summaryrefslogtreecommitdiff
path: root/src/resources
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-04-26 15:14:30 +0300
committerAndrei Karas <akaras@inbox.ru>2016-04-26 15:14:30 +0300
commitefd0e0d1bdbaf5a5d5ff469a5fd7efdf9db446be (patch)
tree9f8b74d79fdadc8e6de9d6fdd427c02096df2e8b /src/resources
parent8486afa9e52f96361cbf2c822258d6c5799c47d8 (diff)
downloadmanaverse-efd0e0d1bdbaf5a5d5ff469a5fd7efdf9db446be.tar.gz
manaverse-efd0e0d1bdbaf5a5d5ff469a5fd7efdf9db446be.tar.bz2
manaverse-efd0e0d1bdbaf5a5d5ff469a5fd7efdf9db446be.tar.xz
manaverse-efd0e0d1bdbaf5a5d5ff469a5fd7efdf9db446be.zip
Add memory count functions into ResourceManager.
Diffstat (limited to 'src/resources')
-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: