Skip to content

Commit

Permalink
NEVERHOOD: Implement resource cache purging and purge it after each s…
Browse files Browse the repository at this point in the history
…cene
  • Loading branch information
johndoe123 authored and wjp committed May 8, 2013
1 parent 30178e4 commit fec1d78
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions engines/neverhood/resourceman.cpp
Expand Up @@ -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
1 change: 1 addition & 0 deletions engines/neverhood/resourceman.h
Expand Up @@ -80,6 +80,7 @@ class ResourceMan {
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;
Expand Down
3 changes: 3 additions & 0 deletions engines/neverhood/scene.cpp
Expand Up @@ -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();

}

Expand Down

0 comments on commit fec1d78

Please sign in to comment.