saveload.h
author truelight
Tue, 21 Feb 2006 19:42:42 +0000
changeset 3062 2c96a73da934
parent 3050 a19b2a2827b2
child 3072 d1e6aa66a450
permissions -rw-r--r--
(svn r3651) -Fix: r3646 fixed some lame compiler, but broke others... this fixes it for some more compilers
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2162
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2162
diff changeset
     2
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     3
#ifndef SAVELOAD_H
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     4
#define SAVELOAD_H
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
2162
b98e430ffd10 (svn r2672) Move saving/loading related declarations to saveload.h
tron
parents: 1887
diff changeset
     6
typedef enum SaveOrLoadResult {
3044
fbaef2401476 (svn r3624) - CodeChange: Some cosmetic changes in the saveload code;
Darkvater
parents: 2848
diff changeset
     7
	SL_OK     = 0, // completed successfully
fbaef2401476 (svn r3624) - CodeChange: Some cosmetic changes in the saveload code;
Darkvater
parents: 2848
diff changeset
     8
	SL_ERROR  = 1, // error that was caught before internal structures were modified
2162
b98e430ffd10 (svn r2672) Move saving/loading related declarations to saveload.h
tron
parents: 1887
diff changeset
     9
	SL_REINIT = 2, // error that was caught in the middle of updating game state, need to clear it. (can only happen during load)
b98e430ffd10 (svn r2672) Move saving/loading related declarations to saveload.h
tron
parents: 1887
diff changeset
    10
} SaveOrLoadResult;
b98e430ffd10 (svn r2672) Move saving/loading related declarations to saveload.h
tron
parents: 1887
diff changeset
    11
b98e430ffd10 (svn r2672) Move saving/loading related declarations to saveload.h
tron
parents: 1887
diff changeset
    12
typedef enum SaveOrLoadMode {
3044
fbaef2401476 (svn r3624) - CodeChange: Some cosmetic changes in the saveload code;
Darkvater
parents: 2848
diff changeset
    13
	SL_INVALID  = -1,
fbaef2401476 (svn r3624) - CodeChange: Some cosmetic changes in the saveload code;
Darkvater
parents: 2848
diff changeset
    14
	SL_LOAD     =  0,
fbaef2401476 (svn r3624) - CodeChange: Some cosmetic changes in the saveload code;
Darkvater
parents: 2848
diff changeset
    15
	SL_SAVE     =  1,
fbaef2401476 (svn r3624) - CodeChange: Some cosmetic changes in the saveload code;
Darkvater
parents: 2848
diff changeset
    16
	SL_OLD_LOAD =  2,
2162
b98e430ffd10 (svn r2672) Move saving/loading related declarations to saveload.h
tron
parents: 1887
diff changeset
    17
} SaveOrLoadMode;
b98e430ffd10 (svn r2672) Move saving/loading related declarations to saveload.h
tron
parents: 1887
diff changeset
    18
b98e430ffd10 (svn r2672) Move saving/loading related declarations to saveload.h
tron
parents: 1887
diff changeset
    19
SaveOrLoadResult SaveOrLoad(const char *filename, int mode);
2285
410dedcf46d1 (svn r2809) Implement more generic threading functions, which allow more than one thread
tron
parents: 2186
diff changeset
    20
void WaitTillSaved(void);
2162
b98e430ffd10 (svn r2672) Move saving/loading related declarations to saveload.h
tron
parents: 1887
diff changeset
    21
b98e430ffd10 (svn r2672) Move saving/loading related declarations to saveload.h
tron
parents: 1887
diff changeset
    22
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1024
diff changeset
    23
