From a2e6f7a5efab2fcf765429aa6985a6faca750c74 Mon Sep 17 00:00:00 2001 From: NHodgesVFX Date: Tue, 4 Feb 2020 16:33:43 -0500 Subject: Fix Vector's Bounce Reflect Fixes Vector 2 and 3 bounce and reflect methods to match gdscript Co-Authored-By: Bruno Campos Move calculation to reflect fix commit squash fix style --- include/core/Vector2.hpp | 4 ++-- include/core/Vector3.hpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/core/Vector2.hpp b/include/core/Vector2.hpp index 99ac60f..5364330 100644 --- a/include/core/Vector2.hpp +++ b/include/core/Vector2.hpp @@ -180,8 +180,8 @@ struct Vector2 { return -reflect(p_normal); } - inline Vector2 reflect(const Vector2 &p_vec) const { - return p_vec - *this * this->dot(p_vec) * 2.0; + inline Vector2 reflect(const Vector2 &p_normal) const { + return -(*this -p_normal * this->dot(p_normal) * 2.0); } inline real_t angle() const { diff --git a/include/core/Vector3.hpp b/include/core/Vector3.hpp index 2d78f21..8b39113 100644 --- a/include/core/Vector3.hpp +++ b/include/core/Vector3.hpp @@ -238,8 +238,8 @@ struct Vector3 { return v; } - inline Vector3 reflect(const Vector3 &by) const { - return by - *this * this->dot(by) * 2.f; + inline Vector3 reflect(const Vector3 &p_normal) const { + return -(*this - p_normal * this->dot(p_normal) * 2.f); } inline Vector3 rotated(const Vector3 &axis, const real_t phi) const { -- cgit v1.2.3 From 82476108bab5d59d2fddec97138296d7b9ae4494 Mon Sep 17 00:00:00 2001 From: NHodgesVFX Date: Thu, 6 Feb 2020 18:44:50 -0500 Subject: Fix Style Issues --- include/core/Vector2.hpp | 2 +- include/core/Vector3.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/core/Vector2.hpp b/include/core/Vector2.hpp index 5364330..d7c00b5 100644 --- a/include/core/Vector2.hpp +++ b/include/core/Vector2.hpp @@ -181,7 +181,7 @@ struct Vector2 { } inline Vector2 reflect(const Vector2 &p_normal) const { - return -(*this -p_normal * this->dot(p_normal) * 2.0); + return -(*this - p_normal * this->dot(p_normal) * 2.0); } inline real_t angle() const { diff --git a/include/core/Vector3.hpp b/include/core/Vector3.hpp index 8b39113..144e369 100644 --- a/include/core/Vector3.hpp +++ b/include/core/Vector3.hpp @@ -239,7 +239,7 @@ struct Vector3 { } inline Vector3 reflect(const Vector3 &p_normal) const { - return -(*this - p_normal * this->dot(p_normal) * 2.f); + return -(*this - p_normal * this->dot(p_normal) * 2.0); } inline Vector3 rotated(const Vector3 &axis, const real_t phi) const { -- cgit v1.2.3 From 5c96e5ede5dd9adf0c744c9a425ecb0fc2a2729c Mon Sep 17 00:00:00 2001 From: Duncan Sparks Date: Wed, 17 Jun 2020 11:45:19 -0700 Subject: Fix alloca.h error in Defs.h --- include/core/Defs.hpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/core/Defs.hpp b/include/core/Defs.hpp index 1b4923e..9981afe 100644 --- a/include/core/Defs.hpp +++ b/include/core/Defs.hpp @@ -62,8 +62,10 @@ enum class Error { #include // alloca() is non-standard. When using MSVC, it's in malloc.h. -#if defined(__linux__) || defined(__APPLE__) || defined(__MINGW32__) +#if defined(__linux__) || defined(__APPLE__) #include +#else +#include #endif typedef float real_t; -- cgit v1.2.3 From 20fdc09c963f876e5d894bc4c0fd3d24b4215190 Mon Sep 17 00:00:00 2001 From: Jummit Date: Wed, 15 Jul 2020 17:05:54 +0200 Subject: Add missing move_toward to Vector2 and Vector3 --- include/core/Vector2.hpp | 7 +++++++ include/core/Vector3.hpp | 7 +++++++ 2 files changed, 14 insertions(+) (limited to 'include') diff --git a/include/core/Vector2.hpp b/include/core/Vector2.hpp index 2a4f5fe..2a4c902 100644 --- a/include/core/Vector2.hpp +++ b/include/core/Vector2.hpp @@ -178,6 +178,13 @@ struct Vector2 { Vector2 cubic_interpolate(const Vector2 &p_b, const Vector2 &p_pre_a, const Vector2 &p_post_b, real_t p_t) const; + Vector2 move_toward(const Vector2 &p_to, const real_t p_delta) const { + Vector2 v = *this; + Vector2 vd = p_to - v; + real_t len = vd.length(); + return len <= p_delta || len < CMP_EPSILON ? p_to : v + vd / len * p_delta; + } + inline Vector2 slide(const Vector2 &p_vec) const { return p_vec - *this * this->dot(p_vec); } diff --git a/include/core/Vector3.hpp b/include/core/Vector3.hpp index 7e2c302..bbe8a95 100644 --- a/include/core/Vector3.hpp +++ b/include/core/Vector3.hpp @@ -167,6 +167,13 @@ struct Vector3 { Vector3 cubic_interpolate(const Vector3 &b, const Vector3 &pre_a, const Vector3 &post_b, const real_t t) const; + Vector3 move_toward(const Vector3 &p_to, const real_t p_delta) const { + Vector3 v = *this; + Vector3 vd = p_to - v; + real_t len = vd.length(); + return len <= p_delta || len < CMP_EPSILON ? p_to : v + vd / len * p_delta; + } + Vector3 bounce(const Vector3 &p_normal) const { return -reflect(p_normal); } -- cgit v1.2.3 From 0939d0f6d15e8a5870ec7bb0dafb617e0d97d532 Mon Sep 17 00:00:00 2001 From: Daniel Rakos Date: Fri, 21 Jun 2019 16:40:36 +0200 Subject: Fixed memory leak with String objects The member _godot_string should never be straight out overwritten ever without first destroying the underlying string object's memory. This change solves the problem through the introduction of a new private constructor to create String objects with a pre-existing godot_string handle. --- include/core/String.hpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'include') diff --git a/include/core/String.hpp b/include/core/String.hpp index d448567..ebf161a 100644 --- a/include/core/String.hpp +++ b/include/core/String.hpp @@ -29,6 +29,9 @@ public: class String { godot_string _godot_string; + String(godot_string contents) : + _godot_string(contents) {} + public: String(); String(const char *contents); -- cgit v1.2.3 From 33f9de16e414ad091fb6d4a6326f5cc435016ef9 Mon Sep 17 00:00:00 2001 From: sheepandshepherd Date: Mon, 21 Oct 2019 18:08:03 +0200 Subject: Use godot_object_cast_to instead of TagDB to cast engine types --- include/core/Godot.hpp | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'include') diff --git a/include/core/Godot.hpp b/include/core/Godot.hpp index ddf1e3e..9d17a2b 100644 --- a/include/core/Godot.hpp +++ b/include/core/Godot.hpp @@ -100,7 +100,7 @@ public: return godot::detail::create_custom_class_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_base_id() { return Base::___get_id(); } \ inline static const char *___get_base_type_name() { return Base::___get_class_name(); } \ inline static godot::Object *___get_from_variant(godot::Variant a) { \ return (godot::Object *)godot::detail::get_custom_class_instance( \ @@ -513,23 +513,28 @@ T *Object::cast_to(const Object *obj) { if (!obj) return nullptr; - size_t have_tag = (size_t)godot::nativescript_1_1_api->godot_nativescript_get_type_tag(obj->_owner); - - if (have_tag) { - if (!godot::_TagDB::is_type_known((size_t)have_tag)) { - have_tag = 0; + if (T::___CLASS_IS_SCRIPT) { + size_t have_tag = (size_t)godot::nativescript_1_1_api->godot_nativescript_get_type_tag(obj->_owner); + if (have_tag) { + if (!godot::_TagDB::is_type_known((size_t)have_tag)) { + have_tag = 0; + } } - } - if (!have_tag) { - have_tag = obj->_type_tag; - } + if (!have_tag) { + have_tag = obj->_type_tag; + } - if (godot::_TagDB::is_type_compatible(typeid(T).hash_code(), have_tag)) { - return (T::___CLASS_IS_SCRIPT) ? detail::get_custom_class_instance(obj) : (T *)obj; + if (godot::_TagDB::is_type_compatible(T::___get_id(), have_tag)) { + return detail::get_custom_class_instance(obj); + } } else { - return nullptr; + if (godot::core_1_2_api->godot_object_cast_to(obj->_owner, (void *)T::___get_id())) { + return (T *)obj; + } } + + return nullptr; } #endif -- cgit v1.2.3 From 469e9da86ca374c051e31524cd4059feea2aa3cb Mon Sep 17 00:00:00 2001 From: Marc Gilleron Date: Sun, 23 Aug 2020 21:32:05 +0100 Subject: Rename `RID::get_rid()` => `get_id()` to match Godot --- include/core/RID.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/core/RID.hpp b/include/core/RID.hpp index d89823b..3b3ce80 100644 --- a/include/core/RID.hpp +++ b/include/core/RID.hpp @@ -15,7 +15,7 @@ public: RID(Object *p); - int32_t get_rid() const; + int32_t get_id() const; inline bool is_valid() const { // is_valid() is not available in the C API... -- cgit v1.2.3