Performance - copy resourceCache, and don't reassign population and update civ resources, when checking improvement stat diff

This commit is contained in:
Yair Morgenstern 2023-08-29 22:38:26 +03:00
parent bf687f2f0f
commit 41fa29f50c
3 changed files with 8 additions and 4 deletions

View File

@ -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
}

View File

@ -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()
}
}
}

View File

@ -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