|
|
@ -25,11 +25,15 @@ import baritone.api.utils.BetterBlockPos;
|
|
|
|
import baritone.pathing.calc.openset.BinaryHeapOpenSet;
|
|
|
|
import baritone.pathing.calc.openset.BinaryHeapOpenSet;
|
|
|
|
import baritone.pathing.movement.CalculationContext;
|
|
|
|
import baritone.pathing.movement.CalculationContext;
|
|
|
|
import baritone.pathing.movement.Moves;
|
|
|
|
import baritone.pathing.movement.Moves;
|
|
|
|
|
|
|
|
import baritone.utils.BlockStateInterface;
|
|
|
|
import baritone.utils.Helper;
|
|
|
|
import baritone.utils.Helper;
|
|
|
|
import baritone.utils.pathing.BetterWorldBorder;
|
|
|
|
import baritone.utils.pathing.BetterWorldBorder;
|
|
|
|
import baritone.utils.pathing.Favoring;
|
|
|
|
import baritone.utils.pathing.Favoring;
|
|
|
|
import baritone.utils.pathing.MutableMoveResult;
|
|
|
|
import baritone.utils.pathing.MutableMoveResult;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
|
|
|
import java.util.Comparator;
|
|
|
|
import java.util.Optional;
|
|
|
|
import java.util.Optional;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -79,6 +83,30 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel
|
|
|
|
int timeCheckInterval = 1 << 6;
|
|
|
|
int timeCheckInterval = 1 << 6;
|
|
|
|
int pathingMaxChunkBorderFetch = Baritone.settings().pathingMaxChunkBorderFetch.get(); // grab all settings beforehand so that changing settings during pathing doesn't cause a crash or unpredictable behavior
|
|
|
|
int pathingMaxChunkBorderFetch = Baritone.settings().pathingMaxChunkBorderFetch.get(); // grab all settings beforehand so that changing settings during pathing doesn't cause a crash or unpredictable behavior
|
|
|
|
boolean minimumImprovementRepropagation = Baritone.settings().minimumImprovementRepropagation.get();
|
|
|
|
boolean minimumImprovementRepropagation = Baritone.settings().minimumImprovementRepropagation.get();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
long[] timeConsumed = new long[Moves.values().length];
|
|
|
|
|
|
|
|
int[] count = new int[Moves.values().length];
|
|
|
|
|
|
|
|
int[] stateLookup = new int[Moves.values().length];
|
|
|
|
|
|
|
|
long[] posCreation = new long[Moves.values().length];
|
|
|
|
|
|
|
|
long heapRemove = 0;
|
|
|
|
|
|
|
|
int heapRemoveCount = 0;
|
|
|
|
|
|
|
|
long heapAdd = 0;
|
|
|
|
|
|
|
|
int heapAddCount = 0;
|
|
|
|
|
|
|
|
long heapUpdate = 0;
|
|
|
|
|
|
|
|
int heapUpdateCount = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
long chunk = 0;
|
|
|
|
|
|
|
|
int chunkCount = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
long goalCheck = 0;
|
|
|
|
|
|
|
|
int goalCheckCount = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
long getNode = 0;
|
|
|
|
|
|
|
|
int getNodeCount = 0;
|
|
|
|
|
|
|
|
int startVal = BlockStateInterface.numTimesChunkSucceeded;
|
|
|
|
|
|
|
|
int startVal2 = BlockStateInterface.numBlockStateLookups;
|
|
|
|
|
|
|
|
long startVal3 = BetterBlockPos.numCreated;
|
|
|
|
|
|
|
|
|
|
|
|
while (!openSet.isEmpty() && numEmptyChunk < pathingMaxChunkBorderFetch && !cancelRequested) {
|
|
|
|
while (!openSet.isEmpty() && numEmptyChunk < pathingMaxChunkBorderFetch && !cancelRequested) {
|
|
|
|
if ((numNodes & (timeCheckInterval - 1)) == 0) { // only call this once every 64 nodes (about half a millisecond)
|
|
|
|
if ((numNodes & (timeCheckInterval - 1)) == 0) { // only call this once every 64 nodes (about half a millisecond)
|
|
|
|
long now = System.currentTimeMillis(); // since nanoTime is slow on windows (takes many microseconds)
|
|
|
|
long now = System.currentTimeMillis(); // since nanoTime is slow on windows (takes many microseconds)
|
|
|
@ -92,14 +120,21 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel
|
|
|
|
} catch (InterruptedException ex) {
|
|
|
|
} catch (InterruptedException ex) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
long before = System.nanoTime();
|
|
|
|
PathNode currentNode = openSet.removeLowest();
|
|
|
|
PathNode currentNode = openSet.removeLowest();
|
|
|
|
|
|
|
|
long t = System.nanoTime();
|
|
|
|
|
|
|
|
heapRemove += t - before;
|
|
|
|
|
|
|
|
heapRemoveCount++;
|
|
|
|
mostRecentConsidered = currentNode;
|
|
|
|
mostRecentConsidered = currentNode;
|
|
|
|
numNodes++;
|
|
|
|
numNodes++;
|
|
|
|
if (goal.isInGoal(currentNode.x, currentNode.y, currentNode.z)) {
|
|
|
|
if (goal.isInGoal(currentNode.x, currentNode.y, currentNode.z)) {
|
|
|
|
logDebug("Took " + (System.currentTimeMillis() - startTime) + "ms, " + numMovementsConsidered + " movements considered");
|
|
|
|
logDebug("Took " + (System.currentTimeMillis() - startTime) + "ms, " + numMovementsConsidered + " movements considered");
|
|
|
|
return Optional.of(new Path(startNode, currentNode, numNodes, goal, calcContext));
|
|
|
|
return Optional.of(new Path(startNode, currentNode, numNodes, goal, calcContext));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
goalCheck += System.nanoTime() - t;
|
|
|
|
|
|
|
|
goalCheckCount++;
|
|
|
|
for (Moves moves : Moves.values()) {
|
|
|
|
for (Moves moves : Moves.values()) {
|
|
|
|
|
|
|
|
long s = System.nanoTime();
|
|
|
|
int newX = currentNode.x + moves.xOffset;
|
|
|
|
int newX = currentNode.x + moves.xOffset;
|
|
|
|
int newZ = currentNode.z + moves.zOffset;
|
|
|
|
int newZ = currentNode.z + moves.zOffset;
|
|
|
|
if ((newX >> 4 != currentNode.x >> 4 || newZ >> 4 != currentNode.z >> 4) && !calcContext.isLoaded(newX, newZ)) {
|
|
|
|
if ((newX >> 4 != currentNode.x >> 4 || newZ >> 4 != currentNode.z >> 4) && !calcContext.isLoaded(newX, newZ)) {
|
|
|
@ -107,6 +142,9 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel
|
|
|
|
if (!moves.dynamicXZ) { // only increment the counter if the movement would have gone out of bounds guaranteed
|
|
|
|
if (!moves.dynamicXZ) { // only increment the counter if the movement would have gone out of bounds guaranteed
|
|
|
|
numEmptyChunk++;
|
|
|
|
numEmptyChunk++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
long costStart = System.nanoTime();
|
|
|
|
|
|
|
|
chunk += costStart - s;
|
|
|
|
|
|
|
|
chunkCount++;
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!moves.dynamicXZ && !worldBorder.entirelyContains(newX, newZ)) {
|
|
|
|
if (!moves.dynamicXZ && !worldBorder.entirelyContains(newX, newZ)) {
|
|
|
@ -115,8 +153,19 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel
|
|
|
|
if (currentNode.y + moves.yOffset > 256 || currentNode.y + moves.yOffset < 0) {
|
|
|
|
if (currentNode.y + moves.yOffset > 256 || currentNode.y + moves.yOffset < 0) {
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
long costStart = System.nanoTime();
|
|
|
|
|
|
|
|
chunk += costStart - s;
|
|
|
|
|
|
|
|
chunkCount++;
|
|
|
|
|
|
|
|
// TODO cache cost
|
|
|
|
|
|
|
|
int numLookupsBefore = BlockStateInterface.numBlockStateLookups;
|
|
|
|
|
|
|
|
long numCreatedBefore = BetterBlockPos.numCreated;
|
|
|
|
res.reset();
|
|
|
|
res.reset();
|
|
|
|
moves.apply(calcContext, currentNode.x, currentNode.y, currentNode.z, res);
|
|
|
|
moves.apply(calcContext, currentNode.x, currentNode.y, currentNode.z, res);
|
|
|
|
|
|
|
|
long costEnd = System.nanoTime();
|
|
|
|
|
|
|
|
stateLookup[moves.ordinal()] += BlockStateInterface.numBlockStateLookups - numLookupsBefore;
|
|
|
|
|
|
|
|
posCreation[moves.ordinal()] += BetterBlockPos.numCreated - numCreatedBefore;
|
|
|
|
|
|
|
|
timeConsumed[moves.ordinal()] += costEnd - costStart;
|
|
|
|
|
|
|
|
count[moves.ordinal()]++;
|
|
|
|
numMovementsConsidered++;
|
|
|
|
numMovementsConsidered++;
|
|
|
|
double actionCost = res.cost;
|
|
|
|
double actionCost = res.cost;
|
|
|
|
if (actionCost >= ActionCosts.COST_INF) {
|
|
|
|
if (actionCost >= ActionCosts.COST_INF) {
|
|
|
@ -140,7 +189,10 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel
|
|
|
|
// see issue #18
|
|
|
|
// see issue #18
|
|
|
|
actionCost *= favored.calculate(hashCode);
|
|
|
|
actionCost *= favored.calculate(hashCode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
long st = System.nanoTime();
|
|
|
|
PathNode neighbor = getNodeAtPosition(res.x, res.y, res.z, hashCode);
|
|
|
|
PathNode neighbor = getNodeAtPosition(res.x, res.y, res.z, hashCode);
|
|
|
|
|
|
|
|
getNode += System.nanoTime() - st;
|
|
|
|
|
|
|
|
getNodeCount++;
|
|
|
|
double tentativeCost = currentNode.cost + actionCost;
|
|
|
|
double tentativeCost = currentNode.cost + actionCost;
|
|
|
|
if (tentativeCost < neighbor.cost) {
|
|
|
|
if (tentativeCost < neighbor.cost) {
|
|
|
|
double improvementBy = neighbor.cost - tentativeCost;
|
|
|
|
double improvementBy = neighbor.cost - tentativeCost;
|
|
|
@ -155,9 +207,15 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel
|
|
|
|
neighbor.cost = tentativeCost;
|
|
|
|
neighbor.cost = tentativeCost;
|
|
|
|
neighbor.combinedCost = tentativeCost + neighbor.estimatedCostToGoal;
|
|
|
|
neighbor.combinedCost = tentativeCost + neighbor.estimatedCostToGoal;
|
|
|
|
if (neighbor.isOpen()) {
|
|
|
|
if (neighbor.isOpen()) {
|
|
|
|
|
|
|
|
long bef = System.nanoTime();
|
|
|
|
openSet.update(neighbor);
|
|
|
|
openSet.update(neighbor);
|
|
|
|
|
|
|
|
heapUpdate += System.nanoTime() - bef;
|
|
|
|
|
|
|
|
heapUpdateCount++;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
|
|
|
|
long bef = System.nanoTime();
|
|
|
|
openSet.insert(neighbor);//dont double count, dont insert into open set if it's already there
|
|
|
|
openSet.insert(neighbor);//dont double count, dont insert into open set if it's already there
|
|
|
|
|
|
|
|
heapAdd += System.nanoTime() - bef;
|
|
|
|
|
|
|
|
heapAddCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (int i = 0; i < bestSoFar.length; i++) {
|
|
|
|
for (int i = 0; i < bestSoFar.length; i++) {
|
|
|
|
double heuristic = neighbor.estimatedCostToGoal + neighbor.cost / COEFFICIENTS[i];
|
|
|
|
double heuristic = neighbor.estimatedCostToGoal + neighbor.cost / COEFFICIENTS[i];
|
|
|
@ -175,6 +233,36 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int numBlockState = BlockStateInterface.numBlockStateLookups - startVal2;
|
|
|
|
|
|
|
|
int numSucc = BlockStateInterface.numTimesChunkSucceeded - startVal;
|
|
|
|
|
|
|
|
long numSuccc = BetterBlockPos.numCreated - startVal3;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
long totalAccountedTimeMS = 0;
|
|
|
|
|
|
|
|
totalAccountedTimeMS += heapRemove / 1000000;
|
|
|
|
|
|
|
|
totalAccountedTimeMS += heapAdd / 1000000;
|
|
|
|
|
|
|
|
totalAccountedTimeMS += heapUpdate / 1000000;
|
|
|
|
|
|
|
|
totalAccountedTimeMS += chunk / 1000000;
|
|
|
|
|
|
|
|
totalAccountedTimeMS += getNode / 1000000;
|
|
|
|
|
|
|
|
totalAccountedTimeMS += goalCheck / 1000000;
|
|
|
|
|
|
|
|
System.out.println("Out of " + numBlockState + " block state lookups, " + numSucc + " were in the same chunk as the previous and could be cached");
|
|
|
|
|
|
|
|
System.out.println("Instantiated " + numSuccc + " BetterBlockPos objects");
|
|
|
|
|
|
|
|
System.out.println("Remove " + (heapRemove / heapRemoveCount) + " " + heapRemove / 1000000 + "ms " + heapRemoveCount);
|
|
|
|
|
|
|
|
System.out.println("Add " + (heapAdd / heapAddCount) + " " + heapAdd / 1000000 + "ms " + heapAddCount);
|
|
|
|
|
|
|
|
System.out.println("Update " + (heapUpdate / heapUpdateCount) + " " + heapUpdate / 1000000 + "ms " + heapUpdateCount);
|
|
|
|
|
|
|
|
System.out.println("Chunk " + (chunk / chunkCount) + " " + chunk / 1000000 + "ms " + chunkCount);
|
|
|
|
|
|
|
|
System.out.println("GetNode " + (getNode / getNodeCount) + " " + getNode / 1000000 + "ms " + getNodeCount);
|
|
|
|
|
|
|
|
System.out.println("GoalCheck " + (goalCheck / goalCheckCount) + " " + goalCheck / 1000000 + "ms " + goalCheckCount);
|
|
|
|
|
|
|
|
ArrayList<Moves> moves = new ArrayList<>(Arrays.asList(Moves.values()));
|
|
|
|
|
|
|
|
moves.sort(Comparator.comparingLong(k -> timeConsumed[k.ordinal()] / count[k.ordinal()]));
|
|
|
|
|
|
|
|
for (Moves move : moves) {
|
|
|
|
|
|
|
|
int num = count[move.ordinal()];
|
|
|
|
|
|
|
|
long nanoTime = timeConsumed[move.ordinal()];
|
|
|
|
|
|
|
|
totalAccountedTimeMS += nanoTime / 1000000;
|
|
|
|
|
|
|
|
System.out.println(nanoTime / num + " " + move + " " + nanoTime / 1000000 + "ms " + num);
|
|
|
|
|
|
|
|
System.out.println(stateLookup[move.ordinal()] / num + " " + stateLookup[move.ordinal()]);
|
|
|
|
|
|
|
|
System.out.println(posCreation[move.ordinal()] / num + " " + posCreation[move.ordinal()]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
System.out.println("Total accounted time: " + totalAccountedTimeMS);
|
|
|
|
if (cancelRequested) {
|
|
|
|
if (cancelRequested) {
|
|
|
|
return Optional.empty();
|
|
|
|
return Optional.empty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|