Move biome runtime state into the engine pack runtime

- Add biome, palette layer and floating child runtimes owned by the pack runtime
- Keep the floating island chunk memo in engine-owned thread slots
- Give seed tables seed-indexed recent slots
- Pass the pack runtime through biome layer, palette and floating island sampling
- Remove the biome, palette layer and floating child caches and their keys
- Delete IrisBiomeLayerHeightCache
- Record the floating island diagnostics as scratch in the state gate
- Update tests to resolve generators through a pack runtime
This commit is contained in:
piexel committed 2026-11-26 19:04:59 +01:00
1 parent 305dbd63e3
commit f6b1bf7e05
54 files changed
+858 -851

No files matched your search

@@ -0,0 +1,81 @@
/*
* 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.biome;
import art.arcane.iris.generation.runtime.PackRuntime;
import art.arcane.iris.generation.runtime.SeedTable;
import art.arcane.volmlib.util.collection.KList;
import art.arcane.volmlib.util.noise.CNG;
import java.util.concurrent.ConcurrentHashMap;
/**
* What one engine derives from an {@link IrisBiome}: its scatter generators, the children generators per shrink
* scale, and the height generators of its layer palettes.
*/
public final class BiomeRuntime {
private static final int BIOME_SEED_CAPACITY = 8;
private static final int CHILD_SEED_CAPACITY = 8;
private static final int LAYER_HEIGHT_SEED_CAPACITY = 32;
private static final int SURFACE_LAYER_SEED_OFFSET = 7235;
private static final int SEA_LAYER_SEED_OFFSET = 7735;
private static final int CEILING_LAYER_SEED_OFFSET = 7235;
private final IrisBiome biome;
private final PackRuntime runtime;
private final SeedTable<CNG> biomeGenerators;
private final ConcurrentHashMap<Long, SeedTable<CNG>> childGeneratorsByScale = new ConcurrentHashMap<>();
private final SeedTable<KList<CNG>> layerHeights;
private final SeedTable<KList<CNG>> seaLayerHeights;
private final SeedTable<KList<CNG>> ceilingLayerHeights;
public BiomeRuntime(IrisBiome biome, PackRuntime runtime) {
this.biome = biome;
this.runtime = runtime;
this.biomeGenerators = new SeedTable<>(BIOME_SEED_CAPACITY, seed -> biome.createBiomeGenerator(seed, runtime));
this.layerHeights = new SeedTable<>(LAYER_HEIGHT_SEED_CAPACITY, seed ->
IrisBiomeLayerGenerator.createHeightGenerators(biome.getLayers(), SURFACE_LAYER_SEED_OFFSET, seed, runtime));
this.seaLayerHeights = new SeedTable<>(LAYER_HEIGHT_SEED_CAPACITY, seed ->
IrisBiomeLayerGenerator.createHeightGenerators(biome.getSeaLayers(), SEA_LAYER_SEED_OFFSET, seed, runtime));
this.ceilingLayerHeights = new SeedTable<>(LAYER_HEIGHT_SEED_CAPACITY, seed ->
IrisBiomeLayerGenerator.createHeightGenerators(biome.getCaveCeilingLayers(), CEILING_LAYER_SEED_OFFSET, seed, runtime));
}
public CNG biomeGenerator(long seed) {
return biomeGenerators.get(seed);
}
public CNG childrenGenerator(long seed, double scale) {
return childGeneratorsByScale.computeIfAbsent(Double.doubleToLongBits(scale), ignored ->
new SeedTable<>(CHILD_SEED_CAPACITY, childSeed -> biome.createChildrenGenerator(childSeed, scale, runtime)))
.get(seed);
}
public KList<CNG> layerHeights(long seed) {
return layerHeights.get(seed);
}
public KList<CNG> seaLayerHeights(long seed) {
return seaLayerHeights.get(seed);
}
public KList<CNG> ceilingLayerHeights(long seed) {
return ceilingLayerHeights.get(seed);
}
}
@@ -0,0 +1,57 @@
/*
* 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.biome;
import art.arcane.iris.generation.cave.IrisCaveProfileSampler;
import art.arcane.iris.generation.runtime.PackRuntime;
import art.arcane.iris.generation.runtime.SeedTable;
import java.util.Optional;
/**
* What one engine derives from an {@link IrisFloatingChildBiomes} entry: its edge taper profile per base seed and the
* cave profile sampler of the biome it carves with.
*/
public final class FloatingChildRuntime {
private static final int EDGE_PROFILE_SEED_CAPACITY = 8;
private final IrisFloatingChildBiomes entry;
private final PackRuntime runtime;
private final SeedTable<FloatingIslandEdgeProfile> edgeProfiles;
private volatile Optional<IrisCaveProfileSampler> carvingProfileSampler;
public FloatingChildRuntime(IrisFloatingChildBiomes entry, PackRuntime runtime) {
this.entry = entry;
this.runtime = runtime;
this.edgeProfiles = new SeedTable<>(EDGE_PROFILE_SEED_CAPACITY, seed -> entry.createEdgeTaperProfile(seed, runtime));
}
public FloatingIslandEdgeProfile edgeTaperProfile(long baseSeed) {
return edgeProfiles.get(baseSeed);
}
public IrisCaveProfileSampler carvingProfileSampler() {
Optional<IrisCaveProfileSampler> resolved = carvingProfileSampler;
if (resolved == null) {
resolved = Optional.ofNullable(entry.createCarvingProfileSampler(runtime));
carvingProfileSampler = resolved;
}
return resolved.orElse(null);
}
}
@@ -0,0 +1,67 @@
/*
* 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.biome;
import java.util.HashMap;
/**
* One worker's floating island samples for the chunk it is generating. A runtime scope keeps one per worker thread,
* so the memo never outlives the engine that produced its samples.
*/
public final class FloatingIslandMemo {
private static final int CHUNK_COLUMN_COUNT = 256;
private final HashMap<Long, MemoizedSample> samples = new HashMap<>(CHUNK_COLUMN_COUNT);
private MemoContext context;
public void clear() {
samples.clear();
context = null;
}
/** The memoized sample for this column and parent, which may itself be null; null when not sampled yet. */
MemoizedSample find(IrisBiome parent, long column) {
MemoizedSample cached = samples.get(column);
return cached != null && cached.parent == parent ? cached : null;
}
void remember(IrisBiome parent, long column, FloatingIslandSample sample) {
samples.put(column, new MemoizedSample(parent, sample));
}
void enterChunk(int chunkX, int chunkZ, int height, long seed, FloatingIslandBoundarySampler boundarySampler) {
if (context != null && context.matches(chunkX, chunkZ, height, seed, boundarySampler)) {
return;
}
samples.clear();
context = new MemoContext(chunkX, chunkZ, height, seed, boundarySampler);
}
private record MemoContext(int chunkX, int chunkZ, int height, long seed,
FloatingIslandBoundarySampler boundarySampler) {
private boolean matches(int chunkX, int chunkZ, int height, long seed,
FloatingIslandBoundarySampler boundarySampler) {
return this.chunkX == chunkX && this.chunkZ == chunkZ && this.height == height && this.seed == seed
&& this.boundarySampler == boundarySampler;
}
}
record MemoizedSample(IrisBiome parent, FloatingIslandSample sample) {
}
}
@@ -20,16 +20,12 @@ package art.arcane.iris.generation.biome;
import art.arcane.iris.generation.cave.IrisCaveProfileSampler;
import art.arcane.iris.pack.loading.IrisData;
import art.arcane.iris.generation.runtime.Engine;
import art.arcane.iris.generation.runtime.PackRuntime;
import art.arcane.iris.spi.IrisLogging;
import art.arcane.volmlib.util.noise.CNG;
import art.arcane.volmlib.util.collection.KList;
import it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap;
import java.util.Arrays;
import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
public final class FloatingIslandSample {
@@ -51,8 +47,6 @@ public final class FloatingIslandSample {
private static final double CARVE_MAX_VERTICAL_RUN_FRACTION = 0.18D;
private static final ThreadLocal<int[]> LAST_REJECT = ThreadLocal.withInitial(() -> new int[1]);
private static final ThreadLocal<double[]> LAST_DENSITY = ThreadLocal.withInitial(() -> new double[2]);
private static final ThreadLocal<ChunkMemo> CHUNK_MEMO = ThreadLocal.withInitial(ChunkMemo::new);
private static final ThreadLocal<IdentityHashMap<CNG, Long2DoubleOpenHashMap>> FOOTPRINT_MEMO = ThreadLocal.withInitial(IdentityHashMap::new);
private static final AtomicBoolean NULL_CNG_WARNED = new AtomicBoolean(false);
public static int getLastReject() {
@@ -67,33 +61,20 @@ public final class FloatingIslandSample {
return LAST_DENSITY.get()[1];
}
public static void clearThreadCaches() {
CHUNK_MEMO.remove();
FOOTPRINT_MEMO.remove();
LAST_REJECT.remove();
LAST_DENSITY.remove();
public static void clearChunkMemo(PackRuntime runtime) {
runtime.floatingIslandMemo().clear();
}
public static void clearChunkMemo() {
CHUNK_MEMO.get().samples.clear();
FOOTPRINT_MEMO.get().clear();
}
public static FloatingIslandSample sampleMemoized(IrisBiome parent, int wx, int wz, int chunkHeight, long baseSeed, IrisData data, Engine engine, FloatingIslandBoundarySampler boundarySampler) {
long key = (((long) wx) << 32) ^ (wz & 0xFFFFFFFFL);
ChunkMemo memo = CHUNK_MEMO.get();
if (memo.context == null || !memo.context.matches(wx >> 4, wz >> 4, chunkHeight, baseSeed,
data, engine, boundarySampler)) {
memo.samples.clear();
FOOTPRINT_MEMO.get().clear();
memo.context = new MemoContext(wx >> 4, wz >> 4, chunkHeight, baseSeed, data, engine, boundarySampler);
public static FloatingIslandSample sampleMemoized(IrisBiome parent, int wx, int wz, int chunkHeight, long baseSeed, PackRuntime runtime, FloatingIslandBoundarySampler boundarySampler) {
long column = (((long) wx) << 32) ^ (wz & 0xFFFFFFFFL);
FloatingIslandMemo memo = runtime.floatingIslandMemo();
memo.enterChunk(wx >> 4, wz >> 4, chunkHeight, baseSeed, boundarySampler);
FloatingIslandMemo.MemoizedSample cached = memo.find(parent, column);
if (cached != null) {
return cached.sample();
}
MemoizedSample cached = memo.samples.get(key);
if (cached != null && cached.parent == parent) {
return cached.sample;
}
FloatingIslandSample result = sample(parent, wx, wz, chunkHeight, baseSeed, data, engine, boundarySampler);
memo.samples.put(key, new MemoizedSample(parent, result));
FloatingIslandSample result = sample(parent, wx, wz, chunkHeight, baseSeed, runtime, boundarySampler);
memo.remember(parent, column, result);
return result;
}
@@ -184,18 +165,18 @@ public final class FloatingIslandSample {
}
private static int maximumEdgeFieldWidth(KList<IrisFloatingChildBiomes> entries, long baseSeed,
IrisData data, IrisBiome parent) {
PackRuntime runtime, IrisBiome parent) {
int maximumWidth = FloatingIslandEdgeProfile.MIN_WIDTH;
for (IrisFloatingChildBiomes entry : entries) {
FloatingIslandEdgeProfile profile = resolveEdgeProfile(entry, baseSeed, data, parent);
FloatingIslandEdgeProfile profile = resolveEdgeProfile(entry, baseSeed, runtime, parent);
maximumWidth = Math.max(maximumWidth, profile.fieldWidth());
}
return maximumWidth;
}
private static FloatingIslandEdgeProfile resolveEdgeProfile(IrisFloatingChildBiomes entry, long baseSeed,
IrisData data, IrisBiome parent) {
FloatingIslandEdgeProfile profile = entry.getEdgeTaperProfile(baseSeed, data);
PackRuntime runtime, IrisBiome parent) {
FloatingIslandEdgeProfile profile = entry.getEdgeTaperProfile(baseSeed, runtime);
if (profile != null) {
return profile;
}
@@ -203,17 +184,17 @@ public final class FloatingIslandSample {
return FloatingIslandEdgeProfile.DEFAULT;
}
public static FloatingIslandSample sample(IrisBiome parent, int wx, int wz, int chunkHeight, long baseSeed, IrisData data, Engine engine, FloatingIslandBoundarySampler boundarySampler) {
public static FloatingIslandSample sample(IrisBiome parent, int wx, int wz, int chunkHeight, long baseSeed, PackRuntime runtime, FloatingIslandBoundarySampler boundarySampler) {
KList<IrisFloatingChildBiomes> entries = parent.getFloatingChildBiomes();
if (entries == null || entries.isEmpty()) {
return reject(REJECT_NO_ENTRIES);
}
int boundaryFieldWidth = maximumEdgeFieldWidth(entries, baseSeed, data, parent);
int boundaryFieldWidth = maximumEdgeFieldWidth(entries, baseSeed, runtime, parent);
int parentBoundaryDistance = boundarySampler.edgeDistance(parent, wx, wz, boundaryFieldWidth);
if (parent.isMergeFloatingChildBiomes()) {
return sampleMerged(parent, entries, wx, wz, chunkHeight, baseSeed, data, engine, boundarySampler,
return sampleMerged(parent, entries, wx, wz, chunkHeight, baseSeed, runtime, boundarySampler,
parentBoundaryDistance, boundaryFieldWidth);
}
@@ -223,7 +204,7 @@ public final class FloatingIslandSample {
entry = entries.getFirst();
} else {
IrisFloatingChildBiomes reference = entries.getFirst();
CNG picker = reference.getPickerCng(baseSeed, data);
CNG picker = reference.getPickerCng(baseSeed, runtime);
if (picker == null) {
warnNullCng("pickerStyle", parent);
return reject(REJECT_NO_PICK);
@@ -237,20 +218,20 @@ public final class FloatingIslandSample {
ownershipBoundaryDistance = ownership.boundaryDistance();
}
return sampleEntry(parent, entry, wx, wz, chunkHeight, baseSeed, data, engine, boundarySampler,
return sampleEntry(parent, entry, wx, wz, chunkHeight, baseSeed, runtime, boundarySampler,
parentBoundaryDistance, ownershipBoundaryDistance);
}
private static FloatingIslandSample sampleMerged(IrisBiome parent, KList<IrisFloatingChildBiomes> entries,
int wx, int wz, int chunkHeight, long baseSeed, IrisData data,
Engine engine, FloatingIslandBoundarySampler boundarySampler,
int wx, int wz, int chunkHeight, long baseSeed, PackRuntime runtime,
FloatingIslandBoundarySampler boundarySampler,
int parentBoundaryDistance, int boundaryFieldWidth) {
KList<FloatingIslandSample> samples = new KList<>();
int minY = Integer.MAX_VALUE;
int maxY = Integer.MIN_VALUE;
for (IrisFloatingChildBiomes entry : entries) {
FloatingIslandSample sample = sampleEntry(parent, entry, wx, wz, chunkHeight, baseSeed, data, engine,
FloatingIslandSample sample = sampleEntry(parent, entry, wx, wz, chunkHeight, baseSeed, runtime,
boundarySampler, parentBoundaryDistance, boundaryFieldWidth + 1);
if (sample == null) {
continue;
@@ -313,11 +294,11 @@ public final class FloatingIslandSample {
}
private static FloatingIslandSample sampleEntry(IrisBiome parent, IrisFloatingChildBiomes entry, int wx, int wz,
int chunkHeight, long baseSeed, IrisData data, Engine engine,
int chunkHeight, long baseSeed, PackRuntime runtime,
FloatingIslandBoundarySampler boundarySampler,
int parentBoundaryDistance, int ownershipBoundaryDistance) {
FloatingIslandEdgeProfile edgeProfile = resolveEdgeProfile(entry, baseSeed, data, parent);
CNG footprintCng = entry.getFootprintCng(baseSeed, data);
FloatingIslandEdgeProfile edgeProfile = resolveEdgeProfile(entry, baseSeed, runtime, parent);
CNG footprintCng = entry.getFootprintCng(baseSeed, runtime);
if (footprintCng == null) {
warnNullCng("footprintStyle", parent);
return reject(REJECT_NO_SEED);
@@ -343,23 +324,23 @@ public final class FloatingIslandSample {
return reject(REJECT_NO_THICKNESS);
}
CNG altitudeCng = entry.getAltitudeCng(baseSeed, data);
CNG altitudeCng = entry.getAltitudeCng(baseSeed, runtime);
if (altitudeCng == null) {
warnNullCng("altitudeStyle", parent);
return reject(REJECT_NO_SEED);
}
double altNoise = altitudeCng.noise(wx, wz);
double altClamped = Math.max(0, Math.min(1, altNoise));
int worldMin = engine.getWorld().minHeight();
int worldMin = runtime.engine().getWorld().minHeight();
int minAlt = Math.max(0, entry.getMinHeightAboveSurface() - worldMin);
int maxAlt = Math.max(minAlt, entry.getMaxHeightAboveSurface() - worldMin);
int baseY = minAlt + (int) Math.round(altClamped * (maxAlt - minAlt));
IrisBiome target = entry.getRealBiome(parent, data);
int fullTopHeight = computeTopHeight(entry, target, engine, baseSeed, wx, wz, data);
IrisBiome target = entry.getRealBiome(parent, runtime.data());
int fullTopHeight = computeTopHeight(entry, target, runtime, baseSeed, wx, wz);
int topH = roundedEdgeHeight(fullTopHeight, edgeFade);
CNG bottomCng = entry.getBottomCng(baseSeed, data);
CNG bottomCng = entry.getBottomCng(baseSeed, runtime);
if (bottomCng == null) {
warnNullCng("bottomStyle", parent);
return reject(REJECT_NO_SEED);
@@ -416,11 +397,11 @@ public final class FloatingIslandSample {
}
boolean[] solidMask = new boolean[thickness];
CNG wallWarp = entry.getWallWarpCng(baseSeed, data);
CNG wallWarp = entry.getWallWarpCng(baseSeed, runtime);
double warpAmp = Math.max(0, entry.getWallWarpAmplitude());
double effectiveWarpAmp = effectiveWallWarpAmplitude(warpAmp, edgeFade);
IrisCaveProfileSampler carvingProfileSampler = entry.getCarvingProfileSampler(engine, data);
CNG carve = carvingProfileSampler == null && !entry.hasCarvingReference() ? entry.getCarveCng(baseSeed, data) : null;
IrisCaveProfileSampler carvingProfileSampler = entry.getCarvingProfileSampler(runtime);
CNG carve = carvingProfileSampler == null && !entry.hasCarvingReference() ? entry.getCarveCng(baseSeed, runtime) : null;
double carveThreshold = entry.getCarveThreshold();
boolean useWarp = wallWarp != null && effectiveWarpAmp > 0;
boolean useProfileCarve = carvingProfileSampler != null;
@@ -683,27 +664,7 @@ public final class FloatingIslandSample {
}
private static double footprintSigned(CNG footprintCng, int wx, int wz) {
IdentityHashMap<CNG, Long2DoubleOpenHashMap> memoByCng = FOOTPRINT_MEMO.get();
Long2DoubleOpenHashMap memo = memoByCng.get(footprintCng);
if (memo == null) {
memo = new Long2DoubleOpenHashMap(512);
memo.defaultReturnValue(Double.NaN);
memoByCng.put(footprintCng, memo);
}
long key = columnKey(wx, wz);
double cached = memo.get(key);
if (!Double.isNaN(cached)) {
return cached;
}
double signed = signedFromUnit(footprintCng.noise(wx, wz));
memo.put(key, signed);
return signed;
}
private static long columnKey(int wx, int wz) {
return ((long) wx << 32) ^ (wz & 0xFFFFFFFFL);
return signedFromUnit(footprintCng.noise(wx, wz));
}
private static double signedFromUnit(double value) {
@@ -779,7 +740,7 @@ public final class FloatingIslandSample {
}
}
private static int computeTopHeight(IrisFloatingChildBiomes entry, IrisBiome target, Engine engine, long baseSeed, int wx, int wz, IrisData data) {
private static int computeTopHeight(IrisFloatingChildBiomes entry, IrisBiome target, PackRuntime runtime, long baseSeed, int wx, int wz) {
int maxTopHeight = Math.max(0, entry.getMaxTopHeight());
if (maxTopHeight == 0) {
return 0;
@@ -787,7 +748,7 @@ public final class FloatingIslandSample {
return switch (entry.getTopShapeMode()) {
case FLAT -> maxTopHeight;
case NOISE -> {
CNG topCng = entry.getTopShapeCng(baseSeed, data);
CNG topCng = entry.getTopShapeCng(baseSeed, runtime);
if (topCng == null) {
warnNullCng("topShapeStyle", null);
yield maxTopHeight / 2;
@@ -801,7 +762,7 @@ public final class FloatingIslandSample {
if (target == null) {
yield maxTopHeight / 2;
}
double h = target.getHeight(engine, wx, wz, baseSeed);
double h = target.getHeight(runtime, wx, wz, baseSeed);
int rounded = (int) Math.round(h);
if (rounded < 0) {
yield 0;
@@ -810,21 +771,4 @@ public final class FloatingIslandSample {
}
};
}
private static final class ChunkMemo {
private final HashMap<Long, MemoizedSample> samples = new HashMap<>(256);
private MemoContext context;
}
private record MemoContext(int chunkX, int chunkZ, int height, long seed, IrisData data, Engine engine,
FloatingIslandBoundarySampler boundarySampler) {
private boolean matches(int chunkX, int chunkZ, int height, long seed, IrisData data, Engine engine,
FloatingIslandBoundarySampler boundarySampler) {
return this.chunkX == chunkX && this.chunkZ == chunkZ && this.height == height && this.seed == seed
&& this.data == data && this.engine == engine && this.boundarySampler == boundarySampler;
}
}
private record MemoizedSample(IrisBiome parent, FloatingIslandSample sample) {
}
}
@@ -48,7 +48,6 @@ import art.arcane.iris.pack.loading.IrisData;
import art.arcane.iris.pack.loading.IrisRegistrant;
import art.arcane.iris.generation.runtime.IrisComplex;
import art.arcane.volmlib.util.cache.AtomicCache;
import art.arcane.iris.generation.cache.LazyBoundedCache;
import art.arcane.iris.generation.runtime.Engine;
import art.arcane.iris.pack.schema.annotation.ArrayType;
import art.arcane.iris.pack.schema.annotation.DependsOn;
@@ -64,7 +63,6 @@ import art.arcane.volmlib.util.collection.KSet;
import art.arcane.iris.generation.block.DataProvider;
import art.arcane.volmlib.util.math.RNG;
import art.arcane.volmlib.util.noise.CNG;
import art.arcane.iris.generation.context.IrisContext;
import art.arcane.volmlib.util.stream.ProceduralStream;
import lombok.AccessLevel;
import lombok.Data;
@@ -94,7 +92,6 @@ import java.util.Objects;
@EqualsAndHashCode(callSuper = false)
public class IrisBiome extends IrisRegistrant implements Rarity {
public static final int CHILD_HOPS = 4;
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<>();
@@ -105,25 +102,10 @@ public class IrisBiome extends IrisRegistrant implements Rarity {
private final transient AtomicCache<Color> cacheColorDecoratorLoad = new AtomicCache<>();
private final transient AtomicCache<Color> cacheColorLayerLoad = new AtomicCache<>();
private final transient AtomicCache<Color> cacheColorDepositLoad = new AtomicCache<>();
@Getter(AccessLevel.NONE)
@Setter(AccessLevel.NONE)
private final transient LazyBoundedCache<ChildGeneratorKey, CNG> childrenGenerators = new LazyBoundedCache<>(8);
@Getter(AccessLevel.NONE)
@Setter(AccessLevel.NONE)
private transient volatile CachedChildGenerator recentChildGenerator;
@Getter(AccessLevel.NONE)
private final transient LazyBoundedCache<Long, CNG> biomeGenerators =
new LazyBoundedCache<>(BIOME_GENERATOR_CACHE_SIZE);
@Getter(AccessLevel.NONE)
@Setter(AccessLevel.NONE)
private transient volatile SeededBiomeGenerator recentBiomeGenerator;
private final transient AtomicCache<Integer> maxHeight = new AtomicCache<>();
private final transient AtomicCache<Integer> maxWithObjectHeight = new AtomicCache<>();
private final transient AtomicCache<IrisBiome> realCarveBiome = new AtomicCache<>();
private final transient AtomicCache<KList<IrisBiome>> realChildren = new AtomicCache<>();
private final transient IrisBiomeLayerHeightCache layerHeightGenerators = new IrisBiomeLayerHeightCache();
private final transient IrisBiomeLayerHeightCache layerCeilingHeightGenerators = new IrisBiomeLayerHeightCache();
private final transient IrisBiomeLayerHeightCache layerSeaHeightGenerators = new IrisBiomeLayerHeightCache();
private final transient AtomicCache<KList<IrisOreGenerator>> surfaceOreCache = new AtomicCache<>();
private final transient AtomicCache<KList<IrisOreGenerator>> undergroundOreCache = new AtomicCache<>();
private final transient AtomicCache<IrisOreBands> surfaceOreBandsCache = new AtomicCache<>();
@@ -470,69 +452,37 @@ public class IrisBiome extends IrisRegistrant implements Rarity {
});
}
public double getHeight(Engine xg, double x, double z, long seed) {
public double getHeight(PackRuntime runtime, double x, double z, long seed) {
double height = 0;
PackRuntime runtime = PackRuntime.of(xg, xg.getData());
for (IrisBiomeGeneratorLink i : generators) {
height += i.getHeight(runtime, x, z, seed);
}
return Math.max(0, Math.min(height, xg.getHeight()));
}
public CNG getBiomeGenerator(RNG random) {
IrisData loader = getLoader();
Engine engine = resolveBiomeGeneratorEngine(loader);
return getBiomeGenerator(random, engine);
return Math.max(0, Math.min(height, runtime.engine().getHeight()));
}
/** Engines seed the scatter generator from their own biome seed; engine-less tools use the caller's seed. */
public CNG getBiomeGenerator(RNG random, Engine engine) {
IrisData loader = getLoader();
long seed = engine == null ? random.getSeed() : engine.getSeedManager().getBiome();
SeededBiomeGenerator recent = recentBiomeGenerator;
if (recent != null && recent.seed == seed) {
return recent.generator;
}
CNG generator = biomeGenerators.computeIfAbsent(seed, ignored -> createBiomeGenerator(seed, loader));
recentBiomeGenerator = new SeededBiomeGenerator(seed, generator);
return generator;
return PackRuntime.of(engine, getLoader()).biome(this).biomeGenerator(seed);
}
private Engine resolveBiomeGeneratorEngine(IrisData loader) {
IrisContext context = IrisContext.get();
if (context != null) {
Engine contextEngine = context.getEngine();
if (!contextEngine.isClosed() && (loader == null || contextEngine.getData() == loader)) {
return contextEngine;
}
}
return loader == null ? null : loader.getEngine();
}
private CNG createBiomeGenerator(long seed, IrisData loader) {
CNG createBiomeGenerator(long seed, PackRuntime runtime) {
int signature = 213949 + 228888 + getRarity() + getName().length();
return biomeStyle.createNoCache(new RNG(seed).nextParallelRNG(signature), PackRuntime.forContext(loader));
return biomeStyle.createNoCache(new RNG(seed).nextParallelRNG(signature), runtime);
}
public CNG getChildrenGenerator(RNG random, int sig, double scale) {
return getChildrenGenerator(deriveChildStyleSeed(random, sig).getSeed(), scale);
public CNG getChildrenGenerator(PackRuntime runtime, RNG random, int sig, double scale) {
return getChildrenGenerator(runtime, deriveChildStyleSeed(random, sig).getSeed(), scale);
}
public CNG getChildrenGenerator(long seed, double scale) {
IrisData data = getLoader();
Engine engine = data == null ? null : data.getEngine();
CachedChildGenerator recent = recentChildGenerator;
if (recent != null && recent.key.matches(seed, scale, data, engine)) {
return recent.generator;
}
ChildGeneratorKey key = new ChildGeneratorKey(seed, scale, data, engine);
CNG generator = childrenGenerators.computeIfAbsent(key,
ignored -> getChildStyle().createScaledGenerator(new RNG(seed), PackRuntime.of(engine, data), scale));
recentChildGenerator = new CachedChildGenerator(key, generator);
return generator;
public CNG getChildrenGenerator(PackRuntime runtime, long seed, double scale) {
return runtime.biome(this).childrenGenerator(seed, scale);
}
CNG createChildrenGenerator(long seed, double scale, PackRuntime runtime) {
return getChildStyle().createScaledGenerator(new RNG(seed), runtime, scale);
}
static RNG deriveChildStyleSeed(RNG random, int signature) {
@@ -543,24 +493,24 @@ public class IrisBiome extends IrisRegistrant implements Rarity {
return deriveChildStyleSeed(random, signature).getSeed();
}
public KList<NativeBlockState> generateLayers(IrisDimension dim, double wx, double wz, RNG random, int maxDepth, int height, IrisData rdata, IrisComplex complex) {
return IrisBiomeLayerGenerator.generateLayers(this, dim, wx, wz, random, maxDepth, height, rdata, complex);
public KList<NativeBlockState> generateLayers(IrisDimension dim, double wx, double wz, RNG random, int maxDepth, int height, PackRuntime runtime, IrisComplex complex) {
return IrisBiomeLayerGenerator.generateLayers(this, dim, wx, wz, random, maxDepth, height, runtime, complex);
}
public KList<NativeBlockState> generateLayersWithSlope(IrisDimension dim, double wx, double wz, RNG random, int maxDepth, int height, IrisData rdata, ProceduralStream<Double> slopeStream) {
return IrisBiomeLayerGenerator.generateLayers(this, dim, wx, wz, random, maxDepth, height, rdata, slopeStream);
public KList<NativeBlockState> generateLayersWithSlope(IrisDimension dim, double wx, double wz, RNG random, int maxDepth, int height, PackRuntime runtime, ProceduralStream<Double> slopeStream) {
return IrisBiomeLayerGenerator.generateLayers(this, dim, wx, wz, random, maxDepth, height, runtime, slopeStream);
}
public KList<NativeBlockState> generateCeilingLayers(IrisDimension dim, double wx, double wz, RNG random, int maxDepth, int height, IrisData rdata, IrisComplex complex) {
return IrisBiomeLayerGenerator.generateCeilingLayers(this, dim, wx, wz, random, maxDepth, height, rdata, complex);
public KList<NativeBlockState> generateCeilingLayers(IrisDimension dim, double wx, double wz, RNG random, int maxDepth, int height, PackRuntime runtime, IrisComplex complex) {
return IrisBiomeLayerGenerator.generateCeilingLayers(this, dim, wx, wz, random, maxDepth, height, runtime, complex);
}
public KList<NativeBlockState> generateLockedLayers(double wx, double wz, RNG random, int maxDepthf, int height, IrisData rdata, IrisComplex complex) {
return IrisBiomeLayerGenerator.generateLockedLayers(this, wx, wz, random, maxDepthf, height, rdata, complex);
public KList<NativeBlockState> generateLockedLayers(double wx, double wz, RNG random, int maxDepthf, int height, PackRuntime runtime, IrisComplex complex) {
return IrisBiomeLayerGenerator.generateLockedLayers(this, wx, wz, random, maxDepthf, height, runtime, complex);
}
public KList<NativeBlockState> generateSeaLayers(double wx, double wz, RNG random, int maxDepth, IrisData rdata) {
return IrisBiomeLayerGenerator.generateSeaLayers(this, wx, wz, random, maxDepth, rdata);
public KList<NativeBlockState> generateSeaLayers(double wx, double wz, RNG random, int maxDepth, PackRuntime runtime) {
return IrisBiomeLayerGenerator.generateSeaLayers(this, wx, wz, random, maxDepth, runtime);
}
/**
@@ -575,20 +525,20 @@ public class IrisBiome extends IrisRegistrant implements Rarity {
return IrisBiomeLayerGenerator.getMaxWithObjectHeight(this, data, engine);
}
public KList<CNG> getLayerHeightGenerators(RNG rng, IrisData rdata) {
return IrisBiomeLayerGenerator.getLayerHeightGenerators(this, rng, rdata);
public KList<CNG> getLayerHeightGenerators(RNG rng, PackRuntime runtime) {
return runtime.biome(this).layerHeights(rng.getSeed());
}
public KList<CNG> getLayerSeaHeightGenerators(RNG rng, IrisData data) {
return IrisBiomeLayerGenerator.getLayerSeaHeightGenerators(this, rng, data);
public KList<CNG> getLayerSeaHeightGenerators(RNG rng, PackRuntime runtime) {
return runtime.biome(this).seaLayerHeights(rng.getSeed());
}
public KList<CNG> getCaveCeilingLayerHeightGenerators(RNG rng, IrisData data) {
return IrisBiomeLayerGenerator.getCaveCeilingLayerHeightGenerators(this, rng, data);
public KList<CNG> getCaveCeilingLayerHeightGenerators(RNG rng, PackRuntime runtime) {
return runtime.biome(this).ceilingLayerHeights(rng.getSeed());
}
public NativeBlockState getSurfaceBlock(int x, int z, RNG rng, IrisData idm) {
return IrisBiomeLayerGenerator.getSurfaceBlock(this, x, z, rng, idm);
public NativeBlockState getSurfaceBlock(int x, int z, RNG rng, PackRuntime runtime) {
return IrisBiomeLayerGenerator.getSurfaceBlock(this, x, z, rng, runtime);
}
public boolean isLand() {
@@ -618,18 +568,10 @@ public class IrisBiome extends IrisRegistrant implements Rarity {
return inferredType.equals(InferredType.SHORE);
}
public Biome getSkyBiome(RNG rng, double x, double y, double z) {
return IrisBiomeDerivatives.getSkyBiome(this, rng, resolveBiomeGeneratorEngine(getLoader()), x, y, z);
}
public Biome getSkyBiome(RNG rng, Engine engine, double x, double y, double z) {
return IrisBiomeDerivatives.getSkyBiome(this, rng, engine, x, y, z);
}
public IrisBiomeCustom getCustomBiome(RNG rng, double x, double y, double z) {
return IrisBiomeDerivatives.getCustomBiome(this, rng, resolveBiomeGeneratorEngine(getLoader()), x, y, z);
}
public IrisBiomeCustom getCustomBiome(RNG rng, Engine engine, double x, double y, double z) {
return IrisBiomeDerivatives.getCustomBiome(this, rng, engine, x, y, z);
}
@@ -658,27 +600,14 @@ public class IrisBiome extends IrisRegistrant implements Rarity {
return new KList<>(m);
}
//TODO: Test
public Biome getGroundBiome(RNG rng, double x, double y, double z) {
return IrisBiomeDerivatives.getGroundBiome(this, rng, resolveBiomeGeneratorEngine(getLoader()), x, y, z);
}
public Biome getGroundBiome(RNG rng, Engine engine, double x, double y, double z) {
return IrisBiomeDerivatives.getGroundBiome(this, rng, engine, x, y, z);
}
public String getSkyBiomeKey(RNG rng, double x, double y, double z) {
return IrisBiomeDerivatives.getSkyBiomeKey(this, rng, resolveBiomeGeneratorEngine(getLoader()), x, y, z);
}
public String getSkyBiomeKey(RNG rng, Engine engine, double x, double y, double z) {
return IrisBiomeDerivatives.getSkyBiomeKey(this, rng, engine, x, y, z);
}
public String getGroundBiomeKey(RNG rng, double x, double y, double z) {
return IrisBiomeDerivatives.getGroundBiomeKey(this, rng, resolveBiomeGeneratorEngine(getLoader()), x, y, z);
}
public String getGroundBiomeKey(RNG rng, Engine engine, double x, double y, double z) {
return IrisBiomeDerivatives.getGroundBiomeKey(this, rng, engine, x, y, z);
}
@@ -716,37 +645,4 @@ public class IrisBiome extends IrisRegistrant implements Rarity {
public String getTypeName() {
return "Biome";
}
private static final class SeededBiomeGenerator {
private final long seed;
private final CNG generator;
private SeededBiomeGenerator(long seed, CNG generator) {
this.seed = seed;
this.generator = generator;
}
}
private record ChildGeneratorKey(long seed, double scale, IrisData data, Engine engine) {
private boolean matches(long seed, double scale, IrisData data, Engine engine) {
return this.seed == seed && Double.doubleToLongBits(this.scale) == Double.doubleToLongBits(scale)
&& this.data == data && this.engine == engine;
}
@Override
public boolean equals(Object object) {
return object instanceof ChildGeneratorKey other && matches(other.seed, other.scale, other.data, other.engine);
}
@Override
public int hashCode() {
int hash = Long.hashCode(seed);
hash = 31 * hash + Double.hashCode(scale);
hash = 31 * hash + System.identityHashCode(data);
return 31 * hash + System.identityHashCode(engine);
}
}
private record CachedChildGenerator(ChildGeneratorKey key, CNG generator) {
}
}
@@ -18,6 +18,7 @@
package art.arcane.iris.generation.biome;
import art.arcane.iris.generation.runtime.PackRuntime;
import art.arcane.iris.generation.terrain.IrisDimension;
import art.arcane.iris.generation.terrain.IrisSlopeClip;
import art.arcane.iris.structure.object.IrisObject;
@@ -45,18 +46,18 @@ final class IrisBiomeLayerGenerator {
private IrisBiomeLayerGenerator() {
}
static KList<NativeBlockState> generateLayers(IrisBiome biome, IrisDimension dim, double wx, double wz, RNG random, int maxDepth, int height, IrisData rdata, IrisComplex complex) {
return generateLayers(biome, dim, wx, wz, random, maxDepth, height, rdata, complex, null);
static KList<NativeBlockState> generateLayers(IrisBiome biome, IrisDimension dim, double wx, double wz, RNG random, int maxDepth, int height, PackRuntime runtime, IrisComplex complex) {
return generateLayers(biome, dim, wx, wz, random, maxDepth, height, runtime, complex, null);
}
static KList<NativeBlockState> generateLayers(IrisBiome biome, IrisDimension dim, double wx, double wz, RNG random, int maxDepth, int height, IrisData rdata, ProceduralStream<Double> slopeStream) {
return generateLayers(biome, dim, wx, wz, random, maxDepth, height, rdata, null, slopeStream);
static KList<NativeBlockState> generateLayers(IrisBiome biome, IrisDimension dim, double wx, double wz, RNG random, int maxDepth, int height, PackRuntime runtime, ProceduralStream<Double> slopeStream) {
return generateLayers(biome, dim, wx, wz, random, maxDepth, height, runtime, null, slopeStream);
}
private static KList<NativeBlockState> generateLayers(IrisBiome biome, IrisDimension dim, double wx, double wz, RNG random, int maxDepth, int height, IrisData rdata, IrisComplex complex, ProceduralStream<Double> slopeStream) {
private static KList<NativeBlockState> generateLayers(IrisBiome biome, IrisDimension dim, double wx, double wz, RNG random, int maxDepth, int height, PackRuntime runtime, IrisComplex complex, ProceduralStream<Double> slopeStream) {
if (biome.isLockLayers()) {
KList<NativeBlockState> data = generateLockedLayers(biome, wx, wz, random, maxDepth, height, rdata, complex, slopeStream);
appendSurfaceFallback(data, biome, dim, wx, wz, random, Math.min(maxDepth, biome.getLockLayersMax()), rdata);
KList<NativeBlockState> data = generateLockedLayers(biome, wx, wz, random, maxDepth, height, runtime, complex, slopeStream);
appendSurfaceFallback(data, biome, dim, wx, wz, random, Math.min(maxDepth, biome.getLockLayersMax()), runtime);
return data;
}
@@ -73,7 +74,7 @@ final class IrisBiomeLayerGenerator {
return data;
}
KList<CNG> heightGenerators = getLayerHeightGenerators(biome, random, rdata);
KList<CNG> heightGenerators = getLayerHeightGenerators(biome, random, runtime);
double surfaceSlope = 0D;
boolean sampledSlope = false;
@@ -98,7 +99,7 @@ final class IrisBiomeLayerGenerator {
continue;
}
appendLayer(data, layer, i, d, wx, wz, random, maxDepth, rdata);
appendLayer(data, layer, i, d, wx, wz, random, maxDepth, runtime);
if (data.size() >= maxDepth) {
break;
@@ -115,12 +116,12 @@ final class IrisBiomeLayerGenerator {
}
}
appendSurfaceFallback(data, biome, dim, wx, wz, random, maxDepth, rdata);
appendSurfaceFallback(data, biome, dim, wx, wz, random, maxDepth, runtime);
return data;
}
private static void appendSurfaceFallback(KList<NativeBlockState> data, IrisBiome biome, IrisDimension dim,
double wx, double wz, RNG random, int maxDepth, IrisData rdata) {
double wx, double wz, RNG random, int maxDepth, PackRuntime runtime) {
if (!data.isEmpty() || maxDepth <= 0 || biome.getLayers().isEmpty()) {
return;
}
@@ -129,11 +130,11 @@ final class IrisBiomeLayerGenerator {
fallback = dim.getSurfaceLayerFallback();
}
if (fallback == IrisSurfaceLayerFallback.TOP_LAYER) {
appendLayer(data, biome.getLayers().get(0), 0, 1, wx, wz, random, maxDepth, rdata);
appendLayer(data, biome.getLayers().get(0), 0, 1, wx, wz, random, maxDepth, runtime);
}
}
static KList<NativeBlockState> generateCeilingLayers(IrisBiome biome, IrisDimension dim, double wx, double wz, RNG random, int maxDepth, int height, IrisData rdata, IrisComplex complex) {
static KList<NativeBlockState> generateCeilingLayers(IrisBiome biome, IrisDimension dim, double wx, double wz, RNG random, int maxDepth, int height, PackRuntime runtime, IrisComplex complex) {
KList<NativeBlockState> data = new KList<>();
if (maxDepth <= 0) {
@@ -147,7 +148,7 @@ final class IrisBiomeLayerGenerator {
return data;
}
KList<CNG> heightGenerators = getCaveCeilingLayerHeightGenerators(biome, random, rdata);
KList<CNG> heightGenerators = getCaveCeilingLayerHeightGenerators(biome, random, runtime);
for (int i = 0; i < layerCount; i++) {
IrisBiomePaletteLayer layer = ceilingLayers.get(i);
@@ -159,7 +160,7 @@ final class IrisBiomeLayerGenerator {
continue;
}
appendLayer(data, layer, i, d, wx, wz, random, maxDepth, rdata);
appendLayer(data, layer, i, d, wx, wz, random, maxDepth, runtime);
if (data.size() >= maxDepth) {
break;
@@ -179,11 +180,11 @@ final class IrisBiomeLayerGenerator {
return data;
}
static KList<NativeBlockState> generateLockedLayers(IrisBiome biome, double wx, double wz, RNG random, int maxDepthf, int height, IrisData rdata, IrisComplex complex) {
return generateLockedLayers(biome, wx, wz, random, maxDepthf, height, rdata, complex, null);
static KList<NativeBlockState> generateLockedLayers(IrisBiome biome, double wx, double wz, RNG random, int maxDepthf, int height, PackRuntime runtime, IrisComplex complex) {
return generateLockedLayers(biome, wx, wz, random, maxDepthf, height, runtime, complex, null);
}
private static KList<NativeBlockState> generateLockedLayers(IrisBiome biome, double wx, double wz, RNG random, int maxDepthf, int height, IrisData rdata, IrisComplex complex, ProceduralStream<Double> slopeStream) {
private static KList<NativeBlockState> generateLockedLayers(IrisBiome biome, double wx, double wz, RNG random, int maxDepthf, int height, PackRuntime runtime, IrisComplex complex, ProceduralStream<Double> slopeStream) {
KList<NativeBlockState> data = new KList<>();
int maxDepth = Math.min(maxDepthf, biome.getLockLayersMax());
KList<IrisBiomePaletteLayer> layers = biome.getLayers();
@@ -192,7 +193,7 @@ final class IrisBiomeLayerGenerator {
return data;
}
KList<CNG> heightGenerators = getLayerHeightGenerators(biome, random, rdata);
KList<CNG> heightGenerators = getLayerHeightGenerators(biome, random, runtime);
int[] boundaries = new int[layerCount + 1];
double surfaceSlope = 0D;
boolean sampledSlope = false;
@@ -230,7 +231,7 @@ final class IrisBiomeLayerGenerator {
double zoom = layer.getZoom();
try {
data.add(layer.get(random, layerIndex + offset,
(wx + offset) / zoom, offset, (wz - offset) / zoom, rdata));
(wx + offset) / zoom, offset, (wz - offset) / zoom, runtime));
} catch (Throwable error) {
GenerationFailures.skipPlacement(error, "surface layer", "block", (int) wx, height - depth, (int) wz, biome.getLoadKey());
}
@@ -274,7 +275,7 @@ final class IrisBiomeLayerGenerator {
: complex.getSlopeStream().getDouble(x, z);
}
static KList<NativeBlockState> generateSeaLayers(IrisBiome biome, double wx, double wz, RNG random, int maxDepth, IrisData rdata) {
static KList<NativeBlockState> generateSeaLayers(IrisBiome biome, double wx, double wz, RNG random, int maxDepth, PackRuntime runtime) {
KList<NativeBlockState> data = new KList<>();
KList<IrisBiomePaletteLayer> seaLayers = biome.getSeaLayers();
@@ -284,7 +285,7 @@ final class IrisBiomeLayerGenerator {
return data;
}
KList<CNG> heightGenerators = getLayerSeaHeightGenerators(biome, random, rdata);
KList<CNG> heightGenerators = getLayerSeaHeightGenerators(biome, random, runtime);
for (int i = 0; i < layerCount; i++) {
IrisBiomePaletteLayer layer = seaLayers.get(i);
@@ -296,7 +297,7 @@ final class IrisBiomeLayerGenerator {
continue;
}
appendLayer(data, layer, i, d, wx, wz, random, maxDepth, rdata);
appendLayer(data, layer, i, d, wx, wz, random, maxDepth, runtime);
if (data.size() >= maxDepth) {
break;
@@ -306,46 +307,51 @@ final class IrisBiomeLayerGenerator {
return data;
}
static KList<CNG> getLayerHeightGenerators(IrisBiome biome, RNG rng, IrisData rdata) {
return getHeightGenerators(biome.getLayerHeightGenerators(), biome.getLayers(), 7235, rng, rdata);
static KList<CNG> getLayerHeightGenerators(IrisBiome biome, RNG rng, PackRuntime runtime) {
return runtime.biome(biome).layerHeights(rng.getSeed());
}
static KList<CNG> getLayerSeaHeightGenerators(IrisBiome biome, RNG rng, IrisData data) {
return getHeightGenerators(biome.getLayerSeaHeightGenerators(), biome.getSeaLayers(), 7735, rng, data);
static KList<CNG> getLayerSeaHeightGenerators(IrisBiome biome, RNG rng, PackRuntime runtime) {
return runtime.biome(biome).seaLayerHeights(rng.getSeed());
}
static KList<CNG> getCaveCeilingLayerHeightGenerators(IrisBiome biome, RNG rng, IrisData data) {
return getHeightGenerators(biome.getLayerCeilingHeightGenerators(), biome.getCaveCeilingLayers(), 7235, rng, data);
static KList<CNG> getCaveCeilingLayerHeightGenerators(IrisBiome biome, RNG rng, PackRuntime runtime) {
return runtime.biome(biome).ceilingLayerHeights(rng.getSeed());
}
private static KList<CNG> getHeightGenerators(IrisBiomeLayerHeightCache cache,
KList<IrisBiomePaletteLayer> layers,
int seedOffset, RNG rng, IrisData data) {
return cache.get(layers, seedOffset, rng, data);
static KList<CNG> createHeightGenerators(KList<IrisBiomePaletteLayer> layers, int seedOffset, long seed,
PackRuntime runtime) {
RNG rng = new RNG(seed);
KList<CNG> result = new KList<>();
int offset = seedOffset;
for (IrisBiomePaletteLayer layer : layers) {
result.add(layer.getHeightGenerator(rng.nextParallelRNG((offset++) * offset * offset * offset), runtime));
}
return result;
}
private static void appendLayer(KList<NativeBlockState> blocks, IrisBiomePaletteLayer layer,
int layerIndex, int thickness, double x, double z,
RNG random, int maxDepth, IrisData data) {
RNG random, int maxDepth, PackRuntime runtime) {
double zoom = layer.getZoom();
for (int offset = 0; offset < thickness && blocks.size() < maxDepth; offset++) {
try {
blocks.add(layer.get(random, layerIndex + offset,
(x + offset) / zoom, offset, (z - offset) / zoom, data));
(x + offset) / zoom, offset, (z - offset) / zoom, runtime));
} catch (Throwable error) {
GenerationFailures.skipPlacement(error, "surface layer", "block", (int) x, -1, (int) z, "none");
}
}
}
static NativeBlockState getSurfaceBlock(IrisBiome biome, int x, int z, RNG rng, IrisData idm) {
static NativeBlockState getSurfaceBlock(IrisBiome biome, int x, int z, RNG rng, PackRuntime runtime) {
KList<IrisBiomePaletteLayer> layers = biome.getLayers();
if (layers.isEmpty()) {
return B.getState("AIR");
}
return layers.get(0).get(rng, x, 0, z, idm);
return layers.get(0).get(rng, x, 0, z, runtime);
}
static int getMaxHeight(IrisBiome biome, Engine engine) {
@@ -1,68 +0,0 @@
package art.arcane.iris.generation.biome;
import art.arcane.iris.generation.cache.LazyBoundedCache;
import art.arcane.iris.generation.runtime.Engine;
import art.arcane.iris.pack.loading.IrisData;
import art.arcane.volmlib.util.collection.KList;
import art.arcane.volmlib.util.math.RNG;
import art.arcane.volmlib.util.noise.CNG;
final class IrisBiomeLayerHeightCache {
private final LazyBoundedCache<GeneratorKey, KList<CNG>> generators = new LazyBoundedCache<>(32);
private volatile CachedGenerators recent;
KList<CNG> get(KList<IrisBiomePaletteLayer> layers, int seedOffset, RNG rng, IrisData data) {
Engine engine = data == null ? null : data.getEngine();
long seed = rng.getSeed();
CachedGenerators cached = recent;
if (cached != null && cached.key.matches(data, engine, seed)) {
return cached.generators;
}
GeneratorKey key = new GeneratorKey(data, engine, seed);
KList<CNG> result = generators.computeIfAbsent(key, ignored -> create(layers, seedOffset, rng, data));
recent = new CachedGenerators(key, result);
return result;
}
private static KList<CNG> create(KList<IrisBiomePaletteLayer> layers, int seedOffset, RNG rng, IrisData data) {
KList<CNG> result = new KList<>();
int offset = seedOffset;
for (IrisBiomePaletteLayer layer : layers) {
result.add(layer.getHeightGenerator(rng.nextParallelRNG((offset++) * offset * offset * offset), data));
}
return result;
}
private record CachedGenerators(GeneratorKey key, KList<CNG> generators) {
}
private static final class GeneratorKey {
private final IrisData data;
private final Engine engine;
private final long seed;
private GeneratorKey(IrisData data, Engine engine, long seed) {
this.data = data;
this.engine = engine;
this.seed = seed;
}
private boolean matches(IrisData data, Engine engine, long seed) {
return this.data == data && this.engine == engine && this.seed == seed;
}
@Override
public boolean equals(Object object) {
return this == object || object instanceof GeneratorKey other
&& matches(other.data, other.engine, other.seed);
}
@Override
public int hashCode() {
int result = System.identityHashCode(data);
result = 31 * result + System.identityHashCode(engine);
return 31 * result + Long.hashCode(seed);
}
}
}
@@ -26,8 +26,6 @@ import art.arcane.iris.generation.terrain.IrisSlopeClip;
import art.arcane.iris.pack.loading.IrisData;
import art.arcane.volmlib.util.cache.AtomicCache;
import art.arcane.iris.generation.cache.LazyBoundedCache;
import art.arcane.iris.generation.runtime.Engine;
import art.arcane.iris.pack.schema.annotation.ArrayType;
import art.arcane.iris.pack.schema.annotation.DependsOn;
import art.arcane.volmlib.util.documentation.Description;
@@ -38,17 +36,12 @@ import art.arcane.iris.pack.schema.annotation.Snippet;
import art.arcane.volmlib.util.collection.KList;
import art.arcane.volmlib.util.math.RNG;
import art.arcane.volmlib.util.noise.CNG;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
import lombok.Setter;
import lombok.experimental.Accessors;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.atomic.AtomicReferenceArray;
@Snippet("biome-palette")
@Accessors(chain = true)
@@ -57,24 +50,7 @@ import java.util.concurrent.atomic.AtomicReferenceArray;
@Description("A layer of surface / subsurface material in biomes")
@Data
public class IrisBiomePaletteLayer {
private static final int LAYER_GENERATOR_CACHE_SIZE = 32;
private final transient AtomicCache<KList<NativeBlockState>> blockData = new AtomicCache<>();
@Getter(AccessLevel.NONE)
@Setter(AccessLevel.NONE)
private final transient LazyBoundedCache<LayerGeneratorKey, CNG> layerGenerators =
new LazyBoundedCache<>(LAYER_GENERATOR_CACHE_SIZE);
@Getter(AccessLevel.NONE)
@Setter(AccessLevel.NONE)
private final transient AtomicReferenceArray<CachedLayerGenerator> recentLayerGenerators =
new AtomicReferenceArray<>(LAYER_GENERATOR_CACHE_SIZE);
@Getter(AccessLevel.NONE)
@Setter(AccessLevel.NONE)
private final transient LazyBoundedCache<LayerGeneratorKey, CNG> heightGenerators =
new LazyBoundedCache<>(LAYER_GENERATOR_CACHE_SIZE);
@Getter(AccessLevel.NONE)
@Setter(AccessLevel.NONE)
private final transient AtomicReference<CachedLayerGenerator> recentHeightGenerator = new AtomicReference<>();
@Description("The style of noise")
private IrisGeneratorStyle style = NoiseStyle.STATIC.style();
@DependsOn({"minHeight", "maxHeight"})
@@ -99,23 +75,17 @@ public class IrisBiomePaletteLayer {
@Description("The palette of blocks to be used in this layer")
private KList<IrisBlockData> palette = new KList<IrisBlockData>().qadd(new IrisBlockData("GRASS_BLOCK"));
public CNG getHeightGenerator(RNG rng, IrisData data) {
Engine engine = data == null ? null : data.getEngine();
long generatorSeed = rng.getSeed() + minHeight * maxHeight + getBlockData(data).size();
CachedLayerGenerator recent = recentHeightGenerator.get();
if (recent != null && recent.key.matches(data, engine, generatorSeed)) {
return recent.generator;
}
LayerGeneratorKey key = new LayerGeneratorKey(data, engine, generatorSeed);
CNG generator = heightGenerators.computeIfAbsent(key,
ignored -> CNG.signature(new RNG(generatorSeed)));
recentHeightGenerator.set(new CachedLayerGenerator(key, generator));
return generator;
public CNG getHeightGenerator(RNG rng, PackRuntime runtime) {
long generatorSeed = rng.getSeed() + minHeight * maxHeight + getBlockData(runtime.data()).size();
return runtime.paletteLayer(this).heightGenerator(generatorSeed);
}
public NativeBlockState get(RNG rng, double x, double y, double z, IrisData data) {
return get(rng, 0, x, y, z, data);
static CNG createHeightGenerator(long generatorSeed) {
return CNG.signature(new RNG(generatorSeed));
}
public NativeBlockState get(RNG rng, double x, double y, double z, PackRuntime runtime) {
return get(rng, 0, x, y, z, runtime);
}
/**
@@ -123,8 +93,8 @@ public class IrisBiomePaletteLayer {
* only built inside the lazy layer generator initializer, using the exact same seed derivation
* as {@code parent.nextParallelRNG(signature)} followed by the generator signature.
*/
public NativeBlockState get(RNG parent, int signature, double x, double y, double z, IrisData data) {
KList<NativeBlockState> localBlockData = getBlockData(data);
public NativeBlockState get(RNG parent, int signature, double x, double y, double z, PackRuntime runtime) {
KList<NativeBlockState> localBlockData = getBlockData(runtime.data());
if (localBlockData.isEmpty()) {
return null;
@@ -138,29 +108,20 @@ public class IrisBiomePaletteLayer {
double scaledX = x / localZoom;
double scaledY = y / localZoom;
double scaledZ = z / localZoom;
return getLayerGenerator(parent, signature, data).fit(localBlockData, scaledX, scaledY, scaledZ);
return getLayerGenerator(parent, signature, runtime).fit(localBlockData, scaledX, scaledY, scaledZ);
}
public CNG getLayerGenerator(RNG rng, IrisData data) {
return getLayerGenerator(rng, 0, data);
public CNG getLayerGenerator(RNG rng, PackRuntime runtime) {
return getLayerGenerator(rng, 0, runtime);
}
public CNG getLayerGenerator(RNG parent, int signature, IrisData data) {
Engine engine = data == null ? null : data.getEngine();
long generatorSeed = parent.getSeed() + signature + minHeight + maxHeight + getBlockData(data).size();
int slot = (int) generatorSeed & (LAYER_GENERATOR_CACHE_SIZE - 1);
CachedLayerGenerator recent = recentLayerGenerators.getAcquire(slot);
if (recent != null && recent.key.matches(data, engine, generatorSeed)) {
return recent.generator;
}
public CNG getLayerGenerator(RNG parent, int signature, PackRuntime runtime) {
long generatorSeed = parent.getSeed() + signature + minHeight + maxHeight + getBlockData(runtime.data()).size();
return runtime.paletteLayer(this).layerGenerator(generatorSeed);
}
LayerGeneratorKey key = new LayerGeneratorKey(data, engine, generatorSeed);
CNG generator = layerGenerators.computeIfAbsent(key,
ignored -> style.create(new RNG(generatorSeed), PackRuntime.of(engine, data)));
if (generator != null) {
recentLayerGenerators.setRelease(slot, new CachedLayerGenerator(key, generator));
}
return generator;
CNG createLayerGenerator(long generatorSeed, PackRuntime runtime) {
return style.createNoCache(new RNG(generatorSeed), runtime);
}
public KList<IrisBlockData> add(String b) {
@@ -196,49 +157,4 @@ public class IrisBiomePaletteLayer {
palette.clear();
return this;
}
private static final class LayerGeneratorKey {
private final IrisData data;
private final Engine engine;
private final long seed;
private LayerGeneratorKey(IrisData data, Engine engine, long seed) {
this.data = data;
this.engine = engine;
this.seed = seed;
}
private boolean matches(IrisData data, Engine engine, long seed) {
return this.data == data && this.engine == engine && this.seed == seed;
}
@Override
public boolean equals(Object object) {
if (this == object) {
return true;
}
if (!(object instanceof LayerGeneratorKey other)) {
return false;
}
return data == other.data && engine == other.engine && seed == other.seed;
}
@Override
public int hashCode() {
int result = System.identityHashCode(data);
result = 31 * result + System.identityHashCode(engine);
result = 31 * result + Long.hashCode(seed);
return result;
}
}
private static final class CachedLayerGenerator {
private final LayerGeneratorKey key;
private final CNG generator;
private CachedLayerGenerator(LayerGeneratorKey key, CNG generator) {
this.key = key;
this.generator = generator;
}
}
}
@@ -34,10 +34,6 @@ import art.arcane.volmlib.util.math.Rarity;
import art.arcane.iris.pack.loading.IrisData;
import art.arcane.volmlib.util.cache.AtomicCache;
import art.arcane.iris.generation.cache.LazyBoundedCache;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import art.arcane.iris.generation.runtime.Engine;
import art.arcane.iris.pack.schema.annotation.ArrayType;
import art.arcane.volmlib.util.documentation.Description;
@@ -63,97 +59,72 @@ import lombok.experimental.Accessors;
@Data
public class IrisFloatingChildBiomes implements Rarity {
private final transient AtomicCache<IrisBiome> resolvedBiome = new AtomicCache<>();
@Getter(AccessLevel.NONE)
@Setter(AccessLevel.NONE)
private final transient LazyBoundedCache<RuntimeKey, FloatingIslandEdgeProfile> edgeTaperProfiles = new LazyBoundedCache<>(8);
@Getter(AccessLevel.NONE)
@Setter(AccessLevel.NONE)
private transient volatile CachedEdgeProfile recentEdgeProfile;
@Getter(AccessLevel.NONE)
@Setter(AccessLevel.NONE)
private final transient LazyBoundedCache<RuntimeKey, IrisCaveProfileSampler> carvingProfileSamplers = new LazyBoundedCache<>(8);
@Getter(AccessLevel.NONE)
@Setter(AccessLevel.NONE)
private transient volatile CachedCarvingProfile recentCarvingProfile;
private final transient AtomicCache<IrisObjectScale> shrinkScaleCache = new AtomicCache<>();
public CNG getFootprintCng(long baseSeed, IrisData data) {
return getFootprintStyle().create(baseSeed ^ 0xF007B17DL, PackRuntime.forContext(data));
public CNG getFootprintCng(long baseSeed, PackRuntime runtime) {
return getFootprintStyle().create(baseSeed ^ 0xF007B17DL, runtime);
}
public FloatingIslandEdgeProfile getEdgeTaperProfile(long baseSeed, IrisData data) {
Engine engine = data == null ? null : data.getEngine();
CachedEdgeProfile recent = recentEdgeProfile;
if (recent != null && recent.key.matches(baseSeed, data, engine)) {
return recent.profile;
}
RuntimeKey key = new RuntimeKey(baseSeed, data, engine);
FloatingIslandEdgeProfile profile = edgeTaperProfiles.computeIfAbsent(key, ignored -> {
int width = FloatingIslandEdgeProfile.clampWidth(getEdgeTaperWidth());
double amplitude = FloatingIslandEdgeProfile.clampVariationAmplitude(
getEdgeTaperVariationAmplitude(), width);
IrisGeneratorStyle style = getEdgeTaperVariationStyle();
CNG variation = amplitude > 0.0D && style != null
? style.create(baseSeed ^ 0xED6E7A9E5L, PackRuntime.forContext(data))
: null;
return new FloatingIslandEdgeProfile(width, getEdgeTaperExponent(), amplitude, variation);
});
recentEdgeProfile = new CachedEdgeProfile(key, profile);
return profile;
public FloatingIslandEdgeProfile getEdgeTaperProfile(long baseSeed, PackRuntime runtime) {
return runtime.floatingChild(this).edgeTaperProfile(baseSeed);
}
public CNG getPickerCng(long baseSeed, IrisData data) {
return getPickerStyle().create(baseSeed ^ 0x91C4E72DL, PackRuntime.forContext(data));
FloatingIslandEdgeProfile createEdgeTaperProfile(long baseSeed, PackRuntime runtime) {
int width = FloatingIslandEdgeProfile.clampWidth(getEdgeTaperWidth());
double amplitude = FloatingIslandEdgeProfile.clampVariationAmplitude(getEdgeTaperVariationAmplitude(), width);
IrisGeneratorStyle style = getEdgeTaperVariationStyle();
CNG variation = amplitude > 0.0D && style != null
? style.create(baseSeed ^ 0xED6E7A9E5L, runtime)
: null;
return new FloatingIslandEdgeProfile(width, getEdgeTaperExponent(), amplitude, variation);
}
public CNG getAltitudeCng(long baseSeed, IrisData data) {
return getAltitudeStyle().create(baseSeed ^ 0xA17DEBBL, PackRuntime.forContext(data));
public CNG getPickerCng(long baseSeed, PackRuntime runtime) {
return getPickerStyle().create(baseSeed ^ 0x91C4E72DL, runtime);
}
public CNG getTopShapeCng(long baseSeed, IrisData data) {
return getTopShapeStyle().create(baseSeed ^ 0x70970601DEFL, PackRuntime.forContext(data));
public CNG getAltitudeCng(long baseSeed, PackRuntime runtime) {
return getAltitudeStyle().create(baseSeed ^ 0xA17DEBBL, runtime);
}
public CNG getBottomCng(long baseSeed, IrisData data) {
return getBottomStyle().create(baseSeed ^ 0xB0770075CAFEL, PackRuntime.forContext(data));
public CNG getTopShapeCng(long baseSeed, PackRuntime runtime) {
return getTopShapeStyle().create(baseSeed ^ 0x70970601DEFL, runtime);
}
public CNG getWallWarpCng(long baseSeed, IrisData data) {
public CNG getBottomCng(long baseSeed, PackRuntime runtime) {
return getBottomStyle().create(baseSeed ^ 0xB0770075CAFEL, runtime);
}
public CNG getWallWarpCng(long baseSeed, PackRuntime runtime) {
IrisGeneratorStyle style = getWallWarpStyle();
if (style == null) {
return null;
}
return style.create(baseSeed ^ 0xA117BA17E0FL, PackRuntime.forContext(data));
return style.create(baseSeed ^ 0xA117BA17E0FL, runtime);
}
public CNG getCarveCng(long baseSeed, IrisData data) {
public CNG getCarveCng(long baseSeed, PackRuntime runtime) {
IrisGeneratorStyle style = getCarveStyle();
if (style == null) {
return null;
}
return style.create(baseSeed ^ 0xCA5EC1EE5EL, PackRuntime.forContext(data));
return style.create(baseSeed ^ 0xCA5EC1EE5EL, runtime);
}
public IrisCaveProfileSampler getCarvingProfileSampler(Engine engine, IrisData data) {
public IrisCaveProfileSampler getCarvingProfileSampler(PackRuntime runtime) {
if (!hasCarvingReference()) {
return null;
}
return runtime.floatingChild(this).carvingProfileSampler();
}
CachedCarvingProfile recent = recentCarvingProfile;
if (recent != null && recent.key.matches(0L, data, engine)) {
return recent.sampler;
IrisCaveProfileSampler createCarvingProfileSampler(PackRuntime runtime) {
Engine engine = runtime.engine();
IrisBiome resolved = resolveCarvingBiome(carving, engine, runtime.data());
if (resolved == null || resolved.getCaveProfile() == null || !resolved.getCaveProfile().isEnabled()) {
return null;
}
RuntimeKey key = new RuntimeKey(0L, data, engine);
IrisCaveProfileSampler sampler = carvingProfileSamplers.computeIfAbsent(key, ignored -> {
IrisBiome resolved = resolveCarvingBiome(carving, engine, data);
if (resolved == null || resolved.getCaveProfile() == null || !resolved.getCaveProfile().isEnabled()) {
return null;
}
return new IrisCaveProfileSampler(engine, resolved.getCaveProfile());
});
recentCarvingProfile = new CachedCarvingProfile(key, sampler);
return sampler;
return new IrisCaveProfileSampler(engine, resolved.getCaveProfile());
}
public boolean hasCarvingReference() {
@@ -401,28 +372,4 @@ public class IrisFloatingChildBiomes implements Rarity {
return loaded;
});
}
private record RuntimeKey(long seed, IrisData data, Engine engine) {
private boolean matches(long seed, IrisData data, Engine engine) {
return this.seed == seed && this.data == data && this.engine == engine;
}
@Override
public boolean equals(Object object) {
return object instanceof RuntimeKey other && matches(other.seed, other.data, other.engine);
}
@Override
public int hashCode() {
int hash = Long.hashCode(seed);
hash = 31 * hash + System.identityHashCode(data);
return 31 * hash + System.identityHashCode(engine);
}
}
private record CachedEdgeProfile(RuntimeKey key, FloatingIslandEdgeProfile profile) {
}
private record CachedCarvingProfile(RuntimeKey key, IrisCaveProfileSampler sampler) {
}
}
@@ -0,0 +1,50 @@
/*
* 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.biome;
import art.arcane.iris.generation.runtime.PackRuntime;
import art.arcane.iris.generation.runtime.SeedTable;
import art.arcane.volmlib.util.noise.CNG;
/**
* What one engine derives from an {@link IrisBiomePaletteLayer}: the block selection and depth generators of the
* seeds that sample it.
*/
public final class PaletteLayerRuntime {
private static final int LAYER_SEED_CAPACITY = 32;
private static final int LAYER_RECENT_SLOTS = 32;
private static final int HEIGHT_SEED_CAPACITY = 32;
private final SeedTable<CNG> layerGenerators;
private final SeedTable<CNG> heightGenerators;
public PaletteLayerRuntime(IrisBiomePaletteLayer layer, PackRuntime runtime) {
this.layerGenerators = new SeedTable<>(LAYER_SEED_CAPACITY, LAYER_RECENT_SLOTS,
seed -> layer.createLayerGenerator(seed, runtime));
this.heightGenerators = new SeedTable<>(HEIGHT_SEED_CAPACITY, IrisBiomePaletteLayer::createHeightGenerator);
}
public CNG layerGenerator(long seed) {
return layerGenerators.get(seed);
}
public CNG heightGenerator(long seed) {
return heightGenerators.get(seed);
}
}
@@ -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.biome.IrisBiome;
@@ -79,7 +80,7 @@ final class IrisSugarCane {
}
IrisBiome biome = complex.getTrueBiomeStream().get(x, z);
KList<NativeBlockState> layers = biome.generateSeaLayers(x, z,
new RNG(engine.getSeedManager().getTerrain()), fluidHeight - terrainHeight, engine.getData());
new RNG(engine.getSeedManager().getTerrain()), fluidHeight - terrainHeight, PackRuntime.of(engine));
int depth = fluidHeight - y;
return supportsAdjacent(layers.hasIndex(depth) ? layers.get(depth) : complex.resolveSeaFluid(x, z));
}
@@ -18,6 +18,7 @@
package art.arcane.iris.generation.mantle;
import art.arcane.iris.generation.runtime.PackRuntime;
import art.arcane.iris.pack.loading.IrisData;
import art.arcane.iris.generation.cache.Cache;
import art.arcane.iris.generation.runtime.Engine;
@@ -32,6 +33,7 @@ import org.jetbrains.annotations.Nullable;
final class FloatingIslandSampleResolver implements IslandObjectPlacer.SampleProvider {
private final IrisData data;
private final Engine engine;
private final PackRuntime runtime;
private final int chunkHeight;
private final long baseSeed;
private final FloatingIslandBoundarySampler boundarySampler;
@@ -41,6 +43,7 @@ final class FloatingIslandSampleResolver implements IslandObjectPlacer.SamplePro
FloatingIslandSampleResolver(EngineMantle engineMantle, FloatingIslandBoundarySampler boundarySampler) {
this.data = engineMantle.getData();
this.engine = engineMantle.getEngine();
this.runtime = PackRuntime.of(engine, data);
this.chunkHeight = engine.getHeight();
this.baseSeed = engine.getSeedManager().getTerrain() ^ IrisFloatingChildBiomeModifier.FLOATING_BASE_SEED_SALT;
this.boundarySampler = boundarySampler;
@@ -48,6 +51,10 @@ final class FloatingIslandSampleResolver implements IslandObjectPlacer.SamplePro
this.resolvedSamples = new LongOpenHashSet();
}
PackRuntime runtime() {
return runtime;
}
@Override
public @Nullable FloatingIslandSample sample(int x, int z) {
long key = Cache.key(x, z);
@@ -59,7 +66,7 @@ final class FloatingIslandSampleResolver implements IslandObjectPlacer.SamplePro
resolvedSamples.add(key);
return null;
}
FloatingIslandSample sample = FloatingIslandSample.sample(parent, x, z, chunkHeight, baseSeed, data, engine, boundarySampler);
FloatingIslandSample sample = FloatingIslandSample.sample(parent, x, z, chunkHeight, baseSeed, runtime, boundarySampler);
resolvedSamples.add(key);
if (sample != null) {
sampleCache.put(key, sample);
@@ -76,7 +76,7 @@ public class MantleFloatingObjectComponent extends IrisMantleComponent {
RNG chunkRng = new RNG(Cache.key(x, z) + seed() + 0x0FA710BEL);
FloatingIslandSampleResolver sampleResolver = new FloatingIslandSampleResolver(getEngineMantle(), context.getFloatingIslandBoundarySampler());
FloatingIslandSample.clearChunkMemo();
FloatingIslandSample.clearChunkMemo(sampleResolver.runtime());
FloatingIslandSample[] samples = new FloatingIslandSample[256];
for (int xf = 0; xf < 16; xf++) {
@@ -278,7 +278,7 @@ public final class DimensionTerrainContext implements DataProvider {
: inferredStreams.get(InferredType.LAND).get(x, z);
})
.convertAware2D((biome, x, z) -> implode(
biome, x, z, rng, dataProvider, childSelectionPlans, 3))
biome, x, z, rng, dimensionRuntime, dataProvider, childSelectionPlans, 3))
: ProceduralStream.of(
(x, z) -> focusBiome,
Interpolated.of(value -> 0D, value -> focusBiome)
@@ -379,7 +379,7 @@ public final class DimensionTerrainContext implements DataProvider {
);
return resolvedBiome == baseBiome
? baseBiome
: implode(resolvedBiome, x, z, rng, dataProvider, childSelectionPlans, 3);
: implode(resolvedBiome, x, z, rng, dimensionRuntime, dataProvider, childSelectionPlans, 3);
}), cachePrefix + "ImageMappedFinalBiomeStream", engine, cacheSize)
: GenerationStreams.cache2D(ProceduralStream.of(
(x, z) -> focusBiome,
@@ -596,6 +596,7 @@ public final class DimensionTerrainContext implements DataProvider {
double x,
double z,
RNG rng,
PackRuntime runtime,
DataProvider dataProvider,
Map<IrisBiome, IrisComplex.ChildSelectionPlan> childSelectionPlans,
int remainingDepth
@@ -623,7 +624,7 @@ public final class DimensionTerrainContext implements DataProvider {
}
IrisBiome selected = selectionPlan.select(
biome.getChildrenGenerator(rng, 123, biome.getChildShrinkFactor()), x, z);
biome.getChildrenGenerator(runtime, rng, 123, biome.getChildShrinkFactor()), x, z);
if (selected == null) {
return biome;
}
@@ -632,6 +633,7 @@ public final class DimensionTerrainContext implements DataProvider {
x,
z,
rng,
runtime,
dataProvider,
childSelectionPlans,
remainingDepth - 1
@@ -2530,7 +2530,7 @@ public class IrisComplex implements DataProvider {
}
private IrisBiome pickChild(IrisBiome parent, double x, double z) {
CNG childCell = parent.getChildrenGenerator(childStyleSeed, parent.getChildShrinkFactor());
CNG childCell = parent.getChildrenGenerator(packRuntime, childStyleSeed, parent.getChildShrinkFactor());
return resolveChildSelectionPlan(parent).select(childCell, x, z).withInferredType(parent.getInferredType());
}
@@ -18,6 +18,13 @@
package art.arcane.iris.generation.runtime;
import art.arcane.iris.generation.biome.BiomeRuntime;
import art.arcane.iris.generation.biome.FloatingChildRuntime;
import art.arcane.iris.generation.biome.FloatingIslandMemo;
import art.arcane.iris.generation.biome.IrisBiome;
import art.arcane.iris.generation.biome.IrisBiomePaletteLayer;
import art.arcane.iris.generation.biome.IrisFloatingChildBiomes;
import art.arcane.iris.generation.biome.PaletteLayerRuntime;
import art.arcane.iris.generation.noise.ExpressionRuntime;
import art.arcane.iris.generation.noise.GeneratorRuntime;
import art.arcane.iris.generation.noise.IrisExpression;
@@ -49,6 +56,12 @@ public final class PackRuntime {
private final RuntimeTable<IrisGenerator, GeneratorRuntime> generators = new RuntimeTable<>(GeneratorRuntime::new);
private final RuntimeTable<IrisExpression, ExpressionRuntime> expressions =
new RuntimeTable<>(expression -> new ExpressionRuntime(expression, this));
private final RuntimeTable<IrisBiome, BiomeRuntime> biomes = new RuntimeTable<>(biome -> new BiomeRuntime(biome, this));
private final RuntimeTable<IrisBiomePaletteLayer, PaletteLayerRuntime> paletteLayers =
new RuntimeTable<>(layer -> new PaletteLayerRuntime(layer, this));
private final RuntimeTable<IrisFloatingChildBiomes, FloatingChildRuntime> floatingChildren =
new RuntimeTable<>(entry -> new FloatingChildRuntime(entry, this));
private final ThreadSlots<FloatingIslandMemo> floatingIslandMemos = new ThreadSlots<>(FloatingIslandMemo::new);
private PackRuntime(Engine engine, IrisData data) {
this.engine = engine;
@@ -78,6 +91,11 @@ public final class PackRuntime {
return engineRuntime.scopeFor(data);
}
/** The engine's scope for its own pack. */
public static PackRuntime of(Engine engine) {
return of(engine, engine.getData());
}
/**
* The scope for a pack object whose class still finds its engine through the pack data's context. Each use is a
* caller that has not been handed its runtime scope yet.
@@ -123,4 +141,21 @@ public final class PackRuntime {
public ExpressionRuntime expression(IrisExpression expression) {
return expressions.get(expression);
}
public BiomeRuntime biome(IrisBiome biome) {
return biomes.get(biome);
}
public PaletteLayerRuntime paletteLayer(IrisBiomePaletteLayer layer) {
return paletteLayers.get(layer);
}
public FloatingChildRuntime floatingChild(IrisFloatingChildBiomes entry) {
return floatingChildren.get(entry);
}
/** The calling worker's floating island samples for its current chunk. */
public FloatingIslandMemo floatingIslandMemo() {
return floatingIslandMemos.get();
}
}
@@ -20,30 +20,46 @@ package art.arcane.iris.generation.runtime;
import java.util.LinkedHashMap;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicReferenceArray;
import java.util.function.LongFunction;
/**
* The values one runtime object builds per seed, for pack objects that callers sample with seeds they derive
* themselves. Bounded by least-recent use; an evicted value is rebuilt from the same seed, so eviction never changes
* output. The most recent value is kept aside because callers usually ask for the same seed many times in a row.
* output. Recently used values are kept aside in seed-indexed slots because callers usually ask for the same few
* seeds many times in a row.
*/
public final class SeedTable<T> {
private static final int SINGLE_RECENT_SLOT = 1;
private final int capacity;
private final LongFunction<T> builder;
private final LinkedHashMap<Long, T> entries;
private volatile Recent<T> recent;
private final AtomicReferenceArray<Recent<T>> recent;
private final int recentMask;
public SeedTable(int capacity, LongFunction<T> builder) {
this(capacity, SINGLE_RECENT_SLOT, builder);
}
/** @param recentSlots a power of two: how many seeds stay on the lock-free path at once */
public SeedTable(int capacity, int recentSlots, LongFunction<T> builder) {
if (capacity < 1) {
throw new IllegalArgumentException("Seed table capacity must be positive.");
}
if (recentSlots < 1 || Integer.bitCount(recentSlots) != 1) {
throw new IllegalArgumentException("Recent seed slots must be a positive power of two.");
}
this.capacity = capacity;
this.builder = Objects.requireNonNull(builder, "seed builder");
this.entries = new LinkedHashMap<>(capacity * 2, 0.75F, true);
this.recent = new AtomicReferenceArray<>(recentSlots);
this.recentMask = recentSlots - 1;
}
public T get(long seed) {
Recent<T> last = recent;
int slot = (int) seed & recentMask;
Recent<T> last = recent.getAcquire(slot);
if (last != null && last.seed == seed) {
return last.value;
}
@@ -51,7 +67,7 @@ public final class SeedTable<T> {
if (value == null) {
value = publish(seed, Objects.requireNonNull(builder.apply(seed), "seeded runtime value"));
}
recent = new Recent<>(seed, value);
recent.setRelease(slot, new Recent<>(seed, value));
return value;
}
@@ -18,6 +18,7 @@
package art.arcane.iris.generation.stage;
import art.arcane.iris.generation.runtime.PackRuntime;
import art.arcane.iris.pack.loading.IrisData;
import art.arcane.iris.generation.subterrain.SubterrainCell;
import art.arcane.iris.generation.subterrain.SubterrainPlanner;
@@ -340,7 +341,7 @@ public class IrisCarveModifier extends EngineAssignedModifier<NativeBlockState>
int blockZ = chunkZ << 4;
return new SubterrainSurfaceMaterials(planner,
planner.plansForBounds(blockX - 1, blockZ - 1, blockX + 16, blockZ + 16),
getEngine().getDimension(), getComplex(), getData(), rng, getEngine().getWorld().minHeight());
getEngine().getDimension(), getComplex(), PackRuntime.of(getEngine()), rng, getEngine().getWorld().minHeight());
}
static boolean hasExplicitCarveIntent(MatterCavern cavern) {
@@ -637,7 +638,7 @@ public class IrisCarveModifier extends EngineAssignedModifier<NativeBlockState>
if (biome == null) {
return;
}
NativeBlockState wall = biome.getWall().get(rng, worldX, yy, worldZ, data);
NativeBlockState wall = biome.getWall().get(rng, worldX, yy, worldZ, inputs.runtime.scopeFor(data));
if (wall != null) {
output.setRaw(rx, yy, rz, wall);
}
@@ -1016,13 +1017,13 @@ public class IrisCarveModifier extends EngineAssignedModifier<NativeBlockState>
private KList<NativeBlockState> floorLayers(CaveLayerMemo layers, IrisBiome biome, int worldX, int worldZ, int floorY,
CaveInputs inputs) {
if (!hasHeightFreeFloorLayers(biome)) {
return biome.generateLayers(inputs.dimension, worldX, worldZ, rng, 3, floorY, inputs.data, inputs.complex);
return biome.generateLayers(inputs.dimension, worldX, worldZ, rng, 3, floorY, inputs.runtime, inputs.complex);
}
KList<NativeBlockState> remembered = layers.floor(biome);
if (remembered != null) {
return remembered;
}
KList<NativeBlockState> blocks = biome.generateLayers(inputs.dimension, worldX, worldZ, rng, 3, floorY, inputs.data, inputs.complex);
KList<NativeBlockState> blocks = biome.generateLayers(inputs.dimension, worldX, worldZ, rng, 3, floorY, inputs.runtime, inputs.complex);
layers.rememberFloor(biome, blocks);
return blocks;
}
@@ -1033,7 +1034,7 @@ public class IrisCarveModifier extends EngineAssignedModifier<NativeBlockState>
if (remembered != null) {
return remembered;
}
KList<NativeBlockState> blocks = biome.generateCeilingLayers(inputs.dimension, worldX, worldZ, rng, 3, ceilingY, inputs.data, inputs.complex);
KList<NativeBlockState> blocks = biome.generateCeilingLayers(inputs.dimension, worldX, worldZ, rng, 3, ceilingY, inputs.runtime, inputs.complex);
layers.rememberCeiling(biome, blocks);
return blocks;
}
@@ -1356,6 +1357,7 @@ public class IrisCarveModifier extends EngineAssignedModifier<NativeBlockState>
private final IrisComplex complex;
private final IrisDimension dimension;
private final IrisData data;
private final PackRuntime runtime;
private final int height;
private final IrisDimensionCarvingResolver.State state = new IrisDimensionCarvingResolver.State();
private final IrisDimensionCarvingResolver.Snapshot snapshot;
@@ -1393,6 +1395,7 @@ public class IrisCarveModifier extends EngineAssignedModifier<NativeBlockState>
complex = engine.getComplex();
dimension = engine.getDimension();
data = engine.getData();
runtime = PackRuntime.of(engine, data);
height = engine.getHeight();
cells = SubterrainChunkCells.of(engine, chunkX, chunkZ);
IrisContext context = IrisContext.get();
@@ -18,6 +18,7 @@
package art.arcane.iris.generation.stage;
import art.arcane.iris.generation.runtime.PackRuntime;
import art.arcane.iris.integration.Identifier;
import art.arcane.iris.pack.loading.IrisData;
import art.arcane.iris.generation.runtime.DimensionStackLayout;
@@ -191,6 +192,7 @@ public final class IrisDimensionStackActuator extends EngineAssignedActuator<Nat
DimensionTerrainContext terrainContext = layer.terrainContext();
IrisDimension dimension = terrainContext.getDimension();
IrisData data = terrainContext.getData();
PackRuntime runtime = PackRuntime.of(getEngine(), data);
IrisBiome biome = layer.biome();
int bedrockDepth = dimension.isBedrock() ? 1 : 0;
int surfaceDepth = Math.max(0, layer.normalTerrainHeight() + 1 - bedrockDepth);
@@ -204,7 +206,7 @@ public final class IrisDimensionStackActuator extends EngineAssignedActuator<Nat
rng,
surfaceDepth,
layer.normalTerrainHeight(),
data,
runtime,
terrainContext.getSlopeStream()
);
int paletteSurfaceY = layer.normalTerrainHeight();
@@ -212,7 +214,7 @@ public final class IrisDimensionStackActuator extends EngineAssignedActuator<Nat
int terrainSpan = layer.terrainColumn() == null ? -1 : layer.terrainColumn().spanCount() - 1;
KList<NativeBlockState> seaBlocks = biome == null || fluidDepth == 0
? null
: biome.generateSeaLayers(worldX, worldZ, rng, fluidDepth, data);
: biome.generateSeaLayers(worldX, worldZ, rng, fluidDepth, runtime);
for (int y = layer.renderMaxY(); y >= layer.renderMinY(); y--) {
int sourceY = y - layer.localBaseY();
@@ -256,7 +258,7 @@ public final class IrisDimensionStackActuator extends EngineAssignedActuator<Nat
if (terrainSpan > 0 && depth >= 2 && ceilingDepth < 2) {
if (ceilingBlocks == null && biome != null) {
ceilingBlocks = biome.generateCeilingLayers(dimension, worldX, worldZ, rng,
2, ceilingY, data, null);
2, ceilingY, runtime, null);
}
writeBlock(output, metadata, localX, y, localZ,
ceilingBlocks != null && ceilingBlocks.hasIndex(ceilingDepth)
@@ -266,7 +268,7 @@ public final class IrisDimensionStackActuator extends EngineAssignedActuator<Nat
}
if (surfaceBlocks == null && biome != null) {
surfaceBlocks = biome.generateLayersWithSlope(dimension, worldX, worldZ, rng,
sourceSurfaceY + 1 - bedrockDepth, sourceSurfaceY, data,
sourceSurfaceY + 1 - bedrockDepth, sourceSurfaceY, runtime,
terrainContext.getSurfaceSlopeStream(sourceSurfaceY));
}
writeBlock(output, metadata, localX, y, localZ,
@@ -19,6 +19,7 @@
package art.arcane.iris.generation.stage;
import art.arcane.iris.generation.runtime.PackRuntime;
import art.arcane.iris.pack.loading.IrisData;
import art.arcane.iris.generation.runtime.DimensionStackLayout;
import art.arcane.iris.generation.runtime.GenerationFailures;
@@ -64,14 +65,14 @@ public class IrisFloatingChildBiomeModifier extends EngineAssignedModifier<Nativ
private final RNG rng;
private final EngineDecorator seaSurfaceDecorator;
private static KList<NativeBlockState> generateBottomPaletteLayers(IrisFloatingChildBiomes entry, IrisDimension dimension, double wx, double wz, RNG random, int paletteDepth, IrisData data, IrisComplex complex) {
private static KList<NativeBlockState> generateBottomPaletteLayers(IrisFloatingChildBiomes entry, IrisDimension dimension, double wx, double wz, RNG random, int paletteDepth, PackRuntime runtime, IrisComplex complex) {
if (entry == null || entry.getBottomPaletteMode() != FloatingBottomPaletteMode.CUSTOM || entry.getBottomPalette() == null || entry.getBottomPalette().isEmpty()) {
return null;
}
return generatePaletteLayers(dimension, entry.getBottomPalette(), wx, wz, random.nextParallelRNG(0xB0770B), paletteDepth, data, complex);
return generatePaletteLayers(dimension, entry.getBottomPalette(), wx, wz, random.nextParallelRNG(0xB0770B), paletteDepth, runtime, complex);
}
private static KList<NativeBlockState> generatePaletteLayers(IrisDimension dimension, KList<IrisBiomePaletteLayer> layers, double wx, double wz, RNG random, int maxDepth, IrisData data, IrisComplex complex) {
private static KList<NativeBlockState> generatePaletteLayers(IrisDimension dimension, KList<IrisBiomePaletteLayer> layers, double wx, double wz, RNG random, int maxDepth, PackRuntime runtime, IrisComplex complex) {
KList<NativeBlockState> generated = new KList<>();
if (layers == null || layers.isEmpty() || maxDepth <= 0) {
return generated;
@@ -80,7 +81,7 @@ public class IrisFloatingChildBiomeModifier extends EngineAssignedModifier<Nativ
int generatorSeed = 7235;
for (int i = 0; i < layers.size(); i++) {
IrisBiomePaletteLayer layer = layers.get(i);
CNG heightGenerator = layer.getHeightGenerator(random.nextParallelRNG((generatorSeed++) * generatorSeed * generatorSeed * generatorSeed), data);
CNG heightGenerator = layer.getHeightGenerator(random.nextParallelRNG((generatorSeed++) * generatorSeed * generatorSeed * generatorSeed), runtime);
if (heightGenerator == null) {
continue;
}
@@ -101,7 +102,7 @@ public class IrisFloatingChildBiomeModifier extends EngineAssignedModifier<Nativ
}
try {
generated.add(layer.get(random.nextParallelRNG(i + j), (wx + j) / layer.getZoom(), j, (wz - j) / layer.getZoom(), data));
generated.add(layer.get(random.nextParallelRNG(i + j), (wx + j) / layer.getZoom(), j, (wz - j) / layer.getZoom(), runtime));
} catch (Throwable e) {
GenerationFailures.skipPlacement(e, "surface layer", "block", (int) wx, -1, (int) wz, "floating");
}
@@ -178,18 +179,18 @@ public class IrisFloatingChildBiomeModifier extends EngineAssignedModifier<Nativ
return block == null ? fallbackSolid : block;
}
private PaletteContext createPaletteContext(IrisBiome parent, IrisFloatingChildBiomes entry, IrisDimension dimension, int wx, int wz, int paletteDepth, int surfaceY, int baseY, IrisData data, IrisComplex complex) {
IrisBiome target = entry == null ? parent : entry.getRealBiome(parent, data);
private PaletteContext createPaletteContext(IrisBiome parent, IrisFloatingChildBiomes entry, IrisDimension dimension, int wx, int wz, int paletteDepth, int surfaceY, int baseY, PackRuntime runtime, IrisComplex complex) {
IrisBiome target = entry == null ? parent : entry.getRealBiome(parent, runtime.data());
RNG layerRng = paletteRng(rng, entry);
boolean physicalDepth = usesPhysicalDepth(target, entry);
int topPaletteDepth = physicalDepth ? Math.max(paletteDepth, surfaceY - baseY + 1) : paletteDepth;
KList<NativeBlockState> topBlocks = target == null ? null : target.generateLayers(dimension, wx, wz, layerRng, topPaletteDepth, surfaceY, data, complex);
KList<NativeBlockState> topBlocks = target == null ? null : target.generateLayers(dimension, wx, wz, layerRng, topPaletteDepth, surfaceY, runtime, complex);
if (topBlocks == null || topBlocks.isEmpty()) {
physicalDepth = usesPhysicalDepth(parent, entry);
topPaletteDepth = physicalDepth ? Math.max(paletteDepth, surfaceY - baseY + 1) : paletteDepth;
topBlocks = parent.generateLayers(dimension, wx, wz, layerRng, topPaletteDepth, surfaceY, data, complex);
topBlocks = parent.generateLayers(dimension, wx, wz, layerRng, topPaletteDepth, surfaceY, runtime, complex);
}
KList<NativeBlockState> bottomBlocks = generateBottomPaletteLayers(entry, dimension, wx, wz, layerRng, paletteDepth, data, complex);
KList<NativeBlockState> bottomBlocks = generateBottomPaletteLayers(entry, dimension, wx, wz, layerRng, paletteDepth, runtime, complex);
return new PaletteContext(topBlocks, bottomBlocks, B.getState("minecraft:stone"), surfaceY, physicalDepth);
}
@@ -230,11 +231,12 @@ public class IrisFloatingChildBiomeModifier extends EngineAssignedModifier<Nativ
PrecisionStopwatch p = PrecisionStopwatch.start();
int chunkHeight = output.getHeight();
IrisData data = getData();
PackRuntime runtime = PackRuntime.of(getEngine(), data);
IrisDimension dimension = getDimension();
IrisComplex complex = getComplex();
long baseSeed = getEngine().getSeedManager().getTerrain() ^ FLOATING_BASE_SEED_SALT;
FloatingIslandBoundarySampler boundarySampler = context.getFloatingIslandBoundarySampler();
FloatingIslandSample.clearChunkMemo();
FloatingIslandSample.clearChunkMemo(runtime);
for (int xf = 0; xf < 16; xf++) {
for (int zf = 0; zf < 16; zf++) {
@@ -244,7 +246,7 @@ public class IrisFloatingChildBiomeModifier extends EngineAssignedModifier<Nativ
if (parent == null || parent.getFloatingChildBiomes() == null || parent.getFloatingChildBiomes().isEmpty()) {
continue;
}
FloatingIslandSample sample = FloatingIslandSample.sampleMemoized(parent, wx, wz, chunkHeight, baseSeed, data, getEngine(), boundarySampler);
FloatingIslandSample sample = FloatingIslandSample.sampleMemoized(parent, wx, wz, chunkHeight, baseSeed, runtime, boundarySampler);
if (sample == null) {
continue;
}
@@ -265,7 +267,7 @@ public class IrisFloatingChildBiomeModifier extends EngineAssignedModifier<Nativ
IrisFloatingChildBiomes entry = sample.entryAt(k);
PaletteContext paletteContext = paletteContexts.get(entry);
if (paletteContext == null) {
paletteContext = createPaletteContext(parent, entry, dimension, wx, wz, paletteDepth, y, sample.islandBaseY, data, complex);
paletteContext = createPaletteContext(parent, entry, dimension, wx, wz, paletteDepth, y, sample.islandBaseY, runtime, complex);
paletteContexts.put(entry, paletteContext);
}
int depth = topDepthByEntry.getOrDefault(entry, 0);
@@ -327,6 +329,7 @@ public class IrisFloatingChildBiomeModifier extends EngineAssignedModifier<Nativ
public void decorateColumns(int x, int z, Hunk<NativeBlockState> output, boolean multicore, ChunkContext context) {
int chunkHeight = output.getHeight();
IrisData data = getData();
PackRuntime runtime = PackRuntime.of(getEngine(), data);
IrisComplex complex = getComplex();
long baseSeed = getEngine().getSeedManager().getTerrain() ^ FLOATING_BASE_SEED_SALT;
FloatingIslandBoundarySampler boundarySampler = context.getFloatingIslandBoundarySampler();
@@ -342,7 +345,7 @@ public class IrisFloatingChildBiomeModifier extends EngineAssignedModifier<Nativ
if (parent == null || parent.getFloatingChildBiomes() == null || parent.getFloatingChildBiomes().isEmpty()) {
continue;
}
FloatingIslandSample sample = FloatingIslandSample.sampleMemoized(parent, wx, wz, chunkHeight, baseSeed, data, getEngine(), boundarySampler);
FloatingIslandSample sample = FloatingIslandSample.sampleMemoized(parent, wx, wz, chunkHeight, baseSeed, runtime, boundarySampler);
if (sample == null) {
continue;
}
@@ -212,7 +212,7 @@ public class IrisPostModifier extends EngineAssignedModifier<NativeBlockState> {
int max = Math.abs(Math.max(h - ha, Math.max(h - hb, Math.max(h - hc, h - hd))));
for (int i = h; i > h - max; i--) {
NativeBlockState d = biome.getWall().get(rng, x + i, i + h, z + i, getData());
NativeBlockState d = biome.getWall().get(rng, x + i, i + h, z + i, getComplex().getPackRuntime());
if (d != null) {
if (isAirOrWater(x, i, z, originX, originZ, currentData)) {
@@ -241,7 +241,7 @@ public class IrisPostModifier extends EngineAssignedModifier<NativeBlockState> {
//@done
{
IrisSlopeClip sc = biome.getSlab().getSlopeCondition();
NativeBlockState d = sc.isValid(getComplex().getSlopeStream().get(x, z)) ? biome.getSlab().get(rng, x, h, z, getData()) : null;
NativeBlockState d = sc.isValid(getComplex().getSlopeStream().get(x, z)) ? biome.getSlab().get(rng, x, h, z, getComplex().getPackRuntime()) : null;
if (d != null) {
boolean cancel = B.isAir(d);
@@ -18,6 +18,7 @@
package art.arcane.iris.generation.stage;
import art.arcane.iris.generation.runtime.PackRuntime;
import art.arcane.iris.generation.runtime.Engine;
import art.arcane.iris.generation.runtime.EngineAssignedActuator;
import art.arcane.iris.pack.loading.IrisData;
@@ -143,6 +144,7 @@ public class IrisTerrainNormalActuator extends EngineAssignedActuator<NativeBloc
private final int chunkHeight;
private final IrisDimension dimension;
private final IrisData data;
private final PackRuntime runtime;
private final Engine oreEngine;
private final IrisComplex complex;
private final ProceduralStream<Double> waterHeadStream;
@@ -181,6 +183,7 @@ public class IrisTerrainNormalActuator extends EngineAssignedActuator<NativeBloc
chunkHeight = h.getHeight();
dimension = getDimension();
data = getData();
runtime = PackRuntime.of(getEngine(), data);
oreEngine = data == null ? null : data.getEngine();
complex = getComplex();
waterHeadStream = complex.getWaterHeadStream();
@@ -278,7 +281,7 @@ public class IrisTerrainNormalActuator extends EngineAssignedActuator<NativeBloc
if (i > he && i <= hf) {
int fdepth = hf - i;
if (seaFloor && fblocks == null) {
fblocks = biome.generateSeaLayers(realX, realZ, rng, role == WaterRole.INLET ? INLET_SEA_LAYERS : hf - he, data);
fblocks = biome.generateSeaLayers(realX, realZ, rng, role == WaterRole.INLET ? INLET_SEA_LAYERS : hf - he, runtime);
}
put(i, HydrologyFluidLayerSelector.select(
fblocks,
@@ -297,7 +300,7 @@ public class IrisTerrainNormalActuator extends EngineAssignedActuator<NativeBloc
}
if (blocks == null) {
blocks = biome.generateLayers(dimension, realX, realZ, rng,
layerSurfaceY + 1 - bedrockFloor, layerSurfaceY, data, complex);
layerSurfaceY + 1 - bedrockFloor, layerSurfaceY, runtime, complex);
}
int deepFloor = Math.max(bedrockFloor, layerCeilingY > 0 ? layerCeilingY + 2 : 0);
@@ -310,7 +313,7 @@ public class IrisTerrainNormalActuator extends EngineAssignedActuator<NativeBloc
if (layerCeilingY > 0 && depth >= 2 && i - layerCeilingY < 2) {
if (ceilingBlocks == null) {
ceilingBlocks = biome.generateCeilingLayers(dimension, realX, realZ, rng,
2, layerCeilingY, data, complex);
2, layerCeilingY, runtime, complex);
}
int ceilingDepth = i - layerCeilingY;
put(i, ceilingBlocks.hasIndex(ceilingDepth)
@@ -495,7 +498,7 @@ public class IrisTerrainNormalActuator extends EngineAssignedActuator<NativeBloc
if (upperBlocks == null && upperBiome != null) {
upperBlocks = upperBiome.generateLayersWithSlope(upperContext.getDimension(),
realX, realZ, rng, sourceSurfaceY + 1 - (bedrockEnabled ? 1 : 0), sourceSurfaceY,
upperContext.getData(), upperContext.getSurfaceSlopeStream(sourceSurfaceY));
runtime.scopeFor(upperContext.getData()), upperContext.getSurfaceSlopeStream(sourceSurfaceY));
}
if (upperBlocks != null && upperBlocks.hasIndex(depthFromFace)) {
put(y, upperBlocks.get(depthFromFace));
@@ -1,5 +1,6 @@
package art.arcane.iris.generation.subterrain;
import art.arcane.iris.generation.runtime.PackRuntime;
import art.arcane.iris.generation.biome.IrisBiome;
import art.arcane.iris.generation.decoration.IrisDecorationPart;
import art.arcane.iris.generation.decoration.IrisDecorator;
@@ -22,19 +23,21 @@ public final class SubterrainSurfaceMaterials {
private final IrisDimension dimension;
private final IrisComplex complex;
private final IrisData data;
private final PackRuntime runtime;
private final RNG random;
private final int minimumY;
private final Map<String, IrisBiome> biomes = new HashMap<>();
private final Map<String, Set<String>> floorSupports = new HashMap<>();
public SubterrainSurfaceMaterials(SubterrainPlanner planner, List<SubterrainPlan> plans,
IrisDimension dimension, IrisComplex complex, IrisData data,
IrisDimension dimension, IrisComplex complex, PackRuntime runtime,
RNG random, int minimumY) {
this.planner = planner;
this.plans = plans;
this.dimension = dimension;
this.complex = complex;
this.data = data;
this.runtime = runtime;
this.data = runtime.data();
this.random = random;
this.minimumY = minimumY;
}
@@ -54,11 +57,11 @@ public final class SubterrainSurfaceMaterials {
}
NativeBlockState candidate;
if (surface == Surface.WALL) {
candidate = biome.getWall().get(random, x, worldY - minimumY, z, data);
candidate = biome.getWall().get(random, x, worldY - minimumY, z, runtime);
} else {
KList<NativeBlockState> layers = surface == Surface.FLOOR
? biome.generateLayers(dimension, x, z, random, 1, worldY + 1 - minimumY, data, complex)
: biome.generateCeilingLayers(dimension, x, z, random, 1, worldY - 1 - minimumY, data, complex);
? biome.generateLayers(dimension, x, z, random, 1, worldY + 1 - minimumY, runtime, complex)
: biome.generateCeilingLayers(dimension, x, z, random, 1, worldY - 1 - minimumY, runtime, complex);
candidate = layers.isEmpty() ? null : layers.getFirst();
}
return SubterrainRasterizer.isRetainedSolid(candidate) ? candidate : fallback;
@@ -1,5 +1,6 @@
package art.arcane.iris.pack.datapack.export.compile.subterrain;
import art.arcane.iris.generation.runtime.PackRuntime;
import art.arcane.iris.generation.biome.IrisBiome;
import art.arcane.iris.generation.subterrain.IrisSubterrainFeature;
import art.arcane.iris.generation.subterrain.SubterrainBounds;
@@ -47,6 +48,7 @@ public final class SubterrainBaker {
private final long seed;
private final IrisData data;
private final PackRuntime runtime;
private final IrisDimension dimension;
private final BlockStateResolver blocks;
private final List<ExportDiagnostic> diagnostics;
@@ -57,6 +59,7 @@ public final class SubterrainBaker {
public SubterrainBaker(PackCompileContext context, long seed) {
this.seed = seed;
data = context.data();
runtime = data.standalonePackRuntime();
dimension = context.dimension();
blocks = BlockStateResolver.forContext(context);
diagnostics = context.diagnostics();
@@ -135,9 +138,9 @@ public final class SubterrainBaker {
}
int height = y - dimension.getMinHeight();
NativeBlockState candidate = switch (surface) {
case WALL -> biome.getWall().get(random, x, height, z, data);
case FLOOR -> first(biome.generateLayersWithSlope(dimension, x, z, random, 1, height + 1, data, FLAT_SLOPE));
case CEILING -> first(biome.generateCeilingLayers(dimension, x, z, random, 1, height - 1, data, null));
case WALL -> biome.getWall().get(random, x, height, z, runtime);
case FLOOR -> first(biome.generateLayersWithSlope(dimension, x, z, random, 1, height + 1, runtime, FLAT_SLOPE));
case CEILING -> first(biome.generateCeilingLayers(dimension, x, z, random, 1, height - 1, runtime, null));
case INTERIOR -> null;
};
return SubterrainRasterizer.isRetainedSolid(candidate) ? candidate : null;
@@ -171,7 +174,7 @@ public final class SubterrainBaker {
this.random = random;
this.resource = resource;
plans = List.of(plan);
surfaces = new SubterrainSurfaceMaterials(planner, plans, dimension, null, data, random, dimension.getMinHeight());
surfaces = new SubterrainSurfaceMaterials(planner, plans, dimension, null, runtime, random, dimension.getMinHeight());
}
private BakedRoom room() {
@@ -1,5 +1,6 @@
package art.arcane.iris.structure.placement;
import art.arcane.iris.generation.runtime.PackRuntime;
import art.arcane.iris.generation.biome.IrisBiome;
import art.arcane.iris.generation.decoration.IrisOreBands;
import art.arcane.iris.generation.runtime.Engine;
@@ -25,6 +26,7 @@ public final class IrisStructureStrata implements StructureStrata {
private final IrisComplex complex;
private final IrisDimension dimension;
private final IrisData data;
private final PackRuntime runtime;
private final RNG rng;
private final int offsetY;
private final int bedrockFloor;
@@ -34,6 +36,7 @@ public final class IrisStructureStrata implements StructureStrata {
complex = Objects.requireNonNull(engine.getComplex(), "Structure strata require a terrain complex");
dimension = engine.getDimension();
data = engine.getData();
runtime = PackRuntime.of(engine, data);
rng = new RNG(engine.getSeedManager().getTerrain());
offsetY = engine.getMinHeight();
bedrockFloor = dimension.isBedrock() ? 1 : 0;
@@ -57,7 +60,7 @@ public final class IrisStructureStrata implements StructureStrata {
}
int surface = surfaceY - offsetY;
KList<NativeBlockState> layers = biome.generateLayersWithSlope(dimension, x, z, rng,
surface + 1 - bedrockFloor, surface, data, FLAT_GROUND);
surface + 1 - bedrockFloor, surface, runtime, FLAT_GROUND);
return new StrataColumn(x, z, surface, submerged, layers, mapped, rock, biome, region);
}
@@ -18,6 +18,7 @@
package art.arcane.iris.studio.map;
import art.arcane.iris.generation.runtime.PackRuntime;
import art.arcane.iris.pack.loading.IrisData;
import art.arcane.iris.generation.decoration.IrisDecorationPart;
import art.arcane.iris.generation.decoration.IrisEngineDecorator;
@@ -37,29 +38,31 @@ import art.arcane.volmlib.util.noise.CNG;
* passes use.
*/
abstract class BiomePalettePlacement {
protected final PackRuntime runtime;
protected final IrisData data;
private BiomePalettePlacement(IrisData data) {
this.data = data;
private BiomePalettePlacement(PackRuntime runtime) {
this.runtime = runtime;
this.data = runtime.data();
}
static BiomePalettePlacement of(Engine engine, IrisBiome biome, BiomePalette palette) {
IrisData data = engine.getData();
PackRuntime runtime = PackRuntime.of(engine);
RNG terrainRandom = new RNG(engine.getSeedManager().getTerrain());
RNG carveRandom = new RNG(engine.getSeedManager().getCarve());
RNG postRandom = new RNG(engine.getSeedManager().getPost());
int seaLevel = seaLevel(engine.getDimension());
int index = palette.index();
return switch (palette.kind()) {
case LAYER -> new StackedLayer(palette.layerIn(biome), index, biome.getLayerHeightGenerators(terrainRandom, data),
terrainRandom, data);
case SEA_LAYER -> new StackedLayer(palette.layerIn(biome), index, biome.getLayerSeaHeightGenerators(terrainRandom, data),
terrainRandom, data);
case LAYER -> new StackedLayer(palette.layerIn(biome), index, biome.getLayerHeightGenerators(terrainRandom, runtime),
terrainRandom, runtime);
case SEA_LAYER -> new StackedLayer(palette.layerIn(biome), index, biome.getLayerSeaHeightGenerators(terrainRandom, runtime),
terrainRandom, runtime);
case CAVE_CEILING_LAYER -> new StackedLayer(palette.layerIn(biome), index,
biome.getCaveCeilingLayerHeightGenerators(carveRandom, data), carveRandom, data);
case WALL -> new SingleBlocks(palette.layerIn(biome), data, carveRandom, seaLevel);
case SLAB -> new SingleBlocks(palette.layerIn(biome), data, postRandom, seaLevel);
case DECORATOR -> new Decorations(palette.decoratorIn(biome), engine.getSeedManager().getComponent(), seaLevel, data);
biome.getCaveCeilingLayerHeightGenerators(carveRandom, runtime), carveRandom, runtime);
case WALL -> new SingleBlocks(palette.layerIn(biome), runtime, carveRandom, seaLevel);
case SLAB -> new SingleBlocks(palette.layerIn(biome), runtime, postRandom, seaLevel);
case DECORATOR -> new Decorations(palette.decoratorIn(biome), engine.getSeedManager().getComponent(), seaLevel, runtime);
};
}
@@ -89,8 +92,8 @@ abstract class BiomePalettePlacement {
private abstract static class LayerPlacement extends BiomePalettePlacement {
protected final IrisBiomePaletteLayer layer;
private LayerPlacement(IrisBiomePaletteLayer layer, IrisData data) {
super(data);
private LayerPlacement(IrisBiomePaletteLayer layer, PackRuntime runtime) {
super(runtime);
this.layer = layer;
}
@@ -114,8 +117,8 @@ abstract class BiomePalettePlacement {
private final RNG random;
private final CNG thicknessNoise;
private StackedLayer(IrisBiomePaletteLayer layer, int index, KList<CNG> thicknessNoises, RNG random, IrisData data) {
super(layer, data);
private StackedLayer(IrisBiomePaletteLayer layer, int index, KList<CNG> thicknessNoises, RNG random, PackRuntime runtime) {
super(layer, runtime);
this.index = index;
this.random = random;
this.thicknessNoise = index < thicknessNoises.size() ? thicknessNoises.get(index) : null;
@@ -143,7 +146,7 @@ abstract class BiomePalettePlacement {
@Override
double noise(int blockX, int blockZ, int depth) {
double zoom = layer.getZoom();
return layer.getLayerGenerator(random, index + depth, data)
return layer.getLayerGenerator(random, index + depth, runtime)
.noise((blockX + depth) / zoom / zoom, depth / zoom, (blockZ - depth) / zoom / zoom);
}
}
@@ -155,8 +158,8 @@ abstract class BiomePalettePlacement {
private final RNG random;
private final int sampleHeight;
private SingleBlocks(IrisBiomePaletteLayer layer, IrisData data, RNG random, int sampleHeight) {
super(layer, data);
private SingleBlocks(IrisBiomePaletteLayer layer, PackRuntime runtime, RNG random, int sampleHeight) {
super(layer, runtime);
this.random = random;
this.sampleHeight = sampleHeight;
}
@@ -169,7 +172,7 @@ abstract class BiomePalettePlacement {
@Override
double noise(int blockX, int blockZ, int depth) {
double zoom = layer.getZoom();
return layer.getLayerGenerator(random, data).noise(blockX / zoom, sampleHeight / zoom, blockZ / zoom);
return layer.getLayerGenerator(random, runtime).noise(blockX / zoom, sampleHeight / zoom, blockZ / zoom);
}
}
@@ -185,8 +188,8 @@ abstract class BiomePalettePlacement {
private final boolean picksFromFlatNoise;
private final int sampleHeight;
private Decorations(IrisDecorator decorator, long componentSeed, int sampleHeight, IrisData data) {
super(data);
private Decorations(IrisDecorator decorator, long componentSeed, int sampleHeight, PackRuntime runtime) {
super(runtime);
this.decorator = decorator;
RNG partRandom = new RNG(IrisEngineDecorator.seedForPart(componentSeed, decorator.getPartOf()));
this.placementNoise = decorator.getGenerator(partRandom, data);
@@ -21,6 +21,7 @@ package art.arcane.iris.studio.map;
import art.arcane.iris.generation.biome.IrisBiome;
import art.arcane.iris.generation.biome.IrisBiomeCustom;
import art.arcane.iris.generation.runtime.Engine;
import art.arcane.volmlib.util.collection.KList;
import art.arcane.volmlib.util.math.RNG;
@@ -38,14 +39,16 @@ final class BiomeTintField {
private final IrisBiome biome;
private final RNG biomeRandom;
private final Engine engine;
private final MinecraftBiomeColors minecraftColors;
private final BiomeTintColors sameColorsEverywhere;
private final Map<IrisBiomeCustom, BiomeTintColors> colorsByCustomBiome = new ConcurrentHashMap<>();
private final BlendedTint[] blendedTintCache = new BlendedTint[BLENDED_TINT_CACHE_SIZE];
private final ChunkColors[] chunkColorsCache = new ChunkColors[CHUNK_COLORS_CACHE_SIZE];
BiomeTintField(IrisBiome biome, RNG biomeRandom, MinecraftBiomeColors minecraftColors) {
BiomeTintField(IrisBiome biome, Engine engine, RNG biomeRandom, MinecraftBiomeColors minecraftColors) {
this.biome = biome;
this.engine = engine;
this.biomeRandom = biomeRandom;
this.minecraftColors = minecraftColors;
BiomeTintColors onlyColors = onlyPossibleColors();
@@ -95,9 +98,9 @@ final class BiomeTintField {
private BiomeTintColors colorsForChunkAt(int originX, int originZ) {
if (biome.isCustom()) {
return customColors(biome.getCustomBiome(biomeRandom, originX, 0, originZ));
return customColors(biome.getCustomBiome(biomeRandom, engine, originX, 0, originZ));
}
return vanillaColors(biome.getSkyBiomeKey(biomeRandom, originX, 0, originZ));
return vanillaColors(biome.getSkyBiomeKey(biomeRandom, engine, originX, 0, originZ));
}
// Follows the same choices as IrisBiome#getSkyBiomeKey and #getCustomBiome, returning null when chunks can differ.
@@ -98,7 +98,7 @@ final class PaletteLayerPreview {
BiomePalettePlacement placement = BiomePalettePlacement.of(engine, biome, palette);
BiomeTintField biomeTints = textures == null
? null
: new BiomeTintField(biome, new RNG(engine.getSeedManager().getBiome()), textures.biomeColors());
: new BiomeTintField(biome, engine, new RNG(engine.getSeedManager().getBiome()), textures.biomeColors());
PaletteLayerPreview ground = palette.kind() == BiomePalette.Kind.DECORATOR
? groundUnder(engine, palette.biomeKey(), biome, data, textures, biomeTints)
: null;
@@ -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());
@@ -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));
@@ -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
@@ -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() {
@@ -26,13 +26,13 @@ public class IrisBiomeFieldSeedCohesionTest {
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)
@@ -66,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)
};
}
@@ -1,7 +1,7 @@
package art.arcane.iris.generation.biome;
import art.arcane.iris.testsupport.MockPackData;
import art.arcane.iris.pack.loading.IrisData;
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;
@@ -12,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;
@@ -27,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);
@@ -76,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 {
@@ -99,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 = MockPackData.create();
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;
}
@@ -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);
@@ -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,14 @@ 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);
when(grass.get(rng, 0, 12D, 0D, -8D, data.standalonePackRuntime())).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 +86,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 +108,14 @@ 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);
when(paletteLayer.get(rng, 0, 12D, 0D, -8D, data.standalonePackRuntime())).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,8 @@ 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());
verify(layer, times(7)).get(same(rng), anyInt(), anyDouble(), anyDouble(), anyDouble(), same(RUNTIME));
}
@Test
@@ -129,8 +132,8 @@ 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());
verify(layer, times(3)).get(same(rng), anyInt(), anyDouble(), anyDouble(), anyDouble(), same(RUNTIME));
}
@Test
@@ -144,7 +147,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 +157,8 @@ 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());
doThrow(failure).when(layer).get(same(rng), anyInt(), anyDouble(), anyDouble(), anyDouble(), same(RUNTIME));
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 +172,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 +181,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()) {
@@ -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), any())).thenAnswer(invocation -> {
when(style.createNoCache(any(RNG.class), any())).thenAnswer(invocation -> {
RNG rng = invocation.getArgument(0);
return generators.get(rng.getSeed());
});
@@ -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,16 @@ 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);
when(layer.get(rng, 0, 12D, 0D, -8D, data.standalonePackRuntime())).thenReturn(surfaceBlock);
when(layer.get(rng, 1, 13D, 1D, -9D, data.standalonePackRuntime())).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 +127,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());
}
@@ -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.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;
@@ -171,7 +172,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 +195,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<>()));
@@ -226,10 +227,10 @@ public class IrisCarveWallPaletteScopeTest {
IrisBiomePaletteLayer palette = mock(IrisBiomePaletteLayer.class);
doReturn(palette).when(biome).getWall();
doAnswer(call -> {
assertSame(expectedData, call.getArgument(4));
assertSame(expectedData, call.<PackRuntime>getArgument(4).data());
paletteCalls.incrementAndGet();
return wall;
}).when(palette).get(any(RNG.class), anyDouble(), anyDouble(), anyDouble(), any(IrisData.class));
}).when(palette).get(any(RNG.class), anyDouble(), anyDouble(), anyDouble(), any(PackRuntime.class));
for (IrisComplex complex : new IrisComplex[]{activeComplex, detachedComplex, assemblyComplex}) {
doReturn(ProceduralStream.of((x, z) -> biome, Interpolated.of(value -> 0D, value -> null)))
.when(complex).getTrueBiomeStream();
@@ -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;
}
}
@@ -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);
@@ -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.runtimeOf(data)))
.thenAnswer(call -> block((int) call.getArgument(1)));
return layer;
}
@@ -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);
@@ -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() {
@@ -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);
@@ -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) {
@@ -1,5 +1,6 @@
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;
@@ -38,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;
@@ -262,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);
@@ -336,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) {
@@ -86,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;
}
@@ -196,21 +196,6 @@ public class PackRuntimeStateGateTest {
);
private static final List<Entry> PENDING_MIGRATION = List.of(
pending("art.arcane.iris.generation.biome.IrisBiome", "biomeGenerators", Kind.RUNTIME),
pending("art.arcane.iris.generation.biome.IrisBiome", "childrenGenerators", Kind.RUNTIME),
pending("art.arcane.iris.generation.biome.IrisBiome", "layerCeilingHeightGenerators", Kind.RUNTIME),
pending("art.arcane.iris.generation.biome.IrisBiome", "layerHeightGenerators", Kind.RUNTIME),
pending("art.arcane.iris.generation.biome.IrisBiome", "layerSeaHeightGenerators", Kind.RUNTIME),
pending("art.arcane.iris.generation.biome.IrisBiome", "recentBiomeGenerator", Kind.RUNTIME),
pending("art.arcane.iris.generation.biome.IrisBiome", "recentChildGenerator", Kind.RUNTIME),
pending("art.arcane.iris.generation.biome.IrisBiomePaletteLayer", "heightGenerators", Kind.RUNTIME),
pending("art.arcane.iris.generation.biome.IrisBiomePaletteLayer", "layerGenerators", Kind.RUNTIME),
pending("art.arcane.iris.generation.biome.IrisBiomePaletteLayer", "recentHeightGenerator", Kind.RUNTIME),
pending("art.arcane.iris.generation.biome.IrisBiomePaletteLayer", "recentLayerGenerators", Kind.RUNTIME),
pending("art.arcane.iris.generation.biome.IrisFloatingChildBiomes", "carvingProfileSamplers", Kind.RUNTIME),
pending("art.arcane.iris.generation.biome.IrisFloatingChildBiomes", "edgeTaperProfiles", Kind.RUNTIME),
pending("art.arcane.iris.generation.biome.IrisFloatingChildBiomes", "recentCarvingProfile", Kind.RUNTIME),
pending("art.arcane.iris.generation.biome.IrisFloatingChildBiomes", "recentEdgeProfile", Kind.RUNTIME),
pending("art.arcane.iris.generation.decoration.IrisDecorator", "generators", Kind.RUNTIME),
pending("art.arcane.iris.generation.decoration.IrisDecorator", "recentGenerators", Kind.RUNTIME),
pending("art.arcane.iris.generation.decoration.IrisDepositGenerator", "objects", Kind.RUNTIME),
@@ -230,8 +215,6 @@ public class PackRuntimeStateGateTest {
pending("art.arcane.iris.structure.object.IrisObjectReplace", "replaceGen", Kind.RUNTIME),
pending("art.arcane.iris.world.entity.IrisEffect", "latch", Kind.RUNTIME),
pending("art.arcane.iris.generation.bake.ChunkBakeCache", "recent", Kind.THREAD),
pending("art.arcane.iris.generation.biome.FloatingIslandSample", "CHUNK_MEMO", Kind.THREAD),
pending("art.arcane.iris.generation.biome.FloatingIslandSample", "FOOTPRINT_MEMO", Kind.THREAD),
pending("art.arcane.iris.generation.hydrology.engine.HydrologyRuntime", "last", Kind.THREAD),
pending("art.arcane.iris.generation.mantle.IrisCaveCarver3D", "scratchCache", Kind.THREAD),
pending("art.arcane.iris.generation.mantle.MantleWriter", "objectPlacementCapture", Kind.THREAD),
@@ -255,16 +238,11 @@ public class PackRuntimeStateGateTest {
pending("art.arcane.iris.world.history.TransitionBandIndex", "lastRegion", Kind.THREAD),
pending("art.arcane.iris.world.history.TransitionBoundarySampler", "cache", Kind.THREAD),
pending("art.arcane.iris.world.history.TransitionDisplacementField", "local", Kind.THREAD),
pending("art.arcane.iris.generation.biome.IrisBiome$ChildGeneratorKey", "engine", Kind.RUNTIME),
pending("art.arcane.iris.generation.biome.IrisBiomePaletteLayer$LayerGeneratorKey", "engine", Kind.RUNTIME),
pending("art.arcane.iris.generation.biome.IrisFloatingChildBiomes$RuntimeKey", "engine", Kind.RUNTIME),
pending("art.arcane.iris.generation.decoration.IrisDecorator$GeneratorKey", "engine", Kind.RUNTIME),
pending("art.arcane.iris.generation.decoration.IrisOreGenerator$ChanceKey", "engine", Kind.RUNTIME),
pending("art.arcane.iris.generation.terrain.IrisMaterialPalette$LayerGeneratorKey", "engine", Kind.RUNTIME),
pending("art.arcane.iris.structure.object.IrisObjectPlacement$SurfaceWarpCacheKey", "engine", Kind.RUNTIME),
pending("art.arcane.iris.generation.bake.ChunkBakeCache", "SPARSE", Kind.SCRATCH),
pending("art.arcane.iris.generation.biome.FloatingIslandSample", "LAST_DENSITY", Kind.SCRATCH),
pending("art.arcane.iris.generation.biome.FloatingIslandSample", "LAST_REJECT", Kind.SCRATCH),
pending("art.arcane.iris.generation.context.IrisContext", "OVERFLOW", Kind.SCRATCH),
pending("art.arcane.iris.generation.decoration.DecoratorCore", "SCRATCH_OPTS", Kind.SCRATCH),
pending("art.arcane.iris.generation.decoration.IrisDepositGenerator", "FOOTPRINT_CELLS", Kind.SCRATCH),
@@ -444,6 +422,8 @@ public class PackRuntimeStateGateTest {
);
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.runtime.EnginePanic$Diagnostics", "current", Kind.UNRELATED, "panic diagnostics strings for crash reports"),
holder("art.arcane.iris.pack.IrisPackBenchmarking", "instance", Kind.UNRELATED, "benchmark command session")
@@ -1,5 +1,7 @@
package art.arcane.iris.structure.placement;
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.decoration.IrisOreBands;
import art.arcane.iris.generation.image.IrisImageMapRuntime;
@@ -23,6 +25,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;
@@ -46,7 +49,7 @@ public class IrisStructureStrataTest {
private final IrisComplex complex = mock(IrisComplex.class);
private final IrisBiome biome = mock(IrisBiome.class);
private final IrisImageMapRuntime imageMap = mock(IrisImageMapRuntime.class);
private final IrisData data = mock(IrisData.class);
private final IrisData data = MockPackData.create();
private final IrisDimension dimension = new IrisDimension().setBedrock(true).setHideOresForHiddenOre(true);
@Before
@@ -62,7 +65,7 @@ public class IrisStructureStrataTest {
when(complex.getRockStream()).thenReturn(ProceduralStream.of((x, z) -> rock, Interpolated.of(value -> 0D, value -> rock)));
when(complex.getImageMapRuntime()).thenReturn(imageMap);
when(biome.generateLayersWithSlope(eq(dimension), anyDouble(), anyDouble(), any(RNG.class),
anyInt(), anyInt(), eq(data), any())).thenReturn(new KList<>(List.of(grass, dirt, dirt)));
anyInt(), anyInt(), MockPackData.runtimeOf(data), any())).thenReturn(new KList<>(List.of(grass, dirt, dirt)));
}
@Test
@@ -82,7 +85,7 @@ public class IrisStructureStrataTest {
IrisStructureStrata.world(engine).column(3, 5, 90, false);
verify(biome).generateLayersWithSlope(eq(dimension), eq(3D), eq(5D), any(RNG.class),
eq(90 - MIN_HEIGHT), eq(90 - MIN_HEIGHT), eq(data), any());
eq(90 - MIN_HEIGHT), eq(90 - MIN_HEIGHT), MockPackData.runtimeOf(data), any());
}
@Test
@@ -3,6 +3,7 @@ package art.arcane.iris.testsupport;
import art.arcane.iris.generation.runtime.PackRuntime;
import art.arcane.iris.pack.loading.IrisData;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.withSettings;
@@ -22,6 +23,11 @@ public final class MockPackData {
return withStandaloneRuntime(mock(IrisData.class, withSettings().stubOnly()));
}
/** Matches a runtime scope of this pack data, without touching the data mock while stubbing. */
public static PackRuntime runtimeOf(IrisData data) {
return argThat(runtime -> runtime != null && runtime.data() == data);
}
private static IrisData withStandaloneRuntime(IrisData data) {
doReturn(PackRuntime.standalone(data)).when(data).standalonePackRuntime();
return data;