170 |
171 |
171 typedef byte SaveLoadType; |
172 typedef byte SaveLoadType; |
172 |
173 |
173 /** SaveLoad type struct. Do NOT use this directly but use the SLE_ macros defined just below! */ |
174 /** SaveLoad type struct. Do NOT use this directly but use the SLE_ macros defined just below! */ |
174 struct SaveLoad { |
175 struct SaveLoad { |
|
176 bool global; ///< should we load a global variable or a non-global one |
175 SaveLoadType cmd; ///< the action to take with the saved/loaded type, All types need different action |
177 SaveLoadType cmd; ///< the action to take with the saved/loaded type, All types need different action |
176 VarType conv; ///< type of the variable to be saved, int |
178 VarType conv; ///< type of the variable to be saved, int |
177 uint16 length; ///< (conditional) length of the variable (eg. arrays) (max array size is 65536 elements) |
179 uint16 length; ///< (conditional) length of the variable (eg. arrays) (max array size is 65536 elements) |
178 uint16 version_from; ///< save/load the variable starting from this savegame version |
180 uint16 version_from; ///< save/load the variable starting from this savegame version |
179 uint16 version_to; ///< save/load the variable until this savegame version |
181 uint16 version_to; ///< save/load the variable until this savegame version |
180 /* NOTE: This element either denotes the address of the variable for a global |
182 /* NOTE: This element either denotes the address of the variable for a global |
181 * variable, or the offset within a struct which is then bound to a variable |
183 * variable, or the offset within a struct which is then bound to a variable |
182 * during runtime. Decision on which one to use is controlled by the function |
184 * during runtime. Decision on which one to use is controlled by the function |
183 * that is called to save it. address: SlGlobList, offset: SlObject */ |
185 * that is called to save it. address: global=true, offset: global=false */ |
184 void *address; ///< address of variable OR offset of variable in the struct (max offset is 65536) |
186 void *address; ///< address of variable OR offset of variable in the struct (max offset is 65536) |
185 }; |
187 }; |
186 |
188 |
187 /* Same as SaveLoad but global variables are used (for better readability); */ |
189 /* Same as SaveLoad but global variables are used (for better readability); */ |
188 typedef SaveLoad SaveLoadGlobVarList; |
190 typedef SaveLoad SaveLoadGlobVarList; |
189 |
191 |
190 /* Simple variables, references (pointers) and arrays */ |
192 /* Simple variables, references (pointers) and arrays */ |
191 #define SLE_GENERAL(cmd, base, variable, type, length, from, to) {cmd, type, length, from, to, (void*)cpp_offsetof(base, variable)} |
193 #define SLE_GENERAL(cmd, base, variable, type, length, from, to) {false, cmd, type, length, from, to, (void*)cpp_offsetof(base, variable)} |
192 #define SLE_CONDVAR(base, variable, type, from, to) SLE_GENERAL(SL_VAR, base, variable, type, 0, from, to) |
194 #define SLE_CONDVAR(base, variable, type, from, to) SLE_GENERAL(SL_VAR, base, variable, type, 0, from, to) |
193 #define SLE_CONDREF(base, variable, type, from, to) SLE_GENERAL(SL_REF, base, variable, type, 0, from, to) |
195 #define SLE_CONDREF(base, variable, type, from, to) SLE_GENERAL(SL_REF, base, variable, type, 0, from, to) |
194 #define SLE_CONDARR(base, variable, type, length, from, to) SLE_GENERAL(SL_ARR, base, variable, type, length, from, to) |
196 #define SLE_CONDARR(base, variable, type, length, from, to) SLE_GENERAL(SL_ARR, base, variable, type, length, from, to) |
195 #define SLE_CONDSTR(base, variable, type, length, from, to) SLE_GENERAL(SL_STR, base, variable, type, length, from, to) |
197 #define SLE_CONDSTR(base, variable, type, length, from, to) SLE_GENERAL(SL_STR, base, variable, type, length, from, to) |
196 #define SLE_CONDLST(base, variable, type, from, to) SLE_GENERAL(SL_LST, base, variable, type, 0, from, to) |
198 #define SLE_CONDLST(base, variable, type, from, to) SLE_GENERAL(SL_LST, base, variable, type, 0, from, to) |
207 #define SLE_WRITEBYTE(base, variable, value) SLE_GENERAL(SL_WRITEBYTE, base, variable, 0, 0, value, value) |
209 #define SLE_WRITEBYTE(base, variable, value) SLE_GENERAL(SL_WRITEBYTE, base, variable, 0, 0, value, value) |
208 /* Load common code and put it into each struct (currently only for vehicles */ |
210 /* Load common code and put it into each struct (currently only for vehicles */ |
209 #define SLE_INCLUDE(base, variable, include_index) SLE_GENERAL(SL_INCLUDE, base, variable, 0, 0, include_index, 0) |
211 #define SLE_INCLUDE(base, variable, include_index) SLE_GENERAL(SL_INCLUDE, base, variable, 0, 0, include_index, 0) |
210 |
212 |
211 /* The same as the ones at the top, only the offset is given directly; used for unions */ |
213 /* The same as the ones at the top, only the offset is given directly; used for unions */ |
212 #define SLE_GENERALX(cmd, offset, type, param1, param2) {cmd, type, 0, param1, param2, (void*)(offset)} |
214 #define SLE_GENERALX(cmd, offset, type, param1, param2) {false, cmd, type, 0, param1, param2, (void*)(offset)} |
213 #define SLE_CONDVARX(offset, type, from, to) SLE_GENERALX(SL_VAR, offset, type, from, to) |
215 #define SLE_CONDVARX(offset, type, from, to) SLE_GENERALX(SL_VAR, offset, type, from, to) |
214 #define SLE_CONDREFX(offset, type, from, to) SLE_GENERALX(SL_REF, offset, type, from, to) |
216 #define SLE_CONDREFX(offset, type, from, to) SLE_GENERALX(SL_REF, offset, type, from, to) |
215 |
217 |
216 #define SLE_VARX(offset, type) SLE_CONDVARX(offset, type, 0, SL_MAX_VERSION) |
218 #define SLE_VARX(offset, type) SLE_CONDVARX(offset, type, 0, SL_MAX_VERSION) |
217 #define SLE_REFX(offset, type) SLE_CONDREFX(offset, type, 0, SL_MAX_VERSION) |
219 #define SLE_REFX(offset, type) SLE_CONDREFX(offset, type, 0, SL_MAX_VERSION) |
218 |
220 |
219 #define SLE_WRITEBYTEX(offset, something) SLE_GENERALX(SL_WRITEBYTE, offset, 0, something, 0) |
221 #define SLE_WRITEBYTEX(offset, something) SLE_GENERALX(SL_WRITEBYTE, offset, 0, something, 0) |
220 #define SLE_INCLUDEX(offset, type) SLE_GENERALX(SL_INCLUDE, offset, type, 0, SL_MAX_VERSION) |
222 #define SLE_INCLUDEX(offset, type) SLE_GENERALX(SL_INCLUDE, offset, type, 0, SL_MAX_VERSION) |
221 |
223 |
222 /* End marker */ |
224 /* End marker */ |
223 #define SLE_END() {SL_END, 0, 0, 0, 0, NULL} |
225 #define SLE_END() {false, SL_END, 0, 0, 0, 0, NULL} |
224 |
226 |
225 /* Simple variables, references (pointers) and arrays, but for global variables */ |
227 /* Simple variables, references (pointers) and arrays, but for global variables */ |
226 #define SLEG_GENERAL(cmd, variable, type, length, from, to) {cmd, type, length, from, to, (void*)&variable} |
228 #define SLEG_GENERAL(cmd, variable, type, length, from, to) {true, cmd, type, length, from, to, (void*)&variable} |
227 |
229 |
228 #define SLEG_CONDVAR(variable, type, from, to) SLEG_GENERAL(SL_VAR, variable, type, 0, from, to) |
230 #define SLEG_CONDVAR(variable, type, from, to) SLEG_GENERAL(SL_VAR, variable, type, 0, from, to) |
229 #define SLEG_CONDREF(variable, type, from, to) SLEG_GENERAL(SL_REF, variable, type, 0, from, to) |
231 #define SLEG_CONDREF(variable, type, from, to) SLEG_GENERAL(SL_REF, variable, type, 0, from, to) |
230 #define SLEG_CONDARR(variable, type, length, from, to) SLEG_GENERAL(SL_ARR, variable, type, length, from, to) |
232 #define SLEG_CONDARR(variable, type, length, from, to) SLEG_GENERAL(SL_ARR, variable, type, length, from, to) |
231 #define SLEG_CONDSTR(variable, type, length, from, to) SLEG_GENERAL(SL_STR, variable, type, length, from, to) |
233 #define SLEG_CONDSTR(variable, type, length, from, to) SLEG_GENERAL(SL_STR, variable, type, length, from, to) |
235 #define SLEG_REF(variable, type) SLEG_CONDREF(variable, type, 0, SL_MAX_VERSION) |
237 #define SLEG_REF(variable, type) SLEG_CONDREF(variable, type, 0, SL_MAX_VERSION) |
236 #define SLEG_ARR(variable, type) SLEG_CONDARR(variable, type, lengthof(variable), 0, SL_MAX_VERSION) |
238 #define SLEG_ARR(variable, type) SLEG_CONDARR(variable, type, lengthof(variable), 0, SL_MAX_VERSION) |
237 #define SLEG_STR(variable, type) SLEG_CONDSTR(variable, type, lengthof(variable), 0, SL_MAX_VERSION) |
239 #define SLEG_STR(variable, type) SLEG_CONDSTR(variable, type, lengthof(variable), 0, SL_MAX_VERSION) |
238 #define SLEG_LST(variable, type) SLEG_CONDLST(variable, type, 0, SL_MAX_VERSION) |
240 #define SLEG_LST(variable, type) SLEG_CONDLST(variable, type, 0, SL_MAX_VERSION) |
239 |
241 |
240 #define SLEG_CONDNULL(length, from, to) {SL_ARR, SLE_FILE_U8 | SLE_VAR_NULL | SLF_CONFIG_NO, length, from, to, (void*)NULL} |
242 #define SLEG_CONDNULL(length, from, to) {true, SL_ARR, SLE_FILE_U8 | SLE_VAR_NULL | SLF_CONFIG_NO, length, from, to, (void*)NULL} |
241 |
243 |
242 #define SLEG_END() {SL_END, 0, 0, 0, 0, NULL} |
244 #define SLEG_END() {true, SL_END, 0, 0, 0, 0, NULL} |
243 |
245 |
244 /** Checks if the savegame is below major.minor. |
246 /** Checks if the savegame is below major.minor. |
245 */ |
247 */ |
246 static inline bool CheckSavegameVersionOldStyle(uint16 major, byte minor) |
248 static inline bool CheckSavegameVersionOldStyle(uint16 major, byte minor) |
247 { |
249 { |