mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 08:44:50 +00:00
Hydrology climate zones
- Hydrology climate splits the land into wet and dry zones with a noise style - Dry zones keep only the dryRainfall share of rainfall and pond density - Zone edges ease across the transition band - Policy climateZones exempts an area from the dry zones - Policy fluid also fills streams and rivers that flow through the area - Bank steepness reads the steepest natural ground between the bank and the water - Bank edges roughen with smooth noise - Natural ground heights reach the rasterizer at full precision - Settings reject climate values outside 0..1 - Hydrology probes read the full precision natural heights
This commit is contained in:
1 parent
304e66b74b
commit
c2eca3e6bd
26 files changed
+427
-73
No files matched your search
+46
@@ -129,6 +129,52 @@ public class IrisHydrologyTerrainSourceTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void climateZonesDryOutRainfallAndPondsOutsideOptedOutBiomes() throws Exception {
|
||||
Path pack = EngineFixture.pack(temporaryFolder.newFolder().toPath());
|
||||
int[] xs = new int[COLUMNS];
|
||||
int[] zs = new int[COLUMNS];
|
||||
columns(xs, zs);
|
||||
try (EngineFixture.Environment ignored = EngineFixture.environment(); EngineFixture fixture = new EngineFixture(pack)) {
|
||||
IrisHydrology config = new IrisHydrology().setEnabled(true).setPersist(false);
|
||||
config.getClimate().setEnabled(true).setDryness(0.5D).setTransition(0D).getStyle().setZoom(4D);
|
||||
HydrologySettings settings = HydrologySettings.compile(config, EngineFixture.SEED, fixture.dimension.getFluidHeight(), 0,
|
||||
EngineFixture.HEIGHT);
|
||||
fixture.data.getBiomeLoader().load("meadow").getHydrologyPolicy().setClimateZones(false);
|
||||
IrisHydrologyTerrainSource source = new IrisHydrologyTerrainSource(fixture.complex, fixture.dimension, settings, null, 1,
|
||||
HydrologyBinding.UNBOUND);
|
||||
HydrologySampleBuffer samples = new HydrologySampleBuffer(COLUMNS);
|
||||
source.sample(xs, zs, samples, false);
|
||||
int dry = 0;
|
||||
int wet = 0;
|
||||
int kept = 0;
|
||||
for (int index = 0; index < COLUMNS; index++) {
|
||||
int x = xs[index];
|
||||
int z = zs[index];
|
||||
boolean meadow = fixture.complex.getBaseBiomeStream().get(x, z).getLoadKey().equals("meadow");
|
||||
boolean alpha = fixture.complex.getRegionStream().get(x, z).getLoadKey().equals("alpha");
|
||||
String at = x + "," + z;
|
||||
assertEquals(at, alpha ? "water" : null, source.channelFluid(x, z));
|
||||
if (meadow) {
|
||||
assertEquals(at, 2f, samples.rainfall()[index], 0f);
|
||||
assertEquals(at, alpha ? 3f : 1f, samples.pondDensity()[index], 0f);
|
||||
kept++;
|
||||
continue;
|
||||
}
|
||||
boolean zoneDry = samples.rainfall()[index] == 0f;
|
||||
assertEquals(at, zoneDry ? 0f : 0.5f, samples.rainfall()[index], 0f);
|
||||
assertEquals(at, zoneDry ? 0f : alpha ? 3f : 1f, samples.pondDensity()[index], 0f);
|
||||
if (zoneDry) {
|
||||
dry++;
|
||||
} else {
|
||||
wet++;
|
||||
}
|
||||
}
|
||||
assertTrue("dry columns " + dry + ", wet columns " + wet + ", opted-out columns " + kept,
|
||||
dry > COLUMNS / 20 && wet > COLUMNS / 20 && kept > 0);
|
||||
}
|
||||
}
|
||||
|
||||
private static void assertUnknownFluidRejected(EngineFixture fixture, HydrologySettings settings, int[] xs, int[] zs) {
|
||||
IrisRegion beta = fixture.data.getRegionLoader().load("beta");
|
||||
beta.setHydrologyPolicy(new IrisHydrologyPolicy().setFluid("slime"));
|
||||
|
||||
+49
@@ -48,6 +48,55 @@ public class HydrologySettingsTest {
|
||||
@Rule
|
||||
public final TemporaryFolder temporary = new TemporaryFolder();
|
||||
|
||||
@Test
|
||||
public void climateIsBoundedAndOnlyEnabledZonesChangeThePlanIdentity() {
|
||||
HydrologySettings plain = compile(new IrisHydrology());
|
||||
IrisHydrology disabled = new IrisHydrology();
|
||||
disabled.getClimate().setDryness(0.8D).setTransition(0.3D);
|
||||
assertEquals(plain.fingerprint(), compile(disabled).fingerprint());
|
||||
IrisHydrology zoned = new IrisHydrology();
|
||||
zoned.getClimate().setEnabled(true);
|
||||
IrisHydrology drier = new IrisHydrology();
|
||||
drier.getClimate().setEnabled(true).setDryness(0.6D);
|
||||
IrisHydrology larger = new IrisHydrology();
|
||||
larger.getClimate().setEnabled(true).getStyle().setZoom(48D);
|
||||
Set<Long> fingerprints = new HashSet<>(List.of(plain.fingerprint(), compile(zoned).fingerprint(), compile(drier).fingerprint(),
|
||||
compile(larger).fingerprint()));
|
||||
assertEquals(4, fingerprints.size());
|
||||
for (double invalid : new double[]{-0.01D, 1.01D, Double.NaN}) {
|
||||
IrisHydrology dryness = new IrisHydrology();
|
||||
dryness.getClimate().setDryness(invalid);
|
||||
assertRejected(dryness, "climate.dryness");
|
||||
IrisHydrology transition = new IrisHydrology();
|
||||
transition.getClimate().setTransition(invalid);
|
||||
assertRejected(transition, "climate.transition");
|
||||
IrisHydrology dryRainfall = new IrisHydrology();
|
||||
dryRainfall.getClimate().setDryRainfall(invalid);
|
||||
assertRejected(dryRainfall, "climate.dryRainfall");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void climateWetnessFadesFromDryToWetZones() {
|
||||
HydrologySettings.Climate off = compile(new IrisHydrology()).climate();
|
||||
assertEquals(1D, off.wetness(0D), 0D);
|
||||
IrisHydrology sharp = new IrisHydrology();
|
||||
sharp.getClimate().setEnabled(true).setDryness(0.5D).setTransition(0D);
|
||||
HydrologySettings.Climate edge = compile(sharp).climate();
|
||||
assertEquals(0D, edge.wetness(0.49D), 0D);
|
||||
assertEquals(1D, edge.wetness(0.5D), 0D);
|
||||
IrisHydrology soft = new IrisHydrology();
|
||||
soft.getClimate().setEnabled(true).setDryness(0.5D).setTransition(0.2D).setDryRainfall(0.25D);
|
||||
HydrologySettings.Climate faded = compile(soft).climate();
|
||||
assertEquals(0.25D, faded.wetness(0.3D), 1e-9D);
|
||||
assertEquals(0.625D, faded.wetness(0.5D), 1e-9D);
|
||||
assertEquals(1D, faded.wetness(0.7D), 1e-9D);
|
||||
assertTrue(faded.wetness(0.45D) < faded.wetness(0.55D));
|
||||
IrisHydrology wet = new IrisHydrology();
|
||||
wet.getClimate().setEnabled(true).setDryness(0D);
|
||||
assertEquals(1D, compile(wet).climate().wetness(0D), 0D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tierForPicksHighestTierBelowCatchment() {
|
||||
HydrologySettings settings = compile(new IrisHydrology());
|
||||
|
||||
+94
-9
@@ -261,7 +261,7 @@ public class ChunkWaterRasterTest {
|
||||
assertTrue("the chain ends at or below the first end grade", previous <= 60);
|
||||
List<IndexedWindow> reversed = new ArrayList<>(scene.windows(31, 34));
|
||||
Collections.reverse(reversed);
|
||||
ChunkWaterRaster backward = new ChunkRasterizer(scene.settings).rasterize(31, 34, scene.natural, reversed, scene.regions(31, 34));
|
||||
ChunkWaterRaster backward = new ChunkRasterizer(scene.settings, ChannelFluids.TIER).rasterize(31, 34, scene.natural::applyAsInt, reversed, scene.regions(31, 34));
|
||||
for (int lz = 0; lz < 16; lz++) {
|
||||
for (int lx = 0; lx < 16; lx++) {
|
||||
assertEquals(scene.raster(31, 34).waterHead(lx, lz), backward.waterHead(lx, lz));
|
||||
@@ -403,7 +403,7 @@ public class ChunkWaterRasterTest {
|
||||
SeaInlet inlet = new SeaInlet(71L, xs, zs, halfWidth, SEA_LEVEL, floor, ceiling, 64, 8, 6);
|
||||
WindowKey key = new WindowKey(0, 0);
|
||||
IndexedWindow own = new IndexedWindow(new WindowPlan(key, List.of(), List.of(), List.of(inlet)), ReachIndex.build(List.of(), List.of()));
|
||||
ChunkRasterizer rasterizer = new ChunkRasterizer(settings);
|
||||
ChunkRasterizer rasterizer = new ChunkRasterizer(settings, ChannelFluids.TIER);
|
||||
ChunkWaterRaster mouth = rasterizer.rasterize(0, 0, (x, z) -> 70, List.of(own), regions(0, 0, List.of()));
|
||||
int[] column = new int[2];
|
||||
int open = 0;
|
||||
@@ -440,8 +440,8 @@ public class ChunkWaterRasterTest {
|
||||
samples.incrementAndGet();
|
||||
return 70;
|
||||
};
|
||||
ChunkRasterizer rasterizer = new ChunkRasterizer(settings);
|
||||
ChunkWaterRaster raster = rasterizer.rasterize(0, 0, natural, List.of(own), regions(0, 0, List.of()));
|
||||
ChunkRasterizer rasterizer = new ChunkRasterizer(settings, ChannelFluids.TIER);
|
||||
ChunkWaterRaster raster = rasterizer.rasterize(0, 0, natural::applyAsInt, List.of(own), regions(0, 0, List.of()));
|
||||
assertTrue(raster.empty());
|
||||
assertFalse(raster.provisional());
|
||||
assertEquals("a riverless chunk never samples natural heights", 0, samples.get());
|
||||
@@ -459,9 +459,94 @@ public class ChunkWaterRasterTest {
|
||||
assertThrows(IllegalStateException.class, () -> raster.terrainHeight(0, 0));
|
||||
assertTrue(ChunkWaterRaster.PROVISIONAL.provisional());
|
||||
assertTrue(ChunkWaterRaster.PROVISIONAL.empty());
|
||||
assertThrows(IllegalArgumentException.class, () -> rasterizer.rasterize(40, 0, natural, List.of(own), regions(40, 0, List.of())));
|
||||
assertThrows(IllegalArgumentException.class, () -> rasterizer.rasterize(40, 0, natural::applyAsInt, List.of(own), regions(40, 0, List.of())));
|
||||
assertFalse("a chunk on the reach is not empty",
|
||||
rasterizer.rasterize(27, 25, natural, List.of(own), regions(27, 25, List.of())).empty());
|
||||
rasterizer.rasterize(27, 25, natural::applyAsInt, List.of(own), regions(27, 25, List.of())).empty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void channelTakesTheAreaFluidWhereOneIsSet() {
|
||||
HydrologySettings settings = settings(new IrisHydrology());
|
||||
Reach reach = line(61L, tier("stream", 1.5f, 0.5f, 0, IrisBankStyle.SMOOTH), 0L, 400f, 400f, 480f, 400f, (x, z) -> 69);
|
||||
WindowKey key = new WindowKey(0, 0);
|
||||
IndexedWindow own = new IndexedWindow(new WindowPlan(key, List.of(reach), List.of(), List.of()), ReachIndex.build(List.of(reach), List.of()));
|
||||
ChannelFluids volcanic = (x, z) -> x < 440 ? "lava" : null;
|
||||
ChunkWaterRaster raster = new ChunkRasterizer(settings, volcanic).rasterize(27, 25, (x, z) -> 70, List.of(own), regions(27, 25, List.of()));
|
||||
int lava = 0;
|
||||
int water = 0;
|
||||
for (int lz = 0; lz < 16; lz++) {
|
||||
for (int lx = 0; lx < 16; lx++) {
|
||||
if (!isChannel(raster.role(lx, lz))) {
|
||||
continue;
|
||||
}
|
||||
boolean inside = 27 * 16 + lx < 440;
|
||||
assertEquals("column " + lx + "," + lz, inside ? "lava" : "water", raster.fluid(lx, lz));
|
||||
if (inside) {
|
||||
lava++;
|
||||
} else {
|
||||
water++;
|
||||
}
|
||||
}
|
||||
}
|
||||
assertTrue("lava columns " + lava + ", water columns " + water, lava > 0 && water > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void banksNeverDipAwayFromTheWater() {
|
||||
HydrologySettings settings = settings(new IrisHydrology());
|
||||
Reach river = line(81L, tier("river", 3f, 0.5f, 32, IrisBankStyle.SMOOTH), 0L, 96f, 256f, 416f, 256f, (x, z) -> 69);
|
||||
WindowKey key = new WindowKey(0, 0);
|
||||
IndexedWindow own = new IndexedWindow(new WindowPlan(key, List.of(river), List.of(), List.of()), ReachIndex.build(List.of(river), List.of()));
|
||||
NaturalHeights natural = (x, z) -> {
|
||||
double away = Math.abs(z - 256);
|
||||
if (x < 256) {
|
||||
return 70D + 8D * Math.min(1D, away / 8D) + 0.15D * Math.max(0D, away - 8D);
|
||||
}
|
||||
return 70D + 8D * (1D - Math.exp(-away / 6D)) + (x < 336 ? 0D : 0.15D * away);
|
||||
};
|
||||
ChunkRasterizer rasterizer = new ChunkRasterizer(settings, ChannelFluids.TIER);
|
||||
Map<Long, Integer> terrain = new HashMap<>();
|
||||
Map<Long, WaterRole> roles = new HashMap<>();
|
||||
for (int chunkZ = 13; chunkZ <= 18; chunkZ++) {
|
||||
for (int chunkX = 12; chunkX <= 25; chunkX++) {
|
||||
ChunkWaterRaster raster = rasterizer.rasterize(chunkX, chunkZ, natural, List.of(own), regions(chunkX, chunkZ, List.of()));
|
||||
for (int lz = 0; lz < 16; lz++) {
|
||||
for (int lx = 0; lx < 16; lx++) {
|
||||
int x = chunkX * 16 + lx;
|
||||
int z = chunkZ * 16 + lz;
|
||||
terrain.put(column(x, z), raster.empty() ? (int) Math.round(natural.height(x, z)) : raster.terrainHeight(lx, lz));
|
||||
roles.put(column(x, z), raster.empty() ? WaterRole.NONE : raster.role(lx, lz));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
int cut = 0;
|
||||
List<String> pits = new ArrayList<>();
|
||||
for (int z = 13 * 16 + 1; z < 19 * 16 - 1; z++) {
|
||||
for (int x = 12 * 16 + 1; x < 26 * 16 - 1; x++) {
|
||||
if (roles.get(column(x, z)) != WaterRole.BANK) {
|
||||
continue;
|
||||
}
|
||||
int height = terrain.get(column(x, z));
|
||||
if (height < (int) Math.round(natural.height(x, z))) {
|
||||
cut++;
|
||||
}
|
||||
int inward = z > 256 ? z - 1 : z + 1;
|
||||
if (z == 256 || roles.get(column(x, inward)) != WaterRole.BANK) {
|
||||
continue;
|
||||
}
|
||||
int nearer = terrain.get(column(x, inward));
|
||||
if (height < nearer) {
|
||||
pits.add(x + "," + z + "@" + height + "<" + nearer);
|
||||
}
|
||||
}
|
||||
}
|
||||
assertTrue("cut bank columns " + cut, cut > 400);
|
||||
assertTrue("bank dips " + pits.size() + " " + pits.subList(0, Math.min(10, pits.size())), pits.isEmpty());
|
||||
}
|
||||
|
||||
private static long column(int x, int z) {
|
||||
return ((long) x << 32) | (z & 0xFFFFFFFFL);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -525,7 +610,7 @@ public class ChunkWaterRasterTest {
|
||||
ChunkWaterRaster forward = scene.raster(31, 12);
|
||||
List<IndexedWindow> reversed = new ArrayList<>(scene.windows(31, 12));
|
||||
Collections.reverse(reversed);
|
||||
ChunkWaterRaster backward = new ChunkRasterizer(scene.settings).rasterize(31, 12, scene.natural, reversed, scene.regions(31, 12));
|
||||
ChunkWaterRaster backward = new ChunkRasterizer(scene.settings, ChannelFluids.TIER).rasterize(31, 12, scene.natural::applyAsInt, reversed, scene.regions(31, 12));
|
||||
for (int lz = 0; lz < 16; lz++) {
|
||||
for (int lx = 0; lx < 16; lx++) {
|
||||
assertEquals(forward.waterHead(lx, lz), backward.waterHead(lx, lz));
|
||||
@@ -837,7 +922,7 @@ public class ChunkWaterRasterTest {
|
||||
private Scene(HydrologySettings settings, IntBinaryOperator natural) {
|
||||
this.settings = settings;
|
||||
this.natural = natural;
|
||||
this.rasterizer = new ChunkRasterizer(settings);
|
||||
this.rasterizer = new ChunkRasterizer(settings, ChannelFluids.TIER);
|
||||
}
|
||||
|
||||
private Scene reach(Reach reach) {
|
||||
@@ -862,7 +947,7 @@ public class ChunkWaterRasterTest {
|
||||
|
||||
private ChunkWaterRaster raster(int chunkX, int chunkZ) {
|
||||
return rasters.computeIfAbsent(pack(chunkX, chunkZ),
|
||||
key -> rasterizer.rasterize(chunkX, chunkZ, natural, windows(chunkX, chunkZ), regions(chunkX, chunkZ)));
|
||||
key -> rasterizer.rasterize(chunkX, chunkZ, natural::applyAsInt, windows(chunkX, chunkZ), regions(chunkX, chunkZ)));
|
||||
}
|
||||
|
||||
private List<IndexedWindow> windows(int chunkX, int chunkZ) {
|
||||
|
||||
@@ -15,6 +15,7 @@ import art.arcane.iris.generation.hydrology.plan.RegionKey;
|
||||
import art.arcane.iris.generation.hydrology.plan.RegionPlan;
|
||||
import art.arcane.iris.generation.hydrology.plan.WindowKey;
|
||||
import art.arcane.iris.generation.hydrology.plan.WindowPlan;
|
||||
import art.arcane.iris.generation.hydrology.raster.ChannelFluids;
|
||||
import art.arcane.iris.generation.hydrology.raster.ChunkRasterizer;
|
||||
import art.arcane.iris.generation.hydrology.raster.ChunkWaterRaster;
|
||||
import art.arcane.iris.generation.hydrology.raster.ReachIndex;
|
||||
@@ -656,7 +657,7 @@ public class PondPlannerTest {
|
||||
|
||||
private static void assertRasterRimContained(HydrologySettings settings, Pond pond, DoubleBinaryOperator natural) {
|
||||
Map<Long, ChunkWaterRaster> rasters = new HashMap<>();
|
||||
ChunkRasterizer rasterizer = new ChunkRasterizer(settings);
|
||||
ChunkRasterizer rasterizer = new ChunkRasterizer(settings, ChannelFluids.TIER);
|
||||
int raised = 0;
|
||||
int[][] sides = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
|
||||
for (int[] wet : wetNodes(pond.mask())) {
|
||||
|
||||
+2
-2
@@ -123,8 +123,8 @@ public class IrisEngineGenerationRuntimeScopeTest {
|
||||
AtomicInteger workerNaturals = new AtomicInteger();
|
||||
doAnswer(invocation -> {
|
||||
observe(engine, historical, caller, naturals, workerNaturals, foreign);
|
||||
return (int) Math.round(bowl(invocation.getArgument(0), invocation.getArgument(1)));
|
||||
}).when(historicalComplex).naturalTrueHeight(anyInt(), anyInt());
|
||||
return bowl(invocation.getArgument(0), invocation.getArgument(1));
|
||||
}).when(historicalComplex).naturalHeight(anyInt(), anyInt());
|
||||
IrisEngine.GenerationRuntimeBinding binding = detachedBinding(engine, historical.runtime);
|
||||
HydrologyRuntime hydrology;
|
||||
try (IrisEngine.GenerationRuntimeScope ignored = engine.openGenerationRuntimeScope(binding)) {
|
||||
|
||||
@@ -84,7 +84,7 @@ public class SchemaBuilderIdentityTest {
|
||||
@ClassRule
|
||||
public static final PlatformLeakGuard PLATFORM_GUARD = PlatformLeakGuard.clean();
|
||||
|
||||
private static final String EXPECTED_SCHEMA_DIGEST = "b8dd16d1a3188e8150a68a9d5b2964aed5094d679c0f941e3703aec675f87e20";
|
||||
private static final String EXPECTED_SCHEMA_DIGEST = "2224e73a1e9d76231d4df8bb1992451340e5f533b3fbafae9f4e1437747e666c";
|
||||
|
||||
private static final List<Class<?>> SCHEMA_ROOTS = List.of(
|
||||
IrisDimension.class,
|
||||
|
||||
@@ -83,7 +83,7 @@ public final class FakeHydrology implements AutoCloseable {
|
||||
});
|
||||
HydrologySettings settings = settings(seaLevel);
|
||||
HydrologyPlanCache cache = new HydrologyPlanCache(settings, this::region, this::window, pool, mainThread);
|
||||
this.runtime = new HydrologyRuntime(settings, cache, naturalHeight, mainThread, System::nanoTime);
|
||||
this.runtime = new HydrologyRuntime(settings, cache, naturalHeight::applyAsInt, mainThread, System::nanoTime);
|
||||
}
|
||||
|
||||
public static HydrologySettings settings(int seaLevel) {
|
||||
|
||||
@@ -9,6 +9,7 @@ import art.arcane.iris.generation.hydrology.plan.RegionKey;
|
||||
import art.arcane.iris.generation.hydrology.plan.RegionPlan;
|
||||
import art.arcane.iris.generation.hydrology.plan.WindowKey;
|
||||
import art.arcane.iris.generation.hydrology.plan.WindowPlan;
|
||||
import art.arcane.iris.generation.hydrology.raster.ChannelFluids;
|
||||
import art.arcane.iris.generation.hydrology.raster.ChunkRasterizer;
|
||||
import art.arcane.iris.generation.hydrology.raster.ChunkWaterRaster;
|
||||
import art.arcane.iris.generation.hydrology.raster.ReachIndex;
|
||||
@@ -40,7 +41,7 @@ public final class WaterScene {
|
||||
|
||||
public WaterScene(IrisHydrology config, IntBinaryOperator natural) {
|
||||
this.natural = natural;
|
||||
this.rasterizer = new ChunkRasterizer(HydrologySettings.compile(config, SEED, SEA_LEVEL, MIN_Y, MAX_Y));
|
||||
this.rasterizer = new ChunkRasterizer(HydrologySettings.compile(config, SEED, SEA_LEVEL, MIN_Y, MAX_Y), ChannelFluids.TIER);
|
||||
}
|
||||
|
||||
public WaterScene reach(Reach reach) {
|
||||
@@ -55,7 +56,7 @@ public final class WaterScene {
|
||||
|
||||
public ChunkWaterRaster raster(int chunkX, int chunkZ) {
|
||||
return rasters.computeIfAbsent(((long) chunkX << 32) | (chunkZ & 0xFFFFFFFFL),
|
||||
key -> rasterizer.rasterize(chunkX, chunkZ, natural, windows(chunkX, chunkZ), regions(chunkX, chunkZ)));
|
||||
key -> rasterizer.rasterize(chunkX, chunkZ, natural::applyAsInt, windows(chunkX, chunkZ), regions(chunkX, chunkZ)));
|
||||
}
|
||||
|
||||
public int terrain(int x, int z) {
|
||||
|
||||
Reference in new issue
Block a user