diff options
author | Paul Gilbert | 2019-06-20 21:20:22 -0700 |
---|---|---|
committer | Paul Gilbert | 2019-06-22 14:40:49 -0700 |
commit | ad1cecaeac5d54b0973d6c7edce8181cb965ff68 (patch) | |
tree | 9ffc7a6a3f6e5e1e6f33ce997662a486fd122be4 /engines/glk/alan2/alan2.cpp | |
parent | df7465232108c15ca613db0b5e709e34378dbd8c (diff) | |
download | scummvm-rg350-ad1cecaeac5d54b0973d6c7edce8181cb965ff68.tar.gz scummvm-rg350-ad1cecaeac5d54b0973d6c7edce8181cb965ff68.tar.bz2 scummvm-rg350-ad1cecaeac5d54b0973d6c7edce8181cb965ff68.zip |
GLK: ALAN2: Added savegame code
Diffstat (limited to 'engines/glk/alan2/alan2.cpp')
-rw-r--r-- | engines/glk/alan2/alan2.cpp | 69 |
1 files changed, 64 insertions, 5 deletions
diff --git a/engines/glk/alan2/alan2.cpp b/engines/glk/alan2/alan2.cpp index c9625a7076..73b8a5e1a3 100644 --- a/engines/glk/alan2/alan2.cpp +++ b/engines/glk/alan2/alan2.cpp @@ -21,13 +21,15 @@ */ #include "glk/alan2/alan2.h" +#include "glk/alan2/exe.h" #include "glk/alan2/main.h" #include "glk/alan2/glkio.h" +#include "common/system.h" #include "common/config-manager.h" #include "common/translation.h" #include "common/error.h" #include "common/scummsys.h" -#include "common/system.h" +#include "common/serializer.h" #include "glk/glk.h" #include "glk/streams.h" @@ -75,13 +77,70 @@ void Alan2::initialize() { } Common::Error Alan2::readSaveData(Common::SeekableReadStream *rs) { - // TODO - return Common::kReadingFailed; + Common::Serializer s(rs, nullptr); + synchronizeSave(s); + + return Common::kNoError; } Common::Error Alan2::writeGameData(Common::WriteStream *ws) { - // TODO - return Common::kWritingFailed; + Common::Serializer s(nullptr, ws); + synchronizeSave(s); + + ws->flush(); + return Common::kNoError; +} + +void Alan2::synchronizeSave(Common::Serializer &s) { + AtrElem *atr; + int i; + + // Sync current values + cur.synchronize(s); + + // Save actors + for (i = ACTMIN; i <= ACTMAX; ++i) { + s.syncAsSint32LE(acts[i-ACTMIN].loc); + s.syncAsSint32LE(acts[i-ACTMIN].script); + s.syncAsSint32LE(acts[i-ACTMIN].step); + s.syncAsSint32LE(acts[i-ACTMIN].count); + + if (acts[i-ACTMIN].atrs) { + for (atr = (AtrElem *)addrTo(acts[i-ACTMIN].atrs); !endOfTable(atr); ++atr) + s.syncAsSint32LE(atr->val); + } + } + + // Sync locations + for (i = LOCMIN; i <= LOCMAX; ++i) { + s.syncAsSint32LE(locs[i-LOCMIN].describe); + if (locs[i-LOCMIN].atrs) + for (atr = (AtrElem *)addrTo(locs[i-LOCMIN].atrs); !endOfTable(atr); atr++) + s.syncAsSint32LE(atr->val); + } + + // Sync objects + for (i = OBJMIN; i <= OBJMAX; ++i) { + s.syncAsSint32LE(objs[i-OBJMIN].loc); + if (objs[i-OBJMIN].atrs) + for (atr = (AtrElem *)addrTo(objs[i-OBJMIN].atrs); !endOfTable(atr); atr++) + s.syncAsSint32LE(atr->val); + } + + // Sync the event queue + if (s.isSaving()) { + eventq[etop].time = 0; // Mark the top + for (i = 0; i <= etop; ++i) + eventq[i].synchronize(s); + } else { + for (etop = 0; eventq[etop - 1].time; ++etop) + eventq[etop].synchronize(s); + --etop; + } + + // Sync scores + for (i = 0; scores[i] != EOF; i++) + s.syncAsSint32LE(scores[i]); } bool Alan2::is_gamefile_valid() { |