segment based timeout, and slowpath warning
This commit is contained in:
parent
9e272824c5
commit
da5460413c
@ -185,7 +185,12 @@ public class Settings {
|
||||
/**
|
||||
* 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
|
||||
|
@ -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.<Long>get();
|
||||
} else {
|
||||
timeout = Baritone.settings().planAheadTimeoutMS.<Long>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();
|
||||
|
@ -55,7 +55,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<IPath> calculate0() {
|
||||
protected Optional<IPath> 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).<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;
|
||||
int numNodes = 0;
|
||||
int numMovementsConsidered = 0;
|
||||
|
@ -76,13 +76,13 @@ public abstract class AbstractNodeCostSearch implements IPathFinder {
|
||||
cancelRequested = true;
|
||||
}
|
||||
|
||||
public synchronized Optional<IPath> calculate() {
|
||||
public synchronized Optional<IPath> calculate(long timeout) {
|
||||
if (isFinished) {
|
||||
throw new IllegalStateException("Path Finder is currently in use, and cannot be reused!");
|
||||
}
|
||||
this.cancelRequested = false;
|
||||
try {
|
||||
Optional<IPath> path = calculate0();
|
||||
Optional<IPath> path = calculate0(timeout);
|
||||
isFinished = true;
|
||||
return path;
|
||||
} 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
|
||||
|
@ -39,7 +39,7 @@ public interface IPathFinder {
|
||||
*
|
||||
* @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
|
||||
|
Loading…
Reference in New Issue
Block a user