From 086573b112bde22a2b39ba12f83846862f8e2cab Mon Sep 17 00:00:00 2001 From: yairm210 Date: Wed, 13 Nov 2024 11:57:32 +0200 Subject: [PATCH] perf(rendering): ignore unit layers with no units --- .../ui/components/tilegroups/layers/TileLayerUnitFlag.kt | 6 ++++++ .../components/tilegroups/layers/TileLayerUnitSprite.kt | 9 +++++++++ .../src/com/unciv/ui/components/widgets/UnitIconGroup.kt | 1 - docs/Modders/uniques.md | 6 ------ 4 files changed, 15 insertions(+), 7 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 95374a4870..93f0b25a4f 100644 --- a/core/src/com/unciv/ui/components/tilegroups/layers/TileLayerUnitFlag.kt +++ b/core/src/com/unciv/ui/components/tilegroups/layers/TileLayerUnitFlag.kt @@ -1,5 +1,6 @@ package com.unciv.ui.components.tilegroups.layers +import com.badlogic.gdx.graphics.g2d.Batch import com.badlogic.gdx.scenes.scene2d.Touchable import com.badlogic.gdx.scenes.scene2d.ui.Table import com.badlogic.gdx.utils.Align @@ -26,10 +27,15 @@ 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) + return for (child in children) child.act(delta) } + // For perf profiling + override fun draw(batch: Batch?, parentAlpha: Float) = super.draw(batch, parentAlpha) + private fun clearSlots() { civilianUnitIcon?.remove() militaryUnitIcon?.remove() diff --git a/core/src/com/unciv/ui/components/tilegroups/layers/TileLayerUnitSprite.kt b/core/src/com/unciv/ui/components/tilegroups/layers/TileLayerUnitSprite.kt index e9209c8d75..2d78afb742 100644 --- a/core/src/com/unciv/ui/components/tilegroups/layers/TileLayerUnitSprite.kt +++ b/core/src/com/unciv/ui/components/tilegroups/layers/TileLayerUnitSprite.kt @@ -1,5 +1,6 @@ package com.unciv.ui.components.tilegroups.layers +import com.badlogic.gdx.graphics.g2d.Batch import com.badlogic.gdx.scenes.scene2d.Actor import com.badlogic.gdx.scenes.scene2d.Group import com.unciv.UncivGame @@ -10,6 +11,9 @@ import com.unciv.ui.images.ImageGetter import com.unciv.ui.components.tilegroups.TileGroup class UnitSpriteSlot : Group() { + init { + isTransform = false + } var imageLocation = "" } @@ -90,4 +94,9 @@ class TileLayerUnitSprite(tileGroup: TileGroup, size: Float) : TileLayer(tileGro civilianSlot.imageLocation = "" militarySlot.imageLocation = "" } + + override fun draw(batch: Batch?, parentAlpha: Float) { + if (civilianSlot.imageLocation.isEmpty() && militarySlot.imageLocation.isEmpty()) return + super.draw(batch, parentAlpha) + } } diff --git a/core/src/com/unciv/ui/components/widgets/UnitIconGroup.kt b/core/src/com/unciv/ui/components/widgets/UnitIconGroup.kt index 2bffcab1e3..12c1363399 100644 --- a/core/src/com/unciv/ui/components/widgets/UnitIconGroup.kt +++ b/core/src/com/unciv/ui/components/widgets/UnitIconGroup.kt @@ -87,7 +87,6 @@ class UnitIconGroup(val unit: MapUnit, val size: Float) : Group() { private var flagMask: Image? = getBackgroundMaskForUnit() init { - isTransform = false // performance helper - nothing here is rotated or scaled color.a *= UncivGame.Current.settings.unitIconOpacity diff --git a/docs/Modders/uniques.md b/docs/Modders/uniques.md index ca0720b828..b6b3856731 100644 --- a/docs/Modders/uniques.md +++ b/docs/Modders/uniques.md @@ -962,9 +962,6 @@ Simple unique parameters are explained by mouseover. Complex parameters are expl ??? example "Can only heal by pillaging" Applicable to: Global, Unit -??? example "Defense bonus when embarked" - Applicable to: Global, Unit - ??? example "[relativeAmount]% maintenance costs" Example: "[+20]% maintenance costs" @@ -1901,9 +1898,6 @@ Simple unique parameters are explained by mouseover. Complex parameters are expl Applicable to: Unit -??? example "Defense bonus when embarked" - Applicable to: Global, Unit - ??? example "No Sight" Applicable to: Unit