mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 16:25:36 +00:00
Defer the listed cave export
The exported world has no Iris caves and says so, the aquifer keeps open water
This commit is contained in:
1 parent
71cac65f91
commit
3922c8f57f
20 files changed
+153
-2304
No files matched your search
+30
-58
@@ -6,13 +6,14 @@ import art.arcane.iris.pack.datapack.export.WorldgenExportMode;
|
||||
import art.arcane.iris.pack.datapack.export.WorldgenExportProgress;
|
||||
import art.arcane.iris.pack.datapack.export.WorldgenExportRequest;
|
||||
import art.arcane.iris.pack.datapack.export.WorldgenExportResult;
|
||||
import art.arcane.iris.pack.datapack.export.ir.ExportDiagnostic;
|
||||
import art.arcane.iris.pack.datapack.export.ir.ExportLimit;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.chunk.ProtoChunk;
|
||||
import net.minecraft.world.level.levelgen.densityfunction.DensityFunction;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
@@ -23,11 +24,12 @@ import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/** Listed caves are not exported yet: the exported world has no Iris caves, and the export says so. */
|
||||
public final class WorldgenExportDeepCaves263Test {
|
||||
@ClassRule
|
||||
public static final PaperRegistryIsolation registryIsolation = new PaperRegistryIsolation();
|
||||
@@ -36,35 +38,21 @@ public final class WorldgenExportDeepCaves263Test {
|
||||
private static final String NAMESPACE = WorldgenExportRequest.DEFAULT_NAMESPACE;
|
||||
private static final String DIMENSION_ID = NAMESPACE + ":" + ExportTestPacks.DIMENSION;
|
||||
private static final int MIN_Y = -64;
|
||||
private static final int LAVA_Y = -62;
|
||||
private static final int LAVA_LINE = -54;
|
||||
private static final int CAVE_TOP = -14;
|
||||
private static final int DEEP_Y = -14;
|
||||
private static final int CHUNK_WIDTH = 16;
|
||||
private static final String CAVE_FIELD = "cave/field";
|
||||
private static final String DIMENSION = """
|
||||
{
|
||||
"regions": ["region"],
|
||||
"dimensionHeight": {"min": -64, "max": 192},
|
||||
"fluidHeight": 63,
|
||||
"caveLavaHeight": 2,
|
||||
"caveProfile": {
|
||||
"enabled": true,
|
||||
"verticalRange": {"min": 0, "max": 50},
|
||||
"verticalEdgeFade": 0,
|
||||
"baseDensityStyle": {"style": "SIMPLEX", "zoom": 0.6},
|
||||
"detailDensityStyle": {"style": "SIMPLEX", "zoom": 0.3},
|
||||
"baseWeight": 1.0,
|
||||
"detailWeight": 0.0,
|
||||
"densityThreshold": {"min": 5.0, "max": 5.0, "style": {"style": "SIMPLEX"}},
|
||||
"thresholdBias": 0.0,
|
||||
"surfaceClearance": 0,
|
||||
"allowSurfaceBreak": false,
|
||||
"allowFluid": false,
|
||||
"allowLava": true,
|
||||
"modules": []
|
||||
}
|
||||
"caves": ["tunnels"]
|
||||
}
|
||||
""";
|
||||
private static final String TUNNELS = """
|
||||
{"tunnel": {"width": {"min": 5, "max": 8}, "spacing": {"horizontal": 32, "vertical": 24}},
|
||||
"depth": {"min": -60, "max": 0}, "surfaceClearance": 0, "allowLava": true}
|
||||
""";
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
@@ -73,53 +61,42 @@ public final class WorldgenExportDeepCaves263Test {
|
||||
public ExportTestPacks.BoundPlatform platform = new ExportTestPacks.BoundPlatform();
|
||||
|
||||
@Test
|
||||
public void deepCavesOpenAsAirAboveTheIrisLavaBand() throws IOException {
|
||||
public void listedCavesAreReportedAsNotExportedOnce() throws IOException {
|
||||
WorldgenExportResult result = export();
|
||||
|
||||
assertTrue(result.message() + " " + result.diagnostics(), result.isSuccess());
|
||||
JsonObject head = JsonParser.parseString(Files.readString(result.output().resolve("data/" + NAMESPACE + "/worldgen/material_rule/"
|
||||
+ ExportTestPacks.DIMENSION + ".json"), StandardCharsets.UTF_8)).getAsJsonObject().getAsJsonArray("sequence").get(0).getAsJsonObject();
|
||||
assertEquals("minecraft:ore_vein", head.get("type").getAsString());
|
||||
String opening = head.get("density").getAsString();
|
||||
assertTrue(opening, Files.isRegularFile(densityFunction(result.output(), opening)));
|
||||
long reports = result.diagnostics().stream().filter(diagnostic -> diagnostic.limit() == ExportLimit.LISTED_CAVES).count();
|
||||
assertEquals(result.diagnostics().toString(), 1, reports);
|
||||
assertTrue(result.diagnostics().stream().filter(diagnostic -> diagnostic.limit() == ExportLimit.LISTED_CAVES)
|
||||
.allMatch(diagnostic -> diagnostic.severity() == ExportDiagnostic.Severity.WARNING));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void theExportedWorldHasNoCaveFieldNoDeepCaveOpeningAndNoCaveAir() throws IOException {
|
||||
WorldgenExportResult result = export();
|
||||
assertTrue(result.message() + " " + result.diagnostics(), result.isSuccess());
|
||||
|
||||
Path materialRule = result.output().resolve("data/" + NAMESPACE + "/worldgen/material_rule/" + ExportTestPacks.DIMENSION + ".json");
|
||||
JsonObject rules = JsonParser.parseString(Files.readString(materialRule, StandardCharsets.UTF_8)).getAsJsonObject();
|
||||
assertFalse(rules.toString(), rules.toString().contains("cave/"));
|
||||
assertFalse(Files.exists(result.output().resolve("data/" + NAMESPACE + "/worldgen/density_function/cave/field.json")));
|
||||
try (WorldgenExportSampler sampler = WorldgenExportSampler.open(result.output(), WorldgenExportMode.OVERWORLD, DIMENSION_ID, SEED)) {
|
||||
ProtoChunk chunk = sampler.terrainChunk(0, 0);
|
||||
for (int x = 0; x < CHUNK_WIDTH; x++) {
|
||||
for (int z = 0; z < CHUNK_WIDTH; z++) {
|
||||
for (int y = MIN_Y; y <= CAVE_TOP; y++) {
|
||||
for (int y = MIN_Y + 1; y <= DEEP_Y; y++) {
|
||||
BlockState state = chunk.getBlockState(new BlockPos(x, y, z));
|
||||
String where = state + " at " + x + "," + y + "," + z;
|
||||
if (y <= LAVA_Y) {
|
||||
assertTrue(where, state.is(Blocks.LAVA));
|
||||
} else {
|
||||
assertTrue(where, state.isAir());
|
||||
}
|
||||
assertFalse(state + " at " + x + "," + y + "," + z, state.isAir() || state.is(Blocks.LAVA));
|
||||
}
|
||||
}
|
||||
}
|
||||
assertTrue(chunk.getBlockState(new BlockPos(0, LAVA_LINE - 1, 0)).isAir());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deepCaveRuleSharesTheCaveFieldCacheWithTheFinalDensity() throws IOException {
|
||||
WorldgenExportResult result = export();
|
||||
assertTrue(result.message() + " " + result.diagnostics(), result.isSuccess());
|
||||
|
||||
try (WorldgenExportSampler sampler = WorldgenExportSampler.open(result.output(), WorldgenExportMode.OVERWORLD, DIMENSION_ID, SEED)) {
|
||||
CompiledCaches caches = CompiledCaches.open(sampler.registries(), SEED);
|
||||
DensityFunction opening = caches.oreVeins().getFirst().density();
|
||||
int field = caches.rootId(caches.function(NAMESPACE + ":" + CAVE_FIELD));
|
||||
Set<Integer> finalDensity = caches.ids(caches.finalDensity());
|
||||
|
||||
assertTrue(caches.ids(opening).toString(), caches.ids(opening).contains(field));
|
||||
assertTrue(finalDensity.toString(), finalDensity.contains(field));
|
||||
assertTrue(finalDensity.toString(), finalDensity.contains(caches.rootId(opening)));
|
||||
}
|
||||
}
|
||||
|
||||
private WorldgenExportResult export() throws IOException {
|
||||
File pack = ExportTestPacks.withDimension(temporaryFolder.newFolder("pack"), DIMENSION);
|
||||
Files.createDirectories(pack.toPath().resolve("caves"));
|
||||
Files.writeString(pack.toPath().resolve("caves/tunnels.json"), TUNNELS, StandardCharsets.UTF_8);
|
||||
WorldgenExportRequest request = WorldgenExportRequest.builder()
|
||||
.pack(pack.toPath())
|
||||
.dimension(ExportTestPacks.DIMENSION)
|
||||
@@ -128,9 +105,4 @@ public final class WorldgenExportDeepCaves263Test {
|
||||
.build();
|
||||
return WorldgenDatapackExporter.create().export(request, WorldgenExportProgress.NONE);
|
||||
}
|
||||
|
||||
private static Path densityFunction(Path datapack, String id) {
|
||||
int separator = id.indexOf(':');
|
||||
return datapack.resolve("data/" + id.substring(0, separator) + "/worldgen/density_function/" + id.substring(separator + 1) + ".json");
|
||||
}
|
||||
}
|
||||
+6
-96
@@ -1,22 +1,15 @@
|
||||
package art.arcane.iris.pack.datapack.export.compile.cave;
|
||||
|
||||
import art.arcane.iris.generation.cave.IrisCaveProfile;
|
||||
import art.arcane.iris.pack.datapack.export.ir.AquiferDef;
|
||||
import art.arcane.iris.pack.datapack.export.ir.Axis;
|
||||
import art.arcane.iris.pack.datapack.export.ir.ExportDiagnostic;
|
||||
import art.arcane.iris.pack.datapack.export.ir.ExportLimit;
|
||||
import art.arcane.iris.pack.datapack.export.ir.Field;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* The aquifer of an exported dimension: dry rock with open water where the surface lies below the fluid height. Cave
|
||||
* fluid and lava are not exported, because the caves they fill are not.
|
||||
*/
|
||||
public final class AquiferCompiler {
|
||||
private static final int LAVA_LIMIT_Y = -10;
|
||||
private static final int LAVA_CENTER_MARGIN = 12;
|
||||
private static final int FLUID_BAND_HEIGHT = 40;
|
||||
private static final int FLUID_BAND_CENTER = 20;
|
||||
private static final double SPREAD_LEVEL_SCALE = 10.0;
|
||||
private static final double LEVEL_ROUNDING_MARGIN = 0.5;
|
||||
private static final int OPEN_WATER_DEPTH = 8;
|
||||
private static final int OPEN_WATER_HEADROOM = 8;
|
||||
@@ -25,41 +18,19 @@ public final class AquiferCompiler {
|
||||
private static final int OPEN_WATER_ESTIMATE_SLACK = 40;
|
||||
private static final Field OPEN_WATER_LIFT = new Field.Const(2.0);
|
||||
private static final Field DRY = new Field.Const(-1.0);
|
||||
private static final Field PARTIAL = new Field.Const(0.6);
|
||||
private static final Field LOW_BARRIER = new Field.Const(-1.0);
|
||||
private static final Field NO_EXCLUSION = new Field.Const(-1.0);
|
||||
private static final Field LAVA = new Field.Const(1.0);
|
||||
private static final Field NO_LAVA = new Field.Const(0.0);
|
||||
private static final Field OUTSIDE_BAND = new Field.Const(0.0);
|
||||
private static final Field INSIDE_BAND = new Field.Const(1.0);
|
||||
|
||||
private final CaveInputs inputs;
|
||||
private final Field blockY;
|
||||
private final int lowFluidBand;
|
||||
private final int highFluidBand;
|
||||
|
||||
public AquiferCompiler(CaveInputs inputs) {
|
||||
this.inputs = Objects.requireNonNull(inputs);
|
||||
this.blockY = inputs.blockY();
|
||||
this.lowFluidBand = Math.floorDiv(inputs.minY(), FLUID_BAND_HEIGHT) - 1;
|
||||
this.highFluidBand = Math.floorDiv(inputs.maxY(), FLUID_BAND_HEIGHT) + 1;
|
||||
}
|
||||
|
||||
public AquiferDef compile(CaveSelection selection) {
|
||||
public AquiferDef compile() {
|
||||
AquiferDef dry = AquiferDef.dry(inputs.aquiferSurface());
|
||||
boolean lavaWanted = any(selection, IrisCaveProfile::isAllowLava);
|
||||
boolean lavaExported = lavaWanted && inputs.lavaY() <= LAVA_LIMIT_Y;
|
||||
if (lavaWanted && !lavaExported) {
|
||||
inputs.diagnostics().add(new ExportDiagnostic(ExportDiagnostic.Severity.WARNING, ExportLimit.LAVA_HEIGHT, inputs.resource(),
|
||||
"Cave lava height Y " + inputs.lavaY() + " is above Y " + LAVA_LIMIT_Y + "; caves export without lava"));
|
||||
}
|
||||
boolean wet = any(selection, IrisCaveProfile::isAllowFluid);
|
||||
if (!lavaExported && !wet) {
|
||||
return new AquiferDef(dry.barrier(), openWater(dry.floodedness()), dry.spread(), dry.lava(), dry.exclusion(), dry.surfaceLevel());
|
||||
}
|
||||
Field spread = lavaExported ? lavaSpread(wet, dry.spread()) : dry.spread();
|
||||
Field lava = lavaExported ? lavaBands() : NO_LAVA;
|
||||
return new AquiferDef(LOW_BARRIER, openWater(floodedness(selection, lavaExported)), spread, lava, NO_EXCLUSION, inputs.aquiferSurface());
|
||||
return new AquiferDef(dry.barrier(), openWater(dry.floodedness()), dry.spread(), dry.lava(), dry.exclusion(), dry.surfaceLevel());
|
||||
}
|
||||
|
||||
private Field openWater(Field caveFlood) {
|
||||
@@ -71,65 +42,4 @@ public final class AquiferCompiler {
|
||||
Field lift = new Field.Gate(aboveFloor, new Field.Gate(lowColumn, OPEN_WATER_LIFT));
|
||||
return new Field.Binary(Field.BinaryOp.ADD, caveFlood, new Field.Gate(nearFluid, new Field.Gate(lowEstimate, lift)));
|
||||
}
|
||||
|
||||
private Field floodedness(CaveSelection selection, boolean lavaExported) {
|
||||
Field flood = selection.profiles().isEmpty() ? DRY : selection.select(source -> flood(source, lavaExported), DRY);
|
||||
for (CaveSource band : selection.bands()) {
|
||||
Field banded = flood(band, lavaExported);
|
||||
if (banded.equals(flood)) {
|
||||
continue;
|
||||
}
|
||||
Field inside = new Field.Partition(blockY, List.of((double) band.minY(), band.maxY() + 1.0), List.of(OUTSIDE_BAND, INSIDE_BAND, OUTSIDE_BAND));
|
||||
flood = new Field.Mux(inside, List.of(flood, banded));
|
||||
}
|
||||
return flood;
|
||||
}
|
||||
|
||||
private Field flood(CaveSource source, boolean lavaExported) {
|
||||
IrisCaveProfile profile = source.profile();
|
||||
int top = Integer.MIN_VALUE;
|
||||
if (lavaExported && profile.isAllowLava()) {
|
||||
top = inputs.lavaY() + LAVA_CENTER_MARGIN;
|
||||
}
|
||||
if (profile.isAllowFluid()) {
|
||||
top = Math.max(top, inputs.fluidHeight());
|
||||
}
|
||||
if (top < inputs.minY()) {
|
||||
return DRY;
|
||||
}
|
||||
if (top >= inputs.maxY()) {
|
||||
return PARTIAL;
|
||||
}
|
||||
return new Field.RangeIf(blockY, inputs.minY(), top + 1.0, PARTIAL, DRY);
|
||||
}
|
||||
|
||||
private Field lavaSpread(boolean wet, Field vanillaSpread) {
|
||||
Field levels = new Field.Coord(Axis.Y, Field.Tiling.CLAMP, lowFluidBand, highFluidBand, spreadAt(lowFluidBand), spreadAt(highFluidBand));
|
||||
return wet ? new Field.RangeIf(fluidBand(), lowFluidBand, lavaBand() + 1.0, levels, vanillaSpread) : levels;
|
||||
}
|
||||
|
||||
private Field lavaBands() {
|
||||
return new Field.RangeIf(fluidBand(), lowFluidBand, lavaBand() + 1.0, LAVA, NO_LAVA);
|
||||
}
|
||||
|
||||
private Field fluidBand() {
|
||||
return new Field.Coord(Axis.Y, Field.Tiling.CLAMP, lowFluidBand, highFluidBand, lowFluidBand, highFluidBand);
|
||||
}
|
||||
|
||||
private int lavaBand() {
|
||||
return Math.floorDiv(inputs.lavaY() + LAVA_CENTER_MARGIN, FLUID_BAND_HEIGHT);
|
||||
}
|
||||
|
||||
private double spreadAt(int band) {
|
||||
return (inputs.lavaY() - FLUID_BAND_CENTER + LEVEL_ROUNDING_MARGIN) / SPREAD_LEVEL_SCALE - band * (FLUID_BAND_HEIGHT / SPREAD_LEVEL_SCALE);
|
||||
}
|
||||
|
||||
private static boolean any(CaveSelection selection, Predicate<IrisCaveProfile> property) {
|
||||
for (CaveSource source : selection.sources()) {
|
||||
if (property.test(source.profile())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
-60
@@ -1,60 +0,0 @@
|
||||
package art.arcane.iris.pack.datapack.export.compile.cave;
|
||||
|
||||
import art.arcane.iris.pack.datapack.export.compile.noise.StyleCompiler;
|
||||
import art.arcane.iris.pack.datapack.export.ir.Field;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public final class CaveFieldCompiler {
|
||||
static final int CELL_XZ = 4;
|
||||
static final int CELL_Y = 4;
|
||||
static final double WALL_BAND = 0.03125;
|
||||
private static final double MIN_GAIN = 1.0 / 64.0;
|
||||
private static final double MAX_GAIN = 64.0;
|
||||
private static final Field UNCOVERED = new Field.Const(CaveProfileCompiler.SOLID);
|
||||
|
||||
private final CaveProfileCompiler profiles;
|
||||
private final CaveInputs inputs;
|
||||
|
||||
public CaveFieldCompiler(StyleCompiler styles, CaveInputs inputs) {
|
||||
this.profiles = new CaveProfileCompiler(styles, inputs);
|
||||
this.inputs = inputs;
|
||||
}
|
||||
|
||||
public Optional<Field> compile(CaveSelection selection) {
|
||||
return union(selection).map(union -> new Field.Grid(union, CELL_XZ, CELL_Y));
|
||||
}
|
||||
|
||||
private Optional<Field> union(CaveSelection selection) {
|
||||
List<Field> parts = new ArrayList<>(selection.bands().size() + 1);
|
||||
if (!selection.profiles().isEmpty()) {
|
||||
parts.add(selection.select(this::normalized, UNCOVERED));
|
||||
}
|
||||
for (CaveSource band : selection.bands()) {
|
||||
parts.add(normalized(band));
|
||||
}
|
||||
if (parts.isEmpty()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
Field union = parts.getFirst();
|
||||
for (int index = 1; index < parts.size(); index++) {
|
||||
union = new Field.Binary(Field.BinaryOp.MIN, union, parts.get(index));
|
||||
}
|
||||
return Optional.of(union);
|
||||
}
|
||||
|
||||
private Field normalized(CaveSource source) {
|
||||
return profiles.compile(source, gain(source));
|
||||
}
|
||||
|
||||
private double gain(CaveSource source) {
|
||||
Optional<CaveInterior> interior = profiles.interior(source);
|
||||
if (interior.isEmpty()) {
|
||||
return 1.0;
|
||||
}
|
||||
double band = WallShellCalibrator.band(interior.get(), inputs.noises().byReference(), inputs.capabilities().target());
|
||||
return band > 0.0 ? Math.clamp(WALL_BAND / band, MIN_GAIN, MAX_GAIN) : 1.0;
|
||||
}
|
||||
}
|
||||
-14
@@ -1,14 +0,0 @@
|
||||
package art.arcane.iris.pack.datapack.export.compile.cave;
|
||||
|
||||
import art.arcane.iris.pack.datapack.export.ir.Field;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
record CaveInterior(Field field, int minY, int maxY) {
|
||||
CaveInterior {
|
||||
Objects.requireNonNull(field);
|
||||
if (maxY < minY) {
|
||||
throw new IllegalArgumentException("Cave interior needs maxY at or above minY, got " + minY + ".." + maxY);
|
||||
}
|
||||
}
|
||||
}
|
||||
-294
@@ -1,294 +0,0 @@
|
||||
package art.arcane.iris.pack.datapack.export.compile.cave;
|
||||
|
||||
import art.arcane.iris.generation.cave.IrisCaveFieldModule;
|
||||
import art.arcane.iris.generation.cave.IrisCaveProfile;
|
||||
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.generation.noise.IrisStyledRange;
|
||||
import art.arcane.iris.generation.noise.NoiseStyle;
|
||||
import art.arcane.iris.pack.datapack.export.compile.noise.StyleCompiler;
|
||||
import art.arcane.iris.pack.datapack.export.ir.Axis;
|
||||
import art.arcane.iris.pack.datapack.export.ir.ExportDiagnostic;
|
||||
import art.arcane.iris.pack.datapack.export.ir.ExportLimit;
|
||||
import art.arcane.iris.pack.datapack.export.ir.Field;
|
||||
import art.arcane.iris.pack.value.IrisRange;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
public final class CaveProfileCompiler {
|
||||
static final double SOLID = 1.0;
|
||||
private static final long BASE_SALT = 934_447L;
|
||||
private static final long DETAIL_SALT = 612_991L;
|
||||
private static final long THRESHOLD_SALT = 489_112L;
|
||||
private static final long SURFACE_BREAK_SALT = 341_219L;
|
||||
private static final long MODULE_SALT = 1_000_003L;
|
||||
private static final long MODULE_SALT_STEP = 65_537L;
|
||||
private static final double LOW_WEIGHT = 0.1;
|
||||
private static final int CEILING_FADE_DEPTH = 12;
|
||||
private static final double CLOSURE_EPSILON = 1.0e-6;
|
||||
private static final double SEALED_MARGIN = 1.0;
|
||||
private static final Set<NoiseStyle> CELLULAR_STYLES = cellularStyles();
|
||||
|
||||
private final StyleCompiler styles;
|
||||
private final CaveInputs inputs;
|
||||
private final Field blockY;
|
||||
|
||||
public CaveProfileCompiler(StyleCompiler styles, CaveInputs inputs) {
|
||||
this.styles = Objects.requireNonNull(styles);
|
||||
this.inputs = Objects.requireNonNull(inputs);
|
||||
this.blockY = inputs.blockY();
|
||||
}
|
||||
|
||||
public Field compile(CaveSource source, double gain) {
|
||||
if (!(gain > 0.0) || Double.isInfinite(gain)) {
|
||||
throw new IllegalArgumentException("Cave field gain must be finite and positive, got " + gain);
|
||||
}
|
||||
IrisCaveProfile profile = source.profile();
|
||||
IrisRange range = profile.getVerticalRange();
|
||||
int floor = floor(inputs, source);
|
||||
int ceiling = Math.min(source.maxY(), Math.min(inputs.maxY(), inputs.minY() + (int) Math.ceil(range.getMax())));
|
||||
if (ceiling < floor) {
|
||||
return new Field.Const(SOLID);
|
||||
}
|
||||
double normalization = normalization(profile) / gain;
|
||||
List<Field> terms = densityTerms(source, normalization, floor, ceiling);
|
||||
edgeFade(profile, floor, ceiling, gain).ifPresent(terms::add);
|
||||
terms.add(surface(source, closure(profile, normalization), gain));
|
||||
return bounded(sum(terms), floor, ceiling);
|
||||
}
|
||||
|
||||
Optional<CaveInterior> interior(CaveSource source) {
|
||||
IrisCaveProfile profile = source.profile();
|
||||
int floor = floor(inputs, source);
|
||||
int ceiling = Math.min(source.maxY(), Math.min(inputs.maxY(), inputs.minY() + (int) Math.ceil(profile.getVerticalRange().getMax())));
|
||||
if (ceiling < floor) {
|
||||
return Optional.empty();
|
||||
}
|
||||
List<Field> terms = densityTerms(source, normalization(profile), floor, ceiling);
|
||||
terms.add(negativeThreshold(profile, 1.0));
|
||||
return Optional.of(new CaveInterior(sum(terms), floor, ceiling));
|
||||
}
|
||||
|
||||
static int floor(CaveInputs inputs, CaveSource source) {
|
||||
return Math.max(source.minY(), inputs.minY() + Math.max(0, (int) Math.floor(source.profile().getVerticalRange().getMin())));
|
||||
}
|
||||
|
||||
static boolean cellular(IrisGeneratorStyle style) {
|
||||
if (style.getExpression() != null || style.getImageMap() != null) {
|
||||
return false;
|
||||
}
|
||||
if (style.getCellularFrequency() > 0.0 || CELLULAR_STYLES.contains(style.getStyle())) {
|
||||
return true;
|
||||
}
|
||||
return style.getFracture() != null && cellular(style.getFracture());
|
||||
}
|
||||
|
||||
private List<Field> densityTerms(CaveSource source, double normalization, int floor, int ceiling) {
|
||||
IrisCaveProfile profile = source.profile();
|
||||
List<Field> terms = new ArrayList<>();
|
||||
addTerm(terms, source, new Term(profile.getBaseDensityStyle(), BASE_SALT, profile.getBaseWeight(), 0.0, false), normalization);
|
||||
addTerm(terms, source, new Term(profile.getDetailDensityStyle(), DETAIL_SALT, profile.getDetailWeight(), 0.0, false), normalization);
|
||||
List<IrisCaveFieldModule> modules = profile.getModules();
|
||||
for (int index = 0; index < modules.size(); index++) {
|
||||
IrisCaveFieldModule module = modules.get(index);
|
||||
IrisRange range = module.getVerticalRange();
|
||||
int low = inputs.minY() + (int) Math.floor(range.getMin());
|
||||
int high = inputs.minY() + (int) Math.ceil(range.getMax());
|
||||
if (module.getWeight() == 0.0 || high < floor || low > ceiling) {
|
||||
continue;
|
||||
}
|
||||
Field term = term(source, new Term(module.getStyle(), MODULE_SALT + index * MODULE_SALT_STEP, module.getWeight(), module.getThreshold(), module.isInvert()), normalization);
|
||||
terms.add(low <= floor && high >= ceiling ? term : new Field.Gate(window(low, high), term));
|
||||
}
|
||||
return terms;
|
||||
}
|
||||
|
||||
private void addTerm(List<Field> terms, CaveSource source, Term term, double normalization) {
|
||||
if (term.weight() != 0.0) {
|
||||
terms.add(term(source, term, normalization));
|
||||
}
|
||||
}
|
||||
|
||||
private Field term(CaveSource source, Term term, double normalization) {
|
||||
double sign = term.invert() ? -1.0 : 1.0;
|
||||
double scale = sign * term.weight() / normalization;
|
||||
Field unit = volume(source, term.style(), term.salt(), Math.abs(term.weight()) < LOW_WEIGHT);
|
||||
return affine(unit, 2.0 * scale, -scale * (1.0 + term.threshold()));
|
||||
}
|
||||
|
||||
private Field volume(CaveSource source, IrisGeneratorStyle style, long salt, boolean lowWeight) {
|
||||
boolean cellularStyle = cellular(style);
|
||||
if (cellularStyle && lowWeight) {
|
||||
return VolumeLift.lift(styles.compile(substitute(style), salt, inputs.noises(), inputs.capabilities()));
|
||||
}
|
||||
Field compiled = styles.compile(style, salt, inputs.noises(), inputs.capabilities());
|
||||
if (compiled.axes().contains(Axis.Y)) {
|
||||
return compiled;
|
||||
}
|
||||
if (!cellularStyle) {
|
||||
return VolumeLift.lift(compiled);
|
||||
}
|
||||
inputs.diagnostics().add(new ExportDiagnostic(ExportDiagnostic.Severity.WARNING, ExportLimit.NOISE_STYLE, source.resource(),
|
||||
"Cellular cave style " + style.getStyle() + " exports as smooth noise"));
|
||||
return VolumeLift.lift(styles.compile(substitute(style), salt, inputs.noises(), inputs.capabilities()));
|
||||
}
|
||||
|
||||
private Field planar(IrisGeneratorStyle style, long salt) {
|
||||
Field compiled = styles.compile(style, salt, inputs.noises(), inputs.capabilities());
|
||||
return compiled.axes().contains(Axis.Y) ? new Field.Slice(compiled, Axis.Y, 0) : compiled;
|
||||
}
|
||||
|
||||
private Field surface(CaveSource source, double closure, double gain) {
|
||||
IrisCaveProfile profile = source.profile();
|
||||
Field negativeThreshold = negativeThreshold(profile, gain);
|
||||
Field depthBelowClearance = new Field.Binary(Field.BinaryOp.SUB,
|
||||
new Field.Binary(Field.BinaryOp.ADD, inputs.surface(), new Field.Const(-Math.max(0, profile.getSurfaceClearance()))),
|
||||
blockY);
|
||||
Field sealed = new Field.Curve(depthBelowClearance, List.of(
|
||||
new Field.Knot(-1.0, new Field.Const(SEALED_MARGIN * gain - closure), 0.0),
|
||||
new Field.Knot(0.0, new Field.Const(-closure), 0.0),
|
||||
new Field.Knot(CEILING_FADE_DEPTH, negativeThreshold, 0.0)));
|
||||
if (!profile.isAllowSurfaceBreak()) {
|
||||
return sealed;
|
||||
}
|
||||
Field breaking = new Field.Binary(Field.BinaryOp.ADD, breakSteps(profile, closure, gain), negativeThreshold);
|
||||
Field breakNoise = planar(profile.getSurfaceBreakStyle(), SURFACE_BREAK_SALT);
|
||||
Field cutoff = new Field.Const((profile.getSurfaceBreakNoiseThreshold() + 1.0) / 2.0);
|
||||
return new Field.Binary(Field.BinaryOp.ADD,
|
||||
new Field.Gate(new Field.Binary(Field.BinaryOp.SUB, cutoff, breakNoise), sealed),
|
||||
new Field.Gate(new Field.Binary(Field.BinaryOp.SUB, breakNoise, cutoff), breaking));
|
||||
}
|
||||
|
||||
private Field breakSteps(IrisCaveProfile profile, double closure, double gain) {
|
||||
int depth = Math.max(0, profile.getSurfaceBreakDepth());
|
||||
double boost = Math.max(0.0, profile.getSurfaceBreakThresholdBoost()) * gain;
|
||||
Field belowSurface = new Field.Binary(Field.BinaryOp.SUB, inputs.surface(), blockY);
|
||||
List<Field.Knot> knots = new ArrayList<>();
|
||||
knots.add(new Field.Knot(-1.0, new Field.Const((thresholdCeiling(profile) + SEALED_MARGIN) * gain - closure + boost), 0.0));
|
||||
knots.add(new Field.Knot(0.0, new Field.Const(-boost), 0.0));
|
||||
if (boost > 0.0) {
|
||||
if (depth > 0) {
|
||||
knots.add(new Field.Knot(depth, new Field.Const(-boost), 0.0));
|
||||
}
|
||||
knots.add(new Field.Knot(depth + 1.0, new Field.Const(0.0), 0.0));
|
||||
}
|
||||
return new Field.Curve(belowSurface, knots);
|
||||
}
|
||||
|
||||
private Field negativeThreshold(IrisCaveProfile profile, double gain) {
|
||||
IrisStyledRange range = profile.getDensityThreshold();
|
||||
double bias = profile.getThresholdBias();
|
||||
if (range.getMin() == range.getMax()) {
|
||||
return new Field.Const(gain * (bias - range.getMin()));
|
||||
}
|
||||
if (range.getStyle().isFlat()) {
|
||||
return new Field.Const(gain * (bias - (range.getMin() + 0.5 * (range.getMax() - range.getMin()))));
|
||||
}
|
||||
return affine(planar(range.getStyle(), THRESHOLD_SALT), gain * (range.getMin() - range.getMax()), gain * (bias - range.getMin()));
|
||||
}
|
||||
|
||||
private Optional<Field> edgeFade(IrisCaveProfile profile, int floor, int ceiling, double gain) {
|
||||
int fade = Math.max(0, profile.getVerticalEdgeFade());
|
||||
double strength = Math.max(0.0, profile.getVerticalEdgeFadeStrength()) * gain;
|
||||
if (fade <= 0 || strength <= 0.0 || ceiling <= floor) {
|
||||
return Optional.empty();
|
||||
}
|
||||
List<Field.Knot> knots = new ArrayList<>();
|
||||
knots.add(new Field.Knot(floor, new Field.Const(strength), 0.0));
|
||||
if (floor + fade <= ceiling - fade) {
|
||||
knots.add(new Field.Knot(floor + fade, new Field.Const(0.0), 0.0));
|
||||
if (ceiling - fade > floor + fade) {
|
||||
knots.add(new Field.Knot(ceiling - fade, new Field.Const(0.0), 0.0));
|
||||
}
|
||||
} else {
|
||||
double middle = floor + (ceiling - floor) / 2.0;
|
||||
double progress = Math.min(middle - floor, ceiling - middle) / fade;
|
||||
knots.add(new Field.Knot(middle, new Field.Const((1.0 - smoothstep(progress)) * strength), 0.0));
|
||||
}
|
||||
knots.add(new Field.Knot(ceiling, new Field.Const(strength), 0.0));
|
||||
return Optional.of(new Field.Curve(blockY, knots));
|
||||
}
|
||||
|
||||
private Field bounded(Field core, int floor, int ceiling) {
|
||||
if (floor <= inputs.minY() && ceiling >= inputs.maxY()) {
|
||||
return core;
|
||||
}
|
||||
Field shifted = new Field.Binary(Field.BinaryOp.ADD, core, new Field.Const(-SOLID));
|
||||
return new Field.Binary(Field.BinaryOp.ADD, new Field.Gate(window(floor, ceiling), shifted), new Field.Const(SOLID));
|
||||
}
|
||||
|
||||
private Field window(int low, int high) {
|
||||
return new Field.RangeIf(blockY, low, high + 1.0, new Field.Const(1.0), new Field.Const(0.0));
|
||||
}
|
||||
|
||||
private static Field affine(Field input, double scale, double offset) {
|
||||
if (input instanceof Field.Const constant) {
|
||||
return new Field.Const(scale * constant.value() + offset);
|
||||
}
|
||||
if (scale == 0.0) {
|
||||
return new Field.Const(offset);
|
||||
}
|
||||
return new Field.Curve(input, List.of(
|
||||
new Field.Knot(0.0, new Field.Const(offset), scale),
|
||||
new Field.Knot(1.0, new Field.Const(scale + offset), scale)));
|
||||
}
|
||||
|
||||
private static Field sum(List<Field> terms) {
|
||||
Field total = terms.getFirst();
|
||||
for (int index = 1; index < terms.size(); index++) {
|
||||
total = new Field.Binary(Field.BinaryOp.ADD, total, terms.get(index));
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
private static double normalization(IrisCaveProfile profile) {
|
||||
double weight = Math.abs(profile.getBaseWeight()) + Math.abs(profile.getDetailWeight());
|
||||
for (IrisCaveFieldModule module : profile.getModules()) {
|
||||
weight += Math.abs(module.getWeight());
|
||||
}
|
||||
return weight <= 0.0 ? 1.0 : weight;
|
||||
}
|
||||
|
||||
private static double closure(IrisCaveProfile profile, double normalization) {
|
||||
double minimum = -Math.abs(profile.getBaseWeight()) - Math.abs(profile.getDetailWeight());
|
||||
for (IrisCaveFieldModule module : profile.getModules()) {
|
||||
double threshold = module.getThreshold();
|
||||
double low = module.isInvert() ? threshold - 1.0 : -1.0 - threshold;
|
||||
double high = module.isInvert() ? threshold + 1.0 : 1.0 - threshold;
|
||||
minimum += Math.min(low * module.getWeight(), high * module.getWeight());
|
||||
}
|
||||
return minimum / normalization - CLOSURE_EPSILON;
|
||||
}
|
||||
|
||||
private static double thresholdCeiling(IrisCaveProfile profile) {
|
||||
IrisStyledRange range = profile.getDensityThreshold();
|
||||
return Math.max(range.getMin(), range.getMax()) - profile.getThresholdBias();
|
||||
}
|
||||
|
||||
private static double smoothstep(double progress) {
|
||||
double clamped = Math.max(0.0, Math.min(1.0, progress));
|
||||
return clamped * clamped * (3.0 - 2.0 * clamped);
|
||||
}
|
||||
|
||||
private static IrisGeneratorStyle substitute(IrisGeneratorStyle style) {
|
||||
return new IrisGeneratorStyle(NoiseStyle.SIMPLEX).zoomed(style.getZoom());
|
||||
}
|
||||
|
||||
private static Set<NoiseStyle> cellularStyles() {
|
||||
Set<NoiseStyle> cellular = EnumSet.noneOf(NoiseStyle.class);
|
||||
for (NoiseStyle style : NoiseStyle.values()) {
|
||||
String name = style.name();
|
||||
if (name.contains("CELL") || name.contains("VASCULAR") || name.contains("GLOB") || name.contains("HEX")) {
|
||||
cellular.add(style);
|
||||
}
|
||||
}
|
||||
return cellular;
|
||||
}
|
||||
|
||||
private record Term(IrisGeneratorStyle style, long salt, double weight, double threshold, boolean invert) {
|
||||
}
|
||||
}
|
||||
-185
@@ -1,185 +0,0 @@
|
||||
package art.arcane.iris.pack.datapack.export.compile.cave;
|
||||
|
||||
import art.arcane.iris.generation.biome.IrisBiome;
|
||||
import art.arcane.iris.generation.cave.IrisCaveProfile;
|
||||
import art.arcane.iris.generation.terrain.IrisDimension;
|
||||
import art.arcane.iris.generation.terrain.IrisDimensionCarvingEntry;
|
||||
import art.arcane.iris.generation.terrain.IrisRegion;
|
||||
import art.arcane.iris.pack.datapack.export.compile.biome.BiomeCodes;
|
||||
import art.arcane.iris.pack.datapack.export.ir.ClimateLayout;
|
||||
import art.arcane.iris.pack.datapack.export.ir.Field;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.pack.value.IrisRange;
|
||||
import art.arcane.volmlib.util.mantle.flag.ReservedFlag;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
public record CaveSelection(Field index, List<CaveSource> profiles, boolean uncovered, List<CaveSource> bands) {
|
||||
private static final int UNCOVERED = -1;
|
||||
private static final Field NO_INDEX = new Field.Const(0.0);
|
||||
private static final Comparator<ClimateLayout.ClimateEntry> CODE_ORDER = Comparator
|
||||
.comparingDouble(ClimateLayout.ClimateEntry::min)
|
||||
.thenComparingDouble(ClimateLayout.ClimateEntry::max)
|
||||
.thenComparing(ClimateLayout.ClimateEntry::biomeId);
|
||||
|
||||
public CaveSelection {
|
||||
Objects.requireNonNull(index);
|
||||
profiles = List.copyOf(profiles);
|
||||
bands = List.copyOf(bands);
|
||||
}
|
||||
|
||||
public static CaveSelection resolve(CaveInputs inputs, IrisDimension dimension, IrisData data, BiomeCodes codes) {
|
||||
if (!dimension.isCarvingEnabled() || dimension.getDisabledComponents().contains(ReservedFlag.CARVED)) {
|
||||
return new CaveSelection(NO_INDEX, List.of(), false, List.of());
|
||||
}
|
||||
Map<IrisCaveProfile, Integer> caseByProfile = new LinkedHashMap<>();
|
||||
List<CaveSource> sources = new ArrayList<>();
|
||||
IrisCaveProfile dimensionProfile = dimension.getCaveProfile();
|
||||
int fallback = enabled(dimensionProfile)
|
||||
? caseOf(source(inputs, inputs.resource(), dimensionProfile), caseByProfile, sources)
|
||||
: UNCOVERED;
|
||||
List<Double> thresholds = new ArrayList<>();
|
||||
List<Integer> leaves = new ArrayList<>();
|
||||
leaves.add(fallback);
|
||||
List<ClimateLayout.ClimateEntry> entries = caveEntries(codes, regionCaveBiomes(dimension, data));
|
||||
for (int position = 0; position < entries.size(); position++) {
|
||||
ClimateLayout.ClimateEntry entry = entries.get(position);
|
||||
Optional<CaveSource> source = entrySource(inputs, dimension, data, codes.loadKeyByBiomeId().get(entry.biomeId()));
|
||||
int selected = source.isPresent() ? caseOf(source.get(), caseByProfile, sources) : fallback;
|
||||
append(thresholds, leaves, entry.min(), selected);
|
||||
double nextMin = position + 1 < entries.size() ? entries.get(position + 1).min() : Double.POSITIVE_INFINITY;
|
||||
if (entry.max() < nextMin) {
|
||||
append(thresholds, leaves, entry.max(), fallback);
|
||||
}
|
||||
}
|
||||
boolean uncovered = leaves.contains(UNCOVERED);
|
||||
int uncoveredCase = sources.size();
|
||||
List<Field> constants = new ArrayList<>(leaves.size());
|
||||
for (int leaf : leaves) {
|
||||
constants.add(new Field.Const(leaf == UNCOVERED ? uncoveredCase : leaf));
|
||||
}
|
||||
Field index = thresholds.isEmpty() ? constants.getFirst() : new Field.Partition(codes.caveCode(), thresholds, constants);
|
||||
return new CaveSelection(index, sources, uncovered, bands(inputs, dimension, data));
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return profiles.isEmpty() && bands.isEmpty();
|
||||
}
|
||||
|
||||
public List<CaveSource> sources() {
|
||||
List<CaveSource> all = new ArrayList<>(profiles.size() + bands.size());
|
||||
all.addAll(profiles);
|
||||
all.addAll(bands);
|
||||
return all;
|
||||
}
|
||||
|
||||
public Field select(Function<CaveSource, Field> compiler, Field uncoveredCase) {
|
||||
List<Field> cases = new ArrayList<>(profiles.size() + 1);
|
||||
for (CaveSource source : profiles) {
|
||||
cases.add(compiler.apply(source));
|
||||
}
|
||||
if (uncovered || cases.isEmpty()) {
|
||||
cases.add(uncoveredCase);
|
||||
}
|
||||
return cases.size() == 1 ? cases.getFirst() : new Field.Mux(index, cases);
|
||||
}
|
||||
|
||||
private static void append(List<Double> thresholds, List<Integer> leaves, double start, int selected) {
|
||||
if (leaves.getLast() == selected) {
|
||||
return;
|
||||
}
|
||||
thresholds.add(start);
|
||||
leaves.add(selected);
|
||||
}
|
||||
|
||||
private static List<ClimateLayout.ClimateEntry> caveEntries(BiomeCodes codes, Set<String> caveBiomes) {
|
||||
List<ClimateLayout.ClimateEntry> entries = new ArrayList<>();
|
||||
for (ClimateLayout.ClimateEntry entry : codes.layout().entries()) {
|
||||
if (entry.axis() == ClimateLayout.ClimateAxis.DEPTH && caveBiomes.contains(codes.loadKeyByBiomeId().get(entry.biomeId()))) {
|
||||
entries.add(entry);
|
||||
}
|
||||
}
|
||||
entries.sort(CODE_ORDER);
|
||||
return entries;
|
||||
}
|
||||
|
||||
private static Set<String> regionCaveBiomes(IrisDimension dimension, IrisData data) {
|
||||
Set<String> caveBiomes = new HashSet<>();
|
||||
for (String regionKey : dimension.getRegions()) {
|
||||
IrisRegion region = regionKey == null ? null : data.getRegionLoader().load(regionKey, false);
|
||||
if (region != null && !region.isCompatExcluded()) {
|
||||
caveBiomes.addAll(region.getCaveBiomes());
|
||||
}
|
||||
}
|
||||
return caveBiomes;
|
||||
}
|
||||
|
||||
private static Optional<CaveSource> entrySource(CaveInputs inputs, IrisDimension dimension, IrisData data, String loadKey) {
|
||||
IrisBiome biome = loadKey == null ? null : data.getBiomeLoader().load(loadKey, false);
|
||||
if (biome == null || biome.isCompatExcluded()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
if (enabled(biome.getCaveProfile())) {
|
||||
return Optional.of(source(inputs, "biomes/" + biome.getLoadKey(), biome.getCaveProfile()));
|
||||
}
|
||||
for (String regionKey : dimension.getRegions()) {
|
||||
IrisRegion region = regionKey == null ? null : data.getRegionLoader().load(regionKey, false);
|
||||
if (region == null || region.isCompatExcluded() || !region.getCaveBiomes().contains(loadKey) || !enabled(region.getCaveProfile())) {
|
||||
continue;
|
||||
}
|
||||
return Optional.of(source(inputs, "regions/" + region.getLoadKey(), region.getCaveProfile()));
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
private static List<CaveSource> bands(CaveInputs inputs, IrisDimension dimension, IrisData data) {
|
||||
List<CaveSource> bands = new ArrayList<>();
|
||||
List<IrisDimensionCarvingEntry> entries = dimension.getCarving();
|
||||
if (entries == null) {
|
||||
return bands;
|
||||
}
|
||||
for (IrisDimensionCarvingEntry entry : entries) {
|
||||
if (entry == null || !entry.isEnabled()) {
|
||||
continue;
|
||||
}
|
||||
IrisBiome biome = entry.getRealBiome(data);
|
||||
if (biome == null || !enabled(biome.getCaveProfile())) {
|
||||
continue;
|
||||
}
|
||||
IrisRange range = entry.getWorldYRange();
|
||||
int low = range == null ? inputs.minY() : Math.max(inputs.minY(), (int) Math.ceil(range.getMin()));
|
||||
int high = range == null ? inputs.maxY() : Math.min(inputs.maxY(), (int) Math.floor(range.getMax()));
|
||||
if (high >= low) {
|
||||
bands.add(new CaveSource("biomes/" + biome.getLoadKey(), biome.getCaveProfile(), low, high));
|
||||
}
|
||||
}
|
||||
return bands;
|
||||
}
|
||||
|
||||
private static int caseOf(CaveSource source, Map<IrisCaveProfile, Integer> caseByProfile, List<CaveSource> sources) {
|
||||
Integer existing = caseByProfile.get(source.profile());
|
||||
if (existing != null) {
|
||||
return existing;
|
||||
}
|
||||
caseByProfile.put(source.profile(), sources.size());
|
||||
sources.add(source);
|
||||
return sources.size() - 1;
|
||||
}
|
||||
|
||||
private static CaveSource source(CaveInputs inputs, String resource, IrisCaveProfile profile) {
|
||||
return new CaveSource(resource, profile, inputs.minY(), inputs.maxY());
|
||||
}
|
||||
|
||||
private static boolean enabled(IrisCaveProfile profile) {
|
||||
return profile != null && profile.isEnabled();
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package art.arcane.iris.pack.datapack.export.compile.cave;
|
||||
|
||||
import art.arcane.iris.generation.cave.IrisCaveProfile;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public record CaveSource(String resource, IrisCaveProfile profile, int minY, int maxY) {
|
||||
public CaveSource {
|
||||
Objects.requireNonNull(resource);
|
||||
Objects.requireNonNull(profile);
|
||||
if (maxY < minY) {
|
||||
throw new IllegalArgumentException("Cave source '" + resource + "' needs maxY at or above minY, got " + minY + ".." + maxY);
|
||||
}
|
||||
}
|
||||
}
|
||||
+32
-12
@@ -1,18 +1,27 @@
|
||||
package art.arcane.iris.pack.datapack.export.compile.cave;
|
||||
|
||||
import art.arcane.iris.generation.biome.IrisBiome;
|
||||
import art.arcane.iris.generation.terrain.IrisDimension;
|
||||
import art.arcane.iris.generation.terrain.IrisRegion;
|
||||
import art.arcane.iris.pack.datapack.export.compile.CompileStage;
|
||||
import art.arcane.iris.pack.datapack.export.compile.PackCompileContext;
|
||||
import art.arcane.iris.pack.datapack.export.ir.BiomeDef;
|
||||
import art.arcane.iris.pack.datapack.export.ir.Field;
|
||||
import art.arcane.iris.pack.datapack.export.ir.ExportDiagnostic;
|
||||
import art.arcane.iris.pack.datapack.export.ir.ExportLimit;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Empties the carvers of the exported biomes and exports the open water of the aquifer. Listed caves are not exported
|
||||
* yet: the exported world has no caves, and the stage says so when the pack lists any.
|
||||
*/
|
||||
public final class CaveStage implements CompileStage {
|
||||
static final String LISTED_CAVES_NOT_EXPORTED = "Listed caves are not exported yet; the exported world has no Iris caves";
|
||||
private static final String CARVERS = "carvers";
|
||||
|
||||
@Override
|
||||
@@ -23,23 +32,34 @@ public final class CaveStage implements CompileStage {
|
||||
@Override
|
||||
public void apply(PackCompileContext context) {
|
||||
CaveInputs inputs = CaveInputs.of(context);
|
||||
CaveSelection selection = CaveSelection.resolve(inputs, context.dimension(), context.data(), context.biomeCodes());
|
||||
CaveFieldCompiler compiler = new CaveFieldCompiler(context.styles(), inputs);
|
||||
Optional<Field> caves = compiler.compile(selection);
|
||||
if (caves.isPresent()) {
|
||||
Field.Shared field = new Field.Shared(DeepCaveCompiler.FIELD, caves.get());
|
||||
Optional<DeepCaveCompiler.DeepCaves> deep = new DeepCaveCompiler(inputs).compile(field, selection);
|
||||
context.setCaveField(field, CaveFieldCompiler.WALL_BAND);
|
||||
context.setCaves(deep.map(DeepCaveCompiler.DeepCaves::router).orElse(field));
|
||||
deep.ifPresent(found -> context.setDeepCaves(found.opening()));
|
||||
if (listsCaves(context.dimension(), context.data())) {
|
||||
inputs.diagnostics().add(new ExportDiagnostic(ExportDiagnostic.Severity.WARNING, ExportLimit.LISTED_CAVES,
|
||||
inputs.resource(), LISTED_CAVES_NOT_EXPORTED));
|
||||
}
|
||||
context.setAquifer(new AquiferCompiler(inputs).compile(selection));
|
||||
context.setAquifer(new AquiferCompiler(inputs).compile());
|
||||
List<BiomeDef> biomes = context.biomes();
|
||||
if (biomes.stream().anyMatch(CaveStage::carves)) {
|
||||
context.setBiomes(withoutCarvers(biomes));
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean listsCaves(IrisDimension dimension, IrisData data) {
|
||||
if (!dimension.getCaves().isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
for (IrisRegion region : dimension.getAllRegions(() -> data)) {
|
||||
if (!region.getCaves().isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
for (IrisBiome biome : dimension.getReachableBiomes(() -> data)) {
|
||||
if (!biome.getCaves().isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static List<BiomeDef> withoutCarvers(List<BiomeDef> biomes) {
|
||||
List<BiomeDef> cleaned = new ArrayList<>(biomes.size());
|
||||
for (BiomeDef biome : biomes) {
|
||||
|
||||
-78
@@ -1,78 +0,0 @@
|
||||
package art.arcane.iris.pack.datapack.export.compile.cave;
|
||||
|
||||
import art.arcane.iris.pack.datapack.export.ir.DimensionDef;
|
||||
import art.arcane.iris.pack.datapack.export.ir.ExportDiagnostic;
|
||||
import art.arcane.iris.pack.datapack.export.ir.ExportLimit;
|
||||
import art.arcane.iris.pack.datapack.export.ir.Field;
|
||||
import art.arcane.iris.pack.datapack.export.lower.FieldDomains;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
public final class DeepCaveCompiler {
|
||||
static final int LAVA_LINE = -54;
|
||||
static final String FIELD = "cave/field";
|
||||
static final String OPENING = "cave/deep_opening";
|
||||
private static final double OPEN_MARGIN = Math.nextUp(Float.MIN_VALUE);
|
||||
private static final Field OPEN = new Field.Const(1.0);
|
||||
private static final Field INSIDE = new Field.Const(0.0);
|
||||
private static final Field CLOSED = new Field.Const(CaveProfileCompiler.SOLID);
|
||||
private static final Field UNMASKED = new Field.Const(-FieldDomains.CONSTANT_LIMIT);
|
||||
|
||||
private final CaveInputs inputs;
|
||||
private final Field blockY;
|
||||
|
||||
public DeepCaveCompiler(CaveInputs inputs) {
|
||||
this.inputs = Objects.requireNonNull(inputs);
|
||||
this.blockY = inputs.blockY();
|
||||
}
|
||||
|
||||
public Optional<DeepCaves> compile(Field.Shared field, CaveSelection selection) {
|
||||
Optional<Zone> found = zone(selection);
|
||||
if (found.isEmpty()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
Zone zone = found.get();
|
||||
inputs.diagnostics().add(new ExportDiagnostic(ExportDiagnostic.Severity.WARNING, ExportLimit.DEEP_CAVE_LAYERS, inputs.resource(),
|
||||
"Caves between Y " + zone.low() + " and Y " + zone.high() + " open in the material pass, so they get wall palettes but no floor or ceiling layers"));
|
||||
Field opened = new Field.Binary(Field.BinaryOp.MAX, field, inside(zone, INSIDE, CLOSED));
|
||||
Field.Shared opening = new Field.Shared(OPENING,
|
||||
new Field.Gate(new Field.Binary(Field.BinaryOp.SUB, new Field.Const(OPEN_MARGIN), opened), OPEN));
|
||||
Field mask = new Field.Binary(Field.BinaryOp.ADD, opening, inside(zone, INSIDE, UNMASKED));
|
||||
return Optional.of(new DeepCaves(new Field.Binary(Field.BinaryOp.MAX, field, mask), opening));
|
||||
}
|
||||
|
||||
private Optional<Zone> zone(CaveSelection selection) {
|
||||
int high = Math.min(line() - 1, inputs.maxY());
|
||||
int low = inputs.minY();
|
||||
int deepest = Integer.MAX_VALUE;
|
||||
for (CaveSource source : selection.sources()) {
|
||||
deepest = Math.min(deepest, CaveProfileCompiler.floor(inputs, source));
|
||||
if (source.profile().isAllowLava()) {
|
||||
low = Math.max(low, inputs.lavaY() + 1);
|
||||
}
|
||||
}
|
||||
if (high < low || high < deepest) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of(new Zone(low, high));
|
||||
}
|
||||
|
||||
private int line() {
|
||||
return Math.min(LAVA_LINE, DimensionDef.seaLevel(inputs.fluidHeight()));
|
||||
}
|
||||
|
||||
private Field inside(Zone zone, Field inRange, Field outOfRange) {
|
||||
return new Field.RangeIf(blockY, zone.low(), zone.high() + 1.0, inRange, outOfRange);
|
||||
}
|
||||
|
||||
public record DeepCaves(Field router, Field.Shared opening) {
|
||||
public DeepCaves {
|
||||
Objects.requireNonNull(router);
|
||||
Objects.requireNonNull(opening);
|
||||
}
|
||||
}
|
||||
|
||||
private record Zone(int low, int high) {
|
||||
}
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
package art.arcane.iris.pack.datapack.export.compile.cave;
|
||||
|
||||
import art.arcane.iris.pack.datapack.export.ir.Field;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
final class VolumeLift {
|
||||
private static final String SHARED_SUFFIX = "/volume";
|
||||
|
||||
private VolumeLift() {
|
||||
}
|
||||
|
||||
static Field lift(Field field) {
|
||||
return switch (field) {
|
||||
case Field.Const constant -> constant;
|
||||
case Field.Coord coord -> coord;
|
||||
case Field.Ref ref -> ref;
|
||||
case Field.TopSurface topSurface -> topSurface;
|
||||
case Field.Slice slice -> slice;
|
||||
case Field.Noise noise -> noise(noise);
|
||||
case Field.Binary binary -> new Field.Binary(binary.op(), lift(binary.left()), lift(binary.right()));
|
||||
case Field.Unary unary -> new Field.Unary(unary.op(), lift(unary.input()));
|
||||
case Field.Clamp clamp -> new Field.Clamp(lift(clamp.input()), clamp.min(), clamp.max());
|
||||
case Field.Lerp lerp -> new Field.Lerp(lift(lerp.alpha()), lift(lerp.first()), lift(lerp.second()));
|
||||
case Field.Round round -> new Field.Round(round.mode(), lift(round.input()), lift(round.multiple()));
|
||||
case Field.Curve curve -> curve(curve);
|
||||
case Field.Partition partition -> new Field.Partition(lift(partition.input()), partition.thresholds(), partition.leaves());
|
||||
case Field.Mux mux -> new Field.Mux(lift(mux.index()), liftAll(mux.cases()));
|
||||
case Field.Gate gate -> new Field.Gate(lift(gate.condition()), lift(gate.expr()));
|
||||
case Field.RangeIf rangeIf -> new Field.RangeIf(lift(rangeIf.input()), rangeIf.min(), rangeIf.max(), lift(rangeIf.inRange()), lift(rangeIf.outOfRange()));
|
||||
case Field.Grid grid -> new Field.Grid(lift(grid.expr()), grid.cellXZ(), grid.cellY());
|
||||
case Field.Shared shared -> shared(shared);
|
||||
};
|
||||
}
|
||||
|
||||
private static Field noise(Field.Noise noise) {
|
||||
double yScale = noise.yScale() == 0.0 ? noise.xzScale() : noise.yScale();
|
||||
return new Field.Noise(noise.noiseId(), noise.xzScale(), yScale, liftShift(noise.shiftX()), liftShift(noise.shiftY()), liftShift(noise.shiftZ()));
|
||||
}
|
||||
|
||||
private static Field liftShift(Field shift) {
|
||||
return shift == null ? null : lift(shift);
|
||||
}
|
||||
|
||||
private static Field.Curve curve(Field.Curve curve) {
|
||||
List<Field.Knot> knots = new ArrayList<>(curve.knots().size());
|
||||
for (Field.Knot knot : curve.knots()) {
|
||||
Field value = knot.value() instanceof Field.Curve nested ? curve(nested) : knot.value();
|
||||
knots.add(new Field.Knot(knot.location(), value, knot.derivative()));
|
||||
}
|
||||
return new Field.Curve(lift(curve.input()), knots);
|
||||
}
|
||||
|
||||
private static List<Field> liftAll(List<Field> fields) {
|
||||
List<Field> lifted = new ArrayList<>(fields.size());
|
||||
for (Field field : fields) {
|
||||
lifted.add(lift(field));
|
||||
}
|
||||
return lifted;
|
||||
}
|
||||
|
||||
private static Field shared(Field.Shared shared) {
|
||||
Field body = lift(shared.expr());
|
||||
return body.equals(shared.expr()) ? shared : new Field.Shared(shared.name() + SHARED_SUFFIX, body);
|
||||
}
|
||||
}
|
||||
-114
@@ -1,114 +0,0 @@
|
||||
package art.arcane.iris.pack.datapack.export.compile.cave;
|
||||
|
||||
import art.arcane.iris.pack.datapack.DataVersion;
|
||||
import art.arcane.iris.pack.datapack.export.ir.FieldEvaluator;
|
||||
import art.arcane.iris.pack.datapack.export.ir.NoiseDef;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.SplittableRandom;
|
||||
|
||||
final class WallShellCalibrator {
|
||||
private static final long SEED = 0x5EED_3A11L;
|
||||
private static final int PATCHES = 256;
|
||||
private static final int PATCH_CELLS = 3;
|
||||
private static final int SPREAD_CELLS = 1024;
|
||||
|
||||
private final Map<String, NoiseDef> noises;
|
||||
private final DataVersion target;
|
||||
private final int cellXZ;
|
||||
private final int cellY;
|
||||
private double[] solid = new double[4096];
|
||||
private int solidCount;
|
||||
private long walls;
|
||||
|
||||
private WallShellCalibrator(Map<String, NoiseDef> noises, DataVersion target, int cellXZ, int cellY) {
|
||||
this.noises = noises;
|
||||
this.target = target;
|
||||
this.cellXZ = cellXZ;
|
||||
this.cellY = cellY;
|
||||
}
|
||||
|
||||
static double band(CaveInterior interior, Map<String, NoiseDef> noises, DataVersion target) {
|
||||
WallShellCalibrator calibrator = new WallShellCalibrator(noises, target, CaveFieldCompiler.CELL_XZ, CaveFieldCompiler.CELL_Y);
|
||||
SplittableRandom random = new SplittableRandom(SEED);
|
||||
for (int patch = 0; patch < PATCHES; patch++) {
|
||||
calibrator.sample(interior, random);
|
||||
}
|
||||
return calibrator.band();
|
||||
}
|
||||
|
||||
private void sample(CaveInterior interior, SplittableRandom random) {
|
||||
int x0 = cellXZ * (random.nextInt(2 * SPREAD_CELLS) - SPREAD_CELLS);
|
||||
int z0 = cellXZ * (random.nextInt(2 * SPREAD_CELLS) - SPREAD_CELLS);
|
||||
int lowCell = Math.floorDiv(interior.minY(), cellY);
|
||||
int highCell = Math.max(lowCell, Math.floorDiv(interior.maxY(), cellY) - PATCH_CELLS);
|
||||
int y0 = cellY * (lowCell + random.nextInt(highCell - lowCell + 1));
|
||||
int corners = PATCH_CELLS + 1;
|
||||
double[][][] lattice = new double[corners][corners][corners];
|
||||
for (int i = 0; i < corners; i++) {
|
||||
for (int j = 0; j < corners; j++) {
|
||||
for (int k = 0; k < corners; k++) {
|
||||
lattice[i][j][k] = FieldEvaluator.sample(interior.field(), noises, SEED, target, x0 + i * cellXZ, y0 + j * cellY, z0 + k * cellXZ);
|
||||
}
|
||||
}
|
||||
}
|
||||
int width = PATCH_CELLS * cellXZ;
|
||||
int height = PATCH_CELLS * cellY;
|
||||
double[][][] voxels = new double[width][height][width];
|
||||
for (int x = 0; x < width; x++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int z = 0; z < width; z++) {
|
||||
voxels[x][y][z] = interpolate(lattice, x, y, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int x = 1; x < width - 1; x++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int z = 1; z < width - 1; z++) {
|
||||
double value = voxels[x][y][z];
|
||||
if (value < 0.0) {
|
||||
continue;
|
||||
}
|
||||
add(value);
|
||||
if (voxels[x - 1][y][z] < 0.0 || voxels[x + 1][y][z] < 0.0 || voxels[x][y][z - 1] < 0.0 || voxels[x][y][z + 1] < 0.0) {
|
||||
walls++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private double interpolate(double[][][] lattice, int x, int y, int z) {
|
||||
int i = x / cellXZ;
|
||||
int j = y / cellY;
|
||||
int k = z / cellXZ;
|
||||
double fx = (x - i * cellXZ) / (double) cellXZ;
|
||||
double fy = (y - j * cellY) / (double) cellY;
|
||||
double fz = (z - k * cellXZ) / (double) cellXZ;
|
||||
double bottom = lerp(fz, lerp(fx, lattice[i][j][k], lattice[i + 1][j][k]), lerp(fx, lattice[i][j][k + 1], lattice[i + 1][j][k + 1]));
|
||||
double top = lerp(fz, lerp(fx, lattice[i][j + 1][k], lattice[i + 1][j + 1][k]), lerp(fx, lattice[i][j + 1][k + 1], lattice[i + 1][j + 1][k + 1]));
|
||||
return lerp(fy, bottom, top);
|
||||
}
|
||||
|
||||
private void add(double value) {
|
||||
if (solidCount == solid.length) {
|
||||
solid = Arrays.copyOf(solid, solid.length * 2);
|
||||
}
|
||||
solid[solidCount++] = value;
|
||||
}
|
||||
|
||||
private double band() {
|
||||
if (walls == 0L) {
|
||||
return 0.0;
|
||||
}
|
||||
double[] sorted = Arrays.copyOf(solid, solidCount);
|
||||
Arrays.sort(sorted);
|
||||
int rank = (int) Math.min(solidCount - 1L, walls);
|
||||
return sorted[rank];
|
||||
}
|
||||
|
||||
private static double lerp(double delta, double start, double end) {
|
||||
return start + delta * (end - start);
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@ public enum ExportLimit {
|
||||
IMAGE_MAP,
|
||||
DIMENSION_HEIGHT,
|
||||
NOISE_STYLE,
|
||||
LAVA_HEIGHT,
|
||||
BIOME_VARIANT,
|
||||
SHORE_WIDTH,
|
||||
VANILLA_BIOME_DATA,
|
||||
@@ -47,7 +46,7 @@ public enum ExportLimit {
|
||||
VANILLA_STRUCTURE_DATA,
|
||||
JIGSAW_STRUCTURE,
|
||||
TRIMMED_CONTENT,
|
||||
DEEP_CAVE_LAYERS,
|
||||
LISTED_CAVES,
|
||||
GENERATION_COST,
|
||||
SUBTERRAIN_BIOME,
|
||||
SUBTERRAIN_VARIANT,
|
||||
|
||||
+19
-102
@@ -1,16 +1,12 @@
|
||||
package art.arcane.iris.pack.datapack.export.compile.cave;
|
||||
|
||||
import art.arcane.iris.generation.cave.IrisCaveProfile;
|
||||
import art.arcane.iris.pack.datapack.export.ExportTestPacks;
|
||||
import art.arcane.iris.pack.datapack.export.compile.PackCompileContext;
|
||||
import art.arcane.iris.pack.datapack.export.ir.AquiferDef;
|
||||
import art.arcane.iris.pack.datapack.export.ir.Axis;
|
||||
import art.arcane.iris.pack.datapack.export.ir.ExportDiagnostic;
|
||||
import art.arcane.iris.pack.datapack.export.ir.ExportLimit;
|
||||
import art.arcane.iris.pack.datapack.export.ir.Field;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.testsupport.PlatformLeakGuard;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Rule;
|
||||
@@ -22,7 +18,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class AquiferCompilerTest {
|
||||
@@ -38,9 +33,6 @@ public class AquiferCompilerTest {
|
||||
private static final int FLUID_HEIGHT = 63;
|
||||
private static final double FULLY_FLOODED = 0.8;
|
||||
private static final double DRY = -1.0;
|
||||
private static final double PARTIAL = 0.6;
|
||||
private static final int FLUID_BAND_HEIGHT = 40;
|
||||
private static final int FLUID_BAND_CENTER = 20;
|
||||
|
||||
@ClassRule
|
||||
public static final PlatformLeakGuard PLATFORM_GUARD = PlatformLeakGuard.clean();
|
||||
@@ -52,8 +44,8 @@ public class AquiferCompilerTest {
|
||||
public ExportTestPacks.BoundPlatform platform = new ExportTestPacks.BoundPlatform();
|
||||
|
||||
@Test
|
||||
public void dryProfilesHaveNegativeFloodedness() throws Exception {
|
||||
PackCompileContext context = compile(CaveTestPacks.dimension(20), CaveTestPacks.constantProfile(-0.1));
|
||||
public void rockAwayFromOpenWaterIsDryAndTheRestIsVanilla() throws Exception {
|
||||
PackCompileContext context = compile(CaveTestPacks.dimension(20), SURFACE, SURFACE);
|
||||
|
||||
AquiferDef aquifer = context.aquifer();
|
||||
AquiferDef vanilla = AquiferDef.dry(SURFACE);
|
||||
@@ -67,9 +59,19 @@ public class AquiferCompilerTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void listedCavesDoNotChangeTheAquifer() throws Exception {
|
||||
JsonObject withCaves = CaveTestPacks.listing(CaveTestPacks.dimension(20), List.of("tunnels"));
|
||||
|
||||
PackCompileContext context = compile(withCaves, SEA_FLOOR_SLOPE, SEA_FLOOR_SLOPE);
|
||||
PackCompileContext without = compile(CaveTestPacks.dimension(20), SEA_FLOOR_SLOPE, SEA_FLOOR_SLOPE);
|
||||
|
||||
assertEquals(without.aquifer(), context.aquifer());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void openWaterAboveTheTerrainFloodsToSeaLevel() throws Exception {
|
||||
PackCompileContext context = compile(CaveTestPacks.dimension(20), CaveTestPacks.constantProfile(-0.1), SEA_FLOOR_SLOPE, SEA_FLOOR_SLOPE);
|
||||
PackCompileContext context = compile(CaveTestPacks.dimension(20), SEA_FLOOR_SLOPE, SEA_FLOOR_SLOPE);
|
||||
|
||||
Field floodedness = context.aquifer().floodedness();
|
||||
assertTrue(CaveTestPacks.sample(floodedness, context.noises(), SEA_X, SEA_FLOOR + 1, 4) > FULLY_FLOODED);
|
||||
@@ -83,7 +85,7 @@ public class AquiferCompilerTest {
|
||||
|
||||
@Test
|
||||
public void openWaterLiftStaysNearSeaLevel() throws Exception {
|
||||
PackCompileContext context = compile(CaveTestPacks.dimension(20), CaveTestPacks.constantProfile(-0.1), SEA_FLOOR_SLOPE, SEA_FLOOR_SLOPE);
|
||||
PackCompileContext context = compile(CaveTestPacks.dimension(20), SEA_FLOOR_SLOPE, SEA_FLOOR_SLOPE);
|
||||
|
||||
Field floodedness = context.aquifer().floodedness();
|
||||
assertEquals(DRY, CaveTestPacks.sample(floodedness, context.noises(), DEEP_SEA_X, FLUID_HEIGHT - 40, 4), 0.0);
|
||||
@@ -93,7 +95,7 @@ public class AquiferCompilerTest {
|
||||
|
||||
@Test
|
||||
public void openWaterLiftStopsAtTheShore() throws Exception {
|
||||
PackCompileContext context = compile(CaveTestPacks.dimension(20), CaveTestPacks.constantProfile(-0.1), SEA_FLOOR_SLOPE, SEA_FLOOR_SLOPE);
|
||||
PackCompileContext context = compile(CaveTestPacks.dimension(20), SEA_FLOOR_SLOPE, SEA_FLOOR_SLOPE);
|
||||
|
||||
Field floodedness = context.aquifer().floodedness();
|
||||
assertTrue(CaveTestPacks.sample(floodedness, context.noises(), SHORE_X, FLUID_HEIGHT, 4) > FULLY_FLOODED);
|
||||
@@ -102,94 +104,16 @@ public class AquiferCompilerTest {
|
||||
|
||||
@Test
|
||||
public void openWaterLiftSkipsColumnsWithAHighSurfaceEstimate() throws Exception {
|
||||
PackCompileContext context = compile(CaveTestPacks.dimension(20), CaveTestPacks.constantProfile(-0.1), SEA_FLOOR_SLOPE, HIGH_ESTIMATE);
|
||||
PackCompileContext context = compile(CaveTestPacks.dimension(20), SEA_FLOOR_SLOPE, HIGH_ESTIMATE);
|
||||
|
||||
assertEquals(DRY, CaveTestPacks.sample(context.aquifer().floodedness(), context.noises(), SEA_X, SEA_FLOOR + 1, 4), 0.0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void wetCavesBelowTheTerrainKeepPartialFlooding() throws Exception {
|
||||
PackCompileContext context = compile(CaveTestPacks.dimension(20), CaveTestPacks.constantProfile(-0.1).setAllowFluid(true), SEA_FLOOR_SLOPE, SEA_FLOOR_SLOPE);
|
||||
|
||||
Field floodedness = context.aquifer().floodedness();
|
||||
assertTrue(CaveTestPacks.sample(floodedness, context.noises(), SEA_X, SEA_FLOOR + 6, 4) > FULLY_FLOODED);
|
||||
assertEquals(PARTIAL, CaveTestPacks.sample(floodedness, context.noises(), SEA_X, SEA_FLOOR - 24, 4), 1.0e-6);
|
||||
assertEquals(PARTIAL, CaveTestPacks.sample(floodedness, context.noises(), LAND_X, FLUID_HEIGHT - 10, 4), 1.0e-6);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lavaAboveMinus10ReportsLimit() throws Exception {
|
||||
PackCompileContext context = compile(CaveTestPacks.dimension(60), CaveTestPacks.constantProfile(-0.1).setAllowLava(true));
|
||||
|
||||
List<ExportDiagnostic> limits = context.diagnostics().stream().filter(diagnostic -> diagnostic.limit() == ExportLimit.LAVA_HEIGHT).toList();
|
||||
assertEquals(1, limits.size());
|
||||
assertEquals("dimensions/" + ExportTestPacks.DIMENSION, limits.getFirst().resource());
|
||||
for (int y = CaveTestPacks.MIN_Y; y < 0; y += 4) {
|
||||
assertEquals(DRY, CaveTestPacks.sample(context.aquifer().floodedness(), context.noises(), 3, y, 5), 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lavaFillsToProfileLavaHeight() throws Exception {
|
||||
int lavaY = CaveTestPacks.MIN_Y + 20;
|
||||
PackCompileContext context = compile(CaveTestPacks.dimension(20), CaveTestPacks.constantProfile(-0.1).setAllowLava(true));
|
||||
|
||||
AquiferDef aquifer = context.aquifer();
|
||||
assertFalse(context.diagnostics().stream().anyMatch(diagnostic -> diagnostic.limit() == ExportLimit.LAVA_HEIGHT));
|
||||
assertEquals(PARTIAL, CaveTestPacks.sample(aquifer.floodedness(), context.noises(), 4, lavaY - 6, 4), 1.0e-6);
|
||||
assertEquals(PARTIAL, CaveTestPacks.sample(aquifer.floodedness(), context.noises(), 4, lavaY + 12, 4), 1.0e-6);
|
||||
assertEquals(DRY, CaveTestPacks.sample(aquifer.floodedness(), context.noises(), 4, lavaY + 13, 4), 0.0);
|
||||
assertEquals(DRY, CaveTestPacks.sample(aquifer.floodedness(), context.noises(), 4, 40, 4), 0.0);
|
||||
int lavaBand = Math.floorDiv(lavaY + 12, FLUID_BAND_HEIGHT);
|
||||
for (int band = Math.floorDiv(CaveTestPacks.MIN_Y, FLUID_BAND_HEIGHT); band <= lavaBand; band++) {
|
||||
double spread = CaveTestPacks.sample(aquifer.spread(), context.noises(), 7, band, -2);
|
||||
int level = band * FLUID_BAND_HEIGHT + FLUID_BAND_CENTER + (int) Math.floor(spread * 10.0 / 3.0) * 3;
|
||||
assertTrue("band " + band + " level " + level, level <= lavaY && level >= lavaY - 2);
|
||||
assertTrue(Math.abs(CaveTestPacks.sample(aquifer.lava(), context.noises(), 7, band, -2)) > 0.3);
|
||||
}
|
||||
assertTrue(Math.abs(CaveTestPacks.sample(aquifer.lava(), context.noises(), 7, lavaBand + 1, -2)) <= 0.3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void wetProfilesFloodBelowSeaLevel() throws Exception {
|
||||
PackCompileContext context = compile(CaveTestPacks.dimension(20), CaveTestPacks.constantProfile(-0.1).setAllowFluid(true));
|
||||
|
||||
assertEquals(PARTIAL, CaveTestPacks.sample(context.aquifer().floodedness(), context.noises(), 4, 30, 4), 1.0e-6);
|
||||
assertEquals(DRY, CaveTestPacks.sample(context.aquifer().floodedness(), context.noises(), 4, 100, 4), 0.0);
|
||||
assertEquals(0.0, CaveTestPacks.sample(context.aquifer().lava(), context.noises(), 4, 0, 4), 0.0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bandProfileDecidesFloodednessInsideItsBand() throws Exception {
|
||||
JsonObject dimension = CaveTestPacks.dimension(20);
|
||||
JsonArray carving = new JsonArray();
|
||||
carving.add(CaveTestPacks.band("deep-band", "cave-band", -60, -30));
|
||||
dimension.add("carving", carving);
|
||||
File pack = CaveTestPacks.pack(temporaryFolder.newFolder("pack"), dimension, CaveTestPacks.region(List.of("cave-dry"), null),
|
||||
Map.of("cave-dry", CaveTestPacks.constantProfile(-0.1), "cave-band", CaveTestPacks.constantProfile(-0.1).setAllowLava(true)));
|
||||
private PackCompileContext compile(JsonObject dimension, Field height, Field estimate) throws Exception {
|
||||
File pack = CaveTestPacks.pack(temporaryFolder.newFolder(), dimension, CaveTestPacks.region(), Map.of("tunnels", CaveTestPacks.LISTED_CAVE));
|
||||
IrisData data = IrisData.openRuntime(pack);
|
||||
try {
|
||||
PackCompileContext context = context(data, "cave-dry");
|
||||
|
||||
new CaveStage().apply(context);
|
||||
|
||||
assertEquals(PARTIAL, CaveTestPacks.sample(context.aquifer().floodedness(), context.noises(), 4, -50, 4), 1.0e-6);
|
||||
assertEquals(DRY, CaveTestPacks.sample(context.aquifer().floodedness(), context.noises(), 4, -62, 4), 0.0);
|
||||
} finally {
|
||||
data.close();
|
||||
}
|
||||
}
|
||||
|
||||
private PackCompileContext compile(JsonObject dimension, IrisCaveProfile profile) throws Exception {
|
||||
return compile(dimension, profile, SURFACE, SURFACE);
|
||||
}
|
||||
|
||||
private PackCompileContext compile(JsonObject dimension, IrisCaveProfile profile, Field height, Field estimate) throws Exception {
|
||||
File pack = CaveTestPacks.pack(temporaryFolder.newFolder("pack"), dimension, CaveTestPacks.region(List.of("cave-only"), null),
|
||||
Map.of("cave-only", profile));
|
||||
IrisData data = IrisData.openRuntime(pack);
|
||||
try {
|
||||
PackCompileContext context = context(data, "cave-only");
|
||||
PackCompileContext context = CaveTestPacks.context(data, FakeCaveStyles.volumetric());
|
||||
context.setHeight(height);
|
||||
context.setSurfaceEstimate(estimate);
|
||||
new CaveStage().apply(context);
|
||||
@@ -198,11 +122,4 @@ public class AquiferCompilerTest {
|
||||
data.close();
|
||||
}
|
||||
}
|
||||
|
||||
private static PackCompileContext context(IrisData data, String caveBiome) {
|
||||
PackCompileContext context = CaveTestPacks.context(data, FakeCaveStyles.volumetric());
|
||||
context.setHeight(SURFACE);
|
||||
context.setBiomeCodes(CaveTestPacks.codes(CaveTestPacks.xGradient(), List.of(new CaveTestPacks.CodeRange(caveBiome, -1.0, 1.0))));
|
||||
return context;
|
||||
}
|
||||
}
|
||||
-550
@@ -1,550 +0,0 @@
|
||||
package art.arcane.iris.pack.datapack.export.compile.cave;
|
||||
|
||||
import art.arcane.iris.generation.cave.IrisCaveProfile;
|
||||
import art.arcane.iris.generation.noise.IrisStyledRange;
|
||||
import art.arcane.iris.generation.noise.NoiseStyle;
|
||||
import art.arcane.iris.pack.datapack.DataVersion;
|
||||
import art.arcane.iris.pack.datapack.export.ExportTestPacks;
|
||||
import art.arcane.iris.pack.datapack.export.compile.PackCompileContext;
|
||||
import art.arcane.iris.pack.datapack.export.ir.AquiferDef;
|
||||
import art.arcane.iris.pack.datapack.export.ir.Axis;
|
||||
import art.arcane.iris.pack.datapack.export.ir.CostClass;
|
||||
import art.arcane.iris.pack.datapack.export.ir.ExportDiagnostic;
|
||||
import art.arcane.iris.pack.datapack.export.ir.ExportLimit;
|
||||
import art.arcane.iris.pack.datapack.export.ir.Field;
|
||||
import art.arcane.iris.pack.datapack.export.ir.FieldEvaluator;
|
||||
import art.arcane.iris.pack.datapack.export.ir.NoiseDef;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.pack.value.IrisRange;
|
||||
import art.arcane.iris.testsupport.PlatformLeakGuard;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class CaveFieldCompilerTest {
|
||||
private static final Field DEEP_SURFACE = new Field.Const(150.0);
|
||||
private static final double OPEN_SHARE_THRESHOLD = 0.15;
|
||||
private static final int BAND_HEIGHT = 16;
|
||||
private static final int FINE_ORIGIN_X = -900;
|
||||
private static final int BROAD_ORIGIN_X = 120;
|
||||
private static final int SHELL_BOXES = 6;
|
||||
private static final int SHELL_BOX = 24;
|
||||
private static final int SHELL_BOX_HEIGHT = 48;
|
||||
private static final int SHELL_BOX_Y = -40;
|
||||
private static final int SHELL_BOX_STEP_X = 130;
|
||||
private static final int SHELL_BOX_STEP_Z = 230;
|
||||
private static final long MIN_WALLS = 200L;
|
||||
private static final double SHELL_TOLERANCE = 0.2;
|
||||
|
||||
@ClassRule
|
||||
public static final PlatformLeakGuard PLATFORM_GUARD = PlatformLeakGuard.clean();
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
|
||||
@Rule
|
||||
public ExportTestPacks.BoundPlatform platform = new ExportTestPacks.BoundPlatform();
|
||||
|
||||
@Test
|
||||
public void profileSelectedByCaveCode() throws Exception {
|
||||
File pack = CaveTestPacks.pack(temporaryFolder.newFolder("pack"), CaveTestPacks.dimension(8),
|
||||
CaveTestPacks.region(List.of("cave-open", "cave-closed"), null),
|
||||
Map.of("cave-open", CaveTestPacks.constantProfile(5.0), "cave-closed", CaveTestPacks.constantProfile(-5.0)));
|
||||
IrisData data = IrisData.openRuntime(pack);
|
||||
try {
|
||||
PackCompileContext context = deepContext(data, FakeCaveStyles.volumetric(), List.of(
|
||||
new CaveTestPacks.CodeRange("cave-open", -1.0, 0.0),
|
||||
new CaveTestPacks.CodeRange("cave-closed", 0.0, 1.0)));
|
||||
|
||||
new CaveStage().apply(context);
|
||||
|
||||
Field caves = context.caves();
|
||||
assertTrue(CaveTestPacks.caveField(caves) instanceof Field.Grid);
|
||||
assertTrue(((Field.Grid) CaveTestPacks.caveField(caves)).expr() instanceof Field.Mux);
|
||||
assertTrue(CaveTestPacks.sample(caves, context.noises(), -500, 0, 0) <= 0.0);
|
||||
assertTrue(CaveTestPacks.sample(caves, context.noises(), 500, 0, 0) > 0.0);
|
||||
} finally {
|
||||
data.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void uncoveredCaveCodesUseTheDimensionProfile() throws Exception {
|
||||
JsonObject dimension = CaveTestPacks.dimension(8);
|
||||
dimension.add("caveProfile", CaveTestPacks.json(CaveTestPacks.constantProfile(5.0)));
|
||||
File pack = CaveTestPacks.pack(temporaryFolder.newFolder("pack"), dimension,
|
||||
CaveTestPacks.region(List.of("cave-closed"), null),
|
||||
Map.of("cave-closed", CaveTestPacks.constantProfile(-5.0)));
|
||||
IrisData data = IrisData.openRuntime(pack);
|
||||
try {
|
||||
PackCompileContext context = deepContext(data, FakeCaveStyles.volumetric(), List.of(
|
||||
new CaveTestPacks.CodeRange("cave-closed", 0.0, 1.0)));
|
||||
|
||||
new CaveStage().apply(context);
|
||||
|
||||
assertTrue(CaveTestPacks.sample(context.caves(), context.noises(), -500, 0, 0) <= 0.0);
|
||||
assertTrue(CaveTestPacks.sample(context.caves(), context.noises(), 500, 0, 0) > 0.0);
|
||||
} finally {
|
||||
data.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void wallShellBandHoldsTheOneBlockWallOfTheCaveField() throws Exception {
|
||||
File pack = CaveTestPacks.pack(temporaryFolder.newFolder("pack"), CaveTestPacks.dimension(8),
|
||||
CaveTestPacks.region(List.of("cave-noise"), null), Map.of("cave-noise", CaveTestPacks.profile()));
|
||||
IrisData data = IrisData.openRuntime(pack);
|
||||
try {
|
||||
PackCompileContext context = deepContext(data, FakeCaveStyles.volumetric(), List.of(new CaveTestPacks.CodeRange("cave-noise", -1.0, 1.0)));
|
||||
|
||||
new CaveStage().apply(context);
|
||||
|
||||
double band = context.wallShellBand();
|
||||
Field field = context.caveField().orElseThrow();
|
||||
long solid = 0L;
|
||||
long walls = 0L;
|
||||
long shell = 0L;
|
||||
for (int column = 0; column < 64; column++) {
|
||||
int x = 37 * column - 1200;
|
||||
int z = 53 * (column % 8) + 400;
|
||||
for (int y = -40; y < 120; y += 2) {
|
||||
double value = CaveTestPacks.sample(field, context.noises(), x, y, z);
|
||||
if (value < 0.0) {
|
||||
continue;
|
||||
}
|
||||
solid++;
|
||||
if (value < band) {
|
||||
shell++;
|
||||
}
|
||||
if (CaveTestPacks.sample(field, context.noises(), x + 1, y, z) < 0.0 || CaveTestPacks.sample(field, context.noises(), x - 1, y, z) < 0.0
|
||||
|| CaveTestPacks.sample(field, context.noises(), x, y, z + 1) < 0.0 || CaveTestPacks.sample(field, context.noises(), x, y, z - 1) < 0.0) {
|
||||
walls++;
|
||||
}
|
||||
}
|
||||
}
|
||||
assertTrue("band " + band, band > 0.0 && band < 0.5);
|
||||
assertTrue(walls + " walls of " + solid, walls > 50L);
|
||||
assertEquals("shell " + shell + " walls " + walls + " solid " + solid, 1.0, shell / (double) walls, 0.25);
|
||||
} finally {
|
||||
data.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void wallShellPaintsTheOneBlockWallOfEveryProfile() throws Exception {
|
||||
File pack = CaveTestPacks.pack(temporaryFolder.newFolder("pack"), CaveTestPacks.dimension(8),
|
||||
CaveTestPacks.region(List.of("cave-fine", "cave-broad"), null), Map.of(
|
||||
"cave-fine", CaveTestPacks.profile().setBaseDensityStyle(CaveTestPacks.style(NoiseStyle.SIMPLEX, 0.25)),
|
||||
"cave-broad", CaveTestPacks.profile().setBaseDensityStyle(CaveTestPacks.style(NoiseStyle.SIMPLEX, 1.5))));
|
||||
IrisData data = IrisData.openRuntime(pack);
|
||||
try {
|
||||
PackCompileContext context = deepContext(data, FakeCaveStyles.volumetric(), List.of(
|
||||
new CaveTestPacks.CodeRange("cave-fine", -1.0, 0.0),
|
||||
new CaveTestPacks.CodeRange("cave-broad", 0.0, 1.0)));
|
||||
|
||||
new CaveStage().apply(context);
|
||||
|
||||
Field field = context.caveField().orElseThrow();
|
||||
double band = context.wallShellBand();
|
||||
ShellCount fine = shellCount(field, context, band, FINE_ORIGIN_X);
|
||||
ShellCount broad = shellCount(field, context, band, BROAD_ORIGIN_X);
|
||||
assertTrue(fine.toString(), fine.walls() > MIN_WALLS);
|
||||
assertTrue(broad.toString(), broad.walls() > MIN_WALLS);
|
||||
assertEquals(fine.toString(), 1.0, fine.ratio(), SHELL_TOLERANCE);
|
||||
assertEquals(broad.toString(), 1.0, broad.ratio(), SHELL_TOLERANCE);
|
||||
} finally {
|
||||
data.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void caveBiomeWithoutProfileUsesItsRegionProfile() throws Exception {
|
||||
File pack = CaveTestPacks.pack(temporaryFolder.newFolder("pack"), CaveTestPacks.dimension(8),
|
||||
CaveTestPacks.region(List.of("cave-plain"), CaveTestPacks.constantProfile(5.0)),
|
||||
Map.of("cave-plain", new IrisCaveProfile()));
|
||||
IrisData data = IrisData.openRuntime(pack);
|
||||
try {
|
||||
PackCompileContext context = deepContext(data, FakeCaveStyles.volumetric(), List.of(
|
||||
new CaveTestPacks.CodeRange("cave-plain", -1.0, 1.0)));
|
||||
|
||||
new CaveStage().apply(context);
|
||||
|
||||
assertTrue(CaveTestPacks.sample(context.caves(), context.noises(), 300, 0, 0) <= 0.0);
|
||||
} finally {
|
||||
data.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void threeDimensionalCellularOnlyInsideGrid() throws Exception {
|
||||
IrisCaveProfile profile = CaveTestPacks.profile()
|
||||
.setBaseDensityStyle(CaveTestPacks.style(NoiseStyle.CELLULAR_IRIS_DOUBLE, 0.7))
|
||||
.setModules(new KList<>(List.of(CaveTestPacks.module(NoiseStyle.CELLULAR, 0.3, 0.0, false, new IrisRange(0, 256)))));
|
||||
File pack = CaveTestPacks.pack(temporaryFolder.newFolder("pack"), CaveTestPacks.dimension(8),
|
||||
CaveTestPacks.region(List.of("cave-cells"), null), Map.of("cave-cells", profile));
|
||||
IrisData data = IrisData.openRuntime(pack);
|
||||
try {
|
||||
PackCompileContext context = deepContext(data, FakeCaveStyles.expensiveCellular(), List.of(
|
||||
new CaveTestPacks.CodeRange("cave-cells", -1.0, 1.0)));
|
||||
|
||||
new CaveStage().apply(context);
|
||||
|
||||
List<Field.Noise> outside = new ArrayList<>();
|
||||
List<Field.Noise> inside = new ArrayList<>();
|
||||
collectCellular(context.caves(), false, inside, outside);
|
||||
assertFalse(inside.isEmpty());
|
||||
assertTrue(outside.toString(), outside.isEmpty());
|
||||
for (Field.Noise noise : inside) {
|
||||
assertTrue(noise.axes().contains(Axis.Y));
|
||||
assertEquals(CostClass.EXPENSIVE, noise.cost());
|
||||
}
|
||||
} finally {
|
||||
data.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lowWeightCellularModulesUseSmoothSubstitutes() throws Exception {
|
||||
IrisCaveProfile profile = CaveTestPacks.profile().setModules(new KList<>(List.of(
|
||||
CaveTestPacks.module(NoiseStyle.CELLULAR_BILINEAR, 0.05, 0.0, false, new IrisRange(0, 256)),
|
||||
CaveTestPacks.module(NoiseStyle.SIMPLEX_VASCULAR, 0.08, 0.1, true, new IrisRange(0, 256)),
|
||||
CaveTestPacks.module(NoiseStyle.VASCULAR, 0.2, 0.0, false, new IrisRange(0, 256)))));
|
||||
File pack = CaveTestPacks.pack(temporaryFolder.newFolder("pack"), CaveTestPacks.dimension(8),
|
||||
CaveTestPacks.region(List.of("cave-mixed"), null), Map.of("cave-mixed", profile));
|
||||
IrisData data = IrisData.openRuntime(pack);
|
||||
try {
|
||||
FakeCaveStyles styles = FakeCaveStyles.volumetric();
|
||||
PackCompileContext context = deepContext(data, styles, List.of(new CaveTestPacks.CodeRange("cave-mixed", -1.0, 1.0)));
|
||||
|
||||
new CaveStage().apply(context);
|
||||
|
||||
List<NoiseStyle> requests = styles.requests();
|
||||
assertFalse(requests.toString(), requests.contains(NoiseStyle.CELLULAR_BILINEAR));
|
||||
assertFalse(requests.toString(), requests.contains(NoiseStyle.SIMPLEX_VASCULAR));
|
||||
assertTrue(requests.toString(), requests.contains(NoiseStyle.VASCULAR));
|
||||
} finally {
|
||||
data.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void planarSmoothStylesLiftToVolume() throws Exception {
|
||||
IrisCaveProfile profile = CaveTestPacks.profile()
|
||||
.setDensityThreshold(new IrisStyledRange(-0.1, 0.1, CaveTestPacks.style(NoiseStyle.SIMPLEX, 1.0)));
|
||||
File pack = CaveTestPacks.pack(temporaryFolder.newFolder("pack"), CaveTestPacks.dimension(8),
|
||||
CaveTestPacks.region(List.of("cave-smooth"), null), Map.of("cave-smooth", profile));
|
||||
IrisData data = IrisData.openRuntime(pack);
|
||||
try {
|
||||
PackCompileContext context = deepContext(data, FakeCaveStyles.planar(), List.of(new CaveTestPacks.CodeRange("cave-smooth", -1.0, 1.0)));
|
||||
|
||||
new CaveStage().apply(context);
|
||||
|
||||
Field.Noise base = noiseContaining(context.caves(), "simplex_934447");
|
||||
Field.Noise threshold = noiseContaining(context.caves(), "simplex_489112");
|
||||
assertEquals(base.xzScale(), base.yScale(), 0.0);
|
||||
assertTrue(base.yScale() != 0.0);
|
||||
assertEquals(0.0, threshold.yScale(), 0.0);
|
||||
} finally {
|
||||
data.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void planarCellularStylesExportAsSmoothNoise() throws Exception {
|
||||
IrisCaveProfile profile = CaveTestPacks.profile().setBaseDensityStyle(CaveTestPacks.style(NoiseStyle.CELLULAR_IRIS_DOUBLE, 0.7));
|
||||
File pack = CaveTestPacks.pack(temporaryFolder.newFolder("pack"), CaveTestPacks.dimension(8),
|
||||
CaveTestPacks.region(List.of("cave-cells"), null), Map.of("cave-cells", profile));
|
||||
IrisData data = IrisData.openRuntime(pack);
|
||||
try {
|
||||
PackCompileContext context = deepContext(data, FakeCaveStyles.planar(), List.of(new CaveTestPacks.CodeRange("cave-cells", -1.0, 1.0)));
|
||||
|
||||
new CaveStage().apply(context);
|
||||
|
||||
Field.Noise base = noiseContaining(context.caves(), "simplex_934447");
|
||||
assertEquals(base.xzScale(), base.yScale(), 0.0);
|
||||
assertTrue(context.diagnostics().stream().anyMatch(diagnostic -> diagnostic.limit() == ExportLimit.NOISE_STYLE
|
||||
&& diagnostic.resource().equals("biomes/cave-cells")));
|
||||
} finally {
|
||||
data.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void caveOpenShareWithinThresholdPerBand() throws Exception {
|
||||
IrisCaveProfile profile = CaveTestPacks.profile()
|
||||
.setVerticalRange(new IrisRange(8, 240))
|
||||
.setVerticalEdgeFade(24)
|
||||
.setVerticalEdgeFadeStrength(0.2)
|
||||
.setDetailWeight(0.15)
|
||||
.setDensityThreshold(new IrisStyledRange(-0.15, 0.02, CaveTestPacks.style(NoiseStyle.SIMPLEX, 1.0)))
|
||||
.setThresholdBias(0.08)
|
||||
.setSurfaceClearance(6)
|
||||
.setAllowSurfaceBreak(true)
|
||||
.setSurfaceBreakStyle(CaveTestPacks.style(NoiseStyle.SIMPLEX, 0.08))
|
||||
.setSurfaceBreakNoiseThreshold(0.4)
|
||||
.setSurfaceBreakDepth(18)
|
||||
.setSurfaceBreakThresholdBoost(0.2)
|
||||
.setModules(new KList<>(List.of(
|
||||
CaveTestPacks.module(NoiseStyle.SIMPLEX, 0.08, 0.1, true, new IrisRange(20, 120)),
|
||||
CaveTestPacks.module(NoiseStyle.FRACTAL_FBM_SIMPLEX, 0.06, 0.0, false, new IrisRange(0, 256)))));
|
||||
File pack = CaveTestPacks.pack(temporaryFolder.newFolder("pack"), CaveTestPacks.dimension(8),
|
||||
CaveTestPacks.region(List.of("cave-real"), null), Map.of("cave-real", profile));
|
||||
IrisData data = IrisData.openRuntime(pack);
|
||||
try {
|
||||
FakeCaveStyles styles = FakeCaveStyles.volumetric();
|
||||
PackCompileContext context = CaveTestPacks.context(data, styles);
|
||||
Field height = rollingSurface(context);
|
||||
context.setHeight(height);
|
||||
context.setBiomeCodes(CaveTestPacks.codes(CaveTestPacks.xGradient(), List.of(new CaveTestPacks.CodeRange("cave-real", -1.0, 1.0))));
|
||||
|
||||
new CaveStage().apply(context);
|
||||
|
||||
IrisCaveReference reference = new IrisCaveReference(profile, styles, context.noises(), context.capabilities(), height);
|
||||
Field caves = context.caves();
|
||||
double referenceTotal = 0.0;
|
||||
int bands = 0;
|
||||
for (int bandMin = CaveTestPacks.MIN_Y; bandMin < CaveTestPacks.MAX_Y; bandMin += BAND_HEIGHT) {
|
||||
int compiledOpen = 0;
|
||||
int referenceOpen = 0;
|
||||
int samples = 0;
|
||||
for (int x = -300; x < 70; x += 37) {
|
||||
for (int z = -250; z < 120; z += 37) {
|
||||
for (int y = bandMin; y < bandMin + BAND_HEIGHT; y += 2) {
|
||||
if (CaveTestPacks.sample(caves, context.noises(), x, y, z) <= 0.0) {
|
||||
compiledOpen++;
|
||||
}
|
||||
if (reference.carved(x, y, z)) {
|
||||
referenceOpen++;
|
||||
}
|
||||
samples++;
|
||||
}
|
||||
}
|
||||
}
|
||||
double compiledShare = compiledOpen / (double) samples;
|
||||
double referenceShare = referenceOpen / (double) samples;
|
||||
assertEquals("band " + bandMin, referenceShare, compiledShare, OPEN_SHARE_THRESHOLD);
|
||||
referenceTotal += referenceShare;
|
||||
bands++;
|
||||
}
|
||||
assertTrue("reference carves nothing", referenceTotal / bands > 0.05);
|
||||
} finally {
|
||||
data.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deepDarkBandIsMinUnioned() throws Exception {
|
||||
JsonObject dimension = CaveTestPacks.dimension(8);
|
||||
JsonArray carving = new JsonArray();
|
||||
carving.add(CaveTestPacks.band("deep-band", "cave-band", -40, -20));
|
||||
dimension.add("carving", carving);
|
||||
File pack = CaveTestPacks.pack(temporaryFolder.newFolder("pack"), dimension,
|
||||
CaveTestPacks.region(List.of("cave-closed"), null),
|
||||
Map.of("cave-closed", CaveTestPacks.constantProfile(-5.0), "cave-band", CaveTestPacks.constantProfile(5.0)));
|
||||
IrisData data = IrisData.openRuntime(pack);
|
||||
try {
|
||||
PackCompileContext context = deepContext(data, FakeCaveStyles.volumetric(), List.of(new CaveTestPacks.CodeRange("cave-closed", -1.0, 1.0)));
|
||||
|
||||
new CaveStage().apply(context);
|
||||
|
||||
Field caves = context.caves();
|
||||
Field union = ((Field.Grid) CaveTestPacks.caveField(caves)).expr();
|
||||
assertTrue(union instanceof Field.Binary binary && binary.op() == Field.BinaryOp.MIN);
|
||||
assertTrue(CaveTestPacks.sample(caves, context.noises(), 40, -30, 40) <= 0.0);
|
||||
assertTrue(CaveTestPacks.sample(caves, context.noises(), 40, 0, 40) > 0.0);
|
||||
assertTrue(CaveTestPacks.sample(caves, context.noises(), 40, -60, 40) > 0.0);
|
||||
} finally {
|
||||
data.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void expensiveSubtreesOnlySelectedThroughMuxOrGate() throws Exception {
|
||||
IrisCaveProfile lava = demandingProfile().setAllowFluid(true);
|
||||
JsonObject dimension = CaveTestPacks.dimension(20);
|
||||
JsonArray carving = new JsonArray();
|
||||
carving.add(CaveTestPacks.band("deep-band", "cave-band", -50, -20));
|
||||
dimension.add("carving", carving);
|
||||
File pack = CaveTestPacks.pack(temporaryFolder.newFolder("pack"), dimension,
|
||||
CaveTestPacks.region(List.of("cave-lava", "cave-plain"), null),
|
||||
Map.of("cave-lava", lava, "cave-plain", CaveTestPacks.profile(), "cave-band", demandingProfile()));
|
||||
IrisData data = IrisData.openRuntime(pack);
|
||||
try {
|
||||
PackCompileContext context = CaveTestPacks.context(data, FakeCaveStyles.expensive());
|
||||
context.setHeight(warpedSurface(context));
|
||||
context.setBiomeCodes(CaveTestPacks.codes(CaveTestPacks.xGradient(), List.of(
|
||||
new CaveTestPacks.CodeRange("cave-lava", -1.0, 0.0),
|
||||
new CaveTestPacks.CodeRange("cave-plain", 0.0, 1.0))));
|
||||
|
||||
new CaveStage().apply(context);
|
||||
|
||||
AquiferDef aquifer = context.aquifer();
|
||||
List<Field> roots = List.of(context.caves(), aquifer.barrier(), aquifer.floodedness(), aquifer.spread(), aquifer.lava(), aquifer.exclusion());
|
||||
boolean expensive = false;
|
||||
boolean muxed = false;
|
||||
for (Field root : roots) {
|
||||
for (Field node : CaveTestPacks.nodes(root)) {
|
||||
expensive |= node.cost() == CostClass.EXPENSIVE;
|
||||
muxed |= node instanceof Field.Mux;
|
||||
for (Field child : CaveTestPacks.eagerChildren(node)) {
|
||||
assertTrue(node.getClass().getSimpleName() + " evaluates an expensive child eagerly", child.cost() != CostClass.EXPENSIVE);
|
||||
}
|
||||
}
|
||||
}
|
||||
assertTrue(expensive);
|
||||
assertTrue(muxed);
|
||||
} finally {
|
||||
data.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compiledCavesAreDeterministic() throws Exception {
|
||||
IrisCaveProfile profile = CaveTestPacks.profile()
|
||||
.setDensityThreshold(new IrisStyledRange(-0.15, 0.02, CaveTestPacks.style(NoiseStyle.SIMPLEX, 1.0)))
|
||||
.setAllowSurfaceBreak(true)
|
||||
.setAllowLava(true)
|
||||
.setModules(new KList<>(List.of(CaveTestPacks.module(NoiseStyle.SIMPLEX, 0.08, 0.1, true, new IrisRange(20, 120)))));
|
||||
File pack = CaveTestPacks.pack(temporaryFolder.newFolder("pack"), CaveTestPacks.dimension(20),
|
||||
CaveTestPacks.region(List.of("cave-one", "cave-two"), null),
|
||||
Map.of("cave-one", profile, "cave-two", CaveTestPacks.constantProfile(-0.2)));
|
||||
Compiled first = compileTwoCodes(pack);
|
||||
Compiled second = compileTwoCodes(pack);
|
||||
|
||||
assertEquals(first.caves(), second.caves());
|
||||
assertEquals(first.aquifer(), second.aquifer());
|
||||
assertEquals(first.noises(), second.noises());
|
||||
assertEquals(first.diagnostics(), second.diagnostics());
|
||||
}
|
||||
|
||||
private Compiled compileTwoCodes(File pack) throws IOException {
|
||||
IrisData data = IrisData.openRuntime(pack);
|
||||
try {
|
||||
PackCompileContext context = deepContext(data, FakeCaveStyles.volumetric(), List.of(
|
||||
new CaveTestPacks.CodeRange("cave-one", -1.0, 0.0),
|
||||
new CaveTestPacks.CodeRange("cave-two", 0.0, 1.0)));
|
||||
new CaveStage().apply(context);
|
||||
return new Compiled(context.caves(), context.aquifer(), context.noises().definitions(), List.copyOf(context.diagnostics()));
|
||||
} finally {
|
||||
data.close();
|
||||
}
|
||||
}
|
||||
|
||||
private static IrisCaveProfile demandingProfile() {
|
||||
return CaveTestPacks.profile()
|
||||
.setVerticalRange(new IrisRange(8, 240))
|
||||
.setVerticalEdgeFade(24)
|
||||
.setDetailWeight(0.15)
|
||||
.setDensityThreshold(new IrisStyledRange(-0.15, 0.02, CaveTestPacks.style(NoiseStyle.SIMPLEX, 1.0)))
|
||||
.setSurfaceClearance(6)
|
||||
.setAllowSurfaceBreak(true)
|
||||
.setAllowLava(true)
|
||||
.setModules(new KList<>(List.of(
|
||||
CaveTestPacks.module(NoiseStyle.SIMPLEX, 0.08, 0.1, true, new IrisRange(20, 120)),
|
||||
CaveTestPacks.module(NoiseStyle.CELLULAR, 0.3, 0.0, false, new IrisRange(0, 256)))));
|
||||
}
|
||||
|
||||
private static PackCompileContext deepContext(IrisData data, FakeCaveStyles styles, List<CaveTestPacks.CodeRange> ranges) {
|
||||
PackCompileContext context = CaveTestPacks.context(data, styles);
|
||||
context.setHeight(DEEP_SURFACE);
|
||||
context.setBiomeCodes(CaveTestPacks.codes(CaveTestPacks.xGradient(), ranges));
|
||||
return context;
|
||||
}
|
||||
|
||||
private static Field rollingSurface(PackCompileContext context) {
|
||||
String id = context.noises().register(new NoiseDef("cave_test/surface", 0, List.of(1.0)));
|
||||
Field noise = new Field.Noise(id, 1.0 / 128.0, 0.0, null, null, null);
|
||||
return new Field.Curve(noise, List.of(
|
||||
new Field.Knot(-1.0, new Field.Const(50.0), 20.0),
|
||||
new Field.Knot(1.0, new Field.Const(90.0), 20.0)));
|
||||
}
|
||||
|
||||
private static Field warpedSurface(PackCompileContext context) {
|
||||
String warp = context.noises().register(new NoiseDef("cave_test/surface_warp", 0, List.of(1.0)));
|
||||
String id = context.noises().register(new NoiseDef("cave_test/surface", 0, List.of(1.0)));
|
||||
Field shift = new Field.Noise(warp, 1.0 / 128.0, 0.0, null, null, null);
|
||||
Field noise = new Field.Shared("height", new Field.Noise(id, 1.0 / 128.0, 0.0, shift, null, shift));
|
||||
return new Field.Curve(noise, List.of(
|
||||
new Field.Knot(-1.0, new Field.Const(50.0), 20.0),
|
||||
new Field.Knot(1.0, new Field.Const(90.0), 20.0)));
|
||||
}
|
||||
|
||||
private static ShellCount shellCount(Field field, PackCompileContext context, double band, int originX) {
|
||||
Map<String, NoiseDef> noises = CaveTestPacks.noises(context.noises());
|
||||
long solid = 0L;
|
||||
long walls = 0L;
|
||||
long shell = 0L;
|
||||
for (int box = 0; box < SHELL_BOXES; box++) {
|
||||
int x0 = originX + box * SHELL_BOX_STEP_X;
|
||||
int z0 = box * SHELL_BOX_STEP_Z - SHELL_BOX_STEP_Z;
|
||||
double[][][] values = new double[SHELL_BOX][SHELL_BOX_HEIGHT][SHELL_BOX];
|
||||
for (int x = 0; x < SHELL_BOX; x++) {
|
||||
for (int y = 0; y < SHELL_BOX_HEIGHT; y++) {
|
||||
for (int z = 0; z < SHELL_BOX; z++) {
|
||||
values[x][y][z] = FieldEvaluator.sample(field, noises, CaveTestPacks.SEED, DataVersion.V26_3, x0 + x, SHELL_BOX_Y + y, z0 + z);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int x = 1; x < SHELL_BOX - 1; x++) {
|
||||
for (int y = 0; y < SHELL_BOX_HEIGHT; y++) {
|
||||
for (int z = 1; z < SHELL_BOX - 1; z++) {
|
||||
double value = values[x][y][z];
|
||||
if (value < 0.0) {
|
||||
continue;
|
||||
}
|
||||
solid++;
|
||||
if (value < band) {
|
||||
shell++;
|
||||
}
|
||||
if (values[x + 1][y][z] < 0.0 || values[x - 1][y][z] < 0.0 || values[x][y][z + 1] < 0.0 || values[x][y][z - 1] < 0.0) {
|
||||
walls++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return new ShellCount(solid, walls, shell);
|
||||
}
|
||||
|
||||
private static Field.Noise noiseContaining(Field root, String fragment) {
|
||||
for (Field node : CaveTestPacks.nodes(root)) {
|
||||
if (node instanceof Field.Noise noise && noise.noiseId().contains(fragment)) {
|
||||
return noise;
|
||||
}
|
||||
}
|
||||
throw new AssertionError("No noise containing '" + fragment + "' in " + root);
|
||||
}
|
||||
|
||||
private static void collectCellular(Field field, boolean insideGrid, List<Field.Noise> inside, List<Field.Noise> outside) {
|
||||
if (field instanceof Field.Noise noise && noise.noiseId().contains(FakeCaveStyles.CELLULAR_PREFIX)) {
|
||||
(insideGrid ? inside : outside).add(noise);
|
||||
}
|
||||
boolean childInside = insideGrid || field instanceof Field.Grid;
|
||||
for (Field child : CaveTestPacks.children(field)) {
|
||||
collectCellular(child, childInside, inside, outside);
|
||||
}
|
||||
}
|
||||
|
||||
private record Compiled(Field caves, AquiferDef aquifer, List<NoiseDef> noises, List<ExportDiagnostic> diagnostics) {
|
||||
}
|
||||
|
||||
private record ShellCount(long solid, long walls, long shell) {
|
||||
private double ratio() {
|
||||
return shell / (double) walls;
|
||||
}
|
||||
}
|
||||
}
|
||||
-96
@@ -1,96 +0,0 @@
|
||||
package art.arcane.iris.pack.datapack.export.compile.cave;
|
||||
|
||||
import art.arcane.iris.generation.cave.IrisCaveProfile;
|
||||
import art.arcane.iris.generation.noise.IrisStyledRange;
|
||||
import art.arcane.iris.generation.noise.NoiseStyle;
|
||||
import art.arcane.iris.pack.datapack.export.ExportTestPacks;
|
||||
import art.arcane.iris.pack.datapack.export.compile.PackCompileContext;
|
||||
import art.arcane.iris.pack.datapack.export.ir.Axis;
|
||||
import art.arcane.iris.pack.datapack.export.ir.Field;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.pack.value.IrisRange;
|
||||
import art.arcane.iris.testsupport.PlatformLeakGuard;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class CaveProfileCompilerTest {
|
||||
private static final double GAIN = 3.0;
|
||||
private static final double TOLERANCE = 1.0e-4;
|
||||
private static final int FLOOR = CaveTestPacks.MIN_Y + 8;
|
||||
private static final int CEILING = CaveTestPacks.MIN_Y + 240;
|
||||
private static final Field SLOPED_SURFACE = new Field.Coord(Axis.X, Field.Tiling.CLAMP, -200, 200, 60, 140);
|
||||
|
||||
@ClassRule
|
||||
public static final PlatformLeakGuard PLATFORM_GUARD = PlatformLeakGuard.clean();
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
|
||||
@Rule
|
||||
public ExportTestPacks.BoundPlatform platform = new ExportTestPacks.BoundPlatform();
|
||||
|
||||
@Test
|
||||
public void gainScalesTheFieldWithoutMovingItsCaves() throws Exception {
|
||||
IrisCaveProfile profile = CaveTestPacks.profile()
|
||||
.setVerticalRange(new IrisRange(8, 240))
|
||||
.setVerticalEdgeFade(24)
|
||||
.setVerticalEdgeFadeStrength(0.2)
|
||||
.setDetailWeight(0.15)
|
||||
.setDensityThreshold(new IrisStyledRange(-0.15, 0.02, CaveTestPacks.style(NoiseStyle.SIMPLEX, 1.0)))
|
||||
.setThresholdBias(0.08)
|
||||
.setSurfaceClearance(6)
|
||||
.setAllowSurfaceBreak(true)
|
||||
.setSurfaceBreakStyle(CaveTestPacks.style(NoiseStyle.SIMPLEX, 0.08))
|
||||
.setSurfaceBreakNoiseThreshold(0.4)
|
||||
.setSurfaceBreakDepth(18)
|
||||
.setSurfaceBreakThresholdBoost(0.1)
|
||||
.setModules(new KList<>(List.of(CaveTestPacks.module(NoiseStyle.SIMPLEX, 0.08, 0.1, true, new IrisRange(20, 120)))));
|
||||
File pack = CaveTestPacks.pack(temporaryFolder.newFolder("pack"), CaveTestPacks.dimension(8),
|
||||
CaveTestPacks.region(List.of("cave-gain"), null), Map.of("cave-gain", profile));
|
||||
IrisData data = IrisData.openRuntime(pack);
|
||||
try {
|
||||
PackCompileContext context = CaveTestPacks.context(data, FakeCaveStyles.volumetric());
|
||||
context.setHeight(SLOPED_SURFACE);
|
||||
CaveInputs inputs = CaveInputs.of(context);
|
||||
CaveProfileCompiler compiler = new CaveProfileCompiler(context.styles(), inputs);
|
||||
CaveSource source = new CaveSource("biomes/cave-gain", profile, inputs.minY(), inputs.maxY());
|
||||
|
||||
Field unit = compiler.compile(source, 1.0);
|
||||
Field scaled = compiler.compile(source, GAIN);
|
||||
|
||||
int caves = 0;
|
||||
for (int x = -240; x <= 240; x += 40) {
|
||||
for (int y = CaveTestPacks.MIN_Y; y < CaveTestPacks.MAX_Y; y += 5) {
|
||||
for (int z = -90; z <= 90; z += 60) {
|
||||
double expected = CaveTestPacks.sample(unit, context.noises(), x, y, z);
|
||||
double actual = CaveTestPacks.sample(scaled, context.noises(), x, y, z);
|
||||
if (y < FLOOR || y > CEILING) {
|
||||
assertEquals(x + "," + y + "," + z, CaveProfileCompiler.SOLID, expected, 0.0);
|
||||
assertEquals(x + "," + y + "," + z, CaveProfileCompiler.SOLID, actual, 0.0);
|
||||
continue;
|
||||
}
|
||||
assertEquals(x + "," + y + "," + z, GAIN * expected, actual, TOLERANCE * Math.max(1.0, Math.abs(actual)));
|
||||
if (expected < 0.0) {
|
||||
caves++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
assertTrue(String.valueOf(caves), caves > 0);
|
||||
assertThrows(IllegalArgumentException.class, () -> compiler.compile(source, 0.0));
|
||||
} finally {
|
||||
data.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
+54
-32
@@ -8,13 +8,14 @@ import art.arcane.iris.pack.datapack.export.compile.CompileStage;
|
||||
import art.arcane.iris.pack.datapack.export.compile.DimensionStage;
|
||||
import art.arcane.iris.pack.datapack.export.compile.PackCompileContext;
|
||||
import art.arcane.iris.pack.datapack.export.compile.PackCompiler;
|
||||
import art.arcane.iris.pack.datapack.export.compile.biome.BiomeStage;
|
||||
import art.arcane.iris.pack.datapack.export.ir.AquiferDef;
|
||||
import art.arcane.iris.pack.datapack.export.ir.BiomeDef;
|
||||
import art.arcane.iris.pack.datapack.export.ir.ExportDiagnostic;
|
||||
import art.arcane.iris.pack.datapack.export.ir.ExportIr;
|
||||
import art.arcane.iris.pack.datapack.export.ir.ExportLimit;
|
||||
import art.arcane.iris.pack.datapack.export.ir.Field;
|
||||
import art.arcane.iris.pack.datapack.export.ir.JsonResource;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.testsupport.CompatTestPlatform;
|
||||
import art.arcane.iris.testsupport.PlatformLeakGuard;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
@@ -32,11 +33,11 @@ import java.util.function.Consumer;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class CaveStageTest {
|
||||
private static final Field SURFACE = new Field.Const(120.0);
|
||||
private static final Field NO_CAVES = new Field.Const(1.0e6);
|
||||
|
||||
@ClassRule
|
||||
public static final PlatformLeakGuard PLATFORM_GUARD = PlatformLeakGuard.clean();
|
||||
@@ -50,14 +51,13 @@ public class CaveStageTest {
|
||||
@Test
|
||||
public void noVanillaCarversEmitted() throws Exception {
|
||||
File pack = CaveTestPacks.pack(temporaryFolder.newFolder("pack"), CaveTestPacks.dimension(8),
|
||||
CaveTestPacks.region(List.of("cave-open"), null), Map.of("cave-open", CaveTestPacks.constantProfile(0.1)));
|
||||
CaveTestPacks.region(), Map.of());
|
||||
IrisData data = IrisData.openRuntime(pack);
|
||||
try {
|
||||
CompileStage vanillaBiomes = new FixedStage("biomes", context -> {
|
||||
JsonObject body = JsonParser.parseString("{\"carvers\":[\"minecraft:cave\",\"minecraft:canyon\"],\"features\":[]}").getAsJsonObject();
|
||||
context.setBiomes(List.of(new BiomeDef(CaveTestPacks.SURFACE_BIOME, body), new BiomeDef("cave-open", body)));
|
||||
context.setHeight(SURFACE);
|
||||
context.setBiomeCodes(CaveTestPacks.codes(CaveTestPacks.xGradient(), List.of(new CaveTestPacks.CodeRange("cave-open", -1.0, 1.0))));
|
||||
});
|
||||
PackCompileContext context = ExportTestPacks.contextBuilder(data, DataVersion.V26_3).styles(FakeCaveStyles.volumetric()).build();
|
||||
|
||||
@@ -101,52 +101,74 @@ public class CaveStageTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void biomeStageCaveCodesSelectCaveProfiles() throws Exception {
|
||||
File pack = CaveTestPacks.pack(temporaryFolder.newFolder("pack"), CaveTestPacks.dimension(8),
|
||||
CaveTestPacks.region(List.of("cave-open"), null), Map.of("cave-open", CaveTestPacks.constantProfile(0.1)));
|
||||
public void aDimensionThatListsCavesExportsNoCavesAndSaysSoOnce() throws Exception {
|
||||
JsonObject dimension = CaveTestPacks.listing(CaveTestPacks.dimension(8), List.of("tunnels"));
|
||||
File pack = CaveTestPacks.pack(temporaryFolder.newFolder("pack"), dimension, CaveTestPacks.region(), Map.of("tunnels", CaveTestPacks.LISTED_CAVE));
|
||||
IrisData data = IrisData.openRuntime(pack);
|
||||
try {
|
||||
PackCompileContext context = CaveTestPacks.context(data, FakeCaveStyles.planar());
|
||||
context.setHeight(SURFACE);
|
||||
new BiomeStage().apply(context);
|
||||
PackCompileContext context = compile(data);
|
||||
|
||||
new CaveStage().apply(context);
|
||||
|
||||
assertNotEquals(new Field.Const(1.0e6), context.caves());
|
||||
assertEquals(NO_CAVES, context.caves());
|
||||
assertTrue(context.caveField().isEmpty());
|
||||
assertTrue(context.deepCaves().isEmpty());
|
||||
List<ExportDiagnostic> notExported = notExported(context);
|
||||
assertEquals(1, notExported.size());
|
||||
assertEquals(ExportDiagnostic.Severity.WARNING, notExported.getFirst().severity());
|
||||
assertEquals(CaveStage.LISTED_CAVES_NOT_EXPORTED, notExported.getFirst().message());
|
||||
} finally {
|
||||
data.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void disabledCarvingKeepsDefaultSlots() throws Exception {
|
||||
JsonObject dimension = CaveTestPacks.dimension(20);
|
||||
dimension.addProperty("carvingEnabled", false);
|
||||
File pack = CaveTestPacks.pack(temporaryFolder.newFolder("pack"), dimension,
|
||||
CaveTestPacks.region(List.of("cave-open"), null), Map.of("cave-open", CaveTestPacks.constantProfile(5.0).setAllowLava(true)));
|
||||
public void aRegionThatListsCavesIsReportedToo() throws Exception {
|
||||
JsonObject region = CaveTestPacks.listing(CaveTestPacks.region(), List.of("tunnels"));
|
||||
File pack = CaveTestPacks.pack(temporaryFolder.newFolder("pack"), CaveTestPacks.dimension(8), region, Map.of("tunnels", CaveTestPacks.LISTED_CAVE));
|
||||
IrisData data = IrisData.openRuntime(pack);
|
||||
try {
|
||||
PackCompileContext context = CaveTestPacks.context(data, FakeCaveStyles.volumetric());
|
||||
context.setHeight(SURFACE);
|
||||
context.setBiomeCodes(CaveTestPacks.codes(CaveTestPacks.xGradient(), List.of(new CaveTestPacks.CodeRange("cave-open", -1.0, 1.0))));
|
||||
assertEquals(1, notExported(compile(data)).size());
|
||||
} finally {
|
||||
data.close();
|
||||
}
|
||||
}
|
||||
|
||||
new CaveStage().apply(context);
|
||||
@Test
|
||||
public void aBiomeThatListsCavesIsReportedToo() throws Exception {
|
||||
File pack = CaveTestPacks.pack(temporaryFolder.newFolder("pack"), CaveTestPacks.dimension(8), CaveTestPacks.region(), Map.of("tunnels", CaveTestPacks.LISTED_CAVE));
|
||||
CompatTestPlatform.write(pack, "biomes/" + CaveTestPacks.SURFACE_BIOME + ".json", "{\"name\":\"Surface\",\"caves\":[\"tunnels\"]}");
|
||||
IrisData data = IrisData.openRuntime(pack);
|
||||
try {
|
||||
assertEquals(1, notExported(compile(data)).size());
|
||||
} finally {
|
||||
data.close();
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals(new Field.Const(1.0e6), context.caves());
|
||||
AquiferDef aquifer = context.aquifer();
|
||||
AquiferDef vanilla = AquiferDef.dry(SURFACE);
|
||||
assertEquals(vanilla.barrier(), aquifer.barrier());
|
||||
assertEquals(vanilla.spread(), aquifer.spread());
|
||||
assertEquals(vanilla.lava(), aquifer.lava());
|
||||
assertEquals(vanilla.exclusion(), aquifer.exclusion());
|
||||
assertEquals(vanilla.surfaceLevel(), aquifer.surfaceLevel());
|
||||
assertEquals(-1.0, CaveTestPacks.sample(aquifer.floodedness(), context.noises(), 4, 40, 4), 0.0);
|
||||
@Test
|
||||
public void aPackWithoutListedCavesReportsNothing() throws Exception {
|
||||
File pack = CaveTestPacks.pack(temporaryFolder.newFolder("pack"), CaveTestPacks.dimension(8), CaveTestPacks.region(), Map.of());
|
||||
IrisData data = IrisData.openRuntime(pack);
|
||||
try {
|
||||
PackCompileContext context = compile(data);
|
||||
|
||||
assertEquals(NO_CAVES, context.caves());
|
||||
assertTrue(context.diagnostics().isEmpty());
|
||||
} finally {
|
||||
data.close();
|
||||
}
|
||||
}
|
||||
|
||||
private PackCompileContext compile(IrisData data) {
|
||||
PackCompileContext context = CaveTestPacks.context(data, FakeCaveStyles.volumetric());
|
||||
context.setHeight(SURFACE);
|
||||
new CaveStage().apply(context);
|
||||
return context;
|
||||
}
|
||||
|
||||
private static List<ExportDiagnostic> notExported(PackCompileContext context) {
|
||||
return context.diagnostics().stream().filter(diagnostic -> diagnostic.limit() == ExportLimit.LISTED_CAVES).toList();
|
||||
}
|
||||
|
||||
private record FixedStage(String name, Consumer<PackCompileContext> action) implements CompileStage {
|
||||
@Override
|
||||
public void apply(PackCompileContext context) {
|
||||
|
||||
+11
-192
@@ -1,47 +1,32 @@
|
||||
package art.arcane.iris.pack.datapack.export.compile.cave;
|
||||
|
||||
import art.arcane.iris.generation.cave.IrisCaveFieldModule;
|
||||
import art.arcane.iris.generation.cave.IrisCaveProfile;
|
||||
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.generation.noise.IrisStyledRange;
|
||||
import art.arcane.iris.generation.noise.NoiseStyle;
|
||||
import art.arcane.iris.pack.datapack.DataVersion;
|
||||
import art.arcane.iris.pack.datapack.export.ExportTestPacks;
|
||||
import art.arcane.iris.pack.datapack.export.compile.DimensionStage;
|
||||
import art.arcane.iris.pack.datapack.export.compile.PackCompileContext;
|
||||
import art.arcane.iris.pack.datapack.export.compile.biome.BiomeCodes;
|
||||
import art.arcane.iris.pack.datapack.export.compile.noise.NoiseRegistry;
|
||||
import art.arcane.iris.pack.datapack.export.compile.noise.StyleCompiler;
|
||||
import art.arcane.iris.pack.datapack.export.ir.Axis;
|
||||
import art.arcane.iris.pack.datapack.export.ir.ClimateLayout;
|
||||
import art.arcane.iris.pack.datapack.export.ir.Field;
|
||||
import art.arcane.iris.pack.datapack.export.ir.FieldEvaluator;
|
||||
import art.arcane.iris.pack.datapack.export.ir.NoiseDef;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.pack.value.IrisRange;
|
||||
import art.arcane.iris.testsupport.CompatTestPlatform;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
|
||||
final class CaveTestPacks {
|
||||
static final String NAMESPACE = "iris_export";
|
||||
static final String SURFACE_BIOME = "surface";
|
||||
static final long SEED = 1337L;
|
||||
static final int MIN_Y = -64;
|
||||
static final int MAX_Y = 192;
|
||||
static final String LISTED_CAVE = "{\"tunnel\": {}}";
|
||||
private static final Gson GSON = new Gson();
|
||||
|
||||
private CaveTestPacks() {
|
||||
@@ -61,111 +46,39 @@ final class CaveTestPacks {
|
||||
return dimension;
|
||||
}
|
||||
|
||||
static JsonObject band(String id, String biome, int min, int max) {
|
||||
JsonObject range = new JsonObject();
|
||||
range.addProperty("min", min);
|
||||
range.addProperty("max", max);
|
||||
JsonObject entry = new JsonObject();
|
||||
entry.addProperty("id", id);
|
||||
entry.addProperty("biome", biome);
|
||||
entry.add("worldYRange", range);
|
||||
return entry;
|
||||
static JsonObject listing(JsonObject resource, List<String> caves) {
|
||||
JsonArray listed = new JsonArray();
|
||||
caves.forEach(listed::add);
|
||||
resource.add("caves", listed);
|
||||
return resource;
|
||||
}
|
||||
|
||||
static JsonObject region(List<String> caveBiomes, IrisCaveProfile profile) {
|
||||
static JsonObject region() {
|
||||
JsonArray surface = new JsonArray();
|
||||
surface.add(SURFACE_BIOME);
|
||||
JsonArray caves = new JsonArray();
|
||||
for (String key : caveBiomes) {
|
||||
caves.add(key);
|
||||
}
|
||||
JsonObject region = new JsonObject();
|
||||
region.add("landBiomes", surface);
|
||||
region.add("seaBiomes", surface.deepCopy());
|
||||
region.add("caveBiomes", caves);
|
||||
if (profile != null) {
|
||||
region.add("caveProfile", GSON.toJsonTree(profile));
|
||||
}
|
||||
return region;
|
||||
}
|
||||
|
||||
static File pack(File folder, JsonObject dimension, JsonObject region, Map<String, IrisCaveProfile> biomes) throws IOException {
|
||||
/** A pack with one region, one surface biome and a cave file for each entry of {@code caves}. */
|
||||
static File pack(File folder, JsonObject dimension, JsonObject region, Map<String, String> caves) throws IOException {
|
||||
CompatTestPlatform.write(folder, "dimensions/" + ExportTestPacks.DIMENSION + ".json", GSON.toJson(dimension));
|
||||
CompatTestPlatform.write(folder, "regions/region.json", GSON.toJson(region));
|
||||
CompatTestPlatform.write(folder, "biomes/" + SURFACE_BIOME + ".json", "{\"name\":\"Surface\"}");
|
||||
for (Map.Entry<String, IrisCaveProfile> entry : new TreeMap<>(biomes).entrySet()) {
|
||||
JsonObject biome = new JsonObject();
|
||||
biome.addProperty("name", entry.getKey());
|
||||
biome.add("caveProfile", GSON.toJsonTree(entry.getValue()));
|
||||
CompatTestPlatform.write(folder, "biomes/" + entry.getKey() + ".json", GSON.toJson(biome));
|
||||
for (Map.Entry<String, String> entry : new TreeMap<>(caves).entrySet()) {
|
||||
CompatTestPlatform.write(folder, "caves/" + entry.getKey() + ".json", entry.getValue());
|
||||
}
|
||||
return folder;
|
||||
}
|
||||
|
||||
static JsonElement json(IrisCaveProfile profile) {
|
||||
return GSON.toJsonTree(profile);
|
||||
}
|
||||
|
||||
static IrisCaveProfile profile() {
|
||||
return new IrisCaveProfile()
|
||||
.setEnabled(true)
|
||||
.setVerticalRange(new IrisRange(0, MAX_Y - MIN_Y))
|
||||
.setVerticalEdgeFade(0)
|
||||
.setBaseDensityStyle(style(NoiseStyle.SIMPLEX, 0.6))
|
||||
.setDetailDensityStyle(style(NoiseStyle.SIMPLEX, 0.3))
|
||||
.setBaseWeight(1.0)
|
||||
.setDetailWeight(0.0)
|
||||
.setDensityThreshold(new IrisStyledRange(0.0, 0.0, style(NoiseStyle.SIMPLEX, 1.0)))
|
||||
.setThresholdBias(0.0)
|
||||
.setSurfaceClearance(0)
|
||||
.setAllowSurfaceBreak(false)
|
||||
.setAllowFluid(false)
|
||||
.setAllowLava(false)
|
||||
.setModules(new KList<>());
|
||||
}
|
||||
|
||||
static IrisCaveProfile constantProfile(double threshold) {
|
||||
return profile().setDensityThreshold(new IrisStyledRange(threshold, threshold, style(NoiseStyle.SIMPLEX, 1.0)));
|
||||
}
|
||||
|
||||
static IrisCaveFieldModule module(NoiseStyle style, double weight, double threshold, boolean invert, IrisRange range) {
|
||||
return new IrisCaveFieldModule()
|
||||
.setStyle(style(style, 0.5))
|
||||
.setWeight(weight)
|
||||
.setThreshold(threshold)
|
||||
.setInvert(invert)
|
||||
.setVerticalRange(range);
|
||||
}
|
||||
|
||||
static IrisGeneratorStyle style(NoiseStyle style, double zoom) {
|
||||
return new IrisGeneratorStyle(style).zoomed(zoom);
|
||||
}
|
||||
|
||||
static PackCompileContext context(IrisData data, StyleCompiler styles) {
|
||||
PackCompileContext context = ExportTestPacks.contextBuilder(data, DataVersion.V26_3).styles(styles).build();
|
||||
new DimensionStage().apply(context);
|
||||
return context;
|
||||
}
|
||||
|
||||
static BiomeCodes codes(Field caveCode, List<CodeRange> ranges) {
|
||||
List<ClimateLayout.ClimateEntry> entries = new ArrayList<>();
|
||||
Map<String, String> loadKeys = new TreeMap<>();
|
||||
String surfaceId = NAMESPACE + ":" + SURFACE_BIOME;
|
||||
entries.add(new ClimateLayout.ClimateEntry(surfaceId, ClimateLayout.ClimateAxis.TEMPERATURE, -1.0, 1.0));
|
||||
loadKeys.put(surfaceId, SURFACE_BIOME);
|
||||
for (CodeRange range : ranges) {
|
||||
String id = NAMESPACE + ":" + range.loadKey();
|
||||
entries.add(new ClimateLayout.ClimateEntry(id, ClimateLayout.ClimateAxis.DEPTH, range.min(), range.max()));
|
||||
loadKeys.put(id, range.loadKey());
|
||||
}
|
||||
Field zero = new Field.Const(0.0);
|
||||
return new BiomeCodes(zero, caveCode, zero, new ClimateLayout(entries), loadKeys);
|
||||
}
|
||||
|
||||
static Field xGradient() {
|
||||
return new Field.Coord(Axis.X, Field.Tiling.CLAMP, -1000, 1000, -1.0, 1.0);
|
||||
}
|
||||
|
||||
static Map<String, NoiseDef> noises(NoiseRegistry registry) {
|
||||
Map<String, NoiseDef> noises = new TreeMap<>();
|
||||
for (NoiseDef definition : registry.definitions()) {
|
||||
@@ -177,98 +90,4 @@ final class CaveTestPacks {
|
||||
static double sample(Field field, NoiseRegistry registry, int x, int y, int z) {
|
||||
return FieldEvaluator.sample(field, noises(registry), SEED, DataVersion.V26_3, x, y, z);
|
||||
}
|
||||
|
||||
static List<Field> children(Field field) {
|
||||
List<Field> children = new ArrayList<>();
|
||||
switch (field) {
|
||||
case Field.Const ignored -> {
|
||||
}
|
||||
case Field.Coord ignored -> {
|
||||
}
|
||||
case Field.Ref ignored -> {
|
||||
}
|
||||
case Field.Noise noise -> {
|
||||
addPresent(children, noise.shiftX());
|
||||
addPresent(children, noise.shiftY());
|
||||
addPresent(children, noise.shiftZ());
|
||||
}
|
||||
case Field.Binary binary -> {
|
||||
children.add(binary.left());
|
||||
children.add(binary.right());
|
||||
}
|
||||
case Field.Unary unary -> children.add(unary.input());
|
||||
case Field.Clamp clamp -> children.add(clamp.input());
|
||||
case Field.Lerp lerp -> children.addAll(List.of(lerp.alpha(), lerp.first(), lerp.second()));
|
||||
case Field.Round round -> children.addAll(List.of(round.input(), round.multiple()));
|
||||
case Field.Curve curve -> {
|
||||
children.add(curve.input());
|
||||
for (Field.Knot knot : curve.knots()) {
|
||||
children.add(knot.value());
|
||||
}
|
||||
}
|
||||
case Field.Partition partition -> {
|
||||
children.add(partition.input());
|
||||
children.addAll(partition.leaves());
|
||||
}
|
||||
case Field.Mux mux -> {
|
||||
children.add(mux.index());
|
||||
children.addAll(mux.cases());
|
||||
}
|
||||
case Field.Gate gate -> children.addAll(List.of(gate.condition(), gate.expr()));
|
||||
case Field.RangeIf rangeIf -> children.addAll(List.of(rangeIf.input(), rangeIf.inRange(), rangeIf.outOfRange()));
|
||||
case Field.Grid grid -> children.add(grid.expr());
|
||||
case Field.Shared shared -> children.add(shared.expr());
|
||||
case Field.Slice slice -> children.add(slice.expr());
|
||||
case Field.TopSurface topSurface -> children.add(topSurface.density());
|
||||
}
|
||||
return children;
|
||||
}
|
||||
|
||||
static List<Field> eagerChildren(Field field) {
|
||||
return switch (field) {
|
||||
case Field.Partition partition -> {
|
||||
List<Field> children = new ArrayList<>();
|
||||
children.add(partition.input());
|
||||
children.addAll(partition.leaves());
|
||||
yield children;
|
||||
}
|
||||
case Field.RangeIf rangeIf -> List.of(rangeIf.input(), rangeIf.inRange(), rangeIf.outOfRange());
|
||||
case Field.Binary binary when binary.op() == Field.BinaryOp.MUL -> List.of(binary.left(), binary.right());
|
||||
case Field.Lerp lerp -> List.of(lerp.alpha(), lerp.first(), lerp.second());
|
||||
default -> List.of();
|
||||
};
|
||||
}
|
||||
|
||||
static Field caveField(Field caves) {
|
||||
Field field = caves instanceof Field.Binary binary && binary.op() == Field.BinaryOp.MAX ? binary.left() : caves;
|
||||
if (field instanceof Field.Shared shared && shared.name().equals(DeepCaveCompiler.FIELD)) {
|
||||
return shared.expr();
|
||||
}
|
||||
return caves;
|
||||
}
|
||||
|
||||
static List<Field> nodes(Field root) {
|
||||
Set<Field> seen = Collections.newSetFromMap(new IdentityHashMap<>());
|
||||
List<Field> nodes = new ArrayList<>();
|
||||
List<Field> pending = new ArrayList<>();
|
||||
pending.add(root);
|
||||
while (!pending.isEmpty()) {
|
||||
Field next = pending.removeLast();
|
||||
if (!seen.add(next)) {
|
||||
continue;
|
||||
}
|
||||
nodes.add(next);
|
||||
pending.addAll(children(next));
|
||||
}
|
||||
return nodes;
|
||||
}
|
||||
|
||||
private static void addPresent(List<Field> children, Field field) {
|
||||
if (field != null) {
|
||||
children.add(field);
|
||||
}
|
||||
}
|
||||
|
||||
record CodeRange(String loadKey, double min, double max) {
|
||||
}
|
||||
}
|
||||
-131
@@ -1,131 +0,0 @@
|
||||
package art.arcane.iris.pack.datapack.export.compile.cave;
|
||||
|
||||
import art.arcane.iris.generation.cave.IrisCaveProfile;
|
||||
import art.arcane.iris.pack.datapack.DataVersion;
|
||||
import art.arcane.iris.pack.datapack.export.ExportTestPacks;
|
||||
import art.arcane.iris.pack.datapack.export.compile.DimensionStage;
|
||||
import art.arcane.iris.pack.datapack.export.compile.PackCompileContext;
|
||||
import art.arcane.iris.pack.datapack.export.ir.CostClass;
|
||||
import art.arcane.iris.pack.datapack.export.ir.ExportDiagnostic;
|
||||
import art.arcane.iris.pack.datapack.export.ir.ExportLimit;
|
||||
import art.arcane.iris.pack.datapack.export.ir.Field;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.testsupport.PlatformLeakGuard;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class DeepCaveCompilerTest {
|
||||
private static final Field SURFACE = new Field.Const(150.0);
|
||||
private static final int LAVA_HEIGHT = 2;
|
||||
private static final int LAVA_Y = CaveTestPacks.MIN_Y + LAVA_HEIGHT;
|
||||
private static final int ZONE_Y = -58;
|
||||
private static final int ABOVE_LINE_Y = -40;
|
||||
|
||||
@ClassRule
|
||||
public static final PlatformLeakGuard PLATFORM_GUARD = PlatformLeakGuard.clean();
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
|
||||
@Rule
|
||||
public ExportTestPacks.BoundPlatform platform = new ExportTestPacks.BoundPlatform();
|
||||
|
||||
@Test
|
||||
public void deepCavesStaySolidInFinalDensityAndOpenThroughTheMaterialPass() throws Exception {
|
||||
PackCompileContext context = compile(CaveTestPacks.constantProfile(5.0).setAllowLava(true), LAVA_HEIGHT, DataVersion.V26_3);
|
||||
|
||||
Field opening = context.deepCaves().orElseThrow();
|
||||
assertTrue(sample(context, context.caves(), ZONE_Y) > 0.0);
|
||||
assertTrue(sample(context, context.caves(), DeepCaveCompiler.LAVA_LINE - 1) > 0.0);
|
||||
assertTrue(sample(context, context.caves(), DeepCaveCompiler.LAVA_LINE) <= 0.0);
|
||||
assertTrue(sample(context, context.caves(), ABOVE_LINE_Y) <= 0.0);
|
||||
assertTrue(sample(context, context.caves(), LAVA_Y) <= 0.0);
|
||||
assertEquals(1.0, sample(context, opening, ZONE_Y), 0.0);
|
||||
assertEquals(1.0, sample(context, opening, LAVA_Y + 1), 0.0);
|
||||
assertEquals(0.0, sample(context, opening, DeepCaveCompiler.LAVA_LINE), 0.0);
|
||||
assertEquals(0.0, sample(context, opening, ABOVE_LINE_Y), 0.0);
|
||||
assertEquals(0.0, sample(context, opening, LAVA_Y), 0.0);
|
||||
assertTrue(has(context, ExportLimit.DEEP_CAVE_LAYERS));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void solidDeepRockStaysClosed() throws Exception {
|
||||
PackCompileContext context = compile(CaveTestPacks.constantProfile(-5.0).setAllowLava(true), LAVA_HEIGHT, DataVersion.V26_3);
|
||||
|
||||
Field opening = context.deepCaves().orElseThrow();
|
||||
assertEquals(0.0, sample(context, opening, ZONE_Y), 0.0);
|
||||
assertTrue(sample(context, context.caves(), ZONE_Y) > 0.0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lavaFreeCavesOpenDownToTheFloor() throws Exception {
|
||||
PackCompileContext context = compile(CaveTestPacks.constantProfile(5.0), LAVA_HEIGHT, DataVersion.V26_3);
|
||||
|
||||
Field opening = context.deepCaves().orElseThrow();
|
||||
assertEquals(1.0, sample(context, opening, CaveTestPacks.MIN_Y), 0.0);
|
||||
assertTrue(sample(context, context.caves(), CaveTestPacks.MIN_Y) > 0.0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lavaAboveTheLineLeavesCavesUnchanged() throws Exception {
|
||||
PackCompileContext context = compile(CaveTestPacks.constantProfile(5.0).setAllowLava(true), 20, DataVersion.V26_3);
|
||||
|
||||
assertTrue(context.deepCaves().isEmpty());
|
||||
assertSame(context.caveField().orElseThrow(), context.caves());
|
||||
assertTrue(CaveTestPacks.caveField(context.caves()) instanceof Field.Grid);
|
||||
assertFalse(has(context, ExportLimit.DEEP_CAVE_LAYERS));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void expensiveCavesNeverSitUnderEagerNodes() throws Exception {
|
||||
PackCompileContext context = compile(CaveTestPacks.constantProfile(5.0).setAllowLava(true), LAVA_HEIGHT, DataVersion.V26_3);
|
||||
|
||||
for (Field root : List.of(context.caves(), context.deepCaves().orElseThrow())) {
|
||||
for (Field node : CaveTestPacks.nodes(root)) {
|
||||
for (Field child : CaveTestPacks.eagerChildren(node)) {
|
||||
assertTrue(node.getClass().getSimpleName() + " evaluates an expensive child eagerly", child.cost() != CostClass.EXPENSIVE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private PackCompileContext compile(IrisCaveProfile profile, int lavaHeight, DataVersion target) throws Exception {
|
||||
File pack = CaveTestPacks.pack(temporaryFolder.newFolder("pack"), CaveTestPacks.dimension(lavaHeight),
|
||||
CaveTestPacks.region(List.of("cave-deep"), null), Map.of("cave-deep", profile));
|
||||
IrisData data = IrisData.openRuntime(pack);
|
||||
try {
|
||||
PackCompileContext context = ExportTestPacks.contextBuilder(data, target).styles(FakeCaveStyles.volumetric()).build();
|
||||
new DimensionStage().apply(context);
|
||||
context.setHeight(SURFACE);
|
||||
context.setBiomeCodes(CaveTestPacks.codes(CaveTestPacks.xGradient(), List.of(new CaveTestPacks.CodeRange("cave-deep", -1.0, 1.0))));
|
||||
new CaveStage().apply(context);
|
||||
return context;
|
||||
} finally {
|
||||
data.close();
|
||||
}
|
||||
}
|
||||
|
||||
private static double sample(PackCompileContext context, Field field, int y) {
|
||||
return CaveTestPacks.sample(field, context.noises(), 40, y, 40);
|
||||
}
|
||||
|
||||
private static boolean has(PackCompileContext context, ExportLimit limit) {
|
||||
for (ExportDiagnostic diagnostic : context.diagnostics()) {
|
||||
if (diagnostic.limit() == limit) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
-159
@@ -1,159 +0,0 @@
|
||||
package art.arcane.iris.pack.datapack.export.compile.cave;
|
||||
|
||||
import art.arcane.iris.generation.cave.IrisCaveFieldModule;
|
||||
import art.arcane.iris.generation.cave.IrisCaveProfile;
|
||||
import art.arcane.iris.generation.noise.IrisStyledRange;
|
||||
import art.arcane.iris.pack.datapack.export.compile.noise.NoiseRegistry;
|
||||
import art.arcane.iris.pack.datapack.export.compile.noise.StyleCompiler;
|
||||
import art.arcane.iris.pack.datapack.export.ir.Field;
|
||||
import art.arcane.iris.pack.datapack.export.lower.ExportCapabilities;
|
||||
import art.arcane.iris.pack.value.IrisRange;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
final class IrisCaveReference {
|
||||
private static final long BASE_SALT = 934_447L;
|
||||
private static final long DETAIL_SALT = 612_991L;
|
||||
private static final long THRESHOLD_SALT = 489_112L;
|
||||
private static final long SURFACE_BREAK_SALT = 341_219L;
|
||||
private static final long MODULE_SALT = 1_000_003L;
|
||||
private static final long MODULE_SALT_STEP = 65_537L;
|
||||
private static final int CEILING_FADE_DEPTH = 12;
|
||||
private static final double CLOSURE_EPSILON = 0.000001D;
|
||||
|
||||
private final IrisCaveProfile profile;
|
||||
private final NoiseRegistry registry;
|
||||
private final Field height;
|
||||
private final Field base;
|
||||
private final Field detail;
|
||||
private final List<Field> modules;
|
||||
private final Field threshold;
|
||||
private final Field surfaceBreak;
|
||||
private final int worldMinY;
|
||||
private final int worldHeight;
|
||||
private final double normalization;
|
||||
|
||||
IrisCaveReference(IrisCaveProfile profile, StyleCompiler styles, NoiseRegistry registry, ExportCapabilities capabilities, Field height) {
|
||||
this.profile = profile;
|
||||
this.registry = registry;
|
||||
this.height = height;
|
||||
this.worldMinY = CaveTestPacks.MIN_Y;
|
||||
this.worldHeight = CaveTestPacks.MAX_Y - CaveTestPacks.MIN_Y;
|
||||
base = styles.compile(profile.getBaseDensityStyle(), BASE_SALT, registry, capabilities);
|
||||
detail = styles.compile(profile.getDetailDensityStyle(), DETAIL_SALT, registry, capabilities);
|
||||
modules = new ArrayList<>();
|
||||
double weight = Math.abs(profile.getBaseWeight()) + Math.abs(profile.getDetailWeight());
|
||||
for (int index = 0; index < profile.getModules().size(); index++) {
|
||||
IrisCaveFieldModule module = profile.getModules().get(index);
|
||||
modules.add(styles.compile(module.getStyle(), MODULE_SALT + index * MODULE_SALT_STEP, registry, capabilities));
|
||||
weight += Math.abs(module.getWeight());
|
||||
}
|
||||
normalization = weight <= 0 ? 1D : weight;
|
||||
IrisStyledRange range = profile.getDensityThreshold();
|
||||
threshold = range.getMin() == range.getMax() || range.getStyle().isFlat() ? null
|
||||
: styles.compile(range.getStyle(), THRESHOLD_SALT, registry, capabilities);
|
||||
surfaceBreak = profile.isAllowSurfaceBreak() ? styles.compile(profile.getSurfaceBreakStyle(), SURFACE_BREAK_SALT, registry, capabilities) : null;
|
||||
}
|
||||
|
||||
boolean carved(int x, int worldY, int z) {
|
||||
int y = worldY - worldMinY;
|
||||
IrisRange range = profile.getVerticalRange();
|
||||
int minY = Math.max(0, (int) Math.floor(range.getMin()));
|
||||
int maxY = Math.min(worldHeight - 1, (int) Math.ceil(range.getMax()));
|
||||
if (y < minY || y > maxY) {
|
||||
return false;
|
||||
}
|
||||
int surface = (int) Math.round(sample(height, x, 0, z)) - worldMinY;
|
||||
int unclampedClearanceTop = surface - Math.max(0, profile.getSurfaceClearance());
|
||||
int clearanceTop = Math.min(maxY, Math.max(minY, unclampedClearanceTop));
|
||||
boolean breakColumn = surfaceBreak != null && signed(sample(surfaceBreak, x, 0, z)) >= profile.getSurfaceBreakNoiseThreshold();
|
||||
int columnTop = breakColumn ? Math.min(maxY, Math.max(minY, surface)) : clearanceTop;
|
||||
if (y > columnTop) {
|
||||
return false;
|
||||
}
|
||||
double local = columnThreshold(x, z) - profile.getThresholdBias();
|
||||
if (breakColumn && y >= Math.max(minY, surface - Math.max(0, profile.getSurfaceBreakDepth()))) {
|
||||
local += Math.max(0, profile.getSurfaceBreakThresholdBoost());
|
||||
}
|
||||
local -= edgeFade(y, minY, maxY);
|
||||
if (!breakColumn && unclampedClearanceTop <= maxY) {
|
||||
int distance = columnTop - y;
|
||||
double closure = closure(y);
|
||||
if (distance >= 0 && distance < CEILING_FADE_DEPTH && local > closure) {
|
||||
double progress = distance / (double) CEILING_FADE_DEPTH;
|
||||
double smooth = progress * progress * (3D - (2D * progress));
|
||||
local = closure + ((local - closure) * smooth);
|
||||
}
|
||||
}
|
||||
return density(x, worldY, z) <= local;
|
||||
}
|
||||
|
||||
private double columnThreshold(int x, int z) {
|
||||
IrisStyledRange range = profile.getDensityThreshold();
|
||||
if (range.getMin() == range.getMax()) {
|
||||
return range.getMin();
|
||||
}
|
||||
if (threshold == null) {
|
||||
return range.getMin() + (range.getMax() - range.getMin()) * 0.5;
|
||||
}
|
||||
return range.getMin() + (range.getMax() - range.getMin()) * sample(threshold, x, 0, z);
|
||||
}
|
||||
|
||||
private double density(int x, int worldY, int z) {
|
||||
int y = worldY - worldMinY;
|
||||
double density = signed(sample(base, x, worldY, z)) * profile.getBaseWeight();
|
||||
density += signed(sample(detail, x, worldY, z)) * profile.getDetailWeight();
|
||||
for (int index = 0; index < modules.size(); index++) {
|
||||
IrisCaveFieldModule module = profile.getModules().get(index);
|
||||
if (!active(module, y)) {
|
||||
continue;
|
||||
}
|
||||
double moduleDensity = signed(sample(modules.get(index), x, worldY, z)) - module.getThreshold();
|
||||
if (module.isInvert()) {
|
||||
moduleDensity = -moduleDensity;
|
||||
}
|
||||
density += moduleDensity * module.getWeight();
|
||||
}
|
||||
return density / normalization;
|
||||
}
|
||||
|
||||
private double closure(int y) {
|
||||
double minimum = -Math.abs(profile.getBaseWeight()) - Math.abs(profile.getDetailWeight());
|
||||
for (IrisCaveFieldModule module : profile.getModules()) {
|
||||
if (!active(module, y)) {
|
||||
continue;
|
||||
}
|
||||
double rawMin = module.isInvert() ? module.getThreshold() - 1D : -1D - module.getThreshold();
|
||||
double rawMax = module.isInvert() ? module.getThreshold() + 1D : 1D - module.getThreshold();
|
||||
minimum += Math.min(rawMin * module.getWeight(), rawMax * module.getWeight());
|
||||
}
|
||||
return minimum / normalization - CLOSURE_EPSILON;
|
||||
}
|
||||
|
||||
private double edgeFade(int y, int minY, int maxY) {
|
||||
int fadeRange = Math.max(0, profile.getVerticalEdgeFade());
|
||||
double strength = Math.max(0D, profile.getVerticalEdgeFadeStrength());
|
||||
if (fadeRange <= 0 || maxY <= minY || strength <= 0D) {
|
||||
return 0D;
|
||||
}
|
||||
int edgeDistance = Math.min(y - minY, maxY - y);
|
||||
if (edgeDistance >= fadeRange) {
|
||||
return 0D;
|
||||
}
|
||||
double t = Math.max(0D, Math.min(1D, edgeDistance / (double) fadeRange));
|
||||
return (1D - t * t * (3D - (2D * t))) * strength;
|
||||
}
|
||||
|
||||
private static boolean active(IrisCaveFieldModule module, int y) {
|
||||
return y >= (int) Math.floor(module.getVerticalRange().getMin()) && y <= (int) Math.ceil(module.getVerticalRange().getMax());
|
||||
}
|
||||
|
||||
private double sample(Field field, int x, int y, int z) {
|
||||
return CaveTestPacks.sample(field, registry, x, y, z);
|
||||
}
|
||||
|
||||
private static double signed(double unit) {
|
||||
return unit * 2D - 1D;
|
||||
}
|
||||
}
|
||||
-47
@@ -1,47 +0,0 @@
|
||||
package art.arcane.iris.pack.datapack.export.compile.cave;
|
||||
|
||||
import art.arcane.iris.pack.datapack.DataVersion;
|
||||
import art.arcane.iris.pack.datapack.export.ir.Axis;
|
||||
import art.arcane.iris.pack.datapack.export.ir.Field;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class WallShellCalibratorTest {
|
||||
private static final int MIN_Y = -64;
|
||||
private static final int MAX_Y = 64;
|
||||
|
||||
@Test
|
||||
public void bandHoldsTheOneBlockHorizontalWall() {
|
||||
double band = WallShellCalibrator.band(new CaveInterior(ridges(0.4), MIN_Y, MAX_Y), Map.of(), DataVersion.V26_3);
|
||||
|
||||
assertEquals(0.1, band, 1.0e-6);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bandScalesWithTheFieldGradient() {
|
||||
double band = WallShellCalibrator.band(new CaveInterior(ridges(1.2), MIN_Y, MAX_Y), Map.of(), DataVersion.V26_3);
|
||||
|
||||
assertEquals(0.3, band, 1.0e-6);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fieldsWithoutCavesHaveAnEmptyBand() {
|
||||
double band = WallShellCalibrator.band(new CaveInterior(new Field.Const(1.0), MIN_Y, MAX_Y), Map.of(), DataVersion.V26_3);
|
||||
|
||||
assertEquals(0.0, band, 0.0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void calibrationIsDeterministic() {
|
||||
CaveInterior interior = new CaveInterior(ridges(1.2), 0, 40);
|
||||
|
||||
assertEquals(WallShellCalibrator.band(interior, Map.of(), DataVersion.V26_3), WallShellCalibrator.band(interior, Map.of(), DataVersion.V26_3), 0.0);
|
||||
}
|
||||
|
||||
private static Field ridges(double amplitude) {
|
||||
return new Field.Coord(Axis.X, Field.Tiling.MIRRORED_REPEAT, 0.0, 8.0, -amplitude, amplitude);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user