mirror of
https://github.com/OpenTTD/OpenTTD
synced 2026-01-23 04:04:09 +01:00
Codechange: Use variable storage for GrfProps with cargo-type groups. (#13557)
Slots are only allocated when used instead of being reserved. Array-based GrfProps are still used when the number of options is more limited.
This commit is contained in:
@@ -756,3 +756,30 @@ void NewGRFSpriteLayout::ProcessRegisters(uint8_t resolved_var10, uint32_t resol
|
||||
if (regs != nullptr) regs++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the SpriteGroup at the specified index.
|
||||
* @param index Index to get.
|
||||
* @returns SpriteGroup at index, or nullptr if not present.
|
||||
*/
|
||||
const SpriteGroup *VariableGRFFileProps::GetSpriteGroup(size_t index) const
|
||||
{
|
||||
auto it = std::ranges::lower_bound(this->spritegroups, index, std::less{}, &CargoSpriteGroup::first);
|
||||
if (it == std::end(this->spritegroups) || it->first != index) return nullptr;
|
||||
return it->second;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the SpriteGroup at the specified index.
|
||||
* @param index Index to set.
|
||||
* @param spritegroup SpriteGroup to set.
|
||||
*/
|
||||
void VariableGRFFileProps::SetSpriteGroup(size_t index, const SpriteGroup *spritegroup)
|
||||
{
|
||||
auto it = std::ranges::lower_bound(this->spritegroups, index, std::less{}, &CargoSpriteGroup::first);
|
||||
if (it == std::end(this->spritegroups) || it->first != index) {
|
||||
this->spritegroups.emplace(it, index, spritegroup);
|
||||
} else {
|
||||
it->second = spritegroup;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user