Performance Improvements Pregenerator

This commit is contained in:
Daniel Mills 2021-07-15 00:39:08 -04:00
parent c99c7ee6c9
commit ecb869695e
2 changed files with 46 additions and 36 deletions

View File

@ -18,6 +18,7 @@
package com.volmit.iris.pregen;
import com.volmit.iris.Iris;
import com.volmit.iris.nms.INMS;
import com.volmit.iris.scaffold.cache.Cache;
import com.volmit.iris.scaffold.data.mca.Chunk;
@ -234,4 +235,21 @@ public class DirectWorldWriter {
return biomeIds;
}
public void verify(int mcaox, int mcaoz) {
MCAFile file = getMCA(mcaox, mcaoz);
for(int i = 0; i < 32; i++)
{
for(int j = 0; j < 32; j++)
{
Chunk c = file.getChunk(i, j);
if(c == null)
{
Iris.warn("Chunk " + ((mcaox << 5) + i) + ", " + ((mcaoz << 5) + j) + " is null in MCA File " + mcaox + ", " + mcaoz);
}
}
}
}
}

View File

@ -46,6 +46,7 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Comparator;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
@ -91,6 +92,7 @@ public class Pregenerator implements Listener {
private final ChronoLatch latch;
private IrisAccess access;
private final KList<ChunkPosition> regionReload;
private KList<ChunkPosition> wait = new KList<>();
public Pregenerator(World world, int blockSize, Runnable onComplete) {
this(world, blockSize);
@ -154,8 +156,6 @@ public class Pregenerator implements Listener {
drawMCA(xx, zz, COLOR_MCA_PREPARE);
if (access != null && generateMCARegion(xx, zz, burst, access, mcaIteration)) {
flushWorld();
} else {
drawMCA(xx, zz, COLOR_MCA_DEFERRED);
}
});
@ -182,6 +182,11 @@ public class Pregenerator implements Listener {
flushWorld();
}
while(wait.isNotEmpty())
{
J.sleep(50);
}
burst.shutdownNow();
directWriter.flush();
flushWorld();
@ -222,6 +227,7 @@ public class Pregenerator implements Listener {
private boolean generateMCARegion(int x, int z, MultiBurst burst, IrisAccess access, Consumer3<Integer, Integer, Consumer2<Integer, Integer>> mcaIteration) {
if (!Iris.instance.isMCA()) {
generateDeferedMCARegion(x, z, burst, mcaIteration);
return false;
}
@ -244,13 +250,10 @@ public class Pregenerator implements Listener {
}));
e.complete();
directWriter.flush();
if (!install(mcg, mca)) {
drawMCA(x, z, COLOR_MCA_DEFERRED);
generated.set(generated.get() - 1024);
}
totalChunks.getAndAdd(1024);
mcaDefer.add(new ChunkPosition(x, z));
} else {
install(mcg, mca);
} else {
totalChunks.getAndAdd(1024);
mcaDefer.add(new ChunkPosition(x, z));
e.complete();
@ -289,30 +292,33 @@ public class Pregenerator implements Listener {
}
private void generateDeferedMCARegion(int x, int z, MultiBurst burst, Consumer3<Integer, Integer, Consumer2<Integer, Integer>> mcaIteration) {
BurstExecutor e = burst.burst(1024);
int mcaox = x << 5;
int mcaoz = z << 5;
if (PaperLib.isPaper()) {
method.set("PaperAsync (Slow)");
mcaIteration.accept(mcaox, mcaoz, (ii, jj) -> e.queue(() -> {
try {
CompletableFuture<Chunk> cc = PaperLib.getChunkAtAsync(world, ii, jj);
while(wait.size() > 8192)
{
J.sleep(25);
}
mcaIteration.accept(mcaox, mcaoz, (ii, jj) -> {
ChunkPosition cx = new ChunkPosition(ii,jj);
PaperLib.getChunkAtAsync(world, ii, jj).thenAccept((c) -> {
draw(ii, jj, COLOR_MCA_GENERATE_SLOW_ASYNC);
cc.join();
draw(ii, jj, COLOR_MCA_GENERATED);
generated.getAndIncrement();
vcax.set(ii);
vcaz.set(jj);
} catch (Throwable ex) {
draw(ii, jj, COLOR_ERROR);
ChunkPosition pos = new ChunkPosition(ii, jj);
errors.add(pos);
totalChunks.addAndGet(1024);
mcaDefer.add(new ChunkPosition(pos.getX() >> 5, pos.getZ() >> 5));
Iris.warn("Hole Detected in Chunk: " + pos.getX() + ", " + pos.getZ() + " (at block " + (pos.getX() << 4) + ", " + lowestBedrock + ", " + (pos.getZ() << 4) + ")");
}
}));
e.complete();
synchronized (wait)
{
wait.remove(cx);
}
});
wait.add(cx);
});
} else {
AtomicInteger m = new AtomicInteger();
method.set("Spigot (Very Slow)");
@ -322,7 +328,6 @@ public class Pregenerator implements Listener {
world.getChunkAt(ii, jj).load(true);
Chunk c = world.getChunkAt(ii, jj);
draw(ii, jj, COLOR_MCA_GENERATED);
checkForError(c);
m.getAndIncrement();
generated.getAndIncrement();
vcax.set(ii);
@ -355,19 +360,6 @@ public class Pregenerator implements Listener {
}
}
private void checkForError(Chunk c) {
if (lowestBedrock >= 0 && lowestBedrock < 256) {
if (!c.getBlock(14, lowestBedrock, 14).getType().equals(Material.BEDROCK)) {
ChunkPosition pos = new ChunkPosition(c.getX(), c.getZ());
errors.add(pos);
totalChunks.addAndGet(1024);
mcaDefer.add(new ChunkPosition(pos.getX() >> 5, pos.getZ() >> 5));
draw(pos.getX(), pos.getZ(), COLOR_ERROR);
Iris.warn("Hole Detected in Chunk: " + pos.getX() + ", " + pos.getZ() + " (at block " + (pos.getX() << 4) + ", " + lowestBedrock + ", " + (pos.getZ() << 4) + ")");
}
}
}
private KList<ChunkPosition> computeChunkOrder() {
ChunkPosition center = new ChunkPosition(15, 15);
KList<ChunkPosition> p = new KList<>();