From 8748d85e376edfc9d0c7e14e0421785b75c93022 Mon Sep 17 00:00:00 2001 From: piexel Date: Tue, 10 Nov 2026 01:16:52 +0100 Subject: [PATCH] Reuse VolmLib's hunk, interpolation and face types and drop the dead util wrappers Iris carried copies of VolmLib's storage hunks, interpolation statics and HunkFace, plus wrappers nothing used. The storage hunks and IrisInterpolation now extend VolmLib's, Hunk uses VolmLib's HunkFace, and the Iris rangeScale stays so interpolation output does not change. The newly shipped VolmLib classes leave the Bukkit jar's left-out list. Upstream: 355d7f413 355161408 114cc68a0 --- core/build.gradle | 5 +- core/purity-allowlist.txt | 4 - .../iris/util/common/board/BoardSettings.java | 51 ------ .../util/common/board/ScoreDirection.java | 16 -- .../inventorygui/UIStaticDecorator.java | 40 ----- .../iris/util/common/inventorygui/Window.java | 84 ---------- .../common/inventorygui/WindowResolution.java | 43 ------ .../iris/util/common/math/VectorMath.java | 78 ---------- .../arcane/iris/util/project/hunk/Hunk.java | 1 + .../iris/util/project/hunk/HunkFace.java | 42 ----- .../util/project/hunk/storage/ArrayHunk.java | 33 +--- .../hunk/storage/AtomicDoubleHunk.java | 30 +--- .../util/project/hunk/storage/AtomicHunk.java | 37 +---- .../hunk/storage/AtomicIntegerHunk.java | 31 +--- .../project/hunk/storage/AtomicLongHunk.java | 31 +--- .../project/hunk/storage/StorageHunk.java | 22 +-- .../hunk/storage/SynchronizedArrayHunk.java | 38 +---- .../interpolation/InterpolationType.java | 27 ---- .../interpolation/IrisInterpolation.java | 146 +----------------- .../hunk/storage/VolmLibStorageHunkTest.java | 66 ++++++++ .../IrisInterpolationRangeScaleTest.java | 28 ++++ core/volmlib-left-out-of-bukkit-jar.txt | 7 - 22 files changed, 105 insertions(+), 755 deletions(-) delete mode 100644 core/src/main/java/art/arcane/iris/util/common/board/BoardSettings.java delete mode 100644 core/src/main/java/art/arcane/iris/util/common/board/ScoreDirection.java delete mode 100644 core/src/main/java/art/arcane/iris/util/common/inventorygui/UIStaticDecorator.java delete mode 100644 core/src/main/java/art/arcane/iris/util/common/inventorygui/Window.java delete mode 100644 core/src/main/java/art/arcane/iris/util/common/inventorygui/WindowResolution.java delete mode 100644 core/src/main/java/art/arcane/iris/util/common/math/VectorMath.java delete mode 100644 core/src/main/java/art/arcane/iris/util/project/hunk/HunkFace.java delete mode 100644 core/src/main/java/art/arcane/iris/util/project/interpolation/InterpolationType.java create mode 100644 core/src/test/java/art/arcane/iris/util/project/hunk/storage/VolmLibStorageHunkTest.java create mode 100644 core/src/test/java/art/arcane/iris/util/project/interpolation/IrisInterpolationRangeScaleTest.java diff --git a/core/build.gradle b/core/build.gradle index aa70d990a..8773af562 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -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 irisPackagesLeftOut = [ - 'art/arcane/iris/core/report/**', - 'art/arcane/iris/util/common/inventorygui/**', - 'art/arcane/iris/util/common/board/**' + 'art/arcane/iris/core/report/**' ] List irisClassesLeftOut = [ @@ -280,7 +278,6 @@ List 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', diff --git a/core/purity-allowlist.txt b/core/purity-allowlist.txt index 7288e718b..96dede65b 100644 --- a/core/purity-allowlist.txt +++ b/core/purity-allowlist.txt @@ -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 diff --git a/core/src/main/java/art/arcane/iris/util/common/board/BoardSettings.java b/core/src/main/java/art/arcane/iris/util/common/board/BoardSettings.java deleted file mode 100644 index 07d27d748..000000000 --- a/core/src/main/java/art/arcane/iris/util/common/board/BoardSettings.java +++ /dev/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); - } - } -} diff --git a/core/src/main/java/art/arcane/iris/util/common/board/ScoreDirection.java b/core/src/main/java/art/arcane/iris/util/common/board/ScoreDirection.java deleted file mode 100644 index 20119cde6..000000000 --- a/core/src/main/java/art/arcane/iris/util/common/board/ScoreDirection.java +++ /dev/null @@ -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; - } -} diff --git a/core/src/main/java/art/arcane/iris/util/common/inventorygui/UIStaticDecorator.java b/core/src/main/java/art/arcane/iris/util/common/inventorygui/UIStaticDecorator.java deleted file mode 100644 index 4bf5da6b0..000000000 --- a/core/src/main/java/art/arcane/iris/util/common/inventorygui/UIStaticDecorator.java +++ /dev/null @@ -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 . - */ - -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; - } -} diff --git a/core/src/main/java/art/arcane/iris/util/common/inventorygui/Window.java b/core/src/main/java/art/arcane/iris/util/common/inventorygui/Window.java deleted file mode 100644 index fa88b247d..000000000 --- a/core/src/main/java/art/arcane/iris/util/common/inventorygui/Window.java +++ /dev/null @@ -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 window); -} diff --git a/core/src/main/java/art/arcane/iris/util/common/inventorygui/WindowResolution.java b/core/src/main/java/art/arcane/iris/util/common/inventorygui/WindowResolution.java deleted file mode 100644 index 5ddf3595e..000000000 --- a/core/src/main/java/art/arcane/iris/util/common/inventorygui/WindowResolution.java +++ /dev/null @@ -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()); - } -} diff --git a/core/src/main/java/art/arcane/iris/util/common/math/VectorMath.java b/core/src/main/java/art/arcane/iris/util/common/math/VectorMath.java deleted file mode 100644 index df7425321..000000000 --- a/core/src/main/java/art/arcane/iris/util/common/math/VectorMath.java +++ /dev/null @@ -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; - } - -} diff --git a/core/src/main/java/art/arcane/iris/util/project/hunk/Hunk.java b/core/src/main/java/art/arcane/iris/util/project/hunk/Hunk.java index b3b0fe4a5..0257a5b24 100644 --- a/core/src/main/java/art/arcane/iris/util/project/hunk/Hunk.java +++ b/core/src/main/java/art/arcane/iris/util/project/hunk/Hunk.java @@ -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; diff --git a/core/src/main/java/art/arcane/iris/util/project/hunk/HunkFace.java b/core/src/main/java/art/arcane/iris/util/project/hunk/HunkFace.java deleted file mode 100644 index ec8e58a21..000000000 --- a/core/src/main/java/art/arcane/iris/util/project/hunk/HunkFace.java +++ /dev/null @@ -1,42 +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.util.project.hunk; - -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); - - private final art.arcane.volmlib.util.hunk.HunkFace shared; - - HunkFace(art.arcane.volmlib.util.hunk.HunkFace shared) { - this.shared = shared; - } - - public art.arcane.volmlib.util.hunk.HunkFace shared() { - return shared; - } - - public static HunkFace fromShared(art.arcane.volmlib.util.hunk.HunkFace shared) { - return HunkFace.valueOf(shared.name()); - } -} diff --git a/core/src/main/java/art/arcane/iris/util/project/hunk/storage/ArrayHunk.java b/core/src/main/java/art/arcane/iris/util/project/hunk/storage/ArrayHunk.java index 6816d3395..132f4ce12 100644 --- a/core/src/main/java/art/arcane/iris/util/project/hunk/storage/ArrayHunk.java +++ b/core/src/main/java/art/arcane/iris/util/project/hunk/storage/ArrayHunk.java @@ -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 extends StorageHunk implements Hunk { - private final T[] data; - - @SuppressWarnings("unchecked") +public class ArrayHunk extends art.arcane.volmlib.util.hunk.storage.ArrayHunk implements Hunk { 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); } } diff --git a/core/src/main/java/art/arcane/iris/util/project/hunk/storage/AtomicDoubleHunk.java b/core/src/main/java/art/arcane/iris/util/project/hunk/storage/AtomicDoubleHunk.java index 10b395a59..ebca42bcf 100644 --- a/core/src/main/java/art/arcane/iris/util/project/hunk/storage/AtomicDoubleHunk.java +++ b/core/src/main/java/art/arcane/iris/util/project/hunk/storage/AtomicDoubleHunk.java @@ -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 implements Hunk { - private final AtomicDoubleArray data; +public class AtomicDoubleHunk extends art.arcane.volmlib.util.hunk.storage.AtomicDoubleHunk implements Hunk { 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; } } diff --git a/core/src/main/java/art/arcane/iris/util/project/hunk/storage/AtomicHunk.java b/core/src/main/java/art/arcane/iris/util/project/hunk/storage/AtomicHunk.java index 2df03cf79..56c6850ec 100644 --- a/core/src/main/java/art/arcane/iris/util/project/hunk/storage/AtomicHunk.java +++ b/core/src/main/java/art/arcane/iris/util/project/hunk/storage/AtomicHunk.java @@ -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 extends StorageHunk implements Hunk { - private final AtomicReferenceArray 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 extends art.arcane.volmlib.util.hunk.storage.AtomicHunk implements Hunk { 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; } } diff --git a/core/src/main/java/art/arcane/iris/util/project/hunk/storage/AtomicIntegerHunk.java b/core/src/main/java/art/arcane/iris/util/project/hunk/storage/AtomicIntegerHunk.java index 24672403b..c2f1883ea 100644 --- a/core/src/main/java/art/arcane/iris/util/project/hunk/storage/AtomicIntegerHunk.java +++ b/core/src/main/java/art/arcane/iris/util/project/hunk/storage/AtomicIntegerHunk.java @@ -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 implements Hunk { - private final AtomicIntegerArray data; +public class AtomicIntegerHunk extends art.arcane.volmlib.util.hunk.storage.AtomicIntegerHunk implements Hunk { 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; } } diff --git a/core/src/main/java/art/arcane/iris/util/project/hunk/storage/AtomicLongHunk.java b/core/src/main/java/art/arcane/iris/util/project/hunk/storage/AtomicLongHunk.java index 89c76128f..913f36f32 100644 --- a/core/src/main/java/art/arcane/iris/util/project/hunk/storage/AtomicLongHunk.java +++ b/core/src/main/java/art/arcane/iris/util/project/hunk/storage/AtomicLongHunk.java @@ -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 implements Hunk { - private final AtomicLongArray data; +public class AtomicLongHunk extends art.arcane.volmlib.util.hunk.storage.AtomicLongHunk implements Hunk { 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; } } diff --git a/core/src/main/java/art/arcane/iris/util/project/hunk/storage/StorageHunk.java b/core/src/main/java/art/arcane/iris/util/project/hunk/storage/StorageHunk.java index feac57805..74fb6a616 100644 --- a/core/src/main/java/art/arcane/iris/util/project/hunk/storage/StorageHunk.java +++ b/core/src/main/java/art/arcane/iris/util/project/hunk/storage/StorageHunk.java @@ -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 implements Hunk { - private final int width; - private final int height; - private final int depth; +public abstract class StorageHunk extends art.arcane.volmlib.util.hunk.storage.StorageHunk implements Hunk { 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); } diff --git a/core/src/main/java/art/arcane/iris/util/project/hunk/storage/SynchronizedArrayHunk.java b/core/src/main/java/art/arcane/iris/util/project/hunk/storage/SynchronizedArrayHunk.java index 4395a1b5a..6f6f08893 100644 --- a/core/src/main/java/art/arcane/iris/util/project/hunk/storage/SynchronizedArrayHunk.java +++ b/core/src/main/java/art/arcane/iris/util/project/hunk/storage/SynchronizedArrayHunk.java @@ -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 extends StorageHunk implements Hunk { - private final T[] data; - - @SuppressWarnings("unchecked") +public class SynchronizedArrayHunk extends art.arcane.volmlib.util.hunk.storage.SynchronizedArrayHunk implements Hunk { 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); - } } } diff --git a/core/src/main/java/art/arcane/iris/util/project/interpolation/InterpolationType.java b/core/src/main/java/art/arcane/iris/util/project/interpolation/InterpolationType.java deleted file mode 100644 index 03a3b8279..000000000 --- a/core/src/main/java/art/arcane/iris/util/project/interpolation/InterpolationType.java +++ /dev/null @@ -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 . - */ - -package art.arcane.iris.util.project.interpolation; - -public enum InterpolationType { - LINEAR, - PARAMETRIC_2, - PARAMETRIC_4, - BEZIER, - NONE -} \ No newline at end of file diff --git a/core/src/main/java/art/arcane/iris/util/project/interpolation/IrisInterpolation.java b/core/src/main/java/art/arcane/iris/util/project/interpolation/IrisInterpolation.java index 39661623a..cfabe90db 100644 --- a/core/src/main/java/art/arcane/iris/util/project/interpolation/IrisInterpolation.java +++ b/core/src/main/java/art/arcane/iris/util/project/interpolation/IrisInterpolation.java @@ -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 NOISE_SAMPLE_CACHE_2D = ThreadLocal.withInitial(() -> new NoiseSampleCache2D(64)); private static final ThreadLocal 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( diff --git a/core/src/test/java/art/arcane/iris/util/project/hunk/storage/VolmLibStorageHunkTest.java b/core/src/test/java/art/arcane/iris/util/project/hunk/storage/VolmLibStorageHunkTest.java new file mode 100644 index 000000000..b56fb31a4 --- /dev/null +++ b/core/src/test/java/art/arcane/iris/util/project/hunk/storage/VolmLibStorageHunkTest.java @@ -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(WIDTH, HEIGHT, DEPTH)); + assertRoundTrip(new AtomicHunk(WIDTH, HEIGHT, DEPTH)); + assertRoundTrip(new SynchronizedArrayHunk(WIDTH, HEIGHT, DEPTH)); + assertRoundTrip(new AtomicIntegerHunk(WIDTH, HEIGHT, DEPTH)); + } + + @Test + public void atomicHunksReportAtomic() { + assertTrue(new AtomicHunk(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 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(0, HEIGHT, DEPTH)); + } + + private static void assertRoundTrip(Hunk 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)); + } + } + } + } +} diff --git a/core/src/test/java/art/arcane/iris/util/project/interpolation/IrisInterpolationRangeScaleTest.java b/core/src/test/java/art/arcane/iris/util/project/interpolation/IrisInterpolationRangeScaleTest.java new file mode 100644 index 000000000..d3e29e403 --- /dev/null +++ b/core/src/test/java/art/arcane/iris/util/project/interpolation/IrisInterpolationRangeScaleTest.java @@ -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); + } +} diff --git a/core/volmlib-left-out-of-bukkit-jar.txt b/core/volmlib-left-out-of-bukkit-jar.txt index e24267296..aa15b3e7f 100644 --- a/core/volmlib-left-out-of-bukkit-jar.txt +++ b/core/volmlib-left-out-of-bukkit-jar.txt @@ -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