From 81dca73da50d8f421a74993de8cd5a9d61ef1e2a Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 25 Apr 2016 23:48:28 +0300 Subject: Add memory counting functions into AtlasResource and some other. --- src/resources/atlas/atlasitem.h | 11 ++++++++++- src/resources/atlas/atlasresource.cpp | 18 ++++++++++++++++++ src/resources/atlas/atlasresource.h | 4 ++++ 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 -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::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 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 +#include "resources/memorycounter.h" +#include #include #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::iterator, it, items) + { + AtlasItem *const item = *it; + sz += item->calcMemory(level + 1); + } + return sz; + } + std::string name; Image *atlasImage; int width; -- cgit v1.2.3-60-g2f50