From c3c397aadeda16e8059229284e20eacd54770846 Mon Sep 17 00:00:00 2001 From: yairm210 Date: Sun, 15 Dec 2024 19:30:34 +0200 Subject: [PATCH] Revert "perf(tile-update): cache base data for tile rendering to only recompute when base data changes" This reverts commit 16f0a9844c0dcfd5d54922ec6a2cef022b77a486. --- .../tilegroups/layers/TileLayerCityButton.kt | 11 +++---- .../tilegroups/layers/TileLayerTerrain.kt | 31 +------------------ 2 files changed, 6 insertions(+), 36 deletions(-) diff --git a/core/src/com/unciv/ui/components/tilegroups/layers/TileLayerCityButton.kt b/core/src/com/unciv/ui/components/tilegroups/layers/TileLayerCityButton.kt index 5a1ac595b3..6941f5f028 100644 --- a/core/src/com/unciv/ui/components/tilegroups/layers/TileLayerCityButton.kt +++ b/core/src/com/unciv/ui/components/tilegroups/layers/TileLayerCityButton.kt @@ -14,7 +14,6 @@ import com.unciv.utils.DebugUtils class TileLayerCityButton(tileGroup: TileGroup, size: Float) : TileLayer(tileGroup, size) { private var cityButton: CityButton? = null - val tile = tileGroup.tile init { touchable = Touchable.childrenOnly @@ -22,18 +21,18 @@ class TileLayerCityButton(tileGroup: TileGroup, size: Float) : TileLayer(tileGro } override fun act(delta: Float) { - if (tile.isCityCenter()) + if (tileGroup.tile.isCityCenter()) super.act(delta) } override fun hit(x: Float, y: Float, touchable: Boolean): Actor? { - if (tile.isCityCenter()) + if (tileGroup.tile.isCityCenter()) return super.hit(x, y, touchable) return null } override fun draw(batch: Batch?, parentAlpha: Float) { - if (tile.isCityCenter()) + if (tileGroup.tile.isCityCenter()) super.draw(batch, parentAlpha) } @@ -48,7 +47,7 @@ class TileLayerCityButton(tileGroup: TileGroup, size: Float) : TileLayer(tileGro override fun doUpdate(viewingCiv: Civilization?, localUniqueCache: LocalUniqueCache) { if (tileGroup !is WorldTileGroup) return - val city = tile.getCity() + val city = tile().getCity() // There used to be a city here but it was razed if (city == null && cityButton != null) { @@ -57,7 +56,7 @@ class TileLayerCityButton(tileGroup: TileGroup, size: Float) : TileLayer(tileGro } if (viewingCiv == null) return - if (city == null || !tile.isCityCenter()) return + if (city == null || !tileGroup.tile.isCityCenter()) return // Create (if not yet) and update city button if (cityButton == null) { diff --git a/core/src/com/unciv/ui/components/tilegroups/layers/TileLayerTerrain.kt b/core/src/com/unciv/ui/components/tilegroups/layers/TileLayerTerrain.kt index 2c2d77ce62..e6686ba37f 100644 --- a/core/src/com/unciv/ui/components/tilegroups/layers/TileLayerTerrain.kt +++ b/core/src/com/unciv/ui/components/tilegroups/layers/TileLayerTerrain.kt @@ -47,7 +47,6 @@ class TileLayerTerrain(tileGroup: TileGroup, size: Float) : TileLayer(tileGroup, return ImageGetter.imageExists(strings().getTile("$shownImprovement-Pillaged")) } - var previousTileImageLocationData: TileImageLocationData? = null private fun getTileBaseImageLocations(viewingCiv: Civilization?): List { val isForceVisible = tileGroup.isForceVisible @@ -76,20 +75,6 @@ class TileLayerTerrain(tileGroup: TileGroup, size: Float) : TileLayer(tileGroup, } } - // Anything that, if changed, would change the terrain images - optimization to avoid unnecessary work - val tileImageLocationData = TileImageLocationData( - viewingCiv, - isForceVisible, - shownImprovement, - shouldShowImprovement, - shouldShowResource, - tile.baseTerrain, - tile.naturalWonder, - tile.terrainFeatures, - ) - if (previousTileImageLocationData == tileImageLocationData) return tileImageIdentifiers - else previousTileImageLocationData = tileImageLocationData - val terrainImages = if (tile.naturalWonder != null) sequenceOf(tile.baseTerrain, tile.naturalWonder!!) else sequenceOf(tile.baseTerrain) + tile.terrainFeatures.asSequence() @@ -103,8 +88,7 @@ class TileLayerTerrain(tileGroup: TileGroup, size: Float) : TileLayer(tileGroup, return when { strings().tileSetConfig.ruleVariants[allTogether] != null -> baseHexagon + strings().tileSetConfig.ruleVariants[allTogether]!!.map { strings().getTile(it) } + edgeImages - ImageGetter.imageExists(allTogetherLocation) -> - baseHexagon + allTogetherLocation + edgeImages + ImageGetter.imageExists(allTogetherLocation) -> baseHexagon + allTogetherLocation + edgeImages tile.naturalWonder != null -> getNaturalWonderBackupImage(baseHexagon) + edgeImages else -> baseHexagon + getTerrainImageLocations(terrainImages) + edgeImages + getImprovementAndResourceImages(resourceAndImprovementSequence) } @@ -137,21 +121,8 @@ class TileLayerTerrain(tileGroup: TileGroup, size: Float) : TileLayer(tileGroup, return@filter true }.map { it.fileName } } - - data class TileImageLocationData( - val viewingCiv: Civilization?, - val isForceVisible: Boolean, - val shownImprovement: String?, - val shouldShowImprovement: Boolean, - val shouldShowResource: Boolean, - val baseTerrain: String, - val naturalWonder: String?, - val terrainFeatures: List, - - ) private fun updateTileImage(viewingCiv: Civilization?) { - val tileBaseImageLocations = getTileBaseImageLocations(viewingCiv) if (tileBaseImageLocations.size == tileImageIdentifiers.size) {