From 317da8756e1d350167739d82b128fc5fcd70687e Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Wed, 3 Jun 2009 14:09:25 +0000 Subject: - Moved the engine state and the console to be private members of SciEngine - Implemented pauseEngineIntern() - Music now stops and resumes when entering/leaving the debugger svn-id: r41139 --- engines/sci/console.cpp | 13 ++++++++-- engines/sci/console.h | 2 ++ engines/sci/engine/grammar.cpp | 4 +-- engines/sci/engine/kevent.cpp | 2 +- engines/sci/gfx/operations.cpp | 4 +-- engines/sci/sci.cpp | 59 +++++++++++++++++++++--------------------- engines/sci/sci.h | 4 +-- engines/sci/tools.cpp | 2 +- engines/sci/vocabulary.cpp | 4 +-- 9 files changed, 52 insertions(+), 42 deletions(-) (limited to 'engines/sci') diff --git a/engines/sci/console.cpp b/engines/sci/console.cpp index 236f01bb51..59477ce710 100644 --- a/engines/sci/console.cpp +++ b/engines/sci/console.cpp @@ -169,6 +169,16 @@ Console::Console(SciEngine *vm) : GUI::Debugger() { Console::~Console() { } +void Console::preEnter() { + g_EngineState->_sound.sfx_suspend(true); + _vm->_mixer->pauseAll(true); +} + +void Console::postEnter() { + g_EngineState->_sound.sfx_suspend(false); + _vm->_mixer->pauseAll(false); +} + bool Console::cmdHelp(int argc, const char **argv) { DebugPrintf("\n"); DebugPrintf("Variables\n"); @@ -1408,10 +1418,9 @@ bool Console::cmdGCObjects(int argc, const char **argv) { return true; } -// TODO/FIXME: This should be using DebugPrintf void _print_address(void * _, reg_t addr) { if (addr.segment) - sciprintf(" %04x:%04x\n", PRINT_REG(addr)); + ((SciEngine *)g_engine)->getDebugger()->DebugPrintf(" %04x:%04x\n", PRINT_REG(addr)); } bool Console::cmdGCShowReachable(int argc, const char **argv) { diff --git a/engines/sci/console.h b/engines/sci/console.h index 4b4b8e618c..edd58f1f90 100644 --- a/engines/sci/console.h +++ b/engines/sci/console.h @@ -42,6 +42,8 @@ class Console : public GUI::Debugger { public: Console(SciEngine *vm); virtual ~Console(); + void preEnter(); + void postEnter(); private: // General diff --git a/engines/sci/engine/grammar.cpp b/engines/sci/engine/grammar.cpp index b54815176e..2c035fcb53 100644 --- a/engines/sci/engine/grammar.cpp +++ b/engines/sci/engine/grammar.cpp @@ -351,7 +351,7 @@ parse_rule_list_t *Vocabulary::buildGNF(bool verbose) { int ntrules_nr; parse_rule_list_t *ntlist = NULL; parse_rule_list_t *tlist, *new_tlist; - Sci::Console *con = ((SciEngine *)g_engine)->_console; + GUI::Debugger *con = ((SciEngine *)g_engine)->getDebugger(); for (uint i = 1; i < _parserBranches.size(); i++) { // branch rule 0 is treated specially parse_rule_t *rule = _vbuild_rule(&_parserBranches[i]); @@ -477,7 +477,7 @@ static int _vbpt_write_subexpression(parse_tree_node_t *nodes, int *pos, parse_r } int Vocabulary::parseGNF(parse_tree_node_t *nodes, const ResultWordList &words, bool verbose) { - Sci::Console *con = ((SciEngine *)g_engine)->_console; + GUI::Debugger *con = ((SciEngine *)g_engine)->getDebugger(); // Get the start rules: parse_rule_list_t *work = _vocab_clone_rule_list_by_id(_parserRules, _parserBranches[0].data[1]); parse_rule_list_t *results = NULL; diff --git a/engines/sci/engine/kevent.cpp b/engines/sci/engine/kevent.cpp index 7b1be0ae62..c0a137469e 100644 --- a/engines/sci/engine/kevent.cpp +++ b/engines/sci/engine/kevent.cpp @@ -111,7 +111,7 @@ reg_t kGetEvent(EngineState *s, int funct_nr, int argc, reg_t *argv) { // track left buttton clicks, if requested if (e.type == SCI_EVT_MOUSE_PRESS && e.data == 1 && debug_track_mouse_clicks) { - ((SciEngine *)g_engine)->_console->DebugPrintf("Mouse clicked at %d, %d\n", + ((SciEngine *)g_engine)->getDebugger()->DebugPrintf("Mouse clicked at %d, %d\n", s->gfx_state->pointer_pos.x, s->gfx_state->pointer_pos.y); } diff --git a/engines/sci/gfx/operations.cpp b/engines/sci/gfx/operations.cpp index 14be83b9aa..7ab1bc28cd 100644 --- a/engines/sci/gfx/operations.cpp +++ b/engines/sci/gfx/operations.cpp @@ -1457,8 +1457,8 @@ static sci_event_t scummvm_get_event(gfx_driver_t *drv) { // Debug console if (ev.kbd.flags == Common::KBD_CTRL && ev.kbd.keycode == Common::KEYCODE_d) { // Open debug console - ((Sci::SciEngine*)g_engine)->_console->attach(); - ((Sci::SciEngine*)g_engine)->_console->onFrame(); + ((Sci::SciEngine*)g_engine)->getDebugger()->attach(); + ((Sci::SciEngine*)g_engine)->getDebugger()->onFrame(); // Clear keyboard event input.type = SCI_EVT_NONE; diff --git a/engines/sci/sci.cpp b/engines/sci/sci.cpp index 52e2798b23..eb75beab8f 100644 --- a/engines/sci/sci.cpp +++ b/engines/sci/sci.cpp @@ -144,37 +144,37 @@ Common::Error SciEngine::run() { map_MIDI_instruments(_resmgr); #endif - EngineState *gamestate = new EngineState(); - gamestate->resmgr = _resmgr; - gamestate->gfx_state = NULL; - gamestate->flags = getFlags(); + _gamestate = new EngineState(); + _gamestate->resmgr = _resmgr; + _gamestate->gfx_state = NULL; + _gamestate->flags = getFlags(); // Verify that we haven't got an invalid game detection entry if (version < SCI_VERSION_1_EARLY) { // SCI0/SCI01 - if (gamestate->flags & GF_SCI1_EGA || - gamestate->flags & GF_SCI1_LOFSABSOLUTE || - gamestate->flags & GF_SCI1_NEWDOSOUND) { + if (_gamestate->flags & GF_SCI1_EGA || + _gamestate->flags & GF_SCI1_LOFSABSOLUTE || + _gamestate->flags & GF_SCI1_NEWDOSOUND) { error("This game entry is erroneous. It's marked as SCI0/SCI01, but it has SCI1 flags set"); } } else if (version >= SCI_VERSION_1_EARLY && version <= SCI_VERSION_1_LATE) { // SCI1 - if (gamestate->flags & GF_SCI0_OLD || - gamestate->flags & GF_SCI0_OLDGFXFUNCS || - gamestate->flags & GF_SCI0_OLDGETTIME) { + if (_gamestate->flags & GF_SCI0_OLD || + _gamestate->flags & GF_SCI0_OLDGFXFUNCS || + _gamestate->flags & GF_SCI0_OLDGETTIME) { error("This game entry is erroneous. It's marked as SCI1, but it has SCI0 flags set"); } } else if (version == SCI_VERSION_1_1 || version == SCI_VERSION_32) { - if (gamestate->flags & GF_SCI1_EGA || - gamestate->flags & GF_SCI1_LOFSABSOLUTE || - gamestate->flags & GF_SCI1_NEWDOSOUND) { + if (_gamestate->flags & GF_SCI1_EGA || + _gamestate->flags & GF_SCI1_LOFSABSOLUTE || + _gamestate->flags & GF_SCI1_NEWDOSOUND) { error("This game entry is erroneous. It's marked as SCI1.1/SCI32, but it has SCI1 flags set"); } - if (gamestate->flags & GF_SCI0_OLD || - gamestate->flags & GF_SCI0_OLDGFXFUNCS || - gamestate->flags & GF_SCI0_OLDGETTIME) { + if (_gamestate->flags & GF_SCI0_OLD || + _gamestate->flags & GF_SCI0_OLDGFXFUNCS || + _gamestate->flags & GF_SCI0_OLDGETTIME) { error("This game entry is erroneous. It's marked as SCI1.1/SCI32, but it has SCI0 flags set"); } @@ -183,11 +183,11 @@ Common::Error SciEngine::run() { error ("Unknown SCI version in game entry"); } - if (script_init_engine(gamestate, version)) + if (script_init_engine(_gamestate, version)) return Common::kUnknownError; - if (game_init(gamestate)) { /* Initialize */ + if (game_init(_gamestate)) { /* Initialize */ warning("Game initialization failed: Aborting..."); // TODO: Add an "init failed" error? return Common::kUnknownError; @@ -195,13 +195,13 @@ Common::Error SciEngine::run() { // Set the savegame dir (actually, we set it to a fake value, // since we cannot let the game control where saves are stored) - script_set_gamestate_save_dir(gamestate, "/"); + script_set_gamestate_save_dir(_gamestate, "/"); GfxState gfx_state; gfx_state.driver = &gfx_driver_scummvm; - gamestate->animation_granularity = 4; - gamestate->gfx_state = &gfx_state; + _gamestate->animation_granularity = 4; + _gamestate->gfx_state = &gfx_state; // Default config: gfx_options_t gfx_options; @@ -232,25 +232,25 @@ Common::Error SciEngine::run() { return Common::kUnknownError; } - if (game_init_graphics(gamestate)) { // Init interpreter graphics + if (game_init_graphics(_gamestate)) { // Init interpreter graphics warning("Game initialization failed: Error in GFX subsystem. Aborting..."); return Common::kUnknownError; } - if (game_init_sound(gamestate, 0)) { + if (game_init_sound(_gamestate, 0)) { warning("Game initialization failed: Error in sound subsystem. Aborting..."); return Common::kUnknownError; } printf("Emulating SCI version %s\n", versionNames[version]); - game_run(&gamestate); // Run the game + game_run(&_gamestate); // Run the game - game_exit(gamestate); - script_free_engine(gamestate); // Uninitialize game state - script_free_breakpoints(gamestate); + game_exit(_gamestate); + script_free_engine(_gamestate); // Uninitialize game state + script_free_breakpoints(_gamestate); - delete gamestate; + delete _gamestate; delete _resmgr; @@ -309,8 +309,7 @@ Common::String SciEngine::unwrapFilename(const Common::String &name) const { } void SciEngine::pauseEngineIntern(bool pause) { - // TODO: pause music and game script execution here - + _gamestate->_sound.sfx_suspend(pause); _mixer->pauseAll(pause); } diff --git a/engines/sci/sci.h b/engines/sci/sci.h index 954a20cd5b..7cadfd0d7b 100644 --- a/engines/sci/sci.h +++ b/engines/sci/sci.h @@ -159,11 +159,11 @@ public: /** Remove the 'TARGET-' prefix of the given filename, if present. */ Common::String unwrapFilename(const Common::String &name) const; - Console *_console; - private: const SciGameDescription *_gameDescription; ResourceManager *_resmgr; + EngineState *_gamestate; + Console *_console; }; } // End of namespace Sci diff --git a/engines/sci/tools.cpp b/engines/sci/tools.cpp index 573938bda4..589ce298d7 100644 --- a/engines/sci/tools.cpp +++ b/engines/sci/tools.cpp @@ -70,7 +70,7 @@ void sciprintf(const char *fmt, ...) { // Display the result suitably if (g_redirect_sciprintf_to_gui) - ((SciEngine *)g_engine)->_console->DebugPrintf("%s", buf); + ((SciEngine *)g_engine)->getDebugger()->DebugPrintf("%s", buf); printf("%s", buf); free(buf); diff --git a/engines/sci/vocabulary.cpp b/engines/sci/vocabulary.cpp index 537f24974c..216ab211be 100644 --- a/engines/sci/vocabulary.cpp +++ b/engines/sci/vocabulary.cpp @@ -438,7 +438,7 @@ bool Vocabulary::tokenizeString(ResultWordList &retval, const char *sentence, ch void Vocabulary::printSuffixes() const { char word_buf[256], alt_buf[256]; - Sci::Console *con = ((SciEngine *)g_engine)->_console; + GUI::Debugger *con = ((SciEngine *)g_engine)->getDebugger(); int i = 0; for (SuffixList::const_iterator suf = _parserSuffixes.begin(); suf != _parserSuffixes.end(); ++suf) { @@ -453,7 +453,7 @@ void Vocabulary::printSuffixes() const { } void Vocabulary::printParserWords() const { - Sci::Console *con = ((SciEngine *)g_engine)->_console; + GUI::Debugger *con = ((SciEngine *)g_engine)->getDebugger(); int j = 0; for (WordMap::iterator i = _parserWords.begin(); i != _parserWords.end(); ++i) { -- cgit v1.2.3