Minor tweaks|

This commit is contained in:
Jesse Boyd 2016-09-16 01:30:45 +10:00
parent f55a58a3f3
commit 58a1fb183e
3 changed files with 41 additions and 20 deletions

View File

@ -31,7 +31,6 @@ public abstract class MappedFaweQueue<WORLD, CHUNK, SECTION> extends FaweQueue {
private WORLD impWorld;
private IFaweQueueMap map;
public ArrayDeque<Runnable> tasks = new ArrayDeque<>();
public MappedFaweQueue(final World world) {
this(world, null);
@ -93,12 +92,6 @@ public abstract class MappedFaweQueue<WORLD, CHUNK, SECTION> extends FaweQueue {
}
@Override
public void addNotifyTask(Runnable runnable) {
this.tasks.add(runnable);
size();
}
public abstract WORLD getImpWorld();
public abstract boolean isChunkLoaded(WORLD world, int x, int z);
@ -210,6 +203,7 @@ public abstract class MappedFaweQueue<WORLD, CHUNK, SECTION> extends FaweQueue {
@Override
public void runTasks() {
super.runTasks();
if (getProgressTask() != null) {
getProgressTask().run(ProgressType.DONE, 1);
}

View File

@ -35,7 +35,7 @@ public abstract class NMSMappedFaweQueue<WORLD, CHUNK, CHUNKSECTION, SECTION> ex
}
private void addRelightTask() {
tasks.add(new Runnable() {
addNotifyTask(new Runnable() {
@Override
public void run() {
if (relighter != null) {

View File

@ -10,7 +10,6 @@ import com.boydti.fawe.util.MainUtil;
import com.boydti.fawe.util.MathMan;
import com.boydti.fawe.util.MemUtil;
import com.boydti.fawe.util.SetQueue;
import com.boydti.fawe.util.TaskManager;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.Vector;
@ -26,7 +25,6 @@ import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentLinkedDeque;
import java.util.concurrent.ExecutorCompletionService;
import java.util.concurrent.atomic.AtomicBoolean;
public abstract class FaweQueue {
@ -269,8 +267,6 @@ public abstract class FaweQueue {
public abstract void addNotifyTask(int x, int z, Runnable runnable);
public abstract void addNotifyTask(Runnable runnable);
public boolean hasBlock(int x, int y, int z) throws FaweException.FaweChunkLoadException {
return getCombinedId4Data(x, y, z) != 0;
}
@ -355,6 +351,10 @@ public abstract class FaweQueue {
public abstract int size();
public boolean isEmpty() {
return size() == 0;
}
/**
* Lock the thread until the queue is empty
*/
@ -371,20 +371,47 @@ public abstract class FaweQueue {
SetQueue.IMP.flush(this);
} else {
if (enqueue()) {
final AtomicBoolean running = new AtomicBoolean(true);
addNotifyTask(new Runnable() {
@Override
public void run() {
TaskManager.IMP.notify(running);
while (!isEmpty() && SetQueue.IMP.isStage(this, SetQueue.QueueStage.ACTIVE)) {
synchronized (this) {
try {
this.wait(time);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
});
TaskManager.IMP.wait(running, time);
}
}
}
}
public abstract void runTasks();
public ConcurrentLinkedDeque<Runnable> tasks = new ConcurrentLinkedDeque<>();
public void addNotifyTask(Runnable runnable) {
this.tasks.add(runnable);
}
public void runTasks() {
synchronized (this) {
this.notifyAll();
}
if (getProgressTask() != null) {
getProgressTask().run(ProgressType.DONE, 1);
}
while (!tasks.isEmpty()) {
Runnable task = tasks.poll();
try {
task.run();
} catch (Throwable e) {
MainUtil.handleError(e);
}
}
}
public void addTask(Runnable whenFree) {
tasks.add(whenFree);
}
public boolean enqueue() {
return SetQueue.IMP.enqueue(this);