Skip to content

Commit

Permalink
Fix PaperTickList (#6191)
Browse files Browse the repository at this point in the history
  • Loading branch information
Machine-Maker authored Jul 16, 2021
1 parent 5a9c14b commit a5acf36
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ index 4c97fa63d912548324e93f366c86666d52738bfb..bfdf4b302860d56dec485af77c69d18d
ConfigurationSection section;
diff --git a/src/main/java/com/destroystokyo/paper/server/ticklist/PaperTickList.java b/src/main/java/com/destroystokyo/paper/server/ticklist/PaperTickList.java
new file mode 100644
index 0000000000000000000000000000000000000000..da13ff17609b7bc8076d9297edf8decf01a2ed88
index 0000000000000000000000000000000000000000..5fdaefc128956581be4bb9b34199fd6410563991
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/server/ticklist/PaperTickList.java
@@ -0,0 +1,628 @@
Expand Down Expand Up @@ -168,7 +168,7 @@ index 0000000000000000000000000000000000000000..da13ff17609b7bc8076d9297edf8decf
+
+ private void queueEntryForTick(final TickNextTickData<T> entry, final ServerChunkCache chunkProvider) {
+ if (entry.tickState == STATE_SCHEDULED) {
+ if (chunkProvider.isTickingReadyMainThread(entry.pos)) {
+ if (chunkProvider.isPositionTickingWithEntitiesLoaded(entry.pos)) {
+ this.toTickThisTick.add(entry);
+ entry.tickState = STATE_PENDING_TICK;
+ } else {
Expand Down Expand Up @@ -368,7 +368,7 @@ index 0000000000000000000000000000000000000000..da13ff17609b7bc8076d9297edf8decf
+ continue;
+ }
+ try {
+ if (chunkProvider.isTickingReadyMainThread(toTick.pos)) {
+ if (chunkProvider.isPositionTickingWithEntitiesLoaded(toTick.pos)) {
+ toTick.tickState = STATE_TICKING;
+ this.tickFunction.accept(toTick);
+ if (toTick.tickState == STATE_TICKING) {
Expand Down Expand Up @@ -924,17 +924,18 @@ index 1dd1b9afaee38fdc994ad0a069bd63b02eedf55c..8104b9be5a8e8d57f6f50475788aec6a
});
// Paper end
diff --git a/src/main/java/net/minecraft/server/level/ServerChunkCache.java b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
index 550338a7170437415342df7bc1b0a5c445480300..a0d96ca2e63157e5995774c5a7a5f535e700bbfa 100644
index 550338a7170437415342df7bc1b0a5c445480300..57aa6d18d181c50071bcfcc933cde9fa828be792 100644
--- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java
+++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
@@ -219,6 +219,12 @@ public class ServerChunkCache extends ChunkSource {
@@ -219,6 +219,13 @@ public class ServerChunkCache extends ChunkSource {
}, this.mainThreadProcessor);
}
// Paper end
+ // Paper start - rewrite ticklistserver
+ public final boolean isTickingReadyMainThread(BlockPos pos) {
+ ChunkHolder chunk = this.chunkMap.getUpdatingChunkIfPresent(net.minecraft.server.MCUtil.getCoordinateKey(pos));
+ return chunk != null && chunk.isTickingReady();
+ public final boolean isPositionTickingWithEntitiesLoaded(BlockPos pos) {
+ long position = net.minecraft.server.MCUtil.getCoordinateKey(pos);
+ ChunkHolder chunkHolder = this.chunkMap.getUpdatingChunkIfPresent(position);
+ return chunkHolder != null && chunkHolder.isTickingReady() && this.level.entityManager.areEntitiesLoaded(position);
+ }
+ // Paper end - rewrite ticklistserver

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,10 @@ index 2b291296821dc6d6a8437bd977eeba517cdb5003..962028a58ee54b99be20905c1fd16cfe
while (objectbidirectionaliterator.hasNext()) {
Entry<ChunkHolder> entry = (Entry) objectbidirectionaliterator.next();
diff --git a/src/main/java/net/minecraft/server/level/ServerChunkCache.java b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
index b9516560183d37ef2917a3f9aaba60a53bcdfd72..b3c66e3f3ef47949f90efa023610ede55aabdf91 100644
index 57aa6d18d181c50071bcfcc933cde9fa828be792..ed3ce0f87eaf4777aedc93fe5bd67971ffb10d86 100644
--- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java
+++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
@@ -766,7 +766,7 @@ public class ServerChunkCache extends ChunkSource {
@@ -767,7 +767,7 @@ public class ServerChunkCache extends ChunkSource {
};
// Paper end
this.level.timings.chunkTicks.startTiming(); // Paper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,26 +147,26 @@ index ce438760cbc92c08c079d06a8b97eaeda1018491..0115ffe84356468ddc254d8d5bdd719b
// Spigot Start
CrashReport crashreport;
diff --git a/src/main/java/net/minecraft/server/level/ServerChunkCache.java b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
index a4c043d33b83003b440eb2baf1cc1bc7081019d3..902394e45ed6d34aa33ed8d3c74ddcaf0adbe83c 100644
index ed3ce0f87eaf4777aedc93fe5bd67971ffb10d86..67c2f84bd2c184475f1a448898d381414bab9118 100644
--- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java
+++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
@@ -703,6 +703,7 @@ public class ServerChunkCache extends ChunkSource {
@@ -704,6 +704,7 @@ public class ServerChunkCache extends ChunkSource {
this.level.getProfiler().push("purge");
this.level.timings.doChunkMap.startTiming(); // Spigot
this.distanceManager.purgeStaleTickets();
+ this.level.getServer().midTickLoadChunks(); // Paper
this.runDistanceManagerUpdates();
this.level.timings.doChunkMap.stopTiming(); // Spigot
this.level.getProfiler().popPush("chunks");
@@ -712,6 +713,7 @@ public class ServerChunkCache extends ChunkSource {
@@ -713,6 +714,7 @@ public class ServerChunkCache extends ChunkSource {
this.level.timings.doChunkUnload.startTiming(); // Spigot
this.level.getProfiler().popPush("unload");
this.chunkMap.tick(booleansupplier);
+ this.level.getServer().midTickLoadChunks(); // Paper
this.level.timings.doChunkUnload.stopTiming(); // Spigot
this.level.getProfiler().pop();
this.clearCache();
@@ -766,7 +768,7 @@ public class ServerChunkCache extends ChunkSource {
@@ -767,7 +769,7 @@ public class ServerChunkCache extends ChunkSource {
};
// Paper end
this.level.timings.chunkTicks.startTiming(); // Paper
Expand All @@ -175,15 +175,15 @@ index a4c043d33b83003b440eb2baf1cc1bc7081019d3..902394e45ed6d34aa33ed8d3c74ddcaf
Optional<LevelChunk> optional = ((Either) playerchunk.getTickingChunkFuture().getNow(ChunkHolder.UNLOADED_LEVEL_CHUNK)).left();

if (optional.isPresent()) {
@@ -777,6 +779,7 @@ public class ServerChunkCache extends ChunkSource {
@@ -778,6 +780,7 @@ public class ServerChunkCache extends ChunkSource {
chunk.setInhabitedTime(chunk.getInhabitedTime() + j);
if (flag1 && (this.spawnEnemies || this.spawnFriendlies) && this.level.getWorldBorder().isWithinBounds(chunk.getPos()) && !this.chunkMap.isOutsideOfRange(chunkcoordintpair, true)) { // Spigot
NaturalSpawner.spawnForChunk(this.level, chunk, spawnercreature_d, this.spawnFriendlies, this.spawnEnemies, flag2);
+ if (chunksTicked[0]++ % 10 == 0) this.level.getServer().midTickLoadChunks(); // Paper
}

// this.level.timings.doTickTiles.startTiming(); // Spigot // Paper
@@ -794,7 +797,7 @@ public class ServerChunkCache extends ChunkSource {
@@ -795,7 +798,7 @@ public class ServerChunkCache extends ChunkSource {
}

this.level.getProfiler().popPush("broadcast");
Expand All @@ -192,7 +192,7 @@ index a4c043d33b83003b440eb2baf1cc1bc7081019d3..902394e45ed6d34aa33ed8d3c74ddcaf
Optional<LevelChunk> optional = ((Either) playerchunk.getTickingChunkFuture().getNow(ChunkHolder.UNLOADED_LEVEL_CHUNK)).left(); // CraftBukkit - decompile error

Objects.requireNonNull(playerchunk);
@@ -958,6 +961,41 @@ public class ServerChunkCache extends ChunkSource {
@@ -959,6 +962,41 @@ public class ServerChunkCache extends ChunkSource {
super.doRunTask(task);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ index 6d810cdb538d078dbf7ccd2ef84a4be27eb1f3e7..aa9846c7d6b8499e01bf0ffeece6a940

completablefuture1.thenAcceptAsync((either) -> {
diff --git a/src/main/java/net/minecraft/server/level/ServerChunkCache.java b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
index de0ef9f056f86e1e0d75f40c9b842ffbe4b37b41..da2a7abd3d2bd1a83e2a3f3a458287730e5a29da 100644
index 67c2f84bd2c184475f1a448898d381414bab9118..0d7de5a2feb75e9862da2926de5bb6afe28f8036 100644
--- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java
+++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
@@ -1008,6 +1008,7 @@ public class ServerChunkCache extends ChunkSource {
@@ -1009,6 +1009,7 @@ public class ServerChunkCache extends ChunkSource {
return super.pollTask() || execChunkTask; // Paper
}
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,10 @@ index b49d380ef088aed3204ec71abc437c348ef004fa..577b391dcba1db712c1e2c83296e1c87

public String getDebugStatus() {
diff --git a/src/main/java/net/minecraft/server/level/ServerChunkCache.java b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
index da2a7abd3d2bd1a83e2a3f3a458287730e5a29da..d6cb161981d3cdef4669522ba51cb1db83f9e04c 100644
index 0d7de5a2feb75e9862da2926de5bb6afe28f8036..08057df46f3044c5e84e55d1669c07426dbd63c6 100644
--- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java
+++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
@@ -729,6 +729,37 @@ public class ServerChunkCache extends ChunkSource {
@@ -730,6 +730,37 @@ public class ServerChunkCache extends ChunkSource {
boolean flag1 = this.level.getGameRules().getBoolean(GameRules.RULE_DOMOBSPAWNING) && !this.level.players().isEmpty(); // CraftBukkit

if (!flag) {
Expand Down Expand Up @@ -332,7 +332,7 @@ index da2a7abd3d2bd1a83e2a3f3a458287730e5a29da..d6cb161981d3cdef4669522ba51cb1db
this.level.getProfiler().push("pollingChunks");
int k = this.level.getGameRules().getInt(GameRules.RULE_RANDOMTICKING);
boolean flag2 = level.ticksPerAnimalSpawns != 0L && worlddata.getGameTime() % level.ticksPerAnimalSpawns == 0L; // CraftBukkit
@@ -758,15 +789,7 @@ public class ServerChunkCache extends ChunkSource {
@@ -759,15 +790,7 @@ public class ServerChunkCache extends ChunkSource {
this.level.getProfiler().pop();
//List<PlayerChunk> list = Lists.newArrayList(this.playerChunkMap.f()); // Paper
//Collections.shuffle(list); // Paper
Expand All @@ -349,7 +349,7 @@ index da2a7abd3d2bd1a83e2a3f3a458287730e5a29da..d6cb161981d3cdef4669522ba51cb1db
this.level.timings.chunkTicks.startTiming(); // Paper
final int[] chunksTicked = {0}; this.chunkMap.forEachVisibleChunk((playerchunk) -> { // Paper - safe iterator incase chunk loads, also no wrapping
Optional<LevelChunk> optional = ((Either) playerchunk.getTickingChunkFuture().getNow(ChunkHolder.UNLOADED_LEVEL_CHUNK)).left();
@@ -775,9 +798,9 @@ public class ServerChunkCache extends ChunkSource {
@@ -776,9 +799,9 @@ public class ServerChunkCache extends ChunkSource {
LevelChunk chunk = (LevelChunk) optional.get();
ChunkPos chunkcoordintpair = chunk.getPos();

Expand Down
4 changes: 2 additions & 2 deletions patches/server/0456-incremental-chunk-saving.patch
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,10 @@ index a1529fef41543486d29271b1de62a6246d07d384..f518fc7a39a807bff2e141fd238ab1bf
ChunkPos chunkcoordintpair = chunk.getPos();

diff --git a/src/main/java/net/minecraft/server/level/ServerChunkCache.java b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
index d8bf5a86a3eb0ae3fd6308e817a707ae98961479..ec0a9f46b50280324ae0d2eed208c8f332a5d88d 100644
index 08057df46f3044c5e84e55d1669c07426dbd63c6..c28eda68d744c0a1c9229790af3a89dfac94ae22 100644
--- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java
+++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
@@ -671,6 +671,15 @@ public class ServerChunkCache extends ChunkSource {
@@ -672,6 +672,15 @@ public class ServerChunkCache extends ChunkSource {
} // Paper - Timings
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -941,10 +941,10 @@ index d94241bcca4f2fd5e464a860bd356af504dc68b7..1cc4e0a1f3d8235ef88b48e01ca8b78a
}
}
diff --git a/src/main/java/net/minecraft/server/level/ServerChunkCache.java b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
index ec0a9f46b50280324ae0d2eed208c8f332a5d88d..ac9cb37dd91ac449f8943b1279f247846a35025a 100644
index c28eda68d744c0a1c9229790af3a89dfac94ae22..f72ef5a0f97119732babc0ea353658cef52d6fe0 100644
--- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java
+++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
@@ -445,6 +445,26 @@ public class ServerChunkCache extends ChunkSource {
@@ -446,6 +446,26 @@ public class ServerChunkCache extends ChunkSource {
public <T> void removeTicketAtLevel(TicketType<T> ticketType, ChunkPos chunkPos, int ticketLevel, T identifier) {
this.distanceManager.removeTicketAtLevel(ticketType, chunkPos, ticketLevel, identifier);
}
Expand All @@ -971,7 +971,7 @@ index ec0a9f46b50280324ae0d2eed208c8f332a5d88d..ac9cb37dd91ac449f8943b1279f24784
// Paper end - async chunk io

@Nullable
@@ -485,6 +505,8 @@ public class ServerChunkCache extends ChunkSource {
@@ -486,6 +506,8 @@ public class ServerChunkCache extends ChunkSource {
Objects.requireNonNull(completablefuture);
if (!completablefuture.isDone()) { // Paper
// Paper start - async chunk io/loading
Expand All @@ -980,7 +980,7 @@ index ec0a9f46b50280324ae0d2eed208c8f332a5d88d..ac9cb37dd91ac449f8943b1279f24784
this.level.asyncChunkTaskManager.raisePriority(x1, z1, com.destroystokyo.paper.io.PrioritizedTaskQueue.HIGHEST_PRIORITY);
com.destroystokyo.paper.io.chunk.ChunkTaskManager.pushChunkWait(this.level, x1, z1);
// Paper end
@@ -493,6 +515,8 @@ public class ServerChunkCache extends ChunkSource {
@@ -494,6 +516,8 @@ public class ServerChunkCache extends ChunkSource {
chunkproviderserver_a.managedBlock(completablefuture::isDone);
com.destroystokyo.paper.io.chunk.ChunkTaskManager.popChunkWait(); // Paper - async chunk debug
this.level.timings.syncChunkLoad.stopTiming(); // Paper
Expand All @@ -989,7 +989,7 @@ index ec0a9f46b50280324ae0d2eed208c8f332a5d88d..ac9cb37dd91ac449f8943b1279f24784
} // Paper
ichunkaccess = (ChunkAccess) ((Either) completablefuture.join()).map((ichunkaccess1) -> {
return ichunkaccess1;
@@ -566,10 +590,12 @@ public class ServerChunkCache extends ChunkSource {
@@ -567,10 +591,12 @@ public class ServerChunkCache extends ChunkSource {
if (flag && !currentlyUnloading) {
// CraftBukkit end
this.distanceManager.addTicket(TicketType.UNKNOWN, chunkcoordintpair, l, chunkcoordintpair);
Expand All @@ -1002,7 +1002,7 @@ index ec0a9f46b50280324ae0d2eed208c8f332a5d88d..ac9cb37dd91ac449f8943b1279f24784
this.runDistanceManagerUpdates();
playerchunk = this.getVisibleChunkIfPresent(k);
gameprofilerfiller.pop();
@@ -578,8 +604,13 @@ public class ServerChunkCache extends ChunkSource {
@@ -579,8 +605,13 @@ public class ServerChunkCache extends ChunkSource {
}
}
}
Expand All @@ -1018,7 +1018,7 @@ index ec0a9f46b50280324ae0d2eed208c8f332a5d88d..ac9cb37dd91ac449f8943b1279f24784
}

private boolean chunkAbsent(@Nullable ChunkHolder holder, int maxLevel) {
@@ -631,6 +662,7 @@ public class ServerChunkCache extends ChunkSource {
@@ -632,6 +663,7 @@ public class ServerChunkCache extends ChunkSource {
}

public boolean runDistanceManagerUpdates() {
Expand Down
6 changes: 3 additions & 3 deletions patches/server/0495-Optimize-Light-Engine.patch
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ index d3d6651eb51c852ed1d1eeb5689569d5308b246d..c2d36600a0081c78425868154bdcf7f4
m = Long.MAX_VALUE;
}
diff --git a/src/main/java/net/minecraft/server/level/ServerChunkCache.java b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
index ac9cb37dd91ac449f8943b1279f247846a35025a..ce1b73363f8a1a012aa7b3cbcc54164d87abc195 100644
index f72ef5a0f97119732babc0ea353658cef52d6fe0..89b484170bc1c4bbd1bcd1e283dcd97c4d1129cd 100644
--- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java
+++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
@@ -1068,7 +1068,7 @@ public class ServerChunkCache extends ChunkSource {
@@ -1069,7 +1069,7 @@ public class ServerChunkCache extends ChunkSource {
if (ServerChunkCache.this.runDistanceManagerUpdates()) {
return true;
} else {
Expand All @@ -139,7 +139,7 @@ index ac9cb37dd91ac449f8943b1279f247846a35025a..ce1b73363f8a1a012aa7b3cbcc54164d
}
} finally {
diff --git a/src/main/java/net/minecraft/server/level/ThreadedLevelLightEngine.java b/src/main/java/net/minecraft/server/level/ThreadedLevelLightEngine.java
index 2c4aa4b66d83b6e7a104479860b7982629c63c3b..84f86e51fca587887c4b2277205a188a92696110 100644
index 2c4aa4b66d83b6e7a104479860b7982629c63c3b..f0df7b2bd618c7be18c4c86f735b303dc73d98ad 100644
--- a/src/main/java/net/minecraft/server/level/ThreadedLevelLightEngine.java
+++ b/src/main/java/net/minecraft/server/level/ThreadedLevelLightEngine.java
@@ -1,6 +1,7 @@
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Subject: [PATCH] Skip distance map update when spawning disabled.


diff --git a/src/main/java/net/minecraft/server/level/ServerChunkCache.java b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
index 8c15f7821864032319665f9fc5183f302856637e..3613d09a88b283d693ca0e39117e8337d6e4b034 100644
index 89b484170bc1c4bbd1bcd1e283dcd97c4d1129cd..c5a73dee1c1c4724f01be44399f52cd2f711256c 100644
--- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java
+++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
@@ -810,7 +810,7 @@ public class ServerChunkCache extends ChunkSource {
@@ -811,7 +811,7 @@ public class ServerChunkCache extends ChunkSource {
int l = this.distanceManager.getNaturalSpawnChunkCount();
// Paper start - per player mob spawning
NaturalSpawner.SpawnState spawnercreature_d; // moved down
Expand Down

0 comments on commit a5acf36

Please sign in to comment.