Codechange: Use TypedIndexContainer for typed index containers

Instead of ReferenceThroughBaseContainer
This commit is contained in:
Jonathan G Rennison 2025-06-08 20:46:58 +01:00 committed by Peter Nelson
parent d0e49a297f
commit 63f1c2aa3a
17 changed files with 23 additions and 23 deletions

View File

@ -52,7 +52,7 @@ void UpdateObjectColours(const Company *c);
CompanyID _local_company; ///< Company controlled by the human player at this client. Can also be #COMPANY_SPECTATOR.
CompanyID _current_company; ///< Company currently doing an action.
ReferenceThroughBaseContainer<std::array<Colours, MAX_COMPANIES>> _company_colours; ///< NOSAVE: can be determined from company structs.
TypedIndexContainer<std::array<Colours, MAX_COMPANIES>, CompanyID> _company_colours; ///< NOSAVE: can be determined from company structs.
CompanyManagerFace _company_manager_face; ///< for company manager face storage in openttd.cfg
uint _cur_company_tick_index; ///< used to generate a name for one company that doesn't have a name yet per tick

View File

@ -36,7 +36,7 @@ CommandCost CheckTileOwnership(TileIndex tile);
extern CompanyID _local_company;
extern CompanyID _current_company;
extern ReferenceThroughBaseContainer<std::array<Colours, MAX_COMPANIES>> _company_colours;
extern TypedIndexContainer<std::array<Colours, MAX_COMPANIES>, CompanyID> _company_colours;
extern CompanyManagerFace _company_manager_face;
PaletteID GetCompanyPalette(CompanyID company);

View File

@ -101,7 +101,7 @@ const ScoreInfo _score_info[] = {
{ 0, 0} // SCORE_TOTAL
};
ReferenceThroughBaseContainer<std::array<std::array<int64_t, SCORE_END>, MAX_COMPANIES>> _score_part;
TypedIndexContainer<std::array<std::array<int64_t, SCORE_END>, MAX_COMPANIES>, CompanyID> _score_part;
Economy _economy;
Prices _price;
static PriceMultipliers _price_base_multiplier;

View File

@ -23,7 +23,7 @@ void ResetPriceBaseMultipliers();
void SetPriceBaseMultiplier(Price price, int factor);
extern const ScoreInfo _score_info[];
extern ReferenceThroughBaseContainer<std::array<std::array<int64_t, SCORE_END>, MAX_COMPANIES>> _score_part;
extern TypedIndexContainer<std::array<std::array<int64_t, SCORE_END>, MAX_COMPANIES>, CompanyID> _score_part;
extern Economy _economy;
/* Prices and also the fractional part. */
extern Prices _price;

View File