typedef void ChunkSaveLoadProc(void);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    24
typedef void AutolengthProc(void *arg);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    25
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    26
typedef struct {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    27
	uint32 id;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    28
	ChunkSaveLoadProc *save_proc;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    29
	ChunkSaveLoadProc *load_proc;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    30
	uint32 flags;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    31
} ChunkHandler;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    32
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    33
typedef struct {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    34
	byte null;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    35
} NullStruct;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    36
1881
435d39bd6ee0 (svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents: 1217
diff changeset
    37
typedef enum SLRefType {
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 956
diff changeset
    38
	REF_ORDER       = 0,
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 956
diff changeset
    39
	REF_VEHICLE     = 1,
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 956
diff changeset
    40
	REF_STATION     = 2,
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 956
diff changeset
    41
	REF_TOWN        = 3,
1217
59c024cfaf54 (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1093
diff changeset
    42
	REF_VEHICLE_OLD = 4,
2848
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2685
diff changeset
    43
	REF_ROADSTOPS   = 5,
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2685
diff changeset
    44
	REF_ENGINE_RENEWS = 6,
1881
435d39bd6ee0 (svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents: 1217
diff changeset
    45
} SLRefType;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    46
3044
fbaef2401476 (svn r3624) - CodeChange: Some cosmetic changes in the saveload code;
Darkvater
parents: 2848
diff changeset
    47
#define SL_MAX_VERSION 255
1881
435d39bd6ee0 (svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents: 1217
diff changeset
    48
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    49
enum {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    50
	INC_VEHICLE_COMMON = 0,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    51
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    52
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    53
enum {
3044
fbaef2401476 (svn r3624) - CodeChange: Some cosmetic changes in the saveload code;
Darkvater
parents: 2848
diff changeset
    54
	CH_RIFF         = 0,
fbaef2401476 (svn r3624) - CodeChange: Some cosmetic changes in the saveload code;
Darkvater
parents: 2848
diff changeset
    55
	CH_ARRAY        = 1,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    56
	CH_SPARSE_ARRAY = 2,
3044
fbaef2401476 (svn r3624) - CodeChange: Some cosmetic changes in the saveload code;
Darkvater
parents: 2848
diff changeset
    57
	CH_TYPE_MASK    = 3,
fbaef2401476 (svn r3624) - CodeChange: Some cosmetic changes in the saveload code;
Darkvater
parents: 2848
diff changeset
    58
	CH_LAST         = 8,
fbaef2401476 (svn r3624) - CodeChange: Some cosmetic changes in the saveload code;
Darkvater
parents: 2848
diff changeset
    59
	CH_AUTO_LENGTH  = 16,
fbaef2401476 (svn r3624) - CodeChange: Some cosmetic changes in the saveload code;
Darkvater
parents: 2848
diff changeset
    60
fbaef2401476 (svn r3624) - CodeChange: Some cosmetic changes in the saveload code;
Darkvater
parents: 2848
diff changeset
    61
	CH_PRI_0          = 0 << 4,
fbaef2401476 (svn r3624) - CodeChange: Some cosmetic changes in the saveload code;
Darkvater
parents: 2848
diff changeset
    62
	CH_PRI_1          = 1 << 4,
fbaef2401476 (svn r3624) - CodeChange: Some cosmetic changes in the saveload code;
Darkvater
parents: 2848
diff changeset
    63
	CH_PRI_2          = 2 << 4,
fbaef2401476 (svn r3624) - CodeChange: Some cosmetic changes in the saveload code;
Darkvater
parents: 2848
diff changeset
    64
	CH_PRI_3          = 3 << 4,
fbaef2401476 (svn r3624) - CodeChange: Some cosmetic changes in the saveload code;
Darkvater
parents: 2848
diff changeset
    65
	CH_PRI_SHL        = 4,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    66
	CH_NUM_PRI_LEVELS = 4,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    67
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    68
3046
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
    69
enum VarTypes {
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
    70
	/* 4 bytes allocated a maximum of 16 types for NumberType */
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
    71
	SLE_FILE_I8       = 0,
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
    72
	SLE_FILE_U8       = 1,
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
    73
	SLE_FILE_I16      = 2,
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
    74
	SLE_FILE_U16      = 3,
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
    75
	SLE_FILE_I32      = 4,
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
    76
	SLE_FILE_U32      = 5,
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
    77
	SLE_FILE_I64      = 6,
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
    78
	SLE_FILE_U64      = 7,
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
    79
	SLE_FILE_STRINGID = 8, /// StringID offset into strings-array
3048
adf46229d390 (svn r3628) - Add BOOL and STRING types to saveload capabilities. String is unused up till now and it saves the full-buffer, regardless of how many characters the string actually has. So give a warning for that and figure it out later.
Darkvater
parents: 3046
diff changeset
    80
	SLE_FILE_STRING   = 9,
adf46229d390 (svn r3628) - Add BOOL and STRING types to saveload capabilities. String is unused up till now and it saves the full-buffer, regardless of how many characters the string actually has. So give a warning for that and figure it out later.
Darkvater
parents: 3046
diff changeset
    81
	/* 6 more possible primitives */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    82
3046
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
    83
	/* 4 bytes allocated a maximum of 16 types for NumberType */
3048
adf46229d390 (svn r3628) - Add BOOL and STRING types to saveload capabilities. String is unused up till now and it saves the full-buffer, regardless of how many characters the string actually has. So give a warning for that and figure it out later.
Darkvater
parents: 3046
diff changeset
    84
	SLE_VAR_BL   =  0 << 4,
adf46229d390 (svn r3628) - Add BOOL and STRING types to saveload capabilities. String is unused up till now and it saves the full-buffer, regardless of how many characters the string actually has. So give a warning for that and figure it out later.
Darkvater
parents: 3046
diff changeset
    85
	SLE_VAR_I8   =  1 << 4,
adf46229d390 (svn r3628) - Add BOOL and STRING types to saveload capabilities. String is unused up till now and it saves the full-buffer, regardless of how many characters the string actually has. So give a warning for that and figure it out later.
Darkvater
parents: 3046
diff changeset
    86
	SLE_VAR_U8   =  2 << 4,
adf46229d390 (svn r3628) - Add BOOL and STRING types to saveload capabilities. String is unused up till now and it saves the full-buffer, regardless of how many characters the string actually has. So give a warning for that and figure it out later.
Darkvater
parents: 3046
diff changeset
    87
	SLE_VAR_I16  =  3 << 4,
adf46229d390 (svn r3628) - Add BOOL and STRING types to saveload capabilities. String is unused up till now and it saves the full-buffer, regardless of how many characters the string actually has. So give a warning for that and figure it out later.
Darkvater
parents: 3046
diff changeset
    88
	SLE_VAR_U16  =  4 << 4,
adf46229d390 (svn r3628) - Add BOOL and STRING types to saveload capabilities. String is unused up till now and it saves the full-buffer, regardless of how many characters the string actually has. So give a warning for that and figure it out later.
Darkvater
parents: 3046
diff changeset
    89
	SLE_VAR_I32  =  5 << 4,
adf46229d390 (svn r3628) - Add BOOL and STRING types to saveload capabilities. String is unused up till now and it saves the full-buffer, regardless of how many characters the string actually has. So give a warning for that and figure it out later.
Darkvater
parents: 3046
diff changeset
    90
	SLE_VAR_U32  =  6 << 4,
adf46229d390 (svn r3628) - Add BOOL and STRING types to saveload capabilities. String is unused up till now and it saves the full-buffer, regardless of how many characters the string actually has. So give a warning for that and figure it out later.
Darkvater
parents: 3046
diff changeset
    91
	SLE_VAR_I64  =  7 << 4,
adf46229d390 (svn r3628) - Add BOOL and STRING types to saveload capabilities. String is unused up till now and it saves the full-buffer, regardless of how many characters the string actually has. So give a warning for that and figure it out later.
Darkvater
parents: 3046
diff changeset
    92
	SLE_VAR_U64  =  8 << 4,
adf46229d390 (svn r3628) - Add BOOL and STRING types to saveload capabilities. String is unused up till now and it saves the full-buffer, regardless of how many characters the string actually has. So give a warning for that and figure it out later.
Darkvater
parents: 3046
diff changeset
    93
	SLE_VAR_NULL =  9 << 4, /// useful to write zeros in savegame.
adf46229d390 (svn r3628) - Add BOOL and STRING types to saveload capabilities. String is unused up till now and it saves the full-buffer, regardless of how many characters the string actually has. So give a warning for that and figure it out later.
Darkvater
parents: 3046
diff changeset
    94
	SLE_VAR_STRB = 10 << 4, /// normal string (with pre-allocated buffer)
adf46229d390 (svn r3628) - Add BOOL and STRING types to saveload capabilities. String is unused up till now and it saves the full-buffer, regardless of how many characters the string actually has. So give a warning for that and figure it out later.
Darkvater
parents: 3046
diff changeset
    95
	SLE_VAR_STRQ = 11 << 4, /// string enclosed in parentheses
adf46229d390 (svn r3628) - Add BOOL and STRING types to saveload capabilities. String is unused up till now and it saves the full-buffer, regardless of how many characters the string actually has. So give a warning for that and figure it out later.
Darkvater
parents: 3046
diff changeset
    96
	/* 4 more possible primitives */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    97
3046
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
    98
	/* Shortcut values */
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
    99
	SLE_VAR_CHAR = SLE_VAR_I8,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   100
3046
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
   101
	/* Default combinations of variables. As savegames change, so can variables
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
   102
	 * and thus it is possible that the saved value and internal size do not
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
   103
	 * match and you need to specify custom combo. The defaults are listed here */
3048
adf46229d390 (svn r3628) - Add BOOL and STRING types to saveload capabilities. String is unused up till now and it saves the full-buffer, regardless of how many characters the string actually has. So give a warning for that and figure it out later.
Darkvater
parents: 3046
diff changeset
   104
	SLE_BOOL        = SLE_FILE_I8  | SLE_VAR_BL,
3046
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
   105
	SLE_INT8        = SLE_FILE_I8  | SLE_VAR_I8,
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
   106
	SLE_UINT8       = SLE_FILE_U8  | SLE_VAR_U8,
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
   107
	SLE_INT16       = SLE_FILE_I16 | SLE_VAR_I16,
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
   108
	SLE_UINT16      = SLE_FILE_U16 | SLE_VAR_U16,
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
   109
	SLE_INT32       = SLE_FILE_I32 | SLE_VAR_I32,
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
   110
	SLE_UINT32      = SLE_FILE_U32 | SLE_VAR_U32,
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
   111
	SLE_INT64       = SLE_FILE_I64 | SLE_VAR_I64,
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
   112
	SLE_UINT64      = SLE_FILE_U64 | SLE_VAR_U64,
3048
adf46229d390 (svn r3628) - Add BOOL and STRING types to saveload capabilities. String is unused up till now and it saves the full-buffer, regardless of how many characters the string actually has. So give a warning for that and figure it out later.
Darkvater
parents: 3046
diff changeset
   113
	SLE_CHAR        = SLE_FILE_I8  | SLE_VAR_CHAR,
3046
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
   114
	SLE_STRINGID    = SLE_FILE_STRINGID | SLE_VAR_U16,
3048
adf46229d390 (svn r3628) - Add BOOL and STRING types to saveload capabilities. String is unused up till now and it saves the full-buffer, regardless of how many characters the string actually has. So give a warning for that and figure it out later.
Darkvater
parents: 3046
diff changeset
   115
	SLE_STRINGBUF   = SLE_FILE_STRING   | SLE_VAR_STRB,
adf46229d390 (svn r3628) - Add BOOL and STRING types to saveload capabilities. String is unused up till now and it saves the full-buffer, regardless of how many characters the string actually has. So give a warning for that and figure it out later.
Darkvater
parents: 3046
diff changeset
   116
	SLE_STRINGQUOTE = SLE_FILE_STRING   | SLE_VAR_STRQ,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   117
3046
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
   118
	/* Shortcut values */
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
   119
	SLE_UINT = SLE_UINT32,
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
   120
	SLE_INT  = SLE_INT32,
3048
adf46229d390 (svn r3628) - Add BOOL and STRING types to saveload capabilities. String is unused up till now and it saves the full-buffer, regardless of how many characters the string actually has. So give a warning for that and figure it out later.
Darkvater
parents: 3046
diff changeset
   121
	SLE_STRB = SLE_STRINGBUF,
adf46229d390 (svn r3628) - Add BOOL and STRING types to saveload capabilities. String is unused up till now and it saves the full-buffer, regardless of how many characters the string actually has. So give a warning for that and figure it out later.
Darkvater
parents: 3046
diff changeset
   122
	SLE_STRQ = SLE_STRINGQUOTE,
3046
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
   123
};
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
   124
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
   125
typedef uint32 VarType;
1881
435d39bd6ee0 (svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents: 1217
diff changeset
   126
435d39bd6ee0 (svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents: 1217
diff changeset
   127
enum SaveLoadTypes {
435d39bd6ee0 (svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents: 1217
diff changeset
   128
	SL_VAR       = 0,
435d39bd6ee0 (svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents: 1217
diff changeset
   129
	SL_REF       = 1,
435d39bd6ee0 (svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents: 1217
diff changeset
   130
	SL_ARR       = 2,
3048
adf46229d390 (svn r3628) - Add BOOL and STRING types to saveload capabilities. String is unused up till now and it saves the full-buffer, regardless of how many characters the string actually has. So give a warning for that and figure it out later.
Darkvater
parents: 3046
diff changeset
   131
	SL_STR       = 3,
1881
435d39bd6ee0 (svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents: 1217
diff changeset
   132
	// non-normal save-load types
435d39bd6ee0 (svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents: 1217
diff changeset
   133
	SL_WRITEBYTE = 8,
435d39bd6ee0 (svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents: 1217
diff changeset
   134
	SL_INCLUDE   = 9,
435d39bd6ee0 (svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents: 1217
diff changeset
   135
	SL_END       = 15
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   136
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   137
3046
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
   138
typedef byte SaveLoadType;
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
   139
typedef uint16 OffSetType;
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
   140
1881
435d39bd6ee0 (svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents: 1217
diff changeset
   141
/** SaveLoad type struct. Do NOT use this directly but use the SLE_ macros defined just below! */
2295
95e8858e9938 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2285
diff changeset
   142
typedef struct SaveLoad {
3046
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
   143
	SaveLoadType cmd;     /// the action to take with the saved/loaded type, All types need different action
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
   144
	VarType conv;         /// type of the variable to be saved, int
1881
435d39bd6ee0 (svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents: 1217
diff changeset
   145
	uint16 length;        /// (conditional) length of the variable (eg. arrays) (max array size is 65536 elements)
435d39bd6ee0 (svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents: 1217
diff changeset
   146
	uint16 version_from;  /// save/load the variable starting from this savegame version
435d39bd6ee0 (svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents: 1217
diff changeset
   147
	uint16 version_to;    /// save/load the variable until this savegame version
3046
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
   148
	/* NOTE: This element either denotes the address of the variable for a global
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
   149
	 * variable, or the offset within a struct which is then bound to a variable
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
   150
	 * during runtime. Decision on which one to use is controlled by the function
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
   151
	 * that is called to save it. address: SlGlobList, offset: SlObject */
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
   152
	union {
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
   153
		void *address;      /// address of variable
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
   154
		OffSetType offset;  /// offset of variable in the struct (max offset is 65536)
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
   155
	} s;
2295
95e8858e9938 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2285
diff changeset
   156
} SaveLoad;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   157
3046
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
   158
/* Same as SaveLoad but global variables are used (for better readability); */
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
   159
typedef SaveLoad SaveLoadGlobVarList;
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
   160
1881
435d39bd6ee0 (svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents: 1217
diff changeset
   161
/* Simple variables, references (pointers) and arrays */
3050
a19b2a2827b2 (svn r3639) Silence warnings on gcc about {} initializers around unions
Darkvater
parents: 3048
diff changeset
   162
#define SLE_GENERAL(cmd, base, variable, type, length, from, to) {cmd, type, length, from, to, {(void*)offsetof(base, variable)}}
3044
fbaef2401476 (svn r3624) - CodeChange: Some cosmetic changes in the saveload code;
Darkvater
parents: 2848
diff changeset
   163
#define SLE_CONDVAR(base, variable, type, from, to) SLE_GENERAL(SL_VAR, base, variable, type, 0, from, to)
fbaef2401476 (svn r3624) - CodeChange: Some cosmetic changes in the saveload code;
Darkvater
parents: 2848
diff changeset
   164
#define SLE_CONDREF(base, variable, type, from, to) SLE_GENERAL(SL_REF, base, variable, type, 0, from, to)
fbaef2401476 (svn r3624) - CodeChange: Some cosmetic changes in the saveload code;
Darkvater
parents: 2848
diff changeset
   165
#define SLE_CONDARR(base, variable, type, length, from, to) SLE_GENERAL(SL_ARR, base, variable, type, length, from, to)
fbaef2401476 (svn r3624) - CodeChange: Some cosmetic changes in the saveload code;
Darkvater
parents: 2848
diff changeset
   166
#define SLE_CONDSTR(base, variable, type, length, from, to) SLE_GENERAL(SL_STR, base, variable, type, length, from, to)
fbaef2401476 (svn r3624) - CodeChange: Some cosmetic changes in the saveload code;
Darkvater
parents: 2848
diff changeset
   167
fbaef2401476 (svn r3624) - CodeChange: Some cosmetic changes in the saveload code;
Darkvater
parents: 2848
diff changeset
   168
#define SLE_VAR(base, variable, type) SLE_CONDVAR(base, variable, type, 0, SL_MAX_VERSION)
fbaef2401476 (svn r3624) - CodeChange: Some cosmetic changes in the saveload code;
Darkvater
parents: 2848
diff changeset
   169
#define SLE_REF(base, variable, type) SLE_CONDREF(base, variable, type, 0, SL_MAX_VERSION)
fbaef2401476 (svn r3624) - CodeChange: Some cosmetic changes in the saveload code;
Darkvater
parents: 2848
diff changeset
   170
#define SLE_ARR(base, variable, type, length) SLE_CONDARR(base, variable, type, length, 0, SL_MAX_VERSION)
fbaef2401476 (svn r3624) - CodeChange: Some cosmetic changes in the saveload code;
Darkvater
parents: 2848
diff changeset
   171
#define SLE_STR(base, variable, type, length) SLE_CONDSTR(base, variable, type, length, 0, SL_MAX_VERSION)
fbaef2401476 (svn r3624) - CodeChange: Some cosmetic changes in the saveload code;
Darkvater
parents: 2848
diff changeset
   172
1881
435d39bd6ee0 (svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents: 1217
diff changeset
   173
/* Translate values ingame to different values in the savegame and vv */
3044
fbaef2401476 (svn r3624) - CodeChange: Some cosmetic changes in the saveload code;
Darkvater
parents: 2848
diff changeset
   174
#define SLE_WRITEBYTE(base, variable, game_value, file_value) SLE_GENERAL(SL_WRITEBYTE, base, variable, 0, 0, game_value, file_value)
1881
435d39bd6ee0 (svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents: 1217
diff changeset
   175
/* Load common code and put it into each struct (currently only for vehicles */
3044
fbaef2401476 (svn r3624) - CodeChange: Some cosmetic changes in the saveload code;
Darkvater
parents: 2848
diff changeset
   176
#define SLE_INCLUDE(base, variable, include_index) SLE_GENERAL(SL_INCLUDE, base, variable, 0, 0, include_index, 0)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   177
1881
435d39bd6ee0 (svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents: 1217
diff changeset
   178
/* The same as the ones at the top, only the offset is given directly; used for unions */
3050
a19b2a2827b2 (svn r3639) Silence warnings on gcc about {} initializers around unions
Darkvater
parents: 3048
diff changeset
   179
#define SLE_GENERALX(cmd, offset, type, param1, param2) {cmd, type, 0, param1, param2, {(void*)(offset)}}
3044
fbaef2401476 (svn r3624) - CodeChange: Some cosmetic changes in the saveload code;
Darkvater
parents: 2848
diff changeset
   180
#define SLE_CONDVARX(offset, type, from, to) SLE_GENERALX(SL_VAR, offset, type, from, to)
fbaef2401476 (svn r3624) - CodeChange: Some cosmetic changes in the saveload code;
Darkvater
parents: 2848
diff changeset
   181
#define SLE_CONDREFX(offset, type, from, to) SLE_GENERALX(SL_REF, offset, type, from, to)
fbaef2401476 (svn r3624) - CodeChange: Some cosmetic changes in the saveload code;
Darkvater
parents: 2848
diff changeset
   182
fbaef2401476 (svn r3624) - CodeChange: Some cosmetic changes in the saveload code;
Darkvater
parents: 2848
diff changeset
   183
#define SLE_VARX(offset, type) SLE_CONDVARX(offset, type, 0, SL_MAX_VERSION)
fbaef2401476 (svn r3624) - CodeChange: Some cosmetic changes in the saveload code;
Darkvater
parents: 2848
diff changeset
   184
#define SLE_REFX(offset, type) SLE_CONDREFX(offset, type, 0, SL_MAX_VERSION)
fbaef2401476 (svn r3624) - CodeChange: Some cosmetic changes in the saveload code;
Darkvater
parents: 2848
diff changeset
   185
fbaef2401476 (svn r3624) - CodeChange: Some cosmetic changes in the saveload code;
Darkvater
parents: 2848
diff changeset
   186
#define SLE_WRITEBYTEX(offset, something) SLE_GENERALX(SL_WRITEBYTE, offset, 0, something, 0)
fbaef2401476 (svn r3624) - CodeChange: Some cosmetic changes in the saveload code;
Darkvater
parents: 2848
diff changeset
   187
#define SLE_INCLUDEX(offset, type) SLE_GENERALX(SL_INCLUDE, offset, type, 0, SL_MAX_VERSION)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   188
1881
435d39bd6ee0 (svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents: 1217
diff changeset
   189
/* End marker */
3050
a19b2a2827b2 (svn r3639) Silence warnings on gcc about {} initializers around unions
Darkvater
parents: 3048
diff changeset
   190
#define SLE_END() {SL_END, 0, 0, 0, 0, {(void*)0}}
3046
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
   191
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
   192
/* Simple variables, references (pointers) and arrays, but for global variables */
3050
a19b2a2827b2 (svn r3639) Silence warnings on gcc about {} initializers around unions
Darkvater
parents: 3048
diff changeset
   193
#define SLEG_GENERAL(cmd, variable, type, length, from, to) {cmd, type, length, from, to, {&variable}}
3046
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
   194
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
   195
#define SLEG_CONDVAR(variable, type, from, to) SLEG_GENERAL(SL_VAR, variable, type, 0, from, to)
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
   196
#define SLEG_CONDREF(variable, type, from, to) SLEG_GENERAL(SL_REF, variable, type, 0, from, to)
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
   197
#define SLEG_CONDARR(variable, type, length, from, to) SLEG_GENERAL(SL_ARR, variable, type, length, from, to)
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
   198
#define SLEG_CONDSTR(variable, type, length, from, to) SLEG_GENERAL(SL_STR, variable, type, length, from, to)
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
   199
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
   200
#define SLEG_VAR(variable, type) SLEG_CONDVAR(variable, type, 0, SL_MAX_VERSION)
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
   201
#define SLEG_REF(variable, type) SLEG_CONDREF(variable, type, 0, SL_MAX_VERSION)
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
   202
#define SLEG_ARR(variable, type) SLEG_CONDARR(variable, type, lengthof(variable), SL_MAX_VERSION)
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
   203
#define SLEG_STR(variable, type) SLEG_CONDSTR(variable, type, lengthof(variable), SL_MAX_VERSION)
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
   204
3050
a19b2a2827b2 (svn r3639) Silence warnings on gcc about {} initializers around unions
Darkvater
parents: 3048
diff changeset
   205
#define SLEG_END() {SL_END, 0, 0, 0, 0, {NULL}}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   206
2685
805a28b7c3b7 (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2380
diff changeset
   207
/** Checks if the savegame is below major.minor.
805a28b7c3b7 (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2380
diff changeset
   208
 */
805a28b7c3b7 (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2380
diff changeset
   209
static inline bool CheckSavegameVersionOldStyle(uint16 major, byte minor)
805a28b7c3b7 (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2380
diff changeset
   210
{
3045
0364fedfd355 (svn r3625) - Move sl_version inside the functions where they are used to force usage.
Darkvater
parents: 3044
diff changeset
   211
	extern uint16 _sl_version;
0364fedfd355 (svn r3625) - Move sl_version inside the functions where they are used to force usage.
Darkvater
parents: 3044
diff changeset
   212
	extern byte   _sl_minor_version;
2685
805a28b7c3b7 (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2380
diff changeset
   213
	return (_sl_version < major) || (_sl_version == major && _sl_minor_version < minor);
805a28b7c3b7 (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2380
diff changeset
   214
}
805a28b7c3b7 (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2380
diff changeset
   215
805a28b7c3b7 (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2380
diff changeset
   216
/** Checks if the savegame is below version.
805a28b7c3b7 (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2380
diff changeset
   217
 */
805a28b7c3b7 (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2380
diff changeset
   218
static inline bool CheckSavegameVersion(uint16 version)
805a28b7c3b7 (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2380
diff changeset
   219
{
3045
0364fedfd355 (svn r3625) - Move sl_version inside the functions where they are used to force usage.
Darkvater
parents: 3044
diff changeset
   220
	extern uint16 _sl_version;
2685
805a28b7c3b7 (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2380
diff changeset
   221
	return _sl_version < version;
805a28b7c3b7 (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2380
diff changeset
   222
}
805a28b7c3b7 (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2380
diff changeset
   223
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   224
void SlSetArrayIndex(uint index);
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1024
diff changeset
   225
int SlIterateArray(void);
3046
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
   226
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   227
void SlAutolength(AutolengthProc *proc, void *arg);
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1024
diff changeset
   228
uint SlGetFieldLength(void);
1881
435d39bd6ee0 (svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents: 1217
diff changeset
   229
void SlSetLength(size_t length);
3046
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
   230
size_t SlCalcObjMemberLength(const SaveLoad *sld);
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
   231
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
   232
byte SlReadByte(void);
1881
435d39bd6ee0 (svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents: 1217
diff changeset
   233
void SlWriteByte(byte b);
3046
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
   234
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
   235
void SlGlobList(const SaveLoadGlobVarList *sldg);
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
   236
void SlArray(void *array, uint length, VarType conv);
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
   237
void SlObject(void *object, const SaveLoad *sld);
baa216f9911a (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3045
diff changeset
   238
bool SlObjectMember(void *object, const SaveLoad *sld);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   239
2380
392bba57462d (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2337
diff changeset
   240
void SaveFileStart(void);
392bba57462d (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2337
diff changeset
   241
void SaveFileDone(void);
392bba57462d (svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Darkvater
parents: 2337
diff changeset
   242
void SaveFileError(void);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   243
#endif /* SAVELOAD_H */