From 62bae6b166fc291bea792d0aa7f74a410dc4b72d Mon Sep 17 00:00:00 2001 From: yairm210 Date: Sun, 15 Dec 2024 12:32:59 +0200 Subject: [PATCH] perf(hit,act): local variables to save data (is null equality that hard to compute?! what's going on?!) --- .../components/tilegroups/layers/TileLayerUnitFlag.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/core/src/com/unciv/ui/components/tilegroups/layers/TileLayerUnitFlag.kt b/core/src/com/unciv/ui/components/tilegroups/layers/TileLayerUnitFlag.kt index f4cfe9ba5f..9fc9f9efaf 100644 --- a/core/src/com/unciv/ui/components/tilegroups/layers/TileLayerUnitFlag.kt +++ b/core/src/com/unciv/ui/components/tilegroups/layers/TileLayerUnitFlag.kt @@ -19,6 +19,7 @@ import com.unciv.ui.screens.basescreen.BaseScreen /** The unit flag is the synbol that appears behind the map unit - circle regularly, shield when defending, etc */ class TileLayerUnitFlag(tileGroup: TileGroup, size: Float) : TileLayer(tileGroup, size) { + private var noIcons = true private var civilianUnitIcon: UnitIconGroup? = null private var militaryUnitIcon: UnitIconGroup? = null @@ -27,14 +28,17 @@ class TileLayerUnitFlag(tileGroup: TileGroup, size: Float) : TileLayer(tileGroup } override fun act(delta: Float) { // No 'snapshotting' since we trust it will remain the same - if (civilianUnitIcon == null && militaryUnitIcon == null) + if (noIcons) return for (child in children) child.act(delta) } // For perf profiling - override fun draw(batch: Batch?, parentAlpha: Float) = super.draw(batch, parentAlpha) + override fun draw(batch: Batch?, parentAlpha: Float) { + if (noIcons) return + super.draw(batch, parentAlpha) + } private fun clearSlots() { civilianUnitIcon?.remove() @@ -139,6 +143,7 @@ class TileLayerUnitFlag(tileGroup: TileGroup, size: Float) : TileLayer(tileGroup civilianUnitIcon = newUnitIcon(0, tileGroup.tile.civilianUnit, isCivilianShown, viewingCiv) militaryUnitIcon = newUnitIcon(1, tileGroup.tile.militaryUnit, isMilitaryShown, viewingCiv) + noIcons = civilianUnitIcon == null && militaryUnitIcon == null } override fun doUpdate(viewingCiv: Civilization?, localUniqueCache: LocalUniqueCache) { @@ -159,6 +164,7 @@ class TileLayerUnitFlag(tileGroup: TileGroup, size: Float) : TileLayer(tileGroup fun reset() { clearSlots() + noIcons = true } }