mirror of
https://github.com/BX-Team/DivineMC.git
synced 2025-12-21 07:49:18 +00:00
603 lines
28 KiB
Diff
603 lines
28 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
|
|
Date: Fri, 31 Jan 2025 21:50:46 +0300
|
|
Subject: [PATCH] Native Math Optimizations
|
|
|
|
|
|
diff --git a/com/mojang/math/OctahedralGroup.java b/com/mojang/math/OctahedralGroup.java
|
|
index 11902e7427761746ee098fea3276a34fef0096ba..3ba23fa243f7af712a41316066ca554f1c23b495 100644
|
|
--- a/com/mojang/math/OctahedralGroup.java
|
|
+++ b/com/mojang/math/OctahedralGroup.java
|
|
@@ -112,6 +112,7 @@ public enum OctahedralGroup implements StringRepresentable {
|
|
this.transformation = new Matrix3f().scaling(invertX ? -1.0F : 1.0F, invertY ? -1.0F : 1.0F, invertZ ? -1.0F : 1.0F);
|
|
this.transformation.mul(permutation.transformation());
|
|
this.initializeRotationDirections(); // Paper - Avoid Lazy Initialization for Enum Fields
|
|
+ this.rotate(Direction.UP); // DivineMC - Math Optimizations
|
|
}
|
|
|
|
private BooleanList packInversions() {
|
|
diff --git a/com/mojang/math/Transformation.java b/com/mojang/math/Transformation.java
|
|
index aa755b8b7f8bc5910322e0c5b520f603da06a85a..e781dea43279aa77cc40a7afd2281c32cc8347a9 100644
|
|
--- a/com/mojang/math/Transformation.java
|
|
+++ b/com/mojang/math/Transformation.java
|
|
@@ -51,6 +51,7 @@ public final class Transformation {
|
|
} else {
|
|
this.matrix = matrix;
|
|
}
|
|
+ ensureDecomposed(); // DivineMC - Math Optimizations
|
|
}
|
|
|
|
public Transformation(@Nullable Vector3f translation, @Nullable Quaternionf leftRotation, @Nullable Vector3f scale, @Nullable Quaternionf rightRotation) {
|
|
@@ -60,6 +61,7 @@ public final class Transformation {
|
|
this.scale = scale != null ? scale : new Vector3f(1.0F, 1.0F, 1.0F);
|
|
this.rightRotation = rightRotation != null ? rightRotation : new Quaternionf();
|
|
this.decomposed = true;
|
|
+ ensureDecomposed(); // DivineMC - Math Optimizations
|
|
}
|
|
|
|
public static Transformation identity() {
|
|
diff --git a/net/minecraft/util/Mth.java b/net/minecraft/util/Mth.java
|
|
index ae1ab070a93b46a0790eed3feda1d09f5fbe9b25..3befc00c10ce8f29d3ee1ea493c2b220df5eaaea 100644
|
|
--- a/net/minecraft/util/Mth.java
|
|
+++ b/net/minecraft/util/Mth.java
|
|
@@ -58,18 +58,15 @@ public class Mth {
|
|
}
|
|
|
|
public static int floor(float value) {
|
|
- int i = (int)value;
|
|
- return value < i ? i - 1 : i;
|
|
+ return (int) Math.floor(value); // DivineMC - Math Optimizations
|
|
}
|
|
|
|
public static int floor(double value) {
|
|
- int i = (int)value;
|
|
- return value < i ? i - 1 : i;
|
|
+ return (int) Math.floor(value); // DivineMC - Math Optimizations
|
|
}
|
|
|
|
public static long lfloor(double value) {
|
|
- long l = (long)value;
|
|
- return value < l ? l - 1L : l;
|
|
+ return (long) Math.floor(value); // DivineMC - Math Optimizations
|
|
}
|
|
|
|
public static float abs(float value) {
|
|
@@ -81,13 +78,11 @@ public class Mth {
|
|
}
|
|
|
|
public static int ceil(float value) {
|
|
- int i = (int)value;
|
|
- return value > i ? i + 1 : i;
|
|
+ return (int) Math.ceil(value); // DivineMC - Math Optimizations
|
|
}
|
|
|
|
public static int ceil(double value) {
|
|
- int i = (int)value;
|
|
- return value > i ? i + 1 : i;
|
|
+ return (int) Math.ceil(value); // DivineMC - Math Optimizations
|
|
}
|
|
|
|
public static int clamp(int value, int min, int max) {
|
|
@@ -123,15 +118,7 @@ public class Mth {
|
|
}
|
|
|
|
public static double absMax(double x, double y) {
|
|
- if (x < 0.0) {
|
|
- x = -x;
|
|
- }
|
|
-
|
|
- if (y < 0.0) {
|
|
- y = -y;
|
|
- }
|
|
-
|
|
- return Math.max(x, y);
|
|
+ return Math.max(Math.abs(x), Math.abs(y)); // DivineMC - Math Optimizations
|
|
}
|
|
|
|
public static int floorDiv(int dividend, int divisor) {
|
|
@@ -162,14 +149,26 @@ public class Mth {
|
|
return Math.floorMod(x, y);
|
|
}
|
|
|
|
- public static float positiveModulo(float numerator, float denominator) {
|
|
+ public static float positiveModuloForAnyDenominator(float numerator, float denominator) { // DivineMC - Math Optimizations
|
|
return (numerator % denominator + denominator) % denominator;
|
|
}
|
|
|
|
- public static double positiveModulo(double numerator, double denominator) {
|
|
+ public static double positiveModuloForAnyDenominator(double numerator, double denominator) { // DivineMC - Math Optimizations
|
|
return (numerator % denominator + denominator) % denominator;
|
|
}
|
|
|
|
+ // DivineMC start - Math Optimizations
|
|
+ public static float positiveModuloForPositiveIntegerDenominator(float numerator, float denominator) {
|
|
+ var modulo = numerator % denominator;
|
|
+ return modulo < 0 ? modulo + denominator : modulo;
|
|
+ }
|
|
+
|
|
+ public static double positiveModuloForPositiveIntegerDenominator(double numerator, double denominator) {
|
|
+ var modulo = numerator % denominator;
|
|
+ return modulo < 0 ? modulo + denominator : modulo;
|
|
+ }
|
|
+ // DivineMC end - Math Optimizations
|
|
+
|
|
public static boolean isMultipleOf(int number, int multiple) {
|
|
return number % multiple == 0;
|
|
}
|
|
diff --git a/net/minecraft/world/level/biome/BiomeManager.java b/net/minecraft/world/level/biome/BiomeManager.java
|
|
index 73962e79a0f3d892e3155443a1b84508b0f4042e..10b930f7e0314bf6658ea9ae79ae88b37aee3e05 100644
|
|
--- a/net/minecraft/world/level/biome/BiomeManager.java
|
|
+++ b/net/minecraft/world/level/biome/BiomeManager.java
|
|
@@ -29,39 +29,64 @@ public class BiomeManager {
|
|
}
|
|
|
|
public Holder<Biome> getBiome(BlockPos pos) {
|
|
- int i = pos.getX() - 2;
|
|
- int i1 = pos.getY() - 2;
|
|
- int i2 = pos.getZ() - 2;
|
|
- int i3 = i >> 2;
|
|
- int i4 = i1 >> 2;
|
|
- int i5 = i2 >> 2;
|
|
- double d = (i & 3) / 4.0;
|
|
- double d1 = (i1 & 3) / 4.0;
|
|
- double d2 = (i2 & 3) / 4.0;
|
|
- int i6 = 0;
|
|
- double d3 = Double.POSITIVE_INFINITY;
|
|
+ // DivineMC start - Native Math Optimizations
|
|
+ if (org.bxteam.divinemc.DivineConfig.nativeAccelerationEnabled) {
|
|
+ int mask = org.bxteam.divinemc.math.Bindings.c2me_natives_biome_access_sample(this.biomeZoomSeed, pos.getX(), pos.getY(), pos.getZ());
|
|
|
|
- for (int i7 = 0; i7 < 8; i7++) {
|
|
- boolean flag = (i7 & 4) == 0;
|
|
- boolean flag1 = (i7 & 2) == 0;
|
|
- boolean flag2 = (i7 & 1) == 0;
|
|
- int i8 = flag ? i3 : i3 + 1;
|
|
- int i9 = flag1 ? i4 : i4 + 1;
|
|
- int i10 = flag2 ? i5 : i5 + 1;
|
|
- double d4 = flag ? d : d - 1.0;
|
|
- double d5 = flag1 ? d1 : d1 - 1.0;
|
|
- double d6 = flag2 ? d2 : d2 - 1.0;
|
|
- double fiddledDistance = getFiddledDistance(this.biomeZoomSeed, i8, i9, i10, d4, d5, d6);
|
|
- if (d3 > fiddledDistance) {
|
|
- i6 = i7;
|
|
- d3 = fiddledDistance;
|
|
+ return this.noiseBiomeSource.getNoiseBiome(
|
|
+ ((pos.getX() - 2) >> 2) + ((mask & 4) != 0 ? 1 : 0),
|
|
+ ((pos.getY() - 2) >> 2) + ((mask & 2) != 0 ? 1 : 0),
|
|
+ ((pos.getZ() - 2) >> 2) + ((mask & 1) != 0 ? 1 : 0)
|
|
+ );
|
|
+ } else {
|
|
+ final int var0 = pos.getX() - 2;
|
|
+ final int var1 = pos.getY() - 2;
|
|
+ final int var2 = pos.getZ() - 2;
|
|
+ final int var3 = var0 >> 2;
|
|
+ final int var4 = var1 >> 2;
|
|
+ final int var5 = var2 >> 2;
|
|
+ final double var6 = (double) (var0 & 3) / 4.0;
|
|
+ final double var7 = (double) (var1 & 3) / 4.0;
|
|
+ final double var8 = (double) (var2 & 3) / 4.0;
|
|
+ int var9 = 0;
|
|
+ double var10 = Double.POSITIVE_INFINITY;
|
|
+ for (int var11 = 0; var11 < 8; ++var11) {
|
|
+ boolean var12 = (var11 & 4) == 0;
|
|
+ boolean var13 = (var11 & 2) == 0;
|
|
+ boolean var14 = (var11 & 1) == 0;
|
|
+ long var15 = var12 ? var3 : var3 + 1;
|
|
+ long var16 = var13 ? var4 : var4 + 1;
|
|
+ long var17 = var14 ? var5 : var5 + 1;
|
|
+ double var18 = var12 ? var6 : var6 - 1.0;
|
|
+ double var19 = var13 ? var7 : var7 - 1.0;
|
|
+ double var20 = var14 ? var8 : var8 - 1.0;
|
|
+ long var21 = this.biomeZoomSeed * (this.biomeZoomSeed * 6364136223846793005L + 1442695040888963407L) + var15;
|
|
+ var21 = var21 * (var21 * 6364136223846793005L + 1442695040888963407L) + var16;
|
|
+ var21 = var21 * (var21 * 6364136223846793005L + 1442695040888963407L) + var17;
|
|
+ var21 = var21 * (var21 * 6364136223846793005L + 1442695040888963407L) + var15;
|
|
+ var21 = var21 * (var21 * 6364136223846793005L + 1442695040888963407L) + var16;
|
|
+ var21 = var21 * (var21 * 6364136223846793005L + 1442695040888963407L) + var17;
|
|
+ double var22 = (double) ((var21 >> 24) & 1023) / 1024.0;
|
|
+ double var23 = (var22 - 0.5) * 0.9;
|
|
+ var21 = var21 * (var21 * 6364136223846793005L + 1442695040888963407L) + this.biomeZoomSeed;
|
|
+ double var24 = (double) ((var21 >> 24) & 1023) / 1024.0;
|
|
+ double var25 = (var24 - 0.5) * 0.9;
|
|
+ var21 = var21 * (var21 * 6364136223846793005L + 1442695040888963407L) + this.biomeZoomSeed;
|
|
+ double var26 = (double) ((var21 >> 24) & 1023) / 1024.0;
|
|
+ double var27 = (var26 - 0.5) * 0.9;
|
|
+ double var28 = Mth.square(var20 + var27) + Mth.square(var19 + var25) + Mth.square(var18 + var23);
|
|
+ if (var10 > var28) {
|
|
+ var9 = var11;
|
|
+ var10 = var28;
|
|
+ }
|
|
}
|
|
- }
|
|
|
|
- int i7x = (i6 & 4) == 0 ? i3 : i3 + 1;
|
|
- int i11 = (i6 & 2) == 0 ? i4 : i4 + 1;
|
|
- int i12 = (i6 & 1) == 0 ? i5 : i5 + 1;
|
|
- return this.noiseBiomeSource.getNoiseBiome(i7x, i11, i12);
|
|
+ int resX = (var9 & 4) == 0 ? var3 : var3 + 1;
|
|
+ int resY = (var9 & 2) == 0 ? var4 : var4 + 1;
|
|
+ int resZ = (var9 & 1) == 0 ? var5 : var5 + 1;
|
|
+ return this.noiseBiomeSource.getNoiseBiome(resX, resY, resZ);
|
|
+ }
|
|
+ // DivineMC end - Native Math Optimizations
|
|
}
|
|
|
|
public Holder<Biome> getNoiseBiomeAtPosition(double x, double y, double z) {
|
|
diff --git a/net/minecraft/world/level/levelgen/DensityFunctions.java b/net/minecraft/world/level/levelgen/DensityFunctions.java
|
|
index fa08f06be03b2e6120ddc105563f68d551da741c..6ff9175641234b0fe55dc4613c6d7c56e00211fd 100644
|
|
--- a/net/minecraft/world/level/levelgen/DensityFunctions.java
|
|
+++ b/net/minecraft/world/level/levelgen/DensityFunctions.java
|
|
@@ -501,6 +501,11 @@ public final class DensityFunctions {
|
|
}
|
|
|
|
protected static final class EndIslandDensityFunction implements DensityFunction.SimpleFunction {
|
|
+ // DivineMC start - Native Math Optimizations
|
|
+ private final java.lang.foreign.Arena c2me$arena = java.lang.foreign.Arena.ofAuto();
|
|
+ private java.lang.foreign.MemorySegment c2me$samplerData = null;
|
|
+ private long c2me$samplerDataPtr;
|
|
+ // DivineMC end - Native Math Optimizations
|
|
public static final KeyDispatchDataCodec<DensityFunctions.EndIslandDensityFunction> CODEC = KeyDispatchDataCodec.of(
|
|
MapCodec.unit(new DensityFunctions.EndIslandDensityFunction(0L))
|
|
);
|
|
@@ -521,6 +526,16 @@ public final class DensityFunctions {
|
|
RandomSource randomSource = new LegacyRandomSource(seed);
|
|
randomSource.consumeCount(17292);
|
|
this.islandNoise = new SimplexNoise(randomSource);
|
|
+ // DivineMC start - Native Math Optimizations
|
|
+ if (org.bxteam.divinemc.DivineConfig.nativeAccelerationEnabled) {
|
|
+ int[] permutation = (this.islandNoise).p;
|
|
+ java.lang.foreign.MemorySegment segment = this.c2me$arena.allocate(permutation.length * 4L, 64);
|
|
+ java.lang.foreign.MemorySegment.copy(java.lang.foreign.MemorySegment.ofArray(permutation), 0L, segment, 0L, permutation.length * 4L);
|
|
+ java.lang.invoke.VarHandle.fullFence();
|
|
+ this.c2me$samplerData = segment;
|
|
+ this.c2me$samplerDataPtr = segment.address();
|
|
+ }
|
|
+ // DivineMC end - Native Math Optimizations
|
|
}
|
|
|
|
private static float getHeightValue(SimplexNoise noise, int x, int z) {
|
|
@@ -567,7 +582,13 @@ public final class DensityFunctions {
|
|
|
|
@Override
|
|
public double compute(DensityFunction.FunctionContext context) {
|
|
- return (getHeightValue(this.islandNoise, context.blockX() / 8, context.blockZ() / 8) - 8.0) / 128.0;
|
|
+ // DivineMC start - Native Math Optimizations
|
|
+ if (org.bxteam.divinemc.DivineConfig.nativeAccelerationEnabled && this.c2me$samplerDataPtr != 0L) {
|
|
+ return ((double) org.bxteam.divinemc.math.Bindings.c2me_natives_end_islands_sample(this.c2me$samplerDataPtr, context.blockX() / 8, context.blockZ() / 8) - 8.0) / 128.0;
|
|
+ } else {
|
|
+ return (getHeightValue(this.islandNoise, context.blockX() / 8, context.blockZ() / 8) - 8.0) / 128.0;
|
|
+ }
|
|
+ // DivineMC end - Native Math Optimizations
|
|
}
|
|
|
|
@Override
|
|
@@ -814,10 +835,42 @@ public final class DensityFunctions {
|
|
return this.noise.getValue(context.blockX() * this.xzScale, context.blockY() * this.yScale, context.blockZ() * this.xzScale);
|
|
}
|
|
|
|
+ // DivineMC start - Native Math Optimizations
|
|
@Override
|
|
- public void fillArray(double[] array, DensityFunction.ContextProvider contextProvider) {
|
|
- contextProvider.fillAllDirectly(array, this);
|
|
+ public void fillArray(double[] densities, DensityFunction.ContextProvider applier) {
|
|
+ if (!org.bxteam.divinemc.DivineConfig.nativeAccelerationEnabled) {
|
|
+ applier.fillAllDirectly(densities, this);
|
|
+ return;
|
|
+ }
|
|
+ NormalNoise noise = this.noise.noise();
|
|
+ if (noise == null) {
|
|
+ Arrays.fill(densities, 0.0);
|
|
+ return;
|
|
+ }
|
|
+ long ptr = noise.c2me$getPointer();
|
|
+ if (ptr == 0L) {
|
|
+ applier.fillAllDirectly(densities, this);
|
|
+ return;
|
|
+ }
|
|
+ double[] x = new double[densities.length];
|
|
+ double[] y = new double[densities.length];
|
|
+ double[] z = new double[densities.length];
|
|
+ for (int i = 0; i < densities.length; i++) {
|
|
+ FunctionContext pos = applier.forIndex(i);
|
|
+ x[i] = pos.blockX() * this.xzScale();
|
|
+ y[i] = pos.blockY() * this.yScale();
|
|
+ z[i] = pos.blockZ() * this.xzScale();
|
|
+ }
|
|
+ org.bxteam.divinemc.math.Bindings.c2me_natives_noise_perlin_double_batch(
|
|
+ ptr,
|
|
+ java.lang.foreign.MemorySegment.ofArray(densities),
|
|
+ java.lang.foreign.MemorySegment.ofArray(x),
|
|
+ java.lang.foreign.MemorySegment.ofArray(y),
|
|
+ java.lang.foreign.MemorySegment.ofArray(z),
|
|
+ densities.length
|
|
+ );
|
|
}
|
|
+ // DivineMC end - Native Math Optimizations
|
|
|
|
@Override
|
|
public DensityFunction mapAll(DensityFunction.Visitor visitor) {
|
|
@@ -938,6 +991,46 @@ public final class DensityFunctions {
|
|
public KeyDispatchDataCodec<? extends DensityFunction> codec() {
|
|
return CODEC;
|
|
}
|
|
+
|
|
+ // DivineMC start - Native Math Optimizations
|
|
+ @Override
|
|
+ public void fillArray(final double[] densities, final ContextProvider applier) {
|
|
+ if (!org.bxteam.divinemc.DivineConfig.nativeAccelerationEnabled) {
|
|
+ applier.fillAllDirectly(densities, this);
|
|
+ return;
|
|
+ }
|
|
+ NormalNoise noise = this.offsetNoise.noise();
|
|
+ if (noise == null) {
|
|
+ Arrays.fill(densities, 0.0);
|
|
+ return;
|
|
+ }
|
|
+ long ptr = noise.c2me$getPointer();
|
|
+ if (ptr == 0L) {
|
|
+ applier.fillAllDirectly(densities, this);
|
|
+ return;
|
|
+ }
|
|
+ double[] x = new double[densities.length];
|
|
+ double[] y = new double[densities.length];
|
|
+ double[] z = new double[densities.length];
|
|
+ for (int i = 0; i < densities.length; i++) {
|
|
+ FunctionContext pos = applier.forIndex(i);
|
|
+ x[i] = pos.blockX() * 0.25;
|
|
+ y[i] = pos.blockY() * 0.25;
|
|
+ z[i] = pos.blockZ() * 0.25;
|
|
+ }
|
|
+ org.bxteam.divinemc.math.Bindings.c2me_natives_noise_perlin_double_batch(
|
|
+ ptr,
|
|
+ java.lang.foreign.MemorySegment.ofArray(densities),
|
|
+ java.lang.foreign.MemorySegment.ofArray(x),
|
|
+ java.lang.foreign.MemorySegment.ofArray(y),
|
|
+ java.lang.foreign.MemorySegment.ofArray(z),
|
|
+ densities.length
|
|
+ );
|
|
+ for (int i = 0; i < densities.length; i++) {
|
|
+ densities[i] *= 4.0;
|
|
+ }
|
|
+ }
|
|
+ // DivineMC end - Native Math Optimizations
|
|
}
|
|
|
|
public record ShiftA(@Override DensityFunction.NoiseHolder offsetNoise) implements DensityFunctions.ShiftNoise {
|
|
@@ -959,6 +1052,46 @@ public final class DensityFunctions {
|
|
public KeyDispatchDataCodec<? extends DensityFunction> codec() {
|
|
return CODEC;
|
|
}
|
|
+
|
|
+ // DivineMC start - Native Math Optimizations
|
|
+ @Override
|
|
+ public void fillArray(final double[] densities, final ContextProvider applier) {
|
|
+ if (!org.bxteam.divinemc.DivineConfig.nativeAccelerationEnabled) {
|
|
+ applier.fillAllDirectly(densities, this);
|
|
+ return;
|
|
+ }
|
|
+ NormalNoise noise = this.offsetNoise.noise();
|
|
+ if (noise == null) {
|
|
+ Arrays.fill(densities, 0.0);
|
|
+ return;
|
|
+ }
|
|
+ long ptr = noise.c2me$getPointer();
|
|
+ if (ptr == 0L) {
|
|
+ applier.fillAllDirectly(densities, this);
|
|
+ return;
|
|
+ }
|
|
+ double[] x = new double[densities.length];
|
|
+ double[] y = new double[densities.length];
|
|
+ double[] z = new double[densities.length];
|
|
+ for (int i = 0; i < densities.length; i++) {
|
|
+ FunctionContext pos = applier.forIndex(i);
|
|
+ x[i] = pos.blockX() * 0.25;
|
|
+ y[i] = 0;
|
|
+ z[i] = pos.blockZ() * 0.25;
|
|
+ }
|
|
+ org.bxteam.divinemc.math.Bindings.c2me_natives_noise_perlin_double_batch(
|
|
+ ptr,
|
|
+ java.lang.foreign.MemorySegment.ofArray(densities),
|
|
+ java.lang.foreign.MemorySegment.ofArray(x),
|
|
+ java.lang.foreign.MemorySegment.ofArray(y),
|
|
+ java.lang.foreign.MemorySegment.ofArray(z),
|
|
+ densities.length
|
|
+ );
|
|
+ for (int i = 0; i < densities.length; i++) {
|
|
+ densities[i] *= 4.0;
|
|
+ }
|
|
+ }
|
|
+ // DivineMC end - Native Math Optimizations
|
|
}
|
|
|
|
public record ShiftB(@Override DensityFunction.NoiseHolder offsetNoise) implements DensityFunctions.ShiftNoise {
|
|
@@ -980,6 +1113,46 @@ public final class DensityFunctions {
|
|
public KeyDispatchDataCodec<? extends DensityFunction> codec() {
|
|
return CODEC;
|
|
}
|
|
+
|
|
+ // DivineMC start - Native Math Optimizations
|
|
+ @Override
|
|
+ public void fillArray(final double[] densities, final ContextProvider applier) {
|
|
+ if (!org.bxteam.divinemc.DivineConfig.nativeAccelerationEnabled) {
|
|
+ applier.fillAllDirectly(densities, this);
|
|
+ return;
|
|
+ }
|
|
+ NormalNoise noise = this.offsetNoise.noise();
|
|
+ if (noise == null) {
|
|
+ Arrays.fill(densities, 0.0);
|
|
+ return;
|
|
+ }
|
|
+ long ptr = noise.c2me$getPointer();
|
|
+ if (ptr == 0L) {
|
|
+ applier.fillAllDirectly(densities, this);
|
|
+ return;
|
|
+ }
|
|
+ double[] x = new double[densities.length];
|
|
+ double[] y = new double[densities.length];
|
|
+ double[] z = new double[densities.length];
|
|
+ for (int i = 0; i < densities.length; i++) {
|
|
+ FunctionContext pos = applier.forIndex(i);
|
|
+ x[i] = pos.blockZ() * 0.25;
|
|
+ y[i] = pos.blockX() * 0.25;
|
|
+ z[i] = 0.0;
|
|
+ }
|
|
+ org.bxteam.divinemc.math.Bindings.c2me_natives_noise_perlin_double_batch(
|
|
+ ptr,
|
|
+ java.lang.foreign.MemorySegment.ofArray(densities),
|
|
+ java.lang.foreign.MemorySegment.ofArray(x),
|
|
+ java.lang.foreign.MemorySegment.ofArray(y),
|
|
+ java.lang.foreign.MemorySegment.ofArray(z),
|
|
+ densities.length
|
|
+ );
|
|
+ for (int i = 0; i < densities.length; i++) {
|
|
+ densities[i] *= 4.0;
|
|
+ }
|
|
+ }
|
|
+ // DivineMC end - Native Math Optimizations
|
|
}
|
|
|
|
interface ShiftNoise extends DensityFunction {
|
|
diff --git a/net/minecraft/world/level/levelgen/blending/Blender.java b/net/minecraft/world/level/levelgen/blending/Blender.java
|
|
index 01e5b29d6e9a5c53c0e23b61ed0c1d7be1a0fe08..d80df05e40f3941ade5ed320e12f8dcf47e6b247 100644
|
|
--- a/net/minecraft/world/level/levelgen/blending/Blender.java
|
|
+++ b/net/minecraft/world/level/levelgen/blending/Blender.java
|
|
@@ -144,7 +144,7 @@ public class Blender {
|
|
private static double heightToOffset(double height) {
|
|
double d = 1.0;
|
|
double d1 = height + 0.5;
|
|
- double d2 = Mth.positiveModulo(d1, 8.0);
|
|
+ double d2 = Mth.positiveModuloForPositiveIntegerDenominator(d1, 8.0); // DivineMC - Math optimizations
|
|
return 1.0 * (32.0 * (d1 - 128.0) - 3.0 * (d1 - 120.0) * d2 + 3.0 * d2 * d2) / (128.0 * (32.0 - 3.0 * d2));
|
|
}
|
|
|
|
diff --git a/net/minecraft/world/level/levelgen/synth/BlendedNoise.java b/net/minecraft/world/level/levelgen/synth/BlendedNoise.java
|
|
index af5f714c285aad5ef844b17a266e06b5092d33aa..6c022157a898e96daabc5c82c7f8b34bee64aca4 100644
|
|
--- a/net/minecraft/world/level/levelgen/synth/BlendedNoise.java
|
|
+++ b/net/minecraft/world/level/levelgen/synth/BlendedNoise.java
|
|
@@ -36,6 +36,11 @@ public class BlendedNoise implements DensityFunction.SimpleFunction {
|
|
private final double maxValue;
|
|
public final double xzScale;
|
|
public final double yScale;
|
|
+ // DivineMC start - Native Math Optimizations
|
|
+ private final java.lang.foreign.Arena c2me$arena = java.lang.foreign.Arena.ofAuto();
|
|
+ private java.lang.foreign.MemorySegment c2me$samplerData = null;
|
|
+ private long c2me$samplerDataPtr;
|
|
+ // DivineMC end - Native Math Optimizations
|
|
|
|
public static BlendedNoise createUnseeded(double xzScale, double yScale, double xzFactor, double yFactor, double smearScaleMultiplier) {
|
|
return new BlendedNoise(new XoroshiroRandomSource(0L), xzScale, yScale, xzFactor, yFactor, smearScaleMultiplier);
|
|
@@ -62,6 +67,12 @@ public class BlendedNoise implements DensityFunction.SimpleFunction {
|
|
this.xzMultiplier = 684.412 * this.xzScale;
|
|
this.yMultiplier = 684.412 * this.yScale;
|
|
this.maxValue = minLimitNoise.maxBrokenValue(this.yMultiplier);
|
|
+ // DivineMC start - Native Math Optimizations
|
|
+ if (org.bxteam.divinemc.DivineConfig.nativeAccelerationEnabled) {
|
|
+ this.c2me$samplerData = org.bxteam.divinemc.math.BindingsTemplate.interpolated_noise_sampler$create(this.c2me$arena, this);
|
|
+ this.c2me$samplerDataPtr = this.c2me$samplerData.address();
|
|
+ }
|
|
+ // DivineMC end - Native Math Optimizations
|
|
}
|
|
|
|
@VisibleForTesting
|
|
diff --git a/net/minecraft/world/level/levelgen/synth/NormalNoise.java b/net/minecraft/world/level/levelgen/synth/NormalNoise.java
|
|
index 45060882654217eeb9a07357c5149b12fbff02c1..c17f43164009f47050a390eb50688460e1d4cf3b 100644
|
|
--- a/net/minecraft/world/level/levelgen/synth/NormalNoise.java
|
|
+++ b/net/minecraft/world/level/levelgen/synth/NormalNoise.java
|
|
@@ -21,6 +21,15 @@ public class NormalNoise {
|
|
private final PerlinNoise second;
|
|
private final double maxValue;
|
|
private final NormalNoise.NoiseParameters parameters;
|
|
+ // DivineMC start - Native Math Optimizations
|
|
+ private final java.lang.foreign.Arena c2me$arena = java.lang.foreign.Arena.ofAuto();
|
|
+ private java.lang.foreign.MemorySegment c2me$samplerData = null;
|
|
+ private long c2me$samplerDataPtr;
|
|
+
|
|
+ public long c2me$getPointer() {
|
|
+ return this.c2me$samplerDataPtr;
|
|
+ }
|
|
+ // DivineMC end - Native Math Optimizations
|
|
|
|
@Deprecated
|
|
public static NormalNoise createLegacyNetherBiome(RandomSource random, NormalNoise.NoiseParameters parameters) {
|
|
@@ -62,6 +71,12 @@ public class NormalNoise {
|
|
|
|
this.valueFactor = 0.16666666666666666 / expectedDeviation(i2 - i1);
|
|
this.maxValue = (this.first.maxValue() + this.second.maxValue()) * this.valueFactor;
|
|
+ // DivineMC start - Native Math Optimizations
|
|
+ if (org.bxteam.divinemc.DivineConfig.nativeAccelerationEnabled) {
|
|
+ this.c2me$samplerData = org.bxteam.divinemc.math.BindingsTemplate.double_octave_sampler_data$create(this.c2me$arena, this.first, this.second, this.valueFactor);
|
|
+ this.c2me$samplerDataPtr = this.c2me$samplerData.address();
|
|
+ }
|
|
+ // DivineMC end - Native Math Optimizations
|
|
}
|
|
|
|
public double maxValue() {
|
|
diff --git a/net/minecraft/world/phys/AABB.java b/net/minecraft/world/phys/AABB.java
|
|
index c9c6e4e460ad8435f12761704bb9b0284d6aa708..54807bb4b4189ceaded1f78a1a9ab85ce40ab2b1 100644
|
|
--- a/net/minecraft/world/phys/AABB.java
|
|
+++ b/net/minecraft/world/phys/AABB.java
|
|
@@ -189,13 +189,15 @@ public class AABB {
|
|
}
|
|
|
|
public AABB intersect(AABB other) {
|
|
- double max = Math.max(this.minX, other.minX);
|
|
- double max1 = Math.max(this.minY, other.minY);
|
|
- double max2 = Math.max(this.minZ, other.minZ);
|
|
- double min = Math.min(this.maxX, other.maxX);
|
|
- double min1 = Math.min(this.maxY, other.maxY);
|
|
- double min2 = Math.min(this.maxZ, other.maxZ);
|
|
- return new AABB(max, max1, max2, min, min1, min2);
|
|
+ // DivineMC start - Math Optimizations
|
|
+ return new AABB(
|
|
+ this.minX > other.minX ? this.minX : other.minX,
|
|
+ this.minY > other.minY ? this.minY : other.minY,
|
|
+ this.minZ > other.minZ ? this.minZ : other.minZ,
|
|
+ this.maxX < other.maxX ? this.maxX : other.maxX,
|
|
+ this.maxY < other.maxY ? this.maxY : other.maxY,
|
|
+ this.maxZ < other.maxZ ? this.maxZ : other.maxZ
|
|
+ );
|
|
}
|
|
|
|
public AABB minmax(AABB other) {
|
|
@@ -227,16 +229,37 @@ public class AABB {
|
|
}
|
|
|
|
public boolean intersects(AABB other) {
|
|
- return this.intersects(other.minX, other.minY, other.minZ, other.maxX, other.maxY, other.maxZ);
|
|
+ // DivineMC start - Math Optimizations
|
|
+ return this.minX < other.maxX &&
|
|
+ this.maxX > other.minX &&
|
|
+ this.minY < other.maxY &&
|
|
+ this.maxY > other.minY &&
|
|
+ this.minZ < other.maxZ &&
|
|
+ this.maxZ > other.minZ;
|
|
+ // DivineMC end - Math Optimizations
|
|
}
|
|
|
|
public boolean intersects(double x1, double y1, double z1, double x2, double y2, double z2) {
|
|
- return this.minX < x2 && this.maxX > x1 && this.minY < y2 && this.maxY > y1 && this.minZ < z2 && this.maxZ > z1;
|
|
+ // DivineMC start - Math Optimizations
|
|
+ return this.minX < x2 &&
|
|
+ this.maxX > x1 &&
|
|
+ this.minY < y2 &&
|
|
+ this.maxY > y1 &&
|
|
+ this.minZ < z2 &&
|
|
+ this.maxZ > z1;
|
|
+ // DivineMC end - Math Optimizations
|
|
}
|
|
|
|
public boolean intersects(Vec3 min, Vec3 max) {
|
|
return this.intersects(
|
|
- Math.min(min.x, max.x), Math.min(min.y, max.y), Math.min(min.z, max.z), Math.max(min.x, max.x), Math.max(min.y, max.y), Math.max(min.z, max.z)
|
|
+ // DivineMC start - Math Optimizations
|
|
+ min.x < max.x ? min.x : max.x,
|
|
+ min.y < max.y ? min.y : max.y,
|
|
+ min.z < max.z ? min.z : max.z,
|
|
+ min.x > max.x ? min.x : max.x,
|
|
+ min.y > max.y ? min.y : max.y,
|
|
+ min.z > max.z ? min.z : max.z
|
|
+ // DivineMC end - Math Optimizations
|
|
);
|
|
}
|
|
|