summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorglx22 <glx@openttd.org>2021-07-04 22:44:23 +0200
committerLoïc Guilloux <glx22@users.noreply.github.com>2021-07-06 22:29:08 +0200
commit7bcc7e11ff367d655b58fdc29bde5174afd49e4b (patch)
tree2014ca7f72fed7417cf73ff69dca401a46b4c872
parent6e627f35ac03008dab7729ad079b79db9df2d68b (diff)
downloadopenttd-7bcc7e11ff367d655b58fdc29bde5174afd49e4b.tar.xz
Codechange: Use a common sub-class for NewGRFMapping chunks
-rw-r--r--src/saveload/airport_sl.cpp28
-rw-r--r--src/saveload/industry_sl.cpp28
-rw-r--r--src/saveload/newgrf_sl.cpp20
-rw-r--r--src/saveload/newgrf_sl.h9
-rw-r--r--src/saveload/object_sl.cpp14
-rw-r--r--src/saveload/town_sl.cpp14
6 files changed, 28 insertions, 85 deletions
diff --git a/src/saveload/airport_sl.cpp b/src/saveload/airport_sl.cpp
index e762c54d0..d83c45b04 100644
--- a/src/saveload/airport_sl.cpp
+++ b/src/saveload/airport_sl.cpp
@@ -14,32 +14,12 @@
#include "../safeguards.h"
-struct APIDChunkHandler : ChunkHandler {
- APIDChunkHandler() : ChunkHandler('APID', CH_TABLE) {}
-
- void Save() const override
- {
- Save_NewGRFMapping(_airport_mngr);
- }
-
- void Load() const override
- {
- Load_NewGRFMapping(_airport_mngr);
- }
+struct APIDChunkHandler : NewGRFMappingChunkHandler {
+ APIDChunkHandler() : NewGRFMappingChunkHandler('APID', _airport_mngr) {}
};
-struct ATIDChunkHandler : ChunkHandler {
- ATIDChunkHandler() : ChunkHandler('ATID', CH_TABLE) {}
-
- void Save() const override
- {
- Save_NewGRFMapping(_airporttile_mngr);
- }
-
- void Load() const override
- {
- Load_NewGRFMapping(_airporttile_mngr);
- }
+struct ATIDChunkHandler : NewGRFMappingChunkHandler {
+ ATIDChunkHandler() : NewGRFMappingChunkHandler('ATID', _airporttile_mngr) {}
};
static const ATIDChunkHandler ATID;
diff --git a/src/saveload/industry_sl.cpp b/src/saveload/industry_sl.cpp
index 6d1645e39..7a941a9c7 100644
--- a/src/saveload/industry_sl.cpp
+++ b/src/saveload/industry_sl.cpp
@@ -119,32 +119,12 @@ struct INDYChunkHandler : ChunkHandler {
}
};
-struct IIDSChunkHandler : ChunkHandler {
- IIDSChunkHandler() : ChunkHandler('IIDS', CH_TABLE) {}
-
- void Save() const override
- {
- Save_NewGRFMapping(_industry_mngr);
- }
-
- void Load() const override
- {
- Load_NewGRFMapping(_industry_mngr);
- }
+struct IIDSChunkHandler : NewGRFMappingChunkHandler {
+ IIDSChunkHandler() : NewGRFMappingChunkHandler('IIDS', _industry_mngr) {}
};
-struct TIDSChunkHandler : ChunkHandler {
- TIDSChunkHandler() : ChunkHandler('TIDS', CH_TABLE) {}
-
- void Save() const override
- {
- Save_NewGRFMapping(_industile_mngr);
- }
-
- void Load() const override
- {
- Load_NewGRFMapping(_industile_mngr);
- }
+struct TIDSChunkHandler : NewGRFMappingChunkHandler {
+ TIDSChunkHandler() : NewGRFMappingChunkHandler('TIDS', _industile_mngr) {}
};
/** Description of the data to save and load in #IndustryBuildData. */
diff --git a/src/saveload/newgrf_sl.cpp b/src/saveload/newgrf_sl.cpp
index 9584d503e..510ffc156 100644
--- a/src/saveload/newgrf_sl.cpp
+++ b/src/saveload/newgrf_sl.cpp
@@ -26,38 +26,36 @@ static const SaveLoad _newgrf_mapping_desc[] = {
/**
* Save a GRF ID + local id -> OpenTTD's id mapping.
- * @param mapping The mapping to save.
*/
-void Save_NewGRFMapping(const OverrideManagerBase &mapping)
+void NewGRFMappingChunkHandler::Save() const
{
SlTableHeader(_newgrf_mapping_desc);
- for (uint i = 0; i < mapping.GetMaxMapping(); i++) {
- if (mapping.mapping_ID[i].grfid == 0 &&
- mapping.mapping_ID[i].entity_id == 0) continue;
+ for (uint i = 0; i < this->mapping.GetMaxMapping(); i++) {
+ if (this->mapping.mapping_ID[i].grfid == 0 &&
+ this->mapping.mapping_ID[i].entity_id == 0) continue;
SlSetArrayIndex(i);
- SlObject(&mapping.mapping_ID[i], _newgrf_mapping_desc);
+ SlObject(&this->mapping.mapping_ID[i], _newgrf_mapping_desc);
}
}
/**
* Load a GRF ID + local id -> OpenTTD's id mapping.
- * @param mapping The mapping to load.
*/
-void Load_NewGRFMapping(OverrideManagerBase &mapping)
+void NewGRFMappingChunkHandler::Load() const
{
const std::vector<SaveLoad> slt = SlCompatTableHeader(_newgrf_mapping_desc, _newgrf_mapping_sl_compat);
/* Clear the current mapping stored.
* This will create the manager if ever it is not yet done */
- mapping.ResetMapping();
+ this->mapping.ResetMapping();
- uint max_id = mapping.GetMaxMapping();
+ uint max_id = this->mapping.GetMaxMapping();
int index;
while ((index = SlIterateArray()) != -1) {
if ((uint)index >= max_id) SlErrorCorrupt("Too many NewGRF entity mappings");
- SlObject(&mapping.mapping_ID[index], slt);
+ SlObject(&this->mapping.mapping_ID[index], slt);
}
}
diff --git a/src/saveload/newgrf_sl.h b/src/saveload/newgrf_sl.h
index 191046de2..c266d90b1 100644
--- a/src/saveload/newgrf_sl.h
+++ b/src/saveload/newgrf_sl.h
@@ -12,7 +12,12 @@
#include "../newgrf_commons.h"
-void Save_NewGRFMapping(const OverrideManagerBase &mapping);
-void Load_NewGRFMapping(OverrideManagerBase &mapping);
+struct NewGRFMappingChunkHandler : ChunkHandler {
+ OverrideManagerBase &mapping;
+
+ NewGRFMappingChunkHandler(uint32 id, OverrideManagerBase &mapping) : ChunkHandler(id, CH_TABLE), mapping(mapping) {}
+ void Save() const override;
+ void Load() const override;
+};
#endif /* SAVELOAD_NEWGRF_SL_H */
diff --git a/src/saveload/object_sl.cpp b/src/saveload/object_sl.cpp
index a61050303..eea1ec0fc 100644
--- a/src/saveload/object_sl.cpp
+++ b/src/saveload/object_sl.cpp
@@ -66,18 +66,8 @@ struct OBJSChunkHandler : ChunkHandler {
}
};
-struct OBIDChunkHandler : ChunkHandler {
- OBIDChunkHandler() : ChunkHandler('OBID', CH_TABLE) {}
-
- void Save() const override
- {
- Save_NewGRFMapping(_object_mngr);
- }
-
- void Load() const override
- {
- Load_NewGRFMapping(_object_mngr);
- }
+struct OBIDChunkHandler : NewGRFMappingChunkHandler {
+ OBIDChunkHandler() : NewGRFMappingChunkHandler('OBID', _object_mngr) {}
};
static const OBIDChunkHandler OBID;
diff --git a/src/saveload/town_sl.cpp b/src/saveload/town_sl.cpp
index edf38178d..7b9125917 100644
--- a/src/saveload/town_sl.cpp
+++ b/src/saveload/town_sl.cpp
@@ -272,18 +272,8 @@ static const SaveLoad _town_desc[] = {
SLEG_CONDSTRUCTLIST("acceptance_matrix", SlTownAcceptanceMatrix, SLV_166, SLV_REMOVE_TOWN_CARGO_CACHE),
};
-struct HIDSChunkHandler : ChunkHandler {
- HIDSChunkHandler() : ChunkHandler('HIDS', CH_TABLE) {}
-
- void Save() const override
- {
- Save_NewGRFMapping(_house_mngr);
- }
-
- void Load() const override
- {
- Load_NewGRFMapping(_house_mngr);
- }
+struct HIDSChunkHandler : NewGRFMappingChunkHandler {
+ HIDSChunkHandler() : NewGRFMappingChunkHandler('HIDS', _house_mngr) {}
};
struct CITYChunkHandler : ChunkHandler {