mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-12-01 02:04:51 +00:00
Roll seeded noise styles from the world seed, read them flat
IrisGeneratorStyle gets the seed field the IrisApi style has. A seeded
style is built from splitMix(worldSeed ^ splitMix(seed)) instead of the
caller's random, so every style with the same seed and shape shares one
noise per world. Material palettes and child biomes read a seeded style
in plain blocks (no palette zoom, no childShrinkFactor).
Tests: the factory ignores the asked seed and follows the world seed;
the decorator chance gate and palette layers read seeded styles flat
(module code, tested here as the other module tests are).
Ported from v3e a1bd24186 and 1be1795e6. IrisApi 2914ed1.
This commit is contained in:
1 parent
ee5f3d90eb
commit
3b9012535f
7 files changed
+154
-5
No files matched your search
@@ -3,6 +3,7 @@ package art.arcane.iris.core.modules;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.loader.ResourceLoader;
|
||||
import art.arcane.iris.engine.UsableBlockPlatform;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.object.material.IrisBlockData;
|
||||
import art.arcane.iris.engine.object.material.IrisMaterialPalette;
|
||||
import art.arcane.iris.engine.object.noise.IrisGeneratorStyle;
|
||||
@@ -41,6 +42,7 @@ import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@@ -129,6 +131,28 @@ public class IrisValuesTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aSeededStyleIgnoresTheSeedItIsAskedForAndFollowsTheWorldSeed() {
|
||||
NoiseStyle seeded = NoiseStyle.of("SIMPLEX").withZoom(40).withSeed(7);
|
||||
IrisData world = packOfWorldSeed(1337L);
|
||||
IrisData otherWorld = packOfWorldSeed(4242L);
|
||||
|
||||
NoiseSampler asked = noiseOf(world).sampler(seeded, 1);
|
||||
NoiseSampler askedOtherwise = noiseOf(world).sampler(seeded, 987_654_321L);
|
||||
NoiseSampler inOtherWorld = noiseOf(otherWorld).sampler(seeded, 1);
|
||||
NoiseSampler otherStyleSeed = noiseOf(world).sampler(seeded.withSeed(8), 1);
|
||||
|
||||
int differsByWorld = 0;
|
||||
int differsByStyleSeed = 0;
|
||||
for (double[] column : COLUMNS) {
|
||||
assertEquals(asked.sample(column[0], column[1]), askedOtherwise.sample(column[0], column[1]), 0);
|
||||
differsByWorld += asked.sample(column[0], column[1]) != inOtherWorld.sample(column[0], column[1]) ? 1 : 0;
|
||||
differsByStyleSeed += asked.sample(column[0], column[1]) != otherStyleSeed.sample(column[0], column[1]) ? 1 : 0;
|
||||
}
|
||||
assertEquals(COLUMNS.length, differsByWorld);
|
||||
assertEquals(COLUMNS.length, differsByStyleSeed);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void signedNoiseIsTheSignedFastReadOfTheIrisGeneratorsNoise() {
|
||||
String json = "{\"style\": \"SIMPLEX\", \"zoom\": 4, \"exponent\": 1.5, \"fracture\": {\"style\": \"PERLIN\", \"zoom\": 2, \"multiplier\": 3}}";
|
||||
@@ -250,6 +274,14 @@ public class IrisValuesTest {
|
||||
return data;
|
||||
}
|
||||
|
||||
private static IrisData packOfWorldSeed(long worldSeed) {
|
||||
IrisData data = packWithoutCustomBlocks();
|
||||
Engine engine = mock(Engine.class, RETURNS_DEEP_STUBS);
|
||||
when(engine.getSeedManager().getSeed()).thenReturn(worldSeed);
|
||||
when(data.getEngine()).thenReturn(engine);
|
||||
return data;
|
||||
}
|
||||
|
||||
private static IrisBlockRegistry blocksOf(IrisData data) {
|
||||
return new IrisBlockRegistry(data, new IrisPackResources(data, List::of));
|
||||
}
|
||||
|
||||
@@ -86,6 +86,30 @@ public class ResolvedDecoratorTest {
|
||||
assertEquals(List.of("CLOVER@" + (SEED + 3 + 7 + 2), "SIMPLEX@" + (SEED + 3), "PERLIN@" + (SEED + 3)), built);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void theChanceGateReadsASeededStyleInPlainBlocks() {
|
||||
List<String> reads = new ArrayList<>();
|
||||
NoiseFactory recording = (style, seed) -> new NoiseSampler() {
|
||||
@Override
|
||||
public double sample(double worldX, double worldZ) {
|
||||
reads.add(worldX + "," + worldZ);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double sample(double worldX, double y, double worldZ) {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
Decorator zoomed = new Gson().fromJson("{\"style\": {\"style\": \"SIMPLEX\", \"zoom\": 4}}", Decorator.class);
|
||||
Decorator seeded = new Gson().fromJson("{\"style\": {\"style\": \"SIMPLEX\", \"zoom\": 4, \"seed\": 3}}", Decorator.class);
|
||||
|
||||
new ResolvedDecorator(zoomed, SEED, recording, state("a"), List.of(), null, List.of(), List.of(), ModuleLogs.discarding(), "test").passesChanceGate(40, -8);
|
||||
new ResolvedDecorator(seeded, SEED, recording, state("a"), List.of(), null, List.of(), List.of(), ModuleLogs.discarding(), "test").passesChanceGate(40, -8);
|
||||
|
||||
assertEquals(List.of("10.0,-2.0", "40.0,-8.0"), reads);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noiseIsOnlyBuiltForWhatIsAskedFor() {
|
||||
NoiseFactory refusing = (style, seed) -> {
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package art.arcane.iris.engine.terrain;
|
||||
|
||||
import art.arcane.iris.builtin.terrain.PaletteLayer;
|
||||
import art.arcane.iris.modules.terrain.LayerBlocks;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.google.gson.Gson;
|
||||
import com.volmit.block.BlockRegistry;
|
||||
import com.volmit.block.BlockSpec;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.noise.NoiseFactory;
|
||||
import com.volmit.noise.NoiseSampler;
|
||||
import com.volmit.resource.PackResources;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class LayerBlocksSeededStyleTest {
|
||||
private static final String ZOOMED = "{\"zoom\": 4, \"style\": {\"style\": \"SIMPLEX\"}, \"palette\": [{\"block\": \"stone\"}, {\"block\": \"dirt\"}]}";
|
||||
private static final String SEEDED = "{\"zoom\": 4, \"style\": {\"style\": \"SIMPLEX\", \"seed\": 9}, \"palette\": [{\"block\": \"stone\"}, {\"block\": \"dirt\"}]}";
|
||||
|
||||
@Test
|
||||
public void aSeededLayerStyleIsReadFlatInPlainBlocks() {
|
||||
List<String> reads = new ArrayList<>();
|
||||
LayerBlocks blocks = TestLayerBlocks.of(resourcesRecording(reads)).get();
|
||||
Gson gson = new Gson();
|
||||
|
||||
blocks.pick(gson.fromJson(ZOOMED, PaletteLayer.class), new RNG(1), 0, 40, 3, -8);
|
||||
blocks.pick(gson.fromJson(SEEDED, PaletteLayer.class), new RNG(1), 0, 40, 3, -8);
|
||||
|
||||
assertEquals(List.of("10.0,0.75,-2.0", "40.0,-8.0"), reads);
|
||||
}
|
||||
|
||||
private static PackResources resourcesRecording(List<String> reads) {
|
||||
BlockRegistry registry = mock(BlockRegistry.class);
|
||||
when(registry.resolve(any(BlockSpec.class))).thenReturn(BlockState.parse("minecraft:stone"));
|
||||
NoiseFactory recording = (style, seed) -> new NoiseSampler() {
|
||||
@Override
|
||||
public double sample(double worldX, double worldZ) {
|
||||
reads.add(worldX + "," + worldZ);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double sample(double worldX, double y, double worldZ) {
|
||||
reads.add(worldX + "," + y + "," + worldZ);
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
PackResources resources = mock(PackResources.class);
|
||||
when(resources.blocks()).thenReturn(registry);
|
||||
when(resources.noise()).thenReturn(recording);
|
||||
return resources;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user