cherry pick 3x faster cache check

This commit is contained in:
leijurv 2018-08-28 21:14:50 -07:00
parent e553ee93b8
commit 8d1570a11b
3 changed files with 21 additions and 3 deletions

View File

@ -77,6 +77,10 @@ public final class CachedRegion implements IBlockTypeAccess {
return null; return null;
} }
public final boolean isCached(int x, int z) {
return chunks[x >> 4][z >> 4] != null;
}
public final LinkedList<BlockPos> getLocationsOf(String block) { public final LinkedList<BlockPos> getLocationsOf(String block) {
LinkedList<BlockPos> res = new LinkedList<>(); LinkedList<BlockPos> res = new LinkedList<>();
for (int chunkX = 0; chunkX < 32; chunkX++) { for (int chunkX = 0; chunkX < 32; chunkX++) {

View File

@ -59,7 +59,8 @@ public final class CachedWorld implements IBlockTypeAccess {
if (!Files.exists(directory)) { if (!Files.exists(directory)) {
try { try {
Files.createDirectories(directory); Files.createDirectories(directory);
} catch (IOException ignored) {} } catch (IOException ignored) {
}
} }
this.directory = directory.toString(); this.directory = directory.toString();
System.out.println("Cached world directory: " + directory); System.out.println("Cached world directory: " + directory);
@ -102,6 +103,17 @@ public final class CachedWorld implements IBlockTypeAccess {
return region.getBlock(x & 511, y, z & 511); return region.getBlock(x & 511, y, z & 511);
} }
public final boolean isCached(BlockPos pos) {
int x = pos.getX();
int z = pos.getZ();
CachedRegion region = getRegion(x >> 9, z >> 9);
if (region == null) {
return false;
}
return region.isCached(x & 511, z & 511);
}
public final LinkedList<BlockPos> getLocationsOf(String block, int minimum, int maxRegionDistanceSq) { public final LinkedList<BlockPos> getLocationsOf(String block, int minimum, int maxRegionDistanceSq) {
LinkedList<BlockPos> res = new LinkedList<>(); LinkedList<BlockPos> res = new LinkedList<>();
int playerRegionX = playerFeet().getX() >> 9; int playerRegionX = playerFeet().getX() >> 9;

View File

@ -18,6 +18,7 @@
package baritone.pathing.calc; package baritone.pathing.calc;
import baritone.Baritone; import baritone.Baritone;
import baritone.chunk.CachedWorld;
import baritone.chunk.WorldProvider; import baritone.chunk.WorldProvider;
import baritone.pathing.calc.openset.BinaryHeapOpenSet; import baritone.pathing.calc.openset.BinaryHeapOpenSet;
import baritone.pathing.calc.openset.IOpenSet; import baritone.pathing.calc.openset.IOpenSet;
@ -70,6 +71,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
CalculationContext calcContext = new CalculationContext(); CalculationContext calcContext = new CalculationContext();
HashSet<BetterBlockPos> favored = favoredPositions.orElse(null); HashSet<BetterBlockPos> favored = favoredPositions.orElse(null);
currentlyRunning = this; currentlyRunning = this;
CachedWorld world = Optional.ofNullable(WorldProvider.INSTANCE.getCurrentWorld()).map(w -> w.cache).orElse(null);
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
boolean slowPath = Baritone.settings().slowPath.get(); boolean slowPath = Baritone.settings().slowPath.get();
long timeoutTime = startTime + (slowPath ? Baritone.settings().slowPathTimeoutMS : Baritone.settings().pathTimeoutMS).<Long>get(); long timeoutTime = startTime + (slowPath ? Baritone.settings().slowPathTimeoutMS : Baritone.settings().pathTimeoutMS).<Long>get();
@ -112,8 +114,8 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
} }
BetterBlockPos dest = (BetterBlockPos) movementToGetToNeighbor.getDest(); BetterBlockPos dest = (BetterBlockPos) movementToGetToNeighbor.getDest();
boolean isPositionCached = false; boolean isPositionCached = false;
if (WorldProvider.INSTANCE.getCurrentWorld() != null) { if (world != null) {
if (WorldProvider.INSTANCE.getCurrentWorld().cache.getBlock(dest) != null) { if (world.isCached(dest)) {
isPositionCached = true; isPositionCached = true;
} }
} }