mirror of
https://github.com/libretro/scummvm.git
synced 2025-03-05 01:38:36 +00:00
SAGA2: Implement objects save/loading
This commit is contained in:
parent
da6a70c3e7
commit
6dadb2e641
@ -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) {
|
||||
|
@ -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
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user