diff --git a/divinemc-server/minecraft-patches/features/0012-Chunk-System-optimization.patch b/divinemc-server/minecraft-patches/features/0012-Chunk-System-optimization.patch index 4d5643d..07bd87a 100644 --- a/divinemc-server/minecraft-patches/features/0012-Chunk-System-optimization.patch +++ b/divinemc-server/minecraft-patches/features/0012-Chunk-System-optimization.patch @@ -5,7 +5,7 @@ Subject: [PATCH] Chunk System optimization diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java b/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java -index f81cc357618c70f2fcf0bc24b0b25be566ffffcc..a2062d976ca45b1360476051f23ff126ff812d4e 100644 +index b28083be4384d6c5efbdce898a0e9d7a2f5bd3d3..b3d6b53bd43045a2dd709567e35ae6f60352f1ea 100644 --- a/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java +++ b/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java @@ -301,7 +301,7 @@ public final class RegionizedPlayerChunkLoader { @@ -26,7 +26,7 @@ index f81cc357618c70f2fcf0bc24b0b25be566ffffcc..a2062d976ca45b1360476051f23ff126 { this.chunkTicketStage.defaultReturnValue(CHUNK_TICKET_STAGE_NONE); } -@@ -492,7 +492,7 @@ public final class RegionizedPlayerChunkLoader { +@@ -499,7 +499,7 @@ public final class RegionizedPlayerChunkLoader { } @Override @@ -35,7 +35,7 @@ index f81cc357618c70f2fcf0bc24b0b25be566ffffcc..a2062d976ca45b1360476051f23ff126 final long chunk = CoordinateUtils.getChunkKey(chunkX, chunkZ); // note: by the time this is called, the tick cleanup should have ran - so, if the chunk is at // the tick stage it was deemed in range for loading. Thus, we need to move it to generated -@@ -626,7 +626,7 @@ public final class RegionizedPlayerChunkLoader { +@@ -633,7 +633,7 @@ public final class RegionizedPlayerChunkLoader { return Math.max(Math.abs(dx), Math.abs(dz)) <= this.lastTickDistance; } @@ -44,7 +44,7 @@ index f81cc357618c70f2fcf0bc24b0b25be566ffffcc..a2062d976ca45b1360476051f23ff126 for (int dz = -radius; dz <= radius; ++dz) { for (int dx = -radius; dx <= radius; ++dx) { if ((dx | dz) == 0) { -@@ -645,19 +645,11 @@ public final class RegionizedPlayerChunkLoader { +@@ -652,19 +652,11 @@ public final class RegionizedPlayerChunkLoader { return true; } @@ -65,7 +65,7 @@ index f81cc357618c70f2fcf0bc24b0b25be566ffffcc..a2062d976ca45b1360476051f23ff126 // try to progress chunk loads while (!this.loadingQueue.isEmpty()) { -@@ -684,8 +676,7 @@ public final class RegionizedPlayerChunkLoader { +@@ -691,8 +683,7 @@ public final class RegionizedPlayerChunkLoader { } // try to push more chunk loads @@ -75,7 +75,7 @@ index f81cc357618c70f2fcf0bc24b0b25be566ffffcc..a2062d976ca45b1360476051f23ff126 if (maxLoadsThisTick > 0) { final LongArrayList chunks = new LongArrayList(maxLoadsThisTick); for (int i = 0; i < maxLoadsThisTick; ++i) { -@@ -760,9 +751,7 @@ public final class RegionizedPlayerChunkLoader { +@@ -767,9 +758,7 @@ public final class RegionizedPlayerChunkLoader { } // try to push more chunk generations @@ -86,7 +86,7 @@ index f81cc357618c70f2fcf0bc24b0b25be566ffffcc..a2062d976ca45b1360476051f23ff126 long ratedGensThisTick = 0L; while (!this.genQueue.isEmpty()) { final long chunkKey = this.genQueue.firstLong(); -@@ -792,8 +781,6 @@ public final class RegionizedPlayerChunkLoader { +@@ -799,8 +788,6 @@ public final class RegionizedPlayerChunkLoader { ); this.generatingQueue.enqueue(chunkKey); } @@ -95,7 +95,7 @@ index f81cc357618c70f2fcf0bc24b0b25be566ffffcc..a2062d976ca45b1360476051f23ff126 // try to pull ticking chunks while (!this.tickingQueue.isEmpty()) { -@@ -823,10 +810,10 @@ public final class RegionizedPlayerChunkLoader { +@@ -830,10 +817,10 @@ public final class RegionizedPlayerChunkLoader { } // try to pull sending chunks diff --git a/divinemc-server/minecraft-patches/sources/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java.patch b/divinemc-server/minecraft-patches/sources/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java.patch index c7d5458..d9d3b97 100644 --- a/divinemc-server/minecraft-patches/sources/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java.patch +++ b/divinemc-server/minecraft-patches/sources/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java.patch @@ -1,15 +1,26 @@ --- a/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java +++ b/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java -@@ -381,8 +_,10 @@ +@@ -380,10 +_,19 @@ + final int centerX = PlayerChunkLoaderData.this.lastChunkX; final int centerZ = PlayerChunkLoaderData.this.lastChunkZ; - return Integer.compare( +- return Integer.compare( - Math.abs(c1x - centerX) + Math.abs(c1z - centerZ), - Math.abs(c2x - centerX) + Math.abs(c2z - centerZ) -+ // DivineMC start - Chunk Loading Priority Optimization -+ (c1x - centerX) * (c1x - centerX) + (c1z - centerZ) * (c1z - centerZ), -+ (c2x - centerX) * (c2x - centerX) + (c2z - centerZ) * (c2z - centerZ) -+ // DivineMC end - Chunk Loading Priority Optimization - ); +- ); ++ // DivineMC start - Chunk Loading Priority Optimization ++ if (org.bxteam.divinemc.DivineConfig.chunkTaskPriority == org.bxteam.divinemc.server.chunk.ChunkTaskPriority.EUCLIDEAN_CIRCLE_PATTERN) { ++ return Integer.compare( ++ (c1x - centerX) * (c1x - centerX) + (c1z - centerZ) * (c1z - centerZ), ++ (c2x - centerX) * (c2x - centerX) + (c2z - centerZ) * (c2z - centerZ) ++ ); ++ } else { ++ return Integer.compare( ++ Math.abs(c1x - centerX) + Math.abs(c1z - centerZ), ++ Math.abs(c2x - centerX) + Math.abs(c2z - centerZ) ++ ); ++ } ++ // DivineMC end - Chunk Loading Priority Optimization }; private final LongHeapPriorityQueue sendQueue = new LongHeapPriorityQueue(CLOSEST_MANHATTAN_DIST); + private final LongHeapPriorityQueue tickingQueue = new LongHeapPriorityQueue(CLOSEST_MANHATTAN_DIST); diff --git a/divinemc-server/src/main/java/org/bxteam/divinemc/DivineConfig.java b/divinemc-server/src/main/java/org/bxteam/divinemc/DivineConfig.java index c49963a..32a14aa 100644 --- a/divinemc-server/src/main/java/org/bxteam/divinemc/DivineConfig.java +++ b/divinemc-server/src/main/java/org/bxteam/divinemc/DivineConfig.java @@ -7,6 +7,7 @@ import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.MemoryConfiguration; import org.bxteam.divinemc.entity.pathfinding.PathfindTaskRejectPolicy; 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; @@ -174,6 +175,7 @@ public class DivineConfig { public static long chunkDataCacheLimit = 32678L; public static int maxViewDistance = 32; 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 enableAsyncNoiseFill = false; public static boolean enableSecureSeed = false; @@ -207,6 +209,11 @@ public class DivineConfig { " - 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("settings.chunk-generation.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("settings.chunk-generation.thread-pool-priority", threadPoolPriority, "Sets the priority of the thread pool used for chunk generation"); enableAsyncNoiseFill = getBoolean("settings.chunk-generation.enable-async-noise-fill", enableAsyncNoiseFill, diff --git a/divinemc-server/src/main/java/org/bxteam/divinemc/server/chunk/ChunkTaskPriority.java b/divinemc-server/src/main/java/org/bxteam/divinemc/server/chunk/ChunkTaskPriority.java new file mode 100644 index 0000000..3b3df3b --- /dev/null +++ b/divinemc-server/src/main/java/org/bxteam/divinemc/server/chunk/ChunkTaskPriority.java @@ -0,0 +1,6 @@ +package org.bxteam.divinemc.server.chunk; + +public enum ChunkTaskPriority { + EUCLIDEAN_CIRCLE_PATTERN, + DEFAULT_DIAMOND_PATTERN, +}