diff options
author | Filippos Karapetis | 2010-06-15 07:20:53 +0000 |
---|---|---|
committer | Filippos Karapetis | 2010-06-15 07:20:53 +0000 |
commit | e93f8902a89cb969fd344e49e7086213c8609dbf (patch) | |
tree | 945226b96275eb14163cb9b1e555fdac6ae7e5a0 /engines | |
parent | ff66c67439ec501da5335e78e77b58943cea0972 (diff) | |
download | scummvm-rg350-e93f8902a89cb969fd344e49e7086213c8609dbf.tar.gz scummvm-rg350-e93f8902a89cb969fd344e49e7086213c8609dbf.tar.bz2 scummvm-rg350-e93f8902a89cb969fd344e49e7086213c8609dbf.zip |
Cleanup of the savegame code:
- Added a saveLoadWithSerializer() method to the reg_t class
- Moved SegManager::reconstructClones() inside savegame.cpp
- Moved SoundCommandParser::syncPlayList() and SoundCommandParser::reconstructPlayList() inside savegame.cpp
svn-id: r49683
Diffstat (limited to 'engines')
-rw-r--r-- | engines/sci/engine/savegame.cpp | 103 | ||||
-rw-r--r-- | engines/sci/engine/seg_manager.cpp | 33 | ||||
-rw-r--r-- | engines/sci/engine/vm_types.h | 6 | ||||
-rw-r--r-- | engines/sci/sound/soundcmd.cpp | 34 |
4 files changed, 87 insertions, 89 deletions
diff --git a/engines/sci/engine/savegame.cpp b/engines/sci/engine/savegame.cpp index a7310d2b6a..34457a819f 100644 --- a/engines/sci/engine/savegame.cpp +++ b/engines/sci/engine/savegame.cpp @@ -36,6 +36,7 @@ #include "sci/engine/state.h" #include "sci/engine/message.h" #include "sci/engine/savegame.h" +#include "sci/engine/selector.h" #include "sci/engine/vm_types.h" #include "sci/engine/script.h" // for SCI_OBJ_EXPORTS and SCI_OBJ_SYNONYMS #include "sci/graphics/gui.h" @@ -77,11 +78,6 @@ SongIterator *build_iterator(ResourceManager *resMan, int song_nr, SongIteratorT static void sync_songlib(Common::Serializer &s, SongLibrary &obj); #endif -static void sync_reg_t(Common::Serializer &s, reg_t &obj) { - s.syncAsUint16LE(obj.segment); - s.syncAsUint16LE(obj.offset); -} - #ifdef USE_OLD_MUSIC_FUNCTIONS static void syncSong(Common::Serializer &s, Song &obj) { s.syncAsSint32LE(obj._handle); @@ -132,7 +128,7 @@ void MusicEntry::saveLoadWithSerializer(Common::Serializer &s) { fadeTickerStep = 0; } else { // A bit more optimized saving - sync_reg_t(s, soundObj); + soundObj.saveLoadWithSerializer(s); s.syncAsSint16LE(resourceId); s.syncAsSint16LE(dataInc); s.syncAsSint16LE(ticker); @@ -217,7 +213,7 @@ void syncArray(Common::Serializer &s, Common::Array<T> &arr) { template <> void syncWithSerializer(Common::Serializer &s, reg_t &obj) { - sync_reg_t(s, obj); + obj.saveLoadWithSerializer(s); } void SegManager::saveLoadWithSerializer(Common::Serializer &s) { @@ -297,7 +293,7 @@ void SegManager::saveLoadWithSerializer(Common::Serializer &s) { template <> void syncWithSerializer(Common::Serializer &s, Class &obj) { s.syncAsSint32LE(obj.script); - sync_reg_t(s, obj.reg); + obj.reg.saveLoadWithSerializer(s); } static void sync_SavegameMetadata(Common::Serializer &s, SavegameMetadata &obj) { @@ -396,7 +392,7 @@ void LocalVariables::saveLoadWithSerializer(Common::Serializer &s) { void Object::saveLoadWithSerializer(Common::Serializer &s) { s.syncAsSint32LE(_flags); - sync_reg_t(s, _pos); + _pos.saveLoadWithSerializer(s); s.skip(4, VER(9), VER(12)); // OBSOLETE: Used to be variable_names_nr s.syncAsSint32LE(_methodCount); // that's actually a uint16 @@ -414,18 +410,18 @@ template <> void syncWithSerializer(Common::Serializer &s, Table<List>::Entry &obj) { s.syncAsSint32LE(obj.next_free); - sync_reg_t(s, obj.first); - sync_reg_t(s, obj.last); + obj.first.saveLoadWithSerializer(s); + obj.last.saveLoadWithSerializer(s); } template <> void syncWithSerializer(Common::Serializer &s, Table<Node>::Entry &obj) { s.syncAsSint32LE(obj.next_free); - sync_reg_t(s, obj.pred); - sync_reg_t(s, obj.succ); - sync_reg_t(s, obj.key); - sync_reg_t(s, obj.value); + obj.pred.saveLoadWithSerializer(s); + obj.succ.saveLoadWithSerializer(s); + obj.key.saveLoadWithSerializer(s); + obj.value.saveLoadWithSerializer(s); } #ifdef ENABLE_SCI32 @@ -459,7 +455,7 @@ void syncWithSerializer(Common::Serializer &s, Table<SciArray<reg_t> >::Entry &o if (s.isSaving()) value = obj.getValue(i); - sync_reg_t(s, value); + value.saveLoadWithSerializer(s); if (s.isLoading()) obj.setValue(i, value); @@ -692,6 +688,40 @@ void SciMusic::saveLoadWithSerializer(Common::Serializer &s) { } #endif +void SoundCommandParser::syncPlayList(Common::Serializer &s) { +#ifndef USE_OLD_MUSIC_FUNCTIONS + _music->saveLoadWithSerializer(s); +#endif +} + +void SoundCommandParser::reconstructPlayList(int savegame_version) { +#ifndef USE_OLD_MUSIC_FUNCTIONS + Common::StackLock lock(_music->_mutex); + + const MusicList::iterator end = _music->getPlayListEnd(); + for (MusicList::iterator i = _music->getPlayListStart(); i != end; ++i) { + if ((*i)->resourceId && _resMan->testResource(ResourceId(kResourceTypeSound, (*i)->resourceId))) { + (*i)->soundRes = new SoundResource((*i)->resourceId, _resMan, _soundVersion); + _music->soundInitSnd(*i); + } else { + (*i)->soundRes = 0; + } + if ((*i)->status == kSoundPlaying) { + if (savegame_version < 14) { + (*i)->dataInc = readSelectorValue(_segMan, (*i)->soundObj, SELECTOR(dataInc)); + (*i)->signal = readSelectorValue(_segMan, (*i)->soundObj, SELECTOR(signal)); + + if (_soundVersion >= SCI_VERSION_1_LATE) + (*i)->volume = readSelectorValue(_segMan, (*i)->soundObj, SELECTOR(vol)); + } + + cmdPlaySound((*i)->soundObj, 0); + } + } + +#endif +} + #ifdef ENABLE_SCI32 void ArrayTable::saveLoadWithSerializer(Common::Serializer &ser) { if (ser.getVersion() < 18) @@ -735,7 +765,13 @@ int gamestate_save(EngineState *s, Common::WriteStream *fh, const char* savename return 0; } -// TODO: Move thie function to a more appropriate place, such as vm.cpp or script.cpp +void SegManager::reconstructStack(EngineState *s) { + DataStack *stack = (DataStack *)(_heap[findSegmentByType(SEG_TYPE_STACK)]); + s->stack_base = stack->_entries; + s->stack_top = s->stack_base + stack->_capacity; +} + +// TODO: Move this function to a more appropriate place, such as vm.cpp or script.cpp void SegManager::reconstructScripts(EngineState *s) { uint i; @@ -771,12 +807,35 @@ void SegManager::reconstructScripts(EngineState *s) { } } -void SegManager::reconstructStack(EngineState *s) { - SegmentId stack_seg = findSegmentByType(SEG_TYPE_STACK); - DataStack *stack = (DataStack *)(_heap[stack_seg]); +void SegManager::reconstructClones() { + for (uint i = 0; i < _heap.size(); i++) { + SegmentObj *mobj = _heap[i]; + if (mobj && mobj->getType() == SEG_TYPE_CLONES) { + CloneTable *ct = (CloneTable *)mobj; + + for (uint j = 0; j < ct->_table.size(); j++) { + // Check if the clone entry is used + uint entryNum = (uint)ct->first_free; + bool isUsed = true; + while (entryNum != ((uint) CloneTable::HEAPENTRY_INVALID)) { + if (entryNum == j) { + isUsed = false; + break; + } + entryNum = ct->_table[entryNum].next_free; + } - s->stack_base = stack->_entries; - s->stack_top = stack->_entries + stack->_capacity; + if (!isUsed) + continue; + + CloneTable::Entry &seeker = ct->_table[j]; + const Object *baseObj = getObject(seeker.getSpeciesSelector()); + seeker.cloneFromObject(baseObj); + if (!baseObj) + warning("Clone entry without a base class: %d", j); + } // end for + } // end if + } // end for } #ifdef USE_OLD_MUSIC_FUNCTIONS diff --git a/engines/sci/engine/seg_manager.cpp b/engines/sci/engine/seg_manager.cpp index 8d51b27099..96670b5aeb 100644 --- a/engines/sci/engine/seg_manager.cpp +++ b/engines/sci/engine/seg_manager.cpp @@ -476,39 +476,6 @@ Clone *SegManager::allocateClone(reg_t *addr) { return &(table->_table[offset]); } -void SegManager::reconstructClones() { - for (uint i = 0; i < _heap.size(); i++) { - if (_heap[i]) { - SegmentObj *mobj = _heap[i]; - if (mobj->getType() == SEG_TYPE_CLONES) { - CloneTable *ct = (CloneTable *)mobj; - - for (uint j = 0; j < ct->_table.size(); j++) { - // Check if the clone entry is used - uint entryNum = (uint)ct->first_free; - bool isUsed = true; - while (entryNum != ((uint) CloneTable::HEAPENTRY_INVALID)) { - if (entryNum == j) { - isUsed = false; - break; - } - entryNum = ct->_table[entryNum].next_free; - } - - if (!isUsed) - continue; - - CloneTable::Entry &seeker = ct->_table[j]; - const Object *baseObj = getObject(seeker.getSpeciesSelector()); - seeker.cloneFromObject(baseObj); - if (!baseObj) - warning("Clone entry without a base class: %d", j); - } // end for - } // end if - } // end if - } // end for -} - List *SegManager::allocateList(reg_t *addr) { ListTable *table; int offset; diff --git a/engines/sci/engine/vm_types.h b/engines/sci/engine/vm_types.h index 29dc798c35..614b6f247d 100644 --- a/engines/sci/engine/vm_types.h +++ b/engines/sci/engine/vm_types.h @@ -27,6 +27,7 @@ #define SCI_ENGINE_VM_TYPES_H #include "common/scummsys.h" +#include "common/serializer.h" namespace Sci { @@ -56,6 +57,11 @@ struct reg_t { int16 toSint16() const { return (int16) offset; } + + void saveLoadWithSerializer(Common::Serializer &s) { + s.syncAsUint16LE(segment); + s.syncAsUint16LE(offset); + } }; static inline reg_t make_reg(SegmentId segment, uint16 offset) { diff --git a/engines/sci/sound/soundcmd.cpp b/engines/sci/sound/soundcmd.cpp index 71fc2b7ef0..e317796aad 100644 --- a/engines/sci/sound/soundcmd.cpp +++ b/engines/sci/sound/soundcmd.cpp @@ -1088,40 +1088,6 @@ void SoundCommandParser::clearPlayList() { #endif } -void SoundCommandParser::syncPlayList(Common::Serializer &s) { -#ifndef USE_OLD_MUSIC_FUNCTIONS - _music->saveLoadWithSerializer(s); -#endif -} - -void SoundCommandParser::reconstructPlayList(int savegame_version) { -#ifndef USE_OLD_MUSIC_FUNCTIONS - Common::StackLock lock(_music->_mutex); - - const MusicList::iterator end = _music->getPlayListEnd(); - for (MusicList::iterator i = _music->getPlayListStart(); i != end; ++i) { - if ((*i)->resourceId && _resMan->testResource(ResourceId(kResourceTypeSound, (*i)->resourceId))) { - (*i)->soundRes = new SoundResource((*i)->resourceId, _resMan, _soundVersion); - _music->soundInitSnd(*i); - } else { - (*i)->soundRes = 0; - } - if ((*i)->status == kSoundPlaying) { - if (savegame_version < 14) { - (*i)->dataInc = readSelectorValue(_segMan, (*i)->soundObj, SELECTOR(dataInc)); - (*i)->signal = readSelectorValue(_segMan, (*i)->soundObj, SELECTOR(signal)); - - if (_soundVersion >= SCI_VERSION_1_LATE) - (*i)->volume = readSelectorValue(_segMan, (*i)->soundObj, SELECTOR(vol)); - } - - cmdPlaySound((*i)->soundObj, 0); - } - } - -#endif -} - void SoundCommandParser::printPlayList(Console *con) { #ifndef USE_OLD_MUSIC_FUNCTIONS _music->printPlayList(con); |