Skip to content

Commit

Permalink
GLK: ALAN3: Add loading savegame from launcher
Browse files Browse the repository at this point in the history
  • Loading branch information
dreammaster committed Jul 6, 2019
1 parent 4de30c9 commit 3165fa6
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 17 deletions.
3 changes: 1 addition & 2 deletions engines/glk/alan3/alan3.cpp
Expand Up @@ -41,8 +41,7 @@ namespace Alan3 {

Alan3 *g_vm = nullptr;

Alan3::Alan3(OSystem *syst, const GlkGameDescription &gameDesc) : GlkIO(syst, gameDesc),
vm_exited_cleanly(false), _pendingLook(false) {
Alan3::Alan3(OSystem *syst, const GlkGameDescription &gameDesc) : GlkIO(syst, gameDesc) {
g_vm = this;

// main
Expand Down
4 changes: 1 addition & 3 deletions engines/glk/alan3/alan3.h
Expand Up @@ -33,9 +33,7 @@ namespace Alan3 {
*/
class Alan3 : public GlkIO {
public:
bool vm_exited_cleanly;
Common::String _advName;
bool _pendingLook;
private:
/**
* Initialization
Expand Down Expand Up @@ -73,7 +71,7 @@ class Alan3 : public GlkIO {
* Save the game. The passed write stream represents access to the UMem chunk
* in the Quetzal save file that will be created
*/
virtual Common::Error writeGameData(Common::WriteStream *ws) override;
virtual Common::Error writeGameData(Common::WriteStream *ws) override;;
};

extern Alan3 *g_vm;
Expand Down
39 changes: 29 additions & 10 deletions engines/glk/alan3/glkio.cpp
Expand Up @@ -62,21 +62,21 @@ void GlkIO::print(const char *fmt, ...) {

va_list argp;
va_start(argp, fmt);
Common::String str = Common::String::vformat(fmt, argp);
va_end(argp);

if (glkMainWin) {
char buf[1024]; /* FIXME: buf size should be foolproof */
vsprintf(buf, fmt, argp);
glk_put_string(buf);
glk_put_string(str.c_str());
} else {
// assume stdio is available in this case only
Common::String str = Common::String::vformat(fmt, argp);
warning(fmt, argp);
warning("%s", str.c_str());
}

va_end(argp);
}

void GlkIO::showImage(int image, int align) {
uint ecode;
if (_saveSlot != -1)
return;

if ((glk_gestalt(gestalt_Graphics, 0) == 1) &&
(glk_gestalt(gestalt_DrawImage, wintype_TextBuffer) == 1)) {
Expand All @@ -88,6 +88,9 @@ void GlkIO::showImage(int image, int align) {
}

void GlkIO::playSound(int sound) {
if (_saveSlot != -1)
return;

#ifdef GLK_MODULE_SOUND
static schanid_t soundChannel = NULL;

Expand Down Expand Up @@ -127,8 +130,7 @@ void GlkIO::statusLine(CONTEXT) {
char line[100];
int pcol = col;

if (!statusLineOption) return;
if (glkStatusWin == NULL)
if (!statusLineOption || _saveSlot != -1 || glkStatusWin == nullptr)
return;

glk_set_window(glkStatusWin);
Expand Down Expand Up @@ -171,7 +173,13 @@ bool GlkIO::readLine(CONTEXT, char *buffer, size_t maxLen) {
static frefid_t commandFileRef;
static strid_t commandFile;

if (readingCommands) {
if (_saveSlot != -1) {
// Return a "restore" command
forcePrint("> ");
forcePrint("restore\n");
strcpy(buffer, "restore");

} else if (readingCommands) {
if (glk_get_line_stream(commandFile, buffer, maxLen) == 0) {
glk_stream_close(commandFile, NULL);
readingCommands = FALSE;
Expand All @@ -180,6 +188,7 @@ bool GlkIO::readLine(CONTEXT, char *buffer, size_t maxLen) {
printf(buffer);
glk_set_style(style_Normal);
}

} else {
glk_request_line_event(glkMainWin, buffer, maxLen, 0);

Expand Down Expand Up @@ -214,5 +223,15 @@ bool GlkIO::readLine(CONTEXT, char *buffer, size_t maxLen) {
return TRUE;
}

Common::Error GlkIO::loadGame() {
if (_saveSlot != -1) {
int saveSlot = _saveSlot;
_saveSlot = -1;
return loadGameState(saveSlot);
} else {
return GlkAPI::loadGame();
}
}

} // End of namespace Alan3
} // End of namespace Glk
20 changes: 18 additions & 2 deletions engines/glk/alan3/glkio.h
Expand Up @@ -48,7 +48,17 @@ class GlkIO : public GlkAPI {
*/
GlkIO(OSystem *syst, const GlkGameDescription &gameDesc);

void print(const char *, ...);
/**
* Print a string to the window
*/
void print(const char *fmt, ...);

/**
* Outputs a string to the window, even during startup
*/
void forcePrint(const char *str) {
glk_put_string(str);
}

void showImage(int image, int align);

Expand All @@ -66,9 +76,15 @@ class GlkIO : public GlkAPI {

void flowBreak() {
/* Make a new paragraph, i.e one empty line (one or two newlines). */
if (glk_gestalt(gestalt_Graphics, 0) == 1)
if (_saveSlot == -1 && glk_gestalt(gestalt_Graphics, 0) == 1)
glk_window_flow_break(glkMainWin);
}

/**
* If a savegame was selected to be loaded from the launcher, then load it.
* Otherwise, prompt the user for a savegame to load, and then load it
*/
Common::Error loadGame();
};

extern GlkIO *g_io;
Expand Down
1 change: 1 addition & 0 deletions engines/glk/alan3/inter.cpp
Expand Up @@ -21,6 +21,7 @@
*/

#include "glk/alan3/inter.h"
#include "glk/alan3/alan3.h"
#include "glk/alan3/current.h"
#include "glk/alan3/exe.h"
#include "glk/alan3/syserr.h"
Expand Down

0 comments on commit 3165fa6

Please sign in to comment.