Codechange: Cache resolved town, station and industry name strings
This commit is contained in:
committed by
Charles Pigott
parent
f1734e7815
commit
c3223903ed
@@ -56,6 +56,7 @@ struct BaseStation : StationPool::PoolItem<&_station_pool> {
|
||||
|
||||
char *name; ///< Custom name
|
||||
StringID string_id; ///< Default name (town area) of station
|
||||
mutable std::string cached_name; ///< NOSAVE: Cache of the resolved name of the station, if not using a custom name
|
||||
|
||||
Town *town; ///< The town this station is associated with
|
||||
Owner owner; ///< The owner of this station
|
||||
@@ -108,6 +109,13 @@ struct BaseStation : StationPool::PoolItem<&_station_pool> {
|
||||
*/
|
||||
virtual void UpdateVirtCoord() = 0;
|
||||
|
||||
inline const char *GetCachedName() const
|
||||
{
|
||||
if (this->name != nullptr) return this->name;
|
||||
if (this->cached_name.empty()) this->FillCachedName();
|
||||
return this->cached_name.c_str();
|
||||
}
|
||||
|
||||
virtual void MoveSign(TileIndex new_xy)
|
||||
{
|
||||
this->xy = new_xy;
|
||||
@@ -161,6 +169,9 @@ struct BaseStation : StationPool::PoolItem<&_station_pool> {
|
||||
}
|
||||
|
||||
static void PostDestructor(size_t index);
|
||||
|
||||
private:
|
||||
void FillCachedName() const;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user