mirror of
https://github.com/yairm210/Unciv.git
synced 2024-12-22 23:14:25 +07:00
perf(memory): Don't clone units when cloning tiles for 'alternative history' checks
This commit is contained in:
parent
b1fe404222
commit
ef78cd95f9
@ -439,7 +439,7 @@ class WorkerAutomation(
|
||||
val removedImprovement = if (removedObject == tile.improvement) removedObject else null
|
||||
|
||||
if (removedFeature != null || removedImprovement != null) {
|
||||
val newTile = tile.clone()
|
||||
val newTile = tile.clone(addUnits = false)
|
||||
newTile.setTerrainTransients()
|
||||
if (removedFeature != null)
|
||||
newTile.removeTerrainFeature(removedFeature)
|
||||
|
@ -193,7 +193,7 @@ class Tile : IsPartOfGameInfoSerialization, Json.Serializable {
|
||||
|
||||
//endregion
|
||||
|
||||
fun clone(): Tile {
|
||||
fun clone(/** For stat diff checks, units are meaningless */ addUnits:Boolean = true): Tile {
|
||||
val toReturn = Tile()
|
||||
toReturn.tileMap = tileMap
|
||||
toReturn.ruleset = ruleset
|
||||
@ -203,9 +203,11 @@ class Tile : IsPartOfGameInfoSerialization, Json.Serializable {
|
||||
toReturn.isLand = isLand
|
||||
toReturn.isWater = isWater
|
||||
toReturn.isOcean = isOcean
|
||||
if (militaryUnit != null) toReturn.militaryUnit = militaryUnit!!.clone()
|
||||
if (civilianUnit != null) toReturn.civilianUnit = civilianUnit!!.clone()
|
||||
for (airUnit in airUnits) toReturn.airUnits.add(airUnit.clone())
|
||||
if (addUnits) {
|
||||
if (militaryUnit != null) toReturn.militaryUnit = militaryUnit!!.clone()
|
||||
if (civilianUnit != null) toReturn.civilianUnit = civilianUnit!!.clone()
|
||||
for (airUnit in airUnits) toReturn.airUnits.add(airUnit.clone())
|
||||
}
|
||||
toReturn.position = position.cpy()
|
||||
toReturn.baseTerrain = baseTerrain
|
||||
toReturn.terrainFeatures = terrainFeatures // immutable lists can be directly passed around
|
||||
|
@ -117,7 +117,7 @@ class TileImprovementFunctions(val tile: Tile) {
|
||||
tile.ruleset.tileRemovals.firstOrNull { it.name == Constants.remove + feature } }
|
||||
if (featureRemovals.isEmpty()) return false
|
||||
if (featureRemovals.any { it !in knownFeatureRemovals }) return false
|
||||
val clonedTile = tile.clone()
|
||||
val clonedTile = tile.clone(addUnits = false)
|
||||
clonedTile.setTerrainFeatures(tile.terrainFeatures.filterNot {
|
||||
feature -> featureRemovals.any { it.name.removePrefix(Constants.remove) == feature } })
|
||||
return clonedTile.improvementFunctions.canImprovementBeBuiltHere(improvement, resourceIsVisible, knownFeatureRemovals, stateForConditionals)
|
||||
|
@ -273,7 +273,7 @@ class TileStatFunctions(val tile: Tile) {
|
||||
val currentStats = currentTileStats
|
||||
?: getTileStats(city, observingCiv, cityUniqueCache)
|
||||
|
||||
val tileClone = tile.clone()
|
||||
val tileClone = tile.clone(addUnits = false)
|
||||
tileClone.setTerrainTransients()
|
||||
|
||||
tileClone.setImprovement(improvement.name)
|
||||
|
@ -89,7 +89,7 @@ class ImprovementPickerScreen(
|
||||
|
||||
// clone tileInfo without "top" feature if it could be removed
|
||||
// Keep this copy around for speed
|
||||
tileWithoutLastTerrain = tile.clone()
|
||||
tileWithoutLastTerrain = tile.clone(addUnits = false)
|
||||
tileWithoutLastTerrain.setTerrainTransients()
|
||||
if (Constants.remove + tileWithoutLastTerrain.lastTerrain.name in ruleset.tileImprovements) {
|
||||
tileWithoutLastTerrain.removeTerrainFeature(tileWithoutLastTerrain.lastTerrain.name)
|
||||
|
Loading…
Reference in New Issue
Block a user