From da5460413c44114a0f68717e2117e84dc387c697 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sun, 2 Sep 2018 13:51:38 -0700 Subject: [PATCH] segment based timeout, and slowpath warning --- src/main/java/baritone/Settings.java | 7 ++++++- src/main/java/baritone/behavior/impl/PathingBehavior.java | 8 +++++++- src/main/java/baritone/pathing/calc/AStarPathFinder.java | 7 +++++-- .../baritone/pathing/calc/AbstractNodeCostSearch.java | 6 +++--- src/main/java/baritone/pathing/calc/IPathFinder.java | 2 +- 5 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/main/java/baritone/Settings.java b/src/main/java/baritone/Settings.java index d7d23c59..78c2d4b3 100644 --- a/src/main/java/baritone/Settings.java +++ b/src/main/java/baritone/Settings.java @@ -185,7 +185,12 @@ public class Settings { /** * Pathing can never take longer than this */ - public Setting pathTimeoutMS = new Setting<>(4000L); + public Setting pathTimeoutMS = new Setting<>(2000L); + + /** + * Planning ahead while executing a segment can never take longer than this + */ + public Setting planAheadTimeoutMS = new Setting<>(4000L); /** * For debugging, consider nodes much much slower diff --git a/src/main/java/baritone/behavior/impl/PathingBehavior.java b/src/main/java/baritone/behavior/impl/PathingBehavior.java index 075d8d6f..fa651a87 100644 --- a/src/main/java/baritone/behavior/impl/PathingBehavior.java +++ b/src/main/java/baritone/behavior/impl/PathingBehavior.java @@ -324,9 +324,15 @@ public class PathingBehavior extends Behavior { goal = new GoalXZ(pos.getX(), pos.getZ()); } } + long timeout; + if (current == null) { + timeout = Baritone.settings().pathTimeoutMS.get(); + } else { + timeout = Baritone.settings().planAheadTimeoutMS.get(); + } try { IPathFinder pf = new AStarPathFinder(start, goal, previous.map(IPath::positions)); - return pf.calculate(); + return pf.calculate(timeout); } catch (Exception e) { displayChatMessageRaw("Pathing exception: " + e); e.printStackTrace(); diff --git a/src/main/java/baritone/pathing/calc/AStarPathFinder.java b/src/main/java/baritone/pathing/calc/AStarPathFinder.java index 0af6f0fe..fa8b5076 100644 --- a/src/main/java/baritone/pathing/calc/AStarPathFinder.java +++ b/src/main/java/baritone/pathing/calc/AStarPathFinder.java @@ -55,7 +55,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper { } @Override - protected Optional calculate0() { + protected Optional calculate0(long timeout) { startNode = getNodeAtPosition(start); startNode.cost = 0; startNode.combinedCost = startNode.estimatedCostToGoal; @@ -74,7 +74,10 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper { ChunkProviderClient chunkProvider = Minecraft.getMinecraft().world.getChunkProvider(); long startTime = System.nanoTime() / 1000000L; boolean slowPath = Baritone.settings().slowPath.get(); - long timeoutTime = startTime + (slowPath ? Baritone.settings().slowPathTimeoutMS : Baritone.settings().pathTimeoutMS).get(); + if (slowPath) { + displayChatMessageRaw("slowPath is on, path timeout will be " + Baritone.settings().slowPathTimeoutMS.get() + "ms instead of " + timeout + "ms"); + } + long timeoutTime = startTime + (slowPath ? Baritone.settings().slowPathTimeoutMS.get() : timeout); //long lastPrintout = 0; int numNodes = 0; int numMovementsConsidered = 0; diff --git a/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java b/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java index 3960a376..5804cb1a 100644 --- a/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java +++ b/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java @@ -76,13 +76,13 @@ public abstract class AbstractNodeCostSearch implements IPathFinder { cancelRequested = true; } - public synchronized Optional calculate() { + public synchronized Optional calculate(long timeout) { if (isFinished) { throw new IllegalStateException("Path Finder is currently in use, and cannot be reused!"); } this.cancelRequested = false; try { - Optional path = calculate0(); + Optional path = calculate0(timeout); isFinished = true; return path; } catch (Exception e) { @@ -96,7 +96,7 @@ public abstract class AbstractNodeCostSearch implements IPathFinder { } } - protected abstract Optional calculate0(); + protected abstract Optional calculate0(long timeout); /** * Determines the distance squared from the specified node to the start diff --git a/src/main/java/baritone/pathing/calc/IPathFinder.java b/src/main/java/baritone/pathing/calc/IPathFinder.java index bbcc7bda..dceee65d 100644 --- a/src/main/java/baritone/pathing/calc/IPathFinder.java +++ b/src/main/java/baritone/pathing/calc/IPathFinder.java @@ -39,7 +39,7 @@ public interface IPathFinder { * * @return The final path */ - Optional calculate(); + Optional calculate(long timeout); /** * Intended to be called concurrently with calculatePath from a different thread to tell if it's finished yet