[Scummvm-git-logs] scummvm master -> c0d5981ff9b125e0c56ce68707ade7e07e304206

dreammaster paulfgilbert at gmail.com
Sun Jun 23 07:04:20 CEST 2019


This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
3683e74d65 GLK: ALAN2: Set up main game loop for restarting game
c0d5981ff9 GLK: ALAN2: Fix quitting in-game


Commit: 3683e74d65273126afd3d7a101c656b7b52b8580
    https://github.com/scummvm/scummvm/commit/3683e74d65273126afd3d7a101c656b7b52b8580
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2019-06-22T22:03:06-07:00

Commit Message:
GLK: ALAN2: Set up main game loop for restarting game

Changed paths:
    engines/glk/alan2/alan2.cpp
    engines/glk/alan2/alan2.h
    engines/glk/alan2/main.cpp


diff --git a/engines/glk/alan2/alan2.cpp b/engines/glk/alan2/alan2.cpp
index 1ae5dda..7d5040c 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 ac67364..9d007d0 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 2dea451..6e6133d 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;
+			}
 		}
 	}
 }


Commit: c0d5981ff9b125e0c56ce68707ade7e07e304206
    https://github.com/scummvm/scummvm/commit/c0d5981ff9b125e0c56ce68707ade7e07e304206
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2019-06-22T22:03:06-07:00

Commit Message:
GLK: ALAN2: Fix quitting in-game

Changed paths:
    engines/glk/alan2/debug.cpp
    engines/glk/alan2/exe.cpp
    engines/glk/alan2/exe.h
    engines/glk/alan2/inter.cpp
    engines/glk/alan2/inter.h
    engines/glk/alan2/main.cpp
    engines/glk/alan2/main.h
    engines/glk/alan2/parse.cpp


