diff options
Diffstat (limited to 'engines/sci/engine/savegame.cpp')
-rw-r--r-- | engines/sci/engine/savegame.cpp | 69 |
1 files changed, 34 insertions, 35 deletions
diff --git a/engines/sci/engine/savegame.cpp b/engines/sci/engine/savegame.cpp index b53e9d522c..2e06afa3cd 100644 --- a/engines/sci/engine/savegame.cpp +++ b/engines/sci/engine/savegame.cpp @@ -205,13 +205,11 @@ void SegManager::saveLoadWithSerializer(Common::Serializer &s) { } static void sync_SegManagerPtr(Common::Serializer &s, SegManager *&obj) { - SciVersion version = SCI_VERSION_AUTODETECT; - ResourceManager *resMgr = 0; + ResourceManager *resourceManager = 0; if (s.isSaving()) { assert(obj); - version = obj->_version; - resMgr = obj->_resMgr; + resourceManager = obj->_resourceManager; } s.skip(1); // obsolete: used to be a flag indicating if we got sci11 or not @@ -219,7 +217,7 @@ static void sync_SegManagerPtr(Common::Serializer &s, SegManager *&obj) { if (s.isLoading()) { // FIXME: Do in-place loading at some point, instead of creating a new EngineState instance from scratch. delete obj; - obj = new SegManager(resMgr, version); + obj = new SegManager(resourceManager); } obj->saveLoadWithSerializer(s); @@ -244,7 +242,7 @@ static void sync_SavegameMetadata(Common::Serializer &s, SavegameMetadata &obj) s.syncString(obj.savegame_name); s.syncAsSint32LE(obj.savegame_version); s.syncString(obj.game_version); - s.syncAsSint32LE(obj.version); + s.skip(4); // obsolete: used to be game version s.syncAsSint32LE(obj.savegame_date); s.syncAsSint32LE(obj.savegame_time); } @@ -266,9 +264,9 @@ void EngineState::saveLoadWithSerializer(Common::Serializer &s) { s.syncAsSint32LE(status_bar_foreground); s.syncAsSint32LE(status_bar_background); - sync_SegManagerPtr(s, seg_manager); + sync_SegManagerPtr(s, segmentManager); - syncArray<Class>(s, seg_manager->_classtable); + syncArray<Class>(s, segmentManager->_classtable); sync_sfx_state_t(s, _sound); } @@ -445,7 +443,7 @@ static void sync_MemObjPtr(Common::Serializer &s, MemObject *&mobj) { assert(mobj); } - s.syncAsSint32LE(mobj->_segmgrId); + s.syncAsSint32LE(mobj->_segManagerId); mobj->saveLoadWithSerializer(s); } @@ -460,7 +458,6 @@ int gamestate_save(EngineState *s, Common::WriteStream *fh, const char* savename SavegameMetadata meta; meta.savegame_version = CURRENT_SAVEGAME_VERSION; meta.savegame_name = savename; - meta.version = s->_version; meta.game_version = s->game_version; meta.savegame_date = ((curTime.tm_mday & 0xFF) << 24) | (((curTime.tm_mon + 1) & 0xFF) << 16) | ((curTime.tm_year + 1900) & 0xFFFF); meta.savegame_time = ((curTime.tm_hour & 0xFF) << 16) | (((curTime.tm_min) & 0xFF) << 8) | ((curTime.tm_sec) & 0xFF); @@ -499,7 +496,9 @@ static SegmentId find_unique_seg_by_type(SegManager *self, int type) { } static byte *find_unique_script_block(EngineState *s, byte *buf, int type) { - if (((SciEngine*)g_engine)->getKernel()->hasOldScriptHeader()) + bool oldScriptHeader = (s->resourceManager->sciVersion() == SCI_VERSION_0_EARLY); + + if (oldScriptHeader) buf += 2; do { @@ -518,8 +517,8 @@ static byte *find_unique_script_block(EngineState *s, byte *buf, int type) { // FIXME: This should probably be turned into an EngineState method static void reconstruct_stack(EngineState *retval) { - SegmentId stack_seg = find_unique_seg_by_type(retval->seg_manager, MEM_OBJ_STACK); - DataStack *stack = (DataStack *)(retval->seg_manager->_heap[stack_seg]); + SegmentId stack_seg = find_unique_seg_by_type(retval->segmentManager, MEM_OBJ_STACK); + DataStack *stack = (DataStack *)(retval->segmentManager->_heap[stack_seg]); retval->stack_segment = stack_seg; retval->stack_base = stack->entries; @@ -540,18 +539,18 @@ static bool clone_entry_used(CloneTable *table, int n) { static void load_script(EngineState *s, SegmentId seg) { Resource *script, *heap = NULL; - Script *scr = (Script *)(s->seg_manager->_heap[seg]); + Script *scr = (Script *)(s->segmentManager->_heap[seg]); assert(scr); scr->buf = (byte *)malloc(scr->buf_size); assert(scr->buf); - script = s->resmgr->findResource(ResourceId(kResourceTypeScript, scr->nr), 0); - if (s->_version >= SCI_VERSION_1_1) - heap = s->resmgr->findResource(ResourceId(kResourceTypeHeap, scr->nr), 0); + script = s->resourceManager->findResource(ResourceId(kResourceTypeScript, scr->nr), 0); + if (s->resourceManager->sciVersion() >= SCI_VERSION_1_1) + heap = s->resourceManager->findResource(ResourceId(kResourceTypeHeap, scr->nr), 0); memcpy(scr->buf, script->data, script->size); - if (s->seg_manager->_version == SCI_VERSION_1_1) + if (s->resourceManager->sciVersion() == SCI_VERSION_1_1) memcpy(scr->buf + scr->script_size, heap->data, heap->size); } @@ -559,7 +558,7 @@ static void load_script(EngineState *s, SegmentId seg) { static void reconstruct_scripts(EngineState *s, SegManager *self) { uint i, j; MemObject *mobj; - SciVersion version = s->_version; // for the selector defines + SciVersion version = self->sciVersion(); // for the selector defines for (i = 0; i < self->_heap.size(); i++) { if (self->_heap[i]) { @@ -570,8 +569,8 @@ static void reconstruct_scripts(EngineState *s, SegManager *self) { // FIXME: Unify this code with script_instantiate_* load_script(s, i); - scr->locals_block = (scr->locals_segment == 0) ? NULL : (LocalVariables *)(s->seg_manager->_heap[scr->locals_segment]); - if (s->seg_manager->_version == SCI_VERSION_1_1) { + scr->locals_block = (scr->locals_segment == 0) ? NULL : (LocalVariables *)(s->segmentManager->_heap[scr->locals_segment]); + if (s->resourceManager->sciVersion() == SCI_VERSION_1_1) { scr->export_table = 0; scr->synonyms = 0; if (READ_LE_UINT16(scr->buf + 6) > 0) { @@ -607,7 +606,7 @@ static void reconstruct_scripts(EngineState *s, SegManager *self) { for (j = 0; j < scr->_objects.size(); j++) { byte *data = scr->buf + scr->_objects[j].pos.offset; - if (self->_version == SCI_VERSION_1_1) { + if (s->resourceManager->sciVersion() == SCI_VERSION_1_1) { uint16 *funct_area = (uint16 *) (scr->buf + READ_LE_UINT16( data + 6 )); uint16 *prop_area = (uint16 *) (scr->buf + READ_LE_UINT16( data + 4 )); @@ -617,7 +616,7 @@ static void reconstruct_scripts(EngineState *s, SegManager *self) { int funct_area = READ_LE_UINT16( data + SCRIPT_FUNCTAREAPTR_OFFSET ); Object *base_obj; - base_obj = obj_get(s->seg_manager, s->_version, scr->_objects[j]._variables[SCRIPT_SPECIES_SELECTOR]); + base_obj = obj_get(s->segmentManager, scr->_objects[j]._variables[SCRIPT_SPECIES_SELECTOR]); if (!base_obj) { warning("Object without a base class: Script %d, index %d (reg address %04x:%04x", @@ -641,8 +640,8 @@ static void reconstruct_scripts(EngineState *s, SegManager *self) { } // FIXME: The following should likely become a SegManager method -static void reconstruct_clones(EngineState *s, SegManager *self) { - SciVersion version = s->_version; // for the selector defines +static void reconstruct_clones(SegManager *self) { + SciVersion version = self->sciVersion(); // for the selector defines for (uint i = 0; i < self->_heap.size(); i++) { if (self->_heap[i]) { @@ -673,7 +672,7 @@ static void reconstruct_clones(EngineState *s, SegManager *self) { continue; } CloneTable::Entry &seeker = ct->_table[j]; - base_obj = obj_get(s->seg_manager, s->_version, seeker._variables[SCRIPT_SPECIES_SELECTOR]); + base_obj = obj_get(self, seeker._variables[SCRIPT_SPECIES_SELECTOR]); if (!base_obj) { printf("Clone entry without a base class: %d\n", j); seeker.base = seeker.base_obj = NULL; @@ -701,7 +700,7 @@ static void reconstruct_sounds(EngineState *s) { Song *seeker; SongIteratorType it_type; - if (s->_version > SCI_VERSION_01) + if (s->resourceManager->sciVersion() > SCI_VERSION_01) it_type = SCI_SONG_ITERATOR_TYPE_SCI1; else it_type = SCI_SONG_ITERATOR_TYPE_SCI0; @@ -765,7 +764,7 @@ EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) { } // FIXME: Do in-place loading at some point, instead of creating a new EngineState instance from scratch. - retval = new EngineState(s->resmgr, s->_version, s->_flags); + retval = new EngineState(s->resourceManager, s->_flags); // Copy some old data retval->gfx_state = s->gfx_state; @@ -786,20 +785,20 @@ EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) { retval->old_screen = 0; temp = retval->_sound._songlib; - retval->_sound.sfx_init(retval->resmgr, s->sfx_init_flags); + retval->_sound.sfx_init(retval->resourceManager, s->sfx_init_flags); retval->sfx_init_flags = s->sfx_init_flags; retval->_sound._songlib.freeSounds(); retval->_sound._songlib = temp; _reset_graphics_input(retval); reconstruct_stack(retval); - reconstruct_scripts(retval, retval->seg_manager); - reconstruct_clones(retval, retval->seg_manager); + reconstruct_scripts(retval, retval->segmentManager); + reconstruct_clones(retval->segmentManager); retval->game_obj = s->game_obj; - retval->script_000 = retval->seg_manager->getScript(retval->seg_manager->getSegment(0, SCRIPT_GET_DONT_LOAD)); + retval->script_000 = retval->segmentManager->getScript(retval->segmentManager->getSegment(0, SCRIPT_GET_DONT_LOAD)); retval->gc_countdown = GC_INTERVAL - 1; - retval->sys_strings_segment = find_unique_seg_by_type(retval->seg_manager, MEM_OBJ_SYS_STRINGS); - retval->sys_strings = (SystemStrings *)GET_SEGMENT(*retval->seg_manager, retval->sys_strings_segment, MEM_OBJ_SYS_STRINGS); + retval->sys_strings_segment = find_unique_seg_by_type(retval->segmentManager, MEM_OBJ_SYS_STRINGS); + retval->sys_strings = (SystemStrings *)GET_SEGMENT(*retval->segmentManager, retval->sys_strings_segment, MEM_OBJ_SYS_STRINGS); // Restore system strings SystemString *str; @@ -836,7 +835,7 @@ EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) { retval->successor = NULL; retval->pic_priority_table = (int *)gfxop_get_pic_metainfo(retval->gfx_state); - retval->_gameName = obj_get_name(retval->seg_manager, retval->_version, retval->game_obj); + retval->_gameName = obj_get_name(retval->segmentManager, retval->game_obj); retval->_sound._it = NULL; retval->_sound._flags = s->_sound._flags; |