diff options
author | glx22 <glx@openttd.org> | 2021-05-02 22:41:34 +0200 |
---|---|---|
committer | Loïc Guilloux <glx22@users.noreply.github.com> | 2021-06-06 19:35:06 +0200 |
commit | c27afdf3f6b8e7e073b70d4935ca1c871855f3ca (patch) | |
tree | 8aa6a64805d1856c873b8a053c2d98a9d1b8585f /src/saveload | |
parent | 3559e55b9145c5b6c146003b357a158c73efee4e (diff) | |
download | openttd-c27afdf3f6b8e7e073b70d4935ca1c871855f3ca.tar.xz |
Codechange: Remove FOR_ALL_CHUNK_HANDLERS
Co-Authored-By: Patric Stout <truebrain@openttd.org>
Diffstat (limited to 'src/saveload')
34 files changed, 268 insertions, 196 deletions
diff --git a/src/saveload/ai_sl.cpp b/src/saveload/ai_sl.cpp index fcb78f2ed..7eb2a5ce1 100644 --- a/src/saveload/ai_sl.cpp +++ b/src/saveload/ai_sl.cpp @@ -120,6 +120,8 @@ static void Save_AIPL() } } -extern const ChunkHandler _ai_chunk_handlers[] = { - { 'AIPL', Save_AIPL, Load_AIPL, nullptr, nullptr, CH_ARRAY | CH_LAST}, +static const ChunkHandler ai_chunk_handlers[] = { + { 'AIPL', Save_AIPL, Load_AIPL, nullptr, nullptr, CH_ARRAY }, }; + +extern const ChunkHandlerTable _ai_chunk_handlers(ai_chunk_handlers); diff --git a/src/saveload/airport_sl.cpp b/src/saveload/airport_sl.cpp index a7470d268..114e5672a 100644 --- a/src/saveload/airport_sl.cpp +++ b/src/saveload/airport_sl.cpp @@ -34,7 +34,9 @@ static void Load_ATID() Load_NewGRFMapping(_airporttile_mngr); } -extern const ChunkHandler _airport_chunk_handlers[] = { +static const ChunkHandler airport_chunk_handlers[] = { { 'ATID', Save_ATID, Load_ATID, nullptr, nullptr, CH_ARRAY }, - { 'APID', Save_APID, Load_APID, nullptr, nullptr, CH_ARRAY | CH_LAST }, + { 'APID', Save_APID, Load_APID, nullptr, nullptr, CH_ARRAY }, }; + +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 9f03e598d..2b3842104 100644 --- a/src/saveload/animated_tile_sl.cpp +++ b/src/saveload/animated_tile_sl.cpp @@ -55,6 +55,8 @@ static void Load_ANIT() * "Definition" imported by the saveload code to be able to load and save * the animated tile table. */ -extern const ChunkHandler _animated_tile_chunk_handlers[] = { - { 'ANIT', Save_ANIT, Load_ANIT, nullptr, nullptr, CH_RIFF | CH_LAST}, +static const ChunkHandler animated_tile_chunk_handlers[] = { + { 'ANIT', Save_ANIT, Load_ANIT, nullptr, nullptr, CH_RIFF }, }; + +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 ef343fc17..f54866c10 100644 --- a/src/saveload/autoreplace_sl.cpp +++ b/src/saveload/autoreplace_sl.cpp @@ -55,6 +55,8 @@ static void Ptrs_ERNW() } } -extern const ChunkHandler _autoreplace_chunk_handlers[] = { - { 'ERNW', Save_ERNW, Load_ERNW, Ptrs_ERNW, nullptr, CH_ARRAY | CH_LAST}, +static const ChunkHandler autoreplace_chunk_handlers[] = { + { 'ERNW', Save_ERNW, Load_ERNW, Ptrs_ERNW, nullptr, CH_ARRAY }, }; + +extern const ChunkHandlerTable _autoreplace_chunk_handlers(autoreplace_chunk_handlers); diff --git a/src/saveload/cargomonitor_sl.cpp b/src/saveload/cargomonitor_sl.cpp index 3ca64d77e..abb0d59b9 100644 --- a/src/saveload/cargomonitor_sl.cpp +++ b/src/saveload/cargomonitor_sl.cpp @@ -117,7 +117,9 @@ static void LoadPickup() } /** Chunk definition of the cargomonitoring maps. */ -extern const ChunkHandler _cargomonitor_chunk_handlers[] = { - { 'CMDL', SaveDelivery, LoadDelivery, nullptr, nullptr, CH_ARRAY}, - { 'CMPU', SavePickup, LoadPickup, nullptr, nullptr, CH_ARRAY | CH_LAST}, +static const ChunkHandler cargomonitor_chunk_handlers[] = { + { 'CMDL', SaveDelivery, LoadDelivery, nullptr, nullptr, CH_ARRAY }, + { 'CMPU', SavePickup, LoadPickup, nullptr, nullptr, CH_ARRAY }, }; + +extern const ChunkHandlerTable _cargomonitor_chunk_handlers(cargomonitor_chunk_handlers); diff --git a/src/saveload/cargopacket_sl.cpp b/src/saveload/cargopacket_sl.cpp index 1b9bb5cb9..96c96cabc 100644 --- a/src/saveload/cargopacket_sl.cpp +++ b/src/saveload/cargopacket_sl.cpp @@ -126,6 +126,8 @@ static void Load_CAPA() } /** Chunk handlers related to cargo packets. */ -extern const ChunkHandler _cargopacket_chunk_handlers[] = { - { 'CAPA', Save_CAPA, Load_CAPA, nullptr, nullptr, CH_ARRAY | CH_LAST}, +static const ChunkHandler cargopacket_chunk_handlers[] = { + { 'CAPA', Save_CAPA, Load_CAPA, nullptr, nullptr, CH_ARRAY }, }; + +extern const ChunkHandlerTable _cargopacket_chunk_handlers(cargopacket_chunk_handlers); diff --git a/src/saveload/cheat_sl.cpp b/src/saveload/cheat_sl.cpp index 9af175922..970e5f3be 100644 --- a/src/saveload/cheat_sl.cpp +++ b/src/saveload/cheat_sl.cpp @@ -48,6 +48,8 @@ static void Load_CHTS() } /** Chunk handlers related to cheats. */ -extern const ChunkHandler _cheat_chunk_handlers[] = { - { 'CHTS', Save_CHTS, Load_CHTS, nullptr, nullptr, CH_RIFF | CH_LAST}, +static const ChunkHandler cheat_chunk_handlers[] = { + { 'CHTS', Save_CHTS, Load_CHTS, nullptr, nullptr, CH_RIFF }, }; + +extern const ChunkHandlerTable _cheat_chunk_handlers(cheat_chunk_handlers); diff --git a/src/saveload/company_sl.cpp b/src/saveload/company_sl.cpp index 21d02121b..4c6437638 100644 --- a/src/saveload/company_sl.cpp +++ b/src/saveload/company_sl.cpp @@ -527,6 +527,8 @@ static void Ptrs_PLYR() } -extern const ChunkHandler _company_chunk_handlers[] = { - { 'PLYR', Save_PLYR, Load_PLYR, Ptrs_PLYR, Check_PLYR, CH_ARRAY | CH_LAST}, +static const ChunkHandler company_chunk_handlers[] = { + { 'PLYR', Save_PLYR, Load_PLYR, Ptrs_PLYR, Check_PLYR, CH_ARRAY }, }; + +extern const ChunkHandlerTable _company_chunk_handlers(company_chunk_handlers); diff --git a/src/saveload/depot_sl.cpp b/src/saveload/depot_sl.cpp index fb8944dba..da195416b 100644 --- a/src/saveload/depot_sl.cpp +++ b/src/saveload/depot_sl.cpp @@ -56,6 +56,8 @@ static void Ptrs_DEPT() } } -extern const ChunkHandler _depot_chunk_handlers[] = { - { 'DEPT', Save_DEPT, Load_DEPT, Ptrs_DEPT, nullptr, CH_ARRAY | CH_LAST}, +static const ChunkHandler depot_chunk_handlers[] = { + { 'DEPT', Save_DEPT, Load_DEPT, Ptrs_DEPT, nullptr, CH_ARRAY }, }; + +extern const ChunkHandlerTable _depot_chunk_handlers(depot_chunk_handlers); diff --git a/src/saveload/economy_sl.cpp b/src/saveload/economy_sl.cpp index 2c785d554..b51151c14 100644 --- a/src/saveload/economy_sl.cpp +++ b/src/saveload/economy_sl.cpp @@ -94,9 +94,11 @@ static void Ptrs_CAPY() } -extern const ChunkHandler _economy_chunk_handlers[] = { - { 'CAPY', Save_CAPY, Load_CAPY, Ptrs_CAPY, nullptr, CH_ARRAY}, - { 'PRIC', nullptr, Load_PRIC, nullptr, nullptr, CH_RIFF }, - { 'CAPR', nullptr, Load_CAPR, nullptr, nullptr, CH_RIFF }, - { 'ECMY', Save_ECMY, Load_ECMY, nullptr, nullptr, CH_RIFF | CH_LAST}, +static const ChunkHandler economy_chunk_handlers[] = { + { 'CAPY', Save_CAPY, Load_CAPY, Ptrs_CAPY, nullptr, CH_ARRAY }, + { 'PRIC', nullptr, Load_PRIC, nullptr, nullptr, CH_RIFF }, + { 'CAPR', nullptr, Load_CAPR, nullptr, nullptr, CH_RIFF }, + { 'ECMY', Save_ECMY, Load_ECMY, nullptr, nullptr, CH_RIFF }, }; + +extern const ChunkHandlerTable _economy_chunk_handlers(economy_chunk_handlers); diff --git a/src/saveload/engine_sl.cpp b/src/saveload/engine_sl.cpp index eea3a0bcf..430ae29d1 100644 --- a/src/saveload/engine_sl.cpp +++ b/src/saveload/engine_sl.cpp @@ -193,8 +193,10 @@ static void Load_EIDS() } } -extern const ChunkHandler _engine_chunk_handlers[] = { - { 'EIDS', Save_EIDS, Load_EIDS, nullptr, nullptr, CH_ARRAY }, - { 'ENGN', Save_ENGN, Load_ENGN, nullptr, nullptr, CH_ARRAY }, - { 'ENGS', nullptr, Load_ENGS, nullptr, nullptr, CH_RIFF | CH_LAST }, +static const ChunkHandler engine_chunk_handlers[] = { + { 'EIDS', Save_EIDS, Load_EIDS, nullptr, nullptr, CH_ARRAY }, + { 'ENGN', Save_ENGN, Load_ENGN, nullptr, nullptr, CH_ARRAY }, + { 'ENGS', nullptr, Load_ENGS, nullptr, nullptr, CH_RIFF }, }; + +extern const ChunkHandlerTable _engine_chunk_handlers(engine_chunk_handlers); diff --git a/src/saveload/game_sl.cpp b/src/saveload/game_sl.cpp index 055a5fbfc..4034df3c9 100644 --- a/src/saveload/game_sl.cpp +++ b/src/saveload/game_sl.cpp @@ -173,7 +173,9 @@ static void Save_GSTR() } } -extern const ChunkHandler _game_chunk_handlers[] = { +static const ChunkHandler game_chunk_handlers[] = { { 'GSTR', Save_GSTR, Load_GSTR, nullptr, nullptr, CH_ARRAY }, - { 'GSDT', Save_GSDT, Load_GSDT, nullptr, nullptr, CH_ARRAY | CH_LAST}, + { 'GSDT', Save_GSDT, Load_GSDT, nullptr, nullptr, CH_ARRAY }, }; + +extern const ChunkHandlerTable _game_chunk_handlers(game_chunk_handlers); diff --git a/src/saveload/gamelog_sl.cpp b/src/saveload/gamelog_sl.cpp index 3d236b136..6569954f8 100644 --- a/src/saveload/gamelog_sl.cpp +++ b/src/saveload/gamelog_sl.cpp @@ -168,6 +168,8 @@ static void Check_GLOG() Load_GLOG_common(_load_check_data.gamelog_action, _load_check_data.gamelog_actions); } -extern const ChunkHandler _gamelog_chunk_handlers[] = { - { 'GLOG', Save_GLOG, Load_GLOG, nullptr, Check_GLOG, CH_RIFF | CH_LAST } +static const ChunkHandler gamelog_chunk_handlers[] = { + { 'GLOG', Save_GLOG, Load_GLOG, nullptr, Check_GLOG, CH_RIFF } }; + +extern const ChunkHandlerTable _gamelog_chunk_handlers(gamelog_chunk_handlers); diff --git a/src/saveload/goal_sl.cpp b/src/saveload/goal_sl.cpp index 2c9d8fde9..2f6679759 100644 --- a/src/saveload/goal_sl.cpp +++ b/src/saveload/goal_sl.cpp @@ -40,6 +40,8 @@ static void Load_GOAL() } } -extern const ChunkHandler _goal_chunk_handlers[] = { - { 'GOAL', Save_GOAL, Load_GOAL, nullptr, nullptr, CH_ARRAY | CH_LAST}, +static const ChunkHandler goal_chunk_handlers[] = { + { 'GOAL', Save_GOAL, Load_GOAL, nullptr, nullptr, CH_ARRAY }, }; + +extern const ChunkHandlerTable _goal_chunk_handlers(goal_chunk_handlers); diff --git a/src/saveload/group_sl.cpp b/src/saveload/group_sl.cpp index a6ae263f9..f41091611 100644 --- a/src/saveload/group_sl.cpp +++ b/src/saveload/group_sl.cpp @@ -55,6 +55,8 @@ static void Load_GRPS() } } -extern const ChunkHandler _group_chunk_handlers[] = { - { 'GRPS', Save_GRPS, Load_GRPS, nullptr, nullptr, CH_ARRAY | CH_LAST}, +static const ChunkHandler group_chunk_handlers[] = { + { 'GRPS', Save_GRPS, Load_GRPS, nullptr, nullptr, CH_ARRAY }, }; + +extern const ChunkHandlerTable _group_chunk_handlers(group_chunk_handlers); diff --git a/src/saveload/industry_sl.cpp b/src/saveload/industry_sl.cpp index a59524de6..c75674069 100644 --- a/src/saveload/industry_sl.cpp +++ b/src/saveload/industry_sl.cpp @@ -176,10 +176,12 @@ static void Load_ITBL() } } -extern const ChunkHandler _industry_chunk_handlers[] = { - { 'INDY', Save_INDY, Load_INDY, Ptrs_INDY, nullptr, CH_ARRAY}, - { 'IIDS', Save_IIDS, Load_IIDS, nullptr, nullptr, CH_ARRAY}, - { 'TIDS', Save_TIDS, Load_TIDS, nullptr, nullptr, CH_ARRAY}, - { 'IBLD', LoadSave_IBLD, LoadSave_IBLD, nullptr, nullptr, CH_RIFF}, - { 'ITBL', Save_ITBL, Load_ITBL, nullptr, nullptr, CH_ARRAY | CH_LAST}, +static const ChunkHandler industry_chunk_handlers[] = { + { 'INDY', Save_INDY, Load_INDY, Ptrs_INDY, nullptr, CH_ARRAY }, + { 'IIDS', Save_IIDS, Load_IIDS, nullptr, nullptr, CH_ARRAY }, + { 'TIDS', Save_TIDS, Load_TIDS, nullptr, nullptr, CH_ARRAY }, + { 'IBLD', LoadSave_IBLD, LoadSave_IBLD, nullptr, nullptr, CH_RIFF }, + { 'ITBL', Save_ITBL, Load_ITBL, nullptr, nullptr, CH_ARRAY }, }; + +extern const ChunkHandlerTable _industry_chunk_handlers(industry_chunk_handlers); diff --git a/src/saveload/labelmaps_sl.cpp b/src/saveload/labelmaps_sl.cpp index 6c2cd1bca..5a7d6fae9 100644 --- a/src/saveload/labelmaps_sl.cpp +++ b/src/saveload/labelmaps_sl.cpp @@ -121,7 +121,9 @@ static void Load_RAIL() } } -extern const ChunkHandler _labelmaps_chunk_handlers[] = { - { 'RAIL', Save_RAIL, Load_RAIL, nullptr, nullptr, CH_ARRAY | CH_LAST}, +static const ChunkHandler labelmaps_chunk_handlers[] = { + { 'RAIL', Save_RAIL, Load_RAIL, nullptr, nullptr, CH_ARRAY }, }; +extern const ChunkHandlerTable _labelmaps_chunk_handlers(labelmaps_chunk_handlers); + diff --git a/src/saveload/linkgraph_sl.cpp b/src/saveload/linkgraph_sl.cpp index 398300028..470d00be4 100644 --- a/src/saveload/linkgraph_sl.cpp +++ b/src/saveload/linkgraph_sl.cpp @@ -280,8 +280,10 @@ static void Ptrs_LGRS() SlObject(&LinkGraphSchedule::instance, GetLinkGraphScheduleDesc()); } -extern const ChunkHandler _linkgraph_chunk_handlers[] = { +static const ChunkHandler linkgraph_chunk_handlers[] = { { 'LGRP', Save_LGRP, Load_LGRP, nullptr, nullptr, CH_ARRAY }, { 'LGRJ', Save_LGRJ, Load_LGRJ, nullptr, nullptr, CH_ARRAY }, - { 'LGRS', Save_LGRS, Load_LGRS, Ptrs_LGRS, nullptr, CH_LAST } + { 'LGRS', Save_LGRS, Load_LGRS, Ptrs_LGRS, nullptr, CH_RIFF } }; + +extern const ChunkHandlerTable _linkgraph_chunk_handlers(linkgraph_chunk_handlers); diff --git a/src/saveload/map_sl.cpp b/src/saveload/map_sl.cpp index d08fc6389..d13900fc6 100644 --- a/src/saveload/map_sl.cpp +++ b/src/saveload/map_sl.cpp @@ -294,7 +294,7 @@ static void Save_MAP8() } -extern const ChunkHandler _map_chunk_handlers[] = { +static const ChunkHandler map_chunk_handlers[] = { { 'MAPS', Save_MAPS, Load_MAPS, nullptr, Check_MAPS, CH_RIFF }, { 'MAPT', Save_MAPT, Load_MAPT, nullptr, nullptr, CH_RIFF }, { 'MAPH', Save_MAPH, Load_MAPH, nullptr, nullptr, CH_RIFF }, @@ -305,5 +305,7 @@ extern const ChunkHandler _map_chunk_handlers[] = { { '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 | CH_LAST }, + { 'MAP8', Save_MAP8, Load_MAP8, nullptr, nullptr, CH_RIFF }, }; + +extern const ChunkHandlerTable _map_chunk_handlers(map_chunk_handlers); diff --git a/src/saveload/misc_sl.cpp b/src/saveload/misc_sl.cpp index ba49c11be..027d68bae 100644 --- a/src/saveload/misc_sl.cpp +++ b/src/saveload/misc_sl.cpp @@ -145,7 +145,9 @@ static void SaveLoad_VIEW() SlGlobList(_view_desc); } -extern const ChunkHandler _misc_chunk_handlers[] = { - { 'DATE', SaveLoad_DATE, SaveLoad_DATE, nullptr, Check_DATE, CH_RIFF}, - { 'VIEW', SaveLoad_VIEW, SaveLoad_VIEW, nullptr, nullptr, CH_RIFF | CH_LAST}, +static const ChunkHandler misc_chunk_handlers[] = { + { 'DATE', SaveLoad_DATE, SaveLoad_DATE, nullptr, Check_DATE, CH_RIFF }, + { 'VIEW', SaveLoad_VIEW, SaveLoad_VIEW, nullptr, nullptr, CH_RIFF }, }; + +extern const ChunkHandlerTable _misc_chunk_handlers(misc_chunk_handlers); diff --git a/src/saveload/newgrf_sl.cpp b/src/saveload/newgrf_sl.cpp index 3faf9a64a..f92da0db3 100644 --- a/src/saveload/newgrf_sl.cpp +++ b/src/saveload/newgrf_sl.cpp @@ -111,6 +111,8 @@ static void Check_NGRF() Load_NGRF_common(_load_check_data.grfconfig); } -extern const ChunkHandler _newgrf_chunk_handlers[] = { - { 'NGRF', Save_NGRF, Load_NGRF, nullptr, Check_NGRF, CH_ARRAY | CH_LAST } +static const ChunkHandler newgrf_chunk_handlers[] = { + { 'NGRF', Save_NGRF, Load_NGRF, nullptr, Check_NGRF, CH_ARRAY } }; + +extern const ChunkHandlerTable _newgrf_chunk_handlers(newgrf_chunk_handlers); diff --git a/src/saveload/object_sl.cpp b/src/saveload/object_sl.cpp index 40ca8cd11..dcf5fd65c 100644 --- a/src/saveload/object_sl.cpp +++ b/src/saveload/object_sl.cpp @@ -66,7 +66,9 @@ static void Load_OBID() Load_NewGRFMapping(_object_mngr); } -extern const ChunkHandler _object_chunk_handlers[] = { +static const ChunkHandler object_chunk_handlers[] = { { 'OBID', Save_OBID, Load_OBID, nullptr, nullptr, CH_ARRAY }, - { 'OBJS', Save_OBJS, Load_OBJS, Ptrs_OBJS, nullptr, CH_ARRAY | CH_LAST}, + { 'OBJS', Save_OBJS, Load_OBJS, Ptrs_OBJS, nullptr, CH_ARRAY }, }; + +extern const ChunkHandlerTable _object_chunk_handlers(object_chunk_handlers); diff --git a/src/saveload/order_sl.cpp b/src/saveload/order_sl.cpp index 44080e695..523a8b804 100644 --- a/src/saveload/order_sl.cpp +++ b/src/saveload/order_sl.cpp @@ -286,8 +286,10 @@ static void Ptrs_BKOR() } } -extern const ChunkHandler _order_chunk_handlers[] = { - { 'BKOR', Save_BKOR, Load_BKOR, Ptrs_BKOR, nullptr, CH_ARRAY}, - { 'ORDR', Save_ORDR, Load_ORDR, Ptrs_ORDR, nullptr, CH_ARRAY}, - { 'ORDL', Save_ORDL, Load_ORDL, Ptrs_ORDL, nullptr, CH_ARRAY | CH_LAST}, +static const ChunkHandler order_chunk_handlers[] = { + { 'BKOR', Save_BKOR, Load_BKOR, Ptrs_BKOR, nullptr, CH_ARRAY }, + { 'ORDR', Save_ORDR, Load_ORDR, Ptrs_ORDR, nullptr, CH_ARRAY }, + { 'ORDL', Save_ORDL, Load_ORDL, Ptrs_ORDL, nullptr, CH_ARRAY }, }; + +extern const ChunkHandlerTable _order_chunk_handlers(order_chunk_handlers); diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp index 01f0e0fd3..3c95e61e2 100644 --- a/src/saveload/saveload.cpp +++ b/src/saveload/saveload.cpp @@ -214,86 +214,92 @@ struct SaveLoadParams { static SaveLoadParams _sl; ///< Parameters used for/at saveload. -/* these define the chunks */ -extern const ChunkHandler _gamelog_chunk_handlers[]; -extern const ChunkHandler _map_chunk_handlers[]; -extern const ChunkHandler _misc_chunk_handlers[]; -extern const ChunkHandler _name_chunk_handlers[]; -extern const ChunkHandler _cheat_chunk_handlers[] ; -extern const ChunkHandler _setting_chunk_handlers[]; -extern const ChunkHandler _company_chunk_handlers[]; -extern const ChunkHandler _engine_chunk_handlers[]; -extern const ChunkHandler _veh_chunk_handlers[]; -extern const ChunkHandler _waypoint_chunk_handlers[]; -extern const ChunkHandler _depot_chunk_handlers[]; -extern const ChunkHandler _order_chunk_handlers[]; -extern const ChunkHandler _town_chunk_handlers[]; -extern const ChunkHandler _sign_chunk_handlers[]; -extern const ChunkHandler _station_chunk_handlers[]; -extern const ChunkHandler _industry_chunk_handlers[]; -extern const ChunkHandler _economy_chunk_handlers[]; -extern const ChunkHandler _subsidy_chunk_handlers[]; -extern const ChunkHandler _cargomonitor_chunk_handlers[]; -extern const ChunkHandler _goal_chunk_handlers[]; -extern const ChunkHandler _story_page_chunk_handlers[]; -extern const ChunkHandler _ai_chunk_handlers[]; -extern const ChunkHandler _game_chunk_handlers[]; -extern const ChunkHandler _animated_tile_chunk_handlers[]; -extern const ChunkHandler _newgrf_chunk_handlers[]; -extern const ChunkHandler _group_chunk_handlers[]; -extern const ChunkHandler _cargopacket_chunk_handlers[]; -extern const ChunkHandler _autoreplace_chunk_handlers[]; -extern const ChunkHandler _labelmaps_chunk_handlers[]; -extern const ChunkHandler _linkgraph_chunk_handlers[]; -extern const ChunkHandler _airport_chunk_handlers[]; -extern const ChunkHandler _object_chunk_handlers[]; -extern const ChunkHandler _persistent_storage_chunk_handlers[]; - -/** Array of all chunks in a savegame, \c nullptr terminated. */ -static const ChunkHandler * const _chunk_handlers[] = { - _gamelog_chunk_handlers, - _map_chunk_handlers, - _misc_chunk_handlers, - _name_chunk_handlers, - _cheat_chunk_handlers, - _setting_chunk_handlers, - _veh_chunk_handlers, - _waypoint_chunk_handlers, - _depot_chunk_handlers, - _order_chunk_handlers, - _industry_chunk_handlers, - _economy_chunk_handlers, - _subsidy_chunk_handlers, - _cargomonitor_chunk_handlers, - _goal_chunk_handlers, - _story_page_chunk_handlers, - _engine_chunk_handlers, - _town_chunk_handlers, - _sign_chunk_handlers, - _station_chunk_handlers, - _company_chunk_handlers, - _ai_chunk_handlers, - _game_chunk_handlers, - _animated_tile_chunk_handlers, - _newgrf_chunk_handlers, - _group_chunk_handlers, - _cargopacket_chunk_handlers, - _autoreplace_chunk_handlers, - _labelmaps_chunk_handlers, - _linkgraph_chunk_handlers, - _airport_chunk_handlers, - _object_chunk_handlers, - _persistent_storage_chunk_handlers, - nullptr, -}; +static const std::vector<ChunkHandler> &ChunkHandlers() +{ + /* These define the chunks */ + extern const ChunkHandlerTable _gamelog_chunk_handlers; + extern const ChunkHandlerTable _map_chunk_handlers; + extern const ChunkHandlerTable _misc_chunk_handlers; + extern const ChunkHandlerTable _name_chunk_handlers; + extern const ChunkHandlerTable _cheat_chunk_handlers; + extern const ChunkHandlerTable _setting_chunk_handlers; + extern const ChunkHandlerTable _company_chunk_handlers; + extern const ChunkHandlerTable _engine_chunk_handlers; + extern const ChunkHandlerTable _veh_chunk_handlers; + extern const ChunkHandlerTable _waypoint_chunk_handlers; + extern const ChunkHandlerTable _depot_chunk_handlers; + extern const ChunkHandlerTable _order_chunk_handlers; + extern const ChunkHandlerTable _town_chunk_handlers; + extern const ChunkHandlerTable _sign_chunk_handlers; + extern const ChunkHandlerTable _station_chunk_handlers; + extern const ChunkHandlerTable _industry_chunk_handlers; + extern const ChunkHandlerTable _economy_chunk_handlers; + extern const ChunkHandlerTable _subsidy_chunk_handlers; + extern const ChunkHandlerTable _cargomonitor_chunk_handlers; + extern const ChunkHandlerTable _goal_chunk_handlers; + extern const ChunkHandlerTable _story_page_chunk_handlers; + extern const ChunkHandlerTable _ai_chunk_handlers; + extern const ChunkHandlerTable _game_chunk_handlers; + extern const ChunkHandlerTable _animated_tile_chunk_handlers; + extern const ChunkHandlerTable _newgrf_chunk_handlers; + extern const ChunkHandlerTable _group_chunk_handlers; + extern const ChunkHandlerTable _cargopacket_chunk_handlers; + extern const ChunkHandlerTable _autoreplace_chunk_handlers; + extern const ChunkHandlerTable _labelmaps_chunk_handlers; + extern const ChunkHandlerTable _linkgraph_chunk_handlers; + extern const ChunkHandlerTable _airport_chunk_handlers; + extern const ChunkHandlerTable _object_chunk_handlers; + extern const ChunkHandlerTable _persistent_storage_chunk_handlers; + + /** List of all chunks in a savegame. */ + static const ChunkHandlerTable _chunk_handler_tables[] = { + _gamelog_chunk_handlers, + _map_chunk_handlers, + _misc_chunk_handlers, + _name_chunk_handlers, + _cheat_chunk_handlers, + _setting_chunk_handlers, + _veh_chunk_handlers, + _waypoint_chunk_handlers, + _depot_chunk_handlers, + _order_chunk_handlers, + _industry_chunk_handlers, + _economy_chunk_handlers, + _subsidy_chunk_handlers, + _cargomonitor_chunk_handlers, + _goal_chunk_handlers, + _story_page_chunk_handlers, + _engine_chunk_handlers, + _town_chunk_handlers, + _sign_chunk_handlers, + _station_chunk_handlers, + _company_chunk_handlers, + _ai_chunk_handlers, + _game_chunk_handlers, + _animated_tile_chunk_handlers, + _newgrf_chunk_handlers, + _group_chunk_handlers, + _cargopacket_chunk_handlers, + _autoreplace_chunk_handlers, + _labelmaps_chunk_handlers, + _linkgraph_chunk_handlers, + _airport_chunk_handlers, + _object_chunk_handlers, + _persistent_storage_chunk_handlers, + }; + + static std::vector<ChunkHandler> _chunk_handlers; + + if (_chunk_handlers.empty()) { + for (auto &chunk_handler_table : _chunk_handler_tables) { + for (auto &chunk_handler : chunk_handler_table) { + _chunk_handlers.push_back(chunk_handler); + } + } + } -/** - * Iterate over all chunk handlers. - * @param ch the chunk handler iterator - */ -#define FOR_ALL_CHUNK_HANDLERS(ch) \ - for (const ChunkHandler * const *chsc = _chunk_handlers; *chsc != nullptr; chsc++) \ - for (const ChunkHandler *ch = *chsc; ch != nullptr; ch = (ch->flags & CH_LAST) ? nullptr : ch + 1) + return _chunk_handlers; +} /** Null all pointers (convert index -> nullptr) */ static void SlNullPointers() @@ -305,10 +311,10 @@ static void SlNullPointers() * pointers from other pools. */ _sl_version = SAVEGAME_VERSION; - FOR_ALL_CHUNK_HANDLERS(ch) { - if (ch->ptrs_proc != nullptr) { - DEBUG(sl, 3, "Nulling pointers for %c%c%c%c", ch->id >> 24, ch->id >> 16, ch->id >> 8, ch->id); - ch->ptrs_proc(); + for (auto &ch : ChunkHandlers()) { + if (ch.ptrs_proc != nullptr) { + DEBUG(sl, 3, "Nulling pointers for %c%c%c%c", ch.id >> 24, ch.id >> 16, ch.id >> 8, ch.id); + ch.ptrs_proc(); } } @@ -1654,7 +1660,7 @@ void SlAutolength(AutolengthProc *proc, void *arg) * Load a chunk of data (eg vehicles, stations, etc.) * @param ch The chunkhandler that will be used for the operation */ -static void SlLoadChunk(const ChunkHandler *ch) +static void SlLoadChunk(const ChunkHandler &ch) { byte m = SlReadByte(); size_t len; @@ -1666,11 +1672,11 @@ static void SlLoadChunk(const ChunkHandler *ch) switch (m) { case CH_ARRAY: _sl.array_index = 0; - ch->load_proc(); + ch.load_proc(); if (_next_offs != 0) SlErrorCorrupt("Invalid array length"); break; case CH_SPARSE_ARRAY: - ch->load_proc(); + ch.load_proc(); if (_next_offs != 0) SlErrorCorrupt("Invalid array length"); break; default: @@ -1680,7 +1686,7 @@ static void SlLoadChunk(const ChunkHandler *ch) len += SlReadUint16(); _sl.obj_len = len; endoffs = _sl.reader->GetSize() + len; - ch->load_proc(); + ch.load_proc(); if (_sl.reader->GetSize() != endoffs) SlErrorCorrupt("Invalid chunk size"); } else { SlErrorCorrupt("Invalid chunk type"); @@ -1694,7 +1700,7 @@ static void SlLoadChunk(const ChunkHandler *ch) * If the chunkhandler is nullptr, the chunk is skipped. * @param ch The chunkhandler that will be used for the operation */ -static void SlLoadCheckChunk(const ChunkHandler *ch) +static void SlLoadCheckChunk(const ChunkHandler &ch) { byte m = SlReadByte(); size_t len; @@ -1706,15 +1712,15 @@ static void SlLoadCheckChunk(const ChunkHandler *ch) switch (m) { case CH_ARRAY: _sl.array_index = 0; - if (ch->load_check_proc) { - ch->load_check_proc(); + if (ch.load_check_proc) { + ch.load_check_proc(); } else { SlSkipArray(); } break; case CH_SPARSE_ARRAY: - if (ch->load_check_proc) { - ch->load_check_proc(); + if (ch.load_check_proc) { + ch.load_check_proc(); } else { SlSkipArray(); } @@ -1726,8 +1732,8 @@ static void SlLoadCheckChunk(const ChunkHandler *ch) len += SlReadUint16(); _sl.obj_len = len; endoffs = _sl.reader->GetSize() + len; - if (ch->load_check_proc) { - ch->load_check_proc(); + if (ch.load_check_proc) { + ch.load_check_proc(); } else { SlSkipBytes(len); } @@ -1744,18 +1750,18 @@ static void SlLoadCheckChunk(const ChunkHandler *ch) * prefixed by an ID identifying it, followed by data, and terminator where appropriate * @param ch The chunkhandler that will be used for the operation */ -static void SlSaveChunk(const ChunkHandler *ch) +static void SlSaveChunk(const ChunkHandler &ch) { - ChunkSaveLoadProc *proc = ch->save_proc; + ChunkSaveLoadProc *proc = ch.save_proc; /* Don't save any chunk information if there is no save handler. */ if (proc == nullptr) return; - SlWriteUint32(ch->id); - DEBUG(sl, 2, "Saving chunk %c%c%c%c", ch->id >> 24, ch->id >> 16, ch->id >> 8, ch->id); + SlWriteUint32(ch.id); + DEBUG(sl, 2, "Saving chunk %c%c%c%c", ch.id >> 24, ch.id >> 16, ch.id >> 8, ch.id); - _sl.block_mode = ch->flags & CH_TYPE_MASK; - switch (ch->flags & CH_TYPE_MASK) { + _sl.block_mode = ch.type; + switch (ch.type) { case CH_RIFF: _sl.need_length = NL_WANTLENGTH; proc(); @@ -1778,7 +1784,7 @@ static void SlSaveChunk(const ChunkHandler *ch) /** Save all chunks */ static void SlSaveChunks() { - FOR_ALL_CHUNK_HANDLERS(ch) { + for (auto &ch : ChunkHandlers()) { SlSaveChunk(ch); } @@ -1794,7 +1800,7 @@ static void SlSaveChunks() */ static const ChunkHandler *SlFindChunkHandler(uint32 id) { - FOR_ALL_CHUNK_HANDLERS(ch) if (ch->id == id) return ch; + for (auto &ch : ChunkHandlers()) if (ch.id == id) return &ch; return nullptr; } @@ -1809,7 +1815,7 @@ static void SlLoadChunks() ch = SlFindChunkHandler(id); if (ch == nullptr) SlErrorCorrupt("Unknown chunk type"); - SlLoadChunk(ch); + SlLoadChunk(*ch); } } @@ -1824,7 +1830,7 @@ static void SlLoadCheckChunks() ch = SlFindChunkHandler(id); if (ch == nullptr) SlErrorCorrupt("Unknown chunk type"); - SlLoadCheckChunk(ch); + SlLoadCheckChunk(*ch); } } @@ -1833,10 +1839,10 @@ static void SlFixPointers() { _sl.action = SLA_PTRS; - FOR_ALL_CHUNK_HANDLERS(ch) { - if (ch->ptrs_proc != nullptr) { - DEBUG(sl, 3, "Fixing pointers for %c%c%c%c", ch->id >> 24, ch->id >> 16, ch->id >> 8, ch->id); - ch->ptrs_proc(); + for (auto &ch : ChunkHandlers()) { + if (ch.ptrs_proc != nullptr) { + DEBUG(sl, 3, "Fixing pointers for %c%c%c%c", ch.id >> 24, ch.id >> 16, ch.id >> 8, ch.id); + ch.ptrs_proc(); } } diff --git a/src/saveload/saveload.h b/src/saveload/saveload.h index 1c763a93f..41880952e 100644 --- a/src/saveload/saveload.h +++ b/src/saveload/saveload.h @@ -14,6 +14,7 @@ #include "../strings_type.h" #include "../core/span_type.hpp" #include <string> +#include <vector> /** SaveLoad versions * Previous savegame versions, the trunk revision where they were @@ -378,6 +379,13 @@ SaveOrLoadResult LoadWithFilter(struct LoadFilter *reader); typedef void ChunkSaveLoadProc(); typedef void AutolengthProc(void *arg); +/** Type of a chunk. */ +enum ChunkType { + CH_RIFF = 0, + CH_ARRAY = 1, + CH_SPARSE_ARRAY = 2, +}; + /** Handlers and description of chunk. */ struct ChunkHandler { uint32 id; ///< Unique ID (4 letters). @@ -385,9 +393,12 @@ struct ChunkHandler { ChunkSaveLoadProc *load_proc; ///< Load procedure of the chunk. ChunkSaveLoadProc *ptrs_proc; ///< Manipulate pointers in the chunk. ChunkSaveLoadProc *load_check_proc; ///< Load procedure for game preview. - uint32 flags; ///< Flags of the chunk. @see ChunkType + ChunkType type; ///< Type of the chunk. @see ChunkType }; +/** A table of ChunkHandler entries. */ +using ChunkHandlerTable = span<const ChunkHandler>; + /** Type of reference (#SLE_REF, #SLE_CONDREF). */ enum SLRefType { REF_ORDER = 0, ///< Load/save a reference to an order. @@ -404,15 +415,6 @@ enum SLRefType { REF_LINK_GRAPH_JOB = 11, ///< Load/save a reference to a link graph job. }; -/** Flags of a chunk. */ -enum ChunkType { - CH_RIFF = 0, - CH_ARRAY = 1, - CH_SPARSE_ARRAY = 2, - CH_TYPE_MASK = 3, - CH_LAST = 8, ///< Last chunk in this array. -}; - /** * VarTypes is the general bitmasked magic type that tells us * certain characteristics about the variable it refers to. For example diff --git a/src/saveload/signs_sl.cpp b/src/saveload/signs_sl.cpp index 86a1468a5..388a92af9 100644 --- a/src/saveload/signs_sl.cpp +++ b/src/saveload/signs_sl.cpp @@ -62,6 +62,8 @@ static void Load_SIGN() } /** Chunk handlers related to signs. */ -extern const ChunkHandler _sign_chunk_handlers[] = { - { 'SIGN', Save_SIGN, Load_SIGN, nullptr, nullptr, CH_ARRAY | CH_LAST}, +static const ChunkHandler sign_chunk_handlers[] = { + { 'SIGN', Save_SIGN, Load_SIGN, nullptr, nullptr, CH_ARRAY }, }; + +extern const ChunkHandlerTable _sign_chunk_handlers(sign_chunk_handlers); diff --git a/src/saveload/station_sl.cpp b/src/saveload/station_sl.cpp index cd1b93138..75b6043e7 100644 --- a/src/saveload/station_sl.cpp +++ b/src/saveload/station_sl.cpp @@ -613,8 +613,10 @@ static void Ptrs_ROADSTOP() } } -extern const ChunkHandler _station_chunk_handlers[] = { +static const ChunkHandler station_chunk_handlers[] = { { 'STNS', nullptr, Load_STNS, Ptrs_STNS, nullptr, CH_ARRAY }, { 'STNN', Save_STNN, Load_STNN, Ptrs_STNN, nullptr, CH_ARRAY }, - { 'ROAD', Save_ROADSTOP, Load_ROADSTOP, Ptrs_ROADSTOP, nullptr, CH_ARRAY | CH_LAST}, + { 'ROAD', Save_ROADSTOP, Load_ROADSTOP, Ptrs_ROADSTOP, nullptr, CH_ARRAY }, }; + +extern const ChunkHandlerTable _station_chunk_handlers(station_chunk_handlers); diff --git a/src/saveload/storage_sl.cpp b/src/saveload/storage_sl.cpp index a01904e3a..50f858f11 100644 --- a/src/saveload/storage_sl.cpp +++ b/src/saveload/storage_sl.cpp @@ -44,6 +44,8 @@ static void Save_PSAC() } /** Chunk handler for persistent storages. */ -extern const ChunkHandler _persistent_storage_chunk_handlers[] = { - { 'PSAC', Save_PSAC, Load_PSAC, nullptr, nullptr, CH_ARRAY | CH_LAST}, +static const ChunkHandler persistent_storage_chunk_handlers[] = { + { 'PSAC', Save_PSAC, Load_PSAC, nullptr, nullptr, CH_ARRAY }, }; + +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 06083fb10..df5b1406f 100644 --- a/src/saveload/story_sl.cpp +++ b/src/saveload/story_sl.cpp @@ -95,7 +95,9 @@ static void Load_STORY_PAGE() _story_page_next_sort_value = max_sort_value + 1; } -extern const ChunkHandler _story_page_chunk_handlers[] = { - { 'STPE', Save_STORY_PAGE_ELEMENT, Load_STORY_PAGE_ELEMENT, nullptr, nullptr, CH_ARRAY}, - { 'STPA', Save_STORY_PAGE, Load_STORY_PAGE, nullptr, nullptr, CH_ARRAY | CH_LAST}, +static const ChunkHandler story_page_chunk_handlers[] = { + { 'STPE', Save_STORY_PAGE_ELEMENT, Load_STORY_PAGE_ELEMENT, nullptr, nullptr, CH_ARRAY }, + { 'STPA', Save_STORY_PAGE, Load_STORY_PAGE, nullptr, nullptr, CH_ARRAY }, }; + +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 dad7eb1ab..52f70b8d5 100644 --- a/src/saveload/strings_sl.cpp +++ b/src/saveload/strings_sl.cpp @@ -131,6 +131,8 @@ static void Load_NAME() } /** Chunk handlers related to strings. */ -extern const ChunkHandler _name_chunk_handlers[] = { - { 'NAME', nullptr, Load_NAME, nullptr, nullptr, CH_ARRAY | CH_LAST}, +static const ChunkHandler name_chunk_handlers[] = { + { 'NAME', nullptr, Load_NAME, nullptr, nullptr, CH_ARRAY }, }; + +extern const ChunkHandlerTable _name_chunk_handlers(name_chunk_handlers); diff --git a/src/saveload/subsidy_sl.cpp b/src/saveload/subsidy_sl.cpp index dbd04c8ad..b17ae1f25 100644 --- a/src/saveload/subsidy_sl.cpp +++ b/src/saveload/subsidy_sl.cpp @@ -43,6 +43,8 @@ static void Load_SUBS() } } -extern const ChunkHandler _subsidy_chunk_handlers[] = { - { 'SUBS', Save_SUBS, Load_SUBS, nullptr, nullptr, CH_ARRAY | CH_LAST}, +static const ChunkHandler subsidy_chunk_handlers[] = { + { 'SUBS', Save_SUBS, Load_SUBS, nullptr, nullptr, CH_ARRAY }, }; + +extern const ChunkHandlerTable _subsidy_chunk_handlers(subsidy_chunk_handlers); diff --git a/src/saveload/town_sl.cpp b/src/saveload/town_sl.cpp index 3ba25f640..908ff2dd7 100644 --- a/src/saveload/town_sl.cpp +++ b/src/saveload/town_sl.cpp @@ -296,7 +296,9 @@ static void Ptrs_TOWN() } /** Chunk handler for towns. */ -extern const ChunkHandler _town_chunk_handlers[] = { +static const ChunkHandler town_chunk_handlers[] = { { 'HIDS', Save_HIDS, Load_HIDS, nullptr, nullptr, CH_ARRAY }, - { 'CITY', Save_TOWN, Load_TOWN, Ptrs_TOWN, nullptr, CH_ARRAY | CH_LAST}, + { 'CITY', Save_TOWN, Load_TOWN, Ptrs_TOWN, nullptr, CH_ARRAY }, }; + +extern const ChunkHandlerTable _town_chunk_handlers(town_chunk_handlers); diff --git a/src/saveload/vehicle_sl.cpp b/src/saveload/vehicle_sl.cpp index e637f03b2..7e9005779 100644 --- a/src/saveload/vehicle_sl.cpp +++ b/src/saveload/vehicle_sl.cpp @@ -931,6 +931,8 @@ static void Ptrs_VEHS() } } -extern const ChunkHandler _veh_chunk_handlers[] = { - { 'VEHS', Save_VEHS, Load_VEHS, Ptrs_VEHS, nullptr, CH_SPARSE_ARRAY | CH_LAST}, +static const ChunkHandler veh_chunk_handlers[] = { + { 'VEHS', Save_VEHS, Load_VEHS, Ptrs_VEHS, nullptr, CH_SPARSE_ARRAY }, }; + +extern const ChunkHandlerTable _veh_chunk_handlers(veh_chunk_handlers); diff --git a/src/saveload/waypoint_sl.cpp b/src/saveload/waypoint_sl.cpp index 9ad3da1f3..97e2d12c9 100644 --- a/src/saveload/waypoint_sl.cpp +++ b/src/saveload/waypoint_sl.cpp @@ -224,6 +224,8 @@ static void Ptrs_WAYP() } } -extern const ChunkHandler _waypoint_chunk_handlers[] = { - { 'CHKP', nullptr, Load_WAYP, Ptrs_WAYP, nullptr, CH_ARRAY | CH_LAST}, +static const ChunkHandler waypoint_chunk_handlers[] = { + { 'CHKP', nullptr, Load_WAYP, Ptrs_WAYP, nullptr, CH_ARRAY }, }; + +extern const ChunkHandlerTable _waypoint_chunk_handlers(waypoint_chunk_handlers); |