diff options
-rw-r--r-- | engines/sci/engine/game.cpp | 30 | ||||
-rw-r--r-- | engines/sci/engine/kernel.cpp | 10 | ||||
-rw-r--r-- | engines/sci/engine/kernel.h | 23 | ||||
-rw-r--r-- | engines/sci/engine/vm.cpp | 6 | ||||
-rw-r--r-- | engines/sci/engine/vm.h | 8 | ||||
-rw-r--r-- | engines/sci/sci.cpp | 39 |
6 files changed, 41 insertions, 75 deletions
diff --git a/engines/sci/engine/game.cpp b/engines/sci/engine/game.cpp index 9e5b9b8990..704fe877c7 100644 --- a/engines/sci/engine/game.cpp +++ b/engines/sci/engine/game.cpp @@ -53,13 +53,21 @@ int game_init_sound(EngineState *s, int sound_flags, SciVersion soundVersion) { } #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 @@ int script_init_engine(EngineState *s) { 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; diff --git a/engines/sci/engine/kernel.cpp b/engines/sci/engine/kernel.cpp index 6ebee2dfbd..995ecc72a4 100644 --- a/engines/sci/engine/kernel.cpp +++ b/engines/sci/engine/kernel.cpp @@ -392,6 +392,7 @@ SciKernelFunction kfunct_mappers[] = { }; 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 @@ bool Kernel::signatureMatch(const char *sig, int argc, const reg_t *argv) { 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 @@ void Kernel::setDefaultKernelNames(Common::String gameId) { // 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 @@ void Kernel::setDefaultKernelNames(Common::String gameId) { } } -bool Kernel::loadKernelNames(Common::String gameId) { +void Kernel::loadKernelNames() { _kernelNames.clear(); #ifdef ENABLE_SCI32 @@ -757,10 +758,9 @@ bool Kernel::loadKernelNames(Common::String gameId) { setKernelNamesSci2(); else #endif - setDefaultKernelNames(gameId); + setDefaultKernelNames(); mapFunctions(); - return true; } Common::String Kernel::lookupText(reg_t address, int index) { diff --git a/engines/sci/engine/kernel.h b/engines/sci/engine/kernel.h index 8f8f34f74e..b79ba8caaa 100644 --- a/engines/sci/engine/kernel.h +++ b/engines/sci/engine/kernel.h @@ -156,17 +156,6 @@ public: 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 @@ public: 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 /** diff --git a/engines/sci/engine/vm.cpp b/engines/sci/engine/vm.cpp index 851f301a75..eb2824d9c7 100644 --- a/engines/sci/engine/vm.cpp +++ b/engines/sci/engine/vm.cpp @@ -1694,19 +1694,13 @@ void game_run(EngineState **_s) { 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; diff --git a/engines/sci/engine/vm.h b/engines/sci/engine/vm.h index 8c84587284..1764284dae 100644 --- a/engines/sci/engine/vm.h +++ b/engines/sci/engine/vm.h @@ -283,14 +283,6 @@ void run_vm(EngineState *s, bool restoring); 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 diff --git a/engines/sci/sci.cpp b/engines/sci/sci.cpp index b30665a59e..22c93c1de0 100644 --- a/engines/sci/sci.cpp +++ b/engines/sci/sci.cpp @@ -163,20 +163,19 @@ Common::Error SciEngine::run() { 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 @@ Common::Error SciEngine::run() { // 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,23 +196,19 @@ Common::Error SciEngine::run() { _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; - - _gamestate->abortScriptProcessing = kAbortNone; + // Add the after market GM patches for the specified game, if they exist + _resMan->addNewGMPatch(getGameID()); if (game_init(_gamestate)) { /* Initialize */ warning("Game initialization failed: Aborting..."); @@ -227,17 +216,13 @@ Common::Error SciEngine::run() { 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 @@ Common::Error SciEngine::run() { delete _gfxPorts; delete _gfxCache; delete _gfxPalette; - delete cursor; + delete _gfxCursor; delete _gfxScreen; delete _eventMan; delete segMan; |