summaryrefslogtreecommitdiffstats
path: root/include/core
diff options
context:
space:
mode:
authorMarc <marc.gilleron@gmail.com>2020-08-31 15:05:09 +0100
committerGitHub <noreply@github.com>2020-08-31 15:05:09 +0100
commite5334579db5d5f291fd5ebc7ef4ec1ceab8a761b (patch)
treeb227dc0a7c796f994c21c30f7725317b6c138605 /include/core
parent31b0ca80d546f66262c961e28ce538e7ed2a0f0b (diff)
parentd53b294f5b12878c8980746d2dc7c58dedb5201a (diff)
downloadredot-cpp-e5334579db5d5f291fd5ebc7ef4ec1ceab8a761b.tar.gz
Merge branch 'master' into arcore_support
Diffstat (limited to 'include/core')
-rw-r--r--include/core/Defs.hpp4
-rw-r--r--include/core/Godot.hpp31
-rw-r--r--include/core/String.hpp3
-rw-r--r--include/core/Vector2.hpp11
-rw-r--r--include/core/Vector3.hpp11
5 files changed, 42 insertions, 18 deletions
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 <GodotGlobal.hpp>
// 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 <alloca.h>
+#else
+#include <malloc.h>
#endif
typedef float real_t;
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<Name>(); \
} \
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<Name>( \
@@ -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<T>(obj) : (T *)obj;
+ if (godot::_TagDB::is_type_compatible(T::___get_id(), have_tag)) {
+ return detail::get_custom_class_instance<T>(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
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);
diff --git a/include/core/Vector2.hpp b/include/core/Vector2.hpp
index 2a4f5fe..b3ef032 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);
}
@@ -186,8 +193,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 7e2c302..0bfa2d9 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);
}
@@ -244,8 +251,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.0);
}
inline Vector3 rotated(const Vector3 &axis, const real_t phi) const {