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

@@ -62,6 +62,7 @@ struct Industry : IndustryPool::PoolItem<&_industry_pool> {
PartOfSubsidy part_of_subsidy; ///< NOSAVE: is this industry a source/destination of a subsidy?
StationList stations_near; ///< NOSAVE: List of nearby stations.
mutable std::string cached_name; ///< NOSAVE: Cache of the resolved name of the industry
Owner founder; ///< Founder of the industry
Date construction_date; ///< Date of the construction of the industry
@@ -157,10 +158,21 @@ struct Industry : IndustryPool::PoolItem<&_industry_pool> {
memset(&counts, 0, sizeof(counts));
}
inline const char *GetCachedName() const
{
if (this->cached_name.empty()) this->FillCachedName();
return this->cached_name.c_str();
}
private:
void FillCachedName() const;
protected:
static uint16 counts[NUM_INDUSTRYTYPES]; ///< Number of industries per type ingame
};
void ClearAllIndustryCachedNames();
void PlantRandomFarmField(const Industry *i);
void ReleaseDisastersTargetingIndustry(IndustryID);