Skip to content

Commit ec74add

Browse files
Merge pull request #1219 from VolmitSoftware/dev
3.7.2
2 parents 6e738e6 + d5b7067 commit ec74add

39 files changed

+968
-572
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ nmsBindings.forEach { key, value ->
105105
pluginJars(tasks.jar.flatMap { it.archiveFile })
106106
javaLauncher = javaToolchains.launcherFor { languageVersion = JavaLanguageVersion.of(jvmVersion.getOrDefault(key, 21))}
107107
runDirectory.convention(layout.buildDirectory.dir("run/$key"))
108-
systemProperty("disable.watchdog", "")
108+
systemProperty("disable.watchdog", "true")
109109
systemProperty("net.kyori.ansi.colorLevel", color)
110110
systemProperty("com.mojang.eula.agree", true)
111111
systemProperty("iris.suppressReporting", !errorReporting)

core/src/main/java/com/volmit/iris/Iris.java

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ public class Iris extends VolmitPlugin implements Listener {
9696
public static IrisCompat compat;
9797
public static FileWatcher configWatcher;
9898
private static VolmitSender sender;
99+
private static Thread shutdownHook;
99100

100101
static {
101102
try {
@@ -453,6 +454,7 @@ private void enable() {
453454
configWatcher = new FileWatcher(getDataFile("settings.json"));
454455
services.values().forEach(IrisService::onEnable);
455456
services.values().forEach(this::registerListener);
457+
addShutdownHook();
456458
J.s(() -> {
457459
J.a(IrisSafeguard::suggestPaper);
458460
J.a(() -> IO.delete(getTemp()));
@@ -471,6 +473,23 @@ private void enable() {
471473
});
472474
}
473475

476+
public void addShutdownHook() {
477+
if (shutdownHook != null) {
478+
Runtime.getRuntime().removeShutdownHook(shutdownHook);
479+
}
480+
shutdownHook = new Thread(() -> {
481+
Bukkit.getWorlds()
482+
.stream()
483+
.map(IrisToolbelt::access)
484+
.filter(Objects::nonNull)
485+
.forEach(PlatformChunkGenerator::close);
486+
487+
MultiBurst.burst.close();
488+
services.clear();
489+
});
490+
Runtime.getRuntime().addShutdownHook(shutdownHook);
491+
}
492+
474493
public void checkForBukkitWorlds(Predicate<String> filter) {
475494
try {
476495
IrisWorlds.readBukkitWorlds().forEach((s, generator) -> {
@@ -548,16 +567,6 @@ public void onDisable() {
548567
super.onDisable();
549568

550569
J.attempt(new JarScanner(instance.getJarFile(), "", false)::scan);
551-
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
552-
Bukkit.getWorlds()
553-
.stream()
554-
.map(IrisToolbelt::access)
555-
.filter(Objects::nonNull)
556-
.forEach(PlatformChunkGenerator::close);
557-
558-
MultiBurst.burst.close();
559-
services.clear();
560-
}));
561570
}
562571

563572
private void setupPapi() {

core/src/main/java/com/volmit/iris/core/IrisSettings.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,13 @@ public int getTectonicPlateSize() {
176176

177177
@Data
178178
public static class IrisSettingsUpdater {
179-
public double threadMultiplier = 2;
179+
public int maxConcurrency = 256;
180180
public double chunkLoadSensitivity = 0.7;
181181
public MsRange emptyMsRange = new MsRange(80, 100);
182182
public MsRange defaultMsRange = new MsRange(20, 40);
183183

184-
public double getThreadMultiplier() {
185-
return Math.min(Math.abs(threadMultiplier), 0.1);
184+
public int getMaxConcurrency() {
185+
return Math.max(Math.abs(maxConcurrency), 1);
186186
}
187187

188188
public double getChunkLoadSensitivity() {
@@ -242,6 +242,7 @@ public static class IrisSettingsGenerator {
242242
public String defaultWorldType = "overworld";
243243
public int maxBiomeChildDepth = 4;
244244
public boolean preventLeafDecay = true;
245+
public boolean useMulticore = false;
245246
}
246247

247248
@Data
@@ -255,6 +256,7 @@ public static class IrisSettingsStudio {
255256
@Data
256257
public static class IrisSettingsEngineSVC {
257258
public boolean useVirtualThreads = true;
259+
public boolean forceMulticoreWrite = false;
258260
public int priority = Thread.NORM_PRIORITY;
259261

260262
public int getPriority() {

core/src/main/java/com/volmit/iris/core/commands/CommandDeveloper.java

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import com.volmit.iris.util.io.IO;
3838
import com.volmit.iris.util.mantle.TectonicPlate;
3939
import com.volmit.iris.util.math.M;
40+
import com.volmit.iris.util.matter.Matter;
4041
import com.volmit.iris.util.nbt.mca.MCAFile;
4142
import com.volmit.iris.util.nbt.mca.MCAUtil;
4243
import com.volmit.iris.util.parallel.MultiBurst;
@@ -53,6 +54,7 @@
5354
import java.io.*;
5455
import java.net.InetAddress;
5556
import java.net.NetworkInterface;
57+
import java.nio.file.Files;
5658
import java.util.*;
5759
import java.util.concurrent.ExecutorService;
5860
import java.util.concurrent.Executors;
@@ -64,7 +66,6 @@
6466
public class CommandDeveloper implements DecreeExecutor {
6567
private CommandTurboPregen turboPregen;
6668
private CommandLazyPregen lazyPregen;
67-
private CommandUpdater updater;
6869

6970
@Decree(description = "Get Loaded TectonicPlates Count", origin = DecreeOrigin.BOTH, sync = true)
7071
public void EngineStatus() {
@@ -79,6 +80,33 @@ public void Sentry() {
7980
Iris.reportError(new Exception("This is a test"));
8081
}
8182

83+
@Decree(description = "Test")
84+
public void mantle(@Param(defaultValue = "false") boolean plate, @Param(defaultValue = "21474836474") String name) throws Throwable {
85+
var base = Iris.instance.getDataFile("dump", "pv." + name + ".ttp.lz4b.bin");
86+
var section = Iris.instance.getDataFile("dump", "pv." + name + ".section.bin");
87+
88+
//extractSection(base, section, 5604930, 4397);
89+
90+
if (plate) {
91+
try (var in = CountingDataInputStream.wrap(new BufferedInputStream(new FileInputStream(base)))) {
92+
new TectonicPlate(1088, in, true);
93+
} catch (Throwable e) {
94+
e.printStackTrace();
95+
}
96+
} else Matter.read(section);
97+
if (!TectonicPlate.hasError())
98+
Iris.info("Read " + (plate ? base : section).length() + " bytes from " + (plate ? base : section).getAbsolutePath());
99+
}
100+
101+
private void extractSection(File source, File target, long offset, int length) throws IOException {
102+
var raf = new RandomAccessFile(source, "r");
103+
var bytes = new byte[length];
104+
raf.seek(offset);
105+
raf.readFully(bytes);
106+
raf.close();
107+
Files.write(target.toPath(), bytes);
108+
}
109+
82110
@Decree(description = "Test")
83111
public void dumpThreads() {
84112
try {
@@ -115,27 +143,6 @@ public void dumpThreads() {
115143
}
116144
}
117145

118-
@Decree(description = "Test")
119-
public void benchmarkMantle(
120-
@Param(description = "The world to bench", aliases = {"world"})
121-
World world
122-
) throws IOException, ClassNotFoundException {
123-
Engine engine = IrisToolbelt.access(world).getEngine();
124-
int maxHeight = engine.getTarget().getHeight();
125-
File folder = new File(Bukkit.getWorldContainer(), world.getName());
126-
int c = 0;
127-
//MCAUtil.read()
128-
129-
File tectonicplates = new File(folder, "mantle");
130-
for (File i : Objects.requireNonNull(tectonicplates.listFiles())) {
131-
TectonicPlate.read(maxHeight, i, true);
132-
c++;
133-
Iris.info("Loaded count: " + c );
134-
135-
}
136-
137-
}
138-
139146
@Decree(description = "Test")
140147
public void packBenchmark(
141148
@Param(description = "The pack to bench", aliases = {"pack"}, defaultValue = "overworld")

core/src/main/java/com/volmit/iris/core/commands/CommandIris.java

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import com.volmit.iris.Iris;
2222
import com.volmit.iris.core.IrisSettings;
2323
import com.volmit.iris.core.nms.INMS;
24-
import com.volmit.iris.core.pregenerator.ChunkUpdater;
2524
import com.volmit.iris.core.service.StudioSVC;
2625
import com.volmit.iris.core.tools.IrisToolbelt;
2726
import com.volmit.iris.engine.framework.Engine;
@@ -33,7 +32,6 @@
3332
import com.volmit.iris.util.decree.annotations.Param;
3433
import com.volmit.iris.util.decree.specialhandlers.NullablePlayerHandler;
3534
import com.volmit.iris.util.format.C;
36-
import com.volmit.iris.util.format.Form;
3735
import com.volmit.iris.util.io.IO;
3836
import com.volmit.iris.util.misc.ServerProperties;
3937
import com.volmit.iris.util.plugin.VolmitSender;
@@ -56,6 +54,7 @@
5654

5755
@Decree(name = "iris", aliases = {"ir", "irs"}, description = "Basic Command")
5856
public class CommandIris implements DecreeExecutor {
57+
private CommandUpdater updater;
5958
private CommandStudio studio;
6059
private CommandPregen pregen;
6160
private CommandSettings settings;
@@ -318,24 +317,6 @@ public static boolean deleteDirectory(File dir) {
318317
return dir.delete();
319318
}
320319

321-
@Decree(description = "Updates all chunk in the specified world")
322-
public void updater(
323-
@Param(description = "World to update chunks at")
324-
World world
325-
) {
326-
if (!IrisToolbelt.isIrisWorld(world)) {
327-
sender().sendMessage(C.GOLD + "This is not an Iris world");
328-
return;
329-
}
330-
ChunkUpdater updater = new ChunkUpdater(world);
331-
if (sender().isPlayer()) {
332-
sender().sendMessage(C.GREEN + "Updating " + world.getName() + " Total chunks: " + Form.f(updater.getChunks()));
333-
} else {
334-
Iris.info(C.GREEN + "Updating " + world.getName() + " Total chunks: " + Form.f(updater.getChunks()));
335-
}
336-
updater.start();
337-
}
338-
339320
@Decree(description = "Set aura spins")
340321
public void aura(
341322
@Param(description = "The h color value", defaultValue = "-20")

core/src/main/java/com/volmit/iris/core/commands/CommandStudio.java

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -182,17 +182,32 @@ public void regen(
182182
int rad = engine.getMantle().getRadius();
183183
var mantle = engine.getMantle().getMantle();
184184
var chunkMap = new KMap<Position2, MantleChunk>();
185-
for (int i = -(radius + rad); i <= radius + rad; i++) {
186-
for (int j = -(radius + rad); j <= radius + rad; j++) {
187-
int xx = i + x, zz = j + z;
188-
if (Math.abs(i) <= radius && Math.abs(j) <= radius) {
189-
mantle.deleteChunk(xx, zz);
190-
continue;
185+
ParallelQueueJob<Position2> prep = new ParallelQueueJob<>() {
186+
@Override
187+
public void execute(Position2 pos) {
188+
var cpos = pos.add(x, z);
189+
if (Math.abs(pos.getX()) <= radius && Math.abs(pos.getZ()) <= radius) {
190+
mantle.deleteChunk(cpos.getX(), cpos.getZ());
191+
return;
191192
}
192-
chunkMap.put(new Position2(xx, zz), mantle.getChunk(xx, zz));
193-
mantle.deleteChunk(xx, zz);
193+
chunkMap.put(cpos, mantle.getChunk(cpos.getX(), cpos.getZ()));
194+
mantle.deleteChunk(cpos.getX(), cpos.getZ());
195+
}
196+
197+
@Override
198+
public String getName() {
199+
return "Preparing Mantle";
200+
}
201+
};
202+
for (int xx = -(radius + rad); xx <= radius + rad; xx++) {
203+
for (int zz = -(radius + rad); zz <= radius + rad; zz++) {
204+
prep.queue(new Position2(xx, zz));
194205
}
195206
}
207+
CountDownLatch pLatch = new CountDownLatch(1);
208+
prep.execute(sender(), pLatch::countDown);
209+
pLatch.await();
210+
196211

197212
ParallelQueueJob<Position2> job = new ParallelQueueJob<>() {
198213
@Override
@@ -210,23 +225,26 @@ public String getName() {
210225
job.queue(new Position2(i + x, j + z));
211226
}
212227
}
213-
214228
CountDownLatch latch = new CountDownLatch(1);
215229
job.execute(sender(), latch::countDown);
216230
latch.await();
217231

218232
int sections = mantle.getWorldHeight() >> 4;
219233
chunkMap.forEach((pos, chunk) -> {
220-
var c = mantle.getChunk(pos.getX(), pos.getZ());
221-
for (MantleFlag flag : MantleFlag.values()) {
222-
c.flag(flag, chunk.isFlagged(flag));
223-
}
224-
c.clear();
225-
for (int y = 0; y < sections; y++) {
226-
var slice = chunk.get(y);
227-
if (slice == null) continue;
228-
var s = c.getOrCreate(y);
229-
slice.getSliceMap().forEach(s::putSlice);
234+
var c = mantle.getChunk(pos.getX(), pos.getZ()).use();
235+
try {
236+
for (MantleFlag flag : MantleFlag.values()) {
237+
c.flag(flag, chunk.isFlagged(flag));
238+
}
239+
c.clear();
240+
for (int y = 0; y < sections; y++) {
241+
var slice = chunk.get(y);
242+
if (slice == null) continue;
243+
var s = c.getOrCreate(y);
244+
slice.getSliceMap().forEach(s::putSlice);
245+
}
246+
} finally {
247+
c.release();
230248
}
231249
});
232250
} catch (Throwable e) {

core/src/main/java/com/volmit/iris/core/commands/CommandUpdater.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
package com.volmit.iris.core.commands;
2020

21+
import lombok.Synchronized;
2122
import org.bukkit.World;
2223

2324
import com.volmit.iris.Iris;
@@ -32,7 +33,8 @@
3233

3334
@Decree(name = "updater", origin = DecreeOrigin.BOTH, description = "Iris World Updater")
3435
public class CommandUpdater implements DecreeExecutor {
35-
private ChunkUpdater chunkUpdater;
36+
private final Object lock = new Object();
37+
private transient ChunkUpdater chunkUpdater;
3638

3739
@Decree(description = "Updates all chunk in the specified world")
3840
public void start(
@@ -43,19 +45,22 @@ public void start(
4345
sender().sendMessage(C.GOLD + "This is not an Iris world");
4446
return;
4547
}
46-
if (chunkUpdater != null) {
47-
chunkUpdater.stop();
48-
}
48+
synchronized (lock) {
49+
if (chunkUpdater != null) {
50+
chunkUpdater.stop();
51+
}
4952

50-
chunkUpdater = new ChunkUpdater(world);
51-
if (sender().isPlayer()) {
52-
sender().sendMessage(C.GREEN + "Updating " + world.getName() + C.GRAY + " Total chunks: " + Form.f(chunkUpdater.getChunks()));
53-
} else {
54-
Iris.info(C.GREEN + "Updating " + world.getName() + C.GRAY + " Total chunks: " + Form.f(chunkUpdater.getChunks()));
53+
chunkUpdater = new ChunkUpdater(world);
54+
if (sender().isPlayer()) {
55+
sender().sendMessage(C.GREEN + "Updating " + world.getName() + C.GRAY + " Total chunks: " + Form.f(chunkUpdater.getChunks()));
56+
} else {
57+
Iris.info(C.GREEN + "Updating " + world.getName() + C.GRAY + " Total chunks: " + Form.f(chunkUpdater.getChunks()));
58+
}
59+
chunkUpdater.start();
5560
}
56-
chunkUpdater.start();
5761
}
5862

63+
@Synchronized("lock")
5964
@Decree(description = "Pause the updater")
6065
public void pause( ) {
6166
if (chunkUpdater == null) {
@@ -78,6 +83,7 @@ public void pause( ) {
7883
}
7984
}
8085

86+
@Synchronized("lock")
8187
@Decree(description = "Stops the updater")
8288
public void stop() {
8389
if (chunkUpdater == null) {

0 commit comments

Comments
 (0)