diff --git a/engines/glk/alan2/debug.cpp b/engines/glk/alan2/debug.cpp
index b455db6..bea427b 100644
--- a/engines/glk/alan2/debug.cpp
+++ b/engines/glk/alan2/debug.cpp
@@ -315,8 +315,11 @@ void debug() {
       $iX -- exit debug mode\
       $iQ -- quit game");
 			break;
-		case 'Q':
-			terminate(0);
+		case 'Q': {
+			Context ctx;
+			terminate(ctx, 0);
+			break;
+		}
 		case 'X':
 			dbgflg = FALSE;       /* Fall through to 'G' */
 		case 'G':
diff --git a/engines/glk/alan2/exe.cpp b/engines/glk/alan2/exe.cpp
index fd3b065..2acd9d2 100644
--- a/engines/glk/alan2/exe.cpp
+++ b/engines/glk/alan2/exe.cpp
@@ -166,7 +166,7 @@ Boolean confirm(MsgKind msgno) {
 	return (buf[0] == '\0');
 }
 
-void quit() {
+void quit(CONTEXT) {
 	char buf[80];
 
 	para();
@@ -174,18 +174,20 @@ void quit() {
 		col = 1;
 		statusline();
 		prmsg(M_QUITACTION);
-		if (!readline(buf)) terminate(0);
+		if (!readline(buf)) {
+			CALL1(terminate, 0)
+		}
 
-		if (strcmp(buf, "restart") == 0)
-			//longjmp(restart_label, TRUE);
-			::error("TODO: restart");
-		else if (strcmp(buf, "restore") == 0) {
+		if (strcmp(buf, "restart") == 0) {
+			g_vm->setRestart(true);
+			LONG_JUMP
+		} else if (strcmp(buf, "restore") == 0) {
 			restore();
-			return;
-		} else if (strcmp(buf, "quit") == 0)
-			terminate(0);
+			LONG_JUMP
+		} else if (strcmp(buf, "quit") == 0) {
+			CALL1(terminate, 0)
+		}
 	}
-	syserr("Fallthrough in QUIT");
 }
 
 void restart() {
diff --git a/engines/glk/alan2/exe.h b/engines/glk/alan2/exe.h
index cc99719..89a34b5 100644
--- a/engines/glk/alan2/exe.h
+++ b/engines/glk/alan2/exe.h
@@ -27,6 +27,7 @@
  */
 
 #include "glk/alan2/types.h"
+#include "glk/alan2/jumps.h"
 
 namespace Glk {
 namespace Alan2 {
@@ -61,7 +62,7 @@ extern void score(Aword sc);
 extern void visits(Aword v);
 extern void schedule(Aword evt, Aword whr, Aword aft);
 extern void cancl(Aword evt);
-extern void quit(void);
+extern void quit(CONTEXT);
 extern void restart(void);
 extern void save(void);
 extern void restore(void);
diff --git a/engines/glk/alan2/inter.cpp b/engines/glk/alan2/inter.cpp
index 51c1e79..4e6639a 100644
--- a/engines/glk/alan2/inter.cpp
+++ b/engines/glk/alan2/inter.cpp
@@ -146,6 +146,11 @@ static void depcase() {
 }
 
 void interpret(Aaddr adr) {
+	Context ctx;
+	interpret(ctx, adr);
+}
+
+void interpret(CONTEXT, Aaddr adr) {
 	Aaddr oldpc;
 	Aword i;
 
@@ -233,7 +238,7 @@ void interpret(Aaddr adr) {
 			case I_QUIT: {
 				if (stpflg)
 					printf("QUIT");
-				quit();
+				CALL0(quit)
 				break;
 			}
 			case I_LOOK: {
diff --git a/engines/glk/alan2/inter.h b/engines/glk/alan2/inter.h
index b4ae725..bb26ce1 100644
--- a/engines/glk/alan2/inter.h
+++ b/engines/glk/alan2/inter.h
@@ -23,10 +23,13 @@
 #ifndef GLK_ALAN2_INTER
 #define GLK_ALAN2_INTER
 
+#include "glk/alan2/jumps.h"
+
 namespace Glk {
 namespace Alan2 {
 
 extern void interpret(Aaddr adr);
+extern void interpret(CONTEXT, Aaddr adr);
 
 } // End of namespace Alan2
 } // End of namespace Glk
diff --git a/engines/glk/alan2/main.cpp b/engines/glk/alan2/main.cpp
index 6e6133d..e6d2226 100644
--- a/engines/glk/alan2/main.cpp
+++ b/engines/glk/alan2/main.cpp
@@ -114,13 +114,14 @@ Boolean skipsp = FALSE;
   return buffers...
 
  */
-void terminate(int code) {
+void terminate(CONTEXT, int code) {
 	newline();
 	free(memory);
 	if (logflg)
 		fclose(logfil);
 
 	g_vm->glk_exit();
+	LONG_JUMP
 }
 
 /*======================================================================
@@ -885,7 +886,7 @@ static void do_it(CONTEXT) {
 						else
 							printf("\n<VERB %d, %s (ONLY), Body:>\n", cur.vrb, trace);
 					}
-					interpret(alt[i]->action);
+					CALL1(interpret, alt[i]->action)
 					if (fail) return;
 					if (alt[i]->qual == (Aword)Q_ONLY) return;
 				}
@@ -908,7 +909,7 @@ static void do_it(CONTEXT) {
 							sprintf(trace, "in PARAMETER %d", i - 1);
 						printf("\n<VERB %d, %s, Body:>\n", cur.vrb, trace);
 					}
-					interpret(alt[i]->action);
+					CALL1(interpret, alt[i]->action)
 					if (fail) return;
 				}
 				done[i] = TRUE;
@@ -929,7 +930,7 @@ static void do_it(CONTEXT) {
 						sprintf(trace, "in PARAMETER %d", i - 1);
 					printf("\n<VERB %d, %s (AFTER), Body:>\n", cur.vrb, trace);
 				}
-				interpret(alt[i]->action);
+				CALL1(interpret, alt[i]->action)
 				if (fail) return;
 			}
 		i--;
diff --git a/engines/glk/alan2/main.h b/engines/glk/alan2/main.h
index 9672899..a77a0c5 100644
--- a/engines/glk/alan2/main.h
+++ b/engines/glk/alan2/main.h
@@ -99,7 +99,7 @@ extern Boolean needsp;
 #define endOfTable(x) eot((Aword *) x)
 
 extern void *allocate(unsigned long len);
-extern void terminate(int code);
+extern void terminate(CONTEXT, int code);
 extern void usage(void);
 extern void error(CONTEXT, MsgKind msg);
 extern void syserr(const char *msg);
diff --git a/engines/glk/alan2/parse.cpp b/engines/glk/alan2/parse.cpp
index bc12d3e..5c9fd35 100644
--- a/engines/glk/alan2/parse.cpp
+++ b/engines/glk/alan2/parse.cpp
@@ -150,7 +150,7 @@ static char *gettoken(char *tokBuf) {
 	return tokBuf;
 }
 
-static void agetline() {
+static void agetline(CONTEXT) {
 	para();
 	do {
 		statusline();
@@ -164,7 +164,7 @@ static void agetline() {
 				return;
 
 			newline();
-			quit();
+			CALL0(quit)
 		}
 
 		getPageSize();
@@ -189,7 +189,7 @@ static void scan(CONTEXT) {
 	int w;
 	char *str;
 
-	agetline();
+	CALL0(agetline)
 	if (g_vm->shouldQuit())
 		return;
 





More information about the Scummvm-git-logs mailing list