mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 16:54:04 +00:00
Agree sea inlets across windows
- Pass the planning window to SeaInletPlanner from WindowPlanner - Mark a site clipped when its candidate area or any trace, cover, mouth or chamber lookup reaches the span edge - Keep clipped inlets out of separation and the planned list unless the planning window owns them - Avoid only reaches owned by the planning window or its 8 neighbours - Add InletTerrain span views and an open-coast 3x3 window agreement test
This commit is contained in:
1 parent
9c95e7901c
commit
21ed677bf4
4 files changed
+187
-35
No files matched your search
+25
-10
@@ -7,6 +7,7 @@ import art.arcane.iris.generation.hydrology.grid.FlowAccumulator;
|
||||
import art.arcane.iris.generation.hydrology.grid.HydrologySampleBuffer;
|
||||
import art.arcane.iris.generation.hydrology.grid.PriorityFlood;
|
||||
import art.arcane.iris.generation.hydrology.plan.HydrologySettings;
|
||||
import art.arcane.iris.generation.hydrology.plan.WindowKey;
|
||||
import art.arcane.iris.generation.hydrology.water.Reach;
|
||||
import art.arcane.iris.generation.hydrology.water.ReachStyle;
|
||||
import art.arcane.iris.generation.hydrology.water.ShapedNetwork;
|
||||
@@ -24,21 +25,24 @@ final class InletTerrain {
|
||||
static final int CELL = 8;
|
||||
static final int WIDTH = 96;
|
||||
static final int DEPTH = 64;
|
||||
static final int SPAN = 3 * WindowKey.SIZE / CELL;
|
||||
|
||||
final DoubleBinaryOperator natural;
|
||||
final WindowKey window;
|
||||
final DemGrid grid;
|
||||
final HydrologySampleBuffer samples;
|
||||
final int[] receivers;
|
||||
final float[] accumulation;
|
||||
|
||||
private InletTerrain(DoubleBinaryOperator natural) {
|
||||
this(natural, 0, 0);
|
||||
this(natural, 0, 0, WIDTH, DEPTH);
|
||||
}
|
||||
|
||||
private InletTerrain(DoubleBinaryOperator natural, int originX, int originZ) {
|
||||
private InletTerrain(DoubleBinaryOperator natural, int originX, int originZ, int width, int depth) {
|
||||
this.natural = natural;
|
||||
this.grid = new DemGrid(originX, originZ, CELL, WIDTH, DEPTH);
|
||||
int count = WIDTH * DEPTH;
|
||||
this.window = WindowKey.containing(originX + width * CELL / 2, originZ + depth * CELL / 2);
|
||||
this.grid = new DemGrid(originX, originZ, CELL, width, depth);
|
||||
int count = width * depth;
|
||||
this.samples = new HydrologySampleBuffer(count);
|
||||
BitSet seeds = new BitSet(count);
|
||||
for (int cell = 0; cell < count; cell++) {
|
||||
@@ -48,14 +52,14 @@ final class InletTerrain {
|
||||
grid.values()[cell] = height;
|
||||
samples.height()[cell] = height;
|
||||
samples.ocean()[cell] = Math.round(height) < SEA;
|
||||
int i = cell % WIDTH;
|
||||
int j = cell / WIDTH;
|
||||
if (samples.ocean()[cell] || i == 0 || j == 0 || i == WIDTH - 1 || j == DEPTH - 1) {
|
||||
int i = cell % width;
|
||||
int j = cell / width;
|
||||
if (samples.ocean()[cell] || i == 0 || j == 0 || i == width - 1 || j == depth - 1) {
|
||||
seeds.set(cell);
|
||||
}
|
||||
}
|
||||
float[] filled = PriorityFlood.fill(grid, seeds, 0.001f);
|
||||
DemGrid surface = new DemGrid(originX, originZ, CELL, WIDTH, DEPTH);
|
||||
DemGrid surface = new DemGrid(originX, originZ, CELL, width, depth);
|
||||
System.arraycopy(filled, 0, surface.values(), 0, count);
|
||||
this.receivers = D8Router.receivers(surface, filled);
|
||||
float[] weights = new float[count];
|
||||
@@ -72,6 +76,13 @@ final class InletTerrain {
|
||||
return new InletTerrain((x, z) -> x < COAST_X ? SEA - 20D : SEA + cliffHeight + 0.08D * (x - COAST_X));
|
||||
}
|
||||
|
||||
static InletTerrain openCoast() {
|
||||
return new InletTerrain((x, z) -> {
|
||||
double coast = 768D + 120D * Math.sin(z / 180D) + 40D * Math.sin(z / 53D);
|
||||
return x < coast ? SEA - 20D : SEA + 30D + 0.08D * (x - coast);
|
||||
});
|
||||
}
|
||||
|
||||
static InletTerrain cliffWithTrough(double cliffHeight, double troughFrom, double troughTo, double troughHeight) {
|
||||
return new InletTerrain((x, z) -> {
|
||||
if (x < COAST_X) {
|
||||
@@ -124,11 +135,15 @@ final class InletTerrain {
|
||||
}
|
||||
|
||||
InletTerrain shifted(int originX, int originZ) {
|
||||
return new InletTerrain(natural, originX, originZ);
|
||||
return new InletTerrain(natural, originX, originZ, WIDTH, DEPTH);
|
||||
}
|
||||
|
||||
InletTerrain span(WindowKey window) {
|
||||
return new InletTerrain(natural, (window.wx() - 1) * WindowKey.SIZE, (window.wz() - 1) * WindowKey.SIZE, SPAN, SPAN);
|
||||
}
|
||||
|
||||
List<SeaInlet> plan(HydrologySettings settings, ShapedNetwork network) {
|
||||
return new SeaInletPlanner(settings).plan(grid, samples, receivers, accumulation, network, SEED);
|
||||
return new SeaInletPlanner(settings).plan(window, grid, samples, receivers, accumulation, network, SEED);
|
||||
}
|
||||
|
||||
List<SeaInlet> plan(HydrologySettings settings) {
|
||||
|
||||
+68
-1
@@ -8,8 +8,11 @@ import art.arcane.iris.generation.hydrology.water.ShapedNetwork;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -336,11 +339,75 @@ public class SeaInletPlannerTest {
|
||||
assertEquals(first.size(), first.stream().mapToLong(SeaInlet::id).distinct().count());
|
||||
InletTerrain terrain = InletTerrain.cliff(30D);
|
||||
List<SeaInlet> otherSeed = new SeaInletPlanner(HydrologySettings.compile(new IrisHydrology(), 99L, SEA, InletTerrain.MIN_Y,
|
||||
InletTerrain.MAX_Y)).plan(terrain.grid, terrain.samples, terrain.receivers, terrain.accumulation,
|
||||
InletTerrain.MAX_Y)).plan(terrain.window, terrain.grid, terrain.samples, terrain.receivers, terrain.accumulation,
|
||||
new ShapedNetwork(List.of(), List.of()), 99L);
|
||||
assertNotEquals(first, otherSeed);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inletsAgreeAcrossWindowsOnOpenCoast() {
|
||||
IrisHydrology dense = new IrisHydrology();
|
||||
dense.getUnderground().getSeaInlets().setSpacing(64);
|
||||
HydrologySettings settings = InletTerrain.settings(dense);
|
||||
InletTerrain coast = InletTerrain.openCoast();
|
||||
List<WindowKey> windows = new ArrayList<>(9);
|
||||
for (int wz = 0; wz <= 2; wz++) {
|
||||
for (int wx = 0; wx <= 2; wx++) {
|
||||
windows.add(new WindowKey(wx, wz));
|
||||
}
|
||||
}
|
||||
Map<WindowKey, List<SeaInlet>> views = views(coast, settings, windows);
|
||||
assertEquals("planning the windows in reverse order changes nothing", views, views(coast, settings, windows.reversed()));
|
||||
List<String> disagreements = new ArrayList<>();
|
||||
int owned = 0;
|
||||
int crossing = 0;
|
||||
int seen = 0;
|
||||
for (WindowKey owner : windows) {
|
||||
for (SeaInlet inlet : views.get(owner)) {
|
||||
if (!owner.equals(owner(inlet))) {
|
||||
continue;
|
||||
}
|
||||
owned++;
|
||||
crossing += leavesWindow(inlet, owner) ? 1 : 0;
|
||||
for (WindowKey view : windows) {
|
||||
if (view.equals(owner)) {
|
||||
continue;
|
||||
}
|
||||
for (SeaInlet other : views.get(view)) {
|
||||
if (other.id() != inlet.id()) {
|
||||
continue;
|
||||
}
|
||||
seen++;
|
||||
if (!other.equals(inlet)) {
|
||||
disagreements.add(inlet + " of " + owner + " is " + other + " in " + view);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
assertTrue(disagreements.size() + " views disagree with the owner: " + disagreements, disagreements.isEmpty());
|
||||
assertTrue("owned inlets " + owned, owned >= 20);
|
||||
assertTrue("owned inlets that neighbouring windows also plan " + seen, seen >= 60);
|
||||
assertTrue("owned inlets crossing a window line " + crossing, crossing > 0);
|
||||
}
|
||||
|
||||
private static Map<WindowKey, List<SeaInlet>> views(InletTerrain coast, HydrologySettings settings, List<WindowKey> order) {
|
||||
Map<WindowKey, List<SeaInlet>> views = new LinkedHashMap<>();
|
||||
for (WindowKey window : order) {
|
||||
views.put(window, coast.span(window).plan(settings));
|
||||
}
|
||||
return views;
|
||||
}
|
||||
|
||||
private static WindowKey owner(SeaInlet inlet) {
|
||||
return WindowKey.containing((int) Math.floor(inlet.xs()[1]), (int) Math.floor(inlet.zs()[1]));
|
||||
}
|
||||
|
||||
private static boolean leavesWindow(SeaInlet inlet, WindowKey owner) {
|
||||
int[] bounds = SeaInletRasterizer.bounds(inlet);
|
||||
return !WindowKey.containing(bounds[0], bounds[1]).equals(owner) || !WindowKey.containing(bounds[2], bounds[3]).equals(owner);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inletsReachingPastTheNextWindowAreRejected() {
|
||||
IrisHydrology fits = new IrisHydrology();
|
||||
|
||||
Reference in new issue
Block a user