summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/config/project_settings.cpp69
-rw-r--r--core/io/json.cpp33
-rw-r--r--core/io/json.h9
-rw-r--r--core/io/resource_format_binary.cpp93
-rw-r--r--core/io/resource_format_binary.h4
-rw-r--r--core/io/resource_loader.cpp20
-rw-r--r--core/io/resource_loader.h3
-rw-r--r--core/math/a_star.cpp14
-rw-r--r--core/math/bvh.h8
-rw-r--r--core/math/delaunay_3d.h12
-rw-r--r--core/math/geometry_3d.cpp28
-rw-r--r--core/object/script_language.cpp31
-rw-r--r--core/object/script_language.h7
-rw-r--r--core/object/script_language_extension.h1
-rw-r--r--core/object/undo_redo.cpp3
-rw-r--r--core/object/worker_thread_pool.cpp12
-rw-r--r--core/os/os.cpp16
-rw-r--r--core/os/os.h2
-rw-r--r--core/templates/local_vector.h64
-rw-r--r--core/variant/variant_setget.cpp8
-rw-r--r--doc/classes/AnimationNodeStateMachinePlayback.xml6
-rw-r--r--doc/classes/EditorPlugin.xml1
-rw-r--r--doc/classes/EditorSettings.xml14
-rw-r--r--doc/classes/JSON.xml14
-rw-r--r--doc/classes/ProjectSettings.xml13
-rw-r--r--doc/classes/ResourceFormatLoader.xml7
-rw-r--r--doc/classes/Shader.xml10
-rw-r--r--doc/classes/TileMap.xml14
-rw-r--r--doc/classes/Window.xml10
-rw-r--r--drivers/gles3/rasterizer_canvas_gles3.cpp2
-rw-r--r--drivers/vulkan/vulkan_context.cpp8
-rw-r--r--drivers/windows/file_access_windows.cpp45
-rw-r--r--drivers/windows/file_access_windows.h6
-rw-r--r--editor/editor_file_system.cpp26
-rw-r--r--editor/editor_file_system.h4
-rw-r--r--editor/editor_inspector.cpp15
-rw-r--r--editor/editor_inspector.h1
-rw-r--r--editor/editor_node.cpp112
-rw-r--r--editor/editor_node.h14
-rw-r--r--editor/editor_properties.cpp63
-rw-r--r--editor/editor_properties.h3
-rw-r--r--editor/editor_quick_open.cpp14
-rw-r--r--editor/editor_quick_open.h1
-rw-r--r--editor/editor_resource_picker.cpp115
-rw-r--r--editor/editor_resource_picker.h8
-rw-r--r--editor/editor_settings.cpp6
-rw-r--r--editor/editor_toaster.cpp8
-rw-r--r--editor/export/editor_export_platform.cpp38
-rw-r--r--editor/export/editor_export_plugin.cpp2
-rw-r--r--editor/filesystem_dock.cpp44
-rw-r--r--editor/filesystem_dock.h1
-rw-r--r--editor/inspector_dock.cpp3
-rw-r--r--editor/multi_node_edit.cpp10
-rw-r--r--editor/plugins/animation_state_machine_editor.cpp4
-rw-r--r--editor/plugins/bone_map_editor_plugin.cpp12
-rw-r--r--editor/plugins/node_3d_editor_plugin.cpp14
-rw-r--r--editor/plugins/node_3d_editor_plugin.h1
-rw-r--r--editor/plugins/shader_editor_plugin.cpp44
-rw-r--r--editor/plugins/tiles/tile_data_editors.cpp19
-rw-r--r--editor/plugins/tiles/tile_map_editor.cpp26
-rw-r--r--editor/project_converter_3_to_4.cpp48
-rw-r--r--editor/register_editor_types.cpp2
-rw-r--r--editor/scene_tree_dock.cpp5
-rw-r--r--main/main.cpp22
-rw-r--r--modules/gdscript/gdscript.cpp4
-rw-r--r--modules/gdscript/gdscript.h1
-rw-r--r--modules/gdscript/language_server/gdscript_text_document.cpp1
-rw-r--r--modules/mono/csharp_script.cpp4
-rw-r--r--modules/mono/csharp_script.h2
-rw-r--r--modules/navigation/godot_navigation_server.cpp27
-rw-r--r--modules/navigation/nav_map.cpp57
-rw-r--r--modules/navigation/navigation_mesh_generator.cpp8
-rw-r--r--modules/raycast/raycast_occlusion_cull.cpp4
-rw-r--r--platform/linuxbsd/crash_handler_linuxbsd.cpp6
-rw-r--r--platform/windows/display_server_windows.cpp1
-rw-r--r--platform/windows/os_windows.cpp4
-rw-r--r--scene/2d/area_2d.cpp5
-rw-r--r--scene/2d/collision_object_2d.cpp20
-rw-r--r--scene/2d/collision_object_2d.h7
-rw-r--r--scene/2d/physics_body_2d.cpp4
-rw-r--r--scene/2d/tile_map.cpp67
-rw-r--r--scene/3d/area_3d.cpp4
-rw-r--r--scene/3d/collision_object_3d.cpp20
-rw-r--r--scene/3d/collision_object_3d.h7
-rw-r--r--scene/3d/lightmap_gi.cpp19
-rw-r--r--scene/3d/physics_body_3d.cpp4
-rw-r--r--scene/animation/animation_blend_tree.cpp2
-rw-r--r--scene/animation/animation_node_state_machine.cpp11
-rw-r--r--scene/animation/animation_node_state_machine.h2
-rw-r--r--scene/animation/animation_player.cpp64
-rw-r--r--scene/animation/animation_tree.cpp2
-rw-r--r--scene/gui/base_button.cpp1
-rw-r--r--scene/gui/color_picker.cpp84
-rw-r--r--scene/gui/color_picker.h8
-rw-r--r--scene/gui/popup.cpp6
-rw-r--r--scene/main/canvas_item.cpp10
-rw-r--r--scene/main/canvas_item.h1
-rw-r--r--scene/main/node.cpp10
-rw-r--r--scene/main/window.cpp20
-rw-r--r--scene/main/window.h6
-rw-r--r--scene/resources/animation.cpp44
-rw-r--r--scene/resources/immediate_mesh.cpp20
-rw-r--r--scene/resources/importer_mesh.cpp19
-rw-r--r--scene/resources/material.cpp57
-rw-r--r--scene/resources/material.h3
-rw-r--r--scene/resources/mesh_library.cpp3
-rw-r--r--scene/resources/packed_scene.cpp3
-rw-r--r--scene/resources/resource_format_text.cpp79
-rw-r--r--scene/resources/resource_format_text.h3
-rw-r--r--scene/resources/shader.cpp19
-rw-r--r--scene/resources/shader.h49
-rw-r--r--scene/resources/surface_tool.cpp34
-rw-r--r--scene/resources/text_paragraph.cpp38
-rw-r--r--scene/resources/tile_set.cpp16
-rw-r--r--servers/physics_3d/godot_collision_solver_3d_sat.cpp44
-rw-r--r--servers/physics_3d/godot_shape_3d.cpp33
-rw-r--r--servers/physics_3d/godot_soft_body_3d.cpp93
-rw-r--r--servers/rendering/renderer_rd/environment/gi.cpp14
-rw-r--r--servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp19
-rw-r--r--servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp11
-rw-r--r--servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp2
-rw-r--r--servers/rendering/renderer_rd/shader_rd.cpp3
-rw-r--r--servers/rendering/renderer_rd/storage_rd/mesh_storage.cpp18
-rw-r--r--servers/rendering/renderer_rd/storage_rd/particles_storage.cpp6
-rw-r--r--servers/rendering/renderer_scene_cull.cpp16
-rw-r--r--servers/rendering/shader_language.cpp2
-rw-r--r--servers/rendering/shader_preprocessor.cpp4
-rw-r--r--servers/rendering_server.cpp4
128 files changed, 1456 insertions, 975 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/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_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..9bfe46727b 100644
--- a/core/math/a_star.cpp
+++ b/core/math/a_star.cpp
@@ -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
+ AStar3D::Point *e = *(it.value); // The neighbour 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/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/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/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/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_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);
}
}
diff --git a/doc/classes/AnimationNodeStateMachinePlayback.xml b/doc/classes/AnimationNodeStateMachinePlayback.xml
index 7e01be12c4..17a946bb3e 100644
--- a/doc/classes/AnimationNodeStateMachinePlayback.xml
+++ b/doc/classes/AnimationNodeStateMachinePlayback.xml
@@ -38,6 +38,12 @@
Returns the playback position within the current animation state.
</description>
</method>
+ <method name="get_fading_from_node" qualifiers="const">
+ <return type="StringName" />
+ <description>
+ Returns the starting state of currently fading animation.
+ </description>
+ </method>
<method name="get_travel_path" qualifiers="const">
<return type="PackedStringArray" />
<description>
diff --git a/doc/classes/EditorPlugin.xml b/doc/classes/EditorPlugin.xml
index 370be8e9f3..326c4f6456 100644
--- a/doc/classes/EditorPlugin.xml
+++ b/doc/classes/EditorPlugin.xml
@@ -41,6 +41,7 @@
<param index="0" name="object" type="Variant" />
<description>
This function is used for plugins that edit specific object types (nodes or resources). It requests the editor to edit the given object.
+ [param object] can be [code]null[/code] if the plugin was editing an object, but there is no longer any selected object handled by this plugin. It can be used to cleanup editing state.
</description>
</method>
<method name="_enable_plugin" qualifiers="virtual">
diff --git a/doc/classes/EditorSettings.xml b/doc/classes/EditorSettings.xml
index fca87f6a56..9015a12b43 100644
--- a/doc/classes/EditorSettings.xml
+++ b/doc/classes/EditorSettings.xml
@@ -433,12 +433,24 @@
The size to use for port previews in the visual shader uniforms (toggled by clicking the "eye" icon next to an output). The value is defined in pixels at 100% zoom, and will scale with zoom automatically.
</member>
<member name="filesystem/directories/autoscan_project_path" type="String" setter="" getter="">
- The folder where projects should be scanned for (recursively), in a way similar to the project manager's [b]Scan[/b]button. This can be set to the same value as [member filesystem/directories/default_project_path] for convenience.
+ The folder where projects should be scanned for (recursively), in a way similar to the project manager's [b]Scan[/b] button. This can be set to the same value as [member filesystem/directories/default_project_path] for convenience.
[b]Note:[/b] Setting this path to a folder with very large amounts of files/folders can slow down the project manager startup significantly. To keep the project manager quick to start up, it is recommended to set this value to a folder as "specific" as possible.
</member>
<member name="filesystem/directories/default_project_path" type="String" setter="" getter="">
The folder where new projects should be created by default when clicking the project manager's [b]New Project[/b] button. This can be set to the same value as [member filesystem/directories/autoscan_project_path] for convenience.
</member>
+ <member name="filesystem/external_programs/3d_model_editor" type="String" setter="" getter="">
+ The program that opens 3D model scene files when clicking "Open in External Program" option in Filesystem Dock. If not specified, the file will be opened in the system's default program.
+ </member>
+ <member name="filesystem/external_programs/audio_editor" type="String" setter="" getter="">
+ The program that opens audio files when clicking "Open in External Program" option in Filesystem Dock. If not specified, the file will be opened in the system's default program.
+ </member>
+ <member name="filesystem/external_programs/raster_image_editor" type="String" setter="" getter="">
+ The program that opens raster image files when clicking "Open in External Program" option in Filesystem Dock. If not specified, the file will be opened in the system's default program.
+ </member>
+ <member name="filesystem/external_programs/vector_image_editor" type="String" setter="" getter="">
+ The program that opens vector image files when clicking "Open in External Program" option in Filesystem Dock. If not specified, the file will be opened in the system's default program.
+ </member>
<member name="filesystem/file_dialog/display_mode" type="int" setter="" getter="">
The display mode to use in the editor's file dialogs.
- [b]Thumbnails[/b] takes more space, but displays dynamic resource thumbnails, making resources easier to preview without having to open them.
diff --git a/doc/classes/JSON.xml b/doc/classes/JSON.xml
index 93731cf553..6fe53dfaac 100644
--- a/doc/classes/JSON.xml
+++ b/doc/classes/JSON.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="JSON" inherits="RefCounted" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
+<class name="JSON" inherits="Resource" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
<brief_description>
Helper class for creating and parsing JSON data.
</brief_description>
@@ -49,13 +49,21 @@
Returns an empty string if the last call to [method parse] was successful, or the error message if it failed.
</description>
</method>
+ <method name="get_parsed_text" qualifiers="const">
+ <return type="String" />
+ <description>
+ Return the text parsed by [method parse] as long as the function is instructed to keep it.
+ </description>
+ </method>
<method name="parse">
<return type="int" enum="Error" />
- <param index="0" name="json_string" type="String" />
+ <param index="0" name="json_text" type="String" />
+ <param index="1" name="keep_text" type="bool" default="false" />
<description>
- Attempts to parse the [param json_string] provided.
+ Attempts to parse the [param json_text] provided.
Returns an [enum Error]. If the parse was successful, it returns [constant OK] and the result can be retrieved using [member data]. If unsuccessful, use [method get_error_line] and [method get_error_message] for identifying the source of the failure.
Non-static variant of [method parse_string], if you want custom error handling.
+ The optional [param keep_text] argument instructs the parser to keep a copy of the original text. This text can be obtained later by using the [method get_parsed_text] function and is used when saving the resource (instead of generating new text from [member data]).
</description>
</method>
<method name="parse_string" qualifiers="static">
diff --git a/doc/classes/ProjectSettings.xml b/doc/classes/ProjectSettings.xml
index de41edc305..bd68dc7a64 100644
--- a/doc/classes/ProjectSettings.xml
+++ b/doc/classes/ProjectSettings.xml
@@ -615,8 +615,17 @@
Main window content is expanded to the full size of the window. Unlike a borderless window, the frame is left intact and can be used to resize the window, and the title bar is transparent, but has minimize/maximize/close buttons.
[b]Note:[/b] This setting is implemented only on macOS.
</member>
- <member name="display/window/size/initial_screen" type="int" setter="" getter="" default="-2">
- Main window initial screen.
+ <member name="display/window/size/initial_position" type="Vector2i" setter="" getter="" default="Vector2i(0, 0)">
+ Main window initial position (in virtual desktop coordinates), this settings is used only if [member display/window/size/initial_position_type] is set to "Absolute" ([code]0[/code]).
+ </member>
+ <member name="display/window/size/initial_position_type" type="int" setter="" getter="" default="1">
+ Main window initial position.
+ [code]0[/code] - "Absolute", [member display/window/size/initial_position] is used to set window position.
+ [code]1[/code] - "Primary Screen Center".
+ [code]2[/code] - "Other Screen Center", [member display/window/size/initial_screen] is used to set window position.
+ </member>
+ <member name="display/window/size/initial_screen" type="int" setter="" getter="" default="0">
+ Main window initial screen, this settings is used only if [member display/window/size/initial_position_type] is set to "Other Screen Center" ([code]2[/code]).
</member>
<member name="display/window/size/mode" type="int" setter="" getter="" default="0">
Main window mode. See [enum DisplayServer.WindowMode] for possible values and how each mode behaves.
diff --git a/doc/classes/ResourceFormatLoader.xml b/doc/classes/ResourceFormatLoader.xml
index 2b6376f2cd..bb55123b37 100644
--- a/doc/classes/ResourceFormatLoader.xml
+++ b/doc/classes/ResourceFormatLoader.xml
@@ -38,6 +38,13 @@
Gets the list of extensions for files this loader is able to read.
</description>
</method>
+ <method name="_get_resource_script_class" qualifiers="virtual const">
+ <return type="String" />
+ <param index="0" name="path" type="String" />
+ <description>
+ Returns the script class name associated with the [Resource] under the given [param path]. If the resource has no script or the script isn't a named class, it should return [code]""[/code].
+ </description>
+ </method>
<method name="_get_resource_type" qualifiers="virtual const">
<return type="String" />
<param index="0" name="path" type="String" />
diff --git a/doc/classes/Shader.xml b/doc/classes/Shader.xml
index 75f835260a..c472ab647e 100644
--- a/doc/classes/Shader.xml
+++ b/doc/classes/Shader.xml
@@ -26,12 +26,12 @@
Returns the shader mode for the shader, either [constant MODE_CANVAS_ITEM], [constant MODE_SPATIAL] or [constant MODE_PARTICLES].
</description>
</method>
- <method name="has_parameter" qualifiers="const">
- <return type="bool" />
- <param index="0" name="name" type="StringName" />
+ <method name="get_shader_uniform_list">
+ <return type="Array" />
+ <param index="0" name="get_groups" type="bool" default="false" />
<description>
- Returns [code]true[/code] if the shader has this param defined as a uniform in its code.
- [b]Note:[/b] [param name] must match the name of the uniform in the code exactly.
+ Get the list of shader uniforms that can be assigned to a [ShaderMaterial], for use with [method ShaderMaterial.set_shader_parameter] and [method ShaderMaterial.get_shader_parameter]. The parameters returned are contained in dictionaries in a similar format to the ones returned by [method Object.get_property_list].
+ If argument [param get_groups] is true, parameter grouping hints will be provided.
</description>
</method>
<method name="set_default_texture_parameter">
diff --git a/doc/classes/TileMap.xml b/doc/classes/TileMap.xml
index f67b84f96f..2fd42666b4 100644
--- a/doc/classes/TileMap.xml
+++ b/doc/classes/TileMap.xml
@@ -104,7 +104,8 @@
<param index="1" name="coords" type="Vector2i" />
<param index="2" name="use_proxies" type="bool" default="false" />
<description>
- Returns the tile source ID of the cell on layer [param layer] at coordinates [param coords]. If [param use_proxies] is [code]false[/code], ignores the [TileSet]'s tile proxies, returning the raw alternative identifier. See [method TileSet.map_tile_proxy].
+ Returns the tile source ID of the cell on layer [param layer] at coordinates [param coords]. Returns [code]-1[/code] if the cell does not exist.
+ If [param use_proxies] is [code]false[/code], ignores the [TileSet]'s tile proxies, returning the raw alternative identifier. See [method TileSet.map_tile_proxy].
</description>
</method>
<method name="get_cell_tile_data" qualifiers="const">
@@ -113,8 +114,17 @@
<param index="1" name="coords" type="Vector2i" />
<param index="2" name="use_proxies" type="bool" default="false" />
<description>
- Returns the [TileData] object associated with the given cell, or [code]null[/code] if the cell is not a [TileSetAtlasSource].
+ Returns the [TileData] object associated with the given cell, or [code]null[/code] if the cell does not exist or is not a [TileSetAtlasSource].
If [param use_proxies] is [code]false[/code], ignores the [TileSet]'s tile proxies, returning the raw alternative identifier. See [method TileSet.map_tile_proxy].
+ [codeblock]
+ func get_clicked_tile_power():
+ var clicked_cell = tile_map.local_to_map(tile_map.get_local_mouse_position())
+ var data = tile_map.get_cell_tile_data(0, clicked_cell)
+ if data:
+ return data.get_custom_data("power")
+ else:
+ return 0
+ [/codeblock]
</description>
</method>
<method name="get_coords_for_body_rid">
diff --git a/doc/classes/Window.xml b/doc/classes/Window.xml
index da31e6761e..c4ea11ab66 100644
--- a/doc/classes/Window.xml
+++ b/doc/classes/Window.xml
@@ -771,8 +771,16 @@
Right-to-left layout direction.
</constant>
<constant name="WINDOW_INITIAL_POSITION_ABSOLUTE" value="0" enum="WindowInitialPosition">
+ Initial window position is determined by [member position].
</constant>
- <constant name="WINDOW_INITIAL_POSITION_CENTER_SCREEN" value="1" enum="WindowInitialPosition">
+ <constant name="WINDOW_INITIAL_POSITION_CENTER_PRIMARY_SCREEN" value="1" enum="WindowInitialPosition">
+ Initial window position is a center of the primary screen.
+ </constant>
+ <constant name="WINDOW_INITIAL_POSITION_CENTER_MAIN_WINDOW_SCREEN" value="2" enum="WindowInitialPosition">
+ Initial window position is a center of the main window screen.
+ </constant>
+ <constant name="WINDOW_INITIAL_POSITION_CENTER_OTHER_SCREEN" value="3" enum="WindowInitialPosition">
+ Initial window position is a center of [member current_screen] screen.
</constant>
</constants>
<theme_items>
diff --git a/drivers/gles3/rasterizer_canvas_gles3.cpp b/drivers/gles3/rasterizer_canvas_gles3.cpp
index fb338b9849..89b1c1889e 100644
--- a/drivers/gles3/rasterizer_canvas_gles3.cpp
+++ b/drivers/gles3/rasterizer_canvas_gles3.cpp
@@ -803,7 +803,7 @@ void RasterizerCanvasGLES3::_record_item_commands(const Item *p_item, RID p_rend
light_count++;
- if (light_count == data.max_lights_per_item) {
+ if (light_count == data.max_lights_per_item - 1) {
break;
}
}
diff --git a/drivers/vulkan/vulkan_context.cpp b/drivers/vulkan/vulkan_context.cpp
index 0bccefede8..27f96f35af 100644
--- a/drivers/vulkan/vulkan_context.cpp
+++ b/drivers/vulkan/vulkan_context.cpp
@@ -353,11 +353,11 @@ Error VulkanContext::_get_preferred_validation_layers(uint32_t *count, const cha
ERR_FAIL_V(ERR_CANT_CREATE);
}
- for (uint32_t i = 0; i < instance_validation_layers_alt.size(); i++) {
- if (_check_layers(instance_validation_layers_alt[i].size(), instance_validation_layers_alt[i].ptr(), instance_layer_count, instance_layers)) {
- *count = instance_validation_layers_alt[i].size();
+ for (const LocalVector<const char *> &layer : instance_validation_layers_alt) {
+ if (_check_layers(layer.size(), layer.ptr(), instance_layer_count, instance_layers)) {
+ *count = layer.size();
if (names != nullptr) {
- *names = instance_validation_layers_alt[i].ptr();
+ *names = layer.ptr();
}
break;
}
diff --git a/drivers/windows/file_access_windows.cpp b/drivers/windows/file_access_windows.cpp
index 37a94ce4cc..ea40622afc 100644
--- a/drivers/windows/file_access_windows.cpp
+++ b/drivers/windows/file_access_windows.cpp
@@ -34,7 +34,6 @@
#include "core/os/os.h"
#include "core/string/print_string.h"
-
#include <share.h> // _SH_DENYNO
#include <shlwapi.h>
#define WIN32_LEAN_AND_MEAN
@@ -58,7 +57,27 @@ void FileAccessWindows::check_errors() const {
}
}
+bool FileAccessWindows::is_path_invalid(const String &p_path) {
+ // Check for invalid operating system file.
+ String fname = p_path;
+ int dot = fname.find(".");
+ if (dot != -1) {
+ fname = fname.substr(0, dot);
+ }
+ fname = fname.to_lower();
+ return invalid_files.has(fname);
+}
+
Error FileAccessWindows::open_internal(const String &p_path, int p_mode_flags) {
+ if (is_path_invalid(p_path)) {
+#ifdef DEBUG_ENABLED
+ if (p_mode_flags != READ) {
+ WARN_PRINT("The path :" + p_path + " is a reserved Windows system pipe, so it can't be used for creating files.");
+ }
+#endif
+ return ERR_INVALID_PARAMETER;
+ }
+
_close();
path_src = p_path;
@@ -313,6 +332,10 @@ void FileAccessWindows::store_buffer(const uint8_t *p_src, uint64_t p_length) {
}
bool FileAccessWindows::file_exists(const String &p_name) {
+ if (is_path_invalid(p_name)) {
+ return false;
+ }
+
String filename = fix_path(p_name);
FILE *g = _wfsopen((LPCWSTR)(filename.utf16().get_data()), L"rb", _SH_DENYNO);
if (g == nullptr) {
@@ -324,6 +347,10 @@ bool FileAccessWindows::file_exists(const String &p_name) {
}
uint64_t FileAccessWindows::_get_modified_time(const String &p_file) {
+ if (is_path_invalid(p_file)) {
+ return 0;
+ }
+
String file = fix_path(p_file);
if (file.ends_with("/") && file != "/") {
file = file.substr(0, file.length() - 1);
@@ -352,4 +379,20 @@ FileAccessWindows::~FileAccessWindows() {
_close();
}
+HashSet<String> FileAccessWindows::invalid_files;
+
+void FileAccessWindows::initialize() {
+ static const char *reserved_files[]{
+ "con", "prn", "aux", "nul", "com0", "com1", "com2", "com3", "com4", "com5", "com6", "com7", "com8", "com9", "lpt0", "lpt1", "lpt2", "lpt3", "lpt4", "lpt5", "lpt6", "lpt7", "lpt8", "lpt9", nullptr
+ };
+ int reserved_file_index = 0;
+ while (reserved_files[reserved_file_index] != nullptr) {
+ invalid_files.insert(reserved_files[reserved_file_index]);
+ reserved_file_index++;
+ }
+}
+void FileAccessWindows::finalize() {
+ invalid_files.clear();
+}
+
#endif // WINDOWS_ENABLED
diff --git a/drivers/windows/file_access_windows.h b/drivers/windows/file_access_windows.h
index 832cef3363..2b9960d494 100644
--- a/drivers/windows/file_access_windows.h
+++ b/drivers/windows/file_access_windows.h
@@ -50,6 +50,9 @@ class FileAccessWindows : public FileAccess {
void _close();
+ static bool is_path_invalid(const String &p_path);
+ static HashSet<String> invalid_files;
+
public:
virtual Error open_internal(const String &p_path, int p_mode_flags) override; ///< open a file
virtual bool is_open() const override; ///< true when file is open
@@ -79,6 +82,9 @@ public:
virtual uint32_t _get_unix_permissions(const String &p_file) override;
virtual Error _set_unix_permissions(const String &p_file, uint32_t p_permissions) override;
+ static void initialize();
+ static void finalize();
+
FileAccessWindows() {}
virtual ~FileAccessWindows();
};
diff --git a/editor/editor_file_system.cpp b/editor/editor_file_system.cpp
index a9b4c08698..16ecac4dac 100644
--- a/editor/editor_file_system.cpp
+++ b/editor/editor_file_system.cpp
@@ -47,7 +47,7 @@
EditorFileSystem *EditorFileSystem::singleton = nullptr;
//the name is the version, to keep compatibility with different versions of Godot
-#define CACHE_FILE_NAME "filesystem_cache7"
+#define CACHE_FILE_NAME "filesystem_cache8"
void EditorFileSystemDirectory::sort_files() {
files.sort_custom<FileInfoSort>();
@@ -169,6 +169,11 @@ StringName EditorFileSystemDirectory::get_file_type(int p_idx) const {
return files[p_idx]->type;
}
+StringName EditorFileSystemDirectory::get_file_resource_script_class(int p_idx) const {
+ ERR_FAIL_INDEX_V(p_idx, files.size(), "");
+ return files[p_idx]->resource_script_class;
+}
+
String EditorFileSystemDirectory::get_name() {
return name;
}
@@ -266,6 +271,10 @@ void EditorFileSystem::_scan_filesystem() {
FileCache fc;
fc.type = split[1];
+ if (fc.type.find("/") != -1) {
+ fc.type = fc.type.get_slice("/", 0);
+ fc.resource_script_class = fc.type.get_slice("/", 1);
+ }
fc.uid = split[2].to_int();
fc.modification_time = split[3].to_int();
fc.import_modification_time = split[4].to_int();
@@ -854,6 +863,7 @@ void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir, Ref<DirAc
if (fc && fc->modification_time == mt && fc->import_modification_time == import_mt && !_test_for_reimport(path, true)) {
fi->type = fc->type;
+ fi->resource_script_class = fc->resource_script_class;
fi->uid = fc->uid;
fi->deps = fc->deps;
fi->modified_time = fc->modification_time;
@@ -875,6 +885,7 @@ void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir, Ref<DirAc
if (fc->type.is_empty()) {
fi->type = ResourceLoader::get_resource_type(path);
+ fi->resource_script_class = ResourceLoader::get_resource_script_class(path);
fi->import_group_file = ResourceLoader::get_import_group_file(path);
//there is also the chance that file type changed due to reimport, must probably check this somehow here (or kind of note it for next time in another file?)
//note: I think this should not happen any longer..
@@ -904,6 +915,7 @@ void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir, Ref<DirAc
if (fc && fc->modification_time == mt) {
//not imported, so just update type if changed
fi->type = fc->type;
+ fi->resource_script_class = fc->resource_script_class;
fi->uid = fc->uid;
fi->modified_time = fc->modification_time;
fi->deps = fc->deps;
@@ -915,6 +927,7 @@ void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir, Ref<DirAc
} else {
//new or modified time
fi->type = ResourceLoader::get_resource_type(path);
+ fi->resource_script_class = ResourceLoader::get_resource_script_class(path);
if (fi->type == "" && textfile_extensions.has(ext)) {
fi->type = "TextFile";
}
@@ -1029,6 +1042,7 @@ void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir, const
fi->modified_time = FileAccess::get_modified_time(path);
fi->import_modified_time = 0;
fi->type = ResourceLoader::get_resource_type(path);
+ fi->resource_script_class = ResourceLoader::get_resource_script_class(path);
if (fi->type == "" && textfile_extensions.has(ext)) {
fi->type = "TextFile";
}
@@ -1285,7 +1299,12 @@ void EditorFileSystem::_save_filesystem_cache(EditorFileSystemDirectory *p_dir,
if (!p_dir->files[i]->import_group_file.is_empty()) {
group_file_cache.insert(p_dir->files[i]->import_group_file);
}
- String s = p_dir->files[i]->file + "::" + p_dir->files[i]->type + "::" + itos(p_dir->files[i]->uid) + "::" + itos(p_dir->files[i]->modified_time) + "::" + itos(p_dir->files[i]->import_modified_time) + "::" + itos(p_dir->files[i]->import_valid) + "::" + p_dir->files[i]->import_group_file + "::" + p_dir->files[i]->script_class_name + "<>" + p_dir->files[i]->script_class_extends + "<>" + p_dir->files[i]->script_class_icon_path;
+
+ String type = p_dir->files[i]->type;
+ if (p_dir->files[i]->resource_script_class) {
+ type += "/" + String(p_dir->files[i]->resource_script_class);
+ }
+ String s = p_dir->files[i]->file + "::" + type + "::" + itos(p_dir->files[i]->uid) + "::" + itos(p_dir->files[i]->modified_time) + "::" + itos(p_dir->files[i]->import_modified_time) + "::" + itos(p_dir->files[i]->import_valid) + "::" + p_dir->files[i]->import_group_file + "::" + p_dir->files[i]->script_class_name + "<>" + p_dir->files[i]->script_class_extends + "<>" + p_dir->files[i]->script_class_icon_path;
s += "::";
for (int j = 0; j < p_dir->files[i]->deps.size(); j++) {
if (j > 0) {
@@ -1612,6 +1631,8 @@ void EditorFileSystem::update_file(const String &p_file) {
if (type.is_empty() && textfile_extensions.has(p_file.get_extension())) {
type = "TextFile";
}
+ String script_class = ResourceLoader::get_resource_script_class(p_file);
+
ResourceUID::ID uid = ResourceLoader::get_resource_uid(p_file);
if (cpos == -1) {
@@ -1645,6 +1666,7 @@ void EditorFileSystem::update_file(const String &p_file) {
}
fs->files[cpos]->type = type;
+ fs->files[cpos]->resource_script_class = script_class;
fs->files[cpos]->uid = uid;
fs->files[cpos]->script_class_name = _get_global_script_class(type, p_file, &fs->files[cpos]->script_class_extends, &fs->files[cpos]->script_class_icon_path);
fs->files[cpos]->import_group_file = ResourceLoader::get_import_group_file(p_file);
diff --git a/editor/editor_file_system.h b/editor/editor_file_system.h
index 03b1fb4a49..2490bd31b3 100644
--- a/editor/editor_file_system.h
+++ b/editor/editor_file_system.h
@@ -54,6 +54,7 @@ class EditorFileSystemDirectory : public Object {
struct FileInfo {
String file;
StringName type;
+ StringName resource_script_class; // If any resource has script with a global class name, its found here.
ResourceUID::ID uid = ResourceUID::INVALID_ID;
uint64_t modified_time = 0;
uint64_t import_modified_time = 0;
@@ -61,6 +62,7 @@ class EditorFileSystemDirectory : public Object {
String import_group_file;
Vector<String> deps;
bool verified = false; //used for checking changes
+ // These are for script resources only.
String script_class_name;
String script_class_extends;
String script_class_icon_path;
@@ -90,6 +92,7 @@ public:
String get_file(int p_idx) const;
String get_file_path(int p_idx) const;
StringName get_file_type(int p_idx) const;
+ StringName get_file_resource_script_class(int p_idx) const;
Vector<String> get_file_deps(int p_idx) const;
bool get_file_import_is_valid(int p_idx) const;
uint64_t get_file_modified_time(int p_idx) const;
@@ -189,6 +192,7 @@ class EditorFileSystem : public Node {
/* Used for reading the filesystem cache file */
struct FileCache {
String type;
+ String resource_script_class;
ResourceUID::ID uid = ResourceUID::INVALID_ID;
uint64_t modification_time = 0;
uint64_t import_modification_time = 0;
diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp
index 035bd96f4d..4753761f05 100644
--- a/editor/editor_inspector.cpp
+++ b/editor/editor_inspector.cpp
@@ -2181,8 +2181,7 @@ void EditorInspectorArray::_notification(int p_what) {
odd_style->set_bg_color(color.darkened(-0.08));
even_style->set_bg_color(color.darkened(0.08));
- for (int i = 0; i < (int)array_elements.size(); i++) {
- ArrayElement &ae = array_elements[i];
+ for (ArrayElement &ae : array_elements) {
if (ae.move_texture_rect) {
ae.move_texture_rect->set_texture(get_theme_icon(SNAME("TripleBar"), SNAME("EditorIcons")));
}
@@ -3283,6 +3282,11 @@ void EditorInspector::update_tree() {
ped->parse_end(object);
_parse_added_editors(main_vbox, nullptr, ped);
}
+
+ if (_is_main_editor_inspector()) {
+ // Updating inspector might invalidate some editing owners.
+ EditorNode::get_singleton()->hide_unused_editors();
+ }
}
void EditorInspector::update_property(const String &p_prop) {
@@ -3307,6 +3311,9 @@ void EditorInspector::_clear() {
sections.clear();
pending.clear();
restart_request_props.clear();
+ if (_is_main_editor_inspector()) {
+ EditorNode::get_singleton()->hide_unused_editors(this);
+ }
}
Object *EditorInspector::get_edited_object() {
@@ -3641,6 +3648,10 @@ void EditorInspector::_edit_set(const String &p_name, const Variant &p_value, bo
}
}
+bool EditorInspector::_is_main_editor_inspector() const {
+ return InspectorDock::get_singleton() && InspectorDock::get_inspector_singleton() == this;
+}
+
void EditorInspector::_property_changed(const String &p_path, const Variant &p_value, const String &p_name, bool p_changing, bool p_update_all) {
// The "changing" variable must be true for properties that trigger events as typing occurs,
// like "text_changed" signal. E.g. text property of Label, Button, RichTextLabel, etc.
diff --git a/editor/editor_inspector.h b/editor/editor_inspector.h
index 699a88e657..1690302e6e 100644
--- a/editor/editor_inspector.h
+++ b/editor/editor_inspector.h
@@ -502,6 +502,7 @@ class EditorInspector : public ScrollContainer {
bool restrict_to_basic = false;
void _edit_set(const String &p_name, const Variant &p_value, bool p_refresh_all, const String &p_changed_field);
+ bool _is_main_editor_inspector() const;
void _property_changed(const String &p_path, const Variant &p_value, const String &p_name = "", bool p_changing = false, bool p_update_all = false);
void _multiple_properties_changed(Vector<String> p_paths, Array p_values, bool p_changing = false);
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp
index 3132581af5..05e0c6750e 100644
--- a/editor/editor_node.cpp
+++ b/editor/editor_node.cpp
@@ -2078,51 +2078,55 @@ bool EditorNode::_is_class_editor_disabled_by_feature_profile(const StringName &
return false;
}
-void EditorNode::edit_item(Object *p_object) {
+void EditorNode::edit_item(Object *p_object, Object *p_editing_owner) {
+ ERR_FAIL_NULL(p_editing_owner);
+
if (p_object && _is_class_editor_disabled_by_feature_profile(p_object->get_class())) {
return;
}
- Vector<EditorPlugin *> top_plugins = editor_plugins_over->get_plugins_list();
Vector<EditorPlugin *> item_plugins;
if (p_object) {
item_plugins = editor_data.get_subeditors(p_object);
}
if (!item_plugins.is_empty()) {
- bool same = true;
- if (item_plugins.size() == top_plugins.size()) {
- for (int i = 0; i < item_plugins.size(); i++) {
- if (item_plugins[i] != top_plugins[i]) {
- same = false;
- }
+ ObjectID owner_id = p_editing_owner->get_instance_id();
+
+ for (EditorPlugin *plugin : active_plugins[owner_id]) {
+ if (!item_plugins.has(plugin)) {
+ plugin->make_visible(false);
+ plugin->edit(nullptr);
}
- } else {
- same = false;
}
- if (!same) {
- _display_top_editors(false);
- _set_top_editors(item_plugins);
+ for (EditorPlugin *plugin : item_plugins) {
+ for (KeyValue<ObjectID, HashSet<EditorPlugin *>> &kv : active_plugins) {
+ if (kv.key != owner_id) {
+ EditorPropertyResource *epres = Object::cast_to<EditorPropertyResource>(ObjectDB::get_instance(kv.key));
+ if (epres && kv.value.has(plugin)) {
+ // If it's resource property editing the same resource type, fold it.
+ epres->fold_resource();
+ }
+ kv.value.erase(plugin);
+ }
+ }
+ active_plugins[owner_id].insert(plugin);
+ plugin->edit(p_object);
+ plugin->make_visible(true);
}
- _set_editing_top_editors(p_object);
- _display_top_editors(true);
- } else if (!top_plugins.is_empty()) {
- hide_top_editors();
+ } else {
+ hide_unused_editors(p_editing_owner);
}
}
-void EditorNode::edit_item_resource(Ref<Resource> p_resource) {
- edit_item(p_resource.ptr());
-}
-
void EditorNode::push_item(Object *p_object, const String &p_property, bool p_inspector_only) {
if (!p_object) {
InspectorDock::get_inspector_singleton()->edit(nullptr);
NodeDock::get_singleton()->set_node(nullptr);
SceneTreeDock::get_singleton()->set_selected(nullptr);
InspectorDock::get_singleton()->update(nullptr);
- _display_top_editors(false);
+ hide_unused_editors();
return;
}
@@ -2150,22 +2154,34 @@ void EditorNode::_save_default_environment() {
}
}
-void EditorNode::hide_top_editors() {
- _display_top_editors(false);
-
- editor_plugins_over->clear();
-}
-
-void EditorNode::_display_top_editors(bool p_display) {
- editor_plugins_over->make_visible(p_display);
-}
-
-void EditorNode::_set_top_editors(Vector<EditorPlugin *> p_editor_plugins_over) {
- editor_plugins_over->set_plugins_list(p_editor_plugins_over);
-}
+void EditorNode::hide_unused_editors(const Object *p_editing_owner) {
+ if (p_editing_owner) {
+ const ObjectID id = p_editing_owner->get_instance_id();
+ for (EditorPlugin *plugin : active_plugins[id]) {
+ plugin->make_visible(false);
+ plugin->edit(nullptr);
+ editor_plugins_over->remove_plugin(plugin);
+ }
+ active_plugins.erase(id);
+ } else {
+ // If no editing owner is provided, this method will go over all owners and check if they are valid.
+ // This is to sweep properties that were removed from the inspector.
+ List<ObjectID> to_remove;
+ for (KeyValue<ObjectID, HashSet<EditorPlugin *>> &kv : active_plugins) {
+ if (!ObjectDB::get_instance(kv.key)) {
+ to_remove.push_back(kv.key);
+ for (EditorPlugin *plugin : kv.value) {
+ plugin->make_visible(false);
+ plugin->edit(nullptr);
+ editor_plugins_over->remove_plugin(plugin);
+ }
+ }
+ }
-void EditorNode::_set_editing_top_editors(Object *p_current_object) {
- editor_plugins_over->edit(p_current_object);
+ for (const ObjectID &id : to_remove) {
+ active_plugins.erase(id);
+ }
+ }
}
static bool overrides_external_editor(Object *p_object) {
@@ -2199,7 +2215,7 @@ void EditorNode::_edit_current(bool p_skip_foreign) {
NodeDock::get_singleton()->set_node(nullptr);
InspectorDock::get_singleton()->update(nullptr);
- _display_top_editors(false);
+ hide_unused_editors();
return;
}
@@ -2327,6 +2343,9 @@ void EditorNode::_edit_current(bool p_skip_foreign) {
InspectorDock::get_inspector_singleton()->set_use_folding(!disable_folding);
}
+ Object *editor_owner = is_node ? (Object *)SceneTreeDock::get_singleton() : is_resource ? (Object *)InspectorDock::get_inspector_singleton()
+ : (Object *)this;
+
// Take care of the main editor plugin.
if (!inspector_only) {
@@ -2343,6 +2362,7 @@ void EditorNode::_edit_current(bool p_skip_foreign) {
}
}
+ ObjectID editor_owner_id = editor_owner->get_instance_id();
if (main_plugin && !skip_main_plugin) {
// Special case if use of external editor is true.
Resource *current_res = Object::cast_to<Resource>(current_obj);
@@ -2353,15 +2373,22 @@ void EditorNode::_edit_current(bool p_skip_foreign) {
}
else if (main_plugin != editor_plugin_screen && (!ScriptEditor::get_singleton() || !ScriptEditor::get_singleton()->is_visible_in_tree() || ScriptEditor::get_singleton()->can_take_away_focus())) {
+ // Unedit previous plugin.
+ editor_plugin_screen->edit(nullptr);
+ active_plugins[editor_owner_id].erase(editor_plugin_screen);
// Update screen main_plugin.
editor_select(plugin_index);
main_plugin->edit(current_obj);
} else {
editor_plugin_screen->edit(current_obj);
}
+ is_main_screen_editing = true;
+ } else if (!main_plugin && editor_plugin_screen && is_main_screen_editing) {
+ editor_plugin_screen->edit(nullptr);
+ is_main_screen_editing = false;
}
- edit_item(current_obj);
+ edit_item(current_obj, editor_owner);
}
InspectorDock::get_singleton()->update(current_obj);
@@ -3712,11 +3739,12 @@ void EditorNode::set_current_scene(int p_idx) {
call_deferred(SNAME("_set_main_scene_state"), state, get_edited_scene()); // Do after everything else is done setting up.
}
-void EditorNode::setup_color_picker(ColorPicker *picker) {
+void EditorNode::setup_color_picker(ColorPicker *p_picker) {
+ p_picker->set_editor_settings(EditorSettings::get_singleton());
int default_color_mode = EDITOR_GET("interface/inspector/default_color_picker_mode");
int picker_shape = EDITOR_GET("interface/inspector/default_color_picker_shape");
- picker->set_color_mode((ColorPicker::ColorModeType)default_color_mode);
- picker->set_picker_shape((ColorPicker::PickerShapeType)picker_shape);
+ p_picker->set_color_mode((ColorPicker::ColorModeType)default_color_mode);
+ p_picker->set_picker_shape((ColorPicker::PickerShapeType)picker_shape);
}
bool EditorNode::is_scene_open(const String &p_path) {
diff --git a/editor/editor_node.h b/editor/editor_node.h
index fb2544c141..ef4ea34da2 100644
--- a/editor/editor_node.h
+++ b/editor/editor_node.h
@@ -68,6 +68,7 @@ class EditorLayoutsDialog;
class EditorLog;
class EditorPluginList;
class EditorQuickOpen;
+class EditorPropertyResource;
class EditorResourcePreview;
class EditorResourceConversionPlugin;
class EditorRun;
@@ -293,6 +294,8 @@ private:
bool _initializing_plugins = false;
HashMap<String, EditorPlugin *> addon_name_to_plugin;
LocalVector<String> pending_addons;
+ HashMap<ObjectID, HashSet<EditorPlugin *>> active_plugins;
+ bool is_main_screen_editing = false;
PanelContainer *scene_root_parent = nullptr;
Control *theme_base = nullptr;
@@ -592,10 +595,6 @@ private:
void _inherit_request(String p_file);
void _instantiate_request(const Vector<String> &p_files);
- void _display_top_editors(bool p_display);
- void _set_top_editors(Vector<EditorPlugin *> p_editor_plugins_over);
- void _set_editing_top_editors(Object *p_current_object);
-
void _quick_opened();
void _quick_run();
void _open_command_palette();
@@ -796,9 +795,8 @@ public:
void show_about() { _menu_option_confirm(HELP_ABOUT, false); }
void push_item(Object *p_object, const String &p_property = "", bool p_inspector_only = false);
- void edit_item(Object *p_object);
- void edit_item_resource(Ref<Resource> p_resource);
- void hide_top_editors();
+ void edit_item(Object *p_object, Object *p_editing_owner);
+ void hide_unused_editors(const Object *p_editing_owner = nullptr);
void select_editor_by_name(const String &p_name);
@@ -824,7 +822,7 @@ public:
void set_current_scene(int p_idx);
- void setup_color_picker(ColorPicker *picker);
+ void setup_color_picker(ColorPicker *p_picker);
void request_instantiate_scene(const String &p_path);
void request_instantiate_scenes(const Vector<String> &p_files);
diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp
index 46f52ec4af..a69214f903 100644
--- a/editor/editor_properties.cpp
+++ b/editor/editor_properties.cpp
@@ -3905,40 +3905,7 @@ void EditorPropertyResource::_open_editor_pressed() {
Ref<Resource> res = get_edited_object()->get(get_edited_property());
if (res.is_valid()) {
// May clear the editor so do it deferred.
- callable_mp(EditorNode::get_singleton(), &EditorNode::edit_item_resource).bind(res).call_deferred();
- }
-}
-
-void EditorPropertyResource::_fold_other_editors(Object *p_self) {
- if (this == p_self) {
- return;
- }
-
- Ref<Resource> res = get_edited_object()->get(get_edited_property());
- if (!res.is_valid()) {
- return;
- }
-
- bool use_editor = false;
- for (int i = 0; i < EditorNode::get_editor_data().get_editor_plugin_count(); i++) {
- EditorPlugin *ep = EditorNode::get_editor_data().get_editor_plugin(i);
- if (ep->handles(res.ptr())) {
- use_editor = true;
- break;
- }
- }
- if (!use_editor) {
- return;
- }
-
- opened_editor = false;
-
- bool unfolded = get_edited_object()->editor_is_section_unfolded(get_edited_property());
- if (unfolded) {
- // Refold.
- resource_picker->set_toggle_pressed(false);
- get_edited_object()->editor_set_section_unfold(get_edited_property(), false);
- update_property();
+ callable_mp(EditorNode::get_singleton(), &EditorNode::edit_item).bind(res.ptr(), this).call_deferred();
}
}
@@ -4091,20 +4058,17 @@ void EditorPropertyResource::update_property() {
sub_inspector_vbox->add_child(sub_inspector);
resource_picker->set_toggle_pressed(true);
- bool use_editor = false;
+ Array editor_list;
for (int i = 0; i < EditorNode::get_editor_data().get_editor_plugin_count(); i++) {
EditorPlugin *ep = EditorNode::get_editor_data().get_editor_plugin(i);
if (ep->handles(res.ptr())) {
- use_editor = true;
+ editor_list.push_back(ep);
}
}
- if (use_editor) {
- // Open editor directly and hide other such editors which are currently open.
+ if (!editor_list.is_empty()) {
+ // Open editor directly.
_open_editor_pressed();
- if (is_inside_tree()) {
- get_tree()->call_deferred(SNAME("call_group"), "_editor_resource_properties", "_fold_other_editors", this);
- }
opened_editor = true;
}
@@ -4123,7 +4087,7 @@ void EditorPropertyResource::update_property() {
sub_inspector_vbox = nullptr;
if (opened_editor) {
- EditorNode::get_singleton()->hide_top_editors();
+ EditorNode::get_singleton()->hide_unused_editors();
opened_editor = false;
}
@@ -4157,6 +4121,15 @@ void EditorPropertyResource::set_use_sub_inspector(bool p_enable) {
use_sub_inspector = p_enable;
}
+void EditorPropertyResource::fold_resource() {
+ bool unfolded = get_edited_object()->editor_is_section_unfolded(get_edited_property());
+ if (unfolded) {
+ resource_picker->set_toggle_pressed(false);
+ get_edited_object()->editor_set_section_unfold(get_edited_property(), false);
+ update_property();
+ }
+}
+
void EditorPropertyResource::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE:
@@ -4168,14 +4141,8 @@ void EditorPropertyResource::_notification(int p_what) {
}
}
-void EditorPropertyResource::_bind_methods() {
- ClassDB::bind_method(D_METHOD("_fold_other_editors"), &EditorPropertyResource::_fold_other_editors);
-}
-
EditorPropertyResource::EditorPropertyResource() {
use_sub_inspector = bool(EDITOR_GET("interface/inspector/open_resources_in_current_inspector"));
-
- add_to_group("_editor_resource_properties");
}
////////////// DEFAULT PLUGIN //////////////////////
diff --git a/editor/editor_properties.h b/editor/editor_properties.h
index a255af30ee..ea9203cbf4 100644
--- a/editor/editor_properties.h
+++ b/editor/editor_properties.h
@@ -834,13 +834,11 @@ class EditorPropertyResource : public EditorProperty {
void _sub_inspector_object_id_selected(int p_id);
void _open_editor_pressed();
- void _fold_other_editors(Object *p_self);
void _update_property_bg();
void _update_preferred_shader();
protected:
virtual void _set_read_only(bool p_read_only) override;
- static void _bind_methods();
void _notification(int p_what);
public:
@@ -852,6 +850,7 @@ public:
void expand_revertable() override;
void set_use_sub_inspector(bool p_enable);
+ void fold_resource();
EditorPropertyResource();
};
diff --git a/editor/editor_quick_open.cpp b/editor/editor_quick_open.cpp
index d516610908..b90edb8f90 100644
--- a/editor/editor_quick_open.cpp
+++ b/editor/editor_quick_open.cpp
@@ -69,17 +69,9 @@ void EditorQuickOpen::_build_search_cache(EditorFileSystemDirectory *p_efsd) {
for (int i = 0; i < p_efsd->get_file_count(); i++) {
String file = p_efsd->get_file_path(i);
String engine_type = p_efsd->get_file_type(i);
- // TODO: Fix lack of caching for resource's script's global class name (if applicable).
- String script_type;
- if (_load_resources) {
- Ref<Resource> res = ResourceLoader::load(file);
- if (res.is_valid()) {
- Ref<Script> scr = res->get_script();
- if (scr.is_valid()) {
- script_type = scr->get_language()->get_global_class_name(file);
- }
- }
- }
+
+ String script_type = p_efsd->get_file_resource_script_class(i);
+
String actual_type = script_type.is_empty() ? engine_type : script_type;
// Iterate all possible base types.
for (String &parent_type : base_types) {
diff --git a/editor/editor_quick_open.h b/editor/editor_quick_open.h
index 0503eec835..4b63a226c2 100644
--- a/editor/editor_quick_open.h
+++ b/editor/editor_quick_open.h
@@ -43,7 +43,6 @@ class EditorQuickOpen : public ConfirmationDialog {
Tree *search_options = nullptr;
String base_type;
bool allow_multi_select = false;
- bool _load_resources = false; // Prohibitively slow for now.
Vector<String> files;
OAHashMap<String, Ref<Texture2D>> icons;
diff --git a/editor/editor_resource_picker.cpp b/editor/editor_resource_picker.cpp
index a1c913aadd..cb71a2457b 100644
--- a/editor/editor_resource_picker.cpp
+++ b/editor/editor_resource_picker.cpp
@@ -42,12 +42,6 @@
#include "editor/plugins/script_editor_plugin.h"
#include "editor/scene_tree_dock.h"
-HashMap<StringName, List<StringName>> EditorResourcePicker::allowed_types_cache;
-
-void EditorResourcePicker::clear_caches() {
- allowed_types_cache.clear();
-}
-
void EditorResourcePicker::_update_resource() {
String resource_path;
if (edited_resource.is_valid() && edited_resource->get_path().is_resource_file()) {
@@ -464,7 +458,7 @@ void EditorResourcePicker::set_create_options(Object *p_menu_node) {
if (!base_type.is_empty()) {
int idx = 0;
- HashSet<String> allowed_types;
+ HashSet<StringName> allowed_types;
_get_allowed_types(false, &allowed_types);
Vector<EditorData::CustomType> custom_resources;
@@ -472,7 +466,7 @@ void EditorResourcePicker::set_create_options(Object *p_menu_node) {
custom_resources = EditorNode::get_editor_data().get_custom_types()["Resource"];
}
- for (const String &E : allowed_types) {
+ for (const StringName &E : allowed_types) {
const String &t = E;
bool is_custom_resource = false;
@@ -561,53 +555,44 @@ String EditorResourcePicker::_get_resource_type(const Ref<Resource> &p_resource)
return res_type;
}
-void EditorResourcePicker::_get_allowed_types(bool p_with_convert, HashSet<String> *p_vector) const {
- Vector<String> allowed_types = base_type.split(",");
- int size = allowed_types.size();
+static void _add_allowed_type(const StringName &p_type, HashSet<StringName> *p_vector) {
+ if (p_vector->has(p_type)) {
+ // Already added
+ return;
+ }
- List<StringName> global_classes;
- ScriptServer::get_global_class_list(&global_classes);
+ if (ClassDB::class_exists(p_type)) {
+ // Engine class,
- for (int i = 0; i < size; i++) {
- String base = allowed_types[i].strip_edges();
- if (!ClassDB::is_virtual(base)) {
- p_vector->insert(base);
+ if (!ClassDB::is_virtual(p_type)) {
+ p_vector->insert(p_type);
}
- // If we hit a familiar base type, take all the data from cache.
- if (allowed_types_cache.has(base)) {
- List<StringName> allowed_subtypes = allowed_types_cache[base];
- for (const StringName &subtype_name : allowed_subtypes) {
- if (!ClassDB::is_virtual(subtype_name)) {
- p_vector->insert(subtype_name);
- }
- }
- } else {
- List<StringName> allowed_subtypes;
+ List<StringName> inheriters;
+ ClassDB::get_inheriters_from_class(p_type, &inheriters);
+ for (const StringName &S : inheriters) {
+ _add_allowed_type(S, p_vector);
+ }
+ } else {
+ // Script class.
+ p_vector->insert(p_type);
+ }
- List<StringName> inheriters;
- if (!ScriptServer::is_global_class(base)) {
- ClassDB::get_inheriters_from_class(base, &inheriters);
- }
- for (const StringName &subtype_name : inheriters) {
- if (!ClassDB::is_virtual(subtype_name)) {
- p_vector->insert(subtype_name);
- }
- allowed_subtypes.push_back(subtype_name);
- }
+ List<StringName> inheriters;
+ ScriptServer::get_inheriters_list(p_type, &inheriters);
+ for (const StringName &S : inheriters) {
+ _add_allowed_type(S, p_vector);
+ }
+}
- for (const StringName &subtype_name : global_classes) {
- if (EditorNode::get_editor_data().script_class_is_parent(subtype_name, base)) {
- if (!ClassDB::is_virtual(subtype_name)) {
- p_vector->insert(subtype_name);
- }
- allowed_subtypes.push_back(subtype_name);
- }
- }
+void EditorResourcePicker::_get_allowed_types(bool p_with_convert, HashSet<StringName> *p_vector) const {
+ Vector<String> allowed_types = base_type.split(",");
+ int size = allowed_types.size();
- // Store the subtypes of the base type in the cache for future use.
- allowed_types_cache[base] = allowed_subtypes;
- }
+ for (int i = 0; i < size; i++) {
+ String base = allowed_types[i].strip_edges();
+
+ _add_allowed_type(base, p_vector);
if (p_with_convert) {
if (base == "BaseMaterial3D") {
@@ -619,14 +604,6 @@ void EditorResourcePicker::_get_allowed_types(bool p_with_convert, HashSet<Strin
}
}
}
-
- if (EditorNode::get_editor_data().get_custom_types().has("Resource")) {
- Vector<EditorData::CustomType> custom_resources = EditorNode::get_editor_data().get_custom_types()["Resource"];
-
- for (int i = 0; i < custom_resources.size(); i++) {
- p_vector->insert(custom_resources[i].name);
- }
- }
}
bool EditorResourcePicker::_is_drop_valid(const Dictionary &p_drag_data) const {
@@ -654,7 +631,7 @@ bool EditorResourcePicker::_is_drop_valid(const Dictionary &p_drag_data) const {
}
}
- HashSet<String> allowed_types;
+ HashSet<StringName> allowed_types;
_get_allowed_types(true, &allowed_types);
if (res.is_valid()) {
@@ -673,9 +650,9 @@ bool EditorResourcePicker::_is_drop_valid(const Dictionary &p_drag_data) const {
return false;
}
-bool EditorResourcePicker::_is_type_valid(const String p_type_name, HashSet<String> p_allowed_types) const {
- for (const String &E : p_allowed_types) {
- String at = E.strip_edges();
+bool EditorResourcePicker::_is_type_valid(const String p_type_name, HashSet<StringName> p_allowed_types) const {
+ for (const StringName &E : p_allowed_types) {
+ String at = E;
if (p_type_name == at || ClassDB::is_parent_class(p_type_name, at) || EditorNode::get_editor_data().script_class_is_parent(p_type_name, at)) {
return true;
}
@@ -721,15 +698,15 @@ void EditorResourcePicker::drop_data_fw(const Point2 &p_point, const Variant &p_
}
if (dropped_resource.is_valid()) {
- HashSet<String> allowed_types;
+ HashSet<StringName> allowed_types;
_get_allowed_types(false, &allowed_types);
String res_type = _get_resource_type(dropped_resource);
// If the accepted dropped resource is from the extended list, it requires conversion.
if (!_is_type_valid(res_type, allowed_types)) {
- for (const String &E : allowed_types) {
- String at = E.strip_edges();
+ for (const StringName &E : allowed_types) {
+ String at = E;
if (at == "BaseMaterial3D" && Ref<Texture2D>(dropped_resource).is_valid()) {
// Use existing resource if possible and only replace its data.
@@ -832,7 +809,7 @@ void EditorResourcePicker::set_base_type(const String &p_base_type) {
// There is a possibility that the new base type is conflicting with the existing value.
// Keep the value, but warn the user that there is a potential mistake.
if (!base_type.is_empty() && edited_resource.is_valid()) {
- HashSet<String> allowed_types;
+ HashSet<StringName> allowed_types;
_get_allowed_types(true, &allowed_types);
StringName custom_class;
@@ -846,10 +823,6 @@ void EditorResourcePicker::set_base_type(const String &p_base_type) {
String class_str = (custom_class == StringName() ? edited_resource->get_class() : vformat("%s (%s)", custom_class, edited_resource->get_class()));
WARN_PRINT(vformat("Value mismatch between the new base type of this EditorResourcePicker, '%s', and the type of the value it already has, '%s'.", base_type, class_str));
}
- } else {
- // Call the method to build the cache immediately.
- HashSet<String> allowed_types;
- _get_allowed_types(false, &allowed_types);
}
}
@@ -858,7 +831,7 @@ String EditorResourcePicker::get_base_type() const {
}
Vector<String> EditorResourcePicker::get_allowed_types() const {
- HashSet<String> allowed_types;
+ HashSet<StringName> allowed_types;
_get_allowed_types(false, &allowed_types);
Vector<String> types;
@@ -866,7 +839,7 @@ Vector<String> EditorResourcePicker::get_allowed_types() const {
int i = 0;
String *w = types.ptrw();
- for (const String &E : allowed_types) {
+ for (const StringName &E : allowed_types) {
w[i] = E;
i++;
}
@@ -882,7 +855,7 @@ void EditorResourcePicker::set_edited_resource(Ref<Resource> p_resource) {
}
if (!base_type.is_empty()) {
- HashSet<String> allowed_types;
+ HashSet<StringName> allowed_types;
_get_allowed_types(true, &allowed_types);
StringName custom_class;
diff --git a/editor/editor_resource_picker.h b/editor/editor_resource_picker.h
index 8641cb6e84..a302e24957 100644
--- a/editor/editor_resource_picker.h
+++ b/editor/editor_resource_picker.h
@@ -42,8 +42,6 @@ class EditorQuickOpen;
class EditorResourcePicker : public HBoxContainer {
GDCLASS(EditorResourcePicker, HBoxContainer);
- static HashMap<StringName, List<StringName>> allowed_types_cache;
-
String base_type;
Ref<Resource> edited_resource;
@@ -92,9 +90,9 @@ class EditorResourcePicker : public HBoxContainer {
void _button_input(const Ref<InputEvent> &p_event);
String _get_resource_type(const Ref<Resource> &p_resource) const;
- void _get_allowed_types(bool p_with_convert, HashSet<String> *p_vector) const;
+ void _get_allowed_types(bool p_with_convert, HashSet<StringName> *p_vector) const;
bool _is_drop_valid(const Dictionary &p_drag_data) const;
- bool _is_type_valid(const String p_type_name, HashSet<String> p_allowed_types) const;
+ bool _is_type_valid(const String p_type_name, HashSet<StringName> p_allowed_types) const;
Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);
bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
@@ -118,8 +116,6 @@ protected:
GDVIRTUAL1R(bool, _handle_menu_selected, int)
public:
- static void clear_caches();
-
void set_base_type(const String &p_base_type);
String get_base_type() const;
Vector<String> get_allowed_types() const;
diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp
index 8ca98e6f76..4879790b74 100644
--- a/editor/editor_settings.cpp
+++ b/editor/editor_settings.cpp
@@ -473,6 +473,12 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
/* Filesystem */
+ // External Programs
+ EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_GLOBAL_DIR, "filesystem/external_programs/raster_image_editor", "", "")
+ EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_GLOBAL_DIR, "filesystem/external_programs/vector_image_editor", "", "")
+ EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_GLOBAL_DIR, "filesystem/external_programs/audio_editor", "", "")
+ EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_GLOBAL_DIR, "filesystem/external_programs/3d_model_editor", "", "")
+
// Directories
EDITOR_SETTING(Variant::STRING, PROPERTY_HINT_GLOBAL_DIR, "filesystem/directories/autoscan_project_path", "", "")
const String fs_dir_default_project_path = OS::get_singleton()->has_environment("HOME") ? OS::get_singleton()->get_environment("HOME") : OS::get_singleton()->get_system_dir(OS::SYSTEM_DIR_DOCUMENTS);
diff --git a/editor/editor_toaster.cpp b/editor/editor_toaster.cpp
index 558423df78..43f2c4e74e 100644
--- a/editor/editor_toaster.cpp
+++ b/editor/editor_toaster.cpp
@@ -230,10 +230,10 @@ void EditorToaster::_auto_hide_or_free_toasts() {
}
// Delete the control right away (removed as child) as it might cause issues otherwise when iterative over the vbox_container children.
- for (unsigned int i = 0; i < to_delete.size(); i++) {
- vbox_container->remove_child(to_delete[i]);
- to_delete[i]->queue_free();
- toasts.erase(to_delete[i]);
+ for (Control *c : to_delete) {
+ vbox_container->remove_child(c);
+ c->queue_free();
+ toasts.erase(c);
}
if (toasts.is_empty()) {
diff --git a/editor/export/editor_export_platform.cpp b/editor/export/editor_export_platform.cpp
index cacd181ad8..8da52e20f7 100644
--- a/editor/export/editor_export_platform.cpp
+++ b/editor/export/editor_export_platform.cpp
@@ -503,8 +503,8 @@ bool EditorExportPlatform::_export_customize_dictionary(Dictionary &dict, LocalV
case Variant::OBJECT: {
Ref<Resource> res = v;
if (res.is_valid()) {
- for (uint32_t j = 0; j < customize_resources_plugins.size(); j++) {
- Ref<Resource> new_res = customize_resources_plugins[j]->_customize_resource(res, "");
+ for (Ref<EditorExportPlugin> &plugin : customize_resources_plugins) {
+ Ref<Resource> new_res = plugin->_customize_resource(res, "");
if (new_res.is_valid()) {
changed = true;
if (new_res != res) {
@@ -550,8 +550,8 @@ bool EditorExportPlatform::_export_customize_array(Array &arr, LocalVector<Ref<E
case Variant::OBJECT: {
Ref<Resource> res = v;
if (res.is_valid()) {
- for (uint32_t j = 0; j < customize_resources_plugins.size(); j++) {
- Ref<Resource> new_res = customize_resources_plugins[j]->_customize_resource(res, "");
+ for (Ref<EditorExportPlugin> &plugin : customize_resources_plugins) {
+ Ref<Resource> new_res = plugin->_customize_resource(res, "");
if (new_res.is_valid()) {
changed = true;
if (new_res != res) {
@@ -597,8 +597,8 @@ bool EditorExportPlatform::_export_customize_object(Object *p_object, LocalVecto
case Variant::OBJECT: {
Ref<Resource> res = p_object->get(E.name);
if (res.is_valid()) {
- for (uint32_t j = 0; j < customize_resources_plugins.size(); j++) {
- Ref<Resource> new_res = customize_resources_plugins[j]->_customize_resource(res, "");
+ for (Ref<EditorExportPlugin> &plugin : customize_resources_plugins) {
+ Ref<Resource> new_res = plugin->_customize_resource(res, "");
if (new_res.is_valid()) {
changed = true;
if (new_res != res) {
@@ -715,16 +715,16 @@ String EditorExportPlatform::_export_customize(const String &p_path, LocalVector
ERR_FAIL_COND_V(ps.is_null(), p_path);
Node *node = ps->instantiate(PackedScene::GEN_EDIT_STATE_INSTANCE); // Make sure the child scene root gets the correct inheritance chain.
ERR_FAIL_COND_V(node == nullptr, p_path);
- if (customize_scenes_plugins.size()) {
- for (uint32_t i = 0; i < customize_scenes_plugins.size(); i++) {
- Node *customized = customize_scenes_plugins[i]->_customize_scene(node, p_path);
+ if (!customize_scenes_plugins.is_empty()) {
+ for (Ref<EditorExportPlugin> &plugin : customize_scenes_plugins) {
+ Node *customized = plugin->_customize_scene(node, p_path);
if (customized != nullptr) {
node = customized;
modified = true;
}
}
}
- if (customize_resources_plugins.size()) {
+ if (!customize_resources_plugins.is_empty()) {
if (_export_customize_scene_resources(node, node, customize_resources_plugins)) {
modified = true;
}
@@ -746,9 +746,9 @@ String EditorExportPlatform::_export_customize(const String &p_path, LocalVector
Ref<Resource> res = ResourceLoader::load(p_path, "", ResourceFormatLoader::CACHE_MODE_IGNORE);
ERR_FAIL_COND_V(res.is_null(), p_path);
- if (customize_resources_plugins.size()) {
- for (uint32_t i = 0; i < customize_resources_plugins.size(); i++) {
- Ref<Resource> new_res = customize_resources_plugins[i]->_customize_resource(res, p_path);
+ if (!customize_resources_plugins.is_empty()) {
+ for (Ref<EditorExportPlugin> &plugin : customize_resources_plugins) {
+ Ref<Resource> new_res = plugin->_customize_resource(res, p_path);
if (new_res.is_valid()) {
modified = true;
if (new_res != res) {
@@ -960,7 +960,7 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &
bool convert_text_to_binary = GLOBAL_GET("editor/export/convert_text_resources_to_binary");
- if (convert_text_to_binary || customize_resources_plugins.size() || customize_scenes_plugins.size()) {
+ if (convert_text_to_binary || !customize_resources_plugins.is_empty() || !customize_scenes_plugins.is_empty()) {
// See if we have something to open
Ref<FileAccess> f = FileAccess::open(export_base_path.path_join("file_cache"), FileAccess::READ);
if (f.is_valid()) {
@@ -1179,7 +1179,7 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &
idx++;
}
- if (convert_text_to_binary || customize_resources_plugins.size() || customize_scenes_plugins.size()) {
+ if (convert_text_to_binary || !customize_resources_plugins.is_empty() || !customize_scenes_plugins.is_empty()) {
// End scene customization
String fcache = export_base_path.path_join("file_cache");
@@ -1196,12 +1196,12 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &
ERR_PRINT("Error opening export file cache: " + fcache);
}
- for (uint32_t i = 0; i < customize_resources_plugins.size(); i++) {
- customize_resources_plugins[i]->_end_customize_resources();
+ for (Ref<EditorExportPlugin> &plugin : customize_resources_plugins) {
+ plugin->_end_customize_resources();
}
- for (uint32_t i = 0; i < customize_scenes_plugins.size(); i++) {
- customize_scenes_plugins[i]->_end_customize_scenes();
+ for (Ref<EditorExportPlugin> &plugin : customize_scenes_plugins) {
+ plugin->_end_customize_scenes();
}
}
//save config!
diff --git a/editor/export/editor_export_plugin.cpp b/editor/export/editor_export_plugin.cpp
index 784dbc116a..dfd4520eec 100644
--- a/editor/export/editor_export_plugin.cpp
+++ b/editor/export/editor_export_plugin.cpp
@@ -227,8 +227,6 @@ void EditorExportPlugin::_bind_methods() {
}
EditorExportPlugin::EditorExportPlugin() {
- GLOBAL_DEF("editor/export/convert_text_resources_to_binary", false);
-
EDITOR_DEF("export/ssh/ssh", "");
EDITOR_DEF("export/ssh/scp", "");
}
diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp
index f1ea8e8e65..f41792af7f 100644
--- a/editor/filesystem_dock.cpp
+++ b/editor/filesystem_dock.cpp
@@ -1819,6 +1819,43 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected
OS::get_singleton()->shell_open(String("file://") + dir);
} break;
+ case FILE_OPEN_EXTERNAL: {
+ String fpath = path;
+ if (path == "Favorites") {
+ fpath = p_selected[0];
+ }
+
+ String file = ProjectSettings::get_singleton()->globalize_path(fpath);
+
+ String resource_type = ResourceLoader::get_resource_type(fpath);
+ String external_program;
+
+ if (resource_type == "CompressedTexture2D" || resource_type == "Image") {
+ if (file.get_extension() == "svg" || file.get_extension() == "svgz") {
+ external_program = EDITOR_GET("filesystem/external_programs/vector_image_editor");
+ } else {
+ external_program = EDITOR_GET("filesystem/external_programs/raster_image_editor");
+ }
+ } else if (ClassDB::is_parent_class(resource_type, "AudioStream")) {
+ external_program = EDITOR_GET("filesystem/external_programs/audio_editor");
+ } else if (resource_type == "PackedScene") {
+ // Ignore non-model scenes.
+ if (file.get_extension() != "tscn" && file.get_extension() != "scn" && file.get_extension() != "res") {
+ external_program = EDITOR_GET("filesystem/external_programs/3d_model_editor");
+ }
+ } else if (ClassDB::is_parent_class(resource_type, "Script")) {
+ external_program = EDITOR_GET("text_editor/external/exec_path");
+ }
+
+ if (external_program.is_empty()) {
+ OS::get_singleton()->shell_open(file);
+ } else {
+ List<String> args;
+ args.push_back(file);
+ OS::get_singleton()->create_process(external_program, args);
+ }
+ } break;
+
case FILE_OPEN: {
// Open folders.
TreeItem *selected = tree->get_root();
@@ -2606,9 +2643,13 @@ void FileSystemDock::_file_and_folders_fill_popup(PopupMenu *p_popup, Vector<Str
}
String fpath = p_paths[0];
- String item_text = fpath.ends_with("/") ? TTR("Open in File Manager") : TTR("Show in File Manager");
+ bool is_directory = fpath.ends_with("/");
+ String item_text = is_directory ? TTR("Open in File Manager") : TTR("Show in File Manager");
p_popup->add_icon_shortcut(get_theme_icon(SNAME("Filesystem"), SNAME("EditorIcons")), ED_GET_SHORTCUT("filesystem_dock/show_in_explorer"), FILE_SHOW_IN_EXPLORER);
p_popup->set_item_text(p_popup->get_item_index(FILE_SHOW_IN_EXPLORER), item_text);
+ if (!is_directory) {
+ p_popup->add_icon_item(get_theme_icon(SNAME("ExternalLink"), SNAME("EditorIcons")), TTR("Open in External Program"), FILE_OPEN_EXTERNAL);
+ }
path = fpath;
}
}
@@ -2714,6 +2755,7 @@ void FileSystemDock::_file_list_empty_clicked(const Vector2 &p_pos, MouseButton
file_list_popup->add_icon_item(get_theme_icon(SNAME("TextFile"), SNAME("EditorIcons")), TTR("New TextFile..."), FILE_NEW_TEXTFILE);
file_list_popup->add_separator();
file_list_popup->add_icon_shortcut(get_theme_icon(SNAME("Filesystem"), SNAME("EditorIcons")), ED_GET_SHORTCUT("filesystem_dock/show_in_explorer"), FILE_SHOW_IN_EXPLORER);
+
file_list_popup->set_position(files->get_screen_position() + p_pos);
file_list_popup->reset_size();
file_list_popup->popup();
diff --git a/editor/filesystem_dock.h b/editor/filesystem_dock.h
index 2304d8f8ad..3f12b73043 100644
--- a/editor/filesystem_dock.h
+++ b/editor/filesystem_dock.h
@@ -94,6 +94,7 @@ private:
FILE_NEW_SCRIPT,
FILE_NEW_SCENE,
FILE_SHOW_IN_EXPLORER,
+ FILE_OPEN_EXTERNAL,
FILE_COPY_PATH,
FILE_COPY_UID,
FILE_NEW_RESOURCE,
diff --git a/editor/inspector_dock.cpp b/editor/inspector_dock.cpp
index b28373e308..52482ecb16 100644
--- a/editor/inspector_dock.cpp
+++ b/editor/inspector_dock.cpp
@@ -189,8 +189,7 @@ void InspectorDock::_menu_option_confirm(int p_option, bool p_confirmed) {
int history_id = EditorUndoRedoManager::get_singleton()->get_history_for_object(current).id;
EditorUndoRedoManager::get_singleton()->clear_history(true, history_id);
- EditorNode::get_singleton()->get_editor_plugins_over()->edit(nullptr);
- EditorNode::get_singleton()->get_editor_plugins_over()->edit(current);
+ EditorNode::get_singleton()->edit_item(current, inspector);
}
} break;
diff --git a/editor/multi_node_edit.cpp b/editor/multi_node_edit.cpp
index 2a55ac949f..4f0db70681 100644
--- a/editor/multi_node_edit.cpp
+++ b/editor/multi_node_edit.cpp
@@ -48,6 +48,8 @@ bool MultiNodeEdit::_set_impl(const StringName &p_name, const Variant &p_value,
if (name == "scripts") { // Script set is intercepted at object level (check Variant Object::get()), so use a different name.
name = "script";
+ } else if (name.begins_with("Metadata/")) {
+ name = name.replace_first("Metadata/", "metadata/");
}
Node *node_path_target = nullptr;
@@ -98,6 +100,8 @@ bool MultiNodeEdit::_get(const StringName &p_name, Variant &r_ret) const {
String name = p_name;
if (name == "scripts") { // Script set is intercepted at object level (check Variant Object::get()), so use a different name.
name = "script";
+ } else if (name.begins_with("Metadata/")) {
+ name = name.replace_first("Metadata/", "metadata/");
}
for (const NodePath &E : nodes) {
@@ -137,14 +141,18 @@ void MultiNodeEdit::_get_property_list(List<PropertyInfo> *p_list) const {
List<PropertyInfo> plist;
n->get_property_list(&plist, true);
- for (const PropertyInfo &F : plist) {
+ for (PropertyInfo F : plist) {
if (F.name == "script") {
continue; // Added later manually, since this is intercepted before being set (check Variant Object::get()).
+ } else if (F.name.begins_with("metadata/")) {
+ F.name = F.name.replace_first("metadata/", "Metadata/"); // Trick to not get actual metadata edited from MultiNodeEdit.
}
+
if (!usage.has(F.name)) {
PLData pld;
pld.uses = 0;
pld.info = F;
+ pld.info.name = F.name;
usage[F.name] = pld;
data_list.push_back(usage.getptr(F.name));
}
diff --git a/editor/plugins/animation_state_machine_editor.cpp b/editor/plugins/animation_state_machine_editor.cpp
index a675495429..c0972d201e 100644
--- a/editor/plugins/animation_state_machine_editor.cpp
+++ b/editor/plugins/animation_state_machine_editor.cpp
@@ -1237,7 +1237,7 @@ void AnimationNodeStateMachineEditor::_state_machine_draw() {
if (playback.is_valid()) {
playing = playback->is_playing();
current = playback->get_current_node();
- blend_from = playback->get_blend_from_node();
+ blend_from = playback->get_fading_from_node();
travel_path = playback->get_travel_path();
}
@@ -1695,7 +1695,7 @@ void AnimationNodeStateMachineEditor::_notification(int p_what) {
tp = playback->get_travel_path();
is_playing = playback->is_playing();
current_node = playback->get_current_node();
- blend_from_node = playback->get_blend_from_node();
+ blend_from_node = playback->get_fading_from_node();
play_pos = playback->get_current_play_pos();
current_length = playback->get_current_length();
}
diff --git a/editor/plugins/bone_map_editor_plugin.cpp b/editor/plugins/bone_map_editor_plugin.cpp
index c913a9b0ab..3d94dd13a7 100644
--- a/editor/plugins/bone_map_editor_plugin.cpp
+++ b/editor/plugins/bone_map_editor_plugin.cpp
@@ -566,9 +566,9 @@ int BoneMapper::search_bone_by_name(Skeleton3D *p_skeleton, Vector<String> p_pic
if (hit_list.size() > 0) {
shortest = hit_list[0];
- for (uint32_t i = 0; i < hit_list.size(); i++) {
- if (hit_list[i].length() < shortest.length()) {
- shortest = hit_list[i]; // Prioritize parent.
+ for (const String &hit : hit_list) {
+ if (hit.length() < shortest.length()) {
+ shortest = hit; // Prioritize parent.
}
}
}
@@ -592,9 +592,9 @@ int BoneMapper::search_bone_by_name(Skeleton3D *p_skeleton, Vector<String> p_pic
if (hit_list.size() > 0) {
shortest = hit_list[0];
- for (uint32_t i = 0; i < hit_list.size(); i++) {
- if (hit_list[i].length() <= shortest.length()) {
- shortest = hit_list[i]; // Prioritize parent.
+ for (const String &hit : hit_list) {
+ if (hit.length() <= shortest.length()) {
+ shortest = hit; // Prioritize parent.
}
}
}
diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp
index dea07ab50c..f1b7ed73b8 100644
--- a/editor/plugins/node_3d_editor_plugin.cpp
+++ b/editor/plugins/node_3d_editor_plugin.cpp
@@ -2208,11 +2208,6 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
if (ED_IS_SHORTCUT("spatial_editor/focus_selection", p_event)) {
_menu_option(VIEW_CENTER_TO_SELECTION);
}
- // Orthgonal mode doesn't work in freelook.
- if (!freelook_active && ED_IS_SHORTCUT("spatial_editor/switch_perspective_orthogonal", p_event)) {
- _menu_option(orthogonal ? VIEW_PERSPECTIVE : VIEW_ORTHOGONAL);
- _update_name();
- }
if (ED_IS_SHORTCUT("spatial_editor/align_transform_with_view", p_event)) {
_menu_option(VIEW_ALIGN_TRANSFORM_WITH_VIEW);
}
@@ -3279,6 +3274,10 @@ void Node3DEditorViewport::_menu_option(int p_option) {
_update_name();
} break;
+ case VIEW_SWITCH_PERSPECTIVE_ORTHOGONAL: {
+ _menu_option(orthogonal ? VIEW_PERSPECTIVE : VIEW_ORTHOGONAL);
+
+ } break;
case VIEW_AUTO_ORTHOGONAL: {
int idx = view_menu->get_popup()->get_item_index(VIEW_AUTO_ORTHOGONAL);
bool current = view_menu->get_popup()->is_item_checked(idx);
@@ -4952,8 +4951,9 @@ Node3DEditorViewport::Node3DEditorViewport(Node3DEditor *p_spatial_editor, int p
view_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("spatial_editor/front_view"), VIEW_FRONT);
view_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("spatial_editor/rear_view"), VIEW_REAR);
view_menu->get_popup()->add_separator();
- view_menu->get_popup()->add_radio_check_item(TTR("Perspective") + " (" + ED_GET_SHORTCUT("spatial_editor/switch_perspective_orthogonal")->get_as_text() + ")", VIEW_PERSPECTIVE);
- view_menu->get_popup()->add_radio_check_item(TTR("Orthogonal") + " (" + ED_GET_SHORTCUT("spatial_editor/switch_perspective_orthogonal")->get_as_text() + ")", VIEW_ORTHOGONAL);
+ view_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("spatial_editor/switch_perspective_orthogonal"), VIEW_SWITCH_PERSPECTIVE_ORTHOGONAL);
+ view_menu->get_popup()->add_radio_check_item(TTR("Perspective"), VIEW_PERSPECTIVE);
+ view_menu->get_popup()->add_radio_check_item(TTR("Orthogonal"), VIEW_ORTHOGONAL);
view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_PERSPECTIVE), true);
view_menu->get_popup()->add_check_item(TTR("Auto Orthogonal Enabled"), VIEW_AUTO_ORTHOGONAL);
view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_AUTO_ORTHOGONAL), true);
diff --git a/editor/plugins/node_3d_editor_plugin.h b/editor/plugins/node_3d_editor_plugin.h
index edc09f115a..a1fd9757d0 100644
--- a/editor/plugins/node_3d_editor_plugin.h
+++ b/editor/plugins/node_3d_editor_plugin.h
@@ -117,6 +117,7 @@ class Node3DEditorViewport : public Control {
VIEW_PERSPECTIVE,
VIEW_ENVIRONMENT,
VIEW_ORTHOGONAL,
+ VIEW_SWITCH_PERSPECTIVE_ORTHOGONAL,
VIEW_HALF_RESOLUTION,
VIEW_AUDIO_LISTENER,
VIEW_AUDIO_DOPPLER,
diff --git a/editor/plugins/shader_editor_plugin.cpp b/editor/plugins/shader_editor_plugin.cpp
index 87d602ccf1..907bc81674 100644
--- a/editor/plugins/shader_editor_plugin.cpp
+++ b/editor/plugins/shader_editor_plugin.cpp
@@ -43,10 +43,10 @@
void ShaderEditorPlugin::_update_shader_list() {
shader_list->clear();
- for (uint32_t i = 0; i < edited_shaders.size(); i++) {
- Ref<Resource> shader = edited_shaders[i].shader;
+ for (EditedShader &edited_shader : edited_shaders) {
+ Ref<Resource> shader = edited_shader.shader;
if (shader.is_null()) {
- shader = edited_shaders[i].shader_inc;
+ shader = edited_shader.shader_inc;
}
String path = shader->get_path();
@@ -62,8 +62,8 @@ void ShaderEditorPlugin::_update_shader_list() {
}
bool unsaved = false;
- if (edited_shaders[i].shader_editor) {
- unsaved = edited_shaders[i].shader_editor->is_unsaved();
+ if (edited_shader.shader_editor) {
+ unsaved = edited_shader.shader_editor->is_unsaved();
}
// TODO: Handle visual shaders too.
@@ -86,7 +86,7 @@ void ShaderEditorPlugin::_update_shader_list() {
}
for (int i = FILE_SAVE; i < FILE_MAX; i++) {
- file_menu->get_popup()->set_item_disabled(file_menu->get_popup()->get_item_index(i), edited_shaders.size() == 0);
+ file_menu->get_popup()->set_item_disabled(file_menu->get_popup()->get_item_index(i), edited_shaders.is_empty());
}
_update_shader_list_status();
@@ -117,6 +117,10 @@ void ShaderEditorPlugin::_move_shader_tab(int p_from, int p_to) {
}
void ShaderEditorPlugin::edit(Object *p_object) {
+ if (!p_object) {
+ return;
+ }
+
EditedShader es;
ShaderInclude *si = Object::cast_to<ShaderInclude>(p_object);
@@ -175,36 +179,36 @@ void ShaderEditorPlugin::selected_notify() {
}
TextShaderEditor *ShaderEditorPlugin::get_shader_editor(const Ref<Shader> &p_for_shader) {
- for (uint32_t i = 0; i < edited_shaders.size(); i++) {
- if (edited_shaders[i].shader == p_for_shader) {
- return edited_shaders[i].shader_editor;
+ for (EditedShader &edited_shader : edited_shaders) {
+ if (edited_shader.shader == p_for_shader) {
+ return edited_shader.shader_editor;
}
}
return nullptr;
}
VisualShaderEditor *ShaderEditorPlugin::get_visual_shader_editor(const Ref<Shader> &p_for_shader) {
- for (uint32_t i = 0; i < edited_shaders.size(); i++) {
- if (edited_shaders[i].shader == p_for_shader) {
- return edited_shaders[i].visual_shader_editor;
+ for (EditedShader &edited_shader : edited_shaders) {
+ if (edited_shader.shader == p_for_shader) {
+ return edited_shader.visual_shader_editor;
}
}
return nullptr;
}
void ShaderEditorPlugin::save_external_data() {
- for (uint32_t i = 0; i < edited_shaders.size(); i++) {
- if (edited_shaders[i].shader_editor) {
- edited_shaders[i].shader_editor->save_external_data();
+ for (EditedShader &edited_shader : edited_shaders) {
+ if (edited_shader.shader_editor) {
+ edited_shader.shader_editor->save_external_data();
}
}
_update_shader_list();
}
void ShaderEditorPlugin::apply_changes() {
- for (uint32_t i = 0; i < edited_shaders.size(); i++) {
- if (edited_shaders[i].shader_editor) {
- edited_shaders[i].shader_editor->apply_shaders();
+ for (EditedShader &edited_shader : edited_shaders) {
+ if (edited_shader.shader_editor) {
+ edited_shader.shader_editor->apply_shaders();
}
}
}
@@ -234,8 +238,8 @@ void ShaderEditorPlugin::_close_shader(int p_index) {
void ShaderEditorPlugin::_resource_saved(Object *obj) {
// May have been renamed on save.
- for (uint32_t i = 0; i < edited_shaders.size(); i++) {
- if (edited_shaders[i].shader.ptr() == obj) {
+ for (EditedShader &edited_shader : edited_shaders) {
+ if (edited_shader.shader.ptr() == obj) {
_update_shader_list();
return;
}
diff --git a/editor/plugins/tiles/tile_data_editors.cpp b/editor/plugins/tiles/tile_data_editors.cpp
index 81aa9bf272..1a4223e9e6 100644
--- a/editor/plugins/tiles/tile_data_editors.cpp
+++ b/editor/plugins/tiles/tile_data_editors.cpp
@@ -169,8 +169,7 @@ void GenericTilePolygonEditor::_base_control_draw() {
}
// Draw the polygons.
- for (unsigned int i = 0; i < polygons.size(); i++) {
- const Vector<Vector2> &polygon = polygons[i];
+ for (const Vector<Vector2> &polygon : polygons) {
Color color = polygon_color;
if (!in_creation_polygon.is_empty()) {
color = color.darkened(0.3);
@@ -285,8 +284,8 @@ void GenericTilePolygonEditor::_advanced_menu_item_pressed(int p_item_pressed) {
undo_redo->add_do_method(base_control, "queue_redraw");
undo_redo->add_do_method(this, "emit_signal", "polygons_changed");
undo_redo->add_undo_method(this, "clear_polygons");
- for (unsigned int i = 0; i < polygons.size(); i++) {
- undo_redo->add_undo_method(this, "add_polygon", polygons[i]);
+ for (const PackedVector2Array &poly : polygons) {
+ undo_redo->add_undo_method(this, "add_polygon", poly);
}
undo_redo->add_undo_method(base_control, "queue_redraw");
undo_redo->add_undo_method(this, "emit_signal", "polygons_changed");
@@ -298,8 +297,8 @@ void GenericTilePolygonEditor::_advanced_menu_item_pressed(int p_item_pressed) {
undo_redo->add_do_method(base_control, "queue_redraw");
undo_redo->add_do_method(this, "emit_signal", "polygons_changed");
undo_redo->add_undo_method(this, "clear_polygons");
- for (unsigned int i = 0; i < polygons.size(); i++) {
- undo_redo->add_undo_method(this, "add_polygon", polygons[i]);
+ for (const PackedVector2Array &polygon : polygons) {
+ undo_redo->add_undo_method(this, "add_polygon", polygon);
}
undo_redo->add_undo_method(base_control, "queue_redraw");
undo_redo->add_undo_method(this, "emit_signal", "polygons_changed");
@@ -327,8 +326,8 @@ void GenericTilePolygonEditor::_advanced_menu_item_pressed(int p_item_pressed) {
}
for (unsigned int i = 0; i < polygons.size(); i++) {
Vector<Point2> new_polygon;
- for (int point_index = 0; point_index < polygons[i].size(); point_index++) {
- Vector2 point = polygons[i][point_index];
+ for (const Vector2 &vec : polygons[i]) {
+ Vector2 point = vec;
switch (p_item_pressed) {
case ROTATE_RIGHT: {
point = Vector2(-point.y, point.x);
@@ -351,8 +350,8 @@ void GenericTilePolygonEditor::_advanced_menu_item_pressed(int p_item_pressed) {
}
undo_redo->add_do_method(base_control, "queue_redraw");
undo_redo->add_do_method(this, "emit_signal", "polygons_changed");
- for (unsigned int i = 0; i < polygons.size(); i++) {
- undo_redo->add_undo_method(this, "set_polygon", polygons[i]);
+ for (const PackedVector2Array &polygon : polygons) {
+ undo_redo->add_undo_method(this, "set_polygon", polygon);
}
undo_redo->add_undo_method(base_control, "queue_redraw");
undo_redo->add_undo_method(this, "emit_signal", "polygons_changed");
diff --git a/editor/plugins/tiles/tile_map_editor.cpp b/editor/plugins/tiles/tile_map_editor.cpp
index 885d41b8da..2394130ad6 100644
--- a/editor/plugins/tiles/tile_map_editor.cpp
+++ b/editor/plugins/tiles/tile_map_editor.cpp
@@ -922,7 +922,7 @@ void TileMapEditorTilesPlugin::forward_canvas_draw_over_viewport(Control *p_over
// Get the tile modulation.
Color modulate = tile_data->get_modulate();
- Color self_modulate = tile_map->get_self_modulate();
+ Color self_modulate = tile_map->get_modulate_in_tree() * tile_map->get_self_modulate();
modulate *= self_modulate;
modulate *= tile_map->get_layer_modulate(tile_map_layer);
@@ -3088,8 +3088,8 @@ void TileMapEditorTerrainsPlugin::_update_terrains_cache() {
per_terrain_terrains_patterns.resize(tile_set->get_terrain_sets_count());
for (int i = 0; i < tile_set->get_terrain_sets_count(); i++) {
per_terrain_terrains_patterns[i].resize(tile_set->get_terrains_count(i));
- for (int j = 0; j < (int)per_terrain_terrains_patterns[i].size(); j++) {
- per_terrain_terrains_patterns[i][j].clear();
+ for (RBSet<TileSet::TerrainsPattern> &pattern : per_terrain_terrains_patterns[i]) {
+ pattern.clear();
}
}
@@ -3519,8 +3519,8 @@ void TileMapEditor::_update_bottom_panel() {
// Update the visibility of controls.
missing_tileset_label->set_visible(!tile_set.is_valid());
- for (unsigned int tab_index = 0; tab_index < tabs_data.size(); tab_index++) {
- tabs_data[tab_index].panel->hide();
+ for (TileMapEditorPlugin::TabData &tab_data : tabs_data) {
+ tab_data.panel->hide();
}
if (tile_set.is_valid()) {
tabs_data[tabs_bar->get_current_tab()].panel->show();
@@ -3609,15 +3609,15 @@ void TileMapEditor::_tab_changed(int p_tab_id) {
tabs_plugins[tabs_bar->get_current_tab()]->edit(tile_map_id, tile_map_layer);
// Update toolbar.
- for (unsigned int tab_index = 0; tab_index < tabs_data.size(); tab_index++) {
- tabs_data[tab_index].toolbar->hide();
+ for (TileMapEditorPlugin::TabData &tab_data : tabs_data) {
+ tab_data.toolbar->hide();
}
tabs_data[p_tab_id].toolbar->show();
// Update visible panel.
TileMap *tile_map = Object::cast_to<TileMap>(ObjectDB::get_instance(tile_map_id));
- for (unsigned int tab_index = 0; tab_index < tabs_data.size(); tab_index++) {
- tabs_data[tab_index].panel->hide();
+ for (TileMapEditorPlugin::TabData &tab_data : tabs_data) {
+ tab_data.panel->hide();
}
if (tile_map && tile_map->get_tileset().is_valid()) {
tabs_data[tabs_bar->get_current_tab()].panel->show();
@@ -3994,10 +3994,10 @@ TileMapEditor::TileMapEditor() {
tile_map_toolbar->add_child(tabs_bar);
// Tabs toolbars.
- for (unsigned int tab_index = 0; tab_index < tabs_data.size(); tab_index++) {
- tabs_data[tab_index].toolbar->hide();
- if (!tabs_data[tab_index].toolbar->get_parent()) {
- tile_map_toolbar->add_child(tabs_data[tab_index].toolbar);
+ for (TileMapEditorPlugin::TabData &tab_data : tabs_data) {
+ tab_data.toolbar->hide();
+ if (!tab_data.toolbar->get_parent()) {
+ tile_map_toolbar->add_child(tab_data.toolbar);
}
}
diff --git a/editor/project_converter_3_to_4.cpp b/editor/project_converter_3_to_4.cpp
index b5dca26c63..5f61d10f9d 100644
--- a/editor/project_converter_3_to_4.cpp
+++ b/editor/project_converter_3_to_4.cpp
@@ -1977,8 +1977,8 @@ public:
}
}
~RegExContainer() {
- for (unsigned int i = 0; i < color_regexes.size(); i++) {
- memdelete(color_regexes[i]);
+ for (RegEx *regex : color_regexes) {
+ memdelete(regex);
}
for (unsigned int i = 0; i < class_tscn_regexes.size(); i++) {
memdelete(class_tscn_regexes[i]);
@@ -1986,38 +1986,38 @@ public:
memdelete(class_shader_regexes[i]);
memdelete(class_regexes[i]);
}
- for (unsigned int i = 0; i < enum_regexes.size(); i++) {
- memdelete(enum_regexes[i]);
+ for (RegEx *regex : enum_regexes) {
+ memdelete(regex);
}
- for (unsigned int i = 0; i < gdscript_function_regexes.size(); i++) {
- memdelete(gdscript_function_regexes[i]);
+ for (RegEx *regex : gdscript_function_regexes) {
+ memdelete(regex);
}
- for (unsigned int i = 0; i < project_settings_regexes.size(); i++) {
- memdelete(project_settings_regexes[i]);
+ for (RegEx *regex : project_settings_regexes) {
+ memdelete(regex);
}
- for (unsigned int i = 0; i < input_map_regexes.size(); i++) {
- memdelete(input_map_regexes[i]);
+ for (RegEx *regex : input_map_regexes) {
+ memdelete(regex);
}
- for (unsigned int i = 0; i < gdscript_properties_regexes.size(); i++) {
- memdelete(gdscript_properties_regexes[i]);
+ for (RegEx *regex : gdscript_properties_regexes) {
+ memdelete(regex);
}
- for (unsigned int i = 0; i < gdscript_signals_regexes.size(); i++) {
- memdelete(gdscript_signals_regexes[i]);
+ for (RegEx *regex : gdscript_signals_regexes) {
+ memdelete(regex);
}
- for (unsigned int i = 0; i < shaders_regexes.size(); i++) {
- memdelete(shaders_regexes[i]);
+ for (RegEx *regex : shaders_regexes) {
+ memdelete(regex);
}
- for (unsigned int i = 0; i < builtin_types_regexes.size(); i++) {
- memdelete(builtin_types_regexes[i]);
+ for (RegEx *regex : builtin_types_regexes) {
+ memdelete(regex);
}
- for (unsigned int i = 0; i < csharp_function_regexes.size(); i++) {
- memdelete(csharp_function_regexes[i]);
+ for (RegEx *regex : csharp_function_regexes) {
+ memdelete(regex);
}
- for (unsigned int i = 0; i < csharp_properties_regexes.size(); i++) {
- memdelete(csharp_properties_regexes[i]);
+ for (RegEx *regex : csharp_properties_regexes) {
+ memdelete(regex);
}
- for (unsigned int i = 0; i < csharp_signal_regexes.size(); i++) {
- memdelete(csharp_signal_regexes[i]);
+ for (RegEx *regex : csharp_signal_regexes) {
+ memdelete(regex);
}
}
};
diff --git a/editor/register_editor_types.cpp b/editor/register_editor_types.cpp
index 5f6b5aa42f..061baaff7e 100644
--- a/editor/register_editor_types.cpp
+++ b/editor/register_editor_types.cpp
@@ -219,6 +219,4 @@ void unregister_editor_types() {
if (EditorPaths::get_singleton()) {
EditorPaths::free();
}
-
- EditorResourcePicker::clear_caches();
}
diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp
index 733f140a56..c1dd9e2f6a 100644
--- a/editor/scene_tree_dock.cpp
+++ b/editor/scene_tree_dock.cpp
@@ -1428,6 +1428,9 @@ void SceneTreeDock::_script_open_request(const Ref<Script> &p_script) {
void SceneTreeDock::_push_item(Object *p_object) {
EditorNode::get_singleton()->push_item(p_object);
+ if (p_object == nullptr) {
+ EditorNode::get_singleton()->hide_unused_editors(this);
+ }
}
void SceneTreeDock::_handle_select(Node *p_node) {
@@ -2061,7 +2064,7 @@ void SceneTreeDock::_delete_confirm(bool p_cut) {
return;
}
- EditorNode::get_singleton()->get_editor_plugins_over()->make_visible(false);
+ EditorNode::get_singleton()->hide_unused_editors(this);
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
undo_redo->create_action(p_cut ? TTR("Cut Node(s)") : TTR("Remove Node(s)"), UndoRedo::MERGE_DISABLE, remove_list.front()->get());
diff --git a/main/main.cpp b/main/main.cpp
index b9cb755cbf..2326e519bf 100644
--- a/main/main.cpp
+++ b/main/main.cpp
@@ -185,6 +185,7 @@ static bool init_maximized = false;
static bool init_windowed = false;
static bool init_always_on_top = false;
static bool init_use_custom_pos = false;
+static bool init_use_custom_screen = false;
static Vector2 init_custom_pos;
// Debug
@@ -964,6 +965,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
if (I->next()) {
init_screen = I->next()->get().to_int();
+ init_use_custom_screen = true;
N = I->next()->next();
} else {
@@ -1669,7 +1671,23 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
window_flags |= DisplayServer::WINDOW_FLAG_NO_FOCUS_BIT;
}
window_mode = (DisplayServer::WindowMode)(GLOBAL_GET("display/window/size/mode").operator int());
- init_screen = GLOBAL_GET("display/window/size/initial_screen").operator int();
+ int initial_position_type = GLOBAL_GET("display/window/size/initial_position_type").operator int();
+ if (initial_position_type == 0) {
+ if (!init_use_custom_pos) {
+ init_custom_pos = GLOBAL_GET("display/window/size/initial_position").operator Vector2i();
+ init_use_custom_pos = true;
+ }
+ } else if (initial_position_type == 1) {
+ if (!init_use_custom_screen) {
+ init_screen = DisplayServer::SCREEN_PRIMARY;
+ init_use_custom_screen = true;
+ }
+ } else if (initial_position_type == 2) {
+ if (!init_use_custom_screen) {
+ init_screen = GLOBAL_GET("display/window/size/initial_screen").operator int();
+ init_use_custom_screen = true;
+ }
+ }
}
GLOBAL_DEF("internationalization/locale/include_text_server_data", false);
@@ -3175,10 +3193,12 @@ bool Main::iteration() {
auto_build_solutions = false;
// Only relevant when running the editor.
if (!editor) {
+ OS::get_singleton()->set_exit_code(EXIT_FAILURE);
ERR_FAIL_V_MSG(true,
"Command line option --build-solutions was passed, but no project is being edited. Aborting.");
}
if (!EditorNode::get_singleton()->call_build()) {
+ OS::get_singleton()->set_exit_code(EXIT_FAILURE);
ERR_FAIL_V_MSG(true,
"Command line option --build-solutions was passed, but the build callback failed. Aborting.");
}
diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp
index ffe01eaa18..6b325d6451 100644
--- a/modules/gdscript/gdscript.cpp
+++ b/modules/gdscript/gdscript.cpp
@@ -248,6 +248,10 @@ Ref<Script> GDScript::get_base_script() const {
}
}
+StringName GDScript::get_global_name() const {
+ return name;
+}
+
StringName GDScript::get_instance_base_type() const {
if (native.is_valid()) {
return native->get_name();
diff --git a/modules/gdscript/gdscript.h b/modules/gdscript/gdscript.h
index 71184ac2da..82d04f641c 100644
--- a/modules/gdscript/gdscript.h
+++ b/modules/gdscript/gdscript.h
@@ -228,6 +228,7 @@ public:
virtual bool can_instantiate() const override;
virtual Ref<Script> get_base_script() const override;
+ virtual StringName get_global_name() const override;
virtual StringName get_instance_base_type() const override; // this may not work in all scripts, will return empty if so
virtual ScriptInstance *instance_create(Object *p_this) override;
diff --git a/modules/gdscript/language_server/gdscript_text_document.cpp b/modules/gdscript/language_server/gdscript_text_document.cpp
index edb2e8117a..b9e6921034 100644
--- a/modules/gdscript/language_server/gdscript_text_document.cpp
+++ b/modules/gdscript/language_server/gdscript_text_document.cpp
@@ -107,6 +107,7 @@ void GDScriptTextDocument::didSave(const Variant &p_param) {
} else {
scr->reload(true);
}
+ scr->update_exports();
ScriptEditor::get_singleton()->update_docs_from_script(scr);
}
}
diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cpp
index 7606465b8a..ca94917938 100644
--- a/modules/mono/csharp_script.cpp
+++ b/modules/mono/csharp_script.cpp
@@ -2606,6 +2606,10 @@ Ref<Script> CSharpScript::get_base_script() const {
return base_script;
}
+StringName CSharpScript::get_global_name() const {
+ return StringName();
+}
+
void CSharpScript::get_script_property_list(List<PropertyInfo> *r_list) const {
#ifdef TOOLS_ENABLED
const CSharpScript *top = this;
diff --git a/modules/mono/csharp_script.h b/modules/mono/csharp_script.h
index ef381fd76a..6021555255 100644
--- a/modules/mono/csharp_script.h
+++ b/modules/mono/csharp_script.h
@@ -186,6 +186,8 @@ public:
bool inherits_script(const Ref<Script> &p_script) const override;
Ref<Script> get_base_script() const override;
+ StringName get_global_name() const override;
+
ScriptLanguage *get_language() const override;
void get_script_method_list(List<MethodInfo> *p_list) const override;
diff --git a/modules/navigation/godot_navigation_server.cpp b/modules/navigation/godot_navigation_server.cpp
index 9b5d78d465..2b5db6462c 100644
--- a/modules/navigation/godot_navigation_server.cpp
+++ b/modules/navigation/godot_navigation_server.cpp
@@ -731,24 +731,21 @@ COMMAND_1(free, RID, p_object) {
NavMap *map = map_owner.get_or_null(p_object);
// Removes any assigned region
- LocalVector<NavRegion *> regions = map->get_regions();
- for (uint32_t i = 0; i < regions.size(); i++) {
- map->remove_region(regions[i]);
- regions[i]->set_map(nullptr);
+ for (NavRegion *region : map->get_regions()) {
+ map->remove_region(region);
+ region->set_map(nullptr);
}
// Removes any assigned links
- LocalVector<NavLink *> links = map->get_links();
- for (uint32_t i = 0; i < links.size(); i++) {
- map->remove_link(links[i]);
- links[i]->set_map(nullptr);
+ for (NavLink *link : map->get_links()) {
+ map->remove_link(link);
+ link->set_map(nullptr);
}
// Remove any assigned agent
- LocalVector<RvoAgent *> agents = map->get_agents();
- for (uint32_t i = 0; i < agents.size(); i++) {
- map->remove_agent(agents[i]);
- agents[i]->set_map(nullptr);
+ for (RvoAgent *agent : map->get_agents()) {
+ map->remove_agent(agent);
+ agent->set_map(nullptr);
}
int map_index = active_maps.find(map);
@@ -806,9 +803,9 @@ void GodotNavigationServer::flush_queries() {
MutexLock lock(commands_mutex);
MutexLock lock2(operations_mutex);
- for (size_t i(0); i < commands.size(); i++) {
- commands[i]->exec(this);
- memdelete(commands[i]);
+ for (SetCommand *command : commands) {
+ command->exec(this);
+ memdelete(command);
}
commands.clear();
}
diff --git a/modules/navigation/nav_map.cpp b/modules/navigation/nav_map.cpp
index fd735f8793..7090588c6e 100644
--- a/modules/navigation/nav_map.cpp
+++ b/modules/navigation/nav_map.cpp
@@ -103,9 +103,7 @@ Vector<Vector3> NavMap::get_path(Vector3 p_origin, Vector3 p_destination, bool p
float begin_d = 1e20;
float end_d = 1e20;
// Find the initial poly and the end poly on this map.
- for (size_t i(0); i < polygons.size(); i++) {
- const gd::Polygon &p = polygons[i];
-
+ for (const gd::Polygon &p : polygons) {
// Only consider the polygon if it in a region with compatible layers.
if ((p_navigation_layers & p.owner->get_navigation_layers()) == 0) {
continue;
@@ -190,9 +188,7 @@ Vector<Vector3> NavMap::get_path(Vector3 p_origin, Vector3 p_destination, bool p
while (true) {
// Takes the current least_cost_poly neighbors (iterating over its edges) and compute the traveled_distance.
- for (size_t i = 0; i < navigation_polys[least_cost_id].poly->edges.size(); i++) {
- const gd::Edge &edge = navigation_polys[least_cost_id].poly->edges[i];
-
+ for (const gd::Edge &edge : navigation_polys[least_cost_id].poly->edges) {
// Iterate over connections in this edge, then compute the new optimized travel distance assigned to this polygon.
for (int connection_index = 0; connection_index < edge.connections.size(); connection_index++) {
const gd::Edge::Connection &connection = edge.connections[connection_index];
@@ -465,9 +461,7 @@ Vector3 NavMap::get_closest_point_to_segment(const Vector3 &p_from, const Vector
Vector3 closest_point;
real_t closest_point_d = 1e20;
- for (size_t i(0); i < polygons.size(); i++) {
- const gd::Polygon &p = polygons[i];
-
+ for (const gd::Polygon &p : polygons) {
// For each face check the distance to the segment
for (size_t point_id = 2; point_id < p.points.size(); point_id += 1) {
const Face3 f(p.points[0].pos, p.points[point_id - 1].pos, p.points[point_id].pos);
@@ -623,20 +617,20 @@ void NavMap::sync() {
// Check if we need to update the links.
if (regenerate_polygons) {
- for (uint32_t r = 0; r < regions.size(); r++) {
- regions[r]->scratch_polygons();
+ for (NavRegion *region : regions) {
+ region->scratch_polygons();
}
regenerate_links = true;
}
- for (uint32_t r = 0; r < regions.size(); r++) {
- if (regions[r]->sync()) {
+ for (NavRegion *region : regions) {
+ if (region->sync()) {
regenerate_links = true;
}
}
- for (uint32_t l = 0; l < links.size(); l++) {
- if (links[l]->check_dirty()) {
+ for (NavLink *link : links) {
+ if (link->check_dirty()) {
regenerate_links = true;
}
}
@@ -649,34 +643,32 @@ void NavMap::sync() {
_new_pm_edge_free_count = 0;
// Remove regions connections.
- for (uint32_t r = 0; r < regions.size(); r++) {
- regions[r]->get_connections().clear();
+ for (NavRegion *region : regions) {
+ region->get_connections().clear();
}
// Resize the polygon count.
int count = 0;
- for (uint32_t r = 0; r < regions.size(); r++) {
- count += regions[r]->get_polygons().size();
+ for (const NavRegion *region : regions) {
+ count += region->get_polygons().size();
}
polygons.resize(count);
// Copy all region polygons in the map.
count = 0;
- for (uint32_t r = 0; r < regions.size(); r++) {
- const LocalVector<gd::Polygon> &polygons_source = regions[r]->get_polygons();
+ for (const NavRegion *region : regions) {
+ const LocalVector<gd::Polygon> &polygons_source = region->get_polygons();
for (uint32_t n = 0; n < polygons_source.size(); n++) {
polygons[count + n] = polygons_source[n];
}
- count += regions[r]->get_polygons().size();
+ count += region->get_polygons().size();
}
_new_pm_polygon_count = polygons.size();
// Group all edges per key.
HashMap<gd::EdgeKey, Vector<gd::Edge::Connection>, gd::EdgeKey> connections;
- for (uint32_t poly_id = 0; poly_id < polygons.size(); poly_id++) {
- gd::Polygon &poly(polygons[poly_id]);
-
+ for (gd::Polygon &poly : polygons) {
for (uint32_t p = 0; p < poly.points.size(); p++) {
int next_point = (p + 1) % poly.points.size();
gd::EdgeKey ek(poly.points[p].key, poly.points[next_point].key);
@@ -787,8 +779,7 @@ void NavMap::sync() {
link_polygons.resize(links.size());
// Search for polygons within range of a nav link.
- for (uint32_t l = 0; l < links.size(); l++) {
- const NavLink *link = links[l];
+ for (const NavLink *link : links) {
const Vector3 start = link->get_start_location();
const Vector3 end = link->get_end_location();
@@ -820,9 +811,7 @@ void NavMap::sync() {
}
// Find any polygons within the search radius of the end point.
- for (uint32_t end_index = 0; end_index < polygons.size(); end_index++) {
- gd::Polygon &end_poly = polygons[end_index];
-
+ for (gd::Polygon &end_poly : polygons) {
// For each face check the distance to the end
for (uint32_t end_point_id = 2; end_point_id < end_poly.points.size(); end_point_id += 1) {
const Face3 end_face(end_poly.points[0].pos, end_poly.points[end_point_id - 1].pos, end_poly.points[end_point_id].pos);
@@ -906,8 +895,8 @@ void NavMap::sync() {
// cannot use LocalVector here as RVO library expects std::vector to build KdTree
std::vector<RVO::Agent *> raw_agents;
raw_agents.reserve(agents.size());
- for (size_t i(0); i < agents.size(); i++) {
- raw_agents.push_back(agents[i]->get_agent());
+ for (RvoAgent *agent : agents) {
+ raw_agents.push_back(agent->get_agent());
}
rvo.buildAgentTree(raw_agents);
}
@@ -941,8 +930,8 @@ void NavMap::step(real_t p_deltatime) {
}
void NavMap::dispatch_callbacks() {
- for (int i(0); i < static_cast<int>(controlled_agents.size()); i++) {
- controlled_agents[i]->dispatch_callback();
+ for (RvoAgent *agent : controlled_agents) {
+ agent->dispatch_callback();
}
}
diff --git a/modules/navigation/navigation_mesh_generator.cpp b/modules/navigation/navigation_mesh_generator.cpp
index fff7a02fc4..74ff9312fd 100644
--- a/modules/navigation/navigation_mesh_generator.cpp
+++ b/modules/navigation/navigation_mesh_generator.cpp
@@ -266,9 +266,7 @@ void NavigationMeshGenerator::_parse_geometry(const Transform3D &p_navmesh_trans
if (err == OK) {
PackedVector3Array faces;
- for (uint32_t j = 0; j < md.faces.size(); ++j) {
- const Geometry3D::MeshData::Face &face = md.faces[j];
-
+ for (const Geometry3D::MeshData::Face &face : md.faces) {
for (uint32_t k = 2; k < face.indices.size(); ++k) {
faces.push_back(md.vertices[face.indices[0]]);
faces.push_back(md.vertices[face.indices[k - 1]]);
@@ -392,9 +390,7 @@ void NavigationMeshGenerator::_parse_geometry(const Transform3D &p_navmesh_trans
if (err == OK) {
PackedVector3Array faces;
- for (uint32_t j = 0; j < md.faces.size(); ++j) {
- const Geometry3D::MeshData::Face &face = md.faces[j];
-
+ for (const Geometry3D::MeshData::Face &face : md.faces) {
for (uint32_t k = 2; k < face.indices.size(); ++k) {
faces.push_back(md.vertices[face.indices[0]]);
faces.push_back(md.vertices[face.indices[k - 1]]);
diff --git a/modules/raycast/raycast_occlusion_cull.cpp b/modules/raycast/raycast_occlusion_cull.cpp
index c74799caa3..9394f71e40 100644
--- a/modules/raycast/raycast_occlusion_cull.cpp
+++ b/modules/raycast/raycast_occlusion_cull.cpp
@@ -426,8 +426,8 @@ bool RaycastOcclusionCull::Scenario::update() {
return false;
}
- for (unsigned int i = 0; i < removed_instances.size(); i++) {
- instances.erase(removed_instances[i]);
+ for (const RID &scenario : removed_instances) {
+ instances.erase(scenario);
}
if (dirty_instances_array.size() / WorkerThreadPool::get_singleton()->get_thread_count() > 128) {
diff --git a/platform/linuxbsd/crash_handler_linuxbsd.cpp b/platform/linuxbsd/crash_handler_linuxbsd.cpp
index 8d03e3d31c..3a245460b4 100644
--- a/platform/linuxbsd/crash_handler_linuxbsd.cpp
+++ b/platform/linuxbsd/crash_handler_linuxbsd.cpp
@@ -81,7 +81,13 @@ static void handle_crash(int sig) {
print_error(vformat("Dumping the backtrace. %s", msg));
char **strings = backtrace_symbols(bt_buffer, size);
// PIE executable relocation, zero for non-PIE executables
+#ifdef __GLIBC__
+ // This is a glibc only thing apparently.
uintptr_t relocation = _r_debug.r_map->l_addr;
+#else
+ // Non glibc systems apparently don't give PIE relocation info.
+ uintptr_t relocation = 0;
+#endif //__GLIBC__
if (strings) {
List<String> args;
for (size_t i = 0; i < size; i++) {
diff --git a/platform/windows/display_server_windows.cpp b/platform/windows/display_server_windows.cpp
index 631543763b..9a732c489d 100644
--- a/platform/windows/display_server_windows.cpp
+++ b/platform/windows/display_server_windows.cpp
@@ -3513,6 +3513,7 @@ void DisplayServerWindows::_process_activate_event(WindowID p_window_id, WPARAM
alt_mem = false;
control_mem = false;
shift_mem = false;
+ gr_mem = false;
// Restore mouse mode.
_set_mouse_mode_impl(mouse_mode);
diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp
index 130c5f7b97..08299d9b98 100644
--- a/platform/windows/os_windows.cpp
+++ b/platform/windows/os_windows.cpp
@@ -210,6 +210,8 @@ void OS_Windows::initialize() {
} else if (!dwrite2_init) {
print_verbose("Unable to load IDWriteFactory2, automatic system font fallback is disabled.");
}
+
+ FileAccessWindows::initialize();
}
void OS_Windows::delete_main_loop() {
@@ -252,6 +254,8 @@ void OS_Windows::finalize() {
}
void OS_Windows::finalize_core() {
+ FileAccessWindows::finalize();
+
timeEndPeriod(1);
memdelete(process_map);
diff --git a/scene/2d/area_2d.cpp b/scene/2d/area_2d.cpp
index 5eb76bdbb5..f80da6e9ab 100644
--- a/scene/2d/area_2d.cpp
+++ b/scene/2d/area_2d.cpp
@@ -175,6 +175,7 @@ void Area2D::_body_inout(int p_status, const RID &p_body, ObjectID p_instance, i
return; //does not exist because it was likely removed from the tree
}
+ lock_callback();
locked = true;
if (body_in) {
@@ -224,6 +225,7 @@ void Area2D::_body_inout(int p_status, const RID &p_body, ObjectID p_instance, i
}
locked = false;
+ unlock_callback();
}
void Area2D::_area_enter_tree(ObjectID p_id) {
@@ -268,6 +270,8 @@ void Area2D::_area_inout(int p_status, const RID &p_area, ObjectID p_instance, i
if (!area_in && !E) {
return; //likely removed from the tree
}
+
+ lock_callback();
locked = true;
if (area_in) {
@@ -317,6 +321,7 @@ void Area2D::_area_inout(int p_status, const RID &p_area, ObjectID p_instance, i
}
locked = false;
+ unlock_callback();
}
void Area2D::_clear_monitoring() {
diff --git a/scene/2d/collision_object_2d.cpp b/scene/2d/collision_object_2d.cpp
index b2fee6ad82..caea753d99 100644
--- a/scene/2d/collision_object_2d.cpp
+++ b/scene/2d/collision_object_2d.cpp
@@ -94,10 +94,14 @@ void CollisionObject2D::_notification(int p_what) {
bool disabled = !is_enabled();
if (!disabled || (disable_mode != DISABLE_MODE_REMOVE)) {
- if (area) {
- PhysicsServer2D::get_singleton()->area_set_space(rid, RID());
+ if (callback_lock > 0) {
+ ERR_PRINT("Removing a CollisionObject node during a physics callback is not allowed and will cause undesired behavior. Remove with call_deferred() instead.");
} else {
- PhysicsServer2D::get_singleton()->body_set_space(rid, RID());
+ if (area) {
+ PhysicsServer2D::get_singleton()->area_set_space(rid, RID());
+ } else {
+ PhysicsServer2D::get_singleton()->body_set_space(rid, RID());
+ }
}
}
@@ -225,10 +229,14 @@ void CollisionObject2D::_apply_disabled() {
switch (disable_mode) {
case DISABLE_MODE_REMOVE: {
if (is_inside_tree()) {
- if (area) {
- PhysicsServer2D::get_singleton()->area_set_space(rid, RID());
+ if (callback_lock > 0) {
+ ERR_PRINT("Disabling a CollisionObject node during a physics callback is not allowed and will cause undesired behavior. Disable with call_deferred() instead.");
} else {
- PhysicsServer2D::get_singleton()->body_set_space(rid, RID());
+ if (area) {
+ PhysicsServer2D::get_singleton()->area_set_space(rid, RID());
+ } else {
+ PhysicsServer2D::get_singleton()->body_set_space(rid, RID());
+ }
}
}
} break;
diff --git a/scene/2d/collision_object_2d.h b/scene/2d/collision_object_2d.h
index d44e402e96..88429b145d 100644
--- a/scene/2d/collision_object_2d.h
+++ b/scene/2d/collision_object_2d.h
@@ -53,6 +53,7 @@ private:
bool area = false;
RID rid;
+ uint32_t callback_lock = 0;
bool pickable = false;
DisableMode disable_mode = DISABLE_MODE_REMOVE;
@@ -83,6 +84,12 @@ private:
void _apply_enabled();
protected:
+ _FORCE_INLINE_ void lock_callback() { callback_lock++; }
+ _FORCE_INLINE_ void unlock_callback() {
+ ERR_FAIL_COND(callback_lock == 0);
+ callback_lock--;
+ }
+
CollisionObject2D(RID p_rid, bool p_area);
void _notification(int p_what);
diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp
index 9fee99c6a7..1721bcde3b 100644
--- a/scene/2d/physics_body_2d.cpp
+++ b/scene/2d/physics_body_2d.cpp
@@ -434,6 +434,8 @@ struct _RigidBody2DInOut {
};
void RigidBody2D::_body_state_changed(PhysicsDirectBodyState2D *p_state) {
+ lock_callback();
+
set_block_transform_notify(true); // don't want notify (would feedback loop)
if (!freeze || freeze_mode != FREEZE_MODE_KINEMATIC) {
set_global_transform(p_state->get_transform());
@@ -527,6 +529,8 @@ void RigidBody2D::_body_state_changed(PhysicsDirectBodyState2D *p_state) {
contact_monitor->locked = false;
}
+
+ unlock_callback();
}
void RigidBody2D::_apply_body_mode() {
diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp
index 4f282dc0ab..05d28e8a0e 100644
--- a/scene/2d/tile_map.cpp
+++ b/scene/2d/tile_map.cpp
@@ -803,10 +803,10 @@ void TileMap::_make_quadrant_dirty(HashMap<Vector2i, TileMapQuadrant>::Iterator
void TileMap::_make_all_quadrants_dirty() {
// Make all quandrants dirty, then trigger an update later.
- for (unsigned int layer = 0; layer < layers.size(); layer++) {
- for (KeyValue<Vector2i, TileMapQuadrant> &E : layers[layer].quadrant_map) {
+ for (TileMapLayer &layer : layers) {
+ for (KeyValue<Vector2i, TileMapQuadrant> &E : layer.quadrant_map) {
if (!E.value.dirty_list_element.in_list()) {
- layers[layer].dirty_quadrant_list.add(&E.value.dirty_list_element);
+ layer.dirty_quadrant_list.add(&E.value.dirty_list_element);
}
}
}
@@ -1014,8 +1014,8 @@ void TileMap::_rendering_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_CANVAS: {
bool node_visible = is_visible_in_tree();
- for (int layer = 0; layer < (int)layers.size(); layer++) {
- for (KeyValue<Vector2i, TileMapQuadrant> &E_quadrant : layers[layer].quadrant_map) {
+ for (TileMapLayer &layer : layers) {
+ for (KeyValue<Vector2i, TileMapQuadrant> &E_quadrant : layer.quadrant_map) {
TileMapQuadrant &q = E_quadrant.value;
for (const KeyValue<Vector2i, RID> &kv : q.occluders) {
Transform2D xform;
@@ -1030,8 +1030,8 @@ void TileMap::_rendering_notification(int p_what) {
case NOTIFICATION_VISIBILITY_CHANGED: {
bool node_visible = is_visible_in_tree();
- for (int layer = 0; layer < (int)layers.size(); layer++) {
- for (KeyValue<Vector2i, TileMapQuadrant> &E_quadrant : layers[layer].quadrant_map) {
+ for (TileMapLayer &layer : layers) {
+ for (KeyValue<Vector2i, TileMapQuadrant> &E_quadrant : layer.quadrant_map) {
TileMapQuadrant &q = E_quadrant.value;
// Update occluders transform.
@@ -1050,8 +1050,8 @@ void TileMap::_rendering_notification(int p_what) {
if (!is_inside_tree()) {
return;
}
- for (int layer = 0; layer < (int)layers.size(); layer++) {
- for (KeyValue<Vector2i, TileMapQuadrant> &E_quadrant : layers[layer].quadrant_map) {
+ for (TileMapLayer &layer : layers) {
+ for (KeyValue<Vector2i, TileMapQuadrant> &E_quadrant : layer.quadrant_map) {
TileMapQuadrant &q = E_quadrant.value;
// Update occluders transform.
@@ -1071,8 +1071,8 @@ void TileMap::_rendering_notification(int p_what) {
} break;
case NOTIFICATION_EXIT_CANVAS: {
- for (int layer = 0; layer < (int)layers.size(); layer++) {
- for (KeyValue<Vector2i, TileMapQuadrant> &E_quadrant : layers[layer].quadrant_map) {
+ for (TileMapLayer &layer : layers) {
+ for (KeyValue<Vector2i, TileMapQuadrant> &E_quadrant : layer.quadrant_map) {
TileMapQuadrant &q = E_quadrant.value;
for (const KeyValue<Vector2i, RID> &kv : q.occluders) {
RS::get_singleton()->canvas_light_occluder_attach_to_canvas(kv.value, RID());
@@ -1257,16 +1257,16 @@ void TileMap::_rendering_update_dirty_quadrants(SelfList<TileMapQuadrant>::List
if (_rendering_quadrant_order_dirty) {
int index = -(int64_t)0x80000000; //always must be drawn below children.
- for (int layer = 0; layer < (int)layers.size(); layer++) {
+ for (TileMapLayer &layer : layers) {
// Sort the quadrants coords per local coordinates.
RBMap<Vector2i, Vector2i, TileMapQuadrant::CoordsWorldComparator> local_to_map;
- for (const KeyValue<Vector2i, TileMapQuadrant> &E : layers[layer].quadrant_map) {
+ for (const KeyValue<Vector2i, TileMapQuadrant> &E : layer.quadrant_map) {
local_to_map[map_to_local(E.key)] = E.key;
}
// Sort the quadrants.
for (const KeyValue<Vector2i, Vector2i> &E : local_to_map) {
- TileMapQuadrant &q = layers[layer].quadrant_map[E.value];
+ TileMapQuadrant &q = layer.quadrant_map[E.value];
for (const RID &ci : q.canvas_items) {
RS::get_singleton()->canvas_item_set_draw_index(ci, index++);
}
@@ -1453,8 +1453,8 @@ void TileMap::_physics_notification(int p_what) {
if (is_inside_tree() && (!collision_animatable || in_editor)) {
// Update the new transform directly if we are not in animatable mode.
Transform2D gl_transform = get_global_transform();
- for (int layer = 0; layer < (int)layers.size(); layer++) {
- for (KeyValue<Vector2i, TileMapQuadrant> &E : layers[layer].quadrant_map) {
+ for (TileMapLayer &layer : layers) {
+ for (KeyValue<Vector2i, TileMapQuadrant> &E : layer.quadrant_map) {
TileMapQuadrant &q = E.value;
for (RID body : q.bodies) {
@@ -1476,8 +1476,8 @@ void TileMap::_physics_notification(int p_what) {
if (is_inside_tree() && !in_editor && collision_animatable) {
// Only active when animatable. Send the new transform to the physics...
new_transform = get_global_transform();
- for (int layer = 0; layer < (int)layers.size(); layer++) {
- for (KeyValue<Vector2i, TileMapQuadrant> &E : layers[layer].quadrant_map) {
+ for (TileMapLayer &layer : layers) {
+ for (KeyValue<Vector2i, TileMapQuadrant> &E : layer.quadrant_map) {
TileMapQuadrant &q = E.value;
for (RID body : q.bodies) {
@@ -1667,13 +1667,12 @@ void TileMap::_navigation_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_TRANSFORM_CHANGED: {
if (is_inside_tree()) {
- for (int layer = 0; layer < (int)layers.size(); layer++) {
+ for (TileMapLayer &layer : layers) {
Transform2D tilemap_xform = get_global_transform();
- for (KeyValue<Vector2i, TileMapQuadrant> &E_quadrant : layers[layer].quadrant_map) {
+ for (KeyValue<Vector2i, TileMapQuadrant> &E_quadrant : layer.quadrant_map) {
TileMapQuadrant &q = E_quadrant.value;
for (const KeyValue<Vector2i, Vector<RID>> &E_region : q.navigation_regions) {
- for (int layer_index = 0; layer_index < E_region.value.size(); layer_index++) {
- RID region = E_region.value[layer_index];
+ for (const RID &region : E_region.value) {
if (!region.is_valid()) {
continue;
}
@@ -2073,7 +2072,7 @@ void TileMap::erase_cell(int p_layer, const Vector2i &p_coords) {
int TileMap::get_cell_source_id(int p_layer, const Vector2i &p_coords, bool p_use_proxies) const {
ERR_FAIL_INDEX_V(p_layer, (int)layers.size(), TileSet::INVALID_SOURCE);
- // Get a cell source id from position
+ // Get a cell source id from position.
const HashMap<Vector2i, TileMapCell> &tile_map = layers[p_layer].tile_map;
HashMap<Vector2i, TileMapCell>::ConstIterator E = tile_map.find(p_coords);
@@ -2129,7 +2128,9 @@ int TileMap::get_cell_alternative_tile(int p_layer, const Vector2i &p_coords, bo
TileData *TileMap::get_cell_tile_data(int p_layer, const Vector2i &p_coords, bool p_use_proxies) const {
int source_id = get_cell_source_id(p_layer, p_coords, p_use_proxies);
- ERR_FAIL_COND_V_MSG(source_id == TileSet::INVALID_SOURCE, nullptr, vformat("Invalid TileSetSource at cell %s. Make sure a tile exists at this cell.", p_coords));
+ if (source_id == TileSet::INVALID_SOURCE) {
+ return nullptr;
+ }
Ref<TileSetAtlasSource> source = tile_set->get_source(source_id);
if (source.is_valid()) {
@@ -2813,8 +2814,8 @@ void TileMap::clear_layer(int p_layer) {
void TileMap::clear() {
// Remove all tiles.
_clear_internals();
- for (unsigned int i = 0; i < layers.size(); i++) {
- layers[i].tile_map.clear();
+ for (TileMapLayer &layer : layers) {
+ layer.tile_map.clear();
}
_recreate_internals();
used_rect_cache_dirty = true;
@@ -3954,15 +3955,15 @@ PackedStringArray TileMap::get_configuration_warnings() const {
// Retrieve the set of Z index values with a Y-sorted layer.
RBSet<int> y_sorted_z_index;
- for (int layer = 0; layer < (int)layers.size(); layer++) {
- if (layers[layer].y_sort_enabled) {
- y_sorted_z_index.insert(layers[layer].z_index);
+ for (const TileMapLayer &layer : layers) {
+ if (layer.y_sort_enabled) {
+ y_sorted_z_index.insert(layer.z_index);
}
}
// Check if we have a non-sorted layer in a Z-index with a Y-sorted layer.
- for (int layer = 0; layer < (int)layers.size(); layer++) {
- if (!layers[layer].y_sort_enabled && y_sorted_z_index.has(layers[layer].z_index)) {
+ for (const TileMapLayer &layer : layers) {
+ if (!layer.y_sort_enabled && y_sorted_z_index.has(layer.z_index)) {
warnings.push_back(RTR("A Y-sorted layer has the same Z-index value as a not Y-sorted layer.\nThis may lead to unwanted behaviors, as a layer that is not Y-sorted will be Y-sorted as a whole with tiles from Y-sorted layers."));
break;
}
@@ -3971,8 +3972,8 @@ PackedStringArray TileMap::get_configuration_warnings() const {
if (tile_set.is_valid() && tile_set->get_tile_shape() == TileSet::TILE_SHAPE_ISOMETRIC) {
bool warn = !is_y_sort_enabled();
if (!warn) {
- for (int layer = 0; layer < (int)layers.size(); layer++) {
- if (!layers[layer].y_sort_enabled) {
+ for (const TileMapLayer &layer : layers) {
+ if (!layer.y_sort_enabled) {
warn = true;
break;
}
diff --git a/scene/3d/area_3d.cpp b/scene/3d/area_3d.cpp
index fa61ce5546..72f186c676 100644
--- a/scene/3d/area_3d.cpp
+++ b/scene/3d/area_3d.cpp
@@ -230,6 +230,7 @@ void Area3D::_body_inout(int p_status, const RID &p_body, ObjectID p_instance, i
return; //likely removed from the tree
}
+ lock_callback();
locked = true;
if (body_in) {
@@ -279,6 +280,7 @@ void Area3D::_body_inout(int p_status, const RID &p_body, ObjectID p_instance, i
}
locked = false;
+ unlock_callback();
}
void Area3D::_clear_monitoring() {
@@ -417,6 +419,7 @@ void Area3D::_area_inout(int p_status, const RID &p_area, ObjectID p_instance, i
return; //likely removed from the tree
}
+ lock_callback();
locked = true;
if (area_in) {
@@ -466,6 +469,7 @@ void Area3D::_area_inout(int p_status, const RID &p_area, ObjectID p_instance, i
}
locked = false;
+ unlock_callback();
}
bool Area3D::is_monitoring() const {
diff --git a/scene/3d/collision_object_3d.cpp b/scene/3d/collision_object_3d.cpp
index c408b0714a..26ada1da5a 100644
--- a/scene/3d/collision_object_3d.cpp
+++ b/scene/3d/collision_object_3d.cpp
@@ -100,10 +100,14 @@ void CollisionObject3D::_notification(int p_what) {
bool disabled = !is_enabled();
if (!disabled || (disable_mode != DISABLE_MODE_REMOVE)) {
- if (area) {
- PhysicsServer3D::get_singleton()->area_set_space(rid, RID());
+ if (callback_lock > 0) {
+ ERR_PRINT("Removing a CollisionObject node during a physics callback is not allowed and will cause undesired behavior. Remove with call_deferred() instead.");
} else {
- PhysicsServer3D::get_singleton()->body_set_space(rid, RID());
+ if (area) {
+ PhysicsServer3D::get_singleton()->area_set_space(rid, RID());
+ } else {
+ PhysicsServer3D::get_singleton()->body_set_space(rid, RID());
+ }
}
}
@@ -223,10 +227,14 @@ void CollisionObject3D::_apply_disabled() {
switch (disable_mode) {
case DISABLE_MODE_REMOVE: {
if (is_inside_tree()) {
- if (area) {
- PhysicsServer3D::get_singleton()->area_set_space(rid, RID());
+ if (callback_lock > 0) {
+ ERR_PRINT("Disabling a CollisionObject node during a physics callback is not allowed and will cause undesired behavior. Disable with call_deferred() instead.");
} else {
- PhysicsServer3D::get_singleton()->body_set_space(rid, RID());
+ if (area) {
+ PhysicsServer3D::get_singleton()->area_set_space(rid, RID());
+ } else {
+ PhysicsServer3D::get_singleton()->body_set_space(rid, RID());
+ }
}
}
} break;
diff --git a/scene/3d/collision_object_3d.h b/scene/3d/collision_object_3d.h
index 656b8c9bf1..ebcbb39e0d 100644
--- a/scene/3d/collision_object_3d.h
+++ b/scene/3d/collision_object_3d.h
@@ -52,6 +52,7 @@ private:
bool area = false;
RID rid;
+ uint32_t callback_lock = 0;
DisableMode disable_mode = DISABLE_MODE_REMOVE;
@@ -97,6 +98,12 @@ private:
protected:
CollisionObject3D(RID p_rid, bool p_area);
+ _FORCE_INLINE_ void lock_callback() { callback_lock++; }
+ _FORCE_INLINE_ void unlock_callback() {
+ ERR_FAIL_COND(callback_lock == 0);
+ callback_lock--;
+ }
+
void _notification(int p_what);
static void _bind_methods();
diff --git a/scene/3d/lightmap_gi.cpp b/scene/3d/lightmap_gi.cpp
index 6940bad4a6..f308ad0999 100644
--- a/scene/3d/lightmap_gi.cpp
+++ b/scene/3d/lightmap_gi.cpp
@@ -455,8 +455,8 @@ int32_t LightmapGI::_compute_bsp_tree(const Vector<Vector3> &p_points, const Loc
Plane best_plane;
float best_plane_score = -1.0;
- for (uint32_t i = 0; i < p_simplex_indices.size(); i++) {
- const BSPSimplex &s = p_simplices[p_simplex_indices[i]];
+ for (const int idx : p_simplex_indices) {
+ const BSPSimplex &s = p_simplices[idx];
for (int j = 0; j < 4; j++) {
uint32_t plane_index = s.planes[j];
if (planes_tested[plane_index] == node_index) {
@@ -484,8 +484,8 @@ int32_t LightmapGI::_compute_bsp_tree(const Vector<Vector3> &p_points, const Loc
int over_count = 0;
int under_count = 0;
- for (uint32_t k = 0; k < p_simplex_indices.size(); k++) {
- int side = _bsp_get_simplex_side(p_points, p_simplices, plane, p_simplex_indices[k]);
+ for (const int &index : p_simplex_indices) {
+ int side = _bsp_get_simplex_side(p_points, p_simplices, plane, index);
if (side == -2) {
continue; //this simplex is invalid, skip for now
} else if (side < 0) {
@@ -523,8 +523,7 @@ int32_t LightmapGI::_compute_bsp_tree(const Vector<Vector3> &p_points, const Loc
LocalVector<int32_t> indices_under;
//split again, but add to list
- for (uint32_t i = 0; i < p_simplex_indices.size(); i++) {
- uint32_t index = p_simplex_indices[i];
+ for (const uint32_t index : p_simplex_indices) {
int side = _bsp_get_simplex_side(p_points, p_simplices, best_plane, index);
if (side == -2) {
@@ -977,8 +976,8 @@ LightmapGI::BakeError LightmapGI::bake(Node *p_from_node, String p_image_data_pa
}
}
- for (uint32_t i = 0; i < new_probe_positions.size(); i++) {
- probes_found.push_back(new_probe_positions[i]);
+ for (const Vector3 &position : new_probe_positions) {
+ probes_found.push_back(position);
}
}
@@ -1219,8 +1218,8 @@ LightmapGI::BakeError LightmapGI::bake(Node *p_from_node, String p_image_data_pa
LocalVector<BSPNode> bsp_nodes;
LocalVector<int32_t> planes_tested;
planes_tested.resize(bsp_planes.size());
- for (uint32_t i = 0; i < planes_tested.size(); i++) {
- planes_tested[i] = 0x7FFFFFFF;
+ for (int &index : planes_tested) {
+ index = 0x7FFFFFFF;
}
if (p_bake_step) {
diff --git a/scene/3d/physics_body_3d.cpp b/scene/3d/physics_body_3d.cpp
index 46956b0a2e..106efbc596 100644
--- a/scene/3d/physics_body_3d.cpp
+++ b/scene/3d/physics_body_3d.cpp
@@ -484,6 +484,8 @@ struct _RigidBodyInOut {
};
void RigidBody3D::_body_state_changed(PhysicsDirectBodyState3D *p_state) {
+ lock_callback();
+
set_ignore_transform_notification(true);
set_global_transform(p_state->get_transform());
@@ -578,6 +580,8 @@ void RigidBody3D::_body_state_changed(PhysicsDirectBodyState3D *p_state) {
contact_monitor->locked = false;
}
+
+ unlock_callback();
}
void RigidBody3D::_notification(int p_what) {
diff --git a/scene/animation/animation_blend_tree.cpp b/scene/animation/animation_blend_tree.cpp
index e074927b9b..a00b1d8ee1 100644
--- a/scene/animation/animation_blend_tree.cpp
+++ b/scene/animation/animation_blend_tree.cpp
@@ -901,7 +901,7 @@ void AnimationNodeTransition::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_reset", "reset"), &AnimationNodeTransition::set_reset);
ClassDB::bind_method(D_METHOD("is_reset"), &AnimationNodeTransition::is_reset);
- ADD_PROPERTY(PropertyInfo(Variant::INT, "enabled_inputs", PROPERTY_HINT_RANGE, "0,64,1", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), "set_enabled_inputs", "get_enabled_inputs");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "enabled_inputs", PROPERTY_HINT_RANGE, "0,31,1", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), "set_enabled_inputs", "get_enabled_inputs");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "xfade_time", PROPERTY_HINT_RANGE, "0,120,0.01,suffix:s"), "set_xfade_time", "get_xfade_time");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "xfade_curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_xfade_curve", "get_xfade_curve");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "reset"), "set_reset", "is_reset");
diff --git a/scene/animation/animation_node_state_machine.cpp b/scene/animation/animation_node_state_machine.cpp
index 2c79e5fe06..02f1e9f9a6 100644
--- a/scene/animation/animation_node_state_machine.cpp
+++ b/scene/animation/animation_node_state_machine.cpp
@@ -212,7 +212,7 @@ StringName AnimationNodeStateMachinePlayback::get_current_node() const {
return current;
}
-StringName AnimationNodeStateMachinePlayback::get_blend_from_node() const {
+StringName AnimationNodeStateMachinePlayback::get_fading_from_node() const {
return fading_from;
}
@@ -411,9 +411,11 @@ double AnimationNodeStateMachinePlayback::_process(AnimationNodeStateMachine *p_
// can't travel, then teleport
if (p_state_machine->states.has(travel_request)) {
path.clear();
- current = travel_request;
- play_start = true;
- reset_request = reset_request_on_teleport;
+ if (current != travel_request || reset_request_on_teleport) {
+ current = travel_request;
+ play_start = true;
+ reset_request = reset_request_on_teleport;
+ }
} else {
StringName node = travel_request;
travel_request = StringName();
@@ -703,6 +705,7 @@ void AnimationNodeStateMachinePlayback::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_current_node"), &AnimationNodeStateMachinePlayback::get_current_node);
ClassDB::bind_method(D_METHOD("get_current_play_position"), &AnimationNodeStateMachinePlayback::get_current_play_pos);
ClassDB::bind_method(D_METHOD("get_current_length"), &AnimationNodeStateMachinePlayback::get_current_length);
+ ClassDB::bind_method(D_METHOD("get_fading_from_node"), &AnimationNodeStateMachinePlayback::get_fading_from_node);
ClassDB::bind_method(D_METHOD("get_travel_path"), &AnimationNodeStateMachinePlayback::get_travel_path);
}
diff --git a/scene/animation/animation_node_state_machine.h b/scene/animation/animation_node_state_machine.h
index 8183d2025a..1b4e010a06 100644
--- a/scene/animation/animation_node_state_machine.h
+++ b/scene/animation/animation_node_state_machine.h
@@ -159,7 +159,7 @@ public:
void stop();
bool is_playing() const;
StringName get_current_node() const;
- StringName get_blend_from_node() const;
+ StringName get_fading_from_node() const;
Vector<StringName> get_travel_path() const;
float get_current_play_pos() const;
float get_current_length() const;
diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp
index 0febe580db..047997ca09 100644
--- a/scene/animation/animation_player.cpp
+++ b/scene/animation/animation_player.cpp
@@ -143,8 +143,8 @@ bool AnimationPlayer::_get(const StringName &p_name, Variant &r_ret) const {
} else if (name.begins_with("libraries")) {
Dictionary d;
- for (uint32_t i = 0; i < animation_libraries.size(); i++) {
- d[animation_libraries[i].name] = animation_libraries[i].library;
+ for (const AnimationLibraryData &lib : animation_libraries) {
+ d[lib.name] = lib.library;
}
r_ret = d;
@@ -1269,13 +1269,13 @@ void AnimationPlayer::_animation_set_cache_update() {
bool clear_cache_needed = false;
// Update changed and add otherwise
- for (uint32_t i = 0; i < animation_libraries.size(); i++) {
- for (const KeyValue<StringName, Ref<Animation>> &K : animation_libraries[i].library->animations) {
- StringName key = animation_libraries[i].name == StringName() ? K.key : StringName(String(animation_libraries[i].name) + "/" + String(K.key));
+ for (const AnimationLibraryData &lib : animation_libraries) {
+ for (const KeyValue<StringName, Ref<Animation>> &K : lib.library->animations) {
+ StringName key = lib.name == StringName() ? K.key : StringName(String(lib.name) + "/" + String(K.key));
if (!animation_set.has(key)) {
AnimationData ad;
ad.animation = K.value;
- ad.animation_library = animation_libraries[i].name;
+ ad.animation_library = lib.name;
ad.name = key;
ad.last_update = animation_set_update_pass;
animation_set.insert(ad.name, ad);
@@ -1283,11 +1283,11 @@ void AnimationPlayer::_animation_set_cache_update() {
AnimationData &ad = animation_set[key];
if (ad.last_update != animation_set_update_pass) {
// Was not updated, update. If the animation is duplicated, the second one will be ignored.
- if (ad.animation != K.value || ad.animation_library != animation_libraries[i].name) {
+ if (ad.animation != K.value || ad.animation_library != lib.name) {
// Animation changed, update and clear caches.
clear_cache_needed = true;
ad.animation = K.value;
- ad.animation_library = animation_libraries[i].name;
+ ad.animation_library = lib.name;
}
ad.last_update = animation_set_update_pass;
@@ -1405,11 +1405,11 @@ Error AnimationPlayer::add_animation_library(const StringName &p_name, const Ref
int insert_pos = 0;
- for (uint32_t i = 0; i < animation_libraries.size(); i++) {
- ERR_FAIL_COND_V_MSG(animation_libraries[i].name == p_name, ERR_ALREADY_EXISTS, "Can't add animation library twice with name: " + String(p_name));
- ERR_FAIL_COND_V_MSG(animation_libraries[i].library == p_animation_library, ERR_ALREADY_EXISTS, "Can't add animation library twice (adding as '" + p_name.operator String() + "', exists as '" + animation_libraries[i].name.operator String() + "'.");
+ for (const AnimationLibraryData &lib : animation_libraries) {
+ ERR_FAIL_COND_V_MSG(lib.name == p_name, ERR_ALREADY_EXISTS, "Can't add animation library twice with name: " + String(p_name));
+ ERR_FAIL_COND_V_MSG(lib.library == p_animation_library, ERR_ALREADY_EXISTS, "Can't add animation library twice (adding as '" + p_name.operator String() + "', exists as '" + lib.name.operator String() + "'.");
- if (animation_libraries[i].name.operator String() >= p_name.operator String()) {
+ if (lib.name.operator String() >= p_name.operator String()) {
break;
}
@@ -1468,21 +1468,21 @@ void AnimationPlayer::rename_animation_library(const StringName &p_name, const S
#endif
bool found = false;
- for (uint32_t i = 0; i < animation_libraries.size(); i++) {
- ERR_FAIL_COND_MSG(animation_libraries[i].name == p_new_name, "Can't rename animation library to another existing name: " + String(p_new_name));
- if (animation_libraries[i].name == p_name) {
+ for (AnimationLibraryData &lib : animation_libraries) {
+ ERR_FAIL_COND_MSG(lib.name == p_new_name, "Can't rename animation library to another existing name: " + String(p_new_name));
+ if (lib.name == p_name) {
found = true;
- animation_libraries[i].name = p_new_name;
+ lib.name = p_new_name;
// rename connections
- animation_libraries[i].library->disconnect(SNAME("animation_added"), callable_mp(this, &AnimationPlayer::_animation_added));
- animation_libraries[i].library->disconnect(SNAME("animation_removed"), callable_mp(this, &AnimationPlayer::_animation_removed));
- animation_libraries[i].library->disconnect(SNAME("animation_renamed"), callable_mp(this, &AnimationPlayer::_animation_renamed));
+ lib.library->disconnect(SNAME("animation_added"), callable_mp(this, &AnimationPlayer::_animation_added));
+ lib.library->disconnect(SNAME("animation_removed"), callable_mp(this, &AnimationPlayer::_animation_removed));
+ lib.library->disconnect(SNAME("animation_renamed"), callable_mp(this, &AnimationPlayer::_animation_renamed));
- animation_libraries[i].library->connect(SNAME("animation_added"), callable_mp(this, &AnimationPlayer::_animation_added).bind(p_new_name));
- animation_libraries[i].library->connect(SNAME("animation_removed"), callable_mp(this, &AnimationPlayer::_animation_removed).bind(p_new_name));
- animation_libraries[i].library->connect(SNAME("animation_renamed"), callable_mp(this, &AnimationPlayer::_animation_renamed).bind(p_new_name));
+ lib.library->connect(SNAME("animation_added"), callable_mp(this, &AnimationPlayer::_animation_added).bind(p_new_name));
+ lib.library->connect(SNAME("animation_removed"), callable_mp(this, &AnimationPlayer::_animation_removed).bind(p_new_name));
+ lib.library->connect(SNAME("animation_renamed"), callable_mp(this, &AnimationPlayer::_animation_renamed).bind(p_new_name));
- for (const KeyValue<StringName, Ref<Animation>> &K : animation_libraries[i].library->animations) {
+ for (const KeyValue<StringName, Ref<Animation>> &K : lib.library->animations) {
StringName old_name = p_name == StringName() ? K.key : StringName(String(p_name) + "/" + String(K.key));
StringName new_name = p_new_name == StringName() ? K.key : StringName(String(p_new_name) + "/" + String(K.key));
_rename_animation(old_name, new_name);
@@ -1502,8 +1502,8 @@ void AnimationPlayer::rename_animation_library(const StringName &p_name, const S
}
bool AnimationPlayer::has_animation_library(const StringName &p_name) const {
- for (uint32_t i = 0; i < animation_libraries.size(); i++) {
- if (animation_libraries[i].name == p_name) {
+ for (const AnimationLibraryData &lib : animation_libraries) {
+ if (lib.name == p_name) {
return true;
}
}
@@ -1512,9 +1512,9 @@ bool AnimationPlayer::has_animation_library(const StringName &p_name) const {
}
Ref<AnimationLibrary> AnimationPlayer::get_animation_library(const StringName &p_name) const {
- for (uint32_t i = 0; i < animation_libraries.size(); i++) {
- if (animation_libraries[i].name == p_name) {
- return animation_libraries[i].library;
+ for (const AnimationLibraryData &lib : animation_libraries) {
+ if (lib.name == p_name) {
+ return lib.library;
}
}
ERR_FAIL_V(Ref<AnimationLibrary>());
@@ -1522,15 +1522,15 @@ Ref<AnimationLibrary> AnimationPlayer::get_animation_library(const StringName &p
TypedArray<StringName> AnimationPlayer::_get_animation_library_list() const {
TypedArray<StringName> ret;
- for (uint32_t i = 0; i < animation_libraries.size(); i++) {
- ret.push_back(animation_libraries[i].name);
+ for (const AnimationLibraryData &lib : animation_libraries) {
+ ret.push_back(lib.name);
}
return ret;
}
void AnimationPlayer::get_animation_library_list(List<StringName> *p_libraries) const {
- for (uint32_t i = 0; i < animation_libraries.size(); i++) {
- p_libraries->push_back(animation_libraries[i].name);
+ for (const AnimationLibraryData &lib : animation_libraries) {
+ p_libraries->push_back(lib.name);
}
}
diff --git a/scene/animation/animation_tree.cpp b/scene/animation/animation_tree.cpp
index dd00897422..077a5696bb 100644
--- a/scene/animation/animation_tree.cpp
+++ b/scene/animation/animation_tree.cpp
@@ -754,7 +754,7 @@ bool AnimationTree::_update_caches(AnimationPlayer *player) {
if (has_reset_anim) {
int rt = reset_anim->find_track(path, track_type);
if (rt >= 0 && reset_anim->track_get_key_count(rt) > 0) {
- track_bezier->init_value = reset_anim->track_get_key_value(rt, 0);
+ track_bezier->init_value = (reset_anim->track_get_key_value(rt, 0).operator Array())[0];
}
}
} break;
diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp
index d0326290ac..472299b135 100644
--- a/scene/gui/base_button.cpp
+++ b/scene/gui/base_button.cpp
@@ -385,6 +385,7 @@ void BaseButton::shortcut_input(const Ref<InputEvent> &p_event) {
if (shortcut_feedback) {
if (shortcut_feedback_timer == nullptr) {
shortcut_feedback_timer = memnew(Timer);
+ shortcut_feedback_timer->set_one_shot(true);
add_child(shortcut_feedback_timer);
shortcut_feedback_timer->set_wait_time(GLOBAL_GET("gui/timers/button_shortcut_feedback_highlight_time"));
shortcut_feedback_timer->connect("timeout", callable_mp(this, &BaseButton::_shortcut_feedback_timeout));
diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp
index b0261dcf23..2c5248f088 100644
--- a/scene/gui/color_picker.cpp
+++ b/scene/gui/color_picker.cpp
@@ -35,11 +35,6 @@
#include "core/os/keyboard.h"
#include "core/os/os.h"
#include "scene/gui/color_mode.h"
-
-#ifdef TOOLS_ENABLED
-#include "editor/editor_settings.h"
-#endif
-
#include "thirdparty/misc/ok_color.h"
#include "thirdparty/misc/ok_color_shader.h"
@@ -50,31 +45,6 @@ void ColorPicker::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
_update_color();
-#ifdef TOOLS_ENABLED
- if (Engine::get_singleton()->is_editor_hint()) {
- if (preset_cache.is_empty()) {
- PackedColorArray saved_presets = EditorSettings::get_singleton()->get_project_metadata("color_picker", "presets", PackedColorArray());
- for (int i = 0; i < saved_presets.size(); i++) {
- preset_cache.push_back(saved_presets[i]);
- }
- }
-
- for (int i = 0; i < preset_cache.size(); i++) {
- presets.push_back(preset_cache[i]);
- }
-
- if (recent_preset_cache.is_empty()) {
- PackedColorArray saved_recent_presets = EditorSettings::get_singleton()->get_project_metadata("color_picker", "recent_presets", PackedColorArray());
- for (int i = 0; i < saved_recent_presets.size(); i++) {
- recent_preset_cache.push_back(saved_recent_presets[i]);
- }
- }
-
- for (int i = 0; i < recent_preset_cache.size(); i++) {
- recent_presets.push_back(recent_preset_cache[i]);
- }
- }
-#endif
[[fallthrough]];
}
case NOTIFICATION_THEME_CHANGED: {
@@ -404,6 +374,40 @@ void ColorPicker::create_slider(GridContainer *gc, int idx) {
}
}
+#ifdef TOOLS_ENABLED
+void ColorPicker::set_editor_settings(Object *p_editor_settings) {
+ if (editor_settings) {
+ return;
+ }
+ editor_settings = p_editor_settings;
+
+ if (preset_cache.is_empty()) {
+ PackedColorArray saved_presets = editor_settings->call(SNAME("get_project_metadata"), "color_picker", "presets", PackedColorArray());
+ for (int i = 0; i < saved_presets.size(); i++) {
+ preset_cache.push_back(saved_presets[i]);
+ }
+ }
+
+ for (int i = 0; i < preset_cache.size(); i++) {
+ presets.push_back(preset_cache[i]);
+ }
+
+ if (recent_preset_cache.is_empty()) {
+ PackedColorArray saved_recent_presets = editor_settings->call(SNAME("get_project_metadata"), "color_picker", "recent_presets", PackedColorArray());
+ for (int i = 0; i < saved_recent_presets.size(); i++) {
+ recent_preset_cache.push_back(saved_recent_presets[i]);
+ }
+ }
+
+ for (int i = 0; i < recent_preset_cache.size(); i++) {
+ recent_presets.push_back(recent_preset_cache[i]);
+ }
+
+ _update_presets();
+ _update_recent_presets();
+}
+#endif
+
HSlider *ColorPicker::get_slider(int p_idx) {
if (p_idx < SLIDER_COUNT) {
return sliders[p_idx];
@@ -553,7 +557,7 @@ void ColorPicker::_update_presets() {
}
#ifdef TOOLS_ENABLED
- if (Engine::get_singleton()->is_editor_hint()) {
+ if (editor_settings) {
// Only load preset buttons when the only child is the add-preset button.
if (preset_container->get_child_count() == 1) {
for (int i = 0; i < preset_cache.size(); i++) {
@@ -567,7 +571,7 @@ void ColorPicker::_update_presets() {
void ColorPicker::_update_recent_presets() {
#ifdef TOOLS_ENABLED
- if (Engine::get_singleton()->is_editor_hint()) {
+ if (editor_settings) {
int recent_preset_count = recent_preset_hbc->get_child_count();
for (int i = 0; i < recent_preset_count; i++) {
memdelete(recent_preset_hbc->get_child(0));
@@ -743,9 +747,9 @@ void ColorPicker::add_preset(const Color &p_color) {
}
#ifdef TOOLS_ENABLED
- if (Engine::get_singleton()->is_editor_hint()) {
+ if (editor_settings) {
PackedColorArray arr_to_save = get_presets();
- EditorSettings::get_singleton()->set_project_metadata("color_picker", "presets", arr_to_save);
+ editor_settings->call(SNAME("set_project_metadata"), "color_picker", "presets", arr_to_save);
}
#endif
}
@@ -764,9 +768,9 @@ void ColorPicker::add_recent_preset(const Color &p_color) {
_select_from_preset_container(p_color);
#ifdef TOOLS_ENABLED
- if (Engine::get_singleton()->is_editor_hint()) {
+ if (editor_settings) {
PackedColorArray arr_to_save = get_recent_presets();
- EditorSettings::get_singleton()->set_project_metadata("color_picker", "recent_presets", arr_to_save);
+ editor_settings->call(SNAME("set_project_metadata"), "color_picker", "recent_presets", arr_to_save);
}
#endif
}
@@ -787,9 +791,9 @@ void ColorPicker::erase_preset(const Color &p_color) {
}
#ifdef TOOLS_ENABLED
- if (Engine::get_singleton()->is_editor_hint()) {
+ if (editor_settings) {
PackedColorArray arr_to_save = get_presets();
- EditorSettings::get_singleton()->set_project_metadata("color_picker", "presets", arr_to_save);
+ editor_settings->call(SNAME("set_project_metadata"), "color_picker", "presets", arr_to_save);
}
#endif
}
@@ -811,9 +815,9 @@ void ColorPicker::erase_recent_preset(const Color &p_color) {
}
#ifdef TOOLS_ENABLED
- if (Engine::get_singleton()->is_editor_hint()) {
+ if (editor_settings) {
PackedColorArray arr_to_save = get_recent_presets();
- EditorSettings::get_singleton()->set_project_metadata("color_picker", "recent_presets", arr_to_save);
+ editor_settings->call(SNAME("set_project_metadata"), "color_picker", "recent_presets", arr_to_save);
}
#endif
}
diff --git a/scene/gui/color_picker.h b/scene/gui/color_picker.h
index 5eaeecca2a..f7578612cd 100644
--- a/scene/gui/color_picker.h
+++ b/scene/gui/color_picker.h
@@ -100,6 +100,10 @@ private:
static List<Color> preset_cache;
static List<Color> recent_preset_cache;
+#ifdef TOOLS_ENABLED
+ Object *editor_settings = nullptr;
+#endif
+
int current_slider_count = SLIDER_COUNT;
static const int MODE_BUTTON_COUNT = 3;
@@ -231,6 +235,10 @@ protected:
static void _bind_methods();
public:
+#ifdef TOOLS_ENABLED
+ void set_editor_settings(Object *p_editor_settings);
+#endif
+
HSlider *get_slider(int idx);
Vector<float> get_active_slider_values();
diff --git a/scene/gui/popup.cpp b/scene/gui/popup.cpp
index c939e7a48a..2ea1b93810 100644
--- a/scene/gui/popup.cpp
+++ b/scene/gui/popup.cpp
@@ -59,9 +59,9 @@ void Popup::_initialize_visible_parents() {
void Popup::_deinitialize_visible_parents() {
if (is_embedded()) {
- for (uint32_t i = 0; i < visible_parents.size(); ++i) {
- visible_parents[i]->disconnect("focus_entered", callable_mp(this, &Popup::_parent_focused));
- visible_parents[i]->disconnect("tree_exited", callable_mp(this, &Popup::_deinitialize_visible_parents));
+ for (Window *parent_window : visible_parents) {
+ parent_window->disconnect("focus_entered", callable_mp(this, &Popup::_parent_focused));
+ parent_window->disconnect("tree_exited", callable_mp(this, &Popup::_deinitialize_visible_parents));
}
visible_parents.clear();
diff --git a/scene/main/canvas_item.cpp b/scene/main/canvas_item.cpp
index bf0a8f7b6c..7b0554442c 100644
--- a/scene/main/canvas_item.cpp
+++ b/scene/main/canvas_item.cpp
@@ -388,6 +388,16 @@ Color CanvasItem::get_modulate() const {
return modulate;
}
+Color CanvasItem::get_modulate_in_tree() const {
+ Color final_modulate = modulate;
+ CanvasItem *parent_item = get_parent_item();
+ while (parent_item) {
+ final_modulate *= parent_item->get_modulate();
+ parent_item = parent_item->get_parent_item();
+ }
+ return final_modulate;
+}
+
void CanvasItem::set_as_top_level(bool p_top_level) {
if (top_level == p_top_level) {
return;
diff --git a/scene/main/canvas_item.h b/scene/main/canvas_item.h
index a7e9fc3c79..644fe856ec 100644
--- a/scene/main/canvas_item.h
+++ b/scene/main/canvas_item.h
@@ -224,6 +224,7 @@ public:
void set_modulate(const Color &p_modulate);
Color get_modulate() const;
+ Color get_modulate_in_tree() const;
void set_self_modulate(const Color &p_self_modulate);
Color get_self_modulate() const;
diff --git a/scene/main/node.cpp b/scene/main/node.cpp
index eb57ccfef1..def91c424c 100644
--- a/scene/main/node.cpp
+++ b/scene/main/node.cpp
@@ -279,7 +279,10 @@ void Node::_propagate_exit_tree() {
//block while removing children
#ifdef DEBUG_ENABLED
- SceneDebugger::remove_from_cache(data.scene_file_path, this);
+ if (!data.scene_file_path.is_empty()) {
+ // Only remove if file path is set (optimization).
+ SceneDebugger::remove_from_cache(data.scene_file_path, this);
+ }
#endif
data.blocked++;
@@ -305,7 +308,6 @@ void Node::_propagate_exit_tree() {
}
// exit groups
-
for (KeyValue<StringName, GroupData> &E : data.grouped) {
data.tree->remove_from_group(E.key, this);
E.value.group = nullptr;
@@ -1166,7 +1168,7 @@ void Node::add_sibling(Node *p_sibling, bool p_force_readable_name) {
void Node::remove_child(Node *p_child) {
ERR_FAIL_NULL(p_child);
- ERR_FAIL_COND_MSG(data.blocked > 0, "Parent node is busy setting up children, `remove_child()` failed. Consider using `remove_child.call_deferred(child)` instead.");
+ ERR_FAIL_COND_MSG(data.blocked > 0, "Parent node is busy adding/removing children, `remove_child()` can't be called at this time. Consider using `remove_child.call_deferred(child)` instead.");
int child_count = data.children.size();
Node **children = data.children.ptrw();
@@ -1197,11 +1199,13 @@ void Node::remove_child(Node *p_child) {
data.internal_children_back--;
}
+ data.blocked++;
p_child->_set_tree(nullptr);
//}
remove_child_notify(p_child);
p_child->notification(NOTIFICATION_UNPARENTED);
+ data.blocked--;
data.children.remove_at(idx);
diff --git a/scene/main/window.cpp b/scene/main/window.cpp
index 4baedc8c14..2c6599d849 100644
--- a/scene/main/window.cpp
+++ b/scene/main/window.cpp
@@ -227,7 +227,7 @@ void Window::_validate_property(PropertyInfo &p_property) const {
p_property.usage = PROPERTY_USAGE_NONE;
}
- if (p_property.name == "current_screen" && initial_position != WINDOW_INITIAL_POSITION_CENTER_SCREEN) {
+ if (p_property.name == "current_screen" && initial_position != WINDOW_INITIAL_POSITION_CENTER_OTHER_SCREEN) {
p_property.usage = PROPERTY_USAGE_NONE;
}
@@ -482,7 +482,11 @@ void Window::_make_window() {
Rect2i window_rect;
if (initial_position == WINDOW_INITIAL_POSITION_ABSOLUTE) {
window_rect = Rect2i(position, size);
- } else if (initial_position == WINDOW_INITIAL_POSITION_CENTER_SCREEN) {
+ } else if (initial_position == WINDOW_INITIAL_POSITION_CENTER_PRIMARY_SCREEN) {
+ window_rect = Rect2i(DisplayServer::get_singleton()->screen_get_position(DisplayServer::SCREEN_PRIMARY) + (DisplayServer::get_singleton()->screen_get_size(DisplayServer::SCREEN_PRIMARY) - size) / 2, size);
+ } else if (initial_position == WINDOW_INITIAL_POSITION_CENTER_MAIN_WINDOW_SCREEN) {
+ window_rect = Rect2i(DisplayServer::get_singleton()->screen_get_position(DisplayServer::SCREEN_OF_MAIN_WINDOW) + (DisplayServer::get_singleton()->screen_get_size(DisplayServer::SCREEN_OF_MAIN_WINDOW) - size) / 2, size);
+ } else if (initial_position == WINDOW_INITIAL_POSITION_CENTER_OTHER_SCREEN) {
window_rect = Rect2i(DisplayServer::get_singleton()->screen_get_position(current_screen) + (DisplayServer::get_singleton()->screen_get_size(current_screen) - size) / 2, size);
}
window_id = DisplayServer::get_singleton()->create_sub_window(DisplayServer::WindowMode(mode), vsync_mode, f, window_rect);
@@ -2246,18 +2250,14 @@ void Window::_bind_methods() {
ClassDB::bind_method(D_METHOD("popup_centered", "minsize"), &Window::popup_centered, DEFVAL(Size2i()));
ClassDB::bind_method(D_METHOD("popup_centered_clamped", "minsize", "fallback_ratio"), &Window::popup_centered_clamped, DEFVAL(Size2i()), DEFVAL(0.75));
- ADD_PROPERTY(PropertyInfo(Variant::INT, "initial_position", PROPERTY_HINT_ENUM, "Absolute,Screen Center"), "set_initial_position", "get_initial_position");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "initial_position", PROPERTY_HINT_ENUM, "Absolute,Primary Screen Center,Main Window Screen Center,Other Screen Center"), "set_initial_position", "get_initial_position");
ADD_PROPERTY(PropertyInfo(Variant::STRING, "title"), "set_title", "get_title");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2I, "position", PROPERTY_HINT_NONE, "suffix:px"), "set_position", "get_position");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2I, "size", PROPERTY_HINT_NONE, "suffix:px"), "set_size", "get_size");
ADD_PROPERTY(PropertyInfo(Variant::INT, "mode", PROPERTY_HINT_ENUM, "Windowed,Minimized,Maximized,Fullscreen"), "set_mode", "get_mode");
// Keep the enum values in sync with the `DisplayServer::SCREEN_` enum.
- String screen_hints = "Primary Monitor:-2,Main Window Monitor:-1";
- for (int i = 0; i < 64; i++) {
- screen_hints += ",Monitor " + itos(i + 1) + ":" + itos(i);
- }
- ADD_PROPERTY(PropertyInfo(Variant::INT, "current_screen", PROPERTY_HINT_ENUM, screen_hints), "set_current_screen", "get_current_screen");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "current_screen", PROPERTY_HINT_RANGE, "0,64,1,or_greater"), "set_current_screen", "get_current_screen");
ADD_PROPERTY(PropertyInfo(Variant::PACKED_VECTOR2_ARRAY, "mouse_passthrough_polygon"), "set_mouse_passthrough_polygon", "get_mouse_passthrough_polygon");
@@ -2340,7 +2340,9 @@ void Window::_bind_methods() {
BIND_ENUM_CONSTANT(LAYOUT_DIRECTION_RTL);
BIND_ENUM_CONSTANT(WINDOW_INITIAL_POSITION_ABSOLUTE);
- BIND_ENUM_CONSTANT(WINDOW_INITIAL_POSITION_CENTER_SCREEN);
+ BIND_ENUM_CONSTANT(WINDOW_INITIAL_POSITION_CENTER_PRIMARY_SCREEN);
+ BIND_ENUM_CONSTANT(WINDOW_INITIAL_POSITION_CENTER_MAIN_WINDOW_SCREEN);
+ BIND_ENUM_CONSTANT(WINDOW_INITIAL_POSITION_CENTER_OTHER_SCREEN);
}
Window::Window() {
diff --git a/scene/main/window.h b/scene/main/window.h
index d819ca7c60..e9c217f973 100644
--- a/scene/main/window.h
+++ b/scene/main/window.h
@@ -90,14 +90,16 @@ public:
enum WindowInitialPosition {
WINDOW_INITIAL_POSITION_ABSOLUTE,
- WINDOW_INITIAL_POSITION_CENTER_SCREEN,
+ WINDOW_INITIAL_POSITION_CENTER_PRIMARY_SCREEN,
+ WINDOW_INITIAL_POSITION_CENTER_MAIN_WINDOW_SCREEN,
+ WINDOW_INITIAL_POSITION_CENTER_OTHER_SCREEN,
};
private:
DisplayServer::WindowID window_id = DisplayServer::INVALID_WINDOW_ID;
String title;
- mutable int current_screen = DisplayServer::SCREEN_PRIMARY;
+ mutable int current_screen = 0;
mutable Vector2i position;
mutable Size2i size = Size2i(DEFAULT_WINDOW_SIZE, DEFAULT_WINDOW_SIZE);
mutable Size2i min_size;
diff --git a/scene/resources/animation.cpp b/scene/resources/animation.cpp
index b371266c83..50f3015814 100644
--- a/scene/resources/animation.cpp
+++ b/scene/resources/animation.cpp
@@ -4754,17 +4754,17 @@ void Animation::compress(uint32_t p_page_size, uint32_t p_fps, float p_split_tol
// The frame has advanced, time to validate the previous frame
uint32_t current_page_size = base_page_size;
- for (uint32_t i = 0; i < data_tracks.size(); i++) {
- uint32_t track_size = data_tracks[i].data.size(); // track size
- track_size += data_tracks[i].get_temp_packet_size(); // Add the temporary data
+ for (const AnimationCompressionDataState &state : data_tracks) {
+ uint32_t track_size = state.data.size(); // track size
+ track_size += state.get_temp_packet_size(); // Add the temporary data
if (track_size > Compression::MAX_DATA_TRACK_SIZE) {
rollback = true; //track to large, time track can't point to keys any longer, because key offset is 12 bits
break;
}
current_page_size += track_size;
}
- for (uint32_t i = 0; i < time_tracks.size(); i++) {
- current_page_size += time_tracks[i].packets.size() * 4; // time packet is 32 bits
+ for (const AnimationCompressionTimeState &state : time_tracks) {
+ current_page_size += state.packets.size() * 4; // time packet is 32 bits
}
if (!rollback && current_page_size > p_page_size) {
@@ -4776,22 +4776,22 @@ void Animation::compress(uint32_t p_page_size, uint32_t p_fps, float p_split_tol
if (rollback) {
// Not valid any longer, so rollback and commit page
- for (uint32_t i = 0; i < data_tracks.size(); i++) {
- data_tracks[i].temp_packets.resize(data_tracks[i].validated_packet_count);
+ for (AnimationCompressionDataState &state : data_tracks) {
+ state.temp_packets.resize(state.validated_packet_count);
}
- for (uint32_t i = 0; i < time_tracks.size(); i++) {
- time_tracks[i].key_index = time_tracks[i].validated_key_index; //rollback key
- time_tracks[i].packets.resize(time_tracks[i].validated_packet_count);
+ for (AnimationCompressionTimeState &state : time_tracks) {
+ state.key_index = state.validated_key_index; //rollback key
+ state.packets.resize(state.validated_packet_count);
}
} else {
// All valid, so save rollback information
- for (uint32_t i = 0; i < data_tracks.size(); i++) {
- data_tracks[i].validated_packet_count = data_tracks[i].temp_packets.size();
+ for (AnimationCompressionDataState &state : data_tracks) {
+ state.validated_packet_count = state.temp_packets.size();
}
- for (uint32_t i = 0; i < time_tracks.size(); i++) {
- time_tracks[i].validated_key_index = time_tracks[i].key_index;
- time_tracks[i].validated_packet_count = time_tracks[i].packets.size();
+ for (AnimationCompressionTimeState &state : time_tracks) {
+ state.validated_key_index = state.key_index;
+ state.validated_packet_count = state.packets.size();
}
// Accept this frame as the frame being processed (as long as it exists)
@@ -4976,8 +4976,8 @@ void Animation::compress(uint32_t p_page_size, uint32_t p_fps, float p_split_tol
}
uint32_t new_size = 0;
- for (uint32_t i = 0; i < compression.pages.size(); i++) {
- new_size += compression.pages[i].data.size();
+ for (const Compression::Page &page : compression.pages) {
+ new_size += page.data.size();
}
print_line("Original size: " + itos(orig_size) + " - Compressed size: " + itos(new_size) + " " + String::num(float(new_size) / float(orig_size) * 100, 2) + "% pages: " + itos(compression.pages.size()));
@@ -5289,8 +5289,8 @@ int Animation::_get_compressed_key_count(uint32_t p_compressed_track) const {
int key_count = 0;
- for (uint32_t i = 0; i < compression.pages.size(); i++) {
- const uint8_t *page_data = compression.pages[i].data.ptr();
+ for (const Compression::Page &page : compression.pages) {
+ const uint8_t *page_data = page.data.ptr();
// Little endian assumed. No major big endian hardware exists any longer, but in case it does it will need to be supported.
const uint32_t *indices = (const uint32_t *)page_data;
const uint16_t *time_keys = (const uint16_t *)&page_data[indices[p_compressed_track * 3 + 0]];
@@ -5323,8 +5323,8 @@ bool Animation::_fetch_compressed_by_index(uint32_t p_compressed_track, int p_in
ERR_FAIL_COND_V(!compression.enabled, false);
ERR_FAIL_UNSIGNED_INDEX_V(p_compressed_track, compression.bounds.size(), false);
- for (uint32_t i = 0; i < compression.pages.size(); i++) {
- const uint8_t *page_data = compression.pages[i].data.ptr();
+ for (const Compression::Page &page : compression.pages) {
+ const uint8_t *page_data = page.data.ptr();
// Little endian assumed. No major big endian hardware exists any longer, but in case it does it will need to be supported.
const uint32_t *indices = (const uint32_t *)page_data;
const uint16_t *time_keys = (const uint16_t *)&page_data[indices[p_compressed_track * 3 + 0]];
@@ -5374,7 +5374,7 @@ bool Animation::_fetch_compressed_by_index(uint32_t p_compressed_track, int p_in
}
}
- r_time = compression.pages[i].time_offset + double(frame) / double(compression.fps);
+ r_time = page.time_offset + double(frame) / double(compression.fps);
for (uint32_t l = 0; l < COMPONENTS; l++) {
r_value[l] = decode[l];
}
diff --git a/scene/resources/immediate_mesh.cpp b/scene/resources/immediate_mesh.cpp
index f4a0db3930..48d609da97 100644
--- a/scene/resources/immediate_mesh.cpp
+++ b/scene/resources/immediate_mesh.cpp
@@ -41,8 +41,8 @@ void ImmediateMesh::surface_set_color(const Color &p_color) {
if (!uses_colors) {
colors.resize(vertices.size());
- for (uint32_t i = 0; i < colors.size(); i++) {
- colors[i] = p_color;
+ for (Color &color : colors) {
+ color = p_color;
}
uses_colors = true;
}
@@ -54,8 +54,8 @@ void ImmediateMesh::surface_set_normal(const Vector3 &p_normal) {
if (!uses_normals) {
normals.resize(vertices.size());
- for (uint32_t i = 0; i < normals.size(); i++) {
- normals[i] = p_normal;
+ for (Vector3 &normal : normals) {
+ normal = p_normal;
}
uses_normals = true;
}
@@ -66,8 +66,8 @@ void ImmediateMesh::surface_set_tangent(const Plane &p_tangent) {
ERR_FAIL_COND_MSG(!surface_active, "Not creating any surface. Use surface_begin() to do it.");
if (!uses_tangents) {
tangents.resize(vertices.size());
- for (uint32_t i = 0; i < tangents.size(); i++) {
- tangents[i] = p_tangent;
+ for (Plane &tangent : tangents) {
+ tangent = p_tangent;
}
uses_tangents = true;
}
@@ -78,8 +78,8 @@ void ImmediateMesh::surface_set_uv(const Vector2 &p_uv) {
ERR_FAIL_COND_MSG(!surface_active, "Not creating any surface. Use surface_begin() to do it.");
if (!uses_uvs) {
uvs.resize(vertices.size());
- for (uint32_t i = 0; i < uvs.size(); i++) {
- uvs[i] = p_uv;
+ for (Vector2 &uv : uvs) {
+ uv = p_uv;
}
uses_uvs = true;
}
@@ -90,8 +90,8 @@ void ImmediateMesh::surface_set_uv2(const Vector2 &p_uv2) {
ERR_FAIL_COND_MSG(!surface_active, "Not creating any surface. Use surface_begin() to do it.");
if (!uses_uv2s) {
uv2s.resize(vertices.size());
- for (uint32_t i = 0; i < uv2s.size(); i++) {
- uv2s[i] = p_uv2;
+ for (Vector2 &uv : uv2s) {
+ uv = p_uv2;
}
uses_uv2s = true;
}
diff --git a/scene/resources/importer_mesh.cpp b/scene/resources/importer_mesh.cpp
index eefa5aa14a..55b633a40c 100644
--- a/scene/resources/importer_mesh.cpp
+++ b/scene/resources/importer_mesh.cpp
@@ -364,9 +364,7 @@ void ImporterMesh::generate_lods(float p_normal_merge_angle, float p_normal_spli
const LocalVector<Pair<int, int>> &close_verts = E->value;
bool found = false;
- for (unsigned int k = 0; k < close_verts.size(); k++) {
- const Pair<int, int> &idx = close_verts[k];
-
+ for (const Pair<int, int> &idx : close_verts) {
bool is_uvs_close = (!uvs_ptr || uvs_ptr[j].distance_squared_to(uvs_ptr[idx.second]) < CMP_EPSILON2);
bool is_uv2s_close = (!uv2s_ptr || uv2s_ptr[j].distance_squared_to(uv2s_ptr[idx.second]) < CMP_EPSILON2);
ERR_FAIL_INDEX(idx.second, normals.size());
@@ -599,8 +597,7 @@ void ImporterMesh::generate_lods(float p_normal_merge_angle, float p_normal_spli
const LocalVector<int> &corners = vertex_corners[j];
const Vector3 &vertex_normal = normals_ptr[j];
- for (unsigned int k = 0; k < corners.size(); k++) {
- const int &corner_idx = corners[k];
+ for (const int &corner_idx : corners) {
const Vector3 &ray_normal = ray_normals[corner_idx];
if (ray_normal.length_squared() < CMP_EPSILON2) {
@@ -635,8 +632,8 @@ void ImporterMesh::generate_lods(float p_normal_merge_angle, float p_normal_spli
split_vertex_indices.push_back(j);
split_vertex_normals.push_back(n);
int new_idx = split_vertex_count++;
- for (unsigned int l = 0; l < group_indices.size(); l++) {
- new_indices_ptr[group_indices[l]] = new_idx;
+ for (const int &index : group_indices) {
+ new_indices_ptr[index] = new_idx;
}
}
}
@@ -1241,10 +1238,10 @@ Error ImporterMesh::lightmap_unwrap_cached(const Transform3D &p_base_transform,
}
//generate surfaces
- for (unsigned int i = 0; i < surfaces_tools.size(); i++) {
- surfaces_tools[i]->index();
- Array arrays = surfaces_tools[i]->commit_to_arrays();
- add_surface(surfaces_tools[i]->get_primitive_type(), arrays, Array(), Dictionary(), surfaces_tools[i]->get_material(), surfaces_tools[i]->get_meta("name"));
+ for (Ref<SurfaceTool> &tool : surfaces_tools) {
+ tool->index();
+ Array arrays = tool->commit_to_arrays();
+ add_surface(tool->get_primitive_type(), arrays, Array(), Dictionary(), tool->get_material(), tool->get_meta("name"));
}
set_lightmap_size_hint(Size2(size_x, size_y));
diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp
index 3e2a952ea7..db7385428b 100644
--- a/scene/resources/material.cpp
+++ b/scene/resources/material.cpp
@@ -149,11 +149,36 @@ Material::~Material() {
bool ShaderMaterial::_set(const StringName &p_name, const Variant &p_value) {
if (shader.is_valid()) {
- StringName pr = shader->remap_parameter(p_name);
- if (pr) {
- set_shader_parameter(pr, p_value);
+ const StringName *sn = remap_cache.getptr(p_name);
+ if (sn) {
+ set_shader_parameter(*sn, p_value);
+ return true;
+ }
+ String s = p_name;
+ if (s.begins_with("shader_parameter/")) {
+ String param = s.replace_first("shader_parameter/", "");
+ remap_cache[s] = param;
+ set_shader_parameter(param, p_value);
return true;
}
+#ifndef DISABLE_DEPRECATED
+ // Compatibility remaps are only needed here.
+ if (s.begins_with("param/")) {
+ s = s.replace_first("param/", "shader_parameter/");
+ } else if (s.begins_with("shader_param/")) {
+ s = s.replace_first("shader_param/", "shader_parameter/");
+ } else if (s.begins_with("shader_uniform/")) {
+ s = s.replace_first("shader_uniform/", "shader_parameter/");
+ } else {
+ return false; // Not a shader parameter.
+ }
+
+ WARN_PRINT("This material (containing shader with path: '" + shader->get_path() + "') uses an old deprecated parameter names. Consider re-saving this resource (or scene which contains it) in order for it to continue working in future versions.");
+ String param = s.replace_first("shader_parameter/", "");
+ remap_cache[s] = param;
+ set_shader_parameter(param, p_value);
+ return true;
+#endif
}
return false;
@@ -161,9 +186,10 @@ bool ShaderMaterial::_set(const StringName &p_name, const Variant &p_value) {
bool ShaderMaterial::_get(const StringName &p_name, Variant &r_ret) const {
if (shader.is_valid()) {
- StringName pr = shader->remap_parameter(p_name);
- if (pr) {
- r_ret = get_shader_parameter(pr);
+ const StringName *sn = remap_cache.getptr(p_name);
+ if (sn) {
+ // Only return a parameter if it was previosly set.
+ r_ret = get_shader_parameter(*sn);
return true;
}
}
@@ -247,6 +273,12 @@ void ShaderMaterial::_get_property_list(List<PropertyInfo> *p_list) const {
PropertyInfo info = E->get();
info.name = "shader_parameter/" + info.name;
+ if (!param_cache.has(E->get().name)) {
+ // Property has never been edited, retrieve with default value.
+ Variant default_value = RenderingServer::get_singleton()->shader_get_parameter_default(shader->get_rid(), E->get().name);
+ param_cache.insert(E->get().name, default_value);
+ remap_cache.insert(info.name, E->get().name);
+ }
groups[last_group][last_subgroup].push_back(info);
}
@@ -275,11 +307,10 @@ void ShaderMaterial::_get_property_list(List<PropertyInfo> *p_list) const {
bool ShaderMaterial::_property_can_revert(const StringName &p_name) const {
if (shader.is_valid()) {
- StringName pr = shader->remap_parameter(p_name);
+ const StringName *pr = remap_cache.getptr(p_name);
if (pr) {
- Variant default_value = RenderingServer::get_singleton()->shader_get_parameter_default(shader->get_rid(), pr);
- Variant current_value;
- _get(p_name, current_value);
+ Variant default_value = RenderingServer::get_singleton()->shader_get_parameter_default(shader->get_rid(), *pr);
+ Variant current_value = get_shader_parameter(*pr);
return default_value.get_type() != Variant::NIL && default_value != current_value;
}
}
@@ -288,9 +319,9 @@ bool ShaderMaterial::_property_can_revert(const StringName &p_name) const {
bool ShaderMaterial::_property_get_revert(const StringName &p_name, Variant &r_property) const {
if (shader.is_valid()) {
- StringName pr = shader->remap_parameter(p_name);
- if (pr) {
- r_property = RenderingServer::get_singleton()->shader_get_parameter_default(shader->get_rid(), pr);
+ const StringName *pr = remap_cache.getptr(p_name);
+ if (*pr) {
+ r_property = RenderingServer::get_singleton()->shader_get_parameter_default(shader->get_rid(), *pr);
return true;
}
}
diff --git a/scene/resources/material.h b/scene/resources/material.h
index f1777d31f4..83c7a09cc4 100644
--- a/scene/resources/material.h
+++ b/scene/resources/material.h
@@ -82,7 +82,8 @@ class ShaderMaterial : public Material {
GDCLASS(ShaderMaterial, Material);
Ref<Shader> shader;
- HashMap<StringName, Variant> param_cache;
+ mutable HashMap<StringName, StringName> remap_cache;
+ mutable HashMap<StringName, Variant> param_cache;
protected:
bool _set(const StringName &p_name, const Variant &p_value);
diff --git a/scene/resources/mesh_library.cpp b/scene/resources/mesh_library.cpp
index d45b8a9295..015eb0fa45 100644
--- a/scene/resources/mesh_library.cpp
+++ b/scene/resources/mesh_library.cpp
@@ -139,7 +139,6 @@ void MeshLibrary::set_item_name(int p_item, const String &p_name) {
ERR_FAIL_COND_MSG(!item_map.has(p_item), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'.");
item_map[p_item].name = p_name;
emit_changed();
- notify_property_list_changed();
}
void MeshLibrary::set_item_mesh(int p_item, const Ref<Mesh> &p_mesh) {
@@ -155,7 +154,6 @@ void MeshLibrary::set_item_mesh_transform(int p_item, const Transform3D &p_trans
item_map[p_item].mesh_transform = p_transform;
notify_change_to_owners();
emit_changed();
- notify_property_list_changed();
}
void MeshLibrary::set_item_shapes(int p_item, const Vector<ShapeData> &p_shapes) {
@@ -190,7 +188,6 @@ void MeshLibrary::set_item_navigation_layers(int p_item, uint32_t p_navigation_l
notify_property_list_changed();
notify_change_to_owners();
emit_changed();
- notify_property_list_changed();
}
void MeshLibrary::set_item_preview(int p_item, const Ref<Texture2D> &p_preview) {
diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp
index 514e7eb260..c24186a109 100644
--- a/scene/resources/packed_scene.cpp
+++ b/scene/resources/packed_scene.cpp
@@ -402,8 +402,7 @@ Node *SceneState::instantiate(GenEditState p_edit_state) const {
}
}
- for (uint32_t i = 0; i < deferred_node_paths.size(); i++) {
- const DeferredNodePathProperties &dnp = deferred_node_paths[i];
+ for (const DeferredNodePathProperties &dnp : deferred_node_paths) {
Node *other = dnp.base->get_node_or_null(dnp.path);
dnp.base->set(dnp.property, other);
}
diff --git a/scene/resources/resource_format_text.cpp b/scene/resources/resource_format_text.cpp
index 2e8b4f93be..0ba177f882 100644
--- a/scene/resources/resource_format_text.cpp
+++ b/scene/resources/resource_format_text.cpp
@@ -923,7 +923,11 @@ Error ResourceLoaderText::rename_dependencies(Ref<FileAccess> p_f, const String
if (is_scene) {
fw->store_line("[gd_scene load_steps=" + itos(resources_total) + " format=" + itos(FORMAT_VERSION) + "]\n");
} else {
- fw->store_line("[gd_resource type=\"" + res_type + "\" load_steps=" + itos(resources_total) + " format=" + itos(FORMAT_VERSION) + "]\n");
+ String script_res_text;
+ if (!script_class.is_empty()) {
+ script_res_text = "script_class=\"" + script_class + "\" ";
+ }
+ fw->store_line("[gd_resource type=\"" + res_type + "\" " + script_res_text + "load_steps=" + itos(resources_total) + " format=" + itos(FORMAT_VERSION) + "]\n");
}
}
@@ -1047,6 +1051,10 @@ void ResourceLoaderText::open(Ref<FileAccess> p_f, bool p_skip_first_tag) {
return;
}
+ if (tag.fields.has("script_class")) {
+ script_class = tag.fields["script_class"];
+ }
+
res_type = tag.fields["type"];
} else {
@@ -1493,6 +1501,44 @@ Error ResourceLoaderText::get_classes_used(HashSet<StringName> *r_classes) {
return OK;
}
+String ResourceLoaderText::recognize_script_class(Ref<FileAccess> p_f) {
+ error = OK;
+
+ lines = 1;
+ f = p_f;
+
+ stream.f = f;
+
+ ignore_resource_parsing = true;
+
+ VariantParser::Tag tag;
+ Error err = VariantParser::parse_tag(&stream, lines, error_text, tag);
+
+ if (err) {
+ _printerr();
+ return "";
+ }
+
+ if (tag.fields.has("format")) {
+ int fmt = tag.fields["format"];
+ if (fmt > FORMAT_VERSION) {
+ error_text = "Saved with newer format version";
+ _printerr();
+ return "";
+ }
+ }
+
+ if (tag.name != "gd_resource") {
+ return "";
+ }
+
+ if (tag.fields.has("script_class")) {
+ return tag.fields["script_class"];
+ }
+
+ return "";
+}
+
String ResourceLoaderText::recognize(Ref<FileAccess> p_f) {
error = OK;
@@ -1662,6 +1708,25 @@ String ResourceFormatLoaderText::get_resource_type(const String &p_path) const {
return ClassDB::get_compatibility_remapped_class(r);
}
+String ResourceFormatLoaderText::get_resource_script_class(const String &p_path) const {
+ String ext = p_path.get_extension().to_lower();
+ if (ext != "tres") {
+ return String();
+ }
+
+ // ...for anything else must test...
+
+ Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::READ);
+ if (f.is_null()) {
+ return ""; //could not read
+ }
+
+ ResourceLoaderText 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 ResourceFormatLoaderText::get_resource_uid(const String &p_path) const {
String ext = p_path.get_extension().to_lower();
@@ -1905,7 +1970,12 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const Ref<Reso
String title = packed_scene.is_valid() ? "[gd_scene " : "[gd_resource ";
if (packed_scene.is_null()) {
title += "type=\"" + _resource_get_class(p_resource) + "\" ";
+ Ref<Script> script = p_resource->get_script();
+ if (script.is_valid() && script->get_global_name()) {
+ title += "script_class=\"" + String(script->get_global_name()) + "\" ";
+ }
}
+
int load_steps = saved_resources.size() + external_resources.size();
if (load_steps > 1) {
@@ -2244,7 +2314,12 @@ Error ResourceLoaderText::set_uid(Ref<FileAccess> p_f, ResourceUID::ID p_uid) {
if (is_scene) {
fw->store_string("[gd_scene load_steps=" + itos(resources_total) + " format=" + itos(FORMAT_VERSION) + " uid=\"" + ResourceUID::get_singleton()->id_to_text(p_uid) + "\"]");
} else {
- fw->store_string("[gd_resource type=\"" + res_type + "\" load_steps=" + itos(resources_total) + " format=" + itos(FORMAT_VERSION) + " uid=\"" + ResourceUID::get_singleton()->id_to_text(p_uid) + "\"]");
+ String script_res_text;
+ if (!script_class.is_empty()) {
+ script_res_text = "script_class=\"" + script_class + "\" ";
+ }
+
+ fw->store_string("[gd_resource type=\"" + res_type + "\" " + script_res_text + "load_steps=" + itos(resources_total) + " format=" + itos(FORMAT_VERSION) + " uid=\"" + ResourceUID::get_singleton()->id_to_text(p_uid) + "\"]");
}
uint8_t c = f->get_8();
diff --git a/scene/resources/resource_format_text.h b/scene/resources/resource_format_text.h
index 0cced3d20c..25001d8023 100644
--- a/scene/resources/resource_format_text.h
+++ b/scene/resources/resource_format_text.h
@@ -64,6 +64,7 @@ class ResourceLoaderText {
int resources_total = 0;
int resource_current = 0;
String resource_type;
+ String script_class;
VariantParser::Tag next_tag;
@@ -124,6 +125,7 @@ public:
void open(Ref<FileAccess> p_f, bool p_skip_first_tag = false);
String recognize(Ref<FileAccess> p_f);
+ String recognize_script_class(Ref<FileAccess> p_f);
ResourceUID::ID get_uid(Ref<FileAccess> p_f);
void get_dependencies(Ref<FileAccess> p_f, List<String> *p_dependencies, bool p_add_types);
Error rename_dependencies(Ref<FileAccess> p_f, const String &p_path, const HashMap<String, String> &p_map);
@@ -143,6 +145,7 @@ public:
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);
diff --git a/scene/resources/shader.cpp b/scene/resources/shader.cpp
index 9bb2db17ab..b3952e745f 100644
--- a/scene/resources/shader.cpp
+++ b/scene/resources/shader.cpp
@@ -43,7 +43,6 @@ Shader::Mode Shader::get_mode() const {
void Shader::_dependency_changed() {
RenderingServer::get_singleton()->shader_set_code(shader, RenderingServer::get_singleton()->shader_get_code(shader));
- params_cache_dirty = true;
emit_changed();
}
@@ -93,7 +92,6 @@ void Shader::set_code(const String &p_code) {
}
RenderingServer::get_singleton()->shader_set_code(shader, pp_code);
- params_cache_dirty = true;
emit_changed();
}
@@ -108,8 +106,6 @@ void Shader::get_shader_uniform_list(List<PropertyInfo> *p_params, bool p_get_gr
List<PropertyInfo> local;
RenderingServer::get_singleton()->get_shader_parameter_list(shader, &local);
- params_cache.clear();
- params_cache_dirty = false;
for (PropertyInfo &pi : local) {
bool is_group = pi.usage == PROPERTY_USAGE_GROUP || pi.usage == PROPERTY_USAGE_SUBGROUP;
@@ -120,7 +116,6 @@ void Shader::get_shader_uniform_list(List<PropertyInfo> *p_params, bool p_get_gr
if (default_textures.has(pi.name)) { //do not show default textures
continue;
}
- params_cache[pi.name] = pi.name;
}
if (p_params) {
//small little hack
@@ -176,11 +171,17 @@ bool Shader::is_text_shader() const {
return true;
}
-bool Shader::has_parameter(const StringName &p_name) const {
- return params_cache.has(p_name);
+void Shader::_update_shader() const {
}
-void Shader::_update_shader() const {
+Array Shader::_get_shader_uniform_list(bool p_get_groups) {
+ List<PropertyInfo> uniform_list;
+ get_shader_uniform_list(&uniform_list, p_get_groups);
+ Array ret;
+ for (const PropertyInfo &pi : uniform_list) {
+ ret.push_back(pi.operator Dictionary());
+ }
+ return ret;
}
void Shader::_bind_methods() {
@@ -192,7 +193,7 @@ void Shader::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_default_texture_parameter", "name", "texture", "index"), &Shader::set_default_texture_parameter, DEFVAL(0));
ClassDB::bind_method(D_METHOD("get_default_texture_parameter", "name", "index"), &Shader::get_default_texture_parameter, DEFVAL(0));
- ClassDB::bind_method(D_METHOD("has_parameter", "name"), &Shader::has_parameter);
+ ClassDB::bind_method(D_METHOD("get_shader_uniform_list", "get_groups"), &Shader::_get_shader_uniform_list, DEFVAL(false));
ADD_PROPERTY(PropertyInfo(Variant::STRING, "code", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_code", "get_code");
diff --git a/scene/resources/shader.h b/scene/resources/shader.h
index e579c2fca1..75c490e912 100644
--- a/scene/resources/shader.h
+++ b/scene/resources/shader.h
@@ -57,15 +57,12 @@ private:
HashSet<Ref<ShaderInclude>> include_dependencies;
String code;
- // hack the name of performance
- // shaders keep a list of ShaderMaterial -> RenderingServer name translations, to make
- // conversion fast and save memory.
- mutable bool params_cache_dirty = true;
- mutable HashMap<StringName, StringName> params_cache; //map a shader param to a material param..
HashMap<StringName, HashMap<int, Ref<Texture2D>>> default_textures;
void _dependency_changed();
virtual void _update_shader() const; //used for visual shader
+ Array _get_shader_uniform_list(bool p_get_groups = false);
+
protected:
static void _bind_methods();
@@ -79,7 +76,6 @@ public:
String get_code() const;
void get_shader_uniform_list(List<PropertyInfo> *p_params, bool p_get_groups = false) const;
- bool has_parameter(const StringName &p_name) const;
void set_default_texture_parameter(const StringName &p_name, const Ref<Texture2D> &p_texture, int p_index = 0);
Ref<Texture2D> get_default_texture_parameter(const StringName &p_name, int p_index = 0) const;
@@ -87,47 +83,6 @@ public:
virtual bool is_text_shader() const;
- // Finds the shader parameter name for the given property name, which should start with "shader_parameter/".
- _FORCE_INLINE_ StringName remap_parameter(const StringName &p_property) const {
- if (params_cache_dirty) {
- get_shader_uniform_list(nullptr);
- }
-
- String n = p_property;
-
- // Backwards compatibility with old shader parameter names.
- // Note: The if statements are important to make sure we are only replacing text exactly at index 0.
- if (n.find("param/") == 0) {
- n = n.replace_first("param/", "shader_parameter/");
- }
- if (n.find("shader_param/") == 0) {
- n = n.replace_first("shader_param/", "shader_parameter/");
- }
- if (n.find("shader_uniform/") == 0) {
- n = n.replace_first("shader_uniform/", "shader_parameter/");
- }
-
- {
- // Additional backwards compatibility for projects between #62972 and #64092 (about a month of v4.0 development).
- // These projects did not have any prefix for shader uniforms due to a bug.
- // This code should be removed during beta or rc of 4.0.
- const HashMap<StringName, StringName>::Iterator E = params_cache.find(n);
- if (E) {
- return E->value;
- }
- }
-
- if (n.begins_with("shader_parameter/")) {
- n = n.replace_first("shader_parameter/", "");
- const HashMap<StringName, StringName>::Iterator E = params_cache.find(n);
- if (E) {
- return E->value;
- }
- }
-
- return StringName();
- }
-
virtual RID get_rid() const override;
Shader();
diff --git a/scene/resources/surface_tool.cpp b/scene/resources/surface_tool.cpp
index e802e1c2d9..17e92ddfca 100644
--- a/scene/resources/surface_tool.cpp
+++ b/scene/resources/surface_tool.cpp
@@ -732,13 +732,13 @@ void SurfaceTool::index() {
LocalVector<Vertex> old_vertex_array = vertex_array;
vertex_array.clear();
- for (uint32_t i = 0; i < old_vertex_array.size(); i++) {
- int *idxptr = indices.getptr(old_vertex_array[i]);
+ for (const Vertex &vertex : old_vertex_array) {
+ int *idxptr = indices.getptr(vertex);
int idx;
if (!idxptr) {
idx = indices.size();
- vertex_array.push_back(old_vertex_array[i]);
- indices[old_vertex_array[i]] = idx;
+ vertex_array.push_back(vertex);
+ indices[vertex] = idx;
} else {
idx = *idxptr;
}
@@ -756,9 +756,8 @@ void SurfaceTool::deindex() {
LocalVector<Vertex> old_vertex_array = vertex_array;
vertex_array.clear();
- for (uint32_t i = 0; i < index_array.size(); i++) {
- uint32_t index = index_array[i];
- ERR_FAIL_COND(index >= old_vertex_array.size());
+ for (const int &index : index_array) {
+ ERR_FAIL_COND(uint32_t(index) >= old_vertex_array.size());
vertex_array.push_back(old_vertex_array[index]);
}
format &= ~Mesh::ARRAY_FORMAT_INDEX;
@@ -1000,8 +999,7 @@ void SurfaceTool::append_from(const Ref<Mesh> &p_existing, int p_surface, const
}
int vfrom = vertex_array.size();
- for (uint32_t vi = 0; vi < nvertices.size(); vi++) {
- Vertex v = nvertices[vi];
+ for (Vertex &v : nvertices) {
v.vertex = p_xform.xform(v.vertex);
if (nformat & RS::ARRAY_FORMAT_NORMAL) {
v.normal = p_xform.basis.xform(v.normal);
@@ -1014,8 +1012,8 @@ void SurfaceTool::append_from(const Ref<Mesh> &p_existing, int p_surface, const
vertex_array.push_back(v);
}
- for (uint32_t i = 0; i < nindices.size(); i++) {
- int dst_index = nindices[i] + vfrom;
+ for (const int &index : nindices) {
+ int dst_index = index + vfrom;
index_array.push_back(dst_index);
}
if (index_array.size() % 3) {
@@ -1132,9 +1130,9 @@ void SurfaceTool::generate_tangents() {
TangentGenerationContextUserData triangle_data;
triangle_data.vertices = &vertex_array;
- for (uint32_t i = 0; i < vertex_array.size(); i++) {
- vertex_array[i].binormal = Vector3();
- vertex_array[i].tangent = Vector3();
+ for (Vertex &vertex : vertex_array) {
+ vertex.binormal = Vector3();
+ vertex.tangent = Vector3();
}
triangle_data.indices = &index_array;
msc.m_pUserData = &triangle_data;
@@ -1176,12 +1174,12 @@ void SurfaceTool::generate_normals(bool p_flip) {
}
}
- for (uint32_t vi = 0; vi < vertex_array.size(); vi++) {
- Vector3 *lv = vertex_hash.getptr(vertex_array[vi]);
+ for (Vertex &vertex : vertex_array) {
+ Vector3 *lv = vertex_hash.getptr(vertex);
if (!lv) {
- vertex_array[vi].normal = Vector3();
+ vertex.normal = Vector3();
} else {
- vertex_array[vi].normal = lv->normalized();
+ vertex.normal = lv->normalized();
}
}
diff --git a/scene/resources/text_paragraph.cpp b/scene/resources/text_paragraph.cpp
index 6d66c48b78..dfafc7d2bc 100644
--- a/scene/resources/text_paragraph.cpp
+++ b/scene/resources/text_paragraph.cpp
@@ -135,8 +135,8 @@ void TextParagraph::_bind_methods() {
void TextParagraph::_shape_lines() {
if (lines_dirty) {
- for (int i = 0; i < (int)lines_rid.size(); i++) {
- TS->free_rid(lines_rid[i]);
+ for (const RID &line_rid : lines_rid) {
+ TS->free_rid(line_rid);
}
lines_rid.clear();
@@ -234,14 +234,14 @@ void TextParagraph::_shape_lines() {
} else {
// Autowrap disabled.
- for (int i = 0; i < (int)lines_rid.size(); i++) {
+ for (const RID &line_rid : lines_rid) {
if (alignment == HORIZONTAL_ALIGNMENT_FILL) {
- TS->shaped_text_fit_to_width(lines_rid[i], width, jst_flags);
+ TS->shaped_text_fit_to_width(line_rid, width, jst_flags);
overrun_flags.set_flag(TextServer::OVERRUN_JUSTIFICATION_AWARE);
- TS->shaped_text_overrun_trim_to_width(lines_rid[i], width, overrun_flags);
- TS->shaped_text_fit_to_width(lines_rid[i], width, jst_flags | TextServer::JUSTIFICATION_CONSTRAIN_ELLIPSIS);
+ TS->shaped_text_overrun_trim_to_width(line_rid, width, overrun_flags);
+ TS->shaped_text_fit_to_width(line_rid, width, jst_flags | TextServer::JUSTIFICATION_CONSTRAIN_ELLIPSIS);
} else {
- TS->shaped_text_overrun_trim_to_width(lines_rid[i], width, overrun_flags);
+ TS->shaped_text_overrun_trim_to_width(line_rid, width, overrun_flags);
}
}
}
@@ -268,8 +268,8 @@ RID TextParagraph::get_dropcap_rid() const {
void TextParagraph::clear() {
_THREAD_SAFE_METHOD_
- for (int i = 0; i < (int)lines_rid.size(); i++) {
- TS->free_rid(lines_rid[i]);
+ for (const RID &line_rid : lines_rid) {
+ TS->free_rid(line_rid);
}
lines_rid.clear();
TS->shaped_text_clear(rid);
@@ -915,17 +915,17 @@ int TextParagraph::hit_test(const Point2 &p_coords) const {
return 0;
}
}
- for (int i = 0; i < (int)lines_rid.size(); i++) {
- if (TS->shaped_text_get_orientation(lines_rid[i]) == TextServer::ORIENTATION_HORIZONTAL) {
- if ((p_coords.y >= ofs.y) && (p_coords.y <= ofs.y + TS->shaped_text_get_size(lines_rid[i]).y)) {
- return TS->shaped_text_hit_test_position(lines_rid[i], p_coords.x);
+ for (const RID &line_rid : lines_rid) {
+ if (TS->shaped_text_get_orientation(line_rid) == TextServer::ORIENTATION_HORIZONTAL) {
+ if ((p_coords.y >= ofs.y) && (p_coords.y <= ofs.y + TS->shaped_text_get_size(line_rid).y)) {
+ return TS->shaped_text_hit_test_position(line_rid, p_coords.x);
}
- ofs.y += TS->shaped_text_get_size(lines_rid[i]).y;
+ ofs.y += TS->shaped_text_get_size(line_rid).y;
} else {
- if ((p_coords.x >= ofs.x) && (p_coords.x <= ofs.x + TS->shaped_text_get_size(lines_rid[i]).x)) {
- return TS->shaped_text_hit_test_position(lines_rid[i], p_coords.y);
+ if ((p_coords.x >= ofs.x) && (p_coords.x <= ofs.x + TS->shaped_text_get_size(line_rid).x)) {
+ return TS->shaped_text_hit_test_position(line_rid, p_coords.y);
}
- ofs.y += TS->shaped_text_get_size(lines_rid[i]).x;
+ ofs.y += TS->shaped_text_get_size(line_rid).x;
}
}
return TS->shaped_text_get_range(rid).y;
@@ -1027,8 +1027,8 @@ TextParagraph::TextParagraph() {
}
TextParagraph::~TextParagraph() {
- for (int i = 0; i < (int)lines_rid.size(); i++) {
- TS->free_rid(lines_rid[i]);
+ for (const RID &line_rid : lines_rid) {
+ TS->free_rid(line_rid);
}
lines_rid.clear();
TS->free_rid(rid);
diff --git a/scene/resources/tile_set.cpp b/scene/resources/tile_set.cpp
index 94e78fc3aa..b5a68ef14b 100644
--- a/scene/resources/tile_set.cpp
+++ b/scene/resources/tile_set.cpp
@@ -404,8 +404,8 @@ void TileSet::_update_terrains_cache() {
if (terrains_cache_dirty) {
// Organizes tiles into structures.
per_terrain_pattern_tiles.resize(terrain_sets.size());
- for (int i = 0; i < (int)per_terrain_pattern_tiles.size(); i++) {
- per_terrain_pattern_tiles[i].clear();
+ for (RBMap<TileSet::TerrainsPattern, RBSet<TileMapCell>> &tiles : per_terrain_pattern_tiles) {
+ tiles.clear();
}
for (const KeyValue<int, Ref<TileSetSource>> &kv : sources) {
@@ -1342,8 +1342,8 @@ void TileSet::clear_tile_proxies() {
int TileSet::add_pattern(Ref<TileMapPattern> p_pattern, int p_index) {
ERR_FAIL_COND_V(!p_pattern.is_valid(), -1);
ERR_FAIL_COND_V_MSG(p_pattern->is_empty(), -1, "Cannot add an empty pattern to the TileSet.");
- for (unsigned int i = 0; i < patterns.size(); i++) {
- ERR_FAIL_COND_V_MSG(patterns[i] == p_pattern, -1, "TileSet has already this pattern.");
+ for (const Ref<TileMapPattern> &pattern : patterns) {
+ ERR_FAIL_COND_V_MSG(pattern == p_pattern, -1, "TileSet has already this pattern.");
}
ERR_FAIL_COND_V(p_index > (int)patterns.size(), -1);
if (p_index < 0) {
@@ -4190,8 +4190,8 @@ real_t TileSetAtlasSource::get_tile_animation_total_duration(const Vector2i p_at
ERR_FAIL_COND_V_MSG(!tiles.has(p_atlas_coords), 1, vformat("TileSetAtlasSource has no tile at %s.", Vector2i(p_atlas_coords)));
real_t sum = 0.0;
- for (int frame = 0; frame < (int)tiles[p_atlas_coords].animation_frames_durations.size(); frame++) {
- sum += tiles[p_atlas_coords].animation_frames_durations[frame];
+ for (const real_t &duration : tiles[p_atlas_coords].animation_frames_durations) {
+ sum += duration;
}
return sum;
}
@@ -4573,8 +4573,8 @@ void TileSetAtlasSource::_clear_tiles_outside_texture() {
}
}
- for (unsigned int i = 0; i < to_remove.size(); i++) {
- remove_tile(to_remove[i]);
+ for (const Vector2i &v : to_remove) {
+ remove_tile(v);
}
}
diff --git a/servers/physics_3d/godot_collision_solver_3d_sat.cpp b/servers/physics_3d/godot_collision_solver_3d_sat.cpp
index 66d1811abb..2cb29b3dd0 100644
--- a/servers/physics_3d/godot_collision_solver_3d_sat.cpp
+++ b/servers/physics_3d/godot_collision_solver_3d_sat.cpp
@@ -827,9 +827,9 @@ static void _collision_sphere_sphere(const GodotShape3D *p_a, const Transform3D
// Perform an analytic sphere collision between the two spheres
analytic_sphere_collision<withMargin>(
p_transform_a.origin,
- sphere_A->get_radius(),
+ sphere_A->get_radius() * p_transform_a.basis[0].length(),
p_transform_b.origin,
- sphere_B->get_radius(),
+ sphere_B->get_radius() * p_transform_b.basis[0].length(),
p_collector,
p_margin_a,
p_margin_b);
@@ -842,7 +842,7 @@ static void _collision_sphere_box(const GodotShape3D *p_a, const Transform3D &p_
// Find the point on the box nearest to the center of the sphere.
- Vector3 center = p_transform_b.xform_inv(p_transform_a.origin);
+ Vector3 center = p_transform_b.affine_inverse().xform(p_transform_a.origin);
Vector3 extents = box_B->get_half_extents();
Vector3 nearest(MIN(MAX(center.x, -extents.x), extents.x),
MIN(MAX(center.y, -extents.y), extents.y),
@@ -853,7 +853,8 @@ static void _collision_sphere_box(const GodotShape3D *p_a, const Transform3D &p_
Vector3 delta = nearest - p_transform_a.origin;
real_t length = delta.length();
- if (length > sphere_A->get_radius() + p_margin_a + p_margin_b) {
+ real_t radius = sphere_A->get_radius() * p_transform_a.basis[0].length();
+ if (length > radius + p_margin_a + p_margin_b) {
return;
}
p_collector->collided = true;
@@ -867,7 +868,7 @@ static void _collision_sphere_box(const GodotShape3D *p_a, const Transform3D &p_
} else {
axis = delta / length;
}
- Vector3 point_a = p_transform_a.origin + (sphere_A->get_radius() + p_margin_a) * axis;
+ Vector3 point_a = p_transform_a.origin + (radius + p_margin_a) * axis;
Vector3 point_b = (withMargin ? nearest - p_margin_b * axis : nearest);
p_collector->call(point_a, point_b, axis);
}
@@ -877,11 +878,12 @@ static void _collision_sphere_capsule(const GodotShape3D *p_a, const Transform3D
const GodotSphereShape3D *sphere_A = static_cast<const GodotSphereShape3D *>(p_a);
const GodotCapsuleShape3D *capsule_B = static_cast<const GodotCapsuleShape3D *>(p_b);
- real_t capsule_B_radius = capsule_B->get_radius();
+ real_t scale_A = p_transform_a.basis[0].length();
+ real_t scale_B = p_transform_b.basis[0].length();
// Construct the capsule segment (ball-center to ball-center)
Vector3 capsule_segment[2];
- Vector3 capsule_axis = p_transform_b.basis.get_column(1) * (capsule_B->get_height() * 0.5 - capsule_B_radius);
+ Vector3 capsule_axis = p_transform_b.basis.get_column(1) * (capsule_B->get_height() * 0.5 - capsule_B->get_radius());
capsule_segment[0] = p_transform_b.origin + capsule_axis;
capsule_segment[1] = p_transform_b.origin - capsule_axis;
@@ -891,9 +893,9 @@ static void _collision_sphere_capsule(const GodotShape3D *p_a, const Transform3D
// Perform an analytic sphere collision between the sphere and the sphere-collider in the capsule
analytic_sphere_collision<withMargin>(
p_transform_a.origin,
- sphere_A->get_radius(),
+ sphere_A->get_radius() * scale_A,
capsule_closest,
- capsule_B_radius,
+ capsule_B->get_radius() * scale_B,
p_collector,
p_margin_a,
p_margin_b);
@@ -903,12 +905,12 @@ template <bool withMargin>
static void analytic_sphere_cylinder_collision(real_t p_radius_a, real_t p_radius_b, real_t p_height_b, const Transform3D &p_transform_a, const Transform3D &p_transform_b, _CollectorCallback *p_collector, real_t p_margin_a, real_t p_margin_b) {
// Find the point on the cylinder nearest to the center of the sphere.
- Vector3 center = p_transform_b.xform_inv(p_transform_a.origin);
+ Vector3 center = p_transform_b.affine_inverse().xform(p_transform_a.origin);
Vector3 nearest = center;
- real_t radius = p_radius_b;
+ real_t scale_A = p_transform_a.basis[0].length();
real_t r = Math::sqrt(center.x * center.x + center.z * center.z);
- if (r > radius) {
- real_t scale = radius / r;
+ if (r > p_radius_b) {
+ real_t scale = p_radius_b / r;
nearest.x *= scale;
nearest.z *= scale;
}
@@ -920,7 +922,7 @@ static void analytic_sphere_cylinder_collision(real_t p_radius_a, real_t p_radiu
Vector3 delta = nearest - p_transform_a.origin;
real_t length = delta.length();
- if (length > p_radius_a + p_margin_a + p_margin_b) {
+ if (length > p_radius_a * scale_A + p_margin_a + p_margin_b) {
return;
}
p_collector->collided = true;
@@ -934,7 +936,7 @@ static void analytic_sphere_cylinder_collision(real_t p_radius_a, real_t p_radiu
} else {
axis = delta / length;
}
- Vector3 point_a = p_transform_a.origin + (p_radius_a + p_margin_a) * axis;
+ Vector3 point_a = p_transform_a.origin + (p_radius_a * scale_A + p_margin_a) * axis;
Vector3 point_b = (withMargin ? nearest - p_margin_b * axis : nearest);
p_collector->call(point_a, point_b, axis);
}
@@ -1632,14 +1634,14 @@ static void _collision_capsule_capsule(const GodotShape3D *p_a, const Transform3
const GodotCapsuleShape3D *capsule_A = static_cast<const GodotCapsuleShape3D *>(p_a);
const GodotCapsuleShape3D *capsule_B = static_cast<const GodotCapsuleShape3D *>(p_b);
- real_t capsule_A_radius = capsule_A->get_radius();
- real_t capsule_B_radius = capsule_B->get_radius();
+ real_t scale_A = p_transform_a.basis[0].length();
+ real_t scale_B = p_transform_b.basis[0].length();
// Get the closest points between the capsule segments
Vector3 capsule_A_closest;
Vector3 capsule_B_closest;
- Vector3 capsule_A_axis = p_transform_a.basis.get_column(1) * (capsule_A->get_height() * 0.5 - capsule_A_radius);
- Vector3 capsule_B_axis = p_transform_b.basis.get_column(1) * (capsule_B->get_height() * 0.5 - capsule_B_radius);
+ Vector3 capsule_A_axis = p_transform_a.basis.get_column(1) * (capsule_A->get_height() * 0.5 - capsule_A->get_radius());
+ Vector3 capsule_B_axis = p_transform_b.basis.get_column(1) * (capsule_B->get_height() * 0.5 - capsule_B->get_radius());
Geometry3D::get_closest_points_between_segments(
p_transform_a.origin + capsule_A_axis,
p_transform_a.origin - capsule_A_axis,
@@ -1651,9 +1653,9 @@ static void _collision_capsule_capsule(const GodotShape3D *p_a, const Transform3
// Perform the analytic collision between the two closest capsule spheres
analytic_sphere_collision<withMargin>(
capsule_A_closest,
- capsule_A_radius,
+ capsule_A->get_radius() * scale_A,
capsule_B_closest,
- capsule_B_radius,
+ capsule_B->get_radius() * scale_B,
p_collector,
p_margin_a,
p_margin_b);
diff --git a/servers/physics_3d/godot_shape_3d.cpp b/servers/physics_3d/godot_shape_3d.cpp
index 8aacfa929f..300dca4e08 100644
--- a/servers/physics_3d/godot_shape_3d.cpp
+++ b/servers/physics_3d/godot_shape_3d.cpp
@@ -852,17 +852,12 @@ Vector3 GodotConvexPolygonShape3D::get_support(const Vector3 &p_normal) const {
// Get the array of vertices
const Vector3 *const vertices_array = mesh.vertices.ptr();
- // Get the array of extreme vertices
- const int *const extreme_array = extreme_vertices.ptr();
- const uint32_t extreme_size = extreme_vertices.size();
-
- // Start with an initial assumption of the first extreme vertex
- int best_vertex = extreme_array[0];
+ // Start with an initial assumption of the first extreme vertex.
+ int best_vertex = extreme_vertices[0];
real_t max_support = p_normal.dot(vertices_array[best_vertex]);
- // Check the remaining extreme vertices for a better vertex
- for (uint32_t i = 0; i < extreme_size; ++i) {
- int vert = extreme_array[i];
+ // Check the remaining extreme vertices for a better vertex.
+ for (const int &vert : extreme_vertices) {
real_t s = p_normal.dot(vertices_array[vert]);
if (s > max_support) {
best_vertex = vert;
@@ -870,27 +865,18 @@ Vector3 GodotConvexPolygonShape3D::get_support(const Vector3 &p_normal) const {
}
}
- // If we checked all vertices in the mesh then we're done
- if (extreme_size == mesh.vertices.size()) {
+ // If we checked all vertices in the mesh then we're done.
+ if (extreme_vertices.size() == mesh.vertices.size()) {
return vertices_array[best_vertex];
}
- // Get the array of neighbor arrays for each vertex
- const LocalVector<int> *const vertex_neighbors_array = vertex_neighbors.ptr();
-
// Move along the surface until we reach the true support vertex.
int last_vertex = -1;
while (true) {
int next_vertex = -1;
- // Get the array of neighbors around the best vertex
- const LocalVector<int> &neighbors = vertex_neighbors_array[best_vertex];
- const int *const neighbors_array = neighbors.ptr();
- const uint32_t neighbors_size = neighbors.size();
-
- // Iterate over all the neighbors checking for a better vertex
- for (uint32_t i = 0; i < neighbors_size; ++i) {
- int vert = neighbors_array[i];
+ // Iterate over all the neighbors checking for a better vertex.
+ for (const int &vert : vertex_neighbors[best_vertex]) {
if (vert != last_vertex) {
real_t s = p_normal.dot(vertices_array[vert]);
if (s > max_support) {
@@ -1149,8 +1135,7 @@ void GodotConvexPolygonShape3D::_setup(const Vector<Vector3> &p_vertices) {
if (extreme_vertices.size() < mesh.vertices.size()) {
vertex_neighbors.resize(mesh.vertices.size());
- for (uint32_t i = 0; i < mesh.edges.size(); i++) {
- Geometry3D::MeshData::Edge &edge = mesh.edges[i];
+ for (Geometry3D::MeshData::Edge &edge : mesh.edges) {
vertex_neighbors[edge.vertex_a].push_back(edge.vertex_b);
vertex_neighbors[edge.vertex_b].push_back(edge.vertex_a);
}
diff --git a/servers/physics_3d/godot_soft_body_3d.cpp b/servers/physics_3d/godot_soft_body_3d.cpp
index 871017a5e7..1820a29553 100644
--- a/servers/physics_3d/godot_soft_body_3d.cpp
+++ b/servers/physics_3d/godot_soft_body_3d.cpp
@@ -167,14 +167,11 @@ void GodotSoftBody3D::update_rendering_server(PhysicsServer3DRenderingServerHand
}
void GodotSoftBody3D::update_normals_and_centroids() {
- uint32_t i, ni;
-
- for (i = 0, ni = nodes.size(); i < ni; ++i) {
- nodes[i].n = Vector3();
+ for (Node &node : nodes) {
+ node.n = Vector3();
}
- for (i = 0, ni = faces.size(); i < ni; ++i) {
- Face &face = faces[i];
+ for (Face &face : faces) {
const Vector3 n = vec3_cross(face.n[0]->x - face.n[2]->x, face.n[0]->x - face.n[1]->x);
face.n[0]->n += n;
face.n[1]->n += n;
@@ -184,8 +181,7 @@ void GodotSoftBody3D::update_normals_and_centroids() {
face.centroid = 0.33333333333 * (face.n[0]->x + face.n[1]->x + face.n[2]->x);
}
- for (i = 0, ni = nodes.size(); i < ni; ++i) {
- Node &node = nodes[i];
+ for (Node &node : nodes) {
real_t len = node.n.length();
if (len > CMP_EPSILON) {
node.n /= len;
@@ -235,9 +231,7 @@ void GodotSoftBody3D::update_area() {
int i, ni;
// Face area.
- for (i = 0, ni = faces.size(); i < ni; ++i) {
- Face &face = faces[i];
-
+ for (Face &face : faces) {
const Vector3 &x0 = face.n[0]->x;
const Vector3 &x1 = face.n[1]->x;
const Vector3 &x2 = face.n[2]->x;
@@ -255,12 +249,11 @@ void GodotSoftBody3D::update_area() {
memset(counts.ptr(), 0, counts.size() * sizeof(int));
}
- for (i = 0, ni = nodes.size(); i < ni; ++i) {
- nodes[i].area = 0.0;
+ for (Node &node : nodes) {
+ node.area = 0.0;
}
- for (i = 0, ni = faces.size(); i < ni; ++i) {
- const Face &face = faces[i];
+ for (const Face &face : faces) {
for (int j = 0; j < 3; ++j) {
const int index = (int)(face.n[j] - &nodes[0]);
counts[index]++;
@@ -278,8 +271,7 @@ void GodotSoftBody3D::update_area() {
}
void GodotSoftBody3D::reset_link_rest_lengths() {
- for (uint32_t i = 0, ni = links.size(); i < ni; ++i) {
- Link &link = links[i];
+ for (Link &link : links) {
link.rl = (link.n[0]->x - link.n[1]->x).length();
link.c1 = link.rl * link.rl;
}
@@ -287,8 +279,7 @@ void GodotSoftBody3D::reset_link_rest_lengths() {
void GodotSoftBody3D::update_link_constants() {
real_t inv_linear_stiffness = 1.0 / linear_stiffness;
- for (uint32_t i = 0, ni = links.size(); i < ni; ++i) {
- Link &link = links[i];
+ for (Link &link : links) {
link.c0 = (link.n[0]->im + link.n[1]->im) * inv_linear_stiffness;
}
}
@@ -619,9 +610,9 @@ void GodotSoftBody3D::generate_bending_constraints(int p_distance) {
}
}
}
- for (i = 0; i < links.size(); ++i) {
- const int ia = (int)(links[i].n[0] - &nodes[0]);
- const int ib = (int)(links[i].n[1] - &nodes[0]);
+ for (Link &link : links) {
+ const int ia = (int)(link.n[0] - &nodes[0]);
+ const int ib = (int)(link.n[1] - &nodes[0]);
int idx = ib * n + ia;
int idx_inv = ia * n + ib;
adj[idx] = 1;
@@ -635,9 +626,9 @@ void GodotSoftBody3D::generate_bending_constraints(int p_distance) {
// Build node links.
node_links.resize(nodes.size());
- for (i = 0; i < links.size(); ++i) {
- const int ia = (int)(links[i].n[0] - &nodes[0]);
- const int ib = (int)(links[i].n[1] - &nodes[0]);
+ for (Link &link : links) {
+ const int ia = (int)(link.n[0] - &nodes[0]);
+ const int ib = (int)(link.n[1] - &nodes[0]);
if (node_links[ia].find(ib) == -1) {
node_links[ia].push_back(ib);
}
@@ -649,8 +640,7 @@ void GodotSoftBody3D::generate_bending_constraints(int p_distance) {
for (uint32_t ii = 0; ii < node_links.size(); ii++) {
for (uint32_t jj = 0; jj < node_links[ii].size(); jj++) {
int k = node_links[ii][jj];
- for (uint32_t kk = 0; kk < node_links[k].size(); kk++) {
- int l = node_links[k][kk];
+ for (const int &l : node_links[k]) {
if ((int)ii != l) {
int idx_ik = k * n + ii;
int idx_kj = l * n + k;
@@ -916,8 +906,7 @@ void GodotSoftBody3D::set_drag_coefficient(real_t p_val) {
}
void GodotSoftBody3D::add_velocity(const Vector3 &p_velocity) {
- for (uint32_t i = 0, ni = nodes.size(); i < ni; ++i) {
- Node &node = nodes[i];
+ for (Node &node : nodes) {
if (node.im > 0) {
node.v += p_velocity;
}
@@ -929,26 +918,22 @@ void GodotSoftBody3D::apply_forces(const LocalVector<GodotArea3D *> &p_wind_area
return;
}
- uint32_t i, ni;
int32_t j;
real_t volume = 0.0;
const Vector3 &org = nodes[0].x;
// Iterate over faces (try not to iterate elsewhere if possible).
- for (i = 0, ni = faces.size(); i < ni; ++i) {
- const Face &face = faces[i];
-
+ for (const Face &face : faces) {
Vector3 wind_force(0, 0, 0);
// Compute volume.
volume += vec3_dot(face.n[0]->x - org, vec3_cross(face.n[1]->x - org, face.n[2]->x - org));
// Compute nodal forces from area winds.
- int wind_area_count = p_wind_areas.size();
- if (wind_area_count > 0) {
- for (j = 0; j < wind_area_count; j++) {
- wind_force += _compute_area_windforce(p_wind_areas[j], &face);
+ if (!p_wind_areas.is_empty()) {
+ for (const GodotArea3D *area : p_wind_areas) {
+ wind_force += _compute_area_windforce(area, &face);
}
for (j = 0; j < 3; j++) {
@@ -962,8 +947,7 @@ void GodotSoftBody3D::apply_forces(const LocalVector<GodotArea3D *> &p_wind_area
// Apply nodal pressure forces.
if (pressure_coefficient > CMP_EPSILON) {
real_t ivolumetp = 1.0 / Math::abs(volume) * pressure_coefficient;
- for (i = 0, ni = nodes.size(); i < ni; ++i) {
- Node &node = nodes[i];
+ for (Node &node : nodes) {
if (node.im > 0) {
node.f += node.n * (node.area * ivolumetp);
}
@@ -1048,9 +1032,7 @@ void GodotSoftBody3D::predict_motion(real_t p_delta) {
real_t clamp_delta_v = max_displacement * inv_delta;
// Integrate.
- uint32_t i, ni;
- for (i = 0, ni = nodes.size(); i < ni; ++i) {
- Node &node = nodes[i];
+ for (Node &node : nodes) {
node.q = node.x;
Vector3 delta_v = node.f * node.im * p_delta;
for (int c = 0; c < 3; c++) {
@@ -1065,9 +1047,7 @@ void GodotSoftBody3D::predict_motion(real_t p_delta) {
update_bounds();
// Node tree update.
- for (i = 0, ni = nodes.size(); i < ni; ++i) {
- const Node &node = nodes[i];
-
+ for (const Node &node : nodes) {
AABB node_aabb(node.x, Vector3());
node_aabb.expand_to(node.x + node.v * p_delta);
node_aabb.grow_by(collision_margin);
@@ -1088,17 +1068,13 @@ void GodotSoftBody3D::predict_motion(real_t p_delta) {
void GodotSoftBody3D::solve_constraints(real_t p_delta) {
const real_t inv_delta = 1.0 / p_delta;
- uint32_t i, ni;
-
- for (i = 0, ni = links.size(); i < ni; ++i) {
- Link &link = links[i];
+ for (Link &link : links) {
link.c3 = link.n[1]->q - link.n[0]->q;
link.c2 = 1 / (link.c3.length_squared() * link.c0);
}
// Solve velocities.
- for (i = 0, ni = nodes.size(); i < ni; ++i) {
- Node &node = nodes[i];
+ for (Node &node : nodes) {
node.x = node.q + node.v * p_delta;
}
@@ -1108,9 +1084,7 @@ void GodotSoftBody3D::solve_constraints(real_t p_delta) {
solve_links(1.0, ti);
}
const real_t vc = (1.0 - damping_coefficient) * inv_delta;
- for (i = 0, ni = nodes.size(); i < ni; ++i) {
- Node &node = nodes[i];
-
+ for (Node &node : nodes) {
node.x += node.bv * p_delta;
node.bv = Vector3();
@@ -1123,8 +1097,7 @@ void GodotSoftBody3D::solve_constraints(real_t p_delta) {
}
void GodotSoftBody3D::solve_links(real_t kst, real_t ti) {
- for (uint32_t i = 0, ni = links.size(); i < ni; ++i) {
- Link &link = links[i];
+ for (Link &link : links) {
if (link.c0 > 0) {
Node &node_a = *link.n[0];
Node &node_b = *link.n[1];
@@ -1183,9 +1156,7 @@ void GodotSoftBody3D::query_ray(const Vector3 &p_from, const Vector3 &p_to, Godo
void GodotSoftBody3D::initialize_face_tree() {
face_tree.clear();
- for (uint32_t i = 0; i < faces.size(); ++i) {
- Face &face = faces[i];
-
+ for (Face &face : faces) {
AABB face_aabb;
face_aabb.position = face.n[0]->x;
@@ -1199,9 +1170,7 @@ void GodotSoftBody3D::initialize_face_tree() {
}
void GodotSoftBody3D::update_face_tree(real_t p_delta) {
- for (uint32_t i = 0; i < faces.size(); ++i) {
- const Face &face = faces[i];
-
+ for (const Face &face : faces) {
AABB face_aabb;
const Node *node0 = face.n[0];
diff --git a/servers/rendering/renderer_rd/environment/gi.cpp b/servers/rendering/renderer_rd/environment/gi.cpp
index a52716cd78..08133bf8d6 100644
--- a/servers/rendering/renderer_rd/environment/gi.cpp
+++ b/servers/rendering/renderer_rd/environment/gi.cpp
@@ -540,9 +540,7 @@ void GI::SDFGI::create(RID p_env, const Vector3 &p_world_position, uint32_t p_re
occlusion_texture = RD::get_singleton()->texture_create_shared(tv, occlusion_data);
}
- for (uint32_t i = 0; i < cascades.size(); i++) {
- SDFGI::Cascade &cascade = cascades[i];
-
+ for (SDFGI::Cascade &cascade : cascades) {
/* 3D Textures */
cascade.sdf_tex = RD::get_singleton()->texture_create(tf_sdf, RD::TextureView());
@@ -743,9 +741,7 @@ void GI::SDFGI::create(RID p_env, const Vector3 &p_world_position, uint32_t p_re
}
//direct light
- for (uint32_t i = 0; i < cascades.size(); i++) {
- SDFGI::Cascade &cascade = cascades[i];
-
+ for (SDFGI::Cascade &cascade : cascades) {
Vector<RD::Uniform> uniforms;
{
RD::Uniform u;
@@ -1134,8 +1130,7 @@ void GI::SDFGI::free_data() {
}
GI::SDFGI::~SDFGI() {
- for (uint32_t i = 0; i < cascades.size(); i++) {
- const SDFGI::Cascade &c = cascades[i];
+ for (const SDFGI::Cascade &c : cascades) {
RD::get_singleton()->free(c.light_data);
RD::get_singleton()->free(c.light_aniso_0_tex);
RD::get_singleton()->free(c.light_aniso_1_tex);
@@ -1198,8 +1193,7 @@ void GI::SDFGI::update(RID p_env, const Vector3 &p_world_position) {
int32_t drag_margin = (cascade_size / SDFGI::PROBE_DIVISOR) / 2;
- for (uint32_t i = 0; i < cascades.size(); i++) {
- SDFGI::Cascade &cascade = cascades[i];
+ for (SDFGI::Cascade &cascade : cascades) {
cascade.dirty_regions = Vector3i();
Vector3 probe_half_size = Vector3(1, 1, 1) * cascade.cell_size * float(cascade_size / SDFGI::PROBE_DIVISOR) * 0.5;
diff --git a/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp b/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp
index 3fd8d55a71..ad63d3fd4b 100644
--- a/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp
+++ b/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp
@@ -1365,8 +1365,8 @@ void RenderForwardClustered::_pre_opaque_render(RenderDataRD *p_render_data, boo
}
//cube shadows are rendered in their own way
- for (uint32_t i = 0; i < p_render_data->cube_shadows.size(); i++) {
- _render_shadow_pass(p_render_data->render_shadows[p_render_data->cube_shadows[i]].light, p_render_data->shadow_atlas, p_render_data->render_shadows[p_render_data->cube_shadows[i]].pass, p_render_data->render_shadows[p_render_data->cube_shadows[i]].instances, camera_plane, lod_distance_multiplier, p_render_data->scene_data->screen_mesh_lod_threshold, true, true, true, p_render_data->render_info);
+ for (const int &index : p_render_data->cube_shadows) {
+ _render_shadow_pass(p_render_data->render_shadows[index].light, p_render_data->shadow_atlas, p_render_data->render_shadows[index].pass, p_render_data->render_shadows[index].instances, camera_plane, lod_distance_multiplier, p_render_data->scene_data->screen_mesh_lod_threshold, true, true, true, p_render_data->render_info);
}
if (p_render_data->directional_shadows.size()) {
@@ -2415,8 +2415,7 @@ void RenderForwardClustered::_render_shadow_process() {
void RenderForwardClustered::_render_shadow_end(uint32_t p_barrier) {
RD::get_singleton()->draw_command_begin_label("Shadow Render");
- for (uint32_t i = 0; i < scene_state.shadow_passes.size(); i++) {
- SceneState::ShadowPass &shadow_pass = scene_state.shadow_passes[i];
+ for (SceneState::ShadowPass &shadow_pass : scene_state.shadow_passes) {
RenderListParameters render_list_parameters(render_list[RENDER_LIST_SECONDARY].elements.ptr() + shadow_pass.element_from, render_list[RENDER_LIST_SECONDARY].element_info.ptr() + shadow_pass.element_from, shadow_pass.element_count, shadow_pass.flip_cull, shadow_pass.pass_mode, 0, true, false, shadow_pass.rp_uniform_set, false, Vector2(), shadow_pass.lod_distance_multiplier, shadow_pass.screen_mesh_lod_threshold, 1, shadow_pass.element_from, RD::BARRIER_MASK_NO_BARRIER);
_render_list_with_threads(&render_list_parameters, shadow_pass.framebuffer, RD::INITIAL_ACTION_DROP, RD::FINAL_ACTION_DISCARD, shadow_pass.initial_depth_action, shadow_pass.final_depth_action, Vector<Color>(), 1.0, 0, shadow_pass.rect);
}
@@ -3376,9 +3375,7 @@ int RenderForwardClustered::sdfgi_get_pending_region_count(const Ref<RenderScene
Ref<RendererRD::GI::SDFGI> sdfgi = rb->get_custom_data(RB_SCOPE_SDFGI);
int dirty_count = 0;
- for (uint32_t i = 0; i < sdfgi->cascades.size(); i++) {
- const RendererRD::GI::SDFGI::Cascade &c = sdfgi->cascades[i];
-
+ for (const RendererRD::GI::SDFGI::Cascade &c : sdfgi->cascades) {
if (c.dirty_regions == RendererRD::GI::SDFGI::Cascade::DIRTY_ALL) {
dirty_count++;
} else {
@@ -4007,11 +4004,11 @@ RenderForwardClustered::~RenderForwardClustered() {
RSG::light_storage->directional_shadow_atlas_set_size(0);
{
- for (uint32_t i = 0; i < scene_state.uniform_buffers.size(); i++) {
- RD::get_singleton()->free(scene_state.uniform_buffers[i]);
+ for (const RID &rid : scene_state.uniform_buffers) {
+ RD::get_singleton()->free(rid);
}
- for (uint32_t i = 0; i < scene_state.implementation_uniform_buffers.size(); i++) {
- RD::get_singleton()->free(scene_state.implementation_uniform_buffers[i]);
+ for (const RID &rid : scene_state.implementation_uniform_buffers) {
+ RD::get_singleton()->free(rid);
}
RD::get_singleton()->free(scene_state.lightmap_buffer);
RD::get_singleton()->free(scene_state.lightmap_capture_buffer);
diff --git a/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp b/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp
index 5d4e3c1ac1..25204f1abf 100644
--- a/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp
+++ b/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp
@@ -579,8 +579,8 @@ void RenderForwardMobile::_pre_opaque_render(RenderDataRD *p_render_data) {
}
//cube shadows are rendered in their own way
- for (uint32_t i = 0; i < p_render_data->cube_shadows.size(); i++) {
- _render_shadow_pass(p_render_data->render_shadows[p_render_data->cube_shadows[i]].light, p_render_data->shadow_atlas, p_render_data->render_shadows[p_render_data->cube_shadows[i]].pass, p_render_data->render_shadows[p_render_data->cube_shadows[i]].instances, camera_plane, lod_distance_multiplier, p_render_data->scene_data->screen_mesh_lod_threshold, true, true, true, p_render_data->render_info);
+ for (const int &index : p_render_data->cube_shadows) {
+ _render_shadow_pass(p_render_data->render_shadows[index].light, p_render_data->shadow_atlas, p_render_data->render_shadows[index].pass, p_render_data->render_shadows[index].instances, camera_plane, lod_distance_multiplier, p_render_data->scene_data->screen_mesh_lod_threshold, true, true, true, p_render_data->render_info);
}
if (p_render_data->directional_shadows.size()) {
@@ -1340,8 +1340,7 @@ void RenderForwardMobile::_render_shadow_process() {
void RenderForwardMobile::_render_shadow_end(uint32_t p_barrier) {
RD::get_singleton()->draw_command_begin_label("Shadow Render");
- for (uint32_t i = 0; i < scene_state.shadow_passes.size(); i++) {
- SceneState::ShadowPass &shadow_pass = scene_state.shadow_passes[i];
+ for (SceneState::ShadowPass &shadow_pass : scene_state.shadow_passes) {
RenderListParameters render_list_parameters(render_list[RENDER_LIST_SECONDARY].elements.ptr() + shadow_pass.element_from, render_list[RENDER_LIST_SECONDARY].element_info.ptr() + shadow_pass.element_from, shadow_pass.element_count, shadow_pass.flip_cull, shadow_pass.pass_mode, shadow_pass.rp_uniform_set, 0, false, Vector2(), shadow_pass.lod_distance_multiplier, shadow_pass.screen_mesh_lod_threshold, 1, shadow_pass.element_from, RD::BARRIER_MASK_NO_BARRIER);
_render_list_with_threads(&render_list_parameters, shadow_pass.framebuffer, RD::INITIAL_ACTION_DROP, RD::FINAL_ACTION_DISCARD, shadow_pass.initial_depth_action, shadow_pass.final_depth_action, Vector<Color>(), 1.0, 0, shadow_pass.rect);
}
@@ -2810,8 +2809,8 @@ RenderForwardMobile::~RenderForwardMobile() {
}
{
- for (uint32_t i = 0; i < scene_state.uniform_buffers.size(); i++) {
- RD::get_singleton()->free(scene_state.uniform_buffers[i]);
+ for (const RID &rid : scene_state.uniform_buffers) {
+ RD::get_singleton()->free(rid);
}
RD::get_singleton()->free(scene_state.lightmap_buffer);
RD::get_singleton()->free(scene_state.lightmap_capture_buffer);
diff --git a/servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp b/servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp
index 462b925134..638fe44266 100644
--- a/servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp
+++ b/servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp
@@ -455,7 +455,7 @@ void RendererCanvasRenderRD::_render_item(RD::DrawListID p_draw_list, RID p_rend
light_count++;
- if (light_count == MAX_LIGHTS_PER_ITEM) {
+ if (light_count == MAX_LIGHTS_PER_ITEM - 1) {
break;
}
}
diff --git a/servers/rendering/renderer_rd/shader_rd.cpp b/servers/rendering/renderer_rd/shader_rd.cpp
index 2d5263a3e2..533a912a34 100644
--- a/servers/rendering/renderer_rd/shader_rd.cpp
+++ b/servers/rendering/renderer_rd/shader_rd.cpp
@@ -165,8 +165,7 @@ void ShaderRD::_clear_version(Version *p_version) {
}
void ShaderRD::_build_variant_code(StringBuilder &builder, uint32_t p_variant, const Version *p_version, const StageTemplate &p_template) {
- for (uint32_t i = 0; i < p_template.chunks.size(); i++) {
- const StageTemplate::Chunk &chunk = p_template.chunks[i];
+ for (const StageTemplate::Chunk &chunk : p_template.chunks) {
switch (chunk.type) {
case StageTemplate::Chunk::TYPE_VERSION_DEFINES: {
builder.append("\n"); //make sure defines begin at newline
diff --git a/servers/rendering/renderer_rd/storage_rd/mesh_storage.cpp b/servers/rendering/renderer_rd/storage_rd/mesh_storage.cpp
index 62da62403f..46a0d85ba8 100644
--- a/servers/rendering/renderer_rd/storage_rd/mesh_storage.cpp
+++ b/servers/rendering/renderer_rd/storage_rd/mesh_storage.cpp
@@ -842,15 +842,15 @@ void MeshStorage::mesh_instance_set_blend_shape_weight(RID p_mesh_instance, int
}
void MeshStorage::_mesh_instance_clear(MeshInstance *mi) {
- for (uint32_t i = 0; i < mi->surfaces.size(); i++) {
- if (mi->surfaces[i].versions) {
- for (uint32_t j = 0; j < mi->surfaces[i].version_count; j++) {
- RD::get_singleton()->free(mi->surfaces[i].versions[j].vertex_array);
+ for (const RendererRD::MeshStorage::MeshInstance::Surface surface : mi->surfaces) {
+ if (surface.versions) {
+ for (uint32_t j = 0; j < surface.version_count; j++) {
+ RD::get_singleton()->free(surface.versions[j].vertex_array);
}
- memfree(mi->surfaces[i].versions);
+ memfree(surface.versions);
}
- if (mi->surfaces[i].vertex_buffer.is_valid()) {
- RD::get_singleton()->free(mi->surfaces[i].vertex_buffer);
+ if (surface.vertex_buffer.is_valid()) {
+ RD::get_singleton()->free(surface.vertex_buffer);
}
}
mi->surfaces.clear();
@@ -866,8 +866,8 @@ void MeshStorage::_mesh_instance_clear(MeshInstance *mi) {
void MeshStorage::_mesh_instance_add_surface(MeshInstance *mi, Mesh *mesh, uint32_t p_surface) {
if (mesh->blend_shape_count > 0 && mi->blend_weights_buffer.is_null()) {
mi->blend_weights.resize(mesh->blend_shape_count);
- for (uint32_t i = 0; i < mi->blend_weights.size(); i++) {
- mi->blend_weights[i] = 0;
+ for (float &weight : mi->blend_weights) {
+ weight = 0;
}
mi->blend_weights_buffer = RD::get_singleton()->storage_buffer_create(sizeof(float) * mi->blend_weights.size(), mi->blend_weights.to_byte_array());
mi->weights_dirty = true;
diff --git a/servers/rendering/renderer_rd/storage_rd/particles_storage.cpp b/servers/rendering/renderer_rd/storage_rd/particles_storage.cpp
index e4149f6bbd..f4c3e769a8 100644
--- a/servers/rendering/renderer_rd/storage_rd/particles_storage.cpp
+++ b/servers/rendering/renderer_rd/storage_rd/particles_storage.cpp
@@ -851,9 +851,9 @@ void ParticlesStorage::_particles_process(Particles *p_particles, double p_delta
collision_heightmap_texture = p_particles->sdf_collision_texture;
//replace in all other history frames where used because parameters are no longer valid if screen moves
- for (uint32_t i = 1; i < p_particles->frame_history.size(); i++) {
- if (p_particles->frame_history[i].collider_count > 0 && p_particles->frame_history[i].colliders[0].type == ParticlesFrameParams::COLLISION_TYPE_2D_SDF) {
- p_particles->frame_history[i].colliders[0] = frame_params.colliders[0];
+ for (ParticlesFrameParams &params : p_particles->frame_history) {
+ if (params.collider_count > 0 && params.colliders[0].type == ParticlesFrameParams::COLLISION_TYPE_2D_SDF) {
+ params.colliders[0] = frame_params.colliders[0];
}
}
}
diff --git a/servers/rendering/renderer_scene_cull.cpp b/servers/rendering/renderer_scene_cull.cpp
index de417082f5..9011cdd98a 100644
--- a/servers/rendering/renderer_scene_cull.cpp
+++ b/servers/rendering/renderer_scene_cull.cpp
@@ -3096,15 +3096,15 @@ void RendererSceneCull::_render_scene(const RendererSceneRender::CameraData *p_c
#endif
if (cull_to > thread_cull_threshold) {
//multiple threads
- for (uint32_t i = 0; i < scene_cull_result_threads.size(); i++) {
- scene_cull_result_threads[i].clear();
+ for (InstanceCullResult &thread : scene_cull_result_threads) {
+ thread.clear();
}
WorkerThreadPool::GroupID group_task = WorkerThreadPool::get_singleton()->add_template_group_task(this, &RendererSceneCull::_scene_cull_threaded, &cull_data, scene_cull_result_threads.size(), -1, true, SNAME("RenderCullInstances"));
WorkerThreadPool::get_singleton()->wait_for_group_task_completion(group_task);
- for (uint32_t i = 0; i < scene_cull_result_threads.size(); i++) {
- scene_cull_result.append_from(scene_cull_result_threads[i]);
+ for (InstanceCullResult &thread : scene_cull_result_threads) {
+ scene_cull_result.append_from(thread);
}
} else {
@@ -4134,8 +4134,8 @@ RendererSceneCull::RendererSceneCull() {
scene_cull_result.init(&rid_cull_page_pool, &geometry_instance_cull_page_pool, &instance_cull_page_pool);
scene_cull_result_threads.resize(WorkerThreadPool::get_singleton()->get_thread_count());
- for (uint32_t i = 0; i < scene_cull_result_threads.size(); i++) {
- scene_cull_result_threads[i].init(&rid_cull_page_pool, &geometry_instance_cull_page_pool, &instance_cull_page_pool);
+ for (InstanceCullResult &thread : scene_cull_result_threads) {
+ thread.init(&rid_cull_page_pool, &geometry_instance_cull_page_pool, &instance_cull_page_pool);
}
indexer_update_iterations = GLOBAL_GET("rendering/limits/spatial_indexer/update_iterations_per_frame");
@@ -4163,8 +4163,8 @@ RendererSceneCull::~RendererSceneCull() {
}
scene_cull_result.reset();
- for (uint32_t i = 0; i < scene_cull_result_threads.size(); i++) {
- scene_cull_result_threads[i].reset();
+ for (InstanceCullResult &thread : scene_cull_result_threads) {
+ thread.reset();
}
scene_cull_result_threads.clear();
diff --git a/servers/rendering/shader_language.cpp b/servers/rendering/shader_language.cpp
index a18fce3d24..ba7ffda00a 100644
--- a/servers/rendering/shader_language.cpp
+++ b/servers/rendering/shader_language.cpp
@@ -5402,7 +5402,7 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons
if (identifier == "SCREEN_TEXTURE" || identifier == "DEPTH_TEXTURE" || identifier == "NORMAL_ROUGHNESS_TEXTURE") {
String name = String(identifier);
String name_lower = name.to_lower();
- _set_error(vformat(RTR("%s has been removed in favor of using hint_%s with a uniform.\nTo continue with minimal code changes add 'uniform sampler2D %s : hint_%s, filter_linear_mipmaps;' near the top of your shader."), name, name_lower, name, name_lower));
+ _set_error(vformat(RTR("%s has been removed in favor of using hint_%s with a uniform.\nTo continue with minimal code changes add 'uniform sampler2D %s : hint_%s, filter_linear_mipmap;' near the top of your shader."), name, name_lower, name, name_lower));
return nullptr;
}
_set_error(vformat(RTR("Unknown identifier in expression: '%s'."), String(identifier)));
diff --git a/servers/rendering/shader_preprocessor.cpp b/servers/rendering/shader_preprocessor.cpp
index ccbf5defa2..97efd2df94 100644
--- a/servers/rendering/shader_preprocessor.cpp
+++ b/servers/rendering/shader_preprocessor.cpp
@@ -330,8 +330,8 @@ String ShaderPreprocessor::vector_to_string(const LocalVector<char32_t> &p_v, in
String ShaderPreprocessor::tokens_to_string(const LocalVector<Token> &p_tokens) {
LocalVector<char32_t> result;
- for (uint32_t i = 0; i < p_tokens.size(); i++) {
- result.push_back(p_tokens[i].text);
+ for (const Token &token : p_tokens) {
+ result.push_back(token.text);
}
return vector_to_string(result);
}
diff --git a/servers/rendering_server.cpp b/servers/rendering_server.cpp
index 675db63b9a..4ef562adcb 100644
--- a/servers/rendering_server.cpp
+++ b/servers/rendering_server.cpp
@@ -2802,9 +2802,7 @@ void RenderingServer::mesh_add_surface_from_mesh_data(RID p_mesh, const Geometry
Vector<Vector3> vertices;
Vector<Vector3> normals;
- for (uint32_t i = 0; i < p_mesh_data.faces.size(); i++) {
- const Geometry3D::MeshData::Face &f = p_mesh_data.faces[i];
-
+ for (const Geometry3D::MeshData::Face &f : p_mesh_data.faces) {
for (uint32_t j = 2; j < f.indices.size(); j++) {
vertices.push_back(p_mesh_data.vertices[f.indices[0]]);
normals.push_back(f.plane.normal);