segment based timeout, and slowpath warning

This commit is contained in:
Leijurv 2018-09-02 13:51:38 -07:00
parent 9e272824c5
commit da5460413c
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
5 changed files with 22 additions and 8 deletions

View File

@ -185,7 +185,12 @@ public class Settings {
/** /**
* Pathing can never take longer than this * Pathing can never take longer than this
*/ */
public Setting<Number> pathTimeoutMS = new Setting<>(4000L); public Setting<Number> pathTimeoutMS = new Setting<>(2000L);
/**
* Planning ahead while executing a segment can never take longer than this
*/
public Setting<Number> planAheadTimeoutMS = new Setting<>(4000L);
/** /**
* For debugging, consider nodes much much slower * For debugging, consider nodes much much slower

View File

@ -324,9 +324,15 @@ public class PathingBehavior extends Behavior {
goal = new GoalXZ(pos.getX(), pos.getZ()); goal = new GoalXZ(pos.getX(), pos.getZ());
} }
} }
long timeout;
if (current == null) {
timeout = Baritone.settings().pathTimeoutMS.<Long>get();
} else {
timeout = Baritone.settings().planAheadTimeoutMS.<Long>get();
}
try { try {
IPathFinder pf = new AStarPathFinder(start, goal, previous.map(IPath::positions)); IPathFinder pf = new AStarPathFinder(start, goal, previous.map(IPath::positions));
return pf.calculate(); return pf.calculate(timeout);
} catch (Exception e) { } catch (Exception e) {
displayChatMessageRaw("Pathing exception: " + e); displayChatMessageRaw("Pathing exception: " + e);
e.printStackTrace(); e.printStackTrace();

View File

@ -55,7 +55,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
} }
@Override @Override
protected Optional<IPath> calculate0() { protected Optional<IPath> calculate0(long timeout) {
startNode = getNodeAtPosition(start); startNode = getNodeAtPosition(start);
startNode.cost = 0; startNode.cost = 0;
startNode.combinedCost = startNode.estimatedCostToGoal; startNode.combinedCost = startNode.estimatedCostToGoal;
@ -74,7 +74,10 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
ChunkProviderClient chunkProvider = Minecraft.getMinecraft().world.getChunkProvider(); ChunkProviderClient chunkProvider = Minecraft.getMinecraft().world.getChunkProvider();
long startTime = System.nanoTime() / 1000000L; long startTime = System.nanoTime() / 1000000L;
boolean slowPath = Baritone.settings().slowPath.get(); boolean slowPath = Baritone.settings().slowPath.get();
long timeoutTime = startTime + (slowPath ? Baritone.settings().slowPathTimeoutMS : Baritone.settings().pathTimeoutMS).<Long>get(); if (slowPath) {
displayChatMessageRaw("slowPath is on, path timeout will be " + Baritone.settings().slowPathTimeoutMS.<Long>get() + "ms instead of " + timeout + "ms");
}
long timeoutTime = startTime + (slowPath ? Baritone.settings().slowPathTimeoutMS.<Long>get() : timeout);
//long lastPrintout = 0; //long lastPrintout = 0;
int numNodes = 0; int numNodes = 0;
int numMovementsConsidered = 0; int numMovementsConsidered = 0;

View File

@ -76,13 +76,13 @@ public abstract class AbstractNodeCostSearch implements IPathFinder {
cancelRequested = true; cancelRequested = true;
} }
public synchronized Optional<IPath> calculate() { public synchronized Optional<IPath> calculate(long timeout) {
if (isFinished) { if (isFinished) {
throw new IllegalStateException("Path Finder is currently in use, and cannot be reused!"); throw new IllegalStateException("Path Finder is currently in use, and cannot be reused!");
} }
this.cancelRequested = false; this.cancelRequested = false;
try { try {
Optional<IPath> path = calculate0(); Optional<IPath> path = calculate0(timeout);
isFinished = true; isFinished = true;
return path; return path;
} catch (Exception e) { } catch (Exception e) {
@ -96,7 +96,7 @@ public abstract class AbstractNodeCostSearch implements IPathFinder {
} }
} }
protected abstract Optional<IPath> calculate0(); protected abstract Optional<IPath> calculate0(long timeout);
/** /**
* Determines the distance squared from the specified node to the start * Determines the distance squared from the specified node to the start

View File

@ -39,7 +39,7 @@ public interface IPathFinder {
* *
* @return The final path * @return The final path
*/ */
Optional<IPath> calculate(); Optional<IPath> calculate(long timeout);
/** /**
* Intended to be called concurrently with calculatePath from a different thread to tell if it's finished yet * Intended to be called concurrently with calculatePath from a different thread to tell if it's finished yet