1 //---------------------------------------------------------------------------- 2 // EDGE New SaveGame Handling (Main defs) 3 //---------------------------------------------------------------------------- 4 // 5 // Copyright (c) 1999-2009 The EDGE Team. 6 // 7 // This program is free software; you can redistribute it and/or 8 // modify it under the terms of the GNU General Public License 9 // as published by the Free Software Foundation; either version 2 10 // of the License, or (at your option) any later version. 11 // 12 // This program is distributed in the hope that it will be useful, 13 // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 // GNU General Public License for more details. 16 // 17 //---------------------------------------------------------------------------- 18 // 19 // Based on the DOOM source code, released by Id Software under the 20 // following copyright: 21 // 22 // Copyright (C) 1993-1996 by id Software, Inc. 23 // 24 //---------------------------------------------------------------------------- 25 // 26 // TERMINOLOGY: 27 // 28 // - "known" here means an array/structure that is currently built 29 // into EDGE. 30 // 31 // - "loaded" here means an array/structure definition that has been 32 // loaded from the savegame file. 33 // 34 35 #ifndef __SV_MAIN_H__ 36 #define __SV_MAIN_H__ 37 38 #include "i_defs.h" 39 40 #include "dm_defs.h" 41 #include "e_player.h" 42 #include "p_local.h" 43 44 class image_c; 45 class mapdef_c; 46 47 // 48 // STRUCTURE TABLE STUFF 49 // 50 51 typedef enum 52 { 53 SFKIND_Invalid = 0, // invalid values can be helpful 54 SFKIND_Numeric, 55 SFKIND_Index, 56 SFKIND_String, 57 SFKIND_Struct 58 } 59 savefieldkind_e; 60 61 typedef struct 62 { 63 // basic kind of field (for SDEF chunk) 64 savefieldkind_e kind; 65 66 // number of bytes for SFKIND_Numeric (1, 2, 4 or 8) 67 int size; 68 69 // name of structure for SFKIND_Struct, or name of array 70 // for SFKIND_Index. 71 const char *name; 72 } 73 savefieldtype_t; 74 75 #define SVT_INVALID { SFKIND_Invalid, 0, NULL } 76 77 #define SVT_INT { SFKIND_Numeric, 4, NULL } 78 #define SVT_SHORT { SFKIND_Numeric, 2, NULL } 79 #define SVT_BYTE { SFKIND_Numeric, 1, NULL } 80 #define SVT_FLOAT { SFKIND_Numeric, 4, NULL } 81 #define SVT_VEC2 { SFKIND_Numeric, 8, NULL } 82 #define SVT_VEC3 { SFKIND_Numeric, 12,NULL } 83 #define SVT_INDEX(name) { SFKIND_Index, 4, name } 84 #define SVT_STRING { SFKIND_String, 0, NULL } 85 #define SVT_STRUCT(name) { SFKIND_Struct, 0, name } 86 87 #define SVT_ANGLE SVT_INT 88 #define SVT_BOOLEAN SVT_INT 89 #define SVT_ENUM SVT_INT 90 #define SVT_RGBCOL SVT_INT 91 #define SVT_PERCENT SVT_FLOAT 92 93 94 // This describes a single field 95 typedef struct savefieldtype_s 96 { 97 // offset of field in structure (actually a ptr into dummy struct) 98 const char *offset_p; 99 100 // name of field in savegame system 101 const char *field_name; 102 103 // number of sequential elements 104 int count; 105 106 // field type information 107 savefieldtype_t type; 108 109 // get & put routines. The extra parameter depends on the type, for 110 // SFKIND_Struct it is the name of the structure, for SFKIND_Index 111 // it is the name of the array. When `field_put' is NULL, then this 112 // field is not saved into the output SDEF chunk. 113 bool (* field_get)(void *storage, int index, void *extra); 114 void (* field_put)(void *storage, int index, void *extra); 115 116 // for loaded info, this points to the known version of the field, 117 // otherwise NULL if the loaded field is unknown. 118 struct savefieldtype_s *known_field; 119 } 120 savefield_t; 121 122 // NOTE: requires SV_F_BASE to be defined as the dummy struct 123 124 #define SVFIELD(field,fname,fnum,ftype,getter,putter) \ 125 { (const char *) & SV_F_BASE.field, \ 126 fname, fnum, ftype, getter, putter, NULL } 127 128 #define SVFIELD_END { 0, NULL, 0, SVT_INVALID, NULL, NULL, NULL } 129 130 #define SVDUMMY ((const char *) & SV_F_BASE) 131 132 133 // This describes a single structure 134 typedef struct savestruct_s 135 { 136 // link in list of structure definitions 137 struct savestruct_s *next; 138 139 // structure name (for SDEF/ADEF chunks) 140 const char *struct_name; 141 142 // four letter marker 143 const char *marker; 144 145 // array of field definitions 146 savefield_t *fields; 147 148 // address of dummy struct (used to compute field offsets) 149 const char *dummy_base; 150 151 // this must be true to put the definition into the savegame file. 152 // Allows compatibility structures that are read-only. 153 bool define_me; 154 155 // only used when loading. For loaded info, this refers to the 156 // known struct of the same name (or NULL if none). For known info, 157 // this points to the loaded info (or NULL if absent). 158 struct savestruct_s *counterpart; 159 } 160 savestruct_t; 161 162 163 // This describes a single array 164 typedef struct savearray_s 165 { 166 // link in list of array definitions 167 struct savearray_s *next; 168 169 // array name (for ADEF and STOR chunks) 170 const char *array_name; 171 172 // array type. For loaded info, this points to the loaded 173 // structure. Never NULL. 174 savestruct_t *sdef; 175 176 // this must be true to put the definition into the savegame file. 177 // Allows compatibility arrays that are read-only. 178 bool define_me; 179 180 // load this array even when loading in HUB mode. There are 181 // some things we _don't_ want to load when going back to a 182 // visited level: players and active_hubs in particular. 183 bool allow_hub; 184 185 // array routines. Not used for loaded info. 186 int (* count_elems)(void); 187 void * (* get_elem)(int index); 188 void (* create_elems)(int num_elems); 189 void (* finalise_elems)(void); 190 191 // only used when loading. For loaded info, this refers to the 192 // known array (or NULL if none). For known info, this points to 193 // the loaded info (or NULL if absent). 194 struct savearray_s *counterpart; 195 196 // number of elements to be loaded. 197 int loaded_size; 198 } 199 savearray_t; 200 201 202 // 203 // COMMON GET ROUTINES 204 // 205 // Note the `SR_' prefix. 206 // 207 bool SR_GetByte(void *storage, int index, void *extra); 208 bool SR_GetShort(void *storage, int index, void *extra); 209 bool SR_GetInt(void *storage, int index, void *extra); 210 211 bool SR_GetAngle(void *storage, int index, void *extra); 212 bool SR_GetFloat(void *storage, int index, void *extra); 213 bool SR_GetBoolean(void *storage, int index, void *extra); 214 215 bool SR_GetVec2(void *storage, int index, void *extra); 216 bool SR_GetVec3(void *storage, int index, void *extra); 217 bool SR_GetFloatFromInt(void *storage, int index, void *extra); 218 bool SR_GetAngleFromSlope(void *storage, int index, void *extra); 219 220 #define SR_GetEnum SR_GetInt 221 #define SR_GetRGB SR_GetInt 222 #define SR_GetPercent SR_GetFloat 223 224 225 // 226 // COMMON PUT ROUTINES 227 // 228 // Note the `SR_' prefix. 229 // 230 void SR_PutByte(void *storage, int index, void *extra); 231 void SR_PutShort(void *storage, int index, void *extra); 232 void SR_PutInt(void *storage, int index, void *extra); 233 234 void SR_PutAngle(void *storage, int index, void *extra); 235 void SR_PutFloat(void *storage, int index, void *extra); 236 void SR_PutBoolean(void *storage, int index, void *extra); 237 238 void SR_PutVec2(void *storage, int index, void *extra); 239 void SR_PutVec3(void *storage, int index, void *extra); 240 void SR_PutAngleToSlope(void *storage, int index, void *extra); 241 242 #define SR_PutEnum SR_PutInt 243 #define SR_PutRGB SR_PutInt 244 #define SR_PutPercent SR_PutFloat 245 246 247 // 248 // GLOBAL STUFF 249 // 250 251 typedef struct crc_check_s 252 { 253 // number of items 254 int count; 255 256 // CRC computed over all the items 257 u32_t crc; 258 } 259 crc_check_t; 260 261 // this structure contains everything for the top-level [GLOB] chunk. 262 // Strings are copies and need to be freed. 263 typedef struct 264 { 265 // [IVAR] stuff: 266 267 const char *game; 268 const char *level; 269 gameflags_t flags; 270 int hub_tag; 271 const char *hub_first; 272 273 int level_time; 274 int exit_time; 275 int p_random; 276 int total_kills; 277 int total_items; 278 int total_secrets; 279 280 int console_player; 281 int skill; 282 int netgame; 283 284 const image_c *sky_image; // -AJA- added 2003/12/19 285 286 const char *description; 287 const char *desc_date; 288 289 crc_check_t mapsector; 290 crc_check_t mapline; 291 crc_check_t mapthing; 292 293 crc_check_t rscript; 294 crc_check_t ddfatk; 295 crc_check_t ddfgame; 296 crc_check_t ddflevl; 297 crc_check_t ddfline; 298 crc_check_t ddfsect; 299 crc_check_t ddfmobj; 300 crc_check_t ddfweap; 301 302 // [VIEW] info. Unused if view_pixels is NULL. 303 unsigned short *view_pixels; 304 int view_width; 305 int view_height; 306 307 // [WADS] info 308 int wad_num; 309 const char ** wad_names; 310 311 // [PLYR] info, for DEMO FILES only! 312 void *players[MAXPLAYERS]; 313 } 314 saveglobals_t; 315 316 saveglobals_t *SV_NewGLOB(void); 317 saveglobals_t *SV_LoadGLOB(void); 318 void SV_SaveGLOB(saveglobals_t *globs); 319 void SV_FreeGLOB(saveglobals_t *globs); 320 321 322 // 323 // ADMININISTRATION 324 // 325 326 void SV_MainInit(void); 327 328 savestruct_t *SV_MainLookupStruct(const char *name); 329 savearray_t *SV_MainLookupArray(const char *name); 330 331 void SV_BeginLoad(bool is_hub); 332 void SV_FinishLoad(void); 333 334 bool SV_LoadStruct(void *base, savestruct_t *info); 335 bool SV_LoadEverything(void); 336 337 void SV_BeginSave(void); 338 void SV_FinishSave(void); 339 340 void SV_SaveStruct(void *base, savestruct_t *info); 341 void SV_SaveEverything(void); 342 343 const char *SV_SlotName(int slot); 344 const char *SV_MapName(const mapdef_c *map); 345 346 std::string SV_FileName(const char *slot_name, const char *map_name); 347 348 void SV_ClearSlot(const char *slot_name); 349 void SV_CopySlot(const char *src_name, const char *dest_name); 350 351 352 // 353 // DEBUGGING 354 // 355 356 void SV_DumpSaveGame(int slot); 357 358 359 // 360 // EXTERNAL DEFS 361 // 362 363 extern void *sv_current_elem; 364 365 extern savestruct_t *sv_known_structs; 366 extern savearray_t *sv_known_arrays; 367 368 bool SR_MobjGetMobj(void *storage, int index, void *extra); 369 void SR_MobjPutMobj(void *storage, int index, void *extra); 370 371 int SV_MobjFindElem(mobj_t *elem); 372 void * SV_MobjGetElem(int index); 373 374 int SV_PlayerFindElem(player_t *elem); 375 void * SV_PlayerGetElem(int index); 376 377 bool SR_LevelGetImage(void *storage, int index, void *extra); 378 void SR_LevelPutImage(void *storage, int index, void *extra); 379 380 bool SR_LevelGetColmap(void *storage, int index, void *extra); 381 void SR_LevelPutColmap(void *storage, int index, void *extra); 382 383 bool SR_LineGetLine(void *storage, int index, void *extra); 384 void SR_LinePutLine(void *storage, int index, void *extra); 385 386 bool SR_SectorGetSector(void *storage, int index, void *extra); 387 void SR_SectorPutSector(void *storage, int index, void *extra); 388 389 bool SR_SectorGetEF(void *storage, int index, void *extra); 390 void SR_SectorPutEF(void *storage, int index, void *extra); 391 392 bool SR_TriggerGetScript(void *storage, int index, void *extra); 393 void SR_TriggerPutScript(void *storage, int index, void *extra); 394 395 396 #endif /*__SV_MAIN_H__*/ 397 398 //--- editor settings --- 399 // vi:ts=4:sw=4:noexpandtab 400