equal
deleted
inserted
replaced
50 |
50 |
51 WriterProc *write_bytes; ///< savegame writer function |
51 WriterProc *write_bytes; ///< savegame writer function |
52 ReaderProc *read_bytes; ///< savegame loader function |
52 ReaderProc *read_bytes; ///< savegame loader function |
53 |
53 |
54 const ChunkHandler* const *chs; ///< the chunk of data that is being processed atm (vehicles, signs, etc.) |
54 const ChunkHandler* const *chs; ///< the chunk of data that is being processed atm (vehicles, signs, etc.) |
55 const SaveLoad* const *includes; ///< the internal layouf of the given chunk |
|
56 |
55 |
57 /* When saving/loading savegames, they are always saved to a temporary memory-place |
56 /* When saving/loading savegames, they are always saved to a temporary memory-place |
58 * to be flushed to file (save) or to final place (load) when full. */ |
57 * to be flushed to file (save) or to final place (load) when full. */ |
59 byte *bufp, *bufe; ///< bufp(ointer) gives the current position in the buffer bufe(nd) gives the end of the buffer |
58 byte *bufp, *bufe; ///< bufp(ointer) gives the current position in the buffer bufe(nd) gives the end of the buffer |
60 |
59 |
753 case SL_LST: return SlCalcListLen(GetVariableAddress(object, sld)); |
752 case SL_LST: return SlCalcListLen(GetVariableAddress(object, sld)); |
754 default: NOT_REACHED(); |
753 default: NOT_REACHED(); |
755 } |
754 } |
756 break; |
755 break; |
757 case SL_WRITEBYTE: return 1; // a byte is logically of size 1 |
756 case SL_WRITEBYTE: return 1; // a byte is logically of size 1 |
758 case SL_INCLUDE: return SlCalcObjLength(object, _sl.includes[sld->version_from]); |
757 case SL_VEH_INCLUDE: return SlCalcObjLength(object, GetVehicleDescription(VEH_END)); |
759 default: NOT_REACHED(); |
758 default: NOT_REACHED(); |
760 } |
759 } |
761 return 0; |
760 return 0; |
762 } |
761 } |
763 |
762 |
802 } else { |
801 } else { |
803 *(byte*)ptr = sld->version_from; |
802 *(byte*)ptr = sld->version_from; |
804 } |
803 } |
805 break; |
804 break; |
806 |
805 |
807 /* SL_INCLUDE loads common code for a type |
806 /* SL_VEH_INCLUDE loads common code for vehicles */ |
808 * XXX - variable renaming abuse |
807 case SL_VEH_INCLUDE: |
809 * include_index: common code to include from _desc_includes[], abused by sld->version_from */ |
808 SlObject(ptr, GetVehicleDescription(VEH_END)); |
810 case SL_INCLUDE: |
|
811 SlObject(ptr, _sl.includes[sld->version_from]); |
|
812 break; |
809 break; |
813 default: NOT_REACHED(); |
810 default: NOT_REACHED(); |
814 } |
811 } |
815 return true; |
812 return true; |
816 } |
813 } |
1279 _group_chunk_handlers, |
1276 _group_chunk_handlers, |
1280 _cargopacket_chunk_handlers, |
1277 _cargopacket_chunk_handlers, |
1281 NULL, |
1278 NULL, |
1282 }; |
1279 }; |
1283 |
1280 |
1284 /* used to include a vehicle desc in another desc. */ |
|
1285 extern const SaveLoad _common_veh_desc[]; |
|
1286 static const SaveLoad* const _desc_includes[] = { |
|
1287 _common_veh_desc |
|
1288 }; |
|
1289 |
|
1290 /** |
1281 /** |
1291 * Pointers cannot be saved to a savegame, so this functions gets |
1282 * Pointers cannot be saved to a savegame, so this functions gets |
1292 * the index of the item, and if not available, it hussles with |
1283 * the index of the item, and if not available, it hussles with |
1293 * pointers (looks really bad :() |
1284 * pointers (looks really bad :() |
1294 * Remember that a NULL item has value 0, and all |
1285 * Remember that a NULL item has value 0, and all |
1626 } |
1617 } |
1627 |
1618 |
1628 _sl.bufe = _sl.bufp = NULL; |
1619 _sl.bufe = _sl.bufp = NULL; |
1629 _sl.offs_base = 0; |
1620 _sl.offs_base = 0; |
1630 _sl.save = (mode != 0); |
1621 _sl.save = (mode != 0); |
1631 _sl.includes = _desc_includes; |
|
1632 _sl.chs = _chunk_handlers; |
1622 _sl.chs = _chunk_handlers; |
1633 |
1623 |
1634 /* General tactic is to first save the game to memory, then use an available writer |
1624 /* General tactic is to first save the game to memory, then use an available writer |
1635 * to write it to file, either in threaded mode if possible, or single-threaded */ |
1625 * to write it to file, either in threaded mode if possible, or single-threaded */ |
1636 if (mode == SL_SAVE) { /* SAVE game */ |
1626 if (mode == SL_SAVE) { /* SAVE game */ |