mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 16:25:36 +00:00
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:355d7f413355161408114cc68a0
This commit is contained in:
1 parent
fd936f4dd8
commit
8748d85e37
22 files changed
+105
-755
No files matched your search
+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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
@@ -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(
|
||||
|
||||
+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
|
||||
|
||||
Reference in new issue
Block a user