Rank studio water features

- Plan-mode pond and lake masks keep the strongest feature per pixel instead of overwriting channels and falls
- Water map ranks come from an explicit switch per feature type, with ponds above lakes
- Studio water tiles redraw recorded cave pools when the hydrology preview revision changes
- Tests cover channels over ponds, ponds over lakes and cave pool refresh on a completed tile
This commit is contained in:
Brian Neumann-Fopiano committed 2026-11-01 22:11:42 -05:00
1 parent c0169d6dcd
commit 0c59e698cd
5 files changed
+185 -32

No files matched your search

@@ -457,15 +457,17 @@ public final class IrisRenderer {
private final double startZ;
private final double step;
private final int resolution;
private final HydrologyRuntime runtime;
private final WaterMap map;
private boolean complete;
private long poolRevision;
private WaterTile(double startX, double startZ, double step, int resolution) {
this.startX = startX;
this.startZ = startZ;
this.step = step;
this.resolution = resolution;
HydrologyRuntime runtime = renderer.getComplex().getHydrologyRuntime();
this.runtime = renderer.getComplex().getHydrologyRuntime();
this.map = runtime == null || !runtime.enabled() || step > WaterMap.MAX_STEP
? null : new WaterMap(runtime, resolution, startX, startZ, step);
complete = map == null;
@@ -477,13 +479,8 @@ public final class IrisRenderer {
if (composite && (base == null || base.length != resolution * resolution)) {
throw new IllegalArgumentException("Water overlay requires matching base pixels");
}
if (!complete) {
map.advance(cancelled);
map.drawCavePools(GenerationSemanticQueries.recordedCavePools(renderer,
Math.floorDiv((int) Math.floor(startX), 16), Math.floorDiv((int) Math.floor(startZ), 16),
Math.floorDiv((int) Math.ceil(startX + resolution * step) - 1, 16),
Math.floorDiv((int) Math.ceil(startZ + resolution * step) - 1, 16)));
complete = !map.provisional();
if (map != null) {
draw(cancelled);
}
int[] colors = composite ? base.clone() : new int[resolution * resolution];
if (!composite) {
@@ -515,6 +512,23 @@ public final class IrisRenderer {
public long bytes() {
return map == null ? 0L : map.bytes();
}
private void draw(BooleanSupplier cancelled) {
long revision = runtime.previewRevision();
boolean advanced = !complete;
if (advanced) {
map.advance(cancelled);
complete = !map.provisional();
}
if (!advanced && revision == poolRevision) {
return;
}
map.drawCavePools(GenerationSemanticQueries.recordedCavePools(renderer,
Math.floorDiv((int) Math.floor(startX), 16), Math.floorDiv((int) Math.floor(startZ), 16),
Math.floorDiv((int) Math.ceil(startX + resolution * step) - 1, 16),
Math.floorDiv((int) Math.ceil(startZ + resolution * step) - 1, 16)));
poolRevision = revision;
}
}
@FunctionalInterface
@@ -24,12 +24,8 @@ import java.util.function.BooleanSupplier;
final class WaterMap {
static final double RASTER_STEP = 2D;
static final double MAX_STEP = 16D;
static final List<HydrologyFeatureType> DRAWN = List.of(HydrologyFeatureType.WATERFALL, HydrologyFeatureType.CASCADE,
HydrologyFeatureType.MOUTH, HydrologyFeatureType.MAJOR_RIVER, HydrologyFeatureType.RIVER, HydrologyFeatureType.STREAM,
HydrologyFeatureType.SEA_INLET, HydrologyFeatureType.LAKE, HydrologyFeatureType.POND, HydrologyFeatureType.DAM,
HydrologyFeatureType.CAVE_POOL);
static final List<HydrologyFeatureType> DRAWN = drawn();
private static final int DRY = Integer.MAX_VALUE;
private static final int[] RANK = ranks();
private final HydrologyRuntime runtime;
private final int resolution;
@@ -280,7 +276,7 @@ final class WaterMap {
int lastX = Math.min(resolution - 1, (int) Math.floor((centreX + half - 1 - startX) / step));
for (int pixelZ = firstZ; pixelZ <= lastZ; pixelZ++) {
for (int pixelX = firstX; pixelX <= lastX; pixelX++) {
ranks[pixelZ * resolution + pixelX] = RANK[type.ordinal()];
stamp(pixelX, pixelZ, type);
}
}
}
@@ -296,7 +292,7 @@ final class WaterMap {
return;
}
int index = pixelZ * resolution + pixelX;
int rank = RANK[type.ordinal()];
int rank = rank(type);
if (rank < ranks[index]) {
ranks[index] = rank;
}
@@ -308,12 +304,31 @@ final class WaterMap {
}
}
private static int[] ranks() {
int[] ranks = new int[HydrologyFeatureType.values().length];
Arrays.fill(ranks, DRY);
for (int index = 0; index < DRAWN.size(); index++) {
ranks[DRAWN.get(index).ordinal()] = index;
private static int rank(HydrologyFeatureType type) {
return switch (type) {
case WATERFALL -> 0;
case CASCADE -> 1;
case MOUTH -> 2;
case MAJOR_RIVER -> 3;
case RIVER -> 4;
case STREAM -> 5;
case SEA_INLET -> 6;
case POND -> 7;
case LAKE -> 8;
case DAM -> 9;
case CAVE_POOL -> 10;
};
}
private static List<HydrologyFeatureType> drawn() {
HydrologyFeatureType[] drawn = new HydrologyFeatureType[HydrologyFeatureType.values().length];
for (HydrologyFeatureType type : HydrologyFeatureType.values()) {
int rank = rank(type);
if (drawn[rank] != null) {
throw new IllegalStateException("Water map ranks " + drawn[rank] + " and " + type + " equally");
}
drawn[rank] = type;
}
return ranks;
return List.of(drawn);
}
}