Skip to content

Commit 6d878b8

Browse files
committed
D* cut off timeout
1 parent fc86013 commit 6d878b8

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

common/src/main/kotlin/com/lambda/module/modules/movement/Pathfinder.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,12 @@ object Pathfinder : Module(
206206
}
207207

208208
private fun SafeContext.updateDStar() {
209+
calculating = true
209210
runConcurrent {
210-
calculating = true
211211
val long: Path
212212
val dStar = measureTimeMillis {
213213
// if (start dist dstar.start > 3) dstar.updateStart(start)
214-
dStar.computeShortestPath()
214+
dStar.computeShortestPath(pathing.cutoffTimeout)
215215
val nodes = dStar.getPath().map { TraverseMove(it, 0.0, NodeType.OPEN, 0.0, 0.0) }
216216
long = Path(ArrayDeque(nodes))
217217
}

common/src/main/kotlin/com/lambda/pathing/dstar/DStarLite.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,10 @@ class DStarLite(
112112
* While the queue top is "less" than calculateKey(start)
113113
* or g(start) < rhs(start), pop and process.
114114
*/
115-
fun computeShortestPath() {
116-
while ((U.topKey() < calculateKey(start)) || (g(start) < rhs(start))) {
115+
fun computeShortestPath(cutoffTimeout: Long = 500L) {
116+
val startTime = System.currentTimeMillis()
117+
118+
while ((U.topKey() < calculateKey(start)) || (g(start) < rhs(start)) && (System.currentTimeMillis() - startTime) < cutoffTimeout) {
117119
val u = U.top() ?: break
118120
val oldKey = U.topKey()
119121
val newKey = calculateKey(u)
@@ -169,6 +171,9 @@ class DStarLite(
169171
*/
170172
fun getPath(): List<FastVector> {
171173
val path = mutableListOf<FastVector>()
174+
175+
if (!graph.contains(start)) return path.toList()
176+
172177
var current = start
173178
path.add(current)
174179
while (current != goal) {

common/src/main/kotlin/com/lambda/pathing/move/MoveFinder.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,18 @@ object MoveFinder {
8181
checkingBlockPos.y < originBlockPos.y -> Box.enclosing(originBlockPos.up(), checkingBlockPos.up())
8282
else -> Box.enclosing(originBlockPos.up(2), checkingBlockPos)
8383
}
84-
traversable(checkingBlockPos) && world.isSpaceEmpty(enclose)
84+
traversable(checkingBlockPos) && world.isSpaceEmpty(enclose.contract(0.01))
8585
} else {
8686
traversable(checkingBlockPos)
8787
}
88+
if (!clear) return null
8889

8990
val hCost = heuristic(checkingPos) /** nodeType.penalty*/
90-
val cost = if (clear) offset.length() else Double.POSITIVE_INFINITY
91+
val cost = offset.length()
9192
val currentFeetY = getFeetY(checkingBlockPos)
9293

9394
return when {
94-
cost == Double.POSITIVE_INFINITY -> BreakMove(checkingPos, hCost, nodeType, currentFeetY, cost)
95+
// cost == Double.POSITIVE_INFINITY -> BreakMove(checkingPos, hCost, nodeType, currentFeetY, cost)
9596
// (currentFeetY - origin.feetY) > player.stepHeight -> ParkourMove(checkingPos, hCost, nodeType, currentFeetY, cost)
9697
else -> TraverseMove(checkingPos, hCost, nodeType, currentFeetY, cost)
9798
}

0 commit comments

Comments
 (0)