diff options
-rw-r--r-- | engines/sci/console.cpp | 7 | ||||
-rw-r--r-- | engines/sci/engine/game.cpp | 8 | ||||
-rw-r--r-- | engines/sci/engine/kevent.cpp | 2 | ||||
-rw-r--r-- | engines/sci/engine/kmisc.cpp | 8 | ||||
-rw-r--r-- | engines/sci/engine/savegame.cpp | 6 | ||||
-rw-r--r-- | engines/sci/engine/state.cpp | 6 | ||||
-rw-r--r-- | engines/sci/engine/state.h | 20 | ||||
-rw-r--r-- | engines/sci/engine/vm.cpp | 34 | ||||
-rw-r--r-- | engines/sci/sci.cpp | 4 |
9 files changed, 37 insertions, 58 deletions
diff --git a/engines/sci/console.cpp b/engines/sci/console.cpp index 814fbff636..e7c70a2aed 100644 --- a/engines/sci/console.cpp +++ b/engines/sci/console.cpp @@ -78,7 +78,7 @@ Console::Console(SciEngine *engine) : GUI::Debugger() { DVar_Register("gc_interval", &engine->_gamestate->script_gc_interval, DVAR_INT, 0); DVar_Register("simulated_key", &g_debug_simulated_key, DVAR_INT, 0); DVar_Register("track_mouse_clicks", &g_debug_track_mouse_clicks, DVAR_BOOL, 0); - DVar_Register("script_abort_flag", &_engine->_gamestate->script_abort_flag, DVAR_INT, 0); + DVar_Register("script_abort_flag", &_engine->_gamestate->abortScriptProcessing, DVAR_INT, 0); // General DCmd_Register("help", WRAP_METHOD(Console, cmdHelp)); @@ -957,8 +957,7 @@ bool Console::cmdRestoreGame(int argc, const char **argv) { } bool Console::cmdRestartGame(int argc, const char **argv) { - _engine->_gamestate->restarting_flags |= SCI_GAME_IS_RESTARTING_NOW; - _engine->_gamestate->script_abort_flag = 1; + _engine->_gamestate->abortScriptProcessing = kAbortRestartGame;; return false; } @@ -2731,7 +2730,7 @@ bool Console::cmdQuit(int argc, const char **argv) { if (!scumm_stricmp(argv[1], "game")) { // Quit gracefully - _engine->_gamestate->script_abort_flag = 1; // Terminate VM + _engine->_gamestate->abortScriptProcessing = kAbortQuitGame; // Terminate VM g_debugState.seeking = kDebugSeekNothing; g_debugState.runningStep = 0; diff --git a/engines/sci/engine/game.cpp b/engines/sci/engine/game.cpp index bc10099e52..5fa1fc0558 100644 --- a/engines/sci/engine/game.cpp +++ b/engines/sci/engine/game.cpp @@ -75,7 +75,7 @@ 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->restarting_flags = SCI_GAME_IS_NOT_RESTARTING; + s->gameWasRestarted = false; debug(2, "Engine initialized"); @@ -111,8 +111,6 @@ int game_init(EngineState *s) { if (g_sci->_gfxMenu) g_sci->_gfxMenu->reset(); - s->restoring = false; - s->game_start_time = g_system->getMillis(); s->last_wait_time = s->game_start_time; @@ -134,7 +132,7 @@ int game_init(EngineState *s) { } int game_exit(EngineState *s) { - if (!s->restoring) { + if (s->abortScriptProcessing != kAbortLoadGame) { s->_executionStack.clear(); #ifdef USE_OLD_MUSIC_FUNCTIONS s->_sound.sfx_exit(); @@ -152,7 +150,7 @@ int game_exit(EngineState *s) { // the segment manager has already been initialized from the // save game. Deleting or resetting it here will result in // invalidating the loaded save state - if (s->restarting_flags & SCI_GAME_IS_RESTARTING_NOW) + if (s->abortScriptProcessing == kAbortRestartGame) s->_segMan->resetSegMan(); // TODO Free parser segment here diff --git a/engines/sci/engine/kevent.cpp b/engines/sci/engine/kevent.cpp index 519a4bcc8f..4b4d605c68 100644 --- a/engines/sci/engine/kevent.cpp +++ b/engines/sci/engine/kevent.cpp @@ -79,7 +79,7 @@ reg_t kGetEvent(EngineState *s, int argc, reg_t *argv) { switch (curEvent.type) { case SCI_EVENT_QUIT: - s->script_abort_flag = 1; // Terminate VM + s->abortScriptProcessing = kAbortQuitGame; // Terminate VM g_debugState.seeking = kDebugSeekNothing; g_debugState.runningStep = 0; break; diff --git a/engines/sci/engine/kmisc.cpp b/engines/sci/engine/kmisc.cpp index f91ba0fd82..d90255ab41 100644 --- a/engines/sci/engine/kmisc.cpp +++ b/engines/sci/engine/kmisc.cpp @@ -37,11 +37,9 @@ namespace Sci { reg_t kRestartGame(EngineState *s, int argc, reg_t *argv) { - s->restarting_flags |= SCI_GAME_IS_RESTARTING_NOW; - s->shrinkStackToBase(); - s->script_abort_flag = 1; // Force vm to abort ASAP + s->abortScriptProcessing = kAbortRestartGame; // Force vm to abort ASAP return NULL_REG; } @@ -49,11 +47,11 @@ reg_t kRestartGame(EngineState *s, int argc, reg_t *argv) { ** Returns the restarting_flag in acc */ reg_t kGameIsRestarting(EngineState *s, int argc, reg_t *argv) { - s->r_acc = make_reg(0, (s->restarting_flags & SCI_GAME_WAS_RESTARTED)); + s->r_acc = make_reg(0, s->gameWasRestarted); if (argc) { // Only happens during replay if (!argv[0].toUint16()) // Set restarting flag - s->restarting_flags &= ~SCI_GAME_WAS_RESTARTED; + s->gameWasRestarted = false; } uint32 neededSleep = 30; diff --git a/engines/sci/engine/savegame.cpp b/engines/sci/engine/savegame.cpp index 835ae5b966..d6111146bd 100644 --- a/engines/sci/engine/savegame.cpp +++ b/engines/sci/engine/savegame.cpp @@ -880,8 +880,6 @@ void gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) { s->last_wait_time = g_system->getMillis(); s->game_start_time = g_system->getMillis(); - s->restoring = false; - #ifdef USE_OLD_MUSIC_FUNCTIONS s->_sound._it = NULL; s->_sound._flags = s->_sound._flags; @@ -906,9 +904,7 @@ void gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) { } #endif - - s->restoring = true; - s->script_abort_flag = 2; // Abort current game with replay + s->abortScriptProcessing = kAbortLoadGame; s->shrinkStackToBase(); } diff --git a/engines/sci/engine/state.cpp b/engines/sci/engine/state.cpp index b4a04f8826..849f1f3c89 100644 --- a/engines/sci/engine/state.cpp +++ b/engines/sci/engine/state.cpp @@ -91,8 +91,6 @@ void EngineState::reset(bool isRestoring) { _memorySegmentSize = 0; _soundCmd = 0; - restarting_flags = 0; - execution_stack_base = 0; _executionStackPosChanged = false; @@ -104,6 +102,7 @@ void EngineState::reset(bool isRestoring) { stack_base = 0; stack_top = 0; + abortScriptProcessing = kAbortNone; } last_wait_time = 0; @@ -114,11 +113,8 @@ void EngineState::reset(bool isRestoring) { _throttleLastTime = 0; _throttleTrigger = false; - script_abort_flag = 0; script_step_counter = 0; script_gc_interval = GC_INTERVAL; - - restoring = false; } void EngineState::wait(int16 ticks) { diff --git a/engines/sci/engine/state.h b/engines/sci/engine/state.h index bcdf66d6ef..6b7dc54a24 100644 --- a/engines/sci/engine/state.h +++ b/engines/sci/engine/state.h @@ -52,6 +52,13 @@ class SciEvent; class MessageState; class SoundCommandParser; +enum AbortGameState { + kAbortNone = 0, + kAbortLoadGame = 1, + kAbortRestartGame = 2, + kAbortQuitGame = 3 +}; + class DirSeeker { protected: reg_t _outbuffer; @@ -113,8 +120,6 @@ public: #endif SoundCommandParser *_soundCmd; - byte restarting_flags; /**< Flags used for restarting */ - uint32 game_start_time; /**< The time at which the interpreter was started */ uint32 last_wait_time; /**< The last time the game invoked Wait() */ @@ -160,12 +165,9 @@ public: int loadFromLauncher; - /** - * Set this to 1 to abort script execution immediately. Aborting will - * leave the debug exec stack intact. - * Set it to 2 to force a replay afterwards. - */ - int script_abort_flag; // Set to 1 to abort execution. Set to 2 to force a replay afterwards + AbortGameState abortScriptProcessing; + bool gameWasRestarted; + int script_step_counter; // Counts the number of steps executed int script_gc_interval; // Number of steps in between gcs @@ -197,8 +199,6 @@ public: * Resets the engine state. */ void reset(bool isRestoring); - - bool restoring; /**< A flag to indicate if a game is being restored */ }; } // End of namespace Sci diff --git a/engines/sci/engine/vm.cpp b/engines/sci/engine/vm.cpp index 9ee2db71b4..5cb333db3c 100644 --- a/engines/sci/engine/vm.cpp +++ b/engines/sci/engine/vm.cpp @@ -816,7 +816,7 @@ void run_vm(EngineState *s, bool restoring) { } - if (s->script_abort_flag || g_engine->shouldQuit()) + if (s->abortScriptProcessing != kAbortNone || g_engine->shouldQuit()) return; // Emergency // Debug if this has been requested: @@ -1708,14 +1708,14 @@ void game_run(EngineState **_s) { do { s->_executionStackPosChanged = false; - run_vm(s, s->restoring); + run_vm(s, (s->abortScriptProcessing == kAbortLoadGame)); + game_exit(s); - if (s->restarting_flags & SCI_GAME_IS_RESTARTING_NOW) { // Restart was requested? - s->restoring = false; + if (s->abortScriptProcessing == kAbortRestartGame) { + s->abortScriptProcessing = kAbortNone; s->_executionStack.clear(); s->_executionStackPosChanged = false; - game_exit(s); script_init_engine(s); game_init(s); #ifdef USE_OLD_MUSIC_FUNCTIONS @@ -1725,24 +1725,16 @@ void game_run(EngineState **_s) { send_selector(s, s->_gameObj, s->_gameObj, s->stack_base, 2, s->stack_base); - s->script_abort_flag = 0; - s->restarting_flags = SCI_GAME_WAS_RESTARTED; + s->gameWasRestarted = true; } else { - if (s->restoring) { - game_exit(s); - s->restoring = false; - if (s->script_abort_flag == 2) { - debugC(2, kDebugLevelVM, "Restarting with replay()"); - s->_executionStack.clear(); // Restart with replay - - _init_stack_base_with_selector(s, g_sci->getKernel()->_selectorCache.replay); - - send_selector(s, s->_gameObj, s->_gameObj, s->stack_base, 2, s->stack_base); - } - - s->script_abort_flag = 0; - + if (s->abortScriptProcessing == kAbortLoadGame) { + s->abortScriptProcessing = kAbortNone; + debugC(2, kDebugLevelVM, "Restarting with replay()"); + s->_executionStack.clear(); + // Restart with replay + _init_stack_base_with_selector(s, g_sci->getKernel()->_selectorCache.replay); + send_selector(s, s->_gameObj, s->_gameObj, s->stack_base, 2, s->stack_base); } else break; // exit loop } diff --git a/engines/sci/sci.cpp b/engines/sci/sci.cpp index 929bdf3307..8d23d5481c 100644 --- a/engines/sci/sci.cpp +++ b/engines/sci/sci.cpp @@ -219,6 +219,8 @@ Common::Error SciEngine::run() { _gfxCache = cache; _gfxCursor = cursor; + _gamestate->abortScriptProcessing = kAbortNone; + if (game_init(_gamestate)) { /* Initialize */ warning("Game initialization failed: Aborting..."); // TODO: Add an "init failed" error? @@ -264,8 +266,6 @@ Common::Error SciEngine::run() { game_run(&_gamestate); // Run the game - game_exit(_gamestate); - ConfMan.flushToDisk(); delete _gamestate->_soundCmd; |