equal
deleted
inserted
replaced
23 #include "station.h" |
23 #include "station.h" |
24 #include "thread.h" |
24 #include "thread.h" |
25 #include "town.h" |
25 #include "town.h" |
26 #include "player.h" |
26 #include "player.h" |
27 #include "saveload.h" |
27 #include "saveload.h" |
|
28 #include "network.h" |
28 #include "variables.h" |
29 #include "variables.h" |
29 #include <setjmp.h> |
30 #include <setjmp.h> |
30 |
31 |
31 enum { |
32 const uint16 SAVEGAME_VERSION = 21; |
32 SAVEGAME_VERSION = 21, |
|
33 |
|
34 }; |
|
35 |
|
36 uint16 _sl_version; /// the major savegame version identifier |
33 uint16 _sl_version; /// the major savegame version identifier |
37 byte _sl_minor_version; /// the minor savegame version, DO NOT USE! |
34 byte _sl_minor_version; /// the minor savegame version, DO NOT USE! |
38 |
35 |
39 typedef void WriterProc(uint len); |
36 typedef void WriterProc(uint len); |
40 typedef uint ReaderProc(void); |
37 typedef uint ReaderProc(void); |
379 } else { |
376 } else { |
380 for (; length != 0; length--) {*p++ = SlReadByteInternal();} |
377 for (; length != 0; length--) {*p++ = SlReadByteInternal();} |
381 } |
378 } |
382 } |
379 } |
383 |
380 |
384 #if 0 |
381 /** Read in bytes from the file/data structure but don't do |
385 /** |
382 * anything with them, discarding them in effect |
386 * Read in bytes from the file/data structure but don't do |
|
387 * anything with them |
|
388 * NOTICE: currently unused |
|
389 * @param length The amount of bytes that is being treated this way |
383 * @param length The amount of bytes that is being treated this way |
390 */ |
384 */ |
391 static inline void SlSkipBytes(size_t length) |
385 static inline void SlSkipBytes(size_t length) |
392 { |
386 { |
393 for (; length != 0; length--) |
387 for (; length != 0; length--) SlReadByte(); |
394 SlReadByte(); |
388 } |
395 } |
|
396 #endif |
|
397 |
389 |
398 /* Get the length of the current object */ |
390 /* Get the length of the current object */ |
399 uint SlGetFieldLength(void) {return _sl.obj_len;} |
391 uint SlGetFieldLength(void) {return _sl.obj_len;} |
400 |
392 |
401 /** Return a signed-long version of the value of a setting |
393 /** Return a signed-long version of the value of a setting |
568 |
560 |
569 /* Are we going to save this object or not? */ |
561 /* Are we going to save this object or not? */ |
570 static inline bool SlIsObjectValidInSavegame(const SaveLoad *sld) |
562 static inline bool SlIsObjectValidInSavegame(const SaveLoad *sld) |
571 { |
563 { |
572 if (_sl_version < sld->version_from || _sl_version > sld->version_to) return false; |
564 if (_sl_version < sld->version_from || _sl_version > sld->version_to) return false; |
|
565 if (sld->conv & SLF_SAVE_NO) return false; |
573 |
566 |
574 return true; |
567 return true; |
|
568 } |
|
569 |
|
570 /** Are we going to load this variable when loading a savegame or not? |
|
571 * @note If the variable is skipped it is skipped in the savegame |
|
572 * bytestream itself as well, so there is no need to skip it somewhere else */ |
|
573 static inline bool SlSkipVariableOnLoad(const SaveLoad *sld) |
|
574 { |
|
575 if ((sld->conv & SLF_NETWORK_NO) && !_sl.save && _networking && !_network_server) { |
|
576 SlSkipBytes(SlCalcConvMemLen(sld->conv) * sld->length); |
|
577 return true; |
|
578 } |
|
579 |
|
580 return false; |
575 } |
581 } |
576 |
582 |
577 /** |
583 /** |
578 * Calculate the size of an object. |
584 * Calculate the size of an object. |
579 * @param sld The @SaveLoad description of the object so we know how to manipulate it |
585 * @param sld The @SaveLoad description of the object so we know how to manipulate it |
624 case SL_REF: |
630 case SL_REF: |
625 case SL_ARR: |
631 case SL_ARR: |
626 case SL_STR: |
632 case SL_STR: |
627 /* CONDITIONAL saveload types depend on the savegame version */ |
633 /* CONDITIONAL saveload types depend on the savegame version */ |
628 if (!SlIsObjectValidInSavegame(sld)) return false; |
634 if (!SlIsObjectValidInSavegame(sld)) return false; |
|
635 if (SlSkipVariableOnLoad(sld)) return false; |
629 |
636 |
630 switch (sld->cmd) { |
637 switch (sld->cmd) { |
631 case SL_VAR: SlSaveLoadConv(ptr, conv); break; |
638 case SL_VAR: SlSaveLoadConv(ptr, conv); break; |
632 case SL_REF: /* Reference variable, translate */ |
639 case SL_REF: /* Reference variable, translate */ |
633 /// @todo XXX - another artificial limitof 65K elements of pointers? |
640 /// @todo XXX - another artificial limitof 65K elements of pointers? |