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

thebluegr at users.sourceforge.net thebluegr at users.sourceforge.net
Fri Jan 28 17:54:57 CET 2011


Revision: 55594
          http://scummvm.svn.sourceforge.net/scummvm/?rev=55594&view=rev
Author:   thebluegr
Date:     2011-01-28 16:54:55 +0000 (Fri, 28 Jan 2011)

Log Message:
-----------
SWORD25: Resources are now cleaned up correctly

The original checked the total amount of memory occupied by all resources. This has been
changed to a maximum number of simultaneous resources instead, so the game resources
are no longer leaked. Also disabled the unused or debug functions getUsedMemory(), 
setMaxMemoryUsage(), setMaxMemoryUsage(), isLogCacheMiss(), setLogCacheMiss(). Performed
some cleanup on code related to the above.

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

Modified: scummvm/trunk/engines/sword25/kernel/kernel.cpp
===================================================================
--- scummvm/trunk/engines/sword25/kernel/kernel.cpp	2011-01-28 16:13:12 UTC (rev 55593)
+++ scummvm/trunk/engines/sword25/kernel/kernel.cpp	2011-01-28 16:54:55 UTC (rev 55594)
@@ -152,15 +152,6 @@
 }
 
 /**
- * Returns how much memory is being used
- */
-size_t Kernel::getUsedMemory() {
-	// TODO: Actually monitor how much memory is being used, so that the game
-	// doesn't keep allocating resources without ever deleting them.
-	return 0;
-}
-
-/**
  * Returns a pointer to the active Gfx Service, or NULL if no Gfx service is active.
  */
 GraphicEngine *Kernel::getGfx() {

Modified: scummvm/trunk/engines/sword25/kernel/kernel.h
===================================================================
--- scummvm/trunk/engines/sword25/kernel/kernel.h	2011-01-28 16:13:12 UTC (rev 55593)
+++ scummvm/trunk/engines/sword25/kernel/kernel.h	2011-01-28 16:54:55 UTC (rev 55594)
@@ -93,10 +93,6 @@
 		return _resourceManager;
 	}
 	/**
-	 * Returns how much memory is being used
-	 */
-	size_t getUsedMemory();
-	/**
 	 * Returns a random number
 	 * @param Min       The minimum allowed value
 	 * @param Max       The maximum allowed value

Modified: scummvm/trunk/engines/sword25/kernel/kernel_script.cpp
===================================================================
--- scummvm/trunk/engines/sword25/kernel/kernel_script.cpp	2011-01-28 16:13:12 UTC (rev 55593)
+++ scummvm/trunk/engines/sword25/kernel/kernel_script.cpp	2011-01-28 16:54:55 UTC (rev 55594)
@@ -168,7 +168,9 @@
 }
 
 static int getUsedMemory(lua_State *L) {
-	lua_pushnumber(L, Kernel::getInstance()->getUsedMemory());
+	// It doesn't really matter what this call returns,
+	// as it's used in a debug function.
+	lua_pushnumber(L, 0);
 	return 1;
 }
 
@@ -404,7 +406,9 @@
 	ResourceManager *pResource = pKernel->getResourceManager();
 	assert(pResource);
 
-	lua_pushnumber(L, pResource->getMaxMemoryUsage());
+	// This is used for debugging, so it doesn't really matter.
+	// The default value set by the scripts is 256000000 bytes
+	lua_pushnumber(L, 256000000);
 
 	return 1;
 }
@@ -415,7 +419,8 @@
 	ResourceManager *pResource = pKernel->getResourceManager();
 	assert(pResource);
 
-	pResource->setMaxMemoryUsage(static_cast<uint>(lua_tonumber(L, 1)));
+	// This call is ignored, we set a limit on the number of
+	// simultaneous resources loaded instead.
 
 	return 0;
 }
@@ -437,7 +442,8 @@
 	ResourceManager *pResource = pKernel->getResourceManager();
 	assert(pResource);
 
-	lua_pushbooleancpp(L, pResource->isLogCacheMiss());
+	// This isn't used in any script
+	lua_pushbooleancpp(L, false);
 
 	return 1;
 }
@@ -448,7 +454,7 @@
 	ResourceManager *pResource = pKernel->getResourceManager();
 	assert(pResource);
 
-	pResource->setLogCacheMiss(lua_tobooleancpp(L, 1));
+	// This isn't used in any script
 
 	return 0;
 }

Modified: scummvm/trunk/engines/sword25/kernel/resmanager.cpp
===================================================================
--- scummvm/trunk/engines/sword25/kernel/resmanager.cpp	2011-01-28 16:13:12 UTC (rev 55593)
+++ scummvm/trunk/engines/sword25/kernel/resmanager.cpp	2011-01-28 16:54:55 UTC (rev 55594)
@@ -40,6 +40,11 @@
 
 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_MAX 100
+
 ResourceManager::~ResourceManager() {
 	// Clear all unlocked resources
 	emptyCache();
@@ -80,7 +85,7 @@
  */
 void ResourceManager::deleteResourcesIfNecessary() {
 	// If enough memory is available, or no resources are loaded, then the function can immediately end
-	if (_kernelPtr->getUsedMemory() < _maxMemoryUsage || _resources.empty())
+	if (_resources.size() < SWORD25_RESOURCECACHE_MAX)
 		return;
 
 	// Keep deleting resources until the memory usage of the process falls below the set maximum limit.
@@ -93,7 +98,7 @@
 		// The resource may be released only if it isn't locked
 		if ((*iter)->getLockCount() == 0)
 			iter = deleteResource(*iter);
-	} while (iter != _resources.begin() && _kernelPtr->getUsedMemory() > _maxMemoryUsage);
+	} while (iter != _resources.begin() && _resources.size() >= SWORD25_RESOURCECACHE_MAX);
 }
 
 /**
@@ -135,10 +140,6 @@
 		}
 	}
 
-	// The resource was not found, therefore, must not be loaded yet
-	if (_logCacheMiss)
-		warning("\"%s\" was not precached.", uniqueFileName.c_str());
-
 	Resource *pResource = loadResource(uniqueFileName);
 	if (pResource) {
 		pResource->addReference();
@@ -296,16 +297,4 @@
 	}
 }
 
-/**
- * Specifies the maximum amount of memory the engine is allowed to use.
- * If this value is exceeded, resources will be unloaded to make room. This value is meant
- * as a guideline, and not as a fixed boundary. It is not guaranteed not to be exceeded;
- * the whole game engine may still use more memory than any amount specified.
- */
-void ResourceManager::setMaxMemoryUsage(uint maxMemoryUsage) {
-	// TODO: Game scripts set this to 256000000. Set it to a more conservative value
-	_maxMemoryUsage = maxMemoryUsage;
-	deleteResourcesIfNecessary();
-}
-
 } // End of namespace Sword25

Modified: scummvm/trunk/engines/sword25/kernel/resmanager.h
===================================================================
--- scummvm/trunk/engines/sword25/kernel/resmanager.h	2011-01-28 16:13:12 UTC (rev 55593)
+++ scummvm/trunk/engines/sword25/kernel/resmanager.h	2011-01-28 16:54:55 UTC (rev 55594)
@@ -82,37 +82,6 @@
 	void emptyCache();
 
 	/**
-	 * Returns the maximum memory the kernel has used
-	 */
-	int getMaxMemoryUsage() const {
-		return _maxMemoryUsage;
-	}
-
-	/**
-	 * Specifies the maximum amount of memory the engine is allowed to use.
-	 * If this value is exceeded, resources will be unloaded to make room. This value is meant
-	 * as a guideline, and not as a fixed boundary. It is not guaranteed not to be exceeded;
-	 * the whole game engine may still use more memory than any amount specified.
-	 */
-	void setMaxMemoryUsage(uint maxMemoryUsage);
-
-	/**
-	 * Specifies whether a warning is written to the log when a cache miss occurs.
-	 * THe default value is "false".
-	 */
-	bool isLogCacheMiss() const {
-		return _logCacheMiss;
-	}
-
-	/**
-	 * Sets whether warnings are written to the log if a cache miss occurs.
-	 * @param Flag      If "true", then future warnings will be logged
-	 */
-	void setLogCacheMiss(bool flag) {
-		_logCacheMiss = flag;
-	}
-
-	/**
 	 * Writes the names of all currently locked resources to the log file
 	 */
 	void dumpLockedResources();
@@ -123,9 +92,7 @@
 	 * Only the BS_Kernel class can generate copies this class. Thus, the constructor is private
 	 */
 	ResourceManager(Kernel *pKernel) :
-		_kernelPtr(pKernel),
-		_maxMemoryUsage(100000000),
-		_logCacheMiss(false)
+		_kernelPtr(pKernel)
 	{}
 	virtual ~ResourceManager();
 
@@ -166,12 +133,10 @@
 	void deleteResourcesIfNecessary();
 
 	Kernel *_kernelPtr;
-	uint _maxMemoryUsage;
 	Common::Array<ResourceService *> _resourceServices;
 	Common::List<Resource *> _resources;
 	typedef Common::HashMap<Common::String, Resource *> ResMap;
 	ResMap _resourceHashMap;
-	bool _logCacheMiss;
 };
 
 } // End of namespace Sword25


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