Codechange: Store grfid with entity grfprops.

This allows using the grfid without having to dereference the grffile pointer.

Uses no extra storage as it fits within otherwise wasted padding space.
This commit is contained in:
2024-11-23 14:05:42 +00:00
committed by Peter Nelson
parent e750d10cee
commit e73d6fcaac
24 changed files with 132 additions and 112 deletions

View File

@@ -1531,8 +1531,8 @@ public:
PickerItem GetPickerItem(int cls_id, int id) const override
{
const auto *spec = HouseSpec::Get(id);
if (spec->grf_prop.grffile == nullptr) return {0, spec->Index(), cls_id, id};
return {spec->grf_prop.grffile->grfid, spec->grf_prop.local_id, cls_id, id};
if (!spec->grf_prop.HasGrfFile()) return {0, spec->Index(), cls_id, id};
return {spec->grf_prop.grfid, spec->grf_prop.local_id, cls_id, id};
}
int GetSelectedType() const override { return sel_type; }
@@ -1587,7 +1587,7 @@ public:
dst.insert(item);
} else {
/* Search for spec by grfid and local index. */
auto it = std::ranges::find_if(specs, [&item](const HouseSpec &spec) { return spec.grf_prop.grffile != nullptr && spec.grf_prop.grffile->grfid == item.grfid && spec.grf_prop.local_id == item.local_id; });
auto it = std::ranges::find_if(specs, [&item](const HouseSpec &spec) { return spec.grf_prop.grfid == item.grfid && spec.grf_prop.local_id == item.local_id; });
if (it == specs.end()) {
/* Not preset, hide from UI. */
dst.insert({item.grfid, item.local_id, -1, -1});