diff --git a/core/src/main/java/art/arcane/iris/generation/hydrology/raster/RiffleProfile.java b/core/src/main/java/art/arcane/iris/generation/hydrology/raster/RiffleProfile.java index 9936ec362..28bd7edf7 100644 --- a/core/src/main/java/art/arcane/iris/generation/hydrology/raster/RiffleProfile.java +++ b/core/src/main/java/art/arcane/iris/generation/hydrology/raster/RiffleProfile.java @@ -43,9 +43,10 @@ final class RiffleProfile { } TreeMap crests = new TreeMap<>(); TreeMap feet = new TreeMap<>(); + TreeMap brinks = new TreeMap<>(); for (int z = 1; z < GRID - 1; z++) { for (int x = 1; x < GRID - 1; x++) { - collect(z * GRID + x, crests, feet); + collect(z * GRID + x, crests, feet, brinks); } } if (crests.isEmpty() && feet.isEmpty()) { @@ -59,9 +60,11 @@ final class RiffleProfile { } } for (Map.Entry fall : feet.entrySet()) { - int[] output = distances.measure(fall.getValue(), fall.getKey().foot(), fall.getKey().reach()); + Fall key = fall.getKey(); + int[] output = distances.measure(fall.getValue(), key.foot(), key.reach()); if (output != null) { - plunges.add(new Plunge(fall.getKey(), output)); + Seeds tail = brinks.get(key.foot()); + plunges.add(new Plunge(key, output, tail == null ? null : distances.measure(tail, key.foot(), key.reach()))); } } } @@ -94,7 +97,7 @@ final class RiffleProfile { return flowing[grid] ? plunge(cell, riffled, head, variation) : riffled; } - private void collect(int cell, TreeMap crests, TreeMap feet) { + private void collect(int cell, TreeMap crests, TreeMap feet, TreeMap brinks) { int head = heads[cell]; if (head == DRY) { return; @@ -112,6 +115,7 @@ final class RiffleProfile { } if (crest) { crests.computeIfAbsent(new Crest(head - 1, features[cell], flowing[cell]), ignored -> new Seeds()).add(cell); + brinks.computeIfAbsent(head, ignored -> new Seeds()).add(cell); } } @@ -127,11 +131,12 @@ final class RiffleProfile { for (Plunge plunge : plunges) { Fall fall = plunge.fall(); int distance = plunge.distances()[cell]; - if (fall.foot() != head || distance >= 10D * fall.radius()) { + double span = plunge.span(cell); + if (fall.foot() != head || distance >= span) { continue; } long depth = Math.clamp(Math.round(PLUNGE_RATIO * fall.drop() * (0.85D + 0.15D * variation)), PLUNGE_MIN_DEPTH, PLUNGE_MAX_DEPTH); - double u = distance / (10D * fall.radius()); + double u = distance / span; double bowl = 1D - u * u * (3D - 2D * u); carved = (int) Math.min(carved, head - 1L - Math.round((depth - 1L) * bowl)); } @@ -216,7 +221,11 @@ final class RiffleProfile { } } - private record Plunge(Fall fall, int[] distances) { + private record Plunge(Fall fall, int[] distances, int[] brinks) { + double span(int cell) { + double radius = 10D * fall.radius(); + return brinks == null ? radius : Math.min(radius, distances[cell] + (double) brinks[cell]); + } } private static final class DistanceField { diff --git a/core/src/test/java/art/arcane/iris/generation/hydrology/raster/RiffleProfileTest.java b/core/src/test/java/art/arcane/iris/generation/hydrology/raster/RiffleProfileTest.java index 46efd3162..035726092 100644 --- a/core/src/test/java/art/arcane/iris/generation/hydrology/raster/RiffleProfileTest.java +++ b/core/src/test/java/art/arcane/iris/generation/hydrology/raster/RiffleProfileTest.java @@ -87,6 +87,38 @@ public class RiffleProfileTest { } } + @Test + public void plungePoolsTailOutBeforeTheNextStep() { + Surface pool = new Surface((x, z) -> x < 0 ? 110 : 98); + for (int brink : new int[]{5, 2, 1}) { + int next = brink + 1; + Surface stepped = new Surface((x, z) -> x < 0 ? 110 : x < next ? 98 : 96); + for (int z = -8; z <= 8; z++) { + for (int original : new int[]{92, 96}) { + String bed = original + " bed at z " + z + " with the next step's brink at x " + brink; + assertEquals("lip sill for the " + bed, 109, stepped.bed(-1, z, original)); + if (original == 96) { + assertEquals("plunge floor under the fall for the " + bed, pool.bed(0, z, original), stepped.bed(0, z, original)); + } + assertTrue("plunge pool at the foot for the " + bed, stepped.bed(0, z, original) <= 95); + assertEquals("1-block water over the brink for the " + bed, 97, stepped.bed(brink, z, original)); + for (int x = 0; x < brink; x++) { + int here = stepped.bed(x, z, original); + assertTrue("deepest at the foot, at " + x + " for the " + bed, stepped.bed(0, z, original) <= here); + assertTrue("tailout rises toward the brink at " + x + " for the " + bed, here <= stepped.bed(x + 1, z, original)); + if (brink >= 5) { + assertTrue("tailout face at " + x + " for the " + bed, stepped.bed(x + 1, z, original) - here <= 2); + } + } + } + } + } + Surface wedged = new Surface((x, z) -> x < 0 ? 110 : x < 1 ? 98 : 96); + for (int z = -8; z <= 8; z++) { + assertEquals("a foot that is also the next step's brink keeps the sill at z " + z, 97, wedged.bed(0, z, 92)); + } + } + @Test public void plungeFieldsMatchAcrossChunkBorders() { IntBinaryOperator heads = (x, z) -> x + z < -7 ? 110 : 98;