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
This commit is contained in:
Aikar 2020-06-08 17:03:42 -04:00
parent 5c048e9ae3
commit fc517efae4
2 changed files with 21 additions and 8 deletions

View File

@ -148,14 +148,27 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
private boolean removeTicket(long i, Ticket<?> ticket) { // CraftBukkit - void -> boolean
+ AsyncCatcher.catchOp("ChunkMapDistance::removeTicket"); // Paper
ArraySetSorted<Ticket<?>> 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...

View File

@ -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;
+ }