Rendering performance improvements - removed nation icon from minimap for less texture switching, set isTransform on vertical progress bars to false, added a ton of debug-help functions

This commit is contained in:
Yair Morgenstern 2022-02-11 10:30:37 +02:00
parent a5ad6c5e81
commit 6a070358eb
6 changed files with 36 additions and 17 deletions

View File

@ -5,6 +5,7 @@ import com.badlogic.gdx.math.Vector2
import com.badlogic.gdx.scenes.scene2d.Group
import com.unciv.logic.HexMath
import com.unciv.logic.map.TileInfo
import com.unciv.ui.tilegroups.ActionlessGroup
import com.unciv.ui.tilegroups.TileGroup
import kotlin.math.max
import kotlin.math.min
@ -78,13 +79,13 @@ class TileGroupMap<T: TileGroup>(
}
}
val baseLayers = ArrayList<Group>()
val featureLayers = ArrayList<Group>()
val miscLayers = ArrayList<Group>()
val baseLayers = ArrayList<ActionlessGroup>()
val featureLayers = ArrayList<ActionlessGroup>()
val miscLayers = ArrayList<ActionlessGroup>()
val unitLayers = ArrayList<Group>()
val unitImageLayers = ArrayList<Group>()
val unitImageLayers = ArrayList<ActionlessGroup>()
val cityButtonLayers = ArrayList<Group>()
val circleCrosshairFogLayers = ArrayList<Group>()
val circleCrosshairFogLayers = ArrayList<ActionlessGroup>()
// Apparently the sortedByDescending is kinda memory-intensive because it needs to sort ALL the tiles
for (group in tileGroups.sortedByDescending { it.tileInfo.position.x + it.tileInfo.position.y }) {

View File

@ -182,7 +182,7 @@ class CityButton(val city: CityInfo, private val tileGroup: WorldTileGroup): Tab
class IconTable: Table() {
override fun draw(batch: Batch?, parentAlpha: Float) { super.draw(batch, parentAlpha) }
}
val iconTable = IconTable()
val iconTable = IconTable().apply { isTransform = false }
iconTable.touchable = Touchable.enabled
iconTable.background = ImageGetter.getRoundedEdgeRectangle(city.civInfo.nation.getOuterColor())

View File

@ -119,7 +119,13 @@ open class TileGroup(var tileInfo: TileInfo, val tileSetStrings:TileSetStrings,
val unitLayerGroup = UnitLayerGroupClass().apply { isTransform = false; setSize(groupSize, groupSize);touchable = Touchable.disabled }
val unitImageLayerGroup = UnitImageLayerGroupClass().apply { isTransform = false; setSize(groupSize, groupSize);touchable = Touchable.disabled }
val cityButtonLayerGroup = Group().apply { isTransform = false; setSize(groupSize, groupSize)
class CityButtonLayerGroupClass:Group() {
override fun draw(batch: Batch?, parentAlpha: Float) = super.draw(batch, parentAlpha)
override fun act(delta: Float) = super.act(delta)
override fun hit(x: Float, y: Float, touchable: Boolean) = super.hit(x, y, touchable)
}
val cityButtonLayerGroup = CityButtonLayerGroupClass().apply { isTransform = false; setSize(groupSize, groupSize)
touchable = Touchable.childrenOnly; setOrigin(Align.center) }
val highlightCrosshairFogLayerGroup = ActionlessGroup().apply { isTransform = false; setSize(groupSize, groupSize) }

View File

@ -1,6 +1,7 @@
package com.unciv.ui.utils
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.Batch
import com.badlogic.gdx.scenes.scene2d.Actor
import com.badlogic.gdx.scenes.scene2d.Group
import com.badlogic.gdx.utils.Align
@ -20,4 +21,6 @@ class IconCircleGroup(size: Float, val actor: Actor, resizeActor: Boolean = true
actor.setOrigin(Align.center)
addActor(actor)
}
override fun draw(batch: Batch?, parentAlpha: Float) = super.draw(batch, parentAlpha)
}

View File

@ -380,6 +380,7 @@ object ImageGetter {
class VerticalProgressBar(width: Float, height: Float):Group() {
init {
setSize(width, height)
isTransform = false
}
fun addColor(color: Color, percentage: Float): VerticalProgressBar {

View File

@ -17,6 +17,7 @@ import com.unciv.logic.civilization.CivilizationInfo
import com.unciv.logic.map.MapShape
import com.unciv.logic.map.MapSize
import com.unciv.logic.map.TileInfo
import com.unciv.ui.tilegroups.ActionlessGroup
import com.unciv.ui.utils.IconCircleGroup
import com.unciv.ui.utils.ImageGetter
import com.unciv.ui.utils.onClick
@ -24,11 +25,13 @@ import com.unciv.ui.utils.surroundWithCircle
import kotlin.math.max
import kotlin.math.min
class Minimap(val mapHolder: WorldMapHolder, minimapSize: Int) : Table(){
class Minimap(val mapHolder: WorldMapHolder, minimapSize: Int) : Group(){
private val allTiles = Group()
private val tileImages = HashMap<TileInfo, Image>()
private val scrollPositionIndicators = ArrayList<ClippingImage>()
private val cityIconsGroup = ActionlessGroup()
init {
isTransform = false // don't try to resize rotate etc - this table has a LOT of children so that's valuable render time!
@ -93,8 +96,10 @@ class Minimap(val mapHolder: WorldMapHolder, minimapSize: Int) : Table(){
allTiles.addActor(indicator)
}
add(allTiles)
layout()
setSize(allTiles.width, allTiles.height)
addActor(allTiles)
cityIconsGroup.setSize(width, height)
addActor(cityIconsGroup)
}
/**### Transform and set coordinates for the scrollPositionIndicator.
@ -135,7 +140,7 @@ class Minimap(val mapHolder: WorldMapHolder, minimapSize: Int) : Table(){
private val cityIcons = HashMap<TileInfo, CivAndImage>()
fun update(cloneCivilization: CivilizationInfo) {
for((tileInfo, hex) in tileImages) {
for ((tileInfo, hex) in tileImages) {
hex.color = when {
!(UncivGame.Current.viewEntireMapForDebug || cloneCivilization.exploredTiles.contains(tileInfo.position)) -> Color.DARK_GRAY
tileInfo.isCityCenter() && !tileInfo.isWater -> tileInfo.getOwner()!!.nation.getInnerColor()
@ -146,16 +151,20 @@ class Minimap(val mapHolder: WorldMapHolder, minimapSize: Int) : Table(){
if (tileInfo.isCityCenter() && cloneCivilization.exploredTiles.contains(tileInfo.position)
&& (!cityIcons.containsKey(tileInfo) || cityIcons[tileInfo]!!.civInfo != tileInfo.getOwner())) {
if (cityIcons.containsKey(tileInfo)) cityIcons[tileInfo]!!.image.remove() // city changed hands - remove old icon
val nationIcon= ImageGetter.getNationIndicator(tileInfo.getOwner()!!.nation,hex.width * 3)
nationIcon.setPosition(hex.x - nationIcon.width/3,hex.y - nationIcon.height/3)
val nation = tileInfo.getOwner()!!.nation
val nationIcon= ImageGetter.getCircle().apply { color = nation.getInnerColor() }.surroundWithCircle(hex.width, color = nation.getOuterColor())
nationIcon.setPosition(hex.x, hex.y)
nationIcon.onClick {
mapHolder.setCenterPosition(tileInfo.position)
}
allTiles.addActor(nationIcon)
cityIconsGroup.addActor(nationIcon)
cityIcons[tileInfo] = CivAndImage(tileInfo.getOwner()!!, nationIcon)
}
}
}
// For debugging purposes
override fun draw(batch: Batch?, parentAlpha: Float) = super.draw(batch, parentAlpha)
}
class MinimapHolder(val mapHolder: WorldMapHolder): Table() {
@ -242,6 +251,7 @@ class MinimapHolder(val mapHolder: WorldMapHolder): Table() {
init {
rebuildIfSizeChanged()
}
private fun rebuildIfSizeChanged() {
val newMinimapSize = worldScreen.game.settings.minimapSize
if (newMinimapSize == minimapSize) return
@ -295,9 +305,7 @@ class MinimapHolder(val mapHolder: WorldMapHolder): Table() {
// 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)
}
private class ClippingImage(drawable: Drawable) : Image(drawable) {