aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/sword25/kernel/resmanager.cpp29
-rw-r--r--engines/sword25/kernel/resmanager.h10
-rw-r--r--engines/sword25/kernel/resource.cpp1
-rw-r--r--engines/sword25/kernel/resource.h8
4 files changed, 14 insertions, 34 deletions
diff --git a/engines/sword25/kernel/resmanager.cpp b/engines/sword25/kernel/resmanager.cpp
index 9b1933568f..8b881dba86 100644
--- a/engines/sword25/kernel/resmanager.cpp
+++ b/engines/sword25/kernel/resmanager.cpp
@@ -64,7 +64,7 @@ ResourceManager::~ResourceManager() {
/**
* Returns a resource by it's ordinal index. Returns NULL if any error occurs
* Note: This method is not optimised for speed and should be used only for debugging purposes
- * @param Ord Ordinal number of the resource. Must be between 0 and GetResourceCount() - 1.
+ * @param ord Ordinal number of the resource. Must be between 0 and GetResourceCount() - 1.
*/
Resource *ResourceManager::getResourceByOrdinal(int ord) const {
// Überprüfen ob der Index Ord innerhald der Listengrenzen liegt.
@@ -231,8 +231,8 @@ Resource *ResourceManager::loadResource(const Common::String &fileName) {
deleteResourcesIfNecessary();
// Load the resource
- Resource *pResource;
- if (!(pResource = _resourceServices[i]->loadResource(fileName))) {
+ Resource *pResource = _resourceServices[i]->loadResource(fileName);
+ if (!pResource) {
BS_LOG_ERRORLN("Responsible service could not load resource \"%s\".", fileName.c_str());
return NULL;
}
@@ -242,7 +242,7 @@ Resource *ResourceManager::loadResource(const Common::String &fileName) {
pResource->_iterator = _resources.begin();
// Also store the resource in the hash table for quick lookup
- _resourceHashTable[pResource->getFileNameHash() % HASH_TABLE_BUCKETS].push_front(pResource);
+ _resourceHashMap[pResource->getFileName()] = pResource;
return pResource;
}
@@ -277,15 +277,13 @@ Common::String ResourceManager::getUniqueFileName(const Common::String &fileName
*/
Common::List<Resource *>::iterator ResourceManager::deleteResource(Resource *pResource) {
// Remove the resource from the hash table
- _resourceHashTable[pResource->getFileNameHash() % HASH_TABLE_BUCKETS].remove(pResource);
-
- Resource *pDummy = pResource;
+ _resourceHashMap.erase(pResource->_fileName);
// Delete the resource from the resource list
Common::List<Resource *>::iterator result = _resources.erase(pResource->_iterator);
// Delete the resource
- delete(pDummy);
+ delete pResource;
// Return the iterator
return result;
@@ -294,21 +292,14 @@ Common::List<Resource *>::iterator ResourceManager::deleteResource(Resource *pRe
/**
* Returns a pointer to a loaded resource. If any error occurs, NULL will be returned.
* @param UniquefileName The absolute path and filename
- * Gibt einen Pointer auf die angeforderte Resource zurück, oder NULL, wenn die Resourcen nicht geladen ist.
*/
Resource *ResourceManager::getResource(const Common::String &uniquefileName) const {
// Determine whether the resource is already loaded
- const Common::List<Resource *>& hashBucket = _resourceHashTable[Common::hashit(uniquefileName) % HASH_TABLE_BUCKETS];
- {
- Common::List<Resource *>::const_iterator iter = hashBucket.begin();
- for (; iter != hashBucket.end(); ++iter) {
- // Wenn die Resource gefunden wurde wird sie zurückgegeben.
- if ((*iter)->getFileName() == uniquefileName)
- return *iter;
- }
- }
+ ResMap::iterator it = _resourceHashMap.find(uniquefileName);
+ if (it != _resourceHashMap.end())
+ return it->_value;
- // Resource wurde nicht gefunden, ist also nicht geladen
+ // Resource was not found, i.e. has not yet been loaded.
return NULL;
}
diff --git a/engines/sword25/kernel/resmanager.h b/engines/sword25/kernel/resmanager.h
index 7f438bb709..f93206eac6 100644
--- a/engines/sword25/kernel/resmanager.h
+++ b/engines/sword25/kernel/resmanager.h
@@ -36,6 +36,8 @@
#define SWORD25_RESOURCEMANAGER_H
#include "common/list.h"
+#include "common/hashmap.h"
+#include "common/hash-str.h"
#include "sword25/kernel/common.h"
@@ -137,10 +139,6 @@ private:
{}
virtual ~ResourceManager();
- enum {
- HASH_TABLE_BUCKETS = 256
- };
-
/**
* Moves a resource to the top of the resource list
* @param pResource The resource
@@ -169,7 +167,6 @@ private:
/**
* Returns a pointer to a loaded resource. If any error occurs, NULL will be returned.
* @param UniqueFileName The absolute path and filename
- * Gibt einen Pointer auf die angeforderte Resource zurück, oder NULL, wenn die Resourcen nicht geladen ist.
*/
Resource *getResource(const Common::String &uniqueFileName) const;
@@ -182,7 +179,8 @@ private:
uint _maxMemoryUsage;
Common::Array<ResourceService *> _resourceServices;
Common::List<Resource *> _resources;
- Common::List<Resource *> _resourceHashTable[HASH_TABLE_BUCKETS];
+ typedef Common::HashMap<Common::String, Resource *> ResMap;
+ ResMap _resourceHashMap;
bool _logCacheMiss;
};
diff --git a/engines/sword25/kernel/resource.cpp b/engines/sword25/kernel/resource.cpp
index f5d9829805..40eea2138c 100644
--- a/engines/sword25/kernel/resource.cpp
+++ b/engines/sword25/kernel/resource.cpp
@@ -47,7 +47,6 @@ Resource::Resource(const Common::String &fileName, RESOURCE_TYPES type) :
BS_ASSERT(pPM);
_fileName = pPM->getAbsolutePath(fileName);
- _fileNameHash = Common::hashit(fileName);
}
void Resource::release() {
diff --git a/engines/sword25/kernel/resource.h b/engines/sword25/kernel/resource.h
index 27003641dd..5c6108a281 100644
--- a/engines/sword25/kernel/resource.h
+++ b/engines/sword25/kernel/resource.h
@@ -89,13 +89,6 @@ public:
}
/**
- * Returns the hash of the filename of a resource
- */
- uint getFileNameHash() const {
- return _fileNameHash;
- }
-
- /**
* Returns a resource's type
*/
uint getType() const {
@@ -107,7 +100,6 @@ protected:
private:
Common::String _fileName; ///< The absolute filename
- uint _fileNameHash; ///< The hash value of the filename
uint _refCount; ///< The number of locks
uint _type; ///< The type of the resource
Common::List<Resource *>::iterator _iterator; ///< Points to the resource position in the LRU list