diff options
Diffstat (limited to 'core')
36 files changed, 3222 insertions, 903 deletions
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index f5a351f16a..c1cf061854 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -3101,8 +3101,8 @@ void _Engine::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "editor_hint"), "set_editor_hint", "is_editor_hint"); ADD_PROPERTY(PropertyInfo(Variant::INT, "iterations_per_second"), "set_iterations_per_second", "get_iterations_per_second"); ADD_PROPERTY(PropertyInfo(Variant::INT, "target_fps"), "set_target_fps", "get_target_fps"); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "time_scale"), "set_time_scale", "get_time_scale"); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "physics_jitter_fix"), "set_physics_jitter_fix", "get_physics_jitter_fix"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "time_scale"), "set_time_scale", "get_time_scale"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "physics_jitter_fix"), "set_physics_jitter_fix", "get_physics_jitter_fix"); } _Engine *_Engine::singleton = NULL; diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index 342c43802e..ae569ea189 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -581,9 +581,9 @@ private: bool _list_skip_hidden; }; -class _Marshalls : public Reference { +class _Marshalls : public Object { - GDCLASS(_Marshalls, Reference); + GDCLASS(_Marshalls, Object); static _Marshalls *singleton; diff --git a/core/callable.h b/core/callable.h index 8ea5377ce8..cecf2264a3 100644 --- a/core/callable.h +++ b/core/callable.h @@ -39,10 +39,9 @@ class Object; class Variant; class CallableCustom; -// This is an abstraction of things that can be called -// it is used for signals and other cases where effient -// calling of functions is required. -// It is designed for the standard case (object and method) +// This is an abstraction of things that can be called. +// It is used for signals and other cases where efficient calling of functions +// is required. It is designed for the standard case (object and method) // but can be optimized or customized. class Callable { diff --git a/core/callable_method_pointer.cpp b/core/callable_method_pointer.cpp new file mode 100644 index 0000000000..8774af6add --- /dev/null +++ b/core/callable_method_pointer.cpp @@ -0,0 +1,94 @@ +/*************************************************************************/ +/* callable_method_pointer.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_method_pointer.h" + +bool CallableCustomMethodPointerBase::compare_equal(const CallableCustom *p_a, const CallableCustom *p_b) { + const CallableCustomMethodPointerBase *a = static_cast<const CallableCustomMethodPointerBase *>(p_a); + const CallableCustomMethodPointerBase *b = static_cast<const CallableCustomMethodPointerBase *>(p_b); + + if (a->comp_size != b->comp_size) { + return false; + } + + for (uint32_t i = 0; i < a->comp_size; i++) { + if (a->comp_ptr[i] != b->comp_ptr[i]) { + return false; + } + } + + return true; +} + +bool CallableCustomMethodPointerBase::compare_less(const CallableCustom *p_a, const CallableCustom *p_b) { + + const CallableCustomMethodPointerBase *a = static_cast<const CallableCustomMethodPointerBase *>(p_a); + const CallableCustomMethodPointerBase *b = static_cast<const CallableCustomMethodPointerBase *>(p_b); + + if (a->comp_size != b->comp_size) { + return a->comp_size < b->comp_size; + } + + for (uint32_t i = 0; i < a->comp_size; i++) { + if (a->comp_ptr[i] == b->comp_ptr[i]) { + continue; + } + + return a->comp_ptr[i] < b->comp_ptr[i]; + } + + return false; +} + +CallableCustom::CompareEqualFunc CallableCustomMethodPointerBase::get_compare_equal_func() const { + return compare_equal; +} + +CallableCustom::CompareLessFunc CallableCustomMethodPointerBase::get_compare_less_func() const { + return compare_less; +} + +uint32_t CallableCustomMethodPointerBase::hash() const { + return h; +} + +void CallableCustomMethodPointerBase::_setup(uint32_t *p_base_ptr, uint32_t p_ptr_size) { + comp_ptr = p_base_ptr; + comp_size = p_ptr_size / 4; + + // Precompute hash. + for (uint32_t i = 0; i < comp_size; i++) { + if (i == 0) { + h = hash_djb2_one_32(comp_ptr[i]); + } else { + h = hash_djb2_one_32(comp_ptr[i], h); + } + } +} diff --git a/core/callable_method_pointer.h b/core/callable_method_pointer.h new file mode 100644 index 0000000000..a931a344e6 --- /dev/null +++ b/core/callable_method_pointer.h @@ -0,0 +1,292 @@ +/*************************************************************************/ +/* callable_method_pointer.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_METHOD_POINTER_H +#define CALLABLE_METHOD_POINTER_H + +#include "core/callable.h" +#include "core/hashfuncs.h" +#include "core/object.h" +#include "core/simple_type.h" + +class CallableCustomMethodPointerBase : public CallableCustom { + + uint32_t *comp_ptr; + uint32_t comp_size; + uint32_t h; +#ifdef DEBUG_METHODS_ENABLED + const char *text = ""; +#endif + static bool compare_equal(const CallableCustom *p_a, const CallableCustom *p_b); + static bool compare_less(const CallableCustom *p_a, const CallableCustom *p_b); + +protected: + void _setup(uint32_t *p_base_ptr, uint32_t p_ptr_size); + +public: +#ifdef DEBUG_METHODS_ENABLED + void set_text(const char *p_text) { + text = p_text; + } + virtual String get_as_text() const { + return text; + } +#else + virtual String get_as_text() const { + return String(); + } +#endif + virtual CompareEqualFunc get_compare_equal_func() const; + virtual CompareLessFunc get_compare_less_func() const; + + 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 { + T *instance; + void (T::*method)(P...); + } data; + +public: + virtual ObjectID get_object() const { return data.instance->get_instance_id(); } + + virtual void call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const { + + call_with_variant_args(data.instance, data.method, p_arguments, p_argcount, r_call_error); + } + + CallableCustomMethodPointer(T *p_instance, void (T::*p_method)(P...)) { + zeromem(&data, sizeof(Data)); // Clear beforehand, may have padding bytes. + data.instance = p_instance; + data.method = p_method; + _setup((uint32_t *)&data, sizeof(Data)); + } +}; + +template <class T, class... P> +Callable create_custom_callable_function_pointer(T *p_instance, +#ifdef DEBUG_METHODS_ENABLED + const char *p_func_text, +#endif + void (T::*p_method)(P...)) { + + typedef CallableCustomMethodPointer<T, 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 + return Callable(ccmp); +} + +// 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" +#endif + +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 + (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 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> +class CallableCustomMethodPointerRet : public CallableCustomMethodPointerBase { + + struct Data { + T *instance; + R(T::*method) + (P...); + } data; + +public: + virtual ObjectID get_object() const { return data.instance->get_instance_id(); } + + virtual void call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const { + + call_with_variant_args_ret(data.instance, data.method, p_arguments, p_argcount, r_return_value, r_call_error); + } + + CallableCustomMethodPointerRet(T *p_instance, R (T::*p_method)(P...)) { + zeromem(&data, sizeof(Data)); // Clear beforehand, may have padding bytes. + data.instance = p_instance; + data.method = p_method; + _setup((uint32_t *)&data, sizeof(Data)); + } +}; + +template <class T, class R, class... P> +Callable create_custom_callable_function_pointer(T *p_instance, +#ifdef DEBUG_METHODS_ENABLED + const char *p_func_text, +#endif + R (T::*p_method)(P...)) { + + 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 + return Callable(ccmp); +} + +#ifdef DEBUG_METHODS_ENABLED +#define callable_mp(I, M) create_custom_callable_function_pointer(I, #M, M) +#else +#define callable_mp(I, M) create_custom_callable_function_pointer(I, M) +#endif + +#endif // CALLABLE_METHOD_POINTER_H diff --git a/core/class_db.h b/core/class_db.h index 404b04f2d0..398eca9132 100644 --- a/core/class_db.h +++ b/core/class_db.h @@ -35,13 +35,15 @@ #include "core/object.h" #include "core/print_string.h" -/** To bind more then 6 parameters include this: +/** To bind more then 6 parameters include this: * #include "core/method_bind_ext.gen.inc" */ -#define DEFVAL(m_defval) (m_defval) +// Makes callable_mp readily available in all classes connecting signals. +// Needs to come after method_bind and object have been included. +#include "core/callable_method_pointer.h" -//#define SIMPLE_METHODDEF +#define DEFVAL(m_defval) (m_defval) #ifdef DEBUG_METHODS_ENABLED diff --git a/core/compressed_translation.cpp b/core/compressed_translation.cpp index ea84ded3b4..ed307fd3ac 100644 --- a/core/compressed_translation.cpp +++ b/core/compressed_translation.cpp @@ -279,8 +279,8 @@ StringName PHashTranslation::get_message(const StringName &p_src_text) const { void PHashTranslation::_get_property_list(List<PropertyInfo> *p_list) const { - p_list->push_back(PropertyInfo(Variant::PACKED_INT_ARRAY, "hash_table")); - p_list->push_back(PropertyInfo(Variant::PACKED_INT_ARRAY, "bucket_table")); + p_list->push_back(PropertyInfo(Variant::PACKED_INT32_ARRAY, "hash_table")); + p_list->push_back(PropertyInfo(Variant::PACKED_INT32_ARRAY, "bucket_table")); p_list->push_back(PropertyInfo(Variant::PACKED_BYTE_ARRAY, "strings")); p_list->push_back(PropertyInfo(Variant::OBJECT, "load_from", PROPERTY_HINT_RESOURCE_TYPE, "Translation", PROPERTY_USAGE_EDITOR)); } diff --git a/core/global_constants.cpp b/core/global_constants.cpp index b990ec9276..0945240c1f 100644 --- a/core/global_constants.cpp +++ b/core/global_constants.cpp @@ -92,9 +92,6 @@ VARIANT_ENUM_CAST(JoystickList); VARIANT_ENUM_CAST(MidiMessageList); void register_global_constants() { - - //{ KEY_BACKSPACE, VK_BACK },// (0x08) // backspace - BIND_GLOBAL_ENUM_CONSTANT(MARGIN_LEFT); BIND_GLOBAL_ENUM_CONSTANT(MARGIN_TOP); BIND_GLOBAL_ENUM_CONSTANT(MARGIN_RIGHT); @@ -116,7 +113,7 @@ void register_global_constants() { BIND_GLOBAL_ENUM_CONSTANT(VALIGN_CENTER); BIND_GLOBAL_ENUM_CONSTANT(VALIGN_BOTTOM); - // hueg list of keys + // huge list of keys BIND_GLOBAL_CONSTANT(SPKEY); BIND_GLOBAL_ENUM_CONSTANT(KEY_ESCAPE); @@ -594,30 +591,36 @@ void register_global_constants() { BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_NIL", Variant::NIL); BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_BOOL", Variant::BOOL); BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_INT", Variant::INT); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_REAL", Variant::REAL); + BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_REAL", Variant::FLOAT); BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_STRING", Variant::STRING); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_VECTOR2", Variant::VECTOR2); // 5 + BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_VECTOR2", Variant::VECTOR2); + BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_VECTOR2I", Variant::VECTOR2I); BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_RECT2", Variant::RECT2); + BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_RECT2I", Variant::RECT2I); BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_VECTOR3", Variant::VECTOR3); + BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_VECTOR3I", Variant::VECTOR3I); BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_TRANSFORM2D", Variant::TRANSFORM2D); BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_PLANE", Variant::PLANE); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_QUAT", Variant::QUAT); // 10 + BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_QUAT", Variant::QUAT); BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_AABB", Variant::AABB); BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_BASIS", Variant::BASIS); BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_TRANSFORM", Variant::TRANSFORM); BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_COLOR", Variant::COLOR); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_NODE_PATH", Variant::NODE_PATH); // 15 + BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_STRING_NAME", Variant::STRING_NAME); + BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_NODE_PATH", Variant::NODE_PATH); BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_RID", Variant::_RID); BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_OBJECT", Variant::OBJECT); BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_CALLABLE", Variant::CALLABLE); BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_SIGNAL", Variant::SIGNAL); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_DICTIONARY", Variant::DICTIONARY); // 20 + BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_DICTIONARY", Variant::DICTIONARY); BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_ARRAY", Variant::ARRAY); BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_RAW_ARRAY", Variant::PACKED_BYTE_ARRAY); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_INT_ARRAY", Variant::PACKED_INT_ARRAY); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_REAL_ARRAY", Variant::PACKED_REAL_ARRAY); + BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_INT32_ARRAY", Variant::PACKED_INT32_ARRAY); + BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_INT64_ARRAY", Variant::PACKED_INT64_ARRAY); + BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_FLOAT32_ARRAY", Variant::PACKED_FLOAT32_ARRAY); + BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_FLOAT64_ARRAY", Variant::PACKED_FLOAT64_ARRAY); BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_STRING_ARRAY", Variant::PACKED_STRING_ARRAY); - BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_VECTOR2_ARRAY", Variant::PACKED_VECTOR2_ARRAY); // 25 + BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_VECTOR2_ARRAY", Variant::PACKED_VECTOR2_ARRAY); BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_VECTOR3_ARRAY", Variant::PACKED_VECTOR3_ARRAY); BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_COLOR_ARRAY", Variant::PACKED_COLOR_ARRAY); BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_MAX", Variant::VARIANT_MAX); diff --git a/core/io/json.cpp b/core/io/json.cpp index 08a147032f..3a0edceb81 100644 --- a/core/io/json.cpp +++ b/core/io/json.cpp @@ -70,9 +70,11 @@ String JSON::_print_var(const Variant &p_var, const String &p_indent, int p_cur_ case Variant::NIL: return "null"; case Variant::BOOL: return p_var.operator bool() ? "true" : "false"; case Variant::INT: return itos(p_var); - case Variant::REAL: return rtos(p_var); - case Variant::PACKED_INT_ARRAY: - case Variant::PACKED_REAL_ARRAY: + case Variant::FLOAT: return rtos(p_var); + case Variant::PACKED_INT32_ARRAY: + case Variant::PACKED_INT64_ARRAY: + case Variant::PACKED_FLOAT32_ARRAY: + case Variant::PACKED_FLOAT64_ARRAY: case Variant::PACKED_STRING_ARRAY: case Variant::ARRAY: { diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp index ab88f4d85c..fbcaa582b7 100644 --- a/core/io/marshalls.cpp +++ b/core/io/marshalls.cpp @@ -147,7 +147,7 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } } break; - case Variant::REAL: { + case Variant::FLOAT: { if (type & ENCODE_FLAG_64) { ERR_FAIL_COND_V(len < 8, ERR_INVALID_DATA); @@ -186,7 +186,19 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int if (r_len) (*r_len) += 4 * 2; - } break; // 5 + } break; + case Variant::VECTOR2I: { + + ERR_FAIL_COND_V(len < 4 * 2, ERR_INVALID_DATA); + Vector2i val; + val.x = decode_uint32(&buf[0]); + val.y = decode_uint32(&buf[4]); + r_variant = val; + + if (r_len) + (*r_len) += 4 * 2; + + } break; case Variant::RECT2: { ERR_FAIL_COND_V(len < 4 * 4, ERR_INVALID_DATA); @@ -201,6 +213,20 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int (*r_len) += 4 * 4; } break; + case Variant::RECT2I: { + + ERR_FAIL_COND_V(len < 4 * 4, ERR_INVALID_DATA); + Rect2i val; + val.position.x = decode_uint32(&buf[0]); + val.position.y = decode_uint32(&buf[4]); + val.size.x = decode_uint32(&buf[8]); + val.size.y = decode_uint32(&buf[12]); + r_variant = val; + + if (r_len) + (*r_len) += 4 * 4; + + } break; case Variant::VECTOR3: { ERR_FAIL_COND_V(len < 4 * 3, ERR_INVALID_DATA); @@ -214,6 +240,19 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int (*r_len) += 4 * 3; } break; + case Variant::VECTOR3I: { + + ERR_FAIL_COND_V(len < 4 * 3, ERR_INVALID_DATA); + Vector3i val; + val.x = decode_uint32(&buf[0]); + val.y = decode_uint32(&buf[4]); + val.z = decode_uint32(&buf[8]); + r_variant = val; + + if (r_len) + (*r_len) += 4 * 3; + + } break; case Variant::TRANSFORM2D: { ERR_FAIL_COND_V(len < 4 * 6, ERR_INVALID_DATA); @@ -328,6 +367,16 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int (*r_len) += 4 * 4; } break; + case Variant::STRING_NAME: { + + String str; + Error err = _decode_string(buf, len, r_len, str); + if (err) + return err; + r_variant = StringName(str); + + } break; + case Variant::NODE_PATH: { ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); @@ -572,7 +621,7 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } } break; - case Variant::PACKED_INT_ARRAY: { + case Variant::PACKED_INT32_ARRAY: { ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); int32_t count = decode_uint32(buf); @@ -581,12 +630,12 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int ERR_FAIL_MUL_OF(count, 4, ERR_INVALID_DATA); ERR_FAIL_COND_V(count < 0 || count * 4 > len, ERR_INVALID_DATA); - Vector<int> data; + Vector<int32_t> data; if (count) { //const int*rbuf=(const int*)buf; data.resize(count); - int *w = data.ptrw(); + int32_t *w = data.ptrw(); for (int32_t i = 0; i < count; i++) { w[i] = decode_uint32(&buf[i * 4]); @@ -594,11 +643,37 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } r_variant = Variant(data); if (r_len) { - (*r_len) += 4 + count * sizeof(int); + (*r_len) += 4 + count * sizeof(int32_t); } } break; - case Variant::PACKED_REAL_ARRAY: { + case Variant::PACKED_INT64_ARRAY: { + + ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); + int64_t count = decode_uint64(buf); + buf += 4; + len -= 4; + ERR_FAIL_MUL_OF(count, 8, ERR_INVALID_DATA); + ERR_FAIL_COND_V(count < 0 || count * 8 > len, ERR_INVALID_DATA); + + Vector<int64_t> data; + + if (count) { + //const int*rbuf=(const int*)buf; + data.resize(count); + int64_t *w = data.ptrw(); + for (int64_t i = 0; i < count; i++) { + + w[i] = decode_uint64(&buf[i * 8]); + } + } + r_variant = Variant(data); + if (r_len) { + (*r_len) += 4 + count * sizeof(int64_t); + } + + } break; + case Variant::PACKED_FLOAT32_ARRAY: { ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); int32_t count = decode_uint32(buf); @@ -625,6 +700,33 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } } break; + case Variant::PACKED_FLOAT64_ARRAY: { + + ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); + int64_t count = decode_uint64(buf); + buf += 4; + len -= 4; + ERR_FAIL_MUL_OF(count, 8, ERR_INVALID_DATA); + ERR_FAIL_COND_V(count < 0 || count * 8 > len, ERR_INVALID_DATA); + + Vector<double> data; + + if (count) { + //const double*rbuf=(const double*)buf; + data.resize(count); + double *w = data.ptrw(); + for (int64_t i = 0; i < count; i++) { + + w[i] = decode_double(&buf[i * 8]); + } + } + r_variant = data; + + if (r_len) { + (*r_len) += 4 + count * sizeof(double); + } + + } break; case Variant::PACKED_STRING_ARRAY: { ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); @@ -802,7 +904,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo flags |= ENCODE_FLAG_64; } } break; - case Variant::REAL: { + case Variant::FLOAT: { double d = p_variant; float f = d; @@ -869,7 +971,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo r_len += 4; } } break; - case Variant::REAL: { + case Variant::FLOAT: { if (flags & ENCODE_FLAG_64) { if (buf) { @@ -939,6 +1041,11 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo _encode_string(p_variant, buf, r_len); } break; + case Variant::STRING_NAME: { + + _encode_string(p_variant, buf, r_len); + + } break; // math types case Variant::VECTOR2: { @@ -951,7 +1058,18 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo r_len += 2 * 4; - } break; // 5 + } break; + case Variant::VECTOR2I: { + + if (buf) { + Vector2i v2 = p_variant; + encode_uint32(v2.x, &buf[0]); + encode_uint32(v2.y, &buf[4]); + } + + r_len += 2 * 4; + + } break; case Variant::RECT2: { if (buf) { @@ -964,6 +1082,18 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo r_len += 4 * 4; } break; + case Variant::RECT2I: { + + if (buf) { + Rect2i r2 = p_variant; + encode_uint32(r2.position.x, &buf[0]); + encode_uint32(r2.position.y, &buf[4]); + encode_uint32(r2.size.x, &buf[8]); + encode_uint32(r2.size.y, &buf[12]); + } + r_len += 4 * 4; + + } break; case Variant::VECTOR3: { if (buf) { @@ -976,6 +1106,18 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo r_len += 3 * 4; } break; + case Variant::VECTOR3I: { + + if (buf) { + Vector3i v3 = p_variant; + encode_uint32(v3.x, &buf[0]); + encode_uint32(v3.y, &buf[4]); + encode_uint32(v3.z, &buf[8]); + } + + r_len += 3 * 4; + + } break; case Variant::TRANSFORM2D: { if (buf) { @@ -1244,33 +1386,50 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } } break; - case Variant::PACKED_INT_ARRAY: { + case Variant::PACKED_INT32_ARRAY: { - Vector<int> data = p_variant; + Vector<int32_t> data = p_variant; int datalen = data.size(); int datasize = sizeof(int32_t); if (buf) { encode_uint32(datalen, buf); buf += 4; - const int *r = data.ptr(); - for (int i = 0; i < datalen; i++) + const int32_t *r = data.ptr(); + for (int32_t i = 0; i < datalen; i++) encode_uint32(r[i], &buf[i * datasize]); } r_len += 4 + datalen * datasize; } break; - case Variant::PACKED_REAL_ARRAY: { + case Variant::PACKED_INT64_ARRAY: { + + Vector<int64_t> data = p_variant; + int datalen = data.size(); + int datasize = sizeof(int64_t); + + if (buf) { + encode_uint64(datalen, buf); + buf += 4; + const int64_t *r = data.ptr(); + for (int64_t i = 0; i < datalen; i++) + encode_uint64(r[i], &buf[i * datasize]); + } + + r_len += 4 + datalen * datasize; + + } break; + case Variant::PACKED_FLOAT32_ARRAY: { - Vector<real_t> data = p_variant; + Vector<float> data = p_variant; int datalen = data.size(); - int datasize = sizeof(real_t); + int datasize = sizeof(float); if (buf) { encode_uint32(datalen, buf); buf += 4; - const real_t *r = data.ptr(); + const float *r = data.ptr(); for (int i = 0; i < datalen; i++) encode_float(r[i], &buf[i * datasize]); } @@ -1278,6 +1437,23 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo r_len += 4 + datalen * datasize; } break; + case Variant::PACKED_FLOAT64_ARRAY: { + + Vector<double> data = p_variant; + int datalen = data.size(); + int datasize = sizeof(double); + + if (buf) { + encode_uint32(datalen, buf); + buf += 4; + const double *r = data.ptr(); + for (int i = 0; i < datalen; i++) + encode_double(r[i], &buf[i * datasize]); + } + + r_len += 4 + datalen * datasize; + + } break; case Variant::PACKED_STRING_ARRAY: { Vector<String> data = p_variant; diff --git a/core/io/multiplayer_api.cpp b/core/io/multiplayer_api.cpp index 1fcd00c0e4..6a0eeea513 100644 --- a/core/io/multiplayer_api.cpp +++ b/core/io/multiplayer_api.cpp @@ -51,7 +51,7 @@ _FORCE_INLINE_ bool _should_call_local(MultiplayerAPI::RPCMode mode, bool is_mas case MultiplayerAPI::RPC_MODE_MASTERSYNC: { if (is_master) r_skip_rpc = true; // I am the master, so skip remote call. - FALLTHROUGH; + [[fallthrough]]; } case MultiplayerAPI::RPC_MODE_REMOTESYNC: case MultiplayerAPI::RPC_MODE_PUPPETSYNC: { diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index 991853e86d..8c343a0f43 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -46,7 +46,7 @@ enum { VARIANT_NIL = 1, VARIANT_BOOL = 2, VARIANT_INT = 3, - VARIANT_REAL = 4, + VARIANT_FLOAT = 4, VARIANT_STRING = 5, VARIANT_VECTOR2 = 10, VARIANT_RECT2 = 11, @@ -65,8 +65,8 @@ enum { VARIANT_DICTIONARY = 26, VARIANT_ARRAY = 30, VARIANT_RAW_ARRAY = 31, - VARIANT_INT_ARRAY = 32, - VARIANT_REAL_ARRAY = 33, + VARIANT_INT32_ARRAY = 32, + VARIANT_FLOAT32_ARRAY = 33, VARIANT_STRING_ARRAY = 34, VARIANT_VECTOR3_ARRAY = 35, VARIANT_COLOR_ARRAY = 36, @@ -75,6 +75,12 @@ enum { VARIANT_DOUBLE = 41, VARIANT_CALLABLE = 42, VARIANT_SIGNAL = 43, + VARIANT_STRING_NAME = 44, + VARIANT_VECTOR2I = 45, + VARIANT_RECT2I = 46, + VARIANT_VECTOR3I = 47, + VARIANT_INT64_ARRAY = 48, + VARIANT_FLOAT64_ARRAY = 49, OBJECT_EMPTY = 0, OBJECT_EXTERNAL_RESOURCE = 1, OBJECT_INTERNAL_RESOURCE = 2, @@ -138,7 +144,7 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) { r_v = int64_t(f->get_64()); } break; - case VARIANT_REAL: { + case VARIANT_FLOAT: { r_v = f->get_real(); } break; @@ -158,6 +164,14 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) { r_v = v; } break; + case VARIANT_VECTOR2I: { + + Vector2i v; + v.x = f->get_32(); + v.y = f->get_32(); + r_v = v; + + } break; case VARIANT_RECT2: { Rect2 v; @@ -168,6 +182,16 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) { r_v = v; } break; + case VARIANT_RECT2I: { + + Rect2i v; + v.position.x = f->get_32(); + v.position.y = f->get_32(); + v.size.x = f->get_32(); + v.size.y = f->get_32(); + r_v = v; + + } break; case VARIANT_VECTOR3: { Vector3 v; @@ -176,6 +200,14 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) { v.z = f->get_real(); r_v = v; } break; + case VARIANT_VECTOR3I: { + + Vector3i v; + v.x = f->get_32(); + v.y = f->get_32(); + v.z = f->get_32(); + r_v = v; + } break; case VARIANT_PLANE: { Plane v; @@ -260,6 +292,10 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) { r_v = v; } break; + case VARIANT_STRING_NAME: { + + r_v = StringName(get_unicode_string()); + } break; case VARIANT_NODE_PATH: { @@ -418,14 +454,14 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) { r_v = array; } break; - case VARIANT_INT_ARRAY: { + case VARIANT_INT32_ARRAY: { uint32_t len = f->get_32(); - Vector<int> array; + Vector<int32_t> array; array.resize(len); - int *w = array.ptrw(); - f->get_buffer((uint8_t *)w, len * 4); + int32_t *w = array.ptrw(); + f->get_buffer((uint8_t *)w, len * sizeof(int32_t)); #ifdef BIG_ENDIAN_ENABLED { uint32_t *ptr = (uint32_t *)w.ptr(); @@ -439,14 +475,35 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) { r_v = array; } break; - case VARIANT_REAL_ARRAY: { + case VARIANT_INT64_ARRAY: { uint32_t len = f->get_32(); - Vector<real_t> array; + Vector<int64_t> array; array.resize(len); - real_t *w = array.ptrw(); - f->get_buffer((uint8_t *)w, len * sizeof(real_t)); + int64_t *w = array.ptrw(); + f->get_buffer((uint8_t *)w, len * sizeof(int64_t)); +#ifdef BIG_ENDIAN_ENABLED + { + uint64_t *ptr = (uint64_t *)w.ptr(); + for (int i = 0; i < len; i++) { + + ptr[i] = BSWAP64(ptr[i]); + } + } + +#endif + + r_v = array; + } break; + case VARIANT_FLOAT32_ARRAY: { + + uint32_t len = f->get_32(); + + Vector<float> array; + array.resize(len); + float *w = array.ptrw(); + f->get_buffer((uint8_t *)w, len * sizeof(float)); #ifdef BIG_ENDIAN_ENABLED { uint32_t *ptr = (uint32_t *)w.ptr(); @@ -460,6 +517,27 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) { r_v = array; } break; + case VARIANT_FLOAT64_ARRAY: { + + uint32_t len = f->get_32(); + + Vector<double> array; + array.resize(len); + double *w = array.ptrw(); + f->get_buffer((uint8_t *)w, len * sizeof(double)); +#ifdef BIG_ENDIAN_ENABLED + { + uint64_t *ptr = (uint64_t *)w.ptr(); + for (int i = 0; i < len; i++) { + + ptr[i] = BSWAP64(ptr[i]); + } + } + +#endif + + r_v = array; + } break; case VARIANT_STRING_ARRAY: { uint32_t len = f->get_32(); @@ -1259,7 +1337,7 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } } break; - case Variant::REAL: { + case Variant::FLOAT: { double d = p_property; float fl = d; @@ -1268,7 +1346,7 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia f->store_double(d); } else { - f->store_32(VARIANT_REAL); + f->store_32(VARIANT_FLOAT); f->store_real(fl); } @@ -1288,6 +1366,14 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia f->store_real(val.y); } break; + case Variant::VECTOR2I: { + + f->store_32(VARIANT_VECTOR2I); + Vector2i val = p_property; + f->store_32(val.x); + f->store_32(val.y); + + } break; case Variant::RECT2: { f->store_32(VARIANT_RECT2); @@ -1298,6 +1384,16 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia f->store_real(val.size.y); } break; + case Variant::RECT2I: { + + f->store_32(VARIANT_RECT2I); + Rect2i val = p_property; + f->store_32(val.position.x); + f->store_32(val.position.y); + f->store_32(val.size.x); + f->store_32(val.size.y); + + } break; case Variant::VECTOR3: { f->store_32(VARIANT_VECTOR3); @@ -1307,6 +1403,15 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia f->store_real(val.z); } break; + case Variant::VECTOR3I: { + + f->store_32(VARIANT_VECTOR3I); + Vector3i val = p_property; + f->store_32(val.x); + f->store_32(val.y); + f->store_32(val.z); + + } break; case Variant::PLANE: { f->store_32(VARIANT_PLANE); @@ -1394,6 +1499,13 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia f->store_real(val.a); } break; + case Variant::STRING_NAME: { + + f->store_32(VARIANT_STRING_NAME); + String val = p_property; + save_unicode_string(f, val); + + } break; case Variant::NODE_PATH: { f->store_32(VARIANT_NODE_PATH); @@ -1505,29 +1617,52 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia _pad_buffer(f, len); } break; - case Variant::PACKED_INT_ARRAY: { + case Variant::PACKED_INT32_ARRAY: { - f->store_32(VARIANT_INT_ARRAY); - Vector<int> arr = p_property; + f->store_32(VARIANT_INT32_ARRAY); + Vector<int32_t> arr = p_property; int len = arr.size(); f->store_32(len); - const int *r = arr.ptr(); + const int32_t *r = arr.ptr(); for (int i = 0; i < len; i++) f->store_32(r[i]); } break; - case Variant::PACKED_REAL_ARRAY: { + case Variant::PACKED_INT64_ARRAY: { - f->store_32(VARIANT_REAL_ARRAY); - Vector<real_t> arr = p_property; + f->store_32(VARIANT_INT64_ARRAY); + Vector<int64_t> arr = p_property; int len = arr.size(); f->store_32(len); - const real_t *r = arr.ptr(); + const int64_t *r = arr.ptr(); + for (int i = 0; i < len; i++) + f->store_64(r[i]); + + } break; + case Variant::PACKED_FLOAT32_ARRAY: { + + f->store_32(VARIANT_FLOAT32_ARRAY); + Vector<float> arr = p_property; + int len = arr.size(); + f->store_32(len); + const float *r = arr.ptr(); for (int i = 0; i < len; i++) { f->store_real(r[i]); } } break; + case Variant::PACKED_FLOAT64_ARRAY: { + + f->store_32(VARIANT_FLOAT64_ARRAY); + Vector<double> arr = p_property; + int len = arr.size(); + f->store_32(len); + const double *r = arr.ptr(); + for (int i = 0; i < len; i++) { + f->store_double(r[i]); + } + + } break; case Variant::PACKED_STRING_ARRAY: { f->store_32(VARIANT_STRING_ARRAY); diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp index 1d5d8f9280..39bbebefa6 100644 --- a/core/io/resource_loader.cpp +++ b/core/io/resource_loader.cpp @@ -248,7 +248,7 @@ void ResourceFormatLoader::_bind_methods() { } ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::PACKED_STRING_ARRAY, "get_recognized_extensions")); - ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "handles_type", PropertyInfo(Variant::STRING, "typename"))); + ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "handles_type", PropertyInfo(Variant::STRING_NAME, "typename"))); ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::STRING, "get_resource_type", PropertyInfo(Variant::STRING, "path"))); ClassDB::add_virtual_method(get_class_static(), MethodInfo("get_dependencies", PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::STRING, "add_types"))); ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::INT, "rename_dependencies", PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::STRING, "renames"))); diff --git a/core/math/a_star.cpp b/core/math/a_star.cpp index b26903e45a..847d4d8681 100644 --- a/core/math/a_star.cpp +++ b/core/math/a_star.cpp @@ -576,8 +576,8 @@ void AStar::_bind_methods() { ClassDB::bind_method(D_METHOD("get_point_path", "from_id", "to_id"), &AStar::get_point_path); ClassDB::bind_method(D_METHOD("get_id_path", "from_id", "to_id"), &AStar::get_id_path); - BIND_VMETHOD(MethodInfo(Variant::REAL, "_estimate_cost", PropertyInfo(Variant::INT, "from_id"), PropertyInfo(Variant::INT, "to_id"))); - BIND_VMETHOD(MethodInfo(Variant::REAL, "_compute_cost", PropertyInfo(Variant::INT, "from_id"), PropertyInfo(Variant::INT, "to_id"))); + BIND_VMETHOD(MethodInfo(Variant::FLOAT, "_estimate_cost", PropertyInfo(Variant::INT, "from_id"), PropertyInfo(Variant::INT, "to_id"))); + BIND_VMETHOD(MethodInfo(Variant::FLOAT, "_compute_cost", PropertyInfo(Variant::INT, "from_id"), PropertyInfo(Variant::INT, "to_id"))); } AStar::AStar() { diff --git a/core/math/expression.cpp b/core/math/expression.cpp index 1130935567..058673b681 100644 --- a/core/math/expression.cpp +++ b/core/math/expression.cpp @@ -212,7 +212,7 @@ int Expression::get_func_argument_count(BuiltinFunc p_func) { if (!p_inputs[m_arg]->is_num()) { \ r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; \ r_error.argument = m_arg; \ - r_error.expected = Variant::REAL; \ + r_error.expected = Variant::FLOAT; \ return; \ } @@ -314,7 +314,7 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant int64_t i = *p_inputs[0]; *r_return = ABS(i); - } else if (p_inputs[0]->get_type() == Variant::REAL) { + } else if (p_inputs[0]->get_type() == Variant::FLOAT) { real_t r = *p_inputs[0]; *r_return = Math::abs(r); @@ -322,7 +322,7 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; - r_error.expected = Variant::REAL; + r_error.expected = Variant::FLOAT; } } break; case MATH_SIGN: { @@ -331,7 +331,7 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant int64_t i = *p_inputs[0]; *r_return = i < 0 ? -1 : (i > 0 ? +1 : 0); - } else if (p_inputs[0]->get_type() == Variant::REAL) { + } else if (p_inputs[0]->get_type() == Variant::FLOAT) { real_t r = *p_inputs[0]; *r_return = r < 0.0 ? -1.0 : (r > 0.0 ? +1.0 : 0.0); @@ -339,7 +339,7 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; - r_error.expected = Variant::REAL; + r_error.expected = Variant::FLOAT; } } break; case MATH_POW: { @@ -1161,7 +1161,7 @@ Error Expression::_get_token(Token &r_token) { if (is_float) r_token.value = num.to_double(); else - r_token.value = num.to_int(); + r_token.value = num.to_int64(); return OK; } else if ((cchar >= 'A' && cchar <= 'Z') || (cchar >= 'a' && cchar <= 'z') || cchar == '_') { diff --git a/core/math/rect2.h b/core/math/rect2.h index 0d2e7eb6e5..e4ea615c22 100644 --- a/core/math/rect2.h +++ b/core/math/rect2.h @@ -387,6 +387,11 @@ struct Rect2i { size = end - begin; } + _FORCE_INLINE_ Rect2i abs() const { + + return Rect2i(Point2i(position.x + MIN(size.x, 0), position.y + MIN(size.y, 0)), size.abs()); + } + operator String() const { return String(position) + ", " + String(size); } operator Rect2() const { return Rect2(position, size); } diff --git a/core/math/vector2.h b/core/math/vector2.h index 1dec830821..ba5558102f 100644 --- a/core/math/vector2.h +++ b/core/math/vector2.h @@ -311,10 +311,15 @@ struct Vector2i { bool operator<(const Vector2i &p_vec2) const { return (x == p_vec2.x) ? (y < p_vec2.y) : (x < p_vec2.x); } bool operator>(const Vector2i &p_vec2) const { return (x == p_vec2.x) ? (y > p_vec2.y) : (x > p_vec2.x); } + bool operator<=(const Vector2i &p_vec2) const { return x == p_vec2.x ? (y <= p_vec2.y) : (x < p_vec2.x); } + bool operator>=(const Vector2i &p_vec2) const { return x == p_vec2.x ? (y >= p_vec2.y) : (x > p_vec2.x); } + bool operator==(const Vector2i &p_vec2) const; bool operator!=(const Vector2i &p_vec2) const; - real_t get_aspect() const { return width / (real_t)height; } + real_t aspect() const { return width / (real_t)height; } + Vector2i sign() const { return Vector2i(SGN(x), SGN(y)); } + Vector2i abs() const { return Vector2i(ABS(x), ABS(y)); } operator String() const { return String::num(x) + ", " + String::num(y); } diff --git a/core/method_bind.h b/core/method_bind.h index 72be141fd3..726ce512f8 100644 --- a/core/method_bind.h +++ b/core/method_bind.h @@ -31,19 +31,18 @@ #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/variant.h" #include <stdio.h> -#ifdef DEBUG_ENABLED -#define DEBUG_METHODS_ENABLED -#endif - -#include "core/type_info.h" - enum MethodFlags { METHOD_FLAG_NORMAL = 1, diff --git a/core/method_ptrcall.h b/core/method_ptrcall.h index 42d71dea46..3db186ca69 100644 --- a/core/method_ptrcall.h +++ b/core/method_ptrcall.h @@ -125,6 +125,7 @@ MAKE_PTRARG_BY_REFERENCE(AABB); MAKE_PTRARG_BY_REFERENCE(Basis); MAKE_PTRARG_BY_REFERENCE(Transform); MAKE_PTRARG_BY_REFERENCE(Color); +MAKE_PTRARG(StringName); MAKE_PTRARG(NodePath); MAKE_PTRARG(RID); MAKE_PTRARG(Dictionary); @@ -132,8 +133,10 @@ MAKE_PTRARG(Callable); MAKE_PTRARG(Signal); MAKE_PTRARG(Array); MAKE_PTRARG(PackedByteArray); -MAKE_PTRARG(PackedIntArray); -MAKE_PTRARG(PackedRealArray); +MAKE_PTRARG(PackedInt32Array); +MAKE_PTRARG(PackedInt64Array); +MAKE_PTRARG(PackedFloat32Array); +MAKE_PTRARG(PackedFloat64Array); MAKE_PTRARG(PackedStringArray); MAKE_PTRARG(PackedVector2Array); MAKE_PTRARG(PackedVector3Array); @@ -373,29 +376,7 @@ MAKE_VECARR(Plane); } \ } -//MAKE_DVECARR(Plane); -//for special case StringName - -#define MAKE_STRINGCONV(m_type) \ - template <> \ - struct PtrToArg<m_type> { \ - _FORCE_INLINE_ static m_type convert(const void *p_ptr) { \ - m_type s = *reinterpret_cast<const String *>(p_ptr); \ - return s; \ - } \ - _FORCE_INLINE_ static void encode(m_type p_vec, void *p_ptr) { \ - String *arr = reinterpret_cast<String *>(p_ptr); \ - *arr = p_vec; \ - } \ - }; \ - \ - template <> \ - struct PtrToArg<const m_type &> { \ - _FORCE_INLINE_ static m_type convert(const void *p_ptr) { \ - m_type s = *reinterpret_cast<const String *>(p_ptr); \ - return s; \ - } \ - } +// Special case for IP_Address. #define MAKE_STRINGCONV_BY_REFERENCE(m_type) \ template <> \ @@ -418,7 +399,6 @@ MAKE_VECARR(Plane); } \ } -MAKE_STRINGCONV(StringName); MAKE_STRINGCONV_BY_REFERENCE(IP_Address); template <> diff --git a/core/node_path.h b/core/node_path.h index 5439658910..05b6d844ff 100644 --- a/core/node_path.h +++ b/core/node_path.h @@ -54,15 +54,6 @@ class NodePath { void _update_hash_cache() const; public: - _FORCE_INLINE_ StringName get_sname() const { - - if (data && data->path.size() == 1 && data->subpath.empty()) { - return data->path[0]; - } else { - return operator String(); - } - } - bool is_absolute() const; int get_name_count() const; StringName get_name(int p_idx) const; diff --git a/core/object.cpp b/core/object.cpp index d5db383cbc..140ee811fe 100644 --- a/core/object.cpp +++ b/core/object.cpp @@ -646,10 +646,10 @@ Variant Object::_call_bind(const Variant **p_args, int p_argcount, Callable::Cal return Variant(); } - if (p_args[0]->get_type() != Variant::STRING) { + if (p_args[0]->get_type() != Variant::STRING_NAME && p_args[0]->get_type() != Variant::STRING) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; - r_error.expected = Variant::STRING; + r_error.expected = Variant::STRING_NAME; return Variant(); } @@ -666,10 +666,10 @@ Variant Object::_call_deferred_bind(const Variant **p_args, int p_argcount, Call return Variant(); } - if (p_args[0]->get_type() != Variant::STRING) { + if (p_args[0]->get_type() != Variant::STRING_NAME && p_args[0]->get_type() != Variant::STRING) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; - r_error.expected = Variant::STRING; + r_error.expected = Variant::STRING_NAME; return Variant(); } @@ -1108,11 +1108,11 @@ Variant Object::_emit_signal(const Variant **p_args, int p_argcount, Callable::C r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; ERR_FAIL_COND_V(p_argcount < 1, Variant()); - if (p_args[0]->get_type() != Variant::STRING) { + if (p_args[0]->get_type() != Variant::STRING_NAME && p_args[0]->get_type() != Variant::STRING) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; - r_error.expected = Variant::STRING; - ERR_FAIL_COND_V(p_args[0]->get_type() != Variant::STRING, Variant()); + r_error.expected = Variant::STRING_NAME; + ERR_FAIL_COND_V(p_args[0]->get_type() != Variant::STRING_NAME && p_args[0]->get_type() != Variant::STRING, Variant()); } r_error.error = Callable::CallError::CALL_OK; @@ -1207,7 +1207,7 @@ Error Object::emit_signal(const StringName &p_name, const Variant **p_args, int if (ce.error == Callable::CallError::CALL_ERROR_INVALID_METHOD && !ClassDB::class_exists(target->get_class_name())) { //most likely object is not initialized yet, do not throw error. } else { - ERR_PRINT("Error calling from signal '" + String(p_name) + "': " + Variant::get_callable_error_text(c.callable, args, argc, ce) + "."); + ERR_PRINT("Error calling from signal '" + String(p_name) + "' to callable: " + Variant::get_callable_error_text(c.callable, args, argc, ce) + "."); err = ERR_METHOD_NOT_FOUND; } } @@ -1405,6 +1405,9 @@ Error Object::connect(const StringName &p_signal, const Callable &p_callable, co ERR_FAIL_COND_V(p_callable.is_null(), ERR_INVALID_PARAMETER); + Object *target_object = p_callable.get_object(); + ERR_FAIL_COND_V(!target_object, ERR_INVALID_PARAMETER); + SignalData *s = signal_map.getptr(p_signal); if (!s) { bool signal_is_valid = ClassDB::has_signal(get_class_name(), p_signal); @@ -1449,7 +1452,7 @@ Error Object::connect(const StringName &p_signal, const Callable &p_callable, co conn.flags = p_flags; conn.binds = p_binds; slot.conn = conn; - slot.cE = p_callable.get_object()->connections.push_back(conn); + slot.cE = target_object->connections.push_back(conn); if (p_flags & CONNECT_REFERENCE_COUNTED) { slot.reference_count = 1; } @@ -1498,6 +1501,10 @@ void Object::disconnect(const StringName &p_signal, const Callable &p_callable) void Object::_disconnect(const StringName &p_signal, const Callable &p_callable, bool p_force) { ERR_FAIL_COND(p_callable.is_null()); + + Object *target_object = p_callable.get_object(); + ERR_FAIL_COND(!target_object); + SignalData *s = signal_map.getptr(p_signal); ERR_FAIL_COND_MSG(!s, vformat("Nonexistent signal '%s' in %s.", p_signal, to_string())); @@ -1511,9 +1518,8 @@ void Object::_disconnect(const StringName &p_signal, const Callable &p_callable, return; } } - Object *object = p_callable.get_object(); - ERR_FAIL_COND(!object); - object->connections.erase(slot->cE); + + target_object->connections.erase(slot->cE); s->slot_map.erase(p_callable); if (s->slot_map.empty() && ClassDB::has_signal(get_class_name(), p_signal)) { @@ -1663,7 +1669,7 @@ void Object::_bind_methods() { { MethodInfo mi; mi.name = "emit_signal"; - mi.arguments.push_back(PropertyInfo(Variant::STRING, "signal")); + mi.arguments.push_back(PropertyInfo(Variant::STRING_NAME, "signal")); ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "emit_signal", &Object::_emit_signal, mi, varray(), false); } @@ -1671,7 +1677,7 @@ void Object::_bind_methods() { { MethodInfo mi; mi.name = "call"; - mi.arguments.push_back(PropertyInfo(Variant::STRING, "method")); + mi.arguments.push_back(PropertyInfo(Variant::STRING_NAME, "method")); ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "call", &Object::_call_bind, mi); } @@ -1679,7 +1685,7 @@ void Object::_bind_methods() { { MethodInfo mi; mi.name = "call_deferred"; - mi.arguments.push_back(PropertyInfo(Variant::STRING, "method")); + mi.arguments.push_back(PropertyInfo(Variant::STRING_NAME, "method")); ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "call_deferred", &Object::_call_deferred_bind, mi, varray(), false); } @@ -1713,9 +1719,9 @@ void Object::_bind_methods() { ADD_SIGNAL(MethodInfo("script_changed")); BIND_VMETHOD(MethodInfo("_notification", PropertyInfo(Variant::INT, "what"))); - BIND_VMETHOD(MethodInfo(Variant::BOOL, "_set", PropertyInfo(Variant::STRING, "property"), PropertyInfo(Variant::NIL, "value"))); + BIND_VMETHOD(MethodInfo(Variant::BOOL, "_set", PropertyInfo(Variant::STRING_NAME, "property"), PropertyInfo(Variant::NIL, "value"))); #ifdef TOOLS_ENABLED - MethodInfo miget("_get", PropertyInfo(Variant::STRING, "property")); + MethodInfo miget("_get", PropertyInfo(Variant::STRING_NAME, "property")); miget.return_val.name = "Variant"; miget.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT; BIND_VMETHOD(miget); diff --git a/core/os/input_event.cpp b/core/os/input_event.cpp index 2e863c9c76..3cb9c2c1c2 100644 --- a/core/os/input_event.cpp +++ b/core/os/input_event.cpp @@ -541,7 +541,7 @@ void InputEventMouseButton::_bind_methods() { ClassDB::bind_method(D_METHOD("set_doubleclick", "doubleclick"), &InputEventMouseButton::set_doubleclick); ClassDB::bind_method(D_METHOD("is_doubleclick"), &InputEventMouseButton::is_doubleclick); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "factor"), "set_factor", "get_factor"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "factor"), "set_factor", "get_factor"); ADD_PROPERTY(PropertyInfo(Variant::INT, "button_index"), "set_button_index", "get_button_index"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "doubleclick"), "set_doubleclick", "is_doubleclick"); @@ -702,7 +702,7 @@ void InputEventMouseMotion::_bind_methods() { ClassDB::bind_method(D_METHOD("get_speed"), &InputEventMouseMotion::get_speed); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "tilt"), "set_tilt", "get_tilt"); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "pressure"), "set_pressure", "get_pressure"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "pressure"), "set_pressure", "get_pressure"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "relative"), "set_relative", "get_relative"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "speed"), "set_speed", "get_speed"); } @@ -780,7 +780,7 @@ void InputEventJoypadMotion::_bind_methods() { ClassDB::bind_method(D_METHOD("get_axis_value"), &InputEventJoypadMotion::get_axis_value); ADD_PROPERTY(PropertyInfo(Variant::INT, "axis"), "set_axis", "get_axis"); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "axis_value"), "set_axis_value", "get_axis_value"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "axis_value"), "set_axis_value", "get_axis_value"); } InputEventJoypadMotion::InputEventJoypadMotion() { @@ -861,7 +861,7 @@ void InputEventJoypadButton::_bind_methods() { // ClassDB::bind_method(D_METHOD("is_pressed"), &InputEventJoypadButton::is_pressed); ADD_PROPERTY(PropertyInfo(Variant::INT, "button_index"), "set_button_index", "get_button_index"); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "pressure"), "set_pressure", "get_pressure"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "pressure"), "set_pressure", "get_pressure"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed"); } @@ -1098,9 +1098,9 @@ void InputEventAction::_bind_methods() { // ClassDB::bind_method(D_METHOD("is_action", "name"), &InputEventAction::is_action); - ADD_PROPERTY(PropertyInfo(Variant::STRING, "action"), "set_action", "get_action"); + ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "action"), "set_action", "get_action"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed"); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "strength", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_strength", "get_strength"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "strength", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_strength", "get_strength"); } InputEventAction::InputEventAction() { @@ -1162,7 +1162,7 @@ void InputEventMagnifyGesture::_bind_methods() { ClassDB::bind_method(D_METHOD("set_factor", "factor"), &InputEventMagnifyGesture::set_factor); ClassDB::bind_method(D_METHOD("get_factor"), &InputEventMagnifyGesture::get_factor); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "factor"), "set_factor", "get_factor"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "factor"), "set_factor", "get_factor"); } InputEventMagnifyGesture::InputEventMagnifyGesture() { diff --git a/core/os/main_loop.cpp b/core/os/main_loop.cpp index 61bcb7dd32..ab43ce4af7 100644 --- a/core/os/main_loop.cpp +++ b/core/os/main_loop.cpp @@ -44,8 +44,8 @@ void MainLoop::_bind_methods() { BIND_VMETHOD(MethodInfo("_input_event", PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent"))); BIND_VMETHOD(MethodInfo("_input_text", PropertyInfo(Variant::STRING, "text"))); BIND_VMETHOD(MethodInfo("_initialize")); - BIND_VMETHOD(MethodInfo(Variant::BOOL, "_iteration", PropertyInfo(Variant::REAL, "delta"))); - BIND_VMETHOD(MethodInfo(Variant::BOOL, "_idle", PropertyInfo(Variant::REAL, "delta"))); + BIND_VMETHOD(MethodInfo(Variant::BOOL, "_iteration", PropertyInfo(Variant::FLOAT, "delta"))); + BIND_VMETHOD(MethodInfo(Variant::BOOL, "_idle", PropertyInfo(Variant::FLOAT, "delta"))); BIND_VMETHOD(MethodInfo("_drop_files", PropertyInfo(Variant::PACKED_STRING_ARRAY, "files"), PropertyInfo(Variant::INT, "from_screen"))); BIND_VMETHOD(MethodInfo("_finalize")); diff --git a/core/packed_data_container.cpp b/core/packed_data_container.cpp index ae5f89e870..b82a366ef2 100644 --- a/core/packed_data_container.cpp +++ b/core/packed_data_container.cpp @@ -225,12 +225,12 @@ uint32_t PackedDataContainer::_pack(const Variant &p_data, Vector<uint8_t> &tmpd string_cache[s] = tmpdata.size(); - FALLTHROUGH; - }; + [[fallthrough]]; + } case Variant::NIL: case Variant::BOOL: case Variant::INT: - case Variant::REAL: + case Variant::FLOAT: case Variant::VECTOR2: case Variant::RECT2: case Variant::VECTOR3: @@ -241,12 +241,15 @@ uint32_t PackedDataContainer::_pack(const Variant &p_data, Vector<uint8_t> &tmpd case Variant::BASIS: case Variant::TRANSFORM: case Variant::PACKED_BYTE_ARRAY: - case Variant::PACKED_INT_ARRAY: - case Variant::PACKED_REAL_ARRAY: + case Variant::PACKED_INT32_ARRAY: + case Variant::PACKED_INT64_ARRAY: + case Variant::PACKED_FLOAT32_ARRAY: + case Variant::PACKED_FLOAT64_ARRAY: case Variant::PACKED_STRING_ARRAY: case Variant::PACKED_VECTOR2_ARRAY: case Variant::PACKED_VECTOR3_ARRAY: case Variant::PACKED_COLOR_ARRAY: + case Variant::STRING_NAME: case Variant::NODE_PATH: { uint32_t pos = tmpdata.size(); diff --git a/core/resource.cpp b/core/resource.cpp index 30e09716aa..2afc9e4042 100644 --- a/core/resource.cpp +++ b/core/resource.cpp @@ -423,7 +423,7 @@ void Resource::_bind_methods() { ADD_GROUP("Resource", "resource_"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "resource_local_to_scene"), "set_local_to_scene", "is_local_to_scene"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "resource_path", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "set_path", "get_path"); - ADD_PROPERTY(PropertyInfo(Variant::STRING, "resource_name"), "set_name", "get_name"); + ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "resource_name"), "set_name", "get_name"); BIND_VMETHOD(MethodInfo("_setup_local_to_scene")); } diff --git a/core/type_info.h b/core/type_info.h index 8e86567f51..5dacf67de4 100644 --- a/core/type_info.h +++ b/core/type_info.h @@ -137,8 +137,8 @@ MAKE_TYPE_INFO_WITH_META(int32_t, Variant::INT, GodotTypeInfo::METADATA_INT_IS_I MAKE_TYPE_INFO_WITH_META(uint64_t, Variant::INT, GodotTypeInfo::METADATA_INT_IS_UINT64) MAKE_TYPE_INFO_WITH_META(int64_t, Variant::INT, GodotTypeInfo::METADATA_INT_IS_INT64) MAKE_TYPE_INFO(wchar_t, Variant::INT) -MAKE_TYPE_INFO_WITH_META(float, Variant::REAL, GodotTypeInfo::METADATA_REAL_IS_FLOAT) -MAKE_TYPE_INFO_WITH_META(double, Variant::REAL, GodotTypeInfo::METADATA_REAL_IS_DOUBLE) +MAKE_TYPE_INFO_WITH_META(float, Variant::FLOAT, GodotTypeInfo::METADATA_REAL_IS_FLOAT) +MAKE_TYPE_INFO_WITH_META(double, Variant::FLOAT, GodotTypeInfo::METADATA_REAL_IS_DOUBLE) MAKE_TYPE_INFO(String, Variant::STRING) MAKE_TYPE_INFO(Vector2, Variant::VECTOR2) @@ -151,6 +151,7 @@ MAKE_TYPE_INFO(AABB, Variant::AABB) MAKE_TYPE_INFO(Basis, Variant::BASIS) MAKE_TYPE_INFO(Transform, Variant::TRANSFORM) MAKE_TYPE_INFO(Color, Variant::COLOR) +MAKE_TYPE_INFO(StringName, Variant::STRING_NAME) MAKE_TYPE_INFO(NodePath, Variant::NODE_PATH) MAKE_TYPE_INFO(RID, Variant::_RID) MAKE_TYPE_INFO(Callable, Variant::CALLABLE) @@ -158,14 +159,15 @@ MAKE_TYPE_INFO(Signal, Variant::SIGNAL) MAKE_TYPE_INFO(Dictionary, Variant::DICTIONARY) MAKE_TYPE_INFO(Array, Variant::ARRAY) MAKE_TYPE_INFO(PackedByteArray, Variant::PACKED_BYTE_ARRAY) -MAKE_TYPE_INFO(PackedIntArray, Variant::PACKED_INT_ARRAY) -MAKE_TYPE_INFO(PackedRealArray, Variant::PACKED_REAL_ARRAY) +MAKE_TYPE_INFO(PackedInt32Array, Variant::PACKED_INT32_ARRAY) +MAKE_TYPE_INFO(PackedInt64Array, Variant::PACKED_INT64_ARRAY) +MAKE_TYPE_INFO(PackedFloat32Array, Variant::PACKED_FLOAT32_ARRAY) +MAKE_TYPE_INFO(PackedFloat64Array, Variant::PACKED_FLOAT64_ARRAY) MAKE_TYPE_INFO(PackedStringArray, Variant::PACKED_STRING_ARRAY) MAKE_TYPE_INFO(PackedVector2Array, Variant::PACKED_VECTOR2_ARRAY) MAKE_TYPE_INFO(PackedVector3Array, Variant::PACKED_VECTOR3_ARRAY) MAKE_TYPE_INFO(PackedColorArray, Variant::PACKED_COLOR_ARRAY) -MAKE_TYPE_INFO(StringName, Variant::STRING) MAKE_TYPE_INFO(IP_Address, Variant::STRING) //objectID @@ -221,20 +223,6 @@ MAKE_TEMPLATE_TYPE_INFO(Vector, Plane, Variant::ARRAY) MAKE_TEMPLATE_TYPE_INFO(Vector, Face3, Variant::PACKED_VECTOR3_ARRAY) MAKE_TEMPLATE_TYPE_INFO(Vector, StringName, Variant::PACKED_STRING_ARRAY) -/* -MAKE_TEMPLATE_TYPE_INFO(Vector, uint8_t, Variant::PACKED_BYTE_ARRAY) -MAKE_TEMPLATE_TYPE_INFO(Vector, int, Variant::PACKED_INT_ARRAY) -MAKE_TEMPLATE_TYPE_INFO(Vector, float, Variant::PACKED_REAL_ARRAY) -MAKE_TEMPLATE_TYPE_INFO(Vector, String, Variant::PACKED_STRING_ARRAY) -MAKE_TEMPLATE_TYPE_INFO(Vector, Vector2, Variant::PACKED_VECTOR2_ARRAY) -MAKE_TEMPLATE_TYPE_INFO(Vector, Vector3, Variant::PACKED_VECTOR3_ARRAY) -MAKE_TEMPLATE_TYPE_INFO(Vector, Color, Variant::PACKED_COLOR_ARRAY) - - -MAKE_TEMPLATE_TYPE_INFO(Vector, Plane, Variant::ARRAY) -MAKE_TEMPLATE_TYPE_INFO(Vector, Face3, Variant::PACKED_VECTOR3_ARRAY) -*/ - template <typename T> struct GetTypeInfo<T *, typename EnableIf<TypeInherits<Object, T>::value>::type> { static const Variant::Type VARIANT_TYPE = Variant::OBJECT; diff --git a/core/typedefs.h b/core/typedefs.h index 0bb80cb2dd..5376b0718a 100644 --- a/core/typedefs.h +++ b/core/typedefs.h @@ -335,26 +335,16 @@ struct _GlobalLock { */ #define CAST_INT_TO_UCHAR_PTR(ptr) ((uint8_t *)(uintptr_t)(ptr)) -/** Hint for compilers that this fallthrough in a switch is intentional. - * Can be replaced by [[fallthrough]] annotation if we move to C++17. - * Including conditional support for it for people who set -std=c++17 - * themselves. - * Requires a trailing semicolon when used. - */ -#if __cplusplus >= 201703L -#define FALLTHROUGH [[fallthrough]] -#elif defined(__GNUC__) && __GNUC__ >= 7 -#define FALLTHROUGH __attribute__((fallthrough)) -#elif defined(__llvm__) && __cplusplus >= 201103L && defined(__has_feature) -#if __has_feature(cxx_attributes) && defined(__has_warning) -#if __has_warning("-Wimplicit-fallthrough") -#define FALLTHROUGH [[clang::fallthrough]] -#endif -#endif -#endif +// Home-made index sequence trick, so it can be used everywhere without the costly include of std::tuple. +// https://stackoverflow.com/questions/15014096/c-index-of-type-during-variadic-template-expansion -#ifndef FALLTHROUGH -#define FALLTHROUGH -#endif +template <size_t... Is> +struct IndexSequence {}; + +template <size_t N, size_t... Is> +struct BuildIndexSequence : BuildIndexSequence<N - 1, N - 1, Is...> {}; + +template <size_t... Is> +struct BuildIndexSequence<0, Is...> : IndexSequence<Is...> {}; #endif // TYPEDEFS_H diff --git a/core/undo_redo.cpp b/core/undo_redo.cpp index 0eef75d587..02f460c93d 100644 --- a/core/undo_redo.cpp +++ b/core/undo_redo.cpp @@ -105,7 +105,7 @@ void UndoRedo::create_action(const String &p_name, MergeMode p_mode) { action_level++; } -void UndoRedo::add_do_method(Object *p_object, const String &p_method, VARIANT_ARG_DECLARE) { +void UndoRedo::add_do_method(Object *p_object, const StringName &p_method, VARIANT_ARG_DECLARE) { VARIANT_ARGPTRS ERR_FAIL_COND(p_object == NULL); @@ -125,7 +125,7 @@ void UndoRedo::add_do_method(Object *p_object, const String &p_method, VARIANT_A actions.write[current_action + 1].do_ops.push_back(do_op); } -void UndoRedo::add_undo_method(Object *p_object, const String &p_method, VARIANT_ARG_DECLARE) { +void UndoRedo::add_undo_method(Object *p_object, const StringName &p_method, VARIANT_ARG_DECLARE) { VARIANT_ARGPTRS ERR_FAIL_COND(p_object == NULL); @@ -149,7 +149,7 @@ void UndoRedo::add_undo_method(Object *p_object, const String &p_method, VARIANT } actions.write[current_action + 1].undo_ops.push_back(undo_op); } -void UndoRedo::add_do_property(Object *p_object, const String &p_property, const Variant &p_value) { +void UndoRedo::add_do_property(Object *p_object, const StringName &p_property, const Variant &p_value) { ERR_FAIL_COND(p_object == NULL); ERR_FAIL_COND(action_level <= 0); @@ -164,7 +164,7 @@ void UndoRedo::add_do_property(Object *p_object, const String &p_property, const do_op.args[0] = p_value; actions.write[current_action + 1].do_ops.push_back(do_op); } -void UndoRedo::add_undo_property(Object *p_object, const String &p_property, const Variant &p_value) { +void UndoRedo::add_undo_property(Object *p_object, const StringName &p_property, const Variant &p_value) { ERR_FAIL_COND(p_object == NULL); ERR_FAIL_COND(action_level <= 0); @@ -446,17 +446,17 @@ Variant UndoRedo::_add_do_method(const Variant **p_args, int p_argcount, Callabl return Variant(); } - if (p_args[1]->get_type() != Variant::STRING) { + if (p_args[1]->get_type() != Variant::STRING_NAME && p_args[1]->get_type() != Variant::STRING) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 1; - r_error.expected = Variant::STRING; + r_error.expected = Variant::STRING_NAME; return Variant(); } r_error.error = Callable::CallError::CALL_OK; Object *object = *p_args[0]; - String method = *p_args[1]; + StringName method = *p_args[1]; Variant v[VARIANT_ARG_MAX]; @@ -484,17 +484,17 @@ Variant UndoRedo::_add_undo_method(const Variant **p_args, int p_argcount, Calla return Variant(); } - if (p_args[1]->get_type() != Variant::STRING) { + if (p_args[1]->get_type() != Variant::STRING_NAME && p_args[1]->get_type() != Variant::STRING) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 1; - r_error.expected = Variant::STRING; + r_error.expected = Variant::STRING_NAME; return Variant(); } r_error.error = Callable::CallError::CALL_OK; Object *object = *p_args[0]; - String method = *p_args[1]; + StringName method = *p_args[1]; Variant v[VARIANT_ARG_MAX]; @@ -518,7 +518,7 @@ void UndoRedo::_bind_methods() { MethodInfo mi; mi.name = "add_do_method"; mi.arguments.push_back(PropertyInfo(Variant::OBJECT, "object")); - mi.arguments.push_back(PropertyInfo(Variant::STRING, "method")); + mi.arguments.push_back(PropertyInfo(Variant::STRING_NAME, "method")); ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "add_do_method", &UndoRedo::_add_do_method, mi, varray(), false); } @@ -527,7 +527,7 @@ void UndoRedo::_bind_methods() { MethodInfo mi; mi.name = "add_undo_method"; mi.arguments.push_back(PropertyInfo(Variant::OBJECT, "object")); - mi.arguments.push_back(PropertyInfo(Variant::STRING, "method")); + mi.arguments.push_back(PropertyInfo(Variant::STRING_NAME, "method")); ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "add_undo_method", &UndoRedo::_add_undo_method, mi, varray(), false); } diff --git a/core/undo_redo.h b/core/undo_redo.h index e707979291..3b91e9ce36 100644 --- a/core/undo_redo.h +++ b/core/undo_redo.h @@ -65,7 +65,7 @@ private: Type type; Ref<Resource> resref; ObjectID object; - String name; + StringName name; Variant args[VARIANT_ARG_MAX]; }; @@ -103,10 +103,10 @@ protected: public: void create_action(const String &p_name = "", MergeMode p_mode = MERGE_DISABLE); - void add_do_method(Object *p_object, const String &p_method, VARIANT_ARG_LIST); - void add_undo_method(Object *p_object, const String &p_method, VARIANT_ARG_LIST); - void add_do_property(Object *p_object, const String &p_property, const Variant &p_value); - void add_undo_property(Object *p_object, const String &p_property, const Variant &p_value); + void add_do_method(Object *p_object, const StringName &p_method, VARIANT_ARG_LIST); + void add_undo_method(Object *p_object, const StringName &p_method, VARIANT_ARG_LIST); + void add_do_property(Object *p_object, const StringName &p_property, const Variant &p_value); + void add_undo_property(Object *p_object, const StringName &p_property, const Variant &p_value); void add_do_reference(Object *p_object); void add_undo_reference(Object *p_object); diff --git a/core/ustring.cpp b/core/ustring.cpp index c4543b89da..1d4d9c2dfd 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -2169,6 +2169,7 @@ int64_t String::to_int(const CharType *p_str, int p_len) { } else { break; } + [[fallthrough]]; } case READING_INT: { diff --git a/core/variant.cpp b/core/variant.cpp index cdc9e47fc8..7bdaab8fa8 100644 --- a/core/variant.cpp +++ b/core/variant.cpp @@ -57,7 +57,7 @@ String Variant::get_type_name(Variant::Type p_type) { return "int"; } break; - case REAL: { + case FLOAT: { return "float"; @@ -72,10 +72,18 @@ String Variant::get_type_name(Variant::Type p_type) { return "Vector2"; } break; + case VECTOR2I: { + + return "Vector2i"; + } break; case RECT2: { return "Rect2"; } break; + case RECT2I: { + + return "Rect2i"; + } break; case TRANSFORM2D: { return "Transform2D"; @@ -84,6 +92,10 @@ String Variant::get_type_name(Variant::Type p_type) { return "Vector3"; } break; + case VECTOR3I: { + + return "Vector3i"; + } break; case PLANE: { return "Plane"; @@ -136,6 +148,11 @@ String Variant::get_type_name(Variant::Type p_type) { return "Signal"; } break; + case STRING_NAME: { + + return "StringName"; + + } break; case NODE_PATH: { return "NodePath"; @@ -158,14 +175,24 @@ String Variant::get_type_name(Variant::Type p_type) { return "PackedByteArray"; } break; - case PACKED_INT_ARRAY: { + case PACKED_INT32_ARRAY: { + + return "PackedInt32Array"; + + } break; + case PACKED_INT64_ARRAY: { + + return "PackedInt64Array"; + + } break; + case PACKED_FLOAT32_ARRAY: { - return "PackedIntArray"; + return "PackedFloat32Array"; } break; - case PACKED_REAL_ARRAY: { + case PACKED_FLOAT64_ARRAY: { - return "PackedRealArray"; + return "PackedFloat64Array"; } break; case PACKED_STRING_ARRAY: { @@ -213,7 +240,7 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) { static const Type valid[] = { INT, - REAL, + FLOAT, STRING, NIL, }; @@ -224,7 +251,7 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) { static const Type valid[] = { BOOL, - REAL, + FLOAT, STRING, NIL, }; @@ -232,7 +259,7 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) { valid_types = valid; } break; - case REAL: { + case FLOAT: { static const Type valid[] = { BOOL, @@ -253,6 +280,46 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) { invalid_types = invalid; } break; + case VECTOR2: { + + static const Type valid[] = { + VECTOR2I, + NIL, + }; + + valid_types = valid; + + } break; + case VECTOR2I: { + + static const Type valid[] = { + VECTOR2, + NIL, + }; + + valid_types = valid; + + } break; + case RECT2: { + + static const Type valid[] = { + RECT2I, + NIL, + }; + + valid_types = valid; + + } break; + case RECT2I: { + + static const Type valid[] = { + RECT2, + NIL, + }; + + valid_types = valid; + + } break; case TRANSFORM2D: { static const Type valid[] = { @@ -262,6 +329,27 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) { valid_types = valid; } break; + case VECTOR3: { + + static const Type valid[] = { + VECTOR3I, + NIL, + }; + + valid_types = valid; + + } break; + case VECTOR3I: { + + static const Type valid[] = { + VECTOR3, + NIL, + }; + + valid_types = valid; + + } break; + case QUAT: { static const Type valid[] = { @@ -325,6 +413,15 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) { valid_types = valid; } break; + case STRING_NAME: { + + static const Type valid[] = { + STRING, + NIL + }; + + valid_types = valid; + } break; case NODE_PATH: { static const Type valid[] = { @@ -338,9 +435,11 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) { static const Type valid[] = { PACKED_BYTE_ARRAY, - PACKED_INT_ARRAY, + PACKED_INT32_ARRAY, + PACKED_INT64_ARRAY, + PACKED_FLOAT32_ARRAY, + PACKED_FLOAT64_ARRAY, PACKED_STRING_ARRAY, - PACKED_REAL_ARRAY, PACKED_COLOR_ARRAY, PACKED_VECTOR2_ARRAY, PACKED_VECTOR3_ARRAY, @@ -359,15 +458,32 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) { valid_types = valid; } break; - case PACKED_INT_ARRAY: { + case PACKED_INT32_ARRAY: { + + static const Type valid[] = { + ARRAY, + NIL + }; + valid_types = valid; + } break; + case PACKED_INT64_ARRAY: { + + static const Type valid[] = { + ARRAY, + NIL + }; + valid_types = valid; + } break; + case PACKED_FLOAT32_ARRAY: { static const Type valid[] = { ARRAY, NIL }; + valid_types = valid; } break; - case PACKED_REAL_ARRAY: { + case PACKED_FLOAT64_ARRAY: { static const Type valid[] = { ARRAY, @@ -460,7 +576,7 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type static const Type valid[] = { INT, - REAL, + FLOAT, //STRING, NIL, }; @@ -471,7 +587,7 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type static const Type valid[] = { BOOL, - REAL, + FLOAT, //STRING, NIL, }; @@ -479,7 +595,7 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type valid_types = valid; } break; - case REAL: { + case FLOAT: { static const Type valid[] = { BOOL, @@ -495,11 +611,52 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type static const Type valid[] = { NODE_PATH, + STRING_NAME, NIL }; valid_types = valid; } break; + case VECTOR2: { + + static const Type valid[] = { + VECTOR2I, + NIL, + }; + + valid_types = valid; + + } break; + case VECTOR2I: { + + static const Type valid[] = { + VECTOR2, + NIL, + }; + + valid_types = valid; + + } break; + case RECT2: { + + static const Type valid[] = { + RECT2I, + NIL, + }; + + valid_types = valid; + + } break; + case RECT2I: { + + static const Type valid[] = { + RECT2, + NIL, + }; + + valid_types = valid; + + } break; case TRANSFORM2D: { static const Type valid[] = { @@ -509,6 +666,27 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type valid_types = valid; } break; + case VECTOR3: { + + static const Type valid[] = { + VECTOR3I, + NIL, + }; + + valid_types = valid; + + } break; + case VECTOR3I: { + + static const Type valid[] = { + VECTOR3, + NIL, + }; + + valid_types = valid; + + } break; + case QUAT: { static const Type valid[] = { @@ -572,6 +750,15 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type valid_types = valid; } break; + case STRING_NAME: { + + static const Type valid[] = { + STRING, + NIL + }; + + valid_types = valid; + } break; case NODE_PATH: { static const Type valid[] = { @@ -585,9 +772,11 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type static const Type valid[] = { PACKED_BYTE_ARRAY, - PACKED_INT_ARRAY, + PACKED_INT32_ARRAY, + PACKED_INT64_ARRAY, + PACKED_FLOAT32_ARRAY, + PACKED_FLOAT64_ARRAY, PACKED_STRING_ARRAY, - PACKED_REAL_ARRAY, PACKED_COLOR_ARRAY, PACKED_VECTOR2_ARRAY, PACKED_VECTOR3_ARRAY, @@ -606,7 +795,7 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type valid_types = valid; } break; - case PACKED_INT_ARRAY: { + case PACKED_INT32_ARRAY: { static const Type valid[] = { ARRAY, @@ -614,7 +803,24 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type }; valid_types = valid; } break; - case PACKED_REAL_ARRAY: { + case PACKED_INT64_ARRAY: { + + static const Type valid[] = { + ARRAY, + NIL + }; + valid_types = valid; + } break; + case PACKED_FLOAT32_ARRAY: { + + static const Type valid[] = { + ARRAY, + NIL + }; + + valid_types = valid; + } break; + case PACKED_FLOAT64_ARRAY: { static const Type valid[] = { ARRAY, @@ -724,9 +930,9 @@ bool Variant::is_zero() const { return _data._int == 0; } break; - case REAL: { + case FLOAT: { - return _data._real == 0; + return _data._float == 0; } break; case STRING: { @@ -741,11 +947,21 @@ bool Variant::is_zero() const { return *reinterpret_cast<const Vector2 *>(_data._mem) == Vector2(); } break; + case VECTOR2I: { + + return *reinterpret_cast<const Vector2i *>(_data._mem) == Vector2i(); + + } break; case RECT2: { return *reinterpret_cast<const Rect2 *>(_data._mem) == Rect2(); } break; + case RECT2I: { + + return *reinterpret_cast<const Rect2i *>(_data._mem) == Rect2i(); + + } break; case TRANSFORM2D: { return *_data._transform2d == Transform2D(); @@ -756,6 +972,11 @@ bool Variant::is_zero() const { return *reinterpret_cast<const Vector3 *>(_data._mem) == Vector3(); } break; + case VECTOR3I: { + + return *reinterpret_cast<const Vector3i *>(_data._mem) == Vector3i(); + + } break; case PLANE: { return *reinterpret_cast<const Plane *>(_data._mem) == Plane(); @@ -808,6 +1029,11 @@ bool Variant::is_zero() const { return reinterpret_cast<const Signal *>(_data._mem)->is_null(); } break; + case STRING_NAME: { + + return *reinterpret_cast<const StringName *>(_data._mem) != StringName(); + + } break; case NODE_PATH: { return reinterpret_cast<const NodePath *>(_data._mem)->is_empty(); @@ -827,37 +1053,47 @@ bool Variant::is_zero() const { // arrays case PACKED_BYTE_ARRAY: { - return reinterpret_cast<const Vector<uint8_t> *>(_data._mem)->size() == 0; + return PackedArrayRef<uint8_t>::get_array(_data.packed_array).size() == 0; + + } break; + case PACKED_INT32_ARRAY: { + + return PackedArrayRef<int32_t>::get_array(_data.packed_array).size() == 0; + + } break; + case PACKED_INT64_ARRAY: { + + return PackedArrayRef<int64_t>::get_array(_data.packed_array).size() == 0; } break; - case PACKED_INT_ARRAY: { + case PACKED_FLOAT32_ARRAY: { - return reinterpret_cast<const Vector<int> *>(_data._mem)->size() == 0; + return PackedArrayRef<float>::get_array(_data.packed_array).size() == 0; } break; - case PACKED_REAL_ARRAY: { + case PACKED_FLOAT64_ARRAY: { - return reinterpret_cast<const Vector<real_t> *>(_data._mem)->size() == 0; + return PackedArrayRef<double>::get_array(_data.packed_array).size() == 0; } break; case PACKED_STRING_ARRAY: { - return reinterpret_cast<const Vector<String> *>(_data._mem)->size() == 0; + return PackedArrayRef<String>::get_array(_data.packed_array).size() == 0; } break; case PACKED_VECTOR2_ARRAY: { - return reinterpret_cast<const Vector<Vector2> *>(_data._mem)->size() == 0; + return PackedArrayRef<Vector2>::get_array(_data.packed_array).size() == 0; } break; case PACKED_VECTOR3_ARRAY: { - return reinterpret_cast<const Vector<Vector3> *>(_data._mem)->size() == 0; + return PackedArrayRef<Vector3>::get_array(_data.packed_array).size() == 0; } break; case PACKED_COLOR_ARRAY: { - return reinterpret_cast<const Vector<Color> *>(_data._mem)->size() == 0; + return PackedArrayRef<Color>::get_array(_data.packed_array).size() == 0; } break; default: { @@ -885,9 +1121,9 @@ bool Variant::is_one() const { return _data._int == 1; } break; - case REAL: { + case FLOAT: { - return _data._real == 1; + return _data._float == 1; } break; case VECTOR2: { @@ -895,16 +1131,31 @@ bool Variant::is_one() const { return *reinterpret_cast<const Vector2 *>(_data._mem) == Vector2(1, 1); } break; + case VECTOR2I: { + + return *reinterpret_cast<const Vector2i *>(_data._mem) == Vector2i(1, 1); + + } break; case RECT2: { return *reinterpret_cast<const Rect2 *>(_data._mem) == Rect2(1, 1, 1, 1); } break; + case RECT2I: { + + return *reinterpret_cast<const Rect2i *>(_data._mem) == Rect2i(1, 1, 1, 1); + + } break; case VECTOR3: { return *reinterpret_cast<const Vector3 *>(_data._mem) == Vector3(1, 1, 1); } break; + case VECTOR3I: { + + return *reinterpret_cast<const Vector3i *>(_data._mem) == Vector3i(1, 1, 1); + + } break; case PLANE: { return *reinterpret_cast<const Plane *>(_data._mem) == Plane(1, 1, 1, 1); @@ -938,7 +1189,7 @@ void Variant::reference(const Variant &p_variant) { case NIL: case BOOL: case INT: - case REAL: + case FLOAT: break; default: clear(); @@ -961,9 +1212,9 @@ void Variant::reference(const Variant &p_variant) { _data._int = p_variant._data._int; } break; - case REAL: { + case FLOAT: { - _data._real = p_variant._data._real; + _data._float = p_variant._data._float; } break; case STRING: { @@ -975,10 +1226,18 @@ void Variant::reference(const Variant &p_variant) { memnew_placement(_data._mem, Vector2(*reinterpret_cast<const Vector2 *>(p_variant._data._mem))); } break; + case VECTOR2I: { + + memnew_placement(_data._mem, Vector2i(*reinterpret_cast<const Vector2i *>(p_variant._data._mem))); + } break; case RECT2: { memnew_placement(_data._mem, Rect2(*reinterpret_cast<const Rect2 *>(p_variant._data._mem))); } break; + case RECT2I: { + + memnew_placement(_data._mem, Rect2i(*reinterpret_cast<const Rect2i *>(p_variant._data._mem))); + } break; case TRANSFORM2D: { _data._transform2d = memnew(Transform2D(*p_variant._data._transform2d)); @@ -987,6 +1246,10 @@ void Variant::reference(const Variant &p_variant) { memnew_placement(_data._mem, Vector3(*reinterpret_cast<const Vector3 *>(p_variant._data._mem))); } break; + case VECTOR3I: { + + memnew_placement(_data._mem, Vector3i(*reinterpret_cast<const Vector3i *>(p_variant._data._mem))); + } break; case PLANE: { memnew_placement(_data._mem, Plane(*reinterpret_cast<const Plane *>(p_variant._data._mem))); @@ -1046,6 +1309,11 @@ void Variant::reference(const Variant &p_variant) { memnew_placement(_data._mem, Signal(*reinterpret_cast<const Signal *>(p_variant._data._mem))); } break; + case STRING_NAME: { + + memnew_placement(_data._mem, StringName(*reinterpret_cast<const StringName *>(p_variant._data._mem))); + + } break; case NODE_PATH: { memnew_placement(_data._mem, NodePath(*reinterpret_cast<const NodePath *>(p_variant._data._mem))); @@ -1065,37 +1333,74 @@ void Variant::reference(const Variant &p_variant) { // arrays case PACKED_BYTE_ARRAY: { - memnew_placement(_data._mem, Vector<uint8_t>(*reinterpret_cast<const Vector<uint8_t> *>(p_variant._data._mem))); + _data.packed_array = static_cast<PackedArrayRef<uint8_t> *>(p_variant._data.packed_array)->reference(); + if (!_data.packed_array) { + _data.packed_array = PackedArrayRef<uint8_t>::create(); + } } break; - case PACKED_INT_ARRAY: { + case PACKED_INT32_ARRAY: { - memnew_placement(_data._mem, Vector<int>(*reinterpret_cast<const Vector<int> *>(p_variant._data._mem))); + _data.packed_array = static_cast<PackedArrayRef<int32_t> *>(p_variant._data.packed_array)->reference(); + if (!_data.packed_array) { + _data.packed_array = PackedArrayRef<int32_t>::create(); + } } break; - case PACKED_REAL_ARRAY: { + case PACKED_INT64_ARRAY: { - memnew_placement(_data._mem, Vector<real_t>(*reinterpret_cast<const Vector<real_t> *>(p_variant._data._mem))); + _data.packed_array = static_cast<PackedArrayRef<int64_t> *>(p_variant._data.packed_array)->reference(); + if (!_data.packed_array) { + _data.packed_array = PackedArrayRef<int64_t>::create(); + } + + } break; + case PACKED_FLOAT32_ARRAY: { + + _data.packed_array = static_cast<PackedArrayRef<float> *>(p_variant._data.packed_array)->reference(); + if (!_data.packed_array) { + _data.packed_array = PackedArrayRef<float>::create(); + } + + } break; + case PACKED_FLOAT64_ARRAY: { + + _data.packed_array = static_cast<PackedArrayRef<double> *>(p_variant._data.packed_array)->reference(); + if (!_data.packed_array) { + _data.packed_array = PackedArrayRef<double>::create(); + } } break; case PACKED_STRING_ARRAY: { - memnew_placement(_data._mem, Vector<String>(*reinterpret_cast<const Vector<String> *>(p_variant._data._mem))); + _data.packed_array = static_cast<PackedArrayRef<String> *>(p_variant._data.packed_array)->reference(); + if (!_data.packed_array) { + _data.packed_array = PackedArrayRef<String>::create(); + } } break; case PACKED_VECTOR2_ARRAY: { - memnew_placement(_data._mem, Vector<Vector2>(*reinterpret_cast<const Vector<Vector2> *>(p_variant._data._mem))); + _data.packed_array = static_cast<PackedArrayRef<Vector2> *>(p_variant._data.packed_array)->reference(); + if (!_data.packed_array) { + _data.packed_array = PackedArrayRef<Vector2>::create(); + } } break; case PACKED_VECTOR3_ARRAY: { - memnew_placement(_data._mem, Vector<Vector3>(*reinterpret_cast<const Vector<Vector3> *>(p_variant._data._mem))); + _data.packed_array = static_cast<PackedArrayRef<Vector3> *>(p_variant._data.packed_array)->reference(); + if (!_data.packed_array) { + _data.packed_array = PackedArrayRef<Vector3>::create(); + } } break; case PACKED_COLOR_ARRAY: { - memnew_placement(_data._mem, Vector<Color>(*reinterpret_cast<const Vector<Color> *>(p_variant._data._mem))); + _data.packed_array = static_cast<PackedArrayRef<Color> *>(p_variant._data.packed_array)->reference(); + if (!_data.packed_array) { + _data.packed_array = PackedArrayRef<Color>::create(); + } } break; default: { @@ -1108,10 +1413,13 @@ void Variant::zero() { case NIL: break; case BOOL: this->_data._bool = false; break; case INT: this->_data._int = 0; break; - case REAL: this->_data._real = 0; break; + case FLOAT: this->_data._float = 0; break; case VECTOR2: *reinterpret_cast<Vector2 *>(this->_data._mem) = Vector2(); break; + case VECTOR2I: *reinterpret_cast<Vector2i *>(this->_data._mem) = Vector2i(); break; case RECT2: *reinterpret_cast<Rect2 *>(this->_data._mem) = Rect2(); break; + case RECT2I: *reinterpret_cast<Rect2i *>(this->_data._mem) = Rect2i(); break; case VECTOR3: *reinterpret_cast<Vector3 *>(this->_data._mem) = Vector3(); break; + case VECTOR3I: *reinterpret_cast<Vector3i *>(this->_data._mem) = Vector3i(); break; case PLANE: *reinterpret_cast<Plane *>(this->_data._mem) = Plane(); break; case QUAT: *reinterpret_cast<Quat *>(this->_data._mem) = Quat(); break; case COLOR: *reinterpret_cast<Color *>(this->_data._mem) = Color(); break; @@ -1152,7 +1460,11 @@ void Variant::clear() { memdelete(_data._transform); } break; - // misc types + // misc types + case STRING_NAME: { + + reinterpret_cast<StringName *>(_data._mem)->~StringName(); + } break; case NODE_PATH: { reinterpret_cast<NodePath *>(_data._mem)->~NodePath(); @@ -1192,31 +1504,39 @@ void Variant::clear() { // arrays case PACKED_BYTE_ARRAY: { - reinterpret_cast<Vector<uint8_t> *>(_data._mem)->~Vector<uint8_t>(); + PackedArrayRefBase::destroy(_data.packed_array); } break; - case PACKED_INT_ARRAY: { + case PACKED_INT32_ARRAY: { - reinterpret_cast<Vector<int> *>(_data._mem)->~Vector<int>(); + PackedArrayRefBase::destroy(_data.packed_array); } break; - case PACKED_REAL_ARRAY: { + case PACKED_INT64_ARRAY: { - reinterpret_cast<Vector<real_t> *>(_data._mem)->~Vector<real_t>(); + PackedArrayRefBase::destroy(_data.packed_array); + } break; + case PACKED_FLOAT32_ARRAY: { + + PackedArrayRefBase::destroy(_data.packed_array); + } break; + case PACKED_FLOAT64_ARRAY: { + + PackedArrayRefBase::destroy(_data.packed_array); } break; case PACKED_STRING_ARRAY: { - reinterpret_cast<Vector<String> *>(_data._mem)->~Vector<String>(); + PackedArrayRefBase::destroy(_data.packed_array); } break; case PACKED_VECTOR2_ARRAY: { - reinterpret_cast<Vector<Vector2> *>(_data._mem)->~Vector<Vector2>(); + PackedArrayRefBase::destroy(_data.packed_array); } break; case PACKED_VECTOR3_ARRAY: { - reinterpret_cast<Vector<Vector3> *>(_data._mem)->~Vector<Vector3>(); + PackedArrayRefBase::destroy(_data.packed_array); } break; case PACKED_COLOR_ARRAY: { - reinterpret_cast<Vector<Color> *>(_data._mem)->~Vector<Color>(); + PackedArrayRefBase::destroy(_data.packed_array); } break; default: { } /* not needed */ @@ -1232,7 +1552,7 @@ Variant::operator signed int() const { case NIL: return 0; case BOOL: return _data._bool ? 1 : 0; case INT: return _data._int; - case REAL: return _data._real; + case FLOAT: return _data._float; case STRING: return operator String().to_int(); default: { @@ -1247,7 +1567,7 @@ Variant::operator unsigned int() const { case NIL: return 0; case BOOL: return _data._bool ? 1 : 0; case INT: return _data._int; - case REAL: return _data._real; + case FLOAT: return _data._float; case STRING: return operator String().to_int(); default: { @@ -1263,7 +1583,7 @@ Variant::operator int64_t() const { case NIL: return 0; case BOOL: return _data._bool ? 1 : 0; case INT: return _data._int; - case REAL: return _data._real; + case FLOAT: return _data._float; case STRING: return operator String().to_int64(); default: { @@ -1280,7 +1600,7 @@ Variant::operator long unsigned int() const { case NIL: return 0; case BOOL: return _data._bool ? 1 : 0; case INT: return _data._int; - case REAL: return _data._real; + case FLOAT: return _data._real; case STRING: return operator String().to_int(); default: { @@ -1299,7 +1619,7 @@ Variant::operator uint64_t() const { case NIL: return 0; case BOOL: return _data._bool ? 1 : 0; case INT: return _data._int; - case REAL: return _data._real; + case FLOAT: return _data._float; case STRING: return operator String().to_int(); default: { @@ -1311,6 +1631,8 @@ Variant::operator uint64_t() const { Variant::operator ObjectID() const { if (type == INT) { return ObjectID(_data._int); + } else if (type == OBJECT) { + return _get_obj().id; } else { return ObjectID(); } @@ -1324,7 +1646,7 @@ Variant::operator signed long() const { case NIL: return 0; case BOOL: return _data._bool ? 1 : 0; case INT: return _data._int; - case REAL: return _data._real; + case FLOAT: return _data._real; case STRING: return operator String().to_int(); default: { @@ -1342,7 +1664,7 @@ Variant::operator unsigned long() const { case NIL: return 0; case BOOL: return _data._bool ? 1 : 0; case INT: return _data._int; - case REAL: return _data._real; + case FLOAT: return _data._real; case STRING: return operator String().to_int(); default: { @@ -1361,7 +1683,7 @@ Variant::operator signed short() const { case NIL: return 0; case BOOL: return _data._bool ? 1 : 0; case INT: return _data._int; - case REAL: return _data._real; + case FLOAT: return _data._float; case STRING: return operator String().to_int(); default: { @@ -1376,7 +1698,7 @@ Variant::operator unsigned short() const { case NIL: return 0; case BOOL: return _data._bool ? 1 : 0; case INT: return _data._int; - case REAL: return _data._real; + case FLOAT: return _data._float; case STRING: return operator String().to_int(); default: { @@ -1391,7 +1713,7 @@ Variant::operator signed char() const { case NIL: return 0; case BOOL: return _data._bool ? 1 : 0; case INT: return _data._int; - case REAL: return _data._real; + case FLOAT: return _data._float; case STRING: return operator String().to_int(); default: { @@ -1406,7 +1728,7 @@ Variant::operator unsigned char() const { case NIL: return 0; case BOOL: return _data._bool ? 1 : 0; case INT: return _data._int; - case REAL: return _data._real; + case FLOAT: return _data._float; case STRING: return operator String().to_int(); default: { @@ -1427,7 +1749,7 @@ Variant::operator float() const { case NIL: return 0; case BOOL: return _data._bool ? 1.0 : 0.0; case INT: return (float)_data._int; - case REAL: return _data._real; + case FLOAT: return _data._float; case STRING: return operator String().to_double(); default: { @@ -1442,7 +1764,7 @@ Variant::operator double() const { case NIL: return 0; case BOOL: return _data._bool ? 1.0 : 0.0; case INT: return (double)_data._int; - case REAL: return _data._real; + case FLOAT: return _data._float; case STRING: return operator String().to_double(); default: { @@ -1453,10 +1775,13 @@ Variant::operator double() const { Variant::operator StringName() const { - if (type == NODE_PATH) { - return reinterpret_cast<const NodePath *>(_data._mem)->get_sname(); + if (type == STRING_NAME) { + return *reinterpret_cast<const StringName *>(_data._mem); + } else if (type == STRING) { + return *reinterpret_cast<const String *>(_data._mem); } - return StringName(operator String()); + + return StringName(); } struct _VariantStrPair { @@ -1482,16 +1807,19 @@ String Variant::stringify(List<const void *> &stack) const { case NIL: return "Null"; case BOOL: return _data._bool ? "True" : "False"; case INT: return itos(_data._int); - case REAL: return rtos(_data._real); + case FLOAT: return rtos(_data._float); case STRING: return *reinterpret_cast<const String *>(_data._mem); case VECTOR2: return "(" + operator Vector2() + ")"; + case VECTOR2I: return "(" + operator Vector2i() + ")"; case RECT2: return "(" + operator Rect2() + ")"; + case RECT2I: return "(" + operator Rect2i() + ")"; case TRANSFORM2D: { Transform2D mat32 = operator Transform2D(); return "(" + Variant(mat32.elements[0]).operator String() + ", " + Variant(mat32.elements[1]).operator String() + ", " + Variant(mat32.elements[2]).operator String() + ")"; } break; case VECTOR3: return "(" + operator Vector3() + ")"; + case VECTOR3I: return "(" + operator Vector3i() + ")"; case PLANE: return operator Plane(); //case QUAT: @@ -1523,6 +1851,7 @@ String Variant::stringify(List<const void *> &stack) const { return mtx + ")"; } break; case TRANSFORM: return operator Transform(); + case STRING_NAME: return operator StringName(); case NODE_PATH: return operator NodePath(); case COLOR: return String::num(operator Color().r) + "," + String::num(operator Color().g) + "," + String::num(operator Color().b) + "," + String::num(operator Color().a); case DICTIONARY: { @@ -1600,9 +1929,22 @@ String Variant::stringify(List<const void *> &stack) const { str += "]"; return str; } break; - case PACKED_INT_ARRAY: { + case PACKED_INT32_ARRAY: { + + Vector<int32_t> vec = operator Vector<int32_t>(); + String str("["); + for (int i = 0; i < vec.size(); i++) { + + if (i > 0) + str += ", "; + str = str + itos(vec[i]); + } + str += "]"; + return str; + } break; + case PACKED_INT64_ARRAY: { - Vector<int> vec = operator Vector<int>(); + Vector<int64_t> vec = operator Vector<int64_t>(); String str("["); for (int i = 0; i < vec.size(); i++) { @@ -1613,9 +1955,22 @@ String Variant::stringify(List<const void *> &stack) const { str += "]"; return str; } break; - case PACKED_REAL_ARRAY: { + case PACKED_FLOAT32_ARRAY: { - Vector<real_t> vec = operator Vector<real_t>(); + Vector<float> vec = operator Vector<float>(); + String str("["); + for (int i = 0; i < vec.size(); i++) { + + if (i > 0) + str += ", "; + str = str + rtos(vec[i]); + } + str += "]"; + return str; + } break; + case PACKED_FLOAT64_ARRAY: { + + Vector<double> vec = operator Vector<double>(); String str("["); for (int i = 0; i < vec.size(); i++) { @@ -1683,28 +2038,78 @@ Variant::operator Vector2() const { if (type == VECTOR2) return *reinterpret_cast<const Vector2 *>(_data._mem); + else if (type == VECTOR2I) + return *reinterpret_cast<const Vector2i *>(_data._mem); else if (type == VECTOR3) return Vector2(reinterpret_cast<const Vector3 *>(_data._mem)->x, reinterpret_cast<const Vector3 *>(_data._mem)->y); + else if (type == VECTOR3I) + return Vector2(reinterpret_cast<const Vector3i *>(_data._mem)->x, reinterpret_cast<const Vector3i *>(_data._mem)->y); else return Vector2(); } + +Variant::operator Vector2i() const { + + if (type == VECTOR2I) + return *reinterpret_cast<const Vector2i *>(_data._mem); + else if (type == VECTOR2) + return *reinterpret_cast<const Vector2 *>(_data._mem); + else if (type == VECTOR3) + return Vector2(reinterpret_cast<const Vector3 *>(_data._mem)->x, reinterpret_cast<const Vector3 *>(_data._mem)->y); + else if (type == VECTOR3I) + return Vector2(reinterpret_cast<const Vector3i *>(_data._mem)->x, reinterpret_cast<const Vector3i *>(_data._mem)->y); + else + return Vector2i(); +} + Variant::operator Rect2() const { if (type == RECT2) return *reinterpret_cast<const Rect2 *>(_data._mem); + else if (type == RECT2I) + return *reinterpret_cast<const Rect2i *>(_data._mem); else return Rect2(); } +Variant::operator Rect2i() const { + + if (type == RECT2I) + return *reinterpret_cast<const Rect2i *>(_data._mem); + else if (type == RECT2) + return *reinterpret_cast<const Rect2 *>(_data._mem); + else + return Rect2i(); +} + Variant::operator Vector3() const { if (type == VECTOR3) return *reinterpret_cast<const Vector3 *>(_data._mem); + else if (type == VECTOR3I) + return *reinterpret_cast<const Vector3i *>(_data._mem); else if (type == VECTOR2) return Vector3(reinterpret_cast<const Vector2 *>(_data._mem)->x, reinterpret_cast<const Vector2 *>(_data._mem)->y, 0.0); + else if (type == VECTOR2I) + return Vector3(reinterpret_cast<const Vector2i *>(_data._mem)->x, reinterpret_cast<const Vector2i *>(_data._mem)->y, 0.0); else return Vector3(); } + +Variant::operator Vector3i() const { + + if (type == VECTOR3I) + return *reinterpret_cast<const Vector3i *>(_data._mem); + else if (type == VECTOR3) + return *reinterpret_cast<const Vector3 *>(_data._mem); + else if (type == VECTOR2) + return Vector3i(reinterpret_cast<const Vector2 *>(_data._mem)->x, reinterpret_cast<const Vector2 *>(_data._mem)->y, 0.0); + else if (type == VECTOR2I) + return Vector3i(reinterpret_cast<const Vector2i *>(_data._mem)->x, reinterpret_cast<const Vector2i *>(_data._mem)->y, 0.0); + else + return Vector3i(); +} + Variant::operator Plane() const { if (type == PLANE) @@ -1921,11 +2326,17 @@ inline DA _convert_array_from_variant(const Variant &p_variant) { case Variant::PACKED_BYTE_ARRAY: { return _convert_array<DA, Vector<uint8_t> >(p_variant.operator Vector<uint8_t>()); } - case Variant::PACKED_INT_ARRAY: { - return _convert_array<DA, Vector<int> >(p_variant.operator Vector<int>()); + case Variant::PACKED_INT32_ARRAY: { + return _convert_array<DA, Vector<int32_t> >(p_variant.operator Vector<int32_t>()); + } + case Variant::PACKED_INT64_ARRAY: { + return _convert_array<DA, Vector<int64_t> >(p_variant.operator Vector<int64_t>()); + } + case Variant::PACKED_FLOAT32_ARRAY: { + return _convert_array<DA, Vector<float> >(p_variant.operator Vector<float>()); } - case Variant::PACKED_REAL_ARRAY: { - return _convert_array<DA, Vector<real_t> >(p_variant.operator Vector<real_t>()); + case Variant::PACKED_FLOAT64_ARRAY: { + return _convert_array<DA, Vector<double> >(p_variant.operator Vector<double>()); } case Variant::PACKED_STRING_ARRAY: { return _convert_array<DA, Vector<String> >(p_variant.operator Vector<String>()); @@ -1956,43 +2367,59 @@ Variant::operator Array() const { Variant::operator Vector<uint8_t>() const { if (type == PACKED_BYTE_ARRAY) - return *reinterpret_cast<const Vector<uint8_t> *>(_data._mem); + return static_cast<PackedArrayRef<uint8_t> *>(_data.packed_array)->array; else return _convert_array_from_variant<Vector<uint8_t> >(*this); } -Variant::operator Vector<int>() const { +Variant::operator Vector<int32_t>() const { - if (type == PACKED_INT_ARRAY) - return *reinterpret_cast<const Vector<int> *>(_data._mem); + if (type == PACKED_INT32_ARRAY) + return static_cast<PackedArrayRef<int32_t> *>(_data.packed_array)->array; else return _convert_array_from_variant<Vector<int> >(*this); } -Variant::operator Vector<real_t>() const { +Variant::operator Vector<int64_t>() const { + + if (type == PACKED_INT64_ARRAY) + return static_cast<PackedArrayRef<int64_t> *>(_data.packed_array)->array; + else + return _convert_array_from_variant<Vector<int64_t> >(*this); +} + +Variant::operator Vector<float>() const { + + if (type == PACKED_FLOAT32_ARRAY) + return static_cast<PackedArrayRef<float> *>(_data.packed_array)->array; + else + return _convert_array_from_variant<Vector<float> >(*this); +} + +Variant::operator Vector<double>() const { - if (type == PACKED_REAL_ARRAY) - return *reinterpret_cast<const Vector<real_t> *>(_data._mem); + if (type == PACKED_FLOAT64_ARRAY) + return static_cast<PackedArrayRef<double> *>(_data.packed_array)->array; else - return _convert_array_from_variant<Vector<real_t> >(*this); + return _convert_array_from_variant<Vector<double> >(*this); } Variant::operator Vector<String>() const { if (type == PACKED_STRING_ARRAY) - return *reinterpret_cast<const Vector<String> *>(_data._mem); + return static_cast<PackedArrayRef<String> *>(_data.packed_array)->array; else return _convert_array_from_variant<Vector<String> >(*this); } Variant::operator Vector<Vector3>() const { if (type == PACKED_VECTOR3_ARRAY) - return *reinterpret_cast<const Vector<Vector3> *>(_data._mem); + return static_cast<PackedArrayRef<Vector3> *>(_data.packed_array)->array; else return _convert_array_from_variant<Vector<Vector3> >(*this); } Variant::operator Vector<Vector2>() const { if (type == PACKED_VECTOR2_ARRAY) - return *reinterpret_cast<const Vector<Vector2> *>(_data._mem); + return static_cast<PackedArrayRef<Vector2> *>(_data.packed_array)->array; else return _convert_array_from_variant<Vector<Vector2> >(*this); } @@ -2000,7 +2427,7 @@ Variant::operator Vector<Vector2>() const { Variant::operator Vector<Color>() const { if (type == PACKED_COLOR_ARRAY) - return *reinterpret_cast<const Vector<Color> *>(_data._mem); + return static_cast<PackedArrayRef<Color> *>(_data.packed_array)->array; else return _convert_array_from_variant<Vector<Color> >(*this); } @@ -2091,7 +2518,7 @@ Variant::operator Orientation() const { Variant::operator IP_Address() const { - if (type == PACKED_REAL_ARRAY || type == PACKED_INT_ARRAY || type == PACKED_BYTE_ARRAY) { + if (type == PACKED_FLOAT32_ARRAY || type == PACKED_INT32_ARRAY || type == PACKED_FLOAT64_ARRAY || type == PACKED_INT64_ARRAY || type == PACKED_BYTE_ARRAY) { Vector<int> addr = operator Vector<int>(); if (addr.size() == 4) { @@ -2175,13 +2602,13 @@ Variant::Variant(unsigned char p_char) { } Variant::Variant(float p_float) { - type = REAL; - _data._real = p_float; + type = FLOAT; + _data._float = p_float; } Variant::Variant(double p_double) { - type = REAL; - _data._real = p_double; + type = FLOAT; + _data._float = p_double; } Variant::Variant(const ObjectID &p_id) { @@ -2191,8 +2618,8 @@ Variant::Variant(const ObjectID &p_id) { Variant::Variant(const StringName &p_string) { - type = STRING; - memnew_placement(_data._mem, String(p_string.operator String())); + type = STRING_NAME; + memnew_placement(_data._mem, StringName(p_string)); } Variant::Variant(const String &p_string) { @@ -2216,17 +2643,36 @@ Variant::Variant(const Vector3 &p_vector3) { type = VECTOR3; memnew_placement(_data._mem, Vector3(p_vector3)); } +Variant::Variant(const Vector3i &p_vector3i) { + + type = VECTOR3I; + memnew_placement(_data._mem, Vector3i(p_vector3i)); +} + Variant::Variant(const Vector2 &p_vector2) { type = VECTOR2; memnew_placement(_data._mem, Vector2(p_vector2)); } + +Variant::Variant(const Vector2i &p_vector2i) { + + type = VECTOR2I; + memnew_placement(_data._mem, Vector2i(p_vector2i)); +} + Variant::Variant(const Rect2 &p_rect2) { type = RECT2; memnew_placement(_data._mem, Rect2(p_rect2)); } +Variant::Variant(const Rect2i &p_rect2i) { + + type = RECT2I; + memnew_placement(_data._mem, Rect2i(p_rect2i)); +} + Variant::Variant(const Plane &p_plane) { type = PLANE; @@ -2354,41 +2800,56 @@ Variant::Variant(const Vector<RID> &p_array) { } } -Variant::Variant(const Vector<uint8_t> &p_raw_array) { +Variant::Variant(const Vector<uint8_t> &p_byte_array) { type = PACKED_BYTE_ARRAY; - memnew_placement(_data._mem, Vector<uint8_t>(p_raw_array)); + + _data.packed_array = PackedArrayRef<uint8_t>::create(p_byte_array); +} +Variant::Variant(const Vector<int32_t> &p_int32_array) { + + type = PACKED_INT32_ARRAY; + _data.packed_array = PackedArrayRef<int32_t>::create(p_int32_array); +} + +Variant::Variant(const Vector<int64_t> &p_int64_array) { + + type = PACKED_INT64_ARRAY; + _data.packed_array = PackedArrayRef<int64_t>::create(p_int64_array); } -Variant::Variant(const Vector<int> &p_int_array) { - type = PACKED_INT_ARRAY; - memnew_placement(_data._mem, Vector<int>(p_int_array)); +Variant::Variant(const Vector<float> &p_float32_array) { + + type = PACKED_FLOAT32_ARRAY; + _data.packed_array = PackedArrayRef<float>::create(p_float32_array); } -Variant::Variant(const Vector<real_t> &p_real_array) { - type = PACKED_REAL_ARRAY; - memnew_placement(_data._mem, Vector<real_t>(p_real_array)); +Variant::Variant(const Vector<double> &p_float64_array) { + + type = PACKED_FLOAT64_ARRAY; + _data.packed_array = PackedArrayRef<double>::create(p_float64_array); } + Variant::Variant(const Vector<String> &p_string_array) { type = PACKED_STRING_ARRAY; - memnew_placement(_data._mem, Vector<String>(p_string_array)); + _data.packed_array = PackedArrayRef<String>::create(p_string_array); } Variant::Variant(const Vector<Vector3> &p_vector3_array) { type = PACKED_VECTOR3_ARRAY; - memnew_placement(_data._mem, Vector<Vector3>(p_vector3_array)); + _data.packed_array = PackedArrayRef<Vector3>::create(p_vector3_array); } Variant::Variant(const Vector<Vector2> &p_vector2_array) { type = PACKED_VECTOR2_ARRAY; - memnew_placement(_data._mem, Vector<Vector2>(p_vector2_array)); + _data.packed_array = PackedArrayRef<Vector2>::create(p_vector2_array); } Variant::Variant(const Vector<Color> &p_color_array) { type = PACKED_COLOR_ARRAY; - memnew_placement(_data._mem, Vector<Color>(p_color_array)); + _data.packed_array = PackedArrayRef<Color>::create(p_color_array); } Variant::Variant(const Vector<Face3> &p_face_array) { @@ -2460,9 +2921,9 @@ void Variant::operator=(const Variant &p_variant) { _data._int = p_variant._data._int; } break; - case REAL: { + case FLOAT: { - _data._real = p_variant._data._real; + _data._float = p_variant._data._float; } break; case STRING: { @@ -2474,10 +2935,18 @@ void Variant::operator=(const Variant &p_variant) { *reinterpret_cast<Vector2 *>(_data._mem) = *reinterpret_cast<const Vector2 *>(p_variant._data._mem); } break; + case VECTOR2I: { + + *reinterpret_cast<Vector2i *>(_data._mem) = *reinterpret_cast<const Vector2i *>(p_variant._data._mem); + } break; case RECT2: { *reinterpret_cast<Rect2 *>(_data._mem) = *reinterpret_cast<const Rect2 *>(p_variant._data._mem); } break; + case RECT2I: { + + *reinterpret_cast<Rect2i *>(_data._mem) = *reinterpret_cast<const Rect2i *>(p_variant._data._mem); + } break; case TRANSFORM2D: { *_data._transform2d = *(p_variant._data._transform2d); @@ -2486,6 +2955,10 @@ void Variant::operator=(const Variant &p_variant) { *reinterpret_cast<Vector3 *>(_data._mem) = *reinterpret_cast<const Vector3 *>(p_variant._data._mem); } break; + case VECTOR3I: { + + *reinterpret_cast<Vector3i *>(_data._mem) = *reinterpret_cast<const Vector3i *>(p_variant._data._mem); + } break; case PLANE: { *reinterpret_cast<Plane *>(_data._mem) = *reinterpret_cast<const Plane *>(p_variant._data._mem); @@ -2549,6 +3022,10 @@ void Variant::operator=(const Variant &p_variant) { *reinterpret_cast<Signal *>(_data._mem) = *reinterpret_cast<const Signal *>(p_variant._data._mem); } break; + case STRING_NAME: { + + *reinterpret_cast<StringName *>(_data._mem) = *reinterpret_cast<const StringName *>(p_variant._data._mem); + } break; case NODE_PATH: { *reinterpret_cast<NodePath *>(_data._mem) = *reinterpret_cast<const NodePath *>(p_variant._data._mem); @@ -2565,31 +3042,39 @@ void Variant::operator=(const Variant &p_variant) { // arrays case PACKED_BYTE_ARRAY: { - *reinterpret_cast<Vector<uint8_t> *>(_data._mem) = *reinterpret_cast<const Vector<uint8_t> *>(p_variant._data._mem); + _data.packed_array = PackedArrayRef<uint8_t>::reference_from(_data.packed_array, p_variant._data.packed_array); + } break; + case PACKED_INT32_ARRAY: { + + _data.packed_array = PackedArrayRef<int32_t>::reference_from(_data.packed_array, p_variant._data.packed_array); + } break; + case PACKED_INT64_ARRAY: { + + _data.packed_array = PackedArrayRef<int64_t>::reference_from(_data.packed_array, p_variant._data.packed_array); } break; - case PACKED_INT_ARRAY: { + case PACKED_FLOAT32_ARRAY: { - *reinterpret_cast<Vector<int> *>(_data._mem) = *reinterpret_cast<const Vector<int> *>(p_variant._data._mem); + _data.packed_array = PackedArrayRef<float>::reference_from(_data.packed_array, p_variant._data.packed_array); } break; - case PACKED_REAL_ARRAY: { + case PACKED_FLOAT64_ARRAY: { - *reinterpret_cast<Vector<real_t> *>(_data._mem) = *reinterpret_cast<const Vector<real_t> *>(p_variant._data._mem); + _data.packed_array = PackedArrayRef<double>::reference_from(_data.packed_array, p_variant._data.packed_array); } break; case PACKED_STRING_ARRAY: { - *reinterpret_cast<Vector<String> *>(_data._mem) = *reinterpret_cast<const Vector<String> *>(p_variant._data._mem); + _data.packed_array = PackedArrayRef<String>::reference_from(_data.packed_array, p_variant._data.packed_array); } break; case PACKED_VECTOR2_ARRAY: { - *reinterpret_cast<Vector<Vector2> *>(_data._mem) = *reinterpret_cast<const Vector<Vector2> *>(p_variant._data._mem); + _data.packed_array = PackedArrayRef<Vector2>::reference_from(_data.packed_array, p_variant._data.packed_array); } break; case PACKED_VECTOR3_ARRAY: { - *reinterpret_cast<Vector<Vector3> *>(_data._mem) = *reinterpret_cast<const Vector<Vector3> *>(p_variant._data._mem); + _data.packed_array = PackedArrayRef<Vector3>::reference_from(_data.packed_array, p_variant._data.packed_array); } break; case PACKED_COLOR_ARRAY: { - *reinterpret_cast<Vector<Color> *>(_data._mem) = *reinterpret_cast<const Vector<Color> *>(p_variant._data._mem); + _data.packed_array = PackedArrayRef<Color>::reference_from(_data.packed_array, p_variant._data.packed_array); } break; default: { } @@ -2629,9 +3114,9 @@ uint32_t Variant::hash() const { return _data._int; } break; - case REAL: { + case FLOAT: { - return hash_djb2_one_float(_data._real); + return hash_djb2_one_float(_data._float); } break; case STRING: { @@ -2644,6 +3129,11 @@ uint32_t Variant::hash() const { uint32_t hash = hash_djb2_one_float(reinterpret_cast<const Vector2 *>(_data._mem)->x); return hash_djb2_one_float(reinterpret_cast<const Vector2 *>(_data._mem)->y, hash); } break; + case VECTOR2I: { + + uint32_t hash = hash_djb2_one_32(reinterpret_cast<const Vector2i *>(_data._mem)->x); + return hash_djb2_one_32(reinterpret_cast<const Vector2i *>(_data._mem)->y, hash); + } break; case RECT2: { uint32_t hash = hash_djb2_one_float(reinterpret_cast<const Rect2 *>(_data._mem)->position.x); @@ -2651,6 +3141,13 @@ uint32_t Variant::hash() const { hash = hash_djb2_one_float(reinterpret_cast<const Rect2 *>(_data._mem)->size.x, hash); return hash_djb2_one_float(reinterpret_cast<const Rect2 *>(_data._mem)->size.y, hash); } break; + case RECT2I: { + + uint32_t hash = hash_djb2_one_32(reinterpret_cast<const Rect2i *>(_data._mem)->position.x); + hash = hash_djb2_one_32(reinterpret_cast<const Rect2i *>(_data._mem)->position.y, hash); + hash = hash_djb2_one_32(reinterpret_cast<const Rect2i *>(_data._mem)->size.x, hash); + return hash_djb2_one_32(reinterpret_cast<const Rect2i *>(_data._mem)->size.y, hash); + } break; case TRANSFORM2D: { uint32_t hash = 5831; @@ -2669,6 +3166,12 @@ uint32_t Variant::hash() const { hash = hash_djb2_one_float(reinterpret_cast<const Vector3 *>(_data._mem)->y, hash); return hash_djb2_one_float(reinterpret_cast<const Vector3 *>(_data._mem)->z, hash); } break; + case VECTOR3I: { + + uint32_t hash = hash_djb2_one_32(reinterpret_cast<const Vector3i *>(_data._mem)->x); + hash = hash_djb2_one_32(reinterpret_cast<const Vector3i *>(_data._mem)->y, hash); + return hash_djb2_one_32(reinterpret_cast<const Vector3i *>(_data._mem)->z, hash); + } break; case PLANE: { uint32_t hash = hash_djb2_one_float(reinterpret_cast<const Plane *>(_data._mem)->normal.x); @@ -2747,6 +3250,10 @@ uint32_t Variant::hash() const { return hash_djb2_one_64(make_uint64_t(_get_obj().obj)); } break; + case STRING_NAME: { + + return reinterpret_cast<const StringName *>(_data._mem)->hash(); + } break; case NODE_PATH: { return reinterpret_cast<const NodePath *>(_data._mem)->hash(); @@ -2775,7 +3282,7 @@ uint32_t Variant::hash() const { } break; case PACKED_BYTE_ARRAY: { - const Vector<uint8_t> &arr = *reinterpret_cast<const Vector<uint8_t> *>(_data._mem); + const Vector<uint8_t> &arr = PackedArrayRef<uint8_t>::get_array(_data.packed_array); int len = arr.size(); if (likely(len)) { const uint8_t *r = arr.ptr(); @@ -2785,26 +3292,51 @@ uint32_t Variant::hash() const { } } break; - case PACKED_INT_ARRAY: { + case PACKED_INT32_ARRAY: { - const Vector<int> &arr = *reinterpret_cast<const Vector<int> *>(_data._mem); + const Vector<int32_t> &arr = PackedArrayRef<int32_t>::get_array(_data.packed_array); int len = arr.size(); if (likely(len)) { - const int *r = arr.ptr(); - return hash_djb2_buffer((uint8_t *)&r[0], len * sizeof(int)); + const int32_t *r = arr.ptr(); + return hash_djb2_buffer((uint8_t *)&r[0], len * sizeof(int32_t)); } else { return hash_djb2_one_64(0); } } break; - case PACKED_REAL_ARRAY: { + case PACKED_INT64_ARRAY: { - const Vector<real_t> &arr = *reinterpret_cast<const Vector<real_t> *>(_data._mem); + const Vector<int64_t> &arr = PackedArrayRef<int64_t>::get_array(_data.packed_array); + int len = arr.size(); + if (likely(len)) { + const int64_t *r = arr.ptr(); + return hash_djb2_buffer((uint8_t *)&r[0], len * sizeof(int64_t)); + } else { + return hash_djb2_one_64(0); + } + + } break; + case PACKED_FLOAT32_ARRAY: { + + const Vector<float> &arr = PackedArrayRef<float>::get_array(_data.packed_array); int len = arr.size(); if (likely(len)) { - const real_t *r = arr.ptr(); - return hash_djb2_buffer((uint8_t *)&r[0], len * sizeof(real_t)); + const float *r = arr.ptr(); + return hash_djb2_buffer((uint8_t *)&r[0], len * sizeof(float)); + } else { + return hash_djb2_one_float(0.0); + } + + } break; + case PACKED_FLOAT64_ARRAY: { + + const Vector<double> &arr = PackedArrayRef<double>::get_array(_data.packed_array); + int len = arr.size(); + + if (likely(len)) { + const double *r = arr.ptr(); + return hash_djb2_buffer((uint8_t *)&r[0], len * sizeof(double)); } else { return hash_djb2_one_float(0.0); } @@ -2813,7 +3345,7 @@ uint32_t Variant::hash() const { case PACKED_STRING_ARRAY: { uint32_t hash = 5831; - const Vector<String> &arr = *reinterpret_cast<const Vector<String> *>(_data._mem); + const Vector<String> &arr = PackedArrayRef<String>::get_array(_data.packed_array); int len = arr.size(); if (likely(len)) { @@ -2829,7 +3361,7 @@ uint32_t Variant::hash() const { case PACKED_VECTOR2_ARRAY: { uint32_t hash = 5831; - const Vector<Vector2> &arr = *reinterpret_cast<const Vector<Vector2> *>(_data._mem); + const Vector<Vector2> &arr = PackedArrayRef<Vector2>::get_array(_data.packed_array); int len = arr.size(); if (likely(len)) { @@ -2846,7 +3378,7 @@ uint32_t Variant::hash() const { case PACKED_VECTOR3_ARRAY: { uint32_t hash = 5831; - const Vector<Vector3> &arr = *reinterpret_cast<const Vector<Vector3> *>(_data._mem); + const Vector<Vector3> &arr = PackedArrayRef<Vector3>::get_array(_data.packed_array); int len = arr.size(); if (likely(len)) { @@ -2864,7 +3396,7 @@ uint32_t Variant::hash() const { case PACKED_COLOR_ARRAY: { uint32_t hash = 5831; - const Vector<Color> &arr = *reinterpret_cast<const Vector<Color> *>(_data._mem); + const Vector<Color> &arr = PackedArrayRef<Color>::get_array(_data.packed_array); int len = arr.size(); if (likely(len)) { @@ -2911,21 +3443,21 @@ uint32_t Variant::hash() const { (hash_compare_scalar((p_lhs).b, (p_rhs).b)) && \ (hash_compare_scalar((p_lhs).a, (p_rhs).a)) -#define hash_compare_pool_array(p_lhs, p_rhs, p_type, p_compare_func) \ - const Vector<p_type> &l = *reinterpret_cast<const Vector<p_type> *>(p_lhs); \ - const Vector<p_type> &r = *reinterpret_cast<const Vector<p_type> *>(p_rhs); \ - \ - if (l.size() != r.size()) \ - return false; \ - \ - const p_type *lr = l.ptr(); \ - const p_type *rr = r.ptr(); \ - \ - for (int i = 0; i < l.size(); ++i) { \ - if (!p_compare_func((lr[i]), (rr[i]))) \ - return false; \ - } \ - \ +#define hash_compare_packed_array(p_lhs, p_rhs, p_type, p_compare_func) \ + const Vector<p_type> &l = PackedArrayRef<p_type>::get_array(p_lhs); \ + const Vector<p_type> &r = PackedArrayRef<p_type>::get_array(p_rhs); \ + \ + if (l.size() != r.size()) \ + return false; \ + \ + const p_type *lr = l.ptr(); \ + const p_type *rr = r.ptr(); \ + \ + for (int i = 0; i < l.size(); ++i) { \ + if (!p_compare_func((lr[i]), (rr[i]))) \ + return false; \ + } \ + \ return true bool Variant::hash_compare(const Variant &p_variant) const { @@ -2933,8 +3465,8 @@ bool Variant::hash_compare(const Variant &p_variant) const { return false; switch (type) { - case REAL: { - return hash_compare_scalar(_data._real, p_variant._data._real); + case FLOAT: { + return hash_compare_scalar(_data._float, p_variant._data._float); } break; case VECTOR2: { @@ -2943,6 +3475,11 @@ bool Variant::hash_compare(const Variant &p_variant) const { return hash_compare_vector2(*l, *r); } break; + case VECTOR2I: { + const Vector2i *l = reinterpret_cast<const Vector2i *>(_data._mem); + const Vector2i *r = reinterpret_cast<const Vector2i *>(p_variant._data._mem); + return *l == *r; + } break; case RECT2: { const Rect2 *l = reinterpret_cast<const Rect2 *>(_data._mem); @@ -2951,6 +3488,12 @@ bool Variant::hash_compare(const Variant &p_variant) const { return (hash_compare_vector2(l->position, r->position)) && (hash_compare_vector2(l->size, r->size)); } break; + case RECT2I: { + const Rect2i *l = reinterpret_cast<const Rect2i *>(_data._mem); + const Rect2i *r = reinterpret_cast<const Rect2i *>(p_variant._data._mem); + + return *l == *r; + } break; case TRANSFORM2D: { Transform2D *l = _data._transform2d; @@ -2970,6 +3513,12 @@ bool Variant::hash_compare(const Variant &p_variant) const { return hash_compare_vector3(*l, *r); } break; + case VECTOR3I: { + const Vector3i *l = reinterpret_cast<const Vector3i *>(_data._mem); + const Vector3i *r = reinterpret_cast<const Vector3i *>(p_variant._data._mem); + + return *l == *r; + } break; case PLANE: { const Plane *l = reinterpret_cast<const Plane *>(_data._mem); @@ -3041,20 +3590,25 @@ bool Variant::hash_compare(const Variant &p_variant) const { return true; } break; - case PACKED_REAL_ARRAY: { - hash_compare_pool_array(_data._mem, p_variant._data._mem, real_t, hash_compare_scalar); + // This is for floating point comparisons only. + case PACKED_FLOAT32_ARRAY: { + hash_compare_packed_array(_data.packed_array, p_variant._data.packed_array, float, hash_compare_scalar); + } break; + + case PACKED_FLOAT64_ARRAY: { + hash_compare_packed_array(_data.packed_array, p_variant._data.packed_array, double, hash_compare_scalar); } break; case PACKED_VECTOR2_ARRAY: { - hash_compare_pool_array(_data._mem, p_variant._data._mem, Vector2, hash_compare_vector2); + hash_compare_packed_array(_data.packed_array, p_variant._data.packed_array, Vector2, hash_compare_vector2); } break; case PACKED_VECTOR3_ARRAY: { - hash_compare_pool_array(_data._mem, p_variant._data._mem, Vector3, hash_compare_vector3); + hash_compare_packed_array(_data.packed_array, p_variant._data.packed_array, Vector3, hash_compare_vector3); } break; case PACKED_COLOR_ARRAY: { - hash_compare_pool_array(_data._mem, p_variant._data._mem, Color, hash_compare_color); + hash_compare_packed_array(_data.packed_array, p_variant._data.packed_array, Color, hash_compare_color); } break; default: diff --git a/core/variant.h b/core/variant.h index d41144f4c5..614d39e84a 100644 --- a/core/variant.h +++ b/core/variant.h @@ -44,9 +44,9 @@ #include "core/math/transform.h" #include "core/math/transform_2d.h" #include "core/math/vector3.h" +#include "core/math/vector3i.h" #include "core/node_path.h" #include "core/object_id.h" - #include "core/rid.h" #include "core/ustring.h" @@ -58,8 +58,10 @@ struct PropertyInfo; struct MethodInfo; typedef Vector<uint8_t> PackedByteArray; -typedef Vector<int> PackedIntArray; -typedef Vector<real_t> PackedRealArray; +typedef Vector<int32_t> PackedInt32Array; +typedef Vector<int64_t> PackedInt64Array; +typedef Vector<float> PackedFloat32Array; +typedef Vector<double> PackedFloat64Array; typedef Vector<String> PackedStringArray; typedef Vector<Vector2> PackedVector2Array; typedef Vector<Vector3> PackedVector3Array; @@ -76,47 +78,51 @@ class Variant { public: // If this changes the table in variant_op must be updated enum Type { - NIL, // atomic types BOOL, INT, - REAL, + FLOAT, STRING, // math types - - VECTOR2, // 5 + VECTOR2, + VECTOR2I, RECT2, + RECT2I, VECTOR3, + VECTOR3I, TRANSFORM2D, PLANE, - QUAT, // 10 + QUAT, AABB, BASIS, TRANSFORM, // misc types COLOR, - NODE_PATH, // 15 + STRING_NAME, + NODE_PATH, _RID, OBJECT, CALLABLE, SIGNAL, DICTIONARY, ARRAY, - // arrays - PACKED_BYTE_ARRAY, // 20 - PACKED_INT_ARRAY, - PACKED_REAL_ARRAY, + + // typed arrays + PACKED_BYTE_ARRAY, + PACKED_INT32_ARRAY, + PACKED_INT64_ARRAY, + PACKED_FLOAT32_ARRAY, + PACKED_FLOAT64_ARRAY, PACKED_STRING_ARRAY, PACKED_VECTOR2_ARRAY, - PACKED_VECTOR3_ARRAY, // 25 + PACKED_VECTOR3_ARRAY, PACKED_COLOR_ARRAY, VARIANT_MAX - }; private: @@ -132,17 +138,77 @@ private: Object *obj; }; + /* array helpers */ + struct PackedArrayRefBase { + SafeRefCount refcount; + _FORCE_INLINE_ PackedArrayRefBase *reference() { + if (this->refcount.ref()) { + return this; + } else { + return nullptr; + } + } + static _FORCE_INLINE_ PackedArrayRefBase *reference_from(PackedArrayRefBase *p_base, PackedArrayRefBase *p_from) { + if (p_base == p_from) { + return p_base; //same thing, do nothing + } + + if (p_from->reference()) { + if (p_base->refcount.unref()) { + memdelete(p_base); + } + return p_from; + } else { + return p_base; //keep, could not reference new + } + } + static _FORCE_INLINE_ void destroy(PackedArrayRefBase *p_array) { + if (p_array->refcount.unref()) { + memdelete(p_array); + } + } + _FORCE_INLINE_ virtual ~PackedArrayRefBase() {} //needs virtual destructor, but make inline + }; + + template <class T> + struct PackedArrayRef : public PackedArrayRefBase { + Vector<T> array; + static _FORCE_INLINE_ PackedArrayRef<T> *create() { + return memnew(PackedArrayRef<T>); + } + static _FORCE_INLINE_ PackedArrayRef<T> *create(const Vector<T> &p_from) { + return memnew(PackedArrayRef<T>(p_from)); + } + + static _FORCE_INLINE_ const Vector<T> &get_array(PackedArrayRefBase *p_base) { + return static_cast<PackedArrayRef<T> *>(p_base)->array; + } + static _FORCE_INLINE_ Vector<T> *get_array_ptr(const PackedArrayRefBase *p_base) { + return &const_cast<PackedArrayRef<T> *>(static_cast<const PackedArrayRef<T> *>(p_base))->array; + } + + _FORCE_INLINE_ PackedArrayRef(const Vector<T> &p_from) { + array = p_from; + refcount.init(); + } + _FORCE_INLINE_ PackedArrayRef() { + refcount.init(); + } + }; + + /* end of array helpers */ _ALWAYS_INLINE_ ObjData &_get_obj(); _ALWAYS_INLINE_ const ObjData &_get_obj() const; union { bool _bool; int64_t _int; - double _real; + double _float; Transform2D *_transform2d; ::AABB *_aabb; Basis *_basis; Transform *_transform; + PackedArrayRefBase *packed_array; void *_ptr; //generic pointer uint8_t _mem[sizeof(ObjData) > (sizeof(real_t) * 4) ? sizeof(ObjData) : (sizeof(real_t) * 4)]; } _data GCC_ALIGNED_8; @@ -151,14 +217,20 @@ private: void clear(); public: - _FORCE_INLINE_ Type get_type() const { return type; } + _FORCE_INLINE_ Type get_type() const { + return type; + } static String get_type_name(Variant::Type p_type); static bool can_convert(Type p_type_from, Type p_type_to); static bool can_convert_strict(Type p_type_from, Type p_type_to); bool is_ref() const; - _FORCE_INLINE_ bool is_num() const { return type == INT || type == REAL; }; - _FORCE_INLINE_ bool is_array() const { return type >= ARRAY; }; + _FORCE_INLINE_ bool is_num() const { + return type == INT || type == FLOAT; + }; + _FORCE_INLINE_ bool is_array() const { + return type >= ARRAY; + }; bool is_shared() const; bool is_zero() const; bool is_one() const; @@ -187,8 +259,11 @@ public: operator String() const; operator StringName() const; operator Vector2() const; + operator Vector2i() const; operator Rect2() const; + operator Rect2i() const; operator Vector3() const; + operator Vector3i() const; operator Plane() const; operator ::AABB() const; operator Quat() const; @@ -211,8 +286,10 @@ public: operator Array() const; operator Vector<uint8_t>() const; - operator Vector<int>() const; - operator Vector<real_t>() const; + operator Vector<int32_t>() const; + operator Vector<int64_t>() const; + operator Vector<float>() const; + operator Vector<double>() const; operator Vector<String>() const; operator Vector<Vector3>() const; operator Vector<Color>() const; @@ -255,8 +332,11 @@ public: Variant(const char *const p_cstring); Variant(const CharType *p_wstring); Variant(const Vector2 &p_vector2); + Variant(const Vector2i &p_vector2i); Variant(const Rect2 &p_rect2); + Variant(const Rect2i &p_rect2i); Variant(const Vector3 &p_vector3); + Variant(const Vector3i &p_vector3i); Variant(const Plane &p_plane); Variant(const ::AABB &p_aabb); Variant(const Quat &p_quat); @@ -273,9 +353,11 @@ public: Variant(const Array &p_array); Variant(const Vector<Plane> &p_array); // helper - Variant(const Vector<uint8_t> &p_raw_array); - Variant(const Vector<int> &p_int_array); - Variant(const Vector<real_t> &p_real_array); + Variant(const Vector<uint8_t> &p_byte_array); + Variant(const Vector<int32_t> &p_int32_array); + Variant(const Vector<int64_t> &p_int64_array); + Variant(const Vector<float> &p_float32_array); + Variant(const Vector<double> &p_float64_array); Variant(const Vector<String> &p_string_array); Variant(const Vector<Vector3> &p_vector3_array); Variant(const Vector<Color> &p_color_array); @@ -395,7 +477,9 @@ public: void operator=(const Variant &p_variant); // only this is enough for all the other types Variant(const Variant &p_variant); - _FORCE_INLINE_ Variant() { type = NIL; } + _FORCE_INLINE_ Variant() { + type = NIL; + } _FORCE_INLINE_ ~Variant() { if (type != Variant::NIL) clear(); } diff --git a/core/variant_call.cpp b/core/variant_call.cpp index 37c35d7c64..9cc08b54e6 100644 --- a/core/variant_call.cpp +++ b/core/variant_call.cpp @@ -383,6 +383,10 @@ struct _VariantCall { 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); @@ -397,6 +401,19 @@ struct _VariantCall { 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); @@ -431,6 +448,10 @@ struct _VariantCall { 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_LOCALMEM0R(Plane, get_any_point); @@ -645,90 +666,139 @@ struct _VariantCall { r_ret = s; } - VCALL_LOCALMEM0R(PackedByteArray, size); - VCALL_LOCALMEM0R(PackedByteArray, empty); - VCALL_LOCALMEM2(PackedByteArray, set); - VCALL_LOCALMEM1R(PackedByteArray, get); - VCALL_LOCALMEM1(PackedByteArray, push_back); - VCALL_LOCALMEM1(PackedByteArray, resize); - VCALL_LOCALMEM2R(PackedByteArray, insert); - VCALL_LOCALMEM1(PackedByteArray, remove); - VCALL_LOCALMEM1(PackedByteArray, append); - VCALL_LOCALMEM1(PackedByteArray, append_array); - VCALL_LOCALMEM0(PackedByteArray, invert); - VCALL_LOCALMEM2R(PackedByteArray, subarray); - - VCALL_LOCALMEM0R(PackedIntArray, size); - VCALL_LOCALMEM0R(PackedIntArray, empty); - VCALL_LOCALMEM2(PackedIntArray, set); - VCALL_LOCALMEM1R(PackedIntArray, get); - VCALL_LOCALMEM1(PackedIntArray, push_back); - VCALL_LOCALMEM1(PackedIntArray, resize); - VCALL_LOCALMEM2R(PackedIntArray, insert); - VCALL_LOCALMEM1(PackedIntArray, remove); - VCALL_LOCALMEM1(PackedIntArray, append); - VCALL_LOCALMEM1(PackedIntArray, append_array); - VCALL_LOCALMEM0(PackedIntArray, invert); - - VCALL_LOCALMEM0R(PackedRealArray, size); - VCALL_LOCALMEM0R(PackedRealArray, empty); - VCALL_LOCALMEM2(PackedRealArray, set); - VCALL_LOCALMEM1R(PackedRealArray, get); - VCALL_LOCALMEM1(PackedRealArray, push_back); - VCALL_LOCALMEM1(PackedRealArray, resize); - VCALL_LOCALMEM2R(PackedRealArray, insert); - VCALL_LOCALMEM1(PackedRealArray, remove); - VCALL_LOCALMEM1(PackedRealArray, append); - VCALL_LOCALMEM1(PackedRealArray, append_array); - VCALL_LOCALMEM0(PackedRealArray, invert); - - VCALL_LOCALMEM0R(PackedStringArray, size); - VCALL_LOCALMEM0R(PackedStringArray, empty); - VCALL_LOCALMEM2(PackedStringArray, set); - VCALL_LOCALMEM1R(PackedStringArray, get); - VCALL_LOCALMEM1(PackedStringArray, push_back); - VCALL_LOCALMEM1(PackedStringArray, resize); - VCALL_LOCALMEM2R(PackedStringArray, insert); - VCALL_LOCALMEM1(PackedStringArray, remove); - VCALL_LOCALMEM1(PackedStringArray, append); - VCALL_LOCALMEM1(PackedStringArray, append_array); - VCALL_LOCALMEM0(PackedStringArray, invert); - - VCALL_LOCALMEM0R(PackedVector2Array, size); - VCALL_LOCALMEM0R(PackedVector2Array, empty); - VCALL_LOCALMEM2(PackedVector2Array, set); - VCALL_LOCALMEM1R(PackedVector2Array, get); - VCALL_LOCALMEM1(PackedVector2Array, push_back); - VCALL_LOCALMEM1(PackedVector2Array, resize); - VCALL_LOCALMEM2R(PackedVector2Array, insert); - VCALL_LOCALMEM1(PackedVector2Array, remove); - VCALL_LOCALMEM1(PackedVector2Array, append); - VCALL_LOCALMEM1(PackedVector2Array, append_array); - VCALL_LOCALMEM0(PackedVector2Array, invert); - - VCALL_LOCALMEM0R(PackedVector3Array, size); - VCALL_LOCALMEM0R(PackedVector3Array, empty); - VCALL_LOCALMEM2(PackedVector3Array, set); - VCALL_LOCALMEM1R(PackedVector3Array, get); - VCALL_LOCALMEM1(PackedVector3Array, push_back); - VCALL_LOCALMEM1(PackedVector3Array, resize); - VCALL_LOCALMEM2R(PackedVector3Array, insert); - VCALL_LOCALMEM1(PackedVector3Array, remove); - VCALL_LOCALMEM1(PackedVector3Array, append); - VCALL_LOCALMEM1(PackedVector3Array, append_array); - VCALL_LOCALMEM0(PackedVector3Array, invert); - - VCALL_LOCALMEM0R(PackedColorArray, size); - VCALL_LOCALMEM0R(PackedColorArray, empty); - VCALL_LOCALMEM2(PackedColorArray, set); - VCALL_LOCALMEM1R(PackedColorArray, get); - VCALL_LOCALMEM1(PackedColorArray, push_back); - VCALL_LOCALMEM1(PackedColorArray, resize); - VCALL_LOCALMEM2R(PackedColorArray, insert); - VCALL_LOCALMEM1(PackedColorArray, remove); - VCALL_LOCALMEM1(PackedColorArray, append); - VCALL_LOCALMEM1(PackedColorArray, append_array); - VCALL_LOCALMEM0(PackedColorArray, invert); +#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_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_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_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_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_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_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_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_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_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(); } @@ -909,6 +979,11 @@ struct _VariantCall { r_ret = Vector2(*p_args[0], *p_args[1]); } + static void Vector2i_init1(Variant &r_ret, const Variant **p_args) { + + r_ret = Vector2i(*p_args[0], *p_args[1]); + } + static void Rect2_init1(Variant &r_ret, const Variant **p_args) { r_ret = Rect2(*p_args[0], *p_args[1]); @@ -919,6 +994,16 @@ struct _VariantCall { r_ret = Rect2(*p_args[0], *p_args[1], *p_args[2], *p_args[3]); } + static void Rect2i_init1(Variant &r_ret, const Variant **p_args) { + + r_ret = Rect2i(*p_args[0], *p_args[1]); + } + + static void Rect2i_init2(Variant &r_ret, const Variant **p_args) { + + r_ret = Rect2i(*p_args[0], *p_args[1], *p_args[2], *p_args[3]); + } + static void Transform2D_init2(Variant &r_ret, const Variant **p_args) { Transform2D m(*p_args[0], *p_args[1]); @@ -939,6 +1024,11 @@ struct _VariantCall { r_ret = Vector3(*p_args[0], *p_args[1], *p_args[2]); } + static void Vector3i_init1(Variant &r_ret, const Variant **p_args) { + + r_ret = Vector3i(*p_args[0], *p_args[1], *p_args[2]); + } + static void Plane_init1(Variant &r_ret, const Variant **p_args) { r_ret = Plane(*p_args[0], *p_args[1], *p_args[2], *p_args[3]); @@ -1195,41 +1285,45 @@ Variant Variant::construct(const Variant::Type p_type, const Variant **p_args, i // atomic types case BOOL: return Variant(false); case INT: return 0; - case REAL: return 0.0f; + case FLOAT: return 0.0f; case STRING: return String(); // math types case VECTOR2: - return Vector2(); // 5 + return Vector2(); case RECT2: return Rect2(); case VECTOR3: return Vector3(); case TRANSFORM2D: return Transform2D(); case PLANE: return Plane(); case QUAT: return Quat(); case AABB: - return ::AABB(); // 10 + return ::AABB(); case BASIS: return Basis(); case TRANSFORM: return Transform(); // misc types case COLOR: return Color(); + case STRING_NAME: + return StringName(); case NODE_PATH: - return NodePath(); // 15 + return NodePath(); case _RID: return RID(); case OBJECT: return (Object *)NULL; case CALLABLE: return Callable(); case SIGNAL: return Signal(); case DICTIONARY: return Dictionary(); case ARRAY: - return Array(); // 20 + return Array(); case PACKED_BYTE_ARRAY: return PackedByteArray(); - case PACKED_INT_ARRAY: return PackedIntArray(); - case PACKED_REAL_ARRAY: return PackedRealArray(); + case PACKED_INT32_ARRAY: return PackedInt32Array(); + case PACKED_INT64_ARRAY: return PackedInt64Array(); + case PACKED_FLOAT32_ARRAY: return PackedFloat32Array(); + case PACKED_FLOAT64_ARRAY: return PackedFloat64Array(); case PACKED_STRING_ARRAY: return PackedStringArray(); case PACKED_VECTOR2_ARRAY: - return PackedVector2Array(); // 25 + return PackedVector2Array(); case PACKED_VECTOR3_ARRAY: return PackedVector3Array(); case PACKED_COLOR_ARRAY: return PackedColorArray(); default: return Variant(); @@ -1251,7 +1345,7 @@ Variant Variant::construct(const Variant::Type p_type, const Variant **p_args, i case INT: { return (int64_t(*p_args[0])); } - case REAL: { + case FLOAT: { return real_t(*p_args[0]); } case STRING: { @@ -1260,33 +1354,44 @@ Variant Variant::construct(const Variant::Type p_type, const Variant **p_args, i case VECTOR2: { return Vector2(*p_args[0]); } + case VECTOR2I: { + return Vector2i(*p_args[0]); + } case RECT2: return (Rect2(*p_args[0])); + case RECT2I: return (Rect2i(*p_args[0])); case VECTOR3: return (Vector3(*p_args[0])); + case VECTOR3I: return (Vector3i(*p_args[0])); case PLANE: return (Plane(*p_args[0])); case QUAT: return (p_args[0]->operator Quat()); case AABB: - return (::AABB(*p_args[0])); // 10 + return (::AABB(*p_args[0])); case BASIS: return (Basis(p_args[0]->operator Basis())); case TRANSFORM: return (Transform(p_args[0]->operator Transform())); // misc types case COLOR: return p_args[0]->type == Variant::STRING ? Color::html(*p_args[0]) : Color::hex(*p_args[0]); + case STRING_NAME: + return (StringName(p_args[0]->operator StringName())); case NODE_PATH: - return (NodePath(p_args[0]->operator NodePath())); // 15 + return (NodePath(p_args[0]->operator NodePath())); case _RID: return (RID(*p_args[0])); case OBJECT: return ((Object *)(p_args[0]->operator Object *())); + case CALLABLE: return ((Callable)(p_args[0]->operator Callable())); + case SIGNAL: return ((Signal)(p_args[0]->operator Signal())); case DICTIONARY: return p_args[0]->operator Dictionary(); case ARRAY: - return p_args[0]->operator Array(); // 20 + return p_args[0]->operator Array(); // arrays case PACKED_BYTE_ARRAY: return (PackedByteArray(*p_args[0])); - case PACKED_INT_ARRAY: return (PackedIntArray(*p_args[0])); - case PACKED_REAL_ARRAY: return (PackedRealArray(*p_args[0])); + case PACKED_INT32_ARRAY: return (PackedInt32Array(*p_args[0])); + case PACKED_INT64_ARRAY: return (PackedInt64Array(*p_args[0])); + case PACKED_FLOAT32_ARRAY: return (PackedFloat32Array(*p_args[0])); + case PACKED_FLOAT64_ARRAY: return (PackedFloat64Array(*p_args[0])); case PACKED_STRING_ARRAY: return (PackedStringArray(*p_args[0])); case PACKED_VECTOR2_ARRAY: - return (PackedVector2Array(*p_args[0])); // 25 + return (PackedVector2Array(*p_args[0])); case PACKED_VECTOR3_ARRAY: return (PackedVector3Array(*p_args[0])); case PACKED_COLOR_ARRAY: return (PackedColorArray(*p_args[0])); default: return Variant(); @@ -1620,7 +1725,7 @@ void register_variant_methods() { 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, REAL, String, similarity, STRING, "text", 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()); @@ -1630,7 +1735,7 @@ void register_variant_methods() { 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_REAL_ARRAY, String, split_floats, STRING, "delimiter", BOOL, "allow_empty", varray(true)); + ADDFUNC2R(STRING, PACKED_FLOAT32_ARRAY, String, split_floats, STRING, "delimiter", BOOL, "allow_empty", varray(true)); ADDFUNC0R(STRING, STRING, String, to_upper, varray()); ADDFUNC0R(STRING, STRING, String, to_lower, varray()); @@ -1677,7 +1782,7 @@ void register_variant_methods() { 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, REAL, String, to_float, varray()); + ADDFUNC0R(STRING, FLOAT, String, to_float, varray()); ADDFUNC0R(STRING, INT, String, hex_to_int, varray()); ADDFUNC1R(STRING, STRING, String, pad_decimals, INT, "digits", varray()); ADDFUNC1R(STRING, STRING, String, pad_zeros, INT, "digits", varray()); @@ -1687,41 +1792,45 @@ void register_variant_methods() { ADDFUNC0R(STRING, PACKED_BYTE_ARRAY, String, to_ascii, varray()); ADDFUNC0R(STRING, PACKED_BYTE_ARRAY, String, to_utf8, varray()); - ADDFUNC0R(VECTOR2, REAL, Vector2, angle, varray()); - ADDFUNC1R(VECTOR2, REAL, Vector2, angle_to, VECTOR2, "to", varray()); - ADDFUNC1R(VECTOR2, REAL, Vector2, angle_to_point, VECTOR2, "to", 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, REAL, Vector2, distance_to, VECTOR2, "to", varray()); - ADDFUNC1R(VECTOR2, REAL, Vector2, distance_squared_to, VECTOR2, "to", varray()); - ADDFUNC0R(VECTOR2, REAL, Vector2, length, varray()); - ADDFUNC0R(VECTOR2, REAL, Vector2, length_squared, 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, REAL, "mod", 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, linear_interpolate, VECTOR2, "b", REAL, "t", varray()); - ADDFUNC2R(VECTOR2, VECTOR2, Vector2, slerp, VECTOR2, "b", REAL, "t", varray()); - ADDFUNC4R(VECTOR2, VECTOR2, Vector2, cubic_interpolate, VECTOR2, "b", VECTOR2, "pre_a", VECTOR2, "post_b", REAL, "t", varray()); - ADDFUNC2R(VECTOR2, VECTOR2, Vector2, move_toward, VECTOR2, "to", REAL, "delta", varray()); - ADDFUNC1R(VECTOR2, VECTOR2, Vector2, rotated, REAL, "phi", varray()); + ADDFUNC2R(VECTOR2, VECTOR2, Vector2, linear_interpolate, 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, REAL, Vector2, aspect, varray()); - ADDFUNC1R(VECTOR2, REAL, Vector2, dot, VECTOR2, "with", 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, REAL, Vector2, cross, VECTOR2, "with", varray()); + ADDFUNC1R(VECTOR2, FLOAT, Vector2, cross, VECTOR2, "with", varray()); ADDFUNC0R(VECTOR2, VECTOR2, Vector2, abs, varray()); - ADDFUNC1R(VECTOR2, VECTOR2, Vector2, clamped, REAL, "length", varray()); + ADDFUNC1R(VECTOR2, VECTOR2, Vector2, clamped, FLOAT, "length", varray()); ADDFUNC0R(VECTOR2, VECTOR2, Vector2, sign, varray()); - ADDFUNC0R(RECT2, REAL, Rect2, get_area, 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()); @@ -1730,30 +1839,43 @@ void register_variant_methods() { 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, REAL, "by", varray()); - ADDFUNC2R(RECT2, RECT2, Rect2, grow_margin, INT, "margin", REAL, "by", varray()); - ADDFUNC4R(RECT2, RECT2, Rect2, grow_individual, REAL, "left", REAL, "top", REAL, "right", REAL, " bottom", 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, REAL, Vector3, angle_to, VECTOR3, "to", varray()); + ADDFUNC1R(VECTOR3, FLOAT, Vector3, angle_to, VECTOR3, "to", varray()); ADDFUNC1R(VECTOR3, VECTOR3, Vector3, direction_to, VECTOR3, "b", varray()); - ADDFUNC1R(VECTOR3, REAL, Vector3, distance_to, VECTOR3, "b", varray()); - ADDFUNC1R(VECTOR3, REAL, Vector3, distance_squared_to, VECTOR3, "b", varray()); - ADDFUNC0R(VECTOR3, REAL, Vector3, length, varray()); - ADDFUNC0R(VECTOR3, REAL, Vector3, length_squared, 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", REAL, "phi", varray()); - ADDFUNC2R(VECTOR3, VECTOR3, Vector3, linear_interpolate, VECTOR3, "b", REAL, "t", varray()); - ADDFUNC2R(VECTOR3, VECTOR3, Vector3, slerp, VECTOR3, "b", REAL, "t", varray()); - ADDFUNC4R(VECTOR3, VECTOR3, Vector3, cubic_interpolate, VECTOR3, "b", VECTOR3, "pre_a", VECTOR3, "post_b", REAL, "t", varray()); - ADDFUNC2R(VECTOR3, VECTOR3, Vector3, move_toward, VECTOR3, "to", REAL, "delta", varray()); - ADDFUNC1R(VECTOR3, REAL, Vector3, dot, VECTOR3, "b", varray()); + ADDFUNC2R(VECTOR3, VECTOR3, Vector3, rotated, VECTOR3, "axis", FLOAT, "phi", varray()); + ADDFUNC2R(VECTOR3, VECTOR3, Vector3, linear_interpolate, 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()); @@ -1761,7 +1883,7 @@ void register_variant_methods() { ADDFUNC0R(VECTOR3, VECTOR3, Vector3, floor, varray()); ADDFUNC0R(VECTOR3, VECTOR3, Vector3, ceil, varray()); ADDFUNC0R(VECTOR3, VECTOR3, Vector3, round, varray()); - ADDFUNC1R(VECTOR3, VECTOR3, Vector3, posmod, REAL, "mod", 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()); @@ -1769,32 +1891,36 @@ void register_variant_methods() { 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()); ADDFUNC0R(PLANE, VECTOR3, Plane, get_any_point, varray()); ADDFUNC1R(PLANE, BOOL, Plane, is_equal_approx, PLANE, "plane", varray()); ADDFUNC1R(PLANE, BOOL, Plane, is_point_over, VECTOR3, "point", varray()); - ADDFUNC1R(PLANE, REAL, Plane, distance_to, VECTOR3, "point", varray()); - ADDFUNC2R(PLANE, BOOL, Plane, has_point, VECTOR3, "point", REAL, "epsilon", varray(CMP_EPSILON)); + 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, REAL, Quat, length, varray()); - ADDFUNC0R(QUAT, REAL, Quat, length_squared, 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, REAL, Quat, dot, QUAT, "b", varray()); + ADDFUNC1R(QUAT, FLOAT, Quat, dot, QUAT, "b", varray()); ADDFUNC1R(QUAT, VECTOR3, Quat, xform, VECTOR3, "v", varray()); - ADDFUNC2R(QUAT, QUAT, Quat, slerp, QUAT, "b", REAL, "t", varray()); - ADDFUNC2R(QUAT, QUAT, Quat, slerpni, QUAT, "b", REAL, "t", varray()); - ADDFUNC4R(QUAT, QUAT, Quat, cubic_slerp, QUAT, "b", QUAT, "pre_a", QUAT, "post_b", REAL, "t", 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", REAL, "angle", 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()); @@ -1804,12 +1930,12 @@ void register_variant_methods() { ADDFUNC0R(COLOR, INT, Color, to_rgba64, varray()); ADDFUNC0R(COLOR, COLOR, Color, inverted, varray()); ADDFUNC0R(COLOR, COLOR, Color, contrasted, varray()); - ADDFUNC2R(COLOR, COLOR, Color, linear_interpolate, COLOR, "b", REAL, "t", varray()); + ADDFUNC2R(COLOR, COLOR, Color, linear_interpolate, COLOR, "b", FLOAT, "t", varray()); ADDFUNC1R(COLOR, COLOR, Color, blend, COLOR, "over", varray()); - ADDFUNC1R(COLOR, COLOR, Color, lightened, REAL, "amount", varray()); - ADDFUNC1R(COLOR, COLOR, Color, darkened, REAL, "amount", 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, REAL, "h", REAL, "s", REAL, "v", REAL, "a", varray(1.0)); + 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()); @@ -1840,13 +1966,13 @@ void register_variant_methods() { 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, Callable, get_method, 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, Signal, get_name, varray()); + ADDFUNC0R(SIGNAL, STRING_NAME, Signal, get_name, varray()); ADDFUNC3R(SIGNAL, INT, Signal, connect, CALLABLE, "callable", ARRAY, "binds", INT, "flags", varray(Array(), 0)); @@ -1903,27 +2029,49 @@ void register_variant_methods() { 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)); - ADDFUNC0R(PACKED_INT_ARRAY, INT, PackedIntArray, size, varray()); - ADDFUNC0R(PACKED_INT_ARRAY, BOOL, PackedIntArray, empty, varray()); - ADDFUNC2(PACKED_INT_ARRAY, NIL, PackedIntArray, set, INT, "idx", INT, "integer", varray()); - ADDFUNC1(PACKED_INT_ARRAY, NIL, PackedIntArray, push_back, INT, "integer", varray()); - ADDFUNC1(PACKED_INT_ARRAY, NIL, PackedIntArray, append, INT, "integer", varray()); - ADDFUNC1(PACKED_INT_ARRAY, NIL, PackedIntArray, append_array, PACKED_INT_ARRAY, "array", varray()); - ADDFUNC1(PACKED_INT_ARRAY, NIL, PackedIntArray, remove, INT, "idx", varray()); - ADDFUNC2R(PACKED_INT_ARRAY, INT, PackedIntArray, insert, INT, "idx", INT, "integer", varray()); - ADDFUNC1(PACKED_INT_ARRAY, NIL, PackedIntArray, resize, INT, "idx", varray()); - ADDFUNC0(PACKED_INT_ARRAY, NIL, PackedIntArray, invert, varray()); - - ADDFUNC0R(PACKED_REAL_ARRAY, INT, PackedRealArray, size, varray()); - ADDFUNC0R(PACKED_REAL_ARRAY, BOOL, PackedRealArray, empty, varray()); - ADDFUNC2(PACKED_REAL_ARRAY, NIL, PackedRealArray, set, INT, "idx", REAL, "value", varray()); - ADDFUNC1(PACKED_REAL_ARRAY, NIL, PackedRealArray, push_back, REAL, "value", varray()); - ADDFUNC1(PACKED_REAL_ARRAY, NIL, PackedRealArray, append, REAL, "value", varray()); - ADDFUNC1(PACKED_REAL_ARRAY, NIL, PackedRealArray, append_array, PACKED_REAL_ARRAY, "array", varray()); - ADDFUNC1(PACKED_REAL_ARRAY, NIL, PackedRealArray, remove, INT, "idx", varray()); - ADDFUNC2R(PACKED_REAL_ARRAY, INT, PackedRealArray, insert, INT, "idx", REAL, "value", varray()); - ADDFUNC1(PACKED_REAL_ARRAY, NIL, PackedRealArray, resize, INT, "idx", varray()); - ADDFUNC0(PACKED_REAL_ARRAY, NIL, PackedRealArray, invert, varray()); + 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()); + 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()); + 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()); + 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()); + ADDFUNC0(PACKED_FLOAT64_ARRAY, NIL, PackedFloat64Array, invert, varray()); ADDFUNC0R(PACKED_STRING_ARRAY, INT, PackedStringArray, size, varray()); ADDFUNC0R(PACKED_STRING_ARRAY, BOOL, PackedStringArray, empty, varray()); @@ -1971,7 +2119,7 @@ void register_variant_methods() { //pointerbased - ADDFUNC0R(AABB, REAL, AABB, get_area, 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()); @@ -1983,95 +2131,100 @@ void register_variant_methods() { 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, REAL, "by", 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, REAL, AABB, get_longest_axis_size, 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, REAL, AABB, get_shortest_axis_size, 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, REAL, Transform2D, get_rotation, 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, REAL, "phi", 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", REAL, "weight", 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, REAL, Basis, determinant, varray()); - ADDFUNC2R(BASIS, BASIS, Basis, rotated, VECTOR3, "axis", REAL, "phi", 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, REAL, Basis, tdotx, VECTOR3, "with", varray()); - ADDFUNC1R(BASIS, REAL, Basis, tdoty, VECTOR3, "with", varray()); - ADDFUNC1R(BASIS, REAL, Basis, tdotz, VECTOR3, "with", 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", REAL, "t", varray()); - ADDFUNC2R(BASIS, BOOL, Basis, is_equal_approx, BASIS, "b", REAL, "epsilon", varray(CMP_EPSILON)); // TODO: Replace in 4.0, see other TODO. + ADDFUNC2R(BASIS, BASIS, Basis, slerp, BASIS, "b", FLOAT, "t", varray()); + ADDFUNC2R(BASIS, BOOL, Basis, is_equal_approx, BASIS, "b", FLOAT, "epsilon", varray(CMP_EPSILON)); // TODO: Replace in 4.0, see other TODO. 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", REAL, "phi", 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", REAL, "weight", 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 */ - _VariantCall::add_constructor(_VariantCall::Vector2_init1, Variant::VECTOR2, "x", Variant::REAL, "y", Variant::REAL); + _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); _VariantCall::add_constructor(_VariantCall::Rect2_init1, Variant::RECT2, "position", Variant::VECTOR2, "size", Variant::VECTOR2); - _VariantCall::add_constructor(_VariantCall::Rect2_init2, Variant::RECT2, "x", Variant::REAL, "y", Variant::REAL, "width", Variant::REAL, "height", Variant::REAL); + _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_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::REAL, "position", Variant::VECTOR2); + _VariantCall::add_constructor(_VariantCall::Transform2D_init2, Variant::TRANSFORM2D, "rotation", Variant::FLOAT, "position", Variant::VECTOR2); _VariantCall::add_constructor(_VariantCall::Transform2D_init3, Variant::TRANSFORM2D, "x_axis", Variant::VECTOR2, "y_axis", Variant::VECTOR2, "origin", Variant::VECTOR2); - _VariantCall::add_constructor(_VariantCall::Vector3_init1, Variant::VECTOR3, "x", Variant::REAL, "y", Variant::REAL, "z", Variant::REAL); + _VariantCall::add_constructor(_VariantCall::Vector3_init1, Variant::VECTOR3, "x", Variant::FLOAT, "y", Variant::FLOAT, "z", Variant::FLOAT); + _VariantCall::add_constructor(_VariantCall::Vector3i_init1, Variant::VECTOR3I, "x", Variant::INT, "y", Variant::INT, "z", Variant::INT); - _VariantCall::add_constructor(_VariantCall::Plane_init1, Variant::PLANE, "a", Variant::REAL, "b", Variant::REAL, "c", Variant::REAL, "d", Variant::REAL); + _VariantCall::add_constructor(_VariantCall::Plane_init1, Variant::PLANE, "a", Variant::FLOAT, "b", Variant::FLOAT, "c", Variant::FLOAT, "d", Variant::FLOAT); _VariantCall::add_constructor(_VariantCall::Plane_init2, Variant::PLANE, "v1", Variant::VECTOR3, "v2", Variant::VECTOR3, "v3", Variant::VECTOR3); - _VariantCall::add_constructor(_VariantCall::Plane_init3, Variant::PLANE, "normal", Variant::VECTOR3, "d", Variant::REAL); + _VariantCall::add_constructor(_VariantCall::Plane_init3, Variant::PLANE, "normal", Variant::VECTOR3, "d", Variant::FLOAT); - _VariantCall::add_constructor(_VariantCall::Quat_init1, Variant::QUAT, "x", Variant::REAL, "y", Variant::REAL, "z", Variant::REAL, "w", Variant::REAL); - _VariantCall::add_constructor(_VariantCall::Quat_init2, Variant::QUAT, "axis", Variant::VECTOR3, "angle", Variant::REAL); + _VariantCall::add_constructor(_VariantCall::Quat_init1, Variant::QUAT, "x", Variant::FLOAT, "y", Variant::FLOAT, "z", Variant::FLOAT, "w", Variant::FLOAT); + _VariantCall::add_constructor(_VariantCall::Quat_init2, Variant::QUAT, "axis", Variant::VECTOR3, "angle", Variant::FLOAT); _VariantCall::add_constructor(_VariantCall::Quat_init3, Variant::QUAT, "euler", Variant::VECTOR3); - _VariantCall::add_constructor(_VariantCall::Color_init1, Variant::COLOR, "r", Variant::REAL, "g", Variant::REAL, "b", Variant::REAL, "a", Variant::REAL); - _VariantCall::add_constructor(_VariantCall::Color_init2, Variant::COLOR, "r", Variant::REAL, "g", Variant::REAL, "b", Variant::REAL); + _VariantCall::add_constructor(_VariantCall::Color_init1, Variant::COLOR, "r", Variant::FLOAT, "g", Variant::FLOAT, "b", Variant::FLOAT, "a", Variant::FLOAT); + _VariantCall::add_constructor(_VariantCall::Color_init2, Variant::COLOR, "r", Variant::FLOAT, "g", Variant::FLOAT, "b", Variant::FLOAT); _VariantCall::add_constructor(_VariantCall::AABB_init1, Variant::AABB, "position", Variant::VECTOR3, "size", Variant::VECTOR3); _VariantCall::add_constructor(_VariantCall::Basis_init1, Variant::BASIS, "x_axis", Variant::VECTOR3, "y_axis", Variant::VECTOR3, "z_axis", Variant::VECTOR3); - _VariantCall::add_constructor(_VariantCall::Basis_init2, Variant::BASIS, "axis", Variant::VECTOR3, "phi", Variant::REAL); + _VariantCall::add_constructor(_VariantCall::Basis_init2, Variant::BASIS, "axis", Variant::VECTOR3, "phi", Variant::FLOAT); _VariantCall::add_constructor(_VariantCall::Transform_init1, Variant::TRANSFORM, "x_axis", Variant::VECTOR3, "y_axis", Variant::VECTOR3, "z_axis", Variant::VECTOR3, "origin", Variant::VECTOR3); _VariantCall::add_constructor(_VariantCall::Transform_init2, Variant::TRANSFORM, "basis", Variant::BASIS, "origin", Variant::VECTOR3); - _VariantCall::add_constructor(_VariantCall::Callable_init2, Variant::CALLABLE, "object", Variant::OBJECT, "method_name", Variant::STRING); - _VariantCall::add_constructor(_VariantCall::Signal_init2, Variant::SIGNAL, "object", Variant::OBJECT, "signal_name", Variant::STRING); + _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 */ @@ -2094,9 +2247,25 @@ void register_variant_methods() { _VariantCall::add_variant_constant(Variant::VECTOR3, "FORWARD", Vector3(0, 0, -1)); _VariantCall::add_variant_constant(Variant::VECTOR3, "BACK", Vector3(0, 0, 1)); + _VariantCall::add_constant(Variant::VECTOR3I, "AXIS_X", Vector3::AXIS_X); + _VariantCall::add_constant(Variant::VECTOR3I, "AXIS_Y", Vector3::AXIS_Y); + _VariantCall::add_constant(Variant::VECTOR3I, "AXIS_Z", Vector3::AXIS_Z); + + _VariantCall::add_variant_constant(Variant::VECTOR3I, "ZERO", Vector3i(0, 0, 0)); + _VariantCall::add_variant_constant(Variant::VECTOR3I, "ONE", Vector3i(1, 1, 1)); + _VariantCall::add_variant_constant(Variant::VECTOR3I, "LEFT", Vector3i(-1, 0, 0)); + _VariantCall::add_variant_constant(Variant::VECTOR3I, "RIGHT", Vector3i(1, 0, 0)); + _VariantCall::add_variant_constant(Variant::VECTOR3I, "UP", Vector3i(0, 1, 0)); + _VariantCall::add_variant_constant(Variant::VECTOR3I, "DOWN", Vector3i(0, -1, 0)); + _VariantCall::add_variant_constant(Variant::VECTOR3I, "FORWARD", Vector3i(0, 0, -1)); + _VariantCall::add_variant_constant(Variant::VECTOR3I, "BACK", Vector3i(0, 0, 1)); + _VariantCall::add_constant(Variant::VECTOR2, "AXIS_X", Vector2::AXIS_X); _VariantCall::add_constant(Variant::VECTOR2, "AXIS_Y", Vector2::AXIS_Y); + _VariantCall::add_constant(Variant::VECTOR2I, "AXIS_X", Vector2::AXIS_X); + _VariantCall::add_constant(Variant::VECTOR2I, "AXIS_Y", Vector2::AXIS_Y); + _VariantCall::add_variant_constant(Variant::VECTOR2, "ZERO", Vector2(0, 0)); _VariantCall::add_variant_constant(Variant::VECTOR2, "ONE", Vector2(1, 1)); _VariantCall::add_variant_constant(Variant::VECTOR2, "INF", Vector2(Math_INF, Math_INF)); @@ -2105,6 +2274,13 @@ void register_variant_methods() { _VariantCall::add_variant_constant(Variant::VECTOR2, "UP", Vector2(0, -1)); _VariantCall::add_variant_constant(Variant::VECTOR2, "DOWN", Vector2(0, 1)); + _VariantCall::add_variant_constant(Variant::VECTOR2I, "ZERO", Vector2i(0, 0)); + _VariantCall::add_variant_constant(Variant::VECTOR2I, "ONE", Vector2i(1, 1)); + _VariantCall::add_variant_constant(Variant::VECTOR2I, "LEFT", Vector2i(-1, 0)); + _VariantCall::add_variant_constant(Variant::VECTOR2I, "RIGHT", Vector2i(1, 0)); + _VariantCall::add_variant_constant(Variant::VECTOR2I, "UP", Vector2i(0, -1)); + _VariantCall::add_variant_constant(Variant::VECTOR2I, "DOWN", Vector2i(0, 1)); + _VariantCall::add_variant_constant(Variant::TRANSFORM2D, "IDENTITY", Transform2D()); _VariantCall::add_variant_constant(Variant::TRANSFORM2D, "FLIP_X", Transform2D(-1, 0, 0, 1, 0, 0)); _VariantCall::add_variant_constant(Variant::TRANSFORM2D, "FLIP_Y", Transform2D(1, 0, 0, -1, 0, 0)); diff --git a/core/variant_op.cpp b/core/variant_op.cpp index 6c98cf4de1..36d1278929 100644 --- a/core/variant_op.cpp +++ b/core/variant_op.cpp @@ -41,11 +41,14 @@ #define CASE_TYPE_ALL_BUT_INT(PREFIX, OP) \ CASE_TYPE(PREFIX, OP, NIL) \ CASE_TYPE(PREFIX, OP, BOOL) \ - CASE_TYPE(PREFIX, OP, REAL) \ + CASE_TYPE(PREFIX, OP, FLOAT) \ CASE_TYPE(PREFIX, OP, STRING) \ CASE_TYPE(PREFIX, OP, VECTOR2) \ + CASE_TYPE(PREFIX, OP, VECTOR2I) \ CASE_TYPE(PREFIX, OP, RECT2) \ + CASE_TYPE(PREFIX, OP, RECT2I) \ CASE_TYPE(PREFIX, OP, VECTOR3) \ + CASE_TYPE(PREFIX, OP, VECTOR3I) \ CASE_TYPE(PREFIX, OP, TRANSFORM2D) \ CASE_TYPE(PREFIX, OP, PLANE) \ CASE_TYPE(PREFIX, OP, QUAT) \ @@ -53,6 +56,7 @@ CASE_TYPE(PREFIX, OP, BASIS) \ CASE_TYPE(PREFIX, OP, TRANSFORM) \ CASE_TYPE(PREFIX, OP, COLOR) \ + CASE_TYPE(PREFIX, OP, STRING_NAME) \ CASE_TYPE(PREFIX, OP, NODE_PATH) \ CASE_TYPE(PREFIX, OP, _RID) \ CASE_TYPE(PREFIX, OP, OBJECT) \ @@ -61,8 +65,10 @@ CASE_TYPE(PREFIX, OP, DICTIONARY) \ CASE_TYPE(PREFIX, OP, ARRAY) \ CASE_TYPE(PREFIX, OP, PACKED_BYTE_ARRAY) \ - CASE_TYPE(PREFIX, OP, PACKED_INT_ARRAY) \ - CASE_TYPE(PREFIX, OP, PACKED_REAL_ARRAY) \ + CASE_TYPE(PREFIX, OP, PACKED_INT32_ARRAY) \ + CASE_TYPE(PREFIX, OP, PACKED_INT64_ARRAY) \ + CASE_TYPE(PREFIX, OP, PACKED_FLOAT32_ARRAY) \ + CASE_TYPE(PREFIX, OP, PACKED_FLOAT64_ARRAY) \ CASE_TYPE(PREFIX, OP, PACKED_STRING_ARRAY) \ CASE_TYPE(PREFIX, OP, PACKED_VECTOR2_ARRAY) \ CASE_TYPE(PREFIX, OP, PACKED_VECTOR3_ARRAY) \ @@ -76,11 +82,14 @@ TYPE(PREFIX, OP, NIL), \ TYPE(PREFIX, OP, BOOL), \ TYPE(PREFIX, OP, INT), \ - TYPE(PREFIX, OP, REAL), \ + TYPE(PREFIX, OP, FLOAT), \ TYPE(PREFIX, OP, STRING), \ TYPE(PREFIX, OP, VECTOR2), \ + TYPE(PREFIX, OP, VECTOR2I), \ TYPE(PREFIX, OP, RECT2), \ + TYPE(PREFIX, OP, RECT2I), \ TYPE(PREFIX, OP, VECTOR3), \ + TYPE(PREFIX, OP, VECTOR3I), \ TYPE(PREFIX, OP, TRANSFORM2D), \ TYPE(PREFIX, OP, PLANE), \ TYPE(PREFIX, OP, QUAT), \ @@ -88,6 +97,7 @@ TYPE(PREFIX, OP, BASIS), \ TYPE(PREFIX, OP, TRANSFORM), \ TYPE(PREFIX, OP, COLOR), \ + TYPE(PREFIX, OP, STRING_NAME), \ TYPE(PREFIX, OP, NODE_PATH), \ TYPE(PREFIX, OP, _RID), \ TYPE(PREFIX, OP, OBJECT), \ @@ -96,8 +106,10 @@ TYPE(PREFIX, OP, DICTIONARY), \ TYPE(PREFIX, OP, ARRAY), \ TYPE(PREFIX, OP, PACKED_BYTE_ARRAY), \ - TYPE(PREFIX, OP, PACKED_INT_ARRAY), \ - TYPE(PREFIX, OP, PACKED_REAL_ARRAY), \ + TYPE(PREFIX, OP, PACKED_INT32_ARRAY), \ + TYPE(PREFIX, OP, PACKED_INT64_ARRAY), \ + TYPE(PREFIX, OP, PACKED_FLOAT32_ARRAY), \ + TYPE(PREFIX, OP, PACKED_FLOAT64_ARRAY), \ TYPE(PREFIX, OP, PACKED_STRING_ARRAY), \ TYPE(PREFIX, OP, PACKED_VECTOR2_ARRAY), \ TYPE(PREFIX, OP, PACKED_VECTOR3_ARRAY), \ @@ -169,21 +181,21 @@ bool Variant::booleanize() const { return; \ } -#define DEFAULT_OP_NUM(m_prefix, m_op_name, m_name, m_op, m_type) \ - CASE_TYPE(m_prefix, m_op_name, m_name) { \ - if (p_b.type == INT) _RETURN(p_a._data.m_type m_op p_b._data._int); \ - if (p_b.type == REAL) _RETURN(p_a._data.m_type m_op p_b._data._real); \ - \ - _RETURN_FAIL \ +#define DEFAULT_OP_NUM(m_prefix, m_op_name, m_name, m_op, m_type) \ + CASE_TYPE(m_prefix, m_op_name, m_name) { \ + if (p_b.type == INT) _RETURN(p_a._data.m_type m_op p_b._data._int); \ + if (p_b.type == FLOAT) _RETURN(p_a._data.m_type m_op p_b._data._float); \ + \ + _RETURN_FAIL \ }; -#define DEFAULT_OP_NUM_NULL(m_prefix, m_op_name, m_name, m_op, m_type) \ - CASE_TYPE(m_prefix, m_op_name, m_name) { \ - if (p_b.type == INT) _RETURN(p_a._data.m_type m_op p_b._data._int); \ - if (p_b.type == REAL) _RETURN(p_a._data.m_type m_op p_b._data._real); \ - if (p_b.type == NIL) _RETURN(!(p_b.type m_op NIL)); \ - \ - _RETURN_FAIL \ +#define DEFAULT_OP_NUM_NULL(m_prefix, m_op_name, m_name, m_op, m_type) \ + CASE_TYPE(m_prefix, m_op_name, m_name) { \ + if (p_b.type == INT) _RETURN(p_a._data.m_type m_op p_b._data._int); \ + if (p_b.type == FLOAT) _RETURN(p_a._data.m_type m_op p_b._data._float); \ + if (p_b.type == NIL) _RETURN(!(p_b.type m_op NIL)); \ + \ + _RETURN_FAIL \ }; #ifdef DEBUG_ENABLED @@ -196,23 +208,23 @@ bool Variant::booleanize() const { } \ _RETURN(p_a._data.m_type / p_b._data._int); \ } \ - if (p_b.type == REAL) { \ - if (p_b._data._real == 0) { \ + if (p_b.type == FLOAT) { \ + if (p_b._data._float == 0) { \ r_valid = false; \ _RETURN("Division By Zero"); \ } \ - _RETURN(p_a._data.m_type / p_b._data._real); \ + _RETURN(p_a._data.m_type / p_b._data._float); \ } \ \ _RETURN_FAIL \ }; #else -#define DEFAULT_OP_NUM_DIV(m_prefix, m_op_name, m_name, m_type) \ - CASE_TYPE(m_prefix, m_op_name, m_name) { \ - if (p_b.type == INT) _RETURN(p_a._data.m_type / p_b._data._int); \ - if (p_b.type == REAL) _RETURN(p_a._data.m_type / p_b._data._real); \ - \ - _RETURN_FAIL \ +#define DEFAULT_OP_NUM_DIV(m_prefix, m_op_name, m_name, m_type) \ + CASE_TYPE(m_prefix, m_op_name, m_name) { \ + if (p_b.type == INT) _RETURN(p_a._data.m_type / p_b._data._int); \ + if (p_b.type == FLOAT) _RETURN(p_a._data.m_type / p_b._data._float); \ + \ + _RETURN_FAIL \ }; #endif @@ -226,33 +238,47 @@ bool Variant::booleanize() const { _RETURN(p_a._data.m_type); \ }; -#define DEFAULT_OP_NUM_VEC(m_prefix, m_op_name, m_name, m_op, m_type) \ - CASE_TYPE(m_prefix, m_op_name, m_name) { \ - if (p_b.type == INT) _RETURN(p_a._data.m_type m_op p_b._data._int); \ - if (p_b.type == REAL) _RETURN(p_a._data.m_type m_op p_b._data._real); \ - if (p_b.type == VECTOR2) _RETURN(p_a._data.m_type m_op *reinterpret_cast<const Vector2 *>(p_b._data._mem)); \ - if (p_b.type == VECTOR3) _RETURN(p_a._data.m_type m_op *reinterpret_cast<const Vector3 *>(p_b._data._mem)); \ - \ - _RETURN_FAIL \ +#define DEFAULT_OP_NUM_VEC(m_prefix, m_op_name, m_name, m_op, m_type) \ + CASE_TYPE(m_prefix, m_op_name, m_name) { \ + if (p_b.type == INT) _RETURN(p_a._data.m_type m_op p_b._data._int); \ + if (p_b.type == FLOAT) _RETURN(p_a._data.m_type m_op p_b._data._float); \ + if (p_b.type == VECTOR2) _RETURN(p_a._data.m_type m_op *reinterpret_cast<const Vector2 *>(p_b._data._mem)); \ + if (p_b.type == VECTOR3) _RETURN(p_a._data.m_type m_op *reinterpret_cast<const Vector3 *>(p_b._data._mem)); \ + if (p_b.type == VECTOR2I) _RETURN(p_a._data.m_type m_op *reinterpret_cast<const Vector2 *>(p_b._data._mem)); \ + if (p_b.type == VECTOR3I) _RETURN(p_a._data.m_type m_op *reinterpret_cast<const Vector3 *>(p_b._data._mem)); \ + \ + _RETURN_FAIL \ }; -#define DEFAULT_OP_STR_REV(m_prefix, m_op_name, m_name, m_op, m_type) \ - CASE_TYPE(m_prefix, m_op_name, m_name) { \ - if (p_b.type == STRING) _RETURN(*reinterpret_cast<const m_type *>(p_b._data._mem) m_op *reinterpret_cast<const String *>(p_a._data._mem)); \ - if (p_b.type == NODE_PATH) _RETURN(*reinterpret_cast<const m_type *>(p_b._data._mem) m_op *reinterpret_cast<const NodePath *>(p_a._data._mem)); \ - \ - _RETURN_FAIL \ +#define DEFAULT_OP_STR_REV(m_prefix, m_op_name, m_name, m_op, m_type) \ + CASE_TYPE(m_prefix, m_op_name, m_name) { \ + if (p_b.type == STRING) _RETURN(*reinterpret_cast<const m_type *>(p_b._data._mem) m_op *reinterpret_cast<const String *>(p_a._data._mem)); \ + if (p_b.type == STRING_NAME) _RETURN(*reinterpret_cast<const m_type *>(p_b._data._mem) m_op *reinterpret_cast<const StringName *>(p_a._data._mem)); \ + if (p_b.type == NODE_PATH) _RETURN(*reinterpret_cast<const m_type *>(p_b._data._mem) m_op *reinterpret_cast<const NodePath *>(p_a._data._mem)); \ + \ + _RETURN_FAIL \ }; -#define DEFAULT_OP_STR(m_prefix, m_op_name, m_name, m_op, m_type) \ - CASE_TYPE(m_prefix, m_op_name, m_name) { \ - if (p_b.type == STRING) _RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem) m_op *reinterpret_cast<const String *>(p_b._data._mem)); \ - if (p_b.type == NODE_PATH) _RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem) m_op *reinterpret_cast<const NodePath *>(p_b._data._mem)); \ - \ - _RETURN_FAIL \ +#define DEFAULT_OP_STR(m_prefix, m_op_name, m_name, m_op, m_type) \ + CASE_TYPE(m_prefix, m_op_name, m_name) { \ + if (p_b.type == STRING) _RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem) m_op *reinterpret_cast<const String *>(p_b._data._mem)); \ + if (p_b.type == STRING_NAME) _RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem) m_op *reinterpret_cast<const StringName *>(p_b._data._mem)); \ + if (p_b.type == NODE_PATH) _RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem) m_op *reinterpret_cast<const NodePath *>(p_b._data._mem)); \ + \ + _RETURN_FAIL \ + }; + +#define DEFAULT_OP_STR_NULL(m_prefix, m_op_name, m_name, m_op, m_type) \ + CASE_TYPE(m_prefix, m_op_name, m_name) { \ + if (p_b.type == STRING) _RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem) m_op *reinterpret_cast<const String *>(p_b._data._mem)); \ + if (p_b.type == STRING_NAME) _RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem) m_op *reinterpret_cast<const StringName *>(p_b._data._mem)); \ + if (p_b.type == NODE_PATH) _RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem) m_op *reinterpret_cast<const NodePath *>(p_b._data._mem)); \ + if (p_b.type == NIL) _RETURN(!(p_b.type m_op NIL)); \ + \ + _RETURN_FAIL \ }; -#define DEFAULT_OP_STR_NULL(m_prefix, m_op_name, m_name, m_op, m_type) \ +#define DEFAULT_OP_STR_NULL_NP(m_prefix, m_op_name, m_name, m_op, m_type) \ CASE_TYPE(m_prefix, m_op_name, m_name) { \ if (p_b.type == STRING) _RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem) m_op *reinterpret_cast<const String *>(p_b._data._mem)); \ if (p_b.type == NODE_PATH) _RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem) m_op *reinterpret_cast<const NodePath *>(p_b._data._mem)); \ @@ -261,6 +287,15 @@ bool Variant::booleanize() const { _RETURN_FAIL \ }; +#define DEFAULT_OP_STR_NULL_SN(m_prefix, m_op_name, m_name, m_op, m_type) \ + CASE_TYPE(m_prefix, m_op_name, m_name) { \ + if (p_b.type == STRING) _RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem) m_op *reinterpret_cast<const String *>(p_b._data._mem)); \ + if (p_b.type == STRING_NAME) _RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem) m_op *reinterpret_cast<const StringName *>(p_b._data._mem)); \ + if (p_b.type == NIL) _RETURN(!(p_b.type m_op NIL)); \ + \ + _RETURN_FAIL \ + }; + #define DEFAULT_OP_LOCALMEM_REV(m_prefix, m_op_name, m_name, m_op, m_type) \ CASE_TYPE(m_prefix, m_op_name, m_name) { \ if (p_b.type == m_name) \ @@ -301,7 +336,7 @@ bool Variant::booleanize() const { CASE_TYPE(m_prefix, m_op_name, m_name) { \ if (p_b.type == m_name) _RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem) m_op *reinterpret_cast<const m_type *>(p_b._data._mem)); \ if (p_b.type == INT) _RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem) m_op p_b._data._int); \ - if (p_b.type == REAL) _RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem) m_op p_b._data._real); \ + if (p_b.type == FLOAT) _RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem) m_op p_b._data._float); \ \ _RETURN_FAIL \ } @@ -361,8 +396,8 @@ bool Variant::booleanize() const { if (p_a.type != p_b.type) \ _RETURN_FAIL \ \ - const Vector<m_type> &array_a = *reinterpret_cast<const Vector<m_type> *>(p_a._data._mem); \ - const Vector<m_type> &array_b = *reinterpret_cast<const Vector<m_type> *>(p_b._data._mem); \ + const Vector<m_type> &array_a = PackedArrayRef<m_type>::get_array(p_a._data.packed_array); \ + const Vector<m_type> &array_b = PackedArrayRef<m_type>::get_array(p_b._data.packed_array); \ \ int a_len = array_a.size(); \ if (a_len m_opa array_b.size()) { \ @@ -385,8 +420,8 @@ bool Variant::booleanize() const { if (p_a.type != p_b.type) \ _RETURN_FAIL; \ \ - const Vector<m_type> &array_a = *reinterpret_cast<const Vector<m_type> *>(p_a._data._mem); \ - const Vector<m_type> &array_b = *reinterpret_cast<const Vector<m_type> *>(p_b._data._mem); \ + const Vector<m_type> &array_a = PackedArrayRef<m_type>::get_array(p_a._data.packed_array); \ + const Vector<m_type> &array_b = PackedArrayRef<m_type>::get_array(p_b._data.packed_array); \ Vector<m_type> sum = array_a; \ sum.append_array(array_b); \ _RETURN(sum); \ @@ -465,24 +500,30 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a, } DEFAULT_OP_NUM_NULL(math, OP_EQUAL, INT, ==, _int); - DEFAULT_OP_NUM_NULL(math, OP_EQUAL, REAL, ==, _real); + DEFAULT_OP_NUM_NULL(math, OP_EQUAL, FLOAT, ==, _float); DEFAULT_OP_STR_NULL(math, OP_EQUAL, STRING, ==, String); DEFAULT_OP_LOCALMEM_NULL(math, OP_EQUAL, VECTOR2, ==, Vector2); + DEFAULT_OP_LOCALMEM_NULL(math, OP_EQUAL, VECTOR2I, ==, Vector2i); DEFAULT_OP_LOCALMEM_NULL(math, OP_EQUAL, RECT2, ==, Rect2); + DEFAULT_OP_LOCALMEM_NULL(math, OP_EQUAL, RECT2I, ==, Rect2i); DEFAULT_OP_PTRREF_NULL(math, OP_EQUAL, TRANSFORM2D, ==, _transform2d); DEFAULT_OP_LOCALMEM_NULL(math, OP_EQUAL, VECTOR3, ==, Vector3); + DEFAULT_OP_LOCALMEM_NULL(math, OP_EQUAL, VECTOR3I, ==, Vector3i); DEFAULT_OP_LOCALMEM_NULL(math, OP_EQUAL, PLANE, ==, Plane); DEFAULT_OP_LOCALMEM_NULL(math, OP_EQUAL, QUAT, ==, Quat); DEFAULT_OP_PTRREF_NULL(math, OP_EQUAL, AABB, ==, _aabb); DEFAULT_OP_PTRREF_NULL(math, OP_EQUAL, BASIS, ==, _basis); DEFAULT_OP_PTRREF_NULL(math, OP_EQUAL, TRANSFORM, ==, _transform); DEFAULT_OP_LOCALMEM_NULL(math, OP_EQUAL, COLOR, ==, Color); - DEFAULT_OP_STR_NULL(math, OP_EQUAL, NODE_PATH, ==, NodePath); + DEFAULT_OP_STR_NULL_SN(math, OP_EQUAL, STRING_NAME, ==, StringName); + DEFAULT_OP_STR_NULL_NP(math, OP_EQUAL, NODE_PATH, ==, NodePath); DEFAULT_OP_LOCALMEM_NULL(math, OP_EQUAL, _RID, ==, RID); DEFAULT_OP_ARRAY_EQ(math, OP_EQUAL, PACKED_BYTE_ARRAY, uint8_t); - DEFAULT_OP_ARRAY_EQ(math, OP_EQUAL, PACKED_INT_ARRAY, int); - DEFAULT_OP_ARRAY_EQ(math, OP_EQUAL, PACKED_REAL_ARRAY, real_t); + DEFAULT_OP_ARRAY_EQ(math, OP_EQUAL, PACKED_INT32_ARRAY, int32_t); + DEFAULT_OP_ARRAY_EQ(math, OP_EQUAL, PACKED_INT64_ARRAY, int64_t); + DEFAULT_OP_ARRAY_EQ(math, OP_EQUAL, PACKED_FLOAT32_ARRAY, float); + DEFAULT_OP_ARRAY_EQ(math, OP_EQUAL, PACKED_FLOAT64_ARRAY, double); DEFAULT_OP_ARRAY_EQ(math, OP_EQUAL, PACKED_STRING_ARRAY, String); DEFAULT_OP_ARRAY_EQ(math, OP_EQUAL, PACKED_VECTOR2_ARRAY, Vector2); DEFAULT_OP_ARRAY_EQ(math, OP_EQUAL, PACKED_VECTOR3_ARRAY, Vector3); @@ -558,24 +599,30 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a, } DEFAULT_OP_NUM_NULL(math, OP_NOT_EQUAL, INT, !=, _int); - DEFAULT_OP_NUM_NULL(math, OP_NOT_EQUAL, REAL, !=, _real); + DEFAULT_OP_NUM_NULL(math, OP_NOT_EQUAL, FLOAT, !=, _float); DEFAULT_OP_STR_NULL(math, OP_NOT_EQUAL, STRING, !=, String); DEFAULT_OP_LOCALMEM_NULL(math, OP_NOT_EQUAL, VECTOR2, !=, Vector2); + DEFAULT_OP_LOCALMEM_NULL(math, OP_NOT_EQUAL, VECTOR2I, !=, Vector2i); DEFAULT_OP_LOCALMEM_NULL(math, OP_NOT_EQUAL, RECT2, !=, Rect2); + DEFAULT_OP_LOCALMEM_NULL(math, OP_NOT_EQUAL, RECT2I, !=, Rect2i); DEFAULT_OP_PTRREF_NULL(math, OP_NOT_EQUAL, TRANSFORM2D, !=, _transform2d); DEFAULT_OP_LOCALMEM_NULL(math, OP_NOT_EQUAL, VECTOR3, !=, Vector3); + DEFAULT_OP_LOCALMEM_NULL(math, OP_NOT_EQUAL, VECTOR3I, !=, Vector3i); DEFAULT_OP_LOCALMEM_NULL(math, OP_NOT_EQUAL, PLANE, !=, Plane); DEFAULT_OP_LOCALMEM_NULL(math, OP_NOT_EQUAL, QUAT, !=, Quat); DEFAULT_OP_PTRREF_NULL(math, OP_NOT_EQUAL, AABB, !=, _aabb); DEFAULT_OP_PTRREF_NULL(math, OP_NOT_EQUAL, BASIS, !=, _basis); DEFAULT_OP_PTRREF_NULL(math, OP_NOT_EQUAL, TRANSFORM, !=, _transform); DEFAULT_OP_LOCALMEM_NULL(math, OP_NOT_EQUAL, COLOR, !=, Color); - DEFAULT_OP_STR_NULL(math, OP_NOT_EQUAL, NODE_PATH, !=, NodePath); + DEFAULT_OP_STR_NULL_SN(math, OP_NOT_EQUAL, STRING_NAME, !=, StringName); + DEFAULT_OP_STR_NULL_NP(math, OP_NOT_EQUAL, NODE_PATH, !=, NodePath); DEFAULT_OP_LOCALMEM_NULL(math, OP_NOT_EQUAL, _RID, !=, RID); DEFAULT_OP_ARRAY_NEQ(math, OP_NOT_EQUAL, PACKED_BYTE_ARRAY, uint8_t); - DEFAULT_OP_ARRAY_NEQ(math, OP_NOT_EQUAL, PACKED_INT_ARRAY, int); - DEFAULT_OP_ARRAY_NEQ(math, OP_NOT_EQUAL, PACKED_REAL_ARRAY, real_t); + DEFAULT_OP_ARRAY_NEQ(math, OP_NOT_EQUAL, PACKED_INT32_ARRAY, int32_t); + DEFAULT_OP_ARRAY_NEQ(math, OP_NOT_EQUAL, PACKED_INT64_ARRAY, int64_t); + DEFAULT_OP_ARRAY_NEQ(math, OP_NOT_EQUAL, PACKED_FLOAT32_ARRAY, float); + DEFAULT_OP_ARRAY_NEQ(math, OP_NOT_EQUAL, PACKED_FLOAT64_ARRAY, double); DEFAULT_OP_ARRAY_NEQ(math, OP_NOT_EQUAL, PACKED_STRING_ARRAY, String); DEFAULT_OP_ARRAY_NEQ(math, OP_NOT_EQUAL, PACKED_VECTOR2_ARRAY, Vector2); DEFAULT_OP_ARRAY_NEQ(math, OP_NOT_EQUAL, PACKED_VECTOR3_ARRAY, Vector3); @@ -625,14 +672,18 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a, } DEFAULT_OP_NUM(math, OP_LESS, INT, <, _int); - DEFAULT_OP_NUM(math, OP_LESS, REAL, <, _real); + DEFAULT_OP_NUM(math, OP_LESS, FLOAT, <, _float); DEFAULT_OP_STR(math, OP_LESS, STRING, <, String); DEFAULT_OP_LOCALMEM(math, OP_LESS, VECTOR2, <, Vector2); + DEFAULT_OP_LOCALMEM(math, OP_LESS, VECTOR2I, <, Vector2i); DEFAULT_OP_LOCALMEM(math, OP_LESS, VECTOR3, <, Vector3); + DEFAULT_OP_LOCALMEM(math, OP_LESS, VECTOR3I, <, Vector3i); DEFAULT_OP_LOCALMEM(math, OP_LESS, _RID, <, RID); DEFAULT_OP_ARRAY_LT(math, OP_LESS, PACKED_BYTE_ARRAY, uint8_t); - DEFAULT_OP_ARRAY_LT(math, OP_LESS, PACKED_INT_ARRAY, int); - DEFAULT_OP_ARRAY_LT(math, OP_LESS, PACKED_REAL_ARRAY, real_t); + DEFAULT_OP_ARRAY_LT(math, OP_LESS, PACKED_INT32_ARRAY, int32_t); + DEFAULT_OP_ARRAY_LT(math, OP_LESS, PACKED_INT64_ARRAY, int64_t); + DEFAULT_OP_ARRAY_LT(math, OP_LESS, PACKED_FLOAT32_ARRAY, float); + DEFAULT_OP_ARRAY_LT(math, OP_LESS, PACKED_FLOAT64_ARRAY, double); DEFAULT_OP_ARRAY_LT(math, OP_LESS, PACKED_STRING_ARRAY, String); DEFAULT_OP_ARRAY_LT(math, OP_LESS, PACKED_VECTOR2_ARRAY, Vector3); DEFAULT_OP_ARRAY_LT(math, OP_LESS, PACKED_VECTOR3_ARRAY, Vector3); @@ -640,6 +691,7 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a, CASE_TYPE(math, OP_LESS, NIL) CASE_TYPE(math, OP_LESS, RECT2) + CASE_TYPE(math, OP_LESS, RECT2I) CASE_TYPE(math, OP_LESS, TRANSFORM2D) CASE_TYPE(math, OP_LESS, PLANE) CASE_TYPE(math, OP_LESS, QUAT) @@ -647,6 +699,7 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a, CASE_TYPE(math, OP_LESS, BASIS) CASE_TYPE(math, OP_LESS, TRANSFORM) CASE_TYPE(math, OP_LESS, COLOR) + CASE_TYPE(math, OP_LESS, STRING_NAME) CASE_TYPE(math, OP_LESS, NODE_PATH) CASE_TYPE(math, OP_LESS, DICTIONARY) _RETURN_FAIL; @@ -660,15 +713,18 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a, } DEFAULT_OP_NUM(math, OP_LESS_EQUAL, INT, <=, _int); - DEFAULT_OP_NUM(math, OP_LESS_EQUAL, REAL, <=, _real); + DEFAULT_OP_NUM(math, OP_LESS_EQUAL, FLOAT, <=, _float); DEFAULT_OP_STR(math, OP_LESS_EQUAL, STRING, <=, String); DEFAULT_OP_LOCALMEM(math, OP_LESS_EQUAL, VECTOR2, <=, Vector2); + DEFAULT_OP_LOCALMEM(math, OP_LESS_EQUAL, VECTOR2I, <=, Vector2i); DEFAULT_OP_LOCALMEM(math, OP_LESS_EQUAL, VECTOR3, <=, Vector3); + DEFAULT_OP_LOCALMEM(math, OP_LESS_EQUAL, VECTOR3I, <=, Vector3i); DEFAULT_OP_LOCALMEM(math, OP_LESS_EQUAL, _RID, <=, RID); CASE_TYPE(math, OP_LESS_EQUAL, NIL) CASE_TYPE(math, OP_LESS_EQUAL, BOOL) CASE_TYPE(math, OP_LESS_EQUAL, RECT2) + CASE_TYPE(math, OP_LESS_EQUAL, RECT2I) CASE_TYPE(math, OP_LESS_EQUAL, TRANSFORM2D) CASE_TYPE(math, OP_LESS_EQUAL, PLANE) CASE_TYPE(math, OP_LESS_EQUAL, QUAT) @@ -676,6 +732,7 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a, CASE_TYPE(math, OP_LESS_EQUAL, BASIS) CASE_TYPE(math, OP_LESS_EQUAL, TRANSFORM) CASE_TYPE(math, OP_LESS_EQUAL, COLOR) + CASE_TYPE(math, OP_LESS_EQUAL, STRING_NAME) CASE_TYPE(math, OP_LESS_EQUAL, NODE_PATH) CASE_TYPE(math, OP_LESS_EQUAL, CALLABLE) CASE_TYPE(math, OP_LESS_EQUAL, SIGNAL) @@ -683,8 +740,10 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a, CASE_TYPE(math, OP_LESS_EQUAL, DICTIONARY) CASE_TYPE(math, OP_LESS_EQUAL, ARRAY) CASE_TYPE(math, OP_LESS_EQUAL, PACKED_BYTE_ARRAY); - CASE_TYPE(math, OP_LESS_EQUAL, PACKED_INT_ARRAY); - CASE_TYPE(math, OP_LESS_EQUAL, PACKED_REAL_ARRAY); + CASE_TYPE(math, OP_LESS_EQUAL, PACKED_INT32_ARRAY); + CASE_TYPE(math, OP_LESS_EQUAL, PACKED_INT64_ARRAY); + CASE_TYPE(math, OP_LESS_EQUAL, PACKED_FLOAT32_ARRAY); + CASE_TYPE(math, OP_LESS_EQUAL, PACKED_FLOAT64_ARRAY); CASE_TYPE(math, OP_LESS_EQUAL, PACKED_STRING_ARRAY); CASE_TYPE(math, OP_LESS_EQUAL, PACKED_VECTOR2_ARRAY); CASE_TYPE(math, OP_LESS_EQUAL, PACKED_VECTOR3_ARRAY); @@ -732,14 +791,18 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a, } DEFAULT_OP_NUM(math, OP_GREATER, INT, >, _int); - DEFAULT_OP_NUM(math, OP_GREATER, REAL, >, _real); + DEFAULT_OP_NUM(math, OP_GREATER, FLOAT, >, _float); DEFAULT_OP_STR_REV(math, OP_GREATER, STRING, <, String); DEFAULT_OP_LOCALMEM_REV(math, OP_GREATER, VECTOR2, <, Vector2); + DEFAULT_OP_LOCALMEM_REV(math, OP_GREATER, VECTOR2I, <, Vector2i); DEFAULT_OP_LOCALMEM_REV(math, OP_GREATER, VECTOR3, <, Vector3); + DEFAULT_OP_LOCALMEM_REV(math, OP_GREATER, VECTOR3I, <, Vector3i); DEFAULT_OP_LOCALMEM_REV(math, OP_GREATER, _RID, <, RID); DEFAULT_OP_ARRAY_GT(math, OP_GREATER, PACKED_BYTE_ARRAY, uint8_t); - DEFAULT_OP_ARRAY_GT(math, OP_GREATER, PACKED_INT_ARRAY, int); - DEFAULT_OP_ARRAY_GT(math, OP_GREATER, PACKED_REAL_ARRAY, real_t); + DEFAULT_OP_ARRAY_GT(math, OP_GREATER, PACKED_INT32_ARRAY, int32_t); + DEFAULT_OP_ARRAY_GT(math, OP_GREATER, PACKED_INT64_ARRAY, int64_t); + DEFAULT_OP_ARRAY_GT(math, OP_GREATER, PACKED_FLOAT32_ARRAY, float); + DEFAULT_OP_ARRAY_GT(math, OP_GREATER, PACKED_FLOAT64_ARRAY, double); DEFAULT_OP_ARRAY_GT(math, OP_GREATER, PACKED_STRING_ARRAY, String); DEFAULT_OP_ARRAY_GT(math, OP_GREATER, PACKED_VECTOR2_ARRAY, Vector3); DEFAULT_OP_ARRAY_GT(math, OP_GREATER, PACKED_VECTOR3_ARRAY, Vector3); @@ -747,6 +810,7 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a, CASE_TYPE(math, OP_GREATER, NIL) CASE_TYPE(math, OP_GREATER, RECT2) + CASE_TYPE(math, OP_GREATER, RECT2I) CASE_TYPE(math, OP_GREATER, TRANSFORM2D) CASE_TYPE(math, OP_GREATER, PLANE) CASE_TYPE(math, OP_GREATER, QUAT) @@ -754,6 +818,7 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a, CASE_TYPE(math, OP_GREATER, BASIS) CASE_TYPE(math, OP_GREATER, TRANSFORM) CASE_TYPE(math, OP_GREATER, COLOR) + CASE_TYPE(math, OP_GREATER, STRING_NAME) CASE_TYPE(math, OP_GREATER, NODE_PATH) CASE_TYPE(math, OP_GREATER, DICTIONARY) CASE_TYPE(math, OP_GREATER, CALLABLE) @@ -770,15 +835,18 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a, } DEFAULT_OP_NUM(math, OP_GREATER_EQUAL, INT, >=, _int); - DEFAULT_OP_NUM(math, OP_GREATER_EQUAL, REAL, >=, _real); + DEFAULT_OP_NUM(math, OP_GREATER_EQUAL, FLOAT, >=, _float); DEFAULT_OP_STR_REV(math, OP_GREATER_EQUAL, STRING, <=, String); DEFAULT_OP_LOCALMEM_REV(math, OP_GREATER_EQUAL, VECTOR2, <=, Vector2); + DEFAULT_OP_LOCALMEM_REV(math, OP_GREATER_EQUAL, VECTOR2I, <=, Vector2i); DEFAULT_OP_LOCALMEM_REV(math, OP_GREATER_EQUAL, VECTOR3, <=, Vector3); + DEFAULT_OP_LOCALMEM_REV(math, OP_GREATER_EQUAL, VECTOR3I, <=, Vector3i); DEFAULT_OP_LOCALMEM_REV(math, OP_GREATER_EQUAL, _RID, <=, RID); CASE_TYPE(math, OP_GREATER_EQUAL, NIL) CASE_TYPE(math, OP_GREATER_EQUAL, BOOL) CASE_TYPE(math, OP_GREATER_EQUAL, RECT2) + CASE_TYPE(math, OP_GREATER_EQUAL, RECT2I) CASE_TYPE(math, OP_GREATER_EQUAL, TRANSFORM2D) CASE_TYPE(math, OP_GREATER_EQUAL, PLANE) CASE_TYPE(math, OP_GREATER_EQUAL, QUAT) @@ -786,6 +854,7 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a, CASE_TYPE(math, OP_GREATER_EQUAL, BASIS) CASE_TYPE(math, OP_GREATER_EQUAL, TRANSFORM) CASE_TYPE(math, OP_GREATER_EQUAL, COLOR) + CASE_TYPE(math, OP_GREATER_EQUAL, STRING_NAME) CASE_TYPE(math, OP_GREATER_EQUAL, NODE_PATH) CASE_TYPE(math, OP_GREATER_EQUAL, CALLABLE) CASE_TYPE(math, OP_GREATER_EQUAL, SIGNAL) @@ -793,8 +862,10 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a, CASE_TYPE(math, OP_GREATER_EQUAL, DICTIONARY) CASE_TYPE(math, OP_GREATER_EQUAL, ARRAY) CASE_TYPE(math, OP_GREATER_EQUAL, PACKED_BYTE_ARRAY); - CASE_TYPE(math, OP_GREATER_EQUAL, PACKED_INT_ARRAY); - CASE_TYPE(math, OP_GREATER_EQUAL, PACKED_REAL_ARRAY); + CASE_TYPE(math, OP_GREATER_EQUAL, PACKED_INT32_ARRAY); + CASE_TYPE(math, OP_GREATER_EQUAL, PACKED_INT64_ARRAY); + CASE_TYPE(math, OP_GREATER_EQUAL, PACKED_FLOAT32_ARRAY); + CASE_TYPE(math, OP_GREATER_EQUAL, PACKED_FLOAT64_ARRAY); CASE_TYPE(math, OP_GREATER_EQUAL, PACKED_STRING_ARRAY); CASE_TYPE(math, OP_GREATER_EQUAL, PACKED_VECTOR2_ARRAY); CASE_TYPE(math, OP_GREATER_EQUAL, PACKED_VECTOR3_ARRAY); @@ -821,16 +892,20 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a, } DEFAULT_OP_NUM(math, OP_ADD, INT, +, _int); - DEFAULT_OP_NUM(math, OP_ADD, REAL, +, _real); + DEFAULT_OP_NUM(math, OP_ADD, FLOAT, +, _float); DEFAULT_OP_STR(math, OP_ADD, STRING, +, String); DEFAULT_OP_LOCALMEM(math, OP_ADD, VECTOR2, +, Vector2); + DEFAULT_OP_LOCALMEM(math, OP_ADD, VECTOR2I, +, Vector2i); DEFAULT_OP_LOCALMEM(math, OP_ADD, VECTOR3, +, Vector3); + DEFAULT_OP_LOCALMEM(math, OP_ADD, VECTOR3I, +, Vector3i); DEFAULT_OP_LOCALMEM(math, OP_ADD, QUAT, +, Quat); DEFAULT_OP_LOCALMEM(math, OP_ADD, COLOR, +, Color); DEFAULT_OP_ARRAY_ADD(math, OP_ADD, PACKED_BYTE_ARRAY, uint8_t); - DEFAULT_OP_ARRAY_ADD(math, OP_ADD, PACKED_INT_ARRAY, int); - DEFAULT_OP_ARRAY_ADD(math, OP_ADD, PACKED_REAL_ARRAY, real_t); + DEFAULT_OP_ARRAY_ADD(math, OP_ADD, PACKED_INT32_ARRAY, int32_t); + DEFAULT_OP_ARRAY_ADD(math, OP_ADD, PACKED_INT64_ARRAY, int64_t); + DEFAULT_OP_ARRAY_ADD(math, OP_ADD, PACKED_FLOAT32_ARRAY, float); + DEFAULT_OP_ARRAY_ADD(math, OP_ADD, PACKED_FLOAT64_ARRAY, double); DEFAULT_OP_ARRAY_ADD(math, OP_ADD, PACKED_STRING_ARRAY, String); DEFAULT_OP_ARRAY_ADD(math, OP_ADD, PACKED_VECTOR2_ARRAY, Vector2); DEFAULT_OP_ARRAY_ADD(math, OP_ADD, PACKED_VECTOR3_ARRAY, Vector3); @@ -839,11 +914,13 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a, CASE_TYPE(math, OP_ADD, NIL) CASE_TYPE(math, OP_ADD, BOOL) CASE_TYPE(math, OP_ADD, RECT2) + CASE_TYPE(math, OP_ADD, RECT2I) CASE_TYPE(math, OP_ADD, TRANSFORM2D) CASE_TYPE(math, OP_ADD, PLANE) CASE_TYPE(math, OP_ADD, AABB) CASE_TYPE(math, OP_ADD, BASIS) CASE_TYPE(math, OP_ADD, TRANSFORM) + CASE_TYPE(math, OP_ADD, STRING_NAME) CASE_TYPE(math, OP_ADD, NODE_PATH) CASE_TYPE(math, OP_ADD, _RID) CASE_TYPE(math, OP_ADD, OBJECT) @@ -856,9 +933,11 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a, SWITCH_OP(math, OP_SUBTRACT, p_a.type) { DEFAULT_OP_NUM(math, OP_SUBTRACT, INT, -, _int); - DEFAULT_OP_NUM(math, OP_SUBTRACT, REAL, -, _real); + DEFAULT_OP_NUM(math, OP_SUBTRACT, FLOAT, -, _float); DEFAULT_OP_LOCALMEM(math, OP_SUBTRACT, VECTOR2, -, Vector2); + DEFAULT_OP_LOCALMEM(math, OP_SUBTRACT, VECTOR2I, -, Vector2i); DEFAULT_OP_LOCALMEM(math, OP_SUBTRACT, VECTOR3, -, Vector3); + DEFAULT_OP_LOCALMEM(math, OP_SUBTRACT, VECTOR3I, -, Vector3i); DEFAULT_OP_LOCALMEM(math, OP_SUBTRACT, QUAT, -, Quat); DEFAULT_OP_LOCALMEM(math, OP_SUBTRACT, COLOR, -, Color); @@ -866,11 +945,13 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a, CASE_TYPE(math, OP_SUBTRACT, BOOL) CASE_TYPE(math, OP_SUBTRACT, STRING) CASE_TYPE(math, OP_SUBTRACT, RECT2) + CASE_TYPE(math, OP_SUBTRACT, RECT2I) CASE_TYPE(math, OP_SUBTRACT, TRANSFORM2D) CASE_TYPE(math, OP_SUBTRACT, PLANE) CASE_TYPE(math, OP_SUBTRACT, AABB) CASE_TYPE(math, OP_SUBTRACT, BASIS) CASE_TYPE(math, OP_SUBTRACT, TRANSFORM) + CASE_TYPE(math, OP_SUBTRACT, STRING_NAME) CASE_TYPE(math, OP_SUBTRACT, NODE_PATH) CASE_TYPE(math, OP_SUBTRACT, _RID) CASE_TYPE(math, OP_SUBTRACT, OBJECT) @@ -880,8 +961,10 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a, CASE_TYPE(math, OP_SUBTRACT, DICTIONARY) CASE_TYPE(math, OP_SUBTRACT, ARRAY) CASE_TYPE(math, OP_SUBTRACT, PACKED_BYTE_ARRAY); - CASE_TYPE(math, OP_SUBTRACT, PACKED_INT_ARRAY); - CASE_TYPE(math, OP_SUBTRACT, PACKED_REAL_ARRAY); + CASE_TYPE(math, OP_SUBTRACT, PACKED_INT32_ARRAY); + CASE_TYPE(math, OP_SUBTRACT, PACKED_INT64_ARRAY); + CASE_TYPE(math, OP_SUBTRACT, PACKED_FLOAT32_ARRAY); + CASE_TYPE(math, OP_SUBTRACT, PACKED_FLOAT64_ARRAY); CASE_TYPE(math, OP_SUBTRACT, PACKED_STRING_ARRAY); CASE_TYPE(math, OP_SUBTRACT, PACKED_VECTOR2_ARRAY); CASE_TYPE(math, OP_SUBTRACT, PACKED_VECTOR3_ARRAY); @@ -910,8 +993,8 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a, case QUAT: { _RETURN(*reinterpret_cast<const Quat *>(p_a._data._mem) * *reinterpret_cast<const Quat *>(p_b._data._mem)); } - case REAL: { - _RETURN(*reinterpret_cast<const Quat *>(p_a._data._mem) * p_b._data._real); + case FLOAT: { + _RETURN(*reinterpret_cast<const Quat *>(p_a._data._mem) * p_b._data._float); } default: _RETURN_FAIL; } @@ -942,17 +1025,21 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a, } DEFAULT_OP_NUM_VEC(math, OP_MULTIPLY, INT, *, _int); - DEFAULT_OP_NUM_VEC(math, OP_MULTIPLY, REAL, *, _real); + DEFAULT_OP_NUM_VEC(math, OP_MULTIPLY, FLOAT, *, _float); DEFAULT_OP_LOCALMEM_NUM(math, OP_MULTIPLY, VECTOR2, *, Vector2); + DEFAULT_OP_LOCALMEM_NUM(math, OP_MULTIPLY, VECTOR2I, *, Vector2i); DEFAULT_OP_LOCALMEM_NUM(math, OP_MULTIPLY, VECTOR3, *, Vector3); + DEFAULT_OP_LOCALMEM_NUM(math, OP_MULTIPLY, VECTOR3I, *, Vector3i); DEFAULT_OP_LOCALMEM_NUM(math, OP_MULTIPLY, COLOR, *, Color); CASE_TYPE(math, OP_MULTIPLY, NIL) CASE_TYPE(math, OP_MULTIPLY, BOOL) CASE_TYPE(math, OP_MULTIPLY, STRING) CASE_TYPE(math, OP_MULTIPLY, RECT2) + CASE_TYPE(math, OP_MULTIPLY, RECT2I) CASE_TYPE(math, OP_MULTIPLY, PLANE) CASE_TYPE(math, OP_MULTIPLY, AABB) + CASE_TYPE(math, OP_MULTIPLY, STRING_NAME) CASE_TYPE(math, OP_MULTIPLY, NODE_PATH) CASE_TYPE(math, OP_MULTIPLY, _RID) CASE_TYPE(math, OP_MULTIPLY, OBJECT) @@ -962,8 +1049,10 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a, CASE_TYPE(math, OP_MULTIPLY, DICTIONARY) CASE_TYPE(math, OP_MULTIPLY, ARRAY) CASE_TYPE(math, OP_MULTIPLY, PACKED_BYTE_ARRAY); - CASE_TYPE(math, OP_MULTIPLY, PACKED_INT_ARRAY); - CASE_TYPE(math, OP_MULTIPLY, PACKED_REAL_ARRAY); + CASE_TYPE(math, OP_MULTIPLY, PACKED_INT32_ARRAY); + CASE_TYPE(math, OP_MULTIPLY, PACKED_INT64_ARRAY); + CASE_TYPE(math, OP_MULTIPLY, PACKED_FLOAT32_ARRAY); + CASE_TYPE(math, OP_MULTIPLY, PACKED_FLOAT64_ARRAY); CASE_TYPE(math, OP_MULTIPLY, PACKED_STRING_ARRAY); CASE_TYPE(math, OP_MULTIPLY, PACKED_VECTOR2_ARRAY); CASE_TYPE(math, OP_MULTIPLY, PACKED_VECTOR3_ARRAY); @@ -973,32 +1062,36 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a, SWITCH_OP(math, OP_DIVIDE, p_a.type) { CASE_TYPE(math, OP_DIVIDE, QUAT) { - if (p_b.type != REAL) + if (p_b.type != FLOAT) _RETURN_FAIL; #ifdef DEBUG_ENABLED - if (p_b._data._real == 0) { + if (p_b._data._float == 0) { r_valid = false; _RETURN("Division By Zero"); } #endif - _RETURN(*reinterpret_cast<const Quat *>(p_a._data._mem) / p_b._data._real); + _RETURN(*reinterpret_cast<const Quat *>(p_a._data._mem) / p_b._data._float); } DEFAULT_OP_NUM_DIV(math, OP_DIVIDE, INT, _int); - DEFAULT_OP_NUM_DIV(math, OP_DIVIDE, REAL, _real); + DEFAULT_OP_NUM_DIV(math, OP_DIVIDE, FLOAT, _float); DEFAULT_OP_LOCALMEM_NUM(math, OP_DIVIDE, VECTOR2, /, Vector2); + DEFAULT_OP_LOCALMEM_NUM(math, OP_DIVIDE, VECTOR2I, /, Vector2i); DEFAULT_OP_LOCALMEM_NUM(math, OP_DIVIDE, VECTOR3, /, Vector3); + DEFAULT_OP_LOCALMEM_NUM(math, OP_DIVIDE, VECTOR3I, /, Vector3i); DEFAULT_OP_LOCALMEM_NUM(math, OP_DIVIDE, COLOR, /, Color); CASE_TYPE(math, OP_DIVIDE, NIL) CASE_TYPE(math, OP_DIVIDE, BOOL) CASE_TYPE(math, OP_DIVIDE, STRING) CASE_TYPE(math, OP_DIVIDE, RECT2) + CASE_TYPE(math, OP_DIVIDE, RECT2I) CASE_TYPE(math, OP_DIVIDE, TRANSFORM2D) CASE_TYPE(math, OP_DIVIDE, PLANE) CASE_TYPE(math, OP_DIVIDE, AABB) CASE_TYPE(math, OP_DIVIDE, BASIS) CASE_TYPE(math, OP_DIVIDE, TRANSFORM) + CASE_TYPE(math, OP_DIVIDE, STRING_NAME) CASE_TYPE(math, OP_DIVIDE, NODE_PATH) CASE_TYPE(math, OP_DIVIDE, _RID) CASE_TYPE(math, OP_DIVIDE, OBJECT) @@ -1008,8 +1101,10 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a, CASE_TYPE(math, OP_DIVIDE, DICTIONARY) CASE_TYPE(math, OP_DIVIDE, ARRAY) CASE_TYPE(math, OP_DIVIDE, PACKED_BYTE_ARRAY); - CASE_TYPE(math, OP_DIVIDE, PACKED_INT_ARRAY); - CASE_TYPE(math, OP_DIVIDE, PACKED_REAL_ARRAY); + CASE_TYPE(math, OP_DIVIDE, PACKED_INT32_ARRAY); + CASE_TYPE(math, OP_DIVIDE, PACKED_INT64_ARRAY); + CASE_TYPE(math, OP_DIVIDE, PACKED_FLOAT32_ARRAY); + CASE_TYPE(math, OP_DIVIDE, PACKED_FLOAT64_ARRAY); CASE_TYPE(math, OP_DIVIDE, PACKED_STRING_ARRAY); CASE_TYPE(math, OP_DIVIDE, PACKED_VECTOR2_ARRAY); CASE_TYPE(math, OP_DIVIDE, PACKED_VECTOR3_ARRAY); @@ -1019,21 +1114,25 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a, SWITCH_OP(math, OP_POSITIVE, p_a.type) { DEFAULT_OP_NUM_POS(math, OP_POSITIVE, INT, _int); - DEFAULT_OP_NUM_POS(math, OP_POSITIVE, REAL, _real); + DEFAULT_OP_NUM_POS(math, OP_POSITIVE, FLOAT, _float); DEFAULT_OP_LOCALMEM_POS(math, OP_POSITIVE, VECTOR3, Vector3); + DEFAULT_OP_LOCALMEM_POS(math, OP_POSITIVE, VECTOR3I, Vector3i); DEFAULT_OP_LOCALMEM_POS(math, OP_POSITIVE, PLANE, Plane); DEFAULT_OP_LOCALMEM_POS(math, OP_POSITIVE, QUAT, Quat); DEFAULT_OP_LOCALMEM_POS(math, OP_POSITIVE, VECTOR2, Vector2); + DEFAULT_OP_LOCALMEM_POS(math, OP_POSITIVE, VECTOR2I, Vector2i); CASE_TYPE(math, OP_POSITIVE, NIL) CASE_TYPE(math, OP_POSITIVE, BOOL) CASE_TYPE(math, OP_POSITIVE, STRING) CASE_TYPE(math, OP_POSITIVE, RECT2) + CASE_TYPE(math, OP_POSITIVE, RECT2I) CASE_TYPE(math, OP_POSITIVE, TRANSFORM2D) CASE_TYPE(math, OP_POSITIVE, AABB) CASE_TYPE(math, OP_POSITIVE, BASIS) CASE_TYPE(math, OP_POSITIVE, TRANSFORM) CASE_TYPE(math, OP_POSITIVE, COLOR) + CASE_TYPE(math, OP_POSITIVE, STRING_NAME) CASE_TYPE(math, OP_POSITIVE, NODE_PATH) CASE_TYPE(math, OP_POSITIVE, _RID) CASE_TYPE(math, OP_POSITIVE, OBJECT) @@ -1043,8 +1142,10 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a, CASE_TYPE(math, OP_POSITIVE, DICTIONARY) CASE_TYPE(math, OP_POSITIVE, ARRAY) CASE_TYPE(math, OP_POSITIVE, PACKED_BYTE_ARRAY) - CASE_TYPE(math, OP_POSITIVE, PACKED_INT_ARRAY) - CASE_TYPE(math, OP_POSITIVE, PACKED_REAL_ARRAY) + CASE_TYPE(math, OP_POSITIVE, PACKED_INT32_ARRAY) + CASE_TYPE(math, OP_POSITIVE, PACKED_INT64_ARRAY) + CASE_TYPE(math, OP_POSITIVE, PACKED_FLOAT32_ARRAY) + CASE_TYPE(math, OP_POSITIVE, PACKED_FLOAT64_ARRAY) CASE_TYPE(math, OP_POSITIVE, PACKED_STRING_ARRAY) CASE_TYPE(math, OP_POSITIVE, PACKED_VECTOR2_ARRAY) CASE_TYPE(math, OP_POSITIVE, PACKED_VECTOR3_ARRAY) @@ -1054,10 +1155,12 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a, SWITCH_OP(math, OP_NEGATE, p_a.type) { DEFAULT_OP_NUM_NEG(math, OP_NEGATE, INT, _int); - DEFAULT_OP_NUM_NEG(math, OP_NEGATE, REAL, _real); + DEFAULT_OP_NUM_NEG(math, OP_NEGATE, FLOAT, _float); DEFAULT_OP_LOCALMEM_NEG(math, OP_NEGATE, VECTOR2, Vector2); + DEFAULT_OP_LOCALMEM_NEG(math, OP_NEGATE, VECTOR2I, Vector2i); DEFAULT_OP_LOCALMEM_NEG(math, OP_NEGATE, VECTOR3, Vector3); + DEFAULT_OP_LOCALMEM_NEG(math, OP_NEGATE, VECTOR3I, Vector3i); DEFAULT_OP_LOCALMEM_NEG(math, OP_NEGATE, PLANE, Plane); DEFAULT_OP_LOCALMEM_NEG(math, OP_NEGATE, QUAT, Quat); DEFAULT_OP_LOCALMEM_NEG(math, OP_NEGATE, COLOR, Color); @@ -1066,10 +1169,12 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a, CASE_TYPE(math, OP_NEGATE, BOOL) CASE_TYPE(math, OP_NEGATE, STRING) CASE_TYPE(math, OP_NEGATE, RECT2) + CASE_TYPE(math, OP_NEGATE, RECT2I) CASE_TYPE(math, OP_NEGATE, TRANSFORM2D) CASE_TYPE(math, OP_NEGATE, AABB) CASE_TYPE(math, OP_NEGATE, BASIS) CASE_TYPE(math, OP_NEGATE, TRANSFORM) + CASE_TYPE(math, OP_NEGATE, STRING_NAME) CASE_TYPE(math, OP_NEGATE, NODE_PATH) CASE_TYPE(math, OP_NEGATE, _RID) CASE_TYPE(math, OP_NEGATE, OBJECT) @@ -1079,8 +1184,10 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a, CASE_TYPE(math, OP_NEGATE, DICTIONARY) CASE_TYPE(math, OP_NEGATE, ARRAY) CASE_TYPE(math, OP_NEGATE, PACKED_BYTE_ARRAY) - CASE_TYPE(math, OP_NEGATE, PACKED_INT_ARRAY) - CASE_TYPE(math, OP_NEGATE, PACKED_REAL_ARRAY) + CASE_TYPE(math, OP_NEGATE, PACKED_INT32_ARRAY) + CASE_TYPE(math, OP_NEGATE, PACKED_INT64_ARRAY) + CASE_TYPE(math, OP_NEGATE, PACKED_FLOAT32_ARRAY) + CASE_TYPE(math, OP_NEGATE, PACKED_FLOAT64_ARRAY) CASE_TYPE(math, OP_NEGATE, PACKED_STRING_ARRAY) CASE_TYPE(math, OP_NEGATE, PACKED_VECTOR2_ARRAY) CASE_TYPE(math, OP_NEGATE, PACKED_VECTOR3_ARRAY) @@ -1122,10 +1229,13 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a, CASE_TYPE(math, OP_MODULE, NIL) CASE_TYPE(math, OP_MODULE, BOOL) - CASE_TYPE(math, OP_MODULE, REAL) + CASE_TYPE(math, OP_MODULE, FLOAT) CASE_TYPE(math, OP_MODULE, VECTOR2) + CASE_TYPE(math, OP_MODULE, VECTOR2I) CASE_TYPE(math, OP_MODULE, RECT2) + CASE_TYPE(math, OP_MODULE, RECT2I) CASE_TYPE(math, OP_MODULE, VECTOR3) + CASE_TYPE(math, OP_MODULE, VECTOR3I) CASE_TYPE(math, OP_MODULE, TRANSFORM2D) CASE_TYPE(math, OP_MODULE, PLANE) CASE_TYPE(math, OP_MODULE, QUAT) @@ -1133,6 +1243,7 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a, CASE_TYPE(math, OP_MODULE, BASIS) CASE_TYPE(math, OP_MODULE, TRANSFORM) CASE_TYPE(math, OP_MODULE, COLOR) + CASE_TYPE(math, OP_MODULE, STRING_NAME) CASE_TYPE(math, OP_MODULE, NODE_PATH) CASE_TYPE(math, OP_MODULE, _RID) CASE_TYPE(math, OP_MODULE, OBJECT) @@ -1142,8 +1253,10 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a, CASE_TYPE(math, OP_MODULE, DICTIONARY) CASE_TYPE(math, OP_MODULE, ARRAY) CASE_TYPE(math, OP_MODULE, PACKED_BYTE_ARRAY) - CASE_TYPE(math, OP_MODULE, PACKED_INT_ARRAY) - CASE_TYPE(math, OP_MODULE, PACKED_REAL_ARRAY) + CASE_TYPE(math, OP_MODULE, PACKED_INT32_ARRAY) + CASE_TYPE(math, OP_MODULE, PACKED_INT64_ARRAY) + CASE_TYPE(math, OP_MODULE, PACKED_FLOAT32_ARRAY) + CASE_TYPE(math, OP_MODULE, PACKED_FLOAT64_ARRAY) CASE_TYPE(math, OP_MODULE, PACKED_STRING_ARRAY) CASE_TYPE(math, OP_MODULE, PACKED_VECTOR2_ARRAY) CASE_TYPE(math, OP_MODULE, PACKED_VECTOR3_ARRAY) @@ -1280,13 +1393,35 @@ void Variant::set_named(const StringName &p_index, const Variant &p_value, bool v->y = p_value._data._int; valid = true; } - } else if (p_value.type == Variant::REAL) { + } else if (p_value.type == Variant::FLOAT) { Vector2 *v = reinterpret_cast<Vector2 *>(_data._mem); if (p_index == CoreStringNames::singleton->x) { - v->x = p_value._data._real; + v->x = p_value._data._float; valid = true; } else if (p_index == CoreStringNames::singleton->y) { - v->y = p_value._data._real; + v->y = p_value._data._float; + valid = true; + } + } + + } break; + case VECTOR2I: { + if (p_value.type == Variant::INT) { + Vector2i *v = reinterpret_cast<Vector2i *>(_data._mem); + if (p_index == CoreStringNames::singleton->x) { + v->x = p_value._data._int; + valid = true; + } else if (p_index == CoreStringNames::singleton->y) { + v->y = p_value._data._int; + valid = true; + } + } else if (p_value.type == Variant::FLOAT) { + Vector2i *v = reinterpret_cast<Vector2i *>(_data._mem); + if (p_index == CoreStringNames::singleton->x) { + v->x = p_value._data._float; + valid = true; + } else if (p_index == CoreStringNames::singleton->y) { + v->y = p_value._data._float; valid = true; } } @@ -1309,6 +1444,23 @@ void Variant::set_named(const StringName &p_index, const Variant &p_value, bool } } } break; + case RECT2I: { + + if (p_value.type == Variant::VECTOR2I) { + Rect2i *v = reinterpret_cast<Rect2i *>(_data._mem); + //scalar name + if (p_index == CoreStringNames::singleton->position) { + v->position = *reinterpret_cast<const Vector2i *>(p_value._data._mem); + valid = true; + } else if (p_index == CoreStringNames::singleton->size) { + v->size = *reinterpret_cast<const Vector2i *>(p_value._data._mem); + valid = true; + } else if (p_index == CoreStringNames::singleton->end) { + v->size = *reinterpret_cast<const Vector2i *>(p_value._data._mem) - v->position; + valid = true; + } + } + } break; case TRANSFORM2D: { if (p_value.type == Variant::VECTOR2) { @@ -1340,16 +1492,45 @@ void Variant::set_named(const StringName &p_index, const Variant &p_value, bool v->z = p_value._data._int; valid = true; } - } else if (p_value.type == Variant::REAL) { + } else if (p_value.type == Variant::FLOAT) { Vector3 *v = reinterpret_cast<Vector3 *>(_data._mem); if (p_index == CoreStringNames::singleton->x) { - v->x = p_value._data._real; + v->x = p_value._data._float; valid = true; } else if (p_index == CoreStringNames::singleton->y) { - v->y = p_value._data._real; + v->y = p_value._data._float; valid = true; } else if (p_index == CoreStringNames::singleton->z) { - v->z = p_value._data._real; + v->z = p_value._data._float; + valid = true; + } + } + + } break; + case VECTOR3I: { + + if (p_value.type == Variant::INT) { + Vector3i *v = reinterpret_cast<Vector3i *>(_data._mem); + if (p_index == CoreStringNames::singleton->x) { + v->x = p_value._data._int; + valid = true; + } else if (p_index == CoreStringNames::singleton->y) { + v->y = p_value._data._int; + valid = true; + } else if (p_index == CoreStringNames::singleton->z) { + v->z = p_value._data._int; + valid = true; + } + } else if (p_value.type == Variant::FLOAT) { + Vector3i *v = reinterpret_cast<Vector3i *>(_data._mem); + if (p_index == CoreStringNames::singleton->x) { + v->x = p_value._data._float; + valid = true; + } else if (p_index == CoreStringNames::singleton->y) { + v->y = p_value._data._float; + valid = true; + } else if (p_index == CoreStringNames::singleton->z) { + v->z = p_value._data._float; valid = true; } } @@ -1372,19 +1553,19 @@ void Variant::set_named(const StringName &p_index, const Variant &p_value, bool v->d = p_value._data._int; valid = true; } - } else if (p_value.type == Variant::REAL) { + } else if (p_value.type == Variant::FLOAT) { Plane *v = reinterpret_cast<Plane *>(_data._mem); if (p_index == CoreStringNames::singleton->x) { - v->normal.x = p_value._data._real; + v->normal.x = p_value._data._float; valid = true; } else if (p_index == CoreStringNames::singleton->y) { - v->normal.y = p_value._data._real; + v->normal.y = p_value._data._float; valid = true; } else if (p_index == CoreStringNames::singleton->z) { - v->normal.z = p_value._data._real; + v->normal.z = p_value._data._float; valid = true; } else if (p_index == CoreStringNames::singleton->d) { - v->d = p_value._data._real; + v->d = p_value._data._float; valid = true; } @@ -1414,24 +1595,24 @@ void Variant::set_named(const StringName &p_index, const Variant &p_value, bool v->w = p_value._data._int; valid = true; } - } else if (p_value.type == Variant::REAL) { + } else if (p_value.type == Variant::FLOAT) { Quat *v = reinterpret_cast<Quat *>(_data._mem); if (p_index == CoreStringNames::singleton->x) { - v->x = p_value._data._real; + v->x = p_value._data._float; valid = true; } else if (p_index == CoreStringNames::singleton->y) { - v->y = p_value._data._real; + v->y = p_value._data._float; valid = true; } else if (p_index == CoreStringNames::singleton->z) { - v->z = p_value._data._real; + v->z = p_value._data._float; valid = true; } else if (p_index == CoreStringNames::singleton->w) { - v->w = p_value._data._real; + v->w = p_value._data._float; valid = true; } } - } break; // 10 + } break; case AABB: { if (p_value.type == Variant::VECTOR3) { @@ -1515,40 +1696,40 @@ void Variant::set_named(const StringName &p_index, const Variant &p_value, bool v->set_hsv(v->get_h(), v->get_v(), p_value._data._int, v->a); valid = true; } - } else if (p_value.type == Variant::REAL) { + } else if (p_value.type == Variant::FLOAT) { Color *v = reinterpret_cast<Color *>(_data._mem); if (p_index == CoreStringNames::singleton->r) { - v->r = p_value._data._real; + v->r = p_value._data._float; valid = true; } else if (p_index == CoreStringNames::singleton->g) { - v->g = p_value._data._real; + v->g = p_value._data._float; valid = true; } else if (p_index == CoreStringNames::singleton->b) { - v->b = p_value._data._real; + v->b = p_value._data._float; valid = true; } else if (p_index == CoreStringNames::singleton->a) { - v->a = p_value._data._real; + v->a = p_value._data._float; valid = true; } else if (p_index == CoreStringNames::singleton->r8) { - v->r = p_value._data._real / 255.0; + v->r = p_value._data._float / 255.0; valid = true; } else if (p_index == CoreStringNames::singleton->g8) { - v->g = p_value._data._real / 255.0; + v->g = p_value._data._float / 255.0; valid = true; } else if (p_index == CoreStringNames::singleton->b8) { - v->b = p_value._data._real / 255.0; + v->b = p_value._data._float / 255.0; valid = true; } else if (p_index == CoreStringNames::singleton->a8) { - v->a = p_value._data._real / 255.0; + v->a = p_value._data._float / 255.0; valid = true; } else if (p_index == CoreStringNames::singleton->h) { - v->set_hsv(p_value._data._real, v->get_s(), v->get_v(), v->a); + v->set_hsv(p_value._data._float, v->get_s(), v->get_v(), v->a); valid = true; } else if (p_index == CoreStringNames::singleton->s) { - v->set_hsv(v->get_h(), p_value._data._real, v->get_v(), v->a); + v->set_hsv(v->get_h(), p_value._data._float, v->get_v(), v->a); valid = true; } else if (p_index == CoreStringNames::singleton->v) { - v->set_hsv(v->get_h(), v->get_s(), p_value._data._real, v->a); + v->set_hsv(v->get_h(), v->get_s(), p_value._data._float, v->a); valid = true; } } @@ -1591,6 +1772,15 @@ Variant Variant::get_named(const StringName &p_index, bool *r_valid) const { } } break; + case VECTOR2I: { + const Vector2i *v = reinterpret_cast<const Vector2i *>(_data._mem); + if (p_index == CoreStringNames::singleton->x) { + return v->x; + } else if (p_index == CoreStringNames::singleton->y) { + return v->y; + } + + } break; case RECT2: { const Rect2 *v = reinterpret_cast<const Rect2 *>(_data._mem); @@ -1603,6 +1793,18 @@ Variant Variant::get_named(const StringName &p_index, bool *r_valid) const { return v->size + v->position; } } break; + case RECT2I: { + + const Rect2i *v = reinterpret_cast<const Rect2i *>(_data._mem); + //scalar name + if (p_index == CoreStringNames::singleton->position) { + return v->position; + } else if (p_index == CoreStringNames::singleton->size) { + return v->size; + } else if (p_index == CoreStringNames::singleton->end) { + return v->size + v->position; + } + } break; case TRANSFORM2D: { const Transform2D *v = _data._transform2d; @@ -1627,6 +1829,18 @@ Variant Variant::get_named(const StringName &p_index, bool *r_valid) const { } } break; + case VECTOR3I: { + + const Vector3i *v = reinterpret_cast<const Vector3i *>(_data._mem); + if (p_index == CoreStringNames::singleton->x) { + return v->x; + } else if (p_index == CoreStringNames::singleton->y) { + return v->y; + } else if (p_index == CoreStringNames::singleton->z) { + return v->z; + } + + } break; case PLANE: { const Plane *v = reinterpret_cast<const Plane *>(_data._mem); @@ -1656,7 +1870,7 @@ Variant Variant::get_named(const StringName &p_index, bool *r_valid) const { return v->w; } - } break; // 10 + } break; case AABB: { const ::AABB *v = _data._aabb; @@ -1750,28 +1964,55 @@ Variant Variant::get_named(const StringName &p_index, bool *r_valid) const { return Variant(); } -#define DEFAULT_OP_ARRAY_CMD(m_name, m_type, skip_test, cmd) \ - case m_name: { \ - skip_test; \ - \ - if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::REAL) { \ - int index = p_index; \ - m_type *arr = reinterpret_cast<m_type *>(_data._mem); \ - \ - if (index < 0) \ - index += arr->size(); \ - if (index >= 0 && index < arr->size()) { \ - valid = true; \ - cmd; \ - } \ - } \ +#define DEFAULT_OP_ARRAY_CMD(m_name, m_type, skip_test, cmd) \ + case m_name: { \ + skip_test; \ + \ + if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) { \ + int index = p_index; \ + m_type *arr = reinterpret_cast<m_type *>(_data._mem); \ + \ + if (index < 0) \ + index += arr->size(); \ + if (index >= 0 && index < arr->size()) { \ + valid = true; \ + cmd; \ + } \ + } \ } break; -#define DEFAULT_OP_DVECTOR_SET(m_name, dv_type, skip_cond) \ - DEFAULT_OP_ARRAY_CMD(m_name, Vector<dv_type>, if (skip_cond) return;, arr->set(index, p_value); return ) +#define DEFAULT_OP_DVECTOR_SET(m_name, m_type, skip_cond) \ + case m_name: { \ + if (skip_cond) return; \ + \ + if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) { \ + int index = p_index; \ + Vector<m_type> *arr = PackedArrayRef<m_type>::get_array_ptr(_data.packed_array); \ + \ + if (index < 0) \ + index += arr->size(); \ + if (index >= 0 && index < arr->size()) { \ + valid = true; \ + arr->set(index, p_value); \ + } \ + } \ + } break; -#define DEFAULT_OP_DVECTOR_GET(m_name, dv_type) \ - DEFAULT_OP_ARRAY_CMD(m_name, const Vector<dv_type>, ;, return arr->get(index)) +#define DEFAULT_OP_DVECTOR_GET(m_name, m_type) \ + case m_name: { \ + \ + if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) { \ + int index = p_index; \ + const Vector<m_type> *arr = &PackedArrayRef<m_type>::get_array(_data.packed_array); \ + \ + if (index < 0) \ + index += arr->size(); \ + if (index >= 0 && index < arr->size()) { \ + valid = true; \ + return arr->get(index); \ + } \ + } \ + } break; void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) { @@ -1790,12 +2031,12 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) case INT: { return; } break; - case REAL: { + case FLOAT: { return; } break; case STRING: { - if (p_index.type != Variant::INT && p_index.type != Variant::REAL) + if (p_index.type != Variant::INT && p_index.type != Variant::FLOAT) return; int idx = p_index; @@ -1807,7 +2048,7 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) return; String chr; - if (p_value.type == Variant::INT || p_value.type == Variant::REAL) { + if (p_value.type == Variant::INT || p_value.type == Variant::FLOAT) { chr = String::chr(p_value); } else if (p_value.type == Variant::STRING) { @@ -1824,10 +2065,10 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) } break; case VECTOR2: { - if (p_value.type != Variant::INT && p_value.type != Variant::REAL) + if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) return; - if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::REAL) { + if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) { // scalar index int idx = p_index; @@ -1856,7 +2097,42 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) } } - } break; // 5 + } break; + case VECTOR2I: { + + if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) + return; + + if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) { + // scalar index + int idx = p_index; + + if (idx < 0) + idx += 2; + if (idx >= 0 && idx < 2) { + + Vector2i *v = reinterpret_cast<Vector2i *>(_data._mem); + valid = true; + (*v)[idx] = p_value; + return; + } + } else if (p_index.get_type() == Variant::STRING) { + //scalar name + + const String *str = reinterpret_cast<const String *>(p_index._data._mem); + Vector2i *v = reinterpret_cast<Vector2i *>(_data._mem); + if (*str == "x") { + valid = true; + v->x = p_value; + return; + } else if (*str == "y") { + valid = true; + v->y = p_value; + return; + } + } + + } break; case RECT2: { if (p_value.type != Variant::VECTOR2) @@ -1882,12 +2158,37 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) } } } break; + case RECT2I: { + + if (p_value.type != Variant::VECTOR2I) + return; + + if (p_index.get_type() == Variant::STRING) { + //scalar name + + const String *str = reinterpret_cast<const String *>(p_index._data._mem); + Rect2i *v = reinterpret_cast<Rect2i *>(_data._mem); + if (*str == "position") { + valid = true; + v->position = p_value; + return; + } else if (*str == "size") { + valid = true; + v->size = p_value; + return; + } else if (*str == "end") { + valid = true; + v->size = Vector2i(p_value) - v->position; + return; + } + } + } break; case TRANSFORM2D: { if (p_value.type != Variant::VECTOR2) return; - if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::REAL) { + if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) { int index = p_index; @@ -1923,10 +2224,10 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) } break; case VECTOR3: { - if (p_value.type != Variant::INT && p_value.type != Variant::REAL) + if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) return; - if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::REAL) { + if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) { //scalar index int idx = p_index; if (idx < 0) @@ -1959,6 +2260,44 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) } } break; + case VECTOR3I: { + + if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) + return; + + if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) { + //scalar index + int idx = p_index; + if (idx < 0) + idx += 3; + if (idx >= 0 && idx < 3) { + + Vector3i *v = reinterpret_cast<Vector3i *>(_data._mem); + valid = true; + (*v)[idx] = p_value; + return; + } + } else if (p_index.get_type() == Variant::STRING) { + + //scalar name + const String *str = reinterpret_cast<const String *>(p_index._data._mem); + Vector3i *v = reinterpret_cast<Vector3i *>(_data._mem); + if (*str == "x") { + valid = true; + v->x = p_value; + return; + } else if (*str == "y") { + valid = true; + v->y = p_value; + return; + } else if (*str == "z") { + valid = true; + v->z = p_value; + return; + } + } + + } break; case PLANE: { if (p_index.get_type() == Variant::STRING) { @@ -1966,21 +2305,21 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) const String *str = reinterpret_cast<const String *>(p_index._data._mem); Plane *v = reinterpret_cast<Plane *>(_data._mem); if (*str == "x") { - if (p_value.type != Variant::INT && p_value.type != Variant::REAL) + if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) return; valid = true; v->normal.x = p_value; return; } else if (*str == "y") { - if (p_value.type != Variant::INT && p_value.type != Variant::REAL) + if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) return; valid = true; v->normal.y = p_value; return; } else if (*str == "z") { - if (p_value.type != Variant::INT && p_value.type != Variant::REAL) + if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) return; valid = true; @@ -2003,7 +2342,7 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) } break; case QUAT: { - if (p_value.type != Variant::INT && p_value.type != Variant::REAL) + if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) return; if (p_index.get_type() == Variant::STRING) { @@ -2029,7 +2368,7 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) } } - } break; // 10 + } break; case AABB: { if (p_value.type != Variant::VECTOR3) @@ -2060,7 +2399,7 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) if (p_value.type != Variant::VECTOR3) return; - if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::REAL) { + if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) { int index = p_index; @@ -2096,7 +2435,7 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) } break; case TRANSFORM: { - if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::REAL) { + if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) { if (p_value.type != Variant::VECTOR3) return; @@ -2139,7 +2478,7 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) } break; case COLOR: { - if (p_value.type != Variant::INT && p_value.type != Variant::REAL) + if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) return; if (p_index.get_type() == Variant::STRING) { @@ -2204,8 +2543,10 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) } } break; + case STRING_NAME: { + } break; case NODE_PATH: { - } break; // 15 + } break; case _RID: { } break; case OBJECT: { @@ -2223,7 +2564,7 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) } #endif - if (p_index.get_type() != Variant::STRING) { + if (p_index.get_type() != Variant::STRING_NAME && p_index.get_type() != Variant::STRING) { obj->setvar(p_index, p_value, r_valid); return; } @@ -2239,12 +2580,14 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) valid = true; //always valid, i guess? should this really be ok? return; } break; - DEFAULT_OP_ARRAY_CMD(ARRAY, Array, ;, (*arr)[index] = p_value; return ) // 20 - DEFAULT_OP_DVECTOR_SET(PACKED_BYTE_ARRAY, uint8_t, p_value.type != Variant::REAL && p_value.type != Variant::INT) - DEFAULT_OP_DVECTOR_SET(PACKED_INT_ARRAY, int, p_value.type != Variant::REAL && p_value.type != Variant::INT) - DEFAULT_OP_DVECTOR_SET(PACKED_REAL_ARRAY, real_t, p_value.type != Variant::REAL && p_value.type != Variant::INT) + DEFAULT_OP_ARRAY_CMD(ARRAY, Array, ;, (*arr)[index] = p_value; return ) + DEFAULT_OP_DVECTOR_SET(PACKED_BYTE_ARRAY, uint8_t, p_value.type != Variant::FLOAT && p_value.type != Variant::INT) + DEFAULT_OP_DVECTOR_SET(PACKED_INT32_ARRAY, int32_t, p_value.type != Variant::FLOAT && p_value.type != Variant::INT) + DEFAULT_OP_DVECTOR_SET(PACKED_INT64_ARRAY, int64_t, p_value.type != Variant::FLOAT && p_value.type != Variant::INT) + DEFAULT_OP_DVECTOR_SET(PACKED_FLOAT32_ARRAY, float, p_value.type != Variant::FLOAT && p_value.type != Variant::INT) + DEFAULT_OP_DVECTOR_SET(PACKED_FLOAT64_ARRAY, double, p_value.type != Variant::FLOAT && p_value.type != Variant::INT) DEFAULT_OP_DVECTOR_SET(PACKED_STRING_ARRAY, String, p_value.type != Variant::STRING) - DEFAULT_OP_DVECTOR_SET(PACKED_VECTOR2_ARRAY, Vector2, p_value.type != Variant::VECTOR2) // 25 + DEFAULT_OP_DVECTOR_SET(PACKED_VECTOR2_ARRAY, Vector2, p_value.type != Variant::VECTOR2) DEFAULT_OP_DVECTOR_SET(PACKED_VECTOR3_ARRAY, Vector3, p_value.type != Variant::VECTOR3) DEFAULT_OP_DVECTOR_SET(PACKED_COLOR_ARRAY, Color, p_value.type != Variant::COLOR) default: @@ -2270,12 +2613,12 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const { case INT: { return Variant(); } break; - case REAL: { + case FLOAT: { return Variant(); } break; case STRING: { - if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::REAL) { + if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) { //string index int idx = p_index; @@ -2292,7 +2635,7 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const { } break; case VECTOR2: { - if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::REAL) { + if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) { // scalar index int idx = p_index; if (idx < 0) @@ -2317,7 +2660,35 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const { } } - } break; // 5 + } break; + case VECTOR2I: { + + if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) { + // scalar index + int idx = p_index; + if (idx < 0) + idx += 2; + if (idx >= 0 && idx < 2) { + + const Vector2i *v = reinterpret_cast<const Vector2i *>(_data._mem); + valid = true; + return (*v)[idx]; + } + } else if (p_index.get_type() == Variant::STRING) { + //scalar name + + const String *str = reinterpret_cast<const String *>(p_index._data._mem); + const Vector2i *v = reinterpret_cast<const Vector2i *>(_data._mem); + if (*str == "x") { + valid = true; + return v->x; + } else if (*str == "y") { + valid = true; + return v->y; + } + } + + } break; case RECT2: { if (p_index.get_type() == Variant::STRING) { @@ -2337,9 +2708,28 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const { } } } break; + case RECT2I: { + + if (p_index.get_type() == Variant::STRING) { + //scalar name + + const String *str = reinterpret_cast<const String *>(p_index._data._mem); + const Rect2i *v = reinterpret_cast<const Rect2i *>(_data._mem); + if (*str == "position") { + valid = true; + return v->position; + } else if (*str == "size") { + valid = true; + return v->size; + } else if (*str == "end") { + valid = true; + return v->size + v->position; + } + } + } break; case VECTOR3: { - if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::REAL) { + if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) { //scalar index int idx = p_index; if (idx < 0) @@ -2368,9 +2758,40 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const { } } break; + case VECTOR3I: { + + if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) { + //scalar index + int idx = p_index; + if (idx < 0) + idx += 3; + if (idx >= 0 && idx < 3) { + + const Vector3i *v = reinterpret_cast<const Vector3i *>(_data._mem); + valid = true; + return (*v)[idx]; + } + } else if (p_index.get_type() == Variant::STRING) { + + //scalar name + const String *str = reinterpret_cast<const String *>(p_index._data._mem); + const Vector3i *v = reinterpret_cast<const Vector3i *>(_data._mem); + if (*str == "x") { + valid = true; + return v->x; + } else if (*str == "y") { + valid = true; + return v->y; + } else if (*str == "z") { + valid = true; + return v->z; + } + } + + } break; case TRANSFORM2D: { - if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::REAL) { + if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) { int index = p_index; @@ -2446,7 +2867,7 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const { } } - } break; // 10 + } break; case AABB: { if (p_index.get_type() == Variant::STRING) { @@ -2468,7 +2889,7 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const { } break; case BASIS: { - if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::REAL) { + if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) { int index = p_index; if (index < 0) @@ -2499,7 +2920,7 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const { } break; case TRANSFORM: { - if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::REAL) { + if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) { int index = p_index; if (index < 0) @@ -2578,8 +2999,10 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const { } } break; + case STRING_NAME: { + } break; case NODE_PATH: { - } break; // 15 + } break; case _RID: { } break; case OBJECT: { @@ -2611,12 +3034,14 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const { return *res; } } break; - DEFAULT_OP_ARRAY_CMD(ARRAY, const Array, ;, return (*arr)[index]) // 20 + DEFAULT_OP_ARRAY_CMD(ARRAY, const Array, ;, return (*arr)[index]) DEFAULT_OP_DVECTOR_GET(PACKED_BYTE_ARRAY, uint8_t) - DEFAULT_OP_DVECTOR_GET(PACKED_INT_ARRAY, int) - DEFAULT_OP_DVECTOR_GET(PACKED_REAL_ARRAY, real_t) + DEFAULT_OP_DVECTOR_GET(PACKED_INT32_ARRAY, int32_t) + DEFAULT_OP_DVECTOR_GET(PACKED_INT64_ARRAY, int64_t) + DEFAULT_OP_DVECTOR_GET(PACKED_FLOAT32_ARRAY, float) + DEFAULT_OP_DVECTOR_GET(PACKED_FLOAT64_ARRAY, double) DEFAULT_OP_DVECTOR_GET(PACKED_STRING_ARRAY, String) - DEFAULT_OP_DVECTOR_GET(PACKED_VECTOR2_ARRAY, Vector2) // 25 + DEFAULT_OP_DVECTOR_GET(PACKED_VECTOR2_ARRAY, Vector2) DEFAULT_OP_DVECTOR_GET(PACKED_VECTOR3_ARRAY, Vector3) DEFAULT_OP_DVECTOR_GET(PACKED_COLOR_ARRAY, Color) default: @@ -2678,7 +3103,7 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const { const Dictionary *dic = reinterpret_cast<const Dictionary *>(_data._mem); return dic->has(p_index); - } break; // 20 + } break; case ARRAY: { const Array *arr = reinterpret_cast<const Array *>(_data._mem); @@ -2695,10 +3120,10 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const { } break; case PACKED_BYTE_ARRAY: { - if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::REAL) { + if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) { int index = p_index; - const Vector<uint8_t> *arr = reinterpret_cast<const Vector<uint8_t> *>(_data._mem); + const Vector<uint8_t> *arr = &PackedArrayRef<uint8_t>::get_array(_data.packed_array); int l = arr->size(); if (l) { const uint8_t *r = arr->ptr(); @@ -2712,14 +3137,49 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const { } } break; - case PACKED_INT_ARRAY: { - if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::REAL) { + case PACKED_INT32_ARRAY: { + if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) { - int index = p_index; - const Vector<int> *arr = reinterpret_cast<const Vector<int> *>(_data._mem); + int32_t index = p_index; + const Vector<int32_t> *arr = &PackedArrayRef<int32_t>::get_array(_data.packed_array); + int32_t l = arr->size(); + if (l) { + const int32_t *r = arr->ptr(); + for (int32_t i = 0; i < l; i++) { + if (r[i] == index) + return true; + } + } + + return false; + } + } break; + case PACKED_INT64_ARRAY: { + if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) { + + int64_t index = p_index; + const Vector<int64_t> *arr = &PackedArrayRef<int64_t>::get_array(_data.packed_array); + int64_t l = arr->size(); + if (l) { + const int64_t *r = arr->ptr(); + for (int64_t i = 0; i < l; i++) { + if (r[i] == index) + return true; + } + } + + return false; + } + } break; + case PACKED_FLOAT32_ARRAY: { + + if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) { + + real_t index = p_index; + const Vector<float> *arr = &PackedArrayRef<float>::get_array(_data.packed_array); int l = arr->size(); if (l) { - const int *r = arr->ptr(); + const float *r = arr->ptr(); for (int i = 0; i < l; i++) { if (r[i] == index) return true; @@ -2728,16 +3188,17 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const { return false; } + } break; - case PACKED_REAL_ARRAY: { + case PACKED_FLOAT64_ARRAY: { - if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::REAL) { + if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) { real_t index = p_index; - const Vector<real_t> *arr = reinterpret_cast<const Vector<real_t> *>(_data._mem); + const Vector<double> *arr = &PackedArrayRef<double>::get_array(_data.packed_array); int l = arr->size(); if (l) { - const real_t *r = arr->ptr(); + const double *r = arr->ptr(); for (int i = 0; i < l; i++) { if (r[i] == index) return true; @@ -2752,7 +3213,7 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const { if (p_index.get_type() == Variant::STRING) { String index = p_index; - const Vector<String> *arr = reinterpret_cast<const Vector<String> *>(_data._mem); + const Vector<String> *arr = &PackedArrayRef<String>::get_array(_data.packed_array); int l = arr->size(); if (l) { @@ -2771,7 +3232,7 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const { if (p_index.get_type() == Variant::VECTOR2) { Vector2 index = p_index; - const Vector<Vector2> *arr = reinterpret_cast<const Vector<Vector2> *>(_data._mem); + const Vector<Vector2> *arr = &PackedArrayRef<Vector2>::get_array(_data.packed_array); int l = arr->size(); if (l) { @@ -2790,7 +3251,7 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const { if (p_index.get_type() == Variant::VECTOR3) { Vector3 index = p_index; - const Vector<Vector3> *arr = reinterpret_cast<const Vector<Vector3> *>(_data._mem); + const Vector<Vector3> *arr = &PackedArrayRef<Vector3>::get_array(_data.packed_array); int l = arr->size(); if (l) { @@ -2810,7 +3271,7 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const { if (p_index.get_type() == Variant::COLOR) { Color index = p_index; - const Vector<Color> *arr = reinterpret_cast<const Vector<Color> *>(_data._mem); + const Vector<Color> *arr = &PackedArrayRef<Color>::get_array(_data.packed_array); int l = arr->size(); if (l) { @@ -2838,10 +3299,16 @@ void Variant::get_property_list(List<PropertyInfo> *p_list) const { switch (type) { case VECTOR2: { - p_list->push_back(PropertyInfo(Variant::REAL, "x")); - p_list->push_back(PropertyInfo(Variant::REAL, "y")); + p_list->push_back(PropertyInfo(Variant::FLOAT, "x")); + p_list->push_back(PropertyInfo(Variant::FLOAT, "y")); + + } break; + case VECTOR2I: { + + p_list->push_back(PropertyInfo(Variant::INT, "x")); + p_list->push_back(PropertyInfo(Variant::INT, "y")); - } break; // 5 + } break; case RECT2: { p_list->push_back(PropertyInfo(Variant::VECTOR2, "position")); @@ -2849,11 +3316,25 @@ void Variant::get_property_list(List<PropertyInfo> *p_list) const { p_list->push_back(PropertyInfo(Variant::VECTOR2, "end")); } break; + case RECT2I: { + + p_list->push_back(PropertyInfo(Variant::VECTOR2I, "position")); + p_list->push_back(PropertyInfo(Variant::VECTOR2I, "size")); + p_list->push_back(PropertyInfo(Variant::VECTOR2I, "end")); + + } break; case VECTOR3: { - p_list->push_back(PropertyInfo(Variant::REAL, "x")); - p_list->push_back(PropertyInfo(Variant::REAL, "y")); - p_list->push_back(PropertyInfo(Variant::REAL, "z")); + p_list->push_back(PropertyInfo(Variant::FLOAT, "x")); + p_list->push_back(PropertyInfo(Variant::FLOAT, "y")); + p_list->push_back(PropertyInfo(Variant::FLOAT, "z")); + + } break; + case VECTOR3I: { + + p_list->push_back(PropertyInfo(Variant::INT, "x")); + p_list->push_back(PropertyInfo(Variant::INT, "y")); + p_list->push_back(PropertyInfo(Variant::INT, "z")); } break; case TRANSFORM2D: { @@ -2866,20 +3347,20 @@ void Variant::get_property_list(List<PropertyInfo> *p_list) const { case PLANE: { p_list->push_back(PropertyInfo(Variant::VECTOR3, "normal")); - p_list->push_back(PropertyInfo(Variant::REAL, "x")); - p_list->push_back(PropertyInfo(Variant::REAL, "y")); - p_list->push_back(PropertyInfo(Variant::REAL, "z")); - p_list->push_back(PropertyInfo(Variant::REAL, "d")); + p_list->push_back(PropertyInfo(Variant::FLOAT, "x")); + p_list->push_back(PropertyInfo(Variant::FLOAT, "y")); + p_list->push_back(PropertyInfo(Variant::FLOAT, "z")); + p_list->push_back(PropertyInfo(Variant::FLOAT, "d")); } break; case QUAT: { - p_list->push_back(PropertyInfo(Variant::REAL, "x")); - p_list->push_back(PropertyInfo(Variant::REAL, "y")); - p_list->push_back(PropertyInfo(Variant::REAL, "z")); - p_list->push_back(PropertyInfo(Variant::REAL, "w")); + p_list->push_back(PropertyInfo(Variant::FLOAT, "x")); + p_list->push_back(PropertyInfo(Variant::FLOAT, "y")); + p_list->push_back(PropertyInfo(Variant::FLOAT, "z")); + p_list->push_back(PropertyInfo(Variant::FLOAT, "w")); - } break; // 10 + } break; case AABB: { p_list->push_back(PropertyInfo(Variant::VECTOR3, "position")); p_list->push_back(PropertyInfo(Variant::VECTOR3, "size")); @@ -2899,21 +3380,23 @@ void Variant::get_property_list(List<PropertyInfo> *p_list) const { } break; case COLOR: { - p_list->push_back(PropertyInfo(Variant::REAL, "r")); - p_list->push_back(PropertyInfo(Variant::REAL, "g")); - p_list->push_back(PropertyInfo(Variant::REAL, "b")); - p_list->push_back(PropertyInfo(Variant::REAL, "a")); - p_list->push_back(PropertyInfo(Variant::REAL, "h")); - p_list->push_back(PropertyInfo(Variant::REAL, "s")); - p_list->push_back(PropertyInfo(Variant::REAL, "v")); + p_list->push_back(PropertyInfo(Variant::FLOAT, "r")); + p_list->push_back(PropertyInfo(Variant::FLOAT, "g")); + p_list->push_back(PropertyInfo(Variant::FLOAT, "b")); + p_list->push_back(PropertyInfo(Variant::FLOAT, "a")); + p_list->push_back(PropertyInfo(Variant::FLOAT, "h")); + p_list->push_back(PropertyInfo(Variant::FLOAT, "s")); + p_list->push_back(PropertyInfo(Variant::FLOAT, "v")); p_list->push_back(PropertyInfo(Variant::INT, "r8")); p_list->push_back(PropertyInfo(Variant::INT, "g8")); p_list->push_back(PropertyInfo(Variant::INT, "b8")); p_list->push_back(PropertyInfo(Variant::INT, "a8")); } break; + case STRING_NAME: { + } break; case NODE_PATH: { - } break; // 15 + } break; case _RID: { } break; case OBJECT: { @@ -2944,12 +3427,14 @@ void Variant::get_property_list(List<PropertyInfo> *p_list) const { } } } break; - case ARRAY: // 20 + case ARRAY: case PACKED_BYTE_ARRAY: - case PACKED_INT_ARRAY: - case PACKED_REAL_ARRAY: + case PACKED_INT32_ARRAY: + case PACKED_INT64_ARRAY: + case PACKED_FLOAT32_ARRAY: + case PACKED_FLOAT64_ARRAY: case PACKED_STRING_ARRAY: - case PACKED_VECTOR2_ARRAY: // 25 + case PACKED_VECTOR2_ARRAY: case PACKED_VECTOR3_ARRAY: case PACKED_COLOR_ARRAY: { @@ -2968,9 +3453,9 @@ bool Variant::iter_init(Variant &r_iter, bool &valid) const { r_iter = 0; return _data._int > 0; } break; - case REAL: { + case FLOAT: { r_iter = 0; - return _data._real > 0.0; + return _data._float > 0.0; } break; case VECTOR2: { int64_t from = reinterpret_cast<const Vector2 *>(_data._mem)->x; @@ -3056,23 +3541,39 @@ bool Variant::iter_init(Variant &r_iter, bool &valid) const { return true; } break; case PACKED_BYTE_ARRAY: { - const Vector<uint8_t> *arr = reinterpret_cast<const Vector<uint8_t> *>(_data._mem); + const Vector<uint8_t> *arr = &PackedArrayRef<uint8_t>::get_array(_data.packed_array); + if (arr->size() == 0) + return false; + r_iter = 0; + return true; + + } break; + case PACKED_INT32_ARRAY: { + const Vector<int32_t> *arr = &PackedArrayRef<int32_t>::get_array(_data.packed_array); + if (arr->size() == 0) + return false; + r_iter = 0; + return true; + + } break; + case PACKED_INT64_ARRAY: { + const Vector<int64_t> *arr = &PackedArrayRef<int64_t>::get_array(_data.packed_array); if (arr->size() == 0) return false; r_iter = 0; return true; } break; - case PACKED_INT_ARRAY: { - const Vector<int> *arr = reinterpret_cast<const Vector<int> *>(_data._mem); + case PACKED_FLOAT32_ARRAY: { + const Vector<float> *arr = &PackedArrayRef<float>::get_array(_data.packed_array); if (arr->size() == 0) return false; r_iter = 0; return true; } break; - case PACKED_REAL_ARRAY: { - const Vector<real_t> *arr = reinterpret_cast<const Vector<real_t> *>(_data._mem); + case PACKED_FLOAT64_ARRAY: { + const Vector<double> *arr = &PackedArrayRef<double>::get_array(_data.packed_array); if (arr->size() == 0) return false; r_iter = 0; @@ -3080,7 +3581,7 @@ bool Variant::iter_init(Variant &r_iter, bool &valid) const { } break; case PACKED_STRING_ARRAY: { - const Vector<String> *arr = reinterpret_cast<const Vector<String> *>(_data._mem); + const Vector<String> *arr = &PackedArrayRef<String>::get_array(_data.packed_array); if (arr->size() == 0) return false; r_iter = 0; @@ -3088,7 +3589,7 @@ bool Variant::iter_init(Variant &r_iter, bool &valid) const { } break; case PACKED_VECTOR2_ARRAY: { - const Vector<Vector2> *arr = reinterpret_cast<const Vector<Vector2> *>(_data._mem); + const Vector<Vector2> *arr = &PackedArrayRef<Vector2>::get_array(_data.packed_array); if (arr->size() == 0) return false; r_iter = 0; @@ -3096,7 +3597,7 @@ bool Variant::iter_init(Variant &r_iter, bool &valid) const { } break; case PACKED_VECTOR3_ARRAY: { - const Vector<Vector3> *arr = reinterpret_cast<const Vector<Vector3> *>(_data._mem); + const Vector<Vector3> *arr = &PackedArrayRef<Vector3>::get_array(_data.packed_array); if (arr->size() == 0) return false; r_iter = 0; @@ -3104,7 +3605,7 @@ bool Variant::iter_init(Variant &r_iter, bool &valid) const { } break; case PACKED_COLOR_ARRAY: { - const Vector<Color> *arr = reinterpret_cast<const Vector<Color> *>(_data._mem); + const Vector<Color> *arr = &PackedArrayRef<Color>::get_array(_data.packed_array); if (arr->size() == 0) return false; r_iter = 0; @@ -3130,10 +3631,10 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const { r_iter = idx; return true; } break; - case REAL: { + case FLOAT: { int64_t idx = r_iter; idx++; - if (idx >= _data._real) + if (idx >= _data._float) return false; r_iter = idx; return true; @@ -3231,7 +3732,7 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const { return true; } break; case PACKED_BYTE_ARRAY: { - const Vector<uint8_t> *arr = reinterpret_cast<const Vector<uint8_t> *>(_data._mem); + const Vector<uint8_t> *arr = &PackedArrayRef<uint8_t>::get_array(_data.packed_array); int idx = r_iter; idx++; if (idx >= arr->size()) @@ -3240,8 +3741,28 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const { return true; } break; - case PACKED_INT_ARRAY: { - const Vector<int> *arr = reinterpret_cast<const Vector<int> *>(_data._mem); + case PACKED_INT32_ARRAY: { + const Vector<int32_t> *arr = &PackedArrayRef<int32_t>::get_array(_data.packed_array); + int32_t idx = r_iter; + idx++; + if (idx >= arr->size()) + return false; + r_iter = idx; + return true; + + } break; + case PACKED_INT64_ARRAY: { + const Vector<int64_t> *arr = &PackedArrayRef<int64_t>::get_array(_data.packed_array); + int64_t idx = r_iter; + idx++; + if (idx >= arr->size()) + return false; + r_iter = idx; + return true; + + } break; + case PACKED_FLOAT32_ARRAY: { + const Vector<float> *arr = &PackedArrayRef<float>::get_array(_data.packed_array); int idx = r_iter; idx++; if (idx >= arr->size()) @@ -3250,8 +3771,8 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const { return true; } break; - case PACKED_REAL_ARRAY: { - const Vector<real_t> *arr = reinterpret_cast<const Vector<real_t> *>(_data._mem); + case PACKED_FLOAT64_ARRAY: { + const Vector<double> *arr = &PackedArrayRef<double>::get_array(_data.packed_array); int idx = r_iter; idx++; if (idx >= arr->size()) @@ -3261,7 +3782,7 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const { } break; case PACKED_STRING_ARRAY: { - const Vector<String> *arr = reinterpret_cast<const Vector<String> *>(_data._mem); + const Vector<String> *arr = &PackedArrayRef<String>::get_array(_data.packed_array); int idx = r_iter; idx++; if (idx >= arr->size()) @@ -3271,7 +3792,7 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const { } break; case PACKED_VECTOR2_ARRAY: { - const Vector<Vector2> *arr = reinterpret_cast<const Vector<Vector2> *>(_data._mem); + const Vector<Vector2> *arr = &PackedArrayRef<Vector2>::get_array(_data.packed_array); int idx = r_iter; idx++; if (idx >= arr->size()) @@ -3281,7 +3802,7 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const { } break; case PACKED_VECTOR3_ARRAY: { - const Vector<Vector3> *arr = reinterpret_cast<const Vector<Vector3> *>(_data._mem); + const Vector<Vector3> *arr = &PackedArrayRef<Vector3>::get_array(_data.packed_array); int idx = r_iter; idx++; if (idx >= arr->size()) @@ -3291,7 +3812,7 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const { } break; case PACKED_COLOR_ARRAY: { - const Vector<Color> *arr = reinterpret_cast<const Vector<Color> *>(_data._mem); + const Vector<Color> *arr = &PackedArrayRef<Color>::get_array(_data.packed_array); int idx = r_iter; idx++; if (idx >= arr->size()) @@ -3315,7 +3836,7 @@ Variant Variant::iter_get(const Variant &r_iter, bool &r_valid) const { return r_iter; } break; - case REAL: { + case FLOAT: { return r_iter; } break; @@ -3378,7 +3899,7 @@ Variant Variant::iter_get(const Variant &r_iter, bool &r_valid) const { return arr->get(idx); } break; case PACKED_BYTE_ARRAY: { - const Vector<uint8_t> *arr = reinterpret_cast<const Vector<uint8_t> *>(_data._mem); + const Vector<uint8_t> *arr = &PackedArrayRef<uint8_t>::get_array(_data.packed_array); int idx = r_iter; #ifdef DEBUG_ENABLED if (idx < 0 || idx >= arr->size()) { @@ -3388,8 +3909,30 @@ Variant Variant::iter_get(const Variant &r_iter, bool &r_valid) const { #endif return arr->get(idx); } break; - case PACKED_INT_ARRAY: { - const Vector<int> *arr = reinterpret_cast<const Vector<int> *>(_data._mem); + case PACKED_INT32_ARRAY: { + const Vector<int32_t> *arr = &PackedArrayRef<int32_t>::get_array(_data.packed_array); + int32_t idx = r_iter; +#ifdef DEBUG_ENABLED + if (idx < 0 || idx >= arr->size()) { + r_valid = false; + return Variant(); + } +#endif + return arr->get(idx); + } break; + case PACKED_INT64_ARRAY: { + const Vector<int64_t> *arr = &PackedArrayRef<int64_t>::get_array(_data.packed_array); + int64_t idx = r_iter; +#ifdef DEBUG_ENABLED + if (idx < 0 || idx >= arr->size()) { + r_valid = false; + return Variant(); + } +#endif + return arr->get(idx); + } break; + case PACKED_FLOAT32_ARRAY: { + const Vector<float> *arr = &PackedArrayRef<float>::get_array(_data.packed_array); int idx = r_iter; #ifdef DEBUG_ENABLED if (idx < 0 || idx >= arr->size()) { @@ -3399,8 +3942,8 @@ Variant Variant::iter_get(const Variant &r_iter, bool &r_valid) const { #endif return arr->get(idx); } break; - case PACKED_REAL_ARRAY: { - const Vector<real_t> *arr = reinterpret_cast<const Vector<real_t> *>(_data._mem); + case PACKED_FLOAT64_ARRAY: { + const Vector<double> *arr = &PackedArrayRef<double>::get_array(_data.packed_array); int idx = r_iter; #ifdef DEBUG_ENABLED if (idx < 0 || idx >= arr->size()) { @@ -3411,7 +3954,7 @@ Variant Variant::iter_get(const Variant &r_iter, bool &r_valid) const { return arr->get(idx); } break; case PACKED_STRING_ARRAY: { - const Vector<String> *arr = reinterpret_cast<const Vector<String> *>(_data._mem); + const Vector<String> *arr = &PackedArrayRef<String>::get_array(_data.packed_array); int idx = r_iter; #ifdef DEBUG_ENABLED if (idx < 0 || idx >= arr->size()) { @@ -3423,7 +3966,7 @@ Variant Variant::iter_get(const Variant &r_iter, bool &r_valid) const { } break; case PACKED_VECTOR2_ARRAY: { - const Vector<Vector2> *arr = reinterpret_cast<const Vector<Vector2> *>(_data._mem); + const Vector<Vector2> *arr = &PackedArrayRef<Vector2>::get_array(_data.packed_array); int idx = r_iter; #ifdef DEBUG_ENABLED if (idx < 0 || idx >= arr->size()) { @@ -3435,7 +3978,7 @@ Variant Variant::iter_get(const Variant &r_iter, bool &r_valid) const { } break; case PACKED_VECTOR3_ARRAY: { - const Vector<Vector3> *arr = reinterpret_cast<const Vector<Vector3> *>(_data._mem); + const Vector<Vector3> *arr = &PackedArrayRef<Vector3>::get_array(_data.packed_array); int idx = r_iter; #ifdef DEBUG_ENABLED if (idx < 0 || idx >= arr->size()) { @@ -3447,7 +3990,7 @@ Variant Variant::iter_get(const Variant &r_iter, bool &r_valid) const { } break; case PACKED_COLOR_ARRAY: { - const Vector<Color> *arr = reinterpret_cast<const Vector<Color> *>(_data._mem); + const Vector<Color> *arr = &PackedArrayRef<Color>::get_array(_data.packed_array); int idx = r_iter; #ifdef DEBUG_ENABLED if (idx < 0 || idx >= arr->size()) { @@ -3510,9 +4053,9 @@ void Variant::blend(const Variant &a, const Variant &b, float c, Variant &r_dst) r_dst = int(va + vb * c + 0.5); } return; - case REAL: { - double ra = a._data._real; - double rb = b._data._real; + case FLOAT: { + double ra = a._data._float; + double rb = b._data._float; r_dst = ra + rb * c; } return; @@ -3520,16 +4063,50 @@ void Variant::blend(const Variant &a, const Variant &b, float c, Variant &r_dst) r_dst = *reinterpret_cast<const Vector2 *>(a._data._mem) + *reinterpret_cast<const Vector2 *>(b._data._mem) * c; } return; + case VECTOR2I: { + int32_t vax = reinterpret_cast<const Vector2i *>(a._data._mem)->x; + int32_t vbx = reinterpret_cast<const Vector2i *>(b._data._mem)->x; + int32_t vay = reinterpret_cast<const Vector2i *>(a._data._mem)->y; + int32_t vby = reinterpret_cast<const Vector2i *>(b._data._mem)->y; + r_dst = Vector2i(int32_t(vax + vbx * c + 0.5), int32_t(vay + vby * c + 0.5)); + } + return; case RECT2: { const Rect2 *ra = reinterpret_cast<const Rect2 *>(a._data._mem); const Rect2 *rb = reinterpret_cast<const Rect2 *>(b._data._mem); r_dst = Rect2(ra->position + rb->position * c, ra->size + rb->size * c); } return; + case RECT2I: { + const Rect2i *ra = reinterpret_cast<const Rect2i *>(a._data._mem); + const Rect2i *rb = reinterpret_cast<const Rect2i *>(b._data._mem); + + int32_t vax = ra->position.x; + int32_t vay = ra->position.y; + int32_t vbx = ra->size.x; + int32_t vby = ra->size.y; + int32_t vcx = rb->position.x; + int32_t vcy = rb->position.y; + int32_t vdx = rb->size.x; + int32_t vdy = rb->size.y; + + r_dst = Rect2i(int32_t(vax + vbx * c + 0.5), int32_t(vay + vby * c + 0.5), int32_t(vcx + vdx * c + 0.5), int32_t(vcy + vdy * c + 0.5)); + } + return; case VECTOR3: { r_dst = *reinterpret_cast<const Vector3 *>(a._data._mem) + *reinterpret_cast<const Vector3 *>(b._data._mem) * c; } return; + case VECTOR3I: { + int32_t vax = reinterpret_cast<const Vector3i *>(a._data._mem)->x; + int32_t vbx = reinterpret_cast<const Vector3i *>(b._data._mem)->x; + int32_t vay = reinterpret_cast<const Vector3i *>(a._data._mem)->y; + int32_t vby = reinterpret_cast<const Vector3i *>(b._data._mem)->y; + int32_t vaz = reinterpret_cast<const Vector3i *>(a._data._mem)->z; + int32_t vbz = reinterpret_cast<const Vector3i *>(b._data._mem)->z; + r_dst = Vector3i(int32_t(vax + vbx * c + 0.5), int32_t(vay + vby * c + 0.5), int32_t(vaz + vbz * c + 0.5)); + } + return; case AABB: { const ::AABB *ra = reinterpret_cast<const ::AABB *>(a._data._mem); const ::AABB *rb = reinterpret_cast<const ::AABB *>(b._data._mem); @@ -3595,9 +4172,9 @@ void Variant::interpolate(const Variant &a, const Variant &b, float c, Variant & r_dst = int(va + (vb - va) * c); } return; - case REAL: { - real_t va = a._data._real; - real_t vb = b._data._real; + case FLOAT: { + real_t va = a._data._float; + real_t vb = b._data._float; r_dst = va + (vb - va) * c; } return; @@ -3646,14 +4223,51 @@ void Variant::interpolate(const Variant &a, const Variant &b, float c, Variant & r_dst = reinterpret_cast<const Vector2 *>(a._data._mem)->linear_interpolate(*reinterpret_cast<const Vector2 *>(b._data._mem), c); } return; + case VECTOR2I: { + int32_t vax = reinterpret_cast<const Vector2i *>(a._data._mem)->x; + int32_t vbx = reinterpret_cast<const Vector2i *>(b._data._mem)->x; + int32_t vay = reinterpret_cast<const Vector2i *>(a._data._mem)->y; + int32_t vby = reinterpret_cast<const Vector2i *>(b._data._mem)->y; + r_dst = Vector2i(int32_t(vax + vbx * c + 0.5), int32_t(vay + vby * c + 0.5)); + } + return; + case RECT2: { r_dst = Rect2(reinterpret_cast<const Rect2 *>(a._data._mem)->position.linear_interpolate(reinterpret_cast<const Rect2 *>(b._data._mem)->position, c), reinterpret_cast<const Rect2 *>(a._data._mem)->size.linear_interpolate(reinterpret_cast<const Rect2 *>(b._data._mem)->size, c)); } return; + case RECT2I: { + const Rect2i *ra = reinterpret_cast<const Rect2i *>(a._data._mem); + const Rect2i *rb = reinterpret_cast<const Rect2i *>(b._data._mem); + + int32_t vax = ra->position.x; + int32_t vay = ra->position.y; + int32_t vbx = ra->size.x; + int32_t vby = ra->size.y; + int32_t vcx = rb->position.x; + int32_t vcy = rb->position.y; + int32_t vdx = rb->size.x; + int32_t vdy = rb->size.y; + + r_dst = Rect2i(int32_t(vax + vbx * c + 0.5), int32_t(vay + vby * c + 0.5), int32_t(vcx + vdx * c + 0.5), int32_t(vcy + vdy * c + 0.5)); + } + return; + case VECTOR3: { r_dst = reinterpret_cast<const Vector3 *>(a._data._mem)->linear_interpolate(*reinterpret_cast<const Vector3 *>(b._data._mem), c); } return; + case VECTOR3I: { + int32_t vax = reinterpret_cast<const Vector3i *>(a._data._mem)->x; + int32_t vbx = reinterpret_cast<const Vector3i *>(b._data._mem)->x; + int32_t vay = reinterpret_cast<const Vector3i *>(a._data._mem)->y; + int32_t vby = reinterpret_cast<const Vector3i *>(b._data._mem)->y; + int32_t vaz = reinterpret_cast<const Vector3i *>(a._data._mem)->z; + int32_t vbz = reinterpret_cast<const Vector3i *>(b._data._mem)->z; + r_dst = Vector3i(int32_t(vax + vbx * c + 0.5), int32_t(vay + vby * c + 0.5), int32_t(vaz + vbz * c + 0.5)); + } + return; + case TRANSFORM2D: { r_dst = a._data._transform2d->interpolate_with(*b._data._transform2d, c); } @@ -3682,6 +4296,10 @@ void Variant::interpolate(const Variant &a, const Variant &b, float c, Variant & r_dst = reinterpret_cast<const Color *>(a._data._mem)->linear_interpolate(*reinterpret_cast<const Color *>(b._data._mem), c); } return; + case STRING_NAME: { + r_dst = a; + } + return; case NODE_PATH: { r_dst = a; } @@ -3705,21 +4323,73 @@ void Variant::interpolate(const Variant &a, const Variant &b, float c, Variant & r_dst = a; } return; - case PACKED_INT_ARRAY: { - const Vector<int> *arr_a = reinterpret_cast<const Vector<int> *>(a._data._mem); - const Vector<int> *arr_b = reinterpret_cast<const Vector<int> *>(b._data._mem); + case PACKED_INT32_ARRAY: { + const Vector<int32_t> *arr_a = &PackedArrayRef<int32_t>::get_array(a._data.packed_array); + const Vector<int32_t> *arr_b = &PackedArrayRef<int32_t>::get_array(b._data.packed_array); + int32_t sz = arr_a->size(); + if (sz == 0 || arr_b->size() != sz) { + + r_dst = a; + } else { + + Vector<int32_t> v; + v.resize(sz); + { + int32_t *vw = v.ptrw(); + const int32_t *ar = arr_a->ptr(); + const int32_t *br = arr_b->ptr(); + + Variant va; + for (int32_t i = 0; i < sz; i++) { + Variant::interpolate(ar[i], br[i], c, va); + vw[i] = va; + } + } + r_dst = v; + } + } + return; + case PACKED_INT64_ARRAY: { + const Vector<int64_t> *arr_a = &PackedArrayRef<int64_t>::get_array(a._data.packed_array); + const Vector<int64_t> *arr_b = &PackedArrayRef<int64_t>::get_array(b._data.packed_array); + int64_t sz = arr_a->size(); + if (sz == 0 || arr_b->size() != sz) { + + r_dst = a; + } else { + + Vector<int64_t> v; + v.resize(sz); + { + int64_t *vw = v.ptrw(); + const int64_t *ar = arr_a->ptr(); + const int64_t *br = arr_b->ptr(); + + Variant va; + for (int64_t i = 0; i < sz; i++) { + Variant::interpolate(ar[i], br[i], c, va); + vw[i] = va; + } + } + r_dst = v; + } + } + return; + case PACKED_FLOAT32_ARRAY: { + const Vector<float> *arr_a = &PackedArrayRef<float>::get_array(a._data.packed_array); + const Vector<float> *arr_b = &PackedArrayRef<float>::get_array(b._data.packed_array); int sz = arr_a->size(); if (sz == 0 || arr_b->size() != sz) { r_dst = a; } else { - Vector<int> v; + Vector<float> v; v.resize(sz); { - int *vw = v.ptrw(); - const int *ar = arr_a->ptr(); - const int *br = arr_b->ptr(); + float *vw = v.ptrw(); + const float *ar = arr_a->ptr(); + const float *br = arr_b->ptr(); Variant va; for (int i = 0; i < sz; i++) { @@ -3731,21 +4401,21 @@ void Variant::interpolate(const Variant &a, const Variant &b, float c, Variant & } } return; - case PACKED_REAL_ARRAY: { - const Vector<real_t> *arr_a = reinterpret_cast<const Vector<real_t> *>(a._data._mem); - const Vector<real_t> *arr_b = reinterpret_cast<const Vector<real_t> *>(b._data._mem); + case PACKED_FLOAT64_ARRAY: { + const Vector<double> *arr_a = &PackedArrayRef<double>::get_array(a._data.packed_array); + const Vector<double> *arr_b = &PackedArrayRef<double>::get_array(b._data.packed_array); int sz = arr_a->size(); if (sz == 0 || arr_b->size() != sz) { r_dst = a; } else { - Vector<real_t> v; + Vector<double> v; v.resize(sz); { - real_t *vw = v.ptrw(); - const real_t *ar = arr_a->ptr(); - const real_t *br = arr_b->ptr(); + double *vw = v.ptrw(); + const double *ar = arr_a->ptr(); + const double *br = arr_b->ptr(); Variant va; for (int i = 0; i < sz; i++) { @@ -3762,8 +4432,8 @@ void Variant::interpolate(const Variant &a, const Variant &b, float c, Variant & } return; case PACKED_VECTOR2_ARRAY: { - const Vector<Vector2> *arr_a = reinterpret_cast<const Vector<Vector2> *>(a._data._mem); - const Vector<Vector2> *arr_b = reinterpret_cast<const Vector<Vector2> *>(b._data._mem); + const Vector<Vector2> *arr_a = &PackedArrayRef<Vector2>::get_array(a._data.packed_array); + const Vector<Vector2> *arr_b = &PackedArrayRef<Vector2>::get_array(b._data.packed_array); int sz = arr_a->size(); if (sz == 0 || arr_b->size() != sz) { @@ -3787,8 +4457,8 @@ void Variant::interpolate(const Variant &a, const Variant &b, float c, Variant & return; case PACKED_VECTOR3_ARRAY: { - const Vector<Vector3> *arr_a = reinterpret_cast<const Vector<Vector3> *>(a._data._mem); - const Vector<Vector3> *arr_b = reinterpret_cast<const Vector<Vector3> *>(b._data._mem); + const Vector<Vector3> *arr_a = &PackedArrayRef<Vector3>::get_array(a._data.packed_array); + const Vector<Vector3> *arr_b = &PackedArrayRef<Vector3>::get_array(b._data.packed_array); int sz = arr_a->size(); if (sz == 0 || arr_b->size() != sz) { @@ -3811,8 +4481,8 @@ void Variant::interpolate(const Variant &a, const Variant &b, float c, Variant & } return; case PACKED_COLOR_ARRAY: { - const Vector<Color> *arr_a = reinterpret_cast<const Vector<Color> *>(a._data._mem); - const Vector<Color> *arr_b = reinterpret_cast<const Vector<Color> *>(b._data._mem); + const Vector<Color> *arr_a = &PackedArrayRef<Color>::get_array(a._data.packed_array); + const Vector<Color> *arr_b = &PackedArrayRef<Color>::get_array(b._data.packed_array); int sz = arr_a->size(); if (sz == 0 || arr_b->size() != sz) { diff --git a/core/variant_parser.cpp b/core/variant_parser.cpp index f036e00ed5..12fd9976bd 100644 --- a/core/variant_parser.cpp +++ b/core/variant_parser.cpp @@ -81,6 +81,7 @@ const char *VariantParser::tk_name[TK_MAX] = { "')'", "identifier", "string", + "string_name", "number", "color", "':'", @@ -93,6 +94,8 @@ const char *VariantParser::tk_name[TK_MAX] = { Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, String &r_err_str) { + bool string_name = false; + while (true) { CharType cchar; @@ -204,6 +207,17 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri r_token.type = TK_COLOR; return OK; }; + case '@': { + cchar = p_stream->get_char(); + if (cchar != '"') { + r_err_str = "Expected '\"' after '@'"; + r_token.type = TK_ERROR; + return ERR_PARSE_ERROR; + } + + string_name = true; + [[fallthrough]]; + } case '"': { String str; @@ -285,8 +299,14 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri if (p_stream->is_utf8()) { str.parse_utf8(str.ascii(true).get_data()); } - r_token.type = TK_STRING; - r_token.value = str; + if (string_name) { + r_token.type = TK_STRING_NAME; + r_token.value = StringName(str); + string_name = false; //reset + } else { + r_token.type = TK_STRING; + r_token.value = str; + } return OK; } break; @@ -525,6 +545,19 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, value = Vector2(args[0], args[1]); return OK; + } else if (id == "Vector2i") { + + Vector<int32_t> args; + Error err = _parse_construct<int32_t>(p_stream, args, line, r_err_str); + if (err) + return err; + + if (args.size() != 2) { + r_err_str = "Expected 2 arguments for constructor"; + } + + value = Vector2i(args[0], args[1]); + return OK; } else if (id == "Rect2") { Vector<float> args; @@ -538,6 +571,19 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, value = Rect2(args[0], args[1], args[2], args[3]); return OK; + } else if (id == "Rect2i") { + + Vector<int32_t> args; + Error err = _parse_construct<int32_t>(p_stream, args, line, r_err_str); + if (err) + return err; + + if (args.size() != 4) { + r_err_str = "Expected 4 arguments for constructor"; + } + + value = Rect2i(args[0], args[1], args[2], args[3]); + return OK; } else if (id == "Vector3") { Vector<float> args; @@ -551,6 +597,19 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, value = Vector3(args[0], args[1], args[2]); return OK; + } else if (id == "Vector3i") { + + Vector<int32_t> args; + Error err = _parse_construct<int32_t>(p_stream, args, line, r_err_str); + if (err) + return err; + + if (args.size() != 3) { + r_err_str = "Expected 3 arguments for constructor"; + } + + value = Vector3i(args[0], args[1], args[2]); + return OK; } else if (id == "Transform2D" || id == "Matrix32") { //compatibility Vector<float> args; @@ -882,20 +941,20 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, return OK; - } else if (id == "PackedIntArray" || id == "PoolIntArray" || id == "IntArray") { + } else if (id == "PackedInt32Array" || id == "PackedIntArray" || id == "PoolIntArray" || id == "IntArray") { - Vector<int> args; - Error err = _parse_construct<int>(p_stream, args, line, r_err_str); + Vector<int32_t> args; + Error err = _parse_construct<int32_t>(p_stream, args, line, r_err_str); if (err) return err; - Vector<int> arr; + Vector<int32_t> arr; { - int len = args.size(); + int32_t len = args.size(); arr.resize(len); - int *w = arr.ptrw(); - for (int i = 0; i < len; i++) { - w[i] = int(args[i]); + int32_t *w = arr.ptrw(); + for (int32_t i = 0; i < len; i++) { + w[i] = int32_t(args[i]); } } @@ -903,7 +962,28 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, return OK; - } else if (id == "PackedRealArray" || id == "PoolRealArray" || id == "FloatArray") { + } else if (id == "PackedInt64Array") { + + Vector<int64_t> args; + Error err = _parse_construct<int64_t>(p_stream, args, line, r_err_str); + if (err) + return err; + + Vector<int64_t> arr; + { + int64_t len = args.size(); + arr.resize(len); + int64_t *w = arr.ptrw(); + for (int64_t i = 0; i < len; i++) { + w[i] = int64_t(args[i]); + } + } + + value = arr; + + return OK; + + } else if (id == "PackedFloat32Array" || id == "PackedRealArray" || id == "PoolRealArray" || id == "FloatArray") { Vector<float> args; Error err = _parse_construct<float>(p_stream, args, line, r_err_str); @@ -923,6 +1003,26 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, value = arr; return OK; + } else if (id == "PackedFloat64Array") { + + Vector<double> args; + Error err = _parse_construct<double>(p_stream, args, line, r_err_str); + if (err) + return err; + + Vector<double> arr; + { + int len = args.size(); + arr.resize(len); + double *w = arr.ptrw(); + for (int i = 0; i < len; i++) { + w[i] = args[i]; + } + } + + value = arr; + + return OK; } else if (id == "PackedStringArray" || id == "PoolStringArray" || id == "StringArray") { get_token(p_stream, token, line, r_err_str); @@ -1051,6 +1151,10 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, value = token.value; return OK; + } else if (token.type == TK_STRING_NAME) { + + value = token.value; + return OK; } else if (token.type == TK_COLOR) { value = token.value; @@ -1392,7 +1496,7 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str p_store_string_func(p_store_string_ud, itos(p_variant.operator int64_t())); } break; - case Variant::REAL: { + case Variant::FLOAT: { String s = rtosfix(p_variant.operator real_t()); if (s.find(".") == -1 && s.find("e") == -1) @@ -1411,17 +1515,33 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str Vector2 v = p_variant; p_store_string_func(p_store_string_ud, "Vector2( " + rtosfix(v.x) + ", " + rtosfix(v.y) + " )"); } break; + case Variant::VECTOR2I: { + + Vector2i v = p_variant; + p_store_string_func(p_store_string_ud, "Vector2i( " + itos(v.x) + ", " + itos(v.y) + " )"); + } break; case Variant::RECT2: { Rect2 aabb = p_variant; p_store_string_func(p_store_string_ud, "Rect2( " + rtosfix(aabb.position.x) + ", " + rtosfix(aabb.position.y) + ", " + rtosfix(aabb.size.x) + ", " + rtosfix(aabb.size.y) + " )"); } break; + case Variant::RECT2I: { + + Rect2i aabb = p_variant; + p_store_string_func(p_store_string_ud, "Rect2i( " + itos(aabb.position.x) + ", " + itos(aabb.position.y) + ", " + itos(aabb.size.x) + ", " + itos(aabb.size.y) + " )"); + + } break; case Variant::VECTOR3: { Vector3 v = p_variant; p_store_string_func(p_store_string_ud, "Vector3( " + rtosfix(v.x) + ", " + rtosfix(v.y) + ", " + rtosfix(v.z) + " )"); } break; + case Variant::VECTOR3I: { + + Vector3i v = p_variant; + p_store_string_func(p_store_string_ud, "Vector3i( " + itos(v.x) + ", " + itos(v.y) + ", " + itos(v.z) + " )"); + } break; case Variant::PLANE: { Plane p = p_variant; @@ -1498,6 +1618,14 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str p_store_string_func(p_store_string_ud, "Color( " + rtosfix(c.r) + ", " + rtosfix(c.g) + ", " + rtosfix(c.b) + ", " + rtosfix(c.a) + " )"); } break; + case Variant::STRING_NAME: { + + String str = p_variant; + + str = "@\"" + str.c_escape() + "\""; + p_store_string_func(p_store_string_ud, str); + + } break; case Variant::NODE_PATH: { String str = p_variant; @@ -1628,14 +1756,32 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str p_store_string_func(p_store_string_ud, " )"); } break; - case Variant::PACKED_INT_ARRAY: { + case Variant::PACKED_INT32_ARRAY: { - p_store_string_func(p_store_string_ud, "PackedIntArray( "); - Vector<int> data = p_variant; - int len = data.size(); - const int *ptr = data.ptr(); + p_store_string_func(p_store_string_ud, "PackedInt32Array( "); + Vector<int32_t> data = p_variant; + int32_t len = data.size(); + const int32_t *ptr = data.ptr(); - for (int i = 0; i < len; i++) { + for (int32_t i = 0; i < len; i++) { + + if (i > 0) + p_store_string_func(p_store_string_ud, ", "); + + p_store_string_func(p_store_string_ud, itos(ptr[i])); + } + + p_store_string_func(p_store_string_ud, " )"); + + } break; + case Variant::PACKED_INT64_ARRAY: { + + p_store_string_func(p_store_string_ud, "PackedInt64Array( "); + Vector<int64_t> data = p_variant; + int64_t len = data.size(); + const int64_t *ptr = data.ptr(); + + for (int64_t i = 0; i < len; i++) { if (i > 0) p_store_string_func(p_store_string_ud, ", "); @@ -1646,12 +1792,29 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str p_store_string_func(p_store_string_ud, " )"); } break; - case Variant::PACKED_REAL_ARRAY: { + case Variant::PACKED_FLOAT32_ARRAY: { + + p_store_string_func(p_store_string_ud, "PackedFloat32Array( "); + Vector<float> data = p_variant; + int len = data.size(); + const float *ptr = data.ptr(); + + for (int i = 0; i < len; i++) { + + if (i > 0) + p_store_string_func(p_store_string_ud, ", "); + p_store_string_func(p_store_string_ud, rtosfix(ptr[i])); + } + + p_store_string_func(p_store_string_ud, " )"); + + } break; + case Variant::PACKED_FLOAT64_ARRAY: { - p_store_string_func(p_store_string_ud, "PackedRealArray( "); - Vector<real_t> data = p_variant; + p_store_string_func(p_store_string_ud, "PackedFloat64Array( "); + Vector<double> data = p_variant; int len = data.size(); - const real_t *ptr = data.ptr(); + const double *ptr = data.ptr(); for (int i = 0; i < len; i++) { diff --git a/core/variant_parser.h b/core/variant_parser.h index 89db3ada0d..ad0a4d6682 100644 --- a/core/variant_parser.h +++ b/core/variant_parser.h @@ -92,6 +92,7 @@ public: TK_PARENTHESIS_CLOSE, TK_IDENTIFIER, TK_STRING, + TK_STRING_NAME, TK_NUMBER, TK_COLOR, TK_COLON, |