From 1c17a20018c81f46eecaf1f173a3f748fd1ca2ec Mon Sep 17 00:00:00 2001 From: yairm210 Date: Wed, 13 Nov 2024 12:04:59 +0200 Subject: [PATCH] perf(rendering): Don't try to find edge tiles unless we know other images have changes as well Ths is a trade off - on the one hand it means edge images will be drawn *above* improvements, on the other hand - profiling shows this is 11% of tile update time, which affects evey single user click! Possible good solution: saving the edge images on the tile itself, and refreshing this and neighboring tiles every time terrains are changed --- .../tilegroups/layers/TileLayerTerrain.kt | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) 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 602860ec3f..b15027ef3a 100644 --- a/core/src/com/unciv/ui/components/tilegroups/layers/TileLayerTerrain.kt +++ b/core/src/com/unciv/ui/components/tilegroups/layers/TileLayerTerrain.kt @@ -76,19 +76,14 @@ class TileLayerTerrain(tileGroup: TileGroup, size: Float) : TileLayer(tileGroup, val terrainImages = if (tile.naturalWonder != null) sequenceOf(tile.baseTerrain, tile.naturalWonder!!) else sequenceOf(tile.baseTerrain) + tile.terrainFeatures.asSequence() - val edgeImages = getEdgeTileLocations() val allTogether = (terrainImages + resourceAndImprovementSequence).joinToString("+") val allTogetherLocation = strings().getTile(allTogether) - // If the tilesetconfig *explicitly* lists the terrains+improvements etc, we can't know where in that list to place the edges - // So we default to placing them over everything else. - // If there is no explicit list, then we can know to place them between the terrain and the improvement return when { - strings().tileSetConfig.ruleVariants[allTogether] != null -> baseHexagon + - strings().tileSetConfig.ruleVariants[allTogether]!!.map { strings().getTile(it) } + edgeImages - ImageGetter.imageExists(allTogetherLocation) -> baseHexagon + allTogetherLocation + edgeImages - tile.naturalWonder != null -> getNaturalWonderBackupImage(baseHexagon) + edgeImages - else -> baseHexagon + getTerrainImageLocations(terrainImages) + edgeImages + getImprovementAndResourceImages(resourceAndImprovementSequence) + strings().tileSetConfig.ruleVariants[allTogether] != null -> baseHexagon + strings().tileSetConfig.ruleVariants[allTogether]!!.map { strings().getTile(it) } + ImageGetter.imageExists(allTogetherLocation) -> baseHexagon + allTogetherLocation + tile.naturalWonder != null -> getNaturalWonderBackupImage(baseHexagon) + else -> baseHexagon + getTerrainImageLocations(terrainImages) + getImprovementAndResourceImages(resourceAndImprovementSequence) } } @@ -114,7 +109,8 @@ class TileLayerTerrain(tileGroup: TileGroup, size: Float) : TileLayer(tileGroup, } private fun updateTileImage(viewingCiv: Civilization?) { - val tileBaseImageLocations = getTileBaseImageLocations(viewingCiv) + val tileBaseImageLocations = getTileBaseImageLocations(viewingCiv) + + getEdgeTileLocations() if (tileBaseImageLocations.size == tileImageIdentifiers.size) { if (tileBaseImageLocations.withIndex().all { (i, imageLocation) -> tileImageIdentifiers[i] == imageLocation })