This should work

queue commands if over limit (default = 1)
fix caclulating history size (in memory)
fix relighting in parallel
This commit is contained in:
Jesse Boyd 2016-09-18 23:48:08 +10:00
parent 8d960213f8
commit 2d67aa5b9d
6 changed files with 52 additions and 42 deletions

View File

@ -56,7 +56,6 @@ public abstract class NMSMappedFaweQueue<WORLD, CHUNK, CHUNKSECTION, SECTION> ex
public void end(FaweChunk chunk) { public void end(FaweChunk chunk) {
super.end(chunk); super.end(chunk);
if (Settings.LIGHTING.MODE == 0) { if (Settings.LIGHTING.MODE == 0) {
refreshChunk(chunk);
return; return;
} }
if (relighter == null) { if (relighter == null) {

View File

@ -8,14 +8,14 @@ import java.util.ArrayDeque;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class NMSRelighter { public class NMSRelighter {
private final NMSMappedFaweQueue queue; private final NMSMappedFaweQueue queue;
private final HashMap<Long, RelightSkyEntry> skyToRelight; private final Map<Long, RelightSkyEntry> skyToRelight;
private final HashMap<Long, RelightBlockEntry> blocksToRelight; private final Map<Long, RelightBlockEntry> blocksToRelight;
private final int maxY; private final int maxY;
private volatile boolean relighting = false; private volatile boolean relighting = false;
@ -23,8 +23,8 @@ public class NMSRelighter {
public NMSRelighter(NMSMappedFaweQueue queue) { public NMSRelighter(NMSMappedFaweQueue queue) {
this.queue = queue; this.queue = queue;
skyToRelight = new HashMap<>(); skyToRelight = new ConcurrentHashMap<>();
blocksToRelight = new HashMap<>(); blocksToRelight = new ConcurrentHashMap<>();
this.maxY = queue.getWEWorld().getMaxY(); this.maxY = queue.getWEWorld().getMaxY();
} }
@ -199,6 +199,7 @@ public class NMSRelighter {
} }
if (opacity > 1 && opacity >= value) { if (opacity > 1 && opacity >= value) {
mask[j] = 0; mask[j] = 0;
queue.setBlockLight(section, x, y, z, 0);
queue.setSkyLight(section, x, y, z, 0); queue.setSkyLight(section, x, y, z, 0);
continue; continue;
} }

View File

@ -42,7 +42,7 @@ public class FaweLimit {
return true; return true;
} }
}; };
MAX.MAX_ACTIONS = Integer.MAX_VALUE; MAX.MAX_ACTIONS = 1;
MAX.MAX_CHANGES = Integer.MAX_VALUE; MAX.MAX_CHANGES = Integer.MAX_VALUE;
MAX.MAX_FAILS = Integer.MAX_VALUE; MAX.MAX_FAILS = Integer.MAX_VALUE;
MAX.MAX_CHECKS = Integer.MAX_VALUE; MAX.MAX_CHECKS = Integer.MAX_VALUE;

View File

@ -5,7 +5,6 @@ import com.boydti.fawe.FaweAPI;
import com.boydti.fawe.config.BBC; import com.boydti.fawe.config.BBC;
import com.boydti.fawe.config.Settings; import com.boydti.fawe.config.Settings;
import com.boydti.fawe.object.clipboard.DiskOptimizedClipboard; import com.boydti.fawe.object.clipboard.DiskOptimizedClipboard;
import com.boydti.fawe.object.exception.FaweException;
import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.MainUtil;
import com.boydti.fawe.util.SetQueue; import com.boydti.fawe.util.SetQueue;
import com.boydti.fawe.util.TaskManager; import com.boydti.fawe.util.TaskManager;
@ -33,6 +32,7 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedDeque;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
public abstract class FawePlayer<T> { public abstract class FawePlayer<T> {
@ -107,11 +107,39 @@ public abstract class FawePlayer<T> {
} }
} }
private AtomicInteger getActions() { private AtomicInteger runningCount = new AtomicInteger();
AtomicInteger adder = getMeta("fawe_action_v2");
public void queueAction(final Runnable run) {
Runnable wrappedTask = new Runnable() {
@Override
public void run() {
try {
run.run();
} catch (Throwable e) {
e.printStackTrace();
}
runningCount.decrementAndGet();
Runnable next = getActions().poll();
if (next != null) {
next.run();
}
}
};
getActions().add(wrappedTask);
FaweLimit limit = getLimit();
if (runningCount.getAndIncrement() < limit.MAX_ACTIONS) {
Runnable task = getActions().poll();
if (task != null) {
task.run();
}
}
}
private ConcurrentLinkedDeque<Runnable> getActions() {
ConcurrentLinkedDeque<Runnable> adder = getMeta("fawe_action_v2");
if (adder == null) { if (adder == null) {
adder = new AtomicInteger(); adder = new ConcurrentLinkedDeque();
AtomicInteger previous = (AtomicInteger) setMeta("fawe_action_v2", adder); ConcurrentLinkedDeque<Runnable> previous = (ConcurrentLinkedDeque<Runnable>) setMeta("fawe_action_v2", adder);
if (previous != null) { if (previous != null) {
setMeta("fawe_action_v2", adder = previous); setMeta("fawe_action_v2", adder = previous);
} }
@ -129,35 +157,10 @@ public abstract class FawePlayer<T> {
public boolean runAction(final Runnable ifFree, boolean checkFree, boolean async) { public boolean runAction(final Runnable ifFree, boolean checkFree, boolean async) {
if (checkFree) { if (checkFree) {
FaweLimit limit = getLimit(); queueAction(ifFree);
int actionLimit = limit.MAX_ACTIONS;
final AtomicInteger current = getActions();
int val = current.incrementAndGet();
if (val > actionLimit) {
current.decrementAndGet();
return false;
}
Runnable r = new Runnable() {
@Override
public void run() {
try {
ifFree.run();
} catch (Throwable e) {
FaweException faweException = FaweException.get(e);
if (faweException != null) {
BBC.WORLDEDIT_CANCEL_REASON.send(FawePlayer.this, faweException.getMessage());
} else {
throw new RuntimeException(e);
}
} finally {
current.decrementAndGet();
}
}
};
TaskManager.IMP.taskNow(r, async);
return true; return true;
} else { } else {
ifFree.run(); TaskManager.IMP.taskNow(ifFree, async);
} }
return false; return false;
} }

View File

@ -90,7 +90,14 @@ public class MemoryOptimizedHistory extends FaweStreamChangeSet {
@Override @Override
public int getCompressedSize() { public int getCompressedSize() {
return ids == null ? 0 : ids.length; if (ids == null) {
return 0;
}
int count = 0;
for (byte[] array : ids) {
count += 4 + array.length;
}
return count;
} }
@Override @Override

View File

@ -28,7 +28,7 @@ import com.boydti.fawe.object.exception.FaweException;
import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.MainUtil;
import com.boydti.fawe.util.TaskManager; import com.boydti.fawe.util.TaskManager;
import com.boydti.fawe.wrappers.FakePlayer; import com.boydti.fawe.wrappers.FakePlayer;
import com.boydti.fawe.wrappers.PlayerWrapper; import com.boydti.fawe.wrappers.LocationMaskedPlayerWrapper;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import com.sk89q.minecraft.util.commands.CommandException; import com.sk89q.minecraft.util.commands.CommandException;
import com.sk89q.minecraft.util.commands.CommandLocals; import com.sk89q.minecraft.util.commands.CommandLocals;
@ -264,7 +264,7 @@ public final class CommandManager {
if (fp == null) { if (fp == null) {
throw new IllegalArgumentException("FAWE doesn't support: " + actor); throw new IllegalArgumentException("FAWE doesn't support: " + actor);
} }
locals.put(Actor.class, actor instanceof Player ? new PlayerWrapper((Player) actor) : actor); locals.put(Actor.class, actor instanceof Player ? (actor = new LocationMaskedPlayerWrapper((Player) actor, ((Player) actor).getPosition())) : actor);
final Actor finalActor = actor; final Actor finalActor = actor;
if (!fp.runAction(new Runnable() { if (!fp.runAction(new Runnable() {
@Override @Override