Skip to content

Commit

Permalink
perf(rendering): ignore unit layers with no units
Browse files Browse the repository at this point in the history
  • Loading branch information
yairm210 committed Nov 13, 2024
1 parent 66357cf commit 086573b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 = ""
}

Expand Down Expand Up @@ -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)
}
}
1 change: 0 additions & 1 deletion core/src/com/unciv/ui/components/widgets/UnitIconGroup.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 0 additions & 6 deletions docs/Modders/uniques.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 086573b

Please sign in to comment.