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

thebluegr at users.sourceforge.net thebluegr at users.sourceforge.net
Wed Jun 9 12:45:54 CEST 2010


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

Log Message:
-----------
Merged script_init_engine() and game_init() and cleaned up SciEngine::run() a bit

Modified Paths:
--------------
    scummvm/trunk/engines/sci/engine/game.cpp
    scummvm/trunk/engines/sci/engine/kernel.cpp
    scummvm/trunk/engines/sci/engine/kernel.h
    scummvm/trunk/engines/sci/engine/vm.cpp
    scummvm/trunk/engines/sci/engine/vm.h
    scummvm/trunk/engines/sci/sci.cpp

Modified: scummvm/trunk/engines/sci/engine/game.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/game.cpp	2010-06-09 09:17:48 UTC (rev 49536)
+++ scummvm/trunk/engines/sci/engine/game.cpp	2010-06-09 10:45:54 UTC (rev 49537)
@@ -53,13 +53,21 @@
 }
 #endif
 
-// Architectural stuff: Init/Unintialize engine
-int script_init_engine(EngineState *s) {
+/*************************************************************/
+/* Game instance stuff: Init/Unitialize state-dependant data */
+/*************************************************************/
+
+int game_init(EngineState *s) {
+	// FIXME Use new VM instantiation code all over the place
+	// Script 0 needs to be allocated here before anything else!
+	int script0Segment = s->_segMan->getScriptSegment(0, SCRIPT_GET_LOCK);
+	DataStack *stack = s->_segMan->allocateStack(VM_STACK_SIZE, NULL);
+
 	s->_msgState = new MessageState(s->_segMan);
 	s->gc_countdown = GC_INTERVAL - 1;
 
 	// Script 0 should always be at segment 1
-	if (s->_segMan->getScriptSegment(0, SCRIPT_GET_LOCK) != 1) {
+	if (script0Segment != 1) {
 		debug(2, "Failed to instantiate script.000");
 		return 1;
 	}
@@ -72,23 +80,11 @@
 
 	s->_executionStack.clear();    // Start without any execution stack
 	s->execution_stack_base = -1; // No vm is running yet
+	s->_executionStackPosChanged = false;
 
+	s->abortScriptProcessing = kAbortNone;
 	s->gameWasRestarted = false;
 
-	debug(2, "Engine initialized");
-
-	return 0;
-}
-
-/*************************************************************/
-/* Game instance stuff: Init/Unitialize state-dependant data */
-/*************************************************************/
-
-int game_init(EngineState *s) {
-	// FIXME Use new VM instantiation code all over the place
-	DataStack *stack;
-
-	stack = s->_segMan->allocateStack(VM_STACK_SIZE, NULL);
 	s->stack_base = stack->_entries;
 	s->stack_top = stack->_entries + stack->_capacity;
 

Modified: scummvm/trunk/engines/sci/engine/kernel.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/kernel.cpp	2010-06-09 09:17:48 UTC (rev 49536)
+++ scummvm/trunk/engines/sci/engine/kernel.cpp	2010-06-09 10:45:54 UTC (rev 49537)
@@ -392,6 +392,7 @@
 };
 
 Kernel::Kernel(ResourceManager *resMan, SegManager *segMan) : _resMan(resMan), _segMan(segMan) {
+	loadKernelNames();
 	loadSelectorNames();
 	mapSelectors();      // Map a few special selectors for later use
 }
@@ -691,7 +692,7 @@
 	return false;
 }
 
-void Kernel::setDefaultKernelNames(Common::String gameId) {
+void Kernel::setDefaultKernelNames() {
 	_kernelNames = Common::StringArray(sci_default_knames, SCI_KNAMES_DEFAULT_ENTRIES_NR);
 
 	// Some (later) SCI versions replaced CanBeHere by CantBeHere
@@ -730,7 +731,7 @@
 		// In KQ6 CD, the empty kSetSynonyms function has been replaced
 		// with kPortrait. In KQ6 Mac, kPlayBack has been replaced by
 		// kShowMovie.
-		if (gameId == "kq6") {
+		if (!strcmp(g_sci->getGameID(), "kq6")) {
 			if (g_sci->getPlatform() == Common::kPlatformMacintosh)
 				_kernelNames[0x84] = "ShowMovie";
 			else
@@ -747,7 +748,7 @@
 	}
 }
 
-bool Kernel::loadKernelNames(Common::String gameId) {
+void Kernel::loadKernelNames() {
 	_kernelNames.clear();
 
 #ifdef ENABLE_SCI32
@@ -757,10 +758,9 @@
 		setKernelNamesSci2();
 	else
 #endif
-		setDefaultKernelNames(gameId);
+		setDefaultKernelNames();
 
 	mapFunctions();
-	return true;
 }
 
 Common::String Kernel::lookupText(reg_t address, int index) {

Modified: scummvm/trunk/engines/sci/engine/kernel.h
===================================================================
--- scummvm/trunk/engines/sci/engine/kernel.h	2010-06-09 09:17:48 UTC (rev 49536)
+++ scummvm/trunk/engines/sci/engine/kernel.h	2010-06-09 10:45:54 UTC (rev 49537)
@@ -156,17 +156,6 @@
 	const Common::String &getKernelName(uint number) const;
 
 	/**
-	 * Loads the kernel function names.
-	 *
-	 * This function reads the kernel function name table from resource_map,
-	 * and fills the _kernelNames array with them.
-	 * The resulting list has the same format regardless of the format of the
-	 * name table of the resource (the format changed between version 0 and 1).
-	 * @return true on success, false on failure
-	 */
-	bool loadKernelNames(Common::String gameId);
-
-	/**
 	 * Determines the selector ID of a selector by its name
 	 * @param selectorName Name of the selector to look up
 	 * @return The appropriate selector ID, or -1 on error
@@ -220,9 +209,19 @@
 
 private:
 	/**
+	 * Loads the kernel function names.
+	 *
+	 * This function reads the kernel function name table from resource_map,
+	 * and fills the _kernelNames array with them.
+	 * The resulting list has the same format regardless of the format of the
+	 * name table of the resource (the format changed between version 0 and 1).
+	 */
+	void loadKernelNames();
+
+	/**
 	 * Sets the default kernel function names, based on the SCI version used
 	 */
-	void setDefaultKernelNames(Common::String gameId);
+	void setDefaultKernelNames();
 
 #ifdef ENABLE_SCI32
 	/**

Modified: scummvm/trunk/engines/sci/engine/vm.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/vm.cpp	2010-06-09 09:17:48 UTC (rev 49536)
+++ scummvm/trunk/engines/sci/engine/vm.cpp	2010-06-09 10:45:54 UTC (rev 49537)
@@ -1694,19 +1694,13 @@
 		game_exit(s);
 
 		if (s->abortScriptProcessing == kAbortRestartGame) {
-			s->abortScriptProcessing = kAbortNone;
-			s->_executionStackPosChanged = false;
-
 			s->_segMan->resetSegMan();
-			script_init_engine(s);
 			game_init(s);
 #ifdef USE_OLD_MUSIC_FUNCTIONS
 			s->_sound.sfx_reset_player();
 #endif
 			_init_stack_base_with_selector(s, g_sci->getKernel()->_selectorCache.play);
-
 			send_selector(s, s->_gameObj, s->_gameObj, s->stack_base, 2, s->stack_base);
-
 			s->gameWasRestarted = true;
 		} else if (s->abortScriptProcessing == kAbortLoadGame) {
 			s->abortScriptProcessing = kAbortNone;

Modified: scummvm/trunk/engines/sci/engine/vm.h
===================================================================
--- scummvm/trunk/engines/sci/engine/vm.h	2010-06-09 09:17:48 UTC (rev 49536)
+++ scummvm/trunk/engines/sci/engine/vm.h	2010-06-09 10:45:54 UTC (rev 49537)
@@ -283,14 +283,6 @@
 void script_debug(EngineState *s);
 
 /**
- * Initializes a EngineState block
- * @param[in] s	The state to initialize
- * @return		0 on success, 1 if vocab.996 (the class table) is missing
- * 				or corrupted
- */
-int script_init_engine(EngineState *);
-
-/**
  * Looks up a selector and returns its type and value
  * varindex is written to iff it is non-NULL and the selector indicates a property of the object.
  * @param[in] segMan		The Segment Manager

Modified: scummvm/trunk/engines/sci/sci.cpp
===================================================================
--- scummvm/trunk/engines/sci/sci.cpp	2010-06-09 09:17:48 UTC (rev 49536)
+++ scummvm/trunk/engines/sci/sci.cpp	2010-06-09 10:45:54 UTC (rev 49537)
@@ -163,20 +163,19 @@
 		upscaledHires = GFX_SCREEN_UPSCALED_640x400;
 
 	// Initialize graphics-related parts
-	GfxScreen *screen = 0;
 
 	// invokes initGraphics()
 	if (_resMan->detectHires())
-		screen = new GfxScreen(_resMan, 640, 480);
+		_gfxScreen = new GfxScreen(_resMan, 640, 480);
 	else
-		screen = new GfxScreen(_resMan, 320, 200, upscaledHires);
+		_gfxScreen = new GfxScreen(_resMan, 320, 200, upscaledHires);
 
 	if (_resMan->isSci11Mac() && getSciVersion() == SCI_VERSION_1_1)
 		_gfxMacIconBar = new GfxMacIconBar();
 
-	GfxPalette *palette = new GfxPalette(_resMan, screen);
-	GfxCache *cache = new GfxCache(_resMan, screen, palette);
-	GfxCursor *cursor = new GfxCursor(_resMan, palette, screen);
+	_gfxPalette = new GfxPalette(_resMan, _gfxScreen);
+	_gfxCache = new GfxCache(_resMan, _gfxScreen, _gfxPalette);
+	_gfxCursor = new GfxCursor(_resMan, _gfxPalette, _gfxScreen);
 
 	// Create debugger console. It requires GFX to be initialized
 	_console = new Console(this);
@@ -185,16 +184,10 @@
 	// Only SCI0 and SCI01 games used a parser
 	_vocabulary = (getSciVersion() <= SCI_VERSION_1_EGA) ? new Vocabulary(_resMan) : NULL;
 	_audio = new AudioPlayer(_resMan);
-
 	_features = new GameFeatures(segMan, _kernel);
-
 	_gamestate = new EngineState(segMan);
-
 	_eventMan = new EventManager(_resMan);
 
-	if (script_init_engine(_gamestate))
-		return Common::kUnknownError;
-
 #ifdef ENABLE_SCI32
 	if (getSciVersion() >= SCI_VERSION_2) {
 		_gfxAnimate = 0;
@@ -203,41 +196,33 @@
 		_gfxPaint16 = 0;
 		_gfxPorts = 0;
 		_gui = 0;
-		_gui32 = new SciGui32(_gamestate->_segMan, _eventMan, screen, palette, cache, cursor);
+		_gui32 = new SciGui32(_gamestate->_segMan, _eventMan, _gfxScreen, _gfxPalette, _gfxCache, _gfxCursor);
 	} else {
 #endif
-		_gfxPorts = new GfxPorts(segMan, screen);
-		_gui = new SciGui(_gamestate, screen, palette, cache, cursor, _gfxPorts, _audio);
+		_gfxPorts = new GfxPorts(segMan, _gfxScreen);
+		_gui = new SciGui(_gamestate, _gfxScreen, _gfxPalette, _gfxCache, _gfxCursor, _gfxPorts, _audio);
 #ifdef ENABLE_SCI32
 		_gui32 = 0;
 		_gfxFrameout = 0;
 	}
 #endif
 
-	_gfxPalette = palette;
-	_gfxScreen = screen;
-	_gfxCache = cache;
-	_gfxCursor = cursor;
+	// Add the after market GM patches for the specified game, if they exist
+	_resMan->addNewGMPatch(getGameID());
 
-	_gamestate->abortScriptProcessing = kAbortNone;
-
 	if (game_init(_gamestate)) { /* Initialize */
 		warning("Game initialization failed: Aborting...");
 		// TODO: Add an "init failed" error?
 		return Common::kUnknownError;
 	}
 
-	// Add the after market GM patches for the specified game, if they exist
-	_resMan->addNewGMPatch(getGameID());
-
 	script_adjust_opcode_formats(_gamestate);
-	_kernel->loadKernelNames(getGameID());
 
 	SciVersion soundVersion = _features->detectDoSoundType();
 
 	_gamestate->_soundCmd = new SoundCommandParser(_resMan, segMan, _kernel, _audio, soundVersion);
 
-	screen->debugUnditherSetState(ConfMan.getBool("undither"));
+	_gfxScreen->debugUnditherSetState(ConfMan.getBool("undither"));
 
 #ifdef USE_OLD_MUSIC_FUNCTIONS
 	if (game_init_sound(_gamestate, 0, soundVersion)) {
@@ -278,7 +263,7 @@
 	delete _gfxPorts;
 	delete _gfxCache;
 	delete _gfxPalette;
-	delete cursor;
+	delete _gfxCursor;
 	delete _gfxScreen;
 	delete _eventMan;
 	delete segMan;


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