1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-24 04:34:16 +01:00

Codechange: Use std::vector for GRFConfig lists. (#10835)

This replaces the C-style custom managed linked-list and allows use of iterators etc.
This commit is contained in:
Peter Nelson
2025-01-31 17:09:09 +00:00
committed by GitHub
parent 40aeedeade
commit 5664b1e2f6
23 changed files with 248 additions and 384 deletions

View File

@@ -17,7 +17,7 @@
ScriptNewGRFList::ScriptNewGRFList()
{
for (auto c = _grfconfig; c != nullptr; c = c->next) {
for (const auto &c : _grfconfig) {
if (!HasBit(c->flags, GCF_STATIC)) {
this->AddItem(std::byteswap(c->ident.grfid));
}
@@ -28,24 +28,15 @@ ScriptNewGRFList::ScriptNewGRFList()
{
grfid = std::byteswap(GB(grfid, 0, 32)); // Match people's expectations.
for (auto c = _grfconfig; c != nullptr; c = c->next) {
if (!HasBit(c->flags, GCF_STATIC) && c->ident.grfid == grfid) {
return true;
}
}
return false;
return std::ranges::any_of(_grfconfig, [grfid](const auto &c) { return !HasBit(c->flags, GCF_STATIC) && c->ident.grfid == grfid; });
}
/* static */ SQInteger ScriptNewGRF::GetVersion(SQInteger grfid)
{
grfid = std::byteswap(GB(grfid, 0, 32)); // Match people's expectations.
for (auto c = _grfconfig; c != nullptr; c = c->next) {
if (!HasBit(c->flags, GCF_STATIC) && c->ident.grfid == grfid) {
return c->version;
}
}
auto it = std::ranges::find_if(_grfconfig, [grfid](const auto &c) { return !HasBit(c->flags, GCF_STATIC) && c->ident.grfid == grfid; });
if (it != std::end(_grfconfig)) return (*it)->version;
return 0;
}
@@ -54,11 +45,8 @@ ScriptNewGRFList::ScriptNewGRFList()
{
grfid = std::byteswap(GB(grfid, 0, 32)); // Match people's expectations.
for (auto c = _grfconfig; c != nullptr; c = c->next) {
if (!HasBit(c->flags, GCF_STATIC) && c->ident.grfid == grfid) {
return c->GetName();
}
}
auto it = std::ranges::find_if(_grfconfig, [grfid](const auto &c) { return !HasBit(c->flags, GCF_STATIC) && c->ident.grfid == grfid; });
if (it != std::end(_grfconfig)) return (*it)->GetName();
return std::nullopt;
}