Merge branch 'master' into arcore_support

This commit is contained in:
Marc
2020-08-31 15:05:09 +01:00
committed by GitHub
10 changed files with 308 additions and 188 deletions

View File

@@ -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;

View File

@@ -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 (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) {
if (!godot::_TagDB::is_type_known((size_t)have_tag)) {
have_tag = 0;
if (!have_tag) {
have_tag = obj->_type_tag;
}
if (godot::_TagDB::is_type_compatible(T::___get_id(), have_tag)) {
return detail::get_custom_class_instance<T>(obj);
}
} else {
if (godot::core_1_2_api->godot_object_cast_to(obj->_owner, (void *)T::___get_id())) {
return (T *)obj;
}
}
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;
} else {
return nullptr;
}
return nullptr;
}
#endif

View File

@@ -29,6 +29,9 @@ public:
class String {
godot_string _godot_string;
String(godot_string contents) :
_godot_string(contents) {}
public:
String();
String(const char *contents);

View File

@@ -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 {

View File

@@ -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 {