mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-01-06 15:51:30 +00:00
minor headless performance improvements
This commit is contained in:
@@ -152,10 +152,12 @@ public class CommandDeveloper implements DecreeExecutor {
|
||||
@Param(description = "The pack to bench", aliases = {"pack"})
|
||||
IrisDimension dimension,
|
||||
@Param(description = "Headless", defaultValue = "false")
|
||||
boolean headless
|
||||
boolean headless,
|
||||
@Param(description = "GUI", defaultValue = "false")
|
||||
boolean gui
|
||||
) {
|
||||
Iris.info("test");
|
||||
IrisPackBenchmarking benchmark = new IrisPackBenchmarking(dimension, 1, headless);
|
||||
IrisPackBenchmarking benchmark = new IrisPackBenchmarking(dimension, 1, headless, gui);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import java.io.Closeable;
|
||||
|
||||
public interface IHeadless extends Closeable {
|
||||
|
||||
void saveAll();
|
||||
void save();
|
||||
|
||||
@ChunkCoordinates
|
||||
boolean exists(int x, int z);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.volmit.iris.core.pregenerator.methods;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.IrisSettings;
|
||||
import com.volmit.iris.core.nms.IHeadless;
|
||||
import com.volmit.iris.core.nms.INMS;
|
||||
import com.volmit.iris.core.pregenerator.PregenListener;
|
||||
@@ -15,14 +16,14 @@ import java.util.concurrent.Semaphore;
|
||||
public class HeadlessPregenMethod implements PregeneratorMethod {
|
||||
private final Engine engine;
|
||||
private final IHeadless headless;
|
||||
private final MultiBurst burst;
|
||||
private final Semaphore semaphore;
|
||||
private final int max;
|
||||
|
||||
public HeadlessPregenMethod(Engine engine) {
|
||||
this.max = IrisSettings.getThreadCount(IrisSettings.get().getConcurrency().getParallelism());
|
||||
this.engine = engine;
|
||||
this.headless = INMS.get().createHeadless(engine);
|
||||
this.burst = new MultiBurst("Iris Headless", Thread.MAX_PRIORITY);
|
||||
this.semaphore = new Semaphore(1024);
|
||||
this.semaphore = new Semaphore(max);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -31,10 +32,9 @@ public class HeadlessPregenMethod implements PregeneratorMethod {
|
||||
@Override
|
||||
public void close() {
|
||||
try {
|
||||
semaphore.acquire(1024);
|
||||
semaphore.acquire(max);
|
||||
} catch (InterruptedException ignored) {}
|
||||
burst.close();
|
||||
headless.saveAll();
|
||||
headless.save();
|
||||
try {
|
||||
headless.close();
|
||||
} catch (IOException e) {
|
||||
@@ -45,7 +45,7 @@ public class HeadlessPregenMethod implements PregeneratorMethod {
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
headless.saveAll();
|
||||
headless.save();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -69,7 +69,7 @@ public class HeadlessPregenMethod implements PregeneratorMethod {
|
||||
semaphore.release();
|
||||
return;
|
||||
}
|
||||
burst.complete(() -> {
|
||||
MultiBurst.burst.complete(() -> {
|
||||
try {
|
||||
listener.onChunkGenerating(x, z);
|
||||
headless.generateChunk(x, z);
|
||||
|
||||
@@ -45,15 +45,17 @@ public class IrisPackBenchmarking {
|
||||
private IrisDimension IrisDimension;
|
||||
private int radius;
|
||||
private final boolean headless;
|
||||
private final boolean gui;
|
||||
private boolean finished = false;
|
||||
private Engine engine;
|
||||
PrecisionStopwatch stopwatch;
|
||||
|
||||
public IrisPackBenchmarking(IrisDimension dimension, int r, boolean headless) {
|
||||
public IrisPackBenchmarking(IrisDimension dimension, int r, boolean headless, boolean gui) {
|
||||
instance = this;
|
||||
this.IrisDimension = dimension;
|
||||
this.radius = r;
|
||||
this.headless = headless;
|
||||
this.gui = gui;
|
||||
runBenchmark();
|
||||
}
|
||||
|
||||
@@ -169,7 +171,7 @@ public class IrisPackBenchmarking {
|
||||
int z = 0;
|
||||
IrisToolbelt.pregenerate(PregenTask
|
||||
.builder()
|
||||
.gui(false)
|
||||
.gui(gui)
|
||||
.center(new Position2(x, z))
|
||||
.width(5)
|
||||
.height(5)
|
||||
|
||||
@@ -48,7 +48,7 @@ public class Headless implements IHeadless, LevelHeightAccessor {
|
||||
private final Engine engine;
|
||||
private final RegionFileStorage storage;
|
||||
private final Queue<ProtoChunk> chunkQueue = new ArrayDeque<>();
|
||||
private final ReentrantLock manualLock = new ReentrantLock();
|
||||
private final ReentrantLock saveLock = new ReentrantLock();
|
||||
private final KMap<String, Holder<Biome>> customBiomes = new KMap<>();
|
||||
private final KMap<NamespacedKey, Holder<Biome>> minecraftBiomes = new KMap<>();
|
||||
private boolean closed = false;
|
||||
@@ -60,11 +60,7 @@ public class Headless implements IHeadless, LevelHeightAccessor {
|
||||
var queueLooper = new Looper() {
|
||||
@Override
|
||||
protected long loop() {
|
||||
if (manualLock.isLocked()) {
|
||||
manualLock.lock();
|
||||
manualLock.unlock();
|
||||
}
|
||||
saveAll();
|
||||
save();
|
||||
return closed ? -1 : 100;
|
||||
}
|
||||
};
|
||||
@@ -84,26 +80,22 @@ public class Headless implements IHeadless, LevelHeightAccessor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveAll() {
|
||||
manualLock.lock();
|
||||
try {
|
||||
save();
|
||||
} finally {
|
||||
manualLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
private void save() {
|
||||
public void save() {
|
||||
if (closed) return;
|
||||
while (!chunkQueue.isEmpty()) {
|
||||
ChunkAccess chunk = chunkQueue.poll();
|
||||
if (chunk == null) break;
|
||||
try {
|
||||
storage.write(chunk.getPos(), binding.serializeChunk(chunk, this));
|
||||
} catch (Throwable e) {
|
||||
Iris.error("Failed to save chunk " + chunk.getPos().x + ", " + chunk.getPos().z);
|
||||
e.printStackTrace();
|
||||
saveLock.lock();
|
||||
try {
|
||||
while (!chunkQueue.isEmpty()) {
|
||||
ChunkAccess chunk = chunkQueue.poll();
|
||||
if (chunk == null) break;
|
||||
try {
|
||||
storage.write(chunk.getPos(), binding.serializeChunk(chunk, this));
|
||||
} catch (Throwable e) {
|
||||
Iris.error("Failed to save chunk " + chunk.getPos().x + ", " + chunk.getPos().z);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
saveLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user