Port c2me optimization.math

This commit is contained in:
Etil
2022-01-10 01:59:05 +01:00
parent e0219aaec7
commit 03f607f5ad
2 changed files with 93 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: ishland <ishlandmc@yeah.net>
Date: Tue, 21 Sep 2021 09:46:15 +0200
Subject: [PATCH] c2me: remove frequent type conversion in PerlinNoise
Original code by RelativityMC, licensed under MIT
You can find the original code on https://github.com/RelativityMC/C2ME-fabric (Yarn mappings)
diff --git a/src/main/java/net/minecraft/world/level/levelgen/synth/PerlinNoise.java b/src/main/java/net/minecraft/world/level/levelgen/synth/PerlinNoise.java
index b6b56a3db74e07ca015deb7a8ebddc97f6228025..728938550e7e4287cfdd019762e90d899ca261ee 100644
--- a/src/main/java/net/minecraft/world/level/levelgen/synth/PerlinNoise.java
+++ b/src/main/java/net/minecraft/world/level/levelgen/synth/PerlinNoise.java
@@ -164,9 +164,15 @@ public class PerlinNoise {
return this.noiseLevels[this.noiseLevels.length - 1 - octave];
}
+ // Mirai start
+ /**
+ * @author ishland
+ * @reason remove frequent type conversion
+ */
public static double wrap(double value) {
- return value - (double)Mth.lfloor(value / 3.3554432E7D + 0.5D) * 3.3554432E7D;
+ return value - Mth.lfloor(value / 3.3554432E7D + 0.5D) * 3.3554432E7D;
}
+ // Mirai end
protected int firstOctave() {
return this.firstOctave;

View File

@@ -0,0 +1,64 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: ishland <ishlandmc@yeah.net>
Date: Tue, 21 Sep 2021 10:37:34 +0200
Subject: [PATCH] c2me: optimize ImprovedNoise
Original code by RelativityMC, licensed under MIT
You can find the original code on https://github.com/RelativityMC/C2ME-fabric (Yarn mappings)
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 765b56776e457109ddea9f7dbfd0b17beefee51e..de5ab4040204e63efd4c536106cc83f7b15c90a7 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
@@ -34,34 +34,38 @@ public final class ImprovedNoise {
return this.noise(x, y, z, 0.0D, 0.0D);
}
+ // Mirai start
+ /**
+ * @author ishland
+ * @reason optimize
+ */
/** @deprecated */
@Deprecated
public double noise(double x, double y, double z, double yScale, double yMax) {
double d = x + this.xo;
double e = y + this.yo;
double f = z + this.zo;
- int i = Mth.floor(d);
- int j = Mth.floor(e);
- int k = Mth.floor(f);
- double g = d - (double)i;
- double h = e - (double)j;
- double l = f - (double)k;
- double o;
- if (yScale != 0.0D) {
+ double i = Mth.floor(d);
+ double j = Mth.floor(e);
+ double k = Mth.floor(f);
+ double g = d - i;
+ double h = e - j;
+ double l = f - k;
+ double o = 0.0D;
+ if (yScale != 0.0) {
double m;
- if (yMax >= 0.0D && yMax < h) {
+ if (yMax >= 0.0 && yMax < h) {
m = yMax;
} else {
m = h;
}
- o = (double)Mth.floor(m / yScale + (double)1.0E-7F) * yScale;
- } else {
- o = 0.0D;
+ o = Mth.floor(m / yScale + 1.0E-7F) * yScale;
}
- return this.sampleAndLerp(i, j, k, g, h - o, l, h);
+ return this.sampleAndLerp((int) i, (int) j, (int) k, g, h - o, l, h);
}
+ // Mirai end
public double noiseWithDerivative(double x, double y, double z, double[] ds) {
double d = x + this.xo;