diff options
author | Max Horn | 2005-04-23 16:52:11 +0000 |
---|---|---|
committer | Max Horn | 2005-04-23 16:52:11 +0000 |
commit | 554ecd57cbe1bf396cda807e25bd4ed832850d0c (patch) | |
tree | 1721b41a946b7ea85b7826513f16d063ac51f87b | |
parent | b43e1e960fadff6b900329ec96c32121406cb92b (diff) | |
download | scummvm-rg350-554ecd57cbe1bf396cda807e25bd4ed832850d0c.tar.gz scummvm-rg350-554ecd57cbe1bf396cda807e25bd4ed832850d0c.tar.bz2 scummvm-rg350-554ecd57cbe1bf396cda807e25bd4ed832850d0c.zip |
Don't use Common::Map for the object table at all; rather use bsearch on a fixed size table.
svn-id: r17777
-rw-r--r-- | scumm/intern.h | 14 | ||||
-rw-r--r-- | scumm/object.cpp | 5 | ||||
-rw-r--r-- | scumm/resource.cpp | 18 | ||||
-rw-r--r-- | scumm/scumm.cpp | 10 |
4 files changed, 34 insertions, 13 deletions
diff --git a/scumm/intern.h b/scumm/intern.h index f934c6ada0..b6ab82b8f9 100644 --- a/scumm/intern.h +++ b/scumm/intern.h @@ -23,8 +23,6 @@ #ifndef INTERN_H #define INTERN_H -#include "common/map.h" - #include "scumm/scumm.h" #include "scumm/wiz_he.h" @@ -1264,12 +1262,16 @@ protected: const OpcodeEntryV8 *_opcodesV8; - typedef Common::Map<Common::String, int> ObjectIDMap; - - ObjectIDMap _objectIDMap; + struct ObjectNameId { + char name[40]; + int id; + }; + int _objectIDMapSize; + ObjectNameId *_objectIDMap; public: - ScummEngine_v8(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16]) : ScummEngine_v7(detector, syst, gs, md5sum) {} + ScummEngine_v8(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16]); + ~ScummEngine_v8(); protected: virtual void setupOpcodes(); diff --git a/scumm/object.cpp b/scumm/object.cpp index 5a45c3af99..668a388969 100644 --- a/scumm/object.cpp +++ b/scumm/object.cpp @@ -1093,7 +1093,10 @@ int ScummEngine_v8::getObjectIdFromOBIM(const byte *obim) { // In V8, IMHD has no obj_id, but rather a name string. We map the name // back to an object id using a table derived from the DOBJ resource. const ImageHeader *imhd = (const ImageHeader *)findResourceData(MKID('IMHD'), obim); - return _objectIDMap[imhd->v8.name]; + ObjectNameId *found = (ObjectNameId *)bsearch(imhd->v8.name, _objectIDMap, _objectIDMapSize, + sizeof(ObjectNameId), (int (*)(const void*, const void*))strcmp); + assert(found); + return found->id; } int ScummEngine_v7::getObjectIdFromOBIM(const byte *obim) { diff --git a/scumm/resource.cpp b/scumm/resource.cpp index 060f3f83b8..668e2b3431 100644 --- a/scumm/resource.cpp +++ b/scumm/resource.cpp @@ -1148,18 +1148,24 @@ void ScummEngine_v8::readGlobalObjects() { int num = _fileHandle->readUint32LE(); assert(num == _numGlobalObjects); - char buffer[40]; + _objectIDMap = new ObjectNameId[num]; + _objectIDMapSize = num; for (i = 0; i < num; i++) { - _fileHandle->read(buffer, 40); - if (buffer[0]) { - // Add to object name-to-id map - _objectIDMap[buffer] = i; - } + // Add to object name-to-id map + _fileHandle->read(_objectIDMap[i].name, 40); + _objectIDMap[i].id = i; + _objectStateTable[i] = _fileHandle->readByte(); _objectRoomTable[i] = _fileHandle->readByte(); _classData[i] = _fileHandle->readUint32LE(); } memset(_objectOwnerTable, 0xFF, num); + + // Finally, sort the object name->ID map, so we can later use + // bsearch on it. For this we (ab)use strcmp, which works fine + // since the table entries start with a string. + qsort(_objectIDMap, _objectIDMapSize, sizeof(ObjectNameId), + (int (*)(const void*, const void*))strcmp); } void ScummEngine_v7::readGlobalObjects() { diff --git a/scumm/scumm.cpp b/scumm/scumm.cpp index ec1d47e0db..4ef1d024a3 100644 --- a/scumm/scumm.cpp +++ b/scumm/scumm.cpp @@ -1287,6 +1287,16 @@ ScummEngine_v72he::ScummEngine_v72he(GameDetector *detector, OSystem *syst, cons VAR_WIZ_TCOLOR = 0xFF; } +ScummEngine_v8::ScummEngine_v8(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16]) + : ScummEngine_v7(detector, syst, gs, md5sum) { + _objectIDMap = 0; +} + +ScummEngine_v8::~ScummEngine_v8() { + delete [] _objectIDMap; +} + + #pragma mark - #pragma mark --- Initialization --- #pragma mark - |