forked from mirror/OpenTTD
Codechange: Cache resolved town, station and industry name strings
This commit is contained in:
committed by
Charles Pigott
parent
f1734e7815
commit
c3223903ed
@@ -199,6 +199,13 @@ void Town::InitializeLayout(TownLayout layout)
|
||||
return Town::Get(index);
|
||||
}
|
||||
|
||||
void Town::FillCachedName() const
|
||||
{
|
||||
char buf[MAX_LENGTH_TOWN_NAME_CHARS * MAX_CHAR_LENGTH];
|
||||
char *end = GetTownName(buf, this, lastof(buf));
|
||||
this->cached_name.assign(buf, end);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cost for removing this house
|
||||
* @return the cost (inflation corrected etc)
|
||||
@@ -412,6 +419,13 @@ void UpdateAllTownVirtCoords()
|
||||
}
|
||||
}
|
||||
|
||||
void ClearAllTownCachedNames()
|
||||
{
|
||||
for (Town *t : Town::Iterate()) {
|
||||
t->cached_name.clear();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the towns population
|
||||
* @param t Town which population has changed
|
||||
@@ -2681,11 +2695,14 @@ CommandCost CmdRenameTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
|
||||
}
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
t->cached_name.clear();
|
||||
free(t->name);
|
||||
t->name = reset ? nullptr : stredup(text);
|
||||
|
||||
t->UpdateVirtCoord();
|
||||
InvalidateWindowData(WC_TOWN_DIRECTORY, 0, TDIWD_FORCE_RESORT);
|
||||
ClearAllStationCachedNames();
|
||||
ClearAllIndustryCachedNames();
|
||||
UpdateAllStationVirtCoords();
|
||||
}
|
||||
return CommandCost();
|
||||
|
Reference in New Issue
Block a user