mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 08:44:50 +00:00
Enforce hydrology ranges at compile
- Compile rejects prefetchRings outside 0..4, fillEpsilon not above 0 and seeded cup density outside 0..64 - Compile rejects negative tier widthFactor and depthRatio, waterfallMinimumDrop below 2 and shoreDepth below 1 - Compile rejects negative maxFill, lakes.maxArea above 2048 squared and seaInlets.spacing below 1 - Compile rejects enabled cave pools whose freeboard max reaches maxDepth or whose maxArea exceeds 961 - Lake and cave pool area schema maxima match the compiled bounds; schema digest recaptured - Engine start checks dimension, region and biome policy fluids whether or not cave pools are enabled - Pack validation warns on written tiers without halfWidth or bankBand and on useMantle false or RIVER_HYDROLOGY disabled
This commit is contained in:
1 parent
720b9ac967
commit
5ef47f016e
9 files changed
+344
-17
No files matched your search
@@ -24,12 +24,12 @@ public class IrisCavePools {
|
||||
private double density = 0.15D;
|
||||
|
||||
@MinNumber(1)
|
||||
@MaxNumber(4096)
|
||||
@MaxNumber(961)
|
||||
@Description("Smallest pool surface in square blocks.")
|
||||
private int minArea = 6;
|
||||
|
||||
@MinNumber(1)
|
||||
@MaxNumber(65536)
|
||||
@MaxNumber(961)
|
||||
@Description("Largest pool surface in square blocks.")
|
||||
private int maxArea = 400;
|
||||
|
||||
|
||||
+2
-2
@@ -16,12 +16,12 @@ public class IrisHydrologyLakes {
|
||||
private boolean enabled = true;
|
||||
|
||||
@MinNumber(1024)
|
||||
@MaxNumber(134217728)
|
||||
@MaxNumber(4194304)
|
||||
@Description("Smallest lake surface in square blocks.")
|
||||
private int minArea = 65536;
|
||||
|
||||
@MinNumber(1024)
|
||||
@MaxNumber(134217728)
|
||||
@MaxNumber(4194304)
|
||||
@Description("Largest lake surface in square blocks. Larger hollows are drained by a cut through their rim.")
|
||||
private int maxArea = 4194304;
|
||||
}
|
||||
+3
-5
@@ -151,11 +151,9 @@ public final class HydrologyRuntime {
|
||||
Objects.requireNonNull(complex, "Hydrology needs the engine's terrain complex");
|
||||
HydrologySettings settings = HydrologySettings.compile(config, engine.getSeedManager().getBodies(), dimension.getFluidHeight(), 0,
|
||||
engine.getHeight());
|
||||
boolean caveFluidPolicies = false;
|
||||
if (settings.underground().cavePools().enabled()) {
|
||||
requireBiomeFluids(dimension.getReachableBiomes(engine), settings);
|
||||
caveFluidPolicies = requireCaveFluids(dimension, dimension.getAllRegions(engine), dimension.getReachableCaveBiomes(engine), settings);
|
||||
}
|
||||
requireBiomeFluids(dimension.getReachableBiomes(engine), settings);
|
||||
boolean caveFluidPolicies = requireCaveFluids(dimension, dimension.getAllRegions(engine), dimension.getReachableCaveBiomes(engine), settings)
|
||||
&& settings.underground().cavePools().enabled();
|
||||
if (settings.density() == 0D) {
|
||||
return DISABLED;
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import art.arcane.iris.generation.hydrology.config.IrisSeaInlets;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInletPlanner;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInletRasterizer;
|
||||
import art.arcane.iris.generation.hydrology.water.HydrologyTier;
|
||||
import art.arcane.iris.generation.hydrology.water.LakeCandidate;
|
||||
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.generation.terrain.IrisMaterialPalette;
|
||||
import com.google.gson.Gson;
|
||||
@@ -47,6 +48,12 @@ public final class HydrologySettings {
|
||||
private static final int INLET_LAST_STEP = (int) Math.ceil(WindowPlanner.CELL * Math.sqrt(2D));
|
||||
private static final int INLET_SHELL = SeaInletRasterizer.SHELL;
|
||||
public static final int MAX_CAVE_POOL_RADIUS = 15;
|
||||
private static final int CAVE_POOL_SPAN = 2 * MAX_CAVE_POOL_RADIUS + 1;
|
||||
private static final int MAX_CAVE_POOL_AREA = CAVE_POOL_SPAN * CAVE_POOL_SPAN;
|
||||
private static final int MAX_LAKE_AREA = LakeCandidate.MAX_EXTENT * LakeCandidate.MAX_EXTENT;
|
||||
private static final int MAX_PREFETCH_RINGS = 4;
|
||||
private static final int MAX_SEEDED_DENSITY = 64;
|
||||
private static final int MIN_WATERFALL_DROP = 2;
|
||||
|
||||
private final long seed;
|
||||
private final int seaLevel;
|
||||
@@ -88,6 +95,7 @@ public final class HydrologySettings {
|
||||
this.seams = seams(config.getFluids());
|
||||
this.prefetchRings = config.getPrefetchRings();
|
||||
this.persist = config.isPersist();
|
||||
requireBounds(config);
|
||||
requireFluidReferences();
|
||||
this.fingerprint = computeFingerprint();
|
||||
}
|
||||
@@ -498,6 +506,77 @@ public final class HydrologySettings {
|
||||
}
|
||||
}
|
||||
|
||||
private void requireBounds(IrisHydrology config) {
|
||||
requireWithin(prefetchRings, 0, MAX_PREFETCH_RINGS, "prefetchRings");
|
||||
requirePositive(config.getDrainage().getFillEpsilon(), "drainage.fillEpsilon");
|
||||
for (int index = 0; index < config.getTiers().size(); index++) {
|
||||
requireTierBounds(config.getTiers().get(index), "tiers[" + index + "]");
|
||||
}
|
||||
double seeded = config.getPonds().getSeeded().getDensity();
|
||||
if (!(seeded >= 0D && seeded <= MAX_SEEDED_DENSITY)) {
|
||||
throw new IllegalArgumentException("Hydrology ponds.seeded.density must stay within 0.." + MAX_SEEDED_DENSITY + ", got " + seeded);
|
||||
}
|
||||
requireShoreDepth(ponds.materials(), "ponds.materials");
|
||||
requireAtLeast(deformation.maxFill(), 0, "deformation.maxFill");
|
||||
if (lakes.maxArea() > MAX_LAKE_AREA) {
|
||||
throw new IllegalArgumentException("Hydrology lakes.maxArea must not go above " + MAX_LAKE_AREA + " (" + LakeCandidate.MAX_EXTENT
|
||||
+ " by " + LakeCandidate.MAX_EXTENT + " blocks, the widest a lake can span), got " + lakes.maxArea());
|
||||
}
|
||||
requireAtLeast(underground.seaInlets().spacing(), 1, "underground.seaInlets.spacing");
|
||||
requireCavePoolBounds(underground.cavePools());
|
||||
}
|
||||
|
||||
private static void requireTierBounds(IrisHydrologyTier config, String field) {
|
||||
requireNonNegative(config.getWidthFactor(), field + ".widthFactor");
|
||||
requireNonNegative(config.getDepthRatio(), field + ".depthRatio");
|
||||
requireAtLeast(config.getWaterfallMinimumDrop(), MIN_WATERFALL_DROP, field + ".waterfallMinimumDrop");
|
||||
requireShoreDepth(config.getMaterials(), field + ".materials");
|
||||
}
|
||||
|
||||
private static void requireShoreDepth(IrisHydrologyMaterials materials, String field) {
|
||||
if (materials != null) {
|
||||
requireAtLeast(materials.getShoreDepth(), 1, field + ".shoreDepth");
|
||||
}
|
||||
}
|
||||
|
||||
private static void requireCavePoolBounds(CavePools pools) {
|
||||
if (!pools.enabled()) {
|
||||
return;
|
||||
}
|
||||
if (pools.freeboard().max() >= pools.maxDepth()) {
|
||||
throw new IllegalArgumentException("Hydrology underground.cavePools.freeboard max " + pools.freeboard().max()
|
||||
+ " must stay below maxDepth " + pools.maxDepth());
|
||||
}
|
||||
if (pools.maxArea() > MAX_CAVE_POOL_AREA) {
|
||||
throw new IllegalArgumentException("Hydrology underground.cavePools.maxArea must not go above " + MAX_CAVE_POOL_AREA + " ("
|
||||
+ CAVE_POOL_SPAN + " by " + CAVE_POOL_SPAN + " blocks, the widest a pool can spread), got " + pools.maxArea());
|
||||
}
|
||||
}
|
||||
|
||||
private static void requireWithin(int value, int min, int max, String field) {
|
||||
if (value < min || value > max) {
|
||||
throw new IllegalArgumentException("Hydrology " + field + " must stay within " + min + ".." + max + ", got " + value);
|
||||
}
|
||||
}
|
||||
|
||||
private static void requireAtLeast(int value, int min, String field) {
|
||||
if (value < min) {
|
||||
throw new IllegalArgumentException("Hydrology " + field + " must be at least " + min + ", got " + value);
|
||||
}
|
||||
}
|
||||
|
||||
private static void requireNonNegative(double value, String field) {
|
||||
if (!(Double.isFinite(value) && value >= 0D)) {
|
||||
throw new IllegalArgumentException("Hydrology " + field + " must be a finite value of at least 0, got " + value);
|
||||
}
|
||||
}
|
||||
|
||||
private static void requirePositive(double value, String field) {
|
||||
if (!(Double.isFinite(value) && value > 0D)) {
|
||||
throw new IllegalArgumentException("Hydrology " + field + " must be a finite value above 0, got " + value);
|
||||
}
|
||||
}
|
||||
|
||||
private void requireFluidReferences() {
|
||||
for (Map.Entry<String, String> seam : seams.entrySet()) {
|
||||
requireFluid(seam.getValue(), "the seam of fluid '" + seam.getKey() + "'");
|
||||
|
||||
@@ -5,6 +5,7 @@ import art.arcane.iris.generation.decoration.HydrologyVegetation;
|
||||
import art.arcane.iris.generation.decoration.IrisDecorator;
|
||||
import art.arcane.iris.generation.hydrology.config.IrisHydrology;
|
||||
import art.arcane.iris.generation.hydrology.config.IrisHydrologyPolicy;
|
||||
import art.arcane.iris.generation.hydrology.config.IrisHydrologyTier;
|
||||
import art.arcane.iris.generation.hydrology.config.IrisHydrologyWetness;
|
||||
import art.arcane.iris.generation.hydrology.plan.HydrologySettings;
|
||||
import art.arcane.iris.generation.terrain.IrisDimension;
|
||||
@@ -14,6 +15,7 @@ import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.volmlib.util.json.JSONArray;
|
||||
import art.arcane.volmlib.util.json.JSONObject;
|
||||
import art.arcane.volmlib.util.mantle.flag.ReservedFlag;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
@@ -39,31 +41,36 @@ final class PackHydrologyValidator {
|
||||
new RangeField("underground.cavePools.freeboard", Floor.NON_NEGATIVE, true)
|
||||
);
|
||||
private static final List<String> FLUID_REFERENCES = List.of("ponds.fluid", "underground.cavePools.fluid");
|
||||
private static final IrisHydrologyTier DEFAULT_TIER = new IrisHydrologyTier();
|
||||
private static final String MANTLE_WATER = "the falling water at waterfalls and cascades, sea inlets and cave pools";
|
||||
|
||||
private PackHydrologyValidator() {
|
||||
}
|
||||
|
||||
static Validation validate(File packFolder, File[] dimensionFiles) {
|
||||
List<String> errors = new ArrayList<>();
|
||||
List<String> warnings = new ArrayList<>();
|
||||
if (packFolder == null || !packFolder.isDirectory() || dimensionFiles == null) {
|
||||
return new Validation(errors, List.of());
|
||||
return new Validation(errors, warnings);
|
||||
}
|
||||
List<File> sortedDimensions = new ArrayList<>(List.of(dimensionFiles));
|
||||
sortedDimensions.sort(Comparator.comparing(File::getPath));
|
||||
File dimensionsFolder = new File(packFolder, PackValidator.DIMENSIONS_FOLDER);
|
||||
Findings findings = new Findings(errors, warnings);
|
||||
IrisData data = null;
|
||||
try {
|
||||
for (File dimensionFile : sortedDimensions) {
|
||||
data = validateDimension(packFolder, dimensionsFolder, dimensionFile, data, errors);
|
||||
data = validateDimension(packFolder, dimensionsFolder, dimensionFile, data, findings);
|
||||
}
|
||||
} finally {
|
||||
close(packFolder, data, errors);
|
||||
}
|
||||
return new Validation(errors, List.of());
|
||||
return new Validation(errors, warnings);
|
||||
}
|
||||
|
||||
private static IrisData validateDimension(File packFolder, File dimensionsFolder, File dimensionFile, IrisData data,
|
||||
List<String> errors) {
|
||||
Findings findings) {
|
||||
List<String> errors = findings.errors();
|
||||
JSONObject dimension = PackValidationIo.readJson(dimensionFile);
|
||||
if (dimension == null || !dimension.has(CONFIG)) {
|
||||
return data;
|
||||
@@ -79,6 +86,7 @@ final class PackHydrologyValidator {
|
||||
}
|
||||
int reported = errors.size();
|
||||
validateRanges(path, hydrology, errors);
|
||||
warnPartialTiers(path, hydrology, findings.warnings());
|
||||
Set<String> fluids = fluidNames(hydrology);
|
||||
Set<String> seams = seamNames(hydrology);
|
||||
validateFluidReferences(path, hydrology, fluids, errors);
|
||||
@@ -87,6 +95,7 @@ final class PackHydrologyValidator {
|
||||
if (loadedDimension == null) {
|
||||
return loaded;
|
||||
}
|
||||
warnMantleOff("Dimension '" + dimensionKey + "'", loadedDimension, findings.warnings());
|
||||
validatePolicies(path, dimensionKey, loaded, loadedDimension, new PolicyFluids(fluids, seams), errors);
|
||||
if (errors.size() == reported && validateCompile(path, loadedDimension, errors)) {
|
||||
validateDecoratorBlocks(path, loaded, loadedDimension.getHydrology(), errors);
|
||||
@@ -150,6 +159,37 @@ final class PackHydrologyValidator {
|
||||
}
|
||||
}
|
||||
|
||||
private static void warnPartialTiers(String path, JSONObject hydrology, List<String> warnings) {
|
||||
JSONArray tiers = hydrology.optJSONArray("tiers");
|
||||
if (tiers == null) {
|
||||
return;
|
||||
}
|
||||
for (int index = 0; index < tiers.length(); index++) {
|
||||
JSONObject tier = tiers.optJSONObject(index);
|
||||
if (tier == null) {
|
||||
continue;
|
||||
}
|
||||
String field = path + ".tiers[" + index + "] ('" + tier.optString("name", DEFAULT_TIER.getName()) + "')";
|
||||
if (!tier.has("halfWidth")) {
|
||||
warnings.add(field + " does not set halfWidth, so it takes the default " + DEFAULT_TIER.getHalfWidth() + ".");
|
||||
}
|
||||
if (!tier.has("bankBand")) {
|
||||
warnings.add(field + " does not set bankBand, so it takes the default " + DEFAULT_TIER.getBankBand()
|
||||
+ " and leaves the ground beside its channels as it is.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void warnMantleOff(String path, IrisDimension dimension, List<String> warnings) {
|
||||
if (!dimension.isUseMantle()) {
|
||||
warnings.add(path + " sets useMantle to false while hydrology is enabled, so " + MANTLE_WATER + " are not generated.");
|
||||
}
|
||||
if (dimension.getDisabledComponents() != null && dimension.getDisabledComponents().contains(ReservedFlag.RIVER_HYDROLOGY)) {
|
||||
warnings.add(path + " disables the " + ReservedFlag.RIVER_HYDROLOGY + " component while hydrology is enabled, so " + MANTLE_WATER
|
||||
+ " are not generated.");
|
||||
}
|
||||
}
|
||||
|
||||
private static double[] range(String field, Object value, Floor floor, boolean whole, List<String> errors) {
|
||||
if (!(value instanceof JSONArray pair) || pair.length() != 2 || !(pair.opt(0) instanceof Number first)
|
||||
|| !(pair.opt(1) instanceof Number second)) {
|
||||
@@ -320,4 +360,7 @@ final class PackHydrologyValidator {
|
||||
|
||||
private record PolicyFluids(Set<String> defined, Set<String> seams) {
|
||||
}
|
||||
|
||||
private record Findings(List<String> errors, List<String> warnings) {
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user