mirror of
https://github.com/Dreeam-qwq/Gale.git
synced 2025-12-19 14:59:29 +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 d04586223a9b2a30efb17da01fb7f3e8f2a6af7b..bae83b708cafb867f43d5378fa78818fc382e2fa 100644
|
|
--- a/src/main/java/net/minecraft/util/Mth.java
|
|
+++ b/src/main/java/net/minecraft/util/Mth.java
|
|
@@ -143,14 +143,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 a6434f2c2d1ddb33e7c51d0a099fd127d8a785e6..a7972d196c354ff175728f2b8e99590181c65451 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
|
|
@@ -141,7 +141,7 @@ public class Blender {
|
|
private static double heightToOffset(double height) {
|
|
double d = 1.0D;
|
|
double e = height + 0.5D;
|
|
- double f = Mth.positiveModulo(e, 8.0D);
|
|
+ double f = Mth.positiveModuloForPositiveIntegerDivisor(e, 8.0D); // Gale - faster floating-point positive modulo
|
|
return 1.0D * (32.0D * (e - 128.0D) - 3.0D * (e - 120.0D) * f + 3.0D * f * f) / (128.0D * (32.0D - 3.0D * f));
|
|
}
|
|
|