perf(rendering): ignore unit layers with no units

This commit is contained in:
yairm210 2024-11-13 11:57:32 +02:00
parent 66357cf729
commit 086573b112
4 changed files with 15 additions and 7 deletions

View File

@ -1,5 +1,6 @@
package com.unciv.ui.components.tilegroups.layers 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.Touchable
import com.badlogic.gdx.scenes.scene2d.ui.Table import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.badlogic.gdx.utils.Align 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 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) for (child in children)
child.act(delta) child.act(delta)
} }
// For perf profiling
override fun draw(batch: Batch?, parentAlpha: Float) = super.draw(batch, parentAlpha)
private fun clearSlots() { private fun clearSlots() {
civilianUnitIcon?.remove() civilianUnitIcon?.remove()
militaryUnitIcon?.remove() militaryUnitIcon?.remove()

View File

@ -1,5 +1,6 @@
package com.unciv.ui.components.tilegroups.layers 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.Actor
import com.badlogic.gdx.scenes.scene2d.Group import com.badlogic.gdx.scenes.scene2d.Group
import com.unciv.UncivGame import com.unciv.UncivGame
@ -10,6 +11,9 @@ import com.unciv.ui.images.ImageGetter
import com.unciv.ui.components.tilegroups.TileGroup import com.unciv.ui.components.tilegroups.TileGroup
class UnitSpriteSlot : Group() { class UnitSpriteSlot : Group() {
init {
isTransform = false
}
var imageLocation = "" var imageLocation = ""
} }
@ -90,4 +94,9 @@ class TileLayerUnitSprite(tileGroup: TileGroup, size: Float) : TileLayer(tileGro
civilianSlot.imageLocation = "" civilianSlot.imageLocation = ""
militarySlot.imageLocation = "" militarySlot.imageLocation = ""
} }
override fun draw(batch: Batch?, parentAlpha: Float) {
if (civilianSlot.imageLocation.isEmpty() && militarySlot.imageLocation.isEmpty()) return
super.draw(batch, parentAlpha)
}
} }

View File

@ -87,7 +87,6 @@ class UnitIconGroup(val unit: MapUnit, val size: Float) : Group() {
private var flagMask: Image? = getBackgroundMaskForUnit() private var flagMask: Image? = getBackgroundMaskForUnit()
init { init {
isTransform = false // performance helper - nothing here is rotated or scaled isTransform = false // performance helper - nothing here is rotated or scaled
color.a *= UncivGame.Current.settings.unitIconOpacity color.a *= UncivGame.Current.settings.unitIconOpacity

View File

@ -962,9 +962,6 @@ Simple unique parameters are explained by mouseover. Complex parameters are expl
??? example "Can only heal by pillaging" ??? example "Can only heal by pillaging"
Applicable to: Global, Unit Applicable to: Global, Unit
??? example "Defense bonus when embarked"
Applicable to: Global, Unit
??? example "[relativeAmount]% maintenance costs" ??? example "[relativeAmount]% maintenance costs"
Example: "[+20]% maintenance costs" Example: "[+20]% maintenance costs"
@ -1901,9 +1898,6 @@ Simple unique parameters are explained by mouseover. Complex parameters are expl
Applicable to: Unit Applicable to: Unit
??? example "Defense bonus when embarked"
Applicable to: Global, Unit
??? example "No Sight" ??? example "No Sight"
Applicable to: Unit Applicable to: Unit