[Scummvm-git-logs] scummvm master -> 2b22e64ffda313984177a7cd3d99e7f4d4a62739

a-yyg 76591232+a-yyg at users.noreply.github.com
Thu Jul 8 23:51:46 UTC 2021


This automated email contains information about 3 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
d7b8d52859 SAGA2: Implement TileCyclingState save/loading
5e5025205c SAGA2: Implement Data Segment save/loading
2b22e64ffd SAGA2: Implement SAGA Threads save/loading


Commit: d7b8d52859685d851528d08adff7059a0631a6b0
    https://github.com/scummvm/scummvm/commit/d7b8d52859685d851528d08adff7059a0631a6b0
Author: a/ (yuri.kgpps at gmail.com)
Date: 2021-07-09T08:51:08+09:00

Commit Message:
SAGA2: Implement TileCyclingState save/loading

Changed paths:
    engines/saga2/loadsave.cpp
    engines/saga2/tile.cpp
    engines/saga2/tile.h


diff --git a/engines/saga2/loadsave.cpp b/engines/saga2/loadsave.cpp
index 512431c788..c632e4c15a 100644
--- a/engines/saga2/loadsave.cpp
+++ b/engines/saga2/loadsave.cpp
@@ -153,9 +153,9 @@ Common::Error saveGameState(int16 saveNo, char *saveName) {
 	savePlayerActors(out);
 	saveCenterActor(out);
 	saveActiveItemStates(out);
+	saveTileCyclingStates(out);
 
 #if 0
-	saveTileCyclingStates(saveGame);
 	saveSAGADataSeg(saveGame);
 	saveSAGAThreads(saveGame);
 	saveMotionTasks(saveGame);
@@ -291,12 +291,12 @@ void loadSavedGameState(int16 saveNo) {
 			loadActiveItemStates(in);
 			loadFlags |= loadActiveItemStatesFlag;
 			break;
-#if 0
 
 		case MKTAG('C', 'Y', 'C', 'L'):
-			loadTileCyclingStates(saveGame);
+			loadTileCyclingStates(in);
 			loadFlags |= loadTileCyclingStatesFlag;
 			break;
+#if 0
 
 		case MKTAG('S', 'D', 'T', 'A'):
 			loadSAGADataSeg(saveGame);
diff --git a/engines/saga2/tile.cpp b/engines/saga2/tile.cpp
index a4a39f2cd7..0859b4d8a7 100644
--- a/engines/saga2/tile.cpp
+++ b/engines/saga2/tile.cpp
@@ -4418,6 +4418,25 @@ void saveTileCyclingStates(SaveFileConstructor &saveGame) {
 	delete[] archiveBuffer;
 }
 
+void saveTileCyclingStates(Common::OutSaveFile *out) {
+	debugC(2, kDebugSaveload, "Saving TileCyclingStates");
+
+	const int tileCycleArchiveSize = 4 + 1;
+
+	out->write("CYCL", 4);
+	out->writeUint32LE(tileCycleArchiveSize * cycleCount);
+
+	for (int i = 0; i < cycleCount; i++) {
+		debugC(3, kDebugSaveload, "Saving TileCyclingState %d", i);
+
+		out->writeSint32LE(cycleList[i].counter);
+		out->writeByte(cycleList[i].currentState);
+
+		debugC(4, kDebugSaveload, "... counter = %d", cycleList[i].counter);
+		debugC(4, kDebugSaveload, "... currentState = %d", cycleList[i].currentState);
+	}
+}
+
 //-----------------------------------------------------------------------
 //	Load the tile cycling state array from a save file
 
@@ -4443,6 +4462,21 @@ void loadTileCyclingStates(SaveFileReader &saveGame) {
 	delete[] archiveBuffer;
 }
 
+void loadTileCyclingStates(Common::InSaveFile *in) {
+	debugC(2, kDebugSaveload, "Loading TileCyclingStates");
+
+	initTileCyclingStates();
+
+	for (int i = 0; i < cycleCount; i++) {
+		debugC(3, kDebugSaveload, "Loading TileCyclingState %d", i);
+		cycleList[i].counter = in->readSint32LE();
+		cycleList[i].currentState = in->readByte();
+
+		debugC(4, kDebugSaveload, "... counter = %d", cycleList[i].counter);
+		debugC(4, kDebugSaveload, "... currentState = %d", cycleList[i].currentState);
+	}
+}
+
 //-----------------------------------------------------------------------
 //	Cleanup the tile cycling state array
 
diff --git a/engines/saga2/tile.h b/engines/saga2/tile.h
index 20c5194636..aa79a1dd9f 100644
--- a/engines/saga2/tile.h
+++ b/engines/saga2/tile.h
@@ -1016,7 +1016,9 @@ void cleanupActiveItemStates(void);
 
 void initTileCyclingStates(void);
 void saveTileCyclingStates(SaveFileConstructor &saveGame);
+void saveTileCyclingStates(Common::OutSaveFile *out);
 void loadTileCyclingStates(SaveFileReader &saveGame);
+void loadTileCyclingStates(Common::InSaveFile *in);
 void cleanupTileCyclingStates(void);
 
 void initAutoMap(void);


Commit: 5e5025205c3387d22a1690a4ed9ff11c9a3426a2
    https://github.com/scummvm/scummvm/commit/5e5025205c3387d22a1690a4ed9ff11c9a3426a2
Author: a/ (yuri.kgpps at gmail.com)
Date: 2021-07-09T08:51:08+09:00

Commit Message:
SAGA2: Implement Data Segment save/loading

Changed paths:
    engines/saga2/interp.cpp
    engines/saga2/loadsave.cpp
    engines/saga2/script.h


diff --git a/engines/saga2/interp.cpp b/engines/saga2/interp.cpp
index 1b54b4c090..48bca86802 100644
--- a/engines/saga2/interp.cpp
+++ b/engines/saga2/interp.cpp
@@ -1763,13 +1763,27 @@ void saveSAGADataSeg(SaveFileConstructor &saveGame) {
 	    dataSegSize);
 }
 
+void saveSAGADataSeg(Common::OutSaveFile *out) {
+	debugC(2, kDebugSaveload, "Saving Data Segment");
+
+	out->write("SDTA", 4);
+	out->writeUint32LE(dataSegSize);
+	out->write(dataSegment, dataSegSize);
+}
+
 //-----------------------------------------------------------------------
 //	Load the SAGA data segment from a save file
 
 void loadSAGADataSeg(SaveFileReader &saveGame) {
+	debugC(2, kDebugSaveload, "Loading Data Segment");
+
 	saveGame.read(dataSegment, dataSegSize);
 }
 
+void loadSAGADataSeg(Common::InSaveFile *in) {
+	in->read(dataSegment, dataSegSize);
+}
+
 //-----------------------------------------------------------------------
 //	Look up an entry in the SAGA export table
 
diff --git a/engines/saga2/loadsave.cpp b/engines/saga2/loadsave.cpp
index c632e4c15a..fa718ffdf1 100644
--- a/engines/saga2/loadsave.cpp
+++ b/engines/saga2/loadsave.cpp
@@ -154,9 +154,9 @@ Common::Error saveGameState(int16 saveNo, char *saveName) {
 	saveCenterActor(out);
 	saveActiveItemStates(out);
 	saveTileCyclingStates(out);
+	saveSAGADataSeg(out);
 
 #if 0
-	saveSAGADataSeg(saveGame);
 	saveSAGAThreads(saveGame);
 	saveMotionTasks(saveGame);
 	saveTaskStacks(saveGame);
@@ -296,12 +296,12 @@ void loadSavedGameState(int16 saveNo) {
 			loadTileCyclingStates(in);
 			loadFlags |= loadTileCyclingStatesFlag;
 			break;
-#if 0
 
 		case MKTAG('S', 'D', 'T', 'A'):
-			loadSAGADataSeg(saveGame);
+			loadSAGADataSeg(in);
 			loadFlags |= loadSAGADataSegFlag;
 			break;
+#if 0
 
 		case MKTAG('S', 'A', 'G', 'A'):
 			loadSAGAThreads(saveGame);
diff --git a/engines/saga2/script.h b/engines/saga2/script.h
index 9336ea70b9..c234a301a7 100644
--- a/engines/saga2/script.h
+++ b/engines/saga2/script.h
@@ -126,9 +126,11 @@ void initSAGADataSeg(void);
 
 //  Save the SAGA data segment to a save file
 void saveSAGADataSeg(SaveFileConstructor &saveGame);
+void saveSAGADataSeg(Common::OutSaveFile *out);
 
 //  Load the SAGA data segment from a save file
 void loadSAGADataSeg(SaveFileReader &saveGame);
+void loadSAGADataSeg(Common::InSaveFile *in);
 
 //  Dispose of the SAGA data segment -- do nothing
 inline void cleanupSAGADataSeg(void) {}


Commit: 2b22e64ffda313984177a7cd3d99e7f4d4a62739
    https://github.com/scummvm/scummvm/commit/2b22e64ffda313984177a7cd3d99e7f4d4a62739
Author: a/ (yuri.kgpps at gmail.com)
Date: 2021-07-09T08:51:08+09:00

Commit Message:
SAGA2: Implement SAGA Threads save/loading

Changed paths:
    engines/saga2/fta.h
    engines/saga2/interp.cpp
    engines/saga2/loadsave.cpp
    engines/saga2/script.h
    engines/saga2/timers.cpp


diff --git a/engines/saga2/fta.h b/engines/saga2/fta.h
index a21cf831ae..80f85805fa 100644
--- a/engines/saga2/fta.h
+++ b/engines/saga2/fta.h
@@ -148,6 +148,9 @@ public:
 	void set(uint32 duration);
 	bool check(void);
 	uint32 elapsed(void);                    // time elapsed since alarm set
+
+	void write(Common::OutSaveFile *out);
+	void read(Common::InSaveFile *in);
 };
 
 /* ===================================================================== *
diff --git a/engines/saga2/interp.cpp b/engines/saga2/interp.cpp
index 48bca86802..b33c3013b2 100644
--- a/engines/saga2/interp.cpp
+++ b/engines/saga2/interp.cpp
@@ -1159,6 +1159,8 @@ public:
 	//  Reconstruct from archive buffer
 	void *restore(void *buf);
 
+	void read(Common::InSaveFile *in);
+
 	//  Return the number of bytes needed to archive this thread list
 	//  in an archive buffer
 	int32 archiveSize(void);
@@ -1166,6 +1168,8 @@ public:
 	//  Create an archive of this thread list in an archive buffer
 	void *archive(void *buf);
 
+	void write(Common::OutSaveFile *out);
+
 	//  Cleanup the active threads
 	void cleanup(void);
 
@@ -1223,6 +1227,26 @@ void *ThreadList::restore(void *buf) {
 	return buf;
 }
 
+void ThreadList::read(Common::InSaveFile *in) {
+	int16 threadCount;
+
+	//  Get the count of threads and increment the buffer pointer
+	threadCount = in->readSint16LE();
+	debugC(3, kDebugSaveload, "... threadCount = %d", threadCount);
+
+	//  Iterate through the archive data, reconstructing the Threads
+	for (int i = 0; i < threadCount; i++) {
+		debugC(3, kDebugSaveload, "Saving Thread %d", i);
+		ThreadID id;
+
+		//  Retreive the Thread's id number
+		id = in->readSint16LE();
+		debugC(4, kDebugSaveload, "...... id = %d", id);
+
+		new Thread(in);
+	}
+}
+
 int32 ThreadList::archiveSize(void) {
 	int32 size = sizeof(int16);
 
@@ -1271,6 +1295,28 @@ void *ThreadList::archive(void *buf) {
 	return buf;
 }
 
+void ThreadList::write(Common::OutSaveFile *out) {
+	int16 threadCount = 0;
+	Thread *th;
+
+	//  Count the active threads
+	for (th = first(); th; th = next(th))
+		threadCount++;
+
+	//  Store the thread count in the archive buffer
+	out->writeSint16LE(threadCount);
+	debugC(3, kDebugSaveload, "... threadCount = %d", threadCount);
+
+	//  Iterate through the threads, archiving each
+	for (th = first(); th; th = next(th)) {
+		debugC(3, kDebugSaveload, "Loading ThreadID %d", getThreadID(th));
+		//  Store the Thread's id number
+		out->writeSint16LE(getThreadID(th));
+
+		th->write(out);
+	}
+}
+
 //-------------------------------------------------------------------
 //	Cleanup the active threads
 
@@ -1352,7 +1398,7 @@ static ThreadList &threadList = *((ThreadList *)threadListBuffer);
 
 void initSAGAThreads(void) {
 	//  Simply call the Thread List default constructor
-	new ThreadList;
+	new (&threadList) ThreadList;
 }
 
 //-------------------------------------------------------------------
@@ -1378,13 +1424,25 @@ void saveSAGAThreads(SaveFileConstructor &saveGame) {
 	free(archiveBuffer);
 }
 
+void saveSAGAThreads(Common::OutSaveFile *out) {
+	debugC(2, kDebugSaveload, "Saving SAGA Threads");
+
+	int32   archiveBufSize;
+
+	archiveBufSize = threadList.archiveSize();
+
+	out->write("SAGA", 4);
+	out->writeUint32LE(archiveBufSize);
+	threadList.write(out);
+}
+
 //-------------------------------------------------------------------
 //	Load the active SAGA threads from a save file
 
 void loadSAGAThreads(SaveFileReader &saveGame) {
 	//  If there is no saved data, simply call the default constructor
 	if (saveGame.getChunkSize() == 0) {
-		new ThreadList;
+		new (&threadList) ThreadList;
 		return;
 	}
 
@@ -1401,7 +1459,7 @@ void loadSAGAThreads(SaveFileReader &saveGame) {
 	bufferPtr = archiveBuffer;
 
 	//  Reconstruct stackList from archived data
-	new ThreadList;
+	new (&threadList) ThreadList;
 	bufferPtr = threadList.restore(bufferPtr);
 
 	assert((char *)bufferPtr == (char *)archiveBuffer +   saveGame.getChunkSize());
@@ -1409,6 +1467,20 @@ void loadSAGAThreads(SaveFileReader &saveGame) {
 	free(archiveBuffer);
 }
 
+void loadSAGAThreads(Common::InSaveFile *in, int32 chunkSize) {
+	debugC(2, kDebugSaveload, "Loading SAGA Threads");
+
+	//  If there is no saved data, simply call the default constructor
+	if (chunkSize == 0) {
+		new (&threadList) ThreadList;
+		return;
+	}
+
+	//  Reconstruct stackList from archived data
+	new (&threadList) ThreadList;
+	threadList.read(in);
+}
+
 //-------------------------------------------------------------------
 //	Dispose of the active SAGA threads
 
@@ -1510,6 +1582,37 @@ Thread::Thread(void **buf) {
 	newThread(this);
 }
 
+Thread::Thread(Common::SeekableReadStream *stream) {
+	int16   stackOffset;
+
+	programCounter.segment = stream->readUint16LE();
+	programCounter.offset = stream->readUint16LE();
+
+	stackSize = stream->readSint16LE();
+	flags = stream->readSint16LE();
+	framePtr = stream->readSint16LE();
+	returnVal = stream->readSint16LE();
+
+	waitAlarm.read(stream);
+
+	stackOffset = stream->readSint16LE();
+
+	debugC(4, kDebugSaveload, "...... stackSize = %d", stackSize);
+	debugC(4, kDebugSaveload, "...... flags = %d", flags);
+	debugC(4, kDebugSaveload, "...... framePtr = %d", framePtr);
+	debugC(4, kDebugSaveload, "...... returnVal = %d", returnVal);
+	debugC(4, kDebugSaveload, "...... stackOffset = %d", stackOffset);
+
+	codeSeg = scriptRes->loadIndexResource(programCounter.segment, "saga code segment");
+
+	stackBase = (byte *)malloc(stackSize);
+	stackPtr = stackBase + stackSize - stackOffset;
+
+	stream->read(stackPtr, stackOffset);
+
+	newThread(this);
+}
+
 //-----------------------------------------------------------------------
 //	Thread destructor
 
@@ -1569,6 +1672,32 @@ void *Thread::archive(void *buf) {
 	return buf;
 }
 
+void Thread::write(Common::OutSaveFile *out) {
+	int16   stackOffset;
+
+	out->writeUint16LE(programCounter.segment);
+	out->writeUint16LE(programCounter.offset);
+
+	out->writeSint16LE(stackSize);
+	out->writeSint16LE(flags);
+	out->writeSint16LE(framePtr);
+	out->writeSint16LE(returnVal);
+
+	waitAlarm.write(out);
+
+	warning("STUB: Thread::write: Pointer arithmetic");
+	stackOffset = (stackBase + stackSize) - stackPtr;
+	out->writeSint16LE(stackOffset);
+
+	out->write(stackPtr, stackOffset);
+
+	debugC(4, kDebugSaveload, "...... stackSize = %d", stackSize);
+	debugC(4, kDebugSaveload, "...... flags = %d", flags);
+	debugC(4, kDebugSaveload, "...... framePtr = %d", framePtr);
+	debugC(4, kDebugSaveload, "...... returnVal = %d", returnVal);
+	debugC(4, kDebugSaveload, "...... stackOffset = %d", stackOffset);
+}
+
 //-----------------------------------------------------------------------
 //	Thread dispatcher
 
diff --git a/engines/saga2/loadsave.cpp b/engines/saga2/loadsave.cpp
index fa718ffdf1..98b246902f 100644
--- a/engines/saga2/loadsave.cpp
+++ b/engines/saga2/loadsave.cpp
@@ -155,9 +155,9 @@ Common::Error saveGameState(int16 saveNo, char *saveName) {
 	saveActiveItemStates(out);
 	saveTileCyclingStates(out);
 	saveSAGADataSeg(out);
+	saveSAGAThreads(out);
 
 #if 0
-	saveSAGAThreads(saveGame);
 	saveMotionTasks(saveGame);
 	saveTaskStacks(saveGame);
 	saveTasks(saveGame);
@@ -301,12 +301,12 @@ void loadSavedGameState(int16 saveNo) {
 			loadSAGADataSeg(in);
 			loadFlags |= loadSAGADataSegFlag;
 			break;
-#if 0
 
 		case MKTAG('S', 'A', 'G', 'A'):
-			loadSAGAThreads(saveGame);
+			loadSAGAThreads(in, chunkSize);
 			loadFlags |= loadSAGAThreadsFlag;
 			break;
+#if 0
 
 		case MKTAG('M', 'O', 'T', 'N'):
 			if (!(~loadFlags & (loadActorsFlag | loadObjectsFlag))) {
diff --git a/engines/saga2/script.h b/engines/saga2/script.h
index c234a301a7..5b69c430bf 100644
--- a/engines/saga2/script.h
+++ b/engines/saga2/script.h
@@ -146,9 +146,11 @@ void initSAGAThreads(void);
 
 //  Save the active SAGA threads to a save file
 void saveSAGAThreads(SaveFileConstructor &saveGame);
+void saveSAGAThreads(Common::OutSaveFile *out);
 
 //  Load the active SAGA threads from a save file
 void loadSAGAThreads(SaveFileReader &saveGame);
+void loadSAGAThreads(Common::InSaveFile *in, int32 chunkSize);
 
 //  Dispose of the active SAGA threads
 void cleanupSAGAThreads(void);
@@ -250,6 +252,8 @@ public:
 	//  Constructor -- reconstruct from archive buffer
 	Thread(void **buf);
 
+	Thread(Common::SeekableReadStream *stream);
+
 	//  Destructor
 	~Thread();
 
@@ -260,6 +264,8 @@ public:
 	//  Create an archive of this thread in an archive buffer
 	void *archive(void *buf);
 
+	void write(Common::OutSaveFile *out);
+
 	//  Dispatch all asynchronous threads
 	static void dispatch(void);
 
diff --git a/engines/saga2/timers.cpp b/engines/saga2/timers.cpp
index 030e6a85c3..d37b469de8 100644
--- a/engines/saga2/timers.cpp
+++ b/engines/saga2/timers.cpp
@@ -98,6 +98,16 @@ void loadTimer(Common::InSaveFile *in) {
    Alarms
  * ====================================================================== */
 
+void Alarm::write(Common::OutSaveFile *out) {
+	out->writeUint32LE(basetime);
+	out->writeUint32LE(duration);
+}
+
+void Alarm::read(Common::InSaveFile *in) {
+	basetime = in->readUint32LE();
+	duration = in->readUint32LE();
+}
+
 void Alarm::set(uint32 dur) {
 	basetime = gameTime;
 	duration = dur;




More information about the Scummvm-git-logs mailing list