mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-12-01 02:04:51 +00:00
Merge tidal inlets
- Sea inlets become tidal reaches on the river pipeline - Recaptures the schema digest for the merged lane
This commit is contained in:
commit
5df42fc49e
82 files changed
+3370
-4647
No files matched your search
@@ -56,7 +56,7 @@ public class IrisHydrology {
|
||||
@Description("How the ground around water is reshaped.")
|
||||
private IrisHydrologyDeformation deformation = new IrisHydrologyDeformation();
|
||||
|
||||
@Description("Water below the surface: flooded sea inlets and cave pools.")
|
||||
@Description("Sea inlets on the coast, and pools and springs in caves.")
|
||||
private IrisHydrologyUnderground underground = new IrisHydrologyUnderground();
|
||||
|
||||
@ArrayType(type = IrisFluidProfile.class, min = 1)
|
||||
|
||||
+2
-2
@@ -7,10 +7,10 @@ import lombok.experimental.Accessors;
|
||||
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@Description("Water below the surface: flooded passages that run inland from the sea, pools on cave floors, and springs in cave walls.")
|
||||
@Description("Sea inlets on the coast, and water below the surface: pools on cave floors and springs in cave walls.")
|
||||
@Data
|
||||
public class IrisHydrologyUnderground {
|
||||
@Description("Flooded passages at sea level that run inland from coastal cliffs.")
|
||||
@Description("Tidal arms of the sea that wind inland from low coasts at sea level.")
|
||||
private IrisSeaInlets seaInlets = new IrisSeaInlets();
|
||||
|
||||
@Description("Standing water on the floors of carved caves.")
|
||||
|
||||
@@ -11,44 +11,58 @@ import lombok.experimental.Accessors;
|
||||
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@Description("Flooded passages that open in coastal cliffs and run inland, up the valleys where the drainage allows and onward under higher ground, with the water held at sea level the whole way, ending in a pool chamber. An inlet, its chamber and its seal stay within 512 blocks of the coast.")
|
||||
@Description("Tidal arms of the sea: winding water courses open to the sky, flat at sea level and filled with sea water, wide at the coast and narrowing inland between shaped banks. They form on low coasts and keep clear of rivers, ponds and lakes.")
|
||||
@Data
|
||||
public class IrisSeaInlets {
|
||||
@Description("Cuts sea inlets into coastal cliffs.")
|
||||
@Description("Cuts sea inlets into low coasts.")
|
||||
private boolean enabled = true;
|
||||
|
||||
@MinNumber(32)
|
||||
@MaxNumber(4096)
|
||||
@Description("Size in blocks of the square cells of the site grid. Each cell holds at most one inlet; inlets in neighbouring cells can lie closer than this.")
|
||||
private int spacing = 192;
|
||||
|
||||
@MinNumber(1)
|
||||
@MaxNumber(128)
|
||||
@Description("Height in blocks the coastal land must rise above sea level to be a site. The passage also needs ground at least headroom min + roofClearance + 2 blocks above sea level within about 16 blocks of the coast, so gentle coasts hold no inlets.")
|
||||
private int minimumCliffHeight = 8;
|
||||
private int spacing = 160;
|
||||
|
||||
@ArrayType(type = Integer.class, min = 2)
|
||||
@Description("Length of an inlet in blocks, written as [min, max]. The max plus 12, plus the larger of halfWidth max and chamberRadius max, plus 3 must not exceed 512.")
|
||||
@Description("Length of an inlet in blocks along its centre line, written as [min, max]. An arm that cannot reach the min is left out. The max, plus the meander, plus mouthHalfWidth max, plus bankBand must not exceed 512.")
|
||||
private KList<Integer> length = new KList<>(64, 256);
|
||||
|
||||
@MinNumber(2)
|
||||
@MaxNumber(128)
|
||||
@Description("Highest ground in blocks above sea level an inlet may cut through. An arm also stays under the height its bank band can grade back without a sheer wall, about 1.7 times bankBand. It routes around or stops short of higher ground, so lower values keep inlets out of hills.")
|
||||
private int maximumBankHeight = 44;
|
||||
|
||||
@ArrayType(type = Double.class, min = 2)
|
||||
@Description("Half-width of the passage in blocks, written as [min, max], each from 1 to 16. The passage narrows toward its inland end.")
|
||||
private KList<Double> halfWidth = new KList<>(2D, 5D);
|
||||
@Description("Half-width of the water at the sea in blocks, written as [min, max], each from 2 to 32. The min must not be below headHalfWidth max.")
|
||||
private KList<Double> mouthHalfWidth = new KList<>(13D, 15D);
|
||||
|
||||
@ArrayType(type = Integer.class, min = 2)
|
||||
@Description("Water depth below sea level in blocks, written as [min, max], each from 2 to 16. Two blocks keep liquid water under an open slot's top sea layer.")
|
||||
private KList<Integer> depth = new KList<>(2, 5);
|
||||
@ArrayType(type = Double.class, min = 2)
|
||||
@Description("Half-width of the water at the inland end in blocks, written as [min, max], each from 1 to 8.")
|
||||
private KList<Double> headHalfWidth = new KList<>(2.5D, 3D);
|
||||
|
||||
@ArrayType(type = Integer.class, min = 2)
|
||||
@Description("Air space above the water in blocks, written as [min, max], each from 0 to 32. It varies smoothly along the passage and shrinks where the ground above is thin.")
|
||||
private KList<Integer> headroom = new KList<>(4, 10);
|
||||
@MinNumber(0.5)
|
||||
@MaxNumber(4)
|
||||
@Description("How the width falls from mouth to head. 1 narrows evenly; above 1 stays narrow further from the head and widens late near the sea; below 1 widens early.")
|
||||
private double taper = 1.4D;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(0.5)
|
||||
@Description("Slow change in width along the arm, as a fraction of the width at that point.")
|
||||
private double widthVariation = 0.18D;
|
||||
|
||||
@MinNumber(1)
|
||||
@MaxNumber(64)
|
||||
@Description("Least solid ground in blocks kept between the passage roof and the surface.")
|
||||
private int roofClearance = 6;
|
||||
@MaxNumber(16)
|
||||
@Description("Half-width in blocks that sets the size of the bends, as a river of that half-width would meander. Larger values give longer, wider bends.")
|
||||
private double meanderWidth = 4D;
|
||||
|
||||
@ArrayType(type = Integer.class, min = 2)
|
||||
@Description("Radius in blocks of the pool chamber at the inland end, written as [min, max], each from 1 to 32.")
|
||||
private KList<Integer> chamberRadius = new KList<>(6, 12);
|
||||
@Description("Water depth at the middle of the arm in blocks, written as [min, max], each from 2 to 16. The depth runs from min at the head to max toward the sea, and shoals to 1 at both ends.")
|
||||
private KList<Integer> depth = new KList<>(2, 5);
|
||||
|
||||
@MinNumber(4)
|
||||
@MaxNumber(64)
|
||||
@Description("Width in blocks of the band of ground beside the water that is shaped into banks.")
|
||||
private int bankBand = 32;
|
||||
|
||||
@Description("Profile of the banks across bankBand.")
|
||||
private IrisBankStyle bankStyle = IrisBankStyle.SMOOTH;
|
||||
}
|
||||
+24
-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;
|
||||
@@ -41,6 +40,8 @@ final class HydrologyFeatureSearch {
|
||||
private static final Set<HydrologyFeatureType> WINDOW_TYPES = EnumSet.of(HydrologyFeatureType.STREAM, HydrologyFeatureType.RIVER,
|
||||
HydrologyFeatureType.MAJOR_RIVER, HydrologyFeatureType.CASCADE, HydrologyFeatureType.WATERFALL, HydrologyFeatureType.MOUTH,
|
||||
HydrologyFeatureType.POND, HydrologyFeatureType.DAM, HydrologyFeatureType.SEA_INLET);
|
||||
private static final double TIDAL_LANDING_FROM = 0.5D;
|
||||
private static final double TIDAL_LANDING_TO = 0.9D;
|
||||
private static final long POLL_NANOS = TimeUnit.MILLISECONDS.toNanos(50L);
|
||||
static final String OFF = "hydrology is off";
|
||||
private static final String PONDS_OFF = "hydrology.ponds.natural and hydrology.ponds.seeded are disabled";
|
||||
@@ -219,18 +220,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 +233,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 +252,21 @@ final class HydrologyFeatureSearch {
|
||||
}
|
||||
}
|
||||
|
||||
private void tidal(Reach reach) {
|
||||
float[] xs = reach.xs();
|
||||
float[] zs = reach.zs();
|
||||
double[] along = new double[xs.length];
|
||||
for (int index = 1; index < xs.length; index++) {
|
||||
along[index] = along[index - 1] + Math.hypot(xs[index] - xs[index - 1], zs[index] - zs[index - 1]);
|
||||
}
|
||||
double total = along[xs.length - 1];
|
||||
for (int index = 0; index < xs.length; index++) {
|
||||
if (along[index] >= TIDAL_LANDING_FROM * total && along[index] <= TIDAL_LANDING_TO * total) {
|
||||
offer(reach.id(), HydrologyFeatureType.SEA_INLET, (int) Math.floor(xs[index]), reach.grade()[index], (int) Math.floor(zs[index]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void pond(Pond pond, HydrologyFeatureType type) {
|
||||
PondMask mask = pond.mask();
|
||||
for (int j = 0; j < mask.depth(); j++) {
|
||||
@@ -306,7 +316,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"));
|
||||
}
|
||||
}
|
||||
+1
-27
@@ -19,8 +19,6 @@ import art.arcane.iris.generation.hydrology.raster.ChannelFluids;
|
||||
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 +305,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 +312,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 +331,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) {
|
||||
@@ -441,28 +437,6 @@ public final class HydrologyRuntime {
|
||||
return HydrologyFeatureSearch.channelType(settings, tier);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public Set<HydrologyFeatureType> standingWaterTypes(int chunkX, int chunkZ, long featureId) {
|
||||
if (cache == null) {
|
||||
throw new IllegalStateException("Hydrology is disabled, so it has no standing water.");
|
||||
|
||||
+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) {
|
||||
}
|
||||
}
|
||||
+68
-34
@@ -21,9 +21,8 @@ import art.arcane.iris.generation.hydrology.config.IrisPondDams;
|
||||
import art.arcane.iris.generation.hydrology.config.IrisPondNatural;
|
||||
import art.arcane.iris.generation.hydrology.config.IrisPondSeeded;
|
||||
import art.arcane.iris.generation.hydrology.config.IrisPondShore;
|
||||
import art.arcane.iris.generation.hydrology.config.IrisBankStyle;
|
||||
import art.arcane.iris.generation.hydrology.config.IrisSeaInlets;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInletPlanner;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInletRasterizer;
|
||||
import art.arcane.iris.generation.hydrology.raster.WaterHeads;
|
||||
import art.arcane.iris.generation.hydrology.water.HydrologyTier;
|
||||
import art.arcane.iris.generation.hydrology.water.LakeCandidate;
|
||||
@@ -52,14 +51,26 @@ 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 double MIN_INLET_HALF_WIDTH = 1D;
|
||||
private static final double MAX_INLET_HALF_WIDTH = 16D;
|
||||
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;
|
||||
private static final double MAX_INLET_HEAD = 8D;
|
||||
private static final int MIN_INLET_DEPTH = 2;
|
||||
private static final int MAX_INLET_DEPTH = 16;
|
||||
private static final int MAX_INLET_HEADROOM = 32;
|
||||
private static final int MAX_INLET_CHAMBER = 32;
|
||||
private static final int MIN_INLET_BANK_HEIGHT = 2;
|
||||
private static final int MAX_INLET_BANK_HEIGHT = 128;
|
||||
private static final double MIN_INLET_TAPER = 0.5D;
|
||||
private static final double MAX_INLET_TAPER = 4D;
|
||||
private static final double MAX_INLET_WIDTH_VARIATION = 0.5D;
|
||||
private static final double MIN_INLET_MEANDER_WIDTH = 1D;
|
||||
private static final double MAX_INLET_MEANDER_WIDTH = 16D;
|
||||
private static final int MIN_INLET_BANK_BAND = 4;
|
||||
private static final int MAX_INLET_BANK_BAND = 64;
|
||||
private static final int INLET_LAST_STEP = (int) Math.ceil(WindowPlanner.CELL * Math.sqrt(2D));
|
||||
private static final int INLET_SHELL = SeaInletRasterizer.SHELL;
|
||||
private static final double INLET_MEANDER_SCALE = 2.5D;
|
||||
private static final double INLET_MEANDER_MAX = 16D;
|
||||
public static final int MAX_CAVE_POOL_RADIUS = 15;
|
||||
private static final int CAVE_POOL_SPAN = 2 * MAX_CAVE_POOL_RADIUS + 1;
|
||||
private static final int MAX_CAVE_POOL_AREA = CAVE_POOL_SPAN * CAVE_POOL_SPAN;
|
||||
@@ -85,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;
|
||||
@@ -108,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();
|
||||
@@ -129,6 +142,10 @@ public final class HydrologySettings {
|
||||
return tiers;
|
||||
}
|
||||
|
||||
public HydrologyTier tidalTier() {
|
||||
return tidalTier;
|
||||
}
|
||||
|
||||
public HydrologyTier majorTier() {
|
||||
return tiers.get(tiers.size() - 1);
|
||||
}
|
||||
@@ -207,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");
|
||||
@@ -365,39 +388,49 @@ public final class HydrologySettings {
|
||||
}
|
||||
|
||||
private SeaInlets seaInlets(IrisSeaInlets config) {
|
||||
SeaInlets inlets = new SeaInlets(config.isEnabled(), config.getSpacing(), config.getMinimumCliffHeight(),
|
||||
SeaInlets inlets = new SeaInlets(config.isEnabled(), config.getSpacing(),
|
||||
intRange(config.getLength(), "underground.seaInlets.length", RangeFloor.POSITIVE),
|
||||
floatRange(config.getHalfWidth(), "underground.seaInlets.halfWidth", RangeFloor.POSITIVE),
|
||||
config.getMaximumBankHeight(),
|
||||
floatRange(config.getMouthHalfWidth(), "underground.seaInlets.mouthHalfWidth", RangeFloor.POSITIVE),
|
||||
floatRange(config.getHeadHalfWidth(), "underground.seaInlets.headHalfWidth", RangeFloor.POSITIVE),
|
||||
(float) config.getTaper(), (float) config.getWidthVariation(), (float) config.getMeanderWidth(),
|
||||
intRange(config.getDepth(), "underground.seaInlets.depth", RangeFloor.POSITIVE),
|
||||
intRange(config.getHeadroom(), "underground.seaInlets.headroom", RangeFloor.NON_NEGATIVE),
|
||||
config.getRoofClearance(),
|
||||
intRange(config.getChamberRadius(), "underground.seaInlets.chamberRadius", RangeFloor.POSITIVE));
|
||||
requireWithin(inlets.halfWidth().min(), MIN_INLET_HALF_WIDTH, MAX_INLET_HALF_WIDTH, "underground.seaInlets.halfWidth", config.getHalfWidth());
|
||||
requireWithin(inlets.halfWidth().max(), MIN_INLET_HALF_WIDTH, MAX_INLET_HALF_WIDTH, "underground.seaInlets.halfWidth", config.getHalfWidth());
|
||||
config.getBankBand(), Objects.requireNonNull(config.getBankStyle(), "Hydrology underground.seaInlets.bankStyle is missing"));
|
||||
requireWithin(inlets.mouthHalfWidth().min(), MIN_INLET_MOUTH, MAX_INLET_MOUTH, "underground.seaInlets.mouthHalfWidth", config.getMouthHalfWidth());
|
||||
requireWithin(inlets.mouthHalfWidth().max(), MIN_INLET_MOUTH, MAX_INLET_MOUTH, "underground.seaInlets.mouthHalfWidth", config.getMouthHalfWidth());
|
||||
requireWithin(inlets.headHalfWidth().min(), MIN_INLET_HEAD, MAX_INLET_HEAD, "underground.seaInlets.headHalfWidth", config.getHeadHalfWidth());
|
||||
requireWithin(inlets.headHalfWidth().max(), MIN_INLET_HEAD, MAX_INLET_HEAD, "underground.seaInlets.headHalfWidth", config.getHeadHalfWidth());
|
||||
requireWithin(inlets.depth().min(), MIN_INLET_DEPTH, MAX_INLET_DEPTH, "underground.seaInlets.depth", config.getDepth());
|
||||
requireWithin(inlets.depth().max(), MIN_INLET_DEPTH, MAX_INLET_DEPTH, "underground.seaInlets.depth", config.getDepth());
|
||||
requireWithin(inlets.headroom().max(), 0, MAX_INLET_HEADROOM, "underground.seaInlets.headroom", config.getHeadroom());
|
||||
requireWithin(inlets.chamberRadius().max(), 1, MAX_INLET_CHAMBER, "underground.seaInlets.chamberRadius", config.getChamberRadius());
|
||||
if (inlets.enabled() && seaLevel > minY && seaLevel - inlets.depth().max() - INLET_SHELL - 1 <= minY) {
|
||||
throw new IllegalArgumentException("Hydrology underground.seaInlets.depth max " + inlets.depth().max()
|
||||
+ " puts the inlet floor and its seal below the world bottom " + minY + " (sea level " + seaLevel + ")");
|
||||
requireWithin(inlets.maximumBankHeight(), MIN_INLET_BANK_HEIGHT, MAX_INLET_BANK_HEIGHT, "underground.seaInlets.maximumBankHeight");
|
||||
requireScalarWithin(config.getTaper(), MIN_INLET_TAPER, MAX_INLET_TAPER, "underground.seaInlets.taper");
|
||||
requireScalarWithin(config.getWidthVariation(), 0D, MAX_INLET_WIDTH_VARIATION, "underground.seaInlets.widthVariation");
|
||||
requireScalarWithin(config.getMeanderWidth(), MIN_INLET_MEANDER_WIDTH, MAX_INLET_MEANDER_WIDTH, "underground.seaInlets.meanderWidth");
|
||||
requireWithin(inlets.bankBand(), MIN_INLET_BANK_BAND, MAX_INLET_BANK_BAND, "underground.seaInlets.bankBand");
|
||||
if (inlets.mouthHalfWidth().min() < inlets.headHalfWidth().max()) {
|
||||
throw new IllegalArgumentException("Hydrology underground.seaInlets.mouthHalfWidth min " + inlets.mouthHalfWidth().min()
|
||||
+ " must not be below headHalfWidth max " + inlets.headHalfWidth().max() + ": an inlet narrows inland");
|
||||
}
|
||||
long extent = (long) inlets.length().max() + INLET_LAST_STEP + Math.max((long) Math.ceil(inlets.halfWidth().max()),
|
||||
inlets.chamberRadius().max()) + 1L + INLET_SHELL;
|
||||
if (inlets.enabled() && seaLevel > minY && seaLevel - inlets.depth().max() - 1 <= minY) {
|
||||
throw new IllegalArgumentException("Hydrology underground.seaInlets.depth max " + inlets.depth().max()
|
||||
+ " puts the inlet floor below the world bottom " + minY + " (sea level " + seaLevel + ")");
|
||||
}
|
||||
long meander = (long) Math.ceil(Math.min(INLET_MEANDER_MAX, INLET_MEANDER_SCALE * (inlets.meanderWidth() + 1f)));
|
||||
long extent = (long) inlets.length().max() + INLET_LAST_STEP + meander + (long) Math.ceil(inlets.mouthHalfWidth().max()) + inlets.bankBand();
|
||||
if (extent > WindowKey.SIZE) {
|
||||
throw new IllegalArgumentException("Hydrology underground.seaInlets reach " + extent + " blocks from the coast (length max "
|
||||
+ inlets.length().max() + " + " + INLET_LAST_STEP + " for the last step + the wider of halfWidth max and chamberRadius max"
|
||||
+ " + " + (1 + INLET_SHELL) + " for the seal); an inlet must stay within " + WindowKey.SIZE + " blocks");
|
||||
}
|
||||
long lookups = SeaInletPlanner.lookupReach(inlets.length().max(), inlets.chamberRadius().max());
|
||||
if (lookups > WindowKey.SIZE) {
|
||||
throw new IllegalArgumentException("Hydrology underground.seaInlets planning looks " + lookups
|
||||
+ " blocks from the coast (length max " + inlets.length().max() + ", chamberRadius max " + inlets.chamberRadius().max()
|
||||
+ "); it must stay within " + WindowKey.SIZE + " blocks");
|
||||
+ inlets.length().max() + " + " + INLET_LAST_STEP + " for the last step + " + meander + " for the meander + mouthHalfWidth max "
|
||||
+ inlets.mouthHalfWidth().max() + " + bankBand " + inlets.bankBand() + "); an inlet must stay within " + WindowKey.SIZE + " blocks");
|
||||
}
|
||||
return inlets;
|
||||
}
|
||||
|
||||
private static void requireScalarWithin(double value, double min, double max, String field) {
|
||||
if (!Double.isFinite(value) || value < min || value > max) {
|
||||
throw new IllegalArgumentException("Hydrology " + field + " must stay within " + min + ".." + max + ", got " + value);
|
||||
}
|
||||
}
|
||||
|
||||
private static void requireWithin(double value, double min, double max, String field, List<? extends Number> written) {
|
||||
if (value < min || value > max) {
|
||||
throw new IllegalArgumentException("Hydrology range " + field + " must stay within " + min + ".." + max + ", got " + written);
|
||||
@@ -761,9 +794,9 @@ public final class HydrologySettings {
|
||||
SeaInlets inlets = underground.seaInlets();
|
||||
CavePools pools = underground.cavePools();
|
||||
CaveSprings springs = underground.caveSprings();
|
||||
hash.add(inlets.enabled()).add(inlets.spacing()).add(inlets.minimumCliffHeight()).add(inlets.length())
|
||||
.add(inlets.halfWidth()).add(inlets.depth()).add(inlets.headroom()).add(inlets.roofClearance())
|
||||
.add(inlets.chamberRadius())
|
||||
hash.add(inlets.enabled()).add(inlets.spacing()).add(inlets.length()).add(inlets.maximumBankHeight())
|
||||
.add(inlets.mouthHalfWidth()).add(inlets.headHalfWidth()).add(inlets.taper()).add(inlets.widthVariation())
|
||||
.add(inlets.meanderWidth()).add(inlets.depth()).add(inlets.bankBand()).add(inlets.bankStyle())
|
||||
.add(pools.enabled()).add(pools.density()).add(pools.minArea()).add(pools.maxArea())
|
||||
.add(pools.maxDepth()).add(pools.radius()).add(pools.freeboard()).add(pools.fluid())
|
||||
.add(pools.deepFluid()).add(pools.deepFluidMaxY())
|
||||
@@ -828,8 +861,9 @@ public final class HydrologySettings {
|
||||
public record Deformation(int maxFill, float bankSlope, float bankSteepFactor, float bankNoise, boolean caveMask) {
|
||||
}
|
||||
|
||||
public record SeaInlets(boolean enabled, int spacing, int minimumCliffHeight, IntRange length, FloatRange halfWidth,
|
||||
IntRange depth, IntRange headroom, int roofClearance, IntRange chamberRadius) {
|
||||
public record SeaInlets(boolean enabled, int spacing, IntRange length, int maximumBankHeight, FloatRange mouthHalfWidth,
|
||||
FloatRange headHalfWidth, float taper, float widthVariation, float meanderWidth, IntRange depth, int bankBand,
|
||||
IrisBankStyle bankStyle) {
|
||||
}
|
||||
|
||||
public record CavePools(boolean enabled, float density, int minArea, int maxArea, int maxDepth, int radius,
|
||||
|
||||
@@ -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;
|
||||
@@ -23,6 +21,7 @@ import art.arcane.iris.generation.hydrology.water.Reach;
|
||||
import art.arcane.iris.generation.hydrology.water.ReachShaper;
|
||||
import art.arcane.iris.generation.hydrology.water.ReachStyle;
|
||||
import art.arcane.iris.generation.hydrology.water.ShapedNetwork;
|
||||
import art.arcane.iris.generation.hydrology.water.TidalPlanner;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.BitSet;
|
||||
@@ -49,14 +48,14 @@ public final class WindowPlanner {
|
||||
private final HeightLattice fine;
|
||||
private final PondPlanner ponds;
|
||||
private final ReachShaper shaper;
|
||||
private final SeaInletPlanner inlets;
|
||||
private final TidalPlanner tidal;
|
||||
|
||||
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);
|
||||
this.tidal = new TidalPlanner(settings, fine);
|
||||
if (fine.cell() != FINE_CELL) {
|
||||
throw new IllegalArgumentException("Window fine lattice cell " + fine.cell() + " must be " + FINE_CELL);
|
||||
}
|
||||
@@ -131,8 +130,9 @@ 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));
|
||||
List<Reach> ownedReaches = new ArrayList<>(ownedReaches(key, reaches));
|
||||
ownedReaches.addAll(tidal.plan(key, natural, samples, network));
|
||||
WindowPlan owned = new WindowPlan(key, ownedReaches, ownedPonds(key, windowPonds));
|
||||
requireSeaConnectedHeads(owned, settings.seaLevel());
|
||||
return new WindowComputation(owned, reaches, windowPonds);
|
||||
}
|
||||
@@ -356,24 +356,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 +388,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());
|
||||
}
|
||||
|
||||
+67
-36
@@ -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,7 @@ 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 ReachCursor.Choice other = new ReachCursor.Choice();
|
||||
private final Map<Long, String> reachFluids = new HashMap<>();
|
||||
private NaturalHeights naturalHeight;
|
||||
|
||||
@@ -89,15 +88,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 +139,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) {
|
||||
@@ -176,25 +166,6 @@ final class RasterComposer {
|
||||
}
|
||||
|
||||
private void dry(int cell, int x, int z, int ground, double variation) {
|
||||
int cut = ground;
|
||||
int raise = Integer.MIN_VALUE;
|
||||
double bankEdge = Double.POSITIVE_INFINITY;
|
||||
ReachCursor.Choice bank = cursor.bank;
|
||||
if (bank.reach != null) {
|
||||
HydrologyTier bankTier = bank.reach.tier();
|
||||
int surface = brinks.head(bank);
|
||||
bankEdge = bank.distance - bank.halfWidth();
|
||||
double u = bankEdge / bankTier.bankBand();
|
||||
if (bankTier.bankStyle() != IrisBankStyle.CLIFF && bankTier.bankStyle() != IrisBankStyle.TERRACED) {
|
||||
u = BedProfile.position(u, -variation);
|
||||
}
|
||||
if (ground >= surface) {
|
||||
double cone = coneSlope(steepestToWater(x, z, bank, bankEdge)) * u * bankTier.bankBand();
|
||||
cut = BankProfile.cut(bankTier.bankStyle(), surface, ground, u, cone, noise(x, z));
|
||||
} else if (ground >= settings.seaLevel()) {
|
||||
raise = BankProfile.levee(bankTier.bankStyle(), surface, ground, u, noise(x, z), settings.deformation().maxFill());
|
||||
}
|
||||
}
|
||||
int nearPond = -1;
|
||||
double pondEdge = Double.POSITIVE_INFINITY;
|
||||
for (int index = 0; index < features.ponds(); index++) {
|
||||
@@ -204,6 +175,29 @@ final class RasterComposer {
|
||||
nearPond = index;
|
||||
}
|
||||
}
|
||||
int cut = ground;
|
||||
int raise = Integer.MIN_VALUE;
|
||||
double bankEdge = Double.POSITIVE_INFINITY;
|
||||
ReachCursor.Choice bank = cursor.bank;
|
||||
if (bank.reach != null) {
|
||||
bankEdge = bank.distance - bank.halfWidth();
|
||||
if (bank.reach.style()[0] == ReachStyle.TIDAL) {
|
||||
cut = tidalBank(bank, x, z, ground, variation, bankEdge, pondEdge);
|
||||
} else {
|
||||
HydrologyTier bankTier = bank.reach.tier();
|
||||
int surface = brinks.head(bank);
|
||||
double u = bankEdge / bankTier.bankBand();
|
||||
if (bankTier.bankStyle() != IrisBankStyle.CLIFF && bankTier.bankStyle() != IrisBankStyle.TERRACED) {
|
||||
u = BedProfile.position(u, -variation);
|
||||
}
|
||||
if (ground >= surface) {
|
||||
double cone = coneSlope(steepestToWater(x, z, bank, bankEdge)) * u * bankTier.bankBand();
|
||||
cut = BankProfile.cut(bankTier.bankStyle(), surface, ground, u, cone, noise(x, z));
|
||||
} else if (ground >= settings.seaLevel()) {
|
||||
raise = BankProfile.levee(bankTier.bankStyle(), surface, ground, u, noise(x, z), settings.deformation().maxFill());
|
||||
}
|
||||
}
|
||||
}
|
||||
int taper = settings.ponds().shore().taper();
|
||||
boolean tapered = nearPond >= 0 && pondEdge <= taper;
|
||||
if (tapered && ground > WaterHeads.standing(features.pond(nearPond).level(), settings.seaLevel())) {
|
||||
@@ -218,6 +212,47 @@ final class RasterComposer {
|
||||
nearestWater(cell, nearPond, pondEdge);
|
||||
}
|
||||
|
||||
private int tidalBank(ReachCursor.Choice bank, int x, int z, int ground, double variation, double bankEdge, double pondEdge) {
|
||||
HydrologyTier tidal = bank.reach.tier();
|
||||
int surface = brinks.head(bank);
|
||||
if (ground < surface) {
|
||||
return ground;
|
||||
}
|
||||
double band = tidal.bankBand();
|
||||
features.segments().nearestOther(x, z, bank.reach.id(), band, other);
|
||||
double otherEdge = other.reach == null ? Double.POSITIVE_INFINITY : other.distance - other.halfWidth();
|
||||
int meet = ground;
|
||||
if (other.reach != null && otherEdge <= other.reach.tier().bankBand()) {
|
||||
meet = Math.min(meet, otherBank(x, z, ground, variation, otherEdge));
|
||||
}
|
||||
double nearest = Math.min(otherEdge, pondEdge);
|
||||
double reach = nearest == Double.POSITIVE_INFINITY ? band : Math.min(band, 0.5D * (bankEdge + nearest));
|
||||
if (bankEdge >= reach) {
|
||||
return Math.max(surface, meet);
|
||||
}
|
||||
double u = bankEdge / reach;
|
||||
if (tidal.bankStyle() != IrisBankStyle.CLIFF && tidal.bankStyle() != IrisBankStyle.TERRACED) {
|
||||
u = BedProfile.position(u, -variation);
|
||||
}
|
||||
double cone = settings.deformation().bankSlope() * u * reach;
|
||||
return Math.min(ground, BankProfile.cut(tidal.bankStyle(), surface, Math.max(surface, meet), u, cone, noise(x, z)));
|
||||
}
|
||||
|
||||
private int otherBank(int x, int z, int ground, double variation, double otherEdge) {
|
||||
HydrologyTier otherTier = other.reach.tier();
|
||||
int surface = brinks.head(other);
|
||||
double u = otherEdge / otherTier.bankBand();
|
||||
if (otherTier.bankStyle() != IrisBankStyle.CLIFF && otherTier.bankStyle() != IrisBankStyle.TERRACED) {
|
||||
u = BedProfile.position(u, -variation);
|
||||
}
|
||||
if (ground < surface) {
|
||||
return ground;
|
||||
}
|
||||
boolean tidal = other.reach.style()[0] == ReachStyle.TIDAL;
|
||||
double slope = tidal ? settings.deformation().bankSlope() : coneSlope(steepestToWater(x, z, other, otherEdge));
|
||||
return BankProfile.cut(otherTier.bankStyle(), surface, ground, u, slope * u * otherTier.bankBand(), noise(x, z));
|
||||
}
|
||||
|
||||
private void nearestWater(int cell, int nearPond, double pondEdge) {
|
||||
double best = Double.POSITIVE_INFINITY;
|
||||
if (cursor.edge.reach != null) {
|
||||
@@ -334,11 +369,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 +554,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;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -141,6 +141,33 @@ final class ReachSegments {
|
||||
cursor.resolveChannel();
|
||||
}
|
||||
|
||||
void nearestOther(double x, double z, long excluded, double reach, ReachCursor.Choice out) {
|
||||
if (!sealed) {
|
||||
seal();
|
||||
}
|
||||
out.reset();
|
||||
double best = Double.POSITIVE_INFINITY;
|
||||
for (int index = 0; index < size; index++) {
|
||||
if (reaches[index].id() == excluded || beyond(x, z, Math.min(startX[index], endX[index]), Math.min(startZ[index], endZ[index]),
|
||||
Math.max(startX[index], endX[index]), Math.max(startZ[index], endZ[index]), radius[index] + reach)) {
|
||||
continue;
|
||||
}
|
||||
double ax = startX[index];
|
||||
double az = startZ[index];
|
||||
double dx = endX[index] - ax;
|
||||
double dz = endZ[index] - az;
|
||||
double length = dx * dx + dz * dz;
|
||||
double t = length == 0D ? 0D : Math.clamp(((x - ax) * dx + (z - az) * dz) / length, 0D, 1D);
|
||||
double distance = Math.hypot(x - (ax + t * dx), z - (az + t * dz));
|
||||
double edge = distance - (startWidth[index] + t * (endWidth[index] - startWidth[index]));
|
||||
if (edge < best && edge <= reach) {
|
||||
best = edge;
|
||||
out.reset();
|
||||
out.offer(reaches[index], segments[index], index, t, distance);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int coveredCell(double x, double z) {
|
||||
if (coverStarts == null) {
|
||||
return -1;
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
package art.arcane.iris.generation.hydrology.underground;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public record SeaInlet(long id, float[] xs, float[] zs, float[] halfWidth, int waterLevel, int[] floor, int[] ceiling, int chamberX,
|
||||
int chamberZ, int chamberRadius) {
|
||||
public static final int OPEN = Integer.MAX_VALUE;
|
||||
|
||||
public SeaInlet {
|
||||
int stations = xs.length;
|
||||
if (stations < 2 || zs.length != stations || halfWidth.length != stations || floor.length != stations || ceiling.length != stations) {
|
||||
throw new IllegalArgumentException("Sea inlet " + id + " needs at least two stations and matching arrays: xs=" + xs.length
|
||||
+ " zs=" + zs.length + " halfWidth=" + halfWidth.length + " floor=" + floor.length + " ceiling=" + ceiling.length);
|
||||
}
|
||||
if (chamberRadius <= 0) {
|
||||
throw new IllegalArgumentException("Sea inlet " + id + " needs a positive chamber radius, got " + chamberRadius);
|
||||
}
|
||||
for (int station = 0; station < stations; station++) {
|
||||
if (!(halfWidth[station] > 0f) || floor[station] >= waterLevel || ceiling[station] < waterLevel) {
|
||||
throw new IllegalArgumentException("Sea inlet " + id + " station " + station + " has half-width " + halfWidth[station]
|
||||
+ ", floor " + floor[station] + " and ceiling " + ceiling[station] + " around water level " + waterLevel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int stations() {
|
||||
return xs.length;
|
||||
}
|
||||
|
||||
public boolean open(int station) {
|
||||
return ceiling[station] == OPEN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
return other instanceof SeaInlet inlet && id == inlet.id && waterLevel == inlet.waterLevel && chamberX == inlet.chamberX
|
||||
&& chamberZ == inlet.chamberZ && chamberRadius == inlet.chamberRadius && Arrays.equals(xs, inlet.xs)
|
||||
&& Arrays.equals(zs, inlet.zs) && Arrays.equals(halfWidth, inlet.halfWidth) && Arrays.equals(floor, inlet.floor)
|
||||
&& Arrays.equals(ceiling, inlet.ceiling);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 31 * Long.hashCode(id) + waterLevel;
|
||||
hash = 31 * hash + chamberX;
|
||||
hash = 31 * hash + chamberZ;
|
||||
hash = 31 * hash + chamberRadius;
|
||||
hash = 31 * hash + Arrays.hashCode(xs);
|
||||
hash = 31 * hash + Arrays.hashCode(zs);
|
||||
hash = 31 * hash + Arrays.hashCode(halfWidth);
|
||||
hash = 31 * hash + Arrays.hashCode(floor);
|
||||
return 31 * hash + Arrays.hashCode(ceiling);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
int last = xs.length - 1;
|
||||
return "SeaInlet[id=" + id + ", stations=" + xs.length + ", mouth=" + xs[0] + "," + zs[0] + ", end=" + xs[last] + "," + zs[last]
|
||||
+ ", waterLevel=" + waterLevel + ", chamber=" + chamberX + "," + chamberZ + " r" + chamberRadius + "]";
|
||||
}
|
||||
}
|
||||
-72
@@ -1,72 +0,0 @@
|
||||
package art.arcane.iris.generation.hydrology.underground;
|
||||
|
||||
final class SeaInletFootprint {
|
||||
private static final byte OPEN = 1;
|
||||
private static final byte COVERED = 2;
|
||||
private static final int SHELL = SeaInletRasterizer.SHELL;
|
||||
|
||||
private final int minX;
|
||||
private final int minZ;
|
||||
private final int maxX;
|
||||
private final int maxZ;
|
||||
private final byte[] kinds;
|
||||
|
||||
private SeaInletFootprint(SeaInlet inlet) {
|
||||
int[] bounds = SeaInletRasterizer.bounds(inlet);
|
||||
this.minX = bounds[0];
|
||||
this.minZ = bounds[1];
|
||||
this.maxX = bounds[2];
|
||||
this.maxZ = bounds[3];
|
||||
this.kinds = new byte[(maxX - minX + 1) * (maxZ - minZ + 1)];
|
||||
int[] column = new int[2];
|
||||
for (int z = minZ; z <= maxZ; z++) {
|
||||
for (int x = minX; x <= maxX; x++) {
|
||||
if (SeaInletRasterizer.column(inlet, x, z, column)) {
|
||||
kinds[index(x, z)] = column[1] == SeaInlet.OPEN ? OPEN : COVERED;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static SeaInletFootprint of(SeaInlet inlet) {
|
||||
return new SeaInletFootprint(inlet);
|
||||
}
|
||||
|
||||
boolean conflicts(SeaInletFootprint other) {
|
||||
return opensBeside(this, other) || opensBeside(other, this);
|
||||
}
|
||||
|
||||
private static boolean opensBeside(SeaInletFootprint open, SeaInletFootprint covered) {
|
||||
int fromX = Math.max(open.minX, covered.minX - SHELL);
|
||||
int toX = Math.min(open.maxX, covered.maxX + SHELL);
|
||||
int fromZ = Math.max(open.minZ, covered.minZ - SHELL);
|
||||
int toZ = Math.min(open.maxZ, covered.maxZ + SHELL);
|
||||
for (int z = fromZ; z <= toZ; z++) {
|
||||
for (int x = fromX; x <= toX; x++) {
|
||||
if (open.kind(x, z) == OPEN && covered.coveredNear(x, z)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean coveredNear(int x, int z) {
|
||||
for (int dz = -SHELL; dz <= SHELL; dz++) {
|
||||
for (int dx = -SHELL; dx <= SHELL; dx++) {
|
||||
if (kind(x + dx, z + dz) == COVERED) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private byte kind(int x, int z) {
|
||||
return x < minX || x > maxX || z < minZ || z > maxZ ? 0 : kinds[index(x, z)];
|
||||
}
|
||||
|
||||
private int index(int x, int z) {
|
||||
return (z - minZ) * (maxX - minX + 1) + x - minX;
|
||||
}
|
||||
}
|
||||
-583
@@ -1,583 +0,0 @@
|
||||
package art.arcane.iris.generation.hydrology.underground;
|
||||
|
||||
import art.arcane.iris.generation.hydrology.grid.CellHash;
|
||||
import art.arcane.iris.generation.hydrology.grid.DemGrid;
|
||||
import art.arcane.iris.generation.hydrology.grid.HydrologySampleBuffer;
|
||||
import art.arcane.iris.generation.hydrology.plan.HydrologySettings;
|
||||
import art.arcane.iris.generation.hydrology.plan.WindowKey;
|
||||
import art.arcane.iris.generation.hydrology.plan.WindowPlanner;
|
||||
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.ShapedNetwork;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public final class SeaInletPlanner {
|
||||
private static final int ROOF_MARGIN = 2;
|
||||
private static final int OPEN_LAND_STATIONS = 2;
|
||||
private static final int STEP_LOOKUP_CELLS = 2;
|
||||
private static final float NOISE_STEP = 32f;
|
||||
private static final int CONTAINMENT = 2;
|
||||
private static final float WET_SLACK = CONTAINMENT + 1 + 6f;
|
||||
private static final int[] SIDE_I = {1, -1, 0, 0};
|
||||
private static final int[] SIDE_J = {0, 0, 1, -1};
|
||||
private static final long SALT_ID = 0x5345414e4c4554L;
|
||||
private static final long SALT_SITE_X = 0x53454153495458L;
|
||||
private static final long SALT_SITE_Z = 0x5345415349545aL;
|
||||
private static final long SALT_LENGTH = 0x5345414c454e47L;
|
||||
private static final long SALT_RADIUS = 0x53454152414449L;
|
||||
private static final long SALT_HEADROOM = 0x53454148454144L;
|
||||
private static final long SALT_DEPTH = 0x53454144455054L;
|
||||
private static final long SALT_DENSITY = 0x53454144454e53L;
|
||||
private static final double SQUARED_MARGIN = 1e-9D;
|
||||
|
||||
private final HydrologySettings settings;
|
||||
|
||||
public SeaInletPlanner(HydrologySettings settings) {
|
||||
this.settings = Objects.requireNonNull(settings, "settings");
|
||||
}
|
||||
|
||||
public static long lookupReach(int lengthMax, int chamberRadiusMax) {
|
||||
int cell = WindowPlanner.CELL;
|
||||
long farthestStation = cell * (long) Math.floor((lengthMax + cell * Math.sqrt(2D) - cell) / cell);
|
||||
return farthestStation + (long) cell * Math.max(STEP_LOOKUP_CELLS, chamberRing(chamberRadiusMax, cell));
|
||||
}
|
||||
|
||||
public List<SeaInlet> plan(WindowKey window, DemGrid raw, HydrologySampleBuffer samples, int[] receivers, float[] accumulation,
|
||||
ShapedNetwork network, long seed) {
|
||||
Objects.requireNonNull(window, "window");
|
||||
HydrologySettings.SeaInlets config = settings.underground().seaInlets();
|
||||
if (!config.enabled() || settings.density() == 0f) {
|
||||
return List.of();
|
||||
}
|
||||
int count = raw.values().length;
|
||||
if (samples.height().length < count || receivers.length != count || accumulation.length != count) {
|
||||
throw new IllegalArgumentException("Sea inlet planning needs " + count + " cells, got samples=" + samples.height().length
|
||||
+ " receivers=" + receivers.length + " accumulation=" + accumulation.length);
|
||||
}
|
||||
Terrain terrain = new Terrain(raw, samples, receivers, accumulation, cover(raw, samples.height(), network), seed);
|
||||
List<Traced> traced = new ArrayList<>();
|
||||
for (Map.Entry<Long, List<Integer>> site : sites(terrain, config).entrySet()) {
|
||||
SeaInlet inlet = site(terrain, config, site.getKey(), site.getValue());
|
||||
if (inlet == null) {
|
||||
continue;
|
||||
}
|
||||
if (terrain.clipped && window.equals(owner(inlet))) {
|
||||
throw new IllegalStateException("Sea inlet " + inlet.id() + " of window " + window
|
||||
+ " reaches the edge of the window's planning span");
|
||||
}
|
||||
traced.add(new Traced(inlet, !terrain.clipped));
|
||||
}
|
||||
traced.sort(Comparator.comparingLong((Traced entry) -> entry.inlet().id()).thenComparingDouble(entry -> entry.inlet().xs()[0])
|
||||
.thenComparingDouble(entry -> entry.inlet().zs()[0]));
|
||||
return separated(traced);
|
||||
}
|
||||
|
||||
private static List<SeaInlet> separated(List<Traced> traced) {
|
||||
List<SeaInletFootprint> footprints = new ArrayList<>(traced.size());
|
||||
for (Traced entry : traced) {
|
||||
footprints.add(SeaInletFootprint.of(entry.inlet()));
|
||||
}
|
||||
List<SeaInlet> kept = new ArrayList<>(traced.size());
|
||||
for (int index = 0; index < traced.size(); index++) {
|
||||
boolean yields = false;
|
||||
for (int earlier = 0; earlier < index && !yields; earlier++) {
|
||||
yields = footprints.get(earlier).conflicts(footprints.get(index));
|
||||
}
|
||||
if (!yields && traced.get(index).whole()) {
|
||||
kept.add(traced.get(index).inlet());
|
||||
}
|
||||
}
|
||||
return List.copyOf(kept);
|
||||
}
|
||||
|
||||
private Map<Long, List<Integer>> sites(Terrain terrain, HydrologySettings.SeaInlets config) {
|
||||
Map<Long, List<Integer>> sites = new TreeMap<>();
|
||||
DemGrid grid = terrain.grid;
|
||||
float cliff = settings.seaLevel() + config.minimumCliffHeight();
|
||||
for (int j = 1; j < grid.depth() - 1; j++) {
|
||||
for (int i = 1; i < grid.width() - 1; i++) {
|
||||
int cell = grid.index(i, j);
|
||||
if (terrain.ocean(cell) || terrain.natural(cell) < cliff || mouth(terrain, cell) < 0) {
|
||||
continue;
|
||||
}
|
||||
long key = siteKey(Math.floorDiv(grid.blockX(cell), config.spacing()), Math.floorDiv(grid.blockZ(cell), config.spacing()));
|
||||
sites.computeIfAbsent(key, ignored -> new ArrayList<>()).add(cell);
|
||||
}
|
||||
}
|
||||
return sites;
|
||||
}
|
||||
|
||||
private SeaInlet site(Terrain terrain, HydrologySettings.SeaInlets config, long key, List<Integer> candidates) {
|
||||
int siteX = (int) (key >> 32);
|
||||
int siteZ = (int) key;
|
||||
if (settings.density() < 1f && CellHash.unit(CellHash.mix(terrain.seed, SALT_DENSITY, siteX, siteZ)) >= settings.density()) {
|
||||
return null;
|
||||
}
|
||||
double targetX = (siteX + CellHash.unit(CellHash.mix(terrain.seed, SALT_SITE_X, siteX, siteZ))) * config.spacing();
|
||||
double targetZ = (siteZ + CellHash.unit(CellHash.mix(terrain.seed, SALT_SITE_Z, siteX, siteZ))) * config.spacing();
|
||||
DemGrid grid = terrain.grid;
|
||||
WindowKey owner = WindowKey.containing((int) Math.floor(targetX), (int) Math.floor(targetZ));
|
||||
terrain.clipped = siteTouchesBorder(terrain, config, siteX, siteZ, owner);
|
||||
List<Integer> ordered = new ArrayList<>(candidates.size());
|
||||
for (int candidate : candidates) {
|
||||
if (owner.equals(WindowKey.containing(grid.blockX(candidate), grid.blockZ(candidate)))) {
|
||||
ordered.add(candidate);
|
||||
}
|
||||
}
|
||||
ordered.sort(Comparator.comparingDouble((Integer cell) -> distanceSquared(grid, cell, targetX, targetZ)).thenComparingInt(cell -> cell));
|
||||
for (int candidate : ordered) {
|
||||
SeaInlet inlet = trace(terrain, config, candidate);
|
||||
if (inlet != null) {
|
||||
return inlet;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private SeaInlet trace(Terrain terrain, HydrologySettings.SeaInlets config, int land) {
|
||||
DemGrid grid = terrain.grid;
|
||||
int mouth = mouth(terrain, land);
|
||||
if (!openable(terrain, mouth)) {
|
||||
return null;
|
||||
}
|
||||
float target = lerp(config.length().min(), config.length().max(), unit(terrain, SALT_LENGTH, land));
|
||||
List<Integer> path = new ArrayList<>();
|
||||
List<Boolean> open = new ArrayList<>();
|
||||
path.add(mouth);
|
||||
open.add(true);
|
||||
int current = land;
|
||||
float length = 0f;
|
||||
int openStations = 0;
|
||||
boolean covered = false;
|
||||
while (current >= 0 && length < target) {
|
||||
if (canCover(terrain, config, current)) {
|
||||
covered = true;
|
||||
} else if (covered || openStations >= OPEN_LAND_STATIONS || !openable(terrain, current)) {
|
||||
break;
|
||||
} else {
|
||||
openStations++;
|
||||
}
|
||||
length += step(grid, path.get(path.size() - 1), current);
|
||||
path.add(current);
|
||||
open.add(!covered);
|
||||
int next = upstream(terrain, mouth, current, path);
|
||||
current = next >= 0 ? next : inland(terrain, config, mouth, current, path);
|
||||
}
|
||||
while (covered && path.size() > 2 && !open.get(path.size() - 1)) {
|
||||
if (pathLength(grid, path) < config.length().min()) {
|
||||
return null;
|
||||
}
|
||||
SeaInlet inlet = build(terrain, config, path, open);
|
||||
if (inlet != null) {
|
||||
return inlet;
|
||||
}
|
||||
path.remove(path.size() - 1);
|
||||
open.remove(open.size() - 1);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private SeaInlet build(Terrain terrain, HydrologySettings.SeaInlets config, List<Integer> path, List<Boolean> open) {
|
||||
DemGrid grid = terrain.grid;
|
||||
int stations = path.size();
|
||||
int mouth = path.get(0);
|
||||
int land = path.get(1);
|
||||
int end = path.get(stations - 1);
|
||||
int water = settings.seaLevel();
|
||||
float chamberCapacity = Float.NaN;
|
||||
int radius = 0;
|
||||
int preferred = Math.round(lerp(config.chamberRadius().min(), config.chamberRadius().max(), unit(terrain, SALT_RADIUS, end)));
|
||||
for (int candidate : new int[]{preferred, config.chamberRadius().min()}) {
|
||||
float capacity = capacity(terrain, config, end, chamberRing(candidate, grid.cell()));
|
||||
if (capacity - water >= config.headroom().min()) {
|
||||
radius = candidate;
|
||||
chamberCapacity = capacity;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (radius == 0) {
|
||||
return null;
|
||||
}
|
||||
float[] capacity = new float[stations];
|
||||
for (int station = 0; station < stations; station++) {
|
||||
capacity[station] = open.get(station) ? Float.POSITIVE_INFINITY
|
||||
: station == stations - 1 ? chamberCapacity : capacity(terrain, config, path.get(station), 1);
|
||||
}
|
||||
float total = pathLength(grid, path);
|
||||
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];
|
||||
float travelled = 0f;
|
||||
HydrologySettings.FloatRange widths = config.halfWidth();
|
||||
for (int station = 0; station < stations; station++) {
|
||||
int cell = path.get(station);
|
||||
if (station > 0) {
|
||||
travelled += step(grid, path.get(station - 1), cell);
|
||||
}
|
||||
xs[station] = grid.blockX(cell);
|
||||
zs[station] = grid.blockZ(cell);
|
||||
halfWidth[station] = widths.max() - (widths.max() - widths.min()) * (travelled / total);
|
||||
floor[station] = water - Math.round(lerp(config.depth().min(), config.depth().max(), smooth(terrain, SALT_DEPTH, land, travelled)));
|
||||
if (open.get(station)) {
|
||||
ceiling[station] = SeaInlet.OPEN;
|
||||
continue;
|
||||
}
|
||||
float room = capacity[station];
|
||||
if (station > 0) {
|
||||
room = Math.min(room, capacity[station - 1]);
|
||||
}
|
||||
if (station + 1 < stations) {
|
||||
room = Math.min(room, capacity[station + 1]);
|
||||
}
|
||||
float headroom = lerp(config.headroom().min(), config.headroom().max(), smooth(terrain, SALT_HEADROOM, land, travelled));
|
||||
ceiling[station] = water + (int) Math.floor(Math.min(headroom, room - water));
|
||||
}
|
||||
long id = CellHash.mix(CellHash.mix(terrain.seed, SALT_ID, grid.blockX(mouth), grid.blockZ(mouth)), SALT_ID, grid.blockX(land),
|
||||
grid.blockZ(land));
|
||||
return new SeaInlet(id, xs, zs, halfWidth, water, floor, ceiling, grid.blockX(end), grid.blockZ(end), radius);
|
||||
}
|
||||
|
||||
private static double smooth(Terrain terrain, long salt, int land, float distance) {
|
||||
float position = distance / NOISE_STEP;
|
||||
int knot = (int) Math.floor(position);
|
||||
double fraction = position - knot;
|
||||
double eased = fraction * fraction * (3D - 2D * fraction);
|
||||
long base = CellHash.mix(terrain.seed, salt, terrain.grid.blockX(land), terrain.grid.blockZ(land));
|
||||
double from = CellHash.unit(CellHash.mix(base, salt, knot, 0));
|
||||
double to = CellHash.unit(CellHash.mix(base, salt, knot + 1, 0));
|
||||
return from + (to - from) * eased;
|
||||
}
|
||||
|
||||
private boolean canCover(Terrain terrain, HydrologySettings.SeaInlets config, int cell) {
|
||||
return capacity(terrain, config, cell, 1) - settings.seaLevel() >= config.headroom().min();
|
||||
}
|
||||
|
||||
private static float capacity(Terrain terrain, HydrologySettings.SeaInlets config, int cell, int ring) {
|
||||
DemGrid grid = terrain.grid;
|
||||
int i = cell % grid.width();
|
||||
int j = cell / grid.width();
|
||||
float lowest = Float.POSITIVE_INFINITY;
|
||||
boolean outside = false;
|
||||
for (int dj = -ring; dj <= ring; dj++) {
|
||||
for (int di = -ring; di <= ring; di++) {
|
||||
int ni = i + di;
|
||||
int nj = j + dj;
|
||||
if (ni < 0 || nj < 0 || ni >= grid.width() || nj >= grid.depth()) {
|
||||
outside = true;
|
||||
continue;
|
||||
}
|
||||
int neighbour = grid.index(ni, nj);
|
||||
if (terrain.ocean(neighbour)) {
|
||||
return Float.NEGATIVE_INFINITY;
|
||||
}
|
||||
lowest = Math.min(lowest, terrain.cover[neighbour]);
|
||||
}
|
||||
}
|
||||
if (outside) {
|
||||
terrain.clipped = true;
|
||||
return Float.NEGATIVE_INFINITY;
|
||||
}
|
||||
return lowest - config.roofClearance() - ROOF_MARGIN;
|
||||
}
|
||||
|
||||
private static boolean openable(Terrain terrain, int cell) {
|
||||
DemGrid grid = terrain.grid;
|
||||
int i = cell % grid.width();
|
||||
int j = cell / grid.width();
|
||||
boolean outside = false;
|
||||
for (int dj = -1; dj <= 1; dj++) {
|
||||
for (int di = -1; di <= 1; di++) {
|
||||
int ni = i + di;
|
||||
int nj = j + dj;
|
||||
if (ni < 0 || nj < 0 || ni >= grid.width() || nj >= grid.depth()) {
|
||||
outside = true;
|
||||
} else if (terrain.wet(grid.index(ni, nj))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
terrain.clipped |= outside;
|
||||
return !outside;
|
||||
}
|
||||
|
||||
private static int mouth(Terrain terrain, int land) {
|
||||
int receiver = terrain.receivers[land];
|
||||
if (receiver >= 0 && terrain.ocean(receiver)) {
|
||||
return receiver;
|
||||
}
|
||||
DemGrid grid = terrain.grid;
|
||||
int i = land % grid.width();
|
||||
int j = land / grid.width();
|
||||
for (int side = 0; side < SIDE_I.length; side++) {
|
||||
int ni = i + SIDE_I[side];
|
||||
int nj = j + SIDE_J[side];
|
||||
if (ni >= 0 && nj >= 0 && ni < grid.width() && nj < grid.depth() && terrain.ocean(grid.index(ni, nj))) {
|
||||
return grid.index(ni, nj);
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
private static int upstream(Terrain terrain, int mouth, int cell, List<Integer> path) {
|
||||
DemGrid grid = terrain.grid;
|
||||
int i = cell % grid.width();
|
||||
int j = cell / grid.width();
|
||||
double away = distanceSquared(grid, cell, grid.blockX(mouth), grid.blockZ(mouth));
|
||||
int best = -1;
|
||||
for (int dj = -1; dj <= 1; dj++) {
|
||||
for (int di = -1; di <= 1; di++) {
|
||||
int neighbour = onward(terrain, mouth, i + di, j + dj, away, path);
|
||||
if (neighbour < 0 || terrain.receivers[neighbour] != cell) {
|
||||
continue;
|
||||
}
|
||||
if (best < 0 || terrain.accumulation[neighbour] > terrain.accumulation[best]
|
||||
|| terrain.accumulation[neighbour] == terrain.accumulation[best] && neighbour < best) {
|
||||
best = neighbour;
|
||||
}
|
||||
}
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
private int inland(Terrain terrain, HydrologySettings.SeaInlets config, int mouth, int cell, List<Integer> path) {
|
||||
DemGrid grid = terrain.grid;
|
||||
int i = cell % grid.width();
|
||||
int j = cell / grid.width();
|
||||
double away = distanceSquared(grid, cell, grid.blockX(mouth), grid.blockZ(mouth));
|
||||
int best = -1;
|
||||
boolean bestCovers = false;
|
||||
double bestAway = 0D;
|
||||
for (int dj = -1; dj <= 1; dj++) {
|
||||
for (int di = -1; di <= 1; di++) {
|
||||
int neighbour = onward(terrain, mouth, i + di, j + dj, away, path);
|
||||
if (neighbour < 0) {
|
||||
continue;
|
||||
}
|
||||
double distance = distanceSquared(grid, neighbour, grid.blockX(mouth), grid.blockZ(mouth));
|
||||
boolean covers = canCover(terrain, config, neighbour);
|
||||
if (best < 0 || covers && !bestCovers || covers == bestCovers && (distance > bestAway
|
||||
|| distance == bestAway && terrain.cover[neighbour] > terrain.cover[best])) {
|
||||
best = neighbour;
|
||||
bestCovers = covers;
|
||||
bestAway = distance;
|
||||
}
|
||||
}
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
private Cover cover(DemGrid grid, float[] natural, ShapedNetwork network) {
|
||||
int count = grid.values().length;
|
||||
float[] cover = new float[count];
|
||||
System.arraycopy(natural, 0, cover, 0, count);
|
||||
boolean[] wet = new boolean[count];
|
||||
for (Reach reach : network.reaches()) {
|
||||
int band = reach.tier().bankBand() + CONTAINMENT + grid.cell();
|
||||
for (int point = 0; point + 1 < reach.xs().length; point++) {
|
||||
float bed = Math.min(reach.grade()[point] - reach.depth()[point], reach.grade()[point + 1] - reach.depth()[point + 1]) - 1f;
|
||||
float water = Math.max(reach.halfWidth()[point], reach.halfWidth()[point + 1]);
|
||||
splat(grid, cover, wet, reach.xs()[point], reach.zs()[point], reach.xs()[point + 1], reach.zs()[point + 1], water + band,
|
||||
water + WET_SLACK, bed);
|
||||
}
|
||||
}
|
||||
HydrologySettings.PondShore shore = settings.ponds().shore();
|
||||
for (Pond pond : network.ponds()) {
|
||||
PondMask mask = pond.mask();
|
||||
float bed = Math.min(pond.floor(), pond.level() - shore.maxDepth()) - 1f;
|
||||
float radius = 2f * mask.step() + shore.taper() + CONTAINMENT + grid.cell();
|
||||
float water = 1.5f * mask.step() + WET_SLACK;
|
||||
for (int nj = 0; nj < mask.depth(); nj++) {
|
||||
for (int ni = 0; ni < mask.width(); ni++) {
|
||||
if (mask.node(ni, nj)) {
|
||||
float x = mask.originX() + ni * mask.step();
|
||||
float z = mask.originZ() + nj * mask.step();
|
||||
splat(grid, cover, wet, x, z, x, z, radius, water, bed);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return new Cover(cover, wet);
|
||||
}
|
||||
|
||||
private static void splat(DemGrid grid, float[] cover, boolean[] wet, float ax, float az, float bx, float bz, float radius, float wetRadius,
|
||||
float bed) {
|
||||
int cell = grid.cell();
|
||||
int minI = Math.max(0, (int) Math.floor((Math.min(ax, bx) - radius - grid.originX()) / cell));
|
||||
int maxI = Math.min(grid.width() - 1, (int) Math.ceil((Math.max(ax, bx) + radius - grid.originX()) / cell));
|
||||
int minJ = Math.max(0, (int) Math.floor((Math.min(az, bz) - radius - grid.originZ()) / cell));
|
||||
int maxJ = Math.min(grid.depth() - 1, (int) Math.ceil((Math.max(az, bz) + radius - grid.originZ()) / cell));
|
||||
double dx = bx - ax;
|
||||
double dz = bz - az;
|
||||
double span = dx * dx + dz * dz;
|
||||
double outside = radius > 0f ? squaredAbove(radius) : Double.POSITIVE_INFINITY;
|
||||
double inside = radius > 0f ? squaredBelow(radius) : Double.NEGATIVE_INFINITY;
|
||||
double wetOutside = wetRadius > 0f ? squaredAbove(wetRadius) : Double.POSITIVE_INFINITY;
|
||||
double wetInside = wetRadius > 0f ? squaredBelow(wetRadius) : Double.NEGATIVE_INFINITY;
|
||||
for (int j = minJ; j <= maxJ; j++) {
|
||||
double pz = grid.originZ() + (double) j * cell;
|
||||
for (int i = minI; i <= maxI; i++) {
|
||||
double px = grid.originX() + (double) i * cell;
|
||||
double t = span <= 0D ? 0D : Math.clamp(((px - ax) * dx + (pz - az) * dz) / span, 0D, 1D);
|
||||
double ex = px - (ax + t * dx);
|
||||
double ez = pz - (az + t * dz);
|
||||
double squared = ex * ex + ez * ez;
|
||||
if (squared > outside || !(squared < inside) && Math.hypot(ex, ez) > radius) {
|
||||
continue;
|
||||
}
|
||||
int index = j * grid.width() + i;
|
||||
cover[index] = Math.min(cover[index], bed);
|
||||
wet[index] |= squared < wetInside || !(squared > wetOutside) && Math.hypot(ex, ez) <= wetRadius;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static int onward(Terrain terrain, int mouth, int ni, int nj, double away, List<Integer> path) {
|
||||
DemGrid grid = terrain.grid;
|
||||
if (ni < 0 || nj < 0 || ni >= grid.width() || nj >= grid.depth()) {
|
||||
terrain.clipped = true;
|
||||
return -1;
|
||||
}
|
||||
int neighbour = grid.index(ni, nj);
|
||||
if (terrain.ocean(neighbour) || path.contains(neighbour)
|
||||
|| distanceSquared(grid, neighbour, grid.blockX(mouth), grid.blockZ(mouth)) <= away) {
|
||||
return -1;
|
||||
}
|
||||
if (ni == 0 || nj == 0 || ni == grid.width() - 1 || nj == grid.depth() - 1) {
|
||||
terrain.clipped = true;
|
||||
return -1;
|
||||
}
|
||||
return neighbour;
|
||||
}
|
||||
|
||||
private boolean siteTouchesBorder(Terrain terrain, HydrologySettings.SeaInlets config, int siteX, int siteZ, WindowKey owner) {
|
||||
DemGrid grid = terrain.grid;
|
||||
CellRange columns = siteCells(siteX, config.spacing(), owner.wx(), grid.originX(), grid.cell());
|
||||
CellRange rows = siteCells(siteZ, config.spacing(), owner.wz(), grid.originZ(), grid.cell());
|
||||
int lastColumn = grid.width() - 1;
|
||||
int lastRow = grid.depth() - 1;
|
||||
if (columns.first() < 0L || rows.first() < 0L || columns.last() > lastColumn || rows.last() > lastRow) {
|
||||
return true;
|
||||
}
|
||||
float cliff = settings.seaLevel() + config.minimumCliffHeight();
|
||||
for (int i = (int) columns.first(); i <= columns.last(); i++) {
|
||||
if (rows.first() == 0L && cliffLand(terrain, i, 0, cliff) || rows.last() == lastRow && cliffLand(terrain, i, lastRow, cliff)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
for (int j = (int) rows.first(); j <= rows.last(); j++) {
|
||||
if (columns.first() == 0L && cliffLand(terrain, 0, j, cliff)
|
||||
|| columns.last() == lastColumn && cliffLand(terrain, lastColumn, j, cliff)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static CellRange siteCells(int site, int spacing, int window, int origin, int cell) {
|
||||
long from = Math.max((long) site * spacing, (long) window * WindowKey.SIZE);
|
||||
long to = Math.min(((long) site + 1L) * spacing, ((long) window + 1L) * WindowKey.SIZE);
|
||||
return new CellRange(Math.ceilDiv(from - origin, cell), Math.ceilDiv(to - origin, cell) - 1L);
|
||||
}
|
||||
|
||||
private static boolean cliffLand(Terrain terrain, int i, int j, float cliff) {
|
||||
int cell = terrain.grid.index(i, j);
|
||||
return !terrain.ocean(cell) && terrain.natural(cell) >= cliff;
|
||||
}
|
||||
|
||||
private static int chamberRing(int radius, int cell) {
|
||||
return (radius + cell - 1) / cell + 1;
|
||||
}
|
||||
|
||||
private static WindowKey owner(SeaInlet inlet) {
|
||||
return WindowKey.containing((int) Math.floor(inlet.xs()[1]), (int) Math.floor(inlet.zs()[1]));
|
||||
}
|
||||
|
||||
private static double squaredAbove(float radius) {
|
||||
return (double) radius * radius * (1D + SQUARED_MARGIN);
|
||||
}
|
||||
|
||||
private static double squaredBelow(float radius) {
|
||||
return (double) radius * radius * (1D - SQUARED_MARGIN);
|
||||
}
|
||||
|
||||
private static float pathLength(DemGrid grid, List<Integer> path) {
|
||||
float length = 0f;
|
||||
for (int station = 1; station < path.size(); station++) {
|
||||
length += step(grid, path.get(station - 1), path.get(station));
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
private static float step(DemGrid grid, int from, int to) {
|
||||
return (float) Math.hypot(grid.blockX(to) - grid.blockX(from), grid.blockZ(to) - grid.blockZ(from));
|
||||
}
|
||||
|
||||
private static double distanceSquared(DemGrid grid, int cell, double x, double z) {
|
||||
double dx = grid.blockX(cell) - x;
|
||||
double dz = grid.blockZ(cell) - z;
|
||||
return dx * dx + dz * dz;
|
||||
}
|
||||
|
||||
private static double unit(Terrain terrain, long salt, int cell) {
|
||||
return CellHash.unit(CellHash.mix(terrain.seed, salt, terrain.grid.blockX(cell), terrain.grid.blockZ(cell)));
|
||||
}
|
||||
|
||||
private static float lerp(float min, float max, double unit) {
|
||||
return (float) (min + (max - min) * unit);
|
||||
}
|
||||
|
||||
private static long siteKey(int siteX, int siteZ) {
|
||||
return ((long) siteX << 32) | (siteZ & 0xFFFFFFFFL);
|
||||
}
|
||||
|
||||
private record Cover(float[] cover, boolean[] wet) {
|
||||
}
|
||||
|
||||
private record Traced(SeaInlet inlet, boolean whole) {
|
||||
}
|
||||
|
||||
private record CellRange(long first, long last) {
|
||||
}
|
||||
|
||||
private static final class Terrain {
|
||||
private final DemGrid grid;
|
||||
private final HydrologySampleBuffer samples;
|
||||
private final int[] receivers;
|
||||
private final float[] accumulation;
|
||||
private final float[] cover;
|
||||
private final boolean[] wet;
|
||||
private final long seed;
|
||||
private boolean clipped;
|
||||
|
||||
private Terrain(DemGrid grid, HydrologySampleBuffer samples, int[] receivers, float[] accumulation, Cover cover, long seed) {
|
||||
this.grid = grid;
|
||||
this.samples = samples;
|
||||
this.receivers = receivers;
|
||||
this.accumulation = accumulation;
|
||||
this.cover = cover.cover();
|
||||
this.wet = cover.wet();
|
||||
this.seed = seed;
|
||||
}
|
||||
|
||||
private boolean ocean(int cell) {
|
||||
return samples.ocean()[cell];
|
||||
}
|
||||
|
||||
private float natural(int cell) {
|
||||
return samples.height()[cell];
|
||||
}
|
||||
|
||||
private boolean wet(int cell) {
|
||||
return wet[cell];
|
||||
}
|
||||
}
|
||||
}
|
||||
-232
@@ -1,232 +0,0 @@
|
||||
package art.arcane.iris.generation.hydrology.underground;
|
||||
|
||||
import art.arcane.iris.generation.hydrology.cave.HydrologyCaveAction;
|
||||
import art.arcane.iris.generation.hydrology.cave.HydrologyCaveCell;
|
||||
import art.arcane.iris.generation.mantle.MantleWriter;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public final class SeaInletRasterizer {
|
||||
public static final int SHELL = 2;
|
||||
private static final int CHUNK = 16;
|
||||
private static final int GRID = CHUNK + 2 * SHELL;
|
||||
static final int NONE = Integer.MIN_VALUE;
|
||||
|
||||
public void write(SeaInlet inlet, int chunkX, int chunkZ, MantleWriter writer, String fluid, SubterrainFluid subterrain,
|
||||
HistoricalChunks historical) {
|
||||
if (!touches(inlet, chunkX, chunkZ)) {
|
||||
return;
|
||||
}
|
||||
int[] floors = new int[GRID * GRID];
|
||||
int[] ceilings = new int[GRID * GRID];
|
||||
if (!shape(inlet, (chunkX << 4) - SHELL, (chunkZ << 4) - SHELL, GRID, floors, ceilings)) {
|
||||
return;
|
||||
}
|
||||
HydrologyCaveCell wet = new HydrologyCaveCell(HydrologyCaveAction.WET_SOURCE, fluid);
|
||||
HydrologyCaveCell dry = new HydrologyCaveCell(HydrologyCaveAction.DRY_AIR, fluid);
|
||||
HydrologyCaveCell guard = new HydrologyCaveCell(HydrologyCaveAction.SEAL_GUARD, fluid);
|
||||
int water = inlet.waterLevel();
|
||||
boolean[] historicalAround = historicalAround(chunkX, chunkZ, historical);
|
||||
for (int lz = 0; lz < CHUNK; lz++) {
|
||||
for (int lx = 0; lx < CHUNK; lx++) {
|
||||
int cell = (lz + SHELL) * GRID + lx + SHELL;
|
||||
int x = (chunkX << 4) + lx;
|
||||
int z = (chunkZ << 4) + lz;
|
||||
int low = nearby(floors, GRID, cell, true);
|
||||
if (low == NONE) {
|
||||
continue;
|
||||
}
|
||||
int floor = floors[cell];
|
||||
if (floor == NONE) {
|
||||
guard(writer, x, low - SHELL, water, z, guard);
|
||||
} else if (ceilings[cell] == SeaInlet.OPEN) {
|
||||
guard(writer, x, low - SHELL, floor - 1, z, guard);
|
||||
} else if (historicalAround != null && besideHistorical(historicalAround, lx, lz)) {
|
||||
guard(writer, x, low - SHELL, ceilings[cell], z, guard);
|
||||
} else {
|
||||
for (int y = floor + 1; y <= water; y++) {
|
||||
writer.setData(x, y, z, wet);
|
||||
writer.clearData(x, y, z, NativeBlockState.class);
|
||||
}
|
||||
for (int y = water + 1; y <= ceilings[cell]; y++) {
|
||||
writer.setData(x, y, z, dry);
|
||||
}
|
||||
guard(writer, x, low - SHELL, floor, z, guard);
|
||||
}
|
||||
int roof = nearbyRoof(ceilings, cell, water);
|
||||
for (int y = water + 1; y <= roof + SHELL; y++) {
|
||||
if (subterrain.at(x, y, z)) {
|
||||
guard(writer, x, y, y, z, guard);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface SubterrainFluid {
|
||||
SubterrainFluid NOWHERE = (x, y, z) -> false;
|
||||
|
||||
boolean at(int x, int y, int z);
|
||||
}
|
||||
|
||||
public interface HistoricalChunks {
|
||||
HistoricalChunks NONE = (chunkX, chunkZ) -> false;
|
||||
|
||||
boolean at(int chunkX, int chunkZ);
|
||||
}
|
||||
|
||||
public static boolean touches(SeaInlet inlet, int chunkX, int chunkZ) {
|
||||
int[] bounds = bounds(inlet);
|
||||
int minX = chunkX << 4;
|
||||
int minZ = chunkZ << 4;
|
||||
return bounds[0] <= minX + CHUNK - 1 + SHELL && bounds[2] >= minX - SHELL && bounds[1] <= minZ + CHUNK - 1 + SHELL
|
||||
&& bounds[3] >= minZ - SHELL;
|
||||
}
|
||||
|
||||
public static int[] bounds(SeaInlet inlet) {
|
||||
float minX = inlet.chamberX() - inlet.chamberRadius();
|
||||
float minZ = inlet.chamberZ() - inlet.chamberRadius();
|
||||
float maxX = inlet.chamberX() + inlet.chamberRadius() + 1;
|
||||
float maxZ = inlet.chamberZ() + inlet.chamberRadius() + 1;
|
||||
for (int station = 0; station < inlet.stations(); station++) {
|
||||
float reach = inlet.halfWidth()[station] + 1f;
|
||||
minX = Math.min(minX, inlet.xs()[station] - reach);
|
||||
minZ = Math.min(minZ, inlet.zs()[station] - reach);
|
||||
maxX = Math.max(maxX, inlet.xs()[station] + reach);
|
||||
maxZ = Math.max(maxZ, inlet.zs()[station] + reach);
|
||||
}
|
||||
return new int[]{(int) Math.floor(minX), (int) Math.floor(minZ), (int) Math.ceil(maxX), (int) Math.ceil(maxZ)};
|
||||
}
|
||||
|
||||
public static boolean column(SeaInlet inlet, int x, int z, int[] out) {
|
||||
double px = x + 0.5D;
|
||||
double pz = z + 0.5D;
|
||||
int floor = Integer.MAX_VALUE;
|
||||
int ceiling = NONE;
|
||||
float[] xs = inlet.xs();
|
||||
float[] zs = inlet.zs();
|
||||
for (int station = 0; station + 1 < xs.length; station++) {
|
||||
double ax = xs[station];
|
||||
double az = zs[station];
|
||||
double dx = xs[station + 1] - ax;
|
||||
double dz = zs[station + 1] - az;
|
||||
double span = dx * dx + dz * dz;
|
||||
double t = span <= 0D ? 0D : Math.clamp(((px - ax) * dx + (pz - az) * dz) / span, 0D, 1D);
|
||||
double distance = Math.hypot(px - (ax + t * dx), pz - (az + t * dz));
|
||||
double half = inlet.halfWidth()[station] + t * (inlet.halfWidth()[station + 1] - inlet.halfWidth()[station]);
|
||||
if (distance > half) {
|
||||
continue;
|
||||
}
|
||||
floor = Math.min(floor, (int) Math.round(inlet.floor()[station] + t * (inlet.floor()[station + 1] - inlet.floor()[station])));
|
||||
ceiling = Math.max(ceiling, ceiling(inlet, station, t));
|
||||
}
|
||||
double radius = inlet.chamberRadius();
|
||||
double fromCentre = Math.hypot(px - inlet.chamberX(), pz - inlet.chamberZ());
|
||||
if (fromCentre <= radius) {
|
||||
int last = xs.length - 1;
|
||||
double dome = Math.sqrt(1D - (fromCentre / radius) * (fromCentre / radius));
|
||||
int water = inlet.waterLevel();
|
||||
floor = Math.min(floor, water - (int) Math.max(1L, Math.round((water - inlet.floor()[last]) * dome)));
|
||||
ceiling = Math.max(ceiling, water + (int) Math.round((inlet.ceiling()[last] - water) * dome));
|
||||
}
|
||||
if (ceiling == NONE) {
|
||||
return false;
|
||||
}
|
||||
out[0] = floor;
|
||||
out[1] = ceiling;
|
||||
return true;
|
||||
}
|
||||
|
||||
private static int ceiling(SeaInlet inlet, int station, double t) {
|
||||
if (inlet.open(station) || inlet.open(station + 1)) {
|
||||
return t <= 0.5D ? inlet.ceiling()[station] : inlet.ceiling()[station + 1];
|
||||
}
|
||||
return (int) Math.round(inlet.ceiling()[station] + t * (inlet.ceiling()[station + 1] - inlet.ceiling()[station]));
|
||||
}
|
||||
|
||||
static boolean shape(SeaInlet inlet, int originX, int originZ, int size, int[] floors, int[] ceilings) {
|
||||
Arrays.fill(floors, NONE);
|
||||
Arrays.fill(ceilings, NONE);
|
||||
boolean any = false;
|
||||
int[] column = new int[2];
|
||||
for (int gz = 0; gz < size; gz++) {
|
||||
for (int gx = 0; gx < size; gx++) {
|
||||
if (column(inlet, originX + gx, originZ + gz, column)) {
|
||||
floors[gz * size + gx] = column[0];
|
||||
ceilings[gz * size + gx] = column[1];
|
||||
any = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return any;
|
||||
}
|
||||
|
||||
static int nearby(int[] values, int size, int cell, boolean lowest) {
|
||||
int found = NONE;
|
||||
int gx = cell % size;
|
||||
int gz = cell / size;
|
||||
for (int dz = -SHELL; dz <= SHELL; dz++) {
|
||||
for (int dx = -SHELL; dx <= SHELL; dx++) {
|
||||
int value = values[(gz + dz) * size + gx + dx];
|
||||
if (value != NONE && (found == NONE || (lowest ? value < found : value > found))) {
|
||||
found = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
private static int nearbyRoof(int[] ceilings, int cell, int water) {
|
||||
int roof = water - SHELL;
|
||||
int gx = cell % GRID;
|
||||
int gz = cell / GRID;
|
||||
for (int dz = -SHELL; dz <= SHELL; dz++) {
|
||||
for (int dx = -SHELL; dx <= SHELL; dx++) {
|
||||
int ceiling = ceilings[(gz + dz) * GRID + gx + dx];
|
||||
if (ceiling != SeaInlet.OPEN && ceiling > water && ceiling > roof) {
|
||||
roof = ceiling;
|
||||
}
|
||||
}
|
||||
}
|
||||
return roof;
|
||||
}
|
||||
|
||||
private static boolean[] historicalAround(int chunkX, int chunkZ, HistoricalChunks historical) {
|
||||
boolean[] around = null;
|
||||
for (int dz = -1; dz <= 1; dz++) {
|
||||
for (int dx = -1; dx <= 1; dx++) {
|
||||
if ((dx != 0 || dz != 0) && historical.at(chunkX + dx, chunkZ + dz)) {
|
||||
if (around == null) {
|
||||
around = new boolean[9];
|
||||
}
|
||||
around[(dz + 1) * 3 + dx + 1] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return around;
|
||||
}
|
||||
|
||||
private static boolean besideHistorical(boolean[] historicalAround, int lx, int lz) {
|
||||
int fromX = lx < SHELL ? -1 : 0;
|
||||
int toX = lx >= CHUNK - SHELL ? 1 : 0;
|
||||
int fromZ = lz < SHELL ? -1 : 0;
|
||||
int toZ = lz >= CHUNK - SHELL ? 1 : 0;
|
||||
for (int dz = fromZ; dz <= toZ; dz++) {
|
||||
for (int dx = fromX; dx <= toX; dx++) {
|
||||
if (historicalAround[(dz + 1) * 3 + dx + 1]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void guard(MantleWriter writer, int x, int fromY, int toY, int z, HydrologyCaveCell guard) {
|
||||
for (int y = fromY; y <= toY; y++) {
|
||||
if (writer.getDataIfPresent(x, y, z, HydrologyCaveCell.class) == null) {
|
||||
writer.setData(x, y, z, guard);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
-63
@@ -1,63 +0,0 @@
|
||||
package art.arcane.iris.generation.hydrology.underground;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
public final class SeaInletSpace {
|
||||
private static final int SHELL = SeaInletRasterizer.SHELL;
|
||||
private static final int NONE = SeaInletRasterizer.NONE;
|
||||
|
||||
private final int originX;
|
||||
private final int originZ;
|
||||
private final int size;
|
||||
private final int[] lows;
|
||||
private final int[] highs;
|
||||
|
||||
private SeaInletSpace(int originX, int originZ, int size, int[] lows, int[] highs) {
|
||||
this.originX = originX;
|
||||
this.originZ = originZ;
|
||||
this.size = size;
|
||||
this.lows = lows;
|
||||
this.highs = highs;
|
||||
}
|
||||
|
||||
public static SeaInletSpace of(Collection<SeaInlet> inlets, int originX, int originZ, int size) {
|
||||
int[] lows = new int[size * size];
|
||||
int[] highs = new int[size * size];
|
||||
Arrays.fill(lows, NONE);
|
||||
Arrays.fill(highs, NONE);
|
||||
int grid = size + 2 * SHELL;
|
||||
int[] floors = new int[grid * grid];
|
||||
int[] ceilings = new int[grid * grid];
|
||||
for (SeaInlet inlet : inlets) {
|
||||
if (!SeaInletRasterizer.shape(inlet, originX - SHELL, originZ - SHELL, grid, floors, ceilings)) {
|
||||
continue;
|
||||
}
|
||||
for (int z = 0; z < size; z++) {
|
||||
for (int x = 0; x < size; x++) {
|
||||
int cell = (z + SHELL) * grid + x + SHELL;
|
||||
int low = SeaInletRasterizer.nearby(floors, grid, cell, true);
|
||||
if (low == NONE) {
|
||||
continue;
|
||||
}
|
||||
int column = z * size + x;
|
||||
int bottom = low - SHELL;
|
||||
int top = Math.max(inlet.waterLevel(), SeaInletRasterizer.nearby(ceilings, grid, cell, false));
|
||||
lows[column] = lows[column] == NONE ? bottom : Math.min(lows[column], bottom);
|
||||
highs[column] = Math.max(highs[column], top);
|
||||
}
|
||||
}
|
||||
}
|
||||
return new SeaInletSpace(originX, originZ, size, lows, highs);
|
||||
}
|
||||
|
||||
public boolean contains(int x, int y, int z) {
|
||||
int localX = x - originX;
|
||||
int localZ = z - originZ;
|
||||
if (localX < 0 || localX >= size || localZ < 0 || localZ >= size) {
|
||||
return false;
|
||||
}
|
||||
int column = localZ * size + localX;
|
||||
return lows[column] != NONE && y >= lows[column] && y <= highs[column];
|
||||
}
|
||||
}
|
||||
@@ -44,10 +44,14 @@ final class ReachFitter {
|
||||
}
|
||||
|
||||
Fitted fit(DemGrid grid, int[] cells, float[] cellCatchment, HydrologyTier tier, long shapeSeed, boolean drainsToTheSea) {
|
||||
return fit(grid, cells, cellCatchment, tier, shapeSeed, drainsToTheSea, tier.halfWidth(cellCatchment[cellCatchment.length - 1]), MEANDER_WIDTH_SCALE, true);
|
||||
}
|
||||
|
||||
Fitted fit(DemGrid grid, int[] cells, float[] cellCatchment, HydrologyTier tier, long shapeSeed, boolean drainsToTheSea, float meanderWidth, double amplitudeScale, boolean dampOnSlopes) {
|
||||
float halfWidth = tier.halfWidth(cellCatchment[cellCatchment.length - 1]);
|
||||
Line line = relax(resample(grid, cells, cellCatchment));
|
||||
Tangents tangents = tangents(line.xs(), line.zs());
|
||||
meander(line, tangents, shapeSeed, halfWidth);
|
||||
meander(line, tangents, shapeSeed, meanderWidth, amplitudeScale, dampOnSlopes);
|
||||
int reach = Math.max(2, (int) Math.ceil(Math.max(VALLEY_SNAP, halfWidth + 2f) / SPACING));
|
||||
Reads reads = read(line, tangents, reach);
|
||||
Fitted fitted = place(line, tangents, reads, soften(viterbi(reads, line.xs().length, reach), reads, reach), tier);
|
||||
@@ -159,7 +163,7 @@ final class ReachFitter {
|
||||
return spaced;
|
||||
}
|
||||
|
||||
private void meander(Line line, Tangents tangents, long shapeSeed, float halfWidth) {
|
||||
private void meander(Line line, Tangents tangents, long shapeSeed, float halfWidth, double amplitudeScale, boolean dampOnSlopes) {
|
||||
int count = line.xs().length;
|
||||
if (count < 3) {
|
||||
return;
|
||||
@@ -168,11 +172,11 @@ final class ReachFitter {
|
||||
for (int wave = 0; wave < phase.length; wave++) {
|
||||
phase[wave] = 2D * Math.PI * CellHash.unit(CellHash.mix(shapeSeed, SALT_MEANDER, wave, 0));
|
||||
}
|
||||
double amplitude = Math.clamp(MEANDER_WIDTH_SCALE * (halfWidth + 1f), MEANDER_MIN, MEANDER_MAX);
|
||||
double amplitude = Math.clamp(amplitudeScale * (halfWidth + 1f), MEANDER_MIN, MEANDER_MAX);
|
||||
double wavelength = Math.clamp(MEANDER_WAVELENGTH_WIDTHS * 2D * (halfWidth + 1f), MEANDER_WAVELENGTH_MIN, MEANDER_WAVELENGTH_MAX);
|
||||
double ramp = Math.min(line.length() / 2D, wavelength / 2D);
|
||||
float[] open = awayFromPonds(line, tangents, (float) amplitude + halfWidth + SHORE_MARGIN);
|
||||
double[] damping = slopeDamping(line);
|
||||
double[] damping = dampOnSlopes ? slopeDamping(line) : null;
|
||||
float[] offsets = new float[count];
|
||||
for (int point = 1; point < count - 1; point++) {
|
||||
double s = line.distance()[point];
|
||||
@@ -181,7 +185,7 @@ final class ReachFitter {
|
||||
wave += MEANDER_WAVE_WEIGHTS[index] * StrictMath.sin(2D * Math.PI * s / (wavelength * MEANDER_WAVE_SCALES[index]) + phase[index]);
|
||||
}
|
||||
double envelope = smoothstep(s / ramp) * smoothstep((line.length() - s) / ramp);
|
||||
offsets[point] = (float) (amplitude * envelope * damping[point] * wave * open[point]);
|
||||
offsets[point] = (float) (amplitude * envelope * (damping == null ? 1D : damping[point]) * wave * open[point]);
|
||||
}
|
||||
for (int point = 1; point < count - 1; point++) {
|
||||
line.xs()[point] -= offsets[point] * tangents.z()[point];
|
||||
|
||||
@@ -370,10 +370,7 @@ public final class ReachShaper {
|
||||
for (int point = 0; point < distance.length; point++) {
|
||||
draft.outletZone[point] = draft.outlet && distance[point] <= OUTLET_LENGTH;
|
||||
}
|
||||
for (int pass = 0; pass < SMOOTHING_PASSES; pass++) {
|
||||
chaikin(draft);
|
||||
}
|
||||
unfold(draft);
|
||||
smooth(draft);
|
||||
float upstream = 0f;
|
||||
float feederEnd = 0f;
|
||||
for (int index : draft.incoming) {
|
||||
@@ -385,6 +382,13 @@ public final class ReachShaper {
|
||||
widths(draft, upstream, feederEnd);
|
||||
}
|
||||
|
||||
static void smooth(ReachDraft draft) {
|
||||
for (int pass = 0; pass < SMOOTHING_PASSES; pass++) {
|
||||
chaikin(draft);
|
||||
}
|
||||
unfold(draft);
|
||||
}
|
||||
|
||||
private static void restyle(ReachDraft draft, int seaLevel) {
|
||||
draft.style = styles(draft.grade, draft.ocean, draft.fixed(), draft.tier.waterfallMinimumDrop(), seaLevel, draft.tier.stepHeight());
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -0,0 +1,793 @@
|
||||
package art.arcane.iris.generation.hydrology.water;
|
||||
|
||||
import art.arcane.iris.generation.hydrology.grid.CellHash;
|
||||
import art.arcane.iris.generation.hydrology.grid.DemGrid;
|
||||
import art.arcane.iris.generation.hydrology.grid.HeightLattice;
|
||||
import art.arcane.iris.generation.hydrology.grid.HydrologySampleBuffer;
|
||||
import art.arcane.iris.generation.hydrology.plan.HydrologySettings;
|
||||
import art.arcane.iris.generation.hydrology.plan.WindowKey;
|
||||
import art.arcane.iris.generation.hydrology.plan.WindowPlanner;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.PriorityQueue;
|
||||
|
||||
public final class TidalPlanner {
|
||||
private static final int CELL = WindowPlanner.CELL;
|
||||
private static final int[] SIDE_I = {1, -1, 0, 0};
|
||||
private static final int[] SIDE_J = {0, 0, 1, -1};
|
||||
private static final int MEMO_SITES = 4096;
|
||||
private static final int BUILD_ATTEMPTS = 24;
|
||||
private static final int TRIM_PASSES = 8;
|
||||
private static final float MOUTH_ZONE = 32f;
|
||||
private static final float END_SHARE = 0.4f;
|
||||
private static final float DIAGONAL = 1.41421356f;
|
||||
private static final float BESIDE_SEA_MARGIN = 10f;
|
||||
private static final float BESIDE_SEA_SHARE = 0.4f;
|
||||
private static final float TIP_LENGTH = 12f;
|
||||
private static final float TIP_HALF_WIDTH = 1.5f;
|
||||
private static final float SHOAL_LENGTH = 16f;
|
||||
private static final float DEEP_SHARE = 0.5f;
|
||||
private static final float SCAN_STEP = 8f;
|
||||
private static final float HEAD_WOBBLE = 0.4f;
|
||||
private static final float WOBBLE_LONG = 57f;
|
||||
private static final float WOBBLE_SHORT = 23f;
|
||||
private static final float BESIDE_NEAR = 1f;
|
||||
private static final float CLEARANCE_MARGIN = 4f;
|
||||
private static final int CLEARANCE_BAND = 24;
|
||||
private static final int LOW_RIVER = 2;
|
||||
private static final float LOW_RIVER_BAND = 4f;
|
||||
private static final float WALK_WIDTH = 4f;
|
||||
private static final float MAX_BANK_SLOPE = 2.5f;
|
||||
private static final float SMOOTH_STEEPEST = 1.5f;
|
||||
private static final float BANK_FIELD_SHARE = 0.125f;
|
||||
private static final float FAR_BANK_SHARE = 1.5f;
|
||||
private static final float HEAD_LOOK_BACK = 16f;
|
||||
private static final float TERRITORY_MARGIN = 8f;
|
||||
private static final int PROFILE_STEP = 4;
|
||||
private static final float CLIFF_RISE = 14f;
|
||||
private static final float WANDER = 12f;
|
||||
private static final float WANDER_CELLS = 5f;
|
||||
private static final float WAVES_PER_LENGTH = 0.5f;
|
||||
private static final float WAVELENGTH_WIDTHS = 24f;
|
||||
private static final double MEANDER_SCALE = 4.5D;
|
||||
private static final long SALT_WANDER = 0x5449444c574eL;
|
||||
private static final long SALT_ID = 0x5449444c4944L;
|
||||
private static final long SALT_SITE = 0x5449444c53L;
|
||||
private static final long SALT_DENSITY = 0x5449444c444eL;
|
||||
private static final long SALT_TARGET_X = 0x5449444c5458L;
|
||||
private static final long SALT_TARGET_Z = 0x5449444c545aL;
|
||||
private static final long SALT_LENGTH = 0x5449444c4c4eL;
|
||||
private static final long SALT_SHAPE = 0x5449444c5348L;
|
||||
private static final long SALT_MOUTH = 0x5449444c4d4fL;
|
||||
private static final long SALT_HEAD = 0x5449444c4845L;
|
||||
private static final long SALT_DEPTH = 0x5449444c4450L;
|
||||
private static final long SALT_WOBBLE = 0x5449444c5742L;
|
||||
|
||||
private final HydrologySettings settings;
|
||||
private final HydrologySettings.SeaInlets config;
|
||||
private final HeightLattice fine;
|
||||
private final int stride;
|
||||
private final long seed;
|
||||
private final float gradedHeight;
|
||||
private final float territory;
|
||||
private final Map<Long, Anchor> anchors = new LinkedHashMap<>(MEMO_SITES, 0.75f, true) {
|
||||
@Override
|
||||
protected boolean removeEldestEntry(Map.Entry<Long, Anchor> eldest) {
|
||||
return size() > MEMO_SITES;
|
||||
}
|
||||
};
|
||||
|
||||
public TidalPlanner(HydrologySettings settings, HeightLattice fine) {
|
||||
this.settings = Objects.requireNonNull(settings, "settings");
|
||||
this.config = settings.underground().seaInlets();
|
||||
this.fine = Objects.requireNonNull(fine, "fine");
|
||||
this.stride = CELL / fine.cell();
|
||||
this.seed = settings.seed();
|
||||
this.gradedHeight = Math.min(config.maximumBankHeight(), MAX_BANK_SLOPE * config.bankBand() / SMOOTH_STEEPEST);
|
||||
this.territory = config.mouthHalfWidth().max() + config.headHalfWidth().max() + TERRITORY_MARGIN;
|
||||
}
|
||||
|
||||
public List<Reach> plan(WindowKey window, DemGrid natural, HydrologySampleBuffer samples, ShapedNetwork network) {
|
||||
Objects.requireNonNull(window, "window");
|
||||
Objects.requireNonNull(network, "network");
|
||||
if (!config.enabled() || settings.density() <= 0f) {
|
||||
return List.of();
|
||||
}
|
||||
List<Anchor> own = own(window);
|
||||
if (own.isEmpty()) {
|
||||
return List.of();
|
||||
}
|
||||
Land land = new Land(natural, samples);
|
||||
float[] coast = coastDistance(land);
|
||||
boolean[] wet = wet(natural, network);
|
||||
banked(natural, samples, wet);
|
||||
ReachFitter fitter = new ReachFitter(fine, new PondLookup(network.ponds()));
|
||||
List<Reach> planned = new ArrayList<>();
|
||||
for (Anchor anchor : own) {
|
||||
List<Anchor> rivals = rivals(anchor);
|
||||
Reach reach = site(window, land, coast, wet, anchor, rivals, fitter, network);
|
||||
if (reach != null) {
|
||||
requireWithinReach(window, reach);
|
||||
planned.add(reach);
|
||||
}
|
||||
}
|
||||
planned.sort(Comparator.comparingLong(Reach::id));
|
||||
return List.copyOf(planned);
|
||||
}
|
||||
|
||||
private List<Anchor> own(WindowKey window) {
|
||||
int spacing = config.spacing();
|
||||
int minSiteX = Math.floorDiv(window.wx() * WindowKey.SIZE, spacing);
|
||||
int maxSiteX = Math.floorDiv((window.wx() + 1) * WindowKey.SIZE - 1, spacing);
|
||||
int minSiteZ = Math.floorDiv(window.wz() * WindowKey.SIZE, spacing);
|
||||
int maxSiteZ = Math.floorDiv((window.wz() + 1) * WindowKey.SIZE - 1, spacing);
|
||||
List<Anchor> own = new ArrayList<>();
|
||||
for (int siteZ = minSiteZ; siteZ <= maxSiteZ; siteZ++) {
|
||||
for (int siteX = minSiteX; siteX <= maxSiteX; siteX++) {
|
||||
Anchor anchor = anchor(siteX, siteZ);
|
||||
if (anchor.active() && anchor.owner().equals(window)) {
|
||||
own.add(anchor);
|
||||
}
|
||||
}
|
||||
}
|
||||
return own;
|
||||
}
|
||||
|
||||
private Anchor anchor(int siteX, int siteZ) {
|
||||
long key = ((long) siteX << 32) | (siteZ & 0xFFFFFFFFL);
|
||||
synchronized (anchors) {
|
||||
Anchor known = anchors.get(key);
|
||||
if (known != null) {
|
||||
return known;
|
||||
}
|
||||
}
|
||||
Anchor anchor = locate(siteX, siteZ);
|
||||
synchronized (anchors) {
|
||||
anchors.put(key, anchor);
|
||||
}
|
||||
return anchor;
|
||||
}
|
||||
|
||||
private Anchor locate(int siteX, int siteZ) {
|
||||
int spacing = config.spacing();
|
||||
double targetX = (siteX + CellHash.unit(CellHash.mix(seed, SALT_TARGET_X, siteX, siteZ))) * spacing;
|
||||
double targetZ = (siteZ + CellHash.unit(CellHash.mix(seed, SALT_TARGET_Z, siteX, siteZ))) * spacing;
|
||||
WindowKey owner = WindowKey.containing((int) Math.floor(targetX), (int) Math.floor(targetZ));
|
||||
if (settings.density() < 1f && CellHash.unit(CellHash.mix(seed, SALT_DENSITY, siteX, siteZ)) >= settings.density()) {
|
||||
return new Anchor(siteX, siteZ, owner, targetX, targetZ, false, 0, 0);
|
||||
}
|
||||
int firstX = Math.ceilDiv(siteX * spacing, CELL) * CELL;
|
||||
int firstZ = Math.ceilDiv(siteZ * spacing, CELL) * CELL;
|
||||
int cellsX = Math.ceilDiv((siteX + 1) * spacing - firstX, CELL);
|
||||
int cellsZ = Math.ceilDiv((siteZ + 1) * spacing - firstZ, CELL);
|
||||
Land land = land(firstX - CELL, firstZ - CELL, cellsX + 2, cellsZ + 2);
|
||||
DemGrid grid = land.grid();
|
||||
int bestX = 0;
|
||||
int bestZ = 0;
|
||||
double best = Double.POSITIVE_INFINITY;
|
||||
for (int j = 1; j <= cellsZ; j++) {
|
||||
for (int i = 1; i <= cellsX; i++) {
|
||||
int cell = grid.index(i, j);
|
||||
int mouth = open(land, cell) ? mouth(land, cell) : -1;
|
||||
if (mouth < 0 || !owner.equals(WindowKey.containing(grid.blockX(mouth), grid.blockZ(mouth)))) {
|
||||
continue;
|
||||
}
|
||||
double distance = Math.hypot(grid.blockX(cell) - targetX, grid.blockZ(cell) - targetZ);
|
||||
if (distance < best) {
|
||||
best = distance;
|
||||
bestX = grid.blockX(cell);
|
||||
bestZ = grid.blockZ(cell);
|
||||
}
|
||||
}
|
||||
}
|
||||
return new Anchor(siteX, siteZ, owner, targetX, targetZ, best != Double.POSITIVE_INFINITY, bestX, bestZ);
|
||||
}
|
||||
|
||||
private List<Anchor> rivals(Anchor anchor) {
|
||||
double reach = 2D * (config.length().max() + 2 * CELL) + territory;
|
||||
int spacing = config.spacing();
|
||||
int minSiteX = Math.floorDiv((int) Math.floor(anchor.x() - reach), spacing);
|
||||
int maxSiteX = Math.floorDiv((int) Math.ceil(anchor.x() + reach), spacing);
|
||||
int minSiteZ = Math.floorDiv((int) Math.floor(anchor.z() - reach), spacing);
|
||||
int maxSiteZ = Math.floorDiv((int) Math.ceil(anchor.z() + reach), spacing);
|
||||
List<Anchor> rivals = new ArrayList<>();
|
||||
for (int siteZ = minSiteZ; siteZ <= maxSiteZ; siteZ++) {
|
||||
for (int siteX = minSiteX; siteX <= maxSiteX; siteX++) {
|
||||
Anchor other = anchor(siteX, siteZ);
|
||||
if (other.active() && (other.siteX() != anchor.siteX() || other.siteZ() != anchor.siteZ())) {
|
||||
rivals.add(other);
|
||||
}
|
||||
}
|
||||
}
|
||||
return rivals;
|
||||
}
|
||||
|
||||
private boolean inTerritory(Anchor anchor, List<Anchor> rivals, double x, double z) {
|
||||
double own = Math.hypot(x - anchor.x(), z - anchor.z());
|
||||
for (Anchor rival : rivals) {
|
||||
if (own + territory > Math.hypot(x - rival.x(), z - rival.z())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private Reach site(WindowKey window, Land land, float[] coast, boolean[] wet, Anchor anchor, List<Anchor> rivals, ReachFitter fitter, ShapedNetwork network) {
|
||||
DemGrid grid = land.grid();
|
||||
int spacing = config.spacing();
|
||||
List<Integer> candidates = new ArrayList<>();
|
||||
int firstI = Math.ceilDiv(anchor.siteX() * spacing - grid.originX(), CELL);
|
||||
int firstJ = Math.ceilDiv(anchor.siteZ() * spacing - grid.originZ(), CELL);
|
||||
int lastI = Math.ceilDiv((anchor.siteX() + 1) * spacing - grid.originX(), CELL) - 1;
|
||||
int lastJ = Math.ceilDiv((anchor.siteZ() + 1) * spacing - grid.originZ(), CELL) - 1;
|
||||
for (int j = Math.max(1, firstJ); j <= Math.min(grid.depth() - 2, lastJ); j++) {
|
||||
for (int i = Math.max(1, firstI); i <= Math.min(grid.width() - 2, lastI); i++) {
|
||||
int cell = grid.index(i, j);
|
||||
int mouth = open(land, cell) && !wet[cell] ? mouth(land, cell) : -1;
|
||||
if (mouth >= 0 && window.equals(WindowKey.containing(grid.blockX(mouth), grid.blockZ(mouth)))
|
||||
&& inTerritory(anchor, rivals, grid.blockX(cell), grid.blockZ(cell))) {
|
||||
candidates.add(cell);
|
||||
}
|
||||
}
|
||||
}
|
||||
candidates.sort(Comparator.comparingDouble((Integer cell) -> Math.hypot(grid.blockX(cell) - anchor.targetX(), grid.blockZ(cell) - anchor.targetZ())).thenComparingInt(cell -> cell));
|
||||
int attempts = 0;
|
||||
for (int cell : candidates) {
|
||||
int[] cells = trace(land, coast, wet, anchor, rivals, cell);
|
||||
if (cells == null) {
|
||||
continue;
|
||||
}
|
||||
Reach reach = shape(land, cells, anchor, rivals, fitter, network);
|
||||
if (reach != null) {
|
||||
return reach;
|
||||
}
|
||||
if (++attempts >= BUILD_ATTEMPTS) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean[] wet(DemGrid grid, ShapedNetwork network) {
|
||||
boolean[] wet = new boolean[grid.values().length];
|
||||
for (Reach river : network.reaches()) {
|
||||
float band = Math.min(river.tier().bankBand(), CLEARANCE_BAND) + CLEARANCE_MARGIN + WALK_WIDTH;
|
||||
for (int point = 0; point < river.xs().length; point += 2) {
|
||||
float apart = river.grade()[point] - settings.seaLevel() <= LOW_RIVER ? CLEARANCE_MARGIN + LOW_RIVER_BAND : band;
|
||||
mark(grid, wet, river.xs()[point], river.zs()[point], river.halfWidth()[point] + apart);
|
||||
}
|
||||
}
|
||||
for (Pond pond : network.ponds()) {
|
||||
PondMask mask = pond.mask();
|
||||
float radius = 1.5f * mask.step() + Math.max(settings.ponds().shore().taper(), CLEARANCE_BAND) + CLEARANCE_MARGIN;
|
||||
for (int j = 0; j < mask.depth(); j++) {
|
||||
for (int i = 0; i < mask.width(); i++) {
|
||||
if (mask.node(i, j)) {
|
||||
mark(grid, wet, mask.originX() + i * mask.step(), mask.originZ() + j * mask.step(), radius);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return wet;
|
||||
}
|
||||
|
||||
private void banked(DemGrid grid, HydrologySampleBuffer samples, boolean[] wet) {
|
||||
int radius = (int) Math.ceil(BANK_FIELD_SHARE * config.bankBand() / CELL);
|
||||
int width = grid.width();
|
||||
int depth = grid.depth();
|
||||
float limit = settings.seaLevel() + gradedHeight;
|
||||
boolean[] high = new boolean[width * depth];
|
||||
for (int cell = 0; cell < high.length; cell++) {
|
||||
high[cell] = !samples.ocean()[cell] && samples.height()[cell] > limit;
|
||||
}
|
||||
boolean[] across = new boolean[high.length];
|
||||
for (int j = 0; j < depth; j++) {
|
||||
int last = Integer.MIN_VALUE / 2;
|
||||
for (int i = 0; i < width; i++) {
|
||||
last = high[j * width + i] ? i : last;
|
||||
across[j * width + i] = i - last <= radius;
|
||||
}
|
||||
last = Integer.MAX_VALUE / 2;
|
||||
for (int i = width - 1; i >= 0; i--) {
|
||||
last = high[j * width + i] ? i : last;
|
||||
across[j * width + i] |= last - i <= radius;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < width; i++) {
|
||||
int last = Integer.MIN_VALUE / 2;
|
||||
for (int j = 0; j < depth; j++) {
|
||||
last = across[j * width + i] ? j : last;
|
||||
wet[j * width + i] |= j - last <= radius;
|
||||
}
|
||||
last = Integer.MAX_VALUE / 2;
|
||||
for (int j = depth - 1; j >= 0; j--) {
|
||||
last = across[j * width + i] ? j : last;
|
||||
wet[j * width + i] |= last - j <= radius;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void mark(DemGrid grid, boolean[] wet, float x, float z, float radius) {
|
||||
int cell = grid.cell();
|
||||
int minI = Math.max(0, (int) Math.floor((x - radius - grid.originX()) / cell));
|
||||
int maxI = Math.min(grid.width() - 1, (int) Math.ceil((x + radius - grid.originX()) / cell));
|
||||
int minJ = Math.max(0, (int) Math.floor((z - radius - grid.originZ()) / cell));
|
||||
int maxJ = Math.min(grid.depth() - 1, (int) Math.ceil((z + radius - grid.originZ()) / cell));
|
||||
float squared = radius * radius;
|
||||
for (int j = minJ; j <= maxJ; j++) {
|
||||
float dz = grid.originZ() + j * cell - z;
|
||||
for (int i = minI; i <= maxI; i++) {
|
||||
float dx = grid.originX() + i * cell - x;
|
||||
if (dx * dx + dz * dz <= squared) {
|
||||
wet[j * grid.width() + i] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Land land(int originX, int originZ, int width, int depth) {
|
||||
HydrologySampleBuffer samples = new HydrologySampleBuffer(width * depth);
|
||||
fine.fill(Math.floorDiv(originX, fine.cell()), Math.floorDiv(originZ, fine.cell()), width, depth, stride, samples);
|
||||
DemGrid grid = new DemGrid(originX, originZ, CELL, width, depth);
|
||||
System.arraycopy(samples.height(), 0, grid.values(), 0, width * depth);
|
||||
return new Land(grid, samples);
|
||||
}
|
||||
|
||||
private boolean open(Land land, int cell) {
|
||||
HydrologySampleBuffer samples = land.samples();
|
||||
float height = samples.height()[cell];
|
||||
return !samples.ocean()[cell] && height >= settings.seaLevel() + 1 && height <= settings.seaLevel() + gradedHeight
|
||||
&& (samples.permission()[cell] & HydrologySampleBuffer.ALLOW_STREAMS) != 0;
|
||||
}
|
||||
|
||||
private static int mouth(Land land, int cell) {
|
||||
DemGrid grid = land.grid();
|
||||
int i = cell % grid.width();
|
||||
int j = cell / grid.width();
|
||||
for (int side = 0; side < SIDE_I.length; side++) {
|
||||
int ni = i + SIDE_I[side];
|
||||
int nj = j + SIDE_J[side];
|
||||
if (ni >= 0 && nj >= 0 && ni < grid.width() && nj < grid.depth() && land.samples().ocean()[grid.index(ni, nj)]) {
|
||||
return grid.index(ni, nj);
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
private static float[] coastDistance(Land land) {
|
||||
DemGrid grid = land.grid();
|
||||
boolean[] ocean = land.samples().ocean();
|
||||
int width = grid.width();
|
||||
int depth = grid.depth();
|
||||
float[] distance = new float[width * depth];
|
||||
Arrays.fill(distance, Float.POSITIVE_INFINITY);
|
||||
for (int cell = 0; cell < distance.length; cell++) {
|
||||
if (ocean[cell]) {
|
||||
distance[cell] = 0f;
|
||||
}
|
||||
}
|
||||
float straight = CELL;
|
||||
float diagonal = CELL * DIAGONAL;
|
||||
for (int pass = 0; pass < 2; pass++) {
|
||||
int step = pass == 0 ? -1 : 1;
|
||||
for (int b = 0; b < depth; b++) {
|
||||
int j = pass == 0 ? b : depth - 1 - b;
|
||||
for (int a = 0; a < width; a++) {
|
||||
int i = pass == 0 ? a : width - 1 - a;
|
||||
int cell = grid.index(i, j);
|
||||
float best = distance[cell];
|
||||
if (i + step >= 0 && i + step < width) {
|
||||
best = Math.min(best, distance[grid.index(i + step, j)] + straight);
|
||||
}
|
||||
if (j + step >= 0 && j + step < depth) {
|
||||
best = Math.min(best, distance[grid.index(i, j + step)] + straight);
|
||||
if (i + step >= 0 && i + step < width) {
|
||||
best = Math.min(best, distance[grid.index(i + step, j + step)] + diagonal);
|
||||
}
|
||||
if (i - step >= 0 && i - step < width) {
|
||||
best = Math.min(best, distance[grid.index(i - step, j + step)] + diagonal);
|
||||
}
|
||||
}
|
||||
distance[cell] = best;
|
||||
}
|
||||
}
|
||||
}
|
||||
return distance;
|
||||
}
|
||||
|
||||
private int[] trace(Land land, float[] coast, boolean[] wet, Anchor anchor, List<Anchor> rivals, int start) {
|
||||
DemGrid grid = land.grid();
|
||||
int mouth = mouth(land, start);
|
||||
double unit = CellHash.unit(CellHash.mix(seed, SALT_LENGTH, grid.blockX(start), grid.blockZ(start)));
|
||||
float target = (float) (config.length().min() + (config.length().max() - config.length().min()) * unit);
|
||||
float[] height = land.samples().height();
|
||||
Map<Integer, Step> reached = new HashMap<>();
|
||||
reached.put(start, new Step(-1, 0f, CELL));
|
||||
PriorityQueue<Integer> frontier = new PriorityQueue<>(Comparator.comparingDouble((Integer cell) -> coast[cell]).thenComparingInt(cell -> cell));
|
||||
frontier.add(start);
|
||||
int chosen = start;
|
||||
float chosenCost = Float.POSITIVE_INFINITY;
|
||||
float longest = CELL;
|
||||
while (!frontier.isEmpty()) {
|
||||
int current = frontier.poll();
|
||||
Step step = reached.get(current);
|
||||
if (step.length() >= target) {
|
||||
float cost = step.cost() / step.length();
|
||||
if (longest < target || cost < chosenCost) {
|
||||
chosen = current;
|
||||
chosenCost = cost;
|
||||
longest = step.length();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (longest < target && step.length() > longest) {
|
||||
longest = step.length();
|
||||
chosen = current;
|
||||
}
|
||||
int i = current % grid.width();
|
||||
int j = current / grid.width();
|
||||
for (int dj = -1; dj <= 1; dj++) {
|
||||
for (int di = -1; di <= 1; di++) {
|
||||
int ni = i + di;
|
||||
int nj = j + dj;
|
||||
if (di == 0 && dj == 0 || ni < 1 || nj < 1 || ni >= grid.width() - 1 || nj >= grid.depth() - 1) {
|
||||
continue;
|
||||
}
|
||||
int next = grid.index(ni, nj);
|
||||
if (coast[next] <= coast[current] || wet[next] || !open(land, next) || !inTerritory(anchor, rivals, grid.blockX(next), grid.blockZ(next))) {
|
||||
continue;
|
||||
}
|
||||
float span = di != 0 && dj != 0 ? CELL * DIAGONAL : CELL;
|
||||
float cost = step.cost() + span * (height[next] - settings.seaLevel() + wander(grid.blockX(next), grid.blockZ(next)));
|
||||
Step known = reached.get(next);
|
||||
if (known == null) {
|
||||
frontier.add(next);
|
||||
}
|
||||
if (known == null || cost < known.cost()) {
|
||||
reached.put(next, new Step(current, cost, step.length() + span));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
float length = reached.get(chosen).length();
|
||||
if (length < config.length().min() || coast[chosen] < END_SHARE * length) {
|
||||
return null;
|
||||
}
|
||||
List<Integer> path = new ArrayList<>();
|
||||
for (int cell = chosen; cell >= 0; cell = reached.get(cell).from()) {
|
||||
path.add(cell);
|
||||
}
|
||||
int[] cells = new int[path.size() + 1];
|
||||
for (int index = 0; index < path.size(); index++) {
|
||||
cells[index] = path.get(index);
|
||||
}
|
||||
cells[path.size()] = mouth;
|
||||
return cells;
|
||||
}
|
||||
|
||||
private float wander(int x, int z) {
|
||||
float size = WANDER_CELLS * CELL;
|
||||
int ix = (int) Math.floor(x / size);
|
||||
int iz = (int) Math.floor(z / size);
|
||||
float u = x / size - ix;
|
||||
float v = z / size - iz;
|
||||
float a = (float) CellHash.unit(CellHash.mix(seed, SALT_WANDER, ix, iz));
|
||||
float b = (float) CellHash.unit(CellHash.mix(seed, SALT_WANDER, ix + 1, iz));
|
||||
float c = (float) CellHash.unit(CellHash.mix(seed, SALT_WANDER, ix, iz + 1));
|
||||
float d = (float) CellHash.unit(CellHash.mix(seed, SALT_WANDER, ix + 1, iz + 1));
|
||||
return WANDER * ((a + (b - a) * u) * (1f - v) + (c + (d - c) * u) * v);
|
||||
}
|
||||
|
||||
private Reach shape(Land land, int[] cells, Anchor anchor, List<Anchor> rivals, ReachFitter fitter, ShapedNetwork network) {
|
||||
DemGrid grid = land.grid();
|
||||
int last = cells.length - 1;
|
||||
int mouthX = grid.blockX(cells[last]);
|
||||
int mouthZ = grid.blockZ(cells[last]);
|
||||
int startX = grid.blockX(cells[last - 1]);
|
||||
int startZ = grid.blockZ(cells[last - 1]);
|
||||
long id = CellHash.mix(CellHash.mix(seed, SALT_ID, mouthX, mouthZ), SALT_SITE, startX, startZ);
|
||||
long shape = CellHash.mix(id, SALT_SHAPE, 0, 0);
|
||||
HydrologyTier tier = settings.tidalTier();
|
||||
float walked = 0f;
|
||||
for (int index = 1; index < cells.length; index++) {
|
||||
walked += (float) Math.hypot(grid.blockX(cells[index]) - grid.blockX(cells[index - 1]), grid.blockZ(cells[index]) - grid.blockZ(cells[index - 1]));
|
||||
}
|
||||
float meanderWidth = Math.clamp(walked * WAVES_PER_LENGTH / WAVELENGTH_WIDTHS - 1f, 1f, config.meanderWidth());
|
||||
ReachFitter.Fitted fitted = fitter.fit(grid, cells, new float[cells.length], tier, shape, true, meanderWidth, MEANDER_SCALE, false);
|
||||
ReachDraft draft = new ReachDraft(new ReachTracer.Chain(cells, ReachTracer.End.OCEAN, -1), id, tier, 0f, Integer.MIN_VALUE, fitted);
|
||||
draft.grade = new int[draft.xs.length];
|
||||
Arrays.fill(draft.grade, settings.seaLevel());
|
||||
draft.outletZone = new boolean[draft.xs.length];
|
||||
ReachShaper.smooth(draft);
|
||||
float[] xs = draft.xs;
|
||||
float[] zs = draft.zs;
|
||||
for (int pass = 0; pass < TRIM_PASSES; pass++) {
|
||||
int grounded = groundedHead(xs, zs, id, shape);
|
||||
if (grounded < 0) {
|
||||
return null;
|
||||
}
|
||||
int head = Math.max(grounded, Math.max(territoryHead(xs, zs, shape, anchor, rivals), clearHead(xs, zs, shape, network)));
|
||||
float[] distance = ReachShaper.distances(xs, zs);
|
||||
if (distance[distance.length - 1] - distance[head] < config.length().min()) {
|
||||
return null;
|
||||
}
|
||||
if (head == 0) {
|
||||
Reach reach = reach(id, shape, xs, zs);
|
||||
if (besideSea(reach)) {
|
||||
return null;
|
||||
}
|
||||
return reach;
|
||||
}
|
||||
xs = Arrays.copyOfRange(xs, head, xs.length);
|
||||
zs = Arrays.copyOfRange(zs, head, zs.length);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private int territoryHead(float[] xs, float[] zs, long shape, Anchor anchor, List<Anchor> rivals) {
|
||||
float[] distance = ReachShaper.distances(xs, zs);
|
||||
for (int point = xs.length - 1; point >= 0; point--) {
|
||||
if (!inTerritory(anchor, rivals, xs[point], zs[point])) {
|
||||
float keep = distance[point] + SCAN_STEP;
|
||||
int head = point;
|
||||
while (head < xs.length - 1 && distance[head] < keep) {
|
||||
head++;
|
||||
}
|
||||
return head;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int clearHead(float[] xs, float[] zs, long shape, ShapedNetwork network) {
|
||||
float[] distance = ReachShaper.distances(xs, zs);
|
||||
float[] widths = widths(shape, distance);
|
||||
float keep = 0f;
|
||||
for (Reach river : network.reaches()) {
|
||||
float band = Math.min(river.tier().bankBand(), CLEARANCE_BAND) + CLEARANCE_MARGIN;
|
||||
for (int segment = 0; segment < river.xs().length; segment++) {
|
||||
float apart = river.grade()[segment] - settings.seaLevel() <= LOW_RIVER ? CLEARANCE_MARGIN + LOW_RIVER_BAND : band;
|
||||
keep = Math.max(keep, blocked(xs, zs, widths, distance, river.xs()[segment], river.zs()[segment], river.halfWidth()[segment] + apart));
|
||||
}
|
||||
}
|
||||
for (Pond pond : network.ponds()) {
|
||||
PondMask mask = pond.mask();
|
||||
float radius = 1.5f * mask.step() + Math.max(settings.ponds().shore().taper(), CLEARANCE_BAND) + CLEARANCE_MARGIN;
|
||||
for (int j = 0; j < mask.depth(); j++) {
|
||||
for (int i = 0; i < mask.width(); i++) {
|
||||
if (mask.node(i, j)) {
|
||||
keep = Math.max(keep, blocked(xs, zs, widths, distance, mask.originX() + i * mask.step(), mask.originZ() + j * mask.step(), radius));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (keep <= 0f) {
|
||||
return 0;
|
||||
}
|
||||
int head = 0;
|
||||
while (head < distance.length - 1 && distance[head] < keep) {
|
||||
head++;
|
||||
}
|
||||
return head;
|
||||
}
|
||||
|
||||
private static float blocked(float[] xs, float[] zs, float[] widths, float[] distance, float x, float z, float radius) {
|
||||
for (int point = xs.length - 1; point >= 0; point--) {
|
||||
float gap = widths[point] + radius;
|
||||
float dx = xs[point] - x;
|
||||
float dz = zs[point] - z;
|
||||
if (dx * dx + dz * dz < gap * gap) {
|
||||
return distance[point] + radius + widths[point];
|
||||
}
|
||||
}
|
||||
return 0f;
|
||||
}
|
||||
|
||||
private Reach reach(long id, long shape, float[] xs, float[] zs) {
|
||||
float[] distance = ReachShaper.distances(xs, zs);
|
||||
float[] halfWidth = widths(shape, distance);
|
||||
float[] depth = depths(shape, distance);
|
||||
int[] grade = new int[xs.length];
|
||||
Arrays.fill(grade, settings.seaLevel());
|
||||
ReachStyle[] style = new ReachStyle[xs.length];
|
||||
Arrays.fill(style, ReachStyle.TIDAL);
|
||||
return new Reach(id, settings.tidalTier(), 0L, xs, zs, grade, halfWidth, depth, style, 0f);
|
||||
}
|
||||
|
||||
private float[] widths(long shape, float[] distance) {
|
||||
float total = distance[distance.length - 1];
|
||||
HydrologySettings.FloatRange mouths = config.mouthHalfWidth();
|
||||
HydrologySettings.FloatRange heads = config.headHalfWidth();
|
||||
float mouth = mouths.min() + (mouths.max() - mouths.min()) * (float) CellHash.unit(CellHash.mix(shape, SALT_MOUTH, 0, 0));
|
||||
float head = heads.min() + (heads.max() - heads.min()) * (float) CellHash.unit(CellHash.mix(shape, SALT_HEAD, 0, 0));
|
||||
double phaseLong = CellHash.unit(CellHash.mix(shape, SALT_WOBBLE, 0, 0));
|
||||
double phaseShort = CellHash.unit(CellHash.mix(shape, SALT_WOBBLE, 1, 0));
|
||||
float[] widths = new float[distance.length];
|
||||
for (int point = 0; point < distance.length; point++) {
|
||||
float s = distance[point];
|
||||
float t = s / total;
|
||||
double funnel = head + (mouth - head) * Math.pow(t, config.taper());
|
||||
double wobble = 0.65D * StrictMath.sin(2D * Math.PI * (s / WOBBLE_LONG + phaseLong)) + 0.35D * StrictMath.sin(2D * Math.PI * (s / WOBBLE_SHORT + phaseShort));
|
||||
double ends = Math.min(1f, Math.min(s, total - s) / TIP_LENGTH);
|
||||
double shaped = funnel * (1D + config.widthVariation() * ends * (HEAD_WOBBLE + (1f - HEAD_WOBBLE) * t) * wobble);
|
||||
double tip = TIP_HALF_WIDTH + (shaped - TIP_HALF_WIDTH) * Math.min(1f, s / TIP_LENGTH);
|
||||
widths[point] = (float) Math.max(TIP_HALF_WIDTH, point == distance.length - 1 ? mouth : tip);
|
||||
}
|
||||
return widths;
|
||||
}
|
||||
|
||||
private float[] depths(long shape, float[] distance) {
|
||||
float total = distance[distance.length - 1];
|
||||
HydrologySettings.IntRange range = config.depth();
|
||||
float deepest = range.min() + (range.max() - range.min()) * (float) CellHash.unit(CellHash.mix(shape, SALT_DEPTH, 0, 0));
|
||||
float[] depth = new float[distance.length];
|
||||
for (int point = 0; point < distance.length; point++) {
|
||||
float s = distance[point];
|
||||
float along = range.min() + (deepest - range.min()) * Math.min(1f, s / total / DEEP_SHARE);
|
||||
float shoal = Math.min(1f, s / SHOAL_LENGTH) * Math.min(1f, (total - s) / SHOAL_LENGTH);
|
||||
depth[point] = 1f + (along - 1f) * shoal;
|
||||
}
|
||||
return depth;
|
||||
}
|
||||
|
||||
private int groundedHead(float[] xs, float[] zs, long id, long shape) {
|
||||
float[] distance = ReachShaper.distances(xs, zs);
|
||||
float total = distance[distance.length - 1];
|
||||
float[] widths = widths(shape, distance);
|
||||
int band = config.bankBand();
|
||||
float limit = settings.seaLevel() + gradedHeight;
|
||||
float farLimit = settings.seaLevel() + FAR_BANK_SHARE * gradedHeight;
|
||||
int rings = band / PROFILE_STEP + 1;
|
||||
int[] columnX = new int[2 * rings + 1];
|
||||
int[] columnZ = new int[2 * rings + 1];
|
||||
HydrologySampleBuffer samples = new HydrologySampleBuffer(columnX.length);
|
||||
int stops = (int) Math.ceil(total / SCAN_STEP);
|
||||
int point = xs.length - 1;
|
||||
for (int stop = 0; stop <= stops; stop++) {
|
||||
float wanted = total - stop * SCAN_STEP;
|
||||
while (point > 0 && distance[point] > wanted) {
|
||||
point--;
|
||||
}
|
||||
int before = Math.max(0, point - 1);
|
||||
int after = Math.min(xs.length - 1, point + 1);
|
||||
double length = Math.max(1e-3D, Math.hypot(xs[after] - xs[before], zs[after] - zs[before]));
|
||||
double nx = -(zs[after] - zs[before]) / length;
|
||||
double nz = (xs[after] - xs[before]) / length;
|
||||
for (int ring = 0; ring < rings; ring++) {
|
||||
double out = widths[point] + BESIDE_NEAR + ring * PROFILE_STEP;
|
||||
columnX[2 * ring] = (int) Math.floor(xs[point] + out * nx);
|
||||
columnZ[2 * ring] = (int) Math.floor(zs[point] + out * nz);
|
||||
columnX[2 * ring + 1] = (int) Math.floor(xs[point] - out * nx);
|
||||
columnZ[2 * ring + 1] = (int) Math.floor(zs[point] - out * nz);
|
||||
}
|
||||
columnX[2 * rings] = (int) Math.floor(xs[point]);
|
||||
columnZ[2 * rings] = (int) Math.floor(zs[point]);
|
||||
fine.sampleColumns(columnX, columnZ, samples);
|
||||
boolean inland = total - distance[point] > MOUTH_ZONE;
|
||||
boolean bad = !samples.ocean()[2 * rings] && samples.height()[2 * rings] > limit;
|
||||
for (int ring = 0; ring < rings && !bad; ring++) {
|
||||
for (int side = 0; side < 2 && !bad; side++) {
|
||||
int index = 2 * ring + side;
|
||||
if (samples.ocean()[index]) {
|
||||
continue;
|
||||
}
|
||||
float height = samples.height()[index];
|
||||
bad = height > (ring >= rings / 2 ? farLimit : limit) || inland && ring < 2 && height < settings.seaLevel();
|
||||
if (!bad && ring > 0 && !samples.ocean()[index - 2]) {
|
||||
bad = height - samples.height()[index - 2] >= CLIFF_RISE;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (bad) {
|
||||
float keep = distance[point] + band + widths[point];
|
||||
int head = point;
|
||||
while (head < xs.length - 1 && distance[head] < keep) {
|
||||
head++;
|
||||
}
|
||||
return total - distance[head] >= config.length().min() ? head : -1;
|
||||
}
|
||||
}
|
||||
return headFacesHighGround(xs, zs, widths, distance, limit) ? headBack(distance, total) : 0;
|
||||
}
|
||||
|
||||
private boolean headFacesHighGround(float[] xs, float[] zs, float[] widths, float[] distance, float limit) {
|
||||
int ahead = 0;
|
||||
while (ahead < xs.length - 1 && distance[ahead] < SCAN_STEP) {
|
||||
ahead++;
|
||||
}
|
||||
double length = Math.max(1e-3D, Math.hypot(xs[0] - xs[ahead], zs[0] - zs[ahead]));
|
||||
double tx = (xs[0] - xs[ahead]) / length;
|
||||
double tz = (zs[0] - zs[ahead]) / length;
|
||||
int rays = 7;
|
||||
int rings = config.bankBand() / PROFILE_STEP;
|
||||
int[] columnX = new int[rays * rings];
|
||||
int[] columnZ = new int[rays * rings];
|
||||
for (int ray = 0; ray < rays; ray++) {
|
||||
double angle = Math.toRadians(-90D + 30D * ray);
|
||||
double dx = tx * Math.cos(angle) - tz * Math.sin(angle);
|
||||
double dz = tx * Math.sin(angle) + tz * Math.cos(angle);
|
||||
for (int ring = 0; ring < rings; ring++) {
|
||||
float out = widths[0] + (ring + 1) * PROFILE_STEP;
|
||||
columnX[ray * rings + ring] = (int) Math.floor(xs[0] + out * dx);
|
||||
columnZ[ray * rings + ring] = (int) Math.floor(zs[0] + out * dz);
|
||||
}
|
||||
}
|
||||
HydrologySampleBuffer samples = new HydrologySampleBuffer(columnX.length);
|
||||
fine.sampleColumns(columnX, columnZ, samples);
|
||||
for (int index = 0; index < columnX.length; index++) {
|
||||
if (samples.ocean()[index]) {
|
||||
continue;
|
||||
}
|
||||
if (samples.height()[index] > limit || index % rings > 0 && !samples.ocean()[index - 1] && samples.height()[index] - samples.height()[index - 1] >= CLIFF_RISE) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private int headBack(float[] distance, float total) {
|
||||
int head = 0;
|
||||
while (head < distance.length - 1 && distance[head] < HEAD_LOOK_BACK) {
|
||||
head++;
|
||||
}
|
||||
return total - distance[head] >= config.length().min() ? head : -1;
|
||||
}
|
||||
|
||||
private boolean besideSea(Reach reach) {
|
||||
float[] distance = ReachShaper.distances(reach.xs(), reach.zs());
|
||||
float total = distance[distance.length - 1];
|
||||
int stops = 0;
|
||||
int beside = 0;
|
||||
int point = 0;
|
||||
int directions = 8;
|
||||
int[] columnX = new int[directions];
|
||||
int[] columnZ = new int[directions];
|
||||
HydrologySampleBuffer samples = new HydrologySampleBuffer(directions);
|
||||
for (float s = 0f; s <= total; s += SCAN_STEP) {
|
||||
while (point < distance.length - 1 && distance[point] < s) {
|
||||
point++;
|
||||
}
|
||||
float radius = reach.halfWidth()[point] + BESIDE_SEA_MARGIN;
|
||||
for (int direction = 0; direction < directions; direction++) {
|
||||
double angle = 2D * Math.PI * direction / directions;
|
||||
columnX[direction] = (int) Math.floor(reach.xs()[point] + radius * Math.cos(angle));
|
||||
columnZ[direction] = (int) Math.floor(reach.zs()[point] + radius * Math.sin(angle));
|
||||
}
|
||||
fine.sampleColumns(columnX, columnZ, samples);
|
||||
boolean sea = false;
|
||||
for (int direction = 0; direction < directions; direction++) {
|
||||
sea |= samples.ocean()[direction];
|
||||
}
|
||||
stops++;
|
||||
beside += sea ? 1 : 0;
|
||||
}
|
||||
return beside > BESIDE_SEA_SHARE * stops;
|
||||
}
|
||||
|
||||
private void requireWithinReach(WindowKey window, Reach reach) {
|
||||
int band = config.bankBand();
|
||||
for (int point = 0; point < reach.xs().length; point++) {
|
||||
float out = reach.halfWidth()[point] + band;
|
||||
if (reach.xs()[point] - out < (window.wx() - 1) * WindowKey.SIZE || reach.xs()[point] + out >= (window.wx() + 2) * WindowKey.SIZE
|
||||
|| reach.zs()[point] - out < (window.wz() - 1) * WindowKey.SIZE || reach.zs()[point] + out >= (window.wz() + 2) * WindowKey.SIZE) {
|
||||
throw new IllegalStateException("Sea inlet " + reach.id() + " of window " + window + " reaches past the next window at point " + point);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private record Step(int from, float cost, float length) {
|
||||
}
|
||||
|
||||
private record Land(DemGrid grid, HydrologySampleBuffer samples) {
|
||||
}
|
||||
|
||||
private record Anchor(int siteX, int siteZ, WindowKey owner, double targetX, double targetZ, boolean active, int x, int z) {
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,8 @@
|
||||
package art.arcane.iris.generation.mantle;
|
||||
|
||||
import art.arcane.iris.generation.hydrology.engine.HydrologyRuntime;
|
||||
import art.arcane.iris.generation.hydrology.raster.ChunkWaterRaster;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInlet;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInletRasterizer;
|
||||
import art.arcane.volmlib.util.math.PowerOfTwoCoordinates;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public final class CaveCeilingMask {
|
||||
static final int CONTAINMENT = 2;
|
||||
@@ -59,69 +54,6 @@ public final class CaveCeilingMask {
|
||||
return masked;
|
||||
}
|
||||
|
||||
public static long[] headroom(int chunkX, int chunkZ, HydrologyRuntime runtime, long[] bands) {
|
||||
List<SeaInlet> inlets = runtime.inlets(chunkX, chunkZ);
|
||||
if (inlets.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
int roofClearance = runtime.settings().underground().seaInlets().roofClearance();
|
||||
return fillHeadroom(chunkX, chunkZ, inlets, roofClearance, bands) ? bands : null;
|
||||
}
|
||||
|
||||
static boolean fillHeadroom(int chunkX, int chunkZ, List<SeaInlet> inlets, int roofClearance, long[] bands) {
|
||||
if (inlets.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
int originX = (chunkX << 4) - CONTAINMENT;
|
||||
int originZ = (chunkZ << 4) - CONTAINMENT;
|
||||
int[] bottoms = new int[FIELD * FIELD];
|
||||
int[] tops = new int[FIELD * FIELD];
|
||||
Arrays.fill(bottoms, Integer.MAX_VALUE);
|
||||
Arrays.fill(tops, Integer.MIN_VALUE);
|
||||
int[] column = new int[2];
|
||||
boolean roofed = false;
|
||||
for (SeaInlet inlet : inlets) {
|
||||
int[] bounds = SeaInletRasterizer.bounds(inlet);
|
||||
int fromX = Math.max(originX, bounds[0]);
|
||||
int toX = Math.min(originX + FIELD - 1, bounds[2]);
|
||||
int toZ = Math.min(originZ + FIELD - 1, bounds[3]);
|
||||
for (int z = Math.max(originZ, bounds[1]); z <= toZ; z++) {
|
||||
for (int x = fromX; x <= toX; x++) {
|
||||
if (!SeaInletRasterizer.column(inlet, x, z, column) || column[1] == SeaInlet.OPEN) {
|
||||
continue;
|
||||
}
|
||||
int index = (z - originZ) * FIELD + x - originX;
|
||||
bottoms[index] = Math.min(bottoms[index], inlet.waterLevel() + 1);
|
||||
tops[index] = Math.max(tops[index], column[1] + roofClearance);
|
||||
roofed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!roofed) {
|
||||
return false;
|
||||
}
|
||||
boolean masked = false;
|
||||
for (int lz = 0; lz < CHUNK; lz++) {
|
||||
for (int lx = 0; lx < CHUNK; lx++) {
|
||||
int bottom = Integer.MAX_VALUE;
|
||||
int top = Integer.MIN_VALUE;
|
||||
for (int fz = lz; fz <= lz + CONTAINMENT * 2; fz++) {
|
||||
for (int fx = lx; fx <= lx + CONTAINMENT * 2; fx++) {
|
||||
bottom = Math.min(bottom, bottoms[fz * FIELD + fx]);
|
||||
top = Math.max(top, tops[fz * FIELD + fx]);
|
||||
}
|
||||
}
|
||||
bands[PowerOfTwoCoordinates.packLocal16(lx, lz)] = SurfaceFluidBoundaryPlan.boundary(bottom, top);
|
||||
masked |= bottom <= top;
|
||||
}
|
||||
}
|
||||
return masked;
|
||||
}
|
||||
|
||||
public static boolean masked(int[] ceilings, long[] headroom, int column, int y) {
|
||||
return ceilings != null && y > ceilings[column] || SurfaceFluidBoundaryPlan.protects(headroom, column, y);
|
||||
}
|
||||
|
||||
public static ChunkWaterRaster ready(ChunkWaterRaster raster, int chunkX, int chunkZ) {
|
||||
if (raster.provisional()) {
|
||||
throw new IllegalStateException("The water raster for chunk " + chunkX + "," + chunkZ
|
||||
|
||||
@@ -5,8 +5,6 @@ import art.arcane.iris.generation.hydrology.config.IrisHydrologyPolicy;
|
||||
import art.arcane.iris.generation.hydrology.engine.HydrologyRuntime;
|
||||
import art.arcane.iris.generation.hydrology.underground.CarvedTerrain;
|
||||
import art.arcane.iris.generation.hydrology.underground.CaveVoxel;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInlet;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInletSpace;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
import art.arcane.iris.generation.stream.ProvisionalSampling;
|
||||
@@ -23,10 +21,7 @@ import art.arcane.volmlib.util.matter.Matter;
|
||||
import art.arcane.volmlib.util.matter.MatterCavern;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
final class MantleCarvedTerrain implements CarvedTerrain {
|
||||
private static final int SPAN = 48;
|
||||
@@ -49,7 +44,6 @@ final class MantleCarvedTerrain implements CarvedTerrain {
|
||||
private final SubterrainPlanner planner;
|
||||
private final List<SubterrainPlan> features;
|
||||
private final boolean terrain3D;
|
||||
private final SeaInletSpace inlets;
|
||||
private final MantleChunk<Matter>[] chunks;
|
||||
private final boolean[] existing;
|
||||
private final int[] surfaces = new int[SPAN * SPAN];
|
||||
@@ -71,7 +65,6 @@ final class MantleCarvedTerrain implements CarvedTerrain {
|
||||
this.minimumY = engine.getWorld().minHeight();
|
||||
HydrologyRuntime runtime = complex.getHydrologyRuntime();
|
||||
this.caveFluids = runtime.caveFluidPolicies();
|
||||
this.inlets = SeaInletSpace.of(inlets(runtime, chunkX, chunkZ), originX, originZ, SPAN);
|
||||
SubterrainPlanner subterrain = complex.getSubterrainPlanner();
|
||||
List<SubterrainPlan> plans = subterrain == null || subterrain.isEmpty() ? List.of()
|
||||
: subterrain.plansForBounds(originX, originZ, originX + SPAN - 1, originZ + SPAN - 1);
|
||||
@@ -88,7 +81,7 @@ final class MantleCarvedTerrain implements CarvedTerrain {
|
||||
@Override
|
||||
public CaveVoxel voxel(int x, int y, int z) {
|
||||
int column = column(x, z);
|
||||
if (y <= 0 || y >= height || existing(x, z) || y > surface(x, z, column) || inlets.contains(x, y, z)) {
|
||||
if (y <= 0 || y >= height || existing(x, z) || y > surface(x, z, column)) {
|
||||
return CaveVoxel.FOREIGN;
|
||||
}
|
||||
if (planner != null && planner.sample(features, x, y + minimumY, z).owned()) {
|
||||
@@ -149,18 +142,6 @@ final class MantleCarvedTerrain implements CarvedTerrain {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static Collection<SeaInlet> inlets(HydrologyRuntime runtime, int chunkX, int chunkZ) {
|
||||
Map<Long, SeaInlet> inlets = new LinkedHashMap<>();
|
||||
for (int offsetZ = -1; offsetZ <= 1; offsetZ++) {
|
||||
for (int offsetX = -1; offsetX <= 1; offsetX++) {
|
||||
for (SeaInlet inlet : runtime.inlets(chunkX + offsetX, chunkZ + offsetZ)) {
|
||||
inlets.putIfAbsent(inlet.id(), inlet);
|
||||
}
|
||||
}
|
||||
}
|
||||
return inlets.values();
|
||||
}
|
||||
|
||||
private int surface(int x, int z, int column) {
|
||||
int known = surfaces[column];
|
||||
if (known == UNKNOWN) {
|
||||
|
||||
@@ -169,10 +169,6 @@ public class MantleCarvingComponent extends IrisMantleComponent {
|
||||
);
|
||||
int[] caveCeilings = CaveCeilingMask.fill(x, z, complex.getHydrologyRuntime()::raster,
|
||||
blendScratch.caveCeilingField, blendScratch.caveCeilings) ? blendScratch.caveCeilings : null;
|
||||
long[] inletHeadroom = CaveCeilingMask.headroom(x, z, complex.getHydrologyRuntime(), blendScratch.inletHeadroom);
|
||||
if (inletHeadroom != null) {
|
||||
SurfaceFluidBoundaryPlan.join(surfaceFluidBoundaries, inletHeadroom);
|
||||
}
|
||||
CaveFluidSupportPlan fluidSupportPlan = new CaveFluidSupportPlan();
|
||||
for (WeightedProfile weightedProfile : weightedProfiles) {
|
||||
carveProfile(weightedProfile, writer, x, z, chunkSurfaceHeights, surfaceFluidBoundaries, caveCeilings, fluidSupportPlan);
|
||||
@@ -194,10 +190,10 @@ public class MantleCarvingComponent extends IrisMantleComponent {
|
||||
caveCeilings
|
||||
);
|
||||
}
|
||||
rasterizeSubterrain(writer, x, z, complex, caveCeilings, inletHeadroom);
|
||||
rasterizeSubterrain(writer, x, z, complex, caveCeilings);
|
||||
}
|
||||
|
||||
private void rasterizeSubterrain(MantleWriter writer, int chunkX, int chunkZ, IrisComplex complex, int[] caveCeilings, long[] inletHeadroom) {
|
||||
private void rasterizeSubterrain(MantleWriter writer, int chunkX, int chunkZ, IrisComplex complex, int[] caveCeilings) {
|
||||
SubterrainPlanner planner = complex.getSubterrainPlanner();
|
||||
if (planner == null || planner.isEmpty()) {
|
||||
return;
|
||||
@@ -211,7 +207,7 @@ public class MantleCarvingComponent extends IrisMantleComponent {
|
||||
if (cell.solid() && !cell.room().reservedSolid()) {
|
||||
return;
|
||||
}
|
||||
if (!cell.solid() && CaveCeilingMask.masked(caveCeilings, inletHeadroom, PowerOfTwoCoordinates.packLocal16(x & 15, z & 15), y)) {
|
||||
if (!cell.solid() && caveCeilings != null && y > caveCeilings[PowerOfTwoCoordinates.packLocal16(x & 15, z & 15)]) {
|
||||
return;
|
||||
}
|
||||
if (cell.solid()) {
|
||||
@@ -767,7 +763,6 @@ public class MantleCarvingComponent extends IrisMantleComponent {
|
||||
private final double[] chunkSurfaceHeightSamples = new double[CHUNK_AREA];
|
||||
private final int[] caveCeilingField = new int[CaveCeilingMask.FIELD * CaveCeilingMask.FIELD];
|
||||
private final int[] caveCeilings = new int[CHUNK_AREA];
|
||||
private final long[] inletHeadroom = new long[CHUNK_AREA];
|
||||
private final double[][] neighbourHeights = new double[NEIGHBOURS][CHUNK_AREA];
|
||||
private final Object[][] neighbourObjects = new Object[NEIGHBOURS][CHUNK_AREA];
|
||||
private final long[][] neighbourSubmerged = new long[NEIGHBOURS][4];
|
||||
|
||||
@@ -12,8 +12,6 @@ import art.arcane.iris.generation.hydrology.raster.FluidSeams;
|
||||
import art.arcane.iris.generation.hydrology.underground.CarvedTerrain;
|
||||
import art.arcane.iris.generation.hydrology.underground.CavePoolFiller;
|
||||
import art.arcane.iris.generation.hydrology.underground.CaveSpringPlacer;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInlet;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInletRasterizer;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
import art.arcane.iris.generation.subterrain.SubterrainPlan;
|
||||
@@ -35,7 +33,6 @@ public final class MantleHydrologyComponent extends IrisMantleComponent {
|
||||
private static final int CHUNK = 16;
|
||||
private static final int GRID = CHUNK + 2;
|
||||
private static final int[] SIDES = {1, -1, GRID, -GRID};
|
||||
private static final SeaInletRasterizer INLETS = new SeaInletRasterizer();
|
||||
|
||||
public MantleHydrologyComponent(EngineMantle engineMantle) {
|
||||
super(engineMantle, ReservedFlag.RIVER_HYDROLOGY, PRIORITY);
|
||||
@@ -84,13 +81,6 @@ public final class MantleHydrologyComponent extends IrisMantleComponent {
|
||||
}
|
||||
HydrologyRuntime runtime = complex.getHydrologyRuntime();
|
||||
ChunkWaterRaster own = CaveCeilingMask.ready(runtime.raster(chunkX, chunkZ), chunkX, chunkZ);
|
||||
List<SeaInlet> inlets = runtime.inlets(chunkX, chunkZ);
|
||||
if (!inlets.isEmpty()) {
|
||||
SeaInletRasterizer.SubterrainFluid subterrain = subterrainFluid(writer, complex, chunkX, chunkZ);
|
||||
for (SeaInlet inlet : inlets) {
|
||||
INLETS.write(inlet, chunkX, chunkZ, writer, HydrologyCaveCell.SEA_FLUID, subterrain, complex::isHistoricalChunk);
|
||||
}
|
||||
}
|
||||
generateFalls(writer, complex, runtime, own, chunkX, chunkZ);
|
||||
if (caveWaterActive()) {
|
||||
HydrologySettings settings = runtime.settings();
|
||||
@@ -107,19 +97,6 @@ public final class MantleHydrologyComponent extends IrisMantleComponent {
|
||||
}
|
||||
}
|
||||
|
||||
private static SeaInletRasterizer.SubterrainFluid subterrainFluid(MantleWriter writer, IrisComplex complex, int chunkX, int chunkZ) {
|
||||
SubterrainPlanner planner = complex.getSubterrainPlanner();
|
||||
if (planner == null || planner.isEmpty()) {
|
||||
return SeaInletRasterizer.SubterrainFluid.NOWHERE;
|
||||
}
|
||||
List<SubterrainPlan> plans = planner.plansForBounds(chunkX << 4, chunkZ << 4, (chunkX << 4) + 15, (chunkZ << 4) + 15);
|
||||
if (plans.isEmpty()) {
|
||||
return SeaInletRasterizer.SubterrainFluid.NOWHERE;
|
||||
}
|
||||
int minimumY = writer.getEngine().getWorld().minHeight();
|
||||
return (x, y, z) -> planner.sample(plans, x, y + minimumY, z).fluid();
|
||||
}
|
||||
|
||||
private void generateFalls(MantleWriter writer, IrisComplex complex, HydrologyRuntime runtime, ChunkWaterRaster own, int chunkX,
|
||||
int chunkZ) {
|
||||
if (!holdsWater(own)) {
|
||||
|
||||
@@ -73,17 +73,6 @@ final class SurfaceFluidBoundaryPlan {
|
||||
}
|
||||
}
|
||||
|
||||
static void join(long[] boundaries, long[] bands) {
|
||||
for (int columnIndex = 0; columnIndex < CHUNK_AREA; columnIndex++) {
|
||||
long band = bands[columnIndex];
|
||||
if (startY(band) > endY(band)) {
|
||||
continue;
|
||||
}
|
||||
long boundary = boundaries[columnIndex];
|
||||
boundaries[columnIndex] = boundary(Math.min(startY(boundary), startY(band)), Math.max(endY(boundary), endY(band)));
|
||||
}
|
||||
}
|
||||
|
||||
static boolean protects(long[] boundaries, int columnIndex, int y) {
|
||||
if (boundaries == null || columnIndex < 0 || columnIndex >= boundaries.length) {
|
||||
return false;
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -1405,6 +1405,11 @@ public class IrisComplex implements DataProvider {
|
||||
return tier == null ? pondMaterials : tier.materials();
|
||||
}
|
||||
|
||||
public boolean isTidalBank(int x, int z) {
|
||||
WaterRole role = resolveWaterRole(x, z);
|
||||
return (role == WaterRole.BANK || role == WaterRole.SHORE) && chunkRasterAt(x, z).tier(x & 15, z & 15) == hydrologyRuntime.settings().tidalTier();
|
||||
}
|
||||
|
||||
public HydrologyVegetation.Decorators resolveWaterDecorators(int x, int z) {
|
||||
if (!waterVegetation.planted()) {
|
||||
return HydrologyVegetation.Decorators.EMPTY;
|
||||
|
||||
@@ -164,8 +164,7 @@ public class IrisCarveModifier extends EngineAssignedModifier<NativeBlockState>
|
||||
getEngine().getWorld().minHeight(),
|
||||
resolverState.complex,
|
||||
subterrainPlanner == null ? null : subterrainPlanner.chunkSampler(x, z),
|
||||
subterrain ? caveCeilings(resolverState.complex, x, z) : null,
|
||||
subterrain ? inletHeadroom(resolverState.complex, x, z) : null
|
||||
subterrain ? caveCeilings(resolverState.complex, x, z) : null
|
||||
);
|
||||
CarveResolver carveResolver = new CarveResolver(resolutionContext);
|
||||
terrain.forEachCell(carveResolver::apply);
|
||||
@@ -263,17 +262,16 @@ public class IrisCarveModifier extends EngineAssignedModifier<NativeBlockState>
|
||||
int minimumY = getEngine().getWorld().minHeight();
|
||||
SubterrainSurfaceMaterials materials = subterrainMaterials(planner, blockX >> 4, blockZ >> 4);
|
||||
int[] caveCeilings = caveCeilings(getComplex(), blockX >> 4, blockZ >> 4);
|
||||
long[] inletHeadroom = inletHeadroom(getComplex(), blockX >> 4, blockZ >> 4);
|
||||
MantleChunk<Matter> chunk = getEngine().getMantle().getMantle().useChunk(blockX >> 4, blockZ >> 4);
|
||||
try {
|
||||
preserveSubterrain(planner, materials, caveCeilings, inletHeadroom, minimumY, blockX, blockZ, output,
|
||||
preserveSubterrain(planner, materials, caveCeilings, minimumY, blockX, blockZ, output,
|
||||
(worldX, y, worldZ) -> HydrologyCaveStorage.getIfPresent(chunk, worldX, y, worldZ));
|
||||
} finally {
|
||||
chunk.release();
|
||||
}
|
||||
}
|
||||
|
||||
private void preserveSubterrain(SubterrainPlanner planner, SubterrainSurfaceMaterials materials, int[] caveCeilings, long[] inletHeadroom,
|
||||
private void preserveSubterrain(SubterrainPlanner planner, SubterrainSurfaceMaterials materials, int[] caveCeilings,
|
||||
int minimumY, int blockX, int blockZ, Hunk<NativeBlockState> output, HydrologyCells hydrology) {
|
||||
SubterrainRasterizer.rasterize(planner, blockX >> 4, blockZ >> 4, (worldX, worldY, worldZ, cell) -> {
|
||||
int y = worldY - minimumY;
|
||||
@@ -282,7 +280,7 @@ public class IrisCarveModifier extends EngineAssignedModifier<NativeBlockState>
|
||||
}
|
||||
int x = worldX & 15;
|
||||
int z = worldZ & 15;
|
||||
if (!cell.solid() && CaveCeilingMask.masked(caveCeilings, inletHeadroom, PowerOfTwoCoordinates.packLocal16(x, z), y)) {
|
||||
if (!cell.solid() && caveCeilings != null && y > caveCeilings[PowerOfTwoCoordinates.packLocal16(x, z)]) {
|
||||
return;
|
||||
}
|
||||
if (hydrology.at(worldX, y, worldZ) != null) {
|
||||
@@ -310,10 +308,6 @@ public class IrisCarveModifier extends EngineAssignedModifier<NativeBlockState>
|
||||
new int[CaveCeilingMask.FIELD * CaveCeilingMask.FIELD], ceilings) ? ceilings : null;
|
||||
}
|
||||
|
||||
private static long[] inletHeadroom(IrisComplex complex, int chunkX, int chunkZ) {
|
||||
return CaveCeilingMask.headroom(chunkX, chunkZ, complex.getHydrologyRuntime(), new long[256]);
|
||||
}
|
||||
|
||||
private void restoreSubterrainSolids(Hunk<NativeBlockState> output, int chunkX, int chunkZ, boolean preserveFloorSupports,
|
||||
HydrologyCells hydrology) {
|
||||
SubterrainPlanner planner = getComplex().getSubterrainPlanner();
|
||||
@@ -476,7 +470,7 @@ public class IrisCarveModifier extends EngineAssignedModifier<NativeBlockState>
|
||||
CarveOwnership.Owner owner = carveOwner(hydrology, feature,
|
||||
context.terrainColumns() == null ? null : context.terrainColumns()[columnIndex], y);
|
||||
if (owner == CarveOwnership.Owner.SUBTERRAIN) {
|
||||
if (!feature.solid() && CaveCeilingMask.masked(context.caveCeilings(), context.inletHeadroom(), columnIndex, y)) {
|
||||
if (!feature.solid() && context.caveCeilings() != null && y > context.caveCeilings()[columnIndex]) {
|
||||
return;
|
||||
}
|
||||
context.output().setRaw(localX, y, localZ, SubterrainRasterizer.state(feature));
|
||||
@@ -566,8 +560,7 @@ public class IrisCarveModifier extends EngineAssignedModifier<NativeBlockState>
|
||||
int minimumY,
|
||||
IrisComplex complex,
|
||||
SubterrainPlanner.ChunkSampler subterrainSampler,
|
||||
int[] caveCeilings,
|
||||
long[] inletHeadroom
|
||||
int[] caveCeilings
|
||||
) {
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,8 @@ public class IrisTerrainNormalActuator extends EngineAssignedActuator<NativeBloc
|
||||
private static final BoundBlockState AIR = BoundBlockState.of("AIR");
|
||||
private static final BoundBlockState DIRT = BoundBlockState.of("minecraft:dirt");
|
||||
private static final BoundBlockState NETHERRACK = BoundBlockState.of("minecraft:netherrack");
|
||||
private static final int SLOT_SEA_LAYERS = 1;
|
||||
private static final int INLET_SEA_LAYERS = 1;
|
||||
private static final int TIDAL_BANK_SHALLOW_CUT = 16;
|
||||
@Getter
|
||||
private final RNG rng;
|
||||
|
||||
@@ -291,7 +292,7 @@ public class IrisTerrainNormalActuator extends EngineAssignedActuator<NativeBloc
|
||||
if (i > he && i <= hf) {
|
||||
int fdepth = hf - i;
|
||||
if (seaFloor && fblocks == null) {
|
||||
fblocks = biome.generateSeaLayers(realX, realZ, rng, role == WaterRole.INLET ? SLOT_SEA_LAYERS : hf - he, data);
|
||||
fblocks = biome.generateSeaLayers(realX, realZ, rng, role == WaterRole.INLET ? INLET_SEA_LAYERS : hf - he, data);
|
||||
}
|
||||
put(i, HydrologyFluidLayerSelector.select(
|
||||
fblocks,
|
||||
@@ -316,6 +317,9 @@ public class IrisTerrainNormalActuator extends EngineAssignedActuator<NativeBloc
|
||||
}
|
||||
blocks = biome.generateLayers(dimension, realX, realZ, rng,
|
||||
layerSurfaceY + cut + 1 - bedrockFloor, layerSurfaceY + cut, data, complex);
|
||||
if (exposeStrata && cut <= TIDAL_BANK_SHALLOW_CUT && complex.isTidalBank(realX, realZ)) {
|
||||
cut = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int deepFloor = Math.max(bedrockFloor, layerCeilingY > 0 ? layerCeilingY + 2 : 0);
|
||||
|
||||
@@ -40,15 +40,14 @@ final class PackHydrologyValidator {
|
||||
new RangeField("ponds.seeded.depth", Floor.POSITIVE, true),
|
||||
new RangeField("ponds.seeded.channelSpacing", Floor.POSITIVE, true),
|
||||
new RangeField("underground.seaInlets.length", Floor.POSITIVE, true),
|
||||
new RangeField("underground.seaInlets.halfWidth", Floor.POSITIVE, false),
|
||||
new RangeField("underground.seaInlets.mouthHalfWidth", Floor.POSITIVE, false),
|
||||
new RangeField("underground.seaInlets.headHalfWidth", Floor.POSITIVE, false),
|
||||
new RangeField("underground.seaInlets.depth", Floor.POSITIVE, true),
|
||||
new RangeField("underground.seaInlets.headroom", Floor.NON_NEGATIVE, true),
|
||||
new RangeField("underground.seaInlets.chamberRadius", Floor.POSITIVE, true),
|
||||
new RangeField("underground.cavePools.freeboard", Floor.NON_NEGATIVE, true)
|
||||
);
|
||||
private static final List<String> FLUID_REFERENCES = List.of("ponds.fluid", "underground.cavePools.fluid");
|
||||
private static final IrisHydrologyTier DEFAULT_TIER = new IrisHydrologyTier();
|
||||
private static final String MANTLE_WATER = "the falling water at waterfalls and cascades, sea inlets and cave pools";
|
||||
private static final String MANTLE_WATER = "the falling water at waterfalls and cascades and cave pools";
|
||||
|
||||
private PackHydrologyValidator() {
|
||||
}
|
||||
|
||||
+1
-1
@@ -68,7 +68,7 @@ final class RiverLimits {
|
||||
|
||||
private void inspectUnderground() {
|
||||
if (settings.underground().seaInlets().enabled()) {
|
||||
add(ExportLimit.SEA_INLET, hydrology, "", "Sea inlets are not exported: coastal cliffs have no flooded passages");
|
||||
add(ExportLimit.SEA_INLET, hydrology, "", "Sea inlets are not exported: low coasts have no tidal arms");
|
||||
}
|
||||
if (settings.underground().cavePools().enabled() && settings.underground().cavePools().density() > 0.0F) {
|
||||
add(ExportLimit.CAVE_POOL, hydrology, "", "Cave pools are not exported: cave floors hold no standing water of their own");
|
||||
|
||||
@@ -44,8 +44,8 @@ public final class IrisStructureWater implements StructureWater {
|
||||
|
||||
static boolean river(WaterRole role) {
|
||||
return switch (role) {
|
||||
case CHANNEL, POND, CASCADE, WATERFALL -> true;
|
||||
case NONE, BANK, SHORE, POND_SHORE, DAM, MOUTH, INLET -> false;
|
||||
case CHANNEL, POND, CASCADE, WATERFALL, INLET -> true;
|
||||
case NONE, BANK, SHORE, POND_SHORE, DAM, MOUTH -> false;
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -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));
|
||||
|
||||
Reference in new issue
Block a user