2017-04-22 08:16:45 +02:00
|
|
|
From ddc58c0259cad56358f0e79c327658a407436af5 Mon Sep 17 00:00:00 2001
|
2016-03-25 07:38:38 +01:00
|
|
|
From: Byteflux <byte@byteflux.net>
|
|
|
|
Date: Wed, 2 Mar 2016 00:52:31 -0600
|
|
|
|
Subject: [PATCH] Lighting Queue
|
|
|
|
|
2016-07-16 00:36:53 +02:00
|
|
|
This provides option to queue lighting updates to ensure they do not cause the server lag
|
2016-03-25 07:38:38 +01:00
|
|
|
|
2016-05-16 00:48:39 +02:00
|
|
|
diff --git a/src/main/java/co/aikar/timings/WorldTimingsHandler.java b/src/main/java/co/aikar/timings/WorldTimingsHandler.java
|
2017-01-02 20:08:55 +01:00
|
|
|
index e7789117b..f90f5bf84 100644
|
2016-05-16 00:48:39 +02:00
|
|
|
--- a/src/main/java/co/aikar/timings/WorldTimingsHandler.java
|
|
|
|
+++ b/src/main/java/co/aikar/timings/WorldTimingsHandler.java
|
2016-10-21 22:42:49 +02:00
|
|
|
@@ -50,6 +50,8 @@ public class WorldTimingsHandler {
|
|
|
|
public final Timing chunkSaveNop;
|
|
|
|
public final Timing chunkSaveData;
|
2016-03-25 07:38:38 +01:00
|
|
|
|
2016-05-16 00:48:39 +02:00
|
|
|
+ public final Timing lightingQueueTimer;
|
|
|
|
+
|
|
|
|
public WorldTimingsHandler(World server) {
|
|
|
|
String name = server.worldData.getName() +" - ";
|
|
|
|
|
2016-10-21 22:42:49 +02:00
|
|
|
@@ -97,5 +99,7 @@ public class WorldTimingsHandler {
|
2016-05-16 00:48:39 +02:00
|
|
|
tracker2 = Timings.ofSafe(name + "tracker stage 2");
|
|
|
|
doTick = Timings.ofSafe(name + "doTick");
|
|
|
|
tickEntities = Timings.ofSafe(name + "tickEntities");
|
|
|
|
+
|
|
|
|
+ lightingQueueTimer = Timings.ofSafe(name + "Lighting Queue");
|
|
|
|
}
|
|
|
|
}
|
2016-03-25 07:38:38 +01:00
|
|
|
diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
|
2017-03-25 04:18:58 +01:00
|
|
|
index e524a464f..fd606ee14 100644
|
2016-03-25 07:38:38 +01:00
|
|
|
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
|
|
|
|
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
|
2017-03-25 04:18:58 +01:00
|
|
|
@@ -143,4 +143,10 @@ public class PaperWorldConfig {
|
2016-03-31 02:50:23 +02:00
|
|
|
netherVoidTopDamage = getBoolean( "nether-ceiling-void-damage", false );
|
|
|
|
log("Top of the nether void damage: " + netherVoidTopDamage);
|
2016-03-25 07:38:38 +01:00
|
|
|
}
|
2016-03-31 02:50:23 +02:00
|
|
|
+
|
2016-03-25 07:38:38 +01: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
|
2017-01-02 20:08:55 +01:00
|
|
|
index 1c0108ef1..b80f95159 100644
|
2016-03-25 07:38:38 +01:00
|
|
|
--- a/src/main/java/net/minecraft/server/Chunk.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/Chunk.java
|
2016-05-16 00:48:39 +02:00
|
|
|
@@ -33,6 +33,7 @@ public class Chunk {
|
|
|
|
private boolean m;
|
|
|
|
public final Map<BlockPosition, TileEntity> tileEntities;
|
|
|
|
public final List<Entity>[] entitySlices; // Spigot
|
|
|
|
+ final PaperLightingQueue.LightingQueue lightingQueue = new PaperLightingQueue.LightingQueue(this); // Paper
|
|
|
|
private boolean done;
|
|
|
|
private boolean lit;
|
|
|
|
private boolean r;
|
2016-06-23 04:18:41 +02:00
|
|
|
@@ -229,6 +230,13 @@ public class Chunk {
|
2016-03-25 07:38:38 +01:00
|
|
|
private void h(boolean flag) {
|
|
|
|
this.world.methodProfiler.a("recheckGaps");
|
|
|
|
if (this.world.areChunksLoaded(new BlockPosition(this.locX * 16 + 8, 0, this.locZ * 16 + 8), 16)) {
|
2016-05-16 00:48:39 +02:00
|
|
|
+ lightingQueue.add(() -> recheckGaps(flag)); // Paper - Queue light update
|
2016-03-25 07:38:38 +01:00
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void recheckGaps(boolean flag) {
|
|
|
|
+ if (true) {
|
|
|
|
+ // Paper end
|
|
|
|
for (int i = 0; i < 16; ++i) {
|
|
|
|
for (int j = 0; j < 16; ++j) {
|
2016-05-12 04:07:46 +02:00
|
|
|
if (this.i[i + j * 16]) {
|
2016-06-23 04:18:41 +02:00
|
|
|
@@ -481,7 +489,7 @@ public class Chunk {
|
2016-03-25 07:38:38 +01:00
|
|
|
} else {
|
|
|
|
if (flag) {
|
|
|
|
this.initLighting();
|
|
|
|
- } else {
|
2016-05-16 00:48:39 +02:00
|
|
|
+ } else { lightingQueue.add(() -> { // Paper - Queue light update
|
2016-03-25 07:38:38 +01:00
|
|
|
int j1 = iblockdata.c();
|
|
|
|
int k1 = iblockdata1.c();
|
|
|
|
|
2016-06-23 04:18:41 +02:00
|
|
|
@@ -496,6 +504,7 @@ public class Chunk {
|
2016-03-25 07:38:38 +01:00
|
|
|
if (j1 != k1 && (j1 < k1 || this.getBrightness(EnumSkyBlock.SKY, blockposition) > 0 || this.getBrightness(EnumSkyBlock.BLOCK, blockposition) > 0)) {
|
|
|
|
this.d(i, k);
|
|
|
|
}
|
2016-05-16 00:48:39 +02:00
|
|
|
+ }); // Paper
|
2016-03-25 07:38:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TileEntity tileentity;
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java
|
2017-02-04 10:59:44 +01:00
|
|
|
index 3ba489d4f..f7f2d12cf 100644
|
2016-03-25 07:38:38 +01:00
|
|
|
--- a/src/main/java/net/minecraft/server/ChunkProviderServer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java
|
2017-02-04 10:59:44 +01:00
|
|
|
@@ -295,6 +295,7 @@ public class ChunkProviderServer implements IChunkProvider {
|
2016-06-23 04:18:41 +02:00
|
|
|
return false;
|
|
|
|
}
|
2016-07-13 06:22:58 +02:00
|
|
|
save = event.isSaveChunk();
|
2016-06-23 04:18:41 +02:00
|
|
|
+ chunk.lightingQueue.processUnload(); // Paper
|
2016-03-25 07:38:38 +01:00
|
|
|
|
2016-06-23 04:18:41 +02:00
|
|
|
// Update neighbor counts
|
|
|
|
for (int x = -2; x < 3; x++) {
|
2016-03-25 07:38:38 +01:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
2017-04-22 08:16:45 +02:00
|
|
|
index c4497aaa6..ca0ff4d30 100644
|
2016-03-25 07:38:38 +01:00
|
|
|
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
2017-01-31 05:33:54 +01:00
|
|
|
@@ -721,7 +721,7 @@ public abstract class MinecraftServer implements Runnable, ICommandListener, IAs
|
2016-05-16 00:48:39 +02:00
|
|
|
protected void C() throws ExceptionWorldConflict { // CraftBukkit - added throws
|
|
|
|
co.aikar.timings.TimingsManager.FULL_SERVER_TICK.startTiming(); // Paper
|
2017-01-31 05:33:54 +01:00
|
|
|
this.slackActivityAccountant.tickStarted(); // Spigot
|
2016-05-16 00:48:39 +02:00
|
|
|
- long i = System.nanoTime();
|
|
|
|
+ long i = System.nanoTime(); long startTime = i; // Paper
|
2016-03-25 07:38:38 +01:00
|
|
|
|
2016-05-16 00:48:39 +02:00
|
|
|
++this.ticks;
|
2016-11-17 03:23:38 +01:00
|
|
|
if (this.T) {
|
2017-01-31 05:33:54 +01:00
|
|
|
@@ -782,6 +782,7 @@ public abstract class MinecraftServer implements Runnable, ICommandListener, IAs
|
2016-03-25 07:38:38 +01:00
|
|
|
this.methodProfiler.b();
|
2016-04-30 03:23:40 +02:00
|
|
|
|
2016-05-16 00:48:39 +02:00
|
|
|
org.spigotmc.WatchdogThread.tick(); // Spigot
|
|
|
|
+ PaperLightingQueue.processQueue(startTime); // Paper
|
2017-01-31 05:33:54 +01:00
|
|
|
this.slackActivityAccountant.tickEnded(tickNanos); // Spigot
|
2016-05-16 00:48:39 +02: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
|
2017-01-02 20:08:55 +01:00
|
|
|
index 000000000..d8d3e1efd
|
2016-05-16 00:48:39 +02:00
|
|
|
--- /dev/null
|
|
|
|
+++ b/src/main/java/net/minecraft/server/PaperLightingQueue.java
|
2017-01-02 20:08:55 +01:00
|
|
|
@@ -0,0 +1,101 @@
|
2016-05-16 00:48:39 +02:00
|
|
|
+package net.minecraft.server;
|
|
|
|
+
|
|
|
|
+import co.aikar.timings.Timing;
|
2017-01-02 20:08:55 +01:00
|
|
|
+import it.unimi.dsi.fastutil.objects.ObjectCollection;
|
|
|
|
+
|
2016-05-16 00:48:39 +02:00
|
|
|
+import java.util.ArrayDeque;
|
2016-03-25 07:38:38 +01:00
|
|
|
+
|
2016-05-16 00:48:39 +02: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-02 20:08:55 +01:00
|
|
|
+ ObjectCollection<Chunk> loadedChunks = ((WorldServer) world).getChunkProviderServer().chunks.values();
|
|
|
|
+ for (Chunk chunk : loadedChunks.toArray(new Chunk[loadedChunks.size()])) {
|
2016-05-16 00:48:39 +02:00
|
|
|
+ if (chunk.lightingQueue.processQueue(startTime, maxTickTime)) {
|
|
|
|
+ break START;
|
2016-03-25 07:38:38 +01:00
|
|
|
+ }
|
|
|
|
+ }
|
2016-05-16 00:48:39 +02:00
|
|
|
+ }
|
|
|
|
+ }
|
2016-03-25 07:38:38 +01:00
|
|
|
+
|
2016-05-16 00:48:39 +02:00
|
|
|
+ static class LightingQueue extends ArrayDeque<Runnable> {
|
|
|
|
+ final private Chunk chunk;
|
|
|
|
+
|
|
|
|
+ LightingQueue(Chunk chunk) {
|
|
|
|
+ super();
|
|
|
|
+ this.chunk = chunk;
|
2016-03-25 07:38:38 +01:00
|
|
|
+ }
|
|
|
|
+
|
2016-05-16 00:48:39 +02:00
|
|
|
+ @Override
|
|
|
|
+ public boolean add(Runnable runnable) {
|
|
|
|
+ if (chunk.world.paperConfig.queueLightUpdates) {
|
|
|
|
+ return super.add(runnable);
|
|
|
|
+ }
|
|
|
|
+ runnable.run();
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 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 07:38:38 +01:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
|
2017-03-25 04:18:58 +01:00
|
|
|
index 632d5c760..e6e85e7a8 100644
|
2016-03-25 07:38:38 +01:00
|
|
|
--- a/src/main/java/net/minecraft/server/World.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/World.java
|
2016-11-17 03:23:38 +01:00
|
|
|
@@ -387,7 +387,7 @@ public abstract class World implements IBlockAccess {
|
2016-03-25 07:38:38 +01:00
|
|
|
} else {
|
|
|
|
if (iblockdata.c() != iblockdata1.c() || iblockdata.d() != iblockdata1.d()) {
|
|
|
|
this.methodProfiler.a("checkLight");
|
|
|
|
- this.w(blockposition);
|
2016-05-16 00:48:39 +02:00
|
|
|
+ chunk.lightingQueue.add(() -> this.w(blockposition)); // Paper - Queue light update
|
2016-03-25 07:38:38 +01:00
|
|
|
this.methodProfiler.b();
|
|
|
|
}
|
|
|
|
|
|
|
|
--
|
2017-04-22 08:16:45 +02:00
|
|
|
2.12.2
|
2016-03-25 07:38:38 +01:00
|
|
|
|