diff options
author | Max Horn | 2009-10-08 22:03:55 +0000 |
---|---|---|
committer | Max Horn | 2009-10-08 22:03:55 +0000 |
commit | 0c457be0fbc7935f264d8df55b034e33bda6f09f (patch) | |
tree | ca56fe1c09aacf5bf978e7cc0fa7dfff6a90186d /engines | |
parent | 860f7ce39befef97035c4eedd862799bd084545f (diff) | |
download | scummvm-rg350-0c457be0fbc7935f264d8df55b034e33bda6f09f.tar.gz scummvm-rg350-0c457be0fbc7935f264d8df55b034e33bda6f09f.tar.bz2 scummvm-rg350-0c457be0fbc7935f264d8df55b034e33bda6f09f.zip |
SCI: Turn reconstruct_scripts into SegManager::reconstructScripts
svn-id: r44806
Diffstat (limited to 'engines')
-rw-r--r-- | engines/sci/engine/savegame.cpp | 142 | ||||
-rw-r--r-- | engines/sci/engine/seg_manager.h | 11 |
2 files changed, 71 insertions, 82 deletions
diff --git a/engines/sci/engine/savegame.cpp b/engines/sci/engine/savegame.cpp index 18e20d9c98..9c8f255902 100644 --- a/engines/sci/engine/savegame.cpp +++ b/engines/sci/engine/savegame.cpp @@ -572,90 +572,78 @@ static void load_script(EngineState *s, Script *scr) { } } -// FIXME: The following should likely become a SegManager method -static void reconstruct_scripts(EngineState *s, SegManager *self) { +void SegManager::reconstructScripts(EngineState *s) { uint i; SegmentObj *mobj; - for (i = 0; i < self->_heap.size(); i++) { - if (self->_heap[i]) { - mobj = self->_heap[i]; - switch (mobj->getType()) { - case SEG_TYPE_SCRIPT: { - Script *scr = (Script *)mobj; - - // FIXME: Unify this code with script_instantiate_* - load_script(s, scr); - scr->_localsBlock = (scr->_localsSegment == 0) ? NULL : (LocalVariables *)(s->_segMan->_heap[scr->_localsSegment]); - if (getSciVersion() >= SCI_VERSION_1_1) { - scr->_exportTable = 0; - scr->_synonyms = 0; - if (READ_LE_UINT16(scr->_buf + 6) > 0) { - scr->setExportTableOffset(6); - s->_segMan->scriptRelocateExportsSci11(i); - } - } else { - scr->_exportTable = (uint16 *) find_unique_script_block(s, scr->_buf, SCI_OBJ_EXPORTS); - scr->_synonyms = find_unique_script_block(s, scr->_buf, SCI_OBJ_SYNONYMS); - scr->_exportTable += 3; - } - scr->_codeBlocks.clear(); - - ObjMap::iterator it; - const ObjMap::iterator end = scr->_objects.end(); - for (it = scr->_objects.begin(); it != end; ++it) { - byte *data = scr->_buf + it->_value._pos.offset; - it->_value.base = scr->_buf; - it->_value.base_obj = data; - } - break; - } - default: - break; + for (i = 0; i < _heap.size(); i++) { + mobj = _heap[i]; + if (!mobj || mobj->getType() != SEG_TYPE_SCRIPT) + continue; + + Script *scr = (Script *)mobj; + + // FIXME: Unify this code with script_instantiate_* ? + load_script(s, scr); + scr->_localsBlock = (scr->_localsSegment == 0) ? NULL : (LocalVariables *)(_heap[scr->_localsSegment]); + if (getSciVersion() >= SCI_VERSION_1_1) { + scr->_exportTable = 0; + scr->_synonyms = 0; + if (READ_LE_UINT16(scr->_buf + 6) > 0) { + scr->setExportTableOffset(6); + s->_segMan->scriptRelocateExportsSci11(i); } + } else { + scr->_exportTable = (uint16 *) find_unique_script_block(s, scr->_buf, SCI_OBJ_EXPORTS); + scr->_synonyms = find_unique_script_block(s, scr->_buf, SCI_OBJ_SYNONYMS); + scr->_exportTable += 3; + } + scr->_codeBlocks.clear(); + + ObjMap::iterator it; + const ObjMap::iterator end = scr->_objects.end(); + for (it = scr->_objects.begin(); it != end; ++it) { + byte *data = scr->_buf + it->_value._pos.offset; + it->_value.base = scr->_buf; + it->_value.base_obj = data; } } - for (i = 0; i < self->_heap.size(); i++) { - if (self->_heap[i]) { - mobj = self->_heap[i]; - switch (mobj->getType()) { - case SEG_TYPE_SCRIPT: { - Script *scr = (Script *)mobj; - - ObjMap::iterator it; - const ObjMap::iterator end = scr->_objects.end(); - for (it = scr->_objects.begin(); it != end; ++it) { - byte *data = scr->_buf + it->_value._pos.offset; - - if (getSciVersion() >= 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 )); - - it->_value.base_method = funct_area; - it->_value.base_vars = prop_area; - } else { - int funct_area = READ_LE_UINT16( data + SCRIPT_FUNCTAREAPTR_OFFSET ); - Object *base_obj; - - base_obj = s->_segMan->getObject(it->_value.getSpeciesSelector()); - - if (!base_obj) { - warning("Object without a base class: Script %d, index %d (reg address %04x:%04x", - scr->_nr, i, PRINT_REG(it->_value.getSpeciesSelector())); - continue; - } - it->_value.variable_names_nr = base_obj->_variables.size(); - it->_value.base_obj = base_obj->base_obj; - - it->_value.base_method = (uint16 *)(data + funct_area); - it->_value.base_vars = (uint16 *)(data + it->_value.variable_names_nr * 2 + SCRIPT_SELECTOR_OFFSET); - } + for (i = 0; i < _heap.size(); i++) { + mobj = _heap[i]; + if (!mobj || mobj->getType() != SEG_TYPE_SCRIPT) + continue; + + Script *scr = (Script *)mobj; + + // FIXME: Unify this code with Script::scriptObjInit ? + ObjMap::iterator it; + const ObjMap::iterator end = scr->_objects.end(); + for (it = scr->_objects.begin(); it != end; ++it) { + byte *data = scr->_buf + it->_value._pos.offset; + + if (getSciVersion() >= 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 )); + + it->_value.base_method = funct_area; + it->_value.base_vars = prop_area; + } else { + int funct_area = READ_LE_UINT16(data + SCRIPT_FUNCTAREAPTR_OFFSET); + Object *base_obj; + + base_obj = s->_segMan->getObject(it->_value.getSpeciesSelector()); + + if (!base_obj) { + warning("Object without a base class: Script %d, index %d (reg address %04x:%04x", + scr->_nr, i, PRINT_REG(it->_value.getSpeciesSelector())); + continue; } - break; - } - default: - break; + it->_value.variable_names_nr = base_obj->_variables.size(); + it->_value.base_obj = base_obj->base_obj; + + it->_value.base_method = (uint16 *)(data + funct_area); + it->_value.base_vars = (uint16 *)(data + it->_value.variable_names_nr * 2 + SCRIPT_SELECTOR_OFFSET); } } } @@ -756,7 +744,7 @@ EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) { _reset_graphics_input(retval); reconstruct_stack(retval); - reconstruct_scripts(retval, retval->_segMan); + retval->_segMan->reconstructScripts(retval); retval->_segMan->reconstructClones(); retval->game_obj = s->game_obj; retval->script_000 = retval->_segMan->getScript(retval->_segMan->getScriptSegment(0, SCRIPT_GET_DONT_LOAD)); diff --git a/engines/sci/engine/seg_manager.h b/engines/sci/engine/seg_manager.h index 877f8f27e6..078e626af4 100644 --- a/engines/sci/engine/seg_manager.h +++ b/engines/sci/engine/seg_manager.h @@ -80,6 +80,11 @@ public: void deallocateScript(int script_nr); /** + * Reconstructs scripts. Used when restoring saved games + */ + void reconstructScripts(EngineState *s); + + /** * Validate whether the specified public function is exported by * the script in the specified segment. * @param pubfunct Index of the function to validate @@ -106,6 +111,7 @@ public: */ SegmentId getScriptSegment(int script_nr, ScriptLoadType load); + // TODO: document this reg_t lookupScriptExport(int script_nr, int export_index) { SegmentId seg = getScriptSegment(script_nr, SCRIPT_GET_DONT_LOAD); return make_reg(seg, validateExportFunc(export_index, seg)); @@ -169,16 +175,11 @@ public: */ Clone *allocateClone(reg_t *addr); - /** * Reconstructs clones. Used when restoring saved games */ void reconstructClones(); - // 3. Objects (static, from Scripts, and dynmic, from Clones) - - - // 4. Stack /** |