CGE: Converted loadGame to use the ScummVM serialiser

This commit is contained in:
Paul Gilbert 2011-07-05 20:26:34 +10:00
parent dbf9e4679c
commit fe0ff3b2e9
5 changed files with 67 additions and 18 deletions

View File

@ -26,6 +26,8 @@
*/
#include "common/scummsys.h"
#include "common/memstream.h"
#include "common/serializer.h"
#include "cge/general.h"
#include "cge/sound.h"
#include "cge/startup.h"
@ -182,14 +184,39 @@ void CGEEngine::loadGame(XFile &file, bool tiny = false) {
Sprite *spr;
int i;
for (st = _savTab; st->Ptr; st++) {
if (file._error)
error("Bad SVG");
file.read((uint8 *)((tiny || st->Flg) ? st->Ptr : &i), st->Len);
}
// Read the data into a data buffer
int size = file.size() - file.mark();
byte *dataBuffer = new byte[size];
file.read(dataBuffer, size);
Common::MemoryReadStream readStream(dataBuffer, size, DisposeAfterUse::YES);
Common::Serializer s(&readStream, NULL);
file.read((uint8 *) &i, sizeof(i));
if (i != SVGCHKSUM)
// Synchronise header data
s.syncAsUint16LE(_now);
s.syncAsUint16LE(_oldLev);
s.syncAsUint16LE(_demoText);
for (i = 0; i < 5; ++i)
s.syncAsUint16LE(_game);
s.syncAsSint16LE(i); // unused VGA::Mono variable
s.syncAsUint16LE(_music);
s.syncBytes(_volume, 2);
for (i = 0; i < 4; ++i)
s.syncAsUint16LE(_flag[i]);
for (i = 0; i < CAVE_MAX; ++i) {
s.syncAsSint16LE(_heroXY[i]._x);
s.syncAsUint16LE(_heroXY[i]._y);
}
for (i = 0; i < 1 + CAVE_MAX; ++i) {
s.syncAsByte(_barriers[i]._horz);
s.syncAsByte(_barriers[i]._vert);
}
for (i = 0; i < POCKET_NX; ++i)
s.syncAsUint16LE(_pocref[i]);
uint16 checksum;
s.syncAsUint16LE(checksum);
if (checksum != SVGCHKSUM)
error("%s", _text->getText(BADSVG_TEXT));
if (Startup::_core < CORE_HIG)
@ -202,12 +229,9 @@ void CGEEngine::loadGame(XFile &file, bool tiny = false) {
}
if (! tiny) { // load sprites & pocket
while (!file._error) {
while (!readStream.eos()) {
Sprite S(this, NULL);
uint16 n = file.read((uint8 *) &S, sizeof(S));
if (n != sizeof(S))
break;
S.sync(s);
S._prev = S._next = NULL;
spr = (scumm_stricmp(S._file + 2, "MUCHA") == 0) ? new Fly(this, NULL)

View File

@ -238,6 +238,10 @@ uint16 IoHand::read(void *buf, uint16 len) {
error("Read %s - %d bytes", _file->getName(), len);
if (_crypt)
_seed = _crypt(buf, len, Seed);
if (_file->eos())
_error = 1;
return bytesRead;
}

View File

@ -176,12 +176,6 @@ public:
virtual long mark() = 0;
virtual long size() = 0;
virtual long seek(long pos) = 0;
uint16 readWord() {
uint16 v;
read(&v, sizeof(uint16));
return FROM_LE_32(v);
}
};

View File

@ -779,6 +779,30 @@ BMP_PTR Sprite::ghost() {
return NULL;
}
void Sprite::sync(Common::Serializer &s) {
uint16 unused;
s.syncAsUint16LE(unused);
s.syncAsUint16LE(unused); // _ext
s.syncAsUint16LE(_ref);
s.syncAsByte(_cave);
s.syncBytes((byte *)&_flags, 2);
s.syncAsUint16LE(_x);
s.syncAsUint16LE(_y);
s.syncAsByte(_z);
s.syncAsUint16LE(_w);
s.syncAsUint16LE(_h);
s.syncAsUint16LE(_time);
s.syncAsByte(_nearPtr);
s.syncAsByte(_takePtr);
s.syncAsUint16LE(_seqPtr);
s.syncAsUint16LE(_shpCnt);
s.syncBytes((byte *)&_file[0], 9);
_file[8] = '\0';
s.syncAsUint16LE(unused); // _prev
s.syncAsUint16LE(unused); // _next
}
Sprite *spriteAt(int x, int y) {
Sprite *spr = NULL, * tail = _vga->_showQ->last();

View File

@ -28,6 +28,7 @@
#ifndef __CGE_VGA13H__
#define __CGE_VGA13H__
#include "common/serializer.h"
#include "graphics/surface.h"
#include "cge/general.h"
#include "cge/bitmap.h"
@ -201,6 +202,7 @@ public:
char _file[MAXFILE];
Sprite *_prev;
Sprite *_next;
bool works(Sprite *spr);
bool seqTest(int n);
inline bool active() {
@ -231,6 +233,7 @@ public:
Snail::Com *snList(SNLIST type);
virtual void touch(uint16 mask, int x, int y);
virtual void tick();
void sync(Common::Serializer &s);
private:
CGEEngine *_vm;
};