From f6ab2b69c6f3cdeee281d228c393f1b0a27cabd1 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Wed, 22 Jan 2025 22:30:32 +0000 Subject: [PATCH] Codechange: Define GRFConfigList alias and pass by reference. (#13358) This adds the distinction between a single GRFConfig and a GRFConfig list, and simplifies how GRFConfig lists are passed to various functions. --- src/fios.h | 2 +- src/fios_gui.cpp | 4 +- src/gamelog.cpp | 55 ++++++++++--------- src/gamelog.h | 10 ++-- src/genworld_gui.cpp | 2 +- src/intro_gui.cpp | 2 +- src/network/core/network_game_info.h | 2 +- src/network/network.cpp | 2 +- src/network/network_content.h | 2 +- src/network/network_coordinator.cpp | 2 +- src/network/network_gamelist.cpp | 4 +- src/network/network_gui.cpp | 2 +- src/network/network_query.cpp | 2 +- src/newgrf_config.cpp | 80 +++++++++++++++------------- src/newgrf_config.h | 22 ++++---- src/newgrf_gui.cpp | 28 +++++----- src/saveload/afterload.cpp | 6 +-- src/saveload/newgrf_sl.cpp | 8 +-- src/saveload/oldloader_sl.cpp | 6 +-- src/saveload/saveload.cpp | 4 +- src/toolbar_gui.cpp | 2 +- 21 files changed, 127 insertions(+), 120 deletions(-) diff --git a/src/fios.h b/src/fios.h index f981c6c74c..03ccf64edb 100644 --- a/src/fios.h +++ b/src/fios.h @@ -42,7 +42,7 @@ struct LoadCheckData { CompanyPropertiesMap companies; ///< Company information. - GRFConfig *grfconfig; ///< NewGrf configuration from save. + GRFConfigList grfconfig; ///< NewGrf configuration from save. GRFListCompatibility grf_compatibility; ///< Summary state of NewGrfs, whether missing files or only compatible found. Gamelog gamelog; ///< Gamelog actions diff --git a/src/fios_gui.cpp b/src/fios_gui.cpp index d90f0a2355..8b6b1500a1 100644 --- a/src/fios_gui.cpp +++ b/src/fios_gui.cpp @@ -60,7 +60,7 @@ void LoadCheckData::Clear() this->gamelog.Reset(); - ClearGRFConfigList(&this->grfconfig); + ClearGRFConfigList(this->grfconfig); } /** Load game/scenario with optional content download */ @@ -697,7 +697,7 @@ public: case WID_SL_NEWGRF_INFO: if (_load_check_data.HasNewGrfs()) { - ShowNewGRFSettings(false, false, false, &_load_check_data.grfconfig); + ShowNewGRFSettings(false, false, false, _load_check_data.grfconfig); } break; diff --git a/src/gamelog.cpp b/src/gamelog.cpp index 7e802cba57..a6c630b85e 100644 --- a/src/gamelog.cpp +++ b/src/gamelog.cpp @@ -505,9 +505,9 @@ bool Gamelog::GRFBugReverse(uint32_t grfid, uint16_t internal_id) * @param g grf to determine * @return true iff GRF is not static and is loaded */ -static inline bool IsLoggableGrfConfig(const GRFConfig *g) +static inline bool IsLoggableGrfConfig(const GRFConfig &g) { - return !HasBit(g->flags, GCF_STATIC) && g->status != GCS_NOT_FOUND; + return !HasBit(g.flags, GCF_STATIC) && g.status != GCS_NOT_FOUND; } /** @@ -525,13 +525,13 @@ void Gamelog::GRFRemove(uint32_t grfid) * Logs adding of a GRF * @param newg added GRF */ -void Gamelog::GRFAdd(const GRFConfig *newg) +void Gamelog::GRFAdd(const GRFConfig &newg) { assert(this->action_type == GLAT_LOAD || this->action_type == GLAT_START || this->action_type == GLAT_GRF); if (!IsLoggableGrfConfig(newg)) return; - this->Change(std::make_unique(newg->ident)); + this->Change(std::make_unique(newg.ident)); } /** @@ -539,11 +539,11 @@ void Gamelog::GRFAdd(const GRFConfig *newg) * (the same ID, but different MD5 hash) * @param newg new (updated) GRF */ -void Gamelog::GRFCompatible(const GRFIdentifier *newg) +void Gamelog::GRFCompatible(const GRFIdentifier &newg) { assert(this->action_type == GLAT_LOAD || this->action_type == GLAT_GRF); - this->Change(std::make_unique(*newg)); + this->Change(std::make_unique(newg)); } /** @@ -573,26 +573,26 @@ void Gamelog::GRFParameters(uint32_t grfid) /** * Logs adding of list of GRFs. * Useful when old savegame is loaded or when new game is started - * @param newg head of GRF linked list + * @param newg the GRFConfigList. */ -void Gamelog::GRFAddList(const GRFConfig *newg) +void Gamelog::GRFAddList(const GRFConfigList &newg) { assert(this->action_type == GLAT_START || this->action_type == GLAT_LOAD); - for (; newg != nullptr; newg = newg->next) { - this->GRFAdd(newg); + for (GRFConfig *gc = newg; gc != nullptr; gc = gc->next) { + this->GRFAdd(*gc); } } /** * Generates GRFList - * @param grfc head of GRF linked list + * @param grfc the GRFConfigList. */ -static std::vector GenerateGRFList(const GRFConfig *grfc) +static std::vector GenerateGRFList(const GRFConfigList &grfc) { std::vector list; for (const GRFConfig *g = grfc; g != nullptr; g = g->next) { - if (IsLoggableGrfConfig(g)) list.push_back(g); + if (IsLoggableGrfConfig(*g)) list.push_back(g); } return list; @@ -603,7 +603,7 @@ static std::vector GenerateGRFList(const GRFConfig *grfc) * @param oldc original GRF list * @param newc new GRF list */ -void Gamelog::GRFUpdate(const GRFConfig *oldc, const GRFConfig *newc) +void Gamelog::GRFUpdate(const GRFConfigList &oldc, const GRFConfigList &newc) { std::vector ol = GenerateGRFList(oldc); std::vector nl = GenerateGRFList(newc); @@ -611,10 +611,10 @@ void Gamelog::GRFUpdate(const GRFConfig *oldc, const GRFConfig *newc) uint o = 0, n = 0; while (o < ol.size() && n < nl.size()) { - const GRFConfig *og = ol[o]; - const GRFConfig *ng = nl[n]; + const GRFConfig &og = *ol[o]; + const GRFConfig &ng = *nl[n]; - if (og->ident.grfid != ng->ident.grfid) { + if (og.ident.grfid != ng.ident.grfid) { uint oi, ni; for (oi = 0; oi < ol.size(); oi++) { if (ol[oi]->ident.grfid == nl[n]->ident.grfid) break; @@ -626,7 +626,7 @@ void Gamelog::GRFUpdate(const GRFConfig *oldc, const GRFConfig *newc) } if (oi == ol.size()) { /* GRF couldn't be found in the OLD list, GRF was ADDED */ - this->GRFAdd(nl[n++]); + this->GRFAdd(*nl[n++]); continue; } for (ni = 0; ni < nl.size(); ni++) { @@ -658,12 +658,12 @@ void Gamelog::GRFUpdate(const GRFConfig *oldc, const GRFConfig *newc) this->GRFMove(nl[n++]->ident.grfid, -(int)oi); } } else { - if (og->ident.md5sum != ng->ident.md5sum) { + if (og.ident.md5sum != ng.ident.md5sum) { /* md5sum changed, probably loading 'compatible' GRF */ - this->GRFCompatible(&nl[n]->ident); + this->GRFCompatible(nl[n]->ident); } - if (og->param != ng->param) { + if (og.param != ng.param) { this->GRFParameters(ol[o]->ident.grfid); } @@ -673,7 +673,7 @@ void Gamelog::GRFUpdate(const GRFConfig *oldc, const GRFConfig *newc) } while (o < ol.size()) this->GRFRemove(ol[o++]->ident.grfid); // remaining GRFs were removed ... - while (n < nl.size()) this->GRFAdd (nl[n++]); // ... or added + while (n < nl.size()) this->GRFAdd (*nl[n++]); // ... or added } /** @@ -709,18 +709,17 @@ void Gamelog::Info(uint32_t *last_ottd_rev, uint8_t *ever_modified, bool *remove * @param c the GRF to get the 'previous' version of. * @return the GRF identifier or \a c if none could be found. */ -const GRFIdentifier *Gamelog::GetOverriddenIdentifier(const GRFConfig *c) +const GRFIdentifier &Gamelog::GetOverriddenIdentifier(const GRFConfig &c) { - assert(c != nullptr); const LoggedAction &la = this->data->action.back(); - if (la.at != GLAT_LOAD) return &c->ident; + if (la.at != GLAT_LOAD) return c.ident; for (const auto &lc : la.change) { if (lc->ct != GLCT_GRFCOMPAT) continue; - const LoggedChangeGRFChanged *grf = static_cast(lc.get()); - if (grf->grfid == c->ident.grfid) return grf; + const LoggedChangeGRFChanged &grf = *static_cast(lc.get()); + if (grf.grfid == c.ident.grfid) return grf; } - return &c->ident; + return c.ident; } diff --git a/src/gamelog.h b/src/gamelog.h index 597683769f..3bc50562a0 100644 --- a/src/gamelog.h +++ b/src/gamelog.h @@ -76,13 +76,13 @@ public: void Oldver(); void Setting(const std::string &name, int32_t oldval, int32_t newval); - void GRFUpdate(const GRFConfig *oldg, const GRFConfig *newg); - void GRFAddList(const GRFConfig *newg); + void GRFUpdate(const GRFConfigList &oldg, const GRFConfigList &newg); + void GRFAddList(const GRFConfigList &newg); void GRFRemove(uint32_t grfid); - void GRFAdd(const GRFConfig *newg); + void GRFAdd(const GRFConfig &newg); void GRFBug(uint32_t grfid, uint8_t bug, uint64_t data); bool GRFBugReverse(uint32_t grfid, uint16_t internal_id); - void GRFCompatible(const GRFIdentifier *newg); + void GRFCompatible(const GRFIdentifier &newg); void GRFMove(uint32_t grfid, int32_t offset); void GRFParameters(uint32_t grfid); @@ -90,7 +90,7 @@ public: void TestMode(); void Info(uint32_t *last_ottd_rev, uint8_t *ever_modified, bool *removed_newgrfs); - const GRFIdentifier *GetOverriddenIdentifier(const GRFConfig *c); + const GRFIdentifier &GetOverriddenIdentifier(const GRFConfig &c); /* Saveload handler for gamelog needs access to internal data. */ friend struct GLOGChunkHandler; diff --git a/src/genworld_gui.cpp b/src/genworld_gui.cpp index 31caf9cb14..d19807ba2c 100644 --- a/src/genworld_gui.cpp +++ b/src/genworld_gui.cpp @@ -862,7 +862,7 @@ struct GenerateLandscapeWindow : public Window { break; case WID_GL_NEWGRF_BUTTON: ///< NewGRF Settings - ShowNewGRFSettings(true, true, false, &_grfconfig_newgame); + ShowNewGRFSettings(true, true, false, _grfconfig_newgame); break; } } diff --git a/src/intro_gui.cpp b/src/intro_gui.cpp index e2f7092fdb..1d7ec39a77 100644 --- a/src/intro_gui.cpp +++ b/src/intro_gui.cpp @@ -362,7 +362,7 @@ struct SelectGameWindow : public Window { case WID_SGI_HIGHSCORE: ShowHighscoreTable(); break; case WID_SGI_HELP: ShowHelpWindow(); break; case WID_SGI_SETTINGS_OPTIONS:ShowGameSettings(); break; - case WID_SGI_GRF_SETTINGS: ShowNewGRFSettings(true, true, false, &_grfconfig_newgame); break; + case WID_SGI_GRF_SETTINGS: ShowNewGRFSettings(true, true, false, _grfconfig_newgame); break; case WID_SGI_CONTENT_DOWNLOAD: if (!_network_available) { ShowErrorMessage(STR_NETWORK_ERROR_NOTAVAILABLE, INVALID_STRING_ID, WL_ERROR); diff --git a/src/network/core/network_game_info.h b/src/network/core/network_game_info.h index 3dfd1f0058..d28e4a6d13 100644 --- a/src/network/core/network_game_info.h +++ b/src/network/core/network_game_info.h @@ -94,7 +94,7 @@ enum NewGRFSerializationType { * The game information that is sent from the server to the client. */ struct NetworkServerGameInfo { - GRFConfig *grfconfig; ///< List of NewGRF files used + GRFConfigList grfconfig; ///< List of NewGRF files used TimerGameCalendar::Date calendar_start; ///< When the game started. TimerGameCalendar::Date calendar_date; ///< Current calendar date. TimerGameTick::TickCounter ticks_playing; ///< Amount of ticks the game has been running unpaused. diff --git a/src/network/network.cpp b/src/network/network.cpp index ba498b100b..1c5b101e02 100644 --- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -696,7 +696,7 @@ NetworkGameList *NetworkAddServer(const std::string &connection_string, bool man /* Ensure the item already exists in the list */ NetworkGameList *item = NetworkGameListAddItem(connection_string); if (item->info.server_name.empty()) { - ClearGRFConfigList(&item->info.grfconfig); + ClearGRFConfigList(item->info.grfconfig); item->info.server_name = connection_string; UpdateNetworkGameWindow(); diff --git a/src/network/network_content.h b/src/network/network_content.h index 1bb1898d09..bf62108edf 100644 --- a/src/network/network_content.h +++ b/src/network/network_content.h @@ -153,6 +153,6 @@ extern ClientNetworkContentSocketHandler _network_content_client; void ShowNetworkContentListWindow(ContentVector *cv = nullptr, ContentType type1 = CONTENT_TYPE_END, ContentType type2 = CONTENT_TYPE_END); -void ShowMissingContentWindow(const struct GRFConfig *list); +void ShowMissingContentWindow(const GRFConfigList &list); #endif /* NETWORK_CONTENT_H */ diff --git a/src/network/network_coordinator.cpp b/src/network/network_coordinator.cpp index e7bd0fdb6c..eb455219ea 100644 --- a/src/network/network_coordinator.cpp +++ b/src/network/network_coordinator.cpp @@ -251,7 +251,7 @@ bool ClientNetworkCoordinatorSocketHandler::Receive_GC_LISTING(Packet &p) NetworkGameList *item = NetworkGameListAddItem(connection_string); /* Clear any existing GRFConfig chain. */ - ClearGRFConfigList(&item->info.grfconfig); + ClearGRFConfigList(item->info.grfconfig); /* Copy the new NetworkGameInfo info. */ item->info = ngi; /* Check for compatability with the client. */ diff --git a/src/network/network_gamelist.cpp b/src/network/network_gamelist.cpp index 3df2021830..832d9ecc08 100644 --- a/src/network/network_gamelist.cpp +++ b/src/network/network_gamelist.cpp @@ -73,7 +73,7 @@ void NetworkGameListRemoveItem(NetworkGameList *remove) } /* Remove GRFConfig information */ - ClearGRFConfigList(&remove->info.grfconfig); + ClearGRFConfigList(remove->info.grfconfig); delete remove; NetworkRebuildHostList(); @@ -100,7 +100,7 @@ void NetworkGameListRemoveExpired() *prev_item = item; /* Remove GRFConfig information */ - ClearGRFConfigList(&remove->info.grfconfig); + ClearGRFConfigList(remove->info.grfconfig); delete remove; } else { prev_item = &item->next; diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp index 7ba45cc823..6c3163ccab 100644 --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -773,7 +773,7 @@ public: break; case WID_NG_NEWGRF: // NewGRF Settings - if (this->server != nullptr) ShowNewGRFSettings(false, false, false, &this->server->info.grfconfig); + if (this->server != nullptr) ShowNewGRFSettings(false, false, false, this->server->info.grfconfig); break; case WID_NG_NEWGRF_MISSING: // Find missing content online diff --git a/src/network/network_query.cpp b/src/network/network_query.cpp index 9f87a277f9..6ba97d5fbd 100644 --- a/src/network/network_query.cpp +++ b/src/network/network_query.cpp @@ -120,7 +120,7 @@ NetworkRecvStatus QueryNetworkGameSocketHandler::Receive_SERVER_GAME_INFO(Packet NetworkGameList *item = NetworkGameListAddItem(this->connection_string); /* Clear any existing GRFConfig chain. */ - ClearGRFConfigList(&item->info.grfconfig); + ClearGRFConfigList(item->info.grfconfig); /* Retrieve the NetworkGameInfo from the packet. */ DeserializeNetworkGameInfo(p, item->info); /* Check for compatability with the client. */ diff --git a/src/newgrf_config.cpp b/src/newgrf_config.cpp index f779c56716..101e1d2912 100644 --- a/src/newgrf_config.cpp +++ b/src/newgrf_config.cpp @@ -145,10 +145,10 @@ void GRFConfig::FinalizeParameterInfo() } } -GRFConfig *_all_grfs; -GRFConfig *_grfconfig; -GRFConfig *_grfconfig_newgame; -GRFConfig *_grfconfig_static; +GRFConfigList _all_grfs; +GRFConfigList _grfconfig; +GRFConfigList _grfconfig_newgame; +GRFConfigList _grfconfig_static; uint _missing_extra_graphics = 0; /** @@ -325,39 +325,48 @@ bool FillGRFDetails(GRFConfig *config, bool is_static, Subdirectory subdir) * @param config Start of the list. * @post \a config is set to \c nullptr. */ -void ClearGRFConfigList(GRFConfig **config) +void ClearGRFConfigList(GRFConfigList &config) { GRFConfig *c, *next; - for (c = *config; c != nullptr; c = next) { + for (c = config; c != nullptr; c = next) { next = c->next; delete c; } - *config = nullptr; + config = nullptr; } +/** + * Append a GRF Config list onto another list. + * @param dst The destination list + * @param src The source list + * @param init_only the copied GRF will be processed up to GLS_INIT + */ +static void AppendGRFConfigList(GRFConfigList &dst, const GRFConfigList &src, bool init_only) +{ + GRFConfig **tail = &dst; + while (*tail != nullptr) tail = &(*tail)->next; + + for (GRFConfig *s = src; s != nullptr; s = s->next) { + GRFConfig *c = new GRFConfig(*s); + + AssignBit(c->flags, GCF_INIT_ONLY, init_only); + + *tail = c; + tail = &c->next; + } +} /** - * Copy a GRF Config list - * @param dst pointer to destination list - * @param src pointer to source list values + * Copy a GRF Config list. + * @param dst The destination list + * @param src The source list * @param init_only the copied GRF will be processed up to GLS_INIT - * @return pointer to the last value added to the destination list */ -GRFConfig **CopyGRFConfigList(GRFConfig **dst, const GRFConfig *src, bool init_only) +void CopyGRFConfigList(GRFConfigList &dst, const GRFConfigList &src, bool init_only) { /* Clear destination as it will be overwritten */ ClearGRFConfigList(dst); - for (; src != nullptr; src = src->next) { - GRFConfig *c = new GRFConfig(*src); - - ClrBit(c->flags, GCF_INIT_ONLY); - if (init_only) SetBit(c->flags, GCF_INIT_ONLY); - - *dst = c; - dst = &c->next; - } - - return dst; + AppendGRFConfigList(dst, src, init_only); } /** @@ -373,7 +382,7 @@ GRFConfig **CopyGRFConfigList(GRFConfig **dst, const GRFConfig *src, bool init_o * * @param list the list to remove the duplicates from */ -static void RemoveDuplicatesFromGRFConfigList(GRFConfig *list) +static void RemoveDuplicatesFromGRFConfigList(GRFConfigList &list) { GRFConfig *prev; GRFConfig *cur; @@ -395,13 +404,10 @@ static void RemoveDuplicatesFromGRFConfigList(GRFConfig *list) * Appends the static GRFs to a list of GRFs * @param dst the head of the list to add to */ -void AppendStaticGRFConfigs(GRFConfig **dst) +void AppendStaticGRFConfigs(GRFConfigList &dst) { - GRFConfig **tail = dst; - while (*tail != nullptr) tail = &(*tail)->next; - - CopyGRFConfigList(tail, _grfconfig_static, false); - RemoveDuplicatesFromGRFConfigList(*dst); + AppendGRFConfigList(dst, _grfconfig_static, false); + RemoveDuplicatesFromGRFConfigList(dst); } /** @@ -409,21 +415,21 @@ void AppendStaticGRFConfigs(GRFConfig **dst) * @param dst the head of the list to add to * @param el the new tail to be */ -void AppendToGRFConfigList(GRFConfig **dst, GRFConfig *el) +void AppendToGRFConfigList(GRFConfigList &dst, GRFConfig *el) { - GRFConfig **tail = dst; + GRFConfig **tail = &dst; while (*tail != nullptr) tail = &(*tail)->next; *tail = el; - RemoveDuplicatesFromGRFConfigList(*dst); + RemoveDuplicatesFromGRFConfigList(dst); } /** Reset the current GRF Config to either blank or newgame settings. */ void ResetGRFConfig(bool defaults) { - CopyGRFConfigList(&_grfconfig, _grfconfig_newgame, !defaults); - AppendStaticGRFConfigs(&_grfconfig); + CopyGRFConfigList(_grfconfig, _grfconfig_newgame, !defaults); + AppendStaticGRFConfigs(_grfconfig); } @@ -438,7 +444,7 @@ void ResetGRFConfig(bool defaults) *
  • GLC_NOT_FOUND: For one or more GRF's no match was found at all * */ -GRFListCompatibility IsGoodGRFConfigList(GRFConfig *grfconfig) +GRFListCompatibility IsGoodGRFConfigList(GRFConfigList &grfconfig) { GRFListCompatibility res = GLC_ALL_GOOD; @@ -596,7 +602,7 @@ static bool GRFSorter(GRFConfig * const &c1, GRFConfig * const &c2) */ void DoScanNewGRFFiles(NewGRFScanCallback *callback) { - ClearGRFConfigList(&_all_grfs); + ClearGRFConfigList(_all_grfs); TarScanner::DoScan(TarScanner::NEWGRF); Debug(grf, 1, "Scanning for NewGRFs"); diff --git a/src/newgrf_config.h b/src/newgrf_config.h index 19f2a8c0a0..ac470da37d 100644 --- a/src/newgrf_config.h +++ b/src/newgrf_config.h @@ -199,6 +199,8 @@ struct GRFConfig { void FinalizeParameterInfo(); }; +using GRFConfigList = GRFConfig *; + /** Method to find GRFs using FindGRFConfig */ enum FindGRFConfigMode { FGCM_EXACT, ///< Only find Grfs matching md5sum @@ -208,10 +210,10 @@ enum FindGRFConfigMode { FGCM_ANY, ///< Use first found }; -extern GRFConfig *_all_grfs; ///< First item in list of all scanned NewGRFs -extern GRFConfig *_grfconfig; ///< First item in list of current GRF set up -extern GRFConfig *_grfconfig_newgame; ///< First item in list of default GRF set up -extern GRFConfig *_grfconfig_static; ///< First item in list of static GRF set up +extern GRFConfigList _all_grfs; ///< First item in list of all scanned NewGRFs +extern GRFConfigList _grfconfig; ///< First item in list of current GRF set up +extern GRFConfigList _grfconfig_newgame; ///< First item in list of default GRF set up +extern GRFConfigList _grfconfig_static; ///< First item in list of static GRF set up extern uint _missing_extra_graphics; ///< Number of sprites provided by the fallback extra GRF, i.e. missing in the baseset. /** Callback for NewGRF scanning. */ @@ -227,17 +229,17 @@ size_t GRFGetSizeOfDataSection(FileHandle &f); void ScanNewGRFFiles(NewGRFScanCallback *callback); const GRFConfig *FindGRFConfig(uint32_t grfid, FindGRFConfigMode mode, const MD5Hash *md5sum = nullptr, uint32_t desired_version = 0); GRFConfig *GetGRFConfig(uint32_t grfid, uint32_t mask = 0xFFFFFFFF); -GRFConfig **CopyGRFConfigList(GRFConfig **dst, const GRFConfig *src, bool init_only); -void AppendStaticGRFConfigs(GRFConfig **dst); -void AppendToGRFConfigList(GRFConfig **dst, GRFConfig *el); -void ClearGRFConfigList(GRFConfig **config); +void CopyGRFConfigList(GRFConfigList &dst, const GRFConfigList &src, bool init_only); +void AppendStaticGRFConfigs(GRFConfigList &dst); +void AppendToGRFConfigList(GRFConfigList &dst, GRFConfig *el); +void ClearGRFConfigList(GRFConfigList &config); void ResetGRFConfig(bool defaults); -GRFListCompatibility IsGoodGRFConfigList(GRFConfig *grfconfig); +GRFListCompatibility IsGoodGRFConfigList(GRFConfigList &grfconfig); bool FillGRFDetails(GRFConfig *config, bool is_static, Subdirectory subdir = NEWGRF_DIR); std::string GRFBuildParamList(const GRFConfig *c); /* In newgrf_gui.cpp */ -void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfig **config); +void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfigList &config); void OpenGRFParameterWindow(bool is_baseset, GRFConfig *c, bool editable); void UpdateNewGRFScanStatus(uint num, const char *name); diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp index 0d78e54b32..1af13d98d4 100644 --- a/src/newgrf_gui.cpp +++ b/src/newgrf_gui.cpp @@ -619,10 +619,10 @@ struct NewGRFWindow : public Window, NewGRFScanCallback { StringList grf_presets; ///< List of known NewGRF presets. - GRFConfig *actives; ///< Temporary active grf list to which changes are made. + GRFConfigList actives; ///< Temporary active grf list to which changes are made. GRFConfig *active_sel; ///< Selected active grf item. - GRFConfig **orig_list; ///< List active grfs in the game. Used as initial value, may be updated by the window. + GRFConfigList *orig_list; ///< List active grfs in the game. Used as initial value, may be updated by the window. bool editable; ///< Is the window editable? bool show_params; ///< Are the grf-parameters shown in the info-panel? bool execute; ///< On pressing 'apply changes' are grf changes applied immediately, or only list is updated. @@ -633,7 +633,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback { Scrollbar *vscroll; Scrollbar *vscroll2; - NewGRFWindow(WindowDesc &desc, bool editable, bool show_params, bool execute, GRFConfig **orig_list) : Window(desc), filter_editbox(EDITBOX_MAX_SIZE) + NewGRFWindow(WindowDesc &desc, bool editable, bool show_params, bool execute, GRFConfigList *orig_list) : Window(desc), filter_editbox(EDITBOX_MAX_SIZE) { this->avail_sel = nullptr; this->avail_pos = -1; @@ -646,7 +646,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback { this->preset = -1; this->active_over = -1; - CopyGRFConfigList(&this->actives, *orig_list, false); + CopyGRFConfigList(this->actives, *orig_list, false); this->grf_presets = GetGRFPresetList(); this->CreateNestedTree(); @@ -681,7 +681,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback { CloseWindowByClass(WC_SAVE_PRESET); if (this->editable && this->modified && !this->execute && !_exit_game) { - CopyGRFConfigList(this->orig_list, this->actives, true); + CopyGRFConfigList(*this->orig_list, this->actives, true); ResetGRFConfig(false); ReloadNewGRFData(); } @@ -692,7 +692,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback { ~NewGRFWindow() { /* Remove the temporary copy of grf-list used in window */ - ClearGRFConfigList(&this->actives); + ClearGRFConfigList(this->actives); } /** @@ -1122,7 +1122,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback { NewGRFConfirmationCallback ); } else { - CopyGRFConfigList(this->orig_list, this->actives, true); + CopyGRFConfigList(*this->orig_list, this->actives, true); ResetGRFConfig(false); ReloadNewGRFData(); this->InvalidateData(GOID_NEWGRF_CHANGES_APPLIED); @@ -1179,7 +1179,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback { if (widget != WID_NS_PRESET_LIST) return; if (!this->editable) return; - ClearGRFConfigList(&this->actives); + ClearGRFConfigList(this->actives); this->preset = index; if (index != -1) { @@ -1563,7 +1563,7 @@ private: * Show the content list window with all missing grfs from the given list. * @param list The list of grfs to check for missing / not exactly matching ones. */ -void ShowMissingContentWindow(const GRFConfig *list) +void ShowMissingContentWindow(const GRFConfigList &list) { /* Only show the things in the current list, or everything when nothing's selected */ ContentVector cv; @@ -1985,7 +1985,7 @@ static void NewGRFConfirmationCallback(Window *w, bool confirmed) _gamelog.StartAction(GLAT_GRF); _gamelog.GRFUpdate(_grfconfig, nw->actives); // log GRF changes - CopyGRFConfigList(nw->orig_list, nw->actives, false); + CopyGRFConfigList(*nw->orig_list, nw->actives, false); ReloadNewGRFData(); _gamelog.StopAction(); @@ -1993,7 +1993,7 @@ static void NewGRFConfirmationCallback(Window *w, bool confirmed) GRFConfig *c; int i = 0; for (c = nw->actives; c != nullptr && c != nw->active_sel; c = c->next, i++) {} - CopyGRFConfigList(&nw->actives, *nw->orig_list, false); + CopyGRFConfigList(nw->actives, *nw->orig_list, false); for (c = nw->actives; c != nullptr && i > 0; c = c->next, i--) {} nw->active_sel = c; nw->avails.ForceRebuild(); @@ -2014,12 +2014,12 @@ static void NewGRFConfirmationCallback(Window *w, bool confirmed) * @param show_params show information about what parameters are set for the grf files * @param exec_changes if changes are made to the list (editable is true), apply these * changes immediately or only update the list - * @param config pointer to a linked-list of grfconfig's that will be shown + * @param config The GRFConfigList that will be shown. */ -void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfig **config) +void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfigList &config) { CloseWindowByClass(WC_GAME_OPTIONS); - new NewGRFWindow(_newgrf_desc, editable, show_params, exec_changes, config); + new NewGRFWindow(_newgrf_desc, editable, show_params, exec_changes, &config); } /** Widget parts of the save preset window. */ diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index d4f8ceacef..de104efa0c 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -389,9 +389,9 @@ static void CDECL HandleSavegameLoadCrash(int signum) for (const GRFConfig *c = _grfconfig; c != nullptr; c = c->next) { if (HasBit(c->flags, GCF_COMPATIBLE)) { - const GRFIdentifier *replaced = _gamelog.GetOverriddenIdentifier(c); + const GRFIdentifier &replaced = _gamelog.GetOverriddenIdentifier(*c); fmt::format_to(std::back_inserter(message), "NewGRF {:08X} (checksum {}) not found.\n Loaded NewGRF \"{}\" (checksum {}) with same GRF ID instead.\n", - BSWAP32(c->ident.grfid), FormatArrayAsHex(c->original_md5sum), c->filename, FormatArrayAsHex(replaced->md5sum)); + BSWAP32(c->ident.grfid), FormatArrayAsHex(c->original_md5sum), c->filename, FormatArrayAsHex(replaced.md5sum)); } if (c->status == GCS_NOT_FOUND) { fmt::format_to(std::back_inserter(message), "NewGRF {:08X} ({}) not found; checksum {}.\n", @@ -711,7 +711,7 @@ bool AfterLoadGame() if (c->status == GCS_NOT_FOUND) { _gamelog.GRFRemove(c->ident.grfid); } else if (HasBit(c->flags, GCF_COMPATIBLE)) { - _gamelog.GRFCompatible(&c->ident); + _gamelog.GRFCompatible(c->ident); } } diff --git a/src/saveload/newgrf_sl.cpp b/src/saveload/newgrf_sl.cpp index 187eaf442d..13569c749c 100644 --- a/src/saveload/newgrf_sl.cpp +++ b/src/saveload/newgrf_sl.cpp @@ -106,17 +106,17 @@ struct NGRFChunkHandler : ChunkHandler { config.param.assign(std::begin(param), last); } - void LoadCommon(GRFConfig *&grfconfig) const + void LoadCommon(GRFConfigList &grfconfig) const { const std::vector slt = SlCompatTableHeader(description, _grfconfig_sl_compat); - ClearGRFConfigList(&grfconfig); + ClearGRFConfigList(grfconfig); while (SlIterateArray() != -1) { GRFConfig *c = new GRFConfig(); SlObject(c, slt); if (IsSavegameVersionBefore(SLV_101)) c->SetSuitablePalette(); this->LoadParameters(*c); - AppendToGRFConfigList(&grfconfig, c); + AppendToGRFConfigList(grfconfig, c); } } @@ -132,7 +132,7 @@ struct NGRFChunkHandler : ChunkHandler { ResetGRFConfig(false); } else { /* Append static NewGRF configuration */ - AppendStaticGRFConfigs(&_grfconfig); + AppendStaticGRFConfigs(_grfconfig); } } diff --git a/src/saveload/oldloader_sl.cpp b/src/saveload/oldloader_sl.cpp index 870a6e6e25..6ed7dba774 100644 --- a/src/saveload/oldloader_sl.cpp +++ b/src/saveload/oldloader_sl.cpp @@ -1554,7 +1554,7 @@ static bool LoadTTDPatchExtraChunks(LoadgameState *ls, int) /* Skip the first element: TTDP hack for the Action D special variables (FFFF0000 01) */ ReadUint32(ls); ReadByte(ls); len -= 5; - ClearGRFConfigList(&_grfconfig); + ClearGRFConfigList(_grfconfig); while (len != 0) { uint32_t grfid = ReadUint32(ls); @@ -1562,14 +1562,14 @@ static bool LoadTTDPatchExtraChunks(LoadgameState *ls, int) GRFConfig *c = new GRFConfig("TTDP game, no information"); c->ident.grfid = grfid; - AppendToGRFConfigList(&_grfconfig, c); + AppendToGRFConfigList(_grfconfig, c); Debug(oldloader, 3, "TTDPatch game using GRF file with GRFID {:08X}", BSWAP32(c->ident.grfid)); } len -= 5; } /* Append static NewGRF configuration */ - AppendStaticGRFConfigs(&_grfconfig); + AppendStaticGRFConfigs(_grfconfig); break; } diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp index adfbba5a78..bcea36362a 100644 --- a/src/saveload/saveload.cpp +++ b/src/saveload/saveload.cpp @@ -3063,7 +3063,7 @@ static SaveOrLoadResult DoLoad(std::shared_ptr reader, bool load_che * Note: this is done here because AfterLoadGame is also called * for TTO/TTD/TTDP savegames which have their own NewGRF logic. */ - ClearGRFConfigList(&_grfconfig); + ClearGRFConfigList(_grfconfig); } } @@ -3146,7 +3146,7 @@ SaveOrLoadResult SaveOrLoad(const std::string &filename, SaveLoadOperation fop, * and if so a new NewGRF list will be made in LoadOldSaveGame. * Note: this is done here because AfterLoadGame is also called * for OTTD savegames which have their own NewGRF logic. */ - ClearGRFConfigList(&_grfconfig); + ClearGRFConfigList(_grfconfig); _gamelog.Reset(); if (!LoadOldSaveGame(filename)) return SL_REINIT; _sl_version = SL_MIN_VERSION; diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp index fe8a32eb6b..cc63de4575 100644 --- a/src/toolbar_gui.cpp +++ b/src/toolbar_gui.cpp @@ -320,7 +320,7 @@ static CallBackFunction MenuClickSettings(int index) case OME_SETTINGS: ShowGameSettings(); return CBF_NONE; case OME_AI_SETTINGS: ShowAIConfigWindow(); return CBF_NONE; case OME_GAMESCRIPT_SETTINGS: ShowGSConfigWindow(); return CBF_NONE; - case OME_NEWGRFSETTINGS: ShowNewGRFSettings(!_networking && _settings_client.gui.UserIsAllowedToChangeNewGRFs(), true, true, &_grfconfig); return CBF_NONE; + case OME_NEWGRFSETTINGS: ShowNewGRFSettings(!_networking && _settings_client.gui.UserIsAllowedToChangeNewGRFs(), true, true, _grfconfig); return CBF_NONE; case OME_SANDBOX: ShowCheatWindow(); break; case OME_TRANSPARENCIES: ShowTransparencyToolbar(); break;