mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-27 22:06:05 -04:00
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:
parent
a5ad6c5e81
commit
6a070358eb
@ -5,6 +5,7 @@ import com.badlogic.gdx.math.Vector2
|
|||||||
import com.badlogic.gdx.scenes.scene2d.Group
|
import com.badlogic.gdx.scenes.scene2d.Group
|
||||||
import com.unciv.logic.HexMath
|
import com.unciv.logic.HexMath
|
||||||
import com.unciv.logic.map.TileInfo
|
import com.unciv.logic.map.TileInfo
|
||||||
|
import com.unciv.ui.tilegroups.ActionlessGroup
|
||||||
import com.unciv.ui.tilegroups.TileGroup
|
import com.unciv.ui.tilegroups.TileGroup
|
||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
@ -78,13 +79,13 @@ class TileGroupMap<T: TileGroup>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val baseLayers = ArrayList<Group>()
|
val baseLayers = ArrayList<ActionlessGroup>()
|
||||||
val featureLayers = ArrayList<Group>()
|
val featureLayers = ArrayList<ActionlessGroup>()
|
||||||
val miscLayers = ArrayList<Group>()
|
val miscLayers = ArrayList<ActionlessGroup>()
|
||||||
val unitLayers = ArrayList<Group>()
|
val unitLayers = ArrayList<Group>()
|
||||||
val unitImageLayers = ArrayList<Group>()
|
val unitImageLayers = ArrayList<ActionlessGroup>()
|
||||||
val cityButtonLayers = ArrayList<Group>()
|
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
|
// 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 }) {
|
for (group in tileGroups.sortedByDescending { it.tileInfo.position.x + it.tileInfo.position.y }) {
|
||||||
|
@ -182,7 +182,7 @@ class CityButton(val city: CityInfo, private val tileGroup: WorldTileGroup): Tab
|
|||||||
class IconTable: Table() {
|
class IconTable: Table() {
|
||||||
override fun draw(batch: Batch?, parentAlpha: Float) { super.draw(batch, parentAlpha) }
|
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.touchable = Touchable.enabled
|
||||||
iconTable.background = ImageGetter.getRoundedEdgeRectangle(city.civInfo.nation.getOuterColor())
|
iconTable.background = ImageGetter.getRoundedEdgeRectangle(city.civInfo.nation.getOuterColor())
|
||||||
|
|
||||||
|
@ -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 unitLayerGroup = UnitLayerGroupClass().apply { isTransform = false; setSize(groupSize, groupSize);touchable = Touchable.disabled }
|
||||||
val unitImageLayerGroup = UnitImageLayerGroupClass().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) }
|
touchable = Touchable.childrenOnly; setOrigin(Align.center) }
|
||||||
|
|
||||||
val highlightCrosshairFogLayerGroup = ActionlessGroup().apply { isTransform = false; setSize(groupSize, groupSize) }
|
val highlightCrosshairFogLayerGroup = ActionlessGroup().apply { isTransform = false; setSize(groupSize, groupSize) }
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.unciv.ui.utils
|
package com.unciv.ui.utils
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.Color
|
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.Actor
|
||||||
import com.badlogic.gdx.scenes.scene2d.Group
|
import com.badlogic.gdx.scenes.scene2d.Group
|
||||||
import com.badlogic.gdx.utils.Align
|
import com.badlogic.gdx.utils.Align
|
||||||
@ -20,4 +21,6 @@ class IconCircleGroup(size: Float, val actor: Actor, resizeActor: Boolean = true
|
|||||||
actor.setOrigin(Align.center)
|
actor.setOrigin(Align.center)
|
||||||
addActor(actor)
|
addActor(actor)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun draw(batch: Batch?, parentAlpha: Float) = super.draw(batch, parentAlpha)
|
||||||
}
|
}
|
||||||
|
@ -380,6 +380,7 @@ object ImageGetter {
|
|||||||
class VerticalProgressBar(width: Float, height: Float):Group() {
|
class VerticalProgressBar(width: Float, height: Float):Group() {
|
||||||
init {
|
init {
|
||||||
setSize(width, height)
|
setSize(width, height)
|
||||||
|
isTransform = false
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addColor(color: Color, percentage: Float): VerticalProgressBar {
|
fun addColor(color: Color, percentage: Float): VerticalProgressBar {
|
||||||
|
@ -17,6 +17,7 @@ import com.unciv.logic.civilization.CivilizationInfo
|
|||||||
import com.unciv.logic.map.MapShape
|
import com.unciv.logic.map.MapShape
|
||||||
import com.unciv.logic.map.MapSize
|
import com.unciv.logic.map.MapSize
|
||||||
import com.unciv.logic.map.TileInfo
|
import com.unciv.logic.map.TileInfo
|
||||||
|
import com.unciv.ui.tilegroups.ActionlessGroup
|
||||||
import com.unciv.ui.utils.IconCircleGroup
|
import com.unciv.ui.utils.IconCircleGroup
|
||||||
import com.unciv.ui.utils.ImageGetter
|
import com.unciv.ui.utils.ImageGetter
|
||||||
import com.unciv.ui.utils.onClick
|
import com.unciv.ui.utils.onClick
|
||||||
@ -24,11 +25,13 @@ import com.unciv.ui.utils.surroundWithCircle
|
|||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
import kotlin.math.min
|
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 allTiles = Group()
|
||||||
private val tileImages = HashMap<TileInfo, Image>()
|
private val tileImages = HashMap<TileInfo, Image>()
|
||||||
private val scrollPositionIndicators = ArrayList<ClippingImage>()
|
private val scrollPositionIndicators = ArrayList<ClippingImage>()
|
||||||
|
|
||||||
|
private val cityIconsGroup = ActionlessGroup()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
isTransform = false // don't try to resize rotate etc - this table has a LOT of children so that's valuable render time!
|
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)
|
allTiles.addActor(indicator)
|
||||||
}
|
}
|
||||||
|
|
||||||
add(allTiles)
|
setSize(allTiles.width, allTiles.height)
|
||||||
layout()
|
addActor(allTiles)
|
||||||
|
cityIconsGroup.setSize(width, height)
|
||||||
|
addActor(cityIconsGroup)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**### Transform and set coordinates for the scrollPositionIndicator.
|
/**### 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>()
|
private val cityIcons = HashMap<TileInfo, CivAndImage>()
|
||||||
|
|
||||||
fun update(cloneCivilization: CivilizationInfo) {
|
fun update(cloneCivilization: CivilizationInfo) {
|
||||||
for((tileInfo, hex) in tileImages) {
|
for ((tileInfo, hex) in tileImages) {
|
||||||
hex.color = when {
|
hex.color = when {
|
||||||
!(UncivGame.Current.viewEntireMapForDebug || cloneCivilization.exploredTiles.contains(tileInfo.position)) -> Color.DARK_GRAY
|
!(UncivGame.Current.viewEntireMapForDebug || cloneCivilization.exploredTiles.contains(tileInfo.position)) -> Color.DARK_GRAY
|
||||||
tileInfo.isCityCenter() && !tileInfo.isWater -> tileInfo.getOwner()!!.nation.getInnerColor()
|
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)
|
if (tileInfo.isCityCenter() && cloneCivilization.exploredTiles.contains(tileInfo.position)
|
||||||
&& (!cityIcons.containsKey(tileInfo) || cityIcons[tileInfo]!!.civInfo != tileInfo.getOwner())) {
|
&& (!cityIcons.containsKey(tileInfo) || cityIcons[tileInfo]!!.civInfo != tileInfo.getOwner())) {
|
||||||
if (cityIcons.containsKey(tileInfo)) cityIcons[tileInfo]!!.image.remove() // city changed hands - remove old icon
|
if (cityIcons.containsKey(tileInfo)) cityIcons[tileInfo]!!.image.remove() // city changed hands - remove old icon
|
||||||
val nationIcon= ImageGetter.getNationIndicator(tileInfo.getOwner()!!.nation,hex.width * 3)
|
val nation = tileInfo.getOwner()!!.nation
|
||||||
nationIcon.setPosition(hex.x - nationIcon.width/3,hex.y - nationIcon.height/3)
|
val nationIcon= ImageGetter.getCircle().apply { color = nation.getInnerColor() }.surroundWithCircle(hex.width, color = nation.getOuterColor())
|
||||||
|
nationIcon.setPosition(hex.x, hex.y)
|
||||||
nationIcon.onClick {
|
nationIcon.onClick {
|
||||||
mapHolder.setCenterPosition(tileInfo.position)
|
mapHolder.setCenterPosition(tileInfo.position)
|
||||||
}
|
}
|
||||||
allTiles.addActor(nationIcon)
|
cityIconsGroup.addActor(nationIcon)
|
||||||
cityIcons[tileInfo] = CivAndImage(tileInfo.getOwner()!!, 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() {
|
class MinimapHolder(val mapHolder: WorldMapHolder): Table() {
|
||||||
@ -242,6 +251,7 @@ class MinimapHolder(val mapHolder: WorldMapHolder): Table() {
|
|||||||
init {
|
init {
|
||||||
rebuildIfSizeChanged()
|
rebuildIfSizeChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun rebuildIfSizeChanged() {
|
private fun rebuildIfSizeChanged() {
|
||||||
val newMinimapSize = worldScreen.game.settings.minimapSize
|
val newMinimapSize = worldScreen.game.settings.minimapSize
|
||||||
if (newMinimapSize == minimapSize) return
|
if (newMinimapSize == minimapSize) return
|
||||||
@ -295,9 +305,7 @@ class MinimapHolder(val mapHolder: WorldMapHolder): Table() {
|
|||||||
|
|
||||||
|
|
||||||
// For debugging purposes
|
// For debugging purposes
|
||||||
override fun draw(batch: Batch?, parentAlpha: Float) {
|
override fun draw(batch: Batch?, parentAlpha: Float) = super.draw(batch, parentAlpha)
|
||||||
super.draw(batch, parentAlpha)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ClippingImage(drawable: Drawable) : Image(drawable) {
|
private class ClippingImage(drawable: Drawable) : Image(drawable) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user