From 2559c70e274f9239cd29c434ab262c46f6dc8552 Mon Sep 17 00:00:00 2001 From: Mika Pi Date: Sat, 22 Feb 2020 18:13:37 -0800 Subject: Fix compilation warnings about unused vars --- include/core/Godot.hpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'include') diff --git a/include/core/Godot.hpp b/include/core/Godot.hpp index 4789632..8983e00 100644 --- a/include/core/Godot.hpp +++ b/include/core/Godot.hpp @@ -45,8 +45,8 @@ public: Name *instance = godot::as(script->new_()); \ return instance; \ } \ - inline static size_t ___get_id() { return typeid(Name).hash_code(); } \ - inline static size_t ___get_base_id() { return typeid(Base).hash_code(); } \ + inline static size_t ___get_id() { return typeid(Name).hash_code(); } \ + inline static size_t ___get_base_id() { return typeid(Base).hash_code(); } \ inline static const char *___get_base_type_name() { return Base::___get_class_name(); } \ inline static Object *___get_from_variant(godot::Variant a) { return (godot::Object *)godot::as(godot::Object::___get_from_variant(a)); } \ \ @@ -96,7 +96,7 @@ struct _ArgCast { // instance and destroy funcs template -void *_godot_class_instance_func(godot_object *p, void *method_data) { +void *_godot_class_instance_func(godot_object *p, void * /*method_data*/) { T *d = new T(); d->_owner = p; d->_type_tag = typeid(T).hash_code(); @@ -105,7 +105,7 @@ void *_godot_class_instance_func(godot_object *p, void *method_data) { } template -void _godot_class_destroy_func(godot_object *p, void *method_data, void *data) { +void _godot_class_destroy_func(godot_object * /*p*/, void * /*method_data*/, void *data) { T *d = (T *)data; delete d; } @@ -145,12 +145,12 @@ void register_tool_class() { typedef godot_variant (*__godot_wrapper_method)(godot_object *, void *, void *, int, godot_variant **); template -const char *___get_method_class_name(R (T::*p)(args... a)) { +const char *___get_method_class_name(R (T::* /*p*/)(args... a)) { return T::___get_type_name(); } template -const char *___get_method_class_name(R (T::*p)(args... a) const) { +const char *___get_method_class_name(R (T::* /*p*/)(args... a) const) { return T::___get_type_name(); } @@ -189,13 +189,13 @@ struct _WrappedMethod { void (T::*f)(As...); template - void apply(Variant *ret, T *obj, Variant **args, __Sequence) { + void apply(Variant * /*ret*/, T *obj, Variant **args, __Sequence) { (obj->*f)(_ArgCast::_arg_cast(*args[I])...); } }; template -godot_variant __wrapped_method(godot_object *, void *method_data, void *user_data, int num_args, godot_variant **args) { +godot_variant __wrapped_method(godot_object *, void *method_data, void *user_data, int /*num_args*/, godot_variant **args) { godot_variant v; godot::api->godot_variant_new_nil(&v); @@ -219,7 +219,7 @@ void *___make_wrapper_function(R (T::*f)(As...)) { } template -__godot_wrapper_method ___get_wrapper_function(R (T::*f)(As...)) { +__godot_wrapper_method ___get_wrapper_function(R (T::* /*f*/)(As...)) { return (__godot_wrapper_method)&__wrapped_method; } @@ -249,7 +249,7 @@ void register_method(const char *name, M method_ptr, godot_method_rpc_mode rpc_t template struct _PropertySetFunc { void (T::*f)(P); - static void _wrapped_setter(godot_object *object, void *method_data, void *user_data, godot_variant *value) { + static void _wrapped_setter(godot_object * /*object*/, void *method_data, void *user_data, godot_variant *value) { _PropertySetFunc *set_func = (_PropertySetFunc *)method_data; T *obj = (T *)user_data; @@ -263,7 +263,7 @@ template struct _PropertyGetFunc { P(T::*f) (); - static godot_variant _wrapped_getter(godot_object *object, void *method_data, void *user_data) { + static godot_variant _wrapped_getter(godot_object * /*object*/, void *method_data, void *user_data) { _PropertyGetFunc *get_func = (_PropertyGetFunc *)method_data; T *obj = (T *)user_data; @@ -281,7 +281,7 @@ struct _PropertyGetFunc { template struct _PropertyDefaultSetFunc { P(T::*f); - static void _wrapped_setter(godot_object *object, void *method_data, void *user_data, godot_variant *value) { + static void _wrapped_setter(godot_object * /*object*/, void *method_data, void *user_data, godot_variant *value) { _PropertyDefaultSetFunc *set_func = (_PropertyDefaultSetFunc *)method_data; T *obj = (T *)user_data; @@ -294,7 +294,7 @@ struct _PropertyDefaultSetFunc { template struct _PropertyDefaultGetFunc { P(T::*f); - static godot_variant _wrapped_getter(godot_object *object, void *method_data, void *user_data) { + static godot_variant _wrapped_getter(godot_object * /*object*/, void *method_data, void *user_data) { _PropertyDefaultGetFunc *get_func = (_PropertyDefaultGetFunc *)method_data; T *obj = (T *)user_data; -- cgit v1.2.3 From deddacd6f725ff9f23b5fc476a70c9745d06b031 Mon Sep 17 00:00:00 2001 From: Marc Gilleron Date: Tue, 8 Dec 2020 20:47:42 +0000 Subject: Fix some Math warnings --- include/core/Defs.hpp | 7 +++++-- include/core/Math.hpp | 26 ++++++++++++++------------ 2 files changed, 19 insertions(+), 14 deletions(-) (limited to 'include') diff --git a/include/core/Defs.hpp b/include/core/Defs.hpp index 67e3279..e90f6ce 100644 --- a/include/core/Defs.hpp +++ b/include/core/Defs.hpp @@ -70,9 +70,12 @@ enum class Error { typedef float real_t; -#define CMP_EPSILON 0.00001 +// This epsilon should match the one used by Godot for consistency. +// Using `f` when `real_t` is float. +#define CMP_EPSILON 0.00001f #define CMP_EPSILON2 (CMP_EPSILON * CMP_EPSILON) -#define Math_PI 3.14159265358979323846 + +#define Math_PI 3.1415926535897932384626433833 #define Math_TAU 6.2831853071795864769252867666 #define _PLANE_EQ_DOT_EPSILON 0.999 diff --git a/include/core/Math.hpp b/include/core/Math.hpp index 4d0d32e..a971bb8 100644 --- a/include/core/Math.hpp +++ b/include/core/Math.hpp @@ -107,21 +107,21 @@ inline T max(T a, T b) { template inline T sign(T x) { - return x < 0 ? -1 : 1; + return static_cast(x < 0 ? -1 : 1); } inline double deg2rad(double p_y) { return p_y * Math_PI / 180.0; } inline float deg2rad(float p_y) { - return p_y * Math_PI / 180.0; + return p_y * static_cast(Math_PI) / 180.f; } inline double rad2deg(double p_y) { return p_y * 180.0 / Math_PI; } inline float rad2deg(float p_y) { - return p_y * 180.0 / Math_PI; + return p_y * 180.f / static_cast(Math_PI); } inline double inverse_lerp(double p_from, double p_to, double p_value) { @@ -165,7 +165,7 @@ inline bool is_zero_approx(real_t s) { } inline double smoothstep(double p_from, double p_to, double p_weight) { - if (is_equal_approx(p_from, p_to)) { + if (is_equal_approx(static_cast(p_from), static_cast(p_to))) { return p_from; } double x = clamp((p_weight - p_from) / (p_to - p_from), 0.0, 1.0); @@ -205,7 +205,7 @@ inline double round(double p_val) { return (p_val >= 0) ? floor(p_val + 0.5) : -floor(-p_val + 0.5); } inline float round(float p_val) { - return (p_val >= 0) ? floor(p_val + 0.5) : -floor(-p_val + 0.5); + return (p_val >= 0) ? floor(p_val + 0.5f) : -floor(-p_val + 0.5f); } inline int64_t wrapi(int64_t value, int64_t min, int64_t max) { @@ -213,16 +213,18 @@ inline int64_t wrapi(int64_t value, int64_t min, int64_t max) { return range == 0 ? min : min + ((((value - min) % range) + range) % range); } -inline double wrapf(double value, double min, double max) { - double range = max - min; - return is_zero_approx(range) ? min : value - (range * floor((value - min) / range)); -} -inline float wrapf(float value, float min, float max) { - float range = max - min; +inline float wrapf(real_t value, real_t min, real_t max) { + const real_t range = max - min; return is_zero_approx(range) ? min : value - (range * floor((value - min) / range)); } -inline real_t stepify(real_t p_value, real_t p_step) { +inline float stepify(float p_value, float p_step) { + if (p_step != 0) { + p_value = floor(p_value / p_step + 0.5f) * p_step; + } + return p_value; +} +inline double stepify(double p_value, double p_step) { if (p_step != 0) { p_value = floor(p_value / p_step + 0.5) * p_step; } -- cgit v1.2.3 From 2893c883f8ceb20dbf3b98683db13aa8840bb183 Mon Sep 17 00:00:00 2001 From: Marc Gilleron Date: Tue, 8 Dec 2020 22:10:59 +0000 Subject: Use safer casts in Ref --- include/core/Ref.hpp | 40 +++++++++++++++------------------------- 1 file changed, 15 insertions(+), 25 deletions(-) (limited to 'include') diff --git a/include/core/Ref.hpp b/include/core/Ref.hpp index 8cbd134..80133a1 100644 --- a/include/core/Ref.hpp +++ b/include/core/Ref.hpp @@ -11,6 +11,10 @@ namespace godot { // Rewritten from f5234e70be7dec4930c2d5a0e829ff480d044b1d. template class Ref { + // TODO For this nice check to work, each class must actually #include Reference classes mentionned in its methods, + // which might be annoying for coders who prefer to forward-declare to reduce compile times + // static_assert(std::is_base_of::value, + // "Ref can only be used with classes deriving from Reference"); T *reference = nullptr; @@ -28,7 +32,7 @@ class Ref { void ref_pointer(T *p_ref) { - ERR_FAIL_COND(!p_ref); + ERR_FAIL_COND(p_ref == nullptr); if (p_ref->init_ref()) reference = p_ref; @@ -90,32 +94,25 @@ public: template void operator=(const Ref &p_from) { - - // TODO We need a safe cast Reference *refb = const_cast(static_cast(p_from.ptr())); - if (!refb) { + if (refb == nullptr) { unref(); return; } Ref r; - //r.reference = Object::cast_to(refb); - r.reference = (T *)refb; + r.reference = Object::cast_to(refb); ref(r); r.reference = nullptr; } void operator=(const Variant &p_variant) { - - // TODO We need a safe cast - Reference *refb = (Reference *)T::___get_from_variant(p_variant); - if (!refb) { + Object *refb = T::___get_from_variant(p_variant); + if (refb == nullptr) { unref(); return; } Ref r; - // TODO We need a safe cast - //r.reference = Object::cast_to(refb); - r.reference = (T *)refb; + r.reference = Object::cast_to(refb); ref(r); r.reference = nullptr; } @@ -128,18 +125,14 @@ public: template Ref(const Ref &p_from) { - reference = nullptr; - // TODO We need a safe cast Reference *refb = const_cast(static_cast(p_from.ptr())); - if (!refb) { + if (refb == nullptr) { unref(); return; } Ref r; - // TODO We need a safe cast - //r.reference = Object::cast_to(refb); - r.reference = (T *)refb; + r.reference = Object::cast_to(refb); ref(r); r.reference = nullptr; } @@ -155,16 +148,13 @@ public: Ref(const Variant &p_variant) { reference = nullptr; - // TODO We need a safe cast - Reference *refb = (Reference *)T::___get_from_variant(p_variant); - if (!refb) { + Object *refb = T::___get_from_variant(p_variant); + if (refb == nullptr) { unref(); return; } Ref r; - // TODO We need a safe cast - //r.reference = Object::cast_to(refb); - r.reference = (T *)refb; + r.reference = Object::cast_to(refb); ref(r); r.reference = nullptr; } -- cgit v1.2.3 From 8e1cc29c66cc4dd28721a0367ef2f55464e9f026 Mon Sep 17 00:00:00 2001 From: Marc Gilleron Date: Tue, 8 Dec 2020 23:00:34 +0000 Subject: Added missing constants to Vector2, Vector3, Basis and Quat --- include/core/Basis.hpp | 5 +++++ include/core/Quat.hpp | 2 ++ include/core/Transform.hpp | 5 +++++ include/core/Transform2D.hpp | 4 ++++ include/core/Vector2.hpp | 15 +++++++++++++++ include/core/Vector3.hpp | 13 +++++++++++++ 6 files changed, 44 insertions(+) (limited to 'include') diff --git a/include/core/Basis.hpp b/include/core/Basis.hpp index 76a345b..0fd697e 100644 --- a/include/core/Basis.hpp +++ b/include/core/Basis.hpp @@ -13,6 +13,11 @@ class Quat; class Basis { private: + static const Basis IDENTITY; + static const Basis FLIP_X; + static const Basis FLIP_Y; + static const Basis FLIP_Z; + // This helper template is for mimicking the behavior difference between the engine // and script interfaces that logically script sees matrices as column major, while // the engine stores them in row major to efficiently take advantage of SIMD diff --git a/include/core/Quat.hpp b/include/core/Quat.hpp index f047178..4add6be 100644 --- a/include/core/Quat.hpp +++ b/include/core/Quat.hpp @@ -11,6 +11,8 @@ namespace godot { class Quat { public: + static const Quat IDENTITY; + real_t x, y, z, w; real_t length_squared() const; diff --git a/include/core/Transform.hpp b/include/core/Transform.hpp index 9da6366..836792c 100644 --- a/include/core/Transform.hpp +++ b/include/core/Transform.hpp @@ -10,6 +10,11 @@ namespace godot { class Transform { public: + static const Transform IDENTITY; + static const Transform FLIP_X; + static const Transform FLIP_Y; + static const Transform FLIP_Z; + Basis basis; Vector3 origin; diff --git a/include/core/Transform2D.hpp b/include/core/Transform2D.hpp index ae01b7f..6a5010f 100644 --- a/include/core/Transform2D.hpp +++ b/include/core/Transform2D.hpp @@ -10,6 +10,10 @@ typedef Vector2 Size2; struct Rect2; struct Transform2D { + static const Transform2D IDENTITY; + static const Transform2D FLIP_X; + static const Transform2D FLIP_Y; + // Warning #1: basis of Transform2D is stored differently from Basis. In terms of elements array, the basis matrix looks like "on paper": // M = (elements[0][0] elements[1][0]) // (elements[0][1] elements[1][1]) diff --git a/include/core/Vector2.hpp b/include/core/Vector2.hpp index 031d47f..3c2a403 100644 --- a/include/core/Vector2.hpp +++ b/include/core/Vector2.hpp @@ -12,6 +12,21 @@ namespace godot { class String; struct Vector2 { + enum Axis { + AXIS_X = 0, + AXIS_Y, + AXIS_COUNT + }; + + static const Vector2 ZERO; + static const Vector2 ONE; + static const Vector2 INF; + + // Coordinate system of the 2D engine + static const Vector2 LEFT; + static const Vector2 RIGHT; + static const Vector2 UP; + static const Vector2 DOWN; union { real_t x; diff --git a/include/core/Vector3.hpp b/include/core/Vector3.hpp index 5971787..cbd4f75 100644 --- a/include/core/Vector3.hpp +++ b/include/core/Vector3.hpp @@ -19,8 +19,21 @@ struct Vector3 { AXIS_X, AXIS_Y, AXIS_Z, + AXIS_COUNT }; + static const Vector3 ZERO; + static const Vector3 ONE; + static const Vector3 INF; + + // Coordinate system of the 3D engine + static const Vector3 LEFT; + static const Vector3 RIGHT; + static const Vector3 UP; + static const Vector3 DOWN; + static const Vector3 FORWARD; + static const Vector3 BACK; + union { struct { real_t x; -- cgit v1.2.3 From 38c9b624db45fd9f00515c28ed6c72edb913b980 Mon Sep 17 00:00:00 2001 From: Colugo Date: Sun, 20 Dec 2020 16:44:49 +0000 Subject: Fix constness of Array::find, Array::find_last and Array::rfind --- include/core/Array.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/core/Array.hpp b/include/core/Array.hpp index 3d13914..5227fea 100644 --- a/include/core/Array.hpp +++ b/include/core/Array.hpp @@ -104,9 +104,9 @@ public: Variant back() const; - int find(const Variant &what, const int from = 0); + int find(const Variant &what, const int from = 0) const; - int find_last(const Variant &what); + int find_last(const Variant &what) const; bool has(const Variant &what) const; @@ -132,7 +132,7 @@ public: void resize(const int size); - int rfind(const Variant &what, const int from = -1); + int rfind(const Variant &what, const int from = -1) const; void sort(); -- cgit v1.2.3