mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-01 23:47:21 +00:00
some more optimizations
This commit is contained in:
parent
97c7ac0528
commit
5b60b655ed
@ -21,21 +21,12 @@ package com.volmit.iris.core.commands;
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.ServerConfigurator;
|
||||
import com.volmit.iris.core.loader.IrisData;
|
||||
import com.volmit.iris.core.nms.INMS;
|
||||
import com.volmit.iris.core.nms.datapack.DataVersion;
|
||||
import com.volmit.iris.core.nms.v1X.NMSBinding1X;
|
||||
import com.volmit.iris.core.pregenerator.ChunkUpdater;
|
||||
import com.volmit.iris.core.service.IrisEngineSVC;
|
||||
import com.volmit.iris.core.tools.IrisConverter;
|
||||
import com.volmit.iris.core.tools.IrisPackBenchmarking;
|
||||
import com.volmit.iris.core.tools.IrisToolbelt;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.engine.mantle.components.MantleObjectComponent;
|
||||
import com.volmit.iris.engine.object.IrisBiome;
|
||||
import com.volmit.iris.engine.object.IrisCave;
|
||||
import com.volmit.iris.engine.object.IrisDimension;
|
||||
import com.volmit.iris.engine.object.IrisEntity;
|
||||
import com.volmit.iris.util.data.Dimension;
|
||||
import com.volmit.iris.util.decree.DecreeExecutor;
|
||||
import com.volmit.iris.util.decree.DecreeOrigin;
|
||||
import com.volmit.iris.util.decree.annotations.Decree;
|
||||
@ -45,13 +36,10 @@ import com.volmit.iris.util.format.Form;
|
||||
import com.volmit.iris.util.io.CountingDataInputStream;
|
||||
import com.volmit.iris.util.io.IO;
|
||||
import com.volmit.iris.util.mantle.TectonicPlate;
|
||||
import com.volmit.iris.util.math.Spiraler;
|
||||
import com.volmit.iris.util.math.Vector3d;
|
||||
import com.volmit.iris.util.nbt.mca.MCAFile;
|
||||
import com.volmit.iris.util.nbt.mca.MCAUtil;
|
||||
import com.volmit.iris.util.parallel.MultiBurst;
|
||||
import com.volmit.iris.util.plugin.VolmitSender;
|
||||
import io.lumine.mythic.bukkit.adapters.BukkitEntity;
|
||||
import net.jpountz.lz4.LZ4BlockInputStream;
|
||||
import net.jpountz.lz4.LZ4BlockOutputStream;
|
||||
import net.jpountz.lz4.LZ4FrameInputStream;
|
||||
@ -59,10 +47,7 @@ import net.jpountz.lz4.LZ4FrameOutputStream;
|
||||
import org.apache.commons.lang.RandomStringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Creeper;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.InetAddress;
|
||||
@ -153,12 +138,14 @@ public class CommandDeveloper implements DecreeExecutor {
|
||||
|
||||
@Decree(description = "Test")
|
||||
public void packBenchmark(
|
||||
@Param(description = "The pack to bench", aliases = {"pack"})
|
||||
IrisDimension dimension
|
||||
@Param(description = "The pack to bench", aliases = {"pack"}, defaultValue = "overworld")
|
||||
IrisDimension dimension,
|
||||
@Param(description = "Radius in regions", defaultValue = "5")
|
||||
int radius,
|
||||
@Param(description = "Open GUI while benchmarking", defaultValue = "false")
|
||||
boolean gui
|
||||
) {
|
||||
Iris.info("test");
|
||||
IrisPackBenchmarking benchmark = new IrisPackBenchmarking(dimension, 1);
|
||||
|
||||
new IrisPackBenchmarking(dimension, radius, gui);
|
||||
}
|
||||
|
||||
@Decree(description = "Upgrade to another Minecraft version")
|
||||
|
@ -22,7 +22,6 @@ import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.pregenerator.PregenListener;
|
||||
import com.volmit.iris.core.pregenerator.PregeneratorMethod;
|
||||
import com.volmit.iris.core.tools.IrisToolbelt;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.mantle.Mantle;
|
||||
import com.volmit.iris.util.math.M;
|
||||
@ -34,12 +33,12 @@ import org.bukkit.World;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.Semaphore;
|
||||
|
||||
public class AsyncPregenMethod implements PregeneratorMethod {
|
||||
private final World world;
|
||||
private final MultiBurst burst;
|
||||
private final KList<Future<?>> future;
|
||||
private final Semaphore semaphore;
|
||||
private final Map<Chunk, Long> lastUse;
|
||||
|
||||
public AsyncPregenMethod(World world, int threads) {
|
||||
@ -49,7 +48,7 @@ public class AsyncPregenMethod implements PregeneratorMethod {
|
||||
|
||||
this.world = world;
|
||||
burst = new MultiBurst("Iris Async Pregen", Thread.MIN_PRIORITY);
|
||||
future = new KList<>(256);
|
||||
semaphore = new Semaphore(256);
|
||||
this.lastUse = new KMap<>();
|
||||
}
|
||||
|
||||
@ -63,7 +62,7 @@ public class AsyncPregenMethod implements PregeneratorMethod {
|
||||
|
||||
for (Chunk i : new ArrayList<>(lastUse.keySet())) {
|
||||
Long lastUseTime = lastUse.get(i);
|
||||
if (lastUseTime != null && M.ms() - lastUseTime >= 10000) {
|
||||
if (!i.isLoaded() || (lastUseTime != null && M.ms() - lastUseTime >= 10000)) {
|
||||
i.unload();
|
||||
lastUse.remove(i);
|
||||
}
|
||||
@ -85,37 +84,8 @@ public class AsyncPregenMethod implements PregeneratorMethod {
|
||||
} catch (InterruptedException ignored) {
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void waitForChunksPartial(int maxWaiting) {
|
||||
while (future.size() > maxWaiting) {
|
||||
try {
|
||||
Future<?> i = future.remove(0);
|
||||
|
||||
if (i == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
i.get();
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void waitForChunks() {
|
||||
for (Future<?> i : future.copy()) {
|
||||
if (i == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
i.get();
|
||||
future.remove(i);
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} finally {
|
||||
semaphore.release();
|
||||
}
|
||||
}
|
||||
|
||||
@ -131,14 +101,13 @@ public class AsyncPregenMethod implements PregeneratorMethod {
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
waitForChunks();
|
||||
semaphore.acquireUninterruptibly(256);
|
||||
unloadAndSaveAllChunks();
|
||||
burst.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
waitForChunksPartial(256);
|
||||
unloadAndSaveAllChunks();
|
||||
}
|
||||
|
||||
@ -155,10 +124,12 @@ public class AsyncPregenMethod implements PregeneratorMethod {
|
||||
@Override
|
||||
public void generateChunk(int x, int z, PregenListener listener) {
|
||||
listener.onChunkGenerating(x, z);
|
||||
if (future.size() > 256) {
|
||||
waitForChunksPartial(256);
|
||||
try {
|
||||
semaphore.acquire();
|
||||
} catch (InterruptedException e) {
|
||||
return;
|
||||
}
|
||||
future.add(burst.complete(() -> completeChunk(x, z, listener)));
|
||||
burst.complete(() -> completeChunk(x, z, listener));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -24,10 +24,8 @@ import com.volmit.iris.core.IrisSettings;
|
||||
import com.volmit.iris.core.ServerConfigurator;
|
||||
import com.volmit.iris.core.pregenerator.PregenTask;
|
||||
import com.volmit.iris.core.service.StudioSVC;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.engine.object.IrisDimension;
|
||||
import com.volmit.iris.engine.platform.PlatformChunkGenerator;
|
||||
import com.volmit.iris.core.safeguard.UtilsSFG;
|
||||
import com.volmit.iris.util.exceptions.IrisException;
|
||||
import com.volmit.iris.util.format.C;
|
||||
import com.volmit.iris.util.format.Form;
|
||||
@ -46,7 +44,6 @@ import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.Supplier;
|
||||
import static com.volmit.iris.core.safeguard.IrisSafeguard.unstablemode;
|
||||
|
||||
/**
|
||||
* Makes it a lot easier to setup an engine, world, studio or whatever
|
||||
@ -126,14 +123,11 @@ public class IrisCreator {
|
||||
if (sender == null)
|
||||
sender = Iris.getSender();
|
||||
|
||||
if (!studio()) {
|
||||
Iris.service(StudioSVC.class).installIntoWorld(sender, d.getLoadKey(), new File(Bukkit.getWorldContainer(), name()));
|
||||
}
|
||||
if (benchmark) {
|
||||
if (!studio() || benchmark) {
|
||||
Iris.service(StudioSVC.class).installIntoWorld(sender, d.getLoadKey(), new File(Bukkit.getWorldContainer(), name()));
|
||||
}
|
||||
|
||||
PlatformChunkGenerator access = null;
|
||||
PlatformChunkGenerator access;
|
||||
AtomicReference<World> world = new AtomicReference<>();
|
||||
AtomicDouble pp = new AtomicDouble(0);
|
||||
O<Boolean> done = new O<>();
|
||||
|
@ -9,8 +9,6 @@ import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.exceptions.IrisException;
|
||||
import com.volmit.iris.util.format.Form;
|
||||
import com.volmit.iris.util.math.Position2;
|
||||
|
||||
import com.volmit.iris.util.scheduling.J;
|
||||
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
|
||||
import lombok.Getter;
|
||||
@ -27,44 +25,44 @@ import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.time.Clock;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Collections;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
|
||||
public class IrisPackBenchmarking {
|
||||
@Getter
|
||||
public static IrisPackBenchmarking instance;
|
||||
public static boolean benchmarkInProgress = false;
|
||||
private IrisDimension IrisDimension;
|
||||
private int radius;
|
||||
private boolean finished = false;
|
||||
PrecisionStopwatch stopwatch;
|
||||
public static boolean benchmarkInProgress = false;
|
||||
private final PrecisionStopwatch stopwatch = new PrecisionStopwatch();
|
||||
private final IrisDimension dimension;
|
||||
private final int radius;
|
||||
private final boolean gui;
|
||||
|
||||
public IrisPackBenchmarking(IrisDimension dimension, int r) {
|
||||
public IrisPackBenchmarking(IrisDimension dimension, int radius, boolean gui) {
|
||||
instance = this;
|
||||
this.IrisDimension = dimension;
|
||||
this.radius = r;
|
||||
this.dimension = dimension;
|
||||
this.radius = radius;
|
||||
this.gui = gui;
|
||||
runBenchmark();
|
||||
}
|
||||
|
||||
private void runBenchmark() {
|
||||
this.stopwatch = new PrecisionStopwatch();
|
||||
ExecutorService service = Executors.newSingleThreadExecutor();
|
||||
service.submit(() -> {
|
||||
Iris.info("Setting up benchmark environment ");
|
||||
benchmarkInProgress = true;
|
||||
File file = new File("benchmark");
|
||||
if (file.exists()) {
|
||||
deleteDirectory(file.toPath());
|
||||
}
|
||||
createBenchmark();
|
||||
while (!IrisToolbelt.isIrisWorld(Bukkit.getWorld("benchmark"))) {
|
||||
J.sleep(1000);
|
||||
Iris.debug("Iris PackBenchmark: Waiting...");
|
||||
}
|
||||
Iris.info("Starting Benchmark!");
|
||||
stopwatch.begin();
|
||||
startBenchmark();
|
||||
});
|
||||
Thread.ofVirtual()
|
||||
.name("PackBenchmarking")
|
||||
.start(() -> {
|
||||
Iris.info("Setting up benchmark environment ");
|
||||
benchmarkInProgress = true;
|
||||
File file = new File("benchmark");
|
||||
if (file.exists()) {
|
||||
deleteDirectory(file.toPath());
|
||||
}
|
||||
createBenchmark();
|
||||
while (!IrisToolbelt.isIrisWorld(Bukkit.getWorld("benchmark"))) {
|
||||
J.sleep(1000);
|
||||
Iris.debug("Iris PackBenchmark: Waiting...");
|
||||
}
|
||||
Iris.info("Starting Benchmark!");
|
||||
stopwatch.begin();
|
||||
startBenchmark();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@ -88,14 +86,14 @@ public class IrisPackBenchmarking {
|
||||
File profilers = new File("plugins" + File.separator + "Iris" + File.separator + "packbenchmarks");
|
||||
profilers.mkdir();
|
||||
|
||||
File results = new File("plugins " + File.separator + "Iris", IrisDimension.getName() + LocalDateTime.now(Clock.systemDefaultZone()) + ".txt");
|
||||
results.createNewFile();
|
||||
File results = new File(profilers, dimension.getName() + " " + LocalDateTime.now(Clock.systemDefaultZone()).toString().replace(':', '-') + ".txt");
|
||||
results.getParentFile().mkdirs();
|
||||
KMap<String, Double> metrics = engine.getMetrics().pull();
|
||||
try (FileWriter writer = new FileWriter(results)) {
|
||||
writer.write("-----------------\n");
|
||||
writer.write("Results:\n");
|
||||
writer.write("Dimension: " + IrisDimension.getName() + "\n");
|
||||
writer.write("- Date of Benchmark: " + LocalDateTime.now(Clock.systemDefaultZone()) + "\n");
|
||||
writer.write("Dimension: " + dimension.getName() + "\n");
|
||||
writer.write("- Date of Benchmark: " + LocalDateTime.now(Clock.systemDefaultZone()) + "\n");
|
||||
writer.write("\n");
|
||||
writer.write("Metrics");
|
||||
for (String m : metrics.k()) {
|
||||
@ -103,7 +101,7 @@ public class IrisPackBenchmarking {
|
||||
writer.write("- " + m + ": " + i);
|
||||
}
|
||||
writer.write("- " + metrics);
|
||||
writer.write("Benchmark: " + LocalDateTime.now(Clock.systemDefaultZone()) + "\n");
|
||||
writer.write("Benchmark: " + LocalDateTime.now(Clock.systemDefaultZone()) + "\n");
|
||||
writer.write("- Total time: " + time + "\n");
|
||||
writer.write("- Average CPS: " + calculateAverage(cps) + "\n");
|
||||
writer.write(" - Median CPS: " + calculateMedian(cps) + "\n");
|
||||
@ -116,17 +114,24 @@ public class IrisPackBenchmarking {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Bukkit.getServer().unloadWorld("benchmark", true);
|
||||
J.s(() -> {
|
||||
var world = Bukkit.getWorld("benchmark");
|
||||
if (world == null) return;
|
||||
IrisToolbelt.evacuate(world);
|
||||
Bukkit.unloadWorld(world, true);
|
||||
});
|
||||
|
||||
stopwatch.end();
|
||||
} catch (Exception e) {
|
||||
Iris.error("Something has gone wrong!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
private void createBenchmark(){
|
||||
|
||||
private void createBenchmark() {
|
||||
try {
|
||||
IrisToolbelt.createWorld()
|
||||
.dimension(IrisDimension.getName())
|
||||
.dimension(dimension.getLoadKey())
|
||||
.name("benchmark")
|
||||
.seed(1337)
|
||||
.studio(false)
|
||||
@ -137,17 +142,14 @@ public class IrisPackBenchmarking {
|
||||
}
|
||||
}
|
||||
|
||||
private void startBenchmark(){
|
||||
int x = 0;
|
||||
int z = 0;
|
||||
IrisToolbelt.pregenerate(PregenTask
|
||||
.builder()
|
||||
.gui(false)
|
||||
.center(new Position2(x, z))
|
||||
.width(5)
|
||||
.height(5)
|
||||
.build(), Bukkit.getWorld("benchmark")
|
||||
);
|
||||
private void startBenchmark() {
|
||||
IrisToolbelt.pregenerate(PregenTask
|
||||
.builder()
|
||||
.gui(gui)
|
||||
.width(radius)
|
||||
.height(radius)
|
||||
.build(), Bukkit.getWorld("benchmark")
|
||||
);
|
||||
}
|
||||
|
||||
private double calculateAverage(KList<Integer> list) {
|
||||
@ -179,7 +181,7 @@ public class IrisPackBenchmarking {
|
||||
|
||||
private boolean deleteDirectory(Path dir) {
|
||||
try {
|
||||
Files.walkFileTree(dir, new SimpleFileVisitor<Path>() {
|
||||
Files.walkFileTree(dir, new SimpleFileVisitor<>() {
|
||||
@Override
|
||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
||||
Files.delete(file);
|
||||
|
@ -29,6 +29,7 @@ import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.collection.KSet;
|
||||
import com.volmit.iris.util.context.IrisContext;
|
||||
import com.volmit.iris.util.data.DataProvider;
|
||||
import com.volmit.iris.util.interpolation.IrisInterpolation.NoiseKey;
|
||||
import com.volmit.iris.util.math.M;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import com.volmit.iris.util.noise.CNG;
|
||||
@ -292,9 +293,11 @@ public class IrisComplex implements DataProvider {
|
||||
return 0;
|
||||
}
|
||||
|
||||
KMap<NoiseKey, IrisBiome> cache = new KMap<>();
|
||||
double hi = interpolator.interpolate(x, z, (xx, zz) -> {
|
||||
try {
|
||||
IrisBiome bx = baseBiomeStream.get(xx, zz);
|
||||
cache.put(new NoiseKey(xx, zz), bx);
|
||||
double b = 0;
|
||||
|
||||
for (IrisGenerator gen : generators) {
|
||||
@ -313,7 +316,11 @@ public class IrisComplex implements DataProvider {
|
||||
|
||||
double lo = interpolator.interpolate(x, z, (xx, zz) -> {
|
||||
try {
|
||||
IrisBiome bx = baseBiomeStream.get(xx, zz);
|
||||
IrisBiome bx = cache.get(new NoiseKey(xx, zz));
|
||||
if (bx == null) {
|
||||
bx = baseBiomeStream.get(xx, zz);
|
||||
cache.put(new NoiseKey(xx, zz), bx);
|
||||
}
|
||||
double b = 0;
|
||||
|
||||
for (IrisGenerator gen : generators) {
|
||||
|
@ -997,11 +997,9 @@ public class IrisInterpolation {
|
||||
return getNoise3D(method, x, y, z, rad, rad, rad, n);
|
||||
}
|
||||
|
||||
private record Key(double x, double z) {}
|
||||
|
||||
public static double getNoise(InterpolationMethod method, int x, int z, double h, NoiseProvider noise) {
|
||||
HashMap<Key, Double> cache = new HashMap<>(64);
|
||||
NoiseProvider n = (x1, z1) -> cache.computeIfAbsent(new Key(x1, z1), k -> noise.noise(k.x, k.z));
|
||||
HashMap<NoiseKey, Double> cache = new HashMap<>(64);
|
||||
NoiseProvider n = (x1, z1) -> cache.computeIfAbsent(new NoiseKey(x1, z1), k -> noise.noise(k.x, k.z));
|
||||
|
||||
if (method.equals(InterpolationMethod.BILINEAR)) {
|
||||
return getBilinearNoise(x, z, h, n);
|
||||
@ -1063,4 +1061,7 @@ public class IrisInterpolation {
|
||||
public static double rangeScale(double amin, double amax, double bmin, double bmax, double b) {
|
||||
return amin + ((amax - amin) * ((b - bmin) / (bmax - bmin)));
|
||||
}
|
||||
|
||||
public record NoiseKey(double x, double z) {
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user