aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/toltecs/TODO.txt1
-rw-r--r--engines/toltecs/resource.cpp12
-rw-r--r--engines/toltecs/resource.h1
-rw-r--r--engines/toltecs/script.cpp1
4 files changed, 13 insertions, 2 deletions
diff --git a/engines/toltecs/TODO.txt b/engines/toltecs/TODO.txt
index ae913ef6e4..449ffcbe15 100644
--- a/engines/toltecs/TODO.txt
+++ b/engines/toltecs/TODO.txt
@@ -12,7 +12,6 @@ TODO
delta-frames so currently, once restored, the screen is wrong. This is only observed in
a few places.
- Add "Quit game" functionality to the menu
-- Flush the resource cache when changing rooms, otherwise the game will keep eating up memory
BUGS
------
diff --git a/engines/toltecs/resource.cpp b/engines/toltecs/resource.cpp
index 62dbca3141..e1e3cb9ac7 100644
--- a/engines/toltecs/resource.cpp
+++ b/engines/toltecs/resource.cpp
@@ -90,7 +90,17 @@ ResourceCache::ResourceCache(ToltecsEngine *vm) : _vm(vm) {
}
ResourceCache::~ResourceCache() {
- // TODO: Delete resources
+ purgeCache();
+}
+
+void ResourceCache::purgeCache() {
+ for (ResourceMap::iterator iter = _cache.begin(); iter != _cache.end(); ++iter) {
+ delete[] iter->_value->data;
+ delete iter->_value;
+ iter->_value = 0;
+ }
+
+ _cache.clear();
}
Resource *ResourceCache::load(uint resIndex) {
diff --git a/engines/toltecs/resource.h b/engines/toltecs/resource.h
index 0201bd5daa..7f4694f0f6 100644
--- a/engines/toltecs/resource.h
+++ b/engines/toltecs/resource.h
@@ -68,6 +68,7 @@ public:
~ResourceCache();
Resource *load(uint resIndex);
+ void purgeCache();
protected:
typedef Common::HashMap<uint, Resource*> ResourceMap;
diff --git a/engines/toltecs/script.cpp b/engines/toltecs/script.cpp
index 8f534ef398..780e9ef215 100644
--- a/engines/toltecs/script.cpp
+++ b/engines/toltecs/script.cpp
@@ -896,6 +896,7 @@ void ScriptInterpreter::sfLoadAddPalette() {
void ScriptInterpreter::sfLoadScene() {
if (arg8(3) == 0) {
_vm->_sound->stopSpeech();
+ _vm->_res->purgeCache();
_vm->loadScene(arg16(4));
} else {
_vm->_screen->loadMouseCursor(arg16(4));