mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-20 15:39:37 +00:00
cleanup & remove threshold in async target finding
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -100,7 +100,7 @@ index 4535858701b2bb232b9d2feb2af6551526232ddc..e65c62dbe4c1560ae153e4c4344e9194
|
|||||||
- // Paper end - detailed watchdog information
|
- // Paper end - detailed watchdog information
|
||||||
}
|
}
|
||||||
diff --git a/net/minecraft/server/level/ServerChunkCache.java b/net/minecraft/server/level/ServerChunkCache.java
|
diff --git a/net/minecraft/server/level/ServerChunkCache.java b/net/minecraft/server/level/ServerChunkCache.java
|
||||||
index 9dd6205e1cdd2124ab9d91f0a1e344eb6aa1fb2e..d8ae228fa4dfb265b628e83936f297f88c74aa57 100644
|
index fc86e900e41305287a6cc6d766184c6e28d6189b..6fd7e881bcfc7df2e4ac7abb99504c8194470e96 100644
|
||||||
--- a/net/minecraft/server/level/ServerChunkCache.java
|
--- a/net/minecraft/server/level/ServerChunkCache.java
|
||||||
+++ b/net/minecraft/server/level/ServerChunkCache.java
|
+++ b/net/minecraft/server/level/ServerChunkCache.java
|
||||||
@@ -622,8 +622,10 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
|
@@ -622,8 +622,10 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
|
||||||
@@ -117,10 +117,10 @@ index 9dd6205e1cdd2124ab9d91f0a1e344eb6aa1fb2e..d8ae228fa4dfb265b628e83936f297f8
|
|||||||
|
|
||||||
for (LevelChunk levelChunk : list) {
|
for (LevelChunk levelChunk : list) {
|
||||||
diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java
|
diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java
|
||||||
index c0044f4013520fd617ec365012b10862571744f3..14d23006d3ec15bb3ec6f976bff6c0975662c69d 100644
|
index 224a032e8992f104ad9380182ed67c316c93274e..7d34862d15360940e12b9c0f131ecffdb2a0a146 100644
|
||||||
--- a/net/minecraft/server/level/ServerLevel.java
|
--- a/net/minecraft/server/level/ServerLevel.java
|
||||||
+++ b/net/minecraft/server/level/ServerLevel.java
|
+++ b/net/minecraft/server/level/ServerLevel.java
|
||||||
@@ -1518,13 +1518,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
|
@@ -1508,13 +1508,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
|
||||||
// Paper end - log detailed entity tick information
|
// Paper end - log detailed entity tick information
|
||||||
|
|
||||||
public void tickNonPassenger(Entity entity) {
|
public void tickNonPassenger(Entity entity) {
|
||||||
@@ -134,7 +134,7 @@ index c0044f4013520fd617ec365012b10862571744f3..14d23006d3ec15bb3ec6f976bff6c097
|
|||||||
entity.setOldPosAndRot();
|
entity.setOldPosAndRot();
|
||||||
entity.tickCount++;
|
entity.tickCount++;
|
||||||
entity.totalEntityAge++; // Paper - age-like counter for all entities
|
entity.totalEntityAge++; // Paper - age-like counter for all entities
|
||||||
@@ -1537,13 +1531,6 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
|
@@ -1527,13 +1521,6 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
|
||||||
for (Entity entity1 : entity.getPassengers()) {
|
for (Entity entity1 : entity.getPassengers()) {
|
||||||
this.tickPassenger(entity, entity1, isActive); // Paper - EAR 2
|
this.tickPassenger(entity, entity1, isActive); // Paper - EAR 2
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package org.dreeam.leaf.async.ai;
|
package org.dreeam.leaf.async.ai;
|
||||||
|
|
||||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.entity.Mob;
|
import net.minecraft.world.entity.Mob;
|
||||||
@@ -10,85 +9,54 @@ import org.dreeam.leaf.config.modules.async.AsyncTargetFinding;
|
|||||||
import org.dreeam.leaf.util.queue.SpscIntQueue;
|
import org.dreeam.leaf.util.queue.SpscIntQueue;
|
||||||
|
|
||||||
import java.util.OptionalInt;
|
import java.util.OptionalInt;
|
||||||
import java.util.concurrent.locks.LockSupport;
|
|
||||||
|
|
||||||
public class AsyncGoalExecutor {
|
public class AsyncGoalExecutor {
|
||||||
|
|
||||||
protected static final Logger LOGGER = LogManager.getLogger("Leaf Async Goal");
|
protected static final Logger LOGGER = LogManager.getLogger("Leaf Async Goal");
|
||||||
protected final SpscIntQueue queue;
|
protected final SpscIntQueue queue;
|
||||||
protected final SpscIntQueue wake;
|
|
||||||
protected final IntArrayList submit;
|
|
||||||
private final ServerLevel world;
|
private final ServerLevel world;
|
||||||
private long midTickCount = 0L;
|
|
||||||
|
|
||||||
public AsyncGoalExecutor(AsyncGoalThread thread, ServerLevel world) {
|
public AsyncGoalExecutor(ServerLevel world) {
|
||||||
this.world = world;
|
this.world = world;
|
||||||
this.queue = new SpscIntQueue(AsyncTargetFinding.queueSize);
|
this.queue = new SpscIntQueue(AsyncTargetFinding.queueSize);
|
||||||
this.wake = new SpscIntQueue(AsyncTargetFinding.queueSize);
|
|
||||||
this.submit = new IntArrayList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean wake(int id) {
|
boolean wakeAll() {
|
||||||
Entity entity = this.world.getEntities().get(id);
|
boolean success = false;
|
||||||
if (entity == null || entity.isRemoved() || !(entity instanceof Mob mob)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
mob.goalSelector.ctx.wake();
|
|
||||||
mob.targetSelector.ctx.wake();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public final void submit(int entityId) {
|
|
||||||
this.submit.add(entityId);
|
|
||||||
}
|
|
||||||
|
|
||||||
public final void tick() {
|
|
||||||
batchSubmit();
|
|
||||||
while (true) {
|
while (true) {
|
||||||
OptionalInt result = this.wake.recv();
|
OptionalInt result = queue.recv();
|
||||||
if (result.isEmpty()) {
|
if (result.isEmpty()) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
int id = result.getAsInt();
|
int id = result.getAsInt();
|
||||||
if (poll(id) && !this.queue.send(id)) {
|
success = true;
|
||||||
do {
|
wake(id);
|
||||||
wake(id);
|
|
||||||
} while (poll(id));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void batchSubmit() {
|
public void tickMob(Mob mob) {
|
||||||
if (submit.isEmpty()) {
|
if (!poll(mob)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int[] raw = submit.elements();
|
int entityId = mob.getId();
|
||||||
int size = submit.size();
|
if (!this.queue.send(entityId)) {
|
||||||
for (int i = 0; i < size; i++) {
|
do {
|
||||||
int id = raw[i];
|
wake(entityId);
|
||||||
if (poll(id) && !this.queue.send(id)) {
|
} while (poll(mob));
|
||||||
do {
|
|
||||||
wake(id);
|
|
||||||
} while (poll(id));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
this.submit.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void midTick() {
|
private void wake(int id) {
|
||||||
if (AsyncTargetFinding.threshold <= 0L || (midTickCount % AsyncTargetFinding.threshold) == 0L) {
|
|
||||||
batchSubmit();
|
|
||||||
}
|
|
||||||
|
|
||||||
midTickCount += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean poll(int id) {
|
|
||||||
Entity entity = this.world.getEntities().get(id);
|
Entity entity = this.world.getEntities().get(id);
|
||||||
if (entity == null || entity.isRemoved() || !(entity instanceof Mob mob)) {
|
if (entity == null || entity.isRemoved() || !(entity instanceof Mob mob)) {
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
mob.goalSelector.ctx.wake();
|
||||||
|
mob.targetSelector.ctx.wake();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean poll(Mob mob) {
|
||||||
try {
|
try {
|
||||||
mob.tickingTarget = true;
|
mob.tickingTarget = true;
|
||||||
boolean a = mob.targetSelector.poll();
|
boolean a = mob.targetSelector.poll();
|
||||||
@@ -97,8 +65,7 @@ public class AsyncGoalExecutor {
|
|||||||
return a || b;
|
return a || b;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error("Exception while polling", e);
|
LOGGER.error("Exception while polling", e);
|
||||||
// retry
|
return false;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,26 +22,11 @@ public class AsyncGoalThread extends Thread {
|
|||||||
while (RUNNING) {
|
while (RUNNING) {
|
||||||
boolean retry = false;
|
boolean retry = false;
|
||||||
for (ServerLevel level : server.getAllLevels()) {
|
for (ServerLevel level : server.getAllLevels()) {
|
||||||
var exec = level.asyncGoalExecutor;
|
retry |= level.asyncGoalExecutor.wakeAll();
|
||||||
while (true) {
|
|
||||||
OptionalInt result = exec.queue.recv();
|
|
||||||
if (result.isEmpty()) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
int id = result.getAsInt();
|
|
||||||
retry = true;
|
|
||||||
if (exec.wake(id)) {
|
|
||||||
while (!exec.wake.send(id)) {
|
|
||||||
Thread.onSpinWait();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Thread.yield();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!retry) {
|
if (!retry) {
|
||||||
LockSupport.parkNanos(10_000L);
|
LockSupport.parkNanos(1_000_000L);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ public class AsyncTargetFinding extends ConfigModules {
|
|||||||
public static boolean searchBlock = true;
|
public static boolean searchBlock = true;
|
||||||
public static boolean searchEntity = true;
|
public static boolean searchEntity = true;
|
||||||
public static int queueSize = 4096;
|
public static int queueSize = 4096;
|
||||||
public static long threshold = 10L;
|
|
||||||
private static boolean asyncTargetFindingInitialized;
|
private static boolean asyncTargetFindingInitialized;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -36,21 +35,17 @@ public class AsyncTargetFinding extends ConfigModules {
|
|||||||
enabled = config.getBoolean(getBasePath() + ".enabled", enabled);
|
enabled = config.getBoolean(getBasePath() + ".enabled", enabled);
|
||||||
// Disable if parallel world ticking is enabled, as they are incompatible.
|
// Disable if parallel world ticking is enabled, as they are incompatible.
|
||||||
if (enabled && SparklyPaperParallelWorldTicking.enabled) {
|
if (enabled && SparklyPaperParallelWorldTicking.enabled) {
|
||||||
LeafConfig.LOGGER.warn("Async Target Finding is incompatible with Parallel World Ticking. Disabling Async Target Finding automatically.");
|
LeafConfig.LOGGER.warn("Async target finding is incompatible with Parallel World Ticking. Disabling Async target finding automatically.");
|
||||||
enabled = false;
|
enabled = false;
|
||||||
}
|
}
|
||||||
alertOther = config.getBoolean(getBasePath() + ".async-alert-other", true);
|
alertOther = config.getBoolean(getBasePath() + ".async-alert-other", true);
|
||||||
searchBlock = config.getBoolean(getBasePath() + ".async-search-block", true);
|
searchBlock = config.getBoolean(getBasePath() + ".async-search-block", true);
|
||||||
searchEntity = config.getBoolean(getBasePath() + ".async-search-entity", true);
|
searchEntity = config.getBoolean(getBasePath() + ".async-search-entity", true);
|
||||||
queueSize = config.getInt(getBasePath() + ".queue-size", 0);
|
queueSize = config.getInt(getBasePath() + ".queue-size", 0);
|
||||||
threshold = config.getLong(getBasePath() + ".threshold", 0);
|
|
||||||
|
|
||||||
if (queueSize <= 0) {
|
if (queueSize <= 0) {
|
||||||
queueSize = 4096;
|
queueSize = 4096;
|
||||||
}
|
}
|
||||||
if (threshold == 0L) {
|
|
||||||
threshold = 10L;
|
|
||||||
}
|
|
||||||
if (!enabled) {
|
if (!enabled) {
|
||||||
alertOther = false;
|
alertOther = false;
|
||||||
searchEntity = false;
|
searchEntity = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user