From 41fa29f50c7d5fed8cad46cebe45ce4cbf2c6631 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Tue, 29 Aug 2023 22:38:26 +0300 Subject: [PATCH] Performance - copy resourceCache, and don't reassign population and update civ resources, when checking improvement stat diff --- core/src/com/unciv/logic/map/tile/Tile.kt | 2 ++ .../unciv/logic/map/tile/TileInfoImprovementFunctions.kt | 6 ++++-- core/src/com/unciv/ui/screens/cityscreen/CityScreen.kt | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/core/src/com/unciv/logic/map/tile/Tile.kt b/core/src/com/unciv/logic/map/tile/Tile.kt index 69eb9e48ee..d0d65d0efc 100644 --- a/core/src/com/unciv/logic/map/tile/Tile.kt +++ b/core/src/com/unciv/logic/map/tile/Tile.kt @@ -179,6 +179,8 @@ open class Tile : IsPartOfGameInfoSerialization { toReturn.continent = continent toReturn.exploredBy = exploredBy toReturn.history = history.clone() + // Setting even though it's transient - where it's needed, it's a real performance saver + toReturn.tileResourceCache = tileResourceCache return toReturn } diff --git a/core/src/com/unciv/logic/map/tile/TileInfoImprovementFunctions.kt b/core/src/com/unciv/logic/map/tile/TileInfoImprovementFunctions.kt index d8c29e7805..9e16029da8 100644 --- a/core/src/com/unciv/logic/map/tile/TileInfoImprovementFunctions.kt +++ b/core/src/com/unciv/logic/map/tile/TileInfoImprovementFunctions.kt @@ -208,8 +208,10 @@ class TileInfoImprovementFunctions(val tile: Tile) { val city = tile.owningCity if (city != null) { city.cityStats.update() - city.civ.cache.updateCivResources() - city.reassignPopulationDeferred() + if (civToActivateBroaderEffects != null) { + city.civ.cache.updateCivResources() + city.reassignPopulationDeferred() + } } } diff --git a/core/src/com/unciv/ui/screens/cityscreen/CityScreen.kt b/core/src/com/unciv/ui/screens/cityscreen/CityScreen.kt index 51db6c5020..75200dac62 100644 --- a/core/src/com/unciv/ui/screens/cityscreen/CityScreen.kt +++ b/core/src/com/unciv/ui/screens/cityscreen/CityScreen.kt @@ -206,7 +206,7 @@ class CityScreen( private fun updateTileGroups() { val cityUniqueCache = LocalUniqueCache() - fun isExistingImprovementValuable(tile: Tile, improvementToPlace: TileImprovement): Boolean { + fun isExistingImprovementValuable(tile: Tile): Boolean { if (tile.improvement == null) return false val civInfo = city.civ @@ -226,7 +226,7 @@ class CityScreen( return when { tile.isMarkedForCreatesOneImprovement() -> Color.BROWN to 0.7f !tile.improvementFunctions.canBuildImprovement(improvementToPlace, city.civ) -> Color.RED to 0.4f - isExistingImprovementValuable(tile, improvementToPlace) -> Color.ORANGE to 0.5f + isExistingImprovementValuable(tile) -> Color.ORANGE to 0.5f tile.improvement != null -> Color.YELLOW to 0.6f tile.turnsToImprovement > 0 -> Color.YELLOW to 0.6f else -> Color.GREEN to 0.5f