From 6f7cab17c4cb86e32cad72c4389cf0fc6a676f55 Mon Sep 17 00:00:00 2001 From: a/ Date: Wed, 14 Jul 2021 12:13:35 +0900 Subject: [PATCH] SAGA2: Make Calender save size portable --- engines/saga2/calender.cpp | 18 +++++++++--------- engines/saga2/calender.h | 4 ++-- engines/saga2/tilemode.cpp | 30 +++++++++++------------------- 3 files changed, 22 insertions(+), 30 deletions(-) diff --git a/engines/saga2/calender.cpp b/engines/saga2/calender.cpp index fcf8ee4376a..0af6b409685 100644 --- a/engines/saga2/calender.cpp +++ b/engines/saga2/calender.cpp @@ -28,6 +28,8 @@ #include "saga2/calender.h" #include "saga2/intrface.h" #include "saga2/localize.h" +#include "saga2/saveload.h" + namespace Saga2 { @@ -67,7 +69,7 @@ void CalenderTime::read(Common::InSaveFile *in) { debugC(3, kDebugSaveload, "... frameInHour = %d", frameInHour); } -void CalenderTime::write(Common::OutSaveFile *out) { +void CalenderTime::write(Common::MemoryWriteStreamDynamic *out) { out->writeUint16LE(years); out->writeUint16LE(weeks); out->writeUint16LE(days); @@ -264,23 +266,21 @@ void initCalender(void) { calender.frameInHour = 0; } -void saveCalender(Common::OutSaveFile *out) { +void saveCalender(Common::OutSaveFile *outS) { debugC(2, kDebugSaveload, "Saving calender"); - out->write("CALE", 4); - out->writeUint32LE(sizeof(calenderPaused) + sizeof(calender)); - - out->writeByte(calenderPaused); - + outS->write("CALE", 4); + CHUNK_BEGIN; + out->writeUint16LE(calenderPaused); debugC(3, kDebugSaveload, "... calenderPaused = %d", calenderPaused); - calender.write(out); + CHUNK_END; } void loadCalender(Common::InSaveFile *in) { debugC(2, kDebugSaveload, "Loading calender"); - calenderPaused = in->readByte(); + calenderPaused = in->readUint16LE(); debugC(3, kDebugSaveload, "... calenderPaused = %d", calenderPaused); diff --git a/engines/saga2/calender.h b/engines/saga2/calender.h index 84d2338db41..da0dd001af9 100644 --- a/engines/saga2/calender.h +++ b/engines/saga2/calender.h @@ -59,7 +59,7 @@ public: frameInHour; void read(Common::InSaveFile *in); - void write(Common::OutSaveFile *out); + void write(Common::MemoryWriteStreamDynamic *out); void update(void); int lightLevel(int maxLevel); @@ -97,7 +97,7 @@ uint32 operator - (const CalenderTime &time1, const CalenderTime &time2); void initCalender(void); -void saveCalender(Common::OutSaveFile *out); +void saveCalender(Common::OutSaveFile *outS); void loadCalender(Common::InSaveFile *in); bool isDayTime(void); diff --git a/engines/saga2/tilemode.cpp b/engines/saga2/tilemode.cpp index e6fcde75bf8..2a1b22b48d0 100644 --- a/engines/saga2/tilemode.cpp +++ b/engines/saga2/tilemode.cpp @@ -41,6 +41,7 @@ #include "saga2/dispnode.h" #include "saga2/uidialog.h" #include "saga2/contain.h" +#include "saga2/saveload.h" namespace Saga2 { @@ -610,26 +611,16 @@ void initTileModeState(void) { combatPaused = false; } -void saveTileModeState(Common::OutSaveFile *out) { +void saveTileModeState(Common::OutSaveFile *outS) { debugC(2, kDebugSaveload, "Saving TileModeState"); - int32 size = 0; - assert(uiKeysEnabled); - // Compute the number of bytes needed - size += sizeof(aggressiveActFlag) - + sizeof(inCombat) - + sizeof(combatPaused); - if (aggressiveActFlag) - size += sizeof(timeOfLastAggressiveAct); - - out->write("TMST", 4); - out->writeUint32LE(size); - - out->writeByte(aggressiveActFlag); - out->writeByte(inCombat); - out->writeByte(combatPaused); + outS->write("TMST", 4); + CHUNK_BEGIN; + out->writeUint16LE(aggressiveActFlag); + out->writeUint16LE(inCombat); + out->writeUint16LE(combatPaused); debugC(3, kDebugSaveload, "... aggressiveActFlag = %d", aggressiveActFlag); debugC(3, kDebugSaveload, "... inCombat = %d", inCombat); @@ -637,15 +628,16 @@ void saveTileModeState(Common::OutSaveFile *out) { if (aggressiveActFlag) timeOfLastAggressiveAct.write(out); + CHUNK_END; } void loadTileModeState(Common::InSaveFile *in) { assert(uiKeysEnabled); // Simply read in the data - aggressiveActFlag = in->readByte(); - inCombat = in->readByte(); - combatPaused = in->readByte(); + aggressiveActFlag = in->readUint16LE(); + inCombat = in->readUint16LE(); + combatPaused = in->readUint16LE(); debugC(3, kDebugSaveload, "... aggressiveActFlag = %d", aggressiveActFlag); debugC(3, kDebugSaveload, "... inCombat = %d", inCombat);