From f387de9506e59029850b8d3ef74ecc55f71aa42b Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Mon, 3 Apr 2023 11:13:29 +0300 Subject: [PATCH] performance: Don't update visible tiles if we've moved within our border --- .../logic/civilization/transients/CivInfoTransientCache.kt | 2 +- core/src/com/unciv/logic/map/mapunit/MapUnit.kt | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/core/src/com/unciv/logic/civilization/transients/CivInfoTransientCache.kt b/core/src/com/unciv/logic/civilization/transients/CivInfoTransientCache.kt index 9a65983151..4f249126d8 100644 --- a/core/src/com/unciv/logic/civilization/transients/CivInfoTransientCache.kt +++ b/core/src/com/unciv/logic/civilization/transients/CivInfoTransientCache.kt @@ -138,7 +138,7 @@ class CivInfoTransientCache(val civInfo: Civilization) { civInfo.viewableInvisibleUnitsTiles = newViewableInvisibleTiles } - private var ourTilesAndNeighboringTiles: Set = HashSet() + var ourTilesAndNeighboringTiles: Set = HashSet() /** Our tiles update pretty infrequently - most 'viewable tile' changes are due to unit movements, * which means we can store this separately and use it 'as is' so we don't need to find the neighboring tiles every time diff --git a/core/src/com/unciv/logic/map/mapunit/MapUnit.kt b/core/src/com/unciv/logic/map/mapunit/MapUnit.kt index fb4e4c1bfc..e09215204e 100644 --- a/core/src/com/unciv/logic/map/mapunit/MapUnit.kt +++ b/core/src/com/unciv/logic/map/mapunit/MapUnit.kt @@ -307,7 +307,10 @@ class MapUnit : IsPartOfGameInfoSerialization { } // Set equality automatically determines if anything changed - https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-abstract-set/equals.html - if (updateCivViewableTiles && oldViewableTiles != viewableTiles) + if (updateCivViewableTiles && oldViewableTiles != viewableTiles + // Don't bother updating if all previous and current viewable tiles are within our borders + && (oldViewableTiles.any { it !in civ.cache.ourTilesAndNeighboringTiles } + || viewableTiles.any { it !in civ.cache.ourTilesAndNeighboringTiles })) civ.cache.updateViewableTiles(explorerPosition) }