diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-04-10 00:33:27 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-04-10 00:33:27 +0300 |
commit | a0c7a0e2d34a13f2c3e86f662e352977ebe2ae73 (patch) | |
tree | 15996308da765b18751048c6bdaeb81926959328 /src/resources/resourcemanager.cpp | |
parent | c5ff42706d5ff540b5f557fa1a2b1924a6cdf07b (diff) | |
download | manaverse-a0c7a0e2d34a13f2c3e86f662e352977ebe2ae73.tar.gz manaverse-a0c7a0e2d34a13f2c3e86f662e352977ebe2ae73.tar.bz2 manaverse-a0c7a0e2d34a13f2c3e86f662e352977ebe2ae73.tar.xz manaverse-a0c7a0e2d34a13f2c3e86f662e352977ebe2ae73.zip |
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.
Diffstat (limited to 'src/resources/resourcemanager.cpp')
-rw-r--r-- | src/resources/resourcemanager.cpp | 30 |
1 files changed, 27 insertions, 3 deletions
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<const SpriteDefLoader *const>(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<SpriteDef*>(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(); |