aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/removed/1.19.2-legacy-chunksystem/0014-ChunkMapDistance-CME.patch
blob: 956878857c86b5e67e91a80480b0cb96c5ecf466 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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
index 0873134f1f6de0c372ba28b89a20302c9a0115d8..e30893d6cbe3b42338d04453d0f452babeb61d8a 100644
--- a/src/main/java/net/minecraft/server/level/ChunkHolder.java
+++ b/src/main/java/net/minecraft/server/level/ChunkHolder.java
@@ -73,6 +73,7 @@ public class ChunkHolder {
     private boolean resendLight;
     private CompletableFuture<Void> pendingFullStateConfirmation;
 
+    boolean isUpdateQueued = false; // Paper
     private final ChunkMap chunkMap; // Paper
 
     // Paper start
diff --git a/src/main/java/net/minecraft/server/level/DistanceManager.java b/src/main/java/net/minecraft/server/level/DistanceManager.java
index f08089b8672454acf8c2309e850466b335248692..6181f675d7addde30f7018b4cd46fe061a14da51 100644
--- a/src/main/java/net/minecraft/server/level/DistanceManager.java
+++ b/src/main/java/net/minecraft/server/level/DistanceManager.java
@@ -52,7 +52,16 @@ public abstract class DistanceManager {
     private final DistanceManager.FixedPlayerDistanceChunkTracker naturalSpawnChunkCounter = new DistanceManager.FixedPlayerDistanceChunkTracker(8);
     private final TickingTracker tickingTicketsTracker = new TickingTracker();
     private final DistanceManager.PlayerTicketTracker playerTicketManager = new DistanceManager.PlayerTicketTracker(33);
-    final Set<ChunkHolder> chunksToUpdateFutures = Sets.newHashSet();
+    // 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
     final ChunkTaskPriorityQueueSorter ticketThrottler;
     final ProcessorHandle<ChunkTaskPriorityQueueSorter.Message<Runnable>> ticketThrottlerInput;
     final ProcessorHandle<ChunkTaskPriorityQueueSorter.Release> ticketThrottlerReleaser;
@@ -127,26 +136,14 @@ public abstract class DistanceManager {
             ;
         }
 
-        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--;
-
-                playerchunk.updateFutures(chunkStorage, this.mainThreadExecutor);
-
-                // 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;
+                remove.updateFutures(chunkStorage, this.mainThreadExecutor);
+            }
+            // Paper end
             return true;
         } else {
             if (!this.ticketsToRelease.isEmpty()) {
@@ -471,7 +468,7 @@ public abstract class DistanceManager {
             if (k != level) {
                 playerchunk = DistanceManager.this.updateChunkScheduling(id, level, playerchunk, k);
                 if (playerchunk != null) {
-                    DistanceManager.this.chunksToUpdateFutures.add(playerchunk);
+                    DistanceManager.this.pendingChunkUpdates.add(playerchunk);
                 }
 
             }