aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjohndoe1232013-01-10 00:08:41 +0000
committerWillem Jan Palenstijn2013-05-08 20:47:39 +0200
commitfec1d7816a3e9924db7eb617eda1a6f3fd7b8978 (patch)
tree4e03d0a26dacd3666eb58becd4ac4befd2b197a6
parent30178e46e522c6d741e82e282f3f3edc1fab4825 (diff)
downloadscummvm-rg350-fec1d7816a3e9924db7eb617eda1a6f3fd7b8978.tar.gz
scummvm-rg350-fec1d7816a3e9924db7eb617eda1a6f3fd7b8978.tar.bz2
scummvm-rg350-fec1d7816a3e9924db7eb617eda1a6f3fd7b8978.zip
NEVERHOOD: Implement resource cache purging and purge it after each scene
-rw-r--r--engines/neverhood/resourceman.cpp10
-rw-r--r--engines/neverhood/resourceman.h1
-rw-r--r--engines/neverhood/scene.cpp3
3 files changed, 14 insertions, 0 deletions
diff --git a/engines/neverhood/resourceman.cpp b/engines/neverhood/resourceman.cpp
index 7b7d5cf236..9e5f9ae52f 100644
--- a/engines/neverhood/resourceman.cpp
+++ b/engines/neverhood/resourceman.cpp
@@ -116,4 +116,14 @@ void ResourceMan::unloadResource(ResourceHandle &resourceHandle) {
}
}
+void ResourceMan::purgeResources() {
+ for (Common::HashMap<uint32, ResourceData*>::iterator it = _data.begin(); it != _data.end(); ++it) {
+ ResourceData *resourceData = (*it)._value;
+ if (resourceData->dataRefCount == 0) {
+ delete resourceData->data;
+ resourceData->data = NULL;
+ }
+ }
+}
+
} // End of namespace Neverhood
diff --git a/engines/neverhood/resourceman.h b/engines/neverhood/resourceman.h
index e83de240ed..5a3697fe0d 100644
--- a/engines/neverhood/resourceman.h
+++ b/engines/neverhood/resourceman.h
@@ -80,6 +80,7 @@ public:
void queryResource(uint32 fileHash, ResourceHandle &resourceHandle);
void loadResource(ResourceHandle &resourceHandle);
void unloadResource(ResourceHandle &resourceHandle);
+ void purgeResources();
protected:
typedef Common::HashMap<uint32, ResourceFileEntry> EntriesMap;
Common::Array<BlbArchive*> _archives;
diff --git a/engines/neverhood/scene.cpp b/engines/neverhood/scene.cpp
index 6141ee4487..c899a59408 100644
--- a/engines/neverhood/scene.cpp
+++ b/engines/neverhood/scene.cpp
@@ -70,6 +70,9 @@ Scene::~Scene() {
delete *iter;
// Don't delete surfaces since they always belong to an entity
+
+ // Purge the resources after each scene
+ _vm->_res->purgeResources();
}