diff options
Diffstat (limited to 'core')
60 files changed, 3678 insertions, 2540 deletions
diff --git a/core/SCsub b/core/SCsub index 59fe63b4b3..b9f06d12ae 100644 --- a/core/SCsub +++ b/core/SCsub @@ -3,7 +3,6 @@ Import("env") import core_builders -import make_binders env.core_sources = [] @@ -87,11 +86,7 @@ if env["builtin_zlib"]: # Minizip library, could be unbundled in theory # However, our version has some custom modifications, so it won't compile with the system one thirdparty_minizip_dir = "#thirdparty/minizip/" -thirdparty_minizip_sources = [ - "ioapi.c", - "unzip.c", - "zip.c", -] +thirdparty_minizip_sources = ["ioapi.c", "unzip.c", "zip.c"] thirdparty_minizip_sources = [thirdparty_minizip_dir + file for file in thirdparty_minizip_sources] env_thirdparty.add_source_files(env.core_sources, thirdparty_minizip_sources) @@ -152,27 +147,16 @@ env.CommandNoCache( env.Run(core_builders.make_certs_header, "Building ca-certificates header."), ) -# Make binders -env.CommandNoCache( - ["method_bind.gen.inc", "method_bind_ext.gen.inc", "method_bind_free_func.gen.inc"], - "make_binders.py", - env.Run(make_binders.run, "Generating method binders."), -) - # Authors env.Depends("#core/authors.gen.h", "../AUTHORS.md") env.CommandNoCache( - "#core/authors.gen.h", - "../AUTHORS.md", - env.Run(core_builders.make_authors_header, "Generating authors header."), + "#core/authors.gen.h", "../AUTHORS.md", env.Run(core_builders.make_authors_header, "Generating authors header.") ) # Donors env.Depends("#core/donors.gen.h", "../DONORS.md") env.CommandNoCache( - "#core/donors.gen.h", - "../DONORS.md", - env.Run(core_builders.make_donors_header, "Generating donors header."), + "#core/donors.gen.h", "../DONORS.md", env.Run(core_builders.make_donors_header, "Generating donors header.") ) # License diff --git a/core/array.cpp b/core/array.cpp index d1c0688e63..c6e90d71ec 100644 --- a/core/array.cpp +++ b/core/array.cpp @@ -31,8 +31,8 @@ #include "array.h" #include "container_type_validate.h" +#include "core/class_db.h" #include "core/hashfuncs.h" -#include "core/object.h" #include "core/script_language.h" #include "core/variant.h" #include "core/vector.h" @@ -330,9 +330,8 @@ struct _ArrayVariantSort { } }; -Array &Array::sort() { +void Array::sort() { _p->array.sort_custom<_ArrayVariantSort>(); - return *this; } struct _ArrayVariantSortCustom { @@ -349,14 +348,13 @@ struct _ArrayVariantSortCustom { return res; } }; -Array &Array::sort_custom(Object *p_obj, const StringName &p_function) { - ERR_FAIL_NULL_V(p_obj, *this); +void Array::sort_custom(Object *p_obj, const StringName &p_function) { + ERR_FAIL_NULL(p_obj); SortArray<Variant, _ArrayVariantSortCustom, true> avs; avs.compare.obj = p_obj; avs.compare.func = p_function; avs.sort(_p->array.ptrw(), _p->array.size()); - return *this; } void Array::shuffle() { @@ -415,9 +413,8 @@ int Array::bsearch_custom(const Variant &p_value, Object *p_obj, const StringNam return bisect(_p->array, p_value, p_before, less); } -Array &Array::invert() { +void Array::invert() { _p->array.invert(); - return *this; } void Array::push_front(const Variant &p_value) { diff --git a/core/array.h b/core/array.h index d2e0537ad5..34367088e4 100644 --- a/core/array.h +++ b/core/array.h @@ -75,12 +75,12 @@ public: Variant front() const; Variant back() const; - Array &sort(); - Array &sort_custom(Object *p_obj, const StringName &p_function); + void sort(); + void sort_custom(Object *p_obj, const StringName &p_function); void shuffle(); int bsearch(const Variant &p_value, bool p_before = true); int bsearch_custom(const Variant &p_value, Object *p_obj, const StringName &p_function, bool p_before = true); - Array &invert(); + void invert(); int find(const Variant &p_value, int p_from = 0) const; int rfind(const Variant &p_value, int p_from = -1) const; diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index c68222c767..baf5d4b928 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -1156,10 +1156,6 @@ Vector<Vector3> _Geometry3D::clip_polygon(const Vector<Vector3> &p_points, const return Geometry3D::clip_polygon(p_points, p_plane); } -int _Geometry3D::get_uv84_normal_bit(const Vector3 &p_vector) { - return Geometry3D::get_uv84_normal_bit(p_vector); -} - void _Geometry3D::_bind_methods() { ClassDB::bind_method(D_METHOD("build_box_planes", "extents"), &_Geometry3D::build_box_planes); ClassDB::bind_method(D_METHOD("build_cylinder_planes", "radius", "height", "sides", "axis"), &_Geometry3D::build_cylinder_planes, DEFVAL(Vector3::AXIS_Z)); @@ -1171,8 +1167,6 @@ void _Geometry3D::_bind_methods() { ClassDB::bind_method(D_METHOD("get_closest_point_to_segment_uncapped", "point", "s1", "s2"), &_Geometry3D::get_closest_point_to_segment_uncapped); - ClassDB::bind_method(D_METHOD("get_uv84_normal_bit", "normal"), &_Geometry3D::get_uv84_normal_bit); - ClassDB::bind_method(D_METHOD("ray_intersects_triangle", "from", "dir", "a", "b", "c"), &_Geometry3D::ray_intersects_triangle); ClassDB::bind_method(D_METHOD("segment_intersects_triangle", "from", "to", "a", "b", "c"), &_Geometry3D::segment_intersects_triangle); ClassDB::bind_method(D_METHOD("segment_intersects_sphere", "from", "to", "sphere_position", "sphere_radius"), &_Geometry3D::segment_intersects_sphere); @@ -1743,11 +1737,13 @@ Error _Directory::rename(String p_from, String p_to) { ERR_FAIL_COND_V_MSG(!is_open(), ERR_UNCONFIGURED, "Directory must be opened before use."); if (!p_from.is_rel_path()) { DirAccess *d = DirAccess::create_for_path(p_from); + ERR_FAIL_COND_V_MSG(!d->file_exists(p_from), ERR_DOES_NOT_EXIST, "File does not exist."); Error err = d->rename(p_from, p_to); memdelete(d); return err; } + ERR_FAIL_COND_V_MSG(!d->file_exists(p_from), ERR_DOES_NOT_EXIST, "File does not exist."); return d->rename(p_from, p_to); } diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index 5c9520d7fe..e75e740cd5 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -344,7 +344,6 @@ public: Vector<Vector3> segment_intersects_sphere(const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_sphere_pos, real_t p_sphere_radius); Vector<Vector3> segment_intersects_cylinder(const Vector3 &p_from, const Vector3 &p_to, float p_height, float p_radius); Vector<Vector3> segment_intersects_convex(const Vector3 &p_from, const Vector3 &p_to, const Vector<Plane> &p_planes); - int get_uv84_normal_bit(const Vector3 &p_vector); Vector<Vector3> clip_polygon(const Vector<Vector3> &p_points, const Plane &p_plane); diff --git a/core/binder_common.h b/core/binder_common.h new file mode 100644 index 0000000000..0fbfa56230 --- /dev/null +++ b/core/binder_common.h @@ -0,0 +1,657 @@ +/*************************************************************************/ +/* binder_common.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef BINDER_COMMON_H +#define BINDER_COMMON_H + +#include "core/list.h" +#include "core/method_ptrcall.h" +#include "core/object.h" +#include "core/simple_type.h" +#include "core/type_info.h" +#include "core/typedefs.h" +#include "core/variant.h" +#include "core/variant_internal.h" + +#include <stdio.h> + +template <class T> +struct VariantCaster { + static _FORCE_INLINE_ T cast(const Variant &p_variant) { + return p_variant; + } +}; + +template <class T> +struct VariantCaster<T &> { + static _FORCE_INLINE_ T cast(const Variant &p_variant) { + return p_variant; + } +}; + +template <class T> +struct VariantCaster<const T &> { + static _FORCE_INLINE_ T cast(const Variant &p_variant) { + return p_variant; + } +}; + +#ifdef PTRCALL_ENABLED + +#define VARIANT_ENUM_CAST(m_enum) \ + MAKE_ENUM_TYPE_INFO(m_enum) \ + template <> \ + struct VariantCaster<m_enum> { \ + static _FORCE_INLINE_ m_enum cast(const Variant &p_variant) { \ + return (m_enum)p_variant.operator int(); \ + } \ + }; \ + template <> \ + struct PtrToArg<m_enum> { \ + _FORCE_INLINE_ static m_enum convert(const void *p_ptr) { \ + return m_enum(*reinterpret_cast<const int *>(p_ptr)); \ + } \ + _FORCE_INLINE_ static void encode(m_enum p_val, const void *p_ptr) { \ + *(int *)p_ptr = p_val; \ + } \ + }; + +#else + +#define VARIANT_ENUM_CAST(m_enum) \ + MAKE_ENUM_TYPE_INFO(m_enum) \ + template <> \ + struct VariantCaster<m_enum> { \ + static _FORCE_INLINE_ m_enum cast(const Variant &p_variant) { \ + return (m_enum)p_variant.operator int(); \ + } \ + }; + +#endif + +// Object enum casts must go here +VARIANT_ENUM_CAST(Object::ConnectFlags); + +VARIANT_ENUM_CAST(Vector3::Axis); + +VARIANT_ENUM_CAST(Error); +VARIANT_ENUM_CAST(Margin); +VARIANT_ENUM_CAST(Corner); +VARIANT_ENUM_CAST(Orientation); +VARIANT_ENUM_CAST(HAlign); +VARIANT_ENUM_CAST(VAlign); +VARIANT_ENUM_CAST(PropertyHint); +VARIANT_ENUM_CAST(PropertyUsageFlags); +VARIANT_ENUM_CAST(Variant::Type); +VARIANT_ENUM_CAST(Variant::Operator); + +template <> +struct VariantCaster<char32_t> { + static _FORCE_INLINE_ char32_t cast(const Variant &p_variant) { + return (char32_t)p_variant.operator int(); + } +}; +#ifdef PTRCALL_ENABLED +template <> +struct PtrToArg<char32_t> { + _FORCE_INLINE_ static char32_t convert(const void *p_ptr) { + return char32_t(*reinterpret_cast<const int *>(p_ptr)); + } + _FORCE_INLINE_ static void encode(char32_t p_val, const void *p_ptr) { + *(int *)p_ptr = p_val; + } +}; +#endif + +template <typename T> +struct VariantObjectClassChecker { + static _FORCE_INLINE_ bool check(const Variant &p_variant) { + return true; + } +}; + +template <> +struct VariantObjectClassChecker<Node *> { + static _FORCE_INLINE_ bool check(const Variant &p_variant) { + Object *obj = p_variant; + Node *node = p_variant; + return node || !obj; + } +}; + +template <> +struct VariantObjectClassChecker<Control *> { + static _FORCE_INLINE_ bool check(const Variant &p_variant) { + Object *obj = p_variant; + Control *control = p_variant; + return control || !obj; + } +}; + +#ifdef DEBUG_METHODS_ENABLED + +template <class T> +struct VariantCasterAndValidate { + static _FORCE_INLINE_ T cast(const Variant **p_args, uint32_t p_arg_idx, Callable::CallError &r_error) { + Variant::Type argtype = GetTypeInfo<T>::VARIANT_TYPE; + if (!Variant::can_convert_strict(p_args[p_arg_idx]->get_type(), argtype) || + !VariantObjectClassChecker<T>::check(p_args[p_arg_idx])) { + r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; + r_error.argument = p_arg_idx; + r_error.expected = argtype; + } + + return VariantCaster<T>::cast(*p_args[p_arg_idx]); + } +}; + +template <class T> +struct VariantCasterAndValidate<T &> { + static _FORCE_INLINE_ T cast(const Variant **p_args, uint32_t p_arg_idx, Callable::CallError &r_error) { + Variant::Type argtype = GetTypeInfo<T>::VARIANT_TYPE; + if (!Variant::can_convert_strict(p_args[p_arg_idx]->get_type(), argtype) || + !VariantObjectClassChecker<T>::check(p_args[p_arg_idx])) { + r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; + r_error.argument = p_arg_idx; + r_error.expected = argtype; + } + + return VariantCaster<T>::cast(*p_args[p_arg_idx]); + } +}; + +template <class T> +struct VariantCasterAndValidate<const T &> { + static _FORCE_INLINE_ T cast(const Variant **p_args, uint32_t p_arg_idx, Callable::CallError &r_error) { + Variant::Type argtype = GetTypeInfo<T>::VARIANT_TYPE; + if (!Variant::can_convert_strict(p_args[p_arg_idx]->get_type(), argtype) || + !VariantObjectClassChecker<T>::check(p_args[p_arg_idx])) { + r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; + r_error.argument = p_arg_idx; + r_error.expected = argtype; + } + + return VariantCaster<T>::cast(*p_args[p_arg_idx]); + } +}; + +#endif // DEBUG_METHODS_ENABLED + +template <class T, class... P, size_t... Is> +void call_with_variant_args_helper(T *p_instance, void (T::*p_method)(P...), const Variant **p_args, Callable::CallError &r_error, IndexSequence<Is...>) { + r_error.error = Callable::CallError::CALL_OK; + +#ifdef DEBUG_METHODS_ENABLED + (p_instance->*p_method)(VariantCasterAndValidate<P>::cast(p_args, Is, r_error)...); +#else + (p_instance->*p_method)(VariantCaster<P>::cast(*p_args[Is])...); +#endif + (void)(p_args); //avoid warning +} + +template <class T, class... P, size_t... Is> +void call_with_variant_argsc_helper(T *p_instance, void (T::*p_method)(P...) const, const Variant **p_args, Callable::CallError &r_error, IndexSequence<Is...>) { + r_error.error = Callable::CallError::CALL_OK; + +#ifdef DEBUG_METHODS_ENABLED + (p_instance->*p_method)(VariantCasterAndValidate<P>::cast(p_args, Is, r_error)...); +#else + (p_instance->*p_method)(VariantCaster<P>::cast(*p_args[Is])...); +#endif + (void)(p_args); //avoid warning +} + +#ifdef PTRCALL_ENABLED + +template <class T, class... P, size_t... Is> +void call_with_ptr_args_helper(T *p_instance, void (T::*p_method)(P...), const void **p_args, IndexSequence<Is...>) { + (p_instance->*p_method)(PtrToArg<P>::convert(p_args[Is])...); +} + +template <class T, class... P, size_t... Is> +void call_with_ptr_argsc_helper(T *p_instance, void (T::*p_method)(P...) const, const void **p_args, IndexSequence<Is...>) { + (p_instance->*p_method)(PtrToArg<P>::convert(p_args[Is])...); +} + +template <class T, class R, class... P, size_t... Is> +void call_with_ptr_args_ret_helper(T *p_instance, R (T::*p_method)(P...), const void **p_args, void *r_ret, IndexSequence<Is...>) { + PtrToArg<R>::encode((p_instance->*p_method)(PtrToArg<P>::convert(p_args[Is])...), r_ret); +} + +template <class T, class R, class... P, size_t... Is> +void call_with_ptr_args_retc_helper(T *p_instance, R (T::*p_method)(P...) const, const void **p_args, void *r_ret, IndexSequence<Is...>) { + PtrToArg<R>::encode((p_instance->*p_method)(PtrToArg<P>::convert(p_args[Is])...), r_ret); +} + +template <class T, class R, class... P, size_t... Is> +void call_with_ptr_args_static_retc_helper(T *p_instance, R (*p_method)(T *, P...), const void **p_args, void *r_ret, IndexSequence<Is...>) { + PtrToArg<R>::encode(p_method(p_instance, PtrToArg<P>::convert(p_args[Is])...), r_ret); +} + +#endif // PTRCALL_ENABLED + +template <class T, class... P, size_t... Is> +void call_with_validated_variant_args_helper(T *p_instance, void (T::*p_method)(P...), const Variant **p_args, IndexSequence<Is...>) { + (p_instance->*p_method)((VariantInternalAccessor<typename GetSimpleTypeT<P>::type_t>::get(p_args[Is]))...); +} + +template <class T, class... P, size_t... Is> +void call_with_validated_variant_argsc_helper(T *p_instance, void (T::*p_method)(P...) const, const Variant **p_args, IndexSequence<Is...>) { + (p_instance->*p_method)((VariantInternalAccessor<typename GetSimpleTypeT<P>::type_t>::get(p_args[Is]))...); +} + +template <class T, class R, class... P, size_t... Is> +void call_with_validated_variant_args_ret_helper(T *p_instance, R (T::*p_method)(P...), const Variant **p_args, Variant *r_ret, IndexSequence<Is...>) { + VariantInternalAccessor<typename GetSimpleTypeT<R>::type_t>::set(r_ret, (p_instance->*p_method)((VariantInternalAccessor<typename GetSimpleTypeT<P>::type_t>::get(p_args[Is]))...)); +} + +template <class T, class R, class... P, size_t... Is> +void call_with_validated_variant_args_retc_helper(T *p_instance, R (T::*p_method)(P...) const, const Variant **p_args, Variant *r_ret, IndexSequence<Is...>) { + VariantInternalAccessor<typename GetSimpleTypeT<R>::type_t>::set(r_ret, (p_instance->*p_method)((VariantInternalAccessor<typename GetSimpleTypeT<P>::type_t>::get(p_args[Is]))...)); +} + +template <class T, class R, class... P, size_t... Is> +void call_with_validated_variant_args_static_retc_helper(T *p_instance, R (*p_method)(T *, P...), const Variant **p_args, Variant *r_ret, IndexSequence<Is...>) { + VariantInternalAccessor<typename GetSimpleTypeT<R>::type_t>::set(r_ret, p_method(p_instance, (VariantInternalAccessor<typename GetSimpleTypeT<P>::type_t>::get(p_args[Is]))...)); +} + +template <class T, class... P> +void call_with_variant_args(T *p_instance, void (T::*p_method)(P...), const Variant **p_args, int p_argcount, Callable::CallError &r_error) { +#ifdef DEBUG_METHODS_ENABLED + if ((size_t)p_argcount > sizeof...(P)) { + r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS; + r_error.argument = sizeof...(P); + return; + } + + if ((size_t)p_argcount < sizeof...(P)) { + r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; + r_error.argument = sizeof...(P); + return; + } +#endif + call_with_variant_args_helper<T, P...>(p_instance, p_method, p_args, r_error, BuildIndexSequence<sizeof...(P)>{}); +} + +template <class T, class... P> +void call_with_variant_args_dv(T *p_instance, void (T::*p_method)(P...), const Variant **p_args, int p_argcount, Callable::CallError &r_error, const Vector<Variant> &default_values) { +#ifdef DEBUG_ENABLED + if ((size_t)p_argcount > sizeof...(P)) { + r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS; + r_error.argument = sizeof...(P); + return; + } +#endif + + int32_t missing = (int32_t)sizeof...(P) - (int32_t)p_argcount; + + int32_t dvs = default_values.size(); +#ifdef DEBUG_ENABLED + if (missing > dvs) { + r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; + r_error.argument = sizeof...(P); + return; + } +#endif + + const Variant *args[sizeof...(P) == 0 ? 1 : sizeof...(P)]; //avoid zero sized array + for (int32_t i = 0; i < (int32_t)sizeof...(P); i++) { + if (i < p_argcount) { + args[i] = p_args[i]; + } else { + args[i] = &default_values[i - p_argcount + (dvs - missing)]; + } + } + + call_with_variant_args_helper(p_instance, p_method, args, r_error, BuildIndexSequence<sizeof...(P)>{}); +} + +template <class T, class... P> +void call_with_variant_argsc(T *p_instance, void (T::*p_method)(P...) const, const Variant **p_args, int p_argcount, Callable::CallError &r_error) { +#ifdef DEBUG_METHODS_ENABLED + if ((size_t)p_argcount > sizeof...(P)) { + r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS; + r_error.argument = sizeof...(P); + return; + } + + if ((size_t)p_argcount < sizeof...(P)) { + r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; + r_error.argument = sizeof...(P); + return; + } +#endif + call_with_variant_args_helper<T, P...>(p_instance, p_method, p_args, r_error, BuildIndexSequence<sizeof...(P)>{}); +} + +template <class T, class... P> +void call_with_variant_argsc_dv(T *p_instance, void (T::*p_method)(P...) const, const Variant **p_args, int p_argcount, Callable::CallError &r_error, const Vector<Variant> &default_values) { +#ifdef DEBUG_ENABLED + if ((size_t)p_argcount > sizeof...(P)) { + r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS; + r_error.argument = sizeof...(P); + return; + } +#endif + + int32_t missing = (int32_t)sizeof...(P) - (int32_t)p_argcount; + + int32_t dvs = default_values.size(); +#ifdef DEBUG_ENABLED + if (missing > dvs) { + r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; + r_error.argument = sizeof...(P); + return; + } +#endif + + const Variant *args[sizeof...(P) == 0 ? 1 : sizeof...(P)]; //avoid zero sized array + for (int32_t i = 0; i < (int32_t)sizeof...(P); i++) { + if (i < p_argcount) { + args[i] = p_args[i]; + } else { + args[i] = &default_values[i - p_argcount + (dvs - missing)]; + } + } + + call_with_variant_argsc_helper(p_instance, p_method, args, r_error, BuildIndexSequence<sizeof...(P)>{}); +} + +template <class T, class R, class... P> +void call_with_variant_args_ret_dv(T *p_instance, R (T::*p_method)(P...), const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error, const Vector<Variant> &default_values) { +#ifdef DEBUG_ENABLED + if ((size_t)p_argcount > sizeof...(P)) { + r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS; + r_error.argument = sizeof...(P); + return; + } +#endif + + int32_t missing = (int32_t)sizeof...(P) - (int32_t)p_argcount; + + int32_t dvs = default_values.size(); +#ifdef DEBUG_ENABLED + if (missing > dvs) { + r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; + r_error.argument = sizeof...(P); + return; + } +#endif + + const Variant *args[sizeof...(P) == 0 ? 1 : sizeof...(P)]; //avoid zero sized array + for (int32_t i = 0; i < (int32_t)sizeof...(P); i++) { + if (i < p_argcount) { + args[i] = p_args[i]; + } else { + args[i] = &default_values[i - p_argcount + (dvs - missing)]; + } + } + + call_with_variant_args_ret_helper(p_instance, p_method, args, r_ret, r_error, BuildIndexSequence<sizeof...(P)>{}); +} + +template <class T, class R, class... P> +void call_with_variant_args_retc_dv(T *p_instance, R (T::*p_method)(P...) const, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error, const Vector<Variant> &default_values) { +#ifdef DEBUG_ENABLED + if ((size_t)p_argcount > sizeof...(P)) { + r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS; + r_error.argument = sizeof...(P); + return; + } +#endif + + int32_t missing = (int32_t)sizeof...(P) - (int32_t)p_argcount; + + int32_t dvs = default_values.size(); +#ifdef DEBUG_ENABLED + if (missing > dvs) { + r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; + r_error.argument = sizeof...(P); + return; + } +#endif + + const Variant *args[sizeof...(P) == 0 ? 1 : sizeof...(P)]; //avoid zero sized array + for (int32_t i = 0; i < (int32_t)sizeof...(P); i++) { + if (i < p_argcount) { + args[i] = p_args[i]; + } else { + args[i] = &default_values[i - p_argcount + (dvs - missing)]; + } + } + + call_with_variant_args_retc_helper(p_instance, p_method, args, r_ret, r_error, BuildIndexSequence<sizeof...(P)>{}); +} + +#ifdef PTRCALL_ENABLED + +template <class T, class... P> +void call_with_ptr_args(T *p_instance, void (T::*p_method)(P...), const void **p_args) { + call_with_ptr_args_helper<T, P...>(p_instance, p_method, p_args, BuildIndexSequence<sizeof...(P)>{}); +} + +template <class T, class... P> +void call_with_ptr_argsc(T *p_instance, void (T::*p_method)(P...) const, const void **p_args) { + call_with_ptr_argsc_helper<T, P...>(p_instance, p_method, p_args, BuildIndexSequence<sizeof...(P)>{}); +} + +template <class T, class R, class... P> +void call_with_ptr_args_ret(T *p_instance, R (T::*p_method)(P...), const void **p_args, void *r_ret) { + call_with_ptr_args_ret_helper<T, R, P...>(p_instance, p_method, p_args, r_ret, BuildIndexSequence<sizeof...(P)>{}); +} + +template <class T, class R, class... P> +void call_with_ptr_args_retc(T *p_instance, R (T::*p_method)(P...) const, const void **p_args, void *r_ret) { + call_with_ptr_args_retc_helper<T, R, P...>(p_instance, p_method, p_args, r_ret, BuildIndexSequence<sizeof...(P)>{}); +} + +template <class T, class R, class... P> +void call_with_ptr_args_static_retc(T *p_instance, R (*p_method)(T *, P...), const void **p_args, void *r_ret) { + call_with_ptr_args_static_retc_helper<T, R, P...>(p_instance, p_method, p_args, r_ret, BuildIndexSequence<sizeof...(P)>{}); +} + +#endif // PTRCALL_ENABLED + +template <class T, class... P> +void call_with_validated_variant_args(Variant *base, void (T::*p_method)(P...), const Variant **p_args) { + call_with_validated_variant_args_helper<T, P...>(VariantGetInternalPtr<T>::get_ptr(base), p_method, p_args, BuildIndexSequence<sizeof...(P)>{}); +} + +template <class T, class R, class... P> +void call_with_validated_variant_args_ret(Variant *base, R (T::*p_method)(P...), const Variant **p_args, Variant *r_ret) { + call_with_validated_variant_args_ret_helper<T, R, P...>(VariantGetInternalPtr<T>::get_ptr(base), p_method, p_args, r_ret, BuildIndexSequence<sizeof...(P)>{}); +} + +template <class T, class R, class... P> +void call_with_validated_variant_args_retc(Variant *base, R (T::*p_method)(P...) const, const Variant **p_args, Variant *r_ret) { + call_with_validated_variant_args_retc_helper<T, R, P...>(VariantGetInternalPtr<T>::get_ptr(base), p_method, p_args, r_ret, BuildIndexSequence<sizeof...(P)>{}); +} + +template <class T, class R, class... P> +void call_with_validated_variant_args_static_retc(Variant *base, R (*p_method)(T *, P...), const Variant **p_args, Variant *r_ret) { + call_with_validated_variant_args_static_retc_helper<T, R, P...>(VariantGetInternalPtr<T>::get_ptr(base), p_method, p_args, r_ret, BuildIndexSequence<sizeof...(P)>{}); +} + +// GCC raises "parameter 'p_args' set but not used" when P = {}, +// it's not clever enough to treat other P values as making this branch valid. +#if defined(DEBUG_METHODS_ENABLED) && defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-but-set-parameter" +#endif + +#ifdef DEBUG_METHODS_ENABLED + +template <class Q> +void call_get_argument_type_helper(int p_arg, int &index, Variant::Type &type) { + if (p_arg == index) { + type = GetTypeInfo<Q>::VARIANT_TYPE; + } + index++; +} + +template <class... P> +Variant::Type call_get_argument_type(int p_arg) { + Variant::Type type = Variant::NIL; + int index = 0; + // I think rocket science is simpler than modern C++. + using expand_type = int[]; + expand_type a{ 0, (call_get_argument_type_helper<P>(p_arg, index, type), 0)... }; + (void)a; // Suppress (valid, but unavoidable) -Wunused-variable warning. + (void)index; // Suppress GCC warning. + return type; +} + +template <class Q> +void call_get_argument_type_info_helper(int p_arg, int &index, PropertyInfo &info) { + if (p_arg == index) { + info = GetTypeInfo<Q>::get_class_info(); + } + index++; +} + +template <class... P> +void call_get_argument_type_info(int p_arg, PropertyInfo &info) { + int index = 0; + // I think rocket science is simpler than modern C++. + using expand_type = int[]; + expand_type a{ 0, (call_get_argument_type_info_helper<P>(p_arg, index, info), 0)... }; + (void)a; // Suppress (valid, but unavoidable) -Wunused-variable warning. + (void)index; // Suppress GCC warning. +} + +template <class Q> +void call_get_argument_metadata_helper(int p_arg, int &index, GodotTypeInfo::Metadata &md) { + if (p_arg == index) { + md = GetTypeInfo<Q>::METADATA; + } + index++; +} + +template <class... P> +GodotTypeInfo::Metadata call_get_argument_metadata(int p_arg) { + GodotTypeInfo::Metadata md = GodotTypeInfo::METADATA_NONE; + + int index = 0; + // I think rocket science is simpler than modern C++. + using expand_type = int[]; + expand_type a{ 0, (call_get_argument_metadata_helper<P>(p_arg, index, md), 0)... }; + (void)a; // Suppress (valid, but unavoidable) -Wunused-variable warning. + (void)index; + return md; +} + +#else + +template <class... P> +Variant::Type call_get_argument_type(int p_arg) { + return Variant::NIL; +} + +#endif // DEBUG_METHODS_ENABLED + +////////////////////// + +template <class T, class R, class... P, size_t... Is> +void call_with_variant_args_ret_helper(T *p_instance, R (T::*p_method)(P...), const Variant **p_args, Variant &r_ret, Callable::CallError &r_error, IndexSequence<Is...>) { + r_error.error = Callable::CallError::CALL_OK; + +#ifdef DEBUG_METHODS_ENABLED + r_ret = (p_instance->*p_method)(VariantCasterAndValidate<P>::cast(p_args, Is, r_error)...); +#else + r_ret = (p_instance->*p_method)(VariantCaster<P>::cast(*p_args[Is])...); +#endif +} + +template <class T, class R, class... P> +void call_with_variant_args_ret(T *p_instance, R (T::*p_method)(P...), const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) { +#ifdef DEBUG_METHODS_ENABLED + if ((size_t)p_argcount > sizeof...(P)) { + r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS; + r_error.argument = sizeof...(P); + return; + } + + if ((size_t)p_argcount < sizeof...(P)) { + r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; + r_error.argument = sizeof...(P); + return; + } +#endif + call_with_variant_args_ret_helper<T, R, P...>(p_instance, p_method, p_args, r_ret, r_error, BuildIndexSequence<sizeof...(P)>{}); +} + +template <class T, class R, class... P, size_t... Is> +void call_with_variant_args_retc_helper(T *p_instance, R (T::*p_method)(P...) const, const Variant **p_args, Variant &r_ret, Callable::CallError &r_error, IndexSequence<Is...>) { + r_error.error = Callable::CallError::CALL_OK; + +#ifdef DEBUG_METHODS_ENABLED + r_ret = (p_instance->*p_method)(VariantCasterAndValidate<P>::cast(p_args, Is, r_error)...); +#else + r_ret = (p_instance->*p_method)(VariantCaster<P>::cast(*p_args[Is])...); +#endif + (void)p_args; +} + +template <class T, class R, class... P> +void call_with_variant_args_retc(T *p_instance, R (T::*p_method)(P...) const, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) { +#ifdef DEBUG_METHODS_ENABLED + if ((size_t)p_argcount > sizeof...(P)) { + r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS; + r_error.argument = sizeof...(P); + return; + } + + if ((size_t)p_argcount < sizeof...(P)) { + r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; + r_error.argument = sizeof...(P); + return; + } +#endif + call_with_variant_args_retc_helper<T, R, P...>(p_instance, p_method, p_args, r_ret, r_error, BuildIndexSequence<sizeof...(P)>{}); +} + +template <class T, class R, class... P, size_t... Is> +void call_with_variant_args_retc_static_helper(T *p_instance, R (*p_method)(T *, P...), const Variant **p_args, Variant &r_ret, Callable::CallError &r_error, IndexSequence<Is...>) { + r_error.error = Callable::CallError::CALL_OK; + +#ifdef DEBUG_METHODS_ENABLED + r_ret = (p_method)(p_instance, VariantCasterAndValidate<P>::cast(p_args, Is, r_error)...); +#else + r_ret = (p_method)(p_instance, VariantCaster<P>::cast(*p_args[Is])...); +#endif + + (void)p_args; +} + +#if defined(DEBUG_METHODS_ENABLED) && defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic pop +#endif + +#endif // BINDER_COMMON_H diff --git a/core/callable.cpp b/core/callable.cpp index b7bdc715f8..c368565687 100644 --- a/core/callable.cpp +++ b/core/callable.cpp @@ -30,6 +30,7 @@ #include "callable.h" +#include "callable_bind.h" #include "core/script_language.h" #include "message_queue.h" #include "object.h" @@ -53,6 +54,18 @@ void Callable::call(const Variant **p_arguments, int p_argcount, Variant &r_retu } } +Callable Callable::bind(const Variant **p_arguments, int p_argcount) const { + Vector<Variant> args; + args.resize(p_argcount); + for (int i = 0; i < p_argcount; i++) { + args.write[i] = *p_arguments[i]; + } + return Callable(memnew(CallableCustomBind(*this, args))); +} +Callable Callable::unbind(int p_argcount) const { + return Callable(memnew(CallableCustomUnbind(*this, p_argcount))); +} + Object *Callable::get_object() const { if (is_null()) { return nullptr; @@ -85,6 +98,18 @@ CallableCustom *Callable::get_custom() const { return custom; } +const Callable *Callable::get_base_comparator() const { + const Callable *comparator = nullptr; + if (is_custom()) { + comparator = custom->get_base_comparator(); + } + if (comparator) { + return comparator; + } else { + return this; + } +} + uint32_t Callable::hash() const { if (is_custom()) { return custom->hash(); @@ -258,6 +283,10 @@ Callable::~Callable() { } } +const Callable *CallableCustom::get_base_comparator() const { + return nullptr; +} + CallableCustom::CallableCustom() { ref_count.init(); } diff --git a/core/callable.h b/core/callable.h index 7fd6b54cf7..936272a681 100644 --- a/core/callable.h +++ b/core/callable.h @@ -80,6 +80,9 @@ public: return method != StringName(); } + Callable bind(const Variant **p_arguments, int p_argcount) const; + Callable unbind(int p_argcount) const; + Object *get_object() const; ObjectID get_object_id() const; StringName get_method() const; @@ -87,6 +90,8 @@ public: uint32_t hash() const; + const Callable *get_base_comparator() const; //used for bind/unbind to do less precise comparisons (ignoring binds) in signal connect/disconnect + bool operator==(const Callable &p_callable) const; bool operator!=(const Callable &p_callable) const; bool operator<(const Callable &p_callable) const; @@ -119,6 +124,7 @@ public: virtual CompareLessFunc get_compare_less_func() const = 0; virtual ObjectID get_object() const = 0; //must always be able to provide an object virtual void call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const = 0; + virtual const Callable *get_base_comparator() const; CallableCustom(); virtual ~CallableCustom() {} diff --git a/core/callable_bind.cpp b/core/callable_bind.cpp new file mode 100644 index 0000000000..da08d3ccbd --- /dev/null +++ b/core/callable_bind.cpp @@ -0,0 +1,193 @@ +/*************************************************************************/ +/* callable_bind.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "callable_bind.h" + +////////////////////////////////// + +uint32_t CallableCustomBind::hash() const { + return callable.hash(); +} +String CallableCustomBind::get_as_text() const { + return callable.operator String(); +} + +bool CallableCustomBind::_equal_func(const CallableCustom *p_a, const CallableCustom *p_b) { + const CallableCustomBind *a = (const CallableCustomBind *)p_a; + const CallableCustomBind *b = (const CallableCustomBind *)p_b; + + if (!(a->callable != b->callable)) { + return false; + } + + if (a->binds.size() != b->binds.size()) { + return false; + } + + return true; +} + +bool CallableCustomBind::_less_func(const CallableCustom *p_a, const CallableCustom *p_b) { + const CallableCustomBind *a = (const CallableCustomBind *)p_a; + const CallableCustomBind *b = (const CallableCustomBind *)p_b; + + if (a->callable < b->callable) { + return true; + } else if (b->callable < a->callable) { + return false; + } + + return a->binds.size() < b->binds.size(); +} + +CallableCustom::CompareEqualFunc CallableCustomBind::get_compare_equal_func() const { + return _equal_func; +} +CallableCustom::CompareLessFunc CallableCustomBind::get_compare_less_func() const { + return _less_func; +} +ObjectID CallableCustomBind::get_object() const { + return callable.get_object_id(); +} +const Callable *CallableCustomBind::get_base_comparator() const { + return &callable; +} + +void CallableCustomBind::call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const { + const Variant **args = (const Variant **)alloca(sizeof(const Variant **) * (binds.size() + p_argcount)); + for (int i = 0; i < p_argcount; i++) { + args[i] = (const Variant *)p_arguments[i]; + } + for (int i = 0; i < binds.size(); i++) { + args[i + p_argcount] = (const Variant *)&binds[i]; + } + + callable.call(args, p_argcount + binds.size(), r_return_value, r_call_error); +} + +CallableCustomBind::CallableCustomBind(const Callable &p_callable, const Vector<Variant> &p_binds) { + callable = p_callable; + binds = p_binds; +} + +CallableCustomBind::~CallableCustomBind() { +} + +////////////////////////////////// + +uint32_t CallableCustomUnbind::hash() const { + return callable.hash(); +} +String CallableCustomUnbind::get_as_text() const { + return callable.operator String(); +} + +bool CallableCustomUnbind::_equal_func(const CallableCustom *p_a, const CallableCustom *p_b) { + const CallableCustomUnbind *a = (const CallableCustomUnbind *)p_a; + const CallableCustomUnbind *b = (const CallableCustomUnbind *)p_b; + + if (!(a->callable != b->callable)) { + return false; + } + + if (a->argcount != b->argcount) { + return false; + } + + return true; +} + +bool CallableCustomUnbind::_less_func(const CallableCustom *p_a, const CallableCustom *p_b) { + const CallableCustomUnbind *a = (const CallableCustomUnbind *)p_a; + const CallableCustomUnbind *b = (const CallableCustomUnbind *)p_b; + + if (a->callable < b->callable) { + return true; + } else if (b->callable < a->callable) { + return false; + } + + return a->argcount < b->argcount; +} + +CallableCustom::CompareEqualFunc CallableCustomUnbind::get_compare_equal_func() const { + return _equal_func; +} +CallableCustom::CompareLessFunc CallableCustomUnbind::get_compare_less_func() const { + return _less_func; +} +ObjectID CallableCustomUnbind::get_object() const { + return callable.get_object_id(); +} +const Callable *CallableCustomUnbind::get_base_comparator() const { + return &callable; +} + +void CallableCustomUnbind::call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const { + if (argcount > p_argcount) { + r_call_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; + r_call_error.argument = 0; + r_call_error.expected = argcount; + return; + } + callable.call(p_arguments, p_argcount - argcount, r_return_value, r_call_error); +} + +CallableCustomUnbind::CallableCustomUnbind(const Callable &p_callable, int p_argcount) { + callable = p_callable; + argcount = p_argcount; +} + +CallableCustomUnbind::~CallableCustomUnbind() { +} + +Callable callable_bind(const Callable &p_callable, const Variant &p_arg1) { + return p_callable.bind((const Variant **)&p_arg1, 1); +} + +Callable callable_bind(const Callable &p_callable, const Variant &p_arg1, const Variant &p_arg2) { + const Variant *args[2] = { &p_arg1, &p_arg2 }; + return p_callable.bind(args, 2); +} + +Callable callable_bind(const Callable &p_callable, const Variant &p_arg1, const Variant &p_arg2, const Variant &p_arg3) { + const Variant *args[3] = { &p_arg1, &p_arg2, &p_arg3 }; + return p_callable.bind(args, 3); +} + +Callable callable_bind(const Callable &p_callable, const Variant &p_arg1, const Variant &p_arg2, const Variant &p_arg3, const Variant &p_arg4) { + const Variant *args[4] = { &p_arg1, &p_arg2, &p_arg3, &p_arg4 }; + return p_callable.bind(args, 4); +} + +Callable callable_bind(const Callable &p_callable, const Variant &p_arg1, const Variant &p_arg2, const Variant &p_arg3, const Variant &p_arg4, const Variant &p_arg5) { + const Variant *args[5] = { &p_arg1, &p_arg2, &p_arg3, &p_arg4, &p_arg5 }; + return p_callable.bind(args, 5); +} diff --git a/core/callable_bind.h b/core/callable_bind.h new file mode 100644 index 0000000000..21b9228be3 --- /dev/null +++ b/core/callable_bind.h @@ -0,0 +1,85 @@ +/*************************************************************************/ +/* callable_bind.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef CALLABLE_BIND_H +#define CALLABLE_BIND_H + +#include "core/callable.h" +#include "core/variant.h" + +class CallableCustomBind : public CallableCustom { + Callable callable; + Vector<Variant> binds; + + static bool _equal_func(const CallableCustom *p_a, const CallableCustom *p_b); + static bool _less_func(const CallableCustom *p_a, const CallableCustom *p_b); + +public: + //for every type that inherits, these must always be the same for this type + virtual uint32_t hash() const; + virtual String get_as_text() const; + virtual CompareEqualFunc get_compare_equal_func() const; + virtual CompareLessFunc get_compare_less_func() const; + virtual ObjectID get_object() const; //must always be able to provide an object + virtual void call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const; + virtual const Callable *get_base_comparator() const; + + CallableCustomBind(const Callable &p_callable, const Vector<Variant> &p_binds); + virtual ~CallableCustomBind(); +}; + +class CallableCustomUnbind : public CallableCustom { + Callable callable; + int argcount; + + static bool _equal_func(const CallableCustom *p_a, const CallableCustom *p_b); + static bool _less_func(const CallableCustom *p_a, const CallableCustom *p_b); + +public: + //for every type that inherits, these must always be the same for this type + virtual uint32_t hash() const; + virtual String get_as_text() const; + virtual CompareEqualFunc get_compare_equal_func() const; + virtual CompareLessFunc get_compare_less_func() const; + virtual ObjectID get_object() const; //must always be able to provide an object + virtual void call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const; + virtual const Callable *get_base_comparator() const; + + CallableCustomUnbind(const Callable &p_callable, int p_argcount); + virtual ~CallableCustomUnbind(); +}; + +Callable callable_bind(const Callable &p_callable, const Variant &p_arg1); +Callable callable_bind(const Callable &p_callable, const Variant &p_arg1, const Variant &p_arg2); +Callable callable_bind(const Callable &p_callable, const Variant &p_arg1, const Variant &p_arg2, const Variant &p_arg3); +Callable callable_bind(const Callable &p_callable, const Variant &p_arg1, const Variant &p_arg2, const Variant &p_arg3, const Variant &p_arg4); +Callable callable_bind(const Callable &p_callable, const Variant &p_arg1, const Variant &p_arg2, const Variant &p_arg3, const Variant &p_arg4, const Variant &p_arg5); + +#endif // CALLABLE_BIND_H diff --git a/core/callable_method_pointer.h b/core/callable_method_pointer.h index 1bb89e53e1..2007b9f338 100644 --- a/core/callable_method_pointer.h +++ b/core/callable_method_pointer.h @@ -31,6 +31,7 @@ #ifndef CALLABLE_METHOD_POINTER_H #define CALLABLE_METHOD_POINTER_H +#include "core/binder_common.h" #include "core/callable.h" #include "core/hashfuncs.h" #include "core/object.h" @@ -69,94 +70,6 @@ public: virtual uint32_t hash() const; }; -#ifdef DEBUG_METHODS_ENABLED - -template <class T> -struct VariantCasterAndValidate { - static _FORCE_INLINE_ T cast(const Variant **p_args, uint32_t p_arg_idx, Callable::CallError &r_error) { - Variant::Type argtype = GetTypeInfo<T>::VARIANT_TYPE; - if (!Variant::can_convert_strict(p_args[p_arg_idx]->get_type(), argtype)) { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; - r_error.argument = p_arg_idx; - r_error.expected = argtype; - } - - return VariantCaster<T>::cast(*p_args[p_arg_idx]); - } -}; - -template <class T> -struct VariantCasterAndValidate<T &> { - static _FORCE_INLINE_ T cast(const Variant **p_args, uint32_t p_arg_idx, Callable::CallError &r_error) { - Variant::Type argtype = GetTypeInfo<T>::VARIANT_TYPE; - if (!Variant::can_convert_strict(p_args[p_arg_idx]->get_type(), argtype)) { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; - r_error.argument = p_arg_idx; - r_error.expected = argtype; - } - - return VariantCaster<T>::cast(*p_args[p_arg_idx]); - } -}; - -template <class T> -struct VariantCasterAndValidate<const T &> { - static _FORCE_INLINE_ T cast(const Variant **p_args, uint32_t p_arg_idx, Callable::CallError &r_error) { - Variant::Type argtype = GetTypeInfo<T>::VARIANT_TYPE; - if (!Variant::can_convert_strict(p_args[p_arg_idx]->get_type(), argtype)) { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; - r_error.argument = p_arg_idx; - r_error.expected = argtype; - } - - return VariantCaster<T>::cast(*p_args[p_arg_idx]); - } -}; - -#endif // DEBUG_METHODS_ENABLED - -// GCC 8 raises "parameter 'p_args' set but not used" here, probably using a -// template version that does not have arguments and thus sees it unused, but -// obviously the template can be used for functions with and without them, and -// the optimizer will get rid of it anyway. -#if defined(DEBUG_METHODS_ENABLED) && defined(__GNUC__) && !defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wunused-but-set-parameter" -#endif - -template <class T, class... P, size_t... Is> -void call_with_variant_args_helper(T *p_instance, void (T::*p_method)(P...), const Variant **p_args, Callable::CallError &r_error, IndexSequence<Is...>) { - r_error.error = Callable::CallError::CALL_OK; - -#ifdef DEBUG_METHODS_ENABLED - (p_instance->*p_method)(VariantCasterAndValidate<P>::cast(p_args, Is, r_error)...); -#else - (p_instance->*p_method)(VariantCaster<P>::cast(*p_args[Is])...); -#endif -} - -#if defined(DEBUG_METHODS_ENABLED) && defined(__GNUC__) && !defined(__clang__) -#pragma GCC diagnostic pop -#endif - -template <class T, class... P> -void call_with_variant_args(T *p_instance, void (T::*p_method)(P...), const Variant **p_args, int p_argcount, Callable::CallError &r_error) { -#ifdef DEBUG_METHODS_ENABLED - if ((size_t)p_argcount > sizeof...(P)) { - r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS; - r_error.argument = sizeof...(P); - return; - } - - if ((size_t)p_argcount < sizeof...(P)) { - r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; - r_error.argument = sizeof...(P); - return; - } -#endif - call_with_variant_args_helper<T, P...>(p_instance, p_method, p_args, r_error, BuildIndexSequence<sizeof...(P)>{}); -} - template <class T, class... P> class CallableCustomMethodPointer : public CallableCustomMethodPointerBase { struct Data { @@ -212,57 +125,71 @@ Callable create_custom_callable_function_pointer(T *p_instance, // VERSION WITH RETURN -// GCC 8 raises "parameter 'p_args' set but not used" here, probably using a -// template version that does not have arguments and thus sees it unused, but -// obviously the template can be used for functions with and without them, and -// the optimizer will get rid of it anyway. -#if defined(DEBUG_METHODS_ENABLED) && defined(__GNUC__) && !defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wunused-but-set-parameter" +template <class T, class R, class... P> +class CallableCustomMethodPointerRet : public CallableCustomMethodPointerBase { + struct Data { + T *instance; +#ifdef DEBUG_ENABLED + uint64_t object_id; #endif + R(T::*method) + (P...); + } data; -template <class T, class R, class... P, size_t... Is> -void call_with_variant_args_ret_helper(T *p_instance, R (T::*p_method)(P...), const Variant **p_args, Variant &r_ret, Callable::CallError &r_error, IndexSequence<Is...>) { - r_error.error = Callable::CallError::CALL_OK; +public: + virtual ObjectID get_object() const { +#ifdef DEBUG_ENABLED + if (ObjectDB::get_instance(ObjectID(data.object_id)) == nullptr) { + return ObjectID(); + } +#endif + return data.instance->get_instance_id(); + } -#ifdef DEBUG_METHODS_ENABLED - r_ret = (p_instance->*p_method)(VariantCasterAndValidate<P>::cast(p_args, Is, r_error)...); -#else - (p_instance->*p_method)(VariantCaster<P>::cast(*p_args[Is])...); + virtual void call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const { +#ifdef DEBUG_ENABLED + ERR_FAIL_COND_MSG(ObjectDB::get_instance(ObjectID(data.object_id)) == nullptr, "Invalid Object id '" + uitos(data.object_id) + "', can't call method."); #endif -} + call_with_variant_args_ret(data.instance, data.method, p_arguments, p_argcount, r_return_value, r_call_error); + } -#if defined(DEBUG_METHODS_ENABLED) && defined(__GNUC__) && !defined(__clang__) -#pragma GCC diagnostic pop + CallableCustomMethodPointerRet(T *p_instance, R (T::*p_method)(P...)) { + zeromem(&data, sizeof(Data)); // Clear beforehand, may have padding bytes. + data.instance = p_instance; +#ifdef DEBUG_ENABLED + data.object_id = p_instance->get_instance_id(); #endif + data.method = p_method; + _setup((uint32_t *)&data, sizeof(Data)); + } +}; template <class T, class R, class... P> -void call_with_variant_args_ret(T *p_instance, R (T::*p_method)(P...), const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) { +Callable create_custom_callable_function_pointer(T *p_instance, #ifdef DEBUG_METHODS_ENABLED - if ((size_t)p_argcount > sizeof...(P)) { - r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS; - r_error.argument = sizeof...(P); - return; - } + const char *p_func_text, +#endif + R (T::*p_method)(P...)) { - if ((size_t)p_argcount < sizeof...(P)) { - r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; - r_error.argument = sizeof...(P); - return; - } + typedef CallableCustomMethodPointerRet<T, R, P...> CCMP; // Messes with memnew otherwise. + CCMP *ccmp = memnew(CCMP(p_instance, p_method)); +#ifdef DEBUG_METHODS_ENABLED + ccmp->set_text(p_func_text + 1); // Try to get rid of the ampersand. #endif - call_with_variant_args_ret_helper<T, R, P...>(p_instance, p_method, p_args, r_ret, r_error, BuildIndexSequence<sizeof...(P)>{}); + return Callable(ccmp); } +// CONST VERSION WITH RETURN + template <class T, class R, class... P> -class CallableCustomMethodPointerRet : public CallableCustomMethodPointerBase { +class CallableCustomMethodPointerRetC : public CallableCustomMethodPointerBase { struct Data { T *instance; #ifdef DEBUG_ENABLED uint64_t object_id; #endif R(T::*method) - (P...); + (P...) const; } data; public: @@ -279,10 +206,10 @@ public: #ifdef DEBUG_ENABLED ERR_FAIL_COND_MSG(ObjectDB::get_instance(ObjectID(data.object_id)) == nullptr, "Invalid Object id '" + uitos(data.object_id) + "', can't call method."); #endif - call_with_variant_args_ret(data.instance, data.method, p_arguments, p_argcount, r_return_value, r_call_error); + call_with_variant_args_retc(data.instance, data.method, p_arguments, p_argcount, r_return_value, r_call_error); } - CallableCustomMethodPointerRet(T *p_instance, R (T::*p_method)(P...)) { + CallableCustomMethodPointerRetC(T *p_instance, R (T::*p_method)(P...) const) { zeromem(&data, sizeof(Data)); // Clear beforehand, may have padding bytes. data.instance = p_instance; #ifdef DEBUG_ENABLED @@ -298,9 +225,9 @@ Callable create_custom_callable_function_pointer(T *p_instance, #ifdef DEBUG_METHODS_ENABLED const char *p_func_text, #endif - R (T::*p_method)(P...)) { + R (T::*p_method)(P...) const) { - typedef CallableCustomMethodPointerRet<T, R, P...> CCMP; // Messes with memnew otherwise. + typedef CallableCustomMethodPointerRetC<T, R, P...> CCMP; // Messes with memnew otherwise. CCMP *ccmp = memnew(CCMP(p_instance, p_method)); #ifdef DEBUG_METHODS_ENABLED ccmp->set_text(p_func_text + 1); // Try to get rid of the ampersand. diff --git a/core/class_db.cpp b/core/class_db.cpp index 88f1df3457..81bc901561 100644 --- a/core/class_db.cpp +++ b/core/class_db.cpp @@ -242,21 +242,25 @@ HashMap<StringName, ClassDB::ClassInfo> ClassDB::classes; HashMap<StringName, StringName> ClassDB::resource_base_extensions; HashMap<StringName, StringName> ClassDB::compat_classes; -bool ClassDB::is_parent_class(const StringName &p_class, const StringName &p_inherits) { - OBJTYPE_RLOCK; - +bool ClassDB::_is_parent_class(const StringName &p_class, const StringName &p_inherits) { StringName inherits = p_class; while (inherits.operator String().length()) { if (inherits == p_inherits) { return true; } - inherits = get_parent_class(inherits); + inherits = _get_parent_class(inherits); } return false; } +bool ClassDB::is_parent_class(const StringName &p_class, const StringName &p_inherits) { + OBJTYPE_RLOCK; + + return _is_parent_class(p_class, p_inherits); +} + void ClassDB::get_class_list(List<StringName> *p_classes) { OBJTYPE_RLOCK; @@ -275,7 +279,7 @@ void ClassDB::get_inheriters_from_class(const StringName &p_class, List<StringNa const StringName *k = nullptr; while ((k = classes.next(k))) { - if (*k != p_class && is_parent_class(*k, p_class)) { + if (*k != p_class && _is_parent_class(*k, p_class)) { p_classes->push_back(*k); } } @@ -287,7 +291,7 @@ void ClassDB::get_direct_inheriters_from_class(const StringName &p_class, List<S const StringName *k = nullptr; while ((k = classes.next(k))) { - if (*k != p_class && get_parent_class(*k) == p_class) { + if (*k != p_class && _get_parent_class(*k) == p_class) { p_classes->push_back(*k); } } @@ -315,14 +319,18 @@ StringName ClassDB::get_compatibility_remapped_class(const StringName &p_class) return p_class; } -StringName ClassDB::get_parent_class(const StringName &p_class) { - OBJTYPE_RLOCK; - +StringName ClassDB::_get_parent_class(const StringName &p_class) { ClassInfo *ti = classes.getptr(p_class); ERR_FAIL_COND_V_MSG(!ti, StringName(), "Cannot get class '" + String(p_class) + "'."); return ti->inherits; } +StringName ClassDB::get_parent_class(const StringName &p_class) { + OBJTYPE_RLOCK; + + return _get_parent_class(p_class); +} + ClassDB::APIType ClassDB::get_api_type(const StringName &p_class) { OBJTYPE_RLOCK; @@ -1343,7 +1351,7 @@ MethodBind *ClassDB::bind_methodfi(uint32_t p_flags, MethodBind *p_bind, const c defvals.resize(p_defcount); for (int i = 0; i < p_defcount; i++) { - defvals.write[i] = *p_defs[p_defcount - i - 1]; + defvals.write[i] = *p_defs[i]; } p_bind->set_default_arguments(defvals); diff --git a/core/class_db.h b/core/class_db.h index 86ac2aa001..22072066d9 100644 --- a/core/class_db.h +++ b/core/class_db.h @@ -36,7 +36,7 @@ #include "core/print_string.h" /** To bind more then 6 parameters include this: - * #include "core/method_bind_ext.gen.inc" + * */ // Makes callable_mp readily available in all classes connecting signals. @@ -164,6 +164,11 @@ public: static HashMap<StringName, HashMap<StringName, Variant>> default_values; static Set<StringName> default_values_cached; +private: + // Non-locking variants of get_parent_class and is_parent_class. + static StringName _get_parent_class(const StringName &p_class); + static bool _is_parent_class(const StringName &p_class, const StringName &p_inherits); + public: // DO NOT USE THIS!!!!!! NEEDS TO BE PUBLIC BUT DO NOT USE NO MATTER WHAT!!! template <class T> diff --git a/core/command_queue_mt.cpp b/core/command_queue_mt.cpp index ace210ca2c..a55eed5d3c 100644 --- a/core/command_queue_mt.cpp +++ b/core/command_queue_mt.cpp @@ -31,6 +31,7 @@ #include "command_queue_mt.h" #include "core/os/os.h" +#include "core/project_settings.h" void CommandQueueMT::lock() { mutex.lock(); @@ -71,7 +72,7 @@ CommandQueueMT::SyncSemaphore *CommandQueueMT::_alloc_sync_sem() { bool CommandQueueMT::dealloc_one() { tryagain: - if (dealloc_ptr == write_ptr) { + if (dealloc_ptr == (write_ptr_and_epoch >> 1)) { // The queue is empty return false; } @@ -94,6 +95,10 @@ tryagain: } CommandQueueMT::CommandQueueMT(bool p_sync) { + command_mem_size = GLOBAL_DEF_RST("memory/limits/command_queue/multithreading_queue_size_kb", DEFAULT_COMMAND_MEM_SIZE_KB); + ProjectSettings::get_singleton()->set_custom_property_info("memory/limits/command_queue/multithreading_queue_size_kb", PropertyInfo(Variant::INT, "memory/limits/command_queue/multithreading_queue_size_kb", PROPERTY_HINT_RANGE, "1,4096,1,or_greater")); + command_mem_size *= 1024; + command_mem = (uint8_t *)memalloc(command_mem_size); if (p_sync) { sync = memnew(Semaphore); } diff --git a/core/command_queue_mt.h b/core/command_queue_mt.h index d7a6a5bc43..0e5bc7f369 100644 --- a/core/command_queue_mt.h +++ b/core/command_queue_mt.h @@ -330,15 +330,15 @@ class CommandQueueMT { /***** BASE *******/ enum { - COMMAND_MEM_SIZE_KB = 256, - COMMAND_MEM_SIZE = COMMAND_MEM_SIZE_KB * 1024, + DEFAULT_COMMAND_MEM_SIZE_KB = 256, SYNC_SEMAPHORES = 8 }; - uint8_t *command_mem = (uint8_t *)memalloc(COMMAND_MEM_SIZE); - uint32_t read_ptr = 0; - uint32_t write_ptr = 0; + uint8_t *command_mem = nullptr; + uint32_t read_ptr_and_epoch = 0; + uint32_t write_ptr_and_epoch = 0; uint32_t dealloc_ptr = 0; + uint32_t command_mem_size = 0; SyncSemaphore sync_sems[SYNC_SEMAPHORES]; Mutex mutex; Semaphore *sync = nullptr; @@ -348,7 +348,11 @@ class CommandQueueMT { // alloc size is size+T+safeguard uint32_t alloc_size = ((sizeof(T) + 8 - 1) & ~(8 - 1)) + 8; + // Assert that the buffer is big enough to hold at least two messages. + ERR_FAIL_COND_V(alloc_size * 2 + sizeof(uint32_t) > command_mem_size, nullptr); + tryagain: + uint32_t write_ptr = write_ptr_and_epoch >> 1; if (write_ptr < dealloc_ptr) { // behind dealloc_ptr, check that there is room @@ -362,7 +366,7 @@ class CommandQueueMT { } else { // ahead of dealloc_ptr, check that there is room - if ((COMMAND_MEM_SIZE - write_ptr) < alloc_size + sizeof(uint32_t)) { + if ((command_mem_size - write_ptr) < alloc_size + sizeof(uint32_t)) { // no room at the end, wrap down; if (dealloc_ptr == 0) { // don't want write_ptr to become dealloc_ptr @@ -375,12 +379,17 @@ class CommandQueueMT { } // if this happens, it's a bug - ERR_FAIL_COND_V((COMMAND_MEM_SIZE - write_ptr) < 8, nullptr); + ERR_FAIL_COND_V((command_mem_size - write_ptr) < 8, nullptr); // zero means, wrap to beginning uint32_t *p = (uint32_t *)&command_mem[write_ptr]; - *p = 0; - write_ptr = 0; + *p = 1; + write_ptr_and_epoch = 0 | (1 & ~write_ptr_and_epoch); // Invert epoch. + // See if we can get the thread to run and clear up some more space while we wait. + // This is required if alloc_size * 2 + 4 > COMMAND_MEM_SIZE + if (sync) { + sync->post(); + } goto tryagain; } } @@ -394,6 +403,7 @@ class CommandQueueMT { // allocate the command T *cmd = memnew_placement(&command_mem[write_ptr], T); write_ptr += size; + write_ptr_and_epoch = (write_ptr << 1) | (write_ptr_and_epoch & 1); return cmd; } @@ -419,19 +429,21 @@ class CommandQueueMT { tryagain: // tried to read an empty queue - if (read_ptr == write_ptr) { + if (read_ptr_and_epoch == write_ptr_and_epoch) { if (p_lock) { unlock(); } return false; } + uint32_t read_ptr = read_ptr_and_epoch >> 1; uint32_t size_ptr = read_ptr; uint32_t size = *(uint32_t *)&command_mem[read_ptr] >> 1; if (size == 0) { + *(uint32_t *)&command_mem[read_ptr] = 0; // clear in-use bit. //end of ringbuffer, wrap - read_ptr = 0; + read_ptr_and_epoch = 0 | (1 & ~read_ptr_and_epoch); // Invert epoch. goto tryagain; } @@ -441,6 +453,8 @@ class CommandQueueMT { read_ptr += size; + read_ptr_and_epoch = (read_ptr << 1) | (read_ptr_and_epoch & 1); + if (p_lock) { unlock(); } diff --git a/core/core_string_names.cpp b/core/core_string_names.cpp index 1d3b333efc..6f86f107e6 100644 --- a/core/core_string_names.cpp +++ b/core/core_string_names.cpp @@ -73,6 +73,8 @@ CoreStringNames::CoreStringNames() : a8(StaticCString::create("a8")), call(StaticCString::create("call")), call_deferred(StaticCString::create("call_deferred")), + bind(StaticCString::create("bind")), + unbind(StaticCString::create("unbind")), emit(StaticCString::create("emit")), notification(StaticCString::create("notification")) { } diff --git a/core/core_string_names.h b/core/core_string_names.h index 1a18c84572..43597ef301 100644 --- a/core/core_string_names.h +++ b/core/core_string_names.h @@ -92,6 +92,8 @@ public: StringName call; StringName call_deferred; + StringName bind; + StringName unbind; StringName emit; StringName notification; }; diff --git a/core/debugger/remote_debugger.h b/core/debugger/remote_debugger.h index dc7e4436e1..320ee15996 100644 --- a/core/debugger/remote_debugger.h +++ b/core/debugger/remote_debugger.h @@ -32,10 +32,10 @@ #define REMOTE_DEBUGGER_H #include "core/array.h" +#include "core/class_db.h" #include "core/debugger/debugger_marshalls.h" #include "core/debugger/engine_debugger.h" #include "core/debugger/remote_debugger_peer.h" -#include "core/object.h" #include "core/string_name.h" #include "core/ustring.h" diff --git a/core/engine.cpp b/core/engine.cpp index d08cf92ecb..b0037ffb37 100644 --- a/core/engine.cpp +++ b/core/engine.cpp @@ -181,6 +181,14 @@ String Engine::get_license_text() const { return String(GODOT_LICENSE_TEXT); } +bool Engine::is_abort_on_gpu_errors_enabled() const { + return abort_on_gpu_errors; +} + +bool Engine::is_validation_layers_enabled() const { + return use_validation_layers; +} + void Engine::add_singleton(const Singleton &p_singleton) { singletons.push_back(p_singleton); singleton_ptrs[p_singleton.name] = p_singleton.ptr; @@ -208,10 +216,6 @@ Engine *Engine::get_singleton() { return singleton; } -bool Engine::is_abort_on_gpu_errors_enabled() const { - return abort_on_gpu_errors; -} - Engine::Engine() { singleton = this; } diff --git a/core/engine.h b/core/engine.h index fef330c0c1..b581c58ec5 100644 --- a/core/engine.h +++ b/core/engine.h @@ -60,10 +60,10 @@ private: float _fps = 1; int _target_fps = 0; float _time_scale = 1.0; - bool _pixel_snap = false; uint64_t _physics_frames = 0; float _physics_interpolation_fraction = 0.0f; bool abort_on_gpu_errors = false; + bool use_validation_layers = false; uint64_t _idle_frames = 0; bool _in_physics = false; @@ -109,8 +109,6 @@ public: bool has_singleton(const String &p_name) const; Object *get_singleton_object(const String &p_name) const; - _FORCE_INLINE_ bool get_use_pixel_snap() const { return _pixel_snap; } - #ifdef TOOLS_ENABLED _FORCE_INLINE_ void set_editor_hint(bool p_enabled) { editor_hint = p_enabled; } _FORCE_INLINE_ bool is_editor_hint() const { return editor_hint; } @@ -127,6 +125,7 @@ public: String get_license_text() const; bool is_abort_on_gpu_errors_enabled() const; + bool is_validation_layers_enabled() const; Engine(); virtual ~Engine() {} diff --git a/core/global_constants.cpp b/core/global_constants.cpp index b30685539a..064c302341 100644 --- a/core/global_constants.cpp +++ b/core/global_constants.cpp @@ -30,8 +30,8 @@ #include "global_constants.h" +#include "core/class_db.h" #include "core/input/input_event.h" -#include "core/object.h" #include "core/os/keyboard.h" #include "core/variant.h" diff --git a/core/input/gamecontrollerdb.txt b/core/input/gamecontrollerdb.txt index 2a3cb23202..180708cea6 100644 --- a/core/input/gamecontrollerdb.txt +++ b/core/input/gamecontrollerdb.txt @@ -338,7 +338,7 @@ xinput,XInput Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2, 03000000120c0000101e000000000000,ZEROPLUS P4 Wired Gamepad,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,platform:Windows, # Mac OS X -030000008f0e00000300000009010000,2In1 USB Joystick,+leftx:h0.2,+lefty:h0.4,-leftx:h0.8,-lefty:h0.1,a:b2,b:b1,back:b8,dpdown:+a1,dpleft:-a0,dpright:+a0,dpup:-a1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b3,y:b0,platform:Mac OS X, +030000008f0e00000300000009010000,2In1 USB Joystick,a:b2,b:b1,x:b3,y:b0,back:b8,start:b9,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,platform:Mac OS X, 03000000c82d00000090000001000000,8BitDo FC30 Pro,a:b1,b:b0,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b6,leftstick:b13,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:a5,rightx:a2,righty:a3,start:b11,x:b4,y:b3,platform:Mac OS X, 03000000c82d00001038000000010000,8BitDo FC30 Pro,a:b1,b:b0,back:b10,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b6,leftstick:b13,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b14,righttrigger:a4,rightx:a2,righty:a3,start:b11,x:b4,y:b3,platform:Mac OS X, 03000000c82d00000650000001000000,8BitDo M30,a:b0,b:b1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b8,lefttrigger:b9,leftx:a0,lefty:a1,rightshoulder:b6,righttrigger:b7,start:b11,x:b3,y:b4,platform:Mac OS X, diff --git a/core/input/input.cpp b/core/input/input.cpp index 4d152c1ac4..b0b1d20222 100644 --- a/core/input/input.cpp +++ b/core/input/input.cpp @@ -874,7 +874,7 @@ void Input::joy_button(int p_device, int p_button, bool p_pressed) { } if (map.type == TYPE_AXIS) { - _axis_event(p_device, map.index, p_pressed ? 1.0 : 0.0); + _axis_event(p_device, map.index, p_pressed ? map.value : 0.0); } // no event? } @@ -920,55 +920,42 @@ void Input::joy_axis(int p_device, int p_axis, const JoyAxis &p_value) { return; } - JoyEvent map = _get_mapped_axis_event(map_db[joy.mapping], p_axis, p_value); + JoyEvent map = _get_mapped_axis_event(map_db[joy.mapping], p_axis, val); if (map.type == TYPE_BUTTON) { - if (map.index == JOY_BUTTON_DPAD_UP || map.index == JOY_BUTTON_DPAD_DOWN) { - bool pressed = p_value.value != 0.0f; - int button = p_value.value < 0 ? JOY_BUTTON_DPAD_UP : JOY_BUTTON_DPAD_DOWN; + bool pressed = map.value > 0.5; + if (pressed == joy_buttons_pressed.has(_combine_device(map.index, p_device))) { + // Button already pressed or released; so ignore. + return; + } + _button_event(p_device, map.index, pressed); - if (!pressed) { - if (joy_buttons_pressed.has(_combine_device(JOY_BUTTON_DPAD_UP, p_device))) { - _button_event(p_device, JOY_BUTTON_DPAD_UP, false); - } + // Ensure opposite D-Pad button is also released. + switch (map.index) { + case JOY_BUTTON_DPAD_UP: if (joy_buttons_pressed.has(_combine_device(JOY_BUTTON_DPAD_DOWN, p_device))) { _button_event(p_device, JOY_BUTTON_DPAD_DOWN, false); } - } - if (pressed == joy_buttons_pressed.has(_combine_device(button, p_device))) { - return; - } - _button_event(p_device, button, true); - return; - } - - if (map.index == JOY_BUTTON_DPAD_LEFT || map.index == JOY_BUTTON_DPAD_RIGHT) { - bool pressed = p_value.value != 0.0f; - int button = p_value.value < 0 ? JOY_BUTTON_DPAD_LEFT : JOY_BUTTON_DPAD_RIGHT; - - if (!pressed) { - if (joy_buttons_pressed.has(_combine_device(JOY_BUTTON_DPAD_LEFT, p_device))) { - _button_event(p_device, JOY_BUTTON_DPAD_LEFT, false); + break; + case JOY_BUTTON_DPAD_DOWN: + if (joy_buttons_pressed.has(_combine_device(JOY_BUTTON_DPAD_UP, p_device))) { + _button_event(p_device, JOY_BUTTON_DPAD_UP, false); } + break; + case JOY_BUTTON_DPAD_LEFT: if (joy_buttons_pressed.has(_combine_device(JOY_BUTTON_DPAD_RIGHT, p_device))) { _button_event(p_device, JOY_BUTTON_DPAD_RIGHT, false); } - } - if (pressed == joy_buttons_pressed.has(_combine_device(button, p_device))) { - return; - } - _button_event(p_device, button, true); - return; - } - - float deadzone = p_value.min == 0 ? 0.5f : 0.0f; - bool pressed = p_value.value > deadzone; - if (pressed == joy_buttons_pressed.has(_combine_device(map.index, p_device))) { - // button already pressed or released, this is an axis bounce value - return; + break; + case JOY_BUTTON_DPAD_RIGHT: + if (joy_buttons_pressed.has(_combine_device(JOY_BUTTON_DPAD_LEFT, p_device))) { + _button_event(p_device, JOY_BUTTON_DPAD_LEFT, false); + } + break; + default: + // Nothing to do. + break; } - - _button_event(p_device, map.index, pressed); return; } @@ -1007,18 +994,15 @@ void Input::joy_hat(int p_device, int p_val) { int cur_val = joy_names[p_device].hat_current; - if ((p_val & HAT_MASK_UP) != (cur_val & HAT_MASK_UP)) { - _button_event(p_device, map[HAT_UP].index, p_val & HAT_MASK_UP); - } - - if ((p_val & HAT_MASK_RIGHT) != (cur_val & HAT_MASK_RIGHT)) { - _button_event(p_device, map[HAT_RIGHT].index, p_val & HAT_MASK_RIGHT); - } - if ((p_val & HAT_MASK_DOWN) != (cur_val & HAT_MASK_DOWN)) { - _button_event(p_device, map[HAT_DOWN].index, p_val & HAT_MASK_DOWN); - } - if ((p_val & HAT_MASK_LEFT) != (cur_val & HAT_MASK_LEFT)) { - _button_event(p_device, map[HAT_LEFT].index, p_val & HAT_MASK_LEFT); + for (int hat_direction = 0, hat_mask = 1; hat_direction < HAT_MAX; hat_direction++, hat_mask <<= 1) { + if ((p_val & hat_mask) != (cur_val & hat_mask)) { + if (map[hat_direction].type == TYPE_BUTTON) { + _button_event(p_device, map[hat_direction].index, p_val & hat_mask); + } + if (map[hat_direction].type == TYPE_AXIS) { + _axis_event(p_device, map[hat_direction].index, (p_val & hat_mask) ? map[hat_direction].value : 0.0); + } + } } joy_names[p_device].hat_current = p_val; @@ -1058,6 +1042,19 @@ Input::JoyEvent Input::_get_mapped_button_event(const JoyDeviceMapping &mapping, return event; case TYPE_AXIS: event.index = binding.output.axis.axis; + switch (binding.output.axis.range) { + case POSITIVE_HALF_AXIS: + event.value = 1; + break; + case NEGATIVE_HALF_AXIS: + event.value = -1; + break; + case FULL_AXIS: + // It doesn't make sense for a button to map to a full axis, + // but keeping as a default for a trigger with a positive half-axis. + event.value = 1; + break; + } return event; default: ERR_PRINT_ONCE("Joypad button mapping error."); @@ -1067,14 +1064,14 @@ Input::JoyEvent Input::_get_mapped_button_event(const JoyDeviceMapping &mapping, return event; } -Input::JoyEvent Input::_get_mapped_axis_event(const JoyDeviceMapping &mapping, int p_axis, const JoyAxis &p_value) { +Input::JoyEvent Input::_get_mapped_axis_event(const JoyDeviceMapping &mapping, int p_axis, float p_value) { JoyEvent event; event.type = TYPE_MAX; for (int i = 0; i < mapping.bindings.size(); i++) { const JoyBinding binding = mapping.bindings[i]; if (binding.inputType == TYPE_AXIS && binding.input.axis.axis == p_axis) { - float value = p_value.value; + float value = p_value; if (binding.input.axis.invert) { value = -value; } @@ -1082,26 +1079,40 @@ Input::JoyEvent Input::_get_mapped_axis_event(const JoyDeviceMapping &mapping, i (binding.input.axis.range == POSITIVE_HALF_AXIS && value > 0) || (binding.input.axis.range == NEGATIVE_HALF_AXIS && value < 0)) { event.type = binding.outputType; + float shifted_positive_value = 0; + switch (binding.input.axis.range) { + case POSITIVE_HALF_AXIS: + shifted_positive_value = value; + break; + case NEGATIVE_HALF_AXIS: + shifted_positive_value = value + 1; + break; + case FULL_AXIS: + shifted_positive_value = (value + 1) / 2; + break; + } switch (binding.outputType) { case TYPE_BUTTON: event.index = binding.output.button; + switch (binding.input.axis.range) { + case POSITIVE_HALF_AXIS: + event.value = shifted_positive_value; + break; + case NEGATIVE_HALF_AXIS: + event.value = 1 - shifted_positive_value; + break; + case FULL_AXIS: + // It doesn't make sense for a full axis to map to a button, + // but keeping as a default for a trigger with a positive half-axis. + event.value = (shifted_positive_value * 2) - 1; + ; + break; + } return event; case TYPE_AXIS: event.index = binding.output.axis.axis; event.value = value; if (binding.output.axis.range != binding.input.axis.range) { - float shifted_positive_value = 0; - switch (binding.input.axis.range) { - case POSITIVE_HALF_AXIS: - shifted_positive_value = value; - break; - case NEGATIVE_HALF_AXIS: - shifted_positive_value = value + 1; - break; - case FULL_AXIS: - shifted_positive_value = (value + 1) / 2; - break; - } switch (binding.output.axis.range) { case POSITIVE_HALF_AXIS: event.value = shifted_positive_value; @@ -1128,32 +1139,45 @@ void Input::_get_mapped_hat_events(const JoyDeviceMapping &mapping, int p_hat, J for (int i = 0; i < mapping.bindings.size(); i++) { const JoyBinding binding = mapping.bindings[i]; if (binding.inputType == TYPE_HAT && binding.input.hat.hat == p_hat) { - int index; + int hat_direction; switch (binding.input.hat.hat_mask) { case HAT_MASK_UP: - index = 0; + hat_direction = HAT_UP; break; case HAT_MASK_RIGHT: - index = 1; + hat_direction = HAT_RIGHT; break; case HAT_MASK_DOWN: - index = 2; + hat_direction = HAT_DOWN; break; case HAT_MASK_LEFT: - index = 3; + hat_direction = HAT_LEFT; break; default: ERR_PRINT_ONCE("Joypad button mapping error."); continue; } - r_events[index].type = binding.outputType; + r_events[hat_direction].type = binding.outputType; switch (binding.outputType) { case TYPE_BUTTON: - r_events[index].index = binding.output.button; + r_events[hat_direction].index = binding.output.button; break; case TYPE_AXIS: - r_events[index].index = binding.output.axis.axis; + r_events[hat_direction].index = binding.output.axis.axis; + switch (binding.output.axis.range) { + case POSITIVE_HALF_AXIS: + r_events[hat_direction].value = 1; + break; + case NEGATIVE_HALF_AXIS: + r_events[hat_direction].value = -1; + break; + case FULL_AXIS: + // It doesn't make sense for a hat direction to map to a full axis, + // but keeping as a default for a trigger with a positive half-axis. + r_events[hat_direction].value = 1; + break; + } break; default: ERR_PRINT_ONCE("Joypad button mapping error."); @@ -1213,12 +1237,12 @@ void Input::parse_mapping(String p_mapping) { JoyAxisRange output_range = FULL_AXIS; if (output[0] == '+' || output[0] == '-') { ERR_CONTINUE_MSG(output.length() < 2, String(entry[idx] + "\nInvalid output: " + entry[idx])); - output = output.right(1); if (output[0] == '+') { output_range = POSITIVE_HALF_AXIS; } else if (output[0] == '-') { output_range = NEGATIVE_HALF_AXIS; } + output = output.right(1); } JoyAxisRange input_range = FULL_AXIS; @@ -1232,6 +1256,7 @@ void Input::parse_mapping(String p_mapping) { bool invert_axis = false; if (input[input.length() - 1] == '~') { invert_axis = true; + input = input.left(input.length() - 1); } JoyButtonList output_button = _get_output_button(output); diff --git a/core/input/input.h b/core/input/input.h index 775663503b..60e378d72c 100644 --- a/core/input/input.h +++ b/core/input/input.h @@ -217,7 +217,7 @@ private: Vector<JoyDeviceMapping> map_db; JoyEvent _get_mapped_button_event(const JoyDeviceMapping &mapping, int p_button); - JoyEvent _get_mapped_axis_event(const JoyDeviceMapping &mapping, int p_axis, const JoyAxis &p_value); + JoyEvent _get_mapped_axis_event(const JoyDeviceMapping &mapping, int p_axis, float p_value); void _get_mapped_hat_events(const JoyDeviceMapping &mapping, int p_hat, JoyEvent r_events[HAT_MAX]); JoyButtonList _get_output_button(String output); JoyAxisList _get_output_axis(String output); diff --git a/core/input/input_map.h b/core/input/input_map.h index 548553ed31..755df26984 100644 --- a/core/input/input_map.h +++ b/core/input/input_map.h @@ -31,8 +31,8 @@ #ifndef INPUT_MAP_H #define INPUT_MAP_H +#include "core/class_db.h" #include "core/input/input_event.h" -#include "core/object.h" class InputMap : public Object { GDCLASS(InputMap, Object); diff --git a/core/io/http_client.cpp b/core/io/http_client.cpp index 46e45500bf..a25413b21b 100644 --- a/core/io/http_client.cpp +++ b/core/io/http_client.cpp @@ -96,6 +96,10 @@ Error HTTPClient::connect_to_host(const String &p_host, int p_port, bool p_ssl, void HTTPClient::set_connection(const Ref<StreamPeer> &p_connection) { ERR_FAIL_COND_MSG(p_connection.is_null(), "Connection is not a reference to a valid StreamPeer object."); + if (connection == p_connection) { + return; + } + close(); connection = p_connection; status = STATUS_CONNECTED; diff --git a/core/io/packet_peer.h b/core/io/packet_peer.h index 92cdbc4151..fb4dc181db 100644 --- a/core/io/packet_peer.h +++ b/core/io/packet_peer.h @@ -31,8 +31,8 @@ #ifndef PACKET_PEER_H #define PACKET_PEER_H +#include "core/class_db.h" #include "core/io/stream_peer.h" -#include "core/object.h" #include "core/ring_buffer.h" class PacketPeer : public Reference { diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index 5097f6d98b..21de7835ce 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -863,7 +863,8 @@ void ResourceLoaderBinary::open(FileAccess *p_f) { if (ver_format > FORMAT_VERSION || ver_major > VERSION_MAJOR) { f->close(); - ERR_FAIL_MSG("File format '" + itos(FORMAT_VERSION) + "." + itos(ver_major) + "." + itos(ver_minor) + "' is too new! Please upgrade to a new engine version: " + local_path + "."); + ERR_FAIL_MSG(vformat("File '%s' can't be loaded, as it uses a format version (%d) or engine version (%d.%d) which are not supported by your engine version (%s).", + local_path, ver_format, ver_major, ver_minor, VERSION_BRANCH)); } type = get_unicode_string(); @@ -1136,7 +1137,9 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons if (ver_format > FORMAT_VERSION || ver_major > VERSION_MAJOR) { memdelete(f); memdelete(fw); - ERR_FAIL_V_MSG(ERR_FILE_UNRECOGNIZED, "File format '" + itos(FORMAT_VERSION) + "." + itos(ver_major) + "." + itos(ver_minor) + "' is too new! Please upgrade to a new engine version: " + local_path + "."); + ERR_FAIL_V_MSG(ERR_FILE_UNRECOGNIZED, + vformat("File '%s' can't be loaded, as it uses a format version (%d) or engine version (%d.%d) which are not supported by your engine version (%s).", + local_path, ver_format, ver_major, ver_minor, VERSION_BRANCH)); } // Since we're not actually converting the file contents, leave the version diff --git a/core/make_binders.py b/core/make_binders.py deleted file mode 100644 index 7d0d08cde6..0000000000 --- a/core/make_binders.py +++ /dev/null @@ -1,390 +0,0 @@ -# -*- coding: ibm850 -*- - -template_typed = """ -#ifdef TYPED_METHOD_BIND -template<class T $ifret ,class R$ $ifargs ,$ $arg, class P@$> -class MethodBind$argc$$ifret R$$ifconst C$ : public MethodBind { -public: - - $ifret R$ $ifnoret void$ (T::*method)($arg, P@$) $ifconst const$; -#ifdef DEBUG_METHODS_ENABLED - virtual Variant::Type _gen_argument_type(int p_arg) const { return _get_argument_type(p_arg); } - virtual GodotTypeInfo::Metadata get_argument_meta(int p_arg) const { - $ifret if (p_arg==-1) return GetTypeInfo<R>::METADATA;$ - $arg if (p_arg==(@-1)) return GetTypeInfo<P@>::METADATA; - $ - return GodotTypeInfo::METADATA_NONE; - } - Variant::Type _get_argument_type(int p_argument) const { - $ifret if (p_argument==-1) return (Variant::Type)GetTypeInfo<R>::VARIANT_TYPE;$ - $arg if (p_argument==(@-1)) return (Variant::Type)GetTypeInfo<P@>::VARIANT_TYPE; - $ - return Variant::NIL; - } - virtual PropertyInfo _gen_argument_type_info(int p_argument) const { - $ifret if (p_argument==-1) return GetTypeInfo<R>::get_class_info();$ - $arg if (p_argument==(@-1)) return GetTypeInfo<P@>::get_class_info(); - $ - return PropertyInfo(); - } -#endif - virtual String get_instance_class() const { - return T::get_class_static(); - } - - virtual Variant call(Object* p_object,const Variant** p_args,int p_arg_count, Callable::CallError& r_error) { - - T *instance=Object::cast_to<T>(p_object); - r_error.error=Callable::CallError::CALL_OK; -#ifdef DEBUG_METHODS_ENABLED - - ERR_FAIL_COND_V(!instance,Variant()); - if (p_arg_count>get_argument_count()) { - r_error.error=Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS; - r_error.argument=get_argument_count(); - return Variant(); - - } - if (p_arg_count<(get_argument_count()-get_default_argument_count())) { - - r_error.error=Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; - r_error.argument=get_argument_count()-get_default_argument_count(); - return Variant(); - } - $arg CHECK_ARG(@); - $ -#endif - $ifret Variant ret = $(instance->*method)($arg, _VC(@)$); - $ifret return Variant(ret);$ - $ifnoret return Variant();$ - } - -#ifdef PTRCALL_ENABLED - virtual void ptrcall(Object*p_object,const void** p_args,void *r_ret) { - - T *instance=Object::cast_to<T>(p_object); - $ifret PtrToArg<R>::encode( $ (instance->*method)($arg, PtrToArg<P@>::convert(p_args[@-1])$) $ifret ,r_ret)$ ; - } -#endif - MethodBind$argc$$ifret R$$ifconst C$ () { -#ifdef DEBUG_METHODS_ENABLED - _set_const($ifconst true$$ifnoconst false$); - _generate_argument_types($argc$); -#else - set_argument_count($argc$); -#endif - - $ifret _set_returns(true); $ - } -}; - -template<class T $ifret ,class R$ $ifargs ,$ $arg, class P@$> -MethodBind* create_method_bind($ifret R$ $ifnoret void$ (T::*p_method)($arg, P@$) $ifconst const$ ) { - - MethodBind$argc$$ifret R$$ifconst C$<T $ifret ,R$ $ifargs ,$ $arg, P@$> * a = memnew( (MethodBind$argc$$ifret R$$ifconst C$<T $ifret ,R$ $ifargs ,$ $arg, P@$>) ); - a->method=p_method; - return a; -} -#endif -""" - -template = """ -#ifndef TYPED_METHOD_BIND -$iftempl template<$ $ifret class R$ $ifretargs ,$ $arg, class P@$ $iftempl >$ -class MethodBind$argc$$ifret R$$ifconst C$ : public MethodBind { - -public: - - StringName type_name; - $ifret R$ $ifnoret void$ (__UnexistingClass::*method)($arg, P@$) $ifconst const$; - -#ifdef DEBUG_METHODS_ENABLED - virtual Variant::Type _gen_argument_type(int p_arg) const { return _get_argument_type(p_arg); } - virtual GodotTypeInfo::Metadata get_argument_meta(int p_arg) const { - $ifret if (p_arg==-1) return GetTypeInfo<R>::METADATA;$ - $arg if (p_arg==(@-1)) return GetTypeInfo<P@>::METADATA; - $ - return GodotTypeInfo::METADATA_NONE; - } - - Variant::Type _get_argument_type(int p_argument) const { - $ifret if (p_argument==-1) return (Variant::Type)GetTypeInfo<R>::VARIANT_TYPE;$ - $arg if (p_argument==(@-1)) return (Variant::Type)GetTypeInfo<P@>::VARIANT_TYPE; - $ - return Variant::NIL; - } - - virtual PropertyInfo _gen_argument_type_info(int p_argument) const { - $ifret if (p_argument==-1) return GetTypeInfo<R>::get_class_info();$ - $arg if (p_argument==(@-1)) return GetTypeInfo<P@>::get_class_info(); - $ - return PropertyInfo(); - } - -#endif - virtual String get_instance_class() const { - return type_name; - } - - virtual Variant call(Object* p_object,const Variant** p_args,int p_arg_count, Callable::CallError& r_error) { - - __UnexistingClass *instance = (__UnexistingClass*)p_object; - - r_error.error=Callable::CallError::CALL_OK; -#ifdef DEBUG_METHODS_ENABLED - - ERR_FAIL_COND_V(!instance,Variant()); - if (p_arg_count>get_argument_count()) { - r_error.error=Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS; - r_error.argument=get_argument_count(); - return Variant(); - } - - if (p_arg_count<(get_argument_count()-get_default_argument_count())) { - - r_error.error=Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; - r_error.argument=get_argument_count()-get_default_argument_count(); - return Variant(); - } - - $arg CHECK_ARG(@); - $ -#endif - $ifret Variant ret = $(instance->*method)($arg, _VC(@)$); - $ifret return Variant(ret);$ - $ifnoret return Variant();$ - } -#ifdef PTRCALL_ENABLED - virtual void ptrcall(Object*p_object,const void** p_args,void *r_ret) { - __UnexistingClass *instance = (__UnexistingClass*)p_object; - $ifret PtrToArg<R>::encode( $ (instance->*method)($arg, PtrToArg<P@>::convert(p_args[@-1])$) $ifret ,r_ret) $ ; - } -#endif - MethodBind$argc$$ifret R$$ifconst C$ () { -#ifdef DEBUG_METHODS_ENABLED - _set_const($ifconst true$$ifnoconst false$); - _generate_argument_types($argc$); -#else - set_argument_count($argc$); -#endif - $ifret _set_returns(true); $ - - - } -}; - -template<class T $ifret ,class R$ $ifargs ,$ $arg, class P@$> -MethodBind* create_method_bind($ifret R$ $ifnoret void$ (T::*p_method)($arg, P@$) $ifconst const$ ) { - - MethodBind$argc$$ifret R$$ifconst C$ $iftempl <$ $ifret R$ $ifretargs ,$ $arg, P@$ $iftempl >$ * a = memnew( (MethodBind$argc$$ifret R$$ifconst C$ $iftempl <$ $ifret R$ $ifretargs ,$ $arg, P@$ $iftempl >$) ); - union { - - $ifret R$ $ifnoret void$ (T::*sm)($arg, P@$) $ifconst const$; - $ifret R$ $ifnoret void$ (__UnexistingClass::*dm)($arg, P@$) $ifconst const$; - } u; - u.sm=p_method; - a->method=u.dm; - a->type_name=T::get_class_static(); - return a; -} -#endif -""" - - -template_typed_free_func = """ -#ifdef TYPED_METHOD_BIND -template<class T $ifret ,class R$ $ifargs ,$ $arg, class P@$> -class FunctionBind$argc$$ifret R$$ifconst C$ : public MethodBind { -public: - - $ifret R$ $ifnoret void$ (*method) ($ifconst const$ T *$ifargs , $$arg, P@$); -#ifdef DEBUG_METHODS_ENABLED - virtual Variant::Type _gen_argument_type(int p_arg) const { return _get_argument_type(p_arg); } - virtual GodotTypeInfo::Metadata get_argument_meta(int p_arg) const { - $ifret if (p_arg==-1) return GetTypeInfo<R>::METADATA;$ - $arg if (p_arg==(@-1)) return GetTypeInfo<P@>::METADATA; - $ - return GodotTypeInfo::METADATA_NONE; - } - Variant::Type _get_argument_type(int p_argument) const { - $ifret if (p_argument==-1) return (Variant::Type)GetTypeInfo<R>::VARIANT_TYPE;$ - $arg if (p_argument==(@-1)) return (Variant::Type)GetTypeInfo<P@>::VARIANT_TYPE; - $ - return Variant::NIL; - } - virtual PropertyInfo _gen_argument_type_info(int p_argument) const { - $ifret if (p_argument==-1) return GetTypeInfo<R>::get_class_info();$ - $arg if (p_argument==(@-1)) return GetTypeInfo<P@>::get_class_info(); - $ - return PropertyInfo(); - } -#endif - virtual String get_instance_class() const { - return T::get_class_static(); - } - - virtual Variant call(Object* p_object,const Variant** p_args,int p_arg_count, Callable::CallError& r_error) { - - T *instance=Object::cast_to<T>(p_object); - r_error.error=Callable::CallError::CALL_OK; -#ifdef DEBUG_METHODS_ENABLED - - ERR_FAIL_COND_V(!instance,Variant()); - if (p_arg_count>get_argument_count()) { - r_error.error=Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS; - r_error.argument=get_argument_count(); - return Variant(); - - } - if (p_arg_count<(get_argument_count()-get_default_argument_count())) { - - r_error.error=Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; - r_error.argument=get_argument_count()-get_default_argument_count(); - return Variant(); - } - $arg CHECK_ARG(@); - $ -#endif - $ifret Variant ret = $(method)(instance$ifargs , $$arg, _VC(@)$); - $ifret return Variant(ret);$ - $ifnoret return Variant();$ - } - -#ifdef PTRCALL_ENABLED - virtual void ptrcall(Object*p_object,const void** p_args,void *r_ret) { - - T *instance=Object::cast_to<T>(p_object); - $ifret PtrToArg<R>::encode( $ (method)(instance$ifargs , $$arg, PtrToArg<P@>::convert(p_args[@-1])$) $ifret ,r_ret)$ ; - } -#endif - FunctionBind$argc$$ifret R$$ifconst C$ () { -#ifdef DEBUG_METHODS_ENABLED - _set_const($ifconst true$$ifnoconst false$); - _generate_argument_types($argc$); -#else - set_argument_count($argc$); -#endif - - $ifret _set_returns(true); $ - } -}; - -template<class T $ifret ,class R$ $ifargs ,$ $arg, class P@$> -MethodBind* create_method_bind($ifret R$ $ifnoret void$ (*p_method)($ifconst const$ T *$ifargs , $$arg, P@$) ) { - - FunctionBind$argc$$ifret R$$ifconst C$<T $ifret ,R$ $ifargs ,$ $arg, P@$> * a = memnew( (FunctionBind$argc$$ifret R$$ifconst C$<T $ifret ,R$ $ifargs ,$ $arg, P@$>) ); - a->method=p_method; - return a; -} -#endif -""" - - -def make_version(template, nargs, argmax, const, ret): - - intext = template - from_pos = 0 - outtext = "" - - while True: - to_pos = intext.find("$", from_pos) - if to_pos == -1: - outtext += intext[from_pos:] - break - else: - outtext += intext[from_pos:to_pos] - end = intext.find("$", to_pos + 1) - if end == -1: - break # ignore - macro = intext[to_pos + 1 : end] - cmd = "" - data = "" - - if macro.find(" ") != -1: - cmd = macro[0 : macro.find(" ")] - data = macro[macro.find(" ") + 1 :] - else: - cmd = macro - - if cmd == "argc": - outtext += str(nargs) - if cmd == "ifret" and ret: - outtext += data - if cmd == "ifargs" and nargs: - outtext += data - if cmd == "ifretargs" and nargs and ret: - outtext += data - if cmd == "ifconst" and const: - outtext += data - elif cmd == "ifnoconst" and not const: - outtext += data - elif cmd == "ifnoret" and not ret: - outtext += data - elif cmd == "iftempl" and (nargs > 0 or ret): - outtext += data - elif cmd == "arg,": - for i in range(1, nargs + 1): - if i > 1: - outtext += ", " - outtext += data.replace("@", str(i)) - elif cmd == "arg": - for i in range(1, nargs + 1): - outtext += data.replace("@", str(i)) - elif cmd == "noarg": - for i in range(nargs + 1, argmax + 1): - outtext += data.replace("@", str(i)) - - from_pos = end + 1 - - return outtext - - -def run(target, source, env): - - versions = 15 - versions_ext = 6 - text = "" - text_ext = "" - text_free_func = "#ifndef METHOD_BIND_FREE_FUNC_H\n#define METHOD_BIND_FREE_FUNC_H\n" - text_free_func += "\n//including this header file allows method binding to use free functions\n" - text_free_func += ( - "//note that the free function must have a pointer to an instance of the class as its first parameter\n" - ) - - for i in range(0, versions + 1): - - t = "" - t += make_version(template, i, versions, False, False) - t += make_version(template_typed, i, versions, False, False) - t += make_version(template, i, versions, False, True) - t += make_version(template_typed, i, versions, False, True) - t += make_version(template, i, versions, True, False) - t += make_version(template_typed, i, versions, True, False) - t += make_version(template, i, versions, True, True) - t += make_version(template_typed, i, versions, True, True) - if i >= versions_ext: - text_ext += t - else: - text += t - - text_free_func += make_version(template_typed_free_func, i, versions, False, False) - text_free_func += make_version(template_typed_free_func, i, versions, False, True) - text_free_func += make_version(template_typed_free_func, i, versions, True, False) - text_free_func += make_version(template_typed_free_func, i, versions, True, True) - - text_free_func += "#endif" - - with open(target[0], "w") as f: - f.write(text) - - with open(target[1], "w") as f: - f.write(text_ext) - - with open(target[2], "w") as f: - f.write(text_free_func) - - -if __name__ == "__main__": - from platform_methods import subprocess_main - - subprocess_main(globals()) diff --git a/core/math/aabb.cpp b/core/math/aabb.cpp index f5c667dab0..e868ebc7c8 100644 --- a/core/math/aabb.cpp +++ b/core/math/aabb.cpp @@ -31,6 +31,7 @@ #include "aabb.h" #include "core/print_string.h" +#include "core/variant.h" real_t AABB::get_area() const { return size.x * size.y * size.z; @@ -375,6 +376,21 @@ void AABB::get_edge(int p_edge, Vector3 &r_from, Vector3 &r_to) const { } } +Variant AABB::intersects_segment_bind(const Vector3 &p_from, const Vector3 &p_to) const { + Vector3 inters; + if (intersects_segment(p_from, p_to, &inters)) { + return inters; + } + return Variant(); +} +Variant AABB::intersects_ray_bind(const Vector3 &p_from, const Vector3 &p_dir) const { + Vector3 inters; + if (intersects_ray(p_from, p_dir, &inters)) { + return inters; + } + return Variant(); +} + AABB::operator String() const { return String() + position + " - " + size; } diff --git a/core/math/aabb.h b/core/math/aabb.h index bd1f3a1a36..8c08754e1c 100644 --- a/core/math/aabb.h +++ b/core/math/aabb.h @@ -39,6 +39,7 @@ * AABB / AABB (Axis Aligned Bounding Box) * This is implemented by a point (position) and the box size */ +class Variant; class AABB { public: @@ -103,6 +104,9 @@ public: return AABB(Vector3(position.x + MIN(size.x, 0), position.y + MIN(size.y, 0), position.z + MIN(size.z, 0)), size.abs()); } + Variant intersects_segment_bind(const Vector3 &p_from, const Vector3 &p_to) const; + Variant intersects_ray_bind(const Vector3 &p_from, const Vector3 &p_dir) const; + operator String() const; _FORCE_INLINE_ AABB() {} diff --git a/core/math/geometry_3d.h b/core/math/geometry_3d.h index 6bbf518141..11cac8f108 100644 --- a/core/math/geometry_3d.h +++ b/core/math/geometry_3d.h @@ -636,54 +636,6 @@ public: void optimize_vertices(); }; - _FORCE_INLINE_ static int get_uv84_normal_bit(const Vector3 &p_vector) { - int lat = Math::fast_ftoi(Math::floor(Math::acos(p_vector.dot(Vector3(0, 1, 0))) * 4.0 / Math_PI + 0.5)); - - if (lat == 0) { - return 24; - } else if (lat == 4) { - return 25; - } - - int lon = Math::fast_ftoi(Math::floor((Math_PI + Math::atan2(p_vector.x, p_vector.z)) * 8.0 / (Math_PI * 2.0) + 0.5)) % 8; - - return lon + (lat - 1) * 8; - } - - _FORCE_INLINE_ static int get_uv84_normal_bit_neighbors(int p_idx) { - if (p_idx == 24) { - return 1 | 2 | 4 | 8; - } else if (p_idx == 25) { - return (1 << 23) | (1 << 22) | (1 << 21) | (1 << 20); - } else { - int ret = 0; - if ((p_idx % 8) == 0) { - ret |= (1 << (p_idx + 7)); - } else { - ret |= (1 << (p_idx - 1)); - } - if ((p_idx % 8) == 7) { - ret |= (1 << (p_idx - 7)); - } else { - ret |= (1 << (p_idx + 1)); - } - - int mask = ret | (1 << p_idx); - if (p_idx < 8) { - ret |= 24; - } else { - ret |= mask >> 8; - } - - if (p_idx >= 16) { - ret |= 25; - } else { - ret |= mask << 8; - } - - return ret; - } - } static MeshData build_convex_mesh(const Vector<Plane> &p_planes); static Vector<Plane> build_sphere_planes(real_t p_radius, int p_lats, int p_lons, Vector3::Axis p_axis = Vector3::AXIS_Z); static Vector<Plane> build_box_planes(const Vector3 &p_extents); diff --git a/core/math/plane.cpp b/core/math/plane.cpp index 4200484c59..ae2021d2f6 100644 --- a/core/math/plane.cpp +++ b/core/math/plane.cpp @@ -31,6 +31,7 @@ #include "plane.h" #include "core/math/math_funcs.h" +#include "core/variant.h" void Plane::set_normal(const Vector3 &p_normal) { normal = p_normal; @@ -138,6 +139,31 @@ bool Plane::intersects_segment(const Vector3 &p_begin, const Vector3 &p_end, Vec return true; } +Variant Plane::intersect_3_bind(const Plane &p_plane1, const Plane &p_plane2) const { + Vector3 inters; + if (intersect_3(p_plane1, p_plane2, &inters)) { + return inters; + } else { + return Variant(); + } +} +Variant Plane::intersects_ray_bind(const Vector3 &p_from, const Vector3 &p_dir) const { + Vector3 inters; + if (intersects_ray(p_from, p_dir, &inters)) { + return inters; + } else { + return Variant(); + } +} +Variant Plane::intersects_segment_bind(const Vector3 &p_begin, const Vector3 &p_end) const { + Vector3 inters; + if (intersects_segment(p_begin, p_end, &inters)) { + return inters; + } else { + return Variant(); + } +} + /* misc */ bool Plane::is_equal_approx_any_side(const Plane &p_plane) const { diff --git a/core/math/plane.h b/core/math/plane.h index 70a6111edd..1386b0a2cb 100644 --- a/core/math/plane.h +++ b/core/math/plane.h @@ -33,6 +33,8 @@ #include "core/math/vector3.h" +class Variant; + class Plane { public: Vector3 normal; @@ -59,6 +61,11 @@ public: bool intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *p_intersection) const; bool intersects_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 *p_intersection) const; + // For Variant bindings. + Variant intersect_3_bind(const Plane &p_plane1, const Plane &p_plane2) const; + Variant intersects_ray_bind(const Vector3 &p_from, const Vector3 &p_dir) const; + Variant intersects_segment_bind(const Vector3 &p_begin, const Vector3 &p_end) const; + _FORCE_INLINE_ Vector3 project(const Vector3 &p_point) const { return p_point - normal * distance_to(p_point); } diff --git a/core/math/random_number_generator.h b/core/math/random_number_generator.h index 920308e597..2e7941b345 100644 --- a/core/math/random_number_generator.h +++ b/core/math/random_number_generator.h @@ -37,9 +37,9 @@ class RandomNumberGenerator : public Reference { GDCLASS(RandomNumberGenerator, Reference); +protected: RandomPCG randbase; -protected: static void _bind_methods(); public: @@ -58,12 +58,18 @@ public: _FORCE_INLINE_ real_t randfn(real_t mean = 0.0, real_t deviation = 1.0) { return randbase.randfn(mean, deviation); } _FORCE_INLINE_ int randi_range(int from, int to) { - unsigned int ret = randbase.rand(); - if (to < from) { - return ret % (from - to + 1) + to; - } else { - return ret % (to - from + 1) + from; + int range; + int min; + if (to > from) { + range = to - from + 1; + min = from; + } else if (to < from) { + range = from - to + 1; + min = to; + } else { // from == to + return from; } + return randbase.rand(range) + min; } RandomNumberGenerator() {} diff --git a/core/math/random_pcg.h b/core/math/random_pcg.h index 09b13ab74d..dfdae53eed 100644 --- a/core/math/random_pcg.h +++ b/core/math/random_pcg.h @@ -81,6 +81,10 @@ public: current_seed = pcg.state; return pcg32_random_r(&pcg); } + _FORCE_INLINE_ uint32_t rand(uint32_t bounds) { + current_seed = pcg.state; + return pcg32_boundedrand_r(&pcg, bounds); + } // Obtaining floating point numbers in [0, 1] range with "good enough" uniformity. // These functions sample the output of rand() as the fraction part of an infinite binary number, diff --git a/core/math/rect2.h b/core/math/rect2.h index 14393325ec..5a746aa732 100644 --- a/core/math/rect2.h +++ b/core/math/rect2.h @@ -197,6 +197,10 @@ struct Rect2 { return g; } + inline Rect2 grow_margin_bind(uint32_t p_margin, real_t p_amount) const { + return grow_margin(Margin(p_margin), p_amount); + } + inline Rect2 grow_individual(real_t p_left, real_t p_top, real_t p_right, real_t p_bottom) const { Rect2 g = *this; g.position.x -= p_left; @@ -240,6 +244,68 @@ struct Rect2 { return Rect2(Point2(position.x + MIN(size.x, 0), position.y + MIN(size.y, 0)), size.abs()); } + Vector2 get_support(const Vector2 &p_normal) const { + Vector2 half_extents = size * 0.5; + Vector2 ofs = position + half_extents; + return Vector2( + (p_normal.x > 0) ? -half_extents.x : half_extents.x, + (p_normal.y > 0) ? -half_extents.y : half_extents.y) + + ofs; + } + + _FORCE_INLINE_ bool intersects_filled_polygon(const Vector2 *p_points, int p_point_count) const { + Vector2 center = position + size * 0.5; + int side_plus = 0; + int side_minus = 0; + Vector2 end = position + size; + + int i_f = p_point_count - 1; + for (int i = 0; i < p_point_count; i++) { + const Vector2 &a = p_points[i_f]; + const Vector2 &b = p_points[i]; + i_f = i; + + Vector2 r = (b - a); + float l = r.length(); + if (l == 0.0) { + continue; + } + + //check inside + Vector2 tg = r.tangent(); + float s = tg.dot(center) - tg.dot(a); + if (s < 0.0) { + side_plus++; + } else { + side_minus++; + } + + //check ray box + r /= l; + Vector2 ir(1.0 / r.x, 1.0 / r.y); + + // lb is the corner of AABB with minimal coordinates - left bottom, rt is maximal corner + // r.org is origin of ray + Vector2 t13 = (position - a) * ir; + Vector2 t24 = (end - a) * ir; + + float tmin = MAX(MIN(t13.x, t24.x), MIN(t13.y, t24.y)); + float tmax = MIN(MAX(t13.x, t24.x), MAX(t13.y, t24.y)); + + // if tmax < 0, ray (line) is intersecting AABB, but the whole AABB is behind us + if (tmax < 0 || tmin > tmax || tmin >= l) { + continue; + } + + return true; + } + + if (side_plus * side_minus == 0) { + return true; //all inside + } else { + return false; + } + } operator String() const { return String(position) + ", " + String(size); } Rect2() {} @@ -301,8 +367,8 @@ struct Rect2i { new_rect.position.x = MAX(p_rect.position.x, position.x); new_rect.position.y = MAX(p_rect.position.y, position.y); - Point2 p_rect_end = p_rect.position + p_rect.size; - Point2 end = position + size; + Point2i p_rect_end = p_rect.position + p_rect.size; + Point2i end = position + size; new_rect.size.x = (int)(MIN(p_rect_end.x, end.x) - new_rect.position.x); new_rect.size.y = (int)(MIN(p_rect_end.y, end.y) - new_rect.position.y); @@ -324,7 +390,7 @@ struct Rect2i { return new_rect; } - bool has_point(const Point2 &p_point) const { + bool has_point(const Point2i &p_point) const { if (p_point.x < position.x) { return false; } @@ -363,6 +429,10 @@ struct Rect2i { return g; } + inline Rect2i grow_margin_bind(uint32_t p_margin, int p_amount) const { + return grow_margin(Margin(p_margin), p_amount); + } + inline Rect2i grow_individual(int p_left, int p_top, int p_right, int p_bottom) const { Rect2i g = *this; g.position.x -= p_left; @@ -415,10 +485,10 @@ struct Rect2i { size(p_r2.size) { } Rect2i(int p_x, int p_y, int p_width, int p_height) : - position(Point2(p_x, p_y)), - size(Size2(p_width, p_height)) { + position(Point2i(p_x, p_y)), + size(Size2i(p_width, p_height)) { } - Rect2i(const Point2 &p_pos, const Size2 &p_size) : + Rect2i(const Point2i &p_pos, const Size2i &p_size) : position(p_pos), size(p_size) { } diff --git a/core/math/vector2.h b/core/math/vector2.h index f41bcc15bc..c2a2656e72 100644 --- a/core/math/vector2.h +++ b/core/math/vector2.h @@ -65,6 +65,14 @@ struct Vector2 { real_t length() const; real_t length_squared() const; + Vector2 min(const Vector2 &p_vector2) const { + return Vector2(MIN(x, p_vector2.x), MIN(y, p_vector2.y)); + } + + Vector2 max(const Vector2 &p_vector2) const { + return Vector2(MAX(x, p_vector2.x), MAX(y, p_vector2.y)); + } + real_t distance_to(const Vector2 &p_vector2) const; real_t distance_squared_to(const Vector2 &p_vector2) const; real_t angle_to(const Vector2 &p_vector2) const; diff --git a/core/message_queue.h b/core/message_queue.h index 710a605371..5d39ceee03 100644 --- a/core/message_queue.h +++ b/core/message_queue.h @@ -31,7 +31,7 @@ #ifndef MESSAGE_QUEUE_H #define MESSAGE_QUEUE_H -#include "core/object.h" +#include "core/class_db.h" #include "core/os/thread_safe.h" class MessageQueue { diff --git a/core/method_bind.h b/core/method_bind.h index 942e2e0036..d43186257b 100644 --- a/core/method_bind.h +++ b/core/method_bind.h @@ -31,18 +31,7 @@ #ifndef METHOD_BIND_H #define METHOD_BIND_H -#ifdef DEBUG_ENABLED -#define DEBUG_METHODS_ENABLED -#endif - -#include "core/list.h" -#include "core/method_ptrcall.h" -#include "core/object.h" -#include "core/type_info.h" -#include "core/typedefs.h" -#include "core/variant.h" - -#include <stdio.h> +#include "core/binder_common.h" enum MethodFlags { @@ -57,151 +46,15 @@ enum MethodFlags { METHOD_FLAGS_DEFAULT = METHOD_FLAG_NORMAL, }; -template <class T> -struct VariantCaster { - static _FORCE_INLINE_ T cast(const Variant &p_variant) { - return p_variant; - } -}; - -template <class T> -struct VariantCaster<T &> { - static _FORCE_INLINE_ T cast(const Variant &p_variant) { - return p_variant; - } -}; - -template <class T> -struct VariantCaster<const T &> { - static _FORCE_INLINE_ T cast(const Variant &p_variant) { - return p_variant; - } -}; - -#define _VC(m_idx) \ - (VariantCaster<P##m_idx>::cast((m_idx - 1) >= p_arg_count ? get_default_argument(m_idx - 1) : *p_args[m_idx - 1])) - -#ifdef PTRCALL_ENABLED - -#define VARIANT_ENUM_CAST(m_enum) \ - MAKE_ENUM_TYPE_INFO(m_enum) \ - template <> \ - struct VariantCaster<m_enum> { \ - static _FORCE_INLINE_ m_enum cast(const Variant &p_variant) { \ - return (m_enum)p_variant.operator int(); \ - } \ - }; \ - template <> \ - struct PtrToArg<m_enum> { \ - _FORCE_INLINE_ static m_enum convert(const void *p_ptr) { \ - return m_enum(*reinterpret_cast<const int *>(p_ptr)); \ - } \ - _FORCE_INLINE_ static void encode(m_enum p_val, const void *p_ptr) { \ - *(int *)p_ptr = p_val; \ - } \ - }; - -#else - -#define VARIANT_ENUM_CAST(m_enum) \ - MAKE_ENUM_TYPE_INFO(m_enum) \ - template <> \ - struct VariantCaster<m_enum> { \ - static _FORCE_INLINE_ m_enum cast(const Variant &p_variant) { \ - return (m_enum)p_variant.operator int(); \ - } \ - }; - -#endif - -// Object enum casts must go here -VARIANT_ENUM_CAST(Object::ConnectFlags); - -template <typename T> -struct VariantObjectClassChecker { - static _FORCE_INLINE_ bool check(const Variant &p_variant) { - return true; - } -}; - -template <> -struct VariantObjectClassChecker<Node *> { - static _FORCE_INLINE_ bool check(const Variant &p_variant) { - Object *obj = p_variant; - Node *node = p_variant; - return node || !obj; - } -}; - -template <> -struct VariantObjectClassChecker<Control *> { - static _FORCE_INLINE_ bool check(const Variant &p_variant) { - Object *obj = p_variant; - Control *control = p_variant; - return control || !obj; - } -}; - -#define CHECK_ARG(m_arg) \ - if ((m_arg - 1) < p_arg_count) { \ - Variant::Type argtype = get_argument_type(m_arg - 1); \ - if (!Variant::can_convert_strict(p_args[m_arg - 1]->get_type(), argtype) || \ - !VariantObjectClassChecker<P##m_arg>::check(*p_args[m_arg - 1])) { \ - r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; \ - r_error.argument = m_arg - 1; \ - r_error.expected = argtype; \ - return Variant(); \ - } \ - } - -#define CHECK_NOARG(m_arg) \ - { \ - if (p_arg##m_arg.get_type() != Variant::NIL) { \ - if (r_argerror) { \ - *r_argerror = (m_arg - 1); \ - } \ - return CALL_ERROR_EXTRA_ARGUMENT; \ - } \ - } +VARIANT_ENUM_CAST(MethodFlags) // some helpers -VARIANT_ENUM_CAST(Vector3::Axis); - -VARIANT_ENUM_CAST(Error); -VARIANT_ENUM_CAST(Margin); -VARIANT_ENUM_CAST(Corner); -VARIANT_ENUM_CAST(Orientation); -VARIANT_ENUM_CAST(HAlign); -VARIANT_ENUM_CAST(VAlign); -VARIANT_ENUM_CAST(PropertyHint); -VARIANT_ENUM_CAST(PropertyUsageFlags); -VARIANT_ENUM_CAST(MethodFlags); -VARIANT_ENUM_CAST(Variant::Type); -VARIANT_ENUM_CAST(Variant::Operator); - -template <> -struct VariantCaster<char32_t> { - static _FORCE_INLINE_ char32_t cast(const Variant &p_variant) { - return (char32_t)p_variant.operator int(); - } -}; -#ifdef PTRCALL_ENABLED -template <> -struct PtrToArg<char32_t> { - _FORCE_INLINE_ static char32_t convert(const void *p_ptr) { - return char32_t(*reinterpret_cast<const int *>(p_ptr)); - } - _FORCE_INLINE_ static void encode(char32_t p_val, const void *p_ptr) { - *(int *)p_ptr = p_val; - } -}; -#endif - class MethodBind { int method_id; uint32_t hint_flags = METHOD_FLAGS_DEFAULT; StringName name; + StringName instance_class; Vector<Variant> default_arguments; int default_argument_count = 0; int argument_count = 0; @@ -225,11 +78,11 @@ protected: void set_argument_count(int p_count) { argument_count = p_count; } public: - Vector<Variant> get_default_arguments() const { return default_arguments; } + _FORCE_INLINE_ const Vector<Variant> &get_default_arguments() const { return default_arguments; } _FORCE_INLINE_ int get_default_argument_count() const { return default_argument_count; } _FORCE_INLINE_ Variant has_default_argument(int p_arg) const { - int idx = argument_count - p_arg - 1; + int idx = p_arg - (argument_count - default_arguments.size()); if (idx < 0 || idx >= default_arguments.size()) { return false; @@ -239,7 +92,7 @@ public: } _FORCE_INLINE_ Variant get_default_argument(int p_arg) const { - int idx = argument_count - p_arg - 1; + int idx = p_arg - (argument_count - default_arguments.size()); if (idx < 0 || idx >= default_arguments.size()) { return Variant(); @@ -249,7 +102,6 @@ public: } #ifdef DEBUG_METHODS_ENABLED - _FORCE_INLINE_ Variant::Type get_argument_type(int p_argument) const { ERR_FAIL_COND_V(p_argument < -1 || p_argument > argument_count, Variant::NIL); return argument_types[p_argument + 1]; @@ -258,15 +110,16 @@ public: PropertyInfo get_argument_info(int p_argument) const; PropertyInfo get_return_info() const; - void set_argument_names(const Vector<StringName> &p_names); //set by class, db, can't be inferred otherwise + void set_argument_names(const Vector<StringName> &p_names); // Set by ClassDB, can't be inferred otherwise. Vector<StringName> get_argument_names() const; virtual GodotTypeInfo::Metadata get_argument_meta(int p_arg) const = 0; - #endif + void set_hint_flags(uint32_t p_hint) { hint_flags = p_hint; } uint32_t get_hint_flags() const { return hint_flags | (is_const() ? METHOD_FLAG_CONST : 0) | (is_vararg() ? METHOD_FLAG_VARARG : 0); } - virtual String get_instance_class() const = 0; + _FORCE_INLINE_ StringName get_instance_class() const { return instance_class; } + _FORCE_INLINE_ void set_instance_class(const StringName &p_class) { instance_class = p_class; } _FORCE_INLINE_ int get_argument_count() const { return argument_count; }; @@ -302,7 +155,6 @@ protected: public: #ifdef DEBUG_METHODS_ENABLED - virtual PropertyInfo _gen_argument_type_info(int p_arg) const { if (p_arg < 0) { return arguments.return_val; @@ -320,14 +172,12 @@ public: virtual GodotTypeInfo::Metadata get_argument_meta(int) const { return GodotTypeInfo::METADATA_NONE; } - #else - virtual Variant::Type _gen_argument_type(int p_arg) const { return Variant::NIL; } - #endif + virtual Variant call(Object *p_object, const Variant **p_args, int p_arg_count, Callable::CallError &r_error) { T *instance = static_cast<T *>(p_object); return (instance->*call_method)(p_args, p_arg_count, r_error); @@ -364,7 +214,6 @@ public: void set_method(NativeCall p_method) { call_method = p_method; } virtual bool is_const() const { return false; } - virtual String get_instance_class() const { return T::get_class_static(); } virtual bool is_vararg() const { return true; } @@ -378,16 +227,365 @@ MethodBind *create_vararg_method_bind(Variant (T::*p_method)(const Variant **, i MethodBindVarArg<T> *a = memnew((MethodBindVarArg<T>)); a->set_method(p_method); a->set_method_info(p_info, p_return_nil_is_variant); + a->set_instance_class(T::get_class_static()); return a; } -/** This amazing hack is based on the FastDelegates theory */ - -// tale of an amazing hack.. // +/**** VARIADIC TEMPLATES ****/ -// if you declare a nonexistent class.. +#ifndef TYPED_METHOD_BIND class __UnexistingClass; +#define MB_T __UnexistingClass +#else +#define MB_T T +#endif -#include "method_bind.gen.inc" +// no return, not const +#ifdef TYPED_METHOD_BIND +template <class T, class... P> +#else +template <class... P> +#endif +class MethodBindT : public MethodBind { + void (MB_T::*method)(P...); + +protected: +#ifdef DEBUG_METHODS_ENABLED +// GCC raises warnings in the case P = {} as the comparison is always false... +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wlogical-op" +#endif + virtual Variant::Type _gen_argument_type(int p_arg) const { + if (p_arg >= 0 && p_arg < (int)sizeof...(P)) { + return call_get_argument_type<P...>(p_arg); + } else { + return Variant::NIL; + } + } +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic pop +#endif + + virtual PropertyInfo _gen_argument_type_info(int p_arg) const { + PropertyInfo pi; + call_get_argument_type_info<P...>(p_arg, pi); + return pi; + } +#endif + +public: +#ifdef DEBUG_METHODS_ENABLED + virtual GodotTypeInfo::Metadata get_argument_meta(int p_arg) const { + return call_get_argument_metadata<P...>(p_arg); + } + +#endif + virtual Variant call(Object *p_object, const Variant **p_args, int p_arg_count, Callable::CallError &r_error) { +#ifdef TYPED_METHOD_BIND + call_with_variant_args_dv(static_cast<T *>(p_object), method, p_args, p_arg_count, r_error, get_default_arguments()); +#else + call_with_variant_args_dv((MB_T *)(p_object), method, p_args, p_arg_count, r_error, get_default_arguments()); +#endif + return Variant(); + } + +#ifdef PTRCALL_ENABLED + virtual void ptrcall(Object *p_object, const void **p_args, void *r_ret) { +#ifdef TYPED_METHOD_BIND + call_with_ptr_args<T, P...>(static_cast<T *>(p_object), method, p_args); +#else + call_with_ptr_args<MB_T, P...>((MB_T *)(p_object), method, p_args); +#endif + } +#endif + + MethodBindT(void (MB_T::*p_method)(P...)) { + method = p_method; +#ifdef DEBUG_METHODS_ENABLED + _generate_argument_types(sizeof...(P)); +#endif + set_argument_count(sizeof...(P)); + } +}; + +template <class T, class... P> +MethodBind *create_method_bind(void (T::*p_method)(P...)) { +#ifdef TYPED_METHOD_BIND + MethodBind *a = memnew((MethodBindT<T, P...>)(p_method)); +#else + MethodBind *a = memnew((MethodBindT<P...>)(reinterpret_cast<void (MB_T::*)(P...)>(p_method))); +#endif + a->set_instance_class(T::get_class_static()); + return a; +} + +// no return, not const + +#ifdef TYPED_METHOD_BIND +template <class T, class... P> +#else +template <class... P> +#endif +class MethodBindTC : public MethodBind { + void (MB_T::*method)(P...) const; + +protected: +#ifdef DEBUG_METHODS_ENABLED +// GCC raises warnings in the case P = {} as the comparison is always false... +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wlogical-op" +#endif + virtual Variant::Type _gen_argument_type(int p_arg) const { + if (p_arg >= 0 && p_arg < (int)sizeof...(P)) { + return call_get_argument_type<P...>(p_arg); + } else { + return Variant::NIL; + } + } +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic pop +#endif + + virtual PropertyInfo _gen_argument_type_info(int p_arg) const { + PropertyInfo pi; + call_get_argument_type_info<P...>(p_arg, pi); + return pi; + } +#endif + +public: +#ifdef DEBUG_METHODS_ENABLED + virtual GodotTypeInfo::Metadata get_argument_meta(int p_arg) const { + return call_get_argument_metadata<P...>(p_arg); + } + +#endif + virtual Variant call(Object *p_object, const Variant **p_args, int p_arg_count, Callable::CallError &r_error) { +#ifdef TYPED_METHOD_BIND + call_with_variant_argsc_dv(static_cast<T *>(p_object), method, p_args, p_arg_count, r_error, get_default_arguments()); +#else + call_with_variant_argsc_dv((MB_T *)(p_object), method, p_args, p_arg_count, r_error, get_default_arguments()); +#endif + return Variant(); + } + +#ifdef PTRCALL_ENABLED + virtual void ptrcall(Object *p_object, const void **p_args, void *r_ret) { +#ifdef TYPED_METHOD_BIND + call_with_ptr_argsc<T, P...>(static_cast<T *>(p_object), method, p_args); +#else + call_with_ptr_argsc<MB_T, P...>((MB_T *)(p_object), method, p_args); +#endif + } +#endif + + MethodBindTC(void (MB_T::*p_method)(P...) const) { + method = p_method; + _set_const(true); +#ifdef DEBUG_METHODS_ENABLED + _generate_argument_types(sizeof...(P)); +#endif + set_argument_count(sizeof...(P)); + } +}; + +template <class T, class... P> +MethodBind *create_method_bind(void (T::*p_method)(P...) const) { +#ifdef TYPED_METHOD_BIND + MethodBind *a = memnew((MethodBindTC<T, P...>)(p_method)); +#else + MethodBind *a = memnew((MethodBindTC<P...>)(reinterpret_cast<void (MB_T::*)(P...) const>(p_method))); +#endif + a->set_instance_class(T::get_class_static()); + return a; +} + +// return, not const + +#ifdef TYPED_METHOD_BIND +template <class T, class R, class... P> +#else +template <class R, class... P> +#endif +class MethodBindTR : public MethodBind { + R(MB_T::*method) + (P...); + +protected: +#ifdef DEBUG_METHODS_ENABLED +// GCC raises warnings in the case P = {} as the comparison is always false... +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wlogical-op" +#endif + virtual Variant::Type _gen_argument_type(int p_arg) const { + if (p_arg >= 0 && p_arg < (int)sizeof...(P)) { + return call_get_argument_type<P...>(p_arg); + } else { + return GetTypeInfo<R>::VARIANT_TYPE; + } + } + + virtual PropertyInfo _gen_argument_type_info(int p_arg) const { + if (p_arg >= 0 && p_arg < (int)sizeof...(P)) { + PropertyInfo pi; + call_get_argument_type_info<P...>(p_arg, pi); + return pi; + } else { + return GetTypeInfo<R>::get_class_info(); + } + } +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic pop +#endif +#endif + +public: +#ifdef DEBUG_METHODS_ENABLED + virtual GodotTypeInfo::Metadata get_argument_meta(int p_arg) const { + if (p_arg >= 0) { + return call_get_argument_metadata<P...>(p_arg); + } else { + return GetTypeInfo<R>::METADATA; + } + } +#endif + + virtual Variant call(Object *p_object, const Variant **p_args, int p_arg_count, Callable::CallError &r_error) { + Variant ret; +#ifdef TYPED_METHOD_BIND + call_with_variant_args_ret_dv(static_cast<T *>(p_object), method, p_args, p_arg_count, ret, r_error, get_default_arguments()); +#else + call_with_variant_args_ret_dv((MB_T *)p_object, method, p_args, p_arg_count, ret, r_error, get_default_arguments()); +#endif + return ret; + } + +#ifdef PTRCALL_ENABLED + virtual void ptrcall(Object *p_object, const void **p_args, void *r_ret) { +#ifdef TYPED_METHOD_BIND + call_with_ptr_args_ret<T, R, P...>(static_cast<T *>(p_object), method, p_args, r_ret); +#else + call_with_ptr_args_ret<MB_T, R, P...>((MB_T *)(p_object), method, p_args, r_ret); +#endif + } +#endif + + MethodBindTR(R (MB_T::*p_method)(P...)) { + method = p_method; + _set_returns(true); +#ifdef DEBUG_METHODS_ENABLED + _generate_argument_types(sizeof...(P)); +#endif + set_argument_count(sizeof...(P)); + } +}; + +template <class T, class R, class... P> +MethodBind *create_method_bind(R (T::*p_method)(P...)) { +#ifdef TYPED_METHOD_BIND + MethodBind *a = memnew((MethodBindTR<T, R, P...>)(p_method)); +#else + MethodBind *a = memnew((MethodBindTR<R, P...>)(reinterpret_cast<R (MB_T::*)(P...)>(p_method))); +#endif + + a->set_instance_class(T::get_class_static()); + return a; +} + +// return, const + +#ifdef TYPED_METHOD_BIND +template <class T, class R, class... P> +#else +template <class R, class... P> +#endif +class MethodBindTRC : public MethodBind { + R(MB_T::*method) + (P...) const; + +protected: +#ifdef DEBUG_METHODS_ENABLED +// GCC raises warnings in the case P = {} as the comparison is always false... +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wlogical-op" +#endif + virtual Variant::Type _gen_argument_type(int p_arg) const { + if (p_arg >= 0 && p_arg < (int)sizeof...(P)) { + return call_get_argument_type<P...>(p_arg); + } else { + return GetTypeInfo<R>::VARIANT_TYPE; + } + } + + virtual PropertyInfo _gen_argument_type_info(int p_arg) const { + if (p_arg >= 0 && p_arg < (int)sizeof...(P)) { + PropertyInfo pi; + call_get_argument_type_info<P...>(p_arg, pi); + return pi; + } else { + return GetTypeInfo<R>::get_class_info(); + } + } +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic pop +#endif +#endif + +public: +#ifdef DEBUG_METHODS_ENABLED + virtual GodotTypeInfo::Metadata get_argument_meta(int p_arg) const { + if (p_arg >= 0) { + return call_get_argument_metadata<P...>(p_arg); + } else { + return GetTypeInfo<R>::METADATA; + } + } +#endif + + virtual Variant call(Object *p_object, const Variant **p_args, int p_arg_count, Callable::CallError &r_error) { + Variant ret; +#ifdef TYPED_METHOD_BIND + call_with_variant_args_retc_dv(static_cast<T *>(p_object), method, p_args, p_arg_count, ret, r_error, get_default_arguments()); +#else + call_with_variant_args_retc_dv((MB_T *)(p_object), method, p_args, p_arg_count, ret, r_error, get_default_arguments()); +#endif + return ret; + } + +#ifdef PTRCALL_ENABLED + virtual void ptrcall(Object *p_object, const void **p_args, void *r_ret) { +#ifdef TYPED_METHOD_BIND + call_with_ptr_args_retc<T, R, P...>(static_cast<T *>(p_object), method, p_args, r_ret); +#else + call_with_ptr_args_retc<MB_T, R, P...>((MB_T *)(p_object), method, p_args, r_ret); +#endif + } +#endif + + MethodBindTRC(R (MB_T::*p_method)(P...) const) { + method = p_method; + _set_returns(true); + _set_const(true); +#ifdef DEBUG_METHODS_ENABLED + _generate_argument_types(sizeof...(P)); +#endif + set_argument_count(sizeof...(P)); + } +}; + +template <class T, class R, class... P> +MethodBind *create_method_bind(R (T::*p_method)(P...) const) { +#ifdef TYPED_METHOD_BIND + MethodBind *a = memnew((MethodBindTRC<T, R, P...>)(p_method)); +#else + MethodBind *a = memnew((MethodBindTRC<R, P...>)(reinterpret_cast<R (MB_T::*)(P...) const>(p_method))); +#endif + a->set_instance_class(T::get_class_static()); + return a; +} #endif // METHOD_BIND_H diff --git a/core/object.cpp b/core/object.cpp index 67c605c39b..0d9e5c5116 100644 --- a/core/object.cpp +++ b/core/object.cpp @@ -1315,9 +1315,10 @@ Error Object::connect(const StringName &p_signal, const Callable &p_callable, co Callable target = p_callable; - if (s->slot_map.has(target)) { + //compare with the base callable, so binds can be ignored + if (s->slot_map.has(*target.get_base_comparator())) { if (p_flags & CONNECT_REFERENCE_COUNTED) { - s->slot_map[target].reference_count++; + s->slot_map[*target.get_base_comparator()].reference_count++; return OK; } else { ERR_FAIL_V_MSG(ERR_INVALID_PARAMETER, "Signal '" + p_signal + "' is already connected to given callable '" + p_callable + "' in that object."); @@ -1337,7 +1338,8 @@ Error Object::connect(const StringName &p_signal, const Callable &p_callable, co slot.reference_count = 1; } - s->slot_map[target] = slot; + //use callable version as key, so binds can be ignored + s->slot_map[*target.get_base_comparator()] = slot; return OK; } @@ -1364,7 +1366,7 @@ bool Object::is_connected(const StringName &p_signal, const Callable &p_callable Callable target = p_callable; - return s->slot_map.has(target); + return s->slot_map.has(*target.get_base_comparator()); //const Map<Signal::Target,Signal::Slot>::Element *E = s->slot_map.find(target); //return (E!=nullptr ); } @@ -1386,7 +1388,7 @@ void Object::_disconnect(const StringName &p_signal, const Callable &p_callable, SignalData *s = signal_map.getptr(p_signal); ERR_FAIL_COND_MSG(!s, vformat("Nonexistent signal '%s' in %s.", p_signal, to_string())); - ERR_FAIL_COND_MSG(!s->slot_map.has(p_callable), "Disconnecting nonexistent signal '" + p_signal + "', callable: " + p_callable + "."); + ERR_FAIL_COND_MSG(!s->slot_map.has(*p_callable.get_base_comparator()), "Disconnecting nonexistent signal '" + p_signal + "', callable: " + p_callable + "."); SignalData::Slot *slot = &s->slot_map[p_callable]; @@ -1398,7 +1400,7 @@ void Object::_disconnect(const StringName &p_signal, const Callable &p_callable, } target_object->connections.erase(slot->cE); - s->slot_map.erase(p_callable); + s->slot_map.erase(*p_callable.get_base_comparator()); if (s->slot_map.empty() && ClassDB::has_signal(get_class_name(), p_signal)) { //not user signal, delete diff --git a/core/object.h b/core/object.h index 12ef600dfc..765fb63c6e 100644 --- a/core/object.h +++ b/core/object.h @@ -31,6 +31,7 @@ #ifndef OBJECT_H #define OBJECT_H +#include "core/callable_bind.h" #include "core/hash_map.h" #include "core/list.h" #include "core/map.h" @@ -811,7 +812,4 @@ public: static int get_object_count(); }; -//needed by macros -#include "core/class_db.h" - #endif // OBJECT_H diff --git a/core/os/main_loop.cpp b/core/os/main_loop.cpp index 434f6fa300..6651fb80d7 100644 --- a/core/os/main_loop.cpp +++ b/core/os/main_loop.cpp @@ -33,11 +33,6 @@ #include "core/script_language.h" void MainLoop::_bind_methods() { - ClassDB::bind_method(D_METHOD("init"), &MainLoop::init); - ClassDB::bind_method(D_METHOD("iteration", "delta"), &MainLoop::iteration); - ClassDB::bind_method(D_METHOD("idle", "delta"), &MainLoop::idle); - ClassDB::bind_method(D_METHOD("finish"), &MainLoop::finish); - BIND_VMETHOD(MethodInfo("_initialize")); BIND_VMETHOD(MethodInfo(Variant::BOOL, "_iteration", PropertyInfo(Variant::FLOAT, "delta"))); BIND_VMETHOD(MethodInfo(Variant::BOOL, "_idle", PropertyInfo(Variant::FLOAT, "delta"))); diff --git a/core/project_settings.cpp b/core/project_settings.cpp index 90f56694c2..3829474626 100644 --- a/core/project_settings.cpp +++ b/core/project_settings.cpp @@ -629,19 +629,26 @@ Error ProjectSettings::_load_settings_text(const String &p_path) { } Error ProjectSettings::_load_settings_text_or_binary(const String &p_text_path, const String &p_bin_path) { - // Attempt first to load the text-based project.godot file - Error err_text = _load_settings_text(p_text_path); - if (err_text == OK) { + // Attempt first to load the binary project.godot file. + Error err = _load_settings_binary(p_bin_path); + if (err == OK) { + return OK; + } else if (err != ERR_FILE_NOT_FOUND) { + // If the file exists but can't be loaded, we want to know it. + ERR_PRINT("Couldn't load file '" + p_bin_path + "', error code " + itos(err) + "."); + return err; + } + + // Fallback to text-based project.godot file if binary was not found. + err = _load_settings_text(p_text_path); + if (err == OK) { return OK; - } else if (err_text != ERR_FILE_NOT_FOUND) { - // If the text-based file exists but can't be loaded, we want to know it - ERR_PRINT("Couldn't load file '" + p_text_path + "', error code " + itos(err_text) + "."); - return err_text; + } else if (err != ERR_FILE_NOT_FOUND) { + ERR_PRINT("Couldn't load file '" + p_text_path + "', error code " + itos(err) + "."); + return err; } - // Fallback to binary project.binary file if text-based was not found - Error err_bin = _load_settings_binary(p_bin_path); - return err_bin; + return err; } int ProjectSettings::get_order(const String &p_name) const { diff --git a/core/project_settings.h b/core/project_settings.h index 6cbb02d30e..9a1d9cee97 100644 --- a/core/project_settings.h +++ b/core/project_settings.h @@ -31,7 +31,7 @@ #ifndef PROJECT_SETTINGS_H #define PROJECT_SETTINGS_H -#include "core/object.h" +#include "core/class_db.h" #include "core/os/thread_safe.h" #include "core/set.h" diff --git a/core/reference.h b/core/reference.h index f5794b0b67..868894aad4 100644 --- a/core/reference.h +++ b/core/reference.h @@ -32,7 +32,6 @@ #define REFERENCE_H #include "core/class_db.h" -#include "core/object.h" #include "core/safe_refcount.h" class Reference : public Object { diff --git a/core/resource.h b/core/resource.h index 7699d48735..41707f216d 100644 --- a/core/resource.h +++ b/core/resource.h @@ -32,7 +32,6 @@ #define RESOURCE_H #include "core/class_db.h" -#include "core/object.h" #include "core/reference.h" #include "core/safe_refcount.h" #include "core/self_list.h" diff --git a/core/script_language.cpp b/core/script_language.cpp index b63aeb952c..d535c54dea 100644 --- a/core/script_language.cpp +++ b/core/script_language.cpp @@ -275,7 +275,13 @@ void ScriptServer::save_global_classes() { gcarr.push_back(d); } - ProjectSettings::get_singleton()->set("_global_script_classes", gcarr); + if (gcarr.empty()) { + if (ProjectSettings::get_singleton()->has_setting("_global_script_classes")) { + ProjectSettings::get_singleton()->clear("_global_script_classes"); + } + } else { + ProjectSettings::get_singleton()->set("_global_script_classes", gcarr); + } ProjectSettings::get_singleton()->save(); } diff --git a/core/script_language.h b/core/script_language.h index aa7014ed3e..a94c128932 100644 --- a/core/script_language.h +++ b/core/script_language.h @@ -255,6 +255,7 @@ struct ScriptCodeCompletionOption { String insert_text; Color font_color; RES icon; + Variant default_value; ScriptCodeCompletionOption() {} diff --git a/core/simple_type.h b/core/simple_type.h index 10dc36cbd4..841ab9f384 100644 --- a/core/simple_type.h +++ b/core/simple_type.h @@ -48,4 +48,9 @@ struct GetSimpleTypeT<T const> { typedef T type_t; }; +template <class T> +struct GetSimpleTypeT<T const &> { + typedef T type_t; +}; + #endif // SIMPLE_TYPE_H diff --git a/core/thread_work_pool.h b/core/thread_work_pool.h index e21d3974ee..661060aa3f 100644 --- a/core/thread_work_pool.h +++ b/core/thread_work_pool.h @@ -73,13 +73,15 @@ class ThreadWorkPool { ThreadData *threads = nullptr; uint32_t thread_count = 0; + BaseWork *current_work = nullptr; static void _thread_function(ThreadData *p_thread); public: template <class C, class M, class U> - void do_work(uint32_t p_elements, C *p_instance, M p_method, U p_userdata) { + void begin_work(uint32_t p_elements, C *p_instance, M p_method, U p_userdata) { ERR_FAIL_COND(!threads); //never initialized + ERR_FAIL_COND(current_work != nullptr); index.store(0); @@ -90,16 +92,37 @@ public: w->index = &index; w->max_elements = p_elements; + current_work = w; + for (uint32_t i = 0; i < thread_count; i++) { threads[i].work = w; threads[i].start.post(); } + } + + bool is_working() const { + return current_work != nullptr; + } + + uint32_t get_work_index() const { + return index; + } + + void end_work() { + ERR_FAIL_COND(current_work == nullptr); for (uint32_t i = 0; i < thread_count; i++) { threads[i].completed.wait(); threads[i].work = nullptr; } - memdelete(w); + memdelete(current_work); + current_work = nullptr; + } + + template <class C, class M, class U> + void do_work(uint32_t p_elements, C *p_instance, M p_method, U p_userdata) { + begin_work(p_elements, p_instance, p_method, p_userdata); + end_work(); } void init(int p_thread_count = -1); diff --git a/core/type_info.h b/core/type_info.h index 3c7f59bb84..b9ae88d97c 100644 --- a/core/type_info.h +++ b/core/type_info.h @@ -31,7 +31,7 @@ #ifndef TYPE_INFO_H #define TYPE_INFO_H -#ifdef DEBUG_METHODS_ENABLED +#include "core/typedefs.h" template <bool C, typename T = void> struct EnableIf { @@ -267,11 +267,4 @@ inline StringName __constant_get_enum_name(T param, const String &p_constant) { #define CLASS_INFO(m_type) (GetTypeInfo<m_type *>::get_class_info()) -#else - -#define MAKE_ENUM_TYPE_INFO(m_enum) -#define CLASS_INFO(m_type) - -#endif // DEBUG_METHODS_ENABLED - #endif // TYPE_INFO_H diff --git a/core/typedefs.h b/core/typedefs.h index 4bfa5debac..f0c32f2c95 100644 --- a/core/typedefs.h +++ b/core/typedefs.h @@ -193,6 +193,20 @@ static inline unsigned int nearest_shift(unsigned int p_number) { return 0; } +// constexpr function to find the floored log2 of a number +template <typename T> +constexpr T floor_log2(T x) { + return x < 2 ? x : 1 + floor_log2(x >> 1); +} + +// Get the number of bits needed to represent the number. +// IE, if you pass in 8, you will get 4. +// If you want to know how many bits are needed to store 8 values however, pass in (8 - 1). +template <typename T> +constexpr T get_num_bits(T x) { + return floor_log2(x); +} + // Swap 16, 32 and 64 bits value for endianness. #if defined(__GNUC__) #define BSWAP16(x) __builtin_bswap16(x) @@ -263,4 +277,8 @@ struct BuildIndexSequence : BuildIndexSequence<N - 1, N - 1, Is...> {}; template <size_t... Is> struct BuildIndexSequence<0, Is...> : IndexSequence<Is...> {}; +#ifdef DEBUG_ENABLED +#define DEBUG_METHODS_ENABLED +#endif + #endif // TYPEDEFS_H diff --git a/core/undo_redo.h b/core/undo_redo.h index b46f7ff867..68a553efd4 100644 --- a/core/undo_redo.h +++ b/core/undo_redo.h @@ -31,7 +31,7 @@ #ifndef UNDO_REDO_H #define UNDO_REDO_H -#include "core/object.h" +#include "core/class_db.h" #include "core/resource.h" class UndoRedo : public Object { diff --git a/core/ustring.cpp b/core/ustring.cpp index d5afbc2b47..27dab8db6e 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -787,29 +787,46 @@ signed char String::naturalnocasecmp_to(const String &p_str) const { if (!*that_str) { return 1; } else if (IS_DIGIT(*this_str)) { - int64_t this_int, that_int; - if (!IS_DIGIT(*that_str)) { return -1; } - /* Compare the numbers */ - this_int = to_int(this_str, -1, true); - that_int = to_int(that_str, -1, true); - - if (this_int < that_int) { - return -1; - } else if (this_int > that_int) { - return 1; - } + // Keep ptrs to start of numerical sequences + const char32_t *this_substr = this_str; + const char32_t *that_substr = that_str; - /* Skip */ + // Compare lengths of both numerical sequences, ignoring leading zeros while (IS_DIGIT(*this_str)) { this_str++; } while (IS_DIGIT(*that_str)) { that_str++; } + while (*this_substr == '0') { + this_substr++; + } + while (*that_substr == '0') { + that_substr++; + } + int this_len = this_str - this_substr; + int that_len = that_str - that_substr; + + if (this_len < that_len) { + return -1; + } else if (this_len > that_len) { + return 1; + } + + // If lengths equal, compare lexicographically + while (this_substr != this_str && that_substr != that_str) { + if (*this_substr < *that_substr) { + return -1; + } else if (*this_substr > *that_substr) { + return 1; + } + this_substr++; + that_substr++; + } } else if (IS_DIGIT(*that_str)) { return 1; } else { @@ -4484,11 +4501,12 @@ String String::sprintf(const Array &values, bool *error) const { int number_len = str.length(); // Padding. + int pad_chars_count = (value < 0 || show_sign) ? min_chars - 1 : min_chars; String pad_char = pad_with_zeroes ? String("0") : String(" "); if (left_justified) { - str = str.rpad(min_chars, pad_char); + str = str.rpad(pad_chars_count, pad_char); } else { - str = str.lpad(min_chars, pad_char); + str = str.lpad(pad_chars_count, pad_char); } // Sign. @@ -4714,6 +4732,69 @@ String String::unquote() const { return substr(1, length() - 2); } +Vector<uint8_t> String::to_ascii_buffer() const { + const String *s = this; + if (s->empty()) { + return Vector<uint8_t>(); + } + CharString charstr = s->ascii(); + + Vector<uint8_t> retval; + size_t len = charstr.length(); + retval.resize(len); + uint8_t *w = retval.ptrw(); + copymem(w, charstr.ptr(), len); + + return retval; +} + +Vector<uint8_t> String::to_utf8_buffer() const { + const String *s = this; + if (s->empty()) { + return Vector<uint8_t>(); + } + CharString charstr = s->utf8(); + + Vector<uint8_t> retval; + size_t len = charstr.length(); + retval.resize(len); + uint8_t *w = retval.ptrw(); + copymem(w, charstr.ptr(), len); + + return retval; +} + +Vector<uint8_t> String::to_utf16_buffer() const { + const String *s = this; + if (s->empty()) { + return Vector<uint8_t>(); + } + Char16String charstr = s->utf16(); + + Vector<uint8_t> retval; + size_t len = charstr.length() * 2; + retval.resize(len); + uint8_t *w = retval.ptrw(); + copymem(w, (const void *)charstr.ptr(), len); + + return retval; +} + +Vector<uint8_t> String::to_utf32_buffer() const { + const String *s = this; + if (s->empty()) { + return Vector<uint8_t>(); + } + + Vector<uint8_t> retval; + size_t len = s->length() * 4; + retval.resize(len); + uint8_t *w = retval.ptrw(); + copymem(w, (const void *)s->ptr(), len); + + return retval; +} + #ifdef TOOLS_ENABLED String TTR(const String &p_text, const String &p_context) { if (TranslationServer::get_singleton()) { diff --git a/core/ustring.h b/core/ustring.h index 1f8a5d7e7d..bf9c06b9ca 100644 --- a/core/ustring.h +++ b/core/ustring.h @@ -440,6 +440,11 @@ public: return *this; } + Vector<uint8_t> to_ascii_buffer() const; + Vector<uint8_t> to_utf8_buffer() const; + Vector<uint8_t> to_utf16_buffer() const; + Vector<uint8_t> to_utf32_buffer() const; + String(const char *p_str); String(const wchar_t *p_str); String(const char32_t *p_str); diff --git a/core/variant.h b/core/variant.h index 112003a7ae..84e5427b21 100644 --- a/core/variant.h +++ b/core/variant.h @@ -414,6 +414,45 @@ public: static void blend(const Variant &a, const Variant &b, float c, Variant &r_dst); static void interpolate(const Variant &a, const Variant &b, float c, Variant &r_dst); + class InternalMethod { +#ifdef DEBUG_ENABLED + protected: + StringName method_name; + Variant::Type base_type; +#endif + public: + enum Flags { + FLAG_IS_CONST = 1, + FLAG_RETURNS_VARIANT = 2, + FLAG_NO_PTRCALL = 4, + FLAG_VARARGS = 8 + }; + + virtual int get_argument_count() const = 0; + virtual Type get_argument_type(int p_arg) const = 0; + virtual Type get_return_type() const = 0; + virtual uint32_t get_flags() const = 0; + +#ifdef DEBUG_ENABLED + virtual String get_argument_name(int p_arg) const = 0; + StringName get_name() const { + return method_name; + } + Variant::Type get_base_type() const { + return base_type; + } +#endif + virtual Vector<Variant> get_default_arguments() const = 0; + virtual void call(Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) = 0; + virtual void validated_call(Variant *base, const Variant **p_args, Variant *r_ret) = 0; +#ifdef PTRCALL_ENABLED + virtual void ptrcall(void *p_base, const void **p_args, void *r_ret) = 0; +#endif + virtual ~InternalMethod() {} + }; + + static InternalMethod *get_internal_method(Type p_type, const StringName &p_method_name); + void call_ptr(const StringName &p_method, const Variant **p_args, int p_argcount, Variant *r_ret, Callable::CallError &r_error); Variant call(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error); Variant call(const StringName &p_method, const Variant &p_arg1 = Variant(), const Variant &p_arg2 = Variant(), const Variant &p_arg3 = Variant(), const Variant &p_arg4 = Variant(), const Variant &p_arg5 = Variant()); diff --git a/core/variant_call.cpp b/core/variant_call.cpp index 5fd970c8e1..b1a046a72c 100644 --- a/core/variant_call.cpp +++ b/core/variant_call.cpp @@ -30,1062 +30,645 @@ #include "variant.h" +#include "core/class_db.h" #include "core/color_names.inc" #include "core/core_string_names.h" #include "core/crypto/crypto_core.h" #include "core/debugger/engine_debugger.h" #include "core/io/compression.h" -#include "core/object.h" +#include "core/oa_hash_map.h" #include "core/os/os.h" +_FORCE_INLINE_ void sarray_add_str(Vector<String> &arr) { +} + +_FORCE_INLINE_ void sarray_add_str(Vector<String> &arr, const String &p_str) { + arr.push_back(p_str); +} + +template <class... P> +_FORCE_INLINE_ void sarray_add_str(Vector<String> &arr, const String &p_str, P... p_args) { + arr.push_back(p_str); + sarray_add_str(arr, p_args...); +} + +template <class... P> +_FORCE_INLINE_ Vector<String> sarray(P... p_args) { + Vector<String> arr; + sarray_add_str(arr, p_args...); + return arr; +} + typedef void (*VariantFunc)(Variant &r_ret, Variant &p_self, const Variant **p_args); typedef void (*VariantConstructFunc)(Variant &r_ret, const Variant **p_args); struct _VariantCall { - static void Vector3_dot(Variant &r_ret, Variant &p_self, const Variant **p_args) { - r_ret = reinterpret_cast<Vector3 *>(p_self._data._mem)->dot(*reinterpret_cast<const Vector3 *>(p_args[0]->_data._mem)); - } - - struct FuncData { - int arg_count; - Vector<Variant> default_args; - Vector<Variant::Type> arg_types; - Vector<StringName> arg_names; - Variant::Type return_type; + template <class T, class... P> + class InternalMethod : public Variant::InternalMethod { + public: + void (T::*method)(P...); + Vector<Variant> default_values; +#ifdef DEBUG_ENABLED + Vector<String> argument_names; +#endif - bool _const; - bool returns; + virtual int get_argument_count() const { + return sizeof...(P); + } + virtual Variant::Type get_argument_type(int p_arg) const { + return call_get_argument_type<P...>(p_arg); + } +#ifdef DEBUG_ENABLED + virtual String get_argument_name(int p_arg) const { + ERR_FAIL_INDEX_V(p_arg, argument_names.size(), String()); + return argument_names[p_arg]; + } +#endif + virtual Vector<Variant> get_default_arguments() const { + return default_values; + } - VariantFunc func; + virtual Variant::Type get_return_type() const { + return Variant::NIL; + } + virtual uint32_t get_flags() const { + return 0; + } - _FORCE_INLINE_ bool verify_arguments(const Variant **p_args, Callable::CallError &r_error) { - if (arg_count == 0) { - return true; - } + virtual void call(Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) { + call_with_variant_args_dv(VariantGetInternalPtr<T>::get_ptr(base), method, p_args, p_argcount, r_error, default_values); + } - const Variant::Type *tptr = &arg_types[0]; + virtual void validated_call(Variant *base, const Variant **p_args, Variant *r_ret) { + call_with_validated_variant_args(base, method, p_args); + } - for (int i = 0; i < arg_count; i++) { - if (tptr[i] == Variant::NIL || tptr[i] == p_args[i]->type) { - continue; // all good - } - if (!Variant::can_convert(p_args[i]->type, tptr[i])) { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; - r_error.argument = i; - r_error.expected = tptr[i]; - return false; - } - } - return true; +#ifdef PTRCALL_ENABLED + virtual void ptrcall(void *p_base, const void **p_args, void *r_ret) { + call_with_ptr_args<T, P...>(reinterpret_cast<T *>(p_base), method, p_args); } +#endif + InternalMethod(void (T::*p_method)(P...), const Vector<Variant> &p_default_args +#ifdef DEBUG_ENABLED + , + const Vector<String> &p_arg_names, const StringName &p_method_name, Variant::Type p_base_type +#endif + ) { + method = p_method; + default_values = p_default_args; +#ifdef DEBUG_ENABLED + argument_names = p_arg_names; + method_name = p_method_name; + base_type = p_base_type; +#endif + } + }; - _FORCE_INLINE_ void call(Variant &r_ret, Variant &p_self, const Variant **p_args, int p_argcount, Callable::CallError &r_error) { + template <class T, class R, class... P> + class InternalMethodR : public Variant::InternalMethod { + public: + R(T::*method) + (P...); + Vector<Variant> default_values; #ifdef DEBUG_ENABLED - if (p_argcount > arg_count) { - r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS; - r_error.argument = arg_count; - return; - } else + Vector<String> argument_names; #endif - if (p_argcount < arg_count) { - int def_argcount = default_args.size(); + + virtual int get_argument_count() const { + return sizeof...(P); + } + virtual Variant::Type get_argument_type(int p_arg) const { + return call_get_argument_type<P...>(p_arg); + return Variant::NIL; + } #ifdef DEBUG_ENABLED - if (p_argcount < (arg_count - def_argcount)) { - r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; - r_error.argument = arg_count - def_argcount; - return; - } + virtual String get_argument_name(int p_arg) const { + ERR_FAIL_INDEX_V(p_arg, argument_names.size(), String()); + return argument_names[p_arg]; + } +#endif + virtual Vector<Variant> get_default_arguments() const { + return default_values; + } + virtual Variant::Type get_return_type() const { + return GetTypeInfo<R>::VARIANT_TYPE; + } + virtual uint32_t get_flags() const { + uint32_t f = 0; + if (get_return_type() == Variant::NIL) { + f |= FLAG_RETURNS_VARIANT; + } + return f; + } + + virtual void call(Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) { + call_with_variant_args_ret_dv(VariantGetInternalPtr<T>::get_ptr(base), method, p_args, p_argcount, r_ret, r_error, default_values); + } + + virtual void validated_call(Variant *base, const Variant **p_args, Variant *r_ret) { + call_with_validated_variant_args_ret(base, method, p_args, r_ret); + } +#ifdef PTRCALL_ENABLED + virtual void ptrcall(void *p_base, const void **p_args, void *r_ret) { + call_with_ptr_args_ret<T, R, P...>(reinterpret_cast<T *>(p_base), method, p_args, r_ret); + } #endif - ERR_FAIL_COND(p_argcount > VARIANT_ARG_MAX); - const Variant *newargs[VARIANT_ARG_MAX]; - for (int i = 0; i < p_argcount; i++) { - newargs[i] = p_args[i]; - } - // fill in any remaining parameters with defaults - int first_default_arg = arg_count - def_argcount; - for (int i = p_argcount; i < arg_count; i++) { - newargs[i] = &default_args[i - first_default_arg]; - } + InternalMethodR(R (T::*p_method)(P...), const Vector<Variant> &p_default_args #ifdef DEBUG_ENABLED - if (!verify_arguments(newargs, r_error)) { - return; - } + , + const Vector<String> &p_arg_names, const StringName &p_method_name, Variant::Type p_base_type #endif - func(r_ret, p_self, newargs); - } else { + ) { + method = p_method; + default_values = p_default_args; #ifdef DEBUG_ENABLED - if (!verify_arguments(p_args, r_error)) { - return; - } + argument_names = p_arg_names; + method_name = p_method_name; + base_type = p_base_type; #endif - func(r_ret, p_self, p_args); - } } }; - struct TypeFunc { - Map<StringName, FuncData> functions; - }; + template <class T, class R, class... P> + class InternalMethodRC : public Variant::InternalMethod { + public: + R(T::*method) + (P...) const; + Vector<Variant> default_values; +#ifdef DEBUG_ENABLED + Vector<String> argument_names; +#endif - static TypeFunc *type_funcs; + virtual int get_argument_count() const { + return sizeof...(P); + } + virtual Variant::Type get_argument_type(int p_arg) const { + return call_get_argument_type<P...>(p_arg); + } +#ifdef DEBUG_ENABLED + virtual String get_argument_name(int p_arg) const { + ERR_FAIL_INDEX_V(p_arg, argument_names.size(), String()); + return argument_names[p_arg]; + } +#endif + virtual Vector<Variant> get_default_arguments() const { + return default_values; + } - struct Arg { - StringName name; - Variant::Type type; - Arg() { type = Variant::NIL; } - Arg(Variant::Type p_type, const StringName &p_name) : - name(p_name), - type(p_type) { + virtual Variant::Type get_return_type() const { + return GetTypeInfo<R>::VARIANT_TYPE; + } + virtual uint32_t get_flags() const { + uint32_t f = FLAG_IS_CONST; + if (get_return_type() == Variant::NIL) { + f |= FLAG_RETURNS_VARIANT; + } + return f; } - }; - //void addfunc(Variant::Type p_type, const StringName& p_name,VariantFunc p_func); + virtual void call(Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) { + call_with_variant_args_retc_dv(VariantGetInternalPtr<T>::get_ptr(base), method, p_args, p_argcount, r_ret, r_error, default_values); + } - static void make_func_return_variant(Variant::Type p_type, const StringName &p_name) { + virtual void validated_call(Variant *base, const Variant **p_args, Variant *r_ret) { + call_with_validated_variant_args_retc(base, method, p_args, r_ret); + } +#ifdef PTRCALL_ENABLED + virtual void ptrcall(void *p_base, const void **p_args, void *r_ret) { + call_with_ptr_args_retc<T, R, P...>(reinterpret_cast<T *>(p_base), method, p_args, r_ret); + } +#endif + InternalMethodRC(R (T::*p_method)(P...) const, const Vector<Variant> &p_default_args #ifdef DEBUG_ENABLED - type_funcs[p_type].functions[p_name].returns = true; + , + const Vector<String> &p_arg_names, const StringName &p_method_name, Variant::Type p_base_type #endif - } - - static void addfunc(bool p_const, Variant::Type p_type, Variant::Type p_return, bool p_has_return, const StringName &p_name, VariantFunc p_func, const Vector<Variant> &p_defaultarg, const Arg &p_argtype1 = Arg(), const Arg &p_argtype2 = Arg(), const Arg &p_argtype3 = Arg(), const Arg &p_argtype4 = Arg(), const Arg &p_argtype5 = Arg()) { - FuncData funcdata; - funcdata.func = p_func; - funcdata.default_args = p_defaultarg; - funcdata._const = p_const; - funcdata.returns = p_has_return; - funcdata.return_type = p_return; + ) { + method = p_method; + default_values = p_default_args; +#ifdef DEBUG_ENABLED + argument_names = p_arg_names; + method_name = p_method_name; + base_type = p_base_type; +#endif + } + }; - if (p_argtype1.name) { - funcdata.arg_types.push_back(p_argtype1.type); + template <class T, class R, class... P> + class InternalMethodRS : public Variant::InternalMethod { + public: + R(*method) + (T *, P...); + Vector<Variant> default_values; #ifdef DEBUG_ENABLED - funcdata.arg_names.push_back(p_argtype1.name); + Vector<String> argument_names; #endif - } else { - goto end; + virtual int get_argument_count() const { + return sizeof...(P); + } + virtual Variant::Type get_argument_type(int p_arg) const { + return call_get_argument_type<P...>(p_arg); } - - if (p_argtype2.name) { - funcdata.arg_types.push_back(p_argtype2.type); #ifdef DEBUG_ENABLED - funcdata.arg_names.push_back(p_argtype2.name); + virtual String get_argument_name(int p_arg) const { + ERR_FAIL_INDEX_V(p_arg, argument_names.size(), String()); + return argument_names[p_arg]; + } #endif + virtual Vector<Variant> get_default_arguments() const { + return default_values; + } - } else { - goto end; + virtual Variant::Type get_return_type() const { + return GetTypeInfo<R>::VARIANT_TYPE; + } + virtual uint32_t get_flags() const { + uint32_t f = 0; + if (get_return_type() == Variant::NIL) { + f |= FLAG_RETURNS_VARIANT; + } + return f; } - if (p_argtype3.name) { - funcdata.arg_types.push_back(p_argtype3.type); + virtual void call(Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) { + const Variant **args = p_args; #ifdef DEBUG_ENABLED - funcdata.arg_names.push_back(p_argtype3.name); + if ((size_t)p_argcount > sizeof...(P)) { + r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS; + r_error.argument = sizeof...(P); + return; + } #endif - - } else { - goto end; + if ((size_t)p_argcount < sizeof...(P)) { + size_t missing = sizeof...(P) - (size_t)p_argcount; + if (missing <= (size_t)default_values.size()) { + args = (const Variant **)alloca(sizeof...(P) * sizeof(const Variant *)); + // GCC fails to see that `sizeof...(P)` cannot be 0 here given the previous + // conditions, so it raises a warning on the potential use of `i < 0` as the + // execution condition. +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wtype-limits" +#endif + for (size_t i = 0; i < sizeof...(P); i++) { + if (i < (size_t)p_argcount) { + args[i] = p_args[i]; + } else { + args[i] = &default_values[i - p_argcount + (default_values.size() - missing)]; + } + } +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic pop +#endif + } else { +#ifdef DEBUG_ENABLED + r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; + r_error.argument = sizeof...(P); +#endif + return; + } + } + call_with_variant_args_retc_static_helper(VariantGetInternalPtr<T>::get_ptr(base), method, args, r_ret, r_error, BuildIndexSequence<sizeof...(P)>{}); } - if (p_argtype4.name) { - funcdata.arg_types.push_back(p_argtype4.type); + virtual void validated_call(Variant *base, const Variant **p_args, Variant *r_ret) { + call_with_validated_variant_args_static_retc(base, method, p_args, r_ret); + } +#ifdef PTRCALL_ENABLED + virtual void ptrcall(void *p_base, const void **p_args, void *r_ret) { + call_with_ptr_args_static_retc<T, R, P...>(reinterpret_cast<T *>(p_base), method, p_args, r_ret); + } +#endif + InternalMethodRS(R (*p_method)(T *, P...), const Vector<Variant> &p_default_args #ifdef DEBUG_ENABLED - funcdata.arg_names.push_back(p_argtype4.name); + , + const Vector<String> &p_arg_names, const StringName &p_method_name, Variant::Type p_base_type +#endif + ) { + method = p_method; + default_values = p_default_args; +#ifdef DEBUG_ENABLED + argument_names = p_arg_names; + method_name = p_method_name; + base_type = p_base_type; #endif - } else { - goto end; } + }; - if (p_argtype5.name) { - funcdata.arg_types.push_back(p_argtype5.type); + class InternalMethodVC : public Variant::InternalMethod { + public: + typedef void (*MethodVC)(Variant *, const Variant **, int, Variant &r_ret, Callable::CallError &); + MethodVC methodvc = nullptr; + uint32_t base_flags = 0; + Vector<String> argument_names; + Vector<Variant::Type> argument_types; + Variant::Type return_type = Variant::NIL; + + virtual int get_argument_count() const { + return argument_names.size(); + } + virtual Variant::Type get_argument_type(int p_arg) const { + ERR_FAIL_INDEX_V(p_arg, argument_types.size(), Variant::NIL); + return argument_types[p_arg]; + } #ifdef DEBUG_ENABLED - funcdata.arg_names.push_back(p_argtype5.name); + virtual String get_argument_name(int p_arg) const { + ERR_FAIL_INDEX_V(p_arg, argument_names.size(), String()); + return argument_names[p_arg]; + } #endif - } else { - goto end; + virtual Vector<Variant> get_default_arguments() const { + return Vector<Variant>(); } - end: + virtual Variant::Type get_return_type() const { + return return_type; + } + virtual uint32_t get_flags() const { + return base_flags | FLAG_NO_PTRCALL; + } - funcdata.arg_count = funcdata.arg_types.size(); - type_funcs[p_type].functions[p_name] = funcdata; - } - -#define VCALL_LOCALMEM0(m_type, m_method) \ - static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { reinterpret_cast<m_type *>(p_self._data._mem)->m_method(); } -#define VCALL_LOCALMEM0R(m_type, m_method) \ - static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { r_ret = reinterpret_cast<m_type *>(p_self._data._mem)->m_method(); } -#define VCALL_LOCALMEM1(m_type, m_method) \ - static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { reinterpret_cast<m_type *>(p_self._data._mem)->m_method(*p_args[0]); } -#define VCALL_LOCALMEM1R(m_type, m_method) \ - static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { r_ret = reinterpret_cast<m_type *>(p_self._data._mem)->m_method(*p_args[0]); } -#define VCALL_LOCALMEM2(m_type, m_method) \ - static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { reinterpret_cast<m_type *>(p_self._data._mem)->m_method(*p_args[0], *p_args[1]); } -#define VCALL_LOCALMEM2R(m_type, m_method) \ - static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { r_ret = reinterpret_cast<m_type *>(p_self._data._mem)->m_method(*p_args[0], *p_args[1]); } -#define VCALL_LOCALMEM3(m_type, m_method) \ - static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { reinterpret_cast<m_type *>(p_self._data._mem)->m_method(*p_args[0], *p_args[1], *p_args[2]); } -#define VCALL_LOCALMEM3R(m_type, m_method) \ - static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { r_ret = reinterpret_cast<m_type *>(p_self._data._mem)->m_method(*p_args[0], *p_args[1], *p_args[2]); } -#define VCALL_LOCALMEM4(m_type, m_method) \ - static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { reinterpret_cast<m_type *>(p_self._data._mem)->m_method(*p_args[0], *p_args[1], *p_args[2], *p_args[3]); } -#define VCALL_LOCALMEM4R(m_type, m_method) \ - static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { r_ret = reinterpret_cast<m_type *>(p_self._data._mem)->m_method(*p_args[0], *p_args[1], *p_args[2], *p_args[3]); } -#define VCALL_LOCALMEM5(m_type, m_method) \ - static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { reinterpret_cast<m_type *>(p_self._data._mem)->m_method(*p_args[0], *p_args[1], *p_args[2], *p_args[3], *p_args[4]); } -#define VCALL_LOCALMEM5R(m_type, m_method) \ - static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { r_ret = reinterpret_cast<m_type *>(p_self._data._mem)->m_method(*p_args[0], *p_args[1], *p_args[2], *p_args[3], *p_args[4]); } - - // built-in functions of localmem based types - - VCALL_LOCALMEM1R(String, casecmp_to); - VCALL_LOCALMEM1R(String, nocasecmp_to); - VCALL_LOCALMEM1R(String, naturalnocasecmp_to); - VCALL_LOCALMEM0R(String, length); - VCALL_LOCALMEM3R(String, count); - VCALL_LOCALMEM3R(String, countn); - VCALL_LOCALMEM2R(String, substr); - VCALL_LOCALMEM2R(String, find); - VCALL_LOCALMEM2R(String, findn); - VCALL_LOCALMEM2R(String, rfind); - VCALL_LOCALMEM2R(String, rfindn); - VCALL_LOCALMEM1R(String, match); - VCALL_LOCALMEM1R(String, matchn); - VCALL_LOCALMEM1R(String, begins_with); - VCALL_LOCALMEM1R(String, ends_with); - VCALL_LOCALMEM1R(String, is_subsequence_of); - VCALL_LOCALMEM1R(String, is_subsequence_ofi); - VCALL_LOCALMEM0R(String, bigrams); - VCALL_LOCALMEM1R(String, similarity); - VCALL_LOCALMEM2R(String, format); - VCALL_LOCALMEM2R(String, replace); - VCALL_LOCALMEM2R(String, replacen); - VCALL_LOCALMEM1R(String, repeat); - VCALL_LOCALMEM2R(String, insert); - VCALL_LOCALMEM0R(String, capitalize); - VCALL_LOCALMEM3R(String, split); - VCALL_LOCALMEM3R(String, rsplit); - VCALL_LOCALMEM2R(String, split_floats); - VCALL_LOCALMEM1R(String, join); - VCALL_LOCALMEM0R(String, to_upper); - VCALL_LOCALMEM0R(String, to_lower); - VCALL_LOCALMEM1R(String, left); - VCALL_LOCALMEM1R(String, right); - VCALL_LOCALMEM0R(String, dedent); - VCALL_LOCALMEM2R(String, strip_edges); - VCALL_LOCALMEM0R(String, strip_escapes); - VCALL_LOCALMEM1R(String, lstrip); - VCALL_LOCALMEM1R(String, rstrip); - VCALL_LOCALMEM0R(String, get_extension); - VCALL_LOCALMEM0R(String, get_basename); - VCALL_LOCALMEM1R(String, plus_file); - VCALL_LOCALMEM1R(String, ord_at); - VCALL_LOCALMEM2(String, erase); - VCALL_LOCALMEM0R(String, hash); - VCALL_LOCALMEM0R(String, md5_text); - VCALL_LOCALMEM0R(String, sha1_text); - VCALL_LOCALMEM0R(String, sha256_text); - VCALL_LOCALMEM0R(String, md5_buffer); - VCALL_LOCALMEM0R(String, sha1_buffer); - VCALL_LOCALMEM0R(String, sha256_buffer); - VCALL_LOCALMEM0R(String, empty); - VCALL_LOCALMEM1R(String, humanize_size); - VCALL_LOCALMEM0R(String, is_abs_path); - VCALL_LOCALMEM0R(String, is_rel_path); - VCALL_LOCALMEM0R(String, get_base_dir); - VCALL_LOCALMEM0R(String, get_file); - VCALL_LOCALMEM0R(String, xml_escape); - VCALL_LOCALMEM0R(String, xml_unescape); - VCALL_LOCALMEM0R(String, http_escape); - VCALL_LOCALMEM0R(String, http_unescape); - VCALL_LOCALMEM0R(String, c_escape); - VCALL_LOCALMEM0R(String, c_unescape); - VCALL_LOCALMEM0R(String, json_escape); - VCALL_LOCALMEM0R(String, percent_encode); - VCALL_LOCALMEM0R(String, percent_decode); - VCALL_LOCALMEM0R(String, is_valid_identifier); - VCALL_LOCALMEM0R(String, is_valid_integer); - VCALL_LOCALMEM0R(String, is_valid_float); - VCALL_LOCALMEM1R(String, is_valid_hex_number); - VCALL_LOCALMEM0R(String, is_valid_html_color); - VCALL_LOCALMEM0R(String, is_valid_ip_address); - VCALL_LOCALMEM0R(String, is_valid_filename); - VCALL_LOCALMEM0R(String, to_int); - VCALL_LOCALMEM0R(String, to_float); - VCALL_LOCALMEM0R(String, hex_to_int); - VCALL_LOCALMEM2R(String, lpad); - VCALL_LOCALMEM2R(String, rpad); - VCALL_LOCALMEM1R(String, pad_decimals); - VCALL_LOCALMEM1R(String, pad_zeros); - VCALL_LOCALMEM1R(String, trim_prefix); - VCALL_LOCALMEM1R(String, trim_suffix); - - static void _call_String_to_ascii(Variant &r_ret, Variant &p_self, const Variant **p_args) { - String *s = reinterpret_cast<String *>(p_self._data._mem); - if (s->empty()) { - r_ret = PackedByteArray(); - return; + virtual void call(Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) { + methodvc(base, p_args, p_argcount, r_ret, r_error); } - CharString charstr = s->ascii(); - PackedByteArray retval; - size_t len = charstr.length(); - retval.resize(len); - uint8_t *w = retval.ptrw(); - copymem(w, charstr.ptr(), len); + virtual void validated_call(Variant *base, const Variant **p_args, Variant *r_ret) { + ERR_FAIL_MSG("No support for validated call"); + } +#ifdef PTRCALL_ENABLED + virtual void ptrcall(void *p_base, const void **p_args, void *r_ret) { + ERR_FAIL_MSG("No support for ptrcall call"); + } +#endif + InternalMethodVC(MethodVC p_method, uint32_t p_flags, const Vector<Variant::Type> &p_argument_types, const Variant::Type &p_return_type +#ifdef DEBUG_ENABLED + , + const Vector<String> &p_arg_names, const StringName &p_method_name, Variant::Type p_base_type +#endif + ) { + methodvc = p_method; + argument_types = p_argument_types; + return_type = p_return_type; + base_flags = p_flags; +#ifdef DEBUG_ENABLED + argument_names = p_arg_names; + method_name = p_method_name; + base_type = p_base_type; +#endif + } + }; - r_ret = retval; - } + typedef OAHashMap<StringName, Variant::InternalMethod *> MethodMap; + static MethodMap *type_internal_methods; + static List<StringName> *type_internal_method_names; - static void _call_String_to_utf8(Variant &r_ret, Variant &p_self, const Variant **p_args) { - String *s = reinterpret_cast<String *>(p_self._data._mem); - if (s->empty()) { - r_ret = PackedByteArray(); - return; - } - CharString charstr = s->utf8(); + template <class T, class... P> + static void _bind_method(const StringName &p_name, void (T::*p_method)(P...), const Vector<Variant> &p_default_args = Vector<Variant>() +#ifdef DEBUG_ENABLED + , + const Vector<String> &p_argument_names = Vector<String>() +#endif + ) { - PackedByteArray retval; - size_t len = charstr.length(); - retval.resize(len); - uint8_t *w = retval.ptrw(); - copymem(w, charstr.ptr(), len); +#ifdef DEBUG_ENABLED + ERR_FAIL_COND_MSG(p_argument_names.size() != sizeof...(P), "Wrong argument name count supplied for method: " + Variant::get_type_name(GetTypeInfo<T>::VARIANT_TYPE) + "::" + String(p_name)); + ERR_FAIL_COND(type_internal_methods[GetTypeInfo<T>::VARIANT_TYPE].has(p_name)); +#endif +#ifdef DEBUG_ENABLED + Variant::InternalMethod *m = memnew((InternalMethod<T, P...>)(p_method, p_default_args, p_argument_names, p_name, GetTypeInfo<T>::VARIANT_TYPE)); +#else + Variant::InternalMethod *m = memnew((InternalMethod<T, P...>)(p_method, p_default_args)); +#endif - r_ret = retval; + type_internal_methods[GetTypeInfo<T>::VARIANT_TYPE].insert(p_name, m); + type_internal_method_names[GetTypeInfo<T>::VARIANT_TYPE].push_back(p_name); } - static void _call_String_to_utf16(Variant &r_ret, Variant &p_self, const Variant **p_args) { - String *s = reinterpret_cast<String *>(p_self._data._mem); - if (s->empty()) { - r_ret = PackedByteArray(); - return; - } - Char16String charstr = s->utf16(); + template <class T, class R, class... P> + static void _bind_method(const StringName &p_name, R (T::*p_method)(P...) const, const Vector<Variant> &p_default_args = Vector<Variant>() +#ifdef DEBUG_ENABLED + , + const Vector<String> &p_argument_names = Vector<String>() +#endif + ) { +#ifdef DEBUG_ENABLED + ERR_FAIL_COND_MSG(p_argument_names.size() != sizeof...(P), "Wrong argument name count supplied for method: " + Variant::get_type_name(GetTypeInfo<T>::VARIANT_TYPE) + "::" + String(p_name)); + ERR_FAIL_COND_MSG(type_internal_methods[GetTypeInfo<T>::VARIANT_TYPE].has(p_name), " Method already registered: " + Variant::get_type_name(GetTypeInfo<T>::VARIANT_TYPE) + "::" + String(p_name)); - PackedByteArray retval; - size_t len = charstr.length() * 2; - retval.resize(len); - uint8_t *w = retval.ptrw(); - copymem(w, (const void *)charstr.ptr(), len); +#endif +#ifdef DEBUG_ENABLED + Variant::InternalMethod *m = memnew((InternalMethodRC<T, R, P...>)(p_method, p_default_args, p_argument_names, p_name, GetTypeInfo<T>::VARIANT_TYPE)); +#else + Variant::InternalMethod *m = memnew((InternalMethodRC<T, R, P...>)(p_method, p_default_args)); +#endif - r_ret = retval; + type_internal_methods[GetTypeInfo<T>::VARIANT_TYPE].insert(p_name, m); + type_internal_method_names[GetTypeInfo<T>::VARIANT_TYPE].push_back(p_name); } - static void _call_String_to_utf32(Variant &r_ret, Variant &p_self, const Variant **p_args) { - String *s = reinterpret_cast<String *>(p_self._data._mem); - if (s->empty()) { - r_ret = PackedByteArray(); - return; - } + template <class T, class R, class... P> + static void _bind_method(const StringName &p_name, R (T::*p_method)(P...), const Vector<Variant> &p_default_args = Vector<Variant>() +#ifdef DEBUG_ENABLED + , + const Vector<String> &p_argument_names = Vector<String>() +#endif + ) { +#ifdef DEBUG_ENABLED + ERR_FAIL_COND_MSG(p_argument_names.size() != sizeof...(P), "Wrong argument name count supplied for method: " + Variant::get_type_name(GetTypeInfo<T>::VARIANT_TYPE) + "::" + String(p_name)); + ERR_FAIL_COND_MSG(type_internal_methods[GetTypeInfo<T>::VARIANT_TYPE].has(p_name), " Method already registered: " + Variant::get_type_name(GetTypeInfo<T>::VARIANT_TYPE) + "::" + String(p_name)); +#endif - PackedByteArray retval; - size_t len = s->length() * 4; - retval.resize(len); - uint8_t *w = retval.ptrw(); - copymem(w, (const void *)s->ptr(), len); - - r_ret = retval; - } - - VCALL_LOCALMEM1R(Vector2, distance_to); - VCALL_LOCALMEM1R(Vector2, distance_squared_to); - VCALL_LOCALMEM0R(Vector2, length); - VCALL_LOCALMEM0R(Vector2, length_squared); - VCALL_LOCALMEM0R(Vector2, normalized); - VCALL_LOCALMEM0R(Vector2, is_normalized); - VCALL_LOCALMEM1R(Vector2, is_equal_approx); - VCALL_LOCALMEM1R(Vector2, posmod); - VCALL_LOCALMEM1R(Vector2, posmodv); - VCALL_LOCALMEM1R(Vector2, project); - VCALL_LOCALMEM1R(Vector2, angle_to); - VCALL_LOCALMEM1R(Vector2, angle_to_point); - VCALL_LOCALMEM1R(Vector2, direction_to); - VCALL_LOCALMEM2R(Vector2, lerp); - VCALL_LOCALMEM2R(Vector2, slerp); - VCALL_LOCALMEM4R(Vector2, cubic_interpolate); - VCALL_LOCALMEM2R(Vector2, move_toward); - VCALL_LOCALMEM1R(Vector2, rotated); - VCALL_LOCALMEM0R(Vector2, tangent); - VCALL_LOCALMEM0R(Vector2, floor); - VCALL_LOCALMEM0R(Vector2, ceil); - VCALL_LOCALMEM0R(Vector2, round); - VCALL_LOCALMEM1R(Vector2, snapped); - VCALL_LOCALMEM0R(Vector2, aspect); - VCALL_LOCALMEM1R(Vector2, dot); - VCALL_LOCALMEM1R(Vector2, slide); - VCALL_LOCALMEM1R(Vector2, bounce); - VCALL_LOCALMEM1R(Vector2, reflect); - VCALL_LOCALMEM0R(Vector2, angle); - VCALL_LOCALMEM1R(Vector2, cross); - VCALL_LOCALMEM0R(Vector2, abs); - VCALL_LOCALMEM1R(Vector2, clamped); - VCALL_LOCALMEM0R(Vector2, sign); - - VCALL_LOCALMEM0R(Vector2i, aspect); - VCALL_LOCALMEM0R(Vector2i, sign); - VCALL_LOCALMEM0R(Vector2i, abs); - - VCALL_LOCALMEM0R(Rect2, get_area); - VCALL_LOCALMEM0R(Rect2, has_no_area); - VCALL_LOCALMEM1R(Rect2, has_point); - VCALL_LOCALMEM1R(Rect2, is_equal_approx); - VCALL_LOCALMEM2R(Rect2, intersects); - VCALL_LOCALMEM1R(Rect2, encloses); - VCALL_LOCALMEM1R(Rect2, clip); - VCALL_LOCALMEM1R(Rect2, merge); - VCALL_LOCALMEM1R(Rect2, expand); - VCALL_LOCALMEM1R(Rect2, grow); - VCALL_LOCALMEM2R(Rect2, grow_margin); - VCALL_LOCALMEM4R(Rect2, grow_individual); - VCALL_LOCALMEM0R(Rect2, abs); - - VCALL_LOCALMEM0R(Rect2i, get_area); - VCALL_LOCALMEM0R(Rect2i, has_no_area); - VCALL_LOCALMEM1R(Rect2i, has_point); - VCALL_LOCALMEM1R(Rect2i, intersects); - VCALL_LOCALMEM1R(Rect2i, encloses); - VCALL_LOCALMEM1R(Rect2i, clip); - VCALL_LOCALMEM1R(Rect2i, merge); - VCALL_LOCALMEM1R(Rect2i, expand); - VCALL_LOCALMEM1R(Rect2i, grow); - VCALL_LOCALMEM2R(Rect2i, grow_margin); - VCALL_LOCALMEM4R(Rect2i, grow_individual); - VCALL_LOCALMEM0R(Rect2i, abs); - - VCALL_LOCALMEM0R(Vector3, min_axis); - VCALL_LOCALMEM0R(Vector3, max_axis); - VCALL_LOCALMEM1R(Vector3, distance_to); - VCALL_LOCALMEM1R(Vector3, distance_squared_to); - VCALL_LOCALMEM0R(Vector3, length); - VCALL_LOCALMEM0R(Vector3, length_squared); - VCALL_LOCALMEM0R(Vector3, normalized); - VCALL_LOCALMEM0R(Vector3, is_normalized); - VCALL_LOCALMEM1R(Vector3, is_equal_approx); - VCALL_LOCALMEM0R(Vector3, inverse); - VCALL_LOCALMEM1R(Vector3, snapped); - VCALL_LOCALMEM2R(Vector3, rotated); - VCALL_LOCALMEM2R(Vector3, lerp); - VCALL_LOCALMEM2R(Vector3, slerp); - VCALL_LOCALMEM4R(Vector3, cubic_interpolate); - VCALL_LOCALMEM2R(Vector3, move_toward); - VCALL_LOCALMEM1R(Vector3, dot); - VCALL_LOCALMEM1R(Vector3, cross); - VCALL_LOCALMEM1R(Vector3, outer); - VCALL_LOCALMEM0R(Vector3, to_diagonal_matrix); - VCALL_LOCALMEM0R(Vector3, abs); - VCALL_LOCALMEM0R(Vector3, floor); - VCALL_LOCALMEM0R(Vector3, ceil); - VCALL_LOCALMEM0R(Vector3, round); - VCALL_LOCALMEM1R(Vector3, posmod); - VCALL_LOCALMEM1R(Vector3, posmodv); - VCALL_LOCALMEM1R(Vector3, project); - VCALL_LOCALMEM1R(Vector3, angle_to); - VCALL_LOCALMEM1R(Vector3, direction_to); - VCALL_LOCALMEM1R(Vector3, slide); - VCALL_LOCALMEM1R(Vector3, bounce); - VCALL_LOCALMEM1R(Vector3, reflect); - VCALL_LOCALMEM0R(Vector3, sign); - - VCALL_LOCALMEM0R(Vector3i, min_axis); - VCALL_LOCALMEM0R(Vector3i, max_axis); - VCALL_LOCALMEM0R(Vector3i, sign); - - VCALL_LOCALMEM0R(Plane, normalized); - VCALL_LOCALMEM0R(Plane, center); - VCALL_LOCALMEM1R(Plane, is_equal_approx); - VCALL_LOCALMEM1R(Plane, is_point_over); - VCALL_LOCALMEM1R(Plane, distance_to); - VCALL_LOCALMEM2R(Plane, has_point); - VCALL_LOCALMEM1R(Plane, project); - - //return vector3 if intersected, nil if not - static void _call_Plane_intersect_3(Variant &r_ret, Variant &p_self, const Variant **p_args) { - Vector3 result; - if (reinterpret_cast<Plane *>(p_self._data._mem)->intersect_3(*p_args[0], *p_args[1], &result)) { - r_ret = result; - } else { - r_ret = Variant(); - } +#ifdef DEBUG_ENABLED + Variant::InternalMethod *m = memnew((InternalMethodR<T, R, P...>)(p_method, p_default_args, p_argument_names, p_name, GetTypeInfo<T>::VARIANT_TYPE)); +#else + Variant::InternalMethod *m = memnew((InternalMethodR<T, R, P...>)(p_method, p_default_args)); +#endif + type_internal_methods[GetTypeInfo<T>::VARIANT_TYPE].insert(p_name, m); + type_internal_method_names[GetTypeInfo<T>::VARIANT_TYPE].push_back(p_name); } - static void _call_Plane_intersects_ray(Variant &r_ret, Variant &p_self, const Variant **p_args) { - Vector3 result; - if (reinterpret_cast<Plane *>(p_self._data._mem)->intersects_ray(*p_args[0], *p_args[1], &result)) { - r_ret = result; - } else { - r_ret = Variant(); - } +#ifdef DEBUG_ENABLED +#define bind_method(m_type, m_method, m_arg_names, m_default_args) _VariantCall::_bind_method(#m_method, &m_type ::m_method, m_default_args, m_arg_names) +#else +#define bind_method(m_type, m_method, m_arg_names, m_default_args) _VariantCall::_bind_method(#m_method, &m_type ::m_method, m_default_args) +#endif + +#ifdef DEBUG_ENABLED +#define bind_methodv(m_name, m_method, m_arg_names, m_default_args) _VariantCall::_bind_method(#m_name, m_method, m_default_args, m_arg_names) +#else +#define bind_methodv(m_name, m_method, m_arg_names, m_default_args) _VariantCall::_bind_method(#m_name, m_method, m_default_args) +#endif + + template <class T, class R, class... P> + static void _bind_function(const StringName &p_name, R (*p_method)(T *, P...), const Vector<Variant> &p_default_args = Vector<Variant>() +#ifdef DEBUG_ENABLED + , + const Vector<String> &p_argument_names = Vector<String>() +#endif + ) { +#ifdef DEBUG_ENABLED + ERR_FAIL_COND_MSG(p_argument_names.size() != sizeof...(P), "Wrong argument name count supplied for method: " + Variant::get_type_name(GetTypeInfo<T>::VARIANT_TYPE) + "::" + String(p_name)); + ERR_FAIL_COND_MSG(type_internal_methods[GetTypeInfo<T>::VARIANT_TYPE].has(p_name), " Method already registered: " + Variant::get_type_name(GetTypeInfo<T>::VARIANT_TYPE) + "::" + String(p_name)); +#endif + +#ifdef DEBUG_ENABLED + Variant::InternalMethod *m = memnew((InternalMethodRS<T, R, P...>)(p_method, p_default_args, p_argument_names, p_name, GetTypeInfo<T>::VARIANT_TYPE)); +#else + Variant::InternalMethod *m = memnew((InternalMethodRS<T, R, P...>)(p_method, p_default_args)); +#endif + + type_internal_methods[GetTypeInfo<T>::VARIANT_TYPE].insert(p_name, m); + type_internal_method_names[GetTypeInfo<T>::VARIANT_TYPE].push_back(p_name); } - static void _call_Plane_intersects_segment(Variant &r_ret, Variant &p_self, const Variant **p_args) { - Vector3 result; - if (reinterpret_cast<Plane *>(p_self._data._mem)->intersects_segment(*p_args[0], *p_args[1], &result)) { - r_ret = result; - } else { - r_ret = Variant(); - } - } - - VCALL_LOCALMEM0R(Quat, length); - VCALL_LOCALMEM0R(Quat, length_squared); - VCALL_LOCALMEM0R(Quat, normalized); - VCALL_LOCALMEM0R(Quat, is_normalized); - VCALL_LOCALMEM1R(Quat, is_equal_approx); - VCALL_LOCALMEM0R(Quat, inverse); - VCALL_LOCALMEM1R(Quat, dot); - VCALL_LOCALMEM1R(Quat, xform); - VCALL_LOCALMEM2R(Quat, slerp); - VCALL_LOCALMEM2R(Quat, slerpni); - VCALL_LOCALMEM4R(Quat, cubic_slerp); - VCALL_LOCALMEM0R(Quat, get_euler); - VCALL_LOCALMEM1(Quat, set_euler); - VCALL_LOCALMEM2(Quat, set_axis_angle); - - VCALL_LOCALMEM0R(Color, to_argb32); - VCALL_LOCALMEM0R(Color, to_abgr32); - VCALL_LOCALMEM0R(Color, to_rgba32); - VCALL_LOCALMEM0R(Color, to_argb64); - VCALL_LOCALMEM0R(Color, to_abgr64); - VCALL_LOCALMEM0R(Color, to_rgba64); - VCALL_LOCALMEM0R(Color, inverted); - VCALL_LOCALMEM0R(Color, contrasted); - VCALL_LOCALMEM2R(Color, lerp); - VCALL_LOCALMEM1R(Color, blend); - VCALL_LOCALMEM1R(Color, lightened); - VCALL_LOCALMEM1R(Color, darkened); - VCALL_LOCALMEM1R(Color, to_html); - VCALL_LOCALMEM4R(Color, from_hsv); - VCALL_LOCALMEM1R(Color, is_equal_approx); - - VCALL_LOCALMEM0R(RID, get_id); - - VCALL_LOCALMEM0R(NodePath, is_absolute); - VCALL_LOCALMEM0R(NodePath, get_name_count); - VCALL_LOCALMEM1R(NodePath, get_name); - VCALL_LOCALMEM0R(NodePath, get_subname_count); - VCALL_LOCALMEM1R(NodePath, get_subname); - VCALL_LOCALMEM0R(NodePath, get_concatenated_subnames); - VCALL_LOCALMEM0R(NodePath, get_as_property_path); - VCALL_LOCALMEM0R(NodePath, is_empty); - - VCALL_LOCALMEM0R(Dictionary, size); - VCALL_LOCALMEM0R(Dictionary, empty); - VCALL_LOCALMEM0(Dictionary, clear); - VCALL_LOCALMEM1R(Dictionary, has); - VCALL_LOCALMEM1R(Dictionary, has_all); - VCALL_LOCALMEM1R(Dictionary, erase); - VCALL_LOCALMEM0R(Dictionary, hash); - VCALL_LOCALMEM0R(Dictionary, keys); - VCALL_LOCALMEM0R(Dictionary, values); - VCALL_LOCALMEM1R(Dictionary, duplicate); - VCALL_LOCALMEM2R(Dictionary, get); - - VCALL_LOCALMEM0R(Callable, is_null); - VCALL_LOCALMEM0R(Callable, is_custom); - VCALL_LOCALMEM0(Callable, is_standard); - VCALL_LOCALMEM0(Callable, get_object); - VCALL_LOCALMEM0(Callable, get_object_id); - VCALL_LOCALMEM0(Callable, get_method); - VCALL_LOCALMEM0(Callable, hash); - - VCALL_LOCALMEM0R(Signal, is_null); - VCALL_LOCALMEM0R(Signal, get_object); - VCALL_LOCALMEM0R(Signal, get_object_id); - VCALL_LOCALMEM0R(Signal, get_name); - VCALL_LOCALMEM3R(Signal, connect); - VCALL_LOCALMEM1(Signal, disconnect); - VCALL_LOCALMEM1R(Signal, is_connected); - VCALL_LOCALMEM0R(Signal, get_connections); - - VCALL_LOCALMEM2(Array, set); - VCALL_LOCALMEM1R(Array, get); - VCALL_LOCALMEM0R(Array, size); - VCALL_LOCALMEM0R(Array, empty); - VCALL_LOCALMEM0(Array, clear); - VCALL_LOCALMEM0R(Array, hash); - VCALL_LOCALMEM1(Array, push_back); - VCALL_LOCALMEM1(Array, push_front); - VCALL_LOCALMEM0R(Array, pop_back); - VCALL_LOCALMEM0R(Array, pop_front); - VCALL_LOCALMEM1(Array, append); - VCALL_LOCALMEM1(Array, resize); - VCALL_LOCALMEM2(Array, insert); - VCALL_LOCALMEM1(Array, remove); - VCALL_LOCALMEM0R(Array, front); - VCALL_LOCALMEM0R(Array, back); - VCALL_LOCALMEM2R(Array, find); - VCALL_LOCALMEM2R(Array, rfind); - VCALL_LOCALMEM1R(Array, find_last); - VCALL_LOCALMEM1R(Array, count); - VCALL_LOCALMEM1R(Array, has); - VCALL_LOCALMEM1(Array, erase); - VCALL_LOCALMEM0(Array, sort); - VCALL_LOCALMEM2(Array, sort_custom); - VCALL_LOCALMEM0(Array, shuffle); - VCALL_LOCALMEM2R(Array, bsearch); - VCALL_LOCALMEM4R(Array, bsearch_custom); - VCALL_LOCALMEM1R(Array, duplicate); - VCALL_LOCALMEM4R(Array, slice); - VCALL_LOCALMEM0(Array, invert); - VCALL_LOCALMEM0R(Array, max); - VCALL_LOCALMEM0R(Array, min); - - static void _call_PackedByteArray_get_string_from_ascii(Variant &r_ret, Variant &p_self, const Variant **p_args) { - Variant::PackedArrayRef<uint8_t> *ba = reinterpret_cast<Variant::PackedArrayRef<uint8_t> *>(p_self._data.packed_array); +#ifdef DEBUG_ENABLED +#define bind_function(m_name, m_method, m_arg_names, m_default_args) _VariantCall::_bind_function(m_name, m_method, m_default_args, m_arg_names) +#else +#define bind_function(m_name, m_method, m_arg_names, m_default_args) _VariantCall::_bind_function(m_name, m_method, m_default_args) +#endif + + static void _bind_custom(Variant::Type p_type, const StringName &p_name, InternalMethodVC::MethodVC p_method, uint32_t p_flags, const Vector<Variant::Type> &p_argument_types, const Variant::Type &p_return_type +#ifdef DEBUG_ENABLED + , + const Vector<String> &p_argument_names = Vector<String>() +#endif + ) { + +#ifdef DEBUG_ENABLED + Variant::InternalMethod *m = memnew(InternalMethodVC(p_method, p_flags, p_argument_types, p_return_type, p_argument_names, p_name, p_type)); +#else + Variant::InternalMethod *m = memnew(InternalMethodVC(p_method, p_flags, p_argument_types, p_return_type)); +#endif + + type_internal_methods[p_type].insert(p_name, m); + type_internal_method_names[p_type].push_back(p_name); + } + +#ifdef DEBUG_ENABLED +#define bind_custom(m_type, m_name, m_method, m_flags, m_arg_types, m_ret_type, m_arg_names) _VariantCall::_bind_custom(m_type, m_name, m_method, m_flags, m_arg_types, m_ret_type, m_arg_names) +#else +#define bind_custom(m_type, m_name, m_method, m_flags, m_arg_types, m_ret_type, m_arg_names) _VariantCall::_bind_custom(m_type, m_name, m_method, m_flags, m_arg_types, m_ret_type) +#endif + + static String func_PackedByteArray_get_string_from_ascii(PackedByteArray *p_instance) { String s; - if (ba->array.size() > 0) { - const uint8_t *r = ba->array.ptr(); + if (p_instance->size() > 0) { + const uint8_t *r = p_instance->ptr(); CharString cs; - cs.resize(ba->array.size() + 1); - copymem(cs.ptrw(), r, ba->array.size()); - cs[ba->array.size()] = 0; + cs.resize(p_instance->size() + 1); + copymem(cs.ptrw(), r, p_instance->size()); + cs[p_instance->size()] = 0; s = cs.get_data(); } - r_ret = s; + return s; } - static void _call_PackedByteArray_get_string_from_utf8(Variant &r_ret, Variant &p_self, const Variant **p_args) { - Variant::PackedArrayRef<uint8_t> *ba = reinterpret_cast<Variant::PackedArrayRef<uint8_t> *>(p_self._data.packed_array); - + static String func_PackedByteArray_get_string_from_utf8(PackedByteArray *p_instance) { String s; - if (ba->array.size() > 0) { - const uint8_t *r = ba->array.ptr(); - s.parse_utf8((const char *)r, ba->array.size()); + if (p_instance->size() > 0) { + const uint8_t *r = p_instance->ptr(); + s.parse_utf8((const char *)r, p_instance->size()); } - r_ret = s; + return s; } - static void _call_PackedByteArray_get_string_from_utf16(Variant &r_ret, Variant &p_self, const Variant **p_args) { - PackedByteArray *ba = reinterpret_cast<PackedByteArray *>(p_self._data._mem); + static String func_PackedByteArray_get_string_from_utf16(PackedByteArray *p_instance) { String s; - if (ba->size() > 0) { - const uint8_t *r = ba->ptr(); - s.parse_utf16((const char16_t *)r, ba->size() / 2); + if (p_instance->size() > 0) { + const uint8_t *r = p_instance->ptr(); + s.parse_utf16((const char16_t *)r, p_instance->size() / 2); } - r_ret = s; + return s; } - static void _call_PackedByteArray_get_string_from_utf32(Variant &r_ret, Variant &p_self, const Variant **p_args) { - PackedByteArray *ba = reinterpret_cast<PackedByteArray *>(p_self._data._mem); + static String func_PackedByteArray_get_string_from_utf32(PackedByteArray *p_instance) { String s; - if (ba->size() > 0) { - const uint8_t *r = ba->ptr(); - s = String((const char32_t *)r, ba->size() / 4); + if (p_instance->size() > 0) { + const uint8_t *r = p_instance->ptr(); + s = String((const char32_t *)r, p_instance->size() / 4); } - r_ret = s; + return s; } - static void _call_PackedByteArray_compress(Variant &r_ret, Variant &p_self, const Variant **p_args) { - Variant::PackedArrayRef<uint8_t> *ba = reinterpret_cast<Variant::PackedArrayRef<uint8_t> *>(p_self._data.packed_array); + static PackedByteArray func_PackedByteArray_compress(PackedByteArray *p_instance, int p_mode) { PackedByteArray compressed; - if (ba->array.size() > 0) { - Compression::Mode mode = (Compression::Mode)(int)(*p_args[0]); - compressed.resize(Compression::get_max_compressed_buffer_size(ba->array.size(), mode)); - int result = Compression::compress(compressed.ptrw(), ba->array.ptr(), ba->array.size(), mode); + if (p_instance->size() > 0) { + Compression::Mode mode = (Compression::Mode)(p_mode); + compressed.resize(Compression::get_max_compressed_buffer_size(p_instance->size(), mode)); + int result = Compression::compress(compressed.ptrw(), p_instance->ptr(), p_instance->size(), mode); result = result >= 0 ? result : 0; compressed.resize(result); } - r_ret = compressed; + return compressed; } - static void _call_PackedByteArray_decompress(Variant &r_ret, Variant &p_self, const Variant **p_args) { - Variant::PackedArrayRef<uint8_t> *ba = reinterpret_cast<Variant::PackedArrayRef<uint8_t> *>(p_self._data.packed_array); + static PackedByteArray func_PackedByteArray_decompress(PackedByteArray *p_instance, int64_t p_buffer_size, int p_mode) { PackedByteArray decompressed; - Compression::Mode mode = (Compression::Mode)(int)(*p_args[1]); + Compression::Mode mode = (Compression::Mode)(p_mode); - int buffer_size = (int)(*p_args[0]); + int64_t buffer_size = p_buffer_size; if (buffer_size <= 0) { - r_ret = decompressed; - ERR_FAIL_MSG("Decompression buffer size must be greater than zero."); + ERR_FAIL_V_MSG(decompressed, "Decompression buffer size must be greater than zero."); } decompressed.resize(buffer_size); - int result = Compression::decompress(decompressed.ptrw(), buffer_size, ba->array.ptr(), ba->array.size(), mode); + int result = Compression::decompress(decompressed.ptrw(), buffer_size, p_instance->ptr(), p_instance->size(), mode); result = result >= 0 ? result : 0; decompressed.resize(result); - r_ret = decompressed; + return decompressed; } - static void _call_PackedByteArray_decompress_dynamic(Variant &r_ret, Variant &p_self, const Variant **p_args) { - Variant::PackedArrayRef<uint8_t> *ba = reinterpret_cast<Variant::PackedArrayRef<uint8_t> *>(p_self._data.packed_array); + static PackedByteArray func_PackedByteArray_decompress_dynamic(PackedByteArray *p_instance, int64_t p_buffer_size, int p_mode) { PackedByteArray decompressed; - int max_output_size = (int)(*p_args[0]); - Compression::Mode mode = (Compression::Mode)(int)(*p_args[1]); + int64_t max_output_size = p_buffer_size; + Compression::Mode mode = (Compression::Mode)(p_mode); - int result = Compression::decompress_dynamic(&decompressed, max_output_size, ba->array.ptr(), ba->array.size(), mode); + int result = Compression::decompress_dynamic(&decompressed, max_output_size, p_instance->ptr(), p_instance->size(), mode); if (result == OK) { - r_ret = decompressed; + return decompressed; } else { decompressed.clear(); - r_ret = decompressed; - ERR_FAIL_MSG("Decompression failed."); + ERR_FAIL_V_MSG(decompressed, "Decompression failed."); } } - static void _call_PackedByteArray_hex_encode(Variant &r_ret, Variant &p_self, const Variant **p_args) { - Variant::PackedArrayRef<uint8_t> *ba = reinterpret_cast<Variant::PackedArrayRef<uint8_t> *>(p_self._data.packed_array); - if (ba->array.size() == 0) { - r_ret = String(); - return; - } - const uint8_t *r = ba->array.ptr(); - String s = String::hex_encode_buffer(&r[0], ba->array.size()); - r_ret = s; - } - -#define VCALL_PARRMEM0(m_type, m_elemtype, m_method) \ - static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { Variant::PackedArrayRef<m_elemtype>::get_array_ptr(p_self._data.packed_array)->m_method(); } -#define VCALL_PARRMEM0R(m_type, m_elemtype, m_method) \ - static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { r_ret = Variant::PackedArrayRef<m_elemtype>::get_array_ptr(p_self._data.packed_array)->m_method(); } -#define VCALL_PARRMEM1(m_type, m_elemtype, m_method) \ - static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { Variant::PackedArrayRef<m_elemtype>::get_array_ptr(p_self._data.packed_array)->m_method(*p_args[0]); } -#define VCALL_PARRMEM1R(m_type, m_elemtype, m_method) \ - static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { r_ret = Variant::PackedArrayRef<m_elemtype>::get_array_ptr(p_self._data.packed_array)->m_method(*p_args[0]); } -#define VCALL_PARRMEM2(m_type, m_elemtype, m_method) \ - static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { Variant::PackedArrayRef<m_elemtype>::get_array_ptr(p_self._data.packed_array)->m_method(*p_args[0], *p_args[1]); } -#define VCALL_PARRMEM2R(m_type, m_elemtype, m_method) \ - static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { r_ret = Variant::PackedArrayRef<m_elemtype>::get_array_ptr(p_self._data.packed_array)->m_method(*p_args[0], *p_args[1]); } -#define VCALL_PARRMEM3(m_type, m_elemtype, m_method) \ - static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { Variant::PackedArrayRef<m_elemtype>::get_array_ptr(p_self._data.packed_array)->m_method(*p_args[0], *p_args[1], *p_args[2]); } -#define VCALL_PARRMEM3R(m_type, m_elemtype, m_method) \ - static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { r_ret = Variant::PackedArrayRef<m_elemtype>::get_array_ptr(p_self._data.packed_array)->m_method(*p_args[0], *p_args[1], *p_args[2]); } -#define VCALL_PARRMEM4(m_type, m_elemtype, m_method) \ - static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { Variant::PackedArrayRef<m_elemtype>::get_array_ptr(p_self._data.packed_array)->m_method(*p_args[0], *p_args[1], *p_args[2], *p_args[3]); } -#define VCALL_PARRMEM4R(m_type, m_elemtype, m_method) \ - static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { r_ret = Variant::PackedArrayRef<m_elemtype>::get_array_ptr(p_self._data.packed_array)->m_method(*p_args[0], *p_args[1], *p_args[2], *p_args[3]); } -#define VCALL_PARRMEM5(m_type, m_elemtype, m_method) \ - static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { Variant::PackedArrayRef<m_elemtype>::get_array_ptr(p_self._data.packed_array)->m_method(*p_args[0], *p_args[1], *p_args[2], *p_args[3], *p_args[4]); } -#define VCALL_PARRMEM5R(m_type, m_elemtype, m_method) \ - static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { r_ret = Variant::PackedArrayRef<m_elemtype>::get_array_ptr(p_self._data.packed_array)->m_method(*p_args[0], *p_args[1], *p_args[2], *p_args[3], *p_args[4]); } - - VCALL_PARRMEM0R(PackedByteArray, uint8_t, size); - VCALL_PARRMEM0R(PackedByteArray, uint8_t, empty); - VCALL_PARRMEM2(PackedByteArray, uint8_t, set); - VCALL_PARRMEM1R(PackedByteArray, uint8_t, get); - VCALL_PARRMEM1(PackedByteArray, uint8_t, push_back); - VCALL_PARRMEM1(PackedByteArray, uint8_t, resize); - VCALL_PARRMEM2R(PackedByteArray, uint8_t, insert); - VCALL_PARRMEM1(PackedByteArray, uint8_t, remove); - VCALL_PARRMEM1(PackedByteArray, uint8_t, append); - VCALL_PARRMEM1(PackedByteArray, uint8_t, append_array); - VCALL_PARRMEM1R(PackedByteArray, uint8_t, has); - VCALL_PARRMEM0(PackedByteArray, uint8_t, sort); - VCALL_PARRMEM0(PackedByteArray, uint8_t, invert); - VCALL_PARRMEM2R(PackedByteArray, uint8_t, subarray); - - VCALL_PARRMEM0R(PackedInt32Array, int32_t, size); - VCALL_PARRMEM0R(PackedInt32Array, int32_t, empty); - VCALL_PARRMEM2(PackedInt32Array, int32_t, set); - VCALL_PARRMEM1R(PackedInt32Array, int32_t, get); - VCALL_PARRMEM1(PackedInt32Array, int32_t, push_back); - VCALL_PARRMEM1(PackedInt32Array, int32_t, resize); - VCALL_PARRMEM2R(PackedInt32Array, int32_t, insert); - VCALL_PARRMEM1(PackedInt32Array, int32_t, remove); - VCALL_PARRMEM1(PackedInt32Array, int32_t, append); - VCALL_PARRMEM1(PackedInt32Array, int32_t, append_array); - VCALL_PARRMEM1R(PackedInt32Array, int32_t, has); - VCALL_PARRMEM0(PackedInt32Array, int32_t, sort); - VCALL_PARRMEM0(PackedInt32Array, int32_t, invert); - - VCALL_PARRMEM0R(PackedInt64Array, int64_t, size); - VCALL_PARRMEM0R(PackedInt64Array, int64_t, empty); - VCALL_PARRMEM2(PackedInt64Array, int64_t, set); - VCALL_PARRMEM1R(PackedInt64Array, int64_t, get); - VCALL_PARRMEM1(PackedInt64Array, int64_t, push_back); - VCALL_PARRMEM1(PackedInt64Array, int64_t, resize); - VCALL_PARRMEM2R(PackedInt64Array, int64_t, insert); - VCALL_PARRMEM1(PackedInt64Array, int64_t, remove); - VCALL_PARRMEM1(PackedInt64Array, int64_t, append); - VCALL_PARRMEM1(PackedInt64Array, int64_t, append_array); - VCALL_PARRMEM1R(PackedInt64Array, int64_t, has); - VCALL_PARRMEM0(PackedInt64Array, int64_t, sort); - VCALL_PARRMEM0(PackedInt64Array, int64_t, invert); - - VCALL_PARRMEM0R(PackedFloat32Array, float, size); - VCALL_PARRMEM0R(PackedFloat32Array, float, empty); - VCALL_PARRMEM2(PackedFloat32Array, float, set); - VCALL_PARRMEM1R(PackedFloat32Array, float, get); - VCALL_PARRMEM1(PackedFloat32Array, float, push_back); - VCALL_PARRMEM1(PackedFloat32Array, float, resize); - VCALL_PARRMEM2R(PackedFloat32Array, float, insert); - VCALL_PARRMEM1(PackedFloat32Array, float, remove); - VCALL_PARRMEM1(PackedFloat32Array, float, append); - VCALL_PARRMEM1(PackedFloat32Array, float, append_array); - VCALL_PARRMEM1R(PackedFloat32Array, float, has); - VCALL_PARRMEM0(PackedFloat32Array, float, sort); - VCALL_PARRMEM0(PackedFloat32Array, float, invert); - - VCALL_PARRMEM0R(PackedFloat64Array, double, size); - VCALL_PARRMEM0R(PackedFloat64Array, double, empty); - VCALL_PARRMEM2(PackedFloat64Array, double, set); - VCALL_PARRMEM1R(PackedFloat64Array, double, get); - VCALL_PARRMEM1(PackedFloat64Array, double, push_back); - VCALL_PARRMEM1(PackedFloat64Array, double, resize); - VCALL_PARRMEM2R(PackedFloat64Array, double, insert); - VCALL_PARRMEM1(PackedFloat64Array, double, remove); - VCALL_PARRMEM1(PackedFloat64Array, double, append); - VCALL_PARRMEM1(PackedFloat64Array, double, append_array); - VCALL_PARRMEM1R(PackedFloat64Array, double, has); - VCALL_PARRMEM0(PackedFloat64Array, double, sort); - VCALL_PARRMEM0(PackedFloat64Array, double, invert); - - VCALL_PARRMEM0R(PackedStringArray, String, size); - VCALL_PARRMEM0R(PackedStringArray, String, empty); - VCALL_PARRMEM2(PackedStringArray, String, set); - VCALL_PARRMEM1R(PackedStringArray, String, get); - VCALL_PARRMEM1(PackedStringArray, String, push_back); - VCALL_PARRMEM1(PackedStringArray, String, resize); - VCALL_PARRMEM2R(PackedStringArray, String, insert); - VCALL_PARRMEM1(PackedStringArray, String, remove); - VCALL_PARRMEM1(PackedStringArray, String, append); - VCALL_PARRMEM1(PackedStringArray, String, append_array); - VCALL_PARRMEM1R(PackedStringArray, String, has); - VCALL_PARRMEM0(PackedStringArray, String, sort); - VCALL_PARRMEM0(PackedStringArray, String, invert); - - VCALL_PARRMEM0R(PackedVector2Array, Vector2, size); - VCALL_PARRMEM0R(PackedVector2Array, Vector2, empty); - VCALL_PARRMEM2(PackedVector2Array, Vector2, set); - VCALL_PARRMEM1R(PackedVector2Array, Vector2, get); - VCALL_PARRMEM1(PackedVector2Array, Vector2, push_back); - VCALL_PARRMEM1(PackedVector2Array, Vector2, resize); - VCALL_PARRMEM2R(PackedVector2Array, Vector2, insert); - VCALL_PARRMEM1(PackedVector2Array, Vector2, remove); - VCALL_PARRMEM1(PackedVector2Array, Vector2, append); - VCALL_PARRMEM1(PackedVector2Array, Vector2, append_array); - VCALL_PARRMEM1R(PackedVector2Array, Vector2, has); - VCALL_PARRMEM0(PackedVector2Array, Vector2, sort); - VCALL_PARRMEM0(PackedVector2Array, Vector2, invert); - - VCALL_PARRMEM0R(PackedVector3Array, Vector3, size); - VCALL_PARRMEM0R(PackedVector3Array, Vector3, empty); - VCALL_PARRMEM2(PackedVector3Array, Vector3, set); - VCALL_PARRMEM1R(PackedVector3Array, Vector3, get); - VCALL_PARRMEM1(PackedVector3Array, Vector3, push_back); - VCALL_PARRMEM1(PackedVector3Array, Vector3, resize); - VCALL_PARRMEM2R(PackedVector3Array, Vector3, insert); - VCALL_PARRMEM1(PackedVector3Array, Vector3, remove); - VCALL_PARRMEM1(PackedVector3Array, Vector3, append); - VCALL_PARRMEM1(PackedVector3Array, Vector3, append_array); - VCALL_PARRMEM1R(PackedVector3Array, Vector3, has); - VCALL_PARRMEM0(PackedVector3Array, Vector3, sort); - VCALL_PARRMEM0(PackedVector3Array, Vector3, invert); - - VCALL_PARRMEM0R(PackedColorArray, Color, size); - VCALL_PARRMEM0R(PackedColorArray, Color, empty); - VCALL_PARRMEM2(PackedColorArray, Color, set); - VCALL_PARRMEM1R(PackedColorArray, Color, get); - VCALL_PARRMEM1(PackedColorArray, Color, push_back); - VCALL_PARRMEM1(PackedColorArray, Color, resize); - VCALL_PARRMEM2R(PackedColorArray, Color, insert); - VCALL_PARRMEM1(PackedColorArray, Color, remove); - VCALL_PARRMEM1(PackedColorArray, Color, append); - VCALL_PARRMEM1(PackedColorArray, Color, append_array); - VCALL_PARRMEM1R(PackedColorArray, Color, has); - VCALL_PARRMEM0(PackedColorArray, Color, sort); - VCALL_PARRMEM0(PackedColorArray, Color, invert); - -#define VCALL_PTR0(m_type, m_method) \ - static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { reinterpret_cast<m_type *>(p_self._data._ptr)->m_method(); } -#define VCALL_PTR0R(m_type, m_method) \ - static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { r_ret = reinterpret_cast<m_type *>(p_self._data._ptr)->m_method(); } -#define VCALL_PTR1(m_type, m_method) \ - static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { reinterpret_cast<m_type *>(p_self._data._ptr)->m_method(*p_args[0]); } -#define VCALL_PTR1R(m_type, m_method) \ - static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { r_ret = reinterpret_cast<m_type *>(p_self._data._ptr)->m_method(*p_args[0]); } -#define VCALL_PTR2(m_type, m_method) \ - static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { reinterpret_cast<m_type *>(p_self._data._ptr)->m_method(*p_args[0], *p_args[1]); } -#define VCALL_PTR2R(m_type, m_method) \ - static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { r_ret = reinterpret_cast<m_type *>(p_self._data._ptr)->m_method(*p_args[0], *p_args[1]); } -#define VCALL_PTR3(m_type, m_method) \ - static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { reinterpret_cast<m_type *>(p_self._data._ptr)->m_method(*p_args[0], *p_args[1], *p_args[2]); } -#define VCALL_PTR3R(m_type, m_method) \ - static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { r_ret = reinterpret_cast<m_type *>(p_self._data._ptr)->m_method(*p_args[0], *p_args[1], *p_args[2]); } -#define VCALL_PTR4(m_type, m_method) \ - static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { reinterpret_cast<m_type *>(p_self._data._ptr)->m_method(*p_args[0], *p_args[1], *p_args[2], *p_args[3]); } -#define VCALL_PTR4R(m_type, m_method) \ - static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { r_ret = reinterpret_cast<m_type *>(p_self._data._ptr)->m_method(*p_args[0], *p_args[1], *p_args[2], *p_args[3]); } -#define VCALL_PTR5(m_type, m_method) \ - static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { reinterpret_cast<m_type *>(p_self._data._ptr)->m_method(*p_args[0], *p_args[1], *p_args[2], *p_args[3], *p_args[4]); } -#define VCALL_PTR5R(m_type, m_method) \ - static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { r_ret = reinterpret_cast<m_type *>(p_self._data._ptr)->m_method(*p_args[0], *p_args[1], *p_args[2], *p_args[3], *p_args[4]); } - - VCALL_PTR0R(AABB, abs); - VCALL_PTR0R(AABB, get_area); - VCALL_PTR0R(AABB, has_no_area); - VCALL_PTR0R(AABB, has_no_surface); - VCALL_PTR1R(AABB, has_point); - VCALL_PTR1R(AABB, is_equal_approx); - VCALL_PTR1R(AABB, intersects); - VCALL_PTR1R(AABB, encloses); - VCALL_PTR1R(AABB, intersects_plane); - VCALL_PTR2R(AABB, intersects_segment); - VCALL_PTR1R(AABB, intersection); - VCALL_PTR1R(AABB, merge); - VCALL_PTR1R(AABB, expand); - VCALL_PTR1R(AABB, grow); - VCALL_PTR1R(AABB, get_support); - VCALL_PTR0R(AABB, get_longest_axis); - VCALL_PTR0R(AABB, get_longest_axis_index); - VCALL_PTR0R(AABB, get_longest_axis_size); - VCALL_PTR0R(AABB, get_shortest_axis); - VCALL_PTR0R(AABB, get_shortest_axis_index); - VCALL_PTR0R(AABB, get_shortest_axis_size); - VCALL_PTR1R(AABB, get_endpoint); - - VCALL_PTR0R(Transform2D, inverse); - VCALL_PTR0R(Transform2D, affine_inverse); - VCALL_PTR0R(Transform2D, get_rotation); - VCALL_PTR0R(Transform2D, get_origin); - VCALL_PTR0R(Transform2D, get_scale); - VCALL_PTR0R(Transform2D, orthonormalized); - VCALL_PTR1R(Transform2D, rotated); - VCALL_PTR1R(Transform2D, scaled); - VCALL_PTR1R(Transform2D, translated); - VCALL_PTR2R(Transform2D, interpolate_with); - VCALL_PTR1R(Transform2D, is_equal_approx); - - static void _call_Transform2D_xform(Variant &r_ret, Variant &p_self, const Variant **p_args) { - switch (p_args[0]->type) { - case Variant::VECTOR2: - r_ret = reinterpret_cast<Transform2D *>(p_self._data._ptr)->xform(p_args[0]->operator Vector2()); - return; - case Variant::RECT2: - r_ret = reinterpret_cast<Transform2D *>(p_self._data._ptr)->xform(p_args[0]->operator Rect2()); - return; - case Variant::PACKED_VECTOR2_ARRAY: - r_ret = reinterpret_cast<Transform2D *>(p_self._data._ptr)->xform(p_args[0]->operator PackedVector2Array()); - return; - default: - r_ret = Variant(); - ERR_PRINT("Invalid type in function 'xform' in base 'Transform2D'. Valid types are Vector2, Rect2, and PackedVector2Array."); + static String func_PackedByteArray_hex_encode(PackedByteArray *p_instance) { + if (p_instance->size() == 0) { + return String(); } + const uint8_t *r = p_instance->ptr(); + String s = String::hex_encode_buffer(&r[0], p_instance->size()); + return s; } - static void _call_Transform2D_xform_inv(Variant &r_ret, Variant &p_self, const Variant **p_args) { - switch (p_args[0]->type) { - case Variant::VECTOR2: - r_ret = reinterpret_cast<Transform2D *>(p_self._data._ptr)->xform_inv(p_args[0]->operator Vector2()); - return; - case Variant::RECT2: - r_ret = reinterpret_cast<Transform2D *>(p_self._data._ptr)->xform_inv(p_args[0]->operator Rect2()); - return; - case Variant::PACKED_VECTOR2_ARRAY: - r_ret = reinterpret_cast<Transform2D *>(p_self._data._ptr)->xform_inv(p_args[0]->operator PackedVector2Array()); - return; - default: - r_ret = Variant(); - ERR_PRINT("Invalid type in function 'xform_inv' in base 'Transform2D'. Valid types are Vector2, Rect2, and PackedVector2Array."); - } + static void func_Callable_call(Variant *v, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) { + Callable *callable = VariantGetInternalPtr<Callable>::get_ptr(v); + callable->call(p_args, p_argcount, r_ret, r_error); } - static void _call_Transform2D_basis_xform(Variant &r_ret, Variant &p_self, const Variant **p_args) { - switch (p_args[0]->type) { - case Variant::VECTOR2: - r_ret = reinterpret_cast<Transform2D *>(p_self._data._ptr)->basis_xform(p_args[0]->operator Vector2()); - return; - default: - r_ret = Variant(); - ERR_PRINT("Invalid type in function 'basis_xform' in base 'Transform2D'. Only Vector2 is valid."); - } + static void func_Callable_call_deferred(Variant *v, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) { + Callable *callable = VariantGetInternalPtr<Callable>::get_ptr(v); + callable->call_deferred(p_args, p_argcount); } - static void _call_Transform2D_basis_xform_inv(Variant &r_ret, Variant &p_self, const Variant **p_args) { - switch (p_args[0]->type) { - case Variant::VECTOR2: - r_ret = reinterpret_cast<Transform2D *>(p_self._data._ptr)->basis_xform_inv(p_args[0]->operator Vector2()); - return; - default: - r_ret = Variant(); - ERR_PRINT("Invalid type in function 'basis_xform_inv' in base 'Transform2D'. Only Vector2 is valid."); - } - } - - VCALL_PTR0R(Basis, inverse); - VCALL_PTR0R(Basis, transposed); - VCALL_PTR0R(Basis, determinant); - VCALL_PTR2R(Basis, rotated); - VCALL_PTR1R(Basis, scaled); - VCALL_PTR0R(Basis, get_scale); - VCALL_PTR0R(Basis, get_euler); - VCALL_PTR0R(Basis, get_euler_xyz); - VCALL_PTR1(Basis, set_euler_xyz); - VCALL_PTR0R(Basis, get_euler_xzy); - VCALL_PTR1(Basis, set_euler_xzy); - VCALL_PTR0R(Basis, get_euler_yzx); - VCALL_PTR1(Basis, set_euler_yzx); - VCALL_PTR0R(Basis, get_euler_yxz); - VCALL_PTR1(Basis, set_euler_yxz); - VCALL_PTR0R(Basis, get_euler_zxy); - VCALL_PTR1(Basis, set_euler_zxy); - VCALL_PTR0R(Basis, get_euler_zyx); - VCALL_PTR1(Basis, set_euler_zyx); - VCALL_PTR1R(Basis, tdotx); - VCALL_PTR1R(Basis, tdoty); - VCALL_PTR1R(Basis, tdotz); - VCALL_PTR1R(Basis, xform); - VCALL_PTR1R(Basis, xform_inv); - VCALL_PTR0R(Basis, get_orthogonal_index); - VCALL_PTR0R(Basis, orthonormalized); - VCALL_PTR2R(Basis, slerp); - VCALL_PTR1R(Basis, is_equal_approx); - VCALL_PTR0R(Basis, get_rotation_quat); - - VCALL_PTR0R(Transform, inverse); - VCALL_PTR0R(Transform, affine_inverse); - VCALL_PTR2R(Transform, rotated); - VCALL_PTR1R(Transform, scaled); - VCALL_PTR1R(Transform, translated); - VCALL_PTR0R(Transform, orthonormalized); - VCALL_PTR2R(Transform, looking_at); - VCALL_PTR2R(Transform, interpolate_with); - VCALL_PTR1R(Transform, is_equal_approx); - - static void _call_Transform_xform(Variant &r_ret, Variant &p_self, const Variant **p_args) { - switch (p_args[0]->type) { - case Variant::VECTOR3: - r_ret = reinterpret_cast<Transform *>(p_self._data._ptr)->xform(p_args[0]->operator Vector3()); - return; - case Variant::PLANE: - r_ret = reinterpret_cast<Transform *>(p_self._data._ptr)->xform(p_args[0]->operator Plane()); - return; - case Variant::AABB: - r_ret = reinterpret_cast<Transform *>(p_self._data._ptr)->xform(p_args[0]->operator ::AABB()); - return; - case Variant::PACKED_VECTOR3_ARRAY: - r_ret = reinterpret_cast<Transform *>(p_self._data._ptr)->xform(p_args[0]->operator ::PackedVector3Array()); - return; - default: - r_ret = Variant(); - ERR_PRINT("Invalid type in function 'xform' in base 'Transform'. Valid types are Vector3, Plane, AABB, and PackedVector3Array."); - } + static void func_Callable_bind(Variant *v, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) { + Callable *callable = VariantGetInternalPtr<Callable>::get_ptr(v); + r_ret = callable->bind(p_args, p_argcount); } - static void _call_Transform_xform_inv(Variant &r_ret, Variant &p_self, const Variant **p_args) { - switch (p_args[0]->type) { - case Variant::VECTOR3: - r_ret = reinterpret_cast<Transform *>(p_self._data._ptr)->xform_inv(p_args[0]->operator Vector3()); - return; - case Variant::PLANE: - r_ret = reinterpret_cast<Transform *>(p_self._data._ptr)->xform_inv(p_args[0]->operator Plane()); - return; - case Variant::AABB: - r_ret = reinterpret_cast<Transform *>(p_self._data._ptr)->xform_inv(p_args[0]->operator ::AABB()); - return; - case Variant::PACKED_VECTOR3_ARRAY: - r_ret = reinterpret_cast<Transform *>(p_self._data._ptr)->xform_inv(p_args[0]->operator ::PackedVector3Array()); - return; - default: - r_ret = Variant(); - ERR_PRINT("Invalid type in function 'xform_inv' in base 'Transform'. Valid types are Vector3, Plane, AABB, and PackedVector3Array."); - } + static void func_Signal_emit(Variant *v, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) { + Signal *signal = VariantGetInternalPtr<Signal>::get_ptr(v); + signal->emit(p_args, p_argcount); } struct ConstructData { @@ -1300,9 +883,10 @@ struct _VariantCall { } }; -_VariantCall::TypeFunc *_VariantCall::type_funcs = nullptr; _VariantCall::ConstructFunc *_VariantCall::construct_funcs = nullptr; _VariantCall::ConstantData *_VariantCall::constant_data = nullptr; +_VariantCall::MethodMap *_VariantCall::type_internal_methods = nullptr; +List<StringName> *_VariantCall::type_internal_method_names = nullptr; Variant Variant::call(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) { Variant ret; @@ -1334,38 +918,14 @@ void Variant::call_ptr(const StringName &p_method, const Variant **p_args, int p } else { r_error.error = Callable::CallError::CALL_OK; - Map<StringName, _VariantCall::FuncData>::Element *E = _VariantCall::type_funcs[type].functions.find(p_method); - - if (E) { - _VariantCall::FuncData &funcdata = E->get(); - funcdata.call(ret, *this, p_args, p_argcount, r_error); + Variant::InternalMethod **m = _VariantCall::type_internal_methods[type].lookup_ptr(p_method); + if (m) { + (*m)->call((Variant *)this, p_args, p_argcount, ret, r_error); } else { - //handle vararg functions manually - bool valid = false; - if (type == CALLABLE) { - if (p_method == CoreStringNames::get_singleton()->call) { - reinterpret_cast<const Callable *>(_data._mem)->call(p_args, p_argcount, ret, r_error); - valid = true; - } - if (p_method == CoreStringNames::get_singleton()->call_deferred) { - reinterpret_cast<const Callable *>(_data._mem)->call_deferred(p_args, p_argcount); - valid = true; - } - } else if (type == SIGNAL) { - if (p_method == CoreStringNames::get_singleton()->emit) { - if (r_ret) { - *r_ret = Variant(); - } - reinterpret_cast<const Signal *>(_data._mem)->emit(p_args, p_argcount); - valid = true; - } - } - if (!valid) { - //ok fail because not found - r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; - return; - } + //ok fail because not found + r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; + return; } } @@ -1593,126 +1153,96 @@ bool Variant::has_method(const StringName &p_method) const { return obj->has_method(p_method); } - const _VariantCall::TypeFunc &tf = _VariantCall::type_funcs[type]; - return tf.functions.has(p_method); + return _VariantCall::type_internal_methods[type].has(p_method); } Vector<Variant::Type> Variant::get_method_argument_types(Variant::Type p_type, const StringName &p_method) { - const _VariantCall::TypeFunc &tf = _VariantCall::type_funcs[p_type]; + Vector<Variant::Type> types; - const Map<StringName, _VariantCall::FuncData>::Element *E = tf.functions.find(p_method); - if (!E) { - return Vector<Variant::Type>(); + Variant::InternalMethod **m = _VariantCall::type_internal_methods[p_type].lookup_ptr(p_method); + if (*m) { + types.resize((*m)->get_argument_count()); + for (int i = 0; i < (*m)->get_argument_count(); i++) { + types.write[i] = (*m)->get_argument_type(i); + } } - return E->get().arg_types; + return types; } bool Variant::is_method_const(Variant::Type p_type, const StringName &p_method) { - const _VariantCall::TypeFunc &tf = _VariantCall::type_funcs[p_type]; - - const Map<StringName, _VariantCall::FuncData>::Element *E = tf.functions.find(p_method); - if (!E) { - return false; + Variant::InternalMethod **m = _VariantCall::type_internal_methods[p_type].lookup_ptr(p_method); + if (*m) { + return (*m)->get_flags() & Variant::InternalMethod::FLAG_IS_CONST; } - - return E->get()._const; + return false; } Vector<StringName> Variant::get_method_argument_names(Variant::Type p_type, const StringName &p_method) { - const _VariantCall::TypeFunc &tf = _VariantCall::type_funcs[p_type]; + Vector<StringName> argnames; - const Map<StringName, _VariantCall::FuncData>::Element *E = tf.functions.find(p_method); - if (!E) { - return Vector<StringName>(); +#ifdef DEBUG_ENABLED + Variant::InternalMethod **m = _VariantCall::type_internal_methods[p_type].lookup_ptr(p_method); + if (*m) { + argnames.resize((*m)->get_argument_count()); + for (int i = 0; i < (*m)->get_argument_count(); i++) { + argnames.write[i] = (*m)->get_argument_name(i); + } } - - return E->get().arg_names; +#endif + return argnames; } Variant::Type Variant::get_method_return_type(Variant::Type p_type, const StringName &p_method, bool *r_has_return) { - const _VariantCall::TypeFunc &tf = _VariantCall::type_funcs[p_type]; - - const Map<StringName, _VariantCall::FuncData>::Element *E = tf.functions.find(p_method); - if (!E) { - return Variant::NIL; - } - - if (r_has_return) { - *r_has_return = E->get().returns; + Variant::Type rt = Variant::NIL; + Variant::InternalMethod **m = _VariantCall::type_internal_methods[p_type].lookup_ptr(p_method); + if (*m) { + rt = (*m)->get_return_type(); + if (r_has_return) { + *r_has_return = ((*m)->get_flags() & Variant::InternalMethod::FLAG_RETURNS_VARIANT) || rt != Variant::NIL; + } } - - return E->get().return_type; + return rt; } Vector<Variant> Variant::get_method_default_arguments(Variant::Type p_type, const StringName &p_method) { - const _VariantCall::TypeFunc &tf = _VariantCall::type_funcs[p_type]; - - const Map<StringName, _VariantCall::FuncData>::Element *E = tf.functions.find(p_method); - if (!E) { - return Vector<Variant>(); + Variant::InternalMethod **m = _VariantCall::type_internal_methods[p_type].lookup_ptr(p_method); + if (*m) { + return (*m)->get_default_arguments(); } - - return E->get().default_args; + return Vector<Variant>(); } void Variant::get_method_list(List<MethodInfo> *p_list) const { - const _VariantCall::TypeFunc &tf = _VariantCall::type_funcs[type]; - - for (const Map<StringName, _VariantCall::FuncData>::Element *E = tf.functions.front(); E; E = E->next()) { - const _VariantCall::FuncData &fd = E->get(); + for (List<StringName>::Element *E = _VariantCall::type_internal_method_names[type].front(); E; E = E->next()) { + Variant::InternalMethod **m = _VariantCall::type_internal_methods[type].lookup_ptr(E->get()); + ERR_CONTINUE(!*m); MethodInfo mi; - mi.name = E->key(); - - if (fd._const) { + mi.name = E->get(); + mi.return_val.type = (*m)->get_return_type(); + if ((*m)->get_flags() & Variant::InternalMethod::FLAG_RETURNS_VARIANT) { + mi.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT; + } + if ((*m)->get_flags() & Variant::InternalMethod::FLAG_IS_CONST) { mi.flags |= METHOD_FLAG_CONST; } - - for (int i = 0; i < fd.arg_types.size(); i++) { - PropertyInfo pi; - pi.type = fd.arg_types[i]; -#ifdef DEBUG_ENABLED - pi.name = fd.arg_names[i]; -#endif - mi.arguments.push_back(pi); + if ((*m)->get_flags() & Variant::InternalMethod::FLAG_VARARGS) { + mi.flags |= METHOD_FLAG_VARARG; } - mi.default_arguments = fd.default_args; - PropertyInfo ret; + for (int i = 0; i < (*m)->get_argument_count(); i++) { + PropertyInfo arg; #ifdef DEBUG_ENABLED - ret.type = fd.return_type; - if (fd.returns) { - ret.name = "ret"; - if (fd.return_type == Variant::NIL) { - ret.usage = PROPERTY_USAGE_NIL_IS_VARIANT; - } - } - mi.return_val = ret; + arg.name = (*m)->get_argument_name(i); +#else + arg.name = "arg" + itos(i + 1); #endif + arg.type = (*m)->get_argument_type(i); + mi.arguments.push_back(arg); + } - p_list->push_back(mi); - } - - if (type == CALLABLE) { - MethodInfo mi; - mi.name = "call"; - mi.return_val.usage = PROPERTY_USAGE_NIL_IS_VARIANT; - mi.flags |= METHOD_FLAG_VARARG; - - p_list->push_back(mi); - - mi.name = "call_deferred"; - mi.return_val.usage = 0; - - p_list->push_back(mi); - } - - if (type == SIGNAL) { - MethodInfo mi; - mi.name = "emit"; - mi.flags |= METHOD_FLAG_VARARG; - + mi.default_arguments = (*m)->get_default_arguments(); p_list->push_back(mi); } } @@ -1811,567 +1341,614 @@ Variant Variant::get_constant_value(Variant::Type p_type, const StringName &p_va return E->get(); } -void register_variant_methods() { - _VariantCall::type_funcs = memnew_arr(_VariantCall::TypeFunc, Variant::VARIANT_MAX); +Variant::InternalMethod *Variant::get_internal_method(Type p_type, const StringName &p_method_name) { + ERR_FAIL_INDEX_V(p_type, VARIANT_MAX, nullptr); + Variant::InternalMethod **m = _VariantCall::type_internal_methods[p_type].lookup_ptr(p_method_name); + if (*m) { + return *m; + } + return nullptr; +} + +void register_variant_methods() { + _VariantCall::type_internal_methods = memnew_arr(_VariantCall::MethodMap, Variant::VARIANT_MAX); + _VariantCall::type_internal_method_names = memnew_arr(List<StringName>, Variant::VARIANT_MAX); _VariantCall::construct_funcs = memnew_arr(_VariantCall::ConstructFunc, Variant::VARIANT_MAX); _VariantCall::constant_data = memnew_arr(_VariantCall::ConstantData, Variant::VARIANT_MAX); -#define ADDFUNC0R(m_vtype, m_ret, m_class, m_method, m_defarg) \ - _VariantCall::addfunc(true, Variant::m_vtype, Variant::m_ret, true, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg); -#define ADDFUNC1R(m_vtype, m_ret, m_class, m_method, m_arg1, m_argname1, m_defarg) \ - _VariantCall::addfunc(true, Variant::m_vtype, Variant::m_ret, true, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg, _VariantCall::Arg(Variant::m_arg1, _scs_create(m_argname1))); -#define ADDFUNC2R(m_vtype, m_ret, m_class, m_method, m_arg1, m_argname1, m_arg2, m_argname2, m_defarg) \ - _VariantCall::addfunc(true, Variant::m_vtype, Variant::m_ret, true, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg, _VariantCall::Arg(Variant::m_arg1, _scs_create(m_argname1)), _VariantCall::Arg(Variant::m_arg2, _scs_create(m_argname2))); -#define ADDFUNC3R(m_vtype, m_ret, m_class, m_method, m_arg1, m_argname1, m_arg2, m_argname2, m_arg3, m_argname3, m_defarg) \ - _VariantCall::addfunc(true, Variant::m_vtype, Variant::m_ret, true, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg, _VariantCall::Arg(Variant::m_arg1, _scs_create(m_argname1)), _VariantCall::Arg(Variant::m_arg2, _scs_create(m_argname2)), _VariantCall::Arg(Variant::m_arg3, _scs_create(m_argname3))); -#define ADDFUNC4R(m_vtype, m_ret, m_class, m_method, m_arg1, m_argname1, m_arg2, m_argname2, m_arg3, m_argname3, m_arg4, m_argname4, m_defarg) \ - _VariantCall::addfunc(true, Variant::m_vtype, Variant::m_ret, true, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg, _VariantCall::Arg(Variant::m_arg1, _scs_create(m_argname1)), _VariantCall::Arg(Variant::m_arg2, _scs_create(m_argname2)), _VariantCall::Arg(Variant::m_arg3, _scs_create(m_argname3)), _VariantCall::Arg(Variant::m_arg4, _scs_create(m_argname4))); - -#define ADDFUNC0RNC(m_vtype, m_ret, m_class, m_method, m_defarg) \ - _VariantCall::addfunc(false, Variant::m_vtype, Variant::m_ret, true, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg); -#define ADDFUNC1RNC(m_vtype, m_ret, m_class, m_method, m_arg1, m_argname1, m_defarg) \ - _VariantCall::addfunc(false, Variant::m_vtype, Variant::m_ret, true, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg, _VariantCall::Arg(Variant::m_arg1, _scs_create(m_argname1))); -#define ADDFUNC2RNC(m_vtype, m_ret, m_class, m_method, m_arg1, m_argname1, m_arg2, m_argname2, m_defarg) \ - _VariantCall::addfunc(false, Variant::m_vtype, Variant::m_ret, true, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg, _VariantCall::Arg(Variant::m_arg1, _scs_create(m_argname1)), _VariantCall::Arg(Variant::m_arg2, _scs_create(m_argname2))); -#define ADDFUNC3RNC(m_vtype, m_ret, m_class, m_method, m_arg1, m_argname1, m_arg2, m_argname2, m_arg3, m_argname3, m_defarg) \ - _VariantCall::addfunc(false, Variant::m_vtype, Variant::m_ret, true, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg, _VariantCall::Arg(Variant::m_arg1, _scs_create(m_argname1)), _VariantCall::Arg(Variant::m_arg2, _scs_create(m_argname2)), _VariantCall::Arg(Variant::m_arg3, _scs_create(m_argname3))); -#define ADDFUNC4RNC(m_vtype, m_ret, m_class, m_method, m_arg1, m_argname1, m_arg2, m_argname2, m_arg3, m_argname3, m_arg4, m_argname4, m_defarg) \ - _VariantCall::addfunc(false, Variant::m_vtype, Variant::m_ret, true, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg, _VariantCall::Arg(Variant::m_arg1, _scs_create(m_argname1)), _VariantCall::Arg(Variant::m_arg2, _scs_create(m_argname2)), _VariantCall::Arg(Variant::m_arg3, _scs_create(m_argname3)), _VariantCall::Arg(Variant::m_arg4, _scs_create(m_argname4))); - -#define ADDFUNC0(m_vtype, m_ret, m_class, m_method, m_defarg) \ - _VariantCall::addfunc(true, Variant::m_vtype, Variant::m_ret, false, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg); -#define ADDFUNC1(m_vtype, m_ret, m_class, m_method, m_arg1, m_argname1, m_defarg) \ - _VariantCall::addfunc(true, Variant::m_vtype, Variant::m_ret, false, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg, _VariantCall::Arg(Variant::m_arg1, _scs_create(m_argname1))); -#define ADDFUNC2(m_vtype, m_ret, m_class, m_method, m_arg1, m_argname1, m_arg2, m_argname2, m_defarg) \ - _VariantCall::addfunc(true, Variant::m_vtype, Variant::m_ret, false, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg, _VariantCall::Arg(Variant::m_arg1, _scs_create(m_argname1)), _VariantCall::Arg(Variant::m_arg2, _scs_create(m_argname2))); -#define ADDFUNC3(m_vtype, m_ret, m_class, m_method, m_arg1, m_argname1, m_arg2, m_argname2, m_arg3, m_argname3, m_defarg) \ - _VariantCall::addfunc(true, Variant::m_vtype, Variant::m_ret, false, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg, _VariantCall::Arg(Variant::m_arg1, _scs_create(m_argname1)), _VariantCall::Arg(Variant::m_arg2, _scs_create(m_argname2)), _VariantCall::Arg(Variant::m_arg3, _scs_create(m_argname3))); -#define ADDFUNC4(m_vtype, m_ret, m_class, m_method, m_arg1, m_argname1, m_arg2, m_argname2, m_arg3, m_argname3, m_arg4, m_argname4, m_defarg) \ - _VariantCall::addfunc(true, Variant::m_vtype, Variant::m_ret, false, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg, _VariantCall::Arg(Variant::m_arg1, _scs_create(m_argname1)), _VariantCall::Arg(Variant::m_arg2, _scs_create(m_argname2)), _VariantCall::Arg(Variant::m_arg3, _scs_create(m_argname3)), _VariantCall::Arg(Variant::m_arg4, _scs_create(m_argname4))); - -#define ADDFUNC0NC(m_vtype, m_ret, m_class, m_method, m_defarg) \ - _VariantCall::addfunc(false, Variant::m_vtype, Variant::m_ret, false, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg); -#define ADDFUNC1NC(m_vtype, m_ret, m_class, m_method, m_arg1, m_argname1, m_defarg) \ - _VariantCall::addfunc(false, Variant::m_vtype, Variant::m_ret, false, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg, _VariantCall::Arg(Variant::m_arg1, _scs_create(m_argname1))); -#define ADDFUNC2NC(m_vtype, m_ret, m_class, m_method, m_arg1, m_argname1, m_arg2, m_argname2, m_defarg) \ - _VariantCall::addfunc(false, Variant::m_vtype, Variant::m_ret, false, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg, _VariantCall::Arg(Variant::m_arg1, _scs_create(m_argname1)), _VariantCall::Arg(Variant::m_arg2, _scs_create(m_argname2))); -#define ADDFUNC3NC(m_vtype, m_ret, m_class, m_method, m_arg1, m_argname1, m_arg2, m_argname2, m_arg3, m_argname3, m_defarg) \ - _VariantCall::addfunc(false, Variant::m_vtype, Variant::m_ret, false, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg, _VariantCall::Arg(Variant::m_arg1, _scs_create(m_argname1)), _VariantCall::Arg(Variant::m_arg2, _scs_create(m_argname2)), _VariantCall::Arg(Variant::m_arg3, _scs_create(m_argname3))); -#define ADDFUNC4NC(m_vtype, m_ret, m_class, m_method, m_arg1, m_argname1, m_arg2, m_argname2, m_arg3, m_argname3, m_arg4, m_argname4, m_defarg) \ - _VariantCall::addfunc(false, Variant::m_vtype, Variant::m_ret, false, _scs_create(#m_method), VCALL(m_class, m_method), m_defarg, _VariantCall::Arg(Variant::m_arg1, _scs_create(m_argname1)), _VariantCall::Arg(Variant::m_arg2, _scs_create(m_argname2)), _VariantCall::Arg(Variant::m_arg3, _scs_create(m_argname3)), _VariantCall::Arg(Variant::m_arg4, _scs_create(m_argname4))); - - /* STRING */ - ADDFUNC1R(STRING, INT, String, casecmp_to, STRING, "to", varray()); - ADDFUNC1R(STRING, INT, String, nocasecmp_to, STRING, "to", varray()); - ADDFUNC1R(STRING, INT, String, naturalnocasecmp_to, STRING, "to", varray()); - ADDFUNC0R(STRING, INT, String, length, varray()); - ADDFUNC2R(STRING, STRING, String, substr, INT, "from", INT, "len", varray(-1)); - - ADDFUNC2R(STRING, INT, String, find, STRING, "what", INT, "from", varray(0)); - - ADDFUNC3R(STRING, INT, String, count, STRING, "what", INT, "from", INT, "to", varray(0, 0)); - ADDFUNC3R(STRING, INT, String, countn, STRING, "what", INT, "from", INT, "to", varray(0, 0)); - - ADDFUNC2R(STRING, INT, String, findn, STRING, "what", INT, "from", varray(0)); - ADDFUNC2R(STRING, INT, String, rfind, STRING, "what", INT, "from", varray(-1)); - ADDFUNC2R(STRING, INT, String, rfindn, STRING, "what", INT, "from", varray(-1)); - ADDFUNC1R(STRING, BOOL, String, match, STRING, "expr", varray()); - ADDFUNC1R(STRING, BOOL, String, matchn, STRING, "expr", varray()); - ADDFUNC1R(STRING, BOOL, String, begins_with, STRING, "text", varray()); - ADDFUNC1R(STRING, BOOL, String, ends_with, STRING, "text", varray()); - ADDFUNC1R(STRING, BOOL, String, is_subsequence_of, STRING, "text", varray()); - ADDFUNC1R(STRING, BOOL, String, is_subsequence_ofi, STRING, "text", varray()); - ADDFUNC0R(STRING, PACKED_STRING_ARRAY, String, bigrams, varray()); - ADDFUNC1R(STRING, FLOAT, String, similarity, STRING, "text", varray()); - - ADDFUNC2R(STRING, STRING, String, format, NIL, "values", STRING, "placeholder", varray("{_}")); - ADDFUNC2R(STRING, STRING, String, replace, STRING, "what", STRING, "forwhat", varray()); - ADDFUNC2R(STRING, STRING, String, replacen, STRING, "what", STRING, "forwhat", varray()); - ADDFUNC1R(STRING, STRING, String, repeat, INT, "count", varray()); - ADDFUNC2R(STRING, STRING, String, insert, INT, "position", STRING, "what", varray()); - ADDFUNC0R(STRING, STRING, String, capitalize, varray()); - ADDFUNC3R(STRING, PACKED_STRING_ARRAY, String, split, STRING, "delimiter", BOOL, "allow_empty", INT, "maxsplit", varray(true, 0)); - ADDFUNC3R(STRING, PACKED_STRING_ARRAY, String, rsplit, STRING, "delimiter", BOOL, "allow_empty", INT, "maxsplit", varray(true, 0)); - ADDFUNC2R(STRING, PACKED_FLOAT32_ARRAY, String, split_floats, STRING, "delimiter", BOOL, "allow_empty", varray(true)); - ADDFUNC1R(STRING, STRING, String, join, PACKED_STRING_ARRAY, "parts", varray()); - - ADDFUNC0R(STRING, STRING, String, to_upper, varray()); - ADDFUNC0R(STRING, STRING, String, to_lower, varray()); - - ADDFUNC1R(STRING, STRING, String, left, INT, "position", varray()); - ADDFUNC1R(STRING, STRING, String, right, INT, "position", varray()); - ADDFUNC2R(STRING, STRING, String, strip_edges, BOOL, "left", BOOL, "right", varray(true, true)); - ADDFUNC0R(STRING, STRING, String, strip_escapes, varray()); - ADDFUNC1R(STRING, STRING, String, lstrip, STRING, "chars", varray()); - ADDFUNC1R(STRING, STRING, String, rstrip, STRING, "chars", varray()); - ADDFUNC0R(STRING, STRING, String, get_extension, varray()); - ADDFUNC0R(STRING, STRING, String, get_basename, varray()); - ADDFUNC1R(STRING, STRING, String, plus_file, STRING, "file", varray()); - ADDFUNC1R(STRING, INT, String, ord_at, INT, "at", varray()); - ADDFUNC0R(STRING, STRING, String, dedent, varray()); - ADDFUNC2(STRING, NIL, String, erase, INT, "position", INT, "chars", varray()); - ADDFUNC0R(STRING, INT, String, hash, varray()); - ADDFUNC0R(STRING, STRING, String, md5_text, varray()); - ADDFUNC0R(STRING, STRING, String, sha1_text, varray()); - ADDFUNC0R(STRING, STRING, String, sha256_text, varray()); - ADDFUNC0R(STRING, PACKED_BYTE_ARRAY, String, md5_buffer, varray()); - ADDFUNC0R(STRING, PACKED_BYTE_ARRAY, String, sha1_buffer, varray()); - ADDFUNC0R(STRING, PACKED_BYTE_ARRAY, String, sha256_buffer, varray()); - ADDFUNC0R(STRING, BOOL, String, empty, varray()); - ADDFUNC1R(STRING, STRING, String, humanize_size, INT, "size", varray()); - ADDFUNC0R(STRING, BOOL, String, is_abs_path, varray()); - ADDFUNC0R(STRING, BOOL, String, is_rel_path, varray()); - ADDFUNC0R(STRING, STRING, String, get_base_dir, varray()); - ADDFUNC0R(STRING, STRING, String, get_file, varray()); - ADDFUNC0R(STRING, STRING, String, xml_escape, varray()); - ADDFUNC0R(STRING, STRING, String, xml_unescape, varray()); - ADDFUNC0R(STRING, STRING, String, http_escape, varray()); - ADDFUNC0R(STRING, STRING, String, http_unescape, varray()); - ADDFUNC0R(STRING, STRING, String, c_escape, varray()); - ADDFUNC0R(STRING, STRING, String, c_unescape, varray()); - ADDFUNC0R(STRING, STRING, String, json_escape, varray()); - ADDFUNC0R(STRING, STRING, String, percent_encode, varray()); - ADDFUNC0R(STRING, STRING, String, percent_decode, varray()); - ADDFUNC0R(STRING, BOOL, String, is_valid_identifier, varray()); - ADDFUNC0R(STRING, BOOL, String, is_valid_integer, varray()); - ADDFUNC0R(STRING, BOOL, String, is_valid_float, varray()); - ADDFUNC1R(STRING, BOOL, String, is_valid_hex_number, BOOL, "with_prefix", varray(false)); - ADDFUNC0R(STRING, BOOL, String, is_valid_html_color, varray()); - ADDFUNC0R(STRING, BOOL, String, is_valid_ip_address, varray()); - ADDFUNC0R(STRING, BOOL, String, is_valid_filename, varray()); - ADDFUNC0R(STRING, INT, String, to_int, varray()); - ADDFUNC0R(STRING, FLOAT, String, to_float, varray()); - ADDFUNC0R(STRING, INT, String, hex_to_int, varray()); - ADDFUNC2R(STRING, STRING, String, lpad, INT, "min_length", STRING, "character", varray(" ")); - ADDFUNC2R(STRING, STRING, String, rpad, INT, "min_length", STRING, "character", varray(" ")); - ADDFUNC1R(STRING, STRING, String, pad_decimals, INT, "digits", varray()); - ADDFUNC1R(STRING, STRING, String, pad_zeros, INT, "digits", varray()); - ADDFUNC1R(STRING, STRING, String, trim_prefix, STRING, "prefix", varray()); - ADDFUNC1R(STRING, STRING, String, trim_suffix, STRING, "suffix", varray()); - - ADDFUNC0R(STRING, PACKED_BYTE_ARRAY, String, to_ascii, varray()); - ADDFUNC0R(STRING, PACKED_BYTE_ARRAY, String, to_utf8, varray()); - ADDFUNC0R(STRING, PACKED_BYTE_ARRAY, String, to_utf16, varray()); - ADDFUNC0R(STRING, PACKED_BYTE_ARRAY, String, to_utf32, varray()); - - ADDFUNC0R(VECTOR2, FLOAT, Vector2, angle, varray()); - ADDFUNC1R(VECTOR2, FLOAT, Vector2, angle_to, VECTOR2, "to", varray()); - ADDFUNC1R(VECTOR2, FLOAT, Vector2, angle_to_point, VECTOR2, "to", varray()); - ADDFUNC1R(VECTOR2, VECTOR2, Vector2, direction_to, VECTOR2, "b", varray()); - ADDFUNC1R(VECTOR2, FLOAT, Vector2, distance_to, VECTOR2, "to", varray()); - ADDFUNC1R(VECTOR2, FLOAT, Vector2, distance_squared_to, VECTOR2, "to", varray()); - ADDFUNC0R(VECTOR2, FLOAT, Vector2, length, varray()); - ADDFUNC0R(VECTOR2, FLOAT, Vector2, length_squared, varray()); - ADDFUNC0R(VECTOR2, VECTOR2, Vector2, normalized, varray()); - ADDFUNC0R(VECTOR2, BOOL, Vector2, is_normalized, varray()); - ADDFUNC1R(VECTOR2, BOOL, Vector2, is_equal_approx, VECTOR2, "v", varray()); - ADDFUNC1R(VECTOR2, VECTOR2, Vector2, posmod, FLOAT, "mod", varray()); - ADDFUNC1R(VECTOR2, VECTOR2, Vector2, posmodv, VECTOR2, "modv", varray()); - ADDFUNC1R(VECTOR2, VECTOR2, Vector2, project, VECTOR2, "b", varray()); - ADDFUNC2R(VECTOR2, VECTOR2, Vector2, lerp, VECTOR2, "b", FLOAT, "t", varray()); - ADDFUNC2R(VECTOR2, VECTOR2, Vector2, slerp, VECTOR2, "b", FLOAT, "t", varray()); - ADDFUNC4R(VECTOR2, VECTOR2, Vector2, cubic_interpolate, VECTOR2, "b", VECTOR2, "pre_a", VECTOR2, "post_b", FLOAT, "t", varray()); - ADDFUNC2R(VECTOR2, VECTOR2, Vector2, move_toward, VECTOR2, "to", FLOAT, "delta", varray()); - ADDFUNC1R(VECTOR2, VECTOR2, Vector2, rotated, FLOAT, "phi", varray()); - ADDFUNC0R(VECTOR2, VECTOR2, Vector2, tangent, varray()); - ADDFUNC0R(VECTOR2, VECTOR2, Vector2, floor, varray()); - ADDFUNC0R(VECTOR2, VECTOR2, Vector2, ceil, varray()); - ADDFUNC0R(VECTOR2, VECTOR2, Vector2, round, varray()); - ADDFUNC1R(VECTOR2, VECTOR2, Vector2, snapped, VECTOR2, "by", varray()); - ADDFUNC0R(VECTOR2, FLOAT, Vector2, aspect, varray()); - ADDFUNC1R(VECTOR2, FLOAT, Vector2, dot, VECTOR2, "with", varray()); - ADDFUNC1R(VECTOR2, VECTOR2, Vector2, slide, VECTOR2, "n", varray()); - ADDFUNC1R(VECTOR2, VECTOR2, Vector2, bounce, VECTOR2, "n", varray()); - ADDFUNC1R(VECTOR2, VECTOR2, Vector2, reflect, VECTOR2, "n", varray()); - ADDFUNC1R(VECTOR2, FLOAT, Vector2, cross, VECTOR2, "with", varray()); - ADDFUNC0R(VECTOR2, VECTOR2, Vector2, abs, varray()); - ADDFUNC1R(VECTOR2, VECTOR2, Vector2, clamped, FLOAT, "length", varray()); - ADDFUNC0R(VECTOR2, VECTOR2, Vector2, sign, varray()); - - ADDFUNC0R(VECTOR2I, FLOAT, Vector2i, aspect, varray()); - ADDFUNC0R(VECTOR2I, VECTOR2I, Vector2i, sign, varray()); - ADDFUNC0R(VECTOR2I, VECTOR2I, Vector2i, abs, varray()); - - ADDFUNC0R(RECT2, FLOAT, Rect2, get_area, varray()); - ADDFUNC0R(RECT2, BOOL, Rect2, has_no_area, varray()); - ADDFUNC1R(RECT2, BOOL, Rect2, has_point, VECTOR2, "point", varray()); - ADDFUNC1R(RECT2, BOOL, Rect2, is_equal_approx, RECT2, "rect", varray()); - ADDFUNC2R(RECT2, BOOL, Rect2, intersects, RECT2, "b", BOOL, "include_borders", varray(false)); - ADDFUNC1R(RECT2, BOOL, Rect2, encloses, RECT2, "b", varray()); - ADDFUNC1R(RECT2, RECT2, Rect2, clip, RECT2, "b", varray()); - ADDFUNC1R(RECT2, RECT2, Rect2, merge, RECT2, "b", varray()); - ADDFUNC1R(RECT2, RECT2, Rect2, expand, VECTOR2, "to", varray()); - ADDFUNC1R(RECT2, RECT2, Rect2, grow, FLOAT, "by", varray()); - ADDFUNC2R(RECT2, RECT2, Rect2, grow_margin, INT, "margin", FLOAT, "by", varray()); - ADDFUNC4R(RECT2, RECT2, Rect2, grow_individual, FLOAT, "left", FLOAT, "top", FLOAT, "right", FLOAT, " bottom", varray()); - ADDFUNC0R(RECT2, RECT2, Rect2, abs, varray()); - - ADDFUNC0R(RECT2I, INT, Rect2i, get_area, varray()); - ADDFUNC0R(RECT2I, BOOL, Rect2i, has_no_area, varray()); - ADDFUNC1R(RECT2I, BOOL, Rect2i, has_point, VECTOR2I, "point", varray()); - ADDFUNC1R(RECT2I, BOOL, Rect2i, intersects, RECT2I, "b", varray()); - ADDFUNC1R(RECT2I, BOOL, Rect2i, encloses, RECT2I, "b", varray()); - ADDFUNC1R(RECT2I, RECT2I, Rect2i, clip, RECT2I, "b", varray()); - ADDFUNC1R(RECT2I, RECT2I, Rect2i, merge, RECT2I, "b", varray()); - ADDFUNC1R(RECT2I, RECT2I, Rect2i, expand, VECTOR2I, "to", varray()); - ADDFUNC1R(RECT2I, RECT2I, Rect2i, grow, INT, "by", varray()); - ADDFUNC2R(RECT2I, RECT2I, Rect2i, grow_margin, INT, "margin", INT, "by", varray()); - ADDFUNC4R(RECT2I, RECT2I, Rect2i, grow_individual, INT, "left", INT, "top", INT, "right", INT, " bottom", varray()); - ADDFUNC0R(RECT2I, RECT2I, Rect2i, abs, varray()); - - ADDFUNC0R(VECTOR3, INT, Vector3, min_axis, varray()); - ADDFUNC0R(VECTOR3, INT, Vector3, max_axis, varray()); - ADDFUNC1R(VECTOR3, FLOAT, Vector3, angle_to, VECTOR3, "to", varray()); - ADDFUNC1R(VECTOR3, VECTOR3, Vector3, direction_to, VECTOR3, "b", varray()); - ADDFUNC1R(VECTOR3, FLOAT, Vector3, distance_to, VECTOR3, "b", varray()); - ADDFUNC1R(VECTOR3, FLOAT, Vector3, distance_squared_to, VECTOR3, "b", varray()); - ADDFUNC0R(VECTOR3, FLOAT, Vector3, length, varray()); - ADDFUNC0R(VECTOR3, FLOAT, Vector3, length_squared, varray()); - ADDFUNC0R(VECTOR3, VECTOR3, Vector3, normalized, varray()); - ADDFUNC0R(VECTOR3, BOOL, Vector3, is_normalized, varray()); - ADDFUNC1R(VECTOR3, BOOL, Vector3, is_equal_approx, VECTOR3, "v", varray()); - ADDFUNC0R(VECTOR3, VECTOR3, Vector3, inverse, varray()); - ADDFUNC1R(VECTOR3, VECTOR3, Vector3, snapped, VECTOR3, "by", varray()); - ADDFUNC2R(VECTOR3, VECTOR3, Vector3, rotated, VECTOR3, "axis", FLOAT, "phi", varray()); - ADDFUNC2R(VECTOR3, VECTOR3, Vector3, lerp, VECTOR3, "b", FLOAT, "t", varray()); - ADDFUNC2R(VECTOR3, VECTOR3, Vector3, slerp, VECTOR3, "b", FLOAT, "t", varray()); - ADDFUNC4R(VECTOR3, VECTOR3, Vector3, cubic_interpolate, VECTOR3, "b", VECTOR3, "pre_a", VECTOR3, "post_b", FLOAT, "t", varray()); - ADDFUNC2R(VECTOR3, VECTOR3, Vector3, move_toward, VECTOR3, "to", FLOAT, "delta", varray()); - ADDFUNC1R(VECTOR3, FLOAT, Vector3, dot, VECTOR3, "b", varray()); - ADDFUNC1R(VECTOR3, VECTOR3, Vector3, cross, VECTOR3, "b", varray()); - ADDFUNC1R(VECTOR3, BASIS, Vector3, outer, VECTOR3, "b", varray()); - ADDFUNC0R(VECTOR3, BASIS, Vector3, to_diagonal_matrix, varray()); - ADDFUNC0R(VECTOR3, VECTOR3, Vector3, abs, varray()); - ADDFUNC0R(VECTOR3, VECTOR3, Vector3, floor, varray()); - ADDFUNC0R(VECTOR3, VECTOR3, Vector3, ceil, varray()); - ADDFUNC0R(VECTOR3, VECTOR3, Vector3, round, varray()); - ADDFUNC1R(VECTOR3, VECTOR3, Vector3, posmod, FLOAT, "mod", varray()); - ADDFUNC1R(VECTOR3, VECTOR3, Vector3, posmodv, VECTOR3, "modv", varray()); - ADDFUNC1R(VECTOR3, VECTOR3, Vector3, project, VECTOR3, "b", varray()); - ADDFUNC1R(VECTOR3, VECTOR3, Vector3, slide, VECTOR3, "n", varray()); - ADDFUNC1R(VECTOR3, VECTOR3, Vector3, bounce, VECTOR3, "n", varray()); - ADDFUNC1R(VECTOR3, VECTOR3, Vector3, reflect, VECTOR3, "n", varray()); - ADDFUNC0R(VECTOR3, VECTOR3, Vector3, sign, varray()); - - ADDFUNC0R(VECTOR3I, INT, Vector3i, min_axis, varray()); - ADDFUNC0R(VECTOR3I, INT, Vector3i, max_axis, varray()); - ADDFUNC0R(VECTOR3I, VECTOR3I, Vector3i, sign, varray()); - - ADDFUNC0R(PLANE, PLANE, Plane, normalized, varray()); - ADDFUNC0R(PLANE, VECTOR3, Plane, center, varray()); - ADDFUNC1R(PLANE, BOOL, Plane, is_equal_approx, PLANE, "plane", varray()); - ADDFUNC1R(PLANE, BOOL, Plane, is_point_over, VECTOR3, "point", varray()); - ADDFUNC1R(PLANE, FLOAT, Plane, distance_to, VECTOR3, "point", varray()); - ADDFUNC2R(PLANE, BOOL, Plane, has_point, VECTOR3, "point", FLOAT, "epsilon", varray(CMP_EPSILON)); - ADDFUNC1R(PLANE, VECTOR3, Plane, project, VECTOR3, "point", varray()); - ADDFUNC2R(PLANE, VECTOR3, Plane, intersect_3, PLANE, "b", PLANE, "c", varray()); - ADDFUNC2R(PLANE, VECTOR3, Plane, intersects_ray, VECTOR3, "from", VECTOR3, "dir", varray()); - ADDFUNC2R(PLANE, VECTOR3, Plane, intersects_segment, VECTOR3, "begin", VECTOR3, "end", varray()); - - ADDFUNC0R(QUAT, FLOAT, Quat, length, varray()); - ADDFUNC0R(QUAT, FLOAT, Quat, length_squared, varray()); - ADDFUNC0R(QUAT, QUAT, Quat, normalized, varray()); - ADDFUNC0R(QUAT, BOOL, Quat, is_normalized, varray()); - ADDFUNC1R(QUAT, BOOL, Quat, is_equal_approx, QUAT, "quat", varray()); - ADDFUNC0R(QUAT, QUAT, Quat, inverse, varray()); - ADDFUNC1R(QUAT, FLOAT, Quat, dot, QUAT, "b", varray()); - ADDFUNC1R(QUAT, VECTOR3, Quat, xform, VECTOR3, "v", varray()); - ADDFUNC2R(QUAT, QUAT, Quat, slerp, QUAT, "b", FLOAT, "t", varray()); - ADDFUNC2R(QUAT, QUAT, Quat, slerpni, QUAT, "b", FLOAT, "t", varray()); - ADDFUNC4R(QUAT, QUAT, Quat, cubic_slerp, QUAT, "b", QUAT, "pre_a", QUAT, "post_b", FLOAT, "t", varray()); - ADDFUNC0R(QUAT, VECTOR3, Quat, get_euler, varray()); - ADDFUNC1(QUAT, NIL, Quat, set_euler, VECTOR3, "euler", varray()); - ADDFUNC2(QUAT, NIL, Quat, set_axis_angle, VECTOR3, "axis", FLOAT, "angle", varray()); - - ADDFUNC0R(COLOR, INT, Color, to_argb32, varray()); - ADDFUNC0R(COLOR, INT, Color, to_abgr32, varray()); - ADDFUNC0R(COLOR, INT, Color, to_rgba32, varray()); - ADDFUNC0R(COLOR, INT, Color, to_argb64, varray()); - ADDFUNC0R(COLOR, INT, Color, to_abgr64, varray()); - ADDFUNC0R(COLOR, INT, Color, to_rgba64, varray()); - ADDFUNC0R(COLOR, COLOR, Color, inverted, varray()); - ADDFUNC0R(COLOR, COLOR, Color, contrasted, varray()); - ADDFUNC2R(COLOR, COLOR, Color, lerp, COLOR, "b", FLOAT, "t", varray()); - ADDFUNC1R(COLOR, COLOR, Color, blend, COLOR, "over", varray()); - ADDFUNC1R(COLOR, COLOR, Color, lightened, FLOAT, "amount", varray()); - ADDFUNC1R(COLOR, COLOR, Color, darkened, FLOAT, "amount", varray()); - ADDFUNC1R(COLOR, STRING, Color, to_html, BOOL, "with_alpha", varray(true)); - ADDFUNC4R(COLOR, COLOR, Color, from_hsv, FLOAT, "h", FLOAT, "s", FLOAT, "v", FLOAT, "a", varray(1.0)); - ADDFUNC1R(COLOR, BOOL, Color, is_equal_approx, COLOR, "color", varray()); - - ADDFUNC0R(_RID, INT, RID, get_id, varray()); - - ADDFUNC0R(NODE_PATH, BOOL, NodePath, is_absolute, varray()); - ADDFUNC0R(NODE_PATH, INT, NodePath, get_name_count, varray()); - ADDFUNC1R(NODE_PATH, STRING, NodePath, get_name, INT, "idx", varray()); - ADDFUNC0R(NODE_PATH, INT, NodePath, get_subname_count, varray()); - ADDFUNC1R(NODE_PATH, STRING, NodePath, get_subname, INT, "idx", varray()); - ADDFUNC0R(NODE_PATH, STRING, NodePath, get_concatenated_subnames, varray()); - ADDFUNC0R(NODE_PATH, NODE_PATH, NodePath, get_as_property_path, varray()); - ADDFUNC0R(NODE_PATH, BOOL, NodePath, is_empty, varray()); - - ADDFUNC0R(DICTIONARY, INT, Dictionary, size, varray()); - ADDFUNC0R(DICTIONARY, BOOL, Dictionary, empty, varray()); - ADDFUNC0NC(DICTIONARY, NIL, Dictionary, clear, varray()); - ADDFUNC1R(DICTIONARY, BOOL, Dictionary, has, NIL, "key", varray()); - ADDFUNC1R(DICTIONARY, BOOL, Dictionary, has_all, ARRAY, "keys", varray()); - ADDFUNC1RNC(DICTIONARY, BOOL, Dictionary, erase, NIL, "key", varray()); - ADDFUNC0R(DICTIONARY, INT, Dictionary, hash, varray()); - ADDFUNC0R(DICTIONARY, ARRAY, Dictionary, keys, varray()); - ADDFUNC0R(DICTIONARY, ARRAY, Dictionary, values, varray()); - ADDFUNC1R(DICTIONARY, DICTIONARY, Dictionary, duplicate, BOOL, "deep", varray(false)); - ADDFUNC2R(DICTIONARY, NIL, Dictionary, get, NIL, "key", NIL, "default", varray(Variant())); - - ADDFUNC0R(CALLABLE, BOOL, Callable, is_null, varray()); - ADDFUNC0R(CALLABLE, BOOL, Callable, is_custom, varray()); - ADDFUNC0R(CALLABLE, BOOL, Callable, is_standard, varray()); - ADDFUNC0R(CALLABLE, OBJECT, Callable, get_object, varray()); - ADDFUNC0R(CALLABLE, INT, Callable, get_object_id, varray()); - ADDFUNC0R(CALLABLE, STRING_NAME, Callable, get_method, varray()); - ADDFUNC0R(CALLABLE, INT, Callable, hash, varray()); - - ADDFUNC0R(SIGNAL, BOOL, Signal, is_null, varray()); - ADDFUNC0R(SIGNAL, OBJECT, Signal, get_object, varray()); - ADDFUNC0R(SIGNAL, INT, Signal, get_object_id, varray()); - ADDFUNC0R(SIGNAL, STRING_NAME, Signal, get_name, varray()); - - ADDFUNC3R(SIGNAL, INT, Signal, connect, CALLABLE, "callable", ARRAY, "binds", INT, "flags", varray(Array(), 0)); - - ADDFUNC1R(SIGNAL, NIL, Signal, disconnect, CALLABLE, "callable", varray()); - ADDFUNC1R(SIGNAL, BOOL, Signal, is_connected, CALLABLE, "callable", varray()); - ADDFUNC0R(SIGNAL, ARRAY, Signal, get_connections, varray()); - - ADDFUNC0R(ARRAY, INT, Array, size, varray()); - ADDFUNC0R(ARRAY, BOOL, Array, empty, varray()); - ADDFUNC0NC(ARRAY, NIL, Array, clear, varray()); - ADDFUNC0R(ARRAY, INT, Array, hash, varray()); - ADDFUNC1NC(ARRAY, NIL, Array, push_back, NIL, "value", varray()); - ADDFUNC1NC(ARRAY, NIL, Array, push_front, NIL, "value", varray()); - ADDFUNC1NC(ARRAY, NIL, Array, append, NIL, "value", varray()); - ADDFUNC1NC(ARRAY, NIL, Array, resize, INT, "size", varray()); - ADDFUNC2NC(ARRAY, NIL, Array, insert, INT, "position", NIL, "value", varray()); - ADDFUNC1NC(ARRAY, NIL, Array, remove, INT, "position", varray()); - ADDFUNC1NC(ARRAY, NIL, Array, erase, NIL, "value", varray()); - ADDFUNC0R(ARRAY, NIL, Array, front, varray()); - ADDFUNC0R(ARRAY, NIL, Array, back, varray()); - ADDFUNC2R(ARRAY, INT, Array, find, NIL, "what", INT, "from", varray(0)); - ADDFUNC2R(ARRAY, INT, Array, rfind, NIL, "what", INT, "from", varray(-1)); - ADDFUNC1R(ARRAY, INT, Array, find_last, NIL, "value", varray()); - ADDFUNC1R(ARRAY, INT, Array, count, NIL, "value", varray()); - ADDFUNC1R(ARRAY, BOOL, Array, has, NIL, "value", varray()); - ADDFUNC0RNC(ARRAY, NIL, Array, pop_back, varray()); - ADDFUNC0RNC(ARRAY, NIL, Array, pop_front, varray()); - ADDFUNC0NC(ARRAY, NIL, Array, sort, varray()); - ADDFUNC2NC(ARRAY, NIL, Array, sort_custom, OBJECT, "obj", STRING, "func", varray()); - ADDFUNC0NC(ARRAY, NIL, Array, shuffle, varray()); - ADDFUNC2R(ARRAY, INT, Array, bsearch, NIL, "value", BOOL, "before", varray(true)); - ADDFUNC4R(ARRAY, INT, Array, bsearch_custom, NIL, "value", OBJECT, "obj", STRING, "func", BOOL, "before", varray(true)); - ADDFUNC0NC(ARRAY, NIL, Array, invert, varray()); - ADDFUNC1R(ARRAY, ARRAY, Array, duplicate, BOOL, "deep", varray(false)); - ADDFUNC4R(ARRAY, ARRAY, Array, slice, INT, "begin", INT, "end", INT, "step", BOOL, "deep", varray(1, false)); - ADDFUNC0R(ARRAY, NIL, Array, max, varray()); - ADDFUNC0R(ARRAY, NIL, Array, min, varray()); - - ADDFUNC0R(PACKED_BYTE_ARRAY, INT, PackedByteArray, size, varray()); - ADDFUNC0R(PACKED_BYTE_ARRAY, BOOL, PackedByteArray, empty, varray()); - ADDFUNC2(PACKED_BYTE_ARRAY, NIL, PackedByteArray, set, INT, "idx", INT, "byte", varray()); - ADDFUNC1(PACKED_BYTE_ARRAY, NIL, PackedByteArray, push_back, INT, "byte", varray()); - ADDFUNC1(PACKED_BYTE_ARRAY, NIL, PackedByteArray, append, INT, "byte", varray()); - ADDFUNC1(PACKED_BYTE_ARRAY, NIL, PackedByteArray, append_array, PACKED_BYTE_ARRAY, "array", varray()); - ADDFUNC1(PACKED_BYTE_ARRAY, NIL, PackedByteArray, remove, INT, "idx", varray()); - ADDFUNC2R(PACKED_BYTE_ARRAY, INT, PackedByteArray, insert, INT, "idx", INT, "byte", varray()); - ADDFUNC1(PACKED_BYTE_ARRAY, NIL, PackedByteArray, resize, INT, "idx", varray()); - ADDFUNC1R(PACKED_BYTE_ARRAY, BOOL, PackedByteArray, has, INT, "value", varray()); - ADDFUNC0(PACKED_BYTE_ARRAY, NIL, PackedByteArray, sort, varray()); - ADDFUNC0(PACKED_BYTE_ARRAY, NIL, PackedByteArray, invert, varray()); - ADDFUNC2R(PACKED_BYTE_ARRAY, PACKED_BYTE_ARRAY, PackedByteArray, subarray, INT, "from", INT, "to", varray()); - - ADDFUNC0R(PACKED_BYTE_ARRAY, STRING, PackedByteArray, get_string_from_ascii, varray()); - ADDFUNC0R(PACKED_BYTE_ARRAY, STRING, PackedByteArray, get_string_from_utf8, varray()); - ADDFUNC0R(PACKED_BYTE_ARRAY, STRING, PackedByteArray, get_string_from_utf16, varray()); - ADDFUNC0R(PACKED_BYTE_ARRAY, STRING, PackedByteArray, get_string_from_utf32, varray()); - ADDFUNC0R(PACKED_BYTE_ARRAY, STRING, PackedByteArray, hex_encode, varray()); - ADDFUNC1R(PACKED_BYTE_ARRAY, PACKED_BYTE_ARRAY, PackedByteArray, compress, INT, "compression_mode", varray(0)); - ADDFUNC2R(PACKED_BYTE_ARRAY, PACKED_BYTE_ARRAY, PackedByteArray, decompress, INT, "buffer_size", INT, "compression_mode", varray(0)); - ADDFUNC2R(PACKED_BYTE_ARRAY, PACKED_BYTE_ARRAY, PackedByteArray, decompress_dynamic, INT, "max_output_size", INT, "compression_mode", varray(0)); - - ADDFUNC0R(PACKED_INT32_ARRAY, INT, PackedInt32Array, size, varray()); - ADDFUNC0R(PACKED_INT32_ARRAY, BOOL, PackedInt32Array, empty, varray()); - ADDFUNC2(PACKED_INT32_ARRAY, NIL, PackedInt32Array, set, INT, "idx", INT, "integer", varray()); - ADDFUNC1(PACKED_INT32_ARRAY, NIL, PackedInt32Array, push_back, INT, "integer", varray()); - ADDFUNC1(PACKED_INT32_ARRAY, NIL, PackedInt32Array, append, INT, "integer", varray()); - ADDFUNC1(PACKED_INT32_ARRAY, NIL, PackedInt32Array, append_array, PACKED_INT32_ARRAY, "array", varray()); - ADDFUNC1(PACKED_INT32_ARRAY, NIL, PackedInt32Array, remove, INT, "idx", varray()); - ADDFUNC2R(PACKED_INT32_ARRAY, INT, PackedInt32Array, insert, INT, "idx", INT, "integer", varray()); - ADDFUNC1(PACKED_INT32_ARRAY, NIL, PackedInt32Array, resize, INT, "idx", varray()); - ADDFUNC1R(PACKED_INT32_ARRAY, BOOL, PackedInt32Array, has, INT, "value", varray()); - ADDFUNC0(PACKED_INT32_ARRAY, NIL, PackedInt32Array, sort, varray()); - ADDFUNC0(PACKED_INT32_ARRAY, NIL, PackedInt32Array, invert, varray()); - - ADDFUNC0R(PACKED_INT64_ARRAY, INT, PackedInt64Array, size, varray()); - ADDFUNC0R(PACKED_INT64_ARRAY, BOOL, PackedInt64Array, empty, varray()); - ADDFUNC2(PACKED_INT64_ARRAY, NIL, PackedInt64Array, set, INT, "idx", INT, "integer", varray()); - ADDFUNC1(PACKED_INT64_ARRAY, NIL, PackedInt64Array, push_back, INT, "integer", varray()); - ADDFUNC1(PACKED_INT64_ARRAY, NIL, PackedInt64Array, append, INT, "integer", varray()); - ADDFUNC1(PACKED_INT64_ARRAY, NIL, PackedInt64Array, append_array, PACKED_INT64_ARRAY, "array", varray()); - ADDFUNC1(PACKED_INT64_ARRAY, NIL, PackedInt64Array, remove, INT, "idx", varray()); - ADDFUNC2R(PACKED_INT64_ARRAY, INT, PackedInt64Array, insert, INT, "idx", INT, "integer", varray()); - ADDFUNC1(PACKED_INT64_ARRAY, NIL, PackedInt64Array, resize, INT, "idx", varray()); - ADDFUNC1R(PACKED_INT64_ARRAY, BOOL, PackedInt64Array, has, INT, "value", varray()); - ADDFUNC0(PACKED_INT64_ARRAY, NIL, PackedInt64Array, sort, varray()); - ADDFUNC0(PACKED_INT64_ARRAY, NIL, PackedInt64Array, invert, varray()); - - ADDFUNC0R(PACKED_FLOAT32_ARRAY, INT, PackedFloat32Array, size, varray()); - ADDFUNC0R(PACKED_FLOAT32_ARRAY, BOOL, PackedFloat32Array, empty, varray()); - ADDFUNC2(PACKED_FLOAT32_ARRAY, NIL, PackedFloat32Array, set, INT, "idx", FLOAT, "value", varray()); - ADDFUNC1(PACKED_FLOAT32_ARRAY, NIL, PackedFloat32Array, push_back, FLOAT, "value", varray()); - ADDFUNC1(PACKED_FLOAT32_ARRAY, NIL, PackedFloat32Array, append, FLOAT, "value", varray()); - ADDFUNC1(PACKED_FLOAT32_ARRAY, NIL, PackedFloat32Array, append_array, PACKED_FLOAT32_ARRAY, "array", varray()); - ADDFUNC1(PACKED_FLOAT32_ARRAY, NIL, PackedFloat32Array, remove, INT, "idx", varray()); - ADDFUNC2R(PACKED_FLOAT32_ARRAY, INT, PackedFloat32Array, insert, INT, "idx", FLOAT, "value", varray()); - ADDFUNC1(PACKED_FLOAT32_ARRAY, NIL, PackedFloat32Array, resize, INT, "idx", varray()); - ADDFUNC1R(PACKED_FLOAT32_ARRAY, BOOL, PackedFloat32Array, has, FLOAT, "value", varray()); - ADDFUNC0(PACKED_FLOAT32_ARRAY, NIL, PackedFloat32Array, sort, varray()); - ADDFUNC0(PACKED_FLOAT32_ARRAY, NIL, PackedFloat32Array, invert, varray()); - - ADDFUNC0R(PACKED_FLOAT64_ARRAY, INT, PackedFloat64Array, size, varray()); - ADDFUNC0R(PACKED_FLOAT64_ARRAY, BOOL, PackedFloat64Array, empty, varray()); - ADDFUNC2(PACKED_FLOAT64_ARRAY, NIL, PackedFloat64Array, set, INT, "idx", FLOAT, "value", varray()); - ADDFUNC1(PACKED_FLOAT64_ARRAY, NIL, PackedFloat64Array, push_back, FLOAT, "value", varray()); - ADDFUNC1(PACKED_FLOAT64_ARRAY, NIL, PackedFloat64Array, append, FLOAT, "value", varray()); - ADDFUNC1(PACKED_FLOAT64_ARRAY, NIL, PackedFloat64Array, append_array, PACKED_FLOAT64_ARRAY, "array", varray()); - ADDFUNC1(PACKED_FLOAT64_ARRAY, NIL, PackedFloat64Array, remove, INT, "idx", varray()); - ADDFUNC2R(PACKED_FLOAT64_ARRAY, INT, PackedFloat64Array, insert, INT, "idx", FLOAT, "value", varray()); - ADDFUNC1(PACKED_FLOAT64_ARRAY, NIL, PackedFloat64Array, resize, INT, "idx", varray()); - ADDFUNC1R(PACKED_FLOAT64_ARRAY, BOOL, PackedFloat64Array, has, FLOAT, "value", varray()); - ADDFUNC0(PACKED_FLOAT64_ARRAY, NIL, PackedFloat64Array, sort, varray()); - ADDFUNC0(PACKED_FLOAT64_ARRAY, NIL, PackedFloat64Array, invert, varray()); - - ADDFUNC0R(PACKED_STRING_ARRAY, INT, PackedStringArray, size, varray()); - ADDFUNC0R(PACKED_STRING_ARRAY, BOOL, PackedStringArray, empty, varray()); - ADDFUNC2(PACKED_STRING_ARRAY, NIL, PackedStringArray, set, INT, "idx", STRING, "string", varray()); - ADDFUNC1(PACKED_STRING_ARRAY, NIL, PackedStringArray, push_back, STRING, "string", varray()); - ADDFUNC1(PACKED_STRING_ARRAY, NIL, PackedStringArray, append, STRING, "string", varray()); - ADDFUNC1(PACKED_STRING_ARRAY, NIL, PackedStringArray, append_array, PACKED_STRING_ARRAY, "array", varray()); - ADDFUNC1(PACKED_STRING_ARRAY, NIL, PackedStringArray, remove, INT, "idx", varray()); - ADDFUNC2R(PACKED_STRING_ARRAY, INT, PackedStringArray, insert, INT, "idx", STRING, "string", varray()); - ADDFUNC1(PACKED_STRING_ARRAY, NIL, PackedStringArray, resize, INT, "idx", varray()); - ADDFUNC1R(PACKED_STRING_ARRAY, BOOL, PackedStringArray, has, STRING, "value", varray()); - ADDFUNC0(PACKED_STRING_ARRAY, NIL, PackedStringArray, sort, varray()); - ADDFUNC0(PACKED_STRING_ARRAY, NIL, PackedStringArray, invert, varray()); - - ADDFUNC0R(PACKED_VECTOR2_ARRAY, INT, PackedVector2Array, size, varray()); - ADDFUNC0R(PACKED_VECTOR2_ARRAY, BOOL, PackedVector2Array, empty, varray()); - ADDFUNC2(PACKED_VECTOR2_ARRAY, NIL, PackedVector2Array, set, INT, "idx", VECTOR2, "vector2", varray()); - ADDFUNC1(PACKED_VECTOR2_ARRAY, NIL, PackedVector2Array, push_back, VECTOR2, "vector2", varray()); - ADDFUNC1(PACKED_VECTOR2_ARRAY, NIL, PackedVector2Array, append, VECTOR2, "vector2", varray()); - ADDFUNC1(PACKED_VECTOR2_ARRAY, NIL, PackedVector2Array, append_array, PACKED_VECTOR2_ARRAY, "array", varray()); - ADDFUNC1(PACKED_VECTOR2_ARRAY, NIL, PackedVector2Array, remove, INT, "idx", varray()); - ADDFUNC2R(PACKED_VECTOR2_ARRAY, INT, PackedVector2Array, insert, INT, "idx", VECTOR2, "vector2", varray()); - ADDFUNC1(PACKED_VECTOR2_ARRAY, NIL, PackedVector2Array, resize, INT, "idx", varray()); - ADDFUNC1R(PACKED_VECTOR2_ARRAY, BOOL, PackedVector2Array, has, VECTOR2, "value", varray()); - ADDFUNC0(PACKED_VECTOR2_ARRAY, NIL, PackedVector2Array, sort, varray()); - ADDFUNC0(PACKED_VECTOR2_ARRAY, NIL, PackedVector2Array, invert, varray()); - - ADDFUNC0R(PACKED_VECTOR3_ARRAY, INT, PackedVector3Array, size, varray()); - ADDFUNC0R(PACKED_VECTOR3_ARRAY, BOOL, PackedVector3Array, empty, varray()); - ADDFUNC2(PACKED_VECTOR3_ARRAY, NIL, PackedVector3Array, set, INT, "idx", VECTOR3, "vector3", varray()); - ADDFUNC1(PACKED_VECTOR3_ARRAY, NIL, PackedVector3Array, push_back, VECTOR3, "vector3", varray()); - ADDFUNC1(PACKED_VECTOR3_ARRAY, NIL, PackedVector3Array, append, VECTOR3, "vector3", varray()); - ADDFUNC1(PACKED_VECTOR3_ARRAY, NIL, PackedVector3Array, append_array, PACKED_VECTOR3_ARRAY, "array", varray()); - ADDFUNC1(PACKED_VECTOR3_ARRAY, NIL, PackedVector3Array, remove, INT, "idx", varray()); - ADDFUNC2R(PACKED_VECTOR3_ARRAY, INT, PackedVector3Array, insert, INT, "idx", VECTOR3, "vector3", varray()); - ADDFUNC1(PACKED_VECTOR3_ARRAY, NIL, PackedVector3Array, resize, INT, "idx", varray()); - ADDFUNC1R(PACKED_VECTOR3_ARRAY, BOOL, PackedVector3Array, has, VECTOR3, "value", varray()); - ADDFUNC0(PACKED_VECTOR3_ARRAY, NIL, PackedVector3Array, sort, varray()); - ADDFUNC0(PACKED_VECTOR3_ARRAY, NIL, PackedVector3Array, invert, varray()); - - ADDFUNC0R(PACKED_COLOR_ARRAY, INT, PackedColorArray, size, varray()); - ADDFUNC0R(PACKED_COLOR_ARRAY, BOOL, PackedColorArray, empty, varray()); - ADDFUNC2(PACKED_COLOR_ARRAY, NIL, PackedColorArray, set, INT, "idx", COLOR, "color", varray()); - ADDFUNC1(PACKED_COLOR_ARRAY, NIL, PackedColorArray, push_back, COLOR, "color", varray()); - ADDFUNC1(PACKED_COLOR_ARRAY, NIL, PackedColorArray, append, COLOR, "color", varray()); - ADDFUNC1(PACKED_COLOR_ARRAY, NIL, PackedColorArray, append_array, PACKED_COLOR_ARRAY, "array", varray()); - ADDFUNC1(PACKED_COLOR_ARRAY, NIL, PackedColorArray, remove, INT, "idx", varray()); - ADDFUNC2R(PACKED_COLOR_ARRAY, INT, PackedColorArray, insert, INT, "idx", COLOR, "color", varray()); - ADDFUNC1(PACKED_COLOR_ARRAY, NIL, PackedColorArray, resize, INT, "idx", varray()); - ADDFUNC1R(PACKED_COLOR_ARRAY, BOOL, PackedColorArray, has, COLOR, "value", varray()); - ADDFUNC0(PACKED_COLOR_ARRAY, NIL, PackedColorArray, sort, varray()); - ADDFUNC0(PACKED_COLOR_ARRAY, NIL, PackedColorArray, invert, varray()); - - //pointerbased - - ADDFUNC0R(AABB, AABB, AABB, abs, varray()); - ADDFUNC0R(AABB, FLOAT, AABB, get_area, varray()); - ADDFUNC0R(AABB, BOOL, AABB, has_no_area, varray()); - ADDFUNC0R(AABB, BOOL, AABB, has_no_surface, varray()); - ADDFUNC1R(AABB, BOOL, AABB, has_point, VECTOR3, "point", varray()); - ADDFUNC1R(AABB, BOOL, AABB, is_equal_approx, AABB, "aabb", varray()); - ADDFUNC1R(AABB, BOOL, AABB, intersects, AABB, "with", varray()); - ADDFUNC1R(AABB, BOOL, AABB, encloses, AABB, "with", varray()); - ADDFUNC1R(AABB, BOOL, AABB, intersects_plane, PLANE, "plane", varray()); - ADDFUNC2R(AABB, BOOL, AABB, intersects_segment, VECTOR3, "from", VECTOR3, "to", varray()); - ADDFUNC1R(AABB, AABB, AABB, intersection, AABB, "with", varray()); - ADDFUNC1R(AABB, AABB, AABB, merge, AABB, "with", varray()); - ADDFUNC1R(AABB, AABB, AABB, expand, VECTOR3, "to_point", varray()); - ADDFUNC1R(AABB, AABB, AABB, grow, FLOAT, "by", varray()); - ADDFUNC1R(AABB, VECTOR3, AABB, get_support, VECTOR3, "dir", varray()); - ADDFUNC0R(AABB, VECTOR3, AABB, get_longest_axis, varray()); - ADDFUNC0R(AABB, INT, AABB, get_longest_axis_index, varray()); - ADDFUNC0R(AABB, FLOAT, AABB, get_longest_axis_size, varray()); - ADDFUNC0R(AABB, VECTOR3, AABB, get_shortest_axis, varray()); - ADDFUNC0R(AABB, INT, AABB, get_shortest_axis_index, varray()); - ADDFUNC0R(AABB, FLOAT, AABB, get_shortest_axis_size, varray()); - ADDFUNC1R(AABB, VECTOR3, AABB, get_endpoint, INT, "idx", varray()); - - ADDFUNC0R(TRANSFORM2D, TRANSFORM2D, Transform2D, inverse, varray()); - ADDFUNC0R(TRANSFORM2D, TRANSFORM2D, Transform2D, affine_inverse, varray()); - ADDFUNC0R(TRANSFORM2D, FLOAT, Transform2D, get_rotation, varray()); - ADDFUNC0R(TRANSFORM2D, VECTOR2, Transform2D, get_origin, varray()); - ADDFUNC0R(TRANSFORM2D, VECTOR2, Transform2D, get_scale, varray()); - ADDFUNC0R(TRANSFORM2D, TRANSFORM2D, Transform2D, orthonormalized, varray()); - ADDFUNC1R(TRANSFORM2D, TRANSFORM2D, Transform2D, rotated, FLOAT, "phi", varray()); - ADDFUNC1R(TRANSFORM2D, TRANSFORM2D, Transform2D, scaled, VECTOR2, "scale", varray()); - ADDFUNC1R(TRANSFORM2D, TRANSFORM2D, Transform2D, translated, VECTOR2, "offset", varray()); - ADDFUNC1R(TRANSFORM2D, NIL, Transform2D, xform, NIL, "v", varray()); - ADDFUNC1R(TRANSFORM2D, NIL, Transform2D, xform_inv, NIL, "v", varray()); - ADDFUNC1R(TRANSFORM2D, VECTOR2, Transform2D, basis_xform, VECTOR2, "v", varray()); - ADDFUNC1R(TRANSFORM2D, VECTOR2, Transform2D, basis_xform_inv, VECTOR2, "v", varray()); - ADDFUNC2R(TRANSFORM2D, TRANSFORM2D, Transform2D, interpolate_with, TRANSFORM2D, "transform", FLOAT, "weight", varray()); - ADDFUNC1R(TRANSFORM2D, BOOL, Transform2D, is_equal_approx, TRANSFORM2D, "transform", varray()); - - ADDFUNC0R(BASIS, BASIS, Basis, inverse, varray()); - ADDFUNC0R(BASIS, BASIS, Basis, transposed, varray()); - ADDFUNC0R(BASIS, BASIS, Basis, orthonormalized, varray()); - ADDFUNC0R(BASIS, FLOAT, Basis, determinant, varray()); - ADDFUNC2R(BASIS, BASIS, Basis, rotated, VECTOR3, "axis", FLOAT, "phi", varray()); - ADDFUNC1R(BASIS, BASIS, Basis, scaled, VECTOR3, "scale", varray()); - ADDFUNC0R(BASIS, VECTOR3, Basis, get_scale, varray()); - ADDFUNC0R(BASIS, VECTOR3, Basis, get_euler, varray()); - ADDFUNC1R(BASIS, FLOAT, Basis, tdotx, VECTOR3, "with", varray()); - ADDFUNC1R(BASIS, FLOAT, Basis, tdoty, VECTOR3, "with", varray()); - ADDFUNC1R(BASIS, FLOAT, Basis, tdotz, VECTOR3, "with", varray()); - ADDFUNC1R(BASIS, VECTOR3, Basis, xform, VECTOR3, "v", varray()); - ADDFUNC1R(BASIS, VECTOR3, Basis, xform_inv, VECTOR3, "v", varray()); - ADDFUNC0R(BASIS, INT, Basis, get_orthogonal_index, varray()); - ADDFUNC2R(BASIS, BASIS, Basis, slerp, BASIS, "b", FLOAT, "t", varray()); - ADDFUNC1R(BASIS, BOOL, Basis, is_equal_approx, BASIS, "b", varray()); - ADDFUNC0R(BASIS, QUAT, Basis, get_rotation_quat, varray()); - - ADDFUNC0R(TRANSFORM, TRANSFORM, Transform, inverse, varray()); - ADDFUNC0R(TRANSFORM, TRANSFORM, Transform, affine_inverse, varray()); - ADDFUNC0R(TRANSFORM, TRANSFORM, Transform, orthonormalized, varray()); - ADDFUNC2R(TRANSFORM, TRANSFORM, Transform, rotated, VECTOR3, "axis", FLOAT, "phi", varray()); - ADDFUNC1R(TRANSFORM, TRANSFORM, Transform, scaled, VECTOR3, "scale", varray()); - ADDFUNC1R(TRANSFORM, TRANSFORM, Transform, translated, VECTOR3, "offset", varray()); - ADDFUNC2R(TRANSFORM, TRANSFORM, Transform, looking_at, VECTOR3, "target", VECTOR3, "up", varray()); - ADDFUNC2R(TRANSFORM, TRANSFORM, Transform, interpolate_with, TRANSFORM, "transform", FLOAT, "weight", varray()); - ADDFUNC1R(TRANSFORM, BOOL, Transform, is_equal_approx, TRANSFORM, "transform", varray()); - ADDFUNC1R(TRANSFORM, NIL, Transform, xform, NIL, "v", varray()); - ADDFUNC1R(TRANSFORM, NIL, Transform, xform_inv, NIL, "v", varray()); - - /* REGISTER CONSTRUCTORS */ + /* String */ + + bind_method(String, casecmp_to, sarray("to"), varray()); + bind_method(String, nocasecmp_to, sarray("to"), varray()); + bind_method(String, naturalnocasecmp_to, sarray("to"), varray()); + bind_method(String, length, sarray(), varray()); + bind_method(String, substr, sarray("from", "len"), varray(-1)); + bind_methodv(find, static_cast<int (String::*)(const String &, int) const>(&String::find), sarray("what", "from"), varray(0)); + bind_method(String, count, sarray("what", "from", "to"), varray(0, 0)); + bind_method(String, countn, sarray("what", "from", "to"), varray(0, 0)); + bind_method(String, findn, sarray("what", "from"), varray(0)); + bind_method(String, rfind, sarray("what", "from"), varray(-1)); + bind_method(String, rfindn, sarray("what", "from"), varray(-1)); + bind_method(String, match, sarray("expr"), varray()); + bind_method(String, matchn, sarray("expr"), varray()); + bind_methodv(begins_with, static_cast<bool (String::*)(const String &) const>(&String::begins_with), sarray("text"), varray()); + bind_method(String, ends_with, sarray("text"), varray()); + bind_method(String, is_subsequence_of, sarray("text"), varray()); + bind_method(String, is_subsequence_ofi, sarray("text"), varray()); + bind_method(String, bigrams, sarray(), varray()); + bind_method(String, similarity, sarray("text"), varray()); + + bind_method(String, format, sarray("values", "placeholder"), varray("{_}")); + bind_methodv(replace, static_cast<String (String::*)(const String &, const String &) const>(&String::replace), sarray("what", "forwhat"), varray()); + bind_method(String, replacen, sarray("what", "forwhat"), varray()); + bind_method(String, repeat, sarray("count"), varray()); + bind_method(String, insert, sarray("position", "what"), varray()); + bind_method(String, capitalize, sarray(), varray()); + bind_method(String, split, sarray("delimiter", "allow_empty", "maxsplit"), varray(true, 0)); + bind_method(String, rsplit, sarray("delimiter", "allow_empty", "maxsplit"), varray(true, 0)); + bind_method(String, split_floats, sarray("delimiter", "allow_empty"), varray(true)); + bind_method(String, join, sarray("parts"), varray()); + + bind_method(String, to_upper, sarray(), varray()); + bind_method(String, to_lower, sarray(), varray()); + + bind_method(String, left, sarray("position"), varray()); + bind_method(String, right, sarray("position"), varray()); + + bind_method(String, strip_edges, sarray("left", "right"), varray(true, true)); + bind_method(String, strip_escapes, sarray(), varray()); + bind_method(String, lstrip, sarray("chars"), varray()); + bind_method(String, rstrip, sarray("chars"), varray()); + bind_method(String, get_extension, sarray(), varray()); + bind_method(String, get_basename, sarray(), varray()); + bind_method(String, plus_file, sarray("file"), varray()); + bind_method(String, ord_at, sarray("at"), varray()); + bind_method(String, dedent, sarray(), varray()); + // FIXME: String needs to be immutable when binding + //bind_method(String, erase, sarray("position", "chars"), varray()); + bind_method(String, hash, sarray(), varray()); + bind_method(String, md5_text, sarray(), varray()); + bind_method(String, sha1_text, sarray(), varray()); + bind_method(String, sha256_text, sarray(), varray()); + bind_method(String, md5_buffer, sarray(), varray()); + bind_method(String, sha1_buffer, sarray(), varray()); + bind_method(String, sha256_buffer, sarray(), varray()); + bind_method(String, empty, sarray(), varray()); + // FIXME: Static function, not sure how to bind + //bind_method(String, humanize_size, sarray("size"), varray()); + + bind_method(String, is_abs_path, sarray(), varray()); + bind_method(String, is_rel_path, sarray(), varray()); + bind_method(String, get_base_dir, sarray(), varray()); + bind_method(String, get_file, sarray(), varray()); + bind_method(String, xml_escape, sarray("escape_quotes"), varray(false)); + bind_method(String, xml_unescape, sarray(), varray()); + bind_method(String, http_escape, sarray(), varray()); + bind_method(String, http_unescape, sarray(), varray()); + bind_method(String, c_escape, sarray(), varray()); + bind_method(String, c_unescape, sarray(), varray()); + bind_method(String, json_escape, sarray(), varray()); + bind_method(String, percent_encode, sarray(), varray()); + bind_method(String, percent_decode, sarray(), varray()); + + bind_method(String, is_valid_identifier, sarray(), varray()); + bind_method(String, is_valid_integer, sarray(), varray()); + bind_method(String, is_valid_float, sarray(), varray()); + bind_method(String, is_valid_hex_number, sarray("with_prefix"), varray(false)); + bind_method(String, is_valid_html_color, sarray(), varray()); + bind_method(String, is_valid_ip_address, sarray(), varray()); + bind_method(String, is_valid_filename, sarray(), varray()); + + bind_method(String, to_int, sarray(), varray()); + bind_method(String, to_float, sarray(), varray()); + bind_method(String, hex_to_int, sarray("with_prefix"), varray(true)); + bind_method(String, bin_to_int, sarray("with_prefix"), varray(true)); + + bind_method(String, lpad, sarray("min_length", "character"), varray(" ")); + bind_method(String, rpad, sarray("min_length", "character"), varray(" ")); + bind_method(String, pad_decimals, sarray("digits"), varray()); + bind_method(String, pad_zeros, sarray("digits"), varray()); + bind_method(String, trim_prefix, sarray("prefix"), varray()); + bind_method(String, trim_suffix, sarray("suffix"), varray()); + + bind_method(String, to_ascii_buffer, sarray(), varray()); + bind_method(String, to_utf8_buffer, sarray(), varray()); + bind_method(String, to_utf16_buffer, sarray(), varray()); + bind_method(String, to_utf32_buffer, sarray(), varray()); + + /* Vector2 */ + + bind_method(Vector2, angle, sarray(), varray()); + bind_method(Vector2, angle_to, sarray("to"), varray()); + bind_method(Vector2, angle_to_point, sarray("to"), varray()); + bind_method(Vector2, direction_to, sarray("b"), varray()); + bind_method(Vector2, distance_to, sarray("to"), varray()); + bind_method(Vector2, distance_squared_to, sarray("to"), varray()); + bind_method(Vector2, length, sarray(), varray()); + bind_method(Vector2, length_squared, sarray(), varray()); + bind_method(Vector2, normalized, sarray(), varray()); + bind_method(Vector2, is_normalized, sarray(), varray()); + bind_method(Vector2, is_equal_approx, sarray("to"), varray()); + bind_method(Vector2, posmod, sarray("mod"), varray()); + bind_method(Vector2, posmodv, sarray("modv"), varray()); + bind_method(Vector2, project, sarray("b"), varray()); + bind_method(Vector2, lerp, sarray("with", "t"), varray()); + bind_method(Vector2, slerp, sarray("with", "t"), varray()); + bind_method(Vector2, cubic_interpolate, sarray("b", "pre_a", "post_b", "t"), varray()); + bind_method(Vector2, move_toward, sarray("to", "delta"), varray()); + bind_method(Vector2, rotated, sarray("phi"), varray()); + bind_method(Vector2, tangent, sarray(), varray()); + bind_method(Vector2, floor, sarray(), varray()); + bind_method(Vector2, ceil, sarray(), varray()); + bind_method(Vector2, round, sarray(), varray()); + bind_method(Vector2, aspect, sarray(), varray()); + bind_method(Vector2, dot, sarray("with"), varray()); + bind_method(Vector2, slide, sarray("n"), varray()); + bind_method(Vector2, bounce, sarray("n"), varray()); + bind_method(Vector2, reflect, sarray("n"), varray()); + bind_method(Vector2, cross, sarray("with"), varray()); + bind_method(Vector2, abs, sarray(), varray()); + bind_method(Vector2, sign, sarray(), varray()); + bind_method(Vector2, snapped, sarray("by"), varray()); + bind_method(Vector2, clamped, sarray("length"), varray()); + + /* Vector2i */ + + bind_method(Vector2i, aspect, sarray(), varray()); + bind_method(Vector2i, sign, sarray(), varray()); + bind_method(Vector2i, abs, sarray(), varray()); + + /* Rect2 */ + + bind_method(Rect2, get_area, sarray(), varray()); + bind_method(Rect2, has_no_area, sarray(), varray()); + bind_method(Rect2, has_point, sarray("point"), varray()); + bind_method(Rect2, is_equal_approx, sarray("rect"), varray()); + bind_method(Rect2, intersects, sarray("b", "include_borders"), varray(false)); + bind_method(Rect2, encloses, sarray("b"), varray()); + bind_method(Rect2, clip, sarray("b"), varray()); + bind_method(Rect2, merge, sarray("b"), varray()); + bind_method(Rect2, expand, sarray("to"), varray()); + bind_method(Rect2, grow, sarray("by"), varray()); + bind_methodv(grow_margin, &Rect2::grow_margin_bind, sarray("margin", "by"), varray()); + bind_method(Rect2, grow_individual, sarray("left", "top", "right", "bottom"), varray()); + bind_method(Rect2, abs, sarray(), varray()); + + /* Rect2i */ + + bind_method(Rect2i, get_area, sarray(), varray()); + bind_method(Rect2i, has_no_area, sarray(), varray()); + bind_method(Rect2i, has_point, sarray("point"), varray()); + bind_method(Rect2i, intersects, sarray("b"), varray()); + bind_method(Rect2i, encloses, sarray("b"), varray()); + bind_method(Rect2i, clip, sarray("b"), varray()); + bind_method(Rect2i, merge, sarray("b"), varray()); + bind_method(Rect2i, expand, sarray("to"), varray()); + bind_method(Rect2i, grow, sarray("by"), varray()); + bind_methodv(grow_margin, &Rect2i::grow_margin_bind, sarray("margin", "by"), varray()); + bind_method(Rect2i, grow_individual, sarray("left", "top", "right", "bottom"), varray()); + bind_method(Rect2i, abs, sarray(), varray()); + + /* Vector3 */ + + bind_method(Vector3, min_axis, sarray(), varray()); + bind_method(Vector3, max_axis, sarray(), varray()); + bind_method(Vector3, angle_to, sarray("to"), varray()); + bind_method(Vector3, direction_to, sarray("b"), varray()); + bind_method(Vector3, distance_to, sarray("b"), varray()); + bind_method(Vector3, distance_squared_to, sarray("b"), varray()); + bind_method(Vector3, length, sarray(), varray()); + bind_method(Vector3, length_squared, sarray(), varray()); + bind_method(Vector3, normalized, sarray(), varray()); + bind_method(Vector3, is_normalized, sarray(), varray()); + bind_method(Vector3, is_equal_approx, sarray("to"), varray()); + bind_method(Vector3, inverse, sarray(), varray()); + bind_method(Vector3, snapped, sarray("by"), varray()); + bind_method(Vector3, rotated, sarray("by_axis", "phi"), varray()); + bind_method(Vector3, lerp, sarray("b", "t"), varray()); + bind_method(Vector3, slerp, sarray("b", "t"), varray()); + bind_method(Vector3, cubic_interpolate, sarray("b", "pre_a", "post_b", "t"), varray()); + bind_method(Vector3, move_toward, sarray("to", "delta"), varray()); + bind_method(Vector3, dot, sarray("with"), varray()); + bind_method(Vector3, cross, sarray("with"), varray()); + bind_method(Vector3, outer, sarray("with"), varray()); + bind_method(Vector3, to_diagonal_matrix, sarray(), varray()); + bind_method(Vector3, abs, sarray(), varray()); + bind_method(Vector3, floor, sarray(), varray()); + bind_method(Vector3, ceil, sarray(), varray()); + bind_method(Vector3, round, sarray(), varray()); + bind_method(Vector3, posmod, sarray("mod"), varray()); + bind_method(Vector3, posmodv, sarray("modv"), varray()); + bind_method(Vector3, project, sarray("b"), varray()); + bind_method(Vector3, slide, sarray("n"), varray()); + bind_method(Vector3, bounce, sarray("n"), varray()); + bind_method(Vector3, reflect, sarray("n"), varray()); + bind_method(Vector3, sign, sarray(), varray()); + + /* Vector3i */ + + bind_method(Vector3i, min_axis, sarray(), varray()); + bind_method(Vector3i, max_axis, sarray(), varray()); + bind_method(Vector3i, sign, sarray(), varray()); + bind_method(Vector3i, abs, sarray(), varray()); + + /* Plane */ + + bind_method(Plane, normalized, sarray(), varray()); + bind_method(Plane, center, sarray(), varray()); + bind_method(Plane, is_equal_approx, sarray("to_plane"), varray()); + bind_method(Plane, is_point_over, sarray("plane"), varray()); + bind_method(Plane, distance_to, sarray("point"), varray()); + bind_method(Plane, has_point, sarray("point", "epsilon"), varray(CMP_EPSILON)); + bind_method(Plane, project, sarray("point"), varray()); + bind_methodv(intersect_3, &Plane::intersect_3_bind, sarray("b", "c"), varray()); + bind_methodv(intersects_ray, &Plane::intersects_ray_bind, sarray("from", "dir"), varray()); + bind_methodv(intersects_segment, &Plane::intersects_segment_bind, sarray("from", "to"), varray()); + + /* Quat */ + + bind_method(Quat, length, sarray(), varray()); + bind_method(Quat, length_squared, sarray(), varray()); + bind_method(Quat, normalized, sarray(), varray()); + bind_method(Quat, is_normalized, sarray(), varray()); + bind_method(Quat, is_equal_approx, sarray("to"), varray()); + bind_method(Quat, inverse, sarray(), varray()); + bind_method(Quat, dot, sarray("with"), varray()); + bind_method(Quat, slerp, sarray("b", "t"), varray()); + bind_method(Quat, slerpni, sarray("b", "t"), varray()); + bind_method(Quat, cubic_slerp, sarray("b", "pre_a", "post_b", "t"), varray()); + bind_method(Quat, get_euler, sarray(), varray()); + + // FIXME: Quat is atomic, this should be done via construcror + //ADDFUNC1(QUAT, NIL, Quat, set_euler, VECTOR3, "euler", varray()); + //ADDFUNC2(QUAT, NIL, Quat, set_axis_angle, VECTOR3, "axis", FLOAT, "angle", varray()); + + /* Color */ + + bind_method(Color, to_argb32, sarray(), varray()); + bind_method(Color, to_abgr32, sarray(), varray()); + bind_method(Color, to_rgba32, sarray(), varray()); + bind_method(Color, to_argb64, sarray(), varray()); + bind_method(Color, to_abgr64, sarray(), varray()); + bind_method(Color, to_rgba64, sarray(), varray()); + + bind_method(Color, inverted, sarray(), varray()); + bind_method(Color, contrasted, sarray(), varray()); + bind_method(Color, lerp, sarray("b", "t"), varray()); + bind_method(Color, lightened, sarray("amount"), varray()); + bind_method(Color, darkened, sarray("amount"), varray()); + bind_method(Color, to_html, sarray("with_alpha"), varray(true)); + bind_method(Color, blend, sarray("over"), varray()); + + // FIXME: Color is immutable, need to probably find a way to do this via constructor + //ADDFUNC4R(COLOR, COLOR, Color, from_hsv, FLOAT, "h", FLOAT, "s", FLOAT, "v", FLOAT, "a", varray(1.0)); + bind_method(Color, is_equal_approx, sarray("to"), varray()); + + /* RID */ + + bind_method(RID, get_id, sarray(), varray()); + + /* NodePath */ + + bind_method(NodePath, is_absolute, sarray(), varray()); + bind_method(NodePath, get_name_count, sarray(), varray()); + bind_method(NodePath, get_name, sarray("idx"), varray()); + bind_method(NodePath, get_subname_count, sarray(), varray()); + bind_method(NodePath, get_subname, sarray("idx"), varray()); + bind_method(NodePath, get_concatenated_subnames, sarray(), varray()); + bind_method(NodePath, get_as_property_path, sarray(), varray()); + bind_method(NodePath, is_empty, sarray(), varray()); + + /* Callable */ + + bind_method(Callable, is_null, sarray(), varray()); + bind_method(Callable, is_custom, sarray(), varray()); + bind_method(Callable, is_standard, sarray(), varray()); + bind_method(Callable, get_object, sarray(), varray()); + bind_method(Callable, get_object_id, sarray(), varray()); + bind_method(Callable, get_method, sarray(), varray()); + bind_method(Callable, hash, sarray(), varray()); + bind_method(Callable, unbind, sarray("argcount"), varray()); + + bind_custom(Variant::CALLABLE, "call", _VariantCall::func_Callable_call, Variant::InternalMethod::FLAG_VARARGS | Variant::InternalMethod::FLAG_RETURNS_VARIANT, Vector<Variant::Type>(), Variant::NIL, sarray()); + bind_custom(Variant::CALLABLE, "call_deferred", _VariantCall::func_Callable_call_deferred, Variant::InternalMethod::FLAG_VARARGS, Vector<Variant::Type>(), Variant::NIL, sarray()); + bind_custom(Variant::CALLABLE, "bind", _VariantCall::func_Callable_bind, Variant::InternalMethod::FLAG_VARARGS, Vector<Variant::Type>(), Variant::CALLABLE, sarray()); + + /* Signal */ + + bind_method(Signal, is_null, sarray(), varray()); + bind_method(Signal, get_object, sarray(), varray()); + bind_method(Signal, get_object_id, sarray(), varray()); + bind_method(Signal, get_name, sarray(), varray()); + + bind_method(Signal, connect, sarray("callable", "binds", "flags"), varray(Array(), 0)); + bind_method(Signal, disconnect, sarray("callable"), varray()); + bind_method(Signal, is_connected, sarray("callable"), varray()); + bind_method(Signal, get_connections, sarray(), varray()); + + bind_custom(Variant::SIGNAL, "emit", _VariantCall::func_Signal_emit, Variant::InternalMethod::FLAG_VARARGS, Vector<Variant::Type>(), Variant::NIL, sarray()); + + /* Transform2D */ + + bind_method(Transform2D, inverse, sarray(), varray()); + bind_method(Transform2D, affine_inverse, sarray(), varray()); + bind_method(Transform2D, get_rotation, sarray(), varray()); + bind_method(Transform2D, get_origin, sarray(), varray()); + bind_method(Transform2D, get_scale, sarray(), varray()); + bind_method(Transform2D, orthonormalized, sarray(), varray()); + bind_method(Transform2D, rotated, sarray("phi"), varray()); + bind_method(Transform2D, scaled, sarray("scale"), varray()); + bind_method(Transform2D, translated, sarray("offset"), varray()); + bind_method(Transform2D, basis_xform, sarray("v"), varray()); + bind_method(Transform2D, basis_xform_inv, sarray("v"), varray()); + bind_method(Transform2D, interpolate_with, sarray("xform", "t"), varray()); + bind_method(Transform2D, is_equal_approx, sarray("xform"), varray()); + + /* Basis */ + + bind_method(Basis, inverse, sarray(), varray()); + bind_method(Basis, transposed, sarray(), varray()); + bind_method(Basis, orthonormalized, sarray(), varray()); + bind_method(Basis, determinant, sarray(), varray()); + bind_methodv(rotated, static_cast<Basis (Basis::*)(const Vector3 &, float) const>(&Basis::rotated), sarray("axis", "phi"), varray()); + bind_method(Basis, scaled, sarray("scale"), varray()); + bind_method(Basis, get_scale, sarray(), varray()); + bind_method(Basis, get_euler, sarray(), varray()); + bind_method(Basis, tdotx, sarray("with"), varray()); + bind_method(Basis, tdoty, sarray("with"), varray()); + bind_method(Basis, tdotz, sarray("with"), varray()); + bind_method(Basis, get_orthogonal_index, sarray(), varray()); + bind_method(Basis, slerp, sarray("b", "t"), varray()); + bind_method(Basis, is_equal_approx, sarray("b"), varray()); + bind_method(Basis, get_rotation_quat, sarray(), varray()); + + /* AABB */ + + bind_method(::AABB, abs, sarray(), varray()); + bind_method(::AABB, get_area, sarray(), varray()); + bind_method(::AABB, has_no_area, sarray(), varray()); + bind_method(::AABB, has_no_surface, sarray(), varray()); + bind_method(::AABB, has_point, sarray("point"), varray()); + bind_method(::AABB, is_equal_approx, sarray("aabb"), varray()); + bind_method(::AABB, intersects, sarray("with"), varray()); + bind_method(::AABB, encloses, sarray("with"), varray()); + bind_method(::AABB, intersects_plane, sarray("plane"), varray()); + bind_method(::AABB, intersection, sarray("with"), varray()); + bind_method(::AABB, merge, sarray("with"), varray()); + bind_method(::AABB, expand, sarray("to_point"), varray()); + bind_method(::AABB, grow, sarray("by"), varray()); + bind_method(::AABB, get_support, sarray("dir"), varray()); + bind_method(::AABB, get_longest_axis, sarray(), varray()); + bind_method(::AABB, get_longest_axis_index, sarray(), varray()); + bind_method(::AABB, get_longest_axis_size, sarray(), varray()); + bind_method(::AABB, get_shortest_axis, sarray(), varray()); + bind_method(::AABB, get_shortest_axis_index, sarray(), varray()); + bind_method(::AABB, get_shortest_axis_size, sarray(), varray()); + bind_method(::AABB, get_endpoint, sarray("idx"), varray()); + bind_methodv(intersects_segment, &AABB::intersects_segment_bind, sarray("from", "to"), varray()); + bind_methodv(intersects_ray, &AABB::intersects_ray_bind, sarray("from", "dir"), varray()); + + /* Transform */ + + bind_method(Transform, inverse, sarray(), varray()); + bind_method(Transform, affine_inverse, sarray(), varray()); + bind_method(Transform, orthonormalized, sarray(), varray()); + bind_method(Transform, rotated, sarray("axis", "phi"), varray()); + bind_method(Transform, scaled, sarray("scale"), varray()); + bind_method(Transform, translated, sarray("offset"), varray()); + bind_method(Transform, looking_at, sarray("target", "up"), varray()); + bind_method(Transform, interpolate_with, sarray("xform", "weight"), varray()); + bind_method(Transform, is_equal_approx, sarray("xform"), varray()); + + /* Dictionary */ + + bind_method(Dictionary, size, sarray(), varray()); + bind_method(Dictionary, empty, sarray(), varray()); + bind_method(Dictionary, clear, sarray(), varray()); + bind_method(Dictionary, has, sarray("key"), varray()); + bind_method(Dictionary, has_all, sarray("keys"), varray()); + bind_method(Dictionary, erase, sarray("key"), varray()); + bind_method(Dictionary, hash, sarray(), varray()); + bind_method(Dictionary, keys, sarray(), varray()); + bind_method(Dictionary, values, sarray(), varray()); + bind_method(Dictionary, duplicate, sarray("deep"), varray(false)); + bind_method(Dictionary, get, sarray("key", "default"), varray(Variant())); + + /* Array */ + + bind_method(Array, size, sarray(), varray()); + bind_method(Array, empty, sarray(), varray()); + bind_method(Array, clear, sarray(), varray()); + bind_method(Array, hash, sarray(), varray()); + bind_method(Array, push_back, sarray("value"), varray()); + bind_method(Array, push_front, sarray("value"), varray()); + bind_method(Array, append, sarray("value"), varray()); + bind_method(Array, resize, sarray("size"), varray()); + bind_method(Array, insert, sarray("position", "value"), varray()); + bind_method(Array, remove, sarray("position"), varray()); + bind_method(Array, erase, sarray("value"), varray()); + bind_method(Array, front, sarray(), varray()); + bind_method(Array, back, sarray(), varray()); + bind_method(Array, find, sarray("what", "from"), varray(0)); + bind_method(Array, rfind, sarray("what", "from"), varray(-1)); + bind_method(Array, find_last, sarray("value"), varray()); + bind_method(Array, count, sarray("value"), varray()); + bind_method(Array, has, sarray("value"), varray()); + bind_method(Array, pop_back, sarray(), varray()); + bind_method(Array, pop_front, sarray(), varray()); + bind_method(Array, sort, sarray(), varray()); + bind_method(Array, sort_custom, sarray("obj", "func"), varray()); + bind_method(Array, shuffle, sarray(), varray()); + bind_method(Array, bsearch, sarray("value", "before"), varray(true)); + bind_method(Array, bsearch_custom, sarray("value", "obj", "func", "before"), varray(true)); + bind_method(Array, invert, sarray(), varray()); + bind_method(Array, duplicate, sarray("deep"), varray(false)); + bind_method(Array, slice, sarray("begin", "end", "step", "deep"), varray(1, false)); + bind_method(Array, max, sarray(), varray()); + bind_method(Array, min, sarray(), varray()); + + /* Byte Array */ + bind_method(PackedByteArray, size, sarray(), varray()); + bind_method(PackedByteArray, empty, sarray(), varray()); + bind_method(PackedByteArray, set, sarray("index", "value"), varray()); + bind_method(PackedByteArray, push_back, sarray("value"), varray()); + bind_method(PackedByteArray, append, sarray("value"), varray()); + bind_method(PackedByteArray, append_array, sarray("array"), varray()); + bind_method(PackedByteArray, remove, sarray("index"), varray()); + bind_method(PackedByteArray, insert, sarray("at_index", "value"), varray()); + bind_method(PackedByteArray, resize, sarray("new_size"), varray()); + bind_method(PackedByteArray, has, sarray("value"), varray()); + bind_method(PackedByteArray, invert, sarray(), varray()); + bind_method(PackedByteArray, subarray, sarray("from", "to"), varray()); + bind_method(PackedByteArray, sort, sarray(), varray()); + + bind_function("get_string_from_ascii", _VariantCall::func_PackedByteArray_get_string_from_ascii, sarray(), varray()); + bind_function("get_string_from_utf8", _VariantCall::func_PackedByteArray_get_string_from_utf8, sarray(), varray()); + bind_function("get_string_from_utf16", _VariantCall::func_PackedByteArray_get_string_from_utf16, sarray(), varray()); + bind_function("get_string_from_utf32", _VariantCall::func_PackedByteArray_get_string_from_utf32, sarray(), varray()); + bind_function("hex_encode", _VariantCall::func_PackedByteArray_hex_encode, sarray(), varray()); + bind_function("compress", _VariantCall::func_PackedByteArray_compress, sarray("compression_mode"), varray(0)); + bind_function("decompress", _VariantCall::func_PackedByteArray_decompress, sarray("buffer_size", "compression_mode"), varray(0)); + bind_function("decompress_dynamic", _VariantCall::func_PackedByteArray_decompress_dynamic, sarray("max_output_size", "compression_mode"), varray(0)); + + /* Int32 Array */ + + bind_method(PackedInt32Array, size, sarray(), varray()); + bind_method(PackedInt32Array, empty, sarray(), varray()); + bind_method(PackedInt32Array, set, sarray("index", "value"), varray()); + bind_method(PackedInt32Array, push_back, sarray("value"), varray()); + bind_method(PackedInt32Array, append, sarray("value"), varray()); + bind_method(PackedInt32Array, append_array, sarray("array"), varray()); + bind_method(PackedInt32Array, remove, sarray("index"), varray()); + bind_method(PackedInt32Array, insert, sarray("at_index", "value"), varray()); + bind_method(PackedInt32Array, resize, sarray("new_size"), varray()); + bind_method(PackedInt32Array, has, sarray("value"), varray()); + bind_method(PackedInt32Array, invert, sarray(), varray()); + bind_method(PackedInt32Array, subarray, sarray("from", "to"), varray()); + bind_method(PackedInt32Array, to_byte_array, sarray(), varray()); + bind_method(PackedInt32Array, sort, sarray(), varray()); + + /* Int64 Array */ + + bind_method(PackedInt64Array, size, sarray(), varray()); + bind_method(PackedInt64Array, empty, sarray(), varray()); + bind_method(PackedInt64Array, set, sarray("index", "value"), varray()); + bind_method(PackedInt64Array, push_back, sarray("value"), varray()); + bind_method(PackedInt64Array, append, sarray("value"), varray()); + bind_method(PackedInt64Array, append_array, sarray("array"), varray()); + bind_method(PackedInt64Array, remove, sarray("index"), varray()); + bind_method(PackedInt64Array, insert, sarray("at_index", "value"), varray()); + bind_method(PackedInt64Array, resize, sarray("new_size"), varray()); + bind_method(PackedInt64Array, has, sarray("value"), varray()); + bind_method(PackedInt64Array, invert, sarray(), varray()); + bind_method(PackedInt64Array, subarray, sarray("from", "to"), varray()); + bind_method(PackedInt64Array, to_byte_array, sarray(), varray()); + bind_method(PackedInt64Array, sort, sarray(), varray()); + + /* Float32 Array */ + + bind_method(PackedFloat32Array, size, sarray(), varray()); + bind_method(PackedFloat32Array, empty, sarray(), varray()); + bind_method(PackedFloat32Array, set, sarray("index", "value"), varray()); + bind_method(PackedFloat32Array, push_back, sarray("value"), varray()); + bind_method(PackedFloat32Array, append, sarray("value"), varray()); + bind_method(PackedFloat32Array, append_array, sarray("array"), varray()); + bind_method(PackedFloat32Array, remove, sarray("index"), varray()); + bind_method(PackedFloat32Array, insert, sarray("at_index", "value"), varray()); + bind_method(PackedFloat32Array, resize, sarray("new_size"), varray()); + bind_method(PackedFloat32Array, has, sarray("value"), varray()); + bind_method(PackedFloat32Array, invert, sarray(), varray()); + bind_method(PackedFloat32Array, subarray, sarray("from", "to"), varray()); + bind_method(PackedFloat32Array, to_byte_array, sarray(), varray()); + bind_method(PackedFloat32Array, sort, sarray(), varray()); + + /* Float64 Array */ + + bind_method(PackedFloat64Array, size, sarray(), varray()); + bind_method(PackedFloat64Array, empty, sarray(), varray()); + bind_method(PackedFloat64Array, set, sarray("index", "value"), varray()); + bind_method(PackedFloat64Array, push_back, sarray("value"), varray()); + bind_method(PackedFloat64Array, append, sarray("value"), varray()); + bind_method(PackedFloat64Array, append_array, sarray("array"), varray()); + bind_method(PackedFloat64Array, remove, sarray("index"), varray()); + bind_method(PackedFloat64Array, insert, sarray("at_index", "value"), varray()); + bind_method(PackedFloat64Array, resize, sarray("new_size"), varray()); + bind_method(PackedFloat64Array, has, sarray("value"), varray()); + bind_method(PackedFloat64Array, invert, sarray(), varray()); + bind_method(PackedFloat64Array, subarray, sarray("from", "to"), varray()); + bind_method(PackedFloat64Array, to_byte_array, sarray(), varray()); + bind_method(PackedFloat64Array, sort, sarray(), varray()); + + /* String Array */ + + bind_method(PackedStringArray, size, sarray(), varray()); + bind_method(PackedStringArray, empty, sarray(), varray()); + bind_method(PackedStringArray, set, sarray("index", "value"), varray()); + bind_method(PackedStringArray, push_back, sarray("value"), varray()); + bind_method(PackedStringArray, append, sarray("value"), varray()); + bind_method(PackedStringArray, append_array, sarray("array"), varray()); + bind_method(PackedStringArray, remove, sarray("index"), varray()); + bind_method(PackedStringArray, insert, sarray("at_index", "value"), varray()); + bind_method(PackedStringArray, resize, sarray("new_size"), varray()); + bind_method(PackedStringArray, has, sarray("value"), varray()); + bind_method(PackedStringArray, invert, sarray(), varray()); + bind_method(PackedStringArray, subarray, sarray("from", "to"), varray()); + bind_method(PackedStringArray, to_byte_array, sarray(), varray()); + bind_method(PackedStringArray, sort, sarray(), varray()); + + /* Vector2 Array */ + + bind_method(PackedVector2Array, size, sarray(), varray()); + bind_method(PackedVector2Array, empty, sarray(), varray()); + bind_method(PackedVector2Array, set, sarray("index", "value"), varray()); + bind_method(PackedVector2Array, push_back, sarray("value"), varray()); + bind_method(PackedVector2Array, append, sarray("value"), varray()); + bind_method(PackedVector2Array, append_array, sarray("array"), varray()); + bind_method(PackedVector2Array, remove, sarray("index"), varray()); + bind_method(PackedVector2Array, insert, sarray("at_index", "value"), varray()); + bind_method(PackedVector2Array, resize, sarray("new_size"), varray()); + bind_method(PackedVector2Array, has, sarray("value"), varray()); + bind_method(PackedVector2Array, invert, sarray(), varray()); + bind_method(PackedVector2Array, subarray, sarray("from", "to"), varray()); + bind_method(PackedVector2Array, to_byte_array, sarray(), varray()); + bind_method(PackedVector2Array, sort, sarray(), varray()); + + /* Vector3 Array */ + + bind_method(PackedVector3Array, size, sarray(), varray()); + bind_method(PackedVector3Array, empty, sarray(), varray()); + bind_method(PackedVector3Array, set, sarray("index", "value"), varray()); + bind_method(PackedVector3Array, push_back, sarray("value"), varray()); + bind_method(PackedVector3Array, append, sarray("value"), varray()); + bind_method(PackedVector3Array, append_array, sarray("array"), varray()); + bind_method(PackedVector3Array, remove, sarray("index"), varray()); + bind_method(PackedVector3Array, insert, sarray("at_index", "value"), varray()); + bind_method(PackedVector3Array, resize, sarray("new_size"), varray()); + bind_method(PackedVector3Array, has, sarray("value"), varray()); + bind_method(PackedVector3Array, invert, sarray(), varray()); + bind_method(PackedVector3Array, subarray, sarray("from", "to"), varray()); + bind_method(PackedVector3Array, to_byte_array, sarray(), varray()); + bind_method(PackedVector3Array, sort, sarray(), varray()); + + /* Color Array */ + + bind_method(PackedColorArray, size, sarray(), varray()); + bind_method(PackedColorArray, empty, sarray(), varray()); + bind_method(PackedColorArray, set, sarray("index", "value"), varray()); + bind_method(PackedColorArray, push_back, sarray("value"), varray()); + bind_method(PackedColorArray, append, sarray("value"), varray()); + bind_method(PackedColorArray, append_array, sarray("array"), varray()); + bind_method(PackedColorArray, remove, sarray("index"), varray()); + bind_method(PackedColorArray, insert, sarray("at_index", "value"), varray()); + bind_method(PackedColorArray, resize, sarray("new_size"), varray()); + bind_method(PackedColorArray, has, sarray("value"), varray()); + bind_method(PackedColorArray, invert, sarray(), varray()); + bind_method(PackedColorArray, subarray, sarray("from", "to"), varray()); + bind_method(PackedColorArray, to_byte_array, sarray(), varray()); + bind_method(PackedColorArray, sort, sarray(), varray()); + + /* Register constructors */ _VariantCall::add_constructor(_VariantCall::Vector2_init1, Variant::VECTOR2, "x", Variant::FLOAT, "y", Variant::FLOAT); _VariantCall::add_constructor(_VariantCall::Vector2i_init1, Variant::VECTOR2I, "x", Variant::INT, "y", Variant::INT); @@ -2379,7 +1956,7 @@ void register_variant_methods() { _VariantCall::add_constructor(_VariantCall::Rect2_init1, Variant::RECT2, "position", Variant::VECTOR2, "size", Variant::VECTOR2); _VariantCall::add_constructor(_VariantCall::Rect2_init2, Variant::RECT2, "x", Variant::FLOAT, "y", Variant::FLOAT, "width", Variant::FLOAT, "height", Variant::FLOAT); - _VariantCall::add_constructor(_VariantCall::Rect2i_init1, Variant::RECT2I, "position", Variant::VECTOR2, "size", Variant::VECTOR2); + _VariantCall::add_constructor(_VariantCall::Rect2i_init1, Variant::RECT2I, "position", Variant::VECTOR2I, "size", Variant::VECTOR2I); _VariantCall::add_constructor(_VariantCall::Rect2i_init2, Variant::RECT2I, "x", Variant::INT, "y", Variant::INT, "width", Variant::INT, "height", Variant::INT); _VariantCall::add_constructor(_VariantCall::Transform2D_init2, Variant::TRANSFORM2D, "rotation", Variant::FLOAT, "position", Variant::VECTOR2); @@ -2412,7 +1989,7 @@ void register_variant_methods() { _VariantCall::add_constructor(_VariantCall::Callable_init2, Variant::CALLABLE, "object", Variant::OBJECT, "method_name", Variant::STRING_NAME); _VariantCall::add_constructor(_VariantCall::Signal_init2, Variant::SIGNAL, "object", Variant::OBJECT, "signal_name", Variant::STRING_NAME); - /* REGISTER CONSTANTS */ + /* Register constants */ _populate_named_colors(); for (Map<String, Color>::Element *color = _named_colors.front(); color; color = color->next()) { @@ -2497,7 +2074,18 @@ void register_variant_methods() { } void unregister_variant_methods() { - memdelete_arr(_VariantCall::type_funcs); + //clear methods + for (int i = 0; i < Variant::VARIANT_MAX; i++) { + for (List<StringName>::Element *E = _VariantCall::type_internal_method_names[i].front(); E; E = E->next()) { + Variant::InternalMethod **m = _VariantCall::type_internal_methods[i].lookup_ptr(E->get()); + if (*m) { + memdelete(*m); + } + } + } + + memdelete_arr(_VariantCall::type_internal_methods); + memdelete_arr(_VariantCall::type_internal_method_names); memdelete_arr(_VariantCall::construct_funcs); memdelete_arr(_VariantCall::constant_data); } diff --git a/core/variant_internal.h b/core/variant_internal.h index 0e0a1e398f..7893c6d382 100644 --- a/core/variant_internal.h +++ b/core/variant_internal.h @@ -113,6 +113,540 @@ public: _FORCE_INLINE_ static const PackedVector3Array *get_vector3_array(const Variant *v) { return &static_cast<const Variant::PackedArrayRef<Vector3> *>(v->_data.packed_array)->array; } _FORCE_INLINE_ static PackedColorArray *get_color_array(Variant *v) { return &static_cast<Variant::PackedArrayRef<Color> *>(v->_data.packed_array)->array; } _FORCE_INLINE_ static const PackedColorArray *get_color_array(const Variant *v) { return &static_cast<const Variant::PackedArrayRef<Color> *>(v->_data.packed_array)->array; } + + _FORCE_INLINE_ static Object **get_object(Variant *v) { return (Object **)&v->_get_obj().obj; } + _FORCE_INLINE_ static const Object **get_object(const Variant *v) { return (const Object **)&v->_get_obj().obj; } +}; + +template <class T> +struct VariantGetInternalPtr { +}; + +template <> +struct VariantGetInternalPtr<bool> { + static bool *get_ptr(Variant *v) { return VariantInternal::get_bool(v); } + static const bool *get_ptr(const Variant *v) { return VariantInternal::get_bool(v); } +}; + +template <> +struct VariantGetInternalPtr<int8_t> { + static int64_t *get_ptr(Variant *v) { return VariantInternal::get_int(v); } + static const int64_t *get_ptr(const Variant *v) { return VariantInternal::get_int(v); } +}; + +template <> +struct VariantGetInternalPtr<uint8_t> { + static int64_t *get_ptr(Variant *v) { return VariantInternal::get_int(v); } + static const int64_t *get_ptr(const Variant *v) { return VariantInternal::get_int(v); } +}; + +template <> +struct VariantGetInternalPtr<int16_t> { + static int64_t *get_ptr(Variant *v) { return VariantInternal::get_int(v); } + static const int64_t *get_ptr(const Variant *v) { return VariantInternal::get_int(v); } +}; + +template <> +struct VariantGetInternalPtr<uint16_t> { + static int64_t *get_ptr(Variant *v) { return VariantInternal::get_int(v); } + static const int64_t *get_ptr(const Variant *v) { return VariantInternal::get_int(v); } +}; + +template <> +struct VariantGetInternalPtr<int32_t> { + static int64_t *get_ptr(Variant *v) { return VariantInternal::get_int(v); } + static const int64_t *get_ptr(const Variant *v) { return VariantInternal::get_int(v); } +}; + +template <> +struct VariantGetInternalPtr<uint32_t> { + static int64_t *get_ptr(Variant *v) { return VariantInternal::get_int(v); } + static const int64_t *get_ptr(const Variant *v) { return VariantInternal::get_int(v); } +}; + +template <> +struct VariantGetInternalPtr<int64_t> { + static int64_t *get_ptr(Variant *v) { return VariantInternal::get_int(v); } + static const int64_t *get_ptr(const Variant *v) { return VariantInternal::get_int(v); } +}; + +template <> +struct VariantGetInternalPtr<uint64_t> { + static int64_t *get_ptr(Variant *v) { return VariantInternal::get_int(v); } + static const int64_t *get_ptr(const Variant *v) { return VariantInternal::get_int(v); } +}; + +template <> +struct VariantGetInternalPtr<char32_t> { + static int64_t *get_ptr(Variant *v) { return VariantInternal::get_int(v); } + static const int64_t *get_ptr(const Variant *v) { return VariantInternal::get_int(v); } +}; + +template <> +struct VariantGetInternalPtr<ObjectID> { + static int64_t *get_ptr(Variant *v) { return VariantInternal::get_int(v); } + static const int64_t *get_ptr(const Variant *v) { return VariantInternal::get_int(v); } +}; + +template <> +struct VariantGetInternalPtr<Error> { + static int64_t *get_ptr(Variant *v) { return VariantInternal::get_int(v); } + static const int64_t *get_ptr(const Variant *v) { return VariantInternal::get_int(v); } +}; + +template <> +struct VariantGetInternalPtr<float> { + static double *get_ptr(Variant *v) { return VariantInternal::get_float(v); } + static const double *get_ptr(const Variant *v) { return VariantInternal::get_float(v); } +}; + +template <> +struct VariantGetInternalPtr<double> { + static double *get_ptr(Variant *v) { return VariantInternal::get_float(v); } + static const double *get_ptr(const Variant *v) { return VariantInternal::get_float(v); } +}; + +template <> +struct VariantGetInternalPtr<String> { + static String *get_ptr(Variant *v) { return VariantInternal::get_string(v); } + static const String *get_ptr(const Variant *v) { return VariantInternal::get_string(v); } +}; + +template <> +struct VariantGetInternalPtr<Vector2> { + static Vector2 *get_ptr(Variant *v) { return VariantInternal::get_vector2(v); } + static const Vector2 *get_ptr(const Variant *v) { return VariantInternal::get_vector2(v); } +}; + +template <> +struct VariantGetInternalPtr<Vector2i> { + static Vector2i *get_ptr(Variant *v) { return VariantInternal::get_vector2i(v); } + static const Vector2i *get_ptr(const Variant *v) { return VariantInternal::get_vector2i(v); } +}; + +template <> +struct VariantGetInternalPtr<Rect2> { + static Rect2 *get_ptr(Variant *v) { return VariantInternal::get_rect2(v); } + static const Rect2 *get_ptr(const Variant *v) { return VariantInternal::get_rect2(v); } +}; + +template <> +struct VariantGetInternalPtr<Rect2i> { + static Rect2i *get_ptr(Variant *v) { return VariantInternal::get_rect2i(v); } + static const Rect2i *get_ptr(const Variant *v) { return VariantInternal::get_rect2i(v); } +}; + +template <> +struct VariantGetInternalPtr<Vector3> { + static Vector3 *get_ptr(Variant *v) { return VariantInternal::get_vector3(v); } + static const Vector3 *get_ptr(const Variant *v) { return VariantInternal::get_vector3(v); } +}; + +template <> +struct VariantGetInternalPtr<Vector3i> { + static Vector3i *get_ptr(Variant *v) { return VariantInternal::get_vector3i(v); } + static const Vector3i *get_ptr(const Variant *v) { return VariantInternal::get_vector3i(v); } +}; + +template <> +struct VariantGetInternalPtr<Transform2D> { + static Transform2D *get_ptr(Variant *v) { return VariantInternal::get_transform2d(v); } + static const Transform2D *get_ptr(const Variant *v) { return VariantInternal::get_transform2d(v); } +}; + +template <> +struct VariantGetInternalPtr<Transform> { + static Transform *get_ptr(Variant *v) { return VariantInternal::get_transform(v); } + static const Transform *get_ptr(const Variant *v) { return VariantInternal::get_transform(v); } +}; + +template <> +struct VariantGetInternalPtr<Plane> { + static Plane *get_ptr(Variant *v) { return VariantInternal::get_plane(v); } + static const Plane *get_ptr(const Variant *v) { return VariantInternal::get_plane(v); } +}; + +template <> +struct VariantGetInternalPtr<Quat> { + static Quat *get_ptr(Variant *v) { return VariantInternal::get_quat(v); } + static const Quat *get_ptr(const Variant *v) { return VariantInternal::get_quat(v); } +}; + +template <> +struct VariantGetInternalPtr<::AABB> { + static ::AABB *get_ptr(Variant *v) { return VariantInternal::get_aabb(v); } + static const ::AABB *get_ptr(const Variant *v) { return VariantInternal::get_aabb(v); } +}; + +template <> +struct VariantGetInternalPtr<Basis> { + static Basis *get_ptr(Variant *v) { return VariantInternal::get_basis(v); } + static const Basis *get_ptr(const Variant *v) { return VariantInternal::get_basis(v); } +}; + +// + +template <> +struct VariantGetInternalPtr<Color> { + static Color *get_ptr(Variant *v) { return VariantInternal::get_color(v); } + static const Color *get_ptr(const Variant *v) { return VariantInternal::get_color(v); } +}; + +template <> +struct VariantGetInternalPtr<StringName> { + static StringName *get_ptr(Variant *v) { return VariantInternal::get_string_name(v); } + static const StringName *get_ptr(const Variant *v) { return VariantInternal::get_string_name(v); } +}; + +template <> +struct VariantGetInternalPtr<NodePath> { + static NodePath *get_ptr(Variant *v) { return VariantInternal::get_node_path(v); } + static const NodePath *get_ptr(const Variant *v) { return VariantInternal::get_node_path(v); } +}; + +template <> +struct VariantGetInternalPtr<RID> { + static RID *get_ptr(Variant *v) { return VariantInternal::get_rid(v); } + static const RID *get_ptr(const Variant *v) { return VariantInternal::get_rid(v); } +}; + +template <> +struct VariantGetInternalPtr<Callable> { + static Callable *get_ptr(Variant *v) { return VariantInternal::get_callable(v); } + static const Callable *get_ptr(const Variant *v) { return VariantInternal::get_callable(v); } +}; + +template <> +struct VariantGetInternalPtr<Signal> { + static Signal *get_ptr(Variant *v) { return VariantInternal::get_signal(v); } + static const Signal *get_ptr(const Variant *v) { return VariantInternal::get_signal(v); } +}; + +template <> +struct VariantGetInternalPtr<Dictionary> { + static Dictionary *get_ptr(Variant *v) { return VariantInternal::get_dictionary(v); } + static const Dictionary *get_ptr(const Variant *v) { return VariantInternal::get_dictionary(v); } +}; + +template <> +struct VariantGetInternalPtr<Array> { + static Array *get_ptr(Variant *v) { return VariantInternal::get_array(v); } + static const Array *get_ptr(const Variant *v) { return VariantInternal::get_array(v); } +}; + +template <> +struct VariantGetInternalPtr<PackedByteArray> { + static PackedByteArray *get_ptr(Variant *v) { return VariantInternal::get_byte_array(v); } + static const PackedByteArray *get_ptr(const Variant *v) { return VariantInternal::get_byte_array(v); } +}; + +template <> +struct VariantGetInternalPtr<PackedInt32Array> { + static PackedInt32Array *get_ptr(Variant *v) { return VariantInternal::get_int32_array(v); } + static const PackedInt32Array *get_ptr(const Variant *v) { return VariantInternal::get_int32_array(v); } +}; + +template <> +struct VariantGetInternalPtr<PackedInt64Array> { + static PackedInt64Array *get_ptr(Variant *v) { return VariantInternal::get_int64_array(v); } + static const PackedInt64Array *get_ptr(const Variant *v) { return VariantInternal::get_int64_array(v); } +}; + +template <> +struct VariantGetInternalPtr<PackedFloat32Array> { + static PackedFloat32Array *get_ptr(Variant *v) { return VariantInternal::get_float32_array(v); } + static const PackedFloat32Array *get_ptr(const Variant *v) { return VariantInternal::get_float32_array(v); } +}; + +template <> +struct VariantGetInternalPtr<PackedFloat64Array> { + static PackedFloat64Array *get_ptr(Variant *v) { return VariantInternal::get_float64_array(v); } + static const PackedFloat64Array *get_ptr(const Variant *v) { return VariantInternal::get_float64_array(v); } +}; + +template <> +struct VariantGetInternalPtr<PackedStringArray> { + static PackedStringArray *get_ptr(Variant *v) { return VariantInternal::get_string_array(v); } + static const PackedStringArray *get_ptr(const Variant *v) { return VariantInternal::get_string_array(v); } +}; + +template <> +struct VariantGetInternalPtr<PackedVector2Array> { + static PackedVector2Array *get_ptr(Variant *v) { return VariantInternal::get_vector2_array(v); } + static const PackedVector2Array *get_ptr(const Variant *v) { return VariantInternal::get_vector2_array(v); } +}; + +template <> +struct VariantGetInternalPtr<PackedVector3Array> { + static PackedVector3Array *get_ptr(Variant *v) { return VariantInternal::get_vector3_array(v); } + static const PackedVector3Array *get_ptr(const Variant *v) { return VariantInternal::get_vector3_array(v); } +}; + +template <> +struct VariantGetInternalPtr<PackedColorArray> { + static PackedColorArray *get_ptr(Variant *v) { return VariantInternal::get_color_array(v); } + static const PackedColorArray *get_ptr(const Variant *v) { return VariantInternal::get_color_array(v); } +}; + +template <class T> +struct VariantInternalAccessor { +}; + +template <> +struct VariantInternalAccessor<bool> { + static _FORCE_INLINE_ bool get(const Variant *v) { return *VariantInternal::get_bool(v); } + static _FORCE_INLINE_ void set(Variant *v, bool p_value) { *VariantInternal::get_bool(v) = p_value; } +}; + +#define VARIANT_ACCESSOR_NUMBER(m_type) \ + template <> \ + struct VariantInternalAccessor<m_type> { \ + static _FORCE_INLINE_ m_type get(const Variant *v) { return (m_type)*VariantInternal::get_int(v); } \ + static _FORCE_INLINE_ void set(Variant *v, m_type p_value) { *VariantInternal::get_int(v) = p_value; } \ + }; + +VARIANT_ACCESSOR_NUMBER(int8_t) +VARIANT_ACCESSOR_NUMBER(uint8_t) +VARIANT_ACCESSOR_NUMBER(int16_t) +VARIANT_ACCESSOR_NUMBER(uint16_t) +VARIANT_ACCESSOR_NUMBER(int32_t) +VARIANT_ACCESSOR_NUMBER(uint32_t) +VARIANT_ACCESSOR_NUMBER(int64_t) +VARIANT_ACCESSOR_NUMBER(uint64_t) +VARIANT_ACCESSOR_NUMBER(char32_t) +VARIANT_ACCESSOR_NUMBER(Error) +VARIANT_ACCESSOR_NUMBER(Margin) + +template <> +struct VariantInternalAccessor<ObjectID> { + static _FORCE_INLINE_ ObjectID get(const Variant *v) { return ObjectID(*VariantInternal::get_int(v)); } + static _FORCE_INLINE_ void set(Variant *v, ObjectID p_value) { *VariantInternal::get_int(v) = p_value; } +}; + +template <> +struct VariantInternalAccessor<float> { + static _FORCE_INLINE_ float get(const Variant *v) { return *VariantInternal::get_float(v); } + static _FORCE_INLINE_ void set(Variant *v, float p_value) { *VariantInternal::get_float(v) = p_value; } +}; + +template <> +struct VariantInternalAccessor<double> { + static _FORCE_INLINE_ double get(const Variant *v) { return *VariantInternal::get_float(v); } + static _FORCE_INLINE_ void set(Variant *v, double p_value) { *VariantInternal::get_float(v) = p_value; } +}; + +template <> +struct VariantInternalAccessor<String> { + static _FORCE_INLINE_ const String &get(const Variant *v) { return *VariantInternal::get_string(v); } + static _FORCE_INLINE_ void set(Variant *v, const String &p_value) { *VariantInternal::get_string(v) = p_value; } +}; + +template <> +struct VariantInternalAccessor<Vector2> { + static _FORCE_INLINE_ const Vector2 &get(const Variant *v) { return *VariantInternal::get_vector2(v); } + static _FORCE_INLINE_ void set(Variant *v, const Vector2 &p_value) { *VariantInternal::get_vector2(v) = p_value; } +}; + +template <> +struct VariantInternalAccessor<Vector2i> { + static _FORCE_INLINE_ const Vector2i &get(const Variant *v) { return *VariantInternal::get_vector2i(v); } + static _FORCE_INLINE_ void set(Variant *v, const Vector2i &p_value) { *VariantInternal::get_vector2i(v) = p_value; } +}; + +template <> +struct VariantInternalAccessor<Rect2> { + static _FORCE_INLINE_ const Rect2 &get(const Variant *v) { return *VariantInternal::get_rect2(v); } + static _FORCE_INLINE_ void set(Variant *v, const Rect2 &p_value) { *VariantInternal::get_rect2(v) = p_value; } +}; + +template <> +struct VariantInternalAccessor<Rect2i> { + static _FORCE_INLINE_ const Rect2i &get(const Variant *v) { return *VariantInternal::get_rect2i(v); } + static _FORCE_INLINE_ void set(Variant *v, const Rect2i &p_value) { *VariantInternal::get_rect2i(v) = p_value; } +}; + +template <> +struct VariantInternalAccessor<Vector3> { + static _FORCE_INLINE_ const Vector3 &get(const Variant *v) { return *VariantInternal::get_vector3(v); } + static _FORCE_INLINE_ void set(Variant *v, const Vector3 &p_value) { *VariantInternal::get_vector3(v) = p_value; } +}; + +template <> +struct VariantInternalAccessor<Vector3i> { + static _FORCE_INLINE_ const Vector3i &get(const Variant *v) { return *VariantInternal::get_vector3i(v); } + static _FORCE_INLINE_ void set(Variant *v, const Vector3i &p_value) { *VariantInternal::get_vector3i(v) = p_value; } +}; + +template <> +struct VariantInternalAccessor<Transform2D> { + static _FORCE_INLINE_ const Transform2D &get(const Variant *v) { return *VariantInternal::get_transform2d(v); } + static _FORCE_INLINE_ void set(Variant *v, const Transform2D &p_value) { *VariantInternal::get_transform2d(v) = p_value; } +}; + +template <> +struct VariantInternalAccessor<Transform> { + static _FORCE_INLINE_ const Transform &get(const Variant *v) { return *VariantInternal::get_transform(v); } + static _FORCE_INLINE_ void set(Variant *v, const Transform &p_value) { *VariantInternal::get_transform(v) = p_value; } +}; + +template <> +struct VariantInternalAccessor<Plane> { + static _FORCE_INLINE_ const Plane &get(const Variant *v) { return *VariantInternal::get_plane(v); } + static _FORCE_INLINE_ void set(Variant *v, const Plane &p_value) { *VariantInternal::get_plane(v) = p_value; } +}; + +template <> +struct VariantInternalAccessor<Quat> { + static _FORCE_INLINE_ const Quat &get(const Variant *v) { return *VariantInternal::get_quat(v); } + static _FORCE_INLINE_ void set(Variant *v, const Quat &p_value) { *VariantInternal::get_quat(v) = p_value; } +}; + +template <> +struct VariantInternalAccessor<AABB> { + static _FORCE_INLINE_ const AABB &get(const Variant *v) { return *VariantInternal::get_aabb(v); } + static _FORCE_INLINE_ void set(Variant *v, const AABB &p_value) { *VariantInternal::get_aabb(v) = p_value; } +}; + +template <> +struct VariantInternalAccessor<Basis> { + static _FORCE_INLINE_ const Basis &get(const Variant *v) { return *VariantInternal::get_basis(v); } + static _FORCE_INLINE_ void set(Variant *v, const Basis &p_value) { *VariantInternal::get_basis(v) = p_value; } +}; + +template <> +struct VariantInternalAccessor<Color> { + static _FORCE_INLINE_ const Color &get(const Variant *v) { return *VariantInternal::get_color(v); } + static _FORCE_INLINE_ void set(Variant *v, const Color &p_value) { *VariantInternal::get_color(v) = p_value; } +}; + +template <> +struct VariantInternalAccessor<StringName> { + static _FORCE_INLINE_ const StringName &get(const Variant *v) { return *VariantInternal::get_string_name(v); } + static _FORCE_INLINE_ void set(Variant *v, const StringName &p_value) { *VariantInternal::get_string_name(v) = p_value; } +}; + +template <> +struct VariantInternalAccessor<NodePath> { + static _FORCE_INLINE_ const NodePath &get(const Variant *v) { return *VariantInternal::get_node_path(v); } + static _FORCE_INLINE_ void set(Variant *v, const NodePath &p_value) { *VariantInternal::get_node_path(v) = p_value; } +}; + +template <> +struct VariantInternalAccessor<RID> { + static _FORCE_INLINE_ const RID &get(const Variant *v) { return *VariantInternal::get_rid(v); } + static _FORCE_INLINE_ void set(Variant *v, const RID &p_value) { *VariantInternal::get_rid(v) = p_value; } +}; + +template <> +struct VariantInternalAccessor<Callable> { + static _FORCE_INLINE_ const Callable &get(const Variant *v) { return *VariantInternal::get_callable(v); } + static _FORCE_INLINE_ void set(Variant *v, const Callable &p_value) { *VariantInternal::get_callable(v) = p_value; } +}; + +template <> +struct VariantInternalAccessor<Signal> { + static _FORCE_INLINE_ const Signal &get(const Variant *v) { return *VariantInternal::get_signal(v); } + static _FORCE_INLINE_ void set(Variant *v, const Signal &p_value) { *VariantInternal::get_signal(v) = p_value; } +}; + +template <> +struct VariantInternalAccessor<Dictionary> { + static _FORCE_INLINE_ const Dictionary &get(const Variant *v) { return *VariantInternal::get_dictionary(v); } + static _FORCE_INLINE_ void set(Variant *v, const Dictionary &p_value) { *VariantInternal::get_dictionary(v) = p_value; } +}; + +template <> +struct VariantInternalAccessor<Array> { + static _FORCE_INLINE_ const Array &get(const Variant *v) { return *VariantInternal::get_array(v); } + static _FORCE_INLINE_ void set(Variant *v, const Array &p_value) { *VariantInternal::get_array(v) = p_value; } +}; + +template <> +struct VariantInternalAccessor<PackedByteArray> { + static _FORCE_INLINE_ const PackedByteArray &get(const Variant *v) { return *VariantInternal::get_byte_array(v); } + static _FORCE_INLINE_ void set(Variant *v, const PackedByteArray &p_value) { *VariantInternal::get_byte_array(v) = p_value; } +}; + +template <> +struct VariantInternalAccessor<PackedInt32Array> { + static _FORCE_INLINE_ const PackedInt32Array &get(const Variant *v) { return *VariantInternal::get_int32_array(v); } + static _FORCE_INLINE_ void set(Variant *v, const PackedInt32Array &p_value) { *VariantInternal::get_int32_array(v) = p_value; } +}; + +template <> +struct VariantInternalAccessor<PackedInt64Array> { + static _FORCE_INLINE_ const PackedInt64Array &get(const Variant *v) { return *VariantInternal::get_int64_array(v); } + static _FORCE_INLINE_ void set(Variant *v, const PackedInt64Array &p_value) { *VariantInternal::get_int64_array(v) = p_value; } +}; + +template <> +struct VariantInternalAccessor<PackedFloat32Array> { + static _FORCE_INLINE_ const PackedFloat32Array &get(const Variant *v) { return *VariantInternal::get_float32_array(v); } + static _FORCE_INLINE_ void set(Variant *v, const PackedFloat32Array &p_value) { *VariantInternal::get_float32_array(v) = p_value; } +}; + +template <> +struct VariantInternalAccessor<PackedFloat64Array> { + static _FORCE_INLINE_ const PackedFloat64Array &get(const Variant *v) { return *VariantInternal::get_float64_array(v); } + static _FORCE_INLINE_ void set(Variant *v, const PackedFloat64Array &p_value) { *VariantInternal::get_float64_array(v) = p_value; } +}; + +template <> +struct VariantInternalAccessor<PackedStringArray> { + static _FORCE_INLINE_ const PackedStringArray &get(const Variant *v) { return *VariantInternal::get_string_array(v); } + static _FORCE_INLINE_ void set(Variant *v, const PackedStringArray &p_value) { *VariantInternal::get_string_array(v) = p_value; } +}; + +template <> +struct VariantInternalAccessor<PackedVector2Array> { + static _FORCE_INLINE_ const PackedVector2Array &get(const Variant *v) { return *VariantInternal::get_vector2_array(v); } + static _FORCE_INLINE_ void set(Variant *v, const PackedVector2Array &p_value) { *VariantInternal::get_vector2_array(v) = p_value; } +}; + +template <> +struct VariantInternalAccessor<PackedVector3Array> { + static _FORCE_INLINE_ const PackedVector3Array &get(const Variant *v) { return *VariantInternal::get_vector3_array(v); } + static _FORCE_INLINE_ void set(Variant *v, const PackedVector3Array &p_value) { *VariantInternal::get_vector3_array(v) = p_value; } +}; + +template <> +struct VariantInternalAccessor<PackedColorArray> { + static _FORCE_INLINE_ const PackedColorArray &get(const Variant *v) { return *VariantInternal::get_color_array(v); } + static _FORCE_INLINE_ void set(Variant *v, const PackedColorArray &p_value) { *VariantInternal::get_color_array(v) = p_value; } +}; + +template <> +struct VariantInternalAccessor<Object *> { + static _FORCE_INLINE_ Object *get(const Variant *v) { return const_cast<Object *>(*VariantInternal::get_object(v)); } + static _FORCE_INLINE_ void set(Variant *v, const Object *p_value) { *VariantInternal::get_object(v) = const_cast<Object *>(p_value); } +}; + +template <> +struct VariantInternalAccessor<Variant> { + static _FORCE_INLINE_ Variant &get(Variant *v) { return *v; } + static _FORCE_INLINE_ const Variant &get(const Variant *v) { return *v; } + static _FORCE_INLINE_ void set(Variant *v, const Variant &p_value) { *v = p_value; } +}; + +template <> +struct VariantInternalAccessor<Vector<Variant>> { + static _FORCE_INLINE_ Vector<Variant> get(const Variant *v) { + Vector<Variant> ret; + int s = VariantInternal::get_array(v)->size(); + ret.resize(s); + for (int i = 0; i < s; i++) { + ret.write[i] = VariantInternal::get_array(v)->get(i); + } + + return ret; + } + static _FORCE_INLINE_ void set(Variant *v, const Vector<Variant> &p_value) { + int s = p_value.size(); + VariantInternal::get_array(v)->resize(s); + for (int i = 0; i < s; i++) { + VariantInternal::get_array(v)->set(i, p_value[i]); + } + } }; #endif // VARIANT_INTERNAL_H diff --git a/core/variant_op.cpp b/core/variant_op.cpp index 533b056f91..47539df856 100644 --- a/core/variant_op.cpp +++ b/core/variant_op.cpp @@ -30,9 +30,9 @@ #include "variant.h" +#include "core/class_db.h" #include "core/core_string_names.h" #include "core/debugger/engine_debugger.h" -#include "core/object.h" #define CASE_TYPE_ALL(PREFIX, OP) \ CASE_TYPE(PREFIX, OP, INT) \ |