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"
minSdkVersion 14
targetSdkVersion 26
versionCode 80
versionName "2.4.10"
versionCode 81
versionName "2.4.11"
}
buildTypes {
release {

View file

@ -51,7 +51,7 @@ class CityConstructions {
fun getProductionForTileInfo(): String {
var result = currentConstruction
if (result != "Science" && result != "Gold")
result += "\r\nin " + turnsToConstruction(currentConstruction) + " turns,\r\n"
result += "\r\nin " + turnsToConstruction(currentConstruction) + " turns"
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 String.tr(): String {return GameBasics.Translations.get(this,UnCivGame.Current.settings.language)}
val fontCache = HashMap<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
// if(screenScale<1) screenScale=1f
@ -140,9 +144,10 @@ fun getFont(size: Int): BitmapFont {
//generator.scaleForPixelHeight(size)
val font = generator.generateFont(parameter) // font size 12 pixels
val font = generator.generateFont(parameter)
// font.data.setScale(1f/screenScale)
generator.dispose() // don't forget to dispose to avoid memory leaks!
fontCache[size]=font
return font
}