Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include "Headers/ResourceCache.h"
#include "Headers/HardwareResource.h"
#include "Core/Headers/ParamHandler.h"

#include "Geometry/Importer/Headers/DVDConverter.h"
#include "Environment/Terrain/Headers/TerrainLoader.h"

namespace Divide {

ResourceCache::ResourceCache()
{
    //_loadingPool = MemoryManager_NEW boost::threadpool::pool(3);
    DVDConverter::createInstance();
    TerrainLoader::createInstance();
}

ResourceCache::~ResourceCache()
{
    DVDConverter::destroyInstance();
    TerrainLoader::destroyInstance();

    Destroy();
    //DELETE(_loadingPool);
    PRINT_FN(Locale::get("RESOURCE_CACHE_DELETE"));
}

void ResourceCache::Destroy() {
    WriteLock w_lock( _creationMutex );
    if ( _resDB.empty() ) {
        return;
    }

    PRINT_FN( Locale::get( "STOP_RESOURCE_CACHE" ) );

	for (ResourceMap::value_type& it : _resDB) {
        while ( it.second->GetRef() > 1 ) {
            it.second->SubRef();
        }
        removeInternal( it.second );
    }

    MemoryManager::DELETE_HASHMAP(_resDB);
}

void ResourceCache::add( const stringImpl& name, Resource* const res ) {
	DIVIDE_ASSERT( !name.empty(), "ResourceCache add error: Invalid resource name!" );
    if(res == nullptr) {
        ERROR_FN(Locale::get("ERROR_RESOURCE_CACHE_LOAD_RES"),name.c_str());
        return;
    }
    res->setName(name);
    WriteLock w_lock( _creationMutex );
    hashAlg::insert(_resDB, hashAlg::makePair(name, res));
}

Resource* ResourceCache::loadResource(const stringImpl& name){
    Resource* res = find(name);
    if ( res ) {
        res->AddRef();
        D_PRINT_FN(Locale::get("RESOURCE_CACHE_GET_RES_INC"), name.c_str(), res->GetRef());
    } else {
        PRINT_FN( Locale::get( "RESOURCE_CACHE_GET_RES" ), name.c_str() );
    }
    return res;
}

Resource* const ResourceCache::find( const stringImpl& name ) {
    ///Search in our resource cache
    ReadLock r_lock( _creationMutex );
    ResourceMap::const_iterator it = _resDB.find(name);
    if(it != _resDB.end()){
        return it->second;
    }
    return nullptr;
}

bool ResourceCache::remove( Resource* resource ) {
    if ( resource == nullptr ) {
        return false;
    }
    stringImpl nameCpy( resource->getName() );
    // If it's not in the resource database, it must've been created manually
    ReadLock r_lock( _creationMutex );
    if ( _resDB.empty() ) {
        ERROR_FN( Locale::get( "RESOURCE_CACHE_REMOVE_NO_DB" ), nameCpy.c_str() );
        return false;
    }
    r_lock.unlock();
    // If we can't remove it right now ...
    if ( removeInternal( resource ) ) {
        WriteLock w_lock( _creationMutex );
        _resDB.erase( _resDB.find( nameCpy ) );
        w_lock.unlock();
        MemoryManager::DELETE( resource );
    } else {
        return false;
    }

    return true;
}

bool ResourceCache::removeInternal(Resource* const resource){
    assert(resource != nullptr);

    stringImpl nameCpy( resource->getName() );
    DIVIDE_ASSERT( !nameCpy.empty(), Locale::get( "ERROR_RESOURCE_CACHE_INVALID_NAME" ) );
    ResourceMap::iterator it = _resDB.find( nameCpy );
	DIVIDE_ASSERT( it != _resDB.end(), Locale::get( "ERROR_RESOURCE_CACHE_UNKNOWN_RESOURCE" ) );
    
	U32 refCount = resource->GetRef();
	if ( refCount > 1 ) {
		resource->SubRef();
        D_PRINT_FN( Locale::get( "RESOURCE_CACHE_REM_RES_DEC" ), nameCpy.c_str(), resource->GetRef() );
		return false; //do not delete pointer
	}

	if (refCount == 1 ) {
        PRINT_FN( Locale::get( "RESOURCE_CACHE_REM_RES" ), nameCpy.c_str() );
        resource->setState(RES_LOADING);
		if ( resource->unload() ) {
			resource->setState(RES_CREATED);
        } else {
            ERROR_FN( Locale::get( "ERROR_RESOURCE_REM" ), nameCpy.c_str() );
            resource->setState(RES_UNKNOWN);
        }
    }

    return true;
}

bool ResourceCache::load(Resource* const res, const stringImpl& name) {
    assert(res != nullptr);
    res->setName(name);
    return true;
}

bool ResourceCache::loadHW(Resource* const res, const stringImpl& name){
    if ( load( res, name ) ) {
        HardwareResource* hwRes = dynamic_cast<HardwareResource* >(res);
        assert(hwRes);
        return hwRes->generateHWResource(name);
    }
    return false;
}

};

