diff options
author | Johannes Schickel | 2016-03-23 20:41:48 +0100 |
---|---|---|
committer | Johannes Schickel | 2016-03-25 01:15:26 +0100 |
commit | f23dd0f4864a0d6b1e6e54159e4948249b15fc80 (patch) | |
tree | ddd5f7af04992f6e6cd1d2f8b935a91584ce6542 /engines/sci | |
parent | 1c6112e121c6a70df965d6cba1b382d1a3cdbc9c (diff) | |
download | scummvm-rg350-f23dd0f4864a0d6b1e6e54159e4948249b15fc80.tar.gz scummvm-rg350-f23dd0f4864a0d6b1e6e54159e4948249b15fc80.tar.bz2 scummvm-rg350-f23dd0f4864a0d6b1e6e54159e4948249b15fc80.zip |
SCI: Use aggregation to store objects in SegmentObjTable.
This allows to store pointers and fundamental types in a SegmentObjTable.
Diffstat (limited to 'engines/sci')
-rw-r--r-- | engines/sci/engine/savegame.cpp | 40 | ||||
-rw-r--r-- | engines/sci/engine/segment.h | 10 |
2 files changed, 24 insertions, 26 deletions
diff --git a/engines/sci/engine/savegame.cpp b/engines/sci/engine/savegame.cpp index 66e8101e9a..3a9ce00626 100644 --- a/engines/sci/engine/savegame.cpp +++ b/engines/sci/engine/savegame.cpp @@ -88,22 +88,12 @@ void syncWithSerializer(Common::Serializer &s, Class &obj) { syncWithSerializer(s, obj.reg); } -void syncWithSerializer(Common::Serializer &s, SegmentObjTable<Clone>::Entry &obj) { - s.syncAsSint32LE(obj.next_free); - - syncWithSerializer(s, (Clone &)obj); -} - -void syncWithSerializer(Common::Serializer &s, SegmentObjTable<List>::Entry &obj) { - s.syncAsSint32LE(obj.next_free); - +void syncWithSerializer(Common::Serializer &s, List &obj) { syncWithSerializer(s, obj.first); syncWithSerializer(s, obj.last); } -void syncWithSerializer(Common::Serializer &s, SegmentObjTable<Node>::Entry &obj) { - s.syncAsSint32LE(obj.next_free); - +void syncWithSerializer(Common::Serializer &s, Node &obj) { syncWithSerializer(s, obj.pred); syncWithSerializer(s, obj.succ); syncWithSerializer(s, obj.key); @@ -111,9 +101,7 @@ void syncWithSerializer(Common::Serializer &s, SegmentObjTable<Node>::Entry &obj } #ifdef ENABLE_SCI32 -void syncWithSerializer(Common::Serializer &s, SegmentObjTable<SciArray<reg_t> >::Entry &obj) { - s.syncAsSint32LE(obj.next_free); - +void syncWithSerializer(Common::Serializer &s, SciArray<reg_t> &obj) { byte type = 0; uint32 size = 0; @@ -146,9 +134,7 @@ void syncWithSerializer(Common::Serializer &s, SegmentObjTable<SciArray<reg_t> > } } -void syncWithSerializer(Common::Serializer &s, SegmentObjTable<SciString>::Entry &obj) { - s.syncAsSint32LE(obj.next_free); - +void syncWithSerializer(Common::Serializer &s, SciString &obj) { uint32 size = 0; if (s.isSaving()) { @@ -184,6 +170,16 @@ struct DefaultSyncer : Common::BinaryFunction<Common::Serializer, T, void> { } }; +// Syncer for entries in a segment obj table +template<typename T> +struct SegmentObjTableEntrySyncer : Common::BinaryFunction<Common::Serializer, typename T::Entry &, void> { + void operator()(Common::Serializer &s, typename T::Entry &entry) const { + s.syncAsSint32LE(entry.next_free); + + syncWithSerializer(s, entry.data); + } +}; + /** * Sync a Common::Array using a Common::Serializer. * When saving, this writes the length of the array, then syncs (writes) all entries. @@ -216,9 +212,9 @@ struct ArraySyncer : Common::BinaryFunction<Common::Serializer, T, void> { }; // Convenience wrapper -template<typename T> +template<typename T, class Syncer = DefaultSyncer<T>> void syncArray(Common::Serializer &s, Common::Array<T> &arr) { - ArraySyncer<T> sync; + ArraySyncer<T, Syncer> sync; sync(s, arr); } @@ -423,7 +419,7 @@ void sync_Table(Common::Serializer &s, T &obj) { s.syncAsSint32LE(obj.first_free); s.syncAsSint32LE(obj.entries_used); - syncArray<typename T::Entry>(s, obj._table); + syncArray<typename T::Entry, SegmentObjTableEntrySyncer<T> >(s, obj._table); } void CloneTable::saveLoadWithSerializer(Common::Serializer &s) { @@ -900,7 +896,7 @@ void SegManager::reconstructClones() { if (!isUsed) continue; - CloneTable::Entry &seeker = ct->_table[j]; + CloneTable::value_type &seeker = ct->at(j); const Object *baseObj = getObject(seeker.getSpeciesSelector()); seeker.cloneFromObject(baseObj); if (!baseObj) { diff --git a/engines/sci/engine/segment.h b/engines/sci/engine/segment.h index 529f6b7a7d..50c77d0538 100644 --- a/engines/sci/engine/segment.h +++ b/engines/sci/engine/segment.h @@ -210,7 +210,8 @@ struct Hunk { template<typename T> struct SegmentObjTable : public SegmentObj { typedef T value_type; - struct Entry : public T { + struct Entry { + T data; int next_free; /* Only used for free entries */ }; enum { HEAPENTRY_INVALID = -1 }; @@ -218,7 +219,8 @@ struct SegmentObjTable : public SegmentObj { int first_free; /**< Beginning of a singly linked list for entries */ int entries_used; /**< Statistical information */ - Common::Array<Entry> _table; + typedef Common::Array<Entry> ArrayType; + ArrayType _table; public: SegmentObjTable(SegmentType type) : SegmentObj(type) { @@ -274,8 +276,8 @@ public: uint size() const { return _table.size(); } - T &at(uint index) { return _table[index]; } - const T &at(uint index) const { return _table[index]; } + T &at(uint index) { return _table[index].data; } + const T &at(uint index) const { return _table[index].data; } T &operator[](uint index) { return at(index); } const T &operator[](uint index) const { return at(index); } |