Fix more issues with math funcs, and link to the math library.

This commit is contained in:
Relintai 2022-03-13 16:22:11 +01:00
parent c6cec44559
commit e8bbb13f85
3 changed files with 36 additions and 34 deletions

View File

@ -86,7 +86,7 @@ env["CXXFLAGS"] = ""
env.Append(CXXFLAGS=str(CXXFLAGS).split()) env.Append(CXXFLAGS=str(CXXFLAGS).split())
LINKFLAGS = env.get("LINKFLAGS", "") LINKFLAGS = env.get("LINKFLAGS", "")
env["LINKFLAGS"] = "" env["LINKFLAGS"] = "-lm"
env.Append(LINKFLAGS=str(LINKFLAGS).split()) env.Append(LINKFLAGS=str(LINKFLAGS).split())
methods.no_verbose(sys, env) methods.no_verbose(sys, env)

View File

@ -29,6 +29,7 @@
/*************************************************************************/ /*************************************************************************/
#include "math_funcs.h" #include "math_funcs.h"
#include <math.h>
//#include "core/error_macros.h" //#include "core/error_macros.h"
@ -85,25 +86,6 @@ int math_step_decimals(double p_step) {
return 0; return 0;
} }
// Only meant for editor usage in float ranges, where a step of 0
// means that decimal digits should not be limited in String::num.
int math_range_step_decimals(double p_step) {
if (p_step < 0.0000000000001) {
return 16; // Max value hardcoded in String::num
}
return step_decimals(p_step);
}
double math_dectime(double p_value, double p_amount, double p_step) {
//WARN_DEPRECATED_MSG("The `dectime()` function has been deprecated and will be removed in Godot 4.0. Use `move_toward()` instead.");
double sgn = p_value < 0 ? -1.0 : 1.0;
double val = math_absd(p_value);
val -= p_amount * p_step;
if (val < 0.0) {
val = 0.0;
}
return val * sgn;
}
double math_ease(double p_x, double p_c) { double math_ease(double p_x, double p_c) {
if (p_x < 0) { if (p_x < 0) {
@ -130,6 +112,26 @@ double math_ease(double p_x, double p_c) {
} }
} }
// Only meant for editor usage in float ranges, where a step of 0
// means that decimal digits should not be limited in String::num.
int math_range_step_decimals(double p_step) {
if (p_step < 0.0000000000001) {
return 16; // Max value hardcoded in String::num
}
return math_step_decimals(p_step);
}
double math_dectime(double p_value, double p_amount, double p_step) {
//WARN_DEPRECATED_MSG("The `dectime()` function has been deprecated and will be removed in Godot 4.0. Use `move_toward()` instead.");
double sgn = p_value < 0 ? -1.0 : 1.0;
double val = math_absd(p_value);
val -= p_amount * p_step;
if (val < 0.0) {
val = 0.0;
}
return val * sgn;
}
float math_stepifyf(float p_value, float p_step) { float math_stepifyf(float p_value, float p_step) {
if (p_step != 0) { if (p_step != 0) {
p_value = math_floorf(p_value / p_step + 0.5) * p_step; p_value = math_floorf(p_value / p_step + 0.5) * p_step;

View File

@ -365,27 +365,27 @@ static _ALWAYS_INLINE_ float math_roundf(float p_val) {
} }
// double only, as these functions are mainly used by the editor and not performance-critical, // double only, as these functions are mainly used by the editor and not performance-critical,
static double ease(double p_x, double p_c); int math_step_decimals(double p_step);
int step_decimals(double p_step); static int math_range_step_decimals(double p_step);
static int range_step_decimals(double p_step); double math_ease(double p_x, double p_c);
static double stepify(double p_value, double p_step); double math_stepify(double p_value, double p_step);
static double dectime(double p_value, double p_amount, double p_step); double math_dectime(double p_value, double p_amount, double p_step);
static uint32_t larger_prime(uint32_t p_val); uint32_t math_larger_prime(uint32_t p_val);
static void seed(uint64_t x); void math_seed(uint64_t x);
static void randomize(); void math_randomize();
static uint32_t rand_from_seed(uint64_t *seed); uint32_t rand_from_seed(uint64_t *seed);
uint32_t rand(); uint32_t math_rand();
static _ALWAYS_INLINE_ double randd() { static _ALWAYS_INLINE_ double randd() {
return (double)rand() / (double)MATH_RANDOM_32BIT_MAX; return (double)math_rand() / (double)MATH_RANDOM_32BIT_MAX;
} }
static _ALWAYS_INLINE_ float randf() { static _ALWAYS_INLINE_ float randf() {
return (float)rand() / (float)MATH_RANDOM_32BIT_MAX; return (float)math_rand() / (float)MATH_RANDOM_32BIT_MAX;
} }
static double math_randomd(double from, double to); double math_randomd(double from, double to);
static float math_randomf(float from, float to); float math_randomf(float from, float to);
static real_t math_randomr(int from, int to) { static real_t math_randomr(int from, int to) {
return (real_t)math_randomf((real_t)from, (real_t)to); return (real_t)math_randomf((real_t)from, (real_t)to);