summaryrefslogtreecommitdiff
path: root/src/resources/resourcemanager.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-09-27 23:02:41 +0300
committerAndrei Karas <akaras@inbox.ru>2012-09-27 23:02:41 +0300
commit3c696abed2aa5b7b8b349b9c4c14c69436ec2d27 (patch)
tree7972afdd8ab3809eee249d67ceb7a80682026dfc /src/resources/resourcemanager.cpp
parentaeff5ccbda56ef0dd4259f0b02ba318c28b7945b (diff)
downloadplus-3c696abed2aa5b7b8b349b9c4c14c69436ec2d27.tar.gz
plus-3c696abed2aa5b7b8b349b9c4c14c69436ec2d27.tar.bz2
plus-3c696abed2aa5b7b8b349b9c4c14c69436ec2d27.tar.xz
plus-3c696abed2aa5b7b8b349b9c4c14c69436ec2d27.zip
Add support for deleted resource list in resourse manager.
Diffstat (limited to 'src/resources/resourcemanager.cpp')
-rw-r--r--src/resources/resourcemanager.cpp28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp
index aae5c3db7..7d80e8bcc 100644
--- a/src/resources/resourcemanager.cpp
+++ b/src/resources/resourcemanager.cpp
@@ -67,6 +67,7 @@ ResourceManager::~ResourceManager()
{
mDestruction = true;
mResources.insert(mOrphanedResources.begin(), mOrphanedResources.end());
+ mResources.insert(mDeletedResources.begin(), mDeletedResources.end());
// Release any remaining spritedefs first because they depend on image sets
ResourceIterator iter = mResources.begin();
@@ -671,7 +672,16 @@ void ResourceManager::release(Resource *const res)
if (!res || mDestruction)
return;
- const ResourceIterator resIter = mResources.find(res->mIdPath);
+ ResourceIterator resIter = mDeletedResources.find(res->mIdPath);
+ if (resIter != mDeletedResources.end() && resIter->second == res)
+ {
+ // we found zero counted image in deleted list. deleting it and exit.
+ mDeletedResources.erase(resIter);
+ delete res;
+ return;
+ }
+
+ resIter = mResources.find(res->mIdPath);
// The resource has to exist
assert(resIter != mResources.end() && resIter->second == res);
@@ -691,6 +701,22 @@ void ResourceManager::release(Resource *const res)
#endif
}
+void ResourceManager::moveToDeleted(Resource *const res)
+{
+ ResourceIterator resIter = mResources.find(res->mIdPath);
+ if (resIter != mResources.end() && resIter->second == res)
+ {
+ mDeletedResources.insert(*resIter);
+ mResources.erase(resIter);
+ }
+ resIter = mOrphanedResources.find(res->mIdPath);
+ if (resIter != mOrphanedResources.end() && resIter->second == res)
+ {
+ mDeletedResources.insert(*resIter);
+ mOrphanedResources.erase(resIter);
+ }
+}
+
ResourceManager *ResourceManager::getInstance()
{
// Create a new instance if necessary.