From a669c2a1d630e784d0b6112dcfbac25ca4eff3a1 Mon Sep 17 00:00:00 2001 From: Yyf2333 <2514537033@qq.com> Date: Mon, 3 Feb 2025 14:16:27 +0800 Subject: [PATCH] Using iterator pattern instead of List::Element *. --- core/config/project_settings.cpp | 4 +- core/core_bind.cpp | 8 +-- core/extension/extension_api_dump.cpp | 8 +-- core/math/geometry_2d.cpp | 4 +- core/object/object.cpp | 4 +- core/string/translation_po.cpp | 7 +- core/variant/variant.cpp | 6 +- drivers/gles3/storage/texture_storage.cpp | 4 +- editor/animation_track_editor.cpp | 4 +- editor/connections_dialog.cpp | 8 +-- editor/create_dialog.cpp | 6 +- .../debug_adapter/debug_adapter_parser.cpp | 4 +- .../debug_adapter/debug_adapter_protocol.cpp | 68 +++++++++---------- editor/doc_tools.cpp | 13 ++-- editor/editor_data.cpp | 3 +- editor/editor_file_system.cpp | 8 +-- editor/editor_inspector.cpp | 4 +- editor/import/3d/editor_import_collada.cpp | 8 +-- .../import/dynamic_font_import_settings.cpp | 19 +++--- editor/import/resource_importer_bmfont.cpp | 6 +- .../animation_state_machine_editor.cpp | 14 ++-- .../tiles/tile_set_atlas_source_editor.cpp | 8 +-- .../plugins/version_control_editor_plugin.cpp | 6 +- .../plugins/visual_shader_editor_plugin.cpp | 4 +- editor/project_manager.cpp | 4 +- modules/enet/enet_connection.cpp | 4 +- modules/gdscript/gdscript_editor.cpp | 4 +- .../language_server/gdscript_workspace.cpp | 4 +- modules/gdscript/language_server/godot_lsp.h | 8 +-- .../navigation/2d/nav_mesh_generator_2d.cpp | 4 +- scene/animation/animation_player.cpp | 3 +- scene/main/node.cpp | 6 +- scene/resources/2d/navigation_polygon.cpp | 4 +- scene/resources/3d/primitive_meshes.cpp | 7 +- scene/resources/material.cpp | 36 +++++----- scene/resources/resource_format_text.cpp | 18 ++--- .../storage_rd/texture_storage.cpp | 4 +- 37 files changed, 155 insertions(+), 179 deletions(-) diff --git a/core/config/project_settings.cpp b/core/config/project_settings.cpp index fdcd4f9b6064..316a2a2d1d2a 100644 --- a/core/config/project_settings.cpp +++ b/core/config/project_settings.cpp @@ -1452,8 +1452,8 @@ void ProjectSettings::_add_builtin_input_map() { Array events; // Convert list of input events into array - for (List>::Element *I = E.value.front(); I; I = I->next()) { - events.push_back(I->get()); + for (const Ref &I : E.value) { + events.push_back(I); } Dictionary action; diff --git a/core/core_bind.cpp b/core/core_bind.cpp index acd589783ece..4c22fc6b28f9 100644 --- a/core/core_bind.cpp +++ b/core/core_bind.cpp @@ -466,8 +466,8 @@ bool OS::is_restart_on_exit_set() const { Vector OS::get_restart_on_exit_arguments() const { List args = ::OS::get_singleton()->get_restart_on_exit_arguments(); Vector args_vector; - for (List::Element *E = args.front(); E; E = E->next()) { - args_vector.push_back(E->get()); + for (const String &E : args) { + args_vector.push_back(E); } return args_vector; @@ -1876,8 +1876,8 @@ Vector Engine::get_singleton_list() const { List<::Engine::Singleton> singletons; ::Engine::get_singleton()->get_singletons(&singletons); Vector ret; - for (List<::Engine::Singleton>::Element *E = singletons.front(); E; E = E->next()) { - ret.push_back(E->get().name); + for (const ::Engine::Singleton &E : singletons) { + ret.push_back(E.name); } return ret; } diff --git a/core/extension/extension_api_dump.cpp b/core/extension/extension_api_dump.cpp index 52f1672a0769..ff2dfa03aacf 100644 --- a/core/extension/extension_api_dump.cpp +++ b/core/extension/extension_api_dump.cpp @@ -970,14 +970,14 @@ Dictionary GDExtensionAPIDump::generate_extension_api(bool p_include_docs) { Array values; List enum_constant_list; ClassDB::get_enum_constants(class_name, F, &enum_constant_list, true); - for (List::Element *G = enum_constant_list.front(); G; G = G->next()) { + for (const StringName &G : enum_constant_list) { Dictionary d3; - d3["name"] = String(G->get()); - d3["value"] = ClassDB::get_integer_constant(class_name, G->get()); + d3["name"] = String(G); + d3["value"] = ClassDB::get_integer_constant(class_name, G); if (p_include_docs) { for (const DocData::ConstantDoc &constant_doc : class_doc->constants) { - if (constant_doc.name == G->get()) { + if (constant_doc.name == G) { d3["description"] = fix_doc_description(constant_doc.description); break; } diff --git a/core/math/geometry_2d.cpp b/core/math/geometry_2d.cpp index 376d5d0b43be..618af9696902 100644 --- a/core/math/geometry_2d.cpp +++ b/core/math/geometry_2d.cpp @@ -57,9 +57,7 @@ Vector> Geometry2D::decompose_polygon_in_convex(const Vector::Element *I = out_poly.front(); I; I = I->next()) { - TPPLPoly &tp = I->get(); - + for (TPPLPoly &tp : out_poly) { decomp.write[idx].resize(tp.GetNumPoints()); for (int64_t i = 0; i < tp.GetNumPoints(); i++) { diff --git a/core/object/object.cpp b/core/object/object.cpp index 8df107ec696b..248f5c13e950 100644 --- a/core/object/object.cpp +++ b/core/object/object.cpp @@ -1080,8 +1080,8 @@ TypedArray Object::_get_method_list_bind() const { get_method_list(&ml); TypedArray ret; - for (List::Element *E = ml.front(); E; E = E->next()) { - Dictionary d = E->get(); + for (const MethodInfo &E : ml) { + Dictionary d = E; //va.push_back(d); ret.push_back(d); } diff --git a/core/string/translation_po.cpp b/core/string/translation_po.cpp index 7eb8a2afebac..a5ebeab857c3 100644 --- a/core/string/translation_po.cpp +++ b/core/string/translation_po.cpp @@ -53,8 +53,7 @@ void TranslationPO::print_translation_map() { List id_l; inner_map.get_key_list(&id_l); - for (List::Element *E2 = id_l.front(); E2; E2 = E2->next()) { - StringName id = E2->get(); + for (const StringName &id : id_l) { file->store_line("msgid: " + String::utf8(String(id).utf8())); for (int i = 0; i < inner_map[id].size(); i++) { file->store_line("msgstr[" + String::num_int64(i) + "]: " + String::utf8(String(inner_map[id][i]).utf8())); @@ -94,8 +93,8 @@ void TranslationPO::_set_messages(const Dictionary &p_messages) { HashMap> temp_map; List id_l; id_str_map.get_key_list(&id_l); - for (List::Element *E2 = id_l.front(); E2; E2 = E2->next()) { - StringName id = E2->get(); + for (const Variant &E2 : id_l) { + StringName id = E2; temp_map[id] = id_str_map[id]; } diff --git a/core/variant/variant.cpp b/core/variant/variant.cpp index f16375dbf053..dbddc7f027bf 100644 --- a/core/variant/variant.cpp +++ b/core/variant/variant.cpp @@ -1659,10 +1659,10 @@ String Variant::stringify(int recursion_count) const { Vector<_VariantStrPair> pairs; - for (List::Element *E = keys.front(); E; E = E->next()) { + for (const Variant &E : keys) { _VariantStrPair sp; - sp.key = stringify_variant_clean(E->get(), recursion_count); - sp.value = stringify_variant_clean(d[E->get()], recursion_count); + sp.key = stringify_variant_clean(E, recursion_count); + sp.value = stringify_variant_clean(d[E], recursion_count); pairs.push_back(sp); } diff --git a/drivers/gles3/storage/texture_storage.cpp b/drivers/gles3/storage/texture_storage.cpp index de5938176857..4c64484d0f37 100644 --- a/drivers/gles3/storage/texture_storage.cpp +++ b/drivers/gles3/storage/texture_storage.cpp @@ -1468,8 +1468,8 @@ void TextureStorage::texture_debug_usage(List *r_info) { List textures; texture_owner.get_owned_list(&textures); - for (List::Element *E = textures.front(); E; E = E->next()) { - Texture *t = texture_owner.get_or_null(E->get()); + for (const RID &E : textures) { + Texture *t = texture_owner.get_or_null(E); if (!t) { continue; } diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp index dbb23d6f17a6..100b15a46e6a 100644 --- a/editor/animation_track_editor.cpp +++ b/editor/animation_track_editor.cpp @@ -1251,12 +1251,12 @@ void AnimationMultiTrackKeyEdit::_get_property_list(List *p_list) if (ap) { List anims; ap->get_animation_list(&anims); - for (List::Element *G = anims.front(); G; G = G->next()) { + for (const StringName &G : anims) { if (!animations.is_empty()) { animations += ","; } - animations += String(G->get()); + animations += String(G); } } } diff --git a/editor/connections_dialog.cpp b/editor/connections_dialog.cpp index 429467d3403c..8cc411162ab4 100644 --- a/editor/connections_dialog.cpp +++ b/editor/connections_dialog.cpp @@ -1459,11 +1459,11 @@ void ConnectionsDock::update_tree() { List base_signals; base->get_script_signal_list(&base_signals); HashSet base_signal_names; - for (List::Element *F = base_signals.front(); F; F = F->next()) { - base_signal_names.insert(F->get().name); + for (const MethodInfo &F : base_signals) { + base_signal_names.insert(F.name); } - for (List::Element *F = class_signals.front(); F; F = F->next()) { - if (base_signal_names.has(F->get().name)) { + for (const MethodInfo &F : class_signals) { + if (base_signal_names.has(F.name)) { class_signals.erase(F); } } diff --git a/editor/create_dialog.cpp b/editor/create_dialog.cpp index 7f1670bcb648..c5b2b380351f 100644 --- a/editor/create_dialog.cpp +++ b/editor/create_dialog.cpp @@ -83,8 +83,7 @@ void CreateDialog::_fill_type_list() { EditorData &ed = EditorNode::get_editor_data(); - for (List::Element *I = complete_type_list.front(); I; I = I->next()) { - StringName type = I->get(); + for (const StringName &type : complete_type_list) { if (!_should_hide_type(type)) { type_list.push_back(type); @@ -216,8 +215,7 @@ void CreateDialog::_update_search() { float highest_score = 0.0f; StringName best_match; - for (List::Element *I = type_list.front(); I; I = I->next()) { - StringName candidate = I->get(); + for (const StringName &candidate : type_list) { if (empty_search || search_text.is_subsequence_ofn(candidate)) { _add_type(candidate, ClassDB::class_exists(candidate) ? TypeCategory::CPP_TYPE : TypeCategory::OTHER_TYPE); diff --git a/editor/debugger/debug_adapter/debug_adapter_parser.cpp b/editor/debugger/debug_adapter/debug_adapter_parser.cpp index 30abbbce8eb5..91a9bd75beb8 100644 --- a/editor/debugger/debug_adapter/debug_adapter_parser.cpp +++ b/editor/debugger/debug_adapter/debug_adapter_parser.cpp @@ -144,9 +144,7 @@ Dictionary DebugAdapterParser::req_initialize(const Dictionary &p_params) const // Send all current breakpoints List breakpoints; ScriptEditor::get_singleton()->get_breakpoints(&breakpoints); - for (List::Element *E = breakpoints.front(); E; E = E->next()) { - String breakpoint = E->get(); - + for (const String &breakpoint : breakpoints) { String path = breakpoint.left(breakpoint.find_char(':', 6)); // Skip initial part of path, aka "res://" int line = breakpoint.substr(path.size()).to_int(); diff --git a/editor/debugger/debug_adapter/debug_adapter_protocol.cpp b/editor/debugger/debug_adapter/debug_adapter_protocol.cpp index ba4c078d7ed5..15d3d9977381 100644 --- a/editor/debugger/debug_adapter/debug_adapter_protocol.cpp +++ b/editor/debugger/debug_adapter/debug_adapter_protocol.cpp @@ -904,66 +904,66 @@ void DebugAdapterProtocol::notify_process() { String launch_mode = _current_peer->attached ? "attach" : "launch"; Dictionary event = parser->ev_process(launch_mode); - for (List>::Element *E = clients.front(); E; E = E->next()) { - E->get()->res_queue.push_back(event); + for (const Ref &E : clients) { + E->res_queue.push_back(event); } } void DebugAdapterProtocol::notify_terminated() { Dictionary event = parser->ev_terminated(); - for (List>::Element *E = clients.front(); E; E = E->next()) { - if ((_current_request == "launch" || _current_request == "restart") && _current_peer == E->get()) { + for (const Ref &E : clients) { + if ((_current_request == "launch" || _current_request == "restart") && _current_peer == E) { continue; } - E->get()->res_queue.push_back(event); + E->res_queue.push_back(event); } } void DebugAdapterProtocol::notify_exited(const int &p_exitcode) { Dictionary event = parser->ev_exited(p_exitcode); - for (List>::Element *E = clients.front(); E; E = E->next()) { - if ((_current_request == "launch" || _current_request == "restart") && _current_peer == E->get()) { + for (const Ref &E : clients) { + if ((_current_request == "launch" || _current_request == "restart") && _current_peer == E) { continue; } - E->get()->res_queue.push_back(event); + E->res_queue.push_back(event); } } void DebugAdapterProtocol::notify_stopped_paused() { Dictionary event = parser->ev_stopped_paused(); - for (List>::Element *E = clients.front(); E; E = E->next()) { - E->get()->res_queue.push_back(event); + for (const Ref &E : clients) { + E->res_queue.push_back(event); } } void DebugAdapterProtocol::notify_stopped_exception(const String &p_error) { Dictionary event = parser->ev_stopped_exception(p_error); - for (List>::Element *E = clients.front(); E; E = E->next()) { - E->get()->res_queue.push_back(event); + for (const Ref &E : clients) { + E->res_queue.push_back(event); } } void DebugAdapterProtocol::notify_stopped_breakpoint(const int &p_id) { Dictionary event = parser->ev_stopped_breakpoint(p_id); - for (List>::Element *E = clients.front(); E; E = E->next()) { - E->get()->res_queue.push_back(event); + for (const Ref &E : clients) { + E->res_queue.push_back(event); } } void DebugAdapterProtocol::notify_stopped_step() { Dictionary event = parser->ev_stopped_step(); - for (List>::Element *E = clients.front(); E; E = E->next()) { - E->get()->res_queue.push_back(event); + for (const Ref &E : clients) { + E->res_queue.push_back(event); } } void DebugAdapterProtocol::notify_continued() { Dictionary event = parser->ev_continued(); - for (List>::Element *E = clients.front(); E; E = E->next()) { - if (_current_request == "continue" && E->get() == _current_peer) { + for (const Ref &E : clients) { + if (_current_request == "continue" && E == _current_peer) { continue; } - E->get()->res_queue.push_back(event); + E->res_queue.push_back(event); } reset_stack_info(); @@ -971,15 +971,14 @@ void DebugAdapterProtocol::notify_continued() { void DebugAdapterProtocol::notify_output(const String &p_message, RemoteDebugger::MessageType p_type) { Dictionary event = parser->ev_output(p_message, p_type); - for (List>::Element *E = clients.front(); E; E = E->next()) { - E->get()->res_queue.push_back(event); + for (const Ref &E : clients) { + E->res_queue.push_back(event); } } void DebugAdapterProtocol::notify_custom_data(const String &p_msg, const Array &p_data) { Dictionary event = parser->ev_custom_data(p_msg, p_data); - for (List>::Element *E = clients.front(); E; E = E->next()) { - Ref peer = E->get(); + for (const Ref &peer : clients) { if (peer->supportsCustomData) { peer->res_queue.push_back(event); } @@ -988,11 +987,11 @@ void DebugAdapterProtocol::notify_custom_data(const String &p_msg, const Array & void DebugAdapterProtocol::notify_breakpoint(const DAP::Breakpoint &p_breakpoint, const bool &p_enabled) { Dictionary event = parser->ev_breakpoint(p_breakpoint, p_enabled); - for (List>::Element *E = clients.front(); E; E = E->next()) { - if (_current_request == "setBreakpoints" && E->get() == _current_peer) { + for (const Ref &E : clients) { + if (_current_request == "setBreakpoints" && E == _current_peer) { continue; } - E->get()->res_queue.push_back(event); + E->res_queue.push_back(event); } } @@ -1011,8 +1010,7 @@ Array DebugAdapterProtocol::update_breakpoints(const String &p_path, const Array } // Remove breakpoints - for (List::Element *E = breakpoint_list.front(); E; E = E->next()) { - DAP::Breakpoint b = E->get(); + for (const DAP::Breakpoint &b : breakpoint_list) { if (b.source.path == p_path && !p_lines.has(b.line)) { EditorDebuggerNode::get_singleton()->get_default_debugger()->_set_breakpoint(p_path, b.line, false); } @@ -1130,8 +1128,7 @@ void DebugAdapterProtocol::on_debug_stack_frame_vars(const int &p_size) { frame.id = _current_frame; ERR_FAIL_COND(!stackframe_list.has(frame)); List scope_ids = stackframe_list.find(frame)->value; - for (List::Element *E = scope_ids.front(); E; E = E->next()) { - int var_id = E->get(); + for (const int var_id : scope_ids) { if (variable_list.has(var_id)) { variable_list.find(var_id)->value.clear(); } else { @@ -1192,8 +1189,7 @@ void DebugAdapterProtocol::poll() { on_client_connected(); } List> to_delete; - for (List>::Element *E = clients.front(); E; E = E->next()) { - Ref peer = E->get(); + for (const Ref &peer : clients) { peer->connection->poll(); StreamPeerTCP::Status status = peer->connection->get_status(); if (status == StreamPeerTCP::STATUS_NONE || status == StreamPeerTCP::STATUS_ERROR) { @@ -1211,8 +1207,8 @@ void DebugAdapterProtocol::poll() { } } - for (List>::Element *E = to_delete.front(); E; E = E->next()) { - on_client_disconnected(E->get()); + for (const Ref &E : to_delete) { + on_client_disconnected(E); } to_delete.clear(); } @@ -1225,8 +1221,8 @@ Error DebugAdapterProtocol::start(int p_port, const IPAddress &p_bind_ip) { } void DebugAdapterProtocol::stop() { - for (List>::Element *E = clients.front(); E; E = E->next()) { - E->get()->connection->disconnect_from_host(); + for (const Ref &E : clients) { + E->connection->disconnect_from_host(); } clients.clear(); diff --git a/editor/doc_tools.cpp b/editor/doc_tools.cpp index 02babe6a068d..83c227821856 100644 --- a/editor/doc_tools.cpp +++ b/editor/doc_tools.cpp @@ -385,9 +385,9 @@ static Variant get_documentation_default_value(const StringName &p_class_name, c // Cannot get default value of classes that can't be instantiated List inheriting_classes; ClassDB::get_direct_inheriters_from_class(p_class_name, &inheriting_classes); - for (List::Element *E2 = inheriting_classes.front(); E2; E2 = E2->next()) { - if (ClassDB::can_instantiate(E2->get())) { - default_value = ClassDB::class_get_default_property_value(E2->get(), p_property_name, &r_default_value_valid); + for (const StringName &E2 : inheriting_classes) { + if (ClassDB::can_instantiate(E2)) { + default_value = ClassDB::class_get_default_property_value(E2, p_property_name, &r_default_value_valid); if (r_default_value_valid) { break; } @@ -648,11 +648,10 @@ void DocTools::generate(BitField p_flags) { ClassDB::get_signal_list(name, &signal_list, true); if (signal_list.size()) { - for (List::Element *EV = signal_list.front(); EV; EV = EV->next()) { + for (const MethodInfo &EV : signal_list) { DocData::MethodDoc signal; - signal.name = EV->get().name; - for (List::Element *EA = EV->get().arguments.front(); EA; EA = EA->next()) { - const PropertyInfo &arginfo = EA->get(); + signal.name = EV.name; + for (const PropertyInfo &arginfo : EV.arguments) { DocData::ArgumentDoc argument; DocData::argument_doc_from_arginfo(argument, arginfo); diff --git a/editor/editor_data.cpp b/editor/editor_data.cpp index 73af9f39a6f5..a169ea703829 100644 --- a/editor/editor_data.cpp +++ b/editor/editor_data.cpp @@ -598,8 +598,7 @@ void EditorData::instantiate_object_properties(Object *p_object) { List pinfo; p_object->get_property_list(&pinfo); - for (List::Element *E = pinfo.front(); E; E = E->next()) { - PropertyInfo pi = E->get(); + for (const PropertyInfo &pi : pinfo) { if (pi.type == Variant::OBJECT && pi.usage & PROPERTY_USAGE_EDITOR_INSTANTIATE_OBJECT) { Object *prop = ClassDB::instantiate(pi.class_name); p_object->set(pi.name, prop); diff --git a/editor/editor_file_system.cpp b/editor/editor_file_system.cpp index b8ce3ff65bf7..fc7ff46f19a3 100644 --- a/editor/editor_file_system.cpp +++ b/editor/editor_file_system.cpp @@ -1088,15 +1088,15 @@ int EditorFileSystem::_scan_new_dir(ScannedDirectory *p_dir, Ref &da) int nb_files_total_scan = 0; - for (List::Element *E = dirs.front(); E; E = E->next()) { - if (da->change_dir(E->get()) == OK) { + for (const String &E : dirs) { + if (da->change_dir(E) == OK) { String d = da->get_current_dir(); if (d == cd || !d.begins_with(cd)) { da->change_dir(cd); //avoid recursion } else { ScannedDirectory *sd = memnew(ScannedDirectory); - sd->name = E->get(); + sd->name = E; sd->full_path = p_dir->full_path.path_join(sd->name); nb_files_total_scan += _scan_new_dir(sd, da); @@ -1106,7 +1106,7 @@ int EditorFileSystem::_scan_new_dir(ScannedDirectory *p_dir, Ref &da) da->change_dir(".."); } } else { - ERR_PRINT("Cannot go into subdir '" + E->get() + "'."); + ERR_PRINT("Cannot go into subdir '" + E + "'."); } } diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index b79d1243ba6c..3d37c4214f74 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -719,9 +719,7 @@ bool EditorProperty::use_keying_next() const { List plist; object->get_property_list(&plist, true); - for (List::Element *I = plist.front(); I; I = I->next()) { - PropertyInfo &p = I->get(); - + for (const PropertyInfo &p : plist) { if (p.name == property) { return (p.usage & PROPERTY_USAGE_KEYING_INCREMENTS); } diff --git a/editor/import/3d/editor_import_collada.cpp b/editor/import/3d/editor_import_collada.cpp index 238aa94095d2..09cd04c47083 100644 --- a/editor/import/3d/editor_import_collada.cpp +++ b/editor/import/3d/editor_import_collada.cpp @@ -1642,22 +1642,22 @@ void ColladaImport::create_animation(int p_clip, bool p_import_value_tracks) { } for (int i = 0; i < snapshots.size(); i++) { - for (List::Element *ET = nm.anim_tracks.front(); ET; ET = ET->next()) { + for (const int ET : nm.anim_tracks) { //apply tracks if (p_clip == -1) { - if (track_filter.has(ET->get())) { + if (track_filter.has(ET)) { continue; } } else { - if (!track_filter.has(ET->get())) { + if (!track_filter.has(ET)) { continue; } } found_anim = true; - const Collada::AnimationTrack &at = collada.state.animation_tracks[ET->get()]; + const Collada::AnimationTrack &at = collada.state.animation_tracks[ET]; int xform_idx = -1; for (int j = 0; j < cn->xform_list.size(); j++) { diff --git a/editor/import/dynamic_font_import_settings.cpp b/editor/import/dynamic_font_import_settings.cpp index 8dcb91e2b0b2..7c17ab4b1669 100644 --- a/editor/import/dynamic_font_import_settings.cpp +++ b/editor/import/dynamic_font_import_settings.cpp @@ -523,8 +523,8 @@ void DynamicFontImportSettingsDialog::_variation_add() { import_variation_data->owner = this; ERR_FAIL_COND(import_variation_data.is_null()); - for (List::Element *E = options_variations.front(); E; E = E->next()) { - import_variation_data->defaults[E->get().option.name] = E->get().default_value; + for (const ResourceImporter::ImportOption &E : options_variations) { + import_variation_data->defaults[E.option.name] = E.default_value; } import_variation_data->options = options_variations; @@ -1124,8 +1124,8 @@ void DynamicFontImportSettingsDialog::open_settings(const String &p_path) { text_settings_data->owner = this; - for (List::Element *F = options_text.front(); F; F = F->next()) { - text_settings_data->defaults[F->get().option.name] = F->get().default_value; + for (const ResourceImporter::ImportOption &F : options_text) { + text_settings_data->defaults[F.option.name] = F.default_value; } text_settings_data->fd = font_main; @@ -1144,8 +1144,8 @@ void DynamicFontImportSettingsDialog::open_settings(const String &p_path) { import_settings_data->settings.clear(); import_settings_data->defaults.clear(); - for (List::Element *E = options_general.front(); E; E = E->next()) { - import_settings_data->defaults[E->get().option.name] = E->get().default_value; + for (const ResourceImporter::ImportOption &E : options_general) { + import_settings_data->defaults[E.option.name] = E.default_value; } Ref config; @@ -1157,8 +1157,7 @@ void DynamicFontImportSettingsDialog::open_settings(const String &p_path) { if (err == OK) { List keys; config->get_section_keys("params", &keys); - for (List::Element *E = keys.front(); E; E = E->next()) { - String key = E->get(); + for (const String &key : keys) { print_verbose(String(" ") + key + " == " + String(config->get_value("params", key))); if (key == "preload") { Array preload_configurations = config->get_value("params", key); @@ -1185,8 +1184,8 @@ void DynamicFontImportSettingsDialog::open_settings(const String &p_path) { ERR_FAIL_COND(import_variation_data_custom.is_null()); import_variation_data_custom->owner = this; - for (List::Element *F = options_variations.front(); F; F = F->next()) { - import_variation_data_custom->defaults[F->get().option.name] = F->get().default_value; + for (const ResourceImporter::ImportOption &F : options_variations) { + import_variation_data_custom->defaults[F.option.name] = F.default_value; } import_variation_data_custom->fd = font_main; diff --git a/editor/import/resource_importer_bmfont.cpp b/editor/import/resource_importer_bmfont.cpp index b7efdbb6d6d0..9b78590ed448 100644 --- a/editor/import/resource_importer_bmfont.cpp +++ b/editor/import/resource_importer_bmfont.cpp @@ -81,16 +81,16 @@ Error ResourceImporterBMFont::import(ResourceUID::ID p_source_id, const String & ERR_FAIL_COND_V_MSG(err != OK, err, "Cannot load font to file \"" + p_source_file + "\"."); // Update import settings for the image files used by font. - for (List::Element *E = image_files.front(); E; E = E->next()) { + for (const String &E : image_files) { Ref config; config.instantiate(); - err = config->load(E->get() + ".import"); + err = config->load(E + ".import"); if (err == OK) { config->clear(); config->set_value("remap", "importer", "skip"); - config->save(E->get() + ".import"); + config->save(E + ".import"); } } diff --git a/editor/plugins/animation_state_machine_editor.cpp b/editor/plugins/animation_state_machine_editor.cpp index f5159818f34c..7585ea2ea9c5 100644 --- a/editor/plugins/animation_state_machine_editor.cpp +++ b/editor/plugins/animation_state_machine_editor.cpp @@ -643,14 +643,14 @@ void AnimationNodeStateMachineEditor::_open_menu(const Vector2 &p_position) { ClassDB::get_inheriters_from_class("AnimationRootNode", &classes); classes.sort_custom(); - for (List::Element *E = classes.front(); E; E = E->next()) { - String name = String(E->get()).replace_first("AnimationNode", ""); + for (const StringName &E : classes) { + String name = String(E).replace_first("AnimationNode", ""); if (name == "Animation" || name == "StartState" || name == "EndState") { continue; // nope } int idx = menu->get_item_count(); menu->add_item(vformat(TTR("Add %s"), name), idx); - menu->set_item_metadata(idx, E->get()); + menu->set_item_metadata(idx, E); } Ref clipb = EditorSettings::get_singleton()->get_resource_clipboard(); @@ -2019,16 +2019,16 @@ void EditorAnimationMultiTransitionEdit::_get_property_list(List * prop_transition_path.name = itos(i) + "/" + "transition_path"; p_list->push_back(prop_transition_path); - for (List::Element *F = plist.front(); F; F = F->next()) { - if (F->get().name == "script" || F->get().name == "resource_name" || F->get().name == "resource_path" || F->get().name == "resource_local_to_scene") { + for (const PropertyInfo &F : plist) { + if (F.name == "script" || F.name == "resource_name" || F.name == "resource_path" || F.name == "resource_local_to_scene") { continue; } - if (F->get().usage != PROPERTY_USAGE_DEFAULT) { + if (F.usage != PROPERTY_USAGE_DEFAULT) { continue; } - PropertyInfo prop = F->get(); + PropertyInfo prop = F; prop.name = itos(i) + "/" + prop.name; p_list->push_back(prop); diff --git a/editor/plugins/tiles/tile_set_atlas_source_editor.cpp b/editor/plugins/tiles/tile_set_atlas_source_editor.cpp index ffb5bb5009db..0ab94a7fd6c0 100644 --- a/editor/plugins/tiles/tile_set_atlas_source_editor.cpp +++ b/editor/plugins/tiles/tile_set_atlas_source_editor.cpp @@ -463,13 +463,13 @@ void TileSetAtlasSourceEditor::AtlasTileProxyObject::_get_property_list(Listget_property_list(&list); HashMap counts; // Counts the number of time a property appears (useful for groups that may appear more than once) - for (List::Element *E_property = list.front(); E_property; E_property = E_property->next()) { + for (const PropertyInfo &E_property : list) { // Don't show category for TileData. - if (E_property->get().usage & PROPERTY_USAGE_CATEGORY) { + if (E_property.usage & PROPERTY_USAGE_CATEGORY) { continue; } - const String &property_string = E_property->get().name; + const String &property_string = E_property.name; if (!tile_data->is_allowing_transform() && (property_string == "flip_h" || property_string == "flip_v" || property_string == "transpose")) { continue; } @@ -480,7 +480,7 @@ void TileSetAtlasSourceEditor::AtlasTileProxyObject::_get_property_list(Listget(); + PropertyInfo stored_property_info = E_property; stored_property_info.usage |= PROPERTY_USAGE_STORAGE; // Ignore the storage flag in comparing properties. PropertyId id = { counts[property_string], property_string }; diff --git a/editor/plugins/version_control_editor_plugin.cpp b/editor/plugins/version_control_editor_plugin.cpp index b6c880d77f83..4da374e0d2a6 100644 --- a/editor/plugins/version_control_editor_plugin.cpp +++ b/editor/plugins/version_control_editor_plugin.cpp @@ -222,8 +222,7 @@ void VersionControlEditorPlugin::_refresh_commit_list() { List commit_info_list = EditorVCSInterface::get_singleton()->get_previous_commits(commit_list_size_button->get_selected_metadata()); - for (List::Element *e = commit_info_list.front(); e; e = e->next()) { - EditorVCSInterface::Commit commit = e->get(); + for (const EditorVCSInterface::Commit &commit : commit_info_list) { TreeItem *item = commit_list->create_item(); // Only display the first line of a commit message @@ -370,8 +369,7 @@ void VersionControlEditorPlugin::_refresh_stage_area() { unstaged_files->get_root()->clear_children(); List status_files = EditorVCSInterface::get_singleton()->get_modified_files_data(); - for (List::Element *E = status_files.front(); E; E = E->next()) { - EditorVCSInterface::StatusFile sf = E->get(); + for (const EditorVCSInterface::StatusFile &sf : status_files) { if (sf.area == EditorVCSInterface::TREE_AREA_STAGED) { _add_new_item(staged_files, sf.file_path, sf.change_type); } else if (sf.area == EditorVCSInterface::TREE_AREA_UNSTAGED) { diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp index 27c2f9575144..0b1588298bff 100644 --- a/editor/plugins/visual_shader_editor_plugin.cpp +++ b/editor/plugins/visual_shader_editor_plugin.cpp @@ -4424,8 +4424,8 @@ void VisualShaderEditor::_delete_nodes(int p_type, const List &p_nodes) { for (const VisualShader::Connection &E : conns) { if (E.from_node == F || E.to_node == F) { bool cancel = false; - for (List::Element *R = used_conns.front(); R; R = R->next()) { - if (R->get().from_node == E.from_node && R->get().from_port == E.from_port && R->get().to_node == E.to_node && R->get().to_port == E.to_port) { + for (const VisualShader::Connection &R : used_conns) { + if (R.from_node == E.from_node && R.from_port == E.from_port && R.to_node == E.to_node && R.to_port == E.to_port) { cancel = true; // to avoid ERR_ALREADY_EXISTS warning break; } diff --git a/editor/project_manager.cpp b/editor/project_manager.cpp index c3bd3acf775f..e115c4b7476a 100644 --- a/editor/project_manager.cpp +++ b/editor/project_manager.cpp @@ -142,8 +142,8 @@ void ProjectManager::_build_icon_type_cache(Ref p_theme) { } List tl; p_theme->get_icon_list(EditorStringName(EditorIcons), &tl); - for (List::Element *E = tl.front(); E; E = E->next()) { - icon_type_cache[E->get()] = p_theme->get_icon(E->get(), EditorStringName(EditorIcons)); + for (const StringName &E : tl) { + icon_type_cache[E] = p_theme->get_icon(E, EditorStringName(EditorIcons)); } } diff --git a/modules/enet/enet_connection.cpp b/modules/enet/enet_connection.cpp index f66f5867368c..6d3a186bdd36 100644 --- a/modules/enet/enet_connection.cpp +++ b/modules/enet/enet_connection.cpp @@ -72,8 +72,8 @@ Error ENetConnection::create_host(int p_max_peers, int p_max_channels, int p_in_ void ENetConnection::destroy() { ERR_FAIL_NULL_MSG(host, "Host already destroyed."); - for (List>::Element *E = peers.front(); E; E = E->next()) { - E->get()->_on_disconnect(); + for (const Ref &E : peers) { + E->_on_disconnect(); } peers.clear(); enet_host_destroy(host); diff --git a/modules/gdscript/gdscript_editor.cpp b/modules/gdscript/gdscript_editor.cpp index 743fe5711e92..adeae4e4d5dd 100644 --- a/modules/gdscript/gdscript_editor.cpp +++ b/modules/gdscript/gdscript_editor.cpp @@ -1505,8 +1505,8 @@ static void _find_identifiers(const GDScriptParser::CompletionContext &p_context List utility_func_names; Variant::get_utility_function_list(&utility_func_names); - for (List::Element *E = utility_func_names.front(); E; E = E->next()) { - ScriptLanguage::CodeCompletionOption option(E->get(), ScriptLanguage::CODE_COMPLETION_KIND_FUNCTION); + for (const StringName &E : utility_func_names) { + ScriptLanguage::CodeCompletionOption option(E, ScriptLanguage::CODE_COMPLETION_KIND_FUNCTION); option.insert_text += "("; option.display += U"(\u2026)"; // As all utility functions contain an argument or more, this is hardcoded here. r_result.insert(option.display, option); diff --git a/modules/gdscript/language_server/gdscript_workspace.cpp b/modules/gdscript/language_server/gdscript_workspace.cpp index ed58588f056c..d5ae5a551a0c 100644 --- a/modules/gdscript/language_server/gdscript_workspace.cpp +++ b/modules/gdscript/language_server/gdscript_workspace.cpp @@ -543,8 +543,8 @@ Vector GDScriptWorkspace::find_all_usages(const lsp::DocumentSymb list_script_files("res://", paths); Vector usages; - for (List::Element *PE = paths.front(); PE; PE = PE->next()) { - usages.append_array(find_usages_in_file(p_symbol, PE->get())); + for (const String &PE : paths) { + usages.append_array(find_usages_in_file(p_symbol, PE)); } return usages; } diff --git a/modules/gdscript/language_server/godot_lsp.h b/modules/gdscript/language_server/godot_lsp.h index 6e19cd7a233c..0a10d27c5f36 100644 --- a/modules/gdscript/language_server/godot_lsp.h +++ b/modules/gdscript/language_server/godot_lsp.h @@ -1874,7 +1874,7 @@ struct GodotNativeClassInfo { const DocData::ClassDoc *class_doc = nullptr; const ClassDB::ClassInfo *class_info = nullptr; - Dictionary to_json() { + Dictionary to_json() const { Dictionary dict; dict["name"] = name; dict["inherits"] = class_doc->inherits; @@ -1889,11 +1889,11 @@ struct GodotCapabilities { */ List native_classes; - Dictionary to_json() { + Dictionary to_json() const { Dictionary dict; Array classes; - for (List::Element *E = native_classes.front(); E; E = E->next()) { - classes.push_back(E->get().to_json()); + for (const GodotNativeClassInfo &E : native_classes) { + classes.push_back(E.to_json()); } dict["native_classes"] = classes; return dict; diff --git a/modules/navigation/2d/nav_mesh_generator_2d.cpp b/modules/navigation/2d/nav_mesh_generator_2d.cpp index 7d79a7e16457..a0e938c3903a 100644 --- a/modules/navigation/2d/nav_mesh_generator_2d.cpp +++ b/modules/navigation/2d/nav_mesh_generator_2d.cpp @@ -502,9 +502,7 @@ void NavMeshGenerator2D::generator_bake_from_source_geometry_data(Ref> new_polygons; HashMap points; - for (List::Element *I = tppl_out_polygon.front(); I; I = I->next()) { - TPPLPoly &tp = I->get(); - + for (const TPPLPoly &tp : tppl_out_polygon) { Vector new_polygon; for (int64_t i = 0; i < tp.GetNumPoints(); i++) { diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp index 8d24859422ec..4ba0ef3f8aee 100644 --- a/scene/animation/animation_player.cpp +++ b/scene/animation/animation_player.cpp @@ -256,8 +256,7 @@ void AnimationPlayer::_process_playback_data(PlaybackData &cd, double p_delta, f float AnimationPlayer::get_current_blend_amount() { Playback &c = playback; float blend = 1.0; - for (List::Element *E = c.blend.front(); E; E = E->next()) { - Blend &b = E->get(); + for (const Blend &b : c.blend) { blend = blend - b.blend_left; } return MAX(0, blend); diff --git a/scene/main/node.cpp b/scene/main/node.cpp index f5bc3344dd4a..e9e2e3fe6a7c 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -2685,9 +2685,9 @@ void Node::get_storable_properties(HashSet &r_storable_properties) c ERR_THREAD_GUARD List pi; get_property_list(&pi); - for (List::Element *E = pi.front(); E; E = E->next()) { - if ((E->get().usage & PROPERTY_USAGE_STORAGE)) { - r_storable_properties.insert(E->get().name); + for (const PropertyInfo &E : pi) { + if ((E.usage & PROPERTY_USAGE_STORAGE)) { + r_storable_properties.insert(E.name); } } } diff --git a/scene/resources/2d/navigation_polygon.cpp b/scene/resources/2d/navigation_polygon.cpp index 0e293b68c522..677a552c01d7 100644 --- a/scene/resources/2d/navigation_polygon.cpp +++ b/scene/resources/2d/navigation_polygon.cpp @@ -396,9 +396,7 @@ void NavigationPolygon::make_polygons_from_outlines() { vertices.clear(); HashMap points; - for (List::Element *I = out_poly.front(); I; I = I->next()) { - TPPLPoly &tp = I->get(); - + for (const TPPLPoly &tp : out_poly) { Vector p; for (int64_t i = 0; i < tp.GetNumPoints(); i++) { diff --git a/scene/resources/3d/primitive_meshes.cpp b/scene/resources/3d/primitive_meshes.cpp index 5ba58b4fe89e..e386d08dbbd2 100644 --- a/scene/resources/3d/primitive_meshes.cpp +++ b/scene/resources/3d/primitive_meshes.cpp @@ -3105,14 +3105,13 @@ void TextMesh::_generate_glyph_mesh_data(const GlyphMeshKey &p_key, const Glyph ERR_FAIL_MSG("Convex decomposing failed. Make sure the font doesn't contain self-intersecting lines, as these are not supported in TextMesh."); } List out_tris; - for (List::Element *I = out_poly.front(); I; I = I->next()) { - if (tpart.Triangulate_OPT(&(I->get()), &out_tris) == 0) { + for (TPPLPoly &I : out_poly) { + if (tpart.Triangulate_OPT(&I, &out_tris) == 0) { ERR_FAIL_MSG("Triangulation failed. Make sure the font doesn't contain self-intersecting lines, as these are not supported in TextMesh."); } } - for (List::Element *I = out_tris.front(); I; I = I->next()) { - TPPLPoly &tp = I->get(); + for (const TPPLPoly &tp : out_tris) { ERR_FAIL_COND(tp.GetNumPoints() != 3); // Triangles only. for (int i = 0; i < 3; i++) { diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp index a9dd89289c01..82ee2964497a 100644 --- a/scene/resources/material.cpp +++ b/scene/resources/material.cpp @@ -257,10 +257,10 @@ void ShaderMaterial::_get_property_list(List *p_list) const { bool is_none_group_undefined = true; bool is_none_group = true; - for (List::Element *E = list.front(); E; E = E->next()) { - if (E->get().usage == PROPERTY_USAGE_GROUP) { - if (!E->get().name.is_empty()) { - Vector vgroup = E->get().name.split("::"); + for (const PropertyInfo &E : list) { + if (E.usage == PROPERTY_USAGE_GROUP) { + if (!E.name.is_empty()) { + Vector vgroup = E.name.split("::"); last_group = vgroup[0]; if (vgroup.size() > 1) { last_subgroup = vgroup[1]; @@ -322,23 +322,23 @@ void ShaderMaterial::_get_property_list(List *p_list) const { vgroups.push_back(Pair>("", { "" })); } - const bool is_uniform_cached = param_cache.has(E->get().name); + const bool is_uniform_cached = param_cache.has(E.name); bool is_uniform_type_compatible = true; if (is_uniform_cached) { // Check if the uniform Variant type changed, for example vec3 to vec4. - const Variant &cached = param_cache.get(E->get().name); + const Variant &cached = param_cache.get(E.name); if (cached.is_array()) { // Allow some array conversions for backwards compatibility. - is_uniform_type_compatible = Variant::can_convert(E->get().type, cached.get_type()); + is_uniform_type_compatible = Variant::can_convert(E.type, cached.get_type()); } else { - is_uniform_type_compatible = E->get().type == cached.get_type(); + is_uniform_type_compatible = E.type == cached.get_type(); } #ifndef DISABLE_DEPRECATED // PackedFloat32Array -> PackedVector4Array conversion. - if (!is_uniform_type_compatible && E->get().type == Variant::PACKED_VECTOR4_ARRAY && cached.get_type() == Variant::PACKED_FLOAT32_ARRAY) { + if (!is_uniform_type_compatible && E.type == Variant::PACKED_VECTOR4_ARRAY && cached.get_type() == Variant::PACKED_FLOAT32_ARRAY) { PackedVector4Array varray; PackedFloat32Array array = (PackedFloat32Array)cached; @@ -346,28 +346,28 @@ void ShaderMaterial::_get_property_list(List *p_list) const { varray.push_back(Vector4(array[i], array[i + 1], array[i + 2], array[i + 3])); } - param_cache.insert(E->get().name, varray); + param_cache.insert(E.name, varray); is_uniform_type_compatible = true; } #endif - if (is_uniform_type_compatible && E->get().type == Variant::OBJECT && cached.get_type() == Variant::OBJECT) { + if (is_uniform_type_compatible && E.type == Variant::OBJECT && cached.get_type() == Variant::OBJECT) { // Check if the Object class (hint string) changed, for example Texture2D sampler to Texture3D. // Allow inheritance, Texture2D type sampler should also accept CompressedTexture2D. Object *cached_obj = cached; - if (!cached_obj->is_class(E->get().hint_string)) { + if (!cached_obj->is_class(E.hint_string)) { is_uniform_type_compatible = false; } } } - PropertyInfo info = E->get(); + PropertyInfo info = E; info.name = "shader_parameter/" + info.name; if (!is_uniform_cached || !is_uniform_type_compatible) { // Property has never been edited or its type changed, 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); + Variant default_value = RenderingServer::get_singleton()->shader_get_parameter_default(shader->get_rid(), E.name); + param_cache.insert(E.name, default_value); + remap_cache.insert(info.name, E.name); } groups[last_group][last_subgroup].push_back(info); } @@ -376,8 +376,8 @@ void ShaderMaterial::_get_property_list(List *p_list) const { String group = group_pair.first; for (const String &subgroup : group_pair.second) { List &prop_infos = groups[group][subgroup]; - for (List::Element *item = prop_infos.front(); item; item = item->next()) { - p_list->push_back(item->get()); + for (const PropertyInfo &item : prop_infos) { + p_list->push_back(item); } } } diff --git a/scene/resources/resource_format_text.cpp b/scene/resources/resource_format_text.cpp index f1cfb5c5f515..8692a3dee926 100644 --- a/scene/resources/resource_format_text.cpp +++ b/scene/resources/resource_format_text.cpp @@ -1908,18 +1908,18 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const Ref property_list; res->get_property_list(&property_list); - for (List::Element *PE = property_list.front(); PE; PE = PE->next()) { - if (skip_editor && PE->get().name.begins_with("__editor")) { + for (const PropertyInfo &PE : property_list) { + if (skip_editor && PE.name.begins_with("__editor")) { continue; } - if (PE->get().name == META_PROPERTY_MISSING_RESOURCES) { + if (PE.name == META_PROPERTY_MISSING_RESOURCES) { continue; } - if (PE->get().usage & PROPERTY_USAGE_STORAGE || missing_resource_properties.has(PE->get().name)) { - String name = PE->get().name; + if (PE.usage & PROPERTY_USAGE_STORAGE || missing_resource_properties.has(PE.name)) { + String name = PE.name; Variant value; - if (PE->get().usage & PROPERTY_USAGE_RESOURCE_NOT_PERSISTENT) { + if (PE.usage & PROPERTY_USAGE_RESOURCE_NOT_PERSISTENT) { NonPersistentKey npk; npk.base = res; npk.property = name; @@ -1930,11 +1930,11 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const Refget(name); } - if (PE->get().type == Variant::OBJECT && missing_resource_properties.has(PE->get().name)) { + if (PE.type == Variant::OBJECT && missing_resource_properties.has(PE.name)) { // Was this missing resource overridden? If so do not save the old value. Ref ures = value; if (ures.is_null()) { - value = missing_resource_properties[PE->get().name]; + value = missing_resource_properties[PE.name]; } } @@ -1944,7 +1944,7 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const Refget().type == Variant::OBJECT && value.is_zero() && !(PE->get().usage & PROPERTY_USAGE_STORE_IF_NULL)) { + if (PE.type == Variant::OBJECT && value.is_zero() && !(PE.usage & PROPERTY_USAGE_STORE_IF_NULL)) { continue; } diff --git a/servers/rendering/renderer_rd/storage_rd/texture_storage.cpp b/servers/rendering/renderer_rd/storage_rd/texture_storage.cpp index 69ae3d971a4e..5196932424bf 100644 --- a/servers/rendering/renderer_rd/storage_rd/texture_storage.cpp +++ b/servers/rendering/renderer_rd/storage_rd/texture_storage.cpp @@ -1634,8 +1634,8 @@ void TextureStorage::texture_debug_usage(List *r_info) { List textures; texture_owner.get_owned_list(&textures); - for (List::Element *E = textures.front(); E; E = E->next()) { - Texture *t = texture_owner.get_or_null(E->get()); + for (const RID &E : textures) { + Texture *t = texture_owner.get_or_null(E); if (!t) { continue; }