saveload.h
author matthijs
Wed, 22 Mar 2006 22:26:16 +0000
branch0.4.5
changeset 9958 bed516c67d61
parent 2848 cb4b1cc0bf65
child 3044 631d21c289e2
permissions -rw-r--r--
(svn r4041) [Debian] Change next version number to 0.4.6 instead of 0.4.5.1.
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2162
diff changeset
     1
/* $Id$ */
461a2aff3486 (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
c1ded3bd3d0c (svn r2672) Move saving/loading related declarations to saveload.h
tron
parents: 1887
diff changeset
     6
typedef enum SaveOrLoadResult {
c1ded3bd3d0c (svn r2672) Move saving/loading related declarations to saveload.h
tron
parents: 1887
diff changeset
     7
	SL_OK = 0, // completed successfully
c1ded3bd3d0c (svn r2672) Move saving/loading related declarations to saveload.h
tron
parents: 1887
diff changeset
     8
	SL_ERROR = 1, // error that was caught before internal structures were modified
c1ded3bd3d0c (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)
c1ded3bd3d0c (svn r2672) Move saving/loading related declarations to saveload.h
tron
parents: 1887
diff changeset
    10
} SaveOrLoadResult;
c1ded3bd3d0c (svn r2672) Move saving/loading related declarations to saveload.h
tron
parents: 1887
diff changeset
    11
c1ded3bd3d0c (svn r2672) Move saving/loading related declarations to saveload.h
tron
parents: 1887
diff changeset
    12
typedef enum SaveOrLoadMode {
c1ded3bd3d0c (svn r2672) Move saving/loading related declarations to saveload.h
tron
parents: 1887
diff changeset
    13
	SL_INVALID = -1,
c1ded3bd3d0c (svn r2672) Move saving/loading related declarations to saveload.h
tron
parents: 1887
diff changeset
    14
	SL_LOAD = 0,
c1ded3bd3d0c (svn r2672) Move saving/loading related declarations to saveload.h
tron
parents: 1887
diff changeset
    15
	SL_SAVE = 1,
c1ded3bd3d0c (svn r2672) Move saving/loading related declarations to saveload.h
tron
parents: 1887
diff changeset
    16
	SL_OLD_LOAD = 2,
c1ded3bd3d0c (svn r2672) Move saving/loading related declarations to saveload.h
tron
parents: 1887
diff changeset
    17
} SaveOrLoadMode;
c1ded3bd3d0c (svn r2672) Move saving/loading related declarations to saveload.h
tron
parents: 1887
diff changeset
    18
c1ded3bd3d0c (svn r2672) Move saving/loading related declarations to saveload.h
tron
parents: 1887
diff changeset
    19
SaveOrLoadResult SaveOrLoad(const char *filename, int mode);
2285
3193cbd1ba88 (svn r2809) Implement more generic threading functions, which allow more than one thread
tron
parents: 2186
diff changeset
    20
void WaitTillSaved(void);
2162
c1ded3bd3d0c (svn r2672) Move saving/loading related declarations to saveload.h
tron
parents: 1887
diff changeset
    21
c1ded3bd3d0c (svn r2672) Move saving/loading related declarations to saveload.h
tron
parents: 1887
diff changeset
    22
1093
e8d26c7dc42f (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 SaveLoadGlobVarList {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    27
	void *address;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    28
	byte conv;
2685
00111d5ca47f (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2380
diff changeset
    29
	uint16 from_version;
00111d5ca47f (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2380
diff changeset
    30
	uint16 to_version;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    31
} SaveLoadGlobVarList;
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
	uint32 id;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    35
	ChunkSaveLoadProc *save_proc;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    36
	ChunkSaveLoadProc *load_proc;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    37
	uint32 flags;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    38
} ChunkHandler;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    39
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    40
typedef struct {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    41
	byte null;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    42
} NullStruct;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    43
1881
023a134a4b12 (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
    44
typedef enum SLRefType {
1024
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 956
diff changeset
    45
	REF_ORDER       = 0,
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 956
diff changeset
    46
	REF_VEHICLE     = 1,
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 956
diff changeset
    47
	REF_STATION     = 2,
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 956
diff changeset
    48
	REF_TOWN        = 3,
1217
ab9f02a224ab (svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents: 1093
diff changeset
    49
	REF_VEHICLE_OLD = 4,
2848
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2685
diff changeset
    50
	REF_ROADSTOPS   = 5,
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2685
diff changeset
    51
	REF_ENGINE_RENEWS = 6,
1881
023a134a4b12 (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
    52
} SLRefType;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    53
1881
023a134a4b12 (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
    54
2685
00111d5ca47f (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2380
diff changeset
    55
extern uint16 _sl_version;       /// the major savegame version identifier
00111d5ca47f (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2380
diff changeset
    56
extern byte   _sl_minor_version; /// the minor savegame version, DO NOT USE!
1881
023a134a4b12 (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
    57
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    58
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    59
enum {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    60
	INC_VEHICLE_COMMON = 0,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    61
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    62
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    63
enum {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    64
	CH_RIFF = 0,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    65
	CH_ARRAY = 1,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    66
	CH_SPARSE_ARRAY = 2,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    67
	CH_TYPE_MASK = 3,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    68
	CH_LAST = 8,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    69
	CH_AUTO_LENGTH = 16,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    70
	CH_PRI_0 = 0 << 4,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    71
	CH_PRI_1 = 1 << 4,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    72
	CH_PRI_2 = 2 << 4,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    73
	CH_PRI_3 = 3 << 4,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    74
	CH_PRI_SHL = 4,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    75
	CH_NUM_PRI_LEVELS = 4,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    76
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    77
1881
023a134a4b12 (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
    78
typedef enum VarTypes {
023a134a4b12 (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
    79
	SLE_FILE_I8  = 0,
023a134a4b12 (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
    80
	SLE_FILE_U8  = 1,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    81
	SLE_FILE_I16 = 2,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    82
	SLE_FILE_U16 = 3,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    83
	SLE_FILE_I32 = 4,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    84
	SLE_FILE_U32 = 5,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    85
	SLE_FILE_I64 = 6,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    86
	SLE_FILE_U64 = 7,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    87
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    88
	SLE_FILE_STRINGID = 8,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    89
//	SLE_FILE_IVAR = 8,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    90
//	SLE_FILE_UVAR = 9,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    91
1881
023a134a4b12 (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
    92
	SLE_VAR_I8   = 0 << 4,
023a134a4b12 (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
    93
	SLE_VAR_U8   = 1 << 4,
023a134a4b12 (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
    94
	SLE_VAR_I16  = 2 << 4,
023a134a4b12 (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
    95
	SLE_VAR_U16  = 3 << 4,
023a134a4b12 (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
    96
	SLE_VAR_I32  = 4 << 4,
023a134a4b12 (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
    97
	SLE_VAR_U32  = 5 << 4,
023a134a4b12 (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
    98
	SLE_VAR_I64  = 6 << 4,
023a134a4b12 (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
    99
	SLE_VAR_U64  = 7 << 4,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   100
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   101
	SLE_VAR_NULL = 8 << 4, // useful to write zeros in savegame.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   102
1881
023a134a4b12 (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
   103
	SLE_VAR_INT  = SLE_VAR_I32,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   104
	SLE_VAR_UINT = SLE_VAR_U32,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   105
1881
023a134a4b12 (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
   106
	SLE_INT8   = SLE_FILE_I8  | SLE_VAR_I8,
023a134a4b12 (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
   107
	SLE_UINT8  = SLE_FILE_U8  | SLE_VAR_U8,
023a134a4b12 (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
   108
	SLE_INT16  = SLE_FILE_I16 | SLE_VAR_I16,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   109
	SLE_UINT16 = SLE_FILE_U16 | SLE_VAR_U16,
1881
023a134a4b12 (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
   110
	SLE_INT32  = SLE_FILE_I32 | SLE_VAR_I32,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   111
	SLE_UINT32 = SLE_FILE_U32 | SLE_VAR_U32,
1881
023a134a4b12 (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
   112
	SLE_INT64  = SLE_FILE_I64 | SLE_VAR_I64,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   113
	SLE_UINT64 = SLE_FILE_U64 | SLE_VAR_U64,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   114
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   115
	SLE_STRINGID = SLE_FILE_STRINGID | SLE_VAR_U16,
1881
023a134a4b12 (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
   116
} VarType;
023a134a4b12 (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
   117
023a134a4b12 (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
   118
enum SaveLoadTypes {
023a134a4b12 (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
   119
	SL_VAR       = 0,
023a134a4b12 (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
   120
	SL_REF       = 1,
023a134a4b12 (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
   121
	SL_ARR       = 2,
023a134a4b12 (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
   122
	SL_CONDVAR   = 0 | (1 << 2), // 4
023a134a4b12 (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
   123
	SL_CONDREF   = 1 | (1 << 2), // 5
023a134a4b12 (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
   124
	SL_CONDARR   = 2 | (1 << 2), // 6
023a134a4b12 (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
   125
	// non-normal save-load types
023a134a4b12 (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
	SL_WRITEBYTE = 8,
023a134a4b12 (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
	SL_INCLUDE   = 9,
023a134a4b12 (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_END       = 15
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   129
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   130
1881
023a134a4b12 (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
   131
/** SaveLoad type struct. Do NOT use this directly but use the SLE_ macros defined just below! */
2295
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2285
diff changeset
   132
typedef struct SaveLoad {
1881
023a134a4b12 (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
	byte cmd;             /// the action to take with the saved/loaded type, All types need different action
023a134a4b12 (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
	VarType type;         /// type of the variable to be saved, int
023a134a4b12 (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
	uint16 offset;        /// offset of this variable in the struct (max offset is 65536)
023a134a4b12 (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
   136
	uint16 length;        /// (conditional) length of the variable (eg. arrays) (max array size is 65536 elements)
023a134a4b12 (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
   137
	uint16 version_from;  /// save/load the variable starting from this savegame version
023a134a4b12 (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
   138
	uint16 version_to;    /// save/load the variable until this savegame version
2295
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2285
diff changeset
   139
} SaveLoad;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   140
1881
023a134a4b12 (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
/* Simple variables, references (pointers) and arrays */
023a134a4b12 (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
   142
#define SLE_VAR(base, variable, type) {SL_VAR, type, offsetof(base, variable), 0, 0, 0}
023a134a4b12 (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
   143
#define SLE_REF(base, variable, type) {SL_REF, type, offsetof(base, variable), 0, 0, 0}
023a134a4b12 (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
   144
#define SLE_ARR(base, variable, type, length) {SL_ARR, type, offsetof(base, variable), length, 0, 0}
023a134a4b12 (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
/* Conditional variables, references (pointers) and arrays that are only valid for certain savegame versions */
023a134a4b12 (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
#define SLE_CONDVAR(base, variable, type, from, to) {SL_CONDVAR, type, offsetof(base, variable), 0, from, to}
023a134a4b12 (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
#define SLE_CONDREF(base, variable, type, from, to) {SL_CONDREF, type, offsetof(base, variable), 0, from, to}
023a134a4b12 (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
   148
#define SLE_CONDARR(base, variable, type, length, from, to) {SL_CONDARR, type, offsetof(base, variable), length, from, to}
023a134a4b12 (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
   149
/* Translate values ingame to different values in the savegame and vv */
023a134a4b12 (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
   150
#define SLE_WRITEBYTE(base, variable, game_value, file_value) {SL_WRITEBYTE, 0, offsetof(base, variable), 0, game_value, file_value}
023a134a4b12 (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
   151
/* Load common code and put it into each struct (currently only for vehicles */
023a134a4b12 (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
   152
#define SLE_INCLUDE(base, variable, include_index) {SL_INCLUDE, 0, offsetof(base, variable), 0, include_index, 0}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   153
1881
023a134a4b12 (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
   154
/* The same as the ones at the top, only the offset is given directly; used for unions */
023a134a4b12 (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
   155
#define SLE_VARX(offset, type) {SL_VAR, type, offset, 0, 0, 0}
023a134a4b12 (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
   156
#define SLE_REFX(offset, type) {SL_REF, type, offset, 0, 0, 0}
023a134a4b12 (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
   157
#define SLE_CONDVARX(offset, type, from, to) {SL_CONDVAR, type, offset, 0, from, to}
023a134a4b12 (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
   158
#define SLE_CONDREFX(offset, type, from, to) {SL_CONDREF, type, offset, 0, from, to}
023a134a4b12 (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
   159
#define SLE_WRITEBYTEX(offset, something) {SL_WRITEBYTE, 0, offset, 0, something, 0}
023a134a4b12 (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
   160
#define SLE_INCLUDEX(offset, type) {SL_INCLUDE, type, offset, 0, 0, 0}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   161
1881
023a134a4b12 (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
   162
/* End marker */
023a134a4b12 (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
   163
#define SLE_END() {SL_END, 0, 0, 0, 0, 0}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   164
2685
00111d5ca47f (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2380
diff changeset
   165
/** Checks if the savegame is below major.minor.
00111d5ca47f (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2380
diff changeset
   166
 */
00111d5ca47f (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2380
diff changeset
   167
static inline bool CheckSavegameVersionOldStyle(uint16 major, byte minor)
00111d5ca47f (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2380
diff changeset
   168
{
00111d5ca47f (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2380
diff changeset
   169
	return (_sl_version < major) || (_sl_version == major && _sl_minor_version < minor);
00111d5ca47f (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2380
diff changeset
   170
}
00111d5ca47f (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2380
diff changeset
   171
00111d5ca47f (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2380
diff changeset
   172
/** Checks if the savegame is below version.
00111d5ca47f (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2380
diff changeset
   173
 */
00111d5ca47f (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2380
diff changeset
   174
static inline bool CheckSavegameVersion(uint16 version)
00111d5ca47f (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2380
diff changeset
   175
{
00111d5ca47f (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2380
diff changeset
   176
	return _sl_version < version;
00111d5ca47f (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2380
diff changeset
   177
}
00111d5ca47f (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2380
diff changeset
   178
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   179
void SlSetArrayIndex(uint index);
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1024
diff changeset
   180
int SlIterateArray(void);
1887
9f1af4f412d4 (svn r2393) - Implemented threaded saving for OS/2
orudge
parents: 1881
diff changeset
   181
void SlArray(void *array, uint length, VarType conv);
1881
023a134a4b12 (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
   182
void SlObject(void *object, const SaveLoad *desc);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   183
void SlAutolength(AutolengthProc *proc, void *arg);
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1024
diff changeset
   184
uint SlGetFieldLength(void);
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1024
diff changeset
   185
int SlReadByte(void);
1881
023a134a4b12 (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
   186
void SlSetLength(size_t length);
023a134a4b12 (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
   187
void SlWriteByte(byte b);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   188
void SlGlobList(const SaveLoadGlobVarList *desc);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   189
2380
3b26659b4a9a (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
   190
void SaveFileStart(void);
3b26659b4a9a (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
   191
void SaveFileDone(void);
3b26659b4a9a (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
   192
void SaveFileError(void);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   193
#endif /* SAVELOAD_H */