41 #if !defined(DEBUG_DUMP_LEAKS) && !defined(UNITTESTS)
46 PRAGMA48(GCC diagnostic ignored
"-Wshadow")
48 #include <SDL_image.h>
85 if (iter->second->mRefCount)
87 logger->
log(std::string(
"ResourceLeak: ").append(
88 iter->second->mIdPath).append(
" (").append(
89 toString(iter->second->mRefCount)).append(
")"));
109 if (iter->second && iter->second->mRefCount)
116 if (
dynamic_cast<SpriteDef*
>(iter->second) !=
nullptr)
134 if (iter->second && iter->second->mRefCount)
141 if (
dynamic_cast<ImageSet*
>(iter->second) !=
nullptr)
159 if (iter->second && iter->second->mRefCount)
166 if (iter->second !=
nullptr)
188 const unsigned refCount = res->
mRefCount;
191 logger->
log(
"ResourceManager::~ResourceManager() cleaning up %u "
194 (refCount == 1) ?
"" :
"s",
230 gettimeofday(&tv,
nullptr);
232 time_t oldest =
static_cast<time_t
>(tv.tv_sec);
233 const time_t threshold = oldest - 30;
249 if (!always && t >= threshold)
276 const Image *
const image =
dynamic_cast<const Image *
>(res);
277 if (image !=
nullptr)
279 std::string src = image->mSource;
280 const int count = image->mRefCount;
282 src.append(
" ").append(
toString(count));
284 image->getGLImage(), src.c_str());
288 std::string src = res->
mSource;
291 src.append(
" ").append(
toString(count));
331 if ((*resDelIter)->mRefCount == 0U)
363 if (resource !=
nullptr)
368 logger->
log(
"set name %p, %s",
static_cast<void*
>(resource),
381 std::stringstream ss;
382 ss << filename <<
"[" << variant <<
"]";
389 return (resIter !=
mResources.end() && (resIter->second !=
nullptr));
397 Resource *
const res = resIter->second;
398 if (resIter->second !=
nullptr)
410 if (resIter->second !=
nullptr)
411 resIter->second->incRef();
412 return resIter->second;
418 Resource *
const res = resIter->second;
430 const void *
const data)
432 #ifndef DISABLE_RESOURCE_CACHING
434 if (resource !=
nullptr)
436 resource = fun(
data);
438 if (resource !=
nullptr)
443 logger->
log(
"set name %p, %s",
static_cast<void*
>(resource),
451 reportAlways(
"Error loading resource: %s", idPath.c_str())
462 logger->
log(
"set name %p, %s",
static_cast<void*
>(resource),
481 #ifndef DISABLE_RESOURCE_CACHING
501 if (resIter->second != res)
511 gettimeofday(&tv,
nullptr);
512 const time_t timestamp =
static_cast<time_t
>(tv.tv_sec);
537 if (resIter !=
mResources.end() && resIter->second == res)
571 if (resIter !=
mResources.end() && resIter->second == res)
592 #ifdef DUMP_LEAKED_RESOURCES
606 const Resource *
const res = iter->second;
611 logger->
log(std::string(
"ResourceLeak: ").append(
641 BLOCK_END(
"ResourceManager::clearScheduled")
666 sz +=
static_cast<int>((*it).first.capacity());
667 sz += (*it).second->calcMemory(level + 1);
671 sz +=
static_cast<int>((*it).first.capacity());
672 sz += (*it).second->calcMemory(level + 1);
676 sz += (*it)->calcMemory(level + 1);
689 return sumLocal + sumChilds;
697 #if defined(DEBUG_DUMP_LEAKS) || defined(UNITTESTS)
708 const std::set<Resource*> &getDeletedResources()
#define reportAlways(...)
void log(const char *const log_text,...)
void log1(const char *const log_text)
static int getSurfaceSize(const SDL_Surface *const surface)
static void printMemory(const std::string &name, const int level, const int localSum, const int childsSum)
#define MSDL_FreeSurface(surface)
#define FOR_EACH(type, iter, array)
bool msg(InputEvent &event)
std::string toString(T const &value)
converts any type to a string
void deleteResourceManager()
Resource *(&) generator(const void *const data)
void release(Resource *const res)
Resources::const_iterator ResourceCIterator
void logResources(const std::string &msg)
void clearDeleted(const bool full)
bool isInCache(const std::string &idPath)
std::set< Resource * > mDeletedResources
Resource * getFromCache(const std::string &filename, const int variant)
void decRefDelete(Resource *const res)
void scheduleDelete(SDL_Surface *const surface)
int calcMemory(const int level)
void logResource(const Resource *const res)
std::set< SDL_Surface * > deletedSurfaces
bool cleanOrphans(const bool always)
void moveToDeleted(Resource *const res)
std::map< std::string, Resource * > Resources
Resources mOrphanedResources
int calcMemoryChilds(const int level)
Resource * get(const std::string &idPath, generator fun, const void *const data)
bool addResource(const std::string &idPath, Resource *const resource)
Resources::iterator ResourceIterator
void cleanUp(Resource *const res)
Resource * getTempResource(const std::string &idPath)
#define BLOCK_START(name)