From fc517efae467be7665bcef49235066d847b1f878 Mon Sep 17 00:00:00 2001 From: Aikar Date: Mon, 8 Jun 2020 17:03:42 -0400 Subject: [PATCH] Fix undesirable behavior around world level changes due to priority priority tickets being added at 33 was hurting sync EMPTY and lesser requests. this was likely the source of recent treasure map issues. This then further hurt nether portal travel too. lots of oddness around. This also avoids scheduling a level change on ticket removal when the level is unchanged, as well as ditches CB's horrible change to not letting you access an unloading chunk which should be valid to cancel the unload --- ...k-Priority-Urgency-System-for-Chunks.patch | 27 ++++++++++++++----- ...asks-Speed-up-processing-of-chunk-lo.patch | 2 +- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/Spigot-Server-Patches/Implement-Chunk-Priority-Urgency-System-for-Chunks.patch b/Spigot-Server-Patches/Implement-Chunk-Priority-Urgency-System-for-Chunks.patch index 1ea230175..5d5af7374 100644 --- a/Spigot-Server-Patches/Implement-Chunk-Priority-Urgency-System-for-Chunks.patch +++ b/Spigot-Server-Patches/Implement-Chunk-Priority-Urgency-System-for-Chunks.patch @@ -148,14 +148,27 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 private boolean removeTicket(long i, Ticket ticket) { // CraftBukkit - void -> boolean + AsyncCatcher.catchOp("ChunkMapDistance::removeTicket"); // Paper ArraySetSorted> arraysetsorted = this.e(i); ++ int oldLevel = a(arraysetsorted); // Paper boolean removed = false; // CraftBukkit + if (arraysetsorted.remove(ticket)) { +@@ -0,0 +0,0 @@ public abstract class ChunkMapDistance { + if (arraysetsorted.isEmpty()) { + this.tickets.remove(i); + } +- +- this.e.b(i, a(arraysetsorted), false); ++ int newLevel = a(arraysetsorted); // Paper ++ if (newLevel > oldLevel) this.e.b(i, newLevel, false); // Paper + return removed; // CraftBukkit + } + @@ -0,0 +0,0 @@ public abstract class ChunkMapDistance { this.addTicketAtLevel(tickettype, chunkcoordintpair, i, t0); } + // Paper start -+ public static final int PRIORITY_TICKET_LEVEL = 33; ++ public static final int PRIORITY_TICKET_LEVEL = PlayerChunkMap.GOLDEN_TICKET; + public static final int URGENT_PRIORITY = 29; + public boolean markUrgent(ChunkCoordIntPair coords) { + return addPriorityTicket(coords, TicketType.URGENT, URGENT_PRIORITY); @@ -186,7 +199,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + if (updatingChunk != null && updatingChunk.priorityBoost < priority) { + // May not be enqueued, enqueue it if not and tick distance manager + chunkMap.queueHolderUpdate(updatingChunk); -+ chunkMap.world.getChunkProvider().tickDistanceManager(); + } + return success; + } @@ -332,7 +344,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 ichunkaccess = (IChunkAccess) ((Either) completablefuture.join()).map((ichunkaccess1) -> { return ichunkaccess1; @@ -0,0 +0,0 @@ public class ChunkProviderServer extends IChunkProvider { - if (flag && !currentlyUnloading) { + PlayerChunk.State currentChunkState = PlayerChunk.getChunkState(playerchunk.getTicketLevel()); + currentlyUnloading = (oldChunkState.isAtLeast(PlayerChunk.State.BORDER) && !currentChunkState.isAtLeast(PlayerChunk.State.BORDER)); + } +- if (flag && !currentlyUnloading) { ++ if (flag) { // Paper - don't care about unloading state // CraftBukkit end this.chunkMapDistance.a(TicketType.UNKNOWN, chunkcoordintpair, l, chunkcoordintpair); + if (isUrgent) this.chunkMapDistance.markUrgent(chunkcoordintpair); // Paper @@ -445,7 +461,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + priority = myPriority; + } + -+ return Math.max(1, Math.min(PlayerChunkMap.GOLDEN_TICKET, priority)); ++ return Math.max(1, Math.min(Math.max(ticketLevel, PlayerChunkMap.GOLDEN_TICKET), priority)); + } + + private int getMyPriority() { @@ -716,9 +732,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + return; // unloaded + } + chunkDistanceManager.pendingChunkUpdates.add(playerchunk); -+ if (!chunkDistanceManager.pollingPendingChunkUpdates) { -+ world.getChunkProvider().tickDistanceManager(); -+ } + }; + if (MCUtil.isMainThread()) { + // We can't use executor here because it will not execute tasks if its currently in the middle of executing tasks... diff --git a/Spigot-Server-Patches/Mid-Tick-Chunk-Tasks-Speed-up-processing-of-chunk-lo.patch b/Spigot-Server-Patches/Mid-Tick-Chunk-Tasks-Speed-up-processing-of-chunk-lo.patch index c7a58d8ba..8c4e734e6 100644 --- a/Spigot-Server-Patches/Mid-Tick-Chunk-Tasks-Speed-up-processing-of-chunk-lo.patch +++ b/Spigot-Server-Patches/Mid-Tick-Chunk-Tasks-Speed-up-processing-of-chunk-lo.patch @@ -163,7 +163,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + public int midTickChunksTasksRan = 0; + private long midTickLastRan = 0; + public void midTickLoadChunks() { -+ if (!isMainThread() || System.nanoTime() - midTickLastRan < 200000) { ++ if (!isMainThread() || System.nanoTime() - midTickLastRan < 1000000) { + // only check once per 0.25ms incase this code is called in a hot method + return; + }