mirror of
https://github.com/yairm210/Unciv.git
synced 2025-02-11 11:28:03 +07:00
A large part of the rendering time was dedicated to trying to run actions on TileGroup groups, most of which can never have actions to begin with!
So now their act() does nothing, greatly improving framerate!
This commit is contained in:
parent
9dd7b2abf3
commit
01ee6cc768
@ -78,7 +78,6 @@ class TileGroupMap<T: TileGroup>(val tileGroups: Collection<T>, val padding: Flo
|
||||
|
||||
|
||||
// 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) }
|
||||
override fun act(delta: Float) { super.act(delta) }
|
||||
}
|
@ -20,8 +20,13 @@ import kotlin.math.PI
|
||||
import kotlin.math.atan
|
||||
import kotlin.random.Random
|
||||
|
||||
/** A lot of the render time was spent on snapshot arrays of the TileGroupMap's groups, in the act() function.
|
||||
* This class is to avoid the overhead of useless act() calls. */
|
||||
open class ActionlessGroup:Group(){
|
||||
override fun act(delta: Float) {}
|
||||
}
|
||||
|
||||
open class TileGroup(var tileInfo: TileInfo, var tileSetStrings:TileSetStrings) : Group() {
|
||||
open class TileGroup(var tileInfo: TileInfo, var tileSetStrings:TileSetStrings) : ActionlessGroup() {
|
||||
val groupSize = 54f
|
||||
|
||||
/*
|
||||
@ -34,7 +39,7 @@ open class TileGroup(var tileInfo: TileInfo, var tileSetStrings:TileSetStrings)
|
||||
*/
|
||||
|
||||
// For recognizing the group in the profiler
|
||||
class BaseLayerGroupClass:Group()
|
||||
class BaseLayerGroupClass:ActionlessGroup()
|
||||
val baseLayerGroup = BaseLayerGroupClass().apply { isTransform = false; setSize(groupSize, groupSize) }
|
||||
|
||||
protected var tileBaseImages: ArrayList<Image> = ArrayList()
|
||||
@ -45,7 +50,7 @@ open class TileGroup(var tileInfo: TileInfo, var tileSetStrings:TileSetStrings)
|
||||
protected var baseTerrainOverlayImage: Image? = null
|
||||
protected var baseTerrain: String = ""
|
||||
|
||||
class TerrainFeatureLayerGroupClass:Group()
|
||||
class TerrainFeatureLayerGroupClass:ActionlessGroup()
|
||||
val terrainFeatureLayerGroup = TerrainFeatureLayerGroupClass()
|
||||
.apply { isTransform = false; setSize(groupSize, groupSize) }
|
||||
|
||||
@ -56,11 +61,11 @@ open class TileGroup(var tileInfo: TileInfo, var tileSetStrings:TileSetStrings)
|
||||
protected var naturalWonderImage: Image? = null
|
||||
|
||||
protected var pixelMilitaryUnitImageLocation = ""
|
||||
protected var pixelMilitaryUnitGroup = Group().apply { isTransform = false; setSize(groupSize, groupSize) }
|
||||
protected var pixelMilitaryUnitGroup = ActionlessGroup().apply { isTransform = false; setSize(groupSize, groupSize) }
|
||||
protected var pixelCivilianUnitImageLocation = ""
|
||||
protected var pixelCivilianUnitGroup = Group().apply { isTransform = false; setSize(groupSize, groupSize) }
|
||||
protected var pixelCivilianUnitGroup = ActionlessGroup().apply { isTransform = false; setSize(groupSize, groupSize) }
|
||||
|
||||
class MiscLayerGroupClass:Group(){
|
||||
class MiscLayerGroupClass:ActionlessGroup(){
|
||||
override fun draw(batch: Batch?, parentAlpha: Float) { super.draw(batch, parentAlpha) }
|
||||
}
|
||||
val miscLayerGroup = MiscLayerGroupClass().apply { isTransform = false; setSize(groupSize, groupSize) }
|
||||
@ -76,7 +81,7 @@ open class TileGroup(var tileInfo: TileInfo, var tileSetStrings:TileSetStrings)
|
||||
override fun draw(batch: Batch?, parentAlpha: Float) { super.draw(batch, parentAlpha) }
|
||||
}
|
||||
|
||||
class UnitImageLayerGroupClass:Group(){
|
||||
class UnitImageLayerGroupClass:ActionlessGroup(){
|
||||
override fun draw(batch: Batch?, parentAlpha: Float) { super.draw(batch, parentAlpha) }
|
||||
}
|
||||
// We separate the units from the units' backgrounds, because all the background elements are in the same texture, and the units' aren't
|
||||
@ -87,7 +92,7 @@ open class TileGroup(var tileInfo: TileInfo, var tileSetStrings:TileSetStrings)
|
||||
val cityButtonLayerGroup = Group().apply { setSize(groupSize, groupSize);
|
||||
touchable = Touchable.childrenOnly; setOrigin(Align.center) }
|
||||
|
||||
val circleCrosshairFogLayerGroup = Group().apply { isTransform = false; setSize(groupSize, groupSize) }
|
||||
val circleCrosshairFogLayerGroup = ActionlessGroup().apply { isTransform = false; setSize(groupSize, groupSize) }
|
||||
private val circleImage = ImageGetter.getCircle() // for blue and red circles on the tile
|
||||
private val crosshairImage = ImageGetter.getImage("OtherIcons/Crosshair") // for when a unit is targete
|
||||
protected val fogImage = ImageGetter.getImage(tileSetStrings.crosshatchHexagon)
|
||||
@ -687,13 +692,12 @@ open class TileGroup(var tileInfo: TileInfo, var tileSetStrings:TileSetStrings)
|
||||
}
|
||||
|
||||
fun updateRiver(currentImage:Image?, shouldDisplay:Boolean,imageName:String): Image? {
|
||||
if(!shouldDisplay){
|
||||
if (!shouldDisplay) {
|
||||
currentImage?.remove()
|
||||
return null
|
||||
}
|
||||
else{
|
||||
if(currentImage!=null) return currentImage
|
||||
if(!ImageGetter.imageExists(imageName)) return null // Old "Default" tileset gets no rivers.
|
||||
} else {
|
||||
if (currentImage != null) return currentImage
|
||||
if (!ImageGetter.imageExists(imageName)) return null // Old "Default" tileset gets no rivers.
|
||||
val newImage = ImageGetter.getImage(imageName)
|
||||
baseLayerGroup.addActor(newImage)
|
||||
setHexagonImageSize(newImage)
|
||||
@ -711,7 +715,6 @@ open class TileGroup(var tileInfo: TileInfo, var tileSetStrings:TileSetStrings)
|
||||
}
|
||||
|
||||
/** This exists so we can easily find the TileGroup draw method in the android profiling, otherwise it's just a mass of Group.draw->drawChildren->Group.draw etc. */
|
||||
override fun draw(batch: Batch?, parentAlpha: Float) {
|
||||
super.draw(batch, parentAlpha)
|
||||
}
|
||||
override fun draw(batch: Batch?, parentAlpha: Float) { super.draw(batch, parentAlpha) }
|
||||
override fun act(delta: Float) { super.act(delta) }
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user