mirror of https://github.com/OpenTTD/OpenTTD
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.pull/13360/head
parent
b1ab1b9f06
commit
f6ab2b69c6
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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<LoggedChangeGRFAdd>(newg->ident));
|
||||
this->Change(std::make_unique<LoggedChangeGRFAdd>(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<LoggedChangeGRFChanged>(*newg));
|
||||
this->Change(std::make_unique<LoggedChangeGRFChanged>(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<const GRFConfig *> GenerateGRFList(const GRFConfig *grfc)
|
||||
static std::vector<const GRFConfig *> GenerateGRFList(const GRFConfigList &grfc)
|
||||
{
|
||||
std::vector<const GRFConfig *> 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<const GRFConfig *> 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<const GRFConfig *> ol = GenerateGRFList(oldc);
|
||||
std::vector<const GRFConfig *> 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<const LoggedChangeGRFChanged *>(lc.get());
|
||||
if (grf->grfid == c->ident.grfid) return grf;
|
||||
const LoggedChangeGRFChanged &grf = *static_cast<const LoggedChangeGRFChanged *>(lc.get());
|
||||
if (grf.grfid == c.ident.grfid) return grf;
|
||||
}
|
||||
|
||||
return &c->ident;
|
||||
return c.ident;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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. */
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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. */
|
||||
|
|
|
@ -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)
|
|||
* <li> GLC_NOT_FOUND: For one or more GRF's no match was found at all
|
||||
* </ul>
|
||||
*/
|
||||
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");
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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. */
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<SaveLoad> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -3063,7 +3063,7 @@ static SaveOrLoadResult DoLoad(std::shared_ptr<LoadFilter> 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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue