[Scummvm-git-logs] scummvm master -> 6dadb2e6419b525c6fa75161c7d7e16b0802ca1e

a-yyg 76591232+a-yyg at users.noreply.github.com
Wed Jul 7 22:10:13 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:
6dadb2e641 SAGA2: Implement objects save/loading


Commit: 6dadb2e6419b525c6fa75161c7d7e16b0802ca1e
    https://github.com/scummvm/scummvm/commit/6dadb2e6419b525c6fa75161c7d7e16b0802ca1e
Author: a/ (yuri.kgpps at gmail.com)
Date: 2021-07-08T07:09:21+09:00

Commit Message:
SAGA2: Implement objects save/loading

Changed paths:
    engines/saga2/loadsave.cpp
    engines/saga2/objects.cpp
    engines/saga2/objects.h
    engines/saga2/objproto.h


diff --git a/engines/saga2/loadsave.cpp b/engines/saga2/loadsave.cpp
index a97f893d88..9ec1cb698f 100644
--- a/engines/saga2/loadsave.cpp
+++ b/engines/saga2/loadsave.cpp
@@ -149,9 +149,9 @@ Common::Error saveGameState(int16 saveNo, char *saveName) {
 	saveCalender(out);
 	saveWorlds(out);
 	saveActors(out);
+	saveObjects(out);
 
 #if 0
-	saveObjects(saveGame);
 	saveBands(saveGame);
 	savePlayerActors(saveGame);
 	saveCenterActor(saveGame);
@@ -261,12 +261,12 @@ void loadSavedGameState(int16 saveNo) {
 			loadActors(in);
 			loadFlags |= loadActorsFlag;
 			break;
-#if 0
 
 		case MKTAG('O', 'B', 'J', 'S'):
-			loadObjects(saveGame);
+			loadObjects(in);
 			loadFlags |= loadObjectsFlag;
 			break;
+#if 0
 
 		case MKTAG('B', 'A', 'N', 'D'):
 			if (loadFlags & loadActorsFlag) {
diff --git a/engines/saga2/objects.cpp b/engines/saga2/objects.cpp
index 16734a2d18..40d473384b 100644
--- a/engines/saga2/objects.cpp
+++ b/engines/saga2/objects.cpp
@@ -75,7 +75,7 @@ int16               objectProtoCount,       // object prototype count
                     actorProtoCount;        // actor prototype count
 
 GameObject          *objectList = nullptr;     // list of all objects
-int16               objectCount;            // count of objects
+const int16         objectCount = 4971;        // count of objects
 
 Actor               *actorList = nullptr;      // list of all actors
 int16               actorCount;
@@ -269,6 +269,12 @@ GameObject::GameObject(void **buf) {
 GameObject::GameObject(Common::InSaveFile *in) {
 	debugC(3, kDebugSaveload, "Loading object %d", thisID());
 
+	read(in);
+}
+
+void GameObject::read(Common::InSaveFile *in) {
+	debugC(3, kDebugSaveload, "Loading object %d", thisID());
+
 	int16 pInd = in->readSint16LE();
 	//  Convert the protoype index into an object proto pointer
 	prototype = pInd != -1
@@ -3046,10 +3052,6 @@ void initObjects(void) {
 	if (resourceObjectCount < 4)
 		error("Unable to load Objects");
 
-	//  Add extra space for alias objects
-
-	objectCount = resourceObjectCount + extraObjects;
-
 	//  Allocate memory for the object list
 	objectListSize = objectCount * sizeof(GameObject);
 	objectList = new GameObject[objectCount]();
@@ -3191,6 +3193,27 @@ void saveObjects(SaveFileConstructor &saveGame) {
 	free(archiveBuffer);
 }
 
+void saveObjects(Common::OutSaveFile *out) {
+	int32 archiveBufSize;
+
+	archiveBufSize = sizeof(objectLimboCount)
+	                 +   sizeof(actorLimboCount)
+	                 +   sizeof(importantLimboCount)
+	                 +   objectListSize;
+
+	out->write("OBJS", 4);
+	out->writeUint32LE(archiveBufSize);
+
+	//  Store the limbo counts
+	out->writeSint16LE(objectLimboCount);
+	out->writeSint16LE(actorLimboCount);
+	out->writeSint16LE(importantLimboCount);
+
+	//  Store the object list
+	for (int i = 0; i < objectCount; i++)
+		objectList[i].write(out);
+}
+
 //-------------------------------------------------------------------
 //	Load the object list from a save file
 
@@ -3205,7 +3228,7 @@ void loadObjects(SaveFileReader &saveGame) {
 
 	//  Restore the object list
 	objectListSize = saveGame.bytesLeftInChunk();
-	objectCount = objectListSize / sizeof(GameObject);
+	//objectCount = objectListSize / sizeof(GameObject);
 
 	objectList = new GameObject[objectCount]();
 	if (objectList == nullptr)
@@ -3224,6 +3247,20 @@ void loadObjects(SaveFileReader &saveGame) {
 	}
 }
 
+void loadObjects(Common::InSaveFile *in) {
+	//  Restore the limbo counts
+	objectLimboCount = in->readSint16LE();
+	actorLimboCount = in->readSint16LE();
+	importantLimboCount = in->readSint16LE();
+
+	objectList = new GameObject[objectCount]();
+	if (objectList == nullptr)
+		error("Unable to load Objects");
+
+	for (int i = 0; i < objectCount; i++)
+		objectList[i].read(in);
+}
+
 //-------------------------------------------------------------------
 //	Cleanup object list
 
diff --git a/engines/saga2/objects.h b/engines/saga2/objects.h
index c2977152a0..0dfee90a80 100644
--- a/engines/saga2/objects.h
+++ b/engines/saga2/objects.h
@@ -129,7 +129,9 @@ class GameObject {
 
 	friend void     initObjects(void);
 	friend void     saveObjects(SaveFileConstructor &);
+	friend void     saveObjects(Common::OutSaveFile *out);
 	friend void     loadObjects(SaveFileReader &);
+	friend void     loadObjects(Common::InSaveFile *in);
 	friend void     cleanupObjects(void);
 
 	friend void     buildDisplayList(void);
@@ -190,6 +192,8 @@ public:
 
 	GameObject(Common::InSaveFile *in);
 
+	void read(Common::InSaveFile *in);
+
 	//  Return the number of bytes needed to archive this object in
 	//  a buffer
 	int32 archiveSize(void);
@@ -1430,9 +1434,11 @@ void initObjects(void);
 
 //  Save the objects to the save file
 void saveObjects(SaveFileConstructor &saveGame);
+void saveObjects(Common::OutSaveFile *out);
 
 //  Load the objects from the save file
 void loadObjects(SaveFileReader &saveGame);
+void loadObjects(Common::InSaveFile *in);
 
 //  Cleanup object list
 void cleanupObjects(void);
diff --git a/engines/saga2/objproto.h b/engines/saga2/objproto.h
index 4737531ffd..103d1811fc 100644
--- a/engines/saga2/objproto.h
+++ b/engines/saga2/objproto.h
@@ -42,9 +42,9 @@ class gameObject;
    Exports
  * ===================================================================== */
 
-extern int16    objectCount,        //  Number of elements in the object list
-       actorCount,         //  Number of elements in the actor list
-       worldCount;         //  Number of elements in the world list
+extern const int16 objectCount;  //  Number of elements in the object list
+extern int16 actorCount,         //  Number of elements in the actor list
+             worldCount;         //  Number of elements in the world list
 
 #define Permanent ((uint8)255)
 




More information about the Scummvm-git-logs mailing list