mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 16:25:36 +00:00
Step warning, seed tests
- Warn in the stepHeight description that 1 is experimental and terraces can rise - Recapture the pinned schema digest for that description - Test the world seed at the window, region and pond D8 callers - Test that the plunge flare stops at the sea - Test that the plunge flare stays out of the running maximum - Open ReachShaper.widths to the package for that test
This commit is contained in:
8 files changed
+179
-3
No files matched your search
+1
-1
@@ -54,7 +54,7 @@ public class IrisHydrologyTier {
|
||||
|
||||
@MinNumber(1)
|
||||
@MaxNumber(2)
|
||||
@Description("Smallest step in blocks between this tier's water surfaces. 2 keeps channel surfaces on every second height above the sea. 1 lets a channel fall one block at a time, and works best with cascades false, which spreads drops into a gentle slope. Falls and plunge pools are unchanged. Ponds and lakes always use 2. A tier cannot use a larger step than the next larger tier.")
|
||||
@Description("Smallest step in blocks between this tier's water surfaces. 2 keeps channel surfaces on every second height above the sea. 1 is experimental: it lets a channel fall one block at a time, and works best with cascades false, which spreads drops into a gentle slope, but on slanted steps the water at inner corners converts to source blocks, so terraces can rise a block and water can reach dry banks. Falls and plunge pools are unchanged. Ponds and lakes always use 2. A tier cannot use a larger step than the next larger tier.")
|
||||
private int stepHeight = 2;
|
||||
|
||||
@MinNumber(0)
|
||||
|
||||
@@ -493,7 +493,7 @@ public final class ReachShaper {
|
||||
}
|
||||
}
|
||||
|
||||
private static void widths(ReachDraft draft, float upstream, float feederEnd) {
|
||||
static void widths(ReachDraft draft, float upstream, float feederEnd) {
|
||||
int count = draft.xs.length;
|
||||
boolean flare = draft.incoming.length > 0 && !draft.outlet;
|
||||
boolean taper = !flare && !draft.outlet;
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
package art.arcane.iris.generation.hydrology.plan;
|
||||
|
||||
import art.arcane.iris.generation.hydrology.config.IrisHydrology;
|
||||
import art.arcane.iris.generation.hydrology.grid.D8Router;
|
||||
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.water.HydrologyTier;
|
||||
import art.arcane.iris.generation.hydrology.water.LakeCandidate;
|
||||
import art.arcane.iris.generation.hydrology.water.Pond;
|
||||
@@ -11,6 +15,7 @@ import art.arcane.iris.generation.hydrology.water.PondPlanner;
|
||||
import art.arcane.iris.generation.hydrology.water.Reach;
|
||||
import art.arcane.iris.generation.hydrology.water.ReachShaper;
|
||||
import art.arcane.iris.generation.hydrology.water.ReachStyle;
|
||||
import java.util.Arrays;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -23,10 +28,15 @@ import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyLong;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
public class RegionPlannerTest {
|
||||
private static final long SEED = 1337L;
|
||||
@@ -320,6 +330,50 @@ public class RegionPlannerTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void routesOverTiedGroundFollowTheWorldSeed() {
|
||||
int[] first = tiedRoutes(11L);
|
||||
assertArrayEquals("the same seed takes the same routes", first, tiedRoutes(11L));
|
||||
assertFalse("another seed takes other routes", Arrays.equals(first, tiedRoutes(12L)));
|
||||
}
|
||||
|
||||
private static int[] tiedRoutes(long seed) {
|
||||
HydrologySettings settings = HydrologySettings.compile(new IrisHydrology(), seed, SEA_LEVEL, SyntheticTerrain.MIN_Y, SyntheticTerrain.MAX_Y);
|
||||
SyntheticTerrain pyramid = SyntheticTerrain.pyramid(2048D, 2048D);
|
||||
HydrologyTerrainSource terrain = new HydrologyTerrainSource() {
|
||||
@Override
|
||||
public void sample(int[] xs, int[] zs, HydrologySampleBuffer out, boolean baseOnly) {
|
||||
pyramid.sample(xs, zs, out, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int seaLevel() {
|
||||
return pyramid.seaLevel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int minY() {
|
||||
return pyramid.minY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int maxY() {
|
||||
return pyramid.maxY();
|
||||
}
|
||||
};
|
||||
ReachShaper shaper = mock(ReachShaper.class);
|
||||
int[][] routes = new int[1][];
|
||||
doAnswer(call -> {
|
||||
DemGrid surface = call.getArgument(0);
|
||||
routes[0] = call.getArgument(1);
|
||||
assertArrayEquals("seed " + seed, D8Router.receivers(surface, surface.values(), seed), routes[0]);
|
||||
return List.of();
|
||||
}).when(shaper).coarsePaths(any(), any(), any(), any(), any(), anyLong());
|
||||
new RegionPlanner(settings, new HeightLattice(terrain, RegionPlanner.CELL, true, 1 << 18), new HeightLattice(terrain, RegionPlanner.FINE_CELL, false, 1 << 20),
|
||||
new PondPlanner(settings), shaper).plan(ORIGIN);
|
||||
return routes[0];
|
||||
}
|
||||
|
||||
private static HydrologySettings settings() {
|
||||
return HydrologySettings.compile(new IrisHydrology(), SEED, SEA_LEVEL, SyntheticTerrain.MIN_Y, SyntheticTerrain.MAX_Y);
|
||||
}
|
||||
|
||||
@@ -95,6 +95,10 @@ final class SyntheticTerrain implements HydrologyTerrainSource {
|
||||
return new SyntheticTerrain((x, z) -> height);
|
||||
}
|
||||
|
||||
static SyntheticTerrain pyramid(double peakX, double peakZ) {
|
||||
return new SyntheticTerrain((x, z) -> 200D - 0.01D * (Math.abs(x - peakX) + Math.abs(z - peakZ)));
|
||||
}
|
||||
|
||||
static SyntheticTerrain southSlope(double northHeight, double gradient) {
|
||||
return new SyntheticTerrain((x, z) -> northHeight - gradient * z);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ package art.arcane.iris.generation.hydrology.plan;
|
||||
|
||||
import art.arcane.iris.generation.hydrology.config.IrisHydrology;
|
||||
import art.arcane.iris.generation.hydrology.config.IrisHydrologyTier;
|
||||
import art.arcane.iris.generation.hydrology.grid.D8Router;
|
||||
import art.arcane.iris.generation.hydrology.grid.DemGrid;
|
||||
import art.arcane.iris.generation.hydrology.grid.HeightLattice;
|
||||
import art.arcane.iris.generation.hydrology.raster.TongueGuard;
|
||||
import art.arcane.iris.generation.hydrology.raster.WaterHeads;
|
||||
@@ -17,6 +19,7 @@ import art.arcane.iris.generation.hydrology.water.Reach;
|
||||
import art.arcane.iris.generation.hydrology.water.ReachShaper;
|
||||
import art.arcane.iris.generation.hydrology.water.ReachStyle;
|
||||
import art.arcane.iris.generation.hydrology.water.ShapedNetwork;
|
||||
import java.util.Arrays;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -31,6 +34,7 @@ import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
@@ -1389,6 +1393,31 @@ public class WindowPlannerTest {
|
||||
return plans;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void routesOverTiedGroundFollowTheWorldSeed() {
|
||||
int[] first = tiedRoutes(11L);
|
||||
assertArrayEquals("the same seed takes the same routes", first, tiedRoutes(11L));
|
||||
assertFalse("another seed takes other routes", Arrays.equals(first, tiedRoutes(12L)));
|
||||
}
|
||||
|
||||
private static int[] tiedRoutes(long seed) {
|
||||
IrisHydrology config = new IrisHydrology();
|
||||
config.getPonds().getNatural().setEnabled(false);
|
||||
config.getPonds().getSeeded().setEnabled(false);
|
||||
HydrologySettings settings = HydrologySettings.compile(config, seed, SEA_LEVEL, SyntheticTerrain.MIN_Y, SyntheticTerrain.MAX_Y);
|
||||
ReachShaper shaper = mock(ReachShaper.class);
|
||||
int[][] routes = new int[1][];
|
||||
doAnswer(call -> {
|
||||
DemGrid surface = call.getArgument(1);
|
||||
routes[0] = call.getArgument(2);
|
||||
assertArrayEquals("seed " + seed, D8Router.receivers(surface, surface.values(), seed), routes[0]);
|
||||
return new ShapedNetwork(List.of(), List.of());
|
||||
}).when(shaper).shape(any(), any(), any(), any(), any(), any(), any(), any(), anyLong());
|
||||
new WindowPlanner(settings, new HeightLattice(SyntheticTerrain.pyramid(512D, 512D), WindowPlanner.FINE_CELL, false, 1 << 21), new PondPlanner(settings), shaper)
|
||||
.plan(ORIGIN, noRegions(ORIGIN));
|
||||
return routes[0];
|
||||
}
|
||||
|
||||
private static List<RegionPlan> noRegions(WindowKey key) {
|
||||
List<RegionPlan> plans = new ArrayList<>();
|
||||
for (RegionKey region : WindowPlanner.lakeRegions(key)) {
|
||||
|
||||
@@ -357,6 +357,64 @@ public class PondPlannerTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void chainSettlementFollowsTheSeedAcrossATiedFork() {
|
||||
int eastward = 0;
|
||||
for (long seed = 1L; seed <= 24L; seed++) {
|
||||
boolean east = forkLowersEast(seed);
|
||||
assertEquals("seed " + seed + " repeats", east, forkLowersEast(seed));
|
||||
eastward += east ? 1 : 0;
|
||||
}
|
||||
assertTrue("east takes " + eastward + " of 24 seeds", eastward > 0 && eastward < 24);
|
||||
}
|
||||
|
||||
private static boolean forkLowersEast(long seed) {
|
||||
IrisHydrology config = new IrisHydrology();
|
||||
seededOnly(config);
|
||||
config.getPonds().setFreeboard(new KList<>(1, 1));
|
||||
config.getPonds().getShore().setRoundness(0D);
|
||||
HydrologySettings settings = HydrologySettings.compile(config, seed, SEA_LEVEL, MIN_Y, MAX_Y);
|
||||
DemGrid grid = new DemGrid(0, 0, 8, 64, 64);
|
||||
Arrays.fill(grid.values(), 100f);
|
||||
float[] filled = new float[grid.values().length];
|
||||
Arrays.fill(filled, 200f);
|
||||
int upper = grid.index(32, 12);
|
||||
int fork = grid.index(32, 20);
|
||||
filled[upper] = 190f;
|
||||
filled[fork] = 150f;
|
||||
int[] westCells = new int[16];
|
||||
int[] eastCells = new int[16];
|
||||
for (int offset = 0; offset < 16; offset++) {
|
||||
westCells[offset] = grid.index(16 + offset, 20);
|
||||
eastCells[offset] = grid.index(33 + offset, 20);
|
||||
filled[westCells[offset]] = 140f;
|
||||
filled[eastCells[offset]] = 140f;
|
||||
}
|
||||
int westFloor = westCells[0];
|
||||
int eastFloor = eastCells[15];
|
||||
List<Basin> basins = List.of(new Basin(0, upper, fork, 100f, 6f, new int[]{upper}, false),
|
||||
new Basin(1, westFloor, grid.index(16, 21), 100f, 6f, westCells, false),
|
||||
new Basin(2, eastFloor, grid.index(48, 21), 100f, 6f, eastCells, false));
|
||||
CupSet cups = new CupSet(List.of(chainedCup(grid, upper), chainedCup(grid, westFloor), chainedCup(grid, eastFloor)));
|
||||
HeightLattice fine = new HeightLattice(new Terrain((x, z) -> 100D, 1f, ALLOW_ALL, null, MIN_Y, MAX_Y), 4, false, 1 << 20);
|
||||
Map<Integer, Integer> levels = new HashMap<>();
|
||||
for (Pond pond : new PondPlanner(settings).ponds(grid, filled, basins, List.of(), fine, cups)) {
|
||||
levels.put(pond.floorX(), pond.level());
|
||||
}
|
||||
assertEquals(levels.toString(), 3, levels.size());
|
||||
int top = levels.get(grid.blockX(upper));
|
||||
boolean east = D8Router.receivers(grid, filled, seed)[fork] == eastCells[0];
|
||||
int lowered = levels.get(grid.blockX(east ? eastFloor : westFloor));
|
||||
int untouched = levels.get(grid.blockX(east ? westFloor : eastFloor));
|
||||
assertEquals("seed " + seed + " the pond the fork reaches sits below the upper pond", top - 1, lowered);
|
||||
assertEquals("seed " + seed + " the pond off the route keeps its level", top, untouched);
|
||||
return east;
|
||||
}
|
||||
|
||||
private static CupSet.Cup chainedCup(DemGrid grid, int cell) {
|
||||
return new CupSet.Cup(grid.blockX(cell), grid.blockZ(cell), 16, 100f, 6, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cupCutNeverExceedsTwiceDepth() {
|
||||
HydrologySettings settings = settings(config -> {
|
||||
|
||||
@@ -649,6 +649,37 @@ public class ReachShaperTest {
|
||||
for (int point = 0; point < count; point++) {
|
||||
assertEquals("a fall into the sea flares nothing at " + point, 0f, atSea[point], 0f);
|
||||
}
|
||||
|
||||
boolean[] estuary = new boolean[count];
|
||||
Arrays.fill(estuary, 5, count, true);
|
||||
float[] aboveEstuary = ReachShaper.plungeFlare(grade, ReachShaper.styles(grade, estuary, noZone, 6, SEA_LEVEL, 2), estuary, distance, 0f, 6);
|
||||
assertTrue("the fall above the estuary flares", aboveEstuary[3] > 0f && aboveEstuary[4] > 0f);
|
||||
for (int point = 5; point < count; point++) {
|
||||
assertEquals("the flare stops where the sea starts, at " + point, 0f, aboveEstuary[point], 0f);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void plungeFlareStaysOutOfTheRunningMaximum() {
|
||||
HydrologySettings settings = settings(config -> config.getTiers().forEach(tier -> tier.setHalfWidth(new KList<>(2D, 32D))));
|
||||
HydrologyTier tier = settings.tiers().get(0);
|
||||
int points = 64;
|
||||
int foot = 50;
|
||||
float[] ground = new float[points];
|
||||
Arrays.fill(ground, 0, foot, 90f);
|
||||
Arrays.fill(ground, foot, points, 78f);
|
||||
ReachDraft draft = draft(tier, ground);
|
||||
draft.grade = new int[points];
|
||||
Arrays.fill(draft.grade, 0, foot, 90);
|
||||
Arrays.fill(draft.grade, foot, points, 78);
|
||||
draft.catchments = new float[points];
|
||||
Arrays.fill(draft.catchments, 40000f);
|
||||
draft.outletZone = new boolean[points];
|
||||
draft.style = ReachShaper.styles(draft.grade, draft.ocean, draft.outletZone, tier.waterfallMinimumDrop(), SEA_LEVEL, 2);
|
||||
ReachShaper.widths(draft, 0f, 0f);
|
||||
float law = tier.halfWidth(40000f);
|
||||
assertEquals("the foot flares", 1.5f * law, draft.halfWidth[foot], 1e-3f);
|
||||
assertEquals("the channel's own width is what feeds downstream", law, draft.maxHalfWidth, 1e-3f);
|
||||
}
|
||||
|
||||
private static float[] plungeShare(Reach reach) {
|
||||
|
||||
@@ -84,7 +84,7 @@ public class SchemaBuilderIdentityTest {
|
||||
@ClassRule
|
||||
public static final PlatformLeakGuard PLATFORM_GUARD = PlatformLeakGuard.clean();
|
||||
|
||||
private static final String EXPECTED_SCHEMA_DIGEST = "addfddb3462b79563ecc3ba52a3000d36d2fc02e63966ae2e1bdf42de90130b5";
|
||||
private static final String EXPECTED_SCHEMA_DIGEST = "d35dfc4ec63cf5cb8f8782177f9b2feac9771c85fdc315d6f3cac5b89cb30924";
|
||||
|
||||
private static final List<Class<?>> SCHEMA_ROOTS = List.of(
|
||||
IrisDimension.class,
|
||||
|
||||
Reference in new issue
Block a user