mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-11 13:10:45 +00:00
Codechange: Update each town label dimensions once during map gen. (#12742)
This avoids re-layouting the label for each change in population as the town is grown.
This commit is contained in:
parent
96fc367bcf
commit
6d2424c0ef
@ -79,6 +79,8 @@ void RebuildTownKdtree()
|
||||
_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.
|
||||
@ -442,6 +444,8 @@ void ClearAllTownCachedNames()
|
||||
static void ChangePopulation(Town *t, int mod)
|
||||
{
|
||||
t->cache.population += mod;
|
||||
if (_generating_town) [[unlikely]] return;
|
||||
|
||||
InvalidateWindowData(WC_TOWN_VIEW, t->index); // Cargo requirements may appear/vanish for small populations
|
||||
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)
|
||||
{
|
||||
AutoRestoreBackup backup(_generating_town, true);
|
||||
|
||||
t->xy = tile;
|
||||
t->cache.num_houses = 0;
|
||||
t->time_until_rebuild = 10;
|
||||
@ -2016,9 +2022,6 @@ static void DoCreateTown(Town *t, TileIndex tile, uint32_t townnameparts, TownSi
|
||||
}
|
||||
t->townnameparts = townnameparts;
|
||||
|
||||
t->UpdateVirtCoord();
|
||||
InvalidateWindowData(WC_TOWN_DIRECTORY, 0, TDIWD_FORCE_REBUILD);
|
||||
|
||||
t->InitializeLayout(layout);
|
||||
|
||||
t->larger_town = city;
|
||||
@ -2036,6 +2039,9 @@ static void DoCreateTown(Town *t, TileIndex tile, uint32_t townnameparts, TownSi
|
||||
GrowTown(t);
|
||||
} while (--i);
|
||||
|
||||
t->UpdateVirtCoord();
|
||||
InvalidateWindowData(WC_TOWN_DIRECTORY, 0, TDIWD_FORCE_REBUILD);
|
||||
|
||||
t->cache.num_houses -= x;
|
||||
UpdateTownRadius(t);
|
||||
UpdateTownGrowthRate(t);
|
||||
|
Loading…
Reference in New Issue
Block a user