[Scummvm-cvs-logs] SF.net SVN: scummvm:[55722] scummvm/trunk/engines/sword25/kernel/resmanager .cpp

thebluegr at users.sourceforge.net thebluegr at users.sourceforge.net
Wed Feb 2 16:35:07 CET 2011


Revision: 55722
          http://scummvm.svn.sourceforge.net/scummvm/?rev=55722&view=rev
Author:   thebluegr
Date:     2011-02-02 15:35:05 +0000 (Wed, 02 Feb 2011)

Log Message:
-----------
SWORD25: Added a cache minimum and maximum limit, so that the resources loaded will always be inside these limits. Resources can now be forcefully unlocked when the upper limit is reached

Modified Paths:
--------------
    scummvm/trunk/engines/sword25/kernel/resmanager.cpp

Modified: scummvm/trunk/engines/sword25/kernel/resmanager.cpp
===================================================================
--- scummvm/trunk/engines/sword25/kernel/resmanager.cpp	2011-02-02 15:33:33 UTC (rev 55721)
+++ scummvm/trunk/engines/sword25/kernel/resmanager.cpp	2011-02-02 15:35:05 UTC (rev 55722)
@@ -43,7 +43,11 @@
 // 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_MAX 100
+#define SWORD25_RESOURCECACHE_MIN 200
+// 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
 
 ResourceManager::~ResourceManager() {
 	// Clear all unlocked resources
@@ -89,7 +93,7 @@
 		return;
 
 	// Keep deleting resources until the memory usage of the process falls below the set maximum limit.
-	// The list is processed backwards in order to first release those resources who have been
+	// The list is processed backwards in order to first release those resources that have been
 	// not been accessed for the longest
 	Common::List<Resource *>::iterator iter = _resources.end();
 	do {
@@ -98,7 +102,20 @@
 		// The resource may be released only if it isn't locked
 		if ((*iter)->getLockCount() == 0)
 			iter = deleteResource(*iter);
-	} while (iter != _resources.begin() && _resources.size() >= SWORD25_RESOURCECACHE_MAX);
+	} while (iter != _resources.begin() && _resources.size() >= SWORD25_RESOURCECACHE_MIN);
+
+	// Are we still above the minimum? If yes, then start releasing locked resources
+	iter = _resources.end();
+	do {
+		--iter;
+
+		// Forcibly unlock the resource
+		while ((*iter)->getLockCount() > 0) {
+			(*iter)->release();
+		};
+
+		iter = deleteResource(*iter);
+	} while (iter != _resources.begin() && _resources.size() >= SWORD25_RESOURCECACHE_MIN);
 }
 
 /**


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list