Commits for Divide-Framework/trunk/Source Code/Core/Resources/ResourceCache.cpp

Diff revisions: vs.
Revision Author Commited Message
331 Diff Diff IonutCava picture IonutCava Sat 06 Dec, 2014 20:53:45 +0000

[Ionut]
- Limited line length to 132 characters to improve readability and diff-comparisons
- Refactored memory allocation/deallocation functions
- Fixed a few compatibility issues with HashMap.h
- Fixed a bug in GPU Skinning shaders (cast a float to int)

326 Diff Diff IonutCava picture IonutCava Tue 30 Sep, 2014 21:11:32 +0000

[Ionut]
- Fixed more memory leaks
- Simplified Task interface and timing System
- Improved compatibility between Boost, STL and EASTL with random combinations of vectors, strings and maps
- Simplified Light class by removing the “slot” member
- Random optimizations

325 Diff Diff IonutCava picture IonutCava Wed 17 Sep, 2014 20:06:13 +0000

[Ionut]
- Reworked transform system:
— Parent transform chain system moved from Transform class to the PhysicsComponent
— PhysicsComponent now returns all transform values needed both global and local (still needs heavy optimization and caching)

- Reworked SceneGraph node management:
— Proper ref counting of SceneNodes and proper removing of resource (ResourceCache is now empty on destruction, as it should be)
— Removed parent transform tracking as that’s the PhysicsComponent’s responsibility
— Only nodes loaded via the ResourceCache are allowed to be added to the SceneGraph (added proper loaders for Impostors, Sky, etc)

- Optimized some of the math classes (mat4, mat3)

324 Diff Diff IonutCava picture IonutCava Sun 14 Sep, 2014 14:01:39 +0000

