mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 00:34:19 +00:00
Falls at cliff edges
- ReachFitter reads ground with lowestCoveredGround, dropping nodes more than 2.5 blocks ahead only at a cliff edge - Exact columns from a point to the midpoint of its next segment cap the trimmed read, so water never overhangs a cliff between lattice nodes - T5 second case and cliffBetweenLatticeNodesKeepsWaterBelowTheGround cover the brink position and the centreline - stepsBelowTheWaterfallMinimumKeepTheFullGroundRead pins the waterfall minimum gate - cascades description separates cascade-start and waterfall-start steps; schema digest recaptured
This commit is contained in:
4 files changed
+118
-5
No files matched your search
+1
-1
@@ -44,7 +44,7 @@ public class IrisHydrologyTier {
|
||||
@Description("Blocks the water surface sits below the ground it flows through.")
|
||||
private int inset = 1;
|
||||
|
||||
@Description("Groups the drops of a run into step-pools: the drops within 2.5 to 5 channel widths, from 6 to 32 blocks, join into one step of up to waterfallMinimumDrop plus 2 blocks, and that limit ends the group early on steep ground. When false, drops are spread into a gentler slope where the terrain allows, including the step where a channel joins lower water; drops that cannot be spread, such as a junction right below a pond outlet, stay as small cascades below the waterfall minimum.")
|
||||
@Description("Groups the drops of a run into step-pools: the drops within 2.5 to 5 channel widths, from 6 to 32 blocks, join into one step. A step that starts with a cascade is at most waterfallMinimumDrop plus 2 blocks, and that limit ends the group early on steep ground. A step that starts with a waterfall is that waterfall plus the small drops it gathers below it. When false, drops are spread into a gentler slope where the terrain allows, including the step where a channel joins lower water; drops that cannot be spread, such as a junction right below a pond outlet, stay as small cascades below the waterfall minimum.")
|
||||
private boolean cascades = true;
|
||||
|
||||
@MinNumber(2)
|
||||
|
||||
@@ -14,6 +14,7 @@ final class ReachFitter {
|
||||
private static final float VALLEY_SNAP = 8f;
|
||||
private static final float MOVE_PENALTY = 0.25f * SPACING;
|
||||
private static final float MIN_ADVANCE = 0.25f * SPACING;
|
||||
private static final float COVER_AHEAD = 2.5f;
|
||||
private static final int[] MOVES = {0, -1, 1};
|
||||
private static final long SALT_MEANDER = 0x4d45414e444552L;
|
||||
|
||||
@@ -34,7 +35,7 @@ final class ReachFitter {
|
||||
Reads reads = read(line, tangents, reach);
|
||||
Fitted fitted = place(line, tangents, reads, viterbi(reads, line.xs().length, reach), tier);
|
||||
seaEnd(fitted.ocean(), drainsToTheSea);
|
||||
lowestNearbyGround(fitted);
|
||||
lowestCoveredGround(fitted, tier);
|
||||
return fitted;
|
||||
}
|
||||
|
||||
@@ -129,7 +130,7 @@ final class ReachFitter {
|
||||
return new Reads(span, ground, samples.ocean(), blocked);
|
||||
}
|
||||
|
||||
private void lowestNearbyGround(Fitted fitted) {
|
||||
private void lowestCoveredGround(Fitted fitted, HydrologyTier tier) {
|
||||
int points = fitted.xs().length;
|
||||
int step = fine.cell();
|
||||
int[] firstX = new int[points];
|
||||
@@ -154,19 +155,75 @@ final class ReachFitter {
|
||||
}
|
||||
HydrologySampleBuffer samples = new HydrologySampleBuffer(nodeX.length);
|
||||
fine.fill(nodeX, nodeZ, samples);
|
||||
Tangents tangents = tangents(fitted.xs(), fitted.zs());
|
||||
float[] covered = new float[points];
|
||||
Arrays.fill(covered, Float.POSITIVE_INFINITY);
|
||||
float drop = tier.waterfallMinimumDrop();
|
||||
for (int point = 0; point < points; point++) {
|
||||
float lowest = Float.POSITIVE_INFINITY;
|
||||
float lowestLand = Float.POSITIVE_INFINITY;
|
||||
float coveredLand = Float.POSITIVE_INFINITY;
|
||||
for (int node = offsets[point]; node < offsets[point + 1]; node++) {
|
||||
int pond = ponds.at(nodeX[node] * step, nodeZ[node] * step);
|
||||
float height = pond < 0 ? samples.height()[node] : Math.max(samples.height()[node], ponds.pond(pond).level());
|
||||
lowest = Math.min(lowest, height);
|
||||
if (!samples.ocean()[node]) {
|
||||
lowestLand = Math.min(lowestLand, height);
|
||||
float ahead = (nodeX[node] * step - fitted.xs()[point]) * tangents.x()[point]
|
||||
+ (nodeZ[node] * step - fitted.zs()[point]) * tangents.z()[point];
|
||||
if (ahead <= COVER_AHEAD) {
|
||||
coveredLand = Math.min(coveredLand, height);
|
||||
}
|
||||
}
|
||||
}
|
||||
fitted.ground()[point] = fitted.ocean()[point] || lowestLand == Float.POSITIVE_INFINITY ? lowest : lowestLand;
|
||||
boolean sea = fitted.ocean()[point] || lowestLand == Float.POSITIVE_INFINITY;
|
||||
fitted.ground()[point] = sea ? lowest : lowestLand;
|
||||
if (!sea && coveredLand != Float.POSITIVE_INFINITY && coveredLand - lowestLand >= drop) {
|
||||
covered[point] = coveredLand;
|
||||
}
|
||||
}
|
||||
standAtCliffEdges(fitted, covered, drop);
|
||||
}
|
||||
|
||||
private void standAtCliffEdges(Fitted fitted, float[] covered, float drop) {
|
||||
int points = fitted.xs().length;
|
||||
int[] offsets = new int[points + 1];
|
||||
for (int point = 0; point < points; point++) {
|
||||
offsets[point + 1] = offsets[point] + (covered[point] == Float.POSITIVE_INFINITY ? 0 : columnsToNext(fitted, point));
|
||||
}
|
||||
if (offsets[points] == 0) {
|
||||
return;
|
||||
}
|
||||
int[] columnX = new int[offsets[points]];
|
||||
int[] columnZ = new int[offsets[points]];
|
||||
for (int point = 0; point < points; point++) {
|
||||
int columns = offsets[point + 1] - offsets[point];
|
||||
int next = Math.min(points - 1, point + 1);
|
||||
for (int column = 0; column < columns; column++) {
|
||||
float share = columns == 1 ? 0f : 0.5f * column / (columns - 1);
|
||||
columnX[offsets[point] + column] = (int) Math.floor(lerp(fitted.xs()[point], fitted.xs()[next], share));
|
||||
columnZ[offsets[point] + column] = (int) Math.floor(lerp(fitted.zs()[point], fitted.zs()[next], share));
|
||||
}
|
||||
}
|
||||
HydrologySampleBuffer samples = new HydrologySampleBuffer(columnX.length);
|
||||
fine.sampleColumns(columnX, columnZ, samples);
|
||||
for (int point = 0; point < points; point++) {
|
||||
float lowest = covered[point];
|
||||
for (int column = offsets[point]; column < offsets[point + 1]; column++) {
|
||||
if (!samples.ocean()[column]) {
|
||||
int pond = ponds.at(columnX[column], columnZ[column]);
|
||||
lowest = Math.min(lowest, pond < 0 ? samples.height()[column] : Math.max(samples.height()[column], ponds.pond(pond).level()));
|
||||
}
|
||||
}
|
||||
if (offsets[point + 1] > offsets[point] && lowest - fitted.ground()[point] >= drop) {
|
||||
fitted.ground()[point] = lowest;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static int columnsToNext(Fitted fitted, int point) {
|
||||
int next = Math.min(fitted.xs().length - 1, point + 1);
|
||||
return 2 + (int) Math.ceil(0.5D * Math.hypot(fitted.xs()[next] - fitted.xs()[point], fitted.zs()[next] - fitted.zs()[point]));
|
||||
}
|
||||
|
||||
private static void seaEnd(boolean[] ocean, boolean drainsToTheSea) {
|
||||
|
||||
@@ -368,6 +368,62 @@ public class ReachShaperTest {
|
||||
end++;
|
||||
}
|
||||
assertTrue(label + " level below the fall from " + foot + " to " + end, STATION * (end - foot) >= StepPools.PLUNGE_MIN);
|
||||
|
||||
HydrologySettings settings = settings(config -> {
|
||||
});
|
||||
DoubleBinaryOperator cliff = steppedValley(12);
|
||||
float brink = brinkMidpoint(shape(settings, network(settings, cliff, 64, 64, VALLEY_THRESHOLD, false)));
|
||||
assertTrue("brink midpoint " + brink, brink >= STEP_X - 3);
|
||||
assertTrue("brink midpoint " + brink, brink <= STEP_X);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cliffBetweenLatticeNodesKeepsWaterBelowTheGround() {
|
||||
HydrologySettings settings = settings(config -> {
|
||||
});
|
||||
for (int edge = STEP_X - 3; edge <= STEP_X + 3; edge++) {
|
||||
int cliffX = edge;
|
||||
DoubleBinaryOperator cliff = (x, z) -> (x < 2 * CELL ? 140D : x < cliffX ? 120D : 108D) + 0.1D * Math.abs(z - VALLEY_Z);
|
||||
ShapedNetwork shaped = shape(settings, network(settings, cliff, 64, 64, VALLEY_THRESHOLD, false));
|
||||
for (Reach reach : shaped.reaches()) {
|
||||
for (int index = 0; index < reach.xs().length; index++) {
|
||||
double natural = cliff.applyAsDouble(reach.xs()[index], reach.zs()[index]);
|
||||
assertTrue("cliff " + cliffX + " " + reach + " at " + index + " x " + reach.xs()[index] + " grade " + reach.grade()[index]
|
||||
+ " natural " + natural, reach.grade()[index] <= natural);
|
||||
}
|
||||
}
|
||||
float brink = brinkMidpoint(shaped);
|
||||
assertTrue("cliff " + cliffX + " brink midpoint " + brink, brink >= cliffX - 5 && brink <= cliffX);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stepsBelowTheWaterfallMinimumKeepTheFullGroundRead() {
|
||||
HydrologySettings settings = settings(config -> {
|
||||
});
|
||||
DoubleBinaryOperator forward = steppedValley(5);
|
||||
DoubleBinaryOperator mirrored = (x, z) -> forward.applyAsDouble(504D - x, z);
|
||||
float before = STEP_X - firstAtOrBelow(shape(settings, network(settings, forward, 64, 64, VALLEY_THRESHOLD, false)), 113, true);
|
||||
float mirroredBefore = firstAtOrBelow(shape(settings, network(settings, mirrored, 64, 64, VALLEY_THRESHOLD, false)), 113, false) - (504 - STEP_X);
|
||||
assertEquals("a step below the waterfall minimum reads the same both ways", before, mirroredBefore, 1e-3f);
|
||||
}
|
||||
|
||||
private static float brinkMidpoint(ShapedNetwork shaped) {
|
||||
int falls = 0;
|
||||
float midpoint = Float.NaN;
|
||||
for (Reach reach : shaped.reaches()) {
|
||||
for (int index = 1; index < reach.xs().length; index++) {
|
||||
if (reach.xs()[index] < WINDOW_MIN_X || reach.xs()[index] > WINDOW_MAX_X) {
|
||||
continue;
|
||||
}
|
||||
if (reach.grade()[index - 1] - reach.grade()[index] >= reach.tier().waterfallMinimumDrop()) {
|
||||
falls++;
|
||||
midpoint = (reach.xs()[index - 1] + reach.xs()[index]) / 2f;
|
||||
}
|
||||
}
|
||||
}
|
||||
assertEquals("falls in the step window", 1, falls);
|
||||
return midpoint;
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -84,7 +84,7 @@ public class SchemaBuilderIdentityTest {
|
||||
@ClassRule
|
||||
public static final PlatformLeakGuard PLATFORM_GUARD = PlatformLeakGuard.clean();
|
||||
|
||||
private static final String EXPECTED_SCHEMA_DIGEST = "42f9e4edec478cc309119c8d90e15ed38f50a500f2e7d4fb870523be6c4fe10d";
|
||||
private static final String EXPECTED_SCHEMA_DIGEST = "c87139f807de29aa444923b6b0a1f85dc8de882ea8cf13ea3818fbdaeb352ae6";
|
||||
|
||||
private static final List<Class<?>> SCHEMA_ROOTS = List.of(
|
||||
IrisDimension.class,
|
||||
|
||||
Reference in new issue
Block a user