better locking of lighting and use correct method for relight without removing first

Fixes #847
This commit is contained in:
dordsor21
2021-01-13 17:24:14 +00:00
parent b066ca8349
commit 97209d5680
4 changed files with 30 additions and 12 deletions

View File

@ -71,6 +71,7 @@ public class NMSRelighter implements Relighter {
private final int maxY;
private final boolean calculateHeightMaps;
private final ReentrantLock lightingLock;
private final AtomicBoolean finished = new AtomicBoolean(false);
private boolean removeFirst;
public NMSRelighter(IQueueExtent<IQueueChunk> queue, boolean calculateHeightMaps) {
@ -99,6 +100,11 @@ public class NMSRelighter implements Relighter {
return lightingLock;
}
@Override
public boolean isFinished() {
return finished.get();
}
@Override public synchronized void removeAndRelight(boolean sky) {
removeFirst = true;
fixLightingSafe(sky);
@ -839,10 +845,12 @@ public class NMSRelighter implements Relighter {
}
if (Settings.IMP.LIGHTING.ASYNC) {
queue.flush();
finished.set(true);
} else {
TaskManager.IMP.sync(new RunnableVal<Object>() {
@Override public void run(Object value) {
queue.flush();
finished.set(true);
}
});
}
@ -873,6 +881,7 @@ public class NMSRelighter implements Relighter {
Fawe.imp().getPlatformAdapter().sendChunk(chunk.getOrCreateGet(), bitMask, true);
iter.remove();
}
finished.set(true);
}
};
if (Settings.IMP.LIGHTING.ASYNC) {

View File

@ -53,4 +53,9 @@ public class NullRelighter implements Relighter {
public ReentrantLock getLock() {
return null;
}
@Override
public boolean isFinished() {
return true;
}
}

View File

@ -70,6 +70,13 @@ public interface Relighter {
ReentrantLock getLock();
/**
* Returns true if the Relighter has been flushed
*
* @return true if finished
*/
boolean isFinished();
class SkipReason {
public static final byte NONE = 0;
public static final byte AIR = 1;