aboutsummaryrefslogtreecommitdiff
path: root/engines/sword25/kernel
diff options
context:
space:
mode:
authorFilippos Karapetis2011-02-02 19:32:04 +0000
committerFilippos Karapetis2011-02-02 19:32:04 +0000
commit832cfddf341345554967079374c553ee1822bb5b (patch)
tree7244c43e2a8659df051f867d1abe7dfd7008a4a2 /engines/sword25/kernel
parent1d38568bc133aaba001912f5c2e746fa0ee2d29a (diff)
downloadscummvm-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/sword25/kernel')
-rw-r--r--engines/sword25/kernel/resmanager.cpp47
1 files changed, 26 insertions, 21 deletions
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;
}