aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Haisch2009-11-23 15:31:58 +0000
committerBenjamin Haisch2009-11-23 15:31:58 +0000
commitecbd0a0d539c7a0119b0cadef79527960ac22225 (patch)
tree4587f4eafa747d13d8e89e89bbddab9f750c4636
parent95d4c62efbf7b083716d1d2c4a0870eb58dcbc74 (diff)
downloadscummvm-rg350-ecbd0a0d539c7a0119b0cadef79527960ac22225.tar.gz
scummvm-rg350-ecbd0a0d539c7a0119b0cadef79527960ac22225.tar.bz2
scummvm-rg350-ecbd0a0d539c7a0119b0cadef79527960ac22225.zip
Optimized object property access speed
svn-id: r46102
-rw-r--r--engines/made/database.cpp20
-rw-r--r--engines/made/database.h4
2 files changed, 22 insertions, 2 deletions
diff --git a/engines/made/database.cpp b/engines/made/database.cpp
index 70f5db30d4..6fad8e881b 100644
--- a/engines/made/database.cpp
+++ b/engines/made/database.cpp
@@ -320,13 +320,28 @@ void GameDatabase::setObjectString(int16 index, const char *str) {
obj->setString(str);
}
+int16 *GameDatabase::findObjectPropertyCached(int16 objectIndex, int16 propertyId, int16 &propertyFlag) {
+ uint32 id = (objectIndex << 16) | propertyId;
+ ObjectPropertyCacheMap::iterator iter = _objectPropertyCache.find(id);
+ int16 *propertyPtr = NULL;
+ if (iter != _objectPropertyCache.end()) {
+ propertyPtr = (*iter)._value;
+ } else {
+ propertyPtr = findObjectProperty(objectIndex, propertyId, propertyFlag);
+ _objectPropertyCache[id] = propertyPtr;
+ }
+ propertyFlag = 1;
+ return propertyPtr;
+}
+
int16 GameDatabase::getObjectProperty(int16 objectIndex, int16 propertyId) {
if (objectIndex == 0)
return 0;
int16 propertyFlag;
- int16 *property = findObjectProperty(objectIndex, propertyId, propertyFlag);
+ //int16 *property = findObjectProperty(objectIndex, propertyId, propertyFlag);
+ int16 *property = findObjectPropertyCached(objectIndex, propertyId, propertyFlag);
if (property) {
return (int16)READ_LE_UINT16(property);
@@ -342,7 +357,8 @@ int16 GameDatabase::setObjectProperty(int16 objectIndex, int16 propertyId, int16
return 0;
int16 propertyFlag;
- int16 *property = findObjectProperty(objectIndex, propertyId, propertyFlag);
+ //int16 *property = findObjectProperty(objectIndex, propertyId, propertyFlag);
+ int16 *property = findObjectPropertyCached(objectIndex, propertyId, propertyFlag);
if (property) {
if (propertyFlag == 1) {
diff --git a/engines/made/database.h b/engines/made/database.h
index cf5dd31225..a71ba925c1 100644
--- a/engines/made/database.h
+++ b/engines/made/database.h
@@ -27,6 +27,7 @@
#define MADE_DATABASE_H
#include "common/array.h"
+#include "common/hashmap.h"
#include "common/util.h"
#include "common/file.h"
#include "common/stream.h"
@@ -141,6 +142,7 @@ public:
void setObjectString(int16 index, const char *str);
virtual int16 *findObjectProperty(int16 objectIndex, int16 propertyId, int16 &propertyFlag) = 0;
+ int16 *findObjectPropertyCached(int16 objectIndex, int16 propertyId, int16 &propertyFlag);
virtual const char *getString(uint16 offset) = 0;
virtual bool getSavegameDescription(const char *filename, Common::String &description, int16 version) = 0;
virtual int16 savegame(const char *filename, const char *description, int16 version) = 0;
@@ -152,8 +154,10 @@ public:
void dumpObject(int16 index);
protected:
+ typedef Common::HashMap<uint32, int16*> ObjectPropertyCacheMap;
MadeEngine *_vm;
Common::Array<Object*> _objects;
+ ObjectPropertyCacheMap _objectPropertyCache;
byte *_gameState;
uint32 _gameStateSize;
int16 _mainCodeObjectIndex;