SAGA2: Make Timers/Alarms/Threads save size portable

This commit is contained in:
a/ 2021-07-15 19:27:50 +09:00
parent e1fb81c91a
commit 2625fafbc5
7 changed files with 24 additions and 36 deletions

View File

@ -172,7 +172,7 @@ int CalenderTime::lightLevel(int maxLevel) {
FrameAlarm member functions
* ===================================================================== */
void FrameAlarm::write(Common::OutSaveFile *out) {
void FrameAlarm::write(Common::MemoryWriteStreamDynamic *out) {
out->writeUint16LE(baseFrame);
out->writeUint16LE(duration);
}

View File

@ -81,7 +81,7 @@ public:
bool check(void);
uint16 elapsed(void);
void write(Common::OutSaveFile *out);
void write(Common::MemoryWriteStreamDynamic *out);
void read(Common::InSaveFile *in);
};

View File

@ -142,7 +142,7 @@ public:
bool check(void);
uint32 elapsed(void); // time elapsed since alarm set
void write(Common::OutSaveFile *out);
void write(Common::MemoryWriteStreamDynamic *out);
void read(Common::InSaveFile *in);
};

View File

@ -33,6 +33,7 @@
#include "saga2/tile.h"
#include "saga2/mission.h"
#include "saga2/hresmgr.h"
#include "saga2/saveload.h"
namespace Saga2 {
@ -1159,7 +1160,7 @@ public:
// in an archive buffer
int32 archiveSize(void);
void write(Common::OutSaveFile *out);
void write(Common::MemoryWriteStreamDynamic *out);
// Cleanup the active threads
void cleanup(void);
@ -1221,7 +1222,7 @@ int32 ThreadList::archiveSize(void) {
return size;
}
void ThreadList::write(Common::OutSaveFile *out) {
void ThreadList::write(Common::MemoryWriteStreamDynamic *out) {
int16 threadCount = 0;
Thread *th;
@ -1326,16 +1327,13 @@ void initSAGAThreads(void) {
// Simply call the Thread List default constructor
}
void saveSAGAThreads(Common::OutSaveFile *out) {
void saveSAGAThreads(Common::OutSaveFile *outS) {
debugC(2, kDebugSaveload, "Saving SAGA Threads");
int32 archiveBufSize;
archiveBufSize = threadList.archiveSize();
out->write("SAGA", 4);
out->writeUint32LE(archiveBufSize);
outS->write("SAGA", 4);
CHUNK_BEGIN;
threadList.write(out);
CHUNK_END;
}
void loadSAGAThreads(Common::InSaveFile *in, int32 chunkSize) {
@ -1477,7 +1475,7 @@ int32 Thread::archiveSize(void) {
+ (stackBase + stackSize) - stackPtr;
}
void Thread::write(Common::OutSaveFile *out) {
void Thread::write(Common::MemoryWriteStreamDynamic *out) {
int16 stackOffset;
out->writeUint16LE(programCounter.segment);

View File

@ -139,7 +139,7 @@ class Thread;
// Initialize the SAGA thread list
void initSAGAThreads(void);
void saveSAGAThreads(Common::OutSaveFile *out);
void saveSAGAThreads(Common::OutSaveFile *outS);
void loadSAGAThreads(Common::InSaveFile *in, int32 chunkSize);
// Dispose of the active SAGA threads
@ -254,7 +254,7 @@ public:
// Create an archive of this thread in an archive buffer
void *archive(void *buf);
void write(Common::OutSaveFile *out);
void write(Common::MemoryWriteStreamDynamic *out);
// Dispatch all asynchronous threads
static void dispatch(void);

View File

@ -30,6 +30,7 @@
#include "saga2/fta.h"
#include "saga2/timers.h"
#include "saga2/objects.h"
#include "saga2/saveload.h"
namespace Saga2 {
@ -79,7 +80,7 @@ void loadTimer(Common::InSaveFile *in) {
Alarms
* ====================================================================== */
void Alarm::write(Common::OutSaveFile *out) {
void Alarm::write(Common::MemoryWriteStreamDynamic *out) {
out->writeUint32LE(basetime);
out->writeUint32LE(duration);
}
@ -170,35 +171,23 @@ static int getTimerID(Timer *t) {
return -1;
}
void saveTimers(Common::OutSaveFile *out) {
void saveTimers(Common::OutSaveFile *outS) {
debugC(2, kDebugSaveload, "Saving Timers");
int16 timerListCount = 0,
timerCount = 0;
int32 archiveBufSize = 0;
// Add the sizes of the timer list count an timer count
archiveBufSize += sizeof(timerListCount) + sizeof(timerCount);
// Tally the timer lists
timerListCount = g_vm->_timerLists.size();
// Add the total archive size of all of the timer lists
archiveBufSize += timerListCount * TimerList::archiveSize();
// Tally the timers
timerCount = g_vm->_timers.size();
debugC(3, kDebugSaveload, "... timerListCount = %d", timerListCount);
debugC(3, kDebugSaveload, "... timerCount = %d", timerCount);
// Add the total archive size of all of the timers
archiveBufSize += timerCount * Timer::archiveSize();
out->write("TIMR", 4);
out->writeUint32LE(archiveBufSize);
outS->write("TIMR", 4);
CHUNK_BEGIN;
// Store the timer list count and timer count
out->writeSint16LE(timerListCount);
out->writeSint16LE(timerCount);
@ -216,6 +205,7 @@ void saveTimers(Common::OutSaveFile *out) {
(*it)->write(out);
}
CHUNK_END;
}
void loadTimers(Common::InSaveFile *in) {
@ -299,7 +289,7 @@ TimerList::~TimerList() {
g_vm->_timerLists.remove(this);
}
void TimerList::write(Common::OutSaveFile *out) {
void TimerList::write(Common::MemoryWriteStreamDynamic *out) {
// Store the object's ID
out->writeUint16LE(_obj->thisID());
}
@ -345,7 +335,7 @@ int32 Timer::archiveSize(void) {
+ sizeof(FrameAlarm);
}
void Timer::write(Common::OutSaveFile *out) {
void Timer::write(Common::MemoryWriteStreamDynamic *out) {
// Store the obj's ID
out->writeUint16LE(_obj->thisID());

View File

@ -46,7 +46,7 @@ void checkTimers(void);
// Initialize the Timers
void initTimers(void);
void saveTimers(Common::OutSaveFile *out);
void saveTimers(Common::OutSaveFile *outS);
void loadTimers(Common::InSaveFile *in);
// Cleanup the active Timers
void cleanupTimers(void);
@ -72,7 +72,7 @@ public:
return sizeof(ObjectID);
}
void write(Common::OutSaveFile *out);
void write(Common::MemoryWriteStreamDynamic *out);
GameObject *getObject(void) {
return _obj;
@ -111,7 +111,7 @@ public:
// a buffer
static int32 archiveSize(void);
void write(Common::OutSaveFile *out);
void write(Common::MemoryWriteStreamDynamic *out);
GameObject *getObject(void) {
return _obj;