From 95c58e76d646cf9a14374d2ba1010ada7723e874 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Tue, 17 Mar 2009 16:08:25 +0000 Subject: SCI: Added TODO: Merge SegInterface and MemObject? And some cleanup svn-id: r39485 --- engines/sci/engine/intmap.cpp | 16 ++++++++++++++-- engines/sci/engine/intmap.h | 3 +++ engines/sci/engine/seg_manager.cpp | 4 ++-- engines/sci/engine/seg_manager.h | 8 ++++++-- 4 files changed, 25 insertions(+), 6 deletions(-) (limited to 'engines') diff --git a/engines/sci/engine/intmap.cpp b/engines/sci/engine/intmap.cpp index 2cb41551f0..732b69d4ea 100644 --- a/engines/sci/engine/intmap.cpp +++ b/engines/sci/engine/intmap.cpp @@ -70,9 +70,9 @@ int IntMapper::checkKey(int key, bool add, bool *was_added) { if (was_added) *was_added = false; - if (*node) { + if (*node) return (*node)->idx; - } + // Not found if (!add) @@ -96,6 +96,18 @@ int IntMapper::checkKey(int key, bool add, bool *was_added) { return (*node)->idx; } +int IntMapper::lookupKey(int key) const { + Node *const *node = &(nodes[HASH(key)]); + + while (*node && (key != (*node)->key)) + node = &((*node)->next); + + if (*node) + return (*node)->idx; + + return -1; +} + void IntMapper::saveLoadWithSerializer(Common::Serializer &s) { s.syncAsSint32LE(base_value); if (s.isLoading()) { diff --git a/engines/sci/engine/intmap.h b/engines/sci/engine/intmap.h index 68823789ec..4ada14542a 100644 --- a/engines/sci/engine/intmap.h +++ b/engines/sci/engine/intmap.h @@ -93,6 +93,9 @@ public: */ int checkKey(int key, bool add, bool *wasAdded = 0); + int lookupKey(int key) const; + + /** * Removes a key from the map. * @param key The key to remove diff --git a/engines/sci/engine/seg_manager.cpp b/engines/sci/engine/seg_manager.cpp index 2b9a1bae8a..ae28b89af7 100644 --- a/engines/sci/engine/seg_manager.cpp +++ b/engines/sci/engine/seg_manager.cpp @@ -568,8 +568,8 @@ void SegManager::sm_put_heap(reg_t reg, int16 value) { #endif // return the seg if script_id is valid and in the map, else -1 -int SegManager::segGet(int script_id) { - return id_seg_map->checkKey(script_id, false); +int SegManager::segGet(int script_id) const { + return id_seg_map->lookupKey(script_id); } // validate the seg diff --git a/engines/sci/engine/seg_manager.h b/engines/sci/engine/seg_manager.h index 78cb8bd005..4fcd938651 100644 --- a/engines/sci/engine/seg_manager.h +++ b/engines/sci/engine/seg_manager.h @@ -103,8 +103,7 @@ public: // Get the segment ID associated with a script number // Parameters: (int) script_nr: Number of the script to look up // Returns : (int) The associated segment ID, or -1 if no matching segment exists - // This function is "pure" (i.e, it doesn't modify anything). - int segGet(int script_nr); + int segGet(int script_nr) const; // script lock operations @@ -445,6 +444,11 @@ private: // 11. Segment interface, primarily for GC +// TODO: Merge SegInterface and MemObject? +// After all, _mobj->type == _typeId +// and we make very little use of _segmgr (-> could get rid of that). +// Other code would benefit, e.g. the saveload code. +// But note that _mobj->segmgr_id != _segId ! class SegInterface { protected: SegInterface(SegManager *segmgr, MemObject *mobj, SegmentId segId, memObjType typeId); -- cgit v1.2.3