mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-25 01:49:16 +00:00
Async Data Read for Parallel World Ticking (#333)
* initial * improve compat further * cleanup and shit * more cleanup * rebase :3 * increase task queue size * [ci skip] rebuild patches * Optimise BlockEntity tickersInLevel * rebase * [ci skip] cleanup * cleanup * cleanup * clear the buffer at shutdown --------- Co-authored-by: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com> Co-authored-by: hayanesuru <hayanesuru@outlook.jp>
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
package org.dreeam.leaf.async.world;
|
||||
|
||||
public enum ReadOperationType {
|
||||
BLOCK_GET_BIOME,
|
||||
BLOCK_GET_COMPUTED_BIOME,
|
||||
BLOCK_IS_INDIRECTLY_POWERED,
|
||||
BLOCK_GET_BLOCK_POWER,
|
||||
BLOCK_RAY_TRACE,
|
||||
BLOCK_CAN_PLACE,
|
||||
BLOCK_GET_NMS_STATE
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package org.dreeam.leaf.async.world;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public record WorldReadRequest(
|
||||
ReadOperationType type,
|
||||
Object[] params, // Parameters for the read operation
|
||||
CompletableFuture<Object> future // Future to complete with the result
|
||||
) {
|
||||
}
|
||||
@@ -8,15 +8,19 @@ import org.dreeam.leaf.config.annotations.Experimental;
|
||||
public class SparklyPaperParallelWorldTicking extends ConfigModules {
|
||||
|
||||
public String getBasePath() {
|
||||
return EnumConfigCategory.ASYNC.getBaseKeyName() + ".parallel-world-tracking";
|
||||
} // TODO: Correct config key when stable
|
||||
// Corrected path based on your comment
|
||||
return EnumConfigCategory.ASYNC.getBaseKeyName() + ".parallel-world-ticking";
|
||||
}
|
||||
|
||||
@Experimental
|
||||
public static boolean enabled = false;
|
||||
public static int threads = 8;
|
||||
public static boolean logContainerCreationStacktraces = false;
|
||||
public static boolean disableHardThrow = false;
|
||||
@Deprecated
|
||||
public static boolean runAsyncTasksSync = false;
|
||||
// STRICT, BUFFERED, DISABLED
|
||||
public static String asyncUnsafeReadHandling = "BUFFERED";
|
||||
|
||||
@Override
|
||||
public void onLoaded() {
|
||||
@@ -34,15 +38,30 @@ public class SparklyPaperParallelWorldTicking extends ConfigModules {
|
||||
} else {
|
||||
threads = 0;
|
||||
}
|
||||
|
||||
logContainerCreationStacktraces = config.getBoolean(getBasePath() + ".log-container-creation-stacktraces", logContainerCreationStacktraces);
|
||||
logContainerCreationStacktraces = enabled && logContainerCreationStacktraces;
|
||||
disableHardThrow = config.getBoolean(getBasePath() + ".disable-hard-throw", disableHardThrow);
|
||||
disableHardThrow = enabled && disableHardThrow;
|
||||
runAsyncTasksSync = config.getBoolean(getBasePath() + ".run-async-tasks-sync", runAsyncTasksSync);
|
||||
runAsyncTasksSync = enabled && runAsyncTasksSync;
|
||||
asyncUnsafeReadHandling = config.getString(getBasePath() + ".async-unsafe-read-handling", asyncUnsafeReadHandling).toUpperCase();
|
||||
|
||||
if (!asyncUnsafeReadHandling.equals("STRICT") && !asyncUnsafeReadHandling.equals("BUFFERED") && !asyncUnsafeReadHandling.equals("DISABLED")) {
|
||||
System.err.println("[Leaf] Invalid value for " + getBasePath() + ".async-unsafe-read-handling: " + asyncUnsafeReadHandling + ". Defaulting to STRICT.");
|
||||
asyncUnsafeReadHandling = "STRICT";
|
||||
}
|
||||
if (!enabled) {
|
||||
asyncUnsafeReadHandling = "DISABLED";
|
||||
}
|
||||
|
||||
runAsyncTasksSync = config.getBoolean(getBasePath() + ".run-async-tasks-sync", false); // Default to false now
|
||||
if (runAsyncTasksSync) {
|
||||
System.err.println("[Leaf] WARNING: The setting '" + getBasePath() + ".run-async-tasks-sync' is deprecated. Use 'async-unsafe-read-handling: STRICT' for similar safety checks or 'BUFFERED' for buffered reads.");
|
||||
}
|
||||
|
||||
if (enabled) {
|
||||
LeafConfig.LOGGER.info("Using {} threads for Parallel World Ticking", threads);
|
||||
}
|
||||
|
||||
runAsyncTasksSync = enabled && runAsyncTasksSync; // Auto-disable if main feature is off
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user