Skip to content

Commit

Permalink
perf(memory): Save unit icon location on baseunit
Browse files Browse the repository at this point in the history
  • Loading branch information
yairm210 committed Nov 5, 2024
1 parent 9ccce38 commit ba37be8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions core/src/com/unciv/models/ruleset/unit/BaseUnit.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions core/src/com/unciv/ui/images/ImageGetter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit ba37be8

Please sign in to comment.