From 41b3314d768e74a0bbb193fb5fdedee7eca49019 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Sat, 2 Mar 2024 13:49:55 +0000 Subject: [PATCH] Codechange: Replace separate Station/RoadStopSpecList with template struct. Reduces duplication and simplifies reuse. Additionally naming an item that is used in a list as a ...List was pretty weird. --- src/base_station_base.h | 19 +++++++------------ src/saveload/station_sl.cpp | 12 ++++++------ 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/src/base_station_base.h b/src/base_station_base.h index 82b6c967b2..4a676361ab 100644 --- a/src/base_station_base.h +++ b/src/base_station_base.h @@ -19,16 +19,11 @@ typedef Pool StationPool; extern StationPool _station_pool; -struct StationSpecList { - const StationSpec *spec; - uint32_t grfid; ///< GRF ID of this custom station - uint16_t localidx; ///< Station ID within GRF of station -}; - -struct RoadStopSpecList { - const RoadStopSpec *spec; - uint32_t grfid; ///< GRF ID of this custom road stop - uint16_t localidx; ///< Station ID within GRF of road stop +template +struct SpecMapping { + const T *spec; ///< Custom spec. + uint32_t grfid; ///< GRF ID of this custom spec. + uint16_t localidx; ///< Local ID within GRF of this custom spec. }; struct RoadStopTileData { @@ -74,8 +69,8 @@ struct BaseStation : StationPool::PoolItem<&_station_pool> { Owner owner; ///< The owner of this station StationFacility facilities; ///< The facilities that this station has - std::vector speclist; ///< List of rail station specs of this station. - std::vector roadstop_speclist; ///< List of road stop specs of this station + std::vector> speclist; ///< List of rail station specs of this station. + std::vector> roadstop_speclist; ///< List of road stop specs of this station TimerGameCalendar::Date build_date; ///< Date of construction diff --git a/src/saveload/station_sl.cpp b/src/saveload/station_sl.cpp index 50227920dc..ee86e5523e 100644 --- a/src/saveload/station_sl.cpp +++ b/src/saveload/station_sl.cpp @@ -205,9 +205,9 @@ static void SwapPackets(GoodsEntry *ge) class SlStationSpecList : public DefaultSaveLoadHandler { public: inline static const SaveLoad description[] = { - SLE_CONDVAR(StationSpecList, grfid, SLE_UINT32, SLV_27, SL_MAX_VERSION), - SLE_CONDVAR(StationSpecList, localidx, SLE_FILE_U8 | SLE_VAR_U16, SLV_27, SLV_EXTEND_ENTITY_MAPPING), - SLE_CONDVAR(StationSpecList, localidx, SLE_UINT16, SLV_EXTEND_ENTITY_MAPPING, SL_MAX_VERSION), + SLE_CONDVAR(SpecMapping, grfid, SLE_UINT32, SLV_27, SL_MAX_VERSION), + SLE_CONDVAR(SpecMapping, localidx, SLE_FILE_U8 | SLE_VAR_U16, SLV_27, SLV_EXTEND_ENTITY_MAPPING), + SLE_CONDVAR(SpecMapping, localidx, SLE_UINT16, SLV_EXTEND_ENTITY_MAPPING, SL_MAX_VERSION), }; inline const static SaveLoadCompatTable compat_description = _station_spec_list_sl_compat; @@ -237,9 +237,9 @@ uint8_t SlStationSpecList::last_num_specs; class SlRoadStopSpecList : public DefaultSaveLoadHandler { public: inline static const SaveLoad description[] = { - SLE_VAR(RoadStopSpecList, grfid, SLE_UINT32), - SLE_CONDVAR(RoadStopSpecList, localidx, SLE_FILE_U8 | SLE_VAR_U16, SLV_27, SLV_EXTEND_ENTITY_MAPPING), - SLE_CONDVAR(RoadStopSpecList, localidx, SLE_UINT16, SLV_EXTEND_ENTITY_MAPPING, SL_MAX_VERSION), + SLE_VAR(SpecMapping, grfid, SLE_UINT32), + SLE_CONDVAR(SpecMapping, localidx, SLE_FILE_U8 | SLE_VAR_U16, SLV_27, SLV_EXTEND_ENTITY_MAPPING), + SLE_CONDVAR(SpecMapping, localidx, SLE_UINT16, SLV_EXTEND_ENTITY_MAPPING, SL_MAX_VERSION), }; inline const static SaveLoadCompatTable compat_description = _station_road_stop_spec_list_sl_compat;