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

thebluegr at users.sourceforge.net thebluegr at users.sourceforge.net
Wed Jun 9 11:17:49 CEST 2010


Revision: 49536
          http://scummvm.svn.sourceforge.net/scummvm/?rev=49536&view=rev
Author:   thebluegr
Date:     2010-06-09 09:17:48 +0000 (Wed, 09 Jun 2010)

Log Message:
-----------
Globals from script 0 are now initialized in script_init_engine(), and are accessed from the relevant variables pointer. Removed direct reference to script 0 from the engine state

Modified Paths:
--------------
    scummvm/trunk/engines/sci/engine/game.cpp
    scummvm/trunk/engines/sci/engine/savegame.cpp
    scummvm/trunk/engines/sci/engine/state.cpp
    scummvm/trunk/engines/sci/engine/state.h
    scummvm/trunk/engines/sci/engine/vm.cpp
    scummvm/trunk/engines/sci/graphics/animate.cpp

Modified: scummvm/trunk/engines/sci/engine/game.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/game.cpp	2010-06-09 08:49:37 UTC (rev 49535)
+++ scummvm/trunk/engines/sci/engine/game.cpp	2010-06-09 09:17:48 UTC (rev 49536)
@@ -58,14 +58,13 @@
 	s->_msgState = new MessageState(s->_segMan);
 	s->gc_countdown = GC_INTERVAL - 1;
 
