mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-24 22:59:34 +07:00
Yet Even Yet More performance improvements
This commit is contained in:
@ -16,6 +16,7 @@ import java.util.*
|
|||||||
|
|
||||||
class GameInfo {
|
class GameInfo {
|
||||||
@Transient lateinit var difficultyObject: Difficulty // Since this is static game-wide, and was taking a large part of nextTurn
|
@Transient lateinit var difficultyObject: Difficulty // Since this is static game-wide, and was taking a large part of nextTurn
|
||||||
|
@Transient lateinit var currentPlayerCiv:CivilizationInfo // this is called thousands of times, no reason to search for it with a find{} every time
|
||||||
|
|
||||||
var civilizations = mutableListOf<CivilizationInfo>()
|
var civilizations = mutableListOf<CivilizationInfo>()
|
||||||
var difficulty="Chieftain" // difficulty is game-wide, think what would happen if 2 human players could play on different difficulties?
|
var difficulty="Chieftain" // difficulty is game-wide, think what would happen if 2 human players could play on different difficulties?
|
||||||
@ -38,7 +39,7 @@ class GameInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun getCivilization(civName:String) = civilizations.first { it.civName==civName }
|
fun getCivilization(civName:String) = civilizations.first { it.civName==civName }
|
||||||
fun getCurrentPlayerCivilization() = getCivilization(currentPlayer)
|
fun getCurrentPlayerCivilization() = currentPlayerCiv
|
||||||
fun getBarbarianCivilization() = getCivilization("Barbarians")
|
fun getBarbarianCivilization() = getCivilization("Barbarians")
|
||||||
fun getDifficulty() = difficultyObject
|
fun getDifficulty() = difficultyObject
|
||||||
//endregion
|
//endregion
|
||||||
@ -84,7 +85,8 @@ class GameInfo {
|
|||||||
switchTurn()
|
switchTurn()
|
||||||
}
|
}
|
||||||
|
|
||||||
currentPlayer=thisPlayer.civName
|
currentPlayer = thisPlayer.civName
|
||||||
|
currentPlayerCiv = getCivilization(currentPlayer)
|
||||||
|
|
||||||
// Start our turn immediately before the player can made decisions - affects whether our units can commit automated actions and then be attacked immediately etc.
|
// Start our turn immediately before the player can made decisions - affects whether our units can commit automated actions and then be attacked immediately etc.
|
||||||
|
|
||||||
@ -171,6 +173,7 @@ class GameInfo {
|
|||||||
tileMap.setTransients()
|
tileMap.setTransients()
|
||||||
|
|
||||||
if(currentPlayer=="") currentPlayer=civilizations[0].civName
|
if(currentPlayer=="") currentPlayer=civilizations[0].civName
|
||||||
|
currentPlayerCiv=getCivilization(currentPlayer)
|
||||||
|
|
||||||
// this is separated into 2 loops because when we activate updateViewableTiles in civ.setTransients,
|
// this is separated into 2 loops because when we activate updateViewableTiles in civ.setTransients,
|
||||||
// we try to find new civs, and we check if civ is barbarian, which we can't know unless the gameInfo is already set.
|
// we try to find new civs, and we check if civ is barbarian, which we can't know unless the gameInfo is already set.
|
||||||
|
@ -69,8 +69,13 @@ fun String.tr(): String {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
val squareBraceRegex = Regex("\\[(.*?)\\]")
|
val squareBraceRegex = Regex("\\[(.*?)\\]")
|
||||||
|
val translationStringWithSquareBracketsOnly = replace(squareBraceRegex,"[]")
|
||||||
|
val translationStringUntilFirstSquareBracket = substringBefore('[')
|
||||||
val englishTranslationPlaceholder = GameBasics.Translations.keys
|
val englishTranslationPlaceholder = GameBasics.Translations.keys
|
||||||
.firstOrNull { it.replace(squareBraceRegex,"[]") == replace(squareBraceRegex,"[]") }
|
.firstOrNull {
|
||||||
|
// this is to filter out obvious non-candidates, which is most of them, before we start using the "heavy lifting" of the regex replacement
|
||||||
|
it.startsWith(translationStringUntilFirstSquareBracket)
|
||||||
|
&& it.replace(squareBraceRegex,"[]") == translationStringWithSquareBracketsOnly }
|
||||||
if(englishTranslationPlaceholder==null ||
|
if(englishTranslationPlaceholder==null ||
|
||||||
!GameBasics.Translations[englishTranslationPlaceholder]!!.containsKey(UnCivGame.Current.settings.language)){
|
!GameBasics.Translations[englishTranslationPlaceholder]!!.containsKey(UnCivGame.Current.settings.language)){
|
||||||
// Translation placeholder doesn't exist for this language
|
// Translation placeholder doesn't exist for this language
|
||||||
|
@ -123,16 +123,20 @@ open class TileGroup(var tileInfo: TileInfo) : Group() {
|
|||||||
fun getTileBaseImageLocation(isRevealed: Boolean): String {
|
fun getTileBaseImageLocation(isRevealed: Boolean): String {
|
||||||
if(!isRevealed) return tileSetLocation+"Hexagon"
|
if(!isRevealed) return tileSetLocation+"Hexagon"
|
||||||
if(tileInfo.isCityCenter()){
|
if(tileInfo.isCityCenter()){
|
||||||
if(ImageGetter.imageExists(tileSetLocation+tileInfo.baseTerrain+"+City"))
|
val terrainAndCity = "$tileSetLocation${tileInfo.baseTerrain}+City"
|
||||||
return tileSetLocation+tileInfo.baseTerrain+"+City"
|
if(ImageGetter.imageExists(terrainAndCity))
|
||||||
|
return terrainAndCity
|
||||||
if(ImageGetter.imageExists(tileSetLocation+"City"))
|
if(ImageGetter.imageExists(tileSetLocation+"City"))
|
||||||
return tileSetLocation+"City"
|
return tileSetLocation+"City"
|
||||||
}
|
}
|
||||||
// these are templates because apparently chain appending is faster or something?
|
// these are templates because apparently chain appending is faster or something?
|
||||||
val baseTerrainTileLocation = "$tileSetLocation${tileInfo.baseTerrain}"
|
val baseTerrainTileLocation = "$tileSetLocation${tileInfo.baseTerrain}"
|
||||||
val baseTerrainAndFeatureTileLocation = "$baseTerrainTileLocation+${tileInfo.terrainFeature}"
|
if(tileInfo.terrainFeature!=null){
|
||||||
if(tileInfo.terrainFeature!=null && ImageGetter.imageExists(baseTerrainAndFeatureTileLocation))
|
val baseTerrainAndFeatureTileLocation = "$baseTerrainTileLocation+${tileInfo.terrainFeature}"
|
||||||
return baseTerrainAndFeatureTileLocation
|
if(ImageGetter.imageExists(baseTerrainAndFeatureTileLocation))
|
||||||
|
return baseTerrainAndFeatureTileLocation
|
||||||
|
}
|
||||||
|
|
||||||
if(ImageGetter.imageExists(baseTerrainTileLocation)) return baseTerrainTileLocation
|
if(ImageGetter.imageExists(baseTerrainTileLocation)) return baseTerrainTileLocation
|
||||||
return tileSetLocation+"Hexagon"
|
return tileSetLocation+"Hexagon"
|
||||||
}
|
}
|
||||||
@ -216,6 +220,7 @@ open class TileGroup(var tileInfo: TileInfo) : Group() {
|
|||||||
|
|
||||||
private fun updateTerrainBaseImage() {
|
private fun updateTerrainBaseImage() {
|
||||||
if (tileInfo.baseTerrain == baseTerrain) return
|
if (tileInfo.baseTerrain == baseTerrain) return
|
||||||
|
baseTerrain = tileInfo.baseTerrain
|
||||||
|
|
||||||
if(baseTerrainOverlayImage!=null){
|
if(baseTerrainOverlayImage!=null){
|
||||||
baseTerrainOverlayImage!!.remove()
|
baseTerrainOverlayImage!!.remove()
|
||||||
@ -234,11 +239,12 @@ open class TileGroup(var tileInfo: TileInfo) : Group() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun updateCityImage() {
|
private fun updateCityImage() {
|
||||||
if(!ImageGetter.imageExists(tileSetLocation+"CityOverlay")) // have a city tile, don't need an overlay
|
|
||||||
return
|
|
||||||
|
|
||||||
if (cityImage == null && tileInfo.isCityCenter()) {
|
if (cityImage == null && tileInfo.isCityCenter()) {
|
||||||
cityImage = ImageGetter.getImage(tileSetLocation+"CityOverlay")
|
val cityOverlayLocation = tileSetLocation+"CityOverlay"
|
||||||
|
if(!ImageGetter.imageExists(cityOverlayLocation)) // have a city tile, don't need an overlay
|
||||||
|
return
|
||||||
|
|
||||||
|
cityImage = ImageGetter.getImage(cityOverlayLocation)
|
||||||
featureLayerGroup.addActor(cityImage)
|
featureLayerGroup.addActor(cityImage)
|
||||||
cityImage!!.run {
|
cityImage!!.run {
|
||||||
setSize(60f, 60f)
|
setSize(60f, 60f)
|
||||||
|
Reference in New Issue
Block a user