mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 16:25:36 +00:00
Let packs tune cave tunnels, caverns and pillars separately
A tunnel's stretch and flatness become spacing.horizontal and spacing.vertical. The bend, the width noise and the coverage patches were all derived from stretch through fixed constants; each now has its own key. warp is a noise style whose zoom sets how often a tunnel turns and whose multiplier sets how far it swings, as in object placement. A flat warp keeps tunnels straight. width is a styled range sampled in 3D, and coverage is a share plus an optional style. Left out, each falls back to what stretch used to give, so a tunnel needs only spacing. The new tunnel height turns the round cross-section into an oval. The distance to the line is measured with the vertical axis stretched by width over height, so the width stays what the pack asks for. A height equal to the width carves exactly the round tunnel. Caverns and pillars take an optional style. Size, height and spacing stay in blocks for any style: the shape measures the style's feature spacing at load and rescales it until it matches. That costs under 10 ms per cave, and a fracture keeps its distance in blocks. Pillars gain flare, which replaces the fixed foot area of 4, and vertical, which reads the pillar field in 3D on the lattice so pillars lean, pinch and break off. Without vertical the per-column cache still decides. The old keys are gone. Written with the new keys, the old caves carve block for block what they carved before, which the carver test pins for five caves, and the carve harness digest matches the old code for the same cave.
This commit is contained in:
1 parent
22d69f362f
commit
5695cf053e
12 files changed
+842
-136
No files matched your search
@@ -48,8 +48,8 @@ public class CarvePipelineHarnessTest {
|
||||
private static final long SEED = 424242L;
|
||||
private static final int APPLIED_CHUNKS_PER_SIDE = 6;
|
||||
private static final int CARVE_RING = 1;
|
||||
private static final String VOIDS_DIGEST = "630fef28ea2529d4";
|
||||
private static final String BLOCKS_DIGEST = "58fbce572cb007d4";
|
||||
private static final String VOIDS_DIGEST = "5624cb08f2804752";
|
||||
private static final String BLOCKS_DIGEST = "7dbd8ad0cb967121";
|
||||
|
||||
private static final BlockState STONE = new BlockState("minecraft:stone");
|
||||
private static final BlockState AIR = new BlockState("minecraft:air");
|
||||
@@ -220,7 +220,7 @@ public class CarvePipelineHarnessTest {
|
||||
|
||||
private static Cave cave() {
|
||||
return TestSettings.of(Cave.class, """
|
||||
{"tunnel": {"width": {"min": 3, "max": 5}, "stretch": 40},
|
||||
{"tunnel": {"width": {"min": 3, "max": 5}, "spacing": {"horizontal": 40, "vertical": 32}},
|
||||
"cavern": {"size": 32, "height": 14, "coverage": 0.12, "pillars": {"spacing": 12, "thickness": 3}},
|
||||
"opensToSurface": true, "fade": 4}
|
||||
""");
|
||||
|
||||
@@ -24,10 +24,10 @@ import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class CaveScenesTest {
|
||||
private static final String MIXED = """
|
||||
{"tunnel": {"width": {"min": 4, "max": 6}, "stretch": 48},
|
||||
{"tunnel": {"width": {"min": 4, "max": 6}, "spacing": {"horizontal": 48, "vertical": 34}},
|
||||
"cavern": {"size": 40, "height": 18, "coverage": 0.2, "pillars": {"spacing": 14, "thickness": 4}}}
|
||||
""";
|
||||
private static final String TUNNELS_ONLY = "{\"tunnel\": {\"width\": {\"min\": 4, \"max\": 6}, \"stretch\": 48}}";
|
||||
private static final String TUNNELS_ONLY = "{\"tunnel\": {\"width\": {\"min\": 4, \"max\": 6}, \"spacing\": {\"horizontal\": 48, \"vertical\": 34}}}";
|
||||
private static final String TUNNEL_BLOCK = "minecraft:light_blue_concrete";
|
||||
private static final String CAVERN_BLOCK = "minecraft:orange_concrete";
|
||||
private static final int[][] NEIGHBOURS = {{1, 0, 0}, {-1, 0, 0}, {0, 1, 0}, {0, -1, 0}, {0, 0, 1}, {0, 0, -1}};
|
||||
|
||||
@@ -4,11 +4,13 @@ import art.arcane.iris.core.modules.CarveTestWorld;
|
||||
import art.arcane.iris.engine.object.TestSettings;
|
||||
import art.arcane.iris.modules.carve.Cave;
|
||||
import com.volmit.noise.NoiseFactory;
|
||||
import com.volmit.noise.NoiseStyle;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Arrays;
|
||||
import java.util.BitSet;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
@@ -23,10 +25,59 @@ public class CaveCarverTest {
|
||||
private static final int WORLD_BOTTOM_Y = 0;
|
||||
private static final int WORLD_HEIGHT = 256;
|
||||
private static final long SEED = 91_277L;
|
||||
private static final String TUNNELS = "{\"tunnel\": {\"width\": {\"min\": 4, \"max\": 6}, \"stretch\": 48}, \"opensToSurface\": true}";
|
||||
private static final String TUNNELS = "{\"tunnel\": {\"width\": {\"min\": 4, \"max\": 6}, \"spacing\": {\"horizontal\": 48, \"vertical\": 34}}, \"opensToSurface\": true}";
|
||||
private static final String OPEN_CAVERN = "{\"cavern\": {\"size\": 40, \"height\": 18, \"coverage\": 0.3}}";
|
||||
|
||||
private final NoiseFactory noise = new CarveTestWorld().resources().noise();
|
||||
|
||||
/**
|
||||
* Each cave written with the new keys, and the size and hash of what the same cave written with the keys it replaced
|
||||
* carved before them (stretch, flatness, a plain coverage, no flare): the defaults reproduce it block for block.
|
||||
*/
|
||||
private record Before(String cave, int carved, int hash) {
|
||||
}
|
||||
|
||||
private static final List<Before> CARVED_BEFORE = List.of(
|
||||
new Before("{\"tunnel\": {\"width\": {\"min\": 4, \"max\": 6}, \"spacing\": {\"horizontal\": 48, \"vertical\": 32}}, \"opensToSurface\": true}",
|
||||
232_825, 1_872_688_103),
|
||||
new Before("{\"tunnel\": {\"width\": {\"min\": 3, \"max\": 6}, \"spacing\": {\"horizontal\": 64, \"vertical\": 32}, \"coverage\": {\"share\": 0.5}}, \"opensToSurface\": true}",
|
||||
48_888, 132_276_646),
|
||||
new Before("{\"cavern\": {\"size\": 40, \"height\": 18, \"coverage\": 0.3, \"pillars\": {\"spacing\": 14, \"thickness\": 4}}}",
|
||||
562_402, 1_318_811_955),
|
||||
new Before("{\"tunnel\": {\"width\": {\"min\": 3, \"max\": 5}, \"spacing\": {\"horizontal\": 40, \"vertical\": 32}, \"coverage\": {\"share\": 0.6}},"
|
||||
+ " \"cavern\": {\"size\": 32, \"height\": 14, \"coverage\": 0.12, \"pillars\": {\"spacing\": 12, \"thickness\": 3}}}",
|
||||
290_404, 533_697_483),
|
||||
new Before("{\"cavern\": {\"size\": 110, \"height\": 40, \"coverage\": 0.18, \"pillars\": {\"spacing\": 26, \"thickness\": 5}}, \"fade\": 14, \"surfaceClearance\": 16}",
|
||||
478_805, -890_025_259));
|
||||
|
||||
@Test
|
||||
public void theDefaultsCarveBlockForBlockWhatTheReplacedKeysCarved() {
|
||||
for (Before before : CARVED_BEFORE) {
|
||||
BitSet carved = carve(before.cave(), SEED, false);
|
||||
|
||||
assertEquals(before.cave(), before.carved(), carved.cardinality());
|
||||
assertEquals(before.cave(), before.hash(), carved.hashCode());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void spelledOutStylesCarveRoughlyWhatTheirDefaultsCarve() {
|
||||
String defaults = "{\"tunnel\": {\"width\": {\"min\": 2, \"max\": 3}, \"spacing\": {\"horizontal\": 64, \"vertical\": 53}, \"coverage\": {\"share\": 0.4}}, \"surfaceClearance\": 6}";
|
||||
String spelledOut = """
|
||||
{"tunnel": {
|
||||
"width": {"min": 2, "max": 3, "style": {"style": "SIMPLEX", "zoom": 1.2}},
|
||||
"spacing": {"horizontal": 64, "vertical": 53},
|
||||
"warp": {"style": "SIMPLEX", "zoom": 0.25, "multiplier": 8},
|
||||
"coverage": {"share": 0.4, "style": {"style": "SIMPLEX", "zoom": 2.4}}},
|
||||
"surfaceClearance": 6}
|
||||
""";
|
||||
|
||||
int byDefaults = carve(defaults, SEED, false).cardinality();
|
||||
int bySpelledOut = carve(spelledOut, SEED, false).cardinality();
|
||||
|
||||
assertWithin("spelled out against defaults", bySpelledOut, byDefaults, 0.2D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void theSameSeedCarvesTheSameCaveAndAnotherSeedADifferentOne() {
|
||||
BitSet first = carve(TUNNELS, SEED, false);
|
||||
@@ -47,7 +98,7 @@ public class CaveCarverTest {
|
||||
|
||||
@Test
|
||||
public void thinTunnelsSurviveBetweenTheLatticePoints() {
|
||||
BitSet carved = carve("{\"tunnel\": {\"width\": {\"min\": 2, \"max\": 3}, \"stretch\": 48}, \"opensToSurface\": true}", SEED, false);
|
||||
BitSet carved = carve(tunnel("\"width\": {\"min\": 2, \"max\": 3}, \"spacing\": {\"horizontal\": 48, \"vertical\": 34}"), SEED, false);
|
||||
|
||||
double largestShare = largestConnectedShare(carved);
|
||||
|
||||
@@ -55,12 +106,126 @@ public class CaveCarverTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pillarsLeaveRockStandingInACavern() {
|
||||
String open = "{\"cavern\": {\"size\": 40, \"height\": 18, \"coverage\": 0.3}}";
|
||||
String pillared = "{\"cavern\": {\"size\": 40, \"height\": 18, \"coverage\": 0.3, \"pillars\": {\"spacing\": 14, \"thickness\": 4}}}";
|
||||
public void widerSpacingCarvesSparserTunnels() {
|
||||
int close = carve(tunnel("\"spacing\": {\"horizontal\": 48, \"vertical\": 34}"), SEED, false).cardinality();
|
||||
int wide = carve(tunnel("\"spacing\": {\"horizontal\": 96, \"vertical\": 34}"), SEED, false).cardinality();
|
||||
|
||||
BitSet withoutPillars = carve(open, SEED, false);
|
||||
BitSet withPillars = carve(pillared, SEED, false);
|
||||
assertTrue(close + " close against " + wide + " wide", wide < close * 0.75D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void closerVerticalSpacingStacksMoreTunnels() {
|
||||
int far = carve(tunnel("\"spacing\": {\"horizontal\": 64, \"vertical\": 64}"), SEED, false).cardinality();
|
||||
int close = carve(tunnel("\"spacing\": {\"horizontal\": 64, \"vertical\": 24}"), SEED, false).cardinality();
|
||||
|
||||
assertTrue(far + " far apart against " + close + " close", close > far * 1.4D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aFlatWarpLeavesTheTunnelsWhereTheSheetsMeet() {
|
||||
String spacing = "\"spacing\": {\"horizontal\": 48, \"vertical\": 34}, ";
|
||||
BitSet flat = carve(tunnel(spacing + "\"warp\": {\"style\": \"FLAT\", \"multiplier\": 30}"), SEED, false);
|
||||
BitSet barelyMoved = carve(tunnel(spacing + "\"warp\": {\"style\": \"SIMPLEX\", \"multiplier\": 0.0001}"), SEED, false);
|
||||
BitSet swung = carve(tunnel(spacing + "\"warp\": {\"style\": \"SIMPLEX\", \"zoom\": 0.3, \"multiplier\": 16}"), SEED, false);
|
||||
|
||||
assertTrue("a flat warp moves nothing: " + differenceShare(flat, barelyMoved), differenceShare(flat, barelyMoved) < 0.002D);
|
||||
assertTrue("a warp moves the tunnels: " + differenceShare(flat, swung), differenceShare(flat, swung) > 0.5D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aLargerWarpMultiplierSwingsTheTunnelsFurther() {
|
||||
String spacing = "\"spacing\": {\"horizontal\": 48, \"vertical\": 34}, ";
|
||||
BitSet flat = carve(tunnel(spacing + "\"warp\": {}"), SEED, false);
|
||||
BitSet small = carve(tunnel(spacing + "\"warp\": {\"style\": \"SIMPLEX\", \"zoom\": 0.3, \"multiplier\": 1}"), SEED, false);
|
||||
BitSet large = carve(tunnel(spacing + "\"warp\": {\"style\": \"SIMPLEX\", \"zoom\": 0.3, \"multiplier\": 12}"), SEED, false);
|
||||
|
||||
assertTrue(differenceShare(flat, small) < differenceShare(flat, large));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aWidthStyleDecidesWhereTunnelsAreNarrowOrWide() {
|
||||
String spacing = "\"spacing\": {\"horizontal\": 48, \"vertical\": 34}, ";
|
||||
BitSet slow = carve(tunnel(spacing + "\"width\": {\"min\": 2, \"max\": 8}"), SEED, false);
|
||||
BitSet styled = carve(tunnel(spacing + "\"width\": {\"min\": 2, \"max\": 8, \"style\": {\"style\": \"SIMPLEX\", \"zoom\": 0.2}}"), SEED, false);
|
||||
BitSet even = carve(tunnel(spacing + "\"width\": {\"min\": 5, \"max\": 5}"), SEED, false);
|
||||
|
||||
assertTrue(differenceShare(slow, styled) > 0.2D);
|
||||
assertTrue(differenceShare(slow, even) > 0.2D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aHeightAsLargeAsTheWidthCarvesRoundTunnels() {
|
||||
String spacing = "\"spacing\": {\"horizontal\": 48, \"vertical\": 34}, ";
|
||||
|
||||
BitSet round = carve(tunnel(spacing + "\"width\": {\"min\": 3, \"max\": 6}"), SEED, false);
|
||||
BitSet ovalAsRound = carve(tunnel(spacing + "\"width\": {\"min\": 3, \"max\": 6}, \"height\": {\"min\": 3, \"max\": 6}"), SEED, false);
|
||||
|
||||
assertEquals(round, ovalAsRound);
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs along an axis also cross sloping tunnels lengthwise, so they change less than the height does: a sloping
|
||||
* tunnel's vertical chord is partly its length, and its horizontal runs grow with its height.
|
||||
*/
|
||||
@Test
|
||||
public void aHeightChangesHowTallTunnelsAreRatherThanHowWide() {
|
||||
String spacing = "\"spacing\": {\"horizontal\": 48, \"vertical\": 34}, ";
|
||||
BitSet round = carve(tunnel(spacing + "\"width\": {\"min\": 6, \"max\": 6}"), SEED, false);
|
||||
BitSet tall = carve(tunnel(spacing + "\"width\": {\"min\": 6, \"max\": 6}, \"height\": {\"min\": 12, \"max\": 12}"), SEED, false);
|
||||
BitSet low = carve(tunnel(spacing + "\"width\": {\"min\": 6, \"max\": 6}, \"height\": {\"min\": 3, \"max\": 3}"), SEED, false);
|
||||
|
||||
double tallHeight = meanRun(tall, 0, 1, 0) / meanRun(round, 0, 1, 0);
|
||||
double tallWidth = horizontalMeanRun(tall) / horizontalMeanRun(round);
|
||||
double lowHeight = meanRun(low, 0, 1, 0) / meanRun(round, 0, 1, 0);
|
||||
double lowWidth = horizontalMeanRun(low) / horizontalMeanRun(round);
|
||||
|
||||
assertTrue("tall: height " + tallHeight + ", width " + tallWidth, tallHeight > 1.3D && tallWidth < 1.15D);
|
||||
assertTrue("low: height " + lowHeight + ", width " + lowWidth, lowHeight < 0.75D && lowWidth > 0.85D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aLowerCoverageShareLeavesMoreRockAndAStyleShapesWhere() {
|
||||
String spacing = "\"spacing\": {\"horizontal\": 48, \"vertical\": 34}, ";
|
||||
BitSet everywhere = carve(tunnel(spacing + "\"coverage\": {\"share\": 1}"), SEED, false);
|
||||
BitSet half = carve(tunnel(spacing + "\"coverage\": {\"share\": 0.5}"), SEED, false);
|
||||
BitSet styledHalf = carve(tunnel(spacing + "\"coverage\": {\"share\": 0.5, \"style\": {\"style\": \"SIMPLEX\", \"zoom\": 0.6}}"), SEED, false);
|
||||
|
||||
assertTrue(half.cardinality() < everywhere.cardinality() * 0.8D);
|
||||
assertTrue(styledHalf.cardinality() < everywhere.cardinality() * 0.8D);
|
||||
assertTrue(differenceShare(half, styledHalf) > 0.2D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aRoomStyleIsScaledToTheRoomSize() {
|
||||
NoiseStyle cellular = TestSettings.of(NoiseStyle.class, "{\"style\": \"CELLULAR\"}");
|
||||
NoiseStyle simplex = TestSettings.of(NoiseStyle.class, "{\"style\": \"SIMPLEX\", \"zoom\": 7}");
|
||||
|
||||
for (NoiseStyle style : List.of(cellular, simplex)) {
|
||||
for (double spacing : new double[]{30D, 150D}) {
|
||||
Field3 field = new CaveNoise(noise, SEED).scaledTo(style, spacing, spacing);
|
||||
|
||||
double measured = FieldStats.featureBlocks(field, spacing).orElseThrow();
|
||||
|
||||
assertWithin(style + " at " + spacing, measured, spacing, 0.15D);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aCavernWithAStyleCarvesItsShareInOtherRooms() {
|
||||
String styled = "{\"cavern\": {\"size\": 40, \"height\": 18, \"coverage\": 0.3, \"style\": {\"style\": \"CELLULAR\", \"fracture\": {\"style\": \"SIMPLEX\", \"multiplier\": 12}}}}";
|
||||
|
||||
BitSet byDefault = carve(OPEN_CAVERN, SEED, false);
|
||||
BitSet byStyle = carve(styled, SEED, false);
|
||||
|
||||
assertWithin("styled against default", byStyle.cardinality(), byDefault.cardinality(), 0.5D);
|
||||
assertTrue(differenceShare(byDefault, byStyle) > 0.5D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pillarsLeaveRockStandingInACavern() {
|
||||
BitSet withoutPillars = carve(OPEN_CAVERN, SEED, false);
|
||||
BitSet withPillars = carve(pillared("\"spacing\": 14, \"thickness\": 4"), SEED, false);
|
||||
|
||||
assertTrue(withPillars.cardinality() < withoutPillars.cardinality());
|
||||
BitSet onlyWithPillars = (BitSet) withPillars.clone();
|
||||
@@ -68,9 +233,49 @@ public class CaveCarverTest {
|
||||
assertTrue("pillars only ever keep rock", onlyWithPillars.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pillarsWithoutVerticalAndFlareAreTheSameFromFloorToCeiling() {
|
||||
BitSet open = carve(OPEN_CAVERN, SEED, false);
|
||||
BitSet straight = carve(pillared("\"spacing\": 14, \"thickness\": 4, \"flare\": 1"), SEED, false);
|
||||
|
||||
assertEquals(0, columnsPartlyKept(open, straight));
|
||||
assertTrue(open.cardinality() > straight.cardinality());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void flarePillarsWidenTowardsFloorAndCeiling() {
|
||||
BitSet straight = carve(pillared("\"spacing\": 14, \"thickness\": 4, \"flare\": 1"), SEED, false);
|
||||
BitSet flared = carve(pillared("\"spacing\": 14, \"thickness\": 4, \"flare\": 6"), SEED, false);
|
||||
BitSet open = carve(OPEN_CAVERN, SEED, false);
|
||||
|
||||
assertTrue(flared.cardinality() < straight.cardinality());
|
||||
assertTrue(columnsPartlyKept(open, flared) > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verticalLetsPillarsChangeWithHeight() {
|
||||
BitSet open = carve(OPEN_CAVERN, SEED, false);
|
||||
BitSet changing = carve(pillared("\"spacing\": 14, \"thickness\": 4, \"flare\": 1, \"vertical\": 16"), SEED, false);
|
||||
|
||||
assertTrue(columnsPartlyKept(open, changing) > 0);
|
||||
BitSet onlyWithPillars = (BitSet) changing.clone();
|
||||
onlyWithPillars.andNot(open);
|
||||
assertTrue("pillars only ever keep rock", onlyWithPillars.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aPillarStyleMovesThePillars() {
|
||||
BitSet byDefault = carve(pillared("\"spacing\": 14, \"thickness\": 4"), SEED, false);
|
||||
BitSet byStyle = carve(pillared("\"spacing\": 14, \"thickness\": 4, \"style\": {\"style\": \"CELLULAR\"}"), SEED, false);
|
||||
BitSet open = carve(OPEN_CAVERN, SEED, false);
|
||||
|
||||
assertNotEquals(byDefault, byStyle);
|
||||
assertTrue(byStyle.cardinality() < open.cardinality());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aCaveOpensTheSurfaceOnlyWhereItMayAndKeepsItsRockElsewhere() {
|
||||
String cave = "{\"tunnel\": {\"width\": {\"min\": 5, \"max\": 7}, \"stretch\": 32}, \"opensToSurface\": true, \"surfaceClearance\": 10}";
|
||||
String cave = "{\"tunnel\": {\"width\": {\"min\": 5, \"max\": 7}, \"spacing\": {\"horizontal\": 32, \"vertical\": 23}}, \"opensToSurface\": true, \"surfaceClearance\": 10}";
|
||||
|
||||
BitSet open = carve(cave, SEED, false);
|
||||
BitSet sealed = carve(cave, SEED, true);
|
||||
@@ -79,6 +284,18 @@ public class CaveCarverTest {
|
||||
assertTrue("a sealed cave keeps its clearance: " + highestCarvedY(sealed), highestCarvedY(sealed) <= SURFACE_Y - 10);
|
||||
}
|
||||
|
||||
private static String tunnel(String keys) {
|
||||
return "{\"tunnel\": {" + keys + "}, \"opensToSurface\": true}";
|
||||
}
|
||||
|
||||
private static String pillared(String pillarKeys) {
|
||||
return "{\"cavern\": {\"size\": 40, \"height\": 18, \"coverage\": 0.3, \"pillars\": {" + pillarKeys + "}}}";
|
||||
}
|
||||
|
||||
private static void assertWithin(String what, double actual, double expected, double share) {
|
||||
assertTrue(what + ": " + actual + " against " + expected, Math.abs(actual - expected) <= expected * share);
|
||||
}
|
||||
|
||||
private BitSet carve(String caveJson, long seed, boolean sealEveryColumn) {
|
||||
CaveCarver carver = new CaveCarver(TestSettings.of(Cave.class, caveJson), noise, seed, WORLD_BOTTOM_Y, WORLD_HEIGHT);
|
||||
int[] surfaceY = new int[256];
|
||||
@@ -106,6 +323,64 @@ public class CaveCarverTest {
|
||||
return (carved.length() - 1) / (SIZE * SIZE);
|
||||
}
|
||||
|
||||
/** Share of the blocks either set carves that only one of them carves. */
|
||||
private static double differenceShare(BitSet first, BitSet second) {
|
||||
BitSet either = (BitSet) first.clone();
|
||||
either.or(second);
|
||||
BitSet onlyOne = (BitSet) first.clone();
|
||||
onlyOne.xor(second);
|
||||
return onlyOne.cardinality() / (double) Math.max(1, either.cardinality());
|
||||
}
|
||||
|
||||
/** Columns where pillars keep some, but not all, of the blocks the open cavern carves. */
|
||||
private static int columnsPartlyKept(BitSet open, BitSet pillared) {
|
||||
int partly = 0;
|
||||
for (int x = 0; x < SIZE; x++) {
|
||||
for (int z = 0; z < SIZE; z++) {
|
||||
int kept = 0;
|
||||
int carvedOpen = 0;
|
||||
for (int y = 0; y < LAYERS; y++) {
|
||||
int block = index(x, y, z);
|
||||
if (!open.get(block)) {
|
||||
continue;
|
||||
}
|
||||
carvedOpen++;
|
||||
if (!pillared.get(block)) {
|
||||
kept++;
|
||||
}
|
||||
}
|
||||
if (kept > 0 && kept < carvedOpen) {
|
||||
partly++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return partly;
|
||||
}
|
||||
|
||||
private static double horizontalMeanRun(BitSet carved) {
|
||||
return (meanRun(carved, 1, 0, 0) + meanRun(carved, 0, 0, 1)) / 2D;
|
||||
}
|
||||
|
||||
/** Mean length of the unbroken runs of carved blocks along one axis. */
|
||||
private static double meanRun(BitSet carved, int stepX, int stepY, int stepZ) {
|
||||
long blocks = 0;
|
||||
long runs = 0;
|
||||
for (int block = carved.nextSetBit(0); block >= 0; block = carved.nextSetBit(block + 1)) {
|
||||
int x = block % SIZE;
|
||||
int z = (block / SIZE) % SIZE;
|
||||
int y = block / (SIZE * SIZE);
|
||||
blocks++;
|
||||
int previousX = x - stepX;
|
||||
int previousY = y - stepY;
|
||||
int previousZ = z - stepZ;
|
||||
boolean previousInside = previousX >= 0 && previousY >= 0 && previousZ >= 0;
|
||||
if (!previousInside || !carved.get(index(previousX, previousY, previousZ))) {
|
||||
runs++;
|
||||
}
|
||||
}
|
||||
return blocks / (double) Math.max(1, runs);
|
||||
}
|
||||
|
||||
private static double largestConnectedShare(BitSet carved) {
|
||||
BitSet seen = new BitSet(carved.size());
|
||||
ArrayDeque<Integer> open = new ArrayDeque<>();
|
||||
|
||||
@@ -21,6 +21,7 @@ package art.arcane.iris.modules.carve;
|
||||
import com.volmit.config.Desc;
|
||||
import com.volmit.config.MaxNumber;
|
||||
import com.volmit.config.MinNumber;
|
||||
import com.volmit.noise.NoiseStyle;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -42,12 +43,20 @@ public final class CaveCavern {
|
||||
@Desc("Share of the underground that is cavern. 0.1 gives scattered rooms, 0.3 joins them into halls.")
|
||||
private double coverage = 0.1;
|
||||
|
||||
@Desc("Noise that shapes the rooms. Scaled to size and height, so its zoom has no effect; a fracture stays in blocks. Detail under about 12 blocks is lost. Leave out for smooth rooms with rough walls.")
|
||||
private NoiseStyle style;
|
||||
|
||||
@Desc("Rock columns left standing inside the rooms. Leave out for open rooms.")
|
||||
private CavePillars pillars;
|
||||
|
||||
public CaveCavern() {
|
||||
}
|
||||
|
||||
/** The noise that shapes the rooms; empty where the pack wrote none. */
|
||||
public Optional<NoiseStyle> style() {
|
||||
return Optional.ofNullable(style);
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return size;
|
||||
}
|
||||
|
||||
@@ -21,6 +21,10 @@ package art.arcane.iris.modules.carve;
|
||||
import com.volmit.config.Desc;
|
||||
import com.volmit.config.MaxNumber;
|
||||
import com.volmit.config.MinNumber;
|
||||
import com.volmit.noise.NoiseStyle;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.OptionalInt;
|
||||
|
||||
/** The pillars of a {@link CaveCavern}: columns of rock left standing from floor to ceiling. */
|
||||
@Desc("Rock columns left standing inside caverns.")
|
||||
@@ -35,9 +39,36 @@ public final class CavePillars {
|
||||
@Desc("Rough thickness of a pillar at its middle, in blocks. Pillars widen towards floor and ceiling.")
|
||||
private int thickness = 4;
|
||||
|
||||
@MinNumber(1)
|
||||
@MaxNumber(16)
|
||||
@Desc("How many times more ground a pillar covers at floor and ceiling than at its middle. 1 gives straight columns.")
|
||||
private double flare = 4;
|
||||
|
||||
@MinNumber(8)
|
||||
@MaxNumber(512)
|
||||
@Desc("Blocks over which the pillars change with height, so they lean, pinch and break off. Detail under about 12 blocks is lost. Leave out for columns that run straight from floor to ceiling.")
|
||||
private Integer vertical;
|
||||
|
||||
@Desc("Noise that places the pillars. Scaled to spacing, so its zoom has no effect; a fracture stays in blocks. Leave out for evenly scattered pillars.")
|
||||
private NoiseStyle style;
|
||||
|
||||
public CavePillars() {
|
||||
}
|
||||
|
||||
public double flare() {
|
||||
return flare;
|
||||
}
|
||||
|
||||
/** Blocks over which the pillars change with height; empty for pillars that run straight. */
|
||||
public OptionalInt vertical() {
|
||||
return vertical == null ? OptionalInt.empty() : OptionalInt.of(vertical);
|
||||
}
|
||||
|
||||
/** The noise that places the pillars; empty where the pack wrote none. */
|
||||
public Optional<NoiseStyle> style() {
|
||||
return Optional.ofNullable(style);
|
||||
}
|
||||
|
||||
public int spacing() {
|
||||
return spacing;
|
||||
}
|
||||
|
||||
@@ -19,47 +19,69 @@
|
||||
package art.arcane.iris.modules.carve;
|
||||
|
||||
import com.volmit.config.Desc;
|
||||
import com.volmit.config.MaxNumber;
|
||||
import com.volmit.config.MinNumber;
|
||||
import com.volmit.config.Range;
|
||||
import com.volmit.config.Required;
|
||||
import com.volmit.noise.NoiseStyle;
|
||||
import com.volmit.noise.StyledRange;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/** The tunnels of a {@link Cave}: long winding passages. Thin ones link other caves together. */
|
||||
@Desc("Long winding passages.")
|
||||
public final class CaveTunnel {
|
||||
@Desc("Tunnel width in blocks. A tunnel varies between the two along its length.")
|
||||
private Range width = Range.of(4, 7);
|
||||
private static final Range DEFAULT_WIDTH = Range.of(4, 7);
|
||||
/**
|
||||
* The style a styled range gets when the pack writes none: white noise, which would make a tunnel's width jump
|
||||
* block by block. A width with this style follows the default width noise instead.
|
||||
*/
|
||||
private static final NoiseStyle STYLE_OF_A_RANGE_WRITTEN_WITHOUT_ONE = NoiseStyle.of("STATIC");
|
||||
|
||||
@MinNumber(16)
|
||||
@MaxNumber(512)
|
||||
@Desc("Roughly how many blocks a tunnel runs between turns and junctions. Larger gives longer, straighter and sparser tunnels.")
|
||||
private int stretch = 96;
|
||||
@Desc("Tunnel width in blocks. The style picks where a tunnel is narrow or wide; leave it out for a slow change that scales with spacing.")
|
||||
private StyledRange width;
|
||||
|
||||
@MinNumber(1)
|
||||
@MaxNumber(4)
|
||||
@Desc("How level tunnels run. 1 lets them go in any direction, higher keeps them closer to horizontal.")
|
||||
private double flatness = 1.4;
|
||||
@Desc("Tunnel height in blocks, low where the tunnel is narrow and tall where it is wide. Leave out for round tunnels.")
|
||||
private Range height;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Desc("Share of the underground that has tunnels at all. 1 puts them everywhere, lower leaves areas without any.")
|
||||
private double coverage = 1;
|
||||
@Required
|
||||
@Desc("Blocks between neighbouring tunnels.")
|
||||
private CaveTunnelSpacing spacing = new CaveTunnelSpacing();
|
||||
|
||||
@Desc("Noise that bends the tunnels: zoom sets how often they turn, multiplier how many blocks they swing. A flat style keeps them straight. Leave out for a gentle bend that scales with spacing.")
|
||||
private NoiseStyle warp;
|
||||
|
||||
@Desc("Where tunnels occur. Leave out to put them everywhere.")
|
||||
private CaveTunnelCoverage coverage;
|
||||
|
||||
public CaveTunnel() {
|
||||
}
|
||||
|
||||
public Range width() {
|
||||
return width == null ? Range.of(4, 7) : width;
|
||||
return width == null ? DEFAULT_WIDTH : Range.of(width.min(), width.max());
|
||||
}
|
||||
|
||||
public int stretch() {
|
||||
return stretch;
|
||||
/** The noise that picks the width along a tunnel; empty where the pack wrote none. */
|
||||
public Optional<NoiseStyle> widthStyle() {
|
||||
if (width == null || width.style().equals(STYLE_OF_A_RANGE_WRITTEN_WITHOUT_ONE)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of(width.style());
|
||||
}
|
||||
|
||||
public double flatness() {
|
||||
return flatness;
|
||||
/** The height range of an oval tunnel; empty for a round one. */
|
||||
public Optional<Range> height() {
|
||||
return Optional.ofNullable(height);
|
||||
}
|
||||
|
||||
public double coverage() {
|
||||
return coverage;
|
||||
public CaveTunnelSpacing spacing() {
|
||||
return spacing == null ? new CaveTunnelSpacing() : spacing;
|
||||
}
|
||||
|
||||
/** The noise that bends the tunnels; empty where the pack wrote none. */
|
||||
public Optional<NoiseStyle> warp() {
|
||||
return Optional.ofNullable(warp);
|
||||
}
|
||||
|
||||
public CaveTunnelCoverage coverage() {
|
||||
return coverage == null ? new CaveTunnelCoverage() : coverage;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.modules.carve;
|
||||
|
||||
import com.volmit.config.Desc;
|
||||
import com.volmit.config.MaxNumber;
|
||||
import com.volmit.config.MinNumber;
|
||||
import com.volmit.noise.NoiseStyle;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/** Where the tunnels of a {@link CaveTunnel} occur: the share of the underground that has them, in patches a noise shapes. */
|
||||
@Desc("Where tunnels occur.")
|
||||
public final class CaveTunnelCoverage {
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Desc("Share of the underground that has tunnels. 1 puts them everywhere, lower leaves areas without any.")
|
||||
private double share = 1;
|
||||
|
||||
@Desc("Noise that shapes the areas with tunnels. Leave out for patches that scale with spacing.")
|
||||
private NoiseStyle style;
|
||||
|
||||
public CaveTunnelCoverage() {
|
||||
}
|
||||
|
||||
public double share() {
|
||||
return share;
|
||||
}
|
||||
|
||||
/** The noise that shapes the areas with tunnels; empty where the pack wrote none. */
|
||||
public Optional<NoiseStyle> style() {
|
||||
return Optional.ofNullable(style);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.modules.carve;
|
||||
|
||||
import com.volmit.config.Desc;
|
||||
import com.volmit.config.MaxNumber;
|
||||
import com.volmit.config.MinNumber;
|
||||
|
||||
/** How far apart the tunnels of a {@link CaveTunnel} run, side by side and stacked. */
|
||||
@Desc("Blocks between neighbouring tunnels.")
|
||||
public final class CaveTunnelSpacing {
|
||||
@MinNumber(16)
|
||||
@MaxNumber(512)
|
||||
@Desc("Blocks between tunnels side by side. Larger gives longer, straighter and sparser tunnels.")
|
||||
private int horizontal = 96;
|
||||
|
||||
@MinNumber(8)
|
||||
@MaxNumber(512)
|
||||
@Desc("Blocks between tunnels stacked above each other. Below horizontal keeps tunnels closer to level.")
|
||||
private int vertical = 69;
|
||||
|
||||
public CaveTunnelSpacing() {
|
||||
}
|
||||
|
||||
public int horizontal() {
|
||||
return horizontal;
|
||||
}
|
||||
|
||||
public int vertical() {
|
||||
return vertical;
|
||||
}
|
||||
}
|
||||
@@ -15,14 +15,18 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.modules.carve.field;
|
||||
|
||||
import com.volmit.noise.NoiseFactory;
|
||||
import com.volmit.noise.NoiseSampler;
|
||||
import com.volmit.noise.NoiseStyle;
|
||||
|
||||
/** Builds the noise fields of cave shapes, sized in blocks instead of in a noise style's zoom. */
|
||||
import java.util.OptionalDouble;
|
||||
|
||||
/**
|
||||
* Builds the noise fields of cave shapes, sized in blocks instead of in a noise style's zoom. Every field takes the
|
||||
* next seed of the cave, whichever way it is built, so changing how one field is built leaves the others alone.
|
||||
*/
|
||||
final class CaveNoise {
|
||||
private static final String STYLE = "SIMPLEX";
|
||||
/** Measured on the host's SIMPLEX style at zoom 1: the mean distance in blocks between two sign changes along a line. */
|
||||
@@ -33,6 +37,10 @@ final class CaveNoise {
|
||||
private static final double DETAIL_SHRINK = 2.7D;
|
||||
/** Below this size a detail layer is finer than the sampling lattice can carry. */
|
||||
private static final double MIN_DETAIL_SPACING_BLOCKS = 12D;
|
||||
/** A pack style is rescaled until its measured feature spacing is within this share of the one asked for. */
|
||||
private static final double SCALING_TOLERANCE = 0.1D;
|
||||
private static final int MOST_SCALING_ROUNDS = 6;
|
||||
private static final Field3 LEVEL = (x, y, z) -> 0D;
|
||||
|
||||
private final NoiseFactory noise;
|
||||
private final long seed;
|
||||
@@ -50,7 +58,7 @@ final class CaveNoise {
|
||||
|
||||
/** A field whose sign changes about every {@code spacing} blocks horizontally and {@code verticalSpacing} vertically. */
|
||||
Field3 smooth(double spacing, double verticalSpacing) {
|
||||
NoiseSampler sampler = nextSampler();
|
||||
NoiseSampler sampler = nextSampler(NoiseStyle.of(STYLE));
|
||||
double horizontal = SIMPLEX_ZERO_SPACING_BLOCKS / spacing;
|
||||
double vertical = SIMPLEX_ZERO_SPACING_BLOCKS / verticalSpacing;
|
||||
return (x, y, z) -> sampler.signed(x * horizontal, y * vertical, z * horizontal);
|
||||
@@ -71,13 +79,79 @@ final class CaveNoise {
|
||||
|
||||
/** A field that only varies over X and Z, changing sign about every {@code spacing} blocks. */
|
||||
Field3 columns(double spacing) {
|
||||
NoiseSampler sampler = nextSampler();
|
||||
NoiseSampler sampler = nextSampler(NoiseStyle.of(STYLE));
|
||||
double scale = SIMPLEX_ZERO_SPACING_BLOCKS / spacing;
|
||||
return (x, y, z) -> sampler.signed(x * scale, z * scale);
|
||||
}
|
||||
|
||||
private NoiseSampler nextSampler() {
|
||||
/** A pack's style read in blocks as the pack wrote it, its zoom included. A flat style gives a level field at 0. */
|
||||
Field3 inBlocks(NoiseStyle style) {
|
||||
if (style.isFlat()) {
|
||||
nextSeed();
|
||||
return LEVEL;
|
||||
}
|
||||
NoiseSampler sampler = nextSampler(style);
|
||||
return sampler::signed;
|
||||
}
|
||||
|
||||
/** A pack's style rescaled so its features lie about {@code spacing} blocks apart horizontally and {@code verticalSpacing} vertically. */
|
||||
Field3 scaledTo(NoiseStyle style, double spacing, double verticalSpacing) {
|
||||
if (style.isFlat()) {
|
||||
nextSeed();
|
||||
return LEVEL;
|
||||
}
|
||||
NoiseSampler sampler = scaledToSpacing(nextSampler(style), style, spacing);
|
||||
double vertical = spacing / verticalSpacing;
|
||||
return (x, y, z) -> sampler.signed(x, y * vertical, z);
|
||||
}
|
||||
|
||||
/** {@link #scaledTo} for a field that only varies over X and Z. */
|
||||
Field3 columnsScaledTo(NoiseStyle style, double spacing) {
|
||||
if (style.isFlat()) {
|
||||
nextSeed();
|
||||
return LEVEL;
|
||||
}
|
||||
NoiseSampler sampler = scaledToSpacing(nextSampler(style), style, spacing);
|
||||
return (x, y, z) -> sampler.signed(x, z);
|
||||
}
|
||||
|
||||
/** How far apart the features of {@code field}, read from {@code style} in blocks, roughly lie. */
|
||||
static double featureBlocks(Field3 field, NoiseStyle style) {
|
||||
double guess = simplexLikeFeatureBlocks(style.zoom());
|
||||
return FieldStats.featureBlocks(field, guess).orElse(guess);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rescales {@code sampler} until its measured feature spacing matches {@code spacing}, starting from where a style
|
||||
* built like SIMPLEX would land. The scale is folded into the noise, so a fracture still moves it in blocks.
|
||||
*/
|
||||
private static NoiseSampler scaledToSpacing(NoiseSampler sampler, NoiseStyle style, double spacing) {
|
||||
double factor = simplexLikeFeatureBlocks(style.zoom()) / spacing;
|
||||
for (int round = 0; round < MOST_SCALING_ROUNDS; round++) {
|
||||
NoiseSampler scaled = sampler.scaled(factor);
|
||||
OptionalDouble measured = FieldStats.featureBlocks((x, y, z) -> scaled.signed(x, y, z), spacing);
|
||||
if (measured.isEmpty()) {
|
||||
return scaled;
|
||||
}
|
||||
double measuredShare = measured.getAsDouble() / spacing;
|
||||
if (Math.abs(measuredShare - 1D) <= SCALING_TOLERANCE) {
|
||||
return scaled;
|
||||
}
|
||||
factor *= measuredShare;
|
||||
}
|
||||
return sampler.scaled(factor);
|
||||
}
|
||||
|
||||
private static double simplexLikeFeatureBlocks(double zoom) {
|
||||
return SIMPLEX_ZERO_SPACING_BLOCKS * zoom;
|
||||
}
|
||||
|
||||
private NoiseSampler nextSampler(NoiseStyle style) {
|
||||
return noise.sampler(style, nextSeed());
|
||||
}
|
||||
|
||||
private long nextSeed() {
|
||||
fieldsBuilt++;
|
||||
return noise.sampler(NoiseStyle.of(STYLE), seed + (fieldsBuilt * 1_000_003L));
|
||||
return seed + (fieldsBuilt * 1_000_003L);
|
||||
}
|
||||
}
|
||||
@@ -20,14 +20,18 @@ package art.arcane.iris.modules.carve.field;
|
||||
|
||||
import art.arcane.iris.modules.carve.CaveCavern;
|
||||
import art.arcane.iris.modules.carve.CavePillars;
|
||||
import com.volmit.noise.NoiseStyle;
|
||||
|
||||
/**
|
||||
* Caverns: the rooms where one slow field rises above a threshold. Pillars are columns where a second field, which
|
||||
* only varies across X and Z, peaks: there the room has to be more open to be carved, so a pillar stands from floor
|
||||
* to ceiling and widens towards both, where the room is least open.
|
||||
* Caverns: the rooms where one slow field rises above a threshold. Pillars stand where a second field peaks: there the
|
||||
* room has to be more open to be carved, so a pillar widens towards floor and ceiling, where the room is least open.
|
||||
* The pillar field varies only across X and Z unless the pack lets pillars change with height; then it is read in 3D
|
||||
* on the lattice, and a pillar whose field fades out mid-room narrows and breaks off, leaving stubs that flare into
|
||||
* floor and ceiling.
|
||||
*/
|
||||
final class CavernShape extends LatticeShape {
|
||||
private static final int ROOMS = 0;
|
||||
private static final int PILLARS = 1;
|
||||
/** A room is the part of a feature above the threshold, which is narrower than the feature itself. */
|
||||
private static final double FEATURE_BLOCKS_PER_ROOM_BLOCK = 1.6D;
|
||||
/** A finer layer keeps room walls from looking like smooth bubbles. */
|
||||
@@ -36,37 +40,51 @@ final class CavernShape extends LatticeShape {
|
||||
private static final double CLOSING_MARGIN = 1.1D;
|
||||
/** Pillars are two features apart: one peak, one trough. */
|
||||
private static final double PILLAR_FEATURES_PER_SPACING = 0.5D;
|
||||
/** How much more ground a pillar covers at floor and ceiling than at its middle. */
|
||||
private static final double PILLAR_FOOT_AREA = 4D;
|
||||
private static final double LARGEST_PILLAR_AREA_SHARE = 0.3D;
|
||||
private static final double NO_PILLAR = 0D;
|
||||
private static final double FULL_PILLAR = 1D;
|
||||
|
||||
private final Field3 rooms;
|
||||
private final double threshold;
|
||||
private final double mostOpen;
|
||||
private final Field3 pillars;
|
||||
private final boolean pillarsChangeWithHeight;
|
||||
private final double pillarMiddle;
|
||||
private final double pillarFoot;
|
||||
|
||||
CavernShape(CaveNoise noise, CaveCavern cavern) {
|
||||
double span = cavern.size() * FEATURE_BLOCKS_PER_ROOM_BLOCK;
|
||||
double height = cavern.height() * FEATURE_BLOCKS_PER_ROOM_BLOCK;
|
||||
this.rooms = noise.detailed(span, height, WALL_DETAIL);
|
||||
this.rooms = cavern.style()
|
||||
.map(style -> noise.scaledTo(style, span, height))
|
||||
.orElseGet(() -> noise.detailed(span, height, WALL_DETAIL));
|
||||
FieldStats stats = FieldStats.measure(rooms, span);
|
||||
this.threshold = stats.valueAboveShare(cavern.coverage());
|
||||
this.mostOpen = Math.max(0D, stats.highest() - threshold);
|
||||
if (cavern.pillars().isEmpty()) {
|
||||
this.pillars = null;
|
||||
this.pillarsChangeWithHeight = false;
|
||||
this.pillarMiddle = Double.POSITIVE_INFINITY;
|
||||
this.pillarFoot = Double.POSITIVE_INFINITY;
|
||||
return;
|
||||
}
|
||||
CavePillars settings = cavern.pillars().get();
|
||||
double featureBlocks = settings.spacing() * PILLAR_FEATURES_PER_SPACING;
|
||||
this.pillars = noise.columns(featureBlocks);
|
||||
this.pillarsChangeWithHeight = settings.vertical().isPresent();
|
||||
this.pillars = pillarField(noise, settings, featureBlocks);
|
||||
FieldStats pillarStats = FieldStats.measure(pillars, featureBlocks);
|
||||
double middleAreaShare = Math.min(LARGEST_PILLAR_AREA_SHARE, pillarAreaShare(settings));
|
||||
this.pillarMiddle = pillarStats.valueAboveShare(middleAreaShare);
|
||||
this.pillarFoot = pillarStats.valueAboveShare(Math.min(1D, middleAreaShare * PILLAR_FOOT_AREA));
|
||||
this.pillarFoot = pillarStats.valueAboveShare(Math.min(1D, middleAreaShare * settings.flare()));
|
||||
}
|
||||
|
||||
private static Field3 pillarField(CaveNoise noise, CavePillars settings, double featureBlocks) {
|
||||
NoiseStyle style = settings.style().orElse(null);
|
||||
if (settings.vertical().isEmpty()) {
|
||||
return style == null ? noise.columns(featureBlocks) : noise.columnsScaledTo(style, featureBlocks);
|
||||
}
|
||||
double vertical = settings.vertical().getAsInt();
|
||||
return style == null ? noise.smooth(featureBlocks, vertical) : noise.scaledTo(style, featureBlocks, vertical);
|
||||
}
|
||||
|
||||
private static double pillarAreaShare(CavePillars pillars) {
|
||||
@@ -76,12 +94,15 @@ final class CavernShape extends LatticeShape {
|
||||
|
||||
@Override
|
||||
protected int fieldCount() {
|
||||
return 1;
|
||||
return pillarsChangeWithHeight ? 2 : 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readFields(int x, int y, int z, double[] values) {
|
||||
values[ROOMS] = rooms.at(x, y, z);
|
||||
if (pillarsChangeWithHeight) {
|
||||
values[PILLARS] = pillars.at(x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -98,20 +119,35 @@ final class CavernShape extends LatticeShape {
|
||||
if (pillars == null) {
|
||||
return true;
|
||||
}
|
||||
return open > pillarStrength(pass, column) * mostOpen;
|
||||
double strength = pillarsChangeWithHeight
|
||||
? pillarStrength(pass.cell(PILLARS).at(shareX, shareY, shareZ))
|
||||
: columnPillarStrength(pass, column);
|
||||
return open > strength * mostOpen;
|
||||
}
|
||||
|
||||
/** How strongly the column is a pillar: 0 outside one, 1 in its middle, in between on the foot it widens into. */
|
||||
private double pillarStrength(Pass pass, int column) {
|
||||
/** {@link #pillarStrength} of a straight pillar, read once per column of the chunk. */
|
||||
private double columnPillarStrength(Pass pass, int column) {
|
||||
double[] strengths = pass.columnValues();
|
||||
double known = strengths[column];
|
||||
if (!Double.isNaN(known)) {
|
||||
return known;
|
||||
}
|
||||
double value = pillars.at(pass.lattice().originX() + (column >> 4), 0D, pass.lattice().originZ() + (column & 15));
|
||||
double intoPillar = Math.max(0D, Math.min(1D, (value - pillarFoot) / (pillarMiddle - pillarFoot)));
|
||||
double strength = intoPillar * intoPillar;
|
||||
double strength = pillarStrength(value);
|
||||
strengths[column] = strength;
|
||||
return strength;
|
||||
}
|
||||
|
||||
/** How strongly a pillar field value is a pillar: 0 outside one, 1 in its middle, in between on the foot it widens into. */
|
||||
private double pillarStrength(double value) {
|
||||
if (value >= pillarMiddle) {
|
||||
return FULL_PILLAR;
|
||||
}
|
||||
double footWidth = pillarMiddle - pillarFoot;
|
||||
if (footWidth <= 0D) {
|
||||
return NO_PILLAR;
|
||||
}
|
||||
double intoPillar = Math.max(0D, Math.min(1D, (value - pillarFoot) / footWidth));
|
||||
return intoPillar * intoPillar;
|
||||
}
|
||||
}
|
||||
@@ -19,10 +19,12 @@
|
||||
package art.arcane.iris.modules.carve.field;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.OptionalDouble;
|
||||
|
||||
/**
|
||||
* What a field's values look like, measured once on fixed sample points so every server measures the same: which value
|
||||
* a given share of the world lies above. Shapes turn a share of the underground into a field threshold with it.
|
||||
* a given share of the world lies above, and how far apart its features lie. Shapes turn a share of the underground
|
||||
* into a field threshold with it, and a pack's noise style into a size in blocks.
|
||||
*/
|
||||
final class FieldStats {
|
||||
private static final int SAMPLES = 4096;
|
||||
@@ -31,6 +33,10 @@ final class FieldStats {
|
||||
private static final double STEP_X = 0.7548776662466927D;
|
||||
private static final double STEP_Y = 0.5698402909980532D;
|
||||
private static final double STEP_Z = 0.8191725133961645D;
|
||||
private static final int LINES = 64;
|
||||
private static final int LINE_SAMPLES = 128;
|
||||
private static final double LINE_STEPS_PER_FEATURE = 16D;
|
||||
private static final int FEWEST_CROSSINGS = 16;
|
||||
|
||||
private final double[] sortedValues;
|
||||
|
||||
@@ -49,6 +55,43 @@ final class FieldStats {
|
||||
return new FieldStats(values);
|
||||
}
|
||||
|
||||
/**
|
||||
* How far apart the features of {@code field} lie in blocks, measured as the mean distance between two crossings
|
||||
* of its middle value along horizontal lines. Lines are read in steps of a fraction of {@code expectedBlocks}, so a
|
||||
* field far finer than expected measures too coarse; measuring again at the answer corrects that. Empty for a field
|
||||
* that hardly crosses its middle, such as a level one.
|
||||
*/
|
||||
static OptionalDouble featureBlocks(Field3 field, double expectedBlocks) {
|
||||
double step = expectedBlocks / LINE_STEPS_PER_FEATURE;
|
||||
double span = expectedBlocks * SPAN_IN_FEATURES;
|
||||
double[] values = new double[LINES * LINE_SAMPLES];
|
||||
for (int line = 0; line < LINES; line++) {
|
||||
double startX = coordinate(line, STEP_X, span);
|
||||
double y = coordinate(line, STEP_Y, span);
|
||||
double startZ = coordinate(line, STEP_Z, span);
|
||||
boolean alongX = (line & 1) == 0;
|
||||
for (int sample = 0; sample < LINE_SAMPLES; sample++) {
|
||||
double along = sample * step;
|
||||
values[(line * LINE_SAMPLES) + sample] = alongX ? field.at(startX + along, y, startZ) : field.at(startX, y, startZ + along);
|
||||
}
|
||||
}
|
||||
double[] sorted = values.clone();
|
||||
Arrays.sort(sorted);
|
||||
double middle = sorted[sorted.length / 2];
|
||||
int crossings = 0;
|
||||
for (int index = 1; index < values.length; index++) {
|
||||
boolean sameLine = index % LINE_SAMPLES != 0;
|
||||
if (sameLine && (values[index - 1] >= middle) != (values[index] >= middle)) {
|
||||
crossings++;
|
||||
}
|
||||
}
|
||||
if (crossings < FEWEST_CROSSINGS) {
|
||||
return OptionalDouble.empty();
|
||||
}
|
||||
double measuredLength = LINES * (LINE_SAMPLES - 1) * step;
|
||||
return OptionalDouble.of(measuredLength / crossings);
|
||||
}
|
||||
|
||||
private static double coordinate(int sample, double step, double span) {
|
||||
double fraction = (sample * step) % 1D;
|
||||
return (fraction - 0.5D) * span;
|
||||
|
||||
@@ -19,6 +19,9 @@
|
||||
package art.arcane.iris.modules.carve.field;
|
||||
|
||||
import art.arcane.iris.modules.carve.CaveTunnel;
|
||||
import art.arcane.iris.modules.carve.CaveTunnelCoverage;
|
||||
import com.volmit.config.Range;
|
||||
import com.volmit.noise.NoiseStyle;
|
||||
|
||||
/**
|
||||
* Tunnels: the lines along which two of three fields are both zero. Each field is zero on winding sheets through the
|
||||
@@ -28,7 +31,9 @@ import art.arcane.iris.modules.carve.CaveTunnel;
|
||||
*
|
||||
* <p>A tunnel is every block within its radius of a line. The distance is worked out in blocks from how steeply the
|
||||
* fields change in the cell, so a tunnel keeps the width the pack asks for wherever the noise is steep or shallow.
|
||||
* The fields are read at gently shifted places, which makes a tunnel's path wiggle without ever breaking it.
|
||||
* An oval tunnel measures the distance with the vertical axis stretched by its width over its height, which keeps its
|
||||
* width and gives it its height. The fields are read at warped places, which makes a tunnel's path bend without ever
|
||||
* breaking it.
|
||||
*/
|
||||
final class TunnelShape extends LatticeShape {
|
||||
private static final int SHEETS = 3;
|
||||
@@ -37,24 +42,37 @@ final class TunnelShape extends LatticeShape {
|
||||
private static final int[] PAIR_FIRST = {0, 0, 1};
|
||||
private static final int[] PAIR_SECOND = {1, 2, 2};
|
||||
private static final int PAIRS = PAIR_FIRST.length;
|
||||
private static final int VALUES_PER_PAIR = 4;
|
||||
/** A round tunnel keeps, per pair of sheets, the three terms of its squared distance from their line and whether it is near. */
|
||||
private static final int ROUND_VALUES_PER_PAIR = 4;
|
||||
private static final int FIRST_SQUARED = 0;
|
||||
private static final int FIRST_TIMES_SECOND = 1;
|
||||
private static final int SECOND_SQUARED = 2;
|
||||
private static final int PAIR_IS_NEAR = 3;
|
||||
/** An oval tunnel keeps each sheet's slope along the three axes, then whether each pair is near. */
|
||||
private static final int OVAL_SLOPE_X = 0;
|
||||
private static final int OVAL_SLOPE_Y = 1;
|
||||
private static final int OVAL_SLOPE_Z = 2;
|
||||
private static final int OVAL_VALUES_PER_SHEET = 3;
|
||||
private static final int OVAL_PAIR_IS_NEAR = SHEETS * OVAL_VALUES_PER_SHEET;
|
||||
/** An oval tunnel's terms depend on its height over its width at the block, so they are worked out block by block here. */
|
||||
private static final ThreadLocal<double[]> OVAL_TERMS = ThreadLocal.withInitial(() -> new double[PAIR_IS_NEAR]);
|
||||
private static final double NEAR = 1D;
|
||||
private static final double FAR = 0D;
|
||||
/** A path shifts by this share of the tunnel's stretch, and changes direction this many times per stretch. */
|
||||
private static final double WIGGLE_SHARE_OF_STRETCH = 0.06D;
|
||||
private static final double WIGGLES_PER_STRETCH = 3D;
|
||||
private static final double SMALLEST_WIGGLE_SPACING_BLOCKS = 16D;
|
||||
private static final double VERTICAL_WIGGLE_SHARE = 0.5D;
|
||||
private static final double WIDTH_CHANGE_STRETCHES = 1.5D;
|
||||
private static final double ROUND = 1D;
|
||||
/** Without a warp, a path shifts by this share of the horizontal spacing, and changes direction this many times per spacing. */
|
||||
private static final double DEFAULT_WARP_SHARE_OF_SPACING = 0.06D;
|
||||
private static final double DEFAULT_WARPS_PER_SPACING = 3D;
|
||||
private static final double SMALLEST_DEFAULT_WARP_SPACING_BLOCKS = 16D;
|
||||
/** A warp moves a path up and down this share of how far it moves it sideways. */
|
||||
private static final double VERTICAL_WARP_SHARE = 0.5D;
|
||||
/** Without a width style, the width changes over this many horizontal spacings. */
|
||||
private static final double DEFAULT_WIDTH_CHANGE_SPACINGS = 1.5D;
|
||||
private static final double WIDTH_SPREAD = 1D;
|
||||
private static final double PRESENCE_STRETCHES = 3D;
|
||||
/** Without a coverage style, the areas with tunnels are this many horizontal spacings across. */
|
||||
private static final double DEFAULT_PRESENCE_SPACINGS = 3D;
|
||||
/** Field value over which tunnels widen from nothing to full size at the edge of an area that has them. */
|
||||
private static final double PRESENCE_EDGE = 0.15D;
|
||||
/** A tunnel narrower than this is not a passage any more, so it ends instead. */
|
||||
/** A tunnel narrower or lower than this is not a passage any more, so it ends instead. */
|
||||
private static final double NARROWEST_RADIUS_BLOCKS = 1D;
|
||||
/** A cell's slope is an average, so a cell is only ruled out when the line is clearly further than the widest tunnel. */
|
||||
private static final double CELL_REACH_SLACK = 1.5D;
|
||||
@@ -67,41 +85,61 @@ final class TunnelShape extends LatticeShape {
|
||||
private static final double LEAST_CROSSING = 0.03D;
|
||||
|
||||
private final Field3[] sheets = new Field3[SHEETS];
|
||||
private final Field3 warpX;
|
||||
private final Field3 warpY;
|
||||
private final Field3 warpZ;
|
||||
private final double warpBlocks;
|
||||
private final Field3 width;
|
||||
private final Field3 presence;
|
||||
private final Field3 wiggleX;
|
||||
private final Field3 wiggleY;
|
||||
private final Field3 wiggleZ;
|
||||
private final double wiggleBlocks;
|
||||
private final double presenceThreshold;
|
||||
private final double narrowRadius;
|
||||
private final double wideRadius;
|
||||
private final boolean oval;
|
||||
private final double lowRadius;
|
||||
private final double tallRadius;
|
||||
private final double leastSteepness;
|
||||
private final double presenceThreshold;
|
||||
|
||||
TunnelShape(CaveNoise noise, CaveTunnel tunnel) {
|
||||
double stretch = tunnel.stretch();
|
||||
double verticalStretch = stretch / Math.max(1D, tunnel.flatness());
|
||||
double spacing = tunnel.spacing().horizontal();
|
||||
double verticalSpacing = tunnel.spacing().vertical();
|
||||
for (int sheet = 0; sheet < SHEETS; sheet++) {
|
||||
sheets[sheet] = noise.smooth(stretch, verticalStretch);
|
||||
sheets[sheet] = noise.smooth(spacing, verticalSpacing);
|
||||
}
|
||||
double wiggleSpacing = Math.max(SMALLEST_WIGGLE_SPACING_BLOCKS, stretch / WIGGLES_PER_STRETCH);
|
||||
this.wiggleX = noise.smooth(wiggleSpacing, wiggleSpacing);
|
||||
this.wiggleY = noise.smooth(wiggleSpacing, wiggleSpacing);
|
||||
this.wiggleZ = noise.smooth(wiggleSpacing, wiggleSpacing);
|
||||
this.wiggleBlocks = stretch * WIGGLE_SHARE_OF_STRETCH;
|
||||
this.width = noise.smooth(stretch * WIDTH_CHANGE_STRETCHES, stretch * WIDTH_CHANGE_STRETCHES);
|
||||
this.narrowRadius = Math.min(tunnel.width().min(), tunnel.width().max()) / 2D;
|
||||
this.wideRadius = Math.max(tunnel.width().min(), tunnel.width().max()) / 2D;
|
||||
double leastSlope = CaveNoise.typicalSlope(stretch) * LEAST_SLOPE_SHARE;
|
||||
NoiseStyle warp = tunnel.warp().orElse(null);
|
||||
if (warp == null) {
|
||||
double warpSpacing = Math.max(SMALLEST_DEFAULT_WARP_SPACING_BLOCKS, spacing / DEFAULT_WARPS_PER_SPACING);
|
||||
this.warpX = noise.smooth(warpSpacing, warpSpacing);
|
||||
this.warpY = noise.smooth(warpSpacing, warpSpacing);
|
||||
this.warpZ = noise.smooth(warpSpacing, warpSpacing);
|
||||
this.warpBlocks = spacing * DEFAULT_WARP_SHARE_OF_SPACING;
|
||||
} else {
|
||||
this.warpX = noise.inBlocks(warp);
|
||||
this.warpY = noise.inBlocks(warp);
|
||||
this.warpZ = noise.inBlocks(warp);
|
||||
this.warpBlocks = warp.isFlat() ? 0D : warp.multiplier() / 2D;
|
||||
}
|
||||
double widthChangeSpacing = spacing * DEFAULT_WIDTH_CHANGE_SPACINGS;
|
||||
this.width = tunnel.widthStyle().map(noise::inBlocks).orElseGet(() -> noise.smooth(widthChangeSpacing, widthChangeSpacing));
|
||||
Range widthRange = tunnel.width();
|
||||
this.narrowRadius = Math.min(widthRange.min(), widthRange.max()) / 2D;
|
||||
this.wideRadius = Math.max(widthRange.min(), widthRange.max()) / 2D;
|
||||
Range height = tunnel.height().orElse(null);
|
||||
this.oval = height != null;
|
||||
this.lowRadius = oval ? Math.min(height.min(), height.max()) / 2D : 0D;
|
||||
this.tallRadius = oval ? Math.max(height.min(), height.max()) / 2D : 0D;
|
||||
double leastSlope = CaveNoise.typicalSlope(spacing) * LEAST_SLOPE_SHARE;
|
||||
this.leastSteepness = leastSlope * leastSlope;
|
||||
if (tunnel.coverage() >= 1D) {
|
||||
CaveTunnelCoverage coverage = tunnel.coverage();
|
||||
if (coverage.share() >= 1D) {
|
||||
this.presence = null;
|
||||
this.presenceThreshold = Double.NEGATIVE_INFINITY;
|
||||
return;
|
||||
}
|
||||
double presenceStretch = stretch * PRESENCE_STRETCHES;
|
||||
this.presence = noise.smooth(presenceStretch, presenceStretch);
|
||||
this.presenceThreshold = FieldStats.measure(presence, presenceStretch).valueAboveShare(tunnel.coverage());
|
||||
double presenceSpacing = spacing * DEFAULT_PRESENCE_SPACINGS;
|
||||
NoiseStyle presenceStyle = coverage.style().orElse(null);
|
||||
this.presence = presenceStyle == null ? noise.smooth(presenceSpacing, presenceSpacing) : noise.inBlocks(presenceStyle);
|
||||
double presenceFeatureBlocks = presenceStyle == null ? presenceSpacing : CaveNoise.featureBlocks(presence, presenceStyle);
|
||||
this.presenceThreshold = FieldStats.measure(presence, presenceFeatureBlocks).valueAboveShare(coverage.share());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -111,94 +149,174 @@ final class TunnelShape extends LatticeShape {
|
||||
|
||||
@Override
|
||||
protected void readFields(int x, int y, int z, double[] values) {
|
||||
double shiftedX = x + (wiggleX.at(x, y, z) * wiggleBlocks);
|
||||
double shiftedY = y + (wiggleY.at(x, y, z) * wiggleBlocks * VERTICAL_WIGGLE_SHARE);
|
||||
double shiftedZ = z + (wiggleZ.at(x, y, z) * wiggleBlocks);
|
||||
for (int sheet = 0; sheet < SHEETS; sheet++) {
|
||||
values[sheet] = sheets[sheet].at(shiftedX, shiftedY, shiftedZ);
|
||||
}
|
||||
readSheets(x, y, z, values);
|
||||
values[WIDTH] = width.at(x, y, z);
|
||||
if (presence != null) {
|
||||
values[PRESENCE] = presence.at(x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
private void readSheets(int x, int y, int z, double[] values) {
|
||||
if (warpBlocks == 0D) {
|
||||
for (int sheet = 0; sheet < SHEETS; sheet++) {
|
||||
values[sheet] = sheets[sheet].at(x, y, z);
|
||||
}
|
||||
return;
|
||||
}
|
||||
double warpedX = x + (warpX.at(x, y, z) * warpBlocks);
|
||||
double warpedY = y + (warpY.at(x, y, z) * warpBlocks * VERTICAL_WARP_SHARE);
|
||||
double warpedZ = z + (warpZ.at(x, y, z) * warpBlocks);
|
||||
for (int sheet = 0; sheet < SHEETS; sheet++) {
|
||||
values[sheet] = sheets[sheet].at(warpedX, warpedY, warpedZ);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean mayCarveIn(Pass pass) {
|
||||
if (presence != null && pass.cell(PRESENCE).highest() <= presenceThreshold) {
|
||||
return false;
|
||||
}
|
||||
double reach = wideRadius * CELL_REACH_SLACK;
|
||||
double[] pairValues = pass.cellValues();
|
||||
double reach = Math.max(wideRadius, tallRadius) * CELL_REACH_SLACK;
|
||||
double[] cellValues = pass.cellValues();
|
||||
if (oval) {
|
||||
keepSlopes(pass, cellValues);
|
||||
}
|
||||
boolean anyPairNear = false;
|
||||
for (int pair = 0; pair < PAIRS; pair++) {
|
||||
boolean near = preparePair(pass.cell(PAIR_FIRST[pair]), pass.cell(PAIR_SECOND[pair]), reach, pairValues, pair * VALUES_PER_PAIR);
|
||||
pairValues[(pair * VALUES_PER_PAIR) + PAIR_IS_NEAR] = near ? NEAR : FAR;
|
||||
LatticeCell first = pass.cell(PAIR_FIRST[pair]);
|
||||
LatticeCell second = pass.cell(PAIR_SECOND[pair]);
|
||||
boolean near = isNear(first, reach) && isNear(second, reach);
|
||||
if (near && !oval) {
|
||||
keepTerms(first, second, ROUND, cellValues, pair * ROUND_VALUES_PER_PAIR);
|
||||
}
|
||||
cellValues[nearIndex(pair)] = near ? NEAR : FAR;
|
||||
anyPairNear |= near;
|
||||
}
|
||||
return anyPairNear;
|
||||
}
|
||||
|
||||
/**
|
||||
* Works out, for the line where two sheets meet, the terms that turn the two field values at a block of the cell
|
||||
* into its squared distance from that line in blocks. Answers false when the line is out of reach of the whole cell.
|
||||
*/
|
||||
private boolean preparePair(LatticeCell first, LatticeCell second, double reach, double[] pairValues, int offset) {
|
||||
double firstSteepness = Math.max(squaredSlope(first), leastSteepness);
|
||||
double secondSteepness = Math.max(squaredSlope(second), leastSteepness);
|
||||
if (isFurtherThan(first.distanceFromZero(), firstSteepness, reach) || isFurtherThan(second.distanceFromZero(), secondSteepness, reach)) {
|
||||
return false;
|
||||
private int nearIndex(int pair) {
|
||||
return oval ? OVAL_PAIR_IS_NEAR + pair : (pair * ROUND_VALUES_PER_PAIR) + PAIR_IS_NEAR;
|
||||
}
|
||||
|
||||
/** Whether the sheet of a field may come within {@code reach} blocks of the cell. */
|
||||
private boolean isNear(LatticeCell cell, double reach) {
|
||||
double fieldDistance = cell.distanceFromZero();
|
||||
double squaredSlope = Math.max(squaredSlope(cell, ROUND), leastSteepness);
|
||||
return fieldDistance * fieldDistance <= reach * reach * squaredSlope;
|
||||
}
|
||||
|
||||
private static void keepSlopes(Pass pass, double[] cellValues) {
|
||||
for (int sheet = 0; sheet < SHEETS; sheet++) {
|
||||
LatticeCell cell = pass.cell(sheet);
|
||||
int offset = sheet * OVAL_VALUES_PER_SHEET;
|
||||
cellValues[offset + OVAL_SLOPE_X] = cell.slopeX();
|
||||
cellValues[offset + OVAL_SLOPE_Y] = cell.slopeY();
|
||||
cellValues[offset + OVAL_SLOPE_Z] = cell.slopeZ();
|
||||
}
|
||||
double together = (first.slopeX() * second.slopeX()) + (first.slopeY() * second.slopeY()) + (first.slopeZ() * second.slopeZ());
|
||||
}
|
||||
|
||||
/**
|
||||
* Works out, for the line where two sheets meet, the terms that turn the two field values at a block into its
|
||||
* squared distance from that line in blocks, with the vertical axis squeezed by {@code verticalScale}.
|
||||
*/
|
||||
private void keepTerms(LatticeCell first, LatticeCell second, double verticalScale, double[] terms, int offset) {
|
||||
keepTerms(first.slopeX(), first.slopeY(), first.slopeZ(), second.slopeX(), second.slopeY(), second.slopeZ(), verticalScale, terms, offset);
|
||||
}
|
||||
|
||||
private void keepTerms(double firstX, double firstY, double firstZ, double secondX, double secondY, double secondZ,
|
||||
double verticalScale, double[] terms, int offset) {
|
||||
double squaredScale = verticalScale * verticalScale;
|
||||
double firstSteepness = Math.max((firstX * firstX) + (squaredScale * firstY * firstY) + (firstZ * firstZ), leastSteepness);
|
||||
double secondSteepness = Math.max((secondX * secondX) + (squaredScale * secondY * secondY) + (secondZ * secondZ), leastSteepness);
|
||||
double together = (firstX * secondX) + (squaredScale * firstY * secondY) + (firstZ * secondZ);
|
||||
double crossing = Math.max((firstSteepness * secondSteepness) - (together * together), firstSteepness * secondSteepness * LEAST_CROSSING);
|
||||
pairValues[offset + FIRST_SQUARED] = secondSteepness / crossing;
|
||||
pairValues[offset + FIRST_TIMES_SECOND] = (-2D * together) / crossing;
|
||||
pairValues[offset + SECOND_SQUARED] = firstSteepness / crossing;
|
||||
return true;
|
||||
terms[offset + FIRST_SQUARED] = secondSteepness / crossing;
|
||||
terms[offset + FIRST_TIMES_SECOND] = (-2D * together) / crossing;
|
||||
terms[offset + SECOND_SQUARED] = firstSteepness / crossing;
|
||||
}
|
||||
|
||||
private static double squaredSlope(LatticeCell cell) {
|
||||
return (cell.slopeX() * cell.slopeX()) + (cell.slopeY() * cell.slopeY()) + (cell.slopeZ() * cell.slopeZ());
|
||||
}
|
||||
|
||||
/** Whether a sheet whose field stays {@code fieldDistance} from zero in the cell is more than {@code blocks} away. */
|
||||
private static boolean isFurtherThan(double fieldDistance, double squaredSlope, double blocks) {
|
||||
return fieldDistance * fieldDistance > blocks * blocks * squaredSlope;
|
||||
private static double squaredSlope(LatticeCell cell, double verticalScale) {
|
||||
double squaredScale = verticalScale * verticalScale;
|
||||
return (cell.slopeX() * cell.slopeX()) + (squaredScale * cell.slopeY() * cell.slopeY()) + (cell.slopeZ() * cell.slopeZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean carvesAt(Pass pass, double shareX, double shareY, double shareZ, double openness, int column) {
|
||||
double radius = radiusAt(pass, shareX, shareY, shareZ) * openness;
|
||||
double widthShare = widthShareAt(pass, shareX, shareY, shareZ);
|
||||
double sizeShare = presenceShareAt(pass, shareX, shareY, shareZ);
|
||||
double radius = ((narrowRadius + ((wideRadius - narrowRadius) * widthShare)) * sizeShare) * openness;
|
||||
if (radius < NARROWEST_RADIUS_BLOCKS) {
|
||||
return false;
|
||||
}
|
||||
if (!oval) {
|
||||
return isWithinRoundTunnel(pass, shareX, shareY, shareZ, radius);
|
||||
}
|
||||
double heightRadius = ((lowRadius + ((tallRadius - lowRadius) * widthShare)) * sizeShare) * openness;
|
||||
if (heightRadius < NARROWEST_RADIUS_BLOCKS) {
|
||||
return false;
|
||||
}
|
||||
return isWithinOvalTunnel(pass, shareX, shareY, shareZ, radius, heightRadius);
|
||||
}
|
||||
|
||||
private boolean isWithinRoundTunnel(Pass pass, double shareX, double shareY, double shareZ, double radius) {
|
||||
double squaredRadius = radius * radius;
|
||||
double[] pairValues = pass.cellValues();
|
||||
double[] terms = pass.cellValues();
|
||||
for (int pair = 0; pair < PAIRS; pair++) {
|
||||
int offset = pair * VALUES_PER_PAIR;
|
||||
if (pairValues[offset + PAIR_IS_NEAR] == FAR) {
|
||||
int offset = pair * ROUND_VALUES_PER_PAIR;
|
||||
if (terms[offset + PAIR_IS_NEAR] == FAR) {
|
||||
continue;
|
||||
}
|
||||
double first = pass.cell(PAIR_FIRST[pair]).at(shareX, shareY, shareZ);
|
||||
double second = pass.cell(PAIR_SECOND[pair]).at(shareX, shareY, shareZ);
|
||||
double squaredBlocksFromLine = (pairValues[offset + FIRST_SQUARED] * first * first)
|
||||
+ (pairValues[offset + FIRST_TIMES_SECOND] * first * second)
|
||||
+ (pairValues[offset + SECOND_SQUARED] * second * second);
|
||||
if (squaredBlocksFromLine < squaredRadius) {
|
||||
if (squaredBlocksFromLine(pass, pair, terms, offset, shareX, shareY, shareZ) < squaredRadius) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private double radiusAt(Pass pass, double shareX, double shareY, double shareZ) {
|
||||
double widthShare = clampToShare(0.5D + (pass.cell(WIDTH).at(shareX, shareY, shareZ) * WIDTH_SPREAD));
|
||||
double radius = narrowRadius + ((wideRadius - narrowRadius) * widthShare);
|
||||
if (presence == null) {
|
||||
return radius;
|
||||
/**
|
||||
* Measures with the vertical axis stretched by the tunnel's width over its height, where the oval is a circle as
|
||||
* wide as the tunnel: a field's upward slope shrinks by the same share.
|
||||
*/
|
||||
private boolean isWithinOvalTunnel(Pass pass, double shareX, double shareY, double shareZ, double radius, double heightRadius) {
|
||||
double squaredRadius = radius * radius;
|
||||
double verticalScale = heightRadius / radius;
|
||||
double[] cellValues = pass.cellValues();
|
||||
double[] terms = OVAL_TERMS.get();
|
||||
for (int pair = 0; pair < PAIRS; pair++) {
|
||||
if (cellValues[OVAL_PAIR_IS_NEAR + pair] == FAR) {
|
||||
continue;
|
||||
}
|
||||
int first = PAIR_FIRST[pair] * OVAL_VALUES_PER_SHEET;
|
||||
int second = PAIR_SECOND[pair] * OVAL_VALUES_PER_SHEET;
|
||||
keepTerms(cellValues[first + OVAL_SLOPE_X], cellValues[first + OVAL_SLOPE_Y], cellValues[first + OVAL_SLOPE_Z],
|
||||
cellValues[second + OVAL_SLOPE_X], cellValues[second + OVAL_SLOPE_Y], cellValues[second + OVAL_SLOPE_Z],
|
||||
verticalScale, terms, 0);
|
||||
if (squaredBlocksFromLine(pass, pair, terms, 0, shareX, shareY, shareZ) < squaredRadius) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
double intoArea = (pass.cell(PRESENCE).at(shareX, shareY, shareZ) - presenceThreshold) / PRESENCE_EDGE;
|
||||
return radius * clampToShare(intoArea);
|
||||
return false;
|
||||
}
|
||||
|
||||
private static double squaredBlocksFromLine(Pass pass, int pair, double[] terms, int offset, double shareX, double shareY, double shareZ) {
|
||||
double first = pass.cell(PAIR_FIRST[pair]).at(shareX, shareY, shareZ);
|
||||
double second = pass.cell(PAIR_SECOND[pair]).at(shareX, shareY, shareZ);
|
||||
return (terms[offset + FIRST_SQUARED] * first * first)
|
||||
+ (terms[offset + FIRST_TIMES_SECOND] * first * second)
|
||||
+ (terms[offset + SECOND_SQUARED] * second * second);
|
||||
}
|
||||
|
||||
private double widthShareAt(Pass pass, double shareX, double shareY, double shareZ) {
|
||||
return clampToShare(0.5D + (pass.cell(WIDTH).at(shareX, shareY, shareZ) * WIDTH_SPREAD));
|
||||
}
|
||||
|
||||
/** How far the block lies into an area with tunnels: 1 inside, falling to 0 over the edge. */
|
||||
private double presenceShareAt(Pass pass, double shareX, double shareY, double shareZ) {
|
||||
if (presence == null) {
|
||||
return 1D;
|
||||
}
|
||||
return clampToShare((pass.cell(PRESENCE).at(shareX, shareY, shareZ) - presenceThreshold) / PRESENCE_EDGE);
|
||||
}
|
||||
|
||||
private static double clampToShare(double value) {
|
||||
|
||||
Reference in new issue
Block a user