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

thebluegr at users.sourceforge.net thebluegr at users.sourceforge.net
Mon Jun 14 00:15:30 CEST 2010


Revision: 49640
          http://scummvm.svn.sourceforge.net/scummvm/?rev=49640&view=rev
Author:   thebluegr
Date:     2010-06-13 22:15:30 +0000 (Sun, 13 Jun 2010)

Log Message:
-----------
The offset of script local variables is now calculated when the script is loaded, thus we no longer need to save it. Merged scriptInitialiseLocals() with scriptInitialiseLocalsZero()

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/seg_manager.h
    scummvm/trunk/engines/sci/engine/segment.cpp

Modified: scummvm/trunk/engines/sci/engine/savegame.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/savegame.cpp	2010-06-13 22:01:10 UTC (rev 49639)
+++ scummvm/trunk/engines/sci/engine/savegame.cpp	2010-06-13 22:15:30 UTC (rev 49640)
@@ -566,7 +566,7 @@
 		}
 	}
 
-	s.syncAsSint32LE(_localsOffset);
+	s.skip(4, VER(9), VER(20));		// OBSOLETE: Used to be _localsOffset
 	s.syncAsSint32LE(_localsSegment);
 
 	s.syncAsSint32LE(_markedAsDeleted);

Modified: scummvm/trunk/engines/sci/engine/savegame.h
===================================================================
--- scummvm/trunk/engines/sci/engine/savegame.h	2010-06-13 22:01:10 UTC (rev 49639)
+++ scummvm/trunk/engines/sci/engine/savegame.h	2010-06-13 22:15:30 UTC (rev 49640)
@@ -36,7 +36,7 @@
 struct EngineState;
 
 enum {
-	CURRENT_SAVEGAME_VERSION = 20,
+	CURRENT_SAVEGAME_VERSION = 21,
 	MINIMUM_SAVEGAME_VERSION = 9
 };
 

Modified: scummvm/trunk/engines/sci/engine/script.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/script.cpp	2010-06-13 22:01:10 UTC (rev 49639)
+++ scummvm/trunk/engines/sci/engine/script.cpp	2010-06-13 22:15:30 UTC (rev 49640)
@@ -159,41 +159,48 @@
 	}
 }
 
