chore: Remove unused distanceToTiles cache

This commit is contained in:
yairm210 2025-08-28 23:31:30 +03:00
parent 5e3beb302f
commit a7de6744ae

View File

@ -267,13 +267,8 @@ class UnitMovement(val unit: MapUnit) {
* @return The tile that we reached this turn * @return The tile that we reached this turn
*/ */
fun headTowards(destination: Tile): Tile { fun headTowards(destination: Tile): Tile {
val escortUnit = if (unit.isEscorting()) unit.getOtherEscortUnit() else null
val startTile = unit.getTile()
val destinationTileThisTurn = getTileToMoveToThisTurn(destination) val destinationTileThisTurn = getTileToMoveToThisTurn(destination)
moveToTile(destinationTileThisTurn) moveToTile(destinationTileThisTurn)
if (startTile != unit.getTile() && escortUnit != null) {
escortUnit.movement.headTowards(unit.getTile())
}
return unit.currentTile return unit.currentTile
} }
@ -748,10 +743,6 @@ class UnitMovement(val unit: MapUnit) {
movementCostCache: HashMap<Pair<Tile, Tile>, Float> = HashMap(), movementCostCache: HashMap<Pair<Tile, Tile>, Float> = HashMap(),
includeOtherEscortUnit: Boolean = true includeOtherEscortUnit: Boolean = true
): PathsToTilesWithinTurn { ): PathsToTilesWithinTurn {
// val cacheResults = pathfindingCache.getDistanceToTiles(considerZoneOfControl)
// if (cacheResults != null) {
// return cacheResults
// }
val distanceToTiles = getMovementToTilesAtPosition( val distanceToTiles = getMovementToTilesAtPosition(
unit.currentTile.position, unit.currentTile.position,
unit.currentMovement, unit.currentMovement,
@ -762,8 +753,6 @@ class UnitMovement(val unit: MapUnit) {
includeOtherEscortUnit includeOtherEscortUnit
) )
pathfindingCache.setDistanceToTiles(considerZoneOfControl, distanceToTiles)
return distanceToTiles return distanceToTiles
} }
@ -838,14 +827,13 @@ class UnitMovement(val unit: MapUnit) {
class PathfindingCache(private val unit: MapUnit) { class PathfindingCache(private val unit: MapUnit) {
private var shortestPathCache = listOf<Tile>() private var shortestPathCache = listOf<Tile>()
private var destination: Tile? = null private var destination: Tile? = null
private val distanceToTilesCache = mutableMapOf<Boolean, PathsToTilesWithinTurn>()
private var movement = -1f private var movement = -1f
private var currentTile: Tile? = null private var currentTile: Tile? = null
/** Check if the caches are valid (only checking if the unit has moved or consumed movement points; /** Check if the caches are valid (only checking if the unit has moved or consumed movement points;
* the isPlayerCivilization check is performed in the functions because we want isValid() == false * the isPlayerCivilization check is performed in the functions because we want isValid() == false
* to have a specific behavior) */ * to have a specific behavior) */
private fun isValid(): Boolean = (movement == unit.currentMovement) && (unit.getTile() == currentTile) @Readonly private fun isValid(): Boolean = (movement == unit.currentMovement) && (unit.getTile() == currentTile)
fun getShortestPathCache(destination: Tile): List<Tile> { fun getShortestPathCache(destination: Tile): List<Tile> {
if (unit.civ.isHuman()) return listOf() if (unit.civ.isHuman()) return listOf()
@ -863,23 +851,7 @@ class PathfindingCache(private val unit: MapUnit) {
} }
} }
fun getDistanceToTiles(zoneOfControl: Boolean): PathsToTilesWithinTurn? {
if (unit.civ.isHuman()) return null
if (isValid())
return distanceToTilesCache[zoneOfControl]
return null
}
fun setDistanceToTiles(zoneOfControl: Boolean, paths: PathsToTilesWithinTurn) {
if (unit.civ.isHuman()) return
if (!isValid()) {
clear() // we want to reset the entire cache at this point
}
distanceToTilesCache[zoneOfControl] = paths
}
fun clear() { fun clear() {
distanceToTilesCache.clear()
movement = unit.currentMovement movement = unit.currentMovement
currentTile = unit.getTile() currentTile = unit.getTile()
destination = null destination = null