From 53358e68258c72b09fbd4a4930d1cc20b5ef3a8c Mon Sep 17 00:00:00 2001 From: Relintai Date: Sun, 11 Jun 2023 08:34:57 +0200 Subject: [PATCH] Removed the PMath singleton. If needed it can easily be recreated as a module. --- core/bind/core_bind.cpp | 96 ----------- core/bind/core_bind.h | 302 ----------------------------------- core/register_core_types.cpp | 5 - 3 files changed, 403 deletions(-) diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index 7d309d3d1..ecc4da1ea 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -1615,102 +1615,6 @@ _OS::_OS() { singleton = this; } -///////////////////// MATH - -PMath *PMath::singleton = nullptr; - -PMath *PMath::get_singleton() { - return singleton; -} - -PMath::PMath() { - singleton = this; -} - -void PMath::_bind_methods() { - ClassDB::bind_method(D_METHOD("sin", "x"), &PMath::sin); - ClassDB::bind_method(D_METHOD("cos", "x"), &PMath::cos); - ClassDB::bind_method(D_METHOD("tan", "x"), &PMath::tan); - ClassDB::bind_method(D_METHOD("sinh", "x"), &PMath::sinh); - ClassDB::bind_method(D_METHOD("sinc", "x"), &PMath::sinc); - ClassDB::bind_method(D_METHOD("sincn", "x"), &PMath::sincn); - ClassDB::bind_method(D_METHOD("cosh", "x"), &PMath::cosh); - ClassDB::bind_method(D_METHOD("tanh", "x"), &PMath::tanh); - ClassDB::bind_method(D_METHOD("asin", "x"), &PMath::asin); - ClassDB::bind_method(D_METHOD("acos", "x"), &PMath::acos); - ClassDB::bind_method(D_METHOD("atan", "x"), &PMath::atan); - ClassDB::bind_method(D_METHOD("atan2", "y", "x"), &PMath::atan2); - - ClassDB::bind_method(D_METHOD("sqrt", "x"), &PMath::sqrt); - ClassDB::bind_method(D_METHOD("fmod", "x", "y"), &PMath::fmod); - ClassDB::bind_method(D_METHOD("floor", "x"), &PMath::floor); - ClassDB::bind_method(D_METHOD("floorf_int", "x"), &PMath::floorf_int); - ClassDB::bind_method(D_METHOD("ceil", "x"), &PMath::ceil); - ClassDB::bind_method(D_METHOD("pow", "x", "y"), &PMath::pow); - ClassDB::bind_method(D_METHOD("log", "x"), &PMath::log); - ClassDB::bind_method(D_METHOD("log1p", "x"), &PMath::log1p); - ClassDB::bind_method(D_METHOD("log10", "x"), &PMath::log10); - ClassDB::bind_method(D_METHOD("log2", "x"), &PMath::log2); - ClassDB::bind_method(D_METHOD("exp", "x"), &PMath::exp); - ClassDB::bind_method(D_METHOD("erf", "x"), &PMath::erf); - - ClassDB::bind_method(D_METHOD("is_nan", "val"), &PMath::is_nan); - ClassDB::bind_method(D_METHOD("is_inf", "val"), &PMath::is_inf); - - ClassDB::bind_method(D_METHOD("abs", "g"), &PMath::abs); - ClassDB::bind_method(D_METHOD("absi", "g"), &PMath::absi); - ClassDB::bind_method(D_METHOD("fposmod", "x", "y"), &PMath::fposmod); - ClassDB::bind_method(D_METHOD("fposmodp", "x", "y"), &PMath::fposmodp); - ClassDB::bind_method(D_METHOD("posmod", "x", "y"), &PMath::posmod); - ClassDB::bind_method(D_METHOD("deg2rad", "y"), &PMath::deg2rad); - ClassDB::bind_method(D_METHOD("rad2deg", "y"), &PMath::rad2deg); - - ClassDB::bind_method(D_METHOD("lerp", "from", "to", "weight"), &PMath::lerp); - ClassDB::bind_method(D_METHOD("lerp_angle", "from", "to", "weight"), &PMath::lerp_angle); - ClassDB::bind_method(D_METHOD("inverse_lerp", "from", "to", "value"), &PMath::inverse_lerp); - ClassDB::bind_method(D_METHOD("range_lerp", "value", "istart", "istop", "ostart", "ostop"), &PMath::range_lerp); - ClassDB::bind_method(D_METHOD("cubic_interpolate", "from", "to", "pre", "post", "weight"), &PMath::cubic_interpolate); - ClassDB::bind_method(D_METHOD("bezier_interpolate", "start", "control_1", "control_2", "end", "t"), &PMath::bezier_interpolate); - ClassDB::bind_method(D_METHOD("smoothstep", "from", "to", "s"), &PMath::smoothstep); - ClassDB::bind_method(D_METHOD("move_toward", "from", "to", "delta"), &PMath::move_toward); - - ClassDB::bind_method(D_METHOD("linear2db", "linear"), &PMath::linear2db); - ClassDB::bind_method(D_METHOD("db2linear", "db"), &PMath::db2linear); - - ClassDB::bind_method(D_METHOD("round", "val"), &PMath::round); - ClassDB::bind_method(D_METHOD("wrapi", "value", "min", "max"), &PMath::wrapi); - ClassDB::bind_method(D_METHOD("wrapf", "value", "min", "max"), &PMath::wrapf); - ClassDB::bind_method(D_METHOD("fract", "value"), &PMath::fract); - ClassDB::bind_method(D_METHOD("pingpong", "value", "length"), &PMath::pingpong); - ClassDB::bind_method(D_METHOD("ease", "x", "c"), &PMath::ease); - ClassDB::bind_method(D_METHOD("step_decimals", "step"), &PMath::step_decimals); - ClassDB::bind_method(D_METHOD("range_step_decimals", "step"), &PMath::range_step_decimals); - ClassDB::bind_method(D_METHOD("stepify", "value", "step"), &PMath::stepify); - ClassDB::bind_method(D_METHOD("dectime", "value", "amount", "step"), &PMath::dectime); - - ClassDB::bind_method(D_METHOD("larger_prime", "val"), &PMath::larger_prime); - ClassDB::bind_method(D_METHOD("seed", "x"), &PMath::seed); - ClassDB::bind_method(D_METHOD("randomize"), &PMath::randomize); - ClassDB::bind_method(D_METHOD("rand"), &PMath::rand); - ClassDB::bind_method(D_METHOD("randd"), &PMath::randd); - ClassDB::bind_method(D_METHOD("randf"), &PMath::randf); - ClassDB::bind_method(D_METHOD("randfn", "mean", "deviation"), &PMath::randfn); - ClassDB::bind_method(D_METHOD("random", "from", "to"), &PMath::random); - ClassDB::bind_method(D_METHOD("randomi", "from", "to"), &PMath::randomi); - - ClassDB::bind_method(D_METHOD("is_equal_approx_ratio", "a", "b", "epsilon", "min_epsilon"), &PMath::is_equal_approx_ratio, CMP_EPSILON, CMP_EPSILON); - ClassDB::bind_method(D_METHOD("is_equal_approx", "a", "b"), &PMath::is_equal_approx); - ClassDB::bind_method(D_METHOD("is_equal_approxt", "a", "b", "tolerance"), &PMath::is_equal_approxt); - ClassDB::bind_method(D_METHOD("is_zero_approx", "s"), &PMath::is_zero_approx); - ClassDB::bind_method(D_METHOD("absd", "g"), &PMath::absd); - ClassDB::bind_method(D_METHOD("fast_ftoi", "a"), &PMath::fast_ftoi); - ClassDB::bind_method(D_METHOD("halfbits_to_floatbits", "h"), &PMath::halfbits_to_floatbits); - ClassDB::bind_method(D_METHOD("half_to_float", "h"), &PMath::half_to_float); - ClassDB::bind_method(D_METHOD("make_half_float", "f"), &PMath::make_half_float); - ClassDB::bind_method(D_METHOD("snap_scalar", "offset", "step", "target"), &PMath::snap_scalar); - ClassDB::bind_method(D_METHOD("snap_scalar_separation", "offset", "step", "target", "separation"), &PMath::snap_scalar_separation); -} - ///////////////////// GEOMETRY _Geometry *_Geometry::singleton = nullptr; diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index 178190a2e..edb312a58 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -434,308 +434,6 @@ VARIANT_ENUM_CAST(_OS::SystemDir); VARIANT_ENUM_CAST(_OS::ScreenOrientation); VARIANT_ENUM_CAST(_OS::HandleType); -// TODO Move this to a module - -class PMath : public Object { - GDCLASS(PMath, Object); - -public: - _ALWAYS_INLINE_ real_t sin(real_t p_x) { - return Math::sin(p_x); - } - - _ALWAYS_INLINE_ real_t cos(real_t p_x) { - return Math::cos(p_x); - } - - _ALWAYS_INLINE_ real_t tan(real_t p_x) { - return Math::tan(p_x); - } - - _ALWAYS_INLINE_ real_t sinh(real_t p_x) { - return Math::sinh(p_x); - } - - _ALWAYS_INLINE_ real_t sinc(real_t p_x) { - return Math::sinc(p_x); - } - - _ALWAYS_INLINE_ real_t sincn(real_t p_x) { - return Math::sincn(p_x); - } - - _ALWAYS_INLINE_ real_t cosh(real_t p_x) { - return Math::cosh(p_x); - } - - _ALWAYS_INLINE_ real_t tanh(real_t p_x) { - return Math::tanh(p_x); - } - - _ALWAYS_INLINE_ real_t asin(real_t p_x) { - return Math::asin(p_x); - } - - _ALWAYS_INLINE_ real_t acos(real_t p_x) { - return Math::acos(p_x); - } - - _ALWAYS_INLINE_ real_t atan(real_t p_x) { - return Math::atan(p_x); - } - - _ALWAYS_INLINE_ real_t atan2(real_t p_y, real_t p_x) { - return Math::atan2(p_y, p_x); - } - - _ALWAYS_INLINE_ real_t sqrt(real_t p_x) { - return Math::sqrt(p_x); - } - - _ALWAYS_INLINE_ real_t fmod(real_t p_x, real_t p_y) { - return Math::fmod(p_x, p_y); - } - - _ALWAYS_INLINE_ real_t floor(real_t p_x) { - return Math::floor(p_x); - } - - _ALWAYS_INLINE_ int floorf_int(const float p_x) { - return Math::floorf_int(p_x); - } - - _ALWAYS_INLINE_ real_t ceil(real_t p_x) { - return Math::ceil(p_x); - } - - _ALWAYS_INLINE_ real_t pow(real_t p_x, real_t p_y) { - return Math::pow(p_x, p_y); - } - - _ALWAYS_INLINE_ real_t log(real_t p_x) { - return Math::log(p_x); - } - - _ALWAYS_INLINE_ real_t log1p(real_t p_x) { - return Math::log1p(p_x); - } - - _ALWAYS_INLINE_ real_t log10(real_t p_x) { - return Math::log10(p_x); - } - - _ALWAYS_INLINE_ real_t log2(real_t p_x) { - return Math::log2(p_x); - } - - _ALWAYS_INLINE_ real_t exp(real_t p_x) { - return Math::exp(p_x); - } - - _ALWAYS_INLINE_ real_t erf(real_t p_x) { - return Math::erf(p_x); - } - - _ALWAYS_INLINE_ bool is_nan(real_t p_val) { - return Math::is_nan(p_val); - } - - _ALWAYS_INLINE_ bool is_inf(real_t p_val) { - return Math::is_inf(p_val); - } - - _ALWAYS_INLINE_ real_t abs(real_t g) { - return Math::abs(g); - } - - _ALWAYS_INLINE_ int absi(int g) { - return Math::abs(g); - } - - _ALWAYS_INLINE_ real_t fposmod(real_t p_x, real_t p_y) { - return Math::fposmod(p_x, p_y); - } - - _ALWAYS_INLINE_ real_t fposmodp(real_t p_x, real_t p_y) { - return Math::fposmodp(p_x, p_y); - } - - _ALWAYS_INLINE_ int64_t posmod(int64_t p_x, int64_t p_y) { - return Math::posmod(p_x, p_y); - } - - _ALWAYS_INLINE_ real_t deg2rad(real_t p_y) { - return Math::deg2rad(p_y); - } - - _ALWAYS_INLINE_ real_t rad2deg(real_t p_y) { - return Math::rad2deg(p_y); - } - - _ALWAYS_INLINE_ real_t lerp(real_t p_from, real_t p_to, real_t p_weight) { - return Math::lerp(p_from, p_to, p_weight); - } - - _ALWAYS_INLINE_ real_t lerp_angle(real_t p_from, real_t p_to, real_t p_weight) { - return Math::lerp_angle(p_from, p_to, p_weight); - } - - _ALWAYS_INLINE_ real_t inverse_lerp(real_t p_from, real_t p_to, real_t p_value) { - return Math::inverse_lerp(p_from, p_to, p_value); - } - - _ALWAYS_INLINE_ real_t range_lerp(real_t p_value, real_t p_istart, real_t p_istop, real_t p_ostart, real_t p_ostop) { - return Math::range_lerp(p_value, p_istart, p_istop, p_ostart, p_ostop); - } - - _ALWAYS_INLINE_ real_t cubic_interpolate(real_t p_from, real_t p_to, real_t p_pre, real_t p_post, real_t p_weight) { - return Math::cubic_interpolate(p_from, p_to, p_pre, p_post, p_weight); - } - - _ALWAYS_INLINE_ real_t bezier_interpolate(real_t p_start, real_t p_control_1, real_t p_control_2, real_t p_end, real_t p_t) { - return Math::bezier_interpolate(p_start, p_control_1, p_control_2, p_end, p_t); - } - - _ALWAYS_INLINE_ real_t smoothstep(real_t p_from, real_t p_to, real_t p_s) { - return Math::smoothstep(p_from, p_to, p_s); - } - - _ALWAYS_INLINE_ real_t move_toward(real_t p_from, real_t p_to, real_t p_delta) { - return Math::move_toward(p_from, p_to, p_delta); - } - - _ALWAYS_INLINE_ real_t linear2db(real_t p_linear) { - return Math::linear2db(p_linear); - } - - _ALWAYS_INLINE_ real_t db2linear(real_t p_db) { - return Math::db2linear(p_db); - } - - _ALWAYS_INLINE_ real_t round(real_t p_val) { - return Math::round(p_val); - } - - _ALWAYS_INLINE_ int64_t wrapi(int64_t value, int64_t min, int64_t max) { - return Math::wrapi(value, min, max); - } - - _ALWAYS_INLINE_ real_t wrapf(real_t value, real_t min, real_t max) { - return Math::wrapf(value, min, max); - } - - _ALWAYS_INLINE_ real_t fract(real_t value) { - return Math::fract(value); - } - - _ALWAYS_INLINE_ real_t pingpong(real_t value, real_t length) { - return Math::pingpong(value, length); - } - - _ALWAYS_INLINE_ double ease(double p_x, double p_c) { - return Math::ease(p_x, p_c); - } - - _ALWAYS_INLINE_ int step_decimals(double p_step) { - return Math::step_decimals(p_step); - } - - _ALWAYS_INLINE_ int range_step_decimals(double p_step) { - return Math::range_step_decimals(p_step); - } - _ALWAYS_INLINE_ double stepify(double p_value, double p_step) { - return Math::stepify(p_value, p_step); - } - - _ALWAYS_INLINE_ double dectime(double p_value, double p_amount, double p_step) { - return Math::dectime(p_value, p_amount, p_step); - } - - _ALWAYS_INLINE_ uint32_t larger_prime(uint32_t p_val) { - return Math::larger_prime(p_val); - } - - _ALWAYS_INLINE_ void seed(uint64_t x) { - return Math::seed(x); - } - _ALWAYS_INLINE_ void randomize() { - return Math::randomize(); - } - - _ALWAYS_INLINE_ uint32_t rand() { - return Math::rand(); - } - - _ALWAYS_INLINE_ double randd() { - return Math::randd(); - } - _ALWAYS_INLINE_ float randf() { - return Math::randf(); - } - _ALWAYS_INLINE_ double randfn(double mean, double deviation) { - return Math::randfn(mean, deviation); - } - - _ALWAYS_INLINE_ real_t random(real_t from, real_t to) { - return Math::random(from, to); - } - _ALWAYS_INLINE_ int randomi(int from, int to) { - return Math::random(from, to); - } - - _ALWAYS_INLINE_ bool is_equal_approx_ratio(real_t a, real_t b, real_t epsilon = CMP_EPSILON, real_t min_epsilon = CMP_EPSILON) { - return Math::is_equal_approx_ratio(a, b, epsilon, min_epsilon); - } - - _ALWAYS_INLINE_ bool is_equal_approx(real_t a, real_t b) { - return Math::is_equal_approx(a, b); - } - - _ALWAYS_INLINE_ bool is_equal_approxt(real_t a, real_t b, real_t tolerance) { - return Math::is_equal_approx(a, b, tolerance); - } - - _ALWAYS_INLINE_ bool is_zero_approx(real_t s) { - return Math::is_zero_approx(s); - } - - _ALWAYS_INLINE_ real_t absd(real_t g) { - return Math::absd(g); - } - - _ALWAYS_INLINE_ int fast_ftoi(float a) { - return Math::fast_ftoi(a); - } - - _ALWAYS_INLINE_ uint32_t halfbits_to_floatbits(uint16_t h) { - return Math::halfbits_to_floatbits(h); - } - - _ALWAYS_INLINE_ float half_to_float(const uint16_t h) { - return Math::half_to_float(h); - } - - _ALWAYS_INLINE_ uint16_t make_half_float(float f) { - return Math::make_half_float(f); - } - - _ALWAYS_INLINE_ float snap_scalar(float p_offset, float p_step, float p_target) { - return Math::snap_scalar(p_offset, p_step, p_target); - } - - _ALWAYS_INLINE_ float snap_scalar_separation(float p_offset, float p_step, float p_target, float p_separation) { - return Math::snap_scalar_separation(p_offset, p_step, p_target, p_separation); - } - - static PMath *get_singleton(); - - PMath(); - -protected: - static void _bind_methods(); - static PMath *singleton; -}; - class _Geometry : public Object { GDCLASS(_Geometry, Object); diff --git a/core/register_core_types.cpp b/core/register_core_types.cpp index 8514eb815..aa86d9e8a 100644 --- a/core/register_core_types.cpp +++ b/core/register_core_types.cpp @@ -100,7 +100,6 @@ static ThreadPool *thread_pool = NULL; static IP *ip = nullptr; -static PMath *_math = nullptr; static _Geometry *_geometry = nullptr; extern Mutex _global_mutex; @@ -230,7 +229,6 @@ void register_core_types() { ip = IP::create(); - _math = memnew(PMath); _geometry = memnew(_Geometry); _resource_loader = memnew(_ResourceLoader); @@ -263,7 +261,6 @@ void register_core_settings() { void register_core_singletons() { ClassDB::register_class(); ClassDB::register_virtual_class(); - ClassDB::register_class(); ClassDB::register_class<_Geometry>(); ClassDB::register_class<_ResourceLoader>(); ClassDB::register_class<_ResourceSaver>(); @@ -284,7 +281,6 @@ void register_core_singletons() { Engine::get_singleton()->add_singleton(Engine::Singleton("ProjectSettings", ProjectSettings::get_singleton())); Engine::get_singleton()->add_singleton(Engine::Singleton("IP", IP::get_singleton())); - Engine::get_singleton()->add_singleton(Engine::Singleton("PMath", PMath::get_singleton())); Engine::get_singleton()->add_singleton(Engine::Singleton("Geometry", _Geometry::get_singleton())); Engine::get_singleton()->add_singleton(Engine::Singleton("ResourceLoader", _ResourceLoader::get_singleton())); Engine::get_singleton()->add_singleton(Engine::Singleton("ResourceSaver", _ResourceSaver::get_singleton())); @@ -313,7 +309,6 @@ void unregister_core_types() { memdelete(_json); memdelete(_plogger); - memdelete(_math); memdelete(_geometry); memdelete(thread_pool);