mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 00:34:19 +00:00
Grade arms through hills
- Route walks around ground too tall for the bank band and stop short of it - Scan bank profiles and head rays for tall ground and cliffs, and trim the head - Widen the default bank band so banks grade back like a river valley - Measure the steepest bank rise, slot runs and head walls in the probe - Add a sections mode rendering real block cross sections of chosen arms
This commit is contained in:
10 files changed
+412
-52
No files matched your search
@@ -28,8 +28,8 @@ public class IrisSeaInlets {
|
||||
|
||||
@MinNumber(2)
|
||||
@MaxNumber(128)
|
||||
@Description("Highest ground in blocks above sea level an inlet may cut through. An arm stops where its banks would pass this height, so lower values keep inlets out of hills.")
|
||||
private int maximumBankHeight = 40;
|
||||
@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 water at the sea in blocks, written as [min, max], each from 2 to 32. The min must not be below headHalfWidth max.")
|
||||
@@ -61,7 +61,7 @@ public class IrisSeaInlets {
|
||||
@MinNumber(4)
|
||||
@MaxNumber(64)
|
||||
@Description("Width in blocks of the band of ground beside the water that is shaped into banks.")
|
||||
private int bankBand = 24;
|
||||
private int bankBand = 32;
|
||||
|
||||
@Description("Profile of the banks across bankBand.")
|
||||
private IrisBankStyle bankStyle = IrisBankStyle.SMOOTH;
|
||||
|
||||
@@ -23,8 +23,8 @@ public final class TidalPlanner {
|
||||
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 = 8;
|
||||
private static final int TRIM_PASSES = 3;
|
||||
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;
|
||||
@@ -39,12 +39,20 @@ public final class TidalPlanner {
|
||||
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 BESIDE_FAR = 4f;
|
||||
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 float MOUTH_MARGIN = 18f;
|
||||
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;
|
||||
@@ -69,6 +77,7 @@ public final class TidalPlanner {
|
||||
private final HeightLattice fine;
|
||||
private final int stride;
|
||||
private final long seed;
|
||||
private final float gradedHeight;
|
||||
private final float territory;
|
||||
private final float mouthSpacing;
|
||||
private final Map<Long, Anchor> anchors = new LinkedHashMap<>(MEMO_SITES, 0.75f, true) {
|
||||
@@ -84,8 +93,9 @@ public final class TidalPlanner {
|
||||
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;
|
||||
this.mouthSpacing = 2f * config.mouthHalfWidth().max() + config.bankBand();
|
||||
this.mouthSpacing = 2f * config.mouthHalfWidth().max() + MOUTH_MARGIN;
|
||||
}
|
||||
|
||||
public List<Reach> plan(WindowKey window, DemGrid natural, HydrologySampleBuffer samples, ShapedNetwork network) {
|
||||
@@ -101,6 +111,7 @@ public final class TidalPlanner {
|
||||
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) {
|
||||
@@ -263,7 +274,7 @@ public final class TidalPlanner {
|
||||
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(), config.bankBand()) + CLEARANCE_MARGIN + WALK_WIDTH;
|
||||
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);
|
||||
@@ -271,7 +282,7 @@ public final class TidalPlanner {
|
||||
}
|
||||
for (Pond pond : network.ponds()) {
|
||||
PondMask mask = pond.mask();
|
||||
float radius = 1.5f * mask.step() + Math.max(settings.ponds().shore().taper(), config.bankBand()) + CLEARANCE_MARGIN;
|
||||
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)) {
|
||||
@@ -283,6 +294,42 @@ public final class TidalPlanner {
|
||||
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));
|
||||
@@ -312,7 +359,7 @@ public final class TidalPlanner {
|
||||
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() + config.maximumBankHeight()
|
||||
return !samples.ocean()[cell] && height >= settings.seaLevel() + 1 && height <= settings.seaLevel() + gradedHeight
|
||||
&& (samples.permission()[cell] & HydrologySampleBuffer.ALLOW_STREAMS) != 0;
|
||||
}
|
||||
|
||||
@@ -519,7 +566,7 @@ public final class TidalPlanner {
|
||||
float[] widths = widths(shape, distance);
|
||||
float keep = 0f;
|
||||
for (Reach river : network.reaches()) {
|
||||
float band = Math.min(river.tier().bankBand(), config.bankBand()) + CLEARANCE_MARGIN;
|
||||
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));
|
||||
@@ -527,7 +574,7 @@ public final class TidalPlanner {
|
||||
}
|
||||
for (Pond pond : network.ponds()) {
|
||||
PondMask mask = pond.mask();
|
||||
float radius = 1.5f * mask.step() + Math.max(settings.ponds().shore().taper(), config.bankBand()) + CLEARANCE_MARGIN;
|
||||
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)) {
|
||||
@@ -610,9 +657,12 @@ public final class TidalPlanner {
|
||||
float total = distance[distance.length - 1];
|
||||
float[] widths = widths(shape, distance);
|
||||
int band = config.bankBand();
|
||||
float limit = settings.seaLevel() + config.maximumBankHeight();
|
||||
int sea = settings.seaLevel();
|
||||
float[] offsets = new float[8];
|
||||
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++) {
|
||||
@@ -620,37 +670,35 @@ public final class TidalPlanner {
|
||||
while (point > 0 && distance[point] > wanted) {
|
||||
point--;
|
||||
}
|
||||
float half = widths[point];
|
||||
offsets[0] = half + BESIDE_NEAR;
|
||||
offsets[1] = -offsets[0];
|
||||
offsets[2] = half + BESIDE_FAR;
|
||||
offsets[3] = -offsets[2];
|
||||
offsets[4] = half + 0.5f * band;
|
||||
offsets[5] = -offsets[4];
|
||||
offsets[6] = half + band;
|
||||
offsets[7] = -offsets[6];
|
||||
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 tx = (xs[after] - xs[before]) / length;
|
||||
double tz = (zs[after] - zs[before]) / length;
|
||||
int[] columnX = new int[offsets.length + 1];
|
||||
int[] columnZ = new int[offsets.length + 1];
|
||||
for (int index = 0; index < offsets.length; index++) {
|
||||
columnX[index] = (int) Math.floor(xs[point] - offsets[index] * tz);
|
||||
columnZ[index] = (int) Math.floor(zs[point] + offsets[index] * tx);
|
||||
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[offsets.length] = (int) Math.floor(xs[point]);
|
||||
columnZ[offsets.length] = (int) Math.floor(zs[point]);
|
||||
HydrologySampleBuffer samples = new HydrologySampleBuffer(columnX.length);
|
||||
columnX[2 * rings] = (int) Math.floor(xs[point]);
|
||||
columnZ[2 * rings] = (int) Math.floor(zs[point]);
|
||||
fine.sampleColumns(columnX, columnZ, samples);
|
||||
boolean bad = false;
|
||||
for (int index = 0; index < columnX.length && !bad; index++) {
|
||||
boolean ocean = samples.ocean()[index];
|
||||
boolean near = index < 4 || index == offsets.length;
|
||||
boolean far = index >= 4 && index < offsets.length;
|
||||
float allowed = far ? limit + band : limit;
|
||||
bad = !ocean && (samples.height()[index] > allowed || near && total - distance[point] > MOUTH_ZONE && samples.height()[index] < sea);
|
||||
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];
|
||||
@@ -661,7 +709,50 @@ public final class TidalPlanner {
|
||||
return total - distance[head] >= config.length().min() ? head : -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
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) {
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ public class IrisHydrologyDefaultsTest {
|
||||
"lakes": { "enabled": true, "minArea": 65536, "maxArea": 4194304 },
|
||||
"deformation": { "maxFill": 6, "bankSlope": 0.2, "bankSteepFactor": 3.5, "bankNoise": 0.2, "caveMask": true },
|
||||
"underground": {
|
||||
"seaInlets": { "enabled": true, "spacing": 192, "length": [64, 256], "maximumBankHeight": 40, "mouthHalfWidth": [13, 15], "headHalfWidth": [2.5, 3], "taper": 1.4, "widthVariation": 0.18, "meanderWidth": 4, "depth": [2, 5], "bankBand": 24, "bankStyle": "SMOOTH" },
|
||||
"seaInlets": { "enabled": true, "spacing": 192, "length": [64, 256], "maximumBankHeight": 44, "mouthHalfWidth": [13, 15], "headHalfWidth": [2.5, 3], "taper": 1.4, "widthVariation": 0.18, "meanderWidth": 4, "depth": [2, 5], "bankBand": 32, "bankStyle": "SMOOTH" },
|
||||
"cavePools": { "enabled": true, "density": 0.15, "minArea": 6, "maxArea": 400, "maxDepth": 4, "radius": 15, "freeboard": [0, 1], "fluid": "water" }
|
||||
},
|
||||
"fluids": [ { "name": "water", "palette": { "palette": [ { "block": "minecraft:water" } ] } } ],
|
||||
|
||||
+3
-3
@@ -38,7 +38,7 @@ public class HydrologySettingsTest {
|
||||
private static final int SEA_LEVEL = 62;
|
||||
private static final int MIN_Y = -64;
|
||||
private static final int MAX_Y = 320;
|
||||
private static final long DEFAULT_FINGERPRINT = 7426172183353655598L;
|
||||
private static final long DEFAULT_FINGERPRINT = -2724181682955020615L;
|
||||
|
||||
@Test
|
||||
public void densityIsBoundedAndChangesThePlanIdentity() {
|
||||
@@ -717,14 +717,14 @@ public class HydrologySettingsTest {
|
||||
assertTrue(inlets.enabled());
|
||||
assertEquals(192, inlets.spacing());
|
||||
assertEquals(new HydrologySettings.IntRange(64, 256), inlets.length());
|
||||
assertEquals(40, inlets.maximumBankHeight());
|
||||
assertEquals(44, inlets.maximumBankHeight());
|
||||
assertEquals(new HydrologySettings.FloatRange(13f, 15f), inlets.mouthHalfWidth());
|
||||
assertEquals(new HydrologySettings.FloatRange(2.5f, 3f), inlets.headHalfWidth());
|
||||
assertEquals(1.4f, inlets.taper(), 0f);
|
||||
assertEquals(0.18f, inlets.widthVariation(), 1e-6f);
|
||||
assertEquals(4f, inlets.meanderWidth(), 0f);
|
||||
assertEquals(new HydrologySettings.IntRange(2, 5), inlets.depth());
|
||||
assertEquals(24, inlets.bankBand());
|
||||
assertEquals(32, inlets.bankBand());
|
||||
assertEquals(IrisBankStyle.SMOOTH, inlets.bankStyle());
|
||||
}
|
||||
|
||||
|
||||
@@ -58,6 +58,11 @@ final class SyntheticTerrain implements HydrologyTerrainSource {
|
||||
return new SyntheticTerrain(natural, rainfall, streamsBlocked, area, land);
|
||||
}
|
||||
|
||||
SyntheticTerrain rising(double fromX, double slope) {
|
||||
DoubleBinaryOperator inner = natural;
|
||||
return new SyntheticTerrain((x, z) -> inner.applyAsDouble(x, z) + Math.max(0D, x - fromX) * slope, rainfall, streamsBlocked, pondsBlocked, land);
|
||||
}
|
||||
|
||||
SyntheticTerrain lowered(double depth) {
|
||||
DoubleBinaryOperator inner = natural;
|
||||
return new SyntheticTerrain((x, z) -> inner.applyAsDouble(x, z) - depth, rainfall, streamsBlocked, pondsBlocked, land);
|
||||
|
||||
@@ -179,6 +179,25 @@ public class TidalPlannerTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void armsNeverGradeBanksThroughGroundTooTallForTheBand() {
|
||||
HydrologySettings settings = settings();
|
||||
double wallX = COAST_X + 150D;
|
||||
SyntheticTerrain hill = SyntheticTerrain.lowCoast(COAST_X).rising(wallX, 2D);
|
||||
double graded = 1.5D * settings.underground().seaInlets().maximumBankHeight();
|
||||
List<Reach> arms = arms(planner(settings, hill));
|
||||
assertFalse("a low strip still holds arms", arms.isEmpty());
|
||||
for (Reach arm : arms) {
|
||||
for (int point = 0; point < arm.xs().length; point++) {
|
||||
double side = arm.halfWidth()[point] + settings.underground().seaInlets().bankBand();
|
||||
assertTrue(arm + " grades through " + hill.natural(arm.xs()[point] + side, arm.zs()[point]),
|
||||
hill.natural(arm.xs()[point] + side, arm.zs()[point]) <= SEA + graded + 1D);
|
||||
}
|
||||
double ahead = arm.halfWidth()[0] + settings.underground().seaInlets().bankBand();
|
||||
assertTrue(arm + " ends against a wall", hill.natural(arm.xs()[0] + ahead, arm.zs()[0]) <= SEA + graded + 1D);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void groundBelowTheSeaBesideAnArmCutsTheArmOffAtIt() {
|
||||
SyntheticTerrain plain = SyntheticTerrain.lowCoast(COAST_X);
|
||||
|
||||
@@ -84,7 +84,7 @@ public class SchemaBuilderIdentityTest {
|
||||
@ClassRule
|
||||
public static final PlatformLeakGuard PLATFORM_GUARD = PlatformLeakGuard.clean();
|
||||
|
||||
private static final String EXPECTED_SCHEMA_DIGEST = "deb2538c92e5801beea672d32ded75301a441cf36d102bb09474f1c16f7821cc";
|
||||
private static final String EXPECTED_SCHEMA_DIGEST = "47b8ebadf50c11e9ab5d4293259056f005bac1d8c33ac8cc7d9bcc80c4afba6c";
|
||||
|
||||
private static final List<Class<?>> SCHEMA_ROOTS = List.of(
|
||||
IrisDimension.class,
|
||||
|
||||
@@ -82,6 +82,24 @@ final class TidalReachMetrics {
|
||||
return difference > 180D ? 360D - difference : difference;
|
||||
}
|
||||
|
||||
static double longestSlotRun(double[] left, double[] right, double rise, double step) {
|
||||
double longest = 0D;
|
||||
double run = 0D;
|
||||
for (int station = 0; station < left.length; station++) {
|
||||
run = left[station] >= rise && right[station] >= rise ? run + step : 0D;
|
||||
longest = Math.max(longest, run);
|
||||
}
|
||||
return longest;
|
||||
}
|
||||
|
||||
static double steepestRise(int[] heights, int span) {
|
||||
double steepest = 0D;
|
||||
for (int from = 0; from + span < heights.length; from++) {
|
||||
steepest = Math.max(steepest, heights[from + span] - heights[from]);
|
||||
}
|
||||
return steepest;
|
||||
}
|
||||
|
||||
static double percentile(double[] values, double share) {
|
||||
if (values.length == 0) {
|
||||
return 0D;
|
||||
|
||||
@@ -56,6 +56,10 @@ public final class TidalReachProbe {
|
||||
private static final int CROP_MARGIN = 48;
|
||||
private static final int MONTAGE_WIDTH = 1800;
|
||||
private static final int RAIL = 5;
|
||||
private static final int BAND_MEASURE = 32;
|
||||
private static final int SECTION_BELOW = 12;
|
||||
private static final int SECTION_LEVELS = 92;
|
||||
private static final double SLOT_RISE = 16D;
|
||||
private static final Map<String, Integer> COVERS = new ConcurrentHashMap<>();
|
||||
|
||||
private TidalReachProbe() {
|
||||
@@ -73,6 +77,7 @@ public final class TidalReachProbe {
|
||||
case "blocks" -> blocks(target, out, arguments.length > 6 ? Integer.parseInt(arguments[6]) : 6);
|
||||
case "digest" -> digests(target, out);
|
||||
case "rivers" -> rivers(target, out);
|
||||
case "sections" -> sections(target, out, Integer.parseInt(arguments[6]), Integer.parseInt(arguments[7]));
|
||||
default -> throw new IllegalArgumentException("Unknown mode " + mode);
|
||||
};
|
||||
System.out.println(LOG + " failures=" + failures);
|
||||
@@ -133,16 +138,18 @@ public final class TidalReachProbe {
|
||||
long seed = target.seed();
|
||||
long[] armEdges = new long[HISTOGRAM];
|
||||
long[] riverEdges = new long[HISTOGRAM];
|
||||
long[] armWalls = new long[HISTOGRAM];
|
||||
long[] riverWalls = new long[HISTOGRAM];
|
||||
List<BufferedImage> crops = new ArrayList<>();
|
||||
try (PrintWriter writer = new PrintWriter(new File(out, "arms-" + seed + ".tsv"))) {
|
||||
writer.println("seed\tid\tmouthX\tmouthZ\theadX\theadZ\tlength\tsinuosity\tstraight\tturn\tmouthHalf\theadHalf\tbesideShare\twet\tdisconnected\toverlap\tlowerDry\tcut\tseamHead\tseamTerrain\tedgeP90\tedge4");
|
||||
writer.println("seed\tid\tmouthX\tmouthZ\theadX\theadZ\tlength\tsinuosity\tstraight\tturn\tmouthHalf\theadHalf\tbesideShare\twet\tdisconnected\toverlap\tlowerDry\tcut\tseamHead\tseamTerrain\tedgeP90\tedge4\twallP90\twall8\tslotRun\theadRise8\theadSteep");
|
||||
for (Reach arm : arms) {
|
||||
ArmStats stats = armStats(arm, columns, armEdges);
|
||||
ArmStats stats = armStats(arm, columns, armEdges, armWalls);
|
||||
int last = arm.xs().length - 1;
|
||||
writer.printf(Locale.ROOT, "%d\t%d\t%.0f\t%.0f\t%.0f\t%.0f\t%.1f\t%.3f\t%.0f\t%.1f\t%.2f\t%.2f\t%.3f\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%.0f\t%.3f%n", seed, arm.id(), arm.xs()[last], arm.zs()[last],
|
||||
writer.printf(Locale.ROOT, "%d\t%d\t%.0f\t%.0f\t%.0f\t%.0f\t%.1f\t%.3f\t%.0f\t%.1f\t%.2f\t%.2f\t%.3f\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%.0f\t%.3f\t%.0f\t%.3f\t%.0f\t%d\t%.0f%n", seed, arm.id(), arm.xs()[last], arm.zs()[last],
|
||||
arm.xs()[0], arm.zs()[0], TidalReachMetrics.length(arm.xs(), arm.zs()), TidalReachMetrics.sinuosity(arm.xs(), arm.zs()),
|
||||
TidalReachMetrics.straightRun(arm.xs(), arm.zs()), TidalReachMetrics.sharpestTurn(arm.xs(), arm.zs()), stats.mouthHalf, stats.headHalf,
|
||||
stats.besideShare, stats.wet, stats.disconnected, stats.overlap, stats.lowerDry, stats.cut, stats.seamHead, stats.seamTerrain, stats.edgeP90, stats.edge4);
|
||||
stats.besideShare, stats.wet, stats.disconnected, stats.overlap, stats.lowerDry, stats.cut, stats.seamHead, stats.seamTerrain, stats.edgeP90, stats.edge4, stats.wallP90, stats.wall8, stats.slotRun, stats.headRise8, stats.headSteep);
|
||||
crops.add(crop(arm, columns));
|
||||
}
|
||||
}
|
||||
@@ -158,6 +165,7 @@ public final class TidalReachProbe {
|
||||
TidalReachMetrics.straightRun(river.xs(), river.zs()), TidalReachMetrics.sharpestTurn(river.xs(), river.zs()));
|
||||
if (measured++ < 40) {
|
||||
edges(river, columns, riverEdges);
|
||||
walls(river, columns, riverWalls, BAND_MEASURE);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -166,6 +174,8 @@ public final class TidalReachProbe {
|
||||
for (int step = 0; step < HISTOGRAM; step++) {
|
||||
writer.println("arm\t" + step + "\t" + armEdges[step]);
|
||||
writer.println("river\t" + step + "\t" + riverEdges[step]);
|
||||
writer.println("wallarm\t" + step + "\t" + armWalls[step]);
|
||||
writer.println("wallriver\t" + step + "\t" + riverWalls[step]);
|
||||
}
|
||||
}
|
||||
if (!crops.isEmpty()) {
|
||||
@@ -237,6 +247,11 @@ public final class TidalReachProbe {
|
||||
private int seamTerrain;
|
||||
private double edgeP90;
|
||||
private double edge4;
|
||||
private double wallP90;
|
||||
private double wall8;
|
||||
private double slotRun;
|
||||
private int headRise8;
|
||||
private double headSteep;
|
||||
}
|
||||
|
||||
private static int[] box(Reach reach, int grow) {
|
||||
@@ -269,7 +284,7 @@ public final class TidalReachProbe {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static ArmStats armStats(Reach arm, Columns columns, long[] edgeHistogram) {
|
||||
private static ArmStats armStats(Reach arm, Columns columns, long[] edgeHistogram, long[] wallHistogram) {
|
||||
ArmStats stats = new ArmStats();
|
||||
float[] widths = arm.halfWidth();
|
||||
int points = widths.length;
|
||||
@@ -349,9 +364,79 @@ public final class TidalReachProbe {
|
||||
break;
|
||||
}
|
||||
}
|
||||
long[] wallCounts = new long[HISTOGRAM];
|
||||
stats.slotRun = walls(arm, columns, wallCounts, columns.plans.settings().underground().seaInlets().bankBand());
|
||||
long wallTotal = 0L;
|
||||
long wallHigh = 0L;
|
||||
for (int step = 0; step < HISTOGRAM; step++) {
|
||||
wallHistogram[step] += wallCounts[step];
|
||||
wallTotal += wallCounts[step];
|
||||
wallHigh += step >= 8 ? wallCounts[step] : 0L;
|
||||
}
|
||||
stats.wall8 = wallTotal == 0L ? 0D : wallHigh / (double) wallTotal;
|
||||
long wallSeen = 0L;
|
||||
for (int step = 0; step < HISTOGRAM; step++) {
|
||||
wallSeen += wallCounts[step];
|
||||
if (wallSeen >= 0.9D * wallTotal) {
|
||||
stats.wallP90 = step;
|
||||
break;
|
||||
}
|
||||
}
|
||||
double headX = arm.xs()[0];
|
||||
double headZ = arm.zs()[0];
|
||||
int ahead = Math.min(arm.xs().length - 1, 8);
|
||||
double span = Math.max(1e-3D, Math.hypot(headX - arm.xs()[ahead], headZ - arm.zs()[ahead]));
|
||||
int[] forward = profile(columns, headX, headZ, (headX - arm.xs()[ahead]) / span, (headZ - arm.zs()[ahead]) / span, arm.halfWidth()[0], 32);
|
||||
stats.headRise8 = forward[Math.min(8, forward.length - 1)] - columns.sea;
|
||||
stats.headSteep = TidalReachMetrics.steepestRise(forward, 4);
|
||||
return stats;
|
||||
}
|
||||
|
||||
private static int[] profile(Columns columns, double x, double z, double nx, double nz, double half, int length) {
|
||||
int[] heights = new int[length + 1];
|
||||
for (int out = 0; out <= length; out++) {
|
||||
double d = half + out;
|
||||
heights[out] = Math.max(columns.sea, columns.height((int) Math.floor(x + nx * d), (int) Math.floor(z + nz * d)));
|
||||
}
|
||||
return heights;
|
||||
}
|
||||
|
||||
private static double walls(Reach reach, Columns columns, long[] histogram, int band) {
|
||||
float[] xs = reach.xs();
|
||||
float[] zs = reach.zs();
|
||||
List<double[]> stations = new ArrayList<>();
|
||||
double next = 0D;
|
||||
double along = 0D;
|
||||
for (int point = 1; point < xs.length; point++) {
|
||||
along += Math.hypot(xs[point] - xs[point - 1], zs[point] - zs[point - 1]);
|
||||
double dx = xs[point] - xs[point - 1];
|
||||
double dz = zs[point] - zs[point - 1];
|
||||
double span = Math.hypot(dx, dz);
|
||||
if (along < next || span <= 0D) {
|
||||
continue;
|
||||
}
|
||||
next = along + 2D;
|
||||
double rise = Double.POSITIVE_INFINITY;
|
||||
double[] sides = new double[2];
|
||||
for (int side = 0; side < 2; side++) {
|
||||
double sign = side == 0 ? 1D : -1D;
|
||||
int[] heights = profile(columns, xs[point], zs[point], -dz / span * sign, dx / span * sign, reach.halfWidth()[point], band);
|
||||
int surface = columns.head((int) Math.floor(xs[point]), (int) Math.floor(zs[point]));
|
||||
int base = surface == Integer.MIN_VALUE ? heights[0] : surface;
|
||||
sides[side] = heights[Math.min(8, band)] - base;
|
||||
histogram[Math.clamp((long) TidalReachMetrics.steepestRise(heights, 4), 0, HISTOGRAM - 1)]++;
|
||||
}
|
||||
stations.add(sides);
|
||||
}
|
||||
double[] left = new double[stations.size()];
|
||||
double[] right = new double[stations.size()];
|
||||
for (int station = 0; station < left.length; station++) {
|
||||
left[station] = stations.get(station)[0];
|
||||
right[station] = stations.get(station)[1];
|
||||
}
|
||||
return TidalReachMetrics.longestSlotRun(left, right, SLOT_RISE, 2D);
|
||||
}
|
||||
|
||||
private static void seams(Reach arm, Columns columns, int[] box, ArmStats stats) {
|
||||
for (int line = Math.ceilDiv(box[0], WindowKey.SIZE) * WindowKey.SIZE; line <= box[2]; line += WindowKey.SIZE) {
|
||||
for (int z = box[1]; z <= box[3]; z++) {
|
||||
@@ -864,6 +949,134 @@ public final class TidalReachProbe {
|
||||
return failures;
|
||||
}
|
||||
|
||||
private static long sections(HydrologyWindows.Target target, File out, int siteX, int siteZ) throws Exception {
|
||||
try (RealPackProbeSupport.Workspace workspace = RealPackProbeSupport.openWorkspace(target.pack(), target.dimension(), LOG);
|
||||
RealPackProbeSupport.EngineSession session = workspace.openEngine(target.seed(), false, "sections")) {
|
||||
Engine engine = session.engine();
|
||||
HydrologySettings settings = settings(engine);
|
||||
HydrologyPlanHarness.Plans plans = plans(engine, settings, target.windows().grown(1));
|
||||
IrisHydrologyTerrainSource terrain = new IrisHydrologyTerrainSource(engine.getComplex(), engine.getDimension(), settings, MultiBurst.hydrology,
|
||||
MultiBurst.hydrology.parallelism(), HydrologyBinding.UNBOUND);
|
||||
HydrologyPlanHarness.RasterCache rasters = new HydrologyPlanHarness.RasterCache(1 << 14, plans::rasterize);
|
||||
Columns columns = new Columns(rasters, terrain, plans, settings.seaLevel());
|
||||
List<Reach> arms = new ArrayList<>(owned(plans, target.windows(), true));
|
||||
Map<Long, Integer> cuts = new HashMap<>();
|
||||
for (Reach arm : arms) {
|
||||
cuts.put(arm.id(), armStats(arm, columns, new long[HISTOGRAM], new long[HISTOGRAM]).cut);
|
||||
}
|
||||
arms.sort(Comparator.comparingDouble((Reach arm) -> nearest(arm, siteX, siteZ)));
|
||||
List<Reach> chosen = new ArrayList<>(arms.subList(0, Math.min(1, arms.size())));
|
||||
arms.sort(Comparator.comparingInt((Reach arm) -> -cuts.get(arm.id())));
|
||||
for (Reach arm : arms) {
|
||||
if (chosen.size() < 4 && !chosen.contains(arm)) {
|
||||
chosen.add(arm);
|
||||
}
|
||||
}
|
||||
int height = engine.getTarget().getHeight();
|
||||
int sea = settings.seaLevel();
|
||||
Set<Long> chunks = new TreeSet<>();
|
||||
for (Reach arm : chosen) {
|
||||
int[] box = box(arm, 64);
|
||||
for (int chunkZ = box[1] >> 4; chunkZ <= box[3] >> 4; chunkZ++) {
|
||||
for (int chunkX = box[0] >> 4; chunkX <= box[2] >> 4; chunkX++) {
|
||||
chunks.add(key(chunkX, chunkZ));
|
||||
}
|
||||
}
|
||||
}
|
||||
Map<Long, Slab> slabs = new ConcurrentHashMap<>();
|
||||
Map<Long, int[]> colors = new ConcurrentHashMap<>();
|
||||
ExecutorService pool = Executors.newFixedThreadPool(6);
|
||||
try {
|
||||
List<Future<?>> futures = new ArrayList<>();
|
||||
for (long chunk : chunks) {
|
||||
futures.add(pool.submit(() -> {
|
||||
int chunkX = (int) (chunk >> 32);
|
||||
int chunkZ = (int) chunk;
|
||||
Hunk<NativeBlockState> blocks = Hunk.newArrayHunk(16, height, 16);
|
||||
Hunk<NativeBiome> biomes = Hunk.newArrayHunk(16, height, 16);
|
||||
engine.generate(chunkX << 4, chunkZ << 4, blocks, biomes, false);
|
||||
slabs.put(chunk, Slab.capture(blocks, height, sea));
|
||||
int[] painted = new int[256 * SECTION_LEVELS];
|
||||
for (int lz = 0; lz < 16; lz++) {
|
||||
for (int lx = 0; lx < 16; lx++) {
|
||||
for (int level = 0; level < SECTION_LEVELS; level++) {
|
||||
NativeBlockState state = blocks.get(lx, sea - SECTION_BELOW + level, lz);
|
||||
painted[(lz << 4 | lx) * SECTION_LEVELS + level] = state == null || state.isAir() ? 0x101820 : Slab.color(state);
|
||||
}
|
||||
}
|
||||
}
|
||||
colors.put(chunk, painted);
|
||||
return null;
|
||||
}));
|
||||
}
|
||||
for (Future<?> future : futures) {
|
||||
future.get();
|
||||
}
|
||||
} finally {
|
||||
pool.shutdown();
|
||||
}
|
||||
for (Reach arm : chosen) {
|
||||
ImageIO.write(sectionSheet(arm, slabs, colors, sea), "png", new File(out, "sections-" + target.seed() + "-" + Math.round(arm.xs()[0]) + "_" + Math.round(arm.zs()[0]) + ".png"));
|
||||
ArmStats stats = armStats(arm, columns, new long[HISTOGRAM], new long[HISTOGRAM]);
|
||||
int last = arm.xs().length - 1;
|
||||
System.out.printf(Locale.ROOT, "%s SECTION head=%.0f,%.0f mouth=%.0f,%.0f nearestSite=%.0f length=%.0f sinuosity=%.2f cut=%d wallP90=%.0f wall8=%.3f slotRun=%.0f headRise8=%d headSteep=%.0f%n", LOG,
|
||||
arm.xs()[0], arm.zs()[0], arm.xs()[last], arm.zs()[last], nearest(arm, siteX, siteZ), TidalReachMetrics.length(arm.xs(), arm.zs()), TidalReachMetrics.sinuosity(arm.xs(), arm.zs()),
|
||||
stats.cut, stats.wallP90, stats.wall8, stats.slotRun, stats.headRise8, stats.headSteep);
|
||||
}
|
||||
}
|
||||
return 0L;
|
||||
}
|
||||
|
||||
private static double nearest(Reach arm, int x, int z) {
|
||||
double best = Double.POSITIVE_INFINITY;
|
||||
for (int point = 0; point < arm.xs().length; point++) {
|
||||
best = Math.min(best, Math.hypot(arm.xs()[point] - x, arm.zs()[point] - z));
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
private static BufferedImage sectionSheet(Reach arm, Map<Long, Slab> slabs, Map<Long, int[]> colors, int sea) {
|
||||
List<BufferedImage> parts = new ArrayList<>();
|
||||
parts.add(blockCrop(arm, slabs, sea));
|
||||
int last = arm.xs().length - 1;
|
||||
double[] shares = {0.03D, 0.15D, 0.3D, 0.5D, 0.7D, 0.9D};
|
||||
for (double share : shares) {
|
||||
int point = Math.clamp(Math.round(share * last), 1, last);
|
||||
double dx = arm.xs()[point] - arm.xs()[point - 1];
|
||||
double dz = arm.zs()[point] - arm.zs()[point - 1];
|
||||
double span = Math.max(1e-3D, Math.hypot(dx, dz));
|
||||
parts.add(slice(arm.xs()[point], arm.zs()[point], -dz / span, dx / span, -64, 64, colors, Math.round(share * 100) + "% from head"));
|
||||
}
|
||||
int ahead = Math.min(last, 8);
|
||||
double span = Math.max(1e-3D, Math.hypot(arm.xs()[0] - arm.xs()[ahead], arm.zs()[0] - arm.zs()[ahead]));
|
||||
parts.add(slice(arm.xs()[0], arm.zs()[0], (arm.xs()[0] - arm.xs()[ahead]) / span, (arm.zs()[0] - arm.zs()[ahead]) / span, -32, 64, colors, "along the head"));
|
||||
return montage(parts);
|
||||
}
|
||||
|
||||
private static BufferedImage slice(double x, double z, double nx, double nz, int from, int to, Map<Long, int[]> colors, String label) {
|
||||
int width = to - from + 1;
|
||||
int scale = 3;
|
||||
BufferedImage image = new BufferedImage(width * scale, SECTION_LEVELS * scale + 14, BufferedImage.TYPE_INT_RGB);
|
||||
for (int across = 0; across < width; across++) {
|
||||
int cx = (int) Math.floor(x + nx * (from + across));
|
||||
int cz = (int) Math.floor(z + nz * (from + across));
|
||||
int[] painted = colors.get(key(cx >> 4, cz >> 4));
|
||||
for (int level = 0; level < SECTION_LEVELS; level++) {
|
||||
int rgb = painted == null ? 0 : painted[((cz & 15) << 4 | (cx & 15)) * SECTION_LEVELS + level];
|
||||
for (int dx = 0; dx < scale; dx++) {
|
||||
for (int dy = 0; dy < scale; dy++) {
|
||||
image.setRGB(across * scale + dx, (SECTION_LEVELS - 1 - level) * scale + dy + 14, rgb);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Graphics2D graphics = image.createGraphics();
|
||||
graphics.setColor(Color.WHITE);
|
||||
graphics.drawString(label + " at " + Math.round(x) + "," + Math.round(z), 2, 11);
|
||||
graphics.dispose();
|
||||
return image;
|
||||
}
|
||||
|
||||
private static long rivers(HydrologyWindows.Target target, File out) throws Exception {
|
||||
try (RealPackProbeSupport.Workspace workspace = RealPackProbeSupport.openWorkspace(target.pack(), target.dimension(), LOG);
|
||||
RealPackProbeSupport.EngineSession session = workspace.openEngine(target.seed(), false, "rivers");
|
||||
|
||||
@@ -45,4 +45,18 @@ public class TidalReachMetricsTest {
|
||||
assertTrue(TidalReachMetrics.straightRun(xs, zs) < 24D);
|
||||
assertEquals(1D, TidalReachMetrics.percentile(new double[]{0D, 1D, 2D}, 0.5D), 0D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void slotRunFindsWallsOnBothSidesAtOnce() {
|
||||
double[] left = {30D, 30D, 30D, 30D, 2D, 30D};
|
||||
double[] right = {30D, 30D, 30D, 30D, 30D, 2D};
|
||||
assertEquals(8D, TidalReachMetrics.longestSlotRun(left, right, 16D, 2D), 0D);
|
||||
assertEquals(0D, TidalReachMetrics.longestSlotRun(new double[]{30D, 2D}, new double[]{2D, 30D}, 16D, 2D), 0D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void steepestRiseSeesASheerWallNotAGradedBank() {
|
||||
assertEquals(30D, TidalReachMetrics.steepestRise(new int[]{0, 0, 30, 30, 30, 30, 30}, 4), 0D);
|
||||
assertEquals(4D, TidalReachMetrics.steepestRise(new int[]{0, 1, 2, 3, 4, 5, 6}, 4), 0D);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user