Optional async relighting

This commit is contained in:
Jesse Boyd 2016-04-20 04:11:09 +10:00
parent 505e99b488
commit 33f3cb6ba5
5 changed files with 104 additions and 45 deletions

View File

@ -108,7 +108,7 @@ public class BukkitQueue_1_8 extends BukkitQueue_0 {
bukkitWorld = Bukkit.getServer().getWorld(world);
}
if (!bukkitWorld.isChunkLoaded(loc.x, loc.z)) {
bukkitWorld.loadChunk(loc.x, loc.z);
bukkitWorld.loadChunk(loc.x, loc.z, true);
}
}
loadQueue.notifyAll();
@ -177,8 +177,14 @@ public class BukkitQueue_1_8 extends BukkitQueue_0 {
return new ArrayList<>();
}
public void sendChunk(FaweChunk<Chunk> fc) {
public void sendChunk(final FaweChunk<Chunk> fc) {
TaskManager.IMP.task(new Runnable() {
@Override
public void run() {
fixLighting(fc, Settings.FIX_ALL_LIGHTING);
TaskManager.IMP.task(new Runnable() {
@Override
public void run() {
Chunk chunk = fc.getChunk();
World world = chunk.getWorld();
final int view = Bukkit.getServer().getViewDistance();
@ -194,13 +200,17 @@ public class BukkitQueue_1_8 extends BukkitQueue_0 {
if ((Math.abs(cx - px) > view) || (Math.abs(cz - pz) > view)) {
continue;
}
final Object entity = this.methodGetHandlePlayer.of(player).call();
final RefExecutor con = this.send.of(this.connection.of(entity).get());
final Object c = this.methodGetHandleChunk.of(fc.getChunk()).call();
Object packet = this.MapChunk.create(c, false, 65535);
final Object entity = methodGetHandlePlayer.of(player).call();
final RefExecutor con = send.of(connection.of(entity).get());
final Object c = methodGetHandleChunk.of(fc.getChunk()).call();
Object packet = MapChunk.create(c, false, 65535);
con.call(packet);
}
}
}, false);
}
}, Settings.ASYNC_LIGHTING);
}
@Override
public boolean fixLighting(final FaweChunk<?> fc, final boolean fixAll) {

View File

@ -98,7 +98,7 @@ public class BukkitQueue_1_9 extends BukkitQueue_0 {
bukkitWorld = Bukkit.getServer().getWorld(world);
}
if (!bukkitWorld.isChunkLoaded(loc.x, loc.z)) {
bukkitWorld.loadChunk(loc.x, loc.z);
bukkitWorld.loadChunk(loc.x, loc.z, true);
}
}
loadQueue.notifyAll();
@ -166,11 +166,21 @@ public class BukkitQueue_1_9 extends BukkitQueue_0 {
return new ArrayList<>();
}
public void sendChunk(FaweChunk<Chunk> fc) {
public void sendChunk(final FaweChunk<Chunk> fc) {
TaskManager.IMP.task(new Runnable() {
@Override
public void run() {
fixLighting(fc, Settings.FIX_ALL_LIGHTING);
TaskManager.IMP.task(new Runnable() {
@Override
public void run() {
final Chunk chunk = fc.getChunk();
chunk.getWorld().refreshChunk(fc.getX(), fc.getZ());
}
}, false);
}
}, Settings.ASYNC_LIGHTING);
}
@Override
public boolean fixLighting(final FaweChunk<?> pc, final boolean fixAll) {

View File

@ -60,7 +60,7 @@ public class BukkitQueue_1_9_R1 extends BukkitQueue_0 {
bukkitWorld = Bukkit.getServer().getWorld(world);
}
if (!bukkitWorld.isChunkLoaded(loc.x, loc.z)) {
bukkitWorld.loadChunk(loc.x, loc.z);
bukkitWorld.loadChunk(loc.x, loc.z, true);
}
}
loadQueue.notifyAll();
@ -117,6 +117,9 @@ public class BukkitQueue_1_9_R1 extends BukkitQueue_0 {
ChunkSection nibble = chunkSections[cy];
lastSection = nibble != null ? nibble.getBlocks() : null;
} else if (cy != lcy) {
if (chunkSections == null) {
return 0;
}
ChunkSection nibble = chunkSections[cy];
lastSection = nibble != null ? nibble.getBlocks() : null;
}
@ -146,11 +149,21 @@ public class BukkitQueue_1_9_R1 extends BukkitQueue_0 {
return new ArrayList<>();
}
public void sendChunk(FaweChunk<Chunk> fc) {
public void sendChunk(final FaweChunk<Chunk> fc) {
TaskManager.IMP.task(new Runnable() {
@Override
public void run() {
fixLighting(fc, Settings.FIX_ALL_LIGHTING);
TaskManager.IMP.task(new Runnable() {
@Override
public void run() {
final Chunk chunk = fc.getChunk();
chunk.getWorld().refreshChunk(fc.getX(), fc.getZ());
}
}, false);
}
}, Settings.ASYNC_LIGHTING);
}
@Override
public boolean fixLighting(final FaweChunk<?> pc, final boolean fixAll) {
@ -375,6 +388,8 @@ public class BukkitQueue_1_9_R1 extends BukkitQueue_0 {
int data = lastId & 0xF;
IBlockData ibd = Block.getById(id).fromLegacyData(data);
lastBit = palette.a(ibd);
palette = (DataPalette) fieldPalette.get(nibble);
bits = (DataBits) fieldBits.get(nibble);
}
bits.a(i, lastBit);
}
@ -390,9 +405,14 @@ public class BukkitQueue_1_9_R1 extends BukkitQueue_0 {
case 0:
int existingBit = bits.a(k);
if (existingBit != lastBit) {
palette = (DataPalette) fieldPalette.get(nibble);
bits = (DataBits) fieldBits.get(nibble);
lastBit = existingBit;
IBlockData ibd = palette.a(existingBit);
if (ibd != null) {
if (ibd == null) {
fill = false;
continue;
}
Block block = ibd.getBlock();
int id = Block.getId(block);
if (FaweCache.hasData(id)) {
@ -400,10 +420,6 @@ public class BukkitQueue_1_9_R1 extends BukkitQueue_0 {
} else {
lastId = id << 4;
}
} else {
fill = false;
continue;
}
}
if (lastId != 0) {
nonEmptyBlockCount++;
@ -420,6 +436,8 @@ public class BukkitQueue_1_9_R1 extends BukkitQueue_0 {
int data = lastId & 0xF;
IBlockData ibd = Block.getById(id).fromLegacyData(data);
lastBit = palette.a(ibd);
palette = (DataPalette) fieldPalette.get(nibble);
bits = (DataBits) fieldBits.get(nibble);
}
bits.a(k, lastBit);
continue;
@ -433,6 +451,8 @@ public class BukkitQueue_1_9_R1 extends BukkitQueue_0 {
int data = lastId & 0xF;
IBlockData ibd = Block.getById(id).fromLegacyData(data);
lastBit = palette.a(ibd);
palette = (DataPalette) fieldPalette.get(nibble);
bits = (DataBits) fieldBits.get(nibble);
}
bits.a(k, lastBit);
continue;

View File

@ -16,7 +16,6 @@ import java.util.Map.Entry;
public class Settings {
public static boolean REQUIRE_SELECTION = false;
public static boolean FIX_ALL_LIGHTING = true;
public static boolean COMMAND_PROCESSOR = false;
public static List<String> WE_BLACKLIST = Arrays.asList("cs", ".s", "restore", "snapshot", "delchunks", "listchunks");
public static long MEM_FREE = 95;
@ -33,6 +32,9 @@ public class Settings {
public static int QUEUE_DISCARD_AFTER = 60000;
public static List<String> ALLOWED_3RDPARTY_EXTENTS;
public static boolean FIX_ALL_LIGHTING = true;
public static boolean ASYNC_LIGHTING = true;
public static HashMap<String, FaweLimit> limits;
public static FaweLimit getLimit(FawePlayer player) {
@ -71,7 +73,8 @@ public class Settings {
options.put("command-processor", COMMAND_PROCESSOR);
options.put("max-memory-percent", MEM_FREE);
options.put("crash-mitigation", ENABLE_HARD_LIMIT);
options.put("fix-all-lighting", FIX_ALL_LIGHTING);
options.put("lighting.fix-all", FIX_ALL_LIGHTING);
options.put("lighting.async", ASYNC_LIGHTING);
options.put("history.use-disk", STORE_HISTORY_ON_DISK);
options.put("history.compress", false);
options.put("history.chunk-wait-ms", CHUNK_WAIT);
@ -99,7 +102,8 @@ public class Settings {
config.set(node.getKey(), node.getValue());
}
}
FIX_ALL_LIGHTING = config.getBoolean("fix-all-lighting");
FIX_ALL_LIGHTING = config.getBoolean("lighting.fix-all");
ASYNC_LIGHTING = config.getBoolean("lighting.async");
COMMAND_PROCESSOR = config.getBoolean("command-processor");
MEM_FREE = config.getInt("max-memory-percent");
REQUIRE_SELECTION = config.getBoolean("require-selection-in-mask");

View File

@ -1,5 +1,6 @@
package com.boydti.fawe.util;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.object.RunnableVal;
import java.util.Collection;
import java.util.Iterator;
@ -16,6 +17,20 @@ public abstract class TaskManager {
public abstract void task(final Runnable r);
public void task(final Runnable r, boolean async) {
if (async) {
async(r);
} else {
if (Fawe.get().getMainThread() == Thread.currentThread()) {
if (r != null) {
r.run();
}
} else {
task(r);
}
}
}
public abstract void later(final Runnable r, final int delay);
public abstract void laterAsync(final Runnable r, final int delay);