aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorPaul Gilbert2011-07-05 20:26:34 +1000
committerPaul Gilbert2011-07-05 20:26:34 +1000
commitfe0ff3b2e98b8a0ec68f497925aefbdea77aeed0 (patch)
treeac085089262f67f823b7af4d70a30ac648572404 /engines
parentdbf9e4679c694277be20dd1d1bc5db8d60f7fabd (diff)
downloadscummvm-rg350-fe0ff3b2e98b8a0ec68f497925aefbdea77aeed0.tar.gz
scummvm-rg350-fe0ff3b2e98b8a0ec68f497925aefbdea77aeed0.tar.bz2
scummvm-rg350-fe0ff3b2e98b8a0ec68f497925aefbdea77aeed0.zip
CGE: Converted loadGame to use the ScummVM serialiser
Diffstat (limited to 'engines')
-rw-r--r--engines/cge/cge_main.cpp46
-rw-r--r--engines/cge/general.cpp4
-rw-r--r--engines/cge/general.h6
-rw-r--r--engines/cge/vga13h.cpp24
-rw-r--r--engines/cge/vga13h.h3
5 files changed, 66 insertions, 17 deletions
diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp
index 6b02f82910..08e373d322 100644
--- a/engines/cge/cge_main.cpp
+++ b/engines/cge/cge_main.cpp
@@ -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);
+
+ // 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]);
- file.read((uint8 *) &i, sizeof(i));
- if (i != SVGCHKSUM)
+ 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)
diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp
index 3c0dc8a802..50dfeaeb5a 100644
--- a/engines/cge/general.cpp
+++ b/engines/cge/general.cpp
@@ -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;
}
diff --git a/engines/cge/general.h b/engines/cge/general.h
index 438e9c014d..95660ad4df 100644
--- a/engines/cge/general.h
+++ b/engines/cge/general.h
@@ -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);
- }
};
diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp
index aa7cd8ad06..1aec1689bc 100644
--- a/engines/cge/vga13h.cpp
+++ b/engines/cge/vga13h.cpp
@@ -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();
diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h
index 5ef7f99c69..d5a87e973d 100644
--- a/engines/cge/vga13h.h
+++ b/engines/cge/vga13h.h
@@ -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;
};