summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/resources/resourcemanager.cpp31
-rw-r--r--src/resources/resourcemanager.h8
2 files changed, 38 insertions, 1 deletions
diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp
index 366460a6b..54ffe2d8e 100644
--- a/src/resources/resourcemanager.cpp
+++ b/src/resources/resourcemanager.cpp
@@ -36,6 +36,7 @@
#endif // USE_OPENGL
#include "resources/imagehelper.h"
#include "resources/imageset.h"
+#include "resources/memorymanager.h"
#include "resources/sdlmusic.h"
#include "resources/soundeffect.h"
@@ -1065,3 +1066,33 @@ void ResourceManager::clearCache()
while (cleanOrphans(true))
continue;
}
+
+int ResourceManager::calcMemoryLocal()
+{
+ int sz = sizeof(ResourceManager);
+ FOR_EACH (std::set<SDL_Surface*>::iterator, it, deletedSurfaces)
+ {
+ sz += memoryManager.getSurfaceSize(*it);
+ }
+ return sz;
+}
+
+int ResourceManager::calcMemoryChilds(const int level)
+{
+ int sz = 0;
+ FOR_EACH (ResourceIterator, it, mResources)
+ {
+ sz += (*it).first.capacity();
+ sz += (*it).second->calcMemory(level + 1);
+ }
+ FOR_EACH (ResourceIterator, it, mOrphanedResources)
+ {
+ sz += (*it).first.capacity();
+ sz += (*it).second->calcMemory(level + 1);
+ }
+ FOR_EACH (std::set<Resource*>::iterator, it, mDeletedResources)
+ {
+ sz += (*it)->calcMemory(level + 1);
+ }
+ return sz;
+}
diff --git a/src/resources/resourcemanager.h b/src/resources/resourcemanager.h
index e518883fa..eef584f27 100644
--- a/src/resources/resourcemanager.h
+++ b/src/resources/resourcemanager.h
@@ -23,6 +23,8 @@
#ifndef RESOURCES_RESOURCEMANAGER_H
#define RESOURCES_RESOURCEMANAGER_H
+#include "resources/memorycounter.h"
+
#include "enums/simpletypes/append.h"
#include "utils/stringvector.h"
@@ -47,7 +49,7 @@ struct SDL_RWops;
/**
* A class for loading and managing resources.
*/
-class ResourceManager final
+class ResourceManager final : public MemoryCounter
{
friend class Resource;
@@ -253,6 +255,10 @@ class ResourceManager final
void clearCache();
+ int calcMemoryLocal() override final;
+
+ int calcMemoryChilds(const int level) override final;
+
static void init();
private: