mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 16:54:04 +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<>();
|
||||
|
||||
Reference in new issue
Block a user