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

Fixes #847
Dieser Commit ist enthalten in:
dordsor21 2021-01-13 17:24:14 +00:00
Ursprung b066ca8349
Commit 97209d5680
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 1E53E88969FFCF0B
4 geänderte Dateien mit 30 neuen und 12 gelöschten Zeilen

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -1098,18 +1098,15 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
limit.set(originalLimit); limit.set(originalLimit);
try { try {
if (relighter != null && !(relighter instanceof NullRelighter)) { if (relighter != null && !(relighter instanceof NullRelighter)) {
// Only relight once! // Don't relight twice!
if (Settings.IMP.LIGHTING.DELAY_PACKET_SENDING && !relighter.getLock().tryLock()) { if (!relighter.isFinished() && relighter.getLock().tryLock()) {
relighter.getLock().lock(); try {
relighter.getLock().unlock(); if (Settings.IMP.LIGHTING.REMOVE_FIRST) {
} else { relighter.removeAndRelight(true);
if (Settings.IMP.LIGHTING.REMOVE_FIRST) { } else {
relighter.removeAndRelight(true); relighter.fixLightingSafe(true);
} else { }
relighter.fixSkyLighting(); } finally {
relighter.fixBlockLighting();
}
if (Settings.IMP.LIGHTING.DELAY_PACKET_SENDING) {
relighter.getLock().unlock(); relighter.getLock().unlock();
} }
} }