From 900c676b0282bed83d00834e3c280ac89c2bc94d Mon Sep 17 00:00:00 2001 From: Aaron Record Date: Wed, 18 May 2022 17:43:40 -0600 Subject: Use range iterators for RBSet in most cases --- core/config/project_settings.cpp | 16 +-- core/io/file_access_pack.cpp | 4 +- core/io/resource.cpp | 4 +- core/io/resource_loader.cpp | 4 +- core/math/a_star.cpp | 6 +- core/multiplayer/multiplayer_api.cpp | 4 +- core/string/translation.cpp | 12 +-- drivers/gles3/storage/material_storage.cpp | 24 ++--- drivers/gles3/storage/mesh_storage.cpp | 12 +-- drivers/vulkan/rendering_device_vulkan.cpp | 42 ++++---- editor/animation_bezier_editor.cpp | 8 +- editor/create_dialog.cpp | 4 +- editor/debugger/editor_debugger_inspector.cpp | 4 +- editor/debugger/editor_debugger_node.cpp | 4 +- editor/debugger/editor_profiler.cpp | 24 ++--- editor/editor_asset_installer.cpp | 6 +- editor/editor_export.cpp | 14 +-- editor/editor_feature_profile.cpp | 12 +-- editor/editor_file_system.cpp | 4 +- editor/editor_folding.cpp | 8 +- editor/editor_node.cpp | 34 +++--- editor/editor_resource_picker.cpp | 16 +-- editor/editor_settings.cpp | 14 +-- editor/editor_translation_parser.cpp | 4 +- editor/import/editor_import_collada.cpp | 14 +-- .../plugins/animation_blend_tree_editor_plugin.cpp | 4 +- editor/plugins/node_3d_editor_plugin.cpp | 8 +- editor/plugins/root_motion_editor_plugin.cpp | 4 +- editor/plugins/script_text_editor.cpp | 4 +- editor/plugins/sprite_frames_editor_plugin.cpp | 8 +- editor/plugins/tiles/tile_data_editors.cpp | 30 +++--- editor/plugins/tiles/tile_map_editor.cpp | 86 +++++++-------- .../plugins/tiles/tile_set_atlas_source_editor.cpp | 114 ++++++++++---------- editor/plugins/visual_shader_editor_plugin.cpp | 4 +- editor/pot_generator.cpp | 8 +- editor/project_manager.cpp | 12 +-- editor/project_settings_editor.cpp | 4 +- editor/property_editor.cpp | 8 +- main/main.cpp | 8 +- modules/gdscript/gdscript.cpp | 12 +-- .../language_server/gdscript_workspace.cpp | 4 +- modules/gridmap/grid_map.cpp | 12 +-- modules/raycast/lightmap_raycaster.cpp | 8 +- modules/raycast/raycast_occlusion_cull.cpp | 6 +- modules/raycast/static_raycaster.cpp | 8 +- .../visual_script/editor/visual_script_editor.cpp | 52 ++++----- modules/visual_script/visual_script.cpp | 118 ++++++++++----------- platform/iphone/export/export_plugin.cpp | 4 +- scene/2d/tile_map.cpp | 84 +++++++-------- scene/3d/collision_object_3d.cpp | 6 +- scene/3d/skeleton_3d.cpp | 40 +++---- scene/animation/animation_player.cpp | 10 +- scene/animation/animation_tree.cpp | 6 +- scene/debugger/scene_debugger.cpp | 30 +++--- scene/gui/base_button.cpp | 20 ++-- scene/gui/code_edit.cpp | 8 +- scene/gui/graph_edit.cpp | 68 ++++++------ scene/gui/grid_container.cpp | 16 +-- scene/gui/range.cpp | 8 +- scene/main/resource_preloader.cpp | 6 +- scene/main/viewport.cpp | 40 +++---- scene/main/window.cpp | 12 +-- scene/multiplayer/scene_cache_interface.cpp | 10 +- scene/resources/concave_polygon_shape_3d.cpp | 6 +- scene/resources/polygon_path_finder.cpp | 70 ++++++------ scene/resources/theme.cpp | 4 +- scene/resources/tile_set.cpp | 18 ++-- scene/resources/visual_shader.cpp | 4 +- servers/physics_2d/godot_physics_server_2d.cpp | 18 ++-- servers/physics_2d/godot_step_2d.cpp | 4 +- servers/physics_3d/godot_physics_server_3d.cpp | 18 ++-- servers/physics_3d/godot_step_3d.cpp | 8 +- servers/physics_server_2d.cpp | 12 +-- servers/physics_server_3d.cpp | 12 +-- servers/rendering/renderer_canvas_cull.cpp | 16 +-- .../renderer_rd/renderer_scene_render_rd.cpp | 4 +- .../renderer_rd/storage_rd/material_storage.cpp | 24 ++--- .../renderer_rd/storage_rd/mesh_storage.cpp | 12 +-- .../renderer_rd/storage_rd/particles_storage.cpp | 4 +- servers/rendering/renderer_scene_cull.cpp | 68 ++++++------ servers/rendering/renderer_storage.h | 8 +- servers/rendering/renderer_viewport.cpp | 46 ++++---- servers/rendering/shader_compiler.cpp | 4 +- servers/rendering/shader_language.cpp | 20 ++-- 84 files changed, 784 insertions(+), 784 deletions(-) diff --git a/core/config/project_settings.cpp b/core/config/project_settings.cpp index 4638d70e59..ff5ff83bf8 100644 --- a/core/config/project_settings.cpp +++ b/core/config/project_settings.cpp @@ -360,8 +360,8 @@ void ProjectSettings::_get_property_list(List *p_list) const { vclist.insert(vc); } - for (RBSet<_VCSort>::Element *E = vclist.front(); E; E = E->next()) { - String prop_info_name = E->get().name; + for (const _VCSort &E : vclist) { + String prop_info_name = E.name; int dot = prop_info_name.find("."); if (dot != -1 && !custom_prop_info.has(prop_info_name)) { prop_info_name = prop_info_name.substr(0, dot); @@ -369,11 +369,11 @@ void ProjectSettings::_get_property_list(List *p_list) const { if (custom_prop_info.has(prop_info_name)) { PropertyInfo pi = custom_prop_info[prop_info_name]; - pi.name = E->get().name; - pi.usage = E->get().flags; + pi.name = E.name; + pi.usage = E.flags; p_list->push_back(pi); } else { - p_list->push_back(PropertyInfo(E->get().type, E->get().name, PROPERTY_HINT_NONE, "", E->get().flags)); + p_list->push_back(PropertyInfo(E.type, E.name, PROPERTY_HINT_NONE, "", E.flags)); } } } @@ -959,9 +959,9 @@ Error ProjectSettings::save_custom(const String &p_path, const CustomMap &p_cust RBMap> props; - for (RBSet<_VCSort>::Element *E = vclist.front(); E; E = E->next()) { - String category = E->get().name; - String name = E->get().name; + for (const _VCSort &E : vclist) { + String category = E.name; + String name = E.name; int div = category.find("/"); diff --git a/core/io/file_access_pack.cpp b/core/io/file_access_pack.cpp index 89efdc4938..595a6e9873 100644 --- a/core/io/file_access_pack.cpp +++ b/core/io/file_access_pack.cpp @@ -406,8 +406,8 @@ Error DirAccessPack::list_dir_begin() { list_dirs.push_back(E.key); } - for (RBSet::Element *E = current->files.front(); E; E = E->next()) { - list_files.push_back(E->get()); + for (const String &E : current->files) { + list_files.push_back(E); } return OK; diff --git a/core/io/resource.cpp b/core/io/resource.cpp index 4a94c17132..ad01eb1083 100644 --- a/core/io/resource.cpp +++ b/core/io/resource.cpp @@ -317,8 +317,8 @@ void Resource::unregister_owner(Object *p_owner) { } void Resource::notify_change_to_owners() { - for (RBSet::Element *E = owners.front(); E; E = E->next()) { - Object *obj = ObjectDB::get_instance(E->get()); + for (const ObjectID &E : owners) { + Object *obj = ObjectDB::get_instance(E); ERR_CONTINUE_MSG(!obj, "Object was deleted, while still owning a resource."); //wtf //TODO store string obj->call("resource_changed", Ref(this)); diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp index 9e6330f34b..fb21db1a19 100644 --- a/core/io/resource_loader.cpp +++ b/core/io/resource_loader.cpp @@ -391,8 +391,8 @@ float ResourceLoader::_dependency_get_progress(const String &p_path) { int dep_count = load_task.sub_tasks.size(); if (dep_count > 0) { float dep_progress = 0; - for (RBSet::Element *E = load_task.sub_tasks.front(); E; E = E->next()) { - dep_progress += _dependency_get_progress(E->get()); + for (const String &E : load_task.sub_tasks) { + dep_progress += _dependency_get_progress(E); } dep_progress /= float(dep_count); dep_progress *= 0.5; diff --git a/core/math/a_star.cpp b/core/math/a_star.cpp index a3ee259030..29aa959e54 100644 --- a/core/math/a_star.cpp +++ b/core/math/a_star.cpp @@ -293,10 +293,10 @@ Vector3 AStar3D::get_closest_position_in_segment(const Vector3 &p_point) const { real_t closest_dist = 1e20; Vector3 closest_point; - for (const RBSet::Element *E = segments.front(); E; E = E->next()) { + for (const Segment &E : segments) { Point *from_point = nullptr, *to_point = nullptr; - points.lookup(E->get().u, from_point); - points.lookup(E->get().v, to_point); + points.lookup(E.u, from_point); + points.lookup(E.v, to_point); if (!(from_point->enabled && to_point->enabled)) { continue; diff --git a/core/multiplayer/multiplayer_api.cpp b/core/multiplayer/multiplayer_api.cpp index e18c3dd2e4..9605647b3f 100644 --- a/core/multiplayer/multiplayer_api.cpp +++ b/core/multiplayer/multiplayer_api.cpp @@ -494,8 +494,8 @@ Vector MultiplayerAPI::get_peer_ids() const { ERR_FAIL_COND_V_MSG(!multiplayer_peer.is_valid(), Vector(), "No multiplayer peer is assigned. Assume no peers are connected."); Vector ret; - for (RBSet::Element *E = connected_peers.front(); E; E = E->next()) { - ret.push_back(E->get()); + for (const int &E : connected_peers) { + ret.push_back(E); } return ret; diff --git a/core/string/translation.cpp b/core/string/translation.cpp index c64f815563..cba2f09022 100644 --- a/core/string/translation.cpp +++ b/core/string/translation.cpp @@ -507,8 +507,8 @@ String TranslationServer::get_locale() const { Array TranslationServer::get_loaded_locales() const { Array locales; - for (const RBSet>::Element *E = translations.front(); E; E = E->next()) { - const Ref &t = E->get(); + for (const Ref &E : translations) { + const Ref &t = E; ERR_FAIL_COND_V(t.is_null(), Array()); String l = t->get_locale(); @@ -530,8 +530,8 @@ Ref TranslationServer::get_translation_object(const String &p_local Ref res; int best_score = 0; - for (const RBSet>::Element *E = translations.front(); E; E = E->next()) { - const Ref &t = E->get(); + for (const Ref &E : translations) { + const Ref &t = E; ERR_FAIL_COND_V(t.is_null(), nullptr); String l = t->get_locale(); @@ -599,8 +599,8 @@ StringName TranslationServer::_get_message_from_translations(const StringName &p StringName res; int best_score = 0; - for (const RBSet>::Element *E = translations.front(); E; E = E->next()) { - const Ref &t = E->get(); + for (const Ref &E : translations) { + const Ref &t = E; ERR_FAIL_COND_V(t.is_null(), p_message); String l = t->get_locale(); diff --git a/drivers/gles3/storage/material_storage.cpp b/drivers/gles3/storage/material_storage.cpp index e93c503396..7b18376a2a 100644 --- a/drivers/gles3/storage/material_storage.cpp +++ b/drivers/gles3/storage/material_storage.cpp @@ -2091,8 +2091,8 @@ void MaterialStorage::global_variable_set(const StringName &p_name, const Varian } else { //texture MaterialStorage *material_storage = MaterialStorage::get_singleton(); - for (RBSet::Element *E = gv.texture_materials.front(); E; E = E->next()) { - Material *material = material_storage->get_material(E->get()); + for (const RID &E : gv.texture_materials) { + Material *material = material_storage->get_material(E); ERR_CONTINUE(!material); material_storage->_material_queue_update(material, false, true); } @@ -2123,8 +2123,8 @@ void MaterialStorage::global_variable_set_override(const StringName &p_name, con } else { //texture MaterialStorage *material_storage = MaterialStorage::get_singleton(); - for (RBSet::Element *E = gv.texture_materials.front(); E; E = E->next()) { - Material *material = material_storage->get_material(E->get()); + for (const RID &E : gv.texture_materials) { + Material *material = material_storage->get_material(E); ERR_CONTINUE(!material); material_storage->_material_queue_update(material, false, true); } @@ -2421,8 +2421,8 @@ void MaterialStorage::shader_set_code(RID p_shader, const String &p_code) { shader->data = nullptr; } - for (RBSet::Element *E = shader->owners.front(); E; E = E->next()) { - Material *material = E->get(); + for (Material *E : shader->owners) { + Material *material = E; material->shader_mode = new_mode; if (material->data) { memdelete(material->data); @@ -2438,8 +2438,8 @@ void MaterialStorage::shader_set_code(RID p_shader, const String &p_code) { shader->mode = RS::SHADER_MAX; //invalid } - for (RBSet::Element *E = shader->owners.front(); E; E = E->next()) { - Material *material = E->get(); + for (Material *E : shader->owners) { + Material *material = E; if (shader->data) { material->data = material_data_request_func[new_mode](shader->data); material->data->self = material->self; @@ -2462,8 +2462,8 @@ void MaterialStorage::shader_set_code(RID p_shader, const String &p_code) { shader->data->set_code(p_code); } - for (RBSet::Element *E = shader->owners.front(); E; E = E->next()) { - Material *material = E->get(); + for (Material *E : shader->owners) { + Material *material = E; material->dependency.changed_notify(RendererStorage::DEPENDENCY_CHANGED_MATERIAL); _material_queue_update(material, true, true); } @@ -2504,8 +2504,8 @@ void MaterialStorage::shader_set_default_texture_param(RID p_shader, const Strin if (shader->data) { shader->data->set_default_texture_param(p_name, p_texture, p_index); } - for (RBSet::Element *E = shader->owners.front(); E; E = E->next()) { - Material *material = E->get(); + for (Material *E : shader->owners) { + Material *material = E; _material_queue_update(material, false, true); } } diff --git a/drivers/gles3/storage/mesh_storage.cpp b/drivers/gles3/storage/mesh_storage.cpp index 5739a63cac..3be1792868 100644 --- a/drivers/gles3/storage/mesh_storage.cpp +++ b/drivers/gles3/storage/mesh_storage.cpp @@ -68,8 +68,8 @@ void MeshStorage::mesh_free(RID p_rid) { ERR_PRINT("deleting mesh with active instances"); } if (mesh->shadow_owners.size()) { - for (RBSet::Element *E = mesh->shadow_owners.front(); E; E = E->next()) { - Mesh *shadow_owner = E->get(); + for (Mesh *E : mesh->shadow_owners) { + Mesh *shadow_owner = E; shadow_owner->shadow_mesh = RID(); shadow_owner->dependency.changed_notify(RendererStorage::DEPENDENCY_CHANGED_MESH); } @@ -268,8 +268,8 @@ void MeshStorage::mesh_add_surface(RID p_mesh, const RS::SurfaceData &p_surface) mesh->dependency.changed_notify(RendererStorage::DEPENDENCY_CHANGED_MESH); - for (RBSet::Element *E = mesh->shadow_owners.front(); E; E = E->next()) { - Mesh *shadow_owner = E->get(); + for (Mesh *E : mesh->shadow_owners) { + Mesh *shadow_owner = E; shadow_owner->shadow_mesh = RID(); shadow_owner->dependency.changed_notify(RendererStorage::DEPENDENCY_CHANGED_MESH); } @@ -610,8 +610,8 @@ void MeshStorage::mesh_clear(RID p_mesh) { mesh->has_bone_weights = false; mesh->dependency.changed_notify(RendererStorage::DEPENDENCY_CHANGED_MESH); - for (RBSet::Element *E = mesh->shadow_owners.front(); E; E = E->next()) { - Mesh *shadow_owner = E->get(); + for (Mesh *E : mesh->shadow_owners) { + Mesh *shadow_owner = E; shadow_owner->shadow_mesh = RID(); shadow_owner->dependency.changed_notify(RendererStorage::DEPENDENCY_CHANGED_MESH); } diff --git a/drivers/vulkan/rendering_device_vulkan.cpp b/drivers/vulkan/rendering_device_vulkan.cpp index 23c2d764b8..1a60ca0647 100644 --- a/drivers/vulkan/rendering_device_vulkan.cpp +++ b/drivers/vulkan/rendering_device_vulkan.cpp @@ -159,8 +159,8 @@ void RenderingDeviceVulkan::_free_dependencies(RID p_id) { E = reverse_dependency_map.find(p_id); if (E) { - for (RBSet::Element *F = E->value.front(); F; F = F->next()) { - HashMap>::Iterator G = dependency_map.find(F->get()); + for (const RID &F : E->value) { + HashMap>::Iterator G = dependency_map.find(F); ERR_CONTINUE(!G); ERR_CONTINUE(!G->value.has(p_id)); G->value.erase(p_id); @@ -5473,9 +5473,9 @@ RenderingDeviceVulkan::DescriptorPool *RenderingDeviceVulkan::_descriptor_pool_a DescriptorPool *pool = nullptr; - for (RBSet::Element *E = descriptor_pools[p_key].front(); E; E = E->next()) { - if (E->get()->usage < max_descriptors_per_pool) { - pool = E->get(); + for (DescriptorPool *E : descriptor_pools[p_key]) { + if (E->usage < max_descriptors_per_pool) { + pool = E; break; } } @@ -8349,31 +8349,31 @@ void RenderingDeviceVulkan::compute_list_end(uint32_t p_post_barrier) { uint32_t barrier_idx = 0; - for (RBSet::Element *E = compute_list->state.textures_to_sampled_layout.front(); E; E = E->next()) { + for (Texture *E : compute_list->state.textures_to_sampled_layout) { VkImageMemoryBarrier &image_memory_barrier = image_barriers[barrier_idx++]; image_memory_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; image_memory_barrier.pNext = nullptr; image_memory_barrier.srcAccessMask = VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT; image_memory_barrier.dstAccessMask = access_flags; - image_memory_barrier.oldLayout = E->get()->layout; + image_memory_barrier.oldLayout = E->layout; image_memory_barrier.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; image_memory_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; image_memory_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; - image_memory_barrier.image = E->get()->image; - image_memory_barrier.subresourceRange.aspectMask = E->get()->read_aspect_mask; - image_memory_barrier.subresourceRange.baseMipLevel = E->get()->base_mipmap; - image_memory_barrier.subresourceRange.levelCount = E->get()->mipmaps; - image_memory_barrier.subresourceRange.baseArrayLayer = E->get()->base_layer; - image_memory_barrier.subresourceRange.layerCount = E->get()->layers; - - E->get()->layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; - - if (E->get()->used_in_frame != frames_drawn) { - E->get()->used_in_transfer = false; - E->get()->used_in_raster = false; - E->get()->used_in_compute = false; - E->get()->used_in_frame = frames_drawn; + image_memory_barrier.image = E->image; + image_memory_barrier.subresourceRange.aspectMask = E->read_aspect_mask; + image_memory_barrier.subresourceRange.baseMipLevel = E->base_mipmap; + image_memory_barrier.subresourceRange.levelCount = E->mipmaps; + image_memory_barrier.subresourceRange.baseArrayLayer = E->base_layer; + image_memory_barrier.subresourceRange.layerCount = E->layers; + + E->layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; + + if (E->used_in_frame != frames_drawn) { + E->used_in_transfer = false; + E->used_in_raster = false; + E->used_in_compute = false; + E->used_in_frame = frames_drawn; } } diff --git a/editor/animation_bezier_editor.cpp b/editor/animation_bezier_editor.cpp index ff8b72274c..c5f800b17a 100644 --- a/editor/animation_bezier_editor.cpp +++ b/editor/animation_bezier_editor.cpp @@ -747,8 +747,8 @@ void AnimationBezierTrackEdit::_update_locked_tracks_after(int p_track) { } Vector updated_locked_tracks; - for (RBSet::Element *E = locked_tracks.front(); E; E = E->next()) { - updated_locked_tracks.push_back(E->get()); + for (const int &E : locked_tracks) { + updated_locked_tracks.push_back(E); } locked_tracks.clear(); for (int i = 0; i < updated_locked_tracks.size(); ++i) { @@ -766,8 +766,8 @@ void AnimationBezierTrackEdit::_update_hidden_tracks_after(int p_track) { } Vector updated_hidden_tracks; - for (RBSet::Element *E = hidden_tracks.front(); E; E = E->next()) { - updated_hidden_tracks.push_back(E->get()); + for (const int &E : hidden_tracks) { + updated_hidden_tracks.push_back(E); } hidden_tracks.clear(); for (int i = 0; i < updated_hidden_tracks.size(); ++i) { diff --git a/editor/create_dialog.cpp b/editor/create_dialog.cpp index fb908ea573..3469e96a0a 100644 --- a/editor/create_dialog.cpp +++ b/editor/create_dialog.cpp @@ -138,8 +138,8 @@ bool CreateDialog::_should_hide_type(const String &p_type) const { return true; // Wrong inheritance. } - for (RBSet::Element *E = type_blacklist.front(); E; E = E->next()) { - if (ClassDB::is_parent_class(p_type, E->get())) { + for (const StringName &E : type_blacklist) { + if (ClassDB::is_parent_class(p_type, E)) { return true; // Parent type is blacklisted. } } diff --git a/editor/debugger/editor_debugger_inspector.cpp b/editor/debugger/editor_debugger_inspector.cpp index 6d7f3f4ae2..0dd7b44b68 100644 --- a/editor/debugger/editor_debugger_inspector.cpp +++ b/editor/debugger/editor_debugger_inspector.cpp @@ -193,8 +193,8 @@ ObjectID EditorDebuggerInspector::add_object(const Array &p_arr) { if (old_prop_size == debugObj->prop_list.size() && new_props_added == 0) { //only some may have changed, if so, then update those, if exist - for (RBSet::Element *E = changed.front(); E; E = E->next()) { - emit_signal(SNAME("object_property_updated"), debugObj->remote_object_id, E->get()); + for (const String &E : changed) { + emit_signal(SNAME("object_property_updated"), debugObj->remote_object_id, E); } } else { //full update, because props were added or removed diff --git a/editor/debugger/editor_debugger_node.cpp b/editor/debugger/editor_debugger_node.cpp index de26b56ab6..bc28b11a71 100644 --- a/editor/debugger/editor_debugger_node.cpp +++ b/editor/debugger/editor_debugger_node.cpp @@ -118,8 +118,8 @@ ScriptEditorDebugger *EditorDebuggerNode::_add_debugger() { } if (!debugger_plugins.is_empty()) { - for (RBSet>::Element *i = debugger_plugins.front(); i; i = i->next()) { - node->add_debugger_plugin(i->get()); + for (const Ref