Inland lowlands not mouths

- Reach chains end at the sea only where the receiver has ocean intent
- Channels continue across non-ocean lowland below sea level toward the sea
- Fitted ocean flags stay only on the trailing run of chains that drain to the sea
- Ground reads off the sea run ignore sub-cell ocean slivers, so a sliver no longer trenches a reach or drops ponds below it
- Inland hollows below sea level hold an outlet-free pond at sea level; oversized ones sink instead of being breached
- Burned trunks neither descend nor drain through inland hollows
- Sea-head check keys on the trailing mouth run and fails closed on mouths inside a reach or draining into another reach
- Inland water keeps the land biome at any head; mouths and inlets keep the sea biome
- Tests for inland hollows, crater rims, sea slivers, inland pond outlets, coastal delta ownership and the sea-level river biome
This commit is contained in:
Brian Neumann-Fopiano committed 2026-11-02 01:57:09 -05:00
1 parent d61b5c3041
commit 30865031ba
19 files changed
+786 -112

No files matched your search

@@ -1,6 +1,6 @@
package art.arcane.iris.generation.hydrology.grid;
public record Basin(int id, int floorIndex, int spillIndex, float spillHeight, float maxDepth, int[] cells) {
public record Basin(int id, int floorIndex, int spillIndex, float spillHeight, float maxDepth, int[] cells, boolean belowSea) {
public int span(int width) {
int minI = Integer.MAX_VALUE;
int maxI = Integer.MIN_VALUE;
@@ -2,7 +2,9 @@ package art.arcane.iris.generation.hydrology.grid;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.List;
import java.util.function.IntPredicate;
public final class BasinExtractor {
private BasinExtractor() {
@@ -62,11 +64,139 @@ public final class BasinExtractor {
}
int spill = spill(raw, filled, floor, lowestFilled);
float spillHeight = heights[spill];
basins.add(new Basin(basins.size(), floor, spill, spillHeight, spillHeight - heights[floor], cells));
basins.add(new Basin(basins.size(), floor, spill, spillHeight, spillHeight - heights[floor], cells, false));
}
return basins;
}
public static BitSet inland(DemGrid natural, boolean[] ocean, int seaLevel) {
float[] heights = natural.values();
int count = heights.length;
if (ocean.length < count) {
throw new IllegalArgumentException("Ocean flags cover " + ocean.length + " cells, grid has " + count);
}
BitSet inland = new BitSet(count);
boolean[] visited = new boolean[count];
int[] queue = new int[count];
for (int start = 0; start < count; start++) {
if (visited[start] || !belowSea(heights, ocean, start, seaLevel)) {
continue;
}
int tail = component(natural, cell -> belowSea(heights, ocean, cell, seaLevel), visited, queue, start);
if (enclosed(natural, ocean, queue, tail)) {
for (int index = 0; index < tail; index++) {
inland.set(queue[index]);
}
}
}
return inland;
}
public static BitSet hollow(DemGrid natural, BitSet inland, int cell) {
BitSet hollow = new BitSet(natural.values().length);
if (!inland.get(cell)) {
return hollow;
}
int[] queue = new int[natural.values().length];
int tail = component(natural, inland::get, new boolean[queue.length], queue, cell);
for (int index = 0; index < tail; index++) {
hollow.set(queue[index]);
}
return hollow;
}
public static List<Basin> hollows(DemGrid natural, BitSet inland, float[] filled, int seaLevel, int firstId) {
float[] heights = natural.values();
boolean[] visited = new boolean[heights.length];
int[] queue = new int[heights.length];
List<Basin> hollows = new ArrayList<>();
for (int start = inland.nextSetBit(0); start >= 0; start = inland.nextSetBit(start + 1)) {
if (visited[start]) {
continue;
}
int tail = component(natural, inland::get, visited, queue, start);
if (!drained(filled, queue, tail, seaLevel)) {
continue;
}
int[] cells = Arrays.copyOf(queue, tail);
Arrays.sort(cells);
int floor = cells[0];
for (int cell : cells) {
if (heights[cell] < heights[floor]) {
floor = cell;
}
}
hollows.add(new Basin(firstId + hollows.size(), floor, floor, seaLevel, seaLevel - heights[floor], cells, true));
}
return hollows;
}
private static boolean drained(float[] filled, int[] cells, int count, int seaLevel) {
for (int index = 0; index < count; index++) {
if (filled[cells[index]] > seaLevel) {
return false;
}
}
return true;
}
private static boolean belowSea(float[] heights, boolean[] ocean, int cell, int seaLevel) {
return !ocean[cell] && Math.round(heights[cell]) < seaLevel;
}
private static boolean enclosed(DemGrid grid, boolean[] ocean, int[] cells, int count) {
int width = grid.width();
int depth = grid.depth();
for (int index = 0; index < count; index++) {
int cell = cells[index];
int i = cell % width;
int j = cell / width;
if (i == 0 || j == 0 || i == width - 1 || j == depth - 1) {
return false;
}
for (int dz = -1; dz <= 1; dz++) {
for (int dx = -1; dx <= 1; dx++) {
if (ocean[(j + dz) * width + i + dx]) {
return false;
}
}
}
}
return true;
}
private static int component(DemGrid grid, IntPredicate member, boolean[] visited, int[] queue, int start) {
int width = grid.width();
int depth = grid.depth();
int head = 0;
int tail = 0;
queue[tail++] = start;
visited[start] = true;
while (head < tail) {
int cell = queue[head++];
int i = cell % width;
int j = cell / width;
for (int dz = -1; dz <= 1; dz++) {
int nj = j + dz;
if (nj < 0 || nj >= depth) {
continue;
}
for (int dx = -1; dx <= 1; dx++) {
int ni = i + dx;
if (ni < 0 || ni >= width) {
continue;
}
int neighbour = nj * width + ni;
if (!visited[neighbour] && member.test(neighbour)) {
visited[neighbour] = true;
queue[tail++] = neighbour;
}
}
}
}
return tail;
}
private static boolean flooded(float[] heights, float[] filled, int cell, float minDepth, float seaLevel) {
return filled[cell] - heights[cell] > minDepth && filled[cell] > seaLevel;
}
@@ -13,22 +13,24 @@ import java.util.Map;
final class BurnedTrunks {
private final BitSet cells;
private final BitSet hollows;
private final int[] next;
private final float[] catchment;
private final float epsilon;
private int[] order;
private BitSet entries;
private BurnedTrunks(int count, float epsilon) {
private BurnedTrunks(int count, float epsilon, BitSet hollows) {
this.cells = new BitSet(count);
this.hollows = hollows;
this.next = new int[count];
this.catchment = new float[count];
this.epsilon = epsilon;
Arrays.fill(next, -1);
}
static BurnedTrunks burn(DemGrid raw, List<Reach> reaches, float depth, float epsilon) {
BurnedTrunks trunks = new BurnedTrunks(raw.values().length, epsilon);
static BurnedTrunks burn(DemGrid raw, List<Reach> reaches, float depth, float epsilon, BitSet hollows) {
BurnedTrunks trunks = new BurnedTrunks(raw.values().length, epsilon, hollows);
Map<Long, Reach> byId = new HashMap<>();
for (Reach reach : reaches) {
byId.putIfAbsent(reach.id(), reach);
@@ -57,7 +59,7 @@ final class BurnedTrunks {
void descend(float[] heights) {
for (int cell : order) {
int successor = next[cell];
if (successor >= 0) {
if (successor >= 0 && !hollows.get(cell)) {
heights[successor] = Math.min(heights[successor], Math.min(heights[cell] - epsilon, Math.nextDown(heights[cell])));
}
}
@@ -65,7 +67,7 @@ final class BurnedTrunks {
void route(int[] receivers) {
for (int cell = cells.nextSetBit(0); cell >= 0; cell = cells.nextSetBit(cell + 1)) {
if (next[cell] >= 0) {
if (next[cell] >= 0 && !hollows.get(cell)) {
receivers[cell] = next[cell];
}
}
@@ -130,7 +130,7 @@ public final class RegionPlanner {
BitSet candidates = ChannelHeads.candidates(surface, accumulation, samples.permission(), settings.majorTier().minCatchment(), settings.seaLevel());
BitSet channels = ChannelHeads.keep(surface, samples.height(), receivers, candidates, settings.drainage().headRelief(), cell -> false,
cell -> CellHash.unit(CellHash.mix(settings.seed(), SALT_HEAD, surface.blockX(cell), surface.blockZ(cell))) < settings.density());
return shaper.coarsePaths(surface, receivers, accumulation, channels, settings.seed());
return shaper.coarsePaths(surface, receivers, accumulation, channels, samples.ocean(), settings.seed());
}
private static List<Reach> ownedReaches(RegionKey key, List<Reach> reaches) {
@@ -85,14 +85,19 @@ public final class WindowPlanner {
int cellZ = Math.multiplyExact(key.wz() - 1, WINDOW_CELLS);
HydrologySampleBuffer samples = new HydrologySampleBuffer(SPAN * SPAN);
fine.fill(cellX * FINE_STRIDE, cellZ * FINE_STRIDE, SPAN, SPAN, FINE_STRIDE, samples);
DemGrid raw = new DemGrid(cellX * CELL, cellZ * CELL, CELL, SPAN, SPAN);
System.arraycopy(samples.height(), 0, raw.values(), 0, SPAN * SPAN);
DemGrid natural = new DemGrid(cellX * CELL, cellZ * CELL, CELL, SPAN, SPAN);
System.arraycopy(samples.height(), 0, natural.values(), 0, SPAN * SPAN);
DemGrid raw = new DemGrid(natural.originX(), natural.originZ(), CELL, SPAN, SPAN);
System.arraycopy(natural.values(), 0, raw.values(), 0, SPAN * SPAN);
BitSet inland = BasinExtractor.inland(natural, samples.ocean(), settings.seaLevel());
List<Pond> lakes = regionLakes(plans.values());
BurnedTrunks trunks = BurnedTrunks.burn(raw, majorReaches(key, plans), settings.majorTier().inset(), settings.drainage().fillEpsilon());
BurnedTrunks trunks = BurnedTrunks.burn(raw, majorReaches(key, plans), settings.majorTier().inset(), settings.drainage().fillEpsilon(),
inland);
BitSet seeds = seeds(samples.ocean(), trunks);
DemGrid preliminary = new DemGrid(raw.originX(), raw.originZ(), CELL, SPAN, SPAN);
System.arraycopy(raw.values(), 0, preliminary.values(), 0, SPAN * SPAN);
Drainage initial = drain(preliminary, seeds, samples, trunks, lakes);
DrainContext context = new DrainContext(samples, trunks, inland);
Drainage initial = drain(preliminary, seeds, context, lakes);
BitSet channelHint = (BitSet) initial.channels().clone();
channelHint.andNot(trunks.cells());
CupSet cups = ponds.subtractCups(raw, key, samples, channelHint);
@@ -102,12 +107,14 @@ public final class WindowPlanner {
drainage = initial;
} else {
trunks.descend(raw.values());
drainage = drain(raw, seeds, samples, trunks, lakes);
drainage = drain(raw, seeds, context, lakes);
}
List<Pond> water = new ArrayList<>(ponds.ponds(raw, drainage.filled(), drainage.basins(), lakes, fine, cups));
List<Basin> basins = new ArrayList<>(drainage.basins());
basins.addAll(BasinExtractor.hollows(natural, inland, drainage.filled(), settings.seaLevel(), basins.size()));
List<Pond> water = new ArrayList<>(ponds.ponds(raw, drainage.filled(), basins, lakes, fine, cups));
water.addAll(lakes);
ShapedNetwork network = PondChannelSettlement.settle(key, shaper.shape(key, drainage.surface(), drainage.receivers(),
drainage.accumulation(), drainage.channels(), water, fine, settings.seed()), settings.seaLevel());
drainage.accumulation(), drainage.channels(), samples.ocean(), water, fine, settings.seed()), settings.seaLevel());
long passes = settlementPasses(water);
for (long pass = 1; lowered(water, network.ponds()); pass++) {
if (pass >= passes) {
@@ -115,7 +122,7 @@ public final class WindowPlanner {
}
water = replanned(settled(raw, cups, water, network.ponds()));
network = PondChannelSettlement.settle(key, shaper.shape(key, drainage.surface(), drainage.receivers(),
drainage.accumulation(), drainage.channels(), water, fine, settings.seed()), settings.seaLevel());
drainage.accumulation(), drainage.channels(), samples.ocean(), water, fine, settings.seed()), settings.seaLevel());
}
List<Reach> reaches = network.reaches();
List<Pond> windowPonds = windowPonds(network.ponds());
@@ -174,13 +181,16 @@ public final class WindowPlanner {
return seeds;
}
private Drainage drain(DemGrid raw, BitSet seeds, HydrologySampleBuffer samples, BurnedTrunks trunks, List<Pond> lakes) {
private Drainage drain(DemGrid raw, BitSet seeds, DrainContext context, List<Pond> lakes) {
HydrologySampleBuffer samples = context.samples();
BurnedTrunks trunks = context.trunks();
float epsilon = settings.drainage().fillEpsilon();
float[] filled = PriorityFlood.fill(raw, seeds, epsilon);
BitSet sinks = (BitSet) seeds.clone();
float[] filled = PriorityFlood.fill(raw, sinks, epsilon);
List<Basin> basins = BasinExtractor.basins(raw, filled, BASIN_DEPTH, settings.seaLevel());
for (int pass = 0; pass < BREACH_PASSES && breach(raw, filled, basins, lakes); pass++) {
for (int pass = 0; pass < BREACH_PASSES && breach(raw, filled, basins, lakes, context.inland(), sinks); pass++) {
trunks.descend(raw.values());
filled = PriorityFlood.fill(raw, seeds, epsilon);
filled = PriorityFlood.fill(raw, sinks, epsilon);
basins = BasinExtractor.basins(raw, filled, BASIN_DEPTH, settings.seaLevel());
}
DemGrid surface = new DemGrid(raw.originX(), raw.originZ(), CELL, SPAN, SPAN);
@@ -197,21 +207,36 @@ public final class WindowPlanner {
trunks.inject(weights);
float[] accumulation = FlowAccumulator.accumulate(receivers, filled, weights, settings.drainage().saturationCatchment());
trunks.pin(accumulation);
BitSet channels = channels(surface, receivers, accumulation, samples, trunks);
BitSet channels = channels(surface, receivers, accumulation, context);
return new Drainage(filled, basins, surface, receivers, accumulation, channels);
}
private boolean breach(DemGrid raw, float[] filled, List<Basin> basins, List<Pond> lakes) {
private boolean breach(DemGrid raw, float[] filled, List<Basin> basins, List<Pond> lakes, BitSet inland, BitSet sinks) {
boolean breached = false;
for (Basin basin : basins) {
if (oversized(basin) && !underLake(raw, basin, lakes)) {
Breacher.breach(raw, filled, basin);
BitSet hollow = hollow(raw, basin, inland);
if (hollow.isEmpty()) {
Breacher.breach(raw, filled, basin);
} else {
sinks.or(hollow);
}
breached = true;
}
}
return breached;
}
private static BitSet hollow(DemGrid raw, Basin basin, BitSet inland) {
BitSet hollow = new BitSet(raw.values().length);
for (int cell : basin.cells()) {
if (inland.get(cell) && !hollow.get(cell)) {
hollow.or(BasinExtractor.hollow(raw, inland, cell));
}
}
return hollow;
}
private boolean oversized(Basin basin) {
return basin.maxDepth() > settings.drainage().breachDepth()
|| (long) basin.cells().length * CELL * CELL > settings.ponds().natural().maxArea();
@@ -228,11 +253,35 @@ public final class WindowPlanner {
return false;
}
private BitSet channels(DemGrid surface, int[] receivers, float[] accumulation, HydrologySampleBuffer samples, BurnedTrunks trunks) {
private BitSet channels(DemGrid surface, int[] receivers, float[] accumulation, DrainContext context) {
HydrologySampleBuffer samples = context.samples();
BitSet candidates = ChannelHeads.candidates(surface, accumulation, samples.permission(), settings.tiers().get(0).minCatchment(),
settings.seaLevel());
return ChannelHeads.keep(surface, samples.height(), receivers, candidates, settings.drainage().headRelief(), trunks::contains,
cell -> keepHead(surface, cell, samples.rainfall()[cell]));
BitSet channels = ChannelHeads.keep(surface, samples.height(), receivers, candidates, settings.drainage().headRelief(),
context.trunks()::contains, cell -> keepHead(surface, cell, samples.rainfall()[cell]));
reachTheSea(channels, surface.values(), receivers, context);
return channels;
}
private void reachTheSea(BitSet channels, float[] filled, int[] receivers, DrainContext context) {
BitSet ends = new BitSet(receivers.length);
for (int cell = channels.nextSetBit(0); cell >= 0; cell = channels.nextSetBit(cell + 1)) {
int receiver = receivers[cell];
if (receiver >= 0 && !channels.get(receiver) && crossable(filled, context, receiver)) {
ends.set(cell);
}
}
for (int end = ends.nextSetBit(0); end >= 0; end = ends.nextSetBit(end + 1)) {
for (int cell = receivers[end]; cell >= 0 && !channels.get(cell) && crossable(filled, context, cell); cell = receivers[cell]) {
channels.set(cell);
}
}
}
private boolean crossable(float[] filled, DrainContext context, int cell) {
HydrologySampleBuffer samples = context.samples();
return !samples.ocean()[cell] && filled[cell] <= settings.seaLevel() && !context.inland().get(cell)
&& (samples.permission()[cell] & HydrologySampleBuffer.ALLOW_STREAMS) != 0;
}
private boolean keepHead(DemGrid surface, int cell, float rainfall) {
@@ -329,16 +378,21 @@ public final class WindowPlanner {
}
}
for (Reach reach : plan.reaches()) {
int mouth = reach.grade().length;
while (mouth > 0 && reach.style()[mouth - 1] == ReachStyle.MOUTH) {
mouth--;
}
if (mouth < reach.grade().length && reach.downstreamId() != 0L) {
throw offSea(plan.key(), reach, mouth, ", but its mouth drains into reach " + reach.downstreamId() + " instead of the sea");
}
for (int point = 0; point < reach.grade().length; point++) {
if (reach.grade()[point] < seaLevel) {
throw offSea(plan.key(), reach, point, ", below sea level " + seaLevel);
}
}
if (reach.downstreamId() != 0L) {
continue;
}
for (int point = reach.grade().length - 1; point >= 0 && reach.style()[point] == ReachStyle.MOUTH; point--) {
if (reach.grade()[point] != seaLevel) {
if (point < mouth && reach.style()[point] == ReachStyle.MOUTH) {
throw offSea(plan.key(), reach, point, ", but a mouth lies inside the reach, away from its sea end");
}
if (point >= mouth && reach.grade()[point] != seaLevel) {
throw offSea(plan.key(), reach, point, ", but the mouth must meet the sea at sea level " + seaLevel);
}
}
@@ -358,4 +412,7 @@ public final class WindowPlanner {
private record Drainage(float[] filled, List<Basin> basins, DemGrid surface, int[] receivers, float[] accumulation, BitSet channels) {
}
private record DrainContext(HydrologySampleBuffer samples, BurnedTrunks trunks, BitSet inland) {
}
}
@@ -106,7 +106,8 @@ public final class PondPlanner {
List<Candidate> kept = new ArrayList<>();
List<Pond> measured = new ArrayList<>();
for (Candidate candidate : candidates) {
Pond pond = measure(raw, fine, cups, candidate, Integer.MAX_VALUE);
Pond pond = candidate.basin().belowSea() ? enclosed(measure(raw, fine, cups, candidate, settings.seaLevel()))
: measure(raw, fine, cups, candidate, Integer.MAX_VALUE);
if (pond != null && !overlapsAny(pond, accepted) && !touchesLake(pond, regionLakes)) {
accepted.add(pond);
kept.add(candidate);
@@ -216,7 +217,7 @@ public final class PondPlanner {
private Candidate candidate(DemGrid raw, Basin basin, CupSet cups, HeightLattice fine) {
PondKind kind = cups.kind(raw, basin);
if (!qualifies(raw, basin, kind)) {
if (!basin.belowSea() && !qualifies(raw, basin, kind)) {
return null;
}
int floorX = raw.blockX(basin.floorIndex());
@@ -225,7 +226,7 @@ public final class PondPlanner {
if ((floor.permission()[0] & HydrologySampleBuffer.ALLOW_PONDS) == 0) {
return null;
}
if (kind == PondKind.NATURAL && CellHash.unit(CellHash.mix(settings.seed(), SALT_KEEP, floorX, floorZ))
if (kind == PondKind.NATURAL && !basin.belowSea() && CellHash.unit(CellHash.mix(settings.seed(), SALT_KEEP, floorX, floorZ))
>= Math.clamp(settings.ponds().natural().keep() * floor.pondDensity()[0], 0f, 1f) * settings.density()) {
return null;
}
@@ -410,6 +411,11 @@ public final class PondPlanner {
mask, 0L, damRaise, site.fluid(), site.floorX(), site.floorZ());
}
private static Pond enclosed(Pond pond) {
return pond == null ? null : new Pond(pond.id(), pond.kind(), pond.level(), pond.floor(), pond.floorX(), pond.floorZ(), pond.level(),
pond.mask(), pond.outletReachId(), pond.damRaise(), pond.fluid(), pond.floorX(), pond.floorZ());
}
private static boolean covered(DemGrid raw, Basin basin, List<Pond> lakes) {
int x = raw.blockX(basin.floorIndex());
int z = raw.blockZ(basin.floorIndex());
@@ -36,7 +36,6 @@ final class ReachDraft {
this.zs = fitted.zs();
this.catchments = fitted.catchment();
this.ocean = fitted.ocean();
this.ocean[xs.length - 1] |= chain.end() == ReachTracer.End.OCEAN;
this.target = new int[xs.length];
for (int point = 0; point < xs.length; point++) {
target[point] = (int) Math.floor(fitted.ground()[point]) - tier.inset();
@@ -25,7 +25,7 @@ final class ReachFitter {
this.ponds = ponds;
}
Fitted fit(DemGrid grid, int[] cells, float[] cellCatchment, HydrologyTier tier, long shapeSeed) {
Fitted fit(DemGrid grid, int[] cells, float[] cellCatchment, HydrologyTier tier, long shapeSeed, boolean drainsToTheSea) {
float halfWidth = tier.halfWidth(cellCatchment[cellCatchment.length - 1]);
Line line = resample(grid, cells, cellCatchment);
meander(line, shapeSeed);
@@ -33,6 +33,7 @@ final class ReachFitter {
Tangents tangents = tangents(line.xs(), line.zs());
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);
return fitted;
}
@@ -155,15 +156,28 @@ final class ReachFitter {
fine.fill(nodeX, nodeZ, samples);
for (int point = 0; point < points; point++) {
float lowest = Float.POSITIVE_INFINITY;
float lowestLand = 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);
}
}
fitted.ground()[point] = lowest;
fitted.ground()[point] = fitted.ocean()[point] || lowestLand == Float.POSITIVE_INFINITY ? lowest : lowestLand;
}
}
private static void seaEnd(boolean[] ocean, boolean drainsToTheSea) {
int start = ocean.length - 1;
ocean[start] = drainsToTheSea;
while (drainsToTheSea && start > 0 && ocean[start - 1]) {
start--;
}
Arrays.fill(ocean, 0, start, false);
}
private static int[] viterbi(Reads reads, int count, int reach) {
int span = reads.span();
float[] cost = new float[count * span];
@@ -35,9 +35,9 @@ public final class ReachShaper {
this.deltas = new DeltaPlanner(settings);
}
public ShapedNetwork shape(WindowKey window, DemGrid filled, int[] receivers, float[] accumulation, BitSet channels, List<Pond> ponds,
HeightLattice fine, long seed) {
requireNetwork(filled, receivers, accumulation, channels);
public ShapedNetwork shape(WindowKey window, DemGrid filled, int[] receivers, float[] accumulation, BitSet channels, boolean[] ocean,
List<Pond> ponds, HeightLattice fine, long seed) {
requireNetwork(filled, receivers, accumulation, channels, ocean);
PondLookup lookup = new PondLookup(ponds);
int[] pondAt = lookup.cells(filled);
int[] outletCells = outletCells(filled, receivers, accumulation, channels, lookup, pondAt);
@@ -47,7 +47,7 @@ public final class ReachShaper {
outlets.set(cell);
}
}
List<ReachTracer.Chain> chains = ReachTracer.trace(filled, receivers, channels, pondAt, outlets, settings.seaLevel());
List<ReachTracer.Chain> chains = ReachTracer.trace(filled, receivers, channels, ocean, pondAt, outlets);
ReachFitter fitter = new ReachFitter(Objects.requireNonNull(fine, "fine"), lookup);
List<ReachDraft> drafts = new ArrayList<>(chains.size());
for (ReachTracer.Chain chain : chains) {
@@ -98,9 +98,9 @@ public final class ReachShaper {
return new ShapedNetwork(reaches, linked);
}
public List<Reach> coarsePaths(DemGrid filled, int[] receivers, float[] accumulation, BitSet channels, long seed) {
requireNetwork(filled, receivers, accumulation, channels);
List<ReachTracer.Chain> chains = ReachTracer.trace(filled, receivers, channels, null, new BitSet(), settings.seaLevel());
public List<Reach> coarsePaths(DemGrid filled, int[] receivers, float[] accumulation, BitSet channels, boolean[] ocean, long seed) {
requireNetwork(filled, receivers, accumulation, channels, ocean);
List<ReachTracer.Chain> chains = ReachTracer.trace(filled, receivers, channels, ocean, null, new BitSet());
int[] downstream = ReachTracer.downstream(chains);
long[] ids = new long[chains.size()];
for (int index = 0; index < ids.length; index++) {
@@ -143,7 +143,7 @@ public final class ReachShaper {
float catchment = cellCatchment[cellCatchment.length - 1];
HydrologyTier tier = settings.tierFor(catchment);
long shapeSeed = CellHash.mix(seed, SALT_SHAPE, grid.blockX(chain.start()), grid.blockZ(chain.start()));
ReachFitter.Fitted fitted = fitter.fit(grid, chain.cells(), cellCatchment, tier, shapeSeed);
ReachFitter.Fitted fitted = fitter.fit(grid, chain.cells(), cellCatchment, tier, shapeSeed, chain.end() == ReachTracer.End.OCEAN);
int endLevel = chain.end() == ReachTracer.End.POND ? ponds.pond(chain.pond()).level() : Integer.MIN_VALUE;
return new ReachDraft(chain, id(seed, SALT_START, SALT_END, grid, chain), tier, catchment, endLevel, fitted);
}
@@ -649,11 +649,11 @@ public final class ReachShaper {
return CellHash.mix(start, endSalt, grid.blockX(chain.last()), grid.blockZ(chain.last()));
}
private static void requireNetwork(DemGrid grid, int[] receivers, float[] accumulation, BitSet channels) {
private static void requireNetwork(DemGrid grid, int[] receivers, float[] accumulation, BitSet channels, boolean[] ocean) {
int count = grid.width() * grid.depth();
if (receivers.length != count || accumulation.length != count || channels.length() > count) {
if (receivers.length != count || accumulation.length != count || channels.length() > count || ocean.length < count) {
throw new IllegalArgumentException("Drainage network does not match the " + count + "-cell grid: receivers=" + receivers.length
+ " accumulation=" + accumulation.length + " channels=" + channels.length());
+ " accumulation=" + accumulation.length + " channels=" + channels.length() + " ocean=" + ocean.length);
}
}
@@ -13,11 +13,11 @@ final class ReachTracer {
private ReachTracer() {
}
static List<Chain> trace(DemGrid grid, int[] receivers, BitSet channels, int[] pondAt, BitSet outlets, int seaLevel) {
static List<Chain> trace(DemGrid grid, int[] receivers, BitSet channels, boolean[] ocean, int[] pondAt, BitSet outlets) {
BitSet starts = starts(grid, receivers, channels, pondAt, outlets);
List<Chain> chains = new ArrayList<>(starts.cardinality());
for (int start = starts.nextSetBit(0); start >= 0; start = starts.nextSetBit(start + 1)) {
Chain chain = walk(grid, receivers, channels, pondAt, starts, seaLevel, start);
Chain chain = walk(receivers, channels, ocean, pondAt, starts, start);
if (chain.cells().length >= 2) {
chains.add(chain);
}
@@ -72,7 +72,7 @@ final class ReachTracer {
return starts;
}
private static Chain walk(DemGrid grid, int[] receivers, BitSet channels, int[] pondAt, BitSet starts, int seaLevel, int start) {
private static Chain walk(int[] receivers, BitSet channels, boolean[] ocean, int[] pondAt, BitSet starts, int start) {
int[] path = new int[16];
int length = 0;
path[length++] = start;
@@ -91,7 +91,7 @@ final class ReachTracer {
return new Chain(Arrays.copyOf(path, length), End.POND, pond);
}
if (!channels.get(receiver)) {
if (grid.values()[receiver] > seaLevel) {
if (!ocean[receiver]) {
return new Chain(Arrays.copyOf(path, length), End.EDGE, -1);
}
path[length++] = receiver;
@@ -1794,8 +1794,7 @@ public class IrisComplex implements DataProvider {
return false;
}
WaterRole role = raster.role(blockX & 15, blockZ & 15);
return role.wet() && role != WaterRole.MOUTH && role != WaterRole.INLET && seamWeight(blockX, blockZ) != 0D
&& raster.waterHead(blockX & 15, blockZ & 15) > transitionFluidHeight(x, z, fluidHeight);
return role.wet() && role != WaterRole.MOUTH && role != WaterRole.INLET && seamWeight(blockX, blockZ) != 0D;
}
private IrisBiome hydrologyShoreBiome(double terrainHeight, double x, double z) {