Fix conflict with vectorization

This commit is contained in:
Etil
2022-01-16 19:03:00 +01:00
parent a564c20639
commit ca9e1a45c9

View File

@@ -8,7 +8,7 @@ You can find the original code on https://github.com/RelativityMC/C2ME-fabric (Y
diff --git a/src/main/java/com/ishland/c2me/libs/vectorized_algorithms/VectorizedAlgorithms.java b/src/main/java/com/ishland/c2me/libs/vectorized_algorithms/VectorizedAlgorithms.java
new file mode 100644
index 0000000000000000000000000000000000000000..77aed653efa723b17e1943e40202954d730f4b47
index 0000000000000000000000000000000000000000..43d1959002295b5f6431e024813b49e30ee7099f
--- /dev/null
+++ b/src/main/java/com/ishland/c2me/libs/vectorized_algorithms/VectorizedAlgorithms.java
@@ -0,0 +1,9 @@
@@ -21,9 +21,10 @@ index 0000000000000000000000000000000000000000..77aed653efa723b17e1943e40202954d
+ }
+
+}
\ No newline at end of file
diff --git a/src/main/java/com/ishland/c2me/libs/vectorized_algorithms/VectorizedPerlinNoise.java b/src/main/java/com/ishland/c2me/libs/vectorized_algorithms/VectorizedPerlinNoise.java
new file mode 100644
index 0000000000000000000000000000000000000000..6679e557f4a3c7dbe88c77c605c97ff673425d7e
index 0000000000000000000000000000000000000000..44085c98292654ebb1f6d522b908bd727c761ede
--- /dev/null
+++ b/src/main/java/com/ishland/c2me/libs/vectorized_algorithms/VectorizedPerlinNoise.java
@@ -0,0 +1,115 @@
@@ -142,8 +143,9 @@ index 0000000000000000000000000000000000000000..6679e557f4a3c7dbe88c77c605c97ff6
+ }
+
+}
\ No newline at end of file
diff --git a/src/main/java/net/minecraft/world/level/levelgen/synth/ImprovedNoise.java b/src/main/java/net/minecraft/world/level/levelgen/synth/ImprovedNoise.java
index de5ab4040204e63efd4c536106cc83f7b15c90a7..026848b6e3ccf68e5d536f79f1a025f7f8352fe2 100644
index cbb044019629796c5b4f0ff708a5a4084932c5f9..53620a833ce92e97866d17f9b7273421d98e2cfd 100644
--- a/src/main/java/net/minecraft/world/level/levelgen/synth/ImprovedNoise.java
+++ b/src/main/java/net/minecraft/world/level/levelgen/synth/ImprovedNoise.java
@@ -1,5 +1,6 @@
@@ -153,61 +155,95 @@ index de5ab4040204e63efd4c536106cc83f7b15c90a7..026848b6e3ccf68e5d536f79f1a025f7
import com.google.common.annotations.VisibleForTesting;
import net.minecraft.util.Mth;
import net.minecraft.world.level.levelgen.RandomSource;
@@ -88,26 +89,36 @@ public final class ImprovedNoise {
return this.p[hash & 255] & 255;
}
+ // Mirai start
+ /**
+ * @author ishland
+ * @reason vectorized perlin
+ */
@@ -115,45 +116,49 @@ public final class ImprovedNoise {
* @reason inline math & small optimization: remove frequent type conversions and redundant ops
*/
private double sampleAndLerp(int sectionX, int sectionY, int sectionZ, double localX, double localY, double localZ, double fadeLocalX) {
- int i = this.p(sectionX);
- int j = this.p(sectionX + 1);
- int k = this.p(i + sectionY);
- int l = this.p(i + sectionY + 1);
- int m = this.p(j + sectionY);
- int n = this.p(j + sectionY + 1);
- double d = gradDot(this.p(k + sectionZ), localX, localY, localZ);
- double e = gradDot(this.p(m + sectionZ), localX - 1.0D, localY, localZ);
- double f = gradDot(this.p(l + sectionZ), localX, localY - 1.0D, localZ);
- double g = gradDot(this.p(n + sectionZ), localX - 1.0D, localY - 1.0D, localZ);
- double h = gradDot(this.p(k + sectionZ + 1), localX, localY, localZ - 1.0D);
- double o = gradDot(this.p(m + sectionZ + 1), localX - 1.0D, localY, localZ - 1.0D);
- double p = gradDot(this.p(l + sectionZ + 1), localX, localY - 1.0D, localZ - 1.0D);
- double q = gradDot(this.p(n + sectionZ + 1), localX - 1.0D, localY - 1.0D, localZ - 1.0D);
- double r = Mth.smoothstep(localX);
- double s = Mth.smoothstep(fadeLocalX);
- double t = Mth.smoothstep(localZ);
- return Mth.lerp3(r, s, t, d, e, f, g, h, o, p, q);
- int i = this.p[sectionX & 0xFF];
- int j = this.p[sectionX + 1 & 0xFF];
- int k = this.p[i + sectionY & 0xFF];
- int l = this.p[i + sectionY + 1 & 0xFF];
- int m = this.p[j + sectionY & 0xFF];
- int n = this.p[j + sectionY + 1 & 0xFF];
-
- double d = (SIMPLEX_NOISE_GRADIENTS[this.p[k + sectionZ & 0xFF] & 15][0] * localX)
- + (SIMPLEX_NOISE_GRADIENTS[this.p[k + sectionZ & 0xFF] & 15][1] * localY)
- + (SIMPLEX_NOISE_GRADIENTS[this.p[k + sectionZ & 0xFF] & 15][2] * localZ);
- double e = (SIMPLEX_NOISE_GRADIENTS[this.p[m + sectionZ & 0xFF] & 15][0] * (localX - 1.0))
- + (SIMPLEX_NOISE_GRADIENTS[this.p[m + sectionZ & 0xFF] & 15][1] * localY)
- + (SIMPLEX_NOISE_GRADIENTS[this.p[m + sectionZ & 0xFF] & 15][2] * localZ);
- double f = (SIMPLEX_NOISE_GRADIENTS[this.p[l + sectionZ & 0xFF] & 15][0] * localX)
- + (SIMPLEX_NOISE_GRADIENTS[this.p[l + sectionZ & 0xFF] & 15][1] * (localY - 1.0))
- + (SIMPLEX_NOISE_GRADIENTS[this.p[l + sectionZ & 0xFF] & 15][2] * localZ);
- double g = (SIMPLEX_NOISE_GRADIENTS[this.p[n + sectionZ & 0xFF] & 15][0] * (localX - 1.0))
- + (SIMPLEX_NOISE_GRADIENTS[this.p[n + sectionZ & 0xFF] & 15][1] * (localY - 1.0))
- + (SIMPLEX_NOISE_GRADIENTS[this.p[n + sectionZ & 0xFF] & 15][2] * localZ);
- double h = (SIMPLEX_NOISE_GRADIENTS[this.p[k + sectionZ + 1 & 0xFF] & 15][0] * localX)
- + (SIMPLEX_NOISE_GRADIENTS[this.p[k + sectionZ + 1 & 0xFF] & 15][1] * localY)
- + (SIMPLEX_NOISE_GRADIENTS[this.p[k + sectionZ + 1 & 0xFF] & 15][2] * (localZ - 1.0));
- double o = (SIMPLEX_NOISE_GRADIENTS[this.p[m + sectionZ + 1 & 0xFF] & 15][0] * (localX - 1.0))
- + (SIMPLEX_NOISE_GRADIENTS[this.p[m + sectionZ + 1 & 0xFF] & 15][1] * localY)
- + (SIMPLEX_NOISE_GRADIENTS[this.p[m + sectionZ + 1 & 0xFF] & 15][2] * (localZ - 1.0));
- double p = (SIMPLEX_NOISE_GRADIENTS[this.p[l + sectionZ + 1 & 0xFF] & 15][0] * localX)
- + (SIMPLEX_NOISE_GRADIENTS[this.p[l + sectionZ + 1 & 0xFF] & 15][1] * (localY - 1.0))
- + (SIMPLEX_NOISE_GRADIENTS[this.p[l + sectionZ + 1 & 0xFF] & 15][2] * (localZ - 1.0));
- double q = (SIMPLEX_NOISE_GRADIENTS[this.p[n + sectionZ + 1 & 0xFF] & 15][0] * (localX - 1.0))
- + (SIMPLEX_NOISE_GRADIENTS[this.p[n + sectionZ + 1 & 0xFF] & 15][1] * (localY - 1.0))
- + (SIMPLEX_NOISE_GRADIENTS[this.p[n + sectionZ + 1 & 0xFF] & 15][2] * (localZ - 1.0));
-
- double r = localX * localX * localX * (localX * (localX * 6.0 - 15.0) + 10.0);
- double s = fadeLocalX * fadeLocalX * fadeLocalX * (fadeLocalX * (fadeLocalX * 6.0 - 15.0) + 10.0);
- double t = localZ * localZ * localZ * (localZ * (localZ * 6.0 - 15.0) + 10.0);
-
- double v0 = d + r * (e - d) + s * (f + r * (g - f) - (d + r * (e - d)));
- double v1 = h + r * (o - h) + s * (p + r * (q - p) - (h + r * (o - h)));
- return v0 + (t * (v1 - v0));
+ if (wtf.etil.mirai.MiraiConfig.vectorizedPerlinNoise) {
+ return VectorizedAlgorithms.perlinNoiseVectorized(p, sectionX, sectionY, sectionZ, localX, localY, localZ, fadeLocalX);
+ } else {
+ int i = this.p(sectionX);
+ int j = this.p(sectionX + 1);
+ int k = this.p(i + sectionY);
+ int l = this.p(i + sectionY + 1);
+ int m = this.p(j + sectionY);
+ int n = this.p(j + sectionY + 1);
+ double d = gradDot(this.p(k + sectionZ), localX, localY, localZ);
+ double e = gradDot(this.p(m + sectionZ), localX - 1.0D, localY, localZ);
+ double f = gradDot(this.p(l + sectionZ), localX, localY - 1.0D, localZ);
+ double g = gradDot(this.p(n + sectionZ), localX - 1.0D, localY - 1.0D, localZ);
+ double h = gradDot(this.p(k + sectionZ + 1), localX, localY, localZ - 1.0D);
+ double o = gradDot(this.p(m + sectionZ + 1), localX - 1.0D, localY, localZ - 1.0D);
+ double p = gradDot(this.p(l + sectionZ + 1), localX, localY - 1.0D, localZ - 1.0D);
+ double q = gradDot(this.p(n + sectionZ + 1), localX - 1.0D, localY - 1.0D, localZ - 1.0D);
+ double r = Mth.smoothstep(localX);
+ double s = Mth.smoothstep(fadeLocalX);
+ double t = Mth.smoothstep(localZ);
+ return Mth.lerp3(r, s, t, d, e, f, g, h, o, p, q);
+ int i = this.p[sectionX & 0xFF];
+ int j = this.p[sectionX + 1 & 0xFF];
+ int k = this.p[i + sectionY & 0xFF];
+ int l = this.p[i + sectionY + 1 & 0xFF];
+ int m = this.p[j + sectionY & 0xFF];
+ int n = this.p[j + sectionY + 1 & 0xFF];
+
+ double d = (SIMPLEX_NOISE_GRADIENTS[this.p[k + sectionZ & 0xFF] & 15][0] * localX)
+ + (SIMPLEX_NOISE_GRADIENTS[this.p[k + sectionZ & 0xFF] & 15][1] * localY)
+ + (SIMPLEX_NOISE_GRADIENTS[this.p[k + sectionZ & 0xFF] & 15][2] * localZ);
+ double e = (SIMPLEX_NOISE_GRADIENTS[this.p[m + sectionZ & 0xFF] & 15][0] * (localX - 1.0))
+ + (SIMPLEX_NOISE_GRADIENTS[this.p[m + sectionZ & 0xFF] & 15][1] * localY)
+ + (SIMPLEX_NOISE_GRADIENTS[this.p[m + sectionZ & 0xFF] & 15][2] * localZ);
+ double f = (SIMPLEX_NOISE_GRADIENTS[this.p[l + sectionZ & 0xFF] & 15][0] * localX)
+ + (SIMPLEX_NOISE_GRADIENTS[this.p[l + sectionZ & 0xFF] & 15][1] * (localY - 1.0))
+ + (SIMPLEX_NOISE_GRADIENTS[this.p[l + sectionZ & 0xFF] & 15][2] * localZ);
+ double g = (SIMPLEX_NOISE_GRADIENTS[this.p[n + sectionZ & 0xFF] & 15][0] * (localX - 1.0))
+ + (SIMPLEX_NOISE_GRADIENTS[this.p[n + sectionZ & 0xFF] & 15][1] * (localY - 1.0))
+ + (SIMPLEX_NOISE_GRADIENTS[this.p[n + sectionZ & 0xFF] & 15][2] * localZ);
+ double h = (SIMPLEX_NOISE_GRADIENTS[this.p[k + sectionZ + 1 & 0xFF] & 15][0] * localX)
+ + (SIMPLEX_NOISE_GRADIENTS[this.p[k + sectionZ + 1 & 0xFF] & 15][1] * localY)
+ + (SIMPLEX_NOISE_GRADIENTS[this.p[k + sectionZ + 1 & 0xFF] & 15][2] * (localZ - 1.0));
+ double o = (SIMPLEX_NOISE_GRADIENTS[this.p[m + sectionZ + 1 & 0xFF] & 15][0] * (localX - 1.0))
+ + (SIMPLEX_NOISE_GRADIENTS[this.p[m + sectionZ + 1 & 0xFF] & 15][1] * localY)
+ + (SIMPLEX_NOISE_GRADIENTS[this.p[m + sectionZ + 1 & 0xFF] & 15][2] * (localZ - 1.0));
+ double p = (SIMPLEX_NOISE_GRADIENTS[this.p[l + sectionZ + 1 & 0xFF] & 15][0] * localX)
+ + (SIMPLEX_NOISE_GRADIENTS[this.p[l + sectionZ + 1 & 0xFF] & 15][1] * (localY - 1.0))
+ + (SIMPLEX_NOISE_GRADIENTS[this.p[l + sectionZ + 1 & 0xFF] & 15][2] * (localZ - 1.0));
+ double q = (SIMPLEX_NOISE_GRADIENTS[this.p[n + sectionZ + 1 & 0xFF] & 15][0] * (localX - 1.0))
+ + (SIMPLEX_NOISE_GRADIENTS[this.p[n + sectionZ + 1 & 0xFF] & 15][1] * (localY - 1.0))
+ + (SIMPLEX_NOISE_GRADIENTS[this.p[n + sectionZ + 1 & 0xFF] & 15][2] * (localZ - 1.0));
+
+ double r = localX * localX * localX * (localX * (localX * 6.0 - 15.0) + 10.0);
+ double s = fadeLocalX * fadeLocalX * fadeLocalX * (fadeLocalX * (fadeLocalX * 6.0 - 15.0) + 10.0);
+ double t = localZ * localZ * localZ * (localZ * (localZ * 6.0 - 15.0) + 10.0);
+
+ double v0 = d + r * (e - d) + s * (f + r * (g - f) - (d + r * (e - d)));
+ double v1 = h + r * (o - h) + s * (p + r * (q - p) - (h + r * (o - h)));
+ return v0 + (t * (v1 - v0));
+ }
}
+ // Mirai end
// Mirai end
private double sampleWithDerivative(int sectionX, int sectionY, int sectionZ, double localX, double localY, double localZ, double[] ds) {
int i = this.p(sectionX);
diff --git a/src/main/java/wtf/etil/mirai/MiraiConfig.java b/src/main/java/wtf/etil/mirai/MiraiConfig.java
index 1ba057cbd0ec23cd7ef3d3d1c7685f44cfe34eec..90cf922c8df669ac80451d64b376918dece09dc9 100644
--- a/src/main/java/wtf/etil/mirai/MiraiConfig.java