favored lookup performance
This commit is contained in:
parent
d9effc4a29
commit
6d1130d2c3
@ -37,12 +37,15 @@ import baritone.pathing.path.CutoffPath;
|
|||||||
import baritone.pathing.path.PathExecutor;
|
import baritone.pathing.path.PathExecutor;
|
||||||
import baritone.utils.Helper;
|
import baritone.utils.Helper;
|
||||||
import baritone.utils.PathRenderer;
|
import baritone.utils.PathRenderer;
|
||||||
|
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.chunk.EmptyChunk;
|
import net.minecraft.world.chunk.EmptyChunk;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public final class PathingBehavior extends Behavior implements IPathingBehavior, Helper {
|
public final class PathingBehavior extends Behavior implements IPathingBehavior, Helper {
|
||||||
|
|
||||||
@ -492,9 +495,11 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
|
|||||||
transformed = new GoalXZ(pos.getX(), pos.getZ());
|
transformed = new GoalXZ(pos.getX(), pos.getZ());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
HashSet<Long> favoredPositions = null;
|
LongOpenHashSet favoredPositions = null;
|
||||||
if (Baritone.settings().backtrackCostFavoringCoefficient.get() != 1D && previous != null) {
|
if (Baritone.settings().backtrackCostFavoringCoefficient.get() != 1D && previous != null) {
|
||||||
favoredPositions = previous.positions().stream().map(BetterBlockPos::longHash).collect(Collectors.toCollection(HashSet::new));
|
LongOpenHashSet tmp = new LongOpenHashSet();
|
||||||
|
previous.positions().forEach(pos -> tmp.add(BetterBlockPos.longHash(pos)));
|
||||||
|
favoredPositions = tmp;
|
||||||
}
|
}
|
||||||
return new AStarPathFinder(start.getX(), start.getY(), start.getZ(), transformed, favoredPositions, context);
|
return new AStarPathFinder(start.getX(), start.getY(), start.getZ(), transformed, favoredPositions, context);
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@ import baritone.pathing.movement.Moves;
|
|||||||
import baritone.utils.Helper;
|
import baritone.utils.Helper;
|
||||||
import baritone.utils.pathing.BetterWorldBorder;
|
import baritone.utils.pathing.BetterWorldBorder;
|
||||||
import baritone.utils.pathing.MutableMoveResult;
|
import baritone.utils.pathing.MutableMoveResult;
|
||||||
|
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@ -39,10 +40,10 @@ import java.util.Optional;
|
|||||||
*/
|
*/
|
||||||
public final class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
|
public final class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
|
||||||
|
|
||||||
private final HashSet<Long> favoredPositions;
|
private final LongOpenHashSet favoredPositions;
|
||||||
private final CalculationContext calcContext;
|
private final CalculationContext calcContext;
|
||||||
|
|
||||||
public AStarPathFinder(int startX, int startY, int startZ, Goal goal, HashSet<Long> favoredPositions, CalculationContext context) {
|
public AStarPathFinder(int startX, int startY, int startZ, Goal goal, LongOpenHashSet favoredPositions, CalculationContext context) {
|
||||||
super(startX, startY, startZ, goal, context);
|
super(startX, startY, startZ, goal, context);
|
||||||
this.favoredPositions = favoredPositions;
|
this.favoredPositions = favoredPositions;
|
||||||
this.calcContext = context;
|
this.calcContext = context;
|
||||||
@ -63,7 +64,7 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel
|
|||||||
bestSoFar[i] = startNode;
|
bestSoFar[i] = startNode;
|
||||||
}
|
}
|
||||||
MutableMoveResult res = new MutableMoveResult();
|
MutableMoveResult res = new MutableMoveResult();
|
||||||
HashSet<Long> favored = favoredPositions;
|
LongOpenHashSet favored = favoredPositions;
|
||||||
BetterWorldBorder worldBorder = new BetterWorldBorder(calcContext.world().getWorldBorder());
|
BetterWorldBorder worldBorder = new BetterWorldBorder(calcContext.world().getWorldBorder());
|
||||||
long startTime = System.nanoTime() / 1000000L;
|
long startTime = System.nanoTime() / 1000000L;
|
||||||
boolean slowPath = Baritone.settings().slowPath.get();
|
boolean slowPath = Baritone.settings().slowPath.get();
|
||||||
|
Loading…
Reference in New Issue
Block a user