PaperMC/patches/server/0330-ChunkMapDistance-CME.patch

85 lines
4.4 KiB
Diff
Raw Normal View History

2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Shane Freeder <theboyetronic@gmail.com>
Date: Wed, 29 May 2019 04:01:22 +0100
Subject: [PATCH] ChunkMapDistance CME
diff --git a/src/main/java/net/minecraft/server/level/ChunkHolder.java b/src/main/java/net/minecraft/server/level/ChunkHolder.java
2021-11-24 05:25:34 +01:00
index 5b999da8c5ad430f9157276857165596d1208f64..26a787864058dccc0365680b0259ddf0dad22b58 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/server/level/ChunkHolder.java
+++ b/src/main/java/net/minecraft/server/level/ChunkHolder.java
2021-11-24 05:25:34 +01:00
@@ -70,6 +70,7 @@ public class ChunkHolder {
2021-06-13 14:43:56 +02:00
private boolean resendLight;
private CompletableFuture<Void> pendingFullStateConfirmation;
2021-06-11 14:02:28 +02:00
+ boolean isUpdateQueued = false; // Paper
2021-06-13 14:43:56 +02:00
private final ChunkMap chunkMap; // Paper
public ChunkHolder(ChunkPos pos, int level, LevelHeightAccessor world, LevelLightEngine lightingProvider, ChunkHolder.LevelChangeListener levelUpdateListener, ChunkHolder.PlayerProvider playersWatchingChunkProvider) {
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/server/level/DistanceManager.java b/src/main/java/net/minecraft/server/level/DistanceManager.java
2021-11-24 05:25:34 +01:00
index ef87c37633cee4ab438f1991144188ade1c4e65f..975f1aab48f04a9f3cae04141b3fb65247f0ffaf 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/server/level/DistanceManager.java
+++ b/src/main/java/net/minecraft/server/level/DistanceManager.java
2021-11-24 05:25:34 +01:00
@@ -51,7 +51,16 @@ public abstract class DistanceManager {
2021-06-11 14:02:28 +02:00
private final DistanceManager.FixedPlayerDistanceChunkTracker naturalSpawnChunkCounter = new DistanceManager.FixedPlayerDistanceChunkTracker(8);
2021-11-24 05:25:34 +01:00
private final TickingTracker tickingTicketsTracker = new TickingTracker();
2021-06-11 14:02:28 +02:00
private final DistanceManager.PlayerTicketTracker playerTicketManager = new DistanceManager.PlayerTicketTracker(33);
2021-06-13 14:43:56 +02:00
- final Set<ChunkHolder> chunksToUpdateFutures = Sets.newHashSet();
2021-06-11 14:02:28 +02:00
+ // Paper start use a queue, but still keep unique requirement
+ public final java.util.Queue<ChunkHolder> pendingChunkUpdates = new java.util.ArrayDeque<ChunkHolder>() {
+ @Override
+ public boolean add(ChunkHolder o) {
+ if (o.isUpdateQueued) return true;
+ o.isUpdateQueued = true;
+ return super.add(o);
+ }
+ };
+ // Paper end
2021-06-13 14:43:56 +02:00
final ChunkTaskPriorityQueueSorter ticketThrottler;
final ProcessorHandle<ChunkTaskPriorityQueueSorter.Message<Runnable>> ticketThrottlerInput;
final ProcessorHandle<ChunkTaskPriorityQueueSorter.Release> ticketThrottlerReleaser;
2021-11-24 05:25:34 +01:00
@@ -124,26 +133,14 @@ public abstract class DistanceManager {
2021-06-11 14:02:28 +02:00
;
}
- if (!this.chunksToUpdateFutures.isEmpty()) {
- // CraftBukkit start
- // Iterate pending chunk updates with protection against concurrent modification exceptions
- java.util.Iterator<ChunkHolder> iter = this.chunksToUpdateFutures.iterator();
- int expectedSize = this.chunksToUpdateFutures.size();
- do {
- ChunkHolder playerchunk = iter.next();
- iter.remove();
- expectedSize--;
-
2021-11-24 05:25:34 +01:00
- playerchunk.updateFutures(chunkStorage, this.mainThreadExecutor);
2021-06-11 14:02:28 +02:00
-
- // Reset iterator if set was modified using add()
- if (this.chunksToUpdateFutures.size() != expectedSize) {
- expectedSize = this.chunksToUpdateFutures.size();
- iter = this.chunksToUpdateFutures.iterator();
- }
- } while (iter.hasNext());
- // CraftBukkit end
-
+ // Paper start
+ if (!this.pendingChunkUpdates.isEmpty()) {
+ while(!this.pendingChunkUpdates.isEmpty()) {
+ ChunkHolder remove = this.pendingChunkUpdates.remove();
+ remove.isUpdateQueued = false;
2021-11-24 05:25:34 +01:00
+ remove.updateFutures(chunkStorage, this.mainThreadExecutor);
2021-06-11 14:02:28 +02:00
+ }
+ // Paper end
return true;
} else {
if (!this.ticketsToRelease.isEmpty()) {
2021-11-24 05:25:34 +01:00
@@ -432,7 +429,7 @@ public abstract class DistanceManager {
2021-06-11 14:02:28 +02:00
if (k != level) {
playerchunk = DistanceManager.this.updateChunkScheduling(id, level, playerchunk, k);
if (playerchunk != null) {
- DistanceManager.this.chunksToUpdateFutures.add(playerchunk);
+ DistanceManager.this.pendingChunkUpdates.add(playerchunk);
}
}