9
0
mirror of https://github.com/BX-Team/DivineMC.git synced 2025-12-22 08:19:19 +00:00

configurable Chunk Task Priority

This commit is contained in:
NONPLAYT
2025-03-13 22:12:45 +03:00
parent ae71aa19ae
commit 127828d16a
4 changed files with 39 additions and 15 deletions

View File

@@ -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 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 --- a/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java
+++ b/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 { @@ -301,7 +301,7 @@ public final class RegionizedPlayerChunkLoader {
@@ -26,7 +26,7 @@ index f81cc357618c70f2fcf0bc24b0b25be566ffffcc..a2062d976ca45b1360476051f23ff126
{ {
this.chunkTicketStage.defaultReturnValue(CHUNK_TICKET_STAGE_NONE); this.chunkTicketStage.defaultReturnValue(CHUNK_TICKET_STAGE_NONE);
} }
@@ -492,7 +492,7 @@ public final class RegionizedPlayerChunkLoader { @@ -499,7 +499,7 @@ public final class RegionizedPlayerChunkLoader {
} }
@Override @Override
@@ -35,7 +35,7 @@ index f81cc357618c70f2fcf0bc24b0b25be566ffffcc..a2062d976ca45b1360476051f23ff126
final long chunk = CoordinateUtils.getChunkKey(chunkX, chunkZ); 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 // 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 // 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; 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 dz = -radius; dz <= radius; ++dz) {
for (int dx = -radius; dx <= radius; ++dx) { for (int dx = -radius; dx <= radius; ++dx) {
if ((dx | dz) == 0) { if ((dx | dz) == 0) {
@@ -645,19 +645,11 @@ public final class RegionizedPlayerChunkLoader { @@ -652,19 +652,11 @@ public final class RegionizedPlayerChunkLoader {
return true; return true;
} }
@@ -65,7 +65,7 @@ index f81cc357618c70f2fcf0bc24b0b25be566ffffcc..a2062d976ca45b1360476051f23ff126
// try to progress chunk loads // try to progress chunk loads
while (!this.loadingQueue.isEmpty()) { 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 // try to push more chunk loads
@@ -75,7 +75,7 @@ index f81cc357618c70f2fcf0bc24b0b25be566ffffcc..a2062d976ca45b1360476051f23ff126
if (maxLoadsThisTick > 0) { if (maxLoadsThisTick > 0) {
final LongArrayList chunks = new LongArrayList(maxLoadsThisTick); final LongArrayList chunks = new LongArrayList(maxLoadsThisTick);
for (int i = 0; i < maxLoadsThisTick; ++i) { 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 // try to push more chunk generations
@@ -86,7 +86,7 @@ index f81cc357618c70f2fcf0bc24b0b25be566ffffcc..a2062d976ca45b1360476051f23ff126
long ratedGensThisTick = 0L; long ratedGensThisTick = 0L;
while (!this.genQueue.isEmpty()) { while (!this.genQueue.isEmpty()) {
final long chunkKey = this.genQueue.firstLong(); 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); this.generatingQueue.enqueue(chunkKey);
} }
@@ -95,7 +95,7 @@ index f81cc357618c70f2fcf0bc24b0b25be566ffffcc..a2062d976ca45b1360476051f23ff126
// try to pull ticking chunks // try to pull ticking chunks
while (!this.tickingQueue.isEmpty()) { 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 // try to pull sending chunks

View File

@@ -1,15 +1,26 @@
--- a/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java --- a/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java
+++ b/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; final int centerZ = PlayerChunkLoaderData.this.lastChunkZ;
return Integer.compare( - return Integer.compare(
- Math.abs(c1x - centerX) + Math.abs(c1z - centerZ), - Math.abs(c1x - centerX) + Math.abs(c1z - centerZ),
- Math.abs(c2x - centerX) + Math.abs(c2z - centerZ) - Math.abs(c2x - centerX) + Math.abs(c2z - centerZ)
+ // DivineMC start - Chunk Loading Priority Optimization - );
+ (c1x - centerX) * (c1x - centerX) + (c1z - centerZ) * (c1z - centerZ), + // DivineMC start - Chunk Loading Priority Optimization
+ (c2x - centerX) * (c2x - centerX) + (c2z - centerZ) * (c2z - centerZ) + if (org.bxteam.divinemc.DivineConfig.chunkTaskPriority == org.bxteam.divinemc.server.chunk.ChunkTaskPriority.EUCLIDEAN_CIRCLE_PATTERN) {
+ // DivineMC end - Chunk Loading Priority Optimization + 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 sendQueue = new LongHeapPriorityQueue(CLOSEST_MANHATTAN_DIST);
private final LongHeapPriorityQueue tickingQueue = new LongHeapPriorityQueue(CLOSEST_MANHATTAN_DIST);

View File

@@ -7,6 +7,7 @@ import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.MemoryConfiguration; import org.bukkit.configuration.MemoryConfiguration;
import org.bxteam.divinemc.entity.pathfinding.PathfindTaskRejectPolicy; import org.bxteam.divinemc.entity.pathfinding.PathfindTaskRejectPolicy;
import org.bxteam.divinemc.server.chunk.ChunkSystemAlgorithms; import org.bxteam.divinemc.server.chunk.ChunkSystemAlgorithms;
import org.bxteam.divinemc.server.chunk.ChunkTaskPriority;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.simpleyaml.configuration.comments.CommentType; import org.simpleyaml.configuration.comments.CommentType;
import org.simpleyaml.configuration.file.YamlFile; import org.simpleyaml.configuration.file.YamlFile;
@@ -174,6 +175,7 @@ public class DivineConfig {
public static long chunkDataCacheLimit = 32678L; public static long chunkDataCacheLimit = 32678L;
public static int maxViewDistance = 32; public static int maxViewDistance = 32;
public static ChunkSystemAlgorithms chunkWorkerAlgorithm = ChunkSystemAlgorithms.C2ME; public static ChunkSystemAlgorithms chunkWorkerAlgorithm = ChunkSystemAlgorithms.C2ME;
public static ChunkTaskPriority chunkTaskPriority = ChunkTaskPriority.EUCLIDEAN_CIRCLE_PATTERN;
public static int threadPoolPriority = Thread.NORM_PRIORITY + 1; public static int threadPoolPriority = Thread.NORM_PRIORITY + 1;
public static boolean enableAsyncNoiseFill = false; public static boolean enableAsyncNoiseFill = false;
public static boolean enableSecureSeed = false; public static boolean enableSecureSeed = false;
@@ -207,6 +209,11 @@ public class DivineConfig {
" - MOONRISE: Default algorithm, used by default in Paper", " - MOONRISE: Default algorithm, used by default in Paper",
" - C2ME: Algorithm used by C2ME (old)", " - C2ME: Algorithm used by C2ME (old)",
" - C2ME_NEW: Modern algorithm used by C2ME")); " - 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, threadPoolPriority = getInt("settings.chunk-generation.thread-pool-priority", threadPoolPriority,
"Sets the priority of the thread pool used for chunk generation"); "Sets the priority of the thread pool used for chunk generation");
enableAsyncNoiseFill = getBoolean("settings.chunk-generation.enable-async-noise-fill", enableAsyncNoiseFill, enableAsyncNoiseFill = getBoolean("settings.chunk-generation.enable-async-noise-fill", enableAsyncNoiseFill,

View File

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