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

thebluegr at users.sourceforge.net thebluegr at users.sourceforge.net
Mon Jun 28 01:20:08 CEST 2010


Revision: 50406
          http://scummvm.svn.sourceforge.net/scummvm/?rev=50406&view=rev
Author:   thebluegr
Date:     2010-06-27 23:20:08 +0000 (Sun, 27 Jun 2010)

Log Message:
-----------
SCI: Removed the hack for loading games from the launcher from run_vm(). This is now done on startup. This should fix loading from the launcher for LSL6

Modified Paths:
--------------
    scummvm/trunk/engines/sci/engine/selector.cpp
    scummvm/trunk/engines/sci/engine/selector.h
    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/sci.cpp

Modified: scummvm/trunk/engines/sci/engine/selector.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/selector.cpp	2010-06-27 21:41:30 UTC (rev 50405)
+++ scummvm/trunk/engines/sci/engine/selector.cpp	2010-06-27 23:20:08 UTC (rev 50406)
@@ -161,6 +161,7 @@
 	FIND_SELECTOR(maxScale);
 	FIND_SELECTOR(vanishingX);
 	FIND_SELECTOR(vanishingY);
+	FIND_SELECTOR(init);
 	FIND_SELECTOR(iconIndex);
 
 #ifdef ENABLE_SCI32

Modified: scummvm/trunk/engines/sci/engine/selector.h
===================================================================
--- scummvm/trunk/engines/sci/engine/selector.h	2010-06-27 21:41:30 UTC (rev 50405)
+++ scummvm/trunk/engines/sci/engine/selector.h	2010-06-27 23:20:08 UTC (rev 50406)
@@ -103,6 +103,8 @@
 	// perform
 	Selector moveDone;	///< used for DoBresen
 
+	Selector init;		///< Used for menu initialization when loading from the launcher
+
 	// SCI1 selectors which have been moved a bit in SCI1.1, but otherwise static
 	Selector cantBeHere; ///< Checks for movement avoidance in SCI1+. Replaces canBeHere
 	Selector topString; ///< SCI1 scroll lists use this instead of lsTop

