mirror of
https://github.com/libretro/scummvm.git
synced 2025-04-02 14:51:40 +00:00
Changed the save/load process to use a common serialiser
svn-id: r36253
This commit is contained in:
parent
8b4c44373c
commit
7238358e6e
@ -180,115 +180,6 @@ backgroundIncrustStruct *addBackgroundIncrust(int16 overlayIdx, int16 objectIdx,
|
||||
return newElement;
|
||||
}
|
||||
|
||||
void saveIncrust(Common::OutSaveFile& currentSaveFile) {
|
||||
int count = 0;
|
||||
|
||||
backgroundIncrustStruct *pl = backgroundIncrustHead.next;
|
||||
while (pl) {
|
||||
count++;
|
||||
pl = pl->next;
|
||||
}
|
||||
|
||||
currentSaveFile.writeSint16LE(count);
|
||||
|
||||
pl = backgroundIncrustHead.next;
|
||||
while (pl) {
|
||||
char dummy[4] = {0, 0, 0, 0};
|
||||
currentSaveFile.write(dummy, 2);
|
||||
currentSaveFile.write(dummy, 2);
|
||||
|
||||
currentSaveFile.writeSint16LE(pl->objectIdx);
|
||||
currentSaveFile.writeSint16LE(pl->type);
|
||||
currentSaveFile.writeSint16LE(pl->overlayIdx);
|
||||
currentSaveFile.writeSint16LE(pl->X);
|
||||
currentSaveFile.writeSint16LE(pl->Y);
|
||||
currentSaveFile.writeSint16LE(pl->field_E);
|
||||
currentSaveFile.writeSint16LE(pl->scale);
|
||||
currentSaveFile.writeSint16LE(pl->backgroundIdx);
|
||||
currentSaveFile.writeSint16LE(pl->scriptNumber);
|
||||
currentSaveFile.writeSint16LE(pl->scriptOverlayIdx);
|
||||
currentSaveFile.write(dummy, 4);
|
||||
currentSaveFile.writeSint16LE(pl->saveWidth / 2);
|
||||
currentSaveFile.writeSint16LE(pl->saveHeight);
|
||||
currentSaveFile.writeSint16LE(pl->saveSize);
|
||||
currentSaveFile.writeSint16LE(pl->savedX);
|
||||
currentSaveFile.writeSint16LE(pl->savedY);
|
||||
currentSaveFile.write(pl->name, 13);
|
||||
currentSaveFile.write(dummy, 1);
|
||||
currentSaveFile.writeSint16LE(pl->spriteId);
|
||||
currentSaveFile.write(dummy, 2);
|
||||
|
||||
if (pl->saveSize) {
|
||||
char* buffer = (char*)malloc(pl->saveSize);
|
||||
memset(buffer, 0, pl->saveSize);
|
||||
currentSaveFile.write(buffer, pl->saveSize);
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
pl = pl->next;
|
||||
}
|
||||
}
|
||||
|
||||
void loadBackgroundIncrustFromSave(Common::InSaveFile& currentSaveFile) {
|
||||
int16 numEntry;
|
||||
int32 i;
|
||||
|
||||
numEntry = currentSaveFile.readSint16LE();
|
||||
|
||||
backgroundIncrustStruct *pl = &backgroundIncrustHead;
|
||||
backgroundIncrustStruct *pl1 = &backgroundIncrustHead;
|
||||
|
||||
for (i = 0; i < numEntry; i++) {
|
||||
backgroundIncrustStruct *pl2 = (backgroundIncrustStruct *)mallocAndZero(sizeof(backgroundIncrustStruct));
|
||||
|
||||
currentSaveFile.skip(2);
|
||||
currentSaveFile.skip(2);
|
||||
|
||||
pl2->objectIdx = currentSaveFile.readSint16LE();
|
||||
pl2->type = currentSaveFile.readSint16LE();
|
||||
pl2->overlayIdx = currentSaveFile.readSint16LE();
|
||||
pl2->X = currentSaveFile.readSint16LE();
|
||||
pl2->Y = currentSaveFile.readSint16LE();
|
||||
pl2->field_E = currentSaveFile.readSint16LE();
|
||||
pl2->scale = currentSaveFile.readSint16LE();
|
||||
pl2->backgroundIdx = currentSaveFile.readSint16LE();
|
||||
pl2->scriptNumber = currentSaveFile.readSint16LE();
|
||||
pl2->scriptOverlayIdx = currentSaveFile.readSint16LE();
|
||||
currentSaveFile.skip(4);
|
||||
pl2->saveWidth = currentSaveFile.readSint16LE() * 2;
|
||||
pl2->saveHeight = currentSaveFile.readSint16LE();
|
||||
pl2->saveSize = currentSaveFile.readUint16LE();
|
||||
pl2->savedX = currentSaveFile.readSint16LE();
|
||||
pl2->savedY = currentSaveFile.readSint16LE();
|
||||
currentSaveFile.read(pl2->name, 13);
|
||||
currentSaveFile.skip(1);
|
||||
pl2->spriteId = currentSaveFile.readSint16LE();
|
||||
currentSaveFile.skip(2);
|
||||
|
||||
if (pl2->saveSize) {
|
||||
/*pl2->ptr = (uint8 *) mallocAndZero(pl2->size);
|
||||
currentSaveFile.read(pl2->ptr, pl2->size);*/
|
||||
|
||||
currentSaveFile.skip(pl2->saveSize);
|
||||
|
||||
int width = pl2->saveWidth;
|
||||
int height = pl2->saveHeight;
|
||||
pl2->ptr = (uint8*)malloc(width * height);
|
||||
memset(pl2->ptr, 0, width * height);
|
||||
|
||||
// TODO: convert graphic format here
|
||||
}
|
||||
|
||||
pl2->next = NULL;
|
||||
pl->next = pl2;
|
||||
|
||||
pl2->prev = pl1->prev;
|
||||
pl1->prev = pl2;
|
||||
|
||||
pl = pl2;
|
||||
}
|
||||
}
|
||||
|
||||
void regenerateBackgroundIncrust(backgroundIncrustStruct *pHead) {
|
||||
|
||||
lastAni[0] = 0;
|
||||
|
@ -56,8 +56,6 @@ extern backgroundIncrustStruct backgroundIncrustHead;
|
||||
|
||||
void resetBackgroundIncrustList(backgroundIncrustStruct * pHead);
|
||||
backgroundIncrustStruct *addBackgroundIncrust(int16 overlayIdx, int16 param2, backgroundIncrustStruct * pHead, int16 scriptNumber, int16 scriptOverlay, int16 backgroundIdx, int16 param4);
|
||||
void saveIncrust(Common::OutSaveFile& currentSaveFile);
|
||||
void loadBackgroundIncrustFromSave(Common::InSaveFile& currentSaveFile);
|
||||
void regenerateBackgroundIncrust(backgroundIncrustStruct * pHead);
|
||||
void freeBackgroundIncrustList(backgroundIncrustStruct * pHead);
|
||||
void removeBackgroundIncrust(int overlay, int idx, backgroundIncrustStruct * pHead);
|
||||
|
@ -44,105 +44,6 @@ void freeMessageList(cellStruct *objPtr) {
|
||||
free(objPtr);
|
||||
} */
|
||||
}
|
||||
void saveCell(Common::OutSaveFile& currentSaveFile) {
|
||||
|
||||
int count = 0;
|
||||
cellStruct *t = cellHead.next;
|
||||
|
||||
while (t) {
|
||||
count++;
|
||||
t = t->next;
|
||||
}
|
||||
|
||||
currentSaveFile.writeSint16LE(count);
|
||||
|
||||
t = cellHead.next;
|
||||
while (t) {
|
||||
char dummy[2] = { 0, 0};
|
||||
|
||||
currentSaveFile.write(dummy, 2);
|
||||
currentSaveFile.write(dummy, 2);
|
||||
|
||||
currentSaveFile.writeSint16LE(t->idx);
|
||||
currentSaveFile.writeSint16LE(t->type);
|
||||
currentSaveFile.writeSint16LE(t->overlay);
|
||||
currentSaveFile.writeSint16LE(t->x);
|
||||
currentSaveFile.writeSint16LE(t->field_C);
|
||||
currentSaveFile.writeSint16LE(t->spriteIdx);
|
||||
currentSaveFile.writeSint16LE(t->color);
|
||||
currentSaveFile.writeSint16LE(t->backgroundPlane);
|
||||
currentSaveFile.writeSint16LE(t->freeze);
|
||||
currentSaveFile.writeSint16LE(t->parent);
|
||||
currentSaveFile.writeSint16LE(t->parentOverlay);
|
||||
currentSaveFile.writeSint16LE(t->parentType);
|
||||
currentSaveFile.writeSint16LE(t->followObjectOverlayIdx);
|
||||
currentSaveFile.writeSint16LE(t->followObjectIdx);
|
||||
currentSaveFile.writeSint16LE(t->animStart);
|
||||
currentSaveFile.writeSint16LE(t->animEnd);
|
||||
currentSaveFile.writeSint16LE(t->animWait);
|
||||
currentSaveFile.writeSint16LE(t->animStep);
|
||||
currentSaveFile.writeSint16LE(t->animChange);
|
||||
currentSaveFile.writeSint16LE(t->animType);
|
||||
currentSaveFile.writeSint16LE(t->animSignal);
|
||||
currentSaveFile.writeSint16LE(t->animCounter);
|
||||
currentSaveFile.writeSint16LE(t->animLoop);
|
||||
currentSaveFile.write(dummy, 2);
|
||||
|
||||
t = t->next;
|
||||
}
|
||||
}
|
||||
|
||||
void loadSavegameDataSub2(Common::InSaveFile& currentSaveFile) {
|
||||
unsigned short int n_chunks;
|
||||
int i;
|
||||
cellStruct *p;
|
||||
cellStruct *t;
|
||||
|
||||
cellHead.next = NULL; // Not in ASM code, but I guess the variable is defaulted
|
||||
// to this value in the .exe
|
||||
|
||||
n_chunks = currentSaveFile.readSint16LE();
|
||||
|
||||
p = &cellHead;
|
||||
|
||||
for (i = 0; i < n_chunks; i++) {
|
||||
t = (cellStruct *) mallocAndZero(sizeof(cellStruct));
|
||||
|
||||
currentSaveFile.skip(2);
|
||||
currentSaveFile.skip(2);
|
||||
|
||||
t->idx = currentSaveFile.readSint16LE();
|
||||
t->type = currentSaveFile.readSint16LE();
|
||||
t->overlay = currentSaveFile.readSint16LE();
|
||||
t->x = currentSaveFile.readSint16LE();
|
||||
t->field_C = currentSaveFile.readSint16LE();
|
||||
t->spriteIdx = currentSaveFile.readSint16LE();
|
||||
t->color = currentSaveFile.readSint16LE();
|
||||
t->backgroundPlane = currentSaveFile.readSint16LE();
|
||||
t->freeze = currentSaveFile.readSint16LE();
|
||||
t->parent = currentSaveFile.readSint16LE();
|
||||
t->parentOverlay = currentSaveFile.readSint16LE();
|
||||
t->parentType = currentSaveFile.readSint16LE();
|
||||
t->followObjectOverlayIdx = currentSaveFile.readSint16LE();
|
||||
t->followObjectIdx = currentSaveFile.readSint16LE();
|
||||
t->animStart = currentSaveFile.readSint16LE();
|
||||
t->animEnd = currentSaveFile.readSint16LE();
|
||||
t->animWait = currentSaveFile.readSint16LE();
|
||||
t->animStep = currentSaveFile.readSint16LE();
|
||||
t->animChange = currentSaveFile.readSint16LE();
|
||||
t->animType = currentSaveFile.readSint16LE();
|
||||
t->animSignal = currentSaveFile.readSint16LE();
|
||||
t->animCounter = currentSaveFile.readSint16LE();
|
||||
t->animLoop = currentSaveFile.readSint16LE();
|
||||
currentSaveFile.skip(2);
|
||||
|
||||
t->next = NULL;
|
||||
p->next = t;
|
||||
t->prev = cellHead.prev;
|
||||
cellHead.prev = t;
|
||||
p = t;
|
||||
}
|
||||
}
|
||||
|
||||
cellStruct *addCell(cellStruct *pHead, int16 overlayIdx, int16 objIdx, int16 type, int16 backgroundPlane, int16 scriptOverlay, int16 scriptNumber, int16 scriptType) {
|
||||
int16 var;
|
||||
|
@ -65,8 +65,6 @@ struct cellStruct {
|
||||
extern cellStruct cellHead;
|
||||
|
||||
void resetPtr(cellStruct * ptr);
|
||||
void loadSavegameDataSub2(Common::InSaveFile& currentSaveFile);
|
||||
void saveCell(Common::OutSaveFile& currentSaveFile);
|
||||
cellStruct *addCell(cellStruct *pHead, int16 overlayIdx, int16 objIdx, int16 type, int16 backgroundPlane, int16 scriptOverlay, int16 scriptNumber, int16 scriptType);
|
||||
void createTextObject(cellStruct *pObject, int overlayIdx, int messageIdx, int x, int y, int width, int16 color, int backgroundPlane, int parentOvl, int parentIdx);
|
||||
void removeCell(cellStruct *objPtr, int ovlNumber, int objectIdx, int objType, int backgroundPlane);
|
||||
|
@ -432,10 +432,10 @@ int initAllData(void) {
|
||||
|
||||
freeDisk();
|
||||
|
||||
initVar5[0] = -1;
|
||||
initVar5[3] = -1;
|
||||
initVar5[6] = -1;
|
||||
initVar5[9] = -1;
|
||||
soundList[0].frameNum = -1;
|
||||
soundList[1].frameNum = -1;
|
||||
soundList[2].frameNum = -1;
|
||||
soundList[3].frameNum = -1;
|
||||
|
||||
menuTable[0] = NULL;
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -26,8 +26,75 @@
|
||||
#ifndef CRUISE_SAVELOAD_H
|
||||
#define CRUISE_SAVELOAD_H
|
||||
|
||||
#include "common/scummsys.h"
|
||||
#include "common/savefile.h"
|
||||
|
||||
namespace Cruise {
|
||||
|
||||
/* TODO: This code is copied verbatim from the Tinsel engine, and in turn was derived from
|
||||
* the SCUMM engine. As such it should probably be brought into the common codebase
|
||||
*/
|
||||
#define SYNC_AS(SUFFIX,TYPE,SIZE) \
|
||||
template <class T> \
|
||||
void syncAs ## SUFFIX(T &val) { \
|
||||
if (_loadStream) \
|
||||
val = static_cast<T>(_loadStream->read ## SUFFIX()); \
|
||||
else { \
|
||||
TYPE tmp = val; \
|
||||
_saveStream->write ## SUFFIX(tmp); \
|
||||
} \
|
||||
_bytesSynced += SIZE; \
|
||||
}
|
||||
|
||||
|
||||
class Serializer {
|
||||
public:
|
||||
Serializer(Common::SeekableReadStream *in, Common::OutSaveFile *out)
|
||||
: _loadStream(in), _saveStream(out), _bytesSynced(0) {
|
||||
assert(in || out);
|
||||
}
|
||||
|
||||
bool isSaving() { return (_saveStream != 0); }
|
||||
bool isLoading() { return (_loadStream != 0); }
|
||||
|
||||
uint bytesSynced() const { return _bytesSynced; }
|
||||
|
||||
void syncBytes(byte *buf, uint16 size) {
|
||||
if (_loadStream)
|
||||
_loadStream->read(buf, size);
|
||||
else
|
||||
_saveStream->write(buf, size);
|
||||
_bytesSynced += size;
|
||||
}
|
||||
|
||||
void syncString(char *buf, uint16 size) {
|
||||
syncBytes((byte *)buf, size);
|
||||
}
|
||||
|
||||
SYNC_AS(Byte, byte, 1)
|
||||
|
||||
SYNC_AS(Uint16LE, uint16, 2)
|
||||
SYNC_AS(Uint16BE, uint16, 2)
|
||||
SYNC_AS(Sint16LE, int16, 2)
|
||||
SYNC_AS(Sint16BE, int16, 2)
|
||||
|
||||
SYNC_AS(Uint32LE, uint32, 4)
|
||||
SYNC_AS(Uint32BE, uint32, 4)
|
||||
SYNC_AS(Sint32LE, int32, 4)
|
||||
SYNC_AS(Sint32BE, int32, 4)
|
||||
|
||||
protected:
|
||||
Common::SeekableReadStream *_loadStream;
|
||||
Common::OutSaveFile *_saveStream;
|
||||
|
||||
uint _bytesSynced;
|
||||
};
|
||||
|
||||
#undef SYNC_AS
|
||||
|
||||
|
||||
|
||||
|
||||
int saveSavegameData(int saveGameIdx);
|
||||
int loadSavegameData(int saveGameIdx);
|
||||
|
||||
|
@ -51,7 +51,7 @@ int32 volumeDataLoaded = 0;
|
||||
|
||||
int16 numOfDisks;
|
||||
|
||||
char musicName[15];
|
||||
char musicName[21];
|
||||
char lastOverlay[15];
|
||||
char nextOverlay[15];
|
||||
|
||||
@ -82,11 +82,11 @@ int16 displayOn = 1;
|
||||
|
||||
int16 globalVars[2000];
|
||||
|
||||
dataFileEntry filesDatabase[257];
|
||||
dataFileEntry filesDatabase[NUM_FILE_ENTRIES];
|
||||
|
||||
int16 bootOverlayNumber;
|
||||
|
||||
int16 initVar5[12];
|
||||
SoundEntry soundList[4];
|
||||
|
||||
opcodeTypeFunction opcodeTypeTable[64];
|
||||
|
||||
|
@ -132,6 +132,13 @@ struct dataFileEntry {
|
||||
uint16 height;
|
||||
dataFileEntrySub subData;
|
||||
};
|
||||
|
||||
struct SoundEntry {
|
||||
int16 frameNum;
|
||||
uint16 frequency;
|
||||
int16 volume;
|
||||
};
|
||||
|
||||
/*
|
||||
struct systemStringsStruct {
|
||||
int8 param;
|
||||
@ -147,7 +154,7 @@ extern int32 volumeDataLoaded;
|
||||
|
||||
extern int16 numOfDisks;
|
||||
|
||||
extern char musicName[15];
|
||||
extern char musicName[21];
|
||||
extern char lastOverlay[15];
|
||||
extern char nextOverlay[15];
|
||||
|
||||
@ -177,12 +184,14 @@ extern int16 volumeNumberOfEntry;
|
||||
|
||||
extern int16 displayOn;
|
||||
|
||||
#define NUM_FILE_ENTRIES 257
|
||||
|
||||
extern int16 globalVars[2000];
|
||||
extern dataFileEntry filesDatabase[257];
|
||||
extern dataFileEntry filesDatabase[NUM_FILE_ENTRIES];
|
||||
|
||||
extern int16 bootOverlayNumber;
|
||||
|
||||
extern int16 initVar5[12];
|
||||
extern SoundEntry soundList[4];
|
||||
|
||||
extern opcodeTypeFunction opcodeTypeTable[64];
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user