mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-27 05:46:43 -04:00
Separated the unit image rendering from the background rendering to avoid texture swapping when rendering unit + background
This commit is contained in:
parent
223da7f531
commit
378c8ab511
@ -167,7 +167,7 @@ class CityScreen(internal val city: CityInfo): CameraStageBaseScreen() {
|
||||
val tileSetStrings = TileSetStrings()
|
||||
val cityTileGroups = cityInfo.getCenterTile().getTilesInDistance(5)
|
||||
.filter { city.civInfo.exploredTiles.contains(it.position) }
|
||||
.map { CityTileGroup(cityInfo, it, tileSetStrings).apply { unitLayerGroup.isVisible = false } }
|
||||
.map { CityTileGroup(cityInfo, it, tileSetStrings) }
|
||||
|
||||
for (tileGroup in cityTileGroups) {
|
||||
val tileInfo = tileGroup.tileInfo
|
||||
|
@ -21,7 +21,8 @@ class CityTileGroup(private val city: CityInfo, tileInfo: TileInfo, tileSetStrin
|
||||
icons.addPopulationIcon(ImageGetter.getImage("OtherIcons/Star")
|
||||
.apply { color = Color.GOLD })
|
||||
}
|
||||
|
||||
unitLayerGroup.isVisible = false
|
||||
unitImageLayerGroup.isVisible = false
|
||||
}
|
||||
|
||||
fun update() {
|
||||
|
@ -35,6 +35,7 @@ class TileGroupMap<T: TileGroup>(val tileGroups: Collection<T>, val padding: Flo
|
||||
val featureLayers = ArrayList<Group>()
|
||||
val miscLayers = ArrayList<Group>()
|
||||
val unitLayers = ArrayList<Group>()
|
||||
val unitImageLayers = ArrayList<Group>()
|
||||
val cityButtonLayers = ArrayList<Group>()
|
||||
val circleCrosshairFogLayers = ArrayList<Group>()
|
||||
|
||||
@ -45,6 +46,7 @@ class TileGroupMap<T: TileGroup>(val tileGroups: Collection<T>, val padding: Flo
|
||||
featureLayers.add(group.terrainFeatureLayerGroup.apply { setPosition(group.x,group.y) })
|
||||
miscLayers.add(group.miscLayerGroup.apply { setPosition(group.x,group.y) })
|
||||
unitLayers.add(group.unitLayerGroup.apply { setPosition(group.x,group.y) })
|
||||
unitImageLayers.add(group.unitImageLayerGroup.apply { setPosition(group.x,group.y) })
|
||||
cityButtonLayers.add(group.cityButtonLayerGroup.apply { setPosition(group.x,group.y) })
|
||||
circleCrosshairFogLayers.add(group.circleCrosshairFogLayerGroup.apply { setPosition(group.x,group.y) })
|
||||
}
|
||||
@ -54,6 +56,7 @@ class TileGroupMap<T: TileGroup>(val tileGroups: Collection<T>, val padding: Flo
|
||||
for(group in circleCrosshairFogLayers) addActor(group)
|
||||
for(group in tileGroups) addActor(group) // The above layers are for the visual layers, this is for the clickability of the tile
|
||||
for(group in unitLayers) addActor(group) // Aaand units above everything else.
|
||||
for(group in unitImageLayers) addActor(group) // This is so the individual textures for the units are rendered together
|
||||
for(group in cityButtonLayers) addActor(group) // city buttons + clickability
|
||||
|
||||
|
||||
|
@ -75,7 +75,14 @@ open class TileGroup(var tileInfo: TileInfo, var tileSetStrings:TileSetStrings)
|
||||
class UnitLayerGroupClass:Group(){
|
||||
override fun draw(batch: Batch?, parentAlpha: Float) { super.draw(batch, parentAlpha) }
|
||||
}
|
||||
|
||||
class UnitImageLayerGroupClass:Group(){
|
||||
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
|
||||
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 { setSize(groupSize, groupSize);
|
||||
touchable = Touchable.childrenOnly; setOrigin(Align.center) }
|
||||
|
@ -65,6 +65,12 @@ class TileGroupIcons(val tileGroup: TileGroup){
|
||||
newImage.center(tileGroup)
|
||||
newImage.y += yFromCenter
|
||||
|
||||
// We "steal" the unit image so that all backgrounds are rendered next to each other
|
||||
// to save texture swapping and improve framerate
|
||||
tileGroup.unitImageLayerGroup.addActor(newImage.unitBaseImage)
|
||||
newImage.unitBaseImage.center(tileGroup)
|
||||
newImage.unitBaseImage.y += yFromCenter
|
||||
|
||||
// Display number of carried air units
|
||||
if (unit.getTile().airUnits.any { unit.isTransportTypeOf(it) } && !unit.getTile().isCityCenter()) {
|
||||
val holder = Table()
|
||||
|
@ -630,7 +630,7 @@ class WorldScreen(val viewingCiv:CivilizationInfo) : CameraStageBaseScreen() {
|
||||
update()
|
||||
showTutorialsOnNextTurn()
|
||||
}
|
||||
// topBar.selectedCivLabel.setText(Gdx.graphics.framesPerSecond) // for framerate testing
|
||||
topBar.selectedCivLabel.setText(Gdx.graphics.framesPerSecond) // for framerate testing
|
||||
|
||||
super.render(delta)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user