Codechange: Cache resolved town, station and industry name strings
This commit is contained in:

committed by
Charles Pigott

parent
f1734e7815
commit
c3223903ed
12
src/town.h
12
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);
|
||||
|
||||
|
Reference in New Issue
Block a user