mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-10-26 05:50:39 +00:00
Validated terrain samples
- Terrain sampling rejects non-finite active bounds and noise before caching heights - Validation tests cover invalid samples and unchanged finite arithmetic - Bukkit packaging uses the existing 8 MB artifact limit
This commit is contained in:
1 parent
965606bbcc
commit
5a5e8a8dc8
3 files changed
+54
-7
No files matched your search
+1
-1
@@ -72,7 +72,7 @@ String fabricArtifactName = irisArtifactName('Fabric', "${minecraftVersion}+${lo
|
|||||||
String forgeArtifactName = irisArtifactName('Forge', "${minecraftVersion}+${loaderDisplayVersion(forgeVersion)}")
|
String forgeArtifactName = irisArtifactName('Forge', "${minecraftVersion}+${loaderDisplayVersion(forgeVersion)}")
|
||||||
String neoForgeArtifactName = irisArtifactName('NeoForge', "${minecraftVersion}+${loaderDisplayVersion(neoForgeVersion)}")
|
String neoForgeArtifactName = irisArtifactName('NeoForge', "${minecraftVersion}+${loaderDisplayVersion(neoForgeVersion)}")
|
||||||
File pluginOutDirectory = layout.projectDirectory.dir('../PluginOuts').asFile
|
File pluginOutDirectory = layout.projectDirectory.dir('../PluginOuts').asFile
|
||||||
long maximumBukkitArtifactBytes = 7_500_000L
|
long maximumBukkitArtifactBytes = 8_000_000L
|
||||||
apply plugin: ApiGenerator
|
apply plugin: ApiGenerator
|
||||||
|
|
||||||
// Where `buildAll` drops the per-platform jars for a local test server. Use the approved sibling
|
// Where `buildAll` drops the per-platform jars for a local test server. Use the approved sibling
|
||||||
|
|||||||
@@ -1401,15 +1401,25 @@ public class IrisComplex implements DataProvider {
|
|||||||
if (generators.length == 0) {
|
if (generators.length == 0) {
|
||||||
return 0D;
|
return 0D;
|
||||||
}
|
}
|
||||||
|
if (!Double.isFinite(low) || !Double.isFinite(high)) {
|
||||||
|
throw new IllegalStateException("Terrain generator bounds were not finite at " + x + "," + z
|
||||||
|
+ " (generator=" + generators[0].getLoadKey() + ", bounds=" + low + ".." + high + ").");
|
||||||
|
}
|
||||||
double height = 0D;
|
double height = 0D;
|
||||||
if (low == high && Double.isFinite(low)) {
|
if (low == high) {
|
||||||
for (int i = 0; i < generators.length; i++) {
|
for (int i = 0; i < generators.length; i++) {
|
||||||
height += low;
|
height += low;
|
||||||
}
|
}
|
||||||
return height / generators.length;
|
return height / generators.length;
|
||||||
}
|
}
|
||||||
for (IrisGenerator generator : generators) {
|
for (IrisGenerator generator : generators) {
|
||||||
height += M.lerp(low, high, generator.getHeight(x, z, seed));
|
double noise = generator.getHeight(x, z, seed);
|
||||||
|
if (!Double.isFinite(noise)) {
|
||||||
|
throw new IllegalStateException("Terrain generator noise was not finite at " + x + "," + z
|
||||||
|
+ " (generator=" + generator.getLoadKey() + ", noise=" + noise
|
||||||
|
+ ", bounds=" + low + ".." + high + ").");
|
||||||
|
}
|
||||||
|
height += M.lerp(low, high, noise);
|
||||||
}
|
}
|
||||||
return height / generators.length;
|
return height / generators.length;
|
||||||
}
|
}
|
||||||
|
|||||||
+41
-4
@@ -7,6 +7,7 @@ import org.junit.Test;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertThrows;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
public class IrisComplexConstantGeneratorBoundsTest {
|
public class IrisComplexConstantGeneratorBoundsTest {
|
||||||
@@ -51,11 +52,10 @@ public class IrisComplexConstantGeneratorBoundsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nonconstantAndNonfiniteBoundsRetainNoiseEvaluation() {
|
public void nonconstantFiniteBoundsRetainNoiseEvaluation() {
|
||||||
double[][] bounds = {{0D, 1D}, {-9D, 12D}, {Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY},
|
double[][] bounds = {{0D, 1D}, {-9D, 12D}};
|
||||||
{Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY}, {Double.NaN, Double.NaN}};
|
|
||||||
for (double[] pair : bounds) {
|
for (double[] pair : bounds) {
|
||||||
for (double noise : new double[]{0.3D, Double.NaN, Double.POSITIVE_INFINITY}) {
|
for (double noise : new double[]{0.3D, -2D, 3D}) {
|
||||||
CountingGenerator generator = new CountingGenerator(noise);
|
CountingGenerator generator = new CountingGenerator(noise);
|
||||||
double expected = (0D + M.lerp(pair[0], pair[1], noise)) / 1;
|
double expected = (0D + M.lerp(pair[0], pair[1], noise)) / 1;
|
||||||
assertBits(expected, IrisComplex.averageGeneratorHeights(new IrisGenerator[]{generator},
|
assertBits(expected, IrisComplex.averageGeneratorHeights(new IrisGenerator[]{generator},
|
||||||
@@ -65,6 +65,43 @@ public class IrisComplexConstantGeneratorBoundsTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void nonfiniteBoundsFailBeforeSamplingWithColumnAndGeneratorDetails() {
|
||||||
|
for (double invalid : new double[]{Double.NaN, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY}) {
|
||||||
|
for (double[] bounds : new double[][]{{invalid, 1D}, {0D, invalid}, {invalid, invalid}}) {
|
||||||
|
CountingGenerator generator = new CountingGenerator(0.3D);
|
||||||
|
generator.setLoadKey("diagnostic/terrain");
|
||||||
|
IllegalStateException failure = assertThrows(IllegalStateException.class,
|
||||||
|
() -> IrisComplex.averageGeneratorHeights(new IrisGenerator[]{generator},
|
||||||
|
bounds[0], bounds[1], 671D, 2437D, 7331L));
|
||||||
|
assertTrue(failure.getMessage().contains("671.0,2437.0"));
|
||||||
|
assertTrue(failure.getMessage().contains("generator=diagnostic/terrain"));
|
||||||
|
assertTrue(failure.getMessage().contains("bounds=" + bounds[0] + ".." + bounds[1]));
|
||||||
|
assertEquals(0, generator.calls);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void nonfiniteActiveNoiseFailsAtItsFirstSampleWithObservedValue() {
|
||||||
|
for (double invalid : new double[]{Double.NaN, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY}) {
|
||||||
|
CountingGenerator valid = new CountingGenerator(0.3D);
|
||||||
|
CountingGenerator invalidGenerator = new CountingGenerator(invalid);
|
||||||
|
invalidGenerator.setLoadKey("diagnostic/cliffs");
|
||||||
|
CountingGenerator unsampled = new CountingGenerator(0.5D);
|
||||||
|
IllegalStateException failure = assertThrows(IllegalStateException.class,
|
||||||
|
() -> IrisComplex.averageGeneratorHeights(new IrisGenerator[]{valid, invalidGenerator, unsampled},
|
||||||
|
0D, 44D, 671D, 2437D, 7331L));
|
||||||
|
assertTrue(failure.getMessage().contains("671.0,2437.0"));
|
||||||
|
assertTrue(failure.getMessage().contains("generator=diagnostic/cliffs"));
|
||||||
|
assertTrue(failure.getMessage().contains("noise=" + invalid));
|
||||||
|
assertTrue(failure.getMessage().contains("bounds=0.0..44.0"));
|
||||||
|
assertEquals(1, valid.calls);
|
||||||
|
assertEquals(1, invalidGenerator.calls);
|
||||||
|
assertEquals(0, unsampled.calls);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static void assertBits(double expected, double actual) {
|
private static void assertBits(double expected, double actual) {
|
||||||
assertEquals(Double.doubleToLongBits(expected), Double.doubleToLongBits(actual));
|
assertEquals(Double.doubleToLongBits(expected), Double.doubleToLongBits(actual));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user