diff --git a/core/src/com/unciv/ui/map/TileGroupMap.kt b/core/src/com/unciv/ui/map/TileGroupMap.kt index c81419f199..17babc084b 100644 --- a/core/src/com/unciv/ui/map/TileGroupMap.kt +++ b/core/src/com/unciv/ui/map/TileGroupMap.kt @@ -78,7 +78,6 @@ class TileGroupMap(val tileGroups: Collection, val padding: Flo // For debugging purposes - override fun draw(batch: Batch?, parentAlpha: Float) { - super.draw(batch, parentAlpha) - } + override fun draw(batch: Batch?, parentAlpha: Float) { super.draw(batch, parentAlpha) } + override fun act(delta: Float) { super.act(delta) } } \ No newline at end of file diff --git a/core/src/com/unciv/ui/tilegroups/TileGroup.kt b/core/src/com/unciv/ui/tilegroups/TileGroup.kt index ab14777e09..42b8a27b80 100644 --- a/core/src/com/unciv/ui/tilegroups/TileGroup.kt +++ b/core/src/com/unciv/ui/tilegroups/TileGroup.kt @@ -20,8 +20,13 @@ import kotlin.math.PI import kotlin.math.atan import kotlin.random.Random +/** A lot of the render time was spent on snapshot arrays of the TileGroupMap's groups, in the act() function. + * This class is to avoid the overhead of useless act() calls. */ +open class ActionlessGroup:Group(){ + override fun act(delta: Float) {} +} -open class TileGroup(var tileInfo: TileInfo, var tileSetStrings:TileSetStrings) : Group() { +open class TileGroup(var tileInfo: TileInfo, var tileSetStrings:TileSetStrings) : ActionlessGroup() { val groupSize = 54f /* @@ -34,7 +39,7 @@ open class TileGroup(var tileInfo: TileInfo, var tileSetStrings:TileSetStrings) */ // For recognizing the group in the profiler - class BaseLayerGroupClass:Group() + class BaseLayerGroupClass:ActionlessGroup() val baseLayerGroup = BaseLayerGroupClass().apply { isTransform = false; setSize(groupSize, groupSize) } protected var tileBaseImages: ArrayList = ArrayList() @@ -45,7 +50,7 @@ open class TileGroup(var tileInfo: TileInfo, var tileSetStrings:TileSetStrings) protected var baseTerrainOverlayImage: Image? = null protected var baseTerrain: String = "" - class TerrainFeatureLayerGroupClass:Group() + class TerrainFeatureLayerGroupClass:ActionlessGroup() val terrainFeatureLayerGroup = TerrainFeatureLayerGroupClass() .apply { isTransform = false; setSize(groupSize, groupSize) } @@ -56,11 +61,11 @@ open class TileGroup(var tileInfo: TileInfo, var tileSetStrings:TileSetStrings) protected var naturalWonderImage: Image? = null protected var pixelMilitaryUnitImageLocation = "" - protected var pixelMilitaryUnitGroup = Group().apply { isTransform = false; setSize(groupSize, groupSize) } + protected var pixelMilitaryUnitGroup = ActionlessGroup().apply { isTransform = false; setSize(groupSize, groupSize) } protected var pixelCivilianUnitImageLocation = "" - protected var pixelCivilianUnitGroup = Group().apply { isTransform = false; setSize(groupSize, groupSize) } + protected var pixelCivilianUnitGroup = ActionlessGroup().apply { isTransform = false; setSize(groupSize, groupSize) } - class MiscLayerGroupClass:Group(){ + class MiscLayerGroupClass:ActionlessGroup(){ override fun draw(batch: Batch?, parentAlpha: Float) { super.draw(batch, parentAlpha) } } val miscLayerGroup = MiscLayerGroupClass().apply { isTransform = false; setSize(groupSize, groupSize) } @@ -76,7 +81,7 @@ open class TileGroup(var tileInfo: TileInfo, var tileSetStrings:TileSetStrings) override fun draw(batch: Batch?, parentAlpha: Float) { super.draw(batch, parentAlpha) } } - class UnitImageLayerGroupClass:Group(){ + class UnitImageLayerGroupClass:ActionlessGroup(){ override fun draw(batch: Batch?, parentAlpha: Float) { super.draw(batch, parentAlpha) } } // We separate the units from the units' backgrounds, because all the background elements are in the same texture, and the units' aren't @@ -87,7 +92,7 @@ open class TileGroup(var tileInfo: TileInfo, var tileSetStrings:TileSetStrings) val cityButtonLayerGroup = Group().apply { setSize(groupSize, groupSize); touchable = Touchable.childrenOnly; setOrigin(Align.center) } - val circleCrosshairFogLayerGroup = Group().apply { isTransform = false; setSize(groupSize, groupSize) } + val circleCrosshairFogLayerGroup = ActionlessGroup().apply { isTransform = false; setSize(groupSize, groupSize) } private val circleImage = ImageGetter.getCircle() // for blue and red circles on the tile private val crosshairImage = ImageGetter.getImage("OtherIcons/Crosshair") // for when a unit is targete protected val fogImage = ImageGetter.getImage(tileSetStrings.crosshatchHexagon) @@ -687,13 +692,12 @@ open class TileGroup(var tileInfo: TileInfo, var tileSetStrings:TileSetStrings) } fun updateRiver(currentImage:Image?, shouldDisplay:Boolean,imageName:String): Image? { - if(!shouldDisplay){ + if (!shouldDisplay) { currentImage?.remove() return null - } - else{ - if(currentImage!=null) return currentImage - if(!ImageGetter.imageExists(imageName)) return null // Old "Default" tileset gets no rivers. + } else { + if (currentImage != null) return currentImage + if (!ImageGetter.imageExists(imageName)) return null // Old "Default" tileset gets no rivers. val newImage = ImageGetter.getImage(imageName) baseLayerGroup.addActor(newImage) setHexagonImageSize(newImage) @@ -711,7 +715,6 @@ open class TileGroup(var tileInfo: TileInfo, var tileSetStrings:TileSetStrings) } /** This exists so we can easily find the TileGroup draw method in the android profiling, otherwise it's just a mass of Group.draw->drawChildren->Group.draw etc. */ - override fun draw(batch: Batch?, parentAlpha: Float) { - super.draw(batch, parentAlpha) - } + override fun draw(batch: Batch?, parentAlpha: Float) { super.draw(batch, parentAlpha) } + override fun act(delta: Float) { super.act(delta) } }