[Scummvm-cvs-logs] SF.net SVN: scummvm:[55593] scummvm/trunk/engines/sword25
thebluegr at users.sourceforge.net
thebluegr at users.sourceforge.net
Fri Jan 28 17:13:14 CET 2011
Revision: 55593
http://scummvm.svn.sourceforge.net/scummvm/?rev=55593&view=rev
Author: thebluegr
Date: 2011-01-28 16:13:12 +0000 (Fri, 28 Jan 2011)
Log Message:
-----------
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.
Modified Paths:
--------------
scummvm/trunk/engines/sword25/gfx/animationresource.cpp
scummvm/trunk/engines/sword25/gfx/fontresource.cpp
scummvm/trunk/engines/sword25/gfx/text.cpp
scummvm/trunk/engines/sword25/kernel/kernel.cpp
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/gfx/animationresource.cpp
===================================================================
--- scummvm/trunk/engines/sword25/gfx/animationresource.cpp 2011-01-28 14:55:56 UTC (rev 55592)
+++ scummvm/trunk/engines/sword25/gfx/animationresource.cpp 2011-01-28 16:13:12 UTC (rev 55593)
@@ -35,6 +35,7 @@
#include "sword25/gfx/animationresource.h"
#include "sword25/kernel/kernel.h"
+#include "sword25/kernel/resmanager.h" // for PRECACHE_RESOURCES
#include "sword25/package/packagemanager.h"
#include "sword25/gfx/bitmapresource.h"
@@ -208,10 +209,14 @@
bool AnimationResource::precacheAllFrames() const {
Common::Array<Frame>::const_iterator iter = _frames.begin();
for (; iter != _frames.end(); ++iter) {
+#ifdef PRECACHE_RESOURCES
if (!Kernel::getInstance()->getResourceManager()->precacheResource((*iter).fileName)) {
error("Could not precache \"%s\".", (*iter).fileName.c_str());
return false;
}
+#else
+ Kernel::getInstance()->getResourceManager()->requestResource((*iter).fileName);
+#endif
}
return true;
Modified: scummvm/trunk/engines/sword25/gfx/fontresource.cpp
===================================================================
--- scummvm/trunk/engines/sword25/gfx/fontresource.cpp 2011-01-28 14:55:56 UTC (rev 55592)
+++ scummvm/trunk/engines/sword25/gfx/fontresource.cpp 2011-01-28 16:13:12 UTC (rev 55593)
@@ -33,6 +33,7 @@
*/
#include "sword25/kernel/kernel.h"
+#include "sword25/kernel/resmanager.h" // for PRECACHE_RESOURCES
#include "sword25/package/packagemanager.h"
#include "sword25/gfx/fontresource.h"
@@ -100,10 +101,14 @@
_bitmapFileName.c_str(), getFileName().c_str());
}
+#ifdef PRECACHE_RESOURCES
// Pre-cache the resource
if (!_pKernel->getResourceManager()->precacheResource(_bitmapFileName)) {
error("Could not precache \"%s\".", _bitmapFileName.c_str());
}
+#else
+ _pKernel->getResourceManager()->requestResource(_bitmapFileName);
+#endif
return true;
}
Modified: scummvm/trunk/engines/sword25/gfx/text.cpp
===================================================================
--- scummvm/trunk/engines/sword25/gfx/text.cpp 2011-01-28 14:55:56 UTC (rev 55592)
+++ scummvm/trunk/engines/sword25/gfx/text.cpp 2011-01-28 16:13:12 UTC (rev 55593)
@@ -39,6 +39,7 @@
#include "sword25/kernel/kernel.h"
#include "sword25/kernel/outputpersistenceblock.h"
#include "sword25/kernel/inputpersistenceblock.h"
+#include "sword25/kernel/resmanager.h" // for PRECACHE_RESOURCES
#include "sword25/gfx/fontresource.h"
#include "sword25/gfx/bitmapresource.h"
@@ -70,7 +71,9 @@
}
bool Text::setFont(const Common::String &font) {
- // Font precachen.
+ // Load font
+
+#ifdef PRECACHE_RESOURCES
if (getResourceManager()->precacheResource(font)) {
_font = font;
updateFormat();
@@ -80,6 +83,13 @@
error("Could not precache font \"%s\". Font probably does not exist.", font.c_str());
return false;
}
+#else
+ getResourceManager()->requestResource(font);
+ _font = font;
+ updateFormat();
+ forceRefresh();
+ return true;
+#endif
}
Modified: scummvm/trunk/engines/sword25/kernel/kernel.cpp
===================================================================
--- scummvm/trunk/engines/sword25/kernel/kernel.cpp 2011-01-28 14:55:56 UTC (rev 55592)
+++ scummvm/trunk/engines/sword25/kernel/kernel.cpp 2011-01-28 16:13:12 UTC (rev 55593)
@@ -155,6 +155,8 @@
* 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;
}
Modified: scummvm/trunk/engines/sword25/kernel/kernel_script.cpp
===================================================================
--- scummvm/trunk/engines/sword25/kernel/kernel_script.cpp 2011-01-28 14:55:56 UTC (rev 55592)
+++ scummvm/trunk/engines/sword25/kernel/kernel_script.cpp 2011-01-28 16:13:12 UTC (rev 55593)
@@ -374,7 +374,11 @@
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 @@
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;
}
Modified: scummvm/trunk/engines/sword25/kernel/resmanager.cpp
===================================================================
--- scummvm/trunk/engines/sword25/kernel/resmanager.cpp 2011-01-28 14:55:56 UTC (rev 55592)
+++ scummvm/trunk/engines/sword25/kernel/resmanager.cpp 2011-01-28 16:13:12 UTC (rev 55593)
@@ -125,6 +125,9 @@
// 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 @@
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 @@
return true;
}
+#endif
+
/**
* Moves a resource to the top of the resource list
* @param pResource The resource
@@ -296,6 +303,7 @@
* 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();
}
Modified: scummvm/trunk/engines/sword25/kernel/resmanager.h
===================================================================
--- scummvm/trunk/engines/sword25/kernel/resmanager.h 2011-01-28 14:55:56 UTC (rev 55592)
+++ scummvm/trunk/engines/sword25/kernel/resmanager.h 2011-01-28 16:13:12 UTC (rev 55593)
@@ -43,6 +43,8 @@
namespace Sword25 {
+//#define PRECACHE_RESOURCES
+
class ResourceService;
class Resource;
class Kernel;
@@ -57,6 +59,7 @@
*/
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 @@
* 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
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