performance: Don't update visible tiles if we've moved within our border

This commit is contained in:
Yair Morgenstern 2023-04-03 11:13:29 +03:00
parent ad299a8a62
commit f387de9506
2 changed files with 5 additions and 2 deletions

View File

@ -138,7 +138,7 @@ class CivInfoTransientCache(val civInfo: Civilization) {
civInfo.viewableInvisibleUnitsTiles = newViewableInvisibleTiles civInfo.viewableInvisibleUnitsTiles = newViewableInvisibleTiles
} }
private var ourTilesAndNeighboringTiles: Set<Tile> = HashSet() var ourTilesAndNeighboringTiles: Set<Tile> = HashSet()
/** Our tiles update pretty infrequently - most 'viewable tile' changes are due to unit movements, /** 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 * which means we can store this separately and use it 'as is' so we don't need to find the neighboring tiles every time

View File

@ -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 // 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) civ.cache.updateViewableTiles(explorerPosition)
} }