aboutsummaryrefslogtreecommitdiff
path: root/engines/lastexpress/game/savegame.h
diff options
context:
space:
mode:
authorLittleboy2012-07-29 19:44:22 -0400
committerLittleboy2012-07-29 21:09:34 -0400
commitc8df89e6b2ad04aac03be89c1ac214dbd144c982 (patch)
tree92d238ec7d5e87e23f8809aa5a5776995b368a91 /engines/lastexpress/game/savegame.h
parentd80d08128b2a030a65ce4f48776f5c63370ac598 (diff)
downloadscummvm-rg350-c8df89e6b2ad04aac03be89c1ac214dbd144c982.tar.gz
scummvm-rg350-c8df89e6b2ad04aac03be89c1ac214dbd144c982.tar.bz2
scummvm-rg350-c8df89e6b2ad04aac03be89c1ac214dbd144c982.zip
LASTEXPRESS: Reorganize savegame code to prepare for compressed savegames support
Diffstat (limited to 'engines/lastexpress/game/savegame.h')
-rw-r--r--engines/lastexpress/game/savegame.h75
1 files changed, 49 insertions, 26 deletions
diff --git a/engines/lastexpress/game/savegame.h b/engines/lastexpress/game/savegame.h
index 6f0408487f..a04c700fb6 100644
--- a/engines/lastexpress/game/savegame.h
+++ b/engines/lastexpress/game/savegame.h
@@ -80,11 +80,51 @@
namespace LastExpress {
// Savegame signatures
-#define SAVEGAME_SIGNATURE 0x12001200
-#define SAVEGAME_ENTRY_SIGNATURE 0xE660E660
+#define SAVEGAME_SIGNATURE 0x12001200 // 301994496
+#define SAVEGAME_ENTRY_SIGNATURE 0xE660E660 // 3865110112
+
+#define WRAP_SYNC_FUNCTION(instance, className, method) \
+ new Common::Functor1Mem<Common::Serializer &, void, className>(instance, &className::method)
class LastExpressEngine;
+class SavegameStream : public Common::MemoryWriteStreamDynamic, public Common::SeekableReadStream {
+public:
+ SavegameStream() : MemoryWriteStreamDynamic(DisposeAfterUse::YES), _eos(false) {
+ _bufferOffset = -1;
+ _valueCount = 0;
+ _previousValue = 0;
+ _field_15F = 0;
+ _offset = 0;
+ _status = 0;
+
+ memset(_buffer, 0, 256);
+ }
+
+ int32 pos() const { return MemoryWriteStreamDynamic::pos(); }
+ int32 size() const { return MemoryWriteStreamDynamic::size(); }
+ bool seek(int32 offset, int whence = SEEK_SET) { return MemoryWriteStreamDynamic::seek(offset, whence); }
+ bool eos() const { return _eos; }
+ uint32 read(void *dataPtr, uint32 dataSize);
+
+ // Compressed data
+ uint32 writeValue(const void *dataPtr, uint32 dataSize);
+ uint32 readValue(void *dataPtr, uint32 dataSize);
+
+private:
+ bool _eos;
+
+ // Compression handling
+ int _bufferOffset;
+ int _valueCount;
+ byte _previousValue;
+ byte _field_15F;
+ int _offset;
+ int _status;
+
+ byte _buffer[256];
+};
+
class SaveLoad {
public:
SaveLoad(LastExpressEngine *engine);
@@ -116,30 +156,6 @@ public:
uint32 getLastSavegameTicks() const { return _gameTicksLastSavegame; }
private:
- class SavegameStream : public Common::MemoryWriteStreamDynamic, public Common::SeekableReadStream {
- public:
- SavegameStream() : MemoryWriteStreamDynamic(DisposeAfterUse::YES),
- _eos(false) {}
-
- int32 pos() const { return MemoryWriteStreamDynamic::pos(); }
- int32 size() const { return MemoryWriteStreamDynamic::size(); }
- bool seek(int32 offset, int whence = SEEK_SET) { return MemoryWriteStreamDynamic::seek(offset, whence); }
- bool eos() const { return _eos; }
- uint32 read(void *dataPtr, uint32 dataSize) {
- if ((int32)dataSize > size() - pos()) {
- dataSize = size() - pos();
- _eos = true;
- }
- memcpy(dataPtr, getData() + pos(), dataSize);
-
- seek(dataSize, SEEK_CUR);
-
- return dataSize;
- }
- private:
- bool _eos;
- };
-
LastExpressEngine *_engine;
struct SavegameMainHeader : Common::Serializable {
@@ -268,6 +284,9 @@ private:
void writeEntry(SavegameType type, EntityIndex entity, uint32 val);
void readEntry(SavegameType *type, EntityIndex *entity, uint32 *val, bool keepIndex);
+ uint32 writeValue(const char *name, Common::Functor1<Common::Serializer &, void> *function, uint size);
+ uint32 readValue(const char *name, Common::Functor1<Common::Serializer &, void> *function, uint size);
+
SavegameEntryHeader *getEntry(uint32 index);
// Opening save files
@@ -279,6 +298,10 @@ private:
void initStream();
void loadStream(GameId id);
void flushStream(GameId id);
+
+ // Misc
+ EntityIndex _entity;
+ void syncEntity(Common::Serializer &ser);
};
} // End of namespace LastExpress