From 9d886e3c696df0ff551b684b75cba112a7184d32 Mon Sep 17 00:00:00 2001 From: piexel Date: Sat, 10 Oct 2026 15:18:05 +0200 Subject: [PATCH] Iris binds AtomicCache's failure handler to its logging and error reporting at startup --- .../src/main/java/art/arcane/iris/Iris.java | 2 + .../iris/modded/ModdedEngineBootstrap.java | 2 + .../iris/engine/data/cache/AtomicCache.java | 197 ----------- .../cache/AtomicCacheFailureReporting.java | 51 +++ .../arcane/iris/engine/data/cache/Cache.java | 47 --- .../iris/util/common/data/VectorMap.java | 331 ------------------ .../util/common/math/IrisBlockVector.java | 34 -- .../iris/util/common/math/IrisVector.java | 163 --------- .../iris/util/common/math/Vector3i.java | 65 ---- .../core/DiagnosticSeverityPolicyTest.java | 2 +- .../engine/data/cache/AtomicCacheTest.java | 106 ------ 11 files changed, 56 insertions(+), 944 deletions(-) delete mode 100644 core/src/main/java/art/arcane/iris/engine/data/cache/AtomicCache.java create mode 100644 core/src/main/java/art/arcane/iris/engine/data/cache/AtomicCacheFailureReporting.java delete mode 100644 core/src/main/java/art/arcane/iris/engine/data/cache/Cache.java delete mode 100644 core/src/main/java/art/arcane/iris/util/common/data/VectorMap.java delete mode 100644 core/src/main/java/art/arcane/iris/util/common/math/IrisBlockVector.java delete mode 100644 core/src/main/java/art/arcane/iris/util/common/math/IrisVector.java delete mode 100644 core/src/main/java/art/arcane/iris/util/common/math/Vector3i.java delete mode 100644 core/src/test/java/art/arcane/iris/engine/data/cache/AtomicCacheTest.java diff --git a/adapters/bukkit/plugin/src/main/java/art/arcane/iris/Iris.java b/adapters/bukkit/plugin/src/main/java/art/arcane/iris/Iris.java index 2decee372..0041c1a39 100644 --- a/adapters/bukkit/plugin/src/main/java/art/arcane/iris/Iris.java +++ b/adapters/bukkit/plugin/src/main/java/art/arcane/iris/Iris.java @@ -19,6 +19,7 @@ package art.arcane.iris; import art.arcane.iris.engine.IrisEngineEffects; +import art.arcane.iris.engine.data.cache.AtomicCacheFailureReporting; import art.arcane.iris.engine.IrisWorldManager; import art.arcane.iris.engine.framework.EngineComponentCleanup; @@ -804,6 +805,7 @@ public class Iris extends VolmitPlugin implements Listener, ReloadAware { public void onEnable() { IrisPlatforms.bind(new BukkitPlatform()); + AtomicCacheFailureReporting.bind(); IrisStartupValidation.begin(); Bukkit.getPluginManager().registerEvents(new IrisStartupAdmissionListener(), this); Bukkit.getPluginManager().registerEvents(pendingWorldReplacements, this); diff --git a/adapters/modded-common/src/main/java/art/arcane/iris/modded/ModdedEngineBootstrap.java b/adapters/modded-common/src/main/java/art/arcane/iris/modded/ModdedEngineBootstrap.java index 685bbdef6..50540e54d 100644 --- a/adapters/modded-common/src/main/java/art/arcane/iris/modded/ModdedEngineBootstrap.java +++ b/adapters/modded-common/src/main/java/art/arcane/iris/modded/ModdedEngineBootstrap.java @@ -20,6 +20,7 @@ package art.arcane.iris.modded; import art.arcane.iris.core.gui.GuiHost; import art.arcane.iris.core.localization.IrisLanguage; +import art.arcane.iris.engine.data.cache.AtomicCacheFailureReporting; import art.arcane.iris.engine.decorator.DecoratorPlatformHooks; import art.arcane.iris.engine.framework.Engine; import art.arcane.iris.engine.framework.EngineEffectsProvider; @@ -348,6 +349,7 @@ public final class ModdedEngineBootstrap { IrisPlatform previousPlatform = IrisPlatforms.isBound() ? IrisPlatforms.get() : null; IrisPlatforms.bind(created); + AtomicCacheFailureReporting.bind(); rollback.add(() -> restorePlatform(previousPlatform)); ModdedServerAccess previousServerAccess = ModdedDimensionManager.bindAccess( diff --git a/core/src/main/java/art/arcane/iris/engine/data/cache/AtomicCache.java b/core/src/main/java/art/arcane/iris/engine/data/cache/AtomicCache.java deleted file mode 100644 index 61f3c367d..000000000 --- a/core/src/main/java/art/arcane/iris/engine/data/cache/AtomicCache.java +++ /dev/null @@ -1,197 +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 . - */ - -package art.arcane.iris.engine.data.cache; - -import art.arcane.iris.spi.IrisLogging; -import art.arcane.volmlib.util.function.NastySupplier; - -import java.util.function.Supplier; - -public class AtomicCache { - private static final Object NULL_VALUE = new Object(); - private transient final Object initLock = new Object(); - private transient final boolean nullSupport; - private transient volatile Object value; - private transient volatile Throwable failure; - - public AtomicCache() { - this(false); - } - - public AtomicCache(boolean nullSupport) { - this.nullSupport = nullSupport; - } - - public void reset() { - synchronized (initLock) { - value = null; - failure = null; - } - } - - public T getIfPresent() { - return unwrap(value); - } - - public T aquireNasty(NastySupplier t) { - return aquire(() -> { - try { - return t.get(); - } catch (Throwable e) { - return null; - } - }); - } - - public T aquireNastyPrint(NastySupplier t) { - return aquire(() -> { - try { - return t.get(); - } catch (Throwable e) { - IrisLogging.reportError("Atomic cache supplier failed.", e); - return null; - } - }); - } - - /** - * Like {@link #aquire(Supplier)} but propagates a supplier failure to the caller instead - * of swallowing it into a null return. For values that are mandatory: a caller of a - * "@NotNull" accessor should see the supplier's real exception, not a downstream NPE. - *

