GLK: ALAN2: Add loading savegames from launcher, deinitialization code

This commit is contained in:
Paul Gilbert 2019-06-23 16:15:00 -07:00
parent e7fbd9268c
commit 5eb0390aca
11 changed files with 80 additions and 117 deletions

View File

@ -39,17 +39,18 @@ namespace Alan2 {
Alan2 *g_vm = nullptr;
Alan2::Alan2(OSystem *syst, const GlkGameDescription &gameDesc) : GlkAPI(syst, gameDesc),
vm_exited_cleanly(false), _restartFlag(false) {
vm_exited_cleanly(false), _restartFlag(false), _saveSlot(-1), _pendingLook(false) {
g_vm = this;
txtfil = nullptr;
logfil = nullptr;
memory = nullptr;
}
void Alan2::runGame() {
Common::String gameFileName = _gameFile.getName();
if (initialize())
Glk::Alan2::run();
if (!initialize())
return;
Glk::Alan2::run();
deinitialize();
}
bool Alan2::initialize() {
@ -91,9 +92,19 @@ bool Alan2::initialize() {
return false;
}
// Check for a save being loaded directly from the launcher
_saveSlot = ConfMan.hasKey("save_slot") ? ConfMan.getInt("save_slot") : -1;
return true;
}
void Alan2::deinitialize() {
free(memory);
delete txtfil;
delete logfil;
}
Common::Error Alan2::readSaveData(Common::SeekableReadStream *rs) {
Common::Serializer s(rs, nullptr);
synchronizeSave(s);

View File

@ -40,12 +40,19 @@ private:
public:
bool vm_exited_cleanly;
Common::String _advName;
int _saveSlot;
bool _pendingLook;
private:
/**
* Initialization
*/
bool initialize();
/**
* Deinitialization
*/
void deinitialize();
/**
* Synchronize data to or from a save file
*/

View File

@ -28,8 +28,6 @@
#include "glk/alan2/inter.h"
#include "glk/alan2/main.h"
#include "glk/alan2/parse.h"
#include "glk/alan2/readline.h"
namespace Glk {
namespace Alan2 {

View File

@ -23,10 +23,10 @@
#include "glk/alan2/alan2.h"
#include "glk/alan2/types.h"
#include "glk/alan2/exe.h"
#include "glk/alan2/glkio.h"
#include "glk/alan2/inter.h"
#include "glk/alan2/main.h"
#include "glk/alan2/parse.h"
#include "glk/alan2/readline.h"
#include "glk/alan2/stack.h"
#include "glk/alan2/decode.h"

View File

@ -23,6 +23,7 @@
#include "glk/glk.h"
#include "glk/alan2/alan2.h"
#include "glk/alan2/glkio.h"
#include "glk/alan2/main.h"
namespace Glk {
namespace Alan2 {
@ -31,6 +32,10 @@ winid_t glkMainWin;
winid_t glkStatusWin;
void glkio_printf(const char *fmt, ...) {
// If there's a savegame being loaded from the launcher, ignore any text out
if (g_vm->_saveSlot != -1)
return;
va_list argp;
va_start(argp, fmt);
if (glkMainWin) {
@ -46,6 +51,43 @@ void glkio_printf(const char *fmt, ...) {
va_end(argp);
}
/*======================================================================
readline()
Read a line from the user, with history and editing
*/
/* 4f - length of user buffer should be used */
Boolean readline(char usrbuf[]) {
if (g_vm->_pendingLook) {
g_vm->_pendingLook = false;
glkio_printf("look\n");
strcpy(usrbuf, "look");
} else {
event_t event;
g_vm->glk_request_line_event(glkMainWin, usrbuf, 255, 0);
/* FIXME: buffer size should be infallible: all existing calls use 256 or
80 character buffers, except parse which uses LISTLEN (currently 100)
*/
do {
g_vm->glk_select(&event);
if (evtype_Arrange == event.type)
statusline();
if (g_vm->shouldQuit())
return false;
} while (event.type != evtype_LineInput);
usrbuf[event.val1] = 0;
}
return TRUE;
}
} // End of namespace Alan2
} // End of namespace Glk

View File

@ -27,6 +27,7 @@
*/
#include "glk/windows.h"
#include "glk/alan2/types.h"
namespace Glk {
namespace Alan2 {
@ -41,6 +42,11 @@ extern winid_t glkStatusWin;
void glkio_printf(const char *, ...);
#define LINELENGTH 80
#define HISTORYLENGTH 20
extern Boolean readline(char usrbuf[]);
} // End of namespace Alan2
} // End of namespace Glk

View File

@ -116,9 +116,6 @@ Boolean skipsp = FALSE;
*/
void terminate(CONTEXT, int code) {
newline();
free(memory);
if (logflg)
fclose(logfil);
g_vm->glk_exit();
LONG_JUMP
@ -1404,6 +1401,13 @@ void run() {
g_vm->setRestart(false);
init();
if (g_vm->_saveSlot != -1) {
if (g_vm->loadGameState(g_vm->_saveSlot).getCode() != Common::kNoError)
return;
g_vm->_saveSlot = -1;
g_vm->_pendingLook = true;
}
Context ctx;
while (!g_vm->shouldQuit() && !g_vm->shouldRestart()) {
if (!ctx._break) {

View File

@ -28,7 +28,6 @@
#include "glk/alan2/main.h"
#include "glk/alan2/params.h"
#include "glk/alan2/parse.h"
#include "glk/alan2/readline.h"
#include "glk/alan2/term.h"
#include "glk/alan2/types.h"

View File

@ -1,62 +0,0 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "glk/alan2/alan2.h"
#include "glk/alan2/types.h"
#include "glk/alan2/glkio.h"
#include "glk/alan2/main.h"
#include "glk/alan2/readline.h"
namespace Glk {
namespace Alan2 {
/*======================================================================
readline()
Read a line from the user, with history and editing
*/
/* 4f - length of user buffer should be used */
Boolean readline(char usrbuf[]) {
event_t event;
g_vm->glk_request_line_event(glkMainWin, usrbuf, 255, 0);
/* FIXME: buffer size should be infallible: all existing calls use 256 or
80 character buffers, except parse which uses LISTLEN (currently 100)
*/
do {
g_vm->glk_select(&event);
if (evtype_Arrange == event.type)
statusline();
if (g_vm->shouldQuit())
return false;
} while (event.type != evtype_LineInput);
usrbuf[event.val1] = 0;
return TRUE;
}
} // End of namespace Alan2
} // End of namespace Glk

View File

@ -1,41 +0,0 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef GLK_ALAN2_READLINE
#define GLK_ALAN2_READLINE
/* Header file for user input, history andediting support */
#include "glk/alan2/types.h"
namespace Glk {
namespace Alan2 {
#define LINELENGTH 80
#define HISTORYLENGTH 20
extern Boolean readline(char usrbuf[]);
} // End of namespace Alan2
} // End of namespace Glk
#endif

View File

@ -43,7 +43,6 @@ MODULE_OBJS := \
alan2/main.o \
alan2/params.o \
alan2/parse.o \
alan2/readline.o \
alan2/reverse.o \
alan2/rules.o \
alan2/stack.o \