|
18 | 18 | long currTime = System.nanoTime(); |
19 | 19 | for (final ServerPlayer player : new java.util.ArrayList<>(this.world.players())) { |
20 | 20 | final PlayerChunkLoaderData loader = ((ChunkSystemServerPlayer)player).moonrise$getChunkLoader(); |
21 | | -@@ -387,6 +_,7 @@ |
22 | | - Math.abs(c2x - centerX) + Math.abs(c2z - centerZ) |
| 21 | +@@ -405,13 +_,13 @@ |
| 22 | + (diff2X * diff2X) + (diff2Z * diff2Z) |
23 | 23 | ); |
24 | 24 | }; |
25 | 25 | + private final LongArrayList retryLaterSendQueue = new LongArrayList(); // ShreddedPaper |
26 | | - private final LongHeapPriorityQueue sendQueue = new LongHeapPriorityQueue(CLOSEST_MANHATTAN_DIST); |
27 | | - private final LongHeapPriorityQueue tickingQueue = new LongHeapPriorityQueue(CLOSEST_MANHATTAN_DIST); |
28 | | - private final LongHeapPriorityQueue generatingQueue = new LongHeapPriorityQueue(CLOSEST_MANHATTAN_DIST); |
29 | | -@@ -641,7 +_,7 @@ |
| 26 | + private final LongHeapPriorityQueue sendQueue = new LongHeapPriorityQueue(this.queueComparator); |
| 27 | + private final LongHeapPriorityQueue tickingQueue = new LongHeapPriorityQueue(this.queueComparator); |
| 28 | + private final LongHeapPriorityQueue generatingQueue = new LongHeapPriorityQueue(this.queueComparator); |
| 29 | + private final LongHeapPriorityQueue genQueue = new LongHeapPriorityQueue(this.queueComparator); |
| 30 | + private final LongHeapPriorityQueue loadingQueue = new LongHeapPriorityQueue(this.queueComparator); |
| 31 | + private final LongHeapPriorityQueue loadQueue = new LongHeapPriorityQueue(this.queueComparator); |
| 32 | +- |
| 33 | + private volatile boolean removed; |
| 34 | + |
| 35 | + public PlayerChunkLoaderData(final ServerLevel world, final ServerPlayer player) { |
| 36 | +@@ -659,7 +_,7 @@ |
30 | 37 | return true; |
31 | 38 | } |
32 | 39 |
|
|
35 | 42 | TickThread.ensureTickThread(this.player, "Cannot tick player chunk loader async"); |
36 | 43 | if (this.removed) { |
37 | 44 | throw new IllegalStateException("Ticking removed player chunk loader"); |
38 | | -@@ -821,17 +_,31 @@ |
39 | | - final long maxSends = Math.max(0L, Math.min(MAX_RATE, Integer.MAX_VALUE)); // note: no logic to track concurrent sends |
40 | | - final int maxSendsThisTick = Math.min((int)this.chunkSendLimiter.takeAllocation(time, sendRate, maxSends), this.sendQueue.size()); |
| 45 | +@@ -838,17 +_,31 @@ |
| 46 | + final long maxSends = Math.max(0L, Math.min(MAX_RATE, Math.min(this.sendQueue.size(), Integer.MAX_VALUE))); // note: no logic to track concurrent sends |
| 47 | + final long maxSendsThisTick = this.chunkSendLimiter.takeAllocation(maxSends); |
41 | 48 | // we do not return sends that we took from the allocation back because we want to limit the max send rate, not target it |
42 | 49 | + int j = 0; // ShreddedPaper |
43 | | - for (int i = 0; i < maxSendsThisTick; ++i) { |
| 50 | + for (long i = 0; i < maxSendsThisTick; ++i) { |
44 | 51 | final long pendingSend = this.sendQueue.firstLong(); |
45 | 52 | final int pendingSendX = CoordinateUtils.getChunkX(pendingSend); |
46 | 53 | final int pendingSendZ = CoordinateUtils.getChunkZ(pendingSend); |
|
68 | 75 | // not yet post-processed, need to do this so that tile entities can properly be sent to clients |
69 | 76 | chunk.postProcessGeneration(this.world); |
70 | 77 | // check if there was any recursive action |
71 | | -@@ -841,7 +_,17 @@ |
| 78 | +@@ -858,7 +_,17 @@ |
72 | 79 | } |
73 | 80 | this.sendQueue.dequeueLong(); |
74 | 81 |
|
|
87 | 94 |
|
88 | 95 | if (this.removed) { |
89 | 96 | // sendChunk may invoke plugin logic |
90 | | -@@ -849,6 +_,15 @@ |
| 97 | +@@ -866,6 +_,15 @@ |
91 | 98 | } |
92 | 99 | } |
93 | 100 |
|
|
103 | 110 | this.flushDelayedTicketOps(); |
104 | 111 | } |
105 | 112 |
|
106 | | -@@ -907,7 +_,7 @@ |
| 113 | +@@ -918,7 +_,7 @@ |
107 | 114 | ); |
108 | 115 | } |
109 | 116 |
|
|
112 | 119 | TickThread.ensureTickThread(this.player, "Cannot update player asynchronously"); |
113 | 120 | if (this.removed) { |
114 | 121 | throw new IllegalStateException("Updating removed player chunk loader"); |
115 | | -@@ -967,6 +_,7 @@ |
| 122 | +@@ -978,6 +_,7 @@ |
116 | 123 | this.player.connection.send(this.updateClientSimulationDistance(tickViewDistance)); |
117 | 124 | } |
118 | 125 |
|
119 | 126 | + this.retryLaterSendQueue.clear(); // ShreddedPaper |
120 | 127 | this.sendQueue.clear(); |
121 | 128 | this.tickingQueue.clear(); |
122 | 129 | this.generatingQueue.clear(); |
123 | | -@@ -1073,6 +_,7 @@ |
| 130 | +@@ -1084,6 +_,7 @@ |
124 | 131 | this.tickMap.remove(); |
125 | 132 |
|
126 | 133 | // purge queues |
|
0 commit comments