mirror of
https://github.com/libretro/scummvm.git
synced 2025-04-14 04:30:43 +00:00
Converted the Cruise engine to use the new Common::Serializer class
svn-id: r39443
This commit is contained in:
parent
52d6f3323b
commit
57b0038e5e
@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
#include "cruise/cruise_main.h"
|
#include "cruise/cruise_main.h"
|
||||||
|
|
||||||
|
#include "common/serializer.h"
|
||||||
#include "common/savefile.h"
|
#include "common/savefile.h"
|
||||||
#include "common/system.h"
|
#include "common/system.h"
|
||||||
|
|
||||||
@ -39,12 +40,12 @@ struct overlayRestoreTemporary {
|
|||||||
|
|
||||||
overlayRestoreTemporary ovlRestoreData[90];
|
overlayRestoreTemporary ovlRestoreData[90];
|
||||||
|
|
||||||
static void syncPalette(Serializer &s, uint8 *p) {
|
static void syncPalette(Common::Serializer &s, uint8 *p) {
|
||||||
// This is different from the original, where palette entries are 2 bytes each
|
// This is different from the original, where palette entries are 2 bytes each
|
||||||
s.syncBytes(p, NBCOLORS * 3);
|
s.syncBytes(p, NBCOLORS * 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void syncBasicInfo(Serializer &s) {
|
static void syncBasicInfo(Common::Serializer &s) {
|
||||||
s.syncAsSint16LE(songLoaded);
|
s.syncAsSint16LE(songLoaded);
|
||||||
s.syncAsSint16LE(songPlayed);
|
s.syncAsSint16LE(songPlayed);
|
||||||
s.syncAsSint16LE(songLoop);
|
s.syncAsSint16LE(songLoop);
|
||||||
@ -107,7 +108,7 @@ static void syncBasicInfo(Serializer &s) {
|
|||||||
s.syncAsSint16LE(entrerMenuJoueur);
|
s.syncAsSint16LE(entrerMenuJoueur);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void syncBackgroundTable(Serializer &s) {
|
static void syncBackgroundTable(Common::Serializer &s) {
|
||||||
// restore backgroundTable
|
// restore backgroundTable
|
||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
s.syncString(backgroundTable[i].name, 9);
|
s.syncString(backgroundTable[i].name, 9);
|
||||||
@ -115,14 +116,14 @@ static void syncBackgroundTable(Serializer &s) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void syncPalScreen(Serializer &s) {
|
static void syncPalScreen(Common::Serializer &s) {
|
||||||
for (int i = 0; i < NBSCREENS; ++i) {
|
for (int i = 0; i < NBSCREENS; ++i) {
|
||||||
for (int j = 0; j < NBCOLORS; ++j)
|
for (int j = 0; j < NBCOLORS; ++j)
|
||||||
s.syncAsUint16LE(palScreen[i][j]);
|
s.syncAsUint16LE(palScreen[i][j]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void syncSoundList(Serializer &s) {
|
static void syncSoundList(Common::Serializer &s) {
|
||||||
for (int i = 0; i < 4; ++i) {
|
for (int i = 0; i < 4; ++i) {
|
||||||
SoundEntry &se = soundList[i];
|
SoundEntry &se = soundList[i];
|
||||||
s.syncAsSint16LE(se.frameNum);
|
s.syncAsSint16LE(se.frameNum);
|
||||||
@ -131,7 +132,7 @@ static void syncSoundList(Serializer &s) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void syncFilesDatabase(Serializer &s) {
|
static void syncFilesDatabase(Common::Serializer &s) {
|
||||||
uint8 dummyVal = 0;
|
uint8 dummyVal = 0;
|
||||||
|
|
||||||
for (int i = 0; i < NUM_FILE_ENTRIES; i++) {
|
for (int i = 0; i < NUM_FILE_ENTRIES; i++) {
|
||||||
@ -173,7 +174,7 @@ static void syncFilesDatabase(Serializer &s) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void syncPreloadData(Serializer &s) {
|
static void syncPreloadData(Common::Serializer &s) {
|
||||||
uint8 dummyByte = 0;
|
uint8 dummyByte = 0;
|
||||||
uint32 dummyLong = 0;
|
uint32 dummyLong = 0;
|
||||||
|
|
||||||
@ -191,7 +192,7 @@ static void syncPreloadData(Serializer &s) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void syncOverlays1(Serializer &s) {
|
static void syncOverlays1(Common::Serializer &s) {
|
||||||
uint8 dummyByte = 0;
|
uint8 dummyByte = 0;
|
||||||
uint32 dummyLong = 0;
|
uint32 dummyLong = 0;
|
||||||
|
|
||||||
@ -211,7 +212,7 @@ static void syncOverlays1(Serializer &s) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void syncOverlays2(Serializer &s) {
|
static void syncOverlays2(Common::Serializer &s) {
|
||||||
|
|
||||||
for (int i = 1; i < numOfLoadedOverlay; i++) {
|
for (int i = 1; i < numOfLoadedOverlay; i++) {
|
||||||
|
|
||||||
@ -274,7 +275,7 @@ static void syncOverlays2(Serializer &s) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncScript(Serializer &s, scriptInstanceStruct *entry) {
|
void syncScript(Common::Serializer &s, scriptInstanceStruct *entry) {
|
||||||
int numScripts = 0;
|
int numScripts = 0;
|
||||||
uint32 dummyLong = 0;
|
uint32 dummyLong = 0;
|
||||||
uint16 dummyWord = 0;
|
uint16 dummyWord = 0;
|
||||||
@ -328,7 +329,7 @@ void syncScript(Serializer &s, scriptInstanceStruct *entry) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void syncCell(Serializer &s) {
|
static void syncCell(Common::Serializer &s) {
|
||||||
int chunkCount = 0;
|
int chunkCount = 0;
|
||||||
cellStruct *t, *p;
|
cellStruct *t, *p;
|
||||||
uint16 dummyWord = 0;
|
uint16 dummyWord = 0;
|
||||||
@ -389,7 +390,7 @@ static void syncCell(Serializer &s) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void syncIncrust(Serializer &s) {
|
static void syncIncrust(Common::Serializer &s) {
|
||||||
int numEntries = 0;
|
int numEntries = 0;
|
||||||
backgroundIncrustStruct *pl, *pl1;
|
backgroundIncrustStruct *pl, *pl1;
|
||||||
uint8 dummyByte = 0;
|
uint8 dummyByte = 0;
|
||||||
@ -471,7 +472,7 @@ static void syncIncrust(Serializer &s) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void syncActors(Serializer &s) {
|
static void syncActors(Common::Serializer &s) {
|
||||||
int numEntries = 0;
|
int numEntries = 0;
|
||||||
actorStruct *ptr;
|
actorStruct *ptr;
|
||||||
uint16 dummyLong = 0;
|
uint16 dummyLong = 0;
|
||||||
@ -522,7 +523,7 @@ static void syncActors(Serializer &s) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void syncSongs(Serializer &s) {
|
static void syncSongs(Common::Serializer &s) {
|
||||||
int size = 0;
|
int size = 0;
|
||||||
|
|
||||||
if (songLoaded) {
|
if (songLoaded) {
|
||||||
@ -538,7 +539,7 @@ static void syncSongs(Serializer &s) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void syncCT(Serializer &s) {
|
static void syncCT(Common::Serializer &s) {
|
||||||
int v = (polyStruct) ? 1 : 0;
|
int v = (polyStruct) ? 1 : 0;
|
||||||
s.syncAsSint32LE(v);
|
s.syncAsSint32LE(v);
|
||||||
|
|
||||||
@ -573,7 +574,7 @@ static void syncCT(Serializer &s) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DoSync(Serializer &s) {
|
static void DoSync(Common::Serializer &s) {
|
||||||
syncBasicInfo(s);
|
syncBasicInfo(s);
|
||||||
|
|
||||||
syncPalette(s, newPal);
|
syncPalette(s, newPal);
|
||||||
@ -759,7 +760,7 @@ int saveSavegameData(int saveGameIdx) {
|
|||||||
f->write(saveIdentBuffer, 6);
|
f->write(saveIdentBuffer, 6);
|
||||||
|
|
||||||
if (!f->ioFailed()) {
|
if (!f->ioFailed()) {
|
||||||
Serializer s(NULL, f);
|
Common::Serializer s(NULL, f);
|
||||||
|
|
||||||
DoSync(s);
|
DoSync(s);
|
||||||
|
|
||||||
@ -801,7 +802,7 @@ int loadSavegameData(int saveGameIdx) {
|
|||||||
|
|
||||||
initVars();
|
initVars();
|
||||||
|
|
||||||
Serializer s(f, NULL);
|
Common::Serializer s(f, NULL);
|
||||||
DoSync(s);
|
DoSync(s);
|
||||||
|
|
||||||
delete f;
|
delete f;
|
||||||
|
@ -27,74 +27,9 @@
|
|||||||
#define CRUISE_SAVELOAD_H
|
#define CRUISE_SAVELOAD_H
|
||||||
|
|
||||||
#include "common/scummsys.h"
|
#include "common/scummsys.h"
|
||||||
#include "common/savefile.h"
|
|
||||||
|
|
||||||
namespace Cruise {
|
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 saveSavegameData(int saveGameIdx);
|
||||||
int loadSavegameData(int saveGameIdx);
|
int loadSavegameData(int saveGameIdx);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user