mirror of
https://github.com/Dreeam-qwq/Gale.git
synced 2025-12-28 19:19:09 +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 6b21782ad18cd5dbd1b9a59e5dc12c670c2a42fb..34bfbbabe3dfbf033f4a4e22a049323213fb23f3 100644
|
|
--- a/src/main/java/net/minecraft/util/Mth.java
|
|
+++ b/src/main/java/net/minecraft/util/Mth.java
|
|
@@ -149,14 +149,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 d058e71d6047bbd9256f6c71bb21966cfc056a7d..079edef073e751f38063b42515df893cecd2fcc4 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
|
|
@@ -146,7 +146,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));
|
|
}
|
|
|