Estuary review fixes

- Taper estuary depth to the minimum depth at the mouth so the bed hands over to the natural seabed
- Stop the estuary walk at an outlet's first point so lake outlets leave the lake at its level
- Return a closed estuary opening for length 0 or a zero-length estuary instead of NaN widths
- Record mouth river features with their reach's own fluid through HydrologyRuntime.channelFluid and the shared ChannelFluids.reachFluid
- Pin the bank-height stop, the held pond lip, the lake outlet start and the degenerate opening
- Use a neutral unknown tier key in the pack compatibility test
- Recapture EXPECTED_SCHEMA_DIGEST for the flare description
This commit is contained in:
Brian Neumann-Fopiano committed 2026-11-01 22:52:35 -05:00
1 parent aef674f206
commit b17ad570ca
12 files changed
+208 -32

No files matched your search

@@ -19,6 +19,6 @@ public class IrisHydrologyEstuary {
@MinNumber(1)
@MaxNumber(4)
@Description("Half-width at the mouth of a full-length estuary as a multiple of the channel's own half-width. The channel widens slowly at first and fastest near the mouth and keeps its own depth; an estuary cut short by higher banks widens less. The half-width never passes 64. 1 keeps the channel's width.")
@Description("Half-width at the mouth of a full-length estuary as a multiple of the channel's own half-width. The channel widens slowly at first and fastest near the mouth while its depth tapers to one block there; an estuary cut short by higher banks widens less. The half-width never passes 64. 1 keeps the channel's width.")
private double flare = 2.5D;
}
@@ -69,6 +69,7 @@ public final class HydrologyRuntime {
private final HydrologySettings settings;
private final HydrologyPlanCache cache;
private final ChunkRasterizer rasterizer;
private final ChannelFluids channelFluids;
private final NaturalHeights naturalHeight;
private final BooleanSupplier mainThread;
private final RasterLru rasters;
@@ -93,6 +94,7 @@ public final class HydrologyRuntime {
this.settings = null;
this.cache = null;
this.rasterizer = null;
this.channelFluids = null;
this.naturalHeight = null;
this.mainThread = null;
this.rasters = null;
@@ -120,6 +122,7 @@ public final class HydrologyRuntime {
Function<PreparedHydrologyCacheIdentity, HydrologyPlanStore> stores, boolean caveFluidPolicies) {
this.settings = Objects.requireNonNull(settings, "settings");
this.cache = Objects.requireNonNull(cache, "cache");
this.channelFluids = Objects.requireNonNull(channelFluids, "channelFluids");
this.rasterizer = new ChunkRasterizer(settings, channelFluids);
this.naturalHeight = Objects.requireNonNull(naturalHeight, "naturalHeight");
this.mainThread = Objects.requireNonNull(mainThread, "mainThread");
@@ -463,6 +466,25 @@ public final class HydrologyRuntime {
+ " that none of its hydrology plans define.");
}
public String channelFluid(int chunkX, int chunkZ, long reachId) {
if (cache == null) {
throw new IllegalStateException("Hydrology is disabled, so it has no channels.");
}
if (mainThread.getAsBoolean()) {
throw new IllegalStateException("Hydrology channel fluid was requested on the main thread.");
}
requireOpen();
for (CompletableFuture<IndexedWindow> window : plans(neighbourhood(chunkX, chunkZ), List.of(), PlanMode.DEMAND).windowFutures()) {
for (Reach reach : cache.awaitPlan(window).plan().reaches()) {
if (reach.id() == reachId) {
return channelFluids.reachFluid(reach);
}
}
}
throw new IllegalStateException("Chunk " + chunkX + "," + chunkZ + " holds channel water " + reachId
+ " that none of its hydrology plans define.");
}
public synchronized void close() {
if (cache == null) {
return;
@@ -1,8 +1,15 @@
package art.arcane.iris.generation.hydrology.raster;
import art.arcane.iris.generation.hydrology.water.Reach;
@FunctionalInterface
public interface ChannelFluids {
ChannelFluids TIER = (x, z) -> null;
String channelFluid(int x, int z);
default String reachFluid(Reach reach) {
String area = channelFluid((int) Math.floor(reach.xs()[0]), (int) Math.floor(reach.zs()[0]));
return area != null ? area : reach.tier().fluid();
}
}
@@ -149,10 +149,7 @@ final class RasterComposer {
}
private String reachFluid(Reach reach) {
return reachFluids.computeIfAbsent(reach.id(), id -> {
String area = channelFluids.channelFluid((int) Math.floor(reach.xs()[0]), (int) Math.floor(reach.zs()[0]));
return area != null ? area : reach.tier().fluid();
});
return reachFluids.computeIfAbsent(reach.id(), id -> channelFluids.reachFluid(reach));
}
private int deepestBed(int ownerHead, int surface, int ground, double variation, double detail) {
@@ -24,7 +24,7 @@ public record HydrologyTier(
List<IrisDecorator> decorators
) {
private static final float CATCHMENT_SCALE = 2500f;
private static final float MINIMUM_DEPTH = 1f;
static final float MINIMUM_DEPTH = 1f;
public float halfWidth(float catchment) {
float grown = minHalfWidth + widthFactor * (float) Math.sqrt(Math.max(0f, catchment) / CATCHMENT_SCALE);
@@ -88,8 +88,8 @@ final class ReachGrader {
if (point < draft.xs.length - 1) {
along += (float) Math.hypot(draft.xs[point + 1] - draft.xs[point], draft.zs[point + 1] - draft.zs[point]);
}
boolean held = draft.held != null && draft.held[point];
if (along > length || held || !draft.ocean[point] && draft.bank[point] > highestBank) {
boolean fixed = draft.held != null && draft.held[point] || point == 0 && draft.outlet;
if (along > length || fixed || !draft.ocean[point] && draft.bank[point] > highestBank) {
return;
}
draft.ocean[point] = true;
@@ -492,7 +492,9 @@ public final class ReachShaper {
boolean flare = draft.incoming.length > 0 && !draft.outlet;
boolean taper = !flare && !draft.outlet;
float[] distance = distances(draft.xs, draft.zs);
float[] estuary = estuaryFlare(draft, distance);
Opening estuary = draft.chain.end() == ReachTracer.End.OCEAN ? estuaryOpening(draft.tier.estuary(), draft.ocean, distance)
: Opening.closed(count);
float widening = (draft.tier.estuary().flare() - 1f) * estuary.share();
float running = upstream;
draft.halfWidth = new float[count];
draft.depth = new float[count];
@@ -505,35 +507,36 @@ public final class ReachShaper {
}
float lip = draft.held != null && draft.held[point] ? LIP_HALF_WIDTH : 0f;
float channel = Math.max(Math.max(law, WAIST * running), lip);
draft.halfWidth[point] = Math.min(HydrologySettings.MAX_HALF_WIDTH, channel * estuary[point]);
float progress = estuary.progress()[point];
draft.halfWidth[point] = Math.min(HydrologySettings.MAX_HALF_WIDTH, channel * (1f + widening * progress));
running = Math.max(running, channel);
draft.depth[point] = draft.tier.depth(channel);
float depth = draft.tier.depth(channel);
draft.depth[point] = depth + (HydrologyTier.MINIMUM_DEPTH - depth) * progress;
}
draft.maxHalfWidth = running;
}
private static float[] estuaryFlare(ReachDraft draft, float[] distance) {
static Opening estuaryOpening(HydrologyTier.Estuary estuary, boolean[] ocean, float[] distance) {
int count = distance.length;
float[] scale = new float[count];
Arrays.fill(scale, 1f);
if (draft.chain.end() != ReachTracer.End.OCEAN) {
return scale;
if (estuary.length() == 0) {
return Opening.closed(count);
}
HydrologyTier.Estuary estuary = draft.tier.estuary();
float mouth = distance[count - 1];
int start = count - 1;
while (start > 0 && draft.ocean[start - 1] && mouth - distance[start - 1] <= estuary.length()) {
while (start > 0 && ocean[start - 1] && mouth - distance[start - 1] <= estuary.length()) {
start--;
}
if (start == count - 1) {
return scale;
}
float first = towardMouth(mouth - distance[start], estuary.length());
float share = 1f - first * first;
if (start == count - 1 || share <= 0f) {
return Opening.closed(count);
}
float[] progress = new float[count];
for (int point = start + 1; point < count; point++) {
float toward = towardMouth(mouth - distance[point], estuary.length());
scale[point] = 1f + (estuary.flare() - 1f) * (toward * toward - first * first);
progress[point] = (toward * toward - first * first) / share;
}
return scale;
return new Opening(progress, share);
}
private static float towardMouth(float remaining, int length) {
@@ -649,4 +652,10 @@ public final class ReachShaper {
+ " accumulation=" + accumulation.length + " channels=" + channels.length());
}
}
record Opening(float[] progress, float share) {
static Opening closed(int count) {
return new Opening(new float[count], 0f);
}
}
}
@@ -165,6 +165,7 @@ public final class GenerationSemanticCapture {
return;
}
Map<Long, Set<HydrologyFeatureType>> standing = new HashMap<>();
Map<Long, String> reachFluids = new HashMap<>();
Set<WaterFeature> recorded = new HashSet<>();
for (int localX = 0; localX < CHUNK_SIZE; localX++) {
int blockX = minimumX + localX;
@@ -181,8 +182,9 @@ public final class GenerationSemanticCapture {
Set<HydrologyFeatureType> types = role == WaterRole.POND
? standing.computeIfAbsent(id, feature -> runtime.standingWaterTypes(chunkX, chunkZ, feature))
: flowingTypes(runtime, role, raster.tier(localX, localZ));
String fluid = Objects.requireNonNull(raster.fluid(localX, localZ),
"Water column " + blockX + "," + blockZ + " has no fluid profile");
String fluid = role == WaterRole.MOUTH
? reachFluids.computeIfAbsent(id, reach -> runtime.channelFluid(chunkX, chunkZ, reach))
: Objects.requireNonNull(raster.fluid(localX, localZ), "Water column " + blockX + "," + blockZ + " has no fluid profile");
int y = Math.addExact((int) Math.round(complex.getWaterHeadStream().getDouble(blockX, blockZ)), minimumY);
for (HydrologyFeatureType type : types) {
if (recorded.add(new WaterFeature(type, id))) {