From a73dcdf224ae88c7bcf73d754781052835af4cd0 Mon Sep 17 00:00:00 2001 From: Walter van Niftrik Date: Sun, 6 Mar 2016 13:36:35 +0100 Subject: ADL: Move functionality into base class --- engines/adl/adl.cpp | 51 ++++++++++++++++++++++++++++++++++++++++++++++++- engines/adl/adl.h | 3 ++- engines/adl/hires1.cpp | 52 +------------------------------------------------- engines/adl/hires1.h | 2 +- 4 files changed, 54 insertions(+), 54 deletions(-) diff --git a/engines/adl/adl.cpp b/engines/adl/adl.cpp index c395fbb81b..701f902ade 100644 --- a/engines/adl/adl.cpp +++ b/engines/adl/adl.cpp @@ -72,6 +72,8 @@ bool AdlEngine::hasFeature(EngineFeature f) const { Common::Error AdlEngine::run() { _display = new Display(); + loadData(); + int saveSlot = ConfMan.getInt("save_slot"); if (saveSlot >= 0) { if (loadGameState(saveSlot).getCode() != Common::kNoError) @@ -83,7 +85,54 @@ Common::Error AdlEngine::run() { initState(); } - runGame(); + _display->setMode(DISPLAY_MODE_MIXED); + printASCIIString("\r\r\r\r\r"); + + while (1) { + uint verb = 0, noun = 0; + + // 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) { + clearScreen(); + showRoom(); + + _canSaveNow = _canRestoreNow = true; + getInput(verb, noun); + _canSaveNow = _canRestoreNow = false; + + if (shouldQuit()) + break; + + if (!doOneCommand(_roomCommands, verb, noun)) + printEngineMessage(IDI_MSG_DONT_UNDERSTAND); + } + + 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. + printASCIIString("\r"); + _isRestoring = false; + verb = _restoreVerb; + noun = _restoreNoun; + } + + // Restarting does end command processing + if (_isRestarting) { + _isRestarting = false; + continue; + } + + doAllCommands(_globalCommands, verb, noun); + _state.moves++; + } return Common::kNoError; } diff --git a/engines/adl/adl.h b/engines/adl/adl.h index 84b9214161..66a539547b 100644 --- a/engines/adl/adl.h +++ b/engines/adl/adl.h @@ -180,7 +180,8 @@ protected: typedef Common::HashMap WordMap; virtual void runIntro() { } - virtual void runGame() = 0; + virtual void loadData() = 0; + void runGame(); virtual void initState() = 0; virtual void restartGame() = 0; virtual uint getEngineMessage(EngineMessage msg) = 0; diff --git a/engines/adl/hires1.cpp b/engines/adl/hires1.cpp index 91407808eb..11d576b217 100644 --- a/engines/adl/hires1.cpp +++ b/engines/adl/hires1.cpp @@ -312,9 +312,7 @@ void HiRes1Engine::restartGame() { printASCIIString("\r\r\r\r\r"); } -void HiRes1Engine::runGame() { - _display->setMode(DISPLAY_MODE_MIXED); - +void HiRes1Engine::loadData() { Common::File f; if (!f.open(IDS_HR1_MESSAGES)) @@ -385,54 +383,6 @@ void HiRes1Engine::runGame() { f.seek(IDI_HR1_OFS_NOUNS); loadNouns(f); - - printASCIIString("\r\r\r\r\r"); - - while (1) { - uint verb = 0, noun = 0; - - // 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) { - clearScreen(); - showRoom(); - - _canSaveNow = _canRestoreNow = true; - getInput(verb, noun); - _canSaveNow = _canRestoreNow = false; - - if (shouldQuit()) - return; - - if (!doOneCommand(_roomCommands, verb, noun)) - printMessage(IDI_HR1_MSG_DONT_UNDERSTAND); - } - - 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. - printASCIIString("\r"); - _isRestoring = false; - verb = _restoreVerb; - noun = _restoreNoun; - } - - // Restarting does end command processing - if (_isRestarting) { - _isRestarting = false; - continue; - } - - doAllCommands(_globalCommands, verb, noun); - _state.moves++; - } } void HiRes1Engine::printMessage(uint idx, bool wait) { diff --git a/engines/adl/hires1.h b/engines/adl/hires1.h index 64cf8f35f7..f72093a92a 100644 --- a/engines/adl/hires1.h +++ b/engines/adl/hires1.h @@ -43,7 +43,7 @@ private: void initState(); void runIntro(); - void runGame(); + void loadData(); void drawPic(Common::ReadStream &stream, const Common::Point &pos); void drawItems(); void drawLine(const Common::Point &p1, const Common::Point &p2, byte color); -- cgit v1.2.3