Performance boost for GameInfo.setTransients - speeds up loadGame and nextTurn

This commit is contained in:
Yair Morgenstern
2022-01-27 00:28:41 +02:00
parent 6a969b98f5
commit fbec7c836e
4 changed files with 5 additions and 5 deletions

View File

@ -417,7 +417,8 @@ class GameInfo {
for (civInfo in civilizations) {
for (unit in civInfo.getCivUnits())
unit.updateVisibleTiles() // this needs to be done after all the units are assigned to their civs and all other transients are set
unit.updateVisibleTiles(false) // this needs to be done after all the units are assigned to their civs and all other transients are set
civInfo.updateViewableTiles() // only run ONCE and not for each unit - this is a huge performance saver!
// Since this depends on the cities of ALL civilizations,
// we need to wait until we've set the transients of all the cities before we can run this.

View File

@ -500,7 +500,6 @@ class CityStats(val cityInfo: CityInfo) {
statPercentBonusTree = newStatsBonusTree
}
/** Does not update tile stats - instead, updating tile stats updates this */
fun update(currentConstruction: IConstruction = cityInfo.cityConstructions.getCurrentConstruction(),
updateTileStats:Boolean = true) {
if (updateTileStats) updateTileStats()

View File

@ -402,7 +402,7 @@ class MapUnit {
/**
* Update this unit's cache of viewable tiles and its civ's as well.
*/
fun updateVisibleTiles() {
fun updateVisibleTiles(updateCivViewableTiles:Boolean = true) {
if (baseUnit.isAirUnit()) {
viewableTiles = if (hasUnique(UniqueType.SixTilesAlwaysVisible))
getTile().getTilesInDistance(6).toList() // it's that simple
@ -411,7 +411,7 @@ class MapUnit {
return
}
viewableTiles = getTile().getViewableTilesList(getVisibilityRange())
civInfo.updateViewableTiles() // for the civ
if (updateCivViewableTiles) civInfo.updateViewableTiles() // for the civ
}
fun isActionUntilHealed() = action?.endsWith("until healed") == true