mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-06-18 06:41:08 +00:00
headless performance improvements
This commit is contained in:
@@ -82,11 +82,8 @@ public class AsyncPregenMethod implements PregeneratorMethod {
|
|||||||
private void completeChunk(int x, int z, PregenListener listener) {
|
private void completeChunk(int x, int z, PregenListener listener) {
|
||||||
try {
|
try {
|
||||||
future.add(PaperLib.getChunkAtAsync(world, x, z, true).thenApply((i) -> {
|
future.add(PaperLib.getChunkAtAsync(world, x, z, true).thenApply((i) -> {
|
||||||
if (i == null) {
|
if (i == null) return 0;
|
||||||
|
lastUse.put(i, M.ms());
|
||||||
}
|
|
||||||
Chunk c = Bukkit.getWorld(world.getUID()).getChunkAt(x, z);
|
|
||||||
lastUse.put(c, M.ms());
|
|
||||||
listener.onChunkGenerated(x, z);
|
listener.onChunkGenerated(x, z);
|
||||||
listener.onChunkCleaned(x, z);
|
listener.onChunkCleaned(x, z);
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
+18
-27
@@ -6,25 +6,23 @@ import com.volmit.iris.core.nms.INMS;
|
|||||||
import com.volmit.iris.core.pregenerator.PregenListener;
|
import com.volmit.iris.core.pregenerator.PregenListener;
|
||||||
import com.volmit.iris.core.pregenerator.PregeneratorMethod;
|
import com.volmit.iris.core.pregenerator.PregeneratorMethod;
|
||||||
import com.volmit.iris.engine.framework.Engine;
|
import com.volmit.iris.engine.framework.Engine;
|
||||||
import com.volmit.iris.util.collection.KList;
|
|
||||||
import com.volmit.iris.util.mantle.Mantle;
|
import com.volmit.iris.util.mantle.Mantle;
|
||||||
import com.volmit.iris.util.parallel.MultiBurst;
|
import com.volmit.iris.util.parallel.MultiBurst;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Objects;
|
import java.util.concurrent.Semaphore;
|
||||||
import java.util.concurrent.Future;
|
|
||||||
|
|
||||||
public class HeadlessPregenMethod implements PregeneratorMethod {
|
public class HeadlessPregenMethod implements PregeneratorMethod {
|
||||||
private final Engine engine;
|
private final Engine engine;
|
||||||
private final IHeadless headless;
|
private final IHeadless headless;
|
||||||
private final MultiBurst burst;
|
private final MultiBurst burst;
|
||||||
private final KList<Future<?>> futures;
|
private final Semaphore semaphore;
|
||||||
|
|
||||||
public HeadlessPregenMethod(Engine engine) {
|
public HeadlessPregenMethod(Engine engine) {
|
||||||
this.engine = engine;
|
this.engine = engine;
|
||||||
this.headless = INMS.get().createHeadless(engine);
|
this.headless = INMS.get().createHeadless(engine);
|
||||||
this.burst = new MultiBurst("Iris Headless", Thread.MAX_PRIORITY);
|
this.burst = new MultiBurst("Iris Headless", Thread.MAX_PRIORITY);
|
||||||
this.futures = new KList<>();
|
this.semaphore = new Semaphore(1024);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -32,7 +30,9 @@ public class HeadlessPregenMethod implements PregeneratorMethod {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
waitForChunksPartial(0);
|
try {
|
||||||
|
semaphore.acquire(1024);
|
||||||
|
} catch (InterruptedException ignored) {}
|
||||||
burst.close();
|
burst.close();
|
||||||
headless.saveAll();
|
headless.saveAll();
|
||||||
try {
|
try {
|
||||||
@@ -63,34 +63,25 @@ public class HeadlessPregenMethod implements PregeneratorMethod {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void generateChunk(int x, int z, PregenListener listener) {
|
public void generateChunk(int x, int z, PregenListener listener) {
|
||||||
futures.removeIf(Future::isDone);
|
try {
|
||||||
waitForChunksPartial(512);
|
semaphore.acquire();
|
||||||
futures.add(burst.complete(() -> {
|
} catch (InterruptedException ignored) {
|
||||||
|
semaphore.release();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
burst.complete(() -> {
|
||||||
|
try {
|
||||||
listener.onChunkGenerating(x, z);
|
listener.onChunkGenerating(x, z);
|
||||||
headless.generateChunk(x, z);
|
headless.generateChunk(x, z);
|
||||||
listener.onChunkGenerated(x, z);
|
listener.onChunkGenerated(x, z);
|
||||||
}));
|
} finally {
|
||||||
|
semaphore.release();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mantle getMantle() {
|
public Mantle getMantle() {
|
||||||
return engine.getMantle().getMantle();
|
return engine.getMantle().getMantle();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void waitForChunksPartial(int maxWaiting) {
|
|
||||||
futures.removeWhere(Objects::isNull);
|
|
||||||
while (futures.size() > maxWaiting) {
|
|
||||||
try {
|
|
||||||
Future<?> i = futures.remove(0);
|
|
||||||
|
|
||||||
if (i == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
i.get();
|
|
||||||
} catch (Throwable e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-2
@@ -119,8 +119,7 @@ public class MedievalPregenMethod implements PregeneratorMethod {
|
|||||||
|
|
||||||
listener.onChunkGenerating(x, z);
|
listener.onChunkGenerating(x, z);
|
||||||
futures.add(J.sfut(() -> {
|
futures.add(J.sfut(() -> {
|
||||||
world.getChunkAt(x, z);
|
Chunk c = world.getChunkAt(x, z);
|
||||||
Chunk c = Bukkit.getWorld(world.getUID()).getChunkAt(x, z);
|
|
||||||
lastUse.put(c, M.ms());
|
lastUse.put(c, M.ms());
|
||||||
listener.onChunkGenerated(x, z);
|
listener.onChunkGenerated(x, z);
|
||||||
listener.onChunkCleaned(x, z);
|
listener.onChunkCleaned(x, z);
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ public class IrisPackBenchmarking {
|
|||||||
return new IrisEngine(new EngineTarget(world, dim, data), false);
|
return new IrisEngine(new EngineTarget(world, dim, data), false);
|
||||||
}
|
}
|
||||||
return IrisToolbelt.access(IrisToolbelt.createWorld()
|
return IrisToolbelt.access(IrisToolbelt.createWorld()
|
||||||
.dimension(IrisDimension.getName())
|
.dimension(IrisDimension.getLoadKey())
|
||||||
.name("benchmark")
|
.name("benchmark")
|
||||||
.seed(1337)
|
.seed(1337)
|
||||||
.studio(false)
|
.studio(false)
|
||||||
|
|||||||
@@ -184,7 +184,7 @@ public class Headless implements IHeadless, LevelHeightAccessor {
|
|||||||
IrisContext.getOr(engine).setChunkContext(ctx);
|
IrisContext.getOr(engine).setChunkContext(ctx);
|
||||||
|
|
||||||
for (EngineStage i : engine.getMode().getStages()) {
|
for (EngineStage i : engine.getMode().getStages()) {
|
||||||
i.generate(x, z, blocks, vbiomes, true, ctx);
|
i.generate(x, z, blocks, vbiomes, false, ctx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user