summaryrefslogtreecommitdiff
path: root/src/resources/atlasmanager.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-09-28 02:09:04 +0300
committerAndrei Karas <akaras@inbox.ru>2012-09-30 04:19:00 +0300
commit48a21f6542e799e41735febbda76815e058954ac (patch)
treed42804ec7de20a3d0c1f417164c547328279ce10 /src/resources/atlasmanager.cpp
parent2364404717e7e7b93daf00f22ee17f72db6e5b27 (diff)
downloadmanaplus-48a21f6542e799e41735febbda76815e058954ac.tar.gz
manaplus-48a21f6542e799e41735febbda76815e058954ac.tar.bz2
manaplus-48a21f6542e799e41735febbda76815e058954ac.tar.xz
manaplus-48a21f6542e799e41735febbda76815e058954ac.zip
Override inc/dec ref to add/remove atlas images to resource cache.
Diffstat (limited to 'src/resources/atlasmanager.cpp')
-rw-r--r--src/resources/atlasmanager.cpp69
1 files changed, 60 insertions, 9 deletions
diff --git a/src/resources/atlasmanager.cpp b/src/resources/atlasmanager.cpp
index 308c8d9ba..a9745bd08 100644
--- a/src/resources/atlasmanager.cpp
+++ b/src/resources/atlasmanager.cpp
@@ -257,20 +257,21 @@ void AtlasManager::convertAtlas(TextureAtlas *atlas)
void AtlasManager::injectToResources(AtlasResource *resource)
{
ResourceManager *const resman = ResourceManager::getInstance();
- int k = 0;
for (std::vector<TextureAtlas*>::iterator it = resource->atlases.begin(),
- it_end = resource->atlases.end(); it != it_end; ++ it, k ++)
+ it_end = resource->atlases.end(); it != it_end; ++ it)
{
// add each atlas image to resources
TextureAtlas *const atlas = *it;
- resman->addResource(atlas->name, atlas->atlasImage);
if (atlas)
{
+ resman->addResource(atlas->name, atlas->atlasImage);
for (std::vector<AtlasItem*>::iterator it2 = atlas->items.begin(),
it2_end = atlas->items.end();
it2 != it2_end; ++ it2)
{
AtlasItem *const item = *it2;
+ if (!item)
+ continue;
// add each atlas sub image to resources
resman->addResource(item->name, item->image);
}
@@ -278,6 +279,42 @@ void AtlasManager::injectToResources(AtlasResource *resource)
}
}
+void AtlasManager::moveToDeleted(AtlasResource *resource)
+{
+ ResourceManager *const resman = ResourceManager::getInstance();
+ for (std::vector<TextureAtlas*>::iterator it = resource->atlases.begin(),
+ it_end = resource->atlases.end(); it != it_end; ++ it)
+ {
+ // move each atlas image to deleted
+ TextureAtlas *const atlas = *it;
+ if (atlas)
+ {
+ Image *const image = atlas->atlasImage;
+ if (image)
+ {
+ image->decRef();
+ resman->moveToDeleted(image);
+ }
+ for (std::vector<AtlasItem*>::iterator it2 = atlas->items.begin(),
+ it2_end = atlas->items.end();
+ it2 != it2_end; ++ it2)
+ {
+ AtlasItem *const item = *it2;
+ if (item)
+ {
+ Image *const image2 = item->image;
+ if (image2)
+ {
+ image2->decRef();
+ // move each atlas sub image to deleted
+ resman->moveToDeleted(image2);
+ }
+ }
+ }
+ }
+ }
+}
+
AtlasResource::~AtlasResource()
{
for (std::vector<TextureAtlas*>::iterator it = atlases.begin(),
@@ -293,18 +330,32 @@ AtlasResource::~AtlasResource()
AtlasItem *const item = *it2;
if (item)
{
- Image *const image = item->image;
- if (image)
- image->decRef();
+// Image *const image = item->image;
+// if (image)
+// image->decRef();
delete item;
}
}
- Image *const image = atlas->atlasImage;
- if (image)
- image->decRef();
+// Image *const image = atlas->atlasImage;
+// if (image)
+// image->decRef();
delete atlas;
}
}
}
+void AtlasResource::incRef()
+{
+ if (!getRefCount())
+ AtlasManager::injectToResources(this);
+ Resource::incRef();
+}
+
+void AtlasResource::decRef()
+{
+ Resource::decRef();
+ if (!getRefCount())
+ AtlasManager::moveToDeleted(this);
+}
+
#endif