@ -39,7 +39,7 @@ void ReconsiderGameScriptLanguage();
/** Container for the raw (unencoded) language strings of a language. */
struct LanguageStrings {
std::string language; ///< Name of the language (base filename). Empty string if invalid.
ReferenceThroughBaseContainer<StringList> lines; ///< The lines of the file to pass into the parser/encoder.
TypedIndexContainer<StringList, StringIndexInTab> lines; ///< The lines of the file to pass into the parser/encoder.
LanguageStrings() {}
LanguageStrings(const std::string &lang) : language(lang) {}
@ -56,8 +56,8 @@ struct GameStrings {
std::vector<LanguageStrings> raw_strings; ///< The raw strings per language, first must be English/the master language!.
std::vector<LanguageStrings> compiled_strings; ///< The compiled strings per language, first must be English/the master language!.
ReferenceThroughBaseContainer<StringList> string_names; ///< The names of the compiled strings.
ReferenceThroughBaseContainer<StringParamsList> string_params; ///< The parameters for the strings.
TypedIndexContainer<StringList, StringIndexInTab> string_names; ///< The names of the compiled strings.
TypedIndexContainer<StringParamsList, StringIndexInTab> string_params; ///< The parameters for the strings.
void Compile();

View File

@ -134,7 +134,7 @@ private:
LinkGraphJob &job; ///< Link graph job we're working with.
/** Lookup table for getting NodeIDs from StationIDs. */
ReferenceThroughBaseContainer<std::vector<NodeID>> station_to_node;
TypedIndexContainer<std::vector<NodeID>, StationID> station_to_node;
/** Current iterator in the shares map. */
FlowStat::SharesMap::const_iterator it;

View File

@ -45,7 +45,7 @@ void NetworkDisconnect(bool close_admins = true);
void NetworkGameLoop();
void NetworkBackgroundLoop();
std::string_view ParseFullConnectionString(std::string_view connection_string, uint16_t &port, CompanyID *company_id = nullptr);
using NetworkCompanyStatsArray = ReferenceThroughBaseContainer<std::array<NetworkCompanyStats, MAX_COMPANIES>>;
using NetworkCompanyStatsArray = TypedIndexContainer<std::array<NetworkCompanyStats, MAX_COMPANIES>, CompanyID>;
NetworkCompanyStatsArray NetworkGetCompanyStats();
void NetworkUpdateClientInfo(ClientID client_id);

View File

@ -74,7 +74,7 @@ GRFLoadedFeatures _loaded_newgrf_features;
GrfProcessingState _cur_gps;
ReferenceThroughBaseContainer<std::vector<GRFTempEngineData>> _gted; ///< Temporary engine data used during NewGRF loading
TypedIndexContainer<std::vector<GRFTempEngineData>, EngineID> _gted; ///< Temporary engine data used during NewGRF loading
/**
* Debug() function dedicated to newGRF debugging messages

View File

@ -49,7 +49,7 @@ struct GRFTempEngineData {
}
};
extern ReferenceThroughBaseContainer<std::vector<GRFTempEngineData>> _gted; ///< Temporary engine data used during NewGRF loading
extern TypedIndexContainer<std::vector<GRFTempEngineData>, EngineID> _gted; ///< Temporary engine data used during NewGRF loading
Engine *GetNewEngine(const GRFFile *file, VehicleType type, uint16_t internal_id, bool static_access = false);
void ConvertTTDBasePrice(uint32_t base_pointer, std::string_view error_location, Price *index);

View File

@ -74,7 +74,7 @@ struct GRFTextEntry {
};
static ReferenceThroughBaseContainer<std::vector<GRFTextEntry>> _grf_text;
static TypedIndexContainer<std::vector<GRFTextEntry>, StringIndexInTab> _grf_text;
static uint8_t _current_lang_id = GRFLX_ENGLISH; ///< by default, english is used.
/**

View File

@ -222,8 +222,8 @@ public:
}
};
ReferenceThroughBaseContainer<std::vector<WaterRegionData>> _water_region_data;
ReferenceThroughBaseContainer<std::vector<bool>> _is_water_region_valid;
TypedIndexContainer<std::vector<WaterRegionData>, WaterRegionIndex> _water_region_data;
TypedIndexContainer<std::vector<bool>, WaterRegionIndex> _is_water_region_valid;
static TileIndex GetTileIndexFromLocalCoordinate(int region_x, int region_y, int local_x, int local_y)
{

View File

@ -41,7 +41,7 @@ static const SaveLoad _engine_desc[] = {
SLE_CONDSSTR(Engine, name, SLE_STR, SLV_84, SL_MAX_VERSION),
};
static ReferenceThroughBaseContainer<std::vector<Engine>> _temp_engine;
static TypedIndexContainer<std::vector<Engine>, EngineID> _temp_engine;
Engine *GetTempDataEngine(EngineID index)
{
@ -134,7 +134,7 @@ struct ENGSChunkHandler : ChunkHandler {
{
/* Load old separate String ID list into a temporary array. This
* was always 256 entries. */
ReferenceThroughBaseContainer<std::array<StringID, 256>> names{};
TypedIndexContainer<std::array<StringID, 256>, EngineID> names{};
SlCopy(names.data(), std::size(names), SLE_STRINGID);

View File

@ -347,7 +347,7 @@ private:
static std::tuple<bool, bool, bool, bool> DoCommandPrep();
static bool DoCommandProcessResult(const CommandCost &res, Script_SuspendCallbackProc *callback, bool estimate_only, bool asynchronous);
static CommandCallbackData *GetDoCommandCallback();
using RandomizerArray = ReferenceThroughBaseContainer<std::array<Randomizer, OWNER_END.base()>>;
using RandomizerArray = TypedIndexContainer<std::array<Randomizer, OWNER_END.base()>, Owner>;
static RandomizerArray random_states; ///< Random states for each of the scripts (game script uses OWNER_DEITY)
};

View File

@ -598,7 +598,7 @@ struct CompanySettings {
/** Container for AI and Game script configuration. */
struct ScriptConfigSettings
{
ReferenceThroughBaseContainer<std::array<std::unique_ptr<class AIConfig>, MAX_COMPANIES>> ai; ///< settings per company
TypedIndexContainer<std::array<std::unique_ptr<class AIConfig>, MAX_COMPANIES>, CompanyID> ai; ///< settings per company
std::unique_ptr<class GameConfig> game; ///< settings for gamescript
ScriptConfigSettings();

View File

@ -181,7 +181,7 @@ static IndustryType _smallmap_industry_highlight = IT_INVALID;
/** State of highlight blinking */
static bool _smallmap_industry_highlight_state;
/** For connecting company ID to position in owner list (small map legend) */
static ReferenceThroughBaseContainer<std::array<uint32_t, MAX_COMPANIES>> _company_to_list_pos;
static TypedIndexContainer<std::array<uint32_t, MAX_COMPANIES>, CompanyID> _company_to_list_pos;
/**
* Fills an array for the industries legends.

View File

@ -4431,8 +4431,8 @@ uint MoveGoodsToStation(CargoType cargo, uint amount, Source source, const Stati
return UpdateStationWaiting(first_station, cargo, amount, source);
}
ReferenceThroughBaseContainer<std::array<uint32_t, OWNER_END.base()>> company_best = {}; // best rating for each company, including OWNER_NONE
ReferenceThroughBaseContainer<std::array<uint32_t, OWNER_END.base()>> company_sum = {}; // sum of ratings for each company
TypedIndexContainer<std::array<uint32_t, OWNER_END.base()>, Owner> company_best = {}; // best rating for each company, including OWNER_NONE
TypedIndexContainer<std::array<uint32_t, OWNER_END.base()>, Owner> company_sum = {}; // sum of ratings for each company
uint best_rating = 0;
uint best_sum = 0; // sum of best ratings for each company

View File

@ -69,10 +69,10 @@ struct Town : TownPool::PoolItem<&_town_pool> {
/* Company ratings. */
CompanyMask have_ratings{}; ///< which companies have a rating
ReferenceThroughBaseContainer<std::array<uint8_t, MAX_COMPANIES>> unwanted{}; ///< how many months companies aren't wanted by towns (bribe)
TypedIndexContainer<std::array<uint8_t, MAX_COMPANIES>, CompanyID> unwanted{}; ///< how many months companies aren't wanted by towns (bribe)
CompanyID exclusivity = CompanyID::Invalid(); ///< which company has exclusivity
uint8_t exclusive_counter = 0; ///< months till the exclusivity expires
ReferenceThroughBaseContainer<std::array<int16_t, MAX_COMPANIES>> ratings{}; ///< ratings of each company for this town
TypedIndexContainer<std::array<int16_t, MAX_COMPANIES>, CompanyID> ratings{}; ///< ratings of each company for this town
std::array<TransportedCargoStat<uint32_t>, NUM_CARGO> supplied{}; ///< Cargo statistics about supplied cargo.
std::array<TransportedCargoStat<uint16_t>, NUM_TAE> received{}; ///< Cargo statistics about received cargotypes.