diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/extension/gdextension.cpp | 78 | ||||
-rw-r--r-- | core/extension/gdextension.h | 1 | ||||
-rw-r--r-- | core/extension/gdextension_interface.cpp | 1 | ||||
-rw-r--r-- | core/extension/gdextension_interface.h | 3 | ||||
-rw-r--r-- | core/io/image.cpp | 20 | ||||
-rw-r--r-- | core/io/resource.cpp | 3 | ||||
-rw-r--r-- | core/io/resource.h | 2 | ||||
-rw-r--r-- | core/math/bvh_refit.inc | 2 | ||||
-rw-r--r-- | core/math/bvh_split.inc | 18 | ||||
-rw-r--r-- | core/math/bvh_structs.inc | 2 | ||||
-rw-r--r-- | core/math/math_funcs.h | 31 | ||||
-rw-r--r-- | core/object/object.cpp | 18 | ||||
-rw-r--r-- | core/object/script_language_extension.h | 17 | ||||
-rw-r--r-- | core/os/os.cpp | 2 | ||||
-rw-r--r-- | core/variant/array.cpp | 2 | ||||
-rw-r--r-- | core/variant/binder_common.h | 56 | ||||
-rw-r--r-- | core/variant/callable_bind.cpp | 6 | ||||
-rw-r--r-- | core/variant/dictionary.cpp | 2 | ||||
-rw-r--r-- | core/variant/variant.cpp | 9 | ||||
-rw-r--r-- | core/variant/variant.h | 3 | ||||
-rw-r--r-- | core/variant/variant_call.cpp | 2 | ||||
-rw-r--r-- | core/variant/variant_utility.cpp | 41 | ||||
-rw-r--r-- | core/variant/variant_utility.h | 3 |
23 files changed, 190 insertions, 132 deletions
diff --git a/core/extension/gdextension.cpp b/core/extension/gdextension.cpp index 28cad12ec9..7e280466a8 100644 --- a/core/extension/gdextension.cpp +++ b/core/extension/gdextension.cpp @@ -683,9 +683,45 @@ GDExtensionInterfaceFunctionPtr GDExtension::get_interface_function(StringName p } Error GDExtension::open_library(const String &p_path, const String &p_entry_symbol) { - Error err = OS::get_singleton()->open_dynamic_library(p_path, library, true, &library_path); + library_path = p_path; + + String abs_path = ProjectSettings::get_singleton()->globalize_path(p_path); +#if defined(WINDOWS_ENABLED) && defined(TOOLS_ENABLED) + // If running on the editor on Windows, we copy the library and open the copy. + // This is so the original file isn't locked and can be updated by a compiler. + if (Engine::get_singleton()->is_editor_hint()) { + if (!FileAccess::exists(abs_path)) { + ERR_PRINT("GDExtension library not found: " + library_path); + return ERR_FILE_NOT_FOUND; + } + + // Copy the file to the same directory as the original with a prefix in the name. + // This is so relative path to dependencies are satisfied. + String copy_path = abs_path.get_base_dir().path_join("~" + abs_path.get_file()); + + // If there's a left-over copy (possibly from a crash) then delete it first. + if (FileAccess::exists(copy_path)) { + DirAccess::remove_absolute(copy_path); + } + + Error copy_err = DirAccess::copy_absolute(abs_path, copy_path); + if (copy_err) { + ERR_PRINT("Error copying GDExtension library: " + library_path); + return ERR_CANT_CREATE; + } + FileAccess::set_hidden_attribute(copy_path, true); + + // Save the copied path so it can be deleted later. + temp_lib_path = copy_path; + + // Use the copy to open the library. + abs_path = copy_path; + } +#endif + + Error err = OS::get_singleton()->open_dynamic_library(abs_path, library, true); if (err != OK) { - ERR_PRINT("GDExtension dynamic library not found: " + p_path); + ERR_PRINT("GDExtension dynamic library not found: " + abs_path); return err; } @@ -694,7 +730,7 @@ Error GDExtension::open_library(const String &p_path, const String &p_entry_symb err = OS::get_singleton()->get_dynamic_library_symbol_handle(library, p_entry_symbol, entry_funcptr, false); if (err != OK) { - ERR_PRINT("GDExtension entry point '" + p_entry_symbol + "' not found in library " + p_path); + ERR_PRINT("GDExtension entry point '" + p_entry_symbol + "' not found in library " + abs_path); OS::get_singleton()->close_dynamic_library(library); return err; } @@ -884,41 +920,7 @@ Error GDExtensionResourceLoader::load_gdextension_resource(const String &p_path, FileAccess::get_modified_time(p_path))); #endif - String abs_path = ProjectSettings::get_singleton()->globalize_path(library_path); -#if defined(WINDOWS_ENABLED) && defined(TOOLS_ENABLED) - // If running on the editor on Windows, we copy the library and open the copy. - // This is so the original file isn't locked and can be updated by a compiler. - if (Engine::get_singleton()->is_editor_hint()) { - if (!FileAccess::exists(abs_path)) { - ERR_PRINT("GDExtension library not found: " + library_path); - return ERR_FILE_NOT_FOUND; - } - - // Copy the file to the same directory as the original with a prefix in the name. - // This is so relative path to dependencies are satisfied. - String copy_path = abs_path.get_base_dir().path_join("~" + abs_path.get_file()); - - // If there's a left-over copy (possibly from a crash) then delete it first. - if (FileAccess::exists(copy_path)) { - DirAccess::remove_absolute(copy_path); - } - - Error copy_err = DirAccess::copy_absolute(abs_path, copy_path); - if (copy_err) { - ERR_PRINT("Error copying GDExtension library: " + library_path); - return ERR_CANT_CREATE; - } - FileAccess::set_hidden_attribute(copy_path, true); - - // Save the copied path so it can be deleted later. - p_extension->set_temp_library_path(copy_path); - - // Use the copy to open the library. - abs_path = copy_path; - } -#endif - - err = p_extension->open_library(abs_path, entry_symbol); + err = p_extension->open_library(library_path, entry_symbol); if (err != OK) { #if defined(WINDOWS_ENABLED) && defined(TOOLS_ENABLED) // If the DLL fails to load, make sure that temporary DLL copies are cleaned up. diff --git a/core/extension/gdextension.h b/core/extension/gdextension.h index 2b42346478..2996100c9a 100644 --- a/core/extension/gdextension.h +++ b/core/extension/gdextension.h @@ -119,7 +119,6 @@ public: void close_library(); #if defined(WINDOWS_ENABLED) && defined(TOOLS_ENABLED) - void set_temp_library_path(const String &p_path) { temp_lib_path = p_path; } String get_temp_library_path() const { return temp_lib_path; } #endif diff --git a/core/extension/gdextension_interface.cpp b/core/extension/gdextension_interface.cpp index 1a806791c9..2b4a37b1e0 100644 --- a/core/extension/gdextension_interface.cpp +++ b/core/extension/gdextension_interface.cpp @@ -1213,6 +1213,7 @@ static GDExtensionScriptInstancePtr gdextension_script_instance_create(const GDE info_2->get_func = p_info->get_func; info_2->get_property_list_func = p_info->get_property_list_func; info_2->free_property_list_func = p_info->free_property_list_func; + info_2->get_class_category_func = nullptr; info_2->property_can_revert_func = p_info->property_can_revert_func; info_2->property_get_revert_func = p_info->property_get_revert_func; info_2->get_owner_func = p_info->get_owner_func; diff --git a/core/extension/gdextension_interface.h b/core/extension/gdextension_interface.h index 08bdf55581..35602b76dd 100644 --- a/core/extension/gdextension_interface.h +++ b/core/extension/gdextension_interface.h @@ -430,6 +430,8 @@ typedef GDExtensionBool (*GDExtensionScriptInstanceSet)(GDExtensionScriptInstanc typedef GDExtensionBool (*GDExtensionScriptInstanceGet)(GDExtensionScriptInstanceDataPtr p_instance, GDExtensionConstStringNamePtr p_name, GDExtensionVariantPtr r_ret); typedef const GDExtensionPropertyInfo *(*GDExtensionScriptInstanceGetPropertyList)(GDExtensionScriptInstanceDataPtr p_instance, uint32_t *r_count); typedef void (*GDExtensionScriptInstanceFreePropertyList)(GDExtensionScriptInstanceDataPtr p_instance, const GDExtensionPropertyInfo *p_list); +typedef GDExtensionBool (*GDExtensionScriptInstanceGetClassCategory)(GDExtensionScriptInstanceDataPtr p_instance, GDExtensionPropertyInfo *p_class_category); + typedef GDExtensionVariantType (*GDExtensionScriptInstanceGetPropertyType)(GDExtensionScriptInstanceDataPtr p_instance, GDExtensionConstStringNamePtr p_name, GDExtensionBool *r_is_valid); typedef GDExtensionBool (*GDExtensionScriptInstanceValidateProperty)(GDExtensionScriptInstanceDataPtr p_instance, GDExtensionPropertyInfo *p_property); @@ -508,6 +510,7 @@ typedef struct { GDExtensionScriptInstanceGet get_func; GDExtensionScriptInstanceGetPropertyList get_property_list_func; GDExtensionScriptInstanceFreePropertyList free_property_list_func; + GDExtensionScriptInstanceGetClassCategory get_class_category_func; GDExtensionScriptInstancePropertyCanRevert property_can_revert_func; GDExtensionScriptInstancePropertyGetRevert property_get_revert_func; diff --git a/core/io/image.cpp b/core/io/image.cpp index 674af6b0a6..15d0182dfc 100644 --- a/core/io/image.cpp +++ b/core/io/image.cpp @@ -1930,8 +1930,7 @@ Error Image::generate_mipmaps(bool p_renormalize) { } Error Image::generate_mipmap_roughness(RoughnessChannel p_roughness_channel, const Ref<Image> &p_normal_map) { - Vector<double> normal_sat_vec; //summed area table - double *normal_sat = nullptr; //summed area table for normal map + LocalVector<double> normal_sat_vec; //summed area table int normal_w = 0, normal_h = 0; ERR_FAIL_COND_V_MSG(p_normal_map.is_null() || p_normal_map->is_empty(), ERR_INVALID_PARAMETER, "Must provide a valid normal map for roughness mipmaps"); @@ -1945,8 +1944,7 @@ Error Image::generate_mipmap_roughness(RoughnessChannel p_roughness_channel, con normal_h = nm->get_height(); normal_sat_vec.resize(normal_w * normal_h * 3); - - normal_sat = normal_sat_vec.ptrw(); + double *normal_sat = normal_sat_vec.ptr(); //create summed area table @@ -2021,24 +2019,26 @@ Error Image::generate_mipmap_roughness(RoughnessChannel p_roughness_channel, con avg[2] += normal_sat[tofs + 2]; } - if (from_y > 0) { + if (from_y > 0 && to_x > 0) { uint32_t tofs = ((from_y - 1) * normal_w + to_x) * 3; avg[0] -= normal_sat[tofs + 0]; avg[1] -= normal_sat[tofs + 1]; avg[2] -= normal_sat[tofs + 2]; } - if (from_x > 0) { + if (from_x > 0 && to_y > 0) { uint32_t tofs = (to_y * normal_w + (from_x - 1)) * 3; avg[0] -= normal_sat[tofs + 0]; avg[1] -= normal_sat[tofs + 1]; avg[2] -= normal_sat[tofs + 2]; } - uint32_t tofs = (to_y * normal_w + to_x) * 3; - avg[0] += normal_sat[tofs + 0]; - avg[1] += normal_sat[tofs + 1]; - avg[2] += normal_sat[tofs + 2]; + if (to_y > 0 && to_x > 0) { + uint32_t tofs = (to_y * normal_w + to_x) * 3; + avg[0] += normal_sat[tofs + 0]; + avg[1] += normal_sat[tofs + 1]; + avg[2] += normal_sat[tofs + 2]; + } double div = double(size_x * size_y); Vector3 vec(avg[0] / div, avg[1] / div, avg[2] / div); diff --git a/core/io/resource.cpp b/core/io/resource.cpp index 68cdeabac7..e0d42a274a 100644 --- a/core/io/resource.cpp +++ b/core/io/resource.cpp @@ -379,8 +379,8 @@ Node *Resource::get_local_scene() const { } void Resource::setup_local_to_scene() { - // Can't use GDVIRTUAL in Resource, so this will have to be done with a signal emit_signal(SNAME("setup_local_to_scene_requested")); + GDVIRTUAL_CALL(_setup_local_to_scene); } void Resource::reset_local_to_scene() { @@ -460,6 +460,7 @@ void Resource::_bind_methods() { get_rid_bind.return_val.type = Variant::RID; ::ClassDB::add_virtual_method(get_class_static(), get_rid_bind, true, Vector<String>(), true); + GDVIRTUAL_BIND(_setup_local_to_scene); } Resource::Resource() : diff --git a/core/io/resource.h b/core/io/resource.h index f848bdba99..a9b1a88f6b 100644 --- a/core/io/resource.h +++ b/core/io/resource.h @@ -33,6 +33,7 @@ #include "core/io/resource_uid.h" #include "core/object/class_db.h" +#include "core/object/gdvirtual.gen.inc" #include "core/object/ref_counted.h" #include "core/templates/safe_refcount.h" #include "core/templates/self_list.h" @@ -81,6 +82,7 @@ protected: void _take_over_path(const String &p_path); virtual void reset_local_to_scene(); + GDVIRTUAL0(_setup_local_to_scene); public: static Node *(*_get_local_scene_func)(); //used by editor diff --git a/core/math/bvh_refit.inc b/core/math/bvh_refit.inc index 717a3438c7..b20b805bb0 100644 --- a/core/math/bvh_refit.inc +++ b/core/math/bvh_refit.inc @@ -134,7 +134,7 @@ void refit_branch(uint32_t p_node_id) { TLeaf &leaf = _node_get_leaf(tnode); if (leaf.is_dirty()) { leaf.set_dirty(false); - refit_upward(p_node_id); + refit_upward(rp.node_id); } } } // while more nodes to pop diff --git a/core/math/bvh_split.inc b/core/math/bvh_split.inc index 875abedb70..2c85a63575 100644 --- a/core/math/bvh_split.inc +++ b/core/math/bvh_split.inc @@ -20,8 +20,8 @@ void _split_leaf_sort_groups_simple(int &num_a, int &num_b, uint16_t *group_a, u group_b[num_b++] = ind; // remove from a - group_a[0] = group_a[num_a - 1]; num_a--; + group_a[0] = group_a[num_a]; return; } @@ -30,15 +30,15 @@ void _split_leaf_sort_groups_simple(int &num_a, int &num_b, uint16_t *group_a, u int order[POINT::AXIS_COUNT]; - order[0] = size.min_axis_index(); - order[POINT::AXIS_COUNT - 1] = size.max_axis_index(); + order[0] = size.max_axis_index(); // The longest axis. + order[POINT::AXIS_COUNT - 1] = size.min_axis_index(); // The shortest axis. static_assert(POINT::AXIS_COUNT <= 3, "BVH POINT::AXIS_COUNT has unexpected size"); if constexpr (POINT::AXIS_COUNT == 3) { order[1] = 3 - (order[0] + order[2]); } - // simplest case, split on the longest axis + // Simplest case, split on the longest axis. int split_axis = order[0]; for (int a = 0; a < num_a; a++) { uint32_t ind = group_a[a]; @@ -48,8 +48,8 @@ void _split_leaf_sort_groups_simple(int &num_a, int &num_b, uint16_t *group_a, u group_b[num_b++] = ind; // remove from a - group_a[a] = group_a[num_a - 1]; num_a--; + group_a[a] = group_a[num_a]; // do this one again, as it has been replaced a--; @@ -67,7 +67,7 @@ void _split_leaf_sort_groups_simple(int &num_a, int &num_b, uint16_t *group_a, u } num_b = 0; - // now calculate the best split + // Now calculate the best split. for (int axis = 1; axis < POINT::AXIS_COUNT; axis++) { split_axis = order[axis]; int count = 0; @@ -105,8 +105,8 @@ void _split_leaf_sort_groups_simple(int &num_a, int &num_b, uint16_t *group_a, u group_b[num_b++] = ind; // remove from a - group_a[a] = group_a[num_a - 1]; num_a--; + group_a[a] = group_a[num_a]; // do this one again, as it has been replaced a--; @@ -123,8 +123,8 @@ void _split_leaf_sort_groups_simple(int &num_a, int &num_b, uint16_t *group_a, u group_b[num_b++] = ind; // remove from a - group_a[0] = group_a[num_a - 1]; num_a--; + group_a[0] = group_a[num_a]; } // opposite problem! :) if (!num_a) { @@ -134,8 +134,8 @@ void _split_leaf_sort_groups_simple(int &num_a, int &num_b, uint16_t *group_a, u group_a[num_a++] = ind; // remove from b - group_b[0] = group_b[num_b - 1]; num_b--; + group_b[0] = group_b[num_b]; } } diff --git a/core/math/bvh_structs.inc b/core/math/bvh_structs.inc index 06f6e5d05d..d40c631ce2 100644 --- a/core/math/bvh_structs.inc +++ b/core/math/bvh_structs.inc @@ -83,7 +83,7 @@ public: void clear() { num_items = 0; - set_dirty(true); + set_dirty(false); } bool is_full() const { return num_items >= MAX_ITEMS; } diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h index 934c75b5d3..366ccca4cb 100644 --- a/core/math/math_funcs.h +++ b/core/math/math_funcs.h @@ -399,15 +399,20 @@ public: return d; } - static _ALWAYS_INLINE_ double lerp_angle(double p_from, double p_to, double p_weight) { + static _ALWAYS_INLINE_ double angle_difference(double p_from, double p_to) { double difference = fmod(p_to - p_from, Math_TAU); - double distance = fmod(2.0 * difference, Math_TAU) - difference; - return p_from + distance * p_weight; + return fmod(2.0 * difference, Math_TAU) - difference; } - static _ALWAYS_INLINE_ float lerp_angle(float p_from, float p_to, float p_weight) { + static _ALWAYS_INLINE_ float angle_difference(float p_from, float p_to) { float difference = fmod(p_to - p_from, (float)Math_TAU); - float distance = fmod(2.0f * difference, (float)Math_TAU) - difference; - return p_from + distance * p_weight; + return fmod(2.0f * difference, (float)Math_TAU) - difference; + } + + static _ALWAYS_INLINE_ double lerp_angle(double p_from, double p_to, double p_weight) { + return p_from + Math::angle_difference(p_from, p_to) * p_weight; + } + static _ALWAYS_INLINE_ float lerp_angle(float p_from, float p_to, float p_weight) { + return p_from + Math::angle_difference(p_from, p_to) * p_weight; } static _ALWAYS_INLINE_ double inverse_lerp(double p_from, double p_to, double p_value) { @@ -438,6 +443,7 @@ public: float s = CLAMP((p_s - p_from) / (p_to - p_from), 0.0f, 1.0f); return s * s * (3.0f - 2.0f * s); } + static _ALWAYS_INLINE_ double move_toward(double p_from, double p_to, double p_delta) { return abs(p_to - p_from) <= p_delta ? p_to : p_from + SIGN(p_to - p_from) * p_delta; } @@ -445,6 +451,19 @@ public: return abs(p_to - p_from) <= p_delta ? p_to : p_from + SIGN(p_to - p_from) * p_delta; } + static _ALWAYS_INLINE_ double rotate_toward(double p_from, double p_to, double p_delta) { + double difference = Math::angle_difference(p_from, p_to); + double abs_difference = Math::abs(difference); + // When `p_delta < 0` move no further than to PI radians away from `p_to` (as PI is the max possible angle distance). + return p_from + CLAMP(p_delta, abs_difference - Math_PI, abs_difference) * (difference >= 0.0 ? 1.0 : -1.0); + } + static _ALWAYS_INLINE_ float rotate_toward(float p_from, float p_to, float p_delta) { + float difference = Math::angle_difference(p_from, p_to); + float abs_difference = Math::abs(difference); + // When `p_delta < 0` move no further than to PI radians away from `p_to` (as PI is the max possible angle distance). + return p_from + CLAMP(p_delta, abs_difference - (float)Math_PI, abs_difference) * (difference >= 0.0f ? 1.0f : -1.0f); + } + static _ALWAYS_INLINE_ double linear_to_db(double p_linear) { return Math::log(p_linear) * 8.6858896380650365530225783783321; } diff --git a/core/object/object.cpp b/core/object/object.cpp index 0a6cd32f3c..f62b93d0ff 100644 --- a/core/object/object.cpp +++ b/core/object/object.cpp @@ -617,7 +617,7 @@ void Object::get_method_list(List<MethodInfo> *p_list) const { Variant Object::_call_bind(const Variant **p_args, int p_argcount, Callable::CallError &r_error) { if (p_argcount < 1) { r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; - r_error.argument = 0; + r_error.expected = 1; return Variant(); } @@ -636,7 +636,7 @@ Variant Object::_call_bind(const Variant **p_args, int p_argcount, Callable::Cal Variant Object::_call_deferred_bind(const Variant **p_args, int p_argcount, Callable::CallError &r_error) { if (p_argcount < 1) { r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; - r_error.argument = 0; + r_error.expected = 1; return Variant(); } @@ -715,12 +715,11 @@ Variant Object::callp(const StringName &p_method, const Variant **p_args, int p_ //free must be here, before anything, always ready #ifdef DEBUG_ENABLED if (p_argcount != 0) { - r_error.argument = 0; r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS; + r_error.expected = 0; return Variant(); } if (Object::cast_to<RefCounted>(this)) { - r_error.argument = 0; r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; ERR_FAIL_V_MSG(Variant(), "Can't 'free' a reference."); } @@ -1036,14 +1035,17 @@ struct _ObjectSignalDisconnectData { }; Error Object::_emit_signal(const Variant **p_args, int p_argcount, Callable::CallError &r_error) { - r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; + if (unlikely(p_argcount < 1)) { + r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; + r_error.expected = 1; + ERR_FAIL_V(Error::ERR_INVALID_PARAMETER); + } - ERR_FAIL_COND_V(p_argcount < 1, Error::ERR_INVALID_PARAMETER); - if (p_args[0]->get_type() != Variant::STRING_NAME && p_args[0]->get_type() != Variant::STRING) { + if (unlikely(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_NAME; - ERR_FAIL_COND_V(p_args[0]->get_type() != Variant::STRING_NAME && p_args[0]->get_type() != Variant::STRING, Error::ERR_INVALID_PARAMETER); + ERR_FAIL_V(Error::ERR_INVALID_PARAMETER); } r_error.error = Callable::CallError::CALL_OK; diff --git a/core/object/script_language_extension.h b/core/object/script_language_extension.h index 3e8284670c..b682efec12 100644 --- a/core/object/script_language_extension.h +++ b/core/object/script_language_extension.h @@ -670,9 +670,20 @@ public: const GDExtensionPropertyInfo *pinfo = native_info->get_property_list_func(instance, &pcount); #ifdef TOOLS_ENABLED - Ref<Script> script = get_script(); - if (script.is_valid() && pcount > 0) { - p_list->push_back(script->get_class_category()); + if (pcount > 0) { + if (native_info->get_class_category_func) { + GDExtensionPropertyInfo gdext_class_category; + if (native_info->get_class_category_func(instance, &gdext_class_category)) { + p_list->push_back(PropertyInfo(gdext_class_category)); + } +#ifndef DISABLE_DEPRECATED + } else { + Ref<Script> script = get_script(); + if (script.is_valid()) { + p_list->push_back(script->get_class_category()); + } +#endif // DISABLE_DEPRECATED + } } #endif // TOOLS_ENABLED diff --git a/core/os/os.cpp b/core/os/os.cpp index 38ea4a0fdd..991b179e1f 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -355,7 +355,7 @@ void OS::set_cmdline(const char *p_execpath, const List<String> &p_args, const L } String OS::get_unique_id() const { - ERR_FAIL_V(""); + return ""; } int OS::get_processor_count() const { diff --git a/core/variant/array.cpp b/core/variant/array.cpp index 4c9ee68ab5..ab0315ae34 100644 --- a/core/variant/array.cpp +++ b/core/variant/array.cpp @@ -137,7 +137,7 @@ bool Array::recursive_equal(const Array &p_array, int recursion_count) const { } recursion_count++; for (int i = 0; i < size; i++) { - if (!a1[i].hash_compare(a2[i], recursion_count)) { + if (!a1[i].hash_compare(a2[i], recursion_count, false)) { return false; } } diff --git a/core/variant/binder_common.h b/core/variant/binder_common.h index 9f8fb7e95e..34b54f1d00 100644 --- a/core/variant/binder_common.h +++ b/core/variant/binder_common.h @@ -404,13 +404,13 @@ void call_with_variant_args(T *p_instance, void (T::*p_method)(P...), const Vari #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); + r_error.expected = 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); + r_error.expected = sizeof...(P); return; } #endif @@ -422,7 +422,7 @@ void call_with_variant_args_dv(T *p_instance, void (T::*p_method)(P...), const V #ifdef DEBUG_ENABLED if ((size_t)p_argcount > sizeof...(P)) { r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS; - r_error.argument = sizeof...(P); + r_error.expected = sizeof...(P); return; } #endif @@ -433,7 +433,7 @@ void call_with_variant_args_dv(T *p_instance, void (T::*p_method)(P...), const V #ifdef DEBUG_ENABLED if (missing > dvs) { r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; - r_error.argument = sizeof...(P); + r_error.expected = sizeof...(P); return; } #endif @@ -455,13 +455,13 @@ void call_with_variant_argsc(T *p_instance, void (T::*p_method)(P...) const, con #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); + r_error.expected = 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); + r_error.expected = sizeof...(P); return; } #endif @@ -473,7 +473,7 @@ void call_with_variant_argsc_dv(T *p_instance, void (T::*p_method)(P...) const, #ifdef DEBUG_ENABLED if ((size_t)p_argcount > sizeof...(P)) { r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS; - r_error.argument = sizeof...(P); + r_error.expected = sizeof...(P); return; } #endif @@ -484,7 +484,7 @@ void call_with_variant_argsc_dv(T *p_instance, void (T::*p_method)(P...) const, #ifdef DEBUG_ENABLED if (missing > dvs) { r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; - r_error.argument = sizeof...(P); + r_error.expected = sizeof...(P); return; } #endif @@ -506,7 +506,7 @@ void call_with_variant_args_ret_dv(T *p_instance, R (T::*p_method)(P...), const #ifdef DEBUG_ENABLED if ((size_t)p_argcount > sizeof...(P)) { r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS; - r_error.argument = sizeof...(P); + r_error.expected = sizeof...(P); return; } #endif @@ -517,7 +517,7 @@ void call_with_variant_args_ret_dv(T *p_instance, R (T::*p_method)(P...), const #ifdef DEBUG_ENABLED if (missing > dvs) { r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; - r_error.argument = sizeof...(P); + r_error.expected = sizeof...(P); return; } #endif @@ -539,7 +539,7 @@ void call_with_variant_args_retc_dv(T *p_instance, R (T::*p_method)(P...) const, #ifdef DEBUG_ENABLED if ((size_t)p_argcount > sizeof...(P)) { r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS; - r_error.argument = sizeof...(P); + r_error.expected = sizeof...(P); return; } #endif @@ -550,7 +550,7 @@ void call_with_variant_args_retc_dv(T *p_instance, R (T::*p_method)(P...) const, #ifdef DEBUG_ENABLED if (missing > dvs) { r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; - r_error.argument = sizeof...(P); + r_error.expected = sizeof...(P); return; } #endif @@ -785,13 +785,13 @@ void call_with_variant_args_ret(T *p_instance, R (T::*p_method)(P...), const Var #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); + r_error.expected = 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); + r_error.expected = sizeof...(P); return; } #endif @@ -815,13 +815,13 @@ void call_with_variant_args_static_ret(R (*p_method)(P...), const Variant **p_ar #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); + r_error.expected = 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); + r_error.expected = sizeof...(P); return; } #endif @@ -833,13 +833,13 @@ void call_with_variant_args_static_ret(void (*p_method)(P...), const Variant **p #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); + r_error.expected = 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); + r_error.expected = sizeof...(P); return; } #endif @@ -851,13 +851,13 @@ void call_with_variant_args_retc(T *p_instance, R (T::*p_method)(P...) const, co #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); + r_error.expected = 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); + r_error.expected = sizeof...(P); return; } #endif @@ -882,7 +882,7 @@ void call_with_variant_args_retc_static_helper_dv(T *p_instance, R (*p_method)(T #ifdef DEBUG_ENABLED if ((size_t)p_argcount > sizeof...(P)) { r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS; - r_error.argument = sizeof...(P); + r_error.expected = sizeof...(P); return; } #endif @@ -893,7 +893,7 @@ void call_with_variant_args_retc_static_helper_dv(T *p_instance, R (*p_method)(T #ifdef DEBUG_ENABLED if (missing > dvs) { r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; - r_error.argument = sizeof...(P); + r_error.expected = sizeof...(P); return; } #endif @@ -928,7 +928,7 @@ void call_with_variant_args_static_helper_dv(T *p_instance, void (*p_method)(T * #ifdef DEBUG_ENABLED if ((size_t)p_argcount > sizeof...(P)) { r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS; - r_error.argument = sizeof...(P); + r_error.expected = sizeof...(P); return; } #endif @@ -939,7 +939,7 @@ void call_with_variant_args_static_helper_dv(T *p_instance, void (*p_method)(T * #ifdef DEBUG_ENABLED if (missing > dvs) { r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; - r_error.argument = sizeof...(P); + r_error.expected = sizeof...(P); return; } #endif @@ -961,7 +961,7 @@ void call_with_variant_args_static_ret_dv(R (*p_method)(P...), const Variant **p #ifdef DEBUG_ENABLED if ((size_t)p_argcount > sizeof...(P)) { r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS; - r_error.argument = sizeof...(P); + r_error.expected = sizeof...(P); return; } #endif @@ -972,7 +972,7 @@ void call_with_variant_args_static_ret_dv(R (*p_method)(P...), const Variant **p #ifdef DEBUG_ENABLED if (missing > dvs) { r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; - r_error.argument = sizeof...(P); + r_error.expected = sizeof...(P); return; } #endif @@ -994,7 +994,7 @@ void call_with_variant_args_static_dv(void (*p_method)(P...), const Variant **p_ #ifdef DEBUG_ENABLED if ((size_t)p_argcount > sizeof...(P)) { r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS; - r_error.argument = sizeof...(P); + r_error.expected = sizeof...(P); return; } #endif @@ -1005,7 +1005,7 @@ void call_with_variant_args_static_dv(void (*p_method)(P...), const Variant **p_ #ifdef DEBUG_ENABLED if (missing > dvs) { r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; - r_error.argument = sizeof...(P); + r_error.expected = sizeof...(P); return; } #endif diff --git a/core/variant/callable_bind.cpp b/core/variant/callable_bind.cpp index a5629d5d39..9a6380a55f 100644 --- a/core/variant/callable_bind.cpp +++ b/core/variant/callable_bind.cpp @@ -245,9 +245,8 @@ void CallableCustomUnbind::get_bound_arguments(Vector<Variant> &r_arguments, int } void CallableCustomUnbind::call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const { - if (argcount > p_argcount) { + if (p_argcount < argcount) { r_call_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; - r_call_error.argument = 0; r_call_error.expected = argcount; return; } @@ -255,9 +254,8 @@ void CallableCustomUnbind::call(const Variant **p_arguments, int p_argcount, Var } Error CallableCustomUnbind::rpc(int p_peer_id, const Variant **p_arguments, int p_argcount, Callable::CallError &r_call_error) const { - if (argcount > p_argcount) { + if (p_argcount < argcount) { r_call_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; - r_call_error.argument = 0; r_call_error.expected = argcount; return ERR_UNCONFIGURED; } diff --git a/core/variant/dictionary.cpp b/core/variant/dictionary.cpp index 2dda9fc1f8..141ce25fa6 100644 --- a/core/variant/dictionary.cpp +++ b/core/variant/dictionary.cpp @@ -210,7 +210,7 @@ bool Dictionary::recursive_equal(const Dictionary &p_dictionary, int recursion_c recursion_count++; for (const KeyValue<Variant, Variant> &this_E : _p->variant_map) { HashMap<Variant, Variant, VariantHasher, StringLikeVariantComparator>::ConstIterator other_E(p_dictionary._p->variant_map.find(this_E.key)); - if (!other_E || !this_E.value.hash_compare(other_E->value, recursion_count)) { + if (!other_E || !this_E.value.hash_compare(other_E->value, recursion_count, false)) { return false; } } diff --git a/core/variant/variant.cpp b/core/variant/variant.cpp index 8a0289898d..63ea3274ce 100644 --- a/core/variant/variant.cpp +++ b/core/variant/variant.cpp @@ -3235,8 +3235,11 @@ uint32_t Variant::recursive_hash(int recursion_count) const { return 0; } +#define hash_compare_scalar_base(p_lhs, p_rhs, semantic_comparison) \ + (((p_lhs) == (p_rhs)) || (semantic_comparison && Math::is_nan(p_lhs) && Math::is_nan(p_rhs))) + #define hash_compare_scalar(p_lhs, p_rhs) \ - (((p_lhs) == (p_rhs)) || (Math::is_nan(p_lhs) && Math::is_nan(p_rhs))) + (hash_compare_scalar_base(p_lhs, p_rhs, true)) #define hash_compare_vector2(p_lhs, p_rhs) \ (hash_compare_scalar((p_lhs).x, (p_rhs).x) && \ @@ -3282,7 +3285,7 @@ uint32_t Variant::recursive_hash(int recursion_count) const { \ return true -bool Variant::hash_compare(const Variant &p_variant, int recursion_count) const { +bool Variant::hash_compare(const Variant &p_variant, int recursion_count, bool semantic_comparison) const { if (type != p_variant.type) { return false; } @@ -3293,7 +3296,7 @@ bool Variant::hash_compare(const Variant &p_variant, int recursion_count) const } break; case FLOAT: { - return hash_compare_scalar(_data._float, p_variant._data._float); + return hash_compare_scalar_base(_data._float, p_variant._data._float, semantic_comparison); } break; case STRING: { diff --git a/core/variant/variant.h b/core/variant/variant.h index 04c2fe2012..d698f85754 100644 --- a/core/variant/variant.h +++ b/core/variant/variant.h @@ -751,7 +751,8 @@ public: uint32_t hash() const; uint32_t recursive_hash(int recursion_count) const; - bool hash_compare(const Variant &p_variant, int recursion_count = 0) const; + // By default, performs a semantic comparison. Otherwise, numeric/binary comparison (if appropriate). + bool hash_compare(const Variant &p_variant, int recursion_count = 0, bool semantic_comparison = true) const; bool identity_compare(const Variant &p_variant) const; bool booleanize() const; String stringify(int recursion_count = 0) const; diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp index b21e23b3ec..f041d2c95e 100644 --- a/core/variant/variant_call.cpp +++ b/core/variant/variant_call.cpp @@ -1037,9 +1037,7 @@ struct _VariantCall { static void func_Callable_rpc_id(Variant *v, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) { if (p_argcount == 0) { r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; - r_error.argument = 0; r_error.expected = 1; - } else if (p_args[0]->get_type() != Variant::INT) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; diff --git a/core/variant/variant_utility.cpp b/core/variant/variant_utility.cpp index 0a63749ac5..6f334d1859 100644 --- a/core/variant/variant_utility.cpp +++ b/core/variant/variant_utility.cpp @@ -337,6 +337,7 @@ Variant VariantUtilityFunctions::snapped(const Variant &x, const Variant &step, if (x.get_type() != step.get_type() && !((x.get_type() == Variant::INT && step.get_type() == Variant::FLOAT) || (x.get_type() == Variant::FLOAT && step.get_type() == Variant::INT))) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 1; + r_error.expected = x.get_type(); return Variant(); } @@ -384,8 +385,8 @@ Variant VariantUtilityFunctions::lerp(const Variant &from, const Variant &to, do r_error.error = Callable::CallError::CALL_OK; if (from.get_type() != to.get_type()) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; - r_error.expected = from.get_type(); r_error.argument = 1; + r_error.expected = from.get_type(); return Variant(); } @@ -451,6 +452,10 @@ double VariantUtilityFunctions::bezier_derivative(double p_start, double p_contr return Math::bezier_derivative(p_start, p_control_1, p_control_2, p_end, p_t); } +double VariantUtilityFunctions::angle_difference(double from, double to) { + return Math::angle_difference(from, to); +} + double VariantUtilityFunctions::lerp_angle(double from, double to, double weight) { return Math::lerp_angle(from, to, weight); } @@ -471,6 +476,10 @@ double VariantUtilityFunctions::move_toward(double from, double to, double delta return Math::move_toward(from, to, delta); } +double VariantUtilityFunctions::rotate_toward(double from, double to, double delta) { + return Math::rotate_toward(from, to, delta); +} + double VariantUtilityFunctions::deg_to_rad(double angle_deg) { return Math::deg_to_rad(angle_deg); } @@ -492,7 +501,7 @@ Variant VariantUtilityFunctions::wrap(const Variant &p_x, const Variant &p_min, if (x_type != Variant::INT && x_type != Variant::FLOAT) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; - r_error.expected = x_type; + r_error.expected = Variant::FLOAT; return Variant(); } @@ -558,8 +567,8 @@ Variant VariantUtilityFunctions::max(const Variant **p_args, int p_argcount, Cal Variant::Type arg_type = p_args[i]->get_type(); if (arg_type != Variant::INT && arg_type != Variant::FLOAT) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; - r_error.expected = Variant::FLOAT; r_error.argument = i; + r_error.expected = Variant::FLOAT; return Variant(); } if (i == 0) { @@ -569,8 +578,8 @@ Variant VariantUtilityFunctions::max(const Variant **p_args, int p_argcount, Cal Variant::evaluate(Variant::OP_LESS, base, *p_args[i], ret, valid); if (!valid) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; - r_error.expected = base.get_type(); r_error.argument = i; + r_error.expected = base.get_type(); return Variant(); } if (ret.booleanize()) { @@ -602,8 +611,8 @@ Variant VariantUtilityFunctions::min(const Variant **p_args, int p_argcount, Cal Variant::Type arg_type = p_args[i]->get_type(); if (arg_type != Variant::INT && arg_type != Variant::FLOAT) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; - r_error.expected = Variant::FLOAT; r_error.argument = i; + r_error.expected = Variant::FLOAT; return Variant(); } if (i == 0) { @@ -613,8 +622,8 @@ Variant VariantUtilityFunctions::min(const Variant **p_args, int p_argcount, Cal Variant::evaluate(Variant::OP_GREATER, base, *p_args[i], ret, valid); if (!valid) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; - r_error.expected = base.get_type(); r_error.argument = i; + r_error.expected = base.get_type(); return Variant(); } if (ret.booleanize()) { @@ -642,8 +651,8 @@ Variant VariantUtilityFunctions::clamp(const Variant &x, const Variant &min, con Variant::evaluate(Variant::OP_LESS, value, min, ret, valid); if (!valid) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; - r_error.expected = value.get_type(); r_error.argument = 1; + r_error.expected = value.get_type(); return Variant(); } if (ret.booleanize()) { @@ -652,8 +661,8 @@ Variant VariantUtilityFunctions::clamp(const Variant &x, const Variant &min, con Variant::evaluate(Variant::OP_GREATER, value, max, ret, valid); if (!valid) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; - r_error.expected = value.get_type(); r_error.argument = 2; + r_error.expected = value.get_type(); return Variant(); } if (ret.booleanize()) { @@ -839,7 +848,7 @@ Variant VariantUtilityFunctions::type_convert(const Variant &p_variant, const Va String VariantUtilityFunctions::str(const Variant **p_args, int p_arg_count, Callable::CallError &r_error) { if (p_arg_count < 1) { r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; - r_error.argument = 1; + r_error.expected = 1; return String(); } String s; @@ -866,6 +875,11 @@ String VariantUtilityFunctions::error_string(Error error) { return String(error_names[error]); } +String VariantUtilityFunctions::type_string(Variant::Type p_type) { + ERR_FAIL_INDEX_V_MSG((int)p_type, (int)Variant::VARIANT_MAX, "<invalid type>", "Invalid type argument to type_string(), use the TYPE_* constants."); + return Variant::get_type_name(p_type); +} + void VariantUtilityFunctions::print(const Variant **p_args, int p_arg_count, Callable::CallError &r_error) { String s; for (int i = 0; i < p_arg_count; i++) { @@ -983,7 +997,7 @@ void VariantUtilityFunctions::printraw(const Variant **p_args, int p_arg_count, void VariantUtilityFunctions::push_error(const Variant **p_args, int p_arg_count, Callable::CallError &r_error) { if (p_arg_count < 1) { r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; - r_error.argument = 1; + r_error.expected = 1; } String s; for (int i = 0; i < p_arg_count; i++) { @@ -1003,7 +1017,7 @@ void VariantUtilityFunctions::push_error(const Variant **p_args, int p_arg_count void VariantUtilityFunctions::push_warning(const Variant **p_args, int p_arg_count, Callable::CallError &r_error) { if (p_arg_count < 1) { r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; - r_error.argument = 1; + r_error.expected = 1; } String s; for (int i = 0; i < p_arg_count; i++) { @@ -1653,12 +1667,14 @@ void Variant::_register_variant_utility_functions() { FUNCBINDR(cubic_interpolate_angle_in_time, sarray("from", "to", "pre", "post", "weight", "to_t", "pre_t", "post_t"), Variant::UTILITY_FUNC_TYPE_MATH); FUNCBINDR(bezier_interpolate, sarray("start", "control_1", "control_2", "end", "t"), Variant::UTILITY_FUNC_TYPE_MATH); FUNCBINDR(bezier_derivative, sarray("start", "control_1", "control_2", "end", "t"), Variant::UTILITY_FUNC_TYPE_MATH); + FUNCBINDR(angle_difference, sarray("from", "to"), Variant::UTILITY_FUNC_TYPE_MATH); FUNCBINDR(lerp_angle, sarray("from", "to", "weight"), Variant::UTILITY_FUNC_TYPE_MATH); FUNCBINDR(inverse_lerp, sarray("from", "to", "weight"), Variant::UTILITY_FUNC_TYPE_MATH); FUNCBINDR(remap, sarray("value", "istart", "istop", "ostart", "ostop"), Variant::UTILITY_FUNC_TYPE_MATH); FUNCBINDR(smoothstep, sarray("from", "to", "x"), Variant::UTILITY_FUNC_TYPE_MATH); FUNCBINDR(move_toward, sarray("from", "to", "delta"), Variant::UTILITY_FUNC_TYPE_MATH); + FUNCBINDR(rotate_toward, sarray("from", "to", "delta"), Variant::UTILITY_FUNC_TYPE_MATH); FUNCBINDR(deg_to_rad, sarray("deg"), Variant::UTILITY_FUNC_TYPE_MATH); FUNCBINDR(rad_to_deg, sarray("rad"), Variant::UTILITY_FUNC_TYPE_MATH); @@ -1702,6 +1718,7 @@ void Variant::_register_variant_utility_functions() { FUNCBINDR(type_convert, sarray("variant", "type"), Variant::UTILITY_FUNC_TYPE_GENERAL); FUNCBINDVARARGS(str, sarray(), Variant::UTILITY_FUNC_TYPE_GENERAL); FUNCBINDR(error_string, sarray("error"), Variant::UTILITY_FUNC_TYPE_GENERAL); + FUNCBINDR(type_string, sarray("type"), Variant::UTILITY_FUNC_TYPE_GENERAL); FUNCBINDVARARGV(print, sarray(), Variant::UTILITY_FUNC_TYPE_GENERAL); FUNCBINDVARARGV(print_rich, sarray(), Variant::UTILITY_FUNC_TYPE_GENERAL); FUNCBINDVARARGV(printerr, sarray(), Variant::UTILITY_FUNC_TYPE_GENERAL); @@ -1749,14 +1766,12 @@ void Variant::call_utility_function(const StringName &p_name, Variant *r_ret, co if (unlikely(!bfi->is_vararg && p_argcount < bfi->argcount)) { r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; - r_error.argument = 0; r_error.expected = bfi->argcount; return; } if (unlikely(!bfi->is_vararg && p_argcount > bfi->argcount)) { r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS; - r_error.argument = 0; r_error.expected = bfi->argcount; return; } diff --git a/core/variant/variant_utility.h b/core/variant/variant_utility.h index 66883fb140..a56c84a8e9 100644 --- a/core/variant/variant_utility.h +++ b/core/variant/variant_utility.h @@ -90,11 +90,13 @@ struct VariantUtilityFunctions { double to_t, double pre_t, double post_t); static double bezier_interpolate(double p_start, double p_control_1, double p_control_2, double p_end, double p_t); static double bezier_derivative(double p_start, double p_control_1, double p_control_2, double p_end, double p_t); + static double angle_difference(double from, double to); static double lerp_angle(double from, double to, double weight); static double inverse_lerp(double from, double to, double weight); static double remap(double value, double istart, double istop, double ostart, double ostop); static double smoothstep(double from, double to, double val); static double move_toward(double from, double to, double delta); + static double rotate_toward(double from, double to, double delta); static double deg_to_rad(double angle_deg); static double rad_to_deg(double angle_rad); static double linear_to_db(double linear); @@ -128,6 +130,7 @@ struct VariantUtilityFunctions { static Variant type_convert(const Variant &p_variant, const Variant::Type p_type); static String str(const Variant **p_args, int p_arg_count, Callable::CallError &r_error); static String error_string(Error error); + static String type_string(Variant::Type p_type); static void print(const Variant **p_args, int p_arg_count, Callable::CallError &r_error); static void print_rich(const Variant **p_args, int p_arg_count, Callable::CallError &r_error); #undef print_verbose |