[Scummvm-cvs-logs] SF.net SVN: scummvm:[49336] scummvm/trunk/engines/sci/engine

thebluegr at users.sourceforge.net thebluegr at users.sourceforge.net
Sun May 30 23:49:08 CEST 2010


Revision: 49336
          http://scummvm.svn.sourceforge.net/scummvm/?rev=49336&view=rev
Author:   thebluegr
Date:     2010-05-30 21:49:07 +0000 (Sun, 30 May 2010)

Log Message:
-----------
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

Modified Paths:
--------------
    scummvm/trunk/engines/sci/engine/savegame.cpp
    scummvm/trunk/engines/sci/engine/savegame.h
    scummvm/trunk/engines/sci/engine/script.cpp
    scummvm/trunk/engines/sci/engine/segment.cpp
    scummvm/trunk/engines/sci/engine/segment.h

Modified: scummvm/trunk/engines/sci/engine/savegame.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/savegame.cpp	2010-05-30 21:44:26 UTC (rev 49335)
+++ scummvm/trunk/engines/sci/engine/savegame.cpp	2010-05-30 21:49:07 UTC (rev 49336)
@@ -541,8 +541,8 @@
 		}
 	}
 
-	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 @@
 		// 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();

Modified: scummvm/trunk/engines/sci/engine/savegame.h
===================================================================
--- scummvm/trunk/engines/sci/engine/savegame.h	2010-05-30 21:44:26 UTC (rev 49335)
+++ scummvm/trunk/engines/sci/engine/savegame.h	2010-05-30 21:49:07 UTC (rev 49336)
@@ -36,7 +36,7 @@
 struct EngineState;
 
 enum {
-	CURRENT_SAVEGAME_VERSION = 19,
+	CURRENT_SAVEGAME_VERSION = 20,
 	MINIMUM_SAVEGAME_VERSION = 9
 };
 

Modified: scummvm/trunk/engines/sci/engine/script.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/script.cpp	2010-05-30 21:44:26 UTC (rev 49335)
+++ scummvm/trunk/engines/sci/engine/script.cpp	2010-05-30 21:49:07 UTC (rev 49336)
@@ -275,10 +275,8 @@
 
 	// Set heap position (beyond the size word)
 	scr->setLockers(1);
-	scr->setExportTableOffset(0);
-	scr->setSynonymsOffset(0);
-	scr->setSynonymsNr(0);
 
+
 	*was_new = 0;
 
 	return seg_id;
@@ -309,7 +307,7 @@
 	}
 
 	// 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 @@
 			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 @@
 
 	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);

Modified: scummvm/trunk/engines/sci/engine/segment.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/segment.cpp	2010-05-30 21:44:26 UTC (rev 49335)
+++ scummvm/trunk/engines/sci/engine/segment.cpp	2010-05-30 21:49:07 UTC (rev 49336)
@@ -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 @@
 		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 @@
 	_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 @@
 	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;
 }

Modified: scummvm/trunk/engines/sci/engine/segment.h
===================================================================
--- scummvm/trunk/engines/sci/engine/segment.h	2010-05-30 21:44:26 UTC (rev 49335)
+++ scummvm/trunk/engines/sci/engine/segment.h	2010-05-30 21:49:07 UTC (rev 49336)
@@ -342,6 +342,7 @@
 	size_t _scriptSize;
 	size_t _heapSize;
 	size_t _bufSize;
+	Common::Array<CodeBlock> _codeBlocks;
 
 public:
 	/**
@@ -354,7 +355,6 @@
 	SegmentId _localsSegment; /**< The local variable segment */
 	LocalVariables *_localsBlock;
 
-	Common::Array<CodeBlock> _codeBlocks;
 	bool _markedAsDeleted;
 
 public:
@@ -444,12 +444,6 @@
 	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 @@
 	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


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list