From a0c7a0e2d34a13f2c3e86f662e352977ebe2ae73 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 10 Apr 2013 00:33:27 +0300 Subject: Add option to left all per map sprites in memory if once was loaded. This can prevent random lags and also can use more memory. --- src/resources/resourcemanager.cpp | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'src/resources/resourcemanager.cpp') diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp index ef5ccf128..2baf09340 100644 --- a/src/resources/resourcemanager.cpp +++ b/src/resources/resourcemanager.cpp @@ -63,7 +63,8 @@ ResourceManager::ResourceManager() : mOldestOrphan(0), mSelectedSkin(""), mSkinName(""), - mDestruction(0) + mDestruction(0), + mUseLongLiveSprites(config.getBoolValue("uselonglivesprites")) { logger->log1("Initializing resource manager..."); } @@ -188,6 +189,27 @@ void ResourceManager::cleanUp(Resource *const res) #endif } +void ResourceManager::cleanProtected() +{ + ResourceIterator iter = mResources.begin(); + while (iter != mResources.end()) + { + Resource *res = iter->second; + if (!res) + { + ++ iter; + continue; + } + if (res->isProtected()) + { + res->setProtected(false); + res->decRef(); + } + + ++ iter; + } +} + bool ResourceManager::cleanOrphans(const bool always) { timeval tv; @@ -772,6 +794,7 @@ struct SpriteDefLoader { std::string path; int variant; + bool useLongLiveSprites; static Resource *load(const void *const v) { if (!v) @@ -779,14 +802,14 @@ struct SpriteDefLoader const SpriteDefLoader *const rl = static_cast(v); - return SpriteDef::load(rl->path, rl->variant); + return SpriteDef::load(rl->path, rl->variant, rl->useLongLiveSprites); } }; SpriteDef *ResourceManager::getSprite(const std::string &path, const int variant) { - SpriteDefLoader rl = { path, variant }; + SpriteDefLoader rl = { path, variant, mUseLongLiveSprites }; std::stringstream ss; ss << path << "[" << variant << "]"; return static_cast(get(ss.str(), SpriteDefLoader::load, &rl)); @@ -888,6 +911,7 @@ void ResourceManager::deleteInstance() if (instance) { logger->log("clean orphans start"); + instance->cleanProtected(); while (instance->cleanOrphans(true)); logger->log("clean orphans end"); ResourceIterator iter = instance->mResources.begin(); -- cgit v1.2.3-70-g09d2