2016-03-08 22:23:28 +00:00
|
|
|
From 712fee2a1cf2121a90ca3aeb86ca6a9213527da9 Mon Sep 17 00:00:00 2001
|
2015-07-01 07:27:58 +00:00
|
|
|
From: Byteflux <byte@byteflux.net>
|
2016-02-29 23:09:49 +00:00
|
|
|
Date: Wed, 2 Mar 2016 00:52:31 -0600
|
2015-04-18 08:30:12 +00:00
|
|
|
Subject: [PATCH] Configurable async light updates
|
|
|
|
|
|
|
|
|
2016-02-29 23:09:49 +00:00
|
|
|
diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
|
2016-03-08 22:23:28 +00:00
|
|
|
index 28e3e3c..5504cfe 100644
|
2016-02-29 23:09:49 +00:00
|
|
|
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
|
|
|
|
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
|
|
|
|
@@ -158,4 +158,9 @@ public class PaperWorldConfig {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
+ public boolean useAsyncLighting;
|
|
|
|
+ private void useAsyncLighting() {
|
2016-03-08 22:23:28 +00:00
|
|
|
+ useAsyncLighting = false; //getBoolean( "use-async-lighting", false );
|
2016-02-29 23:09:49 +00:00
|
|
|
+ log("World async lighting: " + useAsyncLighting);
|
|
|
|
+ }
|
|
|
|
}
|
2015-07-01 07:27:58 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java
|
2016-03-06 20:59:17 +00:00
|
|
|
index cde4124..5df38be 100644
|
2015-07-01 07:27:58 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/Chunk.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/Chunk.java
|
|
|
|
@@ -11,6 +11,8 @@ import java.util.Map;
|
|
|
|
import java.util.Random;
|
|
|
|
import java.util.concurrent.Callable;
|
|
|
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
2016-02-29 23:09:49 +00:00
|
|
|
+import java.util.concurrent.atomic.AtomicInteger; // Paper
|
2015-07-01 07:27:58 +00:00
|
|
|
+
|
|
|
|
import org.apache.logging.log4j.LogManager;
|
|
|
|
import org.apache.logging.log4j.Logger;
|
|
|
|
|
2016-02-29 23:09:49 +00:00
|
|
|
@@ -44,6 +46,10 @@ public class Chunk {
|
|
|
|
private int w;
|
|
|
|
private ConcurrentLinkedQueue<BlockPosition> x;
|
2015-07-01 07:27:58 +00:00
|
|
|
protected gnu.trove.map.hash.TObjectIntHashMap<Class> entityCount = new gnu.trove.map.hash.TObjectIntHashMap<Class>(); // Spigot
|
2016-02-29 23:09:49 +00:00
|
|
|
+ // Paper start - Asynchronous light updates
|
2015-07-01 07:27:58 +00:00
|
|
|
+ public AtomicInteger pendingLightUpdates = new AtomicInteger();
|
|
|
|
+ public long lightUpdateTime;
|
2016-02-29 23:09:49 +00:00
|
|
|
+ // Paper end
|
2015-07-01 07:27:58 +00:00
|
|
|
|
|
|
|
// CraftBukkit start - Neighbor loaded cache for chunk lighting and entity ticking
|
|
|
|
private int neighbors = 0x1 << 12;
|
2016-02-29 23:09:49 +00:00
|
|
|
@@ -278,7 +284,7 @@ public class Chunk {
|
2015-07-01 07:27:58 +00:00
|
|
|
private void a(int i, int j, int k, int l) {
|
|
|
|
if (l > k && this.world.areChunksLoaded(new BlockPosition(i, 0, j), 16)) {
|
|
|
|
for (int i1 = k; i1 < l; ++i1) {
|
|
|
|
- this.world.c(EnumSkyBlock.SKY, new BlockPosition(i, i1, j));
|
2016-02-29 23:09:49 +00:00
|
|
|
+ this.world.updateLight(EnumSkyBlock.SKY, new BlockPosition(i, i1, j));
|
2015-07-01 07:27:58 +00:00
|
|
|
}
|
|
|
|
|
2016-02-29 23:09:49 +00:00
|
|
|
this.r = true;
|
|
|
|
@@ -991,7 +997,7 @@ public class Chunk {
|
2015-08-04 22:44:54 +00:00
|
|
|
|
|
|
|
public void b(boolean flag) {
|
2016-02-29 23:09:49 +00:00
|
|
|
if (this.l && !this.world.worldProvider.m() && !flag) {
|
2015-08-04 22:44:54 +00:00
|
|
|
- this.h(this.world.isClientSide);
|
2016-02-29 23:09:49 +00:00
|
|
|
+ this.recheckGaps(this.world.isClientSide); // Paper - Asynchronous lighting updates
|
2015-08-04 22:44:54 +00:00
|
|
|
}
|
|
|
|
|
2016-02-29 23:09:49 +00:00
|
|
|
this.q = true;
|
|
|
|
@@ -1012,6 +1018,23 @@ public class Chunk {
|
2015-08-04 22:44:54 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
2016-02-29 23:09:49 +00:00
|
|
|
+ * Paper- Recheck gaps asynchronously
|
2015-08-04 22:44:54 +00:00
|
|
|
+ */
|
|
|
|
+ public void recheckGaps(final boolean isClientSide) {
|
2016-02-29 23:09:49 +00:00
|
|
|
+ if (!world.paperConfig.useAsyncLighting) {
|
|
|
|
+ this.h(this.world.isClientSide);
|
2015-08-04 22:44:54 +00:00
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ world.lightingExecutor.submit(new Runnable() {
|
|
|
|
+ @Override
|
|
|
|
+ public void run() {
|
|
|
|
+ Chunk.this.h(isClientSide);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
public boolean isReady() {
|
|
|
|
// Spigot Start
|
|
|
|
/*
|
2015-07-01 07:27:58 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java
|
2016-03-06 20:59:17 +00:00
|
|
|
index 83857a6..49288c9 100644
|
2015-07-01 07:27:58 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/ChunkProviderServer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java
|
2016-02-29 23:09:49 +00:00
|
|
|
@@ -46,6 +46,12 @@ public class ChunkProviderServer implements IChunkProvider {
|
2015-07-01 07:27:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void queueUnload(int i, int j) {
|
2016-02-29 23:09:49 +00:00
|
|
|
+ // Paper start - Asynchronous lighting updates
|
2015-07-01 07:27:58 +00:00
|
|
|
+ Chunk chunk = chunks.get(LongHash.toLong(i, j));
|
2016-02-29 23:09:49 +00:00
|
|
|
+ if (chunk != null && chunk.world.paperConfig.useAsyncLighting && (chunk.pendingLightUpdates.get() > 0 || chunk.world.getTime() - chunk.lightUpdateTime < 20)) {
|
2015-07-01 07:27:58 +00:00
|
|
|
+ return;
|
|
|
|
+ }
|
2016-02-29 23:09:49 +00:00
|
|
|
+ // Paper end
|
|
|
|
if (this.world.worldProvider.c(i, j)) {
|
|
|
|
// CraftBukkit start
|
|
|
|
this.unloadQueue.add(i, j);
|
2015-04-18 08:30:12 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
|
2016-03-06 20:59:17 +00:00
|
|
|
index 0b5c9fe..aa2c65e 100644
|
2015-04-18 08:30:12 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/World.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/World.java
|
2016-02-29 23:09:49 +00:00
|
|
|
@@ -29,6 +29,12 @@ import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
|
|
|
|
import org.bukkit.generator.ChunkGenerator;
|
|
|
|
// CraftBukkit end
|
2015-04-18 08:30:12 +00:00
|
|
|
|
2016-02-29 23:09:49 +00:00
|
|
|
+// Paper start
|
2015-04-18 08:30:12 +00:00
|
|
|
+import java.util.concurrent.ExecutorService;
|
|
|
|
+import java.util.concurrent.Executors;
|
|
|
|
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
2016-02-29 23:09:49 +00:00
|
|
|
+// Paper end
|
2015-04-18 08:30:12 +00:00
|
|
|
+
|
2016-02-29 23:09:49 +00:00
|
|
|
public abstract class World implements IBlockAccess {
|
2015-05-18 23:41:57 +00:00
|
|
|
|
2016-02-29 23:09:49 +00:00
|
|
|
private int a = 63;
|
|
|
|
@@ -134,6 +140,7 @@ public abstract class World implements IBlockAccess {
|
2015-09-13 04:29:23 +00:00
|
|
|
private org.spigotmc.TickLimiter entityLimiter;
|
|
|
|
private org.spigotmc.TickLimiter tileLimiter;
|
2015-07-01 07:27:58 +00:00
|
|
|
private int tileTickPosition;
|
2016-02-29 23:09:49 +00:00
|
|
|
+ public ExecutorService lightingExecutor = Executors.newSingleThreadExecutor(new ThreadFactoryBuilder().setNameFormat("Paper - Lighting Thread").build()); // Paper - Asynchronous lighting updates
|
2015-07-01 07:27:58 +00:00
|
|
|
|
2016-02-29 23:09:49 +00:00
|
|
|
public CraftWorld getWorld() {
|
|
|
|
return this.world;
|
2016-03-06 20:59:17 +00:00
|
|
|
@@ -476,7 +483,7 @@ public abstract class World implements IBlockAccess {
|
2015-07-01 07:27:58 +00:00
|
|
|
|
2016-02-29 23:09:49 +00:00
|
|
|
if (!this.worldProvider.m()) {
|
2015-07-01 07:27:58 +00:00
|
|
|
for (i1 = k; i1 <= l; ++i1) {
|
|
|
|
- this.c(EnumSkyBlock.SKY, new BlockPosition(i, i1, j));
|
2016-02-29 23:09:49 +00:00
|
|
|
+ this.updateLight(EnumSkyBlock.SKY, new BlockPosition(i, i1, j)); // Paper - Asynchronous lighting updates
|
2015-07-01 07:27:58 +00:00
|
|
|
}
|
2015-04-18 08:30:12 +00:00
|
|
|
}
|
|
|
|
|
2016-03-06 20:59:17 +00:00
|
|
|
@@ -2244,10 +2251,10 @@ public abstract class World implements IBlockAccess {
|
2015-07-01 07:27:58 +00:00
|
|
|
boolean flag = false;
|
|
|
|
|
2016-02-29 23:09:49 +00:00
|
|
|
if (!this.worldProvider.m()) {
|
2015-07-01 07:27:58 +00:00
|
|
|
- flag |= this.c(EnumSkyBlock.SKY, blockposition);
|
2016-02-29 23:09:49 +00:00
|
|
|
+ flag |= this.updateLight(EnumSkyBlock.SKY, blockposition); // Paper - Asynchronous lighting updates
|
2015-04-18 08:30:12 +00:00
|
|
|
}
|
|
|
|
|
2015-07-01 07:27:58 +00:00
|
|
|
- flag |= this.c(EnumSkyBlock.BLOCK, blockposition);
|
2016-02-29 23:09:49 +00:00
|
|
|
+ flag |= this.updateLight(EnumSkyBlock.BLOCK, blockposition); // Paper - Asynchronous lighting updates
|
2015-07-01 07:27:58 +00:00
|
|
|
return flag;
|
2015-04-18 08:30:12 +00:00
|
|
|
}
|
|
|
|
|
2016-03-06 20:59:17 +00:00
|
|
|
@@ -2297,10 +2304,15 @@ public abstract class World implements IBlockAccess {
|
2015-04-18 08:30:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-29 23:09:49 +00:00
|
|
|
+ // Paper start - Asynchronous lighting updates
|
|
|
|
public boolean c(EnumSkyBlock enumskyblock, BlockPosition blockposition) {
|
|
|
|
+ return this.c(enumskyblock, blockposition, null, null);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public boolean c(EnumSkyBlock enumskyblock, BlockPosition blockposition, Chunk chunk, List<Chunk> neighbors) { // Paper
|
2015-07-01 07:27:58 +00:00
|
|
|
// CraftBukkit start - Use neighbor cache instead of looking up
|
2015-04-18 08:30:12 +00:00
|
|
|
- Chunk chunk = this.getChunkIfLoaded(blockposition.getX() >> 4, blockposition.getZ() >> 4);
|
|
|
|
- if (chunk == null || !chunk.areNeighborsLoaded(1) /*!this.areChunksLoaded(blockposition, 17, false)*/) {
|
2015-07-01 07:27:58 +00:00
|
|
|
+ //Chunk chunk = this.getChunkIfLoaded(blockposition.getX() >> 4, blockposition.getZ() >> 4);
|
|
|
|
+ if (chunk == null /*|| !chunk.areNeighborsLoaded(1)*/ /*!this.areChunksLoaded(blockposition, 17, false)*/) {
|
|
|
|
// CraftBukkit end
|
|
|
|
return false;
|
|
|
|
} else {
|
2016-03-06 20:59:17 +00:00
|
|
|
@@ -2371,6 +2383,17 @@ public abstract class World implements IBlockAccess {
|
2016-02-29 23:09:49 +00:00
|
|
|
i = 0;
|
2015-07-01 07:27:58 +00:00
|
|
|
}
|
2015-04-18 08:30:12 +00:00
|
|
|
|
2016-02-29 23:09:49 +00:00
|
|
|
+ // Paper start - Asynchronous light updates
|
|
|
|
+ if (chunk.world.paperConfig.useAsyncLighting) {
|
2015-07-01 07:27:58 +00:00
|
|
|
+ chunk.pendingLightUpdates.decrementAndGet();
|
|
|
|
+ if (neighbors != null) {
|
|
|
|
+ for (Chunk neighbor : neighbors) {
|
|
|
|
+ neighbor.pendingLightUpdates.decrementAndGet();
|
2015-04-18 08:30:12 +00:00
|
|
|
+ }
|
2015-07-01 07:27:58 +00:00
|
|
|
+ }
|
|
|
|
+ }
|
2016-02-29 23:09:49 +00:00
|
|
|
+ // Paper end
|
|
|
|
+
|
2015-07-01 07:27:58 +00:00
|
|
|
this.methodProfiler.b();
|
2016-02-29 23:09:49 +00:00
|
|
|
this.methodProfiler.a("checkedPosition < toCheckCount");
|
|
|
|
|
2016-03-06 20:59:17 +00:00
|
|
|
@@ -2425,6 +2448,52 @@ public abstract class World implements IBlockAccess {
|
2015-07-01 07:27:58 +00:00
|
|
|
}
|
|
|
|
}
|
2015-04-18 08:30:12 +00:00
|
|
|
|
2015-07-01 07:27:58 +00:00
|
|
|
+ /**
|
2016-02-29 23:09:49 +00:00
|
|
|
+ * Paper - Asynchronous lighting updates
|
2015-07-01 07:27:58 +00:00
|
|
|
+ */
|
|
|
|
+ public boolean updateLight(final EnumSkyBlock enumskyblock, final BlockPosition position) {
|
|
|
|
+ int x = position.getX();
|
|
|
|
+ int z = position.getZ();
|
|
|
|
+ final Chunk chunk = this.getChunkIfLoaded(x >> 4, z >> 4);
|
2015-07-10 10:20:10 +00:00
|
|
|
+ if (chunk == null || !chunk.areNeighborsLoaded(1)) {
|
2015-07-01 07:27:58 +00:00
|
|
|
+ return false;
|
|
|
|
+ }
|
2015-04-18 08:30:12 +00:00
|
|
|
+
|
2016-02-29 23:09:49 +00:00
|
|
|
+ if (!chunk.world.paperConfig.useAsyncLighting) {
|
2015-07-01 07:27:58 +00:00
|
|
|
+ return this.c(enumskyblock, position, chunk, null);
|
|
|
|
+ }
|
2015-04-18 08:30:12 +00:00
|
|
|
+
|
2015-07-01 07:27:58 +00:00
|
|
|
+ chunk.pendingLightUpdates.incrementAndGet();
|
|
|
|
+ chunk.lightUpdateTime = chunk.world.getTime();
|
2015-04-18 08:30:12 +00:00
|
|
|
+
|
2015-07-01 07:27:58 +00:00
|
|
|
+ final List<Chunk> neighbors = new ArrayList<Chunk>();
|
2016-02-29 23:09:49 +00:00
|
|
|
+
|
2015-07-05 00:42:28 +00:00
|
|
|
+ for (int cx = (x >> 4) - 1; cx <= (x >> 4) + 1; ++cx) {
|
|
|
|
+ for (int cz = (z >> 4) - 1; cz <= (z >> 4) + 1; ++cz) {
|
2015-07-15 09:01:49 +00:00
|
|
|
+ if (cx != x >> 4 && cz != z >> 4) {
|
|
|
|
+ Chunk neighbor = this.getChunkIfLoaded(cx, cz);
|
|
|
|
+ if (neighbor != null) {
|
2015-07-01 07:27:58 +00:00
|
|
|
+ neighbor.pendingLightUpdates.incrementAndGet();
|
|
|
|
+ neighbor.lightUpdateTime = chunk.world.getTime();
|
|
|
|
+ neighbors.add(neighbor);
|
|
|
|
+ }
|
|
|
|
+ }
|
2015-04-18 08:30:12 +00:00
|
|
|
+ }
|
2015-07-01 07:27:58 +00:00
|
|
|
+ }
|
|
|
|
+
|
2015-08-04 22:44:54 +00:00
|
|
|
+ if (!Bukkit.isPrimaryThread()) {
|
|
|
|
+ return this.c(enumskyblock, position, chunk, neighbors);
|
|
|
|
+ }
|
|
|
|
+
|
2015-07-01 07:27:58 +00:00
|
|
|
+ lightingExecutor.submit(new Runnable() {
|
|
|
|
+ @Override
|
|
|
|
+ public void run() {
|
|
|
|
+ World.this.c(enumskyblock, position, chunk, neighbors);
|
|
|
|
+ }
|
|
|
|
+ });
|
2015-04-18 08:30:12 +00:00
|
|
|
+ return true;
|
2015-07-01 07:27:58 +00:00
|
|
|
+ }
|
|
|
|
+
|
2015-04-18 08:30:12 +00:00
|
|
|
public boolean a(boolean flag) {
|
|
|
|
return false;
|
2015-07-01 07:27:58 +00:00
|
|
|
}
|
2015-04-18 08:30:12 +00:00
|
|
|
--
|
2016-02-29 23:09:49 +00:00
|
|
|
2.7.2
|
2015-04-18 08:30:12 +00:00
|
|
|
|