ADL: Implement hires5 game loop

This commit is contained in:
Walter van Niftrik 2016-12-28 22:11:53 +01:00
parent d7844bbf17
commit cfaf749c60
4 changed files with 105 additions and 55 deletions

View File

@ -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;
}

View File

@ -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

View File

@ -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();

View File

@ -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;