diff options
author | Jonathan G Rennison <j.g.rennison@gmail.com> | 2020-01-06 20:40:31 +0000 |
---|---|---|
committer | Charles Pigott <charlespigott@googlemail.com> | 2020-01-12 19:37:43 +0000 |
commit | c3223903ed4f39abe8589355882b30b973da434e (patch) | |
tree | 9876dda172d7a076d7724efc52e21302bb7696a7 /src/town.h | |
parent | f1734e7815653829d42ebd4def8c0d7d5aeae986 (diff) | |
download | openttd-c3223903ed4f39abe8589355882b30b973da434e.tar.xz |
Codechange: Cache resolved town, station and industry name strings
Diffstat (limited to 'src/town.h')
-rw-r--r-- | src/town.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/town.h b/src/town.h index 9898e3fb6..8399fa63f 100644 --- a/src/town.h +++ b/src/town.h @@ -60,6 +60,7 @@ struct Town : TownPool::PoolItem<&_town_pool> { uint16 townnametype; uint32 townnameparts; char *name; ///< Custom town name. If nullptr, the town was not renamed and uses the generated name. + mutable std::string cached_name; ///< NOSAVE: Cache of the resolved name of the town, if not using a custom town name byte flags; ///< See #TownFlags. @@ -130,6 +131,13 @@ struct Town : TownPool::PoolItem<&_town_pool> { void UpdateVirtCoord(); + 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(); + } + static inline Town *GetByTile(TileIndex tile) { return Town::Get(GetTownIndex(tile)); @@ -137,11 +145,15 @@ struct Town : TownPool::PoolItem<&_town_pool> { static Town *GetRandom(); static void PostDestructor(size_t index); + +private: + void FillCachedName() const; }; uint32 GetWorldPopulation(); void UpdateAllTownVirtCoords(); +void ClearAllTownCachedNames(); void ShowTownViewWindow(TownID town); void ExpandTown(Town *t); |