From cfaf749c60c4c641f11142bde53ce6b183847895 Mon Sep 17 00:00:00 2001 From: Walter van Niftrik Date: Wed, 28 Dec 2016 22:11:53 +0100 Subject: ADL: Implement hires5 game loop --- engines/adl/adl.cpp | 109 +++++++++++++++++++++++++------------------------ engines/adl/adl.h | 5 ++- engines/adl/adl_v4.cpp | 45 ++++++++++++++++++++ engines/adl/adl_v4.h | 1 + 4 files changed, 105 insertions(+), 55 deletions(-) (limited to 'engines/adl') diff --git a/engines/adl/adl.cpp b/engines/adl/adl.cpp index 3cf68c5dfa..c1c3820b10 100644 --- a/engines/adl/adl.cpp +++ b/engines/adl/adl.cpp @@ -586,6 +586,60 @@ void AdlEngine::dropItem(byte noun) { printMessage(_messageIds.dontUnderstand); } +void AdlEngine::gameLoop() { + uint verb = 0, noun = 0; + _isRestarting = false; + + // When restoring from the launcher, we don't read + // input on the first iteration. This is needed to + // ensure that restoring from the launcher and + // restoring in-game brings us to the same game state. + // (Also see comment below.) + if (!_isRestoring) { + showRoom(); + + if (_isRestarting) + return; + + _canSaveNow = _canRestoreNow = true; + getInput(verb, noun); + _canSaveNow = _canRestoreNow = false; + + if (shouldQuit()) + return; + + // If we just restored from the GMM, we skip this command + // set, as no command has been input by the user + if (!_isRestoring) + checkInput(verb, noun); + } + + if (_isRestoring) { + // We restored from the GMM or launcher. As restoring + // with "RESTORE GAME" does not end command processing, + // we don't break it off here either. This essentially + // means that restoring a game will always run through + // the global commands and increase the move counter + // before the first user input. + _display->printAsciiString("\r"); + _isRestoring = false; + verb = _restoreVerb; + noun = _restoreNoun; + } + + // Restarting does end command processing + if (_isRestarting) + return; + + doAllCommands(_globalCommands, verb, noun); + + if (_isRestarting) + return; + + advanceClock(); + _state.moves++; +} + Common::Error AdlEngine::run() { initGraphics(DISPLAY_WIDTH * 2, DISPLAY_HEIGHT * 2, true); @@ -611,59 +665,8 @@ Common::Error AdlEngine::run() { _display->setMode(DISPLAY_MODE_MIXED); - while (!_isQuitting) { - uint verb = 0, noun = 0; - _isRestarting = false; - - // When restoring from the launcher, we don't read - // input on the first iteration. This is needed to - // ensure that restoring from the launcher and - // restoring in-game brings us to the same game state. - // (Also see comment below.) - if (!_isRestoring) { - showRoom(); - - if (_isRestarting) - continue; - - _canSaveNow = _canRestoreNow = true; - getInput(verb, noun); - _canSaveNow = _canRestoreNow = false; - - if (shouldQuit()) - break; - - // If we just restored from the GMM, we skip this command - // set, as no command has been input by the user - if (!_isRestoring) - checkInput(verb, noun); - } - - if (_isRestoring) { - // We restored from the GMM or launcher. As restoring - // with "RESTORE GAME" does not end command processing, - // we don't break it off here either. This essentially - // means that restoring a game will always run through - // the global commands and increase the move counter - // before the first user input. - _display->printAsciiString("\r"); - _isRestoring = false; - verb = _restoreVerb; - noun = _restoreNoun; - } - - // Restarting does end command processing - if (_isRestarting) - continue; - - doAllCommands(_globalCommands, verb, noun); - - if (_isRestarting) - continue; - - advanceClock(); - _state.moves++; - } + while (!(_isQuitting || shouldQuit())) + gameLoop(); return Common::kNoError; } diff --git a/engines/adl/adl.h b/engines/adl/adl.h index 2b336c9e86..62c5ea1b8e 100644 --- a/engines/adl/adl.h +++ b/engines/adl/adl.h @@ -239,6 +239,7 @@ protected: Common::Error loadGameState(int slot); Common::Error saveGameState(int slot, const Common::String &desc); + virtual void gameLoop(); virtual void loadState(Common::ReadStream &stream); virtual void saveState(Common::WriteStream &stream); Common::String readString(Common::ReadStream &stream, byte until = 0) const; @@ -253,6 +254,7 @@ protected: Common::String inputString(byte prompt = 0) const; byte inputKey(bool showCursor = true) const; + void getInput(uint &verb, uint &noun); virtual Common::String formatVerbError(const Common::String &verb) const; virtual Common::String formatNounError(const Common::String &verb, const Common::String &noun) const; @@ -388,6 +390,7 @@ protected: State _state; bool _isRestarting, _isRestoring, _isQuitting; + bool _canSaveNow, _canRestoreNow; bool _skipOneCommand; const AdlGameDescription *_gameDescription; @@ -412,12 +415,10 @@ private: byte convertKey(uint16 ascii) const; Common::String getLine() const; Common::String getWord(const Common::String &line, uint &index) const; - void getInput(uint &verb, uint &noun); Console *_console; GUI::Debugger *getDebugger() { return _console; } byte _saveVerb, _saveNoun, _restoreVerb, _restoreNoun; - bool _canSaveNow, _canRestoreNow; }; } // End of namespace Adl diff --git a/engines/adl/adl_v4.cpp b/engines/adl/adl_v4.cpp index c979f836aa..dcf0f997c9 100644 --- a/engines/adl/adl_v4.cpp +++ b/engines/adl/adl_v4.cpp @@ -37,6 +37,51 @@ AdlEngine_v4::~AdlEngine_v4() { delete _itemPicIndex; } +void AdlEngine_v4::gameLoop() { + uint verb = 0, noun = 0; + _isRestarting = false; + + if (_isRestoring) { + // Game restored from launcher. As this version of ADL long jumps to + // the game loop after restoring, no special action is required. + _isRestoring = false; + } + + showRoom(); + + if (_isRestarting || shouldQuit()) + return; + + _canSaveNow = _canRestoreNow = true; + getInput(verb, noun); + _canSaveNow = _canRestoreNow = false; + + if (_isRestoring) { + // Game restored from GMM. Move cursor to next line and jump to + // start of game loop. + _display->printAsciiString("\r"); + _isRestoring = false; + return; + } + + if (_isRestarting || shouldQuit()) + return; + + _linesPrinted = 0; + + checkInput(verb, noun); + + if (_isRestarting || shouldQuit()) + return; + + doAllCommands(_globalCommands, verb, noun); + + if (_isRestarting || shouldQuit()) + return; + + _state.moves++; +} + void AdlEngine_v4::loadState(Common::ReadStream &stream) { _state.room = stream.readByte(); _state.region = stream.readByte(); diff --git a/engines/adl/adl_v4.h b/engines/adl/adl_v4.h index caf2b3f7f8..4e87530673 100644 --- a/engines/adl/adl_v4.h +++ b/engines/adl/adl_v4.h @@ -49,6 +49,7 @@ protected: AdlEngine_v4(OSystem *syst, const AdlGameDescription *gd); // AdlEngine + virtual void gameLoop(); virtual void loadState(Common::ReadStream &stream); virtual void saveState(Common::WriteStream &stream); virtual Common::String loadMessage(uint idx) const; -- cgit v1.2.3