From 09d6e4b720829e9c329e384c94ba1fff6952371c Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 31 Oct 2026 02:12:13 -0500 Subject: [PATCH] Let hydrology policies set the fluid of rivers A hydrology policy's fluid filled ponds and lakes, but channels always used their tier's fluid, so a volcanic region could have lava lakes but only water rivers. Each reach now takes the fluid its policy (biome, then region, then dimension) names where the reach starts, its upstream end, falling back to the tier's fluid when no policy names one, and keeps it to its downstream end. Deciding per reach rather than per column keeps a river one fluid from source to confluence, so two fluids only meet where streams join or flow into a lake, not along every border a river crosses. River plans and the plan cache are unchanged. --- .../hydrology/engine/HydrologyRuntime.java | 15 ++++++++----- .../engine/IrisHydrologyTerrainSource.java | 10 +++++++++ .../hydrology/raster/ChunkRasterizer.java | 15 ++++++++++++- .../hydrology/raster/RasterComposer.java | 22 +++++++++++++++++-- 4 files changed, 54 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/art/arcane/iris/generation/hydrology/engine/HydrologyRuntime.java b/core/src/main/java/art/arcane/iris/generation/hydrology/engine/HydrologyRuntime.java index 2f525c3d9..2b3c2251d 100644 --- a/core/src/main/java/art/arcane/iris/generation/hydrology/engine/HydrologyRuntime.java +++ b/core/src/main/java/art/arcane/iris/generation/hydrology/engine/HydrologyRuntime.java @@ -80,6 +80,7 @@ public final class HydrologyRuntime { private final HydrologyBinding binding; private final Function stores; private final boolean caveFluidPolicies; + private final ChunkRasterizer.AreaFluid areaFluid; private final AtomicLong rasterRevision = new AtomicLong(); private volatile PreparedHydrologyCacheIdentity storeIdentity; private boolean storeOpen; @@ -102,16 +103,19 @@ public final class HydrologyRuntime { this.binding = HydrologyBinding.UNBOUND; this.stores = identity -> null; this.caveFluidPolicies = false; + this.areaFluid = ChunkRasterizer.AreaFluid.NONE; } public HydrologyRuntime(HydrologySettings settings, HydrologyPlanCache cache, IntBinaryOperator naturalHeight, BooleanSupplier mainThread, LongSupplier ticker) { - this(settings, cache, naturalHeight, mainThread, ticker, HydrologyBinding.UNBOUND, identity -> null, false); + this(settings, cache, naturalHeight, mainThread, ticker, HydrologyBinding.UNBOUND, identity -> null, false, + ChunkRasterizer.AreaFluid.NONE); } private HydrologyRuntime(HydrologySettings settings, HydrologyPlanCache cache, IntBinaryOperator naturalHeight, BooleanSupplier mainThread, LongSupplier ticker, HydrologyBinding binding, - Function stores, boolean caveFluidPolicies) { + Function stores, boolean caveFluidPolicies, + ChunkRasterizer.AreaFluid areaFluid) { this.settings = Objects.requireNonNull(settings, "settings"); this.cache = Objects.requireNonNull(cache, "cache"); this.rasterizer = new ChunkRasterizer(settings); @@ -128,6 +132,7 @@ public final class HydrologyRuntime { this.binding = Objects.requireNonNull(binding, "binding"); this.stores = Objects.requireNonNull(stores, "stores"); this.caveFluidPolicies = caveFluidPolicies; + this.areaFluid = Objects.requireNonNull(areaFluid, "areaFluid"); } public static HydrologyRuntime create(Engine engine, IrisComplex complex) { @@ -154,7 +159,7 @@ public final class HydrologyRuntime { String dimensionKey = dimension.getLoadKey(); IrisWorld world = engine.getWorld(); return new HydrologyRuntime(settings, cache, source::naturalHeight, mainThread, System::nanoTime, binding, - identity -> store(world, dimensionKey, settings, identity), caveFluidPolicies); + identity -> store(world, dimensionKey, settings, identity), caveFluidPolicies, source::channelFluid); } static boolean requireBiomeFluids(Collection biomes, HydrologySettings settings) { @@ -516,7 +521,7 @@ public final class HydrologyRuntime { } ChunkWaterRaster raster; try (HydrologyBinding.Scope ignored = binding.open()) { - raster = rasterizer.rasterize(chunkX, chunkZ, naturalHeight, windows, lakes); + raster = rasterizer.rasterize(chunkX, chunkZ, naturalHeight, windows, lakes, areaFluid); } prefetch(chunkX, chunkZ); return raster; @@ -644,7 +649,7 @@ public final class HydrologyRuntime { try { if (!closed) { try (HydrologyBinding.Scope ignored = binding.open()) { - remember(key, rasterizer.rasterize(chunkX, chunkZ, naturalHeight, plans.windows(), plans.lakes())); + remember(key, rasterizer.rasterize(chunkX, chunkZ, naturalHeight, plans.windows(), plans.lakes(), areaFluid)); } } } catch (RuntimeException failure) { diff --git a/core/src/main/java/art/arcane/iris/generation/hydrology/engine/IrisHydrologyTerrainSource.java b/core/src/main/java/art/arcane/iris/generation/hydrology/engine/IrisHydrologyTerrainSource.java index 2cd730752..43eeb494f 100644 --- a/core/src/main/java/art/arcane/iris/generation/hydrology/engine/IrisHydrologyTerrainSource.java +++ b/core/src/main/java/art/arcane/iris/generation/hydrology/engine/IrisHydrologyTerrainSource.java @@ -163,6 +163,16 @@ public final class IrisHydrologyTerrainSource implements HydrologyTerrainSource return type == InferredType.SEA; } + /** The fluid this column's hydrology policy names (biome, then region, then dimension), or null if none does. */ + public String channelFluid(int x, int z) { + ChunkBakeCache.enterSparse(); + try { + return policy(biomes.get(x, z), regions.get(x, z)).fluid(); + } finally { + ChunkBakeCache.exitSparse(); + } + } + private Policy policy(IrisBiome biome, IrisRegion region) { PolicyKey key = new PolicyKey(biome, region); Policy known = policies.get(key); diff --git a/core/src/main/java/art/arcane/iris/generation/hydrology/raster/ChunkRasterizer.java b/core/src/main/java/art/arcane/iris/generation/hydrology/raster/ChunkRasterizer.java index 369be027d..f437dd672 100644 --- a/core/src/main/java/art/arcane/iris/generation/hydrology/raster/ChunkRasterizer.java +++ b/core/src/main/java/art/arcane/iris/generation/hydrology/raster/ChunkRasterizer.java @@ -33,13 +33,26 @@ public final class ChunkRasterizer { chunkX * CHUNK + CHUNK - 1 + halo, chunkZ * CHUNK + CHUNK - 1 + halo); } + /** The fluid an area's hydrology policy names for the water flowing through it, or null to keep the tier's fluid. */ + @FunctionalInterface + public interface AreaFluid { + AreaFluid NONE = (x, z) -> null; + + String at(int x, int z); + } + public ChunkWaterRaster rasterize(int chunkX, int chunkZ, IntBinaryOperator naturalHeight, List windows, List lakeRegionPlans) { + return rasterize(chunkX, chunkZ, naturalHeight, windows, lakeRegionPlans, AreaFluid.NONE); + } + + public ChunkWaterRaster rasterize(int chunkX, int chunkZ, IntBinaryOperator naturalHeight, List windows, + List lakeRegionPlans, AreaFluid areaFluid) { Objects.requireNonNull(naturalHeight, "naturalHeight"); ChunkFeatures features = ChunkFeatures.gather(settings, chunkX, chunkZ, halo, windows, lakeRegionPlans, lakeRegions(chunkX, chunkZ)); if (features.empty()) { return ChunkWaterRaster.EMPTY; } - return new RasterComposer(settings, features, chunkX, chunkZ).compose(naturalHeight); + return new RasterComposer(settings, features, chunkX, chunkZ, areaFluid).compose(naturalHeight); } } diff --git a/core/src/main/java/art/arcane/iris/generation/hydrology/raster/RasterComposer.java b/core/src/main/java/art/arcane/iris/generation/hydrology/raster/RasterComposer.java index 36dec7012..aa36744d6 100644 --- a/core/src/main/java/art/arcane/iris/generation/hydrology/raster/RasterComposer.java +++ b/core/src/main/java/art/arcane/iris/generation/hydrology/raster/RasterComposer.java @@ -11,6 +11,8 @@ import art.arcane.iris.generation.hydrology.water.Reach; import art.arcane.iris.generation.hydrology.water.ReachStyle; import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; import java.util.function.IntBinaryOperator; final class RasterComposer { @@ -43,8 +45,12 @@ final class RasterComposer { private final int[] inletColumn = new int[2]; private IntBinaryOperator naturalHeight; - RasterComposer(HydrologySettings settings, ChunkFeatures features, int chunkX, int chunkZ) { + private final ChunkRasterizer.AreaFluid areaFluid; + private final Map reachFluids = new HashMap<>(); + + RasterComposer(HydrologySettings settings, ChunkFeatures features, int chunkX, int chunkZ, ChunkRasterizer.AreaFluid areaFluid) { this.settings = settings; + this.areaFluid = areaFluid; this.features = features; this.originX = chunkX * CHUNK - 1; this.originZ = chunkZ * CHUNK - 1; @@ -138,7 +144,19 @@ final class RasterComposer { role[cell] = role(reach.style()[point]); feature[cell] = reach.id(); tier[cell] = reach.tier(); - fluid[cell] = reach.tier().fluid(); + fluid[cell] = reachFluid(reach); + } + + /** + * The fluid of a whole reach: the one the hydrology policy names where the reach starts (its upstream end), else the + * tier's. Deciding per reach instead of per column keeps a river one fluid from source to confluence, so two fluids + * only meet where streams join or flow into a lake, not along every region border the river crosses. + */ + private String reachFluid(Reach reach) { + return reachFluids.computeIfAbsent(reach.id(), id -> { + String area = areaFluid.at((int) Math.floor(reach.xs()[0]), (int) Math.floor(reach.zs()[0])); + return area != null ? area : reach.tier().fluid(); + }); } private static int bed(ReachCursor.Choice hit, int surface, int ground, double variation, double detail) {