diff options
author | Filippos Karapetis | 2010-05-30 21:49:07 +0000 |
---|---|---|
committer | Filippos Karapetis | 2010-05-30 21:49:07 +0000 |
commit | a0ee93ece52213cd989a50902281d917fe392ea4 (patch) | |
tree | c3f56972fc286a2fd399ad61dd0fd1d648b9a775 /engines/sci/engine | |
parent | e13abd77e92a4c363731f4a6775aa26865bb4ad6 (diff) | |
download | scummvm-rg350-a0ee93ece52213cd989a50902281d917fe392ea4.tar.gz scummvm-rg350-a0ee93ece52213cd989a50902281d917fe392ea4.tar.bz2 scummvm-rg350-a0ee93ece52213cd989a50902281d917fe392ea4.zip |
SCI: Script exports and synonyms are now initialized when a script is loaded. Removed a sanity check inside script_instantiate_sci0 for a bug which no longer exists
svn-id: r49336
Diffstat (limited to 'engines/sci/engine')
-rw-r--r-- | engines/sci/engine/savegame.cpp | 16 | ||||
-rw-r--r-- | engines/sci/engine/savegame.h | 2 | ||||
-rw-r--r-- | engines/sci/engine/script.cpp | 26 | ||||
-rw-r--r-- | engines/sci/engine/segment.cpp | 41 | ||||
-rw-r--r-- | engines/sci/engine/segment.h | 21 |
5 files changed, 29 insertions, 77 deletions
diff --git a/engines/sci/engine/savegame.cpp b/engines/sci/engine/savegame.cpp index 2d21ce6cbb..ae233f8c09 100644 --- a/engines/sci/engine/savegame.cpp +++ b/engines/sci/engine/savegame.cpp @@ -541,8 +541,8 @@ void Script::saveLoadWithSerializer(Common::Serializer &s) { } } - s.syncAsSint32LE(_numExports); - s.syncAsSint32LE(_numSynonyms); + s.skip(4, VER(9), VER(19)); // OBSOLETE: Used to be _numExports + s.skip(4, VER(9), VER(19)); // OBSOLETE: Used to be _numSynonyms s.syncAsSint32LE(_lockers); // Sync _objects. This is a hashmap, and we use the following on disk format: @@ -763,18 +763,6 @@ void SegManager::reconstructScripts(EngineState *s) { // FIXME: Unify this code with script_instantiate_* ? scr->load(g_sci->getResMan()); 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); - } - } else { - scr->_exportTable = (const uint16 *)scr->findBlock(SCI_OBJ_EXPORTS); - scr->_synonyms = scr->findBlock(SCI_OBJ_SYNONYMS); - scr->_exportTable += 3; - } - scr->_codeBlocks.clear(); ObjMap::iterator it; const ObjMap::iterator end = scr->_objects.end(); diff --git a/engines/sci/engine/savegame.h b/engines/sci/engine/savegame.h index bad79fca27..7be05381da 100644 --- a/engines/sci/engine/savegame.h +++ b/engines/sci/engine/savegame.h @@ -36,7 +36,7 @@ namespace Sci { struct EngineState; enum { - CURRENT_SAVEGAME_VERSION = 19, + CURRENT_SAVEGAME_VERSION = 20, MINIMUM_SAVEGAME_VERSION = 9 }; diff --git a/engines/sci/engine/script.cpp b/engines/sci/engine/script.cpp index fda7d05aa0..793f78e030 100644 --- a/engines/sci/engine/script.cpp +++ b/engines/sci/engine/script.cpp @@ -275,9 +275,7 @@ int script_instantiate_common(ResourceManager *resMan, SegManager *segMan, int s // Set heap position (beyond the size word) scr->setLockers(1); - scr->setExportTableOffset(0); - scr->setSynonymsOffset(0); - scr->setSynonymsNr(0); + *was_new = 0; @@ -309,7 +307,7 @@ int script_instantiate_sci0(ResourceManager *resMan, SegManager *segMan, int scr } // Now do a first pass through the script objects to find the - // export table and local variable block + // local variable blocks do { objType = scr->getHeap(curOffset); @@ -317,29 +315,12 @@ int script_instantiate_sci0(ResourceManager *resMan, SegManager *segMan, int scr break; objLength = scr->getHeap(curOffset + 2); - - // This happens in some demos (e.g. the EcoQuest 1 demo). Not sure what is the - // actual cause of it, but the scripts of these demos can't be loaded properly - // and we're stuck forever in this loop, as objLength never changes - if (!objLength) { - warning("script_instantiate_sci0: objLength is 0, unable to parse script"); - return 0; - } - curOffset += 4; // skip header switch (objType) { - case SCI_OBJ_EXPORTS: - scr->setExportTableOffset(curOffset); - break; - case SCI_OBJ_SYNONYMS: - scr->setSynonymsOffset(curOffset); - scr->setSynonymsNr((objLength) / 4); - break; case SCI_OBJ_LOCALVARS: segMan->scriptInitialiseLocals(make_reg(seg_id, curOffset)); break; - case SCI_OBJ_CLASS: { int classpos = curOffset - SCRIPT_OBJECT_MAGIC_OFFSET; int species = scr->getHeap(curOffset - SCRIPT_OBJECT_MAGIC_OFFSET + SCRIPT_SPECIES_OFFSET); @@ -424,9 +405,6 @@ int script_instantiate_sci11(ResourceManager *resMan, SegManager *segMan, int sc Script *scr = segMan->getScript(seg_id); - if (READ_SCI11ENDIAN_UINT16(scr->_buf + 6) > 0) - scr->setExportTableOffset(6); - int heapStart = scr->getScriptSize(); segMan->scriptInitialiseLocals(make_reg(seg_id, heapStart + 4)); segMan->scriptInitialiseObjectsSci11(seg_id); diff --git a/engines/sci/engine/segment.cpp b/engines/sci/engine/segment.cpp index bdd9fbc966..3653ff4ae9 100644 --- a/engines/sci/engine/segment.cpp +++ b/engines/sci/engine/segment.cpp @@ -27,6 +27,7 @@ #include "sci/sci.h" #include "sci/engine/features.h" +#include "sci/engine/script.h" // for SCI_OBJ_EXPORTS and SCI_OBJ_SYNONYMS #include "sci/engine/segment.h" #include "sci/engine/seg_manager.h" #include "sci/engine/state.h" @@ -182,6 +183,28 @@ void Script::load(ResourceManager *resMan) { assert(_bufSize - _scriptSize <= heap->size); memcpy(_heapStart, heap->data, heap->size); } + + _codeBlocks.clear(); + + _exportTable = 0; + _numExports = 0; + _synonyms = 0; + _numSynonyms = 0; + + if (getSciVersion() >= SCI_VERSION_1_1) { + if (READ_LE_UINT16(_buf + 6) > 0) { + _exportTable = (const uint16 *)(_buf + 6 + 2); + _numExports = READ_SCI11ENDIAN_UINT16(_exportTable - 1); + } + } else { + _exportTable = (const uint16 *)findBlock(SCI_OBJ_EXPORTS); + if (_exportTable) { + _exportTable += 3; + _numExports = READ_SCI11ENDIAN_UINT16(_exportTable - 1); + } + _synonyms = findBlock(SCI_OBJ_SYNONYMS); + _numSynonyms = _synonyms ? READ_SCI11ENDIAN_UINT16(_synonyms - 2) / 4 : 0; + } } Object *Script::allocateObject(uint16 offset) { @@ -343,16 +366,6 @@ void Script::setLockers(int lockers) { _lockers = lockers; } -void Script::setExportTableOffset(int offset) { - if (offset) { - _exportTable = (const uint16 *)(_buf + offset + 2); - _numExports = READ_SCI11ENDIAN_UINT16(_exportTable - 1); - } else { - _exportTable = NULL; - _numExports = 0; - } -} - uint16 Script::validateExportFunc(int pubfunct) { bool exportsAreWide = (g_sci->_features->detectLofsType() == SCI_VERSION_1_MIDDLE); @@ -369,18 +382,10 @@ uint16 Script::validateExportFunc(int pubfunct) { return offset; } -void Script::setSynonymsOffset(int offset) { - _synonyms = _buf + offset; -} - const byte *Script::getSynonyms() const { return _synonyms; } -void Script::setSynonymsNr(int n) { - _numSynonyms = n; -} - int Script::getSynonymsNr() const { return _numSynonyms; } diff --git a/engines/sci/engine/segment.h b/engines/sci/engine/segment.h index 7b0828ab6b..ea85a6e764 100644 --- a/engines/sci/engine/segment.h +++ b/engines/sci/engine/segment.h @@ -342,6 +342,7 @@ private: size_t _scriptSize; size_t _heapSize; size_t _bufSize; + Common::Array<CodeBlock> _codeBlocks; public: /** @@ -354,7 +355,6 @@ public: SegmentId _localsSegment; /**< The local variable segment */ LocalVariables *_localsBlock; - Common::Array<CodeBlock> _codeBlocks; bool _markedAsDeleted; public: @@ -444,12 +444,6 @@ public: int getSynonymsNr() const; /** - * Sets the script-relative offset of the exports table. - * @param offset script-relative exports table offset - */ - void setExportTableOffset(int offset); - - /** * Validate whether the specified public function is exported by * the script in the specified segment. * @param pubfunct Index of the function to validate @@ -459,19 +453,6 @@ public: uint16 validateExportFunc(int pubfunct); /** - * Sets the script-relative offset of the synonyms associated with this script. - * @param offset script-relative offset of the synonyms block - */ - void setSynonymsOffset(int offset); - - /** - * Sets the number of synonyms associated with this script, - * @param nr number of synonyms, as to be stored within the script - */ - void setSynonymsNr(int nr); - - - /** * Marks the script as deleted. * This will not actually delete the script. If references remain present on the * heap or the stack, the script will stay in memory in a quasi-deleted state until |