summaryrefslogtreecommitdiff
path: root/src/town_cmd.cpp
diff options
context:
space:
mode:
authorJonathan G Rennison <j.g.rennison@gmail.com>2020-01-06 20:40:31 +0000
committerCharles Pigott <charlespigott@googlemail.com>2020-01-12 19:37:43 +0000
commitc3223903ed4f39abe8589355882b30b973da434e (patch)
tree9876dda172d7a076d7724efc52e21302bb7696a7 /src/town_cmd.cpp
parentf1734e7815653829d42ebd4def8c0d7d5aeae986 (diff)
downloadopenttd-c3223903ed4f39abe8589355882b30b973da434e.tar.xz
Codechange: Cache resolved town, station and industry name strings
Diffstat (limited to 'src/town_cmd.cpp')
-rw-r--r--src/town_cmd.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp
index 08ab17855..0a582eee7 100644
--- a/src/town_cmd.cpp
+++ b/src/town_cmd.cpp
@@ -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();