diff options
Diffstat (limited to 'core')
47 files changed, 248 insertions, 575 deletions
diff --git a/core/config/project_settings.cpp b/core/config/project_settings.cpp index 73d7d7420f..ed89bc15d3 100644 --- a/core/config/project_settings.cpp +++ b/core/config/project_settings.cpp @@ -33,6 +33,7 @@ #include "core/core_bind.h" // For Compression enum. #include "core/core_string_names.h" #include "core/input/input_map.h" +#include "core/io/config_file.h" #include "core/io/dir_access.h" #include "core/io/file_access.h" #include "core/io/file_access_network.h" @@ -1068,23 +1069,6 @@ Variant _GLOBAL_DEF(const PropertyInfo &p_info, const Variant &p_default, bool p return ret; } -Vector<String> ProjectSettings::get_optimizer_presets() const { - List<PropertyInfo> pi; - ProjectSettings::get_singleton()->get_property_list(&pi); - Vector<String> names; - - for (const PropertyInfo &E : pi) { - if (!E.name.begins_with("optimizer_presets/")) { - continue; - } - names.push_back(E.name.get_slicec('/', 1)); - } - - names.sort(); - - return names; -} - void ProjectSettings::_add_property_info_bind(const Dictionary &p_info) { ERR_FAIL_COND(!p_info.has("name")); ERR_FAIL_COND(!p_info.has("type")); @@ -1148,6 +1132,29 @@ Variant ProjectSettings::get_setting(const String &p_setting, const Variant &p_d } } +Array ProjectSettings::get_global_class_list() { + Array script_classes; + + Ref<ConfigFile> cf; + cf.instantiate(); + if (cf->load(get_project_data_path().path_join("global_script_class_cache.cfg")) == OK) { + script_classes = cf->get_value("", "list"); + } else { +#ifndef TOOLS_ENABLED + // Script classes can't be recreated in exported project, so print an error. + ERR_PRINT("Could not load global script cache."); +#endif + } + return script_classes; +} + +void ProjectSettings::store_global_class_list(const Array &p_classes) { + Ref<ConfigFile> cf; + cf.instantiate(); + cf->set_value("", "list", p_classes); + cf->save(get_project_data_path().path_join("global_script_class_cache.cfg")); +} + bool ProjectSettings::has_custom_feature(const String &p_feature) const { return custom_features.has(p_feature); } diff --git a/core/config/project_settings.h b/core/config/project_settings.h index 353e298919..d1704a7c31 100644 --- a/core/config/project_settings.h +++ b/core/config/project_settings.h @@ -141,6 +141,8 @@ public: void set_setting(const String &p_setting, const Variant &p_value); Variant get_setting(const String &p_setting, const Variant &p_default_value = Variant()) const; + Array get_global_class_list(); + void store_global_class_list(const Array &p_classes); bool has_setting(String p_var) const; String localize_path(const String &p_path) const; @@ -176,8 +178,6 @@ public: const HashMap<StringName, PropertyInfo> &get_custom_property_info() const; uint64_t get_last_saved_time() { return last_save_time; } - Vector<String> get_optimizer_presets() const; - List<String> get_input_presets() const { return input_presets; } Variant get_setting_with_override(const StringName &p_name) const; diff --git a/core/core_bind.cpp b/core/core_bind.cpp index ab433bd8f1..96e1da9dde 100644 --- a/core/core_bind.cpp +++ b/core/core_bind.cpp @@ -322,8 +322,12 @@ String OS::get_environment(const String &p_var) const { return ::OS::get_singleton()->get_environment(p_var); } -bool OS::set_environment(const String &p_var, const String &p_value) const { - return ::OS::get_singleton()->set_environment(p_var, p_value); +void OS::set_environment(const String &p_var, const String &p_value) const { + ::OS::get_singleton()->set_environment(p_var, p_value); +} + +void OS::unset_environment(const String &p_var) const { + ::OS::get_singleton()->unset_environment(p_var); } String OS::get_name() const { @@ -548,9 +552,10 @@ void OS::_bind_methods() { ClassDB::bind_method(D_METHOD("is_process_running", "pid"), &OS::is_process_running); ClassDB::bind_method(D_METHOD("get_process_id"), &OS::get_process_id); + ClassDB::bind_method(D_METHOD("has_environment", "variable"), &OS::has_environment); ClassDB::bind_method(D_METHOD("get_environment", "variable"), &OS::get_environment); ClassDB::bind_method(D_METHOD("set_environment", "variable", "value"), &OS::set_environment); - ClassDB::bind_method(D_METHOD("has_environment", "variable"), &OS::has_environment); + ClassDB::bind_method(D_METHOD("unset_environment", "variable"), &OS::unset_environment); ClassDB::bind_method(D_METHOD("get_name"), &OS::get_name); ClassDB::bind_method(D_METHOD("get_distribution_name"), &OS::get_distribution_name); diff --git a/core/core_bind.h b/core/core_bind.h index 7ef346d1c4..c0c87fd009 100644 --- a/core/core_bind.h +++ b/core/core_bind.h @@ -162,7 +162,8 @@ public: bool has_environment(const String &p_var) const; String get_environment(const String &p_var) const; - bool set_environment(const String &p_var, const String &p_value) const; + void set_environment(const String &p_var, const String &p_value) const; + void unset_environment(const String &p_var) const; String get_name() const; String get_distribution_name() const; diff --git a/core/debugger/script_debugger.cpp b/core/debugger/script_debugger.cpp index 8af1573bff..32725b76c1 100644 --- a/core/debugger/script_debugger.cpp +++ b/core/debugger/script_debugger.cpp @@ -73,10 +73,6 @@ bool ScriptDebugger::is_breakpoint(int p_line, const StringName &p_source) const return breakpoints[p_line].has(p_source); } -bool ScriptDebugger::is_breakpoint_line(int p_line) const { - return breakpoints.has(p_line); -} - String ScriptDebugger::breakpoint_find_source(const String &p_source) const { return p_source; } diff --git a/core/debugger/script_debugger.h b/core/debugger/script_debugger.h index c7aa90027b..edce089179 100644 --- a/core/debugger/script_debugger.h +++ b/core/debugger/script_debugger.h @@ -64,7 +64,6 @@ public: void insert_breakpoint(int p_line, const StringName &p_source); void remove_breakpoint(int p_line, const StringName &p_source); bool is_breakpoint(int p_line, const StringName &p_source) const; - bool is_breakpoint_line(int p_line) const; void clear_breakpoints(); const HashMap<int, HashSet<StringName>> &get_breakpoints() const { return breakpoints; } diff --git a/core/extension/extension_api_dump.cpp b/core/extension/extension_api_dump.cpp index 312064a36c..7be14b741d 100644 --- a/core/extension/extension_api_dump.cpp +++ b/core/extension/extension_api_dump.cpp @@ -458,6 +458,7 @@ Dictionary GDExtensionAPIDump::generate_extension_api() { // Global enums and constants. Array constants; HashMap<String, List<Pair<String, int64_t>>> enum_list; + HashMap<String, bool> enum_is_bitfield; for (int i = 0; i < CoreConstants::get_global_constant_count(); i++) { int64_t value = CoreConstants::get_global_constant_value(i); @@ -466,6 +467,7 @@ Dictionary GDExtensionAPIDump::generate_extension_api() { bool bitfield = CoreConstants::is_global_constant_bitfield(i); if (!enum_name.is_empty()) { enum_list[enum_name].push_back(Pair<String, int64_t>(name, value)); + enum_is_bitfield[enum_name] = bitfield; } else { Dictionary d; d["name"] = name; @@ -481,6 +483,7 @@ Dictionary GDExtensionAPIDump::generate_extension_api() { for (const KeyValue<String, List<Pair<String, int64_t>>> &E : enum_list) { Dictionary d1; d1["name"] = E.key; + d1["is_bitfield"] = enum_is_bitfield[E.key]; Array values; for (const Pair<String, int64_t> &F : E.value) { Dictionary d2; diff --git a/core/extension/gdextension_interface.cpp b/core/extension/gdextension_interface.cpp index bd4fa61bd5..a9063c8b27 100644 --- a/core/extension/gdextension_interface.cpp +++ b/core/extension/gdextension_interface.cpp @@ -31,8 +31,11 @@ #include "gdextension_interface.h" #include "core/config/engine.h" +#include "core/io/file_access.h" +#include "core/io/xml_parser.h" #include "core/object/class_db.h" #include "core/object/script_language_extension.h" +#include "core/object/worker_thread_pool.h" #include "core/os/memory.h" #include "core/variant/variant.h" #include "core/version.h" @@ -678,6 +681,59 @@ static const char32_t *gdextension_string_operator_index_const(GDExtensionConstS return &self->ptr()[p_index]; } +static void gdextension_string_operator_plus_eq_string(GDExtensionStringPtr p_self, GDExtensionConstStringPtr p_b) { + String *self = (String *)p_self; + const String *b = (const String *)p_b; + *self += *b; +} + +static void gdextension_string_operator_plus_eq_char(GDExtensionStringPtr p_self, char32_t p_b) { + String *self = (String *)p_self; + *self += p_b; +} + +static void gdextension_string_operator_plus_eq_cstr(GDExtensionStringPtr p_self, const char *p_b) { + String *self = (String *)p_self; + *self += p_b; +} + +static void gdextension_string_operator_plus_eq_wcstr(GDExtensionStringPtr p_self, const wchar_t *p_b) { + String *self = (String *)p_self; + *self += p_b; +} + +static void gdextension_string_operator_plus_eq_c32str(GDExtensionStringPtr p_self, const char32_t *p_b) { + String *self = (String *)p_self; + *self += p_b; +} + +static GDExtensionInt gdextension_xml_parser_open_buffer(GDExtensionObjectPtr p_instance, const uint8_t *p_buffer, size_t p_size) { + XMLParser *xml = (XMLParser *)p_instance; + return (GDExtensionInt)xml->_open_buffer(p_buffer, p_size); +} + +static void gdextension_file_access_store_buffer(GDExtensionObjectPtr p_instance, const uint8_t *p_src, uint64_t p_length) { + FileAccess *fa = (FileAccess *)p_instance; + fa->store_buffer(p_src, p_length); +} + +static uint64_t gdextension_file_access_get_buffer(GDExtensionConstObjectPtr p_instance, uint8_t *p_dst, uint64_t p_length) { + const FileAccess *fa = (FileAccess *)p_instance; + return fa->get_buffer(p_dst, p_length); +} + +static int64_t gdextension_worker_thread_pool_add_native_group_task(GDExtensionObjectPtr p_instance, void (*p_func)(void *, uint32_t), void *p_userdata, int p_elements, int p_tasks, GDExtensionBool p_high_priority, GDExtensionConstStringPtr p_description) { + WorkerThreadPool *p = (WorkerThreadPool *)p_instance; + const String *description = (const String *)p_description; + return (int64_t)p->add_native_group_task(p_func, p_userdata, p_elements, p_tasks, static_cast<bool>(p_high_priority), *description); +} + +static int64_t gdextension_worker_thread_pool_add_native_task(GDExtensionObjectPtr p_instance, void (*p_func)(void *), void *p_userdata, GDExtensionBool p_high_priority, GDExtensionConstStringPtr p_description) { + WorkerThreadPool *p = (WorkerThreadPool *)p_instance; + const String *description = (const String *)p_description; + return (int64_t)p->add_native_task(p_func, p_userdata, static_cast<bool>(p_high_priority), *description); +} + /* Packed array functions */ static uint8_t *gdextension_packed_byte_array_operator_index(GDExtensionTypePtr p_self, GDExtensionInt p_index) { @@ -1025,6 +1081,25 @@ void gdextension_setup_interface(GDExtensionInterface *p_interface) { gde_interface.string_to_wide_chars = gdextension_string_to_wide_chars; gde_interface.string_operator_index = gdextension_string_operator_index; gde_interface.string_operator_index_const = gdextension_string_operator_index_const; + gde_interface.string_operator_plus_eq_string = gdextension_string_operator_plus_eq_string; + gde_interface.string_operator_plus_eq_char = gdextension_string_operator_plus_eq_char; + gde_interface.string_operator_plus_eq_cstr = gdextension_string_operator_plus_eq_cstr; + gde_interface.string_operator_plus_eq_wcstr = gdextension_string_operator_plus_eq_wcstr; + gde_interface.string_operator_plus_eq_c32str = gdextension_string_operator_plus_eq_c32str; + + /* XMLParser extra utilities */ + + gde_interface.xml_parser_open_buffer = gdextension_xml_parser_open_buffer; + + /* FileAccess extra utilities */ + + gde_interface.file_access_store_buffer = gdextension_file_access_store_buffer; + gde_interface.file_access_get_buffer = gdextension_file_access_get_buffer; + + /* WorkerThreadPool extra utilities */ + + gde_interface.worker_thread_pool_add_native_group_task = gdextension_worker_thread_pool_add_native_group_task; + gde_interface.worker_thread_pool_add_native_task = gdextension_worker_thread_pool_add_native_task; /* Packed array functions */ diff --git a/core/extension/gdextension_interface.h b/core/extension/gdextension_interface.h index 190298ee8a..6e5dee8265 100644 --- a/core/extension/gdextension_interface.h +++ b/core/extension/gdextension_interface.h @@ -503,6 +503,26 @@ typedef struct { char32_t *(*string_operator_index)(GDExtensionStringPtr p_self, GDExtensionInt p_index); const char32_t *(*string_operator_index_const)(GDExtensionConstStringPtr p_self, GDExtensionInt p_index); + void (*string_operator_plus_eq_string)(GDExtensionStringPtr p_self, GDExtensionConstStringPtr p_b); + void (*string_operator_plus_eq_char)(GDExtensionStringPtr p_self, char32_t p_b); + void (*string_operator_plus_eq_cstr)(GDExtensionStringPtr p_self, const char *p_b); + void (*string_operator_plus_eq_wcstr)(GDExtensionStringPtr p_self, const wchar_t *p_b); + void (*string_operator_plus_eq_c32str)(GDExtensionStringPtr p_self, const char32_t *p_b); + + /* XMLParser extra utilities */ + + GDExtensionInt (*xml_parser_open_buffer)(GDExtensionObjectPtr p_instance, const uint8_t *p_buffer, size_t p_size); + + /* FileAccess extra utilities */ + + void (*file_access_store_buffer)(GDExtensionObjectPtr p_instance, const uint8_t *p_src, uint64_t p_length); + uint64_t (*file_access_get_buffer)(GDExtensionConstObjectPtr p_instance, uint8_t *p_dst, uint64_t p_length); + + /* WorkerThreadPool extra utilities */ + + int64_t (*worker_thread_pool_add_native_group_task)(GDExtensionObjectPtr p_instance, void (*p_func)(void *, uint32_t), void *p_userdata, int p_elements, int p_tasks, GDExtensionBool p_high_priority, GDExtensionConstStringPtr p_description); + int64_t (*worker_thread_pool_add_native_task)(GDExtensionObjectPtr p_instance, void (*p_func)(void *), void *p_userdata, GDExtensionBool p_high_priority, GDExtensionConstStringPtr p_description); + /* Packed array functions */ uint8_t *(*packed_byte_array_operator_index)(GDExtensionTypePtr p_self, GDExtensionInt p_index); // p_self should be a PackedByteArray diff --git a/core/input/input_builders.py b/core/input/input_builders.py index a7729c9af2..76e199e0ff 100644 --- a/core/input/input_builders.py +++ b/core/input/input_builders.py @@ -45,7 +45,7 @@ def make_default_controller_mappings(target, source, env): platform_mappings[current_platform][guid] = line platform_variables = { - "Linux": "#if X11_ENABLED", + "Linux": "#if LINUXBSD_ENABLED", "Windows": "#ifdef WINDOWS_ENABLED", "Mac OS X": "#ifdef MACOS_ENABLED", "Android": "#if defined(__ANDROID__)", diff --git a/core/io/file_access.cpp b/core/io/file_access.cpp index 77d1bdcc5c..cacbcb28a4 100644 --- a/core/io/file_access.cpp +++ b/core/io/file_access.cpp @@ -292,7 +292,7 @@ real_t FileAccess::get_real() const { Variant FileAccess::get_var(bool p_allow_objects) const { uint32_t len = get_32(); - Vector<uint8_t> buff = _get_buffer(len); + Vector<uint8_t> buff = get_buffer(len); ERR_FAIL_COND_V((uint32_t)buff.size() != len, Variant()); const uint8_t *r = buff.ptr(); @@ -469,7 +469,7 @@ uint64_t FileAccess::get_buffer(uint8_t *p_dst, uint64_t p_length) const { return i; } -Vector<uint8_t> FileAccess::_get_buffer(int64_t p_length) const { +Vector<uint8_t> FileAccess::get_buffer(int64_t p_length) const { Vector<uint8_t> data; ERR_FAIL_COND_V_MSG(p_length < 0, data, "Length of buffer cannot be smaller than 0."); @@ -663,7 +663,7 @@ void FileAccess::store_buffer(const uint8_t *p_src, uint64_t p_length) { } } -void FileAccess::_store_buffer(const Vector<uint8_t> &p_buffer) { +void FileAccess::store_buffer(const Vector<uint8_t> &p_buffer) { uint64_t len = p_buffer.size(); if (len == 0) { return; @@ -687,7 +687,7 @@ void FileAccess::store_var(const Variant &p_var, bool p_full_objects) { ERR_FAIL_COND_MSG(err != OK, "Error when trying to encode Variant."); store_32(len); - _store_buffer(buff); + store_buffer(buff); } Vector<uint8_t> FileAccess::get_file_as_bytes(const String &p_path, Error *r_error) { @@ -829,7 +829,7 @@ void FileAccess::_bind_methods() { ClassDB::bind_method(D_METHOD("get_float"), &FileAccess::get_float); ClassDB::bind_method(D_METHOD("get_double"), &FileAccess::get_double); ClassDB::bind_method(D_METHOD("get_real"), &FileAccess::get_real); - ClassDB::bind_method(D_METHOD("get_buffer", "length"), &FileAccess::_get_buffer); + ClassDB::bind_method(D_METHOD("get_buffer", "length"), (Vector<uint8_t>(FileAccess::*)(int64_t) const) & FileAccess::get_buffer); ClassDB::bind_method(D_METHOD("get_line"), &FileAccess::get_line); ClassDB::bind_method(D_METHOD("get_csv_line", "delim"), &FileAccess::get_csv_line, DEFVAL(",")); ClassDB::bind_method(D_METHOD("get_as_text", "skip_cr"), &FileAccess::get_as_text, DEFVAL(false)); @@ -847,7 +847,7 @@ void FileAccess::_bind_methods() { ClassDB::bind_method(D_METHOD("store_float", "value"), &FileAccess::store_float); ClassDB::bind_method(D_METHOD("store_double", "value"), &FileAccess::store_double); ClassDB::bind_method(D_METHOD("store_real", "value"), &FileAccess::store_real); - ClassDB::bind_method(D_METHOD("store_buffer", "buffer"), &FileAccess::_store_buffer); + ClassDB::bind_method(D_METHOD("store_buffer", "buffer"), (void(FileAccess::*)(const Vector<uint8_t> &)) & FileAccess::store_buffer); ClassDB::bind_method(D_METHOD("store_line", "line"), &FileAccess::store_line); ClassDB::bind_method(D_METHOD("store_csv_line", "values", "delim"), &FileAccess::store_csv_line, DEFVAL(",")); ClassDB::bind_method(D_METHOD("store_string", "string"), &FileAccess::store_string); diff --git a/core/io/file_access.h b/core/io/file_access.h index 3116ed521f..3e51ba11ed 100644 --- a/core/io/file_access.h +++ b/core/io/file_access.h @@ -127,7 +127,7 @@ public: Variant get_var(bool p_allow_objects = false) const; virtual uint64_t get_buffer(uint8_t *p_dst, uint64_t p_length) const; ///< get an array of bytes - Vector<uint8_t> _get_buffer(int64_t p_length) const; + Vector<uint8_t> get_buffer(int64_t p_length) const; virtual String get_line() const; virtual String get_token() const; virtual Vector<String> get_csv_line(const String &p_delim = ",") const; @@ -162,7 +162,7 @@ public: virtual String get_pascal_string(); virtual void store_buffer(const uint8_t *p_src, uint64_t p_length); ///< store an array of bytes - void _store_buffer(const Vector<uint8_t> &p_buffer); + void store_buffer(const Vector<uint8_t> &p_buffer); void store_var(const Variant &p_var, bool p_full_objects = false); diff --git a/core/io/image_loader.cpp b/core/io/image_loader.cpp index 17fb199811..c6452f1033 100644 --- a/core/io/image_loader.cpp +++ b/core/io/image_loader.cpp @@ -135,10 +135,6 @@ void ImageLoader::remove_image_format_loader(Ref<ImageFormatLoader> p_loader) { loader.erase(p_loader); } -const Vector<Ref<ImageFormatLoader>> &ImageLoader::get_image_format_loaders() { - return loader; -} - void ImageLoader::cleanup() { while (loader.size()) { remove_image_format_loader(loader[0]); diff --git a/core/io/image_loader.h b/core/io/image_loader.h index 1473f24186..ac51f13376 100644 --- a/core/io/image_loader.h +++ b/core/io/image_loader.h @@ -98,8 +98,6 @@ public: static void add_image_format_loader(Ref<ImageFormatLoader> p_loader); static void remove_image_format_loader(Ref<ImageFormatLoader> p_loader); - static const Vector<Ref<ImageFormatLoader>> &get_image_format_loaders(); - static void cleanup(); }; diff --git a/core/io/json.cpp b/core/io/json.cpp index ca29534c35..448e39b2c3 100644 --- a/core/io/json.cpp +++ b/core/io/json.cpp @@ -30,6 +30,7 @@ #include "json.h" +#include "core/config/engine.h" #include "core/string/print_string.h" const char *JSON::tk_name[TK_MAX] = { @@ -506,6 +507,7 @@ Error JSON::_parse_object(Dictionary &object, const char32_t *p_str, int &index, void JSON::set_data(const Variant &p_data) { data = p_data; + text.clear(); } Error JSON::_parse_string(const String &p_json, Variant &r_ret, String &r_err_str, int &r_err_line) { @@ -539,14 +541,21 @@ Error JSON::_parse_string(const String &p_json, Variant &r_ret, String &r_err_st return err; } -Error JSON::parse(const String &p_json_string) { +Error JSON::parse(const String &p_json_string, bool p_keep_text) { Error err = _parse_string(p_json_string, data, err_str, err_line); if (err == Error::OK) { err_line = 0; } + if (p_keep_text) { + text = p_json_string; + } return err; } +String JSON::get_parsed_text() const { + return text; +} + String JSON::stringify(const Variant &p_var, const String &p_indent, bool p_sort_keys, bool p_full_precision) { Ref<JSON> jason; jason.instantiate(); @@ -565,10 +574,11 @@ Variant JSON::parse_string(const String &p_json_string) { void JSON::_bind_methods() { ClassDB::bind_static_method("JSON", D_METHOD("stringify", "data", "indent", "sort_keys", "full_precision"), &JSON::stringify, DEFVAL(""), DEFVAL(true), DEFVAL(false)); ClassDB::bind_static_method("JSON", D_METHOD("parse_string", "json_string"), &JSON::parse_string); - ClassDB::bind_method(D_METHOD("parse", "json_string"), &JSON::parse); + ClassDB::bind_method(D_METHOD("parse", "json_text", "keep_text"), &JSON::parse, DEFVAL(false)); ClassDB::bind_method(D_METHOD("get_data"), &JSON::get_data); ClassDB::bind_method(D_METHOD("set_data", "data"), &JSON::set_data); + ClassDB::bind_method(D_METHOD("get_parsed_text"), &JSON::get_parsed_text); ClassDB::bind_method(D_METHOD("get_error_line"), &JSON::get_error_line); ClassDB::bind_method(D_METHOD("get_error_message"), &JSON::get_error_message); @@ -592,13 +602,20 @@ Ref<Resource> ResourceFormatLoaderJSON::load(const String &p_path, const String Ref<JSON> json; json.instantiate(); - Error err = json->parse(FileAccess::get_file_as_string(p_path)); + Error err = json->parse(FileAccess::get_file_as_string(p_path), Engine::get_singleton()->is_editor_hint()); if (err != OK) { - if (r_error) { - *r_error = err; + String err_text = "Error parsing JSON file at '" + p_path + "', on line " + itos(json->get_error_line()) + ": " + json->get_error_message(); + + if (Engine::get_singleton()->is_editor_hint()) { + // If running on editor, still allow opening the JSON so the code editor can edit it. + WARN_PRINT(err_text); + } else { + if (r_error) { + *r_error = err; + } + ERR_PRINT(err_text); + return Ref<Resource>(); } - ERR_PRINT("Error parsing JSON file at '" + p_path + "', on line " + itos(json->get_error_line()) + ": " + json->get_error_message()); - return Ref<Resource>(); } if (r_error) { @@ -628,7 +645,7 @@ Error ResourceFormatSaverJSON::save(const Ref<Resource> &p_resource, const Strin Ref<JSON> json = p_resource; ERR_FAIL_COND_V(json.is_null(), ERR_INVALID_PARAMETER); - String source = JSON::stringify(json->get_data(), "\t", false, true); + String source = json->get_parsed_text().is_empty() ? JSON::stringify(json->get_data(), "\t", false, true) : json->get_parsed_text(); Error err; Ref<FileAccess> file = FileAccess::open(p_path, FileAccess::WRITE, &err); diff --git a/core/io/json.h b/core/io/json.h index d66a4e24a3..a21cc542fd 100644 --- a/core/io/json.h +++ b/core/io/json.h @@ -36,8 +36,8 @@ #include "core/io/resource_saver.h" #include "core/variant/variant.h" -class JSON : public RefCounted { - GDCLASS(JSON, RefCounted); +class JSON : public Resource { + GDCLASS(JSON, Resource); enum TokenType { TK_CURLY_BRACKET_OPEN, @@ -65,6 +65,7 @@ class JSON : public RefCounted { Variant value; }; + String text; Variant data; String err_str; int err_line = 0; @@ -83,7 +84,9 @@ protected: static void _bind_methods(); public: - Error parse(const String &p_json_string); + Error parse(const String &p_json_string, bool p_keep_text = false); + String get_parsed_text() const; + static String stringify(const Variant &p_var, const String &p_indent = "", bool p_sort_keys = true, bool p_full_precision = false); static Variant parse_string(const String &p_json_string); diff --git a/core/io/resource.cpp b/core/io/resource.cpp index 2d6f09725f..6d3575b9fa 100644 --- a/core/io/resource.cpp +++ b/core/io/resource.cpp @@ -385,10 +385,6 @@ void Resource::set_as_translation_remapped(bool p_remapped) { ResourceCache::lock.unlock(); } -bool Resource::is_translation_remapped() const { - return remapped_list.in_list(); -} - #ifdef TOOLS_ENABLED //helps keep IDs same number when loading/saving scenes. -1 clears ID and it Returns -1 when no id stored void Resource::set_id_for_path(const String &p_path, const String &p_id) { @@ -481,9 +477,6 @@ void ResourceCache::clear() { resources.clear(); } -void ResourceCache::reload_externals() { -} - bool ResourceCache::has(const String &p_path) { lock.lock(); diff --git a/core/io/resource.h b/core/io/resource.h index 22ce5cef43..5135664f36 100644 --- a/core/io/resource.h +++ b/core/io/resource.h @@ -136,7 +136,6 @@ public: #endif void set_as_translation_remapped(bool p_remapped); - bool is_translation_remapped() const; virtual RID get_rid() const; // some resources may offer conversion to RID @@ -164,7 +163,6 @@ class ResourceCache { friend void register_core_types(); public: - static void reload_externals(); static bool has(const String &p_path); static Ref<Resource> get_ref(const String &p_path); static void get_cached_resources(List<Ref<Resource>> *p_resources); diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index 45e1301930..03beb25b03 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -661,10 +661,6 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) { return OK; //never reach anyway } -void ResourceLoaderBinary::set_local_path(const String &p_local_path) { - res_path = p_local_path; -} - Ref<Resource> ResourceLoaderBinary::get_resource() { return resource; } diff --git a/core/io/resource_format_binary.h b/core/io/resource_format_binary.h index 2e8988005f..9dd208e3cd 100644 --- a/core/io/resource_format_binary.h +++ b/core/io/resource_format_binary.h @@ -92,7 +92,6 @@ class ResourceLoaderBinary { HashMap<String, Ref<Resource>> dependency_cache; public: - void set_local_path(const String &p_local_path); Ref<Resource> get_resource(); Error load(); void set_translation_remapped(bool p_remapped); diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp index 946c31cf0d..68b9f8b6f7 100644 --- a/core/io/resource_loader.cpp +++ b/core/io/resource_loader.cpp @@ -1011,13 +1011,6 @@ bool ResourceLoader::add_custom_resource_format_loader(String script_path) { return true; } -void ResourceLoader::remove_custom_resource_format_loader(String script_path) { - Ref<ResourceFormatLoader> custom_loader = _find_custom_resource_format_loader(script_path); - if (custom_loader.is_valid()) { - remove_resource_format_loader(custom_loader); - } -} - void ResourceLoader::set_create_missing_resources_if_class_unavailable(bool p_enable) { create_missing_resources_if_class_unavailable = p_enable; } diff --git a/core/io/resource_loader.h b/core/io/resource_loader.h index 41ba0dc6e6..e427a2f5fc 100644 --- a/core/io/resource_loader.h +++ b/core/io/resource_loader.h @@ -225,7 +225,6 @@ public: static ResourceLoaderImport import; static bool add_custom_resource_format_loader(String script_path); - static void remove_custom_resource_format_loader(String script_path); static void add_custom_loaders(); static void remove_custom_loaders(); diff --git a/core/io/resource_saver.cpp b/core/io/resource_saver.cpp index 9809b9a48f..b8201cc6b9 100644 --- a/core/io/resource_saver.cpp +++ b/core/io/resource_saver.cpp @@ -250,13 +250,6 @@ bool ResourceSaver::add_custom_resource_format_saver(String script_path) { return true; } -void ResourceSaver::remove_custom_resource_format_saver(String script_path) { - Ref<ResourceFormatSaver> custom_saver = _find_custom_resource_format_saver(script_path); - if (custom_saver.is_valid()) { - remove_resource_format_saver(custom_saver); - } -} - void ResourceSaver::add_custom_savers() { // Custom resource savers exploits global class names diff --git a/core/io/resource_saver.h b/core/io/resource_saver.h index 2043947963..9e88b2086b 100644 --- a/core/io/resource_saver.h +++ b/core/io/resource_saver.h @@ -101,7 +101,6 @@ public: static void set_get_resource_id_for_path(ResourceSaverGetResourceIDForPath p_callback); static bool add_custom_resource_format_saver(String script_path); - static void remove_custom_resource_format_saver(String script_path); static void add_custom_savers(); static void remove_custom_savers(); }; diff --git a/core/io/xml_parser.cpp b/core/io/xml_parser.cpp index 09836419be..5c0a017bfc 100644 --- a/core/io/xml_parser.cpp +++ b/core/io/xml_parser.cpp @@ -354,10 +354,10 @@ void XMLParser::_bind_methods() { ClassDB::bind_method(D_METHOD("get_node_offset"), &XMLParser::get_node_offset); ClassDB::bind_method(D_METHOD("get_attribute_count"), &XMLParser::get_attribute_count); ClassDB::bind_method(D_METHOD("get_attribute_name", "idx"), &XMLParser::get_attribute_name); - ClassDB::bind_method(D_METHOD("get_attribute_value", "idx"), (String(XMLParser::*)(int) const) & XMLParser::get_attribute_value); + ClassDB::bind_method(D_METHOD("get_attribute_value", "idx"), &XMLParser::get_attribute_value); ClassDB::bind_method(D_METHOD("has_attribute", "name"), &XMLParser::has_attribute); - ClassDB::bind_method(D_METHOD("get_named_attribute_value", "name"), (String(XMLParser::*)(const String &) const) & XMLParser::get_attribute_value); - ClassDB::bind_method(D_METHOD("get_named_attribute_value_safe", "name"), &XMLParser::get_attribute_value_safe); + ClassDB::bind_method(D_METHOD("get_named_attribute_value", "name"), &XMLParser::get_named_attribute_value); + ClassDB::bind_method(D_METHOD("get_named_attribute_value_safe", "name"), &XMLParser::get_named_attribute_value_safe); ClassDB::bind_method(D_METHOD("is_empty"), &XMLParser::is_empty); ClassDB::bind_method(D_METHOD("get_current_line"), &XMLParser::get_current_line); ClassDB::bind_method(D_METHOD("skip_section"), &XMLParser::skip_section); @@ -422,7 +422,7 @@ bool XMLParser::has_attribute(const String &p_name) const { return false; } -String XMLParser::get_attribute_value(const String &p_name) const { +String XMLParser::get_named_attribute_value(const String &p_name) const { int idx = -1; for (int i = 0; i < attributes.size(); i++) { if (attributes[i].name == p_name) { @@ -436,7 +436,7 @@ String XMLParser::get_attribute_value(const String &p_name) const { return attributes[idx].value; } -String XMLParser::get_attribute_value_safe(const String &p_name) const { +String XMLParser::get_named_attribute_value_safe(const String &p_name) const { int idx = -1; for (int i = 0; i < attributes.size(); i++) { if (attributes[i].name == p_name) { diff --git a/core/io/xml_parser.h b/core/io/xml_parser.h index b4ae5c93b6..b96478c7a5 100644 --- a/core/io/xml_parser.h +++ b/core/io/xml_parser.h @@ -109,8 +109,8 @@ public: String get_attribute_name(int p_idx) const; String get_attribute_value(int p_idx) const; bool has_attribute(const String &p_name) const; - String get_attribute_value(const String &p_name) const; - String get_attribute_value_safe(const String &p_name) const; // do not print error if doesn't exist + String get_named_attribute_value(const String &p_name) const; + String get_named_attribute_value_safe(const String &p_name) const; // do not print error if doesn't exist bool is_empty() const; int get_current_line() const; diff --git a/core/math/basis.cpp b/core/math/basis.cpp index 39e383fb49..234a4ddb79 100644 --- a/core/math/basis.cpp +++ b/core/math/basis.cpp @@ -36,23 +36,6 @@ #define cofac(row1, col1, row2, col2) \ (rows[row1][col1] * rows[row2][col2] - rows[row1][col2] * rows[row2][col1]) -void Basis::from_z(const Vector3 &p_z) { - if (Math::abs(p_z.z) > (real_t)Math_SQRT12) { - // choose p in y-z plane - real_t a = p_z[1] * p_z[1] + p_z[2] * p_z[2]; - real_t k = 1.0f / Math::sqrt(a); - rows[0] = Vector3(0, -p_z[2] * k, p_z[1] * k); - rows[1] = Vector3(a * k, -p_z[0] * rows[0][2], p_z[0] * rows[0][1]); - } else { - // choose p in x-y plane - real_t a = p_z.x * p_z.x + p_z.y * p_z.y; - real_t k = 1.0f / Math::sqrt(a); - rows[0] = Vector3(-p_z.y * k, p_z.x * k, 0); - rows[1] = Vector3(-p_z.z * rows[0].y, p_z.z * rows[0].x, a * k); - } - rows[2] = p_z; -} - void Basis::invert() { real_t co[3] = { cofac(1, 1, 2, 2), cofac(1, 2, 2, 0), cofac(1, 0, 2, 1) @@ -271,14 +254,6 @@ float Basis::get_uniform_scale() const { return (rows[0].length() + rows[1].length() + rows[2].length()) / 3.0f; } -void Basis::make_scale_uniform() { - float l = (rows[0].length() + rows[1].length() + rows[2].length()) / 3.0f; - for (int i = 0; i < 3; i++) { - rows[i].normalize(); - rows[i] *= l; - } -} - Basis Basis::scaled_local(const Vector3 &p_scale) const { return (*this) * Basis::from_scale(p_scale); } diff --git a/core/math/basis.h b/core/math/basis.h index b3197dbc84..bbc1d40469 100644 --- a/core/math/basis.h +++ b/core/math/basis.h @@ -56,8 +56,6 @@ struct _NO_DISCARD_ Basis { _FORCE_INLINE_ real_t determinant() const; - void from_z(const Vector3 &p_z); - void rotate(const Vector3 &p_axis, real_t p_angle); Basis rotated(const Vector3 &p_axis, real_t p_angle) const; @@ -101,8 +99,6 @@ struct _NO_DISCARD_ Basis { void scale_orthogonal(const Vector3 &p_scale); Basis scaled_orthogonal(const Vector3 &p_scale) const; - - void make_scale_uniform(); float get_uniform_scale() const; Vector3 get_scale() const; diff --git a/core/math/face3.cpp b/core/math/face3.cpp index e53bbf872b..1dff0ee4a6 100644 --- a/core/math/face3.cpp +++ b/core/math/face3.cpp @@ -120,36 +120,6 @@ bool Face3::is_degenerate() const { return (normal.length_squared() < (real_t)CMP_EPSILON2); } -Face3::Side Face3::get_side_of(const Face3 &p_face, ClockDirection p_clock_dir) const { - int over = 0, under = 0; - - Plane plane = get_plane(p_clock_dir); - - for (int i = 0; i < 3; i++) { - const Vector3 &v = p_face.vertex[i]; - - if (plane.has_point(v)) { //coplanar, don't bother - continue; - } - - if (plane.is_point_over(v)) { - over++; - } else { - under++; - } - } - - if (over > 0 && under == 0) { - return SIDE_OVER; - } else if (under > 0 && over == 0) { - return SIDE_UNDER; - } else if (under == 0 && over == 0) { - return SIDE_COPLANAR; - } else { - return SIDE_SPANNING; - } -} - Vector3 Face3::get_random_point_inside() const { real_t a = Math::random(0.0, 1.0); real_t b = Math::random(0.0, 1.0); @@ -164,20 +134,10 @@ Plane Face3::get_plane(ClockDirection p_dir) const { return Plane(vertex[0], vertex[1], vertex[2], p_dir); } -Vector3 Face3::get_median_point() const { - return (vertex[0] + vertex[1] + vertex[2]) / 3.0f; -} - real_t Face3::get_area() const { return vec3_cross(vertex[0] - vertex[1], vertex[0] - vertex[2]).length() * 0.5f; } -ClockDirection Face3::get_clock_dir() const { - Vector3 normal = vec3_cross(vertex[0] - vertex[1], vertex[0] - vertex[2]); - //printf("normal is %g,%g,%g x %g,%g,%g- wtfu is %g\n",tofloat(normal.x),tofloat(normal.y),tofloat(normal.z),tofloat(vertex[0].x),tofloat(vertex[0].y),tofloat(vertex[0].z),tofloat( normal.dot( vertex[0] ) ) ); - return (normal.dot(vertex[0]) >= 0) ? CLOCKWISE : COUNTERCLOCKWISE; -} - bool Face3::intersects_aabb(const AABB &p_aabb) const { /** TEST PLANE **/ if (!p_aabb.intersects_plane(get_plane())) { diff --git a/core/math/face3.h b/core/math/face3.h index 3d87de03dc..3dd47d0226 100644 --- a/core/math/face3.h +++ b/core/math/face3.h @@ -57,19 +57,14 @@ struct _NO_DISCARD_ Face3 { Plane get_plane(ClockDirection p_dir = CLOCKWISE) const; Vector3 get_random_point_inside() const; - Side get_side_of(const Face3 &p_face, ClockDirection p_clock_dir = CLOCKWISE) const; - bool is_degenerate() const; real_t get_area() const; - Vector3 get_median_point() const; Vector3 get_closest_point_to(const Vector3 &p_point) const; bool intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *p_intersection = nullptr) const; bool intersects_segment(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *p_intersection = nullptr) const; - ClockDirection get_clock_dir() const; ///< todo, test if this is returning the proper clockwisity - void get_support(const Vector3 &p_normal, const Transform3D &p_transform, Vector3 *p_vertices, int *p_count, int p_max) const; void project_range(const Vector3 &p_normal, const Transform3D &p_transform, real_t &r_min, real_t &r_max) const; diff --git a/core/math/geometry_2d.cpp b/core/math/geometry_2d.cpp index a0b76d31cb..74cb92539a 100644 --- a/core/math/geometry_2d.cpp +++ b/core/math/geometry_2d.cpp @@ -320,41 +320,6 @@ Vector<Vector<Point2>> Geometry2D::_polypath_offset(const Vector<Point2> &p_poly return polypaths; } -Vector<Point2i> Geometry2D::pack_rects(const Vector<Size2i> &p_sizes, const Size2i &p_atlas_size) { - Vector<stbrp_node> nodes; - nodes.resize(p_atlas_size.width); - - stbrp_context context; - stbrp_init_target(&context, p_atlas_size.width, p_atlas_size.height, nodes.ptrw(), p_atlas_size.width); - - Vector<stbrp_rect> rects; - rects.resize(p_sizes.size()); - - for (int i = 0; i < p_sizes.size(); i++) { - rects.write[i].id = 0; - rects.write[i].w = p_sizes[i].width; - rects.write[i].h = p_sizes[i].height; - rects.write[i].x = 0; - rects.write[i].y = 0; - rects.write[i].was_packed = 0; - } - - int res = stbrp_pack_rects(&context, rects.ptrw(), rects.size()); - if (res == 0) { //pack failed - return Vector<Point2i>(); - } - - Vector<Point2i> ret; - ret.resize(p_sizes.size()); - - for (int i = 0; i < p_sizes.size(); i++) { - Point2i r(rects[i].x, rects[i].y); - ret.write[i] = r; - } - - return ret; -} - Vector<Vector3i> Geometry2D::partial_pack_rects(const Vector<Vector2i> &p_sizes, const Size2i &p_atlas_size) { Vector<stbrp_node> nodes; nodes.resize(p_atlas_size.width); diff --git a/core/math/geometry_2d.h b/core/math/geometry_2d.h index b55aecf85e..0e5702e0af 100644 --- a/core/math/geometry_2d.h +++ b/core/math/geometry_2d.h @@ -464,7 +464,6 @@ public: static Vector<Vector<Vector2>> decompose_polygon_in_convex(Vector<Point2> polygon); static void make_atlas(const Vector<Size2i> &p_rects, Vector<Point2i> &r_result, Size2i &r_size); - static Vector<Point2i> pack_rects(const Vector<Size2i> &p_sizes, const Size2i &p_atlas_size); static Vector<Vector3i> partial_pack_rects(const Vector<Vector2i> &p_sizes, const Size2i &p_atlas_size); private: diff --git a/core/math/geometry_3d.cpp b/core/math/geometry_3d.cpp index 3ac78e0709..51523ea296 100644 --- a/core/math/geometry_3d.cpp +++ b/core/math/geometry_3d.cpp @@ -198,149 +198,6 @@ struct _FaceClassify { _FaceClassify() {} }; -static bool _connect_faces(_FaceClassify *p_faces, int len, int p_group) { - // Connect faces, error will occur if an edge is shared between more than 2 faces. - // Clear connections. - - bool error = false; - - for (int i = 0; i < len; i++) { - for (int j = 0; j < 3; j++) { - p_faces[i].links[j].clear(); - } - } - - for (int i = 0; i < len; i++) { - if (p_faces[i].group != p_group) { - continue; - } - for (int j = i + 1; j < len; j++) { - if (p_faces[j].group != p_group) { - continue; - } - - for (int k = 0; k < 3; k++) { - Vector3 vi1 = p_faces[i].face.vertex[k]; - Vector3 vi2 = p_faces[i].face.vertex[(k + 1) % 3]; - - for (int l = 0; l < 3; l++) { - Vector3 vj2 = p_faces[j].face.vertex[l]; - Vector3 vj1 = p_faces[j].face.vertex[(l + 1) % 3]; - - if (vi1.distance_to(vj1) < 0.00001f && - vi2.distance_to(vj2) < 0.00001f) { - if (p_faces[i].links[k].face != -1) { - ERR_PRINT("already linked\n"); - error = true; - break; - } - if (p_faces[j].links[l].face != -1) { - ERR_PRINT("already linked\n"); - error = true; - break; - } - - p_faces[i].links[k].face = j; - p_faces[i].links[k].edge = l; - p_faces[j].links[l].face = i; - p_faces[j].links[l].edge = k; - } - } - if (error) { - break; - } - } - if (error) { - break; - } - } - if (error) { - break; - } - } - - for (int i = 0; i < len; i++) { - p_faces[i].valid = true; - for (int j = 0; j < 3; j++) { - if (p_faces[i].links[j].face == -1) { - p_faces[i].valid = false; - } - } - } - return error; -} - -static bool _group_face(_FaceClassify *p_faces, int len, int p_index, int p_group) { - if (p_faces[p_index].group >= 0) { - return false; - } - - p_faces[p_index].group = p_group; - - for (int i = 0; i < 3; i++) { - ERR_FAIL_INDEX_V(p_faces[p_index].links[i].face, len, true); - _group_face(p_faces, len, p_faces[p_index].links[i].face, p_group); - } - - return true; -} - -Vector<Vector<Face3>> Geometry3D::separate_objects(Vector<Face3> p_array) { - Vector<Vector<Face3>> objects; - - int len = p_array.size(); - - const Face3 *arrayptr = p_array.ptr(); - - Vector<_FaceClassify> fc; - - fc.resize(len); - - _FaceClassify *_fcptr = fc.ptrw(); - - for (int i = 0; i < len; i++) { - _fcptr[i].face = arrayptr[i]; - } - - bool error = _connect_faces(_fcptr, len, -1); - - ERR_FAIL_COND_V_MSG(error, Vector<Vector<Face3>>(), "Invalid geometry."); - - // Group connected faces in separate objects. - - int group = 0; - for (int i = 0; i < len; i++) { - if (!_fcptr[i].valid) { - continue; - } - if (_group_face(_fcptr, len, i, group)) { - group++; - } - } - - // Group connected faces in separate objects. - - for (int i = 0; i < len; i++) { - _fcptr[i].face = arrayptr[i]; - } - - if (group >= 0) { - objects.resize(group); - Vector<Face3> *group_faces = objects.ptrw(); - - for (int i = 0; i < len; i++) { - if (!_fcptr[i].valid) { - continue; - } - if (_fcptr[i].group >= 0 && _fcptr[i].group < group) { - group_faces[_fcptr[i].group].push_back(_fcptr[i].face); - } - } - } - - return objects; -} - /*** GEOMETRY WRAPPER ***/ enum _CellFlags { @@ -748,7 +605,7 @@ Geometry3D::MeshData Geometry3D::build_convex_mesh(const Vector<Plane> &p_planes Vector3 right = p.normal.cross(ref).normalized(); Vector3 up = p.normal.cross(right).normalized(); - Vector3 center = p.center(); + Vector3 center = p.get_center(); // make a quad clockwise LocalVector<Vector3> vertices = { diff --git a/core/math/geometry_3d.h b/core/math/geometry_3d.h index 6759db5766..99c554fe05 100644 --- a/core/math/geometry_3d.h +++ b/core/math/geometry_3d.h @@ -532,8 +532,6 @@ public: return clipped; } - static Vector<Vector<Face3>> separate_objects(Vector<Face3> p_array); - // Create a "wrap" that encloses the given geometry. static Vector<Face3> wrap_geometry(Vector<Face3> p_array, real_t *p_error = nullptr); diff --git a/core/math/plane.h b/core/math/plane.h index 3bc7c54b9d..8159f25342 100644 --- a/core/math/plane.h +++ b/core/math/plane.h @@ -47,7 +47,7 @@ struct _NO_DISCARD_ Plane { /* Plane-Point operations */ - _FORCE_INLINE_ Vector3 center() const { return normal * d; } + _FORCE_INLINE_ Vector3 get_center() const { return normal * d; } Vector3 get_any_perpendicular_normal() const; _FORCE_INLINE_ bool is_point_over(const Vector3 &p_point) const; ///< Point is over plane diff --git a/core/math/transform_2d.cpp b/core/math/transform_2d.cpp index 6a7ee32230..910995d717 100644 --- a/core/math/transform_2d.cpp +++ b/core/math/transform_2d.cpp @@ -221,12 +221,6 @@ Transform2D Transform2D::operator*(const Transform2D &p_transform) const { return t; } -Transform2D Transform2D::basis_scaled(const Size2 &p_scale) const { - Transform2D copy = *this; - copy.scale_basis(p_scale); - return copy; -} - Transform2D Transform2D::scaled(const Size2 &p_scale) const { // Equivalent to left multiplication Transform2D copy = *this; diff --git a/core/math/transform_2d.h b/core/math/transform_2d.h index 2a0917c63f..4a17a9db37 100644 --- a/core/math/transform_2d.h +++ b/core/math/transform_2d.h @@ -85,7 +85,6 @@ struct _NO_DISCARD_ Transform2D { _FORCE_INLINE_ const Vector2 &get_origin() const { return columns[2]; } _FORCE_INLINE_ void set_origin(const Vector2 &p_origin) { columns[2] = p_origin; } - Transform2D basis_scaled(const Size2 &p_scale) const; Transform2D scaled(const Size2 &p_scale) const; Transform2D scaled_local(const Size2 &p_scale) const; Transform2D translated(const Vector2 &p_offset) const; diff --git a/core/math/triangle_mesh.cpp b/core/math/triangle_mesh.cpp index 4b6921d38b..0da1b8c7ad 100644 --- a/core/math/triangle_mesh.cpp +++ b/core/math/triangle_mesh.cpp @@ -182,90 +182,6 @@ void TriangleMesh::create(const Vector<Vector3> &p_faces, const Vector<int32_t> valid = true; } -Vector3 TriangleMesh::get_area_normal(const AABB &p_aabb) const { - uint32_t *stack = (uint32_t *)alloca(sizeof(int) * max_depth); - - enum { - TEST_AABB_BIT = 0, - VISIT_LEFT_BIT = 1, - VISIT_RIGHT_BIT = 2, - VISIT_DONE_BIT = 3, - VISITED_BIT_SHIFT = 29, - NODE_IDX_MASK = (1 << VISITED_BIT_SHIFT) - 1, - VISITED_BIT_MASK = ~NODE_IDX_MASK, - - }; - - int n_count = 0; - Vector3 n; - - int level = 0; - - const Triangle *triangleptr = triangles.ptr(); - // const Vector3 *verticesr = vertices.ptr(); - const BVH *bvhptr = bvh.ptr(); - - int pos = bvh.size() - 1; - - stack[0] = pos; - while (true) { - uint32_t node = stack[level] & NODE_IDX_MASK; - const BVH &b = bvhptr[node]; - bool done = false; - - switch (stack[level] >> VISITED_BIT_SHIFT) { - case TEST_AABB_BIT: { - if (!b.aabb.intersects(p_aabb)) { - stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node; - } else { - if (b.face_index >= 0) { - const Triangle &s = triangleptr[b.face_index]; - n += s.normal; - n_count++; - - stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node; - - } else { - stack[level] = (VISIT_LEFT_BIT << VISITED_BIT_SHIFT) | node; - } - } - continue; - } - case VISIT_LEFT_BIT: { - stack[level] = (VISIT_RIGHT_BIT << VISITED_BIT_SHIFT) | node; - level++; - stack[level] = b.left | TEST_AABB_BIT; - continue; - } - case VISIT_RIGHT_BIT: { - stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node; - level++; - stack[level] = b.right | TEST_AABB_BIT; - continue; - } - case VISIT_DONE_BIT: { - if (level == 0) { - done = true; - break; - } else { - level--; - } - continue; - } - } - - if (done) { - break; - } - } - - if (n_count > 0) { - n /= n_count; - } - - return n; -} - bool TriangleMesh::intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_point, Vector3 &r_normal, int32_t *r_surf_index) const { uint32_t *stack = (uint32_t *)alloca(sizeof(int) * max_depth); @@ -468,118 +384,6 @@ bool TriangleMesh::intersect_ray(const Vector3 &p_begin, const Vector3 &p_dir, V return inters; } -bool TriangleMesh::intersect_convex_shape(const Plane *p_planes, int p_plane_count, const Vector3 *p_points, int p_point_count) const { - uint32_t *stack = (uint32_t *)alloca(sizeof(int) * max_depth); - - //p_fully_inside = true; - - enum { - TEST_AABB_BIT = 0, - VISIT_LEFT_BIT = 1, - VISIT_RIGHT_BIT = 2, - VISIT_DONE_BIT = 3, - VISITED_BIT_SHIFT = 29, - NODE_IDX_MASK = (1 << VISITED_BIT_SHIFT) - 1, - VISITED_BIT_MASK = ~NODE_IDX_MASK, - - }; - - int level = 0; - - const Triangle *triangleptr = triangles.ptr(); - const Vector3 *vertexptr = vertices.ptr(); - const BVH *bvhptr = bvh.ptr(); - - int pos = bvh.size() - 1; - - stack[0] = pos; - while (true) { - uint32_t node = stack[level] & NODE_IDX_MASK; - const BVH &b = bvhptr[node]; - bool done = false; - - switch (stack[level] >> VISITED_BIT_SHIFT) { - case TEST_AABB_BIT: { - if (!b.aabb.intersects_convex_shape(p_planes, p_plane_count, p_points, p_point_count)) { - stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node; - } else { - if (b.face_index >= 0) { - const Triangle &s = triangleptr[b.face_index]; - - for (int j = 0; j < 3; ++j) { - const Vector3 &point = vertexptr[s.indices[j]]; - const Vector3 &next_point = vertexptr[s.indices[(j + 1) % 3]]; - Vector3 res; - bool over = true; - for (int i = 0; i < p_plane_count; i++) { - const Plane &p = p_planes[i]; - - if (p.intersects_segment(point, next_point, &res)) { - bool inisde = true; - for (int k = 0; k < p_plane_count; k++) { - if (k == i) { - continue; - } - const Plane &pp = p_planes[k]; - if (pp.is_point_over(res)) { - inisde = false; - break; - } - } - if (inisde) { - return true; - } - } - - if (p.is_point_over(point)) { - over = false; - break; - } - } - if (over) { - return true; - } - } - - stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node; - - } else { - stack[level] = (VISIT_LEFT_BIT << VISITED_BIT_SHIFT) | node; - } - } - continue; - } - case VISIT_LEFT_BIT: { - stack[level] = (VISIT_RIGHT_BIT << VISITED_BIT_SHIFT) | node; - level++; - stack[level] = b.left | TEST_AABB_BIT; - continue; - } - case VISIT_RIGHT_BIT: { - stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node; - level++; - stack[level] = b.right | TEST_AABB_BIT; - continue; - } - case VISIT_DONE_BIT: { - if (level == 0) { - done = true; - break; - } else { - level--; - } - continue; - } - } - - if (done) { - break; - } - } - - return false; -} - bool TriangleMesh::inside_convex_shape(const Plane *p_planes, int p_plane_count, const Vector3 *p_points, int p_point_count, Vector3 p_scale) const { uint32_t *stack = (uint32_t *)alloca(sizeof(int) * max_depth); diff --git a/core/math/triangle_mesh.h b/core/math/triangle_mesh.h index 728fd600d5..24fc12dda9 100644 --- a/core/math/triangle_mesh.h +++ b/core/math/triangle_mesh.h @@ -84,9 +84,7 @@ public: bool is_valid() const; bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_point, Vector3 &r_normal, int32_t *r_surf_index = nullptr) const; bool intersect_ray(const Vector3 &p_begin, const Vector3 &p_dir, Vector3 &r_point, Vector3 &r_normal, int32_t *r_surf_index = nullptr) const; - bool intersect_convex_shape(const Plane *p_planes, int p_plane_count, const Vector3 *p_points, int p_point_count) const; bool inside_convex_shape(const Plane *p_planes, int p_plane_count, const Vector3 *p_points, int p_point_count, Vector3 p_scale = Vector3(1, 1, 1)) const; - Vector3 get_area_normal(const AABB &p_aabb) const; Vector<Face3> get_faces() const; const Vector<Triangle> &get_triangles() const { return triangles; } diff --git a/core/object/script_language.cpp b/core/object/script_language.cpp index 7be3a6c688..66ef418e42 100644 --- a/core/object/script_language.cpp +++ b/core/object/script_language.cpp @@ -186,6 +186,7 @@ void ScriptServer::unregister_language(const ScriptLanguage *p_language) { void ScriptServer::init_languages() { { // Load global classes. global_classes_clear(); +#ifndef DISABLE_DEPRECATED if (ProjectSettings::get_singleton()->has_setting("_global_script_classes")) { Array script_classes = GLOBAL_GET("_global_script_classes"); @@ -196,6 +197,17 @@ void ScriptServer::init_languages() { } add_global_class(c["class"], c["base"], c["language"], c["path"]); } + ProjectSettings::get_singleton()->clear("_global_script_classes"); + } +#endif + + Array script_classes = ProjectSettings::get_singleton()->get_global_class_list(); + for (int i = 0; i < script_classes.size(); i++) { + Dictionary c = script_classes[i]; + if (!c.has("class") || !c.has("language") || !c.has("path") || !c.has("base")) { + continue; + } + add_global_class(c["class"], c["base"], c["language"], c["path"]); } } @@ -251,6 +263,15 @@ void ScriptServer::remove_global_class(const StringName &p_class) { global_classes.erase(p_class); } +void ScriptServer::remove_global_class_by_path(const String &p_path) { + for (const KeyValue<StringName, GlobalScriptClass> &kv : global_classes) { + if (kv.value.path == p_path) { + global_classes.erase(kv.key); + return; + } + } +} + bool ScriptServer::is_global_class(const StringName &p_class) { return global_classes.has(p_class); } @@ -291,6 +312,17 @@ void ScriptServer::get_global_class_list(List<StringName> *r_global_classes) { } void ScriptServer::save_global_classes() { + Dictionary class_icons; + + Array script_classes = ProjectSettings::get_singleton()->get_global_class_list(); + for (int i = 0; i < script_classes.size(); i++) { + Dictionary d = script_classes[i]; + if (!d.has("name") || !d.has("icon")) { + continue; + } + class_icons[d["name"]] = d["icon"]; + } + List<StringName> gc; get_global_class_list(&gc); Array gcarr; @@ -300,25 +332,10 @@ void ScriptServer::save_global_classes() { d["language"] = global_classes[E].language; d["path"] = global_classes[E].path; d["base"] = global_classes[E].base; + d["icon"] = class_icons.get(E, ""); gcarr.push_back(d); } - - Array old; - if (ProjectSettings::get_singleton()->has_setting("_global_script_classes")) { - old = GLOBAL_GET("_global_script_classes"); - } - if ((!old.is_empty() || gcarr.is_empty()) && gcarr.hash() == old.hash()) { - return; - } - - if (gcarr.is_empty()) { - if (ProjectSettings::get_singleton()->has_setting("_global_script_classes")) { - ProjectSettings::get_singleton()->clear("_global_script_classes"); - } - } else { - ProjectSettings::get_singleton()->set("_global_script_classes", gcarr); - } - ProjectSettings::get_singleton()->save(); + ProjectSettings::get_singleton()->store_global_class_list(gcarr); } //////////////////// diff --git a/core/object/script_language.h b/core/object/script_language.h index ff678bcd25..02d1880dc2 100644 --- a/core/object/script_language.h +++ b/core/object/script_language.h @@ -80,6 +80,7 @@ public: static void global_classes_clear(); static void add_global_class(const StringName &p_class, const StringName &p_base, const StringName &p_language, const String &p_path); static void remove_global_class(const StringName &p_class); + static void remove_global_class_by_path(const String &p_path); static bool is_global_class(const StringName &p_class); static StringName get_global_class_language(const StringName &p_class); static String get_global_class_path(const String &p_class); diff --git a/core/os/keyboard.cpp b/core/os/keyboard.cpp index e0231b818f..5183b77cb1 100644 --- a/core/os/keyboard.cpp +++ b/core/os/keyboard.cpp @@ -63,12 +63,15 @@ static const _KeyCodeText _keycodes[] = { {Key::CTRL ,"Ctrl"}, #if defined(MACOS_ENABLED) {Key::META ,"Command"}, + {Key::CMD_OR_CTRL ,"Command"}, {Key::ALT ,"Option"}, #elif defined(WINDOWS_ENABLED) {Key::META ,"Windows"}, + {Key::CMD_OR_CTRL ,"Ctrl"}, {Key::ALT ,"Alt"}, #else {Key::META ,"Meta"}, + {Key::CMD_OR_CTRL ,"Ctrl"}, {Key::ALT ,"Alt"}, #endif {Key::CAPSLOCK ,"CapsLock"}, diff --git a/core/os/keyboard.h b/core/os/keyboard.h index 389baee915..c78fa2a631 100644 --- a/core/os/keyboard.h +++ b/core/os/keyboard.h @@ -65,6 +65,11 @@ enum class Key { SHIFT = SPECIAL | 0x15, CTRL = SPECIAL | 0x16, META = SPECIAL | 0x17, +#if defined(MACOS_ENABLED) + CMD_OR_CTRL = META, +#else + CMD_OR_CTRL = CTRL, +#endif ALT = SPECIAL | 0x18, CAPSLOCK = SPECIAL | 0x19, NUMLOCK = SPECIAL | 0x1A, diff --git a/core/os/os.h b/core/os/os.h index c96c675bcb..436a83eae3 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -167,7 +167,8 @@ public: virtual bool has_environment(const String &p_var) const = 0; virtual String get_environment(const String &p_var) const = 0; - virtual bool set_environment(const String &p_var, const String &p_value) const = 0; + virtual void set_environment(const String &p_var, const String &p_value) const = 0; + virtual void unset_environment(const String &p_var) const = 0; virtual String get_name() const = 0; virtual String get_distribution_name() const = 0; diff --git a/core/variant/variant.h b/core/variant/variant.h index fff59c43a6..b9294de77d 100644 --- a/core/variant/variant.h +++ b/core/variant/variant.h @@ -655,6 +655,7 @@ public: static bool has_indexing(Variant::Type p_type); static Variant::Type get_indexed_element_type(Variant::Type p_type); + static uint32_t get_indexed_element_usage(Variant::Type p_type); typedef void (*ValidatedIndexedSetter)(Variant *base, int64_t index, const Variant *value, bool *oob); typedef void (*ValidatedIndexedGetter)(const Variant *base, int64_t index, Variant *value, bool *oob); diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp index 05fb62ff12..2cc0b3a8d7 100644 --- a/core/variant/variant_call.cpp +++ b/core/variant/variant_call.cpp @@ -1923,7 +1923,7 @@ static void _register_variant_builtin_methods() { /* Plane */ bind_method(Plane, normalized, sarray(), varray()); - bind_method(Plane, center, sarray(), varray()); + bind_method(Plane, get_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()); diff --git a/core/variant/variant_setget.cpp b/core/variant/variant_setget.cpp index b8d4495702..ba37e15f31 100644 --- a/core/variant/variant_setget.cpp +++ b/core/variant/variant_setget.cpp @@ -389,6 +389,7 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const { v.write[index] = PtrToArg<m_elem_type>::convert(member); \ } \ static Variant::Type get_index_type() { return GetTypeInfo<m_elem_type>::VARIANT_TYPE; } \ + static uint32_t get_index_usage() { return GetTypeInfo<m_elem_type>::get_class_info().usage; } \ static uint64_t get_indexed_size(const Variant *base) { return VariantGetInternalPtr<m_base_type>::get_ptr(base)->size(); } \ }; @@ -460,6 +461,7 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const { v.write[index] = PtrToArg<m_elem_type>::convert(member); \ } \ static Variant::Type get_index_type() { return GetTypeInfo<m_elem_type>::VARIANT_TYPE; } \ + static uint32_t get_index_usage() { return GetTypeInfo<m_elem_type>::get_class_info().usage; } \ static uint64_t get_indexed_size(const Variant *base) { return VariantGetInternalPtr<m_base_type>::get_ptr(base)->size(); } \ }; @@ -515,6 +517,7 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const { v[index] = PtrToArg<m_elem_type>::convert(member); \ } \ static Variant::Type get_index_type() { return GetTypeInfo<m_elem_type>::VARIANT_TYPE; } \ + static uint32_t get_index_usage() { return GetTypeInfo<m_elem_type>::get_class_info().usage; } \ static uint64_t get_indexed_size(const Variant *base) { return m_max; } \ }; @@ -564,6 +567,7 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const { v m_accessor[index] = PtrToArg<m_elem_type>::convert(member); \ } \ static Variant::Type get_index_type() { return GetTypeInfo<m_elem_type>::VARIANT_TYPE; } \ + static uint32_t get_index_usage() { return GetTypeInfo<m_elem_type>::get_class_info().usage; } \ static uint64_t get_indexed_size(const Variant *base) { return m_max; } \ }; @@ -613,6 +617,7 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const { v.m_set(index, PtrToArg<m_elem_type>::convert(member)); \ } \ static Variant::Type get_index_type() { return GetTypeInfo<m_elem_type>::VARIANT_TYPE; } \ + static uint32_t get_index_usage() { return GetTypeInfo<m_elem_type>::get_class_info().usage; } \ static uint64_t get_indexed_size(const Variant *base) { return m_max; } \ }; @@ -683,6 +688,7 @@ struct VariantIndexedSetGet_Array { v.set(index, PtrToArg<Variant>::convert(member)); } static Variant::Type get_index_type() { return Variant::NIL; } + static uint32_t get_index_usage() { return PROPERTY_USAGE_NIL_IS_VARIANT; } static uint64_t get_indexed_size(const Variant *base) { return 0; } }; @@ -768,6 +774,7 @@ struct VariantIndexedSetGet_String { } } static Variant::Type get_index_type() { return Variant::STRING; } + static uint32_t get_index_usage() { return PROPERTY_USAGE_DEFAULT; } static uint64_t get_indexed_size(const Variant *base) { return VariantInternal::get_string(base)->length(); } }; @@ -812,6 +819,7 @@ struct VariantIndexedSetGet_String { v[index] = PtrToArg<Variant>::convert(member); \ } \ static Variant::Type get_index_type() { return Variant::NIL; } \ + static uint32_t get_index_usage() { return PROPERTY_USAGE_DEFAULT; } \ static uint64_t get_indexed_size(const Variant *base) { return VariantGetInternalPtr<m_base_type>::get_ptr(base)->size(); } \ }; @@ -852,7 +860,8 @@ struct VariantIndexedSetterGetterInfo { uint64_t (*get_indexed_size)(const Variant *base) = nullptr; - Variant::Type index_type; + Variant::Type index_type = Variant::NIL; + uint32_t index_usage = PROPERTY_USAGE_DEFAULT; bool valid = false; }; @@ -872,6 +881,7 @@ static void register_indexed_member(Variant::Type p_type) { sgi.ptr_getter = T::ptr_get; sgi.index_type = T::get_index_type(); + sgi.index_usage = T::get_index_usage(); sgi.get_indexed_size = T::get_indexed_size; sgi.valid = true; @@ -920,6 +930,11 @@ Variant::Type Variant::get_indexed_element_type(Variant::Type p_type) { return variant_indexed_setters_getters[p_type].index_type; } +uint32_t Variant::get_indexed_element_usage(Variant::Type p_type) { + ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, PROPERTY_USAGE_DEFAULT); + return variant_indexed_setters_getters[p_type].index_usage; +} + Variant::ValidatedIndexedSetter Variant::get_member_validated_indexed_setter(Variant::Type p_type) { ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, nullptr); return variant_indexed_setters_getters[p_type].validated_setter; @@ -1253,7 +1268,7 @@ bool Variant::iter_init(Variant &r_iter, bool &valid) const { return _data._int > 0; } break; case FLOAT: { - r_iter = 0; + r_iter = 0.0; return _data._float > 0.0; } break; case VECTOR2: { @@ -1457,7 +1472,7 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const { return true; } break; case FLOAT: { - int64_t idx = r_iter; + double idx = r_iter; idx++; if (idx >= _data._float) { return false; |