-	SegmentId script_000_segment = s->_segMan->getScriptSegment(0, SCRIPT_GET_LOCK);
-
-	if (script_000_segment <= 0) {
+	// Script 0 should always be at segment 1
+	if (s->_segMan->getScriptSegment(0, SCRIPT_GET_LOCK) != 1) {
 		debug(2, "Failed to instantiate script.000");
 		return 1;
 	}
 
-	s->script_000 = s->_segMan->getScript(script_000_segment);
+	s->initGlobals();
 
 	s->_segMan->initSysStrings();
 

Modified: scummvm/trunk/engines/sci/engine/savegame.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/savegame.cpp	2010-06-09 08:49:37 UTC (rev 49535)
+++ scummvm/trunk/engines/sci/engine/savegame.cpp	2010-06-09 09:17:48 UTC (rev 49536)
@@ -870,7 +870,7 @@
 	s->_segMan->reconstructStack(s);
 	s->_segMan->reconstructScripts(s);
 	s->_segMan->reconstructClones();
-	s->script_000 = s->_segMan->getScript(s->_segMan->getScriptSegment(0, SCRIPT_GET_DONT_LOAD));
+	s->initGlobals();
 	s->gc_countdown = GC_INTERVAL - 1;
 
 	// Time state:

Modified: scummvm/trunk/engines/sci/engine/state.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/state.cpp	2010-06-09 08:49:37 UTC (rev 49535)
+++ scummvm/trunk/engines/sci/engine/state.cpp	2010-06-09 09:17:48 UTC (rev 49536)
@@ -85,7 +85,6 @@
 #endif
 
 	if (!isRestoring) {
-		script_000 = 0;
 		_gameObj = NULL_REG;
 
 		_memorySegmentSize = 0;
@@ -127,12 +126,23 @@
 	g_sci->getEventManager()->sleep(ticks * 1000 / 60);
 }
 
+void EngineState::initGlobals() {
+	Script *script_000 = _segMan->getScript(1);
+	
+	if (!script_000->_localsBlock)
+		error("Script 0 has no locals block");
+
+	variables_seg[VAR_GLOBAL] = script_000->_localsSegment;
+	variables_base[VAR_GLOBAL] = variables[VAR_GLOBAL] = script_000->_localsBlock->_locals.begin();
+	variables_max[VAR_GLOBAL] = script_000->_localsBlock->_locals.size();
+}
+
 uint16 EngineState::currentRoomNumber() const {
-	return script_000->_localsBlock->_locals[13].toUint16();
+	return variables[VAR_GLOBAL][13].toUint16();
 }
 
 void EngineState::setRoomNumber(uint16 roomNumber) {
-	script_000->_localsBlock->_locals[13] = make_reg(0, roomNumber);
+	variables[VAR_GLOBAL][13] = make_reg(0, roomNumber);
 }
 
 void EngineState::shrinkStackToBase() {

Modified: scummvm/trunk/engines/sci/engine/state.h
===================================================================
--- scummvm/trunk/engines/sci/engine/state.h	2010-06-09 08:49:37 UTC (rev 49535)
+++ scummvm/trunk/engines/sci/engine/state.h	2010-06-09 09:17:48 UTC (rev 49536)
@@ -79,13 +79,6 @@
 	MAX_SAVE_DIR_SIZE = MAXPATHLEN
 };
 
-/** values for EngineState.restarting_flag */
-enum {
-	SCI_GAME_IS_NOT_RESTARTING = 0,
-	SCI_GAME_WAS_RESTARTED = 1,
-	SCI_GAME_IS_RESTARTING_NOW = 2
-};
-
 class FileHandle {
 public:
 	Common::String _name;
@@ -145,7 +138,7 @@
 	bool _executionStackPosChanged;   /**< Set to true if the execution stack position should be re-evaluated by the vm */
 
 	reg_t r_acc; /**< Accumulator */
-	int16 restAdjust; /**< current &rest register (only used for save games) */
+	int16 restAdjust; /**< current &rest register */
 	reg_t r_prev; /**< previous comparison result */
 
 	StackPtr stack_base; /**< Pointer to the least stack element */
@@ -158,8 +151,6 @@
 	SegmentId variables_seg[4];	///< Same as above, contains segment IDs
 	int variables_max[4];		///< Max. values for all variables
 
-	Script *script_000;  /**< script 000, e.g. for globals */
-
 	int loadFromLauncher;
 
 	AbortGameState abortScriptProcessing;
@@ -172,6 +163,11 @@
 	void setRoomNumber(uint16 roomNumber);
 
 	/**
+	 * Sets global variables from script 0
+	 */
+	void initGlobals();
+
+	/**
 	 * Shrink execution stack to size.
 	 * Contains an assert it is not already smaller.
 	 */

Modified: scummvm/trunk/engines/sci/engine/vm.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/vm.cpp	2010-06-09 08:49:37 UTC (rev 49535)
+++ scummvm/trunk/engines/sci/engine/vm.cpp	2010-06-09 09:17:48 UTC (rev 49536)
@@ -736,24 +736,9 @@
 	if (!restoring)
 		s->execution_stack_base = s->_executionStack.size() - 1;
 
-#ifndef DISABLE_VALIDATIONS
-	// Initialize maximum variable count
-	if (s->script_000->_localsBlock)
-		s->variables_max[VAR_GLOBAL] = s->script_000->_localsBlock->_locals.size();
-	else
-		s->variables_max[VAR_GLOBAL] = 0;
-#endif
-
-	s->variables_seg[VAR_GLOBAL] = s->script_000->_localsSegment;
 	s->variables_seg[VAR_TEMP] = s->variables_seg[VAR_PARAM] = s->_segMan->findSegmentByType(SEG_TYPE_STACK);
 	s->variables_base[VAR_TEMP] = s->variables_base[VAR_PARAM] = s->stack_base;
 
-	// SCI code reads the zeroth argument to determine argc
-	if (s->script_000->_localsBlock)
-		s->variables_base[VAR_GLOBAL] = s->variables[VAR_GLOBAL] = s->script_000->_localsBlock->_locals.begin();
-	else
-		s->variables_base[VAR_GLOBAL] = s->variables[VAR_GLOBAL] = NULL;
-
 	s->_executionStackPosChanged = true; // Force initialization
 
 	while (1) {

Modified: scummvm/trunk/engines/sci/graphics/animate.cpp
===================================================================
--- scummvm/trunk/engines/sci/graphics/animate.cpp	2010-06-09 08:49:37 UTC (rev 49535)
+++ scummvm/trunk/engines/sci/graphics/animate.cpp	2010-06-09 09:17:48 UTC (rev 49536)
@@ -84,10 +84,8 @@
 		if (!_ignoreFastCast) {
 			// Check if the game has a fastCast object set
 			//  if we don't abort kAnimate processing, at least in kq5 there will be animation cels drawn into speech boxes.
-			reg_t global84 = _s->script_000->_localsBlock->_locals[84];
-
-			if (!global84.isNull()) {
-				if (!strcmp(_s->_segMan->getObjectName(global84), "fastCast"))
+			if (!_s->variables[VAR_GLOBAL][84].isNull()) {
+				if (!strcmp(_s->_segMan->getObjectName(_s->variables[VAR_GLOBAL][84]), "fastCast"))
 					return false;
 			}
 		}


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