diff options
author | Andrei Karas <akaras@inbox.ru> | 2016-04-25 23:48:28 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2016-04-25 23:48:28 +0300 |
commit | 81dca73da50d8f421a74993de8cd5a9d61ef1e2a (patch) | |
tree | 506308ca4243c57eb15c6c537e231f19255c1047 /src/resources/atlas | |
parent | a73b1787f1b2c293f00f4e71186753c0df476b77 (diff) | |
download | manaplus-81dca73da50d8f421a74993de8cd5a9d61ef1e2a.tar.gz manaplus-81dca73da50d8f421a74993de8cd5a9d61ef1e2a.tar.bz2 manaplus-81dca73da50d8f421a74993de8cd5a9d61ef1e2a.tar.xz manaplus-81dca73da50d8f421a74993de8cd5a9d61ef1e2a.zip |
Add memory counting functions into AtlasResource and some other.
Diffstat (limited to 'src/resources/atlas')
-rw-r--r-- | src/resources/atlas/atlasitem.h | 11 | ||||
-rw-r--r-- | src/resources/atlas/atlasresource.cpp | 18 | ||||
-rw-r--r-- | src/resources/atlas/atlasresource.h | 4 | ||||
-rw-r--r-- | src/resources/atlas/textureatlas.h | 23 |
4 files changed, 53 insertions, 3 deletions
diff --git a/src/resources/atlas/atlasitem.h b/src/resources/atlas/atlasitem.h index 37e021ee8..3a9f05f8d 100644 --- a/src/resources/atlas/atlasitem.h +++ b/src/resources/atlas/atlasitem.h @@ -24,12 +24,14 @@ #ifdef USE_OPENGL #include "resources/image.h" +#include "resources/memorycounter.h" #include <string> -struct AtlasItem final +struct AtlasItem final : public MemoryCounter { explicit AtlasItem(Image *const image0) : + MemoryCounter(), image(image0), name(), x(0), @@ -41,6 +43,13 @@ struct AtlasItem final A_DELETE_COPY(AtlasItem) + int calcMemoryLocal() override final + { + return sizeof(AtlasItem) + + name.capacity(); + // +++ here need print, but not add to sum size of image + } + Image *image; std::string name; int x; diff --git a/src/resources/atlas/atlasresource.cpp b/src/resources/atlas/atlasresource.cpp index 089d12bb7..d48394698 100644 --- a/src/resources/atlas/atlasresource.cpp +++ b/src/resources/atlas/atlasresource.cpp @@ -71,4 +71,22 @@ void AtlasResource::decRef() AtlasManager::moveToDeleted(this); } +int AtlasResource::calcMemoryLocal() +{ + return sizeof(AtlasResource) + + Resource::calcMemoryLocal() + + atlases.capacity() * sizeof(TextureAtlas*); +} + +int AtlasResource::calcMemoryChilds(const int level) +{ + int sz = 0; + FOR_EACH (std::vector<TextureAtlas*>::iterator, it, atlases) + { + TextureAtlas *const atlas = *it; + sz += atlas->calcMemory(level + 1); + } + return sz; +} + #endif diff --git a/src/resources/atlas/atlasresource.h b/src/resources/atlas/atlasresource.h index 0a9d90f04..7dddc6728 100644 --- a/src/resources/atlas/atlasresource.h +++ b/src/resources/atlas/atlasresource.h @@ -44,6 +44,10 @@ class AtlasResource final : public Resource void decRef() override final; + int calcMemoryLocal() override final; + + int calcMemoryChilds(const int level) override final; + std::vector<TextureAtlas*> atlases; }; diff --git a/src/resources/atlas/textureatlas.h b/src/resources/atlas/textureatlas.h index 78b6ff00a..2b9f05930 100644 --- a/src/resources/atlas/textureatlas.h +++ b/src/resources/atlas/textureatlas.h @@ -25,8 +25,9 @@ #include "utils/stringvector.h" -#include <vector> +#include "resources/memorycounter.h" +#include <vector> #include <SDL.h> #include "localconsts.h" @@ -37,9 +38,10 @@ class Resource; struct AtlasItem; -struct TextureAtlas final +struct TextureAtlas final : public MemoryCounter { TextureAtlas() : + MemoryCounter(), name(), atlasImage(nullptr), width(0), @@ -50,6 +52,23 @@ struct TextureAtlas final A_DELETE_COPY(TextureAtlas) + int calcMemoryLocal() override final + { + return sizeof(TextureAtlas) + + items.capacity() * sizeof(AtlasItem*); + } + + int calcMemoryChilds(const int level) override final + { + int sz = 0; + FOR_EACH (std::vector<AtlasItem*>::iterator, it, items) + { + AtlasItem *const item = *it; + sz += item->calcMemory(level + 1); + } + return sz; + } + std::string name; Image *atlasImage; int width; |