src/saveload.h
branchcpp_gui
changeset 6298 c30fe89622df
parent 5922 510e1bbc5992
child 6307 f40e88cff863
equal deleted inserted replaced
6297:4bf29d14edba 6298:c30fe89622df
     7 #undef SIZE_MAX
     7 #undef SIZE_MAX
     8 #endif
     8 #endif
     9 
     9 
    10 #define SIZE_MAX ((size_t)-1)
    10 #define SIZE_MAX ((size_t)-1)
    11 
    11 
    12 typedef enum SaveOrLoadResult {
    12 enum SaveOrLoadResult {
    13 	SL_OK     = 0, // completed successfully
    13 	SL_OK     = 0, // completed successfully
    14 	SL_ERROR  = 1, // error that was caught before internal structures were modified
    14 	SL_ERROR  = 1, // error that was caught before internal structures were modified
    15 	SL_REINIT = 2, // error that was caught in the middle of updating game state, need to clear it. (can only happen during load)
    15 	SL_REINIT = 2, // error that was caught in the middle of updating game state, need to clear it. (can only happen during load)
    16 } SaveOrLoadResult;
    16 };
    17 
    17 
    18 typedef enum SaveOrLoadMode {
    18 enum SaveOrLoadMode {
    19 	SL_INVALID  = -1,
    19 	SL_INVALID  = -1,
    20 	SL_LOAD     =  0,
    20 	SL_LOAD     =  0,
    21 	SL_SAVE     =  1,
    21 	SL_SAVE     =  1,
    22 	SL_OLD_LOAD =  2,
    22 	SL_OLD_LOAD =  2,
    23 	SL_PNG      =  3,
    23 	SL_PNG      =  3,
    24 	SL_BMP      =  4,
    24 	SL_BMP      =  4,
    25 } SaveOrLoadMode;
    25 };
    26 
    26 
    27 SaveOrLoadResult SaveOrLoad(const char *filename, int mode);
    27 SaveOrLoadResult SaveOrLoad(const char *filename, int mode);
    28 void WaitTillSaved(void);
    28 void WaitTillSaved();
    29 void DoExitSave(void);
    29 void DoExitSave();
    30 
    30 
    31 
    31 
    32 typedef void ChunkSaveLoadProc(void);
    32 typedef void ChunkSaveLoadProc();
    33 typedef void AutolengthProc(void *arg);
    33 typedef void AutolengthProc(void *arg);
    34 
    34 
    35 typedef struct {
    35 struct ChunkHandler {
    36 	uint32 id;
    36 	uint32 id;
    37 	ChunkSaveLoadProc *save_proc;
    37 	ChunkSaveLoadProc *save_proc;
    38 	ChunkSaveLoadProc *load_proc;
    38 	ChunkSaveLoadProc *load_proc;
    39 	uint32 flags;
    39 	uint32 flags;
    40 } ChunkHandler;
    40 };
    41 
    41 
    42 typedef struct {
    42 struct NullStruct {
    43 	byte null;
    43 	byte null;
    44 } NullStruct;
    44 };
    45 
    45 
    46 typedef enum SLRefType {
    46 enum SLRefType {
    47 	REF_ORDER         = 0,
    47 	REF_ORDER         = 0,
    48 	REF_VEHICLE       = 1,
    48 	REF_VEHICLE       = 1,
    49 	REF_STATION       = 2,
    49 	REF_STATION       = 2,
    50 	REF_TOWN          = 3,
    50 	REF_TOWN          = 3,
    51 	REF_VEHICLE_OLD   = 4,
    51 	REF_VEHICLE_OLD   = 4,
    52 	REF_ROADSTOPS     = 5,
    52 	REF_ROADSTOPS     = 5,
    53 	REF_ENGINE_RENEWS = 6,
    53 	REF_ENGINE_RENEWS = 6,
    54 } SLRefType;
    54 };
    55 
    55 
    56 #define SL_MAX_VERSION 255
    56 #define SL_MAX_VERSION 255
    57 
    57 
    58 enum {
    58 enum {
    59 	INC_VEHICLE_COMMON = 0,
    59 	INC_VEHICLE_COMMON = 0,
   164 };
   164 };
   165 
   165 
   166 typedef byte SaveLoadType;
   166 typedef byte SaveLoadType;
   167 
   167 
   168 /** SaveLoad type struct. Do NOT use this directly but use the SLE_ macros defined just below! */
   168 /** SaveLoad type struct. Do NOT use this directly but use the SLE_ macros defined just below! */
   169 typedef struct SaveLoad {
   169 struct SaveLoad {
   170 	SaveLoadType cmd;    ///< the action to take with the saved/loaded type, All types need different action
   170 	SaveLoadType cmd;    ///< the action to take with the saved/loaded type, All types need different action
   171 	VarType conv;        ///< type of the variable to be saved, int
   171 	VarType conv;        ///< type of the variable to be saved, int
   172 	uint16 length;       ///< (conditional) length of the variable (eg. arrays) (max array size is 65536 elements)
   172 	uint16 length;       ///< (conditional) length of the variable (eg. arrays) (max array size is 65536 elements)
   173 	uint16 version_from; ///< save/load the variable starting from this savegame version
   173 	uint16 version_from; ///< save/load the variable starting from this savegame version
   174 	uint16 version_to;   ///< save/load the variable until this savegame version
   174 	uint16 version_to;   ///< save/load the variable until this savegame version
   175 	/* NOTE: This element either denotes the address of the variable for a global
   175 	/* NOTE: This element either denotes the address of the variable for a global
   176 	 * variable, or the offset within a struct which is then bound to a variable
   176 	 * variable, or the offset within a struct which is then bound to a variable
   177 	 * during runtime. Decision on which one to use is controlled by the function
   177 	 * during runtime. Decision on which one to use is controlled by the function
   178 	 * that is called to save it. address: SlGlobList, offset: SlObject */
   178 	 * that is called to save it. address: SlGlobList, offset: SlObject */
   179 	void *address;       ///< address of variable OR offset of variable in the struct (max offset is 65536)
   179 	void *address;       ///< address of variable OR offset of variable in the struct (max offset is 65536)
   180 } SaveLoad;
   180 };
   181 
   181 
   182 /* Same as SaveLoad but global variables are used (for better readability); */
   182 /* Same as SaveLoad but global variables are used (for better readability); */
   183 typedef SaveLoad SaveLoadGlobVarList;
   183 typedef SaveLoad SaveLoadGlobVarList;
   184 
   184 
   185 /* Simple variables, references (pointers) and arrays */
   185 /* Simple variables, references (pointers) and arrays */
   288 
   288 
   289 int64 ReadValue(const void *ptr, VarType conv);
   289 int64 ReadValue(const void *ptr, VarType conv);
   290 void WriteValue(void *ptr, VarType conv, int64 val);
   290 void WriteValue(void *ptr, VarType conv, int64 val);
   291 
   291 
   292 void SlSetArrayIndex(uint index);
   292 void SlSetArrayIndex(uint index);
   293 int SlIterateArray(void);
   293 int SlIterateArray();
   294 
   294 
   295 void SlAutolength(AutolengthProc *proc, void *arg);
   295 void SlAutolength(AutolengthProc *proc, void *arg);
   296 uint SlGetFieldLength(void);
   296 uint SlGetFieldLength();
   297 void SlSetLength(size_t length);
   297 void SlSetLength(size_t length);
   298 size_t SlCalcObjMemberLength(const void *object, const SaveLoad *sld);
   298 size_t SlCalcObjMemberLength(const void *object, const SaveLoad *sld);
   299 
   299 
   300 byte SlReadByte(void);
   300 byte SlReadByte();
   301 void SlWriteByte(byte b);
   301 void SlWriteByte(byte b);
   302 
   302 
   303 void SlGlobList(const SaveLoadGlobVarList *sldg);
   303 void SlGlobList(const SaveLoadGlobVarList *sldg);
   304 void SlArray(void *array, uint length, VarType conv);
   304 void SlArray(void *array, uint length, VarType conv);
   305 void SlObject(void *object, const SaveLoad *sld);
   305 void SlObject(void *object, const SaveLoad *sld);
   306 bool SlObjectMember(void *object, const SaveLoad *sld);
   306 bool SlObjectMember(void *object, const SaveLoad *sld);
   307 
   307 
   308 void SaveFileStart(void);
   308 void SaveFileStart();
   309 void SaveFileDone(void);
   309 void SaveFileDone();
   310 void SaveFileError(void);
   310 void SaveFileError();
   311 #endif /* SAVELOAD_H */
   311 #endif /* SAVELOAD_H */