this will really help performance a lot

This commit is contained in:
Leijurv 2018-09-26 15:32:54 -07:00
parent 2aa4770b45
commit f28cdc531f
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
2 changed files with 5 additions and 5 deletions

View File

@ -48,7 +48,7 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel
@Override
protected Optional<IPath> 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) {

View File

@ -129,8 +129,7 @@ public abstract class AbstractNodeCostSearch implements IPathFinder {
* @return The associated node
* @see <a href="https://github.com/cabaletta/baritone/issues/107">Issue #107</a>
*/
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);