Cached fonts for reuse - generating them takes valuable time!

This commit is contained in:
Yair Morgenstern 2018-06-12 21:38:40 +03:00
parent 9e3772a58d
commit e1df4b4840
3 changed files with 9 additions and 4 deletions

View File

@ -21,8 +21,8 @@ android {
applicationId "com.unciv.game" applicationId "com.unciv.game"
minSdkVersion 14 minSdkVersion 14
targetSdkVersion 26 targetSdkVersion 26
versionCode 80 versionCode 81
versionName "2.4.10" versionName "2.4.11"
} }
buildTypes { buildTypes {
release { release {

View File

@ -51,7 +51,7 @@ class CityConstructions {
fun getProductionForTileInfo(): String { fun getProductionForTileInfo(): String {
var result = currentConstruction var result = currentConstruction
if (result != "Science" && result != "Gold") if (result != "Science" && result != "Gold")
result += "\r\nin " + turnsToConstruction(currentConstruction) + " turns,\r\n" result += "\r\nin " + turnsToConstruction(currentConstruction) + " turns"
return result return result
} }

View File

@ -126,7 +126,11 @@ fun Actor.center(parent:Stage){ centerX(parent); centerY(parent)}
fun Label.setFontColor(color:Color): Label {style=Label.LabelStyle(style).apply { fontColor=color }; return this} fun Label.setFontColor(color:Color): Label {style=Label.LabelStyle(style).apply { fontColor=color }; return this}
fun String.tr(): String {return GameBasics.Translations.get(this,UnCivGame.Current.settings.language)} fun String.tr(): String {return GameBasics.Translations.get(this,UnCivGame.Current.settings.language)}
val fontCache = HashMap<Int,BitmapFont>()
fun getFont(size: Int): BitmapFont { fun getFont(size: Int): BitmapFont {
if(fontCache.containsKey(size)) return fontCache[size]!!
// var screenScale = Gdx.graphics.width / 1000f // screen virtual width as defined in CameraStageBaseScreen // var screenScale = Gdx.graphics.width / 1000f // screen virtual width as defined in CameraStageBaseScreen
// if(screenScale<1) screenScale=1f // if(screenScale<1) screenScale=1f
@ -140,9 +144,10 @@ fun getFont(size: Int): BitmapFont {
//generator.scaleForPixelHeight(size) //generator.scaleForPixelHeight(size)
val font = generator.generateFont(parameter) // font size 12 pixels val font = generator.generateFont(parameter)
// font.data.setScale(1f/screenScale) // font.data.setScale(1f/screenScale)
generator.dispose() // don't forget to dispose to avoid memory leaks! generator.dispose() // don't forget to dispose to avoid memory leaks!
fontCache[size]=font
return font return font
} }