mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 00:34:19 +00:00
Fix studio world leak (#1276)
- Move seeded generator caches into engine-owned PackRuntime - Replace per-thread ThreadLocal memos with engine-owned ThreadSlots - Release engine-keyed structure entries when an engine closes - Keep pack objects as read-only configuration
This commit is contained in:
1 parent
1e04f61957
commit
d720e9afab
239 files changed
+4755
-3170
No files matched your search
+21
-18
@@ -18,6 +18,7 @@
|
||||
|
||||
package art.arcane.iris.generation.biome;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.world.IrisWorld;
|
||||
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
@@ -553,42 +554,43 @@ public class FloatingIslandBoundarySamplerTest {
|
||||
IrisBiome parent = mock(IrisBiome.class);
|
||||
IrisData data = mock(IrisData.class);
|
||||
Engine engine = mock(Engine.class);
|
||||
PackRuntime runtime = PackRuntime.forEngine(engine, data);
|
||||
IrisWorld world = IrisWorld.builder().minHeight(0).maxHeight(320).build();
|
||||
KList<IrisFloatingChildBiomes> entries = new KList<>();
|
||||
entries.add(entry);
|
||||
when(parent.getFloatingChildBiomes()).thenReturn(entries);
|
||||
when(parent.isMergeFloatingChildBiomes()).thenReturn(false);
|
||||
when(entry.getFootprintCng(anyLong(), same(data))).thenReturn(footprint);
|
||||
when(entry.getFootprintCng(anyLong(), same(runtime))).thenReturn(footprint);
|
||||
when(entry.getFootprintThreshold()).thenReturn(0.5D);
|
||||
when(entry.getAltitudeCng(anyLong(), same(data))).thenReturn(constant);
|
||||
when(entry.getAltitudeCng(anyLong(), same(runtime))).thenReturn(constant);
|
||||
when(entry.getMinHeightAboveSurface()).thenReturn(160);
|
||||
when(entry.getMaxHeightAboveSurface()).thenReturn(160);
|
||||
when(entry.getRealBiome(parent, data)).thenReturn(parent);
|
||||
when(entry.getTopShapeMode()).thenReturn(TopShapeMode.NOISE);
|
||||
when(entry.getTopShapeCng(anyLong(), same(data))).thenReturn(constant);
|
||||
when(entry.getTopShapeCng(anyLong(), same(runtime))).thenReturn(constant);
|
||||
when(entry.getTopShapeAmp()).thenReturn(1.0D);
|
||||
when(entry.getMaxTopHeight()).thenReturn(18);
|
||||
when(entry.getBottomCng(anyLong(), same(data))).thenReturn(constant);
|
||||
when(entry.getBottomCng(anyLong(), same(runtime))).thenReturn(constant);
|
||||
when(entry.getBottomExponent()).thenReturn(1.0D);
|
||||
when(entry.getBottomDepthMin()).thenReturn(20);
|
||||
when(entry.getBottomDepthMax()).thenReturn(20);
|
||||
when(entry.getMaxThickness()).thenReturn(64);
|
||||
when(entry.getMinAbsoluteY()).thenReturn(null);
|
||||
when(entry.getMaxAbsoluteY()).thenReturn(null);
|
||||
when(entry.getWallWarpCng(anyLong(), same(data))).thenReturn(null);
|
||||
when(entry.getWallWarpCng(anyLong(), same(runtime))).thenReturn(null);
|
||||
when(entry.getWallWarpAmplitude()).thenReturn(0.0D);
|
||||
when(entry.getCarvingProfileSampler(engine, data)).thenReturn(null);
|
||||
when(entry.getCarvingProfileSampler(runtime)).thenReturn(null);
|
||||
when(entry.hasCarvingReference()).thenReturn(false);
|
||||
when(entry.getCarveCng(anyLong(), same(data))).thenReturn(constant);
|
||||
when(entry.getCarveCng(anyLong(), same(runtime))).thenReturn(constant);
|
||||
when(entry.getCarveThreshold()).thenReturn(0.5D);
|
||||
when(engine.getWorld()).thenReturn(world);
|
||||
FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> parent);
|
||||
int[] expectedBottom = {159, 158, 156, 153, 150, 147, 144, 142, 141, 140};
|
||||
int[] expectedTop = {161, 162, 164, 166, 169, 172, 174, 176, 177, 178};
|
||||
|
||||
assertNull(FloatingIslandSample.sample(parent, 0, 0, 320, 31L, data, engine, sampler));
|
||||
assertNull(FloatingIslandSample.sample(parent, 0, 0, 320, 31L, runtime, sampler));
|
||||
for (int i = 0; i < expectedBottom.length; i++) {
|
||||
FloatingIslandSample sample = FloatingIslandSample.sample(parent, i + 1, 0, 320, 31L, data, engine, sampler);
|
||||
FloatingIslandSample sample = FloatingIslandSample.sample(parent, i + 1, 0, 320, 31L, runtime, sampler);
|
||||
assertNotNull("distance " + (i + 2) + " rejected with code " + FloatingIslandSample.getLastReject(), sample);
|
||||
assertEquals(expectedBottom[i], sample.bottomY());
|
||||
assertEquals(expectedTop[i], sample.topY());
|
||||
@@ -633,6 +635,7 @@ public class FloatingIslandBoundarySamplerTest {
|
||||
IrisBiome parent = mock(IrisBiome.class);
|
||||
IrisData data = mock(IrisData.class);
|
||||
Engine engine = mock(Engine.class);
|
||||
PackRuntime runtime = PackRuntime.forEngine(engine, data);
|
||||
IrisWorld world = IrisWorld.builder().minHeight(0).maxHeight(320).build();
|
||||
KList<IrisFloatingChildBiomes> entries = new KList<>();
|
||||
entries.add(lower);
|
||||
@@ -640,26 +643,26 @@ public class FloatingIslandBoundarySamplerTest {
|
||||
when(parent.getFloatingChildBiomes()).thenReturn(entries);
|
||||
when(parent.isMergeFloatingChildBiomes()).thenReturn(true);
|
||||
for (IrisFloatingChildBiomes entry : entries) {
|
||||
when(entry.getFootprintCng(anyLong(), same(data))).thenReturn(footprint);
|
||||
when(entry.getFootprintCng(anyLong(), same(runtime))).thenReturn(footprint);
|
||||
when(entry.getFootprintThreshold()).thenReturn(0.5D);
|
||||
when(entry.getAltitudeCng(anyLong(), same(data))).thenReturn(constant);
|
||||
when(entry.getAltitudeCng(anyLong(), same(runtime))).thenReturn(constant);
|
||||
when(entry.getRealBiome(parent, data)).thenReturn(parent);
|
||||
when(entry.getTopShapeMode()).thenReturn(TopShapeMode.NOISE);
|
||||
when(entry.getTopShapeCng(anyLong(), same(data))).thenReturn(constant);
|
||||
when(entry.getTopShapeCng(anyLong(), same(runtime))).thenReturn(constant);
|
||||
when(entry.getTopShapeAmp()).thenReturn(1.0D);
|
||||
when(entry.getMaxTopHeight()).thenReturn(18);
|
||||
when(entry.getBottomCng(anyLong(), same(data))).thenReturn(constant);
|
||||
when(entry.getBottomCng(anyLong(), same(runtime))).thenReturn(constant);
|
||||
when(entry.getBottomExponent()).thenReturn(1.0D);
|
||||
when(entry.getBottomDepthMin()).thenReturn(20);
|
||||
when(entry.getBottomDepthMax()).thenReturn(20);
|
||||
when(entry.getMaxThickness()).thenReturn(64);
|
||||
when(entry.getMinAbsoluteY()).thenReturn(null);
|
||||
when(entry.getMaxAbsoluteY()).thenReturn(null);
|
||||
when(entry.getWallWarpCng(anyLong(), same(data))).thenReturn(null);
|
||||
when(entry.getWallWarpCng(anyLong(), same(runtime))).thenReturn(null);
|
||||
when(entry.getWallWarpAmplitude()).thenReturn(0.0D);
|
||||
when(entry.getCarvingProfileSampler(engine, data)).thenReturn(null);
|
||||
when(entry.getCarvingProfileSampler(runtime)).thenReturn(null);
|
||||
when(entry.hasCarvingReference()).thenReturn(false);
|
||||
when(entry.getCarveCng(anyLong(), same(data))).thenReturn(null);
|
||||
when(entry.getCarveCng(anyLong(), same(runtime))).thenReturn(null);
|
||||
when(entry.getCarveThreshold()).thenReturn(1.0D);
|
||||
}
|
||||
when(lower.getMinHeightAboveSurface()).thenReturn(160);
|
||||
@@ -669,8 +672,8 @@ public class FloatingIslandBoundarySamplerTest {
|
||||
when(engine.getWorld()).thenReturn(world);
|
||||
FloatingIslandBoundarySampler sampler = new FloatingIslandBoundarySampler((x, z) -> parent);
|
||||
|
||||
assertNull(FloatingIslandSample.sample(parent, 0, 0, 320, 35L, data, engine, sampler));
|
||||
FloatingIslandSample sample = FloatingIslandSample.sample(parent, 1, 0, 320, 35L, data, engine, sampler);
|
||||
assertNull(FloatingIslandSample.sample(parent, 0, 0, 320, 35L, runtime, sampler));
|
||||
FloatingIslandSample sample = FloatingIslandSample.sample(parent, 1, 0, 320, 35L, runtime, sampler);
|
||||
|
||||
assertNotNull(sample);
|
||||
assertTrue(sample.hasMergedEntries());
|
||||
|
||||
+12
-8
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.generation.biome;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.generation.block.B;
|
||||
import art.arcane.iris.generation.context.ChunkContext;
|
||||
import art.arcane.iris.generation.hydrology.raster.WaterRole;
|
||||
@@ -20,6 +21,7 @@ import java.util.Arrays;
|
||||
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.argThat;
|
||||
import static org.mockito.ArgumentMatchers.anyDouble;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyLong;
|
||||
@@ -41,6 +43,8 @@ public class FloatingIslandLockedLayersTest {
|
||||
.setFloatingChildBiomes(new KList<>(entry));
|
||||
Engine engine = mock(Engine.class, RETURNS_DEEP_STUBS);
|
||||
when(engine.getDimension()).thenReturn(new IrisDimension());
|
||||
PackRuntime engineRuntime = PackRuntime.forEngine(engine, engine.getData());
|
||||
when(engine.getPackRuntime()).thenReturn(engineRuntime);
|
||||
when(engine.getSubterrainCell(anyInt(), anyInt(), anyInt())).thenReturn(null);
|
||||
when(engine.getComplex().allowsNewDiscreteContentAt(anyInt(), anyInt())).thenReturn(false);
|
||||
when(engine.getComplex().getWaterRoleStream()).thenReturn(ProceduralStream.of((x, z) -> WaterRole.NONE,
|
||||
@@ -71,19 +75,19 @@ public class FloatingIslandLockedLayersTest {
|
||||
MockedStatic<B> blocks = mockStatic(B.class)) {
|
||||
blocks.when(() -> B.getState("minecraft:stone")).thenReturn(first);
|
||||
samples.when(() -> FloatingIslandSample.sampleMemoized(eq(parent), eq(-16), eq(-16),
|
||||
anyInt(), anyLong(), any(), eq(engine), eq(boundary))).thenReturn(thin);
|
||||
anyInt(), anyLong(), argThat((PackRuntime runtime) -> runtime.engine() == engine), eq(boundary))).thenReturn(thin);
|
||||
samples.when(() -> FloatingIslandSample.sampleMemoized(eq(parent), eq(-15), eq(-16),
|
||||
anyInt(), anyLong(), any(), eq(engine), eq(boundary))).thenReturn(thick);
|
||||
anyInt(), anyLong(), argThat((PackRuntime runtime) -> runtime.engine() == engine), eq(boundary))).thenReturn(thick);
|
||||
samples.when(() -> FloatingIslandSample.sampleMemoized(eq(parent), eq(-14), eq(-16),
|
||||
anyInt(), anyLong(), any(), eq(engine), eq(boundary))).thenReturn(raised);
|
||||
anyInt(), anyLong(), argThat((PackRuntime runtime) -> runtime.engine() == engine), eq(boundary))).thenReturn(raised);
|
||||
samples.when(() -> FloatingIslandSample.sampleMemoized(eq(parent), eq(-13), eq(-16),
|
||||
anyInt(), anyLong(), any(), eq(engine), eq(boundary))).thenReturn(gapped);
|
||||
anyInt(), anyLong(), argThat((PackRuntime runtime) -> runtime.engine() == engine), eq(boundary))).thenReturn(gapped);
|
||||
samples.when(() -> FloatingIslandSample.sampleMemoized(eq(parent), eq(-12), eq(-16),
|
||||
anyInt(), anyLong(), any(), eq(engine), eq(boundary))).thenReturn(mirrored);
|
||||
anyInt(), anyLong(), argThat((PackRuntime runtime) -> runtime.engine() == engine), eq(boundary))).thenReturn(mirrored);
|
||||
samples.when(() -> FloatingIslandSample.sampleMemoized(eq(parent), eq(-11), eq(-16),
|
||||
anyInt(), anyLong(), any(), eq(engine), eq(boundary))).thenReturn(custom);
|
||||
anyInt(), anyLong(), argThat((PackRuntime runtime) -> runtime.engine() == engine), eq(boundary))).thenReturn(custom);
|
||||
samples.when(() -> FloatingIslandSample.sampleMemoized(eq(ordinaryParent), eq(-10), eq(-16),
|
||||
anyInt(), anyLong(), any(), eq(engine), eq(boundary))).thenReturn(ordinary);
|
||||
anyInt(), anyLong(), argThat((PackRuntime runtime) -> runtime.engine() == engine), eq(boundary))).thenReturn(ordinary);
|
||||
new IrisFloatingChildBiomeModifier(engine).onModify(-16, -16, output, false, context);
|
||||
}
|
||||
assertSame(first, output.get(0, 20, 0));
|
||||
@@ -121,7 +125,7 @@ public class FloatingIslandLockedLayersTest {
|
||||
when(layer.getSlopeCondition()).thenReturn(new IrisSlopeClip());
|
||||
when(layer.getHeightGenerator(any(), any())).thenReturn(height);
|
||||
when(height.fit(anyInt(), anyInt(), anyDouble(), anyDouble())).thenReturn(1);
|
||||
when(layer.get(any(), anyInt(), anyDouble(), anyDouble(), anyDouble(), any())).thenReturn(block);
|
||||
when(layer.get(any(), anyInt(), anyDouble(), anyDouble(), anyDouble(), any(PaletteLayerRuntime.class))).thenReturn(block);
|
||||
when(layer.get(any(), anyDouble(), anyDouble(), anyDouble(), any())).thenReturn(block);
|
||||
return layer;
|
||||
}
|
||||
|
||||
+24
-19
@@ -1,9 +1,9 @@
|
||||
package art.arcane.iris.generation.biome;
|
||||
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertNull;
|
||||
@@ -13,35 +13,40 @@ import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class FloatingIslandMemoContextTest {
|
||||
@After
|
||||
public void clearMemo() {
|
||||
FloatingIslandSample.clearThreadCaches();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rejectedColumnsAreCachedOnlyForTheirParentAndContext() {
|
||||
FloatingIslandSample.clearThreadCaches();
|
||||
public void rejectedColumnsAreCachedOnlyForTheirParentContextAndRuntime() {
|
||||
IrisBiome first = parent();
|
||||
IrisBiome second = parent();
|
||||
IrisData data = mock(IrisData.class);
|
||||
Engine engine = mock(Engine.class);
|
||||
PackRuntime runtime = PackRuntime.forEngine(mock(Engine.class), data);
|
||||
FloatingIslandBoundarySampler boundary = new FloatingIslandBoundarySampler((x, z) -> first);
|
||||
sample(first, 320, 7L, data, engine, boundary);
|
||||
sample(first, 320, 7L, data, engine, boundary);
|
||||
sample(second, 320, 7L, data, engine, boundary);
|
||||
sample(first, 320, 7L, runtime, boundary);
|
||||
sample(first, 320, 7L, runtime, boundary);
|
||||
sample(second, 320, 7L, runtime, boundary);
|
||||
verify(first, times(1)).getFloatingChildBiomes();
|
||||
verify(second, times(1)).getFloatingChildBiomes();
|
||||
sample(first, 320, 9L, data, engine, boundary);
|
||||
sample(first, 128, 9L, data, engine, boundary);
|
||||
sample(first, 128, 9L, data, mock(Engine.class), boundary);
|
||||
sample(first, 128, 9L, mock(IrisData.class), engine, boundary);
|
||||
sample(first, 128, 9L, data, engine, new FloatingIslandBoundarySampler((x, z) -> first));
|
||||
sample(first, 320, 9L, runtime, boundary);
|
||||
sample(first, 128, 9L, runtime, boundary);
|
||||
sample(first, 128, 9L, PackRuntime.forEngine(mock(Engine.class), data), boundary);
|
||||
sample(first, 128, 9L, runtime.scopeFor(mock(IrisData.class)), boundary);
|
||||
sample(first, 128, 9L, runtime, new FloatingIslandBoundarySampler((x, z) -> first));
|
||||
verify(first, times(6)).getFloatingChildBiomes();
|
||||
}
|
||||
|
||||
private static void sample(IrisBiome parent, int height, long seed, IrisData data, Engine engine,
|
||||
@Test
|
||||
public void clearingTheChunkMemoSamplesAgain() {
|
||||
IrisBiome parent = parent();
|
||||
PackRuntime runtime = PackRuntime.forEngine(mock(Engine.class), mock(IrisData.class));
|
||||
FloatingIslandBoundarySampler boundary = new FloatingIslandBoundarySampler((x, z) -> parent);
|
||||
sample(parent, 320, 7L, runtime, boundary);
|
||||
FloatingIslandSample.clearChunkMemo(runtime);
|
||||
sample(parent, 320, 7L, runtime, boundary);
|
||||
verify(parent, times(2)).getFloatingChildBiomes();
|
||||
}
|
||||
|
||||
private static void sample(IrisBiome parent, int height, long seed, PackRuntime runtime,
|
||||
FloatingIslandBoundarySampler boundary) {
|
||||
assertNull(FloatingIslandSample.sampleMemoized(parent, -16, 32, height, seed, data, engine, boundary));
|
||||
assertNull(FloatingIslandSample.sampleMemoized(parent, -16, 32, height, seed, runtime, boundary));
|
||||
}
|
||||
|
||||
private static IrisBiome parent() {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.generation.biome;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.generation.terrain.IrisDimension;
|
||||
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
@@ -15,6 +16,8 @@ import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
public class IrisBiomeCeilingLayerTest {
|
||||
private static final PackRuntime RUNTIME = PackRuntime.standalone(null);
|
||||
|
||||
@Test
|
||||
public void emitsEveryCeilingLayerWithoutSurfaceLayers() {
|
||||
NativeBlockState first = mock(NativeBlockState.class);
|
||||
@@ -24,7 +27,7 @@ public class IrisBiomeCeilingLayerTest {
|
||||
new KList<>(layer(first, 2), layer(second, 1), layer(third, 2)));
|
||||
|
||||
KList<NativeBlockState> result = biome.generateCeilingLayers(
|
||||
new IrisDimension(), 13, -27, new RNG(1), 8, 64, null, null);
|
||||
new IrisDimension(), 13, -27, new RNG(1), 8, 64, RUNTIME, null);
|
||||
|
||||
assertEquals(List.of(first, first, second, third, third), result);
|
||||
}
|
||||
@@ -34,17 +37,17 @@ public class IrisBiomeCeilingLayerTest {
|
||||
IrisBiome first = variableBiome(1, 1);
|
||||
IrisBiome second = variableBiome(7, 31);
|
||||
RNG rng = new RNG(37);
|
||||
second.getLayerHeightGenerators(rng, null);
|
||||
second.getLayerHeightGenerators(rng, RUNTIME);
|
||||
for (int x = -200; x <= 200; x += 7) {
|
||||
KList<NativeBlockState> firstCeiling = first.generateCeilingLayers(
|
||||
new IrisDimension(), x, -x, rng, 100, 120, null, null);
|
||||
new IrisDimension(), x, -x, rng, 100, 120, RUNTIME, null);
|
||||
KList<NativeBlockState> secondCeiling = second.generateCeilingLayers(
|
||||
new IrisDimension(), x, -x, rng, 100, 120, null, null);
|
||||
new IrisDimension(), x, -x, rng, 100, 120, RUNTIME, null);
|
||||
assertEquals(firstCeiling.size(), secondCeiling.size());
|
||||
}
|
||||
first.getLayerHeightGenerators(rng, null);
|
||||
assertNotSame(first.getLayerHeightGenerators(rng, null).get(0),
|
||||
first.getLayerCeilingHeightGenerators().get(first.getCaveCeilingLayers(), 7235, rng, null).get(0));
|
||||
first.getLayerHeightGenerators(rng, RUNTIME);
|
||||
assertNotSame(first.getLayerHeightGenerators(rng, RUNTIME).get(0),
|
||||
first.getCaveCeilingLayerHeightGenerators(rng, RUNTIME).get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -53,9 +56,9 @@ public class IrisBiomeCeilingLayerTest {
|
||||
NativeBlockState second = mock(NativeBlockState.class);
|
||||
IrisBiome biome = new IrisBiome().setCaveCeilingLayers(new KList<>(layer(first, 2), layer(second, 3)));
|
||||
assertEquals(List.of(first, first, second), biome.generateCeilingLayers(
|
||||
new IrisDimension(), 0, 0, new RNG(1), 3, 64, null, null));
|
||||
new IrisDimension(), 0, 0, new RNG(1), 3, 64, RUNTIME, null));
|
||||
assertTrue(biome.generateCeilingLayers(
|
||||
new IrisDimension(), 0, 0, new RNG(1), 0, 64, null, null).isEmpty());
|
||||
new IrisDimension(), 0, 0, new RNG(1), 0, 64, RUNTIME, null).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+3
-2
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.generation.biome;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.generation.noise.NoiseStyle;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
@@ -30,7 +31,7 @@ public class IrisBiomeChildrenGeneratorTest {
|
||||
}
|
||||
|
||||
private void buildChildrenGenerator() {
|
||||
biome.getChildrenGenerator(new RNG(WORLD_SEED), CHILDREN_SIGNATURE, CHILD_SHRINK_FACTOR);
|
||||
biome.getChildrenGenerator(PackRuntime.standalone(biome.getLoader()), new RNG(WORLD_SEED), CHILDREN_SIGNATURE, CHILD_SHRINK_FACTOR);
|
||||
}
|
||||
|
||||
private double[] sampleUntouchedSharedChildStyleGenerator() {
|
||||
@@ -38,7 +39,7 @@ public class IrisBiomeChildrenGeneratorTest {
|
||||
}
|
||||
|
||||
private double[] sampleSharedChildStyleGenerator(IrisGeneratorStyle childStyle) {
|
||||
return sampleSharedGenerator(childStyle, deriveSharedChildStyleSeed(), packData);
|
||||
return sampleSharedGenerator(childStyle, deriveSharedChildStyleSeed(), PackRuntime.of(packData.getEngine(), packData));
|
||||
}
|
||||
|
||||
private static RNG deriveSharedChildStyleSeed() {
|
||||
|
||||
+13
-12
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.generation.biome;
|
||||
|
||||
import art.arcane.iris.testsupport.MockPackData;
|
||||
import art.arcane.iris.generation.noise.NoiseStyle;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
@@ -20,23 +21,23 @@ import static org.mockito.Mockito.mock;
|
||||
public class IrisBiomeFieldSeedCohesionTest {
|
||||
@Test
|
||||
public void childrenGeneratorsSeparateSeedsSignaturesAndScales() {
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisData data = MockPackData.create();
|
||||
IrisBiome shared = biome(data);
|
||||
for (long seed : new long[]{29L, 11L, 29L}) {
|
||||
for (int signature : new int[]{2137, 91}) {
|
||||
for (double scale : new double[]{4D, 0.25D}) {
|
||||
assertArrayEquals(samples(biome(data).getChildrenGenerator(new RNG(seed), signature, scale)),
|
||||
samples(shared.getChildrenGenerator(new RNG(seed), signature, scale)), 0D);
|
||||
assertArrayEquals(samples(biome(data).getChildrenGenerator(data.standalonePackRuntime(), new RNG(seed), signature, scale)),
|
||||
samples(shared.getChildrenGenerator(data.standalonePackRuntime(), new RNG(seed), signature, scale)), 0D);
|
||||
}
|
||||
}
|
||||
}
|
||||
CNG first = shared.getChildrenGenerator(new RNG(29L), 2137, 4D);
|
||||
assertSame(first, shared.getChildrenGenerator(new RNG(29L), 2137, 4D));
|
||||
CNG first = shared.getChildrenGenerator(data.standalonePackRuntime(), new RNG(29L), 2137, 4D);
|
||||
assertSame(first, shared.getChildrenGenerator(data.standalonePackRuntime(), new RNG(29L), 2137, 4D));
|
||||
}
|
||||
|
||||
@Test(timeout = 15000)
|
||||
public void concurrentFloatingFieldsAndEvictionRetainSeedAssignments() throws Exception {
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisData data = MockPackData.create();
|
||||
IrisFloatingChildBiomes shared = new IrisFloatingChildBiomes();
|
||||
ExecutorService workers = Executors.newFixedThreadPool(4);
|
||||
try {
|
||||
@@ -65,12 +66,12 @@ public class IrisBiomeFieldSeedCohesionTest {
|
||||
double x = -71.25D;
|
||||
double z = 145.75D;
|
||||
return new double[]{
|
||||
entry.getFootprintCng(seed, data).noise(x, z),
|
||||
entry.getPickerCng(seed, data).noise(x, z),
|
||||
entry.getAltitudeCng(seed, data).noise(x, z),
|
||||
entry.getTopShapeCng(seed, data).noise(x, z),
|
||||
entry.getBottomCng(seed, data).noise(x, z),
|
||||
entry.getEdgeTaperProfile(seed, data).fade(4, -71, 145)
|
||||
entry.getFootprintCng(seed, data.standalonePackRuntime()).noise(x, z),
|
||||
entry.getPickerCng(seed, data.standalonePackRuntime()).noise(x, z),
|
||||
entry.getAltitudeCng(seed, data.standalonePackRuntime()).noise(x, z),
|
||||
entry.getTopShapeCng(seed, data.standalonePackRuntime()).noise(x, z),
|
||||
entry.getBottomCng(seed, data.standalonePackRuntime()).noise(x, z),
|
||||
entry.getEdgeTaperProfile(seed, data.standalonePackRuntime()).fade(4, -71, 145)
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+30
-35
@@ -1,6 +1,7 @@
|
||||
package art.arcane.iris.generation.biome;
|
||||
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.testsupport.MockPackData;
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.runtime.SeedManager;
|
||||
import art.arcane.volmlib.util.noise.CNG;
|
||||
@@ -11,7 +12,6 @@ import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
@@ -26,48 +26,47 @@ public class IrisBiomeGeneratorSeedIsolationTest {
|
||||
|
||||
@Test
|
||||
public void engineSeedMakesPaperStyleFirstCallOrderIrrelevant() {
|
||||
IrisData data = dataWithActiveEngine(new AtomicReference<>(engine(1337L)));
|
||||
IrisBiome paperFirst = biome(data);
|
||||
IrisBiome moddedFirst = biome(data);
|
||||
Engine engine = engine(1337L);
|
||||
IrisBiome paperFirst = biome();
|
||||
IrisBiome moddedFirst = biome();
|
||||
|
||||
CNG paperGenerator = paperFirst.getBiomeGenerator(new RNG(8457289L));
|
||||
CNG moddedGenerator = moddedFirst.getBiomeGenerator(new RNG(-991245L));
|
||||
CNG paperGenerator = paperFirst.getBiomeGenerator(new RNG(8457289L), engine);
|
||||
CNG moddedGenerator = moddedFirst.getBiomeGenerator(new RNG(-991245L), engine);
|
||||
|
||||
assertEquals(paperGenerator.noise(SAMPLE_X, SAMPLE_Z), moddedGenerator.noise(SAMPLE_X, SAMPLE_Z), 0D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void distinctEnginesKeepDistinctBiomeGenerators() {
|
||||
Engine firstEngine = engine(1337L);
|
||||
Engine secondEngine = engine(7331L);
|
||||
IrisBiome biome = biome(dataWithActiveEngine(new AtomicReference<>(secondEngine)));
|
||||
IrisBiome biome = biome();
|
||||
|
||||
CNG first = biome.getBiomeGenerator(new RNG(1L), firstEngine);
|
||||
CNG second = biome.getBiomeGenerator(new RNG(1L), secondEngine);
|
||||
CNG first = biome.getBiomeGenerator(new RNG(1L), engine(1337L));
|
||||
CNG second = biome.getBiomeGenerator(new RNG(1L), engine(7331L));
|
||||
|
||||
assertNotSame(first, second);
|
||||
assertNotEquals(first.noise(SAMPLE_X, SAMPLE_Z), second.noise(SAMPLE_X, SAMPLE_Z), 0D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sameSeedEnginesSharingBiomeReuseBiomeGenerator() {
|
||||
public void sameSeedEnginesBuildEqualButOwnBiomeGenerators() {
|
||||
IrisBiome biome = biome();
|
||||
Engine firstEngine = engine(1337L);
|
||||
Engine secondEngine = engine(1337L);
|
||||
IrisBiome biome = biome(dataWithActiveEngine(new AtomicReference<>(secondEngine)));
|
||||
|
||||
CNG first = biome.getBiomeGenerator(new RNG(11L), firstEngine);
|
||||
CNG second = biome.getBiomeGenerator(new RNG(99L), secondEngine);
|
||||
CNG second = biome.getBiomeGenerator(new RNG(99L), engine(1337L));
|
||||
|
||||
assertSame(first, second);
|
||||
assertSame(first, biome.getBiomeGenerator(new RNG(99L), firstEngine));
|
||||
assertNotSame(first, second);
|
||||
assertEquals(first.noise(SAMPLE_X, SAMPLE_Z), second.noise(SAMPLE_X, SAMPLE_Z), 0D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void engineLessToolingUsesSuppliedRngSeed() {
|
||||
IrisBiome biome = biome(null);
|
||||
IrisBiome biome = biome();
|
||||
|
||||
CNG first = biome.getBiomeGenerator(new RNG(11L));
|
||||
CNG sameSeed = biome.getBiomeGenerator(new RNG(11L));
|
||||
CNG second = biome.getBiomeGenerator(new RNG(99L));
|
||||
CNG first = biome.getBiomeGenerator(new RNG(11L), null);
|
||||
CNG sameSeed = biome.getBiomeGenerator(new RNG(11L), null);
|
||||
CNG second = biome.getBiomeGenerator(new RNG(99L), null);
|
||||
|
||||
assertSame(first, sameSeed);
|
||||
assertNotSame(first, second);
|
||||
@@ -75,10 +74,10 @@ public class IrisBiomeGeneratorSeedIsolationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void concurrentExactEnginesIgnoreLoaderEngine() throws Exception {
|
||||
public void concurrentEnginesKeepTheirOwnGenerators() throws Exception {
|
||||
Engine firstEngine = engine(1337L);
|
||||
Engine secondEngine = engine(7331L);
|
||||
IrisBiome biome = biome(dataWithActiveEngine(new AtomicReference<>(secondEngine)));
|
||||
IrisBiome biome = biome();
|
||||
CountDownLatch start = new CountDownLatch(1);
|
||||
ExecutorService executor = Executors.newFixedThreadPool(2);
|
||||
try {
|
||||
@@ -98,33 +97,29 @@ public class IrisBiomeGeneratorSeedIsolationTest {
|
||||
|
||||
@Test
|
||||
public void biomeGeneratorCacheEvictsOldSeeds() {
|
||||
IrisBiome biome = biome(null);
|
||||
CNG first = biome.getBiomeGenerator(new RNG(0L));
|
||||
IrisBiome biome = biome();
|
||||
CNG first = biome.getBiomeGenerator(new RNG(0L), null);
|
||||
|
||||
for (long seed = 1L; seed <= 8L; seed++) {
|
||||
biome.getBiomeGenerator(new RNG(seed));
|
||||
biome.getBiomeGenerator(new RNG(seed), null);
|
||||
}
|
||||
|
||||
assertNotSame(first, biome.getBiomeGenerator(new RNG(0L)));
|
||||
assertNotSame(first, biome.getBiomeGenerator(new RNG(0L), null));
|
||||
}
|
||||
|
||||
private IrisBiome biome(IrisData data) {
|
||||
private IrisBiome biome() {
|
||||
IrisBiome biome = new IrisBiome().setName("Scatter Test");
|
||||
biome.setLoader(data);
|
||||
biome.setLoader(MockPackData.create());
|
||||
return biome;
|
||||
}
|
||||
|
||||
private IrisData dataWithActiveEngine(AtomicReference<Engine> activeEngine) {
|
||||
IrisData data = mock(IrisData.class);
|
||||
when(data.getEngine()).thenAnswer(ignored -> activeEngine.get());
|
||||
return data;
|
||||
}
|
||||
|
||||
private Engine engine(long biomeSeed) {
|
||||
SeedManager seedManager = mock(SeedManager.class);
|
||||
when(seedManager.getBiome()).thenReturn(biomeSeed);
|
||||
Engine engine = mock(Engine.class);
|
||||
when(engine.getSeedManager()).thenReturn(seedManager);
|
||||
PackRuntime runtime = PackRuntime.forEngine(engine, null);
|
||||
when(engine.getPackRuntime()).thenReturn(runtime);
|
||||
return engine;
|
||||
}
|
||||
|
||||
|
||||
+43
-45
@@ -1,5 +1,7 @@
|
||||
package art.arcane.iris.generation.biome;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.testsupport.MockPackData;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.terrain.IrisDimension;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
@@ -26,6 +28,8 @@ import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class IrisBiomeLayerHeightCacheTest {
|
||||
private static final PackRuntime RUNTIME = PackRuntime.standalone(null);
|
||||
|
||||
private static final long TERRAIN_SEED = 7191L;
|
||||
private static final long CARVE_SEED = -872315L;
|
||||
private static final long FLOATING_SEED = (TERRAIN_SEED ^ 0x7EB0A73F1DCE514DL)
|
||||
@@ -34,15 +38,15 @@ public class IrisBiomeLayerHeightCacheTest {
|
||||
@Test
|
||||
public void layerHeightUsesEachCallerSeedInEitherOrder() {
|
||||
IrisBiomePaletteLayer layer = layer();
|
||||
assertNoise(layer().getHeightGenerator(new RNG(CARVE_SEED), null),
|
||||
layer.getHeightGenerator(new RNG(CARVE_SEED), null));
|
||||
assertNoise(layer().getHeightGenerator(new RNG(FLOATING_SEED), null),
|
||||
layer.getHeightGenerator(new RNG(FLOATING_SEED), null));
|
||||
assertNoise(layer().getHeightGenerator(new RNG(CARVE_SEED), RUNTIME),
|
||||
layer.getHeightGenerator(new RNG(CARVE_SEED), RUNTIME));
|
||||
assertNoise(layer().getHeightGenerator(new RNG(FLOATING_SEED), RUNTIME),
|
||||
layer.getHeightGenerator(new RNG(FLOATING_SEED), RUNTIME));
|
||||
IrisBiomePaletteLayer reversed = layer();
|
||||
assertNoise(layer.getHeightGenerator(new RNG(FLOATING_SEED), null),
|
||||
reversed.getHeightGenerator(new RNG(FLOATING_SEED), null));
|
||||
assertNoise(layer.getHeightGenerator(new RNG(CARVE_SEED), null),
|
||||
reversed.getHeightGenerator(new RNG(CARVE_SEED), null));
|
||||
assertNoise(layer.getHeightGenerator(new RNG(FLOATING_SEED), RUNTIME),
|
||||
reversed.getHeightGenerator(new RNG(FLOATING_SEED), RUNTIME));
|
||||
assertNoise(layer.getHeightGenerator(new RNG(CARVE_SEED), RUNTIME),
|
||||
reversed.getHeightGenerator(new RNG(CARVE_SEED), RUNTIME));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -50,16 +54,16 @@ public class IrisBiomeLayerHeightCacheTest {
|
||||
IrisBiome biome = biome();
|
||||
long[] seeds = {FLOATING_SEED, CARVE_SEED, TERRAIN_SEED, FLOATING_SEED + 733L};
|
||||
for (long seed : seeds) {
|
||||
assertGenerators(biome().getLayerHeightGenerators(new RNG(seed), null),
|
||||
biome.getLayerHeightGenerators(new RNG(seed), null));
|
||||
assertGenerators(biome().getLayerHeightGenerators(new RNG(seed), RUNTIME),
|
||||
biome.getLayerHeightGenerators(new RNG(seed), RUNTIME));
|
||||
}
|
||||
IrisBiome reversed = biome();
|
||||
for (int i = seeds.length - 1; i >= 0; i--) {
|
||||
assertGenerators(biome.getLayerHeightGenerators(new RNG(seeds[i]), null),
|
||||
reversed.getLayerHeightGenerators(new RNG(seeds[i]), null));
|
||||
assertGenerators(biome.getLayerHeightGenerators(new RNG(seeds[i]), RUNTIME),
|
||||
reversed.getLayerHeightGenerators(new RNG(seeds[i]), RUNTIME));
|
||||
}
|
||||
assertNotEquals(biome.getLayerHeightGenerators(new RNG(TERRAIN_SEED), null).get(0).noise(13, -29),
|
||||
biome.getLayerHeightGenerators(new RNG(FLOATING_SEED), null).get(0).noise(13, -29), 0D);
|
||||
assertNotEquals(biome.getLayerHeightGenerators(new RNG(TERRAIN_SEED), RUNTIME).get(0).noise(13, -29),
|
||||
biome.getLayerHeightGenerators(new RNG(FLOATING_SEED), RUNTIME).get(0).noise(13, -29), 0D);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -72,11 +76,11 @@ public class IrisBiomeLayerHeightCacheTest {
|
||||
try {
|
||||
for (int worker = 0; worker < 8; worker++) {
|
||||
long seed = seeds[worker % seeds.length];
|
||||
KList<CNG> expected = biome().getLayerHeightGenerators(new RNG(seed), null);
|
||||
KList<CNG> expected = biome().getLayerHeightGenerators(new RNG(seed), RUNTIME);
|
||||
tasks.add(executor.submit(() -> {
|
||||
assertTrue(start.await(5, TimeUnit.SECONDS));
|
||||
for (int sample = 0; sample < 30; sample++) {
|
||||
assertGenerators(expected, shared.getLayerHeightGenerators(new RNG(seed), null));
|
||||
assertGenerators(expected, shared.getLayerHeightGenerators(new RNG(seed), RUNTIME));
|
||||
}
|
||||
return null;
|
||||
}));
|
||||
@@ -91,28 +95,22 @@ public class IrisBiomeLayerHeightCacheTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void runtimeAndDataIdentitiesDoNotReuseHeightGenerators() {
|
||||
public void runtimeIdentitiesDoNotReuseHeightGenerators() {
|
||||
IrisBiome biome = biome();
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisData otherData = mock(IrisData.class);
|
||||
Engine first = mock(Engine.class);
|
||||
Engine second = mock(Engine.class);
|
||||
when(data.getEngine()).thenReturn(first);
|
||||
when(otherData.getEngine()).thenReturn(first);
|
||||
IrisData data = MockPackData.create();
|
||||
PackRuntime standalone = data.standalonePackRuntime();
|
||||
PackRuntime otherData = MockPackData.create().standalonePackRuntime();
|
||||
PackRuntime engineScope = PackRuntime.forEngine(mock(Engine.class), data);
|
||||
RNG rng = new RNG(TERRAIN_SEED);
|
||||
KList<CNG> original = biome.getLayerHeightGenerators(rng, data);
|
||||
assertSame(original, biome.getLayerHeightGenerators(rng, data));
|
||||
KList<CNG> other = biome.getLayerHeightGenerators(rng, otherData);
|
||||
assertNotSame(original, other);
|
||||
assertNotSame(original.get(0), other.get(0));
|
||||
assertGenerators(original, other);
|
||||
when(data.getEngine()).thenReturn(second);
|
||||
KList<CNG> replacement = biome.getLayerHeightGenerators(rng, data);
|
||||
assertNotSame(original, replacement);
|
||||
assertNotSame(original.get(0), replacement.get(0));
|
||||
assertGenerators(original, replacement);
|
||||
when(data.getEngine()).thenReturn(first);
|
||||
assertSame(original, biome.getLayerHeightGenerators(rng, data));
|
||||
KList<CNG> original = biome.getLayerHeightGenerators(rng, standalone);
|
||||
assertSame(original, biome.getLayerHeightGenerators(rng, standalone));
|
||||
for (PackRuntime other : new PackRuntime[]{otherData, engineScope}) {
|
||||
KList<CNG> separate = biome.getLayerHeightGenerators(rng, other);
|
||||
assertNotSame(original, separate);
|
||||
assertNotSame(original.get(0), separate.get(0));
|
||||
assertGenerators(original, separate);
|
||||
}
|
||||
assertSame(original, biome.getLayerHeightGenerators(rng, standalone));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -126,12 +124,12 @@ public class IrisBiomeLayerHeightCacheTest {
|
||||
IrisBiome isolated = materialBiome(first, second);
|
||||
RNG rng = new RNG(seed);
|
||||
for (int x = -65; x <= 65; x += 7) {
|
||||
assertEquals(isolated.generateLayers(dimension, x, -x, rng, 64, 120, null, null),
|
||||
shared.generateLayers(dimension, x, -x, rng, 64, 120, null, null));
|
||||
assertEquals(isolated.generateCeilingLayers(dimension, x, -x, rng, 64, 120, null, null),
|
||||
shared.generateCeilingLayers(dimension, x, -x, rng, 64, 120, null, null));
|
||||
assertEquals(isolated.generateSeaLayers(x, -x, rng, 64, null),
|
||||
shared.generateSeaLayers(x, -x, rng, 64, null));
|
||||
assertEquals(isolated.generateLayers(dimension, x, -x, rng, 64, 120, RUNTIME, null),
|
||||
shared.generateLayers(dimension, x, -x, rng, 64, 120, RUNTIME, null));
|
||||
assertEquals(isolated.generateCeilingLayers(dimension, x, -x, rng, 64, 120, RUNTIME, null),
|
||||
shared.generateCeilingLayers(dimension, x, -x, rng, 64, 120, RUNTIME, null));
|
||||
assertEquals(isolated.generateSeaLayers(x, -x, rng, 64, RUNTIME),
|
||||
shared.generateSeaLayers(x, -x, rng, 64, RUNTIME));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -139,11 +137,11 @@ public class IrisBiomeLayerHeightCacheTest {
|
||||
@Test
|
||||
public void evictionRecomputesTheSameNoise() {
|
||||
IrisBiome biome = biome();
|
||||
KList<CNG> original = biome.getLayerHeightGenerators(new RNG(TERRAIN_SEED), null);
|
||||
KList<CNG> original = biome.getLayerHeightGenerators(new RNG(TERRAIN_SEED), RUNTIME);
|
||||
for (int seed = 0; seed < 96; seed++) {
|
||||
biome.getLayerHeightGenerators(new RNG(seed), null);
|
||||
biome.getLayerHeightGenerators(new RNG(seed), RUNTIME);
|
||||
}
|
||||
KList<CNG> recomputed = biome.getLayerHeightGenerators(new RNG(TERRAIN_SEED), null);
|
||||
KList<CNG> recomputed = biome.getLayerHeightGenerators(new RNG(TERRAIN_SEED), RUNTIME);
|
||||
assertNotSame(original, recomputed);
|
||||
assertNotSame(original.get(0), recomputed.get(0));
|
||||
assertGenerators(original, recomputed);
|
||||
|
||||
+14
-10
@@ -1,5 +1,7 @@
|
||||
package art.arcane.iris.generation.biome;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.testsupport.MockPackData;
|
||||
import art.arcane.iris.generation.terrain.IrisDimension;
|
||||
import art.arcane.iris.generation.terrain.IrisSlopeClip;
|
||||
|
||||
@@ -52,7 +54,7 @@ public final class IrisBiomeLayerSlopeSourceTest {
|
||||
|
||||
@Test
|
||||
public void lowerLedgeSlopeControlsSurfacePaletteSelection() {
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisData data = MockPackData.create();
|
||||
IrisComplex complex = mock(IrisComplex.class);
|
||||
IrisBiomePaletteLayer grass = mock(IrisBiomePaletteLayer.class);
|
||||
CNG heightGenerator = mock(CNG.class);
|
||||
@@ -66,14 +68,15 @@ public final class IrisBiomeLayerSlopeSourceTest {
|
||||
when(grass.getMinHeight()).thenReturn(1);
|
||||
when(grass.getMaxHeight()).thenReturn(1);
|
||||
when(grass.getSlopeCondition()).thenReturn(new IrisSlopeClip(0D, 2.6D));
|
||||
when(grass.getHeightGenerator(any(RNG.class), same(data))).thenReturn(heightGenerator);
|
||||
when(grass.getHeightGenerator(any(RNG.class), MockPackData.runtimeOf(data))).thenReturn(heightGenerator);
|
||||
when(heightGenerator.fit(1, 1, 12D, -8D)).thenReturn(1);
|
||||
when(grass.get(rng, 0, 12D, 0D, -8D, data)).thenReturn(block);
|
||||
PaletteLayerRuntime grassRuntime = data.standalonePackRuntime().paletteLayer(grass);
|
||||
when(grass.get(rng, 0, 12D, 0D, -8D, grassRuntime)).thenReturn(block);
|
||||
|
||||
KList<NativeBlockState> ledge = biome.generateLayers(
|
||||
rockFallbackDimension(), 12D, -8D, rng, 1, 32, data, complex);
|
||||
rockFallbackDimension(), 12D, -8D, rng, 1, 32, data.standalonePackRuntime(), complex);
|
||||
KList<NativeBlockState> cap = biome.generateLayers(
|
||||
rockFallbackDimension(), 12D, -8D, rng, 1, 96, data, complex);
|
||||
rockFallbackDimension(), 12D, -8D, rng, 1, 96, data.standalonePackRuntime(), complex);
|
||||
|
||||
assertEquals(1, ledge.size());
|
||||
assertSame(block, ledge.get(0));
|
||||
@@ -84,7 +87,7 @@ public final class IrisBiomeLayerSlopeSourceTest {
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void explicitSlopeStreamControlsSurfacePaletteSelection() {
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisData data = MockPackData.create();
|
||||
IrisComplex hostComplex = mock(IrisComplex.class);
|
||||
ProceduralStream<Double> hostSlope = mock(ProceduralStream.class);
|
||||
ProceduralStream<Double> sourceSlope = mock(ProceduralStream.class);
|
||||
@@ -106,14 +109,15 @@ public final class IrisBiomeLayerSlopeSourceTest {
|
||||
when(paletteLayer.getMinHeight()).thenReturn(1);
|
||||
when(paletteLayer.getMaxHeight()).thenReturn(1);
|
||||
when(paletteLayer.getSlopeCondition()).thenReturn(new IrisSlopeClip(5D, 5D));
|
||||
when(paletteLayer.getHeightGenerator(any(RNG.class), same(data))).thenReturn(heightGenerator);
|
||||
when(paletteLayer.getHeightGenerator(any(RNG.class), MockPackData.runtimeOf(data))).thenReturn(heightGenerator);
|
||||
when(heightGenerator.fit(1, 1, 12D, -8D)).thenReturn(1);
|
||||
when(paletteLayer.get(rng, 0, 12D, 0D, -8D, data)).thenReturn(surfaceBlock);
|
||||
PaletteLayerRuntime paletteLayerRuntime = data.standalonePackRuntime().paletteLayer(paletteLayer);
|
||||
when(paletteLayer.get(rng, 0, 12D, 0D, -8D, paletteLayerRuntime)).thenReturn(surfaceBlock);
|
||||
|
||||
KList<NativeBlockState> hostLayers = biome.generateLayers(
|
||||
rockFallbackDimension(), 12D, -8D, rng, 1, 32, data, hostComplex);
|
||||
rockFallbackDimension(), 12D, -8D, rng, 1, 32, data.standalonePackRuntime(), hostComplex);
|
||||
KList<NativeBlockState> sourceLayers = biome.generateLayersWithSlope(
|
||||
rockFallbackDimension(), 12D, -8D, rng, 1, 32, data, sourceSlope);
|
||||
rockFallbackDimension(), 12D, -8D, rng, 1, 32, data.standalonePackRuntime(), sourceSlope);
|
||||
|
||||
assertTrue(hostLayers.isEmpty());
|
||||
assertEquals(1, sourceLayers.size());
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.generation.biome;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.generation.noise.NoiseStyle;
|
||||
import art.arcane.iris.generation.terrain.IrisSlopeClip;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
@@ -24,6 +25,8 @@ import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
public class IrisBiomeLockedLayerTest {
|
||||
private static final PackRuntime RUNTIME = PackRuntime.standalone(null);
|
||||
|
||||
@Test
|
||||
public void repeatsLockedLayersAcrossTheReferenceHeight() {
|
||||
NativeBlockState first = mock(NativeBlockState.class);
|
||||
@@ -38,7 +41,7 @@ public class IrisBiomeLockedLayerTest {
|
||||
int[][] expectedCycles = {{1, 2, 0}, {0, 1, 2}, {0, 1, 2}, {2, 0, 1}, {1, 2, 0}, {1, 2, 0}};
|
||||
for (int index = 0; index < heights.length; index++) {
|
||||
KList<NativeBlockState> blocks = biome.generateLockedLayers(
|
||||
13, -27, new RNG(37), 8, heights[index], null, null);
|
||||
13, -27, new RNG(37), 8, heights[index], RUNTIME, null);
|
||||
assertEquals(8, blocks.size());
|
||||
for (int depth = 0; depth < blocks.size(); depth++) {
|
||||
assertEquals(cycle.get(expectedCycles[index][depth % 3]), blocks.get(depth));
|
||||
@@ -56,8 +59,8 @@ public class IrisBiomeLockedLayerTest {
|
||||
IrisBiomeCeilingLayerTest.layer(second, 1),
|
||||
IrisBiomeCeilingLayerTest.layer(third, 1)));
|
||||
for (int surface : new int[]{-17, 20, 512, 1000}) {
|
||||
KList<NativeBlockState> lower = biome.generateLockedLayers(13, -27, new RNG(37), 8, surface, null, null);
|
||||
KList<NativeBlockState> higher = biome.generateLockedLayers(13, -27, new RNG(37), 9, surface + 1, null, null);
|
||||
KList<NativeBlockState> lower = biome.generateLockedLayers(13, -27, new RNG(37), 8, surface, RUNTIME, null);
|
||||
KList<NativeBlockState> higher = biome.generateLockedLayers(13, -27, new RNG(37), 9, surface + 1, RUNTIME, null);
|
||||
for (int depth = 0; depth < lower.size(); depth++) {
|
||||
assertEquals(lower.get(depth), higher.get(depth + 1));
|
||||
}
|
||||
@@ -86,7 +89,7 @@ public class IrisBiomeLockedLayerTest {
|
||||
for (int height : heights) {
|
||||
for (int depth : depths) {
|
||||
assertEquals(expandedBands(biome, x, -x, rng, depth, height, 0D),
|
||||
biome.generateLockedLayers(x, -x, rng, depth, height, null, null));
|
||||
biome.generateLockedLayers(x, -x, rng, depth, height, RUNTIME, null));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -100,17 +103,17 @@ public class IrisBiomeLockedLayerTest {
|
||||
palette(1, 1, 1D, block), palette(2, 2, 1D, (NativeBlockState) null)));
|
||||
RNG rng = new RNG(37L);
|
||||
assertEquals(expandedBands(biome, 3D, -11D, rng, 30, 1000, 0D),
|
||||
biome.generateLockedLayers(3D, -11D, rng, 30, 1000, null, null));
|
||||
biome.generateLockedLayers(3D, -11D, rng, 30, 1000, RUNTIME, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void zeroThicknessAndEmptyPalettesProduceNoBands() {
|
||||
IrisBiome biome = new IrisBiome().setLockLayers(true).setLayers(new KList<>());
|
||||
RNG rng = new RNG(37L);
|
||||
assertTrue(biome.generateLockedLayers(0D, 0D, rng, 7, 64, null, null).isEmpty());
|
||||
assertTrue(biome.generateLockedLayers(0D, 0D, rng, 7, 64, RUNTIME, null).isEmpty());
|
||||
biome.setLayers(new KList<>(palette(0, 0, 1D, mock(NativeBlockState.class))));
|
||||
assertTrue(biome.generateLockedLayers(0D, 0D, rng, 7, 64, null, null).isEmpty());
|
||||
assertTrue(biome.generateLockedLayers(0D, 0D, rng, -1, 64, null, null).isEmpty());
|
||||
assertTrue(biome.generateLockedLayers(0D, 0D, rng, 7, 64, RUNTIME, null).isEmpty());
|
||||
assertTrue(biome.generateLockedLayers(0D, 0D, rng, -1, 64, RUNTIME, null).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -119,8 +122,9 @@ public class IrisBiomeLockedLayerTest {
|
||||
mock(NativeBlockState.class), mock(NativeBlockState.class)));
|
||||
IrisBiome biome = new IrisBiome().setLockLayers(true).setLayers(new KList<>(layer));
|
||||
RNG rng = new RNG(37L);
|
||||
assertEquals(7, biome.generateLockedLayers(13D, -27D, rng, 7, 64, null, null).size());
|
||||
verify(layer, times(7)).get(same(rng), anyInt(), anyDouble(), anyDouble(), anyDouble(), isNull());
|
||||
assertEquals(7, biome.generateLockedLayers(13D, -27D, rng, 7, 64, RUNTIME, null).size());
|
||||
PaletteLayerRuntime layerRuntime = RUNTIME.paletteLayer(layer);
|
||||
verify(layer, times(7)).get(same(rng), anyInt(), anyDouble(), anyDouble(), anyDouble(), same(layerRuntime));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -129,8 +133,9 @@ public class IrisBiomeLockedLayerTest {
|
||||
mock(NativeBlockState.class), mock(NativeBlockState.class)));
|
||||
IrisBiome biome = new IrisBiome().setLockLayers(true).setLockLayersMax(100).setLayers(new KList<>(layer));
|
||||
RNG rng = new RNG(37L);
|
||||
assertEquals(100, biome.generateLockedLayers(13D, -27D, rng, 100, 64, null, null).size());
|
||||
verify(layer, times(3)).get(same(rng), anyInt(), anyDouble(), anyDouble(), anyDouble(), isNull());
|
||||
assertEquals(100, biome.generateLockedLayers(13D, -27D, rng, 100, 64, RUNTIME, null).size());
|
||||
PaletteLayerRuntime layerRuntime = RUNTIME.paletteLayer(layer);
|
||||
verify(layer, times(3)).get(same(rng), anyInt(), anyDouble(), anyDouble(), anyDouble(), same(layerRuntime));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -144,7 +149,7 @@ public class IrisBiomeLockedLayerTest {
|
||||
for (double slope : slopes) {
|
||||
ProceduralStream<Double> slopeStream = ProceduralStream.ofDouble((x, z) -> slope);
|
||||
assertEquals(expandedBands(biome, 13D, -27D, rng, 30, 64, slope),
|
||||
biome.generateLayersWithSlope(null, 13D, -27D, rng, 30, 64, null, slopeStream));
|
||||
biome.generateLayersWithSlope(null, 13D, -27D, rng, 30, 64, RUNTIME, slopeStream));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,8 +159,9 @@ public class IrisBiomeLockedLayerTest {
|
||||
IrisBiome biome = new IrisBiome().setLockLayers(true).setLayers(new KList<>(layer));
|
||||
RNG rng = new RNG(37L);
|
||||
IllegalStateException failure = new IllegalStateException("Palette unavailable");
|
||||
doThrow(failure).when(layer).get(same(rng), anyInt(), anyDouble(), anyDouble(), anyDouble(), isNull());
|
||||
assertTrue(biome.generateLockedLayers(0D, 0D, rng, 7, 64, null, null).isEmpty());
|
||||
PaletteLayerRuntime layerRuntime = RUNTIME.paletteLayer(layer);
|
||||
doThrow(failure).when(layer).get(same(rng), anyInt(), anyDouble(), anyDouble(), anyDouble(), same(layerRuntime));
|
||||
assertTrue(biome.generateLockedLayers(0D, 0D, rng, 7, 64, RUNTIME, null).isEmpty());
|
||||
}
|
||||
|
||||
private static IrisBiomePaletteLayer palette(int minimum, int maximum, double zoom, NativeBlockState... blocks) {
|
||||
@@ -169,7 +175,7 @@ public class IrisBiomeLockedLayerTest {
|
||||
int maxDepth, int height, double slope) {
|
||||
KList<NativeBlockState> expanded = new KList<>();
|
||||
KList<NativeBlockState> result = new KList<>();
|
||||
KList<CNG> heights = biome.getLayerHeightGenerators(rng, null);
|
||||
KList<CNG> heights = biome.getLayerHeightGenerators(rng, RUNTIME);
|
||||
for (int index = 0; index < biome.getLayers().size(); index++) {
|
||||
IrisBiomePaletteLayer layer = biome.getLayers().get(index);
|
||||
double zoom = layer.getZoom();
|
||||
@@ -178,7 +184,7 @@ public class IrisBiomeLockedLayerTest {
|
||||
continue;
|
||||
}
|
||||
for (int offset = 0; offset < thickness; offset++) {
|
||||
expanded.add(layer.get(rng, index + offset, (x + offset) / zoom, offset, (z - offset) / zoom, null));
|
||||
expanded.add(layer.get(rng, index + offset, (x + offset) / zoom, offset, (z - offset) / zoom, RUNTIME));
|
||||
}
|
||||
}
|
||||
if (!expanded.isEmpty()) {
|
||||
|
||||
+11
-9
@@ -1,5 +1,7 @@
|
||||
package art.arcane.iris.generation.biome;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.testsupport.MockPackData;
|
||||
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
||||
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
@@ -31,11 +33,11 @@ public final class IrisBiomePaletteLayerGeneratorCacheTest {
|
||||
GeneratorFixture fixture = new GeneratorFixture();
|
||||
|
||||
assertSame(fixture.carveGenerator,
|
||||
fixture.layer.getLayerGenerator(new RNG(11L), SIGNATURE, fixture.data));
|
||||
fixture.layer.getLayerGenerator(new RNG(11L), SIGNATURE, fixture.data.standalonePackRuntime()));
|
||||
assertSame(fixture.postGenerator,
|
||||
fixture.layer.getLayerGenerator(new RNG(29L), SIGNATURE, fixture.data));
|
||||
fixture.layer.getLayerGenerator(new RNG(29L), SIGNATURE, fixture.data.standalonePackRuntime()));
|
||||
assertSame(fixture.carveGenerator,
|
||||
fixture.layer.getLayerGenerator(new RNG(11L), SIGNATURE, fixture.data));
|
||||
fixture.layer.getLayerGenerator(new RNG(11L), SIGNATURE, fixture.data.standalonePackRuntime()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -43,9 +45,9 @@ public final class IrisBiomePaletteLayerGeneratorCacheTest {
|
||||
GeneratorFixture fixture = new GeneratorFixture();
|
||||
|
||||
assertSame(fixture.postGenerator,
|
||||
fixture.layer.getLayerGenerator(new RNG(29L), SIGNATURE, fixture.data));
|
||||
fixture.layer.getLayerGenerator(new RNG(29L), SIGNATURE, fixture.data.standalonePackRuntime()));
|
||||
assertSame(fixture.carveGenerator,
|
||||
fixture.layer.getLayerGenerator(new RNG(11L), SIGNATURE, fixture.data));
|
||||
fixture.layer.getLayerGenerator(new RNG(11L), SIGNATURE, fixture.data.standalonePackRuntime()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -56,11 +58,11 @@ public final class IrisBiomePaletteLayerGeneratorCacheTest {
|
||||
try {
|
||||
Future<CNG> carve = executor.submit(() -> {
|
||||
assertTrue(start.await(5L, TimeUnit.SECONDS));
|
||||
return fixture.layer.getLayerGenerator(new RNG(11L), SIGNATURE, fixture.data);
|
||||
return fixture.layer.getLayerGenerator(new RNG(11L), SIGNATURE, fixture.data.standalonePackRuntime());
|
||||
});
|
||||
Future<CNG> post = executor.submit(() -> {
|
||||
assertTrue(start.await(5L, TimeUnit.SECONDS));
|
||||
return fixture.layer.getLayerGenerator(new RNG(29L), SIGNATURE, fixture.data);
|
||||
return fixture.layer.getLayerGenerator(new RNG(29L), SIGNATURE, fixture.data.standalonePackRuntime());
|
||||
});
|
||||
start.countDown();
|
||||
|
||||
@@ -72,7 +74,7 @@ public final class IrisBiomePaletteLayerGeneratorCacheTest {
|
||||
}
|
||||
|
||||
private static final class GeneratorFixture {
|
||||
private final IrisData data = mock(IrisData.class);
|
||||
private final IrisData data = MockPackData.create();
|
||||
private final Engine engine = mock(Engine.class);
|
||||
private final IrisGeneratorStyle style = mock(IrisGeneratorStyle.class);
|
||||
private final CNG carveGenerator = mock(CNG.class);
|
||||
@@ -85,7 +87,7 @@ public final class IrisBiomePaletteLayerGeneratorCacheTest {
|
||||
11L + SIGNATURE + LAYER_SIGNATURE, carveGenerator,
|
||||
29L + SIGNATURE + LAYER_SIGNATURE, postGenerator
|
||||
);
|
||||
when(style.create(any(RNG.class), same(data), same(engine))).thenAnswer(invocation -> {
|
||||
when(style.createNoCache(any(RNG.class), any())).thenAnswer(invocation -> {
|
||||
RNG rng = invocation.getArgument(0);
|
||||
return generators.get(rng.getSeed());
|
||||
});
|
||||
|
||||
+9
-6
@@ -1,5 +1,7 @@
|
||||
package art.arcane.iris.generation.biome;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.testsupport.MockPackData;
|
||||
import art.arcane.iris.generation.terrain.IrisDimension;
|
||||
import art.arcane.iris.generation.terrain.IrisSlopeClip;
|
||||
|
||||
@@ -20,7 +22,7 @@ import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public final class IrisSurfaceLayerFallbackTest {
|
||||
private final IrisData data = mock(IrisData.class);
|
||||
private final IrisData data = MockPackData.create();
|
||||
private final IrisBiomePaletteLayer layer = mock(IrisBiomePaletteLayer.class);
|
||||
private final CNG heightGenerator = mock(CNG.class);
|
||||
private final NativeBlockState surfaceBlock = mock(NativeBlockState.class);
|
||||
@@ -34,16 +36,17 @@ public final class IrisSurfaceLayerFallbackTest {
|
||||
when(layer.getZoom()).thenReturn(1D);
|
||||
when(layer.getMinHeight()).thenReturn(1);
|
||||
when(layer.getMaxHeight()).thenReturn(2);
|
||||
when(layer.getHeightGenerator(any(RNG.class), same(data))).thenReturn(heightGenerator);
|
||||
when(layer.getHeightGenerator(any(RNG.class), MockPackData.runtimeOf(data))).thenReturn(heightGenerator);
|
||||
when(heightGenerator.fit(1, 2, 12D, -8D)).thenReturn(2);
|
||||
when(layer.get(rng, 0, 12D, 0D, -8D, data)).thenReturn(surfaceBlock);
|
||||
when(layer.get(rng, 1, 13D, 1D, -9D, data)).thenReturn(secondBlock);
|
||||
PaletteLayerRuntime layerRuntime = data.standalonePackRuntime().paletteLayer(layer);
|
||||
when(layer.get(rng, 0, 12D, 0D, -8D, layerRuntime)).thenReturn(surfaceBlock);
|
||||
when(layer.get(rng, 1, 13D, 1D, -9D, layerRuntime)).thenReturn(secondBlock);
|
||||
when(slopeStream.getDouble(12D, -8D)).thenReturn(9D);
|
||||
return new IrisBiome().setLayers(new KList<>(layer));
|
||||
}
|
||||
|
||||
private KList<NativeBlockState> generate(IrisBiome biome, IrisDimension dim) {
|
||||
return biome.generateLayersWithSlope(dim, 12D, -8D, rng, 4, 32, data, slopeStream);
|
||||
return biome.generateLayersWithSlope(dim, 12D, -8D, rng, 4, 32, data.standalonePackRuntime(), slopeStream);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -125,7 +128,7 @@ public final class IrisSurfaceLayerFallbackTest {
|
||||
when(layer.getSlopeCondition()).thenReturn(new IrisSlopeClip(0D, 4D));
|
||||
IrisDimension dimension = new IrisDimension();
|
||||
|
||||
assertTrue(biome.generateLayersWithSlope(dimension, 12D, -8D, rng, 0, 32, data, slopeStream).isEmpty());
|
||||
assertTrue(biome.generateLayersWithSlope(dimension, 12D, -8D, rng, 0, 32, data.standalonePackRuntime(), slopeStream).isEmpty());
|
||||
assertTrue(generate(biome.setLockLayersMax(0), dimension).isEmpty());
|
||||
assertTrue(generate(biome.setLockLayersMax(7).setLayers(new KList<>()), dimension).isEmpty());
|
||||
}
|
||||
|
||||
-139
@@ -1,139 +0,0 @@
|
||||
package art.arcane.iris.generation.cache;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class LazyBoundedCacheTest {
|
||||
@Test
|
||||
public void backingStorageIsLazy() {
|
||||
LazyBoundedCache<String, Object> cache = new LazyBoundedCache<>(8);
|
||||
|
||||
assertFalse(cache.isInitialized());
|
||||
assertEquals(0, cache.size());
|
||||
assertNull(cache.computeIfAbsent("missing", ignored -> null));
|
||||
assertFalse(cache.isInitialized());
|
||||
|
||||
Object expected = new Object();
|
||||
assertSame(expected, cache.computeIfAbsent("present", ignored -> expected));
|
||||
assertTrue(cache.isInitialized());
|
||||
assertEquals(1, cache.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void capacityUsesAccessOrder() {
|
||||
LazyBoundedCache<Integer, Object> cache = new LazyBoundedCache<>(8);
|
||||
Object first = new Object();
|
||||
cache.computeIfAbsent(0, ignored -> first);
|
||||
for (int key = 1; key < 8; key++) {
|
||||
cache.computeIfAbsent(key, ignored -> new Object());
|
||||
}
|
||||
|
||||
assertSame(first, cache.computeIfAbsent(0, ignored -> new Object()));
|
||||
cache.computeIfAbsent(8, ignored -> new Object());
|
||||
|
||||
AtomicInteger reloads = new AtomicInteger();
|
||||
cache.computeIfAbsent(1, ignored -> {
|
||||
reloads.incrementAndGet();
|
||||
return new Object();
|
||||
});
|
||||
assertEquals(1, reloads.get());
|
||||
assertEquals(8, cache.size());
|
||||
assertSame(first, cache.computeIfAbsent(0, ignored -> new Object()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void concurrentSameKeyComputesOnce() throws Exception {
|
||||
int threadCount = 16;
|
||||
LazyBoundedCache<String, Object> cache = new LazyBoundedCache<>(8);
|
||||
CountDownLatch start = new CountDownLatch(1);
|
||||
CountDownLatch resolverEntered = new CountDownLatch(1);
|
||||
CountDownLatch releaseResolver = new CountDownLatch(1);
|
||||
AtomicInteger computations = new AtomicInteger();
|
||||
Object expected = new Object();
|
||||
ExecutorService executor = Executors.newFixedThreadPool(threadCount);
|
||||
List<Future<Object>> futures = new ArrayList<>(threadCount);
|
||||
try {
|
||||
for (int index = 0; index < threadCount; index++) {
|
||||
futures.add(executor.submit(() -> {
|
||||
start.await();
|
||||
return cache.computeIfAbsent("shared", ignored -> {
|
||||
computations.incrementAndGet();
|
||||
resolverEntered.countDown();
|
||||
await(releaseResolver);
|
||||
return expected;
|
||||
});
|
||||
}));
|
||||
}
|
||||
start.countDown();
|
||||
assertTrue(resolverEntered.await(5L, TimeUnit.SECONDS));
|
||||
releaseResolver.countDown();
|
||||
for (Future<Object> future : futures) {
|
||||
assertSame(expected, future.get(5L, TimeUnit.SECONDS));
|
||||
}
|
||||
} finally {
|
||||
releaseResolver.countDown();
|
||||
executor.shutdownNow();
|
||||
assertTrue(executor.awaitTermination(5L, TimeUnit.SECONDS));
|
||||
}
|
||||
|
||||
assertEquals(1, computations.get());
|
||||
assertEquals(1, cache.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void keysRetainIdentityEqualitySemantics() {
|
||||
Object firstIdentity = new String("same");
|
||||
Object secondIdentity = new String("same");
|
||||
LazyBoundedCache<IdentityKey, Object> cache = new LazyBoundedCache<>(8);
|
||||
Object firstValue = new Object();
|
||||
|
||||
assertSame(firstValue, cache.computeIfAbsent(new IdentityKey(firstIdentity), ignored -> firstValue));
|
||||
assertSame(firstValue, cache.computeIfAbsent(new IdentityKey(firstIdentity), ignored -> new Object()));
|
||||
assertNotSame(firstValue, cache.computeIfAbsent(new IdentityKey(secondIdentity), ignored -> new Object()));
|
||||
assertEquals(2, cache.size());
|
||||
}
|
||||
|
||||
private static void await(CountDownLatch latch) {
|
||||
try {
|
||||
if (!latch.await(5L, TimeUnit.SECONDS)) {
|
||||
throw new IllegalStateException("Timed out waiting for cache test latch");
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static final class IdentityKey {
|
||||
private final Object identity;
|
||||
|
||||
private IdentityKey(Object identity) {
|
||||
this.identity = identity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
return other instanceof IdentityKey key && identity == key.identity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return System.identityHashCode(identity);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.generation.cave;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.generation.noise.NoiseStyle;
|
||||
import art.arcane.iris.generation.noise.IrisStyledRange;
|
||||
@@ -26,7 +27,7 @@ public class IrisCaveProfileSamplerTest {
|
||||
public void resolvesThresholdNoiseOnceWhilePreservingCoordinateDecisions() {
|
||||
IrisGeneratorStyle style = mock(IrisGeneratorStyle.class);
|
||||
CNG thresholdNoise = mock(CNG.class);
|
||||
when(style.create(any(), isNull())).thenReturn(thresholdNoise);
|
||||
when(style.create(any(), any(PackRuntime.class))).thenReturn(thresholdNoise);
|
||||
when(thresholdNoise.fitDouble(anyDouble(), anyDouble(), anyDouble(), anyDouble()))
|
||||
.thenAnswer(invocation -> (double) invocation.getArgument(2) * 0.003D
|
||||
+ (double) invocation.getArgument(3) * 0.005D);
|
||||
@@ -41,7 +42,7 @@ public class IrisCaveProfileSamplerTest {
|
||||
assertEquals(density <= threshold, sampler.shouldCarve(x, y, z, 0.75D));
|
||||
}
|
||||
}
|
||||
verify(style, times(1)).create(any(), isNull());
|
||||
verify(style, times(1)).create(any(), any(PackRuntime.class));
|
||||
verify(thresholdNoise, times(585)).fitDouble(anyDouble(), anyDouble(), anyDouble(), anyDouble());
|
||||
}
|
||||
|
||||
@@ -58,7 +59,7 @@ public class IrisCaveProfileSamplerTest {
|
||||
for (int z : coordinates) {
|
||||
for (int y = -60; y <= 60; y += 3) {
|
||||
for (double floatingThreshold : floatingThresholds) {
|
||||
double threshold = range.get(thresholdRng, x, z, null) - profile.getThresholdBias();
|
||||
double threshold = range.get(thresholdRng, x, z, PackRuntime.standalone(null)) - profile.getThresholdBias();
|
||||
threshold += (1D - Math.max(0D, Math.min(1D, floatingThreshold))) * 0.2D;
|
||||
assertEquals("x=" + x + " y=" + y + " z=" + z + " floating=" + floatingThreshold,
|
||||
density(x, y, z) <= threshold, sampler.shouldCarve(x, y, z, floatingThreshold));
|
||||
@@ -98,7 +99,7 @@ public class IrisCaveProfileSamplerTest {
|
||||
when(densityNoise.noiseFastSigned3D(anyDouble(), anyDouble(), anyDouble())).thenAnswer(invocation ->
|
||||
density(invocation.getArgument(0), invocation.getArgument(1), invocation.getArgument(2)));
|
||||
IrisGeneratorStyle densityStyle = mock(IrisGeneratorStyle.class);
|
||||
when(densityStyle.create(any(), isNull())).thenReturn(densityNoise);
|
||||
when(densityStyle.create(any(), any(PackRuntime.class))).thenReturn(densityNoise);
|
||||
IrisCaveProfile profile = mock(IrisCaveProfile.class);
|
||||
when(profile.getBaseDensityStyle()).thenReturn(densityStyle);
|
||||
when(profile.getDetailDensityStyle()).thenReturn(densityStyle);
|
||||
|
||||
+3
-3
@@ -8,7 +8,7 @@ import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
import art.arcane.iris.generation.runtime.SeedManager;
|
||||
import art.arcane.iris.generation.terrain.InferredType;
|
||||
import art.arcane.iris.generation.terrain.IrisDimension;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.testsupport.MockPackData;
|
||||
import art.arcane.iris.spi.IrisPlatform;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.iris.spi.PlatformRegistries;
|
||||
@@ -89,7 +89,7 @@ public class DecorationFailureContainmentTest {
|
||||
doReturn("minecraft:vine").when(vine).materialKey();
|
||||
|
||||
IrisDecorator decorator = mock(IrisDecorator.class);
|
||||
doReturn(true).when(decorator).passesChanceGate(any(), anyDouble(), anyDouble(), any());
|
||||
doReturn(true).when(decorator).passesChanceGate(any(), anyDouble(), anyDouble(), any(DecoratorRuntime.class));
|
||||
doReturn(true).when(decorator).isForcePlace();
|
||||
doReturn(vine).when(decorator).pickBlockData(any(), any(), anyDouble(), anyDouble());
|
||||
doReturn(new NativeBlockState[]{vine}).when(decorator).getBlockDataArray(any());
|
||||
@@ -121,7 +121,7 @@ public class DecorationFailureContainmentTest {
|
||||
private static Engine engine() {
|
||||
Engine engine = mock(Engine.class);
|
||||
doReturn(mock(SeedManager.class)).when(engine).getSeedManager();
|
||||
doReturn(mock(IrisData.class)).when(engine).getData();
|
||||
doReturn(MockPackData.create()).when(engine).getData();
|
||||
IrisDimension dimension = mock(IrisDimension.class);
|
||||
doReturn(63).when(dimension).getFluidHeight();
|
||||
doReturn(dimension).when(engine).getDimension();
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package art.arcane.iris.generation.decoration;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.testsupport.MockPackData;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.generation.biome.IrisBiome;
|
||||
import art.arcane.iris.generation.block.IrisBlockData;
|
||||
@@ -86,39 +88,42 @@ public class DecoratorCoreTest {
|
||||
@Test
|
||||
public void pickDecorator_emptyBucket_returnsNull() {
|
||||
IrisBiome biome = mock(IrisBiome.class);
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisData data = MockPackData.create();
|
||||
PackRuntime runtime = data.standalonePackRuntime();
|
||||
when(biome.getDecoratorBucket(IrisDecorationPart.NONE)).thenReturn(new IrisDecorator[0]);
|
||||
|
||||
IrisDecorator result = DecoratorCore.pickDecorator(
|
||||
biome, IrisDecorationPart.NONE, new RNG(1L), new RNG(2L), data, 0.0, 0.0);
|
||||
biome, IrisDecorationPart.NONE, new RNG(1L), new RNG(2L), runtime, 0.0, 0.0);
|
||||
assertNull(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pickDecorator_nonePassChanceGate_returnsNull() {
|
||||
IrisBiome biome = mock(IrisBiome.class);
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisData data = MockPackData.create();
|
||||
PackRuntime runtime = data.standalonePackRuntime();
|
||||
IrisDecorator d = mock(IrisDecorator.class);
|
||||
when(d.passesChanceGate(any(RNG.class), anyDouble(), anyDouble(), any(IrisData.class))).thenReturn(false);
|
||||
when(d.passesChanceGate(any(RNG.class), anyDouble(), anyDouble(), any(DecoratorRuntime.class))).thenReturn(false);
|
||||
when(biome.getDecoratorBucket(IrisDecorationPart.NONE)).thenReturn(new IrisDecorator[]{d});
|
||||
|
||||
IrisDecorator result = DecoratorCore.pickDecorator(
|
||||
biome, IrisDecorationPart.NONE, new RNG(1L), new RNG(2L), data, 0.0, 0.0);
|
||||
biome, IrisDecorationPart.NONE, new RNG(1L), new RNG(2L), runtime, 0.0, 0.0);
|
||||
assertNull(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pickDecorator_singleCandidate_alwaysReturnsThat() {
|
||||
IrisBiome biome = mock(IrisBiome.class);
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisData data = MockPackData.create();
|
||||
PackRuntime runtime = data.standalonePackRuntime();
|
||||
IrisDecorator d = mock(IrisDecorator.class);
|
||||
when(d.passesChanceGate(any(RNG.class), anyDouble(), anyDouble(), any(IrisData.class))).thenReturn(true);
|
||||
when(d.passesChanceGate(any(RNG.class), anyDouble(), anyDouble(), any(DecoratorRuntime.class))).thenReturn(true);
|
||||
when(biome.getDecoratorBucket(IrisDecorationPart.NONE)).thenReturn(new IrisDecorator[]{d});
|
||||
|
||||
RNG gRNG = new RNG(42L);
|
||||
for (int t = 0; t < 50; t++) {
|
||||
IrisDecorator result = DecoratorCore.pickDecorator(
|
||||
biome, IrisDecorationPart.NONE, gRNG, new RNG(t * 13L + 7), data, 0.0, 0.0);
|
||||
biome, IrisDecorationPart.NONE, gRNG, new RNG(t * 13L + 7), runtime, 0.0, 0.0);
|
||||
assertSame(d, result);
|
||||
}
|
||||
}
|
||||
@@ -126,13 +131,14 @@ public class DecoratorCoreTest {
|
||||
@Test
|
||||
public void pickDecorator_multiplePassingCandidates_selectsUniformly() {
|
||||
IrisBiome biome = mock(IrisBiome.class);
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisData data = MockPackData.create();
|
||||
PackRuntime runtime = data.standalonePackRuntime();
|
||||
|
||||
int n = 4;
|
||||
IrisDecorator[] decorators = new IrisDecorator[n];
|
||||
for (int i = 0; i < n; i++) {
|
||||
IrisDecorator d = mock(IrisDecorator.class);
|
||||
when(d.passesChanceGate(any(RNG.class), anyDouble(), anyDouble(), any(IrisData.class))).thenReturn(true);
|
||||
when(d.passesChanceGate(any(RNG.class), anyDouble(), anyDouble(), any(DecoratorRuntime.class))).thenReturn(true);
|
||||
decorators[i] = d;
|
||||
}
|
||||
when(biome.getDecoratorBucket(IrisDecorationPart.NONE)).thenReturn(decorators);
|
||||
@@ -143,7 +149,7 @@ public class DecoratorCoreTest {
|
||||
|
||||
for (int t = 0; t < trials; t++) {
|
||||
IrisDecorator picked = DecoratorCore.pickDecorator(
|
||||
biome, IrisDecorationPart.NONE, gRNG, new RNG(t * 31L + 3), data, 0.0, 0.0);
|
||||
biome, IrisDecorationPart.NONE, gRNG, new RNG(t * 31L + 3), runtime, 0.0, 0.0);
|
||||
assertNotNull(picked);
|
||||
for (int i = 0; i < n; i++) {
|
||||
if (picked == decorators[i]) {
|
||||
@@ -164,22 +170,23 @@ public class DecoratorCoreTest {
|
||||
@Test
|
||||
public void singleStackTargetsBlockAboveSupport() {
|
||||
IrisDecorator decorator = mock(IrisDecorator.class);
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisData data = MockPackData.create();
|
||||
PackRuntime runtime = data.standalonePackRuntime();
|
||||
NativeBlockState support = sturdyState();
|
||||
NativeBlockState air = mock(NativeBlockState.class);
|
||||
NativeBlockState decorant = mock(NativeBlockState.class);
|
||||
when(air.isAir()).thenReturn(true);
|
||||
when(decorant.key()).thenReturn("minecraft:stone");
|
||||
when(decorant.canPlaceOnto(support)).thenReturn(true);
|
||||
when(decorator.getHeight(any(RNG.class), anyDouble(), anyDouble(), eq(data))).thenReturn(1);
|
||||
when(decorator.pickBlockDataTop(any(RNG.class), eq(data), anyDouble(), anyDouble())).thenReturn(decorant);
|
||||
when(decorator.getHeight(any(RNG.class), anyDouble(), anyDouble(), eq(runtime))).thenReturn(1);
|
||||
when(decorator.pickBlockDataTop(any(RNG.class), eq(runtime), anyDouble(), anyDouble())).thenReturn(decorant);
|
||||
|
||||
Hunk<NativeBlockState> output = Hunk.newArrayHunk(1, 4, 1);
|
||||
output.set(0, 1, 0, support);
|
||||
output.set(0, 2, 0, air);
|
||||
DecoratorCore.PlaceOpts opts = new DecoratorCore.PlaceOpts();
|
||||
|
||||
DecoratorCore.placeStackUp(decorator, 0, 0, 0, 0, 1, 3, output, new RNG(1L), data, opts);
|
||||
DecoratorCore.placeStackUp(decorator, 0, 0, 0, 0, 1, 3, output, new RNG(1L), runtime, opts);
|
||||
|
||||
assertSame(support, output.get(0, 1, 0));
|
||||
assertSame(decorant, output.get(0, 2, 0));
|
||||
@@ -188,21 +195,22 @@ public class DecoratorCoreTest {
|
||||
@Test
|
||||
public void singleStackDoesNotOverwriteOccupiedTarget() {
|
||||
IrisDecorator decorator = mock(IrisDecorator.class);
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisData data = MockPackData.create();
|
||||
PackRuntime runtime = data.standalonePackRuntime();
|
||||
NativeBlockState support = sturdyState();
|
||||
NativeBlockState occupied = mock(NativeBlockState.class);
|
||||
NativeBlockState decorant = mock(NativeBlockState.class);
|
||||
when(occupied.isAir()).thenReturn(false);
|
||||
when(occupied.isFluid()).thenReturn(false);
|
||||
when(decorator.getHeight(any(RNG.class), anyDouble(), anyDouble(), eq(data))).thenReturn(1);
|
||||
when(decorator.pickBlockDataTop(any(RNG.class), eq(data), anyDouble(), anyDouble())).thenReturn(decorant);
|
||||
when(decorator.getHeight(any(RNG.class), anyDouble(), anyDouble(), eq(runtime))).thenReturn(1);
|
||||
when(decorator.pickBlockDataTop(any(RNG.class), eq(runtime), anyDouble(), anyDouble())).thenReturn(decorant);
|
||||
|
||||
Hunk<NativeBlockState> output = Hunk.newArrayHunk(1, 4, 1);
|
||||
output.set(0, 1, 0, support);
|
||||
output.set(0, 2, 0, occupied);
|
||||
DecoratorCore.PlaceOpts opts = new DecoratorCore.PlaceOpts();
|
||||
|
||||
DecoratorCore.placeStackUp(decorator, 0, 0, 0, 0, 1, 3, output, new RNG(1L), data, opts);
|
||||
DecoratorCore.placeStackUp(decorator, 0, 0, 0, 0, 1, 3, output, new RNG(1L), runtime, opts);
|
||||
|
||||
assertSame(support, output.get(0, 1, 0));
|
||||
assertSame(occupied, output.get(0, 2, 0));
|
||||
@@ -211,7 +219,8 @@ public class DecoratorCoreTest {
|
||||
@Test
|
||||
public void multiStackStopsBeforeOccupiedTarget() {
|
||||
IrisDecorator decorator = mock(IrisDecorator.class);
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisData data = MockPackData.create();
|
||||
PackRuntime runtime = data.standalonePackRuntime();
|
||||
NativeBlockState support = sturdyState();
|
||||
NativeBlockState air = mock(NativeBlockState.class);
|
||||
NativeBlockState occupied = mock(NativeBlockState.class);
|
||||
@@ -221,10 +230,10 @@ public class DecoratorCoreTest {
|
||||
when(occupied.isFluid()).thenReturn(false);
|
||||
when(decorant.key()).thenReturn("minecraft:tall_grass");
|
||||
when(decorant.canPlaceOnto(support)).thenReturn(true);
|
||||
when(decorator.getHeight(any(RNG.class), anyDouble(), anyDouble(), eq(data))).thenReturn(3);
|
||||
when(decorator.getHeight(any(RNG.class), anyDouble(), anyDouble(), eq(runtime))).thenReturn(3);
|
||||
when(decorator.getTopThreshold()).thenReturn(0.75);
|
||||
when(decorator.pickBlockData(any(RNG.class), eq(data), anyDouble(), anyDouble())).thenReturn(decorant);
|
||||
when(decorator.pickBlockDataTop(any(RNG.class), eq(data), anyDouble(), anyDouble())).thenReturn(decorant);
|
||||
when(decorator.pickBlockData(any(RNG.class), eq(runtime), anyDouble(), anyDouble())).thenReturn(decorant);
|
||||
when(decorator.pickBlockDataTop(any(RNG.class), eq(runtime), anyDouble(), anyDouble())).thenReturn(decorant);
|
||||
|
||||
Hunk<NativeBlockState> output = Hunk.newArrayHunk(1, 5, 1);
|
||||
output.set(0, 1, 0, support);
|
||||
@@ -233,7 +242,7 @@ public class DecoratorCoreTest {
|
||||
output.set(0, 4, 0, air);
|
||||
DecoratorCore.PlaceOpts opts = new DecoratorCore.PlaceOpts();
|
||||
|
||||
DecoratorCore.placeStackUp(decorator, 0, 0, 0, 0, 1, 4, output, new RNG(1L), data, opts);
|
||||
DecoratorCore.placeStackUp(decorator, 0, 0, 0, 0, 1, 4, output, new RNG(1L), runtime, opts);
|
||||
|
||||
assertSame(decorant, output.get(0, 2, 0));
|
||||
assertSame(occupied, output.get(0, 3, 0));
|
||||
@@ -243,19 +252,20 @@ public class DecoratorCoreTest {
|
||||
@Test
|
||||
public void descendingStackStopsAtLocalWorldFloor() {
|
||||
IrisDecorator decorator = mock(IrisDecorator.class);
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisData data = MockPackData.create();
|
||||
PackRuntime runtime = data.standalonePackRuntime();
|
||||
NativeBlockState decorant = mock(NativeBlockState.class);
|
||||
when(decorant.key()).thenReturn("minecraft:stone");
|
||||
when(decorator.getHeight(any(RNG.class), anyDouble(), anyDouble(), eq(data))).thenReturn(2);
|
||||
when(decorator.getHeight(any(RNG.class), anyDouble(), anyDouble(), eq(runtime))).thenReturn(2);
|
||||
when(decorator.getTopThreshold()).thenReturn(1.0);
|
||||
when(decorator.pickBlockData(any(RNG.class), eq(data), anyDouble(), anyDouble())).thenReturn(decorant);
|
||||
when(decorator.pickBlockDataTop(any(RNG.class), eq(data), anyDouble(), anyDouble())).thenReturn(decorant);
|
||||
when(decorator.pickBlockData(any(RNG.class), eq(runtime), anyDouble(), anyDouble())).thenReturn(decorant);
|
||||
when(decorator.pickBlockDataTop(any(RNG.class), eq(runtime), anyDouble(), anyDouble())).thenReturn(decorant);
|
||||
|
||||
Hunk<NativeBlockState> output = Hunk.newArrayHunk(1, 2, 1);
|
||||
DecoratorCore.PlaceOpts opts = new DecoratorCore.PlaceOpts();
|
||||
|
||||
DecoratorCore.placeStackDown(
|
||||
decorator, 0, 0, 0, 0, 0, -64, output, new RNG(1L), data, 2, opts, null);
|
||||
decorator, 0, 0, 0, 0, 0, -64, output, new RNG(1L), runtime, 2, opts, null);
|
||||
|
||||
assertSame(decorant, output.get(0, 0, 0));
|
||||
}
|
||||
@@ -263,16 +273,17 @@ public class DecoratorCoreTest {
|
||||
@Test
|
||||
public void singleDescendingStackPreservesTargetWhenPickIsNull() {
|
||||
IrisDecorator decorator = mock(IrisDecorator.class);
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisData data = MockPackData.create();
|
||||
PackRuntime runtime = data.standalonePackRuntime();
|
||||
NativeBlockState existing = mock(NativeBlockState.class);
|
||||
when(decorator.getHeight(any(RNG.class), anyDouble(), anyDouble(), eq(data))).thenReturn(1);
|
||||
when(decorator.getHeight(any(RNG.class), anyDouble(), anyDouble(), eq(runtime))).thenReturn(1);
|
||||
|
||||
Hunk<NativeBlockState> output = Hunk.newArrayHunk(1, 2, 1);
|
||||
output.set(0, 0, 0, existing);
|
||||
DecoratorCore.PlaceOpts opts = new DecoratorCore.PlaceOpts();
|
||||
|
||||
DecoratorCore.placeStackDown(
|
||||
decorator, 0, 0, 0, 0, 0, 0, output, new RNG(1L), data, 1, opts, null);
|
||||
decorator, 0, 0, 0, 0, 0, 0, output, new RNG(1L), runtime, 1, opts, null);
|
||||
|
||||
assertSame(existing, output.get(0, 0, 0));
|
||||
}
|
||||
@@ -280,10 +291,11 @@ public class DecoratorCoreTest {
|
||||
@Test
|
||||
public void multiDescendingStackStopsWhenPickIsNull() {
|
||||
IrisDecorator decorator = mock(IrisDecorator.class);
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisData data = MockPackData.create();
|
||||
PackRuntime runtime = data.standalonePackRuntime();
|
||||
NativeBlockState lowerExisting = mock(NativeBlockState.class);
|
||||
NativeBlockState upperExisting = mock(NativeBlockState.class);
|
||||
when(decorator.getHeight(any(RNG.class), anyDouble(), anyDouble(), eq(data))).thenReturn(2);
|
||||
when(decorator.getHeight(any(RNG.class), anyDouble(), anyDouble(), eq(runtime))).thenReturn(2);
|
||||
when(decorator.getTopThreshold()).thenReturn(1.0);
|
||||
|
||||
Hunk<NativeBlockState> output = Hunk.newArrayHunk(1, 2, 1);
|
||||
@@ -292,7 +304,7 @@ public class DecoratorCoreTest {
|
||||
DecoratorCore.PlaceOpts opts = new DecoratorCore.PlaceOpts();
|
||||
|
||||
DecoratorCore.placeStackDown(
|
||||
decorator, 0, 0, 0, 0, 1, 0, output, new RNG(1L), data, 2, opts, null);
|
||||
decorator, 0, 0, 0, 0, 1, 0, output, new RNG(1L), runtime, 2, opts, null);
|
||||
|
||||
assertSame(lowerExisting, output.get(0, 0, 0));
|
||||
assertSame(upperExisting, output.get(0, 1, 0));
|
||||
@@ -301,18 +313,19 @@ public class DecoratorCoreTest {
|
||||
@Test
|
||||
public void floatingStackStopsAtHunkCeiling() {
|
||||
IrisDecorator decorator = mock(IrisDecorator.class);
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisData data = MockPackData.create();
|
||||
PackRuntime runtime = data.standalonePackRuntime();
|
||||
NativeBlockState decorant = mock(NativeBlockState.class);
|
||||
when(decorant.key()).thenReturn("minecraft:stone");
|
||||
when(decorator.getHeight(any(RNG.class), anyDouble(), anyDouble(), eq(data))).thenReturn(3);
|
||||
when(decorator.getHeight(any(RNG.class), anyDouble(), anyDouble(), eq(runtime))).thenReturn(3);
|
||||
when(decorator.getTopThreshold()).thenReturn(1.0);
|
||||
when(decorator.pickBlockData(any(RNG.class), eq(data), anyDouble(), anyDouble())).thenReturn(decorant);
|
||||
when(decorator.pickBlockDataTop(any(RNG.class), eq(data), anyDouble(), anyDouble())).thenReturn(decorant);
|
||||
when(decorator.pickBlockData(any(RNG.class), eq(runtime), anyDouble(), anyDouble())).thenReturn(decorant);
|
||||
when(decorator.pickBlockDataTop(any(RNG.class), eq(runtime), anyDouble(), anyDouble())).thenReturn(decorant);
|
||||
|
||||
Hunk<NativeBlockState> output = Hunk.newArrayHunk(1, 2, 1);
|
||||
output.set(0, 0, 0, sturdyState());
|
||||
int placed = DecoratorCore.placeFloatingStacked(
|
||||
decorator, 0, 0, 0, 0, 0, 3, output, new RNG(1L), data, null);
|
||||
decorator, 0, 0, 0, 0, 0, 3, output, new RNG(1L), runtime, null);
|
||||
|
||||
assertEquals(1, placed);
|
||||
assertSame(decorant, output.get(0, 1, 0));
|
||||
@@ -321,7 +334,8 @@ public class DecoratorCoreTest {
|
||||
@Test
|
||||
public void floatingDecoratorsRejectUnsupportedSurface() {
|
||||
IrisDecorator decorator = mock(IrisDecorator.class);
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisData data = MockPackData.create();
|
||||
PackRuntime runtime = data.standalonePackRuntime();
|
||||
NativeBlockState decorant = mock(NativeBlockState.class);
|
||||
NativeBlockState air = airState();
|
||||
NativeBlockState fluid = mock(NativeBlockState.class);
|
||||
@@ -329,10 +343,10 @@ public class DecoratorCoreTest {
|
||||
when(plant.key()).thenReturn("minecraft:short_grass");
|
||||
when(fluid.isFluid()).thenReturn(true);
|
||||
when(decorant.key()).thenReturn("minecraft:cobblestone_slab");
|
||||
when(decorator.getHeight(any(RNG.class), anyDouble(), anyDouble(), eq(data))).thenReturn(2);
|
||||
when(decorator.getHeight(any(RNG.class), anyDouble(), anyDouble(), eq(runtime))).thenReturn(2);
|
||||
when(decorator.getTopThreshold()).thenReturn(1.0);
|
||||
when(decorator.pickBlockData(any(RNG.class), eq(data), anyDouble(), anyDouble())).thenReturn(decorant);
|
||||
when(decorator.pickBlockDataTop(any(RNG.class), eq(data), anyDouble(), anyDouble())).thenReturn(decorant);
|
||||
when(decorator.pickBlockData(any(RNG.class), eq(runtime), anyDouble(), anyDouble())).thenReturn(decorant);
|
||||
when(decorator.pickBlockDataTop(any(RNG.class), eq(runtime), anyDouble(), anyDouble())).thenReturn(decorant);
|
||||
|
||||
for (NativeBlockState surface : new NativeBlockState[]{null, air, fluid, plant}) {
|
||||
Hunk<NativeBlockState> output = Hunk.newArrayHunk(1, 5, 1);
|
||||
@@ -342,11 +356,11 @@ public class DecoratorCoreTest {
|
||||
output.set(0, 4, 0, air);
|
||||
|
||||
DecoratorCore.placeFloatingSimple(
|
||||
decorator, 0, 0, 0, 0, 2, 3, output, new RNG(1L), data, null);
|
||||
decorator, 0, 0, 0, 0, 2, 3, output, new RNG(1L), runtime, null);
|
||||
assertSame(air, output.get(0, 3, 0));
|
||||
|
||||
int placed = DecoratorCore.placeFloatingStacked(
|
||||
decorator, 0, 0, 0, 0, 2, 3, output, new RNG(1L), data, null);
|
||||
decorator, 0, 0, 0, 0, 2, 3, output, new RNG(1L), runtime, null);
|
||||
assertEquals(0, placed);
|
||||
assertSame(surface, output.get(0, 2, 0));
|
||||
assertSame(air, output.get(0, 3, 0));
|
||||
@@ -357,27 +371,28 @@ public class DecoratorCoreTest {
|
||||
@Test
|
||||
public void floatingDecoratorsPreserveSupportedPlacementWithoutMaterialGating() {
|
||||
IrisDecorator decorator = mock(IrisDecorator.class);
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisData data = MockPackData.create();
|
||||
PackRuntime runtime = data.standalonePackRuntime();
|
||||
NativeBlockState surface = mock(NativeBlockState.class);
|
||||
NativeBlockState decorant = mock(NativeBlockState.class);
|
||||
when(surface.isSolid()).thenReturn(true);
|
||||
when(decorant.key()).thenReturn("minecraft:cobblestone_slab");
|
||||
when(decorator.getHeight(any(RNG.class), anyDouble(), anyDouble(), eq(data))).thenReturn(2);
|
||||
when(decorator.getHeight(any(RNG.class), anyDouble(), anyDouble(), eq(runtime))).thenReturn(2);
|
||||
when(decorator.getTopThreshold()).thenReturn(1.0);
|
||||
when(decorator.pickBlockData(any(RNG.class), eq(data), anyDouble(), anyDouble())).thenReturn(decorant);
|
||||
when(decorator.pickBlockDataTop(any(RNG.class), eq(data), anyDouble(), anyDouble())).thenReturn(decorant);
|
||||
when(decorator.pickBlockData(any(RNG.class), eq(runtime), anyDouble(), anyDouble())).thenReturn(decorant);
|
||||
when(decorator.pickBlockDataTop(any(RNG.class), eq(runtime), anyDouble(), anyDouble())).thenReturn(decorant);
|
||||
Hunk<NativeBlockState> output = Hunk.newArrayHunk(1, 4, 1);
|
||||
output.set(0, 1, 0, surface);
|
||||
output.set(0, 2, 0, airState());
|
||||
output.set(0, 3, 0, airState());
|
||||
|
||||
DecoratorCore.placeFloatingSimple(
|
||||
decorator, 0, 0, 0, 0, 1, 3, output, new RNG(1L), data, null);
|
||||
decorator, 0, 0, 0, 0, 1, 3, output, new RNG(1L), runtime, null);
|
||||
assertSame(decorant, output.get(0, 2, 0));
|
||||
output.set(0, 2, 0, airState());
|
||||
|
||||
int placed = DecoratorCore.placeFloatingStacked(
|
||||
decorator, 0, 0, 0, 0, 1, 3, output, new RNG(1L), data, null);
|
||||
decorator, 0, 0, 0, 0, 1, 3, output, new RNG(1L), runtime, null);
|
||||
assertEquals(2, placed);
|
||||
assertSame(surface, output.get(0, 1, 0));
|
||||
assertSame(decorant, output.get(0, 2, 0));
|
||||
@@ -387,12 +402,13 @@ public class DecoratorCoreTest {
|
||||
@Test
|
||||
public void tallSurfacePlantDoesNotPlaceWhenUpperTargetIsOccupied() {
|
||||
IrisDecorator decorator = mock(IrisDecorator.class);
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisData data = MockPackData.create();
|
||||
PackRuntime runtime = data.standalonePackRuntime();
|
||||
NativeBlockState support = sturdyState();
|
||||
NativeBlockState air = airState();
|
||||
NativeBlockState occupied = mock(NativeBlockState.class);
|
||||
NativeBlockState plant = tallPlantState();
|
||||
when(decorator.pickBlockData(any(RNG.class), eq(data), anyDouble(), anyDouble())).thenReturn(plant);
|
||||
when(decorator.pickBlockData(any(RNG.class), eq(runtime), anyDouble(), anyDouble())).thenReturn(plant);
|
||||
|
||||
Hunk<NativeBlockState> output = Hunk.newArrayHunk(1, 4, 1);
|
||||
output.set(0, 0, 0, support);
|
||||
@@ -400,7 +416,7 @@ public class DecoratorCoreTest {
|
||||
output.set(0, 2, 0, occupied);
|
||||
|
||||
DecoratorCore.placeSurfaceSingle(
|
||||
decorator, 0, 0, 0, 0, 0, output, new RNG(1L), data, false, false, null);
|
||||
decorator, 0, 0, 0, 0, 0, output, new RNG(1L), runtime, false, false, null);
|
||||
|
||||
assertSame(air, output.get(0, 1, 0));
|
||||
assertSame(occupied, output.get(0, 2, 0));
|
||||
@@ -409,11 +425,12 @@ public class DecoratorCoreTest {
|
||||
@Test
|
||||
public void tallFloatingPlantDoesNotPlaceWhenUpperTargetIsOccupied() {
|
||||
IrisDecorator decorator = mock(IrisDecorator.class);
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisData data = MockPackData.create();
|
||||
PackRuntime runtime = data.standalonePackRuntime();
|
||||
NativeBlockState air = airState();
|
||||
NativeBlockState occupied = mock(NativeBlockState.class);
|
||||
NativeBlockState plant = tallPlantState();
|
||||
when(decorator.pickBlockData(any(RNG.class), eq(data), anyDouble(), anyDouble())).thenReturn(plant);
|
||||
when(decorator.pickBlockData(any(RNG.class), eq(runtime), anyDouble(), anyDouble())).thenReturn(plant);
|
||||
|
||||
Hunk<NativeBlockState> output = Hunk.newArrayHunk(1, 4, 1);
|
||||
output.set(0, 0, 0, sturdyState());
|
||||
@@ -421,7 +438,7 @@ public class DecoratorCoreTest {
|
||||
output.set(0, 2, 0, occupied);
|
||||
|
||||
DecoratorCore.placeFloatingSimple(
|
||||
decorator, 0, 0, 0, 0, 0, 3, output, new RNG(1L), data, null);
|
||||
decorator, 0, 0, 0, 0, 0, 3, output, new RNG(1L), runtime, null);
|
||||
|
||||
assertSame(air, output.get(0, 1, 0));
|
||||
assertSame(occupied, output.get(0, 2, 0));
|
||||
@@ -430,7 +447,8 @@ public class DecoratorCoreTest {
|
||||
@Test
|
||||
public void tallSurfacePlantPlacesBothHalvesTogether() {
|
||||
IrisDecorator decorator = mock(IrisDecorator.class);
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisData data = MockPackData.create();
|
||||
PackRuntime runtime = data.standalonePackRuntime();
|
||||
NativeBlockState support = sturdyState();
|
||||
NativeBlockState lowerAir = airState();
|
||||
NativeBlockState upperAir = airState();
|
||||
@@ -438,7 +456,7 @@ public class DecoratorCoreTest {
|
||||
NativeBlockState upper = mock(NativeBlockState.class);
|
||||
NativeBlockState plant = tallPlantState(lower, upper);
|
||||
when(plant.canPlaceOnto(support)).thenReturn(true);
|
||||
when(decorator.pickBlockData(any(RNG.class), eq(data), anyDouble(), anyDouble())).thenReturn(plant);
|
||||
when(decorator.pickBlockData(any(RNG.class), eq(runtime), anyDouble(), anyDouble())).thenReturn(plant);
|
||||
|
||||
Hunk<NativeBlockState> output = Hunk.newArrayHunk(1, 4, 1);
|
||||
output.set(0, 0, 0, support);
|
||||
@@ -446,7 +464,7 @@ public class DecoratorCoreTest {
|
||||
output.set(0, 2, 0, upperAir);
|
||||
|
||||
DecoratorCore.placeSurfaceSingle(
|
||||
decorator, 0, 0, 0, 0, 0, output, new RNG(1L), data, false, false, null);
|
||||
decorator, 0, 0, 0, 0, 0, output, new RNG(1L), runtime, false, false, null);
|
||||
|
||||
assertSame(lower, output.get(0, 1, 0));
|
||||
assertSame(upper, output.get(0, 2, 0));
|
||||
@@ -455,19 +473,20 @@ public class DecoratorCoreTest {
|
||||
@Test
|
||||
public void surfaceDecorantRejectsInvalidNativeSupport() {
|
||||
IrisDecorator decorator = mock(IrisDecorator.class);
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisData data = MockPackData.create();
|
||||
PackRuntime runtime = data.standalonePackRuntime();
|
||||
NativeBlockState support = sturdyState();
|
||||
NativeBlockState air = airState();
|
||||
NativeBlockState decorant = mock(NativeBlockState.class);
|
||||
when(decorant.canPlaceOnto(support)).thenReturn(false);
|
||||
when(decorator.pickBlockData(any(RNG.class), eq(data), anyDouble(), anyDouble())).thenReturn(decorant);
|
||||
when(decorator.pickBlockData(any(RNG.class), eq(runtime), anyDouble(), anyDouble())).thenReturn(decorant);
|
||||
|
||||
Hunk<NativeBlockState> output = Hunk.newArrayHunk(1, 3, 1);
|
||||
output.set(0, 0, 0, support);
|
||||
output.set(0, 1, 0, air);
|
||||
|
||||
DecoratorCore.placeSurfaceSingle(
|
||||
decorator, 0, 0, 0, 0, 0, output, new RNG(1L), data, false, false, null);
|
||||
decorator, 0, 0, 0, 0, 0, output, new RNG(1L), runtime, false, false, null);
|
||||
|
||||
assertSame(air, output.get(0, 1, 0));
|
||||
}
|
||||
@@ -476,7 +495,8 @@ public class DecoratorCoreTest {
|
||||
public void forcedSurfaceBlockStillPlacesDecorantAboveIt() {
|
||||
IrisDecorator decorator = mock(IrisDecorator.class);
|
||||
IrisBlockData forcedBlock = mock(IrisBlockData.class);
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisData data = MockPackData.create();
|
||||
PackRuntime runtime = data.standalonePackRuntime();
|
||||
NativeBlockState support = sturdyState();
|
||||
NativeBlockState farmland = sturdyState();
|
||||
NativeBlockState air = airState();
|
||||
@@ -484,14 +504,14 @@ public class DecoratorCoreTest {
|
||||
when(wheat.key()).thenReturn("minecraft:wheat[age=7]");
|
||||
when(decorator.getForceBlock()).thenReturn(forcedBlock);
|
||||
when(forcedBlock.getBlockData(data)).thenReturn(farmland);
|
||||
when(decorator.pickBlockData(any(RNG.class), eq(data), anyDouble(), anyDouble())).thenReturn(wheat);
|
||||
when(decorator.pickBlockData(any(RNG.class), eq(runtime), anyDouble(), anyDouble())).thenReturn(wheat);
|
||||
|
||||
Hunk<NativeBlockState> output = Hunk.newArrayHunk(1, 3, 1);
|
||||
output.set(0, 0, 0, support);
|
||||
output.set(0, 1, 0, air);
|
||||
|
||||
DecoratorCore.placeSurfaceSingle(
|
||||
decorator, 0, 0, 0, 0, 0, output, new RNG(1L), data, false, false, null);
|
||||
decorator, 0, 0, 0, 0, 0, output, new RNG(1L), runtime, false, false, null);
|
||||
|
||||
assertSame(farmland, output.get(0, 0, 0));
|
||||
assertSame(wheat, output.get(0, 1, 0));
|
||||
@@ -667,10 +687,10 @@ public class DecoratorCoreTest {
|
||||
SpikeFixture fixture = new SpikeFixture(1, upward);
|
||||
if (upward) {
|
||||
DecoratorCore.placeSurfaceSingle(fixture.decorator, 0, 0, 0, 0, 0,
|
||||
fixture.output, new RNG(1L), fixture.data, false, false, null);
|
||||
fixture.output, new RNG(1L), fixture.runtime, false, false, null);
|
||||
} else {
|
||||
DecoratorCore.placeSingleAt(fixture.decorator, 0, 0, 0, 1, 0,
|
||||
fixture.output, new RNG(1L), fixture.data, true, null);
|
||||
fixture.output, new RNG(1L), fixture.runtime, true, null);
|
||||
}
|
||||
assertEquals("tip", fixture.property(1, "thickness"));
|
||||
assertEquals(upward ? "up" : "down", fixture.property(1, "vertical_direction"));
|
||||
@@ -703,7 +723,7 @@ public class DecoratorCoreTest {
|
||||
when(fixture.decorator.getWhitelistArray(fixture.data)).thenReturn(new NativeBlockState[]{original});
|
||||
|
||||
DecoratorCore.placeSurfaceSingle(fixture.decorator, 0, 0, 0, 0, 0,
|
||||
fixture.output, new RNG(1L), fixture.data, false, false, null);
|
||||
fixture.output, new RNG(1L), fixture.runtime, false, false, null);
|
||||
|
||||
assertSame(replacement, fixture.output.get(0, 0, 0));
|
||||
assertEquals("tip", fixture.property(1, "thickness"));
|
||||
@@ -717,8 +737,8 @@ public class DecoratorCoreTest {
|
||||
NativeBlockState obstruction = sturdyState();
|
||||
when(plant.key()).thenReturn("minecraft:weeping_vines_plant");
|
||||
when(tip.key()).thenReturn("minecraft:weeping_vines");
|
||||
when(fixture.decorator.pickBlockData(any(RNG.class), eq(fixture.data), anyDouble(), anyDouble())).thenReturn(tip);
|
||||
when(fixture.decorator.pickBlockDataTop(any(RNG.class), eq(fixture.data), anyDouble(), anyDouble())).thenReturn(tip);
|
||||
when(fixture.decorator.pickBlockData(any(RNG.class), eq(fixture.runtime), anyDouble(), anyDouble())).thenReturn(tip);
|
||||
when(fixture.decorator.pickBlockDataTop(any(RNG.class), eq(fixture.runtime), anyDouble(), anyDouble())).thenReturn(tip);
|
||||
fixture.output.set(0, 3, 0, obstruction);
|
||||
try (MockedStatic<B> blocks = mockStatic(B.class, CALLS_REAL_METHODS)) {
|
||||
blocks.when(() -> B.getState("minecraft:weeping_vines_plant")).thenReturn(plant);
|
||||
@@ -756,18 +776,19 @@ public class DecoratorCoreTest {
|
||||
@Test
|
||||
public void stackedVineCurtainHangsFromTheWallItsTopStrandFaces() {
|
||||
IrisDecorator decorator = mock(IrisDecorator.class);
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisData data = MockPackData.create();
|
||||
PackRuntime runtime = data.standalonePackRuntime();
|
||||
NativeBlockState vine = facingState(VINE, VINE_FACES, EnumSet.of(BlockFace.NORTH));
|
||||
when(decorator.getHeight(any(RNG.class), anyDouble(), anyDouble(), eq(data))).thenReturn(3);
|
||||
when(decorator.getHeight(any(RNG.class), anyDouble(), anyDouble(), eq(runtime))).thenReturn(3);
|
||||
when(decorator.getTopThreshold()).thenReturn(1.0);
|
||||
when(decorator.pickBlockData(any(RNG.class), eq(data), anyDouble(), anyDouble())).thenReturn(vine);
|
||||
when(decorator.pickBlockDataTop(any(RNG.class), eq(data), anyDouble(), anyDouble())).thenReturn(vine);
|
||||
when(decorator.pickBlockData(any(RNG.class), eq(runtime), anyDouble(), anyDouble())).thenReturn(vine);
|
||||
when(decorator.pickBlockDataTop(any(RNG.class), eq(runtime), anyDouble(), anyDouble())).thenReturn(vine);
|
||||
Hunk<NativeBlockState> output = Hunk.newArrayHunk(16, 8, 16);
|
||||
output.set(8, 6, 8, sturdyState());
|
||||
output.set(8, 5, 7, sturdyState());
|
||||
output.set(9, 4, 8, sturdyState());
|
||||
|
||||
DecoratorCore.placeStackDown(decorator, 8, 8, 8, 8, 5, 0, output, new RNG(1L), data, 3,
|
||||
DecoratorCore.placeStackDown(decorator, 8, 8, 8, 8, 5, 0, output, new RNG(1L), runtime, 3,
|
||||
new DecoratorCore.PlaceOpts(), null);
|
||||
|
||||
assertEquals(EnumSet.of(BlockFace.NORTH, BlockFace.UP), faces(output.get(8, 5, 8)));
|
||||
@@ -778,16 +799,17 @@ public class DecoratorCoreTest {
|
||||
@Test
|
||||
public void stackedVineCurtainHangsUnderAnOpenCeiling() {
|
||||
IrisDecorator decorator = mock(IrisDecorator.class);
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisData data = MockPackData.create();
|
||||
PackRuntime runtime = data.standalonePackRuntime();
|
||||
NativeBlockState vine = facingState(VINE, VINE_FACES, EnumSet.of(BlockFace.NORTH));
|
||||
when(decorator.getHeight(any(RNG.class), anyDouble(), anyDouble(), eq(data))).thenReturn(3);
|
||||
when(decorator.getHeight(any(RNG.class), anyDouble(), anyDouble(), eq(runtime))).thenReturn(3);
|
||||
when(decorator.getTopThreshold()).thenReturn(1.0);
|
||||
when(decorator.pickBlockData(any(RNG.class), eq(data), anyDouble(), anyDouble())).thenReturn(vine);
|
||||
when(decorator.pickBlockDataTop(any(RNG.class), eq(data), anyDouble(), anyDouble())).thenReturn(vine);
|
||||
when(decorator.pickBlockData(any(RNG.class), eq(runtime), anyDouble(), anyDouble())).thenReturn(vine);
|
||||
when(decorator.pickBlockDataTop(any(RNG.class), eq(runtime), anyDouble(), anyDouble())).thenReturn(vine);
|
||||
Hunk<NativeBlockState> output = Hunk.newArrayHunk(16, 8, 16);
|
||||
output.set(8, 6, 8, sturdyState());
|
||||
|
||||
DecoratorCore.placeStackDown(decorator, 8, 8, 8, 8, 5, 0, output, new RNG(1L), data, 3,
|
||||
DecoratorCore.placeStackDown(decorator, 8, 8, 8, 8, 5, 0, output, new RNG(1L), runtime, 3,
|
||||
new DecoratorCore.PlaceOpts(), null);
|
||||
|
||||
assertEquals(EnumSet.of(BlockFace.NORTH, BlockFace.UP), faces(output.get(8, 5, 8)));
|
||||
@@ -915,14 +937,15 @@ public class DecoratorCoreTest {
|
||||
|
||||
private Hunk<NativeBlockState> placeSpikeColumn(String material, int height, boolean upward, boolean waterlogged, boolean submerged) {
|
||||
IrisDecorator decorator = mock(IrisDecorator.class);
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisData data = MockPackData.create();
|
||||
PackRuntime runtime = data.standalonePackRuntime();
|
||||
NativeBlockState spike = spikeState(material, Map.of(
|
||||
"thickness", "tip_merge", "vertical_direction", upward ? "down" : "up",
|
||||
"waterlogged", Boolean.toString(waterlogged)));
|
||||
when(decorator.getHeight(any(RNG.class), anyDouble(), anyDouble(), eq(data))).thenReturn(height);
|
||||
when(decorator.getHeight(any(RNG.class), anyDouble(), anyDouble(), eq(runtime))).thenReturn(height);
|
||||
when(decorator.getTopThreshold()).thenReturn(0.75);
|
||||
when(decorator.pickBlockData(any(RNG.class), eq(data), anyDouble(), anyDouble())).thenReturn(spike);
|
||||
when(decorator.pickBlockDataTop(any(RNG.class), eq(data), anyDouble(), anyDouble())).thenReturn(spike);
|
||||
when(decorator.pickBlockData(any(RNG.class), eq(runtime), anyDouble(), anyDouble())).thenReturn(spike);
|
||||
when(decorator.pickBlockDataTop(any(RNG.class), eq(runtime), anyDouble(), anyDouble())).thenReturn(spike);
|
||||
|
||||
Hunk<NativeBlockState> output = Hunk.newArrayHunk(1, height + 2, 1);
|
||||
NativeBlockState target = airState();
|
||||
@@ -941,9 +964,9 @@ public class DecoratorCoreTest {
|
||||
opts.underwater = submerged;
|
||||
opts.fluidHeight = height;
|
||||
if (upward) {
|
||||
DecoratorCore.placeStackUp(decorator, 0, 0, 0, 0, 0, height, output, new RNG(1L), data, opts);
|
||||
DecoratorCore.placeStackUp(decorator, 0, 0, 0, 0, 0, height, output, new RNG(1L), runtime, opts);
|
||||
} else {
|
||||
DecoratorCore.placeStackDown(decorator, 0, 0, 0, 0, height, 1, output, new RNG(1L), data, height, opts, null);
|
||||
DecoratorCore.placeStackDown(decorator, 0, 0, 0, 0, height, 1, output, new RNG(1L), runtime, height, opts, null);
|
||||
}
|
||||
assertSame(support, output.get(0, upward ? 0 : height + 1, 0));
|
||||
return output;
|
||||
@@ -987,23 +1010,24 @@ public class DecoratorCoreTest {
|
||||
private void assertSingleVoxelHalfPlacement(boolean floating) {
|
||||
for (String key : new String[]{"minecraft:oak_stairs[half=bottom]", "minecraft:oak_trapdoor[half=top]"}) {
|
||||
IrisDecorator decorator = mock(IrisDecorator.class);
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisData data = MockPackData.create();
|
||||
PackRuntime runtime = data.standalonePackRuntime();
|
||||
NativeBlockState support = sturdyState();
|
||||
NativeBlockState air = airState();
|
||||
NativeBlockState occupied = mock(NativeBlockState.class);
|
||||
NativeBlockState block = mock(NativeBlockState.class);
|
||||
when(block.key()).thenReturn(key);
|
||||
when(block.canPlaceOnto(support)).thenReturn(true);
|
||||
when(decorator.pickBlockData(any(RNG.class), eq(data), anyDouble(), anyDouble())).thenReturn(block);
|
||||
when(decorator.pickBlockData(any(RNG.class), eq(runtime), anyDouble(), anyDouble())).thenReturn(block);
|
||||
Hunk<NativeBlockState> output = Hunk.newArrayHunk(1, 4, 1);
|
||||
output.set(0, 0, 0, support);
|
||||
output.set(0, 1, 0, air);
|
||||
output.set(0, 2, 0, occupied);
|
||||
|
||||
if (floating) {
|
||||
DecoratorCore.placeFloatingSimple(decorator, 0, 0, 0, 0, 0, 3, output, new RNG(1L), data, null);
|
||||
DecoratorCore.placeFloatingSimple(decorator, 0, 0, 0, 0, 0, 3, output, new RNG(1L), runtime, null);
|
||||
} else {
|
||||
DecoratorCore.placeSurfaceSingle(decorator, 0, 0, 0, 0, 0, output, new RNG(1L), data, false, false, null);
|
||||
DecoratorCore.placeSurfaceSingle(decorator, 0, 0, 0, 0, 0, output, new RNG(1L), runtime, false, false, null);
|
||||
}
|
||||
|
||||
assertSame(key, block, output.get(0, 1, 0));
|
||||
@@ -1033,7 +1057,8 @@ public class DecoratorCoreTest {
|
||||
}
|
||||
private class SpikeFixture {
|
||||
private final IrisDecorator decorator = mock(IrisDecorator.class);
|
||||
private final IrisData data = mock(IrisData.class);
|
||||
private final IrisData data = MockPackData.create();
|
||||
private final PackRuntime runtime = data.standalonePackRuntime();
|
||||
private final DecoratorCore.PlaceOpts opts = new DecoratorCore.PlaceOpts();
|
||||
private final Hunk<NativeBlockState> output;
|
||||
private final int height;
|
||||
@@ -1049,17 +1074,17 @@ public class DecoratorCoreTest {
|
||||
output.set(0, upward ? 0 : height + 1, 0, sturdyState());
|
||||
NativeBlockState spike = spikeState("minecraft:sulfur_spike", Map.of(
|
||||
"thickness", "tip_merge", "vertical_direction", upward ? "down" : "up", "waterlogged", "false"));
|
||||
when(decorator.getHeight(any(RNG.class), anyDouble(), anyDouble(), eq(data))).thenReturn(height);
|
||||
when(decorator.getHeight(any(RNG.class), anyDouble(), anyDouble(), eq(runtime))).thenReturn(height);
|
||||
when(decorator.getTopThreshold()).thenReturn(0.75);
|
||||
when(decorator.pickBlockData(any(RNG.class), eq(data), anyDouble(), anyDouble())).thenReturn(spike);
|
||||
when(decorator.pickBlockDataTop(any(RNG.class), eq(data), anyDouble(), anyDouble())).thenReturn(spike);
|
||||
when(decorator.pickBlockData(any(RNG.class), eq(runtime), anyDouble(), anyDouble())).thenReturn(spike);
|
||||
when(decorator.pickBlockDataTop(any(RNG.class), eq(runtime), anyDouble(), anyDouble())).thenReturn(spike);
|
||||
}
|
||||
|
||||
private void place() {
|
||||
if (upward) {
|
||||
DecoratorCore.placeStackUp(decorator, 0, 0, 0, 0, 0, height, output, new RNG(1L), data, opts);
|
||||
DecoratorCore.placeStackUp(decorator, 0, 0, 0, 0, 0, height, output, new RNG(1L), runtime, opts);
|
||||
} else {
|
||||
DecoratorCore.placeStackDown(decorator, 0, 0, 0, 0, height, 1, output, new RNG(1L), data, height, opts, null);
|
||||
DecoratorCore.placeStackDown(decorator, 0, 0, 0, 0, height, 1, output, new RNG(1L), runtime, height, opts, null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+8
-6
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.generation.decoration;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
import art.arcane.volmlib.util.hunk.Hunk;
|
||||
@@ -36,6 +37,7 @@ public class DecoratorStackSamplingTest {
|
||||
|
||||
private static void assertEquivalentStack(long seed, int height, int direction, int coordinate) {
|
||||
IrisData data = mock(IrisData.class);
|
||||
PackRuntime runtime = PackRuntime.standalone(data);
|
||||
RNG rng = new RNG(seed);
|
||||
RNG controlRng = new RNG(seed);
|
||||
CNG variance = new CNG(new RNG(seed + 11L));
|
||||
@@ -46,7 +48,7 @@ public class DecoratorStackSamplingTest {
|
||||
.setStackMin(height).setStackMax(height).setTopThreshold(0.4D));
|
||||
doReturn(body).when(decorator).getBlockDataArray(data);
|
||||
doReturn(top).when(decorator).getBlockDataTopsArray(data);
|
||||
doReturn(variance).when(decorator).getVarianceGenerator(rng, data);
|
||||
doReturn(variance).when(decorator).getVarianceGenerator(rng, runtime);
|
||||
NativeBlockState air = block("minecraft:air");
|
||||
doReturn(true).when(air).isAir();
|
||||
NativeBlockState support = block("minecraft:stone");
|
||||
@@ -64,11 +66,11 @@ public class DecoratorStackSamplingTest {
|
||||
int z = coordinate * 3 - 7;
|
||||
switch (direction) {
|
||||
case 0 -> DecoratorCore.placeStackUp(decorator, 0, 0, coordinate, z, 0, height,
|
||||
output, rng, data, opts);
|
||||
output, rng, runtime, opts);
|
||||
case 1 -> DecoratorCore.placeStackDown(decorator, 0, 0, coordinate, z, height, 0,
|
||||
output, rng, data, height, opts, null);
|
||||
output, rng, runtime, height, opts, null);
|
||||
case 2 -> assertEquals(height, DecoratorCore.placeFloatingStacked(decorator, 0, 0,
|
||||
coordinate, z, 0, height + 1, output, rng, data, null));
|
||||
coordinate, z, 0, height + 1, output, rng, runtime, null));
|
||||
default -> throw new IllegalArgumentException("Unknown stack direction");
|
||||
}
|
||||
boolean usedBody = false;
|
||||
@@ -84,8 +86,8 @@ public class DecoratorStackSamplingTest {
|
||||
usedTop |= topSegment;
|
||||
}
|
||||
assertSame(support, output.get(0, supportY, 0));
|
||||
verify(decorator, times(usedBody ? 1 : 0)).pickBlockData(rng, data, coordinate, z);
|
||||
verify(decorator, times(usedTop ? 1 : 0)).pickBlockDataTop(rng, data, coordinate, z);
|
||||
verify(decorator, times(usedBody ? 1 : 0)).pickBlockData(rng, runtime, coordinate, z);
|
||||
verify(decorator, times(usedTop ? 1 : 0)).pickBlockDataTop(rng, runtime, coordinate, z);
|
||||
assertEquals(controlRng.nextLong(), rng.nextLong());
|
||||
}
|
||||
|
||||
|
||||
+4
-3
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.generation.decoration;
|
||||
|
||||
import art.arcane.iris.testsupport.MockPackData;
|
||||
import art.arcane.iris.generation.block.IrisBlockData;
|
||||
import art.arcane.iris.generation.hydrology.config.IrisHydrology;
|
||||
import art.arcane.iris.generation.hydrology.raster.ChunkWaterRaster;
|
||||
@@ -41,7 +42,7 @@ public class HydrologyVegetationTest {
|
||||
private static final Set<String> WATER_PLANTS = Set.of("minecraft:seagrass", "minecraft:tall_seagrass", "minecraft:kelp", "minecraft:kelp_plant");
|
||||
private static final int[][] SIDES = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
|
||||
|
||||
private final IrisData data = mock(IrisData.class);
|
||||
private final IrisData data = MockPackData.create();
|
||||
private PlantPlatform platform;
|
||||
|
||||
@Before
|
||||
@@ -591,7 +592,7 @@ public class HydrologyVegetationTest {
|
||||
for (int lz = 0; lz < 16; lz++) {
|
||||
int x = (chunkX << 4) + lx;
|
||||
int z = (chunkZ << 4) + lz;
|
||||
vegetation.decorate(chunk, lx, lz, x, z, role(x, z), this, data);
|
||||
vegetation.decorate(chunk, lx, lz, x, z, role(x, z), this, data.standalonePackRuntime());
|
||||
}
|
||||
}
|
||||
return chunk;
|
||||
@@ -663,7 +664,7 @@ public class HydrologyVegetationTest {
|
||||
for (int lz = 0; lz < 16; lz++) {
|
||||
int x = (chunkX << 4) + lx;
|
||||
int z = (chunkZ << 4) + lz;
|
||||
vegetation.decorate(chunk, lx, lz, x, z, role(x, z), this, data);
|
||||
vegetation.decorate(chunk, lx, lz, x, z, role(x, z), this, data.standalonePackRuntime());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-5
@@ -1,6 +1,7 @@
|
||||
package art.arcane.iris.generation.decoration;
|
||||
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.testsupport.MockPackData;
|
||||
import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
import art.arcane.iris.generation.mantle.EngineMantle;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
@@ -63,7 +64,7 @@ public class IrisDecoratorCaveContextTest {
|
||||
Engine engine = mock(Engine.class);
|
||||
SeedManager seedManager = mock(SeedManager.class);
|
||||
doReturn(seedManager).when(engine).getSeedManager();
|
||||
doReturn(mock(IrisData.class)).when(engine).getData();
|
||||
doReturn(MockPackData.create()).when(engine).getData();
|
||||
IrisDimension dimension = mock(IrisDimension.class);
|
||||
doReturn(63).when(dimension).getFluidHeight();
|
||||
doReturn(dimension).when(engine).getDimension();
|
||||
@@ -74,7 +75,7 @@ public class IrisDecoratorCaveContextTest {
|
||||
doReturn(63).when(mantle).getFluidHeight(anyInt(), anyInt());
|
||||
|
||||
IrisDecorator decorator = mock(IrisDecorator.class);
|
||||
doReturn(true).when(decorator).passesChanceGate(any(), anyDouble(), anyDouble(), any());
|
||||
doReturn(true).when(decorator).passesChanceGate(any(), anyDouble(), anyDouble(), any(DecoratorRuntime.class));
|
||||
doReturn(true).when(decorator).isStacking();
|
||||
doReturn(true).when(decorator).isForcePlace();
|
||||
doReturn(1).when(decorator).getHeight(any(), anyDouble(), anyDouble(), any());
|
||||
@@ -113,7 +114,7 @@ public class IrisDecoratorCaveContextTest {
|
||||
public void dryBlendedSurfaceRunsBiomeDecoratorDespiteHigherModeledWater() {
|
||||
Engine engine = mock(Engine.class);
|
||||
doReturn(mock(SeedManager.class)).when(engine).getSeedManager();
|
||||
doReturn(mock(IrisData.class)).when(engine).getData();
|
||||
doReturn(MockPackData.create()).when(engine).getData();
|
||||
doReturn(7L).when(engine).getGenerationSessionId();
|
||||
IrisDimension dimension = mock(IrisDimension.class);
|
||||
doReturn(dimension).when(engine).getDimension();
|
||||
@@ -122,7 +123,7 @@ public class IrisDecoratorCaveContextTest {
|
||||
doReturn(63).when(mantle).getFluidHeight(anyInt(), anyInt());
|
||||
|
||||
IrisDecorator decorator = mock(IrisDecorator.class);
|
||||
doReturn(true).when(decorator).passesChanceGate(any(), anyDouble(), anyDouble(), any());
|
||||
doReturn(true).when(decorator).passesChanceGate(any(), anyDouble(), anyDouble(), any(DecoratorRuntime.class));
|
||||
doReturn(true).when(decorator).isStacking();
|
||||
doReturn(true).when(decorator).isForcePlace();
|
||||
doReturn(1).when(decorator).getHeight(any(), anyDouble(), anyDouble(), any());
|
||||
@@ -143,7 +144,7 @@ public class IrisDecoratorCaveContextTest {
|
||||
assertEquals(63, surface.surfaceFluidHeight(16, 0));
|
||||
}
|
||||
|
||||
verify(decorator).passesChanceGate(any(), anyDouble(), anyDouble(), any());
|
||||
verify(decorator).passesChanceGate(any(), anyDouble(), anyDouble(), any(DecoratorRuntime.class));
|
||||
assertFalse(DecoratorCore.SCRATCH_OPTS.get().underwater);
|
||||
assertEquals(63, surface.surfaceFluidHeight(0, 0));
|
||||
try (IrisContext.Scope scope = IrisContext.open(engine, 8L, chunk)) {
|
||||
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
package art.arcane.iris.generation.decoration;
|
||||
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.volmlib.util.noise.CNG;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import org.junit.Test;
|
||||
@@ -18,13 +18,13 @@ public class IrisDecoratorHeightTest {
|
||||
when(generator.fit(eq(1), eq(2), anyDouble(), anyDouble())).thenReturn(2);
|
||||
IrisDecorator decorator = new IrisDecorator() {
|
||||
@Override
|
||||
public CNG getHeightGenerator(RNG rng, IrisData data) {
|
||||
public CNG getHeightGenerator(RNG rng, PackRuntime runtime) {
|
||||
return generator;
|
||||
}
|
||||
};
|
||||
decorator.setStackMin(1);
|
||||
decorator.setStackMax(2);
|
||||
|
||||
assertEquals(2, decorator.getHeight(new RNG(1L), 0, 0, mock(IrisData.class)));
|
||||
assertEquals(2, decorator.getHeight(new RNG(1L), 0, 0, PackRuntime.standalone(null)));
|
||||
}
|
||||
}
|
||||
+13
-9
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.generation.decoration;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.generation.biome.IrisBiome;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
@@ -21,6 +22,7 @@ public class IrisDecoratorPaletteSelectionTest {
|
||||
@Test
|
||||
public void multipleTopEntriesVaryEvenWhenTheBodyPaletteIsASingleBlock() {
|
||||
IrisData data = mock(IrisData.class);
|
||||
PackRuntime runtime = PackRuntime.standalone(data);
|
||||
IrisBiome biome = mock(IrisBiome.class);
|
||||
IrisDecorator decorator = spy(new IrisDecorator().setChance(1D));
|
||||
NativeBlockState body = mock(NativeBlockState.class);
|
||||
@@ -32,13 +34,13 @@ public class IrisDecoratorPaletteSelectionTest {
|
||||
RNG rng = new RNG(37L);
|
||||
doReturn(new KList<>(body)).when(decorator).getBlockData(data);
|
||||
doReturn(tops).when(decorator).getBlockDataTops(data);
|
||||
doReturn(chance).when(decorator).getGenerator(rng, data);
|
||||
doReturn(variance).when(decorator).getVarianceGenerator(rng, data);
|
||||
doReturn(chance).when(decorator).getGenerator(rng, runtime);
|
||||
doReturn(variance).when(decorator).getVarianceGenerator(rng, runtime);
|
||||
doReturn(second).when(variance).fit(tops, 23D, 9D, 17D);
|
||||
doReturn(first).when(variance).fit(tops, 24D, 9D, 17D);
|
||||
|
||||
assertSame(second, decorator.getBlockDataForTop(biome, rng, 17D, 9D, 23D, data));
|
||||
assertSame(first, decorator.getBlockDataForTop(biome, rng, 17D, 9D, 24D, data));
|
||||
assertSame(second, decorator.getBlockDataForTop(biome, rng, 17D, 9D, 23D, runtime));
|
||||
assertSame(first, decorator.getBlockDataForTop(biome, rng, 17D, 9D, 24D, runtime));
|
||||
verify(variance).fit(tops, 23D, 9D, 17D);
|
||||
verify(variance).fit(tops, 24D, 9D, 17D);
|
||||
}
|
||||
@@ -46,6 +48,7 @@ public class IrisDecoratorPaletteSelectionTest {
|
||||
@Test
|
||||
public void aSingleTopEntryDoesNotBuildOrSampleTheVarianceGenerator() {
|
||||
IrisData data = mock(IrisData.class);
|
||||
PackRuntime runtime = PackRuntime.standalone(data);
|
||||
IrisBiome biome = mock(IrisBiome.class);
|
||||
IrisDecorator decorator = spy(new IrisDecorator().setChance(1D));
|
||||
NativeBlockState firstBody = mock(NativeBlockState.class);
|
||||
@@ -54,16 +57,17 @@ public class IrisDecoratorPaletteSelectionTest {
|
||||
RNG rng = new RNG(37L);
|
||||
doReturn(new KList<>(firstBody, secondBody)).when(decorator).getBlockData(data);
|
||||
doReturn(new KList<>(top)).when(decorator).getBlockDataTops(data);
|
||||
doReturn(mock(CNG.class)).when(decorator).getGenerator(rng, data);
|
||||
doReturn(mock(CNG.class)).when(decorator).getGenerator(rng, runtime);
|
||||
|
||||
assertSame(top, decorator.getBlockDataForTop(biome, rng, 17D, 9D, 23D, data));
|
||||
verify(decorator, never()).getVarianceGenerator(rng, data);
|
||||
assertSame(top, decorator.getBlockDataForTop(biome, rng, 17D, 9D, 23D, runtime));
|
||||
verify(decorator, never()).getVarianceGenerator(rng, runtime);
|
||||
verify(decorator, times(1)).getBlockDataTops(data);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bodySamplingResolvesPaletteOnceAndPreservesCoordinatesAndRngConsumption() {
|
||||
IrisData data = mock(IrisData.class);
|
||||
PackRuntime runtime = PackRuntime.standalone(data);
|
||||
IrisBiome biome = mock(IrisBiome.class);
|
||||
IrisDecorator decorator = spy(new IrisDecorator());
|
||||
NativeBlockState first = mock(NativeBlockState.class);
|
||||
@@ -73,13 +77,13 @@ public class IrisDecoratorPaletteSelectionTest {
|
||||
RNG rng = new RNG(37L);
|
||||
RNG control = new RNG(37L);
|
||||
doReturn(palette).when(decorator).getBlockData(data);
|
||||
doReturn(variance).when(decorator).getVarianceGenerator(rng, data);
|
||||
doReturn(variance).when(decorator).getVarianceGenerator(rng, runtime);
|
||||
|
||||
for (int x = -8; x < 8; x++) {
|
||||
for (int y = 0; y < 4; y++) {
|
||||
double z = x * 3D - 2D;
|
||||
NativeBlockState expected = variance.fit(palette, z, y, x);
|
||||
assertSame(expected, decorator.getBlockData100(biome, rng, x, y, z, data));
|
||||
assertSame(expected, decorator.getBlockData100(biome, rng, x, y, z, runtime));
|
||||
}
|
||||
}
|
||||
verify(decorator, times(64)).getBlockData(data);
|
||||
|
||||
+3
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.generation.decoration;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.generation.biome.IrisBiome;
|
||||
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.generation.noise.NoiseStyle;
|
||||
@@ -113,6 +114,8 @@ public class IrisDecoratorSeedCohesionTest {
|
||||
|
||||
private Fixture(long seed, IrisDecorator decorator, IrisData data) {
|
||||
when(engine.getData()).thenReturn(data);
|
||||
PackRuntime runtime = PackRuntime.forEngine(engine, data);
|
||||
when(engine.getPackRuntime()).thenReturn(runtime);
|
||||
when(engine.getHeight()).thenReturn(32);
|
||||
when(engine.getSeedManager().getComponent()).thenReturn(seed);
|
||||
when(engine.getAllBiomes()).thenReturn(new KList<>(biome));
|
||||
|
||||
+3
-2
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.generation.decoration;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.generation.block.IrisBlockData;
|
||||
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.generation.noise.NoiseStyle;
|
||||
@@ -26,7 +27,7 @@ public class IrisDecoratorVarianceGeneratorTest {
|
||||
}
|
||||
|
||||
private double[] sampleSharedVarianceStyleGeneratorAfterVarianceBuilt() {
|
||||
decorator.getVarianceGenerator(new RNG(WORLD_SEED), packData);
|
||||
decorator.getVarianceGenerator(new RNG(WORLD_SEED), PackRuntime.of(packData.getEngine(), packData));
|
||||
return sampleSharedVarianceStyleGenerator(decorator.getVariance());
|
||||
}
|
||||
|
||||
@@ -35,7 +36,7 @@ public class IrisDecoratorVarianceGeneratorTest {
|
||||
}
|
||||
|
||||
private double[] sampleSharedVarianceStyleGenerator(IrisGeneratorStyle varianceStyle) {
|
||||
return sampleSharedGenerator(varianceStyle, decorator.deriveVarianceSeed(new RNG(WORLD_SEED), packData), packData);
|
||||
return sampleSharedGenerator(varianceStyle, decorator.deriveVarianceSeed(new RNG(WORLD_SEED), packData), PackRuntime.of(packData.getEngine(), packData));
|
||||
}
|
||||
|
||||
private static IrisDecorator createDecoratorWithZoomedSimplexVariance() {
|
||||
|
||||
+52
-13
@@ -1,6 +1,9 @@
|
||||
package art.arcane.iris.generation.decoration;
|
||||
|
||||
import art.arcane.iris.generation.biome.IrisBiome;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.generation.runtime.SeedManager;
|
||||
import art.arcane.iris.generation.block.IrisBlockData;
|
||||
import art.arcane.iris.generation.block.VectorMap;
|
||||
import art.arcane.iris.structure.object.IrisObject;
|
||||
@@ -24,6 +27,7 @@ import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.mockStatic;
|
||||
@@ -163,17 +167,52 @@ public class IrisDepositTuningTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clumpCachesAreScopedByWorldSeedAndSize() {
|
||||
IrisDepositGenerator.ClumpCacheKey firstWorld =
|
||||
new IrisDepositGenerator.ClumpCacheKey(41L, 4, 8);
|
||||
IrisDepositGenerator.ClumpCacheKey secondWorld =
|
||||
new IrisDepositGenerator.ClumpCacheKey(42L, 4, 8);
|
||||
IrisDepositGenerator.ClumpCacheKey largerVein =
|
||||
new IrisDepositGenerator.ClumpCacheKey(41L, 8, 16);
|
||||
public void clumpVariantsAreScopedByWorldSeedAndSize() {
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisDepositGenerator generator = paletteGenerator(data).setMinSize(4).setMaxSize(8);
|
||||
DepositRuntime firstWorld = PackRuntime.forEngine(engineWithDepositSeed(41L), data).deposit(generator);
|
||||
DepositRuntime secondWorld = PackRuntime.forEngine(engineWithDepositSeed(42L), data).deposit(generator);
|
||||
DepositRuntime sameSeedWorld = PackRuntime.forEngine(engineWithDepositSeed(41L), data).deposit(generator);
|
||||
|
||||
assertNotEquals(firstWorld, secondWorld);
|
||||
assertNotEquals(firstWorld, largerVein);
|
||||
assertEquals(firstWorld, new IrisDepositGenerator.ClumpCacheKey(41L, 4, 8));
|
||||
assertSame(firstWorld.clumps(), firstWorld.clumps());
|
||||
assertSame(firstWorld.scaledClumps(4, 8), firstWorld.scaledClumps(4, 8));
|
||||
assertEquals(blocks(firstWorld.clumps()), blocks(sameSeedWorld.clumps()));
|
||||
assertNotEquals(blocks(firstWorld.clumps()), blocks(secondWorld.clumps()));
|
||||
assertNotEquals(blocks(firstWorld.scaledClumps(4, 8)), blocks(firstWorld.scaledClumps(8, 16)));
|
||||
assertNotEquals(blocks(firstWorld.clumps()), blocks(firstWorld.scaledClumps(4, 8)));
|
||||
}
|
||||
|
||||
private static IrisDepositGenerator paletteGenerator(IrisData data) {
|
||||
IrisDepositGenerator generator = new IrisDepositGenerator();
|
||||
for (String key : new String[]{"minecraft:iron_ore", "minecraft:gold_ore", "minecraft:copper_ore"}) {
|
||||
IrisBlockData block = mock(IrisBlockData.class);
|
||||
NativeBlockState state = mock(NativeBlockState.class);
|
||||
when(block.getBlockData(data)).thenReturn(state);
|
||||
when(state.key()).thenReturn(key);
|
||||
generator.getPalette().add(block);
|
||||
}
|
||||
return generator;
|
||||
}
|
||||
|
||||
private static Engine engineWithDepositSeed(long depositSeed) {
|
||||
SeedManager seeds = mock(SeedManager.class);
|
||||
when(seeds.getDeposit()).thenReturn(depositSeed);
|
||||
Engine engine = mock(Engine.class);
|
||||
when(engine.getSeedManager()).thenReturn(seeds);
|
||||
return engine;
|
||||
}
|
||||
|
||||
private static List<String> blocks(KList<IrisObject> clumps) {
|
||||
List<String> blocks = new ArrayList<>();
|
||||
for (IrisObject clump : clumps) {
|
||||
VectorMap<NativeBlockState>.Cursor cursor = clump.getBlocks().cursor();
|
||||
while (cursor.next()) {
|
||||
blocks.add(cursor.key().getBlockX() + "," + cursor.key().getBlockY() + ","
|
||||
+ cursor.key().getBlockZ() + "=" + cursor.value().key());
|
||||
}
|
||||
blocks.add("|");
|
||||
}
|
||||
return blocks;
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -237,7 +276,7 @@ public class IrisDepositTuningTest {
|
||||
generator.setMinSize(size).setMaxSize(size);
|
||||
for (long seed = 0; seed < 300; seed++) {
|
||||
RNG built = new RNG(seed);
|
||||
IrisObject clump = generator.getClump(null, built, data);
|
||||
IrisObject clump = generator.getClump(PackRuntime.standalone(data), built);
|
||||
RNG sampled = new RNG(seed);
|
||||
IrisDepositGenerator.ClumpFootprint footprint = generator.sampleClumpFootprint(sampled, data);
|
||||
assertNotNull(footprint);
|
||||
@@ -269,7 +308,7 @@ public class IrisDepositTuningTest {
|
||||
generator.setMinSize(size).setMaxSize(size);
|
||||
for (long seed = 0; seed < 300; seed++) {
|
||||
RNG built = new RNG(seed);
|
||||
IrisObject clump = generator.getClump(null, built, data);
|
||||
IrisObject clump = generator.getClump(PackRuntime.standalone(data), built);
|
||||
long expectedNext = built.nextLong();
|
||||
List<String> expected = new ArrayList<>();
|
||||
VectorMap<NativeBlockState>.Cursor cursor = clump.getBlocks().cursor();
|
||||
@@ -325,7 +364,7 @@ public class IrisDepositTuningTest {
|
||||
for (int size : new int[]{0, 1, 3, 4, 9, 17, 25, 64}) {
|
||||
generator.setMinSize(size).setMaxSize(size);
|
||||
for (long seed = 0; seed < 300; seed++) {
|
||||
IrisObject clump = generator.getClump(null, new RNG(seed), data);
|
||||
IrisObject clump = generator.getClump(PackRuntime.standalone(data), new RNG(seed));
|
||||
List<String> expected = new ArrayList<>();
|
||||
VectorMap<NativeBlockState>.Cursor cursor = clump.getBlocks().cursor();
|
||||
while (cursor.next()) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package art.arcane.iris.generation.decoration;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.generation.block.IrisBlockData;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.testsupport.KeyedBlockState;
|
||||
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.generation.noise.NoiseStyle;
|
||||
@@ -48,7 +48,7 @@ public class IrisOreBandsTest {
|
||||
}
|
||||
for (int x = -3; x <= 3; x++) {
|
||||
assertSame("trial " + trial + " y " + y + " x " + x,
|
||||
scan(ores, x, y, 5 - x), bands.generate(x, y, 5 - x, RNG_SOURCE, null, null));
|
||||
scan(ores, x, y, 5 - x), generate(bands, x, y, 5 - x));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -71,7 +71,7 @@ public class IrisOreBandsTest {
|
||||
IrisGeneratorStyle style = new IrisGeneratorStyle(NoiseStyle.FLAT).setZoom(2.5D).setExponent(1.3D)
|
||||
.setFracture(new IrisGeneratorStyle(NoiseStyle.SIMPLEX).setMultiplier(9D));
|
||||
flat.setPalette(palette).setChanceStyle(style).setRange(new IrisRange(0, 100));
|
||||
CNG reference = style.create(RNG_SOURCE, null);
|
||||
CNG reference = style.create(RNG_SOURCE, PackRuntime.standalone(null));
|
||||
for (double threshold : new double[]{0.1D, 0.5D, 0.99D, 1D}) {
|
||||
flat.setThreshold(threshold);
|
||||
for (int index = 0; index < 100; index++) {
|
||||
@@ -79,14 +79,18 @@ public class IrisOreBandsTest {
|
||||
int y = index % 101;
|
||||
int z = 400 - index * 11;
|
||||
NativeBlockState expected = reference.noise(x, y, z) > threshold ? null : ore;
|
||||
assertSame(expected, flat.generate(x, y, z, RNG_SOURCE, null));
|
||||
assertSame(expected, flat.generate(x, y, z, RNG_SOURCE, PackRuntime.standalone(null)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static NativeBlockState generate(IrisOreBands bands, int x, int y, int z) {
|
||||
return PackRuntime.standalone(null).oreBands(bands, RNG_SOURCE.getSeed()).generate(x, y, z, RNG_SOURCE);
|
||||
}
|
||||
|
||||
private static NativeBlockState scan(KList<IrisOreGenerator> ores, int x, int y, int z) {
|
||||
for (IrisOreGenerator ore : ores) {
|
||||
NativeBlockState state = ore.generate(x, y, z, RNG_SOURCE, null);
|
||||
NativeBlockState state = ore.generate(x, y, z, RNG_SOURCE, PackRuntime.standalone(null));
|
||||
if (state != null) {
|
||||
return state;
|
||||
}
|
||||
@@ -110,10 +114,10 @@ public class IrisOreBandsTest {
|
||||
ores.add(generator(1D, 57D, 1D, 2L));
|
||||
ores.add(generator(58D, 58D, 1D, 3L));
|
||||
IrisOreBands bands = IrisOreBands.of(ores);
|
||||
assertSame(scan(ores, 0, 0, 0), bands.generate(0, 0, 0, RNG_SOURCE, null, null));
|
||||
assertSame(scan(ores, 0, 30, 0), bands.generate(0, 30, 0, RNG_SOURCE, null, null));
|
||||
assertSame(scan(ores, 0, 58, 0), bands.generate(0, 58, 0, RNG_SOURCE, null, null));
|
||||
assertNull(bands.contains(59) ? bands.generate(0, 59, 0, RNG_SOURCE, null, null) : null);
|
||||
assertSame(scan(ores, 0, 0, 0), generate(bands, 0, 0, 0));
|
||||
assertSame(scan(ores, 0, 30, 0), generate(bands, 0, 30, 0));
|
||||
assertSame(scan(ores, 0, 58, 0), generate(bands, 0, 58, 0));
|
||||
assertNull(bands.contains(59) ? generate(bands, 0, 59, 0) : null);
|
||||
}
|
||||
private static final class FixedPalette extends IrisMaterialPalette {
|
||||
private final NativeBlockState state;
|
||||
@@ -124,7 +128,7 @@ public class IrisOreBandsTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeBlockState get(RNG rng, double x, double y, double z, IrisData data) {
|
||||
public NativeBlockState get(RNG rng, double x, double y, double z, PackRuntime runtime) {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
@@ -137,7 +141,7 @@ public class IrisOreBandsTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CNG create(RNG rng, IrisData data) {
|
||||
public CNG create(RNG rng, PackRuntime runtime) {
|
||||
return chance;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.generation.decoration;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.generation.block.IrisBlockData;
|
||||
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.generation.terrain.IrisMaterialPalette;
|
||||
@@ -25,7 +26,7 @@ public class IrisOreGeneratorTest {
|
||||
Fixture fixture = new Fixture(0.0);
|
||||
fixture.generator.setThreshold(0.0);
|
||||
|
||||
assertNull(fixture.generator.generate(2, 40, 3, fixture.rng, null));
|
||||
assertNull(fixture.generator.generate(2, 40, 3, fixture.rng, PackRuntime.standalone(null)));
|
||||
verifyNoInteractions(fixture.noise, fixture.style);
|
||||
}
|
||||
|
||||
@@ -34,12 +35,12 @@ public class IrisOreGeneratorTest {
|
||||
Fixture fixture = new Fixture(0.5);
|
||||
fixture.generator.setThreshold(0.5);
|
||||
|
||||
assertSame(fixture.ore, fixture.generator.generate(2, 30, 3, fixture.rng, null));
|
||||
assertSame(fixture.ore, fixture.generator.generate(2, 80, 3, fixture.rng, null));
|
||||
assertNull(fixture.generator.generate(2, 29, 3, fixture.rng, null));
|
||||
assertNull(fixture.generator.generate(2, 81, 3, fixture.rng, null));
|
||||
assertSame(fixture.ore, fixture.generator.generate(2, 30, 3, fixture.rng, PackRuntime.standalone(null)));
|
||||
assertSame(fixture.ore, fixture.generator.generate(2, 80, 3, fixture.rng, PackRuntime.standalone(null)));
|
||||
assertNull(fixture.generator.generate(2, 29, 3, fixture.rng, PackRuntime.standalone(null)));
|
||||
assertNull(fixture.generator.generate(2, 81, 3, fixture.rng, PackRuntime.standalone(null)));
|
||||
fixture.generator.setThreshold(0.49);
|
||||
assertNull(fixture.generator.generate(2, 40, 3, fixture.rng, null));
|
||||
assertNull(fixture.generator.generate(2, 40, 3, fixture.rng, PackRuntime.standalone(null)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -47,7 +48,7 @@ public class IrisOreGeneratorTest {
|
||||
Fixture fixture = new Fixture(1.0);
|
||||
fixture.generator.setThreshold(1.0);
|
||||
|
||||
assertSame(fixture.ore, fixture.generator.generate(2, 40, 3, fixture.rng, null));
|
||||
assertSame(fixture.ore, fixture.generator.generate(2, 40, 3, fixture.rng, PackRuntime.standalone(null)));
|
||||
}
|
||||
|
||||
private static final class Fixture {
|
||||
@@ -60,9 +61,9 @@ public class IrisOreGeneratorTest {
|
||||
private Fixture(double sample) {
|
||||
IrisMaterialPalette palette = mock(IrisMaterialPalette.class);
|
||||
when(palette.getPalette()).thenReturn(new KList<>(mock(IrisBlockData.class)));
|
||||
when(palette.get(any(), anyDouble(), anyDouble(), anyDouble(), isNull())).thenReturn(ore);
|
||||
when(palette.get(any(), anyDouble(), anyDouble(), anyDouble(), any(PackRuntime.class))).thenReturn(ore);
|
||||
when(noise.noise(anyDouble(), anyDouble(), anyDouble())).thenReturn(sample);
|
||||
when(style.create(any(), isNull())).thenReturn(noise);
|
||||
when(style.create(any(), any(PackRuntime.class))).thenReturn(noise);
|
||||
generator.setPalette(palette);
|
||||
generator.setChanceStyle(style);
|
||||
}
|
||||
|
||||
+3
-2
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.generation.decoration;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.generation.noise.NoiseStyle;
|
||||
import art.arcane.iris.generation.terrain.IrisMaterialPalette;
|
||||
@@ -36,7 +37,7 @@ public class IrisOreSeedCohesionTest {
|
||||
for (int i = SEEDS.length - 1; i >= 0; i--) {
|
||||
IrisOreGenerator cold = generator();
|
||||
long[] expected = sample(cold, new RNG(SEEDS[i]), data, false);
|
||||
shared.warm(new RNG(SEEDS[(i + 1) % SEEDS.length]), data);
|
||||
shared.warm(new RNG(SEEDS[(i + 1) % SEEDS.length]), PackRuntime.of(data.getEngine(), data));
|
||||
assertArrayEquals(expected, sample(shared, new RNG(SEEDS[i]), data, true));
|
||||
RNG consumed = new RNG(SEEDS[i]);
|
||||
for (int draw = 0; draw < 128; draw++) {
|
||||
@@ -93,7 +94,7 @@ public class IrisOreSeedCohesionTest {
|
||||
for (int index = 0; index < SAMPLES; index++) {
|
||||
int sample = reverse ? SAMPLES - index - 1 : index;
|
||||
NativeBlockState block = generator.generate(sample * 13 - 901,
|
||||
sample % 257, sample * 7 - 713, rng, data);
|
||||
sample % 257, sample * 7 - 713, rng, PackRuntime.of(data.getEngine(), data));
|
||||
output[sample] = block == null ? 0L : block.key().hashCode();
|
||||
}
|
||||
return output;
|
||||
|
||||
+6
-1
@@ -1,6 +1,8 @@
|
||||
package art.arcane.iris.generation.decoration;
|
||||
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.testsupport.MockPackData;
|
||||
import art.arcane.iris.generation.biome.IrisBiome;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
import art.arcane.volmlib.util.hunk.Hunk;
|
||||
@@ -121,10 +123,13 @@ public class IrisSeaDecoratorBoundsTest {
|
||||
|
||||
private Fixture(int height, boolean surface) {
|
||||
when(engine.getHeight()).thenReturn(height);
|
||||
IrisData data = MockPackData.create();
|
||||
when(engine.getPackRuntime()).thenReturn(null);
|
||||
when(engine.getData()).thenReturn(data);
|
||||
output = Hunk.newArrayHunk(1, height, 1);
|
||||
IrisDecorationPart part = surface ? IrisDecorationPart.SEA_SURFACE : IrisDecorationPart.SEA_FLOOR;
|
||||
when(biome.getDecoratorBucket(part)).thenReturn(new IrisDecorator[]{decorator});
|
||||
when(decorator.passesChanceGate(any(), anyDouble(), anyDouble(), any())).thenReturn(true);
|
||||
when(decorator.passesChanceGate(any(), anyDouble(), anyDouble(), any(DecoratorRuntime.class))).thenReturn(true);
|
||||
when(decorator.getBlockData100(any(), any(), anyDouble(), anyDouble(), anyDouble(), any())).thenReturn(body);
|
||||
when(decorator.getBlockDataForTop(any(), any(), anyDouble(), anyDouble(), anyDouble(), any())).thenReturn(top);
|
||||
when(decorator.getTopThreshold()).thenReturn(1D);
|
||||
|
||||
+11
-10
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.generation.decoration;
|
||||
|
||||
import art.arcane.iris.testsupport.MockPackData;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
import art.arcane.iris.generation.mantle.EngineMantle;
|
||||
@@ -70,9 +71,9 @@ public class IrisShoreLineDecoratorTest {
|
||||
output, fixture.biome, FLUID_HEIGHT, output.getHeight());
|
||||
|
||||
assertSame(targetAir, output.get(0, FLUID_HEIGHT + 1, 0));
|
||||
verify(fixture.decorator).passesChanceGate(any(), anyDouble(), anyDouble(), eq(fixture.data));
|
||||
verify(fixture.decorator).passesChanceGate(any(), anyDouble(), anyDouble(), MockPackData.decoratorRuntimeOf(fixture.data));
|
||||
verify(fixture.decorator, never()).getBlockData100(
|
||||
eq(fixture.biome), any(), anyDouble(), anyDouble(), anyDouble(), eq(fixture.data));
|
||||
eq(fixture.biome), any(), anyDouble(), anyDouble(), anyDouble(), MockPackData.runtimeOf(fixture.data));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -88,7 +89,7 @@ public class IrisShoreLineDecoratorTest {
|
||||
|
||||
assertSame(targetAir, output.get(0, FLUID_HEIGHT + 1, 0));
|
||||
verify(fixture.decorator, never()).getBlockData100(
|
||||
eq(fixture.biome), any(), anyDouble(), anyDouble(), anyDouble(), eq(fixture.data));
|
||||
eq(fixture.biome), any(), anyDouble(), anyDouble(), anyDouble(), MockPackData.runtimeOf(fixture.data));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -199,13 +200,13 @@ public class IrisShoreLineDecoratorTest {
|
||||
when(fixture.decorator.isStacking()).thenReturn(true);
|
||||
when(fixture.decorator.isScaleStack()).thenReturn(false);
|
||||
when(fixture.decorator.getStackMax()).thenReturn(2);
|
||||
when(fixture.decorator.getHeight(any(), anyDouble(), anyDouble(), eq(fixture.data))).thenReturn(2);
|
||||
when(fixture.decorator.getHeight(any(), anyDouble(), anyDouble(), MockPackData.runtimeOf(fixture.data))).thenReturn(2);
|
||||
when(fixture.decorator.getTopThreshold()).thenReturn(1D);
|
||||
when(fixture.decorator.getBlockDataArray(fixture.data)).thenReturn(new NativeBlockState[0]);
|
||||
when(fixture.decorator.getBlockDataTopsArray(fixture.data))
|
||||
.thenReturn(new NativeBlockState[]{waterloggedTop});
|
||||
when(fixture.decorator.getBlockDataForTop(
|
||||
eq(fixture.biome), any(), anyDouble(), anyDouble(), anyDouble(), eq(fixture.data)))
|
||||
eq(fixture.biome), any(), anyDouble(), anyDouble(), anyDouble(), MockPackData.runtimeOf(fixture.data)))
|
||||
.thenReturn(waterloggedTop);
|
||||
|
||||
Hunk<NativeBlockState> output = Hunk.newArrayHunk(1, FLUID_HEIGHT + 3, 1);
|
||||
@@ -239,7 +240,7 @@ public class IrisShoreLineDecoratorTest {
|
||||
SeedManager seedManager = mock(SeedManager.class);
|
||||
IrisDimension dimension = mock(IrisDimension.class);
|
||||
IrisComplex complex = mock(IrisComplex.class);
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisData data = MockPackData.create();
|
||||
IrisBiome biome = mock(IrisBiome.class);
|
||||
IrisDecorator decorator = mock(IrisDecorator.class);
|
||||
IrisSlopeClip slope = mock(IrisSlopeClip.class);
|
||||
@@ -263,11 +264,11 @@ public class IrisShoreLineDecoratorTest {
|
||||
when(engine.getData()).thenReturn(data);
|
||||
when(biome.getDecoratorBucket(IrisDecorationPart.SHORE_LINE))
|
||||
.thenReturn(new IrisDecorator[]{decorator});
|
||||
when(decorator.passesChanceGate(any(), anyDouble(), anyDouble(), eq(data))).thenReturn(true);
|
||||
when(decorator.passesChanceGate(any(), anyDouble(), anyDouble(), MockPackData.decoratorRuntimeOf(data))).thenReturn(true);
|
||||
when(decorator.isForcePlace()).thenReturn(forcePlace);
|
||||
when(decorator.getSlopeCondition()).thenReturn(slope);
|
||||
when(slope.isDefault()).thenReturn(true);
|
||||
when(decorator.getBlockData100(eq(biome), any(), anyDouble(), anyDouble(), anyDouble(), eq(data)))
|
||||
when(decorator.getBlockData100(eq(biome), any(), anyDouble(), anyDouble(), anyDouble(), MockPackData.runtimeOf(data)))
|
||||
.thenReturn(decorant);
|
||||
|
||||
return new Fixture(new IrisShoreLineDecorator(engine), data, biome, decorator, decorant);
|
||||
@@ -282,10 +283,10 @@ public class IrisShoreLineDecoratorTest {
|
||||
when(fixture.decorator.isStacking()).thenReturn(true);
|
||||
when(fixture.decorator.isScaleStack()).thenReturn(true);
|
||||
when(fixture.decorator.getAbsoluteMaxStack()).thenReturn(3);
|
||||
when(fixture.decorator.getHeight(any(), anyDouble(), anyDouble(), eq(fixture.data))).thenReturn(100);
|
||||
when(fixture.decorator.getHeight(any(), anyDouble(), anyDouble(), MockPackData.runtimeOf(fixture.data))).thenReturn(100);
|
||||
when(fixture.decorator.getTopThreshold()).thenReturn(0.9D);
|
||||
when(fixture.decorator.getBlockDataForTop(eq(fixture.biome), any(), anyDouble(), anyDouble(),
|
||||
anyDouble(), eq(fixture.data))).thenReturn(top);
|
||||
anyDouble(), MockPackData.runtimeOf(fixture.data))).thenReturn(top);
|
||||
Hunk<NativeBlockState> output = Hunk.newArrayHunk(1, 64, 1);
|
||||
for (int y = FLUID_HEIGHT + 1; y < output.getHeight(); y++) {
|
||||
output.set(0, y, 0, airState());
|
||||
|
||||
+5
-4
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.generation.decoration;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.hydrology.raster.WaterRole;
|
||||
@@ -122,13 +123,13 @@ public class IrisSugarCanePlacementTest {
|
||||
int world = -16 + local;
|
||||
switch (placement) {
|
||||
case FLOATING_SINGLE -> DecoratorCore.placeFloatingSimple(decorator, local, local, world, world,
|
||||
3, 4, output, new RNG(1L), null, mantle);
|
||||
3, 4, output, new RNG(1L), PackRuntime.standalone(null), mantle);
|
||||
case FLOATING_STACK -> DecoratorCore.placeFloatingStacked(decorator, local, local, world, world,
|
||||
3, 4, output, new RNG(1L), null, mantle);
|
||||
3, 4, output, new RNG(1L), PackRuntime.standalone(null), mantle);
|
||||
case CEILING_SINGLE -> DecoratorCore.placeSingleAt(decorator, local, local, world, 4, world,
|
||||
output, new RNG(1L), null, false, mantle);
|
||||
output, new RNG(1L), PackRuntime.standalone(null), false, mantle);
|
||||
case CEILING_STACK -> DecoratorCore.placeStackDown(decorator, local, local, world, world,
|
||||
4, 0, output, new RNG(1L), null, 2, new DecoratorCore.PlaceOpts(), mantle);
|
||||
4, 0, output, new RNG(1L), PackRuntime.standalone(null), 2, new DecoratorCore.PlaceOpts(), mantle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.generation.decoration.formation;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.generation.block.IrisBlockData;
|
||||
import art.arcane.iris.generation.terrain.IrisMaterialPalette;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
@@ -51,7 +52,7 @@ public class FormationBlockResolverTest {
|
||||
long sampleSeed = formation.getSeed() + (expectedPalette == strata ? sampleY * 31L : 0L);
|
||||
RNG fresh = new RNG(sampleSeed);
|
||||
NativeBlockState expected = expectedPalette.get(fresh,
|
||||
position.getBlockX(), sampleY, position.getBlockZ(), null);
|
||||
position.getBlockX(), sampleY, position.getBlockZ(), PackRuntime.forPack(null));
|
||||
assertSame(expected, resolver.resolve(role, position));
|
||||
assertEquals(new RNG(sampleSeed).nextLong(), fresh.nextLong());
|
||||
materials.add(expected.key());
|
||||
|
||||
+2
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.generation.mantle;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.generation.cave.IrisCaveFieldModule;
|
||||
import art.arcane.iris.generation.cave.IrisCaveProfile;
|
||||
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
||||
@@ -154,6 +155,7 @@ public class IrisCaveCarver3DCellKernelTest {
|
||||
IrisDimension dimension = mock(IrisDimension.class, withSettings().stubOnly());
|
||||
SeedManager seedManager = mock(SeedManager.class, withSettings().stubOnly());
|
||||
doReturn(data).when(engine).getData();
|
||||
doReturn(PackRuntime.forEngine(engine, data)).when(engine).getPackRuntime();
|
||||
doReturn(dimension).when(engine).getDimension();
|
||||
doReturn(seedManager).when(engine).getSeedManager();
|
||||
doReturn(CARVE_SEED).when(seedManager).getCarve();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.generation.mantle;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.generation.cave.IrisCaveFieldModule;
|
||||
import art.arcane.iris.generation.cave.IrisCaveProfile;
|
||||
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
||||
@@ -162,6 +163,7 @@ public class IrisCaveCarver3DLatticeTest {
|
||||
IrisDimension dimension = mock(IrisDimension.class, withSettings().stubOnly());
|
||||
SeedManager seedManager = mock(SeedManager.class, withSettings().stubOnly());
|
||||
doReturn(data).when(engine).getData();
|
||||
doReturn(PackRuntime.forEngine(engine, data)).when(engine).getPackRuntime();
|
||||
doReturn(dimension).when(engine).getDimension();
|
||||
doReturn(seedManager).when(engine).getSeedManager();
|
||||
doReturn(CARVE_SEED).when(seedManager).getCarve();
|
||||
|
||||
+7
-4
@@ -1,5 +1,7 @@
|
||||
package art.arcane.iris.generation.mantle;
|
||||
|
||||
import art.arcane.iris.generation.runtime.ThreadSlots;
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.runtime.EngineMetrics;
|
||||
@@ -209,7 +211,7 @@ public class IrisCaveCarver3DNearParityTest {
|
||||
}).when(density).noiseFastSigned3D(anyDouble(), anyDouble(), anyDouble());
|
||||
IrisGeneratorStyle style = mock(IrisGeneratorStyle.class, withSettings().stubOnly());
|
||||
doReturn("density_expression").when(style).getExpression();
|
||||
doReturn(density).when(style).create(any(RNG.class), any(IrisData.class));
|
||||
doReturn(density).when(style).create(any(RNG.class), any());
|
||||
IrisCaveProfile profile = createProfile(false, false).setBaseDensityStyle(style)
|
||||
.setDetailWeight(0D).setAllowFluid(false)
|
||||
.setDensityThreshold(new IrisStyledRange(0.15D, 0.15D, new IrisGeneratorStyle(NoiseStyle.FLAT)));
|
||||
@@ -377,7 +379,7 @@ public class IrisCaveCarver3DNearParityTest {
|
||||
}
|
||||
Field scratchField = IrisCaveCarver3D.class.getDeclaredField("scratchCache");
|
||||
scratchField.setAccessible(true);
|
||||
ThreadLocal<?> scratchCache = (ThreadLocal<?>) scratchField.get(carver);
|
||||
ThreadSlots<?> scratchCache = (ThreadSlots<?>) scratchField.get(carver);
|
||||
CaveCarveScratch scratch = (CaveCarveScratch) scratchCache.get();
|
||||
assertTrue(scratch.sectionMatter.length > 0);
|
||||
for (Matter matter : scratch.sectionMatter) {
|
||||
@@ -1304,7 +1306,7 @@ public class IrisCaveCarver3DNearParityTest {
|
||||
.noiseFastSigned3D(anyDouble(), anyDouble(), anyDouble());
|
||||
IrisGeneratorStyle style = mock(IrisGeneratorStyle.class, withSettings().stubOnly());
|
||||
doReturn("density_expression").when(style).getExpression();
|
||||
doReturn(density).when(style).create(any(RNG.class), any(IrisData.class));
|
||||
doReturn(density).when(style).create(any(RNG.class), any());
|
||||
AtomicInteger lookups = new AtomicInteger();
|
||||
CaveDensityGrid grid = countingGrid(4, lookups);
|
||||
IrisCaveCarver3D carver = new IrisCaveCarver3D(engine,
|
||||
@@ -1470,7 +1472,7 @@ public class IrisCaveCarver3DNearParityTest {
|
||||
continue;
|
||||
}
|
||||
|
||||
passThreshold[columnIndex] = profile.getDensityThreshold().get(thresholdRng, x, z, data) - profile.getThresholdBias();
|
||||
passThreshold[columnIndex] = profile.getDensityThreshold().get(thresholdRng, x, z, PackRuntime.standalone(data)) - profile.getThresholdBias();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1642,6 +1644,7 @@ public class IrisCaveCarver3DNearParityTest {
|
||||
IrisWorld world = IrisWorld.builder().minHeight(0).maxHeight(worldHeight).build();
|
||||
|
||||
doReturn(data).when(engine).getData();
|
||||
doReturn(PackRuntime.forEngine(engine, data)).when(engine).getPackRuntime();
|
||||
doReturn(dimension).when(engine).getDimension();
|
||||
doReturn(seedManager).when(engine).getSeedManager();
|
||||
doReturn(CARVE_SEED).when(seedManager).getCarve();
|
||||
|
||||
+7
-7
@@ -1,6 +1,6 @@
|
||||
package art.arcane.iris.generation.mantle;
|
||||
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.generation.terrain.IrisMaterialPalette;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
import art.arcane.volmlib.util.matter.MatterCavern;
|
||||
@@ -20,15 +20,15 @@ public class IrisStructureFoundationWriteTest {
|
||||
MantleWriter writer = mock(MantleWriter.class);
|
||||
IrisMaterialPalette palette = mock(IrisMaterialPalette.class);
|
||||
RNG rng = new RNG(1337L);
|
||||
IrisData data = mock(IrisData.class);
|
||||
PackRuntime runtime = PackRuntime.standalone(null);
|
||||
NativeBlockState deepslateBricks = mock(NativeBlockState.class);
|
||||
when(palette.get(rng, 12, -247, -18, data)).thenReturn(deepslateBricks);
|
||||
when(palette.get(rng, 12, -247, -18, runtime)).thenReturn(deepslateBricks);
|
||||
|
||||
IrisStructureComponent.writeFoundationSupport(
|
||||
writer, palette, rng, data, 12, 9, -18, -256);
|
||||
writer, palette, rng, runtime, 12, 9, -18, -256);
|
||||
|
||||
InOrder order = inOrder(palette, writer);
|
||||
order.verify(palette).get(rng, 12, -247, -18, data);
|
||||
order.verify(palette).get(rng, 12, -247, -18, runtime);
|
||||
order.verify(writer).clearData(12, 9, -18, MatterCavern.class);
|
||||
order.verify(writer).set(12, 9, -18, deepslateBricks);
|
||||
}
|
||||
@@ -38,11 +38,11 @@ public class IrisStructureFoundationWriteTest {
|
||||
MantleWriter writer = mock(MantleWriter.class);
|
||||
IrisMaterialPalette palette = mock(IrisMaterialPalette.class);
|
||||
RNG rng = new RNG(1337L);
|
||||
IrisData data = mock(IrisData.class);
|
||||
PackRuntime runtime = PackRuntime.standalone(null);
|
||||
|
||||
try {
|
||||
IrisStructureComponent.writeFoundationSupport(
|
||||
writer, palette, rng, data, 12, 9, -18, -256);
|
||||
writer, palette, rng, runtime, 12, 9, -18, -256);
|
||||
} catch (IllegalStateException error) {
|
||||
assertTrue(error.getMessage().contains("12,-247,-18"));
|
||||
verifyNoInteractions(writer);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.generation.mantle;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.generation.terrain.transform.IrisTerrainTransform;
|
||||
import art.arcane.iris.generation.biome.IrisBiome;
|
||||
import art.arcane.iris.generation.hydrology.cave.HydrologyCaveAction;
|
||||
@@ -366,6 +367,7 @@ public class MantleCarvedTerrainTest {
|
||||
case "getWorld" -> world;
|
||||
case "getPlatformHooks" -> hooks;
|
||||
case "getData" -> null;
|
||||
case "getPackRuntime" -> null;
|
||||
default -> InvocationHandler.invokeDefault(proxy, method, arguments);
|
||||
});
|
||||
}
|
||||
|
||||
+2
-1
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.generation.mantle;
|
||||
|
||||
import art.arcane.iris.testsupport.MockPackData;
|
||||
import art.arcane.iris.generation.biome.FloatingIslandBoundarySampler;
|
||||
import art.arcane.iris.generation.biome.IrisBiome;
|
||||
import art.arcane.iris.generation.biome.IrisFloatingChildBiomes;
|
||||
@@ -201,7 +202,7 @@ public class MantleFloatingObjectComponentEmptyTest {
|
||||
private Fixture(IrisBiome biome) {
|
||||
biomes = mock(ResourceLoader.class);
|
||||
ResourceLoader<IrisObject> objects = mock(ResourceLoader.class);
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisData data = MockPackData.create();
|
||||
when(data.getBiomeLoader()).thenReturn(biomes);
|
||||
when(data.getObjectLoader()).thenReturn(objects);
|
||||
when(dimension.isUseMantle()).thenReturn(true);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.generation.mantle;
|
||||
|
||||
import art.arcane.iris.testsupport.MockPackData;
|
||||
import art.arcane.iris.generation.block.TileData;
|
||||
import art.arcane.iris.generation.decoration.IrisStiltSettings;
|
||||
import art.arcane.iris.generation.decoration.IrisVacuumSettings;
|
||||
@@ -78,9 +79,9 @@ public class PlacementReachTest {
|
||||
when(engine.getHeight()).thenReturn(256);
|
||||
when(engine.getMinHeight()).thenReturn(0);
|
||||
when(engine.getComplex()).thenReturn(complex);
|
||||
data = mock(IrisData.class, withSettings().stubOnly());
|
||||
data = MockPackData.stubOnly();
|
||||
when(data.getEngine()).thenReturn(engine);
|
||||
objectData = mock(IrisData.class, withSettings().stubOnly());
|
||||
objectData = MockPackData.stubOnly();
|
||||
}
|
||||
|
||||
@After
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.generation.noise;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -8,6 +9,8 @@ import java.util.SplittableRandom;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class GeneratorProgramParityTest {
|
||||
private final PackRuntime runtime = PackRuntime.standalone(null);
|
||||
|
||||
private static final NoiseStyle[] STYLES = {
|
||||
NoiseStyle.SIMPLEX, NoiseStyle.PERLIN, NoiseStyle.IRIS, NoiseStyle.IRIS_HALF, NoiseStyle.FRACTAL_SMOKE,
|
||||
NoiseStyle.FRACTAL_WATER, NoiseStyle.CLOVER, NoiseStyle.CELLULAR, NoiseStyle.NOWHERE,
|
||||
@@ -24,7 +27,7 @@ public class GeneratorProgramParityTest {
|
||||
IrisGenerator scalar = generator(new SplittableRandom(shapeSeed));
|
||||
IrisGenerator batch = generator(new SplittableRandom(shapeSeed));
|
||||
long superSeed = random.nextLong();
|
||||
GeneratorProgram program = batch.compileProgram(superSeed);
|
||||
GeneratorProgram program = batch.compileProgram(runtime, superSeed);
|
||||
int count = 1 + random.nextInt(600);
|
||||
double[] xs = new double[count];
|
||||
double[] zs = new double[count];
|
||||
@@ -33,7 +36,7 @@ public class GeneratorProgramParityTest {
|
||||
program.heights(scratch, xs, zs, count, out);
|
||||
for (int index = 0; index < count; index++) {
|
||||
assertEquals("generator " + generatorIndex + " point " + xs[index] + "," + zs[index],
|
||||
Double.doubleToRawLongBits(scalar.getHeight(xs[index], zs[index], superSeed)),
|
||||
Double.doubleToRawLongBits(scalar.getHeight(runtime, xs[index], zs[index], superSeed)),
|
||||
Double.doubleToRawLongBits(out[index]));
|
||||
}
|
||||
}
|
||||
@@ -48,12 +51,12 @@ public class GeneratorProgramParityTest {
|
||||
IrisGenerator scalar = generator(new SplittableRandom(shapeSeed));
|
||||
IrisGenerator compiled = generator(new SplittableRandom(shapeSeed));
|
||||
long superSeed = random.nextLong();
|
||||
GeneratorProgram program = compiled.compileProgram(superSeed);
|
||||
GeneratorProgram program = compiled.compileProgram(runtime, superSeed);
|
||||
for (int sample = 0; sample < 400; sample++) {
|
||||
double x = coordinate(random);
|
||||
double z = random.nextInt(5) == 0 ? x : coordinate(random);
|
||||
assertEquals("generator " + generatorIndex + " point " + x + "," + z,
|
||||
Double.doubleToRawLongBits(scalar.getHeight(x, z, superSeed)),
|
||||
Double.doubleToRawLongBits(scalar.getHeight(runtime, x, z, superSeed)),
|
||||
Double.doubleToRawLongBits(program.height(scratch, x, z)));
|
||||
}
|
||||
}
|
||||
@@ -71,7 +74,7 @@ public class GeneratorProgramParityTest {
|
||||
IrisGenerator scalar = generator(new SplittableRandom(shapeSeed));
|
||||
IrisGenerator batch = generator(new SplittableRandom(shapeSeed));
|
||||
long superSeed = random.nextLong();
|
||||
GeneratorProgram program = batch.compileProgram(superSeed);
|
||||
GeneratorProgram program = batch.compileProgram(runtime, superSeed);
|
||||
for (int chunk = 0; chunk < 4; chunk++) {
|
||||
int originX = random.nextInt(-200_000, 200_000) << 4;
|
||||
int originZ = random.nextInt(-200_000, 200_000) << 4;
|
||||
@@ -81,7 +84,7 @@ public class GeneratorProgramParityTest {
|
||||
}
|
||||
program.heights(scratch, xs, zs, 256, out);
|
||||
for (int index = 0; index < 256; index++) {
|
||||
assertEquals(Double.doubleToRawLongBits(scalar.getHeight(xs[index], zs[index], superSeed)),
|
||||
assertEquals(Double.doubleToRawLongBits(scalar.getHeight(runtime, xs[index], zs[index], superSeed)),
|
||||
Double.doubleToRawLongBits(out[index]));
|
||||
}
|
||||
}
|
||||
|
||||
+15
-10
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.generation.noise;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import org.junit.Test;
|
||||
@@ -10,17 +11,17 @@ public class IrisExpressionCoordinateTest {
|
||||
@Test
|
||||
public void planarEvaluationBindsHorizontalAxesAndAbsentHeight() {
|
||||
RNG rng = new RNG(17L);
|
||||
assertEquals(23.5D, expression("x").evaluate(rng, 23.5D, -94.75D), 0D);
|
||||
assertEquals(-94.75D, expression("y").evaluate(rng, 23.5D, -94.75D), 0D);
|
||||
assertEquals(-1D, expression("z").evaluate(rng, 23.5D, -94.75D), 0D);
|
||||
assertEquals(23.5D, runtimeOf(expression("x")).evaluate(rng, 23.5D, -94.75D), 0D);
|
||||
assertEquals(-94.75D, runtimeOf(expression("y")).evaluate(rng, 23.5D, -94.75D), 0D);
|
||||
assertEquals(-1D, runtimeOf(expression("z")).evaluate(rng, 23.5D, -94.75D), 0D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void volumetricEvaluationBindsEachAxis() {
|
||||
RNG rng = new RNG(17L);
|
||||
assertEquals(23.5D, expression("x").evaluate(rng, 23.5D, 61D, -94.75D), 0D);
|
||||
assertEquals(61D, expression("y").evaluate(rng, 23.5D, 61D, -94.75D), 0D);
|
||||
assertEquals(-94.75D, expression("z").evaluate(rng, 23.5D, 61D, -94.75D), 0D);
|
||||
assertEquals(23.5D, runtimeOf(expression("x")).evaluate(rng, 23.5D, 61D, -94.75D), 0D);
|
||||
assertEquals(61D, runtimeOf(expression("y")).evaluate(rng, 23.5D, 61D, -94.75D), 0D);
|
||||
assertEquals(-94.75D, runtimeOf(expression("z")).evaluate(rng, 23.5D, 61D, -94.75D), 0D);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -28,16 +29,20 @@ public class IrisExpressionCoordinateTest {
|
||||
IrisExpression expression = expression("value + x + 10 * y + 100 * z")
|
||||
.setVariables(new KList<>(new IrisExpressionLoad().setName("value").setStaticValue(7D)));
|
||||
RNG rng = new RNG(17L);
|
||||
assertEquals(-1017D, expression.evaluate(rng, 23.5D, -94.75D), 0D);
|
||||
assertEquals(-8834.5D, expression.evaluate(rng, 23.5D, 61D, -94.75D), 0D);
|
||||
assertEquals(-1017D, runtimeOf(expression).evaluate(rng, 23.5D, -94.75D), 0D);
|
||||
assertEquals(-8834.5D, runtimeOf(expression).evaluate(rng, 23.5D, 61D, -94.75D), 0D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void expressionStreamsAndNoiseUsePlanarCoordinates() {
|
||||
IrisExpression expression = expression("x + 100 * y");
|
||||
RNG rng = new RNG(17L);
|
||||
assertEquals(-9451.5D, expression.stream(rng).getDouble(23.5D, -94.75D), 0D);
|
||||
assertEquals(-9451.5D, new ExpressionNoise(rng, expression).noise(23.5D, -94.75D), 0D);
|
||||
assertEquals(-9451.5D, runtimeOf(expression).stream(rng).getDouble(23.5D, -94.75D), 0D);
|
||||
assertEquals(-9451.5D, new ExpressionNoise(rng, runtimeOf(expression)).noise(23.5D, -94.75D), 0D);
|
||||
}
|
||||
|
||||
private static ExpressionRuntime runtimeOf(IrisExpression expression) {
|
||||
return PackRuntime.standalone(null).expression(expression);
|
||||
}
|
||||
|
||||
private static IrisExpression expression(String source) {
|
||||
|
||||
+25
-33
@@ -1,68 +1,60 @@
|
||||
package art.arcane.iris.generation.noise;
|
||||
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
import art.arcane.iris.generation.runtime.IrisEngineStreamType;
|
||||
import art.arcane.iris.generation.runtime.IrisEngineValueType;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.volmlib.util.stream.ProceduralStream;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import art.arcane.volmlib.util.stream.ProceduralStream;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class IrisExpressionLoadEngineCacheTest {
|
||||
@Test
|
||||
public void engineValuesAreCachedPerEngineIdentity() {
|
||||
public void engineValuesBelongToTheEngineRuntime() {
|
||||
Engine first = mock(Engine.class);
|
||||
Engine second = mock(Engine.class);
|
||||
when(first.getHeight()).thenReturn(128);
|
||||
when(second.getHeight()).thenReturn(320);
|
||||
AtomicReference<Engine> active = new AtomicReference<>(first);
|
||||
IrisData data = data(active);
|
||||
IrisExpressionLoad load = new IrisExpressionLoad()
|
||||
IrisExpression expression = expression(new IrisExpressionLoad()
|
||||
.setName("height")
|
||||
.setEngineValue(IrisEngineValueType.ENGINE_HEIGHT);
|
||||
.setEngineValue(IrisEngineValueType.ENGINE_HEIGHT));
|
||||
IrisData data = mock(IrisData.class);
|
||||
|
||||
assertEquals(128D, load.getValue(new RNG(1L), data, 0D, 0D), 0D);
|
||||
active.set(second);
|
||||
assertEquals(320D, load.getValue(new RNG(1L), data, 0D, 0D), 0D);
|
||||
assertEquals(128D, PackRuntime.forEngine(first, data).expression(expression).evaluate(new RNG(1L), 0D, 0D), 0D);
|
||||
assertEquals(320D, PackRuntime.forEngine(second, data).expression(expression).evaluate(new RNG(1L), 0D, 0D), 0D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void engineStreamsAreCachedPerEngineIdentity() {
|
||||
Engine first = streamEngine(12D);
|
||||
Engine second = streamEngine(27D);
|
||||
AtomicReference<Engine> active = new AtomicReference<>(first);
|
||||
IrisData data = data(active);
|
||||
IrisExpressionLoad load = new IrisExpressionLoad()
|
||||
public void engineStreamsBelongToTheEngineRuntime() {
|
||||
IrisExpression expression = expression(new IrisExpressionLoad()
|
||||
.setName("height")
|
||||
.setEngineStreamValue(IrisEngineStreamType.HEIGHT);
|
||||
.setEngineStreamValue(IrisEngineStreamType.HEIGHT));
|
||||
IrisData data = mock(IrisData.class);
|
||||
|
||||
assertEquals(12D, load.getValue(new RNG(1L), data, 4D, 8D), 0D);
|
||||
active.set(second);
|
||||
assertEquals(27D, load.getValue(new RNG(1L), data, 4D, 8D), 0D);
|
||||
assertEquals(12D, PackRuntime.forEngine(streamEngine(12D), data).expression(expression)
|
||||
.evaluate(new RNG(1L), 4D, 8D), 0D);
|
||||
assertEquals(27D, PackRuntime.forEngine(streamEngine(27D), data).expression(expression)
|
||||
.evaluate(new RNG(1L), 4D, 8D), 0D);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void engineBackedValueFailsWithoutUnambiguousEngine() {
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisExpressionLoad load = new IrisExpressionLoad()
|
||||
public void engineBackedValueFailsWithoutAnEngine() {
|
||||
IrisExpression expression = expression(new IrisExpressionLoad()
|
||||
.setName("height")
|
||||
.setEngineValue(IrisEngineValueType.ENGINE_HEIGHT);
|
||||
.setEngineValue(IrisEngineValueType.ENGINE_HEIGHT));
|
||||
|
||||
load.getValue(new RNG(1L), data, 0D, 0D);
|
||||
PackRuntime.standalone(mock(IrisData.class)).expression(expression).evaluate(new RNG(1L), 0D, 0D);
|
||||
}
|
||||
|
||||
private IrisData data(AtomicReference<Engine> active) {
|
||||
IrisData data = mock(IrisData.class);
|
||||
when(data.getEngine()).thenAnswer(ignored -> active.get());
|
||||
return data;
|
||||
private static IrisExpression expression(IrisExpressionLoad variable) {
|
||||
return new IrisExpression().setExpression("height").setVariables(new KList<>(variable));
|
||||
}
|
||||
|
||||
private Engine streamEngine(double value) {
|
||||
|
||||
+67
-36
@@ -1,10 +1,12 @@
|
||||
package art.arcane.iris.generation.noise;
|
||||
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.dfsek.paralithic.Expression;
|
||||
import com.dfsek.paralithic.functions.dynamic.Context;
|
||||
import com.dfsek.paralithic.functions.dynamic.DynamicFunction;
|
||||
import com.dfsek.paralithic.node.Statefulness;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -15,6 +17,7 @@ import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
@@ -27,9 +30,8 @@ import static org.mockito.Mockito.mock;
|
||||
public class IrisExpressionScratchTest {
|
||||
@Test
|
||||
public void sequentialPlanarAndVolumetricSamplesReuseTheArgumentArrayAndKeepRngState() {
|
||||
IrisExpression expression = new IrisExpression();
|
||||
Expression compiled = mock(Expression.class);
|
||||
expression.getExpressionCache().aquire(() -> compiled);
|
||||
ExpressionRuntime expression = runtimeOf(parsedAs(new IrisExpression(), compiled));
|
||||
AtomicReference<double[]> first = new AtomicReference<>();
|
||||
doAnswer(invocation -> {
|
||||
double[] arguments = (double[]) invocation.getRawArguments()[1];
|
||||
@@ -51,21 +53,16 @@ public class IrisExpressionScratchTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void recursiveVariableEvaluationKeepsOuterArgumentsBeyondTheRetainedDepth() {
|
||||
AtomicReference<IrisExpression> expression = new AtomicReference<>();
|
||||
IrisExpressionLoad recursive = new IrisExpressionLoad() {
|
||||
@Override
|
||||
public double getValue(RNG rng, IrisData data, double x, double z) {
|
||||
return x <= 0D ? 7D : expression.get().evaluate(rng, x - 1D, z);
|
||||
}
|
||||
}.setName("prior");
|
||||
expression.set(new IrisExpression().setExpression("prior + 17 * x + 31 * y + z")
|
||||
.setVariables(new KList<>(recursive)));
|
||||
public void recursiveEvaluationWithVariablesKeepsOuterArgumentsBeyondTheRetainedDepth() {
|
||||
AtomicReference<ExpressionRuntime> expression = new AtomicReference<>();
|
||||
IrisExpression config = recursive(new IrisExpression().setExpression("prior(x, y) + value + 17 * x + 31 * y + z")
|
||||
.setVariables(new KList<>(new IrisExpressionLoad().setName("value").setStaticValue(-1D))), expression);
|
||||
expression.set(runtimeOf(config));
|
||||
RNG rng = new RNG(78264193L);
|
||||
RNG control = new RNG(78264193L);
|
||||
double expected = 7D;
|
||||
for (int x = 0; x <= 31; x++) {
|
||||
expected = expected + 17D * x + 31D * 3.75D - 1D;
|
||||
expected = expected + 17D * x + 31D * 3.75D - 2D;
|
||||
}
|
||||
|
||||
assertEquals(expected, expression.get().evaluate(rng, 31D, 3.75D), 0D);
|
||||
@@ -75,22 +72,9 @@ public class IrisExpressionScratchTest {
|
||||
|
||||
@Test
|
||||
public void recursiveFunctionEvaluationDoesNotOverwriteTheOuterCoordinates() {
|
||||
AtomicReference<IrisExpression> expression = new AtomicReference<>();
|
||||
IrisExpressionFunction recursive = new IrisExpressionFunction() {
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double eval(Context context, double... coordinates) {
|
||||
RNG rng = ((FunctionContext) context).rng();
|
||||
return coordinates[0] <= 0D ? 7D
|
||||
: expression.get().evaluate(rng, coordinates[0] - 1D, coordinates[1]);
|
||||
}
|
||||
}.setName("prior");
|
||||
expression.set(new IrisExpression().setExpression("prior(x, y) + 17 * x + 31 * y + z")
|
||||
.setFunctions(new KList<>(recursive)));
|
||||
AtomicReference<ExpressionRuntime> expression = new AtomicReference<>();
|
||||
expression.set(runtimeOf(recursive(new IrisExpression().setExpression("prior(x, y) + 17 * x + 31 * y + z"),
|
||||
expression)));
|
||||
double expected = 7D;
|
||||
for (int x = 0; x <= 31; x++) {
|
||||
expected = expected + 17D * x + 31D * 3.75D - 1D;
|
||||
@@ -102,9 +86,8 @@ public class IrisExpressionScratchTest {
|
||||
|
||||
@Test
|
||||
public void failedEvaluationUnwindsTheRetainedFrame() {
|
||||
IrisExpression expression = new IrisExpression();
|
||||
Expression compiled = mock(Expression.class);
|
||||
expression.getExpressionCache().aquire(() -> compiled);
|
||||
ExpressionRuntime expression = runtimeOf(parsedAs(new IrisExpression(), compiled));
|
||||
AtomicBoolean fail = new AtomicBoolean(true);
|
||||
AtomicReference<double[]> failedArguments = new AtomicReference<>();
|
||||
doAnswer(invocation -> {
|
||||
@@ -124,14 +107,12 @@ public class IrisExpressionScratchTest {
|
||||
|
||||
@Test
|
||||
public void largeArgumentListsRemainSupportedWithoutRetainingTheirArrays() {
|
||||
IrisExpression expression = new IrisExpression();
|
||||
KList<IrisExpressionLoad> variables = new KList<>();
|
||||
for (int i = 0; i < 300; i++) {
|
||||
variables.add(new IrisExpressionLoad().setName("value" + i).setStaticValue(i));
|
||||
}
|
||||
expression.setVariables(variables);
|
||||
Expression compiled = mock(Expression.class);
|
||||
expression.getExpressionCache().aquire(() -> compiled);
|
||||
ExpressionRuntime expression = runtimeOf(parsedAs(new IrisExpression().setVariables(variables), compiled));
|
||||
AtomicReference<double[]> first = new AtomicReference<>();
|
||||
doAnswer(invocation -> {
|
||||
double[] arguments = (double[]) invocation.getRawArguments()[1];
|
||||
@@ -152,7 +133,7 @@ public class IrisExpressionScratchTest {
|
||||
|
||||
@Test(timeout = 15000)
|
||||
public void sharedExpressionKeepsExactSamplesAcrossThreadsAndDimensions() throws Exception {
|
||||
IrisExpression expression = new IrisExpression().setExpression("sin(x) + cos(y) + z / 7");
|
||||
ExpressionRuntime expression = runtimeOf(new IrisExpression().setExpression("sin(x) + cos(y) + z / 7"));
|
||||
RNG control = new RNG(17L);
|
||||
long[] expected = new long[128];
|
||||
for (int i = 0; i < expected.length; i++) {
|
||||
@@ -182,4 +163,54 @@ public class IrisExpressionScratchTest {
|
||||
executor.awaitTermination(5, TimeUnit.SECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
private static ExpressionRuntime runtimeOf(IrisExpression expression) {
|
||||
return PackRuntime.standalone(null).expression(expression);
|
||||
}
|
||||
|
||||
private static IrisExpression parsedAs(IrisExpression template, Expression compiled) {
|
||||
return new IrisExpression() {
|
||||
@Override
|
||||
public Expression parse(Function<IrisExpressionFunction, DynamicFunction> functionRuntime) {
|
||||
return compiled;
|
||||
}
|
||||
}.setVariables(template.getVariables());
|
||||
}
|
||||
|
||||
private static IrisExpression recursive(IrisExpression template, AtomicReference<ExpressionRuntime> expression) {
|
||||
IrisExpression config = new IrisExpression() {
|
||||
@Override
|
||||
public Expression parse(Function<IrisExpressionFunction, DynamicFunction> functionRuntime) {
|
||||
return super.parse(function -> new PriorFunction(expression));
|
||||
}
|
||||
};
|
||||
config.setExpression(template.getExpression());
|
||||
config.setVariables(template.getVariables());
|
||||
config.setFunctions(new KList<>(new IrisExpressionFunction().setName("prior")
|
||||
.setStyleValue(new IrisGeneratorStyle())));
|
||||
return config;
|
||||
}
|
||||
|
||||
private record PriorFunction(AtomicReference<ExpressionRuntime> expression) implements DynamicFunction {
|
||||
@Override
|
||||
public int getArgNumber() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Statefulness statefulness() {
|
||||
return Statefulness.STATEFUL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double eval(double... coordinates) {
|
||||
return 0D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double eval(Context context, double... coordinates) {
|
||||
RNG rng = ((ExpressionRuntime.FunctionContext) context).rng();
|
||||
return coordinates[0] <= 0D ? 7D : expression.get().evaluate(rng, coordinates[0] - 1D, coordinates[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
+25
-27
@@ -3,6 +3,7 @@ package art.arcane.iris.generation.noise;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
import art.arcane.iris.generation.runtime.IrisEngineStreamType;
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
@@ -15,7 +16,6 @@ import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertSame;
|
||||
@@ -26,9 +26,9 @@ public class IrisExpressionSeedCohesionTest {
|
||||
@Test
|
||||
public void expressionStreamsSeparateSeedsAndInitializationOrder() {
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisExpression expression = expression(data);
|
||||
double first = expression(data).evaluate(new RNG(17L), 23.5D, -94.75D);
|
||||
double second = expression(data).evaluate(new RNG(53L), 23.5D, -94.75D);
|
||||
ExpressionRuntime expression = PackRuntime.standalone(data).expression(expression(data));
|
||||
double first = PackRuntime.standalone(data).expression(expression(data)).evaluate(new RNG(17L), 23.5D, -94.75D);
|
||||
double second = PackRuntime.standalone(data).expression(expression(data)).evaluate(new RNG(53L), 23.5D, -94.75D);
|
||||
ProceduralStream<Double> secondStream = expression.stream(new RNG(53L));
|
||||
ProceduralStream<Double> firstStream = expression.stream(new RNG(17L));
|
||||
assertEquals(second, secondStream.get(23.5D, -94.75D), 0D);
|
||||
@@ -37,41 +37,39 @@ public class IrisExpressionSeedCohesionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void expressionFunctionTracksEngineIdentity() {
|
||||
Engine firstEngine = engine(17D);
|
||||
Engine secondEngine = engine(53D);
|
||||
AtomicReference<Engine> active = new AtomicReference<>(firstEngine);
|
||||
public void expressionFunctionReadsItsOwnEngine() {
|
||||
IrisData data = mock(IrisData.class);
|
||||
when(data.getEngine()).thenAnswer(ignored -> active.get());
|
||||
IrisExpressionFunction function = new IrisExpressionFunction()
|
||||
.setName("height")
|
||||
.setData(data)
|
||||
.setEngineStreamValue(IrisEngineStreamType.HEIGHT);
|
||||
IrisExpressionFunction.FunctionContext context = new IrisExpressionFunction.FunctionContext(new RNG(91L));
|
||||
assertEquals(17D, function.eval(context, 4D, -8D), 0D);
|
||||
active.set(secondEngine);
|
||||
assertEquals(53D, function.eval(context, 4D, -8D), 0D);
|
||||
active.set(firstEngine);
|
||||
assertEquals(17D, function.eval(context, 4D, -8D), 0D);
|
||||
IrisExpression expression = new IrisExpression()
|
||||
.setExpression("height(x, z)")
|
||||
.setFunctions(new KList<>(new IrisExpressionFunction()
|
||||
.setName("height")
|
||||
.setEngineStreamValue(IrisEngineStreamType.HEIGHT)));
|
||||
ExpressionRuntime first = PackRuntime.forEngine(engine(17D), data).expression(expression);
|
||||
ExpressionRuntime second = PackRuntime.forEngine(engine(53D), data).expression(expression);
|
||||
RNG rng = new RNG(91L);
|
||||
|
||||
assertEquals(17D, first.evaluate(rng, 4D, -8D), 0D);
|
||||
assertEquals(53D, second.evaluate(rng, 4D, -8D), 0D);
|
||||
assertEquals(17D, first.evaluate(rng, 4D, -8D), 0D);
|
||||
}
|
||||
|
||||
@Test(timeout = 15000)
|
||||
public void concurrentFunctionInitializationAndEvictionRetainSeedSamples() throws Exception {
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisExpressionFunction shared = function(data);
|
||||
IrisExpression config = new IrisExpression().setExpression("field(x, z)").setFunctions(new KList<>(function()));
|
||||
ExpressionRuntime shared = PackRuntime.standalone(data).expression(config);
|
||||
ExecutorService workers = Executors.newFixedThreadPool(4);
|
||||
try {
|
||||
List<Future<Double>> results = new ArrayList<>(32);
|
||||
double[] expected = new double[32];
|
||||
for (int index = 0; index < 32; index++) {
|
||||
long seed = index;
|
||||
expected[index] = function(data).eval(new IrisExpressionFunction.FunctionContext(new RNG(seed)), 23.5D, -94.75D);
|
||||
results.add(workers.submit(() -> shared.eval(
|
||||
new IrisExpressionFunction.FunctionContext(new RNG(seed)), 23.5D, -94.75D)));
|
||||
expected[index] = PackRuntime.standalone(data).expression(config).evaluate(new RNG(seed), 23.5D, -94.75D);
|
||||
results.add(workers.submit(() -> shared.evaluate(new RNG(seed), 23.5D, -94.75D)));
|
||||
}
|
||||
for (int index = 0; index < results.size(); index++) {
|
||||
assertEquals(expected[index], results.get(index).get(5L, TimeUnit.SECONDS), 0D);
|
||||
assertEquals(expected[index], shared.eval(new IrisExpressionFunction.FunctionContext(new RNG(index)), 23.5D, -94.75D), 0D);
|
||||
assertEquals(expected[index], shared.evaluate(new RNG(index), 23.5D, -94.75D), 0D);
|
||||
}
|
||||
} finally {
|
||||
workers.shutdownNow();
|
||||
@@ -81,14 +79,14 @@ public class IrisExpressionSeedCohesionTest {
|
||||
private static IrisExpression expression(IrisData data) {
|
||||
IrisExpression expression = new IrisExpression()
|
||||
.setExpression("field(x, z) + value")
|
||||
.setFunctions(new KList<>(function(data)))
|
||||
.setFunctions(new KList<>(function()))
|
||||
.setVariables(new KList<>(new IrisExpressionLoad().setName("value").setStyleValue(NoiseStyle.PERLIN.style())));
|
||||
expression.setLoader(data);
|
||||
return expression;
|
||||
}
|
||||
|
||||
private static IrisExpressionFunction function(IrisData data) {
|
||||
return new IrisExpressionFunction().setName("field").setStyleValue(NoiseStyle.SIMPLEX.style()).setData(data);
|
||||
private static IrisExpressionFunction function() {
|
||||
return new IrisExpressionFunction().setName("field").setStyleValue(NoiseStyle.SIMPLEX.style());
|
||||
}
|
||||
|
||||
private static Engine engine(double height) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.generation.noise;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -8,13 +9,15 @@ import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyLong;
|
||||
import static org.mockito.ArgumentMatchers.isNull;
|
||||
import static org.mockito.ArgumentMatchers.same;
|
||||
import static org.mockito.Mockito.clearInvocations;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
public class IrisGeneratorBatchTest {
|
||||
private final PackRuntime runtime = PackRuntime.standalone(null);
|
||||
|
||||
private static final double[] XS = {-0D, 0D, -12D, -5.75D, 18D, 18D, 8191.25D, -29999999.5D, 2147483647D};
|
||||
private static final double[] ZS = {0D, -0D, 6D, 2.5D, -6D, -6D, -4096.75D, 29999998D, -2147483648D};
|
||||
|
||||
@@ -31,10 +34,10 @@ public class IrisGeneratorBatchTest {
|
||||
assertTrue(batch.supportsBatch());
|
||||
double[] sampled = new double[XS.length];
|
||||
for (long seed : seeds) {
|
||||
batch.compileProgram(seed).heights(new TerrainBatchScratch(), XS, ZS, sampled.length, sampled);
|
||||
batch.compileProgram(runtime, seed).heights(new TerrainBatchScratch(), XS, ZS, sampled.length, sampled);
|
||||
for (int index = 0; index < sampled.length; index++) {
|
||||
assertEquals(style + " detail=" + detail + " seed=" + seed + " index=" + index,
|
||||
Double.doubleToRawLongBits(scalar.getHeight(XS[index], ZS[index], seed)),
|
||||
Double.doubleToRawLongBits(scalar.getHeight(runtime, XS[index], ZS[index], seed)),
|
||||
Double.doubleToRawLongBits(sampled[index]));
|
||||
}
|
||||
}
|
||||
@@ -51,9 +54,9 @@ public class IrisGeneratorBatchTest {
|
||||
IrisGenerator batch = generator(style, detail, false).setCliffHeightMax(0D).setCellFractureHeight(0D);
|
||||
double[] values = new double[XS.length];
|
||||
for (long seed : new long[]{-1337L, Long.MAX_VALUE - 37L}) {
|
||||
batch.compileProgram(seed).heights(new TerrainBatchScratch(), XS, ZS, XS.length, values);
|
||||
batch.compileProgram(runtime, seed).heights(new TerrainBatchScratch(), XS, ZS, XS.length, values);
|
||||
for (int index = 0; index < XS.length; index++) {
|
||||
assertEquals(Double.doubleToRawLongBits(scalar.getHeight(XS[index], ZS[index], seed)),
|
||||
assertEquals(Double.doubleToRawLongBits(scalar.getHeight(runtime, XS[index], ZS[index], seed)),
|
||||
Double.doubleToRawLongBits(values[index]));
|
||||
}
|
||||
}
|
||||
@@ -66,27 +69,27 @@ public class IrisGeneratorBatchTest {
|
||||
IrisNoiseGenerator layer = spy(new IrisNoiseGenerator().setStyle(NoiseStyle.SIMPLEX.style()));
|
||||
IrisGenerator generator = new IrisGenerator().setComposite(new KList<>(layer));
|
||||
double[] sampled = new double[XS.length];
|
||||
GeneratorProgram program = generator.compileProgram(99L);
|
||||
verify(layer, times(1)).getGenerator(anyLong(), isNull(), isNull());
|
||||
GeneratorProgram program = generator.compileProgram(runtime, 99L);
|
||||
verify(layer, times(1)).getGenerator(anyLong(), same(runtime));
|
||||
clearInvocations(layer);
|
||||
program.heights(new TerrainBatchScratch(), XS, ZS, XS.length, sampled);
|
||||
verify(layer, times(0)).getGenerator(anyLong(), isNull(), isNull());
|
||||
verify(layer, times(0)).getGenerator(anyLong(), same(runtime));
|
||||
for (int index = 0; index < XS.length; index++) {
|
||||
generator.getHeight(XS[index], ZS[index], 99L);
|
||||
generator.getHeight(runtime, XS[index], ZS[index], 99L);
|
||||
}
|
||||
verify(layer, times(XS.length)).getGenerator(anyLong(), isNull(), isNull());
|
||||
verify(layer, times(XS.length)).getGenerator(anyLong(), same(runtime));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customGeneratorsCannotCompile() {
|
||||
IrisGenerator generator = new IrisGenerator() {
|
||||
@Override
|
||||
public double getHeight(double x, double z, long seed) {
|
||||
public double getHeight(PackRuntime runtime, double x, double z, long seed) {
|
||||
return x;
|
||||
}
|
||||
};
|
||||
assertFalse(generator.supportsBatch());
|
||||
assertThrows(IllegalStateException.class, () -> generator.compileProgram(0L));
|
||||
assertThrows(IllegalStateException.class, () -> generator.compileProgram(runtime, 0L));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+14
-20
@@ -1,14 +1,13 @@
|
||||
package art.arcane.iris.generation.noise;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.volmlib.util.noise.CNG;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
@@ -32,39 +31,34 @@ public class IrisGeneratorStyleCacheIsolationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cacheSeparatesSeedsAndEngineIdentity() throws Exception {
|
||||
Engine firstEngine = mock(Engine.class);
|
||||
Engine secondEngine = mock(Engine.class);
|
||||
AtomicReference<Engine> activeEngine = new AtomicReference<>(firstEngine);
|
||||
public void runtimeSeparatesSeedsAndOwners() throws Exception {
|
||||
IrisData data = mock(IrisData.class);
|
||||
when(data.getEngine()).thenAnswer(ignored -> activeEngine.get());
|
||||
when(data.getDataFolder()).thenReturn(temporaryFolder.newFolder("pack"));
|
||||
PackRuntime owner = PackRuntime.standalone(data);
|
||||
PackRuntime otherOwner = PackRuntime.standalone(data);
|
||||
IrisGeneratorStyle style = new IrisGeneratorStyle(NoiseStyle.SIMPLEX);
|
||||
|
||||
CNG first = style.create(new RNG(41L), data);
|
||||
CNG firstAgain = style.create(new RNG(41L), data);
|
||||
CNG differentSeed = style.create(new RNG(42L), data);
|
||||
activeEngine.set(secondEngine);
|
||||
CNG differentEngine = style.create(new RNG(41L), data);
|
||||
CNG first = style.create(new RNG(41L), owner);
|
||||
CNG firstAgain = style.create(new RNG(41L), owner);
|
||||
CNG differentSeed = style.create(new RNG(42L), owner);
|
||||
CNG differentOwner = style.create(new RNG(41L), otherOwner);
|
||||
|
||||
assertSame(first, firstAgain);
|
||||
assertNotSame(first, differentSeed);
|
||||
assertNotSame(first, differentEngine);
|
||||
assertNotSame(first, differentOwner);
|
||||
assertNotEquals(first.noise(12D, -7D), differentSeed.noise(12D, -7D), 0D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cacheEvictsOldEngineSeedEntries() {
|
||||
IrisData data = mock(IrisData.class);
|
||||
Engine engine = mock(Engine.class);
|
||||
when(data.getEngine()).thenReturn(engine);
|
||||
public void runtimeEvictsOldSeedEntries() {
|
||||
PackRuntime owner = PackRuntime.standalone(mock(IrisData.class));
|
||||
IrisGeneratorStyle style = new IrisGeneratorStyle(NoiseStyle.SIMPLEX);
|
||||
CNG first = style.create(new RNG(0L), data);
|
||||
CNG first = style.create(new RNG(0L), owner);
|
||||
|
||||
for (long seed = 1L; seed <= 8L; seed++) {
|
||||
style.create(new RNG(seed), data);
|
||||
style.create(new RNG(seed), owner);
|
||||
}
|
||||
|
||||
assertNotSame(first, style.create(new RNG(0L), data));
|
||||
assertNotSame(first, style.create(new RNG(0L), owner));
|
||||
}
|
||||
}
|
||||
+9
-6
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.generation.noise;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.generation.image.IrisImage;
|
||||
import art.arcane.iris.generation.image.IrisImageMap;
|
||||
import art.arcane.iris.generation.image.IrisImageMapOutOfBounds;
|
||||
@@ -41,13 +42,14 @@ public class IrisGeneratorStyleOverrideTest {
|
||||
IrisGeneratorStyle style = new IrisGeneratorStyle(NoiseStyle.FLAT).setExpression("height");
|
||||
IrisStyledRange range = new IrisStyledRange().setMin(2D).setMax(14D).setStyle(style);
|
||||
RNG rng = new RNG(78264193L);
|
||||
double first = style.create(rng, data).fitDouble(2D, 14D, 0D, 0D);
|
||||
double second = style.create(rng, data).fitDouble(2D, 14D, 1D, 0D);
|
||||
PackRuntime runtime = PackRuntime.standalone(data);
|
||||
double first = style.create(rng, runtime).fitDouble(2D, 14D, 0D, 0D);
|
||||
double second = style.create(rng, runtime).fitDouble(2D, 14D, 1D, 0D);
|
||||
|
||||
assertNotEquals(8D, first, 0D);
|
||||
assertNotEquals(first, second, 0D);
|
||||
assertEquals(first, range.get(rng, 0D, 0D, data), 0D);
|
||||
assertEquals(second, range.get(rng, 1D, 0D, data), 0D);
|
||||
assertEquals(first, range.get(rng, 0D, 0D, runtime), 0D);
|
||||
assertEquals(second, range.get(rng, 1D, 0D, runtime), 0D);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -66,7 +68,8 @@ public class IrisGeneratorStyleOverrideTest {
|
||||
IrisStyledRange range = new IrisStyledRange().setMin(2D).setMax(14D).setStyle(style);
|
||||
RNG rng = new RNG(78264193L);
|
||||
|
||||
assertEquals(2D, range.get(rng, 0D, 0D, data), 0D);
|
||||
assertEquals(14D, range.get(rng, 1D, 0D, data), 0D);
|
||||
PackRuntime runtime = PackRuntime.standalone(data);
|
||||
assertEquals(2D, range.get(rng, 0D, 0D, runtime), 0D);
|
||||
assertEquals(14D, range.get(rng, 1D, 0D, runtime), 0D);
|
||||
}
|
||||
}
|
||||
+40
-73
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.generation.noise;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
@@ -20,6 +21,8 @@ import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class IrisGeneratorSurfaceDetailTest {
|
||||
private final PackRuntime runtime = PackRuntime.standalone(null);
|
||||
|
||||
@Test
|
||||
public void defaultUsesTheOriginalSampleOnce() {
|
||||
AtomicInteger samples = new AtomicInteger();
|
||||
@@ -28,7 +31,7 @@ public class IrisGeneratorSurfaceDetailTest {
|
||||
return x * 0.01D + z * 0.02D;
|
||||
});
|
||||
|
||||
assertEquals(0.07D, generator.getHeight(1, 3, 27L), 1e-12D);
|
||||
assertEquals(0.07D, generator.getHeight(runtime, 1, 3, 27L), 1e-12D);
|
||||
assertEquals(1, samples.get());
|
||||
}
|
||||
|
||||
@@ -41,7 +44,7 @@ public class IrisGeneratorSurfaceDetailTest {
|
||||
for (int z = -12; z <= 12; z++) {
|
||||
for (int x = -12; x <= 12; x++) {
|
||||
double expected = x % 6 == 0 && z % 6 == 0 ? 0.2D : 0.5D;
|
||||
assertEquals(expected, generator.getHeight(x, z, 27L), 1e-12D);
|
||||
assertEquals(expected, generator.getHeight(runtime, x, z, 27L), 1e-12D);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -54,7 +57,7 @@ public class IrisGeneratorSurfaceDetailTest {
|
||||
for (double z = -4.25D; z < 4D; z += 0.5D) {
|
||||
for (double x = -4.75D; x < 4D; x += 0.5D) {
|
||||
assertEquals(0.5D + x * 0.01D + z * 0.02D,
|
||||
generator.getHeight(x, z, 27L), 1e-12D);
|
||||
generator.getHeight(runtime, x, z, 27L), 1e-12D);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -70,7 +73,7 @@ public class IrisGeneratorSurfaceDetailTest {
|
||||
|
||||
for (int z = 0; z < 16; z++) {
|
||||
for (int x = 0; x < 16; x++) {
|
||||
assertEquals(0.5D, generator.getHeight(x, z, 27L), 0D);
|
||||
assertEquals(0.5D, generator.getHeight(runtime, x, z, 27L), 0D);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,7 +92,7 @@ public class IrisGeneratorSurfaceDetailTest {
|
||||
|
||||
for (int z = -16; z < 16; z += 4) {
|
||||
for (int x = -16; x < 16; x += 4) {
|
||||
generator.getHeight(x, z, 27L);
|
||||
generator.getHeight(runtime, x, z, 27L);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,10 +111,9 @@ public class IrisGeneratorSurfaceDetailTest {
|
||||
};
|
||||
|
||||
for (double[] point : points) {
|
||||
cold.rescale(1D);
|
||||
long expected = Double.doubleToRawLongBits(cold.getHeight(point[0], point[1], 27L));
|
||||
long expected = Double.doubleToRawLongBits(cold.getHeight(PackRuntime.standalone(null), point[0], point[1], 27L));
|
||||
for (int repeat = 0; repeat < 4; repeat++) {
|
||||
assertEquals(expected, Double.doubleToRawLongBits(warm.getHeight(point[0], point[1], 27L)));
|
||||
assertEquals(expected, Double.doubleToRawLongBits(warm.getHeight(runtime, point[0], point[1], 27L)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -124,16 +126,16 @@ public class IrisGeneratorSurfaceDetailTest {
|
||||
return seed * 0.000001D;
|
||||
}).setSurfaceDetail(0.5D);
|
||||
|
||||
double first = generator.getHeight(0, 0, 27L);
|
||||
assertEquals(Double.doubleToRawLongBits(first), Double.doubleToRawLongBits(generator.getHeight(0, 0, 27L)));
|
||||
double first = generator.getHeight(runtime, 0, 0, 27L);
|
||||
assertEquals(Double.doubleToRawLongBits(first), Double.doubleToRawLongBits(generator.getHeight(runtime, 0, 0, 27L)));
|
||||
assertEquals(1, samples.get());
|
||||
|
||||
double second = generator.getHeight(0, 0, 28L);
|
||||
double second = generator.getHeight(runtime, 0, 0, 28L);
|
||||
assertEquals(0.000001D, second - first, 1e-12D);
|
||||
assertEquals(Double.doubleToRawLongBits(second), Double.doubleToRawLongBits(generator.getHeight(0, 0, 28L)));
|
||||
assertEquals(Double.doubleToRawLongBits(second), Double.doubleToRawLongBits(generator.getHeight(runtime, 0, 0, 28L)));
|
||||
assertEquals(2, samples.get());
|
||||
|
||||
assertEquals(Double.doubleToRawLongBits(first), Double.doubleToRawLongBits(generator.getHeight(0, 0, 27L)));
|
||||
assertEquals(Double.doubleToRawLongBits(first), Double.doubleToRawLongBits(generator.getHeight(runtime, 0, 0, 27L)));
|
||||
assertEquals(3, samples.get());
|
||||
}
|
||||
|
||||
@@ -147,14 +149,14 @@ public class IrisGeneratorSurfaceDetailTest {
|
||||
return x * 0.00001D;
|
||||
}).setSurfaceDetail(0.5D);
|
||||
|
||||
assertEquals(0L, Double.doubleToRawLongBits(generator.getHeight(0, 0, 27L)));
|
||||
assertEquals(0L, Double.doubleToRawLongBits(generator.getHeight(0, 0, 27L)));
|
||||
assertEquals(0L, Double.doubleToRawLongBits(generator.getHeight(runtime, 0, 0, 27L)));
|
||||
assertEquals(0L, Double.doubleToRawLongBits(generator.getHeight(runtime, 0, 0, 27L)));
|
||||
assertEquals(1, originSamples.get());
|
||||
assertEquals(Double.doubleToRawLongBits(71754D * 0.00001D),
|
||||
Double.doubleToRawLongBits(generator.getHeight(71754, 0, 27L)));
|
||||
assertEquals(0L, Double.doubleToRawLongBits(generator.getHeight(0, 0, 27L)));
|
||||
Double.doubleToRawLongBits(generator.getHeight(runtime, 71754, 0, 27L)));
|
||||
assertEquals(0L, Double.doubleToRawLongBits(generator.getHeight(runtime, 0, 0, 27L)));
|
||||
assertEquals(2, originSamples.get());
|
||||
assertEquals(0L, Double.doubleToRawLongBits(generator.getHeight(0, 0, 27L)));
|
||||
assertEquals(0L, Double.doubleToRawLongBits(generator.getHeight(runtime, 0, 0, 27L)));
|
||||
assertEquals(2, originSamples.get());
|
||||
}
|
||||
|
||||
@@ -168,7 +170,7 @@ public class IrisGeneratorSurfaceDetailTest {
|
||||
long[][] expected = new long[xs.length][seeds.length];
|
||||
for (int coordinate = 0; coordinate < xs.length; coordinate++) {
|
||||
for (int seed = 0; seed < seeds.length; seed++) {
|
||||
expected[coordinate][seed] = Double.doubleToRawLongBits(reference.getHeight(xs[coordinate], 0D, seeds[seed]));
|
||||
expected[coordinate][seed] = Double.doubleToRawLongBits(reference.getHeight(runtime, xs[coordinate], 0D, seeds[seed]));
|
||||
}
|
||||
}
|
||||
ForkJoinPool pool = new ForkJoinPool(4);
|
||||
@@ -181,7 +183,7 @@ public class IrisGeneratorSurfaceDetailTest {
|
||||
int coordinate = (sample + offset) & 1;
|
||||
int seed = (sample / 2 + offset) & 1;
|
||||
assertEquals(expected[coordinate][seed],
|
||||
Double.doubleToRawLongBits(generator.getHeight(xs[coordinate], 0D, seeds[seed])));
|
||||
Double.doubleToRawLongBits(generator.getHeight(runtime, xs[coordinate], 0D, seeds[seed])));
|
||||
}
|
||||
}));
|
||||
}
|
||||
@@ -198,67 +200,32 @@ public class IrisGeneratorSurfaceDetailTest {
|
||||
public void cachedLatticeHeightsRemainIsolatedBySeed() {
|
||||
IrisGenerator generator = generator((seed, x, z) -> seed * 0.000001D);
|
||||
generator.setSurfaceDetail(0.5D);
|
||||
double first = generator.getHeight(1, 1, 27L);
|
||||
double second = generator.getHeight(1, 1, 28L);
|
||||
double first = generator.getHeight(runtime, 1, 1, 27L);
|
||||
double second = generator.getHeight(runtime, 1, 1, 28L);
|
||||
|
||||
assertEquals(0.000001D, second - first, 1e-12D);
|
||||
assertEquals(first, generator.getHeight(1, 1, 27L), 0D);
|
||||
assertEquals(first, generator.getHeight(runtime, 1, 1, 27L), 0D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cachedLatticeHeightsRemainIsolatedByEngine() {
|
||||
Engine firstEngine = mock(Engine.class);
|
||||
Engine secondEngine = mock(Engine.class);
|
||||
AtomicReference<Engine> activeEngine = new AtomicReference<>(firstEngine);
|
||||
IrisData data = mock(IrisData.class);
|
||||
when(data.getEngine()).thenAnswer(ignored -> activeEngine.get());
|
||||
IrisGenerator generator = new IrisGenerator().setSurfaceDetail(0.5D).setComposite(new KList<>(
|
||||
new ContextNoise(loader -> loader.getEngine() == firstEngine ? 0.2D : 0.8D)));
|
||||
generator.setLoader(data);
|
||||
|
||||
assertEquals(0.2D, generator.getHeight(0, 0, 27L), 1e-12D);
|
||||
assertEquals(0.2D, generator.getHeight(1, 1, 27L), 1e-12D);
|
||||
activeEngine.set(secondEngine);
|
||||
assertEquals(0.8D, generator.getHeight(0, 0, 27L), 1e-12D);
|
||||
assertEquals(0.8D, generator.getHeight(1, 1, 27L), 1e-12D);
|
||||
activeEngine.set(firstEngine);
|
||||
assertEquals(0.2D, generator.getHeight(1, 1, 27L), 1e-12D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cachedLatticeHeightsRemainIsolatedByLoader() {
|
||||
Engine engine = mock(Engine.class);
|
||||
public void cachedLatticeHeightsBelongToTheirRuntime() {
|
||||
IrisData firstData = mock(IrisData.class);
|
||||
IrisData secondData = mock(IrisData.class);
|
||||
when(firstData.getEngine()).thenReturn(engine);
|
||||
when(secondData.getEngine()).thenReturn(engine);
|
||||
PackRuntime first = PackRuntime.standalone(firstData);
|
||||
PackRuntime second = PackRuntime.standalone(secondData);
|
||||
IrisGenerator generator = new IrisGenerator().setSurfaceDetail(0.5D).setComposite(new KList<>(
|
||||
new ContextNoise(loader -> loader == firstData ? 0.2D : 0.8D)));
|
||||
generator.setLoader(firstData);
|
||||
new ContextNoise(scope -> scope.data() == firstData ? 0.2D : 0.8D)));
|
||||
|
||||
assertEquals(0.2D, generator.getHeight(0, 0, 27L), 1e-12D);
|
||||
assertEquals(0.2D, generator.getHeight(1, 1, 27L), 1e-12D);
|
||||
generator.setLoader(secondData);
|
||||
assertEquals(0.8D, generator.getHeight(0, 0, 27L), 1e-12D);
|
||||
assertEquals(0.8D, generator.getHeight(1, 1, 27L), 1e-12D);
|
||||
generator.setLoader(firstData);
|
||||
assertEquals(0.2D, generator.getHeight(1, 1, 27L), 1e-12D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rescalingClearsCachedLatticeHeights() {
|
||||
IrisGenerator generator = generator((seed, x, z) -> x * 0.01D + z * 0.02D);
|
||||
generator.setSurfaceDetail(0.5D);
|
||||
assertEquals(0.06D, generator.getHeight(2, 2, 27L), 1e-12D);
|
||||
|
||||
generator.rescale(2D);
|
||||
|
||||
assertEquals(0.12D, generator.getHeight(2, 2, 27L), 1e-12D);
|
||||
assertEquals(0.2D, generator.getHeight(first, 0, 0, 27L), 1e-12D);
|
||||
assertEquals(0.2D, generator.getHeight(first, 1, 1, 27L), 1e-12D);
|
||||
assertEquals(0.8D, generator.getHeight(second, 0, 0, 27L), 1e-12D);
|
||||
assertEquals(0.8D, generator.getHeight(second, 1, 1, 27L), 1e-12D);
|
||||
assertEquals(0.2D, generator.getHeight(first, 1, 1, 27L), 1e-12D);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void rejectsNonfiniteDetail() {
|
||||
generator((seed, x, z) -> 0D).setSurfaceDetail(Double.NaN).getHeight(1, 1, 27L);
|
||||
generator((seed, x, z) -> 0D).setSurfaceDetail(Double.NaN).getHeight(runtime, 1, 1, 27L);
|
||||
}
|
||||
|
||||
private static IrisGenerator generator(Sampler sampler) {
|
||||
@@ -277,21 +244,21 @@ public class IrisGeneratorSurfaceDetailTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getNoise(long superSeed, double x, double z, IrisData data, Engine engine) {
|
||||
public double getNoise(long superSeed, double x, double z, PackRuntime runtime) {
|
||||
return sampler.sample(superSeed, x, z);
|
||||
}
|
||||
}
|
||||
|
||||
private static final class ContextNoise extends IrisNoiseGenerator {
|
||||
private final ToDoubleFunction<IrisData> sampler;
|
||||
private final ToDoubleFunction<PackRuntime> sampler;
|
||||
|
||||
private ContextNoise(ToDoubleFunction<IrisData> sampler) {
|
||||
private ContextNoise(ToDoubleFunction<PackRuntime> sampler) {
|
||||
this.sampler = sampler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getNoise(long superSeed, double x, double z, IrisData data, Engine engine) {
|
||||
return sampler.applyAsDouble(data);
|
||||
public double getNoise(long superSeed, double x, double z, PackRuntime runtime) {
|
||||
return sampler.applyAsDouble(runtime);
|
||||
}
|
||||
}
|
||||
}
|
||||
+22
-45
@@ -1,9 +1,9 @@
|
||||
package art.arcane.iris.generation.noise;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.volmlib.util.noise.CNG;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -24,7 +24,6 @@ import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.never;
|
||||
|
||||
public final class IrisNoiseGeneratorCacheTest {
|
||||
private static final long GENERATOR_SALT = 33_955_677L;
|
||||
@@ -35,17 +34,17 @@ public final class IrisNoiseGeneratorCacheTest {
|
||||
public void callerSeedsDoNotShareAFirstWinnerGenerator() {
|
||||
GeneratorFixture fixture = new GeneratorFixture();
|
||||
|
||||
assertSame(fixture.firstGenerator, fixture.generator.getGenerator(11L, fixture.data, fixture.engine));
|
||||
assertSame(fixture.secondGenerator, fixture.generator.getGenerator(29L, fixture.data, fixture.engine));
|
||||
assertSame(fixture.firstGenerator, fixture.generator.getGenerator(11L, fixture.data, fixture.engine));
|
||||
assertSame(fixture.firstGenerator, fixture.generator.getGenerator(11L, fixture.runtime));
|
||||
assertSame(fixture.secondGenerator, fixture.generator.getGenerator(29L, fixture.runtime));
|
||||
assertSame(fixture.firstGenerator, fixture.generator.getGenerator(11L, fixture.runtime));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void reverseInitializationOrderKeepsSeedAssignments() {
|
||||
GeneratorFixture fixture = new GeneratorFixture();
|
||||
|
||||
assertSame(fixture.secondGenerator, fixture.generator.getGenerator(29L, fixture.data, fixture.engine));
|
||||
assertSame(fixture.firstGenerator, fixture.generator.getGenerator(11L, fixture.data, fixture.engine));
|
||||
assertSame(fixture.secondGenerator, fixture.generator.getGenerator(29L, fixture.runtime));
|
||||
assertSame(fixture.firstGenerator, fixture.generator.getGenerator(11L, fixture.runtime));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -56,11 +55,11 @@ public final class IrisNoiseGeneratorCacheTest {
|
||||
try {
|
||||
Future<CNG> first = executor.submit(() -> {
|
||||
assertTrue(start.await(5L, TimeUnit.SECONDS));
|
||||
return fixture.generator.getGenerator(11L, fixture.data, fixture.engine);
|
||||
return fixture.generator.getGenerator(11L, fixture.runtime);
|
||||
});
|
||||
Future<CNG> second = executor.submit(() -> {
|
||||
assertTrue(start.await(5L, TimeUnit.SECONDS));
|
||||
return fixture.generator.getGenerator(29L, fixture.data, fixture.engine);
|
||||
return fixture.generator.getGenerator(29L, fixture.runtime);
|
||||
});
|
||||
start.countDown();
|
||||
|
||||
@@ -72,55 +71,34 @@ public final class IrisNoiseGeneratorCacheTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void heightResolvesEngineOnceAcrossFracturesAndSurfaceCorners() {
|
||||
public void eachRuntimeBuildsItsOwnGeneratorAndKeepsIt() {
|
||||
IrisData data = mock(IrisData.class);
|
||||
Engine engine = mock(Engine.class);
|
||||
when(data.getEngine()).thenReturn(engine);
|
||||
IrisNoiseGenerator child = new IrisNoiseGenerator().setStyle(NoiseStyle.SIMPLEX.style());
|
||||
IrisNoiseGenerator layer = new IrisNoiseGenerator().setStyle(NoiseStyle.SIMPLEX.style())
|
||||
.setFracture(new KList<>(child));
|
||||
IrisGenerator generator = new IrisGenerator().setComposite(new KList<>(layer, child))
|
||||
.setSurfaceDetail(0.5D);
|
||||
generator.setLoader(data);
|
||||
|
||||
double first = generator.getHeight(13D, -21D, 71L);
|
||||
verify(data, times(1)).getEngine();
|
||||
assertEquals(Double.doubleToRawLongBits(first),
|
||||
Double.doubleToRawLongBits(generator.getHeight(13D, -21D, 71L)));
|
||||
verify(data, times(2)).getEngine();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void changedEngineUsesDistinctConstructionAndRestoresPreviousGenerator() {
|
||||
IrisData data = mock(IrisData.class);
|
||||
Engine firstEngine = mock(Engine.class);
|
||||
Engine secondEngine = mock(Engine.class);
|
||||
PackRuntime firstRuntime = PackRuntime.forEngine(mock(Engine.class), data);
|
||||
PackRuntime secondRuntime = PackRuntime.forEngine(mock(Engine.class), data);
|
||||
IrisGeneratorStyle style = mock(IrisGeneratorStyle.class);
|
||||
CNG first = mock(CNG.class);
|
||||
CNG second = mock(CNG.class);
|
||||
IrisNoiseGenerator layer = new IrisNoiseGenerator().setStyle(style);
|
||||
when(data.getEngine()).thenReturn(firstEngine, secondEngine, firstEngine);
|
||||
when(style.createForLayer(any(RNG.class), same(data), eq(1), same(firstEngine))).thenReturn(first);
|
||||
when(style.createForLayer(any(RNG.class), same(data), eq(1), same(secondEngine))).thenReturn(second);
|
||||
when(style.createForLayer(any(RNG.class), same(firstRuntime), eq(1))).thenReturn(first);
|
||||
when(style.createForLayer(any(RNG.class), same(secondRuntime), eq(1))).thenReturn(second);
|
||||
|
||||
assertSame(first, layer.getGenerator(11L, data, data.getEngine()));
|
||||
assertSame(second, layer.getGenerator(11L, data, data.getEngine()));
|
||||
assertSame(first, layer.getGenerator(11L, data, data.getEngine()));
|
||||
verify(style, times(1)).createForLayer(any(RNG.class), same(data), eq(1), same(firstEngine));
|
||||
verify(style, times(1)).createForLayer(any(RNG.class), same(data), eq(1), same(secondEngine));
|
||||
assertSame(first, layer.getGenerator(11L, firstRuntime));
|
||||
assertSame(second, layer.getGenerator(11L, secondRuntime));
|
||||
assertSame(first, layer.getGenerator(11L, firstRuntime));
|
||||
verify(style, times(1)).createForLayer(any(RNG.class), same(firstRuntime), eq(1));
|
||||
verify(style, times(1)).createForLayer(any(RNG.class), same(secondRuntime), eq(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void disabledNoiseDoesNotResolveEngine() {
|
||||
IrisData data = mock(IrisData.class);
|
||||
public void disabledNoiseReturnsItsOffset() {
|
||||
IrisNoiseGenerator layer = new IrisNoiseGenerator(false).setOffsetY(0.37D);
|
||||
assertEquals(0.37D, layer.getNoise(11L, 13D, -21D, data), 0D);
|
||||
verify(data, never()).getEngine();
|
||||
assertEquals(0.37D, layer.getNoise(11L, 13D, -21D, PackRuntime.standalone(null)), 0D);
|
||||
}
|
||||
|
||||
private static final class GeneratorFixture {
|
||||
private final IrisData data = mock(IrisData.class);
|
||||
private final Engine engine = mock(Engine.class);
|
||||
private final PackRuntime runtime = PackRuntime.forEngine(engine, data);
|
||||
private final IrisGeneratorStyle style = mock(IrisGeneratorStyle.class);
|
||||
private final CNG firstGenerator = mock(CNG.class);
|
||||
private final CNG secondGenerator = mock(CNG.class);
|
||||
@@ -130,12 +108,11 @@ public final class IrisNoiseGeneratorCacheTest {
|
||||
.setOctaves(OCTAVES);
|
||||
|
||||
private GeneratorFixture() {
|
||||
when(data.getEngine()).thenReturn(engine);
|
||||
Map<Long, CNG> generators = Map.of(
|
||||
11L + GENERATOR_SALT - CONFIGURED_SEED, firstGenerator,
|
||||
29L + GENERATOR_SALT - CONFIGURED_SEED, secondGenerator
|
||||
);
|
||||
when(style.createForLayer(any(RNG.class), same(data), eq(OCTAVES), same(engine))).thenAnswer(invocation -> {
|
||||
when(style.createForLayer(any(RNG.class), same(runtime), eq(OCTAVES))).thenAnswer(invocation -> {
|
||||
RNG rng = invocation.getArgument(0);
|
||||
return generators.get(rng.getSeed());
|
||||
});
|
||||
|
||||
+5
-2
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.generation.noise;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.noise.NoiseGenerator;
|
||||
import org.junit.Test;
|
||||
@@ -7,6 +8,8 @@ import org.junit.Test;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public final class IrisNoiseGeneratorFractureMirrorTest {
|
||||
private static final PackRuntime RUNTIME = PackRuntime.standalone(null);
|
||||
|
||||
private static final long SEED = 71L;
|
||||
private static final int GRID_SIZE = 40;
|
||||
private static final double GRID_STEP = 7.3D;
|
||||
@@ -31,7 +34,7 @@ public final class IrisNoiseGeneratorFractureMirrorTest {
|
||||
for (int j = i + 1; j < GRID_SIZE; j++) {
|
||||
double a = i * GRID_STEP;
|
||||
double b = j * GRID_STEP + 0.5D;
|
||||
if (Math.abs(noise.getNoise(SEED, a, b, null) - noise.getNoise(SEED, b, a, null)) < MIRRORED) {
|
||||
if (Math.abs(noise.getNoise(SEED, a, b, RUNTIME) - noise.getNoise(SEED, b, a, RUNTIME)) < MIRRORED) {
|
||||
mirroredSamples++;
|
||||
}
|
||||
}
|
||||
@@ -41,7 +44,7 @@ public final class IrisNoiseGeneratorFractureMirrorTest {
|
||||
|
||||
private static IrisNoiseGenerator diagonalSymmetricRoot() {
|
||||
IrisNoiseGenerator root = new IrisNoiseGenerator().setStyle(NoiseStyle.SIMPLEX.style()).setSeed(5L);
|
||||
root.getGenerator(SEED, null, null).setGenerator(new DiagonalSymmetricGenerator());
|
||||
root.getGenerator(SEED, RUNTIME).setGenerator(new DiagonalSymmetricGenerator());
|
||||
return root;
|
||||
}
|
||||
|
||||
|
||||
+41
-38
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.generation.noise;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
@@ -29,6 +30,8 @@ import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
public final class IrisNoiseGeneratorFractureTest {
|
||||
private static final PackRuntime RUNTIME = PackRuntime.standalone(null);
|
||||
|
||||
@Test
|
||||
public void deepChainsMatchRecursiveSamplingBits() {
|
||||
Random coordinates = new Random(718311L);
|
||||
@@ -37,13 +40,13 @@ public final class IrisNoiseGeneratorFractureTest {
|
||||
for (int depth : new int[]{0, 1, 3, 4, 5, 8}) {
|
||||
IrisNoiseGenerator root = chain(depth, style).getFirst();
|
||||
for (long seed : new long[]{0L, -4193L, Long.MIN_VALUE, Long.MAX_VALUE}) {
|
||||
assertParity(root, seed, 0D, -0D, null, null);
|
||||
assertParity(root, seed, -0D, 0D, null, null);
|
||||
assertParity(root, seed, -30_000_000D, 29_999_999.75D, null, null);
|
||||
assertParity(root, seed, Math.nextDown(-64D), Math.nextUp(64D), null, null);
|
||||
assertParity(root, seed, 0D, -0D, RUNTIME);
|
||||
assertParity(root, seed, -0D, 0D, RUNTIME);
|
||||
assertParity(root, seed, -30_000_000D, 29_999_999.75D, RUNTIME);
|
||||
assertParity(root, seed, Math.nextDown(-64D), Math.nextUp(64D), RUNTIME);
|
||||
for (int index = 0; index < 8; index++) {
|
||||
assertParity(root, seed, coordinates.nextDouble() * 4096D - 2048D,
|
||||
coordinates.nextDouble() * 4096D - 2048D, null, null);
|
||||
coordinates.nextDouble() * 4096D - 2048D, RUNTIME);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -54,13 +57,13 @@ public final class IrisNoiseGeneratorFractureTest {
|
||||
public void fourFracturesReducePrimitiveSamplesFromThirtyOneToNine() {
|
||||
List<IrisNoiseGenerator> chain = chain(4, NoiseStyle.SIMPLEX);
|
||||
List<NoiseGenerator> bases = spyBases(chain, 71L);
|
||||
reference(chain.getFirst(), 71L, 13.25D, -21.75D, null, null);
|
||||
reference(chain.getFirst(), 71L, 13.25D, -21.75D, RUNTIME);
|
||||
for (int index = 0; index < bases.size(); index++) {
|
||||
verify(bases.get(index), times(1 << index)).noise(anyDouble(), anyDouble());
|
||||
clearInvocations(bases.get(index));
|
||||
}
|
||||
|
||||
chain.getFirst().getNoise(71L, 13.25D, -21.75D, null);
|
||||
chain.getFirst().getNoise(71L, 13.25D, -21.75D, RUNTIME);
|
||||
for (int index = 0; index < bases.size(); index++) {
|
||||
verify(bases.get(index), times(index == 0 ? 1 : 2)).noise(anyDouble(), anyDouble());
|
||||
}
|
||||
@@ -70,7 +73,7 @@ public final class IrisNoiseGeneratorFractureTest {
|
||||
public void shallowChainsKeepTheirSamplingCounts() {
|
||||
List<IrisNoiseGenerator> chain = chain(3, NoiseStyle.SIMPLEX);
|
||||
List<NoiseGenerator> bases = spyBases(chain, 71L);
|
||||
chain.getFirst().getNoise(71L, 13.25D, -21.75D, null);
|
||||
chain.getFirst().getNoise(71L, 13.25D, -21.75D, RUNTIME);
|
||||
for (int index = 0; index < bases.size(); index++) {
|
||||
verify(bases.get(index), times(1 << index)).noise(anyDouble(), anyDouble());
|
||||
}
|
||||
@@ -80,18 +83,18 @@ public final class IrisNoiseGeneratorFractureTest {
|
||||
public void changedParametersAndFracturesRemainVisible() {
|
||||
List<IrisNoiseGenerator> chain = chain(5, NoiseStyle.IRIS);
|
||||
IrisNoiseGenerator root = chain.getFirst();
|
||||
assertParity(root, 19L, 31D, -79D, null, null);
|
||||
assertParity(root, 19L, 31D, -79D, RUNTIME);
|
||||
chain.get(3).setOffsetX(-319D).setOffsetZ(17D).setOffsetY(-0.7D)
|
||||
.setSeed(Long.MAX_VALUE).setOpacity(0.35D).setZoom(17D);
|
||||
assertParity(root, 19L, 31D, -79D, null, null);
|
||||
assertParity(root, 19L, 31D, -79D, RUNTIME);
|
||||
chain.get(4).setEnabled(false);
|
||||
assertParity(root, 19L, 31D, -79D, null, null);
|
||||
assertParity(root, 19L, 31D, -79D, RUNTIME);
|
||||
chain.get(4).setEnabled(true);
|
||||
chain.get(2).getFracture().add(new IrisNoiseGenerator().setStyle(NoiseStyle.PERLIN.style()));
|
||||
assertParity(root, 19L, 31D, -79D, null, null);
|
||||
assertParity(root, 19L, 31D, -79D, RUNTIME);
|
||||
chain.get(2).getFracture().removeLast();
|
||||
chain.getLast().getFracture().add(new IrisNoiseGenerator().setStyle(NoiseStyle.SIMPLEX.style()));
|
||||
assertParity(root, 19L, 31D, -79D, null, null);
|
||||
assertParity(root, 19L, 31D, -79D, RUNTIME);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -99,11 +102,11 @@ public final class IrisNoiseGeneratorFractureTest {
|
||||
List<IrisNoiseGenerator> chain = chain(4, NoiseStyle.SIMPLEX);
|
||||
long leafSeed = childSeed(chain, 23L, chain.size() - 1);
|
||||
StatefulNoise stateful = new StatefulNoise();
|
||||
chain.getLast().getGenerator(leafSeed, null, null).setGenerator(stateful);
|
||||
double expected = reference(chain.getFirst(), 23L, 17D, -31D, null, null);
|
||||
chain.getLast().getGenerator(leafSeed, RUNTIME).setGenerator(stateful);
|
||||
double expected = reference(chain.getFirst(), 23L, 17D, -31D, RUNTIME);
|
||||
assertEquals(16, stateful.samples);
|
||||
stateful.samples = 0;
|
||||
double actual = chain.getFirst().getNoise(23L, 17D, -31D, null);
|
||||
double actual = chain.getFirst().getNoise(23L, 17D, -31D, RUNTIME);
|
||||
assertBits(expected, actual);
|
||||
assertEquals(16, stateful.samples);
|
||||
}
|
||||
@@ -113,11 +116,11 @@ public final class IrisNoiseGeneratorFractureTest {
|
||||
List<IrisNoiseGenerator> chain = chain(4, NoiseStyle.SIMPLEX);
|
||||
List<NoiseGenerator> bases = spyBases(chain, 71L);
|
||||
chain.getLast().getStyle().setExpression("custom");
|
||||
chain.getFirst().getNoise(71L, 13.25D, -21.75D, null);
|
||||
chain.getFirst().getNoise(71L, 13.25D, -21.75D, RUNTIME);
|
||||
verify(bases.getLast(), times(16)).noise(anyDouble(), anyDouble());
|
||||
chain.getLast().getStyle().setExpression(null).setImageMap("map");
|
||||
clearInvocations(bases.getLast());
|
||||
chain.getFirst().getNoise(71L, 13.25D, -21.75D, null);
|
||||
chain.getFirst().getNoise(71L, 13.25D, -21.75D, RUNTIME);
|
||||
verify(bases.getLast(), times(16)).noise(anyDouble(), anyDouble());
|
||||
}
|
||||
|
||||
@@ -127,7 +130,7 @@ public final class IrisNoiseGeneratorFractureTest {
|
||||
List<NoiseGenerator> bases = spyBases(chain, 71L);
|
||||
chain.getLast().setStyle(new IrisGeneratorStyle(NoiseStyle.SIMPLEX) {
|
||||
});
|
||||
chain.getFirst().getNoise(71L, 13.25D, -21.75D, null);
|
||||
chain.getFirst().getNoise(71L, 13.25D, -21.75D, RUNTIME);
|
||||
verify(bases.getLast(), times(16)).noise(anyDouble(), anyDouble());
|
||||
}
|
||||
|
||||
@@ -138,9 +141,9 @@ public final class IrisNoiseGeneratorFractureTest {
|
||||
doThrow(new IllegalStateException("sample failed")).doCallRealMethod()
|
||||
.when(bases.getLast()).noise(anyDouble(), anyDouble());
|
||||
assertThrows(IllegalStateException.class,
|
||||
() -> chain.getFirst().getNoise(71L, 13.25D, -21.75D, null));
|
||||
() -> chain.getFirst().getNoise(71L, 13.25D, -21.75D, RUNTIME));
|
||||
clearInvocations(bases.getLast());
|
||||
chain.getFirst().getNoise(71L, 13.25D, -21.75D, null);
|
||||
chain.getFirst().getNoise(71L, 13.25D, -21.75D, RUNTIME);
|
||||
verify(bases.getLast(), times(2)).noise(anyDouble(), anyDouble());
|
||||
}
|
||||
|
||||
@@ -148,24 +151,24 @@ public final class IrisNoiseGeneratorFractureTest {
|
||||
public void threadsAndEngineIdentitiesRemainIndependent() throws Exception {
|
||||
IrisNoiseGenerator root = chain(5, NoiseStyle.IRIS).getFirst();
|
||||
IrisData data = mock(IrisData.class);
|
||||
Engine firstEngine = mock(Engine.class);
|
||||
Engine secondEngine = mock(Engine.class);
|
||||
PackRuntime firstEngine = PackRuntime.forEngine(mock(Engine.class), data);
|
||||
PackRuntime secondEngine = PackRuntime.forEngine(mock(Engine.class), data);
|
||||
CountDownLatch start = new CountDownLatch(1);
|
||||
ExecutorService executor = Executors.newFixedThreadPool(2);
|
||||
try {
|
||||
Future<?> first = executor.submit(() -> sampleConcurrently(root, data, firstEngine, 47L, start));
|
||||
Future<?> second = executor.submit(() -> sampleConcurrently(root, data, secondEngine, -131L, start));
|
||||
Future<?> first = executor.submit(() -> sampleConcurrently(root, firstEngine, 47L, start));
|
||||
Future<?> second = executor.submit(() -> sampleConcurrently(root, secondEngine, -131L, start));
|
||||
start.countDown();
|
||||
first.get(15L, TimeUnit.SECONDS);
|
||||
second.get(15L, TimeUnit.SECONDS);
|
||||
} finally {
|
||||
executor.shutdownNow();
|
||||
}
|
||||
assertParity(root, 47L, 17D, 19D, data, secondEngine);
|
||||
assertParity(root, 47L, 17D, 19D, data, firstEngine);
|
||||
assertParity(root, 47L, 17D, 19D, secondEngine);
|
||||
assertParity(root, 47L, 17D, 19D, firstEngine);
|
||||
}
|
||||
|
||||
private static void sampleConcurrently(IrisNoiseGenerator root, IrisData data, Engine engine,
|
||||
private static void sampleConcurrently(IrisNoiseGenerator root, PackRuntime RUNTIME,
|
||||
long seed, CountDownLatch start) {
|
||||
try {
|
||||
assertTrue(start.await(5L, TimeUnit.SECONDS));
|
||||
@@ -174,7 +177,7 @@ public final class IrisNoiseGeneratorFractureTest {
|
||||
throw new AssertionError(failure);
|
||||
}
|
||||
for (int index = 0; index < 64; index++) {
|
||||
assertParity(root, seed, index * 13.75D, -index * 2.25D, data, engine);
|
||||
assertParity(root, seed, index * 13.75D, -index * 2.25D, RUNTIME);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,7 +201,7 @@ public final class IrisNoiseGeneratorFractureTest {
|
||||
private static List<NoiseGenerator> spyBases(List<IrisNoiseGenerator> nodes, long superSeed) {
|
||||
List<NoiseGenerator> bases = new ArrayList<>(nodes.size());
|
||||
for (IrisNoiseGenerator node : nodes) {
|
||||
CNG generator = node.getGenerator(superSeed, null, null);
|
||||
CNG generator = node.getGenerator(superSeed, RUNTIME);
|
||||
NoiseGenerator base = spy(generator.getGenerator());
|
||||
generator.setGenerator(base);
|
||||
bases.add(base);
|
||||
@@ -215,8 +218,8 @@ public final class IrisNoiseGeneratorFractureTest {
|
||||
}
|
||||
|
||||
private static void assertParity(IrisNoiseGenerator node, long seed, double x, double z,
|
||||
IrisData data, Engine engine) {
|
||||
assertBits(reference(node, seed, x, z, data, engine), node.getNoise(seed, x, z, data, engine));
|
||||
PackRuntime RUNTIME) {
|
||||
assertBits(reference(node, seed, x, z, RUNTIME), node.getNoise(seed, x, z, RUNTIME));
|
||||
}
|
||||
|
||||
private static void assertBits(double expected, double actual) {
|
||||
@@ -224,12 +227,12 @@ public final class IrisNoiseGeneratorFractureTest {
|
||||
}
|
||||
|
||||
private static double reference(IrisNoiseGenerator node, long superSeed, double xv, double zv,
|
||||
IrisData data, Engine engine) {
|
||||
return reference(node, superSeed, xv, zv, data, engine, IrisNoiseGenerator.X_AXIS);
|
||||
PackRuntime RUNTIME) {
|
||||
return reference(node, superSeed, xv, zv, RUNTIME, IrisNoiseGenerator.X_AXIS);
|
||||
}
|
||||
|
||||
private static double reference(IrisNoiseGenerator node, long superSeed, double xv, double zv,
|
||||
IrisData data, Engine engine, int axis) {
|
||||
PackRuntime RUNTIME, int axis) {
|
||||
if (!node.isEnabled()) {
|
||||
return node.getOffsetY();
|
||||
}
|
||||
@@ -240,14 +243,14 @@ public final class IrisNoiseGeneratorFractureTest {
|
||||
if (child.isEnabled()) {
|
||||
double offset = child.getOpacity() / 2D;
|
||||
long childSeed = superSeed + node.getSeed() + salt;
|
||||
x += reference(child, childSeed, xv, zv, data, engine, IrisNoiseGenerator.X_AXIS) - offset;
|
||||
z += reference(child, childSeed, xv, zv, data, engine, IrisNoiseGenerator.Z_AXIS) - offset;
|
||||
x += reference(child, childSeed, xv, zv, RUNTIME, IrisNoiseGenerator.X_AXIS) - offset;
|
||||
z += reference(child, childSeed, xv, zv, RUNTIME, IrisNoiseGenerator.Z_AXIS) - offset;
|
||||
}
|
||||
salt += 819;
|
||||
}
|
||||
double sampleX = (x / node.getZoom()) + node.getOffsetX();
|
||||
double sampleZ = (z / node.getZoom()) + node.getOffsetZ();
|
||||
CNG generator = node.getGenerator(superSeed, data, engine).reseededForAxis(axis);
|
||||
CNG generator = node.getGenerator(superSeed, RUNTIME).reseededForAxis(axis);
|
||||
double result = generator.noiseFast2D(sampleX, sampleZ) * node.getOpacity();
|
||||
result = node.isNegative() ? -result + node.getOpacity() : result;
|
||||
result = (node.getExponent() != 1D ? result < 0D ? -Math.pow(-result, node.getExponent())
|
||||
|
||||
+2
-1
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.generation.noise;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -13,7 +14,7 @@ public class IrisNoiseGeneratorRemapTest {
|
||||
.setStyle(NoiseStyle.FLAT.style())
|
||||
.setOpacity(sample[0])
|
||||
.setParametric(true);
|
||||
assertEquals(sample[1], layer.getNoise(75L, 13D, -21D, null), 0.000000000001D);
|
||||
assertEquals(sample[1], layer.getNoise(75L, 13D, -21D, PackRuntime.standalone(null)), 0.000000000001D);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.generation.noise;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import art.arcane.volmlib.util.noise.CNG;
|
||||
import org.junit.Test;
|
||||
@@ -60,12 +61,12 @@ public class NoiseSeedCohesionTest {
|
||||
public void generatorCacheEvictionRetainsSamples() {
|
||||
for (NoiseStyle style : NoiseStyle.values()) {
|
||||
IrisGeneratorStyle configured = style.style();
|
||||
double[] expected = samples(configured.create(new RNG(SEEDS[0]), null), false);
|
||||
double[] expected = samples(configured.create(new RNG(SEEDS[0]), PackRuntime.standalone(null)), false);
|
||||
for (long seed = 0; seed < 9; seed++) {
|
||||
configured.create(new RNG(seed), null);
|
||||
configured.create(new RNG(seed), PackRuntime.standalone(null));
|
||||
}
|
||||
assertArrayEquals(style.name(), expected,
|
||||
samples(configured.create(new RNG(SEEDS[0]), null), true), 0D);
|
||||
samples(configured.create(new RNG(SEEDS[0]), PackRuntime.standalone(null)), true), 0D);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.generation.noise;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.volmlib.util.noise.CNG;
|
||||
import art.arcane.volmlib.util.noise.NoiseGenerator;
|
||||
@@ -71,8 +72,8 @@ public final class NoiseStyleContractTest {
|
||||
if (style == NoiseStyle.STATIC) {
|
||||
continue;
|
||||
}
|
||||
CNG normal = style.style().createNoCache(new RNG(45231L), null);
|
||||
CNG enlarged = style.style().zoomed(2D).createNoCache(new RNG(45231L), null);
|
||||
CNG normal = style.style().createNoCache(new RNG(45231L), PackRuntime.standalone(null));
|
||||
CNG enlarged = style.style().zoomed(2D).createNoCache(new RNG(45231L), PackRuntime.standalone(null));
|
||||
assertEquals(style.name(), normal.noise(13.25D, -17.75D),
|
||||
enlarged.noise(26.5D, -35.5D), 0.000000001D);
|
||||
assertEquals(style.name(), normal.noise(13.25D), enlarged.noise(26.5D), 0.000000001D);
|
||||
@@ -85,7 +86,7 @@ public final class NoiseStyleContractTest {
|
||||
public void defaultSettingsPreserveEveryPreset() {
|
||||
for (NoiseStyle style : NoiseStyle.values()) {
|
||||
CNG direct = style.create(new RNG(7253L));
|
||||
CNG configured = style.style().createNoCache(new RNG(7253L), null);
|
||||
CNG configured = style.style().createNoCache(new RNG(7253L), PackRuntime.standalone(null));
|
||||
for (int index = 0; index < 32; index++) {
|
||||
double x = index * 19.713D - 400D;
|
||||
double z = index * -31.579D + 100D;
|
||||
@@ -119,16 +120,16 @@ public final class NoiseStyleContractTest {
|
||||
NoiseStyle.IRIS.style().setCellularFrequency(0.7D).setCellularZoom(1.25D)
|
||||
};
|
||||
for (IrisGeneratorStyle style : styles) {
|
||||
CNG normal = style.createNoCache(new RNG(217L), null);
|
||||
CNG enlarged = style.setZoom(2D).createNoCache(new RNG(217L), null);
|
||||
CNG normal = style.createNoCache(new RNG(217L), PackRuntime.standalone(null));
|
||||
CNG enlarged = style.setZoom(2D).createNoCache(new RNG(217L), PackRuntime.standalone(null));
|
||||
assertEquals(normal.noise(19.25D, -71.75D), enlarged.noise(38.5D, -143.5D), 0.000000001D);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void configuredExponentCompoundsThePresetCurve() {
|
||||
CNG base = NoiseStyle.VASCULAR_THIN.style().createNoCache(new RNG(8831L), null);
|
||||
CNG squared = NoiseStyle.VASCULAR_THIN.style().setExponent(2D).createNoCache(new RNG(8831L), null);
|
||||
CNG base = NoiseStyle.VASCULAR_THIN.style().createNoCache(new RNG(8831L), PackRuntime.standalone(null));
|
||||
CNG squared = NoiseStyle.VASCULAR_THIN.style().setExponent(2D).createNoCache(new RNG(8831L), PackRuntime.standalone(null));
|
||||
double value = base.noise(29.5D, -33.25D);
|
||||
assertEquals(value * value, squared.noise(29.5D, -33.25D), 0.000000000001D);
|
||||
}
|
||||
@@ -158,11 +159,11 @@ public final class NoiseStyleContractTest {
|
||||
@Test
|
||||
public void layerOctavesPreserveAndMultiplyPresetDetail() {
|
||||
IrisGeneratorStyle style = NoiseStyle.QUADOCTAVE_SIMPLEX.style();
|
||||
CNG unchanged = style.createForLayer(new RNG(71L), null, 1);
|
||||
CNG detailed = style.createForLayer(new RNG(71L), null, 2);
|
||||
CNG unchanged = style.createForLayer(new RNG(71L), PackRuntime.standalone(null), 1);
|
||||
CNG detailed = style.createForLayer(new RNG(71L), PackRuntime.standalone(null), 2);
|
||||
assertEquals(4, unchanged.getOct());
|
||||
assertEquals(8, detailed.getOct());
|
||||
assertEquals(16, style.createForLayer(new RNG(71L), null, Integer.MAX_VALUE).getOct());
|
||||
assertEquals(16, style.createForLayer(new RNG(71L), PackRuntime.standalone(null), Integer.MAX_VALUE).getOct());
|
||||
assertNotEquals(unchanged.noise(21D, -31D), detailed.noise(21D, -31D), 0D);
|
||||
}
|
||||
|
||||
@@ -172,10 +173,10 @@ public final class NoiseStyleContractTest {
|
||||
IrisData data = mock(IrisData.class);
|
||||
when(data.getDataFolder()).thenReturn(dataFolder);
|
||||
IrisGeneratorStyle cached = NoiseStyle.BIOCTAVE_SIMPLEX.style().setCacheSize(32);
|
||||
CNG first = cached.createForLayer(new RNG(921L), data, 3);
|
||||
CNG reloaded = cached.createForLayer(new RNG(921L), data, 3);
|
||||
CNG uncached = NoiseStyle.BIOCTAVE_SIMPLEX.style().createForLayer(new RNG(921L), data, 3);
|
||||
CNG different = cached.createForLayer(new RNG(921L), data, 1);
|
||||
CNG first = cached.createForLayer(new RNG(921L), PackRuntime.standalone(data), 3);
|
||||
CNG reloaded = cached.createForLayer(new RNG(921L), PackRuntime.standalone(data), 3);
|
||||
CNG uncached = NoiseStyle.BIOCTAVE_SIMPLEX.style().createForLayer(new RNG(921L), PackRuntime.standalone(data), 3);
|
||||
CNG different = cached.createForLayer(new RNG(921L), PackRuntime.standalone(data), 1);
|
||||
assertEquals(6, first.getOct());
|
||||
assertEquals(6, reloaded.getOct());
|
||||
assertEquals(uncached.noise(4D, 7D), first.noise(4D, 7D), 0.000001D);
|
||||
@@ -190,12 +191,12 @@ public final class NoiseStyleContractTest {
|
||||
double[] invalid = {0D, -1D, Double.NaN, Double.POSITIVE_INFINITY, Double.MIN_VALUE};
|
||||
for (double value : invalid) {
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> NoiseStyle.SIMPLEX.style().setZoom(value).createNoCache(new RNG(1L), null));
|
||||
() -> NoiseStyle.SIMPLEX.style().setZoom(value).createNoCache(new RNG(1L), PackRuntime.standalone(null)));
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> NoiseStyle.SIMPLEX.style().setExponent(value).createNoCache(new RNG(1L), null));
|
||||
() -> NoiseStyle.SIMPLEX.style().setExponent(value).createNoCache(new RNG(1L), PackRuntime.standalone(null)));
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> NoiseStyle.SIMPLEX.style().setCellularFrequency(1D).setCellularZoom(value)
|
||||
.createNoCache(new RNG(1L), null));
|
||||
.createNoCache(new RNG(1L), PackRuntime.standalone(null)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.generation.noise;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import art.arcane.volmlib.util.noise.CNG;
|
||||
import org.junit.Test;
|
||||
@@ -18,7 +19,7 @@ public class PatternNoiseStyleTest {
|
||||
public void styleIntegrationUsesTheSameScaleInEveryDimension() {
|
||||
for (NoiseStyle style : STYLES) {
|
||||
CNG direct = style.create(new RNG(7331L));
|
||||
CNG zoomed = style.style().zoomed(2D).createNoCache(new RNG(7331L), null);
|
||||
CNG zoomed = style.style().zoomed(2D).createNoCache(new RNG(7331L), PackRuntime.standalone(null));
|
||||
for (int index = 0; index < 128; index++) {
|
||||
double x = index * 13.713D - 400D;
|
||||
double y = index * 1.119D - 70D;
|
||||
|
||||
+2
-1
@@ -10,6 +10,7 @@ import art.arcane.iris.generation.biome.IrisBiome;
|
||||
import art.arcane.iris.generation.terrain.IrisDimension;
|
||||
import art.arcane.iris.generation.terrain.IrisRegion;
|
||||
import art.arcane.iris.generation.biome.IrisBiomePaletteLayer;
|
||||
import art.arcane.iris.generation.biome.PaletteLayerRuntime;
|
||||
import art.arcane.iris.generation.terrain.IrisSlopeClip;
|
||||
import art.arcane.iris.generation.image.IrisImageMapRuntime;
|
||||
import art.arcane.iris.generation.terrain.Terrain3DColumn;
|
||||
@@ -425,7 +426,7 @@ public class DimensionTerrain3DCompositionTest {
|
||||
when(layer.getSlopeCondition()).thenReturn(slope);
|
||||
when(layer.getHeightGenerator(any(), any())).thenReturn(height);
|
||||
when(height.fit(anyInt(), anyInt(), anyDouble(), anyDouble())).thenReturn(1);
|
||||
when(layer.get(any(), anyInt(), anyDouble(), anyDouble(), anyDouble(), any())).thenReturn(block);
|
||||
when(layer.get(any(), anyInt(), anyDouble(), anyDouble(), anyDouble(), any(PaletteLayerRuntime.class))).thenReturn(block);
|
||||
layers.add(layer);
|
||||
}
|
||||
return new IrisBiome().setLockLayers(locked).setLayers(layers);
|
||||
|
||||
@@ -143,6 +143,7 @@ public class EngineBiomeColumnTest {
|
||||
case "getData" -> data;
|
||||
case "getDimension" -> dimension;
|
||||
case "getWorld" -> world;
|
||||
case "getPackRuntime" -> null;
|
||||
default -> InvocationHandler.invokeDefault(proxy, method, arguments);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package art.arcane.iris.generation.runtime;
|
||||
|
||||
import art.arcane.iris.structure.nativegen.NativeStructureVolumeIndex;
|
||||
import art.arcane.iris.structure.placement.StructureReachability;
|
||||
import art.arcane.iris.structure.placement.StructurePlacementScope;
|
||||
import art.arcane.iris.structure.placement.IrisStructureLocator;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.generation.runtime.EngineRuntimeBuilder.RuntimeAssembly;
|
||||
import art.arcane.iris.structure.nativegen.NativeStructureOwnershipStore;
|
||||
@@ -135,6 +139,25 @@ public class EngineShutdownDrainTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void closedEngineRemovesItselfFromEveryStructureRegistry() throws Exception {
|
||||
ShutdownFixture fixture = new ShutdownFixture();
|
||||
try (MockedStatic<NativeStructureOwnershipStore> ownership = mockStatic(NativeStructureOwnershipStore.class);
|
||||
MockedStatic<IrisStructureLocator> locator = mockStatic(IrisStructureLocator.class);
|
||||
MockedStatic<StructureReachability> reachability = mockStatic(StructureReachability.class);
|
||||
MockedStatic<StructurePlacementScope> scopes = mockStatic(StructurePlacementScope.class);
|
||||
MockedStatic<NativeStructureVolumeIndex> volumes = mockStatic(NativeStructureVolumeIndex.class)) {
|
||||
fixture.shutdown.close();
|
||||
|
||||
assertTrue(fixture.engine.closed);
|
||||
ownership.verify(() -> NativeStructureOwnershipStore.release(fixture.engine));
|
||||
locator.verify(() -> IrisStructureLocator.invalidate(fixture.engine));
|
||||
reachability.verify(() -> StructureReachability.invalidate(fixture.engine));
|
||||
scopes.verify(() -> StructurePlacementScope.invalidate(fixture.engine));
|
||||
volumes.verify(() -> NativeStructureVolumeIndex.uninstall(fixture.engine));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void closingRuntimeAllowsItsBackgroundWorkersToOpenCapturedScopes() throws Exception {
|
||||
ShutdownFixture fixture = new ShutdownFixture();
|
||||
@@ -887,7 +910,7 @@ public class EngineShutdownDrainTest {
|
||||
when(generation.runtimeKernel()).thenReturn(kernel);
|
||||
GenerationRuntime nextGeneration = generation(target, mantle);
|
||||
when(nextGeneration.complex()).thenReturn(replacement);
|
||||
when(generation.withComplex(anyInt(), same(replacement), isNull(), isNull(), any()))
|
||||
when(generation.withComplex(anyInt(), same(replacement), any(), isNull(), isNull(), any()))
|
||||
.thenReturn(nextGeneration);
|
||||
EngineRuntimeBuilder builder = spy(new EngineRuntimeBuilder(engine));
|
||||
doReturn(new GenerationRuntime.BiomeMaxes(0D, 0D, 0D)).when(builder).computeBiomeMaxes();
|
||||
|
||||
+3
-2
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.generation.runtime;
|
||||
|
||||
import art.arcane.iris.testsupport.MockPackData;
|
||||
import art.arcane.iris.generation.biome.IrisBiome;
|
||||
import art.arcane.iris.generation.block.IrisBlockData;
|
||||
import art.arcane.iris.generation.decoration.HydrologyVegetation;
|
||||
@@ -42,7 +43,7 @@ public class HydrologyVegetationSourceTest {
|
||||
private static final Set<String> KNOWN = Set.of("minecraft:air", "minecraft:dirt", "minecraft:fern", "minecraft:sugar_cane",
|
||||
"minecraft:short_grass", "minecraft:dead_bush", "minecraft:poppy", "minecraft:dandelion");
|
||||
|
||||
private final IrisData data = mock(IrisData.class);
|
||||
private final IrisData data = MockPackData.create();
|
||||
private PlantPlatform platform;
|
||||
|
||||
@Before
|
||||
@@ -221,7 +222,7 @@ public class HydrologyVegetationSourceTest {
|
||||
return decorators;
|
||||
}
|
||||
};
|
||||
new HydrologyVegetation(3L, null).decorate(chunk, 8, 8, 8, 8, WaterRole.SHORE, water, data);
|
||||
new HydrologyVegetation(3L, null).decorate(chunk, 8, 8, 8, 8, WaterRole.SHORE, water, data.standalonePackRuntime());
|
||||
return ((PlantBlockState) chunk.get(8, 61, 8)).block();
|
||||
}
|
||||
|
||||
|
||||
+8
-6
@@ -1,10 +1,12 @@
|
||||
package art.arcane.iris.generation.runtime;
|
||||
|
||||
import art.arcane.iris.testsupport.MockPackData;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.generation.mantle.EngineMantle;
|
||||
import art.arcane.iris.generation.stage.IrisCarveModifier;
|
||||
import art.arcane.iris.generation.biome.IrisBiome;
|
||||
import art.arcane.iris.generation.biome.IrisBiomePaletteLayer;
|
||||
import art.arcane.iris.generation.biome.PaletteLayerRuntime;
|
||||
import art.arcane.iris.generation.terrain.IrisDimension;
|
||||
import art.arcane.iris.generation.terrain.IrisDimensionCarvingResolver;
|
||||
import art.arcane.iris.world.IrisWorld;
|
||||
@@ -171,7 +173,7 @@ public class IrisCarveWallPaletteScopeTest {
|
||||
private final MantleChunk<Matter> chunk;
|
||||
private final GenerationRuntime active;
|
||||
private final GenerationRuntime detached;
|
||||
private final IrisData assemblyData = mock(IrisData.class);
|
||||
private final IrisData assemblyData = MockPackData.create();
|
||||
private final IrisComplex assemblyComplex = mock(IrisComplex.class);
|
||||
private final EngineRuntimeBuilder.RuntimeAssembly assembly;
|
||||
private final AtomicInteger dataLookups = new AtomicInteger();
|
||||
@@ -194,8 +196,8 @@ public class IrisCarveWallPaletteScopeTest {
|
||||
doReturn(1).when(chunk).sectionCount();
|
||||
doReturn(true).when(chunk).exists(0);
|
||||
doReturn(section).when(chunk).get(0);
|
||||
active = runtime(mock(IrisData.class), mock(IrisComplex.class), engineMantle);
|
||||
detached = runtime(mock(IrisData.class), mock(IrisComplex.class), engineMantle);
|
||||
active = runtime(MockPackData.create(), mock(IrisComplex.class), engineMantle);
|
||||
detached = runtime(MockPackData.create(), mock(IrisComplex.class), engineMantle);
|
||||
field(engine, IrisEngine.class, "lifecycleLock", new Object());
|
||||
field(engine, IrisEngine.class, "threadState", new EngineThreadState());
|
||||
field(engine, IrisEngine.class, "detachedGenerationRuntimes", Collections.newSetFromMap(new IdentityHashMap<>()));
|
||||
@@ -219,17 +221,17 @@ public class IrisCarveWallPaletteScopeTest {
|
||||
doReturn(engine.getWorld()).when(assemblyTarget).getWorld();
|
||||
doReturn(assemblyData).when(assemblyTarget).getData();
|
||||
doReturn(mock(IrisDimension.class)).when(assemblyTarget).getDimension();
|
||||
assembly = new EngineRuntimeBuilder.RuntimeAssembly(19, assemblyTarget);
|
||||
assembly = new EngineRuntimeBuilder.RuntimeAssembly(engine, 19, assemblyTarget);
|
||||
assembly.complex = assemblyComplex;
|
||||
assembly.mantle = engineMantle;
|
||||
IrisBiome biome = mock(IrisBiome.class);
|
||||
IrisBiomePaletteLayer palette = mock(IrisBiomePaletteLayer.class);
|
||||
doReturn(palette).when(biome).getWall();
|
||||
doAnswer(call -> {
|
||||
assertSame(expectedData, call.getArgument(4));
|
||||
assertSame(expectedData, call.<PaletteLayerRuntime>getArgument(5).packRuntime().data());
|
||||
paletteCalls.incrementAndGet();
|
||||
return wall;
|
||||
}).when(palette).get(any(RNG.class), anyDouble(), anyDouble(), anyDouble(), any(IrisData.class));
|
||||
}).when(palette).get(any(RNG.class), anyInt(), anyDouble(), anyDouble(), anyDouble(), any(PaletteLayerRuntime.class));
|
||||
for (IrisComplex complex : new IrisComplex[]{activeComplex, detachedComplex, assemblyComplex}) {
|
||||
doReturn(ProceduralStream.of((x, z) -> biome, Interpolated.of(value -> 0D, value -> null)))
|
||||
.when(complex).getTrueBiomeStream();
|
||||
|
||||
+3
-3
@@ -171,7 +171,7 @@ public class IrisComplexChunkCornersTest {
|
||||
Class<?> cacheClass = Class.forName("art.arcane.iris.generation.runtime.IrisComplex$GridBoundsCache");
|
||||
Constructor<?> cacheConstructor = cacheClass.getDeclaredConstructor();
|
||||
cacheConstructor.setAccessible(true);
|
||||
setField(complex, "gridBoundsCache", ThreadLocal.withInitial(() -> newCache(cacheConstructor)));
|
||||
setField(complex, "gridBoundsCache", new ThreadSlots<>(() -> newCache(cacheConstructor)));
|
||||
return complex;
|
||||
}
|
||||
|
||||
@@ -257,7 +257,7 @@ public class IrisComplexChunkCornersTest {
|
||||
private boolean nested;
|
||||
|
||||
@Override
|
||||
public double getHeight(double x, double z, long seed) {
|
||||
public double getHeight(PackRuntime runtime, double x, double z, long seed) {
|
||||
if (nested) {
|
||||
return Math.cos(x * 0.13D) * 0.5D;
|
||||
}
|
||||
@@ -281,7 +281,7 @@ public class IrisComplexChunkCornersTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getHeight(double x, double z, long seed) {
|
||||
public double getHeight(PackRuntime runtime, double x, double z, long seed) {
|
||||
invocations++;
|
||||
return Math.sin(x * 0.37D + seed) * Math.cos(z * 0.21D) * amplitude;
|
||||
}
|
||||
|
||||
+7
-7
@@ -32,7 +32,7 @@ public class IrisComplexConstantGeneratorBoundsTest {
|
||||
expected += M.lerp(low, high, noise);
|
||||
}
|
||||
expected /= size;
|
||||
assertBits(expected, IrisComplex.averageGeneratorHeights(generators, low, high, 12D, -9D, 7331L));
|
||||
assertBits(expected, IrisComplex.averageGeneratorHeights(PackRuntime.standalone(null), generators, low, high, 12D, -9D, 7331L));
|
||||
assertEquals(0, generator.calls);
|
||||
}
|
||||
}
|
||||
@@ -44,8 +44,8 @@ public class IrisComplexConstantGeneratorBoundsTest {
|
||||
public void inactiveInvalidNoiseMatchesExistingConstantFitContract() {
|
||||
for (double noise : new double[]{Double.NaN, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY}) {
|
||||
CountingGenerator generator = new CountingGenerator(noise);
|
||||
assertBits(generator.fitDouble(0D, 0D, 7331L, 12D, -9D),
|
||||
IrisComplex.averageGeneratorHeights(new IrisGenerator[]{generator}, 0D, 0D, 12D, -9D, 7331L));
|
||||
assertBits(generator.fitDouble(PackRuntime.standalone(null), 0D, 0D, 7331L, 12D, -9D),
|
||||
IrisComplex.averageGeneratorHeights(PackRuntime.standalone(null), new IrisGenerator[]{generator}, 0D, 0D, 12D, -9D, 7331L));
|
||||
assertEquals(0, generator.calls);
|
||||
assertTrue(Double.isNaN(M.lerp(0D, 0D, noise)));
|
||||
}
|
||||
@@ -58,7 +58,7 @@ public class IrisComplexConstantGeneratorBoundsTest {
|
||||
for (double noise : new double[]{0.3D, -2D, 3D}) {
|
||||
CountingGenerator generator = new CountingGenerator(noise);
|
||||
double expected = (0D + M.lerp(pair[0], pair[1], noise)) / 1;
|
||||
assertBits(expected, IrisComplex.averageGeneratorHeights(new IrisGenerator[]{generator},
|
||||
assertBits(expected, IrisComplex.averageGeneratorHeights(PackRuntime.standalone(null), new IrisGenerator[]{generator},
|
||||
pair[0], pair[1], 12D, -9D, 7331L));
|
||||
assertEquals(1, generator.calls);
|
||||
}
|
||||
@@ -72,7 +72,7 @@ public class IrisComplexConstantGeneratorBoundsTest {
|
||||
CountingGenerator generator = new CountingGenerator(0.3D);
|
||||
generator.setLoadKey("diagnostic/terrain");
|
||||
IllegalStateException failure = assertThrows(IllegalStateException.class,
|
||||
() -> IrisComplex.averageGeneratorHeights(new IrisGenerator[]{generator},
|
||||
() -> IrisComplex.averageGeneratorHeights(PackRuntime.standalone(null), new IrisGenerator[]{generator},
|
||||
bounds[0], bounds[1], 671D, 2437D, 7331L));
|
||||
assertTrue(failure.getMessage().contains("671.0,2437.0"));
|
||||
assertTrue(failure.getMessage().contains("generator=diagnostic/terrain"));
|
||||
@@ -90,7 +90,7 @@ public class IrisComplexConstantGeneratorBoundsTest {
|
||||
invalidGenerator.setLoadKey("diagnostic/cliffs");
|
||||
CountingGenerator unsampled = new CountingGenerator(0.5D);
|
||||
IllegalStateException failure = assertThrows(IllegalStateException.class,
|
||||
() -> IrisComplex.averageGeneratorHeights(new IrisGenerator[]{valid, invalidGenerator, unsampled},
|
||||
() -> IrisComplex.averageGeneratorHeights(PackRuntime.standalone(null), new IrisGenerator[]{valid, invalidGenerator, unsampled},
|
||||
0D, 44D, 671D, 2437D, 7331L));
|
||||
assertTrue(failure.getMessage().contains("671.0,2437.0"));
|
||||
assertTrue(failure.getMessage().contains("generator=diagnostic/cliffs"));
|
||||
@@ -115,7 +115,7 @@ public class IrisComplexConstantGeneratorBoundsTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getHeight(double x, double z, long seed) {
|
||||
public double getHeight(PackRuntime runtime, double x, double z, long seed) {
|
||||
calls++;
|
||||
return value;
|
||||
}
|
||||
|
||||
+3
-3
@@ -60,7 +60,7 @@ public class IrisComplexGeneratorOrderingTest {
|
||||
);
|
||||
double output = 0D;
|
||||
for (IrisComplex.GeneratorGroup group : groups) {
|
||||
output += IrisComplex.averageGeneratorHeights(
|
||||
output += IrisComplex.averageGeneratorHeights(PackRuntime.standalone(null),
|
||||
group.generators(),
|
||||
0D,
|
||||
1D,
|
||||
@@ -78,7 +78,7 @@ public class IrisComplexGeneratorOrderingTest {
|
||||
Map<IrisInterpolator, Set<IrisGenerator>> generators = Map.of();
|
||||
|
||||
assertEquals(0, IrisComplex.freezeGeneratorGroups(generators).length);
|
||||
assertEquals(0D, IrisComplex.averageGeneratorHeights(
|
||||
assertEquals(0D, IrisComplex.averageGeneratorHeights(PackRuntime.standalone(null),
|
||||
new IrisGenerator[0],
|
||||
-1D,
|
||||
1D,
|
||||
@@ -141,7 +141,7 @@ public class IrisComplexGeneratorOrderingTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getHeight(double x, double z, long seed) {
|
||||
public double getHeight(PackRuntime runtime, double x, double z, long seed) {
|
||||
return height;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -247,7 +247,7 @@ public class IrisComplexGridBoundsCacheTest {
|
||||
Class<?> cacheClass = Class.forName("art.arcane.iris.generation.runtime.IrisComplex$GridBoundsCache");
|
||||
Constructor<?> cacheConstructor = cacheClass.getDeclaredConstructor();
|
||||
cacheConstructor.setAccessible(true);
|
||||
ThreadLocal<Object> cache = ThreadLocal.withInitial(() -> newCache(cacheConstructor));
|
||||
ThreadSlots<Object> cache = new ThreadSlots<>(() -> newCache(cacheConstructor));
|
||||
Field gridBoundsCache = IrisComplex.class.getDeclaredField("gridBoundsCache");
|
||||
gridBoundsCache.setAccessible(true);
|
||||
gridBoundsCache.set(complex, cache);
|
||||
@@ -295,7 +295,7 @@ public class IrisComplexGridBoundsCacheTest {
|
||||
private static long invokeCornerBounds(IrisComplex complex, Method method, IrisInterpolator interpolator, int x, int z) throws Exception {
|
||||
Field gridBoundsCache = IrisComplex.class.getDeclaredField("gridBoundsCache");
|
||||
gridBoundsCache.setAccessible(true);
|
||||
ThreadLocal<?> cache = (ThreadLocal<?>) gridBoundsCache.get(complex);
|
||||
ThreadSlots<?> cache = (ThreadSlots<?>) gridBoundsCache.get(complex);
|
||||
return (long) method.invoke(complex, cache.get(), null, interpolator, 0, new IrisGenerator[0], x, z);
|
||||
}
|
||||
|
||||
@@ -392,7 +392,7 @@ public class IrisComplexGridBoundsCacheTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getHeight(double x, double z, long seed) {
|
||||
public double getHeight(PackRuntime runtime, double x, double z, long seed) {
|
||||
invocations++;
|
||||
return value;
|
||||
}
|
||||
|
||||
+1
-1
@@ -106,7 +106,7 @@ public class IrisComplexSelfSelectionTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CNG getChildrenGenerator(long seed, double scale) {
|
||||
public CNG getChildrenGenerator(PackRuntime runtime, long seed, double scale) {
|
||||
return noise;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-3
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.generation.runtime;
|
||||
|
||||
import art.arcane.iris.testsupport.MockPackData;
|
||||
import art.arcane.iris.generation.context.ChunkContext;
|
||||
import art.arcane.iris.world.history.TransitionDisplacementField;
|
||||
import art.arcane.iris.generation.hydrology.raster.ChunkWaterRaster;
|
||||
@@ -671,7 +672,7 @@ public class IrisComplexTransitionTest {
|
||||
|
||||
private Hunk<NativeBlockState> paint(int chunkX) {
|
||||
Engine engine = mock(Engine.class);
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisData data = MockPackData.create();
|
||||
IrisBiome biome = mock(IrisBiome.class);
|
||||
IrisRegion region = new IrisRegion();
|
||||
IrisDimension dimension = new IrisDimension().setBedrock(false).setHideOresForHiddenOre(true);
|
||||
@@ -679,9 +680,9 @@ public class IrisComplexTransitionTest {
|
||||
when(engine.getComplex()).thenReturn(complex);
|
||||
when(engine.getData()).thenReturn(data);
|
||||
when(engine.getSeedManager()).thenReturn(mock(SeedManager.class));
|
||||
when(biome.generateLayers(eq(dimension), anyDouble(), anyDouble(), any(RNG.class), anyInt(), anyInt(), eq(data), same(complex)))
|
||||
when(biome.generateLayers(eq(dimension), anyDouble(), anyDouble(), any(RNG.class), anyInt(), anyInt(), MockPackData.runtimeOf(data), same(complex)))
|
||||
.thenAnswer(invocation -> new KList<>(List.of(stone)));
|
||||
when(biome.generateSeaLayers(anyDouble(), anyDouble(), any(RNG.class), anyInt(), eq(data)))
|
||||
when(biome.generateSeaLayers(anyDouble(), anyDouble(), any(RNG.class), anyInt(), MockPackData.runtimeOf(data)))
|
||||
.thenAnswer(invocation -> new KList<>(Collections.nCopies(seaLayers, ice)));
|
||||
int[] grounds = grounds(chunkX);
|
||||
ChunkContext context = mock(ChunkContext.class);
|
||||
|
||||
+3
-2
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.generation.runtime;
|
||||
|
||||
import art.arcane.iris.testsupport.MockPackData;
|
||||
import art.arcane.iris.generation.runtime.EngineBackgroundTasks.BackgroundTaskDrain;
|
||||
import art.arcane.iris.generation.biome.IrisBiome;
|
||||
import art.arcane.iris.generation.decoration.IrisOreGenerator;
|
||||
@@ -75,7 +76,7 @@ public class IrisEngineGenerationCacheWarmTest {
|
||||
Fixture fixture = fixture();
|
||||
AtomicReference<Callable<Void>> queued = new AtomicReference<>();
|
||||
IllegalStateException expected = new IllegalStateException("cache warm failed");
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisData data = MockPackData.create();
|
||||
IrisOreGenerator ore = mock(IrisOreGenerator.class);
|
||||
IrisBiome biome = new IrisBiome();
|
||||
biome.setLoadKey("failing-ore");
|
||||
@@ -83,7 +84,7 @@ public class IrisEngineGenerationCacheWarmTest {
|
||||
when(fixture.engine().getData()).thenReturn(data);
|
||||
when(fixture.engine().getSeedManager()).thenReturn(mock(SeedManager.class));
|
||||
when(fixture.engine().getAllBiomes()).thenReturn(new KList<>(biome));
|
||||
doThrow(expected).when(ore).warm(any(RNG.class), same(data));
|
||||
doThrow(expected).when(ore).warm(any(RNG.class), MockPackData.runtimeOf(data));
|
||||
try (MockedStatic<J> scheduling = scheduler(queued);
|
||||
MockedStatic<IrisLogging> logging = mockStatic(IrisLogging.class)) {
|
||||
fixture.engine().prepareGenerationCaches(IrisEngine.InitializationMode.WORLD_CREATION, System.nanoTime());
|
||||
|
||||
+6
-2
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.generation.runtime;
|
||||
|
||||
import art.arcane.iris.testsupport.MockPackData;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.generation.hydrology.config.IrisHydrology;
|
||||
import art.arcane.iris.generation.hydrology.engine.HydrologyRuntime;
|
||||
@@ -55,6 +56,7 @@ import java.util.function.IntConsumer;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
@@ -197,8 +199,8 @@ public class IrisEngineGenerationRuntimeScopeTest {
|
||||
when(childBiome.getRarity()).thenReturn(1);
|
||||
when(root.getRealBiome(fixture.data)).thenReturn(parentBiome);
|
||||
when(child.getRealBiome(fixture.data)).thenReturn(childBiome);
|
||||
when(root.getChildrenGenerator(fixture.runtime.seedManager().getCarve() ^ 0x9E3779B97F4A7C15L,
|
||||
fixture.data)).thenReturn(generator);
|
||||
when(root.getChildrenGenerator(eq(fixture.runtime.seedManager().getCarve() ^ 0x9E3779B97F4A7C15L),
|
||||
MockPackData.runtimeOf(fixture.data))).thenReturn(generator);
|
||||
when(fixture.dimension.getCarving()).thenReturn(new KList<>(root));
|
||||
when(fixture.dimension.getCarvingEntryIndex()).thenReturn(Map.of("child", child));
|
||||
expected[index] = childBiome;
|
||||
@@ -816,6 +818,7 @@ public class IrisEngineGenerationRuntimeScopeTest {
|
||||
RuntimeFixture active = runtime(1, 1D, 1D, 1D);
|
||||
IrisEngine engine = engine(active.runtime, mock(EngineEffects.class), mock(EngineWorldManager.class));
|
||||
EngineRuntimeBuilder.RuntimeAssembly assembly = new EngineRuntimeBuilder.RuntimeAssembly(
|
||||
engine,
|
||||
2,
|
||||
active.target,
|
||||
Path.of("build", "test-mantles", "assembly"));
|
||||
@@ -1073,6 +1076,7 @@ public class IrisEngineGenerationRuntimeScopeTest {
|
||||
mock(SeedManager.class),
|
||||
null,
|
||||
complex,
|
||||
PackRuntime.standalone(data),
|
||||
upperContext,
|
||||
dimensionStackContext,
|
||||
mode,
|
||||
|
||||
@@ -92,7 +92,7 @@ public class IrisEngineStreamTypeTest {
|
||||
assertUnknownStream("NOT_A_STREAM", () -> data.getExpressionLoader().load("inline"));
|
||||
assertUnknownStream("NOT_A_STREAM", () -> data.getExpressionLoader().load("snippet"));
|
||||
assertUnknownStream("water_head", () -> data.getExpressionLoader().load("lowercase"));
|
||||
assertUnknownStream("NOT_A_STREAM", () -> new IrisGeneratorStyle().setExpression("inline").create(new RNG(7L), data));
|
||||
assertUnknownStream("NOT_A_STREAM", () -> new IrisGeneratorStyle().setExpression("inline").create(new RNG(7L), PackRuntime.standalone(data)));
|
||||
|
||||
IrisExpression known = data.getExpressionLoader().load("known");
|
||||
assertSame(IrisEngineStreamType.WATER_HEAD, known.getVariables().get(0).getEngineStreamValue());
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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.generation.runtime;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertSame;
|
||||
|
||||
public class RuntimeTableTest {
|
||||
@Test
|
||||
public void buildsOncePerPackObject() {
|
||||
AtomicInteger builds = new AtomicInteger();
|
||||
RuntimeTable<List<String>, Object> table = new RuntimeTable<>(config -> {
|
||||
builds.incrementAndGet();
|
||||
return new Object();
|
||||
});
|
||||
List<String> config = List.of("a");
|
||||
|
||||
assertSame(table.get(config), table.get(config));
|
||||
assertEquals(1, builds.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equalPackObjectsGetTheirOwnRuntime() {
|
||||
RuntimeTable<List<String>, Object> table = new RuntimeTable<>(config -> new Object());
|
||||
|
||||
assertNotSame(table.get(List.of("a")), table.get(new ArrayList<>(List.of("a"))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void builderMayResolveOtherEntriesOfTheSameTable() {
|
||||
RuntimeTable<Integer, Integer>[] holder = new RuntimeTable[1];
|
||||
holder[0] = new RuntimeTable<>(depth -> depth == 0 ? 0 : holder[0].get(depth - 1) + 1);
|
||||
|
||||
assertEquals(Integer.valueOf(3), holder[0].get(3));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* 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.generation.runtime;
|
||||
|
||||
import static org.junit.Assert.assertNull;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.concurrent.atomic.AtomicReferenceArray;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertSame;
|
||||
|
||||
public class ThreadSlotsTest {
|
||||
private static final int THREAD_CHURN = 2_000;
|
||||
|
||||
@Test
|
||||
public void sameThreadGetsItsOwnValueBack() {
|
||||
ThreadSlots<Object> slots = new ThreadSlots<>(Object::new);
|
||||
|
||||
assertSame(slots.get(), slots.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void otherThreadsGetTheirOwnValues() throws Exception {
|
||||
ThreadSlots<Object> slots = new ThreadSlots<>(Object::new);
|
||||
Object callerValue = slots.get();
|
||||
AtomicReference<Object> workerValue = new AtomicReference<>();
|
||||
|
||||
Thread worker = new Thread(() -> workerValue.set(slots.get()));
|
||||
worker.start();
|
||||
worker.join();
|
||||
|
||||
assertNotSame(callerValue, workerValue.get());
|
||||
assertSame(callerValue, slots.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void workerChurnReusesSlotsOfDeadThreads() throws Exception {
|
||||
AtomicInteger created = new AtomicInteger();
|
||||
ThreadSlots<Object> slots = new ThreadSlots<>(() -> {
|
||||
created.incrementAndGet();
|
||||
return new Object();
|
||||
});
|
||||
|
||||
for (int index = 0; index < THREAD_CHURN; index++) {
|
||||
Thread worker = new Thread(slots::get);
|
||||
worker.start();
|
||||
worker.join();
|
||||
}
|
||||
|
||||
assertEquals(THREAD_CHURN, created.get());
|
||||
assertEquals("The table must stay at its fixed size", 256, slotCount(slots));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bindingsStayUnsetUntilBoundAndClearOnRemove() {
|
||||
ThreadSlots<Object> bindings = ThreadSlots.bindings();
|
||||
Object value = new Object();
|
||||
|
||||
assertNull(bindings.get());
|
||||
bindings.set(value);
|
||||
assertSame(value, bindings.get());
|
||||
bindings.remove();
|
||||
assertNull(bindings.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void liveThreadsBeyondTheProbedSlotsKeepTheirValues() throws Exception {
|
||||
ThreadSlots<Object> slots = new ThreadSlots<>(Object::new);
|
||||
int threads = 300;
|
||||
CountDownLatch filled = new CountDownLatch(threads);
|
||||
CountDownLatch release = new CountDownLatch(1);
|
||||
AtomicInteger lost = new AtomicInteger();
|
||||
List<Thread> workers = new ArrayList<>();
|
||||
for (int index = 0; index < threads; index++) {
|
||||
Thread worker = new Thread(() -> {
|
||||
Object first = slots.get();
|
||||
filled.countDown();
|
||||
try {
|
||||
release.await();
|
||||
} catch (InterruptedException interrupted) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
if (slots.get() != first) {
|
||||
lost.incrementAndGet();
|
||||
}
|
||||
});
|
||||
workers.add(worker);
|
||||
worker.start();
|
||||
}
|
||||
filled.await();
|
||||
release.countDown();
|
||||
for (Thread worker : workers) {
|
||||
worker.join();
|
||||
}
|
||||
|
||||
assertEquals(0, lost.get());
|
||||
}
|
||||
|
||||
private static int slotCount(ThreadSlots<?> slots) throws ReflectiveOperationException {
|
||||
Field field = ThreadSlots.class.getDeclaredField("owners");
|
||||
field.setAccessible(true);
|
||||
return ((AtomicReferenceArray<?>) field.get(slots)).length();
|
||||
}
|
||||
}
|
||||
+7
-5
@@ -1,5 +1,7 @@
|
||||
package art.arcane.iris.generation.stage;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.testsupport.MockPackData;
|
||||
import art.arcane.iris.generation.biome.IrisBiome;
|
||||
import art.arcane.iris.generation.biome.IrisBiomePaletteLayer;
|
||||
import art.arcane.iris.generation.biome.IrisSurfaceLayerFallback;
|
||||
@@ -33,7 +35,7 @@ public class IrisCarveModifierLayerMemoTest {
|
||||
|
||||
@Test
|
||||
public void heightFreeFloorLayersIgnoreTheZoneFloor() {
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisData data = MockPackData.create();
|
||||
IrisComplex complex = mock(IrisComplex.class);
|
||||
when(complex.hasTerrain3D()).thenReturn(true);
|
||||
when(complex.terrainSurfaceSlope(anyInt(), anyInt(), anyInt())).thenAnswer(call -> (double) (int) call.getArgument(1));
|
||||
@@ -44,9 +46,9 @@ public class IrisCarveModifierLayerMemoTest {
|
||||
IrisDimension dimension = new IrisDimension().setSurfaceLayerFallback(IrisSurfaceLayerFallback.TOP_LAYER);
|
||||
|
||||
assertTrue(IrisCarveModifier.hasHeightFreeFloorLayers(biome));
|
||||
KList<NativeBlockState> reference = biome.generateLayers(dimension, 14D, -9D, rng, 3, 0, data, complex);
|
||||
KList<NativeBlockState> reference = biome.generateLayers(dimension, 14D, -9D, rng, 3, 0, data.standalonePackRuntime(), complex);
|
||||
for (int floor = -64; floor < 320; floor += 7) {
|
||||
assertEquals(reference, biome.generateLayers(dimension, 14D, -9D, rng, 3, floor, data, complex));
|
||||
assertEquals(reference, biome.generateLayers(dimension, 14D, -9D, rng, 3, floor, data.standalonePackRuntime(), complex));
|
||||
}
|
||||
|
||||
biome.setLockLayers(true);
|
||||
@@ -82,9 +84,9 @@ public class IrisCarveModifierLayerMemoTest {
|
||||
when(layer.getMinHeight()).thenReturn(thickness);
|
||||
when(layer.getMaxHeight()).thenReturn(thickness);
|
||||
when(layer.getSlopeCondition()).thenReturn(slope);
|
||||
when(layer.getHeightGenerator(any(RNG.class), same(data))).thenReturn(height);
|
||||
when(layer.getHeightGenerator(any(RNG.class), MockPackData.runtimeOf(data))).thenReturn(height);
|
||||
when(height.fit(anyInt(), anyInt(), anyDouble(), anyDouble())).thenReturn(thickness);
|
||||
when(layer.get(any(RNG.class), anyInt(), anyDouble(), anyDouble(), anyDouble(), same(data)))
|
||||
when(layer.get(any(RNG.class), anyInt(), anyDouble(), anyDouble(), anyDouble(), MockPackData.paletteLayerRuntimeOf(data)))
|
||||
.thenAnswer(call -> block((int) call.getArgument(1)));
|
||||
return layer;
|
||||
}
|
||||
|
||||
+3
-1
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.generation.stage;
|
||||
|
||||
import art.arcane.iris.testsupport.MockPackData;
|
||||
import art.arcane.iris.generation.block.B;
|
||||
import art.arcane.iris.generation.hydrology.cave.HydrologyCaveAction;
|
||||
import art.arcane.iris.generation.hydrology.cave.HydrologyCaveCell;
|
||||
@@ -157,7 +158,8 @@ public class IrisCarveModifierSubterrainMaskTest {
|
||||
when(engine.getWorld()).thenReturn(IrisWorld.builder().minHeight(MINIMUM_Y).maxHeight(64).build());
|
||||
when(engine.getComplex()).thenReturn(complex);
|
||||
when(engine.getDimension()).thenReturn(new IrisDimension());
|
||||
when(engine.getData()).thenReturn(mock(IrisData.class));
|
||||
IrisData data = MockPackData.create();
|
||||
when(engine.getData()).thenReturn(data);
|
||||
when(complex.getSubterrainPlanner()).thenReturn(planner);
|
||||
when(complex.getHydrologyRuntime()).thenReturn(hydrology);
|
||||
IrisCarveModifier modifier = mock(IrisCarveModifier.class, CALLS_REAL_METHODS);
|
||||
|
||||
+5
-5
@@ -82,7 +82,7 @@ public class IrisDepositModifierContextTest {
|
||||
public void workerPreparationFailurePropagatesAfterAllScopesClose() throws Exception {
|
||||
try (Fixture fixture = new Fixture(mock(IrisEngine.class, RETURNS_DEEP_STUBS), true)) {
|
||||
GenerationClosedException failure = new GenerationClosedException("worker clump preparation failed");
|
||||
doThrow(failure).when(fixture.dimensionDeposit).getClump(any(), any(), any());
|
||||
doThrow(failure).when(fixture.dimensionDeposit).getClump(any(), any());
|
||||
assertSame(failure, assertThrows(GenerationClosedException.class, () ->
|
||||
fixture.modifier.modify(32, -48, Hunk.newArrayHunk(16, 16, 16), true, fixture.context)));
|
||||
verify(fixture.chunk).release();
|
||||
@@ -94,7 +94,7 @@ public class IrisDepositModifierContextTest {
|
||||
@Test
|
||||
public void contentFailureInOneClumpSkipsItAndTheChunkContinues() throws Exception {
|
||||
try (Fixture fixture = new Fixture(mock(IrisEngine.class, RETURNS_DEEP_STUBS), true)) {
|
||||
doThrow(new IllegalArgumentException("bad clump")).when(fixture.dimensionDeposit).getClump(any(), any(), any());
|
||||
doThrow(new IllegalArgumentException("bad clump")).when(fixture.dimensionDeposit).getClump(any(), any());
|
||||
fixture.modifier.modify(32, -48, Hunk.newArrayHunk(16, 16, 16), true, fixture.context);
|
||||
verify(fixture.chunk).release();
|
||||
assertNull(IrisContext.get());
|
||||
@@ -127,7 +127,7 @@ public class IrisDepositModifierContextTest {
|
||||
RejectedExecutionException secondWorker = new RejectedExecutionException("second worker failure");
|
||||
when(fixture.dimensionDeposit.getMinPerChunk()).thenReturn(200);
|
||||
when(fixture.dimensionDeposit.getMaxPerChunk()).thenReturn(200);
|
||||
doThrow(firstWorker, secondWorker).when(fixture.dimensionDeposit).getClump(any(), any(), any());
|
||||
doThrow(firstWorker, secondWorker).when(fixture.dimensionDeposit).getClump(any(), any());
|
||||
assertSame(firstWorker, assertThrows(GenerationClosedException.class, () ->
|
||||
fixture.modifier.modify(32, -48, Hunk.newArrayHunk(16, 16, 16), true, fixture.context)));
|
||||
assertEquals(1, firstWorker.getSuppressed().length);
|
||||
@@ -154,7 +154,7 @@ public class IrisDepositModifierContextTest {
|
||||
|
||||
verify(generator, times(4)).getPerClumpSpawnChance();
|
||||
verify(rng, times(1)).i(0, 5);
|
||||
verify(generator, never()).getClump(any(), any(), any());
|
||||
verify(generator, never()).getClump(any(), any());
|
||||
}
|
||||
|
||||
private static final class Fixture implements AutoCloseable {
|
||||
@@ -222,7 +222,7 @@ public class IrisDepositModifierContextTest {
|
||||
assertEquals(71L, IrisContext.require().getGenerationSessionId());
|
||||
completed.incrementAndGet();
|
||||
return clump;
|
||||
}).when(generator).getClump(any(), any(), any());
|
||||
}).when(generator).getClump(any(), any());
|
||||
}
|
||||
when(dimensionDeposit.getMinPerChunk()).thenReturn(9);
|
||||
when(dimensionDeposit.getMaxPerChunk()).thenReturn(9);
|
||||
|
||||
+1
-1
@@ -359,7 +359,7 @@ public class IrisDepositModifierOrderingTest {
|
||||
clump.getBlocks().put(new IrisBlockVector(x, 0, z), replacement);
|
||||
}
|
||||
}
|
||||
when(generator.getClump(any(), any(), any())).thenAnswer(invocation -> {
|
||||
when(generator.getClump(any(), any())).thenAnswer(invocation -> {
|
||||
if (reverse && name.equals("dimension")) {
|
||||
assertTrue(regionReady.await(10, TimeUnit.SECONDS));
|
||||
} else if (reverse && name.equals("region")) {
|
||||
|
||||
+5
-2
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.generation.stage;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.testsupport.KeyedBlockState;
|
||||
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
@@ -277,6 +278,8 @@ public class IrisDepositModifierParityTest {
|
||||
when(engine.getData()).thenReturn(data);
|
||||
when(engine.getDimensionStackContext()).thenReturn(null);
|
||||
}
|
||||
PackRuntime runtime = PackRuntime.forEngine(engine, engine.getData());
|
||||
when(engine.getPackRuntime()).thenReturn(runtime);
|
||||
when(engine.getCaveBiome(anyInt(), anyInt(), anyInt(), any())).thenAnswer(invocation -> {
|
||||
caveBiomeLookups.incrementAndGet();
|
||||
int x = invocation.getArgument(0);
|
||||
@@ -564,9 +567,9 @@ public class IrisDepositModifierParityTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public IrisObject getClump(Engine engine, RNG rng, IrisData data) {
|
||||
public IrisObject getClump(PackRuntime runtime, RNG rng) {
|
||||
clumps.incrementAndGet();
|
||||
return super.getClump(engine, rng, data);
|
||||
return super.getClump(runtime, rng);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -147,7 +147,7 @@ public class IrisDepositModifierPoolGuardTest {
|
||||
clump.getBlocks().put(new IrisBlockVector(x, 0, z), gravel);
|
||||
}
|
||||
}
|
||||
when(generator.getClump(any(), any(), any())).thenReturn(clump);
|
||||
when(generator.getClump(any(), any())).thenReturn(clump);
|
||||
return generator;
|
||||
}
|
||||
}
|
||||
+6
-3
@@ -1,5 +1,7 @@
|
||||
package art.arcane.iris.generation.stage;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.testsupport.MockPackData;
|
||||
import art.arcane.iris.generation.biome.IrisBiome;
|
||||
import art.arcane.iris.generation.context.ChunkContext;
|
||||
import art.arcane.iris.generation.context.ChunkedDataCache;
|
||||
@@ -25,6 +27,7 @@ import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.same;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
@@ -92,7 +95,7 @@ public class IrisTerrainNormalActuatorBankCutTest {
|
||||
private final IrisComplex complex = mock(IrisComplex.class);
|
||||
|
||||
private Fixture(WaterRole role) {
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisData data = MockPackData.create();
|
||||
IrisBiome biome = mock(IrisBiome.class);
|
||||
IrisRegion region = new IrisRegion();
|
||||
IrisDimension dimension = new IrisDimension()
|
||||
@@ -129,9 +132,9 @@ public class IrisTerrainNormalActuatorBankCutTest {
|
||||
when(context.getFluid()).thenReturn(new ChunkedDataCache<>(
|
||||
ProceduralStream.of((x, z) -> null, Interpolated.of(value -> 0D, value -> null)), 11, -4, false));
|
||||
when(biome.generateLayers(eq(dimension), anyDouble(), anyDouble(), any(RNG.class),
|
||||
anyInt(), anyInt(), eq(data), eq(complex))).thenReturn(new KList<>(List.of(grass, dirt)));
|
||||
anyInt(), anyInt(), MockPackData.runtimeOf(data), eq(complex))).thenReturn(new KList<>(List.of(grass, dirt)));
|
||||
when(biome.generateCeilingLayers(eq(dimension), anyDouble(), anyDouble(), any(RNG.class),
|
||||
anyInt(), anyInt(), eq(data), eq(complex))).thenReturn(new KList<>());
|
||||
anyInt(), anyInt(), MockPackData.runtimeOf(data), eq(complex))).thenReturn(new KList<>());
|
||||
}
|
||||
|
||||
private Hunk<NativeBlockState> actuate() {
|
||||
|
||||
+12
-9
@@ -1,5 +1,7 @@
|
||||
package art.arcane.iris.generation.stage;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.testsupport.MockPackData;
|
||||
import art.arcane.iris.generation.biome.IrisBiome;
|
||||
import art.arcane.iris.generation.block.B;
|
||||
import art.arcane.iris.generation.block.IrisBlockData;
|
||||
@@ -41,6 +43,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.same;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
@@ -110,7 +113,7 @@ public class IrisTerrainNormalActuatorColumnParityTest {
|
||||
private final Engine engine = mock(Engine.class);
|
||||
private final ChunkContext context = mock(ChunkContext.class);
|
||||
private final IrisComplex complex = mock(IrisComplex.class);
|
||||
private final IrisData data = mock(IrisData.class);
|
||||
private final IrisData data = MockPackData.create();
|
||||
private final IrisBiome biome = mock(IrisBiome.class);
|
||||
private final IrisRegion region = new IrisRegion();
|
||||
private final IrisDimension dimension;
|
||||
@@ -203,11 +206,11 @@ public class IrisTerrainNormalActuatorColumnParityTest {
|
||||
when(context.getFluid()).thenReturn(new ChunkedDataCache<>(
|
||||
ProceduralStream.of((x, z) -> fluid, Interpolated.of(value -> 0D, value -> fluid)), X, Z, false));
|
||||
when(biome.generateLayers(eq(dimension), anyDouble(), anyDouble(), any(RNG.class),
|
||||
anyInt(), anyInt(), eq(data), eq(complex))).thenAnswer(invocation -> layers(gravityLayers ? "sand" : "layer", layerCount));
|
||||
when(biome.generateSeaLayers(anyDouble(), anyDouble(), any(RNG.class), anyInt(), eq(data)))
|
||||
anyInt(), anyInt(), MockPackData.runtimeOf(data), eq(complex))).thenAnswer(invocation -> layers(gravityLayers ? "sand" : "layer", layerCount));
|
||||
when(biome.generateSeaLayers(anyDouble(), anyDouble(), any(RNG.class), anyInt(), MockPackData.runtimeOf(data)))
|
||||
.thenAnswer(invocation -> layers("sea", seaCount));
|
||||
when(biome.generateCeilingLayers(eq(dimension), anyDouble(), anyDouble(), any(RNG.class),
|
||||
anyInt(), anyInt(), eq(data), eq(complex))).thenAnswer(invocation -> layers("ceiling", ceilingCount));
|
||||
anyInt(), anyInt(), MockPackData.runtimeOf(data), eq(complex))).thenAnswer(invocation -> layers("ceiling", ceilingCount));
|
||||
when(biome.getSurfaceOreBands()).thenReturn(IrisOreBands.of(biomeSurface));
|
||||
when(biome.getUndergroundOreBands()).thenReturn(IrisOreBands.of(biomeUnderground));
|
||||
description = "he=" + he + " fluid=" + surfaceFluid + " bedrock=" + bedrock + " mapped=" + (mapped != null)
|
||||
@@ -306,7 +309,7 @@ public class IrisTerrainNormalActuatorColumnParityTest {
|
||||
if (i > he && i <= hf) {
|
||||
int fdepth = hf - i;
|
||||
if (seaFloor && fblocks == null) {
|
||||
fblocks = biome.generateSeaLayers(realX, realZ, rng, hf - he, data);
|
||||
fblocks = biome.generateSeaLayers(realX, realZ, rng, hf - he, data.standalonePackRuntime());
|
||||
}
|
||||
h.setRaw(xf, i, zf, HydrologyFluidLayerSelector.select(fblocks, fdepth, columnFluid, !seaFloor || openUnderFall));
|
||||
continue;
|
||||
@@ -319,11 +322,11 @@ public class IrisTerrainNormalActuatorColumnParityTest {
|
||||
}
|
||||
if (blocks == null) {
|
||||
blocks = biome.generateLayers(dimension, realX, realZ, rng,
|
||||
layerSurfaceY, layerSurfaceY, data, complex);
|
||||
layerSurfaceY, layerSurfaceY, data.standalonePackRuntime(), complex);
|
||||
}
|
||||
if (layerCeilingY > 0 && depth >= 2 && i - layerCeilingY < 2) {
|
||||
if (ceilingBlocks == null) {
|
||||
ceilingBlocks = biome.generateCeilingLayers(dimension, realX, realZ, rng, 2, layerCeilingY, data, complex);
|
||||
ceilingBlocks = biome.generateCeilingLayers(dimension, realX, realZ, rng, 2, layerCeilingY, data.standalonePackRuntime(), complex);
|
||||
}
|
||||
int ceilingDepth = i - layerCeilingY;
|
||||
h.setRaw(xf, i, zf, ceilingBlocks.hasIndex(ceilingDepth) ? ceilingBlocks.get(ceilingDepth) : rock);
|
||||
@@ -356,7 +359,7 @@ public class IrisTerrainNormalActuatorColumnParityTest {
|
||||
|
||||
private NativeBlockState scan(KList<IrisOreGenerator> ores, int x, int y, int z) {
|
||||
for (IrisOreGenerator ore : ores) {
|
||||
NativeBlockState state = ore.generate(x, y, z, rng, data);
|
||||
NativeBlockState state = ore.generate(x, y, z, rng, PackRuntime.standalone(data));
|
||||
if (state != null) {
|
||||
return state;
|
||||
}
|
||||
@@ -376,7 +379,7 @@ public class IrisTerrainNormalActuatorColumnParityTest {
|
||||
IrisMaterialPalette palette = mock(IrisMaterialPalette.class);
|
||||
NativeBlockState block = state(name);
|
||||
palettes.put(name, block);
|
||||
when(palette.get(any(RNG.class), anyDouble(), anyDouble(), anyDouble(), eq(data))).thenReturn(block);
|
||||
when(palette.get(any(RNG.class), anyDouble(), anyDouble(), anyDouble(), MockPackData.runtimeOf(data))).thenReturn(block);
|
||||
return palette;
|
||||
}
|
||||
|
||||
|
||||
+10
-7
@@ -1,5 +1,7 @@
|
||||
package art.arcane.iris.generation.stage;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.testsupport.MockPackData;
|
||||
import art.arcane.iris.generation.biome.IrisBiome;
|
||||
import art.arcane.iris.generation.context.ChunkContext;
|
||||
import art.arcane.iris.generation.context.ChunkedDataCache;
|
||||
@@ -29,6 +31,7 @@ import org.junit.Before;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.same;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
@@ -182,7 +185,7 @@ public class IrisTerrainNormalActuatorHydrologyTest {
|
||||
for (int y = GROUND + 1; y < HEAD; y++) {
|
||||
assertSame("the mouth holds the sea fluid at y " + y, mouth.sea, estuary.get(0, y, 0));
|
||||
}
|
||||
verify(mouth.biome).generateSeaLayers(anyDouble(), anyDouble(), any(RNG.class), eq(HEAD - GROUND), eq(mouth.data));
|
||||
verify(mouth.biome).generateSeaLayers(anyDouble(), anyDouble(), any(RNG.class), eq(HEAD - GROUND), MockPackData.runtimeOf(mouth.data));
|
||||
|
||||
Painter frozenMouth = new Painter(WaterRole.MOUTH, HEAD);
|
||||
when(frozenMouth.complex.resolveWaterFluid(11, -4)).thenReturn(frozenMouth.sea);
|
||||
@@ -402,7 +405,7 @@ public class IrisTerrainNormalActuatorHydrologyTest {
|
||||
private static final class Painter {
|
||||
private final Engine engine = mock(Engine.class);
|
||||
private final IrisComplex complex = mock(IrisComplex.class);
|
||||
private final IrisData data = mock(IrisData.class);
|
||||
private final IrisData data = MockPackData.create();
|
||||
private final IrisBiome biome = mock(IrisBiome.class);
|
||||
private final IrisRegion region = new IrisRegion();
|
||||
private final ChunkContext context = mock(ChunkContext.class);
|
||||
@@ -439,7 +442,7 @@ public class IrisTerrainNormalActuatorHydrologyTest {
|
||||
ProceduralStream.of((x, z) -> rock, Interpolated.of(value -> 0D, value -> rock)), 11, -4, false));
|
||||
when(context.getFluid()).thenReturn(new ChunkedDataCache<>(
|
||||
ProceduralStream.of((x, z) -> sea, Interpolated.of(value -> 0D, value -> sea)), 11, -4, false));
|
||||
when(biome.generateSeaLayers(anyDouble(), anyDouble(), any(RNG.class), anyInt(), eq(data)))
|
||||
when(biome.generateSeaLayers(anyDouble(), anyDouble(), any(RNG.class), anyInt(), MockPackData.runtimeOf(data)))
|
||||
.thenAnswer(invocation -> new KList<>(List.of(ice)));
|
||||
layers(grass, dirt);
|
||||
}
|
||||
@@ -453,7 +456,7 @@ public class IrisTerrainNormalActuatorHydrologyTest {
|
||||
}
|
||||
|
||||
private void thickSeaLayers() {
|
||||
when(biome.generateSeaLayers(anyDouble(), anyDouble(), any(RNG.class), anyInt(), eq(data))).thenAnswer(invocation -> {
|
||||
when(biome.generateSeaLayers(anyDouble(), anyDouble(), any(RNG.class), anyInt(), MockPackData.runtimeOf(data))).thenAnswer(invocation -> {
|
||||
KList<NativeBlockState> layers = new KList<>();
|
||||
for (int layer = 0; layer < (int) invocation.getArgument(3); layer++) {
|
||||
layers.add(ice);
|
||||
@@ -475,12 +478,12 @@ public class IrisTerrainNormalActuatorHydrologyTest {
|
||||
when(complex.terrainColumn(11, -4)).thenReturn(carved);
|
||||
when(complex.naturalTerrainColumn(11, -4)).thenReturn(natural);
|
||||
when(biome.generateCeilingLayers(eq(dimension), anyDouble(), anyDouble(), any(RNG.class),
|
||||
anyInt(), anyInt(), eq(data), eq(complex))).thenReturn(new KList<>());
|
||||
anyInt(), anyInt(), MockPackData.runtimeOf(data), eq(complex))).thenReturn(new KList<>());
|
||||
}
|
||||
|
||||
private void layers(NativeBlockState top, NativeBlockState second) {
|
||||
when(biome.generateLayers(eq(dimension), anyDouble(), anyDouble(), any(RNG.class),
|
||||
anyInt(), anyInt(), eq(data), eq(complex))).thenAnswer(invocation -> new KList<>(List.of(top, second)));
|
||||
anyInt(), anyInt(), MockPackData.runtimeOf(data), eq(complex))).thenAnswer(invocation -> new KList<>(List.of(top, second)));
|
||||
}
|
||||
|
||||
private IrisHydrologyMaterials materials(boolean palettes) {
|
||||
@@ -494,7 +497,7 @@ public class IrisTerrainNormalActuatorHydrologyTest {
|
||||
|
||||
private IrisMaterialPalette palette(NativeBlockState block) {
|
||||
IrisMaterialPalette palette = mock(IrisMaterialPalette.class);
|
||||
when(palette.get(any(RNG.class), anyDouble(), anyDouble(), anyDouble(), eq(data))).thenReturn(block);
|
||||
when(palette.get(any(RNG.class), anyDouble(), anyDouble(), anyDouble(), MockPackData.runtimeOf(data))).thenReturn(block);
|
||||
return palette;
|
||||
}
|
||||
|
||||
|
||||
+8
-5
@@ -1,5 +1,7 @@
|
||||
package art.arcane.iris.generation.subterrain;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.testsupport.MockPackData;
|
||||
import art.arcane.iris.generation.biome.IrisBiome;
|
||||
import art.arcane.iris.generation.biome.IrisBiomePaletteLayer;
|
||||
import art.arcane.iris.generation.decoration.IrisDecorationPart;
|
||||
@@ -37,6 +39,7 @@ import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.same;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@@ -235,7 +238,7 @@ public class SubterrainSurfaceMaterialsTest {
|
||||
private final NativeBlockState wall = solid("minecraft:andesite");
|
||||
private final IrisDimension dimension = new IrisDimension();
|
||||
private final IrisComplex complex = mock(IrisComplex.class);
|
||||
private final IrisData data = mock(IrisData.class);
|
||||
private final IrisData data = MockPackData.create();
|
||||
private final IrisBiome biome = mock(IrisBiome.class);
|
||||
private final RNG random = new RNG(44339L);
|
||||
private final SubterrainPlanner planner;
|
||||
@@ -261,8 +264,8 @@ public class SubterrainSurfaceMaterialsTest {
|
||||
when(biome.getDecoratorBucket(IrisDecorationPart.NONE)).thenReturn(new IrisDecorator[0]);
|
||||
IrisBiomePaletteLayer wallPalette = mock(IrisBiomePaletteLayer.class);
|
||||
when(biome.getWall()).thenReturn(wallPalette);
|
||||
when(wallPalette.get(eq(random), anyDouble(), anyDouble(), anyDouble(), eq(data))).thenReturn(wall);
|
||||
when(biome.generateCeilingLayers(eq(dimension), anyDouble(), anyDouble(), eq(random), eq(1), anyInt(), eq(data), eq(complex)))
|
||||
when(wallPalette.get(eq(random), anyDouble(), anyDouble(), anyDouble(), MockPackData.runtimeOf(data))).thenReturn(wall);
|
||||
when(biome.generateCeilingLayers(eq(dimension), anyDouble(), anyDouble(), eq(random), eq(1), anyInt(), MockPackData.runtimeOf(data), eq(complex)))
|
||||
.thenReturn(new KList<>(ceiling));
|
||||
floorPalette(floor);
|
||||
NativeBlockState air = mock(NativeBlockState.class);
|
||||
@@ -335,12 +338,12 @@ public class SubterrainSurfaceMaterialsTest {
|
||||
}
|
||||
|
||||
private void floorPalette(NativeBlockState state) {
|
||||
when(biome.generateLayers(eq(dimension), anyDouble(), anyDouble(), eq(random), eq(1), anyInt(), eq(data), eq(complex)))
|
||||
when(biome.generateLayers(eq(dimension), anyDouble(), anyDouble(), eq(random), eq(1), anyInt(), MockPackData.runtimeOf(data), eq(complex)))
|
||||
.thenReturn(state == null ? new KList<>() : new KList<>(state));
|
||||
}
|
||||
|
||||
private SubterrainSurfaceMaterials materials(List<SubterrainPlan> candidates) {
|
||||
return new SubterrainSurfaceMaterials(planner, candidates, dimension, complex, data, random, -64);
|
||||
return new SubterrainSurfaceMaterials(planner, candidates, dimension, complex, data.standalonePackRuntime(), random, -64);
|
||||
}
|
||||
|
||||
private SubterrainCell cell(SubterrainPosition position) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.generation.terrain;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.generation.noise.NoiseStyle;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
@@ -91,11 +92,11 @@ public class ContinentGeneratorTest {
|
||||
}
|
||||
|
||||
private double[] sampleSharedStyleGenerator(IrisGeneratorStyle style) {
|
||||
return sampleSharedGenerator(style, ContinentGenerator.deriveContinentSeed(new RNG(WORLD_SEED)), packData);
|
||||
return sampleSharedGenerator(style, ContinentGenerator.deriveContinentSeed(new RNG(WORLD_SEED)), PackRuntime.of(packData.getEngine(), packData));
|
||||
}
|
||||
|
||||
private double[] sampleContinentMap(IrisDimension dimension, double[][] blocks) {
|
||||
return sampleAtBlocks(ContinentGenerator.create(dimension, new RNG(WORLD_SEED), packData), blocks);
|
||||
return sampleAtBlocks(ContinentGenerator.create(dimension, new RNG(WORLD_SEED), PackRuntime.of(packData.getEngine(), packData)), blocks);
|
||||
}
|
||||
|
||||
private static double[][] shrinkByContinentZoom(double[][] blocks) {
|
||||
|
||||
+3
-2
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.generation.terrain;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.generation.noise.NoiseStyle;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
@@ -25,7 +26,7 @@ public class IrisDimensionCarvingEntryTest {
|
||||
}
|
||||
|
||||
private double[] sampleSharedChildStyleGeneratorAfterChildrenGeneratorBuilt() {
|
||||
carvingEntry.getChildrenGenerator(WORLD_SEED, packData);
|
||||
carvingEntry.getChildrenGenerator(WORLD_SEED, PackRuntime.of(packData.getEngine(), packData));
|
||||
return sampleSharedChildStyleGenerator(carvingEntry.getChildStyle());
|
||||
}
|
||||
|
||||
@@ -34,7 +35,7 @@ public class IrisDimensionCarvingEntryTest {
|
||||
}
|
||||
|
||||
private double[] sampleSharedChildStyleGenerator(IrisGeneratorStyle childStyle) {
|
||||
return sampleSharedGenerator(childStyle, deriveSharedChildStyleSeed(), packData);
|
||||
return sampleSharedGenerator(childStyle, deriveSharedChildStyleSeed(), PackRuntime.of(packData.getEngine(), packData));
|
||||
}
|
||||
|
||||
private RNG deriveSharedChildStyleSeed() {
|
||||
|
||||
+25
-29
@@ -1,5 +1,7 @@
|
||||
package art.arcane.iris.generation.terrain;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.testsupport.MockPackData;
|
||||
import art.arcane.iris.generation.biome.IrisBiome;
|
||||
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.pack.value.IrisRange;
|
||||
@@ -115,7 +117,7 @@ public class IrisDimensionCarvingResolverParityTest {
|
||||
dimension.getCarvingEntryIndex().put("root-low", parent);
|
||||
CNG generator = mock(CNG.class);
|
||||
doReturn(0.5D, 0D).when(generator).noiseFast2D(-17D, 23D);
|
||||
doReturn(generator).when(parent).getChildrenGenerator(anyLong(), any(IrisData.class));
|
||||
doReturn(generator).when(parent).getChildrenGenerator(anyLong(), any(PackRuntime.class));
|
||||
IrisDimensionCarvingResolver.Snapshot snapshot = IrisDimensionCarvingResolver.snapshot(fixture.engine);
|
||||
|
||||
assertSame(fixture.engine.getData().getBiomeLoader().load("root-low"), snapshot.resolveBiome(-17, 40, 23));
|
||||
@@ -139,7 +141,7 @@ public class IrisDimensionCarvingResolverParityTest {
|
||||
parent.setChildRecursionDepth(1);
|
||||
CNG generator = mock(CNG.class);
|
||||
doReturn(0.5D).when(generator).noiseFast2D(-17D, 23D);
|
||||
doReturn(generator).when(parent).getChildrenGenerator(anyLong(), any(IrisData.class));
|
||||
doReturn(generator).when(parent).getChildrenGenerator(anyLong(), any(PackRuntime.class));
|
||||
|
||||
IrisDimensionCarvingEntry selected = IrisDimensionCarvingResolver.resolveFromRoot(
|
||||
engine, parent, -17, -1500, 23, new IrisDimensionCarvingResolver.State());
|
||||
@@ -159,7 +161,7 @@ public class IrisDimensionCarvingResolverParityTest {
|
||||
child.setWorldYRange(new IrisRange(-20, 20));
|
||||
CNG generator = mock(CNG.class);
|
||||
doReturn(0.5D).when(generator).noiseFast2D(anyDouble(), anyDouble());
|
||||
doReturn(generator).when(parent).getChildrenGenerator(anyLong(), any(IrisData.class));
|
||||
doReturn(generator).when(parent).getChildrenGenerator(anyLong(), any(PackRuntime.class));
|
||||
IrisDimensionCarvingResolver.State state = new IrisDimensionCarvingResolver.State();
|
||||
assertSame(child, IrisDimensionCarvingResolver.resolveFromRoot(fixture.engine, parent, 7, 0, 9, state));
|
||||
assertSame(parent, IrisDimensionCarvingResolver.resolveFromRoot(fixture.engine, parent, 7, 30, 9, state));
|
||||
@@ -175,7 +177,7 @@ public class IrisDimensionCarvingResolverParityTest {
|
||||
parent.setChildren(new KList<>(children));
|
||||
CNG generator = mock(CNG.class);
|
||||
doReturn(0.5D).when(generator).noiseFast2D(anyDouble(), anyDouble());
|
||||
doReturn(generator).when(parent).getChildrenGenerator(anyLong(), any(IrisData.class));
|
||||
doReturn(generator).when(parent).getChildrenGenerator(anyLong(), any(PackRuntime.class));
|
||||
IrisDimensionCarvingResolver.State state = new IrisDimensionCarvingResolver.State();
|
||||
|
||||
for (int worldY = -80; worldY < 140; worldY += 13) {
|
||||
@@ -199,7 +201,7 @@ public class IrisDimensionCarvingResolverParityTest {
|
||||
parent.setChildRecursionDepth(1);
|
||||
CNG generator = mock(CNG.class);
|
||||
doReturn(0.5D).when(generator).noiseFast2D(anyDouble(), anyDouble());
|
||||
doReturn(generator).when(parent).getChildrenGenerator(anyLong(), any(IrisData.class));
|
||||
doReturn(generator).when(parent).getChildrenGenerator(anyLong(), any(PackRuntime.class));
|
||||
IrisDimensionCarvingEntry child = fixture.engine.getDimension().getCarvingEntryIndex().get("child-a");
|
||||
IrisDimensionCarvingResolver.State state = new IrisDimensionCarvingResolver.State();
|
||||
|
||||
@@ -227,7 +229,7 @@ public class IrisDimensionCarvingResolverParityTest {
|
||||
}
|
||||
CNG generator = mock(CNG.class);
|
||||
doReturn(0.5D, 0D).when(generator).noiseFast2D(-17D, 23D);
|
||||
doReturn(generator).when(parent).getChildrenGenerator(anyLong(), any(IrisData.class));
|
||||
doReturn(generator).when(parent).getChildrenGenerator(anyLong(), any(PackRuntime.class));
|
||||
IrisDimensionCarvingEntry child = fixture.engine.getDimension().getCarvingEntryIndex().get("child-a");
|
||||
IrisDimensionCarvingResolver.State state = new IrisDimensionCarvingResolver.State();
|
||||
|
||||
@@ -244,7 +246,7 @@ public class IrisDimensionCarvingResolverParityTest {
|
||||
parent.setChildRecursionDepth(1);
|
||||
CNG generator = mock(CNG.class);
|
||||
doReturn(0.5D).when(generator).noiseFast2D(anyDouble(), anyDouble());
|
||||
doReturn(generator).when(parent).getChildrenGenerator(anyLong(), any(IrisData.class));
|
||||
doReturn(generator).when(parent).getChildrenGenerator(anyLong(), any(PackRuntime.class));
|
||||
IrisDimensionCarvingResolver.State state = new IrisDimensionCarvingResolver.State();
|
||||
IrisDimensionCarvingEntry firstChild = fixture.engine.getDimension().getCarvingEntryIndex().get("child-a");
|
||||
IrisDimensionCarvingEntry replacementChild = replacement.engine.getDimension().getCarvingEntryIndex().get("child-a");
|
||||
@@ -395,7 +397,7 @@ public class IrisDimensionCarvingResolverParityTest {
|
||||
Fixture fixture = createFixture();
|
||||
Engine engine = fixture.engine;
|
||||
IrisData firstData = engine.getData();
|
||||
IrisData replacementData = mock(IrisData.class);
|
||||
IrisData replacementData = MockPackData.create();
|
||||
IrisDimensionCarvingEntry entry = mock(IrisDimensionCarvingEntry.class);
|
||||
IrisBiome firstBiome = new IrisBiome();
|
||||
IrisBiome replacementBiome = new IrisBiome();
|
||||
@@ -430,7 +432,7 @@ public class IrisDimensionCarvingResolverParityTest {
|
||||
Fixture fixture = createFixture();
|
||||
IrisData firstData = fixture.engine.getData();
|
||||
IrisDimension dimension = fixture.engine.getDimension();
|
||||
IrisData replacementData = mock(IrisData.class);
|
||||
IrisData replacementData = MockPackData.create();
|
||||
IrisDimensionCarvingEntry entry = mock(IrisDimensionCarvingEntry.class);
|
||||
IrisBiome firstBiome = new IrisBiome();
|
||||
IrisBiome replacementBiome = new IrisBiome();
|
||||
@@ -470,12 +472,12 @@ public class IrisDimensionCarvingResolverParityTest {
|
||||
}
|
||||
|
||||
@Test(timeout = 20_000L)
|
||||
public void longLivedWorkerDoesNotRetainPopulatedThreadLocalStateOrEngine() throws Exception {
|
||||
public void longLivedWorkerDoesNotRetainPopulatedResolverStateOrEngine() throws Exception {
|
||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
CountDownLatch blockerStarted = new CountDownLatch(1);
|
||||
CountDownLatch releaseBlocker = new CountDownLatch(1);
|
||||
try {
|
||||
LifetimeReferences references = executor.submit(this::populateThreadLocalLifetimeReferences).get();
|
||||
LifetimeReferences references = executor.submit(this::populateResolverStateLifetimeReferences).get();
|
||||
Future<?> blocker = executor.submit(() -> {
|
||||
blockerStarted.countDown();
|
||||
releaseBlocker.await();
|
||||
@@ -494,31 +496,22 @@ public class IrisDimensionCarvingResolverParityTest {
|
||||
}
|
||||
}
|
||||
|
||||
private LifetimeReferences populateThreadLocalLifetimeReferences() throws Exception {
|
||||
private LifetimeReferences populateResolverStateLifetimeReferences() throws Exception {
|
||||
RetainedFixture fixture = createRetainedFixture();
|
||||
assertNotNull(IrisDimensionCarvingResolver.resolveRootEntry(fixture.engine(), 80));
|
||||
|
||||
Field threadStateField = IrisDimensionCarvingResolver.class.getDeclaredField("THREAD_STATE");
|
||||
threadStateField.setAccessible(true);
|
||||
ThreadLocal<?> threadState = (ThreadLocal<?>) threadStateField.get(null);
|
||||
Object value = threadState.get();
|
||||
assertTrue(value instanceof WeakReference<?>);
|
||||
@SuppressWarnings("unchecked")
|
||||
WeakReference<IrisDimensionCarvingResolver.State> state =
|
||||
(WeakReference<IrisDimensionCarvingResolver.State>) value;
|
||||
IrisDimensionCarvingResolver.State populatedState = state.get();
|
||||
assertNotNull(populatedState);
|
||||
IrisDimensionCarvingResolver.State populatedState = fixture.engine().getPackRuntime().carvingResolverState();
|
||||
Field biomeCacheField = IrisDimensionCarvingResolver.State.class.getDeclaredField("biomeCache");
|
||||
biomeCacheField.setAccessible(true);
|
||||
assertFalse(((Map<?, ?>) biomeCacheField.get(populatedState)).isEmpty());
|
||||
return new LifetimeReferences(
|
||||
state,
|
||||
new WeakReference<>(populatedState),
|
||||
new WeakReference<>(fixture.engine()));
|
||||
}
|
||||
|
||||
private static void awaitCollection(LifetimeReferences references) {
|
||||
AtomicInteger attempt = new AtomicInteger();
|
||||
Await.reached("the thread-local State and Engine to be collected", Duration.ofSeconds(5L), () -> {
|
||||
Await.reached("the resolver State and Engine to be collected", Duration.ofSeconds(5L), () -> {
|
||||
System.gc();
|
||||
if (references.state().get() == null
|
||||
&& references.engine().get() == null) {
|
||||
@@ -528,7 +521,7 @@ public class IrisDimensionCarvingResolverParityTest {
|
||||
pressure[0] = (byte) attempt.incrementAndGet();
|
||||
return false;
|
||||
});
|
||||
assertTrue("Thread-local State was retained", references.state().get() == null);
|
||||
assertTrue("Resolver State was retained", references.state().get() == null);
|
||||
assertTrue("Engine was retained", references.engine().get() == null);
|
||||
}
|
||||
|
||||
@@ -547,7 +540,7 @@ public class IrisDimensionCarvingResolverParityTest {
|
||||
}
|
||||
|
||||
private RetainedFixture createRetainedFixture() {
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisData data = MockPackData.create();
|
||||
IrisBiome biome = new IrisBiome();
|
||||
biome.setLoader(data);
|
||||
|
||||
@@ -564,17 +557,20 @@ public class IrisDimensionCarvingResolverParityTest {
|
||||
IrisDimension dimension = new IrisDimension();
|
||||
dimension.setCarving(carvingEntries);
|
||||
|
||||
AtomicReference<PackRuntime> runtime = new AtomicReference<>();
|
||||
Engine engine = (Engine) Proxy.newProxyInstance(
|
||||
Engine.class.getClassLoader(),
|
||||
new Class<?>[]{Engine.class},
|
||||
(proxy, method, arguments) -> switch (method.getName()) {
|
||||
case "getDimension" -> dimension;
|
||||
case "getData" -> data;
|
||||
case "getPackRuntime" -> runtime.get();
|
||||
case "hashCode" -> System.identityHashCode(proxy);
|
||||
case "equals" -> proxy == arguments[0];
|
||||
case "toString" -> "carving-retention-test-engine";
|
||||
default -> throw new UnsupportedOperationException(method.toString());
|
||||
});
|
||||
runtime.set(PackRuntime.forEngine(engine, data));
|
||||
return new RetainedFixture(engine, entry);
|
||||
}
|
||||
|
||||
@@ -602,7 +598,7 @@ public class IrisDimensionCarvingResolverParityTest {
|
||||
doReturn(childBBiome).when(biomeLoader).load("child-b");
|
||||
doReturn(childCBiome).when(biomeLoader).load("child-c");
|
||||
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisData data = MockPackData.create();
|
||||
doReturn(biomeLoader).when(data).getBiomeLoader();
|
||||
|
||||
IrisDimensionCarvingEntry rootLow = buildEntry("root-low", "root-low", new IrisRange(-64, 120), 4, List.of("child-a", "child-b"));
|
||||
@@ -678,7 +674,7 @@ public class IrisDimensionCarvingResolverParityTest {
|
||||
doReturn(childFBiome).when(biomeLoader).load("child-f");
|
||||
doReturn(childGBiome).when(biomeLoader).load("child-g");
|
||||
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisData data = MockPackData.create();
|
||||
doReturn(biomeLoader).when(data).getBiomeLoader();
|
||||
|
||||
IrisDimensionCarvingEntry rootLow = buildEntry("root-low", "root-low", new IrisRange(-64, 120), 7, List.of("child-a", "child-d", "child-e"));
|
||||
@@ -872,7 +868,7 @@ public class IrisDimensionCarvingResolverParityTest {
|
||||
}
|
||||
|
||||
long seed = engine.getSeedManager().getCarve() ^ CHILD_SEED_SALT;
|
||||
CNG childGenerator = parent.getChildrenGenerator(seed, engine.getData());
|
||||
CNG childGenerator = parent.getChildrenGenerator(seed, PackRuntime.of(engine));
|
||||
LegacyCarvingChoice selected = childGenerator.fitRarity(options, worldX, worldZ);
|
||||
if (selected == null || selected.entry == null) {
|
||||
return parent;
|
||||
|
||||
+10
-10
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.generation.terrain;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
||||
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
@@ -29,17 +30,17 @@ public final class IrisMaterialPaletteGeneratorCacheTest {
|
||||
public void callerSeedsDoNotShareAFirstWinnerGenerator() {
|
||||
GeneratorFixture fixture = new GeneratorFixture();
|
||||
|
||||
assertSame(fixture.firstGenerator, fixture.palette.getLayerGenerator(new RNG(11L), fixture.data));
|
||||
assertSame(fixture.secondGenerator, fixture.palette.getLayerGenerator(new RNG(29L), fixture.data));
|
||||
assertSame(fixture.firstGenerator, fixture.palette.getLayerGenerator(new RNG(11L), fixture.data));
|
||||
assertSame(fixture.firstGenerator, fixture.palette.getLayerGenerator(new RNG(11L), fixture.runtime));
|
||||
assertSame(fixture.secondGenerator, fixture.palette.getLayerGenerator(new RNG(29L), fixture.runtime));
|
||||
assertSame(fixture.firstGenerator, fixture.palette.getLayerGenerator(new RNG(11L), fixture.runtime));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void reverseInitializationOrderKeepsSeedAssignments() {
|
||||
GeneratorFixture fixture = new GeneratorFixture();
|
||||
|
||||
assertSame(fixture.secondGenerator, fixture.palette.getLayerGenerator(new RNG(29L), fixture.data));
|
||||
assertSame(fixture.firstGenerator, fixture.palette.getLayerGenerator(new RNG(11L), fixture.data));
|
||||
assertSame(fixture.secondGenerator, fixture.palette.getLayerGenerator(new RNG(29L), fixture.runtime));
|
||||
assertSame(fixture.firstGenerator, fixture.palette.getLayerGenerator(new RNG(11L), fixture.runtime));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -50,11 +51,11 @@ public final class IrisMaterialPaletteGeneratorCacheTest {
|
||||
try {
|
||||
Future<CNG> first = executor.submit(() -> {
|
||||
assertTrue(start.await(5L, TimeUnit.SECONDS));
|
||||
return fixture.palette.getLayerGenerator(new RNG(11L), fixture.data);
|
||||
return fixture.palette.getLayerGenerator(new RNG(11L), fixture.runtime);
|
||||
});
|
||||
Future<CNG> second = executor.submit(() -> {
|
||||
assertTrue(start.await(5L, TimeUnit.SECONDS));
|
||||
return fixture.palette.getLayerGenerator(new RNG(29L), fixture.data);
|
||||
return fixture.palette.getLayerGenerator(new RNG(29L), fixture.runtime);
|
||||
});
|
||||
start.countDown();
|
||||
|
||||
@@ -67,19 +68,18 @@ public final class IrisMaterialPaletteGeneratorCacheTest {
|
||||
|
||||
private static final class GeneratorFixture {
|
||||
private final IrisData data = mock(IrisData.class);
|
||||
private final Engine engine = mock(Engine.class);
|
||||
private final PackRuntime runtime = PackRuntime.forEngine(mock(Engine.class), data);
|
||||
private final IrisGeneratorStyle style = mock(IrisGeneratorStyle.class);
|
||||
private final CNG firstGenerator = mock(CNG.class);
|
||||
private final CNG secondGenerator = mock(CNG.class);
|
||||
private final IrisMaterialPalette palette = new IrisMaterialPalette().qclear().setStyle(style);
|
||||
|
||||
private GeneratorFixture() {
|
||||
when(data.getEngine()).thenReturn(engine);
|
||||
Map<Long, CNG> generators = Map.of(
|
||||
11L + GENERATOR_SALT, firstGenerator,
|
||||
29L + GENERATOR_SALT, secondGenerator
|
||||
);
|
||||
when(style.create(any(RNG.class), same(data), same(engine))).thenAnswer(invocation -> {
|
||||
when(style.createNoCache(any(RNG.class), any())).thenAnswer(invocation -> {
|
||||
RNG rng = invocation.getArgument(0);
|
||||
return generators.get(rng.getSeed());
|
||||
});
|
||||
|
||||
+7
-20
@@ -1,5 +1,7 @@
|
||||
package art.arcane.iris.generation.terrain;
|
||||
|
||||
import art.arcane.iris.generation.noise.GeneratorRuntime;
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.generation.noise.IrisGenerator;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import art.arcane.volmlib.util.noise.CNG;
|
||||
@@ -11,29 +13,14 @@ import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertSame;
|
||||
|
||||
public class TerrainFieldSeedCohesionTest {
|
||||
@Test
|
||||
public void coordinateFracturesSeparateSeedAndSignature() {
|
||||
IrisDimension shared = new IrisDimension();
|
||||
for (long seed : new long[]{91L, 17L, 91L}) {
|
||||
for (int signature : new int[]{73, 211}) {
|
||||
CNG expected = new IrisDimension().getCoordFracture(new RNG(seed), signature);
|
||||
CNG actual = shared.getCoordFracture(new RNG(seed), signature);
|
||||
for (int index = 0; index < 8; index++) {
|
||||
assertEquals(expected.noise(index * 128D - 600D, index * -251D + 300D),
|
||||
actual.noise(index * 128D - 600D, index * -251D + 300D), 0D);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cellGeneratorsRetainSeedAssignments() {
|
||||
IrisGenerator generator = new IrisGenerator();
|
||||
CellGenerator first = generator.getCellGenerator(17L);
|
||||
CellGenerator second = generator.getCellGenerator(91L);
|
||||
GeneratorRuntime generator = PackRuntime.standalone(null).generator(new IrisGenerator());
|
||||
CellGenerator first = generator.cellGenerator(17L);
|
||||
CellGenerator second = generator.cellGenerator(91L);
|
||||
assertNotSame(first, second);
|
||||
assertSame(first, generator.getCellGenerator(17L));
|
||||
CellGenerator expected = new IrisGenerator().getCellGenerator(91L);
|
||||
assertSame(first, generator.cellGenerator(17L));
|
||||
CellGenerator expected = PackRuntime.standalone(null).generator(new IrisGenerator()).cellGenerator(91L);
|
||||
assertEquals(expected.getDistance(17D, -81D), second.getDistance(17D, -81D), 0D);
|
||||
}
|
||||
}
|
||||
+7
-6
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.pack.datapack.export.compile.biome;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.generation.biome.IrisBiome;
|
||||
import art.arcane.iris.generation.stream.RarityStream;
|
||||
import art.arcane.iris.generation.terrain.ContinentGenerator;
|
||||
@@ -40,15 +41,15 @@ final class IrisSelectionReference {
|
||||
loaded.add(region);
|
||||
}
|
||||
}
|
||||
regions = new RarityStream<>(dimension.getRegionStyle().create(rng.nextParallelRNG(883), data).stream().zoom(dimension.getRegionZoom()), loaded);
|
||||
continent = ContinentGenerator.create(dimension, rng, data);
|
||||
regions = new RarityStream<>(dimension.getRegionStyle().create(rng.nextParallelRNG(883), PackRuntime.standalone(data)).stream().zoom(dimension.getRegionZoom()), loaded);
|
||||
continent = ContinentGenerator.create(dimension, rng, PackRuntime.standalone(data));
|
||||
for (IrisRegion region : loaded) {
|
||||
Map<InferredType, RarityStream<IrisBiome>> streams = new EnumMap<>(InferredType.class);
|
||||
streams.put(InferredType.LAND, new RarityStream<>(dimension.getLandBiomeStyle().create(rng.nextParallelRNG(InferredType.LAND.ordinal()), data).stream()
|
||||
streams.put(InferredType.LAND, new RarityStream<>(dimension.getLandBiomeStyle().create(rng.nextParallelRNG(InferredType.LAND.ordinal()), PackRuntime.standalone(data)).stream()
|
||||
.zoom(dimension.getBiomeZoom()).zoom(dimension.getLandZoom()).zoom(region.getLandBiomeZoom()), pool(region.getLandBiomes())));
|
||||
streams.put(InferredType.SEA, new RarityStream<>(dimension.getSeaBiomeStyle().create(rng.nextParallelRNG(InferredType.SEA.ordinal()), data).stream()
|
||||
streams.put(InferredType.SEA, new RarityStream<>(dimension.getSeaBiomeStyle().create(rng.nextParallelRNG(InferredType.SEA.ordinal()), PackRuntime.standalone(data)).stream()
|
||||
.zoom(dimension.getBiomeZoom()).zoom(dimension.getSeaZoom()).zoom(region.getSeaBiomeZoom()), pool(region.getSeaBiomes())));
|
||||
streams.put(InferredType.SHORE, new RarityStream<>(dimension.getShoreBiomeStyle().create(rng.nextParallelRNG(InferredType.SHORE.ordinal()), data).stream()
|
||||
streams.put(InferredType.SHORE, new RarityStream<>(dimension.getShoreBiomeStyle().create(rng.nextParallelRNG(InferredType.SHORE.ordinal()), PackRuntime.standalone(data)).stream()
|
||||
.zoom(dimension.getBiomeZoom()).zoom(region.getShoreBiomeZoom()), pool(region.getShoreBiomes())));
|
||||
picks.put(region, streams);
|
||||
}
|
||||
@@ -85,7 +86,7 @@ final class IrisSelectionReference {
|
||||
long maximum = selection.size() - 1L;
|
||||
IrisBiome selected = maximum <= 0L
|
||||
? selection.get(0L)
|
||||
: selection.get(biome.getChildrenGenerator(childStyleSeed, biome.getChildShrinkFactor()).fit2D(0, (int) maximum, x, z));
|
||||
: selection.get(biome.getChildrenGenerator(data.standalonePackRuntime(), childStyleSeed, biome.getChildShrinkFactor()).fit2D(0, (int) maximum, x, z));
|
||||
if (selected.getLoadKey().equals(biome.getLoadKey())) {
|
||||
return biome;
|
||||
}
|
||||
|
||||
+2
-1
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.pack.datapack.export.compile.decoration;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.pack.datapack.DataVersion;
|
||||
import art.arcane.iris.pack.datapack.export.ExportTestPacks;
|
||||
@@ -461,7 +462,7 @@ public class DecorationStageTest {
|
||||
|
||||
private static GatePattern irisPattern(String styleJson, double chance) {
|
||||
IrisGeneratorStyle style = new Gson().fromJson(styleJson, IrisGeneratorStyle.class);
|
||||
CNG generator = style.create(new RNG(4242L), null);
|
||||
CNG generator = style.create(new RNG(4242L), PackRuntime.standalone(null));
|
||||
double zoom = style.getZoom();
|
||||
return pattern((x, z) -> generator.fitDouble(0.0, 1.0, x / zoom, z / zoom) <= chance);
|
||||
}
|
||||
|
||||
+3
-2
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.pack.datapack.export.compile.noise;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.generation.noise.IrisGenerator;
|
||||
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.generation.noise.IrisNoiseGenerator;
|
||||
@@ -245,7 +246,7 @@ public final class NoiseStyleCompilerTest {
|
||||
NoiseRegistry registry = new NoiseRegistry("iris_export");
|
||||
Field field = SMOOTH.compileLayer(layer, SEED, registry, CAPABILITIES);
|
||||
for (int x = -20; x <= 20; x += 10) {
|
||||
assertEquals(layer.getNoise(SUPER_SEED, x, -x, null), sample(field, registry, x, -x), tolerance);
|
||||
assertEquals(layer.getNoise(SUPER_SEED, x, -x, PackRuntime.standalone(null)), sample(field, registry, x, -x), tolerance);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -253,7 +254,7 @@ public final class NoiseStyleCompilerTest {
|
||||
NoiseRegistry registry = new NoiseRegistry("iris_export");
|
||||
Field field = SMOOTH.compileComposite(generator, SEED, registry, CAPABILITIES);
|
||||
for (int x = -30; x <= 30; x += 15) {
|
||||
assertEquals(generator.getHeight(x, 2 * x, SUPER_SEED), sample(field, registry, x, 2 * x), FLOAT_TOLERANCE);
|
||||
assertEquals(generator.getHeight(PackRuntime.standalone(null), x, 2 * x, SUPER_SEED), sample(field, registry, x, 2 * x), FLOAT_TOLERANCE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-3
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.pack.datapack.export.compile.noise;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.generation.noise.IrisNoiseGenerator;
|
||||
import art.arcane.iris.generation.noise.NoiseStyle;
|
||||
@@ -60,7 +61,7 @@ public final class SmoothNoiseFidelityTest {
|
||||
IrisGeneratorStyle style = new IrisGeneratorStyle(NoiseStyle.SIMPLEX);
|
||||
NoiseRegistry registry = new NoiseRegistry(NAMESPACE);
|
||||
Field field = COMPILER.compile(style, SALT, registry, CAPABILITIES);
|
||||
CNG iris = style.createNoCache(new RNG(IRIS_SEED), null);
|
||||
CNG iris = style.createNoCache(new RNG(IRIS_SEED), PackRuntime.standalone(null));
|
||||
double[] irisValues = grid((x, z) -> iris.noise(x, z), 0, 0, SIZE, STRIDE);
|
||||
double[] lowered = new double[0];
|
||||
for (int window = 0; window < 4; window++) {
|
||||
@@ -76,7 +77,7 @@ public final class SmoothNoiseFidelityTest {
|
||||
IrisGeneratorStyle style = new IrisGeneratorStyle(NoiseStyle.QUADOCTAVE_FRACTAL_FBM_SIMPLEX).zoomed(0.5);
|
||||
NoiseRegistry registry = new NoiseRegistry(NAMESPACE);
|
||||
Field field = COMPILER.compile(style, SALT, registry, CAPABILITIES);
|
||||
CNG iris = style.createNoCache(new RNG(IRIS_SEED), null);
|
||||
CNG iris = style.createNoCache(new RNG(IRIS_SEED), PackRuntime.standalone(null));
|
||||
double[] irisSpectrum = new double[SIZE / 2];
|
||||
double[] loweredSpectrum = new double[SIZE / 2];
|
||||
for (int window = 0; window < WINDOWS.length; window++) {
|
||||
@@ -115,7 +116,7 @@ public final class SmoothNoiseFidelityTest {
|
||||
IrisGeneratorStyle style = new IrisGeneratorStyle(NoiseStyle.NOWHERE).zoomed(0.5);
|
||||
NoiseRegistry registry = new NoiseRegistry(NAMESPACE);
|
||||
Field field = COMPILER.compile(style, SALT, registry, CAPABILITIES);
|
||||
CNG iris = style.createNoCache(new RNG(IRIS_SEED), null);
|
||||
CNG iris = style.createNoCache(new RNG(IRIS_SEED), PackRuntime.standalone(null));
|
||||
long irisFragments = 0L;
|
||||
long loweredFragments = 0L;
|
||||
for (int window = 0; window < WINDOWS.length; window++) {
|
||||
|
||||
+3
-2
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.pack.datapack.export.compile.terrain;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.generation.noise.NoiseStyle;
|
||||
import art.arcane.iris.generation.terrain.IrisDimension;
|
||||
@@ -101,7 +102,7 @@ public class VolumetricCompilerTest {
|
||||
try {
|
||||
NoiseRegistry registry = new NoiseRegistry(TerrainTestSupport.NAMESPACE);
|
||||
Compiled compiled = compile(data, registry, NoiseStyleCompiler.create(new ArrayList<>()), TerrainTestSupport.twoBiomeCodes(registry, 0.0));
|
||||
CNG iris = new IrisGeneratorStyle(NoiseStyle.SIMPLEX).createNoCache(new RNG(MARGINAL_SEED), data);
|
||||
CNG iris = new IrisGeneratorStyle(NoiseStyle.SIMPLEX).createNoCache(new RNG(MARGINAL_SEED), PackRuntime.standalone(data));
|
||||
SplittableRandom random = new SplittableRandom(MARGINAL_SEED);
|
||||
double[] exported = new double[MARGINAL_SAMPLES];
|
||||
double[] expected = new double[MARGINAL_SAMPLES];
|
||||
@@ -129,7 +130,7 @@ public class VolumetricCompilerTest {
|
||||
try {
|
||||
NoiseRegistry registry = new NoiseRegistry(TerrainTestSupport.NAMESPACE);
|
||||
Compiled compiled = compile(data, registry, NoiseStyleCompiler.create(new ArrayList<>()), TerrainTestSupport.twoBiomeCodes(registry, 0.0));
|
||||
CNG iris = new IrisGeneratorStyle(NoiseStyle.SIMPLEX).createNoCache(new RNG(MARGINAL_SEED), data);
|
||||
CNG iris = new IrisGeneratorStyle(NoiseStyle.SIMPLEX).createNoCache(new RNG(MARGINAL_SEED), PackRuntime.standalone(data));
|
||||
SplittableRandom random = new SplittableRandom(MARGINAL_SEED);
|
||||
int exported = 0;
|
||||
int expected = 0;
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package art.arcane.iris.pack.loading;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class IrisDataCloseLoadedUnderTest {
|
||||
@Rule
|
||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
|
||||
@Test
|
||||
public void closesOnlyLoadersInsideTheWorldFolder() throws IOException {
|
||||
Path dimensions = temporaryFolder.newFolder("dimensions").toPath();
|
||||
Path world = dimensions.resolve("studio");
|
||||
Path epochPack = createPack(world.resolve("iris/generation/epochs/a/pack"));
|
||||
Path prefixSiblingPack = createPack(dimensions.resolve("studio-other/iris/pack"));
|
||||
Path sourcePack = createPack(temporaryFolder.newFolder("packs").toPath().resolve("source"));
|
||||
IrisData epochData = IrisData.get(epochPack.toFile());
|
||||
IrisData prefixSiblingData = IrisData.get(prefixSiblingPack.toFile());
|
||||
IrisData sourceData = IrisData.get(sourcePack.toFile());
|
||||
|
||||
try {
|
||||
IrisData.closeLoadedUnder(world.toFile());
|
||||
|
||||
assertTrue(IrisData.getLoaded(epochPack.toFile()).isEmpty());
|
||||
assertTrue(epochData.isClosed());
|
||||
assertSame(prefixSiblingData, IrisData.getLoaded(prefixSiblingPack.toFile()).orElse(null));
|
||||
assertSame(sourceData, IrisData.getLoaded(sourcePack.toFile()).orElse(null));
|
||||
} finally {
|
||||
IrisData.getLoaded(epochPack.toFile()).ifPresent(IrisData::close);
|
||||
IrisData.getLoaded(prefixSiblingPack.toFile()).ifPresent(IrisData::close);
|
||||
IrisData.getLoaded(sourcePack.toFile()).ifPresent(IrisData::close);
|
||||
}
|
||||
}
|
||||
|
||||
private static Path createPack(Path pack) throws IOException {
|
||||
Files.createDirectories(pack.resolve("dimensions"));
|
||||
Files.writeString(pack.resolve("dimensions/" + pack.getFileName() + ".json"), "{}");
|
||||
return pack;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.pack.value;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.generation.noise.IrisGenerator;
|
||||
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.generation.noise.IrisNoiseGenerator;
|
||||
@@ -38,17 +39,17 @@ public class IrisMathNoiseHotPathParityTest {
|
||||
.setStyle(NoiseStyle.PERLIN_IRIS.style())
|
||||
.setExponent(1.15D);
|
||||
|
||||
assertEquals(0.4646529061250786D, noiseGenerator.getNoise(9988L, 31.25D, -17.5D, null), 0D);
|
||||
assertEquals(0.4646529061250786D, noiseGenerator.getNoise(9988L, 31.25D, -17.5D, PackRuntime.standalone(null)), 0D);
|
||||
|
||||
IrisGeneratorStyle style = NoiseStyle.IRIS_DOUBLE.style();
|
||||
assertEquals(0.6855680984398492D, style.createNoCache(new RNG(112233L), null).noiseFast2D(42.5D, -19.75D), 0D);
|
||||
assertEquals(0.6855680984398492D, style.createNoCache(new RNG(112233L), PackRuntime.standalone(null)).noiseFast2D(42.5D, -19.75D), 0D);
|
||||
|
||||
IrisGenerator generator = new IrisGenerator()
|
||||
.setZoom(9.5D)
|
||||
.setOpacity(0.91D)
|
||||
.setComposite(new KList<IrisNoiseGenerator>().qadd(noiseGenerator));
|
||||
|
||||
assertEquals(0.5023367573389593D, generator.getHeight(63.0D, -27.0D, 445566L), 0D);
|
||||
assertEquals(0.5023367573389593D, generator.getHeight(PackRuntime.standalone(null), 63.0D, -27.0D, 445566L), 0D);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -0,0 +1,507 @@
|
||||
package art.arcane.iris.purity;
|
||||
|
||||
import art.arcane.iris.pack.schema.annotation.Snippet;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
import java.util.TreeSet;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
* Pack objects are read-only configuration once loaded. Everything derived for an engine (seeded noise, samplers,
|
||||
* per-chunk memos) lives in runtime objects the engine owns, so a closed engine can never be pinned by a pack object
|
||||
* that outlives it. This gate is the ledger of every non-serialized field on a pack type: each one must be listed as
|
||||
* {@link Kind#CONFIG} (derived from the pack's own content only) or still be pending migration.
|
||||
*/
|
||||
public class PackRuntimeStateGateTest {
|
||||
private static final String IRIS_PACKAGE = "art/arcane/iris";
|
||||
private static final String REGISTRANT = "art/arcane/iris/pack/loading/IrisRegistrant";
|
||||
private static final String SNIPPET_DESCRIPTOR = "Lart/arcane/iris/pack/schema/annotation/Snippet;";
|
||||
private static final List<String> GSON_SKIPPED_TYPES = List.of(
|
||||
"Lart/arcane/volmlib/util/cache/AtomicCache;",
|
||||
"Lart/arcane/volmlib/util/scheduling/ChronoLatch;");
|
||||
private static final List<String> ADDITIONAL_PACK_TYPES = List.of(
|
||||
"art.arcane.iris.generation.block.TileData",
|
||||
"art.arcane.iris.generation.block.LegacyTileData",
|
||||
"art.arcane.iris.world.loot.IrisVanillaLootTable");
|
||||
private static final List<String> ENGINE_TYPES = List.of(
|
||||
"Lart/arcane/iris/generation/runtime/Engine;",
|
||||
"Lart/arcane/iris/generation/runtime/IrisEngine;",
|
||||
"Lart/arcane/iris/generation/runtime/IrisComplex;");
|
||||
private static final String THREAD_LOCAL = "Ljava/lang/ThreadLocal;";
|
||||
private static final List<String> ENGINE_LIFETIME_TYPES = List.of(
|
||||
"Lart/arcane/iris/generation/runtime/Engine;",
|
||||
"Lart/arcane/iris/generation/runtime/IrisEngine;",
|
||||
"Lart/arcane/iris/generation/runtime/IrisComplex;",
|
||||
"Lart/arcane/iris/pack/loading/IrisData;",
|
||||
"Lart/arcane/iris/generation/runtime/ThreadSlots;",
|
||||
"Lart/arcane/iris/world/IrisWorld;",
|
||||
"Lart/arcane/volmlib/nativelib/terrain/NativeWorld;",
|
||||
"Lorg/bukkit/World;");
|
||||
private static final Pattern REFERENCED_TYPE = Pattern.compile("L(art/arcane/iris/[A-Za-z0-9_/$]+)[;<]");
|
||||
|
||||
enum Kind {
|
||||
CONFIG,
|
||||
RUNTIME,
|
||||
THREAD,
|
||||
SCRATCH,
|
||||
STATIC,
|
||||
UNRELATED
|
||||
}
|
||||
|
||||
private record Entry(String owner, String field, Kind kind, String reason) {
|
||||
private String key() {
|
||||
return owner + "#" + field;
|
||||
}
|
||||
}
|
||||
|
||||
private static Entry config(String owner, String field, String reason) {
|
||||
return new Entry(owner, field, Kind.CONFIG, reason);
|
||||
}
|
||||
|
||||
private static final List<Entry> CONFIG_FIELDS = List.of(
|
||||
config("art.arcane.iris.generation.biome.IrisBiome", "biomeScatterResolved", "platform biome resolved from the biome's own key"),
|
||||
config("art.arcane.iris.generation.biome.IrisBiome", "biomeSkyScatterResolved", "platform biome resolved from the biome's own key"),
|
||||
config("art.arcane.iris.generation.biome.IrisBiome", "cacheColor", "preview color computed from the biome's own content"),
|
||||
config("art.arcane.iris.generation.biome.IrisBiome", "cacheColorDecoratorLoad", "preview color computed from the biome's own content"),
|
||||
config("art.arcane.iris.generation.biome.IrisBiome", "cacheColorDepositLoad", "preview color computed from the biome's own content"),
|
||||
config("art.arcane.iris.generation.biome.IrisBiome", "cacheColorLayerLoad", "preview color computed from the biome's own content"),
|
||||
config("art.arcane.iris.generation.biome.IrisBiome", "cacheColorObjectDensity", "preview color computed from the biome's own content"),
|
||||
config("art.arcane.iris.generation.biome.IrisBiome", "carveObjectsCache", "filters the biome's own object placements"),
|
||||
config("art.arcane.iris.generation.biome.IrisBiome", "decoratorBuckets", "groups the biome's own decorators by part"),
|
||||
config("art.arcane.iris.generation.biome.IrisBiome", "derivativeResolved", "platform biome resolved from the biome's own key"),
|
||||
config("art.arcane.iris.generation.biome.IrisBiome", "genCache", "generator links indexed by key from the biome's own list"),
|
||||
config("art.arcane.iris.generation.biome.IrisBiome", "inferredType", "biome context inferred while loading the pack's regions"),
|
||||
config("art.arcane.iris.generation.biome.IrisBiome", "inferredVariants", "biome context inferred while loading the pack's regions"),
|
||||
config("art.arcane.iris.generation.biome.IrisBiome", "maxHeight", "sums the biome's own generator link and object heights"),
|
||||
config("art.arcane.iris.generation.biome.IrisBiome", "maxWithObjectHeight", "sums the biome's own generator link and object heights"),
|
||||
config("art.arcane.iris.generation.biome.IrisBiome", "realCarveBiome", "biome references resolved through the pack's IrisData"),
|
||||
config("art.arcane.iris.generation.biome.IrisBiome", "realChildren", "biome references resolved through the pack's IrisData"),
|
||||
config("art.arcane.iris.generation.biome.IrisBiome", "surfaceObjectsCache", "filters the biome's own object placements"),
|
||||
config("art.arcane.iris.generation.biome.IrisBiome", "surfaceOreBandsCache", "filters and bands the biome's own ore list"),
|
||||
config("art.arcane.iris.generation.biome.IrisBiome", "surfaceOreCache", "filters and bands the biome's own ore list"),
|
||||
config("art.arcane.iris.generation.biome.IrisBiome", "surfaceOreReplaceableBlockData", "parsed block keys from the biome's own list"),
|
||||
config("art.arcane.iris.generation.biome.IrisBiome", "undergroundOreBandsCache", "filters and bands the biome's own ore list"),
|
||||
config("art.arcane.iris.generation.biome.IrisBiome", "undergroundOreCache", "filters and bands the biome's own ore list"),
|
||||
config("art.arcane.iris.generation.biome.IrisBiome", "vanillaDerivativeResolved", "platform biome resolved from the biome's own key"),
|
||||
config("art.arcane.iris.generation.biome.IrisBiomeCustomParticle", "particleResolved", "platform particle resolved from its own key"),
|
||||
config("art.arcane.iris.generation.biome.IrisBiomeCustomSpawn", "typeResolved", "platform entity type resolved from its own key"),
|
||||
config("art.arcane.iris.generation.biome.IrisBiomeGeneratorLink", "gen", "generator resolved through the pack's IrisData"),
|
||||
config("art.arcane.iris.generation.biome.IrisBiomePaletteLayer", "blockData", "block states parsed from the layer's own palette"),
|
||||
config("art.arcane.iris.generation.biome.IrisFloatingChildBiomes", "resolvedBiome", "child biome resolved through the pack's IrisData"),
|
||||
config("art.arcane.iris.generation.biome.IrisFloatingChildBiomes", "shrinkScaleCache", "object scale built from the child's own shrink factor"),
|
||||
config("art.arcane.iris.generation.block.IrisBlockData", "blockdata", "block state parsed from its own key through the pack's IrisData"),
|
||||
config("art.arcane.iris.generation.block.IrisBlockData", "realProperties", "block state parsed from its own key through the pack's IrisData"),
|
||||
config("art.arcane.iris.generation.block.VectorMap", "orderedSnapshot", "ordered view of the map's own entries"),
|
||||
config("art.arcane.iris.generation.decoration.IrisDecorator", "blacklistArray", "block states parsed from the decorator's own palettes"),
|
||||
config("art.arcane.iris.generation.decoration.IrisDecorator", "blockData", "block states parsed from the decorator's own palettes"),
|
||||
config("art.arcane.iris.generation.decoration.IrisDecorator", "blockDataArray", "block states parsed from the decorator's own palettes"),
|
||||
config("art.arcane.iris.generation.decoration.IrisDecorator", "blockDataTops", "block states parsed from the decorator's own palettes"),
|
||||
config("art.arcane.iris.generation.decoration.IrisDecorator", "blockDataTopsArray", "block states parsed from the decorator's own palettes"),
|
||||
config("art.arcane.iris.generation.decoration.IrisDecorator", "whitelistArray", "block states parsed from the decorator's own palettes"),
|
||||
config("art.arcane.iris.generation.decoration.IrisDepositGenerator", "blockData", "block states parsed from the deposit's own palette"),
|
||||
config("art.arcane.iris.generation.decoration.IrisDepositGenerator", "ore", "block states parsed from the deposit's own palette"),
|
||||
config("art.arcane.iris.generation.decoration.IrisDepositGenerator", "replaceableBlockData", "block states parsed from the deposit's own palette"),
|
||||
config("art.arcane.iris.generation.decoration.IrisDepositGenerator", "surfaceReplaceableBlockData", "block states parsed from the deposit's own palette"),
|
||||
config("art.arcane.iris.generation.decoration.IrisDepositVariant", "resolved", "block states parsed from the variant's own palette"),
|
||||
config("art.arcane.iris.generation.decoration.coral.IrisCoral", "variantCache", "variants baked from the decorator's own seed and shape settings"),
|
||||
config("art.arcane.iris.generation.decoration.crystal.IrisCrystal", "variantCache", "variants baked from the decorator's own seed and shape settings"),
|
||||
config("art.arcane.iris.generation.decoration.formation.IrisFormation", "variantCache", "variants baked from the decorator's own seed and shape settings"),
|
||||
config("art.arcane.iris.generation.decoration.fungus.IrisFungus", "variantCache", "variants baked from the decorator's own seed and shape settings"),
|
||||
config("art.arcane.iris.generation.decoration.ruin.IrisRuin", "variantCache", "variants baked from the decorator's own seed and shape settings"),
|
||||
config("art.arcane.iris.generation.decoration.tree.IrisProceduralTree", "variantCache", "variants baked from the decorator's own seed and shape settings"),
|
||||
config("art.arcane.iris.generation.terrain.IrisDimension", "carvingEntryIndex", "carving entries indexed from the dimension's own list"),
|
||||
config("art.arcane.iris.generation.terrain.IrisDimension", "cosr", "trigonometry of the dimension's own angle"),
|
||||
config("art.arcane.iris.generation.terrain.IrisDimension", "rad", "trigonometry of the dimension's own angle"),
|
||||
config("art.arcane.iris.generation.terrain.IrisDimension", "sinr", "trigonometry of the dimension's own angle"),
|
||||
config("art.arcane.iris.generation.terrain.IrisDimension", "staticObjectLayer", "static object layer compiled from the dimension's own placements"),
|
||||
config("art.arcane.iris.generation.terrain.IrisDimension", "surfaceOreBandsCache", "filters and bands the dimension's own ore list"),
|
||||
config("art.arcane.iris.generation.terrain.IrisDimension", "surfaceOreCache", "filters and bands the dimension's own ore list"),
|
||||
config("art.arcane.iris.generation.terrain.IrisDimension", "undergroundOreBandsCache", "filters and bands the dimension's own ore list"),
|
||||
config("art.arcane.iris.generation.terrain.IrisDimension", "undergroundOreCache", "filters and bands the dimension's own ore list"),
|
||||
config("art.arcane.iris.generation.terrain.IrisDimension", "undergroundSpawnTables", "spawner references resolved through the pack's IrisData"),
|
||||
config("art.arcane.iris.generation.terrain.IrisDimensionCarvingEntry", "realBiome", "carving biome resolved through the pack's IrisData"),
|
||||
config("art.arcane.iris.generation.terrain.IrisMaterialPalette", "blockData", "block states parsed from the palette's own entries"),
|
||||
config("art.arcane.iris.generation.terrain.IrisMaterialPalette", "fallback", "constant default stone entry of the palette"),
|
||||
config("art.arcane.iris.generation.terrain.IrisRegion", "cacheColor", "preview color computed from the region's own content"),
|
||||
config("art.arcane.iris.generation.terrain.IrisRegion", "cacheRidge", "biome keys collected from the region's own lists"),
|
||||
config("art.arcane.iris.generation.terrain.IrisRegion", "cacheSpot", "biome keys collected from the region's own lists"),
|
||||
config("art.arcane.iris.generation.terrain.IrisRegion", "carveObjectsCache", "filters the region's own object placements"),
|
||||
config("art.arcane.iris.generation.terrain.IrisRegion", "realCaveBiomes", "biome pools resolved through the pack's IrisData"),
|
||||
config("art.arcane.iris.generation.terrain.IrisRegion", "realLandBiomes", "biome pools resolved through the pack's IrisData"),
|
||||
config("art.arcane.iris.generation.terrain.IrisRegion", "realSeaBiomes", "biome pools resolved through the pack's IrisData"),
|
||||
config("art.arcane.iris.generation.terrain.IrisRegion", "realShoreBiomes", "biome pools resolved through the pack's IrisData"),
|
||||
config("art.arcane.iris.generation.terrain.IrisRegion", "shoreHeightGenerator", "noise seeded only from the region's own name and biome settings"),
|
||||
config("art.arcane.iris.generation.terrain.IrisRegion", "surfaceObjectsCache", "filters the region's own object placements"),
|
||||
config("art.arcane.iris.generation.terrain.IrisRegion", "surfaceOreBandsCache", "filters and bands the region's own ore list"),
|
||||
config("art.arcane.iris.generation.terrain.IrisRegion", "surfaceOreCache", "filters and bands the region's own ore list"),
|
||||
config("art.arcane.iris.generation.terrain.IrisRegion", "undergroundOreBandsCache", "filters and bands the region's own ore list"),
|
||||
config("art.arcane.iris.generation.terrain.IrisRegion", "undergroundOreCache", "filters and bands the region's own ore list"),
|
||||
config("art.arcane.iris.pack.loading.IrisRegistrant", "compat", "compatibility status of the object's own content"),
|
||||
config("art.arcane.iris.pack.loading.IrisRegistrant", "loadFile", "the key and file this object was loaded from"),
|
||||
config("art.arcane.iris.pack.loading.IrisRegistrant", "loadKey", "the key and file this object was loaded from"),
|
||||
config("art.arcane.iris.pack.loading.IrisRegistrant", "loader", "the IrisData that loaded this object"),
|
||||
config("art.arcane.iris.pack.value.IrisColor", "color", "color parsed from its own hex or channels"),
|
||||
config("art.arcane.iris.structure.object.IrisAxisRotationClamp", "forceLock", "lock flag derived from the clamp's own settings"),
|
||||
config("art.arcane.iris.structure.object.IrisObject", "aabb", "geometry derived from the object's own blocks"),
|
||||
config("art.arcane.iris.structure.object.IrisObject", "center", "geometry derived from the object's own blocks"),
|
||||
config("art.arcane.iris.structure.object.IrisObject", "floatingFootprint", "geometry derived from the object's own blocks"),
|
||||
config("art.arcane.iris.structure.object.IrisObject", "placementBakes", "rotated block layouts keyed only by rotation and translation"),
|
||||
config("art.arcane.iris.structure.object.IrisObject", "placementLayout", "rotated block layouts keyed only by rotation and translation"),
|
||||
config("art.arcane.iris.structure.object.IrisObject", "readLock", "guards the object's own block data"),
|
||||
config("art.arcane.iris.structure.object.IrisObject", "shrinkOffset", "geometry derived from the object's own blocks"),
|
||||
config("art.arcane.iris.structure.object.IrisObject", "smartBoreVariant", "shape variant derived from the object's own blocks"),
|
||||
config("art.arcane.iris.structure.object.IrisObject", "smartBored", "shape variant derived from the object's own blocks"),
|
||||
config("art.arcane.iris.structure.object.IrisObject", "surfaceSupportOffsets", "geometry derived from the object's own blocks"),
|
||||
config("art.arcane.iris.structure.object.IrisObject", "treeGrounding", "grounding offsets of a tree object's own trunk"),
|
||||
config("art.arcane.iris.structure.object.IrisObject", "writeLock", "guards the object's own block data"),
|
||||
config("art.arcane.iris.structure.object.IrisObjectLoot", "filterCache", "block states parsed from its own filter list"),
|
||||
config("art.arcane.iris.structure.object.IrisObjectMarker", "findData", "block states parsed from its own marker list"),
|
||||
config("art.arcane.iris.structure.object.IrisObjectPlacement", "cache", "loot tables resolved through the pack's IrisData"),
|
||||
config("art.arcane.iris.structure.object.IrisObjectPlacement", "compatCache", "compatibility of the placement's own object keys"),
|
||||
config("art.arcane.iris.structure.object.IrisObjectPlacement", "compatPlaceCache", "compatibility of the placement's own object keys"),
|
||||
config("art.arcane.iris.structure.object.IrisObjectReplace", "findData", "block states parsed from its own lists"),
|
||||
config("art.arcane.iris.structure.object.IrisObjectReplace", "replaceData", "block states parsed from its own lists"),
|
||||
config("art.arcane.iris.structure.object.IrisObjectRotation", "stateRotations", "rotated block states keyed by state and rotation step"),
|
||||
config("art.arcane.iris.structure.object.IrisObjectVanillaLoot", "filterCache", "block states parsed from its own filter list"),
|
||||
config("art.arcane.iris.world.entity.IrisEffect", "particleEffectResolved", "platform types resolved from the effect's own keys"),
|
||||
config("art.arcane.iris.world.entity.IrisEffect", "pt", "platform types resolved from the effect's own keys"),
|
||||
config("art.arcane.iris.world.entity.IrisEffect", "soundResolved", "platform types resolved from the effect's own keys"),
|
||||
config("art.arcane.iris.world.entity.IrisEntitySpawn", "ent", "entity resolved through the pack's IrisData"),
|
||||
config("art.arcane.iris.world.entity.IrisPotionEffect", "pt", "potion type resolved from its own key"),
|
||||
config("art.arcane.iris.world.loot.IrisBlockDrops", "data", "block data parsed from its own list"),
|
||||
config("art.arcane.iris.world.loot.IrisLoot", "dyeColorResolved", "dye color parsed from its own key"),
|
||||
config("art.arcane.iris.world.loot.IrisLootReference", "tt", "loot tables resolved through the pack's IrisData"),
|
||||
config("art.arcane.iris.world.loot.IrisVanillaLootTable", "resolvedKey", "namespaced key parsed from its own string")
|
||||
);
|
||||
|
||||
@Test
|
||||
public void everyNonSerializedPackFieldIsInTheLedger() throws Exception {
|
||||
Map<String, Entry> ledger = ledger();
|
||||
PackTypes types = PackTypes.scan();
|
||||
List<String> unlisted = new ArrayList<>();
|
||||
for (String type : types.packTypes()) {
|
||||
for (ClassFileFacts.DeclaredField field : types.facts(type).fields()) {
|
||||
if (!isNonSerializedState(field)) {
|
||||
continue;
|
||||
}
|
||||
String key = type + "#" + field.name();
|
||||
if (!ledger.containsKey(key)) {
|
||||
unlisted.add(key + " : " + (field.signature() == null ? field.descriptor() : field.signature()));
|
||||
}
|
||||
}
|
||||
}
|
||||
assertTrue("Non-serialized pack fields missing from the ledger. Derived engine state belongs in a runtime "
|
||||
+ "object the engine owns; list only content-derived values as CONFIG:" + join(unlisted), unlisted.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void everyThreadLocalAndEngineHoldingStaticIsInTheLedger() throws Exception {
|
||||
PackTypes types = PackTypes.scan();
|
||||
Map<String, Entry> ledger = holderLedger();
|
||||
List<String> unlisted = new ArrayList<>();
|
||||
for (Map.Entry<String, ClassFileFacts> type : types.all().entrySet()) {
|
||||
for (ClassFileFacts.DeclaredField field : type.getValue().fields()) {
|
||||
if (!isThreadLocal(field) && !(field.isStatic() && holdsEngineLifetimeState(field))) {
|
||||
continue;
|
||||
}
|
||||
String key = type.getKey() + "#" + field.name();
|
||||
if (!ledger.containsKey(key)) {
|
||||
unlisted.add(key + " : " + (field.signature() == null ? field.descriptor() : field.signature()));
|
||||
}
|
||||
}
|
||||
}
|
||||
assertTrue("Thread-locals and static holders missing from the ledger:" + join(unlisted), unlisted.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void everyLedgerEntryStillExists() throws Exception {
|
||||
PackTypes types = PackTypes.scan();
|
||||
List<String> stale = new ArrayList<>();
|
||||
for (List<Entry> list : List.of(CONFIG_FIELDS, SETTLED_HOLDERS, ENGINE_PARAMETERS)) {
|
||||
for (Entry entry : list) {
|
||||
if (!types.declares(entry.owner(), entry.field())) {
|
||||
stale.add(entry.key());
|
||||
}
|
||||
}
|
||||
}
|
||||
assertTrue("Ledger entries for fields that no longer exist; remove them:" + join(stale), stale.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void configAllowlistHoldsOnlyConfigEntries() {
|
||||
for (Entry entry : CONFIG_FIELDS) {
|
||||
assertTrue(entry.key() + " is not CONFIG", entry.kind() == Kind.CONFIG);
|
||||
assertTrue(entry.key() + " needs a reason", !entry.reason().isBlank());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void packTypesHoldNoEngineReference() throws Exception {
|
||||
PackTypes types = PackTypes.scan();
|
||||
Set<String> exempt = keys(ENGINE_PARAMETERS);
|
||||
List<String> failures = new ArrayList<>();
|
||||
for (String type : types.packTypesWithNested()) {
|
||||
for (ClassFileFacts.DeclaredField field : types.facts(type).fields()) {
|
||||
if (exempt.contains(type + "#" + field.name())) {
|
||||
continue;
|
||||
}
|
||||
for (String engineType : ENGINE_TYPES) {
|
||||
if (mentions(field, engineType)) {
|
||||
failures.add(type + "#" + field.name() + " : " + engineType);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!failures.isEmpty()) {
|
||||
fail("Pack types must not hold an engine; move the derived value into an engine-owned runtime object:"
|
||||
+ join(failures));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scanFindsThePackTypes() throws Exception {
|
||||
PackTypes types = PackTypes.scan();
|
||||
assertTrue("expected the scan to find the biome type", types.packTypes().contains("art.arcane.iris.generation.biome.IrisBiome"));
|
||||
assertTrue("expected the scan to follow field types to nested config", types.packTypes().contains("art.arcane.iris.generation.noise.IrisGeneratorStyle"));
|
||||
assertTrue("expected more than 100 pack types, found " + types.packTypes().size(), types.packTypes().size() > 100);
|
||||
}
|
||||
|
||||
private static boolean isThreadLocal(ClassFileFacts.DeclaredField field) {
|
||||
return field.descriptor().equals(THREAD_LOCAL);
|
||||
}
|
||||
|
||||
private static boolean holdsEngineLifetimeState(ClassFileFacts.DeclaredField field) {
|
||||
for (String type : ENGINE_LIFETIME_TYPES) {
|
||||
if (mentions(field, type)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isNonSerializedState(ClassFileFacts.DeclaredField field) {
|
||||
if (field.isStatic()) {
|
||||
return false;
|
||||
}
|
||||
return field.isTransient() || GSON_SKIPPED_TYPES.contains(field.descriptor());
|
||||
}
|
||||
|
||||
private static boolean mentions(ClassFileFacts.DeclaredField field, String descriptor) {
|
||||
String bare = descriptor.substring(0, descriptor.length() - 1);
|
||||
return field.descriptor().contains(descriptor)
|
||||
|| (field.signature() != null && (field.signature().contains(descriptor) || field.signature().contains(bare + "<")));
|
||||
}
|
||||
|
||||
private static final List<Entry> ENGINE_PARAMETERS = List.of(
|
||||
holder("art.arcane.iris.generation.runtime.IrisEngineStreamType", "getter", Kind.CONFIG,
|
||||
"a function that takes the engine as its argument, stores none"),
|
||||
holder("art.arcane.iris.generation.runtime.IrisEngineValueType", "getter", Kind.CONFIG,
|
||||
"a function that takes the engine as its argument, stores none"),
|
||||
holder("art.arcane.iris.generation.terrain.IrisDimensionModeType", "factory", Kind.CONFIG,
|
||||
"a function that takes the engine as its argument, stores none"),
|
||||
holder("art.arcane.iris.world.entity.IrisEntity$BukkitOps$1", "val$gen", Kind.UNRELATED,
|
||||
"loot table adapter attached to a spawned entity, never stored on the pack object")
|
||||
);
|
||||
|
||||
private static final List<Entry> SETTLED_HOLDERS = List.of(
|
||||
holder("art.arcane.iris.generation.biome.FloatingIslandSample", "LAST_DENSITY", Kind.SCRATCH, "the last cluster diagnostic doubles, no engine or pack reference"),
|
||||
holder("art.arcane.iris.generation.biome.FloatingIslandSample", "LAST_REJECT", Kind.SCRATCH, "the last reject code, no engine or pack reference"),
|
||||
holder("art.arcane.iris.generation.noise.ExpressionRuntime", "EVALUATION_SCRATCH", Kind.SCRATCH, "per-depth double argument arrays, no engine or pack reference"),
|
||||
holder("art.arcane.iris.generation.bake.ChunkBakeCache", "SPARSE", Kind.SCRATCH, "a per-thread sparse-bake depth counter, no engine or pack reference"),
|
||||
holder("art.arcane.iris.generation.context.IrisContext", "OVERFLOW", Kind.SCRATCH, "a scoped context binding removed when the thread's outermost scope closes"),
|
||||
holder("art.arcane.iris.generation.decoration.DecoratorCore", "SCRATCH_OPTS", Kind.SCRATCH, "placement flags; the mantle reference is cleared when each placement returns"),
|
||||
holder("art.arcane.iris.generation.decoration.IrisDepositGenerator", "FOOTPRINT_CELLS", Kind.SCRATCH, "primitive footprint cell buffers, no engine or pack reference"),
|
||||
holder("art.arcane.iris.generation.mantle.CarveOrphanSweep", "SCRATCH", Kind.SCRATCH, "primitive sweep buffers, no engine or pack reference"),
|
||||
holder("art.arcane.iris.generation.mantle.CaveLatticeBatch", "CURRENT", Kind.SCRATCH, "primitive noise and lattice buffers, no engine or pack reference"),
|
||||
holder("art.arcane.iris.generation.mantle.MantleCarvingComponent", "BLEND_SCRATCH", Kind.SCRATCH, "profile, biome and region slots cleared by release when each chunk returns"),
|
||||
holder("art.arcane.iris.generation.noise.IrisNoiseGenerator", "FRACTURE_SAMPLES", Kind.SCRATCH, "fracture node and generator slots cleared when each sample returns"),
|
||||
holder("art.arcane.iris.generation.runtime.IrisComplex", "BATCH_SCRATCH", Kind.SCRATCH, "primitive noise batch buffers, no engine or pack reference"),
|
||||
holder("art.arcane.iris.generation.runtime.PaintedColumnRuns", "SCRATCH", Kind.SCRATCH, "primitive run buffers, no engine or pack reference"),
|
||||
holder("art.arcane.iris.generation.stage.IrisCarveModifier", "SCRATCH", Kind.SCRATCH, "carve masks, cavern and biome memos released when each chunk is carved"),
|
||||
holder("art.arcane.iris.generation.stream.ProvisionalSampling", "TRACKERS", Kind.SCRATCH, "a per-thread provisional revision counter, no engine or pack reference"),
|
||||
holder("art.arcane.iris.generation.terrain.Terrain3DFragmentFilter", "TRAVERSALS", Kind.SCRATCH, "traversal buffers whose column slots are cleared after each classification"),
|
||||
holder("art.arcane.iris.structure.object.IrisSurfaceSupport", "STENCIL", Kind.SCRATCH, "primitive stencil buffers, no engine or pack reference"),
|
||||
holder("art.arcane.iris.world.history.NativeTerrainReceipt", "DEFLATERS", Kind.SCRATCH, "a reusable zlib deflater, no engine or pack reference"),
|
||||
holder("art.arcane.iris.world.history.SavedBiomeStore", "DEFLATERS", Kind.SCRATCH, "a reusable zlib deflater, no engine or pack reference"),
|
||||
holder("art.arcane.iris.world.storage.matter.IrisMatterContext", "DATA", Kind.SCRATCH, "a scoped pack data binding removed when the thread's outermost scope closes"),
|
||||
holder("art.arcane.iris.world.tree.TreeSVC", "REENTRANT", Kind.SCRATCH, "a reentrancy flag, no engine or pack reference"),
|
||||
holder("art.arcane.iris.structure.nativegen.NativeStructureOwnershipStore", "STATES", Kind.STATIC, "live-engine registry; a closed engine releases its store in the shutdown sequence (EngineShutdownDrainTest)"),
|
||||
holder("art.arcane.iris.structure.nativegen.NativeStructureVolumeIndex", "INDEXES", Kind.STATIC, "live-engine registry; a closed engine uninstalls its index in the shutdown sequence (EngineShutdownDrainTest)"),
|
||||
holder("art.arcane.iris.structure.placement.IrisStructureLocator", "INDEX_CACHE", Kind.STATIC, "live-engine registry; a closed engine invalidates its index in the shutdown sequence (EngineShutdownDrainTest)"),
|
||||
holder("art.arcane.iris.structure.placement.IrisStructureLocator", "LOCATABLE_INDEX_CACHE", Kind.STATIC, "live-engine registry; a closed engine invalidates its index in the shutdown sequence (EngineShutdownDrainTest)"),
|
||||
holder("art.arcane.iris.structure.placement.StructurePlacementScope", "SCOPE_INDEXES", Kind.STATIC, "live-engine registry; a closed engine invalidates its index in the shutdown sequence (EngineShutdownDrainTest)"),
|
||||
holder("art.arcane.iris.structure.placement.StructureReachability", "REACHABLE_CACHE", Kind.STATIC, "live-engine registry; a closed engine invalidates its keys in the shutdown sequence (EngineShutdownDrainTest)"),
|
||||
holder("art.arcane.iris.generation.runtime.EngineTickRegistry", "TICK_ENGINES", Kind.STATIC, "live-engine registry; every engine unregisters itself when it closes (EngineReleaseProbeTest)"),
|
||||
holder("art.arcane.iris.pack.loading.IrisData", "ENGINE_HOLDERS", Kind.STATIC, "pack data with live engines; an engine unregisters from its pack data when it closes (EngineReleaseProbeTest)"),
|
||||
holder("art.arcane.iris.pack.loading.IrisData", "dataLoaders", Kind.STATIC, "pack data by folder; pack data drops each engine that closes (EngineReleaseProbeTest)"),
|
||||
holder("art.arcane.iris.studio.object.ObjectStudioActivation", "SOURCES", Kind.STATIC, "studio object source packs, removed when the studio pack deactivates; pack data holds no closed engine"),
|
||||
holder("art.arcane.iris.generation.runtime.EnginePanic$Diagnostics", "current", Kind.UNRELATED, "panic diagnostics strings for crash reports"),
|
||||
holder("art.arcane.iris.pack.IrisPackBenchmarking", "instance", Kind.UNRELATED, "benchmark command session")
|
||||
);
|
||||
|
||||
private static Entry holder(String owner, String field, Kind kind, String reason) {
|
||||
return new Entry(owner, field, kind, reason);
|
||||
}
|
||||
|
||||
private static Set<String> keys(List<Entry> entries) {
|
||||
Set<String> keys = new TreeSet<>();
|
||||
for (Entry entry : entries) {
|
||||
keys.add(entry.key());
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
private static Map<String, Entry> holderLedger() {
|
||||
Map<String, Entry> entries = new LinkedHashMap<>();
|
||||
for (Entry entry : SETTLED_HOLDERS) {
|
||||
if (entries.put(entry.key(), entry) != null) {
|
||||
fail("Duplicate holder ledger entry " + entry.key());
|
||||
}
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
|
||||
private static Map<String, Entry> ledger() {
|
||||
Map<String, Entry> entries = new LinkedHashMap<>();
|
||||
for (Entry entry : CONFIG_FIELDS) {
|
||||
if (entries.put(entry.key(), entry) != null) {
|
||||
fail("Duplicate ledger entry " + entry.key());
|
||||
}
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
|
||||
private static String join(List<String> lines) {
|
||||
StringBuilder out = new StringBuilder();
|
||||
for (String line : lines) {
|
||||
out.append("\n ").append(line);
|
||||
}
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
private record PackTypes(Map<String, ClassFileFacts> all, Set<String> packTypes) {
|
||||
private static PackTypes scan() throws Exception {
|
||||
Map<String, ClassFileFacts> all = new TreeMap<>();
|
||||
ClassLoader loader = PackRuntimeStateGateTest.class.getClassLoader();
|
||||
for (String name : classNamesUnder(IRIS_PACKAGE)) {
|
||||
byte[] bytes = BukkitHidingClassLoader.readClassBytes(loader, name);
|
||||
if (bytes != null) {
|
||||
all.put(name, ClassFileFacts.read(bytes));
|
||||
}
|
||||
}
|
||||
Set<String> roots = new TreeSet<>(ADDITIONAL_PACK_TYPES);
|
||||
for (Map.Entry<String, ClassFileFacts> entry : all.entrySet()) {
|
||||
if (entry.getValue().hasClassAnnotation(SNIPPET_DESCRIPTOR) || extendsRegistrant(entry.getValue(), all)) {
|
||||
roots.add(entry.getKey());
|
||||
}
|
||||
}
|
||||
Set<String> packTypes = new TreeSet<>();
|
||||
List<String> queue = new ArrayList<>(roots);
|
||||
while (!queue.isEmpty()) {
|
||||
String type = queue.removeLast();
|
||||
ClassFileFacts facts = all.get(type);
|
||||
if (facts == null || !packTypes.add(type)) {
|
||||
continue;
|
||||
}
|
||||
if (facts.superName() != null) {
|
||||
queue.add(facts.superName().replace('/', '.'));
|
||||
}
|
||||
for (ClassFileFacts.DeclaredField field : facts.fields()) {
|
||||
if (field.isStatic() || field.isTransient() || GSON_SKIPPED_TYPES.contains(field.descriptor())) {
|
||||
continue;
|
||||
}
|
||||
queue.addAll(referencedTypes(field));
|
||||
}
|
||||
}
|
||||
return new PackTypes(all, packTypes);
|
||||
}
|
||||
|
||||
private ClassFileFacts facts(String type) {
|
||||
return all.get(type);
|
||||
}
|
||||
|
||||
private boolean declares(String type, String fieldName) {
|
||||
ClassFileFacts facts = all.get(type);
|
||||
if (facts == null) {
|
||||
return false;
|
||||
}
|
||||
for (ClassFileFacts.DeclaredField field : facts.fields()) {
|
||||
if (field.name().equals(fieldName)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private Set<String> packTypesWithNested() {
|
||||
Set<String> types = new TreeSet<>(packTypes);
|
||||
for (String candidate : all.keySet()) {
|
||||
int nested = candidate.indexOf('$');
|
||||
if (nested > 0 && packTypes.contains(candidate.substring(0, nested))) {
|
||||
types.add(candidate);
|
||||
}
|
||||
}
|
||||
return types;
|
||||
}
|
||||
|
||||
private static boolean extendsRegistrant(ClassFileFacts facts, Map<String, ClassFileFacts> all) {
|
||||
ClassFileFacts current = facts;
|
||||
while (current != null && current.superName() != null) {
|
||||
if (current.superName().equals(REGISTRANT)) {
|
||||
return true;
|
||||
}
|
||||
current = all.get(current.superName().replace('/', '.'));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static List<String> referencedTypes(ClassFileFacts.DeclaredField field) {
|
||||
List<String> types = new ArrayList<>();
|
||||
collect(field.descriptor(), types);
|
||||
if (field.signature() != null) {
|
||||
collect(field.signature(), types);
|
||||
}
|
||||
return types;
|
||||
}
|
||||
|
||||
private static void collect(String text, List<String> sink) {
|
||||
Matcher matcher = REFERENCED_TYPE.matcher(text);
|
||||
while (matcher.find()) {
|
||||
sink.add(matcher.group(1).replace('/', '.'));
|
||||
}
|
||||
}
|
||||
|
||||
private static List<String> classNamesUnder(String packageInternalName) throws Exception {
|
||||
URL location = Snippet.class.getProtectionDomain().getCodeSource().getLocation();
|
||||
Path root = Paths.get(location.toURI());
|
||||
List<String> names = new ArrayList<>();
|
||||
if (!Files.isDirectory(root)) {
|
||||
throw new IOException("Pack type scan expects a class directory, found " + root);
|
||||
}
|
||||
try (Stream<Path> walk = Files.walk(root.resolve(packageInternalName))) {
|
||||
walk.filter(path -> path.toString().endsWith(".class")).forEach(path -> {
|
||||
String relative = root.relativize(path).toString().replace(File.separatorChar, '/');
|
||||
names.add(relative.substring(0, relative.length() - ".class".length()).replace('/', '.'));
|
||||
});
|
||||
}
|
||||
return names;
|
||||
}
|
||||
}
|
||||
}
|
||||
+20
@@ -1,5 +1,8 @@
|
||||
package art.arcane.iris.structure.nativegen;
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Cache;
|
||||
import java.lang.reflect.Field;
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
|
||||
import art.arcane.iris.generation.runtime.IrisEngine;
|
||||
@@ -221,6 +224,23 @@ public class NativeStructureOwnershipStoreTest {
|
||||
record.structureKey(), record.originChunkX(), record.originChunkZ()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void releasedStoreOfAClosedEngineCannotReopen() throws Exception {
|
||||
Engine engine = engine();
|
||||
NativeStructureOwnershipStore.close(engine);
|
||||
when(engine.isClosed()).thenReturn(true);
|
||||
|
||||
NativeStructureOwnershipStore.release(engine);
|
||||
|
||||
Field states = NativeStructureOwnershipStore.class.getDeclaredField("STATES");
|
||||
states.setAccessible(true);
|
||||
@SuppressWarnings("unchecked")
|
||||
Cache<Engine, ?> stores = (Cache<Engine, ?>) states.get(null);
|
||||
assertNull(stores.getIfPresent(engine));
|
||||
assertThrows(IllegalStateException.class, () ->
|
||||
NativeStructureOwnershipStore.findPersisted(engine, "test:after_release", 0, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void explicitCloseCreatesAndRetainsAClosedOwnershipState() {
|
||||
Engine engine = engine();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.structure.object;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import org.junit.Test;
|
||||
@@ -15,11 +16,11 @@ public class HeightmapObjectPlacerTest {
|
||||
Engine engine = mock(Engine.class);
|
||||
IObjectPlacer ownedDelegate = mock(IObjectPlacer.class);
|
||||
when(ownedDelegate.getEngine()).thenReturn(engine);
|
||||
HeightmapObjectPlacer owned = new HeightmapObjectPlacer(mock(RNG.class), 1, 2, 3, new IrisObjectPlacement(), ownedDelegate);
|
||||
HeightmapObjectPlacer owned = new HeightmapObjectPlacer(mock(RNG.class), 1, 2, 3, new IrisObjectPlacement(), ownedDelegate, PackRuntime.standalone(null));
|
||||
assertSame(engine, owned.getEngine());
|
||||
|
||||
IObjectPlacer unownedDelegate = mock(IObjectPlacer.class);
|
||||
HeightmapObjectPlacer unowned = new HeightmapObjectPlacer(mock(RNG.class), 1, 2, 3, new IrisObjectPlacement(), unownedDelegate);
|
||||
HeightmapObjectPlacer unowned = new HeightmapObjectPlacer(mock(RNG.class), 1, 2, 3, new IrisObjectPlacement(), unownedDelegate, PackRuntime.standalone(null));
|
||||
assertNull(unowned.getEngine());
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.structure.object;
|
||||
|
||||
import art.arcane.iris.testsupport.MockPackData;
|
||||
import art.arcane.iris.generation.terrain.IrisSlopeClip;
|
||||
|
||||
import art.arcane.iris.generation.noise.IrisNoiseGenerator;
|
||||
@@ -74,7 +75,7 @@ public class IrisObjectPlacementLifecycleRegressionTest {
|
||||
|
||||
engine = mock(Engine.class);
|
||||
when(engine.getHeight()).thenReturn(256);
|
||||
data = mock(IrisData.class);
|
||||
data = MockPackData.create();
|
||||
when(data.getEngine()).thenReturn(engine);
|
||||
solid = state("minecraft:stone", true);
|
||||
schematicAir = state("minecraft:air", false);
|
||||
|
||||
+11
-9
@@ -1,5 +1,7 @@
|
||||
package art.arcane.iris.structure.object;
|
||||
|
||||
import art.arcane.iris.testsupport.MockPackData;
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.generation.block.TileData;
|
||||
import art.arcane.iris.generation.geometry.IrisBlockVector;
|
||||
import art.arcane.iris.generation.decoration.IrisStiltSettings;
|
||||
@@ -85,7 +87,7 @@ public class IrisObjectPlacementRunnerRegressionTest {
|
||||
|
||||
engine = mock(Engine.class);
|
||||
when(engine.getHeight()).thenReturn(256);
|
||||
data = mock(IrisData.class);
|
||||
data = MockPackData.create();
|
||||
when(data.getEngine()).thenReturn(engine);
|
||||
solid = state("minecraft:stone", true);
|
||||
schematicAir = state("minecraft:air", false);
|
||||
@@ -262,7 +264,7 @@ public class IrisObjectPlacementRunnerRegressionTest {
|
||||
IrisObjectReplace edit = mock(IrisObjectReplace.class);
|
||||
when(edit.getChance()).thenReturn(0.45F);
|
||||
when(edit.getFind(data)).thenReturn(new KList<>(solid));
|
||||
when(edit.getReplace(any(RNG.class), anyDouble(), anyDouble(), anyDouble(), any(IrisData.class)))
|
||||
when(edit.getReplace(any(RNG.class), anyDouble(), anyDouble(), anyDouble(), any(PackRuntime.class)))
|
||||
.thenReturn(replacement);
|
||||
IrisMaterialPalette palette = mock(IrisMaterialPalette.class);
|
||||
when(palette.getTile(any(RNG.class), anyDouble(), anyDouble(), anyDouble(), any(IrisData.class)))
|
||||
@@ -351,7 +353,7 @@ public class IrisObjectPlacementRunnerRegressionTest {
|
||||
IrisMaterialPalette palette = mock(IrisMaterialPalette.class);
|
||||
when(edit.getChance()).thenReturn(1F);
|
||||
when(edit.getFind(data)).thenReturn(new KList<>(chest));
|
||||
when(edit.getReplace(any(RNG.class), anyDouble(), anyDouble(), anyDouble(), any(IrisData.class)))
|
||||
when(edit.getReplace(any(RNG.class), anyDouble(), anyDouble(), anyDouble(), any(PackRuntime.class)))
|
||||
.thenReturn(solid);
|
||||
when(edit.getReplace()).thenReturn(palette);
|
||||
when(palette.getTile(any(RNG.class), anyDouble(), anyDouble(), anyDouble(), any(IrisData.class)))
|
||||
@@ -534,7 +536,7 @@ public class IrisObjectPlacementRunnerRegressionTest {
|
||||
NativeBlockState calcite = state("minecraft:calcite", true);
|
||||
NativeBlockState cobblestone = state("minecraft:cobblestone", true);
|
||||
IrisMaterialPalette palette = mock(IrisMaterialPalette.class);
|
||||
when(palette.get(any(RNG.class), anyDouble(), anyDouble(), anyDouble(), any(IrisData.class)))
|
||||
when(palette.get(any(RNG.class), anyDouble(), anyDouble(), anyDouble(), any(PackRuntime.class)))
|
||||
.thenReturn(cobblestone);
|
||||
IrisObject object = lineObject(3);
|
||||
object.setUnsigned(2, 0, 0, calcite);
|
||||
@@ -561,7 +563,7 @@ public class IrisObjectPlacementRunnerRegressionTest {
|
||||
object.setUnsigned(0, 0, 0, ice);
|
||||
object.setUnsigned(2, 0, 0, cluster);
|
||||
IrisMaterialPalette palette = mock(IrisMaterialPalette.class);
|
||||
when(palette.get(any(RNG.class), anyDouble(), anyDouble(), anyDouble(), any(IrisData.class)))
|
||||
when(palette.get(any(RNG.class), anyDouble(), anyDouble(), anyDouble(), any(PackRuntime.class)))
|
||||
.thenReturn(solid);
|
||||
RecordingPlacer placer = new RecordingPlacer(null);
|
||||
IrisObjectPlacement placement = placement().setMode(ObjectPlaceMode.CENTER_STILT)
|
||||
@@ -582,10 +584,10 @@ public class IrisObjectPlacementRunnerRegressionTest {
|
||||
NativeBlockState packedIce = state("minecraft:packed_ice", true);
|
||||
IrisMaterialPalette body = mock(IrisMaterialPalette.class);
|
||||
when(body.getPalette()).thenReturn(new KList<>(new IrisBlockData("minecraft:ice")));
|
||||
when(body.get(any(RNG.class), anyDouble(), anyDouble(), anyDouble(), any(IrisData.class)))
|
||||
when(body.get(any(RNG.class), anyDouble(), anyDouble(), anyDouble(), any(PackRuntime.class)))
|
||||
.thenReturn(ice);
|
||||
IrisMaterialPalette roots = mock(IrisMaterialPalette.class);
|
||||
when(roots.get(any(RNG.class), anyDouble(), anyDouble(), anyDouble(), any(IrisData.class)))
|
||||
when(roots.get(any(RNG.class), anyDouble(), anyDouble(), anyDouble(), any(PackRuntime.class)))
|
||||
.thenReturn(packedIce);
|
||||
IrisFormation formation = new IrisFormation().setForm(IrisFormationForm.OVERHANG)
|
||||
.setHeightMin(16).setHeightMax(25).setBaseWidthMin(5).setBaseWidthMax(8)
|
||||
@@ -726,7 +728,7 @@ public class IrisObjectPlacementRunnerRegressionTest {
|
||||
when(barrel.isStorage()).thenReturn(true);
|
||||
for (NativeBlockState replacement : List.of(calcite, barrel)) {
|
||||
IrisMaterialPalette palette = mock(IrisMaterialPalette.class);
|
||||
when(palette.get(any(RNG.class), anyDouble(), anyDouble(), anyDouble(), any(IrisData.class)))
|
||||
when(palette.get(any(RNG.class), anyDouble(), anyDouble(), anyDouble(), any(PackRuntime.class)))
|
||||
.thenReturn(replacement);
|
||||
RecordingPlacer placer = new RecordingPlacer(null);
|
||||
IrisObjectPlacement placement = placement().setMode(ObjectPlaceMode.CENTER_STILT)
|
||||
@@ -750,7 +752,7 @@ public class IrisObjectPlacementRunnerRegressionTest {
|
||||
IrisMaterialPalette palette = mock(IrisMaterialPalette.class);
|
||||
when(edit.getChance()).thenReturn(1F);
|
||||
when(edit.getFind(data)).thenReturn(new KList<>(solid));
|
||||
when(edit.getReplace(any(RNG.class), anyDouble(), anyDouble(), anyDouble(), any(IrisData.class)))
|
||||
when(edit.getReplace(any(RNG.class), anyDouble(), anyDouble(), anyDouble(), any(PackRuntime.class)))
|
||||
.thenReturn(replacement);
|
||||
when(edit.getReplace()).thenReturn(palette);
|
||||
when(palette.getTile(any(RNG.class), anyDouble(), anyDouble(), anyDouble(), any(IrisData.class)))
|
||||
|
||||
+12
-15
@@ -1,5 +1,7 @@
|
||||
package art.arcane.iris.structure.object;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.testsupport.MockPackData;
|
||||
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.generation.noise.NoiseStyle;
|
||||
|
||||
@@ -10,8 +12,6 @@ import art.arcane.volmlib.util.noise.CNG;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -20,29 +20,26 @@ import static org.mockito.Mockito.when;
|
||||
public class IrisObjectPlacementSurfaceWarpCacheTest {
|
||||
@Test
|
||||
public void surfaceWarpSeparatesEngineSeeds() {
|
||||
Engine first = engine(100L);
|
||||
Engine second = engine(200L);
|
||||
AtomicReference<Engine> active = new AtomicReference<>(first);
|
||||
IrisData data = mock(IrisData.class);
|
||||
when(data.getEngine()).thenAnswer(ignored -> active.get());
|
||||
IrisData data = MockPackData.create();
|
||||
PackRuntime first = PackRuntime.forEngine(engine(100L), data);
|
||||
PackRuntime second = PackRuntime.forEngine(engine(200L), data);
|
||||
IrisObjectPlacement placement = placement();
|
||||
|
||||
CNG firstWarp = placement.getSurfaceWarp(new RNG(1L), data);
|
||||
assertSame(firstWarp, placement.getSurfaceWarp(new RNG(999L), data));
|
||||
active.set(second);
|
||||
CNG firstWarp = placement.getSurfaceWarp(new RNG(1L), first);
|
||||
assertSame(firstWarp, placement.getSurfaceWarp(new RNG(999L), first));
|
||||
|
||||
assertNotSame(firstWarp, placement.getSurfaceWarp(new RNG(1L), data));
|
||||
assertNotSame(firstWarp, placement.getSurfaceWarp(new RNG(1L), second));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void standaloneSurfaceWarpUsesSuppliedSeed() {
|
||||
IrisData data = mock(IrisData.class);
|
||||
PackRuntime runtime = PackRuntime.standalone(MockPackData.create());
|
||||
IrisObjectPlacement placement = placement();
|
||||
|
||||
CNG first = placement.getSurfaceWarp(new RNG(1L), data);
|
||||
CNG first = placement.getSurfaceWarp(new RNG(1L), runtime);
|
||||
|
||||
assertSame(first, placement.getSurfaceWarp(new RNG(1L), data));
|
||||
assertNotSame(first, placement.getSurfaceWarp(new RNG(2L), data));
|
||||
assertSame(first, placement.getSurfaceWarp(new RNG(1L), runtime));
|
||||
assertNotSame(first, placement.getSurfaceWarp(new RNG(2L), runtime));
|
||||
}
|
||||
|
||||
private IrisObjectPlacement placement() {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.structure.object;
|
||||
|
||||
import art.arcane.iris.testsupport.MockPackData;
|
||||
import art.arcane.iris.generation.hydrology.raster.WaterRole;
|
||||
import art.arcane.iris.generation.block.BlockDataMergeSupport;
|
||||
import art.arcane.iris.generation.block.IrisBlockData;
|
||||
@@ -125,10 +126,10 @@ public class ObjectPlacementGoldenTest {
|
||||
when(engine.getDimension()).thenReturn(dimension);
|
||||
ContentGate gate = mock(ContentGate.class, withSettings().stubOnly());
|
||||
when(gate.ready()).thenReturn(false);
|
||||
data = mock(IrisData.class, withSettings().stubOnly());
|
||||
data = MockPackData.stubOnly();
|
||||
when(data.getEngine()).thenReturn(engine);
|
||||
when(data.getContentGate()).thenReturn(gate);
|
||||
objectData = mock(IrisData.class, withSettings().stubOnly());
|
||||
objectData = MockPackData.stubOnly();
|
||||
when(objectData.getContentGate()).thenReturn(gate);
|
||||
}
|
||||
|
||||
|
||||
+10
-9
@@ -18,6 +18,7 @@
|
||||
|
||||
package art.arcane.iris.structure.placement;
|
||||
|
||||
import art.arcane.iris.testsupport.MockPackData;
|
||||
import art.arcane.volmlib.util.structure.StructureTerrainMode;
|
||||
|
||||
import art.arcane.volmlib.util.structure.StructureCarveShape;
|
||||
@@ -114,7 +115,7 @@ public class IrisStructureLocatorContractTest {
|
||||
|
||||
@Test
|
||||
public void locatableIndexIncludesAliasesAndSeparatesEditableFromNativePlacements() {
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisData data = MockPackData.create();
|
||||
IrisStructure structure = new IrisStructure();
|
||||
structure.setLoadKey("test:city");
|
||||
structure.setVanillaSource("source:city");
|
||||
@@ -156,7 +157,7 @@ public class IrisStructureLocatorContractTest {
|
||||
|
||||
@Test
|
||||
public void nativeStructureReplacementSuppressesOnlyItsRegisteredSource() {
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisData data = MockPackData.create();
|
||||
Engine engine = mock(Engine.class);
|
||||
IrisDimension dimension = mock(IrisDimension.class);
|
||||
IrisStructurePlacement placement = new IrisStructurePlacement()
|
||||
@@ -185,7 +186,7 @@ public class IrisStructureLocatorContractTest {
|
||||
|
||||
@Test
|
||||
public void vanillaSourceRequiresExplicitDimensionSuppression() {
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisData data = MockPackData.create();
|
||||
IrisStructure structure = new IrisStructure();
|
||||
structure.setLoadKey("test:city");
|
||||
structure.setVanillaSource("minecraft:ancient_city");
|
||||
@@ -214,7 +215,7 @@ public class IrisStructureLocatorContractTest {
|
||||
|
||||
@Test
|
||||
public void regionReplacementFailsInsteadOfFallingBackToNative() {
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisData data = MockPackData.create();
|
||||
IrisStructure structure = new IrisStructure();
|
||||
structure.setLoadKey("test:city");
|
||||
structure.setVanillaSource("minecraft:ancient_city");
|
||||
@@ -242,7 +243,7 @@ public class IrisStructureLocatorContractTest {
|
||||
|
||||
@Test
|
||||
public void geometryFailureFailsInsteadOfFallingBackToNative() {
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisData data = MockPackData.create();
|
||||
IrisStructure structure = new IrisStructure()
|
||||
.setStartPool("test:start")
|
||||
.setMaxDepth(1)
|
||||
@@ -304,7 +305,7 @@ public class IrisStructureLocatorContractTest {
|
||||
|
||||
@Test
|
||||
public void missingVanillaSourceFailsInsteadOfFallingBackToNative() {
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisData data = MockPackData.create();
|
||||
IrisStructure structure = new IrisStructure();
|
||||
structure.setLoadKey("test:city");
|
||||
when(data.load(IrisStructure.class, "test:city", false)).thenReturn(structure);
|
||||
@@ -327,7 +328,7 @@ public class IrisStructureLocatorContractTest {
|
||||
|
||||
@Test
|
||||
public void missingNonReplacementStructureFailsInsteadOfBeingSkipped() {
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisData data = MockPackData.create();
|
||||
IrisStructurePlacement placement = new IrisStructurePlacement();
|
||||
placement.getStructures().add("test:missing");
|
||||
IrisDimension dimension = mock(IrisDimension.class);
|
||||
@@ -752,7 +753,7 @@ public class IrisStructureLocatorContractTest {
|
||||
|
||||
@Test
|
||||
public void placementIndexIsScopedAndInvalidatedPerEngine() {
|
||||
IrisData sharedData = mock(IrisData.class);
|
||||
IrisData sharedData = MockPackData.create();
|
||||
Engine firstEngine = emptyEngine(sharedData);
|
||||
Engine secondEngine = emptyEngine(sharedData);
|
||||
Set<String> firstIndex = IrisStructureLocator.placedKeys(firstEngine);
|
||||
@@ -1089,7 +1090,7 @@ public class IrisStructureLocatorContractTest {
|
||||
|
||||
private Engine densityEngine(double density, boolean underground, int worldMin, int worldHeight,
|
||||
int placementMin, int placementMax) {
|
||||
IrisData data = mock(IrisData.class);
|
||||
IrisData data = MockPackData.create();
|
||||
IrisStructure structure = new IrisStructure();
|
||||
structure.setLoadKey("test:density");
|
||||
when(data.load(IrisStructure.class, "test:density", false)).thenReturn(structure);
|
||||
|
||||
Loaded 100 of 239 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user