diff --git a/core/src/main/java/com/volmit/iris/core/pregenerator/IrisPregenerator.java b/core/src/main/java/com/volmit/iris/core/pregenerator/IrisPregenerator.java index 3201bebf4..dbd734a56 100644 --- a/core/src/main/java/com/volmit/iris/core/pregenerator/IrisPregenerator.java +++ b/core/src/main/java/com/volmit/iris/core/pregenerator/IrisPregenerator.java @@ -66,8 +66,10 @@ public class IrisPregenerator { private final KSet net; private final ChronoLatch cl; private final ChronoLatch saveLatch = new ChronoLatch(30000); + private final IrisPackBenchmarking benchmarking; public IrisPregenerator(PregenTask task, PregeneratorMethod generator, PregenListener listener) { + benchmarking = IrisPackBenchmarking.getInstance(); this.listener = listenify(listener); cl = new ChronoLatch(5000); generatedRegions = new KSet<>(); @@ -135,7 +137,7 @@ public class IrisPregenerator { double percentage = ((double) generated.get() / (double) totalChunks.get()) * 100; Iris.info("%s: %s of %s (%.0f%%), %s/s ETA: %s", - IrisPackBenchmarking.benchmarkInProgress ? "Benchmarking" : "Pregen", + benchmarking != null ? "Benchmarking" : "Pregen", Form.f(generated.get()), Form.f(totalChunks.get()), percentage, @@ -174,10 +176,10 @@ public class IrisPregenerator { task.iterateRegions((x, z) -> visitRegion(x, z, false)); Iris.info("Pregen took " + Form.duration((long) p.getMilliseconds())); shutdown(); - if (!IrisPackBenchmarking.benchmarkInProgress) { + if (benchmarking == null) { Iris.info(C.IRIS + "Pregen stopped."); } else { - IrisPackBenchmarking.instance.finishedBenchmark(chunksPerSecondHistory); + benchmarking.finishedBenchmark(chunksPerSecondHistory); } } diff --git a/core/src/main/java/com/volmit/iris/core/tools/IrisPackBenchmarking.java b/core/src/main/java/com/volmit/iris/core/tools/IrisPackBenchmarking.java index d9c6b0bd0..4f39a7527 100644 --- a/core/src/main/java/com/volmit/iris/core/tools/IrisPackBenchmarking.java +++ b/core/src/main/java/com/volmit/iris/core/tools/IrisPackBenchmarking.java @@ -12,7 +12,6 @@ import com.volmit.iris.util.format.Form; import com.volmit.iris.util.io.IO; import com.volmit.iris.util.scheduling.J; import com.volmit.iris.util.scheduling.PrecisionStopwatch; -import lombok.Getter; import org.bukkit.Bukkit; import java.io.File; @@ -24,28 +23,28 @@ import java.util.Collections; public class IrisPackBenchmarking { - @Getter - public static IrisPackBenchmarking instance; - public static boolean benchmarkInProgress = false; + private static final ThreadLocal instance = new ThreadLocal<>(); private final PrecisionStopwatch stopwatch = new PrecisionStopwatch(); private final IrisDimension dimension; private final int radius; private final boolean gui; public IrisPackBenchmarking(IrisDimension dimension, int radius, boolean gui) { - instance = this; this.dimension = dimension; this.radius = radius; this.gui = gui; runBenchmark(); } + public static IrisPackBenchmarking getInstance() { + return instance.get(); + } + private void runBenchmark() { Thread.ofVirtual() .name("PackBenchmarking") .start(() -> { Iris.info("Setting up benchmark environment "); - benchmarkInProgress = true; IO.delete(new File(Bukkit.getWorldContainer(), "benchmark")); createBenchmark(); while (!IrisToolbelt.isIrisWorld(Bukkit.getWorld("benchmark"))) { @@ -59,10 +58,6 @@ public class IrisPackBenchmarking { } - public boolean getBenchmarkInProgress() { - return benchmarkInProgress; - } - public void finishedBenchmark(KList cps) { try { String time = Form.duration((long) stopwatch.getMilliseconds()); @@ -132,13 +127,18 @@ public class IrisPackBenchmarking { } private void startBenchmark() { - IrisToolbelt.pregenerate(PregenTask - .builder() - .gui(gui) - .radiusX(radius) - .radiusZ(radius) - .build(), Bukkit.getWorld("benchmark") - ); + try { + instance.set(this); + IrisToolbelt.pregenerate(PregenTask + .builder() + .gui(gui) + .radiusX(radius) + .radiusZ(radius) + .build(), Bukkit.getWorld("benchmark") + ); + } finally { + instance.remove(); + } } private double calculateAverage(KList list) {