Fix several issues, mostly saving pending teleporting entities

The place/portal async function now track entities that have been
removed from the world but have not teleported. When the server
shuts down, these entities will have their passenger tree restored
and re-added to the entity slices at the location they were teleporting to,
or in the case of portals that did not run placeAsync yet,
the location they entered the portal on. This should ensure that
for regular teleports that the entity is placed at its correct
target location, and for portalling to ensure that either
the entity is placed at the portal entrace location (where
they entered) or the portal destination. In any case,
the entity is preserved in a location and will survive
the shutdown.

Additionally, move player saving until after the worlds save. This
is to ensure that the save logic is performed only after
all teleportations have completed.

Fix some other misc issues as well:
 - Fix double nether portal creation by checking if a portal exists again
   before creating it, fixing a race condition where two entites would portal
   and neither would see that the other created a portal.
 - Make all remove ticket add an unknown ticket.
   In general this behavior is better since it means that unloads will only
   ever occur at the next tick, rather than during the tick logic. Thus,
   there will be no cases where a chunk is unloaded unexpectedly.
 - Do not use fastFloor for calculating chunk position from block position
   It is not going to return a good value outside of [-1024, 1024]
 - Always perform mid tick update for ticking regionised player chunk loader
   If no entities were loaded, no chunks were loaded, and nothing else -
   the logic would not have otherwise ran. This fixed some rare cases of
   chunks never loading for players after logging in.
This commit is contained in:
Spottedleaf 2023-03-01 19:12:31 -08:00
parent 3cccc8b3e9
commit 093b1e5394
4 changed files with 339 additions and 152 deletions

View File

@ -46,10 +46,10 @@ index 0e45a340ae534caf676b7f9d0adcbcee5829925e..6df1948b1204a7288ecb7238b6fc2a73
private ChunkSystem() {
diff --git a/src/main/java/io/papermc/paper/chunk/system/RegionisedPlayerChunkLoader.java b/src/main/java/io/papermc/paper/chunk/system/RegionisedPlayerChunkLoader.java
new file mode 100644
index 0000000000000000000000000000000000000000..cb170d1039fd9dadfbc27da0b181c00742e72025
index 0000000000000000000000000000000000000000..7e2176f343160b299e7d4a2817c8f6c9ba7dba7b
--- /dev/null
+++ b/src/main/java/io/papermc/paper/chunk/system/RegionisedPlayerChunkLoader.java
@@ -0,0 +1,1302 @@
@@ -0,0 +1,1304 @@
+package io.papermc.paper.chunk.system;
+
+import ca.spottedleaf.concurrentutil.executor.standard.PrioritisedExecutor;
@ -283,8 +283,10 @@ index 0000000000000000000000000000000000000000..cb170d1039fd9dadfbc27da0b181c007
+
+ public void tick() {
+ TickThread.ensureTickThread("Cannot tick player chunk loader async");
+ long currTime = System.nanoTime();
+ for (final ServerPlayer player : this.world.players()) {
+ player.chunkLoader.update();
+ player.chunkLoader.midTickUpdate(currTime);
+ }
+ }
+

File diff suppressed because it is too large Load Diff

View File

@ -10,7 +10,7 @@ will allow the chunk system to scale beyond 10 threads
per world.
diff --git a/src/main/java/io/papermc/paper/chunk/system/RegionisedPlayerChunkLoader.java b/src/main/java/io/papermc/paper/chunk/system/RegionisedPlayerChunkLoader.java
index 5cccfcf45b3c3cdfdebdf47dc674934441cc0c4c..ede3fbe3287a08b9b1a026f8443f1c97d4205dde 100644
index 245242b276e3de1edde1e2ebd0ce518fd0d08117..acf77a7745db2e28bd674107cdcb65d278625445 100644
--- a/src/main/java/io/papermc/paper/chunk/system/RegionisedPlayerChunkLoader.java
+++ b/src/main/java/io/papermc/paper/chunk/system/RegionisedPlayerChunkLoader.java
@@ -12,6 +12,7 @@ import it.unimi.dsi.fastutil.longs.LongArrayFIFOQueue;
@ -32,7 +32,7 @@ index 5cccfcf45b3c3cdfdebdf47dc674934441cc0c4c..ede3fbe3287a08b9b1a026f8443f1c97
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
@@ -284,7 +286,92 @@ public class RegionisedPlayerChunkLoader {
@@ -286,7 +288,92 @@ public class RegionisedPlayerChunkLoader {
}
}
@ -196,10 +196,10 @@ index 0b7a2b0ead4f3bc07bfd9a38c2b7cf024bd140c6..36e93fefdfbebddce4c153974c7cd81a
final int chunkX = CoordinateUtils.getChunkX(coordinate);
final int chunkZ = CoordinateUtils.getChunkZ(coordinate);
diff --git a/src/main/java/io/papermc/paper/chunk/system/scheduling/ChunkHolderManager.java b/src/main/java/io/papermc/paper/chunk/system/scheduling/ChunkHolderManager.java
index 309b45885edc1400ae5a97cac7e5e5a19d73be0c..a5d44db5e1cc26d871c9db7727fdbae571880663 100644
index 32b88d7902e877e1cce0b7635cbfa67b84b8eac0..89e8b5d3a62241df0e3cb5c296f1deb754305843 100644
--- a/src/main/java/io/papermc/paper/chunk/system/scheduling/ChunkHolderManager.java
+++ b/src/main/java/io/papermc/paper/chunk/system/scheduling/ChunkHolderManager.java
@@ -1310,17 +1310,23 @@ public final class ChunkHolderManager {
@@ -1306,17 +1306,23 @@ public final class ChunkHolderManager {
}
public Boolean tryDrainTicketUpdates() {

View File

@ -1,5 +1,4 @@
Get done before testing:
- make sure async teleport / player join / async place entities are saved on shutdown
- make scheduler load chunks better
Pre-Test: List of things not fully tested