diff options
Diffstat (limited to 'core')
37 files changed, 554 insertions, 413 deletions
diff --git a/core/config/project_settings.cpp b/core/config/project_settings.cpp index ed89bc15d3..db3191334a 100644 --- a/core/config/project_settings.cpp +++ b/core/config/project_settings.cpp @@ -1232,12 +1232,9 @@ ProjectSettings::ProjectSettings() { singleton = this; GLOBAL_DEF_BASIC("application/config/name", ""); - GLOBAL_DEF_BASIC("application/config/name_localized", Dictionary()); - custom_prop_info["application/config/name_localized"] = PropertyInfo(Variant::DICTIONARY, "application/config/name_localized", PROPERTY_HINT_LOCALIZABLE_STRING); - GLOBAL_DEF_BASIC("application/config/description", ""); - custom_prop_info["application/config/description"] = PropertyInfo(Variant::STRING, "application/config/description", PROPERTY_HINT_MULTILINE_TEXT); - GLOBAL_DEF_BASIC("application/run/main_scene", ""); - custom_prop_info["application/run/main_scene"] = PropertyInfo(Variant::STRING, "application/run/main_scene", PROPERTY_HINT_FILE, "*.tscn,*.scn,*.res"); + GLOBAL_DEF_BASIC(PropertyInfo(Variant::DICTIONARY, "application/config/name_localized", PROPERTY_HINT_LOCALIZABLE_STRING), Dictionary()); + GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "application/config/description", PROPERTY_HINT_MULTILINE_TEXT), ""); + GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "application/run/main_scene", PROPERTY_HINT_FILE, "*.tscn,*.scn,*.res"), ""); GLOBAL_DEF("application/run/disable_stdout", false); GLOBAL_DEF("application/run/disable_stderr", false); GLOBAL_DEF_RST("application/config/use_hidden_project_data_directory", true); @@ -1249,22 +1246,15 @@ ProjectSettings::ProjectSettings() { // - Have a 16:9 aspect ratio, // - Have both dimensions divisible by 8 to better play along with video recording, // - Be displayable correctly in windowed mode on a 1366×768 display (tested on Windows 10 with default settings). - GLOBAL_DEF_BASIC("display/window/size/viewport_width", 1152); - custom_prop_info["display/window/size/viewport_width"] = PropertyInfo(Variant::INT, "display/window/size/viewport_width", PROPERTY_HINT_RANGE, "0,7680,1,or_greater"); // 8K resolution + GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "display/window/size/viewport_width", PROPERTY_HINT_RANGE, "0,7680,1,or_greater"), 1152); // 8K resolution + GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "display/window/size/viewport_height", PROPERTY_HINT_RANGE, "0,4320,1,or_greater"), 648); // 8K resolution - GLOBAL_DEF_BASIC("display/window/size/viewport_height", 648); - custom_prop_info["display/window/size/viewport_height"] = PropertyInfo(Variant::INT, "display/window/size/viewport_height", PROPERTY_HINT_RANGE, "0,4320,1,or_greater"); // 8K resolution - - GLOBAL_DEF_BASIC("display/window/size/mode", 0); - custom_prop_info["display/window/size/mode"] = PropertyInfo(Variant::INT, "display/window/size/mode", PROPERTY_HINT_ENUM, "Windowed,Minimized,Maximized,Fullscreen,Exclusive Fullscreen"); + GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "display/window/size/mode", PROPERTY_HINT_ENUM, "Windowed,Minimized,Maximized,Fullscreen,Exclusive Fullscreen"), 0); // Keep the enum values in sync with the `DisplayServer::SCREEN_` enum. - GLOBAL_DEF_BASIC("display/window/size/initial_screen", -2); - String screen_hints = "Primary Monitor:-2"; // Note: Main Window Monitor:-1 is not used for the main window, skip it. - for (int i = 0; i < 64; i++) { - screen_hints += ",Monitor " + itos(i + 1) + ":" + itos(i); - } - custom_prop_info["display/window/size/initial_screen"] = PropertyInfo(Variant::INT, "display/window/size/initial_screen", PROPERTY_HINT_ENUM, screen_hints); + GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "display/window/size/initial_position_type", PROPERTY_HINT_ENUM, "Absolute,Primary Screen Center,Other Screen Center"), 1); + GLOBAL_DEF_BASIC(PropertyInfo(Variant::VECTOR2I, "display/window/size/initial_position"), Vector2i()); + GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "display/window/size/initial_screen", PROPERTY_HINT_RANGE, "0,64,1,or_greater"), 0); GLOBAL_DEF_BASIC("display/window/size/resizable", true); GLOBAL_DEF_BASIC("display/window/size/borderless", false); @@ -1273,20 +1263,15 @@ ProjectSettings::ProjectSettings() { GLOBAL_DEF("display/window/size/extend_to_title", false); GLOBAL_DEF("display/window/size/no_focus", false); - GLOBAL_DEF("display/window/size/window_width_override", 0); - custom_prop_info["display/window/size/window_width_override"] = PropertyInfo(Variant::INT, "display/window/size/window_width_override", PROPERTY_HINT_RANGE, "0,7680,1,or_greater"); // 8K resolution - GLOBAL_DEF("display/window/size/window_height_override", 0); - custom_prop_info["display/window/size/window_height_override"] = PropertyInfo(Variant::INT, "display/window/size/window_height_override", PROPERTY_HINT_RANGE, "0,4320,1,or_greater"); // 8K resolution + GLOBAL_DEF(PropertyInfo(Variant::INT, "display/window/size/window_width_override", PROPERTY_HINT_RANGE, "0,7680,1,or_greater"), 0); // 8K resolution + GLOBAL_DEF(PropertyInfo(Variant::INT, "display/window/size/window_height_override", PROPERTY_HINT_RANGE, "0,4320,1,or_greater"), 0); // 8K resolution GLOBAL_DEF("display/window/energy_saving/keep_screen_on", true); GLOBAL_DEF("display/window/energy_saving/keep_screen_on.editor", false); - GLOBAL_DEF_BASIC("audio/buses/default_bus_layout", "res://default_bus_layout.tres"); - custom_prop_info["audio/buses/default_bus_layout"] = PropertyInfo(Variant::STRING, "audio/buses/default_bus_layout", PROPERTY_HINT_FILE, "*.tres"); - GLOBAL_DEF_RST("audio/general/2d_panning_strength", 0.5f); - custom_prop_info["audio/general/2d_panning_strength"] = PropertyInfo(Variant::FLOAT, "audio/general/2d_panning_strength", PROPERTY_HINT_RANGE, "0,2,0.01"); - GLOBAL_DEF_RST("audio/general/3d_panning_strength", 0.5f); - custom_prop_info["audio/general/3d_panning_strength"] = PropertyInfo(Variant::FLOAT, "audio/general/3d_panning_strength", PROPERTY_HINT_RANGE, "0,2,0.01"); + GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "audio/buses/default_bus_layout", PROPERTY_HINT_FILE, "*.tres"), "res://default_bus_layout.tres"); + GLOBAL_DEF_RST(PropertyInfo(Variant::FLOAT, "audio/general/2d_panning_strength", PROPERTY_HINT_RANGE, "0,2,0.01"), 0.5f); + GLOBAL_DEF_RST(PropertyInfo(Variant::FLOAT, "audio/general/3d_panning_strength", PROPERTY_HINT_RANGE, "0,2,0.01"), 0.5f); PackedStringArray extensions; extensions.push_back("gd"); @@ -1297,11 +1282,9 @@ ProjectSettings::ProjectSettings() { GLOBAL_DEF("editor/run/main_run_args", ""); - GLOBAL_DEF("editor/script/search_in_file_extensions", extensions); - custom_prop_info["editor/script/search_in_file_extensions"] = PropertyInfo(Variant::PACKED_STRING_ARRAY, "editor/script/search_in_file_extensions"); + GLOBAL_DEF(PropertyInfo(Variant::PACKED_STRING_ARRAY, "editor/script/search_in_file_extensions"), extensions); - GLOBAL_DEF("editor/script/templates_search_path", "res://script_templates"); - custom_prop_info["editor/script/templates_search_path"] = PropertyInfo(Variant::STRING, "editor/script/templates_search_path", PROPERTY_HINT_DIR); + GLOBAL_DEF(PropertyInfo(Variant::STRING, "editor/script/templates_search_path", PROPERTY_HINT_DIR), "res://script_templates"); _add_builtin_input_map(); @@ -1313,21 +1296,13 @@ ProjectSettings::ProjectSettings() { GLOBAL_DEF("physics/2d/run_on_separate_thread", false); GLOBAL_DEF("physics/3d/run_on_separate_thread", 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"); - - GLOBAL_DEF("compression/formats/zstd/long_distance_matching", Compression::zstd_long_distance_matching); - custom_prop_info["compression/formats/zstd/long_distance_matching"] = PropertyInfo(Variant::BOOL, "compression/formats/zstd/long_distance_matching"); - GLOBAL_DEF("compression/formats/zstd/compression_level", Compression::zstd_level); - custom_prop_info["compression/formats/zstd/compression_level"] = PropertyInfo(Variant::INT, "compression/formats/zstd/compression_level", PROPERTY_HINT_RANGE, "1,22,1"); - GLOBAL_DEF("compression/formats/zstd/window_log_size", Compression::zstd_window_log_size); - custom_prop_info["compression/formats/zstd/window_log_size"] = PropertyInfo(Variant::INT, "compression/formats/zstd/window_log_size", PROPERTY_HINT_RANGE, "10,30,1"); - - GLOBAL_DEF("compression/formats/zlib/compression_level", Compression::zlib_level); - custom_prop_info["compression/formats/zlib/compression_level"] = PropertyInfo(Variant::INT, "compression/formats/zlib/compression_level", PROPERTY_HINT_RANGE, "-1,9,1"); + GLOBAL_DEF(PropertyInfo(Variant::INT, "debug/settings/profiler/max_functions", PROPERTY_HINT_RANGE, "128,65535,1"), 16384); - 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(PropertyInfo(Variant::BOOL, "compression/formats/zstd/long_distance_matching"), Compression::zstd_long_distance_matching); + GLOBAL_DEF(PropertyInfo(Variant::INT, "compression/formats/zstd/compression_level", PROPERTY_HINT_RANGE, "1,22,1"), Compression::zstd_level); + GLOBAL_DEF(PropertyInfo(Variant::INT, "compression/formats/zstd/window_log_size", PROPERTY_HINT_RANGE, "10,30,1"), Compression::zstd_window_log_size); + GLOBAL_DEF(PropertyInfo(Variant::INT, "compression/formats/zlib/compression_level", PROPERTY_HINT_RANGE, "-1,9,1"), Compression::zlib_level); + GLOBAL_DEF(PropertyInfo(Variant::INT, "compression/formats/gzip/compression_level", PROPERTY_HINT_RANGE, "-1,9,1"), Compression::gzip_level); GLOBAL_DEF("debug/settings/crash_handler/message", String("Please include this when reporting the bug to the project developer.")); diff --git a/core/core_constants.cpp b/core/core_constants.cpp index edb72f73cb..e28f7bfc4f 100644 --- a/core/core_constants.cpp +++ b/core/core_constants.cpp @@ -274,14 +274,9 @@ void register_global_constants() { BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, KP_7); BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, KP_8); BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, KP_9); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, SUPER_L); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, SUPER_R); BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, MENU); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, HYPER_L); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, HYPER_R); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, HYPER); BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, HELP); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, DIRECTION_L); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, DIRECTION_R); BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, BACK); BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, FORWARD); BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, STOP); @@ -289,11 +284,6 @@ void register_global_constants() { BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, VOLUMEDOWN); BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, VOLUMEMUTE); BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, VOLUMEUP); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, BASSBOOST); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, BASSUP); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, BASSDOWN); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, TREBLEUP); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, TREBLEDOWN); BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, MEDIAPLAY); BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, MEDIASTOP); BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, MEDIAPREVIOUS); @@ -392,72 +382,12 @@ void register_global_constants() { BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, BAR); BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, BRACERIGHT); BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ASCIITILDE); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, NOBREAKSPACE); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, EXCLAMDOWN); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, CENT); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, STERLING); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, CURRENCY); BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, YEN); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, BROKENBAR); BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, SECTION); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, DIAERESIS); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, COPYRIGHT); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ORDFEMININE); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, GUILLEMOTLEFT); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, NOTSIGN); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, HYPHEN); - BIND_CORE_ENUM_CLASS_CONSTANT_CUSTOM(Key, KEY_REGISTERED, KEY_REGISTERED); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, MACRON); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, DEGREE); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, PLUSMINUS); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, TWOSUPERIOR); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, THREESUPERIOR); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ACUTE); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, MU); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, PARAGRAPH); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, PERIODCENTERED); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, CEDILLA); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ONESUPERIOR); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, MASCULINE); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, GUILLEMOTRIGHT); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ONEQUARTER); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ONEHALF); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, THREEQUARTERS); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, QUESTIONDOWN); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, AGRAVE); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, AACUTE); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ACIRCUMFLEX); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ATILDE); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ADIAERESIS); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ARING); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, AE); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, CCEDILLA); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, EGRAVE); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, EACUTE); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ECIRCUMFLEX); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, EDIAERESIS); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, IGRAVE); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, IACUTE); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ICIRCUMFLEX); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, IDIAERESIS); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ETH); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, NTILDE); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, OGRAVE); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, OACUTE); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, OCIRCUMFLEX); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, OTILDE); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ODIAERESIS); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, MULTIPLY); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, OOBLIQUE); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, UGRAVE); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, UACUTE); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, UCIRCUMFLEX); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, UDIAERESIS); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, YACUTE); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, THORN); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, SSHARP); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, DIVISION); - BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, YDIAERESIS); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, GLOBE); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, KEYBOARD); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, JIS_EISU); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, JIS_KANA); BIND_CORE_BITFIELD_CLASS_FLAG_CUSTOM(KeyModifierMask, KEY_CODE_MASK, CODE_MASK); BIND_CORE_BITFIELD_CLASS_FLAG_CUSTOM(KeyModifierMask, KEY_MODIFIER_MASK, MODIFIER_MASK); diff --git a/core/error/error_macros.cpp b/core/error/error_macros.cpp index ddfee3fc5d..8376c0aaf8 100644 --- a/core/error/error_macros.cpp +++ b/core/error/error_macros.cpp @@ -118,11 +118,11 @@ void _err_print_error(const char *p_function, const char *p_file, int p_line, co void _err_print_index_error(const char *p_function, const char *p_file, int p_line, int64_t p_index, int64_t p_size, const char *p_index_str, const char *p_size_str, const char *p_message, bool p_editor_notify, bool p_fatal) { String fstr(p_fatal ? "FATAL: " : ""); String err(fstr + "Index " + p_index_str + " = " + itos(p_index) + " is out of bounds (" + p_size_str + " = " + itos(p_size) + ")."); - _err_print_error(p_function, p_file, p_line, err.utf8().get_data(), p_message); + _err_print_error(p_function, p_file, p_line, err.utf8().get_data(), p_message, p_editor_notify, ERR_HANDLER_ERROR); } void _err_print_index_error(const char *p_function, const char *p_file, int p_line, int64_t p_index, int64_t p_size, const char *p_index_str, const char *p_size_str, const String &p_message, bool p_editor_notify, bool p_fatal) { - _err_print_index_error(p_function, p_file, p_line, p_index, p_size, p_index_str, p_size_str, p_message.utf8().get_data(), p_fatal); + _err_print_index_error(p_function, p_file, p_line, p_index, p_size, p_index_str, p_size_str, p_message.utf8().get_data(), p_editor_notify, p_fatal); } void _err_flush_stdout() { diff --git a/core/error/error_macros.h b/core/error/error_macros.h index 63a2d22416..65804b7796 100644 --- a/core/error/error_macros.h +++ b/core/error/error_macros.h @@ -189,12 +189,12 @@ void _err_flush_stdout(); * Ensures an integer index `m_index` is less than `m_size` and greater than or equal to 0. * If not, the application crashes. */ -#define CRASH_BAD_INDEX(m_index, m_size) \ - if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \ - _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), "", true); \ - _err_flush_stdout(); \ - GENERATE_TRAP(); \ - } else \ +#define CRASH_BAD_INDEX(m_index, m_size) \ + if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \ + _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), "", false, true); \ + _err_flush_stdout(); \ + GENERATE_TRAP(); \ + } else \ ((void)0) /** @@ -204,12 +204,12 @@ void _err_flush_stdout(); * Ensures an integer index `m_index` is less than `m_size` and greater than or equal to 0. * If not, prints `m_msg` and the application crashes. */ -#define CRASH_BAD_INDEX_MSG(m_index, m_size, m_msg) \ - if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \ - _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), m_msg, true); \ - _err_flush_stdout(); \ - GENERATE_TRAP(); \ - } else \ +#define CRASH_BAD_INDEX_MSG(m_index, m_size, m_msg) \ + if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \ + _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), m_msg, false, true); \ + _err_flush_stdout(); \ + GENERATE_TRAP(); \ + } else \ ((void)0) // Unsigned integer index out of bounds error macros. @@ -292,12 +292,12 @@ void _err_flush_stdout(); * Ensures an unsigned integer index `m_index` is less than `m_size`. * If not, the application crashes. */ -#define CRASH_BAD_UNSIGNED_INDEX(m_index, m_size) \ - if (unlikely((m_index) >= (m_size))) { \ - _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), "", true); \ - _err_flush_stdout(); \ - GENERATE_TRAP(); \ - } else \ +#define CRASH_BAD_UNSIGNED_INDEX(m_index, m_size) \ + if (unlikely((m_index) >= (m_size))) { \ + _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), "", false, true); \ + _err_flush_stdout(); \ + GENERATE_TRAP(); \ + } else \ ((void)0) /** @@ -307,12 +307,12 @@ void _err_flush_stdout(); * Ensures an unsigned integer index `m_index` is less than `m_size`. * If not, prints `m_msg` and the application crashes. */ -#define CRASH_BAD_UNSIGNED_INDEX_MSG(m_index, m_size, m_msg) \ - if (unlikely((m_index) >= (m_size))) { \ - _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), m_msg, true); \ - _err_flush_stdout(); \ - GENERATE_TRAP(); \ - } else \ +#define CRASH_BAD_UNSIGNED_INDEX_MSG(m_index, m_size, m_msg) \ + if (unlikely((m_index) >= (m_size))) { \ + _err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), m_msg, false, true); \ + _err_flush_stdout(); \ + GENERATE_TRAP(); \ + } else \ ((void)0) // Null reference error macros. diff --git a/core/input/input.cpp b/core/input/input.cpp index 0afa004515..1ea9f00fee 100644 --- a/core/input/input.cpp +++ b/core/input/input.cpp @@ -93,6 +93,7 @@ void Input::_bind_methods() { ClassDB::bind_method(D_METHOD("is_anything_pressed"), &Input::is_anything_pressed); ClassDB::bind_method(D_METHOD("is_key_pressed", "keycode"), &Input::is_key_pressed); ClassDB::bind_method(D_METHOD("is_physical_key_pressed", "keycode"), &Input::is_physical_key_pressed); + ClassDB::bind_method(D_METHOD("is_key_label_pressed", "keycode"), &Input::is_key_label_pressed); ClassDB::bind_method(D_METHOD("is_mouse_button_pressed", "button"), &Input::is_mouse_button_pressed); ClassDB::bind_method(D_METHOD("is_joy_button_pressed", "device", "button"), &Input::is_joy_button_pressed); ClassDB::bind_method(D_METHOD("is_action_pressed", "action", "exact_match"), &Input::is_action_pressed, DEFVAL(false)); @@ -250,6 +251,11 @@ bool Input::is_physical_key_pressed(Key p_keycode) const { return physical_keys_pressed.has(p_keycode); } +bool Input::is_key_label_pressed(Key p_keycode) const { + _THREAD_SAFE_METHOD_ + return key_label_pressed.has(p_keycode); +} + bool Input::is_mouse_button_pressed(MouseButton p_button) const { _THREAD_SAFE_METHOD_ return mouse_button_mask.has_flag(mouse_button_to_mask(p_button)); @@ -499,6 +505,13 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em physical_keys_pressed.erase(k->get_physical_keycode()); } } + if (k.is_valid() && !k->is_echo() && k->get_key_label() != Key::NONE) { + if (k->is_pressed()) { + key_label_pressed.insert(k->get_key_label()); + } else { + key_label_pressed.erase(k->get_key_label()); + } + } Ref<InputEventMouseButton> mb = p_event; @@ -919,6 +932,7 @@ void Input::release_pressed_events() { keys_pressed.clear(); physical_keys_pressed.clear(); + key_label_pressed.clear(); joy_buttons_pressed.clear(); _joy_axis.clear(); diff --git a/core/input/input.h b/core/input/input.h index 0915588700..f2de56b6b9 100644 --- a/core/input/input.h +++ b/core/input/input.h @@ -84,6 +84,7 @@ public: private: BitField<MouseButtonMask> mouse_button_mask; + RBSet<Key> key_label_pressed; RBSet<Key> physical_keys_pressed; RBSet<Key> keys_pressed; RBSet<JoyButton> joy_buttons_pressed; @@ -247,6 +248,7 @@ public: bool is_anything_pressed() const; bool is_key_pressed(Key p_keycode) const; bool is_physical_key_pressed(Key p_keycode) const; + bool is_key_label_pressed(Key p_keycode) const; bool is_mouse_button_pressed(MouseButton p_button) const; bool is_joy_button_pressed(int p_device, JoyButton p_button) const; bool is_action_pressed(const StringName &p_action, bool p_exact = false) const; diff --git a/core/input/input_event.cpp b/core/input/input_event.cpp index 0dd7fdc19b..dbe9b55ee3 100644 --- a/core/input/input_event.cpp +++ b/core/input/input_event.cpp @@ -285,6 +285,8 @@ void InputEventWithModifiers::_bind_methods() { ClassDB::bind_method(D_METHOD("set_meta_pressed", "pressed"), &InputEventWithModifiers::set_meta_pressed); ClassDB::bind_method(D_METHOD("is_meta_pressed"), &InputEventWithModifiers::is_meta_pressed); + ClassDB::bind_method(D_METHOD("get_modifiers_mask"), &InputEventWithModifiers::get_modifiers_mask); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "command_or_control_autoremap"), "set_command_or_control_autoremap", "is_command_or_control_autoremap"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "alt_pressed"), "set_alt_pressed", "is_alt_pressed"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "shift_pressed"), "set_shift_pressed", "is_shift_pressed"); @@ -328,6 +330,15 @@ Key InputEventKey::get_keycode() const { return keycode; } +void InputEventKey::set_key_label(Key p_key_label) { + key_label = p_key_label; + emit_changed(); +} + +Key InputEventKey::get_key_label() const { + return key_label; +} + void InputEventKey::set_physical_keycode(Key p_keycode) { physical_keycode = p_keycode; emit_changed(); @@ -363,13 +374,72 @@ Key InputEventKey::get_physical_keycode_with_modifiers() const { return physical_keycode | (int64_t)get_modifiers_mask(); } +Key InputEventKey::get_key_label_with_modifiers() const { + return key_label | get_modifiers_mask(); +} + +String InputEventKey::as_text_physical_keycode() const { + String kc; + + if (physical_keycode != Key::NONE) { + kc = keycode_get_string(physical_keycode); + } else { + kc = "(" + RTR("Unset") + ")"; + } + + if (kc.is_empty()) { + return kc; + } + + String mods_text = InputEventWithModifiers::as_text(); + return mods_text.is_empty() ? kc : mods_text + "+" + kc; +} + +String InputEventKey::as_text_keycode() const { + String kc; + + if (keycode != Key::NONE) { + kc = keycode_get_string(keycode); + } else { + kc = "(" + RTR("Unset") + ")"; + } + + if (kc.is_empty()) { + return kc; + } + + String mods_text = InputEventWithModifiers::as_text(); + return mods_text.is_empty() ? kc : mods_text + "+" + kc; +} + +String InputEventKey::as_text_key_label() const { + String kc; + + if (key_label != Key::NONE) { + kc = keycode_get_string(key_label); + } else { + kc = "(" + RTR("Unset") + ")"; + } + + if (kc.is_empty()) { + return kc; + } + + String mods_text = InputEventWithModifiers::as_text(); + return mods_text.is_empty() ? kc : mods_text + "+" + kc; +} + String InputEventKey::as_text() const { String kc; - if (keycode == Key::NONE) { + if (keycode == Key::NONE && physical_keycode == Key::NONE && key_label != Key::NONE) { + kc = keycode_get_string(key_label) + " (Unicode)"; + } else if (keycode != Key::NONE) { + kc = keycode_get_string(keycode); + } else if (physical_keycode != Key::NONE) { kc = keycode_get_string(physical_keycode) + " (" + RTR("Physical") + ")"; } else { - kc = keycode_get_string(keycode); + kc = "(" + RTR("Unset") + ")"; } if (kc.is_empty()) { @@ -386,11 +456,16 @@ String InputEventKey::to_string() { String kc = ""; String physical = "false"; - if (keycode == Key::NONE) { + + if (keycode == Key::NONE && physical_keycode == Key::NONE && unicode != 0) { + kc = "U+" + String::num_uint64(unicode, 16) + " (" + String::chr(unicode) + ")"; + } else if (keycode != Key::NONE) { + kc = itos((int64_t)keycode) + " (" + keycode_get_string(keycode) + ")"; + } else if (physical_keycode != Key::NONE) { kc = itos((int64_t)physical_keycode) + " (" + keycode_get_string(physical_keycode) + ")"; physical = "true"; } else { - kc = itos((int64_t)keycode) + " (" + keycode_get_string(keycode) + ")"; + kc = "(" + RTR("Unset") + ")"; } String mods = InputEventWithModifiers::as_text(); @@ -403,6 +478,7 @@ Ref<InputEventKey> InputEventKey::create_reference(Key p_keycode) { Ref<InputEventKey> ie; ie.instantiate(); ie->set_keycode(p_keycode & KeyModifierMask::CODE_MASK); + ie->set_key_label(p_keycode & KeyModifierMask::CODE_MASK); ie->set_unicode(char32_t(p_keycode & KeyModifierMask::CODE_MASK)); if ((p_keycode & KeyModifierMask::SHIFT) != Key::NONE) { @@ -435,11 +511,16 @@ bool InputEventKey::action_match(const Ref<InputEvent> &p_event, bool p_exact_ma } bool match; - if (keycode != Key::NONE) { + if (keycode == Key::NONE && physical_keycode == Key::NONE && key_label != Key::NONE) { + match = key_label == key->key_label; + } else if (keycode != Key::NONE) { match = keycode == key->keycode; + } else if (physical_keycode != Key::NONE) { + match = physical_keycode == key->physical_keycode; } else { - match = get_physical_keycode() == key->get_physical_keycode(); + match = false; } + Key action_mask = (Key)(int64_t)get_modifiers_mask(); Key key_mask = (Key)(int64_t)key->get_modifiers_mask(); if (key->is_pressed()) { @@ -470,12 +551,17 @@ bool InputEventKey::is_match(const Ref<InputEvent> &p_event, bool p_exact_match) return false; } - if (keycode == Key::NONE) { - return physical_keycode == key->physical_keycode && + if (keycode == Key::NONE && physical_keycode == Key::NONE && key_label != Key::NONE) { + return (key_label == key->key_label) && (!p_exact_match || get_modifiers_mask() == key->get_modifiers_mask()); - } else { - return keycode == key->keycode && + } else if (keycode != Key::NONE) { + return (keycode == key->keycode) && (!p_exact_match || get_modifiers_mask() == key->get_modifiers_mask()); + } else if (physical_keycode != Key::NONE) { + return (physical_keycode == key->physical_keycode) && + (!p_exact_match || get_modifiers_mask() == key->get_modifiers_mask()); + } else { + return false; } } @@ -488,6 +574,9 @@ void InputEventKey::_bind_methods() { ClassDB::bind_method(D_METHOD("set_physical_keycode", "physical_keycode"), &InputEventKey::set_physical_keycode); ClassDB::bind_method(D_METHOD("get_physical_keycode"), &InputEventKey::get_physical_keycode); + ClassDB::bind_method(D_METHOD("set_key_label", "key_label"), &InputEventKey::set_key_label); + ClassDB::bind_method(D_METHOD("get_key_label"), &InputEventKey::get_key_label); + ClassDB::bind_method(D_METHOD("set_unicode", "unicode"), &InputEventKey::set_unicode); ClassDB::bind_method(D_METHOD("get_unicode"), &InputEventKey::get_unicode); @@ -495,10 +584,16 @@ void InputEventKey::_bind_methods() { ClassDB::bind_method(D_METHOD("get_keycode_with_modifiers"), &InputEventKey::get_keycode_with_modifiers); ClassDB::bind_method(D_METHOD("get_physical_keycode_with_modifiers"), &InputEventKey::get_physical_keycode_with_modifiers); + ClassDB::bind_method(D_METHOD("get_key_label_with_modifiers"), &InputEventKey::get_key_label_with_modifiers); + + ClassDB::bind_method(D_METHOD("as_text_keycode"), &InputEventKey::as_text_keycode); + ClassDB::bind_method(D_METHOD("as_text_physical_keycode"), &InputEventKey::as_text_physical_keycode); + ClassDB::bind_method(D_METHOD("as_text_key_label"), &InputEventKey::as_text_key_label); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed"); ADD_PROPERTY(PropertyInfo(Variant::INT, "keycode"), "set_keycode", "get_keycode"); ADD_PROPERTY(PropertyInfo(Variant::INT, "physical_keycode"), "set_physical_keycode", "get_physical_keycode"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "key_label"), "set_key_label", "get_key_label"); ADD_PROPERTY(PropertyInfo(Variant::INT, "unicode"), "set_unicode", "get_unicode"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "echo"), "set_echo", "is_echo"); } diff --git a/core/input/input_event.h b/core/input/input_event.h index 2d7a72e327..797761b208 100644 --- a/core/input/input_event.h +++ b/core/input/input_event.h @@ -153,6 +153,7 @@ class InputEventKey : public InputEventWithModifiers { Key keycode = Key::NONE; // Key enum, without modifier masks. Key physical_keycode = Key::NONE; + Key key_label = Key::NONE; uint32_t unicode = 0; ///unicode bool echo = false; /// true if this is an echo key @@ -170,6 +171,9 @@ public: void set_physical_keycode(Key p_keycode); Key get_physical_keycode() const; + void set_key_label(Key p_key_label); + Key get_key_label() const; + void set_unicode(char32_t p_unicode); char32_t get_unicode() const; @@ -178,12 +182,16 @@ public: Key get_keycode_with_modifiers() const; Key get_physical_keycode_with_modifiers() const; + Key get_key_label_with_modifiers() const; virtual bool action_match(const Ref<InputEvent> &p_event, bool p_exact_match, float p_deadzone, bool *r_pressed, float *r_strength, float *r_raw_strength) const override; virtual bool is_match(const Ref<InputEvent> &p_event, bool p_exact_match = true) const override; virtual bool is_action_type() const override { return true; } + virtual String as_text_physical_keycode() const; + virtual String as_text_keycode() const; + virtual String as_text_key_label() const; virtual String as_text() const override; virtual String to_string() override; 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/marshalls.h b/core/io/marshalls.h index 5e760c7565..6f015ac386 100644 --- a/core/io/marshalls.h +++ b/core/io/marshalls.h @@ -44,7 +44,7 @@ typedef uint32_t uintr_t; #endif /** - * Miscellaneous helpers for marshalling data types, and encoding + * Miscellaneous helpers for marshaling data types, and encoding * in an endian independent way */ diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index 03beb25b03..c0463de427 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -91,7 +91,8 @@ enum { // Version 2: added 64 bits support for float and int. // Version 3: changed nodepath encoding. // Version 4: new string ID for ext/subresources, breaks forward compat. - FORMAT_VERSION = 4, + // Version 5: Ability to store script class in the header. + FORMAT_VERSION = 5, FORMAT_VERSION_CAN_RENAME_DEPS = 1, FORMAT_VERSION_NO_NODEPATH_PROPERTY = 3, }; @@ -1009,6 +1010,10 @@ void ResourceLoaderBinary::open(Ref<FileAccess> p_f, bool p_no_resources, bool p uid = ResourceUID::INVALID_ID; } + if (flags & ResourceFormatSaverBinaryInstance::FORMAT_FLAG_HAS_SCRIPT_CLASS) { + script_class = get_unicode_string(); + } + for (int i = 0; i < ResourceFormatSaverBinaryInstance::RESERVED_FIELDS; i++) { f->get_32(); //skip a few reserved fields } @@ -1113,6 +1118,57 @@ String ResourceLoaderBinary::recognize(Ref<FileAccess> p_f) { return get_unicode_string(); } +String ResourceLoaderBinary::recognize_script_class(Ref<FileAccess> p_f) { + error = OK; + + f = p_f; + uint8_t header[4]; + f->get_buffer(header, 4); + if (header[0] == 'R' && header[1] == 'S' && header[2] == 'C' && header[3] == 'C') { + // Compressed. + Ref<FileAccessCompressed> fac; + fac.instantiate(); + error = fac->open_after_magic(f); + if (error != OK) { + f.unref(); + return ""; + } + f = fac; + + } else if (header[0] != 'R' || header[1] != 'S' || header[2] != 'R' || header[3] != 'C') { + // Not normal. + error = ERR_FILE_UNRECOGNIZED; + f.unref(); + return ""; + } + + bool big_endian = f->get_32(); + f->get_32(); // use_real64 + + f->set_big_endian(big_endian != 0); //read big endian if saved as big endian + + uint32_t ver_major = f->get_32(); + f->get_32(); // ver_minor + uint32_t ver_fmt = f->get_32(); + + if (ver_fmt > FORMAT_VERSION || ver_major > VERSION_MAJOR) { + f.unref(); + return ""; + } + + get_unicode_string(); // type + + f->get_64(); // Metadata offset + uint32_t flags = f->get_32(); + f->get_64(); // UID + + if (flags & ResourceFormatSaverBinaryInstance::FORMAT_FLAG_HAS_SCRIPT_CLASS) { + return get_unicode_string(); + } else { + return String(); + } +} + Ref<Resource> ResourceFormatLoaderBinary::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) { if (r_error) { *r_error = ERR_FILE_CANT_OPEN; @@ -1295,6 +1351,9 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons fw->store_32(flags); fw->store_64(uid_data); + if (flags & ResourceFormatSaverBinaryInstance::FORMAT_FLAG_HAS_SCRIPT_CLASS) { + save_ustring(fw, get_ustring(f)); + } for (int i = 0; i < ResourceFormatSaverBinaryInstance::RESERVED_FIELDS; i++) { fw->store_32(0); // reserved @@ -1416,6 +1475,18 @@ String ResourceFormatLoaderBinary::get_resource_type(const String &p_path) const return ClassDB::get_compatibility_remapped_class(r); } +String ResourceFormatLoaderBinary::get_resource_script_class(const String &p_path) const { + Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::READ); + if (f.is_null()) { + return ""; //could not read + } + + ResourceLoaderBinary loader; + loader.local_path = ProjectSettings::get_singleton()->localize_path(p_path); + loader.res_path = loader.local_path; + return loader.recognize_script_class(f); +} + ResourceUID::ID ResourceFormatLoaderBinary::get_resource_uid(const String &p_path) const { String ext = p_path.get_extension().to_lower(); if (!ClassDB::is_resource_extension(ext)) { @@ -2033,15 +2104,31 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const Ref<Re save_unicode_string(f, _resource_get_class(p_resource)); f->store_64(0); //offset to import metadata + + String script_class; { uint32_t format_flags = FORMAT_FLAG_NAMED_SCENE_IDS | FORMAT_FLAG_UIDS; #ifdef REAL_T_IS_DOUBLE format_flags |= FORMAT_FLAG_REAL_T_IS_DOUBLE; #endif + if (!p_resource->is_class("PackedScene")) { + Ref<Script> s = p_resource->get_script(); + if (s.is_valid()) { + script_class = s->get_global_name(); + if (!script_class.is_empty()) { + format_flags |= ResourceFormatSaverBinaryInstance::FORMAT_FLAG_HAS_SCRIPT_CLASS; + } + } + } + f->store_32(format_flags); } ResourceUID::ID uid = ResourceSaver::get_resource_id_for_path(p_path, true); f->store_64(uid); + if (!script_class.is_empty()) { + save_unicode_string(f, script_class); + } + for (int i = 0; i < ResourceFormatSaverBinaryInstance::RESERVED_FIELDS; i++) { f->store_32(0); // reserved } @@ -2294,6 +2381,10 @@ Error ResourceFormatSaverBinaryInstance::set_uid(const String &p_path, ResourceU fw->store_32(flags); fw->store_64(p_uid); + if (flags & ResourceFormatSaverBinaryInstance::FORMAT_FLAG_HAS_SCRIPT_CLASS) { + save_ustring(fw, get_ustring(f)); + } + //rest of file uint8_t b = f->get_8(); while (!f->eof_reached()) { diff --git a/core/io/resource_format_binary.h b/core/io/resource_format_binary.h index 9dd208e3cd..add7cdf297 100644 --- a/core/io/resource_format_binary.h +++ b/core/io/resource_format_binary.h @@ -65,6 +65,7 @@ class ResourceLoaderBinary { bool using_named_scene_ids = false; bool using_uids = false; + String script_class; bool use_sub_threads = false; float *progress = nullptr; Vector<ExtResource> external_resources; @@ -99,6 +100,7 @@ public: void set_remaps(const HashMap<String, String> &p_remaps) { remaps = p_remaps; } void open(Ref<FileAccess> p_f, bool p_no_resources = false, bool p_keep_uuid_paths = false); String recognize(Ref<FileAccess> p_f); + String recognize_script_class(Ref<FileAccess> p_f); void get_dependencies(Ref<FileAccess> p_f, List<String> *p_dependencies, bool p_add_types); void get_classes_used(Ref<FileAccess> p_f, HashSet<StringName> *p_classes); @@ -112,6 +114,7 @@ public: virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual bool handles_type(const String &p_type) const; virtual String get_resource_type(const String &p_path) const; + virtual String get_resource_script_class(const String &p_path) const; virtual void get_classes_used(const String &p_path, HashSet<StringName> *r_classes); virtual ResourceUID::ID get_resource_uid(const String &p_path) const; virtual void get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types = false); @@ -164,6 +167,7 @@ public: FORMAT_FLAG_NAMED_SCENE_IDS = 1, FORMAT_FLAG_UIDS = 2, FORMAT_FLAG_REAL_T_IS_DOUBLE = 4, + FORMAT_FLAG_HAS_SCRIPT_CLASS = 8, // Amount of reserved 32-bit fields in resource header RESERVED_FIELDS = 11 diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp index 68b9f8b6f7..7447119ab7 100644 --- a/core/io/resource_loader.cpp +++ b/core/io/resource_loader.cpp @@ -99,6 +99,12 @@ String ResourceFormatLoader::get_resource_type(const String &p_path) const { return ret; } +String ResourceFormatLoader::get_resource_script_class(const String &p_path) const { + String ret; + GDVIRTUAL_CALL(_get_resource_script_class, p_path, ret); + return ret; +} + ResourceUID::ID ResourceFormatLoader::get_resource_uid(const String &p_path) const { int64_t uid = ResourceUID::INVALID_ID; GDVIRTUAL_CALL(_get_resource_uid, p_path, uid); @@ -184,6 +190,7 @@ void ResourceFormatLoader::_bind_methods() { GDVIRTUAL_BIND(_recognize_path, "path", "type"); GDVIRTUAL_BIND(_handles_type, "type"); GDVIRTUAL_BIND(_get_resource_type, "path"); + GDVIRTUAL_BIND(_get_resource_script_class, "path"); GDVIRTUAL_BIND(_get_resource_uid, "path"); GDVIRTUAL_BIND(_get_dependencies, "path", "add_types"); GDVIRTUAL_BIND(_rename_dependencies, "path", "renames"); @@ -764,6 +771,19 @@ String ResourceLoader::get_resource_type(const String &p_path) { return ""; } +String ResourceLoader::get_resource_script_class(const String &p_path) { + String local_path = _validate_local_path(p_path); + + for (int i = 0; i < loader_count; i++) { + String result = loader[i]->get_resource_script_class(local_path); + if (!result.is_empty()) { + return result; + } + } + + return ""; +} + ResourceUID::ID ResourceLoader::get_resource_uid(const String &p_path) { String local_path = _validate_local_path(p_path); diff --git a/core/io/resource_loader.h b/core/io/resource_loader.h index e427a2f5fc..eb8155e046 100644 --- a/core/io/resource_loader.h +++ b/core/io/resource_loader.h @@ -54,6 +54,7 @@ protected: GDVIRTUAL2RC(bool, _recognize_path, String, StringName) GDVIRTUAL1RC(bool, _handles_type, StringName) GDVIRTUAL1RC(String, _get_resource_type, String) + GDVIRTUAL1RC(String, _get_resource_script_class, String) GDVIRTUAL1RC(ResourceUID::ID, _get_resource_uid, String) GDVIRTUAL2RC(Vector<String>, _get_dependencies, String, bool) GDVIRTUAL1RC(Vector<String>, _get_classes_used, String) @@ -71,6 +72,7 @@ public: virtual bool handles_type(const String &p_type) const; virtual void get_classes_used(const String &p_path, HashSet<StringName> *r_classes); virtual String get_resource_type(const String &p_path) const; + virtual String get_resource_script_class(const String &p_path) const; virtual ResourceUID::ID get_resource_uid(const String &p_path) const; virtual void get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types = false); virtual Error rename_dependencies(const String &p_path, const HashMap<String, String> &p_map); @@ -175,6 +177,7 @@ public: static void remove_resource_format_loader(Ref<ResourceFormatLoader> p_format_loader); static void get_classes_used(const String &p_path, HashSet<StringName> *r_classes); static String get_resource_type(const String &p_path); + static String get_resource_script_class(const String &p_path); static ResourceUID::ID get_resource_uid(const String &p_path); static void get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types = false); static Error rename_dependencies(const String &p_path, const HashMap<String, String> &p_map); diff --git a/core/math/a_star.cpp b/core/math/a_star.cpp index a54804c5dc..646bdea758 100644 --- a/core/math/a_star.cpp +++ b/core/math/a_star.cpp @@ -106,11 +106,11 @@ void AStar3D::remove_point(int64_t p_id) { bool p_exists = points.lookup(p_id, p); ERR_FAIL_COND_MSG(!p_exists, vformat("Can't remove point. Point with id: %d doesn't exist.", p_id)); - for (OAHashMap<int64_t, Point *>::Iterator it = p->neighbours.iter(); it.valid; it = p->neighbours.next_iter(it)) { + for (OAHashMap<int64_t, Point *>::Iterator it = p->neighbors.iter(); it.valid; it = p->neighbors.next_iter(it)) { Segment s(p_id, (*it.key)); segments.erase(s); - (*it.value)->neighbours.remove(p->id); + (*it.value)->neighbors.remove(p->id); (*it.value)->unlinked_neighbours.remove(p->id); } @@ -118,7 +118,7 @@ void AStar3D::remove_point(int64_t p_id) { Segment s(p_id, (*it.key)); segments.erase(s); - (*it.value)->neighbours.remove(p->id); + (*it.value)->neighbors.remove(p->id); (*it.value)->unlinked_neighbours.remove(p->id); } @@ -138,10 +138,10 @@ void AStar3D::connect_points(int64_t p_id, int64_t p_with_id, bool bidirectional bool to_exists = points.lookup(p_with_id, b); ERR_FAIL_COND_MSG(!to_exists, vformat("Can't connect points. Point with id: %d doesn't exist.", p_with_id)); - a->neighbours.set(b->id, b); + a->neighbors.set(b->id, b); if (bidirectional) { - b->neighbours.set(a->id, a); + b->neighbors.set(a->id, a); } else { b->unlinked_neighbours.set(a->id, a); } @@ -155,7 +155,7 @@ void AStar3D::connect_points(int64_t p_id, int64_t p_with_id, bool bidirectional if (element) { s.direction |= element->direction; if (s.direction == Segment::BIDIRECTIONAL) { - // Both are neighbours of each other now + // Both are neighbors of each other now a->unlinked_neighbours.remove(b->id); b->unlinked_neighbours.remove(a->id); } @@ -183,9 +183,9 @@ void AStar3D::disconnect_points(int64_t p_id, int64_t p_with_id, bool bidirectio // Erase the directions to be removed s.direction = (element->direction & ~remove_direction); - a->neighbours.remove(b->id); + a->neighbors.remove(b->id); if (bidirectional) { - b->neighbours.remove(a->id); + b->neighbors.remove(a->id); if (element->direction != Segment::BIDIRECTIONAL) { a->unlinked_neighbours.remove(b->id); b->unlinked_neighbours.remove(a->id); @@ -226,7 +226,7 @@ Vector<int64_t> AStar3D::get_point_connections(int64_t p_id) { Vector<int64_t> point_list; - for (OAHashMap<int64_t, Point *>::Iterator it = p->neighbours.iter(); it.valid; it = p->neighbours.next_iter(it)) { + for (OAHashMap<int64_t, Point *>::Iterator it = p->neighbors.iter(); it.valid; it = p->neighbors.next_iter(it)) { point_list.push_back((*it.key)); } @@ -346,8 +346,8 @@ bool AStar3D::_solve(Point *begin_point, Point *end_point) { open_list.remove_at(open_list.size() - 1); p->closed_pass = pass; // Mark the point as closed - for (OAHashMap<int64_t, Point *>::Iterator it = p->neighbours.iter(); it.valid; it = p->neighbours.next_iter(it)) { - Point *e = *(it.value); // The neighbour point + for (OAHashMap<int64_t, Point *>::Iterator it = p->neighbors.iter(); it.valid; it = p->neighbors.next_iter(it)) { + Point *e = *(it.value); // The neighbor point if (!e->enabled || e->closed_pass == pass) { continue; @@ -794,7 +794,7 @@ bool AStar2D::_solve(AStar3D::Point *begin_point, AStar3D::Point *end_point) { bool found_route = false; - Vector<AStar3D::Point *> open_list; + LocalVector<AStar3D::Point *> open_list; SortArray<AStar3D::Point *, AStar3D::SortPoints> sorter; begin_point->g_score = 0; @@ -802,19 +802,19 @@ bool AStar2D::_solve(AStar3D::Point *begin_point, AStar3D::Point *end_point) { open_list.push_back(begin_point); while (!open_list.is_empty()) { - AStar3D::Point *p = open_list[0]; // The currently processed point + AStar3D::Point *p = open_list[0]; // The currently processed point. if (p == end_point) { found_route = true; break; } - sorter.pop_heap(0, open_list.size(), open_list.ptrw()); // Remove the current point from the open list + sorter.pop_heap(0, open_list.size(), open_list.ptr()); // Remove the current point from the open list. open_list.remove_at(open_list.size() - 1); - p->closed_pass = astar.pass; // Mark the point as closed + p->closed_pass = astar.pass; // Mark the point as closed. - for (OAHashMap<int64_t, AStar3D::Point *>::Iterator it = p->neighbours.iter(); it.valid; it = p->neighbours.next_iter(it)) { - AStar3D::Point *e = *(it.value); // The neighbour point + for (OAHashMap<int64_t, AStar3D::Point *>::Iterator it = p->neighbors.iter(); it.valid; it = p->neighbors.next_iter(it)) { + AStar3D::Point *e = *(it.value); // The neighbor point. if (!e->enabled || e->closed_pass == astar.pass) { continue; @@ -837,9 +837,9 @@ bool AStar2D::_solve(AStar3D::Point *begin_point, AStar3D::Point *end_point) { e->f_score = e->g_score + _estimate_cost(e->id, end_point->id); if (new_point) { // The position of the new points is already known. - sorter.push_heap(0, open_list.size() - 1, 0, e, open_list.ptrw()); + sorter.push_heap(0, open_list.size() - 1, 0, e, open_list.ptr()); } else { - sorter.push_heap(0, open_list.find(e), 0, e, open_list.ptrw()); + sorter.push_heap(0, open_list.find(e), 0, e, open_list.ptr()); } } } diff --git a/core/math/a_star.h b/core/math/a_star.h index a475e4f2fc..fc4bb09f03 100644 --- a/core/math/a_star.h +++ b/core/math/a_star.h @@ -52,7 +52,7 @@ class AStar3D : public RefCounted { real_t weight_scale = 0; bool enabled = false; - OAHashMap<int64_t, Point *> neighbours = 4u; + OAHashMap<int64_t, Point *> neighbors = 4u; OAHashMap<int64_t, Point *> unlinked_neighbours = 4u; // Used for pathfinding. diff --git a/core/math/a_star_grid_2d.cpp b/core/math/a_star_grid_2d.cpp index 30d50073d7..677e609763 100644 --- a/core/math/a_star_grid_2d.cpp +++ b/core/math/a_star_grid_2d.cpp @@ -401,7 +401,7 @@ bool AStarGrid2D::_solve(Point *p_begin_point, Point *p_end_point) { List<Point *> nbors; _get_nbors(p, nbors); for (List<Point *>::Element *E = nbors.front(); E; E = E->next()) { - Point *e = E->get(); // The neighbour point. + Point *e = E->get(); // The neighbor point. real_t weight_scale = 1.0; if (jumping_enabled) { diff --git a/core/math/bvh.h b/core/math/bvh.h index 9de704834b..357d483375 100644 --- a/core/math/bvh.h +++ b/core/math/bvh.h @@ -444,9 +444,7 @@ private: params.result_array = nullptr; params.subindex_array = nullptr; - for (unsigned int n = 0; n < changed_items.size(); n++) { - const BVHHandle &h = changed_items[n]; - + for (const BVHHandle &h : changed_items) { // use the expanded aabb for pairing const BOUNDS &expanded_aabb = tree._pairs[h.id()].expanded_aabb; BVHABB_CLASS abb; @@ -465,9 +463,7 @@ private: params.result_count_overall = 0; // might not be needed tree.cull_aabb(params, false); - for (unsigned int i = 0; i < tree._cull_hits.size(); i++) { - uint32_t ref_id = tree._cull_hits[i]; - + for (const uint32_t ref_id : tree._cull_hits) { // don't collide against ourself if (ref_id == changed_item_ref_id) { continue; diff --git a/core/math/bvh_abb.h b/core/math/bvh_abb.h index 32b011bd3b..fb0207e0bd 100644 --- a/core/math/bvh_abb.h +++ b/core/math/bvh_abb.h @@ -87,7 +87,7 @@ struct BVH_ABB { return -neg_max - min; } - POINT calculate_centre() const { + POINT calculate_center() const { return POINT((calculate_size() * 0.5) + min); } diff --git a/core/math/bvh_split.inc b/core/math/bvh_split.inc index 180bbfb511..875abedb70 100644 --- a/core/math/bvh_split.inc +++ b/core/math/bvh_split.inc @@ -25,7 +25,7 @@ void _split_leaf_sort_groups_simple(int &num_a, int &num_b, uint16_t *group_a, u return; } - POINT centre = full_bound.calculate_centre(); + POINT center = full_bound.calculate_center(); POINT size = full_bound.calculate_size(); int order[POINT::AXIS_COUNT]; @@ -43,7 +43,7 @@ void _split_leaf_sort_groups_simple(int &num_a, int &num_b, uint16_t *group_a, u for (int a = 0; a < num_a; a++) { uint32_t ind = group_a[a]; - if (temp_bounds[ind].min.coord[split_axis] > centre.coord[split_axis]) { + if (temp_bounds[ind].min.coord[split_axis] > center.coord[split_axis]) { // add to b group_b[num_b++] = ind; @@ -75,7 +75,7 @@ void _split_leaf_sort_groups_simple(int &num_a, int &num_b, uint16_t *group_a, u for (int a = 0; a < num_a; a++) { uint32_t ind = group_a[a]; - if (temp_bounds[ind].min.coord[split_axis] > centre.coord[split_axis]) { + if (temp_bounds[ind].min.coord[split_axis] > center.coord[split_axis]) { count++; } } @@ -100,7 +100,7 @@ void _split_leaf_sort_groups_simple(int &num_a, int &num_b, uint16_t *group_a, u for (int a = 0; a < num_a; a++) { uint32_t ind = group_a[a]; - if (temp_bounds[ind].min.coord[split_axis] > centre.coord[split_axis]) { + if (temp_bounds[ind].min.coord[split_axis] > center.coord[split_axis]) { // add to b group_b[num_b++] = ind; diff --git a/core/math/color.cpp b/core/math/color.cpp index 5bae8d25d6..3e5fa7b402 100644 --- a/core/math/color.cpp +++ b/core/math/color.cpp @@ -194,7 +194,7 @@ void Color::set_hsv(float p_h, float p_s, float p_v, float p_alpha) { a = p_alpha; if (p_s == 0.0f) { - // Achromatic (grey) + // Achromatic (gray) r = g = b = p_v; return; } diff --git a/core/math/delaunay_3d.h b/core/math/delaunay_3d.h index 8ca38d571a..55923e0133 100644 --- a/core/math/delaunay_3d.h +++ b/core/math/delaunay_3d.h @@ -313,20 +313,20 @@ public: //remove simplex and continue simplex_list.erase(simplex->SE); - for (uint32_t k = 0; k < simplex->grid_positions.size(); k++) { - Vector3i p = simplex->grid_positions[k].pos; - acceleration_grid[p.x][p.y][p.z].erase(simplex->grid_positions[k].E); + for (const GridPos &gp : simplex->grid_positions) { + Vector3i p = gp.pos; + acceleration_grid[p.x][p.y][p.z].erase(gp.E); } memdelete(simplex); } E = N; } - for (uint32_t j = 0; j < triangles.size(); j++) { - if (triangles[j].bad) { + for (const Triangle &triangle : triangles) { + if (triangle.bad) { continue; } - Simplex *new_simplex = memnew(Simplex(triangles[j].triangle[0], triangles[j].triangle[1], triangles[j].triangle[2], i)); + Simplex *new_simplex = memnew(Simplex(triangle.triangle[0], triangle.triangle[1], triangle.triangle[2], i)); circum_sphere_compute(points, new_simplex); new_simplex->SE = simplex_list.push_back(new_simplex); { diff --git a/core/math/expression.cpp b/core/math/expression.cpp index da52bb9465..d1ec987d56 100644 --- a/core/math/expression.cpp +++ b/core/math/expression.cpp @@ -434,14 +434,13 @@ Error Expression::_get_token(Token &r_token) { } return OK; - } else if (is_ascii_char(cchar) || is_underscore(cchar)) { - String id; - bool first = true; + } else if (is_unicode_identifier_start(cchar)) { + String id = String::chr(cchar); + cchar = GET_CHAR(); - while (is_ascii_char(cchar) || is_underscore(cchar) || (!first && is_digit(cchar))) { + while (is_unicode_identifier_continue(cchar)) { id += String::chr(cchar); cchar = GET_CHAR(); - first = false; } str_ofs--; //go back one diff --git a/core/math/geometry_3d.cpp b/core/math/geometry_3d.cpp index 51523ea296..4786110054 100644 --- a/core/math/geometry_3d.cpp +++ b/core/math/geometry_3d.cpp @@ -141,21 +141,19 @@ real_t Geometry3D::get_closest_distance_between_segments(const Vector3 &p_p0, co void Geometry3D::MeshData::optimize_vertices() { HashMap<int, int> vtx_remap; - 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)) { + for (MeshData::Face &face : faces) { + for (int &index : face.indices) { + if (!vtx_remap.has(index)) { int ni = vtx_remap.size(); - vtx_remap[idx] = ni; + vtx_remap[index] = ni; } - - faces[i].indices[j] = vtx_remap[idx]; + index = vtx_remap[index]; } } - for (uint32_t i = 0; i < edges.size(); i++) { - int a = edges[i].vertex_a; - int b = edges[i].vertex_b; + for (MeshData::Edge edge : edges) { + int a = edge.vertex_a; + int b = edge.vertex_b; if (!vtx_remap.has(a)) { int ni = vtx_remap.size(); @@ -166,8 +164,8 @@ void Geometry3D::MeshData::optimize_vertices() { vtx_remap[b] = ni; } - edges[i].vertex_a = vtx_remap[a]; - edges[i].vertex_b = vtx_remap[b]; + edge.vertex_a = vtx_remap[a]; + edge.vertex_b = vtx_remap[b]; } LocalVector<Vector3> new_vertices; @@ -673,10 +671,10 @@ Geometry3D::MeshData Geometry3D::build_convex_mesh(const Vector<Plane> &p_planes MeshData::Face face; // Add face indices. - for (uint32_t j = 0; j < vertices.size(); j++) { + for (const Vector3 &vertex : vertices) { int idx = -1; for (uint32_t k = 0; k < mesh.vertices.size(); k++) { - if (mesh.vertices[k].distance_to(vertices[j]) < 0.001f) { + if (mesh.vertices[k].distance_to(vertex) < 0.001f) { idx = k; break; } @@ -684,7 +682,7 @@ Geometry3D::MeshData Geometry3D::build_convex_mesh(const Vector<Plane> &p_planes if (idx == -1) { idx = mesh.vertices.size(); - mesh.vertices.push_back(vertices[j]); + mesh.vertices.push_back(vertex); } face.indices.push_back(idx); diff --git a/core/object/script_language.cpp b/core/object/script_language.cpp index 66ef418e42..df5486512d 100644 --- a/core/object/script_language.cpp +++ b/core/object/script_language.cpp @@ -245,9 +245,12 @@ void ScriptServer::thread_exit() { } HashMap<StringName, ScriptServer::GlobalScriptClass> ScriptServer::global_classes; +HashMap<StringName, Vector<StringName>> ScriptServer::inheriters_cache; +bool ScriptServer::inheriters_cache_dirty = true; void ScriptServer::global_classes_clear() { global_classes.clear(); + inheriters_cache.clear(); } void ScriptServer::add_global_class(const StringName &p_class, const StringName &p_base, const StringName &p_language, const String &p_path) { @@ -257,16 +260,44 @@ void ScriptServer::add_global_class(const StringName &p_class, const StringName g.path = p_path; g.base = p_base; global_classes[p_class] = g; + inheriters_cache_dirty = true; } void ScriptServer::remove_global_class(const StringName &p_class) { global_classes.erase(p_class); + inheriters_cache_dirty = true; +} + +void ScriptServer::get_inheriters_list(const StringName &p_base_type, List<StringName> *r_classes) { + if (inheriters_cache_dirty) { + inheriters_cache.clear(); + for (const KeyValue<StringName, GlobalScriptClass> &K : global_classes) { + if (!inheriters_cache.has(K.value.base)) { + inheriters_cache[K.value.base] = Vector<StringName>(); + } + inheriters_cache[K.value.base].push_back(K.key); + } + for (KeyValue<StringName, Vector<StringName>> &K : inheriters_cache) { + K.value.sort_custom<StringName::AlphCompare>(); + } + inheriters_cache_dirty = false; + } + + if (!inheriters_cache.has(p_base_type)) { + return; + } + + const Vector<StringName> &v = inheriters_cache[p_base_type]; + for (int i = 0; i < v.size(); i++) { + r_classes->push_back(v[i]); + } } 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); + inheriters_cache_dirty = true; return; } } diff --git a/core/object/script_language.h b/core/object/script_language.h index 02d1880dc2..f82b58439f 100644 --- a/core/object/script_language.h +++ b/core/object/script_language.h @@ -56,10 +56,12 @@ class ScriptServer { struct GlobalScriptClass { StringName language; String path; - String base; + StringName base; }; static HashMap<StringName, GlobalScriptClass> global_classes; + static HashMap<StringName, Vector<StringName>> inheriters_cache; + static bool inheriters_cache_dirty; public: static ScriptEditRequestFunction edit_request_func; @@ -87,6 +89,7 @@ public: static StringName get_global_class_base(const String &p_class); static StringName get_global_class_native_base(const String &p_class); static void get_global_class_list(List<StringName> *r_global_classes); + static void get_inheriters_list(const StringName &p_base_type, List<StringName> *r_classes); static void save_global_classes(); static void init_languages(); @@ -120,7 +123,7 @@ public: virtual bool can_instantiate() const = 0; virtual Ref<Script> get_base_script() const = 0; //for script inheritance - + virtual StringName get_global_name() const = 0; virtual bool inherits_script(const Ref<Script> &p_script) const = 0; virtual StringName get_instance_base_type() const = 0; // this may not work in all scripts, will return empty if so diff --git a/core/object/script_language_extension.h b/core/object/script_language_extension.h index 912f2218c4..8e162a1b0f 100644 --- a/core/object/script_language_extension.h +++ b/core/object/script_language_extension.h @@ -53,6 +53,7 @@ protected: public: EXBIND0RC(bool, can_instantiate) EXBIND0RC(Ref<Script>, get_base_script) + EXBIND0RC(StringName, get_global_name) EXBIND1RC(bool, inherits_script, const Ref<Script> &) EXBIND0RC(StringName, get_instance_base_type) diff --git a/core/object/undo_redo.cpp b/core/object/undo_redo.cpp index e84933eb69..077929351e 100644 --- a/core/object/undo_redo.cpp +++ b/core/object/undo_redo.cpp @@ -99,8 +99,7 @@ void UndoRedo::create_action(const String &p_name, MergeMode p_mode) { } } - for (unsigned int i = 0; i < to_remove.size(); i++) { - List<Operation>::Element *E = to_remove[i]; + for (List<Operation>::Element *E : to_remove) { // Delete all object references E->get().delete_reference(); E->erase(); diff --git a/core/object/worker_thread_pool.cpp b/core/object/worker_thread_pool.cpp index fc907b2301..721c8d0a10 100644 --- a/core/object/worker_thread_pool.cpp +++ b/core/object/worker_thread_pool.cpp @@ -377,11 +377,11 @@ void WorkerThreadPool::wait_for_group_task_completion(GroupID p_group) { Group *group = *groupp; if (group->low_priority_native_tasks.size() > 0) { - for (uint32_t i = 0; i < group->low_priority_native_tasks.size(); i++) { - group->low_priority_native_tasks[i]->low_priority_thread->wait_to_finish(); - native_thread_allocator.free(group->low_priority_native_tasks[i]->low_priority_thread); + for (Task *task : group->low_priority_native_tasks) { + task->low_priority_thread->wait_to_finish(); + native_thread_allocator.free(task->low_priority_thread); task_mutex.lock(); - task_allocator.free(group->low_priority_native_tasks[i]); + task_allocator.free(task); task_mutex.unlock(); } @@ -449,8 +449,8 @@ void WorkerThreadPool::finish() { task_available_semaphore.post(); } - for (uint32_t i = 0; i < threads.size(); i++) { - threads[i].thread.wait_to_finish(); + for (ThreadData &data : threads) { + data.thread.wait_to_finish(); } threads.clear(); diff --git a/core/os/keyboard.cpp b/core/os/keyboard.cpp index 5183b77cb1..25a4b320cd 100644 --- a/core/os/keyboard.cpp +++ b/core/os/keyboard.cpp @@ -127,14 +127,9 @@ static const _KeyCodeText _keycodes[] = { {Key::KP_7 ,"Kp 7"}, {Key::KP_8 ,"Kp 8"}, {Key::KP_9 ,"Kp 9"}, - {Key::SUPER_L ,"Super L"}, - {Key::SUPER_R ,"Super R"}, {Key::MENU ,"Menu"}, - {Key::HYPER_L ,"Hyper L"}, - {Key::HYPER_R ,"Hyper R"}, + {Key::HYPER ,"Hyper"}, {Key::HELP ,"Help"}, - {Key::DIRECTION_L ,"Direction L"}, - {Key::DIRECTION_R ,"Direction R"}, {Key::BACK ,"Back"}, {Key::FORWARD ,"Forward"}, {Key::STOP ,"Stop"}, @@ -142,11 +137,6 @@ static const _KeyCodeText _keycodes[] = { {Key::VOLUMEDOWN ,"VolumeDown"}, {Key::VOLUMEMUTE ,"VolumeMute"}, {Key::VOLUMEUP ,"VolumeUp"}, - {Key::BASSBOOST ,"BassBoost"}, - {Key::BASSUP ,"BassUp"}, - {Key::BASSDOWN ,"BassDown"}, - {Key::TREBLEUP ,"TrebleUp"}, - {Key::TREBLEDOWN ,"TrebleDown"}, {Key::MEDIAPLAY ,"MediaPlay"}, {Key::MEDIASTOP ,"MediaStop"}, {Key::MEDIAPREVIOUS ,"MediaPrevious"}, @@ -174,6 +164,10 @@ static const _KeyCodeText _keycodes[] = { {Key::LAUNCHD ,"LaunchD"}, {Key::LAUNCHE ,"LaunchE"}, {Key::LAUNCHF ,"LaunchF"}, + {Key::GLOBE ,"Globe"}, + {Key::KEYBOARD ,"On-screen keyboard"}, + {Key::JIS_EISU ,"JIS Eisu"}, + {Key::JIS_KANA ,"JIS Kana"}, {Key::UNKNOWN ,"Unknown"}, {Key::SPACE ,"Space"}, {Key::EXCLAM ,"Exclam"}, @@ -244,72 +238,6 @@ static const _KeyCodeText _keycodes[] = { {Key::BAR ,"Bar"}, {Key::BRACERIGHT ,"BraceRight"}, {Key::ASCIITILDE ,"AsciiTilde"}, - {Key::NOBREAKSPACE ,"NoBreakSpace"}, - {Key::EXCLAMDOWN ,"ExclamDown"}, - {Key::CENT ,"Cent"}, - {Key::STERLING ,"Sterling"}, - {Key::CURRENCY ,"Currency"}, - {Key::YEN ,"Yen"}, - {Key::BROKENBAR ,"BrokenBar"}, - {Key::SECTION ,"Section"}, - {Key::DIAERESIS ,"Diaeresis"}, - {Key::COPYRIGHT ,"Copyright"}, - {Key::ORDFEMININE ,"Ordfeminine"}, - {Key::GUILLEMOTLEFT ,"GuillemotLeft"}, - {Key::NOTSIGN ,"NotSign"}, - {Key::HYPHEN ,"Hyphen"}, - {Key::KEY_REGISTERED ,"Registered"}, - {Key::MACRON ,"Macron"}, - {Key::DEGREE ,"Degree"}, - {Key::PLUSMINUS ,"PlusMinus"}, - {Key::TWOSUPERIOR ,"TwoSuperior"}, - {Key::THREESUPERIOR ,"ThreeSuperior"}, - {Key::ACUTE ,"Acute"}, - {Key::MU ,"Mu"}, - {Key::PARAGRAPH ,"Paragraph"}, - {Key::PERIODCENTERED ,"PeriodCentered"}, - {Key::CEDILLA ,"Cedilla"}, - {Key::ONESUPERIOR ,"OneSuperior"}, - {Key::MASCULINE ,"Masculine"}, - {Key::GUILLEMOTRIGHT ,"GuillemotRight"}, - {Key::ONEQUARTER ,"OneQuarter"}, - {Key::ONEHALF ,"OneHalf"}, - {Key::THREEQUARTERS ,"ThreeQuarters"}, - {Key::QUESTIONDOWN ,"QuestionDown"}, - {Key::AGRAVE ,"Agrave"}, - {Key::AACUTE ,"Aacute"}, - {Key::ACIRCUMFLEX ,"AcircumFlex"}, - {Key::ATILDE ,"Atilde"}, - {Key::ADIAERESIS ,"Adiaeresis"}, - {Key::ARING ,"Aring"}, - {Key::AE ,"Ae"}, - {Key::CCEDILLA ,"Ccedilla"}, - {Key::EGRAVE ,"Egrave"}, - {Key::EACUTE ,"Eacute"}, - {Key::ECIRCUMFLEX ,"Ecircumflex"}, - {Key::EDIAERESIS ,"Ediaeresis"}, - {Key::IGRAVE ,"Igrave"}, - {Key::IACUTE ,"Iacute"}, - {Key::ICIRCUMFLEX ,"Icircumflex"}, - {Key::IDIAERESIS ,"Idiaeresis"}, - {Key::ETH ,"Eth"}, - {Key::NTILDE ,"Ntilde"}, - {Key::OGRAVE ,"Ograve"}, - {Key::OACUTE ,"Oacute"}, - {Key::OCIRCUMFLEX ,"Ocircumflex"}, - {Key::OTILDE ,"Otilde"}, - {Key::ODIAERESIS ,"Odiaeresis"}, - {Key::MULTIPLY ,"Multiply"}, - {Key::OOBLIQUE ,"Ooblique"}, - {Key::UGRAVE ,"Ugrave"}, - {Key::UACUTE ,"Uacute"}, - {Key::UCIRCUMFLEX ,"Ucircumflex"}, - {Key::UDIAERESIS ,"Udiaeresis"}, - {Key::YACUTE ,"Yacute"}, - {Key::THORN ,"Thorn"}, - {Key::SSHARP ,"Ssharp"}, - {Key::DIVISION ,"Division"}, - {Key::YDIAERESIS ,"Ydiaeresis"}, {Key::NONE ,nullptr} /* clang-format on */ }; @@ -378,14 +306,9 @@ bool keycode_has_unicode(Key p_keycode) { case Key::F33: case Key::F34: case Key::F35: - case Key::SUPER_L: - case Key::SUPER_R: case Key::MENU: - case Key::HYPER_L: - case Key::HYPER_R: + case Key::HYPER: case Key::HELP: - case Key::DIRECTION_L: - case Key::DIRECTION_R: case Key::BACK: case Key::FORWARD: case Key::STOP: @@ -393,11 +316,6 @@ bool keycode_has_unicode(Key p_keycode) { case Key::VOLUMEDOWN: case Key::VOLUMEMUTE: case Key::VOLUMEUP: - case Key::BASSBOOST: - case Key::BASSUP: - case Key::BASSDOWN: - case Key::TREBLEUP: - case Key::TREBLEDOWN: case Key::MEDIAPLAY: case Key::MEDIASTOP: case Key::MEDIAPREVIOUS: @@ -426,6 +344,10 @@ bool keycode_has_unicode(Key p_keycode) { case Key::LAUNCHD: case Key::LAUNCHE: case Key::LAUNCHF: + case Key::GLOBE: + case Key::KEYBOARD: + case Key::JIS_EISU: + case Key::JIS_KANA: return false; default: { } @@ -522,3 +444,24 @@ int keycode_get_value_by_index(int p_index) { const char *keycode_get_name_by_index(int p_index) { return _keycodes[p_index].text; } + +char32_t fix_unicode(char32_t p_char) { + if (p_char >= 0x20 && p_char != 0x7F) { + return p_char; + } + return 0; +} + +Key fix_keycode(char32_t p_char, Key p_key) { + if (p_char >= 0x20 && p_char <= 0x7E) { + return (Key)String::char_uppercase(p_char); + } + return p_key; +} + +Key fix_key_label(char32_t p_char, Key p_key) { + if (p_char >= 0x20 && p_char != 0x7F) { + return (Key)String::char_uppercase(p_char); + } + return p_key; +} diff --git a/core/os/keyboard.h b/core/os/keyboard.h index c78fa2a631..6315356510 100644 --- a/core/os/keyboard.h +++ b/core/os/keyboard.h @@ -127,11 +127,8 @@ enum class Key { SUPER_L = SPECIAL | 0x40, SUPER_R = SPECIAL | 0x41, MENU = SPECIAL | 0x42, - HYPER_L = SPECIAL | 0x43, - HYPER_R = SPECIAL | 0x44, + HYPER = SPECIAL | 0x43, HELP = SPECIAL | 0x45, - DIRECTION_L = SPECIAL | 0x46, - DIRECTION_R = SPECIAL | 0x47, BACK = SPECIAL | 0x48, FORWARD = SPECIAL | 0x49, STOP = SPECIAL | 0x4A, @@ -139,11 +136,6 @@ enum class Key { VOLUMEDOWN = SPECIAL | 0x4C, VOLUMEMUTE = SPECIAL | 0x4D, VOLUMEUP = SPECIAL | 0x4E, - BASSBOOST = SPECIAL | 0x4F, - BASSUP = SPECIAL | 0x50, - BASSDOWN = SPECIAL | 0x51, - TREBLEUP = SPECIAL | 0x52, - TREBLEDOWN = SPECIAL | 0x53, MEDIAPLAY = SPECIAL | 0x54, MEDIASTOP = SPECIAL | 0x55, MEDIAPREVIOUS = SPECIAL | 0x56, @@ -173,7 +165,12 @@ enum class Key { LAUNCHE = SPECIAL | 0x6E, LAUNCHF = SPECIAL | 0x6F, - UNKNOWN = SPECIAL | 0xFFFFFF, + GLOBE = SPECIAL | 0x70, + KEYBOARD = SPECIAL | 0x71, + JIS_EISU = SPECIAL | 0x72, + JIS_KANA = SPECIAL | 0x73, + + UNKNOWN = SPECIAL | 0x7FFFFF, /* PRINTABLE LATIN 1 CODES */ @@ -246,74 +243,8 @@ enum class Key { BAR = 0x007C, BRACERIGHT = 0x007D, ASCIITILDE = 0x007E, - NOBREAKSPACE = 0x00A0, - EXCLAMDOWN = 0x00A1, - CENT = 0x00A2, - STERLING = 0x00A3, - CURRENCY = 0x00A4, YEN = 0x00A5, - BROKENBAR = 0x00A6, SECTION = 0x00A7, - DIAERESIS = 0x00A8, - COPYRIGHT = 0x00A9, - ORDFEMININE = 0x00AA, - GUILLEMOTLEFT = 0x00AB, - NOTSIGN = 0x00AC, - HYPHEN = 0x00AD, - KEY_REGISTERED = 0x00AE, // "REGISTERED" is a reserved word on Windows. - MACRON = 0x00AF, - DEGREE = 0x00B0, - PLUSMINUS = 0x00B1, - TWOSUPERIOR = 0x00B2, - THREESUPERIOR = 0x00B3, - ACUTE = 0x00B4, - MU = 0x00B5, - PARAGRAPH = 0x00B6, - PERIODCENTERED = 0x00B7, - CEDILLA = 0x00B8, - ONESUPERIOR = 0x00B9, - MASCULINE = 0x00BA, - GUILLEMOTRIGHT = 0x00BB, - ONEQUARTER = 0x00BC, - ONEHALF = 0x00BD, - THREEQUARTERS = 0x00BE, - QUESTIONDOWN = 0x00BF, - AGRAVE = 0x00C0, - AACUTE = 0x00C1, - ACIRCUMFLEX = 0x00C2, - ATILDE = 0x00C3, - ADIAERESIS = 0x00C4, - ARING = 0x00C5, - AE = 0x00C6, - CCEDILLA = 0x00C7, - EGRAVE = 0x00C8, - EACUTE = 0x00C9, - ECIRCUMFLEX = 0x00CA, - EDIAERESIS = 0x00CB, - IGRAVE = 0x00CC, - IACUTE = 0x00CD, - ICIRCUMFLEX = 0x00CE, - IDIAERESIS = 0x00CF, - ETH = 0x00D0, - NTILDE = 0x00D1, - OGRAVE = 0x00D2, - OACUTE = 0x00D3, - OCIRCUMFLEX = 0x00D4, - OTILDE = 0x00D5, - ODIAERESIS = 0x00D6, - MULTIPLY = 0x00D7, - OOBLIQUE = 0x00D8, - UGRAVE = 0x00D9, - UACUTE = 0x00DA, - UCIRCUMFLEX = 0x00DB, - UDIAERESIS = 0x00DC, - YACUTE = 0x00DD, - THORN = 0x00DE, - SSHARP = 0x00DF, - - DIVISION = 0x00F7, - YDIAERESIS = 0x00FF, - END_LATIN1 = 0x0100, }; enum class KeyModifierMask { @@ -407,4 +338,8 @@ int keycode_get_count(); int keycode_get_value_by_index(int p_index); const char *keycode_get_name_by_index(int p_index); +char32_t fix_unicode(char32_t p_char); +Key fix_keycode(char32_t p_char, Key p_key); +Key fix_key_label(char32_t p_char, Key p_key); + #endif // KEYBOARD_H diff --git a/core/os/os.cpp b/core/os/os.cpp index c6fa8d307b..86469852e3 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -203,16 +203,26 @@ uint64_t OS::get_embedded_pck_offset() const { } // Helper function to ensure that a dir name/path will be valid on the OS -String OS::get_safe_dir_name(const String &p_dir_name, bool p_allow_dir_separator) const { +String OS::get_safe_dir_name(const String &p_dir_name, bool p_allow_paths) const { + String safe_dir_name = p_dir_name; Vector<String> invalid_chars = String(": * ? \" < > |").split(" "); - if (p_allow_dir_separator) { + if (p_allow_paths) { // Dir separators are allowed, but disallow ".." to avoid going up the filesystem invalid_chars.push_back(".."); + safe_dir_name = safe_dir_name.replace("\\", "/").strip_edges(); } else { invalid_chars.push_back("/"); + invalid_chars.push_back("\\"); + safe_dir_name = safe_dir_name.strip_edges(); + + // These directory names are invalid. + if (safe_dir_name == ".") { + safe_dir_name = "dot"; + } else if (safe_dir_name == "..") { + safe_dir_name = "twodots"; + } } - String safe_dir_name = p_dir_name.replace("\\", "/").strip_edges(); for (int i = 0; i < invalid_chars.size(); i++) { safe_dir_name = safe_dir_name.replace(invalid_chars[i], "-"); } diff --git a/core/os/os.h b/core/os/os.h index 4818e9281a..436a83eae3 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -238,7 +238,7 @@ public: virtual uint64_t get_embedded_pck_offset() const; - String get_safe_dir_name(const String &p_dir_name, bool p_allow_dir_separator = false) const; + String get_safe_dir_name(const String &p_dir_name, bool p_allow_paths = false) const; virtual String get_godot_dir_name() const; virtual String get_data_path() const; diff --git a/core/templates/local_vector.h b/core/templates/local_vector.h index 55761bb604..5311a94987 100644 --- a/core/templates/local_vector.h +++ b/core/templates/local_vector.h @@ -169,6 +169,70 @@ public: return data[p_index]; } + struct Iterator { + _FORCE_INLINE_ T &operator*() const { + return *elem_ptr; + } + _FORCE_INLINE_ T *operator->() const { return elem_ptr; } + _FORCE_INLINE_ Iterator &operator++() { + elem_ptr++; + return *this; + } + _FORCE_INLINE_ Iterator &operator--() { + elem_ptr--; + return *this; + } + + _FORCE_INLINE_ bool operator==(const Iterator &b) const { return elem_ptr == b.elem_ptr; } + _FORCE_INLINE_ bool operator!=(const Iterator &b) const { return elem_ptr != b.elem_ptr; } + + Iterator(T *p_ptr) { elem_ptr = p_ptr; } + Iterator() {} + Iterator(const Iterator &p_it) { elem_ptr = p_it.elem_ptr; } + + private: + T *elem_ptr = nullptr; + }; + + struct ConstIterator { + _FORCE_INLINE_ const T &operator*() const { + return *elem_ptr; + } + _FORCE_INLINE_ const T *operator->() const { return elem_ptr; } + _FORCE_INLINE_ ConstIterator &operator++() { + elem_ptr++; + return *this; + } + _FORCE_INLINE_ ConstIterator &operator--() { + elem_ptr--; + return *this; + } + + _FORCE_INLINE_ bool operator==(const ConstIterator &b) const { return elem_ptr == b.elem_ptr; } + _FORCE_INLINE_ bool operator!=(const ConstIterator &b) const { return elem_ptr != b.elem_ptr; } + + ConstIterator(const T *p_ptr) { elem_ptr = p_ptr; } + ConstIterator() {} + ConstIterator(const ConstIterator &p_it) { elem_ptr = p_it.elem_ptr; } + + private: + const T *elem_ptr = nullptr; + }; + + _FORCE_INLINE_ Iterator begin() { + return Iterator(data); + } + _FORCE_INLINE_ Iterator end() { + return Iterator(data + size()); + } + + _FORCE_INLINE_ ConstIterator begin() const { + return ConstIterator(ptr()); + } + _FORCE_INLINE_ ConstIterator end() const { + return ConstIterator(ptr() + size()); + } + void insert(U p_pos, T p_val) { ERR_FAIL_UNSIGNED_INDEX(p_pos, count + 1); if (p_pos == count) { diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp index 2cc0b3a8d7..9e8c6fccb3 100644 --- a/core/variant/variant_call.cpp +++ b/core/variant/variant_call.cpp @@ -2135,7 +2135,7 @@ static void _register_variant_builtin_methods() { bind_static_method(Projection, create_depth_correction, sarray("flip_y"), varray()); bind_static_method(Projection, create_light_atlas_rect, sarray("rect"), varray()); bind_static_method(Projection, create_perspective, sarray("fovy", "aspect", "z_near", "z_far", "flip_fov"), varray(false)); - bind_static_method(Projection, create_perspective_hmd, sarray("fovy", "aspect", "z_near", "z_far", "flip_fov", "eye", "intraocular_dist", " convergence_dist"), varray()); + bind_static_method(Projection, create_perspective_hmd, sarray("fovy", "aspect", "z_near", "z_far", "flip_fov", "eye", "intraocular_dist", "convergence_dist"), varray()); bind_static_method(Projection, create_for_hmd, sarray("eye", "aspect", "intraocular_dist", "display_width", "display_to_lens", "oversample", "z_near", "z_far"), varray()); bind_static_method(Projection, create_orthogonal, sarray("left", "right", "bottom", "top", "z_near", "z_far"), varray()); bind_static_method(Projection, create_orthogonal_aspect, sarray("size", "aspect", "z_near", "z_far", "flip_fov"), varray(false)); diff --git a/core/variant/variant_setget.cpp b/core/variant/variant_setget.cpp index ba37e15f31..30fb5d0e9f 100644 --- a/core/variant/variant_setget.cpp +++ b/core/variant/variant_setget.cpp @@ -151,8 +151,8 @@ void unregister_named_setters_getters() { bool Variant::has_member(Variant::Type p_type, const StringName &p_member) { ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, false); - for (uint32_t i = 0; i < variant_setters_getters_names[p_type].size(); i++) { - if (variant_setters_getters_names[p_type][i] == p_member) { + for (const StringName &member : variant_setters_getters_names[p_type]) { + if (member == p_member) { return true; } } @@ -172,8 +172,8 @@ Variant::Type Variant::get_member_type(Variant::Type p_type, const StringName &p } void Variant::get_member_list(Variant::Type p_type, List<StringName> *r_members) { - for (uint32_t i = 0; i < variant_setters_getters_names[p_type].size(); i++) { - r_members->push_back(variant_setters_getters_names[p_type][i]); + for (const StringName &member : variant_setters_getters_names[p_type]) { + r_members->push_back(member); } } |