9
0
mirror of https://github.com/BX-Team/DivineMC.git synced 2025-12-21 07:49:18 +00:00

remove old shit

This commit is contained in:
NONPLAYT
2025-06-29 15:37:48 +03:00
parent cf50ee19bb
commit 880ce4bded
17 changed files with 265 additions and 447 deletions

View File

@@ -1,20 +1,21 @@
package com.ishland.flowsched.structs;
import org.bxteam.divinemc.server.chunk.PriorityHandler;
import ca.spottedleaf.moonrise.common.util.MoonriseConstants;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicIntegerArray;
@SuppressWarnings("unchecked")
public class DynamicPriorityQueue<E> {
public static final int MAX_PRIORITY = MoonriseConstants.MAX_VIEW_DISTANCE + 3;
private final AtomicIntegerArray taskCount;
public final ConcurrentLinkedQueue<E>[] priorities;
private final ConcurrentHashMap<E, Integer> priorityMap = new ConcurrentHashMap<>();
public DynamicPriorityQueue() {
this.taskCount = new AtomicIntegerArray(PriorityHandler.MAX_PRIORITY + 1);
this.priorities = new ConcurrentLinkedQueue[PriorityHandler.MAX_PRIORITY + 1];
for (int i = 0; i < (PriorityHandler.MAX_PRIORITY + 1); i++) {
this.taskCount = new AtomicIntegerArray(MAX_PRIORITY);
this.priorities = new ConcurrentLinkedQueue[MAX_PRIORITY];
for (int i = 0; i < (MAX_PRIORITY); i++) {
this.priorities[i] = new ConcurrentLinkedQueue<>();
}
}

View File

@@ -11,8 +11,6 @@ import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.MemoryConfiguration;
import org.bxteam.divinemc.entity.pathfinding.PathfindTaskRejectPolicy;
import org.bxteam.divinemc.region.LinearImplementation;
import org.bxteam.divinemc.server.chunk.ChunkSystemAlgorithms;
import org.bxteam.divinemc.server.chunk.ChunkTaskPriority;
import org.jetbrains.annotations.Nullable;
import org.simpleyaml.configuration.comments.CommentType;
import org.simpleyaml.configuration.file.YamlFile;
@@ -339,8 +337,6 @@ public class DivineConfig {
public static long chunkDataCacheLimit = 32678L;
public static int maxViewDistance = 32;
public static int playerNearChunkDetectionRange = 128;
public static ChunkSystemAlgorithms chunkWorkerAlgorithm = ChunkSystemAlgorithms.C2ME;
public static ChunkTaskPriority chunkTaskPriority = ChunkTaskPriority.EUCLIDEAN_CIRCLE_PATTERN;
public static int threadPoolPriority = Thread.NORM_PRIORITY + 1;
public static boolean smoothBedrockLayer = false;
public static boolean enableDensityFunctionCompiler = false;
@@ -410,17 +406,6 @@ public class DivineConfig {
playerNearChunkDetectionRange = 128;
}
chunkWorkerAlgorithm = ChunkSystemAlgorithms.valueOf(getString(ConfigCategory.PERFORMANCE.key("chunks.chunk-worker-algorithm"), chunkWorkerAlgorithm.name(),
"Modifies what algorithm the chunk system will use to define thread counts.",
"Valid values:",
" - MOONRISE: Default algorithm, used by default in Paper",
" - C2ME: Algorithm used by C2ME (old)",
" - C2ME_NEW: Modern algorithm used by C2ME"));
chunkTaskPriority = ChunkTaskPriority.valueOf(getString(ConfigCategory.PERFORMANCE.key("chunks.chunk-task-priority"), chunkTaskPriority.name(),
"Sets the algorithm for determining chunk task priorities (generation, loading and etc.).",
"Valid values:",
" - EUCLIDEAN_CIRCLE_PATTERN: Euclidean distance squared algorithm, chunk priorities will be ordered in a circle pattern",
" - DEFAULT_DIAMOND_PATTERN: Default one, chunk priorities will be ordered in a diamond pattern"));
threadPoolPriority = getInt(ConfigCategory.PERFORMANCE.key("chunks.thread-pool-priority"), threadPoolPriority,
"Sets the priority of the thread pool used for chunk generation");

View File

@@ -1,32 +0,0 @@
package org.bxteam.divinemc.server.chunk;
import ca.spottedleaf.concurrentutil.util.ConcurrentUtil;
import net.minecraft.server.level.ServerLevel;
import java.lang.invoke.VarHandle;
public class ChunkRunnable implements Runnable {
public final int chunkX;
public final int chunkZ;
public final ServerLevel world;
private volatile Runnable toRun;
private static final VarHandle TO_RUN_HANDLE = ConcurrentUtil.getVarHandle(ChunkRunnable.class, "toRun", Runnable.class);
public ChunkRunnable(int chunkX, int chunkZ, ServerLevel world, Runnable run) {
this.chunkX = chunkX;
this.chunkZ = chunkZ;
this.world = world;
this.toRun = run;
}
public void setRunnable(final Runnable run) {
final Runnable prev = (Runnable)TO_RUN_HANDLE.compareAndExchange(this, (Runnable)null, run);
if (prev != null) {
throw new IllegalStateException("Runnable already set");
}
}
@Override
public void run() {
((Runnable)TO_RUN_HANDLE.getVolatile(this)).run();
}
}

View File

@@ -1,116 +0,0 @@
package org.bxteam.divinemc.server.chunk;
import ca.spottedleaf.moonrise.common.PlatformHooks;
import io.netty.util.internal.PlatformDependent;
import net.objecthunter.exp4j.ExpressionBuilder;
import net.objecthunter.exp4j.function.Function;
import org.jetbrains.annotations.NotNull;
import oshi.util.tuples.Pair;
import java.util.function.BiFunction;
public enum ChunkSystemAlgorithms {
MOONRISE((configWorkerThreads, configIoThreads) -> {
int defaultWorkerThreads = Runtime.getRuntime().availableProcessors() / 2;
if (defaultWorkerThreads <= 4) {
defaultWorkerThreads = defaultWorkerThreads <= 3 ? 1 : 2;
} else {
defaultWorkerThreads = defaultWorkerThreads / 2;
}
defaultWorkerThreads = Integer.getInteger(PlatformHooks.get().getBrand() + ".WorkerThreadCount", Integer.valueOf(defaultWorkerThreads));
int workerThreads = configWorkerThreads;
if (workerThreads <= 0) {
workerThreads = defaultWorkerThreads;
}
final int ioThreads = Math.max(1, configIoThreads);
return new Pair<>(workerThreads, ioThreads);
}),
C2ME_NEW((configWorkerThreads, configIoThreads) -> {
String expression = """
max(
1,
min(
if( is_windows,
(cpus / 1.6),
(cpus / 1.3)
) - if(is_client, 1, 0),
( ( mem_gb - (if(is_client, 1.0, 0.5)) ) / 0.6 )
)
)
\040""";
int eval = configWorkerThreads <= 0 ? tryEvaluateExpression(expression) : configWorkerThreads;
return new Pair<>(eval, Math.max(1, configIoThreads));
}),
C2ME((configWorkerThreads, configIoThreads) -> {
String expression = """
max(
1,
min(
if( is_windows,
(cpus / 1.6 - 2),
(cpus / 1.2 - 2)
) - if(is_client, 2, 0),
if( is_j9vm,
( ( mem_gb - (if(is_client, 0.6, 0.2)) ) / 0.4 ),
( ( mem_gb - (if(is_client, 1.2, 0.6)) ) / 0.6 )
)
)
)
\040""";
int eval = configWorkerThreads <= 0 ? tryEvaluateExpression(expression) : configWorkerThreads;
return new Pair<>(eval, Math.max(1, configIoThreads));
});
private final BiFunction<Integer, Integer, Pair<Integer, Integer>> eval;
ChunkSystemAlgorithms(BiFunction<Integer, Integer, Pair<Integer, Integer>> eval) {
this.eval = eval;
}
private static int tryEvaluateExpression(String expression) {
return (int) Math.max(1,
new ExpressionBuilder(expression)
.variables("is_windows", "is_j9vm", "is_client", "cpus", "mem_gb")
.function(new Function("max", 2) {
@Override
public double apply(double... args) {
return Math.max(args[0], args[1]);
}
})
.function(new Function("min", 2) {
@Override
public double apply(double... args) {
return Math.min(args[0], args[1]);
}
})
.function(new Function("if", 3) {
@Override
public double apply(double... args) {
return args[0] != 0 ? args[1] : args[2];
}
})
.build()
.setVariable("is_windows", PlatformDependent.isWindows() ? 1 : 0)
.setVariable("is_j9vm", PlatformDependent.isJ9Jvm() ? 1 : 0)
.setVariable("is_client", 0)
.setVariable("cpus", Runtime.getRuntime().availableProcessors())
.setVariable("mem_gb", Runtime.getRuntime().maxMemory() / 1024.0 / 1024.0 / 1024.0)
.evaluate()
);
}
public int evalWorkers(final int configWorkerThreads, final int configIoThreads) {
return eval.apply(configWorkerThreads, configIoThreads).getA();
}
public int evalIO(final int configWorkerThreads, final int configIoThreads) {
return eval.apply(configWorkerThreads, configIoThreads).getB();
}
public @NotNull String asDebugString() {
return this + "(" + evalWorkers(-1, -1) + ")";
}
}

View File

@@ -3,9 +3,7 @@ package org.bxteam.divinemc.server.chunk;
import ca.spottedleaf.concurrentutil.executor.PrioritisedExecutor;
import ca.spottedleaf.concurrentutil.util.ConcurrentUtil;
import ca.spottedleaf.concurrentutil.util.Priority;
import ca.spottedleaf.moonrise.patches.chunk_system.scheduling.executor.RadiusAwarePrioritisedExecutor;
import ca.spottedleaf.moonrise.patches.chunk_system.scheduling.task.ChunkUpgradeGenericStatusTask;
import ca.spottedleaf.moonrise.patches.chunk_system.scheduling.task.GenericDataLoadTask;
import java.lang.invoke.VarHandle;
import java.util.Comparator;
import java.util.Map;
@@ -152,29 +150,7 @@ public final class ChunkSystemTaskQueue implements PrioritisedExecutor {
this.holder = new Holder(this, this.priority.priority, this.subOrder, this.id);
ChunkSystemTaskQueue.this.scheduledTasks.getAndIncrement();
int priority = this.holder.task.priority.priority;
if (this.holder.task.priority.isHigherOrEqualPriority(Priority.BLOCKING)) {
priority = PriorityHandler.BLOCKING;
} else if (this.holder.task.execute instanceof ChunkUpgradeGenericStatusTask upgradeTask) {
int x = upgradeTask.chunkX;
int z = upgradeTask.chunkZ;
priority = upgradeTask.world.chunkSystemPriorities.priority(x, z);
} else if (this.holder.task.execute instanceof RadiusAwarePrioritisedExecutor.Task task) {
int x = task.chunkX;
int z = task.chunkZ;
if (!(x == 0 && z == 0)) {
priority = task.world.chunkSystemPriorities.priority(x, z);
} // else | infinite radius task, ignore.
} else if (this.holder.task.execute instanceof GenericDataLoadTask<?, ?>.ProcessOffMainTask offMainTask) {
int x = offMainTask.loadTask().chunkX;
int z = offMainTask.loadTask().chunkZ;
priority = offMainTask.loadTask().world.chunkSystemPriorities.priority(x, z);
} else if (this.holder.task.execute instanceof ChunkRunnable chunkRunnable) {
int x = chunkRunnable.chunkX;
int z = chunkRunnable.chunkZ;
priority = chunkRunnable.world.chunkSystemPriorities.priority(x, z);
}
ChunkSystemTaskQueue.this.chunkSystem.schedule(this.holder.task.execute, priority);
ChunkSystemTaskQueue.this.chunkSystem.schedule(this.holder.task.execute, this.holder.task.priority.priority);
}
if (ChunkSystemTaskQueue.this.isShutdown()) {

View File

@@ -1,6 +0,0 @@
package org.bxteam.divinemc.server.chunk;
public enum ChunkTaskPriority {
EUCLIDEAN_CIRCLE_PATTERN,
DEFAULT_DIAMOND_PATTERN,
}

View File

@@ -1,32 +0,0 @@
package org.bxteam.divinemc.server.chunk;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.Mth;
import net.minecraft.world.level.ChunkPos;
import static ca.spottedleaf.moonrise.common.util.MoonriseConstants.MAX_VIEW_DISTANCE;
public class PriorityHandler {
public static final int MAX_PRIORITY = MAX_VIEW_DISTANCE + 2;
public static final int BLOCKING = 0;
public final ServerLevel level;
public PriorityHandler(ServerLevel world) {
this.level = world;
}
public int priority(int chunkX, int chunkZ) {
int priority = MAX_PRIORITY;
for (final ServerPlayer player : this.level.players()) {
ChunkPos playerChunk = player.chunkPosition();
int playerChunkX = playerChunk.x;
int playerChunkZ = playerChunk.z;
int dist = Math.max(Mth.abs(playerChunkX - chunkX), Mth.abs(playerChunkZ - chunkZ));
int distPriority = Math.max(0, MAX_VIEW_DISTANCE - dist);
priority = Math.min(priority, distPriority);
}
return priority;
}
}