[Scummvm-git-logs] scummvm master -> ce8c887d76c59009a326611bfac5bc0cb1e75df9
a-yyg
76591232+a-yyg at users.noreply.github.com
Fri Jul 9 13:01:57 UTC 2021
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
ce8c887d76 SAGA2: Implement TaskStack save/loading
Commit: ce8c887d76c59009a326611bfac5bc0cb1e75df9
https://github.com/scummvm/scummvm/commit/ce8c887d76c59009a326611bfac5bc0cb1e75df9
Author: a/ (yuri.kgpps at gmail.com)
Date: 2021-07-09T22:01:26+09:00
Commit Message:
SAGA2: Implement TaskStack save/loading
Changed paths:
engines/saga2/loadsave.cpp
engines/saga2/task.cpp
engines/saga2/task.h
diff --git a/engines/saga2/loadsave.cpp b/engines/saga2/loadsave.cpp
index 9879be4622..1a4ef5cf5d 100644
--- a/engines/saga2/loadsave.cpp
+++ b/engines/saga2/loadsave.cpp
@@ -157,9 +157,9 @@ Common::Error saveGameState(int16 saveNo, char *saveName) {
saveSAGADataSeg(out);
saveSAGAThreads(out);
saveMotionTasks(out);
+ saveTaskStacks(out);
#if 0
- saveTaskStacks(saveGame);
saveTasks(saveGame);
saveTileTasks(saveGame);
saveSpeechTasks(saveGame);
@@ -314,15 +314,15 @@ void loadSavedGameState(int16 saveNo) {
} else
error("MotionTasks loaded prematurely");
break;
-#if 0
case MKTAG('T', 'S', 'T', 'K'):
if (loadFlags & loadActorsFlag) {
- loadTaskStacks(saveGame);
+ loadTaskStacks(in, chunkSize);
loadFlags |= loadTaskStacksFlag;
} else
error("TaskStacks loaded prematurely");
break;
+#if 0
case MKTAG('T', 'A', 'S', 'K'):
if (loadFlags & loadTaskStacksFlag) {
diff --git a/engines/saga2/task.cpp b/engines/saga2/task.cpp
index 532cc7b672..00250fe9f1 100644
--- a/engines/saga2/task.cpp
+++ b/engines/saga2/task.cpp
@@ -118,6 +118,8 @@ public:
// Reconstruct from an archive buffer
void *restore(void *buf);
+ void read(Common::InSaveFile *in);
+
// Return the number of bytes needed to make an archive of the
// TaskStackList
int32 archiveSize(void);
@@ -125,6 +127,8 @@ public:
// Make an archive of the TaskStackList in an archive buffer
void *archive(void *buf);
+ void write(Common::OutSaveFile *out);
+
// Place a TaskStack from the inactive list into the active
// list.
void newTaskStack(TaskStack *p);
@@ -206,6 +210,32 @@ void *TaskStackList::restore(void *buf) {
return buf;
}
+void TaskStackList::read(Common::InSaveFile *in) {
+ int16 taskStackCount;
+
+ // Get the count of task stacks and increment the buffer pointer
+ taskStackCount = in->readSint16LE();
+ debugC(3, kDebugSaveload, "... taskStackCount = %d", taskStackCount);
+
+ // Iterate through the archive data, reconstructing the TaskStacks
+ for (int i = 0; i < taskStackCount; i++) {
+ TaskStackID id;
+ TaskStack *ts;
+
+ // Retreive the TaskStack's id number
+ id = in->readSint16LE();
+ debugC(3, kDebugSaveload, "Loading Task Stack %d", id);
+
+ ts = new TaskStack;
+ _list[id] = ts;
+
+ ts->read(in);
+
+ // Plug this TaskStack into the Actor
+ ts->getActor()->curTask = ts;
+ }
+}
+
//----------------------------------------------------------------------
// Return the number of bytes necessary to archive this TaskStackList
@@ -258,6 +288,30 @@ void *TaskStackList::archive(void *buf) {
return buf;
}
+void TaskStackList::write(Common::OutSaveFile *out) {
+ int16 taskStackCount = 0;
+
+ // Count the active task stacks
+ for (int i = 0; i < numTaskStacks; i++)
+ if (_list[i])
+ taskStackCount++;
+
+ // Store the task stack count in the archive buffer
+ out->writeSint16LE(taskStackCount);
+ debugC(3, kDebugSaveload, "... taskStackCount = %d", taskStackCount);
+
+ for (int i = 0; i < numTaskStacks; i++) {
+ if (_list[i] == nullptr)
+ continue;
+
+ debugC(3, kDebugSaveload, "Saving Task Stack %d", i);
+
+ TaskStack *ts = _list[i];
+ out->writeSint16LE(i);
+ ts->write(out);
+ }
+}
+
//----------------------------------------------------------------------
// Place a TaskStack into the active list and return its address
@@ -395,6 +449,19 @@ void saveTaskStacks(SaveFileConstructor &saveGame) {
free(archiveBuffer);
}
+void saveTaskStacks(Common::OutSaveFile *out) {
+ debugC(2, kDebugSaveload, "Saving Task Stacks");
+
+ int32 archiveBufSize;
+
+ archiveBufSize = stackList.archiveSize();
+
+ out->write("TSTK", 4);
+ out->writeUint32LE(archiveBufSize);
+
+ stackList.write(out);
+}
+
//----------------------------------------------------------------------
// Load the stackList from a save file
@@ -428,6 +495,20 @@ void loadTaskStacks(SaveFileReader &saveGame) {
free(archiveBuffer);
}
+void loadTaskStacks(Common::InSaveFile *in, int32 chunkSize) {
+ debugC(2, kDebugSaveload, "Saving Task Stacks");
+
+ // If there is no saved data, simply call the default constructor
+ if (chunkSize == 0) {
+ new (&stackList) TaskStackList;
+ return;
+ }
+
+ // Reconstruct stackList from archived data
+ new (&stackList) TaskStackList;
+ stackList.read(in);
+}
+
//----------------------------------------------------------------------
// Cleanup the stackList
@@ -4597,6 +4678,46 @@ void *TaskStack::archive(void *buf) {
return buf;
}
+void TaskStack::write(Common::OutSaveFile *out) {
+ // Store the stack bottom TaskID
+ out->writeSint16LE(stackBottomID);
+
+ // Store the actor's id
+ out->writeUint16LE(actor->thisID());
+
+ // Store the evalCount and evalRate
+ out->writeSint16LE(evalCount);
+
+ out->writeSint16LE(evalRate);
+
+ debugC(4, kDebugSaveload, "...... stackBottomID = %d", stackBottomID);
+ debugC(4, kDebugSaveload, "...... actorID = %d", actor->thisID());
+ debugC(4, kDebugSaveload, "...... evalCount = %d", evalCount);
+ debugC(4, kDebugSaveload, "...... evalRate = %d", evalRate);
+}
+
+void TaskStack::read(Common::InSaveFile *in) {
+ ObjectID actorID;
+
+ // Restore the stack bottom pointer
+ stackBottomID = in->readSint16LE();
+
+ // Restore the actor pointer
+ actorID = in->readUint16LE();
+ actor = (Actor *)GameObject::objectAddress(actorID);
+
+ // Restore the evaluation count
+ evalCount = in->readSint16LE();
+
+ // Restore the evaluation rate
+ evalRate = in->readSint16LE();
+
+ debugC(4, kDebugSaveload, "...... stackBottomID = %d", stackBottomID);
+ debugC(4, kDebugSaveload, "...... actorID = %d", actorID);
+ debugC(4, kDebugSaveload, "...... evalCount = %d", evalCount);
+ debugC(4, kDebugSaveload, "...... evalRate = %d", evalRate);
+}
+
#if DEBUG
//----------------------------------------------------------------------
// Debugging function used to mark this task and any sub tasks as being
diff --git a/engines/saga2/task.h b/engines/saga2/task.h
index d4014bba10..4e049309ec 100644
--- a/engines/saga2/task.h
+++ b/engines/saga2/task.h
@@ -88,9 +88,11 @@ void initTaskStacks(void);
// Save the task stack list to a save file
void saveTaskStacks(SaveFileConstructor &saveGame);
+void saveTaskStacks(Common::OutSaveFile *out);
// Load the task stack list from a save file
void loadTaskStacks(SaveFileReader &saveGame);
+void loadTaskStacks(Common::InSaveFile *in, int32 chunkSize);
// Cleanup the task stacks
void cleanupTaskStacks(void);
@@ -1678,6 +1680,12 @@ public:
Actor *actor; // Pointer to actor performing tasks
// Constructor
+ TaskStack() :
+ stackBottomID(0),
+ evalCount(0),
+ evalRate(0),
+ actor(nullptr) {}
+
TaskStack(Actor *a) :
stackBottomID(NoTask),
actor(a),
@@ -1707,6 +1715,10 @@ public:
// Create an archive of this TaskStack in a buffer
void *archive(void *buf);
+ void write(Common::OutSaveFile *out);
+
+ void read(Common::InSaveFile *in);
+
// Set the bottom task of this task stack
void setTask(Task *t);
More information about the Scummvm-git-logs
mailing list