From 4e6efd1b07f1c6d53d226977ddc729333b74306a Mon Sep 17 00:00:00 2001 From: Aaron Franke Date: Thu, 15 Jul 2021 23:45:57 -0400 Subject: Use C++ iterators for Lists in many situations --- scene/2d/animated_sprite_2d.cpp | 2 +- scene/2d/physics_body_2d.cpp | 3 +- scene/2d/tile_map.cpp | 20 +++--- scene/3d/gpu_particles_collision_3d.cpp | 4 +- scene/3d/mesh_instance_3d.cpp | 4 +- scene/3d/node_3d.cpp | 12 ++-- scene/3d/physics_body_3d.cpp | 3 +- scene/3d/skeleton_3d.cpp | 12 ++-- scene/3d/soft_body_3d.cpp | 3 +- scene/3d/sprite_3d.cpp | 6 +- scene/3d/visual_instance_3d.cpp | 3 +- scene/3d/voxel_gi.cpp | 4 +- scene/animation/animation_blend_tree.cpp | 12 ++-- scene/animation/animation_cache.cpp | 10 +-- scene/animation/animation_node_state_machine.cpp | 11 ++-- scene/animation/animation_player.cpp | 26 ++++---- scene/animation/animation_tree.cpp | 48 +++++++------- scene/animation/tween.cpp | 8 +-- scene/debugger/scene_debugger.cpp | 9 ++- scene/gui/code_edit.cpp | 21 +++--- scene/gui/control.cpp | 84 ++++++++++++------------ scene/gui/file_dialog.cpp | 6 +- scene/gui/graph_edit.cpp | 76 ++++++++++----------- scene/gui/popup_menu.cpp | 8 +-- scene/gui/rich_text_label.cpp | 42 ++++++------ scene/main/canvas_item.cpp | 15 ++--- scene/main/http_request.cpp | 10 +-- scene/main/instance_placeholder.cpp | 22 +++---- scene/main/node.cpp | 62 +++++++++-------- scene/main/scene_tree.cpp | 15 ++--- scene/main/viewport.cpp | 3 +- scene/main/window.cpp | 8 +-- scene/resources/animation.h | 8 +-- scene/resources/curve.cpp | 10 +-- scene/resources/material.cpp | 4 +- scene/resources/navigation_mesh.cpp | 8 +-- scene/resources/packed_scene.cpp | 34 +++++----- scene/resources/resource_format_text.cpp | 10 +-- scene/resources/shader.cpp | 5 +- scene/resources/sprite_frames.cpp | 4 +- scene/resources/syntax_highlighter.cpp | 4 +- scene/resources/theme.cpp | 12 ++-- scene/resources/tile_set.cpp | 20 +++--- scene/resources/visual_shader.cpp | 52 +++++++-------- 44 files changed, 358 insertions(+), 385 deletions(-) (limited to 'scene') diff --git a/scene/2d/animated_sprite_2d.cpp b/scene/2d/animated_sprite_2d.cpp index 9ee37670d1..da2ab6ada8 100644 --- a/scene/2d/animated_sprite_2d.cpp +++ b/scene/2d/animated_sprite_2d.cpp @@ -123,7 +123,7 @@ void AnimatedSprite2D::_validate_property(PropertyInfo &property) const { } property.hint_string += String(E->get()); - if (animation == E->get()) { + if (animation == E) { current_found = true; } } diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp index 5b12da8b57..8709acf7f1 100644 --- a/scene/2d/physics_body_2d.cpp +++ b/scene/2d/physics_body_2d.cpp @@ -145,8 +145,7 @@ TypedArray PhysicsBody2D::get_collision_exceptions() { List exceptions; PhysicsServer2D::get_singleton()->body_get_collision_exceptions(get_rid(), &exceptions); Array ret; - for (List::Element *E = exceptions.front(); E; E = E->next()) { - RID body = E->get(); + for (RID body : exceptions) { ObjectID instance_id = PhysicsServer2D::get_singleton()->body_get_object_instance_id(body); Object *obj = ObjectDB::get_instance(instance_id); PhysicsBody2D *physics_body = Object::cast_to(obj); diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp index bf2f8f8947..4a15a1dc46 100644 --- a/scene/2d/tile_map.cpp +++ b/scene/2d/tile_map.cpp @@ -1596,8 +1596,8 @@ void TileMap::set_light_mask(int p_light_mask) { // Occlusion: set light mask. CanvasItem::set_light_mask(p_light_mask); for (Map::Element *E = quadrant_map.front(); E; E = E->next()) { - for (List::Element *F = E->get().canvas_items.front(); F; F = F->next()) { - RenderingServer::get_singleton()->canvas_item_set_light_mask(F->get(), get_light_mask()); + for (RID F : E->get().canvas_items) { + RenderingServer::get_singleton()->canvas_item_set_light_mask(F, get_light_mask()); } } } @@ -1609,8 +1609,8 @@ void TileMap::set_material(const Ref &p_material) { // Update material for the whole tilemap. for (Map::Element *E = quadrant_map.front(); E; E = E->next()) { TileMapQuadrant &q = E->get(); - for (List::Element *F = q.canvas_items.front(); F; F = F->next()) { - RS::get_singleton()->canvas_item_set_use_parent_material(F->get(), get_use_parent_material() || get_material().is_valid()); + for (RID F : q.canvas_items) { + RS::get_singleton()->canvas_item_set_use_parent_material(F, get_use_parent_material() || get_material().is_valid()); } } } @@ -1622,8 +1622,8 @@ void TileMap::set_use_parent_material(bool p_use_parent_material) { // Update use_parent_material for the whole tilemap. for (Map::Element *E = quadrant_map.front(); E; E = E->next()) { TileMapQuadrant &q = E->get(); - for (List::Element *F = q.canvas_items.front(); F; F = F->next()) { - RS::get_singleton()->canvas_item_set_use_parent_material(F->get(), get_use_parent_material() || get_material().is_valid()); + for (RID F : q.canvas_items) { + RS::get_singleton()->canvas_item_set_use_parent_material(F, get_use_parent_material() || get_material().is_valid()); } } } @@ -1633,8 +1633,8 @@ void TileMap::set_texture_filter(TextureFilter p_texture_filter) { CanvasItem::set_texture_filter(p_texture_filter); for (Map::Element *F = quadrant_map.front(); F; F = F->next()) { TileMapQuadrant &q = F->get(); - for (List::Element *E = q.canvas_items.front(); E; E = E->next()) { - RenderingServer::get_singleton()->canvas_item_set_default_texture_filter(E->get(), RS::CanvasItemTextureFilter(p_texture_filter)); + for (RID E : q.canvas_items) { + RenderingServer::get_singleton()->canvas_item_set_default_texture_filter(E, RS::CanvasItemTextureFilter(p_texture_filter)); _make_quadrant_dirty(F); } } @@ -1645,8 +1645,8 @@ void TileMap::set_texture_repeat(CanvasItem::TextureRepeat p_texture_repeat) { CanvasItem::set_texture_repeat(p_texture_repeat); for (Map::Element *F = quadrant_map.front(); F; F = F->next()) { TileMapQuadrant &q = F->get(); - for (List::Element *E = q.canvas_items.front(); E; E = E->next()) { - RenderingServer::get_singleton()->canvas_item_set_default_texture_repeat(E->get(), RS::CanvasItemTextureRepeat(p_texture_repeat)); + for (RID E : q.canvas_items) { + RenderingServer::get_singleton()->canvas_item_set_default_texture_repeat(E, RS::CanvasItemTextureRepeat(p_texture_repeat)); _make_quadrant_dirty(F); } } diff --git a/scene/3d/gpu_particles_collision_3d.cpp b/scene/3d/gpu_particles_collision_3d.cpp index df7d7be1fd..97b562837a 100644 --- a/scene/3d/gpu_particles_collision_3d.cpp +++ b/scene/3d/gpu_particles_collision_3d.cpp @@ -397,9 +397,7 @@ Ref GPUParticlesCollisionSDF::bake() { bake_step_function(0, "Finding Meshes"); } - for (List::Element *E = plot_meshes.front(); E; E = E->next()) { - const PlotMesh &pm = E->get(); - + for (PlotMesh &pm : plot_meshes) { for (int i = 0; i < pm.mesh->get_surface_count(); i++) { if (pm.mesh->surface_get_primitive_type(i) != Mesh::PRIMITIVE_TRIANGLES) { continue; //only triangles diff --git a/scene/3d/mesh_instance_3d.cpp b/scene/3d/mesh_instance_3d.cpp index 5bb598227c..93cd088418 100644 --- a/scene/3d/mesh_instance_3d.cpp +++ b/scene/3d/mesh_instance_3d.cpp @@ -94,8 +94,8 @@ void MeshInstance3D::_get_property_list(List *p_list) const { ls.sort(); - for (List::Element *E = ls.front(); E; E = E->next()) { - p_list->push_back(PropertyInfo(Variant::FLOAT, E->get(), PROPERTY_HINT_RANGE, "-1,1,0.00001")); + for (String &E : ls) { + p_list->push_back(PropertyInfo(Variant::FLOAT, E, PROPERTY_HINT_RANGE, "-1,1,0.00001")); } if (mesh.is_valid()) { diff --git a/scene/3d/node_3d.cpp b/scene/3d/node_3d.cpp index d1f96230e0..0daee69ee5 100644 --- a/scene/3d/node_3d.cpp +++ b/scene/3d/node_3d.cpp @@ -103,11 +103,11 @@ void Node3D::_propagate_transform_changed(Node3D *p_origin) { data.children_lock++; - for (List::Element *E = data.children.front(); E; E = E->next()) { - if (E->get()->data.top_level_active) { + for (Node3D *&E : data.children) { + if (E->data.top_level_active) { continue; //don't propagate to a top_level } - E->get()->_propagate_transform_changed(p_origin); + E->_propagate_transform_changed(p_origin); } #ifdef TOOLS_ENABLED if ((!data.gizmos.is_empty() || data.notify_transform) && !data.ignore_notification && !xform_change.in_list()) { @@ -527,8 +527,7 @@ void Node3D::_propagate_visibility_changed() { } #endif - for (List::Element *E = data.children.front(); E; E = E->next()) { - Node3D *c = E->get(); + for (Node3D *c : data.children) { if (!c || !c->data.visible) { continue; } @@ -753,8 +752,7 @@ void Node3D::_update_visibility_parent(bool p_update_root) { RS::get_singleton()->instance_set_visibility_parent(vi->get_instance(), data.visibility_parent); } - for (List::Element *E = data.children.front(); E; E = E->next()) { - Node3D *c = E->get(); + for (Node3D *c : data.children) { c->_update_visibility_parent(false); } } diff --git a/scene/3d/physics_body_3d.cpp b/scene/3d/physics_body_3d.cpp index 0e3180bcdf..6736a4ec40 100644 --- a/scene/3d/physics_body_3d.cpp +++ b/scene/3d/physics_body_3d.cpp @@ -78,8 +78,7 @@ TypedArray PhysicsBody3D::get_collision_exceptions() { List exceptions; PhysicsServer3D::get_singleton()->body_get_collision_exceptions(get_rid(), &exceptions); Array ret; - for (List::Element *E = exceptions.front(); E; E = E->next()) { - RID body = E->get(); + for (RID body : exceptions) { ObjectID instance_id = PhysicsServer3D::get_singleton()->body_get_object_instance_id(body); Object *obj = ObjectDB::get_instance(instance_id); PhysicsBody3D *physics_body = Object::cast_to(obj); diff --git a/scene/3d/skeleton_3d.cpp b/scene/3d/skeleton_3d.cpp index ba70a6eb41..fb5e9639c7 100644 --- a/scene/3d/skeleton_3d.cpp +++ b/scene/3d/skeleton_3d.cpp @@ -264,8 +264,8 @@ void Skeleton3D::_notification(int p_what) { b.global_pose_override_amount = 0.0; } - for (List::Element *E = b.nodes_bound.front(); E; E = E->next()) { - Object *obj = ObjectDB::get_instance(E->get()); + for (ObjectID &E : b.nodes_bound) { + Object *obj = ObjectDB::get_instance(E); ERR_CONTINUE(!obj); Node3D *node_3d = Object::cast_to(obj); ERR_CONTINUE(!node_3d); @@ -524,8 +524,8 @@ void Skeleton3D::bind_child_node_to_bone(int p_bone, Node *p_node) { ObjectID id = p_node->get_instance_id(); - for (const List::Element *E = bones[p_bone].nodes_bound.front(); E; E = E->next()) { - if (E->get() == id) { + for (const ObjectID &E : bones[p_bone].nodes_bound) { + if (E == id) { return; // already here } } @@ -544,8 +544,8 @@ void Skeleton3D::unbind_child_node_from_bone(int p_bone, Node *p_node) { void Skeleton3D::get_bound_child_nodes_to_bone(int p_bone, List *p_bound) const { ERR_FAIL_INDEX(p_bone, bones.size()); - for (const List::Element *E = bones[p_bone].nodes_bound.front(); E; E = E->next()) { - Object *obj = ObjectDB::get_instance(E->get()); + for (const ObjectID &E : bones[p_bone].nodes_bound) { + Object *obj = ObjectDB::get_instance(E); ERR_CONTINUE(!obj); p_bound->push_back(Object::cast_to(obj)); } diff --git a/scene/3d/soft_body_3d.cpp b/scene/3d/soft_body_3d.cpp index 05530c39a1..0d00d10d32 100644 --- a/scene/3d/soft_body_3d.cpp +++ b/scene/3d/soft_body_3d.cpp @@ -592,8 +592,7 @@ Array SoftBody3D::get_collision_exceptions() { List exceptions; PhysicsServer3D::get_singleton()->soft_body_get_collision_exceptions(physics_rid, &exceptions); Array ret; - for (List::Element *E = exceptions.front(); E; E = E->next()) { - RID body = E->get(); + for (RID body : exceptions) { ObjectID instance_id = PhysicsServer3D::get_singleton()->body_get_object_instance_id(body); Object *obj = ObjectDB::get_instance(instance_id); PhysicsBody3D *physics_body = Object::cast_to(obj); diff --git a/scene/3d/sprite_3d.cpp b/scene/3d/sprite_3d.cpp index fd3bf99e0a..a901920dbe 100644 --- a/scene/3d/sprite_3d.cpp +++ b/scene/3d/sprite_3d.cpp @@ -60,8 +60,8 @@ void SpriteBase3D::_propagate_color_changed() { color_dirty = true; _queue_update(); - for (List::Element *E = children.front(); E; E = E->next()) { - E->get()->_propagate_color_changed(); + for (SpriteBase3D *&E : children) { + E->_propagate_color_changed(); } } @@ -996,7 +996,7 @@ void AnimatedSprite3D::_validate_property(PropertyInfo &property) const { } property.hint_string += String(E->get()); - if (animation == E->get()) { + if (animation == E) { current_found = true; } } diff --git a/scene/3d/visual_instance_3d.cpp b/scene/3d/visual_instance_3d.cpp index bd47af8100..70a7021f22 100644 --- a/scene/3d/visual_instance_3d.cpp +++ b/scene/3d/visual_instance_3d.cpp @@ -238,8 +238,7 @@ bool GeometryInstance3D::_get(const StringName &p_name, Variant &r_ret) const { void GeometryInstance3D::_get_property_list(List *p_list) const { List pinfo; RS::get_singleton()->instance_geometry_get_shader_parameter_list(get_instance(), &pinfo); - for (List::Element *E = pinfo.front(); E; E = E->next()) { - PropertyInfo pi = E->get(); + for (PropertyInfo &pi : pinfo) { bool has_def_value = false; Variant def_value = RS::get_singleton()->instance_geometry_get_shader_parameter_default_value(get_instance(), pi.name); if (def_value.get_type() != Variant::NIL) { diff --git a/scene/3d/voxel_gi.cpp b/scene/3d/voxel_gi.cpp index bc52db5387..5cf7522667 100644 --- a/scene/3d/voxel_gi.cpp +++ b/scene/3d/voxel_gi.cpp @@ -384,14 +384,14 @@ void VoxelGI::bake(Node *p_from_node, bool p_create_visual_debug) { int pmc = 0; - for (List::Element *E = mesh_list.front(); E; E = E->next()) { + for (PlotMesh &E : mesh_list) { if (bake_step_function) { bake_step_function(pmc, RTR("Plotting Meshes") + " " + itos(pmc) + "/" + itos(mesh_list.size())); } pmc++; - baker.plot_mesh(E->get().local_xform, E->get().mesh, E->get().instance_materials, E->get().override_material); + baker.plot_mesh(E.local_xform, E.mesh, E.instance_materials, E.override_material); } if (bake_step_function) { bake_step_function(pmc++, RTR("Finishing Plot")); diff --git a/scene/animation/animation_blend_tree.cpp b/scene/animation/animation_blend_tree.cpp index 200a688067..495f60d4c9 100644 --- a/scene/animation/animation_blend_tree.cpp +++ b/scene/animation/animation_blend_tree.cpp @@ -1089,10 +1089,10 @@ bool AnimationNodeBlendTree::_get(const StringName &p_name, Variant &r_ret) cons conns.resize(nc.size() * 3); int idx = 0; - for (List::Element *E = nc.front(); E; E = E->next()) { - conns[idx * 3 + 0] = E->get().input_node; - conns[idx * 3 + 1] = E->get().input_index; - conns[idx * 3 + 2] = E->get().output_node; + for (NodeConnection &E : nc) { + conns[idx * 3 + 0] = E.input_node; + conns[idx * 3 + 1] = E.input_index; + conns[idx * 3 + 2] = E.output_node; idx++; } @@ -1110,8 +1110,8 @@ void AnimationNodeBlendTree::_get_property_list(List *p_list) cons } names.sort_custom(); - for (List::Element *E = names.front(); E; E = E->next()) { - String name = E->get(); + for (StringName &E : names) { + String name = E; if (name != "output") { p_list->push_back(PropertyInfo(Variant::OBJECT, "nodes/" + name + "/node", PROPERTY_HINT_RESOURCE_TYPE, "AnimationNode", PROPERTY_USAGE_NOEDITOR)); } diff --git a/scene/animation/animation_cache.cpp b/scene/animation/animation_cache.cpp index b8980fd56b..56743007e4 100644 --- a/scene/animation/animation_cache.cpp +++ b/scene/animation/animation_cache.cpp @@ -252,8 +252,8 @@ void AnimationCache::set_all(float p_time, float p_delta) { List indices; animation->value_track_get_key_indices(i, p_time, p_delta, &indices); - for (List::Element *E = indices.front(); E; E = E->next()) { - Variant v = animation->track_get_key_value(i, E->get()); + for (int &E : indices) { + Variant v = animation->track_get_key_value(i, E); set_track_value(i, v); } } @@ -263,9 +263,9 @@ void AnimationCache::set_all(float p_time, float p_delta) { List indices; animation->method_track_get_key_indices(i, p_time, p_delta, &indices); - for (List::Element *E = indices.front(); E; E = E->next()) { - Vector args = animation->method_track_get_params(i, E->get()); - StringName name = animation->method_track_get_name(i, E->get()); + for (int &E : indices) { + Vector args = animation->method_track_get_params(i, E); + StringName name = animation->method_track_get_name(i, E); Callable::CallError err; if (!args.size()) { diff --git a/scene/animation/animation_node_state_machine.cpp b/scene/animation/animation_node_state_machine.cpp index 6496331cb0..383d92d37f 100644 --- a/scene/animation/animation_node_state_machine.cpp +++ b/scene/animation/animation_node_state_machine.cpp @@ -512,8 +512,8 @@ void AnimationNodeStateMachine::get_parameter_list(List *r_list) c } advance_conditions.sort_custom(); - for (List::Element *E = advance_conditions.front(); E; E = E->next()) { - r_list->push_back(PropertyInfo(Variant::BOOL, E->get())); + for (StringName &E : advance_conditions) { + r_list->push_back(PropertyInfo(Variant::BOOL, E)); } } @@ -679,8 +679,8 @@ void AnimationNodeStateMachine::get_node_list(List *r_nodes) const { } nodes.sort_custom(); - for (List::Element *E = nodes.front(); E; E = E->next()) { - r_nodes->push_back(E->get()); + for (StringName &E : nodes) { + r_nodes->push_back(E); } } @@ -902,8 +902,7 @@ void AnimationNodeStateMachine::_get_property_list(List *p_list) c } names.sort_custom(); - for (List::Element *E = names.front(); E; E = E->next()) { - String name = E->get(); + for (StringName &name : names) { p_list->push_back(PropertyInfo(Variant::OBJECT, "states/" + name + "/node", PROPERTY_HINT_RESOURCE_TYPE, "AnimationNode", PROPERTY_USAGE_NOEDITOR)); p_list->push_back(PropertyInfo(Variant::VECTOR2, "states/" + name + "/position", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR)); } diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp index 14ca325c25..0f557519b2 100644 --- a/scene/animation/animation_player.cpp +++ b/scene/animation/animation_player.cpp @@ -176,8 +176,8 @@ void AnimationPlayer::_get_property_list(List *p_list) const { anim_names.sort(); - for (List::Element *E = anim_names.front(); E; E = E->next()) { - p_list->push_back(E->get()); + for (PropertyInfo &E : anim_names) { + p_list->push_back(E); } p_list->push_back(PropertyInfo(Variant::ARRAY, "blend_times", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL)); @@ -485,8 +485,8 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, float List indices; a->value_track_get_key_indices(i, p_time, p_delta, &indices); - for (List::Element *F = indices.front(); F; F = F->next()) { - Variant value = a->track_get_key_value(i, F->get()); + for (int &F : indices) { + Variant value = a->track_get_key_value(i, F); switch (pa->special) { case SP_NONE: { bool valid; @@ -544,9 +544,9 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, float a->method_track_get_key_indices(i, p_time, p_delta, &indices); - for (List::Element *E = indices.front(); E; E = E->next()) { - StringName method = a->method_track_get_name(i, E->get()); - Vector params = a->method_track_get_params(i, E->get()); + for (int &E : indices) { + StringName method = a->method_track_get_name(i, E); + Vector params = a->method_track_get_params(i, E); int s = params.size(); @@ -1076,8 +1076,8 @@ void AnimationPlayer::get_animation_list(List *p_animations) const { anims.sort(); - for (List::Element *E = anims.front(); E; E = E->next()) { - p_animations->push_back(E->get()); + for (String &E : anims) { + p_animations->push_back(E); } } @@ -1118,8 +1118,8 @@ void AnimationPlayer::queue(const StringName &p_name) { Vector AnimationPlayer::get_queue() { Vector ret; - for (List::Element *E = queued.front(); E; E = E->next()) { - ret.push_back(E->get()); + for (StringName &E : queued) { + ret.push_back(E); } return ret; @@ -1502,8 +1502,8 @@ void AnimationPlayer::get_argument_options(const StringName &p_function, int p_i if (p_idx == 0 && (p_function == "play" || p_function == "play_backwards" || p_function == "remove_animation" || p_function == "has_animation" || p_function == "queue")) { List al; get_animation_list(&al); - for (List::Element *E = al.front(); E; E = E->next()) { - r_options->push_back(quote_style + String(E->get()) + quote_style); + for (StringName &E : al) { + r_options->push_back(quote_style + String(E) + quote_style); } } Node::get_argument_options(p_function, p_idx, r_options); diff --git a/scene/animation/animation_tree.cpp b/scene/animation/animation_tree.cpp index 72448fc4f7..d277808e1f 100644 --- a/scene/animation/animation_tree.cpp +++ b/scene/animation/animation_tree.cpp @@ -76,10 +76,10 @@ void AnimationNode::get_child_nodes(List *r_child_nodes) { Dictionary cn = get_script_instance()->call("_get_child_nodes"); List keys; cn.get_key_list(&keys); - for (List::Element *E = keys.front(); E; E = E->next()) { + for (Variant &E : keys) { ChildNode child; - child.name = E->get(); - child.node = cn[E->get()]; + child.name = E; + child.node = cn[E]; r_child_nodes->push_back(child); } } @@ -536,8 +536,8 @@ bool AnimationTree::_update_caches(AnimationPlayer *player) { List sname; player->get_animation_list(&sname); - for (List::Element *E = sname.front(); E; E = E->next()) { - Ref anim = player->get_animation(E->get()); + for (StringName &E : sname) { + Ref anim = player->get_animation(E); for (int i = 0; i < anim->get_track_count(); i++) { NodePath path = anim->track_get_path(i); Animation::TrackType track_type = anim->track_get_type(i); @@ -561,7 +561,7 @@ bool AnimationTree::_update_caches(AnimationPlayer *player) { Node *child = parent->get_node_and_resource(path, resource, leftover_path); if (!child) { - ERR_PRINT("AnimationTree: '" + String(E->get()) + "', couldn't resolve track: '" + String(path) + "'"); + ERR_PRINT("AnimationTree: '" + String(E) + "', couldn't resolve track: '" + String(path) + "'"); continue; } @@ -590,7 +590,7 @@ bool AnimationTree::_update_caches(AnimationPlayer *player) { Node3D *node_3d = Object::cast_to(child); if (!node_3d) { - ERR_PRINT("AnimationTree: '" + String(E->get()) + "', transform track does not point to Node3D: '" + String(path) + "'"); + ERR_PRINT("AnimationTree: '" + String(E) + "', transform track does not point to Node3D: '" + String(path) + "'"); continue; } @@ -816,9 +816,7 @@ void AnimationTree::_process_graph(float p_delta) { { bool can_call = is_inside_tree() && !Engine::get_singleton()->is_editor_hint(); - for (List::Element *E = state.animation_states.front(); E; E = E->next()) { - const AnimationNode::AnimationState &as = E->get(); - + for (AnimationNode::AnimationState &as : state.animation_states) { Ref a = as.animation; float time = as.time; float delta = as.delta; @@ -962,8 +960,8 @@ void AnimationTree::_process_graph(float p_delta) { List indices; a->value_track_get_key_indices(i, time, delta, &indices); - for (List::Element *F = indices.front(); F; F = F->next()) { - Variant value = a->track_get_key_value(i, F->get()); + for (int &F : indices) { + Variant value = a->track_get_key_value(i, F); t->object->set_indexed(t->subpath, value); } } @@ -979,9 +977,9 @@ void AnimationTree::_process_graph(float p_delta) { a->method_track_get_key_indices(i, time, delta, &indices); - for (List::Element *F = indices.front(); F; F = F->next()) { - StringName method = a->method_track_get_name(i, F->get()); - Vector params = a->method_track_get_params(i, F->get()); + for (int &F : indices) { + StringName method = a->method_track_get_name(i, F); + Vector params = a->method_track_get_params(i, F); int s = params.size(); @@ -1355,9 +1353,7 @@ void AnimationTree::_update_properties_for_node(const String &p_base_path, Ref plist; node->get_parameter_list(&plist); - for (List::Element *E = plist.front(); E; E = E->next()) { - PropertyInfo pinfo = E->get(); - + for (PropertyInfo &pinfo : plist) { StringName key = pinfo.name; if (!property_map.has(p_base_path + key)) { @@ -1373,8 +1369,8 @@ void AnimationTree::_update_properties_for_node(const String &p_base_path, Ref children; node->get_child_nodes(&children); - for (List::Element *E = children.front(); E; E = E->next()) { - _update_properties_for_node(p_base_path + E->get().name + "/", E->get().node); + for (AnimationNode::ChildNode &E : children) { + _update_properties_for_node(p_base_path + E.name + "/", E.node); } } @@ -1428,17 +1424,17 @@ void AnimationTree::_get_property_list(List *p_list) const { const_cast(this)->_update_properties(); } - for (const List::Element *E = properties.front(); E; E = E->next()) { - p_list->push_back(E->get()); + for (const PropertyInfo &E : properties) { + p_list->push_back(E); } } void AnimationTree::rename_parameter(const String &p_base, const String &p_new_base) { //rename values first - for (const List::Element *E = properties.front(); E; E = E->next()) { - if (E->get().name.begins_with(p_base)) { - String new_name = E->get().name.replace_first(p_base, p_new_base); - property_map[new_name] = property_map[E->get().name]; + for (const PropertyInfo &E : properties) { + if (E.name.begins_with(p_base)) { + String new_name = E.name.replace_first(p_base, p_new_base); + property_map[new_name] = property_map[E.name]; } } diff --git a/scene/animation/tween.cpp b/scene/animation/tween.cpp index 761046c14a..b31c3d57f9 100644 --- a/scene/animation/tween.cpp +++ b/scene/animation/tween.cpp @@ -46,8 +46,8 @@ void Tween::start_tweeners() { ERR_FAIL_MSG("Tween without commands, aborting."); } - for (List>::Element *E = tweeners.write[current_step].front(); E; E = E->next()) { - E->get()->start(); + for (Ref E : tweeners.write[current_step]) { + E->start(); } } @@ -253,11 +253,11 @@ bool Tween::step(float p_delta) { float step_delta = rem_delta; step_active = false; - for (List>::Element *E = tweeners.write[current_step].front(); E; E = E->next()) { + for (Ref E : tweeners.write[current_step]) { // Modified inside Tweener.step(). float temp_delta = rem_delta; // Turns to true if any Tweener returns true (i.e. is still not finished). - step_active = E->get()->step(temp_delta) || step_active; + step_active = E->step(temp_delta) || step_active; step_delta = MIN(temp_delta, rem_delta); } diff --git a/scene/debugger/scene_debugger.cpp b/scene/debugger/scene_debugger.cpp index fd5637be11..5012aed99a 100644 --- a/scene/debugger/scene_debugger.cpp +++ b/scene/debugger/scene_debugger.cpp @@ -292,9 +292,9 @@ SceneDebuggerObject::SceneDebuggerObject(ObjectID p_id) { // Add base object properties. List pinfo; obj->get_property_list(&pinfo, true); - for (List::Element *E = pinfo.front(); E; E = E->next()) { - if (E->get().usage & (PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CATEGORY)) { - properties.push_back(SceneDebuggerProperty(E->get(), obj->get(E->get().name))); + for (PropertyInfo &E : pinfo) { + if (E.usage & (PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CATEGORY)) { + properties.push_back(SceneDebuggerProperty(E, obj->get(E.name))); } } } @@ -452,8 +452,7 @@ SceneDebuggerTree::SceneDebuggerTree(Node *p_root) { } void SceneDebuggerTree::serialize(Array &p_arr) { - for (List::Element *E = nodes.front(); E; E = E->next()) { - RemoteNode &n = E->get(); + for (RemoteNode &n : nodes) { p_arr.push_back(n.child_count); p_arr.push_back(n.name); p_arr.push_back(n.type_name); diff --git a/scene/gui/code_edit.cpp b/scene/gui/code_edit.cpp index f302f64224..6e3d0e2767 100644 --- a/scene/gui/code_edit.cpp +++ b/scene/gui/code_edit.cpp @@ -2288,14 +2288,14 @@ void CodeEdit::_filter_code_completion_candidates() { TypedArray completion_options_sources; completion_options_sources.resize(code_completion_option_sources.size()); int i = 0; - for (List::Element *E = code_completion_option_sources.front(); E; E = E->next()) { + for (ScriptCodeCompletionOption &E : code_completion_option_sources) { Dictionary option; - option["kind"] = E->get().kind; - option["display_text"] = E->get().display; - option["insert_text"] = E->get().insert_text; - option["font_color"] = E->get().font_color; - option["icon"] = E->get().icon; - option["default_value"] = E->get().default_value; + option["kind"] = E.kind; + option["display_text"] = E.display; + option["insert_text"] = E.insert_text; + option["font_color"] = E.font_color; + option["icon"] = E.icon; + option["default_value"] = E.default_value; completion_options_sources[i] = option; i++; } @@ -2406,9 +2406,7 @@ void CodeEdit::_filter_code_completion_candidates() { int max_width = 0; String string_to_complete_lower = string_to_complete.to_lower(); - for (List::Element *E = code_completion_option_sources.front(); E; E = E->next()) { - ScriptCodeCompletionOption &option = E->get(); - + for (ScriptCodeCompletionOption &option : code_completion_option_sources) { if (single_quote && option.display.is_quoted()) { option.display = option.display.unquote().quote("'"); } @@ -2527,8 +2525,7 @@ void CodeEdit::_lines_edited_from(int p_from_line, int p_to_line) { int line_count = (p_to_line - p_from_line); List breakpoints; breakpointed_lines.get_key_list(&breakpoints); - for (const List::Element *E = breakpoints.front(); E; E = E->next()) { - int line = E->get(); + for (const int line : breakpoints) { if (line <= from_line) { continue; } diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 032533d4a9..ae1f4b2f65 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -343,73 +343,73 @@ void Control::_get_property_list(List *p_list) const { { List names; theme->get_icon_list(get_class_name(), &names); - for (List::Element *E = names.front(); E; E = E->next()) { + for (StringName &E : names) { uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE; - if (data.icon_override.has(E->get())) { + if (data.icon_override.has(E)) { usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED; } - p_list->push_back(PropertyInfo(Variant::OBJECT, "custom_icons/" + E->get(), PROPERTY_HINT_RESOURCE_TYPE, "Texture2D", usage)); + p_list->push_back(PropertyInfo(Variant::OBJECT, "custom_icons/" + E, PROPERTY_HINT_RESOURCE_TYPE, "Texture2D", usage)); } } { List names; theme->get_stylebox_list(get_class_name(), &names); - for (List::Element *E = names.front(); E; E = E->next()) { + for (StringName &E : names) { uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE; - if (data.style_override.has(E->get())) { + if (data.style_override.has(E)) { usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED; } - p_list->push_back(PropertyInfo(Variant::OBJECT, "custom_styles/" + E->get(), PROPERTY_HINT_RESOURCE_TYPE, "StyleBox", usage)); + p_list->push_back(PropertyInfo(Variant::OBJECT, "custom_styles/" + E, PROPERTY_HINT_RESOURCE_TYPE, "StyleBox", usage)); } } { List names; theme->get_font_list(get_class_name(), &names); - for (List::Element *E = names.front(); E; E = E->next()) { + for (StringName &E : names) { uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE; - if (data.font_override.has(E->get())) { + if (data.font_override.has(E)) { usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED; } - p_list->push_back(PropertyInfo(Variant::OBJECT, "custom_fonts/" + E->get(), PROPERTY_HINT_RESOURCE_TYPE, "Font", usage)); + p_list->push_back(PropertyInfo(Variant::OBJECT, "custom_fonts/" + E, PROPERTY_HINT_RESOURCE_TYPE, "Font", usage)); } } { List names; theme->get_font_size_list(get_class_name(), &names); - for (List::Element *E = names.front(); E; E = E->next()) { + for (StringName &E : names) { uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE; - if (data.font_size_override.has(E->get())) { + if (data.font_size_override.has(E)) { usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED; } - p_list->push_back(PropertyInfo(Variant::INT, "custom_font_sizes/" + E->get(), PROPERTY_HINT_NONE, "", usage)); + p_list->push_back(PropertyInfo(Variant::INT, "custom_font_sizes/" + E, PROPERTY_HINT_NONE, "", usage)); } } { List names; theme->get_color_list(get_class_name(), &names); - for (List::Element *E = names.front(); E; E = E->next()) { + for (StringName &E : names) { uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE; - if (data.color_override.has(E->get())) { + if (data.color_override.has(E)) { usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED; } - p_list->push_back(PropertyInfo(Variant::COLOR, "custom_colors/" + E->get(), PROPERTY_HINT_NONE, "", usage)); + p_list->push_back(PropertyInfo(Variant::COLOR, "custom_colors/" + E, PROPERTY_HINT_NONE, "", usage)); } } { List names; theme->get_constant_list(get_class_name(), &names); - for (List::Element *E = names.front(); E; E = E->next()) { + for (StringName &E : names) { uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE; - if (data.constant_override.has(E->get())) { + if (data.constant_override.has(E)) { usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED; } - p_list->push_back(PropertyInfo(Variant::INT, "custom_constants/" + E->get(), PROPERTY_HINT_RANGE, "-16384,16384", usage)); + p_list->push_back(PropertyInfo(Variant::INT, "custom_constants/" + E, PROPERTY_HINT_RANGE, "-16384,16384", usage)); } } } @@ -428,14 +428,14 @@ void Control::_validate_property(PropertyInfo &property) const { Vector unique_names; String hint_string; - for (List::Element *E = names.front(); E; E = E->next()) { + for (StringName &E : names) { // Skip duplicate values. - if (unique_names.has(E->get())) { + if (unique_names.has(E)) { continue; } - hint_string += String(E->get()) + ","; - unique_names.append(E->get()); + hint_string += String(E) + ","; + unique_names.append(E); } property.hint_string = hint_string; @@ -793,13 +793,13 @@ T Control::get_theme_item_in_types(Control *p_theme_owner, Window *p_theme_owner Window *theme_owner_window = p_theme_owner_window; while (theme_owner || theme_owner_window) { - for (List::Element *E = p_theme_types.front(); E; E = E->next()) { - if (theme_owner && theme_owner->data.theme->has_theme_item(p_data_type, p_name, E->get())) { - return theme_owner->data.theme->get_theme_item(p_data_type, p_name, E->get()); + for (StringName &E : p_theme_types) { + if (theme_owner && theme_owner->data.theme->has_theme_item(p_data_type, p_name, E)) { + return theme_owner->data.theme->get_theme_item(p_data_type, p_name, E); } - if (theme_owner_window && theme_owner_window->theme->has_theme_item(p_data_type, p_name, E->get())) { - return theme_owner_window->theme->get_theme_item(p_data_type, p_name, E->get()); + if (theme_owner_window && theme_owner_window->theme->has_theme_item(p_data_type, p_name, E)) { + return theme_owner_window->theme->get_theme_item(p_data_type, p_name, E); } } @@ -822,17 +822,17 @@ T Control::get_theme_item_in_types(Control *p_theme_owner, Window *p_theme_owner // Secondly, check the project-defined Theme resource. if (Theme::get_project_default().is_valid()) { - for (List::Element *E = p_theme_types.front(); E; E = E->next()) { - if (Theme::get_project_default()->has_theme_item(p_data_type, p_name, E->get())) { - return Theme::get_project_default()->get_theme_item(p_data_type, p_name, E->get()); + for (StringName &E : p_theme_types) { + if (Theme::get_project_default()->has_theme_item(p_data_type, p_name, E)) { + return Theme::get_project_default()->get_theme_item(p_data_type, p_name, E); } } } // Lastly, fall back on the items defined in the default Theme, if they exist. - for (List::Element *E = p_theme_types.front(); E; E = E->next()) { - if (Theme::get_default()->has_theme_item(p_data_type, p_name, E->get())) { - return Theme::get_default()->get_theme_item(p_data_type, p_name, E->get()); + for (StringName &E : p_theme_types) { + if (Theme::get_default()->has_theme_item(p_data_type, p_name, E)) { + return Theme::get_default()->get_theme_item(p_data_type, p_name, E); } } // If they don't exist, use any type to return the default/empty value. @@ -848,12 +848,12 @@ bool Control::has_theme_item_in_types(Control *p_theme_owner, Window *p_theme_ow Window *theme_owner_window = p_theme_owner_window; while (theme_owner || theme_owner_window) { - for (List::Element *E = p_theme_types.front(); E; E = E->next()) { - if (theme_owner && theme_owner->data.theme->has_theme_item(p_data_type, p_name, E->get())) { + for (StringName &E : p_theme_types) { + if (theme_owner && theme_owner->data.theme->has_theme_item(p_data_type, p_name, E)) { return true; } - if (theme_owner_window && theme_owner_window->theme->has_theme_item(p_data_type, p_name, E->get())) { + if (theme_owner_window && theme_owner_window->theme->has_theme_item(p_data_type, p_name, E)) { return true; } } @@ -877,16 +877,16 @@ bool Control::has_theme_item_in_types(Control *p_theme_owner, Window *p_theme_ow // Secondly, check the project-defined Theme resource. if (Theme::get_project_default().is_valid()) { - for (List::Element *E = p_theme_types.front(); E; E = E->next()) { - if (Theme::get_project_default()->has_theme_item(p_data_type, p_name, E->get())) { + for (StringName &E : p_theme_types) { + if (Theme::get_project_default()->has_theme_item(p_data_type, p_name, E)) { return true; } } } // Lastly, fall back on the items defined in the default Theme, if they exist. - for (List::Element *E = p_theme_types.front(); E; E = E->next()) { - if (Theme::get_default()->has_theme_item(p_data_type, p_name, E->get())) { + for (StringName &E : p_theme_types) { + if (Theme::get_default()->has_theme_item(p_data_type, p_name, E)) { return true; } } @@ -2580,8 +2580,8 @@ void Control::get_argument_options(const StringName &p_function, int p_idx, List } sn.sort_custom(); - for (List::Element *E = sn.front(); E; E = E->next()) { - r_options->push_back(quote_style + E->get() + quote_style); + for (StringName &E : sn) { + r_options->push_back(quote_style + E + quote_style); } } } diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp index 9ed3a2244e..67cb6f04a7 100644 --- a/scene/gui/file_dialog.cpp +++ b/scene/gui/file_dialog.cpp @@ -552,9 +552,9 @@ void FileDialog::update_file_list() { bool match = patterns.is_empty(); String match_str; - for (List::Element *E = patterns.front(); E; E = E->next()) { - if (files.front()->get().matchn(E->get())) { - match_str = E->get(); + for (String &E : patterns) { + if (files.front()->get().matchn(E)) { + match_str = E; match = true; break; } diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp index 2281fb19c6..8ad4d04b7f 100644 --- a/scene/gui/graph_edit.cpp +++ b/scene/gui/graph_edit.cpp @@ -217,8 +217,8 @@ Error GraphEdit::connect_node(const StringName &p_from, int p_from_port, const S } bool GraphEdit::is_node_connected(const StringName &p_from, int p_from_port, const StringName &p_to, int p_to_port) { - for (List::Element *E = connections.front(); E; E = E->next()) { - if (E->get().from == p_from && E->get().from_port == p_from_port && E->get().to == p_to && E->get().to_port == p_to_port) { + for (Connection &E : connections) { + if (E.from == p_from && E.from_port == p_from_port && E.to == p_to && E.to_port == p_to_port) { return true; } } @@ -227,7 +227,7 @@ bool GraphEdit::is_node_connected(const StringName &p_from, int p_from_port, con } void GraphEdit::disconnect_node(const StringName &p_from, int p_from_port, const StringName &p_to, int p_to_port) { - for (List::Element *E = connections.front(); E; E = E->next()) { + for (const List::Element *E = connections.front(); E; E = E->next()) { if (E->get().from == p_from && E->get().from_port == p_from_port && E->get().to == p_to && E->get().to_port == p_to_port) { connections.erase(E); top_layer->update(); @@ -561,20 +561,20 @@ void GraphEdit::_top_layer_input(const Ref &p_ev) { if (is_in_hot_zone(pos / zoom, click_pos)) { if (valid_left_disconnect_types.has(gn->get_connection_output_type(j))) { //check disconnect - for (List::Element *E = connections.front(); E; E = E->next()) { - if (E->get().from == gn->get_name() && E->get().from_port == j) { - Node *to = get_node(String(E->get().to)); + for (Connection &E : connections) { + if (E.from == gn->get_name() && E.from_port == j) { + Node *to = get_node(String(E.to)); if (Object::cast_to(to)) { - connecting_from = E->get().to; - connecting_index = E->get().to_port; + connecting_from = E.to; + connecting_index = E.to_port; connecting_out = false; - connecting_type = Object::cast_to(to)->get_connection_input_type(E->get().to_port); - connecting_color = Object::cast_to(to)->get_connection_input_color(E->get().to_port); + connecting_type = Object::cast_to(to)->get_connection_input_type(E.to_port); + connecting_color = Object::cast_to(to)->get_connection_input_color(E.to_port); connecting_target = false; connecting_to = pos; just_disconnected = true; - emit_signal(SNAME("disconnection_request"), E->get().from, E->get().from_port, E->get().to, E->get().to_port); + emit_signal(SNAME("disconnection_request"), E.from, E.from_port, E.to, E.to_port); to = get_node(String(connecting_from)); //maybe it was erased if (Object::cast_to(to)) { connecting = true; @@ -603,20 +603,20 @@ void GraphEdit::_top_layer_input(const Ref &p_ev) { if (is_in_hot_zone(pos / zoom, click_pos)) { if (right_disconnects || valid_right_disconnect_types.has(gn->get_connection_input_type(j))) { //check disconnect - for (List::Element *E = connections.front(); E; E = E->next()) { - if (E->get().to == gn->get_name() && E->get().to_port == j) { - Node *fr = get_node(String(E->get().from)); + for (Connection &E : connections) { + if (E.to == gn->get_name() && E.to_port == j) { + Node *fr = get_node(String(E.from)); if (Object::cast_to(fr)) { - connecting_from = E->get().from; - connecting_index = E->get().from_port; + connecting_from = E.from; + connecting_index = E.from_port; connecting_out = true; - connecting_type = Object::cast_to(fr)->get_connection_output_type(E->get().from_port); - connecting_color = Object::cast_to(fr)->get_connection_output_color(E->get().from_port); + connecting_type = Object::cast_to(fr)->get_connection_output_type(E.from_port); + connecting_color = Object::cast_to(fr)->get_connection_output_color(E.from_port); connecting_target = false; connecting_to = pos; just_disconnected = true; - emit_signal(SNAME("disconnection_request"), E->get().from, E->get().from_port, E->get().to, E->get().to_port); + emit_signal(SNAME("disconnection_request"), E.from, E.from_port, E.to, E.to_port); fr = get_node(String(connecting_from)); //maybe it was erased if (Object::cast_to(fr)) { connecting = true; @@ -1001,8 +1001,8 @@ void GraphEdit::_minimap_draw() { // Draw node connections. Color activity_color = get_theme_color(SNAME("activity")); - for (List::Element *E = connections.front(); E; E = E->next()) { - NodePath fromnp(E->get().from); + for (Connection &E : connections) { + NodePath fromnp(E.from); Node *from = get_node(fromnp); if (!from) { @@ -1013,7 +1013,7 @@ void GraphEdit::_minimap_draw() { continue; } - NodePath tonp(E->get().to); + NodePath tonp(E.to); Node *to = get_node(tonp); if (!to) { continue; @@ -1023,16 +1023,16 @@ void GraphEdit::_minimap_draw() { continue; } - Vector2 from_slot_position = gfrom->get_position_offset() * zoom + gfrom->get_connection_output_position(E->get().from_port); + Vector2 from_slot_position = gfrom->get_position_offset() * zoom + gfrom->get_connection_output_position(E.from_port); Vector2 from_position = minimap->_convert_from_graph_position(from_slot_position - graph_offset) + minimap_offset; - Color from_color = gfrom->get_connection_output_color(E->get().from_port); - Vector2 to_slot_position = gto->get_position_offset() * zoom + gto->get_connection_input_position(E->get().to_port); + Color from_color = gfrom->get_connection_output_color(E.from_port); + Vector2 to_slot_position = gto->get_position_offset() * zoom + gto->get_connection_input_position(E.to_port); Vector2 to_position = minimap->_convert_from_graph_position(to_slot_position - graph_offset) + minimap_offset; - Color to_color = gto->get_connection_input_color(E->get().to_port); + Color to_color = gto->get_connection_input_color(E.to_port); - if (E->get().activity > 0) { - from_color = from_color.lerp(activity_color, E->get().activity); - to_color = to_color.lerp(activity_color, E->get().activity); + if (E.activity > 0) { + from_color = from_color.lerp(activity_color, E.activity); + to_color = to_color.lerp(activity_color, E.activity); } _draw_cos_line(minimap, from_position, to_position, from_color, to_color, 1.0, 0.5); } @@ -1360,15 +1360,15 @@ void GraphEdit::_gui_input(const Ref &p_ev) { } void GraphEdit::set_connection_activity(const StringName &p_from, int p_from_port, const StringName &p_to, int p_to_port, float p_activity) { - for (List::Element *E = connections.front(); E; E = E->next()) { - if (E->get().from == p_from && E->get().from_port == p_from_port && E->get().to == p_to && E->get().to_port == p_to_port) { - if (Math::is_equal_approx(E->get().activity, p_activity)) { + for (Connection &E : connections) { + if (E.from == p_from && E.from_port == p_from_port && E.to == p_to && E.to_port == p_to_port) { + if (Math::is_equal_approx(E.activity, p_activity)) { //update only if changed top_layer->update(); minimap->update(); connections_layer->update(); } - E->get().activity = p_activity; + E.activity = p_activity; return; } } @@ -1500,12 +1500,12 @@ Array GraphEdit::_get_connection_list() const { List conns; get_connection_list(&conns); Array arr; - for (List::Element *E = conns.front(); E; E = E->next()) { + for (Connection &E : conns) { Dictionary d; - d["from"] = E->get().from; - d["from_port"] = E->get().from_port; - d["to"] = E->get().to; - d["to_port"] = E->get().to_port; + d["from"] = E.from; + d["from_port"] = E.from_port; + d["to"] = E.to; + d["to_port"] = E.to_port; arr.push_back(d); } return arr; diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp index 14c86c0d27..ae3db4a983 100644 --- a/scene/gui/popup_menu.cpp +++ b/scene/gui/popup_menu.cpp @@ -397,8 +397,8 @@ void PopupMenu::_gui_input(const Ref &p_event) { Ref m = p_event; if (m.is_valid()) { - for (List::Element *E = autohide_areas.front(); E; E = E->next()) { - if (!Rect2(Point2(), get_size()).has_point(m->get_position()) && E->get().has_point(m->get_position())) { + for (Rect2 &E : autohide_areas) { + if (!Rect2(Point2(), get_size()).has_point(m->get_position()) && E.has_point(m->get_position())) { _close_pressed(); return; } @@ -751,8 +751,8 @@ void PopupMenu::_notification(int p_what) { Point2 mouse_pos = DisplayServer::get_singleton()->mouse_get_position(); mouse_pos -= get_position(); - for (List::Element *E = autohide_areas.front(); E; E = E->next()) { - if (!Rect2(Point2(), get_size()).has_point(mouse_pos) && E->get().has_point(mouse_pos)) { + for (Rect2 &E : autohide_areas) { + if (!Rect2(Point2(), get_size()).has_point(mouse_pos) && E.has_point(mouse_pos)) { _close_pressed(); return; } diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index 99395aae30..3925e0c38e 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -238,9 +238,9 @@ void RichTextLabel::_resize_line(ItemFrame *p_frame, int p_line, const Ref } int idx = 0; - for (List::Element *E = table->subitems.front(); E; E = E->next()) { - ERR_CONTINUE(E->get()->type != ITEM_FRAME); // Children should all be frames. - ItemFrame *frame = static_cast(E->get()); + for (Item *E : table->subitems) { + ERR_CONTINUE(E->type != ITEM_FRAME); // Children should all be frames. + ItemFrame *frame = static_cast(E); for (int i = 0; i < frame->lines.size(); i++) { _resize_line(frame, i, p_base_font, p_base_font_size, 1); } @@ -316,9 +316,9 @@ void RichTextLabel::_resize_line(ItemFrame *p_frame, int p_line, const Ref Vector2 offset; float row_height = 0.0; - for (List::Element *E = table->subitems.front(); E; E = E->next()) { - ERR_CONTINUE(E->get()->type != ITEM_FRAME); // Children should all be frames. - ItemFrame *frame = static_cast(E->get()); + for (Item *E : table->subitems) { + ERR_CONTINUE(E->type != ITEM_FRAME); // Children should all be frames. + ItemFrame *frame = static_cast(E); int column = idx % col_count; @@ -472,9 +472,9 @@ void RichTextLabel::_shape_line(ItemFrame *p_frame, int p_line, const Ref const int available_width = p_width - hseparation * (col_count - 1); int idx = 0; - for (List::Element *E = table->subitems.front(); E; E = E->next()) { - ERR_CONTINUE(E->get()->type != ITEM_FRAME); // Children should all be frames. - ItemFrame *frame = static_cast(E->get()); + for (Item *E : table->subitems) { + ERR_CONTINUE(E->type != ITEM_FRAME); // Children should all be frames. + ItemFrame *frame = static_cast(E); int column = idx % col_count; for (int i = 0; i < frame->lines.size(); i++) { @@ -556,7 +556,7 @@ void RichTextLabel::_shape_line(ItemFrame *p_frame, int p_line, const Ref Vector2 offset; float row_height = 0.0; - for (List::Element *E = table->subitems.front(); E; E = E->next()) { + for (const List::Element *E = table->subitems.front(); E; E = E->next()) { ERR_CONTINUE(E->get()->type != ITEM_FRAME); // Children should all be frames. ItemFrame *frame = static_cast(E->get()); @@ -783,8 +783,8 @@ int RichTextLabel::_draw_line(ItemFrame *p_frame, int p_line, const Vector2 &p_o int row_count = table->rows.size(); int idx = 0; - for (List::Element *E = table->subitems.front(); E; E = E->next()) { - ItemFrame *frame = static_cast(E->get()); + for (Item *E : table->subitems) { + ItemFrame *frame = static_cast(E); int col = idx % col_count; int row = idx / col_count; @@ -1203,8 +1203,8 @@ float RichTextLabel::_find_click_in_line(ItemFrame *p_frame, int p_line, const V int col_count = table->columns.size(); int row_count = table->rows.size(); - for (List::Element *E = table->subitems.front(); E; E = E->next()) { - ItemFrame *frame = static_cast(E->get()); + for (Item *E : table->subitems) { + ItemFrame *frame = static_cast(E); int col = idx % col_count; int row = idx / col_count; @@ -2080,8 +2080,8 @@ bool RichTextLabel::_find_layout_subitem(Item *from, Item *to) { return true; } - for (List::Element *E = from->subitems.front(); E; E = E->next()) { - bool layout = _find_layout_subitem(E->get(), to); + for (Item *E : from->subitems) { + bool layout = _find_layout_subitem(E, to); if (layout) { return true; @@ -3448,8 +3448,8 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) { } Vector fx_items; - for (List::Element *E = main->subitems.front(); E; E = E->next()) { - Item *subitem = static_cast(E->get()); + for (Item *E : main->subitems) { + Item *subitem = static_cast(E); _fetch_item_fx_stack(subitem, fx_items); if (fx_items.size()) { @@ -3719,9 +3719,9 @@ String RichTextLabel::_get_line_text(ItemFrame *p_frame, int p_line, Selection p ItemTable *table = static_cast(it); int idx = 0; int col_count = table->columns.size(); - for (List::Element *E = table->subitems.front(); E; E = E->next()) { - ERR_CONTINUE(E->get()->type != ITEM_FRAME); // Children should all be frames. - ItemFrame *frame = static_cast(E->get()); + for (Item *E : table->subitems) { + ERR_CONTINUE(E->type != ITEM_FRAME); // Children should all be frames. + ItemFrame *frame = static_cast(E); int column = idx % col_count; for (int i = 0; i < frame->lines.size(); i++) { diff --git a/scene/main/canvas_item.cpp b/scene/main/canvas_item.cpp index 5a12480577..0a76351885 100644 --- a/scene/main/canvas_item.cpp +++ b/scene/main/canvas_item.cpp @@ -956,8 +956,7 @@ void CanvasItem::_notify_transform(CanvasItem *p_node) { } } - for (List::Element *E = p_node->children_items.front(); E; E = E->next()) { - CanvasItem *ci = E->get(); + for (CanvasItem *ci : p_node->children_items) { if (ci->top_level) { continue; } @@ -1334,9 +1333,9 @@ void CanvasItem::_update_texture_filter_changed(bool p_propagate) { update(); if (p_propagate) { - for (List::Element *E = children_items.front(); E; E = E->next()) { - if (!E->get()->top_level && E->get()->texture_filter == TEXTURE_FILTER_PARENT_NODE) { - E->get()->_update_texture_filter_changed(true); + for (CanvasItem *E : children_items) { + if (!E->top_level && E->texture_filter == TEXTURE_FILTER_PARENT_NODE) { + E->_update_texture_filter_changed(true); } } } @@ -1374,9 +1373,9 @@ void CanvasItem::_update_texture_repeat_changed(bool p_propagate) { RS::get_singleton()->canvas_item_set_default_texture_repeat(get_canvas_item(), texture_repeat_cache); update(); if (p_propagate) { - for (List::Element *E = children_items.front(); E; E = E->next()) { - if (!E->get()->top_level && E->get()->texture_repeat == TEXTURE_REPEAT_PARENT_NODE) { - E->get()->_update_texture_repeat_changed(true); + for (CanvasItem *E : children_items) { + if (!E->top_level && E->texture_repeat == TEXTURE_REPEAT_PARENT_NODE) { + E->_update_texture_repeat_changed(true); } } } diff --git a/scene/main/http_request.cpp b/scene/main/http_request.cpp index f649380afa..588d4b67d5 100644 --- a/scene/main/http_request.cpp +++ b/scene/main/http_request.cpp @@ -220,8 +220,8 @@ bool HTTPRequest::_handle_response(bool *ret_value) { client->get_response_headers(&rheaders); response_headers.resize(0); downloaded.set(0); - for (List::Element *E = rheaders.front(); E; E = E->next()) { - response_headers.push_back(E->get()); + for (String &E : rheaders) { + response_headers.push_back(E); } if (response_code == 301 || response_code == 302) { @@ -235,9 +235,9 @@ bool HTTPRequest::_handle_response(bool *ret_value) { String new_request; - for (List::Element *E = rheaders.front(); E; E = E->next()) { - if (E->get().findn("Location: ") != -1) { - new_request = E->get().substr(9, E->get().length()).strip_edges(); + for (String &E : rheaders) { + if (E.findn("Location: ") != -1) { + new_request = E.substr(9, E.length()).strip_edges(); } } diff --git a/scene/main/instance_placeholder.cpp b/scene/main/instance_placeholder.cpp index 89dac5f5a8..b7c6723cfc 100644 --- a/scene/main/instance_placeholder.cpp +++ b/scene/main/instance_placeholder.cpp @@ -42,9 +42,9 @@ bool InstancePlaceholder::_set(const StringName &p_name, const Variant &p_value) } bool InstancePlaceholder::_get(const StringName &p_name, Variant &r_ret) const { - for (const List::Element *E = stored_values.front(); E; E = E->next()) { - if (E->get().name == p_name) { - r_ret = E->get().value; + for (const PropSet &E : stored_values) { + if (E.name == p_name) { + r_ret = E.value; return true; } } @@ -52,10 +52,10 @@ bool InstancePlaceholder::_get(const StringName &p_name, Variant &r_ret) const { } void InstancePlaceholder::_get_property_list(List *p_list) const { - for (const List::Element *E = stored_values.front(); E; E = E->next()) { + for (const PropSet &E : stored_values) { PropertyInfo pi; - pi.name = E->get().name; - pi.type = E->get().value.get_type(); + pi.name = E.name; + pi.type = E.value.get_type(); pi.usage = PROPERTY_USAGE_STORAGE; p_list->push_back(pi); @@ -95,8 +95,8 @@ Node *InstancePlaceholder::create_instance(bool p_replace, const Refset_name(get_name()); int pos = get_index(); - for (List::Element *E = stored_values.front(); E; E = E->next()) { - scene->set(E->get().name, E->get().value); + for (PropSet &E : stored_values) { + scene->set(E.name, E.value); } if (p_replace) { @@ -114,10 +114,10 @@ Dictionary InstancePlaceholder::get_stored_values(bool p_with_order) { Dictionary ret; PackedStringArray order; - for (List::Element *E = stored_values.front(); E; E = E->next()) { - ret[E->get().name] = E->get().value; + for (PropSet &E : stored_values) { + ret[E.name] = E.value; if (p_with_order) { - order.push_back(E->get().name); + order.push_back(E.name); } }; diff --git a/scene/main/node.cpp b/scene/main/node.cpp index 0d060240de..4b496d4761 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -1597,8 +1597,8 @@ Array Node::_get_groups() const { Array groups; List gi; get_groups(&gi); - for (List::Element *E = gi.front(); E; E = E->next()) { - groups.push_back(E->get().name); + for (GroupInfo &E : gi) { + groups.push_back(E.name); } return groups; @@ -1947,18 +1947,18 @@ Node *Node::_duplicate(int p_flags, Map *r_duplimap) const List plist; N->get()->get_property_list(&plist); - for (List::Element *E = plist.front(); E; E = E->next()) { - if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) { + for (PropertyInfo &E : plist) { + if (!(E.usage & PROPERTY_USAGE_STORAGE)) { continue; } - String name = E->get().name; + String name = E.name; if (name == script_property_name) { continue; } Variant value = N->get()->get(name).duplicate(true); - if (E->get().usage & PROPERTY_USAGE_DO_NOT_SHARE_ON_DUPLICATE) { + if (E.usage & PROPERTY_USAGE_DO_NOT_SHARE_ON_DUPLICATE) { Resource *res = Object::cast_to(value); if (res) { // Duplicate only if it's a resource current_node->set(name, res->duplicate()); @@ -1983,14 +1983,14 @@ Node *Node::_duplicate(int p_flags, Map *r_duplimap) const if (p_flags & DUPLICATE_GROUPS) { List gi; get_groups(&gi); - for (List::Element *E = gi.front(); E; E = E->next()) { + for (GroupInfo &E : gi) { #ifdef TOOLS_ENABLED - if ((p_flags & DUPLICATE_FROM_EDITOR) && !E->get().persistent) { + if ((p_flags & DUPLICATE_FROM_EDITOR) && !E.persistent) { continue; } #endif - node->add_to_group(E->get().name, E->get().persistent); + node->add_to_group(E.name, E.persistent); } } @@ -2014,21 +2014,21 @@ Node *Node::_duplicate(int p_flags, Map *r_duplimap) const } } - for (List::Element *E = hidden_roots.front(); E; E = E->next()) { - Node *parent = node->get_node(get_path_to(E->get()->data.parent)); + for (const Node *&E : hidden_roots) { + Node *parent = node->get_node(get_path_to(E->data.parent)); if (!parent) { memdelete(node); return nullptr; } - Node *dup = E->get()->_duplicate(p_flags, r_duplimap); + Node *dup = E->_duplicate(p_flags, r_duplimap); if (!dup) { memdelete(node); return nullptr; } parent->add_child(dup); - int pos = E->get()->get_index(); + int pos = E->get_index(); if (pos < parent->get_child_count() - 1) { parent->move_child(dup, pos); @@ -2073,17 +2073,17 @@ void Node::remap_node_resources(Node *p_node, const Map &p_resource_re List props; p_node->get_property_list(&props); - for (List::Element *E = props.front(); E; E = E->next()) { - if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) { + for (PropertyInfo &E : props) { + if (!(E.usage & PROPERTY_USAGE_STORAGE)) { continue; } - Variant v = p_node->get(E->get().name); + Variant v = p_node->get(E.name); if (v.is_ref()) { RES res = v; if (res.is_valid()) { if (p_resource_remap.has(res)) { - p_node->set(E->get().name, p_resource_remap[res]); + p_node->set(E.name, p_resource_remap[res]); remap_nested_resources(res, p_resource_remap); } } @@ -2099,17 +2099,17 @@ void Node::remap_nested_resources(RES p_resource, const Map &p_resourc List props; p_resource->get_property_list(&props); - for (List::Element *E = props.front(); E; E = E->next()) { - if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) { + for (PropertyInfo &E : props) { + if (!(E.usage & PROPERTY_USAGE_STORAGE)) { continue; } - Variant v = p_resource->get(E->get().name); + Variant v = p_resource->get(E.name); if (v.is_ref()) { RES res = v; if (res.is_valid()) { if (p_resource_remap.has(res)) { - p_resource->set(E->get().name, p_resource_remap[res]); + p_resource->set(E.name, p_resource_remap[res]); remap_nested_resources(res, p_resource_remap); } } @@ -2135,13 +2135,13 @@ void Node::_duplicate_signals(const Node *p_original, Node *p_copy) const { List conns; n->get_all_signal_connections(&conns); - for (List::Element *E = conns.front(); E; E = E->next()) { - if (E->get().flags & CONNECT_PERSIST) { + for (Connection &E : conns) { + if (E.flags & CONNECT_PERSIST) { //user connected NodePath p = p_original->get_path_to(n); Node *copy = p_copy->get_node(p); - Node *target = Object::cast_to(E->get().callable.get_object()); + Node *target = Object::cast_to(E.callable.get_object()); if (!target) { continue; } @@ -2158,9 +2158,9 @@ void Node::_duplicate_signals(const Node *p_original, Node *p_copy) const { } if (copy && copytarget) { - const Callable copy_callable = Callable(copytarget, E->get().callable.get_method()); - if (!copy->is_connected(E->get().signal.get_name(), copy_callable)) { - copy->connect(E->get().signal.get_name(), copy_callable, E->get().binds, E->get().flags); + const Callable copy_callable = Callable(copytarget, E.callable.get_method()); + if (!copy->is_connected(E.signal.get_name(), copy_callable)) { + copy->connect(E.signal.get_name(), copy_callable, E.binds, E.flags); } } } @@ -2194,8 +2194,8 @@ void Node::replace_by(Node *p_node, bool p_keep_groups) { List groups; get_groups(&groups); - for (List::Element *E = groups.front(); E; E = E->next()) { - p_node->add_to_group(E->get().name, E->get().persistent); + for (GroupInfo &E : groups) { + p_node->add_to_group(E.name, E.persistent); } } @@ -2241,9 +2241,7 @@ void Node::_replace_connections_target(Node *p_new_target) { List cl; get_signals_connected_to_this(&cl); - for (List::Element *E = cl.front(); E; E = E->next()) { - Connection &c = E->get(); - + for (Connection &c : cl) { if (c.flags & CONNECT_PERSIST) { c.signal.get_object()->disconnect(c.signal.get_name(), Callable(this, c.callable.get_method())); bool valid = p_new_target->has_method(c.callable.get_method()) || Ref