2018-07-24 08:24:44 +08:00
|
|
|
From 8dca59c82d4970ec06b04d9656b4b2d6cb1b841d Mon Sep 17 00:00:00 2001
|
2016-03-25 14:38:38 +08:00
|
|
|
From: Byteflux <byte@byteflux.net>
|
|
|
|
Date: Wed, 2 Mar 2016 00:52:31 -0600
|
|
|
|
Subject: [PATCH] Lighting Queue
|
|
|
|
|
2016-07-16 06:36:53 +08:00
|
|
|
This provides option to queue lighting updates to ensure they do not cause the server lag
|
2016-03-25 14:38:38 +08:00
|
|
|
|
2016-05-16 06:48:39 +08:00
|
|
|
diff --git a/src/main/java/co/aikar/timings/WorldTimingsHandler.java b/src/main/java/co/aikar/timings/WorldTimingsHandler.java
|
2018-07-15 09:53:17 +08:00
|
|
|
index 145cb274b..eff9dcf54 100644
|
2016-05-16 06:48:39 +08:00
|
|
|
--- a/src/main/java/co/aikar/timings/WorldTimingsHandler.java
|
|
|
|
+++ b/src/main/java/co/aikar/timings/WorldTimingsHandler.java
|
2018-07-15 09:53:17 +08:00
|
|
|
@@ -50,6 +50,8 @@ public class WorldTimingsHandler {
|
2017-08-13 05:32:01 +08:00
|
|
|
public final Timing worldSaveLevel;
|
2016-10-22 04:42:49 +08:00
|
|
|
public final Timing chunkSaveData;
|
2016-03-25 14:38:38 +08:00
|
|
|
|
2016-05-16 06:48:39 +08:00
|
|
|
+ public final Timing lightingQueueTimer;
|
|
|
|
+
|
|
|
|
public WorldTimingsHandler(World server) {
|
|
|
|
String name = server.worldData.getName() +" - ";
|
|
|
|
|
2018-07-15 09:53:17 +08:00
|
|
|
@@ -96,6 +98,8 @@ public class WorldTimingsHandler {
|
2016-05-16 06:48:39 +08:00
|
|
|
tracker2 = Timings.ofSafe(name + "tracker stage 2");
|
|
|
|
doTick = Timings.ofSafe(name + "doTick");
|
|
|
|
tickEntities = Timings.ofSafe(name + "tickEntities");
|
|
|
|
+
|
|
|
|
+ lightingQueueTimer = Timings.ofSafe(name + "Lighting Queue");
|
|
|
|
}
|
2018-07-15 09:53:17 +08:00
|
|
|
|
|
|
|
public static Timing getTickList(WorldServer worldserver, String timingsType) {
|
2016-03-25 14:38:38 +08:00
|
|
|
diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
|
2018-07-24 08:24:44 +08:00
|
|
|
index 68898d624..4b36a0f05 100644
|
2016-03-25 14:38:38 +08:00
|
|
|
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
|
|
|
|
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
|
2018-07-24 08:24:44 +08:00
|
|
|
@@ -130,4 +130,10 @@ public class PaperWorldConfig {
|
2016-03-31 08:50:23 +08:00
|
|
|
netherVoidTopDamage = getBoolean( "nether-ceiling-void-damage", false );
|
|
|
|
log("Top of the nether void damage: " + netherVoidTopDamage);
|
2016-03-25 14:38:38 +08:00
|
|
|
}
|
2016-03-31 08:50:23 +08:00
|
|
|
+
|
2016-03-25 14:38:38 +08:00
|
|
|
+ public boolean queueLightUpdates;
|
|
|
|
+ private void queueLightUpdates() {
|
|
|
|
+ queueLightUpdates = getBoolean("queue-light-updates", false);
|
|
|
|
+ log("Lighting Queue enabled: " + queueLightUpdates);
|
|
|
|
+ }
|
|
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java
|
2018-07-23 01:10:15 +08:00
|
|
|
index adf3dee2e..eb7a41977 100644
|
2016-03-25 14:38:38 +08:00
|
|
|
--- a/src/main/java/net/minecraft/server/Chunk.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/Chunk.java
|
2018-07-15 09:53:17 +08:00
|
|
|
@@ -91,6 +91,7 @@ public class Chunk implements IChunkAccess {
|
2018-07-04 15:55:24 +08:00
|
|
|
return removed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
+ final PaperLightingQueue.LightingQueue lightingQueue = new PaperLightingQueue.LightingQueue(this);
|
|
|
|
// Paper end
|
2018-07-15 09:53:17 +08:00
|
|
|
public boolean areNeighborsLoaded(final int radius) {
|
|
|
|
switch (radius) {
|
|
|
|
@@ -281,6 +282,13 @@ public class Chunk implements IChunkAccess {
|
|
|
|
private void g(boolean flag) {
|
2016-03-25 14:38:38 +08:00
|
|
|
this.world.methodProfiler.a("recheckGaps");
|
|
|
|
if (this.world.areChunksLoaded(new BlockPosition(this.locX * 16 + 8, 0, this.locZ * 16 + 8), 16)) {
|
2017-12-23 05:25:01 +08:00
|
|
|
+ this.runOrQueueLightUpdate(() -> recheckGaps(flag)); // Paper - Queue light update
|
2016-03-25 14:38:38 +08:00
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void recheckGaps(boolean flag) {
|
|
|
|
+ if (true) {
|
|
|
|
+ // Paper end
|
|
|
|
for (int i = 0; i < 16; ++i) {
|
|
|
|
for (int j = 0; j < 16; ++j) {
|
2018-07-15 09:53:17 +08:00
|
|
|
if (this.h[i + j * 16]) {
|
|
|
|
@@ -524,6 +532,7 @@ public class Chunk implements IChunkAccess {
|
|
|
|
if (flag1) {
|
2016-03-25 14:38:38 +08:00
|
|
|
this.initLighting();
|
2017-12-23 05:25:01 +08:00
|
|
|
} else {
|
|
|
|
+ this.runOrQueueLightUpdate(() -> { // Paper - Queue light update
|
2018-07-15 09:53:17 +08:00
|
|
|
int i1 = iblockdata.b(this.world, blockposition);
|
|
|
|
int j1 = iblockdata1.b(this.world, blockposition);
|
2016-03-25 14:38:38 +08:00
|
|
|
|
2018-07-15 09:53:17 +08:00
|
|
|
@@ -531,6 +540,7 @@ public class Chunk implements IChunkAccess {
|
|
|
|
if (i1 != j1 && (i1 < j1 || this.getBrightness(EnumSkyBlock.SKY, blockposition) > 0 || this.getBrightness(EnumSkyBlock.BLOCK, blockposition) > 0)) {
|
|
|
|
this.c(i, k);
|
2016-03-25 14:38:38 +08:00
|
|
|
}
|
2016-05-16 06:48:39 +08:00
|
|
|
+ }); // Paper
|
2016-03-25 14:38:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TileEntity tileentity;
|
2018-07-23 01:10:15 +08:00
|
|
|
@@ -1287,6 +1297,16 @@ public class Chunk implements IChunkAccess {
|
2018-07-15 09:53:17 +08:00
|
|
|
return this.E == 8;
|
2017-12-23 05:25:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
+ // Paper start
|
|
|
|
+ public void runOrQueueLightUpdate(Runnable runnable) {
|
|
|
|
+ if (this.world.paperConfig.queueLightUpdates) {
|
|
|
|
+ lightingQueue.add(runnable);
|
|
|
|
+ } else {
|
|
|
|
+ runnable.run();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
+
|
|
|
|
public static enum EnumTileEntityState {
|
|
|
|
|
|
|
|
IMMEDIATE, QUEUED, CHECK;
|
2016-03-25 14:38:38 +08:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java
|
2018-07-22 13:27:46 +08:00
|
|
|
index d23f4e80c..48b484da1 100644
|
2016-03-25 14:38:38 +08:00
|
|
|
--- a/src/main/java/net/minecraft/server/ChunkProviderServer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java
|
2018-07-22 13:27:46 +08:00
|
|
|
@@ -322,6 +322,7 @@ public class ChunkProviderServer implements IChunkProvider {
|
2016-06-23 10:18:41 +08:00
|
|
|
return false;
|
|
|
|
}
|
2016-07-13 12:22:58 +08:00
|
|
|
save = event.isSaveChunk();
|
2016-06-23 10:18:41 +08:00
|
|
|
+ chunk.lightingQueue.processUnload(); // Paper
|
2016-03-25 14:38:38 +08:00
|
|
|
|
2016-06-23 10:18:41 +08:00
|
|
|
// Update neighbor counts
|
|
|
|
for (int x = -2; x < 3; x++) {
|
2016-03-25 14:38:38 +08:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
2018-07-22 13:27:46 +08:00
|
|
|
index ae17796ce..1ac8d61cd 100644
|
2016-03-25 14:38:38 +08:00
|
|
|
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
2018-07-22 13:27:46 +08:00
|
|
|
@@ -864,7 +864,7 @@ public abstract class MinecraftServer implements IAsyncTaskHandler, IMojangStati
|
2018-07-15 09:53:17 +08:00
|
|
|
protected void v() {
|
2016-05-16 06:48:39 +08:00
|
|
|
co.aikar.timings.TimingsManager.FULL_SERVER_TICK.startTiming(); // Paper
|
2017-01-31 12:33:54 +08:00
|
|
|
this.slackActivityAccountant.tickStarted(); // Spigot
|
2018-07-15 09:53:17 +08:00
|
|
|
- long i = SystemUtils.c();
|
|
|
|
+ long i = SystemUtils.c(); long startTime = i; // Paper
|
2016-03-25 14:38:38 +08:00
|
|
|
|
2016-05-16 06:48:39 +08:00
|
|
|
++this.ticks;
|
2018-07-15 09:53:17 +08:00
|
|
|
if (this.S) {
|
2018-07-22 13:27:46 +08:00
|
|
|
@@ -922,6 +922,7 @@ public abstract class MinecraftServer implements IAsyncTaskHandler, IMojangStati
|
2018-07-15 09:53:17 +08:00
|
|
|
this.methodProfiler.e();
|
|
|
|
this.methodProfiler.e();
|
2016-05-16 06:48:39 +08:00
|
|
|
org.spigotmc.WatchdogThread.tick(); // Spigot
|
|
|
|
+ PaperLightingQueue.processQueue(startTime); // Paper
|
2018-07-15 09:53:17 +08:00
|
|
|
this.slackActivityAccountant.tickEnded(l); // Spigot
|
2016-05-16 06:48:39 +08:00
|
|
|
co.aikar.timings.TimingsManager.FULL_SERVER_TICK.stopTiming(); // Paper
|
|
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/PaperLightingQueue.java b/src/main/java/net/minecraft/server/PaperLightingQueue.java
|
|
|
|
new file mode 100644
|
2018-07-04 15:55:24 +08:00
|
|
|
index 000000000..345cd5824
|
2016-05-16 06:48:39 +08:00
|
|
|
--- /dev/null
|
|
|
|
+++ b/src/main/java/net/minecraft/server/PaperLightingQueue.java
|
2017-12-23 05:25:01 +08:00
|
|
|
@@ -0,0 +1,92 @@
|
2016-05-16 06:48:39 +08:00
|
|
|
+package net.minecraft.server;
|
|
|
|
+
|
|
|
|
+import co.aikar.timings.Timing;
|
2017-01-03 03:08:55 +08:00
|
|
|
+import it.unimi.dsi.fastutil.objects.ObjectCollection;
|
|
|
|
+
|
2016-05-16 06:48:39 +08:00
|
|
|
+import java.util.ArrayDeque;
|
2016-03-25 14:38:38 +08:00
|
|
|
+
|
2016-05-16 06:48:39 +08:00
|
|
|
+class PaperLightingQueue {
|
|
|
|
+ private static final long MAX_TIME = (long) (1000000000 / 20 * .95);
|
|
|
|
+ private static int updatesThisTick;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ static void processQueue(long curTime) {
|
|
|
|
+ updatesThisTick = 0;
|
|
|
|
+
|
|
|
|
+ final long startTime = System.nanoTime();
|
|
|
|
+ final long maxTickTime = MAX_TIME - (startTime - curTime);
|
|
|
|
+
|
|
|
|
+ START:
|
|
|
|
+ for (World world : MinecraftServer.getServer().worlds) {
|
|
|
|
+ if (!world.paperConfig.queueLightUpdates) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
2017-01-03 03:08:55 +08:00
|
|
|
+ ObjectCollection<Chunk> loadedChunks = ((WorldServer) world).getChunkProviderServer().chunks.values();
|
|
|
|
+ for (Chunk chunk : loadedChunks.toArray(new Chunk[loadedChunks.size()])) {
|
2016-05-16 06:48:39 +08:00
|
|
|
+ if (chunk.lightingQueue.processQueue(startTime, maxTickTime)) {
|
|
|
|
+ break START;
|
2016-03-25 14:38:38 +08:00
|
|
|
+ }
|
|
|
|
+ }
|
2016-05-16 06:48:39 +08:00
|
|
|
+ }
|
|
|
|
+ }
|
2016-03-25 14:38:38 +08:00
|
|
|
+
|
2016-05-16 06:48:39 +08:00
|
|
|
+ static class LightingQueue extends ArrayDeque<Runnable> {
|
|
|
|
+ final private Chunk chunk;
|
|
|
|
+
|
|
|
|
+ LightingQueue(Chunk chunk) {
|
|
|
|
+ super();
|
|
|
|
+ this.chunk = chunk;
|
2016-03-25 14:38:38 +08:00
|
|
|
+ }
|
|
|
|
+
|
2016-05-16 06:48:39 +08:00
|
|
|
+ /**
|
|
|
|
+ * Processes the lighting queue for this chunk
|
|
|
|
+ *
|
|
|
|
+ * @param startTime If start Time is 0, we will not limit execution time
|
|
|
|
+ * @param maxTickTime Maximum time to spend processing lighting updates
|
|
|
|
+ * @return true to abort processing furthur lighting updates
|
|
|
|
+ */
|
|
|
|
+ private boolean processQueue(long startTime, long maxTickTime) {
|
|
|
|
+ if (this.isEmpty()) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ try (Timing ignored = chunk.world.timings.lightingQueueTimer.startTiming()) {
|
|
|
|
+ Runnable lightUpdate;
|
|
|
|
+ while ((lightUpdate = this.poll()) != null) {
|
|
|
|
+ lightUpdate.run();
|
|
|
|
+ if (startTime > 0 && ++PaperLightingQueue.updatesThisTick % 10 == 0 && PaperLightingQueue.updatesThisTick > 10) {
|
|
|
|
+ if (System.nanoTime() - startTime > maxTickTime) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Flushes lighting updates to unload the chunk
|
|
|
|
+ */
|
|
|
|
+ void processUnload() {
|
|
|
|
+ if (!chunk.world.paperConfig.queueLightUpdates) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ processQueue(0, 0); // No timeout
|
|
|
|
+
|
|
|
|
+ final int radius = 1; // TODO: bitflip, why should this ever be 2?
|
|
|
|
+ for (int x = chunk.locX - radius; x <= chunk.locX + radius; ++x) {
|
|
|
|
+ for (int z = chunk.locZ - radius; z <= chunk.locZ + radius; ++z) {
|
|
|
|
+ if (x == chunk.locX && z == chunk.locZ) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Chunk neighbor = MCUtil.getLoadedChunkWithoutMarkingActive(chunk.world, x, z);
|
|
|
|
+ if (neighbor != null) {
|
|
|
|
+ neighbor.lightingQueue.processQueue(0, 0); // No timeout
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
2016-03-25 14:38:38 +08:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
|
2018-07-22 13:27:46 +08:00
|
|
|
index bfe09a205..c40ecbc0c 100644
|
2016-03-25 14:38:38 +08:00
|
|
|
--- a/src/main/java/net/minecraft/server/World.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/World.java
|
2018-07-15 09:53:17 +08:00
|
|
|
@@ -325,7 +325,7 @@ public abstract class World implements GeneratorAccess, IIBlockAccess, AutoClose
|
|
|
|
|
|
|
|
if (iblockdata2.b(this, blockposition) != iblockdata1.b(this, blockposition) || iblockdata2.e() != iblockdata1.e()) {
|
2016-03-25 14:38:38 +08:00
|
|
|
this.methodProfiler.a("checkLight");
|
2018-07-15 09:53:17 +08:00
|
|
|
- this.r(blockposition);
|
|
|
|
+ chunk.runOrQueueLightUpdate(() -> this.r(blockposition)); // Paper - Queue light update
|
|
|
|
this.methodProfiler.e();
|
2016-03-25 14:38:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
--
|
2018-07-04 15:55:24 +08:00
|
|
|
2.18.0
|
2016-03-25 14:38:38 +08:00
|
|
|
|