aboutsummaryrefslogtreecommitdiff
path: root/engines/sword25
diff options
context:
space:
mode:
authorFilippos Karapetis2011-01-28 16:13:12 +0000
committerFilippos Karapetis2011-01-28 16:13:12 +0000
commita2f960017931ad871c37bf1d9c197418aa8afca9 (patch)
treeea003cd1f548266f26255e048d1d575673b981d7 /engines/sword25
parent7760628bdba085f57711b18c3fa9fdff6c12a38b (diff)
downloadscummvm-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')
-rw-r--r--engines/sword25/gfx/animationresource.cpp5
-rw-r--r--engines/sword25/gfx/fontresource.cpp5
-rw-r--r--engines/sword25/gfx/text.cpp12
-rw-r--r--engines/sword25/kernel/kernel.cpp2
-rw-r--r--engines/sword25/kernel/kernel_script.cpp8
-rw-r--r--engines/sword25/kernel/resmanager.cpp8
-rw-r--r--engines/sword25/kernel/resmanager.h4
7 files changed, 43 insertions, 1 deletions
diff --git a/engines/sword25/gfx/animationresource.cpp b/engines/sword25/gfx/animationresource.cpp
index 8b1062c706..f9347e3dad 100644
--- a/engines/sword25/gfx/animationresource.cpp
+++ b/engines/sword25/gfx/animationresource.cpp
@@ -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 @@ AnimationResource::~AnimationResource() {
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;
diff --git a/engines/sword25/gfx/fontresource.cpp b/engines/sword25/gfx/fontresource.cpp
index 4951d7a9a0..0f0496e9ab 100644
--- a/engines/sword25/gfx/fontresource.cpp
+++ b/engines/sword25/gfx/fontresource.cpp
@@ -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 @@ bool FontResource::parserCallback_font(ParserNode *node) {
_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;
}
diff --git a/engines/sword25/gfx/text.cpp b/engines/sword25/gfx/text.cpp
index 5dad89207f..bbfc3804a3 100644
--- a/engines/sword25/gfx/text.cpp
+++ b/engines/sword25/gfx/text.cpp
@@ -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 @@ Text::Text(InputPersistenceBlock &reader, RenderObjectPtr<RenderObject> parentPt
}
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 @@ bool Text::setFont(const Common::String &font) {
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
}
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