From a1846b27ea09af5c5dfb980e270b4bf6a0de5d9e Mon Sep 17 00:00:00 2001 From: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> Date: Sun, 25 Aug 2024 14:15:10 +0200 Subject: [PATCH] Improve use of `Ref.is_null/valid` Use `is_null` over `!is_valid` and vice versa. --- editor/animation_bezier_editor.cpp | 2 +- editor/animation_track_editor.cpp | 2 +- editor/animation_track_editor_plugins.cpp | 18 +++---- editor/code_editor.cpp | 4 +- editor/create_dialog.cpp | 4 +- editor/debugger/editor_debugger_inspector.cpp | 2 +- editor/debugger/editor_debugger_node.cpp | 2 +- editor/editor_autoload_settings.cpp | 2 +- editor/editor_data.cpp | 6 +-- editor/editor_file_system.cpp | 2 +- editor/editor_inspector.cpp | 2 +- editor/editor_interface.cpp | 4 +- editor/editor_node.cpp | 8 +-- editor/editor_resource_picker.cpp | 18 +++---- editor/editor_resource_preview.cpp | 8 +-- editor/editor_settings.cpp | 6 +-- editor/export/editor_export.cpp | 2 +- editor/export/project_export.cpp | 4 +- editor/gui/scene_tree_editor.cpp | 4 +- editor/import/3d/editor_import_collada.cpp | 2 +- ...post_import_plugin_skeleton_rest_fixer.cpp | 2 +- ...import_plugin_skeleton_track_organizer.cpp | 2 +- editor/import/3d/resource_importer_scene.cpp | 20 ++++---- .../import/audio_stream_import_settings.cpp | 12 ++--- .../import/resource_importer_shader_file.cpp | 2 +- .../resource_importer_texture_atlas.cpp | 2 +- editor/import_dock.cpp | 2 +- .../animation_blend_space_1d_editor.cpp | 4 +- .../animation_blend_space_2d_editor.cpp | 4 +- .../animation_blend_tree_editor_plugin.cpp | 12 ++--- editor/plugins/animation_library_editor.cpp | 6 +-- .../animation_player_editor_plugin.cpp | 8 +-- .../animation_state_machine_editor.cpp | 12 ++--- .../plugins/asset_library_editor_plugin.cpp | 2 +- editor/plugins/bone_map_editor_plugin.cpp | 20 ++++---- editor/plugins/canvas_item_editor_plugin.cpp | 4 +- editor/plugins/editor_plugin.cpp | 24 ++++----- editor/plugins/editor_preview_plugins.cpp | 6 +-- .../gizmos/mesh_instance_3d_gizmo_plugin.cpp | 2 +- .../occluder_instance_3d_gizmo_plugin.cpp | 2 +- editor/plugins/material_editor_plugin.cpp | 18 +++---- .../mesh_instance_3d_editor_plugin.cpp | 10 ++-- editor/plugins/mesh_library_editor_plugin.cpp | 4 +- editor/plugins/multimesh_editor_plugin.cpp | 2 +- .../navigation_polygon_editor_plugin.cpp | 2 +- editor/plugins/node_3d_editor_gizmos.cpp | 2 +- editor/plugins/node_3d_editor_plugin.cpp | 24 ++++----- .../resource_preloader_editor_plugin.cpp | 4 +- editor/plugins/script_editor_plugin.cpp | 26 +++++----- editor/plugins/script_text_editor.cpp | 12 ++--- editor/plugins/shader_editor_plugin.cpp | 2 +- editor/plugins/skeleton_3d_editor_plugin.cpp | 4 +- editor/plugins/sprite_2d_editor_plugin.cpp | 6 +-- editor/plugins/text_shader_editor.cpp | 4 +- editor/plugins/texture_3d_editor_plugin.cpp | 6 +-- .../plugins/texture_layered_editor_plugin.cpp | 4 +- editor/plugins/tiles/atlas_merging_dialog.cpp | 4 +- editor/plugins/tiles/tile_atlas_view.cpp | 2 +- editor/plugins/tiles/tile_data_editors.cpp | 16 +++--- .../plugins/tiles/tile_map_layer_editor.cpp | 2 +- .../tiles/tile_proxies_manager_dialog.cpp | 2 +- .../tiles/tile_set_atlas_source_editor.cpp | 14 +++--- editor/plugins/tiles/tile_set_editor.cpp | 18 +++---- ...le_set_scenes_collection_source_editor.cpp | 4 +- editor/plugins/tiles/tiles_editor_plugin.cpp | 4 +- .../plugins/visual_shader_editor_plugin.cpp | 50 +++++++++---------- editor/scene_tree_dock.cpp | 6 +-- main/main.cpp | 2 +- modules/csg/csg_shape.cpp | 4 +- modules/gdscript/gdscript_analyzer.cpp | 2 +- .../gdscript/gdscript_utility_functions.cpp | 6 +-- .../language_server/gdscript_workspace.cpp | 2 +- .../gdscript/tests/gdscript_test_runner.cpp | 2 +- modules/gltf/gltf_document.cpp | 2 +- .../gridmap/editor/grid_map_editor_plugin.cpp | 4 +- modules/gridmap/grid_map.cpp | 14 +++--- .../audio_stream_interactive.cpp | 2 +- .../audio_stream_playlist.cpp | 2 +- modules/mbedtls/crypto_mbedtls.cpp | 8 +-- modules/mbedtls/dtls_server_mbedtls.cpp | 2 +- modules/mbedtls/packet_peer_mbed_dtls.cpp | 6 +-- modules/mbedtls/stream_peer_mbedtls.cpp | 2 +- modules/mono/csharp_script.cpp | 16 +++--- modules/mono/glue/runtime_interop.cpp | 2 +- .../multiplayer/editor/replication_editor.cpp | 2 +- modules/multiplayer/scene_multiplayer.cpp | 10 ++-- modules/multiplayer/scene_rpc_interface.cpp | 2 +- .../2d/godot_navigation_server_2d.cpp | 14 +++--- .../navigation/2d/nav_mesh_generator_2d.cpp | 18 +++---- .../3d/godot_navigation_server_3d.cpp | 10 ++-- .../navigation/3d/nav_mesh_generator_3d.cpp | 12 ++--- .../editor/navigation_mesh_editor_plugin.cpp | 2 +- .../openxr_dpad_binding_extension.cpp | 2 +- ...penxr_valve_analog_threshold_extension.cpp | 4 +- modules/webp/resource_saver_webp.cpp | 2 +- modules/webrtc/webrtc_multiplayer_peer.cpp | 2 +- platform/android/os_android.cpp | 2 +- platform/ios/export/godot_plugin_config.cpp | 2 +- platform/linuxbsd/wayland/wayland_thread.cpp | 2 +- scene/2d/animated_sprite_2d.cpp | 4 +- scene/2d/cpu_particles_2d.cpp | 2 +- scene/2d/light_2d.cpp | 4 +- scene/2d/light_occluder_2d.cpp | 2 +- scene/2d/navigation_region_2d.cpp | 4 +- scene/2d/path_2d.cpp | 6 +-- scene/2d/physics/collision_object_2d.cpp | 2 +- scene/2d/physics/collision_shape_2d.cpp | 6 +-- scene/2d/skeleton_2d.cpp | 2 +- scene/2d/tile_map.cpp | 12 ++--- scene/2d/tile_map_layer.cpp | 14 +++--- scene/2d/touch_screen_button.cpp | 2 +- scene/3d/cpu_particles_3d.cpp | 2 +- scene/3d/gpu_particles_3d.cpp | 2 +- scene/3d/gpu_particles_collision_3d.cpp | 2 +- scene/3d/lightmap_gi.cpp | 6 +-- scene/3d/mesh_instance_3d.cpp | 4 +- scene/3d/navigation_agent_3d.cpp | 4 +- scene/3d/navigation_region_3d.cpp | 8 +-- scene/3d/path_3d.cpp | 4 +- scene/3d/physics/collision_object_3d.cpp | 2 +- scene/3d/physics/collision_shape_3d.cpp | 2 +- scene/3d/physics/ray_cast_3d.cpp | 2 +- scene/3d/physics/shape_cast_3d.cpp | 4 +- scene/3d/sprite_3d.cpp | 4 +- scene/3d/voxel_gi.cpp | 2 +- scene/3d/world_environment.cpp | 2 +- scene/3d/xr_body_modifier_3d.cpp | 2 +- scene/3d/xr_face_modifier_3d.cpp | 2 +- scene/3d/xr_nodes.cpp | 2 +- scene/animation/animation_blend_space_1d.cpp | 2 +- scene/animation/animation_blend_space_2d.cpp | 2 +- .../animation_node_state_machine.cpp | 18 +++---- scene/animation/animation_tree.cpp | 6 +-- scene/debugger/scene_debugger.cpp | 14 +++--- scene/gui/base_button.cpp | 2 +- scene/gui/check_box.cpp | 16 +++--- scene/gui/check_button.cpp | 4 +- scene/gui/code_edit.cpp | 4 +- scene/gui/color_picker.cpp | 2 +- scene/gui/control.cpp | 6 +-- scene/gui/graph_node.cpp | 4 +- scene/gui/rich_text_label.cpp | 16 +++--- scene/gui/slider.cpp | 2 +- scene/gui/tab_bar.cpp | 2 +- scene/gui/texture_button.cpp | 2 +- scene/gui/texture_rect.cpp | 2 +- scene/gui/tree.cpp | 6 +-- scene/gui/video_stream_player.cpp | 8 +-- scene/main/instance_placeholder.cpp | 4 +- scene/main/resource_preloader.cpp | 2 +- scene/main/scene_tree.cpp | 4 +- scene/main/window.cpp | 6 +-- .../skeleton_modification_stack_2d.cpp | 10 ++-- scene/resources/2d/tile_set.cpp | 8 +-- ...avigation_mesh_source_geometry_data_3d.cpp | 2 +- scene/resources/animated_texture.cpp | 8 +-- scene/resources/atlas_texture.cpp | 2 +- scene/resources/bone_map.cpp | 4 +- scene/resources/compressed_texture.cpp | 2 +- scene/resources/font.cpp | 2 +- scene/resources/image_texture.cpp | 2 +- scene/resources/material.cpp | 2 +- scene/resources/mesh.cpp | 2 +- scene/resources/multimesh.cpp | 2 +- scene/resources/packed_scene.cpp | 6 +-- .../resources/portable_compressed_texture.cpp | 2 +- scene/resources/resource_format_text.cpp | 8 +-- scene/resources/visual_shader.cpp | 4 +- .../visual_shader_particle_nodes.cpp | 2 +- servers/movie_writer/movie_writer_mjpeg.cpp | 2 +- servers/movie_writer/movie_writer_pngwav.cpp | 2 +- servers/physics_server_2d.cpp | 12 ++--- servers/physics_server_3d.cpp | 12 ++--- servers/rendering/rendering_device.cpp | 2 +- servers/xr_server.cpp | 6 +-- tests/core/io/test_file_access.h | 6 +-- tests/core/io/test_image.h | 10 ++-- 177 files changed, 517 insertions(+), 519 deletions(-) diff --git a/editor/animation_bezier_editor.cpp b/editor/animation_bezier_editor.cpp index 43c6285d282..2c8fa257869 100644 --- a/editor/animation_bezier_editor.cpp +++ b/editor/animation_bezier_editor.cpp @@ -689,7 +689,7 @@ void AnimationBezierTrackEdit::set_editor(AnimationTrackEditor *p_editor) { } void AnimationBezierTrackEdit::_play_position_draw() { - if (!animation.is_valid() || play_position_pos < 0) { + if (animation.is_null() || play_position_pos < 0) { return; } diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp index 6ae74aef428..f93029a3c5c 100644 --- a/editor/animation_track_editor.cpp +++ b/editor/animation_track_editor.cpp @@ -8066,7 +8066,7 @@ void AnimationTrackKeyEditEditor::_time_edit_exited() { } AnimationTrackKeyEditEditor::AnimationTrackKeyEditEditor(Ref p_animation, int p_track, real_t p_key_ofs, bool p_use_fps) { - if (!p_animation.is_valid()) { + if (p_animation.is_null()) { return; } diff --git a/editor/animation_track_editor_plugins.cpp b/editor/animation_track_editor_plugins.cpp index da3112fc79c..9c30f156267 100644 --- a/editor/animation_track_editor_plugins.cpp +++ b/editor/animation_track_editor_plugins.cpp @@ -220,7 +220,7 @@ Rect2 AnimationTrackEditAudio::get_key_rect(int p_index, float p_pixels_sec) { Ref stream = object->call("get_stream"); - if (!stream.is_valid()) { + if (stream.is_null()) { return AnimationTrackEdit::get_key_rect(p_index, p_pixels_sec); } @@ -260,7 +260,7 @@ void AnimationTrackEditAudio::draw_key(int p_index, float p_pixels_sec, int p_x, Ref stream = object->call("get_stream"); - if (!stream.is_valid()) { + if (stream.is_null()) { AnimationTrackEdit::draw_key(p_index, p_pixels_sec, p_x, p_selected, p_clip_left, p_clip_right); return; } @@ -379,7 +379,7 @@ Rect2 AnimationTrackEditSpriteFrame::get_key_rect(int p_index, float p_pixels_se if (Object::cast_to(object) || Object::cast_to(object)) { Ref texture = object->call("get_texture"); - if (!texture.is_valid()) { + if (texture.is_null()) { return AnimationTrackEdit::get_key_rect(p_index, p_pixels_sec); } @@ -422,7 +422,7 @@ Rect2 AnimationTrackEditSpriteFrame::get_key_rect(int p_index, float p_pixels_se } Ref texture = sf->get_frame_texture(animation_name, frame); - if (!texture.is_valid()) { + if (texture.is_null()) { return AnimationTrackEdit::get_key_rect(p_index, p_pixels_sec); } @@ -456,7 +456,7 @@ void AnimationTrackEditSpriteFrame::draw_key(int p_index, float p_pixels_sec, in if (Object::cast_to(object) || Object::cast_to(object)) { texture = object->call("get_texture"); - if (!texture.is_valid()) { + if (texture.is_null()) { AnimationTrackEdit::draw_key(p_index, p_pixels_sec, p_x, p_selected, p_clip_left, p_clip_right); return; } @@ -514,7 +514,7 @@ void AnimationTrackEditSpriteFrame::draw_key(int p_index, float p_pixels_sec, in } texture = sf->get_frame_texture(animation_name, frame); - if (!texture.is_valid()) { + if (texture.is_null()) { AnimationTrackEdit::draw_key(p_index, p_pixels_sec, p_x, p_selected, p_clip_left, p_clip_right); return; } @@ -808,7 +808,7 @@ int AnimationTrackEditTypeAudio::get_key_height() const { Rect2 AnimationTrackEditTypeAudio::get_key_rect(int p_index, float p_pixels_sec) { Ref stream = get_animation()->audio_track_get_key_stream(get_track(), p_index); - if (!stream.is_valid()) { + if (stream.is_null()) { return AnimationTrackEdit::get_key_rect(p_index, p_pixels_sec); } @@ -841,7 +841,7 @@ bool AnimationTrackEditTypeAudio::is_key_selectable_by_distance() const { void AnimationTrackEditTypeAudio::draw_key(int p_index, float p_pixels_sec, int p_x, bool p_selected, int p_clip_left, int p_clip_right) { Ref stream = get_animation()->audio_track_get_key_stream(get_track(), p_index); - if (!stream.is_valid()) { + if (stream.is_null()) { AnimationTrackEdit::draw_key(p_index, p_pixels_sec, p_x, p_selected, p_clip_left, p_clip_right); // Draw diamond. return; } @@ -1025,7 +1025,7 @@ void AnimationTrackEditTypeAudio::gui_input(const Ref &p_event) { for (int i = 0; i < get_animation()->track_get_key_count(get_track()); i++) { Ref stream = get_animation()->audio_track_get_key_stream(get_track(), i); - if (!stream.is_valid()) { + if (stream.is_null()) { continue; } diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp index 5ccf2d413d0..9934b8f4521 100644 --- a/editor/code_editor.cpp +++ b/editor/code_editor.cpp @@ -866,7 +866,7 @@ void CodeTextEditor::input(const Ref &event) { const Ref key_event = event; - if (!key_event.is_valid()) { + if (key_event.is_null()) { return; } if (!key_event->is_pressed()) { @@ -1053,7 +1053,7 @@ Ref CodeTextEditor::_get_completion_icon(const ScriptLanguage::CodeCo tex = get_editor_theme_icon(p_option.display); } else { tex = EditorNode::get_singleton()->get_class_icon(p_option.display); - if (!tex.is_valid()) { + if (tex.is_null()) { tex = get_editor_theme_icon(SNAME("Object")); } } diff --git a/editor/create_dialog.cpp b/editor/create_dialog.cpp index a383ebbc3c2..cd3f9b6c0a0 100644 --- a/editor/create_dialog.cpp +++ b/editor/create_dialog.cpp @@ -114,7 +114,7 @@ bool CreateDialog::_is_type_preferred(const String &p_type) const { bool CreateDialog::_is_class_disabled_by_feature_profile(const StringName &p_class) const { Ref profile = EditorFeatureProfileManager::get_singleton()->get_current_profile(); - return !profile.is_null() && profile->is_class_disabled(p_class); + return profile.is_valid() && profile->is_class_disabled(p_class); } bool CreateDialog::_should_hide_type(const StringName &p_type) const { @@ -312,7 +312,7 @@ void CreateDialog::_configure_search_option_item(TreeItem *r_item, const StringN r_item->set_suffix(0, "(" + suffix + ")"); } - ERR_FAIL_COND(!scr.is_valid()); + ERR_FAIL_COND(scr.is_null()); is_abstract = scr->is_abstract(); } else { r_item->set_metadata(0, custom_type_parents[p_type]); diff --git a/editor/debugger/editor_debugger_inspector.cpp b/editor/debugger/editor_debugger_inspector.cpp index e085e2e4480..7a1435e92bb 100644 --- a/editor/debugger/editor_debugger_inspector.cpp +++ b/editor/debugger/editor_debugger_inspector.cpp @@ -167,7 +167,7 @@ ObjectID EditorDebuggerInspector::add_object(const Array &p_arr) { if (debug_obj->get_script() != var) { debug_obj->set_script(Ref()); Ref