Replace remaining uses of std::deque with ring buffers

Cargo packet lists and associated save/load
pull/590/head
Jonathan G Rennison 10 months ago
parent b59a8dc21c
commit 23ad010d70

@ -19,7 +19,7 @@
#include "company_type.h"
#include "core/multimap.hpp"
#include "sl/saveload_common.h"
#include <deque>
#include "core/ring_buffer.hpp"
/** Unique identifier for a single cargo packet. */
typedef uint32 CargoPacketID;
@ -296,7 +296,7 @@ public:
void InvalidateCache();
};
typedef std::deque<CargoPacket *> CargoPacketList;
typedef ring_buffer<CargoPacket *> CargoPacketList;
/**
* CargoList that is used for vehicles.

@ -34,9 +34,9 @@
#include "../town.h"
#include "../roadstop_base.h"
#include "../autoreplace_base.h"
#include "../core/ring_buffer.hpp"
#include <atomic>
#include <deque>
#include <vector>
#include <string>
#include <map>
@ -303,14 +303,14 @@ static uint8 GetSavegameFileType(const SaveLoad &sld)
case SL_STDSTR:
case SL_ARR:
case SL_VECTOR:
case SL_DEQUE:
case SL_RING:
return GetVarFileType(sld.conv) | SLE_FILE_HAS_LENGTH_FIELD; break;
case SL_REF:
return IsSavegameVersionBefore(SLV_69) ? SLE_FILE_U16 : SLE_FILE_U32;
case SL_REFLIST:
case SL_REFDEQUE:
case SL_REFRING:
case SL_REFVEC:
return (IsSavegameVersionBefore(SLV_69) ? SLE_FILE_U16 : SLE_FILE_U32) | SLE_FILE_HAS_LENGTH_FIELD;
@ -1071,9 +1071,9 @@ void SlSaveLoadRef(void *ptr, VarType conv)
/**
* Template class to help with list-like types.
*/
template <template<typename, typename> typename Tstorage, typename Tvar, typename Tallocator = std::allocator<Tvar>>
template <template<typename> typename Tstorage, typename Tvar>
class SlStorageHelper {
typedef Tstorage<Tvar, Tallocator> SlStorageT;
typedef Tstorage<Tvar> SlStorageT;
public:
/**
* Internal templated helper to return the size in bytes of a list-like type.
@ -1166,18 +1166,18 @@ static inline size_t SlCalcRefListLen(const void *list, VarType conv)
}
/**
* Return the size in bytes of a deque.
* @param list The std::list to find the size of.
* Return the size in bytes of a ring buffer.
* @param list The ring buffer to find the size of.
* @param conv VarType type of variable that is used for calculating the size.
*/
static inline size_t SlCalcRefDequeLen(const void *list, VarType conv)
static inline size_t SlCalcRefRingLen(const void *list, VarType conv)
{
return SlStorageHelper<std::deque, void *>::SlCalcLen(list, conv, SL_REF);
return SlStorageHelper<ring_buffer, void *>::SlCalcLen(list, conv, SL_REF);
}
/**
* Return the size in bytes of a vector.
* @param list The std::list to find the size of.
* @param list The std::vector to find the size of.
* @param conv VarType type of variable that is used for calculating the size.
*/
static inline size_t SlCalcRefVectorLen(const void *list, VarType conv)
@ -1203,24 +1203,24 @@ static void SlRefList(void *list, VarType conv)
}
/**
* Save/Load a deque.
* Save/Load a ring buffer.
* @param list The list being manipulated.
* @param conv VarType type of variable that is used for calculating the size.
*/
static void SlRefDeque(void *list, VarType conv)
static void SlRefRing(void *list, VarType conv)
{
/* Automatically calculate the length? */
if (_sl.need_length != NL_NONE) {
SlSetLength(SlCalcRefDequeLen(list, conv));
SlSetLength(SlCalcRefRingLen(list, conv));
/* Determine length only? */
if (_sl.need_length == NL_CALCLENGTH) return;
}
SlStorageHelper<std::deque, void *>::SlSaveLoad(list, conv, SL_REF);
SlStorageHelper<ring_buffer, void *>::SlSaveLoad(list, conv, SL_REF);
}
/**
* Save/Load a deque.
* Save/Load a vector.
* @param list The list being manipulated.
* @param conv VarType type of variable that is used for calculating the size.
*/
@ -1237,43 +1237,43 @@ static void SlRefVector(void *list, VarType conv)
}
/**
* Return the size in bytes of a std::deque.
* @param deque The std::deque to find the size of
* Return the size in bytes of a ring buffer.
* @param ring The ring buffer to find the size of
* @param conv VarType type of variable that is used for calculating the size
*/
static inline size_t SlCalcDequeLen(const void *deque, VarType conv)
static inline size_t SlCalcRingLen(const void *ring, VarType conv)
{
switch (GetVarMemType(conv)) {
case SLE_VAR_BL: return SlStorageHelper<std::deque, bool>::SlCalcLen(deque, conv);
case SLE_VAR_I8: return SlStorageHelper<std::deque, int8>::SlCalcLen(deque, conv);
case SLE_VAR_U8: return SlStorageHelper<std::deque, uint8>::SlCalcLen(deque, conv);
case SLE_VAR_I16: return SlStorageHelper<std::deque, int16>::SlCalcLen(deque, conv);
case SLE_VAR_U16: return SlStorageHelper<std::deque, uint16>::SlCalcLen(deque, conv);
case SLE_VAR_I32: return SlStorageHelper<std::deque, int32>::SlCalcLen(deque, conv);
case SLE_VAR_U32: return SlStorageHelper<std::deque, uint32>::SlCalcLen(deque, conv);
case SLE_VAR_I64: return SlStorageHelper<std::deque, int64>::SlCalcLen(deque, conv);
case SLE_VAR_U64: return SlStorageHelper<std::deque, uint64>::SlCalcLen(deque, conv);
case SLE_VAR_BL: return SlStorageHelper<ring_buffer, bool>::SlCalcLen(ring, conv);
case SLE_VAR_I8: return SlStorageHelper<ring_buffer, int8>::SlCalcLen(ring, conv);
case SLE_VAR_U8: return SlStorageHelper<ring_buffer, uint8>::SlCalcLen(ring, conv);
case SLE_VAR_I16: return SlStorageHelper<ring_buffer, int16>::SlCalcLen(ring, conv);
case SLE_VAR_U16: return SlStorageHelper<ring_buffer, uint16>::SlCalcLen(ring, conv);
case SLE_VAR_I32: return SlStorageHelper<ring_buffer, int32>::SlCalcLen(ring, conv);
case SLE_VAR_U32: return SlStorageHelper<ring_buffer, uint32>::SlCalcLen(ring, conv);
case SLE_VAR_I64: return SlStorageHelper<ring_buffer, int64>::SlCalcLen(ring, conv);
case SLE_VAR_U64: return SlStorageHelper<ring_buffer, uint64>::SlCalcLen(ring, conv);
default: NOT_REACHED();
}
}
/**
* Save/load a std::deque.
* @param deque The std::deque being manipulated
* Save/load a ring buffer.
* @param ring The ring buffer being manipulated
* @param conv VarType type of variable that is used for calculating the size
*/
static void SlDeque(void *deque, VarType conv)
static void SlRing(void *ring, VarType conv)
{
switch (GetVarMemType(conv)) {
case SLE_VAR_BL: SlStorageHelper<std::deque, bool>::SlSaveLoad(deque, conv); break;
case SLE_VAR_I8: SlStorageHelper<std::deque, int8>::SlSaveLoad(deque, conv); break;
case SLE_VAR_U8: SlStorageHelper<std::deque, uint8>::SlSaveLoad(deque, conv); break;
case SLE_VAR_I16: SlStorageHelper<std::deque, int16>::SlSaveLoad(deque, conv); break;
case SLE_VAR_U16: SlStorageHelper<std::deque, uint16>::SlSaveLoad(deque, conv); break;
case SLE_VAR_I32: SlStorageHelper<std::deque, int32>::SlSaveLoad(deque, conv); break;
case SLE_VAR_U32: SlStorageHelper<std::deque, uint32>::SlSaveLoad(deque, conv); break;
case SLE_VAR_I64: SlStorageHelper<std::deque, int64>::SlSaveLoad(deque, conv); break;
case SLE_VAR_U64: SlStorageHelper<std::deque, uint64>::SlSaveLoad(deque, conv); break;
case SLE_VAR_BL: SlStorageHelper<ring_buffer, bool>::SlSaveLoad(ring, conv); break;
case SLE_VAR_I8: SlStorageHelper<ring_buffer, int8>::SlSaveLoad(ring, conv); break;
case SLE_VAR_U8: SlStorageHelper<ring_buffer, uint8>::SlSaveLoad(ring, conv); break;
case SLE_VAR_I16: SlStorageHelper<ring_buffer, int16>::SlSaveLoad(ring, conv); break;
case SLE_VAR_U16: SlStorageHelper<ring_buffer, uint16>::SlSaveLoad(ring, conv); break;
case SLE_VAR_I32: SlStorageHelper<ring_buffer, int32>::SlSaveLoad(ring, conv); break;
case SLE_VAR_U32: SlStorageHelper<ring_buffer, uint32>::SlSaveLoad(ring, conv); break;
case SLE_VAR_I64: SlStorageHelper<ring_buffer, int64>::SlSaveLoad(ring, conv); break;
case SLE_VAR_U64: SlStorageHelper<ring_buffer, uint64>::SlSaveLoad(ring, conv); break;
default: NOT_REACHED();
}
}
@ -1383,9 +1383,9 @@ size_t SlCalcObjMemberLength(const void *object, const SaveLoad &sld)
case SL_ARR: return SlCalcArrayLen(sld.length, sld.conv);
case SL_STR: return SlCalcStringLen(GetVariableAddress(object, sld), sld.length, sld.conv);
case SL_REFLIST: return SlCalcRefListLen(GetVariableAddress(object, sld), sld.conv);
case SL_REFDEQUE: return SlCalcRefDequeLen(GetVariableAddress(object, sld), sld.conv);
case SL_REFRING: return SlCalcRefRingLen(GetVariableAddress(object, sld), sld.conv);
case SL_REFVEC: return SlCalcRefVectorLen(GetVariableAddress(object, sld), sld.conv);
case SL_DEQUE: return SlCalcDequeLen(GetVariableAddress(object, sld), sld.conv);
case SL_RING: return SlCalcRingLen(GetVariableAddress(object, sld), sld.conv);
case SL_VECTOR: return SlCalcVectorLen(GetVariableAddress(object, sld), sld.conv);
case SL_STDSTR: return SlCalcStdStringLen(GetVariableAddress(object, sld));
case SL_SAVEBYTE: return 1; // a byte is logically of size 1
@ -1481,9 +1481,9 @@ static bool SlObjectMember(void *object, const SaveLoad &sld)
case SL_ARR:
case SL_STR:
case SL_REFLIST:
case SL_REFDEQUE:
case SL_REFRING:
case SL_REFVEC:
case SL_DEQUE:
case SL_RING:
case SL_VECTOR:
case SL_STDSTR: {
void *ptr = GetVariableAddress(object, sld);
@ -1494,9 +1494,9 @@ static bool SlObjectMember(void *object, const SaveLoad &sld)
case SL_ARR: SlArray(ptr, sld.length, conv); break;
case SL_STR: SlString(ptr, sld.length, sld.conv); break;
case SL_REFLIST: SlRefList(ptr, conv); break;
case SL_REFDEQUE: SlRefDeque(ptr, conv); break;
case SL_REFRING: SlRefRing(ptr, conv); break;
case SL_REFVEC: SlRefVector(ptr, conv); break;
case SL_DEQUE: SlDeque(ptr, conv); break;
case SL_RING: SlRing(ptr, conv); break;
case SL_VECTOR: SlVector(ptr, conv); break;
case SL_STDSTR: SlStdString(ptr, sld.conv); break;
default: NOT_REACHED();

@ -273,7 +273,7 @@ enum SaveLoadType : byte {
SL_STDSTR = 4, ///< Save/load a \c std::string.
SL_ARR = 5, ///< Save/load a fixed-size array of #SL_VAR elements.
SL_DEQUE = 6, ///< Save/load a deque of #SL_VAR elements.
SL_RING = 6, ///< Save/load a ring of #SL_VAR elements.
SL_VECTOR = 7, ///< Save/load a vector of #SL_VAR elements.
SL_REFLIST = 8, ///< Save/load a list of #SL_REF elements.
SL_STRUCTLIST = 9, ///< Save/load a list of structs.
@ -281,7 +281,7 @@ enum SaveLoadType : byte {
SL_SAVEBYTE = 10, ///< Save (but not load) a byte.
SL_NULL = 11, ///< Save null-bytes and load to nowhere.
SL_REFDEQUE, ///< Save/load a deque of #SL_REF elements.
SL_REFRING, ///< Save/load a ring of #SL_REF elements.
SL_REFVEC, ///< Save/load a vector of #SL_REF elements.
};
@ -417,14 +417,14 @@ struct SaveLoadCompat {
#define SLE_CONDREFLIST(base, variable, type, from, to) SLE_GENERAL(SL_REFLIST, base, variable, type, 0, from, to, 0)
/**
* Storage of a deque of #SL_REF elements in some savegame versions.
* Storage of a ring of #SL_REF elements in some savegame versions.
* @param base Name of the class or struct containing the list.
* @param variable Name of the variable in the class or struct referenced by \a base.
* @param type Storage of the data in memory and in the savegame.
* @param from First savegame version that has the list.
* @param to Last savegame version that has the list.
*/
#define SLE_CONDREFDEQUE(base, variable, type, from, to) SLE_GENERAL(SL_REFDEQUE, base, variable, type, 0, from, to, 0)
#define SLE_CONDREFRING(base, variable, type, from, to) SLE_GENERAL(SL_REFRING, base, variable, type, 0, from, to, 0)
/**
* Storage of a vector of #SL_REF elements in some savegame versions.
@ -437,14 +437,14 @@ struct SaveLoadCompat {
#define SLE_CONDREFVEC(base, variable, type, from, to) SLE_GENERAL(SL_REFVEC, base, variable, type, 0, from, to, 0)
/**
* Storage of a deque of #SL_VAR elements in some savegame versions.
* Storage of a ring of #SL_VAR elements in some savegame versions.
* @param base Name of the class or struct containing the list.
* @param variable Name of the variable in the class or struct referenced by \a base.
* @param type Storage of the data in memory and in the savegame.
* @param from First savegame version that has the list.
* @param to Last savegame version that has the list.
*/
#define SLE_CONDDEQUE(base, variable, type, from, to) SLE_GENERAL(SL_DEQUE, base, variable, type, 0, from, to, 0)
#define SLE_CONDRING(base, variable, type, from, to) SLE_GENERAL(SL_RING, base, variable, type, 0, from, to, 0)
/**
* Storage of a variable in every version of a savegame.
@ -498,12 +498,12 @@ struct SaveLoadCompat {
#define SLE_REFLIST(base, variable, type) SLE_CONDREFLIST(base, variable, type, SL_MIN_VERSION, SL_MAX_VERSION)
/**
* Storage of a deque of #SL_REF elements in every savegame version.
* Storage of a ring of #SL_REF elements in every savegame version.
* @param base Name of the class or struct containing the list.
* @param variable Name of the variable in the class or struct referenced by \a base.
* @param type Storage of the data in memory and in the savegame.
*/
#define SLE_REFDEQUE(base, variable, type) SLE_CONDREFDEQUE(base, variable, type, SL_MIN_VERSION, SL_MAX_VERSION)
#define SLE_REFRING(base, variable, type) SLE_CONDREFRING(base, variable, type, SL_MIN_VERSION, SL_MAX_VERSION)
/**
* Storage of a vector of #SL_REF elements in every savegame version.
@ -610,14 +610,14 @@ struct SaveLoadCompat {
#define SLEG_CONDREFLIST(name, variable, type, from, to) SLEG_GENERAL(name, SL_REFLIST, variable, type, 0, from, to, 0)
/**
* Storage of a global reference deque in some savegame versions.
* Storage of a global reference ring in some savegame versions.
* @param name The name of the field.
* @param variable Name of the global variable.
* @param type Storage of the data in memory and in the savegame.
* @param from First savegame version that has the list.
* @param to Last savegame version that has the list.
*/
#define SLEG_CONDREFDEQUE(name, variable, type, from, to) SLEG_GENERAL(name, SL_REFDEQUE, variable, type, 0, from, to, 0)
#define SLEG_CONDREFRING(name, variable, type, from, to) SLEG_GENERAL(name, SL_REFRING, variable, type, 0, from, to, 0)
/**
* Storage of a global reference vector in some savegame versions.
@ -704,12 +704,12 @@ struct SaveLoadCompat {
#define SLEG_REFLIST(name, variable, type) SLEG_CONDREFLIST(name, variable, type, SL_MIN_VERSION, SL_MAX_VERSION)
/**
* Storage of a global reference deque in every savegame version.
* Storage of a global reference ring in every savegame version.
* @param name The name of the field.
* @param variable Name of the global variable.
* @param type Storage of the data in memory and in the savegame.
*/
#define SLEG_REFDEQUE(name, variable, type) SLEG_CONDREFDEQUE(name, variable, type, SL_MIN_VERSION, SL_MAX_VERSION)
#define SLEG_REFRING(name, variable, type) SLEG_CONDREFRING(name, variable, type, SL_MIN_VERSION, SL_MAX_VERSION)
/**
* Storage of a global vector of #SL_VAR elements in every savegame version.

@ -135,8 +135,8 @@ public:
class SlStationCargo : public DefaultSaveLoadHandler<SlStationCargo, GoodsEntry> {
public:
inline static const SaveLoad description[] = {
SLE_VAR(StationCargoPair, first, SLE_UINT16),
SLE_REFDEQUE(StationCargoPair, second, REF_CARGO_PACKET),
SLE_VAR(StationCargoPair, first, SLE_UINT16),
SLE_REFRING(StationCargoPair, second, REF_CARGO_PACKET),
};
inline const static SaveLoadCompatTable compat_description = _station_cargo_sl_compat;
@ -227,7 +227,7 @@ public:
SLEG_CONDVAR("cargo_feeder_share", _cargo_feeder_share, SLE_FILE_U32 | SLE_VAR_I64, SLV_14, SLV_65),
SLEG_CONDVAR("cargo_feeder_share", _cargo_feeder_share, SLE_INT64, SLV_65, SLV_68),
SLE_CONDVAR(GoodsEntry, amount_fract, SLE_UINT8, SLV_150, SL_MAX_VERSION),
SLEG_CONDREFDEQUE("packets", _packets, REF_CARGO_PACKET, SLV_68, SLV_183),
SLEG_CONDREFRING("packets", _packets, REF_CARGO_PACKET, SLV_68, SLV_183),
SLEG_CONDVAR("old_num_dests", _old_num_dests, SLE_UINT32, SLV_183, SLV_SAVELOAD_LIST_LENGTH),
SLE_CONDVAR(GoodsEntry, cargo.reserved_count, SLE_UINT, SLV_181, SL_MAX_VERSION),
SLE_CONDVAR(GoodsEntry, link_graph, SLE_UINT16, SLV_183, SL_MAX_VERSION),

@ -102,7 +102,7 @@ public:
SLE_VAR(Vehicle, cargo_cap, SLE_UINT16),
SLE_CONDVAR(Vehicle, refit_cap, SLE_UINT16, SLV_182, SL_MAX_VERSION),
SLEG_CONDVAR("cargo_count", _cargo_count, SLE_UINT16, SL_MIN_VERSION, SLV_68),
SLE_CONDREFDEQUE(Vehicle, cargo.packets, REF_CARGO_PACKET, SLV_68, SL_MAX_VERSION),
SLE_CONDREFRING(Vehicle, cargo.packets, REF_CARGO_PACKET, SLV_68, SL_MAX_VERSION),
SLE_CONDARR(Vehicle, cargo.action_counts, SLE_UINT, VehicleCargoList::NUM_MOVE_TO_ACTION, SLV_181, SL_MAX_VERSION),
SLE_CONDVAR(Vehicle, cargo_age_counter, SLE_UINT16, SLV_162, SL_MAX_VERSION),

@ -45,8 +45,8 @@
#include "../load_check.h"
#include "../error.h"
#include "../scope.h"
#include "../core/ring_buffer.hpp"
#include <atomic>
#include <deque>
#include <string>
#ifdef __EMSCRIPTEN__
# include <emscripten.h>
@ -61,7 +61,6 @@
#include "saveload_buffer.h"
#include "extended_ver_sl.h"
#include <deque>
#include <vector>
#include "../thread.h"
@ -1398,9 +1397,9 @@ void SlSaveLoadRef(void *ptr, VarType conv)
/**
* Template class to help with list-like types.
*/
template <template<typename, typename> typename Tstorage, typename Tvar, typename Tallocator = std::allocator<Tvar>>
template <template<typename> typename Tstorage, typename Tvar>
class SlStorageHelper {
typedef Tstorage<Tvar, Tallocator> SlStorageT;
typedef Tstorage<Tvar> SlStorageT;
public:
/**
* Internal templated helper to return the size in bytes of a list-like type.
@ -1615,43 +1614,43 @@ static void SlVarList(void *list, VarType conv)
}
/**
* Return the size in bytes of a std::deque.
* @param deque The std::deque to find the size of
* Return the size in bytes of a ring buffer.
* @param ring The ring buffer to find the size of
* @param conv VarType type of variable that is used for calculating the size
*/
static inline size_t SlCalcDequeLen(const void *deque, VarType conv)
static inline size_t SlCalcRingLen(const void *ring, VarType conv)
{
switch (GetVarMemType(conv)) {
case SLE_VAR_BL: return SlStorageHelper<std::deque, bool>::SlCalcLen(deque, conv);
case SLE_VAR_I8: return SlStorageHelper<std::deque, int8>::SlCalcLen(deque, conv);
case SLE_VAR_U8: return SlStorageHelper<std::deque, uint8>::SlCalcLen(deque, conv);
case SLE_VAR_I16: return SlStorageHelper<std::deque, int16>::SlCalcLen(deque, conv);
case SLE_VAR_U16: return SlStorageHelper<std::deque, uint16>::SlCalcLen(deque, conv);
case SLE_VAR_I32: return SlStorageHelper<std::deque, int32>::SlCalcLen(deque, conv);
case SLE_VAR_U32: return SlStorageHelper<std::deque, uint32>::SlCalcLen(deque, conv);
case SLE_VAR_I64: return SlStorageHelper<std::deque, int64>::SlCalcLen(deque, conv);
case SLE_VAR_U64: return SlStorageHelper<std::deque, uint64>::SlCalcLen(deque, conv);
case SLE_VAR_BL: return SlStorageHelper<ring_buffer, bool>::SlCalcLen(ring, conv);
case SLE_VAR_I8: return SlStorageHelper<ring_buffer, int8>::SlCalcLen(ring, conv);
case SLE_VAR_U8: return SlStorageHelper<ring_buffer, uint8>::SlCalcLen(ring, conv);
case SLE_VAR_I16: return SlStorageHelper<ring_buffer, int16>::SlCalcLen(ring, conv);
case SLE_VAR_U16: return SlStorageHelper<ring_buffer, uint16>::SlCalcLen(ring, conv);
case SLE_VAR_I32: return SlStorageHelper<ring_buffer, int32>::SlCalcLen(ring, conv);
case SLE_VAR_U32: return SlStorageHelper<ring_buffer, uint32>::SlCalcLen(ring, conv);
case SLE_VAR_I64: return SlStorageHelper<ring_buffer, int64>::SlCalcLen(ring, conv);
case SLE_VAR_U64: return SlStorageHelper<ring_buffer, uint64>::SlCalcLen(ring, conv);
default: NOT_REACHED();
}
}
/**
* Save/load a std::deque.
* @param deque The std::deque being manipulated
* Save/load a ring buffer.
* @param ring The ring buffer being manipulated
* @param conv VarType type of variable that is used for calculating the size
*/
static void SlDeque(void *deque, VarType conv)
static void SlRing(void *ring, VarType conv)
{
switch (GetVarMemType(conv)) {
case SLE_VAR_BL: SlStorageHelper<std::deque, bool>::SlSaveLoad(deque, conv); break;
case SLE_VAR_I8: SlStorageHelper<std::deque, int8>::SlSaveLoad(deque, conv); break;
case SLE_VAR_U8: SlStorageHelper<std::deque, uint8>::SlSaveLoad(deque, conv); break;
case SLE_VAR_I16: SlStorageHelper<std::deque, int16>::SlSaveLoad(deque, conv); break;
case SLE_VAR_U16: SlStorageHelper<std::deque, uint16>::SlSaveLoad(deque, conv); break;
case SLE_VAR_I32: SlStorageHelper<std::deque, int32>::SlSaveLoad(deque, conv); break;
case SLE_VAR_U32: SlStorageHelper<std::deque, uint32>::SlSaveLoad(deque, conv); break;
case SLE_VAR_I64: SlStorageHelper<std::deque, int64>::SlSaveLoad(deque, conv); break;
case SLE_VAR_U64: SlStorageHelper<std::deque, uint64>::SlSaveLoad(deque, conv); break;
case SLE_VAR_BL: SlStorageHelper<ring_buffer, bool>::SlSaveLoad(ring, conv); break;
case SLE_VAR_I8: SlStorageHelper<ring_buffer, int8>::SlSaveLoad(ring, conv); break;
case SLE_VAR_U8: SlStorageHelper<ring_buffer, uint8>::SlSaveLoad(ring, conv); break;
case SLE_VAR_I16: SlStorageHelper<ring_buffer, int16>::SlSaveLoad(ring, conv); break;
case SLE_VAR_U16: SlStorageHelper<ring_buffer, uint16>::SlSaveLoad(ring, conv); break;
case SLE_VAR_I32: SlStorageHelper<ring_buffer, int32>::SlSaveLoad(ring, conv); break;
case SLE_VAR_U32: SlStorageHelper<ring_buffer, uint32>::SlSaveLoad(ring, conv); break;
case SLE_VAR_I64: SlStorageHelper<ring_buffer, int64>::SlSaveLoad(ring, conv); break;
case SLE_VAR_U64: SlStorageHelper<ring_buffer, uint64>::SlSaveLoad(ring, conv); break;
default: NOT_REACHED();
}
}
@ -1689,9 +1688,9 @@ size_t SlCalcObjMemberLength(const void *object, const SaveLoad &sld)
case SL_ARR:
case SL_STR:
case SL_REFLIST:
case SL_PTRDEQ:
case SL_PTRRING:
case SL_VEC:
case SL_DEQUE:
case SL_RING:
case SL_STDSTR:
case SL_VARVEC:
/* CONDITIONAL saveload types depend on the savegame version */
@ -1703,9 +1702,9 @@ size_t SlCalcObjMemberLength(const void *object, const SaveLoad &sld)
case SL_ARR: return SlCalcArrayLen(sld.length, sld.conv);
case SL_STR: return SlCalcStringLen(GetVariableAddress(object, sld), sld.length, sld.conv);
case SL_REFLIST: return SlCalcRefListLen<std::list<void *>>(GetVariableAddress(object, sld));
case SL_PTRDEQ: return SlCalcRefListLen<std::deque<void *>>(GetVariableAddress(object, sld));
case SL_PTRRING: return SlCalcRefListLen<ring_buffer<void *>>(GetVariableAddress(object, sld));
case SL_VEC: return SlCalcRefListLen<std::vector<void *>>(GetVariableAddress(object, sld));
case SL_DEQUE: return SlCalcDequeLen(GetVariableAddress(object, sld), sld.conv);
case SL_RING: return SlCalcRingLen(GetVariableAddress(object, sld), sld.conv);
case SL_VARVEC: {
const size_t size_len = SlCalcConvMemLen(sld.conv);
switch (size_len) {
@ -1788,9 +1787,9 @@ static void SlFilterObjectMember(const SaveLoad &sld, std::vector<SaveLoad> &sav
case SL_ARR:
case SL_STR:
case SL_REFLIST:
case SL_PTRDEQ:
case SL_PTRRING:
case SL_VEC:
case SL_DEQUE:
case SL_RING:
case SL_STDSTR:
case SL_VARVEC:
/* CONDITIONAL saveload types depend on the savegame version */
@ -1806,7 +1805,7 @@ static void SlFilterObjectMember(const SaveLoad &sld, std::vector<SaveLoad> &sav
switch (sld.cmd) {
case SL_REF:
case SL_REFLIST:
case SL_PTRDEQ:
case SL_PTRRING:
case SL_VEC:
break;
@ -1869,9 +1868,9 @@ bool SlObjectMemberGeneric(void *object, const SaveLoad &sld)
case SL_ARR:
case SL_STR:
case SL_REFLIST:
case SL_PTRDEQ:
case SL_PTRRING:
case SL_VEC:
case SL_DEQUE:
case SL_RING:
case SL_STDSTR:
case SL_VARVEC:
/* CONDITIONAL saveload types depend on the savegame version */
@ -1902,9 +1901,9 @@ bool SlObjectMemberGeneric(void *object, const SaveLoad &sld)
case SL_ARR: SlArray(ptr, sld.length, conv); break;
case SL_STR: SlString(ptr, sld.length, sld.conv); break;
case SL_REFLIST: SlRefList<std::list<void *>>(ptr, (SLRefType)conv); break;
case SL_PTRDEQ: SlRefList<std::deque<void *>>(ptr, (SLRefType)conv); break;
case SL_PTRRING: SlRefList<ring_buffer<void *>>(ptr, (SLRefType)conv); break;
case SL_VEC: SlRefList<std::vector<void *>>(ptr, (SLRefType)conv); break;
case SL_DEQUE: SlDeque(ptr, conv); break;
case SL_RING: SlRing(ptr, conv); break;
case SL_VARVEC: {
const size_t size_len = SlCalcConvMemLen(sld.conv);
switch (size_len) {

@ -287,7 +287,7 @@ DECLARE_ENUM_AS_BIT_SET(SaveLoadChunkExtHeaderFlags)
#define SLE_CONDREFLIST(base, variable, type, from, to) SLE_CONDREFLIST_X(base, variable, type, from, to, SlXvFeatureTest())
/**
* Storage of a deque in some savegame versions.
* Storage of a ring in some savegame versions.
* @param base Name of the class or struct containing the list.
* @param variable Name of the variable in the class or struct referenced by \a base.
* @param type Storage of the data in memory and in the savegame.
@ -295,8 +295,8 @@ DECLARE_ENUM_AS_BIT_SET(SaveLoadChunkExtHeaderFlags)
* @param to Last savegame version that has the list.
* @param extver SlXvFeatureTest to test (along with from and to) which savegames have the field
*/
#define SLE_CONDPTRDEQ_X(base, variable, type, from, to, extver) SLE_GENERAL_X(SL_PTRDEQ, base, variable, type, 0, from, to, extver)
#define SLE_CONDPTRDEQ(base, variable, type, from, to) SLE_CONDPTRDEQ_X(base, variable, type, from, to, SlXvFeatureTest())
#define SLE_CONDPTRRING_X(base, variable, type, from, to, extver) SLE_GENERAL_X(SL_PTRRING, base, variable, type, 0, from, to, extver)
#define SLE_CONDPTRRING(base, variable, type, from, to) SLE_CONDPTRRING_X(base, variable, type, from, to, SlXvFeatureTest())
/**
* Storage of a vector in some savegame versions.
@ -323,7 +323,7 @@ DECLARE_ENUM_AS_BIT_SET(SaveLoadChunkExtHeaderFlags)
#define SLE_CONDVARVEC(base, variable, type, from, to) SLE_CONDVARVEC_X(base, variable, type, from, to, SlXvFeatureTest())
/**
* Storage of a deque of #SL_VAR elements in some savegame versions.
* Storage of a ring of #SL_VAR elements in some savegame versions.
* @param base Name of the class or struct containing the list.
* @param variable Name of the variable in the class or struct referenced by \a base.
* @param type Storage of the data in memory and in the savegame.
@ -331,8 +331,8 @@ DECLARE_ENUM_AS_BIT_SET(SaveLoadChunkExtHeaderFlags)
* @param to Last savegame version that has the list.
* @param extver SlXvFeatureTest to test (along with from and to) which savegames have the field
*/
#define SLE_CONDDEQUE_X(base, variable, type, from, to, extver) SLE_GENERAL_X(SL_DEQUE, base, variable, type, 0, from, to, extver)
#define SLE_CONDDEQUE(base, variable, type, from, to) SLE_CONDDEQUE_X(base, variable, type, from, to, SlXvFeatureTest())
#define SLE_CONDRING_X(base, variable, type, from, to, extver) SLE_GENERAL_X(SL_RING, base, variable, type, 0, from, to, extver)
#define SLE_CONDRING(base, variable, type, from, to) SLE_CONDRING_X(base, variable, type, from, to, SlXvFeatureTest())
/**
* Storage of a variable in every version of a savegame.
@ -385,12 +385,12 @@ DECLARE_ENUM_AS_BIT_SET(SaveLoadChunkExtHeaderFlags)
#define SLE_REFLIST(base, variable, type) SLE_CONDREFLIST(base, variable, type, SL_MIN_VERSION, SL_MAX_VERSION)
/**
* Storage of a deque in every savegame version.
* Storage of a ring in every savegame version.
* @param base Name of the class or struct containing the list.
* @param variable Name of the variable in the class or struct referenced by \a base.
* @param type Storage of the data in memory and in the savegame.
*/
#define SLE_PTRDEQ(base, variable, type) SLE_CONDPTRDEQ(base, variable, type, SL_MIN_VERSION, SL_MAX_VERSION)
#define SLE_PTRRING(base, variable, type) SLE_CONDPTRRING(base, variable, type, SL_MIN_VERSION, SL_MAX_VERSION)
/**
* Storage of a vector in every savegame version.
@ -511,15 +511,15 @@ DECLARE_ENUM_AS_BIT_SET(SaveLoadChunkExtHeaderFlags)
#define SLEG_CONDREFLIST(variable, type, from, to) SLEG_CONDREFLIST_X(variable, type, from, to, SlXvFeatureTest())
/**
* Storage of a global deque in some savegame versions.
* Storage of a global ring in some savegame versions.
* @param variable Name of the global variable.
* @param type Storage of the data in memory and in the savegame.
* @param from First savegame version that has the list.
* @param to Last savegame version that has the list.
* @param extver SlXvFeatureTest to test (along with from and to) which savegames have the field
*/
#define SLEG_CONDPTRDEQ_X(variable, type, from, to, extver) SLEG_GENERAL_X(SL_PTRDEQ, variable, type, 0, from, to, extver)
#define SLEG_CONDPTRDEQ(variable, type, from, to) SLEG_CONDPTRDEQ_X(variable, type, from, to, SlXvFeatureTest())
#define SLEG_CONDPTRRING_X(variable, type, from, to, extver) SLEG_GENERAL_X(SL_PTRRING, variable, type, 0, from, to, extver)
#define SLEG_CONDPTRRING(variable, type, from, to) SLEG_CONDPTRRING_X(variable, type, from, to, SlXvFeatureTest())
/**
* Storage of a global vector in some savegame versions.
@ -586,11 +586,11 @@ DECLARE_ENUM_AS_BIT_SET(SaveLoadChunkExtHeaderFlags)
#define SLEG_REFLIST(variable, type) SLEG_CONDREFLIST(variable, type, SL_MIN_VERSION, SL_MAX_VERSION)
/**
* Storage of a global deque in every savegame version.
* Storage of a global ring in every savegame version.
* @param variable Name of the global variable.
* @param type Storage of the data in memory and in the savegame.
*/
#define SLEG_PTRDEQ(variable, type) SLEG_CONDPTRDEQ(variable, type, SL_MIN_VERSION, SL_MAX_VERSION)
#define SLEG_PTRRING(variable, type) SLEG_CONDPTRRING(variable, type, SL_MIN_VERSION, SL_MAX_VERSION)
/**
* Storage of a global vector in every savegame version.

@ -100,7 +100,7 @@ enum SaveLoadTypes {
SL_ARR = 2, ///< Save/load a fixed-size array of #SL_VAR elements.
SL_STR = 3, ///< Save/load a string.
SL_REFLIST = 4, ///< Save/load a list of #SL_REF elements.
SL_DEQUE = 5, ///< Save/load a deque of #SL_VAR elements.
SL_RING = 5, ///< Save/load a ring of #SL_VAR elements.
SL_VEC = 6, ///< Save/load a vector of #SL_REF elements.
SL_STDSTR = 7, ///< Save/load a std::string.
@ -109,7 +109,7 @@ enum SaveLoadTypes {
SL_VEH_INCLUDE = 9,
SL_ST_INCLUDE = 10,
SL_PTRDEQ = 13, ///< Save/load a deque of #SL_REF elements.
SL_PTRRING = 13, ///< Save/load a ring of #SL_REF elements.
SL_VARVEC = 14, ///< Save/load a primitive type vector.
};

@ -293,7 +293,7 @@ SaveLoadTable GetGoodsDesc()
SLEG_CONDVAR( _cargo_feeder_share, SLE_FILE_U32 | SLE_VAR_I64, SLV_14, SLV_65),
SLEG_CONDVAR( _cargo_feeder_share, SLE_INT64, SLV_65, SLV_68),
SLE_CONDVAR(GoodsEntry, amount_fract, SLE_UINT8, SLV_150, SL_MAX_VERSION),
SLEG_CONDPTRDEQ_X( _packets, REF_CARGO_PACKET, SLV_68, SLV_183, SlXvFeatureTest(XSLFTO_AND, XSLFI_CHILLPP, 0, 0)),
SLEG_CONDPTRRING_X( _packets, REF_CARGO_PACKET, SLV_68, SLV_183, SlXvFeatureTest(XSLFTO_AND, XSLFI_CHILLPP, 0, 0)),
SLEG_CONDVAR_X( _num_dests, SLE_UINT32, SLV_183, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_OR, XSLFI_CHILLPP)),
SLE_CONDVAR(GoodsEntry, cargo.reserved_count, SLE_UINT, SLV_181, SL_MAX_VERSION),
SLE_CONDVAR(GoodsEntry, link_graph, SLE_UINT16, SLV_183, SL_MAX_VERSION),
@ -311,7 +311,7 @@ typedef std::pair<const StationID, CargoPacketList> StationCargoPair;
static const SaveLoad _cargo_list_desc[] = {
SLE_VAR(StationCargoPair, first, SLE_UINT16),
SLE_PTRDEQ(StationCargoPair, second, REF_CARGO_PACKET),
SLE_PTRRING(StationCargoPair, second, REF_CARGO_PACKET),
};
/**

@ -706,8 +706,8 @@ SaveLoadTable GetVehicleDescription(VehicleType vt)
SLE_VAR(Vehicle, cargo_cap, SLE_UINT16),
SLE_CONDVAR(Vehicle, refit_cap, SLE_UINT16, SLV_182, SL_MAX_VERSION),
SLEG_CONDVAR( _cargo_count, SLE_UINT16, SL_MIN_VERSION, SLV_68),
SLE_CONDPTRDEQ(Vehicle, cargo.packets, REF_CARGO_PACKET, SLV_68, SL_MAX_VERSION),
SLEG_CONDPTRDEQ_X( _cpp_packets, REF_CARGO_PACKET, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_CHILLPP)),
SLE_CONDPTRRING(Vehicle, cargo.packets, REF_CARGO_PACKET, SLV_68, SL_MAX_VERSION),
SLEG_CONDPTRRING_X( _cpp_packets, REF_CARGO_PACKET, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_CHILLPP)),
SLE_CONDARR(Vehicle, cargo.action_counts, SLE_UINT, VehicleCargoList::NUM_MOVE_TO_ACTION, SLV_181, SL_MAX_VERSION),
SLE_CONDVAR(Vehicle, cargo_age_counter, SLE_UINT16, SLV_162, SL_MAX_VERSION),

Loading…
Cancel
Save