Stop rescaling the cached style generator for continents and child biomes

IrisGeneratorStyle.create returns a generator cached per data and engine, and baking and scaling it in place applied the continent zoom and child scale again whenever a complex was rebuilt against the same data. Continents and child biomes now scale a fresh generator, and the continent assembly shared by IrisComplex and UpperDimensionContext lives in ContinentGenerator.

Upstream: 41664fc60 d80fcedd9 a0aa62b8c b7e6259a0 0b6ac19fa 5bffa6eb0 f07dfb7a8 789644b93 bda770650 ba4708f2b a9df19cae cf7ebcece 0d16f8e57 5c4f7bb52 700dc5355 1544c34f4 99cc2383d
This commit is contained in:
piexel committed 2026-11-10 00:55:24 +01:00
1 parent a81a3abb9f
commit b9d8125180
6 files changed
+136 -6

No files matched your search

@@ -0,0 +1,102 @@
package art.arcane.iris.engine;
import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.engine.object.noise.IrisGeneratorStyle;
import art.arcane.iris.engine.object.noise.NoiseStyle;
import art.arcane.iris.engine.object.world.biome.IrisBiome;
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
import art.arcane.iris.util.project.noise.CNG;
import art.arcane.volmlib.util.math.RNG;
import org.junit.Test;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertNotSame;
import static org.mockito.Mockito.mock;
public class ContinentGeneratorTest {
private static final long WORLD_SEED = 7L;
private static final double CONTINENT_ZOOM = 4D;
private static final double CHILD_SCALE = 3D;
private static final int CHILD_SIGNATURE = 5;
private static final int CHILDREN_SEED_SALT = 2137;
private static final double[][] SAMPLE_BLOCKS = {{0D, 0D}, {137D, -52D}, {-480D, 911D}, {2048D, 2048D}};
private final IrisData packData = mock(IrisData.class);
@Test
public void continentMapIsTheUnscaledNoiseShrunkByTheContinentZoom() {
IrisDimension dimension = dimensionWithContinentZoom();
CNG unscaled = dimension.getContinentalStyle()
.createNoCache(ContinentGenerator.deriveContinentSeed(new RNG(WORLD_SEED)), packData);
CNG continent = ContinentGenerator.create(dimension, new RNG(WORLD_SEED), packData);
assertArrayEquals(sample(unscaled, 1D / CONTINENT_ZOOM), sample(continent, 1D), 0D);
}
@Test
public void rebuildingTheContinentMapZoomsItOnlyOnce() {
IrisDimension dimension = dimensionWithContinentZoom();
double[] first = sample(ContinentGenerator.create(dimension, new RNG(WORLD_SEED), packData), 1D);
double[] rebuilt = sample(ContinentGenerator.create(dimension, new RNG(WORLD_SEED), packData), 1D);
assertArrayEquals(first, rebuilt, 0D);
}
@Test
public void buildingTheContinentMapLeavesTheSharedStyleGeneratorUnscaled() {
IrisDimension dimension = dimensionWithContinentZoom();
RNG continentSeed = ContinentGenerator.deriveContinentSeed(new RNG(WORLD_SEED));
double[] before = sample(dimension.getContinentalStyle().create(continentSeed, packData), 1D);
ContinentGenerator.create(dimension, new RNG(WORLD_SEED), packData);
assertArrayEquals(before, sample(dimension.getContinentalStyle().create(continentSeed, packData), 1D), 0D);
}
@Test
public void childGeneratorsOfTwoBiomesSharingAStyleAreScaledOnlyOnce() {
IrisGeneratorStyle sharedStyle = new IrisGeneratorStyle(NoiseStyle.SIMPLEX);
IrisBiome first = biomeWithChildStyle(sharedStyle);
IrisBiome second = biomeWithChildStyle(sharedStyle);
CNG firstChildren = first.getChildrenGenerator(new RNG(WORLD_SEED), CHILD_SIGNATURE, CHILD_SCALE);
CNG secondChildren = second.getChildrenGenerator(new RNG(WORLD_SEED), CHILD_SIGNATURE, CHILD_SCALE);
assertNotSame(firstChildren, secondChildren);
assertArrayEquals(sample(firstChildren, 1D), sample(secondChildren, 1D), 0D);
}
@Test
public void childGeneratorLeavesTheSharedStyleGeneratorUnscaled() {
IrisGeneratorStyle sharedStyle = new IrisGeneratorStyle(NoiseStyle.SIMPLEX);
IrisBiome biome = biomeWithChildStyle(sharedStyle);
RNG childSeed = new RNG(WORLD_SEED).nextParallelRNG(CHILD_SIGNATURE * CHILDREN_SEED_SALT);
double[] before = sample(sharedStyle.create(childSeed, packData), 1D);
biome.getChildrenGenerator(new RNG(WORLD_SEED), CHILD_SIGNATURE, CHILD_SCALE);
assertArrayEquals(before, sample(sharedStyle.create(childSeed, packData), 1D), 0D);
}
private IrisBiome biomeWithChildStyle(IrisGeneratorStyle childStyle) {
IrisBiome biome = new IrisBiome().setChildStyle(childStyle);
biome.setLoader(packData);
return biome;
}
private static IrisDimension dimensionWithContinentZoom() {
return new IrisDimension()
.setContinentalStyle(new IrisGeneratorStyle(NoiseStyle.SIMPLEX))
.setContinentZoom(CONTINENT_ZOOM);
}
private static double[] sample(CNG generator, double blockScale) {
double[] samples = new double[SAMPLE_BLOCKS.length];
for (int i = 0; i < SAMPLE_BLOCKS.length; i++) {
samples[i] = generator.noise(SAMPLE_BLOCKS[i][0] * blockScale, SAMPLE_BLOCKS[i][1] * blockScale);
}
return samples;
}
}