mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 16:54:04 +00:00
Cross-window confluence settling
- Track every reach owned by the nine loaded windows in ChunkFeatures.Links.owned - Settle a feeder whose downstream reach has another owner window into L = min(raw downstream start, raw feeder ends, downstream outlet pond level) through LinkBlend.settleInto - Delegate LinkBlend.settleInto to ConfluenceGrader.settle with vertex 0 and outlet-zone vertices fixed, spreading the junction on tiers without cascades - Restyle every grade change made by link clamping or settling with ReachShaper.styles, so seam drops become cascades and waterfalls - Rebase the cross-window width and depth blend on the junction width so an already flared downstream reach is unchanged - Clamp a led-in pond outlet to the pond it leads out of instead of the lowest pond sharing it - Make ConfluenceGrader.spreadJunction and ReachShaper.styles public - Add ChunkWaterRasterTest cases for cross-window settling in both window orders, styled seam drops, spread junctions, flare rebasing and shared outlets
This commit is contained in:
1 parent
b6166bc6fa
commit
e62585b450
5 files changed
+271
-44
No files matched your search
@@ -7,6 +7,7 @@ import art.arcane.iris.generation.hydrology.plan.RegionPlan;
|
||||
import art.arcane.iris.generation.hydrology.plan.WindowKey;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInlet;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInletRasterizer;
|
||||
import art.arcane.iris.generation.hydrology.water.ConfluenceGrader;
|
||||
import art.arcane.iris.generation.hydrology.water.Pond;
|
||||
import art.arcane.iris.generation.hydrology.water.PondMask;
|
||||
import art.arcane.iris.generation.hydrology.water.Reach;
|
||||
@@ -294,18 +295,24 @@ final class ChunkFeatures {
|
||||
|
||||
private static final class Links {
|
||||
private final Map<WindowKey, IndexedWindow> windows;
|
||||
private final Map<Long, Integer> outletLevels = new HashMap<>();
|
||||
private final Map<Long, List<PondMask>> outletMasks = new HashMap<>();
|
||||
private final Map<Long, Reach> owned = new HashMap<>();
|
||||
private final Map<Long, List<Pond>> outletPonds = new HashMap<>();
|
||||
private final Map<Long, Reach> resolved = new HashMap<>();
|
||||
private final Set<Long> resolving = new HashSet<>();
|
||||
|
||||
private Links(Map<WindowKey, IndexedWindow> windows) {
|
||||
this.windows = windows;
|
||||
for (IndexedWindow window : windows.values()) {
|
||||
for (Reach reach : window.plan().reaches()) {
|
||||
Reach other = owned.putIfAbsent(reach.id(), reach);
|
||||
if (other != null) {
|
||||
throw new IllegalStateException("Reach " + reach.id() + " is owned by window " + window.plan().key()
|
||||
+ " and by window " + windowAt(other, other.xs().length - 1));
|
||||
}
|
||||
}
|
||||
for (Pond pond : window.plan().ponds()) {
|
||||
if (pond.outletReachId() != 0L) {
|
||||
outletLevels.merge(pond.outletReachId(), pond.level(), Math::min);
|
||||
outletMasks.computeIfAbsent(pond.outletReachId(), ignored -> new ArrayList<>()).add(pond.mask());
|
||||
outletPonds.computeIfAbsent(pond.outletReachId(), ignored -> new ArrayList<>()).add(pond);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -325,10 +332,31 @@ final class ChunkFeatures {
|
||||
return linked;
|
||||
}
|
||||
|
||||
private Reach link(Reach downstream, WindowKey owner) {
|
||||
Reach linked = feederLink(downstream, owner);
|
||||
Integer pondLevel = outletLevels.get(linked.id());
|
||||
return pondLevel == null ? linked : LinkBlend.clamp(linked, pondLevel);
|
||||
private Reach link(Reach reach, WindowKey owner) {
|
||||
Reach linked = feederLink(reach, owner);
|
||||
Integer pondLevel = outletLevel(reach);
|
||||
return settle(reach, pondLevel == null ? linked : LinkBlend.clamp(linked, pondLevel), owner);
|
||||
}
|
||||
|
||||
private Reach settle(Reach feeder, Reach linked, WindowKey owner) {
|
||||
Reach downstream = owned.get(feeder.downstreamId());
|
||||
if (downstream == null || owner.equals(windowAt(downstream, downstream.xs().length - 1))) {
|
||||
return linked;
|
||||
}
|
||||
int level = downstream.grade()[0];
|
||||
Integer pondLevel = outletLevel(downstream);
|
||||
if (pondLevel != null) {
|
||||
level = Math.min(level, pondLevel);
|
||||
}
|
||||
List<ConfluenceGrader.Footprint> receiving = new ArrayList<>();
|
||||
receiving.add(LinkBlend.footprint(downstream));
|
||||
for (Reach sibling : feeders(owner, downstream.id())) {
|
||||
level = Math.min(level, sibling.grade()[sibling.grade().length - 1]);
|
||||
if (sibling.id() != feeder.id()) {
|
||||
receiving.add(LinkBlend.footprint(sibling));
|
||||
}
|
||||
}
|
||||
return LinkBlend.settleInto(linked, level, receiving);
|
||||
}
|
||||
|
||||
private Reach feederLink(Reach downstream, WindowKey owner) {
|
||||
@@ -356,18 +384,39 @@ final class ChunkFeatures {
|
||||
}
|
||||
|
||||
private int junction(Reach reach) {
|
||||
List<PondMask> masks = outletMasks.get(reach.id());
|
||||
if (masks == null || reach.xs().length < 2) {
|
||||
return 0;
|
||||
return source(reach) == null ? 0 : 1;
|
||||
}
|
||||
|
||||
private Integer outletLevel(Reach reach) {
|
||||
List<Pond> ponds = outletPonds.get(reach.id());
|
||||
if (ponds == null) {
|
||||
return null;
|
||||
}
|
||||
Pond source = source(reach);
|
||||
if (source != null) {
|
||||
return source.level();
|
||||
}
|
||||
int level = Integer.MAX_VALUE;
|
||||
for (Pond pond : ponds) {
|
||||
level = Math.min(level, pond.level());
|
||||
}
|
||||
return level;
|
||||
}
|
||||
|
||||
private Pond source(Reach reach) {
|
||||
List<Pond> ponds = outletPonds.get(reach.id());
|
||||
if (ponds == null) {
|
||||
return null;
|
||||
}
|
||||
int x = Math.round(reach.xs()[0]);
|
||||
int z = Math.round(reach.zs()[0]);
|
||||
for (PondMask mask : masks) {
|
||||
if (mask.contains(x, z)) {
|
||||
return 1;
|
||||
Pond source = null;
|
||||
for (Pond pond : ponds) {
|
||||
if (pond.mask().contains(x, z) && (source == null || lower(pond, source))) {
|
||||
source = pond;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return source;
|
||||
}
|
||||
|
||||
private long cornerBlock(Reach reach) {
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package art.arcane.iris.generation.hydrology.raster;
|
||||
|
||||
import art.arcane.iris.generation.hydrology.water.ConfluenceGrader;
|
||||
import art.arcane.iris.generation.hydrology.water.Reach;
|
||||
import art.arcane.iris.generation.hydrology.water.ReachShaper;
|
||||
import art.arcane.iris.generation.hydrology.water.ReachStyle;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -19,7 +22,6 @@ public final class LinkBlend {
|
||||
}
|
||||
|
||||
static Reach blend(Reach downstream, List<Reach> feeders, int junction) {
|
||||
int end = lowestEnd(feeders);
|
||||
float width = 0f;
|
||||
float depth = 0f;
|
||||
for (Reach feeder : feeders) {
|
||||
@@ -29,20 +31,20 @@ public final class LinkBlend {
|
||||
}
|
||||
float[] xs = downstream.xs();
|
||||
float[] zs = downstream.zs();
|
||||
int[] grade = clamped(downstream.grade(), end);
|
||||
float[] halfWidth = downstream.halfWidth().clone();
|
||||
float[] depths = downstream.depth().clone();
|
||||
float widthShift = width - halfWidth[junction];
|
||||
float depthShift = depth - depths[junction];
|
||||
float[] along = new float[xs.length];
|
||||
for (int point = 1; point < xs.length; point++) {
|
||||
along[point] = along[point - 1] + (float) Math.hypot(xs[point] - xs[point - 1], zs[point] - zs[point - 1]);
|
||||
}
|
||||
for (int point = 0; point < xs.length; point++) {
|
||||
float fromJunction = along[point] - along[junction];
|
||||
halfWidth[point] = blend(width, halfWidth[point], fromJunction);
|
||||
depths[point] = blend(depth, depths[point], fromJunction);
|
||||
halfWidth[point] += blend(widthShift, 0f, fromJunction);
|
||||
depths[point] += blend(depthShift, 0f, fromJunction);
|
||||
}
|
||||
return new Reach(downstream.id(), downstream.tier(), downstream.downstreamId(), xs, zs, grade, halfWidth, depths,
|
||||
downstream.style(), downstream.catchment());
|
||||
return regraded(downstream, clamped(downstream.grade(), lowestEnd(feeders)), halfWidth, depths);
|
||||
}
|
||||
|
||||
static Reach clamp(Reach downstream, List<Reach> feeders) {
|
||||
@@ -50,15 +52,52 @@ public final class LinkBlend {
|
||||
}
|
||||
|
||||
static Reach clamp(Reach downstream, int end) {
|
||||
boolean above = false;
|
||||
for (int grade : downstream.grade()) {
|
||||
above |= grade > end;
|
||||
int[] grade = clamped(downstream.grade(), end);
|
||||
return grade == downstream.grade() ? downstream : regraded(downstream, grade, downstream.halfWidth(), downstream.depth());
|
||||
}
|
||||
|
||||
static Reach settleInto(Reach feeder, int level, List<ConfluenceGrader.Footprint> receiving) {
|
||||
int[] grade = feeder.grade();
|
||||
boolean[] fixed = fixed(feeder);
|
||||
int waterfallMinimumDrop = feeder.tier().waterfallMinimumDrop();
|
||||
int[] settled = ConfluenceGrader.settle(footprint(feeder), grade, fixed, receiving, level, waterfallMinimumDrop);
|
||||
if (settled == grade) {
|
||||
return feeder;
|
||||
}
|
||||
if (!above) {
|
||||
return downstream;
|
||||
if (!feeder.tier().cascades()) {
|
||||
ConfluenceGrader.spreadJunction(settled, grade, fixed, waterfallMinimumDrop, Integer.MIN_VALUE);
|
||||
}
|
||||
return new Reach(downstream.id(), downstream.tier(), downstream.downstreamId(), downstream.xs(), downstream.zs(),
|
||||
clamped(downstream.grade(), end), downstream.halfWidth(), downstream.depth(), downstream.style(), downstream.catchment());
|
||||
return regraded(feeder, settled, feeder.halfWidth(), feeder.depth());
|
||||
}
|
||||
|
||||
static ConfluenceGrader.Footprint footprint(Reach reach) {
|
||||
return new ConfluenceGrader.Footprint(reach.xs(), reach.zs(), reach.halfWidth());
|
||||
}
|
||||
|
||||
private static boolean[] fixed(Reach feeder) {
|
||||
ReachStyle[] style = feeder.style();
|
||||
boolean[] fixed = new boolean[style.length];
|
||||
fixed[0] = true;
|
||||
for (int point = 1; point < style.length; point++) {
|
||||
fixed[point] = style[point] == ReachStyle.POND_OUTLET;
|
||||
}
|
||||
return fixed;
|
||||
}
|
||||
|
||||
private static Reach regraded(Reach reach, int[] grade, float[] halfWidth, float[] depth) {
|
||||
ReachStyle[] style = grade == reach.grade() ? reach.style() : restyled(reach.style(), grade, reach.tier().waterfallMinimumDrop());
|
||||
return new Reach(reach.id(), reach.tier(), reach.downstreamId(), reach.xs(), reach.zs(), grade, halfWidth, depth, style,
|
||||
reach.catchment());
|
||||
}
|
||||
|
||||
private static ReachStyle[] restyled(ReachStyle[] style, int[] grade, int waterfallMinimumDrop) {
|
||||
boolean[] mouth = new boolean[style.length];
|
||||
boolean[] outlet = new boolean[style.length];
|
||||
for (int point = 0; point < style.length; point++) {
|
||||
mouth[point] = style[point] == ReachStyle.MOUTH;
|
||||
outlet[point] = style[point] == ReachStyle.POND_OUTLET;
|
||||
}
|
||||
return ReachShaper.styles(grade, mouth, outlet, waterfallMinimumDrop);
|
||||
}
|
||||
|
||||
private static int lowestEnd(List<Reach> feeders) {
|
||||
@@ -70,9 +109,14 @@ public final class LinkBlend {
|
||||
}
|
||||
|
||||
private static int[] clamped(int[] grade, int end) {
|
||||
int[] result = grade.clone();
|
||||
for (int point = 0; point < result.length; point++) {
|
||||
result[point] = Math.min(result[point], end);
|
||||
int[] result = grade;
|
||||
for (int point = 0; point < grade.length; point++) {
|
||||
if (grade[point] > end) {
|
||||
if (result == grade) {
|
||||
result = grade.clone();
|
||||
}
|
||||
result[point] = end;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
+12
-12
@@ -30,6 +30,18 @@ public final class ConfluenceGrader {
|
||||
return settled;
|
||||
}
|
||||
|
||||
public static void spreadJunction(int[] settled, int[] grade, boolean[] fixed, int waterfallMinimumDrop, int startLimit) {
|
||||
int lowered = 0;
|
||||
while (settled[lowered] == grade[lowered]) {
|
||||
lowered++;
|
||||
}
|
||||
for (int point = settled.length - 2; point >= 0; point--) {
|
||||
if (!ReachGrader.spreadPoint(settled, point, waterfallMinimumDrop, startLimit, fixed) && point < lowered) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static boolean[] level(List<ReachDraft> drafts, int[] upstreamFirst) {
|
||||
boolean[] touched = new boolean[drafts.size()];
|
||||
for (int position = upstreamFirst.length - 1; position >= 0; position--) {
|
||||
@@ -83,18 +95,6 @@ public final class ConfluenceGrader {
|
||||
+ " of its feeder reach " + feeder.id + " at junction " + feeder.xs[end] + "," + feeder.zs[end]);
|
||||
}
|
||||
|
||||
private static void spreadJunction(int[] settled, int[] grade, boolean[] fixed, int waterfallMinimumDrop, int startLimit) {
|
||||
int lowered = 0;
|
||||
while (settled[lowered] == grade[lowered]) {
|
||||
lowered++;
|
||||
}
|
||||
for (int point = settled.length - 2; point >= 0; point--) {
|
||||
if (!ReachGrader.spreadPoint(settled, point, waterfallMinimumDrop, startLimit, fixed) && point < lowered) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean pooled(Footprint feeder, boolean[] fixed, List<Footprint> receiving, double[] arc, int point) {
|
||||
if (arc[point] > POOL_CAP || fixed[point]) {
|
||||
return false;
|
||||
|
||||
@@ -506,7 +506,7 @@ public final class ReachShaper {
|
||||
draft.maxHalfWidth = running;
|
||||
}
|
||||
|
||||
static ReachStyle[] styles(int[] grade, boolean[] ocean, boolean[] outletZone, int waterfallMinimumDrop) {
|
||||
public static ReachStyle[] styles(int[] grade, boolean[] ocean, boolean[] outletZone, int waterfallMinimumDrop) {
|
||||
ReachStyle[] styles = new ReachStyle[grade.length];
|
||||
for (int point = 0; point < grade.length; point++) {
|
||||
int drop = point == 0 ? 0 : grade[point - 1] - grade[point];
|
||||
|
||||
Reference in new issue
Block a user