[Ionut]
- New memory management system (no custom allocators in this commit)
— Memory tracer to detect memory leaks on shutdown (from: https://www.relisoft.com/book/tech/9new.html)
— SAFE_DELETE_XYZ are now inline template functions not macros
— ASSERTION system now supports logging and message boxes and continue on error configurable for each build type
— Fixed a lot of memory leaks detected by the new system (some still remain)

- Added SRGB support (part 1)
— Albedo textures are loaded as SRGB (make sure resources are SRGB)
— Shaders output gamma corrected colors
— Moved terrain textures back to 2 array system (albedo and normal maps, albedo maps using a SRGB sampler)

- Sky is now loaded via the ResourceCache system
- Added include safeguards in shader atoms

322 Diff Diff IonutCava picture IonutCava Sat 06 Sep, 2014 20:33:47 +0000

[Ionut]
- Refactored most of Boost related code to be C++11 based
— Boost is only used for ThreadPool, Mutex handling, XML parsing and networking (ASIO)
— Function binds, threads, regex, NonCopyable base, Hashing algorithms and more are now using C++11 libraries
- Replaced all FOR_EACH calls with standard, range, “for” calls

321 Diff Diff IonutCava picture IonutCava Wed 03 Sep, 2014 22:05:15 +0000

[Ionut]
- Added support (and enabled by default) for the EASTL library (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2271.html / https://github.com/paulhodge/EASTL)
— Strings, vectors and hash_maps can be combined from EASTL, STL and Boost (not all combinations work. e.g. EASTL strings with STL/Boost containers due to the lack of a proper hash function)

318 Diff Diff IonutCava picture IonutCava Sat 30 Aug, 2014 17:35:53 +0000

[Ionut]
- Wrapped the entire code in a “Divide” namespace
- VertexBuffers now call “shrink_to_fit” on all internal data storage
- Improved some vector performance by preferring “emplace_back” instead of “push_back” + proepr usage of reserve / resize
- Wrapped OIS specific types and classes in Divide::Input namespace
- Added the messageBox.layout file (forgot it in the previous few commits)

301 Diff Diff IonutCava picture IonutCava Tue 05 Aug, 2014 20:55:30 +0000

[Ionut]
- Code cleanups and comments (ShaderManager, ShaderProgram, Texture)
- Fixed some singleton destruction order between ResourceCache and ShaderManager to properly unload remaining shader programs

286 Diff Diff IonutCava picture IonutCava Fri 18 Jul, 2014 16:32:03 +0000

[Ionut] [[BR]]

    • very buggy commit ** [[BR]]

- New rendering pipeline: [[BR]]
— Bumped OpenGL version to 4.4 [[BR]]
— Command based rendering. GFXDevice dispatches rendering commands to their respective buffers [[BR]]
— State changing is exclusively controlled by the GFXDevice class [[BR]]
— Material properties and transform matrices are stored in shader storage buffers that are updated after culling and uploaded once per RenderPass. Objects use drawIDs to index data in shaders [[BR]]
— Removed all custom matrices and other, per shader, bind data [[BR]]
— Removed per node light data. Light culling and shader buffers will replace the old light management system [[BR]]
— Framebuffers now use the Texture class for attachments [[BR]]
— Sampler objects now work like RenderStateBlocks. GL_API handles them and stores them in a hash indexed map [[BR]]
— Removed “prepareMaterial” calls. Pre-draw material setup is now only limited to texture binding [[BR]]
— Moved immediate mode emulation and primitive rendering from API level to GFXDevice level [[BR]]
— Framebuffer rendering must be completed with a call to end() to ensure proper MSAA resolve (asserts, otherwise) [[BR]]
- Fixed hash code generation for RenderStateBlock (and now, glSamplerObject) using boost::hash_combine [[BR]]
- Temporarily disabled XML caching for materials [[BR]]

264 k1ngp1n picture k1ngp1n Tue 27 May, 2014 13:04:38 +0000

[Ionut] [[BR]]
- New camera system: [[BR]]
— Stack based (push/pop active camera) [[BR]]
— Per camera frustum [[BR]]
— Per camera projection [[BR]]
— Shadow mapping now uses the new camera system (each light has a shadow camera) [[BR]]
[[BR]]
- New terrain, water and vegetation system: [[BR]]
— Direct import of terrain from L3DT both as 8-bit grayscale and 16-bit raw formats [[BR]]
— Multiple alpha maps for texture splatting support [[BR]]
— Per texture detail map support [[BR]]
— Transform feedback based visibility culling for vegetation [[BR]]
— Alpha-map based vegetation placing on terrain [[BR]]
— Water now uses a refraction map instead of alpha blending for better refraction effects [[BR]]
[[BR]]
- SceneGraph improvements: [[BR]]
— Better bounding box updates from child to parent [[BR]]
— Better onDraw / postDraw implementation [[BR]]
[[BR]]
- Performance improvements: [[BR]]
— Batch 2D rendering tasks together as much as possible[[BR]]
— Improve renderStateBlock hash generation for better sorting [[BR]]
— Move most state related gfx changes from API implementation to the GFXDevice class [[BR]]
— Move viewport stack to the GFXDevice class [[BR]]
— Added various performance counters (frame duration with round-robin query system, draw call count, etc) [[BR]]
— Fixed and improved clip plane management [[BR]]
— Delete client-side texture data after GPU upload [[BR]]
[[BR]]
- New features: [[BR]]
— Added callback support to the Task class so that a specific task may call a function in the main thread upon completion [[BR]]
— Added mouse-wheel zoom support to Orbit/ThirdPerson cameras [[BR]]
— Added 2D Texture Array support (e.g. used for terrain textures) [[BR]]