summaryrefslogtreecommitdiff
path: root/src
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
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')
-rw-r--r--src/resources/resourcemanager.cpp28
-rw-r--r--src/resources/resourcemanager.h6
2 files changed, 33 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.
diff --git a/src/resources/resourcemanager.h b/src/resources/resourcemanager.h
index 7ed510ac4..2c9fbe3eb 100644
--- a/src/resources/resourcemanager.h
+++ b/src/resources/resourcemanager.h
@@ -224,6 +224,11 @@ class ResourceManager final
void release(Resource *const res);
/**
+ * Move resource to deleted resources list.
+ */
+ void moveToDeleted(Resource *const res);
+
+ /**
* Allocates data into a buffer pointer for raw data loading. The
* returned data is expected to be freed using <code>free()</code>.
*
@@ -307,6 +312,7 @@ class ResourceManager final
std::set<SDL_Surface*> deletedSurfaces;
Resources mResources;
Resources mOrphanedResources;
+ Resources mDeletedResources;
time_t mOldestOrphan;
std::string mSelectedSkin;
std::string mSkinName;