Codechange: Cache resolved town, station and industry name strings

This commit is contained in:
Jonathan G Rennison
2020-01-06 20:40:31 +00:00
committed by Charles Pigott
parent f1734e7815
commit c3223903ed
10 changed files with 95 additions and 0 deletions

View File

@@ -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);