diff options
author | glx22 <glx@openttd.org> | 2021-06-09 16:23:35 +0200 |
---|---|---|
committer | Loïc Guilloux <glx22@users.noreply.github.com> | 2021-07-06 22:29:08 +0200 |
commit | c1a9fe6fbd736c9e3a93314b0721d8f2cb8a2052 (patch) | |
tree | 801fdadf7721c07033fff31bf4d04c3d5f6200a5 /src | |
parent | f371a5ad705e10940612475cc697091914a2c96a (diff) | |
download | openttd-c1a9fe6fbd736c9e3a93314b0721d8f2cb8a2052.tar.xz |
Codechange: Use static array of references to ChunkHandler
Diffstat (limited to 'src')
35 files changed, 174 insertions, 108 deletions
diff --git a/src/saveload/ai_sl.cpp b/src/saveload/ai_sl.cpp index 047a08d5b..f5cf040a9 100644 --- a/src/saveload/ai_sl.cpp +++ b/src/saveload/ai_sl.cpp @@ -127,8 +127,9 @@ static void Save_AIPL() } } -static const ChunkHandler ai_chunk_handlers[] = { - { 'AIPL', Save_AIPL, Load_AIPL, nullptr, nullptr, CH_TABLE }, +static const ChunkHandler AIPL{ 'AIPL', Save_AIPL, Load_AIPL, nullptr, nullptr, CH_TABLE }; +static const ChunkHandlerRef ai_chunk_handlers[] = { + AIPL, }; extern const ChunkHandlerTable _ai_chunk_handlers(ai_chunk_handlers); diff --git a/src/saveload/airport_sl.cpp b/src/saveload/airport_sl.cpp index 6862fc133..3ab852150 100644 --- a/src/saveload/airport_sl.cpp +++ b/src/saveload/airport_sl.cpp @@ -34,9 +34,11 @@ static void Load_ATID() Load_NewGRFMapping(_airporttile_mngr); } -static const ChunkHandler airport_chunk_handlers[] = { - { 'ATID', Save_ATID, Load_ATID, nullptr, nullptr, CH_TABLE }, - { 'APID', Save_APID, Load_APID, nullptr, nullptr, CH_TABLE }, +static const ChunkHandler ATID{ 'ATID', Save_ATID, Load_ATID, nullptr, nullptr, CH_TABLE }; +static const ChunkHandler APID{ 'APID', Save_APID, Load_APID, nullptr, nullptr, CH_TABLE }; +static const ChunkHandlerRef airport_chunk_handlers[] = { + ATID, + APID, }; extern const ChunkHandlerTable _airport_chunk_handlers(airport_chunk_handlers); diff --git a/src/saveload/animated_tile_sl.cpp b/src/saveload/animated_tile_sl.cpp index 50fe05df2..607c2ed97 100644 --- a/src/saveload/animated_tile_sl.cpp +++ b/src/saveload/animated_tile_sl.cpp @@ -68,8 +68,9 @@ static void Load_ANIT() if (SlIterateArray() != -1) SlErrorCorrupt("Too many ANIT entries"); } -static const ChunkHandler animated_tile_chunk_handlers[] = { - { 'ANIT', Save_ANIT, Load_ANIT, nullptr, nullptr, CH_TABLE }, +static const ChunkHandler ANIT{ 'ANIT', Save_ANIT, Load_ANIT, nullptr, nullptr, CH_TABLE }; +static const ChunkHandlerRef animated_tile_chunk_handlers[] = { + ANIT, }; extern const ChunkHandlerTable _animated_tile_chunk_handlers(animated_tile_chunk_handlers); diff --git a/src/saveload/autoreplace_sl.cpp b/src/saveload/autoreplace_sl.cpp index 2c848c96d..388246833 100644 --- a/src/saveload/autoreplace_sl.cpp +++ b/src/saveload/autoreplace_sl.cpp @@ -61,8 +61,9 @@ static void Ptrs_ERNW() } } -static const ChunkHandler autoreplace_chunk_handlers[] = { - { 'ERNW', Save_ERNW, Load_ERNW, Ptrs_ERNW, nullptr, CH_TABLE }, +static const ChunkHandler ERNW{ 'ERNW', Save_ERNW, Load_ERNW, Ptrs_ERNW, nullptr, CH_TABLE }; +static const ChunkHandlerRef autoreplace_chunk_handlers[] = { + ERNW, }; extern const ChunkHandlerTable _autoreplace_chunk_handlers(autoreplace_chunk_handlers); diff --git a/src/saveload/cargomonitor_sl.cpp b/src/saveload/cargomonitor_sl.cpp index e00d38332..b660609b5 100644 --- a/src/saveload/cargomonitor_sl.cpp +++ b/src/saveload/cargomonitor_sl.cpp @@ -127,9 +127,11 @@ static void LoadPickup() } /** Chunk definition of the cargomonitoring maps. */ -extern const ChunkHandler cargomonitor_chunk_handlers[] = { - { 'CMDL', SaveDelivery, LoadDelivery, nullptr, nullptr, CH_TABLE }, - { 'CMPU', SavePickup, LoadPickup, nullptr, nullptr, CH_TABLE }, +static const ChunkHandler CMDL{ 'CMDL', SaveDelivery, LoadDelivery, nullptr, nullptr, CH_TABLE }; +static const ChunkHandler CMPU{ 'CMPU', SavePickup, LoadPickup, nullptr, nullptr, CH_TABLE }; +static const ChunkHandlerRef cargomonitor_chunk_handlers[] = { + CMDL, + CMPU, }; extern const ChunkHandlerTable _cargomonitor_chunk_handlers(cargomonitor_chunk_handlers); diff --git a/src/saveload/cargopacket_sl.cpp b/src/saveload/cargopacket_sl.cpp index def62a7b9..c37d6434b 100644 --- a/src/saveload/cargopacket_sl.cpp +++ b/src/saveload/cargopacket_sl.cpp @@ -128,8 +128,9 @@ static void Load_CAPA() } } -static const ChunkHandler cargopacket_chunk_handlers[] = { - { 'CAPA', Save_CAPA, Load_CAPA, nullptr, nullptr, CH_TABLE }, +static const ChunkHandler CAPA{ 'CAPA', Save_CAPA, Load_CAPA, nullptr, nullptr, CH_TABLE }; +static const ChunkHandlerRef cargopacket_chunk_handlers[] = { + CAPA, }; extern const ChunkHandlerTable _cargopacket_chunk_handlers(cargopacket_chunk_handlers); diff --git a/src/saveload/cheat_sl.cpp b/src/saveload/cheat_sl.cpp index cef8b7e90..f68b5a5a5 100644 --- a/src/saveload/cheat_sl.cpp +++ b/src/saveload/cheat_sl.cpp @@ -75,8 +75,9 @@ static void Load_CHTS() if (!IsSavegameVersionBefore(SLV_RIFF_TO_ARRAY) && SlIterateArray() != -1) SlErrorCorrupt("Too many CHTS entries"); } -static const ChunkHandler cheat_chunk_handlers[] = { - { 'CHTS', Save_CHTS, Load_CHTS, nullptr, nullptr, CH_TABLE }, +static const ChunkHandler CHTS{ 'CHTS', Save_CHTS, Load_CHTS, nullptr, nullptr, CH_TABLE }; +static const ChunkHandlerRef cheat_chunk_handlers[] = { + CHTS, }; extern const ChunkHandlerTable _cheat_chunk_handlers(cheat_chunk_handlers); diff --git a/src/saveload/company_sl.cpp b/src/saveload/company_sl.cpp index 073868865..b4dfd1350 100644 --- a/src/saveload/company_sl.cpp +++ b/src/saveload/company_sl.cpp @@ -557,9 +557,9 @@ static void Ptrs_PLYR() } } - -static const ChunkHandler company_chunk_handlers[] = { - { 'PLYR', Save_PLYR, Load_PLYR, Ptrs_PLYR, Check_PLYR, CH_TABLE }, +static const ChunkHandler PLYR{ 'PLYR', Save_PLYR, Load_PLYR, Ptrs_PLYR, Check_PLYR, CH_TABLE }; +static const ChunkHandlerRef company_chunk_handlers[] = { + PLYR, }; extern const ChunkHandlerTable _company_chunk_handlers(company_chunk_handlers); diff --git a/src/saveload/depot_sl.cpp b/src/saveload/depot_sl.cpp index c1252562a..b34108c21 100644 --- a/src/saveload/depot_sl.cpp +++ b/src/saveload/depot_sl.cpp @@ -62,8 +62,9 @@ static void Ptrs_DEPT() } } -static const ChunkHandler depot_chunk_handlers[] = { - { 'DEPT', Save_DEPT, Load_DEPT, Ptrs_DEPT, nullptr, CH_TABLE }, +static const ChunkHandler DEPT{ 'DEPT', Save_DEPT, Load_DEPT, Ptrs_DEPT, nullptr, CH_TABLE }; +static const ChunkHandlerRef depot_chunk_handlers[] = { + DEPT, }; extern const ChunkHandlerTable _depot_chunk_handlers(depot_chunk_handlers); diff --git a/src/saveload/economy_sl.cpp b/src/saveload/economy_sl.cpp index 4d7890b4b..277901845 100644 --- a/src/saveload/economy_sl.cpp +++ b/src/saveload/economy_sl.cpp @@ -105,12 +105,15 @@ static void Ptrs_CAPY() } } - -static const ChunkHandler economy_chunk_handlers[] = { - { 'CAPY', Save_CAPY, Load_CAPY, Ptrs_CAPY, nullptr, CH_TABLE }, - { 'PRIC', nullptr, Load_PRIC, nullptr, nullptr, CH_READONLY }, - { 'CAPR', nullptr, Load_CAPR, nullptr, nullptr, CH_READONLY }, - { 'ECMY', Save_ECMY, Load_ECMY, nullptr, nullptr, CH_TABLE }, +static const ChunkHandler CAPY{ 'CAPY', Save_CAPY, Load_CAPY, Ptrs_CAPY, nullptr, CH_TABLE }; +static const ChunkHandler PRIC{ 'PRIC', nullptr, Load_PRIC, nullptr, nullptr, CH_READONLY }; +static const ChunkHandler CAPR{ 'CAPR', nullptr, Load_CAPR, nullptr, nullptr, CH_READONLY }; +static const ChunkHandler ECMY{ 'ECMY', Save_ECMY, Load_ECMY, nullptr, nullptr, CH_TABLE }; +static const ChunkHandlerRef economy_chunk_handlers[] = { + CAPY, + PRIC, + CAPR, + ECMY, }; extern const ChunkHandlerTable _economy_chunk_handlers(economy_chunk_handlers); diff --git a/src/saveload/engine_sl.cpp b/src/saveload/engine_sl.cpp index 109d90434..aca046ec1 100644 --- a/src/saveload/engine_sl.cpp +++ b/src/saveload/engine_sl.cpp @@ -199,10 +199,13 @@ static void Load_EIDS() } } -static const ChunkHandler engine_chunk_handlers[] = { - { 'EIDS', Save_EIDS, Load_EIDS, nullptr, nullptr, CH_TABLE }, - { 'ENGN', Save_ENGN, Load_ENGN, nullptr, nullptr, CH_TABLE }, - { 'ENGS', nullptr, Load_ENGS, nullptr, nullptr, CH_READONLY }, +static const ChunkHandler EIDS{ 'EIDS', Save_EIDS, Load_EIDS, nullptr, nullptr, CH_TABLE }; +static const ChunkHandler ENGN{ 'ENGN', Save_ENGN, Load_ENGN, nullptr, nullptr, CH_TABLE }; +static const ChunkHandler ENGS{ 'ENGS', nullptr, Load_ENGS, nullptr, nullptr, CH_READONLY }; +static const ChunkHandlerRef engine_chunk_handlers[] = { + EIDS, + ENGN, + ENGS, }; extern const ChunkHandlerTable _engine_chunk_handlers(engine_chunk_handlers); diff --git a/src/saveload/game_sl.cpp b/src/saveload/game_sl.cpp index f0083cb88..e075326ae 100644 --- a/src/saveload/game_sl.cpp +++ b/src/saveload/game_sl.cpp @@ -188,9 +188,11 @@ static void Save_GSTR() } } -static const ChunkHandler game_chunk_handlers[] = { - { 'GSTR', Save_GSTR, Load_GSTR, nullptr, nullptr, CH_TABLE }, - { 'GSDT', Save_GSDT, Load_GSDT, nullptr, nullptr, CH_TABLE }, +static const ChunkHandler GSTR{ 'GSTR', Save_GSTR, Load_GSTR, nullptr, nullptr, CH_TABLE }; +static const ChunkHandler GSDT{ 'GSDT', Save_GSDT, Load_GSDT, nullptr, nullptr, CH_TABLE }; +static const ChunkHandlerRef game_chunk_handlers[] = { + GSTR, + GSDT, }; extern const ChunkHandlerTable _game_chunk_handlers(game_chunk_handlers); diff --git a/src/saveload/gamelog_sl.cpp b/src/saveload/gamelog_sl.cpp index 8cc81c8cf..d2ca49aed 100644 --- a/src/saveload/gamelog_sl.cpp +++ b/src/saveload/gamelog_sl.cpp @@ -401,8 +401,9 @@ static void Check_GLOG() Load_GLOG_common(_load_check_data.gamelog_action, _load_check_data.gamelog_actions); } -static const ChunkHandler gamelog_chunk_handlers[] = { - { 'GLOG', Save_GLOG, Load_GLOG, nullptr, Check_GLOG, CH_TABLE } +static const ChunkHandler GLOG{ 'GLOG', Save_GLOG, Load_GLOG, nullptr, Check_GLOG, CH_TABLE }; +static const ChunkHandlerRef gamelog_chunk_handlers[] = { + GLOG, }; extern const ChunkHandlerTable _gamelog_chunk_handlers(gamelog_chunk_handlers); diff --git a/src/saveload/goal_sl.cpp b/src/saveload/goal_sl.cpp index 7e2cad491..2dac477d0 100644 --- a/src/saveload/goal_sl.cpp +++ b/src/saveload/goal_sl.cpp @@ -46,8 +46,9 @@ static void Load_GOAL() } } -static const ChunkHandler goal_chunk_handlers[] = { - { 'GOAL', Save_GOAL, Load_GOAL, nullptr, nullptr, CH_TABLE }, +static const ChunkHandler GOAL{ 'GOAL', Save_GOAL, Load_GOAL, nullptr, nullptr, CH_TABLE }; +static const ChunkHandlerRef goal_chunk_handlers[] = { + GOAL, }; extern const ChunkHandlerTable _goal_chunk_handlers(goal_chunk_handlers); diff --git a/src/saveload/group_sl.cpp b/src/saveload/group_sl.cpp index 77ab23bd8..6c510b6e6 100644 --- a/src/saveload/group_sl.cpp +++ b/src/saveload/group_sl.cpp @@ -59,8 +59,9 @@ static void Load_GRPS() } } -static const ChunkHandler group_chunk_handlers[] = { - { 'GRPS', Save_GRPS, Load_GRPS, nullptr, nullptr, CH_TABLE }, +static const ChunkHandler GRPS{ 'GRPS', Save_GRPS, Load_GRPS, nullptr, nullptr, CH_TABLE }; +static const ChunkHandlerRef group_chunk_handlers[] = { + GRPS, }; extern const ChunkHandlerTable _group_chunk_handlers(group_chunk_handlers); diff --git a/src/saveload/industry_sl.cpp b/src/saveload/industry_sl.cpp index 1be1ad219..e1d2da93a 100644 --- a/src/saveload/industry_sl.cpp +++ b/src/saveload/industry_sl.cpp @@ -194,12 +194,17 @@ static void Load_ITBL() } } -static const ChunkHandler industry_chunk_handlers[] = { - { 'INDY', Save_INDY, Load_INDY, Ptrs_INDY, nullptr, CH_TABLE }, - { 'IIDS', Save_IIDS, Load_IIDS, nullptr, nullptr, CH_TABLE }, - { 'TIDS', Save_TIDS, Load_TIDS, nullptr, nullptr, CH_TABLE }, - { 'IBLD', Save_IBLD, Load_IBLD, nullptr, nullptr, CH_TABLE }, - { 'ITBL', Save_ITBL, Load_ITBL, nullptr, nullptr, CH_TABLE }, +static const ChunkHandler INDY{ 'INDY', Save_INDY, Load_INDY, Ptrs_INDY, nullptr, CH_TABLE }; +static const ChunkHandler IIDS{ 'IIDS', Save_IIDS, Load_IIDS, nullptr, nullptr, CH_TABLE }; +static const ChunkHandler TIDS{ 'TIDS', Save_TIDS, Load_TIDS, nullptr, nullptr, CH_TABLE }; +static const ChunkHandler IBLD{ 'IBLD', Save_IBLD, Load_IBLD, nullptr, nullptr, CH_TABLE }; +static const ChunkHandler ITBL{ 'ITBL', Save_ITBL, Load_ITBL, nullptr, nullptr, CH_TABLE }; +static const ChunkHandlerRef industry_chunk_handlers[] = { + INDY, + IIDS, + TIDS, + IBLD, + ITBL, }; extern const ChunkHandlerTable _industry_chunk_handlers(industry_chunk_handlers); diff --git a/src/saveload/labelmaps_sl.cpp b/src/saveload/labelmaps_sl.cpp index 6b8509b53..970985b92 100644 --- a/src/saveload/labelmaps_sl.cpp +++ b/src/saveload/labelmaps_sl.cpp @@ -127,8 +127,9 @@ static void Load_RAIL() } } -static const ChunkHandler labelmaps_chunk_handlers[] = { - { 'RAIL', Save_RAIL, Load_RAIL, nullptr, nullptr, CH_TABLE }, +static const ChunkHandler RAIL{ 'RAIL', Save_RAIL, Load_RAIL, nullptr, nullptr, CH_TABLE }; +static const ChunkHandlerRef labelmaps_chunk_handlers[] = { + RAIL, }; extern const ChunkHandlerTable _labelmaps_chunk_handlers(labelmaps_chunk_handlers); diff --git a/src/saveload/linkgraph_sl.cpp b/src/saveload/linkgraph_sl.cpp index 952ae1de3..04664bed9 100644 --- a/src/saveload/linkgraph_sl.cpp +++ b/src/saveload/linkgraph_sl.cpp @@ -326,10 +326,13 @@ static void Ptrs_LGRS() SlObject(&LinkGraphSchedule::instance, GetLinkGraphScheduleDesc()); } -static const ChunkHandler linkgraph_chunk_handlers[] = { - { 'LGRP', Save_LGRP, Load_LGRP, nullptr, nullptr, CH_TABLE }, - { 'LGRJ', Save_LGRJ, Load_LGRJ, nullptr, nullptr, CH_TABLE }, - { 'LGRS', Save_LGRS, Load_LGRS, Ptrs_LGRS, nullptr, CH_TABLE }, +static const ChunkHandler LGRP{ 'LGRP', Save_LGRP, Load_LGRP, nullptr, nullptr, CH_TABLE }; +static const ChunkHandler LGRJ{ 'LGRJ', Save_LGRJ, Load_LGRJ, nullptr, nullptr, CH_TABLE }; +static const ChunkHandler LGRS{ 'LGRS', Save_LGRS, Load_LGRS, Ptrs_LGRS, nullptr, CH_TABLE }; +static const ChunkHandlerRef linkgraph_chunk_handlers[] = { + LGRP, + LGRJ, + LGRS, }; extern const ChunkHandlerTable _linkgraph_chunk_handlers(linkgraph_chunk_handlers); diff --git a/src/saveload/map_sl.cpp b/src/saveload/map_sl.cpp index e55ac665a..a6f9448e5 100644 --- a/src/saveload/map_sl.cpp +++ b/src/saveload/map_sl.cpp @@ -309,19 +309,29 @@ static void Save_MAP8() } } - -static const ChunkHandler map_chunk_handlers[] = { - { 'MAPS', Save_MAPS, Load_MAPS, nullptr, Check_MAPS, CH_TABLE }, - { 'MAPT', Save_MAPT, Load_MAPT, nullptr, nullptr, CH_RIFF }, - { 'MAPH', Save_MAPH, Load_MAPH, nullptr, nullptr, CH_RIFF }, - { 'MAPO', Save_MAP1, Load_MAP1, nullptr, nullptr, CH_RIFF }, - { 'MAP2', Save_MAP2, Load_MAP2, nullptr, nullptr, CH_RIFF }, - { 'M3LO', Save_MAP3, Load_MAP3, nullptr, nullptr, CH_RIFF }, - { 'M3HI', Save_MAP4, Load_MAP4, nullptr, nullptr, CH_RIFF }, - { 'MAP5', Save_MAP5, Load_MAP5, nullptr, nullptr, CH_RIFF }, - { 'MAPE', Save_MAP6, Load_MAP6, nullptr, nullptr, CH_RIFF }, - { 'MAP7', Save_MAP7, Load_MAP7, nullptr, nullptr, CH_RIFF }, - { 'MAP8', Save_MAP8, Load_MAP8, nullptr, nullptr, CH_RIFF }, +static const ChunkHandler MAPS{ 'MAPS', Save_MAPS, Load_MAPS, nullptr, Check_MAPS, CH_TABLE }; +static const ChunkHandler MAPT{ 'MAPT', Save_MAPT, Load_MAPT, nullptr, nullptr, CH_RIFF }; +static const ChunkHandler MAPH{ 'MAPH', Save_MAPH, Load_MAPH, nullptr, nullptr, CH_RIFF }; +static const ChunkHandler MAPO{ 'MAPO', Save_MAP1, Load_MAP1, nullptr, nullptr, CH_RIFF }; +static const ChunkHandler MAP2{ 'MAP2', Save_MAP2, Load_MAP2, nullptr, nullptr, CH_RIFF }; +static const ChunkHandler M3LO{ 'M3LO', Save_MAP3, Load_MAP3, nullptr, nullptr, CH_RIFF }; +static const ChunkHandler M3HI{ 'M3HI', Save_MAP4, Load_MAP4, nullptr, nullptr, CH_RIFF }; +static const ChunkHandler MAP5{ 'MAP5', Save_MAP5, Load_MAP5, nullptr, nullptr, CH_RIFF }; +static const ChunkHandler MAPE{ 'MAPE', Save_MAP6, Load_MAP6, nullptr, nullptr, CH_RIFF }; +static const ChunkHandler MAP7{ 'MAP7', Save_MAP7, Load_MAP7, nullptr, nullptr, CH_RIFF }; +static const ChunkHandler MAP8{ 'MAP8', Save_MAP8, Load_MAP8, nullptr, nullptr, CH_RIFF }; +static const ChunkHandlerRef map_chunk_handlers[] = { + MAPS, + MAPT, + MAPH, + MAPO, + MAP2, + M3LO, + M3HI, + MAP5, + MAPE, + MAP7, + MAP8, }; extern const ChunkHandlerTable _map_chunk_handlers(map_chunk_handlers); diff --git a/src/saveload/misc_sl.cpp b/src/saveload/misc_sl.cpp index 35b59a021..a742090e8 100644 --- a/src/saveload/misc_sl.cpp +++ b/src/saveload/misc_sl.cpp @@ -152,9 +152,11 @@ static void Load_VIEW() if (!IsSavegameVersionBefore(SLV_RIFF_TO_ARRAY) && SlIterateArray() != -1) SlErrorCorrupt("Too many DATE entries"); } -static const ChunkHandler misc_chunk_handlers[] = { - { 'DATE', Save_DATE, Load_DATE, nullptr, Check_DATE, CH_TABLE }, - { 'VIEW', Save_VIEW, Load_VIEW, nullptr, nullptr, CH_TABLE }, +static const ChunkHandler DATE{ 'DATE', Save_DATE, Load_DATE, nullptr, Check_DATE, CH_TABLE }; +static const ChunkHandler VIEW{ 'VIEW', Save_VIEW, Load_VIEW, nullptr, nullptr, CH_TABLE }; +static const ChunkHandlerRef misc_chunk_handlers[] = { + DATE, + VIEW, }; extern const ChunkHandlerTable _misc_chunk_handlers(misc_chunk_handlers); diff --git a/src/saveload/newgrf_sl.cpp b/src/saveload/newgrf_sl.cpp index 20b658562..10a65e936 100644 --- a/src/saveload/newgrf_sl.cpp +++ b/src/saveload/newgrf_sl.cpp @@ -121,8 +121,9 @@ static void Check_NGRF() Load_NGRF_common(_load_check_data.grfconfig); } -static const ChunkHandler newgrf_chunk_handlers[] = { - { 'NGRF', Save_NGRF, Load_NGRF, nullptr, Check_NGRF, CH_TABLE } +static const ChunkHandler NGRF{ 'NGRF', Save_NGRF, Load_NGRF, nullptr, Check_NGRF, CH_TABLE }; +static const ChunkHandlerRef newgrf_chunk_handlers[] = { + NGRF, }; extern const ChunkHandlerTable _newgrf_chunk_handlers(newgrf_chunk_handlers); diff --git a/src/saveload/object_sl.cpp b/src/saveload/object_sl.cpp index 57e34af3a..b970c3934 100644 --- a/src/saveload/object_sl.cpp +++ b/src/saveload/object_sl.cpp @@ -72,9 +72,11 @@ static void Load_OBID() Load_NewGRFMapping(_object_mngr); } -static const ChunkHandler object_chunk_handlers[] = { - { 'OBID', Save_OBID, Load_OBID, nullptr, nullptr, CH_TABLE }, - { 'OBJS', Save_OBJS, Load_OBJS, Ptrs_OBJS, nullptr, CH_TABLE }, +static const ChunkHandler OBID{ 'OBID', Save_OBID, Load_OBID, nullptr, nullptr, CH_TABLE }; +static const ChunkHandler OBJS{ 'OBJS', Save_OBJS, Load_OBJS, Ptrs_OBJS, nullptr, CH_TABLE }; +static const ChunkHandlerRef object_chunk_handlers[] = { + OBID, + OBJS, }; extern const ChunkHandlerTable _object_chunk_handlers(object_chunk_handlers); diff --git a/src/saveload/order_sl.cpp b/src/saveload/order_sl.cpp index 4d9bf3d8f..797c16d1b 100644 --- a/src/saveload/order_sl.cpp +++ b/src/saveload/order_sl.cpp @@ -298,10 +298,13 @@ static void Ptrs_BKOR() } } -static const ChunkHandler order_chunk_handlers[] = { - { 'BKOR', Save_BKOR, Load_BKOR, Ptrs_BKOR, nullptr, CH_TABLE }, - { 'ORDR', Save_ORDR, Load_ORDR, Ptrs_ORDR, nullptr, CH_TABLE }, - { 'ORDL', Save_ORDL, Load_ORDL, Ptrs_ORDL, nullptr, CH_TABLE }, +static const ChunkHandler BKOR{ 'BKOR', Save_BKOR, Load_BKOR, Ptrs_BKOR, nullptr, CH_TABLE }; +static const ChunkHandler ORDR{ 'ORDR', Save_ORDR, Load_ORDR, Ptrs_ORDR, nullptr, CH_TABLE }; +static const ChunkHandler ORDL{ 'ORDL', Save_ORDL, Load_ORDL, Ptrs_ORDL, nullptr, CH_TABLE }; +static const ChunkHandlerRef order_chunk_handlers[] = { + BKOR, + ORDR, + ORDL, }; extern const ChunkHandlerTable _order_chunk_handlers(order_chunk_handlers); diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp index 69bbc75b1..39941c268 100644 --- a/src/saveload/saveload.cpp +++ b/src/saveload/saveload.cpp @@ -216,7 +216,7 @@ struct SaveLoadParams { static SaveLoadParams _sl; ///< Parameters used for/at saveload. -static const std::vector<ChunkHandler> &ChunkHandlers() +static const std::vector<ChunkHandlerRef> &ChunkHandlers() { /* These define the chunks */ extern const ChunkHandlerTable _gamelog_chunk_handlers; @@ -290,7 +290,7 @@ static const std::vector<ChunkHandler> &ChunkHandlers() _persistent_storage_chunk_handlers, }; - static std::vector<ChunkHandler> _chunk_handlers; + static std::vector<ChunkHandlerRef> _chunk_handlers; if (_chunk_handlers.empty()) { for (auto &chunk_handler_table : _chunk_handler_tables) { @@ -313,7 +313,7 @@ static void SlNullPointers() * pointers from other pools. */ _sl_version = SAVEGAME_VERSION; - for (auto &ch : ChunkHandlers()) { + for (const ChunkHandler &ch : ChunkHandlers()) { if (ch.fix_pointers) { Debug(sl, 3, "Nulling pointers for {:c}{:c}{:c}{:c}", ch.id >> 24, ch.id >> 16, ch.id >> 8, ch.id); ch.FixPointers(); @@ -2312,7 +2312,7 @@ static void SlSaveChunks() */ static const ChunkHandler *SlFindChunkHandler(uint32 id) { - for (auto &ch : ChunkHandlers()) if (ch.id == id) return &ch; + for (const ChunkHandler &ch : ChunkHandlers()) if (ch.id == id) return &ch; return nullptr; } @@ -2351,7 +2351,7 @@ static void SlFixPointers() { _sl.action = SLA_PTRS; - for (auto &ch : ChunkHandlers()) { + for (const ChunkHandler &ch : ChunkHandlers()) { if (ch.fix_pointers) { Debug(sl, 3, "Fixing pointers for {:c}{:c}{:c}{:c}", ch.id >> 24, ch.id >> 16, ch.id >> 8, ch.id); ch.FixPointers(); diff --git a/src/saveload/saveload.h b/src/saveload/saveload.h index 381e355e0..2f5ebba1f 100644 --- a/src/saveload/saveload.h +++ b/src/saveload/saveload.h @@ -450,8 +450,11 @@ struct ChunkHandler { virtual void LoadCheck(size_t len = 0) const; }; +/** A reference to ChunkHandler. */ +using ChunkHandlerRef = std::reference_wrapper<const ChunkHandler>; + /** A table of ChunkHandler entries. */ -using ChunkHandlerTable = span<const ChunkHandler>; +using ChunkHandlerTable = span<const ChunkHandlerRef>; /** A table of SaveLoad entries. */ using SaveLoadTable = span<const struct SaveLoad>; diff --git a/src/saveload/settings_sl.cpp b/src/saveload/settings_sl.cpp index 2097d8645..fe320db5d 100644 --- a/src/saveload/settings_sl.cpp +++ b/src/saveload/settings_sl.cpp @@ -170,9 +170,11 @@ static void Save_PATS() SaveSettings(_settings, &_settings_game); } -static const ChunkHandler setting_chunk_handlers[] = { - { 'OPTS', nullptr, Load_OPTS, nullptr, nullptr, CH_READONLY }, - { 'PATS', Save_PATS, Load_PATS, nullptr, Check_PATS, CH_TABLE }, +static const ChunkHandler OPTS{ 'OPTS', nullptr, Load_OPTS, nullptr, nullptr, CH_READONLY }; +static const ChunkHandler PATS{ 'PATS', Save_PATS, Load_PATS, nullptr, Check_PATS, CH_TABLE }; +static const ChunkHandlerRef setting_chunk_handlers[] = { + OPTS, + PATS, }; extern const ChunkHandlerTable _setting_chunk_handlers(setting_chunk_handlers); diff --git a/src/saveload/signs_sl.cpp b/src/saveload/signs_sl.cpp index 4479ff63d..21cd69f15 100644 --- a/src/saveload/signs_sl.cpp +++ b/src/saveload/signs_sl.cpp @@ -67,8 +67,9 @@ static void Load_SIGN() } } -static const ChunkHandler sign_chunk_handlers[] = { - { 'SIGN', Save_SIGN, Load_SIGN, nullptr, nullptr, CH_TABLE }, +static const ChunkHandler SIGN{ 'SIGN', Save_SIGN, Load_SIGN, nullptr, nullptr, CH_TABLE }; +static const ChunkHandlerRef sign_chunk_handlers[] = { + SIGN, }; extern const ChunkHandlerTable _sign_chunk_handlers(sign_chunk_handlers); diff --git a/src/saveload/station_sl.cpp b/src/saveload/station_sl.cpp index d9978cd6f..5662e4a46 100644 --- a/src/saveload/station_sl.cpp +++ b/src/saveload/station_sl.cpp @@ -719,10 +719,13 @@ static void Ptrs_ROADSTOP() } } -static const ChunkHandler station_chunk_handlers[] = { - { 'STNS', nullptr, Load_STNS, Ptrs_STNS, nullptr, CH_READONLY }, - { 'STNN', Save_STNN, Load_STNN, Ptrs_STNN, nullptr, CH_TABLE }, - { 'ROAD', Save_ROADSTOP, Load_ROADSTOP, Ptrs_ROADSTOP, nullptr, CH_TABLE }, +static const ChunkHandler STNS{ 'STNS', nullptr, Load_STNS, Ptrs_STNS, nullptr, CH_READONLY }; +static const ChunkHandler STNN{ 'STNN', Save_STNN, Load_STNN, Ptrs_STNN, nullptr, CH_TABLE }; +static const ChunkHandler ROAD{ 'ROAD', Save_ROADSTOP, Load_ROADSTOP, Ptrs_ROADSTOP, nullptr, CH_TABLE }; +static const ChunkHandlerRef station_chunk_handlers[] = { + STNS, + STNN, + ROAD, }; extern const ChunkHandlerTable _station_chunk_handlers(station_chunk_handlers); diff --git a/src/saveload/storage_sl.cpp b/src/saveload/storage_sl.cpp index 4838e9f12..4a360d58d 100644 --- a/src/saveload/storage_sl.cpp +++ b/src/saveload/storage_sl.cpp @@ -50,8 +50,9 @@ static void Save_PSAC() } } -static const ChunkHandler persistent_storage_chunk_handlers[] = { - { 'PSAC', Save_PSAC, Load_PSAC, nullptr, nullptr, CH_TABLE }, +static const ChunkHandler PSAC{ 'PSAC', Save_PSAC, Load_PSAC, nullptr, nullptr, CH_TABLE }; +static const ChunkHandlerRef persistent_storage_chunk_handlers[] = { + PSAC, }; extern const ChunkHandlerTable _persistent_storage_chunk_handlers(persistent_storage_chunk_handlers); diff --git a/src/saveload/story_sl.cpp b/src/saveload/story_sl.cpp index 9dabd5cbf..6371b4162 100644 --- a/src/saveload/story_sl.cpp +++ b/src/saveload/story_sl.cpp @@ -105,9 +105,11 @@ static void Load_STORY_PAGE() _story_page_next_sort_value = max_sort_value + 1; } -static const ChunkHandler story_page_chunk_handlers[] = { - { 'STPE', Save_STORY_PAGE_ELEMENT, Load_STORY_PAGE_ELEMENT, nullptr, nullptr, CH_TABLE }, - { 'STPA', Save_STORY_PAGE, Load_STORY_PAGE, nullptr, nullptr, CH_TABLE }, +static const ChunkHandler STPE{ 'STPE', Save_STORY_PAGE_ELEMENT, Load_STORY_PAGE_ELEMENT, nullptr, nullptr, CH_TABLE }; +static const ChunkHandler STPA{ 'STPA', Save_STORY_PAGE, Load_STORY_PAGE, nullptr, nullptr, CH_TABLE }; +static const ChunkHandlerRef story_page_chunk_handlers[] = { + STPE, + STPA, }; extern const ChunkHandlerTable _story_page_chunk_handlers(story_page_chunk_handlers); diff --git a/src/saveload/strings_sl.cpp b/src/saveload/strings_sl.cpp index 70d001e73..7cad1fba6 100644 --- a/src/saveload/strings_sl.cpp +++ b/src/saveload/strings_sl.cpp @@ -130,8 +130,9 @@ static void Load_NAME() } } -static const ChunkHandler name_chunk_handlers[] = { - { 'NAME', nullptr, Load_NAME, nullptr, nullptr, CH_READONLY }, +static const ChunkHandler NAME{ 'NAME', nullptr, Load_NAME, nullptr, nullptr, CH_READONLY }; +static const ChunkHandlerRef name_chunk_handlers[] = { + NAME, }; extern const ChunkHandlerTable _name_chunk_handlers(name_chunk_handlers); diff --git a/src/saveload/subsidy_sl.cpp b/src/saveload/subsidy_sl.cpp index 0a9c25ebd..a02c19319 100644 --- a/src/saveload/subsidy_sl.cpp +++ b/src/saveload/subsidy_sl.cpp @@ -50,8 +50,9 @@ static void Load_SUBS() } } -static const ChunkHandler subsidy_chunk_handlers[] = { - { 'SUBS', Save_SUBS, Load_SUBS, nullptr, nullptr, CH_TABLE }, +static const ChunkHandler SUBS{ 'SUBS', Save_SUBS, Load_SUBS, nullptr, nullptr, CH_TABLE }; +static const ChunkHandlerRef subsidy_chunk_handlers[] = { + SUBS, }; extern const ChunkHandlerTable _subsidy_chunk_handlers(subsidy_chunk_handlers); diff --git a/src/saveload/town_sl.cpp b/src/saveload/town_sl.cpp index c5b5b0080..906940033 100644 --- a/src/saveload/town_sl.cpp +++ b/src/saveload/town_sl.cpp @@ -318,9 +318,11 @@ static void Ptrs_TOWN() } } -static const ChunkHandler town_chunk_handlers[] = { - { 'HIDS', Save_HIDS, Load_HIDS, nullptr, nullptr, CH_TABLE }, - { 'CITY', Save_TOWN, Load_TOWN, Ptrs_TOWN, nullptr, CH_TABLE }, +static const ChunkHandler HIDS{ 'HIDS', Save_HIDS, Load_HIDS, nullptr, nullptr, CH_TABLE }; +static const ChunkHandler CITY{ 'CITY', Save_TOWN, Load_TOWN, Ptrs_TOWN, nullptr, CH_TABLE }; +static const ChunkHandlerRef town_chunk_handlers[] = { + HIDS, + CITY, }; extern const ChunkHandlerTable _town_chunk_handlers(town_chunk_handlers); diff --git a/src/saveload/vehicle_sl.cpp b/src/saveload/vehicle_sl.cpp index 962f5f99a..2be5998f5 100644 --- a/src/saveload/vehicle_sl.cpp +++ b/src/saveload/vehicle_sl.cpp @@ -1064,8 +1064,9 @@ void Ptrs_VEHS() } } -static const ChunkHandler veh_chunk_handlers[] = { - { 'VEHS', Save_VEHS, Load_VEHS, Ptrs_VEHS, nullptr, CH_SPARSE_TABLE }, +static const ChunkHandler VEHS{ 'VEHS', Save_VEHS, Load_VEHS, Ptrs_VEHS, nullptr, CH_SPARSE_TABLE }; +static const ChunkHandlerRef veh_chunk_handlers[] = { + VEHS, }; extern const ChunkHandlerTable _veh_chunk_handlers(veh_chunk_handlers); diff --git a/src/saveload/waypoint_sl.cpp b/src/saveload/waypoint_sl.cpp index 8105cc190..bf22720fc 100644 --- a/src/saveload/waypoint_sl.cpp +++ b/src/saveload/waypoint_sl.cpp @@ -224,8 +224,9 @@ static void Ptrs_WAYP() } } -static const ChunkHandler waypoint_chunk_handlers[] = { - { 'CHKP', nullptr, Load_WAYP, Ptrs_WAYP, nullptr, CH_READONLY }, +static const ChunkHandler CHKP{ 'CHKP', nullptr, Load_WAYP, Ptrs_WAYP, nullptr, CH_READONLY }; +static const ChunkHandlerRef waypoint_chunk_handlers[] = { + CHKP, }; extern const ChunkHandlerTable _waypoint_chunk_handlers(waypoint_chunk_handlers); |