mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 08:44:50 +00:00
Merge upstream port lane b
This commit is contained in:
commit
c448da1155
82 files changed
+2029
-881
No files matched your search
+12
@@ -1131,6 +1131,18 @@ public class NMSBinding implements INMSBinding {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean pollChunkTask(World world) {
|
||||
if (J.isFolia()) {
|
||||
return false;
|
||||
}
|
||||
ServerLevel level = ((CraftWorld) world).getHandle();
|
||||
if (Thread.currentThread() != level.getServer().getRunningThread()) {
|
||||
throw new IllegalStateException("Native chunk tasks can only be polled from the server thread.");
|
||||
}
|
||||
return level.getChunkSource().pollTask();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flushChunkIO(World world) {
|
||||
try {
|
||||
|
||||
+11
@@ -18,6 +18,17 @@ public class NMSBindingShutdownBoundaryContractTest {
|
||||
assertTrue(boundary.contains("server.getRunningThread()"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void chunkTaskPollingIsServerThreadOnlyAndSkipsFolia() throws Exception {
|
||||
String source = Files.readString(Path.of(System.getProperty("iris.nmsBindingSource"))).replace("\r\n", "\n");
|
||||
String polling = section(source, "public boolean pollChunkTask", "public void flushChunkIO");
|
||||
|
||||
int foliaGuard = polling.indexOf("J.isFolia()");
|
||||
int ownerGuard = polling.indexOf("level.getServer().getRunningThread()");
|
||||
int poll = polling.indexOf("level.getChunkSource().pollTask()");
|
||||
assertTrue(foliaGuard >= 0 && ownerGuard > foliaGuard && poll > ownerGuard);
|
||||
}
|
||||
|
||||
private static String section(String source, String startMarker, String endMarker) {
|
||||
int start = source.indexOf(startMarker);
|
||||
int end = source.indexOf(endMarker, start);
|
||||
|
||||
@@ -39,6 +39,7 @@ import art.arcane.iris.core.SettingsHotloadWatch;
|
||||
import art.arcane.iris.core.ServerConfigurator;
|
||||
import art.arcane.iris.core.datapack.DatapackIngestService;
|
||||
import art.arcane.iris.core.datapack.DatapackIngestService.StartupValidationOutcome;
|
||||
import art.arcane.iris.core.lifecycle.IrisRuntimeStatics;
|
||||
import art.arcane.iris.core.lifecycle.ManagedWorldLoader;
|
||||
import art.arcane.iris.core.lifecycle.MissingWorldStorageLog;
|
||||
import art.arcane.iris.core.lifecycle.PaperLibBootstrap;
|
||||
@@ -205,16 +206,23 @@ public class Iris extends VolmitPlugin implements Listener, ReloadAware {
|
||||
private volatile Thread serverLifecycleThread;
|
||||
|
||||
public static VolmitSender getSender() {
|
||||
if (sender == null) {
|
||||
sender = new VolmitSender(Bukkit.getConsoleSender());
|
||||
sender.setTag(instance.getTag());
|
||||
VolmitSender current = sender;
|
||||
if (current == null) {
|
||||
Iris plugin = instance;
|
||||
current = new VolmitSender(Bukkit.getConsoleSender());
|
||||
current.setTag(plugin == null ? IrisSafeguard.mode().tag("") : plugin.getTag());
|
||||
sender = current;
|
||||
}
|
||||
return sender;
|
||||
return current;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T service(Class<T> c) {
|
||||
return (T) instance.services.get(c);
|
||||
Iris plugin = instance;
|
||||
if (plugin == null || plugin.services == null) {
|
||||
throw new IllegalStateException("Iris is disabled; " + c.getSimpleName() + " is unavailable");
|
||||
}
|
||||
return (T) plugin.services.get(c);
|
||||
}
|
||||
|
||||
public static void callEvent(Event e) {
|
||||
@@ -253,7 +261,11 @@ public class Iris extends VolmitPlugin implements Listener, ReloadAware {
|
||||
}
|
||||
|
||||
public static File getTemp() {
|
||||
return instance.getDataFolder("cache", "temp");
|
||||
Iris plugin = instance;
|
||||
if (plugin == null) {
|
||||
throw new IllegalStateException("Iris is disabled; the temp folder is unavailable");
|
||||
}
|
||||
return plugin.getDataFolder("cache", "temp");
|
||||
}
|
||||
|
||||
public static void msg(String string) {
|
||||
@@ -522,11 +534,11 @@ public class Iris extends VolmitPlugin implements Listener, ReloadAware {
|
||||
Iris::msg,
|
||||
Iris::reportError,
|
||||
(event) -> Iris.callEvent((org.bukkit.event.Event) event),
|
||||
() -> Iris.instance.getDataFolder(),
|
||||
(path) -> Iris.instance.getDataFile(path),
|
||||
() -> Iris.instance.getJarFile(),
|
||||
() -> Iris.instance.getIrisVersion(),
|
||||
() -> Iris.instance.getMCVersion()));
|
||||
this::getDataFolder,
|
||||
this::getDataFile,
|
||||
this::getJarFile,
|
||||
this::getIrisVersion,
|
||||
this::getMCVersion));
|
||||
SlimJar.load();
|
||||
}
|
||||
|
||||
@@ -951,10 +963,19 @@ public class Iris extends VolmitPlugin implements Listener, ReloadAware {
|
||||
J.attempt(MultiBurst.burst::close);
|
||||
J.attempt(MultiBurst.ioBurst::close);
|
||||
clearQueues();
|
||||
IrisServices.clear();
|
||||
IrisRuntimeStatics.reset();
|
||||
releaseStatics();
|
||||
}
|
||||
}
|
||||
|
||||
private static void releaseStatics() {
|
||||
linkMultiverseCore = null;
|
||||
compat = null;
|
||||
tickets = null;
|
||||
sender = null;
|
||||
instance = null;
|
||||
}
|
||||
|
||||
private void quiesceRuntimeForServerShutdown(String reason) {
|
||||
serverStopTeardownDeferred.set(true);
|
||||
JigsawStudioService jigsawStudioService = IrisServices.getOrNull(JigsawStudioService.class);
|
||||
@@ -972,7 +993,16 @@ public class Iris extends VolmitPlugin implements Listener, ReloadAware {
|
||||
StudioBridges.closeAll();
|
||||
|
||||
try {
|
||||
PregeneratorJob.shutdownAndWait(SERVER_STOP_PREGEN_TIMEOUT_MILLIS);
|
||||
if (J.isFolia()) {
|
||||
PregeneratorJob.shutdownAndWait(SERVER_STOP_PREGEN_TIMEOUT_MILLIS);
|
||||
} else {
|
||||
List<World> worlds = Bukkit.getWorlds();
|
||||
PregeneratorJob.shutdownAndWait(SERVER_STOP_PREGEN_TIMEOUT_MILLIS, () -> {
|
||||
for (World world : worlds) {
|
||||
INMS.get().pollChunkTask(world);
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
Iris.reportError("Failed to quiesce the Iris pregenerator before server shutdown.", e);
|
||||
}
|
||||
@@ -1067,6 +1097,7 @@ public class Iris extends VolmitPlugin implements Listener, ReloadAware {
|
||||
Iris.reportError("Failed to run Iris post-shutdown cleanup.", e);
|
||||
} finally {
|
||||
IrisPlatforms.unbind();
|
||||
BukkitPlatform.releaseHost();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1248,7 +1279,7 @@ public class Iris extends VolmitPlugin implements Listener, ReloadAware {
|
||||
}
|
||||
|
||||
public int getIrisVersion() {
|
||||
String input = Iris.instance.getDescription().getVersion();
|
||||
String input = getDescription().getVersion();
|
||||
int hyphenIndex = input.indexOf('-');
|
||||
if (hyphenIndex != -1) {
|
||||
String result = input.substring(0, hyphenIndex);
|
||||
|
||||
+1
-1
@@ -159,7 +159,7 @@ public final class BukkitEnginePlatformHooks implements EnginePlatformHooks {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldBypassMantleStages(Engine engine) {
|
||||
public boolean shouldRefuseGeneration(Engine engine) {
|
||||
if (!J.isFolia() || !engine.getWorld().hasPlatformWorld()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package art.arcane.iris;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
|
||||
public class IrisDisabledStaticsTest {
|
||||
@Test
|
||||
public void serviceLookupAfterDisableStatesThatIrisIsDisabled() {
|
||||
assertNull(Iris.instance);
|
||||
|
||||
IllegalStateException failure = assertThrows(IllegalStateException.class, () -> Iris.service(Runnable.class));
|
||||
|
||||
assertEquals("Iris is disabled; Runnable is unavailable", failure.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tempFolderAfterDisableStatesThatIrisIsDisabled() {
|
||||
assertNull(Iris.instance);
|
||||
|
||||
IllegalStateException failure = assertThrows(IllegalStateException.class, Iris::getTemp);
|
||||
|
||||
assertEquals("Iris is disabled; the temp folder is unavailable", failure.getMessage());
|
||||
}
|
||||
}
|
||||
+4
-1
@@ -52,7 +52,10 @@ public class BukkitEngineLifecycleContractTest {
|
||||
String waitedShutdown = method(jobSource,
|
||||
"private static boolean shutdownAndWait(PregeneratorJob inst, long timeoutMs)");
|
||||
assertBefore(waitedShutdown, "inst.worker.interrupt()", "inst.worker.join(");
|
||||
assertTrue(waitedShutdown.contains("inst.worker.isAlive()"));
|
||||
assertBefore(waitedShutdown, "inst.worker.join(", "finishShutdown(inst, timeoutMs)");
|
||||
String finishedShutdown = method(jobSource,
|
||||
"private static boolean finishShutdown(PregeneratorJob inst, long timeoutMs)");
|
||||
assertBefore(finishedShutdown, "inst.worker.isAlive()", "instance.compareAndSet(inst, null)");
|
||||
|
||||
String hooksSource = Files.readString(Path.of(System.getProperty("iris.bukkitEnginePlatformHooksSource")));
|
||||
String hookShutdown = method(hooksSource, "public void shutdownPregenerator(Engine engine)");
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.volmit.generation;
|
||||
|
||||
/** Marks an exception that says the engine, not one piece of content, failed: a closed session, a stopping runtime. The
|
||||
* placement code that skips a failed piece lets it through instead; see {@link GenerationFailures}.
|
||||
*/
|
||||
public interface EngineFailure {
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
package com.volmit.generation;
|
||||
|
||||
import com.volmit.ModuleLog;
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.util.concurrent.CancellationException;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.RejectedExecutionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/** Tells failures of the engine, its executors or the JVM from failures of one piece of content. Code that places a
|
||||
* list of objects or decorations may skip a piece that fails, because every rebuild skips it the same way. An engine
|
||||
* failure is transient, so skipping it would leave a half-built chunk that a healthy engine never produces: it must
|
||||
* end the chunk instead.
|
||||
*/
|
||||
public final class GenerationFailures {
|
||||
private static final int MAXIMUM_CAUSE_DEPTH = 32;
|
||||
private static final int MAXIMUM_SKIP_KEYS = 512;
|
||||
private static final String OVERFLOW_SKIP_KEY = "overflow";
|
||||
private static final String PACKAGE_PREFIX = "art.arcane.";
|
||||
static final long SKIP_WARNING_INTERVAL_NANOS = 60_000_000_000L;
|
||||
private static final ConcurrentHashMap<String, SkipWarning> SKIP_WARNINGS = new ConcurrentHashMap<>();
|
||||
|
||||
private GenerationFailures() {
|
||||
}
|
||||
|
||||
/** Whether {@code failure} or one of its causes is an {@link Error}, an {@link EngineFailure}, an I/O or timeout
|
||||
* failure, or a stopping executor or thread; any failure on an interrupted thread counts too.
|
||||
*/
|
||||
public static boolean isEngineFailure(Throwable failure) {
|
||||
return Thread.currentThread().isInterrupted() || hasCause(failure, cause -> cause instanceof Error
|
||||
|| cause instanceof EngineFailure
|
||||
|| cause instanceof IOException
|
||||
|| cause instanceof UncheckedIOException
|
||||
|| cause instanceof TimeoutException
|
||||
|| cause instanceof InterruptedException
|
||||
|| cause instanceof RejectedExecutionException
|
||||
|| cause instanceof CancellationException);
|
||||
}
|
||||
|
||||
/** Throws {@code failure} when it is an engine failure, so a catch block can call it first and then handle the
|
||||
* content failures that remain. A checked failure is wrapped in an {@link IllegalStateException}.
|
||||
*/
|
||||
public static void rethrowEngineFailure(Throwable failure) {
|
||||
if (!isEngineFailure(failure)) {
|
||||
return;
|
||||
}
|
||||
if (failure instanceof RuntimeException runtimeFailure) {
|
||||
throw runtimeFailure;
|
||||
}
|
||||
if (failure instanceof Error error) {
|
||||
throw error;
|
||||
}
|
||||
if (failure instanceof InterruptedException) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
throw new IllegalStateException("Iris generation stopped: " + failure, failure);
|
||||
}
|
||||
|
||||
/** Ends one failed placement: an engine failure leaves through {@link #rethrowEngineFailure}, anything else is one
|
||||
* warning on {@code log} per minute for each {@code kind}, {@code subject} and failure type, counting the ones
|
||||
* skipped meanwhile, and the caller moves on. The limit only decides what is logged, never what is placed.
|
||||
*
|
||||
* @param kind what was being placed, such as {@code decoration}
|
||||
* @param subject the pack content that failed, such as a block or an object name; it keys the warning, so it must
|
||||
* not hold a coordinate
|
||||
* @param where where it failed, such as {@code at 1,2,3}; it is only printed
|
||||
*/
|
||||
public static void skipPlacement(ModuleLog log, Throwable failure, String kind, String subject, String where) {
|
||||
rethrowEngineFailure(failure);
|
||||
long suppressed = claimSkipWarning(kind + '|' + subject + '|' + failure.getClass().getName(), System.nanoTime());
|
||||
if (suppressed >= 0L) {
|
||||
log.warn(skipWarning(kind, subject, where, failure, suppressed));
|
||||
}
|
||||
}
|
||||
|
||||
static long claimSkipWarning(String key, long now) {
|
||||
SkipWarning warning = SKIP_WARNINGS.get(key);
|
||||
if (warning == null) {
|
||||
String resolved = SKIP_WARNINGS.size() >= MAXIMUM_SKIP_KEYS ? OVERFLOW_SKIP_KEY : key;
|
||||
warning = SKIP_WARNINGS.computeIfAbsent(resolved, ignored -> new SkipWarning(now - SKIP_WARNING_INTERVAL_NANOS));
|
||||
}
|
||||
return warning.claim(now);
|
||||
}
|
||||
|
||||
static String skipWarning(String kind, String subject, String where, Throwable failure, long suppressed) {
|
||||
String message = failure.getMessage() == null ? "" : ": " + failure.getMessage().replaceAll("\\s+", " ");
|
||||
StringBuilder line = new StringBuilder("Skipped ").append(kind).append(' ').append(subject)
|
||||
.append(' ').append(where).append(": ").append(failure.getClass().getSimpleName()).append(message);
|
||||
StackTraceElement origin = origin(failure);
|
||||
if (origin != null) {
|
||||
String className = origin.getClassName();
|
||||
line.append(" (").append(className.substring(className.lastIndexOf('.') + 1)).append('.')
|
||||
.append(origin.getMethodName()).append(')');
|
||||
}
|
||||
if (suppressed > 0L) {
|
||||
line.append(", ").append(suppressed).append(" more");
|
||||
}
|
||||
return line.toString();
|
||||
}
|
||||
|
||||
private static StackTraceElement origin(Throwable failure) {
|
||||
StackTraceElement[] frames = failure.getStackTrace();
|
||||
for (StackTraceElement frame : frames) {
|
||||
if (frame.getClassName().startsWith(PACKAGE_PREFIX)) {
|
||||
return frame;
|
||||
}
|
||||
}
|
||||
return frames.length == 0 ? null : frames[0];
|
||||
}
|
||||
|
||||
private static boolean hasCause(Throwable failure, Predicate<Throwable> match) {
|
||||
Throwable current = failure;
|
||||
for (int depth = 0; current != null && depth < MAXIMUM_CAUSE_DEPTH; depth++, current = current.getCause()) {
|
||||
if (match.test(current)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static final class SkipWarning {
|
||||
private final AtomicLong last;
|
||||
private final AtomicLong suppressed = new AtomicLong();
|
||||
|
||||
private SkipWarning(long start) {
|
||||
last = new AtomicLong(start);
|
||||
}
|
||||
|
||||
private long claim(long now) {
|
||||
long previous = last.get();
|
||||
if (now - previous >= SKIP_WARNING_INTERVAL_NANOS && last.compareAndSet(previous, now)) {
|
||||
return suppressed.getAndSet(0L);
|
||||
}
|
||||
suppressed.incrementAndGet();
|
||||
return -1L;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
package com.volmit.generation;
|
||||
|
||||
import com.volmit.ModuleLog;
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletionException;
|
||||
import java.util.concurrent.RejectedExecutionException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class GenerationFailuresTest {
|
||||
private static final long START_NANOS = 1_000_000_000L;
|
||||
|
||||
private static final class ClosedSession extends Exception implements EngineFailure {
|
||||
ClosedSession(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
private static ModuleLog logInto(List<String> warnings) {
|
||||
return (ModuleLog) Proxy.newProxyInstance(ModuleLog.class.getClassLoader(), new Class<?>[] {ModuleLog.class},
|
||||
(proxy, method, arguments) -> {
|
||||
if (method.getName().equals("warn")) {
|
||||
warnings.add((String) arguments[0]);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void engineFailuresAreRecognizedThroughWrappers() {
|
||||
assertTrue(GenerationFailures.isEngineFailure(new ClosedSession("sealed")));
|
||||
assertTrue(GenerationFailures.isEngineFailure(new RejectedExecutionException("pool shut down")));
|
||||
assertTrue(GenerationFailures.isEngineFailure(new OutOfMemoryError()));
|
||||
assertTrue(GenerationFailures.isEngineFailure(new UncheckedIOException(new IOException("plate read"))));
|
||||
assertTrue(GenerationFailures.isEngineFailure(new CompletionException(
|
||||
new IllegalStateException("placement failed", new ClosedSession("sealed")))));
|
||||
}
|
||||
|
||||
@Test
|
||||
void contentFailuresAreNotEngineFailures() {
|
||||
assertFalse(GenerationFailures.isEngineFailure(new IllegalArgumentException("malformed object")));
|
||||
assertFalse(GenerationFailures.isEngineFailure(new NullPointerException("missing block")));
|
||||
assertFalse(GenerationFailures.isEngineFailure(new IllegalStateException("unrelated")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void anyFailureOnAnInterruptedThreadIsAnEngineFailure() {
|
||||
Thread.currentThread().interrupt();
|
||||
try {
|
||||
assertTrue(GenerationFailures.isEngineFailure(new IllegalArgumentException("malformed object")));
|
||||
} finally {
|
||||
Thread.interrupted();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void rethrowPropagatesEngineFailuresAndReturnsForContentFailures() {
|
||||
var closed = new IllegalStateException("closed", new RejectedExecutionException());
|
||||
assertSame(closed, assertThrows(IllegalStateException.class, () -> GenerationFailures.rethrowEngineFailure(closed)));
|
||||
|
||||
var checked = new ClosedSession("sealed");
|
||||
var wrapped = assertThrows(IllegalStateException.class, () -> GenerationFailures.rethrowEngineFailure(checked));
|
||||
assertSame(checked, wrapped.getCause());
|
||||
|
||||
var error = new OutOfMemoryError();
|
||||
assertSame(error, assertThrows(OutOfMemoryError.class, () -> GenerationFailures.rethrowEngineFailure(error)));
|
||||
|
||||
GenerationFailures.rethrowEngineFailure(new IllegalArgumentException("malformed object"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void skippedPlacementRethrowsEngineFailuresAndWarnsOnContentFailures() {
|
||||
var warnings = new ArrayList<String>();
|
||||
var log = logInto(warnings);
|
||||
GenerationFailures.skipPlacement(log, new IllegalArgumentException("Invalid\nblockFace"),
|
||||
"decoration", "minecraft:vine", "at 1,2,3");
|
||||
assertEquals(1, warnings.size());
|
||||
assertTrue(warnings.get(0).startsWith(
|
||||
"Skipped decoration minecraft:vine at 1,2,3: IllegalArgumentException: Invalid blockFace ("), warnings.get(0));
|
||||
assertTrue(warnings.get(0).contains("GenerationFailuresTest."), warnings.get(0));
|
||||
|
||||
var closed = new ClosedSession("sealed");
|
||||
var thrown = assertThrows(IllegalStateException.class,
|
||||
() -> GenerationFailures.skipPlacement(log, closed, "decoration", "minecraft:vine", "at 1,2,3"));
|
||||
assertSame(closed, thrown.getCause());
|
||||
assertEquals(1, warnings.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void repeatedSkipsAreLimitedPerKeyAndCountedOnTheNextLine() {
|
||||
assertEquals(0L, GenerationFailures.claimSkipWarning("limit-test", START_NANOS));
|
||||
assertEquals(-1L, GenerationFailures.claimSkipWarning("limit-test", START_NANOS + 1L));
|
||||
assertEquals(-1L, GenerationFailures.claimSkipWarning("limit-test", START_NANOS + 2L));
|
||||
assertEquals(0L, GenerationFailures.claimSkipWarning("limit-test-other", START_NANOS + 2L));
|
||||
assertEquals(2L, GenerationFailures.claimSkipWarning("limit-test",
|
||||
START_NANOS + GenerationFailures.SKIP_WARNING_INTERVAL_NANOS + 1L));
|
||||
}
|
||||
|
||||
@Test
|
||||
void theSkipWarningNamesTheFirstIrisFrameAndTheSuppressedCount() {
|
||||
var failure = new IllegalArgumentException("bad");
|
||||
failure.setStackTrace(new StackTraceElement[] {
|
||||
new StackTraceElement("java.util.HashMap", "get", "HashMap.java", 1),
|
||||
new StackTraceElement("art.arcane.iris.engine.decorator.DecoratorCore", "place", "DecoratorCore.java", 2)});
|
||||
assertEquals("Skipped decoration minecraft:vine at 1,2,3: IllegalArgumentException: bad (DecoratorCore.place), 4 more",
|
||||
GenerationFailures.skipWarning("decoration", "minecraft:vine", "at 1,2,3", failure, 4L));
|
||||
}
|
||||
}
|
||||
+1
-4
@@ -265,9 +265,7 @@ if (runningOnlyTestTasks) {
|
||||
// the reference graph over the shipped jar and fails on any dangling reference, so an exclude that stops being dead is a
|
||||
// build failure rather than a runtime crash.
|
||||
List<String> irisPackagesLeftOut = [
|
||||
'art/arcane/iris/core/report/**',
|
||||
'art/arcane/iris/util/common/inventorygui/**',
|
||||
'art/arcane/iris/util/common/board/**'
|
||||
'art/arcane/iris/core/report/**'
|
||||
]
|
||||
|
||||
List<String> irisClassesLeftOut = [
|
||||
@@ -280,7 +278,6 @@ List<String> irisClassesLeftOut = [
|
||||
'art/arcane/iris/engine/object/placement/IPostBlockAccess',
|
||||
'art/arcane/iris/engine/object/entity/IrisPotionEffect',
|
||||
'art/arcane/iris/engine/platform/DummyChunkGenerator',
|
||||
'art/arcane/iris/util/common/math/VectorMath',
|
||||
'art/arcane/iris/util/common/parallel/GridLock',
|
||||
'art/arcane/iris/util/common/reflect/W',
|
||||
'art/arcane/iris/util/slimjar/BuildConstants',
|
||||
|
||||
@@ -144,12 +144,8 @@ art/arcane/iris/util/common/director/handlers/VectorHandler.java
|
||||
art/arcane/iris/util/common/director/handlers/WorldHandler.java
|
||||
art/arcane/iris/util/common/director/specialhandlers/NullablePlayerHandler.java
|
||||
art/arcane/iris/util/common/format/C.java
|
||||
art/arcane/iris/util/common/inventorygui/UIStaticDecorator.java
|
||||
art/arcane/iris/util/common/inventorygui/Window.java
|
||||
art/arcane/iris/util/common/inventorygui/WindowResolution.java
|
||||
art/arcane/iris/util/common/math/AxisAlignedBB.java
|
||||
art/arcane/iris/util/common/math/Direction.java
|
||||
art/arcane/iris/util/common/math/VectorMath.java
|
||||
art/arcane/iris/util/common/misc/Bindings.java
|
||||
art/arcane/iris/util/common/nbt/mca/Chunk.java
|
||||
art/arcane/iris/util/common/nbt/mca/NBTWorld.java
|
||||
|
||||
@@ -158,6 +158,16 @@ public class ServerConfigurator {
|
||||
}
|
||||
}
|
||||
|
||||
public static void resetLoadedDatapackRuntime() {
|
||||
synchronized (DATAPACK_INSTALL_LOCK) {
|
||||
loadedDatapackRuntimeReady = false;
|
||||
loadedDatapackCompilerInputFingerprint = "";
|
||||
loadedDatapackRegistryRequirements = Map.of();
|
||||
loadedDatapackRuntimeGeneration++;
|
||||
loadedDatapackRestartRequired = false;
|
||||
}
|
||||
}
|
||||
|
||||
public static LoadedDatapackRuntimeInvalidation invalidateLoadedDatapackRuntime() {
|
||||
synchronized (DATAPACK_INSTALL_LOCK) {
|
||||
boolean wasReady = loadedDatapackRuntimeReady;
|
||||
|
||||
@@ -43,6 +43,7 @@ import art.arcane.iris.util.common.scheduling.J;
|
||||
import java.awt.Color;
|
||||
import java.awt.EventQueue;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
@@ -57,6 +58,7 @@ public class PregeneratorJob implements PregenListener, PregenRenderSource {
|
||||
// 60s permit drain + 120s flush + plate reclaim), or a routine drain trips the deadline
|
||||
// and aborts the engine shutdown sequence mid-teardown.
|
||||
private static final long WORLD_SHUTDOWN_TIMEOUT_MILLIS = 200_000L;
|
||||
private static final long PENDING_TASK_POLL_MILLIS = 1L;
|
||||
private static final Color COLOR_EXISTS = parseColor("#4d7d5b");
|
||||
private static final Color COLOR_BLACK = parseColor("#4d7d5b");
|
||||
private static final Color COLOR_MANTLE = parseColor("#3c2773");
|
||||
@@ -203,6 +205,29 @@ public class PregeneratorJob implements PregenListener, PregenRenderSource {
|
||||
return shutdownAndWait(inst, timeoutMs);
|
||||
}
|
||||
|
||||
public static boolean shutdownAndWait(long timeoutMs, Runnable processPendingTasks) {
|
||||
Objects.requireNonNull(processPendingTasks, "processPendingTasks");
|
||||
PregeneratorJob inst = instance.get();
|
||||
if (inst == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
inst.pregenerator.close();
|
||||
inst.worker.interrupt();
|
||||
long started = System.nanoTime();
|
||||
long timeoutNanos = TimeUnit.MILLISECONDS.toNanos(Math.max(1L, timeoutMs));
|
||||
try {
|
||||
while (inst.worker.isAlive() && System.nanoTime() - started < timeoutNanos) {
|
||||
processPendingTasks.run();
|
||||
inst.worker.join(PENDING_TASK_POLL_MILLIS);
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
throw new IllegalStateException("Interrupted while stopping the Iris pregenerator.", e);
|
||||
}
|
||||
return finishShutdown(inst, timeoutMs);
|
||||
}
|
||||
|
||||
private static boolean shutdownAndWait(PregeneratorJob inst, long timeoutMs) {
|
||||
inst.pregenerator.close();
|
||||
inst.worker.interrupt();
|
||||
@@ -212,6 +237,10 @@ public class PregeneratorJob implements PregenListener, PregenRenderSource {
|
||||
Thread.currentThread().interrupt();
|
||||
throw new IllegalStateException("Interrupted while stopping the Iris pregenerator.", e);
|
||||
}
|
||||
return finishShutdown(inst, timeoutMs);
|
||||
}
|
||||
|
||||
private static boolean finishShutdown(PregeneratorJob inst, long timeoutMs) {
|
||||
if (inst.worker.isAlive()) {
|
||||
throw new IllegalStateException("Timed out while stopping the Iris pregenerator after "
|
||||
+ Math.max(1L, timeoutMs) + "ms.");
|
||||
@@ -224,6 +253,14 @@ public class PregeneratorJob implements PregenListener, PregenRenderSource {
|
||||
return instance.get();
|
||||
}
|
||||
|
||||
public static void reportChunkGenerationFailure(String worldIdentity, int chunkX, int chunkZ, Throwable failure) {
|
||||
PregeneratorJob inst = instance.get();
|
||||
if (inst == null || !inst.targetsWorldIdentity(worldIdentity)) {
|
||||
return;
|
||||
}
|
||||
inst.pregenerator.onChunkGenerationFailed(chunkX, chunkZ, failure);
|
||||
}
|
||||
|
||||
public static boolean pauseResume() {
|
||||
PregeneratorJob inst = instance.get();
|
||||
if (inst == null) {
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package art.arcane.iris.core.lifecycle;
|
||||
|
||||
import art.arcane.iris.core.ServerConfigurator;
|
||||
import art.arcane.iris.core.localization.IrisLanguage;
|
||||
import art.arcane.iris.core.runtime.WorldRuntimeControlService;
|
||||
import art.arcane.iris.spi.IrisServices;
|
||||
|
||||
/**
|
||||
* Drops every process-wide cache core keeps about the running server, so a disable leaves nothing an
|
||||
* enable in the same JVM could answer from. The host bindings are not cleared here: core still logs
|
||||
* through them while the adapter finishes its own teardown.
|
||||
*/
|
||||
public final class IrisRuntimeStatics {
|
||||
private IrisRuntimeStatics() {
|
||||
}
|
||||
|
||||
public static void reset() {
|
||||
IrisServices.clear();
|
||||
WorldLifecycleService.reset();
|
||||
WorldRuntimeControlService.reset();
|
||||
ServerConfigurator.resetLoadedDatapackRuntime();
|
||||
IrisLanguage.shutdown();
|
||||
}
|
||||
}
|
||||
@@ -51,6 +51,12 @@ public final class WorldLifecycleService {
|
||||
this.worldBackendByKey = new ConcurrentHashMap<>();
|
||||
}
|
||||
|
||||
public static void reset() {
|
||||
synchronized (WorldLifecycleService.class) {
|
||||
instance = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static WorldLifecycleService get() {
|
||||
WorldLifecycleService current = instance;
|
||||
if (current != null) {
|
||||
|
||||
@@ -78,6 +78,11 @@ public final class IrisLanguage {
|
||||
private IrisLanguage() {
|
||||
}
|
||||
|
||||
public static synchronized void shutdown() {
|
||||
dataFolder = null;
|
||||
PLAIN_MEMO.set(null);
|
||||
}
|
||||
|
||||
public static boolean initialize() {
|
||||
if (!IrisPlatforms.isBound()) {
|
||||
return false;
|
||||
|
||||
@@ -60,9 +60,6 @@ public final class CustomModule implements IrisModule {
|
||||
|
||||
private static void record(ChunkStageContext context) {
|
||||
IrisChunk chunk = context.extension(IrisChunk.class).orElseThrow();
|
||||
if (chunk.bypassesMantleStages()) {
|
||||
return;
|
||||
}
|
||||
chunk.state(CustomBlockRecording.class, CustomBlockRecording::new).record(chunk.originX(), chunk.originZ(), chunk.blocks(), chunk.multicore());
|
||||
}
|
||||
|
||||
|
||||
@@ -90,9 +90,4 @@ public final class IrisChunk {
|
||||
public <T> T state(Class<T> type, Function<Engine, T> create) {
|
||||
return engine.getGeneration().state(type, create);
|
||||
}
|
||||
|
||||
/** Whether stages backed by the mantle skip this chunk, as maintenance regeneration on Folia requires. */
|
||||
public boolean bypassesMantleStages() {
|
||||
return engine.getGeneration().bypassesMantleStages();
|
||||
}
|
||||
}
|
||||
@@ -37,8 +37,7 @@ import java.util.function.BooleanSupplier;
|
||||
* The blocks Iris's mantle holds for chunks to take over, IrisApi's {@link com.volmit.mantle.Mantle#blocks()}: what object
|
||||
* and structure placements wrote into the mantle's block slice, read as IrisApi block states over the chunks one
|
||||
* invocation may touch. Stages only read them. A dimension that keeps no mantle ({@code useMantle: false}) holds none,
|
||||
* even where an older mantle file still has some, as Iris never copied those into chunks; neither does a chunk that
|
||||
* generates without its mantle (maintenance regeneration on Folia, {@link art.arcane.iris.engine.framework.EngineGeneration#bypassesMantleStages()}).
|
||||
* even where an older mantle file still has some, as Iris never copied those into chunks.
|
||||
*/
|
||||
final class PlannedBlocks implements MantleLayer<BlockState> {
|
||||
private static final int CHUNK_SHIFT = 4;
|
||||
@@ -64,7 +63,7 @@ final class PlannedBlocks implements MantleLayer<BlockState> {
|
||||
/** The planned blocks of {@code engine}'s mantle in {@code bounds}, converted with the invocation's {@code states}. */
|
||||
static PlannedBlocks of(Engine engine, BlockBox bounds, IrisModuleMantle.Chunks chunks, PlatformBlockStates states) {
|
||||
return new PlannedBlocks(bounds, chunks, states,
|
||||
() -> engine.getDimension().isUseMantle() && !engine.getGeneration().bypassesMantleStages());
|
||||
() -> engine.getDimension().isUseMantle());
|
||||
}
|
||||
|
||||
/** No planned blocks in {@code bounds}, as in a dimension that keeps no mantle. */
|
||||
|
||||
@@ -223,6 +223,10 @@ public interface INMSBinding {
|
||||
return false;
|
||||
}
|
||||
|
||||
default boolean pollChunkTask(World world) {
|
||||
return false;
|
||||
}
|
||||
|
||||
default void flushChunkIO(World world) {
|
||||
}
|
||||
|
||||
|
||||
@@ -195,6 +195,10 @@ public class IrisPregenerator {
|
||||
shutdown.set(true);
|
||||
}
|
||||
|
||||
public void onChunkGenerationFailed(int chunkX, int chunkZ, Throwable failure) {
|
||||
generator.onChunkGenerationFailed(chunkX, chunkZ, failure);
|
||||
}
|
||||
|
||||
public void start() {
|
||||
PrecisionStopwatch p = PrecisionStopwatch.start();
|
||||
boolean completed = false;
|
||||
@@ -203,7 +207,7 @@ public class IrisPregenerator {
|
||||
// fires — leaving a phantom job that suppresses spawns and blocks future pregens.
|
||||
try {
|
||||
init();
|
||||
task.iterateAllChunks((_a, _b) -> totalChunks.incrementAndGet());
|
||||
totalChunks.set(task.chunkCount());
|
||||
long startedAt = M.ms();
|
||||
startTime.set(startedAt);
|
||||
rateTracker.reset(startedAt, generated.get());
|
||||
|
||||
+17
-16
@@ -16,27 +16,28 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.util.project.hunk;
|
||||
package art.arcane.iris.core.pregenerator;
|
||||
|
||||
public enum HunkFace {
|
||||
TOP(art.arcane.volmlib.util.hunk.HunkFace.TOP),
|
||||
BOTTOM(art.arcane.volmlib.util.hunk.HunkFace.BOTTOM),
|
||||
EAST(art.arcane.volmlib.util.hunk.HunkFace.EAST),
|
||||
WEST(art.arcane.volmlib.util.hunk.HunkFace.WEST),
|
||||
NORTH(art.arcane.volmlib.util.hunk.HunkFace.NORTH),
|
||||
SOUTH(art.arcane.volmlib.util.hunk.HunkFace.SOUTH);
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
|
||||
private final art.arcane.volmlib.util.hunk.HunkFace shared;
|
||||
|
||||
HunkFace(art.arcane.volmlib.util.hunk.HunkFace shared) {
|
||||
this.shared = shared;
|
||||
public final class PregenDiagnostics {
|
||||
private PregenDiagnostics() {
|
||||
}
|
||||
|
||||
public art.arcane.volmlib.util.hunk.HunkFace shared() {
|
||||
return shared;
|
||||
public static void probeFailed(String probe, Throwable failure) {
|
||||
IrisLogging.debug("Pregen probe " + describeProbe(probe) + " failed: " + describeFailure(failure));
|
||||
}
|
||||
|
||||
public static HunkFace fromShared(art.arcane.volmlib.util.hunk.HunkFace shared) {
|
||||
return HunkFace.valueOf(shared.name());
|
||||
public static String describeProbe(String probe) {
|
||||
return probe == null || probe.isBlank() ? "unnamed" : probe;
|
||||
}
|
||||
|
||||
public static String describeFailure(Throwable failure) {
|
||||
if (failure == null) {
|
||||
return "no throwable reported";
|
||||
}
|
||||
|
||||
String message = failure.getMessage();
|
||||
return message == null ? failure.getClass().getName() : failure.getClass().getName() + ": " + message;
|
||||
}
|
||||
}
|
||||
@@ -170,7 +170,8 @@ public final class PregenMantleBackpressure {
|
||||
|
||||
try {
|
||||
return cancelled.getAsBoolean();
|
||||
} catch (Throwable ignored) {
|
||||
} catch (Throwable e) {
|
||||
PregenDiagnostics.probeFailed("pregen cancellation state", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -178,7 +179,8 @@ public final class PregenMantleBackpressure {
|
||||
private Mantle resolveMantle() {
|
||||
try {
|
||||
return mantleSupplier.get();
|
||||
} catch (Throwable ignored) {
|
||||
} catch (Throwable e) {
|
||||
PregenDiagnostics.probeFailed("mantle handle for backpressure", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,6 +174,11 @@ public class PregenTask {
|
||||
return new int[]{bound.minX(), bound.minZ(), bound.maxX(), bound.maxZ()};
|
||||
}
|
||||
|
||||
public long chunkCount() {
|
||||
Bound bound = bounds.chunk();
|
||||
return (long) bound.sizeX() * bound.sizeZ();
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface InterleavedChunkConsumer {
|
||||
boolean on(int regionX, int regionZ, int chunkX, int chunkZ, boolean firstChunkInRegion, boolean lastChunkInRegion);
|
||||
|
||||
@@ -83,6 +83,9 @@ public interface PregeneratorMethod {
|
||||
default void onRegionBounds(int minRegionX, int minRegionZ, int maxRegionX, int maxRegionZ) {
|
||||
}
|
||||
|
||||
default void onChunkGenerationFailed(int chunkX, int chunkZ, Throwable failure) {
|
||||
}
|
||||
|
||||
default void onRegionSubmitted(int regionX, int regionZ) {
|
||||
}
|
||||
|
||||
|
||||
+5
@@ -87,6 +87,11 @@ public class AsyncOrMedievalPregenMethod implements PregeneratorMethod {
|
||||
method.onRegionBounds(minRegionX, minRegionZ, maxRegionX, maxRegionZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChunkGenerationFailed(int chunkX, int chunkZ, Throwable failure) {
|
||||
method.onChunkGenerationFailed(chunkX, chunkZ, failure);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRegionSubmitted(int regionX, int regionZ) {
|
||||
method.onRegionSubmitted(regionX, regionZ);
|
||||
|
||||
+138
-20
@@ -22,6 +22,7 @@ import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.iris.core.IrisPaperLikeBackendMode;
|
||||
import art.arcane.iris.core.IrisRuntimeSchedulerMode;
|
||||
import art.arcane.iris.core.IrisSettings;
|
||||
import art.arcane.iris.core.pregenerator.PregenDiagnostics;
|
||||
import art.arcane.iris.core.pregenerator.PregenListener;
|
||||
import art.arcane.iris.core.pregenerator.PregenMantleBackpressure;
|
||||
import art.arcane.iris.core.pregenerator.PregeneratorMethod;
|
||||
@@ -44,6 +45,7 @@ import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -56,6 +58,7 @@ import java.util.concurrent.TimeoutException;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
public class AsyncPregenMethod implements PregeneratorMethod {
|
||||
// THREAD_COUNT records the pool's original size while boosted; BOOST_HOLDERS counts live
|
||||
@@ -65,8 +68,10 @@ public class AsyncPregenMethod implements PregeneratorMethod {
|
||||
private static final AtomicInteger BOOST_HOLDERS = new AtomicInteger();
|
||||
private static final int ADAPTIVE_SLOW_REQUEST_STEP = 3;
|
||||
private static final int ADAPTIVE_RECOVERY_INTERVAL = 8;
|
||||
private static final long CLOSE_DRAIN_WARNING_SECONDS = 60L;
|
||||
private static final long CLOSE_DRAIN_WARNING_SECONDS = 20L;
|
||||
private static final long CLOSE_DRAIN_TIMEOUT_SECONDS = 60L;
|
||||
private static final long FLUSH_TIMEOUT_SECONDS = 120L;
|
||||
private static final long FLUSH_STOP_POLL_MILLIS = 100L;
|
||||
private final World world;
|
||||
private final IrisRuntimeSchedulerMode runtimeSchedulerMode;
|
||||
private final IrisPaperLikeBackendMode paperLikeBackendMode;
|
||||
@@ -108,6 +113,8 @@ public class AsyncPregenMethod implements PregeneratorMethod {
|
||||
private final AtomicLong failed = new AtomicLong();
|
||||
private final AtomicLong lastProgressAt = new AtomicLong(M.ms());
|
||||
private final AtomicBoolean closing = new AtomicBoolean();
|
||||
private final PregenInFlightRequests inFlightRequests = new PregenInFlightRequests();
|
||||
private final AtomicReference<GenerationFailure> generationFailure = new AtomicReference<>();
|
||||
private final AtomicBoolean holdsWorkerBoost = new AtomicBoolean();
|
||||
private final Object permitMonitor = new Object();
|
||||
private volatile Engine metricsEngine;
|
||||
@@ -208,7 +215,8 @@ public class AsyncPregenMethod implements PregeneratorMethod {
|
||||
if (coreThreads instanceof Thread[] threadsArray) {
|
||||
return threadsArray.length;
|
||||
}
|
||||
} catch (Throwable ignored) {
|
||||
} catch (Throwable e) {
|
||||
PregenDiagnostics.probeFailed("moonrise worker pool size", e);
|
||||
}
|
||||
|
||||
return -1;
|
||||
@@ -234,7 +242,8 @@ public class AsyncPregenMethod implements PregeneratorMethod {
|
||||
int resolved = radius > 0 ? Math.max(1, (int) Math.ceil(radius / 32.0)) : 2;
|
||||
evictionWindowRegions = resolved;
|
||||
return resolved;
|
||||
} catch (Throwable ignored) {
|
||||
} catch (Throwable e) {
|
||||
PregenDiagnostics.probeFailed("mantle radius for eviction window", e);
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
@@ -344,6 +353,9 @@ public class AsyncPregenMethod implements PregeneratorMethod {
|
||||
}
|
||||
|
||||
private void evictRegion(long c) {
|
||||
if (IrisToolbelt.isServerStopping()) {
|
||||
return;
|
||||
}
|
||||
if (!evictedRegions.add(c)) {
|
||||
return;
|
||||
}
|
||||
@@ -400,7 +412,9 @@ public class AsyncPregenMethod implements PregeneratorMethod {
|
||||
private void unloadChunkSafely(int cx, int cz) {
|
||||
try {
|
||||
world.removePluginChunkTicket(cx, cz, BukkitPlatform.plugin());
|
||||
} catch (Throwable ignored) {
|
||||
} catch (Throwable e) {
|
||||
IrisLogging.reportError("Async pregen could not release the plugin chunk ticket at " + cx + "," + cz
|
||||
+ " in world " + world.getName() + "; the chunk stays pinned in memory.", e);
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -413,6 +427,9 @@ public class AsyncPregenMethod implements PregeneratorMethod {
|
||||
}
|
||||
|
||||
private void flushAllRemainingChunks() {
|
||||
if (IrisToolbelt.isServerStopping()) {
|
||||
return;
|
||||
}
|
||||
List<Long> keys = new ArrayList<>(regionChunks.keySet());
|
||||
|
||||
if (foliaRuntime) {
|
||||
@@ -423,6 +440,9 @@ public class AsyncPregenMethod implements PregeneratorMethod {
|
||||
}
|
||||
|
||||
CompletableFuture<Void> flush = J.sfut(() -> {
|
||||
if (IrisToolbelt.isServerStopping()) {
|
||||
return;
|
||||
}
|
||||
for (Long rk : keys) {
|
||||
if (!evictedRegions.add(rk)) {
|
||||
continue;
|
||||
@@ -446,7 +466,7 @@ public class AsyncPregenMethod implements PregeneratorMethod {
|
||||
});
|
||||
|
||||
try {
|
||||
flush.get(FLUSH_TIMEOUT_SECONDS, TimeUnit.SECONDS);
|
||||
awaitFlushUnlessServerStops(flush);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
IrisLogging.warn("Interrupted while flushing pregen chunks for " + world.getName() + ".");
|
||||
@@ -458,22 +478,49 @@ public class AsyncPregenMethod implements PregeneratorMethod {
|
||||
}
|
||||
}
|
||||
|
||||
private Chunk onChunkFutureFailure(int x, int z, Throwable throwable) {
|
||||
try {
|
||||
IrisLogging.warn("Failed async pregen chunk load at " + x + "," + z + ". " + metricsSnapshot());
|
||||
private static void awaitFlushUnlessServerStops(CompletableFuture<Void> flush) throws Exception {
|
||||
long started = System.nanoTime();
|
||||
long timeoutNanos = TimeUnit.SECONDS.toNanos(FLUSH_TIMEOUT_SECONDS);
|
||||
while (!IrisToolbelt.isServerStopping()) {
|
||||
long remainingNanos = timeoutNanos - (System.nanoTime() - started);
|
||||
if (remainingNanos <= 0L) {
|
||||
throw new TimeoutException();
|
||||
}
|
||||
try {
|
||||
flush.get(Math.min(remainingNanos, TimeUnit.MILLISECONDS.toNanos(FLUSH_STOP_POLL_MILLIS)), TimeUnit.NANOSECONDS);
|
||||
return;
|
||||
} catch (TimeoutException pollElapsed) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IrisLogging.reportError(throwable);
|
||||
private Chunk onChunkFutureFailure(int x, int z, Throwable throwable) {
|
||||
IrisLogging.reportError("Failed async pregen chunk load at " + x + "," + z + ".", throwable);
|
||||
|
||||
try {
|
||||
IrisLogging.warn("Async pregen state at the failed chunk " + x + "," + z + ". " + metricsSnapshot());
|
||||
} catch (Throwable e) {
|
||||
PregenDiagnostics.probeFailed("pregen metrics snapshot", e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void completeChunk(int x, int z, PregenListener listener, Chunk chunk, Throwable throwable) {
|
||||
PregenListener owner = inFlightRequests.settle(PregenInFlightRequests.key(x, z));
|
||||
if (owner == null) {
|
||||
return;
|
||||
}
|
||||
settleChunk(x, z, owner, chunk, throwable, true);
|
||||
}
|
||||
|
||||
private void settleChunk(int x, int z, PregenListener listener, Chunk chunk, Throwable throwable, boolean reportFailure) {
|
||||
boolean success = false;
|
||||
try {
|
||||
if (throwable != null) {
|
||||
onChunkFutureFailure(x, z, throwable);
|
||||
if (reportFailure) {
|
||||
onChunkFutureFailure(x, z, throwable);
|
||||
}
|
||||
onChunkFailedToLoad(x, z);
|
||||
listener.onChunkFailed(x, z);
|
||||
} else if (chunk == null) {
|
||||
@@ -651,11 +698,53 @@ public class AsyncPregenMethod implements PregeneratorMethod {
|
||||
+ " stalledForMs=" + stalledFor;
|
||||
}
|
||||
|
||||
private void markSubmitted() {
|
||||
private void markSubmitted(int x, int z, PregenListener listener) {
|
||||
inFlightRequests.add(PregenInFlightRequests.key(x, z), listener);
|
||||
submitted.incrementAndGet();
|
||||
inFlight.incrementAndGet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChunkGenerationFailed(int chunkX, int chunkZ, Throwable failure) {
|
||||
GenerationFailure recorded = new GenerationFailure(chunkX, chunkZ, failure);
|
||||
if (generationFailure.compareAndSet(null, recorded)) {
|
||||
IrisLogging.error("Async pregen aborting: Iris failed to generate chunk " + chunkX + "," + chunkZ
|
||||
+ " and the server's chunk system will not complete the " + inFlightRequests.size()
|
||||
+ " outstanding chunk request(s). " + metricsSnapshot());
|
||||
}
|
||||
failOutstandingRequests(failure);
|
||||
}
|
||||
|
||||
private void failOutstandingRequests(Throwable failure) {
|
||||
settleAll(inFlightRequests.drain(), failure);
|
||||
}
|
||||
|
||||
private void throwIfGenerationFailed() {
|
||||
GenerationFailure failure = generationFailure.get();
|
||||
if (failure != null) {
|
||||
throw new IllegalStateException("Pregen aborted: Iris failed to generate chunk " + failure.chunkX() + ","
|
||||
+ failure.chunkZ() + " in world " + world.getName()
|
||||
+ " and the server's chunk system stopped completing requests.", failure.cause());
|
||||
}
|
||||
}
|
||||
|
||||
private void abandonOutstandingRequests(Drain drain) {
|
||||
Map<Long, PregenListener> abandoned = inFlightRequests.drain();
|
||||
IrisLogging.error("Async pregen abandoned " + abandoned.size() + " chunk request(s) that did not complete within "
|
||||
+ CLOSE_DRAIN_TIMEOUT_SECONDS + "s of closing (" + drain.outstanding()
|
||||
+ " permit(s) still held). They are not cached and regenerate on the next run. " + metricsSnapshot());
|
||||
settleAll(abandoned, new IllegalStateException(
|
||||
"Async chunk request never completed before the pregen closed in world " + world.getName() + "."));
|
||||
}
|
||||
|
||||
private void settleAll(Map<Long, PregenListener> requests, Throwable failure) {
|
||||
for (Map.Entry<Long, PregenListener> entry : requests.entrySet()) {
|
||||
long key = entry.getKey();
|
||||
settleChunk(PregenInFlightRequests.chunkX(key), PregenInFlightRequests.chunkZ(key), entry.getValue(),
|
||||
null, failure, false);
|
||||
}
|
||||
}
|
||||
|
||||
private void markFinished(boolean success) {
|
||||
if (success) {
|
||||
completed.incrementAndGet();
|
||||
@@ -697,7 +786,9 @@ public class AsyncPregenMethod implements PregeneratorMethod {
|
||||
if (engine != null) {
|
||||
try {
|
||||
engine.getMantle().forceCleanupChunk(x, z);
|
||||
} catch (Throwable ignored) {
|
||||
} catch (Throwable e) {
|
||||
IrisLogging.reportError("Async pregen mantle cleanup failed at chunk " + x + "," + z
|
||||
+ " in world " + world.getName() + "; tectonic plates for that chunk stay resident.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -718,7 +809,8 @@ public class AsyncPregenMethod implements PregeneratorMethod {
|
||||
metricsEngine = resolvedEngine;
|
||||
}
|
||||
return resolvedEngine;
|
||||
} catch (Throwable ignored) {
|
||||
} catch (Throwable e) {
|
||||
PregenDiagnostics.probeFailed("engine access for world " + world.getName(), e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -773,13 +865,18 @@ public class AsyncPregenMethod implements PregeneratorMethod {
|
||||
// A stop request interrupts the pregen worker; shield the drain and flush so chunks still hit disk.
|
||||
boolean interrupted = Thread.interrupted();
|
||||
try {
|
||||
interrupted |= awaitDrain(
|
||||
Drain drain = awaitDrain(
|
||||
semaphore,
|
||||
threads,
|
||||
CLOSE_DRAIN_WARNING_SECONDS,
|
||||
CLOSE_DRAIN_TIMEOUT_SECONDS,
|
||||
TimeUnit.SECONDS,
|
||||
() -> IrisLogging.warn("Async pregen is still draining outstanding chunks. " + metricsSnapshot())
|
||||
);
|
||||
interrupted |= drain.interrupted();
|
||||
if (!drain.drained()) {
|
||||
abandonOutstandingRequests(drain);
|
||||
}
|
||||
|
||||
flushAllRemainingChunks();
|
||||
executor.shutdown();
|
||||
@@ -793,18 +890,25 @@ public class AsyncPregenMethod implements PregeneratorMethod {
|
||||
}
|
||||
}
|
||||
|
||||
static boolean awaitDrain(
|
||||
static Drain awaitDrain(
|
||||
Semaphore semaphore,
|
||||
int permits,
|
||||
long warningInterval,
|
||||
long deadline,
|
||||
TimeUnit timeUnit,
|
||||
Runnable onWait
|
||||
) {
|
||||
long warningNanos = timeUnit.toNanos(warningInterval);
|
||||
long deadlineAt = System.nanoTime() + timeUnit.toNanos(deadline);
|
||||
boolean interrupted = false;
|
||||
while (true) {
|
||||
long remaining = deadlineAt - System.nanoTime();
|
||||
if (remaining <= 0L) {
|
||||
return new Drain(false, interrupted, permits - semaphore.availablePermits());
|
||||
}
|
||||
try {
|
||||
if (semaphore.tryAcquire(permits, warningInterval, timeUnit)) {
|
||||
return interrupted;
|
||||
if (semaphore.tryAcquire(permits, Math.min(warningNanos, remaining), TimeUnit.NANOSECONDS)) {
|
||||
return new Drain(true, interrupted, 0);
|
||||
}
|
||||
onWait.run();
|
||||
} catch (InterruptedException e) {
|
||||
@@ -814,7 +918,7 @@ public class AsyncPregenMethod implements PregeneratorMethod {
|
||||
}
|
||||
|
||||
private boolean isCancelled() {
|
||||
return closing.get() || Thread.currentThread().isInterrupted();
|
||||
return closing.get() || generationFailure.get() != null || Thread.currentThread().isInterrupted();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -833,6 +937,7 @@ public class AsyncPregenMethod implements PregeneratorMethod {
|
||||
|
||||
@Override
|
||||
public void generateChunk(int x, int z, PregenListener listener) {
|
||||
throwIfGenerationFailed();
|
||||
listener.onChunkGenerating(x, z);
|
||||
backpressure.enforceMantleBudget();
|
||||
backpressure.awaitHeapHeadroom();
|
||||
@@ -871,9 +976,14 @@ public class AsyncPregenMethod implements PregeneratorMethod {
|
||||
return;
|
||||
}
|
||||
|
||||
throwIfGenerationFailed();
|
||||
regionPending.computeIfAbsent(rkey(x >> 5, z >> 5), k -> new AtomicInteger(1)).incrementAndGet();
|
||||
markSubmitted();
|
||||
markSubmitted(x, z, listener);
|
||||
executor.generate(x, z, listener);
|
||||
GenerationFailure failure = generationFailure.get();
|
||||
if (failure != null) {
|
||||
failOutstandingRequests(failure.cause());
|
||||
}
|
||||
}
|
||||
|
||||
private CompletableFuture<Chunk> requestChunkAsync(int x, int z) {
|
||||
@@ -1053,7 +1163,9 @@ public class AsyncPregenMethod implements PregeneratorMethod {
|
||||
requestMonitoredChunkAsync(x, z)
|
||||
.whenComplete((chunk, throwable) -> completeChunk(x, z, listener, chunk, throwable));
|
||||
return;
|
||||
} catch (Throwable ignored) {
|
||||
} catch (Throwable e) {
|
||||
PregenDiagnostics.probeFailed("folia direct chunk request at " + x + "," + z
|
||||
+ ", falling back to a region task", e);
|
||||
}
|
||||
|
||||
Runnable regionTask = () -> {
|
||||
@@ -1111,6 +1223,12 @@ public class AsyncPregenMethod implements PregeneratorMethod {
|
||||
}
|
||||
}
|
||||
|
||||
record Drain(boolean drained, boolean interrupted, int outstanding) {
|
||||
}
|
||||
|
||||
private record GenerationFailure(int chunkX, int chunkZ, Throwable cause) {
|
||||
}
|
||||
|
||||
private record ChunkAsyncMethodSelection(Method urgentMethod, Method standardMethod, String mode) {
|
||||
}
|
||||
}
|
||||
@@ -175,6 +175,11 @@ public class CachedPregenMethod implements PregeneratorMethod {
|
||||
method.onRegionBounds(minRegionX, minRegionZ, maxRegionX, maxRegionZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChunkGenerationFailed(int chunkX, int chunkZ, Throwable failure) {
|
||||
method.onChunkGenerationFailed(chunkX, chunkZ, failure);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRegionSubmitted(int regionX, int regionZ) {
|
||||
method.onRegionSubmitted(regionX, regionZ);
|
||||
|
||||
@@ -80,6 +80,11 @@ public class HybridPregenMethod implements PregeneratorMethod {
|
||||
inWorld.onRegionBounds(minRegionX, minRegionZ, maxRegionX, maxRegionZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChunkGenerationFailed(int chunkX, int chunkZ, Throwable failure) {
|
||||
inWorld.onChunkGenerationFailed(chunkX, chunkZ, failure);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRegionSubmitted(int regionX, int regionZ) {
|
||||
inWorld.onRegionSubmitted(regionX, regionZ);
|
||||
|
||||
+3
-1
@@ -19,6 +19,7 @@
|
||||
package art.arcane.iris.core.pregenerator.methods;
|
||||
|
||||
import art.arcane.iris.core.IrisSettings;
|
||||
import art.arcane.iris.core.pregenerator.PregenDiagnostics;
|
||||
import art.arcane.iris.core.pregenerator.PregenListener;
|
||||
import art.arcane.iris.core.pregenerator.PregeneratorMethod;
|
||||
import art.arcane.iris.core.tools.IrisToolbelt;
|
||||
@@ -101,7 +102,8 @@ public class MedievalPregenMethod implements PregeneratorMethod {
|
||||
if (cached != null) {
|
||||
cachedEngine = cached;
|
||||
}
|
||||
} catch (Throwable ignored) {
|
||||
} catch (Throwable e) {
|
||||
PregenDiagnostics.probeFailed("engine access for world " + world.getName(), e);
|
||||
}
|
||||
return cached;
|
||||
}
|
||||
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
package art.arcane.iris.core.pregenerator.methods;
|
||||
|
||||
import art.arcane.iris.core.pregenerator.PregenListener;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public final class PregenInFlightRequests {
|
||||
private final ConcurrentHashMap<Long, PregenListener> requests = new ConcurrentHashMap<>();
|
||||
|
||||
public static long key(int chunkX, int chunkZ) {
|
||||
return ((long) chunkX << 32) | (chunkZ & 0xFFFFFFFFL);
|
||||
}
|
||||
|
||||
public static int chunkX(long key) {
|
||||
return (int) (key >> 32);
|
||||
}
|
||||
|
||||
public static int chunkZ(long key) {
|
||||
return (int) key;
|
||||
}
|
||||
|
||||
public boolean add(long key, PregenListener listener) {
|
||||
return requests.putIfAbsent(key, Objects.requireNonNull(listener, "listener")) == null;
|
||||
}
|
||||
|
||||
public PregenListener settle(long key) {
|
||||
return requests.remove(key);
|
||||
}
|
||||
|
||||
public Map<Long, PregenListener> drain() {
|
||||
HashMap<Long, PregenListener> drained = new HashMap<>();
|
||||
for (Map.Entry<Long, PregenListener> entry : requests.entrySet()) {
|
||||
if (requests.remove(entry.getKey(), entry.getValue())) {
|
||||
drained.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
return drained;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return requests.size();
|
||||
}
|
||||
}
|
||||
@@ -79,6 +79,12 @@ public final class WorldRuntimeControlService {
|
||||
+ ", " + backend.describeCapabilities();
|
||||
}
|
||||
|
||||
public static void reset() {
|
||||
synchronized (WorldRuntimeControlService.class) {
|
||||
instance = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static WorldRuntimeControlService get() {
|
||||
WorldRuntimeControlService current = instance;
|
||||
if (current != null) {
|
||||
|
||||
@@ -81,6 +81,8 @@ import java.util.function.Supplier;
|
||||
@Data
|
||||
public class IrisEngine implements Engine {
|
||||
static final long SESSION_DRAIN_TIMEOUT_MILLIS = 15000L;
|
||||
private static final long MAINTENANCE_REFUSAL_WARNING_MILLIS = 5000L;
|
||||
private static final AtomicLong lastMaintenanceRefusalWarning = new AtomicLong();
|
||||
|
||||
private final AtomicInteger bud;
|
||||
private final AtomicInteger buds;
|
||||
@@ -632,6 +634,9 @@ public class IrisEngine implements Engine {
|
||||
@Override
|
||||
public void generate(int x, int z, Hunk<PlatformBlockState> vblocks, Hunk<PlatformBiome> vbiomes, boolean multicore) throws WrongEngineBroException {
|
||||
awaitGenerationCacheWarm();
|
||||
if (platformHooks.shouldRefuseGeneration(this)) {
|
||||
refuseMaintenanceGeneration(x >> 4, z >> 4);
|
||||
}
|
||||
try (GenerationSessionLease lease = acquireGenerationLease("chunk_generate");
|
||||
IrisContext.Scope generationScope = IrisContext.open(this, lease.sessionId(), null)) {
|
||||
getEngineData().getStatistics().generatedChunk();
|
||||
@@ -649,10 +654,7 @@ public class IrisEngine implements Engine {
|
||||
getGeneration().generate(x, z, blocks, vbiomes, multicore, lease.sessionId());
|
||||
}
|
||||
|
||||
boolean skipRealFlag = platformHooks.shouldBypassMantleStages(this);
|
||||
if (!skipRealFlag) {
|
||||
getMantle().getMantle().flag(x >> 4, z >> 4, MantleFlag.REAL, true);
|
||||
}
|
||||
getMantle().getMantle().flag(x >> 4, z >> 4, MantleFlag.REAL, true);
|
||||
getMetrics().getTotal().put(p.getMilliseconds());
|
||||
generated.incrementAndGet();
|
||||
|
||||
@@ -671,6 +673,17 @@ public class IrisEngine implements Engine {
|
||||
}
|
||||
}
|
||||
|
||||
private void refuseMaintenanceGeneration(int chunkX, int chunkZ) throws GenerationSessionException {
|
||||
long now = System.currentTimeMillis();
|
||||
long last = lastMaintenanceRefusalWarning.get();
|
||||
if (now - last >= MAINTENANCE_REFUSAL_WARNING_MILLIS && lastMaintenanceRefusalWarning.compareAndSet(last, now)) {
|
||||
IrisLogging.warn("Iris refused chunk " + chunkX + "," + chunkZ + " in " + getWorld().name()
|
||||
+ ": world maintenance forbids mantle generation, the chunk stays ungenerated");
|
||||
}
|
||||
throw new GenerationSessionException("Iris refused chunk " + chunkX + "," + chunkZ + " in "
|
||||
+ getWorld().name() + " during world maintenance.", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GenerationSessionManager getGenerationSessions() {
|
||||
return generationSessions;
|
||||
|
||||
@@ -21,7 +21,6 @@ package art.arcane.iris.engine.framework;
|
||||
import art.arcane.iris.core.modules.IrisPackWorld;
|
||||
import art.arcane.iris.core.modules.ModuleChunkGeneration;
|
||||
import art.arcane.iris.core.modules.ModuleWorlds;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.iris.spi.PlatformBiome;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.util.project.context.ChunkContext;
|
||||
@@ -29,7 +28,6 @@ import art.arcane.iris.util.project.context.IrisContext;
|
||||
import art.arcane.iris.util.project.hunk.Hunk;
|
||||
import art.arcane.volmlib.util.documentation.BlockCoordinates;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
@@ -40,8 +38,6 @@ import java.util.function.Function;
|
||||
*/
|
||||
public final class EngineGeneration {
|
||||
private static final int CHUNK_SHIFT = 4;
|
||||
private static final long MAINTENANCE_LOG_INTERVAL_MILLIS = 5000L;
|
||||
private static final AtomicLong lastMaintenanceBypassLog = new AtomicLong(0L);
|
||||
|
||||
private final Engine engine;
|
||||
private final ModuleWorlds modules;
|
||||
@@ -91,18 +87,6 @@ public final class EngineGeneration {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether stages backed by the mantle skip this chunk: on Folia, maintenance regeneration runs without the
|
||||
* mantle to stay region-safe.
|
||||
*/
|
||||
public boolean bypassesMantleStages() {
|
||||
boolean bypass = engine.getPlatformHooks().shouldBypassMantleStages(engine);
|
||||
if (bypass) {
|
||||
logMaintenanceBypass();
|
||||
}
|
||||
return bypass;
|
||||
}
|
||||
|
||||
/** Writes what modules saved with the world, as the engine saves its data; see {@link com.volmit.world.RunningWorld#saved}. */
|
||||
public void saveModuleData() {
|
||||
modules.saveCurrentWorldState();
|
||||
@@ -118,17 +102,6 @@ public final class EngineGeneration {
|
||||
}
|
||||
|
||||
private void generateMantle(int x, int z, boolean multicore, ChunkContext context) {
|
||||
if (bypassesMantleStages()) {
|
||||
return;
|
||||
}
|
||||
engine.getMantle().generateMatter(x >> CHUNK_SHIFT, z >> CHUNK_SHIFT, multicore || engine.isStudio(), context);
|
||||
}
|
||||
|
||||
private static void logMaintenanceBypass() {
|
||||
long now = System.currentTimeMillis();
|
||||
long last = lastMaintenanceBypassLog.get();
|
||||
if (now - last >= MAINTENANCE_LOG_INTERVAL_MILLIS && lastMaintenanceBypassLog.compareAndSet(last, now)) {
|
||||
IrisLogging.info("Maintenance regen bypass: skipping mantle-backed stages for Folia safety.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -67,7 +67,11 @@ public interface EnginePlatformHooks {
|
||||
return false;
|
||||
}
|
||||
|
||||
default boolean shouldBypassMantleStages(Engine engine) {
|
||||
/**
|
||||
* True while world maintenance forbids the mantle-backed stages. Generating without them would persist a
|
||||
* chunk with no objects, caves or deposits, so the engine refuses the chunk instead.
|
||||
*/
|
||||
default boolean shouldRefuseGeneration(Engine engine) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package art.arcane.iris.engine.framework;
|
||||
|
||||
public class GenerationSessionException extends WrongEngineBroException {
|
||||
import com.volmit.generation.EngineFailure;
|
||||
|
||||
public class GenerationSessionException extends WrongEngineBroException implements EngineFailure {
|
||||
private final boolean expectedTeardown;
|
||||
|
||||
public GenerationSessionException(String message) {
|
||||
|
||||
@@ -24,6 +24,8 @@ import art.arcane.iris.engine.object.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.iris.util.project.matter.TileWrapper;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.volmit.generation.GenerationFailures;
|
||||
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
|
||||
import art.arcane.iris.core.IrisSettings;
|
||||
import art.arcane.iris.core.link.Identifier;
|
||||
import art.arcane.iris.core.tools.WorldMaintenance;
|
||||
@@ -130,7 +132,7 @@ public class MantleWriter implements IObjectPlacer, AutoCloseable {
|
||||
return Math.max(1, availableProcessors / 2);
|
||||
}
|
||||
|
||||
private static Set<IrisPosition> getBallooned(Set<IrisPosition> vset, double radius) {
|
||||
static Set<IrisPosition> getBallooned(Set<IrisPosition> vset, double radius) {
|
||||
Set<IrisPosition> returnset = new HashSet<>();
|
||||
int ceilrad = (int) Math.ceil(radius);
|
||||
double r2 = Math.pow(radius, 2);
|
||||
@@ -153,30 +155,83 @@ public class MantleWriter implements IObjectPlacer, AutoCloseable {
|
||||
return returnset;
|
||||
}
|
||||
|
||||
private static Set<IrisPosition> getHollowed(Set<IrisPosition> vset) {
|
||||
static Set<IrisPosition> getHollowed(Set<IrisPosition> vset) {
|
||||
PositionLookup lookup = PositionLookup.of(vset);
|
||||
Set<IrisPosition> returnset = new KSet<>();
|
||||
for (IrisPosition v : vset) {
|
||||
double x = v.getX();
|
||||
double y = v.getY();
|
||||
double z = v.getZ();
|
||||
if (!(vset.contains(new IrisPosition(x + 1, y, z))
|
||||
&& vset.contains(new IrisPosition(x - 1, y, z))
|
||||
&& vset.contains(new IrisPosition(x, y + 1, z))
|
||||
&& vset.contains(new IrisPosition(x, y - 1, z))
|
||||
&& vset.contains(new IrisPosition(x, y, z + 1))
|
||||
&& vset.contains(new IrisPosition(x, y, z - 1)))) {
|
||||
int x = v.getX();
|
||||
int y = v.getY();
|
||||
int z = v.getZ();
|
||||
if (!(lookup.contains(x + 1, y, z)
|
||||
&& lookup.contains(x - 1, y, z)
|
||||
&& lookup.contains(x, y + 1, z)
|
||||
&& lookup.contains(x, y - 1, z)
|
||||
&& lookup.contains(x, y, z + 1)
|
||||
&& lookup.contains(x, y, z - 1))) {
|
||||
returnset.add(v);
|
||||
}
|
||||
}
|
||||
return returnset;
|
||||
}
|
||||
|
||||
private static double hypot(double... pars) {
|
||||
double sum = 0;
|
||||
for (double d : pars) {
|
||||
sum += Math.pow(d, 2);
|
||||
private static double hypot(double x, double y, double z) {
|
||||
return Math.pow(x, 2) + Math.pow(y, 2) + Math.pow(z, 2);
|
||||
}
|
||||
|
||||
record PositionLookup(LongOpenHashSet keys, Set<IrisPosition> positions, int originX, int originY, int originZ) {
|
||||
private static final int AXIS_BITS = 21;
|
||||
private static final long AXIS_LIMIT = 1L << AXIS_BITS;
|
||||
|
||||
static PositionLookup of(Set<IrisPosition> positions) {
|
||||
if (positions.isEmpty()) {
|
||||
return new PositionLookup(new LongOpenHashSet(), positions, 0, 0, 0);
|
||||
}
|
||||
|
||||
int minX = Integer.MAX_VALUE;
|
||||
int minY = Integer.MAX_VALUE;
|
||||
int minZ = Integer.MAX_VALUE;
|
||||
int maxX = Integer.MIN_VALUE;
|
||||
int maxY = Integer.MIN_VALUE;
|
||||
int maxZ = Integer.MIN_VALUE;
|
||||
for (IrisPosition position : positions) {
|
||||
minX = Math.min(minX, position.getX());
|
||||
minY = Math.min(minY, position.getY());
|
||||
minZ = Math.min(minZ, position.getZ());
|
||||
maxX = Math.max(maxX, position.getX());
|
||||
maxY = Math.max(maxY, position.getY());
|
||||
maxZ = Math.max(maxZ, position.getZ());
|
||||
}
|
||||
|
||||
if ((long) maxX - minX >= AXIS_LIMIT - 2L
|
||||
|| (long) maxY - minY >= AXIS_LIMIT - 2L
|
||||
|| (long) maxZ - minZ >= AXIS_LIMIT - 2L) {
|
||||
return new PositionLookup(null, positions, 0, 0, 0);
|
||||
}
|
||||
|
||||
LongOpenHashSet keys = new LongOpenHashSet(positions.size());
|
||||
for (IrisPosition position : positions) {
|
||||
keys.add(key(position.getX() - minX, position.getY() - minY, position.getZ() - minZ));
|
||||
}
|
||||
return new PositionLookup(keys, positions, minX, minY, minZ);
|
||||
}
|
||||
|
||||
boolean contains(int x, int y, int z) {
|
||||
if (keys == null) {
|
||||
return positions.contains(new IrisPosition(x, y, z));
|
||||
}
|
||||
|
||||
long dx = (long) x - originX;
|
||||
long dy = (long) y - originY;
|
||||
long dz = (long) z - originZ;
|
||||
if ((dx | dy | dz) < 0L || dx >= AXIS_LIMIT || dy >= AXIS_LIMIT || dz >= AXIS_LIMIT) {
|
||||
return false;
|
||||
}
|
||||
return keys.contains(key(dx, dy, dz));
|
||||
}
|
||||
|
||||
private static long key(long x, long y, long z) {
|
||||
return (x << (AXIS_BITS * 2)) | (y << AXIS_BITS) | z;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
private static double lengthSq(double x, double y, double z) {
|
||||
@@ -795,10 +850,11 @@ public class MantleWriter implements IObjectPlacer, AutoCloseable {
|
||||
setConsumer(vset, data);
|
||||
}
|
||||
|
||||
private static Set<IrisPosition> getMasked(Set<IrisPosition> vectors, Set<IrisPosition> masks, double radius) {
|
||||
static Set<IrisPosition> getMasked(Set<IrisPosition> vectors, Set<IrisPosition> masks, double radius) {
|
||||
Set<IrisPosition> vset = new KSet<>();
|
||||
int ceil = (int) Math.ceil(radius);
|
||||
double r2 = Math.pow(radius, 2);
|
||||
PositionLookup maskLookup = PositionLookup.of(masks);
|
||||
|
||||
for (IrisPosition v : vectors) {
|
||||
int tipX = v.getX();
|
||||
@@ -808,7 +864,7 @@ public class MantleWriter implements IObjectPlacer, AutoCloseable {
|
||||
for (int x = -ceil; x <= ceil; x++) {
|
||||
for (int y = -ceil; y <= ceil; y++) {
|
||||
for (int z = -ceil; z <= ceil; z++) {
|
||||
if (hypot(x, y, z) > r2 || !masks.contains(new IrisPosition(x, y, z)))
|
||||
if (hypot(x, y, z) > r2 || !maskLookup.contains(x, y, z))
|
||||
continue;
|
||||
vset.add(new IrisPosition(tipX + x, tipY + y, tipZ + z));
|
||||
}
|
||||
@@ -963,6 +1019,7 @@ public class MantleWriter implements IObjectPlacer, AutoCloseable {
|
||||
try {
|
||||
setData(pos.getX(), pos.getY(), pos.getZ(), data);
|
||||
} catch (Throwable e) {
|
||||
GenerationFailures.rethrowEngineFailure(e);
|
||||
// Reached per position while an object writes past the edge of the writer window, which is
|
||||
// how a large object is clipped. Nothing here is actionable from outside the engine.
|
||||
IrisLogging.debug("No set? " + data.toString() + " for " + pos.toString());
|
||||
|
||||
@@ -836,6 +836,15 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
|
||||
|
||||
@Override
|
||||
public void generateNoise(@NotNull WorldInfo world, @NotNull Random random, int x, int z, @NotNull ChunkGenerator.ChunkData d) {
|
||||
try {
|
||||
generateNoiseChunk(world, random, x, z, d);
|
||||
} catch (Throwable e) {
|
||||
PregeneratorJob.reportChunkGenerationFailure(this.world.identity(), x, z, e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
private void generateNoiseChunk(WorldInfo world, Random random, int x, int z, ChunkGenerator.ChunkData d) {
|
||||
if (closing) {
|
||||
throw new IllegalStateException("Iris chunk generation was rejected while the generator is closing.");
|
||||
}
|
||||
|
||||
@@ -103,6 +103,14 @@ public final class BukkitPlatform implements IrisPlatform {
|
||||
PLUGIN = plugin;
|
||||
}
|
||||
|
||||
public static void releaseHost() {
|
||||
PLUGIN = null;
|
||||
HUD_BAR = null;
|
||||
HUD_LANES = null;
|
||||
CONSOLE = null;
|
||||
BRIDGE = null;
|
||||
}
|
||||
|
||||
public static Plugin plugin() {
|
||||
Plugin plugin = PLUGIN;
|
||||
if (plugin == null) {
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
package art.arcane.iris.util.common.board;
|
||||
|
||||
import art.arcane.volmlib.util.board.BoardProvider;
|
||||
|
||||
public class BoardSettings {
|
||||
private final BoardProvider boardProvider;
|
||||
private final ScoreDirection scoreDirection;
|
||||
|
||||
private BoardSettings(BoardProvider boardProvider, ScoreDirection scoreDirection) {
|
||||
this.boardProvider = boardProvider;
|
||||
this.scoreDirection = scoreDirection;
|
||||
}
|
||||
|
||||
public BoardProvider getBoardProvider() {
|
||||
return boardProvider;
|
||||
}
|
||||
|
||||
public ScoreDirection getScoreDirection() {
|
||||
return scoreDirection;
|
||||
}
|
||||
|
||||
public art.arcane.volmlib.util.board.BoardSettings toShared() {
|
||||
return art.arcane.volmlib.util.board.BoardSettings.builder()
|
||||
.boardProvider(boardProvider)
|
||||
.scoreDirection(scoreDirection.toShared())
|
||||
.build();
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private BoardProvider boardProvider;
|
||||
private ScoreDirection scoreDirection;
|
||||
|
||||
public Builder boardProvider(BoardProvider boardProvider) {
|
||||
this.boardProvider = boardProvider;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder scoreDirection(ScoreDirection scoreDirection) {
|
||||
this.scoreDirection = scoreDirection;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BoardSettings build() {
|
||||
return new BoardSettings(boardProvider, scoreDirection);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package art.arcane.iris.util.common.board;
|
||||
|
||||
public enum ScoreDirection {
|
||||
UP,
|
||||
DOWN;
|
||||
|
||||
public art.arcane.volmlib.util.board.ScoreDirection toShared() {
|
||||
return this == UP
|
||||
? art.arcane.volmlib.util.board.ScoreDirection.UP
|
||||
: art.arcane.volmlib.util.board.ScoreDirection.DOWN;
|
||||
}
|
||||
|
||||
public static ScoreDirection fromShared(art.arcane.volmlib.util.board.ScoreDirection direction) {
|
||||
return direction == art.arcane.volmlib.util.board.ScoreDirection.UP ? UP : DOWN;
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.util.common.inventorygui;
|
||||
|
||||
import art.arcane.volmlib.util.inventorygui.WindowDecorator;
|
||||
|
||||
import art.arcane.volmlib.util.inventorygui.Element;
|
||||
|
||||
import art.arcane.volmlib.util.data.MaterialBlock;
|
||||
import org.bukkit.Material;
|
||||
|
||||
@SuppressWarnings("ClassCanBeRecord")
|
||||
public class UIStaticDecorator implements WindowDecorator {
|
||||
private final Element element;
|
||||
|
||||
public UIStaticDecorator(Element element) {
|
||||
this.element = element == null ? new art.arcane.volmlib.util.inventorygui.UIElement("bg").setMaterial(new MaterialBlock(Material.AIR)) : element;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Element onDecorateBackground(art.arcane.volmlib.util.inventorygui.Window window, int position, int row) {
|
||||
return element;
|
||||
}
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
package art.arcane.iris.util.common.inventorygui;
|
||||
|
||||
import art.arcane.volmlib.util.inventorygui.WindowDecorator;
|
||||
|
||||
import art.arcane.volmlib.util.inventorygui.Element;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public interface Window {
|
||||
WindowDecorator getDecorator();
|
||||
|
||||
Window setDecorator(WindowDecorator decorator);
|
||||
|
||||
art.arcane.volmlib.util.inventorygui.WindowResolution getResolution();
|
||||
|
||||
Window setResolution(art.arcane.volmlib.util.inventorygui.WindowResolution resolution);
|
||||
|
||||
default Window setResolution(WindowResolution resolution) {
|
||||
return setResolution(resolution.toShared());
|
||||
}
|
||||
|
||||
default WindowResolution getLocalResolution() {
|
||||
return WindowResolution.fromShared(getResolution());
|
||||
}
|
||||
|
||||
Window clearElements();
|
||||
|
||||
Window close();
|
||||
|
||||
Window open();
|
||||
|
||||
Window callClosed();
|
||||
|
||||
Window updateInventory();
|
||||
|
||||
ItemStack computeItemStack(int viewportSlot);
|
||||
|
||||
int getLayoutRow(int viewportSlottedPosition);
|
||||
|
||||
int getLayoutPosition(int viewportSlottedPosition);
|
||||
|
||||
int getRealLayoutPosition(int viewportSlottedPosition);
|
||||
|
||||
int getRealPosition(int position, int row);
|
||||
|
||||
int getRow(int realPosition);
|
||||
|
||||
int getPosition(int realPosition);
|
||||
|
||||
boolean isVisible();
|
||||
|
||||
Window setVisible(boolean visible);
|
||||
|
||||
int getViewportPosition();
|
||||
|
||||
Window setViewportPosition(int position);
|
||||
|
||||
int getViewportSlots();
|
||||
|
||||
int getMaxViewportPosition();
|
||||
|
||||
Window scroll(int direction);
|
||||
|
||||
int getViewportHeight();
|
||||
|
||||
Window setViewportHeight(int height);
|
||||
|
||||
String getTitle();
|
||||
|
||||
Window setTitle(String title);
|
||||
|
||||
boolean hasElement(int position, int row);
|
||||
|
||||
Window setElement(int position, int row, Element e);
|
||||
|
||||
Element getElement(int position, int row);
|
||||
|
||||
Player getViewer();
|
||||
|
||||
Window reopen();
|
||||
|
||||
Window onClosed(art.arcane.volmlib.util.scheduling.Callback<art.arcane.volmlib.util.inventorygui.Window> window);
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
package art.arcane.iris.util.common.inventorygui;
|
||||
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
|
||||
public enum WindowResolution {
|
||||
W9_H6(9, 6, InventoryType.CHEST),
|
||||
W5_H1(5, 1, InventoryType.HOPPER),
|
||||
W3_H3(3, 3, InventoryType.DROPPER);
|
||||
|
||||
private final int width;
|
||||
private final int maxHeight;
|
||||
private final InventoryType type;
|
||||
|
||||
WindowResolution(int w, int h, InventoryType type) {
|
||||
this.width = w;
|
||||
this.maxHeight = h;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public int getMaxWidthOffset() {
|
||||
return (getWidth() - 1) / 2;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public int getMaxHeight() {
|
||||
return maxHeight;
|
||||
}
|
||||
|
||||
public InventoryType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public art.arcane.volmlib.util.inventorygui.WindowResolution toShared() {
|
||||
return art.arcane.volmlib.util.inventorygui.WindowResolution.valueOf(name());
|
||||
}
|
||||
|
||||
public static WindowResolution fromShared(art.arcane.volmlib.util.inventorygui.WindowResolution resolution) {
|
||||
return valueOf(resolution.name());
|
||||
}
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
package art.arcane.iris.util.common.math;
|
||||
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public class VectorMath extends art.arcane.volmlib.util.math.VectorMath {
|
||||
public static Vector rotate(Direction current, Direction to, Vector v) {
|
||||
if (current.equals(to)) {
|
||||
return v;
|
||||
} else if (current.equals(to.reverse())) {
|
||||
if (current.isVertical()) {
|
||||
return new Vector(v.getX(), -v.getY(), v.getZ());
|
||||
} else {
|
||||
return new Vector(-v.getX(), v.getY(), -v.getZ());
|
||||
}
|
||||
} else {
|
||||
Vector c = current.toVector().clone().add(to.toVector());
|
||||
|
||||
if (c.getX() == 0) {
|
||||
if (c.getY() != c.getZ()) {
|
||||
return rotate90CX(v);
|
||||
}
|
||||
|
||||
return rotate90CCX(v);
|
||||
} else if (c.getY() == 0) {
|
||||
if (c.getX() != c.getZ()) {
|
||||
return rotate90CY(v);
|
||||
}
|
||||
|
||||
return rotate90CCY(v);
|
||||
} else if (c.getZ() == 0) {
|
||||
if (c.getX() != c.getY()) {
|
||||
return rotate90CZ(v);
|
||||
}
|
||||
|
||||
return rotate90CCZ(v);
|
||||
}
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
public static Vector rotate(Direction current, Direction to, Vector v, int w, int h, int d) {
|
||||
if (current.equals(to)) {
|
||||
return v;
|
||||
} else if (current.equals(to.reverse())) {
|
||||
if (current.isVertical()) {
|
||||
return new Vector(v.getX(), -v.getY() + h, v.getZ());
|
||||
} else {
|
||||
return new Vector(-v.getX() + w, v.getY(), -v.getZ() + d);
|
||||
}
|
||||
} else {
|
||||
Vector c = current.toVector().clone().add(to.toVector());
|
||||
|
||||
if (c.getX() == 0) {
|
||||
if (c.getY() != c.getZ()) {
|
||||
return rotate90CX(v, d);
|
||||
}
|
||||
|
||||
return rotate90CCX(v, h);
|
||||
} else if (c.getY() == 0) {
|
||||
if (c.getX() != c.getZ()) {
|
||||
return rotate90CY(v, d);
|
||||
}
|
||||
|
||||
return rotate90CCY(v, w);
|
||||
} else if (c.getZ() == 0) {
|
||||
if (c.getX() != c.getY()) {
|
||||
return rotate90CZ(v, w);
|
||||
}
|
||||
|
||||
return rotate90CCZ(v, h);
|
||||
}
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -772,7 +772,7 @@ public class J {
|
||||
}
|
||||
|
||||
private static boolean isPluginEnabled() {
|
||||
return usesBukkitScheduler() && BukkitPlatform.hasPlugin() && Bukkit.getPluginManager().isPluginEnabled(BukkitPlatform.plugin());
|
||||
return usesBukkitScheduler() && BukkitPlatform.hasPlugin() && BukkitPlatform.plugin().isEnabled();
|
||||
}
|
||||
|
||||
private static boolean canSchedule() {
|
||||
|
||||
@@ -36,6 +36,7 @@ import art.arcane.volmlib.util.hunk.HunkCoreSupport;
|
||||
import art.arcane.volmlib.util.hunk.HunkInterpolationSupport;
|
||||
import art.arcane.volmlib.util.hunk.HunkMutationSupport;
|
||||
import art.arcane.volmlib.util.hunk.HunkSectionSupport;
|
||||
import art.arcane.volmlib.util.hunk.HunkFace;
|
||||
import art.arcane.volmlib.util.hunk.HunkLike;
|
||||
import art.arcane.iris.util.project.hunk.storage.ArrayHunk;
|
||||
import art.arcane.iris.util.project.hunk.storage.AtomicDoubleHunk;
|
||||
|
||||
@@ -18,41 +18,10 @@
|
||||
|
||||
package art.arcane.iris.util.project.hunk.storage;
|
||||
|
||||
import art.arcane.volmlib.util.cache.CacheKey;
|
||||
import art.arcane.iris.util.project.hunk.Hunk;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@SuppressWarnings("Lombok")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class ArrayHunk<T> extends StorageHunk<T> implements Hunk<T> {
|
||||
private final T[] data;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class ArrayHunk<T> extends art.arcane.volmlib.util.hunk.storage.ArrayHunk<T> implements Hunk<T> {
|
||||
public ArrayHunk(int w, int h, int d) {
|
||||
super(w, h, d);
|
||||
data = (T[]) new Object[w * h * d];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRaw(int x, int y, int z, T t) {
|
||||
data[index(x, y, z)] = t;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getRaw(int x, int y, int z) {
|
||||
return data[index(x, y, z)];
|
||||
}
|
||||
|
||||
private int index(int x, int y, int z) {
|
||||
return CacheKey.to1D(x, y, z, getWidth(), getHeight());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fill(T t) {
|
||||
Arrays.fill(data, t);
|
||||
}
|
||||
}
|
||||
@@ -18,38 +18,10 @@
|
||||
|
||||
package art.arcane.iris.util.project.hunk.storage;
|
||||
|
||||
import com.google.common.util.concurrent.AtomicDoubleArray;
|
||||
import art.arcane.iris.util.project.hunk.Hunk;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@SuppressWarnings({"Lombok"})
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class AtomicDoubleHunk extends StorageHunk<Double> implements Hunk<Double> {
|
||||
private final AtomicDoubleArray data;
|
||||
|
||||
public class AtomicDoubleHunk extends art.arcane.volmlib.util.hunk.storage.AtomicDoubleHunk implements Hunk<Double> {
|
||||
public AtomicDoubleHunk(int w, int h, int d) {
|
||||
super(w, h, d);
|
||||
data = new AtomicDoubleArray(w * h * d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAtomic() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRaw(int x, int y, int z, Double t) {
|
||||
data.set(index(x, y, z), t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double getRaw(int x, int y, int z) {
|
||||
return data.get(index(x, y, z));
|
||||
}
|
||||
|
||||
private int index(int x, int y, int z) {
|
||||
return (z * getWidth() * getHeight()) + (y * getWidth()) + x;
|
||||
}
|
||||
}
|
||||
@@ -19,44 +19,9 @@
|
||||
package art.arcane.iris.util.project.hunk.storage;
|
||||
|
||||
import art.arcane.iris.util.project.hunk.Hunk;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicReferenceArray;
|
||||
|
||||
@SuppressWarnings({"Lombok"})
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class AtomicHunk<T> extends StorageHunk<T> implements Hunk<T> {
|
||||
private final AtomicReferenceArray<T> data;
|
||||
// index() runs per block access on the hottest paths; two final-field multiplies beat
|
||||
// re-deriving the strides through the accessors every call.
|
||||
private final int xStride;
|
||||
private final int zStride;
|
||||
|
||||
public class AtomicHunk<T> extends art.arcane.volmlib.util.hunk.storage.AtomicHunk<T> implements Hunk<T> {
|
||||
public AtomicHunk(int w, int h, int d) {
|
||||
super(w, h, d);
|
||||
data = new AtomicReferenceArray<>(w * h * d);
|
||||
xStride = w;
|
||||
zStride = w * h;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAtomic() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRaw(int x, int y, int z, T t) {
|
||||
data.set(index(x, y, z), t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getRaw(int x, int y, int z) {
|
||||
return data.get(index(x, y, z));
|
||||
}
|
||||
|
||||
private int index(int x, int y, int z) {
|
||||
return (z * zStride) + (y * xStride) + x;
|
||||
}
|
||||
}
|
||||
+1
-30
@@ -19,38 +19,9 @@
|
||||
package art.arcane.iris.util.project.hunk.storage;
|
||||
|
||||
import art.arcane.iris.util.project.hunk.Hunk;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicIntegerArray;
|
||||
|
||||
@SuppressWarnings({"Lombok"})
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class AtomicIntegerHunk extends StorageHunk<Integer> implements Hunk<Integer> {
|
||||
private final AtomicIntegerArray data;
|
||||
|
||||
public class AtomicIntegerHunk extends art.arcane.volmlib.util.hunk.storage.AtomicIntegerHunk implements Hunk<Integer> {
|
||||
public AtomicIntegerHunk(int w, int h, int d) {
|
||||
super(w, h, d);
|
||||
data = new AtomicIntegerArray(w * h * d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAtomic() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRaw(int x, int y, int z, Integer t) {
|
||||
data.set(index(x, y, z), t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getRaw(int x, int y, int z) {
|
||||
return data.get(index(x, y, z));
|
||||
}
|
||||
|
||||
private int index(int x, int y, int z) {
|
||||
return (z * getWidth() * getHeight()) + (y * getWidth()) + x;
|
||||
}
|
||||
}
|
||||
@@ -19,38 +19,9 @@
|
||||
package art.arcane.iris.util.project.hunk.storage;
|
||||
|
||||
import art.arcane.iris.util.project.hunk.Hunk;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicLongArray;
|
||||
|
||||
@SuppressWarnings({"Lombok"})
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class AtomicLongHunk extends StorageHunk<Long> implements Hunk<Long> {
|
||||
private final AtomicLongArray data;
|
||||
|
||||
public class AtomicLongHunk extends art.arcane.volmlib.util.hunk.storage.AtomicLongHunk implements Hunk<Long> {
|
||||
public AtomicLongHunk(int w, int h, int d) {
|
||||
super(w, h, d);
|
||||
data = new AtomicLongArray(w * h * d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAtomic() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRaw(int x, int y, int z, Long t) {
|
||||
data.set(index(x, y, z), t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getRaw(int x, int y, int z) {
|
||||
return data.get(index(x, y, z));
|
||||
}
|
||||
|
||||
private int index(int x, int y, int z) {
|
||||
return (z * getWidth() * getHeight()) + (y * getWidth()) + x;
|
||||
}
|
||||
}
|
||||
@@ -19,27 +19,9 @@
|
||||
package art.arcane.iris.util.project.hunk.storage;
|
||||
|
||||
import art.arcane.iris.util.project.hunk.Hunk;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public abstract class StorageHunk<T> implements Hunk<T> {
|
||||
private final int width;
|
||||
private final int height;
|
||||
private final int depth;
|
||||
|
||||
public abstract class StorageHunk<T> extends art.arcane.volmlib.util.hunk.storage.StorageHunk<T> implements Hunk<T> {
|
||||
public StorageHunk(int width, int height, int depth) {
|
||||
if (width <= 0 || height <= 0 || depth <= 0) {
|
||||
throw new RuntimeException("Unsupported size " + width + " " + height + " " + depth);
|
||||
}
|
||||
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.depth = depth;
|
||||
super(width, height, depth);
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract void setRaw(int x, int y, int z, T t);
|
||||
|
||||
@Override
|
||||
public abstract T getRaw(int x, int y, int z);
|
||||
}
|
||||
+1
-37
@@ -19,45 +19,9 @@
|
||||
package art.arcane.iris.util.project.hunk.storage;
|
||||
|
||||
import art.arcane.iris.util.project.hunk.Hunk;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@SuppressWarnings({"Lombok"})
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class SynchronizedArrayHunk<T> extends StorageHunk<T> implements Hunk<T> {
|
||||
private final T[] data;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class SynchronizedArrayHunk<T> extends art.arcane.volmlib.util.hunk.storage.SynchronizedArrayHunk<T> implements Hunk<T> {
|
||||
public SynchronizedArrayHunk(int w, int h, int d) {
|
||||
super(w, h, d);
|
||||
data = (T[]) new Object[w * h * d];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRaw(int x, int y, int z, T t) {
|
||||
synchronized (data) {
|
||||
data[index(x, y, z)] = t;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getRaw(int x, int y, int z) {
|
||||
synchronized (data) {
|
||||
return data[index(x, y, z)];
|
||||
}
|
||||
}
|
||||
|
||||
private int index(int x, int y, int z) {
|
||||
return (z * getWidth() * getHeight()) + (y * getWidth()) + x;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fill(T t) {
|
||||
synchronized (data) {
|
||||
Arrays.fill(data, t);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.util.project.interpolation;
|
||||
|
||||
public enum InterpolationType {
|
||||
LINEAR,
|
||||
PARAMETRIC_2,
|
||||
PARAMETRIC_4,
|
||||
BEZIER,
|
||||
NONE
|
||||
}
|
||||
+1
-145
@@ -25,7 +25,7 @@ import art.arcane.volmlib.util.function.NoiseProvider;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import art.arcane.iris.util.project.noise.CNG;
|
||||
|
||||
public class IrisInterpolation {
|
||||
public class IrisInterpolation extends art.arcane.volmlib.util.interpolation.IrisInterpolation {
|
||||
public static CNG cng = NoiseStyle.SIMPLEX.create(new RNG());
|
||||
private static final ThreadLocal<NoiseSampleCache2D> NOISE_SAMPLE_CACHE_2D = ThreadLocal.withInitial(() -> new NoiseSampleCache2D(64));
|
||||
private static final ThreadLocal<NoiseBoundsSampleCache2D> NOISE_BOUNDS_SAMPLE_CACHE_2D = ThreadLocal.withInitial(() -> new NoiseBoundsSampleCache2D(64));
|
||||
@@ -63,26 +63,6 @@ public class IrisInterpolation {
|
||||
return a + (parametric(f, v) * (b - a));
|
||||
}
|
||||
|
||||
public static double blerp(double a, double b, double c, double d, double tx, double ty, InterpolationType type) {
|
||||
if (type.equals(InterpolationType.LINEAR)) {
|
||||
return blerp(a, b, c, d, tx, ty);
|
||||
}
|
||||
|
||||
if (type.equals(InterpolationType.BEZIER)) {
|
||||
return blerpBezier(a, b, c, d, tx, ty);
|
||||
}
|
||||
|
||||
if (type.equals(InterpolationType.PARAMETRIC_2)) {
|
||||
return blerpParametric(a, b, c, d, tx, ty, 2);
|
||||
}
|
||||
|
||||
if (type.equals(InterpolationType.PARAMETRIC_4)) {
|
||||
return blerpParametric(a, b, c, d, tx, ty, 4);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static double blerpBezier(double a, double b, double c, double d, double tx, double ty) {
|
||||
return lerpBezier(lerpBezier(a, b, tx), lerpBezier(c, d, tx), ty);
|
||||
}
|
||||
@@ -133,130 +113,6 @@ public class IrisInterpolation {
|
||||
return parametric(cubic(p0, p1, p2, p3, mu), a);
|
||||
}
|
||||
|
||||
public static double hermite(double p0, double p1, double p2, double p3, double mu, double tension, double bias) {
|
||||
double m0, m1, mu2, mu3;
|
||||
double a0, a1, a2, a3;
|
||||
|
||||
mu2 = mu * mu;
|
||||
mu3 = mu2 * mu;
|
||||
m0 = (p1 - p0) * (1 + bias) * (1 - tension) / 2;
|
||||
m0 += (p2 - p1) * (1 - bias) * (1 - tension) / 2;
|
||||
m1 = (p2 - p1) * (1 + bias) * (1 - tension) / 2;
|
||||
m1 += (p3 - p2) * (1 - bias) * (1 - tension) / 2;
|
||||
a0 = 2 * mu3 - 3 * mu2 + 1;
|
||||
a1 = mu3 - 2 * mu2 + mu;
|
||||
a2 = mu3 - mu2;
|
||||
a3 = -2 * mu3 + 3 * mu2;
|
||||
|
||||
return (a0 * p1 + a1 * m0 + a2 * m1 + a3 * p2);
|
||||
}
|
||||
|
||||
public static double cubic(double p0, double p1, double p2, double p3, double mu) {
|
||||
double a0, a1, a2, a3, mu2;
|
||||
|
||||
mu2 = mu * mu;
|
||||
a0 = p3 - p2 - p0 + p1;
|
||||
a1 = p0 - p1 - a0;
|
||||
a2 = p2 - p0;
|
||||
a3 = p1;
|
||||
|
||||
return a0 * mu * mu2 + a1 * mu2 + a2 * mu + a3;
|
||||
}
|
||||
|
||||
public static double bicubic(double p00, double p01, double p02, double p03, double p10, double p11, double p12, double p13, double p20, double p21, double p22, double p23, double p30, double p31, double p32, double p33, double mux, double muy) {
|
||||
//@builder
|
||||
return cubic(
|
||||
cubic(p00, p01, p02, p03, muy),
|
||||
cubic(p10, p11, p12, p13, muy),
|
||||
cubic(p20, p21, p22, p23, muy),
|
||||
cubic(p30, p31, p32, p33, muy),
|
||||
mux);
|
||||
//@done
|
||||
}
|
||||
|
||||
public static double bihermite(double p00, double p01, double p02, double p03, double p10, double p11, double p12, double p13, double p20, double p21, double p22, double p23, double p30, double p31, double p32, double p33, double mux, double muy, double tension, double bias) {
|
||||
//@builder
|
||||
return hermite(
|
||||
hermite(p00, p01, p02, p03, muy, tension, bias),
|
||||
hermite(p10, p11, p12, p13, muy, tension, bias),
|
||||
hermite(p20, p21, p22, p23, muy, tension, bias),
|
||||
hermite(p30, p31, p32, p33, muy, tension, bias),
|
||||
mux, tension, bias);
|
||||
//@done
|
||||
}
|
||||
|
||||
public static double trihermite(double p000, double p001, double p002, double p003, double p010, double p011, double p012, double p013, double p020, double p021, double p022, double p023, double p030, double p031, double p032, double p033, double p100, double p101, double p102, double p103, double p110, double p111, double p112, double p113, double p120, double p121, double p122, double p123, double p130, double p131, double p132, double p133, double p200, double p201, double p202, double p203, double p210, double p211, double p212, double p213, double p220, double p221, double p222, double p223, double p230, double p231, double p232, double p233, double p300, double p301, double p302, double p303, double p310, double p311, double p312, double p313, double p320, double p321, double p322, double p323, double p330, double p331, double p332, double p333, double mux, double muy, double muz, double tension, double bias) {
|
||||
//@builder
|
||||
return hermite(
|
||||
bihermite(p000, p001, p002, p003,
|
||||
p010, p011, p012, p013,
|
||||
p020, p021, p022, p023,
|
||||
p030, p031, p032, p033,
|
||||
mux, muy, tension, bias),
|
||||
bihermite(p100, p101, p102, p103,
|
||||
p110, p111, p112, p113,
|
||||
p120, p121, p122, p123,
|
||||
p130, p131, p132, p133,
|
||||
mux, muy, tension, bias),
|
||||
bihermite(p200, p201, p202, p203,
|
||||
p210, p211, p212, p213,
|
||||
p220, p221, p222, p223,
|
||||
p230, p231, p232, p233,
|
||||
mux, muy, tension, bias),
|
||||
bihermite(p300, p301, p302, p303,
|
||||
p310, p311, p312, p313,
|
||||
p320, p321, p322, p323,
|
||||
p330, p331, p332, p333,
|
||||
mux, muy, tension, bias),
|
||||
muz, tension, bias);
|
||||
//@done
|
||||
}
|
||||
|
||||
public static double tricubic(double p000,
|
||||
double p001,
|
||||
double p002,
|
||||
double p003,
|
||||
double p010,
|
||||
double p011,
|
||||
double p012, double p013, double p020, double p021, double p022, double p023, double p030, double p031, double p032, double p033, double p100, double p101, double p102, double p103, double p110, double p111, double p112, double p113, double p120, double p121, double p122, double p123, double p130, double p131, double p132, double p133, double p200, double p201, double p202, double p203, double p210, double p211, double p212, double p213, double p220, double p221, double p222, double p223, double p230, double p231, double p232, double p233, double p300, double p301, double p302, double p303, double p310, double p311, double p312, double p313, double p320, double p321, double p322, double p323, double p330, double p331, double p332, double p333, double mux, double muy, double muz) {
|
||||
//@builder
|
||||
return cubic(
|
||||
bicubic(p000, p001, p002, p003,
|
||||
p010, p011, p012, p013,
|
||||
p020, p021, p022, p023,
|
||||
p030, p031, p032, p033,
|
||||
mux, muy),
|
||||
bicubic(p100, p101, p102, p103,
|
||||
p110, p111, p112, p113,
|
||||
p120, p121, p122, p123,
|
||||
p130, p131, p132, p133,
|
||||
mux, muy),
|
||||
bicubic(p200, p201, p202, p203,
|
||||
p210, p211, p212, p213,
|
||||
p220, p221, p222, p223,
|
||||
p230, p231, p232, p233,
|
||||
mux, muy),
|
||||
bicubic(p300, p301, p302, p303,
|
||||
p310, p311, p312, p313,
|
||||
p320, p321, p322, p323,
|
||||
p330, p331, p332, p333,
|
||||
mux, muy),
|
||||
muz);
|
||||
//@done
|
||||
}
|
||||
|
||||
public static double lerp(double a, double b, double f) {
|
||||
return a + (f * (b - a));
|
||||
}
|
||||
|
||||
public static double blerp(double a, double b, double c, double d, double tx, double ty) {
|
||||
return lerp(lerp(a, b, tx), lerp(c, d, tx), ty);
|
||||
}
|
||||
|
||||
public static double trilerp(double v1, double v2, double v3, double v4, double v5, double v6, double v7, double v8, double x, double y, double z) {
|
||||
return lerp(blerp(v1, v2, v3, v4, x, y), blerp(v5, v6, v7, v8, x, y), z);
|
||||
}
|
||||
|
||||
public static double bicubicBezier(double p00, double p01, double p02, double p03, double p10, double p11, double p12, double p13, double p20, double p21, double p22, double p23, double p30, double p31, double p32, double p33, double mux, double muy) {
|
||||
//@builder
|
||||
return cubicBezier(
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
package art.arcane.iris.core.gui;
|
||||
|
||||
import art.arcane.iris.core.pregenerator.IrisPregenerator;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.CALLS_REAL_METHODS;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
public class PregeneratorJobOwnerDrainTest {
|
||||
@Test
|
||||
public void ownerPollingCompletesTheRequestThatKeepsTheWorkerAlive() throws Exception {
|
||||
try (Fixture fixture = new Fixture()) {
|
||||
Thread owner = Thread.currentThread();
|
||||
AtomicInteger polls = new AtomicInteger();
|
||||
assertTrue(PregeneratorJob.shutdownAndWait(1_000L, () -> {
|
||||
assertSame(owner, Thread.currentThread());
|
||||
polls.incrementAndGet();
|
||||
fixture.completion.complete(null);
|
||||
}));
|
||||
assertTrue(polls.get() > 0);
|
||||
assertFalse(fixture.worker.isAlive());
|
||||
assertNull(PregeneratorJob.getInstance());
|
||||
verify(fixture.pregenerator).close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void timeoutKeepsThePendingJobAndDoesNotCompleteItsRequest() throws Exception {
|
||||
try (Fixture fixture = new Fixture()) {
|
||||
AtomicInteger polls = new AtomicInteger();
|
||||
IllegalStateException failure = assertThrows(IllegalStateException.class,
|
||||
() -> PregeneratorJob.shutdownAndWait(20L, polls::incrementAndGet));
|
||||
assertEquals("Timed out while stopping the Iris pregenerator after 20ms.", failure.getMessage());
|
||||
assertTrue(polls.get() > 0);
|
||||
assertTrue(fixture.worker.isAlive());
|
||||
assertFalse(fixture.completion.isDone());
|
||||
assertSame(fixture.job, PregeneratorJob.getInstance());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void interruptedOwnerKeepsTheJobAndOriginalInterruption() throws Exception {
|
||||
try (Fixture fixture = new Fixture()) {
|
||||
try {
|
||||
IllegalStateException failure = assertThrows(IllegalStateException.class,
|
||||
() -> PregeneratorJob.shutdownAndWait(1_000L, () -> Thread.currentThread().interrupt()));
|
||||
assertTrue(failure.getCause() instanceof InterruptedException);
|
||||
assertTrue(Thread.currentThread().isInterrupted());
|
||||
assertSame(fixture.job, PregeneratorJob.getInstance());
|
||||
assertFalse(fixture.completion.isDone());
|
||||
} finally {
|
||||
Thread.interrupted();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ownerTaskFailureEscapesWithItsCauseAndRetainsTheJob() throws Exception {
|
||||
try (Fixture fixture = new Fixture()) {
|
||||
IllegalStateException expected = new IllegalStateException("Native task failed", new Exception("Chunk cause"));
|
||||
IllegalStateException actual = assertThrows(IllegalStateException.class,
|
||||
() -> PregeneratorJob.shutdownAndWait(1_000L, () -> {
|
||||
throw expected;
|
||||
}));
|
||||
assertSame(expected, actual);
|
||||
assertSame(expected.getCause(), actual.getCause());
|
||||
assertSame(fixture.job, PregeneratorJob.getInstance());
|
||||
assertFalse(fixture.completion.isDone());
|
||||
}
|
||||
}
|
||||
|
||||
private static final class Fixture implements AutoCloseable {
|
||||
private final PregeneratorJob job = mock(PregeneratorJob.class, CALLS_REAL_METHODS);
|
||||
private final IrisPregenerator pregenerator = mock(IrisPregenerator.class);
|
||||
private final CompletableFuture<Void> completion = new CompletableFuture<>();
|
||||
private final AtomicReference<PregeneratorJob> instance;
|
||||
private final PregeneratorJob previous;
|
||||
private final Thread worker;
|
||||
|
||||
private Fixture() throws Exception {
|
||||
CountDownLatch started = new CountDownLatch(1);
|
||||
worker = new Thread(() -> {
|
||||
started.countDown();
|
||||
completion.join();
|
||||
}, "Pregen owner drain test");
|
||||
set("worker", worker);
|
||||
set("pregenerator", pregenerator);
|
||||
instance = instance();
|
||||
previous = instance.getAndSet(job);
|
||||
worker.start();
|
||||
assertTrue(started.await(5L, TimeUnit.SECONDS));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws Exception {
|
||||
completion.complete(null);
|
||||
worker.join(5_000L);
|
||||
instance.set(previous);
|
||||
assertFalse(worker.isAlive());
|
||||
}
|
||||
|
||||
private void set(String name, Object value) throws Exception {
|
||||
Field field = PregeneratorJob.class.getDeclaredField(name);
|
||||
field.setAccessible(true);
|
||||
field.set(job, value);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static AtomicReference<PregeneratorJob> instance() throws Exception {
|
||||
Field field = PregeneratorJob.class.getDeclaredField("instance");
|
||||
field.setAccessible(true);
|
||||
return (AtomicReference<PregeneratorJob>) field.get(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package art.arcane.iris.core.lifecycle;
|
||||
|
||||
import art.arcane.iris.spi.IrisServices;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
public class IrisRuntimeStaticsTest {
|
||||
@After
|
||||
public void clearStatics() {
|
||||
IrisRuntimeStatics.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resetUnbindsEveryRegisteredService() {
|
||||
IrisServices.register(Runnable.class, (Runnable) () -> {
|
||||
});
|
||||
|
||||
IrisRuntimeStatics.reset();
|
||||
|
||||
assertNull(IrisServices.getOrNull(Runnable.class));
|
||||
}
|
||||
}
|
||||
@@ -78,7 +78,7 @@ public class ModuleMantleComponentTest {
|
||||
assertEquals(List.of(MantleFlag.of(first), MantleFlag.of(first + 1), MantleFlag.of(first + 2), MantleFlag.of(first + 3), MantleFlag.of(first + 4)),
|
||||
components.stream().map(ModuleMantleComponent::getFlag).toList());
|
||||
assertEquals(List.of(0, 1, 2, 3, 4), components.stream().map(ModuleMantleComponent::getPriority).toList());
|
||||
assertEquals("a pack without objects or structures: caves 1, floating objects at least 16", List.of(1, 0, 16, 0, MARK_REACH),
|
||||
assertEquals("a pack without objects or structures: caves 1, no floating objects", List.of(1, 0, 0, 0, MARK_REACH),
|
||||
components.stream().map(ModuleMantleComponent::getRadius).toList());
|
||||
assertEquals("disabledComponents: [iris:carve/caves] turns the cave pass off", List.of(false, true, true, true, true),
|
||||
components.stream().map(ModuleMantleComponent::isEnabled).toList());
|
||||
|
||||
@@ -20,7 +20,6 @@ package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.engine.UsableBlockPlatform;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.EngineGeneration;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.util.project.hunk.Hunk;
|
||||
@@ -68,7 +67,7 @@ public class PlannedBlocksTest {
|
||||
public void placementsBlocksReadInWorldCoordinatesInVisitOrder() {
|
||||
plan(20, 10, 33, planks);
|
||||
plan(17, 40, 35, planks);
|
||||
PlannedBlocks blocks = planned(true, false);
|
||||
PlannedBlocks blocks = planned(true);
|
||||
List<String> visited = new ArrayList<>();
|
||||
|
||||
blocks.visit(CHUNK, (x, y, z, block) -> visited.add(x + "," + y + "," + z + " " + block.key()));
|
||||
@@ -79,20 +78,20 @@ public class PlannedBlocksTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aDimensionWithoutAMantleOrAChunkWithoutItPlansNothing() {
|
||||
public void aDimensionWithoutAMantlePlansNothing() {
|
||||
plan(20, 10, 33, planks);
|
||||
PlannedBlocks blocks = planned(false);
|
||||
List<BlockState> visited = new ArrayList<>();
|
||||
|
||||
for (PlannedBlocks blocks : List.of(planned(false, false), planned(true, true))) {
|
||||
List<BlockState> visited = new ArrayList<>();
|
||||
blocks.visit(CHUNK, (x, y, z, block) -> visited.add(block));
|
||||
assertEquals(List.of(), visited);
|
||||
assertNull(blocks.get(20, 10, 33));
|
||||
}
|
||||
blocks.visit(CHUNK, (x, y, z, block) -> visited.add(block));
|
||||
|
||||
assertEquals(List.of(), visited);
|
||||
assertNull(blocks.get(20, 10, 33));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stagesCannotPlanBlocks() {
|
||||
MantleLayer<BlockState> blocks = planned(true, false);
|
||||
MantleLayer<BlockState> blocks = planned(true);
|
||||
BlockState stone = BlockState.parse("minecraft:stone");
|
||||
|
||||
assertThrows(UnsupportedOperationException.class, () -> blocks.set(20, 10, 33, stone));
|
||||
@@ -106,7 +105,7 @@ public class PlannedBlocksTest {
|
||||
PlatformBlockState vanilla = UsableBlockPlatform.block("minecraft:note_block");
|
||||
plan(20, 10, 33, custom);
|
||||
PlatformBlockStates states = new PlatformBlockStates(key -> vanilla);
|
||||
PlannedBlocks blocks = PlannedBlocks.of(engine(true, false), CHUNK, mantle::chunk, states);
|
||||
PlannedBlocks blocks = PlannedBlocks.of(engine(true), CHUNK, mantle::chunk, states);
|
||||
Hunk<PlatformBlockState> chunk = Hunk.newArrayHunk(16, SECTIONS * 16, 16);
|
||||
BlockStateHunk hunk = new BlockStateHunk(chunk, states);
|
||||
|
||||
@@ -121,18 +120,15 @@ public class PlannedBlocksTest {
|
||||
mantle.chunk(x >> 4, z >> 4).getOrCreate(y >> 4).slice(PlatformBlockState.class).set(x & 15, y & 15, z & 15, block);
|
||||
}
|
||||
|
||||
private PlannedBlocks planned(boolean useMantle, boolean bypass) {
|
||||
return PlannedBlocks.of(engine(useMantle, bypass), CHUNK, mantle::chunk, new PlatformBlockStates(UsableBlockPlatform::block));
|
||||
private PlannedBlocks planned(boolean useMantle) {
|
||||
return PlannedBlocks.of(engine(useMantle), CHUNK, mantle::chunk, new PlatformBlockStates(UsableBlockPlatform::block));
|
||||
}
|
||||
|
||||
private static Engine engine(boolean useMantle, boolean bypass) {
|
||||
private static Engine engine(boolean useMantle) {
|
||||
IrisDimension dimension = mock(IrisDimension.class);
|
||||
when(dimension.isUseMantle()).thenReturn(useMantle);
|
||||
EngineGeneration generation = mock(EngineGeneration.class);
|
||||
when(generation.bypassesMantleStages()).thenReturn(bypass);
|
||||
Engine engine = mock(Engine.class);
|
||||
when(engine.getDimension()).thenReturn(dimension);
|
||||
when(engine.getGeneration()).thenReturn(generation);
|
||||
return engine;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package art.arcane.iris.core.pregenerator;
|
||||
|
||||
import art.arcane.iris.spi.IrisPlatform;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.iris.spi.LogLevel;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.ArgumentMatchers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
public class PregenDiagnosticsTest {
|
||||
private final List<String> emitted = new ArrayList<>();
|
||||
private final List<LogLevel> levels = new ArrayList<>();
|
||||
private IrisPlatform previousPlatform;
|
||||
|
||||
@Before
|
||||
public void captureLog() {
|
||||
previousPlatform = IrisPlatforms.isBound() ? IrisPlatforms.get() : null;
|
||||
IrisPlatforms.unbind();
|
||||
emitted.clear();
|
||||
levels.clear();
|
||||
IrisPlatform platform = mock(IrisPlatform.class);
|
||||
doAnswer(invocation -> {
|
||||
levels.add(invocation.getArgument(0, LogLevel.class));
|
||||
emitted.add(invocation.getArgument(1, String.class));
|
||||
return null;
|
||||
}).when(platform).log(ArgumentMatchers.any(LogLevel.class), ArgumentMatchers.anyString());
|
||||
IrisPlatforms.bind(platform);
|
||||
}
|
||||
|
||||
@After
|
||||
public void restorePlatform() {
|
||||
IrisPlatforms.unbind();
|
||||
if (previousPlatform != null) {
|
||||
IrisPlatforms.bind(previousPlatform);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aFailedProbeReportsItsNameClassAndMessageAtDebug() {
|
||||
PregenDiagnostics.probeFailed("moonrise worker pool size", new IllegalStateException("no such field"));
|
||||
|
||||
assertEquals(1, emitted.size());
|
||||
assertEquals(LogLevel.DEBUG, levels.get(0));
|
||||
assertTrue(emitted.get(0), emitted.get(0).contains("moonrise worker pool size"));
|
||||
assertTrue(emitted.get(0), emitted.get(0).contains(IllegalStateException.class.getName()));
|
||||
assertTrue(emitted.get(0), emitted.get(0).contains("no such field"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aThrowableWithNoMessageStillReportsItsClass() {
|
||||
PregenDiagnostics.probeFailed("engine access", new NoClassDefFoundError());
|
||||
|
||||
assertEquals(1, emitted.size());
|
||||
assertTrue(emitted.get(0), emitted.get(0).contains(NoClassDefFoundError.class.getName()));
|
||||
assertTrue(emitted.get(0), emitted.get(0).contains("engine access"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aMissingProbeNameAndThrowableStillProduceAReadableLine() {
|
||||
PregenDiagnostics.probeFailed(null, null);
|
||||
|
||||
assertEquals(1, emitted.size());
|
||||
assertTrue(emitted.get(0), emitted.get(0).contains("unnamed"));
|
||||
assertTrue(emitted.get(0), emitted.get(0).contains("no throwable reported"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void percentSignsInAProbeNameAreNotTreatedAsFormatSpecifiers() {
|
||||
PregenDiagnostics.probeFailed("heap at 95% headroom", new IllegalArgumentException("bad %s value"));
|
||||
|
||||
assertEquals(1, emitted.size());
|
||||
assertTrue(emitted.get(0), emitted.get(0).contains("heap at 95% headroom"));
|
||||
assertTrue(emitted.get(0), emitted.get(0).contains("bad %s value"));
|
||||
}
|
||||
}
|
||||
+136
@@ -0,0 +1,136 @@
|
||||
package art.arcane.iris.core.pregenerator;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class PregenSilentFailureContractTest {
|
||||
@Test
|
||||
public void noPregenSourceSwallowsAThrowableWithoutSayingAnything() throws IOException {
|
||||
List<String> offenders = new ArrayList<>();
|
||||
Path pregenRoot = sourceRoot().resolve("art/arcane/iris/core/pregenerator");
|
||||
try (Stream<Path> sources = Files.walk(pregenRoot)) {
|
||||
for (Path source : sources.filter(path -> path.toString().endsWith(".java")).toList()) {
|
||||
String text = Files.readString(source);
|
||||
if (text.contains("catch (Throwable ignored)") || text.contains("catch (Exception ignored)")) {
|
||||
offenders.add(source.getFileName().toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals("silent catches on the pregen path: " + offenders, List.of(), offenders);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mantleCleanupFailureIsReportedWithItsStackTrace() throws IOException {
|
||||
String cleanup = method(read("art/arcane/iris/core/pregenerator/methods/AsyncPregenMethod.java"),
|
||||
"private void cleanupMantleChunk(");
|
||||
|
||||
assertTrue(cleanup, cleanup.contains("IrisLogging.reportError("));
|
||||
assertTrue(cleanup, cleanup.contains("catch (Throwable e)"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aStrandedPluginChunkTicketIsReportedWithItsStackTrace() throws IOException {
|
||||
String unload = method(read("art/arcane/iris/core/pregenerator/methods/AsyncPregenMethod.java"),
|
||||
"private void unloadChunkSafely(");
|
||||
|
||||
assertTrue(unload, unload.contains("removePluginChunkTicket"));
|
||||
assertEquals(unload, 2, countOccurrences(unload, "IrisLogging.reportError("));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void capabilityProbesLogThroughTheNamedDebugHelperRatherThanReportingErrors() throws IOException {
|
||||
String async = read("art/arcane/iris/core/pregenerator/methods/AsyncPregenMethod.java");
|
||||
|
||||
assertTrue(method(async, "private int resolveWorkerPoolThreads()").contains("PregenDiagnostics.probeFailed("));
|
||||
assertTrue(method(async, "private int evictionWindow()").contains("PregenDiagnostics.probeFailed("));
|
||||
assertTrue(method(async, "private Engine resolveMetricsEngine()").contains("PregenDiagnostics.probeFailed("));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void theFoliaSubmitFallbackNamesTheFailureItIsFallingBackFrom() throws IOException {
|
||||
String executor = method(read("art/arcane/iris/core/pregenerator/methods/AsyncPregenMethod.java"),
|
||||
"private class FoliaRegionExecutor");
|
||||
|
||||
assertTrue(executor, executor.contains("PregenDiagnostics.probeFailed("));
|
||||
assertTrue(executor, executor.contains("falling back to a region task"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void backpressureProbesAnnounceWhyTheyFellBack() throws IOException {
|
||||
String backpressure = read("art/arcane/iris/core/pregenerator/PregenMantleBackpressure.java");
|
||||
|
||||
assertTrue(method(backpressure, "private boolean isCancelled()").contains("PregenDiagnostics.probeFailed("));
|
||||
assertTrue(method(backpressure, "private Mantle resolveMantle()").contains("PregenDiagnostics.probeFailed("));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void medievalEngineResolutionAnnouncesWhyItFellBack() throws IOException {
|
||||
String medieval = read("art/arcane/iris/core/pregenerator/methods/MedievalPregenMethod.java");
|
||||
|
||||
assertTrue(method(medieval, "private Engine resolveEngine()").contains("PregenDiagnostics.probeFailed("));
|
||||
}
|
||||
|
||||
private static int countOccurrences(String text, String needle) {
|
||||
int count = 0;
|
||||
int index = text.indexOf(needle);
|
||||
while (index >= 0) {
|
||||
count++;
|
||||
index = text.indexOf(needle, index + needle.length());
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
private static Path sourceRoot() throws IOException {
|
||||
Path current;
|
||||
try {
|
||||
current = Path.of(PregenSilentFailureContractTest.class.getProtectionDomain()
|
||||
.getCodeSource()
|
||||
.getLocation()
|
||||
.toURI());
|
||||
} catch (URISyntaxException e) {
|
||||
throw new IOException("Unable to resolve the core source root", e);
|
||||
}
|
||||
while (current != null && !Files.isDirectory(current.resolve("src/main/java"))) {
|
||||
current = current.getParent();
|
||||
}
|
||||
if (current == null) {
|
||||
throw new IOException("Unable to locate the core source root");
|
||||
}
|
||||
return current.resolve("src/main/java");
|
||||
}
|
||||
|
||||
private static String read(String relativePath) throws IOException {
|
||||
return Files.readString(sourceRoot().resolve(relativePath));
|
||||
}
|
||||
|
||||
private static String method(String source, String signature) {
|
||||
int start = source.indexOf(signature);
|
||||
assertTrue("Missing source contract signature: " + signature, start >= 0);
|
||||
int openBrace = source.indexOf('{', start);
|
||||
assertTrue("Missing source contract method body: " + signature, openBrace >= 0);
|
||||
int depth = 0;
|
||||
for (int index = openBrace; index < source.length(); index++) {
|
||||
char current = source.charAt(index);
|
||||
if (current == '{') {
|
||||
depth++;
|
||||
} else if (current == '}') {
|
||||
depth--;
|
||||
if (depth == 0) {
|
||||
return source.substring(start, index + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Unclosed source contract method: " + signature);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package art.arcane.iris.core.pregenerator;
|
||||
|
||||
import art.arcane.volmlib.util.math.Position2;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class PregenTaskChunkCountTest {
|
||||
@Test
|
||||
public void countMatchesTraversalAcrossChunkAndRegionBoundaries() {
|
||||
int[][] areas = {
|
||||
{0, 0, 1, 1},
|
||||
{0, 0, 16, 32},
|
||||
{17, -17, 15, 33},
|
||||
{-16, -32, 16, 16},
|
||||
{-513, 511, 32, 17},
|
||||
{512, -512, 512, 256},
|
||||
{PregenTask.MAX_WORLD_BLOCK - 32, 0, 32, 1},
|
||||
{0, -PregenTask.MAX_WORLD_BLOCK + 32, 1, 32}
|
||||
};
|
||||
for (int[] area : areas) {
|
||||
PregenTask task = PregenTask.builder()
|
||||
.center(new Position2(area[0], area[1]))
|
||||
.radiusX(area[2])
|
||||
.radiusZ(area[3])
|
||||
.build();
|
||||
AtomicLong visited = new AtomicLong();
|
||||
|
||||
task.iterateAllChunks((x, z) -> visited.incrementAndGet());
|
||||
|
||||
assertEquals("center=" + area[0] + "," + area[1], visited.get(), task.chunkCount());
|
||||
}
|
||||
}
|
||||
|
||||
@Test(timeout = 2_000L)
|
||||
public void entireWorldCountUsesLongArithmeticWithoutTraversal() {
|
||||
PregenTask task = PregenTask.builder()
|
||||
.radiusX(PregenTask.MAX_WORLD_BLOCK)
|
||||
.radiusZ(PregenTask.MAX_WORLD_BLOCK)
|
||||
.build();
|
||||
|
||||
assertEquals(14_062_492_500_001L, task.chunkCount());
|
||||
}
|
||||
}
|
||||
+151
@@ -0,0 +1,151 @@
|
||||
package art.arcane.iris.core.pregenerator.methods;
|
||||
|
||||
import art.arcane.iris.core.pregenerator.PregenListener;
|
||||
import art.arcane.iris.core.pregenerator.PregenMantleBackpressure;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.World;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.Semaphore;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.mockito.Mockito.CALLS_REAL_METHODS;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class AsyncPregenGenerationFailureTest {
|
||||
private static final int OUTSTANDING_REQUESTS = 2;
|
||||
|
||||
@Test
|
||||
public void aGenerationFailureFailsEveryOutstandingRequestAndReleasesTheirPermits() throws Exception {
|
||||
Harness harness = Harness.withOutstanding(OUTSTANDING_REQUESTS);
|
||||
IllegalStateException cause = new IllegalStateException("Accepted hydrology layer exceeds the mantle bounds");
|
||||
|
||||
harness.method.onChunkGenerationFailed(48, -4, cause);
|
||||
|
||||
assertEquals(OUTSTANDING_REQUESTS, harness.semaphore.availablePermits());
|
||||
assertEquals(OUTSTANDING_REQUESTS, harness.failed.get());
|
||||
assertEquals(0, harness.inFlight.get());
|
||||
assertEquals(0, harness.requests.size());
|
||||
verify(harness.listener).onChunkFailed(10, 0);
|
||||
verify(harness.listener).onChunkFailed(11, 0);
|
||||
|
||||
IllegalStateException abort = assertThrows(IllegalStateException.class,
|
||||
() -> harness.method.generateChunk(12, 0, harness.listener));
|
||||
assertSame(cause, abort.getCause());
|
||||
verify(harness.listener, never()).onChunkGenerating(12, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aLateCompletionForASettledRequestIsIgnored() throws Exception {
|
||||
Harness harness = Harness.withOutstanding(OUTSTANDING_REQUESTS);
|
||||
harness.method.onChunkGenerationFailed(48, -4, new IllegalStateException("boom"));
|
||||
|
||||
harness.completeChunk(10, 0, null, null);
|
||||
harness.completeChunk(11, 0, null, new IllegalStateException("late failure"));
|
||||
|
||||
assertEquals(OUTSTANDING_REQUESTS, harness.failed.get());
|
||||
assertEquals(0, harness.completed.get());
|
||||
assertEquals(0, harness.inFlight.get());
|
||||
assertEquals(OUTSTANDING_REQUESTS, harness.semaphore.availablePermits());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void closingAbandonsRequestsThatNeverCompleteAndReturnsTheirPermits() throws Exception {
|
||||
Harness harness = Harness.withOutstanding(OUTSTANDING_REQUESTS);
|
||||
|
||||
harness.abandon(new AsyncPregenMethod.Drain(false, false, OUTSTANDING_REQUESTS));
|
||||
|
||||
assertEquals(OUTSTANDING_REQUESTS, harness.semaphore.availablePermits());
|
||||
assertEquals(OUTSTANDING_REQUESTS, harness.failed.get());
|
||||
assertEquals(0, harness.requests.size());
|
||||
verify(harness.listener).onChunkFailed(10, 0);
|
||||
verify(harness.listener).onChunkFailed(11, 0);
|
||||
}
|
||||
|
||||
private static final class Harness {
|
||||
private final AsyncPregenMethod method;
|
||||
private final Semaphore semaphore;
|
||||
private final PregenInFlightRequests requests;
|
||||
private final PregenListener listener;
|
||||
private final AtomicInteger inFlight;
|
||||
private final AtomicLong failed;
|
||||
private final AtomicLong completed;
|
||||
|
||||
private Harness(AsyncPregenMethod method, Semaphore semaphore, PregenInFlightRequests requests,
|
||||
PregenListener listener, AtomicInteger inFlight, AtomicLong failed, AtomicLong completed) {
|
||||
this.method = method;
|
||||
this.semaphore = semaphore;
|
||||
this.requests = requests;
|
||||
this.listener = listener;
|
||||
this.inFlight = inFlight;
|
||||
this.failed = failed;
|
||||
this.completed = completed;
|
||||
}
|
||||
|
||||
static Harness withOutstanding(int outstanding) throws Exception {
|
||||
AsyncPregenMethod method = mock(AsyncPregenMethod.class, CALLS_REAL_METHODS);
|
||||
World world = mock(World.class);
|
||||
when(world.getName()).thenReturn("qa");
|
||||
Semaphore semaphore = new Semaphore(outstanding, true);
|
||||
semaphore.acquire(outstanding);
|
||||
PregenInFlightRequests requests = new PregenInFlightRequests();
|
||||
PregenListener listener = mock(PregenListener.class);
|
||||
AtomicInteger inFlight = new AtomicInteger(outstanding);
|
||||
AtomicLong failed = new AtomicLong();
|
||||
AtomicLong completed = new AtomicLong();
|
||||
for (int index = 0; index < outstanding; index++) {
|
||||
requests.add(PregenInFlightRequests.key(10 + index, 0), listener);
|
||||
}
|
||||
set(method, "world", world);
|
||||
set(method, "semaphore", semaphore);
|
||||
set(method, "backpressure", mock(PregenMantleBackpressure.class));
|
||||
set(method, "inFlightRequests", requests);
|
||||
set(method, "generationFailure", new AtomicReference<>());
|
||||
set(method, "regionPending", new ConcurrentHashMap<>());
|
||||
set(method, "lastFailedReleaseLogAt", new AtomicLong());
|
||||
set(method, "slowRequestWarnIntervalMs", 15_000);
|
||||
set(method, "inFlight", inFlight);
|
||||
set(method, "submitted", new AtomicLong(outstanding));
|
||||
set(method, "completed", completed);
|
||||
set(method, "failed", failed);
|
||||
set(method, "lastProgressAt", new AtomicLong());
|
||||
set(method, "adaptiveInFlightLimit", new AtomicInteger(outstanding));
|
||||
set(method, "permitMonitor", new Object());
|
||||
set(method, "threads", outstanding);
|
||||
set(method, "closing", new AtomicBoolean());
|
||||
return new Harness(method, semaphore, requests, listener, inFlight, failed, completed);
|
||||
}
|
||||
|
||||
void completeChunk(int x, int z, Chunk chunk, Throwable throwable) throws Exception {
|
||||
Method complete = AsyncPregenMethod.class.getDeclaredMethod(
|
||||
"completeChunk", int.class, int.class, PregenListener.class, Chunk.class, Throwable.class);
|
||||
complete.setAccessible(true);
|
||||
complete.invoke(method, x, z, listener, chunk, throwable);
|
||||
}
|
||||
|
||||
void abandon(AsyncPregenMethod.Drain drain) throws Exception {
|
||||
Method abandon = AsyncPregenMethod.class.getDeclaredMethod(
|
||||
"abandonOutstandingRequests", AsyncPregenMethod.Drain.class);
|
||||
abandon.setAccessible(true);
|
||||
abandon.invoke(method, drain);
|
||||
}
|
||||
|
||||
private static void set(AsyncPregenMethod method, String name, Object value) throws Exception {
|
||||
Field field = AsyncPregenMethod.class.getDeclaredField(name);
|
||||
field.setAccessible(true);
|
||||
field.set(method, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
+26
-2
@@ -90,10 +90,11 @@ public class AsyncPregenMethodConcurrencyCapTest {
|
||||
AtomicInteger warnings = new AtomicInteger();
|
||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
try {
|
||||
Future<Boolean> drain = executor.submit(() -> AsyncPregenMethod.awaitDrain(
|
||||
Future<AsyncPregenMethod.Drain> drain = executor.submit(() -> AsyncPregenMethod.awaitDrain(
|
||||
semaphore,
|
||||
2,
|
||||
10L,
|
||||
5L * 1000L,
|
||||
TimeUnit.MILLISECONDS,
|
||||
warnings::incrementAndGet
|
||||
));
|
||||
@@ -103,11 +104,34 @@ public class AsyncPregenMethodConcurrencyCapTest {
|
||||
}
|
||||
semaphore.release(2);
|
||||
|
||||
assertFalse(drain.get(1L, TimeUnit.SECONDS));
|
||||
AsyncPregenMethod.Drain result = drain.get(1L, TimeUnit.SECONDS);
|
||||
assertTrue(result.drained());
|
||||
assertFalse(result.interrupted());
|
||||
assertEquals(0, result.outstanding());
|
||||
assertTrue(warnings.get() > 0);
|
||||
assertEquals(0, semaphore.availablePermits());
|
||||
} finally {
|
||||
executor.shutdownNow();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void closeDrainGivesUpAtItsDeadlineWhilePermitsStayHeld() {
|
||||
Semaphore semaphore = new Semaphore(0);
|
||||
AtomicInteger warnings = new AtomicInteger();
|
||||
|
||||
AsyncPregenMethod.Drain result = AsyncPregenMethod.awaitDrain(
|
||||
semaphore,
|
||||
2,
|
||||
5L,
|
||||
80L,
|
||||
TimeUnit.MILLISECONDS,
|
||||
warnings::incrementAndGet
|
||||
);
|
||||
|
||||
assertFalse(result.drained());
|
||||
assertFalse(result.interrupted());
|
||||
assertEquals(2, result.outstanding());
|
||||
assertTrue(warnings.get() > 0);
|
||||
}
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
package art.arcane.iris.core.pregenerator.methods;
|
||||
|
||||
import art.arcane.iris.core.pregenerator.PregenListener;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
public class PregenInFlightRequestsTest {
|
||||
@Test
|
||||
public void settlingARequestReturnsItsListenerOnlyOnce() {
|
||||
PregenInFlightRequests requests = new PregenInFlightRequests();
|
||||
PregenListener listener = mock(PregenListener.class);
|
||||
long key = PregenInFlightRequests.key(48, -4);
|
||||
|
||||
assertTrue(requests.add(key, listener));
|
||||
assertEquals(1, requests.size());
|
||||
assertSame(listener, requests.settle(key));
|
||||
assertNull(requests.settle(key));
|
||||
assertEquals(0, requests.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aDuplicateSubmissionKeepsTheOriginalRequest() {
|
||||
PregenInFlightRequests requests = new PregenInFlightRequests();
|
||||
PregenListener first = mock(PregenListener.class);
|
||||
PregenListener second = mock(PregenListener.class);
|
||||
long key = PregenInFlightRequests.key(1, 2);
|
||||
|
||||
assertTrue(requests.add(key, first));
|
||||
assertFalse(requests.add(key, second));
|
||||
assertSame(first, requests.settle(key));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void drainingHandsBackEveryOutstandingRequestExactlyOnce() {
|
||||
PregenInFlightRequests requests = new PregenInFlightRequests();
|
||||
PregenListener listener = mock(PregenListener.class);
|
||||
requests.add(PregenInFlightRequests.key(0, 0), listener);
|
||||
requests.add(PregenInFlightRequests.key(1, 0), listener);
|
||||
requests.add(PregenInFlightRequests.key(-7, 9), listener);
|
||||
|
||||
Map<Long, PregenListener> drained = requests.drain();
|
||||
|
||||
assertEquals(3, drained.size());
|
||||
assertEquals(0, requests.size());
|
||||
assertTrue(requests.drain().isEmpty());
|
||||
assertNull(requests.settle(PregenInFlightRequests.key(1, 0)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void keysKeepNegativeCoordinatesApartAndRoundTrip() {
|
||||
assertNotEquals(PregenInFlightRequests.key(1, -1), PregenInFlightRequests.key(-1, 1));
|
||||
assertNotEquals(PregenInFlightRequests.key(0, -1), PregenInFlightRequests.key(-1, 0));
|
||||
long key = PregenInFlightRequests.key(-48, -4);
|
||||
assertEquals(-48, PregenInFlightRequests.chunkX(key));
|
||||
assertEquals(-4, PregenInFlightRequests.chunkZ(key));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package art.arcane.iris.engine;
|
||||
|
||||
import art.arcane.iris.engine.framework.EnginePlatformHooks;
|
||||
import art.arcane.iris.engine.framework.GenerationSessionException;
|
||||
import art.arcane.iris.engine.object.world.IrisWorld;
|
||||
import art.arcane.iris.spi.PlatformBiome;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.util.project.hunk.Hunk;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.doCallRealMethod;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class IrisEngineMaintenanceRefusalTest {
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void maintenanceThatCannotRunMantleStagesRefusesTheChunkInsteadOfGeneratingIt() throws Exception {
|
||||
IrisEngine engine = mock(IrisEngine.class);
|
||||
EnginePlatformHooks hooks = mock(EnginePlatformHooks.class);
|
||||
when(hooks.shouldRefuseGeneration(engine)).thenReturn(true);
|
||||
Field platformHooks = IrisEngine.class.getDeclaredField("platformHooks");
|
||||
platformHooks.setAccessible(true);
|
||||
platformHooks.set(engine, hooks);
|
||||
IrisWorld world = mock(IrisWorld.class);
|
||||
when(world.name()).thenReturn("world");
|
||||
when(engine.getWorld()).thenReturn(world);
|
||||
doCallRealMethod().when(engine).generate(anyInt(), anyInt(), any(), any(), anyBoolean());
|
||||
Hunk<PlatformBlockState> blocks = mock(Hunk.class);
|
||||
Hunk<PlatformBiome> biomes = mock(Hunk.class);
|
||||
|
||||
GenerationSessionException refused = assertThrows(GenerationSessionException.class,
|
||||
() -> engine.generate(32, 48, blocks, biomes, false));
|
||||
|
||||
assertTrue(refused.isExpectedTeardown());
|
||||
verify(engine, never()).acquireGenerationLease(anyString());
|
||||
verifyNoInteractions(blocks, biomes);
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import org.junit.Test;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.RejectedExecutionException;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -22,6 +23,7 @@ import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyDouble;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -85,6 +87,27 @@ public class DecoratorCoreTest {
|
||||
assertNull(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pickDecorator_contentFailure_skipsThatDecorator() {
|
||||
ResolvedDecorator broken = mock(ResolvedDecorator.class);
|
||||
when(broken.passesChanceGate(anyDouble(), anyDouble())).thenThrow(new IllegalArgumentException("malformed decorator"));
|
||||
ResolvedDecorator healthy = mock(ResolvedDecorator.class);
|
||||
when(healthy.passesChanceGate(anyDouble(), anyDouble())).thenReturn(true);
|
||||
|
||||
ResolvedDecorator result = DecoratorCore.pickDecorator(new ResolvedDecorator[]{broken, healthy}, new RNG(2L), 0.0, 0.0, ModuleLogs.discarding());
|
||||
assertSame(healthy, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pickDecorator_engineFailure_endsTheChunk() {
|
||||
ResolvedDecorator closed = mock(ResolvedDecorator.class);
|
||||
RejectedExecutionException failure = new RejectedExecutionException("pool shut down");
|
||||
when(closed.passesChanceGate(anyDouble(), anyDouble())).thenThrow(failure);
|
||||
|
||||
assertSame(failure, assertThrows(RejectedExecutionException.class, () ->
|
||||
DecoratorCore.pickDecorator(new ResolvedDecorator[]{closed}, new RNG(2L), 0.0, 0.0, ModuleLogs.discarding())));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pickDecorator_singleCandidate_alwaysReturnsThat() {
|
||||
ResolvedDecorator d = mock(ResolvedDecorator.class);
|
||||
|
||||
@@ -0,0 +1,184 @@
|
||||
package art.arcane.iris.engine.mantle;
|
||||
|
||||
import art.arcane.iris.engine.object.value.IrisPosition;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class MantleWriterNeighborhoodTest {
|
||||
@Test
|
||||
public void balloonedVoxelsMatchTheReferenceSphereForFractionalRadii() {
|
||||
for (double radius : new double[]{0.0D, 0.5D, 1.0D, 1.5D, 2.0D, 3.7D, 5.0D}) {
|
||||
Set<IrisPosition> seeds = line(-3, 60, 7, 4, 63, 9);
|
||||
assertEquals("radius " + radius, referenceBallooned(seeds, radius), MantleWriter.getBallooned(seeds, radius));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hollowedVoxelsMatchTheReferenceSurfaceExtraction() {
|
||||
Set<IrisPosition> ballooned = MantleWriter.getBallooned(line(0, 40, 0, 6, 44, 3), 4.0D);
|
||||
|
||||
assertEquals(referenceHollowed(ballooned), MantleWriter.getHollowed(ballooned));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hollowingASolidBlockKeepsOnlyItsShell() {
|
||||
Set<IrisPosition> solid = new LinkedHashSet<>();
|
||||
for (int x = 0; x < 5; x++) {
|
||||
for (int y = 0; y < 5; y++) {
|
||||
for (int z = 0; z < 5; z++) {
|
||||
solid.add(new IrisPosition(x, y, z));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Set<IrisPosition> hollow = MantleWriter.getHollowed(solid);
|
||||
|
||||
assertEquals(98, hollow.size());
|
||||
assertFalse(hollow.contains(new IrisPosition(2, 2, 2)));
|
||||
assertTrue(hollow.contains(new IrisPosition(0, 2, 2)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aSetTooWideToPackFallsBackToPositionEqualityWithoutChangingTheResult() {
|
||||
Set<IrisPosition> spread = new LinkedHashSet<>();
|
||||
spread.add(new IrisPosition(-20_000_000, 60, 0));
|
||||
spread.add(new IrisPosition(20_000_000, 60, 0));
|
||||
spread.add(new IrisPosition(20_000_001, 60, 0));
|
||||
|
||||
assertEquals(referenceHollowed(spread), MantleWriter.getHollowed(spread));
|
||||
assertEquals(spread, MantleWriter.getHollowed(spread));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void maskedVoxelsMatchTheReferenceMaskExpansion() {
|
||||
Set<IrisPosition> seeds = line(0, 70, 0, 3, 70, 4);
|
||||
Set<IrisPosition> masks = new LinkedHashSet<>();
|
||||
masks.add(new IrisPosition(0, 0, 0));
|
||||
masks.add(new IrisPosition(1, 0, 0));
|
||||
masks.add(new IrisPosition(0, 1, 0));
|
||||
masks.add(new IrisPosition(-1, 0, 1));
|
||||
masks.add(new IrisPosition(0, 0, -2));
|
||||
|
||||
assertEquals(referenceMasked(seeds, masks, 3.0D), MantleWriter.getMasked(seeds, masks, 3.0D));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void anEmptyMaskProducesNoVoxels() {
|
||||
assertTrue(MantleWriter.getMasked(line(0, 70, 0, 2, 70, 2), new LinkedHashSet<>(), 2.0D).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aPositionLookupReportsMembershipOutsideItsBoundingBoxAsAbsent() {
|
||||
Set<IrisPosition> positions = new LinkedHashSet<>();
|
||||
positions.add(new IrisPosition(10, 20, 30));
|
||||
MantleWriter.PositionLookup lookup = MantleWriter.PositionLookup.of(positions);
|
||||
|
||||
assertTrue(lookup.contains(10, 20, 30));
|
||||
assertFalse(lookup.contains(9, 20, 30));
|
||||
assertFalse(lookup.contains(10, 20, 31));
|
||||
assertFalse(lookup.contains(Integer.MIN_VALUE, 20, 30));
|
||||
assertFalse(lookup.contains(Integer.MAX_VALUE, 20, 30));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void anEmptyPositionLookupContainsNothing() {
|
||||
MantleWriter.PositionLookup lookup = MantleWriter.PositionLookup.of(new LinkedHashSet<>());
|
||||
|
||||
assertFalse(lookup.contains(0, 0, 0));
|
||||
assertFalse(lookup.contains(-1, -1, -1));
|
||||
}
|
||||
|
||||
private static Set<IrisPosition> line(int x1, int y1, int z1, int x2, int y2, int z2) {
|
||||
Set<IrisPosition> positions = new LinkedHashSet<>();
|
||||
int steps = Math.max(Math.max(Math.abs(x2 - x1), Math.abs(y2 - y1)), Math.abs(z2 - z1));
|
||||
for (int step = 0; step <= steps; step++) {
|
||||
double t = steps == 0 ? 0D : (double) step / steps;
|
||||
positions.add(new IrisPosition(
|
||||
(int) Math.round(x1 + t * (x2 - x1)),
|
||||
(int) Math.round(y1 + t * (y2 - y1)),
|
||||
(int) Math.round(z1 + t * (z2 - z1))));
|
||||
}
|
||||
return positions;
|
||||
}
|
||||
|
||||
static Set<IrisPosition> referenceBallooned(Set<IrisPosition> vset, double radius) {
|
||||
Set<IrisPosition> returnset = new HashSet<>();
|
||||
int ceilrad = (int) Math.ceil(radius);
|
||||
double r2 = Math.pow(radius, 2);
|
||||
|
||||
for (IrisPosition v : vset) {
|
||||
int tipx = v.getX();
|
||||
int tipy = v.getY();
|
||||
int tipz = v.getZ();
|
||||
|
||||
for (int loopx = tipx - ceilrad; loopx <= tipx + ceilrad; loopx++) {
|
||||
for (int loopy = tipy - ceilrad; loopy <= tipy + ceilrad; loopy++) {
|
||||
for (int loopz = tipz - ceilrad; loopz <= tipz + ceilrad; loopz++) {
|
||||
if (referenceHypot(loopx - tipx, loopy - tipy, loopz - tipz) <= r2) {
|
||||
returnset.add(new IrisPosition(loopx, loopy, loopz));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return returnset;
|
||||
}
|
||||
|
||||
static Set<IrisPosition> referenceHollowed(Set<IrisPosition> vset) {
|
||||
Set<IrisPosition> returnset = new LinkedHashSet<>();
|
||||
for (IrisPosition v : vset) {
|
||||
double x = v.getX();
|
||||
double y = v.getY();
|
||||
double z = v.getZ();
|
||||
if (!(vset.contains(new IrisPosition(x + 1, y, z))
|
||||
&& vset.contains(new IrisPosition(x - 1, y, z))
|
||||
&& vset.contains(new IrisPosition(x, y + 1, z))
|
||||
&& vset.contains(new IrisPosition(x, y - 1, z))
|
||||
&& vset.contains(new IrisPosition(x, y, z + 1))
|
||||
&& vset.contains(new IrisPosition(x, y, z - 1)))) {
|
||||
returnset.add(v);
|
||||
}
|
||||
}
|
||||
return returnset;
|
||||
}
|
||||
|
||||
static Set<IrisPosition> referenceMasked(Set<IrisPosition> vectors, Set<IrisPosition> masks, double radius) {
|
||||
Set<IrisPosition> vset = new LinkedHashSet<>();
|
||||
int ceil = (int) Math.ceil(radius);
|
||||
double r2 = Math.pow(radius, 2);
|
||||
|
||||
for (IrisPosition v : vectors) {
|
||||
int tipX = v.getX();
|
||||
int tipY = v.getY();
|
||||
int tipZ = v.getZ();
|
||||
|
||||
for (int x = -ceil; x <= ceil; x++) {
|
||||
for (int y = -ceil; y <= ceil; y++) {
|
||||
for (int z = -ceil; z <= ceil; z++) {
|
||||
if (referenceHypot(x, y, z) > r2 || !masks.contains(new IrisPosition(x, y, z))) {
|
||||
continue;
|
||||
}
|
||||
vset.add(new IrisPosition(tipX + x, tipY + y, tipZ + z));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return vset;
|
||||
}
|
||||
|
||||
private static double referenceHypot(double... pars) {
|
||||
double sum = 0;
|
||||
for (double d : pars) {
|
||||
sum += Math.pow(d, 2);
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
}
|
||||
+34
@@ -38,6 +38,7 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@@ -58,6 +59,39 @@ public class FloatingObjectPlacingBoundaryRadiusTest {
|
||||
assertEquals(33, FloatingObjectPlacing.reach(pack(new FloatingChildSettings(List.of(floatingChild)), resources), ModuleLogs.discarding()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void packWithoutFloatingChildrenHasNoReach() {
|
||||
assertEquals(0, FloatingObjectPlacing.reach(pack(new FloatingChildSettings(List.of()), mock(PackResources.class)), ModuleLogs.discarding()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void floatingChildWithoutObjectsHasNoReach() {
|
||||
FloatingChildBiome floatingChild = TestSettings.with(new FloatingChildBiome(), "inheritObjects", false);
|
||||
|
||||
assertEquals(0, FloatingObjectPlacing.reach(pack(new FloatingChildSettings(List.of(floatingChild)), mock(PackResources.class)), ModuleLogs.discarding()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void placementOfMissingObjectKeepsTheMinimumReach() {
|
||||
ObjectPlacement placement = TestSettings.of(ObjectPlacement.class, "{\"place\":[\"test/missing\"]}");
|
||||
FloatingChildBiome floatingChild = TestSettings.with(new FloatingChildBiome(), "extraObjects", List.of(placement));
|
||||
PackResources resources = mock(PackResources.class);
|
||||
PackObjects objects = mock(PackObjects.class);
|
||||
when(resources.objects()).thenReturn(objects);
|
||||
when(objects.sizeOf(any())).thenReturn(Optional.empty());
|
||||
|
||||
assertEquals(16, FloatingObjectPlacing.reach(pack(new FloatingChildSettings(List.of(floatingChild)), resources), ModuleLogs.discarding()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void failedReachScanKeepsTheMinimumReach() {
|
||||
PackSettings failing = mock(PackSettings.class);
|
||||
when(failing.resources()).thenReturn(mock(PackResources.class));
|
||||
when(failing.declared(any())).thenThrow(new IllegalStateException("Unavailable settings"));
|
||||
|
||||
assertEquals(16, FloatingObjectPlacing.reach(failing, ModuleLogs.discarding()));
|
||||
}
|
||||
|
||||
private static PackSettings pack(FloatingChildSettings declared, PackResources resources) {
|
||||
return new PackSettings() {
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package art.arcane.iris.platform.bukkit;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
public class BukkitPlatformHostReleaseTest {
|
||||
@After
|
||||
public void clearHost() {
|
||||
BukkitPlatform.releaseHost();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void releasingTheHostDropsThePluginTheHudAndTheBridges() {
|
||||
BukkitPlatform.hostPlugin(mock(Plugin.class));
|
||||
BukkitPlatform.hostConsoleSender(() -> null);
|
||||
|
||||
BukkitPlatform.releaseHost();
|
||||
|
||||
assertFalse(BukkitPlatform.hasPlugin());
|
||||
assertFalse(BukkitPlatform.hasHud());
|
||||
assertThrows(IllegalStateException.class, BukkitPlatform::console);
|
||||
}
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
package art.arcane.iris.util.common.scheduling;
|
||||
|
||||
import art.arcane.iris.platform.bukkit.BukkitPlatform;
|
||||
import art.arcane.iris.spi.IrisPlatform;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.volmlib.util.scheduling.FoliaScheduler;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.MockedStatic;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.mockStatic;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class JPluginEnabledCheckTest {
|
||||
private final Plugin plugin = mock(Plugin.class);
|
||||
private final PluginManager manager = mock(PluginManager.class);
|
||||
private final BukkitScheduler scheduler = mock(BukkitScheduler.class);
|
||||
|
||||
@Before
|
||||
public void bindBukkitHost() {
|
||||
IrisPlatform platform = mock(IrisPlatform.class);
|
||||
when(platform.platformName()).thenReturn("bukkit");
|
||||
IrisPlatforms.bind(platform);
|
||||
BukkitPlatform.hostPlugin(plugin);
|
||||
}
|
||||
|
||||
@After
|
||||
public void unbindBukkitHost() {
|
||||
BukkitPlatform.hostPlugin(null);
|
||||
IrisPlatforms.unbind();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void enabledCheckReadsThePluginWithoutTheManagerMonitor() {
|
||||
when(plugin.isEnabled()).thenReturn(true);
|
||||
|
||||
scheduleAsync();
|
||||
|
||||
verify(scheduler).runTaskAsynchronously(eq(plugin), any(Runnable.class));
|
||||
verify(manager, never()).isPluginEnabled(any(Plugin.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void disabledPluginRejectsSchedulingWithoutTheManagerMonitor() {
|
||||
when(plugin.isEnabled()).thenReturn(false);
|
||||
|
||||
scheduleAsync();
|
||||
|
||||
verify(scheduler, never()).runTaskAsynchronously(any(Plugin.class), any(Runnable.class));
|
||||
verify(manager, never()).isPluginEnabled(any(Plugin.class));
|
||||
}
|
||||
|
||||
private void scheduleAsync() {
|
||||
try (MockedStatic<Bukkit> bukkit = mockStatic(Bukkit.class);
|
||||
MockedStatic<FoliaScheduler> folia = mockStatic(FoliaScheduler.class)) {
|
||||
bukkit.when(Bukkit::getPluginManager).thenReturn(manager);
|
||||
bukkit.when(Bukkit::getScheduler).thenReturn(scheduler);
|
||||
J.aBukkit(() -> {
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
package art.arcane.iris.util.project.hunk.storage;
|
||||
|
||||
import art.arcane.iris.util.project.hunk.Hunk;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class VolmLibStorageHunkTest {
|
||||
private static final int WIDTH = 3;
|
||||
private static final int HEIGHT = 4;
|
||||
private static final int DEPTH = 5;
|
||||
|
||||
@Test
|
||||
public void everyStorageHunkReadsBackWhatWasWritten() {
|
||||
assertRoundTrip(new ArrayHunk<Integer>(WIDTH, HEIGHT, DEPTH));
|
||||
assertRoundTrip(new AtomicHunk<Integer>(WIDTH, HEIGHT, DEPTH));
|
||||
assertRoundTrip(new SynchronizedArrayHunk<Integer>(WIDTH, HEIGHT, DEPTH));
|
||||
assertRoundTrip(new AtomicIntegerHunk(WIDTH, HEIGHT, DEPTH));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void atomicHunksReportAtomic() {
|
||||
assertTrue(new AtomicHunk<Integer>(WIDTH, HEIGHT, DEPTH).isAtomic());
|
||||
assertTrue(new AtomicDoubleHunk(WIDTH, HEIGHT, DEPTH).isAtomic());
|
||||
assertTrue(new AtomicIntegerHunk(WIDTH, HEIGHT, DEPTH).isAtomic());
|
||||
assertTrue(new AtomicLongHunk(WIDTH, HEIGHT, DEPTH).isAtomic());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void filledHunkHoldsTheValueEverywhere() {
|
||||
ArrayHunk<Integer> hunk = new ArrayHunk<>(WIDTH, HEIGHT, DEPTH);
|
||||
hunk.fill(7);
|
||||
|
||||
assertEquals(Integer.valueOf(7), hunk.getRaw(0, 0, 0));
|
||||
assertEquals(Integer.valueOf(7), hunk.getRaw(WIDTH - 1, HEIGHT - 1, DEPTH - 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptyHunkIsRejected() {
|
||||
assertThrows(RuntimeException.class, () -> new ArrayHunk<Integer>(0, HEIGHT, DEPTH));
|
||||
}
|
||||
|
||||
private static void assertRoundTrip(Hunk<Integer> hunk) {
|
||||
assertEquals(WIDTH, hunk.getWidth());
|
||||
assertEquals(HEIGHT, hunk.getHeight());
|
||||
assertEquals(DEPTH, hunk.getDepth());
|
||||
|
||||
for (int x = 0; x < WIDTH; x++) {
|
||||
for (int y = 0; y < HEIGHT; y++) {
|
||||
for (int z = 0; z < DEPTH; z++) {
|
||||
hunk.setRaw(x, y, z, x * 100 + y * 10 + z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int x = 0; x < WIDTH; x++) {
|
||||
for (int y = 0; y < HEIGHT; y++) {
|
||||
for (int z = 0; z < DEPTH; z++) {
|
||||
assertEquals(Integer.valueOf(x * 100 + y * 10 + z), hunk.getRaw(x, y, z));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package art.arcane.iris.util.project.interpolation;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class IrisInterpolationRangeScaleTest {
|
||||
private static final double TOLERANCE = 1e-12;
|
||||
|
||||
@Test
|
||||
public void degenerateSourceRangeKeepsIrisArithmetic() {
|
||||
assertTrue(Double.isNaN(IrisInterpolation.rangeScale(0, 1, 5, 5, 5)));
|
||||
assertTrue(Double.isInfinite(IrisInterpolation.rangeScale(0, 1, 5, 5, 6)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rangeScaleMapsAcrossTheRange() {
|
||||
assertEquals(0.25, IrisInterpolation.rangeScale(0, 1, 0, 8, 2), TOLERANCE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inheritedInterpolationStillBlends() {
|
||||
assertEquals(2.5, IrisInterpolation.lerp(2, 3, 0.5), TOLERANCE);
|
||||
assertEquals(1.5, IrisInterpolation.blerp(1, 2, 1, 2, 0.5, 0.5), TOLERANCE);
|
||||
assertEquals(2.5, IrisInterpolation.hermite(1, 2, 3, 4, 0.5, 0, 0), TOLERANCE);
|
||||
}
|
||||
}
|
||||
@@ -81,8 +81,6 @@ art/arcane/volmlib/util/data/base/ComplexCacheBase
|
||||
art/arcane/volmlib/util/director/DirectorNodeBase
|
||||
art/arcane/volmlib/util/director/DirectorParameterBase
|
||||
art/arcane/volmlib/util/director/theme/DirectorThemes
|
||||
art/arcane/volmlib/util/interpolation/InterpolationMethod
|
||||
art/arcane/volmlib/util/interpolation/IrisInterpolation
|
||||
art/arcane/volmlib/util/math/INode
|
||||
art/arcane/volmlib/util/math/IrisMathHelper
|
||||
art/arcane/volmlib/util/math/KochanekBartelsInterpolation
|
||||
@@ -92,11 +90,6 @@ art/arcane/volmlib/util/board/BoardManager
|
||||
art/arcane/volmlib/util/board/BoardUpdateTask
|
||||
art/arcane/volmlib/util/bukkit/Placeholders
|
||||
art/arcane/volmlib/util/hunk/HunkFactory
|
||||
art/arcane/volmlib/util/hunk/storage/ArrayHunk
|
||||
art/arcane/volmlib/util/hunk/storage/AtomicDoubleHunk
|
||||
art/arcane/volmlib/util/hunk/storage/AtomicIntegerHunk
|
||||
art/arcane/volmlib/util/hunk/storage/AtomicLongHunk
|
||||
art/arcane/volmlib/util/hunk/storage/SynchronizedArrayHunk
|
||||
art/arcane/volmlib/util/hunk/view/BiomeForceBridge
|
||||
art/arcane/volmlib/util/hunk/view/BiomeGridForceSupport
|
||||
art/arcane/volmlib/util/hunk/view/BiomeGridHunkHolder
|
||||
|
||||
@@ -20,6 +20,7 @@ package art.arcane.iris.engine.decorator;
|
||||
import art.arcane.iris.builtin.decorant.DecorationPart;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.ModuleLog;
|
||||
import com.volmit.generation.GenerationFailures;
|
||||
import com.volmit.geometry.BlockFace;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.block.BlockTrait;
|
||||
@@ -94,7 +95,7 @@ final class DecoratorCore {
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
log.error("A decorator failed to pick for the column", e);
|
||||
GenerationFailures.skipPlacement(log, e, "decorator", "chance gate", "at " + realX + "," + realZ);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,7 +153,7 @@ final class DecoratorCore {
|
||||
data.set(x, lowerY, z, lower);
|
||||
data.set(x, upperY, z, upper);
|
||||
} catch (Throwable e) {
|
||||
scene.log().error("Failed to place a two-block plant", e);
|
||||
GenerationFailures.skipPlacement(scene.log(), e, "decoration", bd.toString(), "at " + realX + "," + lowerY + "," + realZ);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -322,7 +323,7 @@ final class DecoratorCore {
|
||||
data.set(xf, lowerY, zf, lower);
|
||||
data.set(xf, upperY, zf, upper);
|
||||
} catch (Throwable e) {
|
||||
scene.log().error("Failed to place a two-block plant", e);
|
||||
GenerationFailures.skipPlacement(scene.log(), e, "decoration", bd.toString(), "at " + xf + "," + lowerY + "," + zf);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
+10
-12
@@ -41,6 +41,7 @@ import com.volmit.ModuleLog;
|
||||
import com.volmit.config.FeatureSettings.Entry;
|
||||
import com.volmit.config.Level;
|
||||
import com.volmit.config.SettingsStack;
|
||||
import com.volmit.generation.GenerationFailures;
|
||||
import com.volmit.object.PlaceableObject;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.stage.MantleStageContext;
|
||||
@@ -245,8 +246,8 @@ final class ChunkObjectPlacing {
|
||||
tally.triggered(scope);
|
||||
placeObject(tally, placement, scope);
|
||||
} catch (Throwable failure) {
|
||||
skipObjectPlacement("object", "in " + ownerKind(scope) + " " + ownerName, placement, failure);
|
||||
tally.errors++;
|
||||
logPlacementFailure("Failed to place objects in the following " + ownerKind(scope) + ": " + ownerName, placement, failure);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -283,8 +284,8 @@ final class ChunkObjectPlacing {
|
||||
try {
|
||||
placeCaveObject(tally, placement, profile, scope, expectedCaveBiome, anchors);
|
||||
} catch (Throwable failure) {
|
||||
skipObjectPlacement("cave object", "in " + ownerKind(scope) + " " + ownerName, placement, failure);
|
||||
tally.errors++;
|
||||
logPlacementFailure("Failed to place cave objects in the following " + ownerKind(scope) + ": " + ownerName, placement, failure);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -293,10 +294,8 @@ final class ChunkObjectPlacing {
|
||||
return scope.startsWith("biome") ? "biome" : "region";
|
||||
}
|
||||
|
||||
private void logPlacementFailure(String message, ObjectPlacement placement, Throwable failure) {
|
||||
log.error(message, failure);
|
||||
log.error("Object(s) " + String.join(", ", placement.place()) + " (" + failure.getClass().getSimpleName() + ").", null);
|
||||
log.error("Are these objects missing?", null);
|
||||
private void skipObjectPlacement(String kind, String where, ObjectPlacement placement, Throwable failure) {
|
||||
GenerationFailures.skipPlacement(log, failure, kind, String.join(", ", placement.place()), where);
|
||||
}
|
||||
|
||||
private void placeObject(Tally tally, ObjectPlacement placement, String scope) {
|
||||
@@ -337,9 +336,9 @@ final class ChunkObjectPlacing {
|
||||
}
|
||||
traceObjectResult(scope, object, result, x, z, densityIndex, density);
|
||||
} catch (Throwable failure) {
|
||||
GenerationFailures.skipPlacement(log, failure, "object", object.name(),
|
||||
"in chunk " + chunkX + "," + chunkZ + " scope " + scope + " attempt " + densityIndex + "/" + density);
|
||||
tally.errors++;
|
||||
log.error("Regen object placement exception: chunk=" + chunkX + "," + chunkZ + " scope=" + scope + " object=" + object.name()
|
||||
+ " densityIndex=" + densityIndex + " density=" + density + " error=" + failure.getClass().getSimpleName() + ":" + failure.getMessage(), failure);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -373,9 +372,9 @@ final class ChunkObjectPlacing {
|
||||
search.minDepthBelowSurface(), tags, null);
|
||||
tallyCave(tally, contained, scope, object, placement, i, density, search, anchor);
|
||||
} catch (Throwable failure) {
|
||||
GenerationFailures.skipPlacement(log, failure, "cave object", object.name(),
|
||||
"in chunk " + chunkX + "," + chunkZ + " scope " + scope + " attempt " + i + "/" + density);
|
||||
tally.errors++;
|
||||
log.error("Regen cave object placement exception: chunk=" + chunkX + "," + chunkZ + " scope=" + scope + " object=" + object.name()
|
||||
+ " densityIndex=" + i + " density=" + density + " error=" + failure.getClass().getSimpleName() + ":" + failure.getMessage(), failure);
|
||||
CaveRejects.log(log,scope, "EXCEPTION", chunkX, chunkZ, placement, object, i, density, search, anchor.y(), failure);
|
||||
}
|
||||
}
|
||||
@@ -430,8 +429,7 @@ final class ChunkObjectPlacing {
|
||||
try {
|
||||
placeUpperObject(placement, forcePlace, scope);
|
||||
} catch (Throwable failure) {
|
||||
log.error("Failed to place upper-dimension objects in " + kind + " " + ownerKey + ": " + String.join(", ", placement.place())
|
||||
+ " (" + failure.getClass().getSimpleName() + ")", failure);
|
||||
skipObjectPlacement("upper-dimension object", "in " + kind + " " + ownerKey, placement, failure);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+23
-8
@@ -40,6 +40,7 @@ import com.volmit.ModuleLog;
|
||||
import com.volmit.config.FeatureSettings.Entry;
|
||||
import com.volmit.config.Level;
|
||||
import com.volmit.config.PackSettings;
|
||||
import com.volmit.generation.GenerationFailures;
|
||||
import com.volmit.geometry.BlockBox;
|
||||
import com.volmit.geometry.BlockPosition;
|
||||
import com.volmit.resource.ResourceId;
|
||||
@@ -57,7 +58,8 @@ import java.util.Set;
|
||||
/**
|
||||
* Places the objects of floating child biomes on and under their islands into the mantle for
|
||||
* {@link art.arcane.iris.engine.modifier.FloatingModule}. One per world. Its reach is the largest placement reach of any
|
||||
* floating object the dimension's biomes can place, at least 16 blocks.
|
||||
* floating object the dimension's biomes can place, at least 16 blocks once any of them places objects, and none when
|
||||
* no floating biome places objects.
|
||||
*/
|
||||
public final class FloatingObjectPlacing {
|
||||
private static final int INVERTED_PICK_ATTEMPTS = 8;
|
||||
@@ -76,13 +78,15 @@ public final class FloatingObjectPlacing {
|
||||
private final ObjectPool objects;
|
||||
private final FloatingPlacer placer;
|
||||
private final long mantleSeed;
|
||||
private final int reachBlocks;
|
||||
private final ModuleLog log;
|
||||
|
||||
FloatingObjectPlacing(FloatingWorld world, ObjectPool objects, FloatingPlacer placer, long mantleSeed, ModuleLog log) {
|
||||
FloatingObjectPlacing(FloatingWorld world, ObjectPool objects, FloatingPlacer placer, long mantleSeed, int reachBlocks, ModuleLog log) {
|
||||
this.world = world;
|
||||
this.objects = objects;
|
||||
this.placer = placer;
|
||||
this.mantleSeed = mantleSeed;
|
||||
this.reachBlocks = reachBlocks;
|
||||
this.log = log;
|
||||
}
|
||||
|
||||
@@ -90,11 +94,15 @@ public final class FloatingObjectPlacing {
|
||||
public static FloatingObjectPlacing of(PackWorld world, ModuleLog log) {
|
||||
return world.state(FloatingObjectPlacing.class,
|
||||
generating -> new FloatingObjectPlacing(FloatingWorld.of(generating), ObjectPool.of(generating),
|
||||
new FloatingPlacer(generating, log), generating.seed(IrisSeedPurposes.MANTLE), log));
|
||||
new FloatingPlacer(generating, log), generating.seed(IrisSeedPurposes.MANTLE),
|
||||
reach(generating.settings(), log), log));
|
||||
}
|
||||
|
||||
/** Places what originates in the chunk of {@code context} into the mantle. */
|
||||
public void place(MantleStageContext context) {
|
||||
if (reachBlocks == 0) {
|
||||
return;
|
||||
}
|
||||
int minX = context.originX();
|
||||
int minZ = context.originZ();
|
||||
BlockBox bounds = context.terrain().bounds();
|
||||
@@ -389,9 +397,9 @@ public final class FloatingObjectPlacing {
|
||||
|
||||
/** How far, in blocks along X and Z, the floating objects of the pack {@code settings} describe may write beyond their chunk. */
|
||||
public static int reach(PackSettings settings, ModuleLog log) {
|
||||
Reach reach = new Reach(settings.resources(), biomeObjectsOf(settings), log);
|
||||
int maxObjectExtent = MIN_REACH_BLOCKS;
|
||||
int maxObjectExtent = 0;
|
||||
try {
|
||||
Reach reach = new Reach(settings.resources(), biomeObjectsOf(settings), log);
|
||||
for (Entry<FloatingChildSettings> declared : settings.declared(FloatingChildSettings.class)) {
|
||||
if (declared.level() != Level.BIOME) {
|
||||
continue;
|
||||
@@ -402,7 +410,9 @@ public final class FloatingObjectPlacing {
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
GenerationFailures.rethrowEngineFailure(e);
|
||||
log.error("Failed to work out the reach of the floating biomes' objects", e);
|
||||
maxObjectExtent = Math.max(maxObjectExtent, MIN_REACH_BLOCKS);
|
||||
}
|
||||
return maxObjectExtent;
|
||||
}
|
||||
@@ -452,8 +462,7 @@ public final class FloatingObjectPlacing {
|
||||
}
|
||||
|
||||
int of(FloatingChildBiome child, ResourceId parent) {
|
||||
int reach = 0;
|
||||
reach = Math.max(reach, placementRadius(child.floatingObjects()));
|
||||
int reach = placementRadius(child.floatingObjects());
|
||||
reach = Math.max(reach, placementRadius(child.extraObjects()));
|
||||
reach = Math.max(reach, placementRadius(child.topObjectOverrides()));
|
||||
reach = Math.max(reach, placementRadius(child.bottomObjectOverrides()));
|
||||
@@ -462,13 +471,18 @@ public final class FloatingObjectPlacing {
|
||||
reach = Math.max(reach, placementRadius(ResolvedFloatingChild.topObjects(child, surface)));
|
||||
reach = Math.max(reach, placementRadius(ResolvedFloatingChild.bottomObjects(child)));
|
||||
} catch (Throwable e) {
|
||||
GenerationFailures.rethrowEngineFailure(e);
|
||||
log.error("Failed to work out the reach of a floating biome's objects", e);
|
||||
reach = Math.max(reach, MIN_REACH_BLOCKS);
|
||||
}
|
||||
return reach;
|
||||
}
|
||||
|
||||
private int placementRadius(List<ObjectPlacement> placements) {
|
||||
int radius = 0;
|
||||
if (placements.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
int radius = MIN_REACH_BLOCKS;
|
||||
for (ObjectPlacement placement : placements) {
|
||||
if (placement == null) {
|
||||
continue;
|
||||
@@ -492,6 +506,7 @@ public final class FloatingObjectPlacing {
|
||||
}
|
||||
return reach;
|
||||
} catch (Throwable e) {
|
||||
GenerationFailures.rethrowEngineFailure(e);
|
||||
log.error("Failed to size a floating object", e);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ import com.volmit.ModuleLog;
|
||||
import com.volmit.block.BlockRegistry;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.block.BlockTrait;
|
||||
import com.volmit.generation.GenerationFailures;
|
||||
import com.volmit.geometry.BlockPosition;
|
||||
import com.volmit.object.BlockEntityData;
|
||||
import com.volmit.object.ObjectBlock;
|
||||
@@ -112,7 +113,7 @@ final class FloatingPlacer {
|
||||
try {
|
||||
place(ObjectRun.of(object, floating, worldX, SAMPLED_HEIGHT, worldZ), context.placementTerrain(), object, id);
|
||||
} catch (Throwable failure) {
|
||||
log.error("Failed to place a floating object", failure);
|
||||
GenerationFailures.skipPlacement(log, failure, "floating object", object.name(), "at " + worldX + "," + worldZ);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,7 +154,7 @@ final class FloatingPlacer {
|
||||
}
|
||||
} catch (Throwable failure) {
|
||||
transaction.discard();
|
||||
log.error("Failed to place an " + kind + " floating object", failure);
|
||||
GenerationFailures.skipPlacement(log, failure, kind + " floating object", object.name(), "at " + worldX + "," + y + "," + worldZ);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ import art.arcane.iris.modules.objects.ObjectSize;
|
||||
import com.volmit.ModuleLog;
|
||||
import com.volmit.config.FeatureSettings.Entry;
|
||||
import com.volmit.config.PackSettings;
|
||||
import com.volmit.generation.GenerationFailures;
|
||||
import com.volmit.geometry.BlockBox;
|
||||
import com.volmit.resource.PackResources;
|
||||
|
||||
@@ -93,6 +94,7 @@ final class PlacementReach {
|
||||
}
|
||||
return reach;
|
||||
} catch (Throwable failure) {
|
||||
GenerationFailures.rethrowEngineFailure(failure);
|
||||
log.error("Failed to work out the reach of an object placement", failure);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ import com.volmit.ModuleLog;
|
||||
import com.volmit.block.BlockRegistry;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.config.FeatureSettings;
|
||||
import com.volmit.generation.GenerationFailures;
|
||||
import com.volmit.hunk.Hunk;
|
||||
import com.volmit.mantle.Mantle;
|
||||
import com.volmit.resource.ResourceId;
|
||||
@@ -229,7 +230,7 @@ final class FloatingIslands {
|
||||
RNG colRng = rng.nextParallelRNG((int) FloatingIslandSample.columnSeed(world.baseSeed(), wx, wz));
|
||||
FloatingDecorator.decorateColumn(scene, decorated, DecorationPart.NONE, xf, zf, wx, wz, topY, max, colRng, NOOP_DECORATION_MISS);
|
||||
} catch (Throwable e) {
|
||||
log.error("Failed to decorate the top of a floating island", e);
|
||||
GenerationFailures.skipPlacement(log, e, "decoration", "floating island top", "at " + wx + "," + topY + "," + wz);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -263,7 +264,7 @@ final class FloatingIslands {
|
||||
try {
|
||||
new IrisSeaSurfaceDecorator(scene).decorate(xf, zf, wx, wx + 1, wx - 1, wz, wz + 1, wz - 1, decorated, fluidTopY, chunk.height);
|
||||
} catch (Throwable e) {
|
||||
log.error("Failed to decorate the sea surface of a floating island", e);
|
||||
GenerationFailures.skipPlacement(log, e, "decoration", "floating island sea surface", "at " + wx + "," + fluidTopY + "," + wz);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -330,7 +331,7 @@ final class FloatingIslands {
|
||||
try {
|
||||
generated.add(layer.get(random.nextParallelRNG(i + j), (wx + j) / layer.zoom(), j, (wz - j) / layer.zoom()));
|
||||
} catch (Throwable e) {
|
||||
log.error("Failed to pick a block of a floating island's palette", e);
|
||||
GenerationFailures.skipPlacement(log, e, "palette block", "floating island", "at " + wx + "," + wz + " depth " + j);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -427,6 +428,7 @@ final class FloatingIslands {
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
GenerationFailures.rethrowEngineFailure(e);
|
||||
log.error("Failed to write the sky biomes of a floating island", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.ModuleLog;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.config.FeatureSettings;
|
||||
import com.volmit.generation.GenerationFailures;
|
||||
import com.volmit.noise.NoiseFactory;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.world.PackWorld;
|
||||
@@ -301,7 +302,7 @@ public final class BiomeLayers {
|
||||
try {
|
||||
blocks.add(layer.get(random, index + j, (wx + j) / blocksPerSample, j, (wz - j) / blocksPerSample));
|
||||
} catch (Throwable e) {
|
||||
log.error("A biome layer failed to pick a block", e);
|
||||
GenerationFailures.skipPlacement(log, e, "layer block", "biome layer " + index, "at " + (long) wx + "," + (long) wz + " depth " + j);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user