mirror of
https://github.com/OpenTTD/OpenTTD
synced 2026-01-25 05:04:07 +01:00
Codechange: Add VectorSaveLoadHandler to simplify handlers for vectors. (#13093)
This reduces the duplication needed for each saved complex vector.
This commit is contained in:
@@ -19,7 +19,7 @@
|
||||
|
||||
static OldPersistentStorage _old_ind_persistent_storage;
|
||||
|
||||
class SlIndustryAccepted : public DefaultSaveLoadHandler<SlIndustryAccepted, Industry> {
|
||||
class SlIndustryAccepted : public VectorSaveLoadHandler<SlIndustryAccepted, Industry, Industry::AcceptedCargo, INDUSTRY_NUM_INPUTS> {
|
||||
public:
|
||||
inline static const SaveLoad description[] = {
|
||||
SLE_VAR(Industry::AcceptedCargo, cargo, SLE_UINT8),
|
||||
@@ -28,27 +28,9 @@ public:
|
||||
};
|
||||
inline const static SaveLoadCompatTable compat_description = _industry_accepts_sl_compat;
|
||||
|
||||
void Save(Industry *i) const override
|
||||
{
|
||||
SlSetStructListLength(i->accepted.size());
|
||||
std::vector<Industry::AcceptedCargo> &GetVector(Industry *i) const override { return i->accepted; }
|
||||
|
||||
for (auto &a : i->accepted) {
|
||||
SlObject(&a, this->GetDescription());
|
||||
}
|
||||
}
|
||||
|
||||
void Load(Industry *i) const override
|
||||
{
|
||||
size_t len = SlGetStructListLength(INDUSTRY_NUM_INPUTS);
|
||||
|
||||
i->accepted.reserve(len);
|
||||
for (size_t index = 0; index < len; ++index) {
|
||||
auto &a = i->accepted.emplace_back();
|
||||
SlObject(&a, this->GetLoadDescription());
|
||||
}
|
||||
}
|
||||
|
||||
/* Old array structure used for savegames before SLV_INDUSTRY_CARGO_REORGANISE. */
|
||||
/* Old array structure used by INDYChunkHandler for savegames before SLV_INDUSTRY_CARGO_REORGANISE. */
|
||||
static inline std::array<CargoID, INDUSTRY_NUM_INPUTS> old_cargo;
|
||||
static inline std::array<uint16_t, INDUSTRY_NUM_INPUTS> old_waiting;
|
||||
static inline std::array<TimerGameEconomy::Date, INDUSTRY_NUM_INPUTS> old_last_accepted;
|
||||
@@ -95,7 +77,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class SlIndustryProduced : public DefaultSaveLoadHandler<SlIndustryProduced, Industry> {
|
||||
class SlIndustryProduced : public VectorSaveLoadHandler<SlIndustryProduced, Industry, Industry::ProducedCargo, INDUSTRY_NUM_OUTPUTS> {
|
||||
public:
|
||||
inline static const SaveLoad description[] = {
|
||||
SLE_VAR(Industry::ProducedCargo, cargo, SLE_UINT8),
|
||||
@@ -105,27 +87,9 @@ public:
|
||||
};
|
||||
inline const static SaveLoadCompatTable compat_description = _industry_produced_sl_compat;
|
||||
|
||||
void Save(Industry *i) const override
|
||||
{
|
||||
SlSetStructListLength(i->produced.size());
|
||||
std::vector<Industry::ProducedCargo> &GetVector(Industry *i) const override { return i->produced; }
|
||||
|
||||
for (auto &p : i->produced) {
|
||||
SlObject(&p, this->GetDescription());
|
||||
}
|
||||
}
|
||||
|
||||
void Load(Industry *i) const override
|
||||
{
|
||||
size_t len = SlGetStructListLength(INDUSTRY_NUM_OUTPUTS);
|
||||
|
||||
i->produced.reserve(len);
|
||||
for (size_t index = 0; index < len; ++index) {
|
||||
auto &p = i->produced.emplace_back();
|
||||
SlObject(&p, this->GetLoadDescription());
|
||||
}
|
||||
}
|
||||
|
||||
/* Old array structure used for savegames before SLV_INDUSTRY_CARGO_REORGANISE. */
|
||||
/* Old array structure used by INDYChunkHandler for savegames before SLV_INDUSTRY_CARGO_REORGANISE. */
|
||||
static inline std::array<CargoID, INDUSTRY_NUM_OUTPUTS> old_cargo;
|
||||
static inline std::array<uint16_t, INDUSTRY_NUM_OUTPUTS> old_waiting;
|
||||
static inline std::array<uint8_t, INDUSTRY_NUM_OUTPUTS> old_rate;
|
||||
|
||||
Reference in New Issue
Block a user