Merge pull request #4055 from babbaj/elytra
cull far away chunks from the cache
This commit is contained in:
@@ -175,8 +175,8 @@ dependencies {
|
||||
transitive = false
|
||||
}
|
||||
launchAnnotationProcessor 'org.spongepowered:mixin:0.8.4-SNAPSHOT:processor'
|
||||
launchImplementation('dev.babbaj:nether-pathfinder:0.24')
|
||||
implementation 'dev.babbaj:nether-pathfinder:0.24'
|
||||
launchImplementation('dev.babbaj:nether-pathfinder:0.34')
|
||||
implementation 'dev.babbaj:nether-pathfinder:0.34'
|
||||
testImplementation 'junit:junit:4.12'
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@ import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@@ -1404,6 +1405,16 @@ public final class Settings {
|
||||
*/
|
||||
public final Setting<Integer> elytraMinimumDurability = new Setting<>(5);
|
||||
|
||||
/**
|
||||
* Time between culling far away chunks from the nether pathfinder chunk cache
|
||||
*/
|
||||
public final Setting<Long> elytraTimeBetweenCacheCullSecs = new Setting<>(TimeUnit.MINUTES.toSeconds(3));
|
||||
|
||||
/**
|
||||
* Maximum distance chunks can be before being culled from the nether pathfinder chunk cache
|
||||
*/
|
||||
public final Setting<Integer> elytraCacheCullDistance = new Setting<>(5000);
|
||||
|
||||
/**
|
||||
* A map of lowercase setting field names to their respective setting
|
||||
*/
|
||||
|
||||
@@ -118,9 +118,11 @@ public final class ElytraBehavior extends Behavior implements IElytraBehavior, H
|
||||
private Solution pendingSolution;
|
||||
private boolean solveNextTick;
|
||||
|
||||
private long timeLastCacheCull = 0L;
|
||||
|
||||
// auto swap
|
||||
private int invTickCountdown = 0;
|
||||
private final Queue<Runnable> transactionQueue = new LinkedList<>();
|
||||
private final Queue<Runnable> invTransactionQueue = new LinkedList<>();
|
||||
|
||||
private ElytraBehavior(Baritone baritone) {
|
||||
super(baritone);
|
||||
@@ -516,6 +518,11 @@ public final class ElytraBehavior extends Behavior implements IElytraBehavior, H
|
||||
if (event.getType() == TickEvent.Type.OUT) {
|
||||
return;
|
||||
}
|
||||
final long now = System.currentTimeMillis();
|
||||
if ((now - this.timeLastCacheCull) / 1000 > Baritone.settings().elytraTimeBetweenCacheCullSecs.value) {
|
||||
this.context.queueCacheCulling(ctx.player().chunkCoordX, ctx.player().chunkCoordZ, Baritone.settings().elytraCacheCullDistance.value, this.boi);
|
||||
this.timeLastCacheCull = now;
|
||||
}
|
||||
|
||||
// Fetch the previous solution, regardless of if it's going to be used
|
||||
this.pendingSolution = null;
|
||||
@@ -1264,7 +1271,7 @@ public final class ElytraBehavior extends Behavior implements IElytraBehavior, H
|
||||
|
||||
private void tickInventoryTransactions() {
|
||||
if (invTickCountdown <= 0) {
|
||||
Runnable r = transactionQueue.poll();
|
||||
Runnable r = invTransactionQueue.poll();
|
||||
if (r != null) {
|
||||
r.run();
|
||||
invTickCountdown = Baritone.settings().ticksBetweenInventoryMoves.value;
|
||||
@@ -1274,7 +1281,7 @@ public final class ElytraBehavior extends Behavior implements IElytraBehavior, H
|
||||
}
|
||||
|
||||
private void queueWindowClick(int windowId, int slotId, int button, ClickType type) {
|
||||
transactionQueue.add(() -> ctx.playerController().windowClick(windowId, slotId, button, type, ctx.player()));
|
||||
invTransactionQueue.add(() -> ctx.playerController().windowClick(windowId, slotId, button, type, ctx.player()));
|
||||
}
|
||||
|
||||
private int findGoodElytra() {
|
||||
@@ -1289,7 +1296,7 @@ public final class ElytraBehavior extends Behavior implements IElytraBehavior, H
|
||||
}
|
||||
|
||||
private void trySwapElytra() {
|
||||
if (!Baritone.settings().elytraAutoSwap.value || !transactionQueue.isEmpty()) {
|
||||
if (!Baritone.settings().elytraAutoSwap.value || !invTransactionQueue.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,15 +25,17 @@ import dev.babbaj.pathfinder.Octree;
|
||||
*/
|
||||
public final class BlockStateOctreeInterface {
|
||||
|
||||
private final long context;
|
||||
private long chunkPtr;
|
||||
private final NetherPathfinderContext context;
|
||||
private final long contextPtr;
|
||||
volatile long chunkPtr;
|
||||
|
||||
// Guarantee that the first lookup will fetch the context by setting MAX_VALUE
|
||||
private int prevChunkX = Integer.MAX_VALUE;
|
||||
private int prevChunkZ = Integer.MAX_VALUE;
|
||||
|
||||
public BlockStateOctreeInterface(final NetherPathfinderContext context) {
|
||||
this.context = context.context;
|
||||
this.context = context;
|
||||
this.contextPtr = context.context;
|
||||
}
|
||||
|
||||
public boolean get0(final int x, final int y, final int z) {
|
||||
@@ -42,11 +44,14 @@ public final class BlockStateOctreeInterface {
|
||||
}
|
||||
final int chunkX = x >> 4;
|
||||
final int chunkZ = z >> 4;
|
||||
if (((chunkX ^ this.prevChunkX) | (chunkZ ^ this.prevChunkZ)) != 0) {
|
||||
long pointer = this.chunkPtr;
|
||||
if (pointer == 0 | ((chunkX ^ this.prevChunkX) | (chunkZ ^ this.prevChunkZ)) != 0) {
|
||||
this.prevChunkX = chunkX;
|
||||
this.prevChunkZ = chunkZ;
|
||||
this.chunkPtr = NetherPathfinder.getOrCreateChunk(this.context, chunkX, chunkZ);
|
||||
synchronized (this.context.cacheLock) {
|
||||
this.chunkPtr = pointer = NetherPathfinder.getOrCreateChunk(this.contextPtr, chunkX, chunkZ);
|
||||
}
|
||||
}
|
||||
return Octree.getBlock(this.chunkPtr, x & 0xF, y & 0x7F, z & 0xF);
|
||||
return Octree.getBlock(pointer, x & 0xF, y & 0x7F, z & 0xF);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ import java.util.concurrent.TimeUnit;
|
||||
public final class NetherPathfinderContext {
|
||||
|
||||
private static final IBlockState AIR_BLOCK_STATE = Blocks.AIR.getDefaultState();
|
||||
public final Object cacheLock = new Object();
|
||||
|
||||
// Visible for access in BlockStateOctreeInterface
|
||||
final long context;
|
||||
@@ -57,6 +58,15 @@ public final class NetherPathfinderContext {
|
||||
this.executor = Executors.newSingleThreadExecutor();
|
||||
}
|
||||
|
||||
public void queueCacheCulling(int chunkX, int chunkZ, int maxDistanceBlocks, BlockStateOctreeInterface boi) {
|
||||
this.executor.execute(() -> {
|
||||
synchronized (this.cacheLock) {
|
||||
boi.chunkPtr = 0L;
|
||||
NetherPathfinder.cullFarChunks(this.context, chunkX, chunkZ, maxDistanceBlocks);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void queueForPacking(final Chunk chunkIn) {
|
||||
final SoftReference<Chunk> ref = new SoftReference<>(chunkIn);
|
||||
this.executor.execute(() -> {
|
||||
|
||||
Reference in New Issue
Block a user