From f5b0874c1cdf4d05f52a263aa081d0a8fb42ec52 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Mon, 1 Jul 2024 20:39:32 +0100 Subject: [PATCH] Do not unnecessarily update town label if local rating unchanged --- src/town.h | 2 +- src/town_cmd.cpp | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/town.h b/src/town.h index fdd563d4e6..810bc84d9d 100644 --- a/src/town.h +++ b/src/town.h @@ -168,7 +168,7 @@ struct Town : TownPool::PoolItem<&_town_pool> { return ClampTo((this->cache.population / _settings_game.economy.town_noise_population[_settings_game.difficulty.town_council_tolerance]) + 3); } - void UpdateVirtCoord(); + void UpdateVirtCoord(bool only_if_label_changed = false); inline const char *GetCachedName() const { diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index 70cd052548..3da9bdf7a7 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -532,10 +532,14 @@ static bool IsCloseToTown(TileIndex tile, uint dist) } /** Resize the sign (label) of the town after it changes population. */ -void Town::UpdateVirtCoord() +void Town::UpdateVirtCoord(bool only_if_label_changed) { if (IsHeadless()) return; + + auto label_rating = this->town_label_rating; this->UpdateLabel(); + if (only_if_label_changed && label_rating == this->town_label_rating) return; + Point pt = RemapCoords2(TileX(this->xy) * TILE_SIZE, TileY(this->xy) * TILE_SIZE); if (_viewport_sign_kdtree_valid && this->cache.sign.kdtree_valid) _viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeTown(this->index)); @@ -4142,7 +4146,7 @@ static void UpdateTownRating(Town *t) t->ratings[i] = Clamp(t->ratings[i], RATING_MINIMUM, RATING_MAXIMUM); } - t->UpdateVirtCoord(); + t->UpdateVirtCoord(true); SetWindowDirty(WC_TOWN_AUTHORITY, t->index); }