perf(memory): Save unit icon location on baseunit

This commit is contained in:
yairm210
2024-11-05 08:42:29 +02:00
parent 9ccce38fcc
commit ba37be8641
2 changed files with 5 additions and 2 deletions

View File

@ -63,6 +63,9 @@ class BaseUnit : RulesetObject(), INonPerpetualConstruction {
@Transient
var cachedForceEvaluation: Int = -1
@delegate:Transient // memory perf optimization to not create the string per unit
val unitIconLocation by lazy { "UnitIcons/$name.png" }
@Transient
val costFunctions = BaseUnitCost(this)

View File

@ -251,8 +251,8 @@ object ImageGetter {
fun getRandomNationPortrait(size: Float): Portrait = PortraitNation(Constants.random, size)
fun getUnitIcon(unit: BaseUnit, color: Color = Color.BLACK): Image =
if (imageExists("UnitIcons/${unit.name}"))
getImage("UnitIcons/${unit.name}").apply { this.color = color }
if (imageExists(unit.unitIconLocation))
getImage(unit.unitIconLocation).apply { this.color = color }
else getImage("UnitTypeIcons/${unit.type}").apply { this.color = color }
fun getConstructionPortrait(construction: String, size: Float): Group {