2002-07-02 20:57:27 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
2005-01-01 16:09:25 +00:00
|
|
|
* Copyright (C) 2002-2005 The ScummVM project
|
2002-07-02 20:57:27 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* $Header$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SAVELOAD_H
|
|
|
|
#define SAVELOAD_H
|
|
|
|
|
2003-08-01 12:21:04 +00:00
|
|
|
#include "common/scummsys.h"
|
2003-06-15 01:42:19 +00:00
|
|
|
|
2005-04-10 15:13:40 +00:00
|
|
|
class InSaveFile;
|
|
|
|
class OutSaveFile;
|
2003-10-03 18:33:57 +00:00
|
|
|
|
|
|
|
namespace Scumm {
|
|
|
|
|
2002-12-08 16:14:29 +00:00
|
|
|
// Support for "old" savegames (made with 2501 CVS build)
|
|
|
|
// Can be useful for other ports too :)
|
|
|
|
|
2003-08-29 04:05:23 +00:00
|
|
|
#define VER(x) x
|
2005-04-15 08:34:18 +00:00
|
|
|
#define CURRENT_VER 49
|
2002-12-08 16:14:29 +00:00
|
|
|
|
2002-09-22 03:57:41 +00:00
|
|
|
// 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
|
2005-01-06 15:57:12 +00:00
|
|
|
// versions have a heuristic built in to detect "offset-of" patterns - which is exactly
|
2002-09-22 03:57:41 +00:00
|
|
|
// what our OFFS macro does. Now, for non-POD types this is not really legal, because
|
|
|
|
// member need not be at a fixed offset relative to the variable, even if they are in
|
|
|
|
// current reality (many of our complex structs are non-POD; for an explanation of
|
|
|
|
// what POD means refer to http://www-cpd.fnal.gov/personal/wb/boost/ISOcxx/doc/POD.html)
|
|
|
|
|
2003-09-19 19:11:33 +00:00
|
|
|
#define OFFS(type,item) (((long)(&((type*)42)->type::item))-42)
|
2002-09-22 03:57:41 +00:00
|
|
|
#define SIZE(type,item) sizeof(((type*)42)->type::item)
|
2002-09-22 02:53:15 +00:00
|
|
|
|
2002-12-08 16:14:29 +00:00
|
|
|
// 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}
|
2003-05-23 02:58:34 +00:00
|
|
|
#define MKARRAY(type,item,saveas,dim,minVer) {OFFS(type,item),128|saveas,SIZE(type,item),minVer,CURRENT_VER}, {dim,1,0,0,0}
|
|
|
|
#define MKARRAY2(type,item,saveas,dim,dim2,rowlen,minVer) {OFFS(type,item),128|saveas,SIZE(type,item),minVer,CURRENT_VER}, {dim,dim2,rowlen,0,0}
|
2002-12-08 16:14:29 +00:00
|
|
|
|
|
|
|
// 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}
|
2003-05-23 02:58:34 +00:00
|
|
|
#define MKARRAY_OLD(type,item,saveas,dim,minVer,maxVer) {OFFS(type,item),128|saveas,SIZE(type,item),minVer,maxVer}, {dim,1,0,0,0}
|
|
|
|
#define MKARRAY2_OLD(type,item,saveas,dim,dim2,rowlen,minVer,maxVer) {OFFS(type,item),128|saveas,SIZE(type,item),minVer,maxVer}, {dim,dim2,rowlen,0,0}
|
2002-12-08 16:14:29 +00:00
|
|
|
|
|
|
|
// 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}
|
2003-05-23 02:58:34 +00:00
|
|
|
#define MK_OBSOLETE_ARRAY(type,item,saveas,dim,minVer,maxVer) {0,128|saveas,0,minVer,maxVer}, {dim,1,0,0,0}
|
|
|
|
#define MK_OBSOLETE_ARRAY2(type,item,saveas,dim,dim2,rowlen,minVer,maxVer) {0,128|saveas,0,minVer,maxVer}, {dim,dim2,rowlen,0,0}
|
2002-12-08 16:14:29 +00:00
|
|
|
|
|
|
|
// 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}
|
|
|
|
|
2002-09-22 02:53:15 +00:00
|
|
|
|
2002-07-16 21:03:14 +00:00
|
|
|
enum {
|
|
|
|
sleByte = 1,
|
|
|
|
sleUint8 = 1,
|
|
|
|
sleInt8 = 1,
|
|
|
|
sleInt16 = 2,
|
|
|
|
sleUint16 = 3,
|
|
|
|
sleInt32 = 4,
|
|
|
|
sleUint32 = 5
|
|
|
|
};
|
|
|
|
|
2002-07-04 10:05:40 +00:00
|
|
|
struct SaveLoadEntry {
|
2003-05-23 02:58:34 +00:00
|
|
|
uint32 offs; // or: array dimension
|
|
|
|
uint16 type; // or: array dimension 2
|
|
|
|
uint16 size; // or: array row length
|
2002-12-08 16:14:29 +00:00
|
|
|
uint8 minVersion;
|
|
|
|
uint8 maxVersion;
|
2002-07-04 10:05:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef int SerializerSaveReference(void *me, byte type, void *ref);
|
|
|
|
typedef void *SerializerLoadReference(void *me, byte type, int ref);
|
|
|
|
|
2002-12-08 16:14:29 +00:00
|
|
|
class Serializer {
|
|
|
|
public:
|
2005-04-10 15:13:40 +00:00
|
|
|
Serializer(InSaveFile *in, OutSaveFile *out, uint32 savegameVersion)
|
|
|
|
: _loadStream(in), _saveStream(out), _save_ref(0), _load_ref(0), _ref_me(0),
|
2002-12-08 16:14:29 +00:00
|
|
|
_savegameVersion(savegameVersion)
|
|
|
|
{ }
|
2002-07-04 10:05:40 +00:00
|
|
|
|
2002-12-08 16:14:29 +00:00
|
|
|
SerializerSaveReference *_save_ref;
|
|
|
|
SerializerLoadReference *_load_ref;
|
2002-07-04 10:05:40 +00:00
|
|
|
void *_ref_me;
|
|
|
|
|
|
|
|
void saveLoadArrayOf(void *b, int len, int datasize, byte filetype);
|
|
|
|
void saveLoadArrayOf(void *b, int num, int datasize, const SaveLoadEntry *sle);
|
2002-12-08 16:14:29 +00:00
|
|
|
void saveLoadEntries(void *d, const SaveLoadEntry *sle);
|
|
|
|
|
2005-04-10 15:13:40 +00:00
|
|
|
bool isSaving() { return (_saveStream != 0); }
|
|
|
|
bool isLoading() { return (_loadStream != 0); }
|
2002-12-21 20:10:47 +00:00
|
|
|
uint32 getVersion() { return _savegameVersion; }
|
2002-12-08 16:14:29 +00:00
|
|
|
|
2002-07-04 10:05:40 +00:00
|
|
|
void saveUint32(uint32 d);
|
2003-12-27 00:10:20 +00:00
|
|
|
void saveUint16(uint16 d);
|
2002-07-04 10:05:40 +00:00
|
|
|
void saveByte(byte b);
|
|
|
|
|
|
|
|
byte loadByte();
|
2003-12-27 00:10:20 +00:00
|
|
|
uint16 loadUint16();
|
2002-07-04 10:05:40 +00:00
|
|
|
uint32 loadUint32();
|
|
|
|
|
2002-12-08 16:14:29 +00:00
|
|
|
void saveBytes(void *b, int len);
|
|
|
|
void loadBytes(void *b, int len);
|
|
|
|
|
|
|
|
protected:
|
2005-04-10 15:13:40 +00:00
|
|
|
InSaveFile *_loadStream;
|
|
|
|
OutSaveFile *_saveStream;
|
2002-12-08 16:14:29 +00:00
|
|
|
uint32 _savegameVersion;
|
2002-07-04 10:05:40 +00:00
|
|
|
|
2002-12-08 16:14:29 +00:00
|
|
|
void saveArrayOf(void *b, int len, int datasize, byte filetype);
|
|
|
|
void loadArrayOf(void *b, int len, int datasize, byte filetype);
|
2002-07-04 10:05:40 +00:00
|
|
|
|
2002-12-08 16:14:29 +00:00
|
|
|
void saveEntries(void *d, const SaveLoadEntry *sle);
|
|
|
|
void loadEntries(void *d, const SaveLoadEntry *sle);
|
2002-07-04 10:05:40 +00:00
|
|
|
};
|
|
|
|
|
2003-10-03 18:33:57 +00:00
|
|
|
} // End of namespace Scumm
|
|
|
|
|
2002-07-02 20:57:27 +00:00
|
|
|
#endif
|