mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 08:44:50 +00:00
Tidal reach plan format
- Add ReachStyle.TIDAL with code 6, rastered as WaterRole.INLET with sea fluid - Add a tidal tier to the settings, built from the river tier and the inlet bank knobs - Remove the inlet section from WindowPlan, HydrologyPlanCodec and HydrologyPlanPreview - Require tidal reaches to be whole, at sea level and draining to the sea - Record, search and draw inlets from tidal reaches
This commit is contained in:
35 files changed
+253
-494
No files matched your search
+13
-14
@@ -11,7 +11,6 @@ import art.arcane.iris.generation.hydrology.query.HydrologyFeatureQuery;
|
||||
import art.arcane.iris.generation.hydrology.query.HydrologyFeatureRef;
|
||||
import art.arcane.iris.generation.hydrology.query.HydrologyFeatureType;
|
||||
import art.arcane.iris.generation.hydrology.query.HydrologySearchTimeoutException;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInlet;
|
||||
import art.arcane.iris.generation.hydrology.water.HydrologyTier;
|
||||
import art.arcane.iris.generation.hydrology.water.Pond;
|
||||
import art.arcane.iris.generation.hydrology.water.PondKind;
|
||||
@@ -219,18 +218,6 @@ final class HydrologyFeatureSearch {
|
||||
pond(pond, type);
|
||||
}
|
||||
}
|
||||
if (types.contains(HydrologyFeatureType.SEA_INLET)) {
|
||||
for (SeaInlet inlet : plan.inlets()) {
|
||||
inlet(inlet);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void inlet(SeaInlet inlet) {
|
||||
for (int station = 0; station < inlet.stations(); station++) {
|
||||
offer(inlet.id(), HydrologyFeatureType.SEA_INLET, (int) Math.floor(inlet.xs()[station]), inlet.waterLevel(),
|
||||
(int) Math.floor(inlet.zs()[station]));
|
||||
}
|
||||
}
|
||||
|
||||
private HydrologyFeatureType pondType(Pond pond) {
|
||||
@@ -244,6 +231,12 @@ final class HydrologyFeatureSearch {
|
||||
}
|
||||
|
||||
private void reach(Reach reach) {
|
||||
if (reach.style()[0] == ReachStyle.TIDAL) {
|
||||
if (types.contains(HydrologyFeatureType.SEA_INLET)) {
|
||||
tidal(reach);
|
||||
}
|
||||
return;
|
||||
}
|
||||
HydrologyFeatureType channel = channelType(settings, reach.tier());
|
||||
boolean whole = types.contains(channel);
|
||||
float[] xs = reach.xs();
|
||||
@@ -257,6 +250,12 @@ final class HydrologyFeatureSearch {
|
||||
}
|
||||
}
|
||||
|
||||
private void tidal(Reach reach) {
|
||||
for (int index = 0; index < reach.xs().length; index++) {
|
||||
offer(reach.id(), HydrologyFeatureType.SEA_INLET, (int) Math.floor(reach.xs()[index]), reach.grade()[index], (int) Math.floor(reach.zs()[index]));
|
||||
}
|
||||
}
|
||||
|
||||
private void pond(Pond pond, HydrologyFeatureType type) {
|
||||
PondMask mask = pond.mask();
|
||||
for (int j = 0; j < mask.depth(); j++) {
|
||||
@@ -306,7 +305,7 @@ final class HydrologyFeatureSearch {
|
||||
case CASCADE -> HydrologyFeatureType.CASCADE;
|
||||
case WATERFALL -> HydrologyFeatureType.WATERFALL;
|
||||
case MOUTH -> HydrologyFeatureType.MOUTH;
|
||||
case RUN, RIFFLE, POND_OUTLET -> null;
|
||||
case RUN, RIFFLE, POND_OUTLET, TIDAL -> null;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+3
-5
@@ -1,20 +1,18 @@
|
||||
package art.arcane.iris.generation.hydrology.engine;
|
||||
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInlet;
|
||||
import art.arcane.iris.generation.hydrology.water.Pond;
|
||||
import art.arcane.iris.generation.hydrology.water.Reach;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public record HydrologyPlanPreview(List<Reach> reaches, List<Pond> ponds, List<Pond> lakes, List<SeaInlet> inlets, boolean complete) {
|
||||
public static final HydrologyPlanPreview EMPTY = new HydrologyPlanPreview(List.of(), List.of(), List.of(), List.of(), true);
|
||||
public static final HydrologyPlanPreview PENDING = new HydrologyPlanPreview(List.of(), List.of(), List.of(), List.of(), false);
|
||||
public record HydrologyPlanPreview(List<Reach> reaches, List<Pond> ponds, List<Pond> lakes, boolean complete) {
|
||||
public static final HydrologyPlanPreview EMPTY = new HydrologyPlanPreview(List.of(), List.of(), List.of(), true);
|
||||
public static final HydrologyPlanPreview PENDING = new HydrologyPlanPreview(List.of(), List.of(), List.of(), false);
|
||||
|
||||
public HydrologyPlanPreview {
|
||||
reaches = List.copyOf(Objects.requireNonNull(reaches, "reaches"));
|
||||
ponds = List.copyOf(Objects.requireNonNull(ponds, "ponds"));
|
||||
lakes = List.copyOf(Objects.requireNonNull(lakes, "lakes"));
|
||||
inlets = List.copyOf(Objects.requireNonNull(inlets, "inlets"));
|
||||
}
|
||||
}
|
||||
+2
-23
@@ -20,7 +20,6 @@ import art.arcane.iris.generation.hydrology.raster.ChunkRasterizer;
|
||||
import art.arcane.iris.generation.hydrology.raster.ChunkWaterRaster;
|
||||
import art.arcane.iris.generation.hydrology.raster.NaturalHeights;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInlet;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInletRasterizer;
|
||||
import art.arcane.iris.generation.hydrology.water.HydrologyTier;
|
||||
import art.arcane.iris.generation.hydrology.water.Pond;
|
||||
import art.arcane.iris.generation.hydrology.water.Reach;
|
||||
@@ -307,7 +306,6 @@ public final class HydrologyRuntime {
|
||||
boolean complete = true;
|
||||
List<Reach> reaches = new ArrayList<>();
|
||||
List<Pond> ponds = new ArrayList<>();
|
||||
List<SeaInlet> inlets = new ArrayList<>();
|
||||
for (int wz = min.wz() - 1; wz <= max.wz() + 1; wz++) {
|
||||
for (int wx = min.wx() - 1; wx <= max.wx() + 1; wx++) {
|
||||
WindowKey window = new WindowKey(wx, wz);
|
||||
@@ -315,7 +313,6 @@ public final class HydrologyRuntime {
|
||||
if (plan.isPresent()) {
|
||||
reaches.addAll(plan.get().plan().reaches());
|
||||
ponds.addAll(plan.get().plan().ponds());
|
||||
inlets.addAll(plan.get().plan().inlets());
|
||||
} else {
|
||||
complete = false;
|
||||
requestPreview(window, windowPreviewFailures, key(wx, wz), "window " + wx + "," + wz, () -> cache.previewWindow(window));
|
||||
@@ -335,7 +332,7 @@ public final class HydrologyRuntime {
|
||||
() -> cache.previewRegion(region));
|
||||
}
|
||||
}
|
||||
return new HydrologyPlanPreview(reaches, ponds, List.copyOf(lakes.values()), inlets, complete);
|
||||
return new HydrologyPlanPreview(reaches, ponds, List.copyOf(lakes.values()), complete);
|
||||
}
|
||||
|
||||
public ChunkWaterRaster rasterAt(int blockX, int blockZ) {
|
||||
@@ -442,25 +439,7 @@ public final class HydrologyRuntime {
|
||||
}
|
||||
|
||||
public List<SeaInlet> inlets(int chunkX, int chunkZ) {
|
||||
if (cache == null) {
|
||||
return List.of();
|
||||
}
|
||||
requireOpen();
|
||||
boolean main = mainThread.getAsBoolean();
|
||||
List<SeaInlet> touching = new ArrayList<>();
|
||||
for (CompletableFuture<IndexedWindow> plan : plans(neighbourhood(chunkX, chunkZ), List.of(), PlanMode.DEMAND).windowFutures()) {
|
||||
if (main && !plan.isDone()) {
|
||||
throw new IllegalStateException("The hydrology windows around chunk " + chunkX + "," + chunkZ
|
||||
+ " are not planned yet, so its sea inlets cannot be generated on the main thread.");
|
||||
}
|
||||
IndexedWindow window = main ? plan.join() : cache.awaitPlan(plan);
|
||||
for (SeaInlet inlet : window.plan().inlets()) {
|
||||
if (SeaInletRasterizer.touches(inlet, chunkX, chunkZ)) {
|
||||
touching.add(inlet);
|
||||
}
|
||||
}
|
||||
}
|
||||
return touching;
|
||||
return List.of();
|
||||
}
|
||||
|
||||
public Set<HydrologyFeatureType> standingWaterTypes(int chunkX, int chunkZ, long featureId) {
|
||||
|
||||
+14
-66
@@ -1,6 +1,5 @@
|
||||
package art.arcane.iris.generation.hydrology.plan;
|
||||
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInlet;
|
||||
import art.arcane.iris.generation.hydrology.water.HydrologyTier;
|
||||
import art.arcane.iris.generation.hydrology.water.Pond;
|
||||
import art.arcane.iris.generation.hydrology.water.PondKind;
|
||||
@@ -26,31 +25,27 @@ public final class HydrologyPlanCodec {
|
||||
private static final int POINT_BYTES = 5 * Integer.BYTES + 1;
|
||||
private static final int REACH_BYTES = 2 * Long.BYTES + 4 * Integer.BYTES + 2 * POINT_BYTES;
|
||||
private static final int POND_BYTES = 2 * Long.BYTES + 1 + 15 * Integer.BYTES;
|
||||
private static final int STATION_BYTES = 5 * Integer.BYTES;
|
||||
private static final int INLET_BYTES = Long.BYTES + 5 * Integer.BYTES + 2 * STATION_BYTES;
|
||||
|
||||
private HydrologyPlanCodec() {
|
||||
}
|
||||
|
||||
public static byte[] encode(HydrologySettings settings, WindowPlan plan) {
|
||||
return encode(settings, WINDOW, plan.key().wx(), plan.key().wz(), plan.reaches(), plan.ponds(), plan.inlets());
|
||||
return encode(settings, WINDOW, plan.key().wx(), plan.key().wz(), plan.reaches(), plan.ponds());
|
||||
}
|
||||
|
||||
public static byte[] encode(HydrologySettings settings, RegionPlan plan) {
|
||||
return encode(settings, REGION, plan.key().rx(), plan.key().rz(), plan.majorReaches(), plan.lakes(), List.of());
|
||||
return encode(settings, REGION, plan.key().rx(), plan.key().rz(), plan.majorReaches(), plan.lakes());
|
||||
}
|
||||
|
||||
public static Optional<WindowPlan> decodeWindow(HydrologySettings settings, byte[] data) {
|
||||
return decode(settings, WINDOW, data).map(body -> new WindowPlan(new WindowKey(body.x(), body.z()), body.reaches(), body.ponds(),
|
||||
body.inlets()));
|
||||
return decode(settings, WINDOW, data).map(body -> new WindowPlan(new WindowKey(body.x(), body.z()), body.reaches(), body.ponds()));
|
||||
}
|
||||
|
||||
public static Optional<RegionPlan> decodeRegion(HydrologySettings settings, byte[] data) {
|
||||
return decode(settings, REGION, data).map(body -> new RegionPlan(new RegionKey(body.x(), body.z()), body.reaches(), body.ponds()));
|
||||
}
|
||||
|
||||
private static byte[] encode(HydrologySettings settings, byte kind, int x, int z, List<Reach> reaches, List<Pond> ponds,
|
||||
List<SeaInlet> inlets) {
|
||||
private static byte[] encode(HydrologySettings settings, byte kind, int x, int z, List<Reach> reaches, List<Pond> ponds) {
|
||||
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||
try (DataOutputStream out = new DataOutputStream(bytes)) {
|
||||
out.writeInt(MAGIC);
|
||||
@@ -66,12 +61,6 @@ public final class HydrologyPlanCodec {
|
||||
for (Pond pond : ponds) {
|
||||
writePond(out, pond);
|
||||
}
|
||||
if (kind == WINDOW) {
|
||||
out.writeInt(inlets.size());
|
||||
for (SeaInlet inlet : inlets) {
|
||||
writeInlet(out, inlet);
|
||||
}
|
||||
}
|
||||
} catch (IOException failure) {
|
||||
throw new UncheckedIOException(failure);
|
||||
}
|
||||
@@ -79,6 +68,9 @@ public final class HydrologyPlanCodec {
|
||||
}
|
||||
|
||||
private static int tierIndex(HydrologySettings settings, Reach reach) {
|
||||
if (reach.tier().equals(settings.tidalTier())) {
|
||||
return settings.tiers().size();
|
||||
}
|
||||
int index = settings.tiers().indexOf(reach.tier());
|
||||
if (index < 0) {
|
||||
throw new IllegalArgumentException("Reach " + reach.id() + " uses tier " + reach.tier().name() + ", which is not in the settings.");
|
||||
@@ -139,24 +131,6 @@ public final class HydrologyPlanCodec {
|
||||
out.writeInt(pond.floorZ());
|
||||
}
|
||||
|
||||
private static void writeInlet(DataOutputStream out, SeaInlet inlet) throws IOException {
|
||||
out.writeLong(inlet.id());
|
||||
out.writeInt(inlet.waterLevel());
|
||||
out.writeInt(inlet.chamberX());
|
||||
out.writeInt(inlet.chamberZ());
|
||||
out.writeInt(inlet.chamberRadius());
|
||||
out.writeInt(inlet.stations());
|
||||
writeFloats(out, inlet.xs());
|
||||
writeFloats(out, inlet.zs());
|
||||
writeFloats(out, inlet.halfWidth());
|
||||
for (int floor : inlet.floor()) {
|
||||
out.writeInt(floor);
|
||||
}
|
||||
for (int ceiling : inlet.ceiling()) {
|
||||
out.writeInt(ceiling);
|
||||
}
|
||||
}
|
||||
|
||||
private static void writeFloats(DataOutputStream out, float[] values) throws IOException {
|
||||
for (float value : values) {
|
||||
out.writeInt(Float.floatToRawIntBits(value));
|
||||
@@ -174,33 +148,28 @@ public final class HydrologyPlanCodec {
|
||||
int reachCount = count(in, REACH_BYTES);
|
||||
List<Reach> reaches = new ArrayList<>(reachCount);
|
||||
for (int index = 0; index < reachCount; index++) {
|
||||
reaches.add(readReach(in, settings.tiers()));
|
||||
reaches.add(readReach(in, settings));
|
||||
}
|
||||
int pondCount = count(in, POND_BYTES);
|
||||
List<Pond> ponds = new ArrayList<>(pondCount);
|
||||
for (int index = 0; index < pondCount; index++) {
|
||||
ponds.add(readPond(in));
|
||||
}
|
||||
List<SeaInlet> inlets = new ArrayList<>();
|
||||
if (kind == WINDOW) {
|
||||
int inletCount = count(in, INLET_BYTES);
|
||||
for (int index = 0; index < inletCount; index++) {
|
||||
inlets.add(readInlet(in));
|
||||
}
|
||||
}
|
||||
if (in.hasRemaining()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of(new Body(x, z, reaches, ponds, inlets));
|
||||
return Optional.of(new Body(x, z, reaches, ponds));
|
||||
} catch (BufferUnderflowException | IllegalArgumentException | IllegalStateException malformed) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
private static Reach readReach(ByteBuffer in, List<HydrologyTier> tiers) {
|
||||
private static Reach readReach(ByteBuffer in, HydrologySettings settings) {
|
||||
long id = in.getLong();
|
||||
long downstreamId = in.getLong();
|
||||
HydrologyTier tier = tiers.get(index(in.getInt(), tiers.size()));
|
||||
List<HydrologyTier> tiers = settings.tiers();
|
||||
int tierIndex = index(in.getInt(), tiers.size() + 1);
|
||||
HydrologyTier tier = tierIndex == tiers.size() ? settings.tidalTier() : tiers.get(tierIndex);
|
||||
float catchment = Float.intBitsToFloat(in.getInt());
|
||||
int points = count(in, POINT_BYTES);
|
||||
float[] xs = readFloats(in, points);
|
||||
@@ -246,27 +215,6 @@ public final class HydrologyPlanCodec {
|
||||
return new Pond(id, kind, level, floor, spillX, spillZ, spillHeight, mask, outletReachId, damRaise, fluid, in.getInt(), in.getInt());
|
||||
}
|
||||
|
||||
private static SeaInlet readInlet(ByteBuffer in) {
|
||||
long id = in.getLong();
|
||||
int waterLevel = in.getInt();
|
||||
int chamberX = in.getInt();
|
||||
int chamberZ = in.getInt();
|
||||
int chamberRadius = in.getInt();
|
||||
int stations = count(in, STATION_BYTES);
|
||||
float[] xs = readFloats(in, stations);
|
||||
float[] zs = readFloats(in, stations);
|
||||
float[] halfWidth = readFloats(in, stations);
|
||||
int[] floor = new int[stations];
|
||||
for (int station = 0; station < stations; station++) {
|
||||
floor[station] = in.getInt();
|
||||
}
|
||||
int[] ceiling = new int[stations];
|
||||
for (int station = 0; station < stations; station++) {
|
||||
ceiling[station] = in.getInt();
|
||||
}
|
||||
return new SeaInlet(id, xs, zs, halfWidth, waterLevel, floor, ceiling, chamberX, chamberZ, chamberRadius);
|
||||
}
|
||||
|
||||
private static String readString(ByteBuffer in) {
|
||||
int length = in.getInt();
|
||||
if (length == -1) {
|
||||
@@ -303,6 +251,6 @@ public final class HydrologyPlanCodec {
|
||||
return value;
|
||||
}
|
||||
|
||||
private record Body(int x, int z, List<Reach> reaches, List<Pond> ponds, List<SeaInlet> inlets) {
|
||||
private record Body(int x, int z, List<Reach> reaches, List<Pond> ponds) {
|
||||
}
|
||||
}
|
||||
@@ -51,6 +51,8 @@ public final class HydrologySettings {
|
||||
private static final int MAX_DELTA_LENGTH = 384;
|
||||
public static final float MAX_HALF_WIDTH = 64f;
|
||||
public static final int DELTA_STEP = 2;
|
||||
private static final int TIDAL_BASE_TIER = 1;
|
||||
private static final String TIDAL_TIER_NAME = "tidal";
|
||||
private static final double MIN_INLET_MOUTH = 2D;
|
||||
private static final double MAX_INLET_MOUTH = 32D;
|
||||
private static final double MIN_INLET_HEAD = 1D;
|
||||
@@ -94,6 +96,7 @@ public final class HydrologySettings {
|
||||
private final Lakes lakes;
|
||||
private final Deformation deformation;
|
||||
private final Underground underground;
|
||||
private final HydrologyTier tidalTier;
|
||||
private final Map<String, IrisMaterialPalette> fluids;
|
||||
private final Map<String, String> seams;
|
||||
private final int prefetchRings;
|
||||
@@ -117,6 +120,7 @@ public final class HydrologySettings {
|
||||
this.lakes = lakes(config.getLakes());
|
||||
this.deformation = deformation(config.getDeformation());
|
||||
this.underground = underground(config.getUnderground());
|
||||
this.tidalTier = tidalTier(tiers.get(Math.min(TIDAL_BASE_TIER, tiers.size() - 1)), underground.seaInlets());
|
||||
this.fluids = fluids(config.getFluids());
|
||||
this.seams = seams(config.getFluids());
|
||||
this.prefetchRings = config.getPrefetchRings();
|
||||
@@ -138,6 +142,10 @@ public final class HydrologySettings {
|
||||
return tiers;
|
||||
}
|
||||
|
||||
public HydrologyTier tidalTier() {
|
||||
return tidalTier;
|
||||
}
|
||||
|
||||
public HydrologyTier majorTier() {
|
||||
return tiers.get(tiers.size() - 1);
|
||||
}
|
||||
@@ -216,6 +224,12 @@ public final class HydrologySettings {
|
||||
return persist;
|
||||
}
|
||||
|
||||
private static HydrologyTier tidalTier(HydrologyTier base, SeaInlets inlets) {
|
||||
return new HydrologyTier(TIDAL_TIER_NAME, base.minCatchment(), inlets.meanderWidth(), inlets.meanderWidth(), 0f, base.depthRatio(), 0, false,
|
||||
base.waterfallMinimumDrop(), base.stepHeight(), inlets.bankBand(), inlets.bankStyle(), new HydrologyTier.Estuary(0, 1f),
|
||||
new HydrologyTier.Delta(0, 0f, 0), base.materials(), base.fluid(), base.decorators());
|
||||
}
|
||||
|
||||
private static Climate climate(IrisHydrologyClimate config) {
|
||||
Objects.requireNonNull(config, "Hydrology climate is missing");
|
||||
IrisGeneratorStyle style = Objects.requireNonNull(config.getStyle(), "Hydrology climate.style is missing");
|
||||
|
||||
@@ -1,17 +1,15 @@
|
||||
package art.arcane.iris.generation.hydrology.plan;
|
||||
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInlet;
|
||||
import art.arcane.iris.generation.hydrology.water.Pond;
|
||||
import art.arcane.iris.generation.hydrology.water.Reach;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public record WindowPlan(WindowKey key, List<Reach> reaches, List<Pond> ponds, List<SeaInlet> inlets) {
|
||||
public record WindowPlan(WindowKey key, List<Reach> reaches, List<Pond> ponds) {
|
||||
public WindowPlan {
|
||||
Objects.requireNonNull(key, "key");
|
||||
reaches = List.copyOf(reaches);
|
||||
ponds = List.copyOf(ponds);
|
||||
inlets = List.copyOf(inlets);
|
||||
}
|
||||
}
|
||||
@@ -13,8 +13,6 @@ import art.arcane.iris.generation.hydrology.grid.HydrologySampleBuffer;
|
||||
import art.arcane.iris.generation.hydrology.grid.PriorityFlood;
|
||||
import art.arcane.iris.generation.hydrology.raster.PondChannelSettlement;
|
||||
import art.arcane.iris.generation.hydrology.raster.TongueGuard;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInlet;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInletPlanner;
|
||||
import art.arcane.iris.generation.hydrology.water.CupSet;
|
||||
import art.arcane.iris.generation.hydrology.water.Pond;
|
||||
import art.arcane.iris.generation.hydrology.water.PondKind;
|
||||
@@ -49,14 +47,12 @@ public final class WindowPlanner {
|
||||
private final HeightLattice fine;
|
||||
private final PondPlanner ponds;
|
||||
private final ReachShaper shaper;
|
||||
private final SeaInletPlanner inlets;
|
||||
|
||||
public WindowPlanner(HydrologySettings settings, HeightLattice fine, PondPlanner ponds, ReachShaper shaper) {
|
||||
this.settings = Objects.requireNonNull(settings, "settings");
|
||||
this.fine = Objects.requireNonNull(fine, "fine");
|
||||
this.ponds = Objects.requireNonNull(ponds, "ponds");
|
||||
this.shaper = Objects.requireNonNull(shaper, "shaper");
|
||||
this.inlets = new SeaInletPlanner(settings);
|
||||
if (fine.cell() != FINE_CELL) {
|
||||
throw new IllegalArgumentException("Window fine lattice cell " + fine.cell() + " must be " + FINE_CELL);
|
||||
}
|
||||
@@ -131,8 +127,7 @@ public final class WindowPlanner {
|
||||
}
|
||||
List<Reach> reaches = network.reaches();
|
||||
List<Pond> windowPonds = windowPonds(network.ponds());
|
||||
List<SeaInlet> planned = inlets.plan(key, raw, samples, drainage.receivers(), drainage.accumulation(), network, settings.seed());
|
||||
WindowPlan owned = new WindowPlan(key, ownedReaches(key, reaches), ownedPonds(key, windowPonds), ownedInlets(key, planned));
|
||||
WindowPlan owned = new WindowPlan(key, ownedReaches(key, reaches), ownedPonds(key, windowPonds));
|
||||
requireSeaConnectedHeads(owned, settings.seaLevel());
|
||||
return new WindowComputation(owned, reaches, windowPonds);
|
||||
}
|
||||
@@ -356,24 +351,11 @@ public final class WindowPlanner {
|
||||
return owned;
|
||||
}
|
||||
|
||||
private static List<SeaInlet> ownedInlets(WindowKey key, List<SeaInlet> planned) {
|
||||
List<SeaInlet> owned = new ArrayList<>();
|
||||
for (SeaInlet inlet : planned) {
|
||||
if (key.equals(WindowKey.containing((int) Math.floor(inlet.xs()[1]), (int) Math.floor(inlet.zs()[1])))) {
|
||||
owned.add(inlet);
|
||||
}
|
||||
}
|
||||
return owned;
|
||||
}
|
||||
|
||||
private static void requireSeaConnectedHeads(WindowPlan plan, int seaLevel) {
|
||||
for (SeaInlet inlet : plan.inlets()) {
|
||||
if (inlet.waterLevel() != seaLevel) {
|
||||
throw new IllegalStateException("Window " + plan.key() + " sea inlet " + inlet.id() + " holds water at " + inlet.waterLevel()
|
||||
+ ", not at sea level " + seaLevel);
|
||||
}
|
||||
}
|
||||
static void requireSeaConnectedHeads(WindowPlan plan, int seaLevel) {
|
||||
for (Reach reach : plan.reaches()) {
|
||||
if (requireTidal(plan.key(), reach, seaLevel)) {
|
||||
continue;
|
||||
}
|
||||
int mouth = reach.grade().length;
|
||||
while (mouth > 0 && reach.style()[mouth - 1] == ReachStyle.MOUTH) {
|
||||
mouth--;
|
||||
@@ -401,6 +383,30 @@ public final class WindowPlanner {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean requireTidal(WindowKey key, Reach reach, int seaLevel) {
|
||||
boolean any = false;
|
||||
boolean all = true;
|
||||
for (ReachStyle style : reach.style()) {
|
||||
any |= style == ReachStyle.TIDAL;
|
||||
all &= style == ReachStyle.TIDAL;
|
||||
}
|
||||
if (!any) {
|
||||
return false;
|
||||
}
|
||||
if (!all) {
|
||||
throw new IllegalStateException("Window " + key + " sea inlet " + reach.id() + " mixes tidal water with other water styles");
|
||||
}
|
||||
if (reach.downstreamId() != 0L) {
|
||||
throw offSea(key, reach, reach.grade().length - 1, ", but a sea inlet drains into reach " + reach.downstreamId() + " instead of the sea");
|
||||
}
|
||||
for (int point = 0; point < reach.grade().length; point++) {
|
||||
if (reach.grade()[point] != seaLevel) {
|
||||
throw offSea(key, reach, point, ", but a sea inlet stands at sea level " + seaLevel);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static IllegalStateException offSea(WindowKey key, Reach reach, int point, String rule) {
|
||||
return new IllegalStateException("Window " + key + " reach " + reach.id() + " " + reach.style()[point] + " point " + point + " at "
|
||||
+ reach.xs()[point] + "," + reach.zs()[point] + " is graded " + reach.grade()[point] + rule);
|
||||
|
||||
@@ -5,8 +5,6 @@ import art.arcane.iris.generation.hydrology.plan.IndexedWindow;
|
||||
import art.arcane.iris.generation.hydrology.plan.RegionKey;
|
||||
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;
|
||||
@@ -14,7 +12,6 @@ import art.arcane.iris.generation.hydrology.water.Reach;
|
||||
import art.arcane.iris.generation.hydrology.water.ReachStyle;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.IdentityHashMap;
|
||||
@@ -31,8 +28,6 @@ final class ChunkFeatures {
|
||||
private final List<Reach> reaches;
|
||||
private final List<Pond> ponds;
|
||||
private final List<Pond> lakes;
|
||||
private final List<SeaInlet> inlets;
|
||||
private final int[] inletBoxes;
|
||||
private final int[] lakeBoxes;
|
||||
private final ReachSegments segments = new ReachSegments(SEGMENT_CAPACITY);
|
||||
private final ReachGeometry.Lookup brinks;
|
||||
@@ -41,14 +36,11 @@ final class ChunkFeatures {
|
||||
private final MaskEdges lakeReach = new MaskEdges(MaskEdges.Kind.GROWN_WATER);
|
||||
private boolean inert;
|
||||
|
||||
private ChunkFeatures(HydrologySettings settings, List<Reach> reaches, Map<Reach, Reach> plans, List<Pond> ponds, List<Pond> lakes,
|
||||
List<SeaInlet> inlets, int[] inletBoxes) {
|
||||
private ChunkFeatures(HydrologySettings settings, List<Reach> reaches, Map<Reach, Reach> plans, List<Pond> ponds, List<Pond> lakes) {
|
||||
this.brinks = new ReachGeometry.Lookup(settings.seed(), settings.seaLevel(), plans);
|
||||
this.reaches = reaches;
|
||||
this.ponds = ponds;
|
||||
this.lakes = lakes;
|
||||
this.inlets = inlets;
|
||||
this.inletBoxes = inletBoxes;
|
||||
this.lakeBoxes = new int[4 * lakes.size()];
|
||||
}
|
||||
|
||||
@@ -58,19 +50,7 @@ final class ChunkFeatures {
|
||||
List<Reach> reaches = new ArrayList<>();
|
||||
Map<Reach, Reach> plans = new IdentityHashMap<>();
|
||||
List<Pond> ponds = new ArrayList<>();
|
||||
List<SeaInlet> inlets = new ArrayList<>();
|
||||
int[] inletBoxes = new int[0];
|
||||
for (IndexedWindow window : windows) {
|
||||
for (SeaInlet inlet : window.plan().inlets()) {
|
||||
int[] bounds = SeaInletRasterizer.bounds(inlet);
|
||||
int padding = RiffleProfile.RADIUS + 1;
|
||||
if (bounds[0] <= chunkX * CHUNK + CHUNK - 1 + padding && bounds[2] >= chunkX * CHUNK - padding
|
||||
&& bounds[1] <= chunkZ * CHUNK + CHUNK - 1 + padding && bounds[3] >= chunkZ * CHUNK - padding) {
|
||||
inletBoxes = Arrays.copyOf(inletBoxes, inletBoxes.length + 4);
|
||||
System.arraycopy(bounds, 0, inletBoxes, 4 * inlets.size(), 4);
|
||||
inlets.add(inlet);
|
||||
}
|
||||
}
|
||||
int before = reaches.size();
|
||||
window.index().candidates(chunkX, chunkZ, halo, reaches, ponds);
|
||||
for (int index = before; index < reaches.size(); index++) {
|
||||
@@ -81,7 +61,7 @@ final class ChunkFeatures {
|
||||
}
|
||||
}
|
||||
List<Pond> lakes = lakes(chunkX, chunkZ, halo, lakeRegionPlans, lakeRegions);
|
||||
ChunkFeatures features = new ChunkFeatures(settings, reaches, plans, ponds, lakes, inlets, inletBoxes);
|
||||
ChunkFeatures features = new ChunkFeatures(settings, reaches, plans, ponds, lakes);
|
||||
features.index(settings, chunkX, chunkZ);
|
||||
return features;
|
||||
}
|
||||
@@ -90,20 +70,6 @@ final class ChunkFeatures {
|
||||
return inert;
|
||||
}
|
||||
|
||||
SeaInlet openInletAt(int x, int z, int[] column) {
|
||||
for (int index = 0; index < inlets.size(); index++) {
|
||||
int box = 4 * index;
|
||||
if (x < inletBoxes[box] || z < inletBoxes[box + 1] || x > inletBoxes[box + 2] || z > inletBoxes[box + 3]) {
|
||||
continue;
|
||||
}
|
||||
SeaInlet inlet = inlets.get(index);
|
||||
if (SeaInletRasterizer.column(inlet, x, z, column) && column[1] == SeaInlet.OPEN) {
|
||||
return inlet;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
ReachGeometry.Lookup brinks() {
|
||||
return brinks;
|
||||
}
|
||||
@@ -123,11 +89,6 @@ final class ChunkFeatures {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for (SeaInlet inlet : inlets) {
|
||||
if (WaterHeads.standing(inlet.waterLevel(), seaLevel) != head) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return segments.hasOnlyLevel(head, seaLevel);
|
||||
}
|
||||
|
||||
@@ -220,20 +181,11 @@ final class ChunkFeatures {
|
||||
lakeReach.collect(mask, minX - shoreReach, minZ - shoreReach, maxX + shoreReach, maxZ + shoreReach);
|
||||
System.arraycopy(grownBox(mask), 0, lakeBoxes, 4 * index, 4);
|
||||
}
|
||||
inert = segments.isEmpty() && !inletsTouch(minX - 1, minZ - 1, maxX + 1, maxZ + 1)
|
||||
inert = segments.isEmpty()
|
||||
&& !pondsTouch(minX - 1 - reach, minZ - 1 - reach, maxX + 1 + reach, maxZ + 1 + reach)
|
||||
&& !lakesTouch(minX - 2 - shoreReach, minZ - 2 - shoreReach, maxX + 2 + shoreReach, maxZ + 2 + shoreReach);
|
||||
}
|
||||
|
||||
private boolean inletsTouch(int minX, int minZ, int maxX, int maxZ) {
|
||||
for (int box = 0; box < inletBoxes.length; box += 4) {
|
||||
if (inletBoxes[box] <= maxX && inletBoxes[box + 2] >= minX && inletBoxes[box + 1] <= maxZ && inletBoxes[box + 3] >= minZ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean pondsTouch(int minX, int minZ, int maxX, int maxZ) {
|
||||
for (Pond pond : ponds) {
|
||||
PondMask mask = pond.mask();
|
||||
|
||||
@@ -20,7 +20,7 @@ public final class ChunkRasterizer {
|
||||
public ChunkRasterizer(HydrologySettings settings, ChannelFluids channelFluids) {
|
||||
this.settings = Objects.requireNonNull(settings, "settings");
|
||||
this.channelFluids = Objects.requireNonNull(channelFluids, "channelFluids");
|
||||
float widest = 0f;
|
||||
float widest = settings.underground().seaInlets().mouthHalfWidth().max();
|
||||
for (HydrologyTier tier : settings.tiers()) {
|
||||
widest = Math.max(widest, tier.maxHalfWidth());
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package art.arcane.iris.generation.hydrology.raster;
|
||||
import art.arcane.iris.generation.hydrology.config.IrisBankStyle;
|
||||
import art.arcane.iris.generation.hydrology.cave.HydrologyCaveCell;
|
||||
import art.arcane.iris.generation.hydrology.plan.HydrologySettings;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInlet;
|
||||
import art.arcane.iris.generation.hydrology.water.HydrologyTier;
|
||||
import art.arcane.iris.generation.hydrology.water.Pond;
|
||||
import art.arcane.iris.generation.hydrology.water.Reach;
|
||||
@@ -44,7 +43,6 @@ final class RasterComposer {
|
||||
private final HydrologyTier[] nearTier = new HydrologyTier[CELLS];
|
||||
private final ReachGeometry.Lookup brinks;
|
||||
private final ReachCursor cursor;
|
||||
private final int[] inletColumn = new int[2];
|
||||
private final Map<Long, String> reachFluids = new HashMap<>();
|
||||
private NaturalHeights naturalHeight;
|
||||
|
||||
@@ -89,15 +87,6 @@ final class RasterComposer {
|
||||
int x = originX + cell % GRID;
|
||||
int z = originZ + cell / GRID;
|
||||
int ground = natural[cell];
|
||||
SeaInlet inlet = features.openInletAt(x, z, inletColumn);
|
||||
if (inlet != null) {
|
||||
head[cell] = WaterHeads.standing(inlet.waterLevel(), settings.seaLevel());
|
||||
terrain[cell] = Math.min(Math.min(ground, inletColumn[0]), head[cell] - 1);
|
||||
role[cell] = WaterRole.INLET;
|
||||
feature[cell] = inlet.id();
|
||||
fluid[cell] = HydrologyCaveCell.SEA_FLUID;
|
||||
return;
|
||||
}
|
||||
int lake = features.lakeAt(x, z, ground);
|
||||
int pondIndex = lake >= 0 ? -1 : features.pondAt(x, z);
|
||||
boolean shore = interior(cell) && lake < 0 && pondIndex < 0;
|
||||
@@ -149,7 +138,7 @@ final class RasterComposer {
|
||||
role[cell] = role(reach.style()[point]);
|
||||
feature[cell] = reach.id();
|
||||
tier[cell] = reach.tier();
|
||||
fluid[cell] = role[cell] == WaterRole.MOUTH ? HydrologyCaveCell.SEA_FLUID : reachFluid(reach);
|
||||
fluid[cell] = role[cell] == WaterRole.MOUTH || role[cell] == WaterRole.INLET ? HydrologyCaveCell.SEA_FLUID : reachFluid(reach);
|
||||
}
|
||||
|
||||
private String reachFluid(Reach reach) {
|
||||
@@ -334,11 +323,6 @@ final class RasterComposer {
|
||||
sample.set(head[cell], feature[cell], role[cell]);
|
||||
return;
|
||||
}
|
||||
SeaInlet inlet = features.openInletAt(x, z, inletColumn);
|
||||
if (inlet != null) {
|
||||
sample.set(WaterHeads.standing(inlet.waterLevel(), settings.seaLevel()), inlet.id(), WaterRole.INLET);
|
||||
return;
|
||||
}
|
||||
int lake = features.lakeCovers(x, z) ? features.lakeAt(x, z, naturalAt(x, z)) : -1;
|
||||
if (lake >= 0) {
|
||||
sample.set(WaterHeads.standing(features.lake(lake).level(), settings.seaLevel()), features.lake(lake).id(), WaterRole.POND);
|
||||
@@ -524,6 +508,7 @@ final class RasterComposer {
|
||||
case CASCADE -> WaterRole.CASCADE;
|
||||
case WATERFALL -> WaterRole.WATERFALL;
|
||||
case MOUTH -> WaterRole.MOUTH;
|
||||
case TIDAL -> WaterRole.INLET;
|
||||
case RUN, RIFFLE, POND_OUTLET -> WaterRole.CHANNEL;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -8,7 +8,8 @@ public enum ReachStyle {
|
||||
CASCADE(2),
|
||||
WATERFALL(3),
|
||||
POND_OUTLET(4),
|
||||
MOUTH(5);
|
||||
MOUTH(5),
|
||||
TIDAL(6);
|
||||
|
||||
private static final PersistedCodes<ReachStyle> CODES = PersistedCodes.of(ReachStyle.class, ReachStyle::code);
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@ final class HydrologyVegetationSource {
|
||||
for (HydrologyTier tier : settings.tiers()) {
|
||||
tiers.put(tier, HydrologyVegetation.Decorators.compile(tier.decorators(), data, "Hydrology tier '" + tier.name() + "' decorators"));
|
||||
}
|
||||
tiers.put(settings.tidalTier(), tiers.get(settings.tiers().get(Math.min(1, settings.tiers().size() - 1))));
|
||||
HydrologyVegetationSource source = new HydrologyVegetationSource(data, dimension, tiers,
|
||||
HydrologyVegetation.Decorators.compile(settings.ponds().decorators(), data, "Hydrology ponds.decorators"));
|
||||
source.planted = !source.ponds.empty();
|
||||
|
||||
@@ -4,11 +4,11 @@ import art.arcane.iris.generation.hydrology.engine.HydrologyPlanPreview;
|
||||
import art.arcane.iris.generation.hydrology.engine.HydrologyRuntime;
|
||||
import art.arcane.iris.generation.hydrology.query.HydrologyFeatureType;
|
||||
import art.arcane.iris.generation.hydrology.raster.ChunkWaterRaster;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInlet;
|
||||
import art.arcane.iris.generation.hydrology.water.HydrologyTier;
|
||||
import art.arcane.iris.generation.hydrology.water.Pond;
|
||||
import art.arcane.iris.generation.hydrology.water.PondMask;
|
||||
import art.arcane.iris.generation.hydrology.water.Reach;
|
||||
import art.arcane.iris.generation.hydrology.water.ReachStyle;
|
||||
import art.arcane.iris.world.history.ChunkGenerationSemantics;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -193,36 +193,20 @@ final class WaterMap {
|
||||
for (Pond lake : plans.lakes()) {
|
||||
drawMask(lake.mask(), HydrologyFeatureType.LAKE);
|
||||
}
|
||||
for (SeaInlet inlet : plans.inlets()) {
|
||||
checkCancelled();
|
||||
drawInlet(inlet);
|
||||
}
|
||||
}
|
||||
|
||||
private void drawInlet(SeaInlet inlet) {
|
||||
float[] xs = inlet.xs();
|
||||
float[] zs = inlet.zs();
|
||||
float[] halfWidth = inlet.halfWidth();
|
||||
for (int station = 0; station + 1 < xs.length; station++) {
|
||||
double radius = Math.max(halfWidth[station], halfWidth[station + 1]) + step / 2D;
|
||||
drawSegment(xs[station], zs[station], xs[station + 1], zs[station + 1], radius, HydrologyFeatureType.SEA_INLET);
|
||||
}
|
||||
drawSegment(inlet.chamberX(), inlet.chamberZ(), inlet.chamberX(), inlet.chamberZ(), inlet.chamberRadius() + step / 2D,
|
||||
HydrologyFeatureType.SEA_INLET);
|
||||
}
|
||||
|
||||
private void drawReach(Reach reach) {
|
||||
float[] xs = reach.xs();
|
||||
float[] zs = reach.zs();
|
||||
float[] halfWidth = reach.halfWidth();
|
||||
HydrologyFeatureType channel = channel(reach.tier());
|
||||
HydrologyFeatureType channel = reach.style()[0] == ReachStyle.TIDAL ? HydrologyFeatureType.SEA_INLET : channel(reach.tier());
|
||||
for (int point = 0; point < xs.length; point++) {
|
||||
int next = Math.min(point + 1, xs.length - 1);
|
||||
HydrologyFeatureType type = switch (reach.style()[point]) {
|
||||
case CASCADE -> HydrologyFeatureType.CASCADE;
|
||||
case WATERFALL -> HydrologyFeatureType.WATERFALL;
|
||||
case MOUTH -> HydrologyFeatureType.MOUTH;
|
||||
case RUN, RIFFLE, POND_OUTLET -> channel;
|
||||
case RUN, RIFFLE, POND_OUTLET, TIDAL -> channel;
|
||||
};
|
||||
double radius = Math.max(halfWidth[point], halfWidth[next]) + step / 2D;
|
||||
drawSegment(xs[point], zs[point], xs[next], zs[next], radius, type);
|
||||
|
||||
@@ -18,8 +18,6 @@ import art.arcane.iris.generation.hydrology.engine.HydrologyRuntime;
|
||||
import art.arcane.iris.generation.hydrology.query.HydrologyFeatureType;
|
||||
import art.arcane.iris.generation.hydrology.raster.ChunkWaterRaster;
|
||||
import art.arcane.iris.generation.hydrology.raster.WaterRole;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInlet;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInletRasterizer;
|
||||
import art.arcane.iris.generation.hydrology.water.HydrologyTier;
|
||||
import art.arcane.iris.generation.biome.IrisBiome;
|
||||
import art.arcane.iris.generation.terrain.IrisRegion;
|
||||
@@ -46,6 +44,7 @@ import java.util.Set;
|
||||
public final class GenerationSemanticCapture {
|
||||
private static final int CHUNK_SIZE = 16;
|
||||
private static final String INLET_PROFILE = HydrologyFeatureType.SEA_INLET.key();
|
||||
private static final Set<HydrologyFeatureType> INLET_TYPES = Set.of(HydrologyFeatureType.SEA_INLET);
|
||||
private static final long CAVE_POOL_SALT = 0x43415645504f4f4cL;
|
||||
|
||||
private GenerationSemanticCapture() {
|
||||
@@ -160,7 +159,6 @@ public final class GenerationSemanticCapture {
|
||||
int minimumX = Math.multiplyExact(chunkX, CHUNK_SIZE);
|
||||
int minimumZ = Math.multiplyExact(chunkZ, CHUNK_SIZE);
|
||||
int minimumY = engine.getDimension().getMinHeight();
|
||||
captureInlets(complex, runtime.inlets(chunkX, chunkZ), minimumX, minimumZ, minimumY, semantics);
|
||||
if (raster.empty()) {
|
||||
return;
|
||||
}
|
||||
@@ -175,14 +173,16 @@ public final class GenerationSemanticCapture {
|
||||
continue;
|
||||
}
|
||||
WaterRole role = complex.getWaterRoleStream().get(blockX, blockZ);
|
||||
if (!role.wet() || role == WaterRole.INLET) {
|
||||
if (!role.wet()) {
|
||||
continue;
|
||||
}
|
||||
long id = raster.featureId(localX, localZ);
|
||||
Set<HydrologyFeatureType> types = role == WaterRole.POND
|
||||
? standing.computeIfAbsent(id, feature -> runtime.standingWaterTypes(chunkX, chunkZ, feature))
|
||||
: flowingTypes(runtime, role, raster.tier(localX, localZ));
|
||||
String fluid = role == WaterRole.MOUTH
|
||||
Set<HydrologyFeatureType> types = switch (role) {
|
||||
case POND -> standing.computeIfAbsent(id, feature -> runtime.standingWaterTypes(chunkX, chunkZ, feature));
|
||||
case INLET -> INLET_TYPES;
|
||||
default -> flowingTypes(runtime, role, raster.tier(localX, localZ));
|
||||
};
|
||||
String fluid = role == WaterRole.INLET ? INLET_PROFILE : 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);
|
||||
@@ -195,29 +195,6 @@ public final class GenerationSemanticCapture {
|
||||
}
|
||||
}
|
||||
|
||||
private static void captureInlets(IrisComplex complex, List<SeaInlet> inlets, int minimumX, int minimumZ, int minimumY,
|
||||
ChunkGenerationSemantics.Builder semantics) {
|
||||
for (SeaInlet inlet : inlets) {
|
||||
captureInlet(complex, inlet, minimumX, minimumZ, minimumY, semantics);
|
||||
}
|
||||
}
|
||||
|
||||
private static void captureInlet(IrisComplex complex, SeaInlet inlet, int minimumX, int minimumZ, int minimumY,
|
||||
ChunkGenerationSemantics.Builder semantics) {
|
||||
int[] column = new int[2];
|
||||
for (int localX = 0; localX < CHUNK_SIZE; localX++) {
|
||||
for (int localZ = 0; localZ < CHUNK_SIZE; localZ++) {
|
||||
int blockX = minimumX + localX;
|
||||
int blockZ = minimumZ + localZ;
|
||||
if (SeaInletRasterizer.column(inlet, blockX, blockZ, column) && hasFullHydrologyWeight(complex, blockX, blockZ)) {
|
||||
semantics.addRiverFeature(INLET_PROFILE, HydrologyFeatureType.SEA_INLET, inlet.id(), blockX,
|
||||
Math.addExact(inlet.waterLevel(), minimumY), blockZ);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Set<HydrologyFeatureType> flowingTypes(HydrologyRuntime runtime, WaterRole role, HydrologyTier tier) {
|
||||
return switch (role) {
|
||||
case CHANNEL -> Set.of(runtime.channelType(tier));
|
||||
|
||||
@@ -37,7 +37,8 @@ public class PersistedCodesTest {
|
||||
ReachStyle.CASCADE, 2,
|
||||
ReachStyle.WATERFALL, 3,
|
||||
ReachStyle.POND_OUTLET, 4,
|
||||
ReachStyle.MOUTH, 5);
|
||||
ReachStyle.MOUTH, 5,
|
||||
ReachStyle.TIDAL, 6);
|
||||
private static final Map<PondKind, Integer> POND_KIND_CODES = Map.of(
|
||||
PondKind.NATURAL, 0,
|
||||
PondKind.SEEDED, 1,
|
||||
|
||||
+2
-2
@@ -222,12 +222,12 @@ public class HydrologyFeatureSearchTest {
|
||||
WindowPlan window(WindowKey key, List<RegionPlan> plans) {
|
||||
calls.incrementAndGet();
|
||||
if (channelTier != null && key.equals(new WindowKey(0, 0))) {
|
||||
return new WindowPlan(key, List.of(channel(channelTier)), List.of(), List.of());
|
||||
return new WindowPlan(key, List.of(channel(channelTier)), List.of());
|
||||
}
|
||||
if (Math.max(Math.abs(key.wx()), Math.abs(key.wz())) > openRing) {
|
||||
hold();
|
||||
}
|
||||
return new WindowPlan(key, List.of(), List.of(), List.of());
|
||||
return new WindowPlan(key, List.of(), List.of());
|
||||
}
|
||||
|
||||
private void hold() {
|
||||
|
||||
+24
-57
@@ -16,8 +16,6 @@ import art.arcane.iris.generation.hydrology.query.HydrologyFeatureRef;
|
||||
import art.arcane.iris.generation.hydrology.query.HydrologyFeatureType;
|
||||
import art.arcane.iris.generation.hydrology.raster.ChunkWaterRaster;
|
||||
import art.arcane.iris.generation.hydrology.raster.WaterRole;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInlet;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInletRasterizer;
|
||||
import art.arcane.iris.generation.hydrology.water.Pond;
|
||||
import art.arcane.iris.generation.hydrology.water.PondKind;
|
||||
import art.arcane.iris.generation.hydrology.water.PondMask;
|
||||
@@ -331,48 +329,15 @@ public class HydrologyRuntimeTest {
|
||||
}
|
||||
|
||||
@Test(timeout = 180_000L)
|
||||
public void seaInletsReachChunksPastTheirOwnerAndFailClosedOnTheMainThread() throws Exception {
|
||||
AtomicBoolean main = new AtomicBoolean(true);
|
||||
public void seaInletsAreSearchedAndPreviewedAsTidalReaches() throws Exception {
|
||||
FakePlanners planners = new FakePlanners(settings());
|
||||
HydrologyRuntime runtime = runtime(planners, main::get);
|
||||
|
||||
CountDownLatch gate = new CountDownLatch(1);
|
||||
planners.gate = gate;
|
||||
assertThrows(IllegalStateException.class, () -> runtime.inlets(68, 25));
|
||||
gate.countDown();
|
||||
main.set(false);
|
||||
List<SeaInlet> tail = runtime.inlets(68, 25);
|
||||
assertEquals(List.of(FakePlanners.inlet()), tail);
|
||||
assertEquals(new WindowKey(2, 0), WindowKey.containing(68 << 4, 25 << 4));
|
||||
assertEquals(tail, runtime.inlets(62, 25));
|
||||
assertEquals(List.of(), runtime.inlets(75, 25));
|
||||
assertEquals(List.of(), runtime.inlets(68, 30));
|
||||
assertEquals(List.of(), runtime.inlets(0, 0));
|
||||
main.set(true);
|
||||
assertEquals(tail, runtime.inlets(68, 25));
|
||||
main.set(false);
|
||||
|
||||
Map<Long, HydrologyCaveCell> written = new ConcurrentHashMap<>();
|
||||
MantleWriter writer = mock(MantleWriter.class);
|
||||
doAnswer(call -> {
|
||||
HydrologyCaveCell cell = call.getArgument(3);
|
||||
int x = call.getArgument(0);
|
||||
assertEquals(68, x >> 4);
|
||||
written.put(((long) x << 40) ^ ((long) (int) call.getArgument(2) << 20) ^ (int) call.getArgument(1), cell);
|
||||
return null;
|
||||
}).when(writer).setData(anyInt(), anyInt(), anyInt(), any(HydrologyCaveCell.class));
|
||||
new SeaInletRasterizer().write(tail.getFirst(), 68, 25, writer, HydrologyCaveCell.SEA_FLUID, SeaInletRasterizer.SubterrainFluid.NOWHERE,
|
||||
SeaInletRasterizer.HistoricalChunks.NONE);
|
||||
assertTrue("the chunk past the owner window writes inlet water",
|
||||
written.values().stream().anyMatch(cell -> cell.action() == HydrologyCaveAction.WET_SOURCE));
|
||||
|
||||
HydrologyRuntime runtime = runtime(planners, () -> false);
|
||||
HydrologyFeatureRef nearest = runtime.nearestFeature(1050, 405, HydrologyFeatureQuery.of(HydrologyFeatureType.SEA_INLET), 512, ANY,
|
||||
RUNNING).orElseThrow();
|
||||
assertEquals(new HydrologyFeatureRef(INLET, HydrologyFeatureType.SEA_INLET, 1048, 40, 400), nearest);
|
||||
assertEquals(Optional.empty(),
|
||||
runtime.nearestFeature(0, 0, HydrologyFeatureQuery.of(HydrologyFeatureType.SEA_INLET), 64, ANY, RUNNING));
|
||||
assertEquals(List.of(FakePlanners.inlet()), runtime.planPreview(900, 300, 1100, 500).inlets());
|
||||
assertEquals(List.of(), FakeHydrology.disabled().inlets(0, 0));
|
||||
assertEquals(List.of(INLET), runtime.planPreview(900, 300, 1100, 500).reaches().stream().map(Reach::id).filter(id -> id == INLET).toList());
|
||||
}
|
||||
|
||||
@Test(timeout = 180_000L)
|
||||
@@ -548,7 +513,7 @@ public class HydrologyRuntimeTest {
|
||||
}
|
||||
assertTrue("a released cap admits new previews", preview.complete());
|
||||
assertEquals(2, preview.ponds().size());
|
||||
assertEquals(1, preview.reaches().size());
|
||||
assertEquals(2, preview.reaches().size());
|
||||
}
|
||||
|
||||
@Test(timeout = 180_000L)
|
||||
@@ -1306,15 +1271,15 @@ public class HydrologyRuntimeTest {
|
||||
throw new IllegalStateException("window planner exploded");
|
||||
}
|
||||
return new WindowPlan(key, List.of(river()), List.of(pond(POND, PondKind.NATURAL, 70, 2, 2, 8),
|
||||
pond(POND + 1, PondKind.SEEDED, 70, 296, 296, 3)), List.of());
|
||||
pond(POND + 1, PondKind.SEEDED, 70, 296, 296, 3)));
|
||||
}
|
||||
if (key.equals(new WindowKey(1, 0))) {
|
||||
return new WindowPlan(key, List.of(), List.of(), List.of(inlet()));
|
||||
return new WindowPlan(key, List.of(tidal()), List.of());
|
||||
}
|
||||
if (key.equals(new WindowKey(3, 0))) {
|
||||
return new WindowPlan(key, List.of(), List.of(pond(FAR_POND, PondKind.NATURAL, 75, 1700, 100, 3)), List.of());
|
||||
return new WindowPlan(key, List.of(), List.of(pond(FAR_POND, PondKind.NATURAL, 75, 1700, 100, 3)));
|
||||
}
|
||||
return new WindowPlan(key, List.of(), List.of(), List.of());
|
||||
return new WindowPlan(key, List.of(), List.of());
|
||||
}
|
||||
|
||||
private void pass() {
|
||||
@@ -1335,21 +1300,23 @@ public class HydrologyRuntimeTest {
|
||||
}
|
||||
}
|
||||
|
||||
private static SeaInlet inlet() {
|
||||
int stations = 13;
|
||||
float[] xs = new float[stations];
|
||||
float[] zs = new float[stations];
|
||||
float[] halfWidth = new float[stations];
|
||||
int[] floor = new int[stations];
|
||||
int[] ceiling = new int[stations];
|
||||
for (int station = 0; station < stations; station++) {
|
||||
xs[station] = 992f + station * 8f;
|
||||
zs[station] = 400f;
|
||||
halfWidth[station] = 3f;
|
||||
floor[station] = 37;
|
||||
ceiling[station] = 45;
|
||||
private Reach tidal() {
|
||||
int points = 13;
|
||||
float[] xs = new float[points];
|
||||
float[] zs = new float[points];
|
||||
int[] grade = new int[points];
|
||||
float[] halfWidth = new float[points];
|
||||
float[] depth = new float[points];
|
||||
ReachStyle[] style = new ReachStyle[points];
|
||||
for (int point = 0; point < points; point++) {
|
||||
xs[point] = 992f + point * 8f;
|
||||
zs[point] = 400f;
|
||||
grade[point] = 40;
|
||||
halfWidth[point] = 3f;
|
||||
depth[point] = 3f;
|
||||
style[point] = ReachStyle.TIDAL;
|
||||
}
|
||||
return new SeaInlet(INLET, xs, zs, halfWidth, 40, floor, ceiling, 1088, 400, 6);
|
||||
return new Reach(INLET, settings.tidalTier(), 0L, xs, zs, grade, halfWidth, depth, style, 0f);
|
||||
}
|
||||
|
||||
private Reach river() {
|
||||
|
||||
+2
-2
@@ -317,7 +317,7 @@ public class HydrologyPlanCacheTest {
|
||||
WindowKey key = new WindowKey(5, -3);
|
||||
HydrologyPlanCache cache = new HydrologyPlanCache(planners.settings, planners::region, (window, regions) -> {
|
||||
Reach reach = planners.window(window, regions).reaches().get(0);
|
||||
return new WindowPlan(window, List.of(reach, reach), List.of(), List.of());
|
||||
return new WindowPlan(window, List.of(reach, reach), List.of());
|
||||
}, pool(1), () -> false);
|
||||
caches.add(cache);
|
||||
Throwable failure = failureOf(() -> cache.window(key));
|
||||
@@ -1174,7 +1174,7 @@ public class HydrologyPlanCacheTest {
|
||||
throw new AssertionError("Window " + key + " got region plans " + given + ", needs " + needed);
|
||||
}
|
||||
hook.accept(key);
|
||||
return new WindowPlan(key, List.of(reach(key)), List.of(), List.of());
|
||||
return new WindowPlan(key, List.of(reach(key)), List.of());
|
||||
}
|
||||
|
||||
private Reach reach(WindowKey key) {
|
||||
|
||||
+19
-23
@@ -4,7 +4,6 @@ import art.arcane.iris.generation.hydrology.config.IrisBankStyle;
|
||||
import art.arcane.iris.generation.hydrology.config.IrisHydrology;
|
||||
import art.arcane.iris.generation.hydrology.config.IrisHydrologyMaterials;
|
||||
import art.arcane.iris.generation.hydrology.grid.HeightLattice;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInlet;
|
||||
import art.arcane.iris.generation.hydrology.water.HydrologyTier;
|
||||
import art.arcane.iris.generation.hydrology.water.Pond;
|
||||
import art.arcane.iris.generation.hydrology.water.PondKind;
|
||||
@@ -47,7 +46,7 @@ public class HydrologyPlanCodecTest {
|
||||
0577617465720000001c000000060000000000000007020000004400000040ffffffec0000001042898000fffffffc00
|
||||
00000800000004000000000000000000000000000000000000002900000002000000046c617661ffffffea0000000e00
|
||||
0000000000000803000000500000003c00000040ffffffc042a10000fffffffc00000008000000040000000000000000
|
||||
00000000ffffffffffffffff00000000ffffffff0000003cffffffc400000000
|
||||
00000000ffffffffffffffff00000000ffffffff0000003cffffffc4
|
||||
""";
|
||||
|
||||
@Test
|
||||
@@ -60,7 +59,7 @@ public class HydrologyPlanCodecTest {
|
||||
new int[]{Integer.MIN_VALUE, -64, 0, 63, 319, Integer.MAX_VALUE},
|
||||
new float[]{0.5f, 1f, 2.75f, NAN_PAYLOAD, 12f, 0f},
|
||||
new float[]{1f, Float.POSITIVE_INFINITY, 0.4f, 1e-42f, -0f, 3f},
|
||||
ReachStyle.values(), NEGATIVE_NAN);
|
||||
Arrays.copyOf(ReachStyle.values(), 6), NEGATIVE_NAN);
|
||||
Reach plain = new Reach(77L, tiers.get(0), -9_000_000_000L, new float[]{10f, 11.5f}, new float[]{-3f, -2.5f}, new int[]{70, 69},
|
||||
new float[]{0.5f, 0.75f}, new float[]{1f, 1f}, new ReachStyle[]{ReachStyle.RUN, ReachStyle.MOUTH}, 1501.25f).withStraightFalls(new int[]{0});
|
||||
List<Pond> ponds = new ArrayList<>();
|
||||
@@ -70,12 +69,7 @@ public class HydrologyPlanCodecTest {
|
||||
index == 0 ? NAN_PAYLOAD : 61.5f + index, mask(index), index == 1 ? -1L : 77L, index * 2, fluid(index),
|
||||
-650 + index, 880 + index));
|
||||
}
|
||||
SeaInlet oddInlet = new SeaInlet(-5_000_000_000L, new float[]{-0f, NAN_PAYLOAD, 1e-40f}, new float[]{NEGATIVE_NAN, 3.5f, -0f},
|
||||
new float[]{Float.MIN_VALUE, 5f, 2.25f}, 63, new int[]{Integer.MIN_VALUE, 60, 62}, new int[]{63, Integer.MAX_VALUE, 70},
|
||||
-12, 40, 9);
|
||||
SeaInlet plainInlet = new SeaInlet(91L, new float[]{8f, 16f}, new float[]{-24f, -16f}, new float[]{5f, 4f}, 306,
|
||||
new int[]{303, 302}, new int[]{340, 312}, 16, -16, 6);
|
||||
WindowPlan window = new WindowPlan(new WindowKey(-3, 7), List.of(odd, plain), ponds, List.of(oddInlet, plainInlet));
|
||||
WindowPlan window = new WindowPlan(new WindowKey(-3, 7), List.of(odd, plain), ponds);
|
||||
WindowPlan decodedWindow = HydrologyPlanCodec.decodeWindow(settings, HydrologyPlanCodec.encode(settings, window)).orElseThrow();
|
||||
assertBitExact(window, decodedWindow, tiers);
|
||||
|
||||
@@ -85,7 +79,7 @@ public class HydrologyPlanCodecTest {
|
||||
assertReachesBitExact(region.majorReaches(), decodedRegion.majorReaches(), tiers);
|
||||
assertPondsBitExact(region.lakes(), decodedRegion.lakes());
|
||||
|
||||
WindowPlan empty = new WindowPlan(new WindowKey(Integer.MIN_VALUE, Integer.MAX_VALUE), List.of(), List.of(), List.of());
|
||||
WindowPlan empty = new WindowPlan(new WindowKey(Integer.MIN_VALUE, Integer.MAX_VALUE), List.of(), List.of());
|
||||
assertEquals(empty, HydrologyPlanCodec.decodeWindow(settings, HydrologyPlanCodec.encode(settings, empty)).orElseThrow());
|
||||
|
||||
SyntheticTerrain terrain = SyntheticTerrain.openFractal(SEED);
|
||||
@@ -105,6 +99,18 @@ public class HydrologyPlanCodecTest {
|
||||
assertBitExact(planned, HydrologyPlanCodec.decodeWindow(settings, HydrologyPlanCodec.encode(settings, planned)).orElseThrow(), tiers);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tidalReachesRoundTripOnTheTidalTier() {
|
||||
HydrologySettings settings = settings(new IrisHydrology());
|
||||
int sea = settings.seaLevel();
|
||||
Reach tidal = new Reach(404L, settings.tidalTier(), 0L, new float[]{0f, 8f, 16f}, new float[]{0f, 4f, 2f}, new int[]{sea, sea, sea},
|
||||
new float[]{2f, 6f, 12f}, new float[]{1f, 4f, 1f}, new ReachStyle[]{ReachStyle.TIDAL, ReachStyle.TIDAL, ReachStyle.TIDAL}, 0f);
|
||||
WindowPlan window = new WindowPlan(new WindowKey(0, 0), List.of(tidal), List.of());
|
||||
WindowPlan decoded = HydrologyPlanCodec.decodeWindow(settings, HydrologyPlanCodec.encode(settings, window)).orElseThrow();
|
||||
assertEquals(window, decoded);
|
||||
assertSame(settings.tidalTier(), decoded.reaches().get(0).tier());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void codecDecodesMismatchedOrCorruptDataAsEmpty() {
|
||||
HydrologySettings settings = settings(new IrisHydrology());
|
||||
@@ -112,9 +118,7 @@ public class HydrologyPlanCodecTest {
|
||||
Reach reach = new Reach(5L, tier, -1L, new float[]{1f, 2f, 3f}, new float[]{4f, 5f, 6f}, new int[]{70, 69, 68},
|
||||
new float[]{1f, 1f, 1.5f}, new float[]{1f, 1f, 1f}, new ReachStyle[]{ReachStyle.RUN, ReachStyle.RIFFLE, ReachStyle.MOUTH}, 2000f);
|
||||
Pond pond = new Pond(9L, PondKind.SEEDED, 66, 62, 10, 12, 66.5f, mask(3), 5L, 0, "water", 11, 13);
|
||||
SeaInlet inlet = new SeaInlet(12L, new float[]{8f, 16f, 24f}, new float[]{0f, 0f, 8f}, new float[]{5f, 4f, 3f}, 63,
|
||||
new int[]{60, 61, 59}, new int[]{90, 68, 70}, 24, 8, 7);
|
||||
WindowPlan window = new WindowPlan(new WindowKey(1, 2), List.of(reach), List.of(pond), List.of(inlet));
|
||||
WindowPlan window = new WindowPlan(new WindowKey(1, 2), List.of(reach), List.of(pond));
|
||||
byte[] encoded = HydrologyPlanCodec.encode(settings, window);
|
||||
|
||||
HydrologySettings reseeded = HydrologySettings.compile(new IrisHydrology(), SEED + 1L, SyntheticTerrain.SEA_LEVEL,
|
||||
@@ -147,7 +151,7 @@ public class HydrologyPlanCodecTest {
|
||||
Reach stray = new Reach(6L, foreign, -1L, new float[]{1f, 2f}, new float[]{1f, 2f}, new int[]{1, 1}, new float[]{1f, 1f},
|
||||
new float[]{1f, 1f}, new ReachStyle[]{ReachStyle.RUN, ReachStyle.RUN}, 1f);
|
||||
try {
|
||||
HydrologyPlanCodec.encode(settings, new WindowPlan(new WindowKey(0, 0), List.of(stray), List.of(), List.of()));
|
||||
HydrologyPlanCodec.encode(settings, new WindowPlan(new WindowKey(0, 0), List.of(stray), List.of()));
|
||||
fail("a tier outside the settings has no index");
|
||||
} catch (IllegalArgumentException expected) {
|
||||
assertTrue(expected.getMessage(), expected.getMessage().contains("foreign"));
|
||||
@@ -174,21 +178,13 @@ public class HydrologyPlanCodecTest {
|
||||
new Pond(6L, PondKind.SEEDED, 74, 71, 30, 8, 74.25f, mask(2), -1L, 1, "water", 28, 6),
|
||||
new Pond(7L, PondKind.CHAINED, 68, 64, -20, 16, 68.75f, mask(0), 41L, 2, "lava", -22, 14),
|
||||
new Pond(8L, PondKind.LAKE, 80, 60, 64, -64, 80.5f, mask(0), -1L, 0, null, 60, -60));
|
||||
return new WindowPlan(new WindowKey(2, -3), List.of(reach), ponds, List.of());
|
||||
return new WindowPlan(new WindowKey(2, -3), List.of(reach), ponds);
|
||||
}
|
||||
|
||||
private static void assertBitExact(WindowPlan expected, WindowPlan actual, List<HydrologyTier> tiers) {
|
||||
assertEquals(expected, actual);
|
||||
assertReachesBitExact(expected.reaches(), actual.reaches(), tiers);
|
||||
assertPondsBitExact(expected.ponds(), actual.ponds());
|
||||
assertEquals(expected.inlets().size(), actual.inlets().size());
|
||||
for (int index = 0; index < expected.inlets().size(); index++) {
|
||||
SeaInlet want = expected.inlets().get(index);
|
||||
SeaInlet got = actual.inlets().get(index);
|
||||
assertArrayEquals(rawBits(want.xs()), rawBits(got.xs()));
|
||||
assertArrayEquals(rawBits(want.zs()), rawBits(got.zs()));
|
||||
assertArrayEquals(rawBits(want.halfWidth()), rawBits(got.halfWidth()));
|
||||
}
|
||||
}
|
||||
|
||||
private static void assertReachesBitExact(List<Reach> expected, List<Reach> actual, List<HydrologyTier> tiers) {
|
||||
|
||||
+1
-1
@@ -225,7 +225,7 @@ public class HydrologyPlanStoreTest {
|
||||
new ReachStyle[]{ReachStyle.RUN, ReachStyle.CASCADE, ReachStyle.RUN}, 1600f);
|
||||
Pond pond = new Pond(key.wz() * 17L - key.wx(), PondKind.NATURAL, 72, 68, (int) x, (int) z, 72.25f,
|
||||
new PondMask((int) x, (int) z, 4, 3, 2, new long[]{0b101101L}), reach.id(), 0, "water", (int) x + 4, (int) z);
|
||||
return new WindowPlan(key, List.of(reach), List.of(pond), List.of());
|
||||
return new WindowPlan(key, List.of(reach), List.of(pond));
|
||||
}
|
||||
|
||||
private static HydrologySettings settings(long seed) {
|
||||
|
||||
@@ -8,7 +8,6 @@ import art.arcane.iris.generation.hydrology.raster.ChunkRasterizer;
|
||||
import art.arcane.iris.generation.hydrology.raster.ChunkWaterRaster;
|
||||
import art.arcane.iris.generation.hydrology.raster.ReachIndex;
|
||||
import art.arcane.iris.generation.hydrology.raster.WaterRole;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInlet;
|
||||
import art.arcane.iris.generation.hydrology.water.Pond;
|
||||
import art.arcane.iris.generation.hydrology.water.PondPlanner;
|
||||
import art.arcane.iris.generation.hydrology.water.Reach;
|
||||
@@ -33,7 +32,6 @@ final class PlannedScene {
|
||||
private final Function<RegionKey, RegionPlan> regions;
|
||||
private final List<Reach> reaches;
|
||||
private final List<Pond> ponds;
|
||||
private final List<SeaInlet> inlets;
|
||||
private final ChunkRasterizer rasterizer;
|
||||
private final Map<WindowKey, IndexedWindow> windows = new HashMap<>();
|
||||
private final Map<Long, ChunkWaterRaster> rasters = new HashMap<>();
|
||||
@@ -49,15 +47,12 @@ final class PlannedScene {
|
||||
this.rasterizer = new ChunkRasterizer(settings, ChannelFluids.TIER);
|
||||
List<Reach> ownedReaches = new ArrayList<>();
|
||||
List<Pond> ownedPonds = new ArrayList<>();
|
||||
List<SeaInlet> ownedInlets = new ArrayList<>();
|
||||
for (WindowPlan plan : plans.values()) {
|
||||
ownedReaches.addAll(plan.reaches());
|
||||
ownedPonds.addAll(plan.ponds());
|
||||
ownedInlets.addAll(plan.inlets());
|
||||
}
|
||||
this.reaches = List.copyOf(ownedReaches);
|
||||
this.ponds = List.copyOf(ownedPonds);
|
||||
this.inlets = List.copyOf(ownedInlets);
|
||||
}
|
||||
|
||||
static PlannedScene plan(SyntheticTerrain terrain, HydrologySettings settings, int windowsX, int windowsZ) {
|
||||
@@ -87,7 +82,7 @@ final class PlannedScene {
|
||||
requireOrigin(origin, WindowKey.containing(pond.floorX(), pond.floorZ()), pond);
|
||||
}
|
||||
Map<WindowKey, WindowPlan> plans = new LinkedHashMap<>();
|
||||
plans.put(origin, new WindowPlan(origin, reaches, ponds, List.of()));
|
||||
plans.put(origin, new WindowPlan(origin, reaches, ponds));
|
||||
return new PlannedScene(terrain, settings, 1, 1, plans, key -> new RegionPlan(key, List.of(), List.of()));
|
||||
}
|
||||
|
||||
@@ -123,10 +118,6 @@ final class PlannedScene {
|
||||
return ponds;
|
||||
}
|
||||
|
||||
List<SeaInlet> inlets() {
|
||||
return inlets;
|
||||
}
|
||||
|
||||
int minX() {
|
||||
return 0;
|
||||
}
|
||||
@@ -184,7 +175,7 @@ final class PlannedScene {
|
||||
|
||||
private IndexedWindow window(WindowKey key) {
|
||||
return windows.computeIfAbsent(key, ignored -> {
|
||||
WindowPlan plan = plans.getOrDefault(key, new WindowPlan(key, List.of(), List.of(), List.of()));
|
||||
WindowPlan plan = plans.getOrDefault(key, new WindowPlan(key, List.of(), List.of()));
|
||||
return new IndexedWindow(plan, ReachIndex.build(key, plan.reaches(), plan.ponds()));
|
||||
});
|
||||
}
|
||||
|
||||
+15
-44
@@ -8,7 +8,6 @@ import art.arcane.iris.generation.hydrology.grid.HeightLattice;
|
||||
import art.arcane.iris.generation.hydrology.raster.TongueGuard;
|
||||
import art.arcane.iris.generation.hydrology.raster.WaterHeads;
|
||||
import art.arcane.iris.generation.hydrology.raster.WaterRole;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInlet;
|
||||
import art.arcane.iris.generation.hydrology.water.HydrologyTier;
|
||||
import art.arcane.iris.generation.hydrology.water.CupSet;
|
||||
import art.arcane.iris.generation.hydrology.water.Pond;
|
||||
@@ -804,45 +803,22 @@ public class WindowPlannerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void seaInletsBelongToTheWindowOfTheirFirstLandStationInAnyPlanningOrder() {
|
||||
public void seaConnectedHeadsAcceptWholeTidalReachesAtSeaLevelOnly() {
|
||||
HydrologySettings settings = settings(new IrisHydrology());
|
||||
SyntheticTerrain terrain = SyntheticTerrain.cliffCoast(1400D);
|
||||
List<WindowKey> keys = List.of(new WindowKey(2, 0), new WindowKey(3, 0), new WindowKey(2, 1), new WindowKey(3, 1));
|
||||
Map<WindowKey, WindowPlan> forward = new HashMap<>();
|
||||
WindowPlanner first = planner(settings, terrain);
|
||||
for (WindowKey key : keys) {
|
||||
forward.put(key, first.plan(key, noRegions(key)));
|
||||
}
|
||||
Map<WindowKey, WindowPlan> backward = new HashMap<>();
|
||||
WindowPlanner second = planner(settings, terrain);
|
||||
for (int index = keys.size() - 1; index >= 0; index--) {
|
||||
backward.put(keys.get(index), second.plan(keys.get(index), noRegions(keys.get(index))));
|
||||
}
|
||||
assertEquals(forward, backward);
|
||||
int spacing = settings.underground().seaInlets().spacing();
|
||||
Set<Long> sites = new HashSet<>();
|
||||
int inlets = 0;
|
||||
int crossing = 0;
|
||||
for (Map.Entry<WindowKey, WindowPlan> entry : forward.entrySet()) {
|
||||
for (SeaInlet inlet : entry.getValue().inlets()) {
|
||||
inlets++;
|
||||
int landX = (int) Math.floor(inlet.xs()[1]);
|
||||
int landZ = (int) Math.floor(inlet.zs()[1]);
|
||||
assertEquals(inlet + " belongs to the window of its first land station", WindowKey.containing(landX, landZ), entry.getKey());
|
||||
assertTrue(inlet + " is the only inlet of its site", sites.add(((long) Math.floorDiv(landX, spacing) << 32)
|
||||
| (Math.floorDiv(landZ, spacing) & 0xFFFFFFFFL)));
|
||||
boolean leaves = false;
|
||||
for (int station = 0; station < inlet.stations(); station++) {
|
||||
leaves |= !WindowKey.containing((int) Math.floor(inlet.xs()[station]), (int) Math.floor(inlet.zs()[station])).equals(entry.getKey());
|
||||
}
|
||||
crossing += leaves ? 1 : 0;
|
||||
}
|
||||
}
|
||||
assertTrue("sea inlets on the cliff coast " + inlets, inlets >= 2);
|
||||
assertTrue("inlets running into the next window " + crossing, crossing > 0);
|
||||
for (WindowKey key : List.of(new WindowKey(3, 0), new WindowKey(3, 1))) {
|
||||
assertTrue("the inland window owns none of the coast's inlets", forward.get(key).inlets().isEmpty());
|
||||
}
|
||||
WindowKey key = new WindowKey(0, 0);
|
||||
int sea = settings.seaLevel();
|
||||
WindowPlanner.requireSeaConnectedHeads(new WindowPlan(key, List.of(tidal(settings, sea, 0L, ReachStyle.TIDAL)), List.of()), sea);
|
||||
assertThrows(IllegalStateException.class,
|
||||
() -> WindowPlanner.requireSeaConnectedHeads(new WindowPlan(key, List.of(tidal(settings, sea + 2, 0L, ReachStyle.TIDAL)), List.of()), sea));
|
||||
assertThrows(IllegalStateException.class,
|
||||
() -> WindowPlanner.requireSeaConnectedHeads(new WindowPlan(key, List.of(tidal(settings, sea, 9L, ReachStyle.TIDAL)), List.of()), sea));
|
||||
assertThrows(IllegalStateException.class,
|
||||
() -> WindowPlanner.requireSeaConnectedHeads(new WindowPlan(key, List.of(tidal(settings, sea, 0L, ReachStyle.RUN)), List.of()), sea));
|
||||
}
|
||||
|
||||
private static Reach tidal(HydrologySettings settings, int grade, long downstream, ReachStyle last) {
|
||||
return new Reach(5L, settings.tidalTier(), downstream, new float[]{0f, 8f}, new float[]{0f, 0f}, new int[]{grade, grade},
|
||||
new float[]{2f, 4f}, new float[]{1f, 1f}, new ReachStyle[]{ReachStyle.TIDAL, last}, 0f);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -855,8 +831,6 @@ public class WindowPlannerTest {
|
||||
assertTrue("mouth vertices on the coastal fractal " + fractalColumns.vertices(), fractalColumns.vertices() >= 100);
|
||||
assertTrue("mouth columns on the coastal fractal " + fractalColumns.mouths(), fractalColumns.mouths() >= 1000);
|
||||
assertTrue("mouth columns on the cliff coast " + cliffColumns.mouths(), cliffColumns.mouths() >= 1000);
|
||||
assertTrue("sea inlets on the cliff coast " + cliff.inlets().size(), cliff.inlets().size() >= 2);
|
||||
assertTrue("inlet columns on the cliff coast " + cliffColumns.inlets(), cliffColumns.inlets() >= 500);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1323,9 +1297,6 @@ public class WindowPlannerTest {
|
||||
}
|
||||
|
||||
private static SeaColumns assertSeaConnectedHeads(String name, PlannedScene scene) {
|
||||
for (SeaInlet inlet : scene.inlets()) {
|
||||
assertEquals(name + " " + inlet, SEA_LEVEL, inlet.waterLevel());
|
||||
}
|
||||
int vertices = 0;
|
||||
for (Reach reach : scene.reaches()) {
|
||||
for (int point = 0; point < reach.grade().length; point++) {
|
||||
|
||||
+38
-40
@@ -11,8 +11,6 @@ import art.arcane.iris.generation.hydrology.plan.RegionKey;
|
||||
import art.arcane.iris.generation.hydrology.plan.RegionPlan;
|
||||
import art.arcane.iris.generation.hydrology.plan.WindowKey;
|
||||
import art.arcane.iris.generation.hydrology.plan.WindowPlan;
|
||||
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.HydrologyTier;
|
||||
import art.arcane.iris.generation.hydrology.water.Pond;
|
||||
@@ -417,48 +415,48 @@ public class ChunkWaterRasterTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void openSeaInletSlotColumnsTakeTheInletRoleAtSeaLevel() {
|
||||
public void tidalReachColumnsTakeTheInletRoleAtSeaLevelBetweenBanks() {
|
||||
HydrologySettings settings = settings(new IrisHydrology());
|
||||
int stations = 10;
|
||||
float[] xs = new float[stations];
|
||||
float[] zs = new float[stations];
|
||||
float[] halfWidth = new float[stations];
|
||||
int[] floor = new int[stations];
|
||||
int[] ceiling = new int[stations];
|
||||
for (int station = 0; station < stations; station++) {
|
||||
xs[station] = -8f + station * 8f;
|
||||
zs[station] = 8f;
|
||||
halfWidth[station] = 4f;
|
||||
floor[station] = SEA_LEVEL - 3;
|
||||
ceiling[station] = station < 2 ? SeaInlet.OPEN : SEA_LEVEL + 5;
|
||||
int points = 9;
|
||||
float[] xs = new float[points];
|
||||
float[] zs = new float[points];
|
||||
int[] grade = new int[points];
|
||||
float[] halfWidth = new float[points];
|
||||
float[] depth = new float[points];
|
||||
ReachStyle[] style = new ReachStyle[points];
|
||||
for (int point = 0; point < points; point++) {
|
||||
xs[point] = -16f + point * 8f;
|
||||
zs[point] = 8f;
|
||||
grade[point] = SEA_LEVEL;
|
||||
halfWidth[point] = 3f;
|
||||
depth[point] = 3f;
|
||||
style[point] = ReachStyle.TIDAL;
|
||||
}
|
||||
SeaInlet inlet = new SeaInlet(71L, xs, zs, halfWidth, SEA_LEVEL, floor, ceiling, 64, 8, 6);
|
||||
Reach reach = new Reach(71L, settings.tidalTier(), 0L, xs, zs, grade, halfWidth, depth, style, 0f);
|
||||
WindowKey key = new WindowKey(0, 0);
|
||||
IndexedWindow own = new IndexedWindow(new WindowPlan(key, List.of(), List.of(), List.of(inlet)), ReachIndex.build(key, List.of(), List.of()));
|
||||
IndexedWindow own = new IndexedWindow(new WindowPlan(key, List.of(reach), List.of()), ReachIndex.build(key, List.of(reach), List.of()));
|
||||
ChunkRasterizer rasterizer = new ChunkRasterizer(settings, ChannelFluids.TIER);
|
||||
ChunkWaterRaster mouth = rasterizer.rasterize(0, 0, (x, z) -> 70, List.of(own), regions(0, 0, List.of()));
|
||||
int[] column = new int[2];
|
||||
int open = 0;
|
||||
ChunkWaterRaster raster = rasterizer.rasterize(0, 0, (x, z) -> SEA_LEVEL + 12, List.of(own), regions(0, 0, List.of()));
|
||||
int wet = 0;
|
||||
int bank = 0;
|
||||
for (int lz = 0; lz < 16; lz++) {
|
||||
for (int lx = 0; lx < 16; lx++) {
|
||||
boolean slot = SeaInletRasterizer.column(inlet, lx, lz, column) && column[1] == SeaInlet.OPEN;
|
||||
if (slot) {
|
||||
open++;
|
||||
assertEquals(WaterRole.INLET, mouth.role(lx, lz));
|
||||
assertEquals(SEA_LEVEL, mouth.waterHead(lx, lz));
|
||||
assertEquals(SEA_LEVEL - 3, mouth.terrainHeight(lx, lz));
|
||||
assertEquals(SEA_LEVEL - 4, mouth.caveCeiling(lx, lz));
|
||||
assertEquals(71L, mouth.featureId(lx, lz));
|
||||
assertEquals(HydrologyCaveCell.SEA_FLUID, mouth.fluid(lx, lz));
|
||||
} else {
|
||||
assertEquals(WaterRole.NONE, mouth.role(lx, lz));
|
||||
assertEquals(70, mouth.terrainHeight(lx, lz));
|
||||
if (Math.abs(lz - 8) <= 2) {
|
||||
wet++;
|
||||
assertEquals(WaterRole.INLET, raster.role(lx, lz));
|
||||
assertEquals(SEA_LEVEL, raster.waterHead(lx, lz));
|
||||
assertTrue(raster.terrainHeight(lx, lz) < SEA_LEVEL);
|
||||
assertEquals(71L, raster.featureId(lx, lz));
|
||||
assertEquals(HydrologyCaveCell.SEA_FLUID, raster.fluid(lx, lz));
|
||||
} else if (raster.waterHead(lx, lz) == Integer.MIN_VALUE) {
|
||||
bank++;
|
||||
assertTrue("shaped ground stays above the water at " + lx + "," + lz, raster.terrainHeight(lx, lz) >= SEA_LEVEL);
|
||||
assertTrue("the band cuts the bank below the natural ground at " + lx + "," + lz, raster.terrainHeight(lx, lz) < SEA_LEVEL + 12);
|
||||
}
|
||||
}
|
||||
}
|
||||
assertTrue("open slot columns " + open, open > 20);
|
||||
assertTrue("a covered passage leaves the surface alone",
|
||||
rasterizer.rasterize(2, 0, (x, z) -> 70, List.of(own), regions(2, 0, List.of())).empty());
|
||||
assertTrue("water columns " + wet, wet > 60);
|
||||
assertTrue("bank columns " + bank, bank > 60);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -466,7 +464,7 @@ public class ChunkWaterRasterTest {
|
||||
HydrologySettings settings = settings(new IrisHydrology());
|
||||
Reach far = line(61L, tier("stream", 1.5f, 0.5f, 0, IrisBankStyle.SMOOTH), 0L, 400f, 400f, 480f, 400f, (x, z) -> 69);
|
||||
WindowKey key = new WindowKey(0, 0);
|
||||
IndexedWindow own = new IndexedWindow(new WindowPlan(key, List.of(far), List.of(), List.of()), ReachIndex.build(key, List.of(far), List.of()));
|
||||
IndexedWindow own = new IndexedWindow(new WindowPlan(key, List.of(far), List.of()), ReachIndex.build(key, List.of(far), List.of()));
|
||||
AtomicInteger samples = new AtomicInteger();
|
||||
IntBinaryOperator natural = (x, z) -> {
|
||||
samples.incrementAndGet();
|
||||
@@ -503,7 +501,7 @@ public class ChunkWaterRasterTest {
|
||||
Reach outflow = line(61L, stream, 0L, 400f, 403f, 480f, 403f, (x, z) -> 69);
|
||||
Reach inflow = line(62L, stream, 0L, 480f, 412f, 400f, 412f, (x, z) -> 69);
|
||||
WindowKey key = new WindowKey(0, 0);
|
||||
IndexedWindow own = new IndexedWindow(new WindowPlan(key, List.of(outflow, inflow), List.of(), List.of()),
|
||||
IndexedWindow own = new IndexedWindow(new WindowPlan(key, List.of(outflow, inflow), List.of()),
|
||||
ReachIndex.build(key, List.of(outflow, inflow), List.of()));
|
||||
ChannelFluids volcanic = (x, z) -> x < 440 ? "lava" : null;
|
||||
ChunkWaterRaster raster = new ChunkRasterizer(settings, volcanic).rasterize(27, 25, (x, z) -> 70, List.of(own), regions(27, 25, List.of()));
|
||||
@@ -531,7 +529,7 @@ public class ChunkWaterRasterTest {
|
||||
HydrologySettings settings = settings(new IrisHydrology());
|
||||
Reach river = line(81L, tier("river", 3f, 0.5f, 32, IrisBankStyle.SMOOTH), 0L, 96f, 256f, 416f, 256f, (x, z) -> 69);
|
||||
WindowKey key = new WindowKey(0, 0);
|
||||
IndexedWindow own = new IndexedWindow(new WindowPlan(key, List.of(river), List.of(), List.of()), ReachIndex.build(key, List.of(river), List.of()));
|
||||
IndexedWindow own = new IndexedWindow(new WindowPlan(key, List.of(river), List.of()), ReachIndex.build(key, List.of(river), List.of()));
|
||||
NaturalHeights natural = (x, z) -> {
|
||||
double away = Math.abs(z - 256);
|
||||
if (x < 256) {
|
||||
@@ -1016,7 +1014,7 @@ public class ChunkWaterRasterTest {
|
||||
WindowKey key = new WindowKey(dx, dz);
|
||||
List<Reach> owned = key.equals(new WindowKey(0, 0)) ? List.of(feeder)
|
||||
: key.equals(new WindowKey(1, 0)) || key.equals(new WindowKey(1, -1)) ? List.of(downstream) : List.of();
|
||||
windows.add(new IndexedWindow(new WindowPlan(key, owned, List.of(), List.of()), ReachIndex.build(key, owned, List.of())));
|
||||
windows.add(new IndexedWindow(new WindowPlan(key, owned, List.of()), ReachIndex.build(key, owned, List.of())));
|
||||
}
|
||||
}
|
||||
ChunkRasterizer rasterizer = new ChunkRasterizer(settings(new IrisHydrology()), ChannelFluids.TIER);
|
||||
@@ -2644,7 +2642,7 @@ public class ChunkWaterRasterTest {
|
||||
ownedPonds.add(pond);
|
||||
}
|
||||
}
|
||||
return new IndexedWindow(new WindowPlan(key, owned, ownedPonds, List.of()), ReachIndex.build(key, owned, ownedPonds));
|
||||
return new IndexedWindow(new WindowPlan(key, owned, ownedPonds), ReachIndex.build(key, owned, ownedPonds));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -114,7 +114,7 @@ public class PondChannelSettlementTest {
|
||||
for (long seed = 1L; seed <= 24L; seed++) {
|
||||
HydrologySettings settings = HydrologySettings.compile(new IrisHydrology(), seed, SEA_LEVEL, -64, 320);
|
||||
ChunkRasterizer rasterizer = new ChunkRasterizer(settings, ChannelFluids.TIER);
|
||||
IndexedWindow window = new IndexedWindow(new WindowPlan(WINDOW, List.of(river), List.of(), List.of()), ReachIndex.build(WINDOW, List.of(river), List.of()));
|
||||
IndexedWindow window = new IndexedWindow(new WindowPlan(WINDOW, List.of(river), List.of()), ReachIndex.build(WINDOW, List.of(river), List.of()));
|
||||
for (int z = 124; z <= 132; z++) {
|
||||
Pond pond = pond(1L, PondKind.NATURAL, 94, circle(504, z, 0));
|
||||
int lowest = Math.min(94, Math.min(rasterHead(rasterizer, window, 504, z), Math.min(rasterHead(rasterizer, window, 505, z),
|
||||
@@ -163,7 +163,7 @@ public class PondChannelSettlementTest {
|
||||
private static int assertSettlementMatchesTheRaster(long seed, Reach river, int minX, int maxX, int minZ, int maxZ, int stride) {
|
||||
HydrologySettings settings = HydrologySettings.compile(new IrisHydrology(), seed, SEA_LEVEL, -64, 320);
|
||||
ChunkRasterizer rasterizer = new ChunkRasterizer(settings, ChannelFluids.TIER);
|
||||
IndexedWindow window = new IndexedWindow(new WindowPlan(WINDOW, List.of(river), List.of(), List.of()), ReachIndex.build(WINDOW, List.of(river), List.of()));
|
||||
IndexedWindow window = new IndexedWindow(new WindowPlan(WINDOW, List.of(river), List.of()), ReachIndex.build(WINDOW, List.of(river), List.of()));
|
||||
Map<Long, ChunkWaterRaster> rasters = new HashMap<>();
|
||||
int lowered = 0;
|
||||
for (int x = minX; x <= maxX; x += stride) {
|
||||
|
||||
@@ -837,7 +837,7 @@ public class PondPlannerTest {
|
||||
long key = ((long) (x >> 4) << 32) | ((z >> 4) & 0xFFFFFFFFL);
|
||||
ChunkWaterRaster raster = rasters.get(key);
|
||||
if (raster == null) {
|
||||
WindowPlan window = new WindowPlan(WindowKey.containing(x, z), List.of(), List.of(pond), List.of());
|
||||
WindowPlan window = new WindowPlan(WindowKey.containing(x, z), List.of(), List.of(pond));
|
||||
IndexedWindow indexed = new IndexedWindow(window, ReachIndex.build(window.key(), List.of(), List.of(pond)));
|
||||
List<RegionPlan> regions = new ArrayList<>();
|
||||
for (RegionKey region : ChunkRasterizer.lakeRegions(x >> 4, z >> 4)) {
|
||||
|
||||
@@ -7,6 +7,7 @@ import art.arcane.iris.generation.hydrology.query.HydrologyFeatureType;
|
||||
import art.arcane.iris.generation.hydrology.raster.ChunkWaterRaster;
|
||||
import art.arcane.iris.generation.hydrology.water.Pond;
|
||||
import art.arcane.iris.generation.hydrology.water.Reach;
|
||||
import art.arcane.iris.generation.hydrology.water.ReachStyle;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
import art.arcane.iris.generation.runtime.IrisEngine;
|
||||
@@ -14,7 +15,6 @@ import art.arcane.iris.world.history.ChunkGenerationSemantics;
|
||||
import art.arcane.iris.world.history.GenerationHistory;
|
||||
import art.arcane.iris.world.history.GenerationHistoryRuntimeRouter;
|
||||
import art.arcane.iris.generation.stream.ProvisionalSampling;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInlet;
|
||||
import art.arcane.iris.testsupport.FakeHydrology;
|
||||
import art.arcane.iris.testsupport.WaterScene;
|
||||
import org.junit.Test;
|
||||
@@ -100,7 +100,7 @@ public class IrisRendererRiverTest {
|
||||
Pond pond = WaterScene.pond(32L, 62, 16, 16, 10);
|
||||
when(runtime.enabled()).thenReturn(true);
|
||||
when(runtime.planPreview(anyInt(), anyInt(), anyInt(), anyInt()))
|
||||
.thenReturn(new HydrologyPlanPreview(List.of(), List.of(pond), List.of(), List.of(), true));
|
||||
.thenReturn(new HydrologyPlanPreview(List.of(), List.of(pond), List.of(), true));
|
||||
when(runtime.rasterPreview(anyInt(), anyInt())).thenReturn(ChunkWaterRaster.PROVISIONAL);
|
||||
IrisRenderer renderer = new IrisRenderer(engine(runtime));
|
||||
|
||||
@@ -166,23 +166,24 @@ public class IrisRendererRiverTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void planModeDrawsSeaInletPathsUnderground() throws Exception {
|
||||
int stations = 26;
|
||||
float[] xs = new float[stations];
|
||||
float[] zs = new float[stations];
|
||||
float[] halfWidth = new float[stations];
|
||||
int[] floor = new int[stations];
|
||||
int[] ceiling = new int[stations];
|
||||
for (int station = 0; station < stations; station++) {
|
||||
xs[station] = 100f + station * 8f;
|
||||
zs[station] = 200f;
|
||||
halfWidth[station] = 4f;
|
||||
floor[station] = SEA_LEVEL - 3;
|
||||
ceiling[station] = SEA_LEVEL + 5;
|
||||
public void planModeDrawsTidalReachesAsSeaInlets() throws Exception {
|
||||
int points = 26;
|
||||
float[] xs = new float[points];
|
||||
float[] zs = new float[points];
|
||||
int[] grade = new int[points];
|
||||
float[] halfWidth = new float[points];
|
||||
float[] depth = new float[points];
|
||||
ReachStyle[] style = new ReachStyle[points];
|
||||
for (int point = 0; point < points; point++) {
|
||||
xs[point] = 100f + point * 8f;
|
||||
zs[point] = 200f;
|
||||
grade[point] = SEA_LEVEL;
|
||||
halfWidth[point] = 4f;
|
||||
depth[point] = 3f;
|
||||
style[point] = ReachStyle.TIDAL;
|
||||
}
|
||||
SeaInlet inlet = new SeaInlet(51L, xs, zs, halfWidth, SEA_LEVEL, floor, ceiling, 300, 200, 8);
|
||||
try (FakeHydrology hydrology = new FakeHydrology(() -> false, (x, z) -> 90, SEA_LEVEL, List.of(), List.of(), List.of(),
|
||||
List.of(inlet))) {
|
||||
Reach tidal = new Reach(51L, FakeHydrology.settings(SEA_LEVEL).tidalTier(), 0L, xs, zs, grade, halfWidth, depth, style, 0f);
|
||||
try (FakeHydrology hydrology = new FakeHydrology(() -> false, (x, z) -> 90, SEA_LEVEL, List.of(tidal), List.of())) {
|
||||
HydrologyRuntime runtime = spy(hydrology.runtime);
|
||||
int[] plan = settled(engine(runtime), 16D * PIXELS, PIXELS);
|
||||
assertEquals(water(HydrologyFeatureType.SEA_INLET), at(plan, PIXELS, 200 / 16, 200 / 16));
|
||||
|
||||
@@ -31,7 +31,7 @@ public class WaterMapProgressTest {
|
||||
HydrologyRuntime runtime = mock(HydrologyRuntime.class);
|
||||
Reach reach = mock(Reach.class);
|
||||
when(runtime.planPreview(anyInt(), anyInt(), anyInt(), anyInt()))
|
||||
.thenReturn(new HydrologyPlanPreview(List.of(reach), List.of(), List.of(), List.of(), true));
|
||||
.thenReturn(new HydrologyPlanPreview(List.of(reach), List.of(), List.of(), true));
|
||||
when(runtime.rasterPreview(anyInt(), anyInt())).thenReturn(ChunkWaterRaster.EMPTY);
|
||||
|
||||
WaterMap map = new WaterMap(runtime, 32, 0D, 0D, 1D);
|
||||
|
||||
@@ -53,7 +53,7 @@ public class WaterMapTest {
|
||||
private static WaterMap draw(List<Reach> reaches, List<Pond> ponds, List<Pond> lakes) {
|
||||
HydrologyRuntime runtime = mock(HydrologyRuntime.class);
|
||||
when(runtime.planPreview(anyInt(), anyInt(), anyInt(), anyInt()))
|
||||
.thenReturn(new HydrologyPlanPreview(reaches, ponds, lakes, List.of(), true));
|
||||
.thenReturn(new HydrologyPlanPreview(reaches, ponds, lakes, true));
|
||||
when(runtime.channelType(any(HydrologyTier.class))).thenReturn(HydrologyFeatureType.STREAM);
|
||||
WaterMap map = new WaterMap(runtime, PIXELS, 0D, 0D, MID_STEP);
|
||||
map.advance(() -> false);
|
||||
|
||||
@@ -9,7 +9,6 @@ import art.arcane.iris.generation.hydrology.plan.RegionPlan;
|
||||
import art.arcane.iris.generation.hydrology.plan.WindowKey;
|
||||
import art.arcane.iris.generation.hydrology.plan.WindowPlan;
|
||||
import art.arcane.iris.generation.hydrology.raster.ChunkWaterRaster;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInlet;
|
||||
import art.arcane.iris.generation.hydrology.water.Pond;
|
||||
import art.arcane.iris.generation.hydrology.water.PondKind;
|
||||
import art.arcane.iris.generation.hydrology.water.PondMask;
|
||||
@@ -46,35 +45,28 @@ public final class FakeHydrology implements AutoCloseable {
|
||||
private final List<Reach> reaches;
|
||||
private final List<Pond> ponds;
|
||||
private final List<Pond> lakes;
|
||||
private final List<SeaInlet> inlets;
|
||||
private final ExecutorService pool;
|
||||
private volatile CountDownLatch gate;
|
||||
|
||||
public FakeHydrology(BooleanSupplier mainThread, IntBinaryOperator naturalHeight, int seaLevel, int pondLevel) {
|
||||
this(mainThread, naturalHeight, seaLevel, pondLevel, List.of(), null, List.of(), List.of());
|
||||
this(mainThread, naturalHeight, seaLevel, pondLevel, List.of(), null, List.of());
|
||||
}
|
||||
|
||||
public FakeHydrology(BooleanSupplier mainThread, IntBinaryOperator naturalHeight, int seaLevel, List<Reach> reaches, List<Pond> ponds) {
|
||||
this(mainThread, naturalHeight, seaLevel, 0, reaches, ponds, List.of(), List.of());
|
||||
this(mainThread, naturalHeight, seaLevel, 0, reaches, ponds, List.of());
|
||||
}
|
||||
|
||||
public FakeHydrology(BooleanSupplier mainThread, IntBinaryOperator naturalHeight, int seaLevel, List<Reach> reaches, List<Pond> ponds,
|
||||
List<Pond> lakes) {
|
||||
this(mainThread, naturalHeight, seaLevel, 0, reaches, ponds, lakes, List.of());
|
||||
}
|
||||
|
||||
public FakeHydrology(BooleanSupplier mainThread, IntBinaryOperator naturalHeight, int seaLevel, List<Reach> reaches, List<Pond> ponds,
|
||||
List<Pond> lakes, List<SeaInlet> inlets) {
|
||||
this(mainThread, naturalHeight, seaLevel, 0, reaches, ponds, lakes, inlets);
|
||||
this(mainThread, naturalHeight, seaLevel, 0, reaches, ponds, lakes);
|
||||
}
|
||||
|
||||
private FakeHydrology(BooleanSupplier mainThread, IntBinaryOperator naturalHeight, int seaLevel, int pondLevel, List<Reach> reaches,
|
||||
List<Pond> ponds, List<Pond> lakes, List<SeaInlet> inlets) {
|
||||
List<Pond> ponds, List<Pond> lakes) {
|
||||
this.pondLevel = pondLevel;
|
||||
this.reaches = List.copyOf(reaches);
|
||||
this.ponds = ponds == null ? List.of(pond()) : List.copyOf(ponds);
|
||||
this.lakes = List.copyOf(lakes);
|
||||
this.inlets = List.copyOf(inlets);
|
||||
AtomicInteger threads = new AtomicInteger();
|
||||
this.pool = Executors.newFixedThreadPool(4, runnable -> {
|
||||
Thread thread = new Thread(runnable, "fake-hydrology-" + threads.incrementAndGet());
|
||||
@@ -135,12 +127,12 @@ public final class FakeHydrology implements AutoCloseable {
|
||||
windowCalls.incrementAndGet();
|
||||
await(gate);
|
||||
if (!key.equals(new WindowKey(0, 0))) {
|
||||
return new WindowPlan(key, List.of(), List.of(), List.of());
|
||||
return new WindowPlan(key, List.of(), List.of());
|
||||
}
|
||||
if (failing.get()) {
|
||||
throw new IllegalStateException(FAILURE);
|
||||
}
|
||||
return new WindowPlan(key, reaches, ponds, inlets);
|
||||
return new WindowPlan(key, reaches, ponds);
|
||||
}
|
||||
|
||||
private Pond pond() {
|
||||
|
||||
@@ -156,7 +156,7 @@ public final class WaterScene {
|
||||
ownedPonds.add(pond);
|
||||
}
|
||||
}
|
||||
return new IndexedWindow(new WindowPlan(key, owned, ownedPonds, List.of()), ReachIndex.build(key, owned, ownedPonds));
|
||||
return new IndexedWindow(new WindowPlan(key, owned, ownedPonds), ReachIndex.build(key, owned, ownedPonds));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+17
-17
@@ -24,7 +24,6 @@ import art.arcane.iris.generation.hydrology.plan.HydrologySettings;
|
||||
import art.arcane.iris.generation.hydrology.query.HydrologyFeatureType;
|
||||
import art.arcane.iris.generation.hydrology.raster.ChunkWaterRaster;
|
||||
import art.arcane.iris.generation.hydrology.raster.WaterRole;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInlet;
|
||||
import art.arcane.iris.generation.hydrology.water.Pond;
|
||||
import art.arcane.iris.generation.hydrology.water.PondKind;
|
||||
import art.arcane.iris.generation.hydrology.water.Reach;
|
||||
@@ -514,23 +513,24 @@ public final class GenerationSemanticCaptureTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void recordsSeaInletsInEveryChunkTheyPassUnderWithTheirOwnProfile() {
|
||||
int stations = 8;
|
||||
float[] xs = new float[stations];
|
||||
float[] zs = new float[stations];
|
||||
float[] halfWidth = new float[stations];
|
||||
int[] floor = new int[stations];
|
||||
int[] ceiling = new int[stations];
|
||||
for (int station = 0; station < stations; station++) {
|
||||
xs[station] = 4f + station * 8f;
|
||||
zs[station] = 24f;
|
||||
halfWidth[station] = 3f;
|
||||
floor[station] = WATER_SEA_LEVEL - 3;
|
||||
ceiling[station] = WATER_SEA_LEVEL + 5;
|
||||
public void recordsTidalReachesInEveryChunkTheyCrossWithTheirOwnProfile() {
|
||||
int points = 8;
|
||||
float[] xs = new float[points];
|
||||
float[] zs = new float[points];
|
||||
int[] grade = new int[points];
|
||||
float[] halfWidth = new float[points];
|
||||
float[] depth = new float[points];
|
||||
ReachStyle[] style = new ReachStyle[points];
|
||||
for (int point = 0; point < points; point++) {
|
||||
xs[point] = 4f + point * 8f;
|
||||
zs[point] = 24f;
|
||||
grade[point] = WATER_SEA_LEVEL;
|
||||
halfWidth[point] = 3f;
|
||||
depth[point] = 3f;
|
||||
style[point] = ReachStyle.TIDAL;
|
||||
}
|
||||
SeaInlet inlet = new SeaInlet(41L, xs, zs, halfWidth, WATER_SEA_LEVEL, floor, ceiling, 60, 24, 4);
|
||||
try (FakeHydrology hydrology = new FakeHydrology(() -> false, (x, z) -> 90, WATER_SEA_LEVEL, List.of(), List.of(), List.of(),
|
||||
List.of(inlet))) {
|
||||
Reach tidal = new Reach(41L, FakeHydrology.settings(WATER_SEA_LEVEL).tidalTier(), 0L, xs, zs, grade, halfWidth, depth, style, 0f);
|
||||
try (FakeHydrology hydrology = new FakeHydrology(() -> false, (x, z) -> 90, WATER_SEA_LEVEL, List.of(tidal), List.of())) {
|
||||
Fixture fixture = new Fixture();
|
||||
fixture.water(hydrology.runtime);
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ final class HydrologyUnderground {
|
||||
|
||||
static Source generated(Engine engine, ExecutorService workers) {
|
||||
return (key, plan) -> {
|
||||
SeaInletProbe.Checks inlets = SeaInletProbe.check(engine, plan.inlets(), workers);
|
||||
SeaInletProbe.Checks inlets = SeaInletProbe.check(engine, List.of(), workers);
|
||||
int minChunkX = key.wx() * HydrologyWindows.CHUNKS;
|
||||
int minChunkZ = key.wz() * HydrologyWindows.CHUNKS;
|
||||
CavePoolProbe.Counts pools = CavePoolProbe.check(engine, new CavePoolProbe.Area(minChunkX, minChunkX + HydrologyWindows.CHUNKS - 1,
|
||||
|
||||
@@ -350,7 +350,7 @@ public class HydrologyMetricsTest {
|
||||
}
|
||||
|
||||
private static WindowPlan plan(WindowKey key, List<Reach> reaches, List<Pond> ponds) {
|
||||
return new WindowPlan(key, reaches, ponds, List.of());
|
||||
return new WindowPlan(key, reaches, ponds);
|
||||
}
|
||||
|
||||
private static Reach reach(long id, HydrologyTier tier, long downstream, float catchment, int[] grade, float... coordinates) {
|
||||
|
||||
@@ -57,7 +57,7 @@ public class RiverTransectProbeTest {
|
||||
RiverTransectProbe.Section section = RiverTransectProbe.section(reach, 5,
|
||||
(x, z) -> new RiverTransectProbe.Column(70, 66, Math.abs(z - 100) <= 2 ? 68 : RiverTransectProbe.NO_WATER, WaterRole.CHANNEL));
|
||||
List<String> summary = RiverTransectProbe.summary(new WindowKey(0, 0),
|
||||
new WindowPlan(new WindowKey(0, 0), List.of(reach), List.of(), List.of()), List.of(),
|
||||
new WindowPlan(new WindowKey(0, 0), List.of(reach), List.of()), List.of(),
|
||||
List.of(section), settings);
|
||||
assertEquals("window 0,0 reaches=1 ponds=0 lakes=0 sections=1", summary.get(0));
|
||||
assertTrue(summary.get(1), summary.get(1).startsWith("reach 7 tier=stream length=40 from=0,100@70 to=40,100@60"));
|
||||
|
||||
@@ -45,7 +45,7 @@ final class SyntheticHydrology implements AutoCloseable {
|
||||
}
|
||||
|
||||
HydrologyProbe.Inputs inputs(UnaryOperator<HydrologyVoxels.ChunkBlocks> edit) {
|
||||
return inputs(edit, (key, plan) -> new HydrologyUnderground.Counts(plan.inlets().size(), 0L, 0, 0L, List.of()));
|
||||
return inputs(edit, (key, plan) -> new HydrologyUnderground.Counts(0, 0L, 0, 0L, List.of()));
|
||||
}
|
||||
|
||||
HydrologyProbe.Inputs inputs(UnaryOperator<HydrologyVoxels.ChunkBlocks> edit, HydrologyUnderground.Source underground) {
|
||||
|
||||
Reference in new issue
Block a user