cull far away chunks from the cache

This commit is contained in:
Babbaj 2023-07-16 01:19:51 -04:00
parent 6f99f891dc
commit 76d3a13f58
No known key found for this signature in database
GPG Key ID: F044309848A07CAC
4 changed files with 28 additions and 6 deletions

View File

@ -175,8 +175,8 @@ dependencies {
transitive = false transitive = false
} }
launchAnnotationProcessor 'org.spongepowered:mixin:0.8.4-SNAPSHOT:processor' launchAnnotationProcessor 'org.spongepowered:mixin:0.8.4-SNAPSHOT:processor'
launchImplementation('dev.babbaj:nether-pathfinder:0.24') launchImplementation('dev.babbaj:nether-pathfinder:0.34')
implementation 'dev.babbaj:nether-pathfinder:0.24' implementation 'dev.babbaj:nether-pathfinder:0.34'
testImplementation 'junit:junit:4.12' testImplementation 'junit:junit:4.12'
} }

View File

@ -38,6 +38,7 @@ import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.List; import java.util.List;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
import java.util.function.Consumer; import java.util.function.Consumer;
@ -1404,6 +1405,16 @@ public final class Settings {
*/ */
public final Setting<Integer> elytraMinimumDurability = new Setting<>(5); 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 * A map of lowercase setting field names to their respective setting
*/ */

View File

@ -118,9 +118,11 @@ public final class ElytraBehavior extends Behavior implements IElytraBehavior, H
private Solution pendingSolution; private Solution pendingSolution;
private boolean solveNextTick; private boolean solveNextTick;
private long timeLastCacheCull = 0L;
// auto swap // auto swap
private int invTickCountdown = 0; private int invTickCountdown = 0;
private final Queue<Runnable> transactionQueue = new LinkedList<>(); private final Queue<Runnable> invTransactionQueue = new LinkedList<>();
private ElytraBehavior(Baritone baritone) { private ElytraBehavior(Baritone baritone) {
super(baritone); super(baritone);
@ -516,6 +518,11 @@ public final class ElytraBehavior extends Behavior implements IElytraBehavior, H
if (event.getType() == TickEvent.Type.OUT) { if (event.getType() == TickEvent.Type.OUT) {
return; 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.timeLastCacheCull = now;
}
// Fetch the previous solution, regardless of if it's going to be used // Fetch the previous solution, regardless of if it's going to be used
this.pendingSolution = null; this.pendingSolution = null;
@ -1264,7 +1271,7 @@ public final class ElytraBehavior extends Behavior implements IElytraBehavior, H
private void tickInventoryTransactions() { private void tickInventoryTransactions() {
if (invTickCountdown <= 0) { if (invTickCountdown <= 0) {
Runnable r = transactionQueue.poll(); Runnable r = invTransactionQueue.poll();
if (r != null) { if (r != null) {
r.run(); r.run();
invTickCountdown = Baritone.settings().ticksBetweenInventoryMoves.value; 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) { 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() { private int findGoodElytra() {
@ -1289,7 +1296,7 @@ public final class ElytraBehavior extends Behavior implements IElytraBehavior, H
} }
private void trySwapElytra() { private void trySwapElytra() {
if (!Baritone.settings().elytraAutoSwap.value || !transactionQueue.isEmpty()) { if (!Baritone.settings().elytraAutoSwap.value || !invTransactionQueue.isEmpty()) {
return; return;
} }

View File

@ -57,6 +57,10 @@ public final class NetherPathfinderContext {
this.executor = Executors.newSingleThreadExecutor(); this.executor = Executors.newSingleThreadExecutor();
} }
public void queueCacheCulling(int chunkX, int chunkZ, int maxDistanceBlocks) {
this.executor.execute(() -> NetherPathfinder.cullFarChunks(this.context, chunkX, chunkZ, maxDistanceBlocks));
}
public void queueForPacking(final Chunk chunkIn) { public void queueForPacking(final Chunk chunkIn) {
final SoftReference<Chunk> ref = new SoftReference<>(chunkIn); final SoftReference<Chunk> ref = new SoftReference<>(chunkIn);
this.executor.execute(() -> { this.executor.execute(() -> {