1
0
Fork 0

Codechange: Update each town label dimensions once during map gen.

This avoids re-layouting the label for each change in population as the town is grown.
pull/12742/head
Peter Nelson 2024-05-28 12:13:01 +01:00
parent 3827229c74
commit 66de82fe82
No known key found for this signature in database
GPG Key ID: 8EF8F0A467DF75ED
1 changed files with 9 additions and 3 deletions

View File

@ -79,6 +79,8 @@ void RebuildTownKdtree()
_town_kdtree.Build(townids.begin(), townids.end()); _town_kdtree.Build(townids.begin(), townids.end());
} }
/** Set if a town is being generated. */
static bool _generating_town = false;
/** /**
* Check if a town 'owns' a bridge. * Check if a town 'owns' a bridge.
@ -442,6 +444,8 @@ void ClearAllTownCachedNames()
static void ChangePopulation(Town *t, int mod) static void ChangePopulation(Town *t, int mod)
{ {
t->cache.population += mod; t->cache.population += mod;
if (_generating_town) [[unlikely]] return;
InvalidateWindowData(WC_TOWN_VIEW, t->index); // Cargo requirements may appear/vanish for small populations InvalidateWindowData(WC_TOWN_VIEW, t->index); // Cargo requirements may appear/vanish for small populations
if (_settings_client.gui.population_in_label) t->UpdateVirtCoord(); if (_settings_client.gui.population_in_label) t->UpdateVirtCoord();
@ -1973,6 +1977,8 @@ static void UpdateTownGrowth(Town *t);
*/ */
static void DoCreateTown(Town *t, TileIndex tile, uint32_t townnameparts, TownSize size, bool city, TownLayout layout, bool manual) static void DoCreateTown(Town *t, TileIndex tile, uint32_t townnameparts, TownSize size, bool city, TownLayout layout, bool manual)
{ {
AutoRestoreBackup backup(_generating_town, true);
t->xy = tile; t->xy = tile;
t->cache.num_houses = 0; t->cache.num_houses = 0;
t->time_until_rebuild = 10; t->time_until_rebuild = 10;
@ -2016,9 +2022,6 @@ static void DoCreateTown(Town *t, TileIndex tile, uint32_t townnameparts, TownSi
} }
t->townnameparts = townnameparts; t->townnameparts = townnameparts;
t->UpdateVirtCoord();
InvalidateWindowData(WC_TOWN_DIRECTORY, 0, TDIWD_FORCE_REBUILD);
t->InitializeLayout(layout); t->InitializeLayout(layout);
t->larger_town = city; t->larger_town = city;
@ -2036,6 +2039,9 @@ static void DoCreateTown(Town *t, TileIndex tile, uint32_t townnameparts, TownSi
GrowTown(t); GrowTown(t);
} while (--i); } while (--i);
t->UpdateVirtCoord();
InvalidateWindowData(WC_TOWN_DIRECTORY, 0, TDIWD_FORCE_REBUILD);
t->cache.num_houses -= x; t->cache.num_houses -= x;
UpdateTownRadius(t); UpdateTownRadius(t);
UpdateTownGrowthRate(t); UpdateTownGrowthRate(t);