mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2026-01-03 22:26:19 +00:00
Made async entity tracker threads configurable to prevent waste too much performance
and Format, Cleanup code
This commit is contained in:
@@ -5,7 +5,7 @@ Subject: [PATCH] Leaf Config
|
||||
|
||||
|
||||
diff --git a/build.gradle.kts b/build.gradle.kts
|
||||
index 936c738fcaa8e97c36d0742d2398d63c20cd2f68..6a74e98d4795aac2e53579fd92a3e53bcf3e670f 100644
|
||||
index a8a720045804cded8f8dffc1bfdd20710b8f0c82..c8ba9702926c55f783d35a7df9b3cfc3af27f005 100644
|
||||
--- a/build.gradle.kts
|
||||
+++ b/build.gradle.kts
|
||||
@@ -56,6 +56,13 @@ dependencies {
|
||||
@@ -36,7 +36,7 @@ index 2c8eb9294890955f71382ed3884874cc827bab5e..ee29ceff6804383edc229cd302ab0734
|
||||
this.setFlightAllowed(dedicatedserverproperties.allowFlight);
|
||||
diff --git a/src/main/java/org/dreeam/leaf/LeafConfig.java b/src/main/java/org/dreeam/leaf/LeafConfig.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..d924db6378b2c60c7b96cf5c45a6d50a091f9790
|
||||
index 0000000000000000000000000000000000000000..74becc68c443917b0ec75bfe40ca4079532e0ac0
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/org/dreeam/leaf/LeafConfig.java
|
||||
@@ -0,0 +1,171 @@
|
||||
@@ -107,7 +107,7 @@ index 0000000000000000000000000000000000000000..d924db6378b2c60c7b96cf5c45a6d50a
|
||||
+ try {
|
||||
+ method.invoke(null);
|
||||
+ } catch (Throwable t) {
|
||||
+ MinecraftServer.LOGGER.warn("Failed to load configuration option from " + method.getName(), t);
|
||||
+ MinecraftServer.LOGGER.warn("Failed to load configuration option from {}", method.getName(), t);
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
|
||||
@@ -42,7 +42,7 @@ index 1591e201ebca4354d5912d3f803f59759af1ba6e..98e666c69b51f7b4fec040b7abd9667d
|
||||
if (false && this.shouldDiscardEntity(entity)) { // CraftBukkit - We prevent spawning in general, so this butchering is not needed
|
||||
entity.discard();
|
||||
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
|
||||
index 6231a59a22b47b16de0b4186eae70759cab92a7f..be371242518c4027e03e233db1bd0a9192e9edc9 100644
|
||||
index 68fe93725a37cb0f52401038c1bda141ba0a4068..daff07928b7087c9a3d5d426446316545a5b08b8 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
||||
@@ -503,6 +503,11 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
|
||||
@@ -70,7 +70,7 @@ index 09e8445a3f8c6b3ebc852a75a9a25b41a51ba659..d86c34111ede6a1454dde5e7223d7caf
|
||||
private String descriptionId;
|
||||
@Nullable
|
||||
diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java
|
||||
index d3a1af49024c7cd2854dc8a715450adc64aa083e..7828db1230d0fea3d6ea43423b4118906890692f 100644
|
||||
index 8f91e97240c50a6bbef6b7c71b5e3002a4ef79a8..b7d2d19f029c6fdc6091c9f60278a528885e17f8 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/Mob.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/Mob.java
|
||||
@@ -227,10 +227,10 @@ public abstract class Mob extends LivingEntity implements Targeting {
|
||||
@@ -294,7 +294,7 @@ index 5a9d567fdcaa02cf91dac889949f4428987f6fdd..e6b5b7c58505f021dc042c2c40733add
|
||||
this.assignProfessionWhenSpawned = false;
|
||||
}
|
||||
diff --git a/src/main/java/org/dreeam/leaf/LeafConfig.java b/src/main/java/org/dreeam/leaf/LeafConfig.java
|
||||
index 5d161351e7517acf57e98203bab8c9f9ab9d4005..634a4e46022f1d63a67c64f19f25553859e73e1f 100644
|
||||
index 825e5d0a155039d9d87eb2ff9ef025fcb69d874a..e4c0f914681cbe99ced38e02b8b072eb1fb00159 100644
|
||||
--- a/src/main/java/org/dreeam/leaf/LeafConfig.java
|
||||
+++ b/src/main/java/org/dreeam/leaf/LeafConfig.java
|
||||
@@ -1,7 +1,9 @@
|
||||
@@ -351,7 +351,7 @@ index 5d161351e7517acf57e98203bab8c9f9ab9d4005..634a4e46022f1d63a67c64f19f255538
|
||||
+ getStringList("performance.dab.blacklisted-entities", "dab.blacklisted-entities", Collections.emptyList(), "A list of entities to ignore for activation")
|
||||
+ .forEach(name -> EntityType.byString(name).ifPresentOrElse(entityType -> {
|
||||
+ entityType.dabEnabled = false;
|
||||
+ }, () -> MinecraftServer.LOGGER.warn("Unknown entity \"" + name + "\"")));
|
||||
+ }, () -> MinecraftServer.LOGGER.warn("Unknown entity \"{}\"", name)));
|
||||
+ setComment("performance.dab", "Optimizes entity brains when", "they're far away from the player");
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ Original license: GPL v3
|
||||
Original project: https://github.com/pufferfish-gg/Pufferfish
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java
|
||||
index 88cccee4152d18db34818a37c7a2c19dcb6ef596..c413a191fa8fd1a2447f51f66187f0c18818c222 100644
|
||||
index b7d2d19f029c6fdc6091c9f60278a528885e17f8..8db706677eaa1bb4fedeae4679b81fe57e797cab 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/Mob.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/Mob.java
|
||||
@@ -223,11 +223,13 @@ public abstract class Mob extends LivingEntity implements Targeting {
|
||||
@@ -26,7 +26,7 @@ index 88cccee4152d18db34818a37c7a2c19dcb6ef596..c413a191fa8fd1a2447f51f66187f0c1
|
||||
}
|
||||
if (this.targetSelector.inactiveTick(this.activatedPriority, true)) { // Pufferfish - pass activated priority
|
||||
diff --git a/src/main/java/org/dreeam/leaf/LeafConfig.java b/src/main/java/org/dreeam/leaf/LeafConfig.java
|
||||
index 634a4e46022f1d63a67c64f19f25553859e73e1f..9a11228726c9a489181fc8a0c511ea83cdcf0f6e 100644
|
||||
index e4c0f914681cbe99ced38e02b8b072eb1fb00159..141754b5b4361905e22dd9276a921cfc4847b0c4 100644
|
||||
--- a/src/main/java/org/dreeam/leaf/LeafConfig.java
|
||||
+++ b/src/main/java/org/dreeam/leaf/LeafConfig.java
|
||||
@@ -173,7 +173,7 @@ public class LeafConfig {
|
||||
@@ -40,7 +40,7 @@ index 634a4e46022f1d63a67c64f19f25553859e73e1f..9a11228726c9a489181fc8a0c511ea83
|
||||
"Whether or not asynchronous mob spawning should be enabled.",
|
||||
@@ -207,6 +207,9 @@ public class LeafConfig {
|
||||
entityType.dabEnabled = false;
|
||||
}, () -> MinecraftServer.LOGGER.warn("Unknown entity \"" + name + "\"")));
|
||||
}, () -> MinecraftServer.LOGGER.warn("Unknown entity \"{}\"", name)));
|
||||
setComment("performance.dab", "Optimizes entity brains when", "they're far away from the player");
|
||||
+ throttleInactiveGoalSelectorTick = getBoolean("performance.inactive-goal-selector-throttle", "inactive-goal-selector-throttle", throttleInactiveGoalSelectorTick,
|
||||
+ "Throttles the AI goal selector in entity inactive ticks.",
|
||||
|
||||
@@ -943,26 +943,10 @@ index 0e2b14e7dfedf209d63279c81723fd7955122d78..079b278e2e262af433bb5bd0c12b3d8d
|
||||
|
||||
public SwimNodeEvaluator(boolean canJumpOutOfWater) {
|
||||
diff --git a/src/main/java/org/dreeam/leaf/LeafConfig.java b/src/main/java/org/dreeam/leaf/LeafConfig.java
|
||||
index 9fe0574ca955e331752a0a324e4582dc5c178f89..5a803587c147c75523fdbfbbe9f1908eaf7b8ed4 100644
|
||||
index 9be596251deb2c73e8af7f4e62a3a24c72cc0369..abcf4fee07b6ea85de116252b823d30e57006654 100644
|
||||
--- a/src/main/java/org/dreeam/leaf/LeafConfig.java
|
||||
+++ b/src/main/java/org/dreeam/leaf/LeafConfig.java
|
||||
@@ -5,6 +5,7 @@ import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import java.util.Random;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
+import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.MemoryConfiguration;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -20,6 +21,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
+import java.util.logging.Level;
|
||||
|
||||
public class LeafConfig {
|
||||
|
||||
@@ -201,6 +203,9 @@ public class LeafConfig {
|
||||
@@ -201,6 +201,9 @@ public class LeafConfig {
|
||||
public static Map<String, Integer> projectileTimeouts;
|
||||
public static boolean useSpigotItemMergingMechanism = true;
|
||||
public static boolean optimizedPoweredRails = false;
|
||||
@@ -972,7 +956,7 @@ index 9fe0574ca955e331752a0a324e4582dc5c178f89..5a803587c147c75523fdbfbbe9f1908e
|
||||
private static void performance() {
|
||||
boolean asyncMobSpawning = getBoolean("performance.enable-async-mob-spawning", enableAsyncMobSpawning,
|
||||
"Whether or not asynchronous mob spawning should be enabled.",
|
||||
@@ -251,6 +256,17 @@ public class LeafConfig {
|
||||
@@ -251,6 +254,17 @@ public class LeafConfig {
|
||||
}
|
||||
useSpigotItemMergingMechanism = getBoolean("performance.use-spigot-item-merging-mechanism", useSpigotItemMergingMechanism);
|
||||
optimizedPoweredRails = getBoolean("performance.optimizedPoweredRails", optimizedPoweredRails);
|
||||
@@ -986,13 +970,13 @@ index 9fe0574ca955e331752a0a324e4582dc5c178f89..5a803587c147c75523fdbfbbe9f1908e
|
||||
+ if (!asyncPathfinding)
|
||||
+ asyncPathfindingMaxThreads = 0;
|
||||
+ else
|
||||
+ Bukkit.getLogger().log(Level.INFO, "Using " + asyncPathfindingMaxThreads + " threads for Async Pathfinding");
|
||||
+ MinecraftServer.LOGGER.info("Using {} threads for Async Pathfinding", asyncPathfindingMaxThreads);
|
||||
}
|
||||
|
||||
public static boolean jadeProtocol = false;
|
||||
diff --git a/src/main/java/org/dreeam/leaf/async/path/AsyncPath.java b/src/main/java/org/dreeam/leaf/async/path/AsyncPath.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..2ee7dca3d66e6bf2d4f72933b8a3dd9e91819c2e
|
||||
index 0000000000000000000000000000000000000000..2f5aff1f0e2aca0a8bfeab27c4ab027ffc21055d
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/org/dreeam/leaf/async/path/AsyncPath.java
|
||||
@@ -0,0 +1,287 @@
|
||||
@@ -1046,19 +1030,19 @@ index 0000000000000000000000000000000000000000..2ee7dca3d66e6bf2d4f72933b8a3dd9e
|
||||
+ private final List<Node> nodes;
|
||||
+ /**
|
||||
+ * the block we're trying to path to
|
||||
+ *
|
||||
+ * <p>
|
||||
+ * while processing, we have no idea where this is so consumers of `Path` should check that the path is processed before checking the target block
|
||||
+ */
|
||||
+ private @Nullable BlockPos target;
|
||||
+ /**
|
||||
+ * how far we are to the target
|
||||
+ *
|
||||
+ * <p>
|
||||
+ * while processing, the target could be anywhere but theoretically we're always "close" to a theoretical target so default is 0
|
||||
+ */
|
||||
+ private float distToTarget = 0;
|
||||
+ /**
|
||||
+ * whether we can reach the target
|
||||
+ *
|
||||
+ * <p>
|
||||
+ * while processing, we can always theoretically reach the target so default is true
|
||||
+ */
|
||||
+ private boolean canReach = true;
|
||||
@@ -1285,7 +1269,7 @@ index 0000000000000000000000000000000000000000..2ee7dca3d66e6bf2d4f72933b8a3dd9e
|
||||
+}
|
||||
diff --git a/src/main/java/org/dreeam/leaf/async/path/AsyncPathProcessor.java b/src/main/java/org/dreeam/leaf/async/path/AsyncPathProcessor.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..28632062a02960a2853b1dc1950689c1cd5a317f
|
||||
index 0000000000000000000000000000000000000000..5f3cc1ebc1c3d3293b04e763eff9540c716bc52e
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/org/dreeam/leaf/async/path/AsyncPathProcessor.java
|
||||
@@ -0,0 +1,52 @@
|
||||
@@ -1308,14 +1292,14 @@ index 0000000000000000000000000000000000000000..28632062a02960a2853b1dc1950689c1
|
||||
+public class AsyncPathProcessor {
|
||||
+
|
||||
+ private static final Executor pathProcessingExecutor = new ThreadPoolExecutor(
|
||||
+ 1,
|
||||
+ org.dreeam.leaf.LeafConfig.asyncPathfindingMaxThreads,
|
||||
+ 1,
|
||||
+ org.dreeam.leaf.LeafConfig.asyncPathfindingMaxThreads,
|
||||
+ org.dreeam.leaf.LeafConfig.asyncPathfindingKeepalive, TimeUnit.SECONDS,
|
||||
+ new LinkedBlockingQueue<>(),
|
||||
+ new ThreadFactoryBuilder()
|
||||
+ .setNameFormat("petal-async-path-thread-%d")
|
||||
+ .setPriority(Thread.NORM_PRIORITY - 2)
|
||||
+ .build()
|
||||
+ new LinkedBlockingQueue<>(),
|
||||
+ new ThreadFactoryBuilder()
|
||||
+ .setNameFormat("petal-async-path-thread-%d")
|
||||
+ .setPriority(Thread.NORM_PRIORITY - 2)
|
||||
+ .build()
|
||||
+ );
|
||||
+
|
||||
+ protected static CompletableFuture<Void> queue(@NotNull AsyncPath path) {
|
||||
@@ -1327,14 +1311,14 @@ index 0000000000000000000000000000000000000000..28632062a02960a2853b1dc1950689c1
|
||||
+ * the consumer will be immediately invoked if the path is already processed
|
||||
+ * the consumer will always be called on the main thread
|
||||
+ *
|
||||
+ * @param entity affected entity
|
||||
+ * @param path a path to wait on
|
||||
+ * @param entity affected entity
|
||||
+ * @param path a path to wait on
|
||||
+ * @param afterProcessing a consumer to be called
|
||||
+ */
|
||||
+ public static void awaitProcessing(Entity entity, @Nullable Path path, Consumer<@Nullable Path> afterProcessing) {
|
||||
+ if (path != null && !path.isProcessed() && path instanceof AsyncPath asyncPath) {
|
||||
+ asyncPath.postProcessing(() ->
|
||||
+ entity.getBukkitEntity().taskScheduler.schedule(nmsEntity -> afterProcessing.accept(path),null, 1)
|
||||
+ entity.getBukkitEntity().taskScheduler.schedule(nmsEntity -> afterProcessing.accept(path), null, 1)
|
||||
+ );
|
||||
+ } else {
|
||||
+ afterProcessing.accept(path);
|
||||
@@ -1421,10 +1405,10 @@ index 0000000000000000000000000000000000000000..9a9e69bc4bd807d62af0cebc05b3186d
|
||||
+}
|
||||
diff --git a/src/main/java/org/dreeam/leaf/async/path/NodeEvaluatorGenerator.java b/src/main/java/org/dreeam/leaf/async/path/NodeEvaluatorGenerator.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..bf7260f912b8cf3f77e12fc259080c56b9aa683d
|
||||
index 0000000000000000000000000000000000000000..062ddc246ed5f8f8f0599a8e86c9b85c4420daf7
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/org/dreeam/leaf/async/path/NodeEvaluatorGenerator.java
|
||||
@@ -0,0 +1,10 @@
|
||||
@@ -0,0 +1,11 @@
|
||||
+package org.dreeam.leaf.async.path;
|
||||
+
|
||||
+import net.minecraft.world.level.pathfinder.NodeEvaluator;
|
||||
@@ -1432,13 +1416,14 @@ index 0000000000000000000000000000000000000000..bf7260f912b8cf3f77e12fc259080c56
|
||||
+
|
||||
+public interface NodeEvaluatorGenerator {
|
||||
+
|
||||
+ @NotNull NodeEvaluator generate(NodeEvaluatorFeatures nodeEvaluatorFeatures);
|
||||
+ @NotNull
|
||||
+ NodeEvaluator generate(NodeEvaluatorFeatures nodeEvaluatorFeatures);
|
||||
+
|
||||
+}
|
||||
\ No newline at end of file
|
||||
diff --git a/src/main/java/org/dreeam/leaf/async/path/NodeEvaluatorType.java b/src/main/java/org/dreeam/leaf/async/path/NodeEvaluatorType.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..fb636eb2f665dd1c1dc78b980dfbccb8cf8eb81a
|
||||
index 0000000000000000000000000000000000000000..c0527323c42acf7e4728237e268f075e85d71a15
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/org/dreeam/leaf/async/path/NodeEvaluatorType.java
|
||||
@@ -0,0 +1,17 @@
|
||||
@@ -1454,7 +1439,7 @@ index 0000000000000000000000000000000000000000..fb636eb2f665dd1c1dc78b980dfbccb8
|
||||
+
|
||||
+ public static NodeEvaluatorType fromNodeEvaluator(NodeEvaluator nodeEvaluator) {
|
||||
+ if (nodeEvaluator instanceof SwimNodeEvaluator) return SWIM;
|
||||
+ if (nodeEvaluator instanceof FlyNodeEvaluator) return FLY;
|
||||
+ if (nodeEvaluator instanceof FlyNodeEvaluator) return FLY;
|
||||
+ if (nodeEvaluator instanceof AmphibiousNodeEvaluator) return AMPHIBIOUS;
|
||||
+ return WALK;
|
||||
+ }
|
||||
|
||||
@@ -275,38 +275,45 @@ index a3b9068efc38b3eb05e884bcc3fb13532e49308d..f016b5e323f8167d058f614800957216
|
||||
}
|
||||
|
||||
diff --git a/src/main/java/org/dreeam/leaf/LeafConfig.java b/src/main/java/org/dreeam/leaf/LeafConfig.java
|
||||
index 5a803587c147c75523fdbfbbe9f1908eaf7b8ed4..c15d539bc84e57c8ad6e4d4d27b6e43c559581e0 100644
|
||||
index abcf4fee07b6ea85de116252b823d30e57006654..af11b77112752a8bb64f6a5cac265a2d2eebf971 100644
|
||||
--- a/src/main/java/org/dreeam/leaf/LeafConfig.java
|
||||
+++ b/src/main/java/org/dreeam/leaf/LeafConfig.java
|
||||
@@ -206,6 +206,8 @@ public class LeafConfig {
|
||||
@@ -204,6 +204,9 @@ public class LeafConfig {
|
||||
public static boolean asyncPathfinding = false;
|
||||
public static int asyncPathfindingMaxThreads = 0;
|
||||
public static int asyncPathfindingKeepalive = 60;
|
||||
+ public static boolean enableAsyncEntityTracker = false;
|
||||
+ public static boolean enableAsyncEntityTrackerInitialized;
|
||||
+ public static boolean asyncEntityTracker = false;
|
||||
+ public static int asyncEntityTrackerMaxThreads = 0;
|
||||
+ public static int asyncEntityTrackerKeepalive = 60;
|
||||
private static void performance() {
|
||||
boolean asyncMobSpawning = getBoolean("performance.enable-async-mob-spawning", enableAsyncMobSpawning,
|
||||
"Whether or not asynchronous mob spawning should be enabled.",
|
||||
@@ -267,6 +269,13 @@ public class LeafConfig {
|
||||
@@ -265,6 +268,19 @@ public class LeafConfig {
|
||||
asyncPathfindingMaxThreads = 0;
|
||||
else
|
||||
Bukkit.getLogger().log(Level.INFO, "Using " + asyncPathfindingMaxThreads + " threads for Async Pathfinding");
|
||||
+ boolean asyncEntityTracker = getBoolean("performance.async-entity-tracker", enableAsyncEntityTracker,
|
||||
MinecraftServer.LOGGER.info("Using {} threads for Async Pathfinding", asyncPathfindingMaxThreads);
|
||||
+ asyncEntityTracker = getBoolean("performance.async-entity-tracker.enable", asyncEntityTracker,
|
||||
+ "Whether or not async entity tracking should be enabled.",
|
||||
+ "You may encounter issues with NPCs.");
|
||||
+ if (!enableAsyncEntityTrackerInitialized) {
|
||||
+ enableAsyncEntityTrackerInitialized = true;
|
||||
+ enableAsyncEntityTracker = asyncEntityTracker;
|
||||
+ }
|
||||
+ "You may encounter issues with NPCs");
|
||||
+ asyncEntityTrackerMaxThreads = getInt("performance.async-entity-tracker.max-threads", asyncEntityTrackerMaxThreads);
|
||||
+ asyncEntityTrackerKeepalive = getInt("performance.async-entity-tracker.keepalive", asyncEntityTrackerKeepalive);
|
||||
+ if (asyncEntityTrackerMaxThreads < 0)
|
||||
+ asyncEntityTrackerMaxThreads = Math.max(Runtime.getRuntime().availableProcessors() + asyncEntityTrackerMaxThreads, 1);
|
||||
+ else if (asyncEntityTrackerMaxThreads == 0)
|
||||
+ asyncEntityTrackerMaxThreads = Math.max(Runtime.getRuntime().availableProcessors() / 4, 1);
|
||||
+ if (!asyncEntityTracker)
|
||||
+ asyncEntityTrackerMaxThreads = 0;
|
||||
+ else
|
||||
+ MinecraftServer.LOGGER.info("Using {} threads for Async Entity Tracker", asyncEntityTrackerMaxThreads);
|
||||
}
|
||||
|
||||
public static boolean jadeProtocol = false;
|
||||
diff --git a/src/main/java/org/dreeam/leaf/async/tracker/MultithreadedTracker.java b/src/main/java/org/dreeam/leaf/async/tracker/MultithreadedTracker.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..b8e1240e8205672d85003919fdeed42716cf7d2b
|
||||
index 0000000000000000000000000000000000000000..9056ea6fc6745f1d83550a544c94c4bd68dc1d2d
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/org/dreeam/leaf/async/tracker/MultithreadedTracker.java
|
||||
@@ -0,0 +1,150 @@
|
||||
@@ -0,0 +1,157 @@
|
||||
+package org.dreeam.leaf.async.tracker;
|
||||
+
|
||||
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||
@@ -319,7 +326,9 @@ index 0000000000000000000000000000000000000000..b8e1240e8205672d85003919fdeed427
|
||||
+
|
||||
+import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
+import java.util.concurrent.Executor;
|
||||
+import java.util.concurrent.Executors;
|
||||
+import java.util.concurrent.LinkedBlockingQueue;
|
||||
+import java.util.concurrent.ThreadPoolExecutor;
|
||||
+import java.util.concurrent.TimeUnit;
|
||||
+import java.util.concurrent.atomic.AtomicInteger;
|
||||
+
|
||||
+public class MultithreadedTracker {
|
||||
@@ -330,10 +339,15 @@ index 0000000000000000000000000000000000000000..b8e1240e8205672d85003919fdeed427
|
||||
+ }
|
||||
+
|
||||
+ private static final int parallelism = Math.max(4, Runtime.getRuntime().availableProcessors());
|
||||
+ private static final Executor trackerExecutor = Executors.newFixedThreadPool(parallelism, new ThreadFactoryBuilder()
|
||||
+ .setNameFormat("petal-async-tracker-thread-%d")
|
||||
+ .setPriority(Thread.NORM_PRIORITY - 2)
|
||||
+ .build());
|
||||
+ private static final Executor trackerExecutor = new ThreadPoolExecutor(
|
||||
+ 1,
|
||||
+ org.dreeam.leaf.LeafConfig.asyncPathfindingMaxThreads,
|
||||
+ org.dreeam.leaf.LeafConfig.asyncPathfindingKeepalive, TimeUnit.SECONDS,
|
||||
+ new LinkedBlockingQueue<>(),
|
||||
+ new ThreadFactoryBuilder()
|
||||
+ .setNameFormat("petal-async-tracker-thread-%d")
|
||||
+ .setPriority(Thread.NORM_PRIORITY - 2)
|
||||
+ .build());
|
||||
+
|
||||
+ private final IteratorSafeOrderedReferenceSet<LevelChunk> entityTickingChunks;
|
||||
+ private final AtomicInteger taskIndex = new AtomicInteger();
|
||||
|
||||
@@ -80,21 +80,21 @@ index eb5bd5cfd131042e366872bf599a315d83dc732b..ce07e75c4faf30520c74016c4ff31be1
|
||||
this.updateInWaterStateAndDoFluidPushing();
|
||||
if (this.isInLava()) {
|
||||
diff --git a/src/main/java/org/dreeam/leaf/LeafConfig.java b/src/main/java/org/dreeam/leaf/LeafConfig.java
|
||||
index c15d539bc84e57c8ad6e4d4d27b6e43c559581e0..78652c7dffffd0f0249a944f96ae90e82cfde282 100644
|
||||
index af11b77112752a8bb64f6a5cac265a2d2eebf971..c73a2f9c3286ecdf57d6cab5c130f69540741a56 100644
|
||||
--- a/src/main/java/org/dreeam/leaf/LeafConfig.java
|
||||
+++ b/src/main/java/org/dreeam/leaf/LeafConfig.java
|
||||
@@ -208,6 +208,7 @@ public class LeafConfig {
|
||||
public static int asyncPathfindingKeepalive = 60;
|
||||
public static boolean enableAsyncEntityTracker = false;
|
||||
public static boolean enableAsyncEntityTrackerInitialized;
|
||||
@@ -207,6 +207,7 @@ public class LeafConfig {
|
||||
public static boolean asyncEntityTracker = false;
|
||||
public static int asyncEntityTrackerMaxThreads = 0;
|
||||
public static int asyncEntityTrackerKeepalive = 60;
|
||||
+ public static boolean cacheMinecartCollision = false;
|
||||
private static void performance() {
|
||||
boolean asyncMobSpawning = getBoolean("performance.enable-async-mob-spawning", enableAsyncMobSpawning,
|
||||
"Whether or not asynchronous mob spawning should be enabled.",
|
||||
@@ -276,6 +277,8 @@ public class LeafConfig {
|
||||
enableAsyncEntityTrackerInitialized = true;
|
||||
enableAsyncEntityTracker = asyncEntityTracker;
|
||||
}
|
||||
@@ -281,6 +282,8 @@ public class LeafConfig {
|
||||
asyncEntityTrackerMaxThreads = 0;
|
||||
else
|
||||
MinecraftServer.LOGGER.info("Using {} threads for Async Entity Tracker", asyncEntityTrackerMaxThreads);
|
||||
+ cacheMinecartCollision = getBoolean("performance.cache-minecart-collision", cacheMinecartCollision,
|
||||
+ "Cache the minecart collision result to prevent massive stacked minecart lag the server.");
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ Subject: [PATCH] Faster Random for xaeroMapServerID generation
|
||||
|
||||
|
||||
diff --git a/src/main/java/org/dreeam/leaf/LeafConfig.java b/src/main/java/org/dreeam/leaf/LeafConfig.java
|
||||
index 78652c7dffffd0f0249a944f96ae90e82cfde282..faf4656ce94a3c7a418ac21dae6c805144ae39bd 100644
|
||||
index c73a2f9c3286ecdf57d6cab5c130f69540741a56..2b9e07b9e6e4f4d4e8b3e52192a983c2ad59abbf 100644
|
||||
--- a/src/main/java/org/dreeam/leaf/LeafConfig.java
|
||||
+++ b/src/main/java/org/dreeam/leaf/LeafConfig.java
|
||||
@@ -2,7 +2,7 @@ package org.dreeam.leaf;
|
||||
@@ -16,8 +16,8 @@ index 78652c7dffffd0f0249a944f96ae90e82cfde282..faf4656ce94a3c7a418ac21dae6c8051
|
||||
+import java.util.concurrent.ThreadLocalRandom;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -284,7 +284,7 @@ public class LeafConfig {
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
@@ -289,7 +289,7 @@ public class LeafConfig {
|
||||
public static boolean jadeProtocol = false;
|
||||
public static boolean appleskinProtocol = false;
|
||||
public static boolean xaeroMapProtocol = false;
|
||||
|
||||
@@ -24,19 +24,19 @@ index 8d3c1897044f9a2bbe1911e1a72dc9a00fb246df..03112a42d1cf3460af5d5ce9d1fdd038
|
||||
}
|
||||
|
||||
diff --git a/src/main/java/org/dreeam/leaf/LeafConfig.java b/src/main/java/org/dreeam/leaf/LeafConfig.java
|
||||
index faf4656ce94a3c7a418ac21dae6c805144ae39bd..2056a6ea44b59874d9876bd80506cf849b3de0b8 100644
|
||||
index 2b9e07b9e6e4f4d4e8b3e52192a983c2ad59abbf..de09de91f4d5cb4fd16aeade1c4597226e4395a6 100644
|
||||
--- a/src/main/java/org/dreeam/leaf/LeafConfig.java
|
||||
+++ b/src/main/java/org/dreeam/leaf/LeafConfig.java
|
||||
@@ -209,6 +209,7 @@ public class LeafConfig {
|
||||
public static boolean enableAsyncEntityTracker = false;
|
||||
public static boolean enableAsyncEntityTrackerInitialized;
|
||||
@@ -208,6 +208,7 @@ public class LeafConfig {
|
||||
public static int asyncEntityTrackerMaxThreads = 0;
|
||||
public static int asyncEntityTrackerKeepalive = 60;
|
||||
public static boolean cacheMinecartCollision = false;
|
||||
+ public static boolean skipMapItemDataUpdatesIfMapDoesNotHaveCraftMapRenderer = true;
|
||||
private static void performance() {
|
||||
boolean asyncMobSpawning = getBoolean("performance.enable-async-mob-spawning", enableAsyncMobSpawning,
|
||||
"Whether or not asynchronous mob spawning should be enabled.",
|
||||
@@ -279,6 +280,7 @@ public class LeafConfig {
|
||||
}
|
||||
@@ -284,6 +285,7 @@ public class LeafConfig {
|
||||
MinecraftServer.LOGGER.info("Using {} threads for Async Entity Tracker", asyncEntityTrackerMaxThreads);
|
||||
cacheMinecartCollision = getBoolean("performance.cache-minecart-collision", cacheMinecartCollision,
|
||||
"Cache the minecart collision result to prevent massive stacked minecart lag the server.");
|
||||
+ skipMapItemDataUpdatesIfMapDoesNotHaveCraftMapRenderer = getBoolean("performance.skip-map-item-data-updates-if-map-does-not-have-craftmaprenderer", skipMapItemDataUpdatesIfMapDoesNotHaveCraftMapRenderer);
|
||||
|
||||
@@ -50,10 +50,10 @@ index 785196e6f4677074890ca965e9add85ccfd0e6e3..4278daf75682875649ce3311405a2bc3
|
||||
|
||||
@Override
|
||||
diff --git a/src/main/java/org/dreeam/leaf/LeafConfig.java b/src/main/java/org/dreeam/leaf/LeafConfig.java
|
||||
index 2056a6ea44b59874d9876bd80506cf849b3de0b8..402c43b6b09716713d2522ce4a10356eca74533f 100644
|
||||
index de09de91f4d5cb4fd16aeade1c4597226e4395a6..94a949eb530588cdeaef31a209d3463609f88555 100644
|
||||
--- a/src/main/java/org/dreeam/leaf/LeafConfig.java
|
||||
+++ b/src/main/java/org/dreeam/leaf/LeafConfig.java
|
||||
@@ -317,4 +317,11 @@ public class LeafConfig {
|
||||
@@ -322,4 +322,11 @@ public class LeafConfig {
|
||||
private static void vanillaEndTeleport() {
|
||||
useVanillaEndTeleport = getBoolean("use-vanilla-end-teleport", useVanillaEndTeleport, "Vanilla End Gateway Teleport");
|
||||
}
|
||||
|
||||
@@ -40,10 +40,10 @@ index 7f2dcf6a9e69779e6f898284b58fb1e32902000c..d7a36437fa95345bef958cb8c6112fc5
|
||||
if (flag1) {
|
||||
TripWireHookBlock.notifyNeighbors(block, world, pos, enumdirection);
|
||||
diff --git a/src/main/java/org/dreeam/leaf/LeafConfig.java b/src/main/java/org/dreeam/leaf/LeafConfig.java
|
||||
index 402c43b6b09716713d2522ce4a10356eca74533f..ecea9b6cd3b063d3edd6944008819b006faf8df9 100644
|
||||
index 94a949eb530588cdeaef31a209d3463609f88555..5e362d086d64ec19dd9bffd680cc82d20164c570 100644
|
||||
--- a/src/main/java/org/dreeam/leaf/LeafConfig.java
|
||||
+++ b/src/main/java/org/dreeam/leaf/LeafConfig.java
|
||||
@@ -324,4 +324,9 @@ public class LeafConfig {
|
||||
@@ -329,4 +329,9 @@ public class LeafConfig {
|
||||
snowballCanKnockback = getBoolean("playerKnockback.snowball-knockback-players", snowballCanKnockback, "Make snowball can knockback players");
|
||||
eggCanKnockback = getBoolean("playerKnockback.egg-knockback-players", eggCanKnockback, "Make egg can knockback players");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user