mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 16:54:04 +00:00
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:41664fc60d80fcedd9a0aa62b8cb7e6259a00b6ac19fa5bffa6eb0f07dfb7a8789644b93bda770650ba4708f2ba9df19caecf7ebcece0d16f8e575c4f7bb52700dc53551544c34f499cc2383d
This commit is contained in:
1 parent
a81a3abb9f
commit
b9d8125180
6 files changed
+136
-6
No files matched your search
@@ -0,0 +1,26 @@
|
||||
package art.arcane.iris.engine;
|
||||
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.util.project.noise.CNG;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
|
||||
public final class ContinentGenerator {
|
||||
private static final int CONTINENT_SEED_SALT = 234234565;
|
||||
|
||||
private ContinentGenerator() {
|
||||
}
|
||||
|
||||
public static CNG create(IrisDimension dimension, RNG parentSeedSource, IrisData packData) {
|
||||
return dimension.getContinentalStyle()
|
||||
.createScaledGenerator(deriveContinentSeed(parentSeedSource), packData, inverseContinentZoom(dimension));
|
||||
}
|
||||
|
||||
static RNG deriveContinentSeed(RNG parentSeedSource) {
|
||||
return parentSeedSource.nextParallelRNG(CONTINENT_SEED_SALT);
|
||||
}
|
||||
|
||||
private static double inverseContinentZoom(IrisDimension dimension) {
|
||||
return 1D / dimension.getContinentZoom();
|
||||
}
|
||||
}
|
||||
@@ -248,8 +248,7 @@ public class IrisComplex implements DataProvider {
|
||||
inferredStreams.put(InferredType.SHORE, shoreBiomeStream);
|
||||
bridgeStream = focusBiome != null ? ProceduralStream.of((x, z) -> focusBiome.getInferredType(),
|
||||
Interpolated.of(a -> 0D, a -> focusBiome.getInferredType())) :
|
||||
engine.getDimension().getContinentalStyle().create(rng.nextParallelRNG(234234565), getData())
|
||||
.bake().scale(1D / engine.getDimension().getContinentZoom()).bake().stream()
|
||||
ContinentGenerator.create(engine.getDimension(), rng, getData()).stream()
|
||||
.convert((v) -> v >= engine.getDimension().getLandChance() ? InferredType.SEA : InferredType.LAND)
|
||||
.cache2D("bridgeStream", engine, cacheSize);
|
||||
ProceduralStream<IrisBiome> proceduralBaseBiomeStream = focusBiome != null ? ProceduralStream.of((x, z) -> implode(focusBiome, x, z),
|
||||
|
||||
@@ -166,9 +166,7 @@ public class UpperDimensionContext implements DataProvider {
|
||||
inferredStreams.put(InferredType.SEA, seaBiomeStream);
|
||||
inferredStreams.put(InferredType.SHORE, shoreBiomeStream);
|
||||
|
||||
ProceduralStream<InferredType> bridgeStream = upperDim.getContinentalStyle()
|
||||
.create(rng.nextParallelRNG(234234565), upperData)
|
||||
.bake().scale(1D / upperDim.getContinentZoom()).bake().stream()
|
||||
ProceduralStream<InferredType> bridgeStream = ContinentGenerator.create(upperDim, rng, upperData).stream()
|
||||
.convert(v -> v >= upperDim.getLandChance() ? InferredType.SEA : InferredType.LAND);
|
||||
|
||||
ProceduralStream<IrisBiome> proceduralBaseBiomeStream = bridgeStream
|
||||
|
||||
@@ -104,6 +104,10 @@ public class IrisGeneratorStyle {
|
||||
return createNoCache(rng, data, false, 0, false, resolveEngine(data));
|
||||
}
|
||||
|
||||
public CNG createScaledGenerator(RNG rng, IrisData data, double scaleFactor) {
|
||||
return createNoCache(rng, data).bake().scale(scaleFactor).bake();
|
||||
}
|
||||
|
||||
public CNG createForPrebake(RNG rng, IrisData data, int fallbackCacheSize) {
|
||||
return createNoCache(rng, data, false, Math.max(0, fallbackCacheSize), true, resolveEngine(data));
|
||||
}
|
||||
|
||||
@@ -73,6 +73,7 @@ import java.util.Objects;
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class IrisBiome extends IrisRegistrant implements IRare {
|
||||
private static final int BIOME_GENERATOR_CACHE_SIZE = 8;
|
||||
private static final int CHILDREN_SEED_SALT = 2137;
|
||||
|
||||
private final transient AtomicCache<KMap<String, IrisBiomeGeneratorLink>> genCache = new AtomicCache<>();
|
||||
private final transient AtomicCache<KMap<String, Integer>> genCacheMax = new AtomicCache<>();
|
||||
@@ -296,7 +297,7 @@ public class IrisBiome extends IrisRegistrant implements IRare {
|
||||
|
||||
public CNG getChildrenGenerator(RNG random, int sig, double scale) {
|
||||
double childScale = getChildStyle().isSeeded() ? 1 : scale;
|
||||
return childrenCell.aquire(() -> getChildStyle().create(random.nextParallelRNG(sig * 2137), getLoader()).bake().scale(childScale).bake());
|
||||
return childrenCell.aquire(() -> getChildStyle().createScaledGenerator(random.nextParallelRNG(sig * CHILDREN_SEED_SALT), getLoader(), childScale));
|
||||
}
|
||||
|
||||
public boolean isLand() {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user