-void SegManager::scriptInitialiseLocalsZero(SegmentId seg, int count) {
-	Script *scr = getScript(seg);
+void SegManager::scriptInitialiseLocals(SegmentId segmentId) {
+	Script *scr = getScript(segmentId);
+	uint16 count;
 
-	scr->_localsOffset = -count * 2; // Make sure it's invalid
+	if (getSciVersion() == SCI_VERSION_0_EARLY) {
+		// Old script block. There won't be a localvar block in this case.
+		// Instead, the script starts with a 16 bit int specifying the
+		// number of locals we need; these are then allocated and zeroed.
+		int localsCount = READ_LE_UINT16(scr->_buf);
+		if (localsCount) {
+			scr->_localsOffset = -localsCount * 2; // Make sure it's invalid
+			LocalVariables *locals = allocLocalsSegment(scr, localsCount);
+			if (locals) {
+				for (int i = 0; i < localsCount; i++)
+					locals->_locals[i] = NULL_REG;
+			}
+		}
 
-	LocalVariables *locals = allocLocalsSegment(scr, count);
-	if (locals) {
-		for (int i = 0; i < count; i++)
-			locals->_locals[i] = NULL_REG;
+		return;
 	}
-}
 
-void SegManager::scriptInitialiseLocals(reg_t location) {
-	Script *scr = getScript(location.segment);
-	unsigned int count;
+	// Check if the script actually has local variables
+	if (scr->_localsOffset == 0)
+		return;
 
-	VERIFY(location.offset + 1 < (uint16)scr->getBufSize(), "Locals beyond end of script\n");
+	VERIFY(scr->_localsOffset + 1 < (uint16)scr->getBufSize(), "Locals beyond end of script\n");
 
 	if (getSciVersion() >= SCI_VERSION_1_1)
-		count = READ_SCI11ENDIAN_UINT16(scr->_buf + location.offset - 2);
+		count = READ_SCI11ENDIAN_UINT16(scr->_buf + scr->_localsOffset - 2);
 	else
-		count = (READ_LE_UINT16(scr->_buf + location.offset - 2) - 4) >> 1;
+		count = (READ_LE_UINT16(scr->_buf + scr->_localsOffset - 2) - 4) >> 1;
 	// half block size
 
-	scr->_localsOffset = location.offset;
-
-	if (!(location.offset + count * 2 + 1 < scr->getBufSize())) {
-		warning("Locals extend beyond end of script: offset %04x, count %x vs size %x", location.offset, count, (uint)scr->getBufSize());
-		count = (scr->getBufSize() - location.offset) >> 1;
+	if (!(scr->_localsOffset + count * 2 + 1 < (uint16)scr->getBufSize())) {
+		warning("Locals extend beyond end of script: offset %04x, count %x vs size %x", scr->_localsOffset, count, (uint)scr->getBufSize());
+		count = (scr->getBufSize() - scr->_localsOffset) >> 1;
 	}
 
 	LocalVariables *locals = allocLocalsSegment(scr, count);
 	if (locals) {
 		uint i;
-		const byte *base = (const byte *)(scr->_buf + location.offset);
+		const byte *base = (const byte *)(scr->_buf + scr->_localsOffset);
 
 		for (i = 0; i < count; i++)
 			locals->_locals[i] = make_reg(0, READ_SCI11ENDIAN_UINT16(base + i * 2));
@@ -258,19 +265,8 @@
 	bool oldScriptHeader = (getSciVersion() == SCI_VERSION_0_EARLY);
 	uint16 curOffset = oldScriptHeader ? 2 : 0;
 
-	if (oldScriptHeader) {
-		// Old script block
-		// There won't be a localvar block in this case
-		// Instead, the script starts with a 16 bit int specifying the
-		// number of locals we need; these are then allocated and zeroed.
-		int localsCount = READ_LE_UINT16(scr->_buf);
-		if (localsCount)
-			segMan->scriptInitialiseLocalsZero(segmentId, localsCount);
-	}
+	// Now do a first pass through the script objects to find all the object classes
 
-	// Now do a first pass through the script objects to find the
-	// local variable blocks
-
 	do {
 		objType = scr->getHeap(curOffset);
 		if (!objType)
@@ -280,9 +276,6 @@
 		curOffset += 4;		// skip header
 
 		switch (objType) {
-		case SCI_OBJ_LOCALVARS:
-			segMan->scriptInitialiseLocals(make_reg(segmentId, 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);
@@ -365,10 +358,9 @@
 
 	scr->init(scriptNum, resMan);
 	scr->load(resMan);
+	segMan->scriptInitialiseLocals(segmentId);
 
 	if (getSciVersion() >= SCI_VERSION_1_1) {
-		int heapStart = scr->getScriptSize();
-		segMan->scriptInitialiseLocals(make_reg(segmentId, heapStart + 4));
 		segMan->scriptInitialiseObjectsSci11(segmentId);
 		scr->relocate(make_reg(segmentId, READ_SCI11ENDIAN_UINT16(scr->_heapStart)));
 	} else {

Modified: scummvm/trunk/engines/sci/engine/seg_manager.h
===================================================================
--- scummvm/trunk/engines/sci/engine/seg_manager.h	2010-06-13 22:01:10 UTC (rev 49639)
+++ scummvm/trunk/engines/sci/engine/seg_manager.h	2010-06-13 22:15:30 UTC (rev 49640)
@@ -146,18 +146,10 @@
 	// i.e. loading and linking.
 
 	/**
-	 * Initializes a script's local variable block
-	 * All variables are initialized to zero.
-	 * @param seg	Segment containing the script to initialize
-	 * @param nr	Number of local variables to allocate
-	 */
-	void scriptInitialiseLocalsZero(SegmentId seg, int nr);
-
-	/**
 	 * Initializes a script's local variable block according to a prototype
-	 * @param location	Location to initialize from
+	 * @param segmentId	Segment containing the script to initialize
 	 */
-	void scriptInitialiseLocals(reg_t location);
+	void scriptInitialiseLocals(SegmentId segmentId);
 
 	// 2. Clones
 

Modified: scummvm/trunk/engines/sci/engine/segment.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/segment.cpp	2010-06-13 22:01:10 UTC (rev 49639)
+++ scummvm/trunk/engines/sci/engine/segment.cpp	2010-06-13 22:15:30 UTC (rev 49640)
@@ -197,6 +197,7 @@
 		if (READ_LE_UINT16(_buf + 1 + 5) > 0) {
 			_exportTable = (const uint16 *)(_buf + 1 + 5 + 2);
 			_numExports = READ_SCI11ENDIAN_UINT16(_exportTable - 1);
+			_localsOffset = _scriptSize + 4;
 		}
 	} else {
 		_exportTable = (const uint16 *)findBlock(SCI_OBJ_EXPORTS);
@@ -209,6 +210,9 @@
 			_numSynonyms = READ_SCI11ENDIAN_UINT16(_synonyms + 2) / 4;
 			_synonyms += 4;	// skip header
 		}
+		const byte* localsBlock = findBlock(SCI_OBJ_LOCALVARS);
+		if (localsBlock)
+			_localsOffset = localsBlock - _buf + 4;
 	}
 }
 


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