From 96fd31b7629c063d26044c31f7d074e3c8da53b0 Mon Sep 17 00:00:00 2001 From: Martijn Date: Thu, 9 Feb 2023 18:27:24 +0100 Subject: [PATCH] Fix chunk sending when the computed time overflows (#8833) --- patches/server/0016-Rewrite-chunk-system.patch | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/patches/server/0016-Rewrite-chunk-system.patch b/patches/server/0016-Rewrite-chunk-system.patch index db676c1af..5f60ba7d1 100644 --- a/patches/server/0016-Rewrite-chunk-system.patch +++ b/patches/server/0016-Rewrite-chunk-system.patch @@ -1309,7 +1309,7 @@ index 0000000000000000000000000000000000000000..99f49b5625cf51d6c97640553cf5c420 +} diff --git a/src/main/java/io/papermc/paper/chunk/PlayerChunkLoader.java b/src/main/java/io/papermc/paper/chunk/PlayerChunkLoader.java new file mode 100644 -index 0000000000000000000000000000000000000000..0b060183429f4c72ec767075538477b4302bbf0d +index 0000000000000000000000000000000000000000..e77972c4c264100ffdd824bfa2dac58dbbc6d678 --- /dev/null +++ b/src/main/java/io/papermc/paper/chunk/PlayerChunkLoader.java @@ -0,0 +1,1128 @@ @@ -1404,7 +1404,7 @@ index 0000000000000000000000000000000000000000..0b060183429f4c72ec767075538477b4 + + final int priorityCompare = Double.compare(holder1 == null ? Double.MAX_VALUE : holder1.priority, holder2 == null ? Double.MAX_VALUE : holder2.priority); + -+ final int lastLoadTimeCompare = Long.compare(p1.lastChunkLoad, p2.lastChunkLoad); ++ final int lastLoadTimeCompare = Long.compare(p1.lastChunkLoad - p2.lastChunkLoad, 0); + + if ((holder1 == null || holder2 == null || lastLoadTimeCompare == 0 || holder1.priority < 0.0 || holder2.priority < 0.0) && priorityCompare != 0) { + return priorityCompare; @@ -1429,7 +1429,7 @@ index 0000000000000000000000000000000000000000..0b060183429f4c72ec767075538477b4 + return 0; + } + -+ final int timeCompare = Long.compare(p1.nextChunkSendTarget, p2.nextChunkSendTarget); ++ final int timeCompare = Long.compare(p1.nextChunkSendTarget - p2.nextChunkSendTarget, 0); + if (timeCompare != 0) { + return timeCompare; + } @@ -1835,14 +1835,14 @@ index 0000000000000000000000000000000000000000..0b060183429f4c72ec767075538477b4 + private static long nextChunkSend; + private void trySendChunks() { + final long time = System.nanoTime(); -+ if (time < nextChunkSend) { ++ if (nextChunkSend - time > 0) { + return; + } + // drain entries from wait queue + while (!this.chunkSendWaitQueue.isEmpty()) { + final PlayerLoaderData data = this.chunkSendWaitQueue.first(); + -+ if (data.nextChunkSendTarget > time) { ++ if (data.nextChunkSendTarget - time > 0) { + break; + } + @@ -1914,7 +1914,7 @@ index 0000000000000000000000000000000000000000..0b060183429f4c72ec767075538477b4 + }); + + nextChunkSend = this.getMaxSendAddend() + time; -+ if (time < nextChunkSend) { ++ if (nextChunkSend - time > 0) { + break; + } + }