mirror of
https://github.com/Dreeam-qwq/Gale.git
synced 2025-12-21 15:59:28 +00:00
55 lines
2.7 KiB
Diff
55 lines
2.7 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Martijn Muijsers <martijnmuijsers@live.nl>
|
|
Date: Tue, 29 Aug 2023 22:29:08 +0200
|
|
Subject: [PATCH] Faster floating-point positive modulo
|
|
|
|
License: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
|
|
Gale - https://galemc.org
|
|
|
|
diff --git a/src/main/java/net/minecraft/util/Mth.java b/src/main/java/net/minecraft/util/Mth.java
|
|
index e102c109d01e0f992808a6096b5f6a323b52d970..6a34354958aec331d6417087c4a7d24b49872f36 100644
|
|
--- a/src/main/java/net/minecraft/util/Mth.java
|
|
+++ b/src/main/java/net/minecraft/util/Mth.java
|
|
@@ -150,14 +150,26 @@ public class Mth {
|
|
return Math.floorMod(dividend, divisor);
|
|
}
|
|
|
|
- public static float positiveModulo(float dividend, float divisor) {
|
|
+ public static float positiveModuloForAnyDivisor(float dividend, float divisor) { // Gale - faster floating-point positive modulo
|
|
return (dividend % divisor + divisor) % divisor;
|
|
}
|
|
|
|
- public static double positiveModulo(double dividend, double divisor) {
|
|
+ public static double positiveModuloForAnyDivisor(double dividend, double divisor) { // Gale - faster floating-point positive modulo
|
|
return (dividend % divisor + divisor) % divisor;
|
|
}
|
|
|
|
+ // Gale start - faster floating-point positive modulo
|
|
+ public static float positiveModuloForPositiveIntegerDivisor(float dividend, float divisor) {
|
|
+ var modulo = dividend % divisor;
|
|
+ return modulo < 0 ? modulo + divisor : modulo;
|
|
+ }
|
|
+
|
|
+ public static double positiveModuloForPositiveIntegerDivisor(double dividend, double divisor) {
|
|
+ var modulo = dividend % divisor;
|
|
+ return modulo < 0 ? modulo + divisor : modulo;
|
|
+ }
|
|
+ // Gale end - faster floating-point positive modulo
|
|
+
|
|
public static boolean isMultipleOf(int a, int b) {
|
|
return a % b == 0;
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/world/level/levelgen/blending/Blender.java b/src/main/java/net/minecraft/world/level/levelgen/blending/Blender.java
|
|
index ef73772bd3f9484efbcd521a86a34c6ec3fd0d14..45f6f74bcae3e3f27809d2ff3973b98edb169f0f 100644
|
|
--- a/src/main/java/net/minecraft/world/level/levelgen/blending/Blender.java
|
|
+++ b/src/main/java/net/minecraft/world/level/levelgen/blending/Blender.java
|
|
@@ -148,7 +148,7 @@ public class Blender {
|
|
private static double heightToOffset(double height) {
|
|
double d = 1.0;
|
|
double e = height + 0.5;
|
|
- double f = Mth.positiveModulo(e, 8.0);
|
|
+ double f = Mth.positiveModuloForPositiveIntegerDivisor(e, 8.0); // Gale - faster floating-point positive modulo
|
|
return 1.0 * (32.0 * (e - 128.0) - 3.0 * (e - 120.0) * f + 3.0 * f * f) / (128.0 * (32.0 - 3.0 * f));
|
|
}
|
|
|