Skip to content

Commit

Permalink
perf(memory): Don't store city distances intermediately
Browse files Browse the repository at this point in the history
  • Loading branch information
yairm210 committed Oct 29, 2024
1 parent a7ccbde commit cbbec40
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -647,13 +647,17 @@ object NextTurnAutomation {
fun getClosestCities(civ1: Civilization, civ2: Civilization): CityDistance? {
if (civ1.cities.isEmpty() || civ2.cities.isEmpty())
return null

var minDistance: CityDistance? = null

val cityDistances = arrayListOf<CityDistance>()
for (civ1city in civ1.cities)
for (civ2city in civ2.cities)
cityDistances += CityDistance(civ1city, civ2city,
for (civ2city in civ2.cities){
val currentDistance = CityDistance(civ1city, civ2city,
civ1city.getCenterTile().aerialDistanceTo(civ2city.getCenterTile()))
if (minDistance == null || currentDistance.aerialDistance < minDistance.aerialDistance)
minDistance = currentDistance
}

return cityDistances.minByOrNull { it.aerialDistance }!!
return minDistance
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ class WorkerAutomation(
if (tile.hasViewableResource(civInfo)) valueOfFort -= 1

// if this place is not perfect, let's see if there is a better one
val nearestTiles = tile.getTilesInDistance(1).filter { it.owningCity?.civ == civInfo }.toList()
val nearestTiles = tile.getTilesInDistance(1).filter { it.owningCity?.civ == civInfo }
for (closeTile in nearestTiles) {
// don't build forts too close to the cities
if (closeTile.isCityCenter()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class TileLayerTerrain(tileGroup: TileGroup, size: Float) : TileLayer(tileGroup,

val baseHexagon = if (strings().tileSetConfig.useColorAsBaseTerrain)
listOf(strings().hexagon)
else listOf()
else emptyList()

val tile = tileGroup.tile

Expand Down

0 comments on commit cbbec40

Please sign in to comment.