diff options
author | Filippos Karapetis | 2011-02-02 19:32:04 +0000 |
---|---|---|
committer | Filippos Karapetis | 2011-02-02 19:32:04 +0000 |
commit | 832cfddf341345554967079374c553ee1822bb5b (patch) | |
tree | 7244c43e2a8659df051f867d1abe7dfd7008a4a2 /engines | |
parent | 1d38568bc133aaba001912f5c2e746fa0ee2d29a (diff) | |
download | scummvm-rg350-832cfddf341345554967079374c553ee1822bb5b.tar.gz scummvm-rg350-832cfddf341345554967079374c553ee1822bb5b.tar.bz2 scummvm-rg350-832cfddf341345554967079374c553ee1822bb5b.zip |
SWORD25: Cache related changes
- Increase the resource cache limits
- Added a check before forcing resources to be freed
- Only force free image and animation resources, with a warning. It seems like there is
a bug in the resource reference code and several bitmap resources are not freed - added
a FIXME
- Clarify that initializeAnimationResource() is used with XML resources
svn-id: r55736
Diffstat (limited to 'engines')
-rw-r--r-- | engines/sword25/gfx/animation.h | 4 | ||||
-rw-r--r-- | engines/sword25/kernel/resmanager.cpp | 47 |
2 files changed, 30 insertions, 21 deletions
diff --git a/engines/sword25/gfx/animation.h b/engines/sword25/gfx/animation.h index 72fe7e2de8..a530c02b12 100644 --- a/engines/sword25/gfx/animation.h +++ b/engines/sword25/gfx/animation.h @@ -211,6 +211,10 @@ private: void initMembers(); AnimationDescription *getAnimationDescription() const; + + /** + * Initializes a new animation resource from an XML file. + */ void initializeAnimationResource(const Common::String &fileName); }; diff --git a/engines/sword25/kernel/resmanager.cpp b/engines/sword25/kernel/resmanager.cpp index 5d9417bdb1..8b446e69d1 100644 --- a/engines/sword25/kernel/resmanager.cpp +++ b/engines/sword25/kernel/resmanager.cpp @@ -43,11 +43,12 @@ namespace Sword25 { // Sets the amount of resources that are simultaneously loaded. // This needs to be a relatively high number, as all the animation // frames in each scene are loaded as separate resources. -#define SWORD25_RESOURCECACHE_MIN 200 +// Also, George's walk states are all loaded here (150 files) +#define SWORD25_RESOURCECACHE_MIN 400 // The maximum number of loaded resources. If more than these resources // are loaded, the resource manager will start purging resources till it // hits the minimum limit above -#define SWORD25_RESOURCECACHE_MAX 300 +#define SWORD25_RESOURCECACHE_MAX 500 ResourceManager::~ResourceManager() { // Clear all unlocked resources @@ -105,16 +106,29 @@ void ResourceManager::deleteResourcesIfNecessary() { } while (iter != _resources.begin() && _resources.size() >= SWORD25_RESOURCECACHE_MIN); // Are we still above the minimum? If yes, then start releasing locked resources + // FIXME: This code shouldn't be needed at all, but it seems like there is a bug + // in the resource lock code, and resources are not unlocked when changing rooms. + // Only image/animation resources are unlocked forcibly, thus this shouldn't have + // any impact on the game itself. + if (_resources.size() <= SWORD25_RESOURCECACHE_MIN) + return; + iter = _resources.end(); do { --iter; - // Forcibly unlock the resource - while ((*iter)->getLockCount() > 0) { - (*iter)->release(); - }; + // Only unlock image/animation resources + if ((*iter)->getFileName().hasSuffix(".swf") || + (*iter)->getFileName().hasSuffix(".png")) { + + warning("Forcibly unlocking %s", (*iter)->getFileName().c_str()); + + // Forcibly unlock the resource + while ((*iter)->getLockCount() > 0) + (*iter)->release(); - iter = deleteResource(*iter); + iter = deleteResource(*iter); + } } while (iter != _resources.begin() && _resources.size() >= SWORD25_RESOURCECACHE_MIN); } @@ -145,21 +159,12 @@ Resource *ResourceManager::requestResource(const Common::String &fileName) { // Determine whether the resource is already loaded // If the resource is found, it will be placed at the head of the resource list and returned - { - Resource *pResource = getResource(uniqueFileName); - if (!pResource) - pResource = loadResource(uniqueFileName); - - if (pResource) { - moveToFront(pResource); - (pResource)->addReference(); - return pResource; - } - } - - Resource *pResource = loadResource(uniqueFileName); + Resource *pResource = getResource(uniqueFileName); + if (!pResource) + pResource = loadResource(uniqueFileName); if (pResource) { - pResource->addReference(); + moveToFront(pResource); + (pResource)->addReference(); return pResource; } |