Inland hollow review fixes

- Trunks are cut where they cross the natural basin draining into an inland hollow, so the major restarts beyond the rim instead of descending through it at sea level
- Lowland channels never climb more than 2 blocks above the lowest ground they crossed or the sea, in a new LowlandChannels helper
- Inland hollow ponds skip dams
- Hollow planner tests assert no reach is held at the sea under high ground and the valley past the rim matches the hollow-free valley
- Pondless inland hollows end streams at their edge
- One shared SeaCells test helper replaces the two copies
This commit is contained in:
Brian Neumann-Fopiano committed 2026-11-02 02:42:35 -05:00
1 parent 30865031ba
commit c0f2c10c1d
12 files changed
+306 -89

No files matched your search

@@ -92,6 +92,23 @@ public final class BasinExtractor {
return inland;
}
public static BitSet draining(DemGrid natural, float[] filled, BitSet inland, float minDepth) {
float[] heights = natural.values();
BitSet basins = new BitSet(heights.length);
boolean[] visited = new boolean[heights.length];
int[] queue = new int[heights.length];
for (int start = inland.nextSetBit(0); start >= 0; start = inland.nextSetBit(start + 1)) {
if (visited[start]) {
continue;
}
int tail = component(natural, cell -> inland.get(cell) || filled[cell] - heights[cell] > minDepth, visited, queue, start);
for (int index = 0; index < tail; index++) {
basins.set(queue[index]);
}
}
return basins;
}
public static BitSet hollow(DemGrid natural, BitSet inland, int cell) {
BitSet hollow = new BitSet(natural.values().length);
if (!inland.get(cell)) {
@@ -13,16 +13,14 @@ 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, BitSet hollows) {
private BurnedTrunks(int count, float epsilon) {
this.cells = new BitSet(count);
this.hollows = hollows;
this.next = new int[count];
this.catchment = new float[count];
this.epsilon = epsilon;
@@ -30,16 +28,18 @@ final class BurnedTrunks {
}
static BurnedTrunks burn(DemGrid raw, List<Reach> reaches, float depth, float epsilon, BitSet hollows) {
BurnedTrunks trunks = new BurnedTrunks(raw.values().length, epsilon, hollows);
BurnedTrunks trunks = new BurnedTrunks(raw.values().length, epsilon);
Map<Long, Reach> byId = new HashMap<>();
for (Reach reach : reaches) {
byId.putIfAbsent(reach.id(), reach);
}
List<int[]> paths = new ArrayList<>();
for (Reach reach : reaches) {
for (int[] path : TrunkRouter.route(raw, reach, byId.get(reach.downstreamId()))) {
trunks.claim(path, reach.catchment());
paths.add(path);
for (int[] route : TrunkRouter.route(raw, reach, byId.get(reach.downstreamId()))) {
for (int[] path : outside(route, hollows)) {
trunks.claim(path, reach.catchment());
paths.add(path);
}
}
}
StreamBurner.burn(raw, paths, depth);
@@ -59,7 +59,7 @@ final class BurnedTrunks {
void descend(float[] heights) {
for (int cell : order) {
int successor = next[cell];
if (successor >= 0 && !hollows.get(cell)) {
if (successor >= 0) {
heights[successor] = Math.min(heights[successor], Math.min(heights[cell] - epsilon, Math.nextDown(heights[cell])));
}
}
@@ -67,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 && !hollows.get(cell)) {
if (next[cell] >= 0) {
receivers[cell] = next[cell];
}
}
@@ -85,6 +85,20 @@ final class BurnedTrunks {
}
}
private static List<int[]> outside(int[] route, BitSet hollows) {
List<int[]> runs = new ArrayList<>(1);
int from = 0;
for (int index = 0; index <= route.length; index++) {
if (index == route.length || hollows.get(route[index])) {
if (index > from) {
runs.add(Arrays.copyOfRange(route, from, index));
}
from = index + 1;
}
}
return runs;
}
private void claim(int[] path, float reachCatchment) {
for (int index = 0; index < path.length; index++) {
int cell = path[index];
@@ -0,0 +1,38 @@
package art.arcane.iris.generation.hydrology.plan;
import art.arcane.iris.generation.hydrology.grid.HydrologySampleBuffer;
import java.util.BitSet;
final class LowlandChannels {
private static final float RISE = 2f;
private LowlandChannels() {
}
static void extend(BitSet channels, float[] filled, int[] receivers, HydrologySampleBuffer samples, BitSet inland, int seaLevel) {
float[] natural = samples.height();
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, samples, inland, seaLevel, receiver, natural[cell])) {
ends.set(cell);
}
}
for (int end = ends.nextSetBit(0); end >= 0; end = ends.nextSetBit(end + 1)) {
float lowest = natural[end];
int cell = receivers[end];
while (cell >= 0 && !channels.get(cell) && crossable(filled, samples, inland, seaLevel, cell, lowest)) {
channels.set(cell);
lowest = Math.min(lowest, natural[cell]);
cell = receivers[cell];
}
}
}
private static boolean crossable(float[] filled, HydrologySampleBuffer samples, BitSet inland, int seaLevel, int cell, float lowest) {
return !samples.ocean()[cell] && filled[cell] <= seaLevel && !inland.get(cell)
&& samples.height()[cell] <= Math.max(lowest, seaLevel) + RISE
&& (samples.permission()[cell] & HydrologySampleBuffer.ALLOW_STREAMS) != 0;
}
}
@@ -90,10 +90,14 @@ public final class WindowPlanner {
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());
BitSet open = open(samples.ocean());
BitSet hollowBasins = inland.isEmpty() ? inland
: BasinExtractor.draining(natural, PriorityFlood.fill(natural, open, settings.drainage().fillEpsilon()), inland, BASIN_DEPTH);
List<Pond> lakes = regionLakes(plans.values());
BurnedTrunks trunks = BurnedTrunks.burn(raw, majorReaches(key, plans), settings.majorTier().inset(), settings.drainage().fillEpsilon(),
inland);
BitSet seeds = seeds(samples.ocean(), trunks);
hollowBasins);
BitSet seeds = trunks.cells();
seeds.or(open);
DemGrid preliminary = new DemGrid(raw.originX(), raw.originZ(), CELL, SPAN, SPAN);
System.arraycopy(raw.values(), 0, preliminary.values(), 0, SPAN * SPAN);
DrainContext context = new DrainContext(samples, trunks, inland);
@@ -169,8 +173,8 @@ public final class WindowPlanner {
return List.copyOf(lakes);
}
private static BitSet seeds(boolean[] ocean, BurnedTrunks trunks) {
BitSet seeds = trunks.cells();
private static BitSet open(boolean[] ocean) {
BitSet seeds = new BitSet(ocean.length);
for (int cell = 0; cell < ocean.length; cell++) {
int i = cell % SPAN;
int j = cell / SPAN;
@@ -259,31 +263,10 @@ public final class WindowPlanner {
settings.seaLevel());
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);
LowlandChannels.extend(channels, surface.values(), receivers, samples, context.inland(), settings.seaLevel());
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) {
HydrologySettings.Drainage drainage = settings.drainage();
float keep = drainage.wetnessThinning() ? Math.clamp(Math.max(drainage.minimumHeadKeep(), rainfall), 0f, 1f) : 1f;
@@ -274,7 +274,7 @@ public final class PondPlanner {
float[] ground = box.ground();
Spill spill = spill(box, ground, floor, null);
int damRaise = 0;
if (settings.ponds().dams().enabled() && spill.height() > ground[floor]) {
if (settings.ponds().dams().enabled() && !candidate.basin().belowSea() && spill.height() > ground[floor]) {
ground = dam(box, ground, floor, spill.height());
Spill raised = spill(box, ground, floor, null);
damRaise = (int) Math.floor(raised.height()) - (int) Math.floor(spill.height());