Memory and performance improvements for tileGroup imagelocation

This commit is contained in:
Yair Morgenstern
2022-02-07 11:01:44 +02:00
parent 77dd9f63f6
commit a495e5c8fe
3 changed files with 12 additions and 10 deletions

View File

@ -203,8 +203,9 @@ open class TileGroup(var tileInfo: TileInfo, val tileSetStrings:TileSetStrings,
crosshairImage.isVisible = true
}
private fun getTileBaseImageLocations(viewingCiv: CivilizationInfo?): List<String> {
if (viewingCiv == null && !showEntireMap) return listOf(tileSetStrings.orFallback { hexagon } )
if (viewingCiv == null && !showEntireMap) return tileSetStrings.hexagonList
if (tileInfo.naturalWonder != null) return listOf(tileSetStrings.orFallback { getTile(tileInfo.naturalWonder!!) })
val shownImprovement = tileInfo.getShownImprovement(viewingCiv)
@ -213,10 +214,10 @@ open class TileGroup(var tileInfo: TileInfo, val tileSetStrings:TileSetStrings,
val shouldShowResource = UncivGame.Current.settings.showPixelImprovements && tileInfo.resource != null &&
(showEntireMap || viewingCiv == null || tileInfo.hasViewableResource(viewingCiv))
var resourceAndImprovementSequence = sequenceOf<String?>()
if (shouldShowResource) resourceAndImprovementSequence += sequenceOf(tileInfo.resource)
if (shouldShowImprovement) resourceAndImprovementSequence += sequenceOf(shownImprovement)
resourceAndImprovementSequence = resourceAndImprovementSequence.filterNotNull()
val resourceAndImprovementSequence = sequence {
if (shouldShowResource) yield(tileInfo.resource)
if (shouldShowImprovement) yield(shownImprovement)
}.filterNotNull()
val terrainImages = (sequenceOf(tileInfo.baseTerrain) + tileInfo.terrainFeatures.asSequence()).filterNotNull()
val allTogether = (terrainImages + resourceAndImprovementSequence).joinToString("+")
@ -296,7 +297,7 @@ open class TileGroup(var tileInfo: TileInfo, val tileSetStrings:TileSetStrings,
}
if (tileBaseImages.isEmpty()) { // Absolutely nothing! This is for the 'default' tileset
val image = ImageGetter.getImage(tileSetStrings.orFallback { hexagon })
val image = ImageGetter.getImage(tileSetStrings.hexagon)
tileBaseImages.add(image)
baseLayerGroup.addActor(image)
setHexagonImageSize(image)

View File

@ -162,7 +162,7 @@ class TileGroupIcons(val tileGroup: TileGroup) {
if (tileGroup.resourceImage != null) { // This could happen on any turn, since resources need certain techs to reveal them
val shouldDisplayResource =
if (tileGroup.showEntireMap) tileGroup.tileInfo.resource != null
if (tileGroup.showEntireMap) showResourcesAndImprovements
else showResourcesAndImprovements
&& tileGroup.tileInfo.hasViewableResource(UncivGame.Current.worldScreen.viewingCiv)
tileGroup.resourceImage!!.isVisible = shouldDisplayResource

View File

@ -17,13 +17,14 @@ class TileSetStrings(tileSet: String = UncivGame.Current.settings.tileSet, fallb
val tileSetLocation = "TileSets/$tileSet/"
val tileSetConfig = TileSetCache[tileSet] ?: TileSetConfig()
val hexagon = tileSetLocation + "Hexagon"
// These need to be by lazy since the orFallback expects a tileset, which it may not get.
val hexagon: String by lazy { orFallback {tileSetLocation + "Hexagon"} }
val hexagonList by lazy { listOf(hexagon) }
val crosshatchHexagon = tileSetLocation + "CrosshatchHexagon"
val cityOverlay = tileSetLocation + "CityOverlay"
val roadsMap = RoadStatus.values()
.filterNot { it == RoadStatus.None }
.map { it to tileSetLocation + it.name }
.toMap()
.associateWith { tileSetLocation + it.name }
val naturalWonderOverlay = tileSetLocation + "NaturalWonderOverlay"
val tilesLocation = tileSetLocation + "Tiles/"