Modified: scummvm/trunk/engines/sci/engine/state.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/state.cpp	2010-06-27 21:41:30 UTC (rev 50405)
+++ scummvm/trunk/engines/sci/engine/state.cpp	2010-06-27 23:20:08 UTC (rev 50406)
@@ -145,12 +145,14 @@
 }
 
 void EngineState::shrinkStackToBase() {
-	uint size = executionStackBase + 1;
-	assert(_executionStack.size() >= size);
-	Common::List<ExecStack>::iterator iter = _executionStack.begin();
-	for (uint i = 0; i < size; ++i)
-		++iter;
-	_executionStack.erase(iter, _executionStack.end());
+	if (_executionStack.size() > 0) {
+		uint size = executionStackBase + 1;
+		assert(_executionStack.size() >= size);
+		Common::List<ExecStack>::iterator iter = _executionStack.begin();
+		for (uint i = 0; i < size; ++i)
+			++iter;
+		_executionStack.erase(iter, _executionStack.end());
+	}
 }
 
 static kLanguage charToLanguage(const char c) {

Modified: scummvm/trunk/engines/sci/engine/state.h
===================================================================
--- scummvm/trunk/engines/sci/engine/state.h	2010-06-27 21:41:30 UTC (rev 50405)
+++ scummvm/trunk/engines/sci/engine/state.h	2010-06-27 23:20:08 UTC (rev 50406)
@@ -152,8 +152,6 @@
 	SegmentId variablesSegment[4];	///< Same as above, contains segment IDs
 	int variablesMax[4];		///< Max. values for all variables
 
-	int loadFromLauncher;
-
 	AbortGameState abortScriptProcessing;
 	bool gameWasRestarted;
 

Modified: scummvm/trunk/engines/sci/engine/vm.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/vm.cpp	2010-06-27 21:41:30 UTC (rev 50405)
+++ scummvm/trunk/engines/sci/engine/vm.cpp	2010-06-27 23:20:08 UTC (rev 50406)
@@ -758,48 +758,24 @@
 		xstack->selector = kernelFuncNr;
 		xstack->type = EXEC_STACK_TYPE_KERNEL;
 
-		//warning("callk %s", kernelFunc.origName.c_str());
+		// Call kernel function
+		s->r_acc = kernelFunc.func(s, argc, argv);
 
-		// TODO: SCI2.1 equivalent
-		if (s->loadFromLauncher >= 0 && (
-				(kernelFuncNr == 0x8 && getSciVersion() <= SCI_VERSION_1_1) ||     // DrawPic
-				(kernelFuncNr == 0x3d && getSciVersion() == SCI_VERSION_2)         // GetSaveDir
-				//(kernelFuncNum == 0x28 && getSciVersion() == SCI_VERSION_2_1)       // AddPlane
-				)) {
-
-				// A game is being loaded from the launcher, and the game is about to draw something on
-				// screen, hence all initialization has taken place (i.e. menus have been constructed etc).
-				// Therefore, inject a kRestoreGame call here, instead of the requested function.
-				// The restore call is injected here mainly for games which have a menu, as the menu is
-				// constructed when the game starts and is not reconstructed when a saved game is loaded.
-				int saveSlot = s->loadFromLauncher;
-				s->loadFromLauncher = -1;	// invalidate slot, so that we don't load again
-
-				if (saveSlot < 0)
-					error("Requested to load invalid save slot");	// should never happen, really
-
-				reg_t restoreArgv[2] = { NULL_REG, make_reg(0, saveSlot) };	// special call (argv[0] is NULL)
-				kRestoreGame(s, 2, restoreArgv);
-		} else {
-			// Call kernel function
-			s->r_acc = kernelFunc.func(s, argc, argv);
-
 #if 0
-			// Used for debugging
-			Common::String debugMsg = kernelFunc.origName +
-										Common::String::printf("[0x%x]", kernelFuncNum) +
-										Common::String::printf(", %d params: ", argc) +
-										" (";
+		// Used for debugging
+		Common::String debugMsg = kernelFunc.origName +
+									Common::String::printf("[0x%x]", kernelFuncNum) +
+									Common::String::printf(", %d params: ", argc) +
+									" (";
 
-			for (int i = 0; i < argc; i++) {
-				debugMsg +=  Common::String::printf("%04x:%04x", PRINT_REG(argv[i]));
-				debugMsg += (i == argc - 1 ? ")" : ", ");
-			}
+		for (int i = 0; i < argc; i++) {
+			debugMsg +=  Common::String::printf("%04x:%04x", PRINT_REG(argv[i]));
+			debugMsg += (i == argc - 1 ? ")" : ", ");
+		}
 
-			debugMsg += ", result: " + Common::String::printf("%04x:%04x", PRINT_REG(s->r_acc));
-			debug("%s", debugMsg.c_str());
+		debugMsg += ", result: " + Common::String::printf("%04x:%04x", PRINT_REG(s->r_acc));
+		debug("%s", debugMsg.c_str());
 #endif
-		}
 
 		// Remove callk stack frame again, if there's still an execution stack
 		if (s->_executionStack.begin() != s->_executionStack.end())

Modified: scummvm/trunk/engines/sci/sci.cpp
===================================================================
--- scummvm/trunk/engines/sci/sci.cpp	2010-06-27 21:41:30 UTC (rev 50405)
+++ scummvm/trunk/engines/sci/sci.cpp	2010-06-27 23:20:08 UTC (rev 50406)
@@ -306,9 +306,30 @@
 
 	// Check whether loading a savestate was requested
 	if (ConfMan.hasKey("save_slot")) {
-		_gamestate->loadFromLauncher = ConfMan.getInt("save_slot");
-	} else {
-		_gamestate->loadFromLauncher = -1;
+		reg_t restoreArgv[2] = { NULL_REG, make_reg(0, ConfMan.getInt("save_slot")) };	// special call (argv[0] is NULL)
+		kRestoreGame(_gamestate, 2, restoreArgv);
+
+		// Initialize the game menu, if there is one.
+		// This is not done when loading, so we must do it manually.
+		reg_t menuBarObj = _gamestate->_segMan->findObjectByName("MenuBar");
+		if (menuBarObj.isNull())
+			menuBarObj = _gamestate->_segMan->findObjectByName("menuBar");	// LSL6
+		if (!menuBarObj.isNull()) {
+			// Game menus are found in SCI0-SCI01 games (but not in demos), which had a selector vocabulary,
+			// thus the following code should always work (at least theoretically).
+			// The init selector is being moved around in all games, thus adding it to the list of static
+			// selectors can be tricky. An alternative way would be to call the first method of the
+			// MenuBar object (which is init), but this will require refactoring.
+			if (_kernel->_selectorCache.init != -1) {
+				// Reset abortScriptProcessing before initializing the game menu, so that the
+				// VM call performed by invokeSelector will actually run.
+				_gamestate->abortScriptProcessing = kAbortNone;
+				invokeSelector(_gamestate, menuBarObj, SELECTOR(init), 0, _gamestate->stack_base);
+				_gamestate->abortScriptProcessing = kAbortLoadGame;
+			} else {
+				warning("Game has a menu but not a selector vocabulary, skipping menu initialization");
+			}
+		}
 	}
 
 	runGame();


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