Don't use relighter for non nms placer

This commit is contained in:
Jesse Boyd 2017-08-13 13:13:03 +10:00
parent 92bf3f702b
commit f0066bbd26
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
2 changed files with 27 additions and 7 deletions

View File

@ -2,6 +2,8 @@ package com.boydti.fawe.bukkit.v0;
import com.boydti.fawe.FaweCache; import com.boydti.fawe.FaweCache;
import com.boydti.fawe.config.Settings; import com.boydti.fawe.config.Settings;
import com.boydti.fawe.example.NullRelighter;
import com.boydti.fawe.example.Relighter;
import com.boydti.fawe.object.FaweChunk; import com.boydti.fawe.object.FaweChunk;
import com.boydti.fawe.object.RegionWrapper; import com.boydti.fawe.object.RegionWrapper;
import com.boydti.fawe.object.RunnableVal; import com.boydti.fawe.object.RunnableVal;
@ -9,6 +11,7 @@ import com.boydti.fawe.util.MathMan;
import com.boydti.fawe.util.ReflectionUtils; import com.boydti.fawe.util.ReflectionUtils;
import com.boydti.fawe.util.SetQueue; import com.boydti.fawe.util.SetQueue;
import com.boydti.fawe.util.TaskManager; import com.boydti.fawe.util.TaskManager;
import com.google.common.collect.MapMaker;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.blocks.BaseBlock;
import java.io.File; import java.io.File;
@ -17,6 +20,7 @@ import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayDeque; import java.util.ArrayDeque;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentMap;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.ChunkSnapshot; import org.bukkit.ChunkSnapshot;
import org.bukkit.Location; import org.bukkit.Location;
@ -27,6 +31,9 @@ public class BukkitQueue_All extends BukkitQueue_0<ChunkSnapshot, ChunkSnapshot,
public static int ALLOCATE; public static int ALLOCATE;
private static int LIGHT_MASK = 0x739C0; private static int LIGHT_MASK = 0x739C0;
private ConcurrentMap<Long, ChunkSnapshot> chunkCache = new MapMaker()
.weakValues()
.makeMap();
public BukkitQueue_All(com.sk89q.worldedit.world.World world) { public BukkitQueue_All(com.sk89q.worldedit.world.World world) {
super(world); super(world);
@ -46,6 +53,11 @@ public class BukkitQueue_All extends BukkitQueue_0<ChunkSnapshot, ChunkSnapshot,
} }
} }
@Override
public Relighter getRelighter() {
return NullRelighter.INSTANCE;
}
private static Class<?> classRegionFileCache; private static Class<?> classRegionFileCache;
private static Class<?> classRegionFile; private static Class<?> classRegionFile;
private static Class<?> classCraftChunk; private static Class<?> classCraftChunk;
@ -220,13 +232,15 @@ public class BukkitQueue_All extends BukkitQueue_0<ChunkSnapshot, ChunkSnapshot,
@Override @Override
public ChunkSnapshot getCachedChunk(World world, int cx, int cz) { public ChunkSnapshot getCachedChunk(World world, int cx, int cz) {
long pair = MathMan.pairInt(cx, cz);
ChunkSnapshot cached = chunkCache.get(pair);
if (cached != null) return cached;
if (world.isChunkLoaded(cx, cz)) { if (world.isChunkLoaded(cx, cz)) {
long pair = MathMan.pairInt(cx, cz);
Long originalKeep = keepLoaded.get(pair); Long originalKeep = keepLoaded.get(pair);
keepLoaded.put(pair, Long.MAX_VALUE); keepLoaded.put(pair, Long.MAX_VALUE);
if (world.isChunkLoaded(cx, cz)) { if (world.isChunkLoaded(cx, cz)) {
Chunk chunk = world.getChunkAt(cx, cz); Chunk chunk = world.getChunkAt(cx, cz);
ChunkSnapshot snapshot = chunk.getChunkSnapshot(false, true, false); ChunkSnapshot snapshot = getAndCacheChunk(chunk);
if (originalKeep != null) { if (originalKeep != null) {
keepLoaded.put(pair, originalKeep); keepLoaded.put(pair, originalKeep);
} else { } else {
@ -263,7 +277,13 @@ public class BukkitQueue_All extends BukkitQueue_0<ChunkSnapshot, ChunkSnapshot,
public ChunkSnapshot loadChunk(World world, int x, int z, boolean generate) { public ChunkSnapshot loadChunk(World world, int x, int z, boolean generate) {
Chunk chunk = world.getChunkAt(x, z); Chunk chunk = world.getChunkAt(x, z);
chunk.load(generate); chunk.load(generate);
return chunk.isLoaded() ? chunk.getChunkSnapshot(false, true, false) : null; return chunk.isLoaded() ? getAndCacheChunk(chunk) : null;
}
private ChunkSnapshot getAndCacheChunk(Chunk chunk) {
ChunkSnapshot snapshot = chunk.getChunkSnapshot(false, true, false);
chunkCache.put(MathMan.pairInt(chunk.getX(), chunk.getZ()), snapshot);
return snapshot;
} }
@Override @Override

View File

@ -38,11 +38,11 @@ public abstract class NMSMappedFaweQueue<WORLD, CHUNK, CHUNKSECTION, SECTION> ex
@Override @Override
public void runTasks() { public void runTasks() {
super.runTasks(); super.runTasks();
if (!relighter.isEmpty()) { if (!getRelighter().isEmpty()) {
TaskManager.IMP.taskNowAsync(new Runnable() { TaskManager.IMP.taskNowAsync(new Runnable() {
@Override @Override
public void run() { public void run() {
relighter.fixLightingSafe(hasSky()); getRelighter().fixLightingSafe(hasSky());
} }
}); });
} }
@ -66,7 +66,7 @@ public abstract class NMSMappedFaweQueue<WORLD, CHUNK, CHUNKSECTION, SECTION> ex
sendChunk(chunk); sendChunk(chunk);
} }
if (Settings.IMP.LIGHTING.MODE == 2) { if (Settings.IMP.LIGHTING.MODE == 2) {
relighter.addChunk(chunk.getX(), chunk.getZ(), null, chunk.getBitMask()); getRelighter().addChunk(chunk.getX(), chunk.getZ(), null, chunk.getBitMask());
return; return;
} }
CharFaweChunk cfc = (CharFaweChunk) chunk; CharFaweChunk cfc = (CharFaweChunk) chunk;
@ -90,7 +90,7 @@ public abstract class NMSMappedFaweQueue<WORLD, CHUNK, CHUNKSECTION, SECTION> ex
} }
} }
if (relight) { if (relight) {
relighter.addChunk(chunk.getX(), chunk.getZ(), fix, chunk.getBitMask()); getRelighter().addChunk(chunk.getX(), chunk.getZ(), fix, chunk.getBitMask());
} else if (Settings.IMP.LIGHTING.DELAY_PACKET_SENDING) { } else if (Settings.IMP.LIGHTING.DELAY_PACKET_SENDING) {
sendChunk(chunk); sendChunk(chunk);
} }