- * The supplier is retried on every call until it produces a value, which is what a caller that can - * repair the cause between attempts needs. Use {@link #aquireOnceOrThrow(Supplier)} when re-running a - * failed supplier is itself the problem. - */ - public T aquireOrThrow(Supplier t) { - Object v = value; - - if (v != null) { - return unwrap(v); - } - - synchronized (initLock) { - v = value; - - if (v != null) { - return unwrap(v); - } - - T computed = t.get(); - if (computed == null) { - throw new IllegalStateException("Atomic cache supplier produced null"); - } - value = computed; - return computed; - } - } - - /** - * Like {@link #aquireOrThrow(Supplier)} but memoizes the failure as well as the value, so a supplier - * that cannot produce one is run exactly once and every later caller is told the same reason. For - * values whose supplier rebuilds shared state, where re-running it per call repeats that work and - * hides the original cause behind whatever the retry happens to fail on. {@link #reset()} clears it. - */ - public T aquireOnceOrThrow(Supplier t) { - Object v = value; - - if (v != null) { - return unwrap(v); - } - rethrowFailure(failure); - - synchronized (initLock) { - v = value; - - if (v != null) { - return unwrap(v); - } - rethrowFailure(failure); - - T computed; - try { - computed = t.get(); - if (computed == null) { - throw new IllegalStateException("Atomic cache supplier produced null"); - } - } catch (Throwable e) { - failure = e; - throw e; - } - value = computed; - return computed; - } - } - - private static void rethrowFailure(Throwable memoized) { - if (memoized == null) { - return; - } - if (memoized instanceof RuntimeException runtimeFailure) { - throw runtimeFailure; - } - if (memoized instanceof Error error) { - throw error; - } - throw new IllegalStateException("Atomic cache supplier failed", memoized); - } - - public T aquire(Supplier t) { - Object v = value; - - if (v != null) { - return unwrap(v); - } - - synchronized (initLock) { - v = value; - - if (v != null) { - return unwrap(v); - } - - try { - T computed = t.get(); - - if (computed != null) { - value = computed; - return computed; - } - - if (nullSupport) { - value = NULL_VALUE; - } - } catch (Throwable e) { - // aquire retries on every call, so a supplier that stays broken is reached per sample. - // The first statement of it carries the stack; the rest are traces of the same cause. - if (IrisLogging.warnOnce("atomic-cache:" + e.getClass().getName() + ":" + e.getMessage(), - "Atomic cache supplier failed: %s: %s", e.getClass().getSimpleName(), e.getMessage())) { - IrisLogging.reportError(e); - } - } - - return null; - } - } - - @SuppressWarnings("unchecked") - private T unwrap(Object v) { - return v == null || v == NULL_VALUE ? null : (T) v; - } -} diff --git a/core/src/main/java/art/arcane/iris/engine/data/cache/AtomicCacheFailureReporting.java b/core/src/main/java/art/arcane/iris/engine/data/cache/AtomicCacheFailureReporting.java new file mode 100644 index 000000000..40b18fb9f --- /dev/null +++ b/core/src/main/java/art/arcane/iris/engine/data/cache/AtomicCacheFailureReporting.java @@ -0,0 +1,51 @@ +/* + * 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 . + */ + +package art.arcane.iris.engine.data.cache; + +import art.arcane.iris.spi.IrisLogging; +import art.arcane.volmlib.util.cache.AtomicCache; +import art.arcane.volmlib.util.cache.AtomicCacheFailureHandler; + +/** + * Sends the failures of {@link AtomicCache} suppliers to Iris's logging and error reporting. Bound once at startup; + * it needs no platform of its own because {@link IrisLogging} falls back to the process streams when none is bound. + */ +public final class AtomicCacheFailureReporting implements AtomicCacheFailureHandler { + private AtomicCacheFailureReporting() { + } + + public static void bind() { + AtomicCache.setFailureHandler(new AtomicCacheFailureReporting()); + } + + @Override + public void supplierFailed(Throwable failure) { + IrisLogging.reportError("Atomic cache supplier failed.", failure); + } + + @Override + public void optionalSupplierFailed(Throwable failure) { + // aquire retries on every call, so a supplier that stays broken is reached per sample. + // The first statement of it carries the stack; the rest are traces of the same cause. + if (IrisLogging.warnOnce("atomic-cache:" + failure.getClass().getName() + ":" + failure.getMessage(), + "Atomic cache supplier failed: %s: %s", failure.getClass().getSimpleName(), failure.getMessage())) { + IrisLogging.reportError(failure); + } + } +} diff --git a/core/src/main/java/art/arcane/iris/engine/data/cache/Cache.java b/core/src/main/java/art/arcane/iris/engine/data/cache/Cache.java deleted file mode 100644 index acc1879e7..000000000 --- a/core/src/main/java/art/arcane/iris/engine/data/cache/Cache.java +++ /dev/null @@ -1,47 +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 . - */ - -package art.arcane.iris.engine.data.cache; - -import art.arcane.volmlib.util.cache.CacheKey; - -public interface Cache { - static long key(int x, int z) { - return CacheKey.key(x, z); - } - - static int keyX(long key) { - return CacheKey.keyX(key); - } - - static int keyZ(long key) { - return CacheKey.keyZ(key); - } - - static int to1D(int x, int y, int z, int w, int h) { - return CacheKey.to1D(x, y, z, w, h); - } - - static int[] to3D(int idx, int w, int h) { - return CacheKey.to3D(idx, w, h); - } - - int getId(); - - V get(int x, int z); -} diff --git a/core/src/main/java/art/arcane/iris/util/common/data/VectorMap.java b/core/src/main/java/art/arcane/iris/util/common/data/VectorMap.java deleted file mode 100644 index 770f8753a..000000000 --- a/core/src/main/java/art/arcane/iris/util/common/data/VectorMap.java +++ /dev/null @@ -1,331 +0,0 @@ -package art.arcane.iris.util.common.data; - -import art.arcane.volmlib.util.collection.KMap; -import lombok.NonNull; -import art.arcane.iris.util.common.math.IrisBlockVector; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Iterator; -import java.util.Map; -import java.util.NoSuchElementException; -import java.util.function.BiConsumer; -import java.util.function.Function; - -public class VectorMap implements Iterable> { - private final Map> map = new KMap<>(); - private transient volatile long modificationRevision; - - public long modificationRevision() { - return modificationRevision; - } - - public int size() { - return map.values().stream().mapToInt(Map::size).sum(); - } - - public boolean isEmpty() { - return map.values().stream().allMatch(Map::isEmpty); - } - - public boolean containsKey(@NonNull IrisBlockVector vector) { - if (map.isEmpty()) return false; - var chunk = map.get(chunk(vector)); - return chunk != null && chunk.containsKey(relative(vector)); - } - - public boolean containsValue(@NonNull T value) { - return map.values().stream().anyMatch(m -> m.containsValue(value)); - } - - public @Nullable T get(@NonNull IrisBlockVector vector) { - if (map.isEmpty()) return null; - var chunk = map.get(chunk(vector)); - return chunk == null ? null : chunk.get(relative(vector)); - } - - public @Nullable T put(@NonNull IrisBlockVector vector, @NonNull T value) { - T previous = map.computeIfAbsent(chunk(vector), k -> new KMap<>()) - .put(relative(vector), value); - modificationRevision++; - return previous; - } - - public @Nullable T computeIfAbsent(@NonNull IrisBlockVector vector, @NonNull Function<@NonNull IrisBlockVector, @NonNull T> mappingFunction) { - boolean[] inserted = new boolean[1]; - T value = map.computeIfAbsent(chunk(vector), key -> new KMap<>()) - .computeIfAbsent(relative(vector), key -> { - inserted[0] = true; - return mappingFunction.apply(vector); - }); - if (inserted[0]) { - modificationRevision++; - } - return value; - } - - @SuppressWarnings("unchecked") - public @Nullable T remove(@NonNull IrisBlockVector vector) { - if (map.isEmpty()) return null; - Key relative = relative(vector); - Object[] removed = new Object[1]; - - // computeIfPresent so the emptied bucket is pruned atomically against a concurrent put. - map.computeIfPresent(chunk(vector), (key, chunk) -> { - removed[0] = chunk.remove(relative); - return chunk.isEmpty() ? null : chunk; - }); - - if (removed[0] != null) { - modificationRevision++; - } - - return (T) removed[0]; - } - - public void putAll(@NonNull VectorMap map) { - map.forEach(this::put); - } - - public void clear() { - if (!map.isEmpty()) { - modificationRevision++; - } - map.clear(); - } - - public void forEach(@NonNull BiConsumer<@NonNull IrisBlockVector, @NonNull T> consumer) { - map.forEach((chunk, values) -> { - int rX = chunk.x << 10; - int rY = chunk.y << 10; - int rZ = chunk.z << 10; - - values.forEach((relative, value) -> consumer.accept( - relative.resolve(rX, rY, rZ), - value - )); - }); - } - - private static Key chunk(IrisBlockVector vector) { - return new Key(vector.getBlockX() >> 10, vector.getBlockY() >> 10, vector.getBlockZ() >> 10); - } - - private static Key relative(IrisBlockVector vector) { - return new Key(vector.getBlockX() & 0x3FF, vector.getBlockY() & 0x3FF, vector.getBlockZ() & 0x3FF); - } - - @Override - public @NotNull EntryIterator iterator() { - return new EntryIterator(); - } - - /** - * Allocation-free entry walk. {@link EntryIterator} allocates a resolved vector plus a Map.Entry per element; - * the cursor resolves into one reused vector instead. Only valid for callers that do not retain the vector - * returned by {@link Cursor#key()} beyond the current step - clone it if it must outlive the next - * {@link Cursor#next()}. - */ - public @NotNull Cursor cursor() { - return new Cursor(); - } - - public @NotNull KeyIterator keys() { - return new KeyIterator(); - } - - public @NotNull ValueIterator values() { - return new ValueIterator(); - } - - public final class Cursor { - private final Iterator>> chunkIterator = map.entrySet().iterator(); - private final IrisBlockVector position = new IrisBlockVector(0, 0, 0); - private Iterator> relativeIterator; - private int rX, rY, rZ; - private T value; - - public boolean next() { - while (relativeIterator == null || !relativeIterator.hasNext()) { - if (!chunkIterator.hasNext()) { - value = null; - return false; - } - - Map.Entry> chunk = chunkIterator.next(); - rX = chunk.getKey().x << 10; - rY = chunk.getKey().y << 10; - rZ = chunk.getKey().z << 10; - relativeIterator = chunk.getValue().entrySet().iterator(); - } - - Map.Entry entry = relativeIterator.next(); - Key relative = entry.getKey(); - position.setX(rX + relative.x); - position.setY(rY + relative.y); - position.setZ(rZ + relative.z); - value = entry.getValue(); - return true; - } - - /** - * The position of the current element. The same instance is returned every step. - */ - public @NotNull IrisBlockVector key() { - return position; - } - - public T value() { - return value; - } - } - - public class EntryIterator implements Iterator> { - private final Iterator>> chunkIterator = map.entrySet().iterator(); - private Iterator> relativeIterator; - private int rX, rY, rZ; - - @Override - public boolean hasNext() { - return advance(); - } - - @Override - public Map.Entry next() { - if (!advance()) throw new NoSuchElementException(); - - var entry = relativeIterator.next(); - return Map.entry(entry.getKey().resolve(rX, rY, rZ), entry.getValue()); - } - - private boolean advance() { - while (relativeIterator == null || !relativeIterator.hasNext()) { - if (!chunkIterator.hasNext()) return false; - var chunk = chunkIterator.next(); - rX = chunk.getKey().x << 10; - rY = chunk.getKey().y << 10; - rZ = chunk.getKey().z << 10; - relativeIterator = chunk.getValue().entrySet().iterator(); - } - - return true; - } - - @Override - public void remove() { - if (relativeIterator == null) throw new IllegalStateException("No element to remove"); - relativeIterator.remove(); - modificationRevision++; - } - } - - public class KeyIterator implements Iterator, Iterable { - private final Iterator>> chunkIterator = map.entrySet().iterator(); - private Iterator relativeIterator; - private int rX, rY, rZ; - - @Override - public boolean hasNext() { - return advance(); - } - - @Override - public IrisBlockVector next() { - if (!advance()) throw new NoSuchElementException(); - - return relativeIterator.next().resolve(rX, rY, rZ); - } - - private boolean advance() { - while (relativeIterator == null || !relativeIterator.hasNext()) { - if (!chunkIterator.hasNext()) return false; - var chunk = chunkIterator.next(); - rX = chunk.getKey().x << 10; - rY = chunk.getKey().y << 10; - rZ = chunk.getKey().z << 10; - relativeIterator = chunk.getValue().keySet().iterator(); - } - - return true; - } - - @Override - public void remove() { - if (relativeIterator == null) throw new IllegalStateException("No element to remove"); - relativeIterator.remove(); - modificationRevision++; - } - - @Override - public @NotNull Iterator iterator() { - return this; - } - } - - public class ValueIterator implements Iterator, Iterable { - private final Iterator> chunkIterator = map.values().iterator(); - private Iterator relativeIterator; - - @Override - public boolean hasNext() { - return advance(); - } - - @Override - public T next() { - if (!advance()) throw new NoSuchElementException(); - - return relativeIterator.next(); - } - - private boolean advance() { - while (relativeIterator == null || !relativeIterator.hasNext()) { - if (!chunkIterator.hasNext()) return false; - relativeIterator = chunkIterator.next().values().iterator(); - } - - return true; - } - - @Override - public void remove() { - if (relativeIterator == null) throw new IllegalStateException("No element to remove"); - relativeIterator.remove(); - modificationRevision++; - } - - @Override - public @NotNull Iterator iterator() { - return this; - } - } - - private static final class Key { - private final int x; - private final int y; - private final int z; - private final int hashCode; - - private Key(int x, int y, int z) { - this.x = x; - this.y = y; - this.z = z; - this.hashCode = (x << 20) | (y << 10) | z; - } - - private IrisBlockVector resolve(int rX, int rY, int rZ) { - return new IrisBlockVector(rX + x, rY + y, rZ + z); - } - - @Override - public int hashCode() { - return hashCode; - } - - @Override - public boolean equals(Object o) { - if (!(o instanceof Key key)) return false; - return x == key.x && y == key.y && z == key.z; - } - } -} diff --git a/core/src/main/java/art/arcane/iris/util/common/math/IrisBlockVector.java b/core/src/main/java/art/arcane/iris/util/common/math/IrisBlockVector.java deleted file mode 100644 index 288fb8e87..000000000 --- a/core/src/main/java/art/arcane/iris/util/common/math/IrisBlockVector.java +++ /dev/null @@ -1,34 +0,0 @@ -package art.arcane.iris.util.common.math; - -public class IrisBlockVector extends IrisVector { - public IrisBlockVector() { - super(); - } - - public IrisBlockVector(int x, int y, int z) { - super(x, y, z); - } - - public IrisBlockVector(double x, double y, double z) { - super(x, y, z); - } - - @Override - public IrisBlockVector clone() { - return (IrisBlockVector) super.clone(); - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof IrisBlockVector other)) { - return false; - } - - return (int) other.getX() == (int) this.x && (int) other.getY() == (int) this.y && (int) other.getZ() == (int) this.z; - } - - @Override - public int hashCode() { - return (Integer.hashCode((int) x) >> 13) ^ (Integer.hashCode((int) y) >> 7) ^ Integer.hashCode((int) z); - } -} diff --git a/core/src/main/java/art/arcane/iris/util/common/math/IrisVector.java b/core/src/main/java/art/arcane/iris/util/common/math/IrisVector.java deleted file mode 100644 index 49c125ac4..000000000 --- a/core/src/main/java/art/arcane/iris/util/common/math/IrisVector.java +++ /dev/null @@ -1,163 +0,0 @@ -package art.arcane.iris.util.common.math; - -public class IrisVector implements Cloneable { - private static final double EPSILON = 0.000001; - protected double x; - protected double y; - protected double z; - - public IrisVector() { - this.x = 0; - this.y = 0; - this.z = 0; - } - - public IrisVector(int x, int y, int z) { - this.x = x; - this.y = y; - this.z = z; - } - - public IrisVector(double x, double y, double z) { - this.x = x; - this.y = y; - this.z = z; - } - - public double getX() { - return x; - } - - public double getY() { - return y; - } - - public double getZ() { - return z; - } - - public int getBlockX() { - return floor(x); - } - - public int getBlockY() { - return floor(y); - } - - public int getBlockZ() { - return floor(z); - } - - public IrisVector setX(double x) { - this.x = x; - return this; - } - - public IrisVector setY(double y) { - this.y = y; - return this; - } - - public IrisVector setZ(double z) { - this.z = z; - return this; - } - - public IrisVector add(IrisVector vec) { - x += vec.x; - y += vec.y; - z += vec.z; - return this; - } - - public IrisVector subtract(IrisVector vec) { - x -= vec.x; - y -= vec.y; - z -= vec.z; - return this; - } - - public IrisVector multiply(double m) { - x *= m; - y *= m; - z *= m; - return this; - } - - public double distance(IrisVector o) { - return Math.sqrt(square(x - o.x) + square(y - o.y) + square(z - o.z)); - } - - public double distanceSquared(IrisVector o) { - return square(x - o.x) + square(y - o.y) + square(z - o.z); - } - - public IrisVector rotateAroundX(double angle) { - double angleCos = Math.cos(angle); - double angleSin = Math.sin(angle); - double y = angleCos * this.y - angleSin * this.z; - double z = angleSin * this.y + angleCos * this.z; - return setY(y).setZ(z); - } - - public IrisVector rotateAroundY(double angle) { - double angleCos = Math.cos(angle); - double angleSin = Math.sin(angle); - double x = angleCos * this.x + angleSin * this.z; - double z = -angleSin * this.x + angleCos * this.z; - return setX(x).setZ(z); - } - - public IrisVector rotateAroundZ(double angle) { - double angleCos = Math.cos(angle); - double angleSin = Math.sin(angle); - double x = angleCos * this.x - angleSin * this.y; - double y = angleSin * this.x + angleCos * this.y; - return setX(x).setY(y); - } - - public IrisBlockVector toBlockVector() { - return new IrisBlockVector(x, y, z); - } - - @Override - public IrisVector clone() { - try { - return (IrisVector) super.clone(); - } catch (CloneNotSupportedException e) { - throw new Error(e); - } - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof IrisVector other)) { - return false; - } - - return Math.abs(x - other.x) < EPSILON && Math.abs(y - other.y) < EPSILON && Math.abs(z - other.z) < EPSILON && this.getClass().equals(obj.getClass()); - } - - @Override - public int hashCode() { - int hash = 7; - hash = 79 * hash + (int) (Double.doubleToLongBits(this.x) ^ (Double.doubleToLongBits(this.x) >>> 32)); - hash = 79 * hash + (int) (Double.doubleToLongBits(this.y) ^ (Double.doubleToLongBits(this.y) >>> 32)); - hash = 79 * hash + (int) (Double.doubleToLongBits(this.z) ^ (Double.doubleToLongBits(this.z) >>> 32)); - return hash; - } - - @Override - public String toString() { - return x + "," + y + "," + z; - } - - protected static int floor(double num) { - int floor = (int) num; - return floor == num ? floor : floor - (int) (Double.doubleToRawLongBits(num) >>> 63); - } - - private static double square(double num) { - return num * num; - } -} diff --git a/core/src/main/java/art/arcane/iris/util/common/math/Vector3i.java b/core/src/main/java/art/arcane/iris/util/common/math/Vector3i.java deleted file mode 100644 index 9051e0c07..000000000 --- a/core/src/main/java/art/arcane/iris/util/common/math/Vector3i.java +++ /dev/null @@ -1,65 +0,0 @@ -package art.arcane.iris.util.common.math; - -public class Vector3i implements Cloneable { - private final int x; - private final int y; - private final int z; - - public Vector3i(int x, int y, int z) { - this.x = x; - this.y = y; - this.z = z; - } - - public int getX() { - return x; - } - - public int getY() { - return y; - } - - public int getZ() { - return z; - } - - public int getBlockX() { - return x; - } - - public int getBlockY() { - return y; - } - - public int getBlockZ() { - return z; - } - - @Override - public Vector3i clone() { - try { - return (Vector3i) super.clone(); - } catch (CloneNotSupportedException e) { - throw new Error(e); - } - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof Vector3i other)) { - return false; - } - - return x == other.x && y == other.y && z == other.z; - } - - @Override - public int hashCode() { - return x ^ (z << 12) ^ (y << 24); - } - - @Override - public String toString() { - return x + "," + y + "," + z; - } -} diff --git a/core/src/test/java/art/arcane/iris/core/DiagnosticSeverityPolicyTest.java b/core/src/test/java/art/arcane/iris/core/DiagnosticSeverityPolicyTest.java index 8794c3fc3..64a84b6e4 100644 --- a/core/src/test/java/art/arcane/iris/core/DiagnosticSeverityPolicyTest.java +++ b/core/src/test/java/art/arcane/iris/core/DiagnosticSeverityPolicyTest.java @@ -33,7 +33,7 @@ public class DiagnosticSeverityPolicyTest { assertLoggedWith("engine/mantle/MantleWriter.java", "Mantle Writer Accessed chunk out of bounds", "debug"); assertLoggedWith("engine/decorator/ResolvedDecorator.java", "Empty Block Data for ", "warnOnce"); assertLoggedWith("engine/object/compatibility/IrisCompat.java", "Can't find block data for ", "warnOnce"); - assertLoggedWith("engine/data/cache/AtomicCache.java", "Atomic cache supplier failed: %s: %s", "warnOnce"); + assertLoggedWith("engine/data/cache/AtomicCacheFailureReporting.java", "Atomic cache supplier failed: %s: %s", "warnOnce"); assertLoggedWith("engine/IrisComplex.java", "Failed to sample interpolated biome bounds", "warnOnce"); assertLoggedWith("engine/framework/placer/WorldObjectPlacer.java", "Tried to place custom block at", "warnOnce"); } diff --git a/core/src/test/java/art/arcane/iris/engine/data/cache/AtomicCacheTest.java b/core/src/test/java/art/arcane/iris/engine/data/cache/AtomicCacheTest.java deleted file mode 100644 index 50aa29006..000000000 --- a/core/src/test/java/art/arcane/iris/engine/data/cache/AtomicCacheTest.java +++ /dev/null @@ -1,106 +0,0 @@ -package art.arcane.iris.engine.data.cache; - -import org.junit.Test; - -import java.util.concurrent.atomic.AtomicInteger; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertThrows; - -public class AtomicCacheTest { - @Test - public void aquireOnceOrThrowCachesTheComputedValue() { - AtomicCache cache = new AtomicCache<>(); - AtomicInteger calls = new AtomicInteger(); - - assertEquals("value", cache.aquireOnceOrThrow(() -> { - calls.incrementAndGet(); - return "value"; - })); - assertEquals("value", cache.aquireOnceOrThrow(() -> { - calls.incrementAndGet(); - return "other"; - })); - assertEquals(1, calls.get()); - } - - /** - * The retrying variant is what a caller that can repair the cause between attempts needs, and the - * world generator relies on it, so memoization must stay confined to aquireOnceOrThrow. - */ - @Test - public void aquireOrThrowStillRetriesAFailedSupplier() { - AtomicCache cache = new AtomicCache<>(); - AtomicInteger calls = new AtomicInteger(); - - assertThrows(IllegalStateException.class, () -> cache.aquireOrThrow(() -> { - calls.incrementAndGet(); - throw new IllegalStateException("repairable"); - })); - assertEquals("repaired", cache.aquireOrThrow(() -> { - calls.incrementAndGet(); - return "repaired"; - })); - assertEquals(2, calls.get()); - } - - @Test - public void aquireOnceOrThrowMemoizesTheSupplierFailureInsteadOfRerunningIt() { - AtomicCache cache = new AtomicCache<>(); - AtomicInteger calls = new AtomicInteger(); - IllegalStateException cause = new IllegalStateException("Frozen Iris pack snapshot is missing"); - - IllegalStateException first = assertThrows(IllegalStateException.class, () -> cache.aquireOnceOrThrow(() -> { - calls.incrementAndGet(); - throw cause; - })); - IllegalStateException second = assertThrows(IllegalStateException.class, () -> cache.aquireOnceOrThrow(() -> { - calls.incrementAndGet(); - return "recovered"; - })); - - assertSame(cause, first); - assertSame(cause, second); - assertEquals("the failure is stated once and replayed, never recomputed", 1, calls.get()); - } - - @Test - public void aquireOnceOrThrowRejectsANullValueAndRemembersThat() { - AtomicCache cache = new AtomicCache<>(); - AtomicInteger calls = new AtomicInteger(); - - assertThrows(IllegalStateException.class, () -> cache.aquireOnceOrThrow(() -> { - calls.incrementAndGet(); - return null; - })); - assertThrows(IllegalStateException.class, () -> cache.aquireOnceOrThrow(() -> { - calls.incrementAndGet(); - return "recovered"; - })); - assertEquals(1, calls.get()); - } - - @Test - public void resetClearsAMemoizedFailure() { - AtomicCache cache = new AtomicCache<>(); - - assertThrows(IllegalStateException.class, () -> cache.aquireOnceOrThrow(() -> { - throw new IllegalStateException("transient"); - })); - cache.reset(); - - assertEquals("recovered", cache.aquireOnceOrThrow(() -> "recovered")); - } - - @Test - public void aquireStillSwallowsFailuresForOptionalValues() { - AtomicCache cache = new AtomicCache<>(); - - assertNull(cache.aquire(() -> { - throw new IllegalStateException("optional value"); - })); - assertEquals("later", cache.aquire(() -> "later")); - } -}