diff options
-rw-r--r-- | common/serializer.h (renamed from engines/tinsel/serializer.h) | 43 | ||||
-rw-r--r-- | common/stream.h | 4 | ||||
-rw-r--r-- | engines/tinsel/actors.cpp | 4 | ||||
-rw-r--r-- | engines/tinsel/dialogs.cpp | 4 | ||||
-rw-r--r-- | engines/tinsel/dialogs.h | 8 | ||||
-rw-r--r-- | engines/tinsel/pcode.cpp | 6 | ||||
-rw-r--r-- | engines/tinsel/pcode.h | 7 | ||||
-rw-r--r-- | engines/tinsel/polygons.cpp | 4 | ||||
-rw-r--r-- | engines/tinsel/saveload.cpp | 36 | ||||
-rw-r--r-- | engines/tinsel/timers.cpp | 4 | ||||
-rw-r--r-- | engines/tinsel/timers.h | 8 | ||||
-rw-r--r-- | engines/tinsel/tinsel.cpp | 4 |
12 files changed, 81 insertions, 51 deletions
diff --git a/engines/tinsel/serializer.h b/common/serializer.h index cfb528776f..24af9dc6f5 100644 --- a/engines/tinsel/serializer.h +++ b/common/serializer.h @@ -21,17 +21,15 @@ * $URL$ * $Id$ * - * Handles timers. */ -#ifndef TINSEL_SERIALIZER_H -#define TINSEL_SERIALIZER_H +#ifndef COMMON_SERIALIZER_H +#define COMMON_SERIALIZER_H -#include "common/scummsys.h" -#include "common/savefile.h" +#include "common/stream.h" +#include "common/str.h" - -namespace Tinsel { +namespace Common { #define SYNC_AS(SUFFIX,TYPE,SIZE) \ @@ -51,7 +49,7 @@ namespace Tinsel { // TODO: Inspired by the SCUMM engine -- move to common/ code and use in more engines? class Serializer { public: - Serializer(Common::SeekableReadStream *in, Common::OutSaveFile *out) + Serializer(Common::SeekableReadStream *in, Common::WriteStream *out) : _loadStream(in), _saveStream(out), _bytesSynced(0) { assert(in || out); } @@ -69,14 +67,33 @@ public: _bytesSynced += size; } + /** + * Sync a C-string, by treating it as a zero-terminated byte sequence. + */ + void syncString(Common::String &str) { + if (_loadStream) { + char c; + str.clear(); + while ((c = _loadStream->readByte())) { + str += c; + _bytesSynced++; + } + _bytesSynced++; + } else { + _saveStream->writeString(str); + _saveStream->writeByte(0); + _bytesSynced += str.size() + 1; + } + } + void skip(uint32 size) { + _bytesSynced += size; if (_loadStream) _loadStream->skip(size); else { while (size--) _saveStream->writeByte(0); } - _bytesSynced += size; } SYNC_AS(Byte, byte, 1) @@ -93,7 +110,7 @@ public: protected: Common::SeekableReadStream *_loadStream; - Common::OutSaveFile *_saveStream; + Common::WriteStream *_saveStream; uint _bytesSynced; }; @@ -132,10 +149,12 @@ public: class Serializable { public: virtual ~Serializable() {} - virtual void saveLoadWithSerializer(Serializer *ser) = 0; + + // Maybe rename this method to "syncWithSerializer" or "syncUsingSerializer" ? + virtual void saveLoadWithSerializer(Serializer &ser) = 0; }; -} // end of namespace Tinsel +} // end of namespace Common #endif diff --git a/common/stream.h b/common/stream.h index f98ad6aa92..b0fc9f5a8b 100644 --- a/common/stream.h +++ b/common/stream.h @@ -154,6 +154,10 @@ public: writeUint32BE((uint32)value); } + /** + * Write the given string to the stream. + * This writes str.size() characters, but no terminating zero byte. + */ void writeString(const String &str); }; diff --git a/engines/tinsel/actors.cpp b/engines/tinsel/actors.cpp index 279c482376..e9d0c9f79f 100644 --- a/engines/tinsel/actors.cpp +++ b/engines/tinsel/actors.cpp @@ -39,7 +39,7 @@ #include "tinsel/polygons.h" #include "tinsel/rince.h" #include "tinsel/sched.h" -#include "tinsel/serializer.h" +#include "common/serializer.h" #include "tinsel/sysvar.h" #include "tinsel/tinsel.h" #include "tinsel/token.h" @@ -1417,7 +1417,7 @@ void ActorsLife(int ano, bool bAlive) { } -void syncAllActorsAlive(Serializer &s) { +void syncAllActorsAlive(Common::Serializer &s) { for (int i = 0; i < MAX_SAVED_ALIVES; i++) { s.syncAsByte(actorInfo[i].bAlive); s.syncAsByte(actorInfo[i].tagged); diff --git a/engines/tinsel/dialogs.cpp b/engines/tinsel/dialogs.cpp index 2987e091b3..c9487a62e3 100644 --- a/engines/tinsel/dialogs.cpp +++ b/engines/tinsel/dialogs.cpp @@ -50,7 +50,7 @@ #include "tinsel/polygons.h" #include "tinsel/savescn.h" #include "tinsel/sched.h" -#include "tinsel/serializer.h" +#include "common/serializer.h" #include "tinsel/sound.h" #include "tinsel/strres.h" #include "tinsel/sysvar.h" @@ -5475,7 +5475,7 @@ void SetObjectFilm(int object, SCNHANDLE hFilm) { /** * (Un)serialize the inventory data for save/restore game. */ -void syncInvInfo(Serializer &s) { +void syncInvInfo(Common::Serializer &s) { for (int i = 0; i < NUM_INV; i++) { s.syncAsSint32LE(InvD[i].MinHicons); s.syncAsSint32LE(InvD[i].MinVicons); diff --git a/engines/tinsel/dialogs.h b/engines/tinsel/dialogs.h index 670f695a06..91fb7f3240 100644 --- a/engines/tinsel/dialogs.h +++ b/engines/tinsel/dialogs.h @@ -31,9 +31,11 @@ #include "tinsel/dw.h" #include "tinsel/events.h" // for PLR_EVENT, PLR_EVENT -namespace Tinsel { +namespace Common { + class Serializer; +} -class Serializer; +namespace Tinsel { enum { INV_OPEN = -1, // DW1 only @@ -146,7 +148,7 @@ bool IsInInventory(int object, int invnum); void KillInventory(void); -void syncInvInfo(Serializer &s); +void syncInvInfo(Common::Serializer &s); int InvGetLimit(int invno); void InvSetLimit(int invno, int n); diff --git a/engines/tinsel/pcode.cpp b/engines/tinsel/pcode.cpp index 33550b39e8..a9c6f43d85 100644 --- a/engines/tinsel/pcode.cpp +++ b/engines/tinsel/pcode.cpp @@ -31,7 +31,7 @@ #include "tinsel/dialogs.h" // for inventory id's #include "tinsel/pcode.h" // opcodes etc. #include "tinsel/scn.h" // FindChunk() -#include "tinsel/serializer.h" +#include "common/serializer.h" #include "tinsel/timers.h" #include "tinsel/tinlib.h" // Library routines #include "tinsel/tinsel.h" @@ -356,7 +356,7 @@ void FreeGlobals(void) { /** * (Un)serialize the global data for save/restore game. */ -void syncGlobInfo(Serializer &s) { +void syncGlobInfo(Common::Serializer &s) { for (int i = 0; i < numGlobals; i++) { s.syncAsSint32LE(pGlobals[i]); } @@ -365,7 +365,7 @@ void syncGlobInfo(Serializer &s) { /** * (Un)serialize an interpreter context for save/restore game. */ -void INT_CONTEXT::syncWithSerializer(Serializer &s) { +void INT_CONTEXT::syncWithSerializer(Common::Serializer &s) { if (s.isLoading()) { // Null out the pointer fields pProc = NULL; diff --git a/engines/tinsel/pcode.h b/engines/tinsel/pcode.h index 0c75cc0df1..4bdfcf5626 100644 --- a/engines/tinsel/pcode.h +++ b/engines/tinsel/pcode.h @@ -30,10 +30,13 @@ #include "tinsel/events.h" // for TINSEL_EVENT #include "tinsel/sched.h" // for PROCESS +namespace Common { + class Serializer; +} + namespace Tinsel { // forward declaration -class Serializer; struct INV_OBJECT; enum RESUME_STATE { @@ -79,7 +82,7 @@ struct INT_CONTEXT { RESCODE resumeCode; RESUME_STATE resumeState; - void syncWithSerializer(Serializer &s); + void syncWithSerializer(Common::Serializer &s); }; typedef INT_CONTEXT *PINT_CONTEXT; diff --git a/engines/tinsel/polygons.cpp b/engines/tinsel/polygons.cpp index cb5b21f0c0..8be174c779 100644 --- a/engines/tinsel/polygons.cpp +++ b/engines/tinsel/polygons.cpp @@ -30,7 +30,7 @@ #include "tinsel/polygons.h" #include "tinsel/rince.h" #include "tinsel/sched.h" -#include "tinsel/serializer.h" +#include "common/serializer.h" #include "tinsel/tinsel.h" #include "tinsel/token.h" @@ -1198,7 +1198,7 @@ void RebootDeadTags(void) { /** * (Un)serialize the dead tag and exit data for save/restore game. */ -void syncPolyInfo(Serializer &s) { +void syncPolyInfo(Common::Serializer &s) { int i; for (i = 0; i < MAX_SCENES; i++) { diff --git a/engines/tinsel/saveload.cpp b/engines/tinsel/saveload.cpp index 13c1fc58f2..b17ee93d4d 100644 --- a/engines/tinsel/saveload.cpp +++ b/engines/tinsel/saveload.cpp @@ -30,11 +30,11 @@ #include "tinsel/dw.h" #include "tinsel/rince.h" #include "tinsel/savescn.h" -#include "tinsel/serializer.h" #include "tinsel/timers.h" #include "tinsel/tinlib.h" #include "tinsel/tinsel.h" +#include "common/serializer.h" #include "common/savefile.h" namespace Tinsel { @@ -73,16 +73,16 @@ SRSTATE SRstate = SR_IDLE; //----------------- EXTERN FUNCTIONS -------------------- // in DOS_DW.C -extern void syncSCdata(Serializer &s); +extern void syncSCdata(Common::Serializer &s); // in DOS_MAIN.C //char HardDriveLetter(void); // in PCODE.C -extern void syncGlobInfo(Serializer &s); +extern void syncGlobInfo(Common::Serializer &s); // in POLYGONS.C -extern void syncPolyInfo(Serializer &s); +extern void syncPolyInfo(Common::Serializer &s); //----------------- LOCAL DEFINES -------------------- @@ -120,7 +120,7 @@ static char *SaveSceneSsData = 0; // points to 'SAVED_DATA ssdata[MAX_NEST]' void setNeedLoad() { NeedLoad = true; } -static void syncTime(Serializer &s, struct tm &t) { +static void syncTime(Common::Serializer &s, struct tm &t) { s.syncAsUint16LE(t.tm_year); s.syncAsByte(t.tm_mon); s.syncAsByte(t.tm_mday); @@ -134,7 +134,7 @@ static void syncTime(Serializer &s, struct tm &t) { } } -static bool syncSaveGameHeader(Serializer &s, SaveGameHeader &hdr) { +static bool syncSaveGameHeader(Common::Serializer &s, SaveGameHeader &hdr) { s.syncAsUint32LE(hdr.id); s.syncAsUint32LE(hdr.size); s.syncAsUint32LE(hdr.ver); @@ -153,7 +153,7 @@ static bool syncSaveGameHeader(Serializer &s, SaveGameHeader &hdr) { return true; } -static void syncSavedMover(Serializer &s, SAVED_MOVER &sm) { +static void syncSavedMover(Common::Serializer &s, SAVED_MOVER &sm) { SCNHANDLE *pList[3] = { (SCNHANDLE *)&sm.walkReels, (SCNHANDLE *)&sm.standReels, (SCNHANDLE *)&sm.talkReels }; @@ -178,7 +178,7 @@ static void syncSavedMover(Serializer &s, SAVED_MOVER &sm) { } } -static void syncSavedActor(Serializer &s, SAVED_ACTOR &sa) { +static void syncSavedActor(Common::Serializer &s, SAVED_ACTOR &sa) { s.syncAsUint16LE(sa.actorID); s.syncAsUint16LE(sa.zFactor); s.syncAsUint32LE(sa.bAlive); @@ -188,33 +188,33 @@ static void syncSavedActor(Serializer &s, SAVED_ACTOR &sa) { s.syncAsUint16LE(sa.presPlayY); } -extern void syncAllActorsAlive(Serializer &s); +extern void syncAllActorsAlive(Common::Serializer &s); -static void syncNoScrollB(Serializer &s, NOSCROLLB &ns) { +static void syncNoScrollB(Common::Serializer &s, NOSCROLLB &ns) { s.syncAsSint32LE(ns.ln); s.syncAsSint32LE(ns.c1); s.syncAsSint32LE(ns.c2); } -static void syncZPosition(Serializer &s, Z_POSITIONS &zp) { +static void syncZPosition(Common::Serializer &s, Z_POSITIONS &zp) { s.syncAsSint16LE(zp.actor); s.syncAsSint16LE(zp.column); s.syncAsSint32LE(zp.z); } -static void syncPolyVolatile(Serializer &s, POLY_VOLATILE &p) { +static void syncPolyVolatile(Common::Serializer &s, POLY_VOLATILE &p) { s.syncAsByte(p.bDead); s.syncAsSint16LE(p.xoff); s.syncAsSint16LE(p.yoff); } -static void syncSoundReel(Serializer &s, SOUNDREELS &sr) { +static void syncSoundReel(Common::Serializer &s, SOUNDREELS &sr) { s.syncAsUint32LE(sr.hFilm); s.syncAsSint32LE(sr.column); s.syncAsSint32LE(sr.actorCol); } -static void syncSavedData(Serializer &s, SAVED_DATA &sd) { +static void syncSavedData(Common::Serializer &s, SAVED_DATA &sd) { s.syncAsUint32LE(sd.SavedSceneHandle); s.syncAsUint32LE(sd.SavedBgroundHandle); for (int i = 0; i < MAX_MOVERS; ++i) @@ -324,7 +324,7 @@ int getList(Common::SaveFileManager *saveFileMan, const Common::String &target) } // Try to load save game header - Serializer s(f, 0); + Common::Serializer s(f, 0); SaveGameHeader hdr; bool validHeader = syncSaveGameHeader(s, hdr); delete f; @@ -379,7 +379,7 @@ char *ListEntry(int i, letype which) { return NULL; } -static void DoSync(Serializer &s) { +static void DoSync(Common::Serializer &s) { int sg = 0; if (TinselV2) { @@ -433,7 +433,7 @@ static bool DoRestore() { return false; } - Serializer s(f, 0); + Common::Serializer s(f, 0); SaveGameHeader hdr; if (!syncSaveGameHeader(s, hdr)) { delete f; // Invalid header, or savegame too new -> skip it @@ -474,7 +474,7 @@ static void DoSave(void) { if (f == NULL) return; - Serializer s(0, f); + Common::Serializer s(0, f); // Write out a savegame header SaveGameHeader hdr; diff --git a/engines/tinsel/timers.cpp b/engines/tinsel/timers.cpp index fa74797dd9..a627b05c31 100644 --- a/engines/tinsel/timers.cpp +++ b/engines/tinsel/timers.cpp @@ -30,7 +30,7 @@ #include "tinsel/timers.h" #include "tinsel/dw.h" -#include "tinsel/serializer.h" +#include "common/serializer.h" #include "common/system.h" @@ -81,7 +81,7 @@ void RebootTimers(void) { /** * (Un)serialize the timer data for save/restore game. */ -void syncTimerInfo(Serializer &s) { +void syncTimerInfo(Common::Serializer &s) { for (int i = 0; i < MAX_TIMERS; i++) { s.syncAsSint32LE(timers[i].tno); s.syncAsSint32LE(timers[i].ticks); diff --git a/engines/tinsel/timers.h b/engines/tinsel/timers.h index 2260074f1d..a03786ff97 100644 --- a/engines/tinsel/timers.h +++ b/engines/tinsel/timers.h @@ -30,9 +30,11 @@ #include "common/scummsys.h" #include "tinsel/dw.h" -namespace Tinsel { +namespace Common { + class Serializer; +} -class Serializer; +namespace Tinsel { #define ONE_SECOND 24 @@ -40,7 +42,7 @@ uint32 DwGetCurrentTime(void); void RebootTimers(void); -void syncTimerInfo(Serializer &s); +void syncTimerInfo(Common::Serializer &s); void FettleTimers(void); diff --git a/engines/tinsel/tinsel.cpp b/engines/tinsel/tinsel.cpp index 9562d57bc2..8fe0446932 100644 --- a/engines/tinsel/tinsel.cpp +++ b/engines/tinsel/tinsel.cpp @@ -30,6 +30,7 @@ #include "common/file.h" #include "common/savefile.h" #include "common/config-manager.h" +#include "common/serializer.h" #include "common/stream.h" #include "graphics/cursorman.h" @@ -60,7 +61,6 @@ #include "tinsel/polygons.h" #include "tinsel/savescn.h" #include "tinsel/scn.h" -#include "tinsel/serializer.h" #include "tinsel/sound.h" #include "tinsel/strres.h" #include "tinsel/sysvar.h" @@ -614,7 +614,7 @@ void UnSuspendHook(void) { bCuttingScene = false; } -void syncSCdata(Serializer &s) { +void syncSCdata(Common::Serializer &s) { s.syncAsUint32LE(HookScene.scene); s.syncAsSint32LE(HookScene.entry); s.syncAsSint32LE(HookScene.trans); |