From f28cdc531fa027740715c3f404ed2d6fc3e3c18f Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 26 Sep 2018 15:32:54 -0700 Subject: [PATCH] this will really help performance a lot --- src/main/java/baritone/pathing/calc/AStarPathFinder.java | 7 ++++--- .../java/baritone/pathing/calc/AbstractNodeCostSearch.java | 3 +-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/baritone/pathing/calc/AStarPathFinder.java b/src/main/java/baritone/pathing/calc/AStarPathFinder.java index 933bb7d4..c1d4cab8 100644 --- a/src/main/java/baritone/pathing/calc/AStarPathFinder.java +++ b/src/main/java/baritone/pathing/calc/AStarPathFinder.java @@ -48,7 +48,7 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel @Override protected Optional calculate0(long timeout) { - startNode = getNodeAtPosition(start.x, start.y, start.z); + startNode = getNodeAtPosition(start.x, start.y, start.z, posHash(start.x, start.y, start.z)); startNode.cost = 0; startNode.combinedCost = startNode.estimatedCostToGoal; BinaryHeapOpenSet openSet = new BinaryHeapOpenSet(); @@ -118,11 +118,12 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel if (actionCost <= 0) { throw new IllegalStateException(moves + " calculated implausible cost " + actionCost); } - if (favoring && favored.contains(posHash(res.destX, res.destY, res.destZ))) { + long hashCode = posHash(res.destX, res.destY, res.destZ); + if (favoring && favored.contains(hashCode)) { // see issue #18 actionCost *= favorCoeff; } - PathNode neighbor = getNodeAtPosition(res.destX, res.destY, res.destZ); + PathNode neighbor = getNodeAtPosition(res.destX, res.destY, res.destZ, hashCode); double tentativeCost = currentNode.cost + actionCost; if (tentativeCost < neighbor.cost) { if (tentativeCost < 0) { diff --git a/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java b/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java index b3ffa427..49e726b0 100644 --- a/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java +++ b/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java @@ -129,8 +129,7 @@ public abstract class AbstractNodeCostSearch implements IPathFinder { * @return The associated node * @see Issue #107 */ - protected PathNode getNodeAtPosition(int x, int y, int z) { - long hashCode = posHash(x, y, z); + protected PathNode getNodeAtPosition(int x, int y, int z, long hashCode) { PathNode node = map.get(hashCode); if (node == null) { node = new PathNode(x, y, z, goal);