mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 08:44:50 +00:00
Plunge pools below falls
- RiffleProfile carves a plunge pool at the foot of every head step of 6 or more blocks in channel water: depth round(0.5 x drop x (0.85 + 0.15 x variation)) clamped to 2..8, radius clamp(0.75 x drop, 3, 12), one distance field per foot and top head pair that spreads only through the foot level, LIMIT kept at 160 - Riffle crests at least 5 blocks above a cell's sill no longer raise its bed, so the foot of a large fall stays deep while the brink keeps its head-1 sill - Plunge pools never seed in or carve pond, lake, sea inlet or mouth columns - The riffle raise below a step between two different channel reaches leaves the lower channel's bed alone (spec 11 design D); fields are keyed by crest level, feature and flowing role - RiffleProfile samples head, feature and role per column through a Water sampler; WaterRole.flowing names the channel, cascade and waterfall roles - RasterComposer styles a channel column below another channel reach's water 2 or more blocks higher as CASCADE, or WATERFALL from the higher reach's waterfallMinimumDrop - ReachShaper.styles takes the sea level and styles a one-block drop out of an outlet zone or held lip as CASCADE when the head snap shows it as a two-block step; LinkBlend restyles with the same rule - LinkBlend.settleInto holds a cross-window feeder's start only for a pond lip, a pond outlet or a fed start more than one block above the junction, the in-window p0cap1 rule - Tests: plunge pool, chunk-border and standing-water RiffleProfile cases, receiving bed below a joining cascade, styled lower-channel edges, falls into ponds and mouths keep their floors, cross-window fed start, held-lip step styles, and no confluence tongues on the cached 2x2 openFractal and sloping valley scenes
This commit is contained in:
1 parent
2edf610e8b
commit
6aafec196b
11 files changed
+485
-76
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,18 +68,18 @@ 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;
|
||||
@@ -95,20 +96,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 +132,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) {
|
||||
|
||||
+161
-36
@@ -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);
|
||||
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());
|
||||
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,25 +152,98 @@ 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);
|
||||
}
|
||||
|
||||
@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 DistanceField(int[] heads) {
|
||||
this.heads = heads;
|
||||
}
|
||||
|
||||
private void reset() {
|
||||
private int[] measure(Seeds seeds, int passable) {
|
||||
level = passable;
|
||||
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) {
|
||||
@@ -166,10 +291,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
|
||||
|
||||
Reference in new issue
Block a user