[Scummvm-git-logs] scummvm master -> d9aece25d857ade06657683fd0894db4d4de040b

a-yyg 76591232+a-yyg at users.noreply.github.com
Thu Jul 8 21:24:08 UTC 2021


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

Summary:
9be1d8918e SAGA2: Implement CenterActor save/loading
d9aece25d8 SAGA2: Implement ActiveItemState loading


Commit: 9be1d8918ef142f09830b5c07f1c8280f86f7c3d
    https://github.com/scummvm/scummvm/commit/9be1d8918ef142f09830b5c07f1c8280f86f7c3d
Author: a/ (yuri.kgpps at gmail.com)
Date: 2021-07-09T06:23:32+09:00

Commit Message:
SAGA2: Implement CenterActor save/loading

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


diff --git a/engines/saga2/loadsave.cpp b/engines/saga2/loadsave.cpp
index e98d0a7fa0..12520d12ce 100644
--- a/engines/saga2/loadsave.cpp
+++ b/engines/saga2/loadsave.cpp
@@ -151,9 +151,9 @@ Common::Error saveGameState(int16 saveNo, char *saveName) {
 	saveObjects(out);
 	saveBands(out);
 	savePlayerActors(out);
+	saveCenterActor(out);
 
 #if 0
-	saveCenterActor(saveGame);
 	saveActiveItemStates(saveGame);
 	saveTileCyclingStates(saveGame);
 	saveSAGADataSeg(saveGame);
@@ -281,12 +281,12 @@ void loadSavedGameState(int16 saveNo) {
 			} else
 				error("PlayerActors loaded prematurely");
 			break;
-#if 0
 
 		case MKTAG('C', 'N', 'T', 'R'):
-			loadCenterActor(saveGame);
+			loadCenterActor(in);
 			loadFlags |= loadCenterActorFlag;
 			break;
+#if 0
 
 		case MKTAG('T', 'A', 'G', 'S'):
 			loadActiveItemStates(saveGame);
diff --git a/engines/saga2/player.cpp b/engines/saga2/player.cpp
index 52008185cd..278055dc3f 100644
--- a/engines/saga2/player.cpp
+++ b/engines/saga2/player.cpp
@@ -1161,6 +1161,21 @@ void saveCenterActor(SaveFileConstructor &saveGame) {
 	saveGame.writeChunk(MakeID('C', 'N', 'T', 'R'), &a, sizeof(a));
 }
 
+void saveCenterActor(Common::OutSaveFile *out) {
+	debugC(2, kDebugSaveload, "Saving CenterActor");
+
+	const int32 centerActorArchiveSize = 4;
+
+	out->write("CNTR", 4);
+	out->writeUint32LE(centerActorArchiveSize);
+	//  Store the center actor and view object
+	out->writeSint16LE(centerActor);
+	out->writeUint16LE(viewCenterObject);
+
+	debugC(3, kDebugSaveload, "... centerActor = %d", centerActor);
+	debugC(3, kDebugSaveload, "... viewCenterObject = %d", viewCenterObject);
+}
+
 //-----------------------------------------------------------------------
 //	Load the center actor ID and the view object ID from the save file
 
@@ -1174,6 +1189,17 @@ void loadCenterActor(SaveFileReader &saveGame) {
 	viewCenterObject    = a.viewCenterObject;
 }
 
+void loadCenterActor(Common::InSaveFile *in) {
+	debugC(2, kDebugSaveload, "Loading CenterActor");
+
+	//  Restore the center actor and view object
+	centerActor = in->readSint16LE();
+	viewCenterObject = in->readUint16LE();
+
+	debugC(3, kDebugSaveload, "... centerActor = %d", centerActor);
+	debugC(3, kDebugSaveload, "... viewCenterObject = %d", viewCenterObject);
+}
+
 //-----------------------------------------------------------------------
 //	Iterates through all player actors
 
diff --git a/engines/saga2/player.h b/engines/saga2/player.h
index 0c1faf99eb..7be248e0b4 100644
--- a/engines/saga2/player.h
+++ b/engines/saga2/player.h
@@ -322,9 +322,11 @@ void initCenterActor(void);
 
 //  Save the center actor ID and the view object ID to a save file
 void saveCenterActor(SaveFileConstructor &saveGame);
+void saveCenterActor(Common::OutSaveFile *out);
 
 //  Load the center actor ID and the view object ID from the save file
 void loadCenterActor(SaveFileReader &saveGame);
+void loadCenterActor(Common::InSaveFile *in);
 
 //  Do nothing
 inline void cleanupCenterActor(void) {}


Commit: d9aece25d857ade06657683fd0894db4d4de040b
    https://github.com/scummvm/scummvm/commit/d9aece25d857ade06657683fd0894db4d4de040b
Author: a/ (yuri.kgpps at gmail.com)
Date: 2021-07-09T06:23:32+09:00

Commit Message:
SAGA2: Implement ActiveItemState 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 12520d12ce..512431c788 100644
--- a/engines/saga2/loadsave.cpp
+++ b/engines/saga2/loadsave.cpp
@@ -152,9 +152,9 @@ Common::Error saveGameState(int16 saveNo, char *saveName) {
 	saveBands(out);
 	savePlayerActors(out);
 	saveCenterActor(out);
+	saveActiveItemStates(out);
 
 #if 0
-	saveActiveItemStates(saveGame);
 	saveTileCyclingStates(saveGame);
 	saveSAGADataSeg(saveGame);
 	saveSAGAThreads(saveGame);
@@ -286,12 +286,12 @@ void loadSavedGameState(int16 saveNo) {
 			loadCenterActor(in);
 			loadFlags |= loadCenterActorFlag;
 			break;
-#if 0
 
 		case MKTAG('T', 'A', 'G', 'S'):
-			loadActiveItemStates(saveGame);
+			loadActiveItemStates(in);
 			loadFlags |= loadActiveItemStatesFlag;
 			break;
+#if 0
 
 		case MKTAG('C', 'Y', 'C', 'L'):
 			loadTileCyclingStates(saveGame);
diff --git a/engines/saga2/tile.cpp b/engines/saga2/tile.cpp
index c75c4c1415..a4a39f2cd7 100644
--- a/engines/saga2/tile.cpp
+++ b/engines/saga2/tile.cpp
@@ -856,6 +856,61 @@ void saveActiveItemStates(SaveFileConstructor &saveGame) {
 	free(archiveBuffer);
 }
 
+void saveActiveItemStates(Common::OutSaveFile *out) {
+	debugC(2, kDebugSaveload, "Saving ActiveItemStates");
+
+	int32 archiveBufSize = 0;
+
+	for (int i = 0; i < worldCount; i++) {
+		int32 size = tileRes->size(tagStateID + i);
+		archiveBufSize += sizeof(int16);
+		if (stateArray[i] != nullptr)
+			archiveBufSize += size;
+	}
+
+	out->write("TAGS", 4);
+	out->writeUint32LE(archiveBufSize);
+
+	for (int i = 0; i < worldCount; i++) {
+		debugC(3, kDebugSaveload, "Saving ActiveItemState %d", i);
+
+		if (stateArray[i] != nullptr) {
+			WorldMapData *mapData = &mapList[i];
+			ActiveItemList *activeItemList = mapData->activeItemList;
+			int16 activeItemCount = mapData->activeCount;
+			int32 arraySize = tileRes->size(tagStateID + i);
+
+			//  Save the size of the state array
+			out->writeSint16LE(arraySize);
+
+			debugC(4, kDebugSaveload, "... arraySize = %d", arraySize);
+
+			for (int j = 0; j < activeItemCount; j++) {
+				ActiveItem *activeItem = activeItemList->_items[j];
+				uint8 *statePtr;
+
+				if (activeItem->_data.itemType != activeTypeInstance)
+					continue;
+
+				//  Get a pointer to the current active item's state
+				//  data in the archive buffer
+				statePtr = &stateArray[i][activeItem->_data.instance.stateIndex];
+
+				//  Set the high bit of the state value based upon the
+				//  active item's locked state
+				if (activeItem->isLocked())
+					*statePtr |= (1 << 7);
+				else
+					*statePtr &= ~(1 << 7);
+			}
+
+			//  Copy the state data to the archive buffer
+			out->write(stateArray[i], arraySize);
+		} else
+			out->writeSint16LE(0);
+	}
+}
+
 //-----------------------------------------------------------------------
 //	Load the active item instance states from a save file
 
@@ -925,6 +980,54 @@ void loadActiveItemStates(SaveFileReader &saveGame) {
 	free(archiveBuffer);
 }
 
+void loadActiveItemStates(Common::InSaveFile *in) {
+	debugC(2, kDebugSaveload, "Loading ActiveItemStates");
+
+	stateArray = new byte *[worldCount]();
+
+	if (stateArray == nullptr)
+		error("Unable to allocate the active item state array array");
+
+	for (int i = 0; i < worldCount; i++) {
+		debugC(3, kDebugSaveload, "Loading ActiveItemState %d", i);
+
+		int32 arraySize;
+
+		arraySize = in->readSint16LE();
+
+		debugC(4, kDebugSaveload, "... arraySize = %d", arraySize);
+
+		stateArray[i] = (byte *)malloc(arraySize);
+		in->read(stateArray[i], arraySize);
+
+		if (arraySize > 0) {
+			WorldMapData *mapData = &mapList[i];
+			ActiveItemList *activeItemList = mapData->activeItemList;
+			int16 activeItemCount = mapData->activeCount;
+
+			for (int j = 0; j < activeItemCount; j++) {
+				ActiveItem      *activeItem = activeItemList->_items[j];
+				uint8           *statePtr;
+
+				if (activeItem->_data.itemType != activeTypeInstance)
+					continue;
+
+				//  Get a pointer to the current active item's state
+				//  data in the archive buffer
+				statePtr = &stateArray[i][activeItem->_data.instance.stateIndex];
+
+				//  Reset the locked state of the active item based
+				//  upon the high bit of the buffered state value
+				activeItem->setLocked((*statePtr & (1 << 7)) != 0);
+
+				//  Clear the high bit of the state value
+				*statePtr &= ~(1 << 7);
+			}
+		} else
+			stateArray[i] = nullptr;
+	}
+}
+
 //-----------------------------------------------------------------------
 //	Cleanup the active item state arrays
 
diff --git a/engines/saga2/tile.h b/engines/saga2/tile.h
index b92dd87bc1..20c5194636 100644
--- a/engines/saga2/tile.h
+++ b/engines/saga2/tile.h
@@ -1009,7 +1009,9 @@ TilePoint getClosestPointOnTAI(ActiveItem *TAI, GameObject *obj);
 
 void initActiveItemStates(void);
 void saveActiveItemStates(SaveFileConstructor &saveGame);
+void saveActiveItemStates(Common::OutSaveFile *out);
 void loadActiveItemStates(SaveFileReader &saveGame);
+void loadActiveItemStates(Common::InSaveFile *in);
 void cleanupActiveItemStates(void);
 
 void initTileCyclingStates(void);




More information about the Scummvm-git-logs mailing list