perf(mem): Create one TileSetStrings shared across all terrain emojis

This commit is contained in:
yairm210 2024-12-05 19:39:14 +02:00
parent c011a254d9
commit 03214379f2
3 changed files with 12 additions and 6 deletions

View File

@ -2916,7 +2916,7 @@ TileSets/HexaRealm/Edges/Lake-Plains/Fresh-Plains-Lakes-TopLeft
orig: 64, 56
offset: 0, 0
index: -1
TileSets/HexaRealm/Edges/Lake-Snow/Fresh-Snow-Lakes--TopLeft
TileSets/HexaRealm/Edges/Lake-Snow/Fresh-Snow-Lakes-TopLeft
rotate: false
xy: 361, 1639
size: 64, 56

View File

@ -14,6 +14,7 @@ import com.unciv.models.tilesets.TileSetCache
import com.unciv.ui.components.extensions.center
import com.unciv.ui.components.extensions.setSize
import com.unciv.ui.components.fonts.FontRulesetIcons.getPixmapFromActor
import com.unciv.ui.components.tilegroups.TileSetStrings
import com.unciv.ui.images.ImageGetter
import com.unciv.ui.images.Portrait
import com.unciv.ui.screens.civilopediascreen.CivilopediaImageGetters
@ -79,16 +80,19 @@ object FontRulesetIcons {
// Upon *game initialization* we can get here without the tileset being loaded yet
// in which case we can't add terrain icons
if (TileSetCache.containsKey(UncivGame.Current.settings.tileSet))
if (TileSetCache.containsKey(UncivGame.Current.settings.tileSet)) {
val tileSetStrings = TileSetStrings(ruleset, UncivGame.Current.settings)
for (terrain in ruleset.terrains.values) {
// These ensure that the font icons are correctly sized - tilegroup rendering works differently than others, to account for clickability vs rendered areas
val tileGroup = CivilopediaImageGetters.terrainImage(terrain, ruleset, Fonts.ORIGINAL_FONT_SIZE)
val tileGroup = CivilopediaImageGetters.terrainImage(terrain, ruleset, Fonts.ORIGINAL_FONT_SIZE, tileSetStrings)
tileGroup.width *= 1.5f
tileGroup.height *= 1.5f
for (layer in tileGroup.children) layer.center(tileGroup)
addChar(terrain.name, tileGroup)
}
}
}

View File

@ -22,7 +22,8 @@ internal object CivilopediaImageGetters {
private const val policyInnerSize = 0.25f
// Todo: potential synergy with map editor
internal fun terrainImage(terrain: Terrain, ruleset: Ruleset, imageSize: Float): Group {
internal fun terrainImage(terrain: Terrain, ruleset: Ruleset,
imageSize: Float, tileSetStrings: TileSetStrings? = null): Group {
val tile = Tile()
tile.ruleset = ruleset
@ -46,7 +47,8 @@ internal object CivilopediaImageGetters {
tile.baseTerrain = terrain.name
}
tile.setTerrainTransients()
val group = TileGroup(tile, TileSetStrings(ruleset, UncivGame.Current.settings), imageSize * 36f / 54f) // TileGroup normally spills out of its bounding box
val group = TileGroup(tile, tileSetStrings ?: TileSetStrings(ruleset, UncivGame.Current.settings),
imageSize * 36f / 54f) // TileGroup normally spills out of its bounding box
group.isForceVisible = true
group.isForMapEditorIcon = true
group.update()