diff --git a/src/ResourceManager.h b/src/ResourceManager.h index 27898efe0..919bc810c 100644 --- a/src/ResourceManager.h +++ b/src/ResourceManager.h @@ -266,40 +266,40 @@ template class Resource { inline Resource(): manager(nullptr), lastCheck(0), _state(ResourceState::Final), data(nullptr) {} /** @brief Copy constructor */ - inline Resource(const Resource& other): manager(other.manager), key(other.key), lastCheck(other.lastCheck), _state(other._state), data(other.data) { - if(manager) manager->incrementReferenceCount(key); + inline Resource(const Resource& other): manager(other.manager), _key(other._key), lastCheck(other.lastCheck), _state(other._state), data(other.data) { + if(manager) manager->incrementReferenceCount(_key); } /** @brief Move constructor */ - inline Resource(Resource&& other): manager(other.manager), key(other.key), lastCheck(other.lastCheck), _state(other._state), data(other.data) { + inline Resource(Resource&& other): manager(other.manager), _key(other._key), lastCheck(other.lastCheck), _state(other._state), data(other.data) { other.manager = nullptr; } /** @brief Destructor */ inline ~Resource() { - if(manager) manager->decrementReferenceCount(key); + if(manager) manager->decrementReferenceCount(_key); } /** @brief Assignment operator */ Resource& operator=(const Resource& other) { - if(manager) manager->decrementReferenceCount(key); + if(manager) manager->decrementReferenceCount(_key); manager = other.manager; - key = other.key; + _key = other._key; lastCheck = other.lastCheck; _state = other._state; data = other.data; - if(manager) manager->incrementReferenceCount(key); + if(manager) manager->incrementReferenceCount(_key); return *this; } /** @brief Assignment move operator */ Resource& operator=(Resource&& other) { - if(manager) manager->decrementReferenceCount(key); + if(manager) manager->decrementReferenceCount(_key); manager = other.manager; - key = other.key; + _key = other._key; lastCheck = other.lastCheck; _state = other._state; data = other.data; @@ -308,6 +308,9 @@ template class Resource { return *this; } + /** @brief Resource key */ + inline ResourceKey key() const { return _key; } + /** * @brief %Resource state * @@ -343,7 +346,7 @@ template class Resource { } private: - inline Resource(Implementation::ResourceManagerData* manager, ResourceKey key): manager(manager), key(key), lastCheck(0), _state(ResourceState::NotLoaded), data(nullptr) { + inline Resource(Implementation::ResourceManagerData* manager, ResourceKey key): manager(manager), _key(key), lastCheck(0), _state(ResourceState::NotLoaded), data(nullptr) { manager->incrementReferenceCount(key); } @@ -355,7 +358,7 @@ template class Resource { if(manager->lastChange() < lastCheck) return; /* Acquire new data and save last check time */ - const typename Implementation::ResourceManagerData::Data& d = manager->data(key); + const typename Implementation::ResourceManagerData::Data& d = manager->data(_key); lastCheck = manager->lastChange(); /* Try to get the data */ @@ -368,7 +371,7 @@ template class Resource { } Implementation::ResourceManagerData* manager; - ResourceKey key; + ResourceKey _key; size_t lastCheck; ResourceState _state; T* data; @@ -423,7 +426,7 @@ Resource cube(manager->get("cube")); if(!cube) { Mesh* mesh = new Mesh; // ... - manager->set("cube", mesh, ResourceDataState::Final, ResourcePolicy::Resident); + manager->set(cube.key(), mesh, ResourceDataState::Final, ResourcePolicy::Resident); } @endcode - Using the resource data.