Fixes chunk sending when block placement is really slow

TODO fix this properly later
- This fix works, but isn't very clean
- Queue should have a `done` stage rather than assuming empty = done
This commit is contained in:
Jesse Boyd 2016-10-21 02:59:01 +11:00
parent 0054e432ae
commit f2204fd188
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
2 changed files with 22 additions and 26 deletions

View File

@ -21,41 +21,36 @@ public abstract class NMSMappedFaweQueue<WORLD, CHUNK, CHUNKSECTION, SECTION> ex
public NMSMappedFaweQueue(World world) {
super(world);
this.maxY = world.getMaxY();
addRelightTask();
}
public NMSMappedFaweQueue(String world) {
super(world);
this.maxY = 256;
addRelightTask();
}
public NMSMappedFaweQueue(String world, IFaweQueueMap map) {
super(world, map);
this.maxY = 256;
addRelightTask();
}
public NMSMappedFaweQueue(World world, IFaweQueueMap map) {
super(world, map);
this.maxY = world.getMaxY();
addRelightTask();
}
private void addRelightTask() {
addNotifyTask(new Runnable() {
@Override
public void run() {
if (relighter != null) {
TaskManager.IMP.taskNowAsync(new Runnable() {
@Override
public void run() {
relighter.fixLightingSafe(hasSky());
}
});
@Override
public void runTasks() {
super.runTasks();
final NMSRelighter tmp = relighter;
relighter = null;
if (tmp != null) {
TaskManager.IMP.taskNowAsync(new Runnable() {
@Override
public void run() {
tmp.fixLightingSafe(hasSky());
}
}
});
});
}
}
private NMSRelighter relighter;
@ -67,11 +62,13 @@ public abstract class NMSMappedFaweQueue<WORLD, CHUNK, CHUNKSECTION, SECTION> ex
sendChunk(chunk);
return;
}
if (relighter == null) {
relighter = new NMSRelighter(this);
NMSRelighter tmp = relighter;
if (tmp == null) {
relighter = tmp = new NMSRelighter(this);
}
if (Settings.LIGHTING.MODE == 2) {
relighter.addChunk(chunk.getX(), chunk.getZ(), null, chunk.getBitMask());
tmp.addChunk(chunk.getX(), chunk.getZ(), null, chunk.getBitMask());
return;
}
CharFaweChunk cfc = (CharFaweChunk) chunk;
@ -85,7 +82,7 @@ public abstract class NMSMappedFaweQueue<WORLD, CHUNK, CHUNKSECTION, SECTION> ex
}
}
if (relight) {
relighter.addChunk(chunk.getX(), chunk.getZ(), fix, chunk.getBitMask());
tmp.addChunk(chunk.getX(), chunk.getZ(), fix, chunk.getBitMask());
} else {
sendChunk(chunk);
}

View File

@ -30,17 +30,16 @@ public class NMSRelighter {
public boolean addChunk(int cx, int cz, boolean[] fix, int bitmask) {
long pair = MathMan.pairInt(cx, cz);
RelightSkyEntry existing = skyToRelight.get(pair);
RelightSkyEntry toPut = new RelightSkyEntry(cx, cz, fix, bitmask);
RelightSkyEntry existing = skyToRelight.put(pair, toPut);
if (existing != null) {
existing.bitmask |= bitmask;
toPut.bitmask |= existing.bitmask;
if (fix != null) {
for (int i = 0; i < fix.length; i++) {
existing.fix[i] |= fix[i];
toPut.fix[i] |= existing.fix[i];
}
}
return false;
}
skyToRelight.put(pair, new RelightSkyEntry(cx, cz, fix, bitmask));
return true;
}