mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-29 01:04:29 +00:00
Drawdown follows zone wetness
- Carry each column's bounded zone wetness and whether climate zones apply to it as wetness and climateZoned sample channels, copied by HeightLattice - Draw pond and lake surfaces down by climateDrawdown times one minus the bounded zone wetness at the floor inside climate zones, and by one minus rainfall where the zones are off or climateZones is false - Test the drawdown in wet, dry and transition zones and outside them, and that two windows give a pond the same level - Test that a policy wetness min keeps a dry-zone pond from drawing down, from the terrain source through the planner - Describe the rainfall policy as lowering ponds only where the climate zones do not apply - Recapture the schema digest
This commit is contained in:
1 parent
fa43b276f4
commit
720b9ac967
9 files changed
+210
-20
No files matched your search
+127
@@ -8,14 +8,24 @@ import art.arcane.iris.generation.hydrology.config.IrisFluidProfile;
|
||||
import art.arcane.iris.generation.hydrology.config.IrisHydrology;
|
||||
import art.arcane.iris.generation.hydrology.config.IrisHydrologyPolicy;
|
||||
import art.arcane.iris.generation.hydrology.config.IrisHydrologyWetness;
|
||||
import art.arcane.iris.generation.hydrology.grid.Basin;
|
||||
import art.arcane.iris.generation.hydrology.grid.BasinExtractor;
|
||||
import art.arcane.iris.generation.hydrology.grid.DemGrid;
|
||||
import art.arcane.iris.generation.hydrology.grid.HeightLattice;
|
||||
import art.arcane.iris.generation.hydrology.grid.HydrologySampleBuffer;
|
||||
import art.arcane.iris.generation.hydrology.grid.HydrologyTerrainSource;
|
||||
import art.arcane.iris.generation.hydrology.grid.PriorityFlood;
|
||||
import art.arcane.iris.generation.hydrology.plan.HydrologySettings;
|
||||
import art.arcane.iris.generation.hydrology.plan.WindowKey;
|
||||
import art.arcane.iris.generation.hydrology.water.CupSet;
|
||||
import art.arcane.iris.generation.hydrology.water.Pond;
|
||||
import art.arcane.iris.generation.hydrology.water.PondPlanner;
|
||||
import art.arcane.iris.generation.stream.ChunkFillableDoubleStream2D;
|
||||
import art.arcane.iris.generation.terrain.InferredType;
|
||||
import art.arcane.iris.generation.terrain.IrisMaterialPalette;
|
||||
import art.arcane.iris.generation.terrain.IrisRegion;
|
||||
import art.arcane.iris.testsupport.PlatformLeakGuard;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.stream.ProceduralStream;
|
||||
import org.junit.After;
|
||||
import org.junit.ClassRule;
|
||||
@@ -24,6 +34,7 @@ import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.BitSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
@@ -33,6 +44,7 @@ import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
@@ -161,15 +173,18 @@ public class IrisHydrologyTerrainSourceTest {
|
||||
boolean alpha = fixture.complex.getRegionStream().get(x, z).getLoadKey().equals("alpha");
|
||||
String at = x + "," + z;
|
||||
assertEquals(at, alpha ? "water" : null, source.channelFluid(x, z));
|
||||
assertEquals(at, !meadow, samples.climateZoned()[index]);
|
||||
if (meadow) {
|
||||
assertEquals(at, 2f, samples.rainfall()[index], 0f);
|
||||
assertEquals(at, alpha ? 3f : 1f, samples.pondDensity()[index], 0f);
|
||||
assertEquals(at, 1f, samples.wetness()[index], 0f);
|
||||
kept++;
|
||||
continue;
|
||||
}
|
||||
boolean zoneDry = samples.rainfall()[index] == 0f;
|
||||
assertEquals(at, zoneDry ? 0f : 0.5f, samples.rainfall()[index], 0f);
|
||||
assertEquals(at, zoneDry ? 0f : alpha ? 3f : 1f, samples.pondDensity()[index], 0f);
|
||||
assertEquals(at, zoneDry ? 0f : 1f, samples.wetness()[index], 0f);
|
||||
if (zoneDry) {
|
||||
dry++;
|
||||
} else {
|
||||
@@ -214,8 +229,12 @@ public class IrisHydrologyTerrainSourceTest {
|
||||
float wet = Math.clamp(zoneDry ? 0f : 1f, swamp ? 0.7f : 0f, swamp || alpha ? 1f : 0.35f);
|
||||
assertEquals(at, rainfall * wet, clamped.rainfall()[index], 0f);
|
||||
assertEquals(at, ponds * wet, clamped.pondDensity()[index], 0f);
|
||||
assertEquals(at, wet, clamped.wetness()[index], 0f);
|
||||
assertTrue(at, clamped.climateZoned()[index]);
|
||||
assertEquals(at, rainfall, unzoned.rainfall()[index], 0f);
|
||||
assertEquals(at, ponds, unzoned.pondDensity()[index], 0f);
|
||||
assertEquals(at, 1f, unzoned.wetness()[index], 0f);
|
||||
assertFalse(at, unzoned.climateZoned()[index]);
|
||||
seen.add(leaf + "@" + (alpha ? "alpha" : "beta") + (zoneDry ? " dry" : " wet"));
|
||||
}
|
||||
assertTrue("sampled " + seen, seen.containsAll(List.of("meadow@alpha dry", "glade@beta dry", "meadow@beta wet", "spires@beta wet",
|
||||
@@ -224,6 +243,72 @@ public class IrisHydrologyTerrainSourceTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void wetnessMinKeepsADryZonePondFromDrawingDown() throws Exception {
|
||||
Path pack = childPack("");
|
||||
int[][] grid = childGrid();
|
||||
try (EngineFixture.Environment ignored = EngineFixture.environment(); EngineFixture fixture = new EngineFixture(pack)) {
|
||||
IrisHydrology config = new IrisHydrology().setEnabled(true).setPersist(false);
|
||||
config.getFluids().add(new IrisFluidProfile().setName("lava").setPalette(new IrisMaterialPalette().qclear().qadd("minecraft:lava")));
|
||||
config.getClimate().setEnabled(true).setDryness(0.5D).setTransition(0D).setDryRainfall(0.15D).getStyle().setZoom(4D);
|
||||
config.getPonds().setFreeboard(new KList<>(1, 1));
|
||||
config.getPonds().getSeeded().setEnabled(false);
|
||||
HydrologySettings settings = HydrologySettings.compile(config, EngineFixture.SEED, fixture.dimension.getFluidHeight(), 0,
|
||||
EngineFixture.HEIGHT);
|
||||
IrisBiome spires = fixture.data.getBiomeLoader().load("spires");
|
||||
spires.setHydrologyPolicy(new IrisHydrologyPolicy().setPondDensity(16D));
|
||||
int[] column = dryZoneColumn(fixture, settings, grid, "spires");
|
||||
Pond dry = floorPond(fixture, settings, column);
|
||||
spires.setHydrologyPolicy(new IrisHydrologyPolicy().setPondDensity(16D).setWetness(new IrisHydrologyWetness().setMin(0.7D)));
|
||||
Pond swamp = floorPond(fixture, settings, column);
|
||||
spires.setHydrologyPolicy(new IrisHydrologyPolicy().setPondDensity(16D).setWetness(new IrisHydrologyWetness().setMin(1D)));
|
||||
Pond kept = floorPond(fixture, settings, column);
|
||||
int drawdown = settings.ponds().climateDrawdown();
|
||||
assertEquals((int) Math.floor(kept.spillHeight()) - 1, kept.level());
|
||||
assertEquals(kept.level() - Math.round(drawdown * 0.3f), swamp.level());
|
||||
assertEquals(kept.level() - Math.round(drawdown * 0.85f), dry.level());
|
||||
}
|
||||
}
|
||||
|
||||
private static int[] dryZoneColumn(EngineFixture fixture, HydrologySettings settings, int[][] grid, String biome) {
|
||||
HydrologySampleBuffer samples = new HydrologySampleBuffer(grid[0].length);
|
||||
new IrisHydrologyTerrainSource(fixture.complex, fixture.dimension, settings, null, 1, HydrologyBinding.UNBOUND)
|
||||
.sample(grid[0], grid[1], samples, false);
|
||||
for (int index = 0; index < grid[0].length; index++) {
|
||||
if (samples.rainfall()[index] < 0.1f && fixture.complex.getBaseBiomeStream().get(grid[0][index], grid[1][index]).getLoadKey().equals(biome)) {
|
||||
return new int[]{grid[0][index], grid[1][index]};
|
||||
}
|
||||
}
|
||||
throw new AssertionError("No sampled " + biome + " column lies in a dry zone");
|
||||
}
|
||||
|
||||
private static Pond floorPond(EngineFixture fixture, HydrologySettings settings, int[] column) {
|
||||
HydrologySampleBuffer floor = new HydrologySampleBuffer(1);
|
||||
new IrisHydrologyTerrainSource(fixture.complex, fixture.dimension, settings, null, 1, HydrologyBinding.UNBOUND)
|
||||
.sample(new int[]{column[0]}, new int[]{column[1]}, floor, false);
|
||||
FloorBowl bowl = new FloorBowl(settings, floor);
|
||||
int span = 64;
|
||||
HydrologySampleBuffer samples = new HydrologySampleBuffer(span * span);
|
||||
new HeightLattice(bowl, 8, false, 1 << 16).fill(0, 0, span, span, samples);
|
||||
DemGrid grid = new DemGrid(0, 0, 8, span, span);
|
||||
System.arraycopy(samples.height(), 0, grid.values(), 0, span * span);
|
||||
PondPlanner planner = new PondPlanner(settings);
|
||||
CupSet cups = planner.subtractCups(grid, new WindowKey(0, 0), samples, new BitSet());
|
||||
BitSet seeds = new BitSet(span * span);
|
||||
for (int j = 0; j < span; j++) {
|
||||
for (int i = 0; i < span; i++) {
|
||||
if (i == 0 || j == 0 || i == span - 1 || j == span - 1) {
|
||||
seeds.set(grid.index(i, j));
|
||||
}
|
||||
}
|
||||
}
|
||||
float[] filled = PriorityFlood.fill(grid, seeds, settings.drainage().fillEpsilon());
|
||||
List<Basin> basins = BasinExtractor.basins(grid, filled, 0.5f, settings.seaLevel());
|
||||
List<Pond> ponds = planner.ponds(grid, filled, basins, List.of(), new HeightLattice(bowl, 4, false, 1 << 18), cups);
|
||||
assertEquals("ponds " + ponds, 1, ponds.size());
|
||||
return ponds.getFirst();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void policyMultipliersOutsideZeroToSixteenAreRejected() throws Exception {
|
||||
Path pack = EngineFixture.pack(temporaryFolder.newFolder().toPath());
|
||||
@@ -525,6 +610,8 @@ public class IrisHydrologyTerrainSourceTest {
|
||||
assertEquals(at, expected.ocean()[index], actual.ocean()[index]);
|
||||
assertEquals(at, Float.floatToRawIntBits(expected.rainfall()[index]), Float.floatToRawIntBits(actual.rainfall()[index]));
|
||||
assertEquals(at, Float.floatToRawIntBits(expected.pondDensity()[index]), Float.floatToRawIntBits(actual.pondDensity()[index]));
|
||||
assertEquals(at, Float.floatToRawIntBits(expected.wetness()[index]), Float.floatToRawIntBits(actual.wetness()[index]));
|
||||
assertEquals(at, expected.climateZoned()[index], actual.climateZoned()[index]);
|
||||
assertEquals(at, expected.permission()[index], actual.permission()[index]);
|
||||
assertEquals(at, expected.fluidProfile()[index], actual.fluidProfile()[index]);
|
||||
}
|
||||
@@ -548,6 +635,46 @@ public class IrisHydrologyTerrainSourceTest {
|
||||
}
|
||||
}
|
||||
|
||||
private static final class FloorBowl implements HydrologyTerrainSource {
|
||||
private final HydrologySettings settings;
|
||||
private final HydrologySampleBuffer floor;
|
||||
|
||||
private FloorBowl(HydrologySettings settings, HydrologySampleBuffer floor) {
|
||||
this.settings = settings;
|
||||
this.floor = floor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sample(int[] xs, int[] zs, HydrologySampleBuffer out, boolean baseOnly) {
|
||||
for (int index = 0; index < xs.length; index++) {
|
||||
double ratio = Math.hypot(xs[index] - 256D, zs[index] - 256D) / 60D;
|
||||
out.height()[index] = (float) (ratio < 1D ? 200D + 12D * ratio * ratio : 212D - 6D * (ratio - 1D));
|
||||
out.ocean()[index] = false;
|
||||
out.rainfall()[index] = floor.rainfall()[0];
|
||||
out.pondDensity()[index] = floor.pondDensity()[0];
|
||||
out.wetness()[index] = floor.wetness()[0];
|
||||
out.climateZoned()[index] = floor.climateZoned()[0];
|
||||
out.permission()[index] = floor.permission()[0];
|
||||
out.fluidProfile()[index] = floor.fluidProfile()[0];
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int seaLevel() {
|
||||
return settings.seaLevel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int minY() {
|
||||
return settings.minY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int maxY() {
|
||||
return settings.maxY();
|
||||
}
|
||||
}
|
||||
|
||||
private static double[] chunk(Map<Long, double[]> chunks, ChunkFillableDoubleStream2D stream, int x, int z) {
|
||||
long key = ((long) (x >> 4) << 32) | ((z >> 4) & 0xFFFFFFFFL);
|
||||
return chunks.computeIfAbsent(key, ignored -> {
|
||||
|
||||
@@ -365,6 +365,8 @@ public class HeightLatticeTest {
|
||||
assertEquals(Float.floatToIntBits(expected.height()[index]), Float.floatToIntBits(actual.height()[index]));
|
||||
assertEquals(Float.floatToIntBits(expected.rainfall()[index]), Float.floatToIntBits(actual.rainfall()[index]));
|
||||
assertEquals(Float.floatToIntBits(expected.pondDensity()[index]), Float.floatToIntBits(actual.pondDensity()[index]));
|
||||
assertEquals(Float.floatToIntBits(expected.wetness()[index]), Float.floatToIntBits(actual.wetness()[index]));
|
||||
assertEquals(expected.climateZoned()[index], actual.climateZoned()[index]);
|
||||
assertEquals(expected.ocean()[index], actual.ocean()[index]);
|
||||
assertEquals(expected.permission()[index], actual.permission()[index]);
|
||||
assertEquals(expected.fluidProfile()[index], actual.fluidProfile()[index]);
|
||||
@@ -410,6 +412,8 @@ public class HeightLatticeTest {
|
||||
out.height()[index] = Float.intBitsToFloat(((int) hash & 0x807FFFFF) | 0x42000000);
|
||||
out.rainfall()[index] = Float.intBitsToFloat(((int) (hash >>> 23) & 0x007FFFFF) | 0x3F000000);
|
||||
out.pondDensity()[index] = Float.intBitsToFloat(((int) (hash >>> 37) & 0x007FFFFF) | 0x3F800000);
|
||||
out.wetness()[index] = Float.intBitsToFloat(((int) (hash >>> 11) & 0x007FFFFF) | 0x3F000000);
|
||||
out.climateZoned()[index] = ((hash >>> 58) & 1L) != 0L;
|
||||
out.ocean()[index] = ((hash >>> 62) & 1L) != 0L;
|
||||
out.permission()[index] = (byte) ((hash >>> 60) & (HydrologySampleBuffer.ALLOW_STREAMS | HydrologySampleBuffer.ALLOW_PONDS));
|
||||
out.fluidProfile()[index] = ((hash >>> 59) & 1L) == 0L ? "water" : "lava";
|
||||
|
||||
@@ -414,7 +414,7 @@ public class PondPlannerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dryClimateDrawsDownLevel() {
|
||||
public void lowRainfallDrawsDownPondsOutsideClimateZones() {
|
||||
HydrologySettings settings = settings(PondPlannerTest::naturalOnly, MIN_Y, MAX_Y);
|
||||
DoubleBinaryOperator terrain = bowl(256, 256, 60, 100, 12, 0.1);
|
||||
Pond wet = single(plan(settings, new Terrain(terrain, 1f, ALLOW_ALL, null, MIN_Y, MAX_Y), 0, 0, 64, 64, null, List.of()));
|
||||
@@ -426,6 +426,31 @@ public class PondPlannerTest {
|
||||
assertContained(dry, terrain);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void drawdownFollowsClimateDryness() {
|
||||
HydrologySettings settings = settings(PondPlannerTest::naturalOnly, MIN_Y, MAX_Y);
|
||||
DoubleBinaryOperator terrain = bowl(256, 256, 60, 100, 12, 0.1);
|
||||
int drawdown = settings.ponds().climateDrawdown();
|
||||
Pond full = single(plan(settings, new Terrain(terrain, 1f, ALLOW_ALL, null, MIN_Y, MAX_Y), 0, 0, 64, 64, null, List.of()));
|
||||
Pond wetZone = single(plan(settings, new Terrain(terrain, 0.5f, ALLOW_ALL, null, MIN_Y, MAX_Y).climateZoned((x, z) -> 1D),
|
||||
0, 0, 64, 64, null, List.of()));
|
||||
Pond dryZone = single(plan(settings, new Terrain(terrain, 1.2f, ALLOW_ALL, null, MIN_Y, MAX_Y).climateZoned((x, z) -> 0.15D),
|
||||
0, 0, 64, 64, null, List.of()));
|
||||
DoubleBinaryOperator band = (x, z) -> Math.clamp(0.5D + (x - 256D) / 512D, 0D, 1D);
|
||||
Terrain transition = new Terrain(terrain, 1f, ALLOW_ALL, null, MIN_Y, MAX_Y).climateZoned(band);
|
||||
Pond west = single(plan(settings, transition, 0, 0, 64, 64, null, List.of()));
|
||||
Pond east = single(plan(settings, transition, 128, 64, 64, 64, null, List.of()));
|
||||
Pond outsideZones = single(plan(settings, new Terrain(terrain, 0.5f, ALLOW_ALL, null, MIN_Y, MAX_Y), 0, 0, 64, 64, null, List.of()));
|
||||
assertEquals(full.id(), dryZone.id());
|
||||
assertEquals(full.level(), wetZone.level());
|
||||
assertEquals(full.level() - Math.round(drawdown * 0.85f), dryZone.level());
|
||||
assertEquals(full.level() - Math.round(drawdown * 0.5f), west.level());
|
||||
assertEquals(west.id(), east.id());
|
||||
assertEquals(west.level(), east.level());
|
||||
assertEquals(full.level() - Math.round(drawdown * 0.5f), outsideZones.level());
|
||||
assertContained(dryZone, terrain);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pondMaskNeverTouchesHalo() {
|
||||
HydrologySettings settings = settings(config -> {
|
||||
@@ -835,13 +860,14 @@ public class PondPlannerTest {
|
||||
private final int maxY;
|
||||
private final boolean inland;
|
||||
private final DoubleBinaryOperator pondDensity;
|
||||
private final DoubleBinaryOperator wetness;
|
||||
|
||||
private Terrain(DoubleBinaryOperator height, float rainfall, byte permission, String fluid, int minY, int maxY) {
|
||||
this(height, rainfall, permission, fluid, minY, maxY, false, (x, z) -> 1D);
|
||||
this(height, rainfall, permission, fluid, minY, maxY, false, (x, z) -> 1D, null);
|
||||
}
|
||||
|
||||
private Terrain(DoubleBinaryOperator height, float rainfall, byte permission, String fluid, int minY, int maxY, boolean inland,
|
||||
DoubleBinaryOperator pondDensity) {
|
||||
DoubleBinaryOperator pondDensity, DoubleBinaryOperator wetness) {
|
||||
this.height = height;
|
||||
this.rainfall = rainfall;
|
||||
this.permission = permission;
|
||||
@@ -850,14 +876,19 @@ public class PondPlannerTest {
|
||||
this.maxY = maxY;
|
||||
this.inland = inland;
|
||||
this.pondDensity = pondDensity;
|
||||
this.wetness = wetness;
|
||||
}
|
||||
|
||||
private Terrain inland() {
|
||||
return new Terrain(height, rainfall, permission, fluid, minY, maxY, true, pondDensity);
|
||||
return new Terrain(height, rainfall, permission, fluid, minY, maxY, true, pondDensity, wetness);
|
||||
}
|
||||
|
||||
private Terrain pondDensity(DoubleBinaryOperator density) {
|
||||
return new Terrain(height, rainfall, permission, fluid, minY, maxY, inland, density);
|
||||
return new Terrain(height, rainfall, permission, fluid, minY, maxY, inland, density, wetness);
|
||||
}
|
||||
|
||||
private Terrain climateZoned(DoubleBinaryOperator zoneWetness) {
|
||||
return new Terrain(height, rainfall, permission, fluid, minY, maxY, inland, pondDensity, zoneWetness);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -868,6 +899,8 @@ public class PondPlannerTest {
|
||||
out.ocean()[index] = !inland && value <= SEA_LEVEL;
|
||||
out.rainfall()[index] = rainfall;
|
||||
out.pondDensity()[index] = (float) pondDensity.applyAsDouble(xs[index], zs[index]);
|
||||
out.wetness()[index] = wetness == null ? 1f : (float) wetness.applyAsDouble(xs[index], zs[index]);
|
||||
out.climateZoned()[index] = wetness != null;
|
||||
out.permission()[index] = permission;
|
||||
out.fluidProfile()[index] = fluid;
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ public class SchemaBuilderIdentityTest {
|
||||
@ClassRule
|
||||
public static final PlatformLeakGuard PLATFORM_GUARD = PlatformLeakGuard.clean();
|
||||
|
||||
private static final String EXPECTED_SCHEMA_DIGEST = "6265ecff41869d4148cb6b5ffb6b8f9ddaf2d60d130bd09bba16ffdd4f72f33e";
|
||||
private static final String EXPECTED_SCHEMA_DIGEST = "34e32452b3e79ed5608e2e71fffeeae85ca99ec5c5c84970eedc9fa7b1c68a04";
|
||||
|
||||
private static final List<Class<?>> SCHEMA_ROOTS = List.of(
|
||||
IrisDimension.class,
|
||||
|
||||
Reference in new issue
Block a user