Organized all game images and added TexturPacker to pack them all into a single image, with an atlas to find the texture regions -

MASSIVE boost in rendering performance!
This commit is contained in:
Yair Morgenstern
2018-08-10 11:05:21 +03:00
parent 4d27f7f769
commit c67d515ec4
186 changed files with 1200 additions and 19 deletions

View File

@ -28,15 +28,13 @@ class CityScreen(internal val city: CityInfo) : CameraStageBaseScreen() {
addTiles()
stage.addActor(tileTable)
val tileTableBackground = com.unciv.ui.utils.ImageGetter.getDrawable("skin/tileTableBackground.png")
.tint(Color(0x0040804f))
tileTableBackground.minHeight = 0f
tileTableBackground.minWidth = 0f
tileTable.background = tileTableBackground
val tableBackgroundColor = ImageGetter.getBlue().lerp(Color.BLACK,0.5f)
tileTable.background = ImageGetter.getBackground(tableBackgroundColor)
val buildingsTableContainer = Table()
buildingsTableContainer.pad(20f)
buildingsTableContainer.background = tileTableBackground
buildingsTableContainer.background = ImageGetter.getBackground(tableBackgroundColor)
buildingsTable.update()
val buildingsScroll = ScrollPane(buildingsTable)
buildingsTableContainer.add(buildingsScroll).height(stage.height / 2)
@ -45,7 +43,7 @@ class CityScreen(internal val city: CityInfo) : CameraStageBaseScreen() {
buildingsTableContainer.setPosition(stage.width - buildingsTableContainer.width,
stage.height - buildingsTableContainer.height)
cityStatsTable.background = tileTableBackground
cityStatsTable.background = ImageGetter.getBackground(tableBackgroundColor)
stage.addActor(cityStatsTable)
stage.addActor(goToWorldButton)
stage.addActor(cityPickerTable)

View File

@ -44,6 +44,7 @@ open class TileGroup(var tileInfo: TileInfo) : Group() {
addCircleImage()
addFogImage()
addCrosshairImage()
isTransform=false
}
private fun addCircleImage() {

View File

@ -72,7 +72,7 @@ class WorldTileGroup(tileInfo: TileInfo) : TileGroup(tileInfo) {
if (city != null && tileInfo.isCityCenter()) {
if (cityButton == null) {
cityButton = Table()
cityButton!!.background = ImageGetter.getDrawable("skin/civTableBackground.png")
cityButton!!.background = ImageGetter.getDrawable("OtherIcons/civTableBackground.png")
cityButton!!.isTransform = true
addActor(cityButton)

View File

@ -1,8 +1,7 @@
package com.unciv.ui.utils
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.Texture
import com.badlogic.gdx.graphics.g2d.TextureAtlas
import com.badlogic.gdx.graphics.g2d.TextureRegion
import com.badlogic.gdx.scenes.scene2d.ui.Image
import com.badlogic.gdx.scenes.scene2d.utils.Drawable
@ -11,7 +10,17 @@ import java.util.*
object ImageGetter {
private var textureRegionByFileName = HashMap<String, TextureRegion>()
const val WhiteDot = "skin/whiteDot.png"
const val WhiteDot = "OtherIcons/whiteDot.png"
// When we used to load images directly from different files, without using a texture atlas,
// The draw() phase of the main screen would take a really long time because the BatchRenderer would
// always have to switch between like 170 different textures.
// So, we now use TexturePacker in the DesktopLauncher class to pack all the different images into single images,
// and the atlas is what tells us what was packed where.
val atlas = TextureAtlas("Images/game.atlas")
init{
}
fun getImage(fileName: String): Image {
return Image(getTextureRegion(fileName))
@ -26,11 +35,11 @@ object ImageGetter {
private fun getTextureRegion(fileName: String): TextureRegion {
try {
if (!textureRegionByFileName.containsKey(fileName)) {
val texture = Texture(Gdx.files.internal(fileName),true)
texture.setFilter(Texture.TextureFilter.MipMapLinearLinear, Texture.TextureFilter.MipMapLinearLinear)
textureRegionByFileName[fileName] = TextureRegion(texture)
}
val region = atlas.findRegion(fileName.replace(".png",""))
if(region==null)
throw Exception("Could not find $fileName")
return region
} catch (ex: Exception) {
return getTextureRegion(WhiteDot)
throw Exception("File $fileName not found!",ex)

View File

@ -24,7 +24,7 @@ class NotificationsScroll(private val notifications: List<Notification>, interna
minitable.add(ImageGetter.getImage("OtherIcons/Circle.png")
.apply { color=notification.color }).size(10f).pad(5f)
minitable.background(ImageGetter.getDrawable("skin/civTableBackground.png"))
minitable.background(ImageGetter.getDrawable("OtherIcons/civTableBackground.png"))
minitable.add(label).pad(3f).padRight(10f)
if (notification.location != null) {

View File

@ -89,7 +89,7 @@ class WorldScreenTopBar(val screen: WorldScreen) : Table() {
}
internal fun getMenuButton(): Image {
val menuButton = ImageGetter.getImage("skin/menuIcon.png")
val menuButton = ImageGetter.getImage("OtherIcons/MenuIcon.png")
.apply { setSize(50f, 50f) }
menuButton.color = Color.WHITE
menuButton.addClickListener {