diff options
Diffstat (limited to 'core')
64 files changed, 878 insertions, 627 deletions
diff --git a/core/config/project_settings.cpp b/core/config/project_settings.cpp index 4d19a93991..001a351e0b 100644 --- a/core/config/project_settings.cpp +++ b/core/config/project_settings.cpp @@ -785,7 +785,7 @@ Error ProjectSettings::save() { return error; } -Error ProjectSettings::_save_settings_binary(const String &p_file, const RBMap<String, List<String>> &props, const CustomMap &p_custom, const String &p_custom_features) { +Error ProjectSettings::_save_settings_binary(const String &p_file, const RBMap<String, List<String>> &p_props, const CustomMap &p_custom, const String &p_custom_features) { Error err; Ref<FileAccess> file = FileAccess::open(p_file, FileAccess::WRITE, &err); ERR_FAIL_COND_V_MSG(err != OK, err, "Couldn't save project.binary at " + p_file + "."); @@ -795,7 +795,7 @@ Error ProjectSettings::_save_settings_binary(const String &p_file, const RBMap<S int count = 0; - for (const KeyValue<String, List<String>> &E : props) { + for (const KeyValue<String, List<String>> &E : p_props) { count += E.value.size(); } @@ -821,7 +821,7 @@ Error ProjectSettings::_save_settings_binary(const String &p_file, const RBMap<S file->store_32(count); //store how many properties are saved } - for (const KeyValue<String, List<String>> &E : props) { + for (const KeyValue<String, List<String>> &E : p_props) { for (const String &key : E.value) { String k = key; if (!E.key.is_empty()) { @@ -853,7 +853,7 @@ Error ProjectSettings::_save_settings_binary(const String &p_file, const RBMap<S return OK; } -Error ProjectSettings::_save_settings_text(const String &p_file, const RBMap<String, List<String>> &props, const CustomMap &p_custom, const String &p_custom_features) { +Error ProjectSettings::_save_settings_text(const String &p_file, const RBMap<String, List<String>> &p_props, const CustomMap &p_custom, const String &p_custom_features) { Error err; Ref<FileAccess> file = FileAccess::open(p_file, FileAccess::WRITE, &err); @@ -874,8 +874,8 @@ Error ProjectSettings::_save_settings_text(const String &p_file, const RBMap<Str } file->store_string("\n"); - for (const KeyValue<String, List<String>> &E : props) { - if (E.key != props.begin()->key) { + for (const KeyValue<String, List<String>> &E : p_props) { + if (E.key != p_props.begin()->key) { file->store_string("\n"); } @@ -980,7 +980,7 @@ Error ProjectSettings::save_custom(const String &p_path, const CustomMap &p_cust vclist.insert(vc); } - RBMap<String, List<String>> props; + RBMap<String, List<String>> save_props; for (const _VCSort &E : vclist) { String category = E.name; @@ -994,24 +994,24 @@ Error ProjectSettings::save_custom(const String &p_path, const CustomMap &p_cust category = category.substr(0, div); name = name.substr(div + 1, name.size()); } - props[category].push_back(name); + save_props[category].push_back(name); } - String custom_features; + String save_features; for (int i = 0; i < p_custom_features.size(); i++) { if (i > 0) { - custom_features += ","; + save_features += ","; } String f = p_custom_features[i].strip_edges().replace("\"", ""); - custom_features += f; + save_features += f; } if (p_path.ends_with(".godot") || p_path.ends_with("override.cfg")) { - return _save_settings_text(p_path, props, p_custom, custom_features); + return _save_settings_text(p_path, save_props, p_custom, save_features); } else if (p_path.ends_with(".binary")) { - return _save_settings_binary(p_path, props, p_custom, custom_features); + return _save_settings_binary(p_path, save_props, p_custom, save_features); } else { ERR_FAIL_V_MSG(ERR_FILE_UNRECOGNIZED, "Unknown config file format: " + p_path + "."); } diff --git a/core/doc_data.h b/core/doc_data.h index bb356f027e..d5fbe37c96 100644 --- a/core/doc_data.h +++ b/core/doc_data.h @@ -57,6 +57,27 @@ public: } return name < p_arg.name; } + static ArgumentDoc from_dict(const Dictionary &p_dict) { + ArgumentDoc doc; + + if (p_dict.has("name")) { + doc.name = p_dict["name"]; + } + + if (p_dict.has("type")) { + doc.type = p_dict["type"]; + } + + if (p_dict.has("enumeration")) { + doc.enumeration = p_dict["enumeration"]; + } + + if (p_dict.has("default_value")) { + doc.default_value = p_dict["default_value"]; + } + + return doc; + } }; struct MethodDoc { @@ -97,6 +118,55 @@ public: } return name < p_method.name; } + static MethodDoc from_dict(const Dictionary &p_dict) { + MethodDoc doc; + + if (p_dict.has("name")) { + doc.name = p_dict["name"]; + } + + if (p_dict.has("return_type")) { + doc.return_type = p_dict["return_type"]; + } + + if (p_dict.has("return_enum")) { + doc.return_enum = p_dict["return_enum"]; + } + + if (p_dict.has("qualifiers")) { + doc.qualifiers = p_dict["qualifiers"]; + } + + if (p_dict.has("description")) { + doc.description = p_dict["description"]; + } + + if (p_dict.has("is_deprecated")) { + doc.is_deprecated = p_dict["is_deprecated"]; + } + + if (p_dict.has("is_experimental")) { + doc.is_experimental = p_dict["is_experimental"]; + } + + Array arguments; + if (p_dict.has("arguments")) { + arguments = p_dict["arguments"]; + } + for (int i = 0; i < arguments.size(); i++) { + doc.arguments.push_back(ArgumentDoc::from_dict(arguments[i])); + } + + Array errors_returned; + if (p_dict.has("errors_returned")) { + errors_returned = p_dict["errors_returned"]; + } + for (int i = 0; i < errors_returned.size(); i++) { + doc.errors_returned.push_back(errors_returned[i]); + } + + return doc; + } }; struct ConstantDoc { @@ -111,6 +181,43 @@ public: bool operator<(const ConstantDoc &p_const) const { return name < p_const.name; } + static ConstantDoc from_dict(const Dictionary &p_dict) { + ConstantDoc doc; + + if (p_dict.has("name")) { + doc.name = p_dict["name"]; + } + + if (p_dict.has("value")) { + doc.value = p_dict["value"]; + } + + if (p_dict.has("is_value_valid")) { + doc.is_value_valid = p_dict["is_value_valid"]; + } + + if (p_dict.has("enumeration")) { + doc.enumeration = p_dict["enumeration"]; + } + + if (p_dict.has("is_bitfield")) { + doc.is_bitfield = p_dict["is_bitfield"]; + } + + if (p_dict.has("description")) { + doc.description = p_dict["description"]; + } + + if (p_dict.has("is_deprecated")) { + doc.is_deprecated = p_dict["is_deprecated"]; + } + + if (p_dict.has("is_experimental")) { + doc.is_experimental = p_dict["is_experimental"]; + } + + return doc; + } }; struct EnumDoc { @@ -118,6 +225,31 @@ public: bool is_bitfield = false; String description; Vector<DocData::ConstantDoc> values; + static EnumDoc from_dict(const Dictionary &p_dict) { + EnumDoc doc; + + if (p_dict.has("name")) { + doc.name = p_dict["name"]; + } + + if (p_dict.has("is_bitfield")) { + doc.is_bitfield = p_dict["is_bitfield"]; + } + + if (p_dict.has("description")) { + doc.description = p_dict["description"]; + } + + Array values; + if (p_dict.has("values")) { + values = p_dict["values"]; + } + for (int i = 0; i < values.size(); i++) { + doc.values.push_back(ConstantDoc::from_dict(values[i])); + } + + return doc; + } }; struct PropertyDoc { @@ -134,6 +266,55 @@ public: bool operator<(const PropertyDoc &p_prop) const { return name < p_prop.name; } + static PropertyDoc from_dict(const Dictionary &p_dict) { + PropertyDoc doc; + + if (p_dict.has("name")) { + doc.name = p_dict["name"]; + } + + if (p_dict.has("type")) { + doc.type = p_dict["type"]; + } + + if (p_dict.has("enumeration")) { + doc.enumeration = p_dict["enumeration"]; + } + + if (p_dict.has("description")) { + doc.description = p_dict["description"]; + } + + if (p_dict.has("setter")) { + doc.setter = p_dict["setter"]; + } + + if (p_dict.has("getter")) { + doc.getter = p_dict["getter"]; + } + + if (p_dict.has("default_value")) { + doc.default_value = p_dict["default_value"]; + } + + if (p_dict.has("overridden")) { + doc.overridden = p_dict["overridden"]; + } + + if (p_dict.has("overrides")) { + doc.overrides = p_dict["overrides"]; + } + + if (p_dict.has("is_deprecated")) { + doc.is_deprecated = p_dict["is_deprecated"]; + } + + if (p_dict.has("is_experimental")) { + doc.is_experimental = p_dict["is_experimental"]; + } + + return doc; + } }; struct ThemeItemDoc { @@ -149,11 +330,49 @@ public: } return data_type < p_theme_item.data_type; } + static ThemeItemDoc from_dict(const Dictionary &p_dict) { + ThemeItemDoc doc; + + if (p_dict.has("name")) { + doc.name = p_dict["name"]; + } + + if (p_dict.has("type")) { + doc.type = p_dict["type"]; + } + + if (p_dict.has("data_type")) { + doc.data_type = p_dict["data_type"]; + } + + if (p_dict.has("description")) { + doc.description = p_dict["description"]; + } + + if (p_dict.has("default_value")) { + doc.default_value = p_dict["default_value"]; + } + + return doc; + } }; struct TutorialDoc { String link; String title; + static TutorialDoc from_dict(const Dictionary &p_dict) { + TutorialDoc doc; + + if (p_dict.has("link")) { + doc.link = p_dict["link"]; + } + + if (p_dict.has("title")) { + doc.title = p_dict["title"]; + } + + return doc; + } }; struct ClassDoc { @@ -179,6 +398,127 @@ public: bool operator<(const ClassDoc &p_class) const { return name < p_class.name; } + static ClassDoc from_dict(const Dictionary &p_dict) { + ClassDoc doc; + + if (p_dict.has("name")) { + doc.name = p_dict["name"]; + } + + if (p_dict.has("inherits")) { + doc.inherits = p_dict["inherits"]; + } + + if (p_dict.has("category")) { + doc.category = p_dict["category"]; + } + + if (p_dict.has("brief_description")) { + doc.brief_description = p_dict["brief_description"]; + } + + if (p_dict.has("description")) { + doc.description = p_dict["description"]; + } + + Array tutorials; + if (p_dict.has("tutorials")) { + tutorials = p_dict["tutorials"]; + } + for (int i = 0; i < tutorials.size(); i++) { + doc.tutorials.push_back(TutorialDoc::from_dict(tutorials[i])); + } + + Array constructors; + if (p_dict.has("constructors")) { + constructors = p_dict["constructors"]; + } + for (int i = 0; i < constructors.size(); i++) { + doc.constructors.push_back(MethodDoc::from_dict(constructors[i])); + } + + Array methods; + if (p_dict.has("methods")) { + methods = p_dict["methods"]; + } + for (int i = 0; i < methods.size(); i++) { + doc.methods.push_back(MethodDoc::from_dict(methods[i])); + } + + Array operators; + if (p_dict.has("operators")) { + operators = p_dict["operators"]; + } + for (int i = 0; i < operators.size(); i++) { + doc.operators.push_back(MethodDoc::from_dict(operators[i])); + } + + Array signals; + if (p_dict.has("signals")) { + signals = p_dict["signals"]; + } + for (int i = 0; i < signals.size(); i++) { + doc.signals.push_back(MethodDoc::from_dict(signals[i])); + } + + Array constants; + if (p_dict.has("constants")) { + constants = p_dict["constants"]; + } + for (int i = 0; i < constants.size(); i++) { + doc.constants.push_back(ConstantDoc::from_dict(constants[i])); + } + + Dictionary enums; + if (p_dict.has("enums")) { + enums = p_dict["enums"]; + } + for (int i = 0; i < enums.size(); i++) { + doc.enums[enums.get_key_at_index(i)] = enums.get_value_at_index(i); + } + + Array properties; + if (p_dict.has("properties")) { + properties = p_dict["properties"]; + } + for (int i = 0; i < properties.size(); i++) { + doc.properties.push_back(PropertyDoc::from_dict(properties[i])); + } + + Array annotations; + if (p_dict.has("annotations")) { + annotations = p_dict["annotations"]; + } + for (int i = 0; i < annotations.size(); i++) { + doc.annotations.push_back(MethodDoc::from_dict(annotations[i])); + } + + Array theme_properties; + if (p_dict.has("theme_properties")) { + theme_properties = p_dict["theme_properties"]; + } + for (int i = 0; i < theme_properties.size(); i++) { + doc.theme_properties.push_back(ThemeItemDoc::from_dict(theme_properties[i])); + } + + if (p_dict.has("is_deprecated")) { + doc.is_deprecated = p_dict["is_deprecated"]; + } + + if (p_dict.has("is_experimental")) { + doc.is_experimental = p_dict["is_experimental"]; + } + + if (p_dict.has("is_script_doc")) { + doc.is_script_doc = p_dict["is_script_doc"]; + } + + if (p_dict.has("script_path")) { + doc.script_path = p_dict["script_path"]; + } + + return doc; + } }; static void return_doc_from_retinfo(DocData::MethodDoc &p_method, const PropertyInfo &p_retinfo); diff --git a/core/extension/extension_api_dump.cpp b/core/extension/extension_api_dump.cpp index e6e0fff266..96b396caa9 100644 --- a/core/extension/extension_api_dump.cpp +++ b/core/extension/extension_api_dump.cpp @@ -38,7 +38,15 @@ #ifdef TOOLS_ENABLED -static String get_type_name(const PropertyInfo &p_info) { +static String get_builtin_or_variant_type_name(const Variant::Type p_type) { + if (p_type == Variant::NIL) { + return "Variant"; + } else { + return Variant::get_type_name(p_type); + } +} + +static String get_property_info_type_name(const PropertyInfo &p_info) { if (p_info.type == Variant::INT && (p_info.hint == PROPERTY_HINT_INT_IS_POINTER)) { if (p_info.hint_string.is_empty()) { return "void*"; @@ -70,7 +78,7 @@ static String get_type_name(const PropertyInfo &p_info) { if (p_info.type == Variant::NIL) { return "void"; } - return Variant::get_type_name(p_info.type); + return get_builtin_or_variant_type_name(p_info.type); } Dictionary NativeExtensionAPIDump::generate_extension_api() { @@ -430,8 +438,7 @@ Dictionary NativeExtensionAPIDump::generate_extension_api() { Dictionary arg; String argname = vararg ? "arg" + itos(i + 1) : Variant::get_utility_function_argument_name(name, i); arg["name"] = argname; - Variant::Type argtype = Variant::get_utility_function_argument_type(name, i); - arg["type"] = argtype == Variant::NIL ? String("Variant") : Variant::get_type_name(argtype); + arg["type"] = get_builtin_or_variant_type_name(Variant::get_utility_function_argument_type(name, i)); //no default value support in utility functions arguments.push_back(arg); } @@ -461,8 +468,7 @@ Dictionary NativeExtensionAPIDump::generate_extension_api() { Dictionary d; d["name"] = Variant::get_type_name(type); if (Variant::has_indexing(type)) { - Variant::Type index_type = Variant::get_indexed_element_type(type); - d["indexing_return_type"] = index_type == Variant::NIL ? String("Variant") : Variant::get_type_name(index_type); + d["indexing_return_type"] = get_builtin_or_variant_type_name(Variant::get_indexed_element_type(type)); } d["is_keyed"] = Variant::is_keyed(type); @@ -476,7 +482,7 @@ Dictionary NativeExtensionAPIDump::generate_extension_api() { for (const StringName &member_name : member_names) { Dictionary d2; d2["name"] = String(member_name); - d2["type"] = Variant::get_type_name(Variant::get_member_type(type, member_name)); + d2["type"] = get_builtin_or_variant_type_name(Variant::get_member_type(type, member_name)); members.push_back(d2); } if (members.size()) { @@ -493,7 +499,7 @@ Dictionary NativeExtensionAPIDump::generate_extension_api() { Dictionary d2; d2["name"] = String(constant_name); Variant constant = Variant::get_constant_value(type, constant_name); - d2["type"] = Variant::get_type_name(constant.get_type()); + d2["type"] = get_builtin_or_variant_type_name(constant.get_type()); d2["value"] = constant.get_construct_string(); constants.push_back(d2); } @@ -544,9 +550,9 @@ Dictionary NativeExtensionAPIDump::generate_extension_api() { Dictionary d2; d2["name"] = Variant::get_operator_name(Variant::Operator(k)); if (k != Variant::OP_NEGATE && k != Variant::OP_POSITIVE && k != Variant::OP_NOT && k != Variant::OP_BIT_NEGATE) { - d2["right_type"] = Variant::get_type_name(Variant::Type(j)); + d2["right_type"] = get_builtin_or_variant_type_name(Variant::Type(j)); } - d2["return_type"] = Variant::get_type_name(Variant::get_operator_return_type(Variant::Operator(k), type, Variant::Type(j))); + d2["return_type"] = get_builtin_or_variant_type_name(Variant::get_operator_return_type(Variant::Operator(k), type, Variant::Type(j))); operators.push_back(d2); } } @@ -580,8 +586,7 @@ Dictionary NativeExtensionAPIDump::generate_extension_api() { for (int j = 0; j < argcount; j++) { Dictionary d3; d3["name"] = Variant::get_builtin_method_argument_name(type, method_name, j); - Variant::Type argtype = Variant::get_builtin_method_argument_type(type, method_name, j); - d3["type"] = argtype == Variant::NIL ? String("Variant") : Variant::get_type_name(argtype); + d3["type"] = get_builtin_or_variant_type_name(Variant::get_builtin_method_argument_type(type, method_name, j)); if (j >= (argcount - default_args.size())) { int dargidx = j - (argcount - default_args.size()); @@ -613,7 +618,7 @@ Dictionary NativeExtensionAPIDump::generate_extension_api() { for (int k = 0; k < argcount; k++) { Dictionary d3; d3["name"] = Variant::get_constructor_argument_name(type, j, k); - d3["type"] = Variant::get_type_name(Variant::get_constructor_argument_type(type, j, k)); + d3["type"] = get_builtin_or_variant_type_name(Variant::get_constructor_argument_type(type, j, k)); arguments.push_back(d3); } if (arguments.size()) { @@ -741,7 +746,7 @@ Dictionary NativeExtensionAPIDump::generate_extension_api() { d3["name"] = pinfo.name; } - d3["type"] = get_type_name(pinfo); + d3["type"] = get_property_info_type_name(pinfo); if (i == -1) { d2["return_value"] = d3; @@ -784,7 +789,7 @@ Dictionary NativeExtensionAPIDump::generate_extension_api() { if (i >= 0) { d3["name"] = pinfo.name; } - d3["type"] = get_type_name(pinfo); + d3["type"] = get_property_info_type_name(pinfo); if (method->get_argument_meta(i) > 0) { static const char *argmeta[11] = { "none", "int8", "int16", "int32", "int64", "uint8", "uint16", "uint32", "uint64", "float", "double" }; @@ -831,7 +836,7 @@ Dictionary NativeExtensionAPIDump::generate_extension_api() { for (int i = 0; i < F.arguments.size(); i++) { Dictionary d3; d3["name"] = F.arguments[i].name; - d3["type"] = get_type_name(F.arguments[i]); + d3["type"] = get_property_info_type_name(F.arguments[i]); arguments.push_back(d3); } if (arguments.size()) { @@ -863,7 +868,7 @@ Dictionary NativeExtensionAPIDump::generate_extension_api() { } StringName property_name = F.name; Dictionary d2; - d2["type"] = get_type_name(F); + d2["type"] = get_property_info_type_name(F); d2["name"] = String(property_name); d2["setter"] = ClassDB::get_property_setter(class_name, F.name); d2["getter"] = ClassDB::get_property_getter(class_name, F.name); diff --git a/core/extension/gdnative_interface.h b/core/extension/gdnative_interface.h index 39378d8261..9ac5cc9398 100644 --- a/core/extension/gdnative_interface.h +++ b/core/extension/gdnative_interface.h @@ -231,7 +231,6 @@ typedef void (*GDNativeExtensionClassUnreference)(GDExtensionClassInstancePtr p_ typedef void (*GDNativeExtensionClassCallVirtual)(GDExtensionClassInstancePtr p_instance, const GDNativeTypePtr *p_args, GDNativeTypePtr r_ret); typedef GDNativeObjectPtr (*GDNativeExtensionClassCreateInstance)(void *p_userdata); typedef void (*GDNativeExtensionClassFreeInstance)(void *p_userdata, GDExtensionClassInstancePtr p_instance); -typedef void (*GDNativeExtensionClassObjectInstance)(GDExtensionClassInstancePtr p_instance, GDNativeObjectPtr p_object_instance); typedef GDNativeExtensionClassCallVirtual (*GDNativeExtensionClassGetVirtual)(void *p_userdata, const char *p_name); typedef struct { diff --git a/core/input/input.cpp b/core/input/input.cpp index 1390a0a7fa..889c2a92fa 100644 --- a/core/input/input.cpp +++ b/core/input/input.cpp @@ -365,7 +365,6 @@ Vector2 Input::get_vector(const StringName &p_negative_x, const StringName &p_po // Inverse lerp length to map (p_deadzone, 1) to (0, 1). return vector * (Math::inverse_lerp(p_deadzone, 1.0f, length) / length); } - return vector; } float Input::get_joy_axis(int p_device, JoyAxis p_axis) const { diff --git a/core/input/input_event.cpp b/core/input/input_event.cpp index 712fc68c93..38037eaf72 100644 --- a/core/input/input_event.cpp +++ b/core/input/input_event.cpp @@ -449,11 +449,11 @@ bool InputEventKey::action_match(const Ref<InputEvent> &p_event, bool p_exact_ma match &= action_mask == key_mask; } if (match) { - bool pressed = key->is_pressed(); + bool key_pressed = key->is_pressed(); if (r_pressed != nullptr) { - *r_pressed = pressed; + *r_pressed = key_pressed; } - float strength = pressed ? 1.0f : 0.0f; + float strength = key_pressed ? 1.0f : 0.0f; if (r_strength != nullptr) { *r_strength = strength; } @@ -610,20 +610,20 @@ bool InputEventMouseButton::action_match(const Ref<InputEvent> &p_event, bool p_ } bool match = button_index == mb->button_index; - Key action_mask = get_modifiers_mask(); - Key button_mask = mb->get_modifiers_mask(); + Key action_modifiers_mask = get_modifiers_mask(); + Key button_modifiers_mask = mb->get_modifiers_mask(); if (mb->is_pressed()) { - match &= (action_mask & button_mask) == action_mask; + match &= (action_modifiers_mask & button_modifiers_mask) == action_modifiers_mask; } if (p_exact_match) { - match &= action_mask == button_mask; + match &= action_modifiers_mask == button_modifiers_mask; } if (match) { - bool pressed = mb->is_pressed(); + bool mb_pressed = mb->is_pressed(); if (r_pressed != nullptr) { - *r_pressed = pressed; + *r_pressed = mb_pressed; } - float strength = pressed ? 1.0f : 0.0f; + float strength = mb_pressed ? 1.0f : 0.0f; if (r_strength != nullptr) { *r_strength = strength; } @@ -808,9 +808,9 @@ String InputEventMouseMotion::as_text() const { } String InputEventMouseMotion::to_string() { - MouseButton button_mask = get_button_mask(); - String button_mask_string = itos((int64_t)button_mask); - switch (button_mask) { + MouseButton mouse_button_mask = get_button_mask(); + String button_mask_string = itos((int64_t)mouse_button_mask); + switch (mouse_button_mask) { case MouseButton::MASK_LEFT: button_mask_string += vformat(" (%s)", TTRGET(_mouse_button_descriptions[(size_t)MouseButton::LEFT - 1])); break; @@ -1045,11 +1045,11 @@ bool InputEventJoypadButton::action_match(const Ref<InputEvent> &p_event, bool p bool match = button_index == jb->button_index; if (match) { - bool pressed = jb->is_pressed(); + bool jb_pressed = jb->is_pressed(); if (r_pressed != nullptr) { - *r_pressed = pressed; + *r_pressed = jb_pressed; } - float strength = pressed ? 1.0f : 0.0f; + float strength = jb_pressed ? 1.0f : 0.0f; if (r_strength != nullptr) { *r_strength = strength; } @@ -1340,16 +1340,16 @@ bool InputEventAction::action_match(const Ref<InputEvent> &p_event, bool p_exact bool match = action == act->action; if (match) { - bool pressed = act->pressed; + bool act_pressed = act->pressed; if (r_pressed != nullptr) { - *r_pressed = pressed; + *r_pressed = act_pressed; } - float strength = pressed ? 1.0f : 0.0f; + float act_strength = act_pressed ? 1.0f : 0.0f; if (r_strength != nullptr) { - *r_strength = strength; + *r_strength = act_strength; } if (r_raw_strength != nullptr) { - *r_raw_strength = strength; + *r_raw_strength = act_strength; } } return match; diff --git a/core/io/file_access_encrypted.cpp b/core/io/file_access_encrypted.cpp index be502dacd9..e7b2a2dfee 100644 --- a/core/io/file_access_encrypted.cpp +++ b/core/io/file_access_encrypted.cpp @@ -102,13 +102,13 @@ Error FileAccessEncrypted::open_and_parse(Ref<FileAccess> p_base, const Vector<u Error FileAccessEncrypted::open_and_parse_password(Ref<FileAccess> p_base, const String &p_key, Mode p_mode) { String cs = p_key.md5_text(); ERR_FAIL_COND_V(cs.length() != 32, ERR_INVALID_PARAMETER); - Vector<uint8_t> key; - key.resize(32); + Vector<uint8_t> key_md5; + key_md5.resize(32); for (int i = 0; i < 32; i++) { - key.write[i] = cs[i]; + key_md5.write[i] = cs[i]; } - return open_and_parse(p_base, key, p_mode); + return open_and_parse(p_base, key_md5, p_mode); } Error FileAccessEncrypted::open_internal(const String &p_path, int p_mode_flags) { diff --git a/core/io/file_access_network.cpp b/core/io/file_access_network.cpp index 13730518bf..87f3f66597 100644 --- a/core/io/file_access_network.cpp +++ b/core/io/file_access_network.cpp @@ -137,12 +137,12 @@ void FileAccessNetworkClient::_thread_func() { int64_t offset = get_64(); int32_t len = get_32(); - Vector<uint8_t> block; - block.resize(len); - client->get_data(block.ptrw(), len); + Vector<uint8_t> resp_block; + resp_block.resize(len); + client->get_data(resp_block.ptrw(), len); if (fa) { //may have been queued - fa->_set_block(offset, block); + fa->_set_block(offset, resp_block); } } break; diff --git a/core/io/http_client_tcp.cpp b/core/io/http_client_tcp.cpp index 5c1d00a330..aff79320ca 100644 --- a/core/io/http_client_tcp.cpp +++ b/core/io/http_client_tcp.cpp @@ -358,38 +358,38 @@ Error HTTPClientTCP::poll() { } break; } } else if (tls) { - Ref<StreamPeerTLS> tls; + Ref<StreamPeerTLS> tls_conn; if (!handshaking) { // Connect the StreamPeerTLS and start handshaking. - tls = Ref<StreamPeerTLS>(StreamPeerTLS::create()); - tls->set_blocking_handshake_enabled(false); - Error err = tls->connect_to_stream(tcp_connection, tls_verify_host, conn_host); + tls_conn = Ref<StreamPeerTLS>(StreamPeerTLS::create()); + tls_conn->set_blocking_handshake_enabled(false); + Error err = tls_conn->connect_to_stream(tcp_connection, tls_verify_host, conn_host); if (err != OK) { close(); status = STATUS_TLS_HANDSHAKE_ERROR; return ERR_CANT_CONNECT; } - connection = tls; + connection = tls_conn; handshaking = true; } else { // We are already handshaking, which means we can use your already active TLS connection. - tls = static_cast<Ref<StreamPeerTLS>>(connection); - if (tls.is_null()) { + tls_conn = static_cast<Ref<StreamPeerTLS>>(connection); + if (tls_conn.is_null()) { close(); status = STATUS_TLS_HANDSHAKE_ERROR; return ERR_CANT_CONNECT; } - tls->poll(); // Try to finish the handshake. + tls_conn->poll(); // Try to finish the handshake. } - if (tls->get_status() == StreamPeerTLS::STATUS_CONNECTED) { + if (tls_conn->get_status() == StreamPeerTLS::STATUS_CONNECTED) { // Handshake has been successful. handshaking = false; ip_candidates.clear(); status = STATUS_CONNECTED; return OK; - } else if (tls->get_status() != StreamPeerTLS::STATUS_HANDSHAKING) { + } else if (tls_conn->get_status() != StreamPeerTLS::STATUS_HANDSHAKING) { // Handshake has failed. close(); status = STATUS_TLS_HANDSHAKE_ERROR; diff --git a/core/io/image.cpp b/core/io/image.cpp index 56c05bf042..4be624a5a8 100644 --- a/core/io/image.cpp +++ b/core/io/image.cpp @@ -3869,15 +3869,15 @@ Dictionary Image::compute_image_metrics(const Ref<Image> p_compared_image, bool double image_metric_max, image_metric_mean, image_metric_mean_squared, image_metric_root_mean_squared, image_metric_peak_snr = 0.0; const bool average_component_error = true; - const uint32_t width = MIN(compared_image->get_width(), source_image->get_width()); - const uint32_t height = MIN(compared_image->get_height(), source_image->get_height()); + const uint32_t w = MIN(compared_image->get_width(), source_image->get_width()); + const uint32_t h = MIN(compared_image->get_height(), source_image->get_height()); // Histogram approach originally due to Charles Bloom. double hist[256]; memset(hist, 0, sizeof(hist)); - for (uint32_t y = 0; y < height; y++) { - for (uint32_t x = 0; x < width; x++) { + for (uint32_t y = 0; y < h; y++) { + for (uint32_t x = 0; x < w; x++) { const Color color_a = compared_image->get_pixel(x, y); const Color color_b = source_image->get_pixel(x, y); @@ -3922,7 +3922,7 @@ Dictionary Image::compute_image_metrics(const Ref<Image> p_compared_image, bool } // See http://richg42.blogspot.com/2016/09/how-to-compute-psnr-from-old-berkeley.html - double total_values = width * height; + double total_values = w * h; if (average_component_error) { total_values *= 4; diff --git a/core/io/image_loader.cpp b/core/io/image_loader.cpp index d6854666c0..397984a2ab 100644 --- a/core/io/image_loader.cpp +++ b/core/io/image_loader.cpp @@ -51,7 +51,7 @@ bool ImageFormatLoader::recognize(const String &p_extension) const { } Error ImageFormatLoaderExtension::load_image(Ref<Image> p_image, Ref<FileAccess> p_fileaccess, BitField<ImageFormatLoader::LoaderFlags> p_flags, float p_scale) { - Error err; + Error err = ERR_UNAVAILABLE; if (GDVIRTUAL_CALL(_load_image, p_image, p_fileaccess, p_flags, p_scale, err)) { return err; } diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index 9ab45f85b8..4611528db7 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -169,10 +169,10 @@ StringName ResourceLoaderBinary::_get_string() { } Error ResourceLoaderBinary::parse_variant(Variant &r_v) { - uint32_t type = f->get_32(); - print_bl("find property of type: " + itos(type)); + uint32_t prop_type = f->get_32(); + print_bl("find property of type: " + itos(prop_type)); - switch (type) { + switch (prop_type) { case VARIANT_NIL: { r_v = Variant(); } break; @@ -1042,7 +1042,14 @@ void ResourceLoaderBinary::open(Ref<FileAccess> p_f, bool p_no_resources, bool p // If a UID is found and the path is valid, it will be used, otherwise, it falls back to the path. er.path = ResourceUID::get_singleton()->get_id_path(er.uid); } else { +#ifdef TOOLS_ENABLED + // Silence a warning that can happen during the initial filesystem scan due to cache being regenerated. + if (ResourceLoader::get_resource_uid(res_path) != er.uid) { + WARN_PRINT(String(res_path + ": In external resource #" + itos(i) + ", invalid UUID: " + ResourceUID::get_singleton()->id_to_text(er.uid) + " - using text path instead: " + er.path).utf8().get_data()); + } +#else WARN_PRINT(String(res_path + ": In external resource #" + itos(i) + ", invalid UUID: " + ResourceUID::get_singleton()->id_to_text(er.uid) + " - using text path instead: " + er.path).utf8().get_data()); +#endif } } } @@ -1100,16 +1107,14 @@ String ResourceLoaderBinary::recognize(Ref<FileAccess> p_f) { uint32_t ver_major = f->get_32(); f->get_32(); // ver_minor - uint32_t ver_format = f->get_32(); + uint32_t ver_fmt = f->get_32(); - if (ver_format > FORMAT_VERSION || ver_major > VERSION_MAJOR) { + if (ver_fmt > FORMAT_VERSION || ver_major > VERSION_MAJOR) { f.unref(); return ""; } - String type = get_unicode_string(); - - return type; + return get_unicode_string(); } Ref<Resource> ResourceFormatLoaderBinary::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) { @@ -2118,9 +2123,9 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const Ref<Re for (int i = 0; i < save_order.size(); i++) { save_unicode_string(f, save_order[i]->get_save_class()); - String path = save_order[i]->get_path(); - path = relative_paths ? local_path.path_to_file(path) : path; - save_unicode_string(f, path); + String res_path = save_order[i]->get_path(); + res_path = relative_paths ? local_path.path_to_file(res_path) : res_path; + save_unicode_string(f, res_path); ResourceUID::ID ruid = ResourceSaver::get_resource_id_for_path(save_order[i]->get_path(), false); f->store_64(ruid); } diff --git a/core/io/resource_importer.cpp b/core/io/resource_importer.cpp index d923522317..564b37e662 100644 --- a/core/io/resource_importer.cpp +++ b/core/io/resource_importer.cpp @@ -110,8 +110,8 @@ Error ResourceFormatImporter::_get_path_and_type(const String &p_path, PathAndTy #ifdef TOOLS_ENABLED if (r_path_and_type.metadata && !r_path_and_type.path.is_empty()) { - Dictionary metadata = r_path_and_type.metadata; - if (metadata.has("has_editor_variant")) { + Dictionary meta = r_path_and_type.metadata; + if (meta.has("has_editor_variant")) { r_path_and_type.path = r_path_and_type.path.get_basename() + ".editor." + r_path_and_type.path.get_extension(); } } diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp index eccb397e2e..a018221b7f 100644 --- a/core/io/resource_loader.cpp +++ b/core/io/resource_loader.cpp @@ -68,7 +68,7 @@ bool ResourceFormatLoader::recognize_path(const String &p_path, const String &p_ } bool ResourceFormatLoader::handles_type(const String &p_type) const { - bool success; + bool success = false; if (GDVIRTUAL_CALL(_handles_type, p_type, success)) { return success; } @@ -102,7 +102,7 @@ String ResourceFormatLoader::get_resource_type(const String &p_path) const { } ResourceUID::ID ResourceFormatLoader::get_resource_uid(const String &p_path) const { - int64_t uid; + int64_t uid = ResourceUID::INVALID_ID; if (GDVIRTUAL_CALL(_get_resource_uid, p_path, uid)) { return uid; } @@ -123,7 +123,7 @@ void ResourceLoader::get_recognized_extensions_for_type(const String &p_type, Li } bool ResourceFormatLoader::exists(const String &p_path) const { - bool success; + bool success = false; if (GDVIRTUAL_CALL(_exists, p_path, success)) { return success; } @@ -175,7 +175,7 @@ Error ResourceFormatLoader::rename_dependencies(const String &p_path, const Hash deps_dict[E.key] = E.value; } - int64_t err; + int64_t err = OK; if (GDVIRTUAL_CALL(_rename_dependencies, p_path, deps_dict, err)) { return (Error)err; } diff --git a/core/io/resource_saver.cpp b/core/io/resource_saver.cpp index 386ccb78e9..2f863baaac 100644 --- a/core/io/resource_saver.cpp +++ b/core/io/resource_saver.cpp @@ -42,7 +42,7 @@ ResourceSavedCallback ResourceSaver::save_callback = nullptr; ResourceSaverGetResourceIDForPath ResourceSaver::save_get_id_for_path = nullptr; Error ResourceFormatSaver::save(const Ref<Resource> &p_resource, const String &p_path, uint32_t p_flags) { - int64_t res; + int64_t res = ERR_METHOD_NOT_FOUND; if (GDVIRTUAL_CALL(_save, p_resource, p_path, p_flags, res)) { return (Error)res; } @@ -51,7 +51,7 @@ Error ResourceFormatSaver::save(const Ref<Resource> &p_resource, const String &p } bool ResourceFormatSaver::recognize(const Ref<Resource> &p_resource) const { - bool success; + bool success = false; if (GDVIRTUAL_CALL(_recognize, p_resource, success)) { return success; } diff --git a/core/io/stream_peer_tcp.cpp b/core/io/stream_peer_tcp.cpp index ba79590c19..e035e1b613 100644 --- a/core/io/stream_peer_tcp.cpp +++ b/core/io/stream_peer_tcp.cpp @@ -256,9 +256,9 @@ void StreamPeerTCP::disconnect_from_host() { peer_port = 0; } -Error StreamPeerTCP::wait(NetSocket::PollType p_type, int timeout) { +Error StreamPeerTCP::wait(NetSocket::PollType p_type, int p_timeout) { ERR_FAIL_COND_V(_sock.is_null() || !_sock->is_open(), ERR_UNAVAILABLE); - return _sock->poll(p_type, timeout); + return _sock->poll(p_type, p_timeout); } Error StreamPeerTCP::put_data(const uint8_t *p_data, int p_bytes) { diff --git a/core/io/stream_peer_tcp.h b/core/io/stream_peer_tcp.h index 39c2e84346..778fb83374 100644 --- a/core/io/stream_peer_tcp.h +++ b/core/io/stream_peer_tcp.h @@ -79,7 +79,7 @@ public: Error poll(); // Wait or check for writable, readable. - Error wait(NetSocket::PollType p_type, int timeout = 0); + Error wait(NetSocket::PollType p_type, int p_timeout = 0); // Read/Write from StreamPeer Error put_data(const uint8_t *p_data, int p_bytes) override; diff --git a/core/math/aabb.cpp b/core/math/aabb.cpp index 4c89be7f4d..fcf245d2ad 100644 --- a/core/math/aabb.cpp +++ b/core/math/aabb.cpp @@ -30,7 +30,7 @@ #include "aabb.h" -#include "core/string/print_string.h" +#include "core/string/ustring.h" #include "core/variant/variant.h" real_t AABB::get_volume() const { @@ -76,6 +76,10 @@ bool AABB::is_equal_approx(const AABB &p_aabb) const { return position.is_equal_approx(p_aabb.position) && size.is_equal_approx(p_aabb.size); } +bool AABB::is_finite() const { + return position.is_finite() && size.is_finite(); +} + AABB AABB::intersection(const AABB &p_aabb) const { #ifdef MATH_CHECKS if (unlikely(size.x < 0 || size.y < 0 || size.z < 0 || p_aabb.size.x < 0 || p_aabb.size.y < 0 || p_aabb.size.z < 0)) { @@ -403,6 +407,7 @@ Variant AABB::intersects_segment_bind(const Vector3 &p_from, const Vector3 &p_to } return Variant(); } + Variant AABB::intersects_ray_bind(const Vector3 &p_from, const Vector3 &p_dir) const { Vector3 inters; if (intersects_ray(p_from, p_dir, &inters)) { diff --git a/core/math/aabb.h b/core/math/aabb.h index acf903eeba..9d5837ad37 100644 --- a/core/math/aabb.h +++ b/core/math/aabb.h @@ -31,7 +31,6 @@ #ifndef AABB_H #define AABB_H -#include "core/math/math_defs.h" #include "core/math/plane.h" #include "core/math/vector3.h" @@ -64,6 +63,7 @@ struct _NO_DISCARD_ AABB { bool operator!=(const AABB &p_rval) const; bool is_equal_approx(const AABB &p_aabb) const; + bool is_finite() const; _FORCE_INLINE_ bool intersects(const AABB &p_aabb) const; /// Both AABBs overlap _FORCE_INLINE_ bool intersects_inclusive(const AABB &p_aabb) const; /// Both AABBs (or their faces) overlap _FORCE_INLINE_ bool encloses(const AABB &p_aabb) const; /// p_aabb is completely inside this @@ -101,7 +101,7 @@ struct _NO_DISCARD_ AABB { _FORCE_INLINE_ void expand_to(const Vector3 &p_vector); /** expand to contain a point if necessary */ _FORCE_INLINE_ AABB abs() const { - return AABB(Vector3(position.x + MIN(size.x, 0), position.y + MIN(size.y, 0), position.z + MIN(size.z, 0)), size.abs()); + return AABB(Vector3(position.x + MIN(size.x, (real_t)0), position.y + MIN(size.y, (real_t)0), position.z + MIN(size.z, (real_t)0)), size.abs()); } Variant intersects_segment_bind(const Vector3 &p_from, const Vector3 &p_to) const; diff --git a/core/math/basis.cpp b/core/math/basis.cpp index 4b163409ce..9b8188eed8 100644 --- a/core/math/basis.cpp +++ b/core/math/basis.cpp @@ -31,7 +31,7 @@ #include "basis.h" #include "core/math/math_funcs.h" -#include "core/string/print_string.h" +#include "core/string/ustring.h" #define cofac(row1, col1, row2, col2) \ (rows[row1][col1] * rows[row2][col2] - rows[row1][col2] * rows[row2][col1]) @@ -142,8 +142,8 @@ bool Basis::is_symmetric() const { #endif Basis Basis::diagonalize() { -//NOTE: only implemented for symmetric matrices -//with the Jacobi iterative method +// NOTE: only implemented for symmetric matrices +// with the Jacobi iterative method #ifdef MATH_CHECKS ERR_FAIL_COND_V(!is_symmetric(), Basis()); #endif @@ -691,6 +691,10 @@ bool Basis::is_equal_approx(const Basis &p_basis) const { return rows[0].is_equal_approx(p_basis.rows[0]) && rows[1].is_equal_approx(p_basis.rows[1]) && rows[2].is_equal_approx(p_basis.rows[2]); } +bool Basis::is_finite() const { + return rows[0].is_finite() && rows[1].is_finite() && rows[2].is_finite(); +} + bool Basis::operator==(const Basis &p_matrix) const { for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { diff --git a/core/math/basis.h b/core/math/basis.h index cc2924f5ff..69bef5a7be 100644 --- a/core/math/basis.h +++ b/core/math/basis.h @@ -134,6 +134,7 @@ struct _NO_DISCARD_ Basis { } bool is_equal_approx(const Basis &p_basis) const; + bool is_finite() const; bool operator==(const Basis &p_matrix) const; bool operator!=(const Basis &p_matrix) const; diff --git a/core/math/bvh_tree.h b/core/math/bvh_tree.h index 8291394b31..3836e92a83 100644 --- a/core/math/bvh_tree.h +++ b/core/math/bvh_tree.h @@ -43,7 +43,6 @@ #include "core/math/bvh_abb.h" #include "core/math/geometry_3d.h" #include "core/math/vector3.h" -#include "core/string/print_string.h" #include "core/templates/local_vector.h" #include "core/templates/pooled_list.h" #include <limits.h> diff --git a/core/math/color.cpp b/core/math/color.cpp index 4bdeafd2f2..f223853f6b 100644 --- a/core/math/color.cpp +++ b/core/math/color.cpp @@ -32,85 +32,85 @@ #include "color_names.inc" #include "core/math/math_funcs.h" -#include "core/string/print_string.h" +#include "core/string/ustring.h" #include "core/templates/rb_map.h" #include "thirdparty/misc/ok_color.h" uint32_t Color::to_argb32() const { - uint32_t c = (uint8_t)Math::round(a * 255); + uint32_t c = (uint8_t)Math::round(a * 255.0f); c <<= 8; - c |= (uint8_t)Math::round(r * 255); + c |= (uint8_t)Math::round(r * 255.0f); c <<= 8; - c |= (uint8_t)Math::round(g * 255); + c |= (uint8_t)Math::round(g * 255.0f); c <<= 8; - c |= (uint8_t)Math::round(b * 255); + c |= (uint8_t)Math::round(b * 255.0f); return c; } uint32_t Color::to_abgr32() const { - uint32_t c = (uint8_t)Math::round(a * 255); + uint32_t c = (uint8_t)Math::round(a * 255.0f); c <<= 8; - c |= (uint8_t)Math::round(b * 255); + c |= (uint8_t)Math::round(b * 255.0f); c <<= 8; - c |= (uint8_t)Math::round(g * 255); + c |= (uint8_t)Math::round(g * 255.0f); c <<= 8; - c |= (uint8_t)Math::round(r * 255); + c |= (uint8_t)Math::round(r * 255.0f); return c; } uint32_t Color::to_rgba32() const { - uint32_t c = (uint8_t)Math::round(r * 255); + uint32_t c = (uint8_t)Math::round(r * 255.0f); c <<= 8; - c |= (uint8_t)Math::round(g * 255); + c |= (uint8_t)Math::round(g * 255.0f); c <<= 8; - c |= (uint8_t)Math::round(b * 255); + c |= (uint8_t)Math::round(b * 255.0f); c <<= 8; - c |= (uint8_t)Math::round(a * 255); + c |= (uint8_t)Math::round(a * 255.0f); return c; } uint64_t Color::to_abgr64() const { - uint64_t c = (uint16_t)Math::round(a * 65535); + uint64_t c = (uint16_t)Math::round(a * 65535.0f); c <<= 16; - c |= (uint16_t)Math::round(b * 65535); + c |= (uint16_t)Math::round(b * 65535.0f); c <<= 16; - c |= (uint16_t)Math::round(g * 65535); + c |= (uint16_t)Math::round(g * 65535.0f); c <<= 16; - c |= (uint16_t)Math::round(r * 65535); + c |= (uint16_t)Math::round(r * 65535.0f); return c; } uint64_t Color::to_argb64() const { - uint64_t c = (uint16_t)Math::round(a * 65535); + uint64_t c = (uint16_t)Math::round(a * 65535.0f); c <<= 16; - c |= (uint16_t)Math::round(r * 65535); + c |= (uint16_t)Math::round(r * 65535.0f); c <<= 16; - c |= (uint16_t)Math::round(g * 65535); + c |= (uint16_t)Math::round(g * 65535.0f); c <<= 16; - c |= (uint16_t)Math::round(b * 65535); + c |= (uint16_t)Math::round(b * 65535.0f); return c; } uint64_t Color::to_rgba64() const { - uint64_t c = (uint16_t)Math::round(r * 65535); + uint64_t c = (uint16_t)Math::round(r * 65535.0f); c <<= 16; - c |= (uint16_t)Math::round(g * 65535); + c |= (uint16_t)Math::round(g * 65535.0f); c <<= 16; - c |= (uint16_t)Math::round(b * 65535); + c |= (uint16_t)Math::round(b * 65535.0f); c <<= 16; - c |= (uint16_t)Math::round(a * 65535); + c |= (uint16_t)Math::round(a * 65535.0f); return c; } String _to_hex(float p_val) { - int v = Math::round(p_val * 255); + int v = Math::round(p_val * 255.0f); v = CLAMP(v, 0, 255); String ret; @@ -150,8 +150,8 @@ float Color::get_h() const { float delta = max - min; - if (delta == 0) { - return 0; + if (delta == 0.0f) { + return 0.0f; } float h; @@ -164,7 +164,7 @@ float Color::get_h() const { } h /= 6.0f; - if (h < 0) { + if (h < 0.0f) { h += 1.0f; } @@ -179,7 +179,7 @@ float Color::get_s() const { float delta = max - min; - return (max != 0) ? (delta / max) : 0; + return (max != 0.0f) ? (delta / max) : 0.0f; } float Color::get_v() const { @@ -193,7 +193,7 @@ void Color::set_hsv(float p_h, float p_s, float p_v, float p_alpha) { float f, p, q, t; a = p_alpha; - if (p_s == 0) { + if (p_s == 0.0f) { // Achromatic (grey) r = g = b = p_v; return; @@ -204,9 +204,9 @@ void Color::set_hsv(float p_h, float p_s, float p_v, float p_alpha) { i = Math::floor(p_h); f = p_h - i; - p = p_v * (1 - p_s); - q = p_v * (1 - p_s * f); - t = p_v * (1 - p_s * (1 - f)); + p = p_v * (1.0f - p_s); + q = p_v * (1.0f - p_s * f); + t = p_v * (1.0f - p_s * (1.0f - f)); switch (i) { case 0: // Red is the dominant color @@ -347,7 +347,7 @@ Color Color::html(const String &p_rgba) { ERR_FAIL_V_MSG(Color(), "Invalid color code: " + p_rgba + "."); } - float r, g, b, a = 1.0; + float r, g, b, a = 1.0f; if (is_shorthand) { r = _parse_col4(color, 0) / 15.0f; g = _parse_col4(color, 1) / 15.0f; @@ -363,10 +363,10 @@ Color Color::html(const String &p_rgba) { a = _parse_col8(color, 6) / 255.0f; } } - ERR_FAIL_COND_V_MSG(r < 0, Color(), "Invalid color code: " + p_rgba + "."); - ERR_FAIL_COND_V_MSG(g < 0, Color(), "Invalid color code: " + p_rgba + "."); - ERR_FAIL_COND_V_MSG(b < 0, Color(), "Invalid color code: " + p_rgba + "."); - ERR_FAIL_COND_V_MSG(a < 0, Color(), "Invalid color code: " + p_rgba + "."); + ERR_FAIL_COND_V_MSG(r < 0.0f, Color(), "Invalid color code: " + p_rgba + "."); + ERR_FAIL_COND_V_MSG(g < 0.0f, Color(), "Invalid color code: " + p_rgba + "."); + ERR_FAIL_COND_V_MSG(b < 0.0f, Color(), "Invalid color code: " + p_rgba + "."); + ERR_FAIL_COND_V_MSG(a < 0.0f, Color(), "Invalid color code: " + p_rgba + "."); return Color(r, g, b, a); } @@ -474,7 +474,7 @@ Color Color::from_rgbe9995(uint32_t p_rgbe) { float g = (p_rgbe >> 9) & 0x1ff; float b = (p_rgbe >> 18) & 0x1ff; float e = (p_rgbe >> 27); - float m = Math::pow(2, e - 15.0f - 9.0f); + float m = Math::pow(2.0f, e - 15.0f - 9.0f); float rd = r * m; float gd = g * m; diff --git a/core/math/color.h b/core/math/color.h index 65036f74cc..a23a4953ce 100644 --- a/core/math/color.h +++ b/core/math/color.h @@ -32,7 +32,8 @@ #define COLOR_H #include "core/math/math_funcs.h" -#include "core/string/ustring.h" + +class String; struct _NO_DISCARD_ Color { union { @@ -55,11 +56,11 @@ struct _NO_DISCARD_ Color { float get_h() const; float get_s() const; float get_v() const; - void set_hsv(float p_h, float p_s, float p_v, float p_alpha = 1.0); + void set_hsv(float p_h, float p_s, float p_v, float p_alpha = 1.0f); float get_ok_hsl_h() const; float get_ok_hsl_s() const; float get_ok_hsl_l() const; - void set_ok_hsl(float p_h, float p_s, float p_l, float p_alpha = 1.0); + void set_ok_hsl(float p_h, float p_s, float p_l, float p_alpha = 1.0f); _FORCE_INLINE_ float &operator[](int p_idx) { return components[p_idx]; @@ -175,9 +176,9 @@ struct _NO_DISCARD_ Color { _FORCE_INLINE_ Color srgb_to_linear() const { return Color( - r < 0.04045f ? r * (1.0 / 12.92) : Math::pow((r + 0.055f) * (float)(1.0 / (1 + 0.055)), 2.4f), - g < 0.04045f ? g * (1.0 / 12.92) : Math::pow((g + 0.055f) * (float)(1.0 / (1 + 0.055)), 2.4f), - b < 0.04045f ? b * (1.0 / 12.92) : Math::pow((b + 0.055f) * (float)(1.0 / (1 + 0.055)), 2.4f), + r < 0.04045f ? r * (1.0f / 12.92f) : Math::pow((r + 0.055f) * (float)(1.0 / (1.0 + 0.055)), 2.4f), + g < 0.04045f ? g * (1.0f / 12.92f) : Math::pow((g + 0.055f) * (float)(1.0 / (1.0 + 0.055)), 2.4f), + b < 0.04045f ? b * (1.0f / 12.92f) : Math::pow((b + 0.055f) * (float)(1.0 / (1.0 + 0.055)), 2.4f), a); } _FORCE_INLINE_ Color linear_to_srgb() const { @@ -198,11 +199,11 @@ struct _NO_DISCARD_ Color { static String get_named_color_name(int p_idx); static Color get_named_color(int p_idx); static Color from_string(const String &p_string, const Color &p_default); - static Color from_hsv(float p_h, float p_s, float p_v, float p_alpha = 1.0); - static Color from_ok_hsl(float p_h, float p_s, float p_l, float p_alpha = 1.0); + static Color from_hsv(float p_h, float p_s, float p_v, float p_alpha = 1.0f); + static Color from_ok_hsl(float p_h, float p_s, float p_l, float p_alpha = 1.0f); static Color from_rgbe9995(uint32_t p_rgbe); - _FORCE_INLINE_ bool operator<(const Color &p_color) const; //used in set keys + _FORCE_INLINE_ bool operator<(const Color &p_color) const; // Used in set keys. operator String() const; // For the binder. diff --git a/core/math/delaunay_3d.h b/core/math/delaunay_3d.h index 13d93d7f67..3f8fe09445 100644 --- a/core/math/delaunay_3d.h +++ b/core/math/delaunay_3d.h @@ -35,7 +35,6 @@ #include "core/math/aabb.h" #include "core/math/projection.h" #include "core/math/vector3.h" -#include "core/string/print_string.h" #include "core/templates/local_vector.h" #include "core/templates/oa_hash_map.h" #include "core/templates/vector.h" diff --git a/core/math/expression.cpp b/core/math/expression.cpp index e230b69dc9..dcec3929fe 100644 --- a/core/math/expression.cpp +++ b/core/math/expression.cpp @@ -560,7 +560,7 @@ const char *Expression::token_name[TK_MAX] = { }; Expression::ENode *Expression::_parse_expression() { - Vector<ExpressionNode> expression; + Vector<ExpressionNode> expression_nodes; while (true) { //keep appending stuff to expression @@ -838,14 +838,14 @@ Expression::ENode *Expression::_parse_expression() { ExpressionNode e; e.is_op = true; e.op = Variant::OP_NEGATE; - expression.push_back(e); + expression_nodes.push_back(e); continue; } break; case TK_OP_NOT: { ExpressionNode e; e.is_op = true; e.op = Variant::OP_NOT; - expression.push_back(e); + expression_nodes.push_back(e); continue; } break; @@ -960,7 +960,7 @@ Expression::ENode *Expression::_parse_expression() { ExpressionNode e; e.is_op = false; e.node = expr; - expression.push_back(e); + expression_nodes.push_back(e); } //ok finally look for an operator @@ -1054,19 +1054,19 @@ Expression::ENode *Expression::_parse_expression() { ExpressionNode e; e.is_op = true; e.op = op; - expression.push_back(e); + expression_nodes.push_back(e); } } /* Reduce the set of expressions and place them in an operator tree, respecting precedence */ - while (expression.size() > 1) { + while (expression_nodes.size() > 1) { int next_op = -1; int min_priority = 0xFFFFF; bool is_unary = false; - for (int i = 0; i < expression.size(); i++) { - if (!expression[i].is_op) { + for (int i = 0; i < expression_nodes.size(); i++) { + if (!expression_nodes[i].is_op) { continue; } @@ -1074,7 +1074,7 @@ Expression::ENode *Expression::_parse_expression() { bool unary = false; - switch (expression[i].op) { + switch (expression_nodes[i].op) { case Variant::OP_POWER: priority = 0; break; @@ -1130,7 +1130,7 @@ Expression::ENode *Expression::_parse_expression() { priority = 14; break; default: { - _set_error("Parser bug, invalid operator in expression: " + itos(expression[i].op)); + _set_error("Parser bug, invalid operator in expression: " + itos(expression_nodes[i].op)); return nullptr; } } @@ -1153,9 +1153,9 @@ Expression::ENode *Expression::_parse_expression() { // OK! create operator.. if (is_unary) { int expr_pos = next_op; - while (expression[expr_pos].is_op) { + while (expression_nodes[expr_pos].is_op) { expr_pos++; - if (expr_pos == expression.size()) { + if (expr_pos == expression_nodes.size()) { //can happen.. _set_error("Unexpected end of expression..."); return nullptr; @@ -1165,29 +1165,29 @@ Expression::ENode *Expression::_parse_expression() { //consecutively do unary operators for (int i = expr_pos - 1; i >= next_op; i--) { OperatorNode *op = alloc_node<OperatorNode>(); - op->op = expression[i].op; - op->nodes[0] = expression[i + 1].node; + op->op = expression_nodes[i].op; + op->nodes[0] = expression_nodes[i + 1].node; op->nodes[1] = nullptr; - expression.write[i].is_op = false; - expression.write[i].node = op; - expression.remove_at(i + 1); + expression_nodes.write[i].is_op = false; + expression_nodes.write[i].node = op; + expression_nodes.remove_at(i + 1); } } else { - if (next_op < 1 || next_op >= (expression.size() - 1)) { + if (next_op < 1 || next_op >= (expression_nodes.size() - 1)) { _set_error("Parser bug..."); ERR_FAIL_V(nullptr); } OperatorNode *op = alloc_node<OperatorNode>(); - op->op = expression[next_op].op; + op->op = expression_nodes[next_op].op; - if (expression[next_op - 1].is_op) { + if (expression_nodes[next_op - 1].is_op) { _set_error("Parser bug..."); ERR_FAIL_V(nullptr); } - if (expression[next_op + 1].is_op) { + if (expression_nodes[next_op + 1].is_op) { // this is not invalid and can really appear // but it becomes invalid anyway because no binary op // can be followed by a unary op in a valid combination, @@ -1197,17 +1197,17 @@ Expression::ENode *Expression::_parse_expression() { return nullptr; } - op->nodes[0] = expression[next_op - 1].node; //expression goes as left - op->nodes[1] = expression[next_op + 1].node; //next expression goes as right + op->nodes[0] = expression_nodes[next_op - 1].node; //expression goes as left + op->nodes[1] = expression_nodes[next_op + 1].node; //next expression goes as right //replace all 3 nodes by this operator and make it an expression - expression.write[next_op - 1].node = op; - expression.remove_at(next_op); - expression.remove_at(next_op); + expression_nodes.write[next_op - 1].node = op; + expression_nodes.remove_at(next_op); + expression_nodes.remove_at(next_op); } } - return expression[0].node; + return expression_nodes[0].node; } bool Expression::_compile_expression() { diff --git a/core/math/geometry_3d.cpp b/core/math/geometry_3d.cpp index 9238293b48..c5871358ed 100644 --- a/core/math/geometry_3d.cpp +++ b/core/math/geometry_3d.cpp @@ -30,8 +30,6 @@ #include "geometry_3d.h" -#include "core/string/print_string.h" - #include "thirdparty/misc/clipper.hpp" #include "thirdparty/misc/polypartition.h" diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h index 7fa674a23d..0af529ad98 100644 --- a/core/math/math_funcs.h +++ b/core/math/math_funcs.h @@ -184,6 +184,9 @@ public: #endif } + static _ALWAYS_INLINE_ bool is_finite(double p_val) { return isfinite(p_val); } + static _ALWAYS_INLINE_ bool is_finite(float p_val) { return isfinite(p_val); } + static _ALWAYS_INLINE_ double abs(double g) { return absd(g); } static _ALWAYS_INLINE_ float abs(float g) { return absf(g); } static _ALWAYS_INLINE_ int abs(int g) { return g > 0 ? g : -g; } diff --git a/core/math/plane.cpp b/core/math/plane.cpp index 6881ad4014..a5d2fe5628 100644 --- a/core/math/plane.cpp +++ b/core/math/plane.cpp @@ -147,6 +147,7 @@ Variant Plane::intersect_3_bind(const Plane &p_plane1, const Plane &p_plane2) co return Variant(); } } + Variant Plane::intersects_ray_bind(const Vector3 &p_from, const Vector3 &p_dir) const { Vector3 inters; if (intersects_ray(p_from, p_dir, &inters)) { @@ -155,6 +156,7 @@ Variant Plane::intersects_ray_bind(const Vector3 &p_from, const Vector3 &p_dir) return Variant(); } } + Variant Plane::intersects_segment_bind(const Vector3 &p_begin, const Vector3 &p_end) const { Vector3 inters; if (intersects_segment(p_begin, p_end, &inters)) { @@ -174,6 +176,10 @@ bool Plane::is_equal_approx(const Plane &p_plane) const { return normal.is_equal_approx(p_plane.normal) && Math::is_equal_approx(d, p_plane.d); } +bool Plane::is_finite() const { + return normal.is_finite() && Math::is_finite(d); +} + Plane::operator String() const { return "[N: " + normal.operator String() + ", D: " + String::num_real(d, false) + "]"; } diff --git a/core/math/plane.h b/core/math/plane.h index 73babfa496..77da59fb27 100644 --- a/core/math/plane.h +++ b/core/math/plane.h @@ -74,6 +74,7 @@ struct _NO_DISCARD_ Plane { Plane operator-() const { return Plane(-normal, -d); } bool is_equal_approx(const Plane &p_plane) const; bool is_equal_approx_any_side(const Plane &p_plane) const; + bool is_finite() const; _FORCE_INLINE_ bool operator==(const Plane &p_plane) const; _FORCE_INLINE_ bool operator!=(const Plane &p_plane) const; diff --git a/core/math/projection.cpp b/core/math/projection.cpp index d579b641a7..70cc9b5f7c 100644 --- a/core/math/projection.cpp +++ b/core/math/projection.cpp @@ -35,7 +35,7 @@ #include "core/math/plane.h" #include "core/math/rect2.h" #include "core/math/transform_3d.h" -#include "core/string/print_string.h" +#include "core/string/ustring.h" float Projection::determinant() const { return columns[0][3] * columns[1][2] * columns[2][1] * columns[3][0] - columns[0][2] * columns[1][3] * columns[2][1] * columns[3][0] - @@ -169,7 +169,7 @@ Projection Projection::perspective_znear_adjusted(real_t p_new_znear) const { } Plane Projection::get_projection_plane(Planes p_plane) const { - const real_t *matrix = (const real_t *)this->columns; + const real_t *matrix = (const real_t *)columns; switch (p_plane) { case PLANE_NEAR: { @@ -402,7 +402,7 @@ void Projection::set_frustum(real_t p_size, real_t p_aspect, Vector2 p_offset, r } real_t Projection::get_z_far() const { - const real_t *matrix = (const real_t *)this->columns; + const real_t *matrix = (const real_t *)columns; Plane new_plane = Plane(matrix[3] - matrix[2], matrix[7] - matrix[6], matrix[11] - matrix[10], @@ -415,7 +415,7 @@ real_t Projection::get_z_far() const { } real_t Projection::get_z_near() const { - const real_t *matrix = (const real_t *)this->columns; + const real_t *matrix = (const real_t *)columns; Plane new_plane = Plane(matrix[3] + matrix[2], matrix[7] + matrix[6], matrix[11] + matrix[10], @@ -426,7 +426,7 @@ real_t Projection::get_z_near() const { } Vector2 Projection::get_viewport_half_extents() const { - const real_t *matrix = (const real_t *)this->columns; + const real_t *matrix = (const real_t *)columns; ///////--- Near Plane ---/////// Plane near_plane = Plane(matrix[3] + matrix[2], matrix[7] + matrix[6], @@ -454,7 +454,7 @@ Vector2 Projection::get_viewport_half_extents() const { } Vector2 Projection::get_far_plane_half_extents() const { - const real_t *matrix = (const real_t *)this->columns; + const real_t *matrix = (const real_t *)columns; ///////--- Far Plane ---/////// Plane far_plane = Plane(matrix[3] - matrix[2], matrix[7] - matrix[6], @@ -496,7 +496,10 @@ bool Projection::get_endpoints(const Transform3D &p_transform, Vector3 *p_8point for (int i = 0; i < 8; i++) { Vector3 point; - bool res = planes[intersections[i][0]].intersect_3(planes[intersections[i][1]], planes[intersections[i][2]], &point); + Plane a = planes[intersections[i][0]]; + Plane b = planes[intersections[i][1]]; + Plane c = planes[intersections[i][2]]; + bool res = a.intersect_3(b, c, &point); ERR_FAIL_COND_V(!res, false); p_8points[i] = p_transform.xform(point); } @@ -514,7 +517,7 @@ Vector<Plane> Projection::get_projection_planes(const Transform3D &p_transform) Vector<Plane> planes; planes.resize(6); - const real_t *matrix = (const real_t *)this->columns; + const real_t *matrix = (const real_t *)columns; Plane new_plane; @@ -807,7 +810,7 @@ bool Projection::is_orthogonal() const { } real_t Projection::get_fov() const { - const real_t *matrix = (const real_t *)this->columns; + const real_t *matrix = (const real_t *)columns; Plane right_plane = Plane(matrix[3] - matrix[0], matrix[7] - matrix[4], @@ -838,8 +841,9 @@ float Projection::get_lod_multiplier() const { return 1.0 / (zn / width); } - //usage is lod_size / (lod_distance * multiplier) < threshold + // Usage is lod_size / (lod_distance * multiplier) < threshold } + void Projection::make_scale(const Vector3 &p_scale) { set_identity(); columns[0][0] = p_scale.x; diff --git a/core/math/projection.h b/core/math/projection.h index 1bf5d8b2ed..38fb9781ae 100644 --- a/core/math/projection.h +++ b/core/math/projection.h @@ -31,10 +31,11 @@ #ifndef PROJECTION_H #define PROJECTION_H -#include "core/math/math_defs.h" #include "core/math/vector3.h" #include "core/math/vector4.h" -#include "core/templates/vector.h" + +template <class T> +class Vector; struct AABB; struct Plane; @@ -42,7 +43,7 @@ struct Rect2; struct Transform3D; struct Vector2; -struct Projection { +struct _NO_DISCARD_ Projection { enum Planes { PLANE_NEAR, PLANE_FAR, diff --git a/core/math/quaternion.cpp b/core/math/quaternion.cpp index c836a82e37..6a5f29f3d8 100644 --- a/core/math/quaternion.cpp +++ b/core/math/quaternion.cpp @@ -31,7 +31,7 @@ #include "quaternion.h" #include "core/math/basis.h" -#include "core/string/print_string.h" +#include "core/string/ustring.h" real_t Quaternion::angle_to(const Quaternion &p_to) const { real_t d = dot(p_to); @@ -79,6 +79,10 @@ bool Quaternion::is_equal_approx(const Quaternion &p_quaternion) const { return Math::is_equal_approx(x, p_quaternion.x) && Math::is_equal_approx(y, p_quaternion.y) && Math::is_equal_approx(z, p_quaternion.z) && Math::is_equal_approx(w, p_quaternion.w); } +bool Quaternion::is_finite() const { + return Math::is_finite(x) && Math::is_finite(y) && Math::is_finite(z) && Math::is_finite(w); +} + real_t Quaternion::length() const { return Math::sqrt(length_squared()); } diff --git a/core/math/quaternion.h b/core/math/quaternion.h index 43d7bffcfc..7aa400aa8c 100644 --- a/core/math/quaternion.h +++ b/core/math/quaternion.h @@ -31,10 +31,10 @@ #ifndef QUATERNION_H #define QUATERNION_H -#include "core/math/math_defs.h" #include "core/math/math_funcs.h" #include "core/math/vector3.h" -#include "core/string/ustring.h" + +class String; struct _NO_DISCARD_ Quaternion { union { @@ -55,6 +55,7 @@ struct _NO_DISCARD_ Quaternion { } _FORCE_INLINE_ real_t length_squared() const; bool is_equal_approx(const Quaternion &p_quaternion) const; + bool is_finite() const; real_t length() const; void normalize(); Quaternion normalized() const; @@ -143,8 +144,7 @@ struct _NO_DISCARD_ Quaternion { w = p_q.w; } - Quaternion(const Vector3 &v0, const Vector3 &v1) // shortest arc - { + Quaternion(const Vector3 &v0, const Vector3 &v1) { // Shortest arc. Vector3 c = v0.cross(v1); real_t d = v0.dot(v1); diff --git a/core/math/rect2.cpp b/core/math/rect2.cpp index 9e78ead816..facf4eb3c4 100644 --- a/core/math/rect2.cpp +++ b/core/math/rect2.cpp @@ -38,6 +38,10 @@ bool Rect2::is_equal_approx(const Rect2 &p_rect) const { return position.is_equal_approx(p_rect.position) && size.is_equal_approx(p_rect.size); } +bool Rect2::is_finite() const { + return position.is_finite() && size.is_finite(); +} + bool Rect2::intersects_segment(const Point2 &p_from, const Point2 &p_to, Point2 *r_pos, Point2 *r_normal) const { #ifdef MATH_CHECKS if (unlikely(size.x < 0 || size.y < 0)) { diff --git a/core/math/rect2.h b/core/math/rect2.h index 2d1be3d4f3..9863405d8e 100644 --- a/core/math/rect2.h +++ b/core/math/rect2.h @@ -178,7 +178,7 @@ struct _NO_DISCARD_ Rect2 { new_rect.size.x = MAX(p_rect.position.x + p_rect.size.x, position.x + size.x); new_rect.size.y = MAX(p_rect.position.y + p_rect.size.y, position.y + size.y); - new_rect.size = new_rect.size - new_rect.position; //make relative again + new_rect.size = new_rect.size - new_rect.position; // Make relative again. return new_rect; } @@ -207,6 +207,7 @@ struct _NO_DISCARD_ Rect2 { } bool is_equal_approx(const Rect2 &p_rect) const; + bool is_finite() const; bool operator==(const Rect2 &p_rect) const { return position == p_rect.position && size == p_rect.size; } bool operator!=(const Rect2 &p_rect) const { return position != p_rect.position || size != p_rect.size; } @@ -253,7 +254,7 @@ struct _NO_DISCARD_ Rect2 { return r; } - inline void expand_to(const Vector2 &p_vector) { //in place function for speed + inline void expand_to(const Vector2 &p_vector) { // In place function for speed. #ifdef MATH_CHECKS if (unlikely(size.x < 0 || size.y < 0)) { ERR_PRINT("Rect2 size is negative, this is not supported. Use Rect2.abs() to get a Rect2 with a positive size."); @@ -281,7 +282,7 @@ struct _NO_DISCARD_ Rect2 { } _FORCE_INLINE_ Rect2 abs() const { - return Rect2(Point2(position.x + MIN(size.x, 0), position.y + MIN(size.y, 0)), size.abs()); + return Rect2(Point2(position.x + MIN(size.x, (real_t)0), position.y + MIN(size.y, (real_t)0)), size.abs()); } Vector2 get_support(const Vector2 &p_normal) const { @@ -311,7 +312,7 @@ struct _NO_DISCARD_ Rect2 { continue; } - //check inside + // Check inside. Vector2 tg = r.orthogonal(); float s = tg.dot(center) - tg.dot(a); if (s < 0.0f) { @@ -320,7 +321,7 @@ struct _NO_DISCARD_ Rect2 { side_minus++; } - //check ray box + // Check ray box. r /= l; Vector2 ir(1.0f / r.x, 1.0f / r.y); @@ -341,7 +342,7 @@ struct _NO_DISCARD_ Rect2 { } if (side_plus * side_minus == 0) { - return true; //all inside + return true; // All inside. } else { return false; } diff --git a/core/math/rect2i.h b/core/math/rect2i.h index 2b58dcdd98..c92f2cae02 100644 --- a/core/math/rect2i.h +++ b/core/math/rect2i.h @@ -121,7 +121,7 @@ struct _NO_DISCARD_ Rect2i { new_rect.size.x = MAX(p_rect.position.x + p_rect.size.x, position.x + size.x); new_rect.size.y = MAX(p_rect.position.y + p_rect.size.y, position.y + size.y); - new_rect.size = new_rect.size - new_rect.position; //make relative again + new_rect.size = new_rect.size - new_rect.position; // Make relative again. return new_rect; } diff --git a/core/math/transform_2d.cpp b/core/math/transform_2d.cpp index 226076029b..548a82d254 100644 --- a/core/math/transform_2d.cpp +++ b/core/math/transform_2d.cpp @@ -168,6 +168,10 @@ bool Transform2D::is_equal_approx(const Transform2D &p_transform) const { return columns[0].is_equal_approx(p_transform.columns[0]) && columns[1].is_equal_approx(p_transform.columns[1]) && columns[2].is_equal_approx(p_transform.columns[2]); } +bool Transform2D::is_finite() const { + return columns[0].is_finite() && columns[1].is_finite() && columns[2].is_finite(); +} + Transform2D Transform2D::looking_at(const Vector2 &p_target) const { Transform2D return_trans = Transform2D(get_rotation(), get_origin()); Vector2 target_position = affine_inverse().xform(p_target); @@ -282,7 +286,7 @@ Transform2D Transform2D::interpolate_with(const Transform2D &p_transform, const real_t dot = v1.dot(v2); - dot = CLAMP(dot, -1.0f, 1.0f); + dot = CLAMP(dot, (real_t)-1.0, (real_t)1.0); Vector2 v; diff --git a/core/math/transform_2d.h b/core/math/transform_2d.h index f23f32867a..2b11f36535 100644 --- a/core/math/transform_2d.h +++ b/core/math/transform_2d.h @@ -98,6 +98,7 @@ struct _NO_DISCARD_ Transform2D { void orthonormalize(); Transform2D orthonormalized() const; bool is_equal_approx(const Transform2D &p_transform) const; + bool is_finite() const; Transform2D looking_at(const Vector2 &p_target) const; diff --git a/core/math/transform_3d.cpp b/core/math/transform_3d.cpp index 2de9e81b38..3285cbd664 100644 --- a/core/math/transform_3d.cpp +++ b/core/math/transform_3d.cpp @@ -31,7 +31,7 @@ #include "transform_3d.h" #include "core/math/math_funcs.h" -#include "core/string/print_string.h" +#include "core/string/ustring.h" void Transform3D::affine_invert() { basis.invert(); @@ -174,6 +174,10 @@ bool Transform3D::is_equal_approx(const Transform3D &p_transform) const { return basis.is_equal_approx(p_transform.basis) && origin.is_equal_approx(p_transform.origin); } +bool Transform3D::is_finite() const { + return basis.is_finite() && origin.is_finite(); +} + bool Transform3D::operator==(const Transform3D &p_transform) const { return (basis == p_transform.basis && origin == p_transform.origin); } diff --git a/core/math/transform_3d.h b/core/math/transform_3d.h index c62e4a7b0e..cb347aa1c1 100644 --- a/core/math/transform_3d.h +++ b/core/math/transform_3d.h @@ -34,6 +34,7 @@ #include "core/math/aabb.h" #include "core/math/basis.h" #include "core/math/plane.h" +#include "core/templates/vector.h" struct _NO_DISCARD_ Transform3D { Basis basis; @@ -74,6 +75,7 @@ struct _NO_DISCARD_ Transform3D { void orthogonalize(); Transform3D orthogonalized() const; bool is_equal_approx(const Transform3D &p_transform) const; + bool is_finite() const; bool operator==(const Transform3D &p_transform) const; bool operator!=(const Transform3D &p_transform) const; diff --git a/core/math/triangle_mesh.cpp b/core/math/triangle_mesh.cpp index 4433559e6d..6515c55a85 100644 --- a/core/math/triangle_mesh.cpp +++ b/core/math/triangle_mesh.cpp @@ -215,10 +215,8 @@ Vector3 TriangleMesh::get_area_normal(const AABB &p_aabb) const { switch (stack[level] >> VISITED_BIT_SHIFT) { case TEST_AABB_BIT: { - bool valid = b.aabb.intersects(p_aabb); - if (!valid) { + if (!b.aabb.intersects(p_aabb)) { stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node; - } else { if (b.face_index >= 0) { const Triangle &s = triangleptr[b.face_index]; @@ -302,12 +300,8 @@ bool TriangleMesh::intersect_segment(const Vector3 &p_begin, const Vector3 &p_en switch (stack[level] >> VISITED_BIT_SHIFT) { case TEST_AABB_BIT: { - bool valid = b.aabb.intersects_segment(p_begin, p_end); - //bool valid = b.aabb.intersects(ray_aabb); - - if (!valid) { + if (!b.aabb.intersects_segment(p_begin, p_end)) { stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node; - } else { if (b.face_index >= 0) { const Triangle &s = triangleptr[b.face_index]; @@ -407,10 +401,8 @@ bool TriangleMesh::intersect_ray(const Vector3 &p_begin, const Vector3 &p_dir, V switch (stack[level] >> VISITED_BIT_SHIFT) { case TEST_AABB_BIT: { - bool valid = b.aabb.intersects_ray(p_begin, p_dir); - if (!valid) { + if (!b.aabb.intersects_ray(p_begin, p_dir)) { stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node; - } else { if (b.face_index >= 0) { const Triangle &s = triangleptr[b.face_index]; @@ -508,10 +500,8 @@ bool TriangleMesh::intersect_convex_shape(const Plane *p_planes, int p_plane_cou switch (stack[level] >> VISITED_BIT_SHIFT) { case TEST_AABB_BIT: { - bool valid = b.aabb.intersects_convex_shape(p_planes, p_plane_count, p_points, p_point_count); - if (!valid) { + if (!b.aabb.intersects_convex_shape(p_planes, p_plane_count, p_points, p_point_count)) { stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node; - } else { if (b.face_index >= 0) { const Triangle &s = triangleptr[b.face_index]; diff --git a/core/math/vector2.cpp b/core/math/vector2.cpp index 56dbba393a..5366587126 100644 --- a/core/math/vector2.cpp +++ b/core/math/vector2.cpp @@ -186,6 +186,10 @@ bool Vector2::is_zero_approx() const { return Math::is_zero_approx(x) && Math::is_zero_approx(y); } +bool Vector2::is_finite() const { + return Math::is_finite(x) && Math::is_finite(y); +} + Vector2::operator String() const { return "(" + String::num_real(x, false) + ", " + String::num_real(y, false) + ")"; } diff --git a/core/math/vector2.h b/core/math/vector2.h index 75364f72f0..5775d8e735 100644 --- a/core/math/vector2.h +++ b/core/math/vector2.h @@ -121,6 +121,7 @@ struct _NO_DISCARD_ Vector2 { bool is_equal_approx(const Vector2 &p_v) const; bool is_zero_approx() const; + bool is_finite() const; Vector2 operator+(const Vector2 &p_v) const; void operator+=(const Vector2 &p_v); diff --git a/core/math/vector3.cpp b/core/math/vector3.cpp index 55ba509144..b106200c4a 100644 --- a/core/math/vector3.cpp +++ b/core/math/vector3.cpp @@ -139,6 +139,10 @@ bool Vector3::is_zero_approx() const { return Math::is_zero_approx(x) && Math::is_zero_approx(y) && Math::is_zero_approx(z); } +bool Vector3::is_finite() const { + return Math::is_finite(x) && Math::is_finite(y) && Math::is_finite(z); +} + Vector3::operator String() const { return "(" + String::num_real(x, false) + ", " + String::num_real(y, false) + ", " + String::num_real(z, false) + ")"; } diff --git a/core/math/vector3.h b/core/math/vector3.h index 62e810fb4d..19771eb312 100644 --- a/core/math/vector3.h +++ b/core/math/vector3.h @@ -136,6 +136,7 @@ struct _NO_DISCARD_ Vector3 { bool is_equal_approx(const Vector3 &p_v) const; bool is_zero_approx() const; + bool is_finite() const; /* Operators */ diff --git a/core/math/vector4.cpp b/core/math/vector4.cpp index 55e51834df..3b189f7ed4 100644 --- a/core/math/vector4.cpp +++ b/core/math/vector4.cpp @@ -30,8 +30,7 @@ #include "vector4.h" -#include "core/math/basis.h" -#include "core/string/print_string.h" +#include "core/string/ustring.h" Vector4::Axis Vector4::min_axis_index() const { uint32_t min_index = 0; @@ -65,6 +64,10 @@ bool Vector4::is_zero_approx() const { return Math::is_zero_approx(x) && Math::is_zero_approx(y) && Math::is_zero_approx(z) && Math::is_zero_approx(w); } +bool Vector4::is_finite() const { + return Math::is_finite(x) && Math::is_finite(y) && Math::is_finite(z) && Math::is_finite(w); +} + real_t Vector4::length() const { return Math::sqrt(length_squared()); } diff --git a/core/math/vector4.h b/core/math/vector4.h index 426c473e13..7c4bdc1788 100644 --- a/core/math/vector4.h +++ b/core/math/vector4.h @@ -31,10 +31,10 @@ #ifndef VECTOR4_H #define VECTOR4_H -#include "core/math/math_defs.h" +#include "core/error/error_macros.h" #include "core/math/math_funcs.h" -#include "core/math/vector3.h" -#include "core/string/ustring.h" + +class String; struct _NO_DISCARD_ Vector4 { static const int AXIS_COUNT = 4; @@ -71,6 +71,7 @@ struct _NO_DISCARD_ Vector4 { _FORCE_INLINE_ real_t length_squared() const; bool is_equal_approx(const Vector4 &p_vec4) const; bool is_zero_approx() const; + bool is_finite() const; real_t length() const; void normalize(); Vector4 normalized() const; diff --git a/core/object/class_db.cpp b/core/object/class_db.cpp index 99b20560da..ca56add2ab 100644 --- a/core/object/class_db.cpp +++ b/core/object/class_db.cpp @@ -1538,7 +1538,11 @@ void ClassDB::register_extension_class(ObjectNativeExtension *p_extension) { } void ClassDB::unregister_extension_class(const StringName &p_class) { - ERR_FAIL_COND(!classes.has(p_class)); + ClassInfo *c = classes.getptr(p_class); + ERR_FAIL_COND_MSG(!c, "Class " + p_class + "does not exist"); + for (KeyValue<StringName, MethodBind *> &F : c->method_map) { + memdelete(F.value); + } classes.erase(p_class); } diff --git a/core/object/method_bind.h b/core/object/method_bind.h index 0d3e40f709..598e8a224d 100644 --- a/core/object/method_bind.h +++ b/core/object/method_bind.h @@ -292,11 +292,6 @@ class MethodBindT : public MethodBind { void (MB_T::*method)(P...); protected: -// GCC raises warnings in the case P = {} as the comparison is always false... -#if defined(__GNUC__) && !defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wlogical-op" -#endif virtual Variant::Type _gen_argument_type(int p_arg) const override { if (p_arg >= 0 && p_arg < (int)sizeof...(P)) { return call_get_argument_type<P...>(p_arg); @@ -304,9 +299,6 @@ protected: return Variant::NIL; } } -#if defined(__GNUC__) && !defined(__clang__) -#pragma GCC diagnostic pop -#endif virtual PropertyInfo _gen_argument_type_info(int p_arg) const override { PropertyInfo pi; @@ -367,11 +359,6 @@ class MethodBindTC : public MethodBind { void (MB_T::*method)(P...) const; protected: -// GCC raises warnings in the case P = {} as the comparison is always false... -#if defined(__GNUC__) && !defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wlogical-op" -#endif virtual Variant::Type _gen_argument_type(int p_arg) const override { if (p_arg >= 0 && p_arg < (int)sizeof...(P)) { return call_get_argument_type<P...>(p_arg); @@ -379,9 +366,6 @@ protected: return Variant::NIL; } } -#if defined(__GNUC__) && !defined(__clang__) -#pragma GCC diagnostic pop -#endif virtual PropertyInfo _gen_argument_type_info(int p_arg) const override { PropertyInfo pi; @@ -444,11 +428,6 @@ class MethodBindTR : public MethodBind { (P...); protected: -// GCC raises warnings in the case P = {} as the comparison is always false... -#if defined(__GNUC__) && !defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wlogical-op" -#endif virtual Variant::Type _gen_argument_type(int p_arg) const override { if (p_arg >= 0 && p_arg < (int)sizeof...(P)) { return call_get_argument_type<P...>(p_arg); @@ -466,9 +445,6 @@ protected: return GetTypeInfo<R>::get_class_info(); } } -#if defined(__GNUC__) && !defined(__clang__) -#pragma GCC diagnostic pop -#endif public: #ifdef DEBUG_METHODS_ENABLED @@ -531,11 +507,6 @@ class MethodBindTRC : public MethodBind { (P...) const; protected: -// GCC raises warnings in the case P = {} as the comparison is always false... -#if defined(__GNUC__) && !defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wlogical-op" -#endif virtual Variant::Type _gen_argument_type(int p_arg) const override { if (p_arg >= 0 && p_arg < (int)sizeof...(P)) { return call_get_argument_type<P...>(p_arg); @@ -553,9 +524,6 @@ protected: return GetTypeInfo<R>::get_class_info(); } } -#if defined(__GNUC__) && !defined(__clang__) -#pragma GCC diagnostic pop -#endif public: #ifdef DEBUG_METHODS_ENABLED @@ -615,11 +583,6 @@ class MethodBindTS : public MethodBind { void (*function)(P...); protected: -// GCC raises warnings in the case P = {} as the comparison is always false... -#if defined(__GNUC__) && !defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wlogical-op" -#endif virtual Variant::Type _gen_argument_type(int p_arg) const override { if (p_arg >= 0 && p_arg < (int)sizeof...(P)) { return call_get_argument_type<P...>(p_arg); @@ -627,9 +590,6 @@ protected: return Variant::NIL; } } -#if defined(__GNUC__) && !defined(__clang__) -#pragma GCC diagnostic pop -#endif virtual PropertyInfo _gen_argument_type_info(int p_arg) const override { PropertyInfo pi; @@ -678,11 +638,6 @@ class MethodBindTRS : public MethodBind { (P...); protected: -// GCC raises warnings in the case P = {} as the comparison is always false... -#if defined(__GNUC__) && !defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wlogical-op" -#endif virtual Variant::Type _gen_argument_type(int p_arg) const override { if (p_arg >= 0 && p_arg < (int)sizeof...(P)) { return call_get_argument_type<P...>(p_arg); @@ -690,9 +645,6 @@ protected: return GetTypeInfo<R>::VARIANT_TYPE; } } -#if defined(__GNUC__) && !defined(__clang__) -#pragma GCC diagnostic pop -#endif virtual PropertyInfo _gen_argument_type_info(int p_arg) const override { if (p_arg >= 0 && p_arg < (int)sizeof...(P)) { diff --git a/core/object/script_language.cpp b/core/object/script_language.cpp index e56d2e80b9..9e26289e66 100644 --- a/core/object/script_language.cpp +++ b/core/object/script_language.cpp @@ -106,23 +106,23 @@ Dictionary Script::_get_script_constant_map() { PropertyInfo Script::get_class_category() const { String path = get_path(); - String name; + String scr_name; if (is_built_in()) { if (get_name().is_empty()) { - name = TTR("Built-in script"); + scr_name = TTR("Built-in script"); } else { - name = vformat("%s (%s)", get_name(), TTR("Built-in")); + scr_name = vformat("%s (%s)", get_name(), TTR("Built-in")); } } else { if (get_name().is_empty()) { - name = path.get_file(); + scr_name = path.get_file(); } else { - name = get_name(); + scr_name = get_name(); } } - return PropertyInfo(Variant::NIL, name, PROPERTY_HINT_NONE, path, PROPERTY_USAGE_CATEGORY); + return PropertyInfo(Variant::NIL, scr_name, PROPERTY_HINT_NONE, path, PROPERTY_USAGE_CATEGORY); } #endif // TOOLS_ENABLED @@ -166,6 +166,7 @@ ScriptLanguage *ScriptServer::get_language(int p_idx) { } void ScriptServer::register_language(ScriptLanguage *p_language) { + ERR_FAIL_NULL(p_language); ERR_FAIL_COND(_language_count >= MAX_LANGUAGES); _languages[_language_count++] = p_language; } diff --git a/core/object/script_language_extension.h b/core/object/script_language_extension.h index 7e74f6a2be..c32fb9d85b 100644 --- a/core/object/script_language_extension.h +++ b/core/object/script_language_extension.h @@ -82,9 +82,10 @@ public: GDVIRTUAL_REQUIRED_CALL(_get_documentation, doc); Vector<DocData::ClassDoc> class_doc; -#ifndef _MSC_VER -#warning missing conversion from documentation to ClassDoc -#endif + for (int i = 0; i < doc.size(); i++) { + class_doc.append(DocData::ClassDoc::from_dict(doc[i])); + } + return class_doc; } #endif // TOOLS_ENABLED diff --git a/core/os/os.cpp b/core/os/os.cpp index 72d68893f3..bbb2a94fe7 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -38,6 +38,7 @@ #include "core/version_generated.gen.h" #include <stdarg.h> +#include <thread> OS *OS::singleton = nullptr; uint64_t OS::target_ticks = 0; @@ -321,7 +322,7 @@ String OS::get_unique_id() const { } int OS::get_processor_count() const { - return 1; + return std::thread::hardware_concurrency(); } String OS::get_processor_name() const { diff --git a/core/string/optimized_translation.cpp b/core/string/optimized_translation.cpp index 07302cc8c3..b130c2fc79 100644 --- a/core/string/optimized_translation.cpp +++ b/core/string/optimized_translation.cpp @@ -179,14 +179,14 @@ void OptimizedTranslation::generate(const Ref<Translation> &p_from) { } bool OptimizedTranslation::_set(const StringName &p_name, const Variant &p_value) { - String name = p_name.operator String(); - if (name == "hash_table") { + String prop_name = p_name.operator String(); + if (prop_name == "hash_table") { hash_table = p_value; - } else if (name == "bucket_table") { + } else if (prop_name == "bucket_table") { bucket_table = p_value; - } else if (name == "strings") { + } else if (prop_name == "strings") { strings = p_value; - } else if (name == "load_from") { + } else if (prop_name == "load_from") { generate(p_value); } else { return false; @@ -196,12 +196,12 @@ bool OptimizedTranslation::_set(const StringName &p_name, const Variant &p_value } bool OptimizedTranslation::_get(const StringName &p_name, Variant &r_ret) const { - String name = p_name.operator String(); - if (name == "hash_table") { + String prop_name = p_name.operator String(); + if (prop_name == "hash_table") { r_ret = hash_table; - } else if (name == "bucket_table") { + } else if (prop_name == "bucket_table") { r_ret = bucket_table; - } else if (name == "strings") { + } else if (prop_name == "strings") { r_ret = strings; } else { return false; diff --git a/core/string/translation.cpp b/core/string/translation.cpp index 4748f1a0cb..9ee7f2b17b 100644 --- a/core/string/translation.cpp +++ b/core/string/translation.cpp @@ -297,27 +297,27 @@ String TranslationServer::standardize_locale(const String &p_locale) const { String univ_locale = p_locale.replace("-", "_"); // Extract locale elements. - String lang, script, country, variant; + String lang_name, script_name, country_name, variant_name; Vector<String> locale_elements = univ_locale.get_slice("@", 0).split("_"); - lang = locale_elements[0]; + lang_name = locale_elements[0]; if (locale_elements.size() >= 2) { if (locale_elements[1].length() == 4 && is_ascii_upper_case(locale_elements[1][0]) && is_ascii_lower_case(locale_elements[1][1]) && is_ascii_lower_case(locale_elements[1][2]) && is_ascii_lower_case(locale_elements[1][3])) { - script = locale_elements[1]; + script_name = locale_elements[1]; } if (locale_elements[1].length() == 2 && is_ascii_upper_case(locale_elements[1][0]) && is_ascii_upper_case(locale_elements[1][1])) { - country = locale_elements[1]; + country_name = locale_elements[1]; } } if (locale_elements.size() >= 3) { if (locale_elements[2].length() == 2 && is_ascii_upper_case(locale_elements[2][0]) && is_ascii_upper_case(locale_elements[2][1])) { - country = locale_elements[2]; - } else if (variant_map.has(locale_elements[2].to_lower()) && variant_map[locale_elements[2].to_lower()] == lang) { - variant = locale_elements[2].to_lower(); + country_name = locale_elements[2]; + } else if (variant_map.has(locale_elements[2].to_lower()) && variant_map[locale_elements[2].to_lower()] == lang_name) { + variant_name = locale_elements[2].to_lower(); } } if (locale_elements.size() >= 4) { - if (variant_map.has(locale_elements[3].to_lower()) && variant_map[locale_elements[3].to_lower()] == lang) { - variant = locale_elements[3].to_lower(); + if (variant_map.has(locale_elements[3].to_lower()) && variant_map[locale_elements[3].to_lower()] == lang_name) { + variant_name = locale_elements[3].to_lower(); } } @@ -325,69 +325,69 @@ String TranslationServer::standardize_locale(const String &p_locale) const { Vector<String> script_extra = univ_locale.get_slice("@", 1).split(";"); for (int i = 0; i < script_extra.size(); i++) { if (script_extra[i].to_lower() == "cyrillic") { - script = "Cyrl"; + script_name = "Cyrl"; break; } else if (script_extra[i].to_lower() == "latin") { - script = "Latn"; + script_name = "Latn"; break; } else if (script_extra[i].to_lower() == "devanagari") { - script = "Deva"; + script_name = "Deva"; break; - } else if (variant_map.has(script_extra[i].to_lower()) && variant_map[script_extra[i].to_lower()] == lang) { - variant = script_extra[i].to_lower(); + } else if (variant_map.has(script_extra[i].to_lower()) && variant_map[script_extra[i].to_lower()] == lang_name) { + variant_name = script_extra[i].to_lower(); } } // Handles known non-ISO language names used e.g. on Windows. - if (locale_rename_map.has(lang)) { - lang = locale_rename_map[lang]; + if (locale_rename_map.has(lang_name)) { + lang_name = locale_rename_map[lang_name]; } // Handle country renames. - if (country_rename_map.has(country)) { - country = country_rename_map[country]; + if (country_rename_map.has(country_name)) { + country_name = country_rename_map[country_name]; } // Remove unsupported script codes. - if (!script_map.has(script)) { - script = ""; + if (!script_map.has(script_name)) { + script_name = ""; } // Add script code base on language and country codes for some ambiguous cases. - if (script.is_empty()) { + if (script_name.is_empty()) { for (int i = 0; i < locale_script_info.size(); i++) { const LocaleScriptInfo &info = locale_script_info[i]; - if (info.name == lang) { - if (country.is_empty() || info.supported_countries.has(country)) { - script = info.script; + if (info.name == lang_name) { + if (country_name.is_empty() || info.supported_countries.has(country_name)) { + script_name = info.script; break; } } } } - if (!script.is_empty() && country.is_empty()) { + if (!script_name.is_empty() && country_name.is_empty()) { // Add conntry code based on script for some ambiguous cases. for (int i = 0; i < locale_script_info.size(); i++) { const LocaleScriptInfo &info = locale_script_info[i]; - if (info.name == lang && info.script == script) { - country = info.default_country; + if (info.name == lang_name && info.script == script_name) { + country_name = info.default_country; break; } } } // Combine results. - String locale = lang; - if (!script.is_empty()) { - locale = locale + "_" + script; + String out = lang_name; + if (!script_name.is_empty()) { + out = out + "_" + script_name; } - if (!country.is_empty()) { - locale = locale + "_" + country; + if (!country_name.is_empty()) { + out = out + "_" + country_name; } - if (!variant.is_empty()) { - locale = locale + "_" + variant; + if (!variant_name.is_empty()) { + out = out + "_" + variant_name; } - return locale; + return out; } int TranslationServer::compare_locales(const String &p_locale_a, const String &p_locale_b) const { @@ -420,31 +420,29 @@ int TranslationServer::compare_locales(const String &p_locale_a, const String &p } String TranslationServer::get_locale_name(const String &p_locale) const { - String locale = standardize_locale(p_locale); - - String lang, script, country; - Vector<String> locale_elements = locale.split("_"); - lang = locale_elements[0]; + String lang_name, script_name, country_name; + Vector<String> locale_elements = standardize_locale(p_locale).split("_"); + lang_name = locale_elements[0]; if (locale_elements.size() >= 2) { if (locale_elements[1].length() == 4 && is_ascii_upper_case(locale_elements[1][0]) && is_ascii_lower_case(locale_elements[1][1]) && is_ascii_lower_case(locale_elements[1][2]) && is_ascii_lower_case(locale_elements[1][3])) { - script = locale_elements[1]; + script_name = locale_elements[1]; } if (locale_elements[1].length() == 2 && is_ascii_upper_case(locale_elements[1][0]) && is_ascii_upper_case(locale_elements[1][1])) { - country = locale_elements[1]; + country_name = locale_elements[1]; } } if (locale_elements.size() >= 3) { if (locale_elements[2].length() == 2 && is_ascii_upper_case(locale_elements[2][0]) && is_ascii_upper_case(locale_elements[2][1])) { - country = locale_elements[2]; + country_name = locale_elements[2]; } } - String name = language_map[lang]; - if (!script.is_empty()) { - name = name + " (" + script_map[script] + ")"; + String name = language_map[lang_name]; + if (!script_name.is_empty()) { + name = name + " (" + script_map[script_name] + ")"; } - if (!country.is_empty()) { - name = name + ", " + country_name_map[country]; + if (!country_name.is_empty()) { + name = name + ", " + country_name_map[country_name]; } return name; } @@ -630,12 +628,12 @@ TranslationServer *TranslationServer::singleton = nullptr; bool TranslationServer::_load_translations(const String &p_from) { if (ProjectSettings::get_singleton()->has_setting(p_from)) { - Vector<String> translations = ProjectSettings::get_singleton()->get(p_from); + const Vector<String> &translation_names = ProjectSettings::get_singleton()->get(p_from); - int tcount = translations.size(); + int tcount = translation_names.size(); if (tcount) { - const String *r = translations.ptr(); + const String *r = translation_names.ptr(); for (int i = 0; i < tcount; i++) { Ref<Translation> tr = ResourceLoader::load(r[i]); @@ -964,7 +962,6 @@ void TranslationServer::_bind_methods() { } void TranslationServer::load_translations() { - String locale = get_locale(); _load_translations("internationalization/locale/translations"); //all _load_translations("internationalization/locale/translations_" + locale.substr(0, 2)); diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp index 6218c21cde..872c8357ae 100644 --- a/core/string/ustring.cpp +++ b/core/string/ustring.cpp @@ -3669,13 +3669,16 @@ String String::simplify_path() const { String drive; if (s.begins_with("local://")) { drive = "local://"; - s = s.substr(8, s.length()); + s = s.substr(8); } else if (s.begins_with("res://")) { drive = "res://"; - s = s.substr(6, s.length()); + s = s.substr(6); } else if (s.begins_with("user://")) { drive = "user://"; - s = s.substr(7, s.length()); + s = s.substr(7); + } else if (s.begins_with("uid://")) { + drive = "uid://"; + s = s.substr(6); } else if (is_network_share_path()) { drive = s.substr(0, 2); s = s.substr(2, s.length() - 2); @@ -3689,7 +3692,7 @@ String String::simplify_path() const { } if (p != -1 && p < s.find("/")) { drive = s.substr(0, p + 2); - s = s.substr(p + 2, s.length()); + s = s.substr(p + 2); } } @@ -4651,10 +4654,10 @@ String String::sprintf(const Array &values, bool *error) const { double value = values[value_index]; bool is_negative = (value < 0); String str = String::num(ABS(value), min_decimals); - bool not_numeric = isinf(value) || isnan(value); + const bool is_finite = Math::is_finite(value); // Pad decimals out. - if (!not_numeric) { + if (is_finite) { str = str.pad_decimals(min_decimals); } @@ -4662,7 +4665,7 @@ String String::sprintf(const Array &values, bool *error) const { // Padding. Leave room for sign later if required. int pad_chars_count = (is_negative || show_sign) ? min_chars - 1 : min_chars; - String pad_char = (pad_with_zeros && !not_numeric) ? String("0") : String(" "); // Never pad NaN or inf with zeros + String pad_char = (pad_with_zeros && is_finite) ? String("0") : String(" "); // Never pad NaN or inf with zeros if (left_justified) { str = str.rpad(pad_chars_count, pad_char); } else { @@ -4713,10 +4716,10 @@ String String::sprintf(const Array &values, bool *error) const { for (int i = 0; i < count; i++) { double val = vec[i]; String number_str = String::num(ABS(val), min_decimals); - bool not_numeric = isinf(val) || isnan(val); + const bool is_finite = Math::is_finite(val); // Pad decimals out. - if (!not_numeric) { + if (is_finite) { number_str = number_str.pad_decimals(min_decimals); } @@ -4724,7 +4727,7 @@ String String::sprintf(const Array &values, bool *error) const { // Padding. Leave room for sign later if required. int pad_chars_count = val < 0 ? min_chars - 1 : min_chars; - String pad_char = (pad_with_zeros && !not_numeric) ? String("0") : String(" "); // Never pad NaN or inf with zeros + String pad_char = (pad_with_zeros && is_finite) ? String("0") : String(" "); // Never pad NaN or inf with zeros if (left_justified) { number_str = number_str.rpad(pad_chars_count, pad_char); } else { diff --git a/core/variant/array.cpp b/core/variant/array.cpp index c1bdd6a6bc..8b958814db 100644 --- a/core/variant/array.cpp +++ b/core/variant/array.cpp @@ -402,6 +402,7 @@ Array Array::recursive_duplicate(bool p_deep, int recursion_count) const { Array Array::slice(int p_begin, int p_end, int p_step, bool p_deep) const { Array result; + result._p->typed = _p->typed; ERR_FAIL_COND_V_MSG(p_step == 0, result, "Slice step cannot be zero."); @@ -433,6 +434,7 @@ Array Array::slice(int p_begin, int p_end, int p_step, bool p_deep) const { Array Array::filter(const Callable &p_callable) const { Array new_arr; new_arr.resize(size()); + new_arr._p->typed = _p->typed; int accepted_count = 0; const Variant *argptrs[1]; diff --git a/core/variant/callable.cpp b/core/variant/callable.cpp index b35e2f004b..79532d9aca 100644 --- a/core/variant/callable.cpp +++ b/core/variant/callable.cpp @@ -402,33 +402,33 @@ Error Signal::emit(const Variant **p_arguments, int p_argcount) const { } Error Signal::connect(const Callable &p_callable, uint32_t p_flags) { - Object *object = get_object(); - ERR_FAIL_COND_V(!object, ERR_UNCONFIGURED); + Object *obj = get_object(); + ERR_FAIL_COND_V(!obj, ERR_UNCONFIGURED); - return object->connect(name, p_callable, p_flags); + return obj->connect(name, p_callable, p_flags); } void Signal::disconnect(const Callable &p_callable) { - Object *object = get_object(); - ERR_FAIL_COND(!object); - object->disconnect(name, p_callable); + Object *obj = get_object(); + ERR_FAIL_COND(!obj); + obj->disconnect(name, p_callable); } bool Signal::is_connected(const Callable &p_callable) const { - Object *object = get_object(); - ERR_FAIL_COND_V(!object, false); + Object *obj = get_object(); + ERR_FAIL_COND_V(!obj, false); - return object->is_connected(name, p_callable); + return obj->is_connected(name, p_callable); } Array Signal::get_connections() const { - Object *object = get_object(); - if (!object) { + Object *obj = get_object(); + if (!obj) { return Array(); } List<Object::Connection> connections; - object->get_signal_connection_list(name, &connections); + obj->get_signal_connection_list(name, &connections); Array arr; for (const Object::Connection &E : connections) { diff --git a/core/variant/variant.cpp b/core/variant/variant.cpp index a6e91bf2ac..b4528e67d1 100644 --- a/core/variant/variant.cpp +++ b/core/variant/variant.cpp @@ -47,146 +47,126 @@ String Variant::get_type_name(Variant::Type p_type) { switch (p_type) { case NIL: { return "Nil"; - } break; + } - // atomic types + // Atomic types. case BOOL: { return "bool"; - } break; + } case INT: { return "int"; - - } break; + } case FLOAT: { return "float"; - - } break; + } case STRING: { return "String"; - } break; + } - // math types + // Math types. case VECTOR2: { return "Vector2"; - } break; + } case VECTOR2I: { return "Vector2i"; - } break; + } case RECT2: { return "Rect2"; - } break; + } case RECT2I: { return "Rect2i"; - } break; + } case TRANSFORM2D: { return "Transform2D"; - } break; + } case VECTOR3: { return "Vector3"; - } break; + } case VECTOR3I: { return "Vector3i"; - } break; + } case VECTOR4: { return "Vector4"; - } break; + } case VECTOR4I: { return "Vector4i"; - } break; + } case PLANE: { return "Plane"; - - } break; + } case AABB: { return "AABB"; - } break; + } case QUATERNION: { return "Quaternion"; - - } break; + } case BASIS: { return "Basis"; - - } break; + } case TRANSFORM3D: { return "Transform3D"; - - } break; + } case PROJECTION: { return "Projection"; + } - } break; - - // misc types + // Miscellaneous types. case COLOR: { return "Color"; - - } break; + } case RID: { return "RID"; - } break; + } case OBJECT: { return "Object"; - } break; + } case CALLABLE: { return "Callable"; - } break; + } case SIGNAL: { return "Signal"; - } break; + } case STRING_NAME: { return "StringName"; - - } break; + } case NODE_PATH: { return "NodePath"; - - } break; + } case DICTIONARY: { return "Dictionary"; - - } break; + } case ARRAY: { return "Array"; + } - } break; - - // arrays + // Arrays. case PACKED_BYTE_ARRAY: { return "PackedByteArray"; - - } break; + } case PACKED_INT32_ARRAY: { return "PackedInt32Array"; - - } break; + } case PACKED_INT64_ARRAY: { return "PackedInt64Array"; - - } break; + } case PACKED_FLOAT32_ARRAY: { return "PackedFloat32Array"; - - } break; + } case PACKED_FLOAT64_ARRAY: { return "PackedFloat64Array"; - - } break; + } case PACKED_STRING_ARRAY: { return "PackedStringArray"; - } break; + } case PACKED_VECTOR2_ARRAY: { return "PackedVector2Array"; - - } break; + } case PACKED_VECTOR3_ARRAY: { return "PackedVector3Array"; - - } break; + } case PACKED_COLOR_ARRAY: { return "PackedColorArray"; - - } break; + } default: { } } @@ -880,157 +860,126 @@ bool Variant::is_zero() const { switch (type) { case NIL: { return true; - } break; + } - // atomic types + // Atomic types. case BOOL: { return !(_data._bool); - } break; + } case INT: { return _data._int == 0; - - } break; + } case FLOAT: { return _data._float == 0; - - } break; + } case STRING: { return *reinterpret_cast<const String *>(_data._mem) == String(); + } - } break; - - // math types + // Math types. case VECTOR2: { 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(); - - } break; + } case VECTOR3: { return *reinterpret_cast<const Vector3 *>(_data._mem) == Vector3(); - - } break; + } case VECTOR3I: { return *reinterpret_cast<const Vector3i *>(_data._mem) == Vector3i(); - - } break; + } case VECTOR4: { return *reinterpret_cast<const Vector4 *>(_data._mem) == Vector4(); - - } break; + } case VECTOR4I: { return *reinterpret_cast<const Vector4i *>(_data._mem) == Vector4i(); - - } break; + } case PLANE: { return *reinterpret_cast<const Plane *>(_data._mem) == Plane(); - - } break; + } case AABB: { return *_data._aabb == ::AABB(); - } break; + } case QUATERNION: { return *reinterpret_cast<const Quaternion *>(_data._mem) == Quaternion(); - - } break; + } case BASIS: { return *_data._basis == Basis(); - - } break; + } case TRANSFORM3D: { return *_data._transform3d == Transform3D(); - - } break; + } case PROJECTION: { return *_data._projection == Projection(); + } - } break; - - // misc types + // Miscellaneous types. case COLOR: { return *reinterpret_cast<const Color *>(_data._mem) == Color(); - - } break; + } case RID: { return *reinterpret_cast<const ::RID *>(_data._mem) == ::RID(); - } break; + } case OBJECT: { return _get_obj().obj == nullptr; - } break; + } case CALLABLE: { return reinterpret_cast<const Callable *>(_data._mem)->is_null(); - } break; + } case SIGNAL: { 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(); - - } break; + } case DICTIONARY: { return reinterpret_cast<const Dictionary *>(_data._mem)->is_empty(); - - } break; + } case ARRAY: { return reinterpret_cast<const Array *>(_data._mem)->is_empty(); + } - } break; - - // arrays + // Arrays. case PACKED_BYTE_ARRAY: { 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_FLOAT32_ARRAY: { return PackedArrayRef<float>::get_array(_data.packed_array).size() == 0; - - } break; + } case PACKED_FLOAT64_ARRAY: { return PackedArrayRef<double>::get_array(_data.packed_array).size() == 0; - - } break; + } case PACKED_STRING_ARRAY: { return PackedArrayRef<String>::get_array(_data.packed_array).size() == 0; - - } break; + } case PACKED_VECTOR2_ARRAY: { return PackedArrayRef<Vector2>::get_array(_data.packed_array).size() == 0; - - } break; + } case PACKED_VECTOR3_ARRAY: { return PackedArrayRef<Vector3>::get_array(_data.packed_array).size() == 0; - - } break; + } case PACKED_COLOR_ARRAY: { return PackedArrayRef<Color>::get_array(_data.packed_array).size() == 0; - - } break; + } default: { } } @@ -1042,67 +991,54 @@ bool Variant::is_one() const { switch (type) { case NIL: { return true; - } break; + } - // atomic types case BOOL: { return _data._bool; - } break; + } case INT: { return _data._int == 1; - - } break; + } case FLOAT: { return _data._float == 1; + } - } break; case VECTOR2: { 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 VECTOR4: { return *reinterpret_cast<const Vector4 *>(_data._mem) == Vector4(1, 1, 1, 1); - - } break; + } case VECTOR4I: { return *reinterpret_cast<const Vector4i *>(_data._mem) == Vector4i(1, 1, 1, 1); - - } break; + } case PLANE: { return *reinterpret_cast<const Plane *>(_data._mem) == Plane(1, 1, 1, 1); + } - } break; case COLOR: { return *reinterpret_cast<const Color *>(_data._mem) == Color(1, 1, 1, 1); - - } break; + } default: { return !is_zero(); } } - - return false; } bool Variant::is_null() const { @@ -1135,10 +1071,10 @@ void Variant::reference(const Variant &p_variant) { switch (p_variant.type) { case NIL: { - // none + // None. } break; - // atomic types + // Atomic types. case BOOL: { _data._bool = p_variant._data._bool; } break; @@ -1152,7 +1088,7 @@ void Variant::reference(const Variant &p_variant) { memnew_placement(_data._mem, String(*reinterpret_cast<const String *>(p_variant._data._mem))); } break; - // math types + // Math types. case VECTOR2: { memnew_placement(_data._mem, Vector2(*reinterpret_cast<const Vector2 *>(p_variant._data._mem))); } break; @@ -1204,10 +1140,9 @@ void Variant::reference(const Variant &p_variant) { memnew_placement(_data._projection, Projection(*p_variant._data._projection)); } break; - // misc types + // Miscellaneous types. case COLOR: { memnew_placement(_data._mem, Color(*reinterpret_cast<const Color *>(p_variant._data._mem))); - } break; case RID: { memnew_placement(_data._mem, ::RID(*reinterpret_cast<const ::RID *>(p_variant._data._mem))); @@ -1226,7 +1161,6 @@ void Variant::reference(const Variant &p_variant) { _get_obj().obj = const_cast<Object *>(p_variant._get_obj().obj); _get_obj().id = p_variant._get_obj().id; - } break; case CALLABLE: { memnew_placement(_data._mem, Callable(*reinterpret_cast<const Callable *>(p_variant._data._mem))); @@ -1236,84 +1170,71 @@ void Variant::reference(const Variant &p_variant) { } 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))); - } break; case DICTIONARY: { memnew_placement(_data._mem, Dictionary(*reinterpret_cast<const Dictionary *>(p_variant._data._mem))); - } break; case ARRAY: { memnew_placement(_data._mem, Array(*reinterpret_cast<const Array *>(p_variant._data._mem))); - } break; - // arrays + // Arrays. case PACKED_BYTE_ARRAY: { _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_INT32_ARRAY: { _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_INT64_ARRAY: { _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: { _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: { _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: { _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: { _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: { } @@ -1333,6 +1254,7 @@ void Variant::zero() { case FLOAT: this->_data._float = 0; break; + case VECTOR2: *reinterpret_cast<Vector2 *>(this->_data._mem) = Vector2(); break; @@ -1363,9 +1285,11 @@ void Variant::zero() { case QUATERNION: *reinterpret_cast<Quaternion *>(this->_data._mem) = Quaternion(); break; + case COLOR: *reinterpret_cast<Color *>(this->_data._mem) = Color(); break; + default: this->clear(); break; @@ -1377,15 +1301,8 @@ void Variant::_clear_internal() { case STRING: { reinterpret_cast<String *>(_data._mem)->~String(); } break; - /* - // no point, they don't allocate memory - VECTOR3, - PLANE, - QUATERNION, - COLOR, - VECTOR2, - RECT2 - */ + + // Math types. case TRANSFORM2D: { if (_data._transform2d) { _data._transform2d->~Transform2D(); @@ -1421,7 +1338,8 @@ void Variant::_clear_internal() { _data._projection = nullptr; } } break; - // misc types + + // Miscellaneous types. case STRING_NAME: { reinterpret_cast<StringName *>(_data._mem)->~StringName(); } break; @@ -1430,7 +1348,7 @@ void Variant::_clear_internal() { } break; case OBJECT: { if (_get_obj().id.is_ref_counted()) { - //we are safe that there is a reference here + // We are safe that there is a reference here. RefCounted *ref_counted = static_cast<RefCounted *>(_get_obj().obj); if (ref_counted->unreference()) { memdelete(ref_counted); @@ -1440,8 +1358,8 @@ void Variant::_clear_internal() { _get_obj().id = ObjectID(); } break; case RID: { - // not much need probably - // Can't seem to use destructor + scoping operator, so hack. + // Not much need probably. + // HACK: Can't seem to use destructor + scoping operator, so hack. typedef ::RID RID_Class; reinterpret_cast<RID_Class *>(_data._mem)->~RID_Class(); } break; @@ -1457,7 +1375,8 @@ void Variant::_clear_internal() { case ARRAY: { reinterpret_cast<Array *>(_data._mem)->~Array(); } break; - // arrays + + // Arrays. case PACKED_BYTE_ARRAY: { PackedArrayRefBase::destroy(_data.packed_array); } break; @@ -1486,7 +1405,9 @@ void Variant::_clear_internal() { PackedArrayRefBase::destroy(_data.packed_array); } break; default: { - } /* not needed */ + // Not needed, there is no point. The following do not allocate memory: + // VECTOR2, VECTOR3, RECT2, PLANE, QUATERNION, COLOR. + } } } @@ -1865,34 +1786,34 @@ String Variant::stringify(int recursion_count) const { str += " }"; return str; - } break; + } case PACKED_VECTOR2_ARRAY: { return stringify_vector(operator Vector<Vector2>(), recursion_count); - } break; + } case PACKED_VECTOR3_ARRAY: { return stringify_vector(operator Vector<Vector3>(), recursion_count); - } break; + } case PACKED_COLOR_ARRAY: { return stringify_vector(operator Vector<Color>(), recursion_count); - } break; + } case PACKED_STRING_ARRAY: { return stringify_vector(operator Vector<String>(), recursion_count); - } break; + } case PACKED_BYTE_ARRAY: { return stringify_vector(operator Vector<uint8_t>(), recursion_count); - } break; + } case PACKED_INT32_ARRAY: { return stringify_vector(operator Vector<int32_t>(), recursion_count); - } break; + } case PACKED_INT64_ARRAY: { return stringify_vector(operator Vector<int64_t>(), recursion_count); - } break; + } case PACKED_FLOAT32_ARRAY: { return stringify_vector(operator Vector<float>(), recursion_count); - } break; + } case PACKED_FLOAT64_ARRAY: { return stringify_vector(operator Vector<double>(), recursion_count); - } break; + } case ARRAY: { Array arr = operator Array(); if (recursion_count > MAX_RECURSION) { @@ -1901,8 +1822,7 @@ String Variant::stringify(int recursion_count) const { } return stringify_vector(arr, recursion_count); - - } break; + } case OBJECT: { if (_get_obj().obj) { if (!_get_obj().id.is_ref_counted() && ObjectDB::get_instance(_get_obj().id) == nullptr) { @@ -1913,31 +1833,27 @@ String Variant::stringify(int recursion_count) const { } else { return "<Object#null>"; } - - } break; + } case CALLABLE: { const Callable &c = *reinterpret_cast<const Callable *>(_data._mem); return c; - } break; + } case SIGNAL: { const Signal &s = *reinterpret_cast<const Signal *>(_data._mem); return s; - } break; + } case RID: { const ::RID &s = *reinterpret_cast<const ::RID *>(_data._mem); return "RID(" + itos(s.get_id()) + ")"; - } break; + } default: { return "<" + get_type_name(type) + ">"; } } - - return ""; } String Variant::to_json_string() const { - JSON json; - return json.stringify(*this); + return JSON::stringify(*this); } Variant::operator Vector2() const { @@ -3573,8 +3489,6 @@ bool Variant::hash_compare(const Variant &p_variant, int recursion_count) const evaluate(OP_EQUAL, *this, p_variant, r, v); return r; } - - return false; } bool Variant::is_ref_counted() const { diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp index 1831f7b72a..900e3d8e77 100644 --- a/core/variant/variant_call.cpp +++ b/core/variant/variant_call.cpp @@ -1606,6 +1606,7 @@ static void _register_variant_builtin_methods() { bind_method(Vector2, is_normalized, sarray(), varray()); bind_method(Vector2, is_equal_approx, sarray("to"), varray()); bind_method(Vector2, is_zero_approx, sarray(), varray()); + bind_method(Vector2, is_finite, sarray(), varray()); bind_method(Vector2, posmod, sarray("mod"), varray()); bind_method(Vector2, posmodv, sarray("modv"), varray()); bind_method(Vector2, project, sarray("b"), varray()); @@ -1653,6 +1654,7 @@ static void _register_variant_builtin_methods() { bind_method(Rect2, has_area, sarray(), varray()); bind_method(Rect2, has_point, sarray("point"), varray()); bind_method(Rect2, is_equal_approx, sarray("rect"), varray()); + bind_method(Rect2, is_finite, sarray(), varray()); bind_method(Rect2, intersects, sarray("b", "include_borders"), varray(false)); bind_method(Rect2, encloses, sarray("b"), varray()); bind_method(Rect2, intersection, sarray("b"), varray()); @@ -1695,6 +1697,7 @@ static void _register_variant_builtin_methods() { bind_method(Vector3, is_normalized, sarray(), varray()); bind_method(Vector3, is_equal_approx, sarray("to"), varray()); bind_method(Vector3, is_zero_approx, sarray(), varray()); + bind_method(Vector3, is_finite, sarray(), varray()); bind_method(Vector3, inverse, sarray(), varray()); bind_method(Vector3, clamp, sarray("min", "max"), varray()); bind_method(Vector3, snapped, sarray("step"), varray()); @@ -1759,6 +1762,7 @@ static void _register_variant_builtin_methods() { bind_method(Vector4, inverse, sarray(), varray()); bind_method(Vector4, is_equal_approx, sarray("with"), varray()); bind_method(Vector4, is_zero_approx, sarray(), varray()); + bind_method(Vector4, is_finite, sarray(), varray()); /* Vector4i */ @@ -1775,6 +1779,7 @@ static void _register_variant_builtin_methods() { bind_method(Plane, normalized, sarray(), varray()); bind_method(Plane, center, sarray(), varray()); bind_method(Plane, is_equal_approx, sarray("to_plane"), varray()); + bind_method(Plane, is_finite, sarray(), varray()); bind_method(Plane, is_point_over, sarray("point"), varray()); bind_method(Plane, distance_to, sarray("point"), varray()); bind_method(Plane, has_point, sarray("point", "tolerance"), varray(CMP_EPSILON)); @@ -1790,6 +1795,7 @@ static void _register_variant_builtin_methods() { bind_method(Quaternion, normalized, sarray(), varray()); bind_method(Quaternion, is_normalized, sarray(), varray()); bind_method(Quaternion, is_equal_approx, sarray("to"), varray()); + bind_method(Quaternion, is_finite, sarray(), varray()); bind_method(Quaternion, inverse, sarray(), varray()); bind_method(Quaternion, log, sarray(), varray()); bind_method(Quaternion, exp, sarray(), varray()); @@ -1909,6 +1915,7 @@ static void _register_variant_builtin_methods() { bind_method(Transform2D, basis_xform_inv, sarray("v"), varray()); bind_method(Transform2D, interpolate_with, sarray("xform", "weight"), varray()); bind_method(Transform2D, is_equal_approx, sarray("xform"), varray()); + bind_method(Transform2D, is_finite, sarray(), varray()); bind_method(Transform2D, set_rotation, sarray("rotation"), varray()); bind_method(Transform2D, set_scale, sarray("scale"), varray()); bind_method(Transform2D, set_skew, sarray("skew"), varray()); @@ -1929,6 +1936,7 @@ static void _register_variant_builtin_methods() { bind_method(Basis, tdotz, sarray("with"), varray()); bind_method(Basis, slerp, sarray("to", "weight"), varray()); bind_method(Basis, is_equal_approx, sarray("b"), varray()); + bind_method(Basis, is_finite, sarray(), varray()); bind_method(Basis, get_rotation_quaternion, sarray(), varray()); bind_static_method(Basis, looking_at, sarray("target", "up"), varray(Vector3(0, 1, 0))); bind_static_method(Basis, from_scale, sarray("scale"), varray()); @@ -1943,6 +1951,7 @@ static void _register_variant_builtin_methods() { bind_method(AABB, has_surface, sarray(), varray()); bind_method(AABB, has_point, sarray("point"), varray()); bind_method(AABB, is_equal_approx, sarray("aabb"), varray()); + bind_method(AABB, is_finite, sarray(), varray()); bind_method(AABB, intersects, sarray("with"), varray()); bind_method(AABB, encloses, sarray("with"), varray()); bind_method(AABB, intersects_plane, sarray("plane"), varray()); @@ -1975,6 +1984,7 @@ static void _register_variant_builtin_methods() { bind_method(Transform3D, looking_at, sarray("target", "up"), varray(Vector3(0, 1, 0))); bind_method(Transform3D, interpolate_with, sarray("xform", "weight"), varray()); bind_method(Transform3D, is_equal_approx, sarray("xform"), varray()); + bind_method(Transform3D, is_finite, sarray(), varray()); /* Projection */ diff --git a/core/variant/variant_destruct.cpp b/core/variant/variant_destruct.cpp index ab8303f3ae..5117c33e2b 100644 --- a/core/variant/variant_destruct.cpp +++ b/core/variant/variant_destruct.cpp @@ -41,13 +41,8 @@ static void add_destructor() { void Variant::_register_variant_destructors() { add_destructor<VariantDestruct<String>>(); - add_destructor<VariantDestruct<Transform2D>>(); - add_destructor<VariantDestruct<::AABB>>(); - add_destructor<VariantDestruct<Basis>>(); - add_destructor<VariantDestruct<Transform3D>>(); add_destructor<VariantDestruct<StringName>>(); add_destructor<VariantDestruct<NodePath>>(); - add_destructor<VariantDestruct<::RID>>(); add_destructor<VariantDestruct<Callable>>(); add_destructor<VariantDestruct<Signal>>(); add_destructor<VariantDestruct<Dictionary>>(); diff --git a/core/variant/variant_destruct.h b/core/variant/variant_destruct.h index 5e3478635d..2730110c0f 100644 --- a/core/variant/variant_destruct.h +++ b/core/variant/variant_destruct.h @@ -50,13 +50,8 @@ struct VariantDestruct {}; } MAKE_PTRDESTRUCT(String); -MAKE_PTRDESTRUCT(Transform2D); -MAKE_PTRDESTRUCT(AABB); -MAKE_PTRDESTRUCT(Basis); -MAKE_PTRDESTRUCT(Transform3D); MAKE_PTRDESTRUCT(StringName); MAKE_PTRDESTRUCT(NodePath); -MAKE_PTRDESTRUCT(RID); MAKE_PTRDESTRUCT(Callable); MAKE_PTRDESTRUCT(Signal); MAKE_PTRDESTRUCT(Dictionary); diff --git a/core/variant/variant_internal.h b/core/variant/variant_internal.h index 874a183d29..7ae2368fe4 100644 --- a/core/variant/variant_internal.h +++ b/core/variant/variant_internal.h @@ -1047,7 +1047,7 @@ struct VariantInternalAccessor<PackedColorArray> { template <> struct VariantInternalAccessor<Object *> { static _FORCE_INLINE_ Object *get(const Variant *v) { return const_cast<Object *>(*VariantInternal::get_object(v)); } - static _FORCE_INLINE_ void set(Variant *v, const Object *p_value) { *VariantInternal::get_object(v) = const_cast<Object *>(p_value); } + static _FORCE_INLINE_ void set(Variant *v, const Object *p_value) { VariantInternal::object_assign(v, p_value); } }; template <> @@ -1532,27 +1532,4 @@ struct VariantTypeConstructor { } }; -template <> -struct VariantTypeConstructor<Object *> { - _FORCE_INLINE_ static void variant_from_type(void *p_variant, void *p_value) { - Variant *variant = reinterpret_cast<Variant *>(p_variant); - VariantInitializer<Object *>::init(variant); - Object *object = *(reinterpret_cast<Object **>(p_value)); - if (object) { - if (object->is_ref_counted()) { - if (!VariantInternal::initialize_ref(object)) { - return; - } - } - VariantInternalAccessor<Object *>::set(variant, object); - VariantInternalAccessor<ObjectID>::set(variant, object->get_instance_id()); - } - } - - _FORCE_INLINE_ static void type_from_variant(void *p_value, void *p_variant) { - Object **value = reinterpret_cast<Object **>(p_value); - *value = VariantInternalAccessor<Object *>::get(reinterpret_cast<Variant *>(p_variant)); - } -}; - #endif // VARIANT_INTERNAL_H diff --git a/core/variant/variant_utility.cpp b/core/variant/variant_utility.cpp index 670b66d53e..3843c32bcc 100644 --- a/core/variant/variant_utility.cpp +++ b/core/variant/variant_utility.cpp @@ -310,6 +310,10 @@ struct VariantUtilityFunctions { return Math::is_zero_approx(x); } + static inline bool is_finite(double x) { + return Math::is_finite(x); + } + static inline double ease(float x, float curve) { return Math::ease(x, curve); } @@ -1420,6 +1424,7 @@ void Variant::_register_variant_utility_functions() { FUNCBINDR(is_equal_approx, sarray("a", "b"), Variant::UTILITY_FUNC_TYPE_MATH); FUNCBINDR(is_zero_approx, sarray("x"), Variant::UTILITY_FUNC_TYPE_MATH); + FUNCBINDR(is_finite, sarray("x"), Variant::UTILITY_FUNC_TYPE_MATH); FUNCBINDR(ease, sarray("x", "curve"), Variant::UTILITY_FUNC_TYPE_MATH); FUNCBINDR(step_decimals, sarray("x"), Variant::UTILITY_FUNC_TYPE_MATH); |