diff options
Diffstat (limited to 'core')
95 files changed, 1542 insertions, 925 deletions
diff --git a/core/config/project_settings.cpp b/core/config/project_settings.cpp index 001a351e0b..473e4a0a89 100644 --- a/core/config/project_settings.cpp +++ b/core/config/project_settings.cpp @@ -82,7 +82,7 @@ String ProjectSettings::get_imported_files_path() const { // Returns the features that a project must have when opened with this build of Godot. // This is used by the project manager to provide the initial_settings for config/features. const PackedStringArray ProjectSettings::get_required_features() { - PackedStringArray features = PackedStringArray(); + PackedStringArray features; features.append(VERSION_BRANCH); #ifdef REAL_T_IS_DOUBLE features.append("Double Precision"); @@ -115,7 +115,7 @@ const PackedStringArray ProjectSettings::_get_supported_features() { // Returns the features that this project needs but this build of Godot lacks. const PackedStringArray ProjectSettings::get_unsupported_features(const PackedStringArray &p_project_features) { - PackedStringArray unsupported_features = PackedStringArray(); + PackedStringArray unsupported_features; PackedStringArray supported_features = singleton->_get_supported_features(); for (int i = 0; i < p_project_features.size(); i++) { if (!supported_features.has(p_project_features[i])) { @@ -153,8 +153,23 @@ const PackedStringArray ProjectSettings::_trim_to_supported_features(const Packe #endif // TOOLS_ENABLED String ProjectSettings::localize_path(const String &p_path) const { - if (resource_path.is_empty() || p_path.begins_with("res://") || p_path.begins_with("user://") || - (p_path.is_absolute_path() && !p_path.begins_with(resource_path))) { + if (resource_path.is_empty() || (p_path.is_absolute_path() && !p_path.begins_with(resource_path))) { + return p_path.simplify_path(); + } + + // Check if we have a special path (like res://) or a protocol identifier. + int p = p_path.find("://"); + bool found = false; + if (p > 0) { + found = true; + for (int i = 0; i < p; i++) { + if (!is_ascii_alphanumeric_char(p_path[i])) { + found = false; + break; + } + } + } + if (found) { return p_path.simplify_path(); } @@ -604,7 +619,7 @@ Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, b Error ProjectSettings::setup(const String &p_path, const String &p_main_pack, bool p_upwards, bool p_ignore_override) { Error err = _setup(p_path, p_main_pack, p_upwards, p_ignore_override); if (err == OK) { - String custom_settings = GLOBAL_DEF("application/config/project_settings_override", ""); + String custom_settings = GLOBAL_GET("application/config/project_settings_override"); if (!custom_settings.is_empty()) { _load_settings_text(custom_settings); } @@ -1022,7 +1037,7 @@ Variant _GLOBAL_DEF(const String &p_var, const Variant &p_default, bool p_restar if (!ProjectSettings::get_singleton()->has_setting(p_var)) { ProjectSettings::get_singleton()->set(p_var, p_default); } - ret = ProjectSettings::get_singleton()->get(p_var); + ret = GLOBAL_GET(p_var); ProjectSettings::get_singleton()->set_initial_value(p_var, p_default); ProjectSettings::get_singleton()->set_builtin_order(p_var); @@ -1236,7 +1251,7 @@ ProjectSettings::ProjectSettings() { GLOBAL_DEF_RST("audio/general/3d_panning_strength", 1.0f); custom_prop_info["audio/general/3d_panning_strength"] = PropertyInfo(Variant::FLOAT, "audio/general/3d_panning_strength", PROPERTY_HINT_RANGE, "0,4,0.01"); - PackedStringArray extensions = PackedStringArray(); + PackedStringArray extensions; extensions.push_back("gd"); if (Engine::get_singleton()->has_singleton("GodotSharp")) { extensions.push_back("cs"); @@ -1261,6 +1276,7 @@ ProjectSettings::ProjectSettings() { GLOBAL_DEF("physics/2d/run_on_separate_thread", false); GLOBAL_DEF("physics/3d/run_on_separate_thread", false); + GLOBAL_DEF("debug/disable_touch", false); GLOBAL_DEF("debug/settings/profiler/max_functions", 16384); custom_prop_info["debug/settings/profiler/max_functions"] = PropertyInfo(Variant::INT, "debug/settings/profiler/max_functions", PROPERTY_HINT_RANGE, "128,65535,1"); @@ -1277,6 +1293,22 @@ ProjectSettings::ProjectSettings() { GLOBAL_DEF("compression/formats/gzip/compression_level", Compression::gzip_level); custom_prop_info["compression/formats/gzip/compression_level"] = PropertyInfo(Variant::INT, "compression/formats/gzip/compression_level", PROPERTY_HINT_RANGE, "-1,9,1"); + GLOBAL_DEF("debug/settings/crash_handler/message", + String("Please include this when reporting the bug to the project developer.")); + GLOBAL_DEF("debug/settings/crash_handler/message.editor", + String("Please include this when reporting the bug on: https://github.com/godotengine/godot/issues")); + GLOBAL_DEF_RST("rendering/occlusion_culling/bvh_build_quality", 2); + GLOBAL_DEF("memory/limits/multithreaded_server/rid_pool_prealloc", 60); + GLOBAL_DEF_RST("internationalization/rendering/force_right_to_left_layout_direction", false); + + GLOBAL_DEF("gui/timers/incremental_search_max_interval_msec", 2000); + ProjectSettings::get_singleton()->set_custom_property_info("gui/timers/incremental_search_max_interval_msec", PropertyInfo(Variant::INT, "gui/timers/incremental_search_max_interval_msec", PROPERTY_HINT_RANGE, "0,10000,1,or_greater")); // No negative numbers. + + GLOBAL_DEF("rendering/rendering_device/staging_buffer/block_size_kb", 256); + GLOBAL_DEF("rendering/rendering_device/staging_buffer/max_size_mb", 128); + GLOBAL_DEF("rendering/rendering_device/staging_buffer/texture_upload_region_size_px", 64); + GLOBAL_DEF("rendering/rendering_device/vulkan/max_descriptors_per_pool", 64); + // These properties will not show up in the dialog nor in the documentation. If you want to exclude whole groups, see _get_property_list() method. GLOBAL_DEF_INTERNAL("application/config/features", PackedStringArray()); GLOBAL_DEF_INTERNAL("internationalization/locale/translation_remaps", PackedStringArray()); diff --git a/core/core_bind.cpp b/core/core_bind.cpp index 5c4ed9e483..1fe34cb4fd 100644 --- a/core/core_bind.cpp +++ b/core/core_bind.cpp @@ -334,6 +334,10 @@ String OS::get_version() const { return ::OS::get_singleton()->get_version(); } +Vector<String> OS::get_video_adapter_driver_info() const { + return ::OS::get_singleton()->get_video_adapter_driver_info(); +} + Vector<String> OS::get_cmdline_args() { List<String> cmdline = ::OS::get_singleton()->get_cmdline_args(); Vector<String> cmdlinev; @@ -549,6 +553,8 @@ void OS::_bind_methods() { ClassDB::bind_method(D_METHOD("get_cmdline_args"), &OS::get_cmdline_args); ClassDB::bind_method(D_METHOD("get_cmdline_user_args"), &OS::get_cmdline_user_args); + ClassDB::bind_method(D_METHOD("get_video_adapter_driver_info"), &OS::get_video_adapter_driver_info); + ClassDB::bind_method(D_METHOD("set_restart_on_exit", "restart", "arguments"), &OS::set_restart_on_exit, DEFVAL(Vector<String>())); ClassDB::bind_method(D_METHOD("is_restart_on_exit_set"), &OS::is_restart_on_exit_set); ClassDB::bind_method(D_METHOD("get_restart_on_exit_arguments"), &OS::get_restart_on_exit_arguments); @@ -599,8 +605,8 @@ void OS::_bind_methods() { ADD_PROPERTY_DEFAULT("low_processor_usage_mode", false); ADD_PROPERTY_DEFAULT("low_processor_usage_mode_sleep_usec", 6900); - BIND_ENUM_CONSTANT(VIDEO_DRIVER_VULKAN); - BIND_ENUM_CONSTANT(VIDEO_DRIVER_OPENGL_3); + BIND_ENUM_CONSTANT(RENDERING_DRIVER_VULKAN); + BIND_ENUM_CONSTANT(RENDERING_DRIVER_OPENGL3); BIND_ENUM_CONSTANT(DAY_SUNDAY); BIND_ENUM_CONSTANT(DAY_MONDAY); diff --git a/core/core_bind.h b/core/core_bind.h index 5c7702be0b..748ecb4929 100644 --- a/core/core_bind.h +++ b/core/core_bind.h @@ -124,9 +124,9 @@ protected: static OS *singleton; public: - enum VideoDriver { - VIDEO_DRIVER_VULKAN, - VIDEO_DRIVER_OPENGL_3, + enum RenderingDriver { + RENDERING_DRIVER_VULKAN, + RENDERING_DRIVER_OPENGL3, }; enum Weekday { @@ -196,6 +196,8 @@ public: Vector<String> get_cmdline_args(); Vector<String> get_cmdline_user_args(); + Vector<String> get_video_adapter_driver_info() const; + String get_locale() const; String get_locale_language() const; @@ -579,7 +581,7 @@ VARIANT_ENUM_CAST(core_bind::ResourceLoader::CacheMode); VARIANT_BITFIELD_CAST(core_bind::ResourceSaver::SaverFlags); -VARIANT_ENUM_CAST(core_bind::OS::VideoDriver); +VARIANT_ENUM_CAST(core_bind::OS::RenderingDriver); VARIANT_ENUM_CAST(core_bind::OS::Weekday); VARIANT_ENUM_CAST(core_bind::OS::Month); VARIANT_ENUM_CAST(core_bind::OS::SystemDir); diff --git a/core/core_constants.cpp b/core/core_constants.cpp index c784d87c87..0e8532a327 100644 --- a/core/core_constants.cpp +++ b/core/core_constants.cpp @@ -167,6 +167,13 @@ void register_global_constants() { BIND_CORE_ENUM_CONSTANT(INLINE_ALIGNMENT_IMAGE_MASK); BIND_CORE_ENUM_CONSTANT(INLINE_ALIGNMENT_TEXT_MASK); + BIND_CORE_ENUM_CLASS_CONSTANT(EulerOrder, EULER_ORDER, XYZ); + BIND_CORE_ENUM_CLASS_CONSTANT(EulerOrder, EULER_ORDER, XZY); + BIND_CORE_ENUM_CLASS_CONSTANT(EulerOrder, EULER_ORDER, YXZ); + BIND_CORE_ENUM_CLASS_CONSTANT(EulerOrder, EULER_ORDER, YZX); + BIND_CORE_ENUM_CLASS_CONSTANT(EulerOrder, EULER_ORDER, ZXY); + BIND_CORE_ENUM_CLASS_CONSTANT(EulerOrder, EULER_ORDER, ZYX); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, NONE); BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, SPECIAL); BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ESCAPE); diff --git a/core/debugger/remote_debugger.cpp b/core/debugger/remote_debugger.cpp index 23ee977df4..a2e3fab82c 100644 --- a/core/debugger/remote_debugger.cpp +++ b/core/debugger/remote_debugger.cpp @@ -39,89 +39,6 @@ #include "core/object/script_language.h" #include "core/os/os.h" -class RemoteDebugger::MultiplayerProfiler : public EngineProfiler { - struct BandwidthFrame { - uint32_t timestamp; - int packet_size; - }; - - int bandwidth_in_ptr = 0; - Vector<BandwidthFrame> bandwidth_in; - int bandwidth_out_ptr = 0; - Vector<BandwidthFrame> bandwidth_out; - uint64_t last_bandwidth_time = 0; - - int bandwidth_usage(const Vector<BandwidthFrame> &p_buffer, int p_pointer) { - ERR_FAIL_COND_V(p_buffer.size() == 0, 0); - int total_bandwidth = 0; - - uint64_t timestamp = OS::get_singleton()->get_ticks_msec(); - uint64_t final_timestamp = timestamp - 1000; - - int i = (p_pointer + p_buffer.size() - 1) % p_buffer.size(); - - while (i != p_pointer && p_buffer[i].packet_size > 0) { - if (p_buffer[i].timestamp < final_timestamp) { - return total_bandwidth; - } - total_bandwidth += p_buffer[i].packet_size; - i = (i + p_buffer.size() - 1) % p_buffer.size(); - } - - ERR_FAIL_COND_V_MSG(i == p_pointer, total_bandwidth, "Reached the end of the bandwidth profiler buffer, values might be inaccurate."); - return total_bandwidth; - } - -public: - void toggle(bool p_enable, const Array &p_opts) { - if (!p_enable) { - bandwidth_in.clear(); - bandwidth_out.clear(); - } else { - bandwidth_in_ptr = 0; - bandwidth_in.resize(16384); // ~128kB - for (int i = 0; i < bandwidth_in.size(); ++i) { - bandwidth_in.write[i].packet_size = -1; - } - bandwidth_out_ptr = 0; - bandwidth_out.resize(16384); // ~128kB - for (int i = 0; i < bandwidth_out.size(); ++i) { - bandwidth_out.write[i].packet_size = -1; - } - } - } - - void add(const Array &p_data) { - ERR_FAIL_COND(p_data.size() < 3); - const String inout = p_data[0]; - int time = p_data[1]; - int size = p_data[2]; - if (inout == "in") { - bandwidth_in.write[bandwidth_in_ptr].timestamp = time; - bandwidth_in.write[bandwidth_in_ptr].packet_size = size; - bandwidth_in_ptr = (bandwidth_in_ptr + 1) % bandwidth_in.size(); - } else if (inout == "out") { - bandwidth_out.write[bandwidth_out_ptr].timestamp = time; - bandwidth_out.write[bandwidth_out_ptr].packet_size = size; - bandwidth_out_ptr = (bandwidth_out_ptr + 1) % bandwidth_out.size(); - } - } - - void tick(double p_frame_time, double p_process_time, double p_physics_time, double p_physics_frame_time) { - uint64_t pt = OS::get_singleton()->get_ticks_msec(); - if (pt - last_bandwidth_time > 200) { - last_bandwidth_time = pt; - int incoming_bandwidth = bandwidth_usage(bandwidth_in, bandwidth_in_ptr); - int outgoing_bandwidth = bandwidth_usage(bandwidth_out, bandwidth_out_ptr); - - Array arr; - arr.push_back(incoming_bandwidth); - arr.push_back(outgoing_bandwidth); - EngineDebugger::get_singleton()->send_message("multiplayer:bandwidth", arr); - } - } -}; - class RemoteDebugger::PerformanceProfiler : public EngineProfiler { Object *performance = nullptr; int last_perf_time = 0; @@ -659,10 +576,6 @@ RemoteDebugger::RemoteDebugger(Ref<RemoteDebuggerPeer> p_peer) { max_errors_per_second = GLOBAL_GET("network/limits/debugger/max_errors_per_second"); max_warnings_per_second = GLOBAL_GET("network/limits/debugger/max_warnings_per_second"); - // Multiplayer Profiler - multiplayer_profiler.instantiate(); - multiplayer_profiler->bind("multiplayer"); - // Performance Profiler Object *perf = Engine::get_singleton()->get_singleton_object("Performance"); if (perf) { diff --git a/core/debugger/remote_debugger.h b/core/debugger/remote_debugger.h index fe4bbe86ea..944229d361 100644 --- a/core/debugger/remote_debugger.h +++ b/core/debugger/remote_debugger.h @@ -50,10 +50,8 @@ public: private: typedef DebuggerMarshalls::OutputError ErrorMessage; - class MultiplayerProfiler; class PerformanceProfiler; - Ref<MultiplayerProfiler> multiplayer_profiler; Ref<PerformanceProfiler> performance_profiler; Ref<RemoteDebuggerPeer> peer; 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/SCsub b/core/extension/SCsub index 23727c1b76..a8f68a1533 100644 --- a/core/extension/SCsub +++ b/core/extension/SCsub @@ -3,10 +3,15 @@ Import("env") import make_wrappers +import make_interface_dumper from platform_methods import run_in_subprocess env.CommandNoCache(["ext_wrappers.gen.inc"], "make_wrappers.py", run_in_subprocess(make_wrappers.run)) - +env.CommandNoCache( + "gdnative_interface_dump.gen.h", + ["gdnative_interface.h", "make_interface_dumper.py"], + run_in_subprocess(make_interface_dumper.run), +) env_extension = env.Clone() diff --git a/core/extension/extension_api_dump.cpp b/core/extension/extension_api_dump.cpp index e6e0fff266..a2c507e350 100644 --- a/core/extension/extension_api_dump.cpp +++ b/core/extension/extension_api_dump.cpp @@ -29,6 +29,7 @@ /*************************************************************************/ #include "extension_api_dump.h" + #include "core/config/engine.h" #include "core/core_constants.h" #include "core/io/file_access.h" @@ -38,7 +39,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 +79,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 +439,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 +469,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 +483,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 +500,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 +551,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 +587,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 +619,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 +747,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 +790,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 +837,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 +869,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); @@ -933,9 +939,9 @@ void NativeExtensionAPIDump::generate_extension_json_file(const String &p_path) Ref<JSON> json; json.instantiate(); - String text = json->stringify(api, "\t", false); + String text = json->stringify(api, "\t", false) + "\n"; Ref<FileAccess> fa = FileAccess::open(p_path, FileAccess::WRITE); - CharString cs = text.ascii(); - fa->store_buffer((const uint8_t *)cs.ptr(), cs.length()); + fa->store_string(text); } -#endif + +#endif // TOOLS_ENABLED diff --git a/core/extension/gdnative_interface.cpp b/core/extension/gdnative_interface.cpp index 193fcb8916..864f2fa86b 100644 --- a/core/extension/gdnative_interface.cpp +++ b/core/extension/gdnative_interface.cpp @@ -61,8 +61,9 @@ static void gdnative_print_script_error(const char *p_description, const char *p _err_print_error(p_function, p_file, p_line, p_description, false, ERR_HANDLER_SCRIPT); } -uint64_t gdnative_get_native_struct_size(const char *p_name) { - return ClassDB::get_native_struct_size(p_name); +uint64_t gdnative_get_native_struct_size(const GDNativeStringNamePtr p_name) { + const StringName name = *reinterpret_cast<const StringName *>(p_name); + return ClassDB::get_native_struct_size(name); } // Variant functions @@ -81,11 +82,11 @@ static void gdnative_variant_destroy(GDNativeVariantPtr p_self) { static void gdnative_variant_call(GDNativeVariantPtr p_self, const GDNativeStringNamePtr p_method, const GDNativeVariantPtr *p_args, const GDNativeInt p_argcount, GDNativeVariantPtr r_return, GDNativeCallError *r_error) { Variant *self = (Variant *)p_self; - const StringName *method = (const StringName *)p_method; + const StringName method = *reinterpret_cast<const StringName *>(p_method); const Variant **args = (const Variant **)p_args; Variant ret; Callable::CallError error; - self->callp(*method, args, p_argcount, ret, error); + self->callp(method, args, p_argcount, ret, error); memnew_placement(r_return, Variant(ret)); if (r_error) { @@ -97,11 +98,11 @@ static void gdnative_variant_call(GDNativeVariantPtr p_self, const GDNativeStrin static void gdnative_variant_call_static(GDNativeVariantType p_type, const GDNativeStringNamePtr p_method, const GDNativeVariantPtr *p_args, const GDNativeInt p_argcount, GDNativeVariantPtr r_return, GDNativeCallError *r_error) { Variant::Type type = (Variant::Type)p_type; - const StringName *method = (const StringName *)p_method; + const StringName method = *reinterpret_cast<const StringName *>(p_method); const Variant **args = (const Variant **)p_args; Variant ret; Callable::CallError error; - Variant::call_static(type, *method, args, p_argcount, ret, error); + Variant::call_static(type, method, args, p_argcount, ret, error); memnew_placement(r_return, Variant(ret)); if (r_error) { @@ -469,11 +470,11 @@ static GDNativeTypeFromVariantConstructorFunc gdnative_get_type_from_variant_con static GDNativePtrOperatorEvaluator gdnative_variant_get_ptr_operator_evaluator(GDNativeVariantOperator p_operator, GDNativeVariantType p_type_a, GDNativeVariantType p_type_b) { return (GDNativePtrOperatorEvaluator)Variant::get_ptr_operator_evaluator(Variant::Operator(p_operator), Variant::Type(p_type_a), Variant::Type(p_type_b)); } -static GDNativePtrBuiltInMethod gdnative_variant_get_ptr_builtin_method(GDNativeVariantType p_type, const char *p_method, GDNativeInt p_hash) { - StringName method = p_method; +static GDNativePtrBuiltInMethod gdnative_variant_get_ptr_builtin_method(GDNativeVariantType p_type, const GDNativeStringNamePtr p_method, GDNativeInt p_hash) { + const StringName method = *reinterpret_cast<const StringName *>(p_method); uint32_t hash = Variant::get_builtin_method_hash(Variant::Type(p_type), method); if (hash != p_hash) { - ERR_PRINT_ONCE("Error getting method " + String(method) + ", hash mismatch."); + ERR_PRINT_ONCE("Error getting method " + method + ", hash mismatch."); return nullptr; } @@ -497,11 +498,13 @@ static void gdnative_variant_construct(GDNativeVariantType p_type, GDNativeVaria r_error->expected = error.expected; } } -static GDNativePtrSetter gdnative_variant_get_ptr_setter(GDNativeVariantType p_type, const char *p_member) { - return (GDNativePtrSetter)Variant::get_member_ptr_setter(Variant::Type(p_type), p_member); +static GDNativePtrSetter gdnative_variant_get_ptr_setter(GDNativeVariantType p_type, const GDNativeStringNamePtr p_member) { + const StringName member = *reinterpret_cast<const StringName *>(p_member); + return (GDNativePtrSetter)Variant::get_member_ptr_setter(Variant::Type(p_type), member); } -static GDNativePtrGetter gdnative_variant_get_ptr_getter(GDNativeVariantType p_type, const char *p_member) { - return (GDNativePtrGetter)Variant::get_member_ptr_getter(Variant::Type(p_type), p_member); +static GDNativePtrGetter gdnative_variant_get_ptr_getter(GDNativeVariantType p_type, const GDNativeStringNamePtr p_member) { + const StringName member = *reinterpret_cast<const StringName *>(p_member); + return (GDNativePtrGetter)Variant::get_member_ptr_getter(Variant::Type(p_type), member); } static GDNativePtrIndexedSetter gdnative_variant_get_ptr_indexed_setter(GDNativeVariantType p_type) { return (GDNativePtrIndexedSetter)Variant::get_member_ptr_indexed_setter(Variant::Type(p_type)); @@ -518,14 +521,15 @@ static GDNativePtrKeyedGetter gdnative_variant_get_ptr_keyed_getter(GDNativeVari static GDNativePtrKeyedChecker gdnative_variant_get_ptr_keyed_checker(GDNativeVariantType p_type) { return (GDNativePtrKeyedChecker)Variant::get_member_ptr_keyed_checker(Variant::Type(p_type)); } -static void gdnative_variant_get_constant_value(GDNativeVariantType p_type, const char *p_constant, GDNativeVariantPtr r_ret) { - memnew_placement(r_ret, Variant(Variant::get_constant_value(Variant::Type(p_type), p_constant))); +static void gdnative_variant_get_constant_value(GDNativeVariantType p_type, const GDNativeStringNamePtr p_constant, GDNativeVariantPtr r_ret) { + StringName constant = *reinterpret_cast<const StringName *>(p_constant); + memnew_placement(r_ret, Variant(Variant::get_constant_value(Variant::Type(p_type), constant))); } -static GDNativePtrUtilityFunction gdnative_variant_get_ptr_utility_function(const char *p_function, GDNativeInt p_hash) { - StringName function = p_function; +static GDNativePtrUtilityFunction gdnative_variant_get_ptr_utility_function(const GDNativeStringNamePtr p_function, GDNativeInt p_hash) { + StringName function = *reinterpret_cast<const StringName *>(p_function); uint32_t hash = Variant::get_utility_function_hash(function); if (hash != p_hash) { - ERR_PRINT_ONCE("Error getting utility function " + String(function) + ", hash mismatch."); + ERR_PRINT_ONCE("Error getting utility function " + function + ", hash mismatch."); return nullptr; } return (GDNativePtrUtilityFunction)Variant::get_ptr_utility_function(function); @@ -836,8 +840,9 @@ static void gdnative_object_destroy(GDNativeObjectPtr p_o) { memdelete((Object *)p_o); } -static GDNativeObjectPtr gdnative_global_get_singleton(const char *p_name) { - return (GDNativeObjectPtr)Engine::get_singleton()->get_singleton_object(String(p_name)); +static GDNativeObjectPtr gdnative_global_get_singleton(const GDNativeStringNamePtr p_name) { + const StringName name = *reinterpret_cast<const StringName *>(p_name); + return (GDNativeObjectPtr)Engine::get_singleton()->get_singleton_object(name); } static void *gdnative_object_get_instance_binding(GDNativeObjectPtr p_object, void *p_token, const GDNativeInstanceBindingCallbacks *p_callbacks) { @@ -850,9 +855,10 @@ static void gdnative_object_set_instance_binding(GDNativeObjectPtr p_object, voi o->set_instance_binding(p_token, p_binding, p_callbacks); } -static void gdnative_object_set_instance(GDNativeObjectPtr p_object, const char *p_classname, GDExtensionClassInstancePtr p_instance) { +static void gdnative_object_set_instance(GDNativeObjectPtr p_object, const GDNativeStringNamePtr p_classname, GDExtensionClassInstancePtr p_instance) { + const StringName classname = *reinterpret_cast<const StringName *>(p_classname); Object *o = (Object *)p_object; - ClassDB::set_object_extension_instance(o, p_classname, p_instance); + ClassDB::set_object_extension_instance(o, classname, p_instance); } static GDNativeObjectPtr gdnative_object_get_instance_from_id(GDObjectInstanceID p_instance_id) { @@ -880,23 +886,26 @@ static GDNativeScriptInstancePtr gdnative_script_instance_create(const GDNativeE return reinterpret_cast<GDNativeScriptInstancePtr>(script_instance_extension); } -static GDNativeMethodBindPtr gdnative_classdb_get_method_bind(const char *p_classname, const char *p_methodname, GDNativeInt p_hash) { - MethodBind *mb = ClassDB::get_method(StringName(p_classname), StringName(p_methodname)); +static GDNativeMethodBindPtr gdnative_classdb_get_method_bind(const GDNativeStringNamePtr p_classname, const GDNativeStringNamePtr p_methodname, GDNativeInt p_hash) { + const StringName classname = *reinterpret_cast<const StringName *>(p_classname); + const StringName methodname = *reinterpret_cast<const StringName *>(p_methodname); + MethodBind *mb = ClassDB::get_method(classname, methodname); ERR_FAIL_COND_V(!mb, nullptr); if (mb->get_hash() != p_hash) { - ERR_PRINT("Hash mismatch for method '" + String(p_classname) + "." + String(p_methodname) + "'."); + ERR_PRINT("Hash mismatch for method '" + classname + "." + methodname + "'."); return nullptr; } - // MethodBind *mb = ClassDB::get_method("Node", "get_name"); return (GDNativeMethodBindPtr)mb; } -static GDNativeObjectPtr gdnative_classdb_construct_object(const char *p_classname) { - return (GDNativeObjectPtr)ClassDB::instantiate(p_classname); +static GDNativeObjectPtr gdnative_classdb_construct_object(const GDNativeStringNamePtr p_classname) { + const StringName classname = *reinterpret_cast<const StringName *>(p_classname); + return (GDNativeObjectPtr)ClassDB::instantiate(classname); } -static void *gdnative_classdb_get_class_tag(const char *p_classname) { - ClassDB::ClassInfo *class_info = ClassDB::classes.getptr(p_classname); +static void *gdnative_classdb_get_class_tag(const GDNativeStringNamePtr p_classname) { + const StringName classname = *reinterpret_cast<const StringName *>(p_classname); + ClassDB::ClassInfo *class_info = ClassDB::classes.getptr(classname); return class_info ? class_info->class_ptr : nullptr; } diff --git a/core/extension/gdnative_interface.h b/core/extension/gdnative_interface.h index 39378d8261..a361e40096 100644 --- a/core/extension/gdnative_interface.h +++ b/core/extension/gdnative_interface.h @@ -201,22 +201,22 @@ typedef GDNativeBool (*GDNativeExtensionClassGet)(GDExtensionClassInstancePtr p_ typedef uint64_t (*GDNativeExtensionClassGetRID)(GDExtensionClassInstancePtr p_instance); typedef struct { - uint32_t type; - const char *name; - const char *class_name; - uint32_t hint; - const char *hint_string; - uint32_t usage; + GDNativeVariantType type; + GDNativeStringNamePtr name; + GDNativeStringNamePtr class_name; + uint32_t hint; // Bitfield of `PropertyHint` (defined in `extension_api.json`) + GDNativeStringPtr hint_string; + uint32_t usage; // Bitfield of `PropertyUsageFlags` (defined in `extension_api.json`) } GDNativePropertyInfo; typedef struct { - const char *name; + GDNativeStringNamePtr name; GDNativePropertyInfo return_value; - uint32_t flags; // From GDNativeExtensionClassMethodFlags + uint32_t flags; // Bitfield of `GDNativeExtensionClassMethodFlags` int32_t id; - GDNativePropertyInfo *arguments; + GDNativePropertyInfo *arguments; // array of `argument_count` size uint32_t argument_count; - GDNativeVariantPtr default_arguments; + GDNativeVariantPtr *default_arguments; // array of `default_argument_count` size uint32_t default_argument_count; } GDNativeMethodInfo; @@ -225,16 +225,17 @@ typedef void (*GDNativeExtensionClassFreePropertyList)(GDExtensionClassInstanceP typedef GDNativeBool (*GDNativeExtensionClassPropertyCanRevert)(GDExtensionClassInstancePtr p_instance, const GDNativeStringNamePtr p_name); typedef GDNativeBool (*GDNativeExtensionClassPropertyGetRevert)(GDExtensionClassInstancePtr p_instance, const GDNativeStringNamePtr p_name, GDNativeVariantPtr r_ret); typedef void (*GDNativeExtensionClassNotification)(GDExtensionClassInstancePtr p_instance, int32_t p_what); -typedef void (*GDNativeExtensionClassToString)(GDExtensionClassInstancePtr p_instance, GDNativeStringPtr p_out); +typedef void (*GDNativeExtensionClassToString)(GDExtensionClassInstancePtr p_instance, GDNativeBool *r_is_valid, GDNativeStringPtr p_out); typedef void (*GDNativeExtensionClassReference)(GDExtensionClassInstancePtr p_instance); typedef void (*GDNativeExtensionClassUnreference)(GDExtensionClassInstancePtr p_instance); 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 GDNativeExtensionClassCallVirtual (*GDNativeExtensionClassGetVirtual)(void *p_userdata, const GDNativeStringNamePtr p_name); typedef struct { + GDNativeBool is_virtual; + GDNativeBool is_abstract; GDNativeExtensionClassSet set_func; GDNativeExtensionClassGet get_func; GDNativeExtensionClassGetPropertyList get_property_list_func; @@ -283,24 +284,21 @@ typedef enum { typedef void (*GDNativeExtensionClassMethodCall)(void *method_userdata, GDExtensionClassInstancePtr p_instance, const GDNativeVariantPtr *p_args, const GDNativeInt p_argument_count, GDNativeVariantPtr r_return, GDNativeCallError *r_error); typedef void (*GDNativeExtensionClassMethodPtrCall)(void *method_userdata, GDExtensionClassInstancePtr p_instance, const GDNativeTypePtr *p_args, GDNativeTypePtr r_ret); -/* passing -1 as argument in the following functions refers to the return type */ -typedef GDNativeVariantType (*GDNativeExtensionClassMethodGetArgumentType)(void *p_method_userdata, int32_t p_argument); -typedef void (*GDNativeExtensionClassMethodGetArgumentInfo)(void *p_method_userdata, int32_t p_argument, GDNativePropertyInfo *r_info); -typedef GDNativeExtensionClassMethodArgumentMetadata (*GDNativeExtensionClassMethodGetArgumentMetadata)(void *p_method_userdata, int32_t p_argument); - typedef struct { - const char *name; + GDNativeStringNamePtr name; void *method_userdata; GDNativeExtensionClassMethodCall call_func; GDNativeExtensionClassMethodPtrCall ptrcall_func; - uint32_t method_flags; /* GDNativeExtensionClassMethodFlags */ + uint32_t method_flags; // Bitfield of `GDNativeExtensionClassMethodFlags` uint32_t argument_count; GDNativeBool has_return_value; - GDNativeExtensionClassMethodGetArgumentType get_argument_type_func; - GDNativeExtensionClassMethodGetArgumentInfo get_argument_info_func; /* name and hint information for the argument can be omitted in release builds. Class name should always be present if it applies. */ - GDNativeExtensionClassMethodGetArgumentMetadata get_argument_metadata_func; + GDNativePropertyInfo *return_value_info; // Ignored if `has_return_value` is false + GDNativeExtensionClassMethodArgumentMetadata return_value_metadata; // Ignored if `has_return_value` is false + /* name and hint information for the argument can be omitted in release builds. Class name should always be present if it applies. */ + GDNativePropertyInfo *aguments_info; // array of `argument_count` size + GDNativeExtensionClassMethodArgumentMetadata *aguments_metadata; // array of `argument_count` size uint32_t default_argument_count; - GDNativeVariantPtr *default_arguments; + GDNativeVariantPtr *default_arguments; // array of `default_argument_count` size } GDNativeExtensionClassMethodInfo; /* SCRIPT INSTANCE EXTENSION */ @@ -327,7 +325,7 @@ typedef GDNativeBool (*GDNativeExtensionScriptInstanceHasMethod)(GDNativeExtensi typedef void (*GDNativeExtensionScriptInstanceCall)(GDNativeExtensionScriptInstanceDataPtr p_self, const GDNativeStringNamePtr p_method, const GDNativeVariantPtr *p_args, const GDNativeInt p_argument_count, GDNativeVariantPtr r_return, GDNativeCallError *r_error); typedef void (*GDNativeExtensionScriptInstanceNotification)(GDNativeExtensionScriptInstanceDataPtr p_instance, int32_t p_what); -typedef const char *(*GDNativeExtensionScriptInstanceToString)(GDNativeExtensionScriptInstanceDataPtr p_instance, GDNativeBool *r_is_valid); +typedef void (*GDNativeExtensionScriptInstanceToString)(GDNativeExtensionScriptInstanceDataPtr p_instance, GDNativeBool *r_is_valid, GDNativeStringPtr r_out); typedef void (*GDNativeExtensionScriptInstanceRefCountIncremented)(GDNativeExtensionScriptInstanceDataPtr p_instance); typedef GDNativeBool (*GDNativeExtensionScriptInstanceRefCountDecremented)(GDNativeExtensionScriptInstanceDataPtr p_instance); @@ -348,7 +346,6 @@ typedef struct { GDNativeExtensionScriptInstanceGet get_func; GDNativeExtensionScriptInstanceGetPropertyList get_property_list_func; GDNativeExtensionScriptInstanceFreePropertyList free_property_list_func; - GDNativeExtensionScriptInstanceGetPropertyType get_property_type_func; GDNativeExtensionScriptInstancePropertyCanRevert property_can_revert_func; GDNativeExtensionScriptInstancePropertyGetRevert property_get_revert_func; @@ -358,6 +355,7 @@ typedef struct { GDNativeExtensionScriptInstanceGetMethodList get_method_list_func; GDNativeExtensionScriptInstanceFreeMethodList free_method_list_func; + GDNativeExtensionScriptInstanceGetPropertyType get_property_type_func; GDNativeExtensionScriptInstanceHasMethod has_method_func; @@ -399,7 +397,7 @@ typedef struct { void (*print_warning)(const char *p_description, const char *p_function, const char *p_file, int32_t p_line); void (*print_script_error)(const char *p_description, const char *p_function, const char *p_file, int32_t p_line); - uint64_t (*get_native_struct_size)(const char *p_name); + uint64_t (*get_native_struct_size)(const GDNativeStringNamePtr p_name); /* GODOT VARIANT */ @@ -442,19 +440,19 @@ typedef struct { GDNativeVariantFromTypeConstructorFunc (*get_variant_from_type_constructor)(GDNativeVariantType p_type); GDNativeTypeFromVariantConstructorFunc (*get_variant_to_type_constructor)(GDNativeVariantType p_type); GDNativePtrOperatorEvaluator (*variant_get_ptr_operator_evaluator)(GDNativeVariantOperator p_operator, GDNativeVariantType p_type_a, GDNativeVariantType p_type_b); - GDNativePtrBuiltInMethod (*variant_get_ptr_builtin_method)(GDNativeVariantType p_type, const char *p_method, GDNativeInt p_hash); + GDNativePtrBuiltInMethod (*variant_get_ptr_builtin_method)(GDNativeVariantType p_type, const GDNativeStringNamePtr p_method, GDNativeInt p_hash); GDNativePtrConstructor (*variant_get_ptr_constructor)(GDNativeVariantType p_type, int32_t p_constructor); GDNativePtrDestructor (*variant_get_ptr_destructor)(GDNativeVariantType p_type); void (*variant_construct)(GDNativeVariantType p_type, GDNativeVariantPtr p_base, const GDNativeVariantPtr *p_args, int32_t p_argument_count, GDNativeCallError *r_error); - GDNativePtrSetter (*variant_get_ptr_setter)(GDNativeVariantType p_type, const char *p_member); - GDNativePtrGetter (*variant_get_ptr_getter)(GDNativeVariantType p_type, const char *p_member); + GDNativePtrSetter (*variant_get_ptr_setter)(GDNativeVariantType p_type, const GDNativeStringNamePtr p_member); + GDNativePtrGetter (*variant_get_ptr_getter)(GDNativeVariantType p_type, const GDNativeStringNamePtr p_member); GDNativePtrIndexedSetter (*variant_get_ptr_indexed_setter)(GDNativeVariantType p_type); GDNativePtrIndexedGetter (*variant_get_ptr_indexed_getter)(GDNativeVariantType p_type); GDNativePtrKeyedSetter (*variant_get_ptr_keyed_setter)(GDNativeVariantType p_type); GDNativePtrKeyedGetter (*variant_get_ptr_keyed_getter)(GDNativeVariantType p_type); GDNativePtrKeyedChecker (*variant_get_ptr_keyed_checker)(GDNativeVariantType p_type); - void (*variant_get_constant_value)(GDNativeVariantType p_type, const char *p_constant, GDNativeVariantPtr r_ret); - GDNativePtrUtilityFunction (*variant_get_ptr_utility_function)(const char *p_function, GDNativeInt p_hash); + void (*variant_get_constant_value)(GDNativeVariantType p_type, const GDNativeStringNamePtr p_constant, GDNativeVariantPtr r_ret); + GDNativePtrUtilityFunction (*variant_get_ptr_utility_function)(const GDNativeStringNamePtr p_function, GDNativeInt p_hash); /* extra utilities */ @@ -523,12 +521,12 @@ typedef struct { void (*object_method_bind_call)(const GDNativeMethodBindPtr p_method_bind, GDNativeObjectPtr p_instance, const GDNativeVariantPtr *p_args, GDNativeInt p_arg_count, GDNativeVariantPtr r_ret, GDNativeCallError *r_error); void (*object_method_bind_ptrcall)(const GDNativeMethodBindPtr p_method_bind, GDNativeObjectPtr p_instance, const GDNativeTypePtr *p_args, GDNativeTypePtr r_ret); void (*object_destroy)(GDNativeObjectPtr p_o); - GDNativeObjectPtr (*global_get_singleton)(const char *p_name); + GDNativeObjectPtr (*global_get_singleton)(const GDNativeStringNamePtr p_name); void *(*object_get_instance_binding)(GDNativeObjectPtr p_o, void *p_token, const GDNativeInstanceBindingCallbacks *p_callbacks); void (*object_set_instance_binding)(GDNativeObjectPtr p_o, void *p_token, void *p_binding, const GDNativeInstanceBindingCallbacks *p_callbacks); - void (*object_set_instance)(GDNativeObjectPtr p_o, const char *p_classname, GDExtensionClassInstancePtr p_instance); /* p_classname should be a registered extension class and should extend the p_o object's class. */ + void (*object_set_instance)(GDNativeObjectPtr p_o, const GDNativeStringNamePtr p_classname, GDExtensionClassInstancePtr p_instance); /* p_classname should be a registered extension class and should extend the p_o object's class. */ GDNativeObjectPtr (*object_cast_to)(const GDNativeObjectPtr p_object, void *p_class_tag); GDNativeObjectPtr (*object_get_instance_from_id)(GDObjectInstanceID p_instance_id); @@ -539,20 +537,21 @@ typedef struct { GDNativeScriptInstancePtr (*script_instance_create)(const GDNativeExtensionScriptInstanceInfo *p_info, GDNativeExtensionScriptInstanceDataPtr p_instance_data); /* CLASSDB */ - GDNativeObjectPtr (*classdb_construct_object)(const char *p_classname); /* The passed class must be a built-in godot class, or an already-registered extension class. In both case, object_set_instance should be called to fully initialize the object. */ - GDNativeMethodBindPtr (*classdb_get_method_bind)(const char *p_classname, const char *p_methodname, GDNativeInt p_hash); - void *(*classdb_get_class_tag)(const char *p_classname); + GDNativeObjectPtr (*classdb_construct_object)(const GDNativeStringNamePtr p_classname); /* The passed class must be a built-in godot class, or an already-registered extension class. In both case, object_set_instance should be called to fully initialize the object. */ + GDNativeMethodBindPtr (*classdb_get_method_bind)(const GDNativeStringNamePtr p_classname, const GDNativeStringNamePtr p_methodname, GDNativeInt p_hash); + void *(*classdb_get_class_tag)(const GDNativeStringNamePtr p_classname); /* CLASSDB EXTENSION */ - void (*classdb_register_extension_class)(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const char *p_parent_class_name, const GDNativeExtensionClassCreationInfo *p_extension_funcs); - void (*classdb_register_extension_class_method)(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const GDNativeExtensionClassMethodInfo *p_method_info); - void (*classdb_register_extension_class_integer_constant)(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const char *p_enum_name, const char *p_constant_name, GDNativeInt p_constant_value, GDNativeBool p_is_bitfield); - void (*classdb_register_extension_class_property)(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const GDNativePropertyInfo *p_info, const char *p_setter, const char *p_getter); - void (*classdb_register_extension_class_property_group)(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const char *p_group_name, const char *p_prefix); - void (*classdb_register_extension_class_property_subgroup)(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const char *p_subgroup_name, const char *p_prefix); - void (*classdb_register_extension_class_signal)(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const char *p_signal_name, const GDNativePropertyInfo *p_argument_info, GDNativeInt p_argument_count); - void (*classdb_unregister_extension_class)(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name); /* Unregistering a parent class before a class that inherits it will result in failure. Inheritors must be unregistered first. */ + // Provided parameters for `classdb_register_extension_*` can be safely freed once the function returns + void (*classdb_register_extension_class)(const GDNativeExtensionClassLibraryPtr p_library, const GDNativeStringNamePtr p_class_name, const GDNativeStringNamePtr p_parent_class_name, const GDNativeExtensionClassCreationInfo *p_extension_funcs); + void (*classdb_register_extension_class_method)(const GDNativeExtensionClassLibraryPtr p_library, const GDNativeStringNamePtr p_class_name, const GDNativeExtensionClassMethodInfo *p_method_info); + void (*classdb_register_extension_class_integer_constant)(const GDNativeExtensionClassLibraryPtr p_library, const GDNativeStringNamePtr p_class_name, const GDNativeStringNamePtr p_enum_name, const GDNativeStringNamePtr p_constant_name, GDNativeInt p_constant_value, GDNativeBool p_is_bitfield); + void (*classdb_register_extension_class_property)(const GDNativeExtensionClassLibraryPtr p_library, const GDNativeStringNamePtr p_class_name, const GDNativePropertyInfo *p_info, const GDNativeStringNamePtr p_setter, const GDNativeStringNamePtr p_getter); + void (*classdb_register_extension_class_property_group)(const GDNativeExtensionClassLibraryPtr p_library, const GDNativeStringNamePtr p_class_name, const GDNativeStringPtr p_group_name, const GDNativeStringPtr p_prefix); + void (*classdb_register_extension_class_property_subgroup)(const GDNativeExtensionClassLibraryPtr p_library, const GDNativeStringNamePtr p_class_name, const GDNativeStringPtr p_subgroup_name, const GDNativeStringPtr p_prefix); + void (*classdb_register_extension_class_signal)(const GDNativeExtensionClassLibraryPtr p_library, const GDNativeStringNamePtr p_class_name, const GDNativeStringNamePtr p_signal_name, const GDNativePropertyInfo *p_argument_info, GDNativeInt p_argument_count); + void (*classdb_unregister_extension_class)(const GDNativeExtensionClassLibraryPtr p_library, const GDNativeStringNamePtr p_class_name); /* Unregistering a parent class before a class that inherits it will result in failure. Inheritors must be unregistered first. */ void (*get_library_path)(const GDNativeExtensionClassLibraryPtr p_library, GDNativeStringPtr r_path); diff --git a/core/extension/make_interface_dumper.py b/core/extension/make_interface_dumper.py new file mode 100644 index 0000000000..cc85c728d5 --- /dev/null +++ b/core/extension/make_interface_dumper.py @@ -0,0 +1,47 @@ +def run(target, source, env): + src = source[0] + dst = target[0] + f = open(src, "r", encoding="utf-8") + g = open(dst, "w", encoding="utf-8") + + g.write( + """/* THIS FILE IS GENERATED DO NOT EDIT */ +#ifndef GDNATIVE_INTERFACE_DUMP_H +#define GDNATIVE_INTERFACE_DUMP_H + +#ifdef TOOLS_ENABLED + +#include "core/io/file_access.h" +#include "core/string/ustring.h" + +class GDNativeInterfaceDump { + private: + static constexpr char const *gdnative_interface_dump =""" + ) + for line in f: + g.write('"' + line.rstrip().replace('"', '\\"') + '\\n"\n') + g.write(";\n") + + g.write( + """ + public: + static void generate_gdnative_interface_file(const String &p_path) { + Ref<FileAccess> fa = FileAccess::open(p_path, FileAccess::WRITE); + CharString cs(gdnative_interface_dump); + fa->store_buffer((const uint8_t *)cs.ptr(), cs.length()); + }; +}; + +#endif // TOOLS_ENABLED + +#endif // GDNATIVE_INTERFACE_DUMP_H +""" + ) + g.close() + f.close() + + +if __name__ == "__main__": + from platform_methods import subprocess_main + + subprocess_main(globals()) diff --git a/core/extension/native_extension.cpp b/core/extension/native_extension.cpp index 6418da2235..8bbb72fd82 100644 --- a/core/extension/native_extension.cpp +++ b/core/extension/native_extension.cpp @@ -42,26 +42,37 @@ String NativeExtension::get_extension_list_config_file() { class NativeExtensionMethodBind : public MethodBind { GDNativeExtensionClassMethodCall call_func; GDNativeExtensionClassMethodPtrCall ptrcall_func; - GDNativeExtensionClassMethodGetArgumentType get_argument_type_func; - GDNativeExtensionClassMethodGetArgumentInfo get_argument_info_func; - GDNativeExtensionClassMethodGetArgumentMetadata get_argument_metadata_func; void *method_userdata; bool vararg; + PropertyInfo return_value_info; + GodotTypeInfo::Metadata return_value_metadata; + List<PropertyInfo> arguments_info; + List<GodotTypeInfo::Metadata> arguments_metadata; protected: virtual Variant::Type _gen_argument_type(int p_arg) const override { - return Variant::Type(get_argument_type_func(method_userdata, p_arg)); + if (p_arg < 0) { + return return_value_info.type; + } else { + return arguments_info[p_arg].type; + } } virtual PropertyInfo _gen_argument_type_info(int p_arg) const override { - GDNativePropertyInfo pinfo; - get_argument_info_func(method_userdata, p_arg, &pinfo); - return PropertyInfo(pinfo); + if (p_arg < 0) { + return return_value_info; + } else { + return arguments_info[p_arg]; + } } public: #ifdef DEBUG_METHODS_ENABLED virtual GodotTypeInfo::Metadata get_argument_meta(int p_arg) const override { - return GodotTypeInfo::Metadata(get_argument_metadata_func(method_userdata, p_arg)); + if (p_arg < 0) { + return return_value_metadata; + } else { + return arguments_metadata[p_arg]; + } } #endif @@ -89,10 +100,17 @@ public: method_userdata = p_method_info->method_userdata; call_func = p_method_info->call_func; ptrcall_func = p_method_info->ptrcall_func; - get_argument_type_func = p_method_info->get_argument_type_func; - get_argument_info_func = p_method_info->get_argument_info_func; - get_argument_metadata_func = p_method_info->get_argument_metadata_func; - set_name(p_method_info->name); + set_name(*reinterpret_cast<StringName *>(p_method_info->name)); + + if (p_method_info->has_return_value) { + return_value_info = PropertyInfo(*p_method_info->return_value_info); + return_value_metadata = GodotTypeInfo::Metadata(p_method_info->return_value_metadata); + } + + for (uint32_t i = 0; i < p_method_info->argument_count; i++) { + arguments_info.push_back(PropertyInfo(p_method_info->aguments_info[i])); + arguments_metadata.push_back(GodotTypeInfo::Metadata(p_method_info->aguments_metadata[i])); + } set_hint_flags(p_method_info->method_flags); @@ -117,15 +135,15 @@ public: static GDNativeInterface gdnative_interface; -void NativeExtension::_register_extension_class(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const char *p_parent_class_name, const GDNativeExtensionClassCreationInfo *p_extension_funcs) { +void NativeExtension::_register_extension_class(const GDNativeExtensionClassLibraryPtr p_library, const GDNativeStringNamePtr p_class_name, const GDNativeStringNamePtr p_parent_class_name, const GDNativeExtensionClassCreationInfo *p_extension_funcs) { NativeExtension *self = static_cast<NativeExtension *>(p_library); - StringName class_name = p_class_name; + StringName class_name = *reinterpret_cast<StringName *>(p_class_name); + StringName parent_class_name = *reinterpret_cast<StringName *>(p_parent_class_name); ERR_FAIL_COND_MSG(!String(class_name).is_valid_identifier(), "Attempt to register extension class '" + class_name + "', which is not a valid class identifier."); ERR_FAIL_COND_MSG(ClassDB::class_exists(class_name), "Attempt to register extension class '" + class_name + "', which appears to be already registered."); Extension *parent_extension = nullptr; - StringName parent_class_name = p_parent_class_name; if (self->extension_classes.has(parent_class_name)) { parent_extension = &self->extension_classes[parent_class_name]; @@ -152,6 +170,8 @@ void NativeExtension::_register_extension_class(const GDNativeExtensionClassLibr extension->native_extension.parent_class_name = parent_class_name; extension->native_extension.class_name = class_name; extension->native_extension.editor_class = self->level_initialized == INITIALIZATION_LEVEL_EDITOR; + extension->native_extension.is_virtual = p_extension_funcs->is_virtual; + extension->native_extension.is_abstract = p_extension_funcs->is_abstract; extension->native_extension.set = p_extension_funcs->set_func; extension->native_extension.get = p_extension_funcs->get_func; extension->native_extension.get_property_list = p_extension_funcs->get_property_list_func; @@ -170,11 +190,11 @@ void NativeExtension::_register_extension_class(const GDNativeExtensionClassLibr ClassDB::register_extension_class(&extension->native_extension); } -void NativeExtension::_register_extension_class_method(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const GDNativeExtensionClassMethodInfo *p_method_info) { +void NativeExtension::_register_extension_class_method(const GDNativeExtensionClassLibraryPtr p_library, const GDNativeStringNamePtr p_class_name, const GDNativeExtensionClassMethodInfo *p_method_info) { NativeExtension *self = static_cast<NativeExtension *>(p_library); - StringName class_name = p_class_name; - StringName method_name = p_method_info->name; + StringName class_name = *reinterpret_cast<const StringName *>(p_class_name); + StringName method_name = *reinterpret_cast<const StringName *>(p_method_info->name); ERR_FAIL_COND_MSG(!self->extension_classes.has(class_name), "Attempt to register extension method '" + String(method_name) + "' for unexisting class '" + class_name + "'."); //Extension *extension = &self->extension_classes[class_name]; @@ -184,56 +204,63 @@ void NativeExtension::_register_extension_class_method(const GDNativeExtensionCl ClassDB::bind_method_custom(class_name, method); } -void NativeExtension::_register_extension_class_integer_constant(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const char *p_enum_name, const char *p_constant_name, GDNativeInt p_constant_value, GDNativeBool p_is_bitfield) { +void NativeExtension::_register_extension_class_integer_constant(const GDNativeExtensionClassLibraryPtr p_library, const GDNativeStringNamePtr p_class_name, const GDNativeStringNamePtr p_enum_name, const GDNativeStringNamePtr p_constant_name, GDNativeInt p_constant_value, GDNativeBool p_is_bitfield) { NativeExtension *self = static_cast<NativeExtension *>(p_library); - StringName class_name = p_class_name; - ERR_FAIL_COND_MSG(!self->extension_classes.has(class_name), "Attempt to register extension constant '" + String(p_constant_name) + "' for unexisting class '" + class_name + "'."); - - //Extension *extension = &self->extension_classes[class_name]; + StringName class_name = *reinterpret_cast<const StringName *>(p_class_name); + StringName enum_name = *reinterpret_cast<const StringName *>(p_enum_name); + StringName constant_name = *reinterpret_cast<const StringName *>(p_constant_name); + ERR_FAIL_COND_MSG(!self->extension_classes.has(class_name), "Attempt to register extension constant '" + constant_name + "' for unexisting class '" + class_name + "'."); - ClassDB::bind_integer_constant(class_name, p_enum_name, p_constant_name, p_constant_value, p_is_bitfield); + ClassDB::bind_integer_constant(class_name, enum_name, constant_name, p_constant_value, p_is_bitfield); } -void NativeExtension::_register_extension_class_property(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const GDNativePropertyInfo *p_info, const char *p_setter, const char *p_getter) { +void NativeExtension::_register_extension_class_property(const GDNativeExtensionClassLibraryPtr p_library, const GDNativeStringNamePtr p_class_name, const GDNativePropertyInfo *p_info, const GDNativeStringNamePtr p_setter, const GDNativeStringNamePtr p_getter) { NativeExtension *self = static_cast<NativeExtension *>(p_library); - StringName class_name = p_class_name; - String property_name = p_info->name; + StringName class_name = *reinterpret_cast<const StringName *>(p_class_name); + StringName setter = *reinterpret_cast<const StringName *>(p_setter); + StringName getter = *reinterpret_cast<const StringName *>(p_getter); + String property_name = *reinterpret_cast<const StringName *>(p_info->name); ERR_FAIL_COND_MSG(!self->extension_classes.has(class_name), "Attempt to register extension class property '" + property_name + "' for unexisting class '" + class_name + "'."); //Extension *extension = &self->extension_classes[class_name]; PropertyInfo pinfo(*p_info); - ClassDB::add_property(class_name, pinfo, p_setter, p_getter); + ClassDB::add_property(class_name, pinfo, setter, getter); } -void NativeExtension::_register_extension_class_property_group(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const char *p_group_name, const char *p_prefix) { +void NativeExtension::_register_extension_class_property_group(const GDNativeExtensionClassLibraryPtr p_library, const GDNativeStringNamePtr p_class_name, const GDNativeStringPtr p_group_name, const GDNativeStringPtr p_prefix) { NativeExtension *self = static_cast<NativeExtension *>(p_library); - StringName class_name = p_class_name; - ERR_FAIL_COND_MSG(!self->extension_classes.has(class_name), "Attempt to register extension class property group '" + String(p_group_name) + "' for unexisting class '" + class_name + "'."); + StringName class_name = *reinterpret_cast<const StringName *>(p_class_name); + String group_name = *reinterpret_cast<const String *>(p_group_name); + String prefix = *reinterpret_cast<const String *>(p_prefix); + ERR_FAIL_COND_MSG(!self->extension_classes.has(class_name), "Attempt to register extension class property group '" + group_name + "' for unexisting class '" + class_name + "'."); - ClassDB::add_property_group(class_name, p_group_name, p_prefix); + ClassDB::add_property_group(class_name, group_name, prefix); } -void NativeExtension::_register_extension_class_property_subgroup(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const char *p_subgroup_name, const char *p_prefix) { +void NativeExtension::_register_extension_class_property_subgroup(const GDNativeExtensionClassLibraryPtr p_library, const GDNativeStringNamePtr p_class_name, const GDNativeStringPtr p_subgroup_name, const GDNativeStringPtr p_prefix) { NativeExtension *self = static_cast<NativeExtension *>(p_library); - StringName class_name = p_class_name; - ERR_FAIL_COND_MSG(!self->extension_classes.has(class_name), "Attempt to register extension class property subgroup '" + String(p_subgroup_name) + "' for unexisting class '" + class_name + "'."); + StringName class_name = *reinterpret_cast<const StringName *>(p_class_name); + String subgroup_name = *reinterpret_cast<const String *>(p_subgroup_name); + String prefix = *reinterpret_cast<const String *>(p_prefix); + ERR_FAIL_COND_MSG(!self->extension_classes.has(class_name), "Attempt to register extension class property subgroup '" + subgroup_name + "' for unexisting class '" + class_name + "'."); - ClassDB::add_property_subgroup(class_name, p_subgroup_name, p_prefix); + ClassDB::add_property_subgroup(class_name, subgroup_name, prefix); } -void NativeExtension::_register_extension_class_signal(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const char *p_signal_name, const GDNativePropertyInfo *p_argument_info, GDNativeInt p_argument_count) { +void NativeExtension::_register_extension_class_signal(const GDNativeExtensionClassLibraryPtr p_library, const GDNativeStringNamePtr p_class_name, const GDNativeStringNamePtr p_signal_name, const GDNativePropertyInfo *p_argument_info, GDNativeInt p_argument_count) { NativeExtension *self = static_cast<NativeExtension *>(p_library); - StringName class_name = p_class_name; - ERR_FAIL_COND_MSG(!self->extension_classes.has(class_name), "Attempt to register extension class signal '" + String(p_signal_name) + "' for unexisting class '" + class_name + "'."); + StringName class_name = *reinterpret_cast<const StringName *>(p_class_name); + StringName signal_name = *reinterpret_cast<const StringName *>(p_signal_name); + ERR_FAIL_COND_MSG(!self->extension_classes.has(class_name), "Attempt to register extension class signal '" + signal_name + "' for unexisting class '" + class_name + "'."); MethodInfo s; - s.name = p_signal_name; + s.name = signal_name; for (int i = 0; i < p_argument_count; i++) { PropertyInfo arg(p_argument_info[i]); s.arguments.push_back(arg); @@ -241,10 +268,10 @@ void NativeExtension::_register_extension_class_signal(const GDNativeExtensionCl ClassDB::add_signal(class_name, s); } -void NativeExtension::_unregister_extension_class(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name) { +void NativeExtension::_unregister_extension_class(const GDNativeExtensionClassLibraryPtr p_library, const GDNativeStringNamePtr p_class_name) { NativeExtension *self = static_cast<NativeExtension *>(p_library); - StringName class_name = p_class_name; + StringName class_name = *reinterpret_cast<const StringName *>(p_class_name); ERR_FAIL_COND_MSG(!self->extension_classes.has(class_name), "Attempt to unregister unexisting extension class '" + class_name + "'."); Extension *ext = &self->extension_classes[class_name]; ERR_FAIL_COND_MSG(ext->native_extension.children.size(), "Attempt to unregister class '" + class_name + "' while other extension classes inherit from it."); diff --git a/core/extension/native_extension.h b/core/extension/native_extension.h index b7238d2899..70f6f9f039 100644 --- a/core/extension/native_extension.h +++ b/core/extension/native_extension.h @@ -47,14 +47,14 @@ class NativeExtension : public Resource { HashMap<StringName, Extension> extension_classes; - static void _register_extension_class(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const char *p_parent_class_name, const GDNativeExtensionClassCreationInfo *p_extension_funcs); - static void _register_extension_class_method(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const GDNativeExtensionClassMethodInfo *p_method_info); - static void _register_extension_class_integer_constant(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const char *p_enum_name, const char *p_constant_name, GDNativeInt p_constant_value, GDNativeBool p_is_bitfield); - static void _register_extension_class_property(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const GDNativePropertyInfo *p_info, const char *p_setter, const char *p_getter); - static void _register_extension_class_property_group(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const char *p_group_name, const char *p_prefix); - static void _register_extension_class_property_subgroup(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const char *p_subgroup_name, const char *p_prefix); - static void _register_extension_class_signal(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const char *p_signal_name, const GDNativePropertyInfo *p_argument_info, GDNativeInt p_argument_count); - static void _unregister_extension_class(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name); + static void _register_extension_class(const GDNativeExtensionClassLibraryPtr p_library, const GDNativeStringNamePtr p_class_name, const GDNativeStringNamePtr p_parent_class_name, const GDNativeExtensionClassCreationInfo *p_extension_funcs); + static void _register_extension_class_method(const GDNativeExtensionClassLibraryPtr p_library, const GDNativeStringNamePtr p_class_name, const GDNativeExtensionClassMethodInfo *p_method_info); + static void _register_extension_class_integer_constant(const GDNativeExtensionClassLibraryPtr p_library, const GDNativeStringNamePtr p_class_name, const GDNativeStringNamePtr p_enum_name, const GDNativeStringNamePtr p_constant_name, GDNativeInt p_constant_value, GDNativeBool p_is_bitfield); + static void _register_extension_class_property(const GDNativeExtensionClassLibraryPtr p_library, const GDNativeStringNamePtr p_class_name, const GDNativePropertyInfo *p_info, const GDNativeStringNamePtr p_setter, const GDNativeStringNamePtr p_getter); + static void _register_extension_class_property_group(const GDNativeExtensionClassLibraryPtr p_library, const GDNativeStringNamePtr p_class_name, const GDNativeStringNamePtr p_group_name, const GDNativeStringNamePtr p_prefix); + static void _register_extension_class_property_subgroup(const GDNativeExtensionClassLibraryPtr p_library, const GDNativeStringNamePtr p_class_name, const GDNativeStringNamePtr p_subgroup_name, const GDNativeStringNamePtr p_prefix); + static void _register_extension_class_signal(const GDNativeExtensionClassLibraryPtr p_library, const GDNativeStringNamePtr p_class_name, const GDNativeStringNamePtr p_signal_name, const GDNativePropertyInfo *p_argument_info, GDNativeInt p_argument_count); + static void _unregister_extension_class(const GDNativeExtensionClassLibraryPtr p_library, const GDNativeStringNamePtr p_class_name); static void _get_library_path(const GDNativeExtensionClassLibraryPtr p_library, GDNativeStringPtr r_path); GDNativeInitialization initialization; diff --git a/core/input/input.cpp b/core/input/input.cpp index 889c2a92fa..cb65d2569c 100644 --- a/core/input/input.cpp +++ b/core/input/input.cpp @@ -519,6 +519,7 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em touch_event.instantiate(); touch_event->set_pressed(mb->is_pressed()); touch_event->set_position(mb->get_position()); + touch_event->set_double_tap(mb->is_double_click()); event_dispatch_function(touch_event); } } @@ -580,6 +581,7 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em button_event->set_global_position(st->get_position()); button_event->set_pressed(st->is_pressed()); button_event->set_button_index(MouseButton::LEFT); + button_event->set_double_click(st->is_double_tap()); if (st->is_pressed()) { button_event->set_button_mask(MouseButton(mouse_button_mask | MouseButton::MASK_LEFT)); } else { @@ -1308,7 +1310,7 @@ void Input::parse_mapping(String p_mapping) { JoyButton output_button = _get_output_button(output); JoyAxis output_axis = _get_output_axis(output); ERR_CONTINUE_MSG(output_button == JoyButton::INVALID && output_axis == JoyAxis::INVALID, - vformat("Unrecognised output string \"%s\" in mapping:\n%s", output, p_mapping)); + vformat("Unrecognized output string \"%s\" in mapping:\n%s", output, p_mapping)); ERR_CONTINUE_MSG(output_button != JoyButton::INVALID && output_axis != JoyAxis::INVALID, vformat("Output string \"%s\" matched both button and axis in mapping:\n%s", output, p_mapping)); diff --git a/core/input/input_event.cpp b/core/input/input_event.cpp index 38037eaf72..0a32b4bf68 100644 --- a/core/input/input_event.cpp +++ b/core/input/input_event.cpp @@ -1162,6 +1162,13 @@ bool InputEventScreenTouch::is_pressed() const { return pressed; } +void InputEventScreenTouch::set_double_tap(bool p_double_tap) { + double_tap = p_double_tap; +} +bool InputEventScreenTouch::is_double_tap() const { + return double_tap; +} + Ref<InputEvent> InputEventScreenTouch::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const { Ref<InputEventScreenTouch> st; st.instantiate(); @@ -1170,6 +1177,7 @@ Ref<InputEvent> InputEventScreenTouch::xformed_by(const Transform2D &p_xform, co st->set_index(index); st->set_position(p_xform.xform(pos + p_local_ofs)); st->set_pressed(pressed); + st->set_double_tap(double_tap); return st; } @@ -1182,7 +1190,8 @@ String InputEventScreenTouch::as_text() const { String InputEventScreenTouch::to_string() { String p = pressed ? "true" : "false"; - return vformat("InputEventScreenTouch: index=%d, pressed=%s, position=(%s)", index, p, String(get_position())); + String double_tap_string = double_tap ? "true" : "false"; + return vformat("InputEventScreenTouch: index=%d, pressed=%s, position=(%s), double_tap=%s", index, p, String(get_position()), double_tap_string); } void InputEventScreenTouch::_bind_methods() { @@ -1195,9 +1204,13 @@ void InputEventScreenTouch::_bind_methods() { ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &InputEventScreenTouch::set_pressed); //ClassDB::bind_method(D_METHOD("is_pressed"),&InputEventScreenTouch::is_pressed); + ClassDB::bind_method(D_METHOD("set_double_tap", "double_tap"), &InputEventScreenTouch::set_double_tap); + ClassDB::bind_method(D_METHOD("is_double_tap"), &InputEventScreenTouch::is_double_tap); + ADD_PROPERTY(PropertyInfo(Variant::INT, "index"), "set_index", "get_index"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "position", PROPERTY_HINT_NONE, "suffix:px"), "set_position", "get_position"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "double_tap"), "set_double_tap", "is_double_tap"); } /////////////////////////////////// @@ -1549,7 +1562,7 @@ String InputEventMIDI::as_text() const { } String InputEventMIDI::to_string() { - return vformat("InputEventMIDI: channel=%d, message=%d, pitch=%d, velocity=%d, pressure=%d", channel, message, pitch, velocity, pressure); + return vformat("InputEventMIDI: channel=%d, message=%d, pitch=%d, velocity=%d, pressure=%d, controller_number=%d, controller_value=%d", channel, message, pitch, velocity, pressure, controller_number, controller_value); } void InputEventMIDI::_bind_methods() { diff --git a/core/input/input_event.h b/core/input/input_event.h index bc3ec3e7ac..adbcb7cf68 100644 --- a/core/input/input_event.h +++ b/core/input/input_event.h @@ -353,6 +353,7 @@ class InputEventScreenTouch : public InputEventFromWindow { int index = 0; Vector2 pos; bool pressed = false; + bool double_tap = false; protected: static void _bind_methods(); @@ -367,6 +368,9 @@ public: void set_pressed(bool p_pressed); virtual bool is_pressed() const override; + void set_double_tap(bool p_double_tap); + bool is_double_tap() const; + virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const override; virtual String as_text() const override; virtual String to_string() override; diff --git a/core/input/input_map.cpp b/core/input/input_map.cpp index ce76d11b6e..1c7d71e309 100644 --- a/core/input/input_map.cpp +++ b/core/input/input_map.cpp @@ -257,7 +257,7 @@ void InputMap::load_from_project_settings() { String name = pi.name.substr(pi.name.find("/") + 1, pi.name.length()); - Dictionary action = ProjectSettings::get_singleton()->get(pi.name); + Dictionary action = GLOBAL_GET(pi.name); float deadzone = action.has("deadzone") ? (float)action["deadzone"] : 0.5f; Array events = action["events"]; @@ -331,12 +331,18 @@ static const _BuiltinActionDisplayName _builtin_action_display_names[] = { { "ui_text_caret_document_start.macos", TTRC("Caret Document Start") }, { "ui_text_caret_document_end", TTRC("Caret Document End") }, { "ui_text_caret_document_end.macos", TTRC("Caret Document End") }, + { "ui_text_caret_add_below", TTRC("Caret Add Below") }, + { "ui_text_caret_add_below.macos", TTRC("Caret Add Below") }, + { "ui_text_caret_add_above", TTRC("Caret Add Above") }, + { "ui_text_caret_add_above.macos", TTRC("Caret Add Above") }, { "ui_text_scroll_up", TTRC("Scroll Up") }, { "ui_text_scroll_up.macos", TTRC("Scroll Up") }, { "ui_text_scroll_down", TTRC("Scroll Down") }, { "ui_text_scroll_down.macos", TTRC("Scroll Down") }, { "ui_text_select_all", TTRC("Select All") }, { "ui_text_select_word_under_caret", TTRC("Select Word Under Caret") }, + { "ui_text_add_selection_for_next_occurrence", TTRC("Add Selection for Next Occurrence") }, + { "ui_text_clear_carets_and_selection", TTRC("Clear Carets and Selection") }, { "ui_text_toggle_insert_mode", TTRC("Toggle Insert Mode") }, { "ui_text_submit", TTRC("Text Submitted") }, { "ui_graph_duplicate", TTRC("Duplicate Nodes") }, @@ -616,6 +622,24 @@ const HashMap<String, List<Ref<InputEvent>>> &InputMap::get_builtins() { inputs.push_back(InputEventKey::create_reference(Key::DOWN | KeyModifierMask::CMD_OR_CTRL)); default_builtin_cache.insert("ui_text_caret_document_end.macos", inputs); + // Text Caret Addition Below/Above + + inputs = List<Ref<InputEvent>>(); + inputs.push_back(InputEventKey::create_reference(Key::DOWN | KeyModifierMask::SHIFT | KeyModifierMask::CMD_OR_CTRL)); + default_builtin_cache.insert("ui_text_caret_add_below", inputs); + + inputs = List<Ref<InputEvent>>(); + inputs.push_back(InputEventKey::create_reference(Key::L | KeyModifierMask::SHIFT | KeyModifierMask::CMD_OR_CTRL)); + default_builtin_cache.insert("ui_text_caret_add_below.macos", inputs); + + inputs = List<Ref<InputEvent>>(); + inputs.push_back(InputEventKey::create_reference(Key::UP | KeyModifierMask::SHIFT | KeyModifierMask::CMD_OR_CTRL)); + default_builtin_cache.insert("ui_text_caret_add_above", inputs); + + inputs = List<Ref<InputEvent>>(); + inputs.push_back(InputEventKey::create_reference(Key::O | KeyModifierMask::SHIFT | KeyModifierMask::CMD_OR_CTRL)); + default_builtin_cache.insert("ui_text_caret_add_above.macos", inputs); + // Text Scrolling inputs = List<Ref<InputEvent>>(); @@ -641,10 +665,18 @@ const HashMap<String, List<Ref<InputEvent>>> &InputMap::get_builtins() { default_builtin_cache.insert("ui_text_select_all", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(Key::D | KeyModifierMask::CMD_OR_CTRL)); + inputs.push_back(InputEventKey::create_reference(Key::G | KeyModifierMask::ALT)); default_builtin_cache.insert("ui_text_select_word_under_caret", inputs); inputs = List<Ref<InputEvent>>(); + inputs.push_back(InputEventKey::create_reference(Key::D | KeyModifierMask::CMD_OR_CTRL)); + default_builtin_cache.insert("ui_text_add_selection_for_next_occurrence", inputs); + + inputs = List<Ref<InputEvent>>(); + inputs.push_back(InputEventKey::create_reference(Key::ESCAPE)); + default_builtin_cache.insert("ui_text_clear_carets_and_selection", inputs); + + inputs = List<Ref<InputEvent>>(); inputs.push_back(InputEventKey::create_reference(Key::INSERT)); default_builtin_cache.insert("ui_text_toggle_insert_mode", inputs); diff --git a/core/io/dir_access.cpp b/core/io/dir_access.cpp index 79e7fa16e3..7eb50d2261 100644 --- a/core/io/dir_access.cpp +++ b/core/io/dir_access.cpp @@ -351,7 +351,7 @@ Error DirAccess::copy(String p_from, String p_to, int p_chmod_flags) { const size_t copy_buffer_limit = 65536; // 64 KB fsrc->seek_end(0); - int size = fsrc->get_position(); + uint64_t size = fsrc->get_position(); fsrc->seek(0); err = OK; size_t buffer_size = MIN(size * sizeof(uint8_t), copy_buffer_limit); diff --git a/core/io/image.cpp b/core/io/image.cpp index 4be624a5a8..65addaf964 100644 --- a/core/io/image.cpp +++ b/core/io/image.cpp @@ -982,7 +982,7 @@ void Image::resize_to_po2(bool p_square, Interpolation p_interpolation) { } void Image::resize(int p_width, int p_height, Interpolation p_interpolation) { - ERR_FAIL_COND_MSG(data.size() == 0, "Cannot resize image before creating it, use create() or create_from_data() first."); + ERR_FAIL_COND_MSG(data.size() == 0, "Cannot resize image before creating it, use set_data() first."); ERR_FAIL_COND_MSG(!_can_modify(format), "Cannot resize in compressed or custom image formats."); bool mipmap_aware = p_interpolation == INTERPOLATE_TRILINEAR /* || p_interpolation == INTERPOLATE_TRICUBIC */; @@ -1017,7 +1017,7 @@ void Image::resize(int p_width, int p_height, Interpolation p_interpolation) { } bool interpolate_mipmaps = mipmap_aware && mip1 != mip2; if (interpolate_mipmaps) { - dst2.create(p_width, p_height, false, format); + dst2.initialize_data(p_width, p_height, false, format); } bool had_mipmaps = mipmaps; @@ -2016,9 +2016,7 @@ Error Image::generate_mipmap_roughness(RoughnessChannel p_roughness_channel, con uint8_t* wr = imgdata.ptrw(); memcpy(wr.ptr(), ptr, size); wr = uint8_t*(); - Ref<Image> im; - im.instantiate(); - im->create(w, h, false, format, imgdata); + Ref<Image> im = Image::create_from_data(w, h, false, format, imgdata); im->save_png("res://mipmap_" + itos(i) + ".png"); } #endif @@ -2051,7 +2049,25 @@ Vector<uint8_t> Image::get_data() const { return data; } -void Image::create(int p_width, int p_height, bool p_use_mipmaps, Format p_format) { +Ref<Image> Image::create_empty(int p_width, int p_height, bool p_use_mipmaps, Format p_format) { + Ref<Image> image; + image.instantiate(); + image->initialize_data(p_width, p_height, p_use_mipmaps, p_format); + return image; +} + +Ref<Image> Image::create_from_data(int p_width, int p_height, bool p_use_mipmaps, Format p_format, const Vector<uint8_t> &p_data) { + Ref<Image> image; + image.instantiate(); + image->initialize_data(p_width, p_height, p_use_mipmaps, p_format, p_data); + return image; +} + +void Image::set_data(int p_width, int p_height, bool p_use_mipmaps, Format p_format, const Vector<uint8_t> &p_data) { + initialize_data(p_width, p_height, p_use_mipmaps, p_format, p_data); +} + +void Image::initialize_data(int p_width, int p_height, bool p_use_mipmaps, Format p_format) { ERR_FAIL_COND_MSG(p_width <= 0, "The Image width specified (" + itos(p_width) + " pixels) must be greater than 0 pixels."); ERR_FAIL_COND_MSG(p_height <= 0, "The Image height specified (" + itos(p_height) + " pixels) must be greater than 0 pixels."); ERR_FAIL_COND_MSG(p_width > MAX_WIDTH, @@ -2077,7 +2093,7 @@ void Image::create(int p_width, int p_height, bool p_use_mipmaps, Format p_forma format = p_format; } -void Image::create(int p_width, int p_height, bool p_use_mipmaps, Format p_format, const Vector<uint8_t> &p_data) { +void Image::initialize_data(int p_width, int p_height, bool p_use_mipmaps, Format p_format, const Vector<uint8_t> &p_data) { ERR_FAIL_COND_MSG(p_width <= 0, "The Image width specified (" + itos(p_width) + " pixels) must be greater than 0 pixels."); ERR_FAIL_COND_MSG(p_height <= 0, "The Image height specified (" + itos(p_height) + " pixels) must be greater than 0 pixels."); ERR_FAIL_COND_MSG(p_width > MAX_WIDTH, @@ -2115,7 +2131,7 @@ void Image::create(int p_width, int p_height, bool p_use_mipmaps, Format p_forma mipmaps = p_use_mipmaps; } -void Image::create(const char **p_xpm) { +void Image::initialize_data(const char **p_xpm) { int size_width = 0; int size_height = 0; int pixelchars = 0; @@ -2230,7 +2246,7 @@ void Image::create(const char **p_xpm) { } if (line == colormap_size) { status = READING_PIXELS; - create(size_width, size_height, false, has_alpha ? FORMAT_RGBA8 : FORMAT_RGB8); + initialize_data(size_width, size_height, false, has_alpha ? FORMAT_RGBA8 : FORMAT_RGB8); data_write = data.ptrw(); pixel_size = has_alpha ? 4 : 3; } @@ -2559,7 +2575,7 @@ Image::Image(const char **p_xpm) { mipmaps = false; format = FORMAT_L8; - create(p_xpm); + initialize_data(p_xpm); } Image::Image(int p_width, int p_height, bool p_use_mipmaps, Format p_format) { @@ -2568,7 +2584,7 @@ Image::Image(int p_width, int p_height, bool p_use_mipmaps, Format p_format) { mipmaps = p_use_mipmaps; format = FORMAT_L8; - create(p_width, p_height, p_use_mipmaps, p_format); + initialize_data(p_width, p_height, p_use_mipmaps, p_format); } Image::Image(int p_width, int p_height, bool p_mipmaps, Format p_format, const Vector<uint8_t> &p_data) { @@ -2577,7 +2593,7 @@ Image::Image(int p_width, int p_height, bool p_mipmaps, Format p_format, const V mipmaps = p_mipmaps; format = FORMAT_L8; - create(p_width, p_height, p_mipmaps, p_format, p_data); + initialize_data(p_width, p_height, p_mipmaps, p_format, p_data); } Rect2i Image::get_used_rect() const { @@ -2620,9 +2636,9 @@ Rect2i Image::get_used_rect() const { } } -Ref<Image> Image::get_rect(const Rect2i &p_area) const { - Ref<Image> img = memnew(Image(p_area.size.x, p_area.size.y, mipmaps, format)); - img->blit_rect(Ref<Image>((Image *)this), p_area, Point2i(0, 0)); +Ref<Image> Image::get_region(const Rect2i &p_region) const { + Ref<Image> img = memnew(Image(p_region.size.x, p_region.size.y, mipmaps, format)); + img->blit_rect(Ref<Image>((Image *)this), p_region, Point2i(0, 0)); return img; } @@ -2846,6 +2862,9 @@ void Image::_repeat_pixel_over_subsequent_memory(uint8_t *p_pixel, int p_pixel_s } void Image::fill(const Color &p_color) { + if (data.size() == 0) { + return; + } ERR_FAIL_COND_MSG(!_can_modify(format), "Cannot fill in compressed or custom image formats."); uint8_t *dst_data_ptr = data.ptrw(); @@ -2859,6 +2878,9 @@ void Image::fill(const Color &p_color) { } void Image::fill_rect(const Rect2i &p_rect, const Color &p_color) { + if (data.size() == 0) { + return; + } ERR_FAIL_COND_MSG(!_can_modify(format), "Cannot fill rect in compressed or custom image formats."); Rect2i r = Rect2i(0, 0, width, height).intersection(p_rect.abs()); @@ -2931,7 +2953,7 @@ void Image::_set_data(const Dictionary &p_data) { ERR_FAIL_COND(ddformat == FORMAT_MAX); - create(dwidth, dheight, dmipmaps, ddformat, ddata); + initialize_data(dwidth, dheight, dmipmaps, ddformat, ddata); } Dictionary Image::_get_data() const { @@ -3294,8 +3316,9 @@ void Image::_bind_methods() { ClassDB::bind_method(D_METHOD("generate_mipmaps", "renormalize"), &Image::generate_mipmaps, DEFVAL(false)); ClassDB::bind_method(D_METHOD("clear_mipmaps"), &Image::clear_mipmaps); - ClassDB::bind_method(D_METHOD("create", "width", "height", "use_mipmaps", "format"), &Image::create_empty); - ClassDB::bind_method(D_METHOD("create_from_data", "width", "height", "use_mipmaps", "format", "data"), &Image::create_from_data); + ClassDB::bind_static_method("Image", D_METHOD("create", "width", "height", "use_mipmaps", "format"), &Image::create_empty); + ClassDB::bind_static_method("Image", D_METHOD("create_from_data", "width", "height", "use_mipmaps", "format", "data"), &Image::create_from_data); + ClassDB::bind_method(D_METHOD("set_data", "width", "height", "use_mipmaps", "format", "data"), &Image::set_data); ClassDB::bind_method(D_METHOD("is_empty"), &Image::is_empty); @@ -3339,7 +3362,7 @@ void Image::_bind_methods() { ClassDB::bind_method(D_METHOD("fill_rect", "rect", "color"), &Image::fill_rect); ClassDB::bind_method(D_METHOD("get_used_rect"), &Image::get_used_rect); - ClassDB::bind_method(D_METHOD("get_rect", "rect"), &Image::get_rect); + ClassDB::bind_method(D_METHOD("get_region", "region"), &Image::get_region); ClassDB::bind_method(D_METHOD("copy_from", "src"), &Image::copy_internals_from); @@ -3460,9 +3483,7 @@ Ref<Image> Image::rgbe_to_srgb() { ERR_FAIL_COND_V(format != FORMAT_RGBE9995, Ref<Image>()); - Ref<Image> new_image; - new_image.instantiate(); - new_image->create(width, height, false, Image::FORMAT_RGB8); + Ref<Image> new_image = create_empty(width, height, false, Image::FORMAT_RGB8); for (int row = 0; row < height; row++) { for (int col = 0; col < width; col++) { @@ -3503,6 +3524,7 @@ Ref<Image> Image::get_image_from_mipmap(int p_mipamp) const { void Image::bump_map_to_normal_map(float bump_scale) { ERR_FAIL_COND(!_can_modify(format)); + clear_mipmaps(); convert(Image::FORMAT_RF); Vector<uint8_t> result_image; //rgba output diff --git a/core/io/image.h b/core/io/image.h index fd264a7a38..62df81e7c8 100644 --- a/core/io/image.h +++ b/core/io/image.h @@ -279,12 +279,12 @@ public: void normalize(); //for normal maps /** - * Create a new image of a given size and format. Current image will be lost + * Creates new internal image data of a given size and format. Current image will be lost. */ - void create(int p_width, int p_height, bool p_use_mipmaps, Format p_format); - void create(int p_width, int p_height, bool p_use_mipmaps, Format p_format, const Vector<uint8_t> &p_data); + void initialize_data(int p_width, int p_height, bool p_use_mipmaps, Format p_format); + void initialize_data(int p_width, int p_height, bool p_use_mipmaps, Format p_format, const Vector<uint8_t> &p_data); + void initialize_data(const char **p_xpm); - void create(const char **p_xpm); /** * returns true when the image is empty (0,0) in size */ @@ -303,13 +303,9 @@ public: Error save_webp(const String &p_path, const bool p_lossy = false, const float p_quality = 0.75f) const; Vector<uint8_t> save_webp_to_buffer(const bool p_lossy = false, const float p_quality = 0.75f) const; - void create_empty(int p_width, int p_height, bool p_use_mipmaps, Format p_format) { - create(p_width, p_height, p_use_mipmaps, p_format); - } - - void create_from_data(int p_width, int p_height, bool p_use_mipmaps, Format p_format, const Vector<uint8_t> &p_data) { - create(p_width, p_height, p_use_mipmaps, p_format, p_data); - } + static Ref<Image> create_empty(int p_width, int p_height, bool p_use_mipmaps, Format p_format); + static Ref<Image> create_from_data(int p_width, int p_height, bool p_use_mipmaps, Format p_format, const Vector<uint8_t> &p_data); + void set_data(int p_width, int p_height, bool p_use_mipmaps, Format p_format, const Vector<uint8_t> &p_data); /** * create an empty image @@ -381,7 +377,7 @@ public: void fill_rect(const Rect2i &p_rect, const Color &p_color); Rect2i get_used_rect() const; - Ref<Image> get_rect(const Rect2i &p_area) const; + Ref<Image> get_region(const Rect2i &p_area) const; static void set_compress_bc_func(void (*p_compress_func)(Image *, float, UsedChannels)); static void set_compress_bptc_func(void (*p_compress_func)(Image *, float, UsedChannels)); diff --git a/core/io/image_loader.cpp b/core/io/image_loader.cpp index 397984a2ab..6c00ca4b67 100644 --- a/core/io/image_loader.cpp +++ b/core/io/image_loader.cpp @@ -52,10 +52,8 @@ 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 = ERR_UNAVAILABLE; - if (GDVIRTUAL_CALL(_load_image, p_image, p_fileaccess, p_flags, p_scale, err)) { - return err; - } - return ERR_UNAVAILABLE; + GDVIRTUAL_CALL(_load_image, p_image, p_fileaccess, p_flags, p_scale, err); + return err; } void ImageFormatLoaderExtension::get_recognized_extensions(List<String> *p_extension) const { diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index 2a79067e02..4611528db7 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -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 } } } diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp index a018221b7f..6219ea70e4 100644 --- a/core/io/resource_loader.cpp +++ b/core/io/resource_loader.cpp @@ -49,6 +49,11 @@ Ref<ResourceFormatLoader> ResourceLoader::loader[ResourceLoader::MAX_LOADERS]; int ResourceLoader::loader_count = 0; bool ResourceFormatLoader::recognize_path(const String &p_path, const String &p_for_type) const { + bool ret = false; + if (GDVIRTUAL_CALL(_recognize_path, p_path, p_for_type, ret)) { + return ret; + } + String extension = p_path.get_extension(); List<String> extensions; @@ -69,11 +74,8 @@ bool ResourceFormatLoader::recognize_path(const String &p_path, const String &p_ bool ResourceFormatLoader::handles_type(const String &p_type) const { bool success = false; - if (GDVIRTUAL_CALL(_handles_type, p_type, success)) { - return success; - } - - return false; + GDVIRTUAL_CALL(_handles_type, p_type, success); + return success; } void ResourceFormatLoader::get_classes_used(const String &p_path, HashSet<StringName> *r_classes) { @@ -93,21 +95,14 @@ void ResourceFormatLoader::get_classes_used(const String &p_path, HashSet<String String ResourceFormatLoader::get_resource_type(const String &p_path) const { String ret; - - if (GDVIRTUAL_CALL(_get_resource_type, p_path, ret)) { - return ret; - } - - return ""; + GDVIRTUAL_CALL(_get_resource_type, p_path, ret); + return ret; } ResourceUID::ID ResourceFormatLoader::get_resource_uid(const String &p_path) const { int64_t uid = ResourceUID::INVALID_ID; - if (GDVIRTUAL_CALL(_get_resource_uid, p_path, uid)) { - return uid; - } - - return ResourceUID::INVALID_ID; + GDVIRTUAL_CALL(_get_resource_uid, p_path, uid); + return uid; } void ResourceFormatLoader::get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) const { @@ -127,7 +122,7 @@ bool ResourceFormatLoader::exists(const String &p_path) const { if (GDVIRTUAL_CALL(_exists, p_path, success)) { return success; } - return FileAccess::exists(p_path); //by default just check file + return FileAccess::exists(p_path); // By default just check file. } void ResourceFormatLoader::get_recognized_extensions(List<String> *p_extensions) const { @@ -176,11 +171,8 @@ Error ResourceFormatLoader::rename_dependencies(const String &p_path, const Hash } int64_t err = OK; - if (GDVIRTUAL_CALL(_rename_dependencies, p_path, deps_dict, err)) { - return (Error)err; - } - - return OK; + GDVIRTUAL_CALL(_rename_dependencies, p_path, deps_dict, err); + return (Error)err; } void ResourceFormatLoader::_bind_methods() { @@ -189,6 +181,7 @@ void ResourceFormatLoader::_bind_methods() { BIND_ENUM_CONSTANT(CACHE_MODE_REPLACE); GDVIRTUAL_BIND(_get_recognized_extensions); + GDVIRTUAL_BIND(_recognize_path, "path", "type"); GDVIRTUAL_BIND(_handles_type, "type"); GDVIRTUAL_BIND(_get_resource_type, "path"); GDVIRTUAL_BIND(_get_resource_uid, "path"); @@ -908,7 +901,7 @@ void ResourceLoader::load_translation_remaps() { return; } - Dictionary remaps = ProjectSettings::get_singleton()->get("internationalization/locale/translation_remaps"); + Dictionary remaps = GLOBAL_GET("internationalization/locale/translation_remaps"); List<Variant> keys; remaps.get_key_list(&keys); for (const Variant &E : keys) { @@ -935,7 +928,7 @@ void ResourceLoader::load_path_remaps() { return; } - Vector<String> remaps = ProjectSettings::get_singleton()->get("path_remap/remapped_paths"); + Vector<String> remaps = GLOBAL_GET("path_remap/remapped_paths"); int rc = remaps.size(); ERR_FAIL_COND(rc & 1); //must be even const String *r = remaps.ptr(); diff --git a/core/io/resource_loader.h b/core/io/resource_loader.h index 91ba930176..243670b2d0 100644 --- a/core/io/resource_loader.h +++ b/core/io/resource_loader.h @@ -51,6 +51,7 @@ protected: static void _bind_methods(); GDVIRTUAL0RC(Vector<String>, _get_recognized_extensions) + GDVIRTUAL2RC(bool, _recognize_path, String, StringName) GDVIRTUAL1RC(bool, _handles_type, StringName) GDVIRTUAL1RC(String, _get_resource_type, String) GDVIRTUAL1RC(ResourceUID::ID, _get_resource_uid, String) diff --git a/core/io/resource_saver.cpp b/core/io/resource_saver.cpp index 2f863baaac..710afc614f 100644 --- a/core/io/resource_saver.cpp +++ b/core/io/resource_saver.cpp @@ -43,20 +43,14 @@ 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 = ERR_METHOD_NOT_FOUND; - if (GDVIRTUAL_CALL(_save, p_resource, p_path, p_flags, res)) { - return (Error)res; - } - - return ERR_METHOD_NOT_FOUND; + GDVIRTUAL_CALL(_save, p_resource, p_path, p_flags, res); + return (Error)res; } bool ResourceFormatSaver::recognize(const Ref<Resource> &p_resource) const { bool success = false; - if (GDVIRTUAL_CALL(_recognize, p_resource, success)) { - return success; - } - - return false; + GDVIRTUAL_CALL(_recognize, p_resource, success); + return success; } void ResourceFormatSaver::get_recognized_extensions(const Ref<Resource> &p_resource, List<String> *p_extensions) const { @@ -69,10 +63,31 @@ void ResourceFormatSaver::get_recognized_extensions(const Ref<Resource> &p_resou } } +bool ResourceFormatSaver::recognize_path(const Ref<Resource> &p_resource, const String &p_path) const { + bool ret = false; + if (GDVIRTUAL_CALL(_recognize_path, p_resource, p_path, ret)) { + return ret; + } + + String extension = p_path.get_extension(); + + List<String> extensions; + get_recognized_extensions(p_resource, &extensions); + + for (const String &E : extensions) { + if (E.nocasecmp_to(extension) == 0) { + return true; + } + } + + return false; +} + void ResourceFormatSaver::_bind_methods() { GDVIRTUAL_BIND(_save, "resource", "path", "flags"); GDVIRTUAL_BIND(_recognize, "resource"); GDVIRTUAL_BIND(_get_recognized_extensions, "resource"); + GDVIRTUAL_BIND(_recognize_path, "resource", "path"); } Error ResourceSaver::save(const Ref<Resource> &p_resource, const String &p_path, uint32_t p_flags) { @@ -90,17 +105,7 @@ Error ResourceSaver::save(const Ref<Resource> &p_resource, const String &p_path, continue; } - List<String> extensions; - bool recognized = false; - saver[i]->get_recognized_extensions(p_resource, &extensions); - - for (const String &E : extensions) { - if (E.nocasecmp_to(extension) == 0) { - recognized = true; - } - } - - if (!recognized) { + if (!saver[i]->recognize_path(p_resource, path)) { continue; } diff --git a/core/io/resource_saver.h b/core/io/resource_saver.h index 4fee2bcfd1..5e48ce88c3 100644 --- a/core/io/resource_saver.h +++ b/core/io/resource_saver.h @@ -44,11 +44,13 @@ protected: GDVIRTUAL3R(int64_t, _save, Ref<Resource>, String, uint32_t) GDVIRTUAL1RC(bool, _recognize, Ref<Resource>) GDVIRTUAL1RC(Vector<String>, _get_recognized_extensions, Ref<Resource>) + GDVIRTUAL2RC(bool, _recognize_path, Ref<Resource>, String) public: virtual Error save(const Ref<Resource> &p_resource, const String &p_path, uint32_t p_flags = 0); virtual bool recognize(const Ref<Resource> &p_resource) const; virtual void get_recognized_extensions(const Ref<Resource> &p_resource, List<String> *p_extensions) const; + virtual bool recognize_path(const Ref<Resource> &p_resource, const String &p_path) const; virtual ~ResourceFormatSaver() {} }; diff --git a/core/io/xml_parser.cpp b/core/io/xml_parser.cpp index abae48fdd8..16b7f3a1f6 100644 --- a/core/io/xml_parser.cpp +++ b/core/io/xml_parser.cpp @@ -41,11 +41,11 @@ static inline bool _is_white_space(char c) { } //! sets the state that text was found. Returns true if set should be set -bool XMLParser::_set_text(char *start, char *end) { +bool XMLParser::_set_text(const char *start, const char *end) { // check if text is more than 2 characters, and if not, check if there is // only white space, so that this text won't be reported if (end - start < 3) { - char *p = start; + const char *p = start; for (; p != end; ++p) { if (!_is_white_space(*p)) { break; @@ -92,7 +92,7 @@ void XMLParser::_parse_closing_xml_element() { void XMLParser::_ignore_definition() { node_type = NODE_UNKNOWN; - char *F = P; + const char *F = P; // move until end marked with '>' reached while (*P && *P != '>') { next_char(); @@ -123,8 +123,8 @@ bool XMLParser::_parse_cdata() { return true; } - char *cDataBegin = P; - char *cDataEnd = nullptr; + const char *cDataBegin = P; + const char *cDataEnd = nullptr; // find end of CDATA while (*P && !cDataEnd) { @@ -152,9 +152,9 @@ void XMLParser::_parse_comment() { node_type = NODE_COMMENT; P += 1; - char *pEndOfInput = data + length; - char *pCommentBegin; - char *pCommentEnd; + const char *pEndOfInput = data + length; + const char *pCommentBegin; + const char *pCommentEnd; if (P + 1 < pEndOfInput && P[0] == '-' && P[1] == '-') { // Comment, use '-->' as end. @@ -293,7 +293,7 @@ void XMLParser::_parse_opening_xml_element() { } void XMLParser::_parse_current_node() { - char *start = P; + const char *start = P; node_offset = P - data; // more forward until '<' found @@ -458,15 +458,36 @@ bool XMLParser::is_empty() const { Error XMLParser::open_buffer(const Vector<uint8_t> &p_buffer) { ERR_FAIL_COND_V(p_buffer.size() == 0, ERR_INVALID_DATA); - if (data) { - memdelete_arr(data); + if (data_copy) { + memdelete_arr(data_copy); + data_copy = nullptr; } length = p_buffer.size(); - data = memnew_arr(char, length + 1); - memcpy(data, p_buffer.ptr(), length); - data[length] = 0; + data_copy = memnew_arr(char, length + 1); + memcpy(data_copy, p_buffer.ptr(), length); + data_copy[length] = 0; + data = data_copy; + P = data; + current_line = 0; + + return OK; +} + +Error XMLParser::_open_buffer(const uint8_t *p_buffer, size_t p_size) { + ERR_FAIL_COND_V(p_size == 0, ERR_INVALID_DATA); + ERR_FAIL_COND_V(!p_buffer, ERR_INVALID_DATA); + + if (data_copy) { + memdelete_arr(data_copy); + data_copy = nullptr; + } + + length = p_size; + data = (const char *)p_buffer; P = data; + current_line = 0; + return OK; } @@ -479,13 +500,15 @@ Error XMLParser::open(const String &p_path) { length = file->get_length(); ERR_FAIL_COND_V(length < 1, ERR_FILE_CORRUPT); - if (data) { - memdelete_arr(data); + if (data_copy) { + memdelete_arr(data_copy); + data_copy = nullptr; } - data = memnew_arr(char, length + 1); - file->get_buffer((uint8_t *)data, length); - data[length] = 0; + data_copy = memnew_arr(char, length + 1); + file->get_buffer((uint8_t *)data_copy, length); + data_copy[length] = 0; + data = data_copy; P = data; current_line = 0; @@ -512,8 +535,9 @@ void XMLParser::skip_section() { } void XMLParser::close() { - if (data) { + if (data_copy) { memdelete_arr(data); + data_copy = nullptr; } data = nullptr; length = 0; @@ -528,7 +552,8 @@ int XMLParser::get_current_line() const { } XMLParser::~XMLParser() { - if (data) { - memdelete_arr(data); + if (data_copy) { + memdelete_arr(data_copy); + data_copy = nullptr; } } diff --git a/core/io/xml_parser.h b/core/io/xml_parser.h index aea252ddc7..be44f771dc 100644 --- a/core/io/xml_parser.h +++ b/core/io/xml_parser.h @@ -65,8 +65,9 @@ public: }; private: - char *data = nullptr; - char *P = nullptr; + char *data_copy = nullptr; + const char *data = nullptr; + const char *P = nullptr; uint64_t length = 0; uint64_t current_line = 0; String node_name; @@ -81,7 +82,7 @@ private: Vector<Attribute> attributes; - bool _set_text(char *start, char *end); + bool _set_text(const char *start, const char *end); void _parse_closing_xml_element(); void _ignore_definition(); bool _parse_cdata(); @@ -118,6 +119,7 @@ public: Error open(const String &p_path); Error open_buffer(const Vector<uint8_t> &p_buffer); + Error _open_buffer(const uint8_t *p_buffer, size_t p_size); void close(); diff --git a/core/io/zip_io.cpp b/core/io/zip_io.cpp index e573e8de19..200e5f5e83 100644 --- a/core/io/zip_io.cpp +++ b/core/io/zip_io.cpp @@ -37,11 +37,17 @@ void *zipio_open(voidpf opaque, const char *p_fname, int mode) { String fname; fname.parse_utf8(p_fname); + int file_access_mode = 0; if (mode & ZLIB_FILEFUNC_MODE_WRITE) { - (*fa) = FileAccess::open(fname, FileAccess::WRITE); - } else { - (*fa) = FileAccess::open(fname, FileAccess::READ); + file_access_mode |= FileAccess::WRITE; } + if (mode & ZLIB_FILEFUNC_MODE_READ) { + file_access_mode |= FileAccess::READ; + } + if (mode & ZLIB_FILEFUNC_MODE_CREATE) { + file_access_mode |= FileAccess::WRITE_READ; + } + (*fa) = FileAccess::open(fname, file_access_mode); if (fa->is_null()) { return nullptr; diff --git a/core/math/aabb.cpp b/core/math/aabb.cpp index 026f179445..fcf245d2ad 100644 --- a/core/math/aabb.cpp +++ b/core/math/aabb.cpp @@ -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)) { diff --git a/core/math/aabb.h b/core/math/aabb.h index b9f777c6cf..9d5837ad37 100644 --- a/core/math/aabb.h +++ b/core/math/aabb.h @@ -63,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 diff --git a/core/math/audio_frame.h b/core/math/audio_frame.h index 1a80faaa12..d06f9bef1e 100644 --- a/core/math/audio_frame.h +++ b/core/math/audio_frame.h @@ -34,7 +34,7 @@ #include "core/math/vector2.h" #include "core/typedefs.h" -static inline float undenormalise(volatile float f) { +static inline float undenormalize(volatile float f) { union { uint32_t i; float f; @@ -101,9 +101,9 @@ struct AudioFrame { r /= p_sample; } - _ALWAYS_INLINE_ void undenormalise() { - l = ::undenormalise(l); - r = ::undenormalise(r); + _ALWAYS_INLINE_ void undenormalize() { + l = ::undenormalize(l); + r = ::undenormalize(r); } _FORCE_INLINE_ AudioFrame lerp(const AudioFrame &p_b, float p_t) const { diff --git a/core/math/basis.cpp b/core/math/basis.cpp index 845686f339..41ec6d8ce3 100644 --- a/core/math/basis.cpp +++ b/core/math/basis.cpp @@ -453,7 +453,7 @@ void Basis::get_rotation_axis_angle_local(Vector3 &p_axis, real_t &p_angle) cons Vector3 Basis::get_euler(EulerOrder p_order) const { switch (p_order) { - case EULER_ORDER_XYZ: { + case EulerOrder::XYZ: { // Euler angles in XYZ convention. // See https://en.wikipedia.org/wiki/Euler_angles#Rotation_matrix // @@ -488,7 +488,7 @@ Vector3 Basis::get_euler(EulerOrder p_order) const { } return euler; } break; - case EULER_ORDER_XZY: { + case EulerOrder::XZY: { // Euler angles in XZY convention. // See https://en.wikipedia.org/wiki/Euler_angles#Rotation_matrix // @@ -517,7 +517,7 @@ Vector3 Basis::get_euler(EulerOrder p_order) const { } return euler; } break; - case EULER_ORDER_YXZ: { + case EulerOrder::YXZ: { // Euler angles in YXZ convention. // See https://en.wikipedia.org/wiki/Euler_angles#Rotation_matrix // @@ -555,7 +555,7 @@ Vector3 Basis::get_euler(EulerOrder p_order) const { return euler; } break; - case EULER_ORDER_YZX: { + case EulerOrder::YZX: { // Euler angles in YZX convention. // See https://en.wikipedia.org/wiki/Euler_angles#Rotation_matrix // @@ -584,7 +584,7 @@ Vector3 Basis::get_euler(EulerOrder p_order) const { } return euler; } break; - case EULER_ORDER_ZXY: { + case EulerOrder::ZXY: { // Euler angles in ZXY convention. // See https://en.wikipedia.org/wiki/Euler_angles#Rotation_matrix // @@ -612,7 +612,7 @@ Vector3 Basis::get_euler(EulerOrder p_order) const { } return euler; } break; - case EULER_ORDER_ZYX: { + case EulerOrder::ZYX: { // Euler angles in ZYX convention. // See https://en.wikipedia.org/wiki/Euler_angles#Rotation_matrix // @@ -663,22 +663,22 @@ void Basis::set_euler(const Vector3 &p_euler, EulerOrder p_order) { Basis zmat(c, -s, 0, s, c, 0, 0, 0, 1); switch (p_order) { - case EULER_ORDER_XYZ: { + case EulerOrder::XYZ: { *this = xmat * (ymat * zmat); } break; - case EULER_ORDER_XZY: { + case EulerOrder::XZY: { *this = xmat * zmat * ymat; } break; - case EULER_ORDER_YXZ: { + case EulerOrder::YXZ: { *this = ymat * xmat * zmat; } break; - case EULER_ORDER_YZX: { + case EulerOrder::YZX: { *this = ymat * zmat * xmat; } break; - case EULER_ORDER_ZXY: { + case EulerOrder::ZXY: { *this = zmat * xmat * ymat; } break; - case EULER_ORDER_ZYX: { + case EulerOrder::ZYX: { *this = zmat * ymat * xmat; } break; default: { @@ -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++) { @@ -811,7 +815,7 @@ void Basis::get_axis_angle(Vector3 &r_axis, real_t &r_angle) const { return; } // As we have reached here there are no singularities so we can handle normally. - double s = Math::sqrt((rows[2][1] - rows[1][2]) * (rows[2][1] - rows[1][2]) + (rows[0][2] - rows[2][0]) * (rows[0][2] - rows[2][0]) + (rows[1][0] - rows[0][1]) * (rows[1][0] - rows[0][1])); // Used to normalise. + double s = Math::sqrt((rows[2][1] - rows[1][2]) * (rows[2][1] - rows[1][2]) + (rows[0][2] - rows[2][0]) * (rows[0][2] - rows[2][0]) + (rows[1][0] - rows[0][1]) * (rows[1][0] - rows[0][1])); // Used to normalize. if (Math::abs(s) < CMP_EPSILON) { // Prevent divide by zero, should not happen if matrix is orthogonal and should be caught by singularity test above. diff --git a/core/math/basis.h b/core/math/basis.h index cc2924f5ff..a1d9fccef1 100644 --- a/core/math/basis.h +++ b/core/math/basis.h @@ -56,15 +56,6 @@ struct _NO_DISCARD_ Basis { _FORCE_INLINE_ real_t determinant() const; - enum EulerOrder { - EULER_ORDER_XYZ, - EULER_ORDER_XZY, - EULER_ORDER_YXZ, - EULER_ORDER_YZX, - EULER_ORDER_ZXY, - EULER_ORDER_ZYX - }; - void from_z(const Vector3 &p_z); void rotate(const Vector3 &p_axis, real_t p_angle); @@ -73,13 +64,13 @@ struct _NO_DISCARD_ Basis { void rotate_local(const Vector3 &p_axis, real_t p_angle); Basis rotated_local(const Vector3 &p_axis, real_t p_angle) const; - void rotate(const Vector3 &p_euler, EulerOrder p_order = EULER_ORDER_YXZ); - Basis rotated(const Vector3 &p_euler, EulerOrder p_order = EULER_ORDER_YXZ) const; + void rotate(const Vector3 &p_euler, EulerOrder p_order = EulerOrder::YXZ); + Basis rotated(const Vector3 &p_euler, EulerOrder p_order = EulerOrder::YXZ) const; void rotate(const Quaternion &p_quaternion); Basis rotated(const Quaternion &p_quaternion) const; - Vector3 get_euler_normalized(EulerOrder p_order = EULER_ORDER_YXZ) const; + Vector3 get_euler_normalized(EulerOrder p_order = EulerOrder::YXZ) const; void get_rotation_axis_angle(Vector3 &p_axis, real_t &p_angle) const; void get_rotation_axis_angle_local(Vector3 &p_axis, real_t &p_angle) const; Quaternion get_rotation_quaternion() const; @@ -88,9 +79,9 @@ struct _NO_DISCARD_ Basis { Vector3 rotref_posscale_decomposition(Basis &rotref) const; - Vector3 get_euler(EulerOrder p_order = EULER_ORDER_YXZ) const; - void set_euler(const Vector3 &p_euler, EulerOrder p_order = EULER_ORDER_YXZ); - static Basis from_euler(const Vector3 &p_euler, EulerOrder p_order = EULER_ORDER_YXZ) { + Vector3 get_euler(EulerOrder p_order = EulerOrder::YXZ) const; + void set_euler(const Vector3 &p_euler, EulerOrder p_order = EulerOrder::YXZ); + static Basis from_euler(const Vector3 &p_euler, EulerOrder p_order = EulerOrder::YXZ) { Basis b; b.set_euler(p_euler, p_order); return b; @@ -119,7 +110,7 @@ struct _NO_DISCARD_ Basis { Vector3 get_scale_local() const; void set_axis_angle_scale(const Vector3 &p_axis, real_t p_angle, const Vector3 &p_scale); - void set_euler_scale(const Vector3 &p_euler, const Vector3 &p_scale, EulerOrder p_order = EULER_ORDER_YXZ); + void set_euler_scale(const Vector3 &p_euler, const Vector3 &p_scale, EulerOrder p_order = EulerOrder::YXZ); void set_quaternion_scale(const Quaternion &p_quaternion, const Vector3 &p_scale); // transposed dot products @@ -134,6 +125,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/convex_hull.cpp b/core/math/convex_hull.cpp index 996f4f4d67..561970d2ee 100644 --- a/core/math/convex_hull.cpp +++ b/core/math/convex_hull.cpp @@ -62,6 +62,7 @@ subject to the following restrictions: #include "core/math/aabb.h" #include "core/math/math_defs.h" #include "core/os/memory.h" +#include "core/templates/oa_hash_map.h" #include "core/templates/paged_allocator.h" #include <string.h> @@ -2252,19 +2253,62 @@ Error ConvexHullComputer::convex_hull(const Vector<Vector3> &p_points, Geometry3 r_mesh.vertices = ch.vertices; + // Tag which face each edge belongs to + LocalVector<int32_t> edge_faces; + edge_faces.resize(ch.edges.size()); + + for (uint32_t i = 0; i < ch.edges.size(); i++) { + edge_faces[i] = -1; + } + + for (uint32_t i = 0; i < ch.faces.size(); i++) { + const Edge *e_start = &ch.edges[ch.faces[i]]; + const Edge *e = e_start; + do { + int64_t ofs = e - ch.edges.ptr(); + edge_faces[ofs] = i; + + e = e->get_next_edge_of_face(); + } while (e != e_start); + } + // Copy the edges over. There's two "half-edges" for every edge, so we pick only one of them. r_mesh.edges.resize(ch.edges.size() / 2); + OAHashMap<uint64_t, int32_t> edge_map; + edge_map.reserve(ch.edges.size() * 4); // The higher the capacity, the faster the insert + uint32_t edges_copied = 0; for (uint32_t i = 0; i < ch.edges.size(); i++) { + ERR_CONTINUE(edge_faces[i] == -1); // Sanity check + uint32_t a = (&ch.edges[i])->get_source_vertex(); uint32_t b = (&ch.edges[i])->get_target_vertex(); if (a < b) { // Copy only the "canonical" edge. For the reverse edge, this will be false. ERR_BREAK(edges_copied >= (uint32_t)r_mesh.edges.size()); - r_mesh.edges.write[edges_copied].a = a; - r_mesh.edges.write[edges_copied].b = b; + r_mesh.edges[edges_copied].vertex_a = a; + r_mesh.edges[edges_copied].vertex_b = b; + r_mesh.edges[edges_copied].face_a = edge_faces[i]; + r_mesh.edges[edges_copied].face_b = -1; + + uint64_t key = a; + key <<= 32; + key |= b; + edge_map.insert(key, edges_copied); + edges_copied++; + } else { + uint64_t key = b; + key <<= 32; + key |= a; + int32_t index; + if (!edge_map.lookup(key, index)) { + ERR_PRINT("Invalid edge"); + } else { + r_mesh.edges[index].face_b = edge_faces[i]; + } } } + if (edges_copied != (uint32_t)r_mesh.edges.size()) { ERR_PRINT("Invalid edge count."); } @@ -2273,7 +2317,7 @@ Error ConvexHullComputer::convex_hull(const Vector<Vector3> &p_points, Geometry3 for (uint32_t i = 0; i < ch.faces.size(); i++) { const Edge *e_start = &ch.edges[ch.faces[i]]; const Edge *e = e_start; - Geometry3D::MeshData::Face &face = r_mesh.faces.write[i]; + Geometry3D::MeshData::Face &face = r_mesh.faces[i]; do { face.indices.push_back(e->get_target_vertex()); @@ -2284,8 +2328,8 @@ Error ConvexHullComputer::convex_hull(const Vector<Vector3> &p_points, Geometry3 // reverse indices: Godot wants clockwise, but this is counter-clockwise if (face.indices.size() > 2) { // reverse all but the first index. - int *indices = face.indices.ptrw(); - for (int c = 0; c < (face.indices.size() - 1) / 2; c++) { + int *indices = face.indices.ptr(); + for (uint32_t c = 0; c < (face.indices.size() - 1) / 2; c++) { SWAP(indices[c + 1], indices[face.indices.size() - 1 - c]); } } diff --git a/core/math/convex_hull.h b/core/math/convex_hull.h index cc41a794bd..ab6671a7d0 100644 --- a/core/math/convex_hull.h +++ b/core/math/convex_hull.h @@ -62,6 +62,10 @@ public: friend class ConvexHullComputer; public: + int32_t get_next_relative() const { + return next; + } + int32_t get_source_vertex() const { return (this + reverse)->target_vertex; } @@ -86,7 +90,7 @@ public: }; // Vertices of the output hull - Vector<Vector3> vertices; + LocalVector<Vector3> vertices; // Edges of the output hull LocalVector<Edge> edges; diff --git a/core/math/expression.cpp b/core/math/expression.cpp index dcec3929fe..26b809e7f2 100644 --- a/core/math/expression.cpp +++ b/core/math/expression.cpp @@ -1420,7 +1420,7 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression: Callable::CallError ce; Variant::call_utility_function(bifunc->func, &r_ret, (const Variant **)argp.ptr(), argp.size(), ce); if (ce.error != Callable::CallError::CALL_OK) { - r_error_str = "Builtin Call Failed. " + Variant::get_call_error_text(bifunc->func, (const Variant **)argp.ptr(), argp.size(), ce); + r_error_str = "Builtin call failed: " + Variant::get_call_error_text(bifunc->func, (const Variant **)argp.ptr(), argp.size(), ce); return true; } diff --git a/core/math/geometry_3d.cpp b/core/math/geometry_3d.cpp index c5871358ed..548b9e4620 100644 --- a/core/math/geometry_3d.cpp +++ b/core/math/geometry_3d.cpp @@ -141,21 +141,21 @@ real_t Geometry3D::get_closest_distance_between_segments(const Vector3 &p_p0, co void Geometry3D::MeshData::optimize_vertices() { HashMap<int, int> vtx_remap; - for (int i = 0; i < faces.size(); i++) { - for (int j = 0; j < faces[i].indices.size(); j++) { + for (uint32_t i = 0; i < faces.size(); i++) { + for (uint32_t j = 0; j < faces[i].indices.size(); j++) { int idx = faces[i].indices[j]; if (!vtx_remap.has(idx)) { int ni = vtx_remap.size(); vtx_remap[idx] = ni; } - faces.write[i].indices.write[j] = vtx_remap[idx]; + faces[i].indices[j] = vtx_remap[idx]; } } - for (int i = 0; i < edges.size(); i++) { - int a = edges[i].a; - int b = edges[i].b; + for (uint32_t i = 0; i < edges.size(); i++) { + int a = edges[i].vertex_a; + int b = edges[i].vertex_b; if (!vtx_remap.has(a)) { int ni = vtx_remap.size(); @@ -166,16 +166,16 @@ void Geometry3D::MeshData::optimize_vertices() { vtx_remap[b] = ni; } - edges.write[i].a = vtx_remap[a]; - edges.write[i].b = vtx_remap[b]; + edges[i].vertex_a = vtx_remap[a]; + edges[i].vertex_b = vtx_remap[b]; } - Vector<Vector3> new_vertices; + LocalVector<Vector3> new_vertices; new_vertices.resize(vtx_remap.size()); - for (int i = 0; i < vertices.size(); i++) { + for (uint32_t i = 0; i < vertices.size(); i++) { if (vtx_remap.has(i)) { - new_vertices.write[vtx_remap[i]] = vertices[i]; + new_vertices[vtx_remap[i]] = vertices[i]; } } vertices = new_vertices; @@ -751,7 +751,7 @@ Geometry3D::MeshData Geometry3D::build_convex_mesh(const Vector<Plane> &p_planes Vector3 center = p.center(); // make a quad clockwise - Vector<Vector3> vertices = { + LocalVector<Vector3> vertices = { center - up * subplane_size + right * subplane_size, center - up * subplane_size - right * subplane_size, center + up * subplane_size - right * subplane_size, @@ -763,7 +763,7 @@ Geometry3D::MeshData Geometry3D::build_convex_mesh(const Vector<Plane> &p_planes continue; } - Vector<Vector3> new_vertices; + LocalVector<Vector3> new_vertices; Plane clip = p_planes[j]; if (clip.normal.dot(p.normal) > 0.95f) { @@ -774,7 +774,7 @@ Geometry3D::MeshData Geometry3D::build_convex_mesh(const Vector<Plane> &p_planes break; } - for (int k = 0; k < vertices.size(); k++) { + for (uint32_t k = 0; k < vertices.size(); k++) { int k_n = (k + 1) % vertices.size(); Vector3 edge0_A = vertices[k]; @@ -816,9 +816,9 @@ Geometry3D::MeshData Geometry3D::build_convex_mesh(const Vector<Plane> &p_planes MeshData::Face face; // Add face indices. - for (int j = 0; j < vertices.size(); j++) { + for (uint32_t j = 0; j < vertices.size(); j++) { int idx = -1; - for (int k = 0; k < mesh.vertices.size(); k++) { + for (uint32_t k = 0; k < mesh.vertices.size(); k++) { if (mesh.vertices[k].distance_to(vertices[j]) < 0.001f) { idx = k; break; @@ -837,28 +837,34 @@ Geometry3D::MeshData Geometry3D::build_convex_mesh(const Vector<Plane> &p_planes // Add edge. - for (int j = 0; j < face.indices.size(); j++) { + for (uint32_t j = 0; j < face.indices.size(); j++) { int a = face.indices[j]; int b = face.indices[(j + 1) % face.indices.size()]; bool found = false; - for (int k = 0; k < mesh.edges.size(); k++) { - if (mesh.edges[k].a == a && mesh.edges[k].b == b) { + int found_idx = -1; + for (uint32_t k = 0; k < mesh.edges.size(); k++) { + if (mesh.edges[k].vertex_a == a && mesh.edges[k].vertex_b == b) { found = true; + found_idx = k; break; } - if (mesh.edges[k].b == a && mesh.edges[k].a == b) { + if (mesh.edges[k].vertex_b == a && mesh.edges[k].vertex_a == b) { found = true; + found_idx = k; break; } } if (found) { + mesh.edges[found_idx].face_b = j; continue; } MeshData::Edge edge; - edge.a = a; - edge.b = b; + edge.vertex_a = a; + edge.vertex_b = b; + edge.face_a = j; + edge.face_b = -1; mesh.edges.push_back(edge); } } diff --git a/core/math/geometry_3d.h b/core/math/geometry_3d.h index e5ace9db72..4b4c173a1e 100644 --- a/core/math/geometry_3d.h +++ b/core/math/geometry_3d.h @@ -33,6 +33,7 @@ #include "core/math/face3.h" #include "core/object/object.h" +#include "core/templates/local_vector.h" #include "core/templates/vector.h" class Geometry3D { @@ -539,18 +540,19 @@ public: struct MeshData { struct Face { Plane plane; - Vector<int> indices; + LocalVector<int> indices; }; - Vector<Face> faces; + LocalVector<Face> faces; struct Edge { - int a, b; + int vertex_a, vertex_b; + int face_a, face_b; }; - Vector<Edge> edges; + LocalVector<Edge> edges; - Vector<Vector3> vertices; + LocalVector<Vector3> vertices; void optimize_vertices(); }; diff --git a/core/math/math_defs.h b/core/math/math_defs.h index b8b82f2ff4..759667e2d5 100644 --- a/core/math/math_defs.h +++ b/core/math/math_defs.h @@ -116,6 +116,15 @@ enum Corner { CORNER_BOTTOM_LEFT }; +enum class EulerOrder { + XYZ, + XZY, + YXZ, + YZX, + ZXY, + ZYX +}; + /** * The "Real" type is an abstract type used for real numbers, such as 1.5, * in contrast to integer numbers. Precision can be controlled with the 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 3b2eab4ae2..a5d2fe5628 100644 --- a/core/math/plane.cpp +++ b/core/math/plane.cpp @@ -176,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/quaternion.cpp b/core/math/quaternion.cpp index 4a8d29e402..942a0b766e 100644 --- a/core/math/quaternion.cpp +++ b/core/math/quaternion.cpp @@ -38,25 +38,11 @@ real_t Quaternion::angle_to(const Quaternion &p_to) const { return Math::acos(CLAMP(d * d * 2 - 1, -1, 1)); } -// get_euler_xyz returns a vector containing the Euler angles in the format -// (ax,ay,az), where ax is the angle of rotation around x axis, -// and similar for other axes. -// This implementation uses XYZ convention (Z is the first rotation). -Vector3 Quaternion::get_euler_xyz() const { - Basis m(*this); - return m.get_euler(Basis::EULER_ORDER_XYZ); -} - -// get_euler_yxz returns a vector containing the Euler angles in the format -// (ax,ay,az), where ax is the angle of rotation around x axis, -// and similar for other axes. -// This implementation uses YXZ convention (Z is the first rotation). -Vector3 Quaternion::get_euler_yxz() const { +Vector3 Quaternion::get_euler(EulerOrder p_order) const { #ifdef MATH_CHECKS ERR_FAIL_COND_V_MSG(!is_normalized(), Vector3(0, 0, 0), "The quaternion must be normalized."); #endif - Basis m(*this); - return m.get_euler(Basis::EULER_ORDER_YXZ); + return Basis(*this).get_euler(p_order); } void Quaternion::operator*=(const Quaternion &p_q) { @@ -79,6 +65,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()); } @@ -326,7 +316,7 @@ Quaternion::Quaternion(const Vector3 &p_axis, real_t p_angle) { // (ax, ay, az), where ax is the angle of rotation around x axis, // and similar for other axes. // This implementation uses YXZ convention (Z is the first rotation). -Quaternion::Quaternion(const Vector3 &p_euler) { +Quaternion Quaternion::from_euler(const Vector3 &p_euler) { real_t half_a1 = p_euler.y * 0.5f; real_t half_a2 = p_euler.x * 0.5f; real_t half_a3 = p_euler.z * 0.5f; @@ -342,8 +332,9 @@ Quaternion::Quaternion(const Vector3 &p_euler) { real_t cos_a3 = Math::cos(half_a3); real_t sin_a3 = Math::sin(half_a3); - x = sin_a1 * cos_a2 * sin_a3 + cos_a1 * sin_a2 * cos_a3; - y = sin_a1 * cos_a2 * cos_a3 - cos_a1 * sin_a2 * sin_a3; - z = -sin_a1 * sin_a2 * cos_a3 + cos_a1 * cos_a2 * sin_a3; - w = sin_a1 * sin_a2 * sin_a3 + cos_a1 * cos_a2 * cos_a3; + return Quaternion( + sin_a1 * cos_a2 * sin_a3 + cos_a1 * sin_a2 * cos_a3, + sin_a1 * cos_a2 * cos_a3 - cos_a1 * sin_a2 * sin_a3, + -sin_a1 * sin_a2 * cos_a3 + cos_a1 * cos_a2 * sin_a3, + sin_a1 * sin_a2 * sin_a3 + cos_a1 * cos_a2 * cos_a3); } diff --git a/core/math/quaternion.h b/core/math/quaternion.h index 178cfaca70..c5af2121d9 100644 --- a/core/math/quaternion.h +++ b/core/math/quaternion.h @@ -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; @@ -65,9 +66,8 @@ struct _NO_DISCARD_ Quaternion { _FORCE_INLINE_ real_t dot(const Quaternion &p_q) const; real_t angle_to(const Quaternion &p_to) const; - Vector3 get_euler_xyz() const; - Vector3 get_euler_yxz() const; - Vector3 get_euler() const { return get_euler_yxz(); }; + Vector3 get_euler(EulerOrder p_order = EulerOrder::YXZ) const; + static Quaternion from_euler(const Vector3 &p_euler); Quaternion slerp(const Quaternion &p_to, const real_t &p_weight) const; Quaternion slerpni(const Quaternion &p_to, const real_t &p_weight) const; @@ -127,8 +127,6 @@ struct _NO_DISCARD_ Quaternion { Quaternion(const Vector3 &p_axis, real_t p_angle); - Quaternion(const Vector3 &p_euler); - Quaternion(const Quaternion &p_q) : x(p_q.x), y(p_q.y), diff --git a/core/math/quick_hull.cpp b/core/math/quick_hull.cpp index c7727a44a1..c194e1cc21 100644 --- a/core/math/quick_hull.cpp +++ b/core/math/quick_hull.cpp @@ -369,7 +369,7 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry3D::MeshData &r_ for (List<Geometry3D::MeshData::Face>::Element *E = ret_faces.front(); E; E = E->next()) { Geometry3D::MeshData::Face &f = E->get(); - for (int i = 0; i < f.indices.size(); i++) { + for (uint32_t i = 0; i < f.indices.size(); i++) { int a = E->get().indices[i]; int b = E->get().indices[(i + 1) % f.indices.size()]; Edge e(a, b); @@ -436,17 +436,24 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry3D::MeshData &r_ r_mesh.faces.clear(); r_mesh.faces.resize(ret_faces.size()); + HashMap<List<Geometry3D::MeshData::Face>::Element *, int> face_indices; + int idx = 0; - for (const Geometry3D::MeshData::Face &E : ret_faces) { - r_mesh.faces.write[idx++] = E; + for (List<Geometry3D::MeshData::Face>::Element *E = ret_faces.front(); E; E = E->next()) { + face_indices[E] = idx; + r_mesh.faces[idx++] = E->get(); } r_mesh.edges.resize(ret_edges.size()); idx = 0; for (const KeyValue<Edge, RetFaceConnect> &E : ret_edges) { Geometry3D::MeshData::Edge e; - e.a = E.key.vertices[0]; - e.b = E.key.vertices[1]; - r_mesh.edges.write[idx++] = e; + e.vertex_a = E.key.vertices[0]; + e.vertex_b = E.key.vertices[1]; + ERR_CONTINUE(!face_indices.has(E.value.left)); + ERR_CONTINUE(!face_indices.has(E.value.right)); + e.face_a = face_indices[E.value.left]; + e.face_b = face_indices[E.value.right]; + r_mesh.edges[idx++] = e; } r_mesh.vertices = p_points; diff --git a/core/math/random_number_generator.h b/core/math/random_number_generator.h index 9352bae0a6..bf67154cd6 100644 --- a/core/math/random_number_generator.h +++ b/core/math/random_number_generator.h @@ -57,7 +57,7 @@ public: _FORCE_INLINE_ real_t randfn(real_t p_mean = 0.0, real_t p_deviation = 1.0) { return randbase.randfn(p_mean, p_deviation); } _FORCE_INLINE_ int randi_range(int p_from, int p_to) { return randbase.random(p_from, p_to); } - RandomNumberGenerator() {} + RandomNumberGenerator() { randbase.randomize(); } }; #endif // RANDOM_NUMBER_GENERATOR_H 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 50dd2dc1df..9863405d8e 100644 --- a/core/math/rect2.h +++ b/core/math/rect2.h @@ -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; } diff --git a/core/math/transform_2d.cpp b/core/math/transform_2d.cpp index 2bfefe979f..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); 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 6741ef4034..3285cbd664 100644 --- a/core/math/transform_3d.cpp +++ b/core/math/transform_3d.cpp @@ -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 44d6d826f3..cb347aa1c1 100644 --- a/core/math/transform_3d.h +++ b/core/math/transform_3d.h @@ -75,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/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 9fd980aaff..3b189f7ed4 100644 --- a/core/math/vector4.cpp +++ b/core/math/vector4.cpp @@ -64,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 ac7b6c3aee..7c4bdc1788 100644 --- a/core/math/vector4.h +++ b/core/math/vector4.h @@ -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 ca56add2ab..ac6ad0fdd2 100644 --- a/core/object/class_db.cpp +++ b/core/object/class_db.cpp @@ -31,6 +31,7 @@ #include "class_db.h" #include "core/config/engine.h" +#include "core/object/script_language.h" #include "core/os/mutex.h" #include "core/version.h" @@ -376,7 +377,12 @@ bool ClassDB::is_virtual(const StringName &p_class) { OBJTYPE_RLOCK; ClassInfo *ti = classes.getptr(p_class); - ERR_FAIL_COND_V_MSG(!ti, false, "Cannot get class '" + String(p_class) + "'."); + if (!ti) { + if (!ScriptServer::is_global_class(p_class)) { + ERR_FAIL_V_MSG(false, "Cannot get class '" + String(p_class) + "'."); + } + return false; + } #ifdef TOOLS_ENABLED if (ti->api == API_EDITOR && !Engine::get_singleton()->is_editor_hint()) { return false; @@ -1454,7 +1460,7 @@ Variant ClassDB::class_get_default_property_value(const StringName &p_class, con if (Engine::get_singleton()->has_singleton(p_class)) { c = Engine::get_singleton()->get_singleton_object(p_class); cleanup_c = false; - } else if (ClassDB::can_instantiate(p_class) && !ClassDB::is_virtual(p_class)) { + } else if (ClassDB::can_instantiate(p_class) && !ClassDB::is_virtual(p_class)) { // Keep this condition in sync with doc_tools.cpp get_documentation_default_value. c = ClassDB::instantiate(p_class); cleanup_c = true; } @@ -1528,7 +1534,10 @@ void ClassDB::register_extension_class(ObjectNativeExtension *p_extension) { c.api = p_extension->editor_class ? API_EDITOR_EXTENSION : API_EXTENSION; c.native_extension = p_extension; c.name = p_extension->class_name; - c.creation_func = parent->creation_func; + c.is_virtual = p_extension->is_virtual; + if (!p_extension->is_abstract) { + c.creation_func = parent->creation_func; + } c.inherits = parent->name; c.class_ptr = parent->class_ptr; c.inherits_ptr = parent; diff --git a/core/object/make_virtuals.py b/core/object/make_virtuals.py index 326a9277ff..61bf6d900a 100644 --- a/core/object/make_virtuals.py +++ b/core/object/make_virtuals.py @@ -16,7 +16,8 @@ _FORCE_INLINE_ bool _gdvirtual_##m_name##_call($CALLARGS) $CONST { \\ } \\ }\\ if (unlikely(_get_extension() && !_gdvirtual_##m_name##_initialized)) {\\ - _gdvirtual_##m_name = (_get_extension() && _get_extension()->get_virtual) ? _get_extension()->get_virtual(_get_extension()->class_userdata, #m_name) : (GDNativeExtensionClassCallVirtual) nullptr;\\ + /* TODO: C-style cast because GDNativeStringNamePtr's const qualifier is broken (see https://github.com/godotengine/godot/pull/67751) */\\ + _gdvirtual_##m_name = (_get_extension() && _get_extension()->get_virtual) ? _get_extension()->get_virtual(_get_extension()->class_userdata, (GDNativeStringNamePtr)&_gdvirtual_##m_name##_sn) : (GDNativeExtensionClassCallVirtual) nullptr;\\ _gdvirtual_##m_name##_initialized = true;\\ }\\ if (_gdvirtual_##m_name) {\\ @@ -40,7 +41,8 @@ _FORCE_INLINE_ bool _gdvirtual_##m_name##_overridden() const { \\ return _script_instance->has_method(_gdvirtual_##m_name##_sn);\\ }\\ if (unlikely(_get_extension() && !_gdvirtual_##m_name##_initialized)) {\\ - _gdvirtual_##m_name = (_get_extension() && _get_extension()->get_virtual) ? _get_extension()->get_virtual(_get_extension()->class_userdata, #m_name) : (GDNativeExtensionClassCallVirtual) nullptr;\\ + /* TODO: C-style cast because GDNativeStringNamePtr's const qualifier is broken (see https://github.com/godotengine/godot/pull/67751) */\\ + _gdvirtual_##m_name = (_get_extension() && _get_extension()->get_virtual) ? _get_extension()->get_virtual(_get_extension()->class_userdata, (GDNativeStringNamePtr)&_gdvirtual_##m_name##_sn) : (GDNativeExtensionClassCallVirtual) nullptr;\\ _gdvirtual_##m_name##_initialized = true;\\ }\\ if (_gdvirtual_##m_name) {\\ diff --git a/core/object/method_bind.cpp b/core/object/method_bind.cpp index 0edc7a90c2..5381c596ce 100644 --- a/core/object/method_bind.cpp +++ b/core/object/method_bind.cpp @@ -63,7 +63,9 @@ PropertyInfo MethodBind::get_argument_info(int p_argument) const { PropertyInfo info = _gen_argument_type_info(p_argument); #ifdef DEBUG_METHODS_ENABLED - info.name = p_argument < arg_names.size() ? String(arg_names[p_argument]) : String("_unnamed_arg" + itos(p_argument)); + if (info.name.is_empty()) { + info.name = p_argument < arg_names.size() ? String(arg_names[p_argument]) : String("_unnamed_arg" + itos(p_argument)); + } #endif return info; } 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/object.cpp b/core/object/object.cpp index c275164b14..d27e0d7621 100644 --- a/core/object/object.cpp +++ b/core/object/object.cpp @@ -808,7 +808,8 @@ String Object::to_string() { } if (_extension && _extension->to_string) { String ret; - _extension->to_string(_extension_instance, &ret); + GDNativeBool is_valid; + _extension->to_string(_extension_instance, &is_valid, &ret); return ret; } return "<" + get_class() + "#" + itos(get_instance_id()) + ">"; @@ -1468,8 +1469,8 @@ void Object::_bind_methods() { ClassDB::bind_method(D_METHOD("is_class", "class"), &Object::is_class); ClassDB::bind_method(D_METHOD("set", "property", "value"), &Object::_set_bind); ClassDB::bind_method(D_METHOD("get", "property"), &Object::_get_bind); - ClassDB::bind_method(D_METHOD("set_indexed", "property", "value"), &Object::_set_indexed_bind); - ClassDB::bind_method(D_METHOD("get_indexed", "property"), &Object::_get_indexed_bind); + ClassDB::bind_method(D_METHOD("set_indexed", "property_path", "value"), &Object::_set_indexed_bind); + ClassDB::bind_method(D_METHOD("get_indexed", "property_path"), &Object::_get_indexed_bind); ClassDB::bind_method(D_METHOD("get_property_list"), &Object::_get_property_list_bind); ClassDB::bind_method(D_METHOD("get_method_list"), &Object::_get_method_list_bind); ClassDB::bind_method(D_METHOD("notification", "what", "reversed"), &Object::notification, DEFVAL(false)); @@ -1856,6 +1857,46 @@ void ObjectDB::debug_objects(DebugFunc p_func) { } void Object::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const { + if (p_idx == 0) { + if (p_function == "connect" || p_function == "is_connected" || p_function == "disconnect" || p_function == "emit_signal" || p_function == "has_signal") { + List<MethodInfo> signals; + get_signal_list(&signals); + for (const MethodInfo &E : signals) { + r_options->push_back(E.name.quote()); + } + } else if (p_function == "call" || p_function == "call_deferred" || p_function == "callv" || p_function == "has_method") { + List<MethodInfo> methods; + get_method_list(&methods); + for (const MethodInfo &E : methods) { + if (E.name.begins_with("_") && !(E.flags & METHOD_FLAG_VIRTUAL)) { + continue; + } + r_options->push_back(E.name.quote()); + } + } else if (p_function == "set" || p_function == "set_deferred" || p_function == "get") { + List<PropertyInfo> properties; + get_property_list(&properties); + for (const PropertyInfo &E : properties) { + if (E.usage & PROPERTY_USAGE_DEFAULT && !(E.usage & PROPERTY_USAGE_INTERNAL)) { + r_options->push_back(E.name.quote()); + } + } + } else if (p_function == "set_meta" || p_function == "get_meta" || p_function == "has_meta" || p_function == "remove_meta") { + for (const KeyValue<StringName, Variant> &K : metadata) { + r_options->push_back(String(K.key).quote()); + } + } + } else if (p_idx == 2) { + if (p_function == "connect") { + // Ideally, the constants should be inferred by the parameter. + // But a parameter's PropertyInfo does not store the enum they come from, so this will do for now. + List<StringName> constants; + ClassDB::get_enum_constants("Object", "ConnectFlags", &constants); + for (const StringName &E : constants) { + r_options->push_back(String(E)); + } + } + } } SpinLock ObjectDB::spin_lock; diff --git a/core/object/object.h b/core/object/object.h index 5ba5453b31..7bb88998a2 100644 --- a/core/object/object.h +++ b/core/object/object.h @@ -89,8 +89,8 @@ enum PropertyHint { PROPERTY_HINT_SAVE_FILE, ///< a file path must be passed, hint_text (optionally) is a filter "*.png,*.wav,*.doc,". This opens a save dialog PROPERTY_HINT_GLOBAL_SAVE_FILE, ///< a file path must be passed, hint_text (optionally) is a filter "*.png,*.wav,*.doc,". This opens a save dialog PROPERTY_HINT_INT_IS_OBJECTID, - PROPERTY_HINT_ARRAY_TYPE, PROPERTY_HINT_INT_IS_POINTER, + PROPERTY_HINT_ARRAY_TYPE, PROPERTY_HINT_LOCALE_ID, PROPERTY_HINT_LOCALIZABLE_STRING, PROPERTY_HINT_NODE_TYPE, ///< a node object type @@ -133,7 +133,7 @@ enum PropertyUsageFlags { PROPERTY_USAGE_ARRAY = 1 << 29, // Used in the inspector to group properties as elements of an array. PROPERTY_USAGE_DEFAULT = PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_EDITOR, - PROPERTY_USAGE_DEFAULT_INTL = PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_INTERNATIONALIZED, + PROPERTY_USAGE_DEFAULT_INTL = PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNATIONALIZED, PROPERTY_USAGE_NO_EDITOR = PROPERTY_USAGE_STORAGE, }; @@ -192,10 +192,10 @@ struct PropertyInfo { explicit PropertyInfo(const GDNativePropertyInfo &pinfo) : type((Variant::Type)pinfo.type), - name(pinfo.name), - class_name(pinfo.class_name), // can be null + name(*reinterpret_cast<StringName *>(pinfo.name)), + class_name(*reinterpret_cast<StringName *>(pinfo.class_name)), hint((PropertyHint)pinfo.hint), - hint_string(pinfo.hint_string), // can be null + hint_string(*reinterpret_cast<String *>(pinfo.hint_string)), usage(pinfo.usage) {} bool operator==(const PropertyInfo &p_info) const { @@ -242,6 +242,20 @@ struct MethodInfo { MethodInfo() {} + explicit MethodInfo(const GDNativeMethodInfo &pinfo) : + name(*reinterpret_cast<StringName *>(pinfo.name)), + return_val(PropertyInfo(pinfo.return_value)), + flags(pinfo.flags), + id(pinfo.id) { + for (uint32_t j = 0; j < pinfo.argument_count; j++) { + arguments.push_back(PropertyInfo(pinfo.arguments[j])); + } + const Variant *def_values = (const Variant *)pinfo.default_arguments; + for (uint32_t j = 0; j < pinfo.default_argument_count; j++) { + default_arguments.push_back(def_values[j]); + } + } + void _push_params(const PropertyInfo &p_param) { arguments.push_back(p_param); } @@ -295,6 +309,8 @@ struct ObjectNativeExtension { StringName parent_class_name; StringName class_name; bool editor_class = false; + bool is_virtual = false; + bool is_abstract = false; GDNativeExtensionClassSet set; GDNativeExtensionClassGet get; GDNativeExtensionClassGetPropertyList get_property_list; diff --git a/core/object/script_language.cpp b/core/object/script_language.cpp index 9e26289e66..056c57a5f1 100644 --- a/core/object/script_language.cpp +++ b/core/object/script_language.cpp @@ -184,10 +184,10 @@ void ScriptServer::unregister_language(const ScriptLanguage *p_language) { } void ScriptServer::init_languages() { - { //load global classes + { // Load global classes. global_classes_clear(); if (ProjectSettings::get_singleton()->has_setting("_global_script_classes")) { - Array script_classes = ProjectSettings::get_singleton()->get("_global_script_classes"); + Array script_classes = GLOBAL_GET("_global_script_classes"); for (int i = 0; i < script_classes.size(); i++) { Dictionary c = script_classes[i]; @@ -305,7 +305,7 @@ void ScriptServer::save_global_classes() { Array old; if (ProjectSettings::get_singleton()->has_setting("_global_script_classes")) { - old = ProjectSettings::get_singleton()->get("_global_script_classes"); + old = GLOBAL_GET("_global_script_classes"); } if ((!old.is_empty() || gcarr.is_empty()) && gcarr.hash() == old.hash()) { return; diff --git a/core/object/script_language_extension.h b/core/object/script_language_extension.h index 7e74f6a2be..9a2a176096 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 @@ -686,7 +687,6 @@ public: if (r_is_valid) { *r_is_valid = is_valid != 0; } - return Variant::Type(type); } return Variant::NIL; @@ -726,19 +726,7 @@ public: uint32_t mcount; const GDNativeMethodInfo *minfo = native_info->get_method_list_func(instance, &mcount); for (uint32_t i = 0; i < mcount; i++) { - MethodInfo m; - m.name = minfo[i].name; - m.flags = minfo[i].flags; - m.id = minfo[i].id; - m.return_val = PropertyInfo(minfo[i].return_value); - for (uint32_t j = 0; j < minfo[i].argument_count; j++) { - m.arguments.push_back(PropertyInfo(minfo[i].arguments[j])); - } - const Variant *def_values = (const Variant *)minfo[i].default_arguments; - for (uint32_t j = 0; j < minfo[i].default_argument_count; j++) { - m.default_arguments.push_back(def_values[j]); - } - p_list->push_back(m); + p_list->push_back(MethodInfo(minfo[i])); } if (native_info->free_method_list_func) { native_info->free_method_list_func(instance, minfo); @@ -772,7 +760,8 @@ public: virtual String to_string(bool *r_valid) override { if (native_info->to_string_func) { GDNativeBool valid; - String ret = native_info->to_string_func(instance, &valid); + String ret; + native_info->to_string_func(instance, &valid, reinterpret_cast<GDNativeStringPtr>(&ret)); if (r_valid) { *r_valid = valid != 0; } diff --git a/core/object/undo_redo.cpp b/core/object/undo_redo.cpp index aa66e86bc0..9f8a1de697 100644 --- a/core/object/undo_redo.cpp +++ b/core/object/undo_redo.cpp @@ -423,6 +423,10 @@ String UndoRedo::get_current_action_name() const { return actions[current_action].name; } +int UndoRedo::get_action_level() const { + return action_level; +} + bool UndoRedo::has_undo() const { return current_action >= 0; } diff --git a/core/object/undo_redo.h b/core/object/undo_redo.h index c7c58697c3..9c6d2d10ed 100644 --- a/core/object/undo_redo.h +++ b/core/object/undo_redo.h @@ -120,6 +120,7 @@ public: bool redo(); bool undo(); String get_current_action_name() const; + int get_action_level() const; int get_history_count(); int get_current_action(); diff --git a/core/os/main_loop.cpp b/core/os/main_loop.cpp index a96e1989f9..c0504a174c 100644 --- a/core/os/main_loop.cpp +++ b/core/os/main_loop.cpp @@ -65,21 +65,15 @@ void MainLoop::initialize() { } bool MainLoop::physics_process(double p_time) { - bool quit; - if (GDVIRTUAL_CALL(_physics_process, p_time, quit)) { - return quit; - } - - return false; + bool quit = false; + GDVIRTUAL_CALL(_physics_process, p_time, quit); + return quit; } bool MainLoop::process(double p_time) { - bool quit; - if (GDVIRTUAL_CALL(_process, p_time, quit)) { - return quit; - } - - return false; + bool quit = false; + GDVIRTUAL_CALL(_process, p_time, quit); + return quit; } void MainLoop::finalize() { diff --git a/core/os/midi_driver.cpp b/core/os/midi_driver.cpp index 410b62068a..79eef95ef2 100644 --- a/core/os/midi_driver.cpp +++ b/core/os/midi_driver.cpp @@ -86,11 +86,6 @@ void MIDIDriver::receive_input_packet(uint64_t timestamp, uint8_t *data, uint32_ if (length >= 2 + param_position) { event->set_pitch(data[param_position]); event->set_velocity(data[param_position + 1]); - - if (event->get_message() == MIDIMessage::NOTE_ON && event->get_velocity() == 0) { - // https://www.midi.org/forum/228-writing-midi-software-send-note-off,-or-zero-velocity-note-on - event->set_message(MIDIMessage::NOTE_OFF); - } } break; diff --git a/core/os/os.h b/core/os/os.h index 1a5e45968d..af7b40f3ec 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -123,6 +123,8 @@ public: int get_display_driver_id() const { return _display_driver_id; } + virtual Vector<String> get_video_adapter_driver_info() const = 0; + void print_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, bool p_editor_notify = false, Logger::ErrorType p_type = Logger::ERR_ERROR); void print(const char *p_format, ...) _PRINTF_FORMAT_ATTRIBUTE_2_3; void print_rich(const char *p_format, ...) _PRINTF_FORMAT_ATTRIBUTE_2_3; diff --git a/core/string/optimized_translation.cpp b/core/string/optimized_translation.cpp index b130c2fc79..2fb3b54e27 100644 --- a/core/string/optimized_translation.cpp +++ b/core/string/optimized_translation.cpp @@ -267,6 +267,39 @@ StringName OptimizedTranslation::get_message(const StringName &p_src_text, const } } +Vector<String> OptimizedTranslation::get_translated_message_list() const { + Vector<String> msgs; + + const int *htr = hash_table.ptr(); + const uint32_t *htptr = (const uint32_t *)&htr[0]; + const int *btr = bucket_table.ptr(); + const uint32_t *btptr = (const uint32_t *)&btr[0]; + const uint8_t *sr = strings.ptr(); + const char *sptr = (const char *)&sr[0]; + + for (int i = 0; i < hash_table.size(); i++) { + uint32_t p = htptr[i]; + if (p != 0xFFFFFFFF) { + const Bucket &bucket = *(const Bucket *)&btptr[p]; + for (int j = 0; j < bucket.size; j++) { + if (bucket.elem[j].comp_size == bucket.elem[j].uncomp_size) { + String rstr; + rstr.parse_utf8(&sptr[bucket.elem[j].str_offset], bucket.elem[j].uncomp_size); + msgs.push_back(rstr); + } else { + CharString uncomp; + uncomp.resize(bucket.elem[j].uncomp_size + 1); + smaz_decompress(&sptr[bucket.elem[j].str_offset], bucket.elem[j].comp_size, uncomp.ptrw(), bucket.elem[j].uncomp_size); + String rstr; + rstr.parse_utf8(uncomp.get_data()); + msgs.push_back(rstr); + } + } + } + } + return msgs; +} + StringName OptimizedTranslation::get_plural_message(const StringName &p_src_text, const StringName &p_plural_text, int p_n, const StringName &p_context) const { // The use of plurals translation is not yet supported in OptimizedTranslation. return get_message(p_src_text, p_context); diff --git a/core/string/optimized_translation.h b/core/string/optimized_translation.h index f3dbfe8f5c..1cd12782d0 100644 --- a/core/string/optimized_translation.h +++ b/core/string/optimized_translation.h @@ -81,6 +81,7 @@ protected: public: virtual StringName get_message(const StringName &p_src_text, const StringName &p_context = "") const override; //overridable for other implementations virtual StringName get_plural_message(const StringName &p_src_text, const StringName &p_plural_text, int p_n, const StringName &p_context = "") const override; + virtual Vector<String> get_translated_message_list() const override; void generate(const Ref<Translation> &p_from); OptimizedTranslation() {} diff --git a/core/string/translation.cpp b/core/string/translation.cpp index 9ee7f2b17b..d1ac91957a 100644 --- a/core/string/translation.cpp +++ b/core/string/translation.cpp @@ -59,6 +59,18 @@ Vector<String> Translation::_get_message_list() const { return msgs; } +Vector<String> Translation::get_translated_message_list() const { + Vector<String> msgs; + msgs.resize(translation_map.size()); + int idx = 0; + for (const KeyValue<StringName, StringName> &E : translation_map) { + msgs.set(idx, E.value); + idx += 1; + } + + return msgs; +} + void Translation::_set_messages(const Dictionary &p_messages) { List<Variant> keys; p_messages.get_key_list(&keys); @@ -140,6 +152,7 @@ void Translation::_bind_methods() { ClassDB::bind_method(D_METHOD("get_plural_message", "src_message", "src_plural_message", "n", "context"), &Translation::get_plural_message, DEFVAL("")); ClassDB::bind_method(D_METHOD("erase_message", "src_message", "context"), &Translation::erase_message, DEFVAL("")); ClassDB::bind_method(D_METHOD("get_message_list"), &Translation::_get_message_list); + ClassDB::bind_method(D_METHOD("get_translated_message_list"), &Translation::get_translated_message_list); ClassDB::bind_method(D_METHOD("get_message_count"), &Translation::get_message_count); ClassDB::bind_method(D_METHOD("_set_messages", "messages"), &Translation::_set_messages); ClassDB::bind_method(D_METHOD("_get_messages"), &Translation::_get_messages); @@ -293,6 +306,10 @@ void TranslationServer::init_locale_info() { } String TranslationServer::standardize_locale(const String &p_locale) const { + return _standardize_locale(p_locale, false); +} + +String TranslationServer::_standardize_locale(const String &p_locale, bool p_add_defaults) const { // Replaces '-' with '_' for macOS style locales. String univ_locale = p_locale.replace("-", "_"); @@ -354,24 +371,26 @@ String TranslationServer::standardize_locale(const String &p_locale) const { } // Add script code base on language and country codes for some ambiguous cases. - 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_name) { - if (country_name.is_empty() || info.supported_countries.has(country_name)) { - script_name = info.script; - break; + if (p_add_defaults) { + 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_name) { + if (country_name.is_empty() || info.supported_countries.has(country_name)) { + script_name = info.script; + break; + } } } } - } - 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_name && info.script == script_name) { - country_name = info.default_country; - break; + 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_name && info.script == script_name) { + country_name = info.default_country; + break; + } } } } @@ -391,8 +410,8 @@ String TranslationServer::standardize_locale(const String &p_locale) const { } int TranslationServer::compare_locales(const String &p_locale_a, const String &p_locale_b) const { - String locale_a = standardize_locale(p_locale_a); - String locale_b = standardize_locale(p_locale_b); + String locale_a = _standardize_locale(p_locale_a, true); + String locale_b = _standardize_locale(p_locale_b, true); if (locale_a == locale_b) { // Exact match. @@ -628,7 +647,7 @@ TranslationServer *TranslationServer::singleton = nullptr; bool TranslationServer::_load_translations(const String &p_from) { if (ProjectSettings::get_singleton()->has_setting(p_from)) { - const Vector<String> &translation_names = ProjectSettings::get_singleton()->get(p_from); + const Vector<String> &translation_names = GLOBAL_GET(p_from); int tcount = translation_names.size(); diff --git a/core/string/translation.h b/core/string/translation.h index 3f97a8d4fc..5e8344baac 100644 --- a/core/string/translation.h +++ b/core/string/translation.h @@ -64,6 +64,7 @@ public: virtual void erase_message(const StringName &p_src_text, const StringName &p_context = ""); virtual void get_message_list(List<StringName> *r_messages) const; virtual int get_message_count() const; + virtual Vector<String> get_translated_message_list() const; Translation() {} }; @@ -102,6 +103,7 @@ class TranslationServer : public Object { static TranslationServer *singleton; bool _load_translations(const String &p_from); + String _standardize_locale(const String &p_locale, bool p_add_defaults) const; StringName _get_message_from_translations(const StringName &p_message, const StringName &p_context, const String &p_locale, bool plural, const String &p_message_plural = "", int p_n = 0) const; diff --git a/core/string/translation_po.cpp b/core/string/translation_po.cpp index fa656b634d..724c1d42bc 100644 --- a/core/string/translation_po.cpp +++ b/core/string/translation_po.cpp @@ -103,6 +103,23 @@ void TranslationPO::_set_messages(const Dictionary &p_messages) { } } +Vector<String> TranslationPO::get_translated_message_list() const { + Vector<String> msgs; + for (const KeyValue<StringName, HashMap<StringName, Vector<StringName>>> &E : translation_map) { + if (E.key != StringName()) { + continue; + } + + for (const KeyValue<StringName, Vector<StringName>> &E2 : E.value) { + for (const StringName &E3 : E2.value) { + msgs.push_back(E3); + } + } + } + + return msgs; +} + Vector<String> TranslationPO::_get_message_list() const { // Return all keys in translation_map. diff --git a/core/string/translation_po.h b/core/string/translation_po.h index 7d63af2246..c50ea85744 100644 --- a/core/string/translation_po.h +++ b/core/string/translation_po.h @@ -70,6 +70,7 @@ protected: static void _bind_methods(); public: + Vector<String> get_translated_message_list() const override; void get_message_list(List<StringName> *r_messages) const override; int get_message_count() const override; void add_message(const StringName &p_src_text, const StringName &p_xlated_text, const StringName &p_context = "") override; diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp index 6218c21cde..8993f9667d 100644 --- a/core/string/ustring.cpp +++ b/core/string/ustring.cpp @@ -1180,9 +1180,14 @@ Vector<String> String::split(const String &p_splitter, bool p_allow_empty, int p int len = length(); while (true) { - int end = find(p_splitter, from); - if (end < 0) { - end = len; + int end; + if (p_splitter.is_empty()) { + end = from + 1; + } else { + end = find(p_splitter, from); + if (end < 0) { + end = len; + } } if (p_allow_empty || (end > from)) { if (p_maxsplit <= 0) { @@ -1223,7 +1228,15 @@ Vector<String> String::rsplit(const String &p_splitter, bool p_allow_empty, int break; } - int left_edge = rfind(p_splitter, remaining_len - p_splitter.length()); + int left_edge; + if (p_splitter.is_empty()) { + left_edge = remaining_len - 1; + if (left_edge == 0) { + left_edge--; // Skip to the < 0 condition. + } + } else { + left_edge = rfind(p_splitter, remaining_len - p_splitter.length()); + } if (left_edge < 0) { // no more splitters, we're done @@ -1447,15 +1460,25 @@ String String::num(double p_num, int p_decimals) { fmt[5] = 'f'; fmt[6] = 0; } - char buf[256]; + // if we want to convert a double with as much decimal places as as + // DBL_MAX or DBL_MIN then we would theoretically need a buffer of at least + // DBL_MAX_10_EXP + 2 for DBL_MAX and DBL_MAX_10_EXP + 4 for DBL_MIN. + // BUT those values where still giving me exceptions, so I tested from + // DBL_MAX_10_EXP + 10 incrementing one by one and DBL_MAX_10_EXP + 17 (325) + // was the first buffer size not to throw an exception + char buf[325]; #if defined(__GNUC__) || defined(_MSC_VER) - snprintf(buf, 256, fmt, p_num); + // PLEASE NOTE that, albeit vcrt online reference states that snprintf + // should safely truncate the output to the given buffer size, we have + // found a case where this is not true, so we should create a buffer + // as big as needed + snprintf(buf, 325, fmt, p_num); #else sprintf(buf, fmt, p_num); #endif - buf[255] = 0; + buf[324] = 0; //destroy trailing zeroes { bool period = false; @@ -1567,10 +1590,11 @@ String String::num_real(double p_num, bool p_trailing) { #else int decimals = 6; #endif - // We want to align the digits to the above sane default, so we only - // need to subtract log10 for numbers with a positive power of ten. - if (p_num > 10) { - decimals -= (int)floor(log10(p_num)); + // We want to align the digits to the above sane default, so we only need + // to subtract log10 for numbers with a positive power of ten magnitude. + double abs_num = Math::abs(p_num); + if (abs_num > 10) { + decimals -= (int)floor(log10(abs_num)); } return num(p_num, decimals); } @@ -2815,7 +2839,7 @@ String String::substr(int p_from, int p_chars) const { return String(*this); } - String s = String(); + String s; s.copy_from_unchecked(&get_data()[p_from], p_chars); return s; } @@ -3667,29 +3691,43 @@ bool String::is_network_share_path() const { String String::simplify_path() const { String s = *this; String drive; - if (s.begins_with("local://")) { - drive = "local://"; - s = s.substr(8, s.length()); - } else if (s.begins_with("res://")) { - drive = "res://"; - s = s.substr(6, s.length()); - } else if (s.begins_with("user://")) { - drive = "user://"; - s = s.substr(7, s.length()); - } else if (is_network_share_path()) { - drive = s.substr(0, 2); - s = s.substr(2, s.length() - 2); - } else if (s.begins_with("/") || s.begins_with("\\")) { - drive = s.substr(0, 1); - s = s.substr(1, s.length() - 1); - } else { - int p = s.find(":/"); - if (p == -1) { - p = s.find(":\\"); + + // Check if we have a special path (like res://) or a protocol identifier. + int p = s.find("://"); + bool found = false; + if (p > 0) { + bool only_chars = true; + for (int i = 0; i < p; i++) { + if (!is_ascii_alphanumeric_char(s[i])) { + only_chars = false; + break; + } + } + if (only_chars) { + found = true; + drive = s.substr(0, p + 3); + s = s.substr(p + 3); } - if (p != -1 && p < s.find("/")) { - drive = s.substr(0, p + 2); - s = s.substr(p + 2, s.length()); + } + if (!found) { + if (is_network_share_path()) { + // Network path, beginning with // or \\. + drive = s.substr(0, 2); + s = s.substr(2); + } else if (s.begins_with("/") || s.begins_with("\\")) { + // Absolute path. + drive = s.substr(0, 1); + s = s.substr(1); + } else { + // Windows-style drive path, like C:/ or C:\. + p = s.find(":/"); + if (p == -1) { + p = s.find(":\\"); + } + if (p != -1 && p < s.find("/")) { + drive = s.substr(0, p + 2); + s = s.substr(p + 2); + } } } @@ -3884,7 +3922,6 @@ String String::c_unescape() const { escaped = escaped.replace("\\v", "\v"); escaped = escaped.replace("\\'", "\'"); escaped = escaped.replace("\\\"", "\""); - escaped = escaped.replace("\\?", "\?"); escaped = escaped.replace("\\\\", "\\"); return escaped; @@ -3901,7 +3938,6 @@ String String::c_escape() const { escaped = escaped.replace("\t", "\\t"); escaped = escaped.replace("\v", "\\v"); escaped = escaped.replace("\'", "\\'"); - escaped = escaped.replace("\?", "\\?"); escaped = escaped.replace("\"", "\\\""); return escaped; @@ -4651,10 +4687,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 +4698,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 +4749,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 +4760,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/string/ustring.h b/core/string/ustring.h index 4b6568a502..8af74584f3 100644 --- a/core/string/ustring.h +++ b/core/string/ustring.h @@ -345,8 +345,8 @@ public: String get_slice(String p_splitter, int p_slice) const; String get_slicec(char32_t p_splitter, int p_slice) const; - Vector<String> split(const String &p_splitter, bool p_allow_empty = true, int p_maxsplit = 0) const; - Vector<String> rsplit(const String &p_splitter, bool p_allow_empty = true, int p_maxsplit = 0) const; + Vector<String> split(const String &p_splitter = "", bool p_allow_empty = true, int p_maxsplit = 0) const; + Vector<String> rsplit(const String &p_splitter = "", bool p_allow_empty = true, int p_maxsplit = 0) const; Vector<String> split_spaces() const; Vector<float> split_floats(const String &p_splitter, bool p_allow_empty = true) const; Vector<float> split_floats_mk(const Vector<String> &p_splitters, bool p_allow_empty = true) const; diff --git a/core/variant/array.cpp b/core/variant/array.cpp index 8b958814db..c6bbd43dc4 100644 --- a/core/variant/array.cpp +++ b/core/variant/array.cpp @@ -31,6 +31,7 @@ #include "array.h" #include "container_type_validate.h" +#include "core/math/math_funcs.h" #include "core/object/class_db.h" #include "core/object/script_language.h" #include "core/templates/hashfuncs.h" @@ -299,6 +300,11 @@ Variant Array::back() const { return operator[](_p->array.size() - 1); } +Variant Array::pick_random() const { + ERR_FAIL_COND_V_MSG(_p->array.size() == 0, Variant(), "Can't take value from empty array."); + return operator[](Math::rand() % _p->array.size()); +} + int Array::find(const Variant &p_value, int p_from) const { ERR_FAIL_COND_V(!_p->typed.validate(p_value, "find"), -1); return _p->array.find(p_value, p_from); diff --git a/core/variant/array.h b/core/variant/array.h index 3d9a794969..ee265a9ffd 100644 --- a/core/variant/array.h +++ b/core/variant/array.h @@ -79,6 +79,7 @@ public: Variant front() const; Variant back() const; + Variant pick_random() const; void sort(); void sort_custom(const Callable &p_callable); diff --git a/core/variant/binder_common.h b/core/variant/binder_common.h index f0c3b1ce38..696b27f9f2 100644 --- a/core/variant/binder_common.h +++ b/core/variant/binder_common.h @@ -138,7 +138,7 @@ VARIANT_ENUM_CAST(Vector3::Axis); VARIANT_ENUM_CAST(Vector3i::Axis); VARIANT_ENUM_CAST(Vector4::Axis); VARIANT_ENUM_CAST(Vector4i::Axis); -VARIANT_ENUM_CAST(Basis::EulerOrder); +VARIANT_ENUM_CAST(EulerOrder); VARIANT_ENUM_CAST(Projection::Planes); VARIANT_ENUM_CAST(Error); diff --git a/core/variant/callable.h b/core/variant/callable.h index 0305dc55c3..32770bd663 100644 --- a/core/variant/callable.h +++ b/core/variant/callable.h @@ -73,6 +73,16 @@ public: void call_deferredp(const Variant **p_arguments, int p_argcount) const; Variant callv(const Array &p_arguments) const; + template <typename... VarArgs> + void call_deferred(VarArgs... p_args) const { + Variant args[sizeof...(p_args) + 1] = { p_args..., 0 }; // +1 makes sure zero sized arrays are also supported. + const Variant *argptrs[sizeof...(p_args) + 1]; + for (uint32_t i = 0; i < sizeof...(p_args); i++) { + argptrs[i] = &args[i]; + } + return call_deferredp(sizeof...(p_args) == 0 ? nullptr : (const Variant **)argptrs, sizeof...(p_args)); + } + Error rpcp(int p_id, const Variant **p_arguments, int p_argcount, CallError &r_call_error) const; _FORCE_INLINE_ bool is_null() const { diff --git a/core/variant/container_type_validate.h b/core/variant/container_type_validate.h index 6171c8c88f..427a337aab 100644 --- a/core/variant/container_type_validate.h +++ b/core/variant/container_type_validate.h @@ -79,9 +79,12 @@ struct ContainerTypeValidate { return true; } - ERR_FAIL_COND_V_MSG(type != p_variant.get_type(), false, "Attempted to " + String(p_operation) + " a variable of type '" + Variant::get_type_name(p_variant.get_type()) + "' into a " + where + " of type '" + Variant::get_type_name(type) + "'."); if (type != p_variant.get_type()) { - return false; + if (p_variant.get_type() == Variant::NIL && type == Variant::OBJECT) { + return true; + } + + ERR_FAIL_V_MSG(false, "Attempted to " + String(p_operation) + " a variable of type '" + Variant::get_type_name(p_variant.get_type()) + "' into a " + where + " of type '" + Variant::get_type_name(type) + "'."); } if (type != Variant::OBJECT) { @@ -90,7 +93,7 @@ struct ContainerTypeValidate { #ifdef DEBUG_ENABLED ObjectID object_id = p_variant; if (object_id == ObjectID()) { - return true; //fine its null; + return true; // This is fine, it's null. } Object *object = ObjectDB::get_instance(object_id); ERR_FAIL_COND_V_MSG(object == nullptr, false, "Attempted to " + String(p_operation) + " an invalid (previously freed?) object instance into a '" + String(where) + "."); @@ -101,7 +104,7 @@ struct ContainerTypeValidate { } #endif if (class_name == StringName()) { - return true; //all good, no class type requested + return true; // All good, no class type requested. } StringName obj_class = object->get_class_name(); @@ -110,12 +113,12 @@ struct ContainerTypeValidate { } if (script.is_null()) { - return true; //all good + return true; // All good, no script requested. } Ref<Script> other_script = object->get_script(); - //check base script.. + // Check base script.. ERR_FAIL_COND_V_MSG(other_script.is_null(), false, "Attempted to " + String(p_operation) + " an object into a " + String(where) + ", that does not inherit from '" + String(script->get_class_name()) + "'."); ERR_FAIL_COND_V_MSG(!other_script->inherits_script(script), false, "Attempted to " + String(p_operation) + " an object into a " + String(where) + ", that does not inherit from '" + String(script->get_class_name()) + "'."); diff --git a/core/variant/variant.cpp b/core/variant/variant.cpp index 4eae23b0fb..c1166a0a14 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,60 +991,49 @@ 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(); @@ -1133,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; @@ -1150,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; @@ -1202,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))); @@ -1224,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))); @@ -1234,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: { } @@ -1331,6 +1254,7 @@ void Variant::zero() { case FLOAT: this->_data._float = 0; break; + case VECTOR2: *reinterpret_cast<Vector2 *>(this->_data._mem) = Vector2(); break; @@ -1361,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; @@ -1375,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(); @@ -1419,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; @@ -1428,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); @@ -1438,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; @@ -1455,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; @@ -1484,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. + } } } @@ -1863,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) { @@ -1899,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) { @@ -1911,20 +1833,19 @@ 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) + ">"; } @@ -1932,8 +1853,7 @@ String Variant::stringify(int recursion_count) const { } String Variant::to_json_string() const { - JSON json; - return json.stringify(*this); + return JSON::stringify(*this); } Variant::operator Vector2() const { @@ -3689,16 +3609,16 @@ String Variant::get_call_error_text(Object *p_base, const StringName &p_method, if (ce.error == Callable::CallError::CALL_ERROR_INVALID_ARGUMENT) { int errorarg = ce.argument; if (p_argptrs) { - err_text = "Cannot convert argument " + itos(errorarg + 1) + " from " + Variant::get_type_name(p_argptrs[errorarg]->get_type()) + " to " + Variant::get_type_name(Variant::Type(ce.expected)) + "."; + err_text = "Cannot convert argument " + itos(errorarg + 1) + " from " + Variant::get_type_name(p_argptrs[errorarg]->get_type()) + " to " + Variant::get_type_name(Variant::Type(ce.expected)); } else { - err_text = "Cannot convert argument " + itos(errorarg + 1) + " from [missing argptr, type unknown] to " + Variant::get_type_name(Variant::Type(ce.expected)) + "."; + err_text = "Cannot convert argument " + itos(errorarg + 1) + " from [missing argptr, type unknown] to " + Variant::get_type_name(Variant::Type(ce.expected)); } } else if (ce.error == Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS) { - err_text = "Method expected " + itos(ce.argument) + " arguments, but called with " + itos(p_argcount) + "."; + err_text = "Method expected " + itos(ce.argument) + " arguments, but called with " + itos(p_argcount); } else if (ce.error == Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS) { - err_text = "Method expected " + itos(ce.argument) + " arguments, but called with " + itos(p_argcount) + "."; + err_text = "Method expected " + itos(ce.argument) + " arguments, but called with " + itos(p_argcount); } else if (ce.error == Callable::CallError::CALL_ERROR_INVALID_METHOD) { - err_text = "Method not found."; + err_text = "Method not found"; } else if (ce.error == Callable::CallError::CALL_ERROR_INSTANCE_IS_NULL) { err_text = "Instance is null"; } else if (ce.error == Callable::CallError::CALL_ERROR_METHOD_NOT_CONST) { diff --git a/core/variant/variant.h b/core/variant/variant.h index b0738e7d44..c5be609184 100644 --- a/core/variant/variant.h +++ b/core/variant/variant.h @@ -490,6 +490,7 @@ public: } // Only enum classes that need to be bound need this to be defined. + VARIANT_ENUM_CLASS_CONSTRUCTOR(EulerOrder) VARIANT_ENUM_CLASS_CONSTRUCTOR(JoyAxis) VARIANT_ENUM_CLASS_CONSTRUCTOR(JoyButton) VARIANT_ENUM_CLASS_CONSTRUCTOR(Key) diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp index 1831f7b72a..a231a956bf 100644 --- a/core/variant/variant_call.cpp +++ b/core/variant/variant_call.cpp @@ -1509,8 +1509,8 @@ static void _register_variant_builtin_methods() { bind_method(String, to_camel_case, sarray(), varray()); bind_method(String, to_pascal_case, sarray(), varray()); bind_method(String, to_snake_case, sarray(), varray()); - bind_method(String, split, sarray("delimiter", "allow_empty", "maxsplit"), varray(true, 0)); - bind_method(String, rsplit, sarray("delimiter", "allow_empty", "maxsplit"), varray(true, 0)); + bind_method(String, split, sarray("delimiter", "allow_empty", "maxsplit"), varray("", true, 0)); + bind_method(String, rsplit, sarray("delimiter", "allow_empty", "maxsplit"), varray("", true, 0)); bind_method(String, split_floats, sarray("delimiter", "allow_empty"), varray(true)); bind_method(String, join, sarray("parts"), varray()); @@ -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()); @@ -1799,7 +1805,8 @@ static void _register_variant_builtin_methods() { bind_method(Quaternion, slerpni, sarray("to", "weight"), varray()); bind_method(Quaternion, spherical_cubic_interpolate, sarray("b", "pre_a", "post_b", "weight"), varray()); bind_method(Quaternion, spherical_cubic_interpolate_in_time, sarray("b", "pre_a", "post_b", "weight", "b_t", "pre_a_t", "post_b_t"), varray()); - bind_method(Quaternion, get_euler, sarray(), varray()); + bind_method(Quaternion, get_euler, sarray("order"), varray((int64_t)EulerOrder::YXZ)); + bind_static_method(Quaternion, from_euler, sarray("euler"), varray()); bind_method(Quaternion, get_axis, sarray(), varray()); bind_method(Quaternion, get_angle, sarray(), varray()); @@ -1829,10 +1836,6 @@ static void _register_variant_builtin_methods() { bind_static_method(Color, hex64, sarray("hex"), varray()); bind_static_method(Color, html, sarray("rgba"), varray()); bind_static_method(Color, html_is_valid, sarray("color"), varray()); - bind_static_method(Color, find_named_color, sarray("name"), varray()); - bind_static_method(Color, get_named_color_count, sarray(), varray()); - bind_static_method(Color, get_named_color_name, sarray("idx"), varray()); - bind_static_method(Color, get_named_color, sarray("idx"), varray()); bind_static_method(Color, from_string, sarray("str", "default"), varray()); bind_static_method(Color, from_hsv, sarray("h", "s", "v", "alpha"), varray(1.0)); bind_static_method(Color, from_ok_hsl, sarray("h", "s", "l", "alpha"), varray(1.0)); @@ -1909,6 +1912,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()); @@ -1923,16 +1927,17 @@ static void _register_variant_builtin_methods() { bind_methodv(Basis, rotated, static_cast<Basis (Basis::*)(const Vector3 &, real_t) const>(&Basis::rotated), sarray("axis", "angle"), varray()); bind_method(Basis, scaled, sarray("scale"), varray()); bind_method(Basis, get_scale, sarray(), varray()); - bind_method(Basis, get_euler, sarray("order"), varray(Basis::EULER_ORDER_YXZ)); + bind_method(Basis, get_euler, sarray("order"), varray((int64_t)EulerOrder::YXZ)); bind_method(Basis, tdotx, sarray("with"), varray()); bind_method(Basis, tdoty, sarray("with"), varray()); 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()); - bind_static_method(Basis, from_euler, sarray("euler", "order"), varray(Basis::EULER_ORDER_YXZ)); + bind_static_method(Basis, from_euler, sarray("euler", "order"), varray((int64_t)EulerOrder::YXZ)); /* AABB */ @@ -1943,6 +1948,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 +1981,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 */ @@ -2043,6 +2050,7 @@ static void _register_variant_builtin_methods() { bind_method(Array, erase, sarray("value"), varray()); bind_method(Array, front, sarray(), varray()); bind_method(Array, back, sarray(), varray()); + bind_method(Array, pick_random, sarray(), varray()); bind_method(Array, find, sarray("what", "from"), varray(0)); bind_method(Array, rfind, sarray("what", "from"), varray(-1)); bind_method(Array, find_last, sarray("value"), varray()); @@ -2426,25 +2434,11 @@ static void _register_variant_builtin_methods() { _VariantCall::add_variant_constant(Variant::VECTOR2I, "UP", Vector2i(0, -1)); _VariantCall::add_variant_constant(Variant::VECTOR2I, "DOWN", Vector2i(0, 1)); - _VariantCall::add_constant(Variant::BASIS, "EULER_ORDER_XYZ", Basis::EULER_ORDER_XYZ); - _VariantCall::add_constant(Variant::BASIS, "EULER_ORDER_XZY", Basis::EULER_ORDER_XZY); - _VariantCall::add_constant(Variant::BASIS, "EULER_ORDER_YXZ", Basis::EULER_ORDER_YXZ); - _VariantCall::add_constant(Variant::BASIS, "EULER_ORDER_YZX", Basis::EULER_ORDER_YZX); - _VariantCall::add_constant(Variant::BASIS, "EULER_ORDER_ZXY", Basis::EULER_ORDER_ZXY); - _VariantCall::add_constant(Variant::BASIS, "EULER_ORDER_ZYX", Basis::EULER_ORDER_ZYX); - - _VariantCall::add_enum_constant(Variant::BASIS, "EulerOrder", "EULER_ORDER_XYZ", Basis::EULER_ORDER_XYZ); - _VariantCall::add_enum_constant(Variant::BASIS, "EulerOrder", "EULER_ORDER_XZY", Basis::EULER_ORDER_XZY); - _VariantCall::add_enum_constant(Variant::BASIS, "EulerOrder", "EULER_ORDER_YXZ", Basis::EULER_ORDER_YXZ); - _VariantCall::add_enum_constant(Variant::BASIS, "EulerOrder", "EULER_ORDER_YZX", Basis::EULER_ORDER_YZX); - _VariantCall::add_enum_constant(Variant::BASIS, "EulerOrder", "EULER_ORDER_ZXY", Basis::EULER_ORDER_ZXY); - _VariantCall::add_enum_constant(Variant::BASIS, "EulerOrder", "EULER_ORDER_ZYX", Basis::EULER_ORDER_ZYX); - _VariantCall::add_variant_constant(Variant::TRANSFORM2D, "IDENTITY", Transform2D()); _VariantCall::add_variant_constant(Variant::TRANSFORM2D, "FLIP_X", Transform2D(-1, 0, 0, 1, 0, 0)); _VariantCall::add_variant_constant(Variant::TRANSFORM2D, "FLIP_Y", Transform2D(1, 0, 0, -1, 0, 0)); - Transform3D identity_transform = Transform3D(); + Transform3D identity_transform; Transform3D flip_x_transform = Transform3D(-1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0); Transform3D flip_y_transform = Transform3D(1, 0, 0, 0, -1, 0, 0, 0, 1, 0, 0, 0); Transform3D flip_z_transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, -1, 0, 0, 0); @@ -2453,7 +2447,7 @@ static void _register_variant_builtin_methods() { _VariantCall::add_variant_constant(Variant::TRANSFORM3D, "FLIP_Y", flip_y_transform); _VariantCall::add_variant_constant(Variant::TRANSFORM3D, "FLIP_Z", flip_z_transform); - Basis identity_basis = Basis(); + Basis identity_basis; Basis flip_x_basis = Basis(-1, 0, 0, 0, 1, 0, 0, 0, 1); Basis flip_y_basis = Basis(1, 0, 0, 0, -1, 0, 0, 0, 1); Basis flip_z_basis = Basis(1, 0, 0, 0, 1, 0, 0, 0, -1); diff --git a/core/variant/variant_construct.cpp b/core/variant/variant_construct.cpp index 3b88dc11ca..ae9727fe79 100644 --- a/core/variant/variant_construct.cpp +++ b/core/variant/variant_construct.cpp @@ -141,7 +141,6 @@ void Variant::_register_variant_constructors() { add_constructor<VariantConstructor<Quaternion, Vector3, double>>(sarray("axis", "angle")); add_constructor<VariantConstructor<Quaternion, Vector3, Vector3>>(sarray("arc_from", "arc_to")); add_constructor<VariantConstructor<Quaternion, double, double, double, double>>(sarray("x", "y", "z", "w")); - add_constructor<VariantConstructor<Quaternion, Vector3>>(sarray("euler_yxz")); add_constructor<VariantConstructNoArgs<::AABB>>(sarray()); add_constructor<VariantConstructor<::AABB, ::AABB>>(sarray("from")); 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..94e7296a99 100644 --- a/core/variant/variant_internal.h +++ b/core/variant/variant_internal.h @@ -824,9 +824,9 @@ VARIANT_ACCESSOR_NUMBER(Vector4i::Axis) VARIANT_ACCESSOR_NUMBER(Projection::Planes) template <> -struct VariantInternalAccessor<Basis::EulerOrder> { - static _FORCE_INLINE_ Basis::EulerOrder get(const Variant *v) { return Basis::EulerOrder(*VariantInternal::get_int(v)); } - static _FORCE_INLINE_ void set(Variant *v, Basis::EulerOrder p_value) { *VariantInternal::get_int(v) = p_value; } +struct VariantInternalAccessor<EulerOrder> { + static _FORCE_INLINE_ EulerOrder get(const Variant *v) { return EulerOrder(*VariantInternal::get_int(v)); } + static _FORCE_INLINE_ void set(Variant *v, EulerOrder p_value) { *VariantInternal::get_int(v) = (int64_t)p_value; } }; template <> @@ -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_op.cpp b/core/variant/variant_op.cpp index 6cca7955ae..25bc241e9b 100644 --- a/core/variant/variant_op.cpp +++ b/core/variant/variant_op.cpp @@ -240,8 +240,6 @@ void Variant::_register_variant_operators() { register_op<OperatorEvaluatorAdd<double, double, int64_t>>(Variant::OP_ADD, Variant::FLOAT, Variant::INT); register_op<OperatorEvaluatorAdd<double, double, double>>(Variant::OP_ADD, Variant::FLOAT, Variant::FLOAT); register_op<OperatorEvaluatorAdd<String, String, String>>(Variant::OP_ADD, Variant::STRING, Variant::STRING); - register_op<OperatorEvaluatorAdd<String, char32_t, String>>(Variant::OP_ADD, Variant::INT, Variant::STRING); - register_op<OperatorEvaluatorAdd<String, String, char32_t>>(Variant::OP_ADD, Variant::STRING, Variant::INT); register_op<OperatorEvaluatorAdd<Vector2, Vector2, Vector2>>(Variant::OP_ADD, Variant::VECTOR2, Variant::VECTOR2); register_op<OperatorEvaluatorAdd<Vector2i, Vector2i, Vector2i>>(Variant::OP_ADD, Variant::VECTOR2I, Variant::VECTOR2I); register_op<OperatorEvaluatorAdd<Vector3, Vector3, Vector3>>(Variant::OP_ADD, Variant::VECTOR3, Variant::VECTOR3); @@ -384,10 +382,6 @@ void Variant::_register_variant_operators() { register_op<OperatorEvaluatorDivNZ<Vector2, Vector2i, double>>(Variant::OP_DIVIDE, Variant::VECTOR2I, Variant::FLOAT); register_op<OperatorEvaluatorDivNZ<Vector2i, Vector2i, int64_t>>(Variant::OP_DIVIDE, Variant::VECTOR2I, Variant::INT); - register_op<OperatorEvaluatorDiv<Vector2, Vector2, Vector2>>(Variant::OP_DIVIDE, Variant::VECTOR2, Variant::VECTOR2); - register_op<OperatorEvaluatorDiv<Vector2, Vector2, double>>(Variant::OP_DIVIDE, Variant::VECTOR2, Variant::FLOAT); - register_op<OperatorEvaluatorDiv<Vector2, Vector2, int64_t>>(Variant::OP_DIVIDE, Variant::VECTOR2, Variant::INT); - register_op<OperatorEvaluatorDiv<Vector3, Vector3, Vector3>>(Variant::OP_DIVIDE, Variant::VECTOR3, Variant::VECTOR3); register_op<OperatorEvaluatorDiv<Vector3, Vector3, double>>(Variant::OP_DIVIDE, Variant::VECTOR3, Variant::FLOAT); register_op<OperatorEvaluatorDiv<Vector3, Vector3, int64_t>>(Variant::OP_DIVIDE, Variant::VECTOR3, Variant::INT); @@ -498,8 +492,6 @@ void Variant::_register_variant_operators() { register_op<OperatorEvaluatorBitXor<int64_t, int64_t, int64_t>>(Variant::OP_BIT_XOR, Variant::INT, Variant::INT); register_op<OperatorEvaluatorBitNeg<int64_t, int64_t>>(Variant::OP_BIT_NEGATE, Variant::INT, Variant::NIL); - register_op<OperatorEvaluatorBitNeg<int64_t, int64_t>>(Variant::OP_BIT_NEGATE, Variant::INT, Variant::NIL); - register_op<OperatorEvaluatorAlwaysTrue<Variant::OP_EQUAL, Variant::NIL, Variant::NIL>>(Variant::OP_EQUAL, Variant::NIL, Variant::NIL); register_op<OperatorEvaluatorEqual<bool, bool>>(Variant::OP_EQUAL, Variant::BOOL, Variant::BOOL); register_op<OperatorEvaluatorEqual<int64_t, int64_t>>(Variant::OP_EQUAL, Variant::INT, Variant::INT); @@ -567,6 +559,7 @@ void Variant::_register_variant_operators() { register_op<OperatorEvaluatorAlwaysFalse<Variant::OP_EQUAL, Variant::AABB, Variant::NIL>>(Variant::OP_EQUAL, Variant::AABB, Variant::NIL); register_op<OperatorEvaluatorAlwaysFalse<Variant::OP_EQUAL, Variant::BASIS, Variant::NIL>>(Variant::OP_EQUAL, Variant::BASIS, Variant::NIL); register_op<OperatorEvaluatorAlwaysFalse<Variant::OP_EQUAL, Variant::TRANSFORM3D, Variant::NIL>>(Variant::OP_EQUAL, Variant::TRANSFORM3D, Variant::NIL); + register_op<OperatorEvaluatorAlwaysFalse<Variant::OP_EQUAL, Variant::PROJECTION, Variant::NIL>>(Variant::OP_EQUAL, Variant::PROJECTION, Variant::NIL); register_op<OperatorEvaluatorAlwaysFalse<Variant::OP_EQUAL, Variant::COLOR, Variant::NIL>>(Variant::OP_EQUAL, Variant::COLOR, Variant::NIL); register_op<OperatorEvaluatorAlwaysFalse<Variant::OP_EQUAL, Variant::STRING_NAME, Variant::NIL>>(Variant::OP_EQUAL, Variant::STRING_NAME, Variant::NIL); register_op<OperatorEvaluatorAlwaysFalse<Variant::OP_EQUAL, Variant::NODE_PATH, Variant::NIL>>(Variant::OP_EQUAL, Variant::NODE_PATH, Variant::NIL); @@ -603,6 +596,7 @@ void Variant::_register_variant_operators() { register_op<OperatorEvaluatorAlwaysFalse<Variant::OP_EQUAL, Variant::NIL, Variant::AABB>>(Variant::OP_EQUAL, Variant::NIL, Variant::AABB); register_op<OperatorEvaluatorAlwaysFalse<Variant::OP_EQUAL, Variant::NIL, Variant::BASIS>>(Variant::OP_EQUAL, Variant::NIL, Variant::BASIS); register_op<OperatorEvaluatorAlwaysFalse<Variant::OP_EQUAL, Variant::NIL, Variant::TRANSFORM3D>>(Variant::OP_EQUAL, Variant::NIL, Variant::TRANSFORM3D); + register_op<OperatorEvaluatorAlwaysFalse<Variant::OP_EQUAL, Variant::NIL, Variant::PROJECTION>>(Variant::OP_EQUAL, Variant::NIL, Variant::PROJECTION); register_op<OperatorEvaluatorAlwaysFalse<Variant::OP_EQUAL, Variant::NIL, Variant::COLOR>>(Variant::OP_EQUAL, Variant::NIL, Variant::COLOR); register_op<OperatorEvaluatorAlwaysFalse<Variant::OP_EQUAL, Variant::NIL, Variant::STRING_NAME>>(Variant::OP_EQUAL, Variant::NIL, Variant::STRING_NAME); register_op<OperatorEvaluatorAlwaysFalse<Variant::OP_EQUAL, Variant::NIL, Variant::NODE_PATH>>(Variant::OP_EQUAL, Variant::NIL, Variant::NODE_PATH); @@ -688,6 +682,7 @@ void Variant::_register_variant_operators() { register_op<OperatorEvaluatorAlwaysTrue<Variant::OP_NOT_EQUAL, Variant::AABB, Variant::NIL>>(Variant::OP_NOT_EQUAL, Variant::AABB, Variant::NIL); register_op<OperatorEvaluatorAlwaysTrue<Variant::OP_NOT_EQUAL, Variant::BASIS, Variant::NIL>>(Variant::OP_NOT_EQUAL, Variant::BASIS, Variant::NIL); register_op<OperatorEvaluatorAlwaysTrue<Variant::OP_NOT_EQUAL, Variant::TRANSFORM3D, Variant::NIL>>(Variant::OP_NOT_EQUAL, Variant::TRANSFORM3D, Variant::NIL); + register_op<OperatorEvaluatorAlwaysTrue<Variant::OP_NOT_EQUAL, Variant::PROJECTION, Variant::NIL>>(Variant::OP_NOT_EQUAL, Variant::PROJECTION, Variant::NIL); register_op<OperatorEvaluatorAlwaysTrue<Variant::OP_NOT_EQUAL, Variant::COLOR, Variant::NIL>>(Variant::OP_NOT_EQUAL, Variant::COLOR, Variant::NIL); register_op<OperatorEvaluatorAlwaysTrue<Variant::OP_NOT_EQUAL, Variant::STRING_NAME, Variant::NIL>>(Variant::OP_NOT_EQUAL, Variant::STRING_NAME, Variant::NIL); register_op<OperatorEvaluatorAlwaysTrue<Variant::OP_NOT_EQUAL, Variant::NODE_PATH, Variant::NIL>>(Variant::OP_NOT_EQUAL, Variant::NODE_PATH, Variant::NIL); @@ -724,6 +719,7 @@ void Variant::_register_variant_operators() { register_op<OperatorEvaluatorAlwaysTrue<Variant::OP_NOT_EQUAL, Variant::NIL, Variant::AABB>>(Variant::OP_NOT_EQUAL, Variant::NIL, Variant::AABB); register_op<OperatorEvaluatorAlwaysTrue<Variant::OP_NOT_EQUAL, Variant::NIL, Variant::BASIS>>(Variant::OP_NOT_EQUAL, Variant::NIL, Variant::BASIS); register_op<OperatorEvaluatorAlwaysTrue<Variant::OP_NOT_EQUAL, Variant::NIL, Variant::TRANSFORM3D>>(Variant::OP_NOT_EQUAL, Variant::NIL, Variant::TRANSFORM3D); + register_op<OperatorEvaluatorAlwaysTrue<Variant::OP_NOT_EQUAL, Variant::NIL, Variant::PROJECTION>>(Variant::OP_NOT_EQUAL, Variant::NIL, Variant::PROJECTION); register_op<OperatorEvaluatorAlwaysTrue<Variant::OP_NOT_EQUAL, Variant::NIL, Variant::COLOR>>(Variant::OP_NOT_EQUAL, Variant::NIL, Variant::COLOR); register_op<OperatorEvaluatorAlwaysTrue<Variant::OP_NOT_EQUAL, Variant::NIL, Variant::STRING_NAME>>(Variant::OP_NOT_EQUAL, Variant::NIL, Variant::STRING_NAME); register_op<OperatorEvaluatorAlwaysTrue<Variant::OP_NOT_EQUAL, Variant::NIL, Variant::NODE_PATH>>(Variant::OP_NOT_EQUAL, Variant::NIL, Variant::NODE_PATH); 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); |