aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorPaul Gilbert2019-07-03 22:22:13 -0700
committerPaul Gilbert2019-07-06 15:27:09 -0700
commitc5214f6d349df9bc4ec088bbbca3543e47b22744 (patch)
tree3efa78f8063858233d7a1fcc85ee35316f2b4a52 /engines
parentb634a97f41877b233a654dc204a2c9760f9ad2f6 (diff)
downloadscummvm-rg350-c5214f6d349df9bc4ec088bbbca3543e47b22744.tar.gz
scummvm-rg350-c5214f6d349df9bc4ec088bbbca3543e47b22744.tar.bz2
scummvm-rg350-c5214f6d349df9bc4ec088bbbca3543e47b22744.zip
GLK: ALAN3: Making GlkIO base class
Diffstat (limited to 'engines')
-rw-r--r--engines/glk/alan3/alan3.cpp30
-rw-r--r--engines/glk/alan3/alan3.h5
-rw-r--r--engines/glk/alan3/debug.cpp2
-rw-r--r--engines/glk/alan3/glkio.cpp109
-rw-r--r--engines/glk/alan3/glkio.h54
-rw-r--r--engines/glk/alan3/inter.cpp6
-rw-r--r--engines/glk/alan3/output.cpp22
-rw-r--r--engines/glk/alan3/scan.cpp8
-rw-r--r--engines/glk/alan3/utils.cpp6
9 files changed, 136 insertions, 106 deletions
diff --git a/engines/glk/alan3/alan3.cpp b/engines/glk/alan3/alan3.cpp
index 52a6e25739..990874ee58 100644
--- a/engines/glk/alan3/alan3.cpp
+++ b/engines/glk/alan3/alan3.cpp
@@ -29,7 +29,6 @@
#include "glk/alan3/save.h"
#include "glk/alan3/syserr.h"
#include "common/system.h"
-#include "common/config-manager.h"
#include "common/translation.h"
#include "common/error.h"
#include "common/scummsys.h"
@@ -42,8 +41,8 @@ namespace Alan3 {
Alan3 *g_vm = nullptr;
-Alan3::Alan3(OSystem *syst, const GlkGameDescription &gameDesc) : GlkAPI(syst, gameDesc),
- vm_exited_cleanly(false), _saveSlot(-1), _pendingLook(false) {
+Alan3::Alan3(OSystem *syst, const GlkGameDescription &gameDesc) : GlkIO(syst, gameDesc),
+ vm_exited_cleanly(false), _pendingLook(false) {
g_vm = this;
// main
@@ -87,29 +86,14 @@ void Alan3::runGame() {
}
bool Alan3::initialize() {
+ if (!GlkIO::initialize())
+ syserr("FATAL ERROR: Cannot open initial window");
+
// Set up adventure name
_advName = getFilename();
if (_advName.size() > 4 && _advName[_advName.size() - 4] == '.')
_advName = Common::String(_advName.c_str(), _advName.size() - 4);
- // first, open a window for error output
- glkMainWin = g_vm->glk_window_open(0, 0, 0, wintype_TextBuffer, 0);
- if (glkMainWin == nullptr)
- syserr("FATAL ERROR: Cannot open initial window");
-
- g_vm->glk_stylehint_set(wintype_TextGrid, style_User1, stylehint_ReverseColor, 1);
- glkStatusWin = g_vm->glk_window_open(glkMainWin, winmethod_Above |
- winmethod_Fixed, 1, wintype_TextGrid, 0);
- g_vm->glk_set_window(glkMainWin);
-
- // Set up the code file to point to the already opened game file
- codfil = &_gameFile;
-
- if (_gameFile.size() < 8) {
- GUIErrorMessage(_("This is too short to be a valid Alan3 file."));
- return false;
- }
-
// In Alan 3, the text data comes from the adventure file itself
Common::File *txt = new Common::File();
if (!txt->open(getFilename())) {
@@ -119,8 +103,8 @@ bool Alan3::initialize() {
}
textFile = txt;
- // Check for a save being loaded directly from the launcher
- _saveSlot = ConfMan.hasKey("save_slot") ? ConfMan.getInt("save_slot") : -1;
+ // Set up the code file to point to the already opened game file
+ codfil = &_gameFile;
return true;
}
diff --git a/engines/glk/alan3/alan3.h b/engines/glk/alan3/alan3.h
index 73a9a03d0b..ffb6282ece 100644
--- a/engines/glk/alan3/alan3.h
+++ b/engines/glk/alan3/alan3.h
@@ -23,7 +23,7 @@
#ifndef GLK_ALAN3
#define GLK_ALAN3
-#include "glk/glk_api.h"
+#include "glk/alan3/glkio.h"
namespace Glk {
namespace Alan3 {
@@ -31,11 +31,10 @@ namespace Alan3 {
/**
* Alan3 game interpreter
*/
-class Alan3 : public GlkAPI {
+class Alan3 : public GlkIO {
public:
bool vm_exited_cleanly;
Common::String _advName;
- int _saveSlot;
bool _pendingLook;
private:
/**
diff --git a/engines/glk/alan3/debug.cpp b/engines/glk/alan3/debug.cpp
index 94f5bb4a96..4705010829 100644
--- a/engines/glk/alan3/debug.cpp
+++ b/engines/glk/alan3/debug.cpp
@@ -742,7 +742,7 @@ static void readCommand(CONTEXT, char buf[], size_t maxLen) {
do {
output("adbg> ");
- FUNC2(readline, flag, buf, maxLen)
+ FUNC2(g_io->readLine, flag, buf, maxLen)
if (!flag) {
newline();
quitGame();
diff --git a/engines/glk/alan3/glkio.cpp b/engines/glk/alan3/glkio.cpp
index ccf2a6716d..15c3278916 100644
--- a/engines/glk/alan3/glkio.cpp
+++ b/engines/glk/alan3/glkio.cpp
@@ -26,17 +26,38 @@
#include "glk/alan3/instance.h"
#include "glk/alan3/options.h"
#include "glk/alan3/output.h"
+#include "common/config-manager.h"
namespace Glk {
namespace Alan3 {
-winid_t glkMainWin;
-winid_t glkStatusWin;
-bool onStatusLine;
+GlkIO *g_io;
-void glkio_printf(const char *fmt, ...) {
+GlkIO::GlkIO(OSystem *syst, const GlkGameDescription &gameDesc) : GlkAPI(syst, gameDesc),
+ glkMainWin(nullptr), glkStatusWin(nullptr), onStatusLine(false), _saveSlot(-1) {
+ g_io = this;
+}
+
+bool GlkIO::initialize() {
+ // first, open a window for error output
+ glkMainWin = glk_window_open(0, 0, 0, wintype_TextBuffer, 0);
+ if (glkMainWin == nullptr)
+ return false;
+
+ glk_stylehint_set(wintype_TextGrid, style_User1, stylehint_ReverseColor, 1);
+ glkStatusWin = glk_window_open(glkMainWin, winmethod_Above |
+ winmethod_Fixed, 1, wintype_TextGrid, 0);
+ glk_set_window(glkMainWin);
+
+ // Check for a save being loaded directly from the launcher
+ _saveSlot = ConfMan.hasKey("save_slot") ? ConfMan.getInt("save_slot") : -1;
+
+ return true;
+}
+
+void GlkIO::print(const char *fmt, ...) {
// If there's a savegame being loaded from the launcher, ignore any text out
- if (g_vm->_saveSlot != -1)
+ if (_saveSlot != -1)
return;
va_list argp;
@@ -44,7 +65,7 @@ void glkio_printf(const char *fmt, ...) {
if (glkMainWin) {
char buf[1024]; /* FIXME: buf size should be foolproof */
vsprintf(buf, fmt, argp);
- g_vm->glk_put_string(buf);
+ glk_put_string(buf);
} else {
// assume stdio is available in this case only
Common::String str = Common::String::vformat(fmt, argp);
@@ -54,54 +75,54 @@ void glkio_printf(const char *fmt, ...) {
va_end(argp);
}
-void showImage(int image, int align) {
+void GlkIO::showImage(int image, int align) {
uint ecode;
- if ((g_vm->glk_gestalt(gestalt_Graphics, 0) == 1) &&
- (g_vm->glk_gestalt(gestalt_DrawImage, wintype_TextBuffer) == 1)) {
- g_vm->glk_window_flow_break(glkMainWin);
+ if ((glk_gestalt(gestalt_Graphics, 0) == 1) &&
+ (glk_gestalt(gestalt_DrawImage, wintype_TextBuffer) == 1)) {
+ glk_window_flow_break(glkMainWin);
printf("\n");
- ecode = g_vm->glk_image_draw(glkMainWin, image, imagealign_MarginLeft, 0);
+ ecode = glk_image_draw(glkMainWin, image, imagealign_MarginLeft, 0);
(void)ecode;
}
}
-void playSound(int sound) {
+void GlkIO::playSound(int sound) {
#ifdef GLK_MODULE_SOUND
static schanid_t soundChannel = NULL;
- if (g_vm->glk_gestalt(gestalt_Sound, 0) == 1) {
+ if (glk_gestalt(gestalt_Sound, 0) == 1) {
if (soundChannel == NULL)
- soundChannel = g_vm->glk_schannel_create(0);
+ soundChannel = glk_schannel_create(0);
if (soundChannel != NULL) {
- g_vm->glk_schannel_stop(soundChannel);
- (void)g_vm->glk_schannel_play(soundChannel, sound);
+ glk_schannel_stop(soundChannel);
+ (void)glk_schannel_play(soundChannel, sound);
}
}
#endif
}
-void setStyle(int style) {
+void GlkIO::setStyle(int style) {
switch (style) {
case NORMAL_STYLE:
- g_vm->glk_set_style(style_Normal);
+ glk_set_style(style_Normal);
break;
case EMPHASIZED_STYLE:
- g_vm->glk_set_style(style_Emphasized);
+ glk_set_style(style_Emphasized);
break;
case PREFORMATTED_STYLE:
- g_vm->glk_set_style(style_Preformatted);
+ glk_set_style(style_Preformatted);
break;
case ALERT_STYLE:
- g_vm->glk_set_style(style_Alert);
+ glk_set_style(style_Alert);
break;
case QUOTE_STYLE:
- g_vm->glk_set_style(style_BlockQuote);
+ glk_set_style(style_BlockQuote);
break;
}
}
-void statusline(CONTEXT) {
+void GlkIO::statusLine(CONTEXT) {
uint32 glkWidth;
char line[100];
int pcol = col;
@@ -110,13 +131,13 @@ void statusline(CONTEXT) {
if (glkStatusWin == NULL)
return;
- g_vm->glk_set_window(glkStatusWin);
- g_vm->glk_window_clear(glkStatusWin);
- g_vm->glk_window_get_size(glkStatusWin, &glkWidth, NULL);
+ glk_set_window(glkStatusWin);
+ glk_window_clear(glkStatusWin);
+ glk_window_get_size(glkStatusWin, &glkWidth, NULL);
onStatusLine = TRUE;
col = 1;
- g_vm->glk_window_move_cursor(glkStatusWin, 1, 0);
+ glk_window_move_cursor(glkStatusWin, 1, 0);
CALL1(sayInstance, where(HERO, /*TRUE*/ TRANSITIVE))
// TODO Add status message1 & 2 as author customizable messages
@@ -124,14 +145,14 @@ void statusline(CONTEXT) {
sprintf(line, "Score %d(%d)/%d moves", current.score, (int)header->maximumScore, current.tick);
else
sprintf(line, "%d moves", current.tick);
- g_vm->glk_window_move_cursor(glkStatusWin, glkWidth - strlen(line) - 1, 0);
- g_vm->glk_put_string(line);
+ glk_window_move_cursor(glkStatusWin, glkWidth - strlen(line) - 1, 0);
+ glk_put_string(line);
needSpace = FALSE;
col = pcol;
onStatusLine = FALSE;
- g_vm->glk_set_window(glkMainWin);
+ glk_set_window(glkMainWin);
}
@@ -144,32 +165,32 @@ void statusline(CONTEXT) {
*/
/* TODO - length of user buffer should be used */
-bool readline(CONTEXT, char *buffer, size_t maxLen) {
+bool GlkIO::readLine(CONTEXT, char *buffer, size_t maxLen) {
event_t event;
static bool readingCommands = FALSE;
static frefid_t commandFileRef;
static strid_t commandFile;
if (readingCommands) {
- if (g_vm->glk_get_line_stream(commandFile, buffer, maxLen) == 0) {
- g_vm->glk_stream_close(commandFile, NULL);
+ if (glk_get_line_stream(commandFile, buffer, maxLen) == 0) {
+ glk_stream_close(commandFile, NULL);
readingCommands = FALSE;
} else {
- g_vm->glk_set_style(style_Input);
+ glk_set_style(style_Input);
printf(buffer);
- g_vm->glk_set_style(style_Normal);
+ glk_set_style(style_Normal);
}
} else {
- g_vm->glk_request_line_event(glkMainWin, buffer, maxLen, 0);
+ glk_request_line_event(glkMainWin, buffer, maxLen, 0);
do {
- g_vm->glk_select(&event);
- if (g_vm->shouldQuit())
+ glk_select(&event);
+ if (shouldQuit())
LONG_JUMP0
switch (event.type) {
case evtype_Arrange:
- R0CALL0(statusline)
+ R0CALL0(g_io->statusLine)
break;
default:
@@ -178,14 +199,14 @@ bool readline(CONTEXT, char *buffer, size_t maxLen) {
} while (event.type != evtype_LineInput);
if (buffer[0] == '@') {
buffer[event.val1] = 0;
- commandFileRef = g_vm->glk_fileref_create_by_name(fileusage_InputRecord + fileusage_TextMode, &buffer[1], 0);
- commandFile = g_vm->glk_stream_open_file(commandFileRef, filemode_Read, 0);
+ commandFileRef = glk_fileref_create_by_name(fileusage_InputRecord + fileusage_TextMode, &buffer[1], 0);
+ commandFile = glk_stream_open_file(commandFileRef, filemode_Read, 0);
if (commandFile != NULL)
- if (g_vm->glk_get_line_stream(commandFile, buffer, maxLen) != 0) {
+ if (glk_get_line_stream(commandFile, buffer, maxLen) != 0) {
readingCommands = TRUE;
- g_vm->glk_set_style(style_Input);
+ glk_set_style(style_Input);
printf(buffer);
- g_vm->glk_set_style(style_Normal);
+ glk_set_style(style_Normal);
}
} else
buffer[event.val1] = 0;
diff --git a/engines/glk/alan3/glkio.h b/engines/glk/alan3/glkio.h
index 8876aec821..55c8ab6cab 100644
--- a/engines/glk/alan3/glkio.h
+++ b/engines/glk/alan3/glkio.h
@@ -23,30 +23,58 @@
#ifndef GLK_ALAN3_GLKIO
#define GLK_ALAN3_GLKIO
-#include "glk/alan3/alan3.h"
-#include "glk/alan3/jumps.h"
+#include "glk/glk_api.h"
#include "glk/windows.h"
+#include "glk/alan3/jumps.h"
namespace Glk {
namespace Alan3 {
-extern winid_t glkMainWin;
-extern winid_t glkStatusWin;
-extern bool onStatusLine;
+class GlkIO : public GlkAPI {
+private:
+ winid_t glkMainWin;
+ winid_t glkStatusWin;
+ int _saveSlot;
+public:
+ bool onStatusLine;
+protected:
+ /**
+ * Does initialization
+ */
+ bool initialize();
+public:
+ /**
+ * Constructor
+ */
+ GlkIO(OSystem *syst, const GlkGameDescription &gameDesc);
-#undef printf
-#define printf glkio_printf
-extern void glkio_printf(const char *, ...);
+ void print(const char *, ...);
+
+ void showImage(int image, int align);
-extern void showImage(int image, int align);
+ void playSound(int sound);
-extern void playSound(int sound);
+ void setStyle(int style);
-extern void setStyle(int style);
+ void statusLine(CONTEXT);
-extern void statusline(CONTEXT);
+ bool readLine(CONTEXT, char *usrBuf, size_t maxLen);
-extern bool readline(CONTEXT, char *usrBuf, size_t maxLen);
+ void clear() {
+ glk_window_clear(glkMainWin);
+ }
+
+ void flowBreak() {
+ /* Make a new paragraph, i.e one empty line (one or two newlines). */
+ if (glk_gestalt(gestalt_Graphics, 0) == 1)
+ glk_window_flow_break(glkMainWin);
+ }
+};
+
+extern GlkIO *g_io;
+
+#undef printf
+#define printf g_io->print
} // End of namespace Alan3
} // End of namespace Glk
diff --git a/engines/glk/alan3/inter.cpp b/engines/glk/alan3/inter.cpp
index 002a580e4c..5ee5ea976e 100644
--- a/engines/glk/alan3/inter.cpp
+++ b/engines/glk/alan3/inter.cpp
@@ -559,7 +559,7 @@ void interpret(CONTEXT, Aaddr adr) {
if (traceInstructionOption) {
printf("STYLE \t%7ld\t\t\"", (long)style);
}
- setStyle(style);
+ g_io->setStyle(style);
break;
}
@@ -829,14 +829,14 @@ void interpret(CONTEXT, Aaddr adr) {
Aint align = pop(stack);
if (traceInstructionOption)
printf("SHOW \t%7ld, %7ld\t\t\t\t", (long)image, (long)align);
- showImage(image, align);
+ g_io->showImage(image, align);
break;
}
case I_PLAY: {
Aint sound = pop(stack);
if (traceInstructionOption)
printf("PLAY \t%7ld\t\t\t\t", (long)sound);
- playSound(sound);
+ g_io->playSound(sound);
break;
}
case I_LOCATE: {
diff --git a/engines/glk/alan3/output.cpp b/engines/glk/alan3/output.cpp
index 405ca2e270..0d946114dc 100644
--- a/engines/glk/alan3/output.cpp
+++ b/engines/glk/alan3/output.cpp
@@ -78,13 +78,13 @@ static int updateColumn(int currentColumn, const char *string) {
/*======================================================================*/
void setSubHeaderStyle(void) {
- g_vm->glk_set_style(style_Subheader);
+ g_io->glk_set_style(style_Subheader);
}
/*======================================================================*/
void setNormalStyle(void) {
- g_vm->glk_set_style(style_Normal);
+ g_io->glk_set_style(style_Normal);
}
/*======================================================================*/
@@ -97,9 +97,7 @@ void newline(void) {
/*======================================================================*/
void para(void) {
- /* Make a new paragraph, i.e one empty line (one or two newlines). */
- if (g_vm->glk_gestalt(gestalt_Graphics, 0) == 1)
- g_vm->glk_window_flow_break(glkMainWin);
+ g_io->flowBreak();
if (col != 1)
newline();
@@ -110,7 +108,7 @@ void para(void) {
/*======================================================================*/
void clear(void) {
- g_vm->glk_window_clear(glkMainWin);
+ g_io->clear();
}
@@ -135,7 +133,7 @@ void printAndLog(const char *string) {
char *stringPart;
printf("%s", string);
- if (!onStatusLine && transcriptOption) {
+ if (!g_io->onStatusLine && transcriptOption) {
// TODO Is this assuming only 70-char wide windows for GLK?
if ((int)strlen(string) > 70 - column) {
stringCopy = strdup(string); /* Make sure we can write NULLs */
@@ -144,16 +142,16 @@ void printAndLog(const char *string) {
int p;
for (p = 70 - column; p > 0 && !isspace((int)stringPart[p]); p--);
stringPart[p] = '\0';
- g_vm->glk_put_string_stream(logFile, stringPart);
- g_vm->glk_put_char_stream(logFile, '\n');
+ g_io->glk_put_string_stream(logFile, stringPart);
+ g_io->glk_put_char_stream(logFile, '\n');
column = 0;
stringPart = &stringPart[p + 1];
}
- g_vm->glk_put_string_stream(logFile, stringPart);
+ g_io->glk_put_string_stream(logFile, stringPart);
column = updateColumn(column, stringPart);
free(stringCopy);
} else {
- g_vm->glk_put_string_stream(logFile, string);
+ g_io->glk_put_string_stream(logFile, string);
column = updateColumn(column, string);
}
}
@@ -442,7 +440,7 @@ bool confirm(CONTEXT, MsgKind msgno) {
it could be affirmative, but for now any input is NOT! */
printMessage(msgno);
- R0FUNC2(readline, flag, buf, 80)
+ R0FUNC2(g_io->readLine, flag, buf, 80)
if (!flag)
return TRUE;
col = 1;
diff --git a/engines/glk/alan3/scan.cpp b/engines/glk/alan3/scan.cpp
index 0875acbcc6..8f3ab80cbd 100644
--- a/engines/glk/alan3/scan.cpp
+++ b/engines/glk/alan3/scan.cpp
@@ -135,7 +135,7 @@ static char *gettoken(char *txtBuf) {
static void getLine(CONTEXT) {
para();
do {
- CALL0(statusline)
+ CALL0(g_io->statusLine)
if (header->prompt) {
anyOutput = FALSE;
@@ -148,7 +148,7 @@ static void getLine(CONTEXT) {
printAndLog("> ");
bool flag;
- FUNC2(readline, flag, buf, 255);
+ FUNC2(g_io->readLine, flag, buf, 255);
if (!flag) {
newline();
quitGame();
@@ -158,8 +158,8 @@ static void getLine(CONTEXT) {
anyOutput = FALSE;
if (transcriptOption || logOption) {
// TODO: Refactor out the logging to log.c?
- g_vm->glk_put_string_stream(logFile, buf);
- g_vm->glk_put_char_stream(logFile, '\n');
+ g_io->glk_put_string_stream(logFile, buf);
+ g_io->glk_put_char_stream(logFile, '\n');
}
/* If the player input an empty command he forfeited his command */
if (strlen(buf) == 0) {
diff --git a/engines/glk/alan3/utils.cpp b/engines/glk/alan3/utils.cpp
index 38176e1924..acbf8e490a 100644
--- a/engines/glk/alan3/utils.cpp
+++ b/engines/glk/alan3/utils.cpp
@@ -52,7 +52,7 @@ void terminate(CONTEXT, int code) {
if (memory)
deallocate(memory);
- g_vm->glk_exit();
+ g_io->glk_exit();
LONG_JUMP
}
@@ -75,7 +75,7 @@ void usage(const char *programName) {
printf(" %s [<switches>] <adventure>\n\n", programName);
printf("where the possible optional switches are:\n");
- g_vm->glk_set_style(style_Preformatted);
+ g_io->glk_set_style(style_Preformatted);
printf(" -v verbose mode\n");
printf(" -l log transcript to a file\n");
printf(" -c log player commands to a file\n");
@@ -84,7 +84,7 @@ void usage(const char *programName) {
printf(" -t[<n>] trace game execution, higher <n> gives more trace\n");
printf(" -i ignore version and checksum errors\n");
printf(" -r make regression test easier (don't timestamp, page break, randomize...)\n");
- g_vm->glk_set_style(style_Normal);
+ g_io->glk_set_style(style_Normal);
}