diff options
-rw-r--r-- | engines/glk/alan2/alan2.cpp | 2 | ||||
-rw-r--r-- | engines/glk/alan2/alan2.h | 12 | ||||
-rw-r--r-- | engines/glk/alan2/main.cpp | 42 |
3 files changed, 35 insertions, 21 deletions
diff --git a/engines/glk/alan2/alan2.cpp b/engines/glk/alan2/alan2.cpp index 1ae5ddad35..7d5040ca67 100644 --- a/engines/glk/alan2/alan2.cpp +++ b/engines/glk/alan2/alan2.cpp @@ -39,7 +39,7 @@ namespace Alan2 { Alan2 *g_vm = nullptr; Alan2::Alan2(OSystem *syst, const GlkGameDescription &gameDesc) : GlkAPI(syst, gameDesc), - vm_exited_cleanly(false) { + vm_exited_cleanly(false), _restartFlag(false) { g_vm = this; } diff --git a/engines/glk/alan2/alan2.h b/engines/glk/alan2/alan2.h index ac67364910..9d007d0bde 100644 --- a/engines/glk/alan2/alan2.h +++ b/engines/glk/alan2/alan2.h @@ -35,6 +35,8 @@ namespace Alan2 { * Alan2 game interpreter */ class Alan2 : public GlkAPI { +private: + bool _restartFlag; public: bool vm_exited_cleanly; Common::String _advName; @@ -65,6 +67,16 @@ public: void runGame(); /** + * Flag for the game to restart + */ + void setRestart(bool flag) { _restartFlag = flag; } + + /** + * Returns whether the game should restart + */ + bool shouldRestart() const { return _restartFlag; } + + /** * Returns the running interpreter type */ virtual InterpreterType getInterpreterType() const override { diff --git a/engines/glk/alan2/main.cpp b/engines/glk/alan2/main.cpp index 2dea4519f7..6e6133db87 100644 --- a/engines/glk/alan2/main.cpp +++ b/engines/glk/alan2/main.cpp @@ -1415,29 +1415,31 @@ void run() { // Set default line and column col = lin = 1; - //setjmp(restart_label); /* Return here if he wanted to restart */ - - init(); /* Load, initialise and start the adventure */ - - Context ctx; - for (;;) { - if (!ctx._break) { - if (dbgflg) - debug(); - - eventchk(); - cur.tick++; - } + while (!g_vm->shouldQuit()) { + // Load, initialise and start the adventure + g_vm->setRestart(false); + init(); + + Context ctx; + while (!g_vm->shouldQuit()) { + if (!ctx._break) { + if (dbgflg) + debug(); + + eventchk(); + cur.tick++; + } - // Execution ends up here after calls to the error method + // Execution ends up here after calls to the error method - // Move all characters - ctx._break = false; - for (cur.act = ACTMIN; cur.act <= (int)ACTMAX && !ctx._break; cur.act++) { - movactor(ctx); + // Move all characters + ctx._break = false; + for (cur.act = ACTMIN; cur.act <= (int)ACTMAX && !ctx._break; cur.act++) { + movactor(ctx); - if (g_vm->shouldQuit()) - return; + if (g_vm->shouldQuit()) + return; + } } } } |