node map performance, fixes #107
This commit is contained in:
parent
5c5507cc9e
commit
cebdd76ca7
@ -20,10 +20,9 @@ package baritone.pathing.calc;
|
||||
import baritone.pathing.goals.Goal;
|
||||
import baritone.pathing.path.IPath;
|
||||
import baritone.utils.pathing.BetterBlockPos;
|
||||
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
@ -42,7 +41,7 @@ public abstract class AbstractNodeCostSearch implements IPathFinder {
|
||||
|
||||
protected final Goal goal;
|
||||
|
||||
protected final Map<BetterBlockPos, PathNode> map;
|
||||
private final Long2ObjectOpenHashMap<PathNode> map; // see issue #107
|
||||
|
||||
protected PathNode startNode;
|
||||
|
||||
@ -69,7 +68,7 @@ public abstract class AbstractNodeCostSearch implements IPathFinder {
|
||||
AbstractNodeCostSearch(BlockPos start, Goal goal) {
|
||||
this.start = new BetterBlockPos(start.getX(), start.getY(), start.getZ());
|
||||
this.goal = goal;
|
||||
this.map = new HashMap<>();
|
||||
this.map = new Long2ObjectOpenHashMap<>();
|
||||
}
|
||||
|
||||
public void cancel() {
|
||||
@ -112,7 +111,14 @@ public abstract class AbstractNodeCostSearch implements IPathFinder {
|
||||
* @return The associated node
|
||||
*/
|
||||
protected PathNode getNodeAtPosition(BetterBlockPos pos) {
|
||||
return map.computeIfAbsent(pos, p -> new PathNode(p, goal));
|
||||
// see issue #107
|
||||
long hashCode = pos.hashCode;
|
||||
PathNode node = map.get(hashCode);
|
||||
if (node == null) {
|
||||
node = new PathNode(pos, goal);
|
||||
map.put(hashCode, node);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -30,7 +30,7 @@ public class BetterBlockPos extends BlockPos {
|
||||
public final int x;
|
||||
public final int y;
|
||||
public final int z;
|
||||
private final int hashCode;
|
||||
public final long hashCode;
|
||||
|
||||
public BetterBlockPos(int x, int y, int z) {
|
||||
super(x, y, z);
|
||||
@ -48,10 +48,10 @@ public class BetterBlockPos extends BlockPos {
|
||||
*
|
||||
* That's why we grab out the X, Y, Z and calculate our own hashcode
|
||||
*/
|
||||
int hash = 3241;
|
||||
hash = 3457689 * hash + x;
|
||||
hash = 8734625 * hash + y;
|
||||
hash = 2873465 * hash + z;
|
||||
long hash = 3241;
|
||||
hash = 3457689L * hash + x;
|
||||
hash = 8734625L * hash + y;
|
||||
hash = 2873465L * hash + z;
|
||||
this.hashCode = hash;
|
||||
}
|
||||
|
||||
@ -61,7 +61,7 @@ public class BetterBlockPos extends BlockPos {
|
||||
|
||||
@Override
|
||||
public final int hashCode() {
|
||||
return hashCode;
|
||||
return (int) hashCode;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user