diff options
author | Filippos Karapetis | 2011-01-28 16:13:12 +0000 |
---|---|---|
committer | Filippos Karapetis | 2011-01-28 16:13:12 +0000 |
commit | a2f960017931ad871c37bf1d9c197418aa8afca9 (patch) | |
tree | ea003cd1f548266f26255e048d1d575673b981d7 /engines/sword25/kernel | |
parent | 7760628bdba085f57711b18c3fa9fdff6c12a38b (diff) | |
download | scummvm-rg350-a2f960017931ad871c37bf1d9c197418aa8afca9.tar.gz scummvm-rg350-a2f960017931ad871c37bf1d9c197418aa8afca9.tar.bz2 scummvm-rg350-a2f960017931ad871c37bf1d9c197418aa8afca9.zip |
SWORD25: Disabled the mechanism which precaches all of the game's resources on startup.
This reduced the initial memory used by 100MB for me, though the game keeps allocating
new resources in each scene without deleting them, because of the missing functionality in
getUsedMemory(). This change also slightly reduces the loading time on game startup.
svn-id: r55593
Diffstat (limited to 'engines/sword25/kernel')
-rw-r--r-- | engines/sword25/kernel/kernel.cpp | 2 | ||||
-rw-r--r-- | engines/sword25/kernel/kernel_script.cpp | 8 | ||||
-rw-r--r-- | engines/sword25/kernel/resmanager.cpp | 8 | ||||
-rw-r--r-- | engines/sword25/kernel/resmanager.h | 4 |
4 files changed, 22 insertions, 0 deletions
diff --git a/engines/sword25/kernel/kernel.cpp b/engines/sword25/kernel/kernel.cpp index 7c6a683907..45ec492bc9 100644 --- a/engines/sword25/kernel/kernel.cpp +++ b/engines/sword25/kernel/kernel.cpp @@ -155,6 +155,8 @@ uint Kernel::getMilliTicks() { * 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; } diff --git a/engines/sword25/kernel/kernel_script.cpp b/engines/sword25/kernel/kernel_script.cpp index 49ad678a00..e5586a513b 100644 --- a/engines/sword25/kernel/kernel_script.cpp +++ b/engines/sword25/kernel/kernel_script.cpp @@ -374,7 +374,11 @@ static int precacheResource(lua_State *L) { ResourceManager *pResource = pKernel->getResourceManager(); assert(pResource); +#ifdef PRECACHE_RESOURCES lua_pushbooleancpp(L, pResource->precacheResource(luaL_checkstring(L, 1))); +#else + lua_pushbooleancpp(L, true); +#endif return 1; } @@ -385,7 +389,11 @@ static int forcePrecacheResource(lua_State *L) { ResourceManager *pResource = pKernel->getResourceManager(); assert(pResource); +#ifdef PRECACHE_RESOURCES lua_pushbooleancpp(L, pResource->precacheResource(luaL_checkstring(L, 1), true)); +#else + lua_pushbooleancpp(L, true); +#endif return 1; } diff --git a/engines/sword25/kernel/resmanager.cpp b/engines/sword25/kernel/resmanager.cpp index df975bcca6..3b0dbcf5eb 100644 --- a/engines/sword25/kernel/resmanager.cpp +++ b/engines/sword25/kernel/resmanager.cpp @@ -125,6 +125,9 @@ Resource *ResourceManager::requestResource(const Common::String &fileName) { // 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(); @@ -145,6 +148,8 @@ Resource *ResourceManager::requestResource(const Common::String &fileName) { return NULL; } +#ifdef PRECACHE_RESOURCES + /** * Loads a resource into the cache * @param FileName The filename of the resource to be cached @@ -178,6 +183,8 @@ bool ResourceManager::precacheResource(const Common::String &fileName, bool forc return true; } +#endif + /** * Moves a resource to the top of the resource list * @param pResource The resource @@ -296,6 +303,7 @@ void ResourceManager::dumpLockedResources() { * 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(); } diff --git a/engines/sword25/kernel/resmanager.h b/engines/sword25/kernel/resmanager.h index 613bb3a3a2..c097ca7024 100644 --- a/engines/sword25/kernel/resmanager.h +++ b/engines/sword25/kernel/resmanager.h @@ -43,6 +43,8 @@ namespace Sword25 { +//#define PRECACHE_RESOURCES + class ResourceService; class Resource; class Kernel; @@ -57,6 +59,7 @@ public: */ Resource *requestResource(const Common::String &fileName); +#ifdef PRECACHE_RESOURCES /** * Loads a resource into the cache * @param FileName The filename of the resource to be cached @@ -64,6 +67,7 @@ public: * This is useful for files that may have changed in the interim */ bool precacheResource(const Common::String &fileName, bool forceReload = false); +#endif /** * Registers a RegisterResourceService. This method is the constructor of |