diff options
Diffstat (limited to 'scumm/saveload.h')
-rw-r--r-- | scumm/saveload.h | 79 |
1 files changed, 60 insertions, 19 deletions
diff --git a/scumm/saveload.h b/scumm/saveload.h index 914d6b9346..1667aeb045 100644 --- a/scumm/saveload.h +++ b/scumm/saveload.h @@ -22,6 +22,17 @@ #ifndef SAVELOAD_H #define SAVELOAD_H +// Support for "old" savegames (made with 2501 CVS build) +// Can be useful for other ports too :) + +#define VER_V10 10 +#define VER_V9 9 +#define VER_V8 8 +#define VER_V7 7 + +#define CURRENT_VER VER_V10 + + // To work around a warning in GCC 3.2 (and 3.1 ?) regarding non-POD types, // we use a small trick: instead of 0 we use 42. Why? Well, it seems newer GCC // versions hae a heuristic built in to detect "offset-of" patterns - which is exactly @@ -32,11 +43,29 @@ #define OFFS(type,item) (((int)(&((type*)42)->type::item))-42) #define SIZE(type,item) sizeof(((type*)42)->type::item) -#define MKLINE(type,item,saveas) {OFFS(type,item),saveas,SIZE(type,item)} -#define MKARRAY(type,item,saveas,num) {OFFS(type,item),128|saveas,SIZE(type,item)}, {num,0,0} -#define MKEND() {0xFFFF,0xFF,0xFF} -#define MKREF(type,item,refid) {OFFS(type,item),refid,0xFF} +// Any item that is still in use automatically gets a maxVersion equal to CURRENT_VER +#define MKLINE(type,item,saveas,minVer) {OFFS(type,item),saveas,SIZE(type,item),minVer,CURRENT_VER} +#define MKARRAY(type,item,saveas,num,minVer) {OFFS(type,item),128|saveas,SIZE(type,item),minVer,CURRENT_VER}, {num,0,0,0,0} + +// Use this if you have an entry that used to be smaller: +#define MKLINE_OLD(type,item,saveas,minVer,maxVer) {OFFS(type,item),saveas,SIZE(type,item),minVer,maxVer} +#define MKARRAY_OLD(type,item,saveas,num,minVer,maxVer) {OFFS(type,item),128|saveas,SIZE(type,item),minVer,maxVer}, {num,0,0,0,0} + +// An obsolete item/array, to be ignored upon load. We retain the type/item params to make it easier to debug. +// Obsolete items have size == 0. +#define MK_OBSOLETE(type,item,saveas,minVer,maxVer) {0,saveas,0,minVer,maxVer} +#define MK_OBSOLETE_ARRAY(type,item,saveas,num,minVer,maxVer) {0,128|saveas,0,minVer,maxVer}, {num,0,0,0,0} + +// End marker +#define MKEND() {0xFFFF,0xFF,0xFF,0,0} + +// A reference +#define MKREF(type,item,refid,minVer) {OFFS(type,item),refid,0xFF,minVer,CURRENT_VER} + +// An obsolete reference. +#define MK_OBSOLETE_REF(type,item,refid,minVer,maxVer) {0,sleUint16,0,minVer,maxVer} + enum { sleByte = 1, @@ -52,6 +81,8 @@ struct SaveLoadEntry { uint32 offs; uint8 type; uint8 size; + uint8 minVersion; + uint8 maxVersion; }; struct SerializerStream { @@ -83,24 +114,25 @@ struct SerializerStream { typedef int SerializerSaveReference(void *me, byte type, void *ref); typedef void *SerializerLoadReference(void *me, byte type, int ref); -struct Serializer { - SerializerStream _saveLoadStream; +class Serializer { +public: + Serializer(SerializerStream stream, bool saveOrLoad, uint32 savegameVersion) + : _save_ref(0), _load_ref(0), _ref_me(0), + _saveLoadStream(stream), _saveOrLoad(saveOrLoad), + _savegameVersion(savegameVersion) + { } - union { - SerializerSaveReference *_save_ref; - SerializerLoadReference *_load_ref; - void *_saveload_ref; - }; + SerializerSaveReference *_save_ref; + SerializerLoadReference *_load_ref; void *_ref_me; - bool _saveOrLoad; - - void saveBytes(void *b, int len); - void loadBytes(void *b, int len); - void saveLoadArrayOf(void *b, int len, int datasize, byte filetype); - void saveLoadEntries(void *d, const SaveLoadEntry *sle); void saveLoadArrayOf(void *b, int num, int datasize, const SaveLoadEntry *sle); + void saveLoadEntries(void *d, const SaveLoadEntry *sle); + + bool isSaving() { return _saveOrLoad; } + + bool checkEOFLoadStream(); void saveUint32(uint32 d); void saveWord(uint16 d); @@ -110,10 +142,19 @@ struct Serializer { uint16 loadWord(); uint32 loadUint32(); - bool isSaving() { return _saveOrLoad; } + void saveBytes(void *b, int len); + void loadBytes(void *b, int len); + +protected: + SerializerStream _saveLoadStream; + bool _saveOrLoad; + uint32 _savegameVersion; - bool checkEOFLoadStream(); + void saveArrayOf(void *b, int len, int datasize, byte filetype); + void loadArrayOf(void *b, int len, int datasize, byte filetype); + void saveEntries(void *d, const SaveLoadEntry *sle); + void loadEntries(void *d, const SaveLoadEntry *sle); }; #endif |