aboutsummaryrefslogtreecommitdiff
path: root/engines/glk/alan3
diff options
context:
space:
mode:
authorPaul Gilbert2019-06-29 14:42:50 -0700
committerPaul Gilbert2019-07-06 15:27:08 -0700
commitc833d39ccf8ec2493929afaa7066113802fb90b0 (patch)
tree13882573c5c91418cf96366377a14d9f06774ede /engines/glk/alan3
parentf0d5304a4c160abc8a16cac637a48ebe751b602c (diff)
downloadscummvm-rg350-c833d39ccf8ec2493929afaa7066113802fb90b0.tar.gz
scummvm-rg350-c833d39ccf8ec2493929afaa7066113802fb90b0.tar.bz2
scummvm-rg350-c833d39ccf8ec2493929afaa7066113802fb90b0.zip
GLK: ALAN3: Outer game loop to handle forfeit setjmp replacement
Diffstat (limited to 'engines/glk/alan3')
-rw-r--r--engines/glk/alan3/alan3.cpp7
-rw-r--r--engines/glk/alan3/main.cpp119
-rw-r--r--engines/glk/alan3/output.cpp8
-rw-r--r--engines/glk/alan3/output.h1
4 files changed, 77 insertions, 58 deletions
diff --git a/engines/glk/alan3/alan3.cpp b/engines/glk/alan3/alan3.cpp
index 950e9cd73a..bbcd6da7f5 100644
--- a/engines/glk/alan3/alan3.cpp
+++ b/engines/glk/alan3/alan3.cpp
@@ -25,6 +25,7 @@
#include "glk/alan3/main.h"
#include "glk/alan3/glkio.h"
#include "glk/alan3/options.h"
+#include "glk/alan3/output.h"
#include "glk/alan3/syserr.h"
#include "common/system.h"
#include "common/config-manager.h"
@@ -67,6 +68,12 @@ Alan3::Alan3(OSystem *syst, const GlkGameDescription &gameDesc) : GlkAPI(syst, g
statusLineOption = true;
regressionTestOption = false;
+ // output
+ anyOutput = false;
+ capitalize = false;
+ needSpace = false;
+ skipSpace = false;
+
// syserr
setSyserrHandler(nullptr);
}
diff --git a/engines/glk/alan3/main.cpp b/engines/glk/alan3/main.cpp
index 52c14761e6..4fd8cf6a3e 100644
--- a/engines/glk/alan3/main.cpp
+++ b/engines/glk/alan3/main.cpp
@@ -651,7 +651,7 @@ static char *scriptName(int theActor, int theScript) {
/*----------------------------------------------------------------------*/
-static void moveActor(int theActor) {
+static void moveActor(CONTEXT, int theActor) {
ScriptEntry *scr;
StepEntry *step;
Aint previousInstance = current.instance;
@@ -659,17 +659,18 @@ static void moveActor(int theActor) {
current.actor = theActor;
current.instance = theActor;
current.location = where(theActor, TRANSITIVE);
- if (theActor == (int)HERO) {
-#ifdef TODO
- /* Ask him! */
- if (setjmp(forfeitLabel) == 0) {
+ if (context._break || theActor == (int)HERO) {
+ if (context._break) {
+ // Forfeit jump destination
+ assert(context._label == "forfeit");
+ context.clear();
+ } else {
+ // Ask him!
parse();
capitalize = TRUE;
- fail = FALSE; /* fail only aborts one actor */
+ fail = FALSE; // fail only aborts one actor
}
-#else
- syserr("TODO: moveActor setjmp");
-#endif
+
} else if (admin[theActor].script != 0) {
for (scr = (ScriptEntry *) pointerTo(header->scriptTableAddress); !isEndOfArray(scr); scr++) {
if (scr->code == admin[theActor].script) {
@@ -748,63 +749,73 @@ void run(void) {
init();
while (!g_vm->shouldQuit()) {
- if (ctx._break) {
- #ifdef TODO
- // Return here if error during execution
- switch (setjmp(returnLabel)) {
- case NO_JUMP_RETURN:
- break;
- case ERROR_RETURN:
- forgetGameState();
- forceNewPlayerInput();
- break;
- case UNDO_RETURN:
- forceNewPlayerInput();
- break;
- default:
- syserr("Unexpected longjmp() return value");
+ if (!(ctx._break && ctx._label == "forfeit")) {
+ if (ctx._break) {
+ assert(ctx._label == "return");
+#ifdef TODO
+ // Return here if error during execution
+ switch (setjmp(returnLabel)) {
+ case NO_JUMP_RETURN:
+ break;
+ case ERROR_RETURN:
+ forgetGameState();
+ forceNewPlayerInput();
+ break;
+ case UNDO_RETURN:
+ forceNewPlayerInput();
+ break;
+ default:
+ syserr("Unexpected longjmp() return value");
+ }
+#endif
+ ctx.clear();
+ } else {
+ if (debugOption)
+ debug(FALSE, 0, 0);
+
+ if (stackDepth(theStack) != 0)
+ syserr("Stack is not empty in main loop");
+
+ if (!current.meta)
+ runPendingEvents();
}
- #endif
- ctx.clear();
- } else {
- if (debugOption)
- debug(FALSE, 0, 0);
- if (stackDepth(theStack) != 0)
- syserr("Stack is not empty in main loop");
+ recursionDepth = 0;
- if (!current.meta)
- runPendingEvents();
+ // Move all characters, hero first
+ rememberGameState();
+ current.meta = FALSE;
}
- recursionDepth = 0;
+ moveActor(ctx, header->theHero);
- // Move all characters, hero first
- rememberGameState();
- current.meta = FALSE;
- moveActor(header->theHero);
+ if (!ctx._break) {
+ if (gameStateChanged)
+ rememberCommands();
+ else
+ forgetGameState();
- if (gameStateChanged)
- rememberCommands();
- else
- forgetGameState();
+ if (!current.meta) {
+ current.tick++;
- if (!current.meta) {
- current.tick++;
+ // Remove this call? Since Eval is done up there after each event...
+ resetAndEvaluateRules(rules, header->version);
- // Remove this call? Since Eval is done up there after each event...
- resetAndEvaluateRules(rules, header->version);
+ /* Then all the other actors... */
+ for (uint i = 1; i <= header->instanceMax; i++) {
+ if (i != header->theHero && isAActor(i)) {
+ moveActor(ctx, i);
+ if (ctx._break)
+ break;
- /* Then all the other actors... */
- for (uint i = 1; i <= header->instanceMax; i++)
- if (i != header->theHero && isAActor(i)) {
- moveActor(i);
- resetAndEvaluateRules(rules, header->version);
+ resetAndEvaluateRules(rules, header->version);
+ }
}
- }
+ }
- if (ctx._break && ctx._label == "restart")
- break;
+ if (ctx._break && ctx._label == "restart")
+ break;
+ }
}
} while (!g_vm->shouldQuit() && ctx._label == "restart");
}
diff --git a/engines/glk/alan3/output.cpp b/engines/glk/alan3/output.cpp
index 97a3a35574..5f646923d4 100644
--- a/engines/glk/alan3/output.cpp
+++ b/engines/glk/alan3/output.cpp
@@ -40,10 +40,10 @@ namespace Glk {
namespace Alan3 {
/* PUBLIC DATA */
-bool anyOutput = FALSE;
-bool capitalize = FALSE;
-bool needSpace = FALSE;
-bool skipSpace = FALSE;
+bool anyOutput;
+bool capitalize;
+bool needSpace;
+bool skipSpace;
/* Screen formatting info */
int col, lin;
diff --git a/engines/glk/alan3/output.h b/engines/glk/alan3/output.h
index e889b76b89..6f52cfccf6 100644
--- a/engines/glk/alan3/output.h
+++ b/engines/glk/alan3/output.h
@@ -36,6 +36,7 @@ extern int pageLength, pageWidth;
extern bool anyOutput;
extern bool needSpace;
extern bool capitalize;
+extern bool skipSpace;
/* Log file */
extern strid_t logFile;