2015-10-17 04:43:03 +02:00
|
|
|
From bd3df799507c4cf52bfa005a06acec8010a5dfea Mon Sep 17 00:00:00 2001
|
2015-07-01 09:27:58 +02:00
|
|
|
From: Byteflux <byte@byteflux.net>
|
|
|
|
Date: Wed, 1 Jul 2015 00:18:10 -0700
|
2015-04-18 10:30:12 +02:00
|
|
|
Subject: [PATCH] Configurable async light updates
|
|
|
|
|
|
|
|
|
2015-07-01 09:27:58 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java
|
2015-08-05 00:44:54 +02:00
|
|
|
index 7242d45..5a3b22a 100644
|
2015-07-01 09:27:58 +02: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;
|
|
|
|
+import java.util.concurrent.atomic.AtomicInteger; // PaperSpigot
|
|
|
|
+
|
|
|
|
import org.apache.logging.log4j.LogManager;
|
|
|
|
import org.apache.logging.log4j.Logger;
|
|
|
|
|
|
|
|
@@ -43,6 +45,10 @@ public class Chunk {
|
|
|
|
private int v;
|
|
|
|
private ConcurrentLinkedQueue<BlockPosition> w;
|
|
|
|
protected gnu.trove.map.hash.TObjectIntHashMap<Class> entityCount = new gnu.trove.map.hash.TObjectIntHashMap<Class>(); // Spigot
|
|
|
|
+ // PaperSpigot start - Asynchronous light updates
|
|
|
|
+ public AtomicInteger pendingLightUpdates = new AtomicInteger();
|
|
|
|
+ public long lightUpdateTime;
|
|
|
|
+ // PaperSpigot end
|
|
|
|
|
|
|
|
// CraftBukkit start - Neighbor loaded cache for chunk lighting and entity ticking
|
|
|
|
private int neighbors = 0x1 << 12;
|
|
|
|
@@ -274,7 +280,7 @@ public class Chunk {
|
|
|
|
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));
|
|
|
|
+ this.world.updateLight(EnumSkyBlock.SKY, new BlockPosition(i, i1, j)); // PaperSpigot - Asynchronous lighting updates
|
|
|
|
}
|
|
|
|
|
|
|
|
this.q = true;
|
2015-08-05 00:44:54 +02:00
|
|
|
@@ -1044,7 +1050,7 @@ public class Chunk {
|
|
|
|
|
|
|
|
public void b(boolean flag) {
|
|
|
|
if (this.k && !this.world.worldProvider.o() && !flag) {
|
|
|
|
- this.h(this.world.isClientSide);
|
|
|
|
+ this.recheckGaps(this.world.isClientSide); // PaperSpigot - Asynchronous lighting updates
|
|
|
|
}
|
|
|
|
|
|
|
|
this.p = true;
|
|
|
|
@@ -1065,6 +1071,23 @@ public class Chunk {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * PaperSpigot - Recheck gaps asynchronously.
|
|
|
|
+ */
|
|
|
|
+ public void recheckGaps(final boolean isClientSide) {
|
|
|
|
+ if (!world.paperSpigotConfig.useAsyncLighting) {
|
|
|
|
+ this.h(isClientSide);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ world.lightingExecutor.submit(new Runnable() {
|
|
|
|
+ @Override
|
|
|
|
+ public void run() {
|
|
|
|
+ Chunk.this.h(isClientSide);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
public boolean isReady() {
|
|
|
|
// Spigot Start
|
|
|
|
/*
|
2015-07-01 09:27:58 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java
|
|
|
|
index 975d666..ae0f276 100644
|
|
|
|
--- a/src/main/java/net/minecraft/server/ChunkProviderServer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java
|
|
|
|
@@ -53,6 +53,12 @@ public class ChunkProviderServer implements IChunkProvider {
|
|
|
|
}
|
|
|
|
|
|
|
|
public void queueUnload(int i, int j) {
|
|
|
|
+ // PaperSpigot start - Asynchronous lighting updates
|
|
|
|
+ Chunk chunk = chunks.get(LongHash.toLong(i, j));
|
|
|
|
+ if (chunk != null && chunk.world.paperSpigotConfig.useAsyncLighting && (chunk.pendingLightUpdates.get() > 0 || chunk.world.getTime() - chunk.lightUpdateTime < 20)) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ // PaperSpigot end
|
|
|
|
if (this.world.worldProvider.e()) {
|
|
|
|
if (!this.world.c(i, j)) {
|
|
|
|
// CraftBukkit start
|
2015-04-18 10:30:12 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
|
2015-10-17 04:43:03 +02:00
|
|
|
index c50536e..82c43e3 100644
|
2015-04-18 10:30:12 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/World.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/World.java
|
2015-05-19 01:41:57 +02:00
|
|
|
@@ -18,6 +18,12 @@ import org.bukkit.generator.ChunkGenerator;
|
|
|
|
import java.util.*;
|
2015-04-18 10:30:12 +02:00
|
|
|
import java.util.concurrent.Callable;
|
|
|
|
|
|
|
|
+// PaperSpigot start
|
|
|
|
+import java.util.concurrent.ExecutorService;
|
|
|
|
+import java.util.concurrent.Executors;
|
|
|
|
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
|
|
|
+// PaperSpigot end
|
|
|
|
+
|
|
|
|
// CraftBukkit start
|
2015-05-19 01:41:57 +02:00
|
|
|
// CraftBukkit end
|
|
|
|
|
2015-10-17 04:43:03 +02:00
|
|
|
@@ -128,6 +134,7 @@ public abstract class World implements IBlockAccess {
|
2015-09-13 06:29:23 +02:00
|
|
|
private org.spigotmc.TickLimiter entityLimiter;
|
|
|
|
private org.spigotmc.TickLimiter tileLimiter;
|
2015-07-01 09:27:58 +02:00
|
|
|
private int tileTickPosition;
|
2015-08-07 06:44:03 +02:00
|
|
|
+ public ExecutorService lightingExecutor = Executors.newSingleThreadExecutor(new ThreadFactoryBuilder().setNameFormat("PaperSpigot - Lighting Thread").build()); // PaperSpigot - Asynchronous lighting updates
|
2015-07-01 09:27:58 +02:00
|
|
|
|
|
|
|
public static long chunkToKey(int x, int z)
|
|
|
|
{
|
2015-10-17 04:43:03 +02:00
|
|
|
@@ -497,7 +504,7 @@ public abstract class World implements IBlockAccess {
|
2015-07-01 09:27:58 +02:00
|
|
|
|
|
|
|
if (!this.worldProvider.o()) {
|
|
|
|
for (i1 = k; i1 <= l; ++i1) {
|
|
|
|
- this.c(EnumSkyBlock.SKY, new BlockPosition(i, i1, j));
|
|
|
|
+ this.updateLight(EnumSkyBlock.SKY, new BlockPosition(i, i1, j)); // PaperSpigot - Asynchronous lighting updates
|
|
|
|
}
|
2015-04-18 10:30:12 +02:00
|
|
|
}
|
|
|
|
|
2015-10-17 04:43:03 +02:00
|
|
|
@@ -2325,10 +2332,10 @@ public abstract class World implements IBlockAccess {
|
2015-07-01 09:27:58 +02:00
|
|
|
boolean flag = false;
|
|
|
|
|
|
|
|
if (!this.worldProvider.o()) {
|
|
|
|
- flag |= this.c(EnumSkyBlock.SKY, blockposition);
|
|
|
|
+ flag |= this.updateLight(EnumSkyBlock.SKY, blockposition); // PaperSpigot - Asynchronous lighting updates
|
2015-04-18 10:30:12 +02:00
|
|
|
}
|
|
|
|
|
2015-07-01 09:27:58 +02:00
|
|
|
- flag |= this.c(EnumSkyBlock.BLOCK, blockposition);
|
|
|
|
+ flag |= this.updateLight(EnumSkyBlock.BLOCK, blockposition); // PaperSpigot - Asynchronous lighting updates
|
|
|
|
return flag;
|
2015-04-18 10:30:12 +02:00
|
|
|
}
|
|
|
|
|
2015-10-17 04:43:03 +02:00
|
|
|
@@ -2375,10 +2382,10 @@ public abstract class World implements IBlockAccess {
|
2015-04-18 10:30:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- public boolean c(EnumSkyBlock enumskyblock, BlockPosition blockposition) {
|
2015-07-01 09:27:58 +02:00
|
|
|
+ public boolean c(EnumSkyBlock enumskyblock, BlockPosition blockposition, Chunk chunk, List<Chunk> neighbors) { // PaperSpigot
|
|
|
|
// CraftBukkit start - Use neighbor cache instead of looking up
|
2015-04-18 10:30:12 +02: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 09:27:58 +02: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 {
|
2015-10-17 04:43:03 +02:00
|
|
|
@@ -2496,11 +2503,66 @@ public abstract class World implements IBlockAccess {
|
2015-07-01 09:27:58 +02:00
|
|
|
}
|
|
|
|
}
|
2015-04-18 10:30:12 +02:00
|
|
|
|
2015-07-01 09:27:58 +02:00
|
|
|
+ // PaperSpigot start - Asynchronous light updates
|
|
|
|
+ if (chunk.world.paperSpigotConfig.useAsyncLighting) {
|
|
|
|
+ chunk.pendingLightUpdates.decrementAndGet();
|
|
|
|
+ if (neighbors != null) {
|
|
|
|
+ for (Chunk neighbor : neighbors) {
|
|
|
|
+ neighbor.pendingLightUpdates.decrementAndGet();
|
2015-04-18 10:30:12 +02:00
|
|
|
+ }
|
2015-07-01 09:27:58 +02:00
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // PaperSpigot end
|
|
|
|
this.methodProfiler.b();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2015-04-18 10:30:12 +02:00
|
|
|
|
2015-07-01 09:27:58 +02:00
|
|
|
+ /**
|
|
|
|
+ * PaperSpigot - Asynchronous lighting updates
|
|
|
|
+ */
|
|
|
|
+ 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 12:20:10 +02:00
|
|
|
+ if (chunk == null || !chunk.areNeighborsLoaded(1)) {
|
2015-07-01 09:27:58 +02:00
|
|
|
+ return false;
|
|
|
|
+ }
|
2015-04-18 10:30:12 +02:00
|
|
|
+
|
2015-07-01 09:27:58 +02:00
|
|
|
+ if (!chunk.world.paperSpigotConfig.useAsyncLighting) {
|
|
|
|
+ return this.c(enumskyblock, position, chunk, null);
|
|
|
|
+ }
|
2015-04-18 10:30:12 +02:00
|
|
|
+
|
2015-07-01 09:27:58 +02:00
|
|
|
+ chunk.pendingLightUpdates.incrementAndGet();
|
|
|
|
+ chunk.lightUpdateTime = chunk.world.getTime();
|
2015-04-18 10:30:12 +02:00
|
|
|
+
|
2015-07-01 09:27:58 +02:00
|
|
|
+ final List<Chunk> neighbors = new ArrayList<Chunk>();
|
2015-07-05 02:42:28 +02: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 11:01:49 +02:00
|
|
|
+ if (cx != x >> 4 && cz != z >> 4) {
|
|
|
|
+ Chunk neighbor = this.getChunkIfLoaded(cx, cz);
|
|
|
|
+ if (neighbor != null) {
|
2015-07-01 09:27:58 +02:00
|
|
|
+ neighbor.pendingLightUpdates.incrementAndGet();
|
|
|
|
+ neighbor.lightUpdateTime = chunk.world.getTime();
|
|
|
|
+ neighbors.add(neighbor);
|
|
|
|
+ }
|
|
|
|
+ }
|
2015-04-18 10:30:12 +02:00
|
|
|
+ }
|
2015-07-01 09:27:58 +02:00
|
|
|
+ }
|
|
|
|
+
|
2015-08-05 00:44:54 +02:00
|
|
|
+ if (!Bukkit.isPrimaryThread()) {
|
|
|
|
+ return this.c(enumskyblock, position, chunk, neighbors);
|
|
|
|
+ }
|
|
|
|
+
|
2015-07-01 09:27:58 +02:00
|
|
|
+ lightingExecutor.submit(new Runnable() {
|
|
|
|
+ @Override
|
|
|
|
+ public void run() {
|
|
|
|
+ World.this.c(enumskyblock, position, chunk, neighbors);
|
|
|
|
+ }
|
|
|
|
+ });
|
2015-04-18 10:30:12 +02:00
|
|
|
+ return true;
|
2015-07-01 09:27:58 +02:00
|
|
|
+ }
|
|
|
|
+
|
2015-04-18 10:30:12 +02:00
|
|
|
public boolean a(boolean flag) {
|
|
|
|
return false;
|
2015-07-01 09:27:58 +02:00
|
|
|
}
|
2015-04-18 10:30:12 +02:00
|
|
|
diff --git a/src/main/java/org/github/paperspigot/PaperSpigotWorldConfig.java b/src/main/java/org/github/paperspigot/PaperSpigotWorldConfig.java
|
2015-08-07 06:44:03 +02:00
|
|
|
index 8421e3b..fa5066b 100644
|
2015-04-18 10:30:12 +02:00
|
|
|
--- a/src/main/java/org/github/paperspigot/PaperSpigotWorldConfig.java
|
|
|
|
+++ b/src/main/java/org/github/paperspigot/PaperSpigotWorldConfig.java
|
2015-06-04 12:57:23 +02:00
|
|
|
@@ -244,4 +244,11 @@ public class PaperSpigotWorldConfig
|
2015-04-18 10:30:12 +02:00
|
|
|
log( "WorldServer TickNextTick cap set at " + tickNextTickCap );
|
|
|
|
log( "WorldServer TickNextTickList cap always processes redstone: " + tickNextTickListCapIgnoresRedstone );
|
|
|
|
}
|
|
|
|
+
|
|
|
|
+ public boolean useAsyncLighting;
|
|
|
|
+ private void useAsyncLighting()
|
|
|
|
+ {
|
|
|
|
+ useAsyncLighting = getBoolean( "use-async-lighting", false );
|
|
|
|
+ log( "World async lighting: " + useAsyncLighting );
|
|
|
|
+ }
|
|
|
|
}
|
|
|
|
--
|
2015-10-17 04:43:03 +02:00
|
|
|
2.6.1.windows.1
|
2015-04-18 10:30:12 +02:00
|
|
|
|