diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/commandhandler.cpp | 73 | ||||
-rw-r--r-- | src/commandhandler.h | 2 | ||||
-rw-r--r-- | src/main.h | 3 | ||||
-rw-r--r-- | src/resources/mapreader.cpp | 2 | ||||
-rw-r--r-- | src/resources/resource.h | 19 | ||||
-rw-r--r-- | src/resources/resourcemanager.h | 22 |
6 files changed, 107 insertions, 14 deletions
diff --git a/src/commandhandler.cpp b/src/commandhandler.cpp index 9371fd493..14a1a3044 100644 --- a/src/commandhandler.cpp +++ b/src/commandhandler.cpp @@ -52,6 +52,12 @@ #include "net/partyhandler.h" #include "net/tradehandler.h" +#ifdef DEBUG_DUMP_LEAKS +#include "resources/image.h" +#include "resources/resource.h" +#include "resources/resourcemanager.h" +#endif + #include "utils/gettext.h" #include "utils/stringutils.h" @@ -276,6 +282,10 @@ void CommandHandler::handleCommand(const std::string &command, ChatTab *tab) { handleAddIgnoreAttack(args, tab); } + else if (type == "dump") + { + handleDump(args, tab); + } else if (tab->handleCommand(type, args)) { // Nothing to do @@ -1088,3 +1098,66 @@ void CommandHandler::handleCacheInfo(const std::string &args _UNUSED_, _("Deleted:"), font->getDeleteCounter())); #endif } + +#ifdef DEBUG_DUMP_LEAKS +void showRes(std::string str, ResourceManager::Resources *res); + +void showRes(std::string str, ResourceManager::Resources *res) +{ + if (debugChatTab) + debugChatTab->chatLog(str + toString(res->size())); + logger->log(str + toString(res->size())); + ResourceManager::ResourceIterator iter = res->begin(); + while (iter != res->end()) + { + if (iter->second && iter->second->getRefCount()) + { + std::string type = " "; + std::string isNew = "N"; + if (iter->second->getDumped()) + isNew = "O"; + else + iter->second->setDumped(true); + + if (dynamic_cast<SubImage*>(iter->second)) + type = "S"; + else if (dynamic_cast<Image*>(iter->second)) + type = "I"; + logger->log("Resource %s%s: %s (%d)", type.c_str(), + isNew.c_str(), iter->second->getIdPath().c_str(), + iter->second->getRefCount()); + } + ++ iter; + } +} + +void CommandHandler::handleDump(const std::string &args, + ChatTab *tab _UNUSED_) +{ + if (!debugChatTab) + return; + + ResourceManager *resman = ResourceManager::getInstance(); + + if (!args.empty()) + { + ResourceManager::Resources *res = resman->getResources(); + showRes(_("Resource images:"), res); + res = resman->getOrphanedResources(); + showRes(_("Resource orphaned images:"), res); + } + else + { + ResourceManager::Resources *res = resman->getResources(); + debugChatTab->chatLog(_("Resource images:") + toString(res->size())); + res = resman->getOrphanedResources(); + debugChatTab->chatLog(_("Resource orphaned images:") + + toString(res->size())); + } +} +#else +void CommandHandler::handleDump(const std::string &args _UNUSED_, + ChatTab *tab _UNUSED_) +{ +} +#endif diff --git a/src/commandhandler.h b/src/commandhandler.h index bb15c139a..f58e86b21 100644 --- a/src/commandhandler.h +++ b/src/commandhandler.h @@ -285,6 +285,8 @@ class CommandHandler void handleAddIgnoreAttack(const std::string &args, ChatTab *tab _UNUSED_); + void handleDump(const std::string &args, ChatTab *tab); + void handleCacheInfo(const std::string &args, ChatTab *tab _UNUSED_); bool parse2Int(const std::string &args, int *x, int *y); diff --git a/src/main.h b/src/main.h index 21316886b..0478e4513 100644 --- a/src/main.h +++ b/src/main.h @@ -83,7 +83,8 @@ #define ENABLEDEBUGLOG 1 -//define DEBUG_LEAKS +//define DEBUG_LEAKS 1 +//define DEBUG_DUMP_LEAKS 1 //define DEBUG_CONFIG 1 //define DEBUG_FONT 1 //define DEBUG_FONT_COUNTERS 1 diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp index 7fa088326..5bec46bdd 100644 --- a/src/resources/mapreader.cpp +++ b/src/resources/mapreader.cpp @@ -419,11 +419,9 @@ inline static void setTile(Map *map, MapLayer *layer, int x, int y, int gid) map->blockTile(x, y, Map::BLOCKTYPE_WALL); break; case Map::COLLISION_AIR: - logger->log("air: %d, %d", x, y); map->blockTile(x, y, Map::BLOCKTYPE_AIR); break; case Map::COLLISION_WATER: - logger->log("water: %d, %d", x, y); map->blockTile(x, y, Map::BLOCKTYPE_WATER); break; default: diff --git a/src/resources/resource.h b/src/resources/resource.h index c4593e7fe..7196fa916 100644 --- a/src/resources/resource.h +++ b/src/resources/resource.h @@ -23,6 +23,8 @@ #ifndef RESOURCE_H #define RESOURCE_H +#include "main.h" + #include <ctime> #include <string> @@ -38,7 +40,11 @@ class Resource * Constructor */ Resource(): mRefCount(0) - { } + { +#ifdef DEBUG_DUMP_LEAKS + mDumped = false; +#endif + } /** * Increments the internal reference count. @@ -66,6 +72,14 @@ class Resource unsigned getRefCount() const { return mRefCount; } +#ifdef DEBUG_DUMP_LEAKS + bool getDumped() + { return mDumped; } + + void setDumped(bool n) + { mDumped = n; } +#endif + protected: /** * Destructor. @@ -77,6 +91,9 @@ class Resource time_t mTimeStamp; /**< Time at which the resource was orphaned. */ unsigned mRefCount; /**< Reference count. */ std::string mName; +#ifdef DEBUG_DUMP_LEAKS + bool mDumped; +#endif }; #endif diff --git a/src/resources/resourcemanager.h b/src/resources/resourcemanager.h index 36abf89e9..16ded5ab2 100644 --- a/src/resources/resourcemanager.h +++ b/src/resources/resourcemanager.h @@ -23,6 +23,8 @@ #ifndef RESOURCE_MANAGER_H #define RESOURCE_MANAGER_H +#include "main.h" + #include <ctime> #include <map> #include <string> @@ -232,17 +234,19 @@ class ResourceManager */ static void deleteInstance(); -/* - void selectSkin(); - - Image *getSkinImage(const std::string &idPath); + int size() + { return mResources.size(); } - std::string mapPathToSkin(const std::string &file); + typedef std::map<std::string, Resource*> Resources; + typedef Resources::iterator ResourceIterator; - void fillSkinsList(std::vector<std::string> &list) const; +#ifdef DEBUG_DUMP_LEAKS + Resources* getResources() + { return &mResources; } - std::string getSkinName() const { return mSkinName; } -*/ + Resources* getOrphanedResources() + { return &mOrphanedResources; } +#endif private: /** @@ -253,8 +257,6 @@ class ResourceManager void cleanOrphans(); static ResourceManager *instance; - typedef std::map<std::string, Resource*> Resources; - typedef Resources::iterator ResourceIterator; std::set<SDL_Surface*> deletedSurfaces; Resources mResources; Resources mOrphanedResources; |