Yet Even Yet More performance improvements

This commit is contained in:
Yair Morgenstern 2019-07-23 01:01:19 +03:00
parent db0543468b
commit 932d09af99
3 changed files with 26 additions and 12 deletions

View file

@ -16,6 +16,7 @@ import java.util.*
class GameInfo {
@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 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 getCurrentPlayerCivilization() = getCivilization(currentPlayer)
fun getCurrentPlayerCivilization() = currentPlayerCiv
fun getBarbarianCivilization() = getCivilization("Barbarians")
fun getDifficulty() = difficultyObject
//endregion
@ -84,7 +85,8 @@ class GameInfo {
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.
@ -171,6 +173,7 @@ class GameInfo {
tileMap.setTransients()
if(currentPlayer=="") currentPlayer=civilizations[0].civName
currentPlayerCiv=getCivilization(currentPlayer)
// 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.

View file

@ -69,8 +69,13 @@ fun String.tr(): String {
*/
val squareBraceRegex = Regex("\\[(.*?)\\]")
val translationStringWithSquareBracketsOnly = replace(squareBraceRegex,"[]")
val translationStringUntilFirstSquareBracket = substringBefore('[')
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 ||
!GameBasics.Translations[englishTranslationPlaceholder]!!.containsKey(UnCivGame.Current.settings.language)){
// Translation placeholder doesn't exist for this language

View file

@ -123,16 +123,20 @@ open class TileGroup(var tileInfo: TileInfo) : Group() {
fun getTileBaseImageLocation(isRevealed: Boolean): String {
if(!isRevealed) return tileSetLocation+"Hexagon"
if(tileInfo.isCityCenter()){
if(ImageGetter.imageExists(tileSetLocation+tileInfo.baseTerrain+"+City"))
return tileSetLocation+tileInfo.baseTerrain+"+City"
val terrainAndCity = "$tileSetLocation${tileInfo.baseTerrain}+City"
if(ImageGetter.imageExists(terrainAndCity))
return terrainAndCity
if(ImageGetter.imageExists(tileSetLocation+"City"))
return tileSetLocation+"City"
}
// these are templates because apparently chain appending is faster or something?
val baseTerrainTileLocation = "$tileSetLocation${tileInfo.baseTerrain}"
val baseTerrainAndFeatureTileLocation = "$baseTerrainTileLocation+${tileInfo.terrainFeature}"
if(tileInfo.terrainFeature!=null && ImageGetter.imageExists(baseTerrainAndFeatureTileLocation))
return baseTerrainAndFeatureTileLocation
if(tileInfo.terrainFeature!=null){
val baseTerrainAndFeatureTileLocation = "$baseTerrainTileLocation+${tileInfo.terrainFeature}"
if(ImageGetter.imageExists(baseTerrainAndFeatureTileLocation))
return baseTerrainAndFeatureTileLocation
}
if(ImageGetter.imageExists(baseTerrainTileLocation)) return baseTerrainTileLocation
return tileSetLocation+"Hexagon"
}
@ -216,6 +220,7 @@ open class TileGroup(var tileInfo: TileInfo) : Group() {
private fun updateTerrainBaseImage() {
if (tileInfo.baseTerrain == baseTerrain) return
baseTerrain = tileInfo.baseTerrain
if(baseTerrainOverlayImage!=null){
baseTerrainOverlayImage!!.remove()
@ -234,11 +239,12 @@ open class TileGroup(var tileInfo: TileInfo) : Group() {
}
private fun updateCityImage() {
if(!ImageGetter.imageExists(tileSetLocation+"CityOverlay")) // have a city tile, don't need an overlay
return
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)
cityImage!!.run {
setSize(60f, 60f)