From aa21cf8a28f036afaa6442b3c9e7a3921950e1bd Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Mon, 7 Feb 2022 11:14:11 +0200 Subject: [PATCH] More tilegroup performance improvements - Only run orFallback once per TileSetStrings and not for every tilegroup We should probably have a dictionary of "original string to actual string" where orFallback only actually runs if the key isn't in the dictionary yet, otherwise it returns the stored value --- core/src/com/unciv/ui/tilegroups/TileGroup.kt | 12 ++++++------ core/src/com/unciv/ui/tilegroups/TileSetStrings.kt | 11 ++++++----- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/core/src/com/unciv/ui/tilegroups/TileGroup.kt b/core/src/com/unciv/ui/tilegroups/TileGroup.kt index a02931cd80..fa6b7bbd4e 100644 --- a/core/src/com/unciv/ui/tilegroups/TileGroup.kt +++ b/core/src/com/unciv/ui/tilegroups/TileGroup.kt @@ -123,9 +123,9 @@ open class TileGroup(var tileInfo: TileInfo, val tileSetStrings:TileSetStrings, touchable = Touchable.childrenOnly; setOrigin(Align.center) } val highlightCrosshairFogLayerGroup = ActionlessGroup().apply { isTransform = false; setSize(groupSize, groupSize) } - val highlightImage = ImageGetter.getImage(tileSetStrings.orFallback { getString(tileSetLocation, "Highlight") }) // for blue and red circles/emphasis on the tile - private val crosshairImage = ImageGetter.getImage(tileSetStrings.orFallback { getString(tileSetLocation, "Crosshair") }) // for when a unit is targeted - private val fogImage = ImageGetter.getImage(tileSetStrings.orFallback { crosshatchHexagon } ) + val highlightImage = ImageGetter.getImage(tileSetStrings.highlight) // for blue and red circles/emphasis on the tile + private val crosshairImage = ImageGetter.getImage(tileSetStrings.crosshair) // for when a unit is targeted + private val fogImage = ImageGetter.getImage(tileSetStrings.crosshatchHexagon ) /** * Class for representing an arrow to add to the map at this tile. @@ -730,9 +730,9 @@ open class TileGroup(var tileInfo: TileInfo, val tileSetStrings:TileSetStrings, private var bottomLeftRiverImage :Image?=null private fun updateRivers(displayBottomRight:Boolean, displayBottom:Boolean, displayBottomLeft:Boolean){ - bottomRightRiverImage = updateRiver(bottomRightRiverImage,displayBottomRight, tileSetStrings.orFallback { bottomRightRiver }) - bottomRiverImage = updateRiver(bottomRiverImage, displayBottom, tileSetStrings.orFallback { bottomRiver }) - bottomLeftRiverImage = updateRiver(bottomLeftRiverImage, displayBottomLeft, tileSetStrings.orFallback { bottomLeftRiver }) + bottomRightRiverImage = updateRiver(bottomRightRiverImage,displayBottomRight, tileSetStrings.bottomRightRiver) + bottomRiverImage = updateRiver(bottomRiverImage, displayBottom, tileSetStrings.bottomRiver) + bottomLeftRiverImage = updateRiver(bottomLeftRiverImage, displayBottomLeft, tileSetStrings.bottomLeftRiver) } private fun updateRiver(currentImage:Image?, shouldDisplay:Boolean,imageName:String): Image? { diff --git a/core/src/com/unciv/ui/tilegroups/TileSetStrings.kt b/core/src/com/unciv/ui/tilegroups/TileSetStrings.kt index b21089bff1..802daea855 100644 --- a/core/src/com/unciv/ui/tilegroups/TileSetStrings.kt +++ b/core/src/com/unciv/ui/tilegroups/TileSetStrings.kt @@ -20,7 +20,9 @@ class TileSetStrings(tileSet: String = UncivGame.Current.settings.tileSet, fallb // These need to be by lazy since the orFallback expects a tileset, which it may not get. val hexagon: String by lazy { orFallback {tileSetLocation + "Hexagon"} } val hexagonList by lazy { listOf(hexagon) } - val crosshatchHexagon = tileSetLocation + "CrosshatchHexagon" + val crosshatchHexagon by lazy { orFallback { tileSetLocation + "CrosshatchHexagon" } } + val crosshair by lazy { orFallback { getString(tileSetLocation, "Crosshair") } } + val highlight by lazy { orFallback { getString(tileSetLocation, "Highlight") } } val cityOverlay = tileSetLocation + "CityOverlay" val roadsMap = RoadStatus.values() .filterNot { it == RoadStatus.None } @@ -29,10 +31,9 @@ class TileSetStrings(tileSet: String = UncivGame.Current.settings.tileSet, fallb val tilesLocation = tileSetLocation + "Tiles/" val cityTile = tilesLocation + "City" - val bottomRightRiver = tilesLocation + "River-BottomRight" - val bottomRiver = tilesLocation + "River-Bottom" - val bottomLeftRiver = tilesLocation + "River-BottomLeft" - + val bottomRightRiver by lazy { orFallback { tilesLocation + "River-BottomRight"} } + val bottomRiver by lazy { orFallback { tilesLocation + "River-Bottom"} } + val bottomLeftRiver by lazy { orFallback { tilesLocation + "River-BottomLeft"} } val unitsLocation = tileSetLocation + "Units/" val landUnit = unitsLocation + "LandUnit" val waterUnit = unitsLocation + "WaterUnit"