mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 00:04:42 +00:00
Integrate lane A plunge pools
- Merge lane A Task 15 (6aafec196,90205dc5f): plunge pools below falls, junction seam and tongue fixes, outlet zone step hold. - No textual conflicts; ConfluenceIncisionTest keeps the integration MAX_WALL_CUT of 29 beside lane A's shared valley scene and tongue test. - Pinned constants unchanged: schema digest, hydrology fingerprint and golden hashes pass as merged.
This commit is contained in:
commit
f76bb19597
11 files changed
+523
-79
No files matched your search
@@ -50,7 +50,7 @@ final class ChunkFeatures {
|
||||
|
||||
static ChunkFeatures gather(HydrologySettings settings, int chunkX, int chunkZ, int halo, List<IndexedWindow> windows,
|
||||
List<RegionPlan> lakeRegionPlans, List<RegionKey> lakeRegions) {
|
||||
Links links = new Links(windowsByKey(chunkX, chunkZ, windows));
|
||||
Links links = new Links(windowsByKey(chunkX, chunkZ, windows), settings.seaLevel());
|
||||
List<Reach> reaches = new ArrayList<>();
|
||||
List<Pond> ponds = new ArrayList<>();
|
||||
List<SeaInlet> inlets = new ArrayList<>();
|
||||
@@ -296,11 +296,13 @@ final class ChunkFeatures {
|
||||
|
||||
private static final class Links {
|
||||
private final Map<WindowKey, IndexedWindow> windows;
|
||||
private final int seaLevel;
|
||||
private final Map<Long, Reach> resolved = new HashMap<>();
|
||||
private final Set<Long> resolving = new HashSet<>();
|
||||
|
||||
private Links(Map<WindowKey, IndexedWindow> windows) {
|
||||
private Links(Map<WindowKey, IndexedWindow> windows, int seaLevel) {
|
||||
this.windows = windows;
|
||||
this.seaLevel = seaLevel;
|
||||
}
|
||||
|
||||
private Reach resolve(Reach reach, WindowKey owner) {
|
||||
@@ -320,7 +322,7 @@ final class ChunkFeatures {
|
||||
private Reach link(Reach reach, WindowKey owner) {
|
||||
Integer pondLevel = outletLevel(reach, owner);
|
||||
Reach linked = feederLink(reach, owner, pondLevel != null || reach.style()[0] == ReachStyle.POND_OUTLET);
|
||||
return settle(reach, pondLevel == null ? linked : LinkBlend.clamp(linked, pondLevel), owner);
|
||||
return settle(reach, pondLevel == null ? linked : LinkBlend.clamp(linked, pondLevel, seaLevel), owner);
|
||||
}
|
||||
|
||||
private Reach settle(Reach feeder, Reach linked, WindowKey owner) {
|
||||
@@ -342,7 +344,7 @@ final class ChunkFeatures {
|
||||
receiving.add(LinkBlend.footprint(sibling));
|
||||
}
|
||||
}
|
||||
return LinkBlend.settleInto(linked, level, receiving, lips(feeder, owner));
|
||||
return LinkBlend.settleInto(linked, new LinkBlend.Junction(level, fed(feeder)), receiving, lips(feeder, owner), seaLevel);
|
||||
}
|
||||
|
||||
private IndexedWindow ownerOf(long id) {
|
||||
@@ -376,7 +378,12 @@ final class ChunkFeatures {
|
||||
for (Reach reach : joining) {
|
||||
feeders.add(cornerBlock(reach) == block ? resolve(reach, link) : reach);
|
||||
}
|
||||
return link.equals(owner) || outlet ? LinkBlend.clamp(downstream, feeders) : LinkBlend.blend(downstream, feeders);
|
||||
return link.equals(owner) || outlet ? LinkBlend.clamp(downstream, feeders, seaLevel) : LinkBlend.blend(downstream, feeders, seaLevel);
|
||||
}
|
||||
|
||||
private boolean fed(Reach reach) {
|
||||
int junction = junction(reach);
|
||||
return !feeders(windowAt(reach, junction), reach.id()).isEmpty() || junction > 0 && !feeders(windowAt(reach, 0), reach.id()).isEmpty();
|
||||
}
|
||||
|
||||
private List<Reach> feeders(WindowKey key, long downstreamId) {
|
||||
|
||||
@@ -22,7 +22,7 @@ public final class LinkBlend {
|
||||
return from + (to - from) * share;
|
||||
}
|
||||
|
||||
static Reach blend(Reach downstream, List<Reach> feeders) {
|
||||
static Reach blend(Reach downstream, List<Reach> feeders, int seaLevel) {
|
||||
float width = 0f;
|
||||
float depth = 0f;
|
||||
for (Reach feeder : feeders) {
|
||||
@@ -44,21 +44,22 @@ public final class LinkBlend {
|
||||
halfWidth[point] += blend(widthShift, 0f, along);
|
||||
depths[point] += blend(depthShift, 0f, along);
|
||||
}
|
||||
return regraded(downstream, clamped(downstream.grade(), lowestEnd(feeders)), halfWidth, depths);
|
||||
return regraded(downstream, clamped(downstream.grade(), lowestEnd(feeders)), halfWidth, depths, seaLevel);
|
||||
}
|
||||
|
||||
static Reach clamp(Reach downstream, List<Reach> feeders) {
|
||||
return clamp(downstream, lowestEnd(feeders));
|
||||
static Reach clamp(Reach downstream, List<Reach> feeders, int seaLevel) {
|
||||
return clamp(downstream, lowestEnd(feeders), seaLevel);
|
||||
}
|
||||
|
||||
static Reach clamp(Reach downstream, int end) {
|
||||
static Reach clamp(Reach downstream, int end, int seaLevel) {
|
||||
int[] grade = clamped(downstream.grade(), end);
|
||||
return grade == downstream.grade() ? downstream : regraded(downstream, grade, downstream.halfWidth(), downstream.depth());
|
||||
return grade == downstream.grade() ? downstream : regraded(downstream, grade, downstream.halfWidth(), downstream.depth(), seaLevel);
|
||||
}
|
||||
|
||||
static Reach settleInto(Reach feeder, int level, List<ConfluenceGrader.Footprint> receiving, List<PondMask> lips) {
|
||||
static Reach settleInto(Reach feeder, Junction junction, List<ConfluenceGrader.Footprint> receiving, List<PondMask> lips, int seaLevel) {
|
||||
int[] grade = feeder.grade();
|
||||
boolean[] fixed = fixed(feeder, lips);
|
||||
int level = junction.level();
|
||||
boolean[] fixed = fixed(feeder, lips, junction.fed() && grade[0] - level > ConfluenceGrader.MAX_START_LOWERING);
|
||||
int waterfallMinimumDrop = feeder.tier().waterfallMinimumDrop();
|
||||
int[] settled = ConfluenceGrader.settle(footprint(feeder), grade, fixed, receiving, level, waterfallMinimumDrop);
|
||||
if (settled == grade) {
|
||||
@@ -67,25 +68,29 @@ public final class LinkBlend {
|
||||
if (!feeder.tier().cascades()) {
|
||||
ConfluenceGrader.spreadJunction(settled, grade, fixed, waterfallMinimumDrop, Integer.MIN_VALUE);
|
||||
}
|
||||
return regraded(feeder, settled, feeder.halfWidth(), feeder.depth());
|
||||
return regraded(feeder, settled, feeder.halfWidth(), feeder.depth(), seaLevel);
|
||||
}
|
||||
|
||||
static ConfluenceGrader.Footprint footprint(Reach reach) {
|
||||
return new ConfluenceGrader.Footprint(reach.xs(), reach.zs(), reach.halfWidth());
|
||||
}
|
||||
|
||||
private static boolean[] fixed(Reach feeder, List<PondMask> lips) {
|
||||
private static boolean[] fixed(Reach feeder, List<PondMask> lips, boolean heldStart) {
|
||||
ReachStyle[] style = feeder.style();
|
||||
boolean[] fixed = new boolean[style.length];
|
||||
boolean held = !lips.isEmpty();
|
||||
fixed[0] = true;
|
||||
fixed[0] = held || heldStart || style[0] == ReachStyle.POND_OUTLET;
|
||||
for (int point = 1; point < style.length; point++) {
|
||||
held = held && nearLip(lips, feeder.xs()[point], feeder.zs()[point], feeder.halfWidth()[point]);
|
||||
fixed[point] = held || style[point] == ReachStyle.POND_OUTLET;
|
||||
fixed[point] = held || style[point] == ReachStyle.POND_OUTLET || zoneStep(feeder, fixed, point);
|
||||
}
|
||||
return fixed;
|
||||
}
|
||||
|
||||
private static boolean zoneStep(Reach feeder, boolean[] fixed, int point) {
|
||||
return fixed[point - 1] && feeder.style()[point] == ReachStyle.CASCADE && feeder.grade()[point - 1] - feeder.grade()[point] == 1;
|
||||
}
|
||||
|
||||
private static boolean nearLip(List<PondMask> lips, float x, float z, float halfWidth) {
|
||||
for (PondMask lip : lips) {
|
||||
if (ReachShaper.nearLip(lip, x, z, halfWidth)) {
|
||||
@@ -95,20 +100,20 @@ public final class LinkBlend {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static Reach regraded(Reach reach, int[] grade, float[] halfWidth, float[] depth) {
|
||||
ReachStyle[] style = grade == reach.grade() ? reach.style() : restyled(reach.style(), grade, reach.tier().waterfallMinimumDrop());
|
||||
private static Reach regraded(Reach reach, int[] grade, float[] halfWidth, float[] depth, int seaLevel) {
|
||||
ReachStyle[] style = grade == reach.grade() ? reach.style() : restyled(reach.style(), grade, reach.tier().waterfallMinimumDrop(), seaLevel);
|
||||
return new Reach(reach.id(), reach.tier(), reach.downstreamId(), reach.xs(), reach.zs(), grade, halfWidth, depth, style,
|
||||
reach.catchment());
|
||||
}
|
||||
|
||||
private static ReachStyle[] restyled(ReachStyle[] style, int[] grade, int waterfallMinimumDrop) {
|
||||
private static ReachStyle[] restyled(ReachStyle[] style, int[] grade, int waterfallMinimumDrop, int seaLevel) {
|
||||
boolean[] mouth = new boolean[style.length];
|
||||
boolean[] outlet = new boolean[style.length];
|
||||
for (int point = 0; point < style.length; point++) {
|
||||
mouth[point] = style[point] == ReachStyle.MOUTH;
|
||||
outlet[point] = style[point] == ReachStyle.POND_OUTLET;
|
||||
}
|
||||
return ReachShaper.styles(grade, mouth, outlet, waterfallMinimumDrop);
|
||||
return ReachShaper.styles(grade, mouth, outlet, waterfallMinimumDrop, seaLevel);
|
||||
}
|
||||
|
||||
private static int lowestEnd(List<Reach> feeders) {
|
||||
@@ -131,4 +136,7 @@ public final class LinkBlend {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
record Junction(int level, boolean fed) {
|
||||
}
|
||||
}
|
||||
@@ -73,6 +73,7 @@ final class RasterComposer {
|
||||
column(cell);
|
||||
}
|
||||
}
|
||||
styleSeams();
|
||||
gradeRiffles();
|
||||
raiseDams();
|
||||
bermEdges();
|
||||
@@ -277,6 +278,30 @@ final class RasterComposer {
|
||||
return (int) Math.clamp((long) Math.floor(level + rise), level, ground);
|
||||
}
|
||||
|
||||
private void styleSeams() {
|
||||
for (int cell = 0; cell < CELLS; cell++) {
|
||||
if (!interior(cell) || role[cell] != WaterRole.CHANNEL) {
|
||||
continue;
|
||||
}
|
||||
int drop = 0;
|
||||
int waterfallMinimumDrop = Integer.MAX_VALUE;
|
||||
for (int side : SIDES) {
|
||||
int upper = cell + side;
|
||||
if (!role[upper].flowing() || feature[upper] == feature[cell]) {
|
||||
continue;
|
||||
}
|
||||
int step = head[upper] - head[cell];
|
||||
if (step >= 2 && step > drop) {
|
||||
drop = step;
|
||||
waterfallMinimumDrop = tier[upper].waterfallMinimumDrop();
|
||||
}
|
||||
}
|
||||
if (drop > 0) {
|
||||
role[cell] = drop >= waterfallMinimumDrop ? WaterRole.WATERFALL : WaterRole.CASCADE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void gradeRiffles() {
|
||||
int surface = Integer.MIN_VALUE;
|
||||
for (int cell = 0; cell < CELLS && surface == Integer.MIN_VALUE; cell++) {
|
||||
@@ -287,7 +312,7 @@ final class RasterComposer {
|
||||
if (surface == Integer.MIN_VALUE || features.hasOnlyLevel(surface, settings.seaLevel())) {
|
||||
return;
|
||||
}
|
||||
RiffleProfile riffles = new RiffleProfile((originX + 1) >> 4, (originZ + 1) >> 4, this::headAt);
|
||||
RiffleProfile riffles = new RiffleProfile((originX + 1) >> 4, (originZ + 1) >> 4, this::sample);
|
||||
for (int cell = 0; cell < CELLS; cell++) {
|
||||
if (interior(cell) && head[cell] != Integer.MIN_VALUE) {
|
||||
int x = originX + cell % GRID;
|
||||
@@ -298,26 +323,34 @@ final class RasterComposer {
|
||||
}
|
||||
}
|
||||
|
||||
private int headAt(int x, int z) {
|
||||
private void sample(int x, int z, RiffleProfile.Sample sample) {
|
||||
int gx = x - originX;
|
||||
int gz = z - originZ;
|
||||
if (gx >= 0 && gx < GRID && gz >= 0 && gz < GRID && !corner(gz * GRID + gx)) {
|
||||
return head[gz * GRID + gx];
|
||||
int cell = gz * GRID + gx;
|
||||
sample.set(head[cell], feature[cell], role[cell]);
|
||||
return;
|
||||
}
|
||||
SeaInlet inlet = features.openInletAt(x, z, inletColumn);
|
||||
if (inlet != null) {
|
||||
return WaterHeads.snap(inlet.waterLevel(), settings.seaLevel());
|
||||
sample.set(WaterHeads.snap(inlet.waterLevel(), settings.seaLevel()), inlet.id(), WaterRole.INLET);
|
||||
return;
|
||||
}
|
||||
int lake = features.lakeCovers(x, z) ? features.lakeAt(x, z, naturalAt(x, z)) : -1;
|
||||
if (lake >= 0) {
|
||||
return WaterHeads.snap(features.lake(lake).level(), settings.seaLevel());
|
||||
sample.set(WaterHeads.snap(features.lake(lake).level(), settings.seaLevel()), features.lake(lake).id(), WaterRole.POND);
|
||||
return;
|
||||
}
|
||||
int pond = features.pondAt(x, z);
|
||||
if (pond >= 0) {
|
||||
return WaterHeads.snap(features.pond(pond).level(), settings.seaLevel());
|
||||
sample.set(WaterHeads.snap(features.pond(pond).level(), settings.seaLevel()), features.pond(pond).id(), WaterRole.POND);
|
||||
return;
|
||||
}
|
||||
features.segments().nearest(x, z, ReachSegments.Scope.CHANNEL, cursor);
|
||||
return cursor.channel.reach == null ? Integer.MIN_VALUE : WaterHeads.snap(cursor.channel.reach.grade()[cursor.channel.point()], settings.seaLevel());
|
||||
ReachCursor.Choice hit = cursor.channel;
|
||||
if (hit.reach != null) {
|
||||
sample.set(WaterHeads.snap(hit.grade(), settings.seaLevel()), hit.reach.id(), role(hit.reach.style()[hit.point()]));
|
||||
}
|
||||
}
|
||||
|
||||
private int pondFloor(int index, int level, int x, int z, int ground, double variation, double detail) {
|
||||
|
||||
+169
-38
@@ -3,11 +3,18 @@ package art.arcane.iris.generation.hydrology.raster;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.TreeSet;
|
||||
import java.util.function.IntBinaryOperator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
final class RiffleProfile {
|
||||
static final int RADIUS = 16;
|
||||
static final int PLUNGE_MIN_DROP = 6;
|
||||
static final double PLUNGE_RATIO = 0.5D;
|
||||
static final int PLUNGE_MAX_DEPTH = 8;
|
||||
private static final int PLUNGE_MIN_DEPTH = 2;
|
||||
private static final double PLUNGE_RADIUS_RATIO = 0.75D;
|
||||
private static final double PLUNGE_MIN_RADIUS = 3D;
|
||||
private static final double PLUNGE_MAX_RADIUS = 12D;
|
||||
private static final int CHUNK = 16;
|
||||
private static final int PADDING = RADIUS + 1;
|
||||
private static final int GRID = CHUNK + 2 * PADDING;
|
||||
@@ -17,48 +24,44 @@ final class RiffleProfile {
|
||||
private static final int[] SIDES = {1, -1, GRID, -GRID};
|
||||
private static final int[] REMAINING = remaining();
|
||||
|
||||
private final int[] heads = new int[GRID * GRID];
|
||||
private final long[] features = new long[GRID * GRID];
|
||||
private final boolean[] flowing = new boolean[GRID * GRID];
|
||||
private final List<Field> fields = new ArrayList<>();
|
||||
private final List<Plunge> plunges = new ArrayList<>();
|
||||
|
||||
RiffleProfile(int chunkX, int chunkZ, IntBinaryOperator headAt) {
|
||||
int[] heads = new int[GRID * GRID];
|
||||
int[] crests = new int[GRID * GRID];
|
||||
RiffleProfile(int chunkX, int chunkZ, Water water) {
|
||||
int originX = (chunkX << 4) - PADDING;
|
||||
int originZ = (chunkZ << 4) - PADDING;
|
||||
Arrays.fill(crests, DRY);
|
||||
Sample sample = new Sample();
|
||||
for (int cell = 0; cell < heads.length; cell++) {
|
||||
heads[cell] = headAt.applyAsInt(originX + cell % GRID, originZ + cell / GRID);
|
||||
sample.set(DRY, 0L, WaterRole.NONE);
|
||||
water.sample(originX + cell % GRID, originZ + cell / GRID, sample);
|
||||
heads[cell] = sample.head;
|
||||
features[cell] = sample.feature;
|
||||
flowing[cell] = sample.role.flowing();
|
||||
}
|
||||
TreeSet<Integer> levels = new TreeSet<>();
|
||||
TreeMap<Crest, Seeds> crests = new TreeMap<>();
|
||||
TreeMap<Fall, Seeds> feet = new TreeMap<>();
|
||||
for (int z = 1; z < GRID - 1; z++) {
|
||||
for (int x = 1; x < GRID - 1; x++) {
|
||||
int cell = z * GRID + x;
|
||||
if (heads[cell] == DRY) {
|
||||
continue;
|
||||
}
|
||||
for (int side : SIDES) {
|
||||
if (heads[cell + side] != DRY && heads[cell + side] <= heads[cell] - 2) {
|
||||
crests[cell] = heads[cell] - 1;
|
||||
levels.add(crests[cell]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
collect(z * GRID + x, crests, feet);
|
||||
}
|
||||
}
|
||||
if (levels.isEmpty()) {
|
||||
if (crests.isEmpty() && feet.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
DistanceField distances = new DistanceField(heads);
|
||||
for (int crest : levels) {
|
||||
distances.reset();
|
||||
for (int cell = 0; cell < crests.length; cell++) {
|
||||
if (crests[cell] == crest) {
|
||||
distances.offer(cell, 0);
|
||||
}
|
||||
}
|
||||
distances.spread();
|
||||
int[] output = distances.output();
|
||||
for (Map.Entry<Crest, Seeds> crest : crests.entrySet()) {
|
||||
int[] output = distances.measure(crest.getValue(), DistanceField.ANY_LEVEL, LIMIT);
|
||||
if (output != null) {
|
||||
fields.add(new Field(crest, output));
|
||||
fields.add(new Field(crest.getKey(), output));
|
||||
}
|
||||
}
|
||||
for (Map.Entry<Fall, Seeds> fall : feet.entrySet()) {
|
||||
int[] output = distances.measure(fall.getValue(), fall.getKey().foot(), fall.getKey().reach());
|
||||
if (output != null) {
|
||||
plunges.add(new Plunge(fall.getKey(), output));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -68,9 +71,13 @@ final class RiffleProfile {
|
||||
return original;
|
||||
}
|
||||
int cell = (localZ + 1) * OUTPUT + localX + 1;
|
||||
int grid = (localZ + PADDING) * GRID + localX + PADDING;
|
||||
double raised = original;
|
||||
for (Field field : fields) {
|
||||
int crest = Math.min(head - 1, field.crest());
|
||||
if (skips(field.crest(), grid, head)) {
|
||||
continue;
|
||||
}
|
||||
int crest = Math.min(head - 1, field.crest().level());
|
||||
if (crest <= original) {
|
||||
continue;
|
||||
}
|
||||
@@ -83,7 +90,52 @@ final class RiffleProfile {
|
||||
double blend = 1D - u * u * (3D - 2D * u);
|
||||
raised = Math.max(raised, original + (crest - (double) original) * blend);
|
||||
}
|
||||
return (int) Math.max(original, Math.min(head - 1L, Math.round(raised)));
|
||||
int riffled = (int) Math.max(original, Math.min(head - 1L, Math.round(raised)));
|
||||
return flowing[grid] ? plunge(cell, riffled, head, variation) : riffled;
|
||||
}
|
||||
|
||||
private void collect(int cell, TreeMap<Crest, Seeds> crests, TreeMap<Fall, Seeds> feet) {
|
||||
int head = heads[cell];
|
||||
if (head == DRY) {
|
||||
return;
|
||||
}
|
||||
boolean crest = false;
|
||||
for (int side : SIDES) {
|
||||
int neighbour = heads[cell + side];
|
||||
if (neighbour == DRY) {
|
||||
continue;
|
||||
}
|
||||
crest |= neighbour <= head - 2;
|
||||
if (flowing[cell] && neighbour - head >= PLUNGE_MIN_DROP) {
|
||||
feet.computeIfAbsent(new Fall(head, neighbour), ignored -> new Seeds()).add(cell);
|
||||
}
|
||||
}
|
||||
if (crest) {
|
||||
crests.computeIfAbsent(new Crest(head - 1, features[cell], flowing[cell]), ignored -> new Seeds()).add(cell);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean skips(Crest crest, int grid, int head) {
|
||||
if (crest.level() - (head - 1) >= PLUNGE_MIN_DROP - 1) {
|
||||
return true;
|
||||
}
|
||||
return crest.level() > head - 1 && crest.flowing() && flowing[grid] && crest.feature() != features[grid];
|
||||
}
|
||||
|
||||
private int plunge(int cell, int bed, int head, double variation) {
|
||||
int carved = bed;
|
||||
for (Plunge plunge : plunges) {
|
||||
Fall fall = plunge.fall();
|
||||
int distance = plunge.distances()[cell];
|
||||
if (fall.foot() != head || distance >= 10D * fall.radius()) {
|
||||
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 bowl = 1D - u * u * (3D - 2D * u);
|
||||
carved = (int) Math.min(carved, head - 1L - Math.round((depth - 1L) * bowl));
|
||||
}
|
||||
return carved;
|
||||
}
|
||||
|
||||
private static int[] remaining() {
|
||||
@@ -100,29 +152,108 @@ final class RiffleProfile {
|
||||
return remaining;
|
||||
}
|
||||
|
||||
private record Field(int crest, int[] distances) {
|
||||
@FunctionalInterface
|
||||
interface Water {
|
||||
void sample(int x, int z, Sample sample);
|
||||
}
|
||||
|
||||
static final class Sample {
|
||||
private int head;
|
||||
private long feature;
|
||||
private WaterRole role;
|
||||
|
||||
void set(int head, long feature, WaterRole role) {
|
||||
this.head = head;
|
||||
this.feature = feature;
|
||||
this.role = role;
|
||||
}
|
||||
}
|
||||
|
||||
private record Crest(int level, long feature, boolean flowing) implements Comparable<Crest> {
|
||||
@Override
|
||||
public int compareTo(Crest other) {
|
||||
if (level != other.level) {
|
||||
return Integer.compare(level, other.level);
|
||||
}
|
||||
if (feature != other.feature) {
|
||||
return Long.compare(feature, other.feature);
|
||||
}
|
||||
return Boolean.compare(flowing, other.flowing);
|
||||
}
|
||||
}
|
||||
|
||||
private record Fall(int foot, int top) implements Comparable<Fall> {
|
||||
int drop() {
|
||||
return top - foot;
|
||||
}
|
||||
|
||||
double radius() {
|
||||
return Math.clamp(PLUNGE_RADIUS_RATIO * drop(), PLUNGE_MIN_RADIUS, PLUNGE_MAX_RADIUS);
|
||||
}
|
||||
|
||||
int reach() {
|
||||
return (int) Math.ceil(10D * radius());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Fall other) {
|
||||
return foot != other.foot ? Integer.compare(foot, other.foot) : Integer.compare(top, other.top);
|
||||
}
|
||||
}
|
||||
|
||||
private record Field(Crest crest, int[] distances) {
|
||||
}
|
||||
|
||||
private static final class Seeds {
|
||||
private int[] cells = new int[16];
|
||||
private int size;
|
||||
|
||||
private void add(int cell) {
|
||||
if (size == cells.length) {
|
||||
cells = Arrays.copyOf(cells, 2 * size);
|
||||
}
|
||||
cells[size++] = cell;
|
||||
}
|
||||
}
|
||||
|
||||
private record Plunge(Fall fall, int[] distances) {
|
||||
}
|
||||
|
||||
private static final class DistanceField {
|
||||
private static final int ANY_LEVEL = Integer.MAX_VALUE;
|
||||
|
||||
private final int[] heads;
|
||||
private final int[] distances = new int[GRID * GRID];
|
||||
private final int[] next = new int[GRID * GRID];
|
||||
private final int[] previous = new int[GRID * GRID];
|
||||
private final int[] first = new int[LIMIT];
|
||||
private int level;
|
||||
private int limit;
|
||||
|
||||
private DistanceField(int[] heads) {
|
||||
this.heads = heads;
|
||||
}
|
||||
|
||||
private void reset() {
|
||||
private int[] measure(Seeds seeds, int passable, int reach) {
|
||||
level = passable;
|
||||
limit = reach;
|
||||
Arrays.fill(distances, LIMIT);
|
||||
Arrays.fill(next, -1);
|
||||
Arrays.fill(previous, -1);
|
||||
Arrays.fill(first, -1);
|
||||
for (int seed = 0; seed < seeds.size; seed++) {
|
||||
offer(seeds.cells[seed], 0);
|
||||
}
|
||||
spread();
|
||||
return output();
|
||||
}
|
||||
|
||||
private boolean blocked(int cell) {
|
||||
return heads[cell] == DRY || level != ANY_LEVEL && heads[cell] != level;
|
||||
}
|
||||
|
||||
private void offer(int cell, int distance) {
|
||||
if (distance + REMAINING[cell] >= LIMIT) {
|
||||
if (distance + REMAINING[cell] >= limit) {
|
||||
return;
|
||||
}
|
||||
if (distances[cell] < LIMIT) {
|
||||
@@ -151,7 +282,7 @@ final class RiffleProfile {
|
||||
}
|
||||
|
||||
private void spread() {
|
||||
for (int distance = 0; distance < LIMIT; distance++) {
|
||||
for (int distance = 0; distance < limit; distance++) {
|
||||
while (first[distance] >= 0) {
|
||||
int cell = first[distance];
|
||||
remove(cell);
|
||||
@@ -166,10 +297,10 @@ final class RiffleProfile {
|
||||
}
|
||||
int neighbour = nz * GRID + nx;
|
||||
int candidate = distance + (dx != 0 && dz != 0 ? 14 : 10);
|
||||
if (heads[neighbour] == DRY || candidate >= distances[neighbour]) {
|
||||
if (blocked(neighbour) || candidate >= distances[neighbour]) {
|
||||
continue;
|
||||
}
|
||||
if (dx != 0 && dz != 0 && (heads[z * GRID + nx] == DRY || heads[nz * GRID + x] == DRY)) {
|
||||
if (dx != 0 && dz != 0 && (blocked(z * GRID + nx) || blocked(nz * GRID + x))) {
|
||||
continue;
|
||||
}
|
||||
offer(neighbour, candidate);
|
||||
|
||||
@@ -29,4 +29,11 @@ public enum WaterRole {
|
||||
case NONE, BANK, SHORE, POND_SHORE, DAM -> false;
|
||||
};
|
||||
}
|
||||
|
||||
public boolean flowing() {
|
||||
return switch (this) {
|
||||
case CHANNEL, CASCADE, WATERFALL -> true;
|
||||
case NONE, BANK, SHORE, POND, POND_SHORE, DAM, MOUTH, INLET -> false;
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import art.arcane.iris.generation.hydrology.grid.HeightLattice;
|
||||
import art.arcane.iris.generation.hydrology.plan.HydrologySettings;
|
||||
import art.arcane.iris.generation.hydrology.plan.WindowKey;
|
||||
import art.arcane.iris.generation.hydrology.raster.LinkBlend;
|
||||
import art.arcane.iris.generation.hydrology.raster.WaterHeads;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -75,7 +76,7 @@ public final class ReachShaper {
|
||||
int[] order = upstreamFirst(drafts, chain);
|
||||
int[] levels = ReachGrader.grade(drafts, order, settings.seaLevel(), settings.deformation().maxFill(), chain);
|
||||
for (int index : order) {
|
||||
finish(drafts, drafts.get(index));
|
||||
finish(drafts, drafts.get(index), settings.seaLevel());
|
||||
}
|
||||
for (int index = 0; index < sources.length; index++) {
|
||||
if (leavesThroughALip(ponds, sources[index])) {
|
||||
@@ -85,7 +86,7 @@ public final class ReachShaper {
|
||||
boolean[] touched = ConfluenceGrader.level(window, drafts, order);
|
||||
for (int index = 0; index < touched.length; index++) {
|
||||
if (touched[index]) {
|
||||
restyle(drafts.get(index));
|
||||
restyle(drafts.get(index), settings.seaLevel());
|
||||
}
|
||||
}
|
||||
List<Pond> linked = new ArrayList<>(ponds.size());
|
||||
@@ -362,7 +363,7 @@ public final class ReachShaper {
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void finish(List<ReachDraft> drafts, ReachDraft draft) {
|
||||
private static void finish(List<ReachDraft> drafts, ReachDraft draft, int seaLevel) {
|
||||
draft.outletZone = new boolean[draft.xs.length];
|
||||
float[] distance = distances(draft.xs, draft.zs);
|
||||
for (int point = 0; point < distance.length; point++) {
|
||||
@@ -380,11 +381,11 @@ public final class ReachShaper {
|
||||
feederEnd = Math.max(feederEnd, feeder.halfWidth[feeder.halfWidth.length - 1]);
|
||||
}
|
||||
widths(draft, upstream, feederEnd);
|
||||
restyle(draft);
|
||||
restyle(draft, seaLevel);
|
||||
}
|
||||
|
||||
private static void restyle(ReachDraft draft) {
|
||||
draft.style = styles(draft.grade, draft.ocean, draft.fixed(), draft.tier.waterfallMinimumDrop());
|
||||
private static void restyle(ReachDraft draft, int seaLevel) {
|
||||
draft.style = styles(draft.grade, draft.ocean, draft.fixed(), draft.tier.waterfallMinimumDrop(), seaLevel);
|
||||
}
|
||||
|
||||
private static void chaikin(ReachDraft draft) {
|
||||
@@ -547,11 +548,15 @@ public final class ReachShaper {
|
||||
return Math.clamp(1f - remaining / length, 0f, 1f);
|
||||
}
|
||||
|
||||
public static ReachStyle[] styles(int[] grade, boolean[] ocean, boolean[] outletZone, int waterfallMinimumDrop) {
|
||||
public static ReachStyle[] styles(int[] grade, boolean[] ocean, boolean[] outletZone, int waterfallMinimumDrop, int seaLevel) {
|
||||
ReachStyle[] styles = new ReachStyle[grade.length];
|
||||
for (int point = 0; point < grade.length; point++) {
|
||||
int drop = point == 0 ? 0 : grade[point - 1] - grade[point];
|
||||
styles[point] = style(drop, waterfallMinimumDrop, ocean[point], outletZone[point]);
|
||||
if (drop == 1 && !ocean[point] && outletZone[point - 1]
|
||||
&& WaterHeads.snap(grade[point - 1], seaLevel) - WaterHeads.snap(grade[point], seaLevel) >= 2) {
|
||||
styles[point] = ReachStyle.CASCADE;
|
||||
}
|
||||
}
|
||||
for (int point = 1; point < grade.length; point++) {
|
||||
if (styles[point] == ReachStyle.MOUTH && styles[point - 1] != ReachStyle.MOUTH
|
||||
|
||||
+20
-1
@@ -6,6 +6,7 @@ import art.arcane.iris.generation.hydrology.water.Pond;
|
||||
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 org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -26,10 +27,16 @@ public class ConfluenceIncisionTest {
|
||||
private static final double WALL_FACE_REACH = 24D;
|
||||
private static final double MAX_WALL_CUT = 29D;
|
||||
private static final int MAX_COPY_DIFFERENCE = 4;
|
||||
private static PlannedScene valley;
|
||||
|
||||
@AfterClass
|
||||
public static void dropScene() {
|
||||
valley = null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void junctionPoolsNeverTrenchASlopingValley() {
|
||||
PlannedScene scene = PlannedScene.plan(SyntheticTerrain.valleySlope(), settings(), 2, 2);
|
||||
PlannedScene scene = valley();
|
||||
int points = 0;
|
||||
int deep = 0;
|
||||
String worst = "";
|
||||
@@ -52,6 +59,11 @@ public class ConfluenceIncisionTest {
|
||||
assertEquals("reach points cut more than " + DEEP_CUT + " below the valley floor, deepest " + worst, 0, deep);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void slopingValleyConfluencesHaveNoTongues() {
|
||||
assertEquals("confluence tongues on the sloping valley over 2x2 windows", List.of(), WaterInvariants.confluenceTongues(valley()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void majorDownAWallBesideTheValleyRiverFollowsTheWall() {
|
||||
SyntheticTerrain terrain = SyntheticTerrain.valleyBelowAWall(WALL_FOOT, WALL_RUN, WALL_HEIGHT);
|
||||
@@ -115,6 +127,13 @@ public class ConfluenceIncisionTest {
|
||||
assertTrue("grades of one reach differ by " + worst + " between the windows that plan it: " + worstCopy, worst <= MAX_COPY_DIFFERENCE);
|
||||
}
|
||||
|
||||
private static synchronized PlannedScene valley() {
|
||||
if (valley == null) {
|
||||
valley = PlannedScene.plan(SyntheticTerrain.valleySlope(), settings(), 2, 2);
|
||||
}
|
||||
return valley;
|
||||
}
|
||||
|
||||
private static HydrologySettings settings() {
|
||||
return HydrologySettings.compile(new IrisHydrology(), SEED, SyntheticTerrain.SEA_LEVEL, SyntheticTerrain.MIN_Y, SyntheticTerrain.MAX_Y);
|
||||
}
|
||||
|
||||
@@ -40,6 +40,12 @@ public class PlannedSceneTest {
|
||||
WaterInvariants.detachedOutlets(openFractal()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void confluencesHaveNoTongues() {
|
||||
assertEquals("confluence tongues on openFractal(1) with rainfall " + RAINFALL + " over 2x2 windows", List.of(),
|
||||
WaterInvariants.confluenceTongues(openFractal()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void feedersAtALedInOutletsExitPoolBesideTheLeadIn() {
|
||||
PlannedScene scene = openFractal();
|
||||
|
||||
+94
@@ -19,6 +19,7 @@ import art.arcane.iris.generation.hydrology.water.Pond;
|
||||
import art.arcane.iris.generation.hydrology.water.PondKind;
|
||||
import art.arcane.iris.generation.hydrology.water.PondMask;
|
||||
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 art.arcane.iris.generation.terrain.IrisMaterialPalette;
|
||||
@@ -275,6 +276,28 @@ public class ChunkWaterRasterTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fallsIntoAPondLeaveItsFloor() {
|
||||
IntBinaryOperator natural = (x, z) -> 70 + ((x - 16) * (x - 16) + (z - 16) * (z - 16)) / 20;
|
||||
Pond pond = pond(21L, PondKind.NATURAL, 75, circle(16, 16, 14, 4), 16, 16, 0);
|
||||
HydrologyTier stream = tier("stream", 1.5f, 0.5f, 4, IrisBankStyle.SMOOTH);
|
||||
Scene level = new Scene(settings(new IrisHydrology()), natural).pond(pond).reach(line(23L, stream, 0L, 16f, -48f, 16f, 6f, (x, z) -> 75));
|
||||
Scene falling = new Scene(settings(new IrisHydrology()), natural).pond(pond).reach(line(23L, stream, 0L, 16f, -48f, 16f, 6f, (x, z) -> 86));
|
||||
int checked = 0;
|
||||
for (int x = -8; x < 40; x++) {
|
||||
for (int z = -8; z < 40; z++) {
|
||||
if (falling.role(x, z) != WaterRole.POND) {
|
||||
continue;
|
||||
}
|
||||
checked++;
|
||||
assertEquals("pond floor under the fall at " + x + "," + z, level.terrain(x, z), falling.terrain(x, z));
|
||||
}
|
||||
}
|
||||
assertTrue("pond columns " + checked, checked > 400);
|
||||
assertEquals("the stream falls into the pond", 86, falling.head(16, -2));
|
||||
assertEquals(74, falling.head(16, 6));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pondColumnsShareOneLevel() {
|
||||
IntBinaryOperator natural = (x, z) -> 70 + ((x - 16) * (x - 16) + (z - 16) * (z - 16)) / 20;
|
||||
@@ -615,6 +638,26 @@ public class ChunkWaterRasterTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stepsAtTheEdgeOfALowerChannelAreStyledAsFalls() {
|
||||
HydrologyTier river = tier("river", 8f, 1f, 16, IrisBankStyle.SMOOTH);
|
||||
HydrologyTier stream = tier("stream", 2f, 0.5f, 4, IrisBankStyle.SMOOTH);
|
||||
Reach lower = line(302L, river, 0L, -96f, 8f, 120f, 8f, (x, z) -> 66);
|
||||
Map<Integer, WaterRole> styles = Map.of(68, WaterRole.CASCADE, 70, WaterRole.CASCADE, 72, WaterRole.WATERFALL);
|
||||
for (int level : new int[]{68, 70, 72}) {
|
||||
Reach perched = line(303L, stream, 0L, 16f, -72f, 16f, 8f, (x, z) -> level);
|
||||
Scene scene = new Scene(settings(new IrisHydrology()), (x, z) -> 80).reach(lower).reach(perched);
|
||||
for (int x = 15; x <= 17; x++) {
|
||||
assertEquals(level, scene.head(x, -1));
|
||||
assertEquals(66, scene.head(x, 0));
|
||||
assertEquals("the " + (level - 66) + "-block step onto the lower channel's edge at x " + x, styles.get(level), scene.role(x, 0));
|
||||
assertEquals("the perched channel above the step at x " + x, WaterRole.CHANNEL, scene.role(x, -1));
|
||||
}
|
||||
assertEquals("the lower channel away from the step", WaterRole.CHANNEL, scene.role(40, 0));
|
||||
assertEquals("the lower channel inside the perched channel's footprint", WaterRole.CHANNEL, scene.role(16, 6));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void crossWindowLinkNeverRaisesWaterDownstream() {
|
||||
HydrologyTier narrow = tier("river", 2f, 0.5f, 4, IrisBankStyle.SMOOTH);
|
||||
@@ -845,6 +888,54 @@ public class ChunkWaterRasterTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void crossWindowFedStartOneBlockAboveTheJunctionJoinsIt() {
|
||||
HydrologyTier narrow = tier("river", 2f, 0.5f, 4, IrisBankStyle.SMOOTH);
|
||||
HydrologyTier wide = tier("river", 3f, 0.5f, 4, IrisBankStyle.SMOOTH);
|
||||
Reach low = line(342L, wide, 0L, 504f, 200f, 600f, 200f, (x, z) -> 61);
|
||||
Reach stub = line(341L, narrow, low.id(), 498f, 200f, 504f, 200f, (x, z) -> 62);
|
||||
Reach upstream = line(340L, narrow, stub.id(), 440f, 200f, 498f, 200f, (x, z) -> 62);
|
||||
assertEquals(new WindowKey(0, 0), WindowKey.containing(504, 200));
|
||||
assertEquals(new WindowKey(1, 0), WindowKey.containing(600, 200));
|
||||
Scene scene = new Scene(settings(new IrisHydrology()), (x, z) -> 90).reach(upstream).reach(stub).reach(low);
|
||||
assertEquals("the stub's start one block above the junction joins it", 60, scene.head(498, 200));
|
||||
int previous = Integer.MAX_VALUE;
|
||||
for (int x = 440; x <= 600; x++) {
|
||||
int head = scene.head(x, 200);
|
||||
assertNotEquals("centre line is water at x=" + x, Integer.MIN_VALUE, head);
|
||||
assertTrue("water rises from " + previous + " to " + head + " at x=" + x, head <= previous);
|
||||
if (head < previous && previous != Integer.MAX_VALUE) {
|
||||
assertEquals("the step at x=" + x + " is styled", WaterRole.CASCADE, scene.role(x, 200));
|
||||
}
|
||||
previous = head;
|
||||
}
|
||||
assertWindowOrderFree(scene, 27, 37, 12);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void crossWindowSettlingKeepsAStepAtTheEndOfAnOutletZone() {
|
||||
HydrologyTier narrow = tier("river", 2f, 0.5f, 4, IrisBankStyle.SMOOTH);
|
||||
HydrologyTier wide = tier("river", 3f, 0.5f, 4, IrisBankStyle.SMOOTH);
|
||||
Reach low = line(332L, wide, 0L, 504f, 200f, 600f, 200f, (x, z) -> 62);
|
||||
Reach drawn = line(331L, narrow, low.id(), 492f, 200f, 504f, 200f, (x, z) -> x < 500f ? 66 : 65);
|
||||
boolean[] zone = new boolean[drawn.xs().length];
|
||||
for (int point = 0; point < zone.length; point++) {
|
||||
zone[point] = drawn.xs()[point] - drawn.xs()[0] <= 8f;
|
||||
}
|
||||
ReachStyle[] style = ReachShaper.styles(drawn.grade(), new boolean[zone.length], zone, narrow.waterfallMinimumDrop(), SEA_LEVEL);
|
||||
assertEquals("the last outlet zone point steps down one block, shown as two", ReachStyle.CASCADE, style[4]);
|
||||
assertTrue("the step lies at the end of the outlet zone", zone[4] && !zone[5]);
|
||||
Reach outlet = new Reach(drawn.id(), narrow, drawn.downstreamId(), drawn.xs(), drawn.zs(), drawn.grade(), drawn.halfWidth(), drawn.depth(),
|
||||
style, drawn.catchment());
|
||||
Scene scene = new Scene(settings(new IrisHydrology()), (x, z) -> 75).reach(outlet).reach(low);
|
||||
for (int x = 492; x <= 498; x++) {
|
||||
assertEquals("outlet zone water at x=" + x, 66, scene.head(x, 200));
|
||||
}
|
||||
assertEquals("the outlet zone keeps the step at its last point", 64, scene.head(500, 200));
|
||||
assertEquals(62, scene.head(502, 200));
|
||||
assertWindowOrderFree(scene, 30, 32, 12);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void crossWindowSettlingKeepsAnOutletsHeldLipAtThePondLevel() {
|
||||
HydrologyTier narrow = tier("river", 2f, 0.5f, 4, IrisBankStyle.SMOOTH);
|
||||
@@ -1119,6 +1210,9 @@ public class ChunkWaterRasterTest {
|
||||
if (scene.role(x, z) == WaterRole.MOUTH) {
|
||||
mouths++;
|
||||
assertEquals(banks + "mouth at sea level at " + x + "," + z, SEA_LEVEL, scene.head(x, z));
|
||||
if (x >= 40) {
|
||||
assertEquals(banks + "the fall leaves the sea floor under the mouth at " + x + "," + z, coast.applyAsInt(x, z), scene.terrain(x, z));
|
||||
}
|
||||
}
|
||||
if (scene.water(x, z)) {
|
||||
continue;
|
||||
|
||||
+118
-4
@@ -67,6 +67,99 @@ public class RiffleProfileTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fallsKeepADeepPlungePoolBelowTheCurtain() {
|
||||
Surface surface = new Surface((x, z) -> x < 0 ? 110 : 98);
|
||||
for (int z = -8; z <= 8; z++) {
|
||||
for (int original : new int[]{92, 96}) {
|
||||
String bed = original + " bed at z " + z;
|
||||
assertEquals("lip sill for the " + bed, 109, surface.bed(-1, z, original));
|
||||
assertTrue("plunge pool at the foot for the " + bed, surface.bed(0, z, original) <= 95);
|
||||
assertTrue("deepest at the foot for the " + bed, surface.bed(0, z, original) <= surface.bed(6, z, original));
|
||||
for (int x = 0; x <= 20; x++) {
|
||||
int here = surface.bed(x, z, original);
|
||||
assertTrue("pool at " + x + " stays below the " + bed, here <= original);
|
||||
assertTrue("downstream face at " + x + " in the " + bed, Math.abs(here - surface.bed(x + 1, z, original)) <= 2);
|
||||
}
|
||||
assertEquals(original, surface.bed(17, z, original));
|
||||
}
|
||||
assertTrue("the bowl cuts below a shallow bed at z " + z, surface.bed(0, z, 96) <= 94);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void plungeFieldsMatchAcrossChunkBorders() {
|
||||
IntBinaryOperator heads = (x, z) -> x + z < -7 ? 110 : 98;
|
||||
Surface surface = new Surface(heads);
|
||||
for (int x = -24; x <= 16; x++) {
|
||||
assertTrue("the foot at " + x + "," + (-7 - x) + " is carved", surface.bed(x, -7 - x, 96) < 96);
|
||||
}
|
||||
for (int chunkX = -2; chunkX <= 1; chunkX++) {
|
||||
for (int chunkZ = -2; chunkZ <= 1; chunkZ++) {
|
||||
RiffleProfile first = new RiffleProfile(chunkX, chunkZ, channel(heads));
|
||||
RiffleProfile east = new RiffleProfile(chunkX + 1, chunkZ, channel(heads));
|
||||
RiffleProfile south = new RiffleProfile(chunkX, chunkZ + 1, channel(heads));
|
||||
for (int edge = 0; edge < 16; edge++) {
|
||||
for (int original : new int[]{92, 96}) {
|
||||
int x = (chunkX + 1) << 4;
|
||||
int z = (chunkZ << 4) + edge;
|
||||
double variation = BedProfile.variation(1337L, x, z);
|
||||
assertEquals(first.bed(16, edge, original, heads.applyAsInt(x, z), variation),
|
||||
east.bed(0, edge, original, heads.applyAsInt(x, z), variation));
|
||||
x = (chunkX << 4) + edge;
|
||||
z = (chunkZ + 1) << 4;
|
||||
variation = BedProfile.variation(1337L, x, z);
|
||||
assertEquals(first.bed(edge, 16, original, heads.applyAsInt(x, z), variation),
|
||||
south.bed(edge, 0, original, heads.applyAsInt(x, z), variation));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void plungeSkipsStandingWaterAndMouths() {
|
||||
IntBinaryOperator heads = (x, z) -> x < 0 ? 110 : 98;
|
||||
IntBinaryOperator features = (x, z) -> x < 0 ? 1 : 2;
|
||||
for (WaterRole standing : new WaterRole[]{WaterRole.POND, WaterRole.MOUTH, WaterRole.INLET}) {
|
||||
Surface surface = new Surface(heads, water(heads, features, (x, z) -> x < 0 ? WaterRole.CHANNEL : standing));
|
||||
for (int z = -8; z <= 8; z++) {
|
||||
assertEquals(standing + " lip sill at z " + z, 109, surface.bed(-1, z, 92));
|
||||
for (int x = 0; x <= 20; x++) {
|
||||
assertEquals(standing + " floor at " + x + "," + z, 92, surface.bed(x, z, 92));
|
||||
assertEquals(standing + " shallow floor at " + x + "," + z, 96, surface.bed(x, z, 96));
|
||||
}
|
||||
}
|
||||
}
|
||||
Surface beside = new Surface(heads, water(heads, (x, z) -> x < 0 ? 1 : z < 0 ? 2 : 3,
|
||||
(x, z) -> x >= 0 && z >= 0 ? WaterRole.POND : WaterRole.CHANNEL));
|
||||
for (int z = -8; z <= 8; z++) {
|
||||
for (int x = 0; x <= 20; x++) {
|
||||
if (z >= 0) {
|
||||
assertEquals("pond floor beside a carved channel foot at " + x + "," + z, 96, beside.bed(x, z, 96));
|
||||
}
|
||||
}
|
||||
if (z < 0) {
|
||||
assertTrue("channel foot beside the pond at z " + z, beside.bed(0, z, 96) < 96);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void receivingChannelKeepsItsBedBelowAJoiningCascade() {
|
||||
IntBinaryOperator heads = (x, z) -> x < 0 ? 104 : 100;
|
||||
Surface joining = new Surface(heads, water(heads, (x, z) -> x < 0 ? 2 : 1, (x, z) -> WaterRole.CHANNEL));
|
||||
for (int z = -8; z <= 8; z++) {
|
||||
assertEquals("the joining channel keeps its lip sill at z " + z, 103, joining.bed(-1, z, 96));
|
||||
assertTrue("the joining channel's approach rises toward its lip at z " + z, joining.bed(-6, z, 96) > 96);
|
||||
for (int x = 0; x <= 20; x++) {
|
||||
assertEquals("receiving bed at " + x + "," + z, 96, joining.bed(x, z, 96));
|
||||
}
|
||||
}
|
||||
Surface outlet = new Surface(heads, water(heads, (x, z) -> x < 0 ? 2 : 1, (x, z) -> x < 0 ? WaterRole.POND : WaterRole.CHANNEL));
|
||||
assertEquals("a channel below a pond's shore still rises toward the lip", 99, outlet.bed(0, 0, 96));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nearbyDisconnectedPoolsKeepTheirDepth() {
|
||||
Surface surface = new Surface((x, z) -> z == 0 ? DRY : z > 0 ? 100 : x < 0 ? 100 : 98);
|
||||
@@ -97,9 +190,9 @@ public class RiffleProfileTest {
|
||||
IntBinaryOperator heads = (x, z) -> x + z < -7 ? 100 : 98;
|
||||
for (int chunkX = -2; chunkX <= 1; chunkX++) {
|
||||
for (int chunkZ = -2; chunkZ <= 1; chunkZ++) {
|
||||
RiffleProfile first = new RiffleProfile(chunkX, chunkZ, heads);
|
||||
RiffleProfile east = new RiffleProfile(chunkX + 1, chunkZ, heads);
|
||||
RiffleProfile south = new RiffleProfile(chunkX, chunkZ + 1, heads);
|
||||
RiffleProfile first = new RiffleProfile(chunkX, chunkZ, channel(heads));
|
||||
RiffleProfile east = new RiffleProfile(chunkX + 1, chunkZ, channel(heads));
|
||||
RiffleProfile south = new RiffleProfile(chunkX, chunkZ + 1, channel(heads));
|
||||
for (int edge = 0; edge < 16; edge++) {
|
||||
int x = (chunkX + 1) << 4;
|
||||
int z = (chunkZ << 4) + edge;
|
||||
@@ -116,19 +209,40 @@ public class RiffleProfileTest {
|
||||
}
|
||||
}
|
||||
|
||||
private static RiffleProfile.Water channel(IntBinaryOperator heads) {
|
||||
return water(heads, (x, z) -> 1, (x, z) -> WaterRole.CHANNEL);
|
||||
}
|
||||
|
||||
private static RiffleProfile.Water water(IntBinaryOperator heads, IntBinaryOperator features, Roles roles) {
|
||||
return (x, z, sample) -> {
|
||||
int head = heads.applyAsInt(x, z);
|
||||
sample.set(head, features.applyAsInt(x, z), head == DRY ? WaterRole.NONE : roles.at(x, z));
|
||||
};
|
||||
}
|
||||
|
||||
private interface Roles {
|
||||
WaterRole at(int x, int z);
|
||||
}
|
||||
|
||||
private static final class Surface {
|
||||
private final IntBinaryOperator heads;
|
||||
private final RiffleProfile.Water water;
|
||||
private final Map<Long, RiffleProfile> chunks = new HashMap<>();
|
||||
|
||||
private Surface(IntBinaryOperator heads) {
|
||||
this(heads, channel(heads));
|
||||
}
|
||||
|
||||
private Surface(IntBinaryOperator heads, RiffleProfile.Water water) {
|
||||
this.heads = heads;
|
||||
this.water = water;
|
||||
}
|
||||
|
||||
private int bed(int x, int z, int original) {
|
||||
int cx = x >> 4;
|
||||
int cz = z >> 4;
|
||||
long key = ((long) cx << 32) | (cz & 0xFFFFFFFFL);
|
||||
RiffleProfile profile = chunks.computeIfAbsent(key, ignored -> new RiffleProfile(cx, cz, heads));
|
||||
RiffleProfile profile = chunks.computeIfAbsent(key, ignored -> new RiffleProfile(cx, cz, water));
|
||||
return profile.bed(x & 15, z & 15, original, heads.applyAsInt(x, z), BedProfile.variation(1337L, x, z));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1581,10 +1581,30 @@ public class ReachShaperTest {
|
||||
|
||||
int[] grade = {62, 62, 62, 40, 40};
|
||||
boolean[] ocean = {false, false, false, true, true};
|
||||
ReachStyle[] styles = ReachShaper.styles(grade, ocean, new boolean[grade.length], 6);
|
||||
ReachStyle[] styles = ReachShaper.styles(grade, ocean, new boolean[grade.length], 6, SEA_LEVEL);
|
||||
assertEquals(List.of(ReachStyle.RUN, ReachStyle.RUN, ReachStyle.WATERFALL, ReachStyle.MOUTH, ReachStyle.MOUTH), List.of(styles));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void heldLipStepThatShowsAsTwoBlocksIsACascade() {
|
||||
int[] grade = {76, 76, 76, 75, 75};
|
||||
boolean[] ocean = new boolean[grade.length];
|
||||
boolean[] held = {true, true, true, false, false};
|
||||
assertEquals("a one-block step off a held lip that the even head snap shows as two blocks",
|
||||
List.of(ReachStyle.POND_OUTLET, ReachStyle.POND_OUTLET, ReachStyle.POND_OUTLET, ReachStyle.CASCADE, ReachStyle.RUN),
|
||||
List.of(ReachShaper.styles(grade, ocean, held, 6, SEA_LEVEL)));
|
||||
assertEquals("the same step hidden by the head snap", ReachStyle.RIFFLE, ReachShaper.styles(grade, ocean, held, 6, SEA_LEVEL + 1)[3]);
|
||||
assertEquals("a one-block step that leaves no held lip", ReachStyle.RIFFLE,
|
||||
ReachShaper.styles(grade, ocean, new boolean[grade.length], 6, SEA_LEVEL)[3]);
|
||||
int[] zoned = {78, 78, 77, 77, 77};
|
||||
boolean[] zone = {true, true, true, true, false};
|
||||
assertEquals("a one-block step inside an outlet zone that the head snap shows as two blocks",
|
||||
List.of(ReachStyle.POND_OUTLET, ReachStyle.POND_OUTLET, ReachStyle.CASCADE, ReachStyle.POND_OUTLET, ReachStyle.RUN),
|
||||
List.of(ReachShaper.styles(zoned, ocean, zone, 6, SEA_LEVEL)));
|
||||
assertEquals("the same step inside the zone hidden by the head snap", ReachStyle.POND_OUTLET,
|
||||
ReachShaper.styles(zoned, ocean, zone, 6, SEA_LEVEL + 1)[2]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void channelWaterStaysBelowNaturalGroundOnSmoothValleys() {
|
||||
HydrologySettings settings = settings(config -> {
|
||||
|
||||
Reference in new issue
Block a user