summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.clang-tidy6
-rw-r--r--core/array.cpp30
-rw-r--r--core/bind/core_bind.cpp86
-rw-r--r--core/class_db.cpp120
-rw-r--r--core/color.cpp44
-rw-r--r--core/color.h9
-rw-r--r--core/color_names.inc3
-rw-r--r--core/command_queue_mt.cpp6
-rw-r--r--core/command_queue_mt.h19
-rw-r--r--core/compressed_translation.cpp18
-rw-r--r--core/compressed_translation.h3
-rw-r--r--core/cowdata.h35
-rw-r--r--core/crypto/crypto.cpp23
-rw-r--r--core/crypto/hashing_context.cpp3
-rw-r--r--core/debugger/debugger_marshalls.cpp3
-rw-r--r--core/debugger/engine_debugger.cpp24
-rw-r--r--core/debugger/local_debugger.cpp21
-rw-r--r--core/debugger/remote_debugger.cpp84
-rw-r--r--core/debugger/remote_debugger_peer.cpp14
-rw-r--r--core/debugger/script_debugger.cpp12
-rw-r--r--core/dictionary.cpp30
-rw-r--r--core/engine.cpp9
-rw-r--r--core/error_macros.cpp5
-rw-r--r--core/func_ref.cpp6
-rw-r--r--core/hash_map.h63
-rw-r--r--core/hashfuncs.h13
-rw-r--r--core/image.cpp315
-rw-r--r--core/input/input.cpp63
-rw-r--r--core/input/input_event.cpp81
-rw-r--r--core/input/input_map.cpp30
-rw-r--r--core/io/compression.cpp9
-rw-r--r--core/io/config_file.cpp27
-rw-r--r--core/io/file_access_compressed.cpp33
-rw-r--r--core/io/file_access_encrypted.cpp22
-rw-r--r--core/io/file_access_memory.cpp8
-rw-r--r--core/io/file_access_network.cpp18
-rw-r--r--core/io/file_access_pack.cpp32
-rw-r--r--core/io/file_access_pack.h6
-rw-r--r--core/io/file_access_zip.cpp15
-rw-r--r--core/io/http_client.cpp32
-rw-r--r--core/io/image_loader.cpp15
-rw-r--r--core/io/ip.cpp16
-rw-r--r--core/io/ip_address.cpp15
-rw-r--r--core/io/ip_address.h25
-rw-r--r--core/io/json.cpp44
-rw-r--r--core/io/logger.cpp5
-rw-r--r--core/io/marshalls.cpp157
-rw-r--r--core/io/marshalls.h3
-rw-r--r--core/io/multiplayer_api.cpp57
-rw-r--r--core/io/net_socket.cpp3
-rw-r--r--core/io/packet_peer.cpp39
-rw-r--r--core/io/packet_peer_udp.cpp32
-rw-r--r--core/io/pck_packer.cpp11
-rw-r--r--core/io/resource_format_binary.cpp84
-rw-r--r--core/io/resource_importer.cpp21
-rw-r--r--core/io/resource_loader.cpp117
-rw-r--r--core/io/resource_loader.h6
-rw-r--r--core/io/resource_saver.cpp27
-rw-r--r--core/io/stream_peer.cpp15
-rw-r--r--core/io/stream_peer_ssl.cpp3
-rw-r--r--core/io/stream_peer_tcp.cpp9
-rw-r--r--core/io/tcp_server.cpp9
-rw-r--r--core/io/translation_loader_po.cpp32
-rw-r--r--core/io/udp_server.cpp9
-rw-r--r--core/io/xml_parser.cpp95
-rw-r--r--core/io/zip_io.cpp3
-rw-r--r--core/list.h70
-rw-r--r--core/local_vector.h6
-rw-r--r--core/map.h135
-rw-r--r--core/math/a_star.cpp44
-rw-r--r--core/math/aabb.cpp35
-rw-r--r--core/math/aabb.h96
-rw-r--r--core/math/basis.cpp31
-rw-r--r--core/math/camera_matrix.cpp21
-rw-r--r--core/math/delaunay_3d.h9
-rw-r--r--core/math/disjoint_set.h3
-rw-r--r--core/math/expression.cpp92
-rw-r--r--core/math/expression.h3
-rw-r--r--core/math/face3.cpp44
-rw-r--r--core/math/face3.h15
-rw-r--r--core/math/geometry.cpp132
-rw-r--r--core/math/geometry.h281
-rw-r--r--core/math/math_funcs.cpp14
-rw-r--r--core/math/math_funcs.h11
-rw-r--r--core/math/octree.h151
-rw-r--r--core/math/plane.cpp8
-rw-r--r--core/math/plane.h5
-rw-r--r--core/math/quat.cpp7
-rw-r--r--core/math/quick_hull.cpp38
-rw-r--r--core/math/random_number_generator.h5
-rw-r--r--core/math/rect2.cpp75
-rw-r--r--core/math/rect2.h95
-rw-r--r--core/math/transform_2d.cpp6
-rw-r--r--core/math/triangle_mesh.cpp65
-rw-r--r--core/math/triangulate.cpp35
-rw-r--r--core/math/vector3.cpp6
-rw-r--r--core/math/vector3.h20
-rw-r--r--core/math/vector3i.h20
-rw-r--r--core/message_queue.cpp30
-rw-r--r--core/method_bind.cpp3
-rw-r--r--core/method_bind.h13
-rw-r--r--core/node_path.cpp81
-rw-r--r--core/node_path.h3
-rw-r--r--core/object.cpp215
-rw-r--r--core/object.h52
-rw-r--r--core/os/dir_access.cpp29
-rw-r--r--core/os/dir_access.h3
-rw-r--r--core/os/file_access.cpp64
-rw-r--r--core/os/file_access.h3
-rw-r--r--core/os/main_loop.cpp12
-rw-r--r--core/os/memory.h18
-rw-r--r--core/os/os.cpp35
-rw-r--r--core/os/rw_lock.h12
-rw-r--r--core/os/semaphore.h3
-rw-r--r--core/os/thread.cpp9
-rw-r--r--core/os/threaded_array_processor.h3
-rw-r--r--core/packed_data_container.cpp25
-rw-r--r--core/pool_allocator.cpp36
-rw-r--r--core/pool_allocator.h3
-rw-r--r--core/print_string.cpp11
-rw-r--r--core/project_settings.cpp113
-rw-r--r--core/reference.cpp6
-rw-r--r--core/reference.h12
-rw-r--r--core/register_core_types.cpp3
-rw-r--r--core/resource.cpp42
-rw-r--r--core/ring_buffer.h9
-rw-r--r--core/safe_refcount.h18
-rw-r--r--core/script_language.cpp57
-rw-r--r--core/script_language.h3
-rw-r--r--core/self_list.h6
-rw-r--r--core/set.h123
-rw-r--r--core/sort_array.h66
-rw-r--r--core/string_buffer.h3
-rw-r--r--core/string_builder.cpp6
-rw-r--r--core/string_name.cpp42
-rw-r--r--core/string_name.h20
-rw-r--r--core/translation.cpp23
-rw-r--r--core/type_info.h3
-rw-r--r--core/typedefs.h3
-rw-r--r--core/undo_redo.cpp66
-rw-r--r--core/ustring.cpp757
-rw-r--r--core/ustring.h20
-rw-r--r--core/variant.cpp324
-rw-r--r--core/variant.h3
-rw-r--r--core/variant_call.cpp105
-rw-r--r--core/variant_op.cpp276
-rw-r--r--core/variant_parser.cpp208
-rw-r--r--core/vector.h12
-rw-r--r--core/vmap.h15
-rw-r--r--core/vset.h18
-rw-r--r--drivers/alsa/audio_driver_alsa.cpp15
-rw-r--r--drivers/alsamidi/midi_driver_alsamidi.cpp6
-rw-r--r--drivers/png/png_driver_common.cpp3
-rw-r--r--drivers/pulseaudio/audio_driver_pulseaudio.cpp9
-rw-r--r--drivers/register_driver_types.cpp3
-rw-r--r--drivers/unix/dir_access_unix.cpp49
-rw-r--r--drivers/unix/file_access_unix.cpp29
-rw-r--r--drivers/unix/ip_unix.cpp12
-rw-r--r--drivers/unix/net_socket_posix.cpp50
-rw-r--r--drivers/unix/os_unix.cpp50
-rw-r--r--drivers/unix/syslog_logger.cpp5
-rw-r--r--drivers/unix/thread_posix.cpp3
-rw-r--r--editor/animation_bezier_editor.cpp66
-rw-r--r--editor/animation_track_editor.cpp366
-rw-r--r--editor/animation_track_editor_plugins.cpp66
-rw-r--r--editor/array_property_edit.cpp21
-rw-r--r--editor/audio_stream_preview.cpp9
-rw-r--r--editor/code_editor.cpp110
-rw-r--r--editor/connections_dialog.cpp74
-rw-r--r--editor/create_dialog.cpp95
-rw-r--r--editor/debugger/editor_debugger_inspector.cpp14
-rw-r--r--editor/debugger/editor_debugger_node.cpp63
-rw-r--r--editor/debugger/editor_debugger_node.h3
-rw-r--r--editor/debugger/editor_debugger_tree.cpp18
-rw-r--r--editor/debugger/editor_profiler.cpp50
-rw-r--r--editor/debugger/editor_visual_profiler.cpp36
-rw-r--r--editor/debugger/script_editor_debugger.cpp110
-rw-r--r--editor/dependency_editor.cpp42
-rw-r--r--editor/dictionary_property_edit.cpp12
-rw-r--r--editor/doc_data.cpp183
-rw-r--r--editor/editor_about.cpp3
-rw-r--r--editor/editor_asset_installer.cpp15
-rw-r--r--editor/editor_atlas_packer.cpp11
-rw-r--r--editor/editor_audio_buses.cpp54
-rw-r--r--editor/editor_autoload_settings.cpp75
-rw-r--r--editor/editor_data.cpp166
-rw-r--r--editor/editor_data.h3
-rw-r--r--editor/editor_dir_dialog.cpp14
-rw-r--r--editor/editor_export.cpp71
-rw-r--r--editor/editor_feature_profile.cpp12
-rw-r--r--editor/editor_file_dialog.cpp131
-rw-r--r--editor/editor_file_system.cpp134
-rw-r--r--editor/editor_folding.cpp3
-rw-r--r--editor/editor_help.cpp148
-rw-r--r--editor/editor_help_search.cpp150
-rw-r--r--editor/editor_inspector.cpp188
-rw-r--r--editor/editor_layouts_dialog.cpp6
-rw-r--r--editor/editor_log.cpp6
-rw-r--r--editor/editor_node.cpp396
-rw-r--r--editor/editor_node.h8
-rw-r--r--editor/editor_path.cpp44
-rw-r--r--editor/editor_plugin.cpp15
-rw-r--r--editor/editor_plugin_settings.cpp6
-rw-r--r--editor/editor_properties.cpp130
-rw-r--r--editor/editor_properties_array_dict.cpp9
-rw-r--r--editor/editor_resource_preview.cpp11
-rw-r--r--editor/editor_run.cpp6
-rw-r--r--editor/editor_run_native.cpp15
-rw-r--r--editor/editor_sectioned_inspector.cpp51
-rw-r--r--editor/editor_settings.cpp69
-rw-r--r--editor/editor_settings.h5
-rw-r--r--editor/editor_spin_slider.cpp15
-rw-r--r--editor/editor_sub_scene.cpp18
-rw-r--r--editor/filesystem_dock.cpp112
-rw-r--r--editor/find_in_files.cpp37
-rw-r--r--editor/groups_editor.cpp24
-rw-r--r--editor/import/collada.cpp330
-rw-r--r--editor/import/collada.h36
-rw-r--r--editor/import/editor_import_collada.cpp142
-rw-r--r--editor/import/editor_scene_importer_gltf.cpp147
-rw-r--r--editor/import/resource_importer_bitmask.cpp3
-rw-r--r--editor/import/resource_importer_layered_texture.cpp3
-rw-r--r--editor/import/resource_importer_obj.cpp14
-rw-r--r--editor/import/resource_importer_scene.cpp158
-rw-r--r--editor/import/resource_importer_texture.cpp18
-rw-r--r--editor/import/resource_importer_texture_atlas.cpp5
-rw-r--r--editor/import/resource_importer_wav.cpp6
-rw-r--r--editor/import/resource_importer_wav.h17
-rw-r--r--editor/import_dock.cpp9
-rw-r--r--editor/inspector_dock.cpp33
-rw-r--r--editor/multi_node_edit.cpp36
-rw-r--r--editor/node_3d_editor_gizmos.cpp186
-rw-r--r--editor/node_dock.cpp5
-rw-r--r--editor/pane_drag.cpp6
-rw-r--r--editor/plugin_config_dialog.cpp3
-rw-r--r--editor/plugins/abstract_polygon_2d_editor.cpp49
-rw-r--r--editor/plugins/animation_blend_space_1d_editor.cpp18
-rw-r--r--editor/plugins/animation_blend_space_2d_editor.cpp21
-rw-r--r--editor/plugins/animation_blend_tree_editor_plugin.cpp21
-rw-r--r--editor/plugins/animation_player_editor_plugin.cpp139
-rw-r--r--editor/plugins/animation_state_machine_editor.cpp30
-rw-r--r--editor/plugins/animation_tree_editor_plugin.cpp12
-rw-r--r--editor/plugins/asset_library_editor_plugin.cpp24
-rw-r--r--editor/plugins/audio_stream_editor_plugin.cpp9
-rw-r--r--editor/plugins/baked_lightmap_editor_plugin.cpp3
-rw-r--r--editor/plugins/camera_3d_editor_plugin.cpp5
-rw-r--r--editor/plugins/canvas_item_editor_plugin.cpp365
-rw-r--r--editor/plugins/canvas_item_editor_plugin.h5
-rw-r--r--editor/plugins/collision_polygon_3d_editor_plugin.cpp42
-rw-r--r--editor/plugins/cpu_particles_2d_editor_plugin.cpp6
-rw-r--r--editor/plugins/curve_editor_plugin.cpp59
-rw-r--r--editor/plugins/debugger_editor_plugin.cpp21
-rw-r--r--editor/plugins/editor_preview_plugins.cpp42
-rw-r--r--editor/plugins/gi_probe_editor_plugin.cpp3
-rw-r--r--editor/plugins/gpu_particles_2d_editor_plugin.cpp16
-rw-r--r--editor/plugins/gpu_particles_3d_editor_plugin.cpp30
-rw-r--r--editor/plugins/gradient_editor_plugin.cpp3
-rw-r--r--editor/plugins/item_list_editor_plugin.cpp60
-rw-r--r--editor/plugins/light_occluder_2d_editor_plugin.cpp18
-rw-r--r--editor/plugins/material_editor_plugin.cpp3
-rw-r--r--editor/plugins/mesh_editor_plugin.cpp4
-rw-r--r--editor/plugins/mesh_instance_3d_editor_plugin.cpp29
-rw-r--r--editor/plugins/mesh_library_editor_plugin.cpp30
-rw-r--r--editor/plugins/multimesh_editor_plugin.cpp16
-rw-r--r--editor/plugins/navigation_polygon_editor_plugin.cpp13
-rw-r--r--editor/plugins/node_3d_editor_plugin.cpp583
-rw-r--r--editor/plugins/path_2d_editor_plugin.cpp48
-rw-r--r--editor/plugins/path_3d_editor_plugin.cpp71
-rw-r--r--editor/plugins/polygon_2d_editor_plugin.cpp92
-rw-r--r--editor/plugins/resource_preloader_editor_plugin.cpp39
-rw-r--r--editor/plugins/root_motion_editor_plugin.cpp6
-rw-r--r--editor/plugins/script_editor_plugin.cpp204
-rw-r--r--editor/plugins/script_text_editor.cpp111
-rw-r--r--editor/plugins/shader_editor_plugin.cpp24
-rw-r--r--editor/plugins/shader_file_editor_plugin.cpp6
-rw-r--r--editor/plugins/skeleton_ik_3d_editor_plugin.cpp14
-rw-r--r--editor/plugins/sprite_2d_editor_plugin.cpp26
-rw-r--r--editor/plugins/sprite_frames_editor_plugin.cpp107
-rw-r--r--editor/plugins/style_box_editor_plugin.cpp3
-rw-r--r--editor/plugins/text_editor.cpp3
-rw-r--r--editor/plugins/texture_editor_plugin.cpp15
-rw-r--r--editor/plugins/texture_layered_editor_plugin.cpp12
-rw-r--r--editor/plugins/texture_layered_editor_plugin.h4
-rw-r--r--editor/plugins/texture_region_editor_plugin.cpp197
-rw-r--r--editor/plugins/theme_editor_plugin.cpp27
-rw-r--r--editor/plugins/tile_map_editor_plugin.cpp217
-rw-r--r--editor/plugins/tile_set_editor_plugin.cpp215
-rw-r--r--editor/plugins/visual_shader_editor_plugin.cpp92
-rw-r--r--editor/progress_dialog.cpp21
-rw-r--r--editor/project_export.cpp128
-rw-r--r--editor/project_manager.cpp65
-rw-r--r--editor/project_settings_editor.cpp144
-rw-r--r--editor/property_editor.cpp140
-rw-r--r--editor/property_selector.cpp64
-rw-r--r--editor/pvrtc_compress.cpp8
-rw-r--r--editor/quick_open.cpp28
-rw-r--r--editor/rename_dialog.cpp9
-rw-r--r--editor/run_settings_dialog.cpp5
-rw-r--r--editor/scene_tree_dock.cpp312
-rw-r--r--editor/scene_tree_editor.cpp197
-rw-r--r--editor/script_create_dialog.cpp39
-rw-r--r--editor/settings_config_dialog.cpp32
-rw-r--r--main/main.cpp143
-rw-r--r--main/main_timer_sync.cpp19
-rw-r--r--main/performance.cpp3
-rw-r--r--main/tests/test_astar.cpp77
-rw-r--r--main/tests/test_gdscript.cpp105
-rw-r--r--main/tests/test_math.cpp9
-rw-r--r--main/tests/test_oa_hash_map.cpp6
-rw-r--r--main/tests/test_ordered_hash_map.cpp6
-rw-r--r--main/tests/test_physics_2d.cpp3
-rw-r--r--main/tests/test_render.cpp3
-rw-r--r--main/tests/test_shader_lang.cpp12
-rw-r--r--main/tests/test_string.cpp93
-rw-r--r--modules/assimp/editor_scene_importer_assimp.cpp3
-rw-r--r--modules/basis_universal/register_types.cpp3
-rw-r--r--modules/bmp/image_loader_bmp.cpp3
-rw-r--r--modules/bullet/area_bullet.cpp18
-rw-r--r--modules/bullet/btRayShape.cpp5
-rw-r--r--modules/bullet/bullet_physics_server.cpp24
-rw-r--r--modules/bullet/collision_object_bullet.cpp23
-rw-r--r--modules/bullet/godot_ray_world_algorithm.cpp7
-rw-r--r--modules/bullet/godot_ray_world_algorithm.h3
-rw-r--r--modules/bullet/godot_result_callbacks.cpp62
-rw-r--r--modules/bullet/godot_result_callbacks.h5
-rw-r--r--modules/bullet/rigid_body_bullet.cpp60
-rw-r--r--modules/bullet/shape_bullet.cpp18
-rw-r--r--modules/bullet/soft_body_bullet.cpp23
-rw-r--r--modules/bullet/space_bullet.cpp33
-rw-r--r--modules/bullet/space_bullet.h3
-rw-r--r--modules/csg/csg.cpp173
-rw-r--r--modules/csg/csg_gizmos.cpp32
-rw-r--r--modules/csg/csg_shape.cpp101
-rw-r--r--modules/cvtt/image_compress_cvtt.cpp14
-rw-r--r--modules/dds/texture_loader_dds.cpp35
-rw-r--r--modules/enet/networked_multiplayer_enet.cpp38
-rw-r--r--modules/enet/register_types.cpp3
-rw-r--r--modules/etc/image_etc.cpp10
-rw-r--r--modules/etc/texture_loader_pkm.cpp15
-rw-r--r--modules/gdnative/gdnative.cpp15
-rw-r--r--modules/gdnative/gdnative/gdnative.cpp6
-rw-r--r--modules/gdnative/gdnative_library_editor_plugin.cpp17
-rw-r--r--modules/gdnative/gdnative_library_singleton_editor.cpp12
-rw-r--r--modules/gdnative/nativescript/godot_nativescript.cpp6
-rw-r--r--modules/gdnative/nativescript/nativescript.cpp129
-rw-r--r--modules/gdnative/pluginscript/pluginscript_loader.cpp9
-rw-r--r--modules/gdnative/pluginscript/pluginscript_script.cpp33
-rw-r--r--modules/gdnative/register_types.cpp3
-rw-r--r--modules/gdnative/videodecoder/video_stream_gdnative.cpp18
-rw-r--r--modules/gdnative/videodecoder/video_stream_gdnative.h3
-rw-r--r--modules/gdnavigation/gd_navigation_server.cpp6
-rw-r--r--modules/gdnavigation/nav_map.cpp20
-rw-r--r--modules/gdnavigation/nav_region.cpp6
-rw-r--r--modules/gdnavigation/navigation_mesh_editor_plugin.cpp3
-rw-r--r--modules/gdnavigation/navigation_mesh_generator.cpp51
-rw-r--r--modules/gdscript/editor/gdscript_highlighter.cpp3
-rw-r--r--modules/gdscript/gdscript.cpp163
-rw-r--r--modules/gdscript/gdscript.h21
-rw-r--r--modules/gdscript/gdscript_compiler.cpp293
-rw-r--r--modules/gdscript/gdscript_compiler.h9
-rw-r--r--modules/gdscript/gdscript_editor.cpp51
-rw-r--r--modules/gdscript/gdscript_function.cpp55
-rw-r--r--modules/gdscript/gdscript_function.h3
-rw-r--r--modules/gdscript/gdscript_functions.cpp14
-rw-r--r--modules/gdscript/gdscript_parser.cpp273
-rw-r--r--modules/gdscript/gdscript_parser.h6
-rw-r--r--modules/gdscript/gdscript_tokenizer.cpp51
-rw-r--r--modules/gdscript/language_server/gdscript_extend_parser.cpp12
-rw-r--r--modules/gdscript/language_server/gdscript_language_protocol.cpp10
-rw-r--r--modules/gdscript/language_server/gdscript_workspace.cpp9
-rw-r--r--modules/gdscript/language_server/lsp.hpp33
-rw-r--r--modules/gdscript/register_types.cpp19
-rw-r--r--modules/gridmap/grid_map.cpp85
-rw-r--r--modules/gridmap/grid_map_editor_plugin.cpp119
-rw-r--r--modules/hdr/image_loader_hdr.cpp9
-rw-r--r--modules/jpg/image_loader_jpegd.cpp11
-rw-r--r--modules/jsonrpc/jsonrpc.cpp3
-rw-r--r--modules/mbedtls/packet_peer_mbed_dtls.cpp16
-rw-r--r--modules/mbedtls/ssl_context_mbedtls.cpp18
-rw-r--r--modules/mbedtls/stream_peer_mbedtls.cpp12
-rw-r--r--modules/mobile_vr/mobile_vr_interface.cpp18
-rw-r--r--modules/opensimplex/noise_texture.cpp24
-rw-r--r--modules/opensimplex/open_simplex_noise.cpp15
-rw-r--r--modules/pvr/texture_loader_pvr.cpp62
-rw-r--r--modules/regex/regex.cpp51
-rw-r--r--modules/squish/image_compress_squish.cpp8
-rw-r--r--modules/stb_vorbis/audio_stream_ogg_vorbis.cpp3
-rw-r--r--modules/tga/image_loader_tga.cpp9
-rw-r--r--modules/theora/video_stream_theora.cpp31
-rw-r--r--modules/tinyexr/image_loader_tinyexr.cpp3
-rw-r--r--modules/visual_script/register_types.cpp3
-rw-r--r--modules/visual_script/visual_script.cpp156
-rw-r--r--modules/visual_script/visual_script.h18
-rw-r--r--modules/visual_script/visual_script_builtin_funcs.cpp135
-rw-r--r--modules/visual_script/visual_script_editor.cpp308
-rw-r--r--modules/visual_script/visual_script_expression.cpp86
-rw-r--r--modules/visual_script/visual_script_expression.h3
-rw-r--r--modules/visual_script/visual_script_flow_control.cpp71
-rw-r--r--modules/visual_script/visual_script_func_nodes.cpp218
-rw-r--r--modules/visual_script/visual_script_nodes.cpp204
-rw-r--r--modules/visual_script/visual_script_property_selector.cpp65
-rw-r--r--modules/visual_script/visual_script_yield_nodes.cpp79
-rw-r--r--modules/webm/video_stream_webm.cpp60
-rw-r--r--modules/webp/image_loader_webp.cpp5
-rw-r--r--modules/webrtc/webrtc_multiplayer.cpp32
-rw-r--r--modules/webrtc/webrtc_multiplayer.h3
-rw-r--r--modules/webrtc/webrtc_peer_connection.cpp3
-rw-r--r--modules/websocket/editor_debugger_server_websocket.cpp3
-rw-r--r--modules/websocket/remote_debugger_peer_websocket.cpp3
-rw-r--r--modules/websocket/websocket_client.cpp3
-rw-r--r--modules/websocket/websocket_multiplayer_peer.cpp21
-rw-r--r--modules/websocket/websocket_server.cpp3
-rw-r--r--modules/websocket/wsl_client.cpp27
-rw-r--r--modules/websocket/wsl_peer.cpp23
-rw-r--r--modules/websocket/wsl_server.cpp45
-rw-r--r--platform/android/export/export.cpp61
-rw-r--r--platform/iphone/export/export.cpp39
-rw-r--r--platform/javascript/export/export.cpp22
-rw-r--r--platform/linuxbsd/crash_handler_linuxbsd.cpp9
-rw-r--r--platform/linuxbsd/display_server_x11.cpp141
-rw-r--r--platform/linuxbsd/godot_linuxbsd.cpp3
-rw-r--r--platform/linuxbsd/joypad_linux.cpp28
-rw-r--r--platform/linuxbsd/key_mapping_x11.cpp46
-rw-r--r--platform/linuxbsd/os_linuxbsd.cpp21
-rw-r--r--platform/osx/export/export.cpp23
-rw-r--r--platform/uwp/export/export.cpp93
-rw-r--r--scene/2d/animated_sprite_2d.cpp101
-rw-r--r--scene/2d/animated_sprite_2d.h12
-rw-r--r--scene/2d/area_2d.cpp61
-rw-r--r--scene/2d/area_2d.h10
-rw-r--r--scene/2d/audio_stream_player_2d.cpp26
-rw-r--r--scene/2d/camera_2d.cpp58
-rw-r--r--scene/2d/canvas_modulate.cpp3
-rw-r--r--scene/2d/collision_object_2d.cpp43
-rw-r--r--scene/2d/collision_polygon_2d.cpp14
-rw-r--r--scene/2d/collision_shape_2d.cpp15
-rw-r--r--scene/2d/cpu_particles_2d.cpp53
-rw-r--r--scene/2d/gpu_particles_2d.cpp21
-rw-r--r--scene/2d/joints_2d.cpp51
-rw-r--r--scene/2d/light_2d.cpp14
-rw-r--r--scene/2d/light_occluder_2d.cpp25
-rw-r--r--scene/2d/line_2d.cpp18
-rw-r--r--scene/2d/line_builder.cpp46
-rw-r--r--scene/2d/mesh_instance_2d.cpp3
-rw-r--r--scene/2d/multimesh_instance_2d.cpp3
-rw-r--r--scene/2d/navigation_agent_2d.cpp20
-rw-r--r--scene/2d/navigation_obstacle_2d.cpp11
-rw-r--r--scene/2d/navigation_region_2d.cpp43
-rw-r--r--scene/2d/node_2d.cpp70
-rw-r--r--scene/2d/parallax_background.cpp21
-rw-r--r--scene/2d/parallax_layer.cpp15
-rw-r--r--scene/2d/path_2d.cpp32
-rw-r--r--scene/2d/physics_body_2d.cpp58
-rw-r--r--scene/2d/physics_body_2d.h3
-rw-r--r--scene/2d/polygon_2d.cpp25
-rw-r--r--scene/2d/position_2d.cpp6
-rw-r--r--scene/2d/ray_cast_2d.cpp59
-rw-r--r--scene/2d/remote_transform_2d.cpp37
-rw-r--r--scene/2d/skeleton_2d.cpp27
-rw-r--r--scene/2d/sprite_2d.cpp57
-rw-r--r--scene/2d/tile_map.cpp148
-rw-r--r--scene/2d/touch_screen_button.cpp65
-rw-r--r--scene/2d/visibility_notifier_2d.cpp44
-rw-r--r--scene/3d/area_3d.cpp58
-rw-r--r--scene/3d/area_3d.h10
-rw-r--r--scene/3d/audio_stream_player_3d.cpp35
-rw-r--r--scene/3d/baked_lightmap.cpp9
-rw-r--r--scene/3d/bone_attachment_3d.cpp9
-rw-r--r--scene/3d/camera_3d.cpp71
-rw-r--r--scene/3d/collision_object_3d.cpp24
-rw-r--r--scene/3d/collision_polygon_3d.cpp12
-rw-r--r--scene/3d/collision_shape_3d.cpp15
-rw-r--r--scene/3d/cpu_particles_3d.cpp47
-rw-r--r--scene/3d/gi_probe.cpp9
-rw-r--r--scene/3d/gpu_particles_3d.cpp24
-rw-r--r--scene/3d/immediate_geometry_3d.cpp3
-rw-r--r--scene/3d/light_3d.cpp6
-rw-r--r--scene/3d/listener_3d.cpp18
-rw-r--r--scene/3d/mesh_instance_3d.cpp61
-rw-r--r--scene/3d/multimesh_instance_3d.cpp10
-rw-r--r--scene/3d/navigation_agent_3d.cpp20
-rw-r--r--scene/3d/navigation_obstacle_3d.cpp11
-rw-r--r--scene/3d/navigation_region_3d.cpp18
-rw-r--r--scene/3d/node_3d.cpp85
-rw-r--r--scene/3d/path_3d.cpp39
-rw-r--r--scene/3d/physics_body_3d.cpp206
-rw-r--r--scene/3d/physics_body_3d.h5
-rw-r--r--scene/3d/physics_joint_3d.cpp68
-rw-r--r--scene/3d/proximity_group_3d.cpp3
-rw-r--r--scene/3d/ray_cast_3d.cpp79
-rw-r--r--scene/3d/remote_transform_3d.cpp27
-rw-r--r--scene/3d/skeleton_3d.cpp64
-rw-r--r--scene/3d/skeleton_ik_3d.cpp42
-rw-r--r--scene/3d/soft_body_3d.cpp51
-rw-r--r--scene/3d/spring_arm_3d.cpp3
-rw-r--r--scene/3d/sprite_3d.cpp130
-rw-r--r--scene/3d/vehicle_body_3d.cpp27
-rw-r--r--scene/3d/velocity_tracker_3d.cpp3
-rw-r--r--scene/3d/visibility_notifier_3d.cpp28
-rw-r--r--scene/3d/visual_instance_3d.cpp3
-rw-r--r--scene/3d/voxelizer.cpp44
-rw-r--r--scene/3d/world_environment.cpp3
-rw-r--r--scene/3d/xr_nodes.cpp15
-rw-r--r--scene/animation/animation_blend_space_2d.cpp18
-rw-r--r--scene/animation/animation_blend_tree.cpp21
-rw-r--r--scene/animation/animation_cache.cpp30
-rw-r--r--scene/animation/animation_node_state_machine.cpp9
-rw-r--r--scene/animation/animation_player.cpp174
-rw-r--r--scene/animation/animation_player.h5
-rw-r--r--scene/animation/animation_tree.cpp39
-rw-r--r--scene/animation/tween.cpp197
-rw-r--r--scene/audio/audio_stream_player.cpp11
-rw-r--r--scene/debugger/scene_debugger.cpp210
-rw-r--r--scene/gui/base_button.cpp32
-rw-r--r--scene/gui/box_container.cpp46
-rw-r--r--scene/gui/button.cpp68
-rw-r--r--scene/gui/center_container.cpp18
-rw-r--r--scene/gui/check_box.cpp17
-rw-r--r--scene/gui/check_button.cpp14
-rw-r--r--scene/gui/color_picker.cpp97
-rw-r--r--scene/gui/container.cpp21
-rw-r--r--scene/gui/control.cpp224
-rw-r--r--scene/gui/control.h3
-rw-r--r--scene/gui/dialogs.cpp21
-rw-r--r--scene/gui/file_dialog.cpp93
-rw-r--r--scene/gui/gradient_edit.cpp39
-rw-r--r--scene/gui/graph_edit.cpp117
-rw-r--r--scene/gui/graph_node.cpp138
-rw-r--r--scene/gui/grid_container.cpp38
-rw-r--r--scene/gui/item_list.cpp88
-rw-r--r--scene/gui/label.cpp61
-rw-r--r--scene/gui/line_edit.cpp183
-rw-r--r--scene/gui/link_button.cpp5
-rw-r--r--scene/gui/margin_container.cpp21
-rw-r--r--scene/gui/menu_button.cpp9
-rw-r--r--scene/gui/nine_patch_rect.cpp9
-rw-r--r--scene/gui/option_button.cpp33
-rw-r--r--scene/gui/panel_container.cpp30
-rw-r--r--scene/gui/popup.cpp12
-rw-r--r--scene/gui/popup_menu.cpp148
-rw-r--r--scene/gui/range.cpp24
-rw-r--r--scene/gui/reference_rect.cpp6
-rw-r--r--scene/gui/rich_text_label.cpp330
-rw-r--r--scene/gui/scroll_bar.cpp57
-rw-r--r--scene/gui/scroll_container.cpp76
-rw-r--r--scene/gui/shortcut.cpp5
-rw-r--r--scene/gui/slider.cpp34
-rw-r--r--scene/gui/spin_box.cpp9
-rw-r--r--scene/gui/split_container.cpp63
-rw-r--r--scene/gui/subviewport_container.cpp49
-rw-r--r--scene/gui/tab_container.cpp161
-rw-r--r--scene/gui/tabs.cpp94
-rw-r--r--scene/gui/text_edit.cpp729
-rw-r--r--scene/gui/texture_button.cpp42
-rw-r--r--scene/gui/texture_progress.cpp66
-rw-r--r--scene/gui/tree.cpp426
-rw-r--r--scene/gui/video_player.cpp65
-rw-r--r--scene/main/canvas_item.cpp129
-rw-r--r--scene/main/canvas_item.h6
-rw-r--r--scene/main/canvas_layer.cpp38
-rw-r--r--scene/main/http_request.cpp21
-rw-r--r--scene/main/instance_placeholder.cpp20
-rw-r--r--scene/main/node.cpp417
-rw-r--r--scene/main/scene_tree.cpp192
-rw-r--r--scene/main/timer.cpp25
-rw-r--r--scene/main/viewport.cpp293
-rw-r--r--scene/main/window.cpp9
-rw-r--r--scene/resources/animation.cpp343
-rw-r--r--scene/resources/audio_stream_sample.cpp56
-rw-r--r--scene/resources/bit_map.cpp43
-rw-r--r--scene/resources/capsule_shape_2d.cpp6
-rw-r--r--scene/resources/concave_polygon_shape_2d.cpp17
-rw-r--r--scene/resources/concave_polygon_shape_3d.h5
-rw-r--r--scene/resources/convex_polygon_shape_2d.cpp5
-rw-r--r--scene/resources/curve.cpp191
-rw-r--r--scene/resources/default_theme/default_theme.cpp3
-rw-r--r--scene/resources/dynamic_font.cpp113
-rw-r--r--scene/resources/environment.cpp8
-rw-r--r--scene/resources/font.cpp102
-rw-r--r--scene/resources/gradient.cpp6
-rw-r--r--scene/resources/gradient.h12
-rw-r--r--scene/resources/height_map_shape_3d.cpp6
-rw-r--r--scene/resources/line_shape_2d.cpp3
-rw-r--r--scene/resources/material.cpp65
-rw-r--r--scene/resources/mesh.cpp87
-rw-r--r--scene/resources/mesh_data_tool.cpp72
-rw-r--r--scene/resources/mesh_library.cpp41
-rw-r--r--scene/resources/multimesh.cpp41
-rw-r--r--scene/resources/navigation_mesh.cpp17
-rw-r--r--scene/resources/packed_scene.cpp99
-rw-r--r--scene/resources/particles_material.cpp120
-rw-r--r--scene/resources/polygon_path_finder.cpp27
-rw-r--r--scene/resources/polygon_path_finder.h5
-rw-r--r--scene/resources/primitive_meshes.cpp8
-rw-r--r--scene/resources/resource_format_text.cpp78
-rw-r--r--scene/resources/segment_shape_2d.cpp3
-rw-r--r--scene/resources/shader.cpp17
-rw-r--r--scene/resources/shader.h6
-rw-r--r--scene/resources/shape_2d.cpp6
-rw-r--r--scene/resources/shape_3d.cpp3
-rw-r--r--scene/resources/sky.cpp3
-rw-r--r--scene/resources/style_box.cpp26
-rw-r--r--scene/resources/surface_tool.cpp91
-rw-r--r--scene/resources/texture.cpp164
-rw-r--r--scene/resources/theme.cpp61
-rw-r--r--scene/resources/tile_set.cpp190
-rw-r--r--scene/resources/visual_shader.cpp45
-rw-r--r--scene/resources/visual_shader_nodes.cpp91
-rw-r--r--scene/resources/world_2d.cpp21
-rw-r--r--scene/resources/world_3d.cpp27
-rw-r--r--servers/audio/audio_driver_dummy.cpp9
-rw-r--r--servers/audio/audio_filter_sw.cpp23
-rw-r--r--servers/audio/audio_rb_resampler.cpp15
-rw-r--r--servers/audio/audio_stream.cpp6
-rw-r--r--servers/audio/effects/audio_effect_chorus.cpp3
-rw-r--r--servers/audio/effects/audio_effect_compressor.cpp9
-rw-r--r--servers/audio/effects/audio_effect_delay.cpp3
-rw-r--r--servers/audio/effects/audio_effect_distortion.cpp5
-rw-r--r--servers/audio/effects/audio_effect_filter.cpp18
-rw-r--r--servers/audio/effects/audio_effect_filter.h9
-rw-r--r--servers/audio/effects/audio_effect_pitch_shift.cpp26
-rw-r--r--servers/audio/effects/audio_effect_spectrum_analyzer.cpp3
-rw-r--r--servers/audio/effects/eq.cpp11
-rw-r--r--servers/audio/effects/reverb.cpp53
-rw-r--r--servers/audio_server.cpp70
-rw-r--r--servers/physics_2d/area_2d_sw.cpp39
-rw-r--r--servers/physics_2d/area_2d_sw.h18
-rw-r--r--servers/physics_2d/area_pair_2d_sw.cpp39
-rw-r--r--servers/physics_2d/body_2d_sw.cpp90
-rw-r--r--servers/physics_2d/body_2d_sw.h15
-rw-r--r--servers/physics_2d/body_pair_2d_sw.cpp45
-rw-r--r--servers/physics_2d/broad_phase_2d_basic.cpp15
-rw-r--r--servers/physics_2d/broad_phase_2d_hash_grid.cpp124
-rw-r--r--servers/physics_2d/collision_object_2d_sw.cpp27
-rw-r--r--servers/physics_2d/collision_solver_2d_sat.cpp354
-rw-r--r--servers/physics_2d/collision_solver_2d_sw.cpp36
-rw-r--r--servers/physics_2d/joints_2d_sw.cpp36
-rw-r--r--servers/physics_2d/physics_server_2d_sw.cpp38
-rw-r--r--servers/physics_2d/physics_server_2d_wrap_mt.cpp5
-rw-r--r--servers/physics_2d/physics_server_2d_wrap_mt.h7
-rw-r--r--servers/physics_2d/shape_2d_sw.cpp65
-rw-r--r--servers/physics_2d/shape_2d_sw.h15
-rw-r--r--servers/physics_2d/space_2d_sw.cpp146
-rw-r--r--servers/physics_2d/space_2d_sw.h3
-rw-r--r--servers/physics_2d/step_2d_sw.cpp18
-rw-r--r--servers/physics_3d/area_3d_sw.cpp39
-rw-r--r--servers/physics_3d/area_3d_sw.h18
-rw-r--r--servers/physics_3d/area_pair_3d_sw.cpp39
-rw-r--r--servers/physics_3d/body_3d_sw.cpp84
-rw-r--r--servers/physics_3d/body_3d_sw.h15
-rw-r--r--servers/physics_3d/body_pair_3d_sw.cpp16
-rw-r--r--servers/physics_3d/broad_phase_3d_basic.cpp18
-rw-r--r--servers/physics_3d/broad_phase_octree.cpp6
-rw-r--r--servers/physics_3d/collision_object_3d_sw.cpp15
-rw-r--r--servers/physics_3d/collision_object_3d_sw.h3
-rw-r--r--servers/physics_3d/collision_solver_3d_sat.cpp249
-rw-r--r--servers/physics_3d/collision_solver_3d_sw.cpp54
-rw-r--r--servers/physics_3d/gjk_epa.cpp85
-rw-r--r--servers/physics_3d/joints/generic_6dof_joint_3d_sw.cpp16
-rw-r--r--servers/physics_3d/joints/pin_joint_3d_sw.cpp6
-rw-r--r--servers/physics_3d/physics_server_3d_sw.cpp41
-rw-r--r--servers/physics_3d/shape_3d_sw.cpp100
-rw-r--r--servers/physics_3d/space_3d_sw.cpp128
-rw-r--r--servers/physics_3d/space_3d_sw.h3
-rw-r--r--servers/physics_3d/step_3d_sw.cpp18
-rw-r--r--servers/physics_server_2d.cpp41
-rw-r--r--servers/physics_server_3d.cpp27
-rw-r--r--servers/rendering/rasterizer.h12
-rw-r--r--servers/rendering/rasterizer_rd/rasterizer_scene_high_end_rd.cpp6
-rw-r--r--servers/rendering/rasterizer_rd/rasterizer_scene_high_end_rd.h9
-rw-r--r--servers/rendering/rasterizer_rd/rasterizer_scene_rd.cpp18
-rw-r--r--servers/rendering/rasterizer_rd/rasterizer_storage_rd.cpp53
-rw-r--r--servers/rendering/rasterizer_rd/shader_compiler_rd.cpp30
-rw-r--r--servers/rendering/rendering_server_canvas.cpp47
-rw-r--r--servers/rendering/rendering_server_canvas.h9
-rw-r--r--servers/rendering/rendering_server_raster.cpp15
-rw-r--r--servers/rendering/rendering_server_scene.cpp107
-rw-r--r--servers/rendering/rendering_server_scene.h6
-rw-r--r--servers/rendering/rendering_server_viewport.cpp12
-rw-r--r--servers/rendering/rendering_server_viewport.h3
-rw-r--r--servers/rendering/shader_language.cpp228
-rw-r--r--servers/rendering/shader_language.h3
-rw-r--r--servers/rendering_server.cpp50
683 files changed, 22790 insertions, 12212 deletions
diff --git a/.clang-tidy b/.clang-tidy
index e6ee412ead..59d0facb96 100644
--- a/.clang-tidy
+++ b/.clang-tidy
@@ -1,5 +1,5 @@
---
-Checks: 'clang-diagnostic-*,clang-analyzer-*,-*,modernize-redundant-void-arg,modernize-use-bool-literals,modernize-use-default-member-init,modernize-use-nullptr'
+Checks: 'clang-diagnostic-*,clang-analyzer-*,-*,modernize-redundant-void-arg,modernize-use-bool-literals,modernize-use-default-member-init,modernize-use-nullptr,readability-braces-around-statements'
WarningsAsErrors: ''
HeaderFilterRegex: '.*'
AnalyzeTemporaryDtors: false
@@ -14,8 +14,6 @@ CheckOptions:
value: '1'
- key: cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
value: '1'
- - key: google-readability-braces-around-statements.ShortStatementLines
- value: '1'
- key: google-readability-function-size.StatementThreshold
value: '800'
- key: google-readability-namespace-comments.ShortNamespaceLines
@@ -40,5 +38,7 @@ CheckOptions:
value: '1'
- key: modernize-use-nullptr.NullMacros
value: 'NULL'
+ - key: readability-braces-around-statements.ShortStatementLines
+ value: '0'
...
diff --git a/core/array.cpp b/core/array.cpp
index 1a8a833404..d1c0688e63 100644
--- a/core/array.cpp
+++ b/core/array.cpp
@@ -50,8 +50,9 @@ void Array::_ref(const Array &p_from) const {
ERR_FAIL_COND(!_fp); // should NOT happen.
- if (_fp == _p)
+ if (_fp == _p) {
return; // whatever it is, nothing to do here move along
+ }
bool success = _fp->refcount.ref();
@@ -63,8 +64,9 @@ void Array::_ref(const Array &p_from) const {
}
void Array::_unref() const {
- if (!_p)
+ if (!_p) {
return;
+ }
if (_p->refcount.unref()) {
memdelete(_p);
@@ -189,8 +191,9 @@ int Array::find(const Variant &p_value, int p_from) const {
}
int Array::rfind(const Variant &p_value, int p_from) const {
- if (_p->array.size() == 0)
+ if (_p->array.size() == 0) {
return -1;
+ }
ERR_FAIL_COND_V(!_p->typed.validate(p_value, "rfind"), -1);
if (p_from < 0) {
@@ -218,8 +221,9 @@ int Array::find_last(const Variant &p_value) const {
int Array::count(const Variant &p_value) const {
ERR_FAIL_COND_V(!_p->typed.validate(p_value, "count"), 0);
- if (_p->array.size() == 0)
+ if (_p->array.size() == 0) {
return 0;
+ }
int amount = 0;
for (int i = 0; i < _p->array.size(); i++) {
@@ -278,14 +282,17 @@ Array Array::slice(int p_begin, int p_end, int p_step, bool p_deep) const { // l
ERR_FAIL_COND_V_MSG(p_step == 0, new_arr, "Array slice step size cannot be zero.");
- if (empty()) // Don't try to slice empty arrays.
+ if (empty()) { // Don't try to slice empty arrays.
return new_arr;
+ }
if (p_step > 0) {
- if (p_begin >= size() || p_end < -size())
+ if (p_begin >= size() || p_end < -size()) {
return new_arr;
+ }
} else { // p_step < 0
- if (p_begin < -size() || p_end >= size())
+ if (p_begin < -size() || p_end >= size()) {
return new_arr;
+ }
}
int begin = _clamp_slice_index(p_begin);
@@ -316,8 +323,9 @@ struct _ArrayVariantSort {
bool valid = false;
Variant res;
Variant::evaluate(Variant::OP_LESS, p_l, p_r, res, valid);
- if (!valid)
+ if (!valid) {
res = false;
+ }
return res;
}
};
@@ -335,8 +343,9 @@ struct _ArrayVariantSortCustom {
const Variant *args[2] = { &p_l, &p_r };
Callable::CallError err;
bool res = obj->call(func, args, 2, err);
- if (err.error != Callable::CallError::CALL_OK)
+ if (err.error != Callable::CallError::CALL_OK) {
res = false;
+ }
return res;
}
};
@@ -352,8 +361,9 @@ Array &Array::sort_custom(Object *p_obj, const StringName &p_function) {
void Array::shuffle() {
const int n = _p->array.size();
- if (n < 2)
+ if (n < 2) {
return;
+ }
Variant *data = _p->array.ptrw();
for (int i = n - 1; i >= 1; i--) {
const int j = Math::rand() % (i + 1);
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp
index 7c7ef4e03c..607e17eae4 100644
--- a/core/bind/core_bind.cpp
+++ b/core/bind/core_bind.cpp
@@ -230,18 +230,20 @@ int _OS::execute(const String &p_path, const Vector<String> &p_arguments, bool p
OS::ProcessID pid = -2;
int exitcode = 0;
List<String> args;
- for (int i = 0; i < p_arguments.size(); i++)
+ for (int i = 0; i < p_arguments.size(); i++) {
args.push_back(p_arguments[i]);
+ }
String pipe;
Error err = OS::get_singleton()->execute(p_path, args, p_blocking, &pid, &pipe, &exitcode, p_read_stderr);
p_output.clear();
p_output.push_back(pipe);
- if (err != OK)
+ if (err != OK) {
return -1;
- else if (p_blocking)
+ } else if (p_blocking) {
return exitcode;
- else
+ } else {
return pid;
+ }
}
Error _OS::kill(int p_pid) {
@@ -564,8 +566,9 @@ void _OS::print_all_textures_by_size() {
ResourceCache::get_cached_resources(&rsrc);
for (List<Ref<Resource>>::Element *E = rsrc.front(); E; E = E->next()) {
- if (!E->get()->is_class("ImageTexture"))
+ if (!E->get()->is_class("ImageTexture")) {
continue;
+ }
Size2 size = E->get()->call("get_size");
int fmt = E->get()->call("get_format");
@@ -603,11 +606,13 @@ void _OS::print_resources_by_type(const Vector<String> &p_types) {
bool found = false;
for (int i = 0; i < p_types.size(); i++) {
- if (r->is_class(p_types[i]))
+ if (r->is_class(p_types[i])) {
found = true;
+ }
}
- if (!found)
+ if (!found) {
continue;
+ }
if (!type_count.has(r->get_class())) {
type_count[r->get_class()] = 0;
@@ -889,18 +894,20 @@ Vector3 _Geometry::get_closest_point_to_segment_uncapped(const Vector3 &p_point,
Variant _Geometry::ray_intersects_triangle(const Vector3 &p_from, const Vector3 &p_dir, const Vector3 &p_v0, const Vector3 &p_v1, const Vector3 &p_v2) {
Vector3 res;
- if (Geometry::ray_intersects_triangle(p_from, p_dir, p_v0, p_v1, p_v2, &res))
+ if (Geometry::ray_intersects_triangle(p_from, p_dir, p_v0, p_v1, p_v2, &res)) {
return res;
- else
+ } else {
return Variant();
+ }
}
Variant _Geometry::segment_intersects_triangle(const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_v0, const Vector3 &p_v1, const Vector3 &p_v2) {
Vector3 res;
- if (Geometry::segment_intersects_triangle(p_from, p_to, p_v0, p_v1, p_v2, &res))
+ if (Geometry::segment_intersects_triangle(p_from, p_to, p_v0, p_v1, p_v2, &res)) {
return res;
- else
+ } else {
return Variant();
+ }
}
bool _Geometry::point_is_inside_triangle(const Vector2 &s, const Vector2 &a, const Vector2 &b, const Vector2 &c) const {
@@ -910,8 +917,9 @@ bool _Geometry::point_is_inside_triangle(const Vector2 &s, const Vector2 &a, con
Vector<Vector3> _Geometry::segment_intersects_sphere(const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_sphere_pos, real_t p_sphere_radius) {
Vector<Vector3> r;
Vector3 res, norm;
- if (!Geometry::segment_intersects_sphere(p_from, p_to, p_sphere_pos, p_sphere_radius, &res, &norm))
+ if (!Geometry::segment_intersects_sphere(p_from, p_to, p_sphere_pos, p_sphere_radius, &res, &norm)) {
return r;
+ }
r.resize(2);
r.set(0, res);
@@ -922,8 +930,9 @@ Vector<Vector3> _Geometry::segment_intersects_sphere(const Vector3 &p_from, cons
Vector<Vector3> _Geometry::segment_intersects_cylinder(const Vector3 &p_from, const Vector3 &p_to, float p_height, float p_radius) {
Vector<Vector3> r;
Vector3 res, norm;
- if (!Geometry::segment_intersects_cylinder(p_from, p_to, p_height, p_radius, &res, &norm))
+ if (!Geometry::segment_intersects_cylinder(p_from, p_to, p_height, p_radius, &res, &norm)) {
return r;
+ }
r.resize(2);
r.set(0, res);
@@ -934,8 +943,9 @@ Vector<Vector3> _Geometry::segment_intersects_cylinder(const Vector3 &p_from, co
Vector<Vector3> _Geometry::segment_intersects_convex(const Vector3 &p_from, const Vector3 &p_to, const Vector<Plane> &p_planes) {
Vector<Vector3> r;
Vector3 res, norm;
- if (!Geometry::segment_intersects_convex(p_from, p_to, p_planes.ptr(), p_planes.size(), &res, &norm))
+ if (!Geometry::segment_intersects_convex(p_from, p_to, p_planes.ptr(), p_planes.size(), &res, &norm)) {
return r;
+ }
r.resize(2);
r.set(0, res);
@@ -1151,8 +1161,9 @@ void _Geometry::_bind_methods() {
Error _File::open_encrypted(const String &p_path, ModeFlags p_mode_flags, const Vector<uint8_t> &p_key) {
Error err = open(p_path, p_mode_flags);
- if (err)
+ if (err) {
return err;
+ }
FileAccessEncrypted *fae = memnew(FileAccessEncrypted);
err = fae->open_and_parse(f, p_key, (p_mode_flags == WRITE) ? FileAccessEncrypted::MODE_WRITE_AES256 : FileAccessEncrypted::MODE_READ);
@@ -1167,8 +1178,9 @@ Error _File::open_encrypted(const String &p_path, ModeFlags p_mode_flags, const
Error _File::open_encrypted_pass(const String &p_path, ModeFlags p_mode_flags, const String &p_pass) {
Error err = open(p_path, p_mode_flags);
- if (err)
+ if (err) {
return err;
+ }
FileAccessEncrypted *fae = memnew(FileAccessEncrypted);
err = fae->open_and_parse_password(f, p_pass, (p_mode_flags == WRITE) ? FileAccessEncrypted::MODE_WRITE_AES256 : FileAccessEncrypted::MODE_READ);
@@ -1202,14 +1214,16 @@ Error _File::open(const String &p_path, ModeFlags p_mode_flags) {
close();
Error err;
f = FileAccess::open(p_path, p_mode_flags, &err);
- if (f)
+ if (f) {
f->set_endian_swap(eswap);
+ }
return err;
}
void _File::close() {
- if (f)
+ if (f) {
memdelete(f);
+ }
f = nullptr;
}
@@ -1292,8 +1306,9 @@ Vector<uint8_t> _File::get_buffer(int p_length) const {
ERR_FAIL_COND_V_MSG(!f, data, "File must be opened before use.");
ERR_FAIL_COND_V_MSG(p_length < 0, data, "Length of buffer cannot be smaller than 0.");
- if (p_length == 0)
+ if (p_length == 0) {
return data;
+ }
Error err = data.resize(p_length);
ERR_FAIL_COND_V_MSG(err != OK, data, "Can't resize data to " + itos(p_length) + " elements.");
@@ -1302,8 +1317,9 @@ Vector<uint8_t> _File::get_buffer(int p_length) const {
int len = f->get_buffer(&w[0], p_length);
ERR_FAIL_COND_V(len < 0, Vector<uint8_t>());
- if (len < p_length)
+ if (len < p_length) {
data.resize(p_length);
+ }
return data;
}
@@ -1352,8 +1368,9 @@ Vector<String> _File::get_csv_line(const String &p_delim) const {
void _File::set_endian_swap(bool p_swap) {
eswap = p_swap;
- if (f)
+ if (f) {
f->set_endian_swap(p_swap);
+ }
}
bool _File::get_endian_swap() {
@@ -1361,8 +1378,9 @@ bool _File::get_endian_swap() {
}
Error _File::get_error() const {
- if (!f)
+ if (!f) {
return ERR_UNCONFIGURED;
+ }
return f->get_error();
}
@@ -1440,8 +1458,9 @@ void _File::store_buffer(const Vector<uint8_t> &p_buffer) {
ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
int len = p_buffer.size();
- if (len == 0)
+ if (len == 0) {
return;
+ }
const uint8_t *r = p_buffer.ptr();
@@ -1554,8 +1573,9 @@ void _File::_bind_methods() {
}
_File::~_File() {
- if (f)
+ if (f) {
memdelete(f);
+ }
}
////// _Directory //////
@@ -1564,10 +1584,12 @@ Error _Directory::open(const String &p_path) {
Error err;
DirAccess *alt = DirAccess::open(p_path, &err);
- if (!alt)
+ if (!alt) {
return err;
- if (d)
+ }
+ if (d) {
memdelete(d);
+ }
d = alt;
return OK;
@@ -1733,8 +1755,9 @@ _Directory::_Directory() {
}
_Directory::~_Directory() {
- if (d)
+ if (d) {
memdelete(d);
+ }
}
////// _Marshalls //////
@@ -1943,8 +1966,9 @@ Error _Thread::start(Object *p_instance, const StringName &p_method, const Varia
}
String _Thread::get_id() const {
- if (!thread)
+ if (!thread) {
return String();
+ }
return itos(thread->get_id());
}
@@ -1962,8 +1986,9 @@ Variant _Thread::wait_to_finish() {
target_method = StringName();
target_instance = nullptr;
userdata = Variant();
- if (thread)
+ if (thread) {
memdelete(thread);
+ }
thread = nullptr;
return r;
@@ -2032,8 +2057,9 @@ bool _ClassDB::can_instance(const StringName &p_class) const {
Variant _ClassDB::instance(const StringName &p_class) const {
Object *obj = ClassDB::instance(p_class);
- if (!obj)
+ if (!obj) {
return Variant();
+ }
Reference *r = Object::cast_to<Reference>(obj);
if (r) {
diff --git a/core/class_db.cpp b/core/class_db.cpp
index 0a187416f4..eed9ec17cb 100644
--- a/core/class_db.cpp
+++ b/core/class_db.cpp
@@ -248,8 +248,9 @@ bool ClassDB::is_parent_class(const StringName &p_class, const StringName &p_inh
StringName inherits = p_class;
while (inherits.operator String().length()) {
- if (inherits == p_inherits)
+ if (inherits == p_inherits) {
return true;
+ }
inherits = get_parent_class(inherits);
}
@@ -274,8 +275,9 @@ void ClassDB::get_inheriters_from_class(const StringName &p_class, List<StringNa
const StringName *k = nullptr;
while ((k = classes.next(k))) {
- if (*k != p_class && is_parent_class(*k, p_class))
+ if (*k != p_class && is_parent_class(*k, p_class)) {
p_classes->push_back(*k);
+ }
}
}
@@ -285,8 +287,9 @@ void ClassDB::get_direct_inheriters_from_class(const StringName &p_class, List<S
const StringName *k = nullptr;
while ((k = classes.next(k))) {
- if (*k != p_class && get_parent_class(*k) == p_class)
+ if (*k != p_class && get_parent_class(*k) == p_class) {
p_classes->push_back(*k);
+ }
}
}
@@ -294,8 +297,9 @@ StringName ClassDB::get_parent_class_nocheck(const StringName &p_class) {
OBJTYPE_RLOCK;
ClassInfo *ti = classes.getptr(p_class);
- if (!ti)
+ if (!ti) {
return StringName();
+ }
return ti->inherits;
}
@@ -347,8 +351,9 @@ uint64_t ClassDB::get_api_hash(APIType p_api) {
for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
ClassInfo *t = classes.getptr(E->get());
ERR_FAIL_COND_V_MSG(!t, 0, "Cannot get class '" + String(E->get()) + "'.");
- if (t->api != p_api || !t->exposed)
+ if (t->api != p_api || !t->exposed) {
continue;
+ }
hash = hash_djb2_one_64(t->name.hash(), hash);
hash = hash_djb2_one_64(t->inherits.hash(), hash);
@@ -363,8 +368,9 @@ uint64_t ClassDB::get_api_hash(APIType p_api) {
ERR_CONTINUE(name.empty());
- if (name[0] == '_')
+ if (name[0] == '_') {
continue; // Ignore non-virtual methods that start with an underscore
+ }
snames.push_back(*k);
}
@@ -549,8 +555,9 @@ void ClassDB::get_method_list(StringName p_class, List<MethodInfo> *p_methods, b
while (type) {
if (type->disabled) {
- if (p_no_inheritance)
+ if (p_no_inheritance) {
break;
+ }
type = type->inherits_ptr;
continue;
@@ -568,8 +575,9 @@ void ClassDB::get_method_list(StringName p_class, List<MethodInfo> *p_methods, b
minfo.name = E->get();
minfo.id = method->get_method_id();
- if (p_exclude_from_properties && type->methods_in_properties.has(minfo.name))
+ if (p_exclude_from_properties && type->methods_in_properties.has(minfo.name)) {
continue;
+ }
for (int i = 0; i < method->get_argument_count(); i++) {
//Variant::Type t=method->get_argument_type(i);
@@ -581,8 +589,9 @@ void ClassDB::get_method_list(StringName p_class, List<MethodInfo> *p_methods, b
minfo.flags = method->get_hint_flags();
for (int i = 0; i < method->get_argument_count(); i++) {
- if (method->has_default_argument(i))
+ if (method->has_default_argument(i)) {
minfo.default_arguments.push_back(method->get_default_argument(i));
+ }
}
p_methods->push_back(minfo);
@@ -601,8 +610,9 @@ void ClassDB::get_method_list(StringName p_class, List<MethodInfo> *p_methods, b
#endif
- if (p_no_inheritance)
+ if (p_no_inheritance) {
break;
+ }
type = type->inherits_ptr;
}
@@ -615,8 +625,9 @@ MethodBind *ClassDB::get_method(StringName p_class, StringName p_name) {
while (type) {
MethodBind **method = type->method_map.getptr(p_name);
- if (method && *method)
+ if (method && *method) {
return *method;
+ }
type = type->inherits_ptr;
}
return nullptr;
@@ -664,8 +675,9 @@ void ClassDB::get_integer_constant_list(const StringName &p_class, List<String>
while (type) {
#ifdef DEBUG_METHODS_ENABLED
- for (List<StringName>::Element *E = type->constant_order.front(); E; E = E->next())
+ for (List<StringName>::Element *E = type->constant_order.front(); E; E = E->next()) {
p_constants->push_back(E->get());
+ }
#else
const StringName *K = nullptr;
@@ -674,8 +686,9 @@ void ClassDB::get_integer_constant_list(const StringName &p_class, List<String>
}
#endif
- if (p_no_inheritance)
+ if (p_no_inheritance) {
break;
+ }
type = type->inherits_ptr;
}
@@ -689,16 +702,18 @@ int ClassDB::get_integer_constant(const StringName &p_class, const StringName &p
while (type) {
int *constant = type->constant_map.getptr(p_name);
if (constant) {
- if (p_success)
+ if (p_success) {
*p_success = true;
+ }
return *constant;
}
type = type->inherits_ptr;
}
- if (p_success)
+ if (p_success) {
*p_success = false;
+ }
return 0;
}
@@ -713,12 +728,14 @@ StringName ClassDB::get_integer_constant_enum(const StringName &p_class, const S
while ((k = type->enum_map.next(k))) {
List<StringName> &constants_list = type->enum_map.get(*k);
const List<StringName>::Element *found = constants_list.find(p_name);
- if (found)
+ if (found) {
return *k;
+ }
}
- if (p_no_inheritance)
+ if (p_no_inheritance) {
break;
+ }
type = type->inherits_ptr;
}
@@ -737,8 +754,9 @@ void ClassDB::get_enum_list(const StringName &p_class, List<StringName> *p_enums
p_enums->push_back(*k);
}
- if (p_no_inheritance)
+ if (p_no_inheritance) {
break;
+ }
type = type->inherits_ptr;
}
@@ -758,8 +776,9 @@ void ClassDB::get_enum_constants(const StringName &p_class, const StringName &p_
}
}
- if (p_no_inheritance)
+ if (p_no_inheritance) {
break;
+ }
type = type->inherits_ptr;
}
@@ -798,8 +817,9 @@ void ClassDB::get_signal_list(StringName p_class, List<MethodInfo> *p_signals, b
p_signals->push_back(check->signal_map[*S]);
}
- if (p_no_inheritance)
+ if (p_no_inheritance) {
return;
+ }
check = check->inherits_ptr;
}
@@ -810,8 +830,9 @@ bool ClassDB::has_signal(StringName p_class, StringName p_signal) {
ClassInfo *type = classes.getptr(p_class);
ClassInfo *check = type;
while (check) {
- if (check->signal_map.has(p_signal))
+ if (check->signal_map.has(p_signal)) {
return true;
+ }
check = check->inherits_ptr;
}
@@ -931,8 +952,9 @@ void ClassDB::get_property_list(StringName p_class, List<PropertyInfo> *p_list,
}
}
- if (p_no_inheritance)
+ if (p_no_inheritance) {
return;
+ }
check = check->inherits_ptr;
}
}
@@ -944,8 +966,9 @@ bool ClassDB::set_property(Object *p_object, const StringName &p_property, const
const PropertySetGet *psg = check->property_setget.getptr(p_property);
if (psg) {
if (!psg->setter) {
- if (r_valid)
+ if (r_valid) {
*r_valid = false;
+ }
return true; //return true but do nothing
}
@@ -970,8 +993,9 @@ bool ClassDB::set_property(Object *p_object, const StringName &p_property, const
}
}
- if (r_valid)
+ if (r_valid) {
*r_valid = ce.error == Callable::CallError::CALL_OK;
+ }
return true;
}
@@ -988,8 +1012,9 @@ bool ClassDB::get_property(Object *p_object, const StringName &p_property, Varia
while (check) {
const PropertySetGet *psg = check->property_setget.getptr(p_property);
if (psg) {
- if (!psg->getter)
+ if (!psg->getter) {
return true; //return true but do nothing
+ }
if (psg->index >= 0) {
Variant index = psg->index;
@@ -1036,16 +1061,18 @@ int ClassDB::get_property_index(const StringName &p_class, const StringName &p_p
while (check) {
const PropertySetGet *psg = check->property_setget.getptr(p_property);
if (psg) {
- if (r_is_valid)
+ if (r_is_valid) {
*r_is_valid = true;
+ }
return psg->index;
}
check = check->inherits_ptr;
}
- if (r_is_valid)
+ if (r_is_valid) {
*r_is_valid = false;
+ }
return -1;
}
@@ -1056,16 +1083,18 @@ Variant::Type ClassDB::get_property_type(const StringName &p_class, const String
while (check) {
const PropertySetGet *psg = check->property_setget.getptr(p_property);
if (psg) {
- if (r_is_valid)
+ if (r_is_valid) {
*r_is_valid = true;
+ }
return psg->type;
}
check = check->inherits_ptr;
}
- if (r_is_valid)
+ if (r_is_valid) {
*r_is_valid = false;
+ }
return Variant::NIL;
}
@@ -1104,11 +1133,13 @@ bool ClassDB::has_property(const StringName &p_class, const StringName &p_proper
ClassInfo *type = classes.getptr(p_class);
ClassInfo *check = type;
while (check) {
- if (check->property_setget.has(p_property))
+ if (check->property_setget.has(p_property)) {
return true;
+ }
- if (p_no_inheritance)
+ if (p_no_inheritance) {
break;
+ }
check = check->inherits_ptr;
}
@@ -1128,10 +1159,12 @@ bool ClassDB::has_method(StringName p_class, StringName p_method, bool p_no_inhe
ClassInfo *type = classes.getptr(p_class);
ClassInfo *check = type;
while (check) {
- if (check->method_map.has(p_method))
+ if (check->method_map.has(p_method)) {
return true;
- if (p_no_inheritance)
+ }
+ if (p_no_inheritance) {
return false;
+ }
check = check->inherits_ptr;
}
@@ -1202,8 +1235,9 @@ void ClassDB::add_virtual_method(const StringName &p_class, const MethodInfo &p_
#ifdef DEBUG_METHODS_ENABLED
MethodInfo mi = p_method;
- if (p_virtual)
+ if (p_virtual) {
mi.flags |= METHOD_FLAG_VIRTUAL;
+ }
classes[p_class].virtual_methods.push_back(mi);
#endif
@@ -1221,8 +1255,9 @@ void ClassDB::get_virtual_methods(const StringName &p_class, List<MethodInfo> *p
p_methods->push_back(E->get());
}
- if (p_no_inheritance)
+ if (p_no_inheritance) {
return;
+ }
check = check->inherits_ptr;
}
@@ -1268,8 +1303,9 @@ StringName ClassDB::get_category(const StringName &p_node) {
}
void ClassDB::add_resource_base_extension(const StringName &p_extension, const StringName &p_class) {
- if (resource_base_extensions.has(p_extension))
+ if (resource_base_extensions.has(p_extension)) {
return;
+ }
resource_base_extensions[p_extension] = p_class;
}
@@ -1287,8 +1323,9 @@ void ClassDB::get_extensions_for_type(const StringName &p_class, List<String> *p
while ((K = resource_base_extensions.next(K))) {
StringName cmp = resource_base_extensions[*K];
- if (is_parent_class(p_class, cmp) || is_parent_class(cmp, p_class))
+ if (is_parent_class(p_class, cmp) || is_parent_class(cmp, p_class)) {
p_extensions->push_back(*K);
+ }
}
}
@@ -1333,19 +1370,22 @@ Variant ClassDB::class_get_default_property_value(const StringName &p_class, con
}
if (!default_values.has(p_class)) {
- if (r_valid != nullptr)
+ if (r_valid != nullptr) {
*r_valid = false;
+ }
return Variant();
}
if (!default_values[p_class].has(p_property)) {
- if (r_valid != nullptr)
+ if (r_valid != nullptr) {
*r_valid = false;
+ }
return Variant();
}
- if (r_valid != nullptr)
+ if (r_valid != nullptr) {
*r_valid = true;
+ }
return default_values[p_class][p_property];
}
diff --git a/core/color.cpp b/core/color.cpp
index 4bee14f3ba..fa3f6475d4 100644
--- a/core/color.cpp
+++ b/core/color.cpp
@@ -115,20 +115,23 @@ float Color::get_h() const {
float delta = max - min;
- if (delta == 0)
+ if (delta == 0) {
return 0;
+ }
float h;
- if (r == max)
+ if (r == max) {
h = (g - b) / delta; // between yellow & magenta
- else if (g == max)
+ } else if (g == max) {
h = 2 + (b - r) / delta; // between cyan & yellow
- else
+ } else {
h = 4 + (r - g) / delta; // between magenta & cyan
+ }
h /= 6.0;
- if (h < 0)
+ if (h < 0) {
h += 1.0;
+ }
return h;
}
@@ -277,10 +280,11 @@ static float _parse_col(const String &p_str, int p_ofs) {
return -1;
}
- if (i == 0)
+ if (i == 0) {
ig += v * 16;
- else
+ } else {
ig += v;
+ }
}
return ig;
@@ -300,10 +304,12 @@ Color Color::contrasted() const {
Color Color::html(const String &p_color) {
String color = p_color;
- if (color.length() == 0)
+ if (color.length() == 0) {
return Color();
- if (color[0] == '#')
+ }
+ if (color[0] == '#') {
color = color.substr(1, color.length() - 1);
+ }
if (color.length() == 3 || color.length() == 4) {
String exp_color;
for (int i = 0; i < color.length(); i++) {
@@ -344,10 +350,12 @@ Color Color::html(const String &p_color) {
bool Color::html_is_valid(const String &p_color) {
String color = p_color;
- if (color.length() == 0)
+ if (color.length() == 0) {
return false;
- if (color[0] == '#')
+ }
+ if (color[0] == '#') {
color = color.substr(1, color.length() - 1);
+ }
bool alpha = false;
@@ -385,8 +393,9 @@ bool Color::html_is_valid(const String &p_color) {
}
Color Color::named(const String &p_name) {
- if (_named_colors.empty())
+ if (_named_colors.empty()) {
_populate_named_colors(); // from color_names.inc
+ }
String name = p_name;
// Normalize name
name = name.replace(" ", "");
@@ -409,10 +418,11 @@ String _to_hex(float p_val) {
for (int i = 0; i < 2; i++) {
CharType c[2] = { 0, 0 };
int lv = v & 0xF;
- if (lv < 10)
+ if (lv < 10) {
c[0] = '0' + lv;
- else
+ } else {
c[0] = 'a' + lv - 10;
+ }
v >>= 4;
String cs = (const CharType *)c;
@@ -427,15 +437,17 @@ String Color::to_html(bool p_alpha) const {
txt += _to_hex(r);
txt += _to_hex(g);
txt += _to_hex(b);
- if (p_alpha)
+ if (p_alpha) {
txt = _to_hex(a) + txt;
+ }
return txt;
}
Color Color::from_hsv(float p_h, float p_s, float p_v, float p_a) const {
p_h = Math::fmod(p_h * 360.0f, 360.0f);
- if (p_h < 0.0)
+ if (p_h < 0.0) {
p_h += 360.0f;
+ }
const float h_ = p_h / 60.0f;
const float c = p_v * p_s;
diff --git a/core/color.h b/core/color.h
index 10d49f3cad..258965fd16 100644
--- a/core/color.h
+++ b/core/color.h
@@ -223,12 +223,15 @@ bool Color::operator<(const Color &p_color) const {
if (g == p_color.g) {
if (b == p_color.b) {
return (a < p_color.a);
- } else
+ } else {
return (b < p_color.b);
- } else
+ }
+ } else {
return g < p_color.g;
- } else
+ }
+ } else {
return r < p_color.r;
+ }
}
#endif // COLOR_H
diff --git a/core/color_names.inc b/core/color_names.inc
index f249ee9868..2b50d88b02 100644
--- a/core/color_names.inc
+++ b/core/color_names.inc
@@ -3,8 +3,9 @@
static Map<String, Color> _named_colors;
static void _populate_named_colors() {
- if (!_named_colors.empty())
+ if (!_named_colors.empty()) {
return;
+ }
_named_colors.insert("aliceblue", Color(0.94, 0.97, 1.00));
_named_colors.insert("antiquewhite", Color(0.98, 0.92, 0.84));
_named_colors.insert("aqua", Color(0.00, 1.00, 1.00));
diff --git a/core/command_queue_mt.cpp b/core/command_queue_mt.cpp
index d23a6425e3..ace210ca2c 100644
--- a/core/command_queue_mt.cpp
+++ b/core/command_queue_mt.cpp
@@ -94,12 +94,14 @@ tryagain:
}
CommandQueueMT::CommandQueueMT(bool p_sync) {
- if (p_sync)
+ if (p_sync) {
sync = memnew(Semaphore);
+ }
}
CommandQueueMT::~CommandQueueMT() {
- if (sync)
+ if (sync) {
memdelete(sync);
+ }
memfree(command_mem);
}
diff --git a/core/command_queue_mt.h b/core/command_queue_mt.h
index d40005fb12..d7a6a5bc43 100644
--- a/core/command_queue_mt.h
+++ b/core/command_queue_mt.h
@@ -413,14 +413,16 @@ class CommandQueueMT {
}
bool flush_one(bool p_lock = true) {
- if (p_lock)
+ if (p_lock) {
lock();
+ }
tryagain:
// tried to read an empty queue
if (read_ptr == write_ptr) {
- if (p_lock)
+ if (p_lock) {
unlock();
+ }
return false;
}
@@ -439,18 +441,21 @@ class CommandQueueMT {
read_ptr += size;
- if (p_lock)
+ if (p_lock) {
unlock();
+ }
cmd->call();
- if (p_lock)
+ if (p_lock) {
lock();
+ }
cmd->post();
cmd->~CommandBase();
*(uint32_t *)&command_mem[size_ptr] &= ~1;
- if (p_lock)
+ if (p_lock) {
unlock();
+ }
return true;
}
@@ -482,8 +487,8 @@ public:
void flush_all() {
//ERR_FAIL_COND(sync);
lock();
- while (flush_one(false))
- ;
+ while (flush_one(false)) {
+ }
unlock();
}
diff --git a/core/compressed_translation.cpp b/core/compressed_translation.cpp
index dd46e23505..a66997aa52 100644
--- a/core/compressed_translation.cpp
+++ b/core/compressed_translation.cpp
@@ -109,8 +109,9 @@ void PHashTranslation::generate(const Ref<Translation> &p_from) {
const Vector<Pair<int, CharString>> &b = buckets[i];
Map<uint32_t, int> &t = table.write[i];
- if (b.size() == 0)
+ if (b.size() == 0) {
continue;
+ }
int d = 1;
int item = 0;
@@ -189,22 +190,24 @@ bool PHashTranslation::_set(const StringName &p_name, const Variant &p_value) {
strings = p_value;
} else if (name == "load_from") {
generate(p_value);
- } else
+ } else {
return false;
+ }
return true;
}
bool PHashTranslation::_get(const StringName &p_name, Variant &r_ret) const {
String name = p_name.operator String();
- if (name == "hash_table")
+ if (name == "hash_table") {
r_ret = hash_table;
- else if (name == "bucket_table")
+ } else if (name == "bucket_table") {
r_ret = bucket_table;
- else if (name == "strings")
+ } else if (name == "strings") {
r_ret = strings;
- else
+ } else {
return false;
+ }
return true;
}
@@ -212,8 +215,9 @@ bool PHashTranslation::_get(const StringName &p_name, Variant &r_ret) const {
StringName PHashTranslation::get_message(const StringName &p_src_text) const {
int htsize = hash_table.size();
- if (htsize == 0)
+ if (htsize == 0) {
return StringName();
+ }
CharString str = p_src_text.operator String().utf8();
uint32_t h = hash(0, str.get_data());
diff --git a/core/compressed_translation.h b/core/compressed_translation.h
index 032e391729..3c029bdf58 100644
--- a/core/compressed_translation.h
+++ b/core/compressed_translation.h
@@ -61,8 +61,9 @@ class PHashTranslation : public Translation {
};
_FORCE_INLINE_ uint32_t hash(uint32_t d, const char *p_str) const {
- if (d == 0)
+ if (d == 0) {
d = 0x1000193;
+ }
while (*p_str) {
d = (d * 0x1000193) ^ uint32_t(*p_str);
p_str++;
diff --git a/core/cowdata.h b/core/cowdata.h
index 72a76d735d..3f72362e29 100644
--- a/core/cowdata.h
+++ b/core/cowdata.h
@@ -59,22 +59,25 @@ private:
// internal helpers
_FORCE_INLINE_ uint32_t *_get_refcount() const {
- if (!_ptr)
+ if (!_ptr) {
return nullptr;
+ }
return reinterpret_cast<uint32_t *>(_ptr) - 2;
}
_FORCE_INLINE_ uint32_t *_get_size() const {
- if (!_ptr)
+ if (!_ptr) {
return nullptr;
+ }
return reinterpret_cast<uint32_t *>(_ptr) - 1;
}
_FORCE_INLINE_ T *_get_data() const {
- if (!_ptr)
+ if (!_ptr) {
return nullptr;
+ }
return reinterpret_cast<T *>(_ptr);
}
@@ -122,10 +125,11 @@ public:
_FORCE_INLINE_ int size() const {
uint32_t *size = (uint32_t *)_get_size();
- if (size)
+ if (size) {
return *size;
- else
+ } else {
return 0;
+ }
}
_FORCE_INLINE_ void clear() { resize(0); }
@@ -165,8 +169,9 @@ public:
Error insert(int p_pos, const T &p_val) {
ERR_FAIL_INDEX_V(p_pos, size() + 1, ERR_INVALID_PARAMETER);
resize(size() + 1);
- for (int i = (size() - 1); i > p_pos; i--)
+ for (int i = (size() - 1); i > p_pos; i--) {
set(i, get(i - 1));
+ }
set(p_pos, p_val);
return OK;
@@ -181,13 +186,15 @@ public:
template <class T>
void CowData<T>::_unref(void *p_data) {
- if (!p_data)
+ if (!p_data) {
return;
+ }
uint32_t *refc = _get_refcount();
- if (atomic_decrement(refc) > 0)
+ if (atomic_decrement(refc) > 0) {
return; // still in use
+ }
// clean up
if (!__has_trivial_destructor(T)) {
@@ -206,8 +213,9 @@ void CowData<T>::_unref(void *p_data) {
template <class T>
void CowData<T>::_copy_on_write() {
- if (!_ptr)
+ if (!_ptr) {
return;
+ }
uint32_t *refc = _get_refcount();
@@ -243,8 +251,9 @@ Error CowData<T>::resize(int p_size) {
int current_size = size();
- if (p_size == current_size)
+ if (p_size == current_size) {
return OK;
+ }
if (p_size == 0) {
// wants to clean up
@@ -337,14 +346,16 @@ void CowData<T>::_ref(const CowData *p_from) {
template <class T>
void CowData<T>::_ref(const CowData &p_from) {
- if (_ptr == p_from._ptr)
+ if (_ptr == p_from._ptr) {
return; // self assign, do nothing.
+ }
_unref(_ptr);
_ptr = nullptr;
- if (!p_from._ptr)
+ if (!p_from._ptr) {
return; //nothing to do
+ }
if (atomic_conditional_increment(p_from._get_refcount()) > 0) { // could reference
_ptr = p_from._ptr;
diff --git a/core/crypto/crypto.cpp b/core/crypto/crypto.cpp
index ed27d2ebc3..eb942c60c9 100644
--- a/core/crypto/crypto.cpp
+++ b/core/crypto/crypto.cpp
@@ -38,8 +38,9 @@
CryptoKey *(*CryptoKey::_create)() = nullptr;
CryptoKey *CryptoKey::create() {
- if (_create)
+ if (_create) {
return _create();
+ }
return nullptr;
}
@@ -50,8 +51,9 @@ void CryptoKey::_bind_methods() {
X509Certificate *(*X509Certificate::_create)() = nullptr;
X509Certificate *X509Certificate::create() {
- if (_create)
+ if (_create) {
return _create();
+ }
return nullptr;
}
@@ -65,14 +67,16 @@ void X509Certificate::_bind_methods() {
void (*Crypto::_load_default_certificates)(String p_path) = nullptr;
Crypto *(*Crypto::_create)() = nullptr;
Crypto *Crypto::create() {
- if (_create)
+ if (_create) {
return _create();
+ }
return memnew(Crypto);
}
void Crypto::load_default_certificates(String p_path) {
- if (_load_default_certificates)
+ if (_load_default_certificates) {
_load_default_certificates(p_path);
+ }
}
void Crypto::_bind_methods() {
@@ -99,13 +103,15 @@ RES ResourceFormatLoaderCrypto::load(const String &p_path, const String &p_origi
String el = p_path.get_extension().to_lower();
if (el == "crt") {
X509Certificate *cert = X509Certificate::create();
- if (cert)
+ if (cert) {
cert->load(p_path);
+ }
return cert;
} else if (el == "key") {
CryptoKey *key = CryptoKey::create();
- if (key)
+ if (key) {
key->load(p_path);
+ }
return key;
}
return nullptr;
@@ -122,10 +128,11 @@ bool ResourceFormatLoaderCrypto::handles_type(const String &p_type) const {
String ResourceFormatLoaderCrypto::get_resource_type(const String &p_path) const {
String el = p_path.get_extension().to_lower();
- if (el == "crt")
+ if (el == "crt") {
return "X509Certificate";
- else if (el == "key")
+ } else if (el == "key") {
return "CryptoKey";
+ }
return "";
}
diff --git a/core/crypto/hashing_context.cpp b/core/crypto/hashing_context.cpp
index 726dc615df..fb0dadfbab 100644
--- a/core/crypto/hashing_context.cpp
+++ b/core/crypto/hashing_context.cpp
@@ -128,6 +128,7 @@ void HashingContext::_bind_methods() {
}
HashingContext::~HashingContext() {
- if (ctx != nullptr)
+ if (ctx != nullptr) {
_delete_ctx();
+ }
}
diff --git a/core/debugger/debugger_marshalls.cpp b/core/debugger/debugger_marshalls.cpp
index 410c55129d..3f949b0ae1 100644
--- a/core/debugger/debugger_marshalls.cpp
+++ b/core/debugger/debugger_marshalls.cpp
@@ -228,8 +228,9 @@ Array DebuggerMarshalls::ScriptStackVariable::serialize(int max_size) {
int len = 0;
Error err = encode_variant(var, nullptr, len, true);
- if (err != OK)
+ if (err != OK) {
ERR_PRINT("Failed to encode variant.");
+ }
if (len > max_size) {
arr.push_back(Variant());
diff --git a/core/debugger/engine_debugger.cpp b/core/debugger/engine_debugger.cpp
index 19ac87ad8b..5c9fb67de4 100644
--- a/core/debugger/engine_debugger.cpp
+++ b/core/debugger/engine_debugger.cpp
@@ -111,8 +111,9 @@ Error EngineDebugger::capture_parse(const StringName &p_name, const String &p_ms
void EngineDebugger::line_poll() {
// The purpose of this is just processing events every now and then when the script might get too busy otherwise bugs like infinite loops can't be caught
- if (poll_every % 2048 == 0)
+ if (poll_every % 2048 == 0) {
poll_events(false);
+ }
poll_every++;
}
@@ -124,8 +125,9 @@ void EngineDebugger::iteration(uint64_t p_frame_ticks, uint64_t p_idle_ticks, ui
// Notify tick to running profilers
for (Map<StringName, Profiler>::Element *E = profilers.front(); E; E = E->next()) {
Profiler &p = E->get();
- if (!p.active || !p.tick)
+ if (!p.active || !p.tick) {
continue;
+ }
p.tick(p.data, frame_time, idle_time, physics_time, physics_frame_time);
}
singleton->poll_events(true);
@@ -133,8 +135,9 @@ void EngineDebugger::iteration(uint64_t p_frame_ticks, uint64_t p_idle_ticks, ui
void EngineDebugger::initialize(const String &p_uri, bool p_skip_breakpoints, Vector<String> p_breakpoints) {
register_uri_handler("tcp://", RemoteDebuggerPeerTCP::create); // TCP is the default protocol. Platforms/modules can add more.
- if (p_uri.empty())
+ if (p_uri.empty()) {
return;
+ }
if (p_uri == "local://") {
singleton = memnew(LocalDebugger);
script_debugger = memnew(ScriptDebugger);
@@ -142,11 +145,13 @@ void EngineDebugger::initialize(const String &p_uri, bool p_skip_breakpoints, Ve
OS::get_singleton()->initialize_debugging();
} else if (p_uri.find("://") >= 0) {
const String proto = p_uri.substr(0, p_uri.find("://") + 3);
- if (!protocols.has(proto))
+ if (!protocols.has(proto)) {
return;
+ }
RemoteDebuggerPeer *peer = protocols[proto](p_uri);
- if (!peer)
+ if (!peer) {
return;
+ }
singleton = memnew(RemoteDebugger(Ref<RemoteDebuggerPeer>(peer)));
script_debugger = memnew(ScriptDebugger);
// Notify editor of our pid (to allow focus stealing).
@@ -154,8 +159,9 @@ void EngineDebugger::initialize(const String &p_uri, bool p_skip_breakpoints, Ve
msg.push_back(OS::get_singleton()->get_process_id());
singleton->send_message("set_pid", msg);
}
- if (!singleton)
+ if (!singleton) {
return;
+ }
// There is a debugger, parse breakpoints.
ScriptDebugger *singleton_script_debugger = singleton->get_script_debugger();
@@ -174,8 +180,9 @@ void EngineDebugger::deinitialize() {
if (singleton) {
// Stop all profilers
for (Map<StringName, Profiler>::Element *E = profilers.front(); E; E = E->next()) {
- if (E->get().active)
+ if (E->get().active) {
singleton->profiler_enable(E->key(), false);
+ }
}
// Flush any remaining message
@@ -192,8 +199,9 @@ void EngineDebugger::deinitialize() {
}
EngineDebugger::~EngineDebugger() {
- if (script_debugger)
+ if (script_debugger) {
memdelete(script_debugger);
+ }
script_debugger = nullptr;
singleton = nullptr;
}
diff --git a/core/debugger/local_debugger.cpp b/core/debugger/local_debugger.cpp
index 9251b77f96..876be79418 100644
--- a/core/debugger/local_debugger.cpp
+++ b/core/debugger/local_debugger.cpp
@@ -69,17 +69,19 @@ struct LocalDebugger::ScriptsProfiler {
void _print_frame_data(bool p_accumulated) {
uint64_t diff = OS::get_singleton()->get_ticks_usec() - idle_accum;
- if (!p_accumulated && diff < 1000000) //show every one second
+ if (!p_accumulated && diff < 1000000) { //show every one second
return;
+ }
idle_accum = OS::get_singleton()->get_ticks_usec();
int ofs = 0;
for (int i = 0; i < ScriptServer::get_language_count(); i++) {
- if (p_accumulated)
+ if (p_accumulated) {
ofs += ScriptServer::get_language(i)->profiling_get_accumulated_data(&pinfo.write[ofs], pinfo.size() - ofs);
- else
+ } else {
ofs += ScriptServer::get_language(i)->profiling_get_frame_data(&pinfo.write[ofs], pinfo.size() - ofs);
+ }
}
SortArray<ScriptLanguage::ProfilingInfo, ProfileInfoSort> sort;
@@ -141,9 +143,9 @@ void LocalDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) {
print_line("\nDebugger Break, Reason: '" + script_lang->debug_get_error() + "'");
print_line("*Frame " + itos(current_frame) + " - " + script_lang->debug_get_stack_level_source(current_frame) + ":" + itos(script_lang->debug_get_stack_level_line(current_frame)) + " in function '" + script_lang->debug_get_stack_level_function(current_frame) + "'");
print_line("Enter \"help\" for assistance.");
- } else if (line == "c" || line == "continue")
+ } else if (line == "c" || line == "continue") {
break;
- else if (line == "bt" || line == "breakpoint") {
+ } else if (line == "bt" || line == "breakpoint") {
for (int i = 0; i < total_frames; i++) {
String cfi = (current_frame == i) ? "*" : " "; //current frame indicator
print_line(cfi + "Frame " + itos(i) + " - " + script_lang->debug_get_stack_level_source(i) + ":" + itos(script_lang->debug_get_stack_level_line(i)) + " in function '" + script_lang->debug_get_stack_level_function(i) + "'");
@@ -257,8 +259,9 @@ void LocalDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) {
String source = breakpoint.first;
int linenr = breakpoint.second;
- if (source.empty())
+ if (source.empty()) {
continue;
+ }
script_debugger->insert_breakpoint(linenr, source);
@@ -282,8 +285,9 @@ void LocalDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) {
String source = breakpoint.first;
int linenr = breakpoint.second;
- if (source.empty())
+ if (source.empty()) {
continue;
+ }
script_debugger->remove_breakpoint(linenr, source);
@@ -377,6 +381,7 @@ LocalDebugger::LocalDebugger() {
LocalDebugger::~LocalDebugger() {
unregister_profiler("scripts");
- if (scripts_profiler)
+ if (scripts_profiler) {
memdelete(scripts_profiler);
+ }
}
diff --git a/core/debugger/remote_debugger.cpp b/core/debugger/remote_debugger.cpp
index ba195f2ab5..62f600c5e5 100644
--- a/core/debugger/remote_debugger.cpp
+++ b/core/debugger/remote_debugger.cpp
@@ -96,8 +96,9 @@ public:
}
void init_node(const ObjectID p_node) {
- if (multiplayer_node_data.has(p_node))
+ if (multiplayer_node_data.has(p_node)) {
return;
+ }
multiplayer_node_data.insert(p_node, DebuggerMarshalls::MultiplayerNodeInfo());
multiplayer_node_data[p_node].node = p_node;
multiplayer_node_data[p_node].node_path = Object::cast_to<Node>(ObjectDB::get_instance(p_node))->get_path();
@@ -218,10 +219,11 @@ struct RemoteDebugger::ScriptsProfiler {
void write_frame_data(Vector<FunctionInfo> &r_funcs, uint64_t &r_total, bool p_accumulated) {
int ofs = 0;
for (int i = 0; i < ScriptServer::get_language_count(); i++) {
- if (p_accumulated)
+ if (p_accumulated) {
ofs += ScriptServer::get_language(i)->profiling_get_accumulated_data(&info.write[ofs], info.size() - ofs);
- else
+ } else {
ofs += ScriptServer::get_language(i)->profiling_get_frame_data(&info.write[ofs], info.size() - ofs);
+ }
}
for (int i = 0; i < ofs; i++) {
@@ -358,8 +360,9 @@ struct RemoteDebugger::VisualProfiler {
void tick(float p_frame_time, float p_idle_time, float p_physics_time, float p_physics_frame_time) {
Vector<RS::FrameProfileArea> profile_areas = RS::get_singleton()->get_frame_profile();
DebuggerMarshalls::VisualProfilerFrame frame;
- if (!profile_areas.size())
+ if (!profile_areas.size()) {
return;
+ }
frame.frame_number = RS::get_singleton()->get_frame_profile_frame();
frame.areas.append_array(profile_areas);
@@ -374,12 +377,14 @@ struct RemoteDebugger::PerformanceProfiler {
void toggle(bool p_enable, const Array &p_opts) {}
void add(const Array &p_data) {}
void tick(float p_frame_time, float p_idle_time, float p_physics_time, float p_physics_frame_time) {
- if (!performance)
+ if (!performance) {
return;
+ }
uint64_t pt = OS::get_singleton()->get_ticks_msec();
- if (pt - last_perf_time < 1000)
+ if (pt - last_perf_time < 1000) {
return;
+ }
last_perf_time = pt;
int max = performance->get("MONITOR_MAX");
Array arr;
@@ -423,25 +428,29 @@ Error RemoteDebugger::_put_msg(String p_message, Array p_data) {
msg.push_back(p_message);
msg.push_back(p_data);
Error err = peer->put_message(msg);
- if (err != OK)
+ if (err != OK) {
n_messages_dropped++;
+ }
return err;
}
void RemoteDebugger::_err_handler(void *p_this, const char *p_func, const char *p_file, int p_line, const char *p_err, const char *p_descr, ErrorHandlerType p_type) {
- if (p_type == ERR_HANDLER_SCRIPT)
+ if (p_type == ERR_HANDLER_SCRIPT) {
return; //ignore script errors, those go through debugger
+ }
RemoteDebugger *rd = (RemoteDebugger *)p_this;
- if (rd->flushing && Thread::get_caller_id() == rd->flush_thread) // Can't handle recursive errors during flush.
+ if (rd->flushing && Thread::get_caller_id() == rd->flush_thread) { // Can't handle recursive errors during flush.
return;
+ }
Vector<ScriptLanguage::StackInfo> si;
for (int i = 0; i < ScriptServer::get_language_count(); i++) {
si = ScriptServer::get_language(i)->debug_get_current_stack_info();
- if (si.size())
+ if (si.size()) {
break;
+ }
}
// send_error will lock internally.
@@ -451,14 +460,16 @@ void RemoteDebugger::_err_handler(void *p_this, const char *p_func, const char *
void RemoteDebugger::_print_handler(void *p_this, const String &p_string, bool p_error) {
RemoteDebugger *rd = (RemoteDebugger *)p_this;
- if (rd->flushing && Thread::get_caller_id() == rd->flush_thread) // Can't handle recursive prints during flush.
+ if (rd->flushing && Thread::get_caller_id() == rd->flush_thread) { // Can't handle recursive prints during flush.
return;
+ }
String s = p_string;
int allowed_chars = MIN(MAX(rd->max_chars_per_second - rd->char_count, 0), s.length());
- if (allowed_chars == 0 && s.length() > 0)
+ if (allowed_chars == 0 && s.length() > 0) {
return;
+ }
if (allowed_chars < s.length()) {
s = s.substr(0, allowed_chars);
@@ -469,8 +480,9 @@ void RemoteDebugger::_print_handler(void *p_this, const String &p_string, bool p
rd->char_count += allowed_chars;
bool overflowed = rd->char_count >= rd->max_chars_per_second;
if (rd->is_peer_connected()) {
- if (overflowed)
+ if (overflowed) {
s += "[...]";
+ }
OutputString output_string;
output_string.message = s;
@@ -502,13 +514,15 @@ void RemoteDebugger::flush_output() {
flush_thread = Thread::get_caller_id();
flushing = true;
MutexLock lock(mutex);
- if (!is_peer_connected())
+ if (!is_peer_connected()) {
return;
+ }
if (n_messages_dropped > 0) {
ErrorMessage err_msg = _create_overflow_error("TOO_MANY_MESSAGES", "Too many messages! " + String::num_int64(n_messages_dropped) + " messages were dropped. Profiling might misbheave, try raising 'network/limits/debugger/max_queued_messages' in project setting.");
- if (_put_msg("error", err_msg.serialize()) == OK)
+ if (_put_msg("error", err_msg.serialize()) == OK) {
n_messages_dropped = 0;
+ }
}
if (output_strings.size()) {
@@ -585,8 +599,9 @@ void RemoteDebugger::send_error(const String &p_func, const String &p_file, int
oe.msec = time % 1000;
oe.callstack.append_array(script_debugger->get_error_stack_info());
- if (flushing && Thread::get_caller_id() == flush_thread) // Can't handle recursive errors during flush.
+ if (flushing && Thread::get_caller_id() == flush_thread) { // Can't handle recursive errors during flush.
return;
+ }
MutexLock lock(mutex);
@@ -644,8 +659,9 @@ Error RemoteDebugger::_try_capture(const String &p_msg, const Array &p_data, boo
return OK;
}
const String cap = p_msg.substr(0, idx);
- if (!has_capture(cap))
+ if (!has_capture(cap)) {
return ERR_UNAVAILABLE; // Unknown message...
+ }
const String msg = p_msg.substr(idx + 1);
return capture_parse(cap, msg, p_data, r_captured);
}
@@ -654,13 +670,15 @@ void RemoteDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) {
//this function is called when there is a debugger break (bug on script)
//or when execution is paused from editor
- if (script_debugger->is_skipping_breakpoints() && !p_is_error_breakpoint)
+ if (script_debugger->is_skipping_breakpoints() && !p_is_error_breakpoint) {
return;
+ }
ERR_FAIL_COND_MSG(!is_peer_connected(), "Script Debugger failed to connect, but being used anyway.");
- if (!peer->can_block())
+ if (!peer->can_block()) {
return; // Peer does not support blocking IO. We could at least send the error though.
+ }
ScriptLanguage *script_lang = script_debugger->get_break_language();
const String error_str = script_lang ? script_lang->debug_get_error() : "";
@@ -672,8 +690,9 @@ void RemoteDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) {
servers_profiler->skip_profile_frame = true; // Avoid frame time spike in debug.
Input::MouseMode mouse_mode = Input::get_singleton()->get_mouse_mode();
- if (mouse_mode != Input::MOUSE_MODE_VISIBLE)
+ if (mouse_mode != Input::MOUSE_MODE_VISIBLE) {
Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE);
+ }
uint64_t loop_begin_usec = 0;
uint64_t loop_time_sec = 0;
@@ -761,10 +780,11 @@ void RemoteDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) {
} else if (command == "breakpoint") {
ERR_FAIL_COND(data.size() < 3);
bool set = data[2];
- if (set)
+ if (set) {
script_debugger->insert_breakpoint(data[1], data[0]);
- else
+ } else {
script_debugger->remove_breakpoint(data[1], data[0]);
+ }
} else if (command == "set_skip_breakpoints") {
ERR_FAIL_COND(data.size() < 1);
@@ -772,8 +792,9 @@ void RemoteDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) {
} else {
bool captured = false;
ERR_CONTINUE(_try_capture(command, data, captured) != OK);
- if (!captured)
+ if (!captured) {
WARN_PRINT("Unknown message received from debugger: " + command);
+ }
}
} else {
OS::get_singleton()->delay_usec(10000);
@@ -790,13 +811,15 @@ void RemoteDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) {
send_message("debug_exit", Array());
- if (mouse_mode != Input::MOUSE_MODE_VISIBLE)
+ if (mouse_mode != Input::MOUSE_MODE_VISIBLE) {
Input::get_singleton()->set_mouse_mode(mouse_mode);
+ }
}
void RemoteDebugger::poll_events(bool p_is_idle) {
- if (peer.is_null())
+ if (peer.is_null()) {
return;
+ }
flush_output();
peer->poll();
@@ -816,8 +839,9 @@ void RemoteDebugger::poll_events(bool p_is_idle) {
}
const String cap = cmd.substr(0, idx);
- if (!has_capture(cap))
+ if (!has_capture(cap)) {
continue; // Unknown message...
+ }
const String msg = cmd.substr(idx + 1);
capture_parse(cap, msg, arr[1], parsed);
@@ -840,10 +864,11 @@ Error RemoteDebugger::_core_capture(const String &p_cmd, const Array &p_data, bo
} else if (p_cmd == "breakpoint") {
ERR_FAIL_COND_V(p_data.size() < 3, ERR_INVALID_DATA);
bool set = p_data[2];
- if (set)
+ if (set) {
script_debugger->insert_breakpoint(p_data[1], p_data[0]);
- else
+ } else {
script_debugger->remove_breakpoint(p_data[1], p_data[0]);
+ }
} else if (p_cmd == "set_skip_breakpoints") {
ERR_FAIL_COND_V(p_data.size() < 1, ERR_INVALID_DATA);
@@ -934,6 +959,7 @@ RemoteDebugger::~RemoteDebugger() {
memdelete(servers_profiler);
memdelete(network_profiler);
memdelete(visual_profiler);
- if (performance_profiler)
+ if (performance_profiler) {
memdelete(performance_profiler);
+ }
}
diff --git a/core/debugger/remote_debugger_peer.cpp b/core/debugger/remote_debugger_peer.cpp
index 1218bc5060..fd1eee0654 100644
--- a/core/debugger/remote_debugger_peer.cpp
+++ b/core/debugger/remote_debugger_peer.cpp
@@ -52,8 +52,9 @@ Array RemoteDebuggerPeerTCP::get_message() {
Error RemoteDebuggerPeerTCP::put_message(const Array &p_arr) {
MutexLock lock(mutex);
- if (out_queue.size() >= max_queued_messages)
+ if (out_queue.size() >= max_queued_messages) {
return ERR_OUT_OF_MEMORY;
+ }
out_queue.push_back(p_arr);
return OK;
@@ -99,8 +100,9 @@ void RemoteDebuggerPeerTCP::_write_out() {
while (tcp_client->poll(NetSocket::POLL_TYPE_OUT) == OK) {
uint8_t *buf = out_buf.ptrw();
if (out_left <= 0) {
- if (out_queue.size() == 0)
+ if (out_queue.size() == 0) {
break; // Nothing left to send
+ }
mutex.lock();
Variant var = out_queue[0];
out_queue.pop_front();
@@ -155,10 +157,11 @@ void RemoteDebuggerPeerTCP::_read_in() {
Error RemoteDebuggerPeerTCP::connect_to_host(const String &p_host, uint16_t p_port) {
IP_Address ip;
- if (p_host.is_valid_ip_address())
+ if (p_host.is_valid_ip_address()) {
ip = p_host;
- else
+ } else {
ip = IP::get_singleton()->resolve_hostname(p_host);
+ }
int port = p_port;
@@ -194,8 +197,9 @@ void RemoteDebuggerPeerTCP::_thread_func(void *p_ud) {
RemoteDebuggerPeerTCP *peer = (RemoteDebuggerPeerTCP *)p_ud;
while (peer->running && peer->is_peer_connected()) {
peer->_poll();
- if (!peer->is_peer_connected())
+ if (!peer->is_peer_connected()) {
break;
+ }
peer->tcp_client->poll(NetSocket::POLL_TYPE_IN_OUT, 1);
}
}
diff --git a/core/debugger/script_debugger.cpp b/core/debugger/script_debugger.cpp
index 179745b11e..0cd3238efb 100644
--- a/core/debugger/script_debugger.cpp
+++ b/core/debugger/script_debugger.cpp
@@ -49,23 +49,27 @@ int ScriptDebugger::get_depth() const {
}
void ScriptDebugger::insert_breakpoint(int p_line, const StringName &p_source) {
- if (!breakpoints.has(p_line))
+ if (!breakpoints.has(p_line)) {
breakpoints[p_line] = Set<StringName>();
+ }
breakpoints[p_line].insert(p_source);
}
void ScriptDebugger::remove_breakpoint(int p_line, const StringName &p_source) {
- if (!breakpoints.has(p_line))
+ if (!breakpoints.has(p_line)) {
return;
+ }
breakpoints[p_line].erase(p_source);
- if (breakpoints[p_line].size() == 0)
+ if (breakpoints[p_line].size() == 0) {
breakpoints.erase(p_line);
+ }
}
bool ScriptDebugger::is_breakpoint(int p_line, const StringName &p_source) const {
- if (!breakpoints.has(p_line))
+ if (!breakpoints.has(p_line)) {
return false;
+ }
return breakpoints[p_line].has(p_source);
}
diff --git a/core/dictionary.cpp b/core/dictionary.cpp
index 0ef26cfc62..052e1bdae1 100644
--- a/core/dictionary.cpp
+++ b/core/dictionary.cpp
@@ -40,8 +40,9 @@ struct DictionaryPrivate {
};
void Dictionary::get_key_list(List<Variant> *p_keys) const {
- if (_p->variant_map.empty())
+ if (_p->variant_map.empty()) {
return;
+ }
for (OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator>::Element E = _p->variant_map.front(); E; E = E.next()) {
p_keys->push_back(E.key());
@@ -83,24 +84,27 @@ const Variant &Dictionary::operator[](const Variant &p_key) const {
const Variant *Dictionary::getptr(const Variant &p_key) const {
OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator>::ConstElement E = ((const OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator> *)&_p->variant_map)->find(p_key);
- if (!E)
+ if (!E) {
return nullptr;
+ }
return &E.get();
}
Variant *Dictionary::getptr(const Variant &p_key) {
OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator>::Element E = _p->variant_map.find(p_key);
- if (!E)
+ if (!E) {
return nullptr;
+ }
return &E.get();
}
Variant Dictionary::get_valid(const Variant &p_key) const {
OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator>::ConstElement E = ((const OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator> *)&_p->variant_map)->find(p_key);
- if (!E)
+ if (!E) {
return Variant();
+ }
return E.get();
}
@@ -148,16 +152,18 @@ bool Dictionary::operator!=(const Dictionary &p_dictionary) const {
void Dictionary::_ref(const Dictionary &p_from) const {
//make a copy first (thread safe)
- if (!p_from._p->refcount.ref())
+ if (!p_from._p->refcount.ref()) {
return; // couldn't copy
+ }
//if this is the same, unreference the other one
if (p_from._p == _p) {
_p->refcount.unref();
return;
}
- if (_p)
+ if (_p) {
_unref();
+ }
_p = p_from._p;
}
@@ -186,8 +192,9 @@ uint32_t Dictionary::hash() const {
Array Dictionary::keys() const {
Array varr;
- if (_p->variant_map.empty())
+ if (_p->variant_map.empty()) {
return varr;
+ }
varr.resize(size());
@@ -202,8 +209,9 @@ Array Dictionary::keys() const {
Array Dictionary::values() const {
Array varr;
- if (_p->variant_map.empty())
+ if (_p->variant_map.empty()) {
return varr;
+ }
varr.resize(size());
@@ -219,14 +227,16 @@ Array Dictionary::values() const {
const Variant *Dictionary::next(const Variant *p_key) const {
if (p_key == nullptr) {
// caller wants to get the first element
- if (_p->variant_map.front())
+ if (_p->variant_map.front()) {
return &_p->variant_map.front().key();
+ }
return nullptr;
}
OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator>::Element E = _p->variant_map.find(*p_key);
- if (E && E.next())
+ if (E && E.next()) {
return &E.next().key();
+ }
return nullptr;
}
diff --git a/core/engine.cpp b/core/engine.cpp
index 25eac27921..43c5766431 100644
--- a/core/engine.cpp
+++ b/core/engine.cpp
@@ -46,8 +46,9 @@ int Engine::get_iterations_per_second() const {
}
void Engine::set_physics_jitter_fix(float p_threshold) {
- if (p_threshold < 0)
+ if (p_threshold < 0) {
p_threshold = 0;
+ }
physics_jitter_fix = p_threshold;
}
@@ -97,8 +98,9 @@ Dictionary Engine::get_version_info() const {
dict["hash"] = hash.length() == 0 ? String("unknown") : hash;
String stringver = String(dict["major"]) + "." + String(dict["minor"]);
- if ((int)dict["patch"] != 0)
+ if ((int)dict["patch"] != 0) {
stringver += "." + String(dict["patch"]);
+ }
stringver += "-" + String(dict["status"]) + " (" + String(dict["build"]) + ")";
dict["string"] = stringver;
@@ -193,8 +195,9 @@ bool Engine::has_singleton(const String &p_name) const {
};
void Engine::get_singletons(List<Singleton> *p_singletons) {
- for (List<Singleton>::Element *E = singletons.front(); E; E = E->next())
+ for (List<Singleton>::Element *E = singletons.front(); E; E = E->next()) {
p_singletons->push_back(E->get());
+ }
}
Engine *Engine::singleton = nullptr;
diff --git a/core/error_macros.cpp b/core/error_macros.cpp
index ff50c9786a..2fae939965 100644
--- a/core/error_macros.cpp
+++ b/core/error_macros.cpp
@@ -51,10 +51,11 @@ void remove_error_handler(ErrorHandlerList *p_handler) {
while (l) {
if (l == p_handler) {
- if (prev)
+ if (prev) {
prev->next = l->next;
- else
+ } else {
error_handler_list = l->next;
+ }
break;
}
prev = l;
diff --git a/core/func_ref.cpp b/core/func_ref.cpp
index 9c0e1698c2..4427d94d2a 100644
--- a/core/func_ref.cpp
+++ b/core/func_ref.cpp
@@ -65,12 +65,14 @@ void FuncRef::set_function(const StringName &p_func) {
}
bool FuncRef::is_valid() const {
- if (id.is_null())
+ if (id.is_null()) {
return false;
+ }
Object *obj = ObjectDB::get_instance(id);
- if (!obj)
+ if (!obj) {
return false;
+ }
return obj->has_method(function);
}
diff --git a/core/hash_map.h b/core/hash_map.h
index a4bc811b67..78592f8d82 100644
--- a/core/hash_map.h
+++ b/core/hash_map.h
@@ -104,8 +104,9 @@ private:
hash_table_power = MIN_HASH_TABLE_POWER;
elements = 0;
- for (int i = 0; i < (1 << MIN_HASH_TABLE_POWER); i++)
+ for (int i = 0; i < (1 << MIN_HASH_TABLE_POWER); i++) {
hash_table[i] = nullptr;
+ }
}
void erase_hash_table() {
@@ -136,12 +137,14 @@ private:
new_hash_table_power--;
}
- if (new_hash_table_power < (int)MIN_HASH_TABLE_POWER)
+ if (new_hash_table_power < (int)MIN_HASH_TABLE_POWER) {
new_hash_table_power = MIN_HASH_TABLE_POWER;
+ }
}
- if (new_hash_table_power == -1)
+ if (new_hash_table_power == -1) {
return;
+ }
Element **new_hash_table = memnew_arr(Element *, ((uint64_t)1 << new_hash_table_power));
ERR_FAIL_COND_MSG(!new_hash_table, "Out of memory.");
@@ -205,13 +208,15 @@ private:
}
void copy_from(const HashMap &p_t) {
- if (&p_t == this)
+ if (&p_t == this) {
return; /* much less bother with that */
+ }
clear();
- if (!p_t.hash_table || p_t.hash_table_power == 0)
+ if (!p_t.hash_table || p_t.hash_table_power == 0) {
return; /* not copying from empty table */
+ }
hash_table = memnew_arr(Element *, (uint64_t)1 << p_t.hash_table_power);
hash_table_power = p_t.hash_table_power;
@@ -243,17 +248,19 @@ public:
Element *set(const Pair &p_pair) {
Element *e = nullptr;
- if (!hash_table)
+ if (!hash_table) {
make_hash_table(); // if no table, make one
- else
+ } else {
e = const_cast<Element *>(get_element(p_pair.key));
+ }
/* if we made it up to here, the pair doesn't exist, create and assign */
if (!e) {
e = create_element(p_pair.key);
- if (!e)
+ if (!e) {
return nullptr;
+ }
check_hash_table(); // perform mantenience routine
}
@@ -289,25 +296,29 @@ public:
*/
_FORCE_INLINE_ TData *getptr(const TKey &p_key) {
- if (unlikely(!hash_table))
+ if (unlikely(!hash_table)) {
return nullptr;
+ }
Element *e = const_cast<Element *>(get_element(p_key));
- if (e)
+ if (e) {
return &e->pair.data;
+ }
return nullptr;
}
_FORCE_INLINE_ const TData *getptr(const TKey &p_key) const {
- if (unlikely(!hash_table))
+ if (unlikely(!hash_table)) {
return nullptr;
+ }
const Element *e = const_cast<Element *>(get_element(p_key));
- if (e)
+ if (e) {
return &e->pair.data;
+ }
return nullptr;
}
@@ -319,8 +330,9 @@ public:
template <class C>
_FORCE_INLINE_ TData *custom_getptr(C p_custom_key, uint32_t p_custom_hash) {
- if (unlikely(!hash_table))
+ if (unlikely(!hash_table)) {
return nullptr;
+ }
uint32_t hash = p_custom_hash;
uint32_t index = hash & ((1 << hash_table_power) - 1);
@@ -342,8 +354,9 @@ public:
template <class C>
_FORCE_INLINE_ const TData *custom_getptr(C p_custom_key, uint32_t p_custom_hash) const {
- if (unlikely(!hash_table))
+ if (unlikely(!hash_table)) {
return nullptr;
+ }
uint32_t hash = p_custom_hash;
uint32_t index = hash & ((1 << hash_table_power) - 1);
@@ -368,8 +381,9 @@ public:
*/
bool erase(const TKey &p_key) {
- if (unlikely(!hash_table))
+ if (unlikely(!hash_table)) {
return false;
+ }
uint32_t hash = Hasher::hash(p_key);
uint32_t index = hash & ((1 << hash_table_power) - 1);
@@ -389,10 +403,11 @@ public:
memdelete(e);
elements--;
- if (elements == 0)
+ if (elements == 0) {
erase_hash_table();
- else
+ } else {
check_hash_table();
+ }
return true;
}
@@ -410,10 +425,11 @@ public:
inline TData &operator[](const TKey &p_key) { //assignment
Element *e = nullptr;
- if (!hash_table)
+ if (!hash_table) {
make_hash_table(); // if no table, make one
- else
+ } else {
e = const_cast<Element *>(get_element(p_key));
+ }
/* if we made it up to here, the pair doesn't exist, create */
if (!e) {
@@ -441,8 +457,9 @@ public:
*
*/
const TKey *next(const TKey *p_key) const {
- if (unlikely(!hash_table))
+ if (unlikely(!hash_table)) {
return nullptr;
+ }
if (!p_key) { /* get the first key */
@@ -508,8 +525,9 @@ public:
}
void get_key_value_ptr_array(const Pair **p_pairs) const {
- if (unlikely(!hash_table))
+ if (unlikely(!hash_table)) {
return;
+ }
for (int i = 0; i < (1 << hash_table_power); i++) {
Element *e = hash_table[i];
while (e) {
@@ -521,8 +539,9 @@ public:
}
void get_key_list(List<TKey> *p_keys) const {
- if (unlikely(!hash_table))
+ if (unlikely(!hash_table)) {
return;
+ }
for (int i = 0; i < (1 << hash_table_power); i++) {
Element *e = hash_table[i];
while (e) {
diff --git a/core/hashfuncs.h b/core/hashfuncs.h
index ccecba5137..d984f6c524 100644
--- a/core/hashfuncs.h
+++ b/core/hashfuncs.h
@@ -53,8 +53,9 @@ static inline uint32_t hash_djb2(const char *p_cstr) {
uint32_t hash = 5381;
uint32_t c;
- while ((c = *chr++))
+ while ((c = *chr++)) {
hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
+ }
return hash;
}
@@ -62,8 +63,9 @@ static inline uint32_t hash_djb2(const char *p_cstr) {
static inline uint32_t hash_djb2_buffer(const uint8_t *p_buff, int p_len, uint32_t p_prev = 5381) {
uint32_t hash = p_prev;
- for (int i = 0; i < p_len; i++)
+ for (int i = 0; i < p_len; i++) {
hash = ((hash << 5) + hash) + p_buff[i]; /* hash * 33 + c */
+ }
return hash;
}
@@ -90,12 +92,13 @@ static inline uint32_t hash_djb2_one_float(double p_in, uint32_t p_prev = 5381)
} u;
// Normalize +/- 0.0 and NaN values so they hash the same.
- if (p_in == 0.0f)
+ if (p_in == 0.0f) {
u.d = 0.0;
- else if (Math::is_nan(p_in))
+ } else if (Math::is_nan(p_in)) {
u.d = Math_NAN;
- else
+ } else {
u.d = p_in;
+ }
return ((p_prev << 5) + p_prev) + hash_one_uint64(u.i);
}
diff --git a/core/image.cpp b/core/image.cpp
index 3fff93ed91..29be2ff5eb 100644
--- a/core/image.cpp
+++ b/core/image.cpp
@@ -244,12 +244,13 @@ void Image::get_format_min_pixel_size(Format p_format, int &r_w, int &r_h) {
}
int Image::get_format_pixel_rshift(Format p_format) {
- if (p_format == FORMAT_DXT1 || p_format == FORMAT_RGTC_R || p_format == FORMAT_PVRTC4 || p_format == FORMAT_PVRTC4A || p_format == FORMAT_ETC || p_format == FORMAT_ETC2_R11 || p_format == FORMAT_ETC2_R11S || p_format == FORMAT_ETC2_RGB8 || p_format == FORMAT_ETC2_RGB8A1)
+ if (p_format == FORMAT_DXT1 || p_format == FORMAT_RGTC_R || p_format == FORMAT_PVRTC4 || p_format == FORMAT_PVRTC4A || p_format == FORMAT_ETC || p_format == FORMAT_ETC2_R11 || p_format == FORMAT_ETC2_R11S || p_format == FORMAT_ETC2_RGB8 || p_format == FORMAT_ETC2_RGB8A1) {
return 1;
- else if (p_format == FORMAT_PVRTC2 || p_format == FORMAT_PVRTC2A)
+ } else if (p_format == FORMAT_PVRTC2 || p_format == FORMAT_PVRTC2A) {
return 2;
- else
+ } else {
return 0;
+ }
}
int Image::get_format_block_size(Format p_format) {
@@ -380,10 +381,11 @@ bool Image::has_mipmaps() const {
}
int Image::get_mipmap_count() const {
- if (mipmaps)
+ if (mipmaps) {
return get_image_required_mipmaps(width, height, format);
- else
+ } else {
return 0;
+ }
}
//using template generates perfectly optimized code due to constant expression reduction and unused variable removal present in all compilers
@@ -429,11 +431,13 @@ static void _convert(int p_width, int p_height, const uint8_t *p_src, uint8_t *p
}
void Image::convert(Format p_new_format) {
- if (data.size() == 0)
+ if (data.size() == 0) {
return;
+ }
- if (p_new_format == format)
+ if (p_new_format == format) {
return;
+ }
if (format > FORMAT_RGBE9995 || p_new_format > FORMAT_RGBE9995) {
ERR_FAIL_MSG("Cannot convert to <-> from compressed formats. Use compress() and decompress() instead.");
@@ -561,8 +565,9 @@ void Image::convert(Format p_new_format) {
_copy_internals_from(new_img);
- if (gen_mipmaps)
+ if (gen_mipmaps) {
generate_mipmaps();
+ }
}
Image::Format Image::get_format() const {
@@ -574,10 +579,11 @@ static double _bicubic_interp_kernel(double x) {
double bc = 0;
- if (x <= 1)
+ if (x <= 1) {
bc = (1.5 * x - 2.5) * x * x + 1;
- else if (x < 2)
+ } else if (x < 2) {
bc = ((-0.5 * x + 2.5) * x - 4) * x + 2;
+ }
return bc;
}
@@ -624,20 +630,24 @@ static void _scale_cubic(const uint8_t *__restrict p_src, uint8_t *__restrict p_
k1 = _bicubic_interp_kernel(dy - (double)n);
oy2 = oy1 + n;
- if (oy2 < 0)
+ if (oy2 < 0) {
oy2 = 0;
- if (oy2 > ymax)
+ }
+ if (oy2 > ymax) {
oy2 = ymax;
+ }
for (int m = -1; m < 3; m++) {
// get X coefficient
k2 = k1 * _bicubic_interp_kernel((double)m - dx);
ox2 = ox1 + m;
- if (ox2 < 0)
+ if (ox2 < 0) {
ox2 = 0;
- if (ox2 > xmax)
+ }
+ if (ox2 > xmax) {
ox2 = xmax;
+ }
// get pixel of original image
const T *__restrict p = ((T *)p_src) + (oy2 * p_src_width + ox2) * CC;
@@ -680,8 +690,9 @@ static void _scale_bilinear(const uint8_t *__restrict p_src, uint8_t *__restrict
uint32_t src_yofs_up = src_yofs_up_fp >> FRAC_BITS;
uint32_t src_yofs_down = (i + 1) * p_src_height / p_dst_height;
- if (src_yofs_down >= p_src_height)
+ if (src_yofs_down >= p_src_height) {
src_yofs_down = p_src_height - 1;
+ }
//src_yofs_up*=CC;
//src_yofs_down*=CC;
@@ -694,8 +705,9 @@ static void _scale_bilinear(const uint8_t *__restrict p_src, uint8_t *__restrict
uint32_t src_xofs_frac = src_xofs_left_fp & FRAC_MASK;
uint32_t src_xofs_left = src_xofs_left_fp >> FRAC_BITS;
uint32_t src_xofs_right = (j + 1) * p_src_width / p_dst_width;
- if (src_xofs_right >= p_src_width)
+ if (src_xofs_right >= p_src_width) {
src_xofs_right = p_src_width - 1;
+ }
src_xofs_left *= CC;
src_xofs_right *= CC;
@@ -805,8 +817,9 @@ static void _scale_lanczos(const uint8_t *__restrict p_src, uint8_t *__restrict
int32_t end_x = MIN(src_width - 1, int32_t(src_x) + half_kernel);
// Create the kernel used by all the pixels of the column
- for (int32_t target_x = start_x; target_x <= end_x; target_x++)
+ for (int32_t target_x = start_x; target_x <= end_x; target_x++) {
kernel[target_x - start_x] = _lanczos((target_x + 0.5f - src_x) / scale_factor);
+ }
for (int32_t buffer_y = 0; buffer_y < src_height; buffer_y++) {
float pixel[CC] = { 0 };
@@ -819,17 +832,19 @@ static void _scale_lanczos(const uint8_t *__restrict p_src, uint8_t *__restrict
const T *__restrict src_data = ((const T *)p_src) + (buffer_y * src_width + target_x) * CC;
for (uint32_t i = 0; i < CC; i++) {
- if (sizeof(T) == 2) //half float
+ if (sizeof(T) == 2) { //half float
pixel[i] += Math::half_to_float(src_data[i]) * lanczos_val;
- else
+ } else {
pixel[i] += src_data[i] * lanczos_val;
+ }
}
}
float *dst_data = ((float *)buffer) + (buffer_y * dst_width + buffer_x) * CC;
- for (uint32_t i = 0; i < CC; i++)
+ for (uint32_t i = 0; i < CC; i++) {
dst_data[i] = pixel[i] / weight; // Normalize the sum of all the samples
+ }
}
}
@@ -850,8 +865,9 @@ static void _scale_lanczos(const uint8_t *__restrict p_src, uint8_t *__restrict
int32_t start_y = MAX(0, int32_t(buffer_y) - half_kernel + 1);
int32_t end_y = MIN(src_height - 1, int32_t(buffer_y) + half_kernel);
- for (int32_t target_y = start_y; target_y <= end_y; target_y++)
+ for (int32_t target_y = start_y; target_y <= end_y; target_y++) {
kernel[target_y - start_y] = _lanczos((target_y + 0.5f - buffer_y) / scale_factor);
+ }
for (int32_t dst_x = 0; dst_x < dst_width; dst_x++) {
float pixel[CC] = { 0 };
@@ -863,8 +879,9 @@ static void _scale_lanczos(const uint8_t *__restrict p_src, uint8_t *__restrict
float *buffer_data = ((float *)buffer) + (target_y * dst_width + dst_x) * CC;
- for (uint32_t i = 0; i < CC; i++)
+ for (uint32_t i = 0; i < CC; i++) {
pixel[i] += buffer_data[i] * lanczos_val;
+ }
}
T *dst_data = ((T *)p_dst) + (dst_y * dst_width + dst_x) * CC;
@@ -872,12 +889,13 @@ static void _scale_lanczos(const uint8_t *__restrict p_src, uint8_t *__restrict
for (uint32_t i = 0; i < CC; i++) {
pixel[i] /= weight;
- if (sizeof(T) == 1) //byte
+ if (sizeof(T) == 1) { //byte
dst_data[i] = CLAMP(Math::fast_ftoi(pixel[i]), 0, 255);
- else if (sizeof(T) == 2) //half float
+ } else if (sizeof(T) == 2) { //half float
dst_data[i] = Math::make_half_float(pixel[i]);
- else // float
+ } else { // float
dst_data[i] = pixel[i];
+ }
}
}
}
@@ -910,8 +928,9 @@ void Image::resize_to_po2(bool p_square) {
}
if (w == width && h == height) {
- if (!p_square || w == h)
+ if (!p_square || w == h) {
return; //nothing to do
+ }
}
resize(w, h);
@@ -929,8 +948,9 @@ void Image::resize(int p_width, int p_height, Interpolation p_interpolation) {
ERR_FAIL_COND_MSG(p_height > MAX_HEIGHT, "Image height cannot be greater than " + itos(MAX_HEIGHT) + ".");
ERR_FAIL_COND_MSG(p_width * p_height > MAX_PIXELS, "Too many pixels for image, maximum is " + itos(MAX_PIXELS));
- if (p_width == width && p_height == height)
+ if (p_width == width && p_height == height) {
return;
+ }
Image dst(p_width, p_height, false, format);
@@ -1213,8 +1233,9 @@ void Image::resize(int p_width, int p_height, Interpolation p_interpolation) {
dst._copy_internals_from(dst2);
}
- if (had_mipmaps)
+ if (had_mipmaps) {
dst.generate_mipmaps();
+ }
_copy_internals_from(dst);
}
@@ -1233,8 +1254,9 @@ void Image::crop_from_point(int p_x, int p_y, int p_width, int p_height) {
will most likely either not be used much, or in critical areas, for now it won't, because
it's a waste of time. */
- if (p_width == width && p_height == height && p_x == 0 && p_y == 0)
+ if (p_width == width && p_height == height && p_x == 0 && p_y == 0) {
return;
+ }
uint8_t pdata[16]; //largest is 16
uint32_t pixel_size = get_format_pixel_size(format);
@@ -1250,8 +1272,9 @@ void Image::crop_from_point(int p_x, int p_y, int p_width, int p_height) {
for (int y = p_y; y < m_h; y++) {
for (int x = p_x; x < m_w; x++) {
if ((x >= width || y >= height)) {
- for (uint32_t i = 0; i < pixel_size; i++)
+ for (uint32_t i = 0; i < pixel_size; i++) {
pdata[i] = 0;
+ }
} else {
_get_pixelb(x, y, pixel_size, r, pdata);
}
@@ -1261,8 +1284,9 @@ void Image::crop_from_point(int p_x, int p_y, int p_width, int p_height) {
}
}
- if (has_mipmaps())
+ if (has_mipmaps()) {
dst.generate_mipmaps();
+ }
_copy_internals_from(dst);
}
@@ -1362,15 +1386,17 @@ int Image::_get_dst_image_size(int p_width, int p_height, Format p_format, int &
*r_mm_height = bh;
}
- if (p_mipmaps >= 0 && mm == p_mipmaps)
+ if (p_mipmaps >= 0 && mm == p_mipmaps) {
break;
+ }
if (p_mipmaps >= 0) {
w = MAX(minw, w >> 1);
h = MAX(minh, h >> 1);
} else {
- if (w == minw && h == minh)
+ if (w == minw && h == minh) {
break;
+ }
w = MAX(minw, w >> 1);
h = MAX(minh, h >> 1);
}
@@ -1429,8 +1455,9 @@ void Image::expand_x2_hq2x() {
Format current = format;
- if (current != FORMAT_RGBA8)
+ if (current != FORMAT_RGBA8) {
convert(FORMAT_RGBA8);
+ }
Vector<uint8_t> dest;
dest.resize(width * 2 * height * 2 * 4);
@@ -1448,8 +1475,9 @@ void Image::expand_x2_hq2x() {
height *= 2;
data = dest;
- if (current != FORMAT_RGBA8)
+ if (current != FORMAT_RGBA8) {
convert(current);
+ }
// FIXME: This is likely meant to use "used_mipmaps" as defined above, but if we do,
// we end up with a regression: GH-22747
@@ -1609,17 +1637,19 @@ Error Image::generate_mipmaps(bool p_renormalize) {
_generate_po2_mipmap<uint8_t, 2, false, Image::average_4_uint8, Image::renormalize_uint8>(&wp[prev_ofs], &wp[ofs], prev_w, prev_h);
break;
case FORMAT_RGB8:
- if (p_renormalize)
+ if (p_renormalize) {
_generate_po2_mipmap<uint8_t, 3, true, Image::average_4_uint8, Image::renormalize_uint8>(&wp[prev_ofs], &wp[ofs], prev_w, prev_h);
- else
+ } else {
_generate_po2_mipmap<uint8_t, 3, false, Image::average_4_uint8, Image::renormalize_uint8>(&wp[prev_ofs], &wp[ofs], prev_w, prev_h);
+ }
break;
case FORMAT_RGBA8:
- if (p_renormalize)
+ if (p_renormalize) {
_generate_po2_mipmap<uint8_t, 4, true, Image::average_4_uint8, Image::renormalize_uint8>(&wp[prev_ofs], &wp[ofs], prev_w, prev_h);
- else
+ } else {
_generate_po2_mipmap<uint8_t, 4, false, Image::average_4_uint8, Image::renormalize_uint8>(&wp[prev_ofs], &wp[ofs], prev_w, prev_h);
+ }
break;
case FORMAT_RF:
_generate_po2_mipmap<float, 1, false, Image::average_4_float, Image::renormalize_float>(reinterpret_cast<const float *>(&wp[prev_ofs]), reinterpret_cast<float *>(&wp[ofs]), prev_w, prev_h);
@@ -1628,17 +1658,19 @@ Error Image::generate_mipmaps(bool p_renormalize) {
_generate_po2_mipmap<float, 2, false, Image::average_4_float, Image::renormalize_float>(reinterpret_cast<const float *>(&wp[prev_ofs]), reinterpret_cast<float *>(&wp[ofs]), prev_w, prev_h);
break;
case FORMAT_RGBF:
- if (p_renormalize)
+ if (p_renormalize) {
_generate_po2_mipmap<float, 3, true, Image::average_4_float, Image::renormalize_float>(reinterpret_cast<const float *>(&wp[prev_ofs]), reinterpret_cast<float *>(&wp[ofs]), prev_w, prev_h);
- else
+ } else {
_generate_po2_mipmap<float, 3, false, Image::average_4_float, Image::renormalize_float>(reinterpret_cast<const float *>(&wp[prev_ofs]), reinterpret_cast<float *>(&wp[ofs]), prev_w, prev_h);
+ }
break;
case FORMAT_RGBAF:
- if (p_renormalize)
+ if (p_renormalize) {
_generate_po2_mipmap<float, 4, true, Image::average_4_float, Image::renormalize_float>(reinterpret_cast<const float *>(&wp[prev_ofs]), reinterpret_cast<float *>(&wp[ofs]), prev_w, prev_h);
- else
+ } else {
_generate_po2_mipmap<float, 4, false, Image::average_4_float, Image::renormalize_float>(reinterpret_cast<const float *>(&wp[prev_ofs]), reinterpret_cast<float *>(&wp[ofs]), prev_w, prev_h);
+ }
break;
case FORMAT_RH:
@@ -1648,24 +1680,27 @@ Error Image::generate_mipmaps(bool p_renormalize) {
_generate_po2_mipmap<uint16_t, 2, false, Image::average_4_half, Image::renormalize_half>(reinterpret_cast<const uint16_t *>(&wp[prev_ofs]), reinterpret_cast<uint16_t *>(&wp[ofs]), prev_w, prev_h);
break;
case FORMAT_RGBH:
- if (p_renormalize)
+ if (p_renormalize) {
_generate_po2_mipmap<uint16_t, 3, true, Image::average_4_half, Image::renormalize_half>(reinterpret_cast<const uint16_t *>(&wp[prev_ofs]), reinterpret_cast<uint16_t *>(&wp[ofs]), prev_w, prev_h);
- else
+ } else {
_generate_po2_mipmap<uint16_t, 3, false, Image::average_4_half, Image::renormalize_half>(reinterpret_cast<const uint16_t *>(&wp[prev_ofs]), reinterpret_cast<uint16_t *>(&wp[ofs]), prev_w, prev_h);
+ }
break;
case FORMAT_RGBAH:
- if (p_renormalize)
+ if (p_renormalize) {
_generate_po2_mipmap<uint16_t, 4, true, Image::average_4_half, Image::renormalize_half>(reinterpret_cast<const uint16_t *>(&wp[prev_ofs]), reinterpret_cast<uint16_t *>(&wp[ofs]), prev_w, prev_h);
- else
+ } else {
_generate_po2_mipmap<uint16_t, 4, false, Image::average_4_half, Image::renormalize_half>(reinterpret_cast<const uint16_t *>(&wp[prev_ofs]), reinterpret_cast<uint16_t *>(&wp[ofs]), prev_w, prev_h);
+ }
break;
case FORMAT_RGBE9995:
- if (p_renormalize)
+ if (p_renormalize) {
_generate_po2_mipmap<uint32_t, 1, true, Image::average_4_rgbe9995, Image::renormalize_rgbe9995>(reinterpret_cast<const uint32_t *>(&wp[prev_ofs]), reinterpret_cast<uint32_t *>(&wp[ofs]), prev_w, prev_h);
- else
+ } else {
_generate_po2_mipmap<uint32_t, 1, false, Image::average_4_rgbe9995, Image::renormalize_rgbe9995>(reinterpret_cast<const uint32_t *>(&wp[prev_ofs]), reinterpret_cast<uint32_t *>(&wp[ofs]), prev_w, prev_h);
+ }
break;
default: {
@@ -1877,11 +1912,13 @@ Error Image::generate_mipmap_roughness(RoughnessChannel p_roughness_channel, con
}
void Image::clear_mipmaps() {
- if (!mipmaps)
+ if (!mipmaps) {
return;
+ }
- if (empty())
+ if (empty()) {
return;
+ }
int ofs, w, h;
_get_mipmap_offset_and_size(1, ofs, w, h);
@@ -1984,15 +2021,17 @@ void Image::create(const char **p_xpm) {
}
//skip spaces
while (*line_ptr == ' ' || *line_ptr == '\t' || *line_ptr == 0) {
- if (*line_ptr == 0)
+ if (*line_ptr == 0) {
break;
+ }
line_ptr++;
}
if (*line_ptr == 'c') {
line_ptr++;
while (*line_ptr == ' ' || *line_ptr == '\t' || *line_ptr == 0) {
- if (*line_ptr == 0)
+ if (*line_ptr == 0) {
break;
+ }
line_ptr++;
}
@@ -2006,14 +2045,15 @@ void Image::create(const char **p_xpm) {
for (int i = 0; i < 6; i++) {
char v = line_ptr[i];
- if (v >= '0' && v <= '9')
+ if (v >= '0' && v <= '9') {
v -= '0';
- else if (v >= 'A' && v <= 'F')
+ } else if (v >= 'A' && v <= 'F') {
v = (v - 'A') + 10;
- else if (v >= 'a' && v <= 'f')
+ } else if (v >= 'a' && v <= 'f') {
v = (v - 'a') + 10;
- else
+ } else {
break;
+ }
switch (i) {
case 0:
@@ -2057,8 +2097,9 @@ void Image::create(const char **p_xpm) {
int y = line - colormap_size - 1;
for (int x = 0; x < size_width; x++) {
char pixelstr[6] = { 0, 0, 0, 0, 0, 0 };
- for (int i = 0; i < pixelchars; i++)
+ for (int i = 0; i < pixelchars; i++) {
pixelstr[i] = line_ptr[x * pixelchars + i];
+ }
Color *colorptr = colormap.getptr(pixelstr);
ERR_FAIL_COND(!colorptr);
@@ -2069,8 +2110,9 @@ void Image::create(const char **p_xpm) {
_put_pixelb(x, y, pixel_size, w, pixel);
}
- if (y == (size_height - 1))
+ if (y == (size_height - 1)) {
status = DONE;
+ }
} break;
default: {
}
@@ -2104,13 +2146,15 @@ void Image::create(const char **p_xpm) {
bool Image::is_invisible() const {
if (format == FORMAT_L8 ||
- format == FORMAT_RGB8 || format == FORMAT_RG8)
+ format == FORMAT_RGB8 || format == FORMAT_RG8) {
return false;
+ }
int len = data.size();
- if (len == 0)
+ if (len == 0) {
return true;
+ }
int w, h;
_get_mipmap_offset_and_size(1, len, w, h);
@@ -2150,8 +2194,9 @@ bool Image::is_invisible() const {
Image::AlphaMode Image::detect_alpha() const {
int len = data.size();
- if (len == 0)
+ if (len == 0) {
return ALPHA_NONE;
+ }
int w, h;
_get_mipmap_offset_and_size(1, len, w, h);
@@ -2185,12 +2230,13 @@ Image::AlphaMode Image::detect_alpha() const {
}
}
- if (detected)
+ if (detected) {
return ALPHA_BLEND;
- else if (bit)
+ } else if (bit) {
return ALPHA_BIT;
- else
+ } else {
return ALPHA_NONE;
+ }
}
Error Image::load(const String &p_path) {
@@ -2203,8 +2249,9 @@ Error Image::load(const String &p_path) {
}
Error Image::save_png(const String &p_path) const {
- if (save_png_func == nullptr)
+ if (save_png_func == nullptr) {
return ERR_UNAVAILABLE;
+ }
return save_png_func(p_path, Ref<Image>((Image *)this));
}
@@ -2218,8 +2265,9 @@ Vector<uint8_t> Image::save_png_to_buffer() const {
}
Error Image::save_exr(const String &p_path, bool p_grayscale) const {
- if (save_exr_func == nullptr)
+ if (save_exr_func == nullptr) {
return ERR_UNAVAILABLE;
+ }
return save_exr_func(p_path, Ref<Image>((Image *)this), p_grayscale);
}
@@ -2265,18 +2313,19 @@ bool Image::is_compressed() const {
}
Error Image::decompress() {
- if (((format >= FORMAT_DXT1 && format <= FORMAT_RGTC_RG) || (format == FORMAT_DXT5_RA_AS_RG)) && _image_decompress_bc)
+ if (((format >= FORMAT_DXT1 && format <= FORMAT_RGTC_RG) || (format == FORMAT_DXT5_RA_AS_RG)) && _image_decompress_bc) {
_image_decompress_bc(this);
- else if (format >= FORMAT_BPTC_RGBA && format <= FORMAT_BPTC_RGBFU && _image_decompress_bptc)
+ } else if (format >= FORMAT_BPTC_RGBA && format <= FORMAT_BPTC_RGBFU && _image_decompress_bptc) {
_image_decompress_bptc(this);
- else if (format >= FORMAT_PVRTC2 && format <= FORMAT_PVRTC4A && _image_decompress_pvrtc)
+ } else if (format >= FORMAT_PVRTC2 && format <= FORMAT_PVRTC4A && _image_decompress_pvrtc) {
_image_decompress_pvrtc(this);
- else if (format == FORMAT_ETC && _image_decompress_etc1)
+ } else if (format == FORMAT_ETC && _image_decompress_etc1) {
_image_decompress_etc1(this);
- else if (format >= FORMAT_ETC2_R11 && format <= FORMAT_ETC2_RA_AS_RG && _image_decompress_etc2)
+ } else if (format >= FORMAT_ETC2_R11 && format <= FORMAT_ETC2_RA_AS_RG && _image_decompress_etc2) {
_image_decompress_etc2(this);
- else
+ } else {
return ERR_UNAVAILABLE;
+ }
return OK;
}
@@ -2343,35 +2392,43 @@ Image::Image(int p_width, int p_height, bool p_mipmaps, Format p_format, const V
}
Rect2 Image::get_used_rect() const {
- if (format != FORMAT_LA8 && format != FORMAT_RGBA8 && format != FORMAT_RGBAF && format != FORMAT_RGBAH && format != FORMAT_RGBA4444 && format != FORMAT_RGB565)
+ if (format != FORMAT_LA8 && format != FORMAT_RGBA8 && format != FORMAT_RGBAF && format != FORMAT_RGBAH && format != FORMAT_RGBA4444 && format != FORMAT_RGB565) {
return Rect2(Point2(), Size2(width, height));
+ }
int len = data.size();
- if (len == 0)
+ if (len == 0) {
return Rect2();
+ }
int minx = 0xFFFFFF, miny = 0xFFFFFFF;
int maxx = -1, maxy = -1;
for (int j = 0; j < height; j++) {
for (int i = 0; i < width; i++) {
- if (!(get_pixel(i, j).a > 0))
+ if (!(get_pixel(i, j).a > 0)) {
continue;
- if (i > maxx)
+ }
+ if (i > maxx) {
maxx = i;
- if (j > maxy)
+ }
+ if (j > maxy) {
maxy = j;
- if (i < minx)
+ }
+ if (i < minx) {
minx = i;
- if (j < miny)
+ }
+ if (j < miny) {
miny = j;
+ }
}
}
- if (maxx == -1)
+ if (maxx == -1) {
return Rect2();
- else
+ } else {
return Rect2(minx, miny, maxx - minx + 1, maxy - miny + 1);
+ }
}
Ref<Image> Image::get_rect(const Rect2 &p_area) const {
@@ -2391,13 +2448,16 @@ void Image::blit_rect(const Ref<Image> &p_src, const Rect2 &p_src_rect, const Po
Rect2i clipped_src_rect = Rect2i(0, 0, p_src->width, p_src->height).clip(p_src_rect);
- if (p_dest.x < 0)
+ if (p_dest.x < 0) {
clipped_src_rect.position.x = ABS(p_dest.x);
- if (p_dest.y < 0)
+ }
+ if (p_dest.y < 0) {
clipped_src_rect.position.y = ABS(p_dest.y);
+ }
- if (clipped_src_rect.size.x <= 0 || clipped_src_rect.size.y <= 0)
+ if (clipped_src_rect.size.x <= 0 || clipped_src_rect.size.y <= 0) {
return;
+ }
Point2 src_underscan = Point2(MIN(0, p_src_rect.position.x), MIN(0, p_src_rect.position.y));
Rect2i dest_rect = Rect2i(0, 0, width, height).clip(Rect2i(p_dest - src_underscan, clipped_src_rect.size));
@@ -2443,13 +2503,16 @@ void Image::blit_rect_mask(const Ref<Image> &p_src, const Ref<Image> &p_mask, co
Rect2i clipped_src_rect = Rect2i(0, 0, p_src->width, p_src->height).clip(p_src_rect);
- if (p_dest.x < 0)
+ if (p_dest.x < 0) {
clipped_src_rect.position.x = ABS(p_dest.x);
- if (p_dest.y < 0)
+ }
+ if (p_dest.y < 0) {
clipped_src_rect.position.y = ABS(p_dest.y);
+ }
- if (clipped_src_rect.size.x <= 0 || clipped_src_rect.size.y <= 0)
+ if (clipped_src_rect.size.x <= 0 || clipped_src_rect.size.y <= 0) {
return;
+ }
Point2 src_underscan = Point2(MIN(0, p_src_rect.position.x), MIN(0, p_src_rect.position.y));
Rect2i dest_rect = Rect2i(0, 0, width, height).clip(Rect2i(p_dest - src_underscan, clipped_src_rect.size));
@@ -2494,13 +2557,16 @@ void Image::blend_rect(const Ref<Image> &p_src, const Rect2 &p_src_rect, const P
Rect2i clipped_src_rect = Rect2i(0, 0, p_src->width, p_src->height).clip(p_src_rect);
- if (p_dest.x < 0)
+ if (p_dest.x < 0) {
clipped_src_rect.position.x = ABS(p_dest.x);
- if (p_dest.y < 0)
+ }
+ if (p_dest.y < 0) {
clipped_src_rect.position.y = ABS(p_dest.y);
+ }
- if (clipped_src_rect.size.x <= 0 || clipped_src_rect.size.y <= 0)
+ if (clipped_src_rect.size.x <= 0 || clipped_src_rect.size.y <= 0) {
return;
+ }
Point2 src_underscan = Point2(MIN(0, p_src_rect.position.x), MIN(0, p_src_rect.position.y));
Rect2i dest_rect = Rect2i(0, 0, width, height).clip(Rect2i(p_dest - src_underscan, clipped_src_rect.size));
@@ -2541,13 +2607,16 @@ void Image::blend_rect_mask(const Ref<Image> &p_src, const Ref<Image> &p_mask, c
Rect2i clipped_src_rect = Rect2i(0, 0, p_src->width, p_src->height).clip(p_src_rect);
- if (p_dest.x < 0)
+ if (p_dest.x < 0) {
clipped_src_rect.position.x = ABS(p_dest.x);
- if (p_dest.y < 0)
+ }
+ if (p_dest.y < 0) {
clipped_src_rect.position.y = ABS(p_dest.y);
+ }
- if (clipped_src_rect.size.x <= 0 || clipped_src_rect.size.y <= 0)
+ if (clipped_src_rect.size.x <= 0 || clipped_src_rect.size.y <= 0) {
return;
+ }
Point2 src_underscan = Point2(MIN(0, p_src_rect.position.x), MIN(0, p_src_rect.position.y));
Rect2i dest_rect = Rect2i(0, 0, width, height).clip(Rect2i(p_dest - src_underscan, clipped_src_rect.size));
@@ -2892,14 +2961,18 @@ Image::UsedChannels Image::detect_used_channels(CompressSource p_source) {
for (int j = 0; j < height; j++) {
Color col = get_pixel(i, j);
- if (col.r > 0.001)
+ if (col.r > 0.001) {
r = true;
- if (col.g > 0.001)
+ }
+ if (col.g > 0.001) {
g = true;
- if (col.b > 0.001)
+ }
+ if (col.b > 0.001) {
b = true;
- if (col.a < 0.999)
+ }
+ if (col.a < 0.999) {
a = true;
+ }
if (col.r != col.b || col.r != col.g || col.b != col.g) {
c = true;
@@ -2909,18 +2982,19 @@ Image::UsedChannels Image::detect_used_channels(CompressSource p_source) {
UsedChannels used_channels;
- if (!c && !a)
+ if (!c && !a) {
used_channels = USED_CHANNELS_L;
- else if (!c && a)
+ } else if (!c && a) {
used_channels = USED_CHANNELS_LA;
- else if (r && !g && !b && !a)
+ } else if (r && !g && !b && !a) {
used_channels = USED_CHANNELS_R;
- else if (r && g && !b && !a)
+ } else if (r && g && !b && !a) {
used_channels = USED_CHANNELS_RG;
- else if (r && g && b && !a)
+ } else if (r && g && b && !a) {
used_channels = USED_CHANNELS_RGB;
- else
+ } else {
used_channels = USED_CHANNELS_RGBA;
+ }
if (p_source == COMPRESS_SOURCE_SRGB && (used_channels == USED_CHANNELS_R || used_channels == USED_CHANNELS_RG)) {
//R and RG do not support SRGB
@@ -3129,8 +3203,9 @@ void Image::normalmap_to_xy() {
}
Ref<Image> Image::rgbe_to_srgb() {
- if (data.size() == 0)
+ if (data.size() == 0) {
return Ref<Image>();
+ }
ERR_FAIL_COND_V(format != FORMAT_RGBE9995, Ref<Image>());
@@ -3193,13 +3268,15 @@ void Image::bumpmap_to_normalmap(float bump_scale) {
for (int ty = 0; ty < height; ty++) {
int py = ty + 1;
- if (py >= height)
+ if (py >= height) {
py -= height;
+ }
for (int tx = 0; tx < width; tx++) {
int px = tx + 1;
- if (px >= width)
+ if (px >= width) {
px -= width;
+ }
float here = read_ptr[ty * width + tx];
float to_right = read_ptr[ty * width + px];
float above = read_ptr[py * width + tx];
@@ -3221,8 +3298,9 @@ void Image::bumpmap_to_normalmap(float bump_scale) {
}
void Image::srgb_to_linear() {
- if (data.size() == 0)
+ if (data.size() == 0) {
return;
+ }
static const uint8_t srgb2lin[256] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 22, 22, 23, 23, 24, 24, 25, 26, 26, 27, 27, 28, 29, 29, 30, 31, 31, 32, 33, 33, 34, 35, 36, 36, 37, 38, 38, 39, 40, 41, 42, 42, 43, 44, 45, 46, 47, 47, 48, 49, 50, 51, 52, 53, 54, 55, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 70, 71, 72, 73, 74, 75, 76, 77, 78, 80, 81, 82, 83, 84, 85, 87, 88, 89, 90, 92, 93, 94, 95, 97, 98, 99, 101, 102, 103, 105, 106, 107, 109, 110, 112, 113, 114, 116, 117, 119, 120, 122, 123, 125, 126, 128, 129, 131, 132, 134, 135, 137, 139, 140, 142, 144, 145, 147, 148, 150, 152, 153, 155, 157, 159, 160, 162, 164, 166, 167, 169, 171, 173, 175, 176, 178, 180, 182, 184, 186, 188, 190, 192, 193, 195, 197, 199, 201, 203, 205, 207, 209, 211, 213, 215, 218, 220, 222, 224, 226, 228, 230, 232, 235, 237, 239, 241, 243, 245, 248, 250, 252, 255 };
@@ -3251,11 +3329,13 @@ void Image::srgb_to_linear() {
}
void Image::premultiply_alpha() {
- if (data.size() == 0)
+ if (data.size() == 0) {
return;
+ }
- if (format != FORMAT_RGBA8)
+ if (format != FORMAT_RGBA8) {
return; //not needed
+ }
uint8_t *data_ptr = data.ptrw();
@@ -3271,11 +3351,13 @@ void Image::premultiply_alpha() {
}
void Image::fix_alpha_edges() {
- if (data.size() == 0)
+ if (data.size() == 0) {
return;
+ }
- if (format != FORMAT_RGBA8)
+ if (format != FORMAT_RGBA8) {
return; //not needed
+ }
Vector<uint8_t> dcopy = data;
const uint8_t *srcptr = dcopy.ptr();
@@ -3291,8 +3373,9 @@ void Image::fix_alpha_edges() {
const uint8_t *rptr = &srcptr[(i * width + j) * 4];
uint8_t *wptr = &data_ptr[(i * width + j) * 4];
- if (rptr[3] >= alpha_threshold)
+ if (rptr[3] >= alpha_threshold) {
continue;
+ }
int closest_dist = max_dist;
uint8_t closest_color[3];
@@ -3307,13 +3390,15 @@ void Image::fix_alpha_edges() {
int dy = i - k;
int dx = j - l;
int dist = dy * dy + dx * dx;
- if (dist >= closest_dist)
+ if (dist >= closest_dist) {
continue;
+ }
const uint8_t *rp2 = &srcptr[(k * width + l) << 2];
- if (rp2[3] < alpha_threshold)
+ if (rp2[3] < alpha_threshold) {
continue;
+ }
closest_dist = dist;
closest_color[0] = rp2[0];
diff --git a/core/input/input.cpp b/core/input/input.cpp
index e81dfcf30f..dc1c207524 100644
--- a/core/input/input.cpp
+++ b/core/input/input.cpp
@@ -222,8 +222,9 @@ void Input::get_argument_options(const StringName &p_function, int p_idx, List<S
for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
const PropertyInfo &pi = E->get();
- if (!pi.name.begins_with("input/"))
+ if (!pi.name.begins_with("input/")) {
continue;
+ }
String name = pi.name.substr(pi.name.find("/") + 1, pi.name.length());
r_options->push_back(quote_style + name + quote_style);
@@ -241,8 +242,9 @@ void Input::SpeedTrack::update(const Vector2 &p_delta_p) {
accum += p_delta_p;
accum_t += delta_t;
- if (accum_t > max_ref_frame * 10)
+ if (accum_t > max_ref_frame * 10) {
accum_t = max_ref_frame * 10;
+ }
while (accum_t >= min_ref_frame) {
float slice_t = min_ref_frame / accum_t;
@@ -291,8 +293,9 @@ bool Input::is_action_pressed(const StringName &p_action) const {
bool Input::is_action_just_pressed(const StringName &p_action) const {
const Map<StringName, Action>::Element *E = action_state.find(p_action);
- if (!E)
+ if (!E) {
return false;
+ }
if (Engine::get_singleton()->is_in_physics_frame()) {
return E->get().pressed && E->get().physics_frame == Engine::get_singleton()->get_physics_frames();
@@ -303,8 +306,9 @@ bool Input::is_action_just_pressed(const StringName &p_action) const {
bool Input::is_action_just_released(const StringName &p_action) const {
const Map<StringName, Action>::Element *E = action_state.find(p_action);
- if (!E)
+ if (!E) {
return false;
+ }
if (Engine::get_singleton()->is_in_physics_frame()) {
return !E->get().pressed && E->get().physics_frame == Engine::get_singleton()->get_physics_frames();
@@ -315,8 +319,9 @@ bool Input::is_action_just_released(const StringName &p_action) const {
float Input::get_action_strength(const StringName &p_action) const {
const Map<StringName, Action>::Element *E = action_state.find(p_action);
- if (!E)
+ if (!E) {
return 0.0f;
+ }
return E->get().strength;
}
@@ -446,10 +451,11 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em
Ref<InputEventKey> k = p_event;
if (k.is_valid() && !k->is_echo() && k->get_keycode() != 0) {
- if (k->is_pressed())
+ if (k->is_pressed()) {
keys_pressed.insert(k->get_keycode());
- else
+ } else {
keys_pressed.erase(k->get_keycode());
+ }
}
Ref<InputEventMouseButton> mb = p_event;
@@ -568,10 +574,11 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em
if (jb.is_valid()) {
int c = _combine_device(jb->get_button_index(), jb->get_device());
- if (jb->is_pressed())
+ if (jb->is_pressed()) {
joy_buttons_pressed.insert(c);
- else
+ } else {
joy_buttons_pressed.erase(c);
+ }
}
Ref<InputEventJoypadMotion> jm = p_event;
@@ -603,8 +610,9 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em
}
}
- if (event_dispatch_function)
+ if (event_dispatch_function) {
event_dispatch_function(p_event);
+ }
}
void Input::set_joy_axis(int p_device, int p_axis, float p_value) {
@@ -776,8 +784,9 @@ Input::CursorShape Input::get_default_cursor_shape() const {
}
void Input::set_default_cursor_shape(CursorShape p_shape) {
- if (default_shape == p_shape)
+ if (default_shape == p_shape) {
return;
+ }
default_shape = p_shape;
// The default shape is set in Viewport::_gui_input_event. To instantly
@@ -794,8 +803,9 @@ Input::CursorShape Input::get_current_cursor_shape() const {
}
void Input::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot) {
- if (Engine::get_singleton()->is_editor_hint())
+ if (Engine::get_singleton()->is_editor_hint()) {
return;
+ }
set_custom_mouse_cursor_func(p_cursor, p_shape, p_hotspot);
}
@@ -833,8 +843,9 @@ void Input::release_pressed_events() {
_joy_axis.clear();
for (Map<StringName, Input::Action>::Element *E = action_state.front(); E; E = E->next()) {
- if (E->get().pressed)
+ if (E->get().pressed) {
action_release(E->key());
+ }
}
}
@@ -1064,8 +1075,9 @@ Input::JoyEvent Input::_get_mapped_axis_event(const JoyDeviceMapping &mapping, i
const JoyBinding binding = mapping.bindings[i];
if (binding.inputType == TYPE_AXIS && binding.input.axis.axis == p_axis) {
float value = p_value.value;
- if (binding.input.axis.invert)
+ if (binding.input.axis.invert) {
value = -value;
+ }
if (binding.input.axis.range == FULL_AXIS ||
(binding.input.axis.range == POSITIVE_HALF_AXIS && value > 0) ||
(binding.input.axis.range == NEGATIVE_HALF_AXIS && value < 0)) {
@@ -1152,16 +1164,18 @@ void Input::_get_mapped_hat_events(const JoyDeviceMapping &mapping, int p_hat, J
JoyButtonList Input::_get_output_button(String output) {
for (int i = 0; _joy_buttons[i]; i++) {
- if (output == _joy_buttons[i])
+ if (output == _joy_buttons[i]) {
return JoyButtonList(i);
+ }
}
return JoyButtonList::JOY_INVALID_BUTTON;
}
JoyAxisList Input::_get_output_axis(String output) {
for (int i = 0; _joy_axes[i]; i++) {
- if (output == _joy_axes[i])
+ if (output == _joy_axes[i]) {
return JoyAxisList(i);
+ }
}
return JoyAxisList::JOY_INVALID_AXIS;
}
@@ -1183,25 +1197,28 @@ void Input::parse_mapping(String p_mapping) {
int idx = 1;
while (++idx < entry.size()) {
- if (entry[idx] == "")
+ if (entry[idx] == "") {
continue;
+ }
String output = entry[idx].get_slice(":", 0).replace(" ", "");
String input = entry[idx].get_slice(":", 1).replace(" ", "");
ERR_CONTINUE_MSG(output.length() < 1 || input.length() < 2,
String(entry[idx] + "\nInvalid device mapping entry: " + entry[idx]));
- if (output == "platform")
+ if (output == "platform") {
continue;
+ }
JoyAxisRange output_range = FULL_AXIS;
if (output[0] == '+' || output[0] == '-') {
ERR_CONTINUE_MSG(output.length() < 2, String(entry[idx] + "\nInvalid output: " + entry[idx]));
output = output.right(1);
- if (output[0] == '+')
+ if (output[0] == '+') {
output_range = POSITIVE_HALF_AXIS;
- else if (output[0] == '-')
+ } else if (output[0] == '-') {
output_range = NEGATIVE_HALF_AXIS;
+ }
}
JoyAxisRange input_range = FULL_AXIS;
@@ -1213,8 +1230,9 @@ void Input::parse_mapping(String p_mapping) {
input = input.right(1);
}
bool invert_axis = false;
- if (input[input.length() - 1] == '~')
+ if (input[input.length() - 1] == '~') {
invert_axis = true;
+ }
JoyButtonList output_button = _get_output_button(output);
JoyAxisList output_axis = _get_output_axis(output);
@@ -1372,8 +1390,9 @@ Input::Input() {
if (env_mapping != "") {
Vector<String> entries = env_mapping.split("\n");
for (int i = 0; i < entries.size(); i++) {
- if (entries[i] == "")
+ if (entries[i] == "") {
continue;
+ }
parse_mapping(entries[i]);
}
}
diff --git a/core/input/input_event.cpp b/core/input/input_event.cpp
index 497ce79038..6ba082f86f 100644
--- a/core/input/input_event.cpp
+++ b/core/input/input_event.cpp
@@ -252,36 +252,45 @@ bool InputEventKey::is_echo() const {
uint32_t InputEventKey::get_keycode_with_modifiers() const {
uint32_t sc = keycode;
- if (get_control())
+ if (get_control()) {
sc |= KEY_MASK_CTRL;
- if (get_alt())
+ }
+ if (get_alt()) {
sc |= KEY_MASK_ALT;
- if (get_shift())
+ }
+ if (get_shift()) {
sc |= KEY_MASK_SHIFT;
- if (get_metakey())
+ }
+ if (get_metakey()) {
sc |= KEY_MASK_META;
+ }
return sc;
}
uint32_t InputEventKey::get_physical_keycode_with_modifiers() const {
uint32_t sc = physical_keycode;
- if (get_control())
+ if (get_control()) {
sc |= KEY_MASK_CTRL;
- if (get_alt())
+ }
+ if (get_alt()) {
sc |= KEY_MASK_ALT;
- if (get_shift())
+ }
+ if (get_shift()) {
sc |= KEY_MASK_SHIFT;
- if (get_metakey())
+ }
+ if (get_metakey()) {
sc |= KEY_MASK_META;
+ }
return sc;
}
String InputEventKey::as_text() const {
String kc = keycode_get_string(keycode);
- if (kc == String())
+ if (kc == String()) {
return kc;
+ }
if (get_metakey()) {
kc = find_keycode_name(KEY_META) + ("+" + kc);
@@ -300,8 +309,9 @@ String InputEventKey::as_text() const {
bool InputEventKey::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const {
Ref<InputEventKey> key = p_event;
- if (key.is_null())
+ if (key.is_null()) {
return false;
+ }
bool match = false;
if (get_keycode() == 0) {
@@ -316,18 +326,21 @@ bool InputEventKey::action_match(const Ref<InputEvent> &p_event, bool *p_pressed
match = get_keycode() == key->get_keycode() && (!key->is_pressed() || (code & event_code) == code);
}
if (match) {
- if (p_pressed != nullptr)
+ if (p_pressed != nullptr) {
*p_pressed = key->is_pressed();
- if (p_strength != nullptr)
+ }
+ if (p_strength != nullptr) {
*p_strength = (p_pressed != nullptr && *p_pressed) ? 1.0f : 0.0f;
+ }
}
return match;
}
bool InputEventKey::shortcut_match(const Ref<InputEvent> &p_event) const {
Ref<InputEventKey> key = p_event;
- if (key.is_null())
+ if (key.is_null()) {
return false;
+ }
uint32_t code = get_keycode_with_modifiers();
uint32_t event_code = key->get_keycode_with_modifiers();
@@ -459,15 +472,18 @@ Ref<InputEvent> InputEventMouseButton::xformed_by(const Transform2D &p_xform, co
bool InputEventMouseButton::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const {
Ref<InputEventMouseButton> mb = p_event;
- if (mb.is_null())
+ if (mb.is_null()) {
return false;
+ }
bool match = mb->button_index == button_index;
if (match) {
- if (p_pressed != nullptr)
+ if (p_pressed != nullptr) {
*p_pressed = mb->is_pressed();
- if (p_strength != nullptr)
+ }
+ if (p_strength != nullptr) {
*p_strength = (p_pressed != nullptr && *p_pressed) ? 1.0f : 0.0f;
+ }
}
return match;
@@ -616,8 +632,9 @@ String InputEventMouseMotion::as_text() const {
bool InputEventMouseMotion::accumulate(const Ref<InputEvent> &p_event) {
Ref<InputEventMouseMotion> motion = p_event;
- if (motion.is_null())
+ if (motion.is_null()) {
return false;
+ }
if (get_window_id() != motion->get_window_id()) {
return false;
@@ -698,15 +715,17 @@ bool InputEventJoypadMotion::is_pressed() const {
bool InputEventJoypadMotion::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const {
Ref<InputEventJoypadMotion> jm = p_event;
- if (jm.is_null())
+ if (jm.is_null()) {
return false;
+ }
bool match = (axis == jm->axis); // Matches even if not in the same direction, but returns a "not pressed" event.
if (match) {
bool same_direction = (((axis_value < 0) == (jm->axis_value < 0)) || jm->axis_value == 0);
bool pressed = same_direction ? Math::abs(jm->get_axis_value()) >= p_deadzone : false;
- if (p_pressed != nullptr)
+ if (p_pressed != nullptr) {
*p_pressed = pressed;
+ }
if (p_strength != nullptr) {
if (pressed) {
if (p_deadzone == 1.0f) {
@@ -765,15 +784,18 @@ float InputEventJoypadButton::get_pressure() const {
bool InputEventJoypadButton::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const {
Ref<InputEventJoypadButton> jb = p_event;
- if (jb.is_null())
+ if (jb.is_null()) {
return false;
+ }
bool match = button_index == jb->button_index;
if (match) {
- if (p_pressed != nullptr)
+ if (p_pressed != nullptr) {
*p_pressed = jb->is_pressed();
- if (p_strength != nullptr)
+ }
+ if (p_strength != nullptr) {
*p_strength = (p_pressed != nullptr && *p_pressed) ? 1.0f : 0.0f;
+ }
}
return match;
@@ -781,8 +803,9 @@ bool InputEventJoypadButton::action_match(const Ref<InputEvent> &p_event, bool *
bool InputEventJoypadButton::shortcut_match(const Ref<InputEvent> &p_event) const {
Ref<InputEventJoypadButton> button = p_event;
- if (button.is_null())
+ if (button.is_null()) {
return false;
+ }
return button_index == button->button_index;
}
@@ -963,8 +986,9 @@ float InputEventAction::get_strength() const {
}
bool InputEventAction::shortcut_match(const Ref<InputEvent> &p_event) const {
- if (p_event.is_null())
+ if (p_event.is_null()) {
return false;
+ }
return p_event->is_action(action);
}
@@ -975,15 +999,18 @@ bool InputEventAction::is_action(const StringName &p_action) const {
bool InputEventAction::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const {
Ref<InputEventAction> act = p_event;
- if (act.is_null())
+ if (act.is_null()) {
return false;
+ }
bool match = action == act->action;
if (match) {
- if (p_pressed != nullptr)
+ if (p_pressed != nullptr) {
*p_pressed = act->pressed;
- if (p_strength != nullptr)
+ }
+ if (p_strength != nullptr) {
*p_strength = (p_pressed != nullptr && *p_pressed) ? 1.0f : 0.0f;
+ }
}
return match;
}
diff --git a/core/input/input_map.cpp b/core/input/input_map.cpp
index d341b5ba4c..3cb4b43a26 100644
--- a/core/input/input_map.cpp
+++ b/core/input/input_map.cpp
@@ -70,8 +70,9 @@ void InputMap::erase_action(const StringName &p_action) {
Array InputMap::_get_actions() {
Array ret;
List<StringName> actions = get_actions();
- if (actions.empty())
+ if (actions.empty()) {
return ret;
+ }
for (const List<StringName>::Element *E = actions.front(); E; E = E->next()) {
ret.push_back(E->get());
@@ -124,8 +125,9 @@ void InputMap::action_set_deadzone(const StringName &p_action, float p_deadzone)
void InputMap::action_add_event(const StringName &p_action, const Ref<InputEvent> &p_event) {
ERR_FAIL_COND_MSG(p_event.is_null(), "It's not a reference to a valid InputEvent object.");
ERR_FAIL_COND_MSG(!input_map.has(p_action), "Request for nonexistent InputMap action '" + String(p_action) + "'.");
- if (_find_event(input_map[p_action], p_event))
+ if (_find_event(input_map[p_action], p_event)) {
return; //already gots
+ }
input_map[p_action].inputs.push_back(p_event);
}
@@ -139,8 +141,9 @@ void InputMap::action_erase_event(const StringName &p_action, const Ref<InputEve
ERR_FAIL_COND_MSG(!input_map.has(p_action), "Request for nonexistent InputMap action '" + String(p_action) + "'.");
List<Ref<InputEvent>>::Element *E = _find_event(input_map[p_action], p_event);
- if (E)
+ if (E) {
input_map[p_action].inputs.erase(E);
+ }
}
void InputMap::action_erase_events(const StringName &p_action) {
@@ -163,8 +166,9 @@ Array InputMap::_get_action_list(const StringName &p_action) {
const List<Ref<InputEvent>> *InputMap::get_action_list(const StringName &p_action) {
const Map<StringName, Action>::Element *E = input_map.find(p_action);
- if (!E)
+ if (!E) {
return nullptr;
+ }
return &E->get().inputs;
}
@@ -179,10 +183,12 @@ bool InputMap::event_get_action_status(const Ref<InputEvent> &p_event, const Str
Ref<InputEventAction> input_event_action = p_event;
if (input_event_action.is_valid()) {
- if (p_pressed != nullptr)
+ if (p_pressed != nullptr) {
*p_pressed = input_event_action->is_pressed();
- if (p_strength != nullptr)
+ }
+ if (p_strength != nullptr) {
*p_strength = (p_pressed != nullptr && *p_pressed) ? input_event_action->get_strength() : 0.0f;
+ }
return input_event_action->get_action() == p_action;
}
@@ -190,10 +196,12 @@ bool InputMap::event_get_action_status(const Ref<InputEvent> &p_event, const Str
float strength;
List<Ref<InputEvent>>::Element *event = _find_event(E->get(), p_event, &pressed, &strength);
if (event != nullptr) {
- if (p_pressed != nullptr)
+ if (p_pressed != nullptr) {
*p_pressed = pressed;
- if (p_strength != nullptr)
+ }
+ if (p_strength != nullptr) {
*p_strength = strength;
+ }
return true;
} else {
return false;
@@ -213,8 +221,9 @@ void InputMap::load_from_globals() {
for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
const PropertyInfo &pi = E->get();
- if (!pi.name.begins_with("input/"))
+ if (!pi.name.begins_with("input/")) {
continue;
+ }
String name = pi.name.substr(pi.name.find("/") + 1, pi.name.length());
@@ -225,8 +234,9 @@ void InputMap::load_from_globals() {
add_action(name, deadzone);
for (int i = 0; i < events.size(); i++) {
Ref<InputEvent> event = events[i];
- if (event.is_null())
+ if (event.is_null()) {
continue;
+ }
action_add_event(name, event);
}
}
diff --git a/core/io/compression.cpp b/core/io/compression.cpp
index 1b6786d888..99ca8107e4 100644
--- a/core/io/compression.cpp
+++ b/core/io/compression.cpp
@@ -62,8 +62,9 @@ int Compression::compress(uint8_t *p_dst, const uint8_t *p_src, int p_src_size,
strm.opaque = Z_NULL;
int level = p_mode == MODE_DEFLATE ? zlib_level : gzip_level;
int err = deflateInit2(&strm, level, Z_DEFLATED, window_bits, 8, Z_DEFAULT_STRATEGY);
- if (err != Z_OK)
+ if (err != Z_OK) {
return -1;
+ }
strm.avail_in = p_src_size;
int aout = deflateBound(&strm, p_src_size);
@@ -97,8 +98,9 @@ int Compression::get_max_compressed_buffer_size(int p_src_size, Mode p_mode) {
switch (p_mode) {
case MODE_FASTLZ: {
int ss = p_src_size + p_src_size * 6 / 100;
- if (ss < 66)
+ if (ss < 66) {
ss = 66;
+ }
return ss;
} break;
@@ -111,8 +113,9 @@ int Compression::get_max_compressed_buffer_size(int p_src_size, Mode p_mode) {
strm.zfree = zipio_free;
strm.opaque = Z_NULL;
int err = deflateInit2(&strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED, window_bits, 8, Z_DEFAULT_STRATEGY);
- if (err != Z_OK)
+ if (err != Z_OK) {
return -1;
+ }
int aout = deflateBound(&strm, p_src_size);
deflateEnd(&strm);
return aout;
diff --git a/core/io/config_file.cpp b/core/io/config_file.cpp
index 334c8f143e..1af9142317 100644
--- a/core/io/config_file.cpp
+++ b/core/io/config_file.cpp
@@ -63,8 +63,9 @@ PackedStringArray ConfigFile::_get_section_keys(const String &p_section) const {
void ConfigFile::set_value(const String &p_section, const String &p_key, const Variant &p_value) {
if (p_value.get_type() == Variant::NIL) {
//erase
- if (!values.has(p_section))
+ if (!values.has(p_section)) {
return; // ?
+ }
values[p_section].erase(p_key);
if (values[p_section].empty()) {
values.erase(p_section);
@@ -94,8 +95,9 @@ bool ConfigFile::has_section(const String &p_section) const {
}
bool ConfigFile::has_section_key(const String &p_section, const String &p_key) const {
- if (!values.has(p_section))
+ if (!values.has(p_section)) {
return false;
+ }
return values[p_section].has(p_key);
}
@@ -130,8 +132,9 @@ Error ConfigFile::save(const String &p_path) {
FileAccess *file = FileAccess::open(p_path, FileAccess::WRITE, &err);
if (err) {
- if (file)
+ if (file) {
memdelete(file);
+ }
return err;
}
@@ -142,8 +145,9 @@ Error ConfigFile::save_encrypted(const String &p_path, const Vector<uint8_t> &p_
Error err;
FileAccess *f = FileAccess::open(p_path, FileAccess::WRITE, &err);
- if (err)
+ if (err) {
return err;
+ }
FileAccessEncrypted *fae = memnew(FileAccessEncrypted);
err = fae->open_and_parse(f, p_key, FileAccessEncrypted::MODE_WRITE_AES256);
@@ -159,8 +163,9 @@ Error ConfigFile::save_encrypted_pass(const String &p_path, const String &p_pass
Error err;
FileAccess *f = FileAccess::open(p_path, FileAccess::WRITE, &err);
- if (err)
+ if (err) {
return err;
+ }
FileAccessEncrypted *fae = memnew(FileAccessEncrypted);
err = fae->open_and_parse_password(f, p_pass, FileAccessEncrypted::MODE_WRITE_AES256);
@@ -175,8 +180,9 @@ Error ConfigFile::save_encrypted_pass(const String &p_path, const String &p_pass
Error ConfigFile::_internal_save(FileAccess *file) {
for (OrderedHashMap<String, OrderedHashMap<String, Variant>>::Element E = values.front(); E; E = E.next()) {
- if (E != values.front())
+ if (E != values.front()) {
file->store_string("\n");
+ }
file->store_string("[" + E.key() + "]\n\n");
for (OrderedHashMap<String, Variant>::Element F = E.get().front(); F; F = F.next()) {
@@ -195,8 +201,9 @@ Error ConfigFile::load(const String &p_path) {
Error err;
FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err);
- if (!f)
+ if (!f) {
return err;
+ }
return _internal_load(p_path, f);
}
@@ -205,8 +212,9 @@ Error ConfigFile::load_encrypted(const String &p_path, const Vector<uint8_t> &p_
Error err;
FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err);
- if (err)
+ if (err) {
return err;
+ }
FileAccessEncrypted *fae = memnew(FileAccessEncrypted);
err = fae->open_and_parse(f, p_key, FileAccessEncrypted::MODE_READ);
@@ -222,8 +230,9 @@ Error ConfigFile::load_encrypted_pass(const String &p_path, const String &p_pass
Error err;
FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err);
- if (err)
+ if (err) {
return err;
+ }
FileAccessEncrypted *fae = memnew(FileAccessEncrypted);
err = fae->open_and_parse_password(f, p_pass, FileAccessEncrypted::MODE_READ);
diff --git a/core/io/file_access_compressed.cpp b/core/io/file_access_compressed.cpp
index 422100010c..7817ccb773 100644
--- a/core/io/file_access_compressed.cpp
+++ b/core/io/file_access_compressed.cpp
@@ -34,11 +34,12 @@
void FileAccessCompressed::configure(const String &p_magic, Compression::Mode p_mode, int p_block_size) {
magic = p_magic.ascii().get_data();
- if (magic.length() > 4)
+ if (magic.length() > 4) {
magic = magic.substr(0, 4);
- else {
- while (magic.length() < 4)
+ } else {
+ while (magic.length() < 4) {
magic += " ";
+ }
}
cmode = p_mode;
@@ -97,8 +98,9 @@ Error FileAccessCompressed::open_after_magic(FileAccess *p_base) {
Error FileAccessCompressed::_open(const String &p_path, int p_mode_flags) {
ERR_FAIL_COND_V(p_mode_flags == READ_WRITE, ERR_UNAVAILABLE);
- if (f)
+ if (f) {
close();
+ }
Error err;
f = FileAccess::open(p_path, p_mode_flags, &err);
@@ -134,8 +136,9 @@ Error FileAccessCompressed::_open(const String &p_path, int p_mode_flags) {
}
void FileAccessCompressed::close() {
- if (!f)
+ if (!f) {
return;
+ }
if (writing) {
//save block table and all compressed blocks
@@ -165,8 +168,9 @@ void FileAccessCompressed::close() {
}
f->seek(16); //ok write block sizes
- for (int i = 0; i < bc; i++)
+ for (int i = 0; i < bc; i++) {
f->store_32(block_sizes[i]);
+ }
f->seek_end();
f->store_buffer((const uint8_t *)mgc.get_data(), mgc.length()); //magic at the end too
@@ -306,8 +310,9 @@ int FileAccessCompressed::get_buffer(uint8_t *p_dst, int p_length) const {
} else {
read_block--;
at_end = true;
- if (i < p_length - 1)
+ if (i < p_length - 1) {
read_eof = true;
+ }
return i;
}
}
@@ -337,22 +342,25 @@ void FileAccessCompressed::store_8(uint8_t p_dest) {
bool FileAccessCompressed::file_exists(const String &p_name) {
FileAccess *fa = FileAccess::open(p_name, FileAccess::READ);
- if (!fa)
+ if (!fa) {
return false;
+ }
memdelete(fa);
return true;
}
uint64_t FileAccessCompressed::_get_modified_time(const String &p_file) {
- if (f)
+ if (f) {
return f->get_modified_time(p_file);
- else
+ } else {
return 0;
+ }
}
uint32_t FileAccessCompressed::_get_unix_permissions(const String &p_file) {
- if (f)
+ if (f) {
return f->_get_unix_permissions(p_file);
+ }
return 0;
}
@@ -364,6 +372,7 @@ Error FileAccessCompressed::_set_unix_permissions(const String &p_file, uint32_t
}
FileAccessCompressed::~FileAccessCompressed() {
- if (f)
+ if (f) {
close();
+ }
}
diff --git a/core/io/file_access_encrypted.cpp b/core/io/file_access_encrypted.cpp
index ceda6c5eb2..5938914cb0 100644
--- a/core/io/file_access_encrypted.cpp
+++ b/core/io/file_access_encrypted.cpp
@@ -115,8 +115,9 @@ Error FileAccessEncrypted::_open(const String &p_path, int p_mode_flags) {
}
void FileAccessEncrypted::close() {
- if (!file)
+ if (!file) {
return;
+ }
if (writing) {
Vector<uint8_t> compressed;
@@ -166,22 +167,25 @@ bool FileAccessEncrypted::is_open() const {
}
String FileAccessEncrypted::get_path() const {
- if (file)
+ if (file) {
return file->get_path();
- else
+ } else {
return "";
+ }
}
String FileAccessEncrypted::get_path_absolute() const {
- if (file)
+ if (file) {
return file->get_path_absolute();
- else
+ } else {
return "";
+ }
}
void FileAccessEncrypted::seek(size_t p_position) {
- if (p_position > (size_t)data.size())
+ if (p_position > (size_t)data.size()) {
p_position = data.size();
+ }
pos = p_position;
eofed = false;
@@ -270,8 +274,9 @@ void FileAccessEncrypted::store_8(uint8_t p_dest) {
bool FileAccessEncrypted::file_exists(const String &p_name) {
FileAccess *fa = FileAccess::open(p_name, FileAccess::READ);
- if (!fa)
+ if (!fa) {
return false;
+ }
memdelete(fa);
return true;
}
@@ -290,6 +295,7 @@ Error FileAccessEncrypted::_set_unix_permissions(const String &p_file, uint32_t
}
FileAccessEncrypted::~FileAccessEncrypted() {
- if (file)
+ if (file) {
close();
+ }
}
diff --git a/core/io/file_access_memory.cpp b/core/io/file_access_memory.cpp
index 790f946752..3c5f846941 100644
--- a/core/io/file_access_memory.cpp
+++ b/core/io/file_access_memory.cpp
@@ -43,18 +43,20 @@ void FileAccessMemory::register_file(String p_name, Vector<uint8_t> p_data) {
}
String name;
- if (ProjectSettings::get_singleton())
+ if (ProjectSettings::get_singleton()) {
name = ProjectSettings::get_singleton()->globalize_path(p_name);
- else
+ } else {
name = p_name;
+ }
//name = DirAccess::normalize_path(name);
(*files)[name] = p_data;
}
void FileAccessMemory::cleanup() {
- if (!files)
+ if (!files) {
return;
+ }
memdelete(files);
}
diff --git a/core/io/file_access_network.cpp b/core/io/file_access_network.cpp
index 4b7f99e5b0..6890740d90 100644
--- a/core/io/file_access_network.cpp
+++ b/core/io/file_access_network.cpp
@@ -115,8 +115,9 @@ void FileAccessNetworkClient::_thread_func() {
}
}
- if (accesses.has(id))
+ if (accesses.has(id)) {
fa = accesses[id];
+ }
switch (response) {
case FileAccessNetwork::RESPONSE_OPEN: {
@@ -140,8 +141,9 @@ void FileAccessNetworkClient::_thread_func() {
block.resize(len);
client->get_data(block.ptrw(), len);
- if (fa) //may have been queued
+ if (fa) { //may have been queued
fa->_set_block(offset, block);
+ }
} break;
case FileAccessNetwork::RESPONSE_FILE_EXISTS: {
@@ -244,8 +246,9 @@ void FileAccessNetwork::_set_block(int p_offset, const Vector<uint8_t> &p_block)
void FileAccessNetwork::_respond(size_t p_len, Error p_status) {
DEBUG_PRINT("GOT RESPONSE - len: " + itos(p_len) + " status: " + itos(p_status));
response = p_status;
- if (response != OK)
+ if (response != OK) {
return;
+ }
opened = true;
total_size = p_len;
int pc = ((total_size - 1) / page_size) + 1;
@@ -254,8 +257,9 @@ void FileAccessNetwork::_respond(size_t p_len, Error p_status) {
Error FileAccessNetwork::_open(const String &p_path, int p_mode_flags) {
ERR_FAIL_COND_V(p_mode_flags != READ, ERR_UNAVAILABLE);
- if (opened)
+ if (opened) {
close();
+ }
FileAccessNetworkClient *nc = FileAccessNetworkClient::singleton;
DEBUG_PRINT("open: " + p_path);
@@ -287,8 +291,9 @@ Error FileAccessNetwork::_open(const String &p_path, int p_mode_flags) {
}
void FileAccessNetwork::close() {
- if (!opened)
+ if (!opened) {
return;
+ }
FileAccessNetworkClient *nc = FileAccessNetworkClient::singleton;
@@ -342,8 +347,9 @@ uint8_t FileAccessNetwork::get_8() const {
}
void FileAccessNetwork::_queue_page(int p_page) const {
- if (p_page >= pages.size())
+ if (p_page >= pages.size()) {
return;
+ }
if (pages[p_page].buffer.empty() && !pages[p_page].queued) {
FileAccessNetworkClient *nc = FileAccessNetworkClient::singleton;
{
diff --git a/core/io/file_access_pack.cpp b/core/io/file_access_pack.cpp
index bb65a1afbc..00c4e76efe 100644
--- a/core/io/file_access_pack.cpp
+++ b/core/io/file_access_pack.cpp
@@ -54,12 +54,14 @@ void PackedData::add_path(const String &pkg_path, const String &path, uint64_t o
pf.pack = pkg_path;
pf.offset = ofs;
pf.size = size;
- for (int i = 0; i < 16; i++)
+ for (int i = 0; i < 16; i++) {
pf.md5[i] = p_md5[i];
+ }
pf.src = p_src;
- if (!exists || p_replace_files)
+ if (!exists || p_replace_files) {
files[pmd5] = pf;
+ }
if (!exists) {
//search for dir
@@ -106,8 +108,9 @@ PackedData::PackedData() {
}
void PackedData::_free_packed_dirs(PackedDir *p_dir) {
- for (Map<String, PackedDir *>::Element *E = p_dir->subdirs.front(); E; E = E->next())
+ for (Map<String, PackedDir *>::Element *E = p_dir->subdirs.front(); E; E = E->next()) {
_free_packed_dirs(E->get());
+ }
memdelete(p_dir);
}
@@ -122,8 +125,9 @@ PackedData::~PackedData() {
bool PackedSourcePCK::try_open_pack(const String &p_path, bool p_replace_files) {
FileAccess *f = FileAccess::open(p_path, FileAccess::READ);
- if (!f)
+ if (!f) {
return false;
+ }
uint32_t magic = f->get_32();
@@ -252,8 +256,9 @@ uint8_t FileAccessPack::get_8() const {
}
int FileAccessPack::get_buffer(uint8_t *p_dst, int p_length) const {
- if (eof)
+ if (eof) {
return 0;
+ }
uint64_t to_read = p_length;
if (to_read + pos > pf.size) {
@@ -263,8 +268,9 @@ int FileAccessPack::get_buffer(uint8_t *p_dst, int p_length) const {
pos += p_length;
- if (to_read <= 0)
+ if (to_read <= 0) {
return 0;
+ }
f->get_buffer(p_dst, to_read);
return to_read;
@@ -276,8 +282,9 @@ void FileAccessPack::set_endian_swap(bool p_swap) {
}
Error FileAccessPack::get_error() const {
- if (eof)
+ if (eof) {
return ERR_FILE_EOF;
+ }
return OK;
}
@@ -308,8 +315,9 @@ FileAccessPack::FileAccessPack(const String &p_path, const PackedData::PackedFil
}
FileAccessPack::~FileAccessPack() {
- if (f)
+ if (f) {
memdelete(f);
+ }
}
//////////////////////////////////////////////////////////////////////////////////
@@ -378,8 +386,9 @@ Error DirAccessPack::change_dir(String p_dir) {
nd = nd.simplify_path();
- if (nd == "")
+ if (nd == "") {
nd = ".";
+ }
if (nd.begins_with("/")) {
nd = nd.replace_first("/", "");
@@ -390,10 +399,11 @@ Error DirAccessPack::change_dir(String p_dir) {
PackedData::PackedDir *pd;
- if (absolute)
+ if (absolute) {
pd = PackedData::get_singleton()->root;
- else
+ } else {
pd = current;
+ }
for (int i = 0; i < paths.size(); i++) {
String p = paths[i];
diff --git a/core/io/file_access_pack.h b/core/io/file_access_pack.h
index a5d4c1f1b6..320a6cb216 100644
--- a/core/io/file_access_pack.h
+++ b/core/io/file_access_pack.h
@@ -175,10 +175,12 @@ public:
FileAccess *PackedData::try_open_path(const String &p_path) {
PathMD5 pmd5(p_path.md5_buffer());
Map<PathMD5, PackedFile>::Element *E = files.find(pmd5);
- if (!E)
+ if (!E) {
return nullptr; //not found
- if (E->get().offset == 0)
+ }
+ if (E->get().offset == 0) {
return nullptr; //was erased
+ }
return E->get().src->get_file(p_path, &E->get());
}
diff --git a/core/io/file_access_zip.cpp b/core/io/file_access_zip.cpp
index 5dde5aa6ce..c3a62706c7 100644
--- a/core/io/file_access_zip.cpp
+++ b/core/io/file_access_zip.cpp
@@ -149,14 +149,16 @@ unzFile ZipArchive::get_file_handle(String p_file) const {
bool ZipArchive::try_open_pack(const String &p_path, bool p_replace_files) {
//printf("opening zip pack %ls, %i, %i\n", p_name.c_str(), p_name.extension().nocasecmp_to("zip"), p_name.extension().nocasecmp_to("pcz"));
- if (p_path.get_extension().nocasecmp_to("zip") != 0 && p_path.get_extension().nocasecmp_to("pcz") != 0)
+ if (p_path.get_extension().nocasecmp_to("zip") != 0 && p_path.get_extension().nocasecmp_to("pcz") != 0) {
return false;
+ }
zlib_filefunc_def io;
FileAccess *fa = FileAccess::open(p_path, FileAccess::READ);
- if (!fa)
+ if (!fa) {
return false;
+ }
io.opaque = fa;
io.zopen_file = godot_open;
io.zread_file = godot_read;
@@ -252,8 +254,9 @@ Error FileAccessZip::_open(const String &p_path, int p_mode_flags) {
}
void FileAccessZip::close() {
- if (!zfile)
+ if (!zfile) {
return;
+ }
ZipArchive *arch = ZipArchive::get_singleton();
ERR_FAIL_COND(!arch);
@@ -300,12 +303,14 @@ uint8_t FileAccessZip::get_8() const {
int FileAccessZip::get_buffer(uint8_t *p_dst, int p_length) const {
ERR_FAIL_COND_V(!zfile, -1);
at_eof = unzeof(zfile);
- if (at_eof)
+ if (at_eof) {
return 0;
+ }
int read = unzReadCurrentFile(zfile, p_dst, p_length);
ERR_FAIL_COND_V(read < 0, read);
- if (read < p_length)
+ if (read < p_length) {
at_eof = true;
+ }
return read;
}
diff --git a/core/io/http_client.cpp b/core/io/http_client.cpp
index 2a1a435b8e..40debae9e5 100644
--- a/core/io/http_client.cpp
+++ b/core/io/http_client.cpp
@@ -240,8 +240,9 @@ int HTTPClient::get_response_code() const {
}
Error HTTPClient::get_response_headers(List<String> *r_response) {
- if (!response_headers.size())
+ if (!response_headers.size()) {
return ERR_INVALID_PARAMETER;
+ }
for (int i = 0; i < response_headers.size(); i++) {
r_response->push_back(response_headers[i]);
@@ -253,8 +254,9 @@ Error HTTPClient::get_response_headers(List<String> *r_response) {
}
void HTTPClient::close() {
- if (tcp_connection->get_status() != StreamPeerTCP::STATUS_NONE)
+ if (tcp_connection->get_status() != StreamPeerTCP::STATUS_NONE) {
tcp_connection->disconnect_from_host();
+ }
connection.unref();
status = STATUS_DISCONNECTED;
@@ -393,8 +395,9 @@ Error HTTPClient::poll() {
return ERR_CONNECTION_ERROR;
}
- if (rec == 0)
+ if (rec == 0) {
return OK; // Still requesting, keep trying!
+ }
response_str.push_back(byte);
int rs = response_str.size();
@@ -424,8 +427,9 @@ Error HTTPClient::poll() {
for (int i = 0; i < responses.size(); i++) {
String header = responses[i].strip_edges();
String s = header.to_lower();
- if (s.length() == 0)
+ if (s.length() == 0) {
continue;
+ }
if (s.begins_with("content-length:")) {
body_size = s.substr(s.find(":") + 1, s.length()).strip_edges().to_int();
body_left = body_size;
@@ -501,8 +505,9 @@ PackedByteArray HTTPClient::read_response_body_chunk() {
int rec = 0;
err = _get_http_data(&b, 1, rec);
- if (rec == 0)
+ if (rec == 0) {
break;
+ }
chunk.push_back(b);
int cs = chunk.size();
@@ -524,8 +529,9 @@ PackedByteArray HTTPClient::read_response_body_chunk() {
int rec = 0;
err = _get_http_data(&b, 1, rec);
- if (rec == 0)
+ if (rec == 0) {
break;
+ }
chunk.push_back(b);
@@ -540,13 +546,13 @@ PackedByteArray HTTPClient::read_response_body_chunk() {
for (int i = 0; i < chunk.size() - 2; i++) {
char c = chunk[i];
int v = 0;
- if (c >= '0' && c <= '9')
+ if (c >= '0' && c <= '9') {
v = c - '0';
- else if (c >= 'a' && c <= 'f')
+ } else if (c >= 'a' && c <= 'f') {
v = c - 'a' + 10;
- else if (c >= 'A' && c <= 'F')
+ } else if (c >= 'A' && c <= 'F') {
v = c - 'A' + 10;
- else {
+ } else {
ERR_PRINT("HTTP Chunk len not in hex!!");
status = STATUS_CONNECTION_ERROR;
break;
@@ -615,8 +621,9 @@ PackedByteArray HTTPClient::read_response_body_chunk() {
body_left -= rec;
}
}
- if (err != OK)
+ if (err != OK) {
break;
+ }
}
}
@@ -727,8 +734,9 @@ Dictionary HTTPClient::_get_response_headers_as_dictionary() {
for (const List<String>::Element *E = rh.front(); E; E = E->next()) {
const String &s = E->get();
int sp = s.find(":");
- if (sp == -1)
+ if (sp == -1) {
continue;
+ }
String key = s.substr(0, sp).strip_edges();
String value = s.substr(sp + 1, s.length()).strip_edges();
ret[key] = value;
diff --git a/core/io/image_loader.cpp b/core/io/image_loader.cpp
index 06e3cc029d..b1e92eb87f 100644
--- a/core/io/image_loader.cpp
+++ b/core/io/image_loader.cpp
@@ -36,8 +36,9 @@ bool ImageFormatLoader::recognize(const String &p_extension) const {
List<String> extensions;
get_recognized_extensions(&extensions);
for (List<String>::Element *E = extensions.front(); E; E = E->next()) {
- if (E->get().nocasecmp_to(p_extension) == 0)
+ if (E->get().nocasecmp_to(p_extension) == 0) {
return true;
+ }
}
return false;
@@ -59,23 +60,26 @@ Error ImageLoader::load_image(String p_file, Ref<Image> p_image, FileAccess *p_c
String extension = p_file.get_extension();
for (int i = 0; i < loader.size(); i++) {
- if (!loader[i]->recognize(extension))
+ if (!loader[i]->recognize(extension)) {
continue;
+ }
Error err = loader[i]->load_image(p_image, f, p_force_linear, p_scale);
if (err != OK) {
ERR_PRINT("Error loading image: " + p_file);
}
if (err != ERR_FILE_UNRECOGNIZED) {
- if (!p_custom)
+ if (!p_custom) {
memdelete(f);
+ }
return err;
}
}
- if (!p_custom)
+ if (!p_custom) {
memdelete(f);
+ }
return ERR_FILE_UNRECOGNIZED;
}
@@ -88,8 +92,9 @@ void ImageLoader::get_recognized_extensions(List<String> *p_extensions) {
ImageFormatLoader *ImageLoader::recognize(const String &p_extension) {
for (int i = 0; i < loader.size(); i++) {
- if (loader[i]->recognize(p_extension))
+ if (loader[i]->recognize(p_extension)) {
return loader[i];
+ }
}
return nullptr;
diff --git a/core/io/ip.cpp b/core/io/ip.cpp
index 642602d0bc..653959b393 100644
--- a/core/io/ip.cpp
+++ b/core/io/ip.cpp
@@ -61,8 +61,9 @@ struct _IP_ResolverPrivate {
IP::ResolverID find_empty_id() const {
for (int i = 0; i < IP::RESOLVER_MAX_QUERIES; i++) {
- if (queue[i].status == IP::RESOLVER_STATUS_NONE)
+ if (queue[i].status == IP::RESOLVER_STATUS_NONE) {
return i;
+ }
}
return IP::RESOLVER_INVALID_ID;
}
@@ -76,14 +77,16 @@ struct _IP_ResolverPrivate {
void resolve_queues() {
for (int i = 0; i < IP::RESOLVER_MAX_QUERIES; i++) {
- if (queue[i].status != IP::RESOLVER_STATUS_WAITING)
+ if (queue[i].status != IP::RESOLVER_STATUS_WAITING) {
continue;
+ }
queue[i].response = IP::get_singleton()->resolve_hostname(queue[i].hostname, queue[i].type);
- if (!queue[i].response.is_valid())
+ if (!queue[i].response.is_valid()) {
queue[i].status = IP::RESOLVER_STATUS_ERROR;
- else
+ } else {
queue[i].status = IP::RESOLVER_STATUS_DONE;
+ }
}
}
@@ -138,10 +141,11 @@ IP::ResolverID IP::resolve_hostname_queue_item(const String &p_hostname, IP::Typ
} else {
resolver->queue[id].response = IP_Address();
resolver->queue[id].status = IP::RESOLVER_STATUS_WAITING;
- if (resolver->thread)
+ if (resolver->thread) {
resolver->sem.post();
- else
+ } else {
resolver->resolve_queues();
+ }
}
return id;
diff --git a/core/io/ip_address.cpp b/core/io/ip_address.cpp
index 817c2f060a..89b317bf93 100644
--- a/core/io/ip_address.cpp
+++ b/core/io/ip_address.cpp
@@ -39,19 +39,23 @@ IP_Address::operator Variant() const {
#include <string.h>
IP_Address::operator String() const {
- if (wildcard)
+ if (wildcard) {
return "*";
+ }
- if (!valid)
+ if (!valid) {
return "";
+ }
- if (is_ipv4())
+ if (is_ipv4()) {
// IPv4 address mapped to IPv6
return itos(field8[12]) + "." + itos(field8[13]) + "." + itos(field8[14]) + "." + itos(field8[15]);
+ }
String ret;
for (int i = 0; i < 8; i++) {
- if (i > 0)
+ if (i > 0) {
ret = ret + ":";
+ }
uint16_t num = (field8[i * 2] << 8) + field8[i * 2 + 1];
ret = ret + String::num_int64(num, 16);
};
@@ -187,8 +191,9 @@ const uint8_t *IP_Address::get_ipv6() const {
void IP_Address::set_ipv6(const uint8_t *p_buf) {
clear();
valid = true;
- for (int i = 0; i < 16; i++)
+ for (int i = 0; i < 16; i++) {
field8[i] = p_buf[i];
+ }
}
IP_Address::IP_Address(const String &p_string) {
diff --git a/core/io/ip_address.h b/core/io/ip_address.h
index 39948ce211..2f8f83503e 100644
--- a/core/io/ip_address.h
+++ b/core/io/ip_address.h
@@ -51,23 +51,32 @@ protected:
public:
//operator Variant() const;
bool operator==(const IP_Address &p_ip) const {
- if (p_ip.valid != valid)
+ if (p_ip.valid != valid) {
return false;
- if (!valid)
+ }
+ if (!valid) {
return false;
- for (int i = 0; i < 4; i++)
- if (field32[i] != p_ip.field32[i])
+ }
+ for (int i = 0; i < 4; i++) {
+ if (field32[i] != p_ip.field32[i]) {
return false;
+ }
+ }
return true;
}
+
bool operator!=(const IP_Address &p_ip) const {
- if (p_ip.valid != valid)
+ if (p_ip.valid != valid) {
return true;
- if (!valid)
+ }
+ if (!valid) {
return true;
- for (int i = 0; i < 4; i++)
- if (field32[i] != p_ip.field32[i])
+ }
+ for (int i = 0; i < 4; i++) {
+ if (field32[i] != p_ip.field32[i]) {
return true;
+ }
+ }
return false;
}
diff --git a/core/io/json.cpp b/core/io/json.cpp
index baa62a4b0a..03f4e65220 100644
--- a/core/io/json.cpp
+++ b/core/io/json.cpp
@@ -48,8 +48,9 @@ const char *JSON::tk_name[TK_MAX] = {
static String _make_indent(const String &p_indent, int p_size) {
String indent_text = "";
if (!p_indent.empty()) {
- for (int i = 0; i < p_size; i++)
+ for (int i = 0; i < p_size; i++) {
indent_text += p_indent;
+ }
}
return indent_text;
}
@@ -98,8 +99,9 @@ String JSON::_print_var(const Variant &p_var, const String &p_indent, int p_cur_
List<Variant> keys;
d.get_key_list(&keys);
- if (p_sort_keys)
+ if (p_sort_keys) {
keys.sort();
+ }
for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
if (E != keys.front()) {
@@ -241,8 +243,9 @@ Error JSON::_get_token(const CharType *p_str, int &index, int p_len, Token &r_to
str += res;
} else {
- if (p_str[index] == '\n')
+ if (p_str[index] == '\n') {
line++;
+ }
str += p_str[index];
}
index++;
@@ -294,27 +297,29 @@ Error JSON::_parse_value(Variant &value, Token &token, const CharType *p_str, in
if (token.type == TK_CURLY_BRACKET_OPEN) {
Dictionary d;
Error err = _parse_object(d, p_str, index, p_len, line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
value = d;
return OK;
} else if (token.type == TK_BRACKET_OPEN) {
Array a;
Error err = _parse_array(a, p_str, index, p_len, line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
value = a;
return OK;
} else if (token.type == TK_IDENTIFIER) {
String id = token.value;
- if (id == "true")
+ if (id == "true") {
value = true;
- else if (id == "false")
+ } else if (id == "false") {
value = false;
- else if (id == "null")
+ } else if (id == "null") {
value = Variant();
- else {
+ } else {
r_err_str = "Expected 'true','false' or 'null', got '" + id + "'.";
return ERR_PARSE_ERROR;
}
@@ -338,8 +343,9 @@ Error JSON::_parse_array(Array &array, const CharType *p_str, int &index, int p_
while (index < p_len) {
Error err = _get_token(p_str, index, p_len, token, line, r_err_str);
- if (err != OK)
+ if (err != OK) {
return err;
+ }
if (token.type == TK_BRACKET_CLOSE) {
return OK;
@@ -357,8 +363,9 @@ Error JSON::_parse_array(Array &array, const CharType *p_str, int &index, int p_
Variant v;
err = _parse_value(v, token, p_str, index, p_len, line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
array.push_back(v);
need_comma = true;
@@ -376,8 +383,9 @@ Error JSON::_parse_object(Dictionary &object, const CharType *p_str, int &index,
while (index < p_len) {
if (at_key) {
Error err = _get_token(p_str, index, p_len, token, line, r_err_str);
- if (err != OK)
+ if (err != OK) {
return err;
+ }
if (token.type == TK_CURLY_BRACKET_CLOSE) {
return OK;
@@ -400,8 +408,9 @@ Error JSON::_parse_object(Dictionary &object, const CharType *p_str, int &index,
key = token.value;
err = _get_token(p_str, index, p_len, token, line, r_err_str);
- if (err != OK)
+ if (err != OK) {
return err;
+ }
if (token.type != TK_COLON) {
r_err_str = "Expected ':'";
return ERR_PARSE_ERROR;
@@ -409,13 +418,15 @@ Error JSON::_parse_object(Dictionary &object, const CharType *p_str, int &index,
at_key = false;
} else {
Error err = _get_token(p_str, index, p_len, token, line, r_err_str);
- if (err != OK)
+ if (err != OK) {
return err;
+ }
Variant v;
err = _parse_value(v, token, p_str, index, p_len, line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
object[key] = v;
need_comma = true;
at_key = true;
@@ -434,8 +445,9 @@ Error JSON::parse(const String &p_json, Variant &r_ret, String &r_err_str, int &
String aux_key;
Error err = _get_token(str, idx, len, token, r_err_line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
err = _parse_value(r_ret, token, str, idx, len, r_err_line, r_err_str);
diff --git a/core/io/logger.cpp b/core/io/logger.cpp
index 23165b575e..ef78b1194e 100644
--- a/core/io/logger.cpp
+++ b/core/io/logger.cpp
@@ -67,10 +67,11 @@ void Logger::log_error(const char *p_function, const char *p_file, int p_line, c
}
const char *err_details;
- if (p_rationale && *p_rationale)
+ if (p_rationale && *p_rationale) {
err_details = p_rationale;
- else
+ } else {
err_details = p_code;
+ }
logf_error("%s: %s\n", err_type, err_details);
logf_error(" at: %s (%s:%i) - %s\n", p_function, p_file, p_line, p_code);
diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp
index fc0b037b07..eb39b1433f 100644
--- a/core/io/marshalls.cpp
+++ b/core/io/marshalls.cpp
@@ -107,8 +107,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
buf += 4;
len -= 4;
- if (r_len)
+ if (r_len) {
*r_len = 4;
+ }
switch (type & ENCODE_MASK) {
case Variant::NIL: {
@@ -118,23 +119,26 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
bool val = decode_uint32(buf);
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 4;
+ }
} break;
case Variant::INT: {
if (type & ENCODE_FLAG_64) {
ERR_FAIL_COND_V(len < 8, ERR_INVALID_DATA);
int64_t val = decode_uint64(buf);
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 8;
+ }
} else {
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
int32_t val = decode_uint32(buf);
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 4;
+ }
}
} break;
@@ -143,22 +147,25 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
ERR_FAIL_COND_V(len < 8, ERR_INVALID_DATA);
double val = decode_double(buf);
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 8;
+ }
} else {
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
float val = decode_float(buf);
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 4;
+ }
}
} break;
case Variant::STRING: {
String str;
Error err = _decode_string(buf, len, r_len, str);
- if (err)
+ if (err) {
return err;
+ }
r_variant = str;
} break;
@@ -171,8 +178,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
val.y = decode_float(&buf[4]);
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 4 * 2;
+ }
} break;
case Variant::VECTOR2I: {
@@ -182,8 +190,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
val.y = decode_uint32(&buf[4]);
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 4 * 2;
+ }
} break;
case Variant::RECT2: {
@@ -195,8 +204,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
val.size.y = decode_float(&buf[12]);
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 4 * 4;
+ }
} break;
case Variant::RECT2I: {
@@ -208,8 +218,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
val.size.y = decode_uint32(&buf[12]);
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 4 * 4;
+ }
} break;
case Variant::VECTOR3: {
@@ -220,8 +231,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
val.z = decode_float(&buf[8]);
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 4 * 3;
+ }
} break;
case Variant::VECTOR3I: {
@@ -232,8 +244,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
val.z = decode_uint32(&buf[8]);
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 4 * 3;
+ }
} break;
case Variant::TRANSFORM2D: {
@@ -247,8 +260,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 4 * 6;
+ }
} break;
case Variant::PLANE: {
@@ -260,8 +274,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
val.d = decode_float(&buf[12]);
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 4 * 4;
+ }
} break;
case Variant::QUAT: {
@@ -273,8 +288,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
val.w = decode_float(&buf[12]);
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 4 * 4;
+ }
} break;
case Variant::AABB: {
@@ -288,8 +304,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
val.size.z = decode_float(&buf[20]);
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 4 * 6;
+ }
} break;
case Variant::BASIS: {
@@ -303,8 +320,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 4 * 9;
+ }
} break;
case Variant::TRANSFORM: {
@@ -321,8 +339,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 4 * 12;
+ }
} break;
@@ -336,15 +355,17 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
val.a = decode_float(&buf[12]);
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 4 * 4;
+ }
} break;
case Variant::STRING_NAME: {
String str;
Error err = _decode_string(buf, len, r_len, str);
- if (err)
+ if (err) {
return err;
+ }
r_variant = StringName(str);
} break;
@@ -366,24 +387,28 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
len -= 12;
buf += 12;
- if (flags & 2) // Obsolete format with property separate from subpath
+ if (flags & 2) { // Obsolete format with property separate from subpath
subnamecount++;
+ }
uint32_t total = namecount + subnamecount;
- if (r_len)
+ if (r_len) {
(*r_len) += 12;
+ }
for (uint32_t i = 0; i < total; i++) {
String str;
Error err = _decode_string(buf, len, r_len, str);
- if (err)
+ if (err) {
return err;
+ }
- if (i < namecount)
+ if (i < namecount) {
names.push_back(str);
- else
+ } else {
subnames.push_back(str);
+ }
}
r_variant = NodePath(names, subnames, flags & 1);
@@ -403,8 +428,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
//this _is_ allowed
ERR_FAIL_COND_V(len < 8, ERR_INVALID_DATA);
ObjectID val = ObjectID(decode_uint64(buf));
- if (r_len)
+ if (r_len) {
(*r_len) += 8;
+ }
if (val.is_null()) {
r_variant = (Object *)nullptr;
@@ -421,8 +447,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
String str;
Error err = _decode_string(buf, len, r_len, str);
- if (err)
+ if (err) {
return err;
+ }
if (str == String()) {
r_variant = (Object *)nullptr;
@@ -442,14 +469,16 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
for (int i = 0; i < count; i++) {
str = String();
err = _decode_string(buf, len, r_len, str);
- if (err)
+ if (err) {
return err;
+ }
Variant value;
int used;
err = decode_variant(value, buf, len, &used, p_allow_objects);
- if (err)
+ if (err) {
return err;
+ }
buf += used;
len -= used;
@@ -573,8 +602,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
r_variant = data;
if (r_len) {
- if (count % 4)
+ if (count % 4) {
(*r_len) += 4 - count % 4;
+ }
(*r_len) += 4 + count;
}
@@ -685,15 +715,17 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
buf += 4;
len -= 4;
- if (r_len)
+ if (r_len) {
(*r_len) += 4;
+ }
//printf("string count: %i\n",count);
for (int32_t i = 0; i < count; i++) {
String str;
Error err = _decode_string(buf, len, r_len, str);
- if (err)
+ if (err) {
return err;
+ }
strings.push_back(str);
}
@@ -726,8 +758,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
int adv = 4 * 2 * count;
- if (r_len)
+ if (r_len) {
(*r_len) += adv;
+ }
}
r_variant = varray;
@@ -760,8 +793,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
int adv = 4 * 3 * count;
- if (r_len)
+ if (r_len) {
(*r_len) += adv;
+ }
}
r_variant = varray;
@@ -795,8 +829,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
int adv = 4 * 4 * count;
- if (r_len)
+ if (r_len) {
(*r_len) += adv;
+ }
}
r_variant = carray;
@@ -927,8 +962,9 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
encode_uint32(uint32_t(np.get_name_count()) | 0x80000000, buf); //for compatibility with the old format
encode_uint32(np.get_subname_count(), buf + 4);
uint32_t np_flags = 0;
- if (np.is_absolute())
+ if (np.is_absolute()) {
np_flags |= 1;
+ }
encode_uint32(np_flags, buf + 8);
@@ -942,17 +978,19 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
for (int i = 0; i < total; i++) {
String str;
- if (i < np.get_name_count())
+ if (i < np.get_name_count()) {
str = np.get_name(i);
- else
+ } else {
str = np.get_subname(i - np.get_name_count());
+ }
CharString utf8 = str.utf8();
int pad = 0;
- if (utf8.length() % 4)
+ if (utf8.length() % 4) {
pad = 4 - utf8.length() % 4;
+ }
if (buf) {
encode_uint32(utf8.length(), buf);
@@ -1157,8 +1195,9 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
int pc = 0;
for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
- if (!(E->get().usage & PROPERTY_USAGE_STORAGE))
+ if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) {
continue;
+ }
pc++;
}
@@ -1170,19 +1209,22 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
r_len += 4;
for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
- if (!(E->get().usage & PROPERTY_USAGE_STORAGE))
+ if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) {
continue;
+ }
_encode_string(E->get().name, buf, r_len);
int len;
Error err = encode_variant(obj->get(E->get().name), buf, len, p_full_objects);
- if (err)
+ if (err) {
return err;
+ }
ERR_FAIL_COND_V(len % 4, ERR_BUG);
r_len += len;
- if (buf)
+ if (buf) {
buf += len;
+ }
}
}
} else {
@@ -1230,15 +1272,17 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
encode_variant(E->get(), buf, len, p_full_objects);
ERR_FAIL_COND_V(len % 4, ERR_BUG);
r_len += len;
- if (buf)
+ if (buf) {
buf += len;
+ }
Variant *v = d.getptr(E->get());
ERR_FAIL_COND_V(!v, ERR_BUG);
encode_variant(*v, buf, len, p_full_objects);
ERR_FAIL_COND_V(len % 4, ERR_BUG);
r_len += len;
- if (buf)
+ if (buf) {
buf += len;
+ }
}
} break;
@@ -1257,8 +1301,9 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
encode_variant(v.get(i), buf, len, p_full_objects);
ERR_FAIL_COND_V(len % 4, ERR_BUG);
r_len += len;
- if (buf)
+ if (buf) {
buf += len;
+ }
}
} break;
@@ -1279,8 +1324,9 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
r_len += 4 + datalen * datasize;
while (r_len % 4) {
r_len++;
- if (buf)
+ if (buf) {
*(buf++) = 0;
+ }
}
} break;
@@ -1293,8 +1339,9 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
encode_uint32(datalen, buf);
buf += 4;
const int32_t *r = data.ptr();
- for (int32_t i = 0; i < datalen; i++)
+ for (int32_t i = 0; i < datalen; i++) {
encode_uint32(r[i], &buf[i * datasize]);
+ }
}
r_len += 4 + datalen * datasize;
@@ -1309,8 +1356,9 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
encode_uint64(datalen, buf);
buf += 4;
const int64_t *r = data.ptr();
- for (int64_t i = 0; i < datalen; i++)
+ for (int64_t i = 0; i < datalen; i++) {
encode_uint64(r[i], &buf[i * datasize]);
+ }
}
r_len += 4 + datalen * datasize;
@@ -1325,8 +1373,9 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
encode_uint32(datalen, buf);
buf += 4;
const float *r = data.ptr();
- for (int i = 0; i < datalen; i++)
+ for (int i = 0; i < datalen; i++) {
encode_float(r[i], &buf[i * datasize]);
+ }
}
r_len += 4 + datalen * datasize;
@@ -1341,8 +1390,9 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
encode_uint32(datalen, buf);
buf += 4;
const double *r = data.ptr();
- for (int i = 0; i < datalen; i++)
+ for (int i = 0; i < datalen; i++) {
encode_double(r[i], &buf[i * datasize]);
+ }
}
r_len += 4 + datalen * datasize;
@@ -1372,8 +1422,9 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
r_len += 4 + utf8.length() + 1;
while (r_len % 4) {
r_len++; //pad
- if (buf)
+ if (buf) {
*(buf++) = 0;
+ }
}
}
diff --git a/core/io/marshalls.h b/core/io/marshalls.h
index 279f782b1a..c21a97ac8a 100644
--- a/core/io/marshalls.h
+++ b/core/io/marshalls.h
@@ -108,8 +108,9 @@ static inline int encode_cstring(const char *p_string, uint8_t *p_data) {
len++;
};
- if (p_data)
+ if (p_data) {
*p_data = 0;
+ }
return len + 1;
}
diff --git a/core/io/multiplayer_api.cpp b/core/io/multiplayer_api.cpp
index a2f65660f2..2f17d9e746 100644
--- a/core/io/multiplayer_api.cpp
+++ b/core/io/multiplayer_api.cpp
@@ -53,8 +53,9 @@ _FORCE_INLINE_ bool _should_call_local(MultiplayerAPI::RPCMode mode, bool is_mas
// Do nothing also. Remote cannot produce a local call.
} break;
case MultiplayerAPI::RPC_MODE_MASTERSYNC: {
- if (is_master)
+ if (is_master) {
r_skip_rpc = true; // I am the master, so skip remote call.
+ }
[[fallthrough]];
}
case MultiplayerAPI::RPC_MODE_REMOTESYNC:
@@ -63,8 +64,9 @@ _FORCE_INLINE_ bool _should_call_local(MultiplayerAPI::RPCMode mode, bool is_mas
return true;
} break;
case MultiplayerAPI::RPC_MODE_MASTER: {
- if (is_master)
+ if (is_master) {
r_skip_rpc = true; // I am the master, so skip remote call.
+ }
return is_master;
} break;
case MultiplayerAPI::RPC_MODE_PUPPET: {
@@ -97,13 +99,15 @@ _FORCE_INLINE_ bool _can_call_mode(Node *p_node, MultiplayerAPI::RPCMode mode, i
}
void MultiplayerAPI::poll() {
- if (!network_peer.is_valid() || network_peer->get_connection_status() == NetworkedMultiplayerPeer::CONNECTION_DISCONNECTED)
+ if (!network_peer.is_valid() || network_peer->get_connection_status() == NetworkedMultiplayerPeer::CONNECTION_DISCONNECTED) {
return;
+ }
network_peer->poll();
- if (!network_peer.is_valid()) // It's possible that polling might have resulted in a disconnection, so check here.
+ if (!network_peer.is_valid()) { // It's possible that polling might have resulted in a disconnection, so check here.
return;
+ }
while (network_peer->get_available_packet_count()) {
int sender = network_peer->get_packet_peer();
@@ -139,8 +143,9 @@ void MultiplayerAPI::set_root_node(Node *p_node) {
}
void MultiplayerAPI::set_network_peer(const Ref<NetworkedMultiplayerPeer> &p_peer) {
- if (p_peer == network_peer)
+ if (p_peer == network_peer) {
return; // Nothing to do
+ }
ERR_FAIL_COND_MSG(p_peer.is_valid() && p_peer->get_connection_status() == NetworkedMultiplayerPeer::CONNECTION_DISCONNECTED,
"Supplied NetworkedMultiplayerPeer must be connecting or connected.");
@@ -325,8 +330,9 @@ Node *MultiplayerAPI::_process_get_node(int p_from, const uint8_t *p_packet, uin
node = root_node->get_node(np);
- if (!node)
+ if (!node) {
ERR_PRINT("Failed to get path from RPC: " + String(np) + ".");
+ }
} else {
// Use cached path.
int id = p_node_target;
@@ -341,8 +347,9 @@ Node *MultiplayerAPI::_process_get_node(int p_from, const uint8_t *p_packet, uin
// Do proper caching later.
node = root_node->get_node(ni->path);
- if (!node)
+ if (!node) {
ERR_PRINT("Failed to get cached path from RPC: " + String(ni->path) + ".");
+ }
}
return node;
}
@@ -529,11 +536,13 @@ bool MultiplayerAPI::_send_confirm_path(Node *p_node, NodePath p_path, PathSentC
List<int> peers_to_add; // If one is missing, take note to add it.
for (Set<int>::Element *E = connected_peers.front(); E; E = E->next()) {
- if (p_target < 0 && E->get() == -p_target)
+ if (p_target < 0 && E->get() == -p_target) {
continue; // Continue, excluded.
+ }
- if (p_target > 0 && E->get() != p_target)
+ if (p_target > 0 && E->get() != p_target) {
continue; // Continue, not for this peer.
+ }
Map<int, bool>::Element *F = psc->confirmed_peers.find(E->get());
@@ -658,8 +667,9 @@ Error MultiplayerAPI::_encode_and_compress_variant(const Variant &p_variant, uin
default:
// Any other case is not yet compressed.
Error err = encode_variant(p_variant, r_buffer, r_len, allow_object_decoding);
- if (err != OK)
+ if (err != OK) {
return err;
+ }
if (r_buffer) {
// The first byte is not used by the marshaling, so store the type
// so we know how to decompress and decode this variant.
@@ -684,48 +694,55 @@ Error MultiplayerAPI::_decode_and_decompress_variant(Variant &r_variant, const u
case Variant::BOOL: {
bool val = (buf[0] & VARIANT_META_BOOL_MASK) > 0;
r_variant = val;
- if (r_len)
+ if (r_len) {
*r_len = 1;
+ }
} break;
case Variant::INT: {
buf += 1;
len -= 1;
- if (r_len)
+ if (r_len) {
*r_len = 1;
+ }
if (encode_mode == ENCODE_8) {
// 8 bits.
ERR_FAIL_COND_V(len < 1, ERR_INVALID_DATA);
int8_t val = buf[0];
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 1;
+ }
} else if (encode_mode == ENCODE_16) {
// 16 bits.
ERR_FAIL_COND_V(len < 2, ERR_INVALID_DATA);
int16_t val = decode_uint16(buf);
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 2;
+ }
} else if (encode_mode == ENCODE_32) {
// 32 bits.
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
int32_t val = decode_uint32(buf);
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 4;
+ }
} else {
// 64 bits.
ERR_FAIL_COND_V(len < 8, ERR_INVALID_DATA);
int64_t val = decode_uint64(buf);
r_variant = val;
- if (r_len)
+ if (r_len) {
(*r_len) += 8;
+ }
}
} break;
default:
Error err = decode_variant(r_variant, p_buffer, p_len, r_len, allow_object_decoding);
- if (err != OK)
+ if (err != OK) {
return err;
+ }
}
return OK;
@@ -925,11 +942,13 @@ void MultiplayerAPI::_send_rpc(Node *p_from, int p_to, bool p_unreliable, bool p
encode_cstring(pname.get_data(), &(packet_cache.write[ofs]));
for (Set<int>::Element *E = connected_peers.front(); E; E = E->next()) {
- if (p_to < 0 && E->get() == -p_to)
+ if (p_to < 0 && E->get() == -p_to) {
continue; // Continue, excluded.
+ }
- if (p_to > 0 && E->get() != p_to)
+ if (p_to > 0 && E->get() != p_to) {
continue; // Continue, not for this peer.
+ }
Map<int, bool>::Element *F = psc->confirmed_peers.find(E->get());
ERR_CONTINUE(!F); // Should never happen.
diff --git a/core/io/net_socket.cpp b/core/io/net_socket.cpp
index e92bc705ce..130a2e245e 100644
--- a/core/io/net_socket.cpp
+++ b/core/io/net_socket.cpp
@@ -33,8 +33,9 @@
NetSocket *(*NetSocket::_create)() = nullptr;
NetSocket *NetSocket::create() {
- if (_create)
+ if (_create) {
return _create();
+ }
ERR_PRINT("Unable to create network socket, platform not supported");
return nullptr;
diff --git a/core/io/packet_peer.cpp b/core/io/packet_peer.cpp
index fe1c9a2eb1..6d37d95994 100644
--- a/core/io/packet_peer.cpp
+++ b/core/io/packet_peer.cpp
@@ -50,24 +50,28 @@ Error PacketPeer::get_packet_buffer(Vector<uint8_t> &r_buffer) {
const uint8_t *buffer;
int buffer_size;
Error err = get_packet(&buffer, buffer_size);
- if (err)
+ if (err) {
return err;
+ }
r_buffer.resize(buffer_size);
- if (buffer_size == 0)
+ if (buffer_size == 0) {
return OK;
+ }
uint8_t *w = r_buffer.ptrw();
- for (int i = 0; i < buffer_size; i++)
+ for (int i = 0; i < buffer_size; i++) {
w[i] = buffer[i];
+ }
return OK;
}
Error PacketPeer::put_packet_buffer(const Vector<uint8_t> &p_buffer) {
int len = p_buffer.size();
- if (len == 0)
+ if (len == 0) {
return OK;
+ }
const uint8_t *r = p_buffer.ptr();
return put_packet(&r[0], len);
@@ -77,8 +81,9 @@ Error PacketPeer::get_var(Variant &r_variant, bool p_allow_objects) {
const uint8_t *buffer;
int buffer_size;
Error err = get_packet(&buffer, buffer_size);
- if (err)
+ if (err) {
return err;
+ }
return decode_variant(r_variant, buffer, buffer_size, nullptr, p_allow_objects);
}
@@ -86,11 +91,13 @@ Error PacketPeer::get_var(Variant &r_variant, bool p_allow_objects) {
Error PacketPeer::put_var(const Variant &p_packet, bool p_full_objects) {
int len;
Error err = encode_variant(p_packet, nullptr, len, p_full_objects); // compute len first
- if (err)
+ if (err) {
return err;
+ }
- if (len == 0)
+ if (len == 0) {
return OK;
+ }
ERR_FAIL_COND_V_MSG(len > encode_buffer_max_size, ERR_OUT_OF_MEMORY, "Failed to encode variant, encode size is bigger then encode_buffer_max_size. Consider raising it via 'set_encode_buffer_max_size'.");
@@ -168,10 +175,12 @@ Error PacketPeerStream::_poll_buffer() const {
int read = 0;
ERR_FAIL_COND_V(input_buffer.size() < ring_buffer.space_left(), ERR_UNAVAILABLE);
Error err = peer->get_partial_data(input_buffer.ptrw(), ring_buffer.space_left(), read);
- if (err)
+ if (err) {
return err;
- if (read == 0)
+ }
+ if (read == 0) {
return OK;
+ }
int w = ring_buffer.write(&input_buffer[0], read);
ERR_FAIL_COND_V(w != read, ERR_BUG);
@@ -193,8 +202,9 @@ int PacketPeerStream::get_available_packet_count() const {
uint32_t len = decode_uint32(lbuf);
remaining -= 4;
ofs += 4;
- if (len > remaining)
+ if (len > remaining) {
break;
+ }
remaining -= len;
ofs += len;
count++;
@@ -228,19 +238,22 @@ Error PacketPeerStream::put_packet(const uint8_t *p_buffer, int p_buffer_size) {
ERR_FAIL_COND_V(peer.is_null(), ERR_UNCONFIGURED);
Error err = _poll_buffer(); //won't hurt to poll here too
- if (err)
+ if (err) {
return err;
+ }
- if (p_buffer_size == 0)
+ if (p_buffer_size == 0) {
return OK;
+ }
ERR_FAIL_COND_V(p_buffer_size < 0, ERR_INVALID_PARAMETER);
ERR_FAIL_COND_V(p_buffer_size + 4 > output_buffer.size(), ERR_INVALID_PARAMETER);
encode_uint32(p_buffer_size, output_buffer.ptrw());
uint8_t *dst = &output_buffer.write[4];
- for (int i = 0; i < p_buffer_size; i++)
+ for (int i = 0; i < p_buffer_size; i++) {
dst[i] = p_buffer[i];
+ }
return peer->put_data(&output_buffer[0], p_buffer_size + 4);
}
diff --git a/core/io/packet_peer_udp.cpp b/core/io/packet_peer_udp.cpp
index e36de8c228..862fca96fc 100644
--- a/core/io/packet_peer_udp.cpp
+++ b/core/io/packet_peer_udp.cpp
@@ -38,8 +38,9 @@ void PacketPeerUDP::set_blocking_mode(bool p_enable) {
void PacketPeerUDP::set_broadcast_enabled(bool p_enabled) {
broadcast = p_enabled;
- if (_sock.is_valid() && _sock->is_open())
+ if (_sock.is_valid() && _sock->is_open()) {
_sock->set_broadcasting_enabled(p_enabled);
+ }
}
Error PacketPeerUDP::join_multicast_group(IP_Address p_multi_address, String p_if_name) {
@@ -72,8 +73,9 @@ Error PacketPeerUDP::_set_dest_address(const String &p_address, int p_port) {
ip = p_address;
} else {
ip = IP::get_singleton()->resolve_hostname(p_address);
- if (!ip.is_valid())
+ if (!ip.is_valid()) {
return ERR_CANT_RESOLVE;
+ }
}
set_dest_address(ip, p_port);
@@ -83,18 +85,21 @@ Error PacketPeerUDP::_set_dest_address(const String &p_address, int p_port) {
int PacketPeerUDP::get_available_packet_count() const {
// TODO we should deprecate this, and expose poll instead!
Error err = const_cast<PacketPeerUDP *>(this)->_poll();
- if (err != OK)
+ if (err != OK) {
return -1;
+ }
return queue_count;
}
Error PacketPeerUDP::get_packet(const uint8_t **r_buffer, int &r_buffer_size) {
Error err = _poll();
- if (err != OK)
+ if (err != OK) {
return err;
- if (queue_count == 0)
+ }
+ if (queue_count == 0) {
return ERR_UNAVAILABLE;
+ }
uint32_t size = 0;
uint8_t ipv6[16];
@@ -131,10 +136,11 @@ Error PacketPeerUDP::put_packet(const uint8_t *p_buffer, int p_buffer_size) {
err = _sock->sendto(p_buffer, p_buffer_size, sent, peer_addr, peer_port);
}
if (err != OK) {
- if (err != ERR_BUSY)
+ if (err != ERR_BUSY) {
return FAILED;
- else if (!blocking)
+ } else if (!blocking) {
return ERR_BUSY;
+ }
// Keep trying to send full packet
continue;
}
@@ -157,13 +163,15 @@ Error PacketPeerUDP::listen(int p_port, const IP_Address &p_bind_address, int p_
Error err;
IP::Type ip_type = IP::TYPE_ANY;
- if (p_bind_address.is_valid())
+ if (p_bind_address.is_valid()) {
ip_type = p_bind_address.is_ipv4() ? IP::TYPE_IPV4 : IP::TYPE_IPV6;
+ }
err = _sock->open(NetSocket::TYPE_UDP, ip_type);
- if (err != OK)
+ if (err != OK) {
return ERR_CANT_CREATE;
+ }
_sock->set_blocking_enabled(false);
_sock->set_reuse_address_enabled(true);
@@ -235,8 +243,9 @@ bool PacketPeerUDP::is_connected_to_host() const {
}
void PacketPeerUDP::close() {
- if (_sock.is_valid())
+ if (_sock.is_valid()) {
_sock->close();
+ }
rb.resize(16);
queue_count = 0;
connected = false;
@@ -269,8 +278,9 @@ Error PacketPeerUDP::_poll() {
}
if (err != OK) {
- if (err == ERR_BUSY)
+ if (err == ERR_BUSY) {
break;
+ }
return FAILED;
}
diff --git a/core/io/pck_packer.cpp b/core/io/pck_packer.cpp
index 4863cd1dbb..06d22ce897 100644
--- a/core/io/pck_packer.cpp
+++ b/core/io/pck_packer.cpp
@@ -35,14 +35,16 @@
#include "core/version.h"
static uint64_t _align(uint64_t p_n, int p_alignment) {
- if (p_alignment == 0)
+ if (p_alignment == 0) {
return p_n;
+ }
uint64_t rest = p_n % p_alignment;
- if (rest == 0)
+ if (rest == 0) {
return p_n;
- else
+ } else {
return p_n + (p_alignment - rest);
+ }
};
static void _pad(FileAccess *p_file, int p_bytes) {
@@ -160,8 +162,9 @@ Error PCKPacker::flush(bool p_verbose) {
};
};
- if (p_verbose)
+ if (p_verbose) {
printf("\n");
+ }
file->close();
memdelete_arr(buf);
diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp
index 230925c29b..5097f6d98b 100644
--- a/core/io/resource_format_binary.cpp
+++ b/core/io/resource_format_binary.cpp
@@ -96,8 +96,9 @@ enum {
void ResourceLoaderBinary::_advance_padding(uint32_t p_len) {
uint32_t extra = 4 - (p_len % 4);
if (extra < 4) {
- for (uint32_t i = 0; i < extra; i++)
+ for (uint32_t i = 0; i < extra; i++) {
f->get_8(); //pad to 32
+ }
}
}
@@ -108,8 +109,9 @@ StringName ResourceLoaderBinary::_get_string() {
if ((int)len > str_buf.size()) {
str_buf.resize(len);
}
- if (len == 0)
+ if (len == 0) {
return StringName();
+ }
f->get_buffer((uint8_t *)&str_buf[0], len);
String s;
s.parse_utf8(&str_buf[0]);
@@ -286,10 +288,12 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) {
subname_count += 1; // has a property field, so we should count it as well
}
- for (int i = 0; i < name_count; i++)
+ for (int i = 0; i < name_count; i++) {
names.push_back(_get_string());
- for (uint32_t i = 0; i < subname_count; i++)
+ }
+ for (uint32_t i = 0; i < subname_count; i++) {
subnames.push_back(_get_string());
+ }
NodePath np = NodePath(names, subnames, absolute);
@@ -512,8 +516,9 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) {
Vector<String> array;
array.resize(len);
String *w = array.ptrw();
- for (uint32_t i = 0; i < len; i++)
+ for (uint32_t i = 0; i < len; i++) {
w[i] = get_unicode_string();
+ }
r_v = array;
@@ -609,8 +614,9 @@ Ref<Resource> ResourceLoaderBinary::get_resource() {
}
Error ResourceLoaderBinary::load() {
- if (error != OK)
+ if (error != OK) {
return error;
+ }
int stage = 0;
@@ -680,8 +686,9 @@ Error ResourceLoaderBinary::load() {
}
}
} else {
- if (!use_nocache && !ResourceCache::has(res_path))
+ if (!use_nocache && !ResourceCache::has(res_path)) {
path = res_path;
+ }
}
uint64_t offset = internal_resources[i].offset;
@@ -730,8 +737,9 @@ Error ResourceLoaderBinary::load() {
Variant value;
error = parse_variant(value);
- if (error)
+ if (error) {
return error;
+ }
res->set(name, value);
}
@@ -783,8 +791,9 @@ String ResourceLoaderBinary::get_unicode_string() {
if (len > str_buf.size()) {
str_buf.resize(len);
}
- if (len == 0)
+ if (len == 0) {
return String();
+ }
f->get_buffer((uint8_t *)&str_buf[0], len);
String s;
s.parse_utf8(&str_buf[0]);
@@ -793,8 +802,9 @@ String ResourceLoaderBinary::get_unicode_string() {
void ResourceLoaderBinary::get_dependencies(FileAccess *p_f, List<String> *p_dependencies, bool p_add_types) {
open(p_f);
- if (error)
+ if (error) {
return;
+ }
for (int i = 0; i < external_resources.size(); i++) {
String dep = external_resources[i].path;
@@ -861,8 +871,9 @@ void ResourceLoaderBinary::open(FileAccess *p_f) {
print_bl("type: " + type);
importmd_ofs = f->get_64();
- for (int i = 0; i < 14; i++)
+ for (int i = 0; i < 14; i++) {
f->get_32(); //skip a few reserved fields
+ }
uint32_t string_table_size = f->get_32();
string_map.resize(string_table_size);
@@ -946,13 +957,15 @@ String ResourceLoaderBinary::recognize(FileAccess *p_f) {
}
ResourceLoaderBinary::~ResourceLoaderBinary() {
- if (f)
+ if (f) {
memdelete(f);
+ }
}
RES ResourceFormatLoaderBinary::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) {
- if (r_error)
+ if (r_error) {
*r_error = ERR_FILE_CANT_OPEN;
+ }
Error err;
FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err);
@@ -1240,8 +1253,9 @@ String ResourceFormatLoaderBinary::get_resource_type(const String &p_path) const
void ResourceFormatSaverBinaryInstance::_pad_buffer(FileAccess *f, int p_bytes) {
int extra = 4 - (p_bytes % 4);
if (extra < 4) {
- for (int i = 0; i < extra; i++)
+ for (int i = 0; i < extra; i++) {
f->store_8(0); //pad to 32
+ }
}
}
@@ -1430,8 +1444,9 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
NodePath np = p_property;
f->store_16(np.get_name_count());
uint16_t snc = np.get_subname_count();
- if (np.is_absolute())
+ if (np.is_absolute()) {
snc |= 0x8000;
+ }
f->store_16(snc);
for (int i = 0; i < np.get_name_count(); i++) {
if (string_map.has(np.get_name(i))) {
@@ -1531,8 +1546,9 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
int len = arr.size();
f->store_32(len);
const int32_t *r = arr.ptr();
- for (int i = 0; i < len; i++)
+ for (int i = 0; i < len; i++) {
f->store_32(r[i]);
+ }
} break;
case Variant::PACKED_INT64_ARRAY: {
@@ -1541,8 +1557,9 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
int len = arr.size();
f->store_32(len);
const int64_t *r = arr.ptr();
- for (int i = 0; i < len; i++)
+ for (int i = 0; i < len; i++) {
f->store_64(r[i]);
+ }
} break;
case Variant::PACKED_FLOAT32_ARRAY: {
@@ -1628,8 +1645,9 @@ void ResourceFormatSaverBinaryInstance::_find_resources(const Variant &p_variant
case Variant::OBJECT: {
RES res = p_variant;
- if (res.is_null() || external_resources.has(res))
+ if (res.is_null() || external_resources.has(res)) {
return;
+ }
if (!p_main && (!bundle_resources) && res->get_path().length() && res->get_path().find("::") == -1) {
if (res->get_path() == path) {
@@ -1641,8 +1659,9 @@ void ResourceFormatSaverBinaryInstance::_find_resources(const Variant &p_variant
return;
}
- if (resource_set.has(res))
+ if (resource_set.has(res)) {
return;
+ }
List<PropertyInfo> property_list;
@@ -1695,10 +1714,12 @@ void ResourceFormatSaverBinaryInstance::_find_resources(const Variant &p_variant
case Variant::NODE_PATH: {
//take the chance and save node path strings
NodePath np = p_variant;
- for (int i = 0; i < np.get_name_count(); i++)
+ for (int i = 0; i < np.get_name_count(); i++) {
get_string_index(np.get_name(i));
- for (int i = 0; i < np.get_subname_count(); i++)
+ }
+ for (int i = 0; i < np.get_subname_count(); i++) {
get_string_index(np.get_subname(i));
+ }
} break;
default: {
@@ -1718,8 +1739,9 @@ void ResourceFormatSaverBinaryInstance::save_unicode_string(FileAccess *f, const
int ResourceFormatSaverBinaryInstance::get_string_index(const String &p_string) {
StringName s = p_string;
- if (string_map.has(s))
+ if (string_map.has(s)) {
return string_map[s];
+ }
string_map[s] = strings.size();
strings.push_back(s);
@@ -1733,8 +1755,9 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p
fac->configure("RSCC");
f = fac;
err = fac->_open(p_path, FileAccess::WRITE);
- if (err)
+ if (err) {
memdelete(f);
+ }
} else {
f = FileAccess::open(p_path, FileAccess::WRITE, &err);
@@ -1748,8 +1771,9 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p
big_endian = p_flags & ResourceSaver::FLAG_SAVE_BIG_ENDIAN;
takeover_paths = p_flags & ResourceSaver::FLAG_REPLACE_SUBRESOURCE_PATHS;
- if (!p_path.begins_with("res://"))
+ if (!p_path.begins_with("res://")) {
takeover_paths = false;
+ }
local_path = p_path.get_base_dir();
path = ProjectSettings::get_singleton()->localize_path(p_path);
@@ -1765,8 +1789,9 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p
if (big_endian) {
f->store_32(1);
f->set_endian_swap(true);
- } else
+ } else {
f->store_32(0);
+ }
f->store_32(0); //64 bits file, false for now
f->store_32(VERSION_MAJOR);
@@ -1781,8 +1806,9 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p
save_unicode_string(f, p_resource->get_class());
f->store_64(0); //offset to import metadata
- for (int i = 0; i < 14; i++)
+ for (int i = 0; i < 14; i++) {
f->store_32(0); // reserved
+ }
List<ResourceData> resources;
@@ -1795,8 +1821,9 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p
E->get()->get_property_list(&property_list);
for (List<PropertyInfo>::Element *F = property_list.front(); F; F = F->next()) {
- if (skip_editor && F->get().name.begins_with("__editor"))
+ if (skip_editor && F->get().name.begins_with("__editor")) {
continue;
+ }
if ((F->get().usage & PROPERTY_USAGE_STORAGE)) {
Property p;
p.name_idx = get_string_index(F->get().name);
@@ -1942,8 +1969,9 @@ bool ResourceFormatSaverBinary::recognize(const RES &p_resource) const {
void ResourceFormatSaverBinary::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const {
String base = p_resource->get_base_extension().to_lower();
p_extensions->push_back(base);
- if (base != "res")
+ if (base != "res") {
p_extensions->push_back("res");
+ }
}
ResourceFormatSaverBinary *ResourceFormatSaverBinary::singleton = nullptr;
diff --git a/core/io/resource_importer.cpp b/core/io/resource_importer.cpp
index c2e27bc9c2..9ed159bd20 100644
--- a/core/io/resource_importer.cpp
+++ b/core/io/resource_importer.cpp
@@ -120,8 +120,9 @@ RES ResourceFormatImporter::load(const String &p_path, const String &p_original_
Error err = _get_path_and_type(p_path, pat);
if (err != OK) {
- if (r_error)
+ if (r_error) {
*r_error = err;
+ }
return RES();
}
@@ -163,11 +164,13 @@ void ResourceFormatImporter::get_recognized_extensions_for_type(const String &p_
for (int i = 0; i < importers.size(); i++) {
String res_type = importers[i]->get_resource_type();
- if (res_type == String())
+ if (res_type == String()) {
continue;
+ }
- if (!ClassDB::is_parent_class(res_type, p_type))
+ if (!ClassDB::is_parent_class(res_type, p_type)) {
continue;
+ }
List<String> local_exts;
importers[i]->get_recognized_extensions(&local_exts);
@@ -206,8 +209,9 @@ int ResourceFormatImporter::get_import_order(const String &p_path) const {
importer = get_importer_by_extension(p_path.get_extension().to_lower());
}
- if (importer.is_valid())
+ if (importer.is_valid()) {
return importer->get_import_order();
+ }
return 0;
}
@@ -215,10 +219,12 @@ int ResourceFormatImporter::get_import_order(const String &p_path) const {
bool ResourceFormatImporter::handles_type(const String &p_type) const {
for (int i = 0; i < importers.size(); i++) {
String res_type = importers[i]->get_resource_type();
- if (res_type == String())
+ if (res_type == String()) {
continue;
- if (ClassDB::is_parent_class(res_type, p_type))
+ }
+ if (ClassDB::is_parent_class(res_type, p_type)) {
return true;
+ }
}
return true;
@@ -239,8 +245,9 @@ void ResourceFormatImporter::get_internal_resource_path_list(const String &p_pat
Error err;
FileAccess *f = FileAccess::open(p_path + ".import", FileAccess::READ, &err);
- if (!f)
+ if (!f) {
return;
+ }
VariantParser::StreamFile stream;
stream.f = f;
diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp
index 8490cb5627..f9d2c9067c 100644
--- a/core/io/resource_loader.cpp
+++ b/core/io/resource_loader.cpp
@@ -59,8 +59,9 @@ bool ResourceFormatLoader::recognize_path(const String &p_path, const String &p_
}
for (List<String>::Element *E = extensions.front(); E; E = E->next()) {
- if (E->get().nocasecmp_to(extension) == 0)
+ if (E->get().nocasecmp_to(extension) == 0) {
return true;
+ }
}
return false;
@@ -84,8 +85,9 @@ String ResourceFormatLoader::get_resource_type(const String &p_path) const {
}
void ResourceFormatLoader::get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) const {
- if (p_type == "" || handles_type(p_type))
+ if (p_type == "" || handles_type(p_type)) {
get_recognized_extensions(p_extensions);
+ }
}
void ResourceLoader::get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) {
@@ -116,12 +118,14 @@ RES ResourceFormatLoader::load(const String &p_path, const String &p_original_pa
Variant res = get_script_instance()->call("load", p_path, p_original_path, p_use_sub_threads);
if (res.get_type() == Variant::INT) {
- if (r_error)
+ if (r_error) {
*r_error = (Error)res.operator int64_t();
+ }
} else {
- if (r_error)
+ if (r_error) {
*r_error = OK;
+ }
return res;
}
@@ -240,8 +244,9 @@ void ResourceLoader::_thread_load_function(void *p_userdata) {
if (load_task.resource.is_valid()) {
load_task.resource->set_path(load_task.local_path);
- if (load_task.xl_remapped)
+ if (load_task.xl_remapped) {
load_task.resource->set_as_translation_remapped(true);
+ }
#ifdef TOOLS_ENABLED
@@ -263,10 +268,11 @@ void ResourceLoader::_thread_load_function(void *p_userdata) {
Error ResourceLoader::load_threaded_request(const String &p_path, const String &p_type_hint, bool p_use_sub_threads, const String &p_source_resource) {
String local_path;
- if (p_path.is_rel_path())
+ if (p_path.is_rel_path()) {
local_path = "res://" + p_path;
- else
+ } else {
local_path = ProjectSettings::get_singleton()->localize_path(p_path);
+ }
thread_load_mutex->lock();
@@ -392,10 +398,11 @@ float ResourceLoader::_dependency_get_progress(const String &p_path) {
ResourceLoader::ThreadLoadStatus ResourceLoader::load_threaded_get_status(const String &p_path, float *r_progress) {
String local_path;
- if (p_path.is_rel_path())
+ if (p_path.is_rel_path()) {
local_path = "res://" + p_path;
- else
+ } else {
local_path = ProjectSettings::get_singleton()->localize_path(p_path);
+ }
thread_load_mutex->lock();
if (!thread_load_tasks.has(local_path)) {
@@ -416,10 +423,11 @@ ResourceLoader::ThreadLoadStatus ResourceLoader::load_threaded_get_status(const
RES ResourceLoader::load_threaded_get(const String &p_path, Error *r_error) {
String local_path;
- if (p_path.is_rel_path())
+ if (p_path.is_rel_path()) {
local_path = "res://" + p_path;
- else
+ } else {
local_path = ProjectSettings::get_singleton()->localize_path(p_path);
+ }
thread_load_mutex->lock();
if (!thread_load_tasks.has(local_path)) {
@@ -496,14 +504,16 @@ RES ResourceLoader::load_threaded_get(const String &p_path, Error *r_error) {
}
RES ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p_no_cache, Error *r_error) {
- if (r_error)
+ if (r_error) {
*r_error = ERR_CANT_OPEN;
+ }
String local_path;
- if (p_path.is_rel_path())
+ if (p_path.is_rel_path()) {
local_path = "res://" + p_path;
- else
+ } else {
local_path = ProjectSettings::get_singleton()->localize_path(p_path);
+ }
if (!p_no_cache) {
thread_load_mutex->lock();
@@ -586,8 +596,9 @@ RES ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p
return RES();
}
- if (xl_remapped)
+ if (xl_remapped) {
res->set_as_translation_remapped(true);
+ }
#ifdef TOOLS_ENABLED
@@ -605,10 +616,11 @@ RES ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p
bool ResourceLoader::exists(const String &p_path, const String &p_type_hint) {
String local_path;
- if (p_path.is_rel_path())
+ if (p_path.is_rel_path()) {
local_path = "res://" + p_path;
- else
+ } else {
local_path = ProjectSettings::get_singleton()->localize_path(p_path);
+ }
if (ResourceCache::has(local_path)) {
return true; // If cached, it probably exists
@@ -623,8 +635,9 @@ bool ResourceLoader::exists(const String &p_path, const String &p_type_hint) {
continue;
}
- if (loader[i]->exists(path))
+ if (loader[i]->exists(path)) {
return true;
+ }
}
return false;
@@ -651,8 +664,9 @@ void ResourceLoader::remove_resource_format_loader(Ref<ResourceFormatLoader> p_f
// Find loader
int i = 0;
for (; i < loader_count; ++i) {
- if (loader[i] == p_format_loader)
+ if (loader[i] == p_format_loader) {
break;
+ }
}
ERR_FAIL_COND(i >= loader_count); // Not found
@@ -669,14 +683,16 @@ int ResourceLoader::get_import_order(const String &p_path) {
String path = _path_remap(p_path);
String local_path;
- if (path.is_rel_path())
+ if (path.is_rel_path()) {
local_path = "res://" + path;
- else
+ } else {
local_path = ProjectSettings::get_singleton()->localize_path(path);
+ }
for (int i = 0; i < loader_count; i++) {
- if (!loader[i]->recognize_path(local_path))
+ if (!loader[i]->recognize_path(local_path)) {
continue;
+ }
/*
if (p_type_hint!="" && !loader[i]->handles_type(p_type_hint))
continue;
@@ -692,14 +708,16 @@ String ResourceLoader::get_import_group_file(const String &p_path) {
String path = _path_remap(p_path);
String local_path;
- if (path.is_rel_path())
+ if (path.is_rel_path()) {
local_path = "res://" + path;
- else
+ } else {
local_path = ProjectSettings::get_singleton()->localize_path(path);
+ }
for (int i = 0; i < loader_count; i++) {
- if (!loader[i]->recognize_path(local_path))
+ if (!loader[i]->recognize_path(local_path)) {
continue;
+ }
/*
if (p_type_hint!="" && !loader[i]->handles_type(p_type_hint))
continue;
@@ -715,14 +733,16 @@ bool ResourceLoader::is_import_valid(const String &p_path) {
String path = _path_remap(p_path);
String local_path;
- if (path.is_rel_path())
+ if (path.is_rel_path()) {
local_path = "res://" + path;
- else
+ } else {
local_path = ProjectSettings::get_singleton()->localize_path(path);
+ }
for (int i = 0; i < loader_count; i++) {
- if (!loader[i]->recognize_path(local_path))
+ if (!loader[i]->recognize_path(local_path)) {
continue;
+ }
/*
if (p_type_hint!="" && !loader[i]->handles_type(p_type_hint))
continue;
@@ -738,14 +758,16 @@ bool ResourceLoader::is_imported(const String &p_path) {
String path = _path_remap(p_path);
String local_path;
- if (path.is_rel_path())
+ if (path.is_rel_path()) {
local_path = "res://" + path;
- else
+ } else {
local_path = ProjectSettings::get_singleton()->localize_path(path);
+ }
for (int i = 0; i < loader_count; i++) {
- if (!loader[i]->recognize_path(local_path))
+ if (!loader[i]->recognize_path(local_path)) {
continue;
+ }
/*
if (p_type_hint!="" && !loader[i]->handles_type(p_type_hint))
continue;
@@ -761,14 +783,16 @@ void ResourceLoader::get_dependencies(const String &p_path, List<String> *p_depe
String path = _path_remap(p_path);
String local_path;
- if (path.is_rel_path())
+ if (path.is_rel_path()) {
local_path = "res://" + path;
- else
+ } else {
local_path = ProjectSettings::get_singleton()->localize_path(path);
+ }
for (int i = 0; i < loader_count; i++) {
- if (!loader[i]->recognize_path(local_path))
+ if (!loader[i]->recognize_path(local_path)) {
continue;
+ }
/*
if (p_type_hint!="" && !loader[i]->handles_type(p_type_hint))
continue;
@@ -782,14 +806,16 @@ Error ResourceLoader::rename_dependencies(const String &p_path, const Map<String
String path = _path_remap(p_path);
String local_path;
- if (path.is_rel_path())
+ if (path.is_rel_path()) {
local_path = "res://" + path;
- else
+ } else {
local_path = ProjectSettings::get_singleton()->localize_path(path);
+ }
for (int i = 0; i < loader_count; i++) {
- if (!loader[i]->recognize_path(local_path))
+ if (!loader[i]->recognize_path(local_path)) {
continue;
+ }
/*
if (p_type_hint!="" && !loader[i]->handles_type(p_type_hint))
continue;
@@ -803,10 +829,11 @@ Error ResourceLoader::rename_dependencies(const String &p_path, const Map<String
String ResourceLoader::get_resource_type(const String &p_path) {
String local_path;
- if (p_path.is_rel_path())
+ if (p_path.is_rel_path()) {
local_path = "res://" + p_path;
- else
+ } else {
local_path = ProjectSettings::get_singleton()->localize_path(p_path);
+ }
for (int i = 0; i < loader_count; i++) {
String result = loader[i]->get_resource_type(local_path);
@@ -951,8 +978,9 @@ void ResourceLoader::reload_translation_remaps() {
}
void ResourceLoader::load_translation_remaps() {
- if (!ProjectSettings::get_singleton()->has_setting("locale/translation_remaps"))
+ if (!ProjectSettings::get_singleton()->has_setting("locale/translation_remaps")) {
return;
+ }
Dictionary remaps = ProjectSettings::get_singleton()->get("locale/translation_remaps");
List<Variant> keys;
@@ -974,8 +1002,9 @@ void ResourceLoader::clear_translation_remaps() {
}
void ResourceLoader::load_path_remaps() {
- if (!ProjectSettings::get_singleton()->has_setting("path_remap/remapped_paths"))
+ if (!ProjectSettings::get_singleton()->has_setting("path_remap/remapped_paths")) {
return;
+ }
Vector<String> remaps = ProjectSettings::get_singleton()->get("path_remap/remapped_paths");
int rc = remaps.size();
@@ -1007,8 +1036,9 @@ Ref<ResourceFormatLoader> ResourceLoader::_find_custom_resource_format_loader(St
}
bool ResourceLoader::add_custom_resource_format_loader(String script_path) {
- if (_find_custom_resource_format_loader(script_path).is_valid())
+ if (_find_custom_resource_format_loader(script_path).is_valid()) {
return false;
+ }
Ref<Resource> res = ResourceLoader::load(script_path);
ERR_FAIL_COND_V(res.is_null(), false);
@@ -1032,8 +1062,9 @@ bool ResourceLoader::add_custom_resource_format_loader(String script_path) {
void ResourceLoader::remove_custom_resource_format_loader(String script_path) {
Ref<ResourceFormatLoader> custom_loader = _find_custom_resource_format_loader(script_path);
- if (custom_loader.is_valid())
+ if (custom_loader.is_valid()) {
remove_resource_format_loader(custom_loader);
+ }
}
void ResourceLoader::add_custom_loaders() {
diff --git a/core/io/resource_loader.h b/core/io/resource_loader.h
index 7d1c4b5d90..9322b5273a 100644
--- a/core/io/resource_loader.h
+++ b/core/io/resource_loader.h
@@ -158,8 +158,9 @@ public:
static bool get_timestamp_on_load() { return timestamp_on_load; }
static void notify_load_error(const String &p_err) {
- if (err_notify)
+ if (err_notify) {
err_notify(err_notify_ud, p_err);
+ }
}
static void set_error_notify_func(void *p_ud, ResourceLoadErrorNotify p_err_notify) {
err_notify = p_err_notify;
@@ -167,8 +168,9 @@ public:
}
static void notify_dependency_error(const String &p_path, const String &p_dependency, const String &p_type) {
- if (dep_err_notify)
+ if (dep_err_notify) {
dep_err_notify(dep_err_notify_ud, p_path, p_dependency, p_type);
+ }
}
static void set_dependency_error_notify_func(void *p_ud, DependencyErrorNotify p_err_notify) {
dep_err_notify = p_err_notify;
diff --git a/core/io/resource_saver.cpp b/core/io/resource_saver.cpp
index 445f9d0c37..a8da215b61 100644
--- a/core/io/resource_saver.cpp
+++ b/core/io/resource_saver.cpp
@@ -86,28 +86,32 @@ Error ResourceSaver::save(const String &p_path, const RES &p_resource, uint32_t
Error err = ERR_FILE_UNRECOGNIZED;
for (int i = 0; i < saver_count; i++) {
- if (!saver[i]->recognize(p_resource))
+ if (!saver[i]->recognize(p_resource)) {
continue;
+ }
List<String> extensions;
bool recognized = false;
saver[i]->get_recognized_extensions(p_resource, &extensions);
for (List<String>::Element *E = extensions.front(); E; E = E->next()) {
- if (E->get().nocasecmp_to(extension) == 0)
+ if (E->get().nocasecmp_to(extension) == 0) {
recognized = true;
+ }
}
- if (!recognized)
+ if (!recognized) {
continue;
+ }
String old_path = p_resource->get_path();
String local_path = ProjectSettings::get_singleton()->localize_path(p_path);
RES rwcopy = p_resource;
- if (p_flags & FLAG_CHANGE_PATH)
+ if (p_flags & FLAG_CHANGE_PATH) {
rwcopy->set_path(local_path);
+ }
err = saver[i]->save(p_path, p_resource, p_flags);
@@ -122,11 +126,13 @@ Error ResourceSaver::save(const String &p_path, const RES &p_resource, uint32_t
}
#endif
- if (p_flags & FLAG_CHANGE_PATH)
+ if (p_flags & FLAG_CHANGE_PATH) {
rwcopy->set_path(old_path);
+ }
- if (save_callback && p_path.begins_with("res://"))
+ if (save_callback && p_path.begins_with("res://")) {
save_callback(p_resource, p_path);
+ }
return OK;
}
@@ -166,8 +172,9 @@ void ResourceSaver::remove_resource_format_saver(Ref<ResourceFormatSaver> p_form
// Find saver
int i = 0;
for (; i < saver_count; ++i) {
- if (saver[i] == p_format_saver)
+ if (saver[i] == p_format_saver) {
break;
+ }
}
ERR_FAIL_COND(i >= saver_count); // Not found
@@ -190,8 +197,9 @@ Ref<ResourceFormatSaver> ResourceSaver::_find_custom_resource_format_saver(Strin
}
bool ResourceSaver::add_custom_resource_format_saver(String script_path) {
- if (_find_custom_resource_format_saver(script_path).is_valid())
+ if (_find_custom_resource_format_saver(script_path).is_valid()) {
return false;
+ }
Ref<Resource> res = ResourceLoader::load(script_path);
ERR_FAIL_COND_V(res.is_null(), false);
@@ -215,8 +223,9 @@ bool ResourceSaver::add_custom_resource_format_saver(String script_path) {
void ResourceSaver::remove_custom_resource_format_saver(String script_path) {
Ref<ResourceFormatSaver> custom_saver = _find_custom_resource_format_saver(script_path);
- if (custom_saver.is_valid())
+ if (custom_saver.is_valid()) {
remove_resource_format_saver(custom_saver);
+ }
}
void ResourceSaver::add_custom_savers() {
diff --git a/core/io/stream_peer.cpp b/core/io/stream_peer.cpp
index e6175e78da..403f61bb24 100644
--- a/core/io/stream_peer.cpp
+++ b/core/io/stream_peer.cpp
@@ -34,8 +34,9 @@
Error StreamPeer::_put_data(const Vector<uint8_t> &p_data) {
int len = p_data.size();
- if (len == 0)
+ if (len == 0) {
return OK;
+ }
const uint8_t *r = p_data.ptr();
return put_data(&r[0], len);
}
@@ -318,8 +319,9 @@ double StreamPeer::get_double() {
}
String StreamPeer::get_string(int p_bytes) {
- if (p_bytes < 0)
+ if (p_bytes < 0) {
p_bytes = get_u32();
+ }
ERR_FAIL_COND_V(p_bytes < 0, String());
Vector<char> buf;
@@ -332,8 +334,9 @@ String StreamPeer::get_string(int p_bytes) {
}
String StreamPeer::get_utf8_string(int p_bytes) {
- if (p_bytes < 0)
+ if (p_bytes < 0) {
p_bytes = get_u32();
+ }
ERR_FAIL_COND_V(p_bytes < 0, String());
Vector<uint8_t> buf;
@@ -421,8 +424,9 @@ void StreamPeerBuffer::_bind_methods() {
}
Error StreamPeerBuffer::put_data(const uint8_t *p_data, int p_bytes) {
- if (p_bytes <= 0)
+ if (p_bytes <= 0) {
return OK;
+ }
if (pointer + p_bytes > data.size()) {
data.resize(pointer + p_bytes);
@@ -443,8 +447,9 @@ Error StreamPeerBuffer::put_partial_data(const uint8_t *p_data, int p_bytes, int
Error StreamPeerBuffer::get_data(uint8_t *p_buffer, int p_bytes) {
int recv;
get_partial_data(p_buffer, p_bytes, recv);
- if (recv != p_bytes)
+ if (recv != p_bytes) {
return ERR_INVALID_PARAMETER;
+ }
return OK;
}
diff --git a/core/io/stream_peer_ssl.cpp b/core/io/stream_peer_ssl.cpp
index 92c775a565..3dc31c6769 100644
--- a/core/io/stream_peer_ssl.cpp
+++ b/core/io/stream_peer_ssl.cpp
@@ -35,8 +35,9 @@
StreamPeerSSL *(*StreamPeerSSL::_create)() = nullptr;
StreamPeerSSL *StreamPeerSSL::create() {
- if (_create)
+ if (_create) {
return _create();
+ }
return nullptr;
}
diff --git a/core/io/stream_peer_tcp.cpp b/core/io/stream_peer_tcp.cpp
index fd7ffa8458..cce728c30a 100644
--- a/core/io/stream_peer_tcp.cpp
+++ b/core/io/stream_peer_tcp.cpp
@@ -117,8 +117,9 @@ Error StreamPeerTCP::write(const uint8_t *p_data, int p_bytes, int &r_sent, bool
}
}
- if (!_sock->is_open())
+ if (!_sock->is_open()) {
return FAILED;
+ }
Error err;
int data_to_send = p_bytes;
@@ -257,8 +258,9 @@ StreamPeerTCP::Status StreamPeerTCP::get_status() {
}
void StreamPeerTCP::disconnect_from_host() {
- if (_sock.is_valid() && _sock->is_open())
+ if (_sock.is_valid() && _sock->is_open()) {
_sock->close();
+ }
timeout = 0;
status = STATUS_NONE;
@@ -308,8 +310,9 @@ Error StreamPeerTCP::_connect(const String &p_address, int p_port) {
ip = p_address;
} else {
ip = IP::get_singleton()->resolve_hostname(p_address);
- if (!ip.is_valid())
+ if (!ip.is_valid()) {
return ERR_CANT_RESOLVE;
+ }
}
return connect_to_host(ip, p_port);
diff --git a/core/io/tcp_server.cpp b/core/io/tcp_server.cpp
index 706c650d7e..d7061b6bf4 100644
--- a/core/io/tcp_server.cpp
+++ b/core/io/tcp_server.cpp
@@ -47,8 +47,9 @@ Error TCP_Server::listen(uint16_t p_port, const IP_Address &p_bind_address) {
IP::Type ip_type = IP::TYPE_ANY;
// If the bind address is valid use its type as the socket type
- if (p_bind_address.is_valid())
+ if (p_bind_address.is_valid()) {
ip_type = p_bind_address.is_ipv4() ? IP::TYPE_IPV4 : IP::TYPE_IPV6;
+ }
err = _sock->open(NetSocket::TYPE_TCP, ip_type);
@@ -82,8 +83,9 @@ bool TCP_Server::is_listening() const {
bool TCP_Server::is_connection_available() const {
ERR_FAIL_COND_V(!_sock.is_valid(), false);
- if (!_sock->is_open())
+ if (!_sock->is_open()) {
return false;
+ }
Error err = _sock->poll(NetSocket::POLL_TYPE_IN, 0);
return (err == OK);
@@ -99,8 +101,9 @@ Ref<StreamPeerTCP> TCP_Server::take_connection() {
IP_Address ip;
uint16_t port = 0;
ns = _sock->accept(ip, port);
- if (!ns.is_valid())
+ if (!ns.is_valid()) {
return conn;
+ }
conn = Ref<StreamPeerTCP>(memnew(StreamPeerTCP));
conn->accept_socket(ns, ip, port);
diff --git a/core/io/translation_loader_po.cpp b/core/io/translation_loader_po.cpp
index 5e109699f5..0e0a948953 100644
--- a/core/io/translation_loader_po.cpp
+++ b/core/io/translation_loader_po.cpp
@@ -47,8 +47,9 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) {
String msg_str;
String config;
- if (r_error)
+ if (r_error) {
*r_error = ERR_FILE_CORRUPT;
+ }
Ref<Translation> translation = Ref<Translation>(memnew(Translation));
int line = 1;
@@ -77,10 +78,12 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) {
}
if (msg_id != "") {
- if (!skip_this)
+ if (!skip_this) {
translation->add_message(msg_id, msg_str);
- } else if (config == "")
+ }
+ } else if (config == "") {
config = msg_str;
+ }
l = l.substr(5, l.length()).strip_edges();
status = STATUS_READING_ID;
@@ -135,10 +138,11 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) {
l = l.substr(0, end_pos);
l = l.c_unescape();
- if (status == STATUS_READING_ID)
+ if (status == STATUS_READING_ID) {
msg_id += l;
- else
+ } else {
msg_str += l;
+ }
line++;
}
@@ -148,10 +152,12 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) {
if (status == STATUS_READING_STRING) {
if (msg_id != "") {
- if (!skip_this)
+ if (!skip_this) {
translation->add_message(msg_id, msg_str);
- } else if (config == "")
+ }
+ } else if (config == "") {
config = msg_str;
+ }
}
ERR_FAIL_COND_V_MSG(config == "", RES(), "No config found in file: " + f->get_path() + ".");
@@ -160,8 +166,9 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) {
for (int i = 0; i < configs.size(); i++) {
String c = configs[i].strip_edges();
int p = c.find(":");
- if (p == -1)
+ if (p == -1) {
continue;
+ }
String prop = c.substr(0, p).strip_edges();
String value = c.substr(p + 1, c.length()).strip_edges();
@@ -170,15 +177,17 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) {
}
}
- if (r_error)
+ if (r_error) {
*r_error = OK;
+ }
return translation;
}
RES TranslationLoaderPO::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) {
- if (r_error)
+ if (r_error) {
*r_error = ERR_CANT_OPEN;
+ }
FileAccess *f = FileAccess::open(p_path, FileAccess::READ);
ERR_FAIL_COND_V_MSG(!f, RES(), "Cannot open file '" + p_path + "'.");
@@ -196,7 +205,8 @@ bool TranslationLoaderPO::handles_type(const String &p_type) const {
}
String TranslationLoaderPO::get_resource_type(const String &p_path) const {
- if (p_path.get_extension().to_lower() == "po")
+ if (p_path.get_extension().to_lower() == "po") {
return "Translation";
+ }
return "";
}
diff --git a/core/io/udp_server.cpp b/core/io/udp_server.cpp
index 40180dcb09..1d329daf8b 100644
--- a/core/io/udp_server.cpp
+++ b/core/io/udp_server.cpp
@@ -46,13 +46,15 @@ Error UDPServer::listen(uint16_t p_port, const IP_Address &p_bind_address) {
Error err;
IP::Type ip_type = IP::TYPE_ANY;
- if (p_bind_address.is_valid())
+ if (p_bind_address.is_valid()) {
ip_type = p_bind_address.is_ipv4() ? IP::TYPE_IPV4 : IP::TYPE_IPV6;
+ }
err = _sock->open(NetSocket::TYPE_UDP, ip_type);
- if (err != OK)
+ if (err != OK) {
return ERR_CANT_CREATE;
+ }
_sock->set_blocking_enabled(false);
_sock->set_reuse_address_enabled(true);
@@ -76,8 +78,9 @@ bool UDPServer::is_listening() const {
bool UDPServer::is_connection_available() const {
ERR_FAIL_COND_V(!_sock.is_valid(), false);
- if (!_sock->is_open())
+ if (!_sock->is_open()) {
return false;
+ }
Error err = _sock->poll(NetSocket::POLL_TYPE_IN, 0);
return (err == OK);
diff --git a/core/io/xml_parser.cpp b/core/io/xml_parser.cpp
index d575e75f0c..11f82fef9d 100644
--- a/core/io/xml_parser.cpp
+++ b/core/io/xml_parser.cpp
@@ -38,9 +38,11 @@ VARIANT_ENUM_CAST(XMLParser::NodeType);
static bool _equalsn(const CharType *str1, const CharType *str2, int len) {
int i;
- for (i = 0; i < len && str1[i] && str2[i]; ++i)
- if (str1[i] != str2[i])
+ for (i = 0; i < len && str1[i] && str2[i]; ++i) {
+ if (str1[i] != str2[i]) {
return false;
+ }
+ }
// if one (or both) of the strings was smaller then they
// are only equal if they have the same length
@@ -51,8 +53,9 @@ String XMLParser::_replace_special_characters(const String &origstr) {
int pos = origstr.find("&");
int oldPos = 0;
- if (pos == -1)
+ if (pos == -1) {
return origstr;
+ }
String newstr;
@@ -83,8 +86,9 @@ String XMLParser::_replace_special_characters(const String &origstr) {
pos = origstr.find("&", pos);
}
- if (oldPos < origstr.length() - 1)
+ if (oldPos < origstr.length() - 1) {
newstr += (origstr.substr(oldPos, origstr.length() - oldPos));
+ }
return newstr;
}
@@ -99,12 +103,15 @@ bool XMLParser::_set_text(char *start, char *end) {
// only white space, so that this text won't be reported
if (end - start < 3) {
char *p = start;
- for (; p != end; ++p)
- if (!_is_white_space(*p))
+ for (; p != end; ++p) {
+ if (!_is_white_space(*p)) {
break;
+ }
+ }
- if (p == end)
+ if (p == end) {
return false;
+ }
}
// set current text to the parsed text, and replace xml special characters
@@ -125,8 +132,9 @@ void XMLParser::_parse_closing_xml_element() {
++P;
const char *pBeginClose = P;
- while (*P != '>')
+ while (*P != '>') {
++P;
+ }
node_name = String::utf8(pBeginClose, (int)(P - pBeginClose));
#ifdef DEBUG_XML
@@ -140,15 +148,17 @@ void XMLParser::_ignore_definition() {
char *F = P;
// move until end marked with '>' reached
- while (*P != '>')
+ while (*P != '>') {
++P;
+ }
node_name.parse_utf8(F, P - F);
++P;
}
bool XMLParser::_parse_cdata() {
- if (*(P + 1) != '[')
+ if (*(P + 1) != '[') {
return false;
+ }
node_type = NODE_CDATA;
@@ -159,8 +169,9 @@ bool XMLParser::_parse_cdata() {
++count;
}
- if (!*P)
+ if (!*P) {
return true;
+ }
char *cDataBegin = P;
char *cDataEnd = nullptr;
@@ -176,10 +187,11 @@ bool XMLParser::_parse_cdata() {
++P;
}
- if (cDataEnd)
+ if (cDataEnd) {
node_name = String::utf8(cDataBegin, (int)(cDataEnd - cDataBegin));
- else
+ } else {
node_name = "";
+ }
#ifdef DEBUG_XML
print_line("XML CDATA: " + node_name);
#endif
@@ -197,10 +209,11 @@ void XMLParser::_parse_comment() {
// move until end of comment reached
while (count) {
- if (*P == '>')
+ if (*P == '>') {
--count;
- else if (*P == '<')
+ } else if (*P == '<') {
++count;
+ }
++P;
}
@@ -222,46 +235,52 @@ void XMLParser::_parse_opening_xml_element() {
const char *startName = P;
// find end of element
- while (*P != '>' && !_is_white_space(*P))
+ while (*P != '>' && !_is_white_space(*P)) {
++P;
+ }
const char *endName = P;
// find attributes
while (*P != '>') {
- if (_is_white_space(*P))
+ if (_is_white_space(*P)) {
++P;
- else {
+ } else {
if (*P != '/') {
// we've got an attribute
// read the attribute names
const char *attributeNameBegin = P;
- while (!_is_white_space(*P) && *P != '=')
+ while (!_is_white_space(*P) && *P != '=') {
++P;
+ }
const char *attributeNameEnd = P;
++P;
// read the attribute value
// check for quotes and single quotes, thx to murphy
- while ((*P != '\"') && (*P != '\'') && *P)
+ while ((*P != '\"') && (*P != '\'') && *P) {
++P;
+ }
- if (!*P) // malformatted xml file
+ if (!*P) { // malformatted xml file
return;
+ }
const char attributeQuoteChar = *P;
++P;
const char *attributeValueBegin = P;
- while (*P != attributeQuoteChar && *P)
+ while (*P != attributeQuoteChar && *P) {
++P;
+ }
- if (!*P) // malformatted xml file
+ if (!*P) { // malformatted xml file
return;
+ }
const char *attributeValueEnd = P;
++P;
@@ -304,16 +323,19 @@ void XMLParser::_parse_current_node() {
node_offset = P - data;
// more forward until '<' found
- while (*P != '<' && *P)
+ while (*P != '<' && *P) {
++P;
+ }
- if (!*P)
+ if (!*P) {
return;
+ }
if (P - start > 0) {
// we found some text, store it
- if (_set_text(start, P))
+ if (_set_text(start, P)) {
return;
+ }
}
++P;
@@ -327,8 +349,9 @@ void XMLParser::_parse_current_node() {
_ignore_definition();
break;
case '!':
- if (!_parse_cdata())
+ if (!_parse_cdata()) {
_parse_comment();
+ }
break;
default:
_parse_opening_xml_element();
@@ -417,8 +440,9 @@ String XMLParser::get_attribute_value(int p_idx) const {
bool XMLParser::has_attribute(const String &p_name) const {
for (int i = 0; i < attributes.size(); i++) {
- if (attributes[i].name == p_name)
+ if (attributes[i].name == p_name) {
return true;
+ }
}
return false;
@@ -447,8 +471,9 @@ String XMLParser::get_attribute_value_safe(const String &p_name) const {
}
}
- if (idx < 0)
+ if (idx < 0) {
return "";
+ }
return attributes[idx].value;
}
@@ -496,8 +521,9 @@ Error XMLParser::open(const String &p_path) {
void XMLParser::skip_section() {
// skip if this element is empty anyway.
- if (is_empty())
+ if (is_empty()) {
return;
+ }
// read until we've reached the last element in this section
int tagcount = 1;
@@ -506,14 +532,16 @@ void XMLParser::skip_section() {
if (get_node_type() == XMLParser::NODE_ELEMENT &&
!is_empty()) {
++tagcount;
- } else if (get_node_type() == XMLParser::NODE_ELEMENT_END)
+ } else if (get_node_type() == XMLParser::NODE_ELEMENT_END) {
--tagcount;
+ }
}
}
void XMLParser::close() {
- if (data)
+ if (data) {
memdelete_arr(data);
+ }
data = nullptr;
length = 0;
P = nullptr;
@@ -535,6 +563,7 @@ XMLParser::XMLParser() {
}
XMLParser::~XMLParser() {
- if (data)
+ if (data) {
memdelete_arr(data);
+ }
}
diff --git a/core/io/zip_io.cpp b/core/io/zip_io.cpp
index 68dd633e70..1979e91b8c 100644
--- a/core/io/zip_io.cpp
+++ b/core/io/zip_io.cpp
@@ -44,8 +44,9 @@ void *zipio_open(void *data, const char *p_fname, int mode) {
f = FileAccess::open(fname, FileAccess::READ);
}
- if (!f)
+ if (!f) {
return nullptr;
+ }
return data;
}
diff --git a/core/list.h b/core/list.h
index fc943790de..86e4a45036 100644
--- a/core/list.h
+++ b/core/list.h
@@ -149,14 +149,17 @@ private:
first = p_I->next_ptr;
};
- if (last == p_I)
+ if (last == p_I) {
last = p_I->prev_ptr;
+ }
- if (p_I->prev_ptr)
+ if (p_I->prev_ptr) {
p_I->prev_ptr->next_ptr = p_I->next_ptr;
+ }
- if (p_I->next_ptr)
+ if (p_I->next_ptr) {
p_I->next_ptr->prev_ptr = p_I->prev_ptr;
+ }
memdelete_allocator<Element, A>(const_cast<Element *>(p_I));
size_cache--;
@@ -220,8 +223,9 @@ public:
_data->last = n;
- if (!_data->first)
+ if (!_data->first) {
_data->first = n;
+ }
_data->size_cache++;
@@ -229,8 +233,9 @@ public:
};
void pop_back() {
- if (_data && _data->last)
+ if (_data && _data->last) {
erase(_data->last);
+ }
}
/**
@@ -256,8 +261,9 @@ public:
_data->first = n;
- if (!_data->last)
+ if (!_data->last) {
_data->last = n;
+ }
_data->size_cache++;
@@ -265,8 +271,9 @@ public:
};
void pop_front() {
- if (_data && _data->first)
+ if (_data && _data->first) {
erase(_data->first);
+ }
}
Element *insert_after(Element *p_element, const T &p_value) {
@@ -328,8 +335,9 @@ public:
Element *find(const T_v &p_val) {
Element *it = front();
while (it) {
- if (it->value == p_val)
+ if (it->value == p_val) {
return it;
+ }
it = it->next();
};
@@ -396,15 +404,19 @@ public:
p_B->next_ptr = A_next;
p_B->prev_ptr = A_prev;
- if (p_A->prev_ptr)
+ if (p_A->prev_ptr) {
p_A->prev_ptr->next_ptr = p_A;
- if (p_A->next_ptr)
+ }
+ if (p_A->next_ptr) {
p_A->next_ptr->prev_ptr = p_A;
+ }
- if (p_B->prev_ptr)
+ if (p_B->prev_ptr) {
p_B->prev_ptr->next_ptr = p_B;
- if (p_B->next_ptr)
+ }
+ if (p_B->next_ptr) {
p_B->next_ptr->prev_ptr = p_B;
+ }
}
/**
* copy the list
@@ -446,18 +458,21 @@ public:
void move_to_back(Element *p_I) {
ERR_FAIL_COND(p_I->data != _data);
- if (!p_I->next_ptr)
+ if (!p_I->next_ptr) {
return;
+ }
if (_data->first == p_I) {
_data->first = p_I->next_ptr;
};
- if (_data->last == p_I)
+ if (_data->last == p_I) {
_data->last = p_I->prev_ptr;
+ }
- if (p_I->prev_ptr)
+ if (p_I->prev_ptr) {
p_I->prev_ptr->next_ptr = p_I->next_ptr;
+ }
p_I->next_ptr->prev_ptr = p_I->prev_ptr;
@@ -480,20 +495,23 @@ public:
void move_to_front(Element *p_I) {
ERR_FAIL_COND(p_I->data != _data);
- if (!p_I->prev_ptr)
+ if (!p_I->prev_ptr) {
return;
+ }
if (_data->first == p_I) {
_data->first = p_I->next_ptr;
};
- if (_data->last == p_I)
+ if (_data->last == p_I) {
_data->last = p_I->prev_ptr;
+ }
p_I->prev_ptr->next_ptr = p_I->next_ptr;
- if (p_I->next_ptr)
+ if (p_I->next_ptr) {
p_I->next_ptr->prev_ptr = p_I->prev_ptr;
+ }
_data->first->prev_ptr = p_I;
p_I->next_ptr = _data->first;
@@ -541,8 +559,9 @@ public:
template <class C>
void sort_custom_inplace() {
- if (size() < 2)
+ if (size() < 2) {
return;
+ }
Element *from = front();
Element *current = from;
@@ -563,15 +582,17 @@ public:
find = find->next_ptr;
}
- if (current->prev_ptr)
+ if (current->prev_ptr) {
current->prev_ptr->next_ptr = current;
- else
+ } else {
from = current;
+ }
- if (current->next_ptr)
+ if (current->next_ptr) {
current->next_ptr->prev_ptr = current;
- else
+ } else {
to = current;
+ }
} else {
current->prev_ptr = nullptr;
current->next_ptr = nullptr;
@@ -597,8 +618,9 @@ public:
//if you don't want to use auxiliary memory, use the in_place version
int s = size();
- if (s < 2)
+ if (s < 2) {
return;
+ }
Element **aux_buffer = memnew_arr(Element *, s);
diff --git a/core/local_vector.h b/core/local_vector.h
index e8b02fe661..c8abb32bf5 100644
--- a/core/local_vector.h
+++ b/core/local_vector.h
@@ -76,8 +76,9 @@ public:
void erase(const T &p_val) {
U idx = find(p_val);
- if (idx >= 0)
+ if (idx >= 0) {
remove(idx);
+ }
}
void invert() {
@@ -167,8 +168,9 @@ public:
template <class C>
void sort_custom() {
U len = count;
- if (len == 0)
+ if (len == 0) {
return;
+ }
SortArray<T, C> sorter;
sorter.sort(data, len);
diff --git a/core/map.h b/core/map.h
index f9321f90b3..4861d6a026 100644
--- a/core/map.h
+++ b/core/map.h
@@ -138,13 +138,15 @@ private:
inline void _rotate_left(Element *p_node) {
Element *r = p_node->right;
p_node->right = r->left;
- if (r->left != _data._nil)
+ if (r->left != _data._nil) {
r->left->parent = p_node;
+ }
r->parent = p_node->parent;
- if (p_node == p_node->parent->left)
+ if (p_node == p_node->parent->left) {
p_node->parent->left = r;
- else
+ } else {
p_node->parent->right = r;
+ }
r->left = p_node;
p_node->parent = r;
@@ -153,13 +155,15 @@ private:
inline void _rotate_right(Element *p_node) {
Element *l = p_node->left;
p_node->left = l->right;
- if (l->right != _data._nil)
+ if (l->right != _data._nil) {
l->right->parent = p_node;
+ }
l->parent = p_node->parent;
- if (p_node == p_node->parent->right)
+ if (p_node == p_node->parent->right) {
p_node->parent->right = l;
- else
+ } else {
p_node->parent->left = l;
+ }
l->right = p_node;
p_node->parent = l;
@@ -179,8 +183,9 @@ private:
node = node->parent;
}
- if (node->parent == _data._root)
+ if (node->parent == _data._root) {
return nullptr; // No successor, as p_node = last node
+ }
return node->parent;
}
}
@@ -199,8 +204,9 @@ private:
node = node->parent;
}
- if (node == _data._root)
+ if (node == _data._root) {
return nullptr; // No predecessor, as p_node = first node
+ }
return node->parent;
}
}
@@ -210,12 +216,13 @@ private:
C less;
while (node != _data._nil) {
- if (less(p_key, node->_key))
+ if (less(p_key, node->_key)) {
node = node->left;
- else if (less(node->_key, p_key))
+ } else if (less(node->_key, p_key)) {
node = node->right;
- else
+ } else {
return node; // found
+ }
}
return nullptr;
@@ -229,19 +236,22 @@ private:
while (node != _data._nil) {
prev = node;
- if (less(p_key, node->_key))
+ if (less(p_key, node->_key)) {
node = node->left;
- else if (less(node->_key, p_key))
+ } else if (less(node->_key, p_key)) {
node = node->right;
- else
+ } else {
return node; // found
+ }
}
- if (prev == nullptr)
+ if (prev == nullptr) {
return nullptr; // tree empty
+ }
- if (less(p_key, prev->_key))
+ if (less(p_key, prev->_key)) {
prev = prev->_prev;
+ }
return prev;
}
@@ -302,11 +312,11 @@ private:
while (node != _data._nil) {
new_parent = node;
- if (less(p_key, node->_key))
+ if (less(p_key, node->_key)) {
node = node->left;
- else if (less(node->_key, p_key))
+ } else if (less(node->_key, p_key)) {
node = node->right;
- else {
+ } else {
node->_value = p_value;
return node; // Return existing node with new value
}
@@ -328,10 +338,12 @@ private:
new_node->_next = _successor(new_node);
new_node->_prev = _predecessor(new_node);
- if (new_node->_next)
+ if (new_node->_next) {
new_node->_next->_prev = new_node;
- if (new_node->_prev)
+ }
+ if (new_node->_prev) {
new_node->_prev->_next = new_node;
+ }
_data.size_cache++;
_insert_rb_fix(new_node);
@@ -426,10 +438,12 @@ private:
rp->right = p_node->right;
rp->parent = p_node->parent;
rp->color = p_node->color;
- if (p_node->left != _data._nil)
+ if (p_node->left != _data._nil) {
p_node->left->parent = rp;
- if (p_node->right != _data._nil)
+ }
+ if (p_node->right != _data._nil) {
p_node->right->parent = rp;
+ }
if (p_node == p_node->parent->left) {
p_node->parent->left = rp;
@@ -438,10 +452,12 @@ private:
}
}
- if (p_node->_next)
+ if (p_node->_next) {
p_node->_next->_prev = p_node->_prev;
- if (p_node->_prev)
+ }
+ if (p_node->_prev) {
p_node->_prev->_next = p_node->_next;
+ }
memdelete_allocator<Element, A>(p_node);
_data.size_cache--;
@@ -449,19 +465,22 @@ private:
}
void _calculate_depth(Element *p_element, int &max_d, int d) const {
- if (p_element == _data._nil)
+ if (p_element == _data._nil) {
return;
+ }
_calculate_depth(p_element->left, max_d, d + 1);
_calculate_depth(p_element->right, max_d, d + 1);
- if (d > max_d)
+ if (d > max_d) {
max_d = d;
+ }
}
void _cleanup_tree(Element *p_element) {
- if (p_element == _data._nil)
+ if (p_element == _data._nil) {
return;
+ }
_cleanup_tree(p_element->left);
_cleanup_tree(p_element->right);
@@ -478,32 +497,36 @@ private:
public:
const Element *find(const K &p_key) const {
- if (!_data._root)
+ if (!_data._root) {
return nullptr;
+ }
const Element *res = _find(p_key);
return res;
}
Element *find(const K &p_key) {
- if (!_data._root)
+ if (!_data._root) {
return nullptr;
+ }
Element *res = _find(p_key);
return res;
}
const Element *find_closest(const K &p_key) const {
- if (!_data._root)
+ if (!_data._root) {
return nullptr;
+ }
const Element *res = _find_closest(p_key);
return res;
}
Element *find_closest(const K &p_key) {
- if (!_data._root)
+ if (!_data._root) {
return nullptr;
+ }
Element *res = _find_closest(p_key);
return res;
@@ -514,31 +537,37 @@ public:
}
Element *insert(const K &p_key, const V &p_value) {
- if (!_data._root)
+ if (!_data._root) {
_data._create_root();
+ }
return _insert(p_key, p_value);
}
void erase(Element *p_element) {
- if (!_data._root || !p_element)
+ if (!_data._root || !p_element) {
return;
+ }
_erase(p_element);
- if (_data.size_cache == 0 && _data._root)
+ if (_data.size_cache == 0 && _data._root) {
_data._free_root();
+ }
}
bool erase(const K &p_key) {
- if (!_data._root)
+ if (!_data._root) {
return false;
+ }
Element *e = find(p_key);
- if (!e)
+ if (!e) {
return false;
+ }
_erase(e);
- if (_data.size_cache == 0 && _data._root)
+ if (_data.size_cache == 0 && _data._root) {
_data._free_root();
+ }
return true;
}
@@ -550,40 +579,48 @@ public:
}
V &operator[](const K &p_key) {
- if (!_data._root)
+ if (!_data._root) {
_data._create_root();
+ }
Element *e = find(p_key);
- if (!e)
+ if (!e) {
e = insert(p_key, V());
+ }
return e->_value;
}
Element *front() const {
- if (!_data._root)
+ if (!_data._root) {
return nullptr;
+ }
Element *e = _data._root->left;
- if (e == _data._nil)
+ if (e == _data._nil) {
return nullptr;
+ }
- while (e->left != _data._nil)
+ while (e->left != _data._nil) {
e = e->left;
+ }
return e;
}
Element *back() const {
- if (!_data._root)
+ if (!_data._root) {
return nullptr;
+ }
Element *e = _data._root->left;
- if (e == _data._nil)
+ if (e == _data._nil) {
return nullptr;
+ }
- while (e->right != _data._nil)
+ while (e->right != _data._nil) {
e = e->right;
+ }
return e;
}
@@ -593,8 +630,9 @@ public:
int calculate_depth() const {
// used for debug mostly
- if (!_data._root)
+ if (!_data._root) {
return 0;
+ }
int max_d = 0;
_calculate_depth(_data._root->left, max_d, 0);
@@ -602,8 +640,9 @@ public:
}
void clear() {
- if (!_data._root)
+ if (!_data._root) {
return;
+ }
_cleanup_tree(_data._root->left);
_data._root->left = _data._nil;
diff --git a/core/math/a_star.cpp b/core/math/a_star.cpp
index a85a0e9db9..45c4a207c3 100644
--- a/core/math/a_star.cpp
+++ b/core/math/a_star.cpp
@@ -154,8 +154,9 @@ void AStar::connect_points(int p_id, int p_with_id, bool bidirectional) {
}
Segment s(p_id, p_with_id);
- if (bidirectional)
+ if (bidirectional) {
s.direction = Segment::BIDIRECTIONAL;
+ }
Set<Segment>::Element *element = segments.find(s);
if (element != nullptr) {
@@ -197,15 +198,17 @@ void AStar::disconnect_points(int p_id, int p_with_id, bool bidirectional) {
b->unlinked_neighbours.remove(a->id);
}
} else {
- if (s.direction == Segment::NONE)
+ if (s.direction == Segment::NONE) {
b->unlinked_neighbours.remove(a->id);
- else
+ } else {
a->unlinked_neighbours.set(b->id, b);
+ }
}
segments.erase(element);
- if (s.direction != Segment::NONE)
+ if (s.direction != Segment::NONE) {
segments.insert(s);
+ }
}
}
@@ -273,8 +276,9 @@ int AStar::get_closest_point(const Vector3 &p_point, bool p_include_disabled) co
real_t closest_dist = 1e20;
for (OAHashMap<int, Point *>::Iterator it = points.iter(); it.valid; it = points.next_iter(it)) {
- if (!p_include_disabled && !(*it.value)->enabled)
+ if (!p_include_disabled && !(*it.value)->enabled) {
continue; // Disabled points should not be considered.
+ }
real_t d = p_point.distance_squared_to((*it.value)->pos);
if (closest_id < 0 || d < closest_dist) {
@@ -320,8 +324,9 @@ Vector3 AStar::get_closest_position_in_segment(const Vector3 &p_point) const {
bool AStar::_solve(Point *begin_point, Point *end_point) {
pass++;
- if (!end_point->enabled)
+ if (!end_point->enabled) {
return false;
+ }
bool found_route = false;
@@ -379,8 +384,9 @@ bool AStar::_solve(Point *begin_point, Point *end_point) {
}
real_t AStar::_estimate_cost(int p_from_id, int p_to_id) {
- if (get_script_instance() && get_script_instance()->has_method(SceneStringNames::get_singleton()->_estimate_cost))
+ if (get_script_instance() && get_script_instance()->has_method(SceneStringNames::get_singleton()->_estimate_cost)) {
return get_script_instance()->call(SceneStringNames::get_singleton()->_estimate_cost, p_from_id, p_to_id);
+ }
Point *from_point;
bool from_exists = points.lookup(p_from_id, from_point);
@@ -394,8 +400,9 @@ real_t AStar::_estimate_cost(int p_from_id, int p_to_id) {
}
real_t AStar::_compute_cost(int p_from_id, int p_to_id) {
- if (get_script_instance() && get_script_instance()->has_method(SceneStringNames::get_singleton()->_compute_cost))
+ if (get_script_instance() && get_script_instance()->has_method(SceneStringNames::get_singleton()->_compute_cost)) {
return get_script_instance()->call(SceneStringNames::get_singleton()->_compute_cost, p_from_id, p_to_id);
+ }
Point *from_point;
bool from_exists = points.lookup(p_from_id, from_point);
@@ -427,8 +434,9 @@ Vector<Vector3> AStar::get_point_path(int p_from_id, int p_to_id) {
Point *end_point = b;
bool found_route = _solve(begin_point, end_point);
- if (!found_route)
+ if (!found_route) {
return Vector<Vector3>();
+ }
Point *p = end_point;
int pc = 1; // Begin point
@@ -475,8 +483,9 @@ Vector<int> AStar::get_id_path(int p_from_id, int p_to_id) {
Point *end_point = b;
bool found_route = _solve(begin_point, end_point);
- if (!found_route)
+ if (!found_route) {
return Vector<int>();
+ }
Point *p = end_point;
int pc = 1; // Begin point
@@ -647,8 +656,9 @@ Vector2 AStar2D::get_closest_position_in_segment(const Vector2 &p_point) const {
}
real_t AStar2D::_estimate_cost(int p_from_id, int p_to_id) {
- if (get_script_instance() && get_script_instance()->has_method(SceneStringNames::get_singleton()->_estimate_cost))
+ if (get_script_instance() && get_script_instance()->has_method(SceneStringNames::get_singleton()->_estimate_cost)) {
return get_script_instance()->call(SceneStringNames::get_singleton()->_estimate_cost, p_from_id, p_to_id);
+ }
AStar::Point *from_point;
bool from_exists = astar.points.lookup(p_from_id, from_point);
@@ -662,8 +672,9 @@ real_t AStar2D::_estimate_cost(int p_from_id, int p_to_id) {
}
real_t AStar2D::_compute_cost(int p_from_id, int p_to_id) {
- if (get_script_instance() && get_script_instance()->has_method(SceneStringNames::get_singleton()->_compute_cost))
+ if (get_script_instance() && get_script_instance()->has_method(SceneStringNames::get_singleton()->_compute_cost)) {
return get_script_instance()->call(SceneStringNames::get_singleton()->_compute_cost, p_from_id, p_to_id);
+ }
AStar::Point *from_point;
bool from_exists = astar.points.lookup(p_from_id, from_point);
@@ -695,8 +706,9 @@ Vector<Vector2> AStar2D::get_point_path(int p_from_id, int p_to_id) {
AStar::Point *end_point = b;
bool found_route = _solve(begin_point, end_point);
- if (!found_route)
+ if (!found_route) {
return Vector<Vector2>();
+ }
AStar::Point *p = end_point;
int pc = 1; // Begin point
@@ -743,8 +755,9 @@ Vector<int> AStar2D::get_id_path(int p_from_id, int p_to_id) {
AStar::Point *end_point = b;
bool found_route = _solve(begin_point, end_point);
- if (!found_route)
+ if (!found_route) {
return Vector<int>();
+ }
AStar::Point *p = end_point;
int pc = 1; // Begin point
@@ -775,8 +788,9 @@ Vector<int> AStar2D::get_id_path(int p_from_id, int p_to_id) {
bool AStar2D::_solve(AStar::Point *begin_point, AStar::Point *end_point) {
astar.pass++;
- if (!end_point->enabled)
+ if (!end_point->enabled) {
return false;
+ }
bool found_route = false;
diff --git a/core/math/aabb.cpp b/core/math/aabb.cpp
index d9cb928944..f5c667dab0 100644
--- a/core/math/aabb.cpp
+++ b/core/math/aabb.cpp
@@ -78,23 +78,23 @@ AABB AABB::intersection(const AABB &p_aabb) const {
Vector3 min, max;
- if (src_min.x > dst_max.x || src_max.x < dst_min.x)
+ if (src_min.x > dst_max.x || src_max.x < dst_min.x) {
return AABB();
- else {
+ } else {
min.x = (src_min.x > dst_min.x) ? src_min.x : dst_min.x;
max.x = (src_max.x < dst_max.x) ? src_max.x : dst_max.x;
}
- if (src_min.y > dst_max.y || src_max.y < dst_min.y)
+ if (src_min.y > dst_max.y || src_max.y < dst_min.y) {
return AABB();
- else {
+ } else {
min.y = (src_min.y > dst_min.y) ? src_min.y : dst_min.y;
max.y = (src_max.y < dst_max.y) ? src_max.y : dst_max.y;
}
- if (src_min.z > dst_max.z || src_max.z < dst_min.z)
+ if (src_min.z > dst_max.z || src_max.z < dst_min.z) {
return AABB();
- else {
+ } else {
min.z = (src_min.z > dst_min.z) ? src_min.z : dst_min.z;
max.z = (src_max.z < dst_max.z) ? src_max.z : dst_max.z;
}
@@ -134,8 +134,9 @@ bool AABB::intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *
}
}
- if (r_clip)
+ if (r_clip) {
*r_clip = c1;
+ }
if (r_normal) {
*r_normal = Vector3();
(*r_normal)[axis] = p_dir[axis] ? -1 : 1;
@@ -158,16 +159,18 @@ bool AABB::intersects_segment(const Vector3 &p_from, const Vector3 &p_to, Vector
real_t csign;
if (seg_from < seg_to) {
- if (seg_from > box_end || seg_to < box_begin)
+ if (seg_from > box_end || seg_to < box_begin) {
return false;
+ }
real_t length = seg_to - seg_from;
cmin = (seg_from < box_begin) ? ((box_begin - seg_from) / length) : 0;
cmax = (seg_to > box_end) ? ((box_end - seg_from) / length) : 1;
csign = -1.0;
} else {
- if (seg_to > box_end || seg_from < box_begin)
+ if (seg_to > box_end || seg_from < box_begin) {
return false;
+ }
real_t length = seg_to - seg_from;
cmin = (seg_from > box_end) ? (box_end - seg_from) / length : 0;
cmax = (seg_to < box_begin) ? (box_begin - seg_from) / length : 1;
@@ -179,10 +182,12 @@ bool AABB::intersects_segment(const Vector3 &p_from, const Vector3 &p_to, Vector
axis = i;
sign = csign;
}
- if (cmax < max)
+ if (cmax < max) {
max = cmax;
- if (max < min)
+ }
+ if (max < min) {
return false;
+ }
}
Vector3 rel = p_to - p_from;
@@ -193,8 +198,9 @@ bool AABB::intersects_segment(const Vector3 &p_from, const Vector3 &p_to, Vector
*r_normal = normal;
}
- if (r_clip)
+ if (r_clip) {
*r_clip = p_from + rel * min;
+ }
return true;
}
@@ -215,10 +221,11 @@ bool AABB::intersects_plane(const Plane &p_plane) const {
bool under = false;
for (int i = 0; i < 8; i++) {
- if (p_plane.distance_to(points[i]) > 0)
+ if (p_plane.distance_to(points[i]) > 0) {
over = true;
- else
+ } else {
under = true;
+ }
}
return under && over;
diff --git a/core/math/aabb.h b/core/math/aabb.h
index a2dd50f4f3..9bbedfe59c 100644
--- a/core/math/aabb.h
+++ b/core/math/aabb.h
@@ -109,35 +109,47 @@ public:
};
inline bool AABB::intersects(const AABB &p_aabb) const {
- if (position.x >= (p_aabb.position.x + p_aabb.size.x))
+ if (position.x >= (p_aabb.position.x + p_aabb.size.x)) {
return false;
- if ((position.x + size.x) <= p_aabb.position.x)
+ }
+ if ((position.x + size.x) <= p_aabb.position.x) {
return false;
- if (position.y >= (p_aabb.position.y + p_aabb.size.y))
+ }
+ if (position.y >= (p_aabb.position.y + p_aabb.size.y)) {
return false;
- if ((position.y + size.y) <= p_aabb.position.y)
+ }
+ if ((position.y + size.y) <= p_aabb.position.y) {
return false;
- if (position.z >= (p_aabb.position.z + p_aabb.size.z))
+ }
+ if (position.z >= (p_aabb.position.z + p_aabb.size.z)) {
return false;
- if ((position.z + size.z) <= p_aabb.position.z)
+ }
+ if ((position.z + size.z) <= p_aabb.position.z) {
return false;
+ }
return true;
}
inline bool AABB::intersects_inclusive(const AABB &p_aabb) const {
- if (position.x > (p_aabb.position.x + p_aabb.size.x))
+ if (position.x > (p_aabb.position.x + p_aabb.size.x)) {
return false;
- if ((position.x + size.x) < p_aabb.position.x)
+ }
+ if ((position.x + size.x) < p_aabb.position.x) {
return false;
- if (position.y > (p_aabb.position.y + p_aabb.size.y))
+ }
+ if (position.y > (p_aabb.position.y + p_aabb.size.y)) {
return false;
- if ((position.y + size.y) < p_aabb.position.y)
+ }
+ if ((position.y + size.y) < p_aabb.position.y) {
return false;
- if (position.z > (p_aabb.position.z + p_aabb.size.z))
+ }
+ if (position.z > (p_aabb.position.z + p_aabb.size.z)) {
return false;
- if ((position.z + size.z) < p_aabb.position.z)
+ }
+ if ((position.z + size.z) < p_aabb.position.z) {
return false;
+ }
return true;
}
@@ -202,8 +214,9 @@ bool AABB::intersects_convex_shape(const Plane *p_planes, int p_plane_count, con
(p.normal.y > 0) ? -half_extents.y : half_extents.y,
(p.normal.z > 0) ? -half_extents.z : half_extents.z);
point += ofs;
- if (p.is_point_over(point))
+ if (p.is_point_over(point)) {
return false;
+ }
}
// Make sure all points in the shape aren't fully separated from the AABB on
@@ -243,26 +256,33 @@ bool AABB::inside_convex_shape(const Plane *p_planes, int p_plane_count) const {
(p.normal.y < 0) ? -half_extents.y : half_extents.y,
(p.normal.z < 0) ? -half_extents.z : half_extents.z);
point += ofs;
- if (p.is_point_over(point))
+ if (p.is_point_over(point)) {
return false;
+ }
}
return true;
}
bool AABB::has_point(const Vector3 &p_point) const {
- if (p_point.x < position.x)
+ if (p_point.x < position.x) {
return false;
- if (p_point.y < position.y)
+ }
+ if (p_point.y < position.y) {
return false;
- if (p_point.z < position.z)
+ }
+ if (p_point.z < position.z) {
return false;
- if (p_point.x > position.x + size.x)
+ }
+ if (p_point.x > position.x + size.x) {
return false;
- if (p_point.y > position.y + size.y)
+ }
+ if (p_point.y > position.y + size.y) {
return false;
- if (p_point.z > position.z + size.z)
+ }
+ if (p_point.z > position.z + size.z) {
return false;
+ }
return true;
}
@@ -271,19 +291,25 @@ inline void AABB::expand_to(const Vector3 &p_vector) {
Vector3 begin = position;
Vector3 end = position + size;
- if (p_vector.x < begin.x)
+ if (p_vector.x < begin.x) {
begin.x = p_vector.x;
- if (p_vector.y < begin.y)
+ }
+ if (p_vector.y < begin.y) {
begin.y = p_vector.y;
- if (p_vector.z < begin.z)
+ }
+ if (p_vector.z < begin.z) {
begin.z = p_vector.z;
+ }
- if (p_vector.x > end.x)
+ if (p_vector.x > end.x) {
end.x = p_vector.x;
- if (p_vector.y > end.y)
+ }
+ if (p_vector.y > end.y) {
end.y = p_vector.y;
- if (p_vector.z > end.z)
+ }
+ if (p_vector.z > end.z) {
end.z = p_vector.z;
+ }
position = begin;
size = end - begin;
@@ -348,12 +374,15 @@ bool AABB::smits_intersect_ray(const Vector3 &p_from, const Vector3 &p_dir, real
tymin = (upbound.y - p_from.y) * divy;
tymax = (position.y - p_from.y) * divy;
}
- if ((tmin > tymax) || (tymin > tmax))
+ if ((tmin > tymax) || (tymin > tmax)) {
return false;
- if (tymin > tmin)
+ }
+ if (tymin > tmin) {
tmin = tymin;
- if (tymax < tmax)
+ }
+ if (tymax < tmax) {
tmax = tymax;
+ }
if (p_dir.z >= 0) {
tzmin = (position.z - p_from.z) * divz;
tzmax = (upbound.z - p_from.z) * divz;
@@ -361,12 +390,15 @@ bool AABB::smits_intersect_ray(const Vector3 &p_from, const Vector3 &p_dir, real
tzmin = (upbound.z - p_from.z) * divz;
tzmax = (position.z - p_from.z) * divz;
}
- if ((tmin > tzmax) || (tzmin > tmax))
+ if ((tmin > tzmax) || (tzmin > tmax)) {
return false;
- if (tzmin > tmin)
+ }
+ if (tzmin > tmin) {
tmin = tzmin;
- if (tzmax < tmax)
+ }
+ if (tzmax < tmax) {
tmax = tzmax;
+ }
return ((tmin < t1) && (tmax > t0));
}
diff --git a/core/math/basis.cpp b/core/math/basis.cpp
index 9981b673ed..cbfd09810c 100644
--- a/core/math/basis.cpp
+++ b/core/math/basis.cpp
@@ -114,12 +114,15 @@ bool Basis::is_rotation() const {
}
bool Basis::is_symmetric() const {
- if (!Math::is_equal_approx_ratio(elements[0][1], elements[1][0], UNIT_EPSILON))
+ if (!Math::is_equal_approx_ratio(elements[0][1], elements[1][0], UNIT_EPSILON)) {
return false;
- if (!Math::is_equal_approx_ratio(elements[0][2], elements[2][0], UNIT_EPSILON))
+ }
+ if (!Math::is_equal_approx_ratio(elements[0][2], elements[2][0], UNIT_EPSILON)) {
return false;
- if (!Math::is_equal_approx_ratio(elements[1][2], elements[2][1], UNIT_EPSILON))
+ }
+ if (!Math::is_equal_approx_ratio(elements[1][2], elements[2][1], UNIT_EPSILON)) {
return false;
+ }
return true;
}
@@ -555,8 +558,9 @@ bool Basis::is_equal_approx(const Basis &p_basis) const {
bool Basis::is_equal_approx_ratio(const Basis &a, const Basis &b, real_t p_epsilon) const {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
- if (!Math::is_equal_approx_ratio(a.elements[i][j], b.elements[i][j], p_epsilon))
+ if (!Math::is_equal_approx_ratio(a.elements[i][j], b.elements[i][j], p_epsilon)) {
return false;
+ }
}
}
@@ -566,8 +570,9 @@ bool Basis::is_equal_approx_ratio(const Basis &a, const Basis &b, real_t p_epsil
bool Basis::operator==(const Basis &p_matrix) const {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
- if (elements[i][j] != p_matrix.elements[i][j])
+ if (elements[i][j] != p_matrix.elements[i][j]) {
return false;
+ }
}
}
@@ -582,8 +587,9 @@ Basis::operator String() const {
String mtx;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
- if (i != 0 || j != 0)
+ if (i != 0 || j != 0) {
mtx += ", ";
+ }
mtx += rtos(elements[i][j]);
}
@@ -661,20 +667,22 @@ int Basis::get_orthogonal_index() const {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
real_t v = orth[i][j];
- if (v > 0.5)
+ if (v > 0.5) {
v = 1.0;
- else if (v < -0.5)
+ } else if (v < -0.5) {
v = -1.0;
- else
+ } else {
v = 0;
+ }
orth[i][j] = v;
}
}
for (int i = 0; i < 24; i++) {
- if (_ortho_bases[i] == orth)
+ if (_ortho_bases[i] == orth) {
return i;
+ }
}
return 0;
@@ -754,8 +762,9 @@ void Basis::get_axis_angle(Vector3 &r_axis, real_t &r_angle) const {
real_t s = Math::sqrt((elements[1][2] - elements[2][1]) * (elements[1][2] - elements[2][1]) + (elements[2][0] - elements[0][2]) * (elements[2][0] - elements[0][2]) + (elements[0][1] - elements[1][0]) * (elements[0][1] - elements[1][0])); // s=|axis||sin(angle)|, used to normalise
angle = Math::acos((elements[0][0] + elements[1][1] + elements[2][2] - 1) / 2);
- if (angle < 0)
+ if (angle < 0) {
s = -s;
+ }
x = (elements[2][1] - elements[1][2]) / s;
y = (elements[0][2] - elements[2][0]) / s;
z = (elements[1][0] - elements[0][1]) / s;
diff --git a/core/math/camera_matrix.cpp b/core/math/camera_matrix.cpp
index c7a3918fe5..81c602d8fe 100644
--- a/core/math/camera_matrix.cpp
+++ b/core/math/camera_matrix.cpp
@@ -469,23 +469,26 @@ void CameraMatrix::invert() {
/** Divide column by minus pivot value **/
for (i = 0; i < 4; i++) {
- if (i != k)
+ if (i != k) {
matrix[i][k] /= (-pvt_val);
+ }
}
/** Reduce the matrix **/
for (i = 0; i < 4; i++) {
hold = matrix[i][k];
for (j = 0; j < 4; j++) {
- if (i != k && j != k)
+ if (i != k && j != k) {
matrix[i][j] += hold * matrix[k][j];
+ }
}
}
/** Divide row by pivot **/
for (j = 0; j < 4; j++) {
- if (j != k)
+ if (j != k) {
matrix[k][j] /= pvt_val;
+ }
}
/** Replace pivot by reciprocal (at last we can touch it). **/
@@ -505,12 +508,13 @@ void CameraMatrix::invert() {
}
j = pvt_i[k]; /* Columns to swap correspond to pivot ROW */
- if (j != k) /* If columns are different */
+ if (j != k) { /* If columns are different */
for (i = 0; i < 4; i++) {
hold = matrix[i][k];
matrix[i][k] = -matrix[i][j];
matrix[i][j] = hold;
}
+ }
}
}
@@ -530,8 +534,9 @@ CameraMatrix CameraMatrix::operator*(const CameraMatrix &p_matrix) const {
for (int j = 0; j < 4; j++) {
for (int i = 0; i < 4; i++) {
real_t ab = 0;
- for (int k = 0; k < 4; k++)
+ for (int k = 0; k < 4; k++) {
ab += matrix[k][i] * p_matrix.matrix[j][k];
+ }
new_matrix.matrix[j][i] = ab;
}
}
@@ -604,9 +609,11 @@ void CameraMatrix::set_light_atlas_rect(const Rect2 &p_rect) {
CameraMatrix::operator String() const {
String str;
- for (int i = 0; i < 4; i++)
- for (int j = 0; j < 4; j++)
+ for (int i = 0; i < 4; i++) {
+ for (int j = 0; j < 4; j++) {
str += String((j > 0) ? ", " : "\n") + rtos(matrix[i][j]);
+ }
+ }
return str;
}
diff --git a/core/math/delaunay_3d.h b/core/math/delaunay_3d.h
index 8fdb52556f..014b4c4621 100644
--- a/core/math/delaunay_3d.h
+++ b/core/math/delaunay_3d.h
@@ -81,12 +81,15 @@ class Delaunay3D {
_FORCE_INLINE_ Triangle() {}
_FORCE_INLINE_ Triangle(uint32_t p_a, uint32_t p_b, uint32_t p_c) {
- if (p_a > p_b)
+ if (p_a > p_b) {
SWAP(p_a, p_b);
- if (p_b > p_c)
+ }
+ if (p_b > p_c) {
SWAP(p_b, p_c);
- if (p_a > p_b)
+ }
+ if (p_a > p_b) {
SWAP(p_a, p_b);
+ }
triangle[0] = p_a;
triangle[1] = p_b;
diff --git a/core/math/disjoint_set.h b/core/math/disjoint_set.h
index 4d93a0035b..198f46e111 100644
--- a/core/math/disjoint_set.h
+++ b/core/math/disjoint_set.h
@@ -109,8 +109,9 @@ void DisjointSet<T, C, AL>::create_union(T a, T b) {
Element *y_root = get_parent(y);
// Already in the same set
- if (x_root == y_root)
+ if (x_root == y_root) {
return;
+ }
// Not in the same set, merge
if (x_root->rank < y_root->rank) {
diff --git a/core/math/expression.cpp b/core/math/expression.cpp
index 7bfebded6a..81c1e7f564 100644
--- a/core/math/expression.cpp
+++ b/core/math/expression.cpp
@@ -111,8 +111,9 @@ const char *Expression::func_name[Expression::FUNC_MAX] = {
Expression::BuiltinFunc Expression::find_function(const String &p_string) {
for (int i = 0; i < FUNC_MAX; i++) {
- if (p_string == func_name[i])
+ if (p_string == func_name[i]) {
return BuiltinFunc(i);
+ }
}
return FUNC_MAX;
@@ -1036,8 +1037,9 @@ Error Expression::_get_token(Token &r_token) {
exp_beg = true;
} else if ((c == '-' || c == '+') && !exp_sign && !exp_beg) {
- if (c == '-')
+ if (c == '-') {
is_float = true;
+ }
exp_sign = true;
} else {
@@ -1046,8 +1048,9 @@ Error Expression::_get_token(Token &r_token) {
} break;
}
- if (reading == READING_DONE)
+ if (reading == READING_DONE) {
break;
+ }
num += String::chr(c);
c = GET_CHAR();
}
@@ -1056,10 +1059,11 @@ Error Expression::_get_token(Token &r_token) {
r_token.type = TK_CONSTANT;
- if (is_float)
+ if (is_float) {
r_token.value = num.to_double();
- else
+ } else {
r_token.value = num.to_int64();
+ }
return OK;
} else if ((cchar >= 'A' && cchar <= 'Z') || (cchar >= 'a' && cchar <= 'z') || cchar == '_') {
@@ -1196,8 +1200,9 @@ Expression::ENode *Expression::_parse_expression() {
Token tk;
_get_token(tk);
- if (error_set)
+ if (error_set) {
return nullptr;
+ }
switch (tk.type) {
case TK_CURLY_BRACKET_OPEN: {
@@ -1213,8 +1218,9 @@ Expression::ENode *Expression::_parse_expression() {
str_ofs = cofs; //revert
//parse an expression
ENode *subexpr = _parse_expression();
- if (!subexpr)
+ if (!subexpr) {
return nullptr;
+ }
dn->dict.push_back(subexpr);
_get_token(tk);
@@ -1224,8 +1230,9 @@ Expression::ENode *Expression::_parse_expression() {
}
subexpr = _parse_expression();
- if (!subexpr)
+ if (!subexpr) {
return nullptr;
+ }
dn->dict.push_back(subexpr);
@@ -1256,8 +1263,9 @@ Expression::ENode *Expression::_parse_expression() {
str_ofs = cofs; //revert
//parse an expression
ENode *subexpr = _parse_expression();
- if (!subexpr)
+ if (!subexpr) {
return nullptr;
+ }
an->array.push_back(subexpr);
cofs = str_ofs;
@@ -1276,8 +1284,9 @@ Expression::ENode *Expression::_parse_expression() {
case TK_PARENTHESIS_OPEN: {
//a suexpression
ENode *e = _parse_expression();
- if (error_set)
+ if (error_set) {
return nullptr;
+ }
_get_token(tk);
if (tk.type != TK_PARENTHESIS_CLOSE) {
_set_error("Expected ')'");
@@ -1308,8 +1317,9 @@ Expression::ENode *Expression::_parse_expression() {
str_ofs = cofs2; //revert
//parse an expression
ENode *subexpr = _parse_expression();
- if (!subexpr)
+ if (!subexpr) {
return nullptr;
+ }
func_call->arguments.push_back(subexpr);
@@ -1386,8 +1396,9 @@ Expression::ENode *Expression::_parse_expression() {
str_ofs = cofs; //revert
//parse an expression
ENode *subexpr = _parse_expression();
- if (!subexpr)
+ if (!subexpr) {
return nullptr;
+ }
constructor->arguments.push_back(subexpr);
@@ -1426,8 +1437,9 @@ Expression::ENode *Expression::_parse_expression() {
str_ofs = cofs; //revert
//parse an expression
ENode *subexpr = _parse_expression();
- if (!subexpr)
+ if (!subexpr) {
return nullptr;
+ }
bifunc->arguments.push_back(subexpr);
@@ -1476,8 +1488,9 @@ Expression::ENode *Expression::_parse_expression() {
while (true) {
int cofs2 = str_ofs;
_get_token(tk);
- if (error_set)
+ if (error_set) {
return nullptr;
+ }
bool done = false;
@@ -1489,8 +1502,9 @@ Expression::ENode *Expression::_parse_expression() {
index->base = expr;
ENode *what = _parse_expression();
- if (!what)
+ if (!what) {
return nullptr;
+ }
index->index = what;
@@ -1529,8 +1543,9 @@ Expression::ENode *Expression::_parse_expression() {
str_ofs = cofs3; //revert
//parse an expression
ENode *subexpr = _parse_expression();
- if (!subexpr)
+ if (!subexpr) {
return nullptr;
+ }
func_call->arguments.push_back(subexpr);
@@ -1563,8 +1578,9 @@ Expression::ENode *Expression::_parse_expression() {
} break;
}
- if (done)
+ if (done) {
break;
+ }
}
//push expression
@@ -1579,8 +1595,9 @@ Expression::ENode *Expression::_parse_expression() {
int cofs = str_ofs;
_get_token(tk);
- if (error_set)
+ if (error_set) {
return nullptr;
+ }
Variant::Operator op = Variant::OP_MAX;
@@ -1843,8 +1860,9 @@ Expression::ENode *Expression::_parse_expression() {
}
bool Expression::_compile_expression() {
- if (!expression_dirty)
+ if (!expression_dirty) {
return error_set;
+ }
if (nodes) {
memdelete(nodes);
@@ -1898,15 +1916,17 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression:
Variant a;
bool ret = _execute(p_inputs, p_instance, op->nodes[0], a, r_error_str);
- if (ret)
+ if (ret) {
return true;
+ }
Variant b;
if (op->nodes[1]) {
ret = _execute(p_inputs, p_instance, op->nodes[1], b, r_error_str);
- if (ret)
+ if (ret) {
return true;
+ }
}
bool valid = true;
@@ -1922,14 +1942,16 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression:
Variant base;
bool ret = _execute(p_inputs, p_instance, index->base, base, r_error_str);
- if (ret)
+ if (ret) {
return true;
+ }
Variant idx;
ret = _execute(p_inputs, p_instance, index->index, idx, r_error_str);
- if (ret)
+ if (ret) {
return true;
+ }
bool valid;
r_ret = base.get(idx, &valid);
@@ -1944,8 +1966,9 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression:
Variant base;
bool ret = _execute(p_inputs, p_instance, index->base, base, r_error_str);
- if (ret)
+ if (ret) {
return true;
+ }
bool valid;
r_ret = base.get_named(index->name, &valid);
@@ -1964,8 +1987,9 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression:
Variant value;
bool ret = _execute(p_inputs, p_instance, array->array[i], value, r_error_str);
- if (ret)
+ if (ret) {
return true;
+ }
arr[i] = value;
}
@@ -1980,13 +2004,15 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression:
Variant key;
bool ret = _execute(p_inputs, p_instance, dictionary->dict[i + 0], key, r_error_str);
- if (ret)
+ if (ret) {
return true;
+ }
Variant value;
ret = _execute(p_inputs, p_instance, dictionary->dict[i + 1], value, r_error_str);
- if (ret)
+ if (ret) {
return true;
+ }
d[key] = value;
}
@@ -2005,8 +2031,9 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression:
Variant value;
bool ret = _execute(p_inputs, p_instance, constructor->arguments[i], value, r_error_str);
- if (ret)
+ if (ret) {
return true;
+ }
arr.write[i] = value;
argp.write[i] = &arr[i];
}
@@ -2031,8 +2058,9 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression:
for (int i = 0; i < bifunc->arguments.size(); i++) {
Variant value;
bool ret = _execute(p_inputs, p_instance, bifunc->arguments[i], value, r_error_str);
- if (ret)
+ if (ret) {
return true;
+ }
arr.write[i] = value;
argp.write[i] = &arr[i];
}
@@ -2052,8 +2080,9 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression:
Variant base;
bool ret = _execute(p_inputs, p_instance, call->base, base, r_error_str);
- if (ret)
+ if (ret) {
return true;
+ }
Vector<Variant> arr;
Vector<const Variant *> argp;
@@ -2064,8 +2093,9 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression:
Variant value;
ret = _execute(p_inputs, p_instance, call->arguments[i], value, r_error_str);
- if (ret)
+ if (ret) {
return true;
+ }
arr.write[i] = value;
argp.write[i] = &arr[i];
}
diff --git a/core/math/expression.h b/core/math/expression.h
index 2d67caca44..59a9a2f4ed 100644
--- a/core/math/expression.h
+++ b/core/math/expression.h
@@ -184,8 +184,9 @@ private:
};
void _set_error(const String &p_err) {
- if (error_set)
+ if (error_set) {
return;
+ }
error_str = p_err;
error_set = true;
}
diff --git a/core/math/face3.cpp b/core/math/face3.cpp
index e1be4f0acf..6d76e116be 100644
--- a/core/math/face3.cpp
+++ b/core/math/face3.cpp
@@ -64,8 +64,9 @@ int Face3::split_by_plane(const Plane &p_plane, Face3 p_res[3], bool p_is_point_
/* Check for Intersection between this and the next vertex*/
Vector3 inters;
- if (!p_plane.intersects_segment(vertex[i], vertex[(i + 1) % 3], &inters))
+ if (!p_plane.intersects_segment(vertex[i], vertex[(i + 1) % 3], &inters)) {
continue;
+ }
/* Intersection goes to both */
ERR_FAIL_COND_V(above_count >= 4, 0);
@@ -127,23 +128,26 @@ Face3::Side Face3::get_side_of(const Face3 &p_face, ClockDirection p_clock_dir)
for (int i = 0; i < 3; i++) {
const Vector3 &v = p_face.vertex[i];
- if (plane.has_point(v)) //coplanar, don't bother
+ if (plane.has_point(v)) { //coplanar, don't bother
continue;
+ }
- if (plane.is_point_over(v))
+ if (plane.is_point_over(v)) {
over++;
- else
+ } else {
under++;
+ }
}
- if (over > 0 && under == 0)
+ if (over > 0 && under == 0) {
return SIDE_OVER;
- else if (under > 0 && over == 0)
+ } else if (under > 0 && over == 0) {
return SIDE_UNDER;
- else if (under == 0 && over == 0)
+ } else if (under == 0 && over == 0) {
return SIDE_COPLANAR;
- else
+ } else {
return SIDE_SPANNING;
+ }
}
Vector3 Face3::get_random_point_inside() const {
@@ -176,8 +180,9 @@ ClockDirection Face3::get_clock_dir() const {
bool Face3::intersects_aabb(const AABB &p_aabb) const {
/** TEST PLANE **/
- if (!p_aabb.intersects_plane(get_plane()))
+ if (!p_aabb.intersects_plane(get_plane())) {
return false;
+ }
#define TEST_AXIS(m_ax) \
/** TEST FACE AXIS */ \
@@ -218,16 +223,18 @@ bool Face3::intersects_aabb(const AABB &p_aabb) const {
Vector3 axis = vec3_cross(e1, e2);
- if (axis.length_squared() < 0.0001)
+ if (axis.length_squared() < 0.0001) {
continue; // coplanar
+ }
axis.normalize();
real_t minA, maxA, minB, maxB;
p_aabb.project_range_in_plane(Plane(axis, 0), minA, maxA);
project_range(axis, Transform(), minB, maxB);
- if (maxA < minB || maxB < minA)
+ if (maxA < minB || maxB < minA) {
return false;
+ }
}
}
return true;
@@ -242,11 +249,13 @@ void Face3::project_range(const Vector3 &p_normal, const Transform &p_transform,
Vector3 v = p_transform.xform(vertex[i]);
real_t d = p_normal.dot(v);
- if (i == 0 || d > r_max)
+ if (i == 0 || d > r_max) {
r_max = d;
+ }
- if (i == 0 || d < r_min)
+ if (i == 0 || d < r_min) {
r_min = d;
+ }
}
}
@@ -254,8 +263,9 @@ void Face3::get_support(const Vector3 &p_normal, const Transform &p_transform, V
#define _FACE_IS_VALID_SUPPORT_THRESHOLD 0.98
#define _EDGE_IS_VALID_SUPPORT_THRESHOLD 0.05
- if (p_max <= 0)
+ if (p_max <= 0) {
return;
+ }
Vector3 n = p_transform.basis.xform_inv(p_normal);
@@ -287,8 +297,9 @@ void Face3::get_support(const Vector3 &p_normal, const Transform &p_transform, V
/** TEST EDGES AS SUPPORT **/
for (int i = 0; i < 3; i++) {
- if (i != vert_support_idx && i + 1 != vert_support_idx)
+ if (i != vert_support_idx && i + 1 != vert_support_idx) {
continue;
+ }
// check if edge is valid as a support
real_t dot = (vertex[i] - vertex[(i + 1) % 3]).normalized().dot(n);
@@ -296,8 +307,9 @@ void Face3::get_support(const Vector3 &p_normal, const Transform &p_transform, V
if (dot < _EDGE_IS_VALID_SUPPORT_THRESHOLD) {
*p_count = MIN(2, p_max);
- for (int j = 0; j < *p_count; j++)
+ for (int j = 0; j < *p_count; j++) {
p_vertices[j] = p_transform.xform(vertex[(j + i) % 3]);
+ }
return;
}
diff --git a/core/math/face3.h b/core/math/face3.h
index eb2b3b8bd5..fb40e8ab9e 100644
--- a/core/math/face3.h
+++ b/core/math/face3.h
@@ -111,8 +111,9 @@ bool Face3::intersects_aabb2(const AABB &p_aabb) const {
real_t dist_a = perp.dot(ofs + sup) - d;
real_t dist_b = perp.dot(ofs - sup) - d;
- if (dist_a * dist_b > 0)
+ if (dist_a * dist_b > 0) {
return false; //does not intersect the plane
+ }
#define TEST_AXIS(m_ax) \
{ \
@@ -209,8 +210,9 @@ bool Face3::intersects_aabb2(const AABB &p_aabb) const {
Vector3 axis = vec3_cross(e1, e2);
- if (axis.length_squared() < 0.0001)
+ if (axis.length_squared() < 0.0001) {
continue; // coplanar
+ }
//axis.normalize();
Vector3 sup2 = Vector3(
@@ -228,15 +230,18 @@ bool Face3::intersects_aabb2(const AABB &p_aabb) const {
for (int k = 0; k < 3; k++) {
real_t vert_d = axis.dot(vertex[k]);
- if (vert_d > maxT)
+ if (vert_d > maxT) {
maxT = vert_d;
+ }
- if (vert_d < minT)
+ if (vert_d < minT) {
minT = vert_d;
+ }
}
- if (maxB < minT || maxT < minB)
+ if (maxB < minT || maxT < minB) {
return false;
+ }
}
}
return true;
diff --git a/core/math/geometry.cpp b/core/math/geometry.cpp
index f1676ec152..f6f22e1db2 100644
--- a/core/math/geometry.cpp
+++ b/core/math/geometry.cpp
@@ -90,8 +90,9 @@ void Geometry::MeshData::optimize_vertices() {
new_vertices.resize(vtx_remap.size());
for (int i = 0; i < vertices.size(); i++) {
- if (vtx_remap.has(i))
+ if (vtx_remap.has(i)) {
new_vertices.write[vtx_remap[i]] = vertices[i];
+ }
}
vertices = new_vertices;
}
@@ -126,11 +127,13 @@ static bool _connect_faces(_FaceClassify *p_faces, int len, int p_group) {
}
for (int i = 0; i < len; i++) {
- if (p_faces[i].group != p_group)
+ if (p_faces[i].group != p_group) {
continue;
+ }
for (int j = i + 1; j < len; j++) {
- if (p_faces[j].group != p_group)
+ if (p_faces[j].group != p_group) {
continue;
+ }
for (int k = 0; k < 3; k++) {
Vector3 vi1 = p_faces[i].face.vertex[k];
@@ -159,29 +162,34 @@ static bool _connect_faces(_FaceClassify *p_faces, int len, int p_group) {
p_faces[j].links[l].edge = k;
}
}
- if (error)
+ if (error) {
break;
+ }
}
- if (error)
+ if (error) {
break;
+ }
}
- if (error)
+ if (error) {
break;
+ }
}
for (int i = 0; i < len; i++) {
p_faces[i].valid = true;
for (int j = 0; j < 3; j++) {
- if (p_faces[i].links[j].face == -1)
+ if (p_faces[i].links[j].face == -1) {
p_faces[i].valid = false;
+ }
}
}
return error;
}
static bool _group_face(_FaceClassify *p_faces, int len, int p_index, int p_group) {
- if (p_faces[p_index].group >= 0)
+ if (p_faces[p_index].group >= 0) {
return false;
+ }
p_faces[p_index].group = p_group;
@@ -218,8 +226,9 @@ Vector<Vector<Face3>> Geometry::separate_objects(Vector<Face3> p_array) {
int group = 0;
for (int i = 0; i < len; i++) {
- if (!_fcptr[i].valid)
+ if (!_fcptr[i].valid) {
continue;
+ }
if (_group_face(_fcptr, len, i, group)) {
group++;
}
@@ -236,8 +245,9 @@ Vector<Vector<Face3>> Geometry::separate_objects(Vector<Face3> p_array) {
Vector<Face3> *group_faces = objects.ptrw();
for (int i = 0; i < len; i++) {
- if (!_fcptr[i].valid)
+ if (!_fcptr[i].valid) {
continue;
+ }
if (_fcptr[i].group >= 0 && _fcptr[i].group < group) {
group_faces[_fcptr[i].group].push_back(_fcptr[i].face);
}
@@ -279,8 +289,9 @@ static inline void _plot_face(uint8_t ***p_cell_status, int x, int y, int z, int
aabb.position = aabb.position * voxelsize;
aabb.size = aabb.size * voxelsize;
- if (!p_face.intersects_aabb(aabb))
+ if (!p_face.intersects_aabb(aabb)) {
return;
+ }
if (len_x == 1 && len_y == 1 && len_z == 1) {
p_cell_status[x][y][z] = _CELL_SOLID;
@@ -326,8 +337,9 @@ static inline void _plot_face(uint8_t ***p_cell_status, int x, int y, int z, int
}
static inline void _mark_outside(uint8_t ***p_cell_status, int x, int y, int z, int len_x, int len_y, int len_z) {
- if (p_cell_status[x][y][z] & 3)
+ if (p_cell_status[x][y][z] & 3) {
return; // Nothing to do, already used and/or visited.
+ }
p_cell_status[x][y][z] = _CELL_PREV_FIRST;
@@ -413,15 +425,19 @@ static inline void _mark_outside(uint8_t ***p_cell_status, int x, int y, int z,
ERR_FAIL();
}
- if (next_x < 0 || next_x >= len_x)
+ if (next_x < 0 || next_x >= len_x) {
continue;
- if (next_y < 0 || next_y >= len_y)
+ }
+ if (next_y < 0 || next_y >= len_y) {
continue;
- if (next_z < 0 || next_z >= len_z)
+ }
+ if (next_z < 0 || next_z >= len_z) {
continue;
+ }
- if (p_cell_status[next_x][next_y][next_z] & 3)
+ if (p_cell_status[next_x][next_y][next_z] & 3) {
continue;
+ }
x = next_x;
y = next_y;
@@ -435,8 +451,9 @@ static inline void _build_faces(uint8_t ***p_cell_status, int x, int y, int z, i
ERR_FAIL_INDEX(y, len_y);
ERR_FAIL_INDEX(z, len_z);
- if (p_cell_status[x][y][z] & _CELL_EXTERIOR)
+ if (p_cell_status[x][y][z] & _CELL_EXTERIOR) {
return;
+ }
#define vert(m_idx) Vector3(((m_idx)&4) >> 2, ((m_idx)&2) >> 1, (m_idx)&1)
@@ -458,21 +475,27 @@ static inline void _build_faces(uint8_t ***p_cell_status, int x, int y, int z, i
bool plot = false;
- if (disp_x < 0 || disp_x >= len_x)
+ if (disp_x < 0 || disp_x >= len_x) {
plot = true;
- if (disp_y < 0 || disp_y >= len_y)
+ }
+ if (disp_y < 0 || disp_y >= len_y) {
plot = true;
- if (disp_z < 0 || disp_z >= len_z)
+ }
+ if (disp_z < 0 || disp_z >= len_z) {
plot = true;
+ }
- if (!plot && (p_cell_status[disp_x][disp_y][disp_z] & _CELL_EXTERIOR))
+ if (!plot && (p_cell_status[disp_x][disp_y][disp_z] & _CELL_EXTERIOR)) {
plot = true;
+ }
- if (!plot)
+ if (!plot) {
continue;
+ }
- for (int j = 0; j < 4; j++)
+ for (int j = 0; j < 4; j++) {
face_points[j] = vert(indices[i][j]) + Vector3(x, y, z);
+ }
p_faces.push_back(
Face3(
@@ -510,20 +533,23 @@ Vector<Face3> Geometry::wrap_geometry(Vector<Face3> p_array, real_t *p_error) {
// Determine amount of cells in grid axis.
int div_x, div_y, div_z;
- if (global_aabb.size.x / _MIN_SIZE < _MAX_LENGTH)
+ if (global_aabb.size.x / _MIN_SIZE < _MAX_LENGTH) {
div_x = (int)(global_aabb.size.x / _MIN_SIZE) + 1;
- else
+ } else {
div_x = _MAX_LENGTH;
+ }
- if (global_aabb.size.y / _MIN_SIZE < _MAX_LENGTH)
+ if (global_aabb.size.y / _MIN_SIZE < _MAX_LENGTH) {
div_y = (int)(global_aabb.size.y / _MIN_SIZE) + 1;
- else
+ } else {
div_y = _MAX_LENGTH;
+ }
- if (global_aabb.size.z / _MIN_SIZE < _MAX_LENGTH)
+ if (global_aabb.size.z / _MIN_SIZE < _MAX_LENGTH) {
div_z = (int)(global_aabb.size.z / _MIN_SIZE) + 1;
- else
+ } else {
div_z = _MAX_LENGTH;
+ }
Vector3 voxelsize = global_aabb.size;
voxelsize.x /= div_x;
@@ -614,8 +640,9 @@ Vector<Face3> Geometry::wrap_geometry(Vector<Face3> p_array, real_t *p_error) {
}
memdelete_arr(cell_status);
- if (p_error)
+ if (p_error) {
*p_error = voxelsize.length();
+ }
return wrapped_faces;
}
@@ -665,8 +692,9 @@ Geometry::MeshData Geometry::build_convex_mesh(const Vector<Plane> &p_planes) {
Vector3 ref = Vector3(0.0, 1.0, 0.0);
- if (ABS(p.normal.dot(ref)) > 0.95)
+ if (ABS(p.normal.dot(ref)) > 0.95) {
ref = Vector3(0.0, 0.0, 1.0); // Change axis.
+ }
Vector3 right = p.normal.cross(ref).normalized();
Vector3 up = p.normal.cross(right).normalized();
@@ -681,17 +709,20 @@ Geometry::MeshData Geometry::build_convex_mesh(const Vector<Plane> &p_planes) {
vertices.push_back(center + up * subplane_size + right * subplane_size);
for (int j = 0; j < p_planes.size(); j++) {
- if (j == i)
+ if (j == i) {
continue;
+ }
Vector<Vector3> new_vertices;
Plane clip = p_planes[j];
- if (clip.normal.dot(p.normal) > 0.95)
+ if (clip.normal.dot(p.normal) > 0.95) {
continue;
+ }
- if (vertices.size() < 3)
+ if (vertices.size() < 3) {
break;
+ }
for (int k = 0; k < vertices.size(); k++) {
int k_n = (k + 1) % vertices.size();
@@ -713,8 +744,9 @@ Geometry::MeshData Geometry::build_convex_mesh(const Vector<Plane> &p_planes) {
Vector3 rel = edge1_A - edge0_A;
real_t den = clip.normal.dot(rel);
- if (Math::is_zero_approx(den))
+ if (Math::is_zero_approx(den)) {
continue; // Point too short.
+ }
real_t dist = -(clip.normal.dot(edge0_A) - clip.d) / den;
Vector3 inters = edge0_A + rel * dist;
@@ -725,8 +757,9 @@ Geometry::MeshData Geometry::build_convex_mesh(const Vector<Plane> &p_planes) {
vertices = new_vertices;
}
- if (vertices.size() < 3)
+ if (vertices.size() < 3) {
continue;
+ }
// Result is a clockwise face.
@@ -770,8 +803,9 @@ Geometry::MeshData Geometry::build_convex_mesh(const Vector<Plane> &p_planes) {
}
}
- if (found)
+ if (found) {
continue;
+ }
MeshData::Edge edge;
edge.a = a;
edge.b = b;
@@ -913,13 +947,15 @@ void Geometry::make_atlas(const Vector<Size2i> &p_rects, Vector<Point2i> &r_resu
int w = 1 << i;
int max_h = 0;
int max_w = 0;
- if (w < widest)
+ if (w < widest) {
continue;
+ }
Vector<int> hmax;
hmax.resize(w);
- for (int j = 0; j < w; j++)
+ for (int j = 0; j < w; j++) {
hmax.write[j] = 0;
+ }
// Place them.
int ofs = 0;
@@ -931,29 +967,34 @@ void Geometry::make_atlas(const Vector<Size2i> &p_rects, Vector<Point2i> &r_resu
int from_y = 0;
for (int k = 0; k < wrects[j].s.width; k++) {
- if (hmax[ofs + k] > from_y)
+ if (hmax[ofs + k] > from_y) {
from_y = hmax[ofs + k];
+ }
}
wrects.write[j].p.x = ofs;
wrects.write[j].p.y = from_y;
int end_h = from_y + wrects[j].s.height;
int end_w = ofs + wrects[j].s.width;
- if (ofs == 0)
+ if (ofs == 0) {
limit_h = end_h;
+ }
for (int k = 0; k < wrects[j].s.width; k++) {
hmax.write[ofs + k] = end_h;
}
- if (end_h > max_h)
+ if (end_h > max_h) {
max_h = end_h;
+ }
- if (end_w > max_w)
+ if (end_w > max_w) {
max_w = end_w;
+ }
- if (ofs == 0 || end_h > limit_h) // While h limit not reached, keep stacking.
+ if (ofs == 0 || end_h > limit_h) { // While h limit not reached, keep stacking.
ofs += wrects[j].s.width;
+ }
}
_AtlasWorkRectResult result;
@@ -1243,8 +1284,9 @@ static void edt(float *f, int stride, int n) {
k = 0;
for (int q = 0; q <= n - 1; q++) {
- while (z[k + 1] < q)
+ while (z[k + 1] < q) {
k++;
+ }
d[q] = square(q - v[k]) + f[v[k] * stride];
}
diff --git a/core/math/geometry.h b/core/math/geometry.h
index b52b081016..a61bf20c4c 100644
--- a/core/math/geometry.h
+++ b/core/math/geometry.h
@@ -78,8 +78,9 @@ public:
// clamp to segment S1. Else pick arbitrary s (here 0).
if (denom != 0.0) {
s = CLAMP((b * f - c * e) / denom, 0.0, 1.0);
- } else
+ } else {
s = 0.0;
+ }
// Compute point on L2 closest to S1(s) using
// t = Dot((P1 + D1*s) - P2,D2) / Dot(D2,D2) = (b*s + f) / e
t = (b * s + f) / e;
@@ -110,14 +111,18 @@ public:
real_t mub = (d_of(p1, q1, q2, q1) + mua * d_of(q2, q1, p2, p1)) / d_of(q2, q1, q2, q1);
// Clip the value between [0..1] constraining the solution to lie on the original curves.
- if (mua < 0)
+ if (mua < 0) {
mua = 0;
- if (mub < 0)
+ }
+ if (mub < 0) {
mub = 0;
- if (mua > 1)
+ }
+ if (mua > 1) {
mua = 1;
- if (mub > 1)
+ }
+ if (mub > 1) {
mub = 1;
+ }
c1 = p1.lerp(p2, mua);
c2 = q1.lerp(q2, mub);
}
@@ -158,22 +163,22 @@ public:
if (tN < 0.0) { // tc < 0 => the t=0 edge is visible.
tN = 0.0;
// Recompute sc for this edge.
- if (-d < 0.0)
+ if (-d < 0.0) {
sN = 0.0;
- else if (-d > a)
+ } else if (-d > a) {
sN = sD;
- else {
+ } else {
sN = -d;
sD = a;
}
} else if (tN > tD) { // tc > 1 => the t=1 edge is visible.
tN = tD;
// Recompute sc for this edge.
- if ((-d + b) < 0.0)
+ if ((-d + b) < 0.0) {
sN = 0;
- else if ((-d + b) > a)
+ } else if ((-d + b) > a) {
sN = sD;
- else {
+ } else {
sN = (-d + b);
sD = a;
}
@@ -193,34 +198,39 @@ public:
Vector3 e2 = p_v2 - p_v0;
Vector3 h = p_dir.cross(e2);
real_t a = e1.dot(h);
- if (Math::is_zero_approx(a)) // Parallel test.
+ if (Math::is_zero_approx(a)) { // Parallel test.
return false;
+ }
real_t f = 1.0 / a;
Vector3 s = p_from - p_v0;
real_t u = f * s.dot(h);
- if (u < 0.0 || u > 1.0)
+ if (u < 0.0 || u > 1.0) {
return false;
+ }
Vector3 q = s.cross(e1);
real_t v = f * p_dir.dot(q);
- if (v < 0.0 || u + v > 1.0)
+ if (v < 0.0 || u + v > 1.0) {
return false;
+ }
// At this stage we can compute t to find out where
// the intersection point is on the line.
real_t t = f * e2.dot(q);
if (t > 0.00001) { // ray intersection
- if (r_res)
+ if (r_res) {
*r_res = p_from + p_dir * t;
+ }
return true;
- } else // This means that there is a line intersection but not a ray intersection.
+ } else { // This means that there is a line intersection but not a ray intersection.
return false;
+ }
}
static inline bool segment_intersects_triangle(const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_v0, const Vector3 &p_v1, const Vector3 &p_v2, Vector3 *r_res = nullptr) {
@@ -229,67 +239,78 @@ public:
Vector3 e2 = p_v2 - p_v0;
Vector3 h = rel.cross(e2);
real_t a = e1.dot(h);
- if (Math::is_zero_approx(a)) // Parallel test.
+ if (Math::is_zero_approx(a)) { // Parallel test.
return false;
+ }
real_t f = 1.0 / a;
Vector3 s = p_from - p_v0;
real_t u = f * s.dot(h);
- if (u < 0.0 || u > 1.0)
+ if (u < 0.0 || u > 1.0) {
return false;
+ }
Vector3 q = s.cross(e1);
real_t v = f * rel.dot(q);
- if (v < 0.0 || u + v > 1.0)
+ if (v < 0.0 || u + v > 1.0) {
return false;
+ }
// At this stage we can compute t to find out where
// the intersection point is on the line.
real_t t = f * e2.dot(q);
if (t > CMP_EPSILON && t <= 1.0) { // Ray intersection.
- if (r_res)
+ if (r_res) {
*r_res = p_from + rel * t;
+ }
return true;
- } else // This means that there is a line intersection but not a ray intersection.
+ } else { // This means that there is a line intersection but not a ray intersection.
return false;
+ }
}
static inline bool segment_intersects_sphere(const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_sphere_pos, real_t p_sphere_radius, Vector3 *r_res = nullptr, Vector3 *r_norm = nullptr) {
Vector3 sphere_pos = p_sphere_pos - p_from;
Vector3 rel = (p_to - p_from);
real_t rel_l = rel.length();
- if (rel_l < CMP_EPSILON)
+ if (rel_l < CMP_EPSILON) {
return false; // Both points are the same.
+ }
Vector3 normal = rel / rel_l;
real_t sphere_d = normal.dot(sphere_pos);
real_t ray_distance = sphere_pos.distance_to(normal * sphere_d);
- if (ray_distance >= p_sphere_radius)
+ if (ray_distance >= p_sphere_radius) {
return false;
+ }
real_t inters_d2 = p_sphere_radius * p_sphere_radius - ray_distance * ray_distance;
real_t inters_d = sphere_d;
- if (inters_d2 >= CMP_EPSILON)
+ if (inters_d2 >= CMP_EPSILON) {
inters_d -= Math::sqrt(inters_d2);
+ }
// Check in segment.
- if (inters_d < 0 || inters_d > rel_l)
+ if (inters_d < 0 || inters_d > rel_l) {
return false;
+ }
Vector3 result = p_from + normal * inters_d;
- if (r_res)
+ if (r_res) {
*r_res = result;
- if (r_norm)
+ }
+ if (r_norm) {
*r_norm = (result - p_sphere_pos).normalized();
+ }
return true;
}
@@ -297,8 +318,9 @@ public:
static inline bool segment_intersects_cylinder(const Vector3 &p_from, const Vector3 &p_to, real_t p_height, real_t p_radius, Vector3 *r_res = nullptr, Vector3 *r_norm = nullptr) {
Vector3 rel = (p_to - p_from);
real_t rel_l = rel.length();
- if (rel_l < CMP_EPSILON)
+ if (rel_l < CMP_EPSILON) {
return false; // Both points are the same.
+ }
// First check if they are parallel.
Vector3 normal = (rel / rel_l);
@@ -315,13 +337,15 @@ public:
real_t dist = z_dir.dot(p_from);
- if (dist >= p_radius)
+ if (dist >= p_radius) {
return false; // Too far away.
+ }
// Convert to 2D.
real_t w2 = p_radius * p_radius - dist * dist;
- if (w2 < CMP_EPSILON)
+ if (w2 < CMP_EPSILON) {
return false; // Avoid numerical error.
+ }
Size2 size(Math::sqrt(w2), p_height * 0.5);
Vector3 x_dir = z_dir.cross(Vector3(0, 0, 1)).normalized();
@@ -341,15 +365,17 @@ public:
real_t cmin, cmax;
if (seg_from < seg_to) {
- if (seg_from > box_end || seg_to < box_begin)
+ if (seg_from > box_end || seg_to < box_begin) {
return false;
+ }
real_t length = seg_to - seg_from;
cmin = (seg_from < box_begin) ? ((box_begin - seg_from) / length) : 0;
cmax = (seg_to > box_end) ? ((box_end - seg_from) / length) : 1;
} else {
- if (seg_to > box_end || seg_from < box_begin)
+ if (seg_to > box_end || seg_from < box_begin) {
return false;
+ }
real_t length = seg_to - seg_from;
cmin = (seg_from > box_end) ? (box_end - seg_from) / length : 0;
cmax = (seg_to < box_begin) ? (box_begin - seg_from) / length : 1;
@@ -359,10 +385,12 @@ public:
min = cmin;
axis = i;
}
- if (cmax < max)
+ if (cmax < max) {
max = cmax;
- if (max < min)
+ }
+ if (max < min) {
return false;
+ }
}
// Convert to 3D again.
@@ -378,10 +406,12 @@ public:
res_normal.normalize();
- if (r_res)
+ if (r_res) {
*r_res = result;
- if (r_norm)
+ }
+ if (r_norm) {
*r_norm = res_normal;
+ }
return true;
}
@@ -392,8 +422,9 @@ public:
Vector3 rel = p_to - p_from;
real_t rel_l = rel.length();
- if (rel_l < CMP_EPSILON)
+ if (rel_l < CMP_EPSILON) {
return false;
+ }
Vector3 dir = rel / rel_l;
@@ -404,15 +435,17 @@ public:
real_t den = p.normal.dot(dir);
- if (Math::abs(den) <= CMP_EPSILON)
+ if (Math::abs(den) <= CMP_EPSILON) {
continue; // Ignore parallel plane.
+ }
real_t dist = -p.distance_to(p_from) / den;
if (den > 0) {
// Backwards facing plane.
- if (dist < max)
+ if (dist < max) {
max = dist;
+ }
} else {
// Front facing plane.
if (dist > min) {
@@ -422,13 +455,16 @@ public:
}
}
- if (max <= min || min < 0 || min > rel_l || min_index == -1) // Exit conditions.
+ if (max <= min || min < 0 || min > rel_l || min_index == -1) { // Exit conditions.
return false; // No intersection.
+ }
- if (p_res)
+ if (p_res) {
*p_res = p_from + dir * min;
- if (p_norm)
+ }
+ if (p_norm) {
*p_norm = p_planes[min_index].normal;
+ }
return true;
}
@@ -437,25 +473,28 @@ public:
Vector3 p = p_point - p_segment[0];
Vector3 n = p_segment[1] - p_segment[0];
real_t l2 = n.length_squared();
- if (l2 < 1e-20)
+ if (l2 < 1e-20) {
return p_segment[0]; // Both points are the same, just give any.
+ }
real_t d = n.dot(p) / l2;
- if (d <= 0.0)
+ if (d <= 0.0) {
return p_segment[0]; // Before first point.
- else if (d >= 1.0)
+ } else if (d >= 1.0) {
return p_segment[1]; // After first point.
- else
+ } else {
return p_segment[0] + n * d; // Inside.
+ }
}
static Vector3 get_closest_point_to_segment_uncapped(const Vector3 &p_point, const Vector3 *p_segment) {
Vector3 p = p_point - p_segment[0];
Vector3 n = p_segment[1] - p_segment[0];
real_t l2 = n.length_squared();
- if (l2 < 1e-20)
+ if (l2 < 1e-20) {
return p_segment[0]; // Both points are the same, just give any.
+ }
real_t d = n.dot(p) / l2;
@@ -466,17 +505,19 @@ public:
Vector2 p = p_point - p_segment[0];
Vector2 n = p_segment[1] - p_segment[0];
real_t l2 = n.length_squared();
- if (l2 < 1e-20)
+ if (l2 < 1e-20) {
return p_segment[0]; // Both points are the same, just give any.
+ }
real_t d = n.dot(p) / l2;
- if (d <= 0.0)
+ if (d <= 0.0) {
return p_segment[0]; // Before first point.
- else if (d >= 1.0)
+ } else if (d >= 1.0) {
return p_segment[1]; // After first point.
- else
+ } else {
return p_segment[0] + n * d; // Inside.
+ }
}
static bool is_point_in_triangle(const Vector2 &s, const Vector2 &a, const Vector2 &b, const Vector2 &c) {
@@ -486,8 +527,9 @@ public:
bool orientation = an.cross(bn) > 0;
- if ((bn.cross(cn) > 0) != orientation)
+ if ((bn.cross(cn) > 0) != orientation) {
return false;
+ }
return (cn.cross(an) > 0) == orientation;
}
@@ -496,8 +538,9 @@ public:
Vector2 p = p_point - p_segment[0];
Vector2 n = p_segment[1] - p_segment[0];
real_t l2 = n.length_squared();
- if (l2 < 1e-20)
+ if (l2 < 1e-20) {
return p_segment[0]; // Both points are the same, just give any.
+ }
real_t d = n.dot(p) / l2;
@@ -524,24 +567,28 @@ public:
Vector2 D = p_to_b - p_from_a;
real_t ABlen = B.dot(B);
- if (ABlen <= 0)
+ if (ABlen <= 0) {
return false;
+ }
Vector2 Bn = B / ABlen;
C = Vector2(C.x * Bn.x + C.y * Bn.y, C.y * Bn.x - C.x * Bn.y);
D = Vector2(D.x * Bn.x + D.y * Bn.y, D.y * Bn.x - D.x * Bn.y);
- if ((C.y < 0 && D.y < 0) || (C.y >= 0 && D.y >= 0))
+ if ((C.y < 0 && D.y < 0) || (C.y >= 0 && D.y >= 0)) {
return false;
+ }
real_t ABpos = D.x + (C.x - D.x) * D.y / (D.y - C.y);
// Fail if segment C-D crosses line A-B outside of segment A-B.
- if (ABpos < 0 || ABpos > 1.0)
+ if (ABpos < 0 || ABpos > 1.0) {
return false;
+ }
// (4) Apply the discovered position to line A-B in the original coordinate system.
- if (r_result)
+ if (r_result) {
*r_result = p_from_a + B * ABpos;
+ }
return true;
}
@@ -551,18 +598,21 @@ public:
Vector3 n1 = (p_point - p_v3).cross(p_point - p_v2);
- if (face_n.dot(n1) < 0)
+ if (face_n.dot(n1) < 0) {
return false;
+ }
Vector3 n2 = (p_v1 - p_v3).cross(p_v1 - p_point);
- if (face_n.dot(n2) < 0)
+ if (face_n.dot(n2) < 0) {
return false;
+ }
Vector3 n3 = (p_v1 - p_point).cross(p_v1 - p_v2);
- if (face_n.dot(n3) < 0)
+ if (face_n.dot(n3) < 0) {
return false;
+ }
return true;
}
@@ -570,8 +620,10 @@ public:
static inline bool triangle_sphere_intersection_test(const Vector3 *p_triangle, const Vector3 &p_normal, const Vector3 &p_sphere_pos, real_t p_sphere_radius, Vector3 &r_triangle_contact, Vector3 &r_sphere_contact) {
real_t d = p_normal.dot(p_sphere_pos) - p_normal.dot(p_triangle[0]);
- if (d > p_sphere_radius || d < -p_sphere_radius) // Not touching the plane of the face, return.
+ if (d > p_sphere_radius || d < -p_sphere_radius) {
+ // Not touching the plane of the face, return.
return false;
+ }
Vector3 contact = p_sphere_pos - (p_normal * d);
@@ -663,8 +715,9 @@ public:
// If the term we intend to square root is less than 0 then the answer won't be real,
// so it definitely won't be t in the range 0 to 1.
- if (sqrtterm < 0)
+ if (sqrtterm < 0) {
return -1;
+ }
// If we can assume that the line segment starts outside the circle (e.g. for continuous time collision detection)
// then the following can be skipped and we can just return the equivalent of res1.
@@ -672,10 +725,12 @@ public:
real_t res1 = (-b - sqrtterm) / (2 * a);
real_t res2 = (-b + sqrtterm) / (2 * a);
- if (res1 >= 0 && res1 <= 1)
+ if (res1 >= 0 && res1 <= 1) {
return res1;
- if (res2 >= 0 && res2 <= 1)
+ }
+ if (res2 >= 0 && res2 <= 1) {
return res2;
+ }
return -1;
}
@@ -686,8 +741,9 @@ public:
LOC_OUTSIDE = -1
};
- if (polygon.size() == 0)
+ if (polygon.size() == 0) {
return polygon;
+ }
int *location_cache = (int *)alloca(sizeof(int) * polygon.size());
int inside_count = 0;
@@ -710,7 +766,6 @@ public:
if (outside_count == 0) {
return polygon; // No changes.
-
} else if (inside_count == 0) {
return Vector<Vector3>(); // Empty.
}
@@ -818,15 +873,17 @@ public:
static Vector<int> triangulate_polygon(const Vector<Vector2> &p_polygon) {
Vector<int> triangles;
- if (!Triangulate::triangulate(p_polygon, triangles))
+ if (!Triangulate::triangulate(p_polygon, triangles)) {
return Vector<int>(); //fail
+ }
return triangles;
}
static bool is_polygon_clockwise(const Vector<Vector2> &p_polygon) {
int c = p_polygon.size();
- if (c < 3)
+ if (c < 3) {
return false;
+ }
const Vector2 *p = p_polygon.ptr();
real_t sum = 0;
for (int i = 0; i < c; i++) {
@@ -841,8 +898,9 @@ public:
// Alternate implementation that should be faster.
static bool is_point_in_polygon(const Vector2 &p_point, const Vector<Vector2> &p_polygon) {
int c = p_polygon.size();
- if (c < 3)
+ if (c < 3) {
return false;
+ }
const Vector2 *p = p_polygon.ptr();
Vector2 further_away(-1e20, -1e20);
Vector2 further_away_opposite(1e20, 1e20);
@@ -914,25 +972,29 @@ public:
return (1 << 23) | (1 << 22) | (1 << 21) | (1 << 20);
} else {
int ret = 0;
- if ((p_idx % 8) == 0)
+ if ((p_idx % 8) == 0) {
ret |= (1 << (p_idx + 7));
- else
+ } else {
ret |= (1 << (p_idx - 1));
- if ((p_idx % 8) == 7)
+ }
+ if ((p_idx % 8) == 7) {
ret |= (1 << (p_idx - 7));
- else
+ } else {
ret |= (1 << (p_idx + 1));
+ }
int mask = ret | (1 << p_idx);
- if (p_idx < 8)
+ if (p_idx < 8) {
ret |= 24;
- else
+ } else {
ret |= mask >> 8;
+ }
- if (p_idx >= 16)
+ if (p_idx >= 16) {
ret |= 25;
- else
+ } else {
ret |= mask << 8;
+ }
return ret;
}
@@ -954,15 +1016,17 @@ public:
// Build lower hull.
for (int i = 0; i < n; ++i) {
- while (k >= 2 && vec2_cross(H[k - 2], H[k - 1], P[i]) <= 0)
+ while (k >= 2 && vec2_cross(H[k - 2], H[k - 1], P[i]) <= 0) {
k--;
+ }
H.write[k++] = P[i];
}
// Build upper hull.
for (int i = n - 2, t = k + 1; i >= 0; i--) {
- while (k >= t && vec2_cross(H[k - 2], H[k - 1], P[i]) <= 0)
+ while (k >= t && vec2_cross(H[k - 2], H[k - 1], P[i]) <= 0) {
k--;
+ }
H.write[k++] = P[i];
}
@@ -983,14 +1047,18 @@ public:
#define FINDMINMAX(x0, x1, x2, min, max) \
min = max = x0; \
- if (x1 < min) \
+ if (x1 < min) { \
min = x1; \
- if (x1 > max) \
+ } \
+ if (x1 > max) { \
max = x1; \
- if (x2 < min) \
+ } \
+ if (x2 < min) { \
min = x2; \
- if (x2 > max) \
- max = x2;
+ } \
+ if (x2 > max) { \
+ max = x2; \
+ }
_FORCE_INLINE_ static bool planeBoxOverlap(Vector3 normal, float d, Vector3 maxbox) {
int q;
@@ -1004,10 +1072,12 @@ public:
vmax[q] = -maxbox[q];
}
}
- if (normal.dot(vmin) + d > 0.0f)
+ if (normal.dot(vmin) + d > 0.0f) {
return false;
- if (normal.dot(vmax) + d >= 0.0f)
+ }
+ if (normal.dot(vmax) + d >= 0.0f) {
return true;
+ }
return false;
}
@@ -1024,8 +1094,9 @@ public:
max = p0; \
} \
rad = fa * boxhalfsize.y + fb * boxhalfsize.z; \
- if (min > rad || max < -rad) \
- return false;
+ if (min > rad || max < -rad) { \
+ return false; \
+ }
#define AXISTEST_X2(a, b, fa, fb) \
p0 = a * v0.y - b * v0.z; \
@@ -1038,8 +1109,9 @@ public:
max = p0; \
} \
rad = fa * boxhalfsize.y + fb * boxhalfsize.z; \
- if (min > rad || max < -rad) \
- return false;
+ if (min > rad || max < -rad) { \
+ return false; \
+ }
/*======================== Y-tests ========================*/
#define AXISTEST_Y02(a, b, fa, fb) \
@@ -1053,8 +1125,9 @@ public:
max = p0; \
} \
rad = fa * boxhalfsize.x + fb * boxhalfsize.z; \
- if (min > rad || max < -rad) \
- return false;
+ if (min > rad || max < -rad) { \
+ return false; \
+ }
#define AXISTEST_Y1(a, b, fa, fb) \
p0 = -a * v0.x + b * v0.z; \
@@ -1067,8 +1140,9 @@ public:
max = p0; \
} \
rad = fa * boxhalfsize.x + fb * boxhalfsize.z; \
- if (min > rad || max < -rad) \
- return false;
+ if (min > rad || max < -rad) { \
+ return false; \
+ }
/*======================== Z-tests ========================*/
@@ -1083,8 +1157,9 @@ public:
max = p2; \
} \
rad = fa * boxhalfsize.x + fb * boxhalfsize.y; \
- if (min > rad || max < -rad) \
- return false;
+ if (min > rad || max < -rad) { \
+ return false; \
+ }
#define AXISTEST_Z0(a, b, fa, fb) \
p0 = a * v0.x - b * v0.y; \
@@ -1097,8 +1172,9 @@ public:
max = p0; \
} \
rad = fa * boxhalfsize.x + fb * boxhalfsize.y; \
- if (min > rad || max < -rad) \
- return false;
+ if (min > rad || max < -rad) { \
+ return false; \
+ }
_FORCE_INLINE_ static bool triangle_box_overlap(const Vector3 &boxcenter, const Vector3 boxhalfsize, const Vector3 *triverts) {
/* use separating axis theorem to test overlap between triangle and box */
@@ -1155,18 +1231,21 @@ public:
/* test in X-direction */
FINDMINMAX(v0.x, v1.x, v2.x, min, max);
- if (min > boxhalfsize.x || max < -boxhalfsize.x)
+ if (min > boxhalfsize.x || max < -boxhalfsize.x) {
return false;
+ }
/* test in Y-direction */
FINDMINMAX(v0.y, v1.y, v2.y, min, max);
- if (min > boxhalfsize.y || max < -boxhalfsize.y)
+ if (min > boxhalfsize.y || max < -boxhalfsize.y) {
return false;
+ }
/* test in Z-direction */
FINDMINMAX(v0.z, v1.z, v2.z, min, max);
- if (min > boxhalfsize.z || max < -boxhalfsize.z)
+ if (min > boxhalfsize.z || max < -boxhalfsize.z) {
return false;
+ }
/* Bullet 2: */
/* test if the box intersects the plane of the triangle */
diff --git a/core/math/math_funcs.cpp b/core/math/math_funcs.cpp
index 0c7a97e5c9..1585c96b38 100644
--- a/core/math/math_funcs.cpp
+++ b/core/math/math_funcs.cpp
@@ -94,16 +94,18 @@ double Math::dectime(double p_value, double p_amount, double p_step) {
double sgn = p_value < 0 ? -1.0 : 1.0;
double val = Math::abs(p_value);
val -= p_amount * p_step;
- if (val < 0.0)
+ if (val < 0.0) {
val = 0.0;
+ }
return val * sgn;
}
double Math::ease(double p_x, double p_c) {
- if (p_x < 0)
+ if (p_x < 0) {
p_x = 0;
- else if (p_x > 1.0)
+ } else if (p_x > 1.0) {
p_x = 1.0;
+ }
if (p_c > 0) {
if (p_c < 1.0) {
return 1.0 - Math::pow(1.0 - p_x, 1.0 / p_c);
@@ -118,8 +120,9 @@ double Math::ease(double p_x, double p_c) {
} else {
return (1.0 - Math::pow(1.0 - (p_x - 0.5) * 2.0, -p_c)) * 0.5 + 0.5;
}
- } else
+ } else {
return 0; // no ease (raw)
+ }
}
double Math::stepify(double p_value, double p_step) {
@@ -166,8 +169,9 @@ uint32_t Math::larger_prime(uint32_t p_val) {
int idx = 0;
while (true) {
ERR_FAIL_COND_V(primes[idx] == 0, 0);
- if (primes[idx] > p_val)
+ if (primes[idx] > p_val) {
return primes[idx];
+ }
idx++;
}
}
diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h
index 33a7d602c3..7a9fd60e23 100644
--- a/core/math/math_funcs.h
+++ b/core/math/math_funcs.h
@@ -232,14 +232,16 @@ public:
static _ALWAYS_INLINE_ float range_lerp(float p_value, float p_istart, float p_istop, float p_ostart, float p_ostop) { return Math::lerp(p_ostart, p_ostop, Math::inverse_lerp(p_istart, p_istop, p_value)); }
static _ALWAYS_INLINE_ double smoothstep(double p_from, double p_to, double p_weight) {
- if (is_equal_approx(p_from, p_to))
+ if (is_equal_approx(p_from, p_to)) {
return p_from;
+ }
double x = CLAMP((p_weight - p_from) / (p_to - p_from), 0.0, 1.0);
return x * x * (3.0 - 2.0 * x);
}
static _ALWAYS_INLINE_ float smoothstep(float p_from, float p_to, float p_weight) {
- if (is_equal_approx(p_from, p_to))
+ if (is_equal_approx(p_from, p_to)) {
return p_from;
+ }
float x = CLAMP((p_weight - p_from) / (p_to - p_from), 0.0f, 1.0f);
return x * x * (3.0f - 2.0f * x);
}
@@ -471,10 +473,11 @@ public:
if (p_step != 0) {
float a = Math::stepify(p_target - p_offset, p_step + p_separation) + p_offset;
float b = a;
- if (p_target >= 0)
+ if (p_target >= 0) {
b -= p_separation;
- else
+ } else {
b += p_step;
+ }
return (Math::abs(p_target - a) < Math::abs(p_target - b)) ? a : b;
}
return p_target;
diff --git a/core/math/octree.h b/core/math/octree.h
index 067103112d..c05fc4e9ed 100644
--- a/core/math/octree.h
+++ b/core/math/octree.h
@@ -190,12 +190,14 @@ private:
}
_FORCE_INLINE_ void _pair_reference(Element *p_A, Element *p_B) {
- if (p_A == p_B || (p_A->userdata == p_B->userdata && p_A->userdata))
+ if (p_A == p_B || (p_A->userdata == p_B->userdata && p_A->userdata)) {
return;
+ }
if (!(p_A->pairable_type & p_B->pairable_mask) &&
- !(p_B->pairable_type & p_A->pairable_mask))
+ !(p_B->pairable_type & p_A->pairable_mask)) {
return; // none can pair with none
+ }
PairKey key(p_A->_id, p_B->_id);
typename PairMap::Element *E = pair_map.find(key);
@@ -220,8 +222,9 @@ private:
}
_FORCE_INLINE_ void _pair_unreference(Element *p_A, Element *p_B) {
- if (p_A == p_B)
+ if (p_A == p_B) {
return;
+ }
PairKey key(p_A->_id, p_B->_id);
typename PairMap::Element *E = pair_map.find(key);
@@ -307,12 +310,14 @@ private:
void _cull_point(Octant *p_octant, const Vector3 &p_point, T **p_result_array, int *p_result_idx, int p_result_max, int *p_subindex_array, uint32_t p_mask);
void _remove_tree(Octant *p_octant) {
- if (!p_octant)
+ if (!p_octant) {
return;
+ }
for (int i = 0; i < 8; i++) {
- if (p_octant->children[i])
+ if (p_octant->children[i]) {
_remove_tree(p_octant->children[i]);
+ }
}
memdelete_allocator<Octant, AL>(p_octant);
@@ -423,12 +428,15 @@ void Octree<T, use_pairs, AL>::_insert_element(Element *p_element, Octant *p_oct
AABB aabb = p_octant->aabb;
aabb.size *= 0.5;
- if (i & 1)
+ if (i & 1) {
aabb.position.x += aabb.size.x;
- if (i & 2)
+ }
+ if (i & 2) {
aabb.position.y += aabb.size.y;
- if (i & 4)
+ }
+ if (i & 4) {
aabb.position.z += aabb.size.z;
+ }
if (aabb.intersects_inclusive(p_element->aabb)) {
/* if actually intersects, create the child */
@@ -535,8 +543,9 @@ bool Octree<T, use_pairs, AL>::_remove_element_from_octant(Element *p_element, O
while (true) {
// check all exit conditions
- if (p_octant == p_limit) // reached limit, nothing to erase, exit
+ if (p_octant == p_limit) { // reached limit, nothing to erase, exit
return octant_removed;
+ }
bool unpaired = false;
@@ -583,8 +592,9 @@ bool Octree<T, use_pairs, AL>::_remove_element_from_octant(Element *p_element, O
octant_removed = true;
}
- if (!removed && !unpaired)
+ if (!removed && !unpaired) {
return octant_removed; // no reason to keep going up anymore! was already visited and was not removed
+ }
p_octant = parent;
}
@@ -618,12 +628,14 @@ void Octree<T, use_pairs, AL>::_unpair_element(Element *p_element, Octant *p_oct
p_octant->last_pass = pass;
- if (p_octant->children_count == 0)
+ if (p_octant->children_count == 0) {
return; // small optimization for leafs
+ }
for (int i = 0; i < 8; i++) {
- if (p_octant->children[i])
+ if (p_octant->children[i]) {
_unpair_element(p_element, p_octant->children[i]);
+ }
}
}
@@ -654,12 +666,14 @@ void Octree<T, use_pairs, AL>::_pair_element(Element *p_element, Octant *p_octan
}
p_octant->last_pass = pass;
- if (p_octant->children_count == 0)
+ if (p_octant->children_count == 0) {
return; // small optimization for leafs
+ }
for (int i = 0; i < 8; i++) {
- if (p_octant->children[i])
+ if (p_octant->children[i]) {
_pair_element(p_element, p_octant->children[i]);
+ }
}
}
@@ -673,8 +687,9 @@ void Octree<T, use_pairs, AL>::_remove_element(Element *p_element) {
for (; I; I = I->next()) {
Octant *o = I->get().octant;
- if (!use_pairs) // small speedup
+ if (!use_pairs) { // small speedup
o->elements.erase(I->get().E);
+ }
_remove_element_from_octant(p_element, o);
}
@@ -690,14 +705,16 @@ void Octree<T, use_pairs, AL>::_remove_element(Element *p_element) {
// erase children pairs, they are erased ONCE even if repeated
pass++;
for (int i = 0; i < 8; i++) {
- if (o->children[i])
+ if (o->children[i]) {
_unpair_element(p_element, o->children[i]);
+ }
}
- if (p_element->pairable)
+ if (p_element->pairable) {
o->pairable_elements.erase(I->get().E);
- else
+ } else {
o->elements.erase(I->get().E);
+ }
}
}
@@ -742,8 +759,9 @@ OctreeElementID Octree<T, use_pairs, AL>::create(T *p_userdata, const AABB &p_aa
if (!e.aabb.has_no_surface()) {
_ensure_valid_root(p_aabb);
_insert_element(&e, root);
- if (use_pairs)
+ if (use_pairs) {
_element_check_pairs(&e);
+ }
}
return last_element_id - 1;
@@ -781,21 +799,24 @@ void Octree<T, use_pairs, AL>::move(OctreeElementID p_id, const AABB &p_aabb) {
e.common_parent = nullptr;
e.aabb = p_aabb;
_insert_element(&e, root);
- if (use_pairs)
+ if (use_pairs) {
_element_check_pairs(&e);
+ }
}
return;
}
- if (!old_has_surf) // doing nothing
+ if (!old_has_surf) { // doing nothing
return;
+ }
// it still is enclosed in the same AABB it was assigned to
if (e.container_aabb.encloses(p_aabb)) {
e.aabb = p_aabb;
- if (use_pairs)
+ if (use_pairs) {
_element_check_pairs(&e); // must check pairs anyway
+ }
return;
}
@@ -815,8 +836,9 @@ void Octree<T, use_pairs, AL>::move(OctreeElementID p_id, const AABB &p_aabb) {
//src is now the place towards where insertion is going to happen
pass++;
- while (common_parent && !common_parent->aabb.encloses(p_aabb))
+ while (common_parent && !common_parent->aabb.encloses(p_aabb)) {
common_parent = common_parent->parent;
+ }
ERR_FAIL_COND(!common_parent);
@@ -838,10 +860,11 @@ void Octree<T, use_pairs, AL>::move(OctreeElementID p_id, const AABB &p_aabb) {
o->elements.erase( F->get().E );
*/
- if (use_pairs && e.pairable)
+ if (use_pairs && e.pairable) {
o->pairable_elements.erase(F->get().E);
- else
+ } else {
o->elements.erase(F->get().E);
+ }
if (_remove_element_from_octant(&e, o, common_parent->parent)) {
owners.erase(F);
@@ -858,8 +881,9 @@ void Octree<T, use_pairs, AL>::move(OctreeElementID p_id, const AABB &p_aabb) {
// erase children pairs, unref ONCE
pass++;
for (int i = 0; i < 8; i++) {
- if (o->children[i])
+ if (o->children[i]) {
_unpair_element(&e, o->children[i]);
+ }
}
}
@@ -876,8 +900,9 @@ void Octree<T, use_pairs, AL>::set_pairable(OctreeElementID p_id, bool p_pairabl
Element &e = E->get();
- if (p_pairable == e.pairable && e.pairable_type == p_pairable_type && e.pairable_mask == p_pairable_mask)
+ if (p_pairable == e.pairable && e.pairable_type == p_pairable_type && e.pairable_mask == p_pairable_mask) {
return; // no changes, return
+ }
if (!e.aabb.has_no_surface()) {
_remove_element(&e);
@@ -891,8 +916,9 @@ void Octree<T, use_pairs, AL>::set_pairable(OctreeElementID p_id, bool p_pairabl
if (!e.aabb.has_no_surface()) {
_ensure_valid_root(e.aabb);
_insert_element(&e, root);
- if (use_pairs)
+ if (use_pairs) {
_element_check_pairs(&e);
+ }
}
}
@@ -913,8 +939,9 @@ void Octree<T, use_pairs, AL>::erase(OctreeElementID p_id) {
template <class T, bool use_pairs, class AL>
void Octree<T, use_pairs, AL>::_cull_convex(Octant *p_octant, _CullConvexData *p_cull) {
- if (*p_cull->result_idx == p_cull->result_max)
+ if (*p_cull->result_idx == p_cull->result_max) {
return; //pointless
+ }
if (!p_octant->elements.empty()) {
typename List<Element *, AL>::Element *I;
@@ -923,8 +950,9 @@ void Octree<T, use_pairs, AL>::_cull_convex(Octant *p_octant, _CullConvexData *p
for (; I; I = I->next()) {
Element *e = I->get();
- if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_cull->mask)))
+ if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_cull->mask))) {
continue;
+ }
e->last_pass = pass;
if (e->aabb.intersects_convex_shape(p_cull->planes, p_cull->plane_count, p_cull->points, p_cull->point_count)) {
@@ -945,8 +973,9 @@ void Octree<T, use_pairs, AL>::_cull_convex(Octant *p_octant, _CullConvexData *p
for (; I; I = I->next()) {
Element *e = I->get();
- if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_cull->mask)))
+ if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_cull->mask))) {
continue;
+ }
e->last_pass = pass;
if (e->aabb.intersects_convex_shape(p_cull->planes, p_cull->plane_count, p_cull->points, p_cull->point_count)) {
@@ -969,8 +998,9 @@ void Octree<T, use_pairs, AL>::_cull_convex(Octant *p_octant, _CullConvexData *p
template <class T, bool use_pairs, class AL>
void Octree<T, use_pairs, AL>::_cull_aabb(Octant *p_octant, const AABB &p_aabb, T **p_result_array, int *p_result_idx, int p_result_max, int *p_subindex_array, uint32_t p_mask) {
- if (*p_result_idx == p_result_max)
+ if (*p_result_idx == p_result_max) {
return; //pointless
+ }
if (!p_octant->elements.empty()) {
typename List<Element *, AL>::Element *I;
@@ -978,15 +1008,17 @@ void Octree<T, use_pairs, AL>::_cull_aabb(Octant *p_octant, const AABB &p_aabb,
for (; I; I = I->next()) {
Element *e = I->get();
- if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_mask)))
+ if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_mask))) {
continue;
+ }
e->last_pass = pass;
if (p_aabb.intersects_inclusive(e->aabb)) {
if (*p_result_idx < p_result_max) {
p_result_array[*p_result_idx] = e->userdata;
- if (p_subindex_array)
+ if (p_subindex_array) {
p_subindex_array[*p_result_idx] = e->subindex;
+ }
(*p_result_idx)++;
} else {
@@ -1002,15 +1034,17 @@ void Octree<T, use_pairs, AL>::_cull_aabb(Octant *p_octant, const AABB &p_aabb,
for (; I; I = I->next()) {
Element *e = I->get();
- if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_mask)))
+ if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_mask))) {
continue;
+ }
e->last_pass = pass;
if (p_aabb.intersects_inclusive(e->aabb)) {
if (*p_result_idx < p_result_max) {
p_result_array[*p_result_idx] = e->userdata;
- if (p_subindex_array)
+ if (p_subindex_array) {
p_subindex_array[*p_result_idx] = e->subindex;
+ }
(*p_result_idx)++;
} else {
return; // pointless to continue
@@ -1028,8 +1062,9 @@ void Octree<T, use_pairs, AL>::_cull_aabb(Octant *p_octant, const AABB &p_aabb,
template <class T, bool use_pairs, class AL>
void Octree<T, use_pairs, AL>::_cull_segment(Octant *p_octant, const Vector3 &p_from, const Vector3 &p_to, T **p_result_array, int *p_result_idx, int p_result_max, int *p_subindex_array, uint32_t p_mask) {
- if (*p_result_idx == p_result_max)
+ if (*p_result_idx == p_result_max) {
return; //pointless
+ }
if (!p_octant->elements.empty()) {
typename List<Element *, AL>::Element *I;
@@ -1037,15 +1072,17 @@ void Octree<T, use_pairs, AL>::_cull_segment(Octant *p_octant, const Vector3 &p_
for (; I; I = I->next()) {
Element *e = I->get();
- if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_mask)))
+ if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_mask))) {
continue;
+ }
e->last_pass = pass;
if (e->aabb.intersects_segment(p_from, p_to)) {
if (*p_result_idx < p_result_max) {
p_result_array[*p_result_idx] = e->userdata;
- if (p_subindex_array)
+ if (p_subindex_array) {
p_subindex_array[*p_result_idx] = e->subindex;
+ }
(*p_result_idx)++;
} else {
@@ -1061,16 +1098,18 @@ void Octree<T, use_pairs, AL>::_cull_segment(Octant *p_octant, const Vector3 &p_
for (; I; I = I->next()) {
Element *e = I->get();
- if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_mask)))
+ if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_mask))) {
continue;
+ }
e->last_pass = pass;
if (e->aabb.intersects_segment(p_from, p_to)) {
if (*p_result_idx < p_result_max) {
p_result_array[*p_result_idx] = e->userdata;
- if (p_subindex_array)
+ if (p_subindex_array) {
p_subindex_array[*p_result_idx] = e->subindex;
+ }
(*p_result_idx)++;
@@ -1090,8 +1129,9 @@ void Octree<T, use_pairs, AL>::_cull_segment(Octant *p_octant, const Vector3 &p_
template <class T, bool use_pairs, class AL>
void Octree<T, use_pairs, AL>::_cull_point(Octant *p_octant, const Vector3 &p_point, T **p_result_array, int *p_result_idx, int p_result_max, int *p_subindex_array, uint32_t p_mask) {
- if (*p_result_idx == p_result_max)
+ if (*p_result_idx == p_result_max) {
return; //pointless
+ }
if (!p_octant->elements.empty()) {
typename List<Element *, AL>::Element *I;
@@ -1099,15 +1139,17 @@ void Octree<T, use_pairs, AL>::_cull_point(Octant *p_octant, const Vector3 &p_po
for (; I; I = I->next()) {
Element *e = I->get();
- if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_mask)))
+ if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_mask))) {
continue;
+ }
e->last_pass = pass;
if (e->aabb.has_point(p_point)) {
if (*p_result_idx < p_result_max) {
p_result_array[*p_result_idx] = e->userdata;
- if (p_subindex_array)
+ if (p_subindex_array) {
p_subindex_array[*p_result_idx] = e->subindex;
+ }
(*p_result_idx)++;
} else {
@@ -1123,16 +1165,18 @@ void Octree<T, use_pairs, AL>::_cull_point(Octant *p_octant, const Vector3 &p_po
for (; I; I = I->next()) {
Element *e = I->get();
- if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_mask)))
+ if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_mask))) {
continue;
+ }
e->last_pass = pass;
if (e->aabb.has_point(p_point)) {
if (*p_result_idx < p_result_max) {
p_result_array[*p_result_idx] = e->userdata;
- if (p_subindex_array)
+ if (p_subindex_array) {
p_subindex_array[*p_result_idx] = e->subindex;
+ }
(*p_result_idx)++;
@@ -1153,12 +1197,14 @@ void Octree<T, use_pairs, AL>::_cull_point(Octant *p_octant, const Vector3 &p_po
template <class T, bool use_pairs, class AL>
int Octree<T, use_pairs, AL>::cull_convex(const Vector<Plane> &p_convex, T **p_result_array, int p_result_max, uint32_t p_mask) {
- if (!root || p_convex.size() == 0)
+ if (!root || p_convex.size() == 0) {
return 0;
+ }
Vector<Vector3> convex_points = Geometry::compute_convex_mesh_points(&p_convex[0], p_convex.size());
- if (convex_points.size() == 0)
+ if (convex_points.size() == 0) {
return 0;
+ }
int result_count = 0;
pass++;
@@ -1179,8 +1225,9 @@ int Octree<T, use_pairs, AL>::cull_convex(const Vector<Plane> &p_convex, T **p_r
template <class T, bool use_pairs, class AL>
int Octree<T, use_pairs, AL>::cull_aabb(const AABB &p_aabb, T **p_result_array, int p_result_max, int *p_subindex_array, uint32_t p_mask) {
- if (!root)
+ if (!root) {
return 0;
+ }
int result_count = 0;
pass++;
@@ -1191,8 +1238,9 @@ int Octree<T, use_pairs, AL>::cull_aabb(const AABB &p_aabb, T **p_result_array,
template <class T, bool use_pairs, class AL>
int Octree<T, use_pairs, AL>::cull_segment(const Vector3 &p_from, const Vector3 &p_to, T **p_result_array, int p_result_max, int *p_subindex_array, uint32_t p_mask) {
- if (!root)
+ if (!root) {
return 0;
+ }
int result_count = 0;
pass++;
@@ -1203,8 +1251,9 @@ int Octree<T, use_pairs, AL>::cull_segment(const Vector3 &p_from, const Vector3
template <class T, bool use_pairs, class AL>
int Octree<T, use_pairs, AL>::cull_point(const Vector3 &p_point, T **p_result_array, int p_result_max, int *p_subindex_array, uint32_t p_mask) {
- if (!root)
+ if (!root) {
return 0;
+ }
int result_count = 0;
pass++;
diff --git a/core/math/plane.cpp b/core/math/plane.cpp
index 94bdd41bd4..df37ceb0e5 100644
--- a/core/math/plane.cpp
+++ b/core/math/plane.cpp
@@ -61,10 +61,11 @@ Vector3 Plane::get_any_perpendicular_normal() const {
static const Vector3 p2 = Vector3(0, 1, 0);
Vector3 p;
- if (ABS(normal.dot(p1)) > 0.99) // if too similar to p1
+ if (ABS(normal.dot(p1)) > 0.99) { // if too similar to p1
p = p2; // use p2
- else
+ } else {
p = p1; // use p1
+ }
p -= normal * normal.dot(p);
p.normalize();
@@ -82,8 +83,9 @@ bool Plane::intersect_3(const Plane &p_plane1, const Plane &p_plane2, Vector3 *r
real_t denom = vec3_cross(normal0, normal1).dot(normal2);
- if (Math::is_zero_approx(denom))
+ if (Math::is_zero_approx(denom)) {
return false;
+ }
if (r_result) {
*r_result = ((vec3_cross(normal1, normal2) * p_plane0.d) +
diff --git a/core/math/plane.h b/core/math/plane.h
index 017835a6da..9a3e5a485f 100644
--- a/core/math/plane.h
+++ b/core/math/plane.h
@@ -109,10 +109,11 @@ Plane::Plane(const Vector3 &p_point, const Vector3 &p_normal) :
}
Plane::Plane(const Vector3 &p_point1, const Vector3 &p_point2, const Vector3 &p_point3, ClockDirection p_dir) {
- if (p_dir == CLOCKWISE)
+ if (p_dir == CLOCKWISE) {
normal = (p_point1 - p_point3).cross(p_point1 - p_point2);
- else
+ } else {
normal = (p_point1 - p_point2).cross(p_point1 - p_point3);
+ }
normal.normalize();
d = normal.dot(p_point1);
diff --git a/core/math/quat.cpp b/core/math/quat.cpp
index f4b708616e..c10f5da494 100644
--- a/core/math/quat.cpp
+++ b/core/math/quat.cpp
@@ -202,8 +202,9 @@ Quat Quat::slerpni(const Quat &q, const real_t &t) const {
real_t dot = from.dot(q);
- if (Math::absf(dot) > 0.9999)
+ if (Math::absf(dot) > 0.9999) {
return from;
+ }
real_t theta = Math::acos(dot),
sinT = 1.0 / Math::sin(theta),
@@ -237,9 +238,9 @@ void Quat::set_axis_angle(const Vector3 &axis, const real_t &angle) {
ERR_FAIL_COND_MSG(!axis.is_normalized(), "The axis Vector3 must be normalized.");
#endif
real_t d = axis.length();
- if (d == 0)
+ if (d == 0) {
set(0, 0, 0, 0);
- else {
+ } else {
real_t sin_angle = Math::sin(angle * 0.5);
real_t cos_angle = Math::cos(angle * 0.5);
real_t s = sin_angle / d;
diff --git a/core/math/quick_hull.cpp b/core/math/quick_hull.cpp
index ace8ac9878..fe16904448 100644
--- a/core/math/quick_hull.cpp
+++ b/core/math/quick_hull.cpp
@@ -75,8 +75,9 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me
real_t max = 0, min = 0;
for (int i = 0; i < p_points.size(); i++) {
- if (!valid_points[i])
+ if (!valid_points[i]) {
continue;
+ }
real_t d = p_points[i][longest_axis];
if (i == 0 || d < min) {
simplex[0] = i;
@@ -97,8 +98,9 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me
Vector3 rel12 = p_points[simplex[0]] - p_points[simplex[1]];
for (int i = 0; i < p_points.size(); i++) {
- if (!valid_points[i])
+ if (!valid_points[i]) {
continue;
+ }
Vector3 n = rel12.cross(p_points[simplex[0]] - p_points[i]).cross(rel12).normalized();
real_t d = Math::abs(n.dot(p_points[simplex[0]]) - n.dot(p_points[i]));
@@ -117,8 +119,9 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me
Plane p(p_points[simplex[0]], p_points[simplex[1]], p_points[simplex[2]]);
for (int i = 0; i < p_points.size(); i++) {
- if (!valid_points[i])
+ if (!valid_points[i]) {
continue;
+ }
real_t d = Math::abs(p.distance_to(p_points[i]));
@@ -173,16 +176,21 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me
/* COMPUTE AVAILABLE VERTICES */
for (int i = 0; i < p_points.size(); i++) {
- if (i == simplex[0])
+ if (i == simplex[0]) {
continue;
- if (i == simplex[1])
+ }
+ if (i == simplex[1]) {
continue;
- if (i == simplex[2])
+ }
+ if (i == simplex[2]) {
continue;
- if (i == simplex[3])
+ }
+ if (i == simplex[3]) {
continue;
- if (!valid_points[i])
+ }
+ if (!valid_points[i]) {
continue;
+ }
for (List<Face>::Element *E = faces.front(); E; E = E->next()) {
if (E->get().plane.distance_to(p_points[i]) > over_tolerance) {
@@ -288,8 +296,9 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me
Face &lf = F->get()->get();
for (int i = 0; i < lf.points_over.size(); i++) {
- if (lf.points_over[i] == f.points_over[next]) //do not add current one
+ if (lf.points_over[i] == f.points_over[next]) { //do not add current one
continue;
+ }
Vector3 p = p_points[lf.points_over[i]];
for (List<List<Face>::Element *>::Element *E = new_faces.front(); E; E = E->next()) {
@@ -397,10 +406,11 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me
Map<Edge, RetFaceConnect>::Element *F2 = ret_edges.find(e2);
ERR_CONTINUE(!F2);
//change faceconnect, point to this face instead
- if (F2->get().left == O)
+ if (F2->get().left == O) {
F2->get().left = E;
- else if (F2->get().right == O)
+ } else if (F2->get().right == O) {
F2->get().right = E;
+ }
}
break;
@@ -409,11 +419,13 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_me
// remove all edge connections to this face
for (Map<Edge, RetFaceConnect>::Element *G = ret_edges.front(); G; G = G->next()) {
- if (G->get().left == O)
+ if (G->get().left == O) {
G->get().left = nullptr;
+ }
- if (G->get().right == O)
+ if (G->get().right == O) {
G->get().right = nullptr;
+ }
}
ret_edges.erase(F); //remove the edge
diff --git a/core/math/random_number_generator.h b/core/math/random_number_generator.h
index 2b125433b3..920308e597 100644
--- a/core/math/random_number_generator.h
+++ b/core/math/random_number_generator.h
@@ -59,10 +59,11 @@ public:
_FORCE_INLINE_ int randi_range(int from, int to) {
unsigned int ret = randbase.rand();
- if (to < from)
+ if (to < from) {
return ret % (from - to + 1) + to;
- else
+ } else {
return ret % (to - from + 1) + from;
+ }
}
RandomNumberGenerator() {}
diff --git a/core/math/rect2.cpp b/core/math/rect2.cpp
index 1e26f815ed..0cc3c4ca0f 100644
--- a/core/math/rect2.cpp
+++ b/core/math/rect2.cpp
@@ -48,16 +48,18 @@ bool Rect2::intersects_segment(const Point2 &p_from, const Point2 &p_to, Point2
real_t csign;
if (seg_from < seg_to) {
- if (seg_from > box_end || seg_to < box_begin)
+ if (seg_from > box_end || seg_to < box_begin) {
return false;
+ }
real_t length = seg_to - seg_from;
cmin = (seg_from < box_begin) ? ((box_begin - seg_from) / length) : 0;
cmax = (seg_to > box_end) ? ((box_end - seg_from) / length) : 1;
csign = -1.0;
} else {
- if (seg_to > box_end || seg_from < box_begin)
+ if (seg_to > box_end || seg_from < box_begin) {
return false;
+ }
real_t length = seg_to - seg_from;
cmin = (seg_from > box_end) ? (box_end - seg_from) / length : 0;
cmax = (seg_to < box_begin) ? (box_begin - seg_from) / length : 1;
@@ -69,10 +71,12 @@ bool Rect2::intersects_segment(const Point2 &p_from, const Point2 &p_to, Point2
axis = i;
sign = csign;
}
- if (cmax < max)
+ if (cmax < max) {
max = cmax;
- if (max < min)
+ }
+ if (max < min) {
return false;
+ }
}
Vector2 rel = p_to - p_from;
@@ -83,8 +87,9 @@ bool Rect2::intersects_segment(const Point2 &p_from, const Point2 &p_to, Point2
*r_normal = normal;
}
- if (r_pos)
+ if (r_pos) {
*r_pos = p_from + rel * min;
+ }
return true;
}
@@ -103,14 +108,18 @@ bool Rect2::intersects_transformed(const Transform2D &p_xform, const Rect2 &p_re
//base rect2 first (faster)
- if (xf_points[0].y > position.y)
+ if (xf_points[0].y > position.y) {
goto next1;
- if (xf_points[1].y > position.y)
+ }
+ if (xf_points[1].y > position.y) {
goto next1;
- if (xf_points[2].y > position.y)
+ }
+ if (xf_points[2].y > position.y) {
goto next1;
- if (xf_points[3].y > position.y)
+ }
+ if (xf_points[3].y > position.y) {
goto next1;
+ }
return false;
@@ -118,27 +127,35 @@ next1:
low_limit = position.y + size.y;
- if (xf_points[0].y < low_limit)
+ if (xf_points[0].y < low_limit) {
goto next2;
- if (xf_points[1].y < low_limit)
+ }
+ if (xf_points[1].y < low_limit) {
goto next2;
- if (xf_points[2].y < low_limit)
+ }
+ if (xf_points[2].y < low_limit) {
goto next2;
- if (xf_points[3].y < low_limit)
+ }
+ if (xf_points[3].y < low_limit) {
goto next2;
+ }
return false;
next2:
- if (xf_points[0].x > position.x)
+ if (xf_points[0].x > position.x) {
goto next3;
- if (xf_points[1].x > position.x)
+ }
+ if (xf_points[1].x > position.x) {
goto next3;
- if (xf_points[2].x > position.x)
+ }
+ if (xf_points[2].x > position.x) {
goto next3;
- if (xf_points[3].x > position.x)
+ }
+ if (xf_points[3].x > position.x) {
goto next3;
+ }
return false;
@@ -146,14 +163,18 @@ next3:
low_limit = position.x + size.x;
- if (xf_points[0].x < low_limit)
+ if (xf_points[0].x < low_limit) {
goto next4;
- if (xf_points[1].x < low_limit)
+ }
+ if (xf_points[1].x < low_limit) {
goto next4;
- if (xf_points[2].x < low_limit)
+ }
+ if (xf_points[2].x < low_limit) {
goto next4;
- if (xf_points[3].x < low_limit)
+ }
+ if (xf_points[3].x < low_limit) {
goto next4;
+ }
return false;
@@ -196,10 +217,12 @@ next4:
maxb = MAX(dp, maxb);
minb = MIN(dp, minb);
- if (mina > maxb)
+ if (mina > maxb) {
return false;
- if (minb > maxa)
+ }
+ if (minb > maxa) {
return false;
+ }
maxa = p_xform.elements[1].dot(xf_points2[0]);
mina = maxa;
@@ -231,10 +254,12 @@ next4:
maxb = MAX(dp, maxb);
minb = MIN(dp, minb);
- if (mina > maxb)
+ if (mina > maxb) {
return false;
- if (minb > maxa)
+ }
+ if (minb > maxa) {
return false;
+ }
return true;
}
diff --git a/core/math/rect2.h b/core/math/rect2.h
index f6274ae32b..1b86dbd49a 100644
--- a/core/math/rect2.h
+++ b/core/math/rect2.h
@@ -48,23 +48,31 @@ struct Rect2 {
inline bool intersects(const Rect2 &p_rect, const bool p_include_borders = false) const {
if (p_include_borders) {
- if (position.x > (p_rect.position.x + p_rect.size.width))
+ if (position.x > (p_rect.position.x + p_rect.size.width)) {
return false;
- if ((position.x + size.width) < p_rect.position.x)
+ }
+ if ((position.x + size.width) < p_rect.position.x) {
return false;
- if (position.y > (p_rect.position.y + p_rect.size.height))
+ }
+ if (position.y > (p_rect.position.y + p_rect.size.height)) {
return false;
- if ((position.y + size.height) < p_rect.position.y)
+ }
+ if ((position.y + size.height) < p_rect.position.y) {
return false;
+ }
} else {
- if (position.x >= (p_rect.position.x + p_rect.size.width))
+ if (position.x >= (p_rect.position.x + p_rect.size.width)) {
return false;
- if ((position.x + size.width) <= p_rect.position.x)
+ }
+ if ((position.x + size.width) <= p_rect.position.x) {
return false;
- if (position.y >= (p_rect.position.y + p_rect.size.height))
+ }
+ if (position.y >= (p_rect.position.y + p_rect.size.height)) {
return false;
- if ((position.y + size.height) <= p_rect.position.y)
+ }
+ if ((position.y + size.height) <= p_rect.position.y) {
return false;
+ }
}
return true;
@@ -95,10 +103,11 @@ struct Rect2 {
inside = false;
}
- if (inside)
+ if (inside) {
return 0;
- else
+ } else {
return dist;
+ }
}
bool intersects_transformed(const Transform2D &p_xform, const Rect2 &p_rect) const;
@@ -118,8 +127,9 @@ struct Rect2 {
Rect2 new_rect = p_rect;
- if (!intersects(new_rect))
+ if (!intersects(new_rect)) {
return Rect2();
+ }
new_rect.position.x = MAX(p_rect.position.x, position.x);
new_rect.position.y = MAX(p_rect.position.y, position.y);
@@ -148,15 +158,19 @@ struct Rect2 {
return new_rect;
};
inline bool has_point(const Point2 &p_point) const {
- if (p_point.x < position.x)
+ if (p_point.x < position.x) {
return false;
- if (p_point.y < position.y)
+ }
+ if (p_point.y < position.y) {
return false;
+ }
- if (p_point.x >= (position.x + size.x))
+ if (p_point.x >= (position.x + size.x)) {
return false;
- if (p_point.y >= (position.y + size.y))
+ }
+ if (p_point.y >= (position.y + size.y)) {
return false;
+ }
return true;
}
@@ -204,15 +218,19 @@ struct Rect2 {
Vector2 begin = position;
Vector2 end = position + size;
- if (p_vector.x < begin.x)
+ if (p_vector.x < begin.x) {
begin.x = p_vector.x;
- if (p_vector.y < begin.y)
+ }
+ if (p_vector.y < begin.y) {
begin.y = p_vector.y;
+ }
- if (p_vector.x > end.x)
+ if (p_vector.x > end.x) {
end.x = p_vector.x;
- if (p_vector.y > end.y)
+ }
+ if (p_vector.y > end.y) {
end.y = p_vector.y;
+ }
position = begin;
size = end - begin;
@@ -247,14 +265,18 @@ struct Rect2i {
int get_area() const { return size.width * size.height; }
inline bool intersects(const Rect2i &p_rect) const {
- if (position.x > (p_rect.position.x + p_rect.size.width))
+ if (position.x > (p_rect.position.x + p_rect.size.width)) {
return false;
- if ((position.x + size.width) < p_rect.position.x)
+ }
+ if ((position.x + size.width) < p_rect.position.x) {
return false;
- if (position.y > (p_rect.position.y + p_rect.size.height))
+ }
+ if (position.y > (p_rect.position.y + p_rect.size.height)) {
return false;
- if ((position.y + size.height) < p_rect.position.y)
+ }
+ if ((position.y + size.height) < p_rect.position.y) {
return false;
+ }
return true;
}
@@ -272,8 +294,9 @@ struct Rect2i {
Rect2i new_rect = p_rect;
- if (!intersects(new_rect))
+ if (!intersects(new_rect)) {
return Rect2i();
+ }
new_rect.position.x = MAX(p_rect.position.x, position.x);
new_rect.position.y = MAX(p_rect.position.y, position.y);
@@ -302,15 +325,19 @@ struct Rect2i {
return new_rect;
};
bool has_point(const Point2 &p_point) const {
- if (p_point.x < position.x)
+ if (p_point.x < position.x) {
return false;
- if (p_point.y < position.y)
+ }
+ if (p_point.y < position.y) {
return false;
+ }
- if (p_point.x >= (position.x + size.x))
+ if (p_point.x >= (position.x + size.x)) {
return false;
- if (p_point.y >= (position.y + size.y))
+ }
+ if (p_point.y >= (position.y + size.y)) {
return false;
+ }
return true;
}
@@ -356,15 +383,19 @@ struct Rect2i {
Point2i begin = position;
Point2i end = position + size;
- if (p_vector.x < begin.x)
+ if (p_vector.x < begin.x) {
begin.x = p_vector.x;
- if (p_vector.y < begin.y)
+ }
+ if (p_vector.y < begin.y) {
begin.y = p_vector.y;
+ }
- if (p_vector.x > end.x)
+ if (p_vector.x > end.x) {
end.x = p_vector.x;
- if (p_vector.y > end.y)
+ }
+ if (p_vector.y > end.y) {
end.y = p_vector.y;
+ }
position = begin;
size = end - begin;
diff --git a/core/math/transform_2d.cpp b/core/math/transform_2d.cpp
index eecfc862f5..dee1b3b23e 100644
--- a/core/math/transform_2d.cpp
+++ b/core/math/transform_2d.cpp
@@ -165,8 +165,9 @@ bool Transform2D::is_equal_approx(const Transform2D &p_transform) const {
bool Transform2D::operator==(const Transform2D &p_transform) const {
for (int i = 0; i < 3; i++) {
- if (elements[i] != p_transform.elements[i])
+ if (elements[i] != p_transform.elements[i]) {
return false;
+ }
}
return true;
@@ -174,8 +175,9 @@ bool Transform2D::operator==(const Transform2D &p_transform) const {
bool Transform2D::operator!=(const Transform2D &p_transform) const {
for (int i = 0; i < 3; i++) {
- if (elements[i] != p_transform.elements[i])
+ if (elements[i] != p_transform.elements[i]) {
return true;
+ }
}
return false;
diff --git a/core/math/triangle_mesh.cpp b/core/math/triangle_mesh.cpp
index 9a608e3f1b..c9a546e385 100644
--- a/core/math/triangle_mesh.cpp
+++ b/core/math/triangle_mesh.cpp
@@ -85,8 +85,9 @@ int TriangleMesh::_create_bvh(BVH *p_bvh, BVH **p_bb, int p_from, int p_size, in
}
void TriangleMesh::get_indices(Vector<int> *r_triangles_indices) const {
- if (!valid)
+ if (!valid) {
return;
+ }
const int triangles_num = triangles.size();
@@ -139,10 +140,11 @@ void TriangleMesh::create(const Vector<Vector3> &p_faces) {
}
f.indices[j] = vidx;
- if (j == 0)
+ if (j == 0) {
bw[i].aabb.position = vs;
- else
+ } else {
bw[i].aabb.expand_to(vs);
+ }
}
f.normal = Face3(r[i * 3 + 0], r[i * 3 + 1], r[i * 3 + 2]).get_plane().get_normal();
@@ -243,18 +245,21 @@ Vector3 TriangleMesh::get_area_normal(const AABB &p_aabb) const {
if (level == 0) {
done = true;
break;
- } else
+ } else {
level--;
+ }
continue;
}
}
- if (done)
+ if (done) {
break;
+ }
}
- if (n_count > 0)
+ if (n_count > 0) {
n /= n_count;
+ }
return n;
}
@@ -340,19 +345,22 @@ bool TriangleMesh::intersect_segment(const Vector3 &p_begin, const Vector3 &p_en
if (level == 0) {
done = true;
break;
- } else
+ } else {
level--;
+ }
continue;
}
}
- if (done)
+ if (done) {
break;
+ }
}
if (inters) {
- if (n.dot(r_normal) > 0)
+ if (n.dot(r_normal) > 0) {
r_normal = -r_normal;
+ }
}
return inters;
@@ -437,19 +445,22 @@ bool TriangleMesh::intersect_ray(const Vector3 &p_begin, const Vector3 &p_dir, V
if (level == 0) {
done = true;
break;
- } else
+ } else {
level--;
+ }
continue;
}
}
- if (done)
+ if (done) {
break;
+ }
}
if (inters) {
- if (n.dot(r_normal) > 0)
+ if (n.dot(r_normal) > 0) {
r_normal = -r_normal;
+ }
}
return inters;
@@ -506,16 +517,18 @@ bool TriangleMesh::intersect_convex_shape(const Plane *p_planes, int p_plane_cou
if (p.intersects_segment(point, next_point, &res)) {
bool inisde = true;
for (int k = 0; k < p_plane_count; k++) {
- if (k == i)
+ if (k == i) {
continue;
+ }
const Plane &pp = p_planes[k];
if (pp.is_point_over(res)) {
inisde = false;
break;
}
}
- if (inisde)
+ if (inisde) {
return true;
+ }
}
if (p.is_point_over(point)) {
@@ -523,8 +536,9 @@ bool TriangleMesh::intersect_convex_shape(const Plane *p_planes, int p_plane_cou
break;
}
}
- if (over)
+ if (over) {
return true;
+ }
}
stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node;
@@ -551,14 +565,16 @@ bool TriangleMesh::intersect_convex_shape(const Plane *p_planes, int p_plane_cou
if (level == 0) {
done = true;
break;
- } else
+ } else {
level--;
+ }
continue;
}
}
- if (done)
+ if (done) {
break;
+ }
}
return false;
@@ -597,8 +613,9 @@ bool TriangleMesh::inside_convex_shape(const Plane *p_planes, int p_plane_count,
switch (stack[level] >> VISITED_BIT_SHIFT) {
case TEST_AABB_BIT: {
bool intersects = scale.xform(b.aabb).intersects_convex_shape(p_planes, p_plane_count, p_points, p_point_count);
- if (!intersects)
+ if (!intersects) {
return false;
+ }
bool inside = scale.xform(b.aabb).inside_convex_shape(p_planes, p_plane_count);
if (inside) {
@@ -611,8 +628,9 @@ bool TriangleMesh::inside_convex_shape(const Plane *p_planes, int p_plane_count,
Vector3 point = scale.xform(vertexptr[s.indices[j]]);
for (int i = 0; i < p_plane_count; i++) {
const Plane &p = p_planes[i];
- if (p.is_point_over(point))
+ if (p.is_point_over(point)) {
return false;
+ }
}
}
@@ -640,14 +658,16 @@ bool TriangleMesh::inside_convex_shape(const Plane *p_planes, int p_plane_count,
if (level == 0) {
done = true;
break;
- } else
+ } else {
level--;
+ }
continue;
}
}
- if (done)
+ if (done) {
break;
+ }
}
return true;
@@ -658,8 +678,9 @@ bool TriangleMesh::is_valid() const {
}
Vector<Face3> TriangleMesh::get_faces() const {
- if (!valid)
+ if (!valid) {
return Vector<Face3>();
+ }
Vector<Face3> faces;
int ts = triangles.size();
diff --git a/core/math/triangulate.cpp b/core/math/triangulate.cpp
index c7b838fd10..7fab36ff50 100644
--- a/core/math/triangulate.cpp
+++ b/core/math/triangulate.cpp
@@ -102,16 +102,19 @@ bool Triangulate::snip(const Vector<Vector2> &p_contour, int u, int v, int w, in
// To avoid that we allow zero-area triangles if all else failed.
float threshold = relaxed ? -CMP_EPSILON : CMP_EPSILON;
- if (threshold > (((Bx - Ax) * (Cy - Ay)) - ((By - Ay) * (Cx - Ax))))
+ if (threshold > (((Bx - Ax) * (Cy - Ay)) - ((By - Ay) * (Cx - Ax)))) {
return false;
+ }
for (p = 0; p < n; p++) {
- if ((p == u) || (p == v) || (p == w))
+ if ((p == u) || (p == v) || (p == w)) {
continue;
+ }
Px = contour[V[p]].x;
Py = contour[V[p]].y;
- if (is_inside_triangle(Ax, Ay, Bx, By, Cx, Cy, Px, Py, relaxed))
+ if (is_inside_triangle(Ax, Ay, Bx, By, Cx, Cy, Px, Py, relaxed)) {
return false;
+ }
}
return true;
@@ -121,20 +124,24 @@ bool Triangulate::triangulate(const Vector<Vector2> &contour, Vector<int> &resul
/* allocate and initialize list of Vertices in polygon */
int n = contour.size();
- if (n < 3)
+ if (n < 3) {
return false;
+ }
Vector<int> V;
V.resize(n);
/* we want a counter-clockwise polygon in V */
- if (0.0 < get_area(contour))
- for (int v = 0; v < n; v++)
+ if (0.0 < get_area(contour)) {
+ for (int v = 0; v < n; v++) {
V.write[v] = v;
- else
- for (int v = 0; v < n; v++)
+ }
+ } else {
+ for (int v = 0; v < n; v++) {
V.write[v] = (n - 1) - v;
+ }
+ }
bool relaxed = false;
@@ -164,14 +171,17 @@ bool Triangulate::triangulate(const Vector<Vector2> &contour, Vector<int> &resul
/* three consecutive vertices in current polygon, <u,v,w> */
int u = v;
- if (nv <= u)
+ if (nv <= u) {
u = 0; /* previous */
+ }
v = u + 1;
- if (nv <= v)
+ if (nv <= v) {
v = 0; /* new v */
+ }
int w = v + 1;
- if (nv <= w)
+ if (nv <= w) {
w = 0; /* next */
+ }
if (snip(contour, u, v, w, nv, V, relaxed)) {
int a, b, c, s, t;
@@ -187,8 +197,9 @@ bool Triangulate::triangulate(const Vector<Vector2> &contour, Vector<int> &resul
result.push_back(c);
/* remove v from remaining polygon */
- for (s = v, t = v + 1; t < nv; s++, t++)
+ for (s = v, t = v + 1; t < nv; s++, t++) {
V.write[s] = V[t];
+ }
nv--;
diff --git a/core/math/vector3.cpp b/core/math/vector3.cpp
index 4a9b251406..568df48c62 100644
--- a/core/math/vector3.cpp
+++ b/core/math/vector3.cpp
@@ -85,10 +85,12 @@ Vector3 Vector3::cubic_interpolaten(const Vector3 &p_b, const Vector3 &p_pre_a,
real_t bc = p1.distance_to(p2);
real_t cd = p2.distance_to(p3);
- if (ab > 0)
+ if (ab > 0) {
p0 = p1 + (p0 - p1) * (bc / ab);
- if (cd > 0)
+ }
+ if (cd > 0) {
p3 = p2 + (p3 - p2) * (bc / cd);
+ }
}
real_t t = p_t;
diff --git a/core/math/vector3.h b/core/math/vector3.h
index 3e35a5bba2..0bc1a467f2 100644
--- a/core/math/vector3.h
+++ b/core/math/vector3.h
@@ -323,10 +323,11 @@ bool Vector3::operator!=(const Vector3 &p_v) const {
bool Vector3::operator<(const Vector3 &p_v) const {
if (Math::is_equal_approx(x, p_v.x)) {
- if (Math::is_equal_approx(y, p_v.y))
+ if (Math::is_equal_approx(y, p_v.y)) {
return z < p_v.z;
- else
+ } else {
return y < p_v.y;
+ }
} else {
return x < p_v.x;
}
@@ -334,10 +335,11 @@ bool Vector3::operator<(const Vector3 &p_v) const {
bool Vector3::operator>(const Vector3 &p_v) const {
if (Math::is_equal_approx(x, p_v.x)) {
- if (Math::is_equal_approx(y, p_v.y))
+ if (Math::is_equal_approx(y, p_v.y)) {
return z > p_v.z;
- else
+ } else {
return y > p_v.y;
+ }
} else {
return x > p_v.x;
}
@@ -345,10 +347,11 @@ bool Vector3::operator>(const Vector3 &p_v) const {
bool Vector3::operator<=(const Vector3 &p_v) const {
if (Math::is_equal_approx(x, p_v.x)) {
- if (Math::is_equal_approx(y, p_v.y))
+ if (Math::is_equal_approx(y, p_v.y)) {
return z <= p_v.z;
- else
+ } else {
return y < p_v.y;
+ }
} else {
return x < p_v.x;
}
@@ -356,10 +359,11 @@ bool Vector3::operator<=(const Vector3 &p_v) const {
bool Vector3::operator>=(const Vector3 &p_v) const {
if (Math::is_equal_approx(x, p_v.x)) {
- if (Math::is_equal_approx(y, p_v.y))
+ if (Math::is_equal_approx(y, p_v.y)) {
return z >= p_v.z;
- else
+ } else {
return y > p_v.y;
+ }
} else {
return x > p_v.x;
}
diff --git a/core/math/vector3i.h b/core/math/vector3i.h
index 524f45b452..08729ad056 100644
--- a/core/math/vector3i.h
+++ b/core/math/vector3i.h
@@ -199,10 +199,11 @@ bool Vector3i::operator!=(const Vector3i &p_v) const {
bool Vector3i::operator<(const Vector3i &p_v) const {
if (x == p_v.x) {
- if (y == p_v.y)
+ if (y == p_v.y) {
return z < p_v.z;
- else
+ } else {
return y < p_v.y;
+ }
} else {
return x < p_v.x;
}
@@ -210,10 +211,11 @@ bool Vector3i::operator<(const Vector3i &p_v) const {
bool Vector3i::operator>(const Vector3i &p_v) const {
if (x == p_v.x) {
- if (y == p_v.y)
+ if (y == p_v.y) {
return z > p_v.z;
- else
+ } else {
return y > p_v.y;
+ }
} else {
return x > p_v.x;
}
@@ -221,10 +223,11 @@ bool Vector3i::operator>(const Vector3i &p_v) const {
bool Vector3i::operator<=(const Vector3i &p_v) const {
if (x == p_v.x) {
- if (y == p_v.y)
+ if (y == p_v.y) {
return z <= p_v.z;
- else
+ } else {
return y < p_v.y;
+ }
} else {
return x < p_v.x;
}
@@ -232,10 +235,11 @@ bool Vector3i::operator<=(const Vector3i &p_v) const {
bool Vector3i::operator>=(const Vector3i &p_v) const {
if (x == p_v.x) {
- if (y == p_v.y)
+ if (y == p_v.y) {
return z >= p_v.z;
- else
+ } else {
return y > p_v.y;
+ }
} else {
return x > p_v.x;
}
diff --git a/core/message_queue.cpp b/core/message_queue.cpp
index 36914de0ba..8c71f760b2 100644
--- a/core/message_queue.cpp
+++ b/core/message_queue.cpp
@@ -50,8 +50,9 @@ Error MessageQueue::push_call(ObjectID p_id, const StringName &p_method, VARIANT
int argc = 0;
for (int i = 0; i < VARIANT_ARG_MAX; i++) {
- if (argptr[i]->get_type() == Variant::NIL)
+ if (argptr[i]->get_type() == Variant::NIL) {
break;
+ }
argc++;
}
@@ -65,8 +66,9 @@ Error MessageQueue::push_set(ObjectID p_id, const StringName &p_prop, const Vari
if ((buffer_end + room_needed) >= buffer_size) {
String type;
- if (ObjectDB::get_instance(p_id))
+ if (ObjectDB::get_instance(p_id)) {
type = ObjectDB::get_instance(p_id)->get_class();
+ }
print_line("Failed set: " + type + ":" + p_prop + " target ID: " + itos(p_id));
statistics();
ERR_FAIL_V_MSG(ERR_OUT_OF_MEMORY, "Message queue out of memory. Try increasing 'memory/limits/message_queue/max_size_kb' in project settings.");
@@ -138,8 +140,9 @@ Error MessageQueue::push_callable(const Callable &p_callable, const Variant **p_
msg->args = p_argcount;
msg->callable = p_callable;
msg->type = TYPE_CALL;
- if (p_show_error)
+ if (p_show_error) {
msg->type |= FLAG_SHOW_ERROR;
+ }
buffer_end += sizeof(Message);
@@ -167,23 +170,26 @@ void MessageQueue::statistics() {
if (target != nullptr) {
switch (message->type & FLAG_MASK) {
case TYPE_CALL: {
- if (!call_count.has(message->callable))
+ if (!call_count.has(message->callable)) {
call_count[message->callable] = 0;
+ }
call_count[message->callable]++;
} break;
case TYPE_NOTIFICATION: {
- if (!notify_count.has(message->notification))
+ if (!notify_count.has(message->notification)) {
notify_count[message->notification] = 0;
+ }
notify_count[message->notification]++;
} break;
case TYPE_SET: {
StringName t = message->callable.get_method();
- if (!set_count.has(t))
+ if (!set_count.has(t)) {
set_count[t] = 0;
+ }
set_count[t]++;
@@ -198,8 +204,9 @@ void MessageQueue::statistics() {
}
read_pos += sizeof(Message);
- if ((message->type & FLAG_MASK) != TYPE_NOTIFICATION)
+ if ((message->type & FLAG_MASK) != TYPE_NOTIFICATION) {
read_pos += sizeof(Variant) * message->args;
+ }
}
print_line("TOTAL BYTES: " + itos(buffer_end));
@@ -261,8 +268,9 @@ void MessageQueue::flush() {
Message *message = (Message *)&buffer[read_pos];
uint32_t advance = sizeof(Message);
- if ((message->type & FLAG_MASK) != TYPE_NOTIFICATION)
+ if ((message->type & FLAG_MASK) != TYPE_NOTIFICATION) {
advance += sizeof(Variant) * message->args;
+ }
//pre-advance so this function is reentrant
read_pos += advance;
@@ -334,14 +342,16 @@ MessageQueue::~MessageQueue() {
Variant *args = (Variant *)(message + 1);
int argc = message->args;
if ((message->type & FLAG_MASK) != TYPE_NOTIFICATION) {
- for (int i = 0; i < argc; i++)
+ for (int i = 0; i < argc; i++) {
args[i].~Variant();
+ }
}
message->~Message();
read_pos += sizeof(Message);
- if ((message->type & FLAG_MASK) != TYPE_NOTIFICATION)
+ if ((message->type & FLAG_MASK) != TYPE_NOTIFICATION) {
read_pos += sizeof(Variant) * message->args;
+ }
}
singleton = nullptr;
diff --git a/core/method_bind.cpp b/core/method_bind.cpp
index a88e6e21b0..3244c63292 100644
--- a/core/method_bind.cpp
+++ b/core/method_bind.cpp
@@ -103,7 +103,8 @@ MethodBind::MethodBind() {
MethodBind::~MethodBind() {
#ifdef DEBUG_METHODS_ENABLED
- if (argument_types)
+ if (argument_types) {
memdelete_arr(argument_types);
+ }
#endif
}
diff --git a/core/method_bind.h b/core/method_bind.h
index 7f3da9c25e..ff2c771f81 100644
--- a/core/method_bind.h
+++ b/core/method_bind.h
@@ -157,8 +157,9 @@ struct VariantObjectClassChecker<Control *> {
#define CHECK_NOARG(m_arg) \
{ \
if (p_arg##m_arg.get_type() != Variant::NIL) { \
- if (r_argerror) \
+ if (r_argerror) { \
*r_argerror = (m_arg - 1); \
+ } \
return CALL_ERROR_EXTRA_ARGUMENT; \
} \
}
@@ -230,19 +231,21 @@ public:
_FORCE_INLINE_ Variant has_default_argument(int p_arg) const {
int idx = argument_count - p_arg - 1;
- if (idx < 0 || idx >= default_arguments.size())
+ if (idx < 0 || idx >= default_arguments.size()) {
return false;
- else
+ } else {
return true;
+ }
}
_FORCE_INLINE_ Variant get_default_argument(int p_arg) const {
int idx = argument_count - p_arg - 1;
- if (idx < 0 || idx >= default_arguments.size())
+ if (idx < 0 || idx >= default_arguments.size()) {
return Variant();
- else
+ } else {
return default_arguments[idx];
+ }
}
#ifdef DEBUG_METHODS_ENABLED
diff --git a/core/node_path.cpp b/core/node_path.cpp
index fd28815704..2a51dca74a 100644
--- a/core/node_path.cpp
+++ b/core/node_path.cpp
@@ -57,15 +57,17 @@ void NodePath::prepend_period() {
}
bool NodePath::is_absolute() const {
- if (!data)
+ if (!data) {
return false;
+ }
return data->absolute;
}
int NodePath::get_name_count() const {
- if (!data)
+ if (!data) {
return 0;
+ }
return data->path.size();
}
@@ -77,8 +79,9 @@ StringName NodePath::get_name(int p_idx) const {
}
int NodePath::get_subname_count() const {
- if (!data)
+ if (!data) {
return 0;
+ }
return data->subpath.size();
}
@@ -97,14 +100,17 @@ void NodePath::unref() {
}
bool NodePath::operator==(const NodePath &p_path) const {
- if (data == p_path.data)
+ if (data == p_path.data) {
return true;
+ }
- if (!data || !p_path.data)
+ if (!data || !p_path.data) {
return false;
+ }
- if (data->absolute != p_path.data->absolute)
+ if (data->absolute != p_path.data->absolute) {
return false;
+ }
int path_size = data->path.size();
@@ -122,16 +128,18 @@ bool NodePath::operator==(const NodePath &p_path) const {
const StringName *r_path_ptr = p_path.data->path.ptr();
for (int i = 0; i < path_size; i++) {
- if (l_path_ptr[i] != r_path_ptr[i])
+ if (l_path_ptr[i] != r_path_ptr[i]) {
return false;
+ }
}
const StringName *l_subpath_ptr = data->subpath.ptr();
const StringName *r_subpath_ptr = p_path.data->subpath.ptr();
for (int i = 0; i < subpath_size; i++) {
- if (l_subpath_ptr[i] != r_subpath_ptr[i])
+ if (l_subpath_ptr[i] != r_subpath_ptr[i]) {
return false;
+ }
}
return true;
@@ -142,8 +150,9 @@ bool NodePath::operator!=(const NodePath &p_path) const {
}
void NodePath::operator=(const NodePath &p_path) {
- if (this == &p_path)
+ if (this == &p_path) {
return;
+ }
unref();
@@ -153,16 +162,19 @@ void NodePath::operator=(const NodePath &p_path) {
}
NodePath::operator String() const {
- if (!data)
+ if (!data) {
return String();
+ }
String ret;
- if (data->absolute)
+ if (data->absolute) {
ret = "/";
+ }
for (int i = 0; i < data->path.size(); i++) {
- if (i > 0)
+ if (i > 0) {
ret += "/";
+ }
ret += data->path[i].operator String();
}
@@ -174,14 +186,16 @@ NodePath::operator String() const {
}
Vector<StringName> NodePath::get_names() const {
- if (data)
+ if (data) {
return data->path;
+ }
return Vector<StringName>();
}
Vector<StringName> NodePath::get_subnames() const {
- if (data)
+ if (data) {
return data->subpath;
+ }
return Vector<StringName>();
}
@@ -211,12 +225,15 @@ NodePath NodePath::rel_path_to(const NodePath &p_np) const {
int common_parent = 0;
while (true) {
- if (src_dirs.size() == common_parent)
+ if (src_dirs.size() == common_parent) {
break;
- if (dst_dirs.size() == common_parent)
+ }
+ if (dst_dirs.size() == common_parent) {
break;
- if (src_dirs[common_parent] != dst_dirs[common_parent])
+ }
+ if (src_dirs[common_parent] != dst_dirs[common_parent]) {
break;
+ }
common_parent++;
}
@@ -232,8 +249,9 @@ NodePath NodePath::rel_path_to(const NodePath &p_np) const {
relpath.push_back(dst_dirs[i]);
}
- if (relpath.size() == 0)
+ if (relpath.size() == 0) {
relpath.push_back(".");
+ }
return NodePath(relpath, p_np.get_subnames(), false);
}
@@ -260,11 +278,13 @@ bool NodePath::is_empty() const {
}
void NodePath::simplify() {
- if (!data)
+ if (!data) {
return;
+ }
for (int i = 0; i < data->path.size(); i++) {
- if (data->path.size() == 1)
+ if (data->path.size() == 1) {
break;
+ }
if (data->path[i].operator String() == ".") {
data->path.remove(i);
i--;
@@ -289,8 +309,9 @@ NodePath NodePath::simplified() const {
}
NodePath::NodePath(const Vector<StringName> &p_path, bool p_absolute) {
- if (p_path.size() == 0)
+ if (p_path.size() == 0) {
return;
+ }
data = memnew(Data);
data->refcount.init();
@@ -301,8 +322,9 @@ NodePath::NodePath(const Vector<StringName> &p_path, bool p_absolute) {
}
NodePath::NodePath(const Vector<StringName> &p_path, const Vector<StringName> &p_subpath, bool p_absolute) {
- if (p_path.size() == 0 && p_subpath.size() == 0)
+ if (p_path.size() == 0 && p_subpath.size() == 0) {
return;
+ }
data = memnew(Data);
data->refcount.init();
@@ -320,8 +342,9 @@ NodePath::NodePath(const NodePath &p_path) {
}
NodePath::NodePath(const String &p_path) {
- if (p_path.length() == 0)
+ if (p_path.length() == 0) {
return;
+ }
String path = p_path;
Vector<StringName> subpath;
@@ -339,8 +362,9 @@ NodePath::NodePath(const String &p_path) {
if (path[i] == ':' || path[i] == 0) {
String str = path.substr(from, i - from);
if (str == "") {
- if (path[i] == 0)
+ if (path[i] == 0) {
continue; // Allow end-of-path :
+ }
ERR_FAIL_MSG("Invalid NodePath '" + p_path + "'.");
}
@@ -358,15 +382,17 @@ NodePath::NodePath(const String &p_path) {
last_is_slash = true;
has_slashes = true;
} else {
- if (last_is_slash)
+ if (last_is_slash) {
slices++;
+ }
last_is_slash = false;
}
}
- if (slices == 0 && !absolute && !subpath.size())
+ if (slices == 0 && !absolute && !subpath.size()) {
return;
+ }
data = memnew(Data);
data->refcount.init();
@@ -375,8 +401,9 @@ NodePath::NodePath(const String &p_path) {
data->subpath = subpath;
data->hash_cache_valid = false;
- if (slices == 0)
+ if (slices == 0) {
return;
+ }
data->path.resize(slices);
last_is_slash = true;
int from = (int)absolute;
diff --git a/core/node_path.h b/core/node_path.h
index 8f89b9fadf..7c06bf01ce 100644
--- a/core/node_path.h
+++ b/core/node_path.h
@@ -69,8 +69,9 @@ public:
NodePath get_parent() const;
_FORCE_INLINE_ uint32_t hash() const {
- if (!data)
+ if (!data) {
return 0;
+ }
if (!data->hash_cache_valid) {
_update_hash_cache();
}
diff --git a/core/object.cpp b/core/object.cpp
index 64b519f1b9..0a4e8a5890 100644
--- a/core/object.cpp
+++ b/core/object.cpp
@@ -75,24 +75,29 @@ PropertyInfo::operator Dictionary() const {
PropertyInfo PropertyInfo::from_dict(const Dictionary &p_dict) {
PropertyInfo pi;
- if (p_dict.has("type"))
+ if (p_dict.has("type")) {
pi.type = Variant::Type(int(p_dict["type"]));
+ }
- if (p_dict.has("name"))
+ if (p_dict.has("name")) {
pi.name = p_dict["name"];
+ }
- if (p_dict.has("class_name"))
+ if (p_dict.has("class_name")) {
pi.class_name = p_dict["class_name"];
+ }
- if (p_dict.has("hint"))
+ if (p_dict.has("hint")) {
pi.hint = PropertyHint(int(p_dict["hint"]));
+ }
- if (p_dict.has("hint_string"))
-
+ if (p_dict.has("hint_string")) {
pi.hint_string = p_dict["hint_string"];
+ }
- if (p_dict.has("usage"))
+ if (p_dict.has("usage")) {
pi.usage = p_dict["usage"];
+ }
return pi;
}
@@ -111,8 +116,9 @@ MethodInfo::operator Dictionary() const {
d["name"] = name;
d["args"] = convert_property_list(&arguments);
Array da;
- for (int i = 0; i < default_arguments.size(); i++)
+ for (int i = 0; i < default_arguments.size(); i++) {
da.push_back(default_arguments[i]);
+ }
d["default_args"] = da;
d["flags"] = flags;
d["id"] = id;
@@ -124,8 +130,9 @@ MethodInfo::operator Dictionary() const {
MethodInfo MethodInfo::from_dict(const Dictionary &p_dict) {
MethodInfo mi;
- if (p_dict.has("name"))
+ if (p_dict.has("name")) {
mi.name = p_dict["name"];
+ }
Array args;
if (p_dict.has("args")) {
args = p_dict["args"];
@@ -147,8 +154,9 @@ MethodInfo MethodInfo::from_dict(const Dictionary &p_dict) {
mi.return_val = PropertyInfo::from_dict(p_dict["return"]);
}
- if (p_dict.has("flags"))
+ if (p_dict.has("flags")) {
mi.flags = p_dict["flags"];
+ }
return mi;
}
@@ -327,14 +335,18 @@ bool Object::Connection::operator<(const Connection &p_conn) const {
Object::Connection::Connection(const Variant &p_variant) {
Dictionary d = p_variant;
- if (d.has("signal"))
+ if (d.has("signal")) {
signal = d["signal"];
- if (d.has("callable"))
+ }
+ if (d.has("callable")) {
callable = d["callable"];
- if (d.has("flags"))
+ }
+ if (d.has("flags")) {
flags = d["flags"];
- if (d.has("binds"))
+ }
+ if (d.has("binds")) {
binds = d["binds"];
+ }
}
bool Object::_predelete() {
@@ -366,8 +378,9 @@ void Object::set(const StringName &p_name, const Variant &p_value, bool *r_valid
if (script_instance) {
if (script_instance->set(p_name, p_value)) {
- if (r_valid)
+ if (r_valid) {
*r_valid = true;
+ }
return;
}
}
@@ -385,23 +398,26 @@ void Object::set(const StringName &p_name, const Variant &p_value, bool *r_valid
if (p_name == CoreStringNames::get_singleton()->_script) {
set_script(p_value);
- if (r_valid)
+ if (r_valid) {
*r_valid = true;
+ }
return;
} else if (p_name == CoreStringNames::get_singleton()->_meta) {
//set_meta(p_name,p_value);
metadata = p_value.duplicate();
- if (r_valid)
+ if (r_valid) {
*r_valid = true;
+ }
return;
}
//something inside the object... :|
bool success = _setv(p_name, p_value);
if (success) {
- if (r_valid)
+ if (r_valid) {
*r_valid = true;
+ }
return;
}
@@ -409,8 +425,9 @@ void Object::set(const StringName &p_name, const Variant &p_value, bool *r_valid
bool valid;
setvar(p_name, p_value, &valid);
if (valid) {
- if (r_valid)
+ if (r_valid) {
*r_valid = true;
+ }
return;
}
}
@@ -420,15 +437,17 @@ void Object::set(const StringName &p_name, const Variant &p_value, bool *r_valid
bool valid;
script_instance->property_set_fallback(p_name, p_value, &valid);
if (valid) {
- if (r_valid)
+ if (r_valid) {
*r_valid = true;
+ }
return;
}
}
#endif
- if (r_valid)
+ if (r_valid) {
*r_valid = false;
+ }
}
Variant Object::get(const StringName &p_name, bool *r_valid) const {
@@ -436,8 +455,9 @@ Variant Object::get(const StringName &p_name, bool *r_valid) const {
if (script_instance) {
if (script_instance->get(p_name, ret)) {
- if (r_valid)
+ if (r_valid) {
*r_valid = true;
+ }
return ret;
}
}
@@ -445,30 +465,34 @@ Variant Object::get(const StringName &p_name, bool *r_valid) const {
//try built-in setgetter
{
if (ClassDB::get_property(const_cast<Object *>(this), p_name, ret)) {
- if (r_valid)
+ if (r_valid) {
*r_valid = true;
+ }
return ret;
}
}
if (p_name == CoreStringNames::get_singleton()->_script) {
ret = get_script();
- if (r_valid)
+ if (r_valid) {
*r_valid = true;
+ }
return ret;
} else if (p_name == CoreStringNames::get_singleton()->_meta) {
ret = metadata;
- if (r_valid)
+ if (r_valid) {
*r_valid = true;
+ }
return ret;
} else {
//something inside the object... :|
bool success = _getv(p_name, ret);
if (success) {
- if (r_valid)
+ if (r_valid) {
*r_valid = true;
+ }
return ret;
}
@@ -477,8 +501,9 @@ Variant Object::get(const StringName &p_name, bool *r_valid) const {
bool valid;
ret = getvar(p_name, &valid);
if (valid) {
- if (r_valid)
+ if (r_valid) {
*r_valid = true;
+ }
return ret;
}
}
@@ -488,23 +513,26 @@ Variant Object::get(const StringName &p_name, bool *r_valid) const {
bool valid;
ret = script_instance->property_get_fallback(p_name, &valid);
if (valid) {
- if (r_valid)
+ if (r_valid) {
*r_valid = true;
+ }
return ret;
}
}
#endif
- if (r_valid)
+ if (r_valid) {
*r_valid = false;
+ }
return Variant();
}
}
void Object::set_indexed(const Vector<StringName> &p_names, const Variant &p_value, bool *r_valid) {
if (p_names.empty()) {
- if (r_valid)
+ if (r_valid) {
*r_valid = false;
+ }
return;
}
if (p_names.size() == 1) {
@@ -513,8 +541,9 @@ void Object::set_indexed(const Vector<StringName> &p_names, const Variant &p_val
}
bool valid = false;
- if (!r_valid)
+ if (!r_valid) {
r_valid = &valid;
+ }
List<Variant> value_stack;
@@ -554,8 +583,9 @@ void Object::set_indexed(const Vector<StringName> &p_names, const Variant &p_val
Variant Object::get_indexed(const Vector<StringName> &p_names, bool *r_valid) const {
if (p_names.empty()) {
- if (r_valid)
+ if (r_valid) {
*r_valid = false;
+ }
return Variant();
}
bool valid = false;
@@ -564,11 +594,13 @@ Variant Object::get_indexed(const Vector<StringName> &p_names, bool *r_valid) co
for (int i = 1; i < p_names.size(); i++) {
current_value = current_value.get_named(p_names[i], &valid);
- if (!valid)
+ if (!valid) {
break;
+ }
}
- if (r_valid)
+ if (r_valid) {
*r_valid = valid;
+ }
return current_value;
}
@@ -741,14 +773,16 @@ bool Object::has_method(const StringName &p_method) const {
}
Variant Object::getvar(const Variant &p_key, bool *r_valid) const {
- if (r_valid)
+ if (r_valid) {
*r_valid = false;
+ }
return Variant();
}
void Object::setvar(const Variant &p_key, const Variant &p_value, bool *r_valid) {
- if (r_valid)
+ if (r_valid) {
*r_valid = false;
+ }
}
Variant Object::callv(const StringName &p_method, const Array &p_args) {
@@ -774,8 +808,9 @@ Variant Object::call(const StringName &p_name, VARIANT_ARG_DECLARE) {
int argc = 0;
for (int i = 0; i < VARIANT_ARG_MAX; i++) {
- if (argptr[i]->get_type() == Variant::NIL)
+ if (argptr[i]->get_type() == Variant::NIL) {
break;
+ }
argc++;
}
@@ -790,8 +825,9 @@ void Object::call_multilevel(const StringName &p_name, VARIANT_ARG_DECLARE) {
int argc = 0;
for (int i = 0; i < VARIANT_ARG_MAX; i++) {
- if (argptr[i]->get_type() == Variant::NIL)
+ if (argptr[i]->get_type() == Variant::NIL) {
break;
+ }
argc++;
}
@@ -871,8 +907,9 @@ String Object::to_string() {
if (script_instance) {
bool valid;
String ret = script_instance->to_string(&valid);
- if (valid)
+ if (valid) {
return ret;
+ }
}
return "[" + get_class() + ":" + itos(get_instance_id()) + "]";
}
@@ -907,8 +944,9 @@ void Object::set_script_and_instance(const Variant &p_script, ScriptInstance *p_
}
void Object::set_script(const Variant &p_script) {
- if (script == p_script)
+ if (script == p_script) {
return;
+ }
if (script_instance) {
memdelete(script_instance);
@@ -933,18 +971,21 @@ void Object::set_script(const Variant &p_script) {
}
void Object::set_script_instance(ScriptInstance *p_instance) {
- if (script_instance == p_instance)
+ if (script_instance == p_instance) {
return;
+ }
- if (script_instance)
+ if (script_instance) {
memdelete(script_instance);
+ }
script_instance = p_instance;
- if (p_instance)
+ if (p_instance) {
script = p_instance->get_script();
- else
+ } else {
script = Variant();
+ }
}
Variant Object::get_script() const {
@@ -1023,8 +1064,9 @@ void Object::add_user_signal(const MethodInfo &p_signal) {
}
bool Object::_has_user_signal(const StringName &p_name) const {
- if (!signal_map.has(p_name))
+ if (!signal_map.has(p_name)) {
return false;
+ }
return signal_map[p_name].user.name.length() > 0;
}
@@ -1061,8 +1103,9 @@ Variant Object::_emit_signal(const Variant **p_args, int p_argcount, Callable::C
}
Error Object::emit_signal(const StringName &p_name, const Variant **p_args, int p_argcount) {
- if (_block_signals)
+ if (_block_signals) {
return ERR_CANT_ACQUIRE_RESOURCE; //no emit, signals blocked
+ }
SignalData *s = signal_map.getptr(p_name);
if (!s) {
@@ -1128,8 +1171,9 @@ Error Object::emit_signal(const StringName &p_name, const Variant **p_args, int
if (ce.error != Callable::CallError::CALL_OK) {
#ifdef DEBUG_ENABLED
- if (c.flags & CONNECT_PERSIST && Engine::get_singleton()->is_editor_hint() && (script.is_null() || !Ref<Script>(script)->is_tool()))
+ if (c.flags & CONNECT_PERSIST && Engine::get_singleton()->is_editor_hint() && (script.is_null() || !Ref<Script>(script)->is_tool())) {
continue;
+ }
#endif
if (ce.error == Callable::CallError::CALL_ERROR_INVALID_METHOD && !ClassDB::class_exists(target->get_class_name())) {
//most likely object is not initialized yet, do not throw error.
@@ -1171,8 +1215,9 @@ Error Object::emit_signal(const StringName &p_name, VARIANT_ARG_DECLARE) {
int argc = 0;
for (int i = 0; i < VARIANT_ARG_MAX; i++) {
- if (argptr[i]->get_type() == Variant::NIL)
+ if (argptr[i]->get_type() == Variant::NIL) {
break;
+ }
argc++;
}
@@ -1191,10 +1236,12 @@ void Object::_add_user_signal(const String &p_name, const Array &p_args) {
Dictionary d = p_args[i];
PropertyInfo param;
- if (d.has("name"))
+ if (d.has("name")) {
param.name = d["name"];
- if (d.has("type"))
+ }
+ if (d.has("type")) {
param.type = (Variant::Type)(int)d["type"];
+ }
mi.arguments.push_back(param);
}
@@ -1293,11 +1340,13 @@ void Object::get_all_signal_connections(List<Connection> *p_connections) const {
void Object::get_signal_connection_list(const StringName &p_signal, List<Connection> *p_connections) const {
const SignalData *s = signal_map.getptr(p_signal);
- if (!s)
+ if (!s) {
return; //nothing
+ }
- for (int i = 0; i < s->slot_map.size(); i++)
+ for (int i = 0; i < s->slot_map.size(); i++) {
p_connections->push_back(s->slot_map.getv(i).conn);
+ }
}
int Object::get_persistent_signal_connection_count() const {
@@ -1395,11 +1444,13 @@ bool Object::is_connected(const StringName &p_signal, const Callable &p_callable
const SignalData *s = signal_map.getptr(p_signal);
if (!s) {
bool signal_is_valid = ClassDB::has_signal(get_class_name(), p_signal);
- if (signal_is_valid)
+ if (signal_is_valid) {
return false;
+ }
- if (!script.is_null() && Ref<Script>(script)->has_script_signal(p_signal))
+ if (!script.is_null() && Ref<Script>(script)->has_script_signal(p_signal)) {
return false;
+ }
ERR_FAIL_V_MSG(false, "Nonexistent signal: " + p_signal + ".");
}
@@ -1466,16 +1517,18 @@ Variant Object::_get_indexed_bind(const NodePath &p_name) const {
void Object::initialize_class() {
static bool initialized = false;
- if (initialized)
+ if (initialized) {
return;
+ }
ClassDB::_add_class<Object>();
_bind_methods();
initialized = true;
}
StringName Object::tr(const StringName &p_message) const {
- if (!_can_translate || !TranslationServer::get_singleton())
+ if (!_can_translate || !TranslationServer::get_singleton()) {
return p_message;
+ }
return TranslationServer::get_singleton()->translate(p_message);
}
@@ -1484,15 +1537,18 @@ void Object::_clear_internal_resource_paths(const Variant &p_var) {
switch (p_var.get_type()) {
case Variant::OBJECT: {
RES r = p_var;
- if (!r.is_valid())
+ if (!r.is_valid()) {
return;
+ }
- if (!r->get_path().begins_with("res://") || r->get_path().find("::") == -1)
+ if (!r->get_path().begins_with("res://") || r->get_path().find("::") == -1) {
return; //not an internal resource
+ }
Object *object = p_var;
- if (!object)
+ if (!object) {
return;
+ }
r->set_path("");
r->clear_internal_resource_paths();
@@ -1522,10 +1578,11 @@ void Object::_clear_internal_resource_paths(const Variant &p_var) {
#ifdef TOOLS_ENABLED
void Object::editor_set_section_unfold(const String &p_section, bool p_unfolded) {
set_edited(true);
- if (p_unfolded)
+ if (p_unfolded) {
editor_section_folding.insert(p_section);
- else
+ } else {
editor_section_folding.erase(p_section);
+ }
}
bool Object::editor_is_section_unfolded(const String &p_section) {
@@ -1669,13 +1726,15 @@ void Object::get_translatable_strings(List<String> *p_strings) const {
get_property_list(&plist);
for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) {
- if (!(E->get().usage & PROPERTY_USAGE_INTERNATIONALIZED))
+ if (!(E->get().usage & PROPERTY_USAGE_INTERNATIONALIZED)) {
continue;
+ }
String text = get(E->get().name);
- if (text == "")
+ if (text == "") {
continue;
+ }
p_strings->push_back(text);
}
@@ -1685,24 +1744,27 @@ Variant::Type Object::get_static_property_type(const StringName &p_property, boo
bool valid;
Variant::Type t = ClassDB::get_property_type(get_class_name(), p_property, &valid);
if (valid) {
- if (r_valid)
+ if (r_valid) {
*r_valid = true;
+ }
return t;
}
if (get_script_instance()) {
return get_script_instance()->get_property_type(p_property, r_valid);
}
- if (r_valid)
+ if (r_valid) {
*r_valid = false;
+ }
return Variant::NIL;
}
Variant::Type Object::get_static_property_type_indexed(const Vector<StringName> &p_path, bool *r_valid) const {
if (p_path.size() == 0) {
- if (r_valid)
+ if (r_valid) {
*r_valid = false;
+ }
return Variant::NIL;
}
@@ -1710,8 +1772,9 @@ Variant::Type Object::get_static_property_type_indexed(const Vector<StringName>
bool valid = false;
Variant::Type t = get_static_property_type(p_path[0], &valid);
if (!valid) {
- if (r_valid)
+ if (r_valid) {
*r_valid = false;
+ }
return Variant::NIL;
}
@@ -1722,22 +1785,25 @@ Variant::Type Object::get_static_property_type_indexed(const Vector<StringName>
for (int i = 1; i < p_path.size(); i++) {
if (check.get_type() == Variant::OBJECT || check.get_type() == Variant::DICTIONARY || check.get_type() == Variant::ARRAY) {
// We cannot be sure about the type of properties this types can have
- if (r_valid)
+ if (r_valid) {
*r_valid = false;
+ }
return Variant::NIL;
}
check = check.get_named(p_path[i], &valid);
if (!valid) {
- if (r_valid)
+ if (r_valid) {
*r_valid = false;
+ }
return Variant::NIL;
}
}
- if (r_valid)
+ if (r_valid) {
*r_valid = true;
+ }
return check.get_type();
}
@@ -1812,8 +1878,9 @@ Object::Object() {
}
Object::~Object() {
- if (script_instance)
+ if (script_instance) {
memdelete(script_instance);
+ }
script_instance = nullptr;
const StringName *S = nullptr;
@@ -1978,10 +2045,12 @@ void ObjectDB::cleanup() {
Object *obj = object_slots[slot].object;
String node_name;
- if (obj->is_class("Node"))
+ if (obj->is_class("Node")) {
node_name = " - Node name: " + String(obj->call("get_name"));
- if (obj->is_class("Resource"))
+ }
+ if (obj->is_class("Resource")) {
node_name = " - Resource name: " + String(obj->call("get_name")) + " Path: " + String(obj->call("get_path"));
+ }
uint64_t id = uint64_t(slot) | (uint64_t(object_slots[slot].validator) << OBJECTDB_VALIDATOR_BITS) | (object_slots[slot].is_reference ? OBJECTDB_REFERENCE_BIT : 0);
print_line("Leaked instance: " + String(obj->get_class()) + ":" + itos(id) + node_name);
diff --git a/core/object.h b/core/object.h
index 84db756323..95662f6208 100644
--- a/core/object.h
+++ b/core/object.h
@@ -260,8 +260,9 @@ public:
return String(#m_class); \
} \
virtual const StringName *_get_class_namev() const { \
- if (!_class_name) \
+ if (!_class_name) { \
_class_name = get_class_static(); \
+ } \
return &_class_name; \
} \
static _FORCE_INLINE_ void *get_class_ptr_static() { \
@@ -281,8 +282,9 @@ public:
static String get_category_static() { \
String category = m_inherits::get_category_static(); \
if (_get_category != m_inherits::_get_category) { \
- if (category != "") \
+ if (category != "") { \
category += "/"; \
+ } \
category += _get_category(); \
} \
return category; \
@@ -309,12 +311,14 @@ protected:
public: \
static void initialize_class() { \
static bool initialized = false; \
- if (initialized) \
+ if (initialized) { \
return; \
+ } \
m_inherits::initialize_class(); \
ClassDB::_add_class<m_class>(); \
- if (m_class::_get_bind_methods() != m_inherits::_get_bind_methods()) \
+ if (m_class::_get_bind_methods() != m_inherits::_get_bind_methods()) { \
_bind_methods(); \
+ } \
initialized = true; \
} \
\
@@ -327,8 +331,9 @@ protected:
} \
virtual bool _getv(const StringName &p_name, Variant &r_ret) const { \
if (m_class::_get_get() != m_inherits::_get_get()) { \
- if (_get(p_name, r_ret)) \
+ if (_get(p_name, r_ret)) { \
return true; \
+ } \
} \
return m_inherits::_getv(p_name, r_ret); \
} \
@@ -336,8 +341,9 @@ protected:
return (bool (Object::*)(const StringName &, const Variant &)) & m_class::_set; \
} \
virtual bool _setv(const StringName &p_name, const Variant &p_property) { \
- if (m_inherits::_setv(p_name, p_property)) \
+ if (m_inherits::_setv(p_name, p_property)) { \
return true; \
+ } \
if (m_class::_get_set() != m_inherits::_get_set()) { \
return _set(p_name, p_property); \
} \
@@ -351,13 +357,15 @@ protected:
m_inherits::_get_property_listv(p_list, p_reversed); \
} \
p_list->push_back(PropertyInfo(Variant::NIL, get_class_static(), PROPERTY_HINT_NONE, String(), PROPERTY_USAGE_CATEGORY)); \
- if (!_is_gpl_reversed()) \
+ if (!_is_gpl_reversed()) { \
ClassDB::get_property_list(#m_class, p_list, true, this); \
+ } \
if (m_class::_get_get_property_list() != m_inherits::_get_get_property_list()) { \
_get_property_list(p_list); \
} \
- if (_is_gpl_reversed()) \
+ if (_is_gpl_reversed()) { \
ClassDB::get_property_list(#m_class, p_list, true, this); \
+ } \
if (p_reversed) { \
m_inherits::_get_property_listv(p_list, p_reversed); \
} \
@@ -366,13 +374,15 @@ protected:
return (void (Object::*)(int)) & m_class::_notification; \
} \
virtual void _notificationv(int p_notification, bool p_reversed) { \
- if (!p_reversed) \
+ if (!p_reversed) { \
m_inherits::_notificationv(p_notification, p_reversed); \
+ } \
if (m_class::_get_notification() != m_inherits::_get_notification()) { \
_notification(p_notification); \
} \
- if (p_reversed) \
+ if (p_reversed) { \
m_inherits::_notificationv(p_notification, p_reversed); \
+ } \
} \
\
private:
@@ -526,8 +536,9 @@ protected:
Variant _call_deferred_bind(const Variant **p_args, int p_argcount, Callable::CallError &r_error);
virtual const StringName *_get_class_namev() const {
- if (!_class_name)
+ if (!_class_name) {
_class_name = get_class_static();
+ }
return &_class_name;
}
@@ -550,8 +561,9 @@ public:
#ifdef TOOLS_ENABLED
_FORCE_INLINE_ void _change_notify(const char *p_property = "") {
_edited = true;
- for (Set<Object *>::Element *E = change_receptors.front(); E; E = E->next())
+ for (Set<Object *>::Element *E = change_receptors.front(); E; E = E->next()) {
((Object *)(E->get()))->_changed_callback(this, p_property);
+ }
}
#else
_FORCE_INLINE_ void _change_notify(const char *p_what = "") {}
@@ -574,12 +586,14 @@ public:
#ifndef NO_SAFE_CAST
return dynamic_cast<T *>(p_object);
#else
- if (!p_object)
+ if (!p_object) {
return nullptr;
- if (p_object->is_class_ptr(T::get_class_ptr_static()))
+ }
+ if (p_object->is_class_ptr(T::get_class_ptr_static())) {
return static_cast<T *>(p_object);
- else
+ } else {
return nullptr;
+ }
#endif
}
@@ -588,12 +602,14 @@ public:
#ifndef NO_SAFE_CAST
return dynamic_cast<const T *>(p_object);
#else
- if (!p_object)
+ if (!p_object) {
return nullptr;
- if (p_object->is_class_ptr(T::get_class_ptr_static()))
+ }
+ if (p_object->is_class_ptr(T::get_class_ptr_static())) {
return static_cast<const T *>(p_object);
- else
+ } else {
return nullptr;
+ }
#endif
}
diff --git a/core/os/dir_access.cpp b/core/os/dir_access.cpp
index 5763c74862..9f2672e038 100644
--- a/core/os/dir_access.cpp
+++ b/core/os/dir_access.cpp
@@ -61,8 +61,9 @@ int DirAccess::get_current_drive() {
String path = get_current_dir().to_lower();
for (int i = 0; i < get_drive_count(); i++) {
String d = get_drive(i).to_lower();
- if (path.begins_with(d))
+ if (path.begins_with(d)) {
return i;
+ }
}
return 0;
@@ -80,10 +81,11 @@ static Error _erase_recursive(DirAccess *da) {
String n = da->get_next();
while (n != String()) {
if (n != "." && n != "..") {
- if (da->current_is_dir())
+ if (da->current_is_dir()) {
dirs.push_back(n);
- else
+ } else {
files.push_back(n);
+ }
}
n = da->get_next();
@@ -147,13 +149,13 @@ Error DirAccess::make_dir_recursive(String p_dir) {
String base;
- if (full_dir.begins_with("res://"))
+ if (full_dir.begins_with("res://")) {
base = "res://";
- else if (full_dir.begins_with("user://"))
+ } else if (full_dir.begins_with("user://")) {
base = "user://";
- else if (full_dir.begins_with("/"))
+ } else if (full_dir.begins_with("/")) {
base = "/";
- else if (full_dir.find(":/") != -1) {
+ } else if (full_dir.find(":/") != -1) {
base = full_dir.substr(0, full_dir.find(":/") + 2);
} else {
ERR_FAIL_V(ERR_INVALID_PARAMETER);
@@ -229,8 +231,9 @@ DirAccess *DirAccess::open(const String &p_path, Error *r_error) {
ERR_FAIL_COND_V_MSG(!da, nullptr, "Cannot create DirAccess for path '" + p_path + "'.");
Error err = da->change_dir(p_path);
- if (r_error)
+ if (r_error) {
*r_error = err;
+ }
if (err != OK) {
memdelete(da);
return nullptr;
@@ -250,8 +253,9 @@ DirAccess *DirAccess::create(AccessType p_access) {
String DirAccess::get_full_path(const String &p_path, AccessType p_access) {
DirAccess *d = DirAccess::create(p_access);
- if (!d)
+ if (!d) {
return p_path;
+ }
d->change_dir(p_path);
String full = d->get_current_dir();
@@ -298,8 +302,9 @@ Error DirAccess::copy(String p_from, String p_to, int p_chmod_flags) {
fdst->close();
err = FileAccess::set_unix_permissions(p_to, p_chmod_flags);
// If running on a platform with no chmod support (i.e., Windows), don't fail
- if (err == ERR_UNAVAILABLE)
+ if (err == ERR_UNAVAILABLE) {
err = OK;
+ }
}
memdelete(fsrc);
@@ -334,9 +339,9 @@ Error DirAccess::_copy_dir(DirAccess *p_target_da, String p_to, int p_chmod_flag
String n = get_next();
while (n != String()) {
if (n != "." && n != "..") {
- if (current_is_dir())
+ if (current_is_dir()) {
dirs.push_back(n);
- else {
+ } else {
const String &rel_path = n;
if (!n.is_rel_path()) {
list_dir_end();
diff --git a/core/os/dir_access.h b/core/os/dir_access.h
index 06b3abca8c..6bce9a4c12 100644
--- a/core/os/dir_access.h
+++ b/core/os/dir_access.h
@@ -133,8 +133,9 @@ struct DirAccessRef {
DirAccessRef(DirAccess *fa) { f = fa; }
~DirAccessRef() {
- if (f)
+ if (f) {
memdelete(f);
+ }
}
};
diff --git a/core/os/file_access.cpp b/core/os/file_access.cpp
index 8b13e53812..f9ba8ff2d2 100644
--- a/core/os/file_access.cpp
+++ b/core/os/file_access.cpp
@@ -51,12 +51,14 @@ FileAccess *FileAccess::create(AccessType p_access) {
}
bool FileAccess::exists(const String &p_name) {
- if (PackedData::get_singleton() && PackedData::get_singleton()->has_path(p_name))
+ if (PackedData::get_singleton() && PackedData::get_singleton()->has_path(p_name)) {
return true;
+ }
FileAccess *f = open(p_name, READ);
- if (!f)
+ if (!f) {
return false;
+ }
memdelete(f);
return true;
}
@@ -90,8 +92,9 @@ FileAccess *FileAccess::open(const String &p_path, int p_mode_flags, Error *r_er
if (!(p_mode_flags & WRITE) && PackedData::get_singleton() && !PackedData::get_singleton()->is_disabled()) {
ret = PackedData::get_singleton()->try_open_path(p_path);
if (ret) {
- if (r_error)
+ if (r_error) {
*r_error = OK;
+ }
return ret;
}
}
@@ -99,8 +102,9 @@ FileAccess *FileAccess::open(const String &p_path, int p_mode_flags, Error *r_er
ret = create_for_path(p_path);
Error err = ret->_open(p_path, p_mode_flags);
- if (r_error)
+ if (r_error) {
*r_error = err;
+ }
if (err != OK) {
memdelete(ret);
ret = nullptr;
@@ -214,10 +218,11 @@ float FileAccess::get_float() const {
};
real_t FileAccess::get_real() const {
- if (real_is_double)
+ if (real_is_double) {
return get_double();
- else
+ } else {
return get_float();
+ }
}
double FileAccess::get_double() const {
@@ -233,8 +238,9 @@ String FileAccess::get_token() const {
while (!eof_reached()) {
if (c <= ' ') {
- if (token.length())
+ if (token.length()) {
break;
+ }
} else {
token += c;
}
@@ -299,8 +305,9 @@ String FileAccess::get_line() const {
if (c == '\n' || c == '\0') {
line.push_back(0);
return String::utf8(line.get_data());
- } else if (c != '\r')
+ } else if (c != '\r') {
line.push_back(c);
+ }
c = get_8();
}
@@ -314,14 +321,16 @@ Vector<String> FileAccess::get_csv_line(const String &p_delim) const {
String l;
int qc = 0;
do {
- if (eof_reached())
+ if (eof_reached()) {
break;
+ }
l += get_line() + "\n";
qc = 0;
for (int i = 0; i < l.length(); i++) {
- if (l[i] == '"')
+ if (l[i] == '"') {
qc++;
+ }
}
} while (qc % 2);
@@ -360,8 +369,9 @@ Vector<String> FileAccess::get_csv_line(const String &p_delim) const {
int FileAccess::get_buffer(uint8_t *p_dst, int p_length) const {
int i = 0;
- for (i = 0; i < p_length && !eof_reached(); i++)
+ for (i = 0; i < p_length && !eof_reached(); i++) {
p_dst[i] = get_8();
+ }
return i;
}
@@ -426,10 +436,11 @@ void FileAccess::store_64(uint64_t p_dest) {
}
void FileAccess::store_real(real_t p_real) {
- if (sizeof(real_t) == 4)
+ if (sizeof(real_t) == 4) {
store_float(p_real);
- else
+ } else {
store_double(p_real);
+ }
}
void FileAccess::store_float(float p_dest) {
@@ -445,8 +456,9 @@ void FileAccess::store_double(double p_dest) {
};
uint64_t FileAccess::get_modified_time(const String &p_file) {
- if (PackedData::get_singleton() && !PackedData::get_singleton()->is_disabled() && PackedData::get_singleton()->has_path(p_file))
+ if (PackedData::get_singleton() && !PackedData::get_singleton()->is_disabled() && PackedData::get_singleton()->has_path(p_file)) {
return 0;
+ }
FileAccess *fa = create_for_path(p_file);
ERR_FAIL_COND_V_MSG(!fa, 0, "Cannot create FileAccess for path '" + p_file + "'.");
@@ -457,8 +469,9 @@ uint64_t FileAccess::get_modified_time(const String &p_file) {
}
uint32_t FileAccess::get_unix_permissions(const String &p_file) {
- if (PackedData::get_singleton() && !PackedData::get_singleton()->is_disabled() && PackedData::get_singleton()->has_path(p_file))
+ if (PackedData::get_singleton() && !PackedData::get_singleton()->is_disabled() && PackedData::get_singleton()->has_path(p_file)) {
return 0;
+ }
FileAccess *fa = create_for_path(p_file);
ERR_FAIL_COND_V_MSG(!fa, 0, "Cannot create FileAccess for path '" + p_file + "'.");
@@ -478,8 +491,9 @@ Error FileAccess::set_unix_permissions(const String &p_file, uint32_t p_permissi
}
void FileAccess::store_string(const String &p_string) {
- if (p_string.length() == 0)
+ if (p_string.length() == 0) {
return;
+ }
CharString cs = p_string.utf8();
store_buffer((uint8_t *)&cs[0], cs.length());
@@ -531,8 +545,9 @@ void FileAccess::store_csv_line(const Vector<String> &p_values, const String &p_
}
void FileAccess::store_buffer(const uint8_t *p_src, int p_length) {
- for (int i = 0; i < p_length; i++)
+ for (int i = 0; i < p_length; i++) {
store_8(p_src[i]);
+ }
}
Vector<uint8_t> FileAccess::get_file_as_array(const String &p_path, Error *r_error) {
@@ -570,8 +585,9 @@ String FileAccess::get_file_as_string(const String &p_path, Error *r_error) {
String FileAccess::get_md5(const String &p_file) {
FileAccess *f = FileAccess::open(p_file, READ);
- if (!f)
+ if (!f) {
return String();
+ }
CryptoCore::MD5Context ctx;
ctx.start();
@@ -583,8 +599,9 @@ String FileAccess::get_md5(const String &p_file) {
if (br > 0) {
ctx.update(step, br);
}
- if (br < 4096)
+ if (br < 4096) {
break;
+ }
}
unsigned char hash[16];
@@ -610,8 +627,9 @@ String FileAccess::get_multiple_md5(const Vector<String> &p_file) {
if (br > 0) {
ctx.update(step, br);
}
- if (br < 4096)
+ if (br < 4096) {
break;
+ }
}
memdelete(f);
}
@@ -624,8 +642,9 @@ String FileAccess::get_multiple_md5(const Vector<String> &p_file) {
String FileAccess::get_sha256(const String &p_file) {
FileAccess *f = FileAccess::open(p_file, READ);
- if (!f)
+ if (!f) {
return String();
+ }
CryptoCore::SHA256Context ctx;
ctx.start();
@@ -637,8 +656,9 @@ String FileAccess::get_sha256(const String &p_file) {
if (br > 0) {
ctx.update(step, br);
}
- if (br < 4096)
+ if (br < 4096) {
break;
+ }
}
unsigned char hash[32];
diff --git a/core/os/file_access.h b/core/os/file_access.h
index a956ae12f4..48b9ee4269 100644
--- a/core/os/file_access.h
+++ b/core/os/file_access.h
@@ -190,8 +190,9 @@ struct FileAccessRef {
FileAccessRef(FileAccess *fa) { f = fa; }
~FileAccessRef() {
- if (f)
+ if (f) {
memdelete(f);
+ }
}
};
diff --git a/core/os/main_loop.cpp b/core/os/main_loop.cpp
index 1ce49b544b..dc68c2a9f9 100644
--- a/core/os/main_loop.cpp
+++ b/core/os/main_loop.cpp
@@ -59,23 +59,27 @@ void MainLoop::set_init_script(const Ref<Script> &p_init_script) {
}
void MainLoop::init() {
- if (init_script.is_valid())
+ if (init_script.is_valid()) {
set_script(init_script);
+ }
- if (get_script_instance())
+ if (get_script_instance()) {
get_script_instance()->call("_initialize");
+ }
}
bool MainLoop::iteration(float p_time) {
- if (get_script_instance())
+ if (get_script_instance()) {
return get_script_instance()->call("_iteration", p_time);
+ }
return false;
}
bool MainLoop::idle(float p_time) {
- if (get_script_instance())
+ if (get_script_instance()) {
return get_script_instance()->call("_idle", p_time);
+ }
return false;
}
diff --git a/core/os/memory.h b/core/os/memory.h
index 42723152e4..46ffb4124b 100644
--- a/core/os/memory.h
+++ b/core/os/memory.h
@@ -108,36 +108,42 @@ _ALWAYS_INLINE_ bool predelete_handler(void *) {
template <class T>
void memdelete(T *p_class) {
- if (!predelete_handler(p_class))
+ if (!predelete_handler(p_class)) {
return; // doesn't want to be deleted
- if (!__has_trivial_destructor(T))
+ }
+ if (!__has_trivial_destructor(T)) {
p_class->~T();
+ }
Memory::free_static(p_class, false);
}
template <class T, class A>
void memdelete_allocator(T *p_class) {
- if (!predelete_handler(p_class))
+ if (!predelete_handler(p_class)) {
return; // doesn't want to be deleted
- if (!__has_trivial_destructor(T))
+ }
+ if (!__has_trivial_destructor(T)) {
p_class->~T();
+ }
A::free(p_class);
}
#define memdelete_notnull(m_v) \
{ \
- if (m_v) \
+ if (m_v) { \
memdelete(m_v); \
+ } \
}
#define memnew_arr(m_class, m_count) memnew_arr_template<m_class>(m_count)
template <typename T>
T *memnew_arr_template(size_t p_elements, const char *p_descr = "") {
- if (p_elements == 0)
+ if (p_elements == 0) {
return nullptr;
+ }
/** overloading operator new[] cannot be done , because it may not return the real allocated address (it may pad the 'element count' before the actual array). Because of that, it must be done by hand. This is the
same strategy used by std::vector, and the Vector class, so it should be safe.*/
diff --git a/core/os/os.cpp b/core/os/os.cpp
index 4414b582bd..da9dabd401 100644
--- a/core/os/os.cpp
+++ b/core/os/os.cpp
@@ -178,14 +178,16 @@ static FileAccess *_OSPRF = nullptr;
static void _OS_printres(Object *p_obj) {
Resource *res = Object::cast_to<Resource>(p_obj);
- if (!res)
+ if (!res) {
return;
+ }
String str = itos(res->get_instance_id()) + String(res->get_class()) + ":" + String(res->get_name()) + " - " + res->get_path();
- if (_OSPRF)
+ if (_OSPRF) {
_OSPRF->store_line(str);
- else
+ } else {
print_line(str);
+ }
}
void OS::print_all_resources(String p_to_file) {
@@ -202,8 +204,9 @@ void OS::print_all_resources(String p_to_file) {
ObjectDB::debug_objects(_OS_printres);
if (p_to_file != "") {
- if (_OSPRF)
+ if (_OSPRF) {
memdelete(_OSPRF);
+ }
_OSPRF = nullptr;
}
}
@@ -366,18 +369,21 @@ void OS::set_has_server_feature_callback(HasServerFeatureCallback p_callback) {
}
bool OS::has_feature(const String &p_feature) {
- if (p_feature == get_name())
+ if (p_feature == get_name()) {
return true;
+ }
#ifdef DEBUG_ENABLED
- if (p_feature == "debug")
+ if (p_feature == "debug") {
return true;
+ }
#else
if (p_feature == "release")
return true;
#endif
#ifdef TOOLS_ENABLED
- if (p_feature == "editor")
+ if (p_feature == "editor") {
return true;
+ }
#else
if (p_feature == "standalone")
return true;
@@ -417,15 +423,17 @@ bool OS::has_feature(const String &p_feature) {
}
#endif
- if (_check_internal_feature_support(p_feature))
+ if (_check_internal_feature_support(p_feature)) {
return true;
+ }
if (has_server_feature_callback && has_server_feature_callback(p_feature)) {
return true;
}
- if (ProjectSettings::get_singleton()->has_custom_feature(p_feature))
+ if (ProjectSettings::get_singleton()->has_custom_feature(p_feature)) {
return true;
+ }
return false;
}
@@ -444,21 +452,24 @@ List<String> OS::get_restart_on_exit_arguments() const {
}
PackedStringArray OS::get_connected_midi_inputs() {
- if (MIDIDriver::get_singleton())
+ if (MIDIDriver::get_singleton()) {
return MIDIDriver::get_singleton()->get_connected_inputs();
+ }
PackedStringArray list;
return list;
}
void OS::open_midi_inputs() {
- if (MIDIDriver::get_singleton())
+ if (MIDIDriver::get_singleton()) {
MIDIDriver::get_singleton()->open();
+ }
}
void OS::close_midi_inputs() {
- if (MIDIDriver::get_singleton())
+ if (MIDIDriver::get_singleton()) {
MIDIDriver::get_singleton()->close();
+ }
}
OS::OS() {
diff --git a/core/os/rw_lock.h b/core/os/rw_lock.h
index e519cea439..1035072cce 100644
--- a/core/os/rw_lock.h
+++ b/core/os/rw_lock.h
@@ -57,12 +57,14 @@ class RWLockRead {
public:
RWLockRead(const RWLock *p_lock) {
lock = const_cast<RWLock *>(p_lock);
- if (lock)
+ if (lock) {
lock->read_lock();
+ }
}
~RWLockRead() {
- if (lock)
+ if (lock) {
lock->read_unlock();
+ }
}
};
@@ -72,12 +74,14 @@ class RWLockWrite {
public:
RWLockWrite(RWLock *p_lock) {
lock = p_lock;
- if (lock)
+ if (lock) {
lock->write_lock();
+ }
}
~RWLockWrite() {
- if (lock)
+ if (lock) {
lock->write_unlock();
+ }
}
};
diff --git a/core/os/semaphore.h b/core/os/semaphore.h
index 3d9d1ab984..077e04704b 100644
--- a/core/os/semaphore.h
+++ b/core/os/semaphore.h
@@ -54,8 +54,9 @@ public:
_ALWAYS_INLINE_ void wait() const {
std::unique_lock<decltype(mutex_)> lock(mutex_);
- while (!count_) // Handle spurious wake-ups.
+ while (!count_) { // Handle spurious wake-ups.
condition_.wait(lock);
+ }
--count_;
}
diff --git a/core/os/thread.cpp b/core/os/thread.cpp
index 399efb19a4..70f960ed2a 100644
--- a/core/os/thread.cpp
+++ b/core/os/thread.cpp
@@ -38,8 +38,9 @@ Error (*Thread::set_name_func)(const String &) = nullptr;
Thread::ID Thread::_main_thread_id = 0;
Thread::ID Thread::get_caller_id() {
- if (get_thread_id_func)
+ if (get_thread_id_func) {
return get_thread_id_func();
+ }
return 0;
}
@@ -51,13 +52,15 @@ Thread *Thread::create(ThreadCreateCallback p_callback, void *p_user, const Sett
}
void Thread::wait_to_finish(Thread *p_thread) {
- if (wait_to_finish_func)
+ if (wait_to_finish_func) {
wait_to_finish_func(p_thread);
+ }
}
Error Thread::set_name(const String &p_name) {
- if (set_name_func)
+ if (set_name_func) {
return set_name_func(p_name);
+ }
return ERR_UNAVAILABLE;
};
diff --git a/core/os/threaded_array_processor.h b/core/os/threaded_array_processor.h
index 0a435961e1..d27399e4cc 100644
--- a/core/os/threaded_array_processor.h
+++ b/core/os/threaded_array_processor.h
@@ -57,8 +57,9 @@ void process_array_thread(void *ud) {
T &data = *(T *)ud;
while (true) {
uint32_t index = atomic_increment(&data.index);
- if (index >= data.elements)
+ if (index >= data.elements) {
break;
+ }
data.process(index);
}
}
diff --git a/core/packed_data_container.cpp b/core/packed_data_container.cpp
index cbaf7e883b..b5aefd6f2c 100644
--- a/core/packed_data_container.cpp
+++ b/core/packed_data_container.cpp
@@ -36,8 +36,9 @@
Variant PackedDataContainer::getvar(const Variant &p_key, bool *r_valid) const {
bool err = false;
Variant ret = _key_at_ofs(0, p_key, err);
- if (r_valid)
+ if (r_valid) {
*r_valid = !err;
+ }
return ret;
}
@@ -48,9 +49,9 @@ int PackedDataContainer::size() const {
Variant PackedDataContainer::_iter_init_ofs(const Array &p_iter, uint32_t p_offset) {
Array ref = p_iter;
uint32_t size = _size(p_offset);
- if (size == 0 || ref.size() != 1)
+ if (size == 0 || ref.size() != 1) {
return false;
- else {
+ } else {
ref[0] = 0;
return true;
}
@@ -59,11 +60,13 @@ Variant PackedDataContainer::_iter_init_ofs(const Array &p_iter, uint32_t p_offs
Variant PackedDataContainer::_iter_next_ofs(const Array &p_iter, uint32_t p_offset) {
Array ref = p_iter;
int size = _size(p_offset);
- if (ref.size() != 1)
+ if (ref.size() != 1) {
return false;
+ }
int pos = ref[0];
- if (pos < 0 || pos >= size)
+ if (pos < 0 || pos >= size) {
return false;
+ }
pos += 1;
ref[0] = pos;
return pos != size;
@@ -72,8 +75,9 @@ Variant PackedDataContainer::_iter_next_ofs(const Array &p_iter, uint32_t p_offs
Variant PackedDataContainer::_iter_get_ofs(const Variant &p_iter, uint32_t p_offset) {
int size = _size(p_offset);
int pos = p_iter;
- if (pos < 0 || pos >= size)
+ if (pos < 0 || pos >= size) {
return Variant();
+ }
const uint8_t *rd = data.ptr();
const uint8_t *r = &rd[p_offset];
@@ -170,16 +174,18 @@ Variant PackedDataContainer::_key_at_ofs(uint32_t p_ofs, const Variant &p_key, b
uint32_t khash = decode_uint32(r + 8 + i * 12 + 0);
if (khash == hash) {
Variant key = _get_at_ofs(decode_uint32(r + 8 + i * 12 + 4), rd, err);
- if (err)
+ if (err) {
return Variant();
+ }
if (key == p_key) {
//key matches, return value
return _get_at_ofs(decode_uint32(r + 8 + i * 12 + 8), rd, err);
}
found = true;
} else {
- if (found)
+ if (found) {
break;
+ }
}
}
@@ -375,8 +381,9 @@ void PackedDataContainerRef::_bind_methods() {
Variant PackedDataContainerRef::getvar(const Variant &p_key, bool *r_valid) const {
bool err = false;
Variant ret = from->_key_at_ofs(offset, p_key, err);
- if (r_valid)
+ if (r_valid) {
*r_valid = !err;
+ }
return ret;
}
diff --git a/core/pool_allocator.cpp b/core/pool_allocator.cpp
index 63fd1d7bd1..1dd215a787 100644
--- a/core/pool_allocator.cpp
+++ b/core/pool_allocator.cpp
@@ -53,8 +53,9 @@ void PoolAllocator::mt_unlock() const {
}
bool PoolAllocator::get_free_entry(EntryArrayPos *p_pos) {
- if (entry_count == entry_max)
+ if (entry_count == entry_max) {
return false;
+ }
for (int i = 0; i < entry_max; i++) {
if (entry_array[i].len == 0) {
@@ -109,8 +110,9 @@ bool PoolAllocator::find_hole(EntryArrayPos *p_pos, int p_for_size) {
void PoolAllocator::compact(int p_up_to) {
uint32_t prev_entry_end_pos = 0;
- if (p_up_to < 0)
+ if (p_up_to < 0) {
p_up_to = entry_count;
+ }
for (int i = 0; i < p_up_to; i++) {
Entry &entry = entry_array[entry_indices[i]];
@@ -158,8 +160,9 @@ bool PoolAllocator::find_entry_index(EntryIndicesPos *p_map_pos, Entry *p_entry)
}
}
- if (entry_pos == entry_max)
+ if (entry_pos == entry_max) {
return false;
+ }
*p_map_pos = entry_pos;
return true;
@@ -168,8 +171,9 @@ bool PoolAllocator::find_entry_index(EntryIndicesPos *p_map_pos, Entry *p_entry)
PoolAllocator::ID PoolAllocator::alloc(int p_size) {
ERR_FAIL_COND_V(p_size < 1, POOL_ALLOCATOR_INVALID_ID);
#ifdef DEBUG_ENABLED
- if (p_size > free_mem)
+ if (p_size > free_mem) {
OS::get_singleton()->debug_break();
+ }
#endif
ERR_FAIL_COND_V(p_size > free_mem, POOL_ALLOCATOR_INVALID_ID);
@@ -221,8 +225,9 @@ PoolAllocator::ID PoolAllocator::alloc(int p_size) {
entry.lock = 0;
entry.check = (check_count++) & CHECK_MASK;
free_mem -= size_to_alloc;
- if (free_mem < free_mem_peak)
+ if (free_mem < free_mem_peak) {
free_mem_peak = free_mem;
+ }
ID retval = (entry_indices[new_entry_indices_pos] << CHECK_BITS) | entry.check;
mt_unlock();
@@ -372,8 +377,9 @@ Error PoolAllocator::resize(ID p_mem, int p_new_size) {
e->len = p_new_size;
free_mem -= alloc_size;
mt_unlock();
- if (free_mem < free_mem_peak)
+ if (free_mem < free_mem_peak) {
free_mem_peak = free_mem;
+ }
return OK;
}
@@ -387,8 +393,9 @@ Error PoolAllocator::resize(ID p_mem, int p_new_size) {
e->len = p_new_size;
free_mem -= alloc_size;
mt_unlock();
- if (free_mem < free_mem_peak)
+ if (free_mem < free_mem_peak) {
free_mem_peak = free_mem;
+ }
return OK;
}
@@ -397,8 +404,9 @@ Error PoolAllocator::resize(ID p_mem, int p_new_size) {
}
Error PoolAllocator::lock(ID p_mem) {
- if (!needs_locking)
+ if (!needs_locking) {
return OK;
+ }
mt_lock();
Entry *e = get_entry(p_mem);
if (!e) {
@@ -412,8 +420,9 @@ Error PoolAllocator::lock(ID p_mem) {
}
bool PoolAllocator::is_locked(ID p_mem) const {
- if (!needs_locking)
+ if (!needs_locking) {
return false;
+ }
mt_lock();
const Entry *e = ((PoolAllocator *)(this))->get_entry(p_mem);
@@ -493,8 +502,9 @@ void *PoolAllocator::get(ID p_mem) {
}
void PoolAllocator::unlock(ID p_mem) {
- if (!needs_locking)
+ if (!needs_locking) {
return;
+ }
mt_lock();
Entry *e = get_entry(p_mem);
if (!e) {
@@ -568,16 +578,18 @@ PoolAllocator::PoolAllocator(int p_align, int p_size, bool p_needs_locking, int
mem_ptr = Memory::alloc_static(p_size + p_align, true);
uint8_t *mem8 = (uint8_t *)mem_ptr;
uint64_t ofs = (uint64_t)mem8;
- if (ofs % p_align)
+ if (ofs % p_align) {
mem8 += p_align - (ofs % p_align);
+ }
create_pool(mem8, p_size, p_max_entries);
needs_locking = p_needs_locking;
align = p_align;
}
PoolAllocator::~PoolAllocator() {
- if (mem_ptr)
+ if (mem_ptr) {
memfree(mem_ptr);
+ }
memdelete_arr(entry_array);
memdelete_arr(entry_indices);
diff --git a/core/pool_allocator.h b/core/pool_allocator.h
index cec95c7323..7d77af6266 100644
--- a/core/pool_allocator.h
+++ b/core/pool_allocator.h
@@ -99,8 +99,9 @@ private:
}
inline int aligned(int p_size) const {
int rem = p_size % align;
- if (rem)
+ if (rem) {
p_size += align - rem;
+ }
return p_size;
}
diff --git a/core/print_string.cpp b/core/print_string.cpp
index b7903b6880..54de229471 100644
--- a/core/print_string.cpp
+++ b/core/print_string.cpp
@@ -53,10 +53,11 @@ void remove_print_handler(PrintHandlerList *p_handler) {
while (l) {
if (l == p_handler) {
- if (prev)
+ if (prev) {
prev->next = l->next;
- else
+ } else {
print_handler_list = l->next;
+ }
break;
}
prev = l;
@@ -69,8 +70,9 @@ void remove_print_handler(PrintHandlerList *p_handler) {
}
void print_line(String p_string) {
- if (!_print_line_enabled)
+ if (!_print_line_enabled) {
return;
+ }
OS::get_singleton()->print("%s\n", p_string.utf8().get_data());
@@ -85,8 +87,9 @@ void print_line(String p_string) {
}
void print_error(String p_string) {
- if (!_print_error_enabled)
+ if (!_print_error_enabled) {
return;
+ }
OS::get_singleton()->printerr("%s\n", p_string.utf8().get_data());
diff --git a/core/project_settings.cpp b/core/project_settings.cpp
index fee9423a5e..cedc7f731f 100644
--- a/core/project_settings.cpp
+++ b/core/project_settings.cpp
@@ -54,12 +54,14 @@ String ProjectSettings::get_resource_path() const {
};
String ProjectSettings::localize_path(const String &p_path) const {
- if (resource_path == "")
+ if (resource_path == "") {
return p_path; //not initialized yet
+ }
if (p_path.begins_with("res://") || p_path.begins_with("user://") ||
- (p_path.is_abs_path() && !p_path.begins_with(resource_path)))
+ (p_path.is_abs_path() && !p_path.begins_with(resource_path))) {
return p_path.simplify_path();
+ }
DirAccess *dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
@@ -140,9 +142,9 @@ String ProjectSettings::globalize_path(const String &p_path) const {
bool ProjectSettings::_set(const StringName &p_name, const Variant &p_value) {
_THREAD_SAFE_METHOD_
- if (p_value.get_type() == Variant::NIL)
+ if (p_value.get_type() == Variant::NIL) {
props.erase(p_name);
- else {
+ } else {
if (p_name == CoreStringNames::get_singleton()->_custom_features) {
Vector<String> custom_feature_array = String(p_value).split(",");
for (int i = 0; i < custom_feature_array.size(); i++) {
@@ -172,8 +174,9 @@ bool ProjectSettings::_set(const StringName &p_name, const Variant &p_value) {
}
if (props.has(p_name)) {
- if (!props[p_name].overridden)
+ if (!props[p_name].overridden) {
props[p_name].variant = p_value;
+ }
} else {
props[p_name] = VariantContainer(p_value, last_order++);
@@ -215,17 +218,19 @@ void ProjectSettings::_get_property_list(List<PropertyInfo> *p_list) const {
for (Map<StringName, VariantContainer>::Element *E = props.front(); E; E = E->next()) {
const VariantContainer *v = &E->get();
- if (v->hide_from_editor)
+ if (v->hide_from_editor) {
continue;
+ }
_VCSort vc;
vc.name = E->key();
vc.order = v->order;
vc.type = v->variant.get_type();
- if (vc.name.begins_with("input/") || vc.name.begins_with("import/") || vc.name.begins_with("export/") || vc.name.begins_with("/remap") || vc.name.begins_with("/locale") || vc.name.begins_with("/autoload"))
+ if (vc.name.begins_with("input/") || vc.name.begins_with("import/") || vc.name.begins_with("export/") || vc.name.begins_with("/remap") || vc.name.begins_with("/locale") || vc.name.begins_with("/autoload")) {
vc.flags = PROPERTY_USAGE_STORAGE;
- else
+ } else {
vc.flags = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_STORAGE;
+ }
if (v->restart_if_changed) {
vc.flags |= PROPERTY_USAGE_RESTART_IF_CHANGED;
@@ -236,27 +241,31 @@ void ProjectSettings::_get_property_list(List<PropertyInfo> *p_list) const {
for (Set<_VCSort>::Element *E = vclist.front(); E; E = E->next()) {
String prop_info_name = E->get().name;
int dot = prop_info_name.find(".");
- if (dot != -1)
+ if (dot != -1) {
prop_info_name = prop_info_name.substr(0, dot);
+ }
if (custom_prop_info.has(prop_info_name)) {
PropertyInfo pi = custom_prop_info[prop_info_name];
pi.name = E->get().name;
pi.usage = E->get().flags;
p_list->push_back(pi);
- } else
+ } else {
p_list->push_back(PropertyInfo(E->get().type, E->get().name, PROPERTY_HINT_NONE, "", E->get().flags));
+ }
}
}
bool ProjectSettings::_load_resource_pack(const String &p_pack, bool p_replace_files) {
- if (PackedData::get_singleton()->is_disabled())
+ if (PackedData::get_singleton()->is_disabled()) {
return false;
+ }
bool ok = PackedData::get_singleton()->add_pack(p_pack, p_replace_files) == OK;
- if (!ok)
+ if (!ok) {
return false;
+ }
//if data.pck is found, all directory access will be from here
DirAccess::make_default<DirAccessPack>(DirAccess::ACCESS_RESOURCES);
@@ -419,8 +428,9 @@ Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, b
if (p_upwards) {
// Try to load settings ascending through parent directories
d->change_dir("..");
- if (d->get_current_dir() == current_dir)
+ if (d->get_current_dir() == current_dir) {
break; // not doing anything useful
+ }
current_dir = d->get_current_dir();
} else {
break;
@@ -431,11 +441,13 @@ Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, b
resource_path = resource_path.replace("\\", "/"); // windows path to unix path just in case
memdelete(d);
- if (!found)
+ if (!found) {
return err;
+ }
- if (resource_path.length() && resource_path[resource_path.length() - 1] == '/')
+ if (resource_path.length() && resource_path[resource_path.length() - 1] == '/') {
resource_path = resource_path.substr(0, resource_path.length() - 1); // chop end
+ }
return OK;
}
@@ -652,29 +664,33 @@ Error ProjectSettings::_save_settings_binary(const String &p_file, const Map<Str
for (Map<String, List<String>>::Element *E = props.front(); E; E = E->next()) {
for (List<String>::Element *F = E->get().front(); F; F = F->next()) {
String key = F->get();
- if (E->key() != "")
+ if (E->key() != "") {
key = E->key() + "/" + key;
+ }
Variant value;
- if (p_custom.has(key))
+ if (p_custom.has(key)) {
value = p_custom[key];
- else
+ } else {
value = get(key);
+ }
file->store_32(key.length());
file->store_string(key);
int len;
err = encode_variant(value, nullptr, len, true);
- if (err != OK)
+ if (err != OK) {
memdelete(file);
+ }
ERR_FAIL_COND_V_MSG(err != OK, ERR_INVALID_DATA, "Error when trying to encode Variant.");
Vector<uint8_t> buff;
buff.resize(len);
err = encode_variant(value, buff.ptrw(), len, true);
- if (err != OK)
+ if (err != OK) {
memdelete(file);
+ }
ERR_FAIL_COND_V_MSG(err != OK, ERR_INVALID_DATA, "Error when trying to encode Variant.");
file->store_32(len);
file->store_buffer(buff.ptr(), buff.size());
@@ -703,25 +719,30 @@ Error ProjectSettings::_save_settings_text(const String &p_file, const Map<Strin
file->store_line("");
file->store_string("config_version=" + itos(CONFIG_VERSION) + "\n");
- if (p_custom_features != String())
+ if (p_custom_features != String()) {
file->store_string("custom_features=\"" + p_custom_features + "\"\n");
+ }
file->store_string("\n");
for (Map<String, List<String>>::Element *E = props.front(); E; E = E->next()) {
- if (E != props.front())
+ if (E != props.front()) {
file->store_string("\n");
+ }
- if (E->key() != "")
+ if (E->key() != "") {
file->store_string("[" + E->key() + "]\n\n");
+ }
for (List<String>::Element *F = E->get().front(); F; F = F->next()) {
String key = F->get();
- if (E->key() != "")
+ if (E->key() != "") {
key = E->key() + "/" + key;
+ }
Variant value;
- if (p_custom.has(key))
+ if (p_custom.has(key)) {
value = p_custom[key];
- else
+ } else {
value = get(key);
+ }
String vstr;
VariantWriter::write_to_string(value, vstr);
@@ -749,19 +770,22 @@ Error ProjectSettings::save_custom(const String &p_path, const CustomMap &p_cust
for (Map<StringName, VariantContainer>::Element *G = props.front(); G; G = G->next()) {
const VariantContainer *v = &G->get();
- if (v->hide_from_editor)
+ if (v->hide_from_editor) {
continue;
+ }
- if (p_custom.has(G->key()))
+ if (p_custom.has(G->key())) {
continue;
+ }
_VCSort vc;
vc.name = G->key(); //*k;
vc.order = v->order;
vc.type = v->variant.get_type();
vc.flags = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_STORAGE;
- if (v->variant == v->initial)
+ if (v->variant == v->initial) {
continue;
+ }
vclist.insert(vc);
}
@@ -787,9 +811,9 @@ Error ProjectSettings::save_custom(const String &p_path, const CustomMap &p_cust
int div = category.find("/");
- if (div < 0)
+ if (div < 0) {
category = "";
- else {
+ } else {
category = category.substr(0, div);
name = name.substr(div + 1, name.size());
}
@@ -799,18 +823,19 @@ Error ProjectSettings::save_custom(const String &p_path, const CustomMap &p_cust
String custom_features;
for (int i = 0; i < p_custom_features.size(); i++) {
- if (i > 0)
+ if (i > 0) {
custom_features += ",";
+ }
String f = p_custom_features[i].strip_edges().replace("\"", "");
custom_features += f;
}
- if (p_path.ends_with(".godot"))
+ if (p_path.ends_with(".godot")) {
return _save_settings_text(p_path, props, p_custom, custom_features);
- else if (p_path.ends_with(".binary"))
+ } else if (p_path.ends_with(".binary")) {
return _save_settings_binary(p_path, props, p_custom, custom_features);
- else {
+ } else {
ERR_FAIL_V_MSG(ERR_FILE_UNRECOGNIZED, "Unknown config file format: " + p_path + ".");
}
}
@@ -834,8 +859,9 @@ Vector<String> ProjectSettings::get_optimizer_presets() const {
Vector<String> names;
for (List<PropertyInfo>::Element *E = pi.front(); E; E = E->next()) {
- if (!E->get().name.begins_with("optimizer_presets/"))
+ if (!E->get().name.begins_with("optimizer_presets/")) {
continue;
+ }
names.push_back(E->get().name.get_slicec('/', 1));
}
@@ -854,10 +880,12 @@ void ProjectSettings::_add_property_info_bind(const Dictionary &p_info) {
pinfo.type = Variant::Type(p_info["type"].operator int());
ERR_FAIL_INDEX(pinfo.type, Variant::VARIANT_MAX);
- if (p_info.has("hint"))
+ if (p_info.has("hint")) {
pinfo.hint = PropertyHint(p_info["hint"].operator int());
- if (p_info.has("hint_string"))
+ }
+ if (p_info.has("hint_string")) {
pinfo.hint_string = p_info["hint_string"];
+ }
set_custom_property_info(pinfo.name, pinfo);
}
@@ -881,15 +909,17 @@ bool ProjectSettings::is_using_datapack() const {
}
bool ProjectSettings::property_can_revert(const String &p_name) {
- if (!props.has(p_name))
+ if (!props.has(p_name)) {
return false;
+ }
return props[p_name].initial != props[p_name].variant;
}
Variant ProjectSettings::property_get_revert(const String &p_name) {
- if (!props.has(p_name))
+ if (!props.has(p_name)) {
return Variant();
+ }
return props[p_name].initial;
}
@@ -948,8 +978,9 @@ ProjectSettings::ProjectSettings() {
PackedStringArray extensions = PackedStringArray();
extensions.push_back("gd");
- if (Engine::get_singleton()->has_singleton("GodotSharp"))
+ if (Engine::get_singleton()->has_singleton("GodotSharp")) {
extensions.push_back("cs");
+ }
extensions.push_back("shader");
GLOBAL_DEF("editor/search_in_file_extensions", extensions);
diff --git a/core/reference.cpp b/core/reference.cpp
index cc8a9854fb..d1dba0d9bf 100644
--- a/core/reference.cpp
+++ b/core/reference.cpp
@@ -103,12 +103,14 @@ Reference::Reference() :
}
Variant WeakRef::get_ref() const {
- if (ref.is_null())
+ if (ref.is_null()) {
return Variant();
+ }
Object *obj = ObjectDB::get_instance(ref);
- if (!obj)
+ if (!obj) {
return Variant();
+ }
Reference *r = cast_to<Reference>(obj);
if (r) {
return REF(r);
diff --git a/core/reference.h b/core/reference.h
index 972fd500d0..f5794b0b67 100644
--- a/core/reference.h
+++ b/core/reference.h
@@ -59,21 +59,24 @@ class Ref {
T *reference = nullptr;
void ref(const Ref &p_from) {
- if (p_from.reference == reference)
+ if (p_from.reference == reference) {
return;
+ }
unref();
reference = p_from.reference;
- if (reference)
+ if (reference) {
reference->reference();
+ }
}
void ref_pointer(T *p_ref) {
ERR_FAIL_COND(!p_ref);
- if (p_ref->init_ref())
+ if (p_ref->init_ref()) {
reference = p_ref;
+ }
}
//virtual Reference * get_reference() const { return reference; }
@@ -189,8 +192,9 @@ public:
}
Ref(T *p_reference) {
- if (p_reference)
+ if (p_reference) {
ref_pointer(p_reference);
+ }
}
Ref(const Variant &p_variant) {
diff --git a/core/register_core_types.cpp b/core/register_core_types.cpp
index 230acb7e6e..3870141ecf 100644
--- a/core/register_core_types.cpp
+++ b/core/register_core_types.cpp
@@ -297,8 +297,9 @@ void unregister_core_types() {
ResourceLoader::remove_resource_format_loader(resource_format_loader_crypto);
resource_format_loader_crypto.unref();
- if (ip)
+ if (ip) {
memdelete(ip);
+ }
ResourceLoader::finalize();
diff --git a/core/resource.cpp b/core/resource.cpp
index 7d0e29d664..0af8c9c2b3 100644
--- a/core/resource.cpp
+++ b/core/resource.cpp
@@ -46,8 +46,9 @@ void Resource::_resource_path_changed() {
}
void Resource::set_path(const String &p_path, bool p_take_over) {
- if (path_cache == p_path)
+ if (path_cache == p_path) {
return;
+ }
if (path_cache != "") {
ResourceCache::lock->write_lock();
@@ -116,22 +117,26 @@ bool Resource::editor_can_reload_from_file() {
void Resource::reload_from_file() {
String path = get_path();
- if (!path.is_resource_file())
+ if (!path.is_resource_file()) {
return;
+ }
Ref<Resource> s = ResourceLoader::load(ResourceLoader::path_remap(path), get_class(), true);
- if (!s.is_valid())
+ if (!s.is_valid()) {
return;
+ }
List<PropertyInfo> pi;
s->get_property_list(&pi);
for (List<PropertyInfo>::Element *E = pi.front(); E; E = E->next()) {
- if (!(E->get().usage & PROPERTY_USAGE_STORAGE))
+ if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) {
continue;
- if (E->get().name == "resource_path")
+ }
+ if (E->get().name == "resource_path") {
continue; //do not change path
+ }
set(E->get().name, s->get(E->get().name));
}
@@ -147,8 +152,9 @@ Ref<Resource> Resource::duplicate_for_local_scene(Node *p_for_scene, Map<Ref<Res
r->local_scene = p_for_scene;
for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) {
- if (!(E->get().usage & PROPERTY_USAGE_STORAGE))
+ if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) {
continue;
+ }
Variant p = get(E->get().name);
if (p.get_type() == Variant::OBJECT) {
RES sr = p;
@@ -180,8 +186,9 @@ void Resource::configure_for_local_scene(Node *p_for_scene, Map<Ref<Resource>, R
local_scene = p_for_scene;
for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) {
- if (!(E->get().usage & PROPERTY_USAGE_STORAGE))
+ if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) {
continue;
+ }
Variant p = get(E->get().name);
if (p.get_type() == Variant::OBJECT) {
RES sr = p;
@@ -205,8 +212,9 @@ Ref<Resource> Resource::duplicate(bool p_subresources) const {
ERR_FAIL_COND_V(!r, Ref<Resource>());
for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) {
- if (!(E->get().usage & PROPERTY_USAGE_STORAGE))
+ if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) {
continue;
+ }
Variant p = get(E->get().name);
if ((p.get_type() == Variant::DICTIONARY || p.get_type() == Variant::ARRAY)) {
@@ -284,8 +292,9 @@ bool Resource::is_local_to_scene() const {
}
Node *Resource::get_local_scene() const {
- if (local_scene)
+ if (local_scene) {
return local_scene;
+ }
if (_get_local_scene_func) {
return _get_local_scene_func();
@@ -295,15 +304,17 @@ Node *Resource::get_local_scene() const {
}
void Resource::setup_local_to_scene() {
- if (get_script_instance())
+ if (get_script_instance()) {
get_script_instance()->call("_setup_local_to_scene");
+ }
}
Node *(*Resource::_get_local_scene_func)() = nullptr;
void Resource::set_as_translation_remapped(bool p_remapped) {
- if (remapped_list.in_list() == p_remapped)
+ if (remapped_list.in_list() == p_remapped) {
return;
+ }
if (ResourceCache::lock) {
ResourceCache::lock->write_lock();
@@ -419,8 +430,9 @@ void ResourceCache::setup() {
}
void ResourceCache::clear() {
- if (resources.size())
+ if (resources.size()) {
ERR_PRINT("Resources Still in use at Exit!");
+ }
resources.clear();
memdelete(lock);
@@ -501,14 +513,16 @@ void ResourceCache::dump(const char *p_file, bool p_short) {
type_count[r->get_class()]++;
if (!p_short) {
- if (f)
+ if (f) {
f->store_line(r->get_class() + ": " + r->get_path());
+ }
}
}
for (Map<String, int>::Element *E = type_count.front(); E; E = E->next()) {
- if (f)
+ if (f) {
f->store_line(E->key() + " count: " + itos(E->get()));
+ }
}
if (f) {
f->close();
diff --git a/core/ring_buffer.h b/core/ring_buffer.h
index 816a5f33e1..2fd622b86f 100644
--- a/core/ring_buffer.h
+++ b/core/ring_buffer.h
@@ -80,8 +80,9 @@ public:
int left = data_left();
if ((p_offset + p_size) > left) {
p_size -= left - p_offset;
- if (p_size <= 0)
+ if (p_size <= 0) {
return 0;
+ }
}
p_size = MIN(left, p_size);
int pos = read_pos;
@@ -105,8 +106,9 @@ public:
int left = data_left();
if ((p_offset + p_max_size) > left) {
p_max_size -= left - p_offset;
- if (p_max_size <= 0)
+ if (p_max_size <= 0) {
return 0;
+ }
}
p_max_size = MIN(left, p_max_size);
int pos = read_pos;
@@ -117,8 +119,9 @@ public:
end = MIN(end, size());
int total = end - pos;
for (int i = 0; i < total; i++) {
- if (data[pos + i] == t)
+ if (data[pos + i] == t) {
return i + (p_max_size - to_read);
+ }
};
to_read -= total;
pos = 0;
diff --git a/core/safe_refcount.h b/core/safe_refcount.h
index 8e23a0cf94..dc4e62354a 100644
--- a/core/safe_refcount.h
+++ b/core/safe_refcount.h
@@ -43,8 +43,9 @@
template <class T>
static _ALWAYS_INLINE_ T atomic_conditional_increment(volatile T *pw) {
- if (*pw == 0)
+ if (*pw == 0) {
return 0;
+ }
(*pw)++;
@@ -81,8 +82,9 @@ static _ALWAYS_INLINE_ T atomic_add(volatile T *pw, volatile V val) {
template <class T, class V>
static _ALWAYS_INLINE_ T atomic_exchange_if_greater(volatile T *pw, volatile V val) {
- if (val > *pw)
+ if (val > *pw) {
*pw = val;
+ }
return *pw;
}
@@ -98,10 +100,12 @@ template <class T>
static _ALWAYS_INLINE_ T atomic_conditional_increment(volatile T *pw) {
while (true) {
T tmp = static_cast<T const volatile &>(*pw);
- if (tmp == 0)
+ if (tmp == 0) {
return 0; // if zero, can't add to it anymore
- if (__sync_val_compare_and_swap(pw, tmp, tmp + 1) == tmp)
+ }
+ if (__sync_val_compare_and_swap(pw, tmp, tmp + 1) == tmp) {
return tmp + 1;
+ }
}
}
@@ -129,10 +133,12 @@ template <class T, class V>
static _ALWAYS_INLINE_ T atomic_exchange_if_greater(volatile T *pw, volatile V val) {
while (true) {
T tmp = static_cast<T const volatile &>(*pw);
- if (tmp >= val)
+ if (tmp >= val) {
return tmp; // already greater, or equal
- if (__sync_val_compare_and_swap(pw, tmp, val) == tmp)
+ }
+ if (__sync_val_compare_and_swap(pw, tmp, val) == tmp) {
return val;
+ }
}
}
diff --git a/core/script_language.cpp b/core/script_language.cpp
index 6e5363e916..38a970f3c6 100644
--- a/core/script_language.cpp
+++ b/core/script_language.cpp
@@ -47,8 +47,9 @@ ScriptEditRequestFunction ScriptServer::edit_request_func = nullptr;
void Script::_notification(int p_what) {
if (p_what == NOTIFICATION_POSTINITIALIZE) {
- if (EngineDebugger::is_active())
+ if (EngineDebugger::is_active()) {
EngineDebugger::get_script_debugger()->set_break_language(get_language());
+ }
}
}
@@ -161,8 +162,9 @@ void ScriptServer::init_languages() {
for (int i = 0; i < script_classes.size(); i++) {
Dictionary c = script_classes[i];
- if (!c.has("class") || !c.has("language") || !c.has("path") || !c.has("base"))
+ if (!c.has("class") || !c.has("language") || !c.has("path") || !c.has("base")) {
continue;
+ }
add_global_class(c["class"], c["base"], c["language"], c["path"]);
}
}
@@ -285,8 +287,9 @@ void ScriptInstance::get_property_state(List<Pair<StringName, Variant>> &state)
if (E->get().usage & PROPERTY_USAGE_STORAGE) {
Pair<StringName, Variant> p;
p.first = E->get().name;
- if (get(p.first, p.second))
+ if (get(p.first, p.second)) {
state.push_back(p);
+ }
}
}
}
@@ -295,8 +298,9 @@ Variant ScriptInstance::call(const StringName &p_method, VARIANT_ARG_DECLARE) {
VARIANT_ARGPTRS;
int argc = 0;
for (int i = 0; i < VARIANT_ARG_MAX; i++) {
- if (argptr[i]->get_type() == Variant::NIL)
+ if (argptr[i]->get_type() == Variant::NIL) {
break;
+ }
argc++;
}
@@ -315,13 +319,15 @@ void ScriptInstance::call_multilevel_reversed(const StringName &p_method, const
}
void ScriptInstance::property_set_fallback(const StringName &, const Variant &, bool *r_valid) {
- if (r_valid)
+ if (r_valid) {
*r_valid = false;
+ }
}
Variant ScriptInstance::property_get_fallback(const StringName &, bool *r_valid) {
- if (r_valid)
+ if (r_valid) {
*r_valid = false;
+ }
return Variant();
}
@@ -329,8 +335,9 @@ void ScriptInstance::call_multilevel(const StringName &p_method, VARIANT_ARG_DEC
VARIANT_ARGPTRS;
int argc = 0;
for (int i = 0; i < VARIANT_ARG_MAX; i++) {
- if (argptr[i]->get_type() == Variant::NIL)
+ if (argptr[i]->get_type() == Variant::NIL) {
break;
+ }
argc++;
}
@@ -349,8 +356,9 @@ void ScriptLanguage::frame() {
}
bool PlaceHolderScriptInstance::set(const StringName &p_name, const Variant &p_value) {
- if (script->is_placeholder_fallback_enabled())
+ if (script->is_placeholder_fallback_enabled()) {
return false;
+ }
if (values.has(p_name)) {
Variant defval;
@@ -414,26 +422,30 @@ void PlaceHolderScriptInstance::get_property_list(List<PropertyInfo> *p_properti
Variant::Type PlaceHolderScriptInstance::get_property_type(const StringName &p_name, bool *r_is_valid) const {
if (values.has(p_name)) {
- if (r_is_valid)
+ if (r_is_valid) {
*r_is_valid = true;
+ }
return values[p_name].get_type();
}
if (constants.has(p_name)) {
- if (r_is_valid)
+ if (r_is_valid) {
*r_is_valid = true;
+ }
return constants[p_name].get_type();
}
- if (r_is_valid)
+ if (r_is_valid) {
*r_is_valid = false;
+ }
return Variant::NIL;
}
void PlaceHolderScriptInstance::get_method_list(List<MethodInfo> *p_list) const {
- if (script->is_placeholder_fallback_enabled())
+ if (script->is_placeholder_fallback_enabled()) {
return;
+ }
if (script.is_valid()) {
script->get_script_method_list(p_list);
@@ -441,8 +453,9 @@ void PlaceHolderScriptInstance::get_method_list(List<MethodInfo> *p_list) const
}
bool PlaceHolderScriptInstance::has_method(const StringName &p_method) const {
- if (script->is_placeholder_fallback_enabled())
+ if (script->is_placeholder_fallback_enabled()) {
return false;
+ }
if (script.is_valid()) {
return script->has_method(p_method);
@@ -457,8 +470,9 @@ void PlaceHolderScriptInstance::update(const List<PropertyInfo> &p_properties, c
new_values.insert(n);
if (!values.has(n) || values[n].get_type() != E->get().type) {
- if (p_values.has(n))
+ if (p_values.has(n)) {
values[n] = p_values[n];
+ }
}
}
@@ -466,8 +480,9 @@ void PlaceHolderScriptInstance::update(const List<PropertyInfo> &p_properties, c
List<StringName> to_remove;
for (Map<StringName, Variant>::Element *E = values.front(); E; E = E->next()) {
- if (!new_values.has(E->key()))
+ if (!new_values.has(E->key())) {
to_remove.push_back(E->key());
+ }
Variant defval;
if (script->get_property_default_value(E->key(), defval)) {
@@ -514,8 +529,9 @@ void PlaceHolderScriptInstance::property_set_fallback(const StringName &p_name,
}
}
- if (r_valid)
+ if (r_valid) {
*r_valid = false; // Cannot change the value in either case
+ }
}
Variant PlaceHolderScriptInstance::property_get_fallback(const StringName &p_name, bool *r_valid) {
@@ -523,21 +539,24 @@ Variant PlaceHolderScriptInstance::property_get_fallback(const StringName &p_nam
const Map<StringName, Variant>::Element *E = values.find(p_name);
if (E) {
- if (r_valid)
+ if (r_valid) {
*r_valid = true;
+ }
return E->value();
}
E = constants.find(p_name);
if (E) {
- if (r_valid)
+ if (r_valid) {
*r_valid = true;
+ }
return E->value();
}
}
- if (r_valid)
+ if (r_valid) {
*r_valid = false;
+ }
return Variant();
}
diff --git a/core/script_language.h b/core/script_language.h
index 602ac42b2f..b6c2a47245 100644
--- a/core/script_language.h
+++ b/core/script_language.h
@@ -204,8 +204,9 @@ public:
virtual void call_multilevel_reversed(const StringName &p_method, const Variant **p_args, int p_argcount);
virtual void notification(int p_notification) = 0;
virtual String to_string(bool *r_valid) {
- if (r_valid)
+ if (r_valid) {
*r_valid = false;
+ }
return String();
}
diff --git a/core/self_list.h b/core/self_list.h
index c70d2a8c0a..3104bcb714 100644
--- a/core/self_list.h
+++ b/core/self_list.h
@@ -115,8 +115,9 @@ private:
public:
_FORCE_INLINE_ bool in_list() const { return _root; }
_FORCE_INLINE_ void remove_from_list() {
- if (_root)
+ if (_root) {
_root->remove(this);
+ }
}
_FORCE_INLINE_ SelfList<T> *next() { return _next; }
_FORCE_INLINE_ SelfList<T> *prev() { return _prev; }
@@ -129,8 +130,9 @@ public:
}
_FORCE_INLINE_ ~SelfList() {
- if (_root)
+ if (_root) {
_root->remove(this);
+ }
}
};
diff --git a/core/set.h b/core/set.h
index 88eccc7ea8..1bc0a3f41e 100644
--- a/core/set.h
+++ b/core/set.h
@@ -125,13 +125,15 @@ private:
inline void _rotate_left(Element *p_node) {
Element *r = p_node->right;
p_node->right = r->left;
- if (r->left != _data._nil)
+ if (r->left != _data._nil) {
r->left->parent = p_node;
+ }
r->parent = p_node->parent;
- if (p_node == p_node->parent->left)
+ if (p_node == p_node->parent->left) {
p_node->parent->left = r;
- else
+ } else {
p_node->parent->right = r;
+ }
r->left = p_node;
p_node->parent = r;
@@ -140,13 +142,15 @@ private:
inline void _rotate_right(Element *p_node) {
Element *l = p_node->left;
p_node->left = l->right;
- if (l->right != _data._nil)
+ if (l->right != _data._nil) {
l->right->parent = p_node;
+ }
l->parent = p_node->parent;
- if (p_node == p_node->parent->right)
+ if (p_node == p_node->parent->right) {
p_node->parent->right = l;
- else
+ } else {
p_node->parent->left = l;
+ }
l->right = p_node;
p_node->parent = l;
@@ -166,8 +170,9 @@ private:
node = node->parent;
}
- if (node->parent == _data._root)
+ if (node->parent == _data._root) {
return nullptr; // No successor, as p_node = last node
+ }
return node->parent;
}
}
@@ -186,8 +191,9 @@ private:
node = node->parent;
}
- if (node == _data._root)
+ if (node == _data._root) {
return nullptr; // No predecessor, as p_node = first node.
+ }
return node->parent;
}
}
@@ -197,12 +203,13 @@ private:
C less;
while (node != _data._nil) {
- if (less(p_value, node->value))
+ if (less(p_value, node->value)) {
node = node->left;
- else if (less(node->value, p_value))
+ } else if (less(node->value, p_value)) {
node = node->right;
- else
+ } else {
return node; // found
+ }
}
return nullptr;
@@ -216,19 +223,22 @@ private:
while (node != _data._nil) {
prev = node;
- if (less(p_value, node->value))
+ if (less(p_value, node->value)) {
node = node->left;
- else if (less(node->value, p_value))
+ } else if (less(node->value, p_value)) {
node = node->right;
- else
+ } else {
return node; // found
+ }
}
- if (prev == nullptr)
+ if (prev == nullptr) {
return nullptr; // tree empty
+ }
- if (less(prev->value, p_value))
+ if (less(prev->value, p_value)) {
prev = prev->_next;
+ }
return prev;
}
@@ -289,11 +299,11 @@ private:
while (node != _data._nil) {
new_parent = node;
- if (less(p_value, node->value))
+ if (less(p_value, node->value)) {
node = node->left;
- else if (less(node->value, p_value))
+ } else if (less(node->value, p_value)) {
node = node->right;
- else {
+ } else {
return node; // Return existing node
}
}
@@ -313,10 +323,12 @@ private:
new_node->_next = _successor(new_node);
new_node->_prev = _predecessor(new_node);
- if (new_node->_next)
+ if (new_node->_next) {
new_node->_next->_prev = new_node;
- if (new_node->_prev)
+ }
+ if (new_node->_prev) {
new_node->_prev->_next = new_node;
+ }
_data.size_cache++;
_insert_rb_fix(new_node);
@@ -411,10 +423,12 @@ private:
rp->right = p_node->right;
rp->parent = p_node->parent;
rp->color = p_node->color;
- if (p_node->left != _data._nil)
+ if (p_node->left != _data._nil) {
p_node->left->parent = rp;
- if (p_node->right != _data._nil)
+ }
+ if (p_node->right != _data._nil) {
p_node->right->parent = rp;
+ }
if (p_node == p_node->parent->left) {
p_node->parent->left = rp;
@@ -423,10 +437,12 @@ private:
}
}
- if (p_node->_next)
+ if (p_node->_next) {
p_node->_next->_prev = p_node->_prev;
- if (p_node->_prev)
+ }
+ if (p_node->_prev) {
p_node->_prev->_next = p_node->_next;
+ }
memdelete_allocator<Element, A>(p_node);
_data.size_cache--;
@@ -434,19 +450,22 @@ private:
}
void _calculate_depth(Element *p_element, int &max_d, int d) const {
- if (p_element == _data._nil)
+ if (p_element == _data._nil) {
return;
+ }
_calculate_depth(p_element->left, max_d, d + 1);
_calculate_depth(p_element->right, max_d, d + 1);
- if (d > max_d)
+ if (d > max_d) {
max_d = d;
+ }
}
void _cleanup_tree(Element *p_element) {
- if (p_element == _data._nil)
+ if (p_element == _data._nil) {
return;
+ }
_cleanup_tree(p_element->left);
_cleanup_tree(p_element->right);
@@ -463,16 +482,18 @@ private:
public:
const Element *find(const T &p_value) const {
- if (!_data._root)
+ if (!_data._root) {
return nullptr;
+ }
const Element *res = _find(p_value);
return res;
}
Element *find(const T &p_value) {
- if (!_data._root)
+ if (!_data._root) {
return nullptr;
+ }
Element *res = _find(p_value);
return res;
@@ -487,58 +508,70 @@ public:
}
Element *insert(const T &p_value) {
- if (!_data._root)
+ if (!_data._root) {
_data._create_root();
+ }
return _insert(p_value);
}
void erase(Element *p_element) {
- if (!_data._root || !p_element)
+ if (!_data._root || !p_element) {
return;
+ }
_erase(p_element);
- if (_data.size_cache == 0 && _data._root)
+ if (_data.size_cache == 0 && _data._root) {
_data._free_root();
+ }
}
bool erase(const T &p_value) {
- if (!_data._root)
+ if (!_data._root) {
return false;
+ }
Element *e = find(p_value);
- if (!e)
+ if (!e) {
return false;
+ }
_erase(e);
- if (_data.size_cache == 0 && _data._root)
+ if (_data.size_cache == 0 && _data._root) {
_data._free_root();
+ }
return true;
}
Element *front() const {
- if (!_data._root)
+ if (!_data._root) {
return nullptr;
+ }
Element *e = _data._root->left;
- if (e == _data._nil)
+ if (e == _data._nil) {
return nullptr;
+ }
- while (e->left != _data._nil)
+ while (e->left != _data._nil) {
e = e->left;
+ }
return e;
}
Element *back() const {
- if (!_data._root)
+ if (!_data._root) {
return nullptr;
+ }
Element *e = _data._root->left;
- if (e == _data._nil)
+ if (e == _data._nil) {
return nullptr;
+ }
- while (e->right != _data._nil)
+ while (e->right != _data._nil) {
e = e->right;
+ }
return e;
}
@@ -548,8 +581,9 @@ public:
int calculate_depth() const {
// used for debug mostly
- if (!_data._root)
+ if (!_data._root) {
return 0;
+ }
int max_d = 0;
_calculate_depth(_data._root->left, max_d, 0);
@@ -557,8 +591,9 @@ public:
}
void clear() {
- if (!_data._root)
+ if (!_data._root) {
return;
+ }
_cleanup_tree(_data._root->left);
_data._root->left = _data._nil;
diff --git a/core/sort_array.h b/core/sort_array.h
index 2dd7c20eae..93cc6f727d 100644
--- a/core/sort_array.h
+++ b/core/sort_array.h
@@ -62,25 +62,28 @@ public:
Comparator compare;
inline const T &median_of_3(const T &a, const T &b, const T &c) const {
- if (compare(a, b))
- if (compare(b, c))
+ if (compare(a, b)) {
+ if (compare(b, c)) {
return b;
- else if (compare(a, c))
+ } else if (compare(a, c)) {
return c;
- else
+ } else {
return a;
- else if (compare(a, c))
+ }
+ } else if (compare(a, c)) {
return a;
- else if (compare(b, c))
+ } else if (compare(b, c)) {
return c;
- else
+ } else {
return b;
+ }
}
inline int bitlog(int n) const {
int k;
- for (k = 0; n != 1; n >>= 1)
+ for (k = 0; n != 1; n >>= 1) {
++k;
+ }
return k;
}
@@ -109,8 +112,9 @@ public:
int second_child = 2 * p_hole_idx + 2;
while (second_child < p_len) {
- if (compare(p_array[p_first + second_child], p_array[p_first + (second_child - 1)]))
+ if (compare(p_array[p_first + second_child], p_array[p_first + (second_child - 1)])) {
second_child--;
+ }
p_array[p_first + p_hole_idx] = p_array[p_first + second_child];
p_hole_idx = second_child;
@@ -131,32 +135,38 @@ public:
}
inline void make_heap(int p_first, int p_last, T *p_array) const {
- if (p_last - p_first < 2)
+ if (p_last - p_first < 2) {
return;
+ }
int len = p_last - p_first;
int parent = (len - 2) / 2;
while (true) {
adjust_heap(p_first, parent, len, p_array[p_first + parent], p_array);
- if (parent == 0)
+ if (parent == 0) {
return;
+ }
parent--;
}
}
inline void partial_sort(int p_first, int p_last, int p_middle, T *p_array) const {
make_heap(p_first, p_middle, p_array);
- for (int i = p_middle; i < p_last; i++)
- if (compare(p_array[i], p_array[p_first]))
+ for (int i = p_middle; i < p_last; i++) {
+ if (compare(p_array[i], p_array[p_first])) {
pop_heap(p_first, p_middle, i, p_array[i], p_array);
+ }
+ }
sort_heap(p_first, p_middle, p_array);
}
inline void partial_select(int p_first, int p_last, int p_middle, T *p_array) const {
make_heap(p_first, p_middle, p_array);
- for (int i = p_middle; i < p_last; i++)
- if (compare(p_array[i], p_array[p_first]))
+ for (int i = p_middle; i < p_last; i++) {
+ if (compare(p_array[i], p_array[p_first])) {
pop_heap(p_first, p_middle, i, p_array[i], p_array);
+ }
+ }
}
inline int partitioner(int p_first, int p_last, T p_pivot, T *p_array) const {
@@ -178,8 +188,9 @@ public:
p_last--;
}
- if (!(p_first < p_last))
+ if (!(p_first < p_last)) {
return p_first;
+ }
SWAP(p_array[p_first], p_array[p_last]);
p_first++;
@@ -228,10 +239,11 @@ public:
p_array[p_last - 1]),
p_array);
- if (cut <= p_nth)
+ if (cut <= p_nth) {
p_first = cut;
- else
+ } else {
p_last = cut;
+ }
}
insertion_sort(p_first, p_last, p_array);
@@ -253,24 +265,29 @@ public:
inline void linear_insert(int p_first, int p_last, T *p_array) const {
T val = p_array[p_last];
if (compare(val, p_array[p_first])) {
- for (int i = p_last; i > p_first; i--)
+ for (int i = p_last; i > p_first; i--) {
p_array[i] = p_array[i - 1];
+ }
p_array[p_first] = val;
- } else
+ } else {
unguarded_linear_insert(p_last, val, p_array);
+ }
}
inline void insertion_sort(int p_first, int p_last, T *p_array) const {
- if (p_first == p_last)
+ if (p_first == p_last) {
return;
- for (int i = p_first + 1; i != p_last; i++)
+ }
+ for (int i = p_first + 1; i != p_last; i++) {
linear_insert(p_first, i, p_array);
+ }
}
inline void unguarded_insertion_sort(int p_first, int p_last, T *p_array) const {
- for (int i = p_first; i != p_last; i++)
+ for (int i = p_first; i != p_last; i++) {
unguarded_linear_insert(i, p_array[i], p_array);
+ }
}
inline void final_insertion_sort(int p_first, int p_last, T *p_array) const {
@@ -294,8 +311,9 @@ public:
}
inline void nth_element(int p_first, int p_last, int p_nth, T *p_array) const {
- if (p_first == p_last || p_nth == p_last)
+ if (p_first == p_last || p_nth == p_last) {
return;
+ }
introselect(p_first, p_nth, p_last, p_array, bitlog(p_last - p_first) * 2);
}
};
diff --git a/core/string_buffer.h b/core/string_buffer.h
index 0f0b572efb..956a6333d9 100644
--- a/core/string_buffer.h
+++ b/core/string_buffer.h
@@ -118,8 +118,9 @@ StringBuffer<SHORT_BUFFER_SIZE> &StringBuffer<SHORT_BUFFER_SIZE>::append(const C
template <int SHORT_BUFFER_SIZE>
StringBuffer<SHORT_BUFFER_SIZE> &StringBuffer<SHORT_BUFFER_SIZE>::reserve(int p_size) {
- if (p_size < SHORT_BUFFER_SIZE || p_size < buffer.size())
+ if (p_size < SHORT_BUFFER_SIZE || p_size < buffer.size()) {
return *this;
+ }
bool need_copy = string_length > 0 && buffer.empty();
buffer.resize(next_power_of_2(p_size));
diff --git a/core/string_builder.cpp b/core/string_builder.cpp
index 6b105611f0..c8d6498f27 100644
--- a/core/string_builder.cpp
+++ b/core/string_builder.cpp
@@ -33,8 +33,9 @@
#include <string.h>
StringBuilder &StringBuilder::append(const String &p_string) {
- if (p_string == String())
+ if (p_string == String()) {
return *this;
+ }
strings.push_back(p_string);
appended_strings.push_back(-1);
@@ -56,8 +57,9 @@ StringBuilder &StringBuilder::append(const char *p_cstring) {
}
String StringBuilder::as_string() const {
- if (string_length == 0)
+ if (string_length == 0) {
return "";
+ }
CharType *buffer = memnew_arr(CharType, string_length);
diff --git a/core/string_name.cpp b/core/string_name.cpp
index 7f2da6151e..cbf6009681 100644
--- a/core/string_name.cpp
+++ b/core/string_name.cpp
@@ -132,8 +132,9 @@ bool StringName::operator!=(const StringName &p_name) const {
}
void StringName::operator=(const StringName &p_name) {
- if (this == &p_name)
+ if (this == &p_name) {
return;
+ }
unref();
@@ -157,8 +158,9 @@ StringName::StringName(const char *p_name) {
ERR_FAIL_COND(!configured);
- if (!p_name || p_name[0] == 0)
+ if (!p_name || p_name[0] == 0) {
return; //empty, ignore
+ }
MutexLock lock(mutex);
@@ -170,8 +172,9 @@ StringName::StringName(const char *p_name) {
while (_data) {
// compare hash first
- if (_data->hash == hash && _data->get_name() == p_name)
+ if (_data->hash == hash && _data->get_name() == p_name) {
break;
+ }
_data = _data->next;
}
@@ -190,8 +193,9 @@ StringName::StringName(const char *p_name) {
_data->cname = nullptr;
_data->next = _table[idx];
_data->prev = nullptr;
- if (_table[idx])
+ if (_table[idx]) {
_table[idx]->prev = _data;
+ }
_table[idx] = _data;
}
@@ -212,8 +216,9 @@ StringName::StringName(const StaticCString &p_static_string) {
while (_data) {
// compare hash first
- if (_data->hash == hash && _data->get_name() == p_static_string.ptr)
+ if (_data->hash == hash && _data->get_name() == p_static_string.ptr) {
break;
+ }
_data = _data->next;
}
@@ -232,8 +237,9 @@ StringName::StringName(const StaticCString &p_static_string) {
_data->cname = p_static_string.ptr;
_data->next = _table[idx];
_data->prev = nullptr;
- if (_table[idx])
+ if (_table[idx]) {
_table[idx]->prev = _data;
+ }
_table[idx] = _data;
}
@@ -242,8 +248,9 @@ StringName::StringName(const String &p_name) {
ERR_FAIL_COND(!configured);
- if (p_name == String())
+ if (p_name == String()) {
return;
+ }
MutexLock lock(mutex);
@@ -253,8 +260,9 @@ StringName::StringName(const String &p_name) {
_data = _table[idx];
while (_data) {
- if (_data->hash == hash && _data->get_name() == p_name)
+ if (_data->hash == hash && _data->get_name() == p_name) {
break;
+ }
_data = _data->next;
}
@@ -273,8 +281,9 @@ StringName::StringName(const String &p_name) {
_data->cname = nullptr;
_data->next = _table[idx];
_data->prev = nullptr;
- if (_table[idx])
+ if (_table[idx]) {
_table[idx]->prev = _data;
+ }
_table[idx] = _data;
}
@@ -282,8 +291,9 @@ StringName StringName::search(const char *p_name) {
ERR_FAIL_COND_V(!configured, StringName());
ERR_FAIL_COND_V(!p_name, StringName());
- if (!p_name[0])
+ if (!p_name[0]) {
return StringName();
+ }
MutexLock lock(mutex);
@@ -294,8 +304,9 @@ StringName StringName::search(const char *p_name) {
while (_data) {
// compare hash first
- if (_data->hash == hash && _data->get_name() == p_name)
+ if (_data->hash == hash && _data->get_name() == p_name) {
break;
+ }
_data = _data->next;
}
@@ -310,8 +321,9 @@ StringName StringName::search(const CharType *p_name) {
ERR_FAIL_COND_V(!configured, StringName());
ERR_FAIL_COND_V(!p_name, StringName());
- if (!p_name[0])
+ if (!p_name[0]) {
return StringName();
+ }
MutexLock lock(mutex);
@@ -323,8 +335,9 @@ StringName StringName::search(const CharType *p_name) {
while (_data) {
// compare hash first
- if (_data->hash == hash && _data->get_name() == p_name)
+ if (_data->hash == hash && _data->get_name() == p_name) {
break;
+ }
_data = _data->next;
}
@@ -348,8 +361,9 @@ StringName StringName::search(const String &p_name) {
while (_data) {
// compare hash first
- if (_data->hash == hash && p_name == _data->get_name())
+ if (_data->hash == hash && p_name == _data->get_name()) {
break;
+ }
_data = _data->next;
}
diff --git a/core/string_name.h b/core/string_name.h
index 0517696ab1..df6b458581 100644
--- a/core/string_name.h
+++ b/core/string_name.h
@@ -96,10 +96,11 @@ public:
return _data == p_name._data;
}
_FORCE_INLINE_ uint32_t hash() const {
- if (_data)
+ if (_data) {
return _data->hash;
- else
+ } else {
return 0;
+ }
}
_FORCE_INLINE_ const void *data_unique_pointer() const {
return (void *)_data;
@@ -108,10 +109,11 @@ public:
_FORCE_INLINE_ operator String() const {
if (_data) {
- if (_data->cname)
+ if (_data->cname) {
return String(_data->cname);
- else
+ } else {
return _data->name;
+ }
}
return String();
@@ -127,15 +129,17 @@ public:
const char *r_cname = r._data ? r._data->cname : "";
if (l_cname) {
- if (r_cname)
+ if (r_cname) {
return is_str_less(l_cname, r_cname);
- else
+ } else {
return is_str_less(l_cname, r._data->name.ptr());
+ }
} else {
- if (r_cname)
+ if (r_cname) {
return is_str_less(l._data->name.ptr(), r_cname);
- else
+ } else {
return is_str_less(l._data->name.ptr(), r._data->name.ptr());
+ }
}
}
};
diff --git a/core/translation.cpp b/core/translation.cpp
index 2eaccc6c4e..f3c1489ce4 100644
--- a/core/translation.cpp
+++ b/core/translation.cpp
@@ -854,8 +854,9 @@ void Translation::add_message(const StringName &p_src_text, const StringName &p_
StringName Translation::get_message(const StringName &p_src_text) const {
const Map<StringName, StringName>::Element *E = translation_map.find(p_src_text);
- if (!E)
+ if (!E) {
return StringName();
+ }
return E->get();
}
@@ -895,8 +896,9 @@ bool TranslationServer::is_locale_valid(const String &p_locale) {
const char **ptr = locale_list;
while (*ptr) {
- if (*ptr == p_locale)
+ if (*ptr == p_locale) {
return true;
+ }
ptr++;
}
@@ -965,8 +967,9 @@ String TranslationServer::get_locale() const {
}
String TranslationServer::get_locale_name(const String &p_locale) const {
- if (!locale_name_map.has(p_locale))
+ if (!locale_name_map.has(p_locale)) {
return String();
+ }
return locale_name_map[p_locale];
}
@@ -1024,8 +1027,9 @@ void TranslationServer::clear() {
StringName TranslationServer::translate(const StringName &p_message) const {
// Match given message against the translation catalog for the project locale.
- if (!enabled)
+ if (!enabled) {
return p_message;
+ }
ERR_FAIL_COND_V_MSG(locale.length() < 2, p_message, "Could not translate message as configured locale '" + locale + "' is invalid.");
@@ -1125,8 +1129,9 @@ bool TranslationServer::_load_translations(const String &p_from) {
for (int i = 0; i < tcount; i++) {
Ref<Translation> tr = ResourceLoader::load(r[i]);
- if (tr.is_valid())
+ if (tr.is_valid()) {
add_translation(tr);
+ }
}
}
return true;
@@ -1138,18 +1143,20 @@ bool TranslationServer::_load_translations(const String &p_from) {
void TranslationServer::setup() {
String test = GLOBAL_DEF("locale/test", "");
test = test.strip_edges();
- if (test != "")
+ if (test != "") {
set_locale(test);
- else
+ } else {
set_locale(OS::get_singleton()->get_locale());
+ }
fallback = GLOBAL_DEF("locale/fallback", "en");
#ifdef TOOLS_ENABLED
{
String options = "";
int idx = 0;
while (locale_list[idx]) {
- if (idx > 0)
+ if (idx > 0) {
options += ",";
+ }
options += locale_list[idx];
idx++;
}
diff --git a/core/type_info.h b/core/type_info.h
index afc0dd2107..e3d2b5bd53 100644
--- a/core/type_info.h
+++ b/core/type_info.h
@@ -258,8 +258,9 @@ struct GetTypeInfo<const T *, typename EnableIf<TypeInherits<Object, T>::value>:
template <typename T>
inline StringName __constant_get_enum_name(T param, const String &p_constant) {
- if (GetTypeInfo<T>::VARIANT_TYPE == Variant::NIL)
+ if (GetTypeInfo<T>::VARIANT_TYPE == Variant::NIL) {
ERR_PRINT("Missing VARIANT_ENUM_CAST for constant's enum: " + p_constant);
+ }
return GetTypeInfo<T>::get_class_info().class_name;
}
diff --git a/core/typedefs.h b/core/typedefs.h
index bafbffcded..4bfa5debac 100644
--- a/core/typedefs.h
+++ b/core/typedefs.h
@@ -185,8 +185,9 @@ static _FORCE_INLINE_ T nearest_power_of_2_templated(T x) {
// Function to find the nearest (bigger) power of 2 to an integer.
static inline unsigned int nearest_shift(unsigned int p_number) {
for (int i = 30; i >= 0; i--) {
- if (p_number & (1 << i))
+ if (p_number & (1 << i)) {
return i + 1;
+ }
}
return 0;
diff --git a/core/undo_redo.cpp b/core/undo_redo.cpp
index d1a71a6b64..90750f2c6e 100644
--- a/core/undo_redo.cpp
+++ b/core/undo_redo.cpp
@@ -33,15 +33,17 @@
#include "core/os/os.h"
void UndoRedo::_discard_redo() {
- if (current_action == actions.size() - 1)
+ if (current_action == actions.size() - 1) {
return;
+ }
for (int i = current_action + 1; i < actions.size(); i++) {
for (List<Operation>::Element *E = actions.write[i].do_ops.front(); E; E = E->next()) {
if (E->get().type == Operation::TYPE_REFERENCE) {
Object *obj = ObjectDB::get_instance(E->get().object);
- if (obj)
+ if (obj) {
memdelete(obj);
+ }
}
}
//ERASE do data
@@ -68,8 +70,9 @@ void UndoRedo::create_action(const String &p_name, MergeMode p_mode) {
if (E->get().type == Operation::TYPE_REFERENCE) {
Object *obj = ObjectDB::get_instance(E->get().object);
- if (obj)
+ if (obj) {
memdelete(obj);
+ }
}
E = E->next();
@@ -101,8 +104,9 @@ void UndoRedo::add_do_method(Object *p_object, const StringName &p_method, VARIA
ERR_FAIL_COND((current_action + 1) >= actions.size());
Operation do_op;
do_op.object = p_object->get_instance_id();
- if (Object::cast_to<Resource>(p_object))
+ if (Object::cast_to<Resource>(p_object)) {
do_op.resref = Ref<Resource>(Object::cast_to<Resource>(p_object));
+ }
do_op.type = Operation::TYPE_METHOD;
do_op.name = p_method;
@@ -120,13 +124,15 @@ void UndoRedo::add_undo_method(Object *p_object, const StringName &p_method, VAR
ERR_FAIL_COND((current_action + 1) >= actions.size());
// No undo if the merge mode is MERGE_ENDS
- if (merge_mode == MERGE_ENDS)
+ if (merge_mode == MERGE_ENDS) {
return;
+ }
Operation undo_op;
undo_op.object = p_object->get_instance_id();
- if (Object::cast_to<Resource>(p_object))
+ if (Object::cast_to<Resource>(p_object)) {
undo_op.resref = Ref<Resource>(Object::cast_to<Resource>(p_object));
+ }
undo_op.type = Operation::TYPE_METHOD;
undo_op.name = p_method;
@@ -143,8 +149,9 @@ void UndoRedo::add_do_property(Object *p_object, const StringName &p_property, c
ERR_FAIL_COND((current_action + 1) >= actions.size());
Operation do_op;
do_op.object = p_object->get_instance_id();
- if (Object::cast_to<Resource>(p_object))
+ if (Object::cast_to<Resource>(p_object)) {
do_op.resref = Ref<Resource>(Object::cast_to<Resource>(p_object));
+ }
do_op.type = Operation::TYPE_PROPERTY;
do_op.name = p_property;
@@ -158,13 +165,15 @@ void UndoRedo::add_undo_property(Object *p_object, const StringName &p_property,
ERR_FAIL_COND((current_action + 1) >= actions.size());
// No undo if the merge mode is MERGE_ENDS
- if (merge_mode == MERGE_ENDS)
+ if (merge_mode == MERGE_ENDS) {
return;
+ }
Operation undo_op;
undo_op.object = p_object->get_instance_id();
- if (Object::cast_to<Resource>(p_object))
+ if (Object::cast_to<Resource>(p_object)) {
undo_op.resref = Ref<Resource>(Object::cast_to<Resource>(p_object));
+ }
undo_op.type = Operation::TYPE_PROPERTY;
undo_op.name = p_property;
@@ -178,8 +187,9 @@ void UndoRedo::add_do_reference(Object *p_object) {
ERR_FAIL_COND((current_action + 1) >= actions.size());
Operation do_op;
do_op.object = p_object->get_instance_id();
- if (Object::cast_to<Resource>(p_object))
+ if (Object::cast_to<Resource>(p_object)) {
do_op.resref = Ref<Resource>(Object::cast_to<Resource>(p_object));
+ }
do_op.type = Operation::TYPE_REFERENCE;
actions.write[current_action + 1].do_ops.push_back(do_op);
@@ -191,13 +201,15 @@ void UndoRedo::add_undo_reference(Object *p_object) {
ERR_FAIL_COND((current_action + 1) >= actions.size());
// No undo if the merge mode is MERGE_ENDS
- if (merge_mode == MERGE_ENDS)
+ if (merge_mode == MERGE_ENDS) {
return;
+ }
Operation undo_op;
undo_op.object = p_object->get_instance_id();
- if (Object::cast_to<Resource>(p_object))
+ if (Object::cast_to<Resource>(p_object)) {
undo_op.resref = Ref<Resource>(Object::cast_to<Resource>(p_object));
+ }
undo_op.type = Operation::TYPE_REFERENCE;
actions.write[current_action + 1].undo_ops.push_back(undo_op);
@@ -206,14 +218,16 @@ void UndoRedo::add_undo_reference(Object *p_object) {
void UndoRedo::_pop_history_tail() {
_discard_redo();
- if (!actions.size())
+ if (!actions.size()) {
return;
+ }
for (List<Operation>::Element *E = actions.write[0].undo_ops.front(); E; E = E->next()) {
if (E->get().type == Operation::TYPE_REFERENCE) {
Object *obj = ObjectDB::get_instance(E->get().object);
- if (obj)
+ if (obj) {
memdelete(obj);
+ }
}
}
@@ -230,8 +244,9 @@ bool UndoRedo::is_committing_action() const {
void UndoRedo::commit_action() {
ERR_FAIL_COND(action_level <= 0);
action_level--;
- if (action_level > 0)
+ if (action_level > 0) {
return; //still nested
+ }
if (merging) {
version--;
@@ -251,8 +266,9 @@ void UndoRedo::_process_operation_list(List<Operation>::Element *E) {
Operation &op = E->get();
Object *obj = ObjectDB::get_instance(op.object);
- if (!obj) //may have been deleted and this is fine
+ if (!obj) { //may have been deleted and this is fine
continue;
+ }
switch (op.type) {
case Operation::TYPE_METHOD: {
@@ -276,8 +292,9 @@ void UndoRedo::_process_operation_list(List<Operation>::Element *E) {
}
#ifdef TOOLS_ENABLED
Resource *res = Object::cast_to<Resource>(obj);
- if (res)
+ if (res) {
res->set_edited(true);
+ }
#endif
@@ -289,8 +306,9 @@ void UndoRedo::_process_operation_list(List<Operation>::Element *E) {
obj->set(op.name, op.args[0]);
#ifdef TOOLS_ENABLED
Resource *res = Object::cast_to<Resource>(obj);
- if (res)
+ if (res) {
res->set_edited(true);
+ }
#endif
if (property_callback) {
property_callback(prop_callback_ud, obj, op.name, op.args[0]);
@@ -306,8 +324,9 @@ void UndoRedo::_process_operation_list(List<Operation>::Element *E) {
bool UndoRedo::redo() {
ERR_FAIL_COND_V(action_level > 0, false);
- if ((current_action + 1) >= actions.size())
+ if ((current_action + 1) >= actions.size()) {
return false; //nothing to redo
+ }
current_action++;
@@ -320,8 +339,9 @@ bool UndoRedo::redo() {
bool UndoRedo::undo() {
ERR_FAIL_COND_V(action_level > 0, false);
- if (current_action < 0)
+ if (current_action < 0) {
return false; //nothing to redo
+ }
_process_operation_list(actions.write[current_action].undo_ops.front());
current_action--;
version--;
@@ -334,8 +354,9 @@ void UndoRedo::clear_history(bool p_increase_version) {
ERR_FAIL_COND(action_level > 0);
_discard_redo();
- while (actions.size())
+ while (actions.size()) {
_pop_history_tail();
+ }
if (p_increase_version) {
version++;
@@ -345,8 +366,9 @@ void UndoRedo::clear_history(bool p_increase_version) {
String UndoRedo::get_current_action_name() const {
ERR_FAIL_COND_V(action_level > 0, "");
- if (current_action < 0)
+ if (current_action < 0) {
return "";
+ }
return actions[current_action].name;
}
diff --git a/core/ustring.cpp b/core/ustring.cpp
index a1a2280066..ed096bd475 100644
--- a/core/ustring.cpp
+++ b/core/ustring.cpp
@@ -83,8 +83,9 @@ bool select_word(const String &p_s, int p_col, int &r_beg, int &r_end) {
end++;
}
- if (end < s.length())
+ if (end < s.length()) {
end += 1;
+ }
r_beg = beg;
r_end = end;
@@ -114,10 +115,11 @@ CharString &CharString::operator+=(char p_char) {
}
const char *CharString::get_data() const {
- if (size())
+ if (size()) {
return &operator[](0);
- else
+ } else {
return "";
+ }
}
CharString &CharString::operator=(const char *p_cstr) {
@@ -153,8 +155,9 @@ void String::copy_from(const char *p_cstr) {
int len = 0;
const char *ptr = p_cstr;
- while (*(ptr++) != 0)
+ while (*(ptr++) != 0) {
len++;
+ }
if (len == 0) {
resize(0);
@@ -178,8 +181,9 @@ void String::copy_from(const CharType *p_cstr, const int p_clip_to) {
int len = 0;
const CharType *ptr = p_cstr;
- while ((p_clip_to < 0 || len < p_clip_to) && *(ptr++) != 0)
+ while ((p_clip_to < 0 || len < p_clip_to) && *(ptr++) != 0) {
len++;
+ }
if (len == 0) {
resize(0);
@@ -211,10 +215,12 @@ void String::copy_from(const CharType &p_char) {
}
bool String::operator==(const String &p_str) const {
- if (length() != p_str.length())
+ if (length() != p_str.length()) {
return false;
- if (empty())
+ }
+ if (empty()) {
return true;
+ }
int l = length();
@@ -223,8 +229,9 @@ bool String::operator==(const String &p_str) const {
/* Compare char by char */
for (int i = 0; i < l; i++) {
- if (src[i] != dst[i])
+ if (src[i] != dst[i]) {
return false;
+ }
}
return true;
@@ -255,8 +262,9 @@ String &String::operator+=(const String &p_str) {
return *this;
}
- if (p_str.empty())
+ if (p_str.empty()) {
return *this;
+ }
int from = length();
@@ -267,8 +275,9 @@ String &String::operator+=(const String &p_str) {
set(length(), 0);
- for (int i = 0; i < p_str.length(); i++)
+ for (int i = 0; i < p_str.length(); i++) {
dst[from + i] = src[i];
+ }
return *this;
}
@@ -287,13 +296,15 @@ String &String::operator+=(CharType p_char) {
}
String &String::operator+=(const char *p_str) {
- if (!p_str || p_str[0] == 0)
+ if (!p_str || p_str[0] == 0) {
return *this;
+ }
int src_len = 0;
const char *ptr = p_str;
- while (*(ptr++) != 0)
+ while (*(ptr++) != 0) {
src_len++;
+ }
int from = length();
@@ -303,8 +314,9 @@ String &String::operator+=(const char *p_str) {
set(length(), 0);
- for (int i = 0; i < src_len; i++)
+ for (int i = 0; i < src_len; i++) {
dst[from + i] = p_str[i];
+ }
return *this;
}
@@ -320,18 +332,21 @@ void String::operator=(const CharType *p_str) {
bool String::operator==(const StrRange &p_str_range) const {
int len = p_str_range.len;
- if (length() != len)
+ if (length() != len) {
return false;
- if (empty())
+ }
+ if (empty()) {
return true;
+ }
const CharType *c_str = p_str_range.c_str;
const CharType *dst = &operator[](0);
/* Compare char by char */
for (int i = 0; i < len; i++) {
- if (c_str[i] != dst[i])
+ if (c_str[i] != dst[i]) {
return false;
+ }
}
return true;
@@ -341,13 +356,16 @@ bool String::operator==(const char *p_str) const {
int len = 0;
const char *aux = p_str;
- while (*(aux++) != 0)
+ while (*(aux++) != 0) {
len++;
+ }
- if (length() != len)
+ if (length() != len) {
return false;
- if (empty())
+ }
+ if (empty()) {
return true;
+ }
int l = length();
@@ -355,8 +373,9 @@ bool String::operator==(const char *p_str) const {
/* Compare char by char */
for (int i = 0; i < l; i++) {
- if (p_str[i] != dst[i])
+ if (p_str[i] != dst[i]) {
return false;
+ }
}
return true;
@@ -366,13 +385,16 @@ bool String::operator==(const CharType *p_str) const {
int len = 0;
const CharType *aux = p_str;
- while (*(aux++) != 0)
+ while (*(aux++) != 0) {
len++;
+ }
- if (length() != len)
+ if (length() != len) {
return false;
- if (empty())
+ }
+ if (empty()) {
return true;
+ }
int l = length();
@@ -380,8 +402,9 @@ bool String::operator==(const CharType *p_str) const {
/* Compare char by char */
for (int i = 0; i < l; i++) {
- if (p_str[i] != dst[i])
+ if (p_str[i] != dst[i]) {
return false;
+ }
}
return true;
@@ -396,10 +419,12 @@ bool String::operator!=(const CharType *p_str) const {
}
bool String::operator<(const CharType *p_str) const {
- if (empty() && p_str[0] == 0)
+ if (empty() && p_str[0] == 0) {
return false;
- if (empty())
+ }
+ if (empty()) {
return true;
+ }
return is_str_less(c_str(), p_str);
}
@@ -409,10 +434,12 @@ bool String::operator<=(const String &p_str) const {
}
bool String::operator<(const char *p_str) const {
- if (empty() && p_str[0] == 0)
+ if (empty() && p_str[0] == 0) {
return false;
- if (empty())
+ }
+ if (empty()) {
return true;
+ }
return is_str_less(c_str(), p_str);
}
@@ -422,27 +449,31 @@ bool String::operator<(const String &p_str) const {
}
signed char String::nocasecmp_to(const String &p_str) const {
- if (empty() && p_str.empty())
+ if (empty() && p_str.empty()) {
return 0;
- if (empty())
+ }
+ if (empty()) {
return -1;
- if (p_str.empty())
+ }
+ if (p_str.empty()) {
return 1;
+ }
const CharType *that_str = p_str.c_str();
const CharType *this_str = c_str();
while (true) {
- if (*that_str == 0 && *this_str == 0)
+ if (*that_str == 0 && *this_str == 0) {
return 0; //we're equal
- else if (*this_str == 0)
+ } else if (*this_str == 0) {
return -1; //if this is empty, and the other one is not, then we're less.. I think?
- else if (*that_str == 0)
+ } else if (*that_str == 0) {
return 1; //otherwise the other one is smaller..
- else if (_find_upper(*this_str) < _find_upper(*that_str)) //more than
+ } else if (_find_upper(*this_str) < _find_upper(*that_str)) { //more than
return -1;
- else if (_find_upper(*this_str) > _find_upper(*that_str)) //less than
+ } else if (_find_upper(*this_str) > _find_upper(*that_str)) { //less than
return 1;
+ }
this_str++;
that_str++;
@@ -450,27 +481,31 @@ signed char String::nocasecmp_to(const String &p_str) const {
}
signed char String::casecmp_to(const String &p_str) const {
- if (empty() && p_str.empty())
+ if (empty() && p_str.empty()) {
return 0;
- if (empty())
+ }
+ if (empty()) {
return -1;
- if (p_str.empty())
+ }
+ if (p_str.empty()) {
return 1;
+ }
const CharType *that_str = p_str.c_str();
const CharType *this_str = c_str();
while (true) {
- if (*that_str == 0 && *this_str == 0)
+ if (*that_str == 0 && *this_str == 0) {
return 0; //we're equal
- else if (*this_str == 0)
+ } else if (*this_str == 0) {
return -1; //if this is empty, and the other one is not, then we're less.. I think?
- else if (*that_str == 0)
+ } else if (*that_str == 0) {
return 1; //otherwise the other one is smaller..
- else if (*this_str < *that_str) //more than
+ } else if (*this_str < *that_str) { //more than
return -1;
- else if (*this_str > *that_str) //less than
+ } else if (*this_str > *that_str) { //less than
return 1;
+ }
this_str++;
that_str++;
@@ -483,53 +518,63 @@ signed char String::naturalnocasecmp_to(const String &p_str) const {
if (this_str && that_str) {
while (*this_str == '.' || *that_str == '.') {
- if (*this_str++ != '.')
+ if (*this_str++ != '.') {
return 1;
- if (*that_str++ != '.')
+ }
+ if (*that_str++ != '.') {
return -1;
- if (!*that_str)
+ }
+ if (!*that_str) {
return 1;
- if (!*this_str)
+ }
+ if (!*this_str) {
return -1;
+ }
}
while (*this_str) {
- if (!*that_str)
+ if (!*that_str) {
return 1;
- else if (IS_DIGIT(*this_str)) {
+ } else if (IS_DIGIT(*this_str)) {
int64_t this_int, that_int;
- if (!IS_DIGIT(*that_str))
+ if (!IS_DIGIT(*that_str)) {
return -1;
+ }
/* Compare the numbers */
this_int = to_int(this_str, -1, true);
that_int = to_int(that_str, -1, true);
- if (this_int < that_int)
+ if (this_int < that_int) {
return -1;
- else if (this_int > that_int)
+ } else if (this_int > that_int) {
return 1;
+ }
/* Skip */
- while (IS_DIGIT(*this_str))
+ while (IS_DIGIT(*this_str)) {
this_str++;
- while (IS_DIGIT(*that_str))
+ }
+ while (IS_DIGIT(*that_str)) {
that_str++;
- } else if (IS_DIGIT(*that_str))
+ }
+ } else if (IS_DIGIT(*that_str)) {
return 1;
- else {
- if (_find_upper(*this_str) < _find_upper(*that_str)) //more than
+ } else {
+ if (_find_upper(*this_str) < _find_upper(*that_str)) { //more than
return -1;
- else if (_find_upper(*this_str) > _find_upper(*that_str)) //less than
+ } else if (_find_upper(*this_str) > _find_upper(*that_str)) { //less than
return 1;
+ }
this_str++;
that_str++;
}
}
- if (*that_str)
+ if (*that_str) {
return -1;
+ }
}
return 0;
@@ -546,8 +591,9 @@ String String::capitalize() const {
String slice = aux.get_slicec(' ', i);
if (slice.length() > 0) {
slice[0] = _find_upper(slice[0]);
- if (i > 0)
+ if (i > 0) {
cap += " ";
+ }
cap += slice;
}
}
@@ -610,10 +656,12 @@ String String::get_with_code_lines() const {
}
int String::get_slice_count(String p_splitter) const {
- if (empty())
+ if (empty()) {
return 0;
- if (p_splitter.empty())
+ }
+ if (p_splitter.empty()) {
return 0;
+ }
int pos = 0;
int slices = 1;
@@ -627,22 +675,26 @@ int String::get_slice_count(String p_splitter) const {
}
String String::get_slice(String p_splitter, int p_slice) const {
- if (empty() || p_splitter.empty())
+ if (empty() || p_splitter.empty()) {
return "";
+ }
int pos = 0;
int prev_pos = 0;
//int slices=1;
- if (p_slice < 0)
+ if (p_slice < 0) {
return "";
- if (find(p_splitter) == -1)
+ }
+ if (find(p_splitter) == -1) {
return *this;
+ }
int i = 0;
while (true) {
pos = find(p_splitter, pos);
- if (pos == -1)
+ if (pos == -1) {
pos = length(); //reached end
+ }
int from = prev_pos;
//int to=pos;
@@ -651,8 +703,9 @@ String String::get_slice(String p_splitter, int p_slice) const {
return substr(from, pos - from);
}
- if (pos == length()) //reached end and no find
+ if (pos == length()) { //reached end and no find
break;
+ }
pos += p_splitter.length();
prev_pos = pos;
i++;
@@ -662,11 +715,13 @@ String String::get_slice(String p_splitter, int p_slice) const {
}
String String::get_slicec(CharType p_splitter, int p_slice) const {
- if (empty())
+ if (empty()) {
return String();
+ }
- if (p_slice < 0)
+ if (p_slice < 0) {
return String();
+ }
const CharType *c = this->ptr();
int i = 0;
@@ -693,16 +748,18 @@ Vector<String> String::split_spaces() const {
int from = 0;
int i = 0;
int len = length();
- if (len == 0)
+ if (len == 0) {
return ret;
+ }
bool inside = false;
while (true) {
bool empty = operator[](i) < 33;
- if (i == 0)
+ if (i == 0) {
inside = !empty;
+ }
if (!empty && !inside) {
inside = true;
@@ -714,8 +771,9 @@ Vector<String> String::split_spaces() const {
inside = false;
}
- if (i == len)
+ if (i == len) {
break;
+ }
i++;
}
@@ -729,12 +787,13 @@ Vector<String> String::split(const String &p_splitter, bool p_allow_empty, int p
while (true) {
int end = find(p_splitter, from);
- if (end < 0)
+ if (end < 0) {
end = len;
+ }
if (p_allow_empty || (end > from)) {
- if (p_maxsplit <= 0)
+ if (p_maxsplit <= 0) {
ret.push_back(substr(from, end - from));
- else {
+ } else {
// Put rest of the string and leave cycle.
if (p_maxsplit == ret.size()) {
ret.push_back(substr(from, len));
@@ -746,8 +805,9 @@ Vector<String> String::split(const String &p_splitter, bool p_allow_empty, int p
}
}
- if (end == len)
+ if (end == len) {
break;
+ }
from = end + p_splitter.length();
}
@@ -796,13 +856,16 @@ Vector<float> String::split_floats(const String &p_splitter, bool p_allow_empty)
while (true) {
int end = find(p_splitter, from);
- if (end < 0)
+ if (end < 0) {
end = len;
- if (p_allow_empty || (end > from))
+ }
+ if (p_allow_empty || (end > from)) {
ret.push_back(String::to_double(&c_str()[from]));
+ }
- if (end == len)
+ if (end == len) {
break;
+ }
from = end + p_splitter.length();
}
@@ -829,8 +892,9 @@ Vector<float> String::split_floats_mk(const Vector<String> &p_splitters, bool p_
ret.push_back(String::to_double(&c_str()[from]));
}
- if (end == len)
+ if (end == len) {
break;
+ }
from = end + spl_len;
}
@@ -845,13 +909,16 @@ Vector<int> String::split_ints(const String &p_splitter, bool p_allow_empty) con
while (true) {
int end = find(p_splitter, from);
- if (end < 0)
+ if (end < 0) {
end = len;
- if (p_allow_empty || (end > from))
+ }
+ if (p_allow_empty || (end > from)) {
ret.push_back(String::to_int(&c_str()[from], end - from));
+ }
- if (end == len)
+ if (end == len) {
break;
+ }
from = end + p_splitter.length();
}
@@ -874,11 +941,13 @@ Vector<int> String::split_ints_mk(const Vector<String> &p_splitters, bool p_allo
spl_len = p_splitters[idx].length();
}
- if (p_allow_empty || (end > from))
+ if (p_allow_empty || (end > from)) {
ret.push_back(String::to_int(&c_str()[from], end - from));
+ }
- if (end == len)
+ if (end == len) {
break;
+ }
from = end + spl_len;
}
@@ -911,8 +980,9 @@ String String::to_upper() const {
for (int i = 0; i < upper.size(); i++) {
const CharType s = upper[i];
const CharType t = _find_upper(s);
- if (s != t) // avoid copy on write
+ if (s != t) { // avoid copy on write
upper[i] = t;
+ }
}
return upper;
@@ -924,8 +994,9 @@ String String::to_lower() const {
for (int i = 0; i < lower.size(); i++) {
const CharType s = lower[i];
const CharType t = _find_lower(s);
- if (s != t) // avoid copy on write
+ if (s != t) { // avoid copy on write
lower[i] = t;
+ }
}
return lower;
@@ -965,8 +1036,9 @@ String String::chr(CharType p_char) {
String String::num(double p_num, int p_decimals) {
#ifndef NO_USE_STDLIB
- if (p_decimals > 16)
+ if (p_decimals > 16) {
p_decimals = 16;
+ }
char fmt[7];
fmt[0] = '%';
@@ -1003,8 +1075,9 @@ String String::num(double p_num, int p_decimals) {
bool period = false;
int z = 0;
while (buf[z]) {
- if (buf[z] == '.')
+ if (buf[z] == '.') {
period = true;
+ }
z++;
}
@@ -1116,8 +1189,9 @@ String String::num_int64(int64_t p_num, int base, bool capitalize_hex) {
chars++;
} while (n);
- if (sign)
+ if (sign) {
chars++;
+ }
String s;
s.resize(chars + 1);
CharType *c = s.ptrw();
@@ -1135,8 +1209,9 @@ String String::num_int64(int64_t p_num, int base, bool capitalize_hex) {
n /= base;
} while (n);
- if (sign)
+ if (sign) {
c[0] = '-';
+ }
return s;
}
@@ -1196,11 +1271,13 @@ String String::num_real(double p_num) {
dec_max = dec_max * 10 + 9;
digit++;
- if ((dec - (float)((int)dec)) < 1e-6)
+ if ((dec - (float)((int)dec)) < 1e-6) {
break;
+ }
- if (digit == decimals)
+ if (digit == decimals) {
break;
+ }
}
dec *= 10;
@@ -1227,10 +1304,9 @@ String String::num_real(double p_num) {
sd = ".0";
}
- if (intn == 0)
-
+ if (intn == 0) {
s = "0";
- else {
+ } else {
while (intn) {
CharType num = '0' + (intn % 10);
intn /= 10;
@@ -1239,8 +1315,9 @@ String String::num_real(double p_num) {
}
s = s + sd;
- if (neg)
+ if (neg) {
s = "-" + s;
+ }
return s;
}
@@ -1275,14 +1352,16 @@ String String::num_scientific(double p_num) {
}
CharString String::ascii(bool p_allow_extended) const {
- if (!length())
+ if (!length()) {
return CharString();
+ }
CharString cs;
cs.resize(size());
- for (int i = 0; i < size(); i++)
+ for (int i = 0; i < size(); i++) {
cs[i] = operator[](i);
+ }
return cs;
}
@@ -1297,8 +1376,9 @@ String String::utf8(const char *p_utf8, int p_len) {
bool String::parse_utf8(const char *p_utf8, int p_len) {
#define _UNICERROR(m_err) print_line("Unicode parsing error: " + String(m_err) + ". Is the string valid UTF-8?");
- if (!p_utf8)
+ if (!p_utf8) {
return true;
+ }
String aux;
@@ -1310,8 +1390,9 @@ bool String::parse_utf8(const char *p_utf8, int p_len) {
bool has_bom = uint8_t(p_utf8[0]) == 0xEF && uint8_t(p_utf8[1]) == 0xBB && uint8_t(p_utf8[2]) == 0xBF;
if (has_bom) {
//just skip it
- if (p_len >= 0)
+ if (p_len >= 0) {
p_len -= 3;
+ }
p_utf8 += 3;
}
}
@@ -1325,19 +1406,19 @@ bool String::parse_utf8(const char *p_utf8, int p_len) {
uint8_t c = *ptrtmp >= 0 ? *ptrtmp : uint8_t(256 + *ptrtmp);
/* Determine the number of characters in sequence */
- if ((c & 0x80) == 0)
+ if ((c & 0x80) == 0) {
skip = 0;
- else if ((c & 0xE0) == 0xC0)
+ } else if ((c & 0xE0) == 0xC0) {
skip = 1;
- else if ((c & 0xF0) == 0xE0)
+ } else if ((c & 0xF0) == 0xE0) {
skip = 2;
- else if ((c & 0xF8) == 0xF0)
+ } else if ((c & 0xF8) == 0xF0) {
skip = 3;
- else if ((c & 0xFC) == 0xF8)
+ } else if ((c & 0xFC) == 0xF8) {
skip = 4;
- else if ((c & 0xFE) == 0xFC)
+ } else if ((c & 0xFE) == 0xFC) {
skip = 5;
- else {
+ } else {
_UNICERROR("invalid skip");
return true; //invalid utf8
}
@@ -1377,19 +1458,19 @@ bool String::parse_utf8(const char *p_utf8, int p_len) {
int len = 0;
/* Determine the number of characters in sequence */
- if ((*p_utf8 & 0x80) == 0)
+ if ((*p_utf8 & 0x80) == 0) {
len = 1;
- else if ((*p_utf8 & 0xE0) == 0xC0)
+ } else if ((*p_utf8 & 0xE0) == 0xC0) {
len = 2;
- else if ((*p_utf8 & 0xF0) == 0xE0)
+ } else if ((*p_utf8 & 0xF0) == 0xE0) {
len = 3;
- else if ((*p_utf8 & 0xF8) == 0xF0)
+ } else if ((*p_utf8 & 0xF8) == 0xF0) {
len = 4;
- else if ((*p_utf8 & 0xFC) == 0xF8)
+ } else if ((*p_utf8 & 0xFC) == 0xF8) {
len = 5;
- else if ((*p_utf8 & 0xFE) == 0xFC)
+ } else if ((*p_utf8 & 0xFE) == 0xFC) {
len = 6;
- else {
+ } else {
_UNICERROR("invalid len");
return true; //invalid UTF8
@@ -1410,9 +1491,9 @@ bool String::parse_utf8(const char *p_utf8, int p_len) {
uint32_t unichar = 0;
- if (len == 1)
+ if (len == 1) {
unichar = *p_utf8;
- else {
+ } else {
unichar = (0xFF >> (len + 1)) & *p_utf8;
for (int i = 1; i < len; i++) {
@@ -1443,16 +1524,17 @@ bool String::parse_utf8(const char *p_utf8, int p_len) {
CharString String::utf8() const {
int l = length();
- if (!l)
+ if (!l) {
return CharString();
+ }
const CharType *d = &operator[](0);
int fl = 0;
for (int i = 0; i < l; i++) {
uint32_t c = d[i];
- if (c <= 0x7f) // 7 bits.
+ if (c <= 0x7f) { // 7 bits.
fl += 1;
- else if (c <= 0x7ff) { // 11 bits
+ } else if (c <= 0x7ff) { // 11 bits
fl += 2;
} else if (c <= 0xffff) { // 16 bits
fl += 3;
@@ -1479,9 +1561,9 @@ CharString String::utf8() const {
for (int i = 0; i < l; i++) {
uint32_t c = d[i];
- if (c <= 0x7f) // 7 bits.
+ if (c <= 0x7f) { // 7 bits.
APPEND_CHAR(c);
- else if (c <= 0x7ff) { // 11 bits
+ } else if (c <= 0x7ff) { // 11 bits
APPEND_CHAR(uint32_t(0xc0 | ((c >> 6) & 0x1f))); // Top 5 bits.
APPEND_CHAR(uint32_t(0x80 | (c & 0x3f))); // Bottom 6 bits.
@@ -1537,15 +1619,17 @@ String::String(const CharType *p_str, int p_clip_to_len) {
}
String::String(const StrRange &p_range) {
- if (!p_range.c_str)
+ if (!p_range.c_str) {
return;
+ }
copy_from(p_range.c_str, p_range.len);
}
int String::hex_to_int(bool p_with_prefix) const {
- if (p_with_prefix && length() < 3)
+ if (p_with_prefix && length() < 3) {
return 0;
+ }
const CharType *s = ptr();
@@ -1556,8 +1640,9 @@ int String::hex_to_int(bool p_with_prefix) const {
}
if (p_with_prefix) {
- if (s[0] != '0' || s[1] != 'x')
+ if (s[0] != '0' || s[1] != 'x') {
return 0;
+ }
s += 2;
}
@@ -1584,8 +1669,9 @@ int String::hex_to_int(bool p_with_prefix) const {
}
int64_t String::hex_to_int64(bool p_with_prefix) const {
- if (p_with_prefix && length() < 3)
+ if (p_with_prefix && length() < 3) {
return 0;
+ }
const CharType *s = ptr();
@@ -1596,8 +1682,9 @@ int64_t String::hex_to_int64(bool p_with_prefix) const {
}
if (p_with_prefix) {
- if (s[0] != '0' || s[1] != 'x')
+ if (s[0] != '0' || s[1] != 'x') {
return 0;
+ }
s += 2;
}
@@ -1624,8 +1711,9 @@ int64_t String::hex_to_int64(bool p_with_prefix) const {
}
int64_t String::bin_to_int64(bool p_with_prefix) const {
- if (p_with_prefix && length() < 3)
+ if (p_with_prefix && length() < 3) {
return 0;
+ }
const CharType *s = ptr();
@@ -1636,8 +1724,9 @@ int64_t String::bin_to_int64(bool p_with_prefix) const {
}
if (p_with_prefix) {
- if (s[0] != '0' || s[1] != 'b')
+ if (s[0] != '0' || s[1] != 'b') {
return 0;
+ }
s += 2;
}
@@ -1662,8 +1751,9 @@ int64_t String::bin_to_int64(bool p_with_prefix) const {
}
int String::to_int() const {
- if (length() == 0)
+ if (length() == 0) {
return 0;
+ }
int to = (find(".") >= 0) ? find(".") : length();
@@ -1686,8 +1776,9 @@ int String::to_int() const {
}
int64_t String::to_int64() const {
- if (length() == 0)
+ if (length() == 0) {
return 0;
+ }
int to = (find(".") >= 0) ? find(".") : length();
@@ -1711,11 +1802,12 @@ int64_t String::to_int64() const {
int String::to_int(const char *p_str, int p_len) {
int to = 0;
- if (p_len >= 0)
+ if (p_len >= 0) {
to = p_len;
- else {
- while (p_str[to] != 0 && p_str[to] != '.')
+ } else {
+ while (p_str[to] != 0 && p_str[to] != '.') {
to++;
+ }
}
int integer = 0;
@@ -1730,8 +1822,9 @@ int String::to_int(const char *p_str, int p_len) {
} else if (c == '-' && integer == 0) {
sign = -sign;
- } else if (c != ' ')
+ } else if (c != ' ') {
break;
+ }
}
return integer * sign;
@@ -1743,8 +1836,9 @@ bool String::is_numeric() const {
};
int s = 0;
- if (operator[](0) == '-')
+ if (operator[](0) == '-') {
++s;
+ }
bool dot = false;
for (int i = s; i < length(); i++) {
CharType c = operator[](i);
@@ -1995,8 +2089,9 @@ double String::to_double(const CharType *p_str, const CharType **r_end) {
}
int64_t String::to_int(const CharType *p_str, int p_len, bool p_clamp) {
- if (p_len == 0 || !p_str[0])
+ if (p_len == 0 || !p_str[0]) {
return 0;
+ }
///@todo make more exact so saving and loading does not lose precision
int64_t integer = 0;
@@ -2058,8 +2153,9 @@ int64_t String::to_int(const CharType *p_str, int p_len, bool p_clamp) {
}
double String::to_double() const {
- if (empty())
+ if (empty()) {
return 0;
+ }
#ifndef NO_USE_STDLIB
return built_in_strtod<CharType>(c_str());
//return wcstod(c_str(),nullptr ); DOES NOT WORK ON ANDROID :(
@@ -2086,24 +2182,27 @@ uint32_t String::hash(const char *p_cstr) {
uint32_t hashv = 5381;
uint32_t c;
- while ((c = *p_cstr++))
+ while ((c = *p_cstr++)) {
hashv = ((hashv << 5) + hashv) + c; /* hash * 33 + c */
+ }
return hashv;
}
uint32_t String::hash(const char *p_cstr, int p_len) {
uint32_t hashv = 5381;
- for (int i = 0; i < p_len; i++)
+ for (int i = 0; i < p_len; i++) {
hashv = ((hashv << 5) + hashv) + p_cstr[i]; /* hash * 33 + c */
+ }
return hashv;
}
uint32_t String::hash(const CharType *p_cstr, int p_len) {
uint32_t hashv = 5381;
- for (int i = 0; i < p_len; i++)
+ for (int i = 0; i < p_len; i++) {
hashv = ((hashv << 5) + hashv) + p_cstr[i]; /* hash * 33 + c */
+ }
return hashv;
}
@@ -2112,8 +2211,9 @@ uint32_t String::hash(const CharType *p_cstr) {
uint32_t hashv = 5381;
uint32_t c;
- while ((c = *p_cstr++))
+ while ((c = *p_cstr++)) {
hashv = ((hashv << 5) + hashv) + c; /* hash * 33 + c */
+ }
return hashv;
}
@@ -2125,8 +2225,9 @@ uint32_t String::hash() const {
uint32_t hashv = 5381;
uint32_t c;
- while ((c = *chr++))
+ while ((c = *chr++)) {
hashv = ((hashv << 5) + hashv) + c; /* hash * 33 + c */
+ }
return hashv;
}
@@ -2138,8 +2239,9 @@ uint64_t String::hash64() const {
uint64_t hashv = 5381;
uint64_t c;
- while ((c = *chr++))
+ while ((c = *chr++)) {
hashv = ((hashv << 5) + hashv) + c; /* hash * 33 + c */
+ }
return hashv;
}
@@ -2206,29 +2308,35 @@ Vector<uint8_t> String::sha256_buffer() const {
}
String String::insert(int p_at_pos, const String &p_string) const {
- if (p_at_pos < 0)
+ if (p_at_pos < 0) {
return *this;
+ }
- if (p_at_pos > length())
+ if (p_at_pos > length()) {
p_at_pos = length();
+ }
String pre;
- if (p_at_pos > 0)
+ if (p_at_pos > 0) {
pre = substr(0, p_at_pos);
+ }
String post;
- if (p_at_pos < length())
+ if (p_at_pos < length()) {
post = substr(p_at_pos, length() - p_at_pos);
+ }
return pre + p_string + post;
}
String String::substr(int p_from, int p_chars) const {
- if (p_chars == -1)
+ if (p_chars == -1) {
p_chars = length() - p_from;
+ }
- if (empty() || p_from < 0 || p_from >= length() || p_chars <= 0)
+ if (empty() || p_from < 0 || p_from >= length() || p_chars <= 0) {
return "";
+ }
if ((p_from + p_chars) > length()) {
p_chars = length() - p_from;
@@ -2256,15 +2364,17 @@ int String::find_last(const String &p_str) const {
}
int String::find(const String &p_str, int p_from) const {
- if (p_from < 0)
+ if (p_from < 0) {
return -1;
+ }
const int src_len = p_str.length();
const int len = length();
- if (src_len == 0 || len == 0)
+ if (src_len == 0 || len == 0) {
return -1; // won't find anything!
+ }
const CharType *src = c_str();
const CharType *str = p_str.c_str();
@@ -2285,27 +2395,31 @@ int String::find(const String &p_str, int p_from) const {
}
}
- if (found)
+ if (found) {
return i;
+ }
}
return -1;
}
int String::find(const char *p_str, int p_from) const {
- if (p_from < 0)
+ if (p_from < 0) {
return -1;
+ }
const int len = length();
- if (len == 0)
+ if (len == 0) {
return -1; // won't find anything!
+ }
const CharType *src = c_str();
int src_len = 0;
- while (p_str[src_len] != '\0')
+ while (p_str[src_len] != '\0') {
src_len++;
+ }
if (src_len == 1) {
const char needle = p_str[0];
@@ -2333,8 +2447,9 @@ int String::find(const char *p_str, int p_from) const {
}
}
- if (found)
+ if (found) {
return i;
+ }
}
}
@@ -2346,18 +2461,21 @@ int String::find_char(const CharType &p_char, int p_from) const {
}
int String::findmk(const Vector<String> &p_keys, int p_from, int *r_key) const {
- if (p_from < 0)
+ if (p_from < 0) {
return -1;
- if (p_keys.size() == 0)
+ }
+ if (p_keys.size() == 0) {
return -1;
+ }
//int src_len=p_str.length();
const String *keys = &p_keys[0];
int key_count = p_keys.size();
int len = length();
- if (len == 0)
+ if (len == 0) {
return -1; // won't find anything!
+ }
const CharType *src = c_str();
@@ -2365,8 +2483,9 @@ int String::findmk(const Vector<String> &p_keys, int p_from, int *r_key) const {
bool found = true;
for (int k = 0; k < key_count; k++) {
found = true;
- if (r_key)
+ if (r_key) {
*r_key = k;
+ }
const CharType *cmp = keys[k].c_str();
int l = keys[k].length();
@@ -2383,25 +2502,29 @@ int String::findmk(const Vector<String> &p_keys, int p_from, int *r_key) const {
break;
}
}
- if (found)
+ if (found) {
break;
+ }
}
- if (found)
+ if (found) {
return i;
+ }
}
return -1;
}
int String::findn(const String &p_str, int p_from) const {
- if (p_from < 0)
+ if (p_from < 0) {
return -1;
+ }
int src_len = p_str.length();
- if (src_len == 0 || length() == 0)
+ if (src_len == 0 || length() == 0) {
return -1; // won't find anything!
+ }
const CharType *srcd = c_str();
@@ -2424,8 +2547,9 @@ int String::findn(const String &p_str, int p_from) const {
}
}
- if (found)
+ if (found) {
return i;
+ }
}
return -1;
@@ -2434,20 +2558,23 @@ int String::findn(const String &p_str, int p_from) const {
int String::rfind(const String &p_str, int p_from) const {
// establish a limit
int limit = length() - p_str.length();
- if (limit < 0)
+ if (limit < 0) {
return -1;
+ }
// establish a starting point
- if (p_from < 0)
+ if (p_from < 0) {
p_from = limit;
- else if (p_from > limit)
+ } else if (p_from > limit) {
p_from = limit;
+ }
int src_len = p_str.length();
int len = length();
- if (src_len == 0 || len == 0)
+ if (src_len == 0 || len == 0) {
return -1; // won't find anything!
+ }
const CharType *src = c_str();
@@ -2467,8 +2594,9 @@ int String::rfind(const String &p_str, int p_from) const {
}
}
- if (found)
+ if (found) {
return i;
+ }
}
return -1;
@@ -2477,20 +2605,23 @@ int String::rfind(const String &p_str, int p_from) const {
int String::rfindn(const String &p_str, int p_from) const {
// establish a limit
int limit = length() - p_str.length();
- if (limit < 0)
+ if (limit < 0) {
return -1;
+ }
// establish a starting point
- if (p_from < 0)
+ if (p_from < 0) {
p_from = limit;
- else if (p_from > limit)
+ } else if (p_from > limit) {
p_from = limit;
+ }
int src_len = p_str.length();
int len = length();
- if (src_len == 0 || len == 0)
+ if (src_len == 0 || len == 0) {
return -1; // won't find anything!
+ }
const CharType *src = c_str();
@@ -2513,8 +2644,9 @@ int String::rfindn(const String &p_str, int p_from) const {
}
}
- if (found)
+ if (found) {
return i;
+ }
}
return -1;
@@ -2522,26 +2654,30 @@ int String::rfindn(const String &p_str, int p_from) const {
bool String::ends_with(const String &p_string) const {
int pos = find_last(p_string);
- if (pos == -1)
+ if (pos == -1) {
return false;
+ }
return pos + p_string.length() == length();
}
bool String::begins_with(const String &p_string) const {
- if (p_string.length() > length())
+ if (p_string.length() > length()) {
return false;
+ }
int l = p_string.length();
- if (l == 0)
+ if (l == 0) {
return true;
+ }
const CharType *src = &p_string[0];
const CharType *str = &operator[](0);
int i = 0;
for (; i < l; i++) {
- if (src[i] != str[i])
+ if (src[i] != str[i]) {
return false;
+ }
}
// only if i == l the p_string matches the beginning
@@ -2550,15 +2686,17 @@ bool String::begins_with(const String &p_string) const {
bool String::begins_with(const char *p_string) const {
int l = length();
- if (l == 0 || !p_string)
+ if (l == 0 || !p_string) {
return false;
+ }
const CharType *str = &operator[](0);
int i = 0;
while (*p_string && i < l) {
- if (*p_string != str[i])
+ if (*p_string != str[i]) {
return false;
+ }
i++;
p_string++;
}
@@ -2720,15 +2858,17 @@ static bool _wildcard_match(const CharType *p_pattern, const CharType *p_string,
}
bool String::match(const String &p_wildcard) const {
- if (!p_wildcard.length() || !length())
+ if (!p_wildcard.length() || !length()) {
return false;
+ }
return _wildcard_match(p_wildcard.c_str(), c_str(), true);
}
bool String::matchn(const String &p_wildcard) const {
- if (!p_wildcard.length() || !length())
+ if (!p_wildcard.length() || !length()) {
return false;
+ }
return _wildcard_match(p_wildcard.c_str(), c_str(), false);
}
@@ -2832,8 +2972,9 @@ String String::replace(const char *p_key, const char *p_with) const {
new_string += substr(search_from, result - search_from);
new_string += p_with;
int k = 0;
- while (p_key[k] != '\0')
+ while (p_key[k] != '\0') {
k++;
+ }
search_from = result + k;
}
@@ -2882,29 +3023,35 @@ String String::repeat(int p_count) const {
new_string.resize(length() * p_count + 1);
- for (int i = 0; i < p_count; i++)
- for (int j = 0; j < length(); j++)
+ for (int i = 0; i < p_count; i++) {
+ for (int j = 0; j < length(); j++) {
new_string[i * length() + j] = src[j];
+ }
+ }
return new_string;
}
String String::left(int p_pos) const {
- if (p_pos <= 0)
+ if (p_pos <= 0) {
return "";
+ }
- if (p_pos >= length())
+ if (p_pos >= length()) {
return *this;
+ }
return substr(0, p_pos);
}
String String::right(int p_pos) const {
- if (p_pos >= length())
+ if (p_pos >= length()) {
return "";
+ }
- if (p_pos <= 0)
+ if (p_pos <= 0) {
return *this;
+ }
return substr(p_pos, (length() - p_pos));
}
@@ -2925,8 +3072,9 @@ String String::dedent() const {
for (int i = 0; i < length(); i++) {
CharType c = operator[](i);
if (c == '\n') {
- if (has_text)
+ if (has_text) {
new_string += substr(indent_stop, i - indent_stop);
+ }
new_string += "\n";
has_text = false;
line_start = i + 1;
@@ -2942,14 +3090,16 @@ String String::dedent() const {
}
if (has_indent && indent_stop < 0) {
int j = i - line_start;
- if (j >= indent.length() || c != indent[j])
+ if (j >= indent.length() || c != indent[j]) {
indent_stop = i;
+ }
}
}
}
- if (has_text)
+ if (has_text) {
new_string += substr(indent_stop, length() - indent_stop);
+ }
return new_string;
}
@@ -2960,24 +3110,27 @@ String String::strip_edges(bool left, bool right) const {
if (left) {
for (int i = 0; i < len; i++) {
- if (operator[](i) <= 32)
+ if (operator[](i) <= 32) {
beg++;
- else
+ } else {
break;
+ }
}
}
if (right) {
for (int i = (int)(len - 1); i >= 0; i--) {
- if (operator[](i) <= 32)
+ if (operator[](i) <= 32) {
end--;
- else
+ } else {
break;
+ }
}
}
- if (beg == 0 && end == len)
+ if (beg == 0 && end == len) {
return *this;
+ }
return substr(beg, end - beg);
}
@@ -2986,8 +3139,9 @@ String String::strip_escapes() const {
String new_string;
for (int i = 0; i < length(); i++) {
// Escape characters on first page of the ASCII table, before 32 (Space).
- if (operator[](i) < 32)
+ if (operator[](i) < 32) {
continue;
+ }
new_string += operator[](i);
}
@@ -2999,12 +3153,14 @@ String String::lstrip(const String &p_chars) const {
int beg;
for (beg = 0; beg < len; beg++) {
- if (p_chars.find_char(get(beg)) == -1)
+ if (p_chars.find_char(get(beg)) == -1) {
break;
+ }
}
- if (beg == 0)
+ if (beg == 0) {
return *this;
+ }
return substr(beg, len - beg);
}
@@ -3014,12 +3170,14 @@ String String::rstrip(const String &p_chars) const {
int end;
for (end = len - 1; end >= 0; end--) {
- if (p_chars.find_char(get(end)) == -1)
+ if (p_chars.find_char(get(end)) == -1) {
break;
+ }
}
- if (end == len - 1)
+ if (end == len - 1) {
return *this;
+ }
return substr(0, end + 1);
}
@@ -3041,8 +3199,9 @@ String String::simplify_path() const {
s = s.substr(1, s.length() - 1);
} else {
int p = s.find(":/");
- if (p == -1)
+ if (p == -1) {
p = s.find(":\\");
+ }
if (p != -1 && p < s.find("/")) {
drive = s.substr(0, p + 2);
s = s.substr(p + 2, s.length());
@@ -3052,10 +3211,11 @@ String String::simplify_path() const {
s = s.replace("\\", "/");
while (true) { // in case of using 2 or more slash
String compare = s.replace("//", "/");
- if (s == compare)
+ if (s == compare) {
break;
- else
+ } else {
s = compare;
+ }
}
Vector<String> dirs = s.split("/", false);
@@ -3079,8 +3239,9 @@ String String::simplify_path() const {
s = "";
for (int i = 0; i < dirs.size(); i++) {
- if (i > 0)
+ if (i > 0) {
s += "/";
+ }
s += dirs[i];
}
@@ -3088,12 +3249,13 @@ String String::simplify_path() const {
}
static int _humanize_digits(int p_num) {
- if (p_num < 100)
+ if (p_num < 100) {
return 2;
- else if (p_num < 1024)
+ } else if (p_num < 1024) {
return 1;
- else
+ } else {
return 0;
+ }
}
String String::humanize_size(uint64_t p_size) {
@@ -3121,32 +3283,36 @@ String String::humanize_size(uint64_t p_size) {
}
bool String::is_abs_path() const {
- if (length() > 1)
+ if (length() > 1) {
return (operator[](0) == '/' || operator[](0) == '\\' || find(":/") != -1 || find(":\\") != -1);
- else if ((length()) == 1)
+ } else if ((length()) == 1) {
return (operator[](0) == '/' || operator[](0) == '\\');
- else
+ } else {
return false;
+ }
}
bool String::is_valid_identifier() const {
int len = length();
- if (len == 0)
+ if (len == 0) {
return false;
+ }
const wchar_t *str = &operator[](0);
for (int i = 0; i < len; i++) {
if (i == 0) {
- if (str[0] >= '0' && str[0] <= '9')
+ if (str[0] >= '0' && str[0] <= '9') {
return false; // no start with number plz
+ }
}
bool valid_char = (str[i] >= '0' && str[i] <= '9') || (str[i] >= 'a' && str[i] <= 'z') || (str[i] >= 'A' && str[i] <= 'Z') || str[i] == '_';
- if (!valid_char)
+ if (!valid_char) {
return false;
+ }
}
return true;
@@ -3296,11 +3462,11 @@ String String::xml_escape(bool p_escape_quotes) const {
str = str.replace("\"", "&quot;");
}
/*
- for (int i=1;i<32;i++) {
+for (int i=1;i<32;i++) {
- char chr[2]={i,0};
- str=str.replace(chr,"&#"+String::num(i)+";");
- }*/
+ char chr[2]={i,0};
+ str=str.replace(chr,"&#"+String::num(i)+";");
+}*/
return str;
}
@@ -3331,37 +3497,45 @@ static _FORCE_INLINE_ int _xml_unescape(const CharType *p_src, int p_src_len, Ch
c |= ct;
}
- if (p_dst)
+ if (p_dst) {
*p_dst = c;
+ }
} else if (p_src_len >= 4 && p_src[1] == 'g' && p_src[2] == 't' && p_src[3] == ';') {
- if (p_dst)
+ if (p_dst) {
*p_dst = '>';
+ }
eat = 4;
} else if (p_src_len >= 4 && p_src[1] == 'l' && p_src[2] == 't' && p_src[3] == ';') {
- if (p_dst)
+ if (p_dst) {
*p_dst = '<';
+ }
eat = 4;
} else if (p_src_len >= 5 && p_src[1] == 'a' && p_src[2] == 'm' && p_src[3] == 'p' && p_src[4] == ';') {
- if (p_dst)
+ if (p_dst) {
*p_dst = '&';
+ }
eat = 5;
} else if (p_src_len >= 6 && p_src[1] == 'q' && p_src[2] == 'u' && p_src[3] == 'o' && p_src[4] == 't' && p_src[5] == ';') {
- if (p_dst)
+ if (p_dst) {
*p_dst = '"';
+ }
eat = 6;
} else if (p_src_len >= 6 && p_src[1] == 'a' && p_src[2] == 'p' && p_src[3] == 'o' && p_src[4] == 's' && p_src[5] == ';') {
- if (p_dst)
+ if (p_dst) {
*p_dst = '\'';
+ }
eat = 6;
} else {
- if (p_dst)
+ if (p_dst) {
*p_dst = *p_src;
+ }
eat = 1;
}
- if (p_dst)
+ if (p_dst) {
p_dst++;
+ }
len++;
p_src += eat;
@@ -3384,8 +3558,9 @@ String String::xml_unescape() const {
String str;
int l = length();
int len = _xml_unescape(c_str(), l, nullptr);
- if (len == 0)
+ if (len == 0) {
return String();
+ }
str.resize(len + 1);
_xml_unescape(c_str(), l, str.ptrw());
str[len] = 0;
@@ -3426,8 +3601,9 @@ String String::pad_zeros(int p_digits) const {
end = s.length();
}
- if (end == 0)
+ if (end == 0) {
return s;
+ }
int begin = 0;
@@ -3435,8 +3611,9 @@ String String::pad_zeros(int p_digits) const {
begin++;
}
- if (begin >= end)
+ if (begin >= end) {
return s;
+ }
while (end - begin < p_digits) {
s = s.insert(begin, "0");
@@ -3465,16 +3642,19 @@ String String::trim_suffix(const String &p_suffix) const {
bool String::is_valid_integer() const {
int len = length();
- if (len == 0)
+ if (len == 0) {
return false;
+ }
int from = 0;
- if (len != 1 && (operator[](0) == '+' || operator[](0) == '-'))
+ if (len != 1 && (operator[](0) == '+' || operator[](0) == '-')) {
from++;
+ }
for (int i = from; i < len; i++) {
- if (operator[](i) < '0' || operator[](i) > '9')
+ if (operator[](i) < '0' || operator[](i) > '9') {
return false; // no start with number plz
+ }
}
return true;
@@ -3483,16 +3663,19 @@ bool String::is_valid_integer() const {
bool String::is_valid_hex_number(bool p_with_prefix) const {
int len = length();
- if (len == 0)
+ if (len == 0) {
return false;
+ }
int from = 0;
- if (len != 1 && (operator[](0) == '+' || operator[](0) == '-'))
+ if (len != 1 && (operator[](0) == '+' || operator[](0) == '-')) {
from++;
+ }
if (p_with_prefix) {
- if (len < 3)
+ if (len < 3) {
return false;
+ }
if (operator[](from) != '0' || operator[](from + 1) != 'x') {
return false;
}
@@ -3501,8 +3684,9 @@ bool String::is_valid_hex_number(bool p_with_prefix) const {
for (int i = from; i < len; i++) {
CharType c = operator[](i);
- if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))
+ if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')) {
continue;
+ }
return false;
}
@@ -3512,8 +3696,9 @@ bool String::is_valid_hex_number(bool p_with_prefix) const {
bool String::is_valid_float() const {
int len = length();
- if (len == 0)
+ if (len == 0) {
return false;
+ }
int from = 0;
if (operator[](0) == '+' || operator[](0) == '-') {
@@ -3528,18 +3713,20 @@ bool String::is_valid_float() const {
for (int i = from; i < len; i++) {
if (operator[](i) >= '0' && operator[](i) <= '9') {
- if (exponent_found)
+ if (exponent_found) {
exponent_values_found = true;
- else
+ } else {
numbers_found = true;
+ }
} else if (numbers_found && !exponent_found && operator[](i) == 'e') {
exponent_found = true;
} else if (!period_found && !exponent_found && operator[](i) == '.') {
period_found = true;
} else if ((operator[](i) == '-' || operator[](i) == '+') && exponent_found && !exponent_values_found && !sign_found) {
sign_found = true;
- } else
+ } else {
return false; // no start with number plz
+ }
}
return numbers_found;
@@ -3550,19 +3737,22 @@ String String::path_to_file(const String &p_path) const {
String src = this->replace("\\", "/");
String dst = p_path.replace("\\", "/").get_base_dir();
String rel = src.path_to(dst);
- if (rel == dst) // failed
+ if (rel == dst) { // failed
return p_path;
- else
+ } else {
return rel + p_path.get_file();
+ }
}
String String::path_to(const String &p_path) const {
String src = this->replace("\\", "/");
String dst = p_path.replace("\\", "/");
- if (!src.ends_with("/"))
+ if (!src.ends_with("/")) {
src += "/";
- if (!dst.ends_with("/"))
+ }
+ if (!dst.ends_with("/")) {
dst += "/";
+ }
String base;
@@ -3583,8 +3773,9 @@ String String::path_to(const String &p_path) const {
String src_begin = src.get_slicec('/', 0);
String dst_begin = dst.get_slicec('/', 0);
- if (src_begin != dst_begin)
+ if (src_begin != dst_begin) {
return p_path; //impossible to do this
+ }
base = src_begin;
src = src.substr(src_begin.length(), src.length());
@@ -3599,12 +3790,15 @@ String String::path_to(const String &p_path) const {
int common_parent = 0;
while (true) {
- if (src_dirs.size() == common_parent)
+ if (src_dirs.size() == common_parent) {
break;
- if (dst_dirs.size() == common_parent)
+ }
+ if (dst_dirs.size() == common_parent) {
break;
- if (src_dirs[common_parent] != dst_dirs[common_parent])
+ }
+ if (src_dirs[common_parent] != dst_dirs[common_parent]) {
break;
+ }
common_parent++;
}
@@ -3620,8 +3814,9 @@ String String::path_to(const String &p_path) const {
dir += dst_dirs[i] + "/";
}
- if (dir.length() == 0)
+ if (dir.length() == 0) {
dir = "./";
+ }
return dir;
}
@@ -3647,29 +3842,35 @@ bool String::is_valid_ip_address() const {
Vector<String> ip = split(":");
for (int i = 0; i < ip.size(); i++) {
String n = ip[i];
- if (n.empty())
+ if (n.empty()) {
continue;
+ }
if (n.is_valid_hex_number(false)) {
int nint = n.hex_to_int(false);
- if (nint < 0 || nint > 0xffff)
+ if (nint < 0 || nint > 0xffff) {
return false;
+ }
continue;
};
- if (!n.is_valid_ip_address())
+ if (!n.is_valid_ip_address()) {
return false;
+ }
};
} else {
Vector<String> ip = split(".");
- if (ip.size() != 4)
+ if (ip.size() != 4) {
return false;
+ }
for (int i = 0; i < ip.size(); i++) {
String n = ip[i];
- if (!n.is_valid_integer())
+ if (!n.is_valid_integer()) {
return false;
+ }
int val = n.to_int();
- if (val < 0 || val > 255)
+ if (val < 0 || val > 255) {
return false;
+ }
}
};
@@ -3702,33 +3903,38 @@ String String::get_base_dir() const {
}
int sep = MAX(rs.find_last("/"), rs.find_last("\\"));
- if (sep == -1)
+ if (sep == -1) {
return base;
+ }
return base + rs.substr(0, sep);
}
String String::get_file() const {
int sep = MAX(find_last("/"), find_last("\\"));
- if (sep == -1)
+ if (sep == -1) {
return *this;
+ }
return substr(sep + 1, length());
}
String String::get_extension() const {
int pos = find_last(".");
- if (pos < 0 || pos < MAX(find_last("/"), find_last("\\")))
+ if (pos < 0 || pos < MAX(find_last("/"), find_last("\\"))) {
return "";
+ }
return substr(pos + 1, length());
}
String String::plus_file(const String &p_file) const {
- if (empty())
+ if (empty()) {
return p_file;
- if (operator[](length() - 1) == '/' || (p_file.size() > 0 && p_file.operator[](0) == '/'))
+ }
+ if (operator[](length() - 1) == '/' || (p_file.size() > 0 && p_file.operator[](0) == '/')) {
return *this + p_file;
+ }
return *this + "/" + p_file;
}
@@ -3763,21 +3969,23 @@ String String::percent_decode() const {
uint8_t a = LOWERCASE(cs[i + 1]);
uint8_t b = LOWERCASE(cs[i + 2]);
- if (a >= '0' && a <= '9')
+ if (a >= '0' && a <= '9') {
c = (a - '0') << 4;
- else if (a >= 'a' && a <= 'f')
+ } else if (a >= 'a' && a <= 'f') {
c = (a - 'a' + 10) << 4;
- else
+ } else {
continue;
+ }
uint8_t d = 0;
- if (b >= '0' && b <= '9')
+ if (b >= '0' && b <= '9') {
d = (b - '0');
- else if (b >= 'a' && b <= 'f')
+ } else if (b >= 'a' && b <= 'f') {
d = (b - 'a' + 10);
- else
+ } else {
continue;
+ }
c += d;
i += 2;
}
@@ -3802,8 +4010,9 @@ String String::property_name_encode() const {
String String::get_basename() const {
int pos = find_last(".");
- if (pos < 0 || pos < MAX(find_last("/"), find_last("\\")))
+ if (pos < 0 || pos < MAX(find_last("/"), find_last("\\"))) {
return *this;
+ }
return substr(0, pos);
}
@@ -3829,8 +4038,9 @@ String String::rpad(int min_length, const String &character) const {
String s = *this;
int padding = min_length - s.length();
if (padding > 0) {
- for (int i = 0; i < padding; i++)
+ for (int i = 0; i < padding; i++) {
s = s + character;
+ }
}
return s;
@@ -3841,8 +4051,9 @@ String String::lpad(int min_length, const String &character) const {
String s = *this;
int padding = min_length - s.length();
if (padding > 0) {
- for (int i = 0; i < padding; i++)
+ for (int i = 0; i < padding; i++) {
s = character + s;
+ }
}
return s;
diff --git a/core/ustring.h b/core/ustring.h
index 34f9c18bad..5b13a1c704 100644
--- a/core/ustring.h
+++ b/core/ustring.h
@@ -51,8 +51,9 @@ class CharProxy {
public:
_FORCE_INLINE_ operator T() const {
- if (unlikely(_index == _cowdata.size()))
+ if (unlikely(_index == _cowdata.size())) {
return _null;
+ }
return _cowdata.get(_index);
}
@@ -83,8 +84,9 @@ public:
_FORCE_INLINE_ char get(int p_index) const { return _cowdata.get(p_index); }
_FORCE_INLINE_ void set(int p_index, const char &p_elem) { _cowdata.set(p_index, p_elem); }
_FORCE_INLINE_ const char &operator[](int p_index) const {
- if (unlikely(p_index == _cowdata.size()))
+ if (unlikely(p_index == _cowdata.size())) {
return _null;
+ }
return _cowdata.get(p_index);
}
@@ -151,8 +153,9 @@ public:
Error resize(int p_size) { return _cowdata.resize(p_size); }
_FORCE_INLINE_ const CharType &operator[](int p_index) const {
- if (unlikely(p_index == _cowdata.size()))
+ if (unlikely(p_index == _cowdata.size())) {
return _null;
+ }
return _cowdata.get(p_index);
}
@@ -388,16 +391,17 @@ struct NaturalNoCaseComparator {
template <typename L, typename R>
_FORCE_INLINE_ bool is_str_less(const L *l_ptr, const R *r_ptr) {
while (true) {
- if (*l_ptr == 0 && *r_ptr == 0)
+ if (*l_ptr == 0 && *r_ptr == 0) {
return false;
- else if (*l_ptr == 0)
+ } else if (*l_ptr == 0) {
return true;
- else if (*r_ptr == 0)
+ } else if (*r_ptr == 0) {
return false;
- else if (*l_ptr < *r_ptr)
+ } else if (*l_ptr < *r_ptr) {
return true;
- else if (*l_ptr > *r_ptr)
+ } else if (*l_ptr > *r_ptr) {
return false;
+ }
l_ptr++;
r_ptr++;
diff --git a/core/variant.cpp b/core/variant.cpp
index 1098d031e5..62d710e493 100644
--- a/core/variant.cpp
+++ b/core/variant.cpp
@@ -182,10 +182,12 @@ String Variant::get_type_name(Variant::Type p_type) {
}
bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
- if (p_type_from == p_type_to)
+ if (p_type_from == p_type_to) {
return true;
- if (p_type_to == NIL && p_type_from != NIL) //nil can convert to anything
+ }
+ if (p_type_to == NIL && p_type_from != NIL) { //nil can convert to anything
return true;
+ }
if (p_type_from == NIL) {
return (p_type_to == OBJECT);
@@ -465,16 +467,18 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
if (valid_types) {
int i = 0;
while (valid_types[i] != NIL) {
- if (p_type_from == valid_types[i])
+ if (p_type_from == valid_types[i]) {
return true;
+ }
i++;
}
} else if (invalid_types) {
int i = 0;
while (invalid_types[i] != NIL) {
- if (p_type_from == invalid_types[i])
+ if (p_type_from == invalid_types[i]) {
return false;
+ }
i++;
}
@@ -485,10 +489,12 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
}
bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type_to) {
- if (p_type_from == p_type_to)
+ if (p_type_from == p_type_to) {
return true;
- if (p_type_to == NIL && p_type_from != NIL) //nil can convert to anything
+ }
+ if (p_type_to == NIL && p_type_from != NIL) { //nil can convert to anything
return true;
+ }
if (p_type_from == NIL) {
return (p_type_to == OBJECT);
@@ -768,8 +774,9 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type
if (valid_types) {
int i = 0;
while (valid_types[i] != NIL) {
- if (p_type_from == valid_types[i])
+ if (p_type_from == valid_types[i]) {
return true;
+ }
i++;
}
}
@@ -778,8 +785,9 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type
}
bool Variant::operator==(const Variant &p_variant) const {
- if (type != p_variant.type) //evaluation of operator== needs to be more strict
+ if (type != p_variant.type) { //evaluation of operator== needs to be more strict
return false;
+ }
bool v;
Variant r;
evaluate(OP_EQUAL, *this, p_variant, r, v);
@@ -787,8 +795,9 @@ bool Variant::operator==(const Variant &p_variant) const {
}
bool Variant::operator!=(const Variant &p_variant) const {
- if (type != p_variant.type) //evaluation of operator== needs to be more strict
+ if (type != p_variant.type) { //evaluation of operator== needs to be more strict
return true;
+ }
bool v;
Variant r;
evaluate(OP_NOT_EQUAL, *this, p_variant, r, v);
@@ -796,8 +805,9 @@ bool Variant::operator!=(const Variant &p_variant) const {
}
bool Variant::operator<(const Variant &p_variant) const {
- if (type != p_variant.type) //if types differ, then order by type first
+ if (type != p_variant.type) { //if types differ, then order by type first
return type < p_variant.type;
+ }
bool v;
Variant r;
evaluate(OP_LESS, *this, p_variant, r, v);
@@ -1678,14 +1688,16 @@ String Variant::stringify(List<const void *> &stack) const {
String mtx("(");
for (int i = 0; i < 3; i++) {
- if (i != 0)
+ if (i != 0) {
mtx += ", ";
+ }
mtx += "(";
for (int j = 0; j < 3; j++) {
- if (j != 0)
+ if (j != 0) {
mtx += ", ";
+ }
mtx += Variant(mat3.elements[i][j]).operator String();
}
@@ -1729,8 +1741,9 @@ String Variant::stringify(List<const void *> &stack) const {
pairs.sort();
for (int i = 0; i < pairs.size(); i++) {
- if (i > 0)
+ if (i > 0) {
str += ", ";
+ }
str += pairs[i].key + ":" + pairs[i].value;
}
str += "}";
@@ -1741,8 +1754,9 @@ String Variant::stringify(List<const void *> &stack) const {
Vector<Vector2> vec = operator Vector<Vector2>();
String str("[");
for (int i = 0; i < vec.size(); i++) {
- if (i > 0)
+ if (i > 0) {
str += ", ";
+ }
str = str + Variant(vec[i]);
}
str += "]";
@@ -1752,8 +1766,9 @@ String Variant::stringify(List<const void *> &stack) const {
Vector<Vector3> vec = operator Vector<Vector3>();
String str("[");
for (int i = 0; i < vec.size(); i++) {
- if (i > 0)
+ if (i > 0) {
str += ", ";
+ }
str = str + Variant(vec[i]);
}
str += "]";
@@ -1763,8 +1778,9 @@ String Variant::stringify(List<const void *> &stack) const {
Vector<String> vec = operator Vector<String>();
String str("[");
for (int i = 0; i < vec.size(); i++) {
- if (i > 0)
+ if (i > 0) {
str += ", ";
+ }
str = str + vec[i];
}
str += "]";
@@ -1774,8 +1790,9 @@ String Variant::stringify(List<const void *> &stack) const {
Vector<int32_t> vec = operator Vector<int32_t>();
String str("[");
for (int i = 0; i < vec.size(); i++) {
- if (i > 0)
+ if (i > 0) {
str += ", ";
+ }
str = str + itos(vec[i]);
}
str += "]";
@@ -1785,8 +1802,9 @@ String Variant::stringify(List<const void *> &stack) const {
Vector<int64_t> vec = operator Vector<int64_t>();
String str("[");
for (int i = 0; i < vec.size(); i++) {
- if (i > 0)
+ if (i > 0) {
str += ", ";
+ }
str = str + itos(vec[i]);
}
str += "]";
@@ -1796,8 +1814,9 @@ String Variant::stringify(List<const void *> &stack) const {
Vector<float> vec = operator Vector<float>();
String str("[");
for (int i = 0; i < vec.size(); i++) {
- if (i > 0)
+ if (i > 0) {
str += ", ";
+ }
str = str + rtos(vec[i]);
}
str += "]";
@@ -1807,8 +1826,9 @@ String Variant::stringify(List<const void *> &stack) const {
Vector<double> vec = operator Vector<double>();
String str("[");
for (int i = 0; i < vec.size(); i++) {
- if (i > 0)
+ if (i > 0) {
str += ", ";
+ }
str = str + rtos(vec[i]);
}
str += "]";
@@ -1823,8 +1843,9 @@ String Variant::stringify(List<const void *> &stack) const {
String str("[");
for (int i = 0; i < arr.size(); i++) {
- if (i)
+ if (i) {
str += ", ";
+ }
str += arr[i].stringify(stack);
}
@@ -1840,8 +1861,9 @@ String Variant::stringify(List<const void *> &stack) const {
};
return _get_obj().obj->to_string();
- } else
+ } else {
return "[Object:null]";
+ }
} break;
case CALLABLE: {
@@ -1865,121 +1887,131 @@ String Variant::stringify(List<const void *> &stack) const {
}
Variant::operator Vector2() const {
- if (type == VECTOR2)
+ if (type == VECTOR2) {
return *reinterpret_cast<const Vector2 *>(_data._mem);
- else if (type == VECTOR2I)
+ } else if (type == VECTOR2I) {
return *reinterpret_cast<const Vector2i *>(_data._mem);
- else if (type == VECTOR3)
+ } else if (type == VECTOR3) {
return Vector2(reinterpret_cast<const Vector3 *>(_data._mem)->x, reinterpret_cast<const Vector3 *>(_data._mem)->y);
- else if (type == VECTOR3I)
+ } else if (type == VECTOR3I) {
return Vector2(reinterpret_cast<const Vector3i *>(_data._mem)->x, reinterpret_cast<const Vector3i *>(_data._mem)->y);
- else
+ } else {
return Vector2();
+ }
}
Variant::operator Vector2i() const {
- if (type == VECTOR2I)
+ if (type == VECTOR2I) {
return *reinterpret_cast<const Vector2i *>(_data._mem);
- else if (type == VECTOR2)
+ } else if (type == VECTOR2) {
return *reinterpret_cast<const Vector2 *>(_data._mem);
- else if (type == VECTOR3)
+ } else if (type == VECTOR3) {
return Vector2(reinterpret_cast<const Vector3 *>(_data._mem)->x, reinterpret_cast<const Vector3 *>(_data._mem)->y);
- else if (type == VECTOR3I)
+ } else if (type == VECTOR3I) {
return Vector2(reinterpret_cast<const Vector3i *>(_data._mem)->x, reinterpret_cast<const Vector3i *>(_data._mem)->y);
- else
+ } else {
return Vector2i();
+ }
}
Variant::operator Rect2() const {
- if (type == RECT2)
+ if (type == RECT2) {
return *reinterpret_cast<const Rect2 *>(_data._mem);
- else if (type == RECT2I)
+ } else if (type == RECT2I) {
return *reinterpret_cast<const Rect2i *>(_data._mem);
- else
+ } else {
return Rect2();
+ }
}
Variant::operator Rect2i() const {
- if (type == RECT2I)
+ if (type == RECT2I) {
return *reinterpret_cast<const Rect2i *>(_data._mem);
- else if (type == RECT2)
+ } else if (type == RECT2) {
return *reinterpret_cast<const Rect2 *>(_data._mem);
- else
+ } else {
return Rect2i();
+ }
}
Variant::operator Vector3() const {
- if (type == VECTOR3)
+ if (type == VECTOR3) {
return *reinterpret_cast<const Vector3 *>(_data._mem);
- else if (type == VECTOR3I)
+ } else if (type == VECTOR3I) {
return *reinterpret_cast<const Vector3i *>(_data._mem);
- else if (type == VECTOR2)
+ } else if (type == VECTOR2) {
return Vector3(reinterpret_cast<const Vector2 *>(_data._mem)->x, reinterpret_cast<const Vector2 *>(_data._mem)->y, 0.0);
- else if (type == VECTOR2I)
+ } else if (type == VECTOR2I) {
return Vector3(reinterpret_cast<const Vector2i *>(_data._mem)->x, reinterpret_cast<const Vector2i *>(_data._mem)->y, 0.0);
- else
+ } else {
return Vector3();
+ }
}
Variant::operator Vector3i() const {
- if (type == VECTOR3I)
+ if (type == VECTOR3I) {
return *reinterpret_cast<const Vector3i *>(_data._mem);
- else if (type == VECTOR3)
+ } else if (type == VECTOR3) {
return *reinterpret_cast<const Vector3 *>(_data._mem);
- else if (type == VECTOR2)
+ } else if (type == VECTOR2) {
return Vector3i(reinterpret_cast<const Vector2 *>(_data._mem)->x, reinterpret_cast<const Vector2 *>(_data._mem)->y, 0.0);
- else if (type == VECTOR2I)
+ } else if (type == VECTOR2I) {
return Vector3i(reinterpret_cast<const Vector2i *>(_data._mem)->x, reinterpret_cast<const Vector2i *>(_data._mem)->y, 0.0);
- else
+ } else {
return Vector3i();
+ }
}
Variant::operator Plane() const {
- if (type == PLANE)
+ if (type == PLANE) {
return *reinterpret_cast<const Plane *>(_data._mem);
- else
+ } else {
return Plane();
+ }
}
Variant::operator ::AABB() const {
- if (type == AABB)
+ if (type == AABB) {
return *_data._aabb;
- else
+ } else {
return ::AABB();
+ }
}
Variant::operator Basis() const {
- if (type == BASIS)
+ if (type == BASIS) {
return *_data._basis;
- else if (type == QUAT)
+ } else if (type == QUAT) {
return *reinterpret_cast<const Quat *>(_data._mem);
- else if (type == VECTOR3) {
+ } else if (type == VECTOR3) {
return Basis(*reinterpret_cast<const Vector3 *>(_data._mem));
- } else if (type == TRANSFORM) // unexposed in Variant::can_convert?
+ } else if (type == TRANSFORM) { // unexposed in Variant::can_convert?
return _data._transform->basis;
- else
+ } else {
return Basis();
+ }
}
Variant::operator Quat() const {
- if (type == QUAT)
+ if (type == QUAT) {
return *reinterpret_cast<const Quat *>(_data._mem);
- else if (type == BASIS)
+ } else if (type == BASIS) {
return *_data._basis;
- else if (type == TRANSFORM)
+ } else if (type == TRANSFORM) {
return _data._transform->basis;
- else
+ } else {
return Quat();
+ }
}
Variant::operator Transform() const {
- if (type == TRANSFORM)
+ if (type == TRANSFORM) {
return *_data._transform;
- else if (type == BASIS)
+ } else if (type == BASIS) {
return Transform(*_data._basis, Vector3());
- else if (type == QUAT)
+ } else if (type == QUAT) {
return Transform(Basis(*reinterpret_cast<const Quat *>(_data._mem)), Vector3());
- else if (type == TRANSFORM2D) {
+ } else if (type == TRANSFORM2D) {
const Transform2D &t = *_data._transform2d;
Transform m;
m.basis.elements[0][0] = t.elements[0][0];
@@ -1989,8 +2021,9 @@ Variant::operator Transform() const {
m.origin[0] = t.elements[2][0];
m.origin[1] = t.elements[2][1];
return m;
- } else
+ } else {
return Transform();
+ }
}
Variant::operator Transform2D() const {
@@ -2006,34 +2039,37 @@ Variant::operator Transform2D() const {
m.elements[2][0] = t.origin[0];
m.elements[2][1] = t.origin[1];
return m;
- } else
+ } else {
return Transform2D();
+ }
}
Variant::operator Color() const {
- if (type == COLOR)
+ if (type == COLOR) {
return *reinterpret_cast<const Color *>(_data._mem);
- else if (type == STRING)
+ } else if (type == STRING) {
return Color::html(operator String());
- else if (type == INT)
+ } else if (type == INT) {
return Color::hex(operator int());
- else
+ } else {
return Color();
+ }
}
Variant::operator NodePath() const {
- if (type == NODE_PATH)
+ if (type == NODE_PATH) {
return *reinterpret_cast<const NodePath *>(_data._mem);
- else if (type == STRING)
+ } else if (type == STRING) {
return NodePath(operator String());
- else
+ } else {
return NodePath();
+ }
}
Variant::operator RID() const {
- if (type == _RID)
+ if (type == _RID) {
return *reinterpret_cast<const RID *>(_data._mem);
- else if (type == OBJECT && _get_obj().obj == nullptr) {
+ } else if (type == OBJECT && _get_obj().obj == nullptr) {
return RID();
} else if (type == OBJECT && _get_obj().obj) {
#ifdef DEBUG_ENABLED
@@ -2053,10 +2089,11 @@ Variant::operator RID() const {
}
Variant::operator Object *() const {
- if (type == OBJECT)
+ if (type == OBJECT) {
return _get_obj().obj;
- else
+ } else {
return nullptr;
+ }
}
Object *Variant::get_validated_object_with_check(bool &r_previously_freed) const {
@@ -2071,45 +2108,51 @@ Object *Variant::get_validated_object_with_check(bool &r_previously_freed) const
}
Object *Variant::get_validated_object() const {
- if (type == OBJECT)
+ if (type == OBJECT) {
return ObjectDB::get_instance(_get_obj().id);
- else
+ } else {
return nullptr;
+ }
}
Variant::operator Node *() const {
- if (type == OBJECT)
+ if (type == OBJECT) {
return Object::cast_to<Node>(_get_obj().obj);
- else
+ } else {
return nullptr;
+ }
}
Variant::operator Control *() const {
- if (type == OBJECT)
+ if (type == OBJECT) {
return Object::cast_to<Control>(_get_obj().obj);
- else
+ } else {
return nullptr;
+ }
}
Variant::operator Dictionary() const {
- if (type == DICTIONARY)
+ if (type == DICTIONARY) {
return *reinterpret_cast<const Dictionary *>(_data._mem);
- else
+ } else {
return Dictionary();
+ }
}
Variant::operator Callable() const {
- if (type == CALLABLE)
+ if (type == CALLABLE) {
return *reinterpret_cast<const Callable *>(_data._mem);
- else
+ } else {
return Callable();
+ }
}
Variant::operator Signal() const {
- if (type == SIGNAL)
+ if (type == SIGNAL) {
return *reinterpret_cast<const Signal *>(_data._mem);
- else
+ } else {
return Signal();
+ }
}
template <class DA, class SA>
@@ -2164,73 +2207,83 @@ inline DA _convert_array_from_variant(const Variant &p_variant) {
}
Variant::operator Array() const {
- if (type == ARRAY)
+ if (type == ARRAY) {
return *reinterpret_cast<const Array *>(_data._mem);
- else
+ } else {
return _convert_array_from_variant<Array>(*this);
+ }
}
Variant::operator Vector<uint8_t>() const {
- if (type == PACKED_BYTE_ARRAY)
+ if (type == PACKED_BYTE_ARRAY) {
return static_cast<PackedArrayRef<uint8_t> *>(_data.packed_array)->array;
- else
+ } else {
return _convert_array_from_variant<Vector<uint8_t>>(*this);
+ }
}
Variant::operator Vector<int32_t>() const {
- if (type == PACKED_INT32_ARRAY)
+ if (type == PACKED_INT32_ARRAY) {
return static_cast<PackedArrayRef<int32_t> *>(_data.packed_array)->array;
- else
+ } else {
return _convert_array_from_variant<Vector<int>>(*this);
+ }
}
Variant::operator Vector<int64_t>() const {
- if (type == PACKED_INT64_ARRAY)
+ if (type == PACKED_INT64_ARRAY) {
return static_cast<PackedArrayRef<int64_t> *>(_data.packed_array)->array;
- else
+ } else {
return _convert_array_from_variant<Vector<int64_t>>(*this);
+ }
}
Variant::operator Vector<float>() const {
- if (type == PACKED_FLOAT32_ARRAY)
+ if (type == PACKED_FLOAT32_ARRAY) {
return static_cast<PackedArrayRef<float> *>(_data.packed_array)->array;
- else
+ } else {
return _convert_array_from_variant<Vector<float>>(*this);
+ }
}
Variant::operator Vector<double>() const {
- if (type == PACKED_FLOAT64_ARRAY)
+ if (type == PACKED_FLOAT64_ARRAY) {
return static_cast<PackedArrayRef<double> *>(_data.packed_array)->array;
- else
+ } else {
return _convert_array_from_variant<Vector<double>>(*this);
+ }
}
Variant::operator Vector<String>() const {
- if (type == PACKED_STRING_ARRAY)
+ if (type == PACKED_STRING_ARRAY) {
return static_cast<PackedArrayRef<String> *>(_data.packed_array)->array;
- else
+ } else {
return _convert_array_from_variant<Vector<String>>(*this);
+ }
}
Variant::operator Vector<Vector3>() const {
- if (type == PACKED_VECTOR3_ARRAY)
+ if (type == PACKED_VECTOR3_ARRAY) {
return static_cast<PackedArrayRef<Vector3> *>(_data.packed_array)->array;
- else
+ } else {
return _convert_array_from_variant<Vector<Vector3>>(*this);
+ }
}
Variant::operator Vector<Vector2>() const {
- if (type == PACKED_VECTOR2_ARRAY)
+ if (type == PACKED_VECTOR2_ARRAY) {
return static_cast<PackedArrayRef<Vector2> *>(_data.packed_array)->array;
- else
+ } else {
return _convert_array_from_variant<Vector<Vector2>>(*this);
+ }
}
Variant::operator Vector<Color>() const {
- if (type == PACKED_COLOR_ARRAY)
+ if (type == PACKED_COLOR_ARRAY) {
return static_cast<PackedArrayRef<Color> *>(_data.packed_array)->array;
- else
+ } else {
return _convert_array_from_variant<Vector<Color>>(*this);
+ }
}
/* helpers */
@@ -2239,8 +2292,9 @@ Variant::operator Vector<RID>() const {
Array va = operator Array();
Vector<RID> rids;
rids.resize(va.size());
- for (int i = 0; i < rids.size(); i++)
+ for (int i = 0; i < rids.size(); i++) {
rids.write[i] = va[i];
+ }
return rids;
}
@@ -2248,14 +2302,16 @@ Variant::operator Vector<Plane>() const {
Array va = operator Array();
Vector<Plane> planes;
int va_size = va.size();
- if (va_size == 0)
+ if (va_size == 0) {
return planes;
+ }
planes.resize(va_size);
Plane *w = planes.ptrw();
- for (int i = 0; i < va_size; i++)
+ for (int i = 0; i < va_size; i++) {
w[i] = va[i];
+ }
return planes;
}
@@ -2264,15 +2320,17 @@ Variant::operator Vector<Face3>() const {
Vector<Vector3> va = operator Vector<Vector3>();
Vector<Face3> faces;
int va_size = va.size();
- if (va_size == 0)
+ if (va_size == 0) {
return faces;
+ }
faces.resize(va_size / 3);
Face3 *w = faces.ptrw();
const Vector3 *r = va.ptr();
- for (int i = 0; i < va_size; i++)
+ for (int i = 0; i < va_size; i++) {
w[i / 3].vertex[i % 3] = r[i];
+ }
return faces;
}
@@ -2281,13 +2339,15 @@ Variant::operator Vector<Variant>() const {
Array va = operator Array();
Vector<Variant> variants;
int va_size = va.size();
- if (va_size == 0)
+ if (va_size == 0) {
return variants;
+ }
variants.resize(va_size);
Variant *w = variants.ptrw();
- for (int i = 0; i < va_size; i++)
+ for (int i = 0; i < va_size; i++) {
w[i] = va[i];
+ }
return variants;
}
@@ -2621,8 +2681,9 @@ Variant::Variant(const Vector<Face3> &p_face_array) {
Vector3 *w = vertices.ptrw();
for (int i = 0; i < face_count; i++) {
- for (int j = 0; j < 3; j++)
+ for (int j = 0; j < 3; j++) {
w[i * 3 + j] = r[i].vertex[j];
+ }
}
}
@@ -2647,14 +2708,16 @@ Variant::Variant(const Vector<StringName> &p_array) {
Vector<String> v;
int len = p_array.size();
v.resize(len);
- for (int i = 0; i < len; i++)
+ for (int i = 0; i < len; i++) {
v.set(i, p_array[i]);
+ }
*this = v;
}
void Variant::operator=(const Variant &p_variant) {
- if (unlikely(this == &p_variant))
+ if (unlikely(this == &p_variant)) {
return;
+ }
if (unlikely(type != p_variant.type)) {
reference(p_variant);
@@ -3132,8 +3195,9 @@ uint32_t Variant::hash() const {
return true
bool Variant::hash_compare(const Variant &p_variant) const {
- if (type != p_variant.type)
+ if (type != p_variant.type) {
return false;
+ }
switch (type) {
case FLOAT: {
@@ -3171,8 +3235,9 @@ bool Variant::hash_compare(const Variant &p_variant) const {
Transform2D *r = p_variant._data._transform2d;
for (int i = 0; i < 3; i++) {
- if (!(hash_compare_vector2(l->elements[i], r->elements[i])))
+ if (!(hash_compare_vector2(l->elements[i], r->elements[i]))) {
return false;
+ }
}
return true;
@@ -3220,8 +3285,9 @@ bool Variant::hash_compare(const Variant &p_variant) const {
const Basis *r = p_variant._data._basis;
for (int i = 0; i < 3; i++) {
- if (!(hash_compare_vector3(l->elements[i], r->elements[i])))
+ if (!(hash_compare_vector3(l->elements[i], r->elements[i]))) {
return false;
+ }
}
return true;
@@ -3232,8 +3298,9 @@ bool Variant::hash_compare(const Variant &p_variant) const {
const Transform *r = p_variant._data._transform;
for (int i = 0; i < 3; i++) {
- if (!(hash_compare_vector3(l->basis.elements[i], r->basis.elements[i])))
+ if (!(hash_compare_vector3(l->basis.elements[i], r->basis.elements[i]))) {
return false;
+ }
}
return hash_compare_vector3(l->origin, r->origin);
@@ -3250,12 +3317,14 @@ bool Variant::hash_compare(const Variant &p_variant) const {
const Array &l = *(reinterpret_cast<const Array *>(_data._mem));
const Array &r = *(reinterpret_cast<const Array *>(p_variant._data._mem));
- if (l.size() != r.size())
+ if (l.size() != r.size()) {
return false;
+ }
for (int i = 0; i < l.size(); ++i) {
- if (!l[i].hash_compare(r[i]))
+ if (!l[i].hash_compare(r[i])) {
return false;
+ }
}
return true;
@@ -3362,8 +3431,9 @@ Variant Variant::call(const StringName &p_method, VARIANT_ARG_DECLARE) {
VARIANT_ARGPTRS;
int argc = 0;
for (int i = 0; i < VARIANT_ARG_MAX; i++) {
- if (argptr[i]->get_type() == Variant::NIL)
+ if (argptr[i]->get_type() == Variant::NIL) {
break;
+ }
argc++;
}
diff --git a/core/variant.h b/core/variant.h
index 70de8479e3..b24cf968de 100644
--- a/core/variant.h
+++ b/core/variant.h
@@ -471,8 +471,9 @@ public:
Variant(const Variant &p_variant);
_FORCE_INLINE_ Variant() {}
_FORCE_INLINE_ ~Variant() {
- if (type != Variant::NIL)
+ if (type != Variant::NIL) {
clear();
+ }
}
};
diff --git a/core/variant_call.cpp b/core/variant_call.cpp
index 61b1e91d6c..82b1f29805 100644
--- a/core/variant_call.cpp
+++ b/core/variant_call.cpp
@@ -59,14 +59,16 @@ struct _VariantCall {
VariantFunc func;
_FORCE_INLINE_ bool verify_arguments(const Variant **p_args, Callable::CallError &r_error) {
- if (arg_count == 0)
+ if (arg_count == 0) {
return true;
+ }
const Variant::Type *tptr = &arg_types[0];
for (int i = 0; i < arg_count; i++) {
- if (tptr[i] == Variant::NIL || tptr[i] == p_args[i]->type)
+ if (tptr[i] == Variant::NIL || tptr[i] == p_args[i]->type) {
continue; // all good
+ }
if (!Variant::can_convert(p_args[i]->type, tptr[i])) {
r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT;
r_error.argument = i;
@@ -97,21 +99,25 @@ struct _VariantCall {
#endif
ERR_FAIL_COND(p_argcount > VARIANT_ARG_MAX);
const Variant *newargs[VARIANT_ARG_MAX];
- for (int i = 0; i < p_argcount; i++)
+ for (int i = 0; i < p_argcount; i++) {
newargs[i] = p_args[i];
+ }
// fill in any remaining parameters with defaults
int first_default_arg = arg_count - def_argcount;
- for (int i = p_argcount; i < arg_count; i++)
+ for (int i = p_argcount; i < arg_count; i++) {
newargs[i] = &default_args[i - first_default_arg];
+ }
#ifdef DEBUG_ENABLED
- if (!verify_arguments(newargs, r_error))
+ if (!verify_arguments(newargs, r_error)) {
return;
+ }
#endif
func(r_ret, p_self, newargs);
} else {
#ifdef DEBUG_ENABLED
- if (!verify_arguments(p_args, r_error))
+ if (!verify_arguments(p_args, r_error)) {
return;
+ }
#endif
func(r_ret, p_self, p_args);
}
@@ -156,8 +162,9 @@ struct _VariantCall {
funcdata.arg_names.push_back(p_argtype1.name);
#endif
- } else
+ } else {
goto end;
+ }
if (p_argtype2.name) {
funcdata.arg_types.push_back(p_argtype2.type);
@@ -165,8 +172,9 @@ struct _VariantCall {
funcdata.arg_names.push_back(p_argtype2.name);
#endif
- } else
+ } else {
goto end;
+ }
if (p_argtype3.name) {
funcdata.arg_types.push_back(p_argtype3.type);
@@ -174,24 +182,27 @@ struct _VariantCall {
funcdata.arg_names.push_back(p_argtype3.name);
#endif
- } else
+ } else {
goto end;
+ }
if (p_argtype4.name) {
funcdata.arg_types.push_back(p_argtype4.type);
#ifdef DEBUG_ENABLED
funcdata.arg_names.push_back(p_argtype4.name);
#endif
- } else
+ } else {
goto end;
+ }
if (p_argtype5.name) {
funcdata.arg_types.push_back(p_argtype5.type);
#ifdef DEBUG_ENABLED
funcdata.arg_names.push_back(p_argtype5.name);
#endif
- } else
+ } else {
goto end;
+ }
end:
@@ -455,26 +466,29 @@ struct _VariantCall {
//return vector3 if intersected, nil if not
static void _call_Plane_intersect_3(Variant &r_ret, Variant &p_self, const Variant **p_args) {
Vector3 result;
- if (reinterpret_cast<Plane *>(p_self._data._mem)->intersect_3(*p_args[0], *p_args[1], &result))
+ if (reinterpret_cast<Plane *>(p_self._data._mem)->intersect_3(*p_args[0], *p_args[1], &result)) {
r_ret = result;
- else
+ } else {
r_ret = Variant();
+ }
}
static void _call_Plane_intersects_ray(Variant &r_ret, Variant &p_self, const Variant **p_args) {
Vector3 result;
- if (reinterpret_cast<Plane *>(p_self._data._mem)->intersects_ray(*p_args[0], *p_args[1], &result))
+ if (reinterpret_cast<Plane *>(p_self._data._mem)->intersects_ray(*p_args[0], *p_args[1], &result)) {
r_ret = result;
- else
+ } else {
r_ret = Variant();
+ }
}
static void _call_Plane_intersects_segment(Variant &r_ret, Variant &p_self, const Variant **p_args) {
Vector3 result;
- if (reinterpret_cast<Plane *>(p_self._data._mem)->intersects_segment(*p_args[0], *p_args[1], &result))
+ if (reinterpret_cast<Plane *>(p_self._data._mem)->intersects_segment(*p_args[0], *p_args[1], &result)) {
r_ret = result;
- else
+ } else {
r_ret = Variant();
+ }
}
VCALL_LOCALMEM0R(Quat, length);
@@ -1121,26 +1135,30 @@ struct _VariantCall {
cd.func = p_func;
cd.arg_count = 0;
- if (p_name1 == "")
+ if (p_name1 == "") {
goto end;
+ }
cd.arg_count++;
cd.arg_names.push_back(p_name1);
cd.arg_types.push_back(p_type1);
- if (p_name2 == "")
+ if (p_name2 == "") {
goto end;
+ }
cd.arg_count++;
cd.arg_names.push_back(p_name2);
cd.arg_types.push_back(p_type2);
- if (p_name3 == "")
+ if (p_name3 == "") {
goto end;
+ }
cd.arg_count++;
cd.arg_names.push_back(p_name3);
cd.arg_types.push_back(p_type3);
- if (p_name4 == "")
+ if (p_name4 == "") {
goto end;
+ }
cd.arg_count++;
cd.arg_names.push_back(p_name4);
cd.arg_types.push_back(p_type4);
@@ -1241,8 +1259,9 @@ void Variant::call_ptr(const StringName &p_method, const Variant **p_args, int p
}
}
- if (r_error.error == Callable::CallError::CALL_OK && r_ret)
+ if (r_error.error == Callable::CallError::CALL_OK && r_ret) {
*r_ret = ret;
+ }
}
#define VCALL(m_type, m_method) _VariantCall::_call_##m_type##_##m_method
@@ -1425,8 +1444,9 @@ Variant Variant::construct(const Variant::Type p_type, const Variant **p_args, i
for (List<_VariantCall::ConstructData>::Element *E = c.constructors.front(); E; E = E->next()) {
const _VariantCall::ConstructData &cd = E->get();
- if (cd.arg_count != p_argcount)
+ if (cd.arg_count != p_argcount) {
continue;
+ }
//validate parameters
for (int i = 0; i < cd.arg_count; i++) {
@@ -1450,8 +1470,9 @@ Variant Variant::construct(const Variant::Type p_type, const Variant **p_args, i
bool Variant::has_method(const StringName &p_method) const {
if (type == OBJECT) {
Object *obj = get_validated_object();
- if (!obj)
+ if (!obj) {
return false;
+ }
return obj->has_method(p_method);
}
@@ -1464,8 +1485,9 @@ Vector<Variant::Type> Variant::get_method_argument_types(Variant::Type p_type, c
const _VariantCall::TypeFunc &tf = _VariantCall::type_funcs[p_type];
const Map<StringName, _VariantCall::FuncData>::Element *E = tf.functions.find(p_method);
- if (!E)
+ if (!E) {
return Vector<Variant::Type>();
+ }
return E->get().arg_types;
}
@@ -1474,8 +1496,9 @@ bool Variant::is_method_const(Variant::Type p_type, const StringName &p_method)
const _VariantCall::TypeFunc &tf = _VariantCall::type_funcs[p_type];
const Map<StringName, _VariantCall::FuncData>::Element *E = tf.functions.find(p_method);
- if (!E)
+ if (!E) {
return false;
+ }
return E->get()._const;
}
@@ -1484,8 +1507,9 @@ Vector<StringName> Variant::get_method_argument_names(Variant::Type p_type, cons
const _VariantCall::TypeFunc &tf = _VariantCall::type_funcs[p_type];
const Map<StringName, _VariantCall::FuncData>::Element *E = tf.functions.find(p_method);
- if (!E)
+ if (!E) {
return Vector<StringName>();
+ }
return E->get().arg_names;
}
@@ -1494,11 +1518,13 @@ Variant::Type Variant::get_method_return_type(Variant::Type p_type, const String
const _VariantCall::TypeFunc &tf = _VariantCall::type_funcs[p_type];
const Map<StringName, _VariantCall::FuncData>::Element *E = tf.functions.find(p_method);
- if (!E)
+ if (!E) {
return Variant::NIL;
+ }
- if (r_has_return)
+ if (r_has_return) {
*r_has_return = E->get().returns;
+ }
return E->get().return_type;
}
@@ -1507,8 +1533,9 @@ Vector<Variant> Variant::get_method_default_arguments(Variant::Type p_type, cons
const _VariantCall::TypeFunc &tf = _VariantCall::type_funcs[p_type];
const Map<StringName, _VariantCall::FuncData>::Element *E = tf.functions.find(p_method);
- if (!E)
+ if (!E) {
return Vector<Variant>();
+ }
return E->get().default_args;
}
@@ -1541,8 +1568,9 @@ void Variant::get_method_list(List<MethodInfo> *p_list) const {
ret.type = fd.return_type;
if (fd.returns) {
ret.name = "ret";
- if (fd.return_type == Variant::NIL)
+ if (fd.return_type == Variant::NIL) {
ret.usage = PROPERTY_USAGE_NIL_IS_VARIANT;
+ }
}
mi.return_val = ret;
#endif
@@ -1592,10 +1620,12 @@ void Variant::get_constructor_list(Variant::Type p_type, List<MethodInfo> *p_lis
}
//default constructors
for (int i = 0; i < VARIANT_MAX; i++) {
- if (i == p_type)
+ if (i == p_type) {
continue;
- if (!Variant::can_convert(Variant::Type(i), p_type))
+ }
+ if (!Variant::can_convert(Variant::Type(i), p_type)) {
continue;
+ }
MethodInfo mi;
mi.name = Variant::get_type_name(p_type);
@@ -1634,8 +1664,9 @@ bool Variant::has_constant(Variant::Type p_type, const StringName &p_value) {
}
Variant Variant::get_constant_value(Variant::Type p_type, const StringName &p_value, bool *r_valid) {
- if (r_valid)
+ if (r_valid) {
*r_valid = false;
+ }
ERR_FAIL_INDEX_V(p_type, Variant::VARIANT_MAX, 0);
_VariantCall::ConstantData &cd = _VariantCall::constant_data[p_type];
@@ -1644,15 +1675,17 @@ Variant Variant::get_constant_value(Variant::Type p_type, const StringName &p_va
if (!E) {
Map<StringName, Variant>::Element *F = cd.variant_value.find(p_value);
if (F) {
- if (r_valid)
+ if (r_valid) {
*r_valid = true;
+ }
return F->get();
} else {
return -1;
}
}
- if (r_valid)
+ if (r_valid) {
*r_valid = true;
+ }
return E->get();
}
diff --git a/core/variant_op.cpp b/core/variant_op.cpp
index 1d75d52db0..8641187f97 100644
--- a/core/variant_op.cpp
+++ b/core/variant_op.cpp
@@ -916,10 +916,12 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a,
int asize = array_a.size();
int bsize = array_b.size();
sum.resize(asize + bsize);
- for (int i = 0; i < asize; i++)
+ for (int i = 0; i < asize; i++) {
sum[i] = array_a[i];
- for (int i = 0; i < bsize; i++)
+ }
+ for (int i = 0; i < bsize; i++) {
sum[i + asize] = array_b[i];
+ }
_RETURN(sum);
}
@@ -1946,13 +1948,15 @@ Variant Variant::get_named(const StringName &p_index, bool *r_valid) const {
case OBJECT: {
#ifdef DEBUG_ENABLED
if (!_get_obj().obj) {
- if (r_valid)
+ if (r_valid) {
*r_valid = false;
+ }
return "Instance base is null.";
} else {
if (EngineDebugger::is_active() && !_get_obj().id.is_reference() && ObjectDB::get_instance(_get_obj().id) == nullptr) {
- if (r_valid)
+ if (r_valid) {
*r_valid = false;
+ }
return "Attempted use of stray pointer object.";
}
}
@@ -2043,16 +2047,19 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid)
return;
} break;
case STRING: {
- if (p_index.type != Variant::INT && p_index.type != Variant::FLOAT)
+ if (p_index.type != Variant::INT && p_index.type != Variant::FLOAT) {
return;
+ }
int idx = p_index;
String *str = reinterpret_cast<String *>(_data._mem);
int len = str->length();
- if (idx < 0)
+ if (idx < 0) {
idx += len;
- if (idx < 0 || idx >= len)
+ }
+ if (idx < 0 || idx >= len) {
return;
+ }
String chr;
if (p_value.type == Variant::INT || p_value.type == Variant::FLOAT) {
@@ -2069,15 +2076,17 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid)
} break;
case VECTOR2: {
- if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT)
+ if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) {
return;
+ }
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) {
// scalar index
int idx = p_index;
- if (idx < 0)
+ if (idx < 0) {
idx += 2;
+ }
if (idx >= 0 && idx < 2) {
Vector2 *v = reinterpret_cast<Vector2 *>(_data._mem);
valid = true;
@@ -2102,15 +2111,17 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid)
} break;
case VECTOR2I: {
- if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT)
+ if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) {
return;
+ }
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) {
// scalar index
int idx = p_index;
- if (idx < 0)
+ if (idx < 0) {
idx += 2;
+ }
if (idx >= 0 && idx < 2) {
Vector2i *v = reinterpret_cast<Vector2i *>(_data._mem);
valid = true;
@@ -2135,8 +2146,9 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid)
} break;
case RECT2: {
- if (p_value.type != Variant::VECTOR2)
+ if (p_value.type != Variant::VECTOR2) {
return;
+ }
if (p_index.get_type() == Variant::STRING) {
//scalar name
@@ -2159,8 +2171,9 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid)
}
} break;
case RECT2I: {
- if (p_value.type != Variant::VECTOR2I)
+ if (p_value.type != Variant::VECTOR2I) {
return;
+ }
if (p_index.get_type() == Variant::STRING) {
//scalar name
@@ -2183,14 +2196,16 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid)
}
} break;
case TRANSFORM2D: {
- if (p_value.type != Variant::VECTOR2)
+ if (p_value.type != Variant::VECTOR2) {
return;
+ }
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) {
int index = p_index;
- if (index < 0)
+ if (index < 0) {
index += 3;
+ }
if (index >= 0 && index < 3) {
Transform2D *v = _data._transform2d;
@@ -2219,14 +2234,16 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid)
} break;
case VECTOR3: {
- if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT)
+ if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) {
return;
+ }
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) {
//scalar index
int idx = p_index;
- if (idx < 0)
+ if (idx < 0) {
idx += 3;
+ }
if (idx >= 0 && idx < 3) {
Vector3 *v = reinterpret_cast<Vector3 *>(_data._mem);
valid = true;
@@ -2254,14 +2271,16 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid)
} break;
case VECTOR3I: {
- if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT)
+ if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) {
return;
+ }
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) {
//scalar index
int idx = p_index;
- if (idx < 0)
+ if (idx < 0) {
idx += 3;
+ }
if (idx >= 0 && idx < 3) {
Vector3i *v = reinterpret_cast<Vector3i *>(_data._mem);
valid = true;
@@ -2294,29 +2313,33 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid)
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
Plane *v = reinterpret_cast<Plane *>(_data._mem);
if (*str == "x") {
- if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT)
+ if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) {
return;
+ }
valid = true;
v->normal.x = p_value;
return;
} else if (*str == "y") {
- if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT)
+ if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) {
return;
+ }
valid = true;
v->normal.y = p_value;
return;
} else if (*str == "z") {
- if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT)
+ if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) {
return;
+ }
valid = true;
v->normal.z = p_value;
return;
} else if (*str == "normal") {
- if (p_value.type != Variant::VECTOR3)
+ if (p_value.type != Variant::VECTOR3) {
return;
+ }
valid = true;
v->normal = p_value;
@@ -2330,8 +2353,9 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid)
} break;
case QUAT: {
- if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT)
+ if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) {
return;
+ }
if (p_index.get_type() == Variant::STRING) {
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
@@ -2357,8 +2381,9 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid)
} break;
case AABB: {
- if (p_value.type != Variant::VECTOR3)
+ if (p_value.type != Variant::VECTOR3) {
return;
+ }
if (p_index.get_type() == Variant::STRING) {
//scalar name
@@ -2381,14 +2406,16 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid)
}
} break;
case BASIS: {
- if (p_value.type != Variant::VECTOR3)
+ if (p_value.type != Variant::VECTOR3) {
return;
+ }
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) {
int index = p_index;
- if (index < 0)
+ if (index < 0) {
index += 3;
+ }
if (index >= 0 && index < 3) {
Basis *v = _data._basis;
@@ -2418,20 +2445,23 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid)
} break;
case TRANSFORM: {
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) {
- if (p_value.type != Variant::VECTOR3)
+ if (p_value.type != Variant::VECTOR3) {
return;
+ }
int index = p_index;
- if (index < 0)
+ if (index < 0) {
index += 4;
+ }
if (index >= 0 && index < 4) {
Transform *v = _data._transform;
valid = true;
- if (index == 3)
+ if (index == 3) {
v->origin = p_value;
- else
+ } else {
v->basis.set_axis(index, p_value);
+ }
return;
}
} else if (p_index.get_type() == Variant::STRING) {
@@ -2439,15 +2469,17 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid)
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
if (*str == "basis") {
- if (p_value.type != Variant::BASIS)
+ if (p_value.type != Variant::BASIS) {
return;
+ }
valid = true;
v->basis = p_value;
return;
}
if (*str == "origin") {
- if (p_value.type != Variant::VECTOR3)
+ if (p_value.type != Variant::VECTOR3) {
return;
+ }
valid = true;
v->origin = p_value;
return;
@@ -2456,8 +2488,9 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid)
} break;
case COLOR: {
- if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT)
+ if (p_value.type != Variant::INT && p_value.type != Variant::FLOAT) {
return;
+ }
if (p_index.get_type() == Variant::STRING) {
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
@@ -2509,8 +2542,9 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid)
}
} else if (p_index.get_type() == Variant::INT) {
int idx = p_index;
- if (idx < 0)
+ if (idx < 0) {
idx += 4;
+ }
if (idx >= 0 && idx < 4) {
Color *v = reinterpret_cast<Color *>(_data._mem);
(*v)[idx] = p_value;
@@ -2594,8 +2628,9 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const {
int idx = p_index;
const String *str = reinterpret_cast<const String *>(_data._mem);
- if (idx < 0)
+ if (idx < 0) {
idx += str->length();
+ }
if (idx >= 0 && idx < str->length()) {
valid = true;
return str->substr(idx, 1);
@@ -2607,8 +2642,9 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const {
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) {
// scalar index
int idx = p_index;
- if (idx < 0)
+ if (idx < 0) {
idx += 2;
+ }
if (idx >= 0 && idx < 2) {
const Vector2 *v = reinterpret_cast<const Vector2 *>(_data._mem);
valid = true;
@@ -2633,8 +2669,9 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const {
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) {
// scalar index
int idx = p_index;
- if (idx < 0)
+ if (idx < 0) {
idx += 2;
+ }
if (idx >= 0 && idx < 2) {
const Vector2i *v = reinterpret_cast<const Vector2i *>(_data._mem);
valid = true;
@@ -2695,8 +2732,9 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const {
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) {
//scalar index
int idx = p_index;
- if (idx < 0)
+ if (idx < 0) {
idx += 3;
+ }
if (idx >= 0 && idx < 3) {
const Vector3 *v = reinterpret_cast<const Vector3 *>(_data._mem);
valid = true;
@@ -2723,8 +2761,9 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const {
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) {
//scalar index
int idx = p_index;
- if (idx < 0)
+ if (idx < 0) {
idx += 3;
+ }
if (idx >= 0 && idx < 3) {
const Vector3i *v = reinterpret_cast<const Vector3i *>(_data._mem);
valid = true;
@@ -2751,8 +2790,9 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const {
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) {
int index = p_index;
- if (index < 0)
+ if (index < 0) {
index += 3;
+ }
if (index >= 0 && index < 3) {
const Transform2D *v = _data._transform2d;
@@ -2841,8 +2881,9 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const {
case BASIS: {
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) {
int index = p_index;
- if (index < 0)
+ if (index < 0) {
index += 3;
+ }
if (index >= 0 && index < 3) {
const Basis *v = _data._basis;
@@ -2869,8 +2910,9 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const {
case TRANSFORM: {
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::FLOAT) {
int index = p_index;
- if (index < 0)
+ if (index < 0) {
index += 4;
+ }
if (index >= 0 && index < 4) {
const Transform *v = _data._transform;
valid = true;
@@ -2931,8 +2973,9 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const {
}
} else if (p_index.get_type() == Variant::INT) {
int idx = p_index;
- if (idx < 0)
+ if (idx < 0) {
idx += 4;
+ }
if (idx >= 0 && idx < 4) {
const Color *v = reinterpret_cast<const Color *>(_data._mem);
valid = true;
@@ -2992,8 +3035,9 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const {
}
bool Variant::in(const Variant &p_index, bool *r_valid) const {
- if (r_valid)
+ if (r_valid) {
*r_valid = true;
+ }
switch (type) {
case STRING: {
@@ -3029,8 +3073,9 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const {
return valid;
} else {
- if (r_valid)
+ if (r_valid) {
*r_valid = false;
+ }
}
return false;
} break;
@@ -3044,8 +3089,9 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const {
int l = arr->size();
if (l) {
for (int i = 0; i < l; i++) {
- if (evaluate(OP_EQUAL, (*arr)[i], p_index))
+ if (evaluate(OP_EQUAL, (*arr)[i], p_index)) {
return true;
+ }
}
}
@@ -3060,8 +3106,9 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const {
if (l) {
const uint8_t *r = arr->ptr();
for (int i = 0; i < l; i++) {
- if (r[i] == index)
+ if (r[i] == index) {
return true;
+ }
}
}
@@ -3077,8 +3124,9 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const {
if (l) {
const int32_t *r = arr->ptr();
for (int32_t i = 0; i < l; i++) {
- if (r[i] == index)
+ if (r[i] == index) {
return true;
+ }
}
}
@@ -3093,8 +3141,9 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const {
if (l) {
const int64_t *r = arr->ptr();
for (int64_t i = 0; i < l; i++) {
- if (r[i] == index)
+ if (r[i] == index) {
return true;
+ }
}
}
@@ -3109,8 +3158,9 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const {
if (l) {
const float *r = arr->ptr();
for (int i = 0; i < l; i++) {
- if (r[i] == index)
+ if (r[i] == index) {
return true;
+ }
}
}
@@ -3126,8 +3176,9 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const {
if (l) {
const double *r = arr->ptr();
for (int i = 0; i < l; i++) {
- if (r[i] == index)
+ if (r[i] == index) {
return true;
+ }
}
}
@@ -3144,8 +3195,9 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const {
if (l) {
const String *r = arr->ptr();
for (int i = 0; i < l; i++) {
- if (r[i] == index)
+ if (r[i] == index) {
return true;
+ }
}
}
@@ -3162,8 +3214,9 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const {
if (l) {
const Vector2 *r = arr->ptr();
for (int i = 0; i < l; i++) {
- if (r[i] == index)
+ if (r[i] == index) {
return true;
+ }
}
}
@@ -3180,8 +3233,9 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const {
if (l) {
const Vector3 *r = arr->ptr();
for (int i = 0; i < l; i++) {
- if (r[i] == index)
+ if (r[i] == index) {
return true;
+ }
}
}
@@ -3198,8 +3252,9 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const {
if (l) {
const Color *r = arr->ptr();
for (int i = 0; i < l; i++) {
- if (r[i] == index)
+ if (r[i] == index) {
return true;
+ }
}
}
@@ -3210,8 +3265,9 @@ bool Variant::in(const Variant &p_index, bool *r_valid) const {
}
}
- if (r_valid)
+ if (r_valid) {
*r_valid = false;
+ }
return false;
}
@@ -3439,15 +3495,17 @@ bool Variant::iter_init(Variant &r_iter, bool &valid) const {
case STRING: {
const String *str = reinterpret_cast<const String *>(_data._mem);
- if (str->empty())
+ if (str->empty()) {
return false;
+ }
r_iter = 0;
return true;
} break;
case DICTIONARY: {
const Dictionary *dic = reinterpret_cast<const Dictionary *>(_data._mem);
- if (dic->empty())
+ if (dic->empty()) {
return false;
+ }
const Variant *next = dic->next(nullptr);
r_iter = *next;
@@ -3456,76 +3514,86 @@ bool Variant::iter_init(Variant &r_iter, bool &valid) const {
} break;
case ARRAY: {
const Array *arr = reinterpret_cast<const Array *>(_data._mem);
- if (arr->empty())
+ if (arr->empty()) {
return false;
+ }
r_iter = 0;
return true;
} break;
case PACKED_BYTE_ARRAY: {
const Vector<uint8_t> *arr = &PackedArrayRef<uint8_t>::get_array(_data.packed_array);
- if (arr->size() == 0)
+ if (arr->size() == 0) {
return false;
+ }
r_iter = 0;
return true;
} break;
case PACKED_INT32_ARRAY: {
const Vector<int32_t> *arr = &PackedArrayRef<int32_t>::get_array(_data.packed_array);
- if (arr->size() == 0)
+ if (arr->size() == 0) {
return false;
+ }
r_iter = 0;
return true;
} break;
case PACKED_INT64_ARRAY: {
const Vector<int64_t> *arr = &PackedArrayRef<int64_t>::get_array(_data.packed_array);
- if (arr->size() == 0)
+ if (arr->size() == 0) {
return false;
+ }
r_iter = 0;
return true;
} break;
case PACKED_FLOAT32_ARRAY: {
const Vector<float> *arr = &PackedArrayRef<float>::get_array(_data.packed_array);
- if (arr->size() == 0)
+ if (arr->size() == 0) {
return false;
+ }
r_iter = 0;
return true;
} break;
case PACKED_FLOAT64_ARRAY: {
const Vector<double> *arr = &PackedArrayRef<double>::get_array(_data.packed_array);
- if (arr->size() == 0)
+ if (arr->size() == 0) {
return false;
+ }
r_iter = 0;
return true;
} break;
case PACKED_STRING_ARRAY: {
const Vector<String> *arr = &PackedArrayRef<String>::get_array(_data.packed_array);
- if (arr->size() == 0)
+ if (arr->size() == 0) {
return false;
+ }
r_iter = 0;
return true;
} break;
case PACKED_VECTOR2_ARRAY: {
const Vector<Vector2> *arr = &PackedArrayRef<Vector2>::get_array(_data.packed_array);
- if (arr->size() == 0)
+ if (arr->size() == 0) {
return false;
+ }
r_iter = 0;
return true;
} break;
case PACKED_VECTOR3_ARRAY: {
const Vector<Vector3> *arr = &PackedArrayRef<Vector3>::get_array(_data.packed_array);
- if (arr->size() == 0)
+ if (arr->size() == 0) {
return false;
+ }
r_iter = 0;
return true;
} break;
case PACKED_COLOR_ARRAY: {
const Vector<Color> *arr = &PackedArrayRef<Color>::get_array(_data.packed_array);
- if (arr->size() == 0)
+ if (arr->size() == 0) {
return false;
+ }
r_iter = 0;
return true;
@@ -3544,16 +3612,18 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const {
case INT: {
int64_t idx = r_iter;
idx++;
- if (idx >= _data._int)
+ if (idx >= _data._int) {
return false;
+ }
r_iter = idx;
return true;
} break;
case FLOAT: {
int64_t idx = r_iter;
idx++;
- if (idx >= _data._float)
+ if (idx >= _data._float) {
return false;
+ }
r_iter = idx;
return true;
} break;
@@ -3563,8 +3633,9 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const {
double idx = r_iter;
idx++;
- if (idx >= to)
+ if (idx >= to) {
return false;
+ }
r_iter = idx;
return true;
@@ -3575,8 +3646,9 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const {
int64_t idx = r_iter;
idx++;
- if (idx >= to)
+ if (idx >= to) {
return false;
+ }
r_iter = idx;
return true;
@@ -3588,11 +3660,13 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const {
double idx = r_iter;
idx += step;
- if (step < 0 && idx <= to)
+ if (step < 0 && idx <= to) {
return false;
+ }
- if (step > 0 && idx >= to)
+ if (step > 0 && idx >= to) {
return false;
+ }
r_iter = idx;
return true;
@@ -3604,11 +3678,13 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const {
int64_t idx = r_iter;
idx += step;
- if (step < 0 && idx <= to)
+ if (step < 0 && idx <= to) {
return false;
+ }
- if (step > 0 && idx >= to)
+ if (step > 0 && idx >= to) {
return false;
+ }
r_iter = idx;
return true;
@@ -3649,16 +3725,18 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const {
const String *str = reinterpret_cast<const String *>(_data._mem);
int idx = r_iter;
idx++;
- if (idx >= str->length())
+ if (idx >= str->length()) {
return false;
+ }
r_iter = idx;
return true;
} break;
case DICTIONARY: {
const Dictionary *dic = reinterpret_cast<const Dictionary *>(_data._mem);
const Variant *next = dic->next(&r_iter);
- if (!next)
+ if (!next) {
return false;
+ }
r_iter = *next;
return true;
@@ -3668,8 +3746,9 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const {
const Array *arr = reinterpret_cast<const Array *>(_data._mem);
int idx = r_iter;
idx++;
- if (idx >= arr->size())
+ if (idx >= arr->size()) {
return false;
+ }
r_iter = idx;
return true;
} break;
@@ -3677,8 +3756,9 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const {
const Vector<uint8_t> *arr = &PackedArrayRef<uint8_t>::get_array(_data.packed_array);
int idx = r_iter;
idx++;
- if (idx >= arr->size())
+ if (idx >= arr->size()) {
return false;
+ }
r_iter = idx;
return true;
@@ -3687,8 +3767,9 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const {
const Vector<int32_t> *arr = &PackedArrayRef<int32_t>::get_array(_data.packed_array);
int32_t idx = r_iter;
idx++;
- if (idx >= arr->size())
+ if (idx >= arr->size()) {
return false;
+ }
r_iter = idx;
return true;
@@ -3697,8 +3778,9 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const {
const Vector<int64_t> *arr = &PackedArrayRef<int64_t>::get_array(_data.packed_array);
int64_t idx = r_iter;
idx++;
- if (idx >= arr->size())
+ if (idx >= arr->size()) {
return false;
+ }
r_iter = idx;
return true;
@@ -3707,8 +3789,9 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const {
const Vector<float> *arr = &PackedArrayRef<float>::get_array(_data.packed_array);
int idx = r_iter;
idx++;
- if (idx >= arr->size())
+ if (idx >= arr->size()) {
return false;
+ }
r_iter = idx;
return true;
@@ -3717,8 +3800,9 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const {
const Vector<double> *arr = &PackedArrayRef<double>::get_array(_data.packed_array);
int idx = r_iter;
idx++;
- if (idx >= arr->size())
+ if (idx >= arr->size()) {
return false;
+ }
r_iter = idx;
return true;
@@ -3727,8 +3811,9 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const {
const Vector<String> *arr = &PackedArrayRef<String>::get_array(_data.packed_array);
int idx = r_iter;
idx++;
- if (idx >= arr->size())
+ if (idx >= arr->size()) {
return false;
+ }
r_iter = idx;
return true;
} break;
@@ -3736,8 +3821,9 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const {
const Vector<Vector2> *arr = &PackedArrayRef<Vector2>::get_array(_data.packed_array);
int idx = r_iter;
idx++;
- if (idx >= arr->size())
+ if (idx >= arr->size()) {
return false;
+ }
r_iter = idx;
return true;
} break;
@@ -3745,8 +3831,9 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const {
const Vector<Vector3> *arr = &PackedArrayRef<Vector3>::get_array(_data.packed_array);
int idx = r_iter;
idx++;
- if (idx >= arr->size())
+ if (idx >= arr->size()) {
return false;
+ }
r_iter = idx;
return true;
} break;
@@ -3754,8 +3841,9 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const {
const Vector<Color> *arr = &PackedArrayRef<Color>::get_array(_data.packed_array);
int idx = r_iter;
idx++;
- if (idx >= arr->size())
+ if (idx >= arr->size()) {
return false;
+ }
r_iter = idx;
return true;
} break;
@@ -4129,16 +4217,18 @@ void Variant::interpolate(const Variant &a, const Variant &b, float c, Variant &
CharType chr = ' ';
if (i < split) {
- if (i < sa.length())
+ if (i < sa.length()) {
chr = sa[i];
- else if (i < sb.length())
+ } else if (i < sb.length()) {
chr = sb[i];
+ }
} else {
- if (i < sb.length())
+ if (i < sb.length()) {
chr = sb[i];
- else if (i < sa.length())
+ } else if (i < sa.length()) {
chr = sa[i];
+ }
}
dst[i] = chr;
diff --git a/core/variant_parser.cpp b/core/variant_parser.cpp
index 3a38720a27..9fe98265dd 100644
--- a/core/variant_parser.cpp
+++ b/core/variant_parser.cpp
@@ -150,8 +150,9 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri
r_token.type = TK_EOF;
return OK;
}
- if (ch == '\n')
+ if (ch == '\n') {
break;
+ }
}
break;
@@ -278,8 +279,9 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri
str += res;
} else {
- if (ch == '\n')
+ if (ch == '\n') {
line++;
+ }
str += ch;
}
}
@@ -362,8 +364,9 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri
} break;
}
- if (reading == READING_DONE)
+ if (reading == READING_DONE) {
break;
+ }
num += c;
c = p_stream->get_char();
}
@@ -372,10 +375,11 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri
r_token.type = TK_NUMBER;
- if (is_float)
+ if (is_float) {
r_token.value = num.as_double();
- else
+ } else {
r_token.value = num.as_int();
+ }
return OK;
} else if ((cchar >= 'A' && cchar <= 'Z') || (cchar >= 'a' && cchar <= 'z') || cchar == '_') {
@@ -484,35 +488,38 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
if (token.type == TK_CURLY_BRACKET_OPEN) {
Dictionary d;
Error err = _parse_dictionary(d, p_stream, line, r_err_str, p_res_parser);
- if (err)
+ if (err) {
return err;
+ }
value = d;
return OK;
} else if (token.type == TK_BRACKET_OPEN) {
Array a;
Error err = _parse_array(a, p_stream, line, r_err_str, p_res_parser);
- if (err)
+ if (err) {
return err;
+ }
value = a;
return OK;
} else if (token.type == TK_IDENTIFIER) {
String id = token.value;
- if (id == "true")
+ if (id == "true") {
value = true;
- else if (id == "false")
+ } else if (id == "false") {
value = false;
- else if (id == "null" || id == "nil")
+ } else if (id == "null" || id == "nil") {
value = Variant();
- else if (id == "inf")
+ } else if (id == "inf") {
value = Math_INF;
- else if (id == "nan")
+ } else if (id == "nan") {
value = Math_NAN;
- else if (id == "Vector2") {
+ } else if (id == "Vector2") {
Vector<float> args;
Error err = _parse_construct<float>(p_stream, args, line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
if (args.size() != 2) {
r_err_str = "Expected 2 arguments for constructor";
@@ -523,8 +530,9 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
} else if (id == "Vector2i") {
Vector<int32_t> args;
Error err = _parse_construct<int32_t>(p_stream, args, line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
if (args.size() != 2) {
r_err_str = "Expected 2 arguments for constructor";
@@ -535,8 +543,9 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
} else if (id == "Rect2") {
Vector<float> args;
Error err = _parse_construct<float>(p_stream, args, line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
if (args.size() != 4) {
r_err_str = "Expected 4 arguments for constructor";
@@ -547,8 +556,9 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
} else if (id == "Rect2i") {
Vector<int32_t> args;
Error err = _parse_construct<int32_t>(p_stream, args, line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
if (args.size() != 4) {
r_err_str = "Expected 4 arguments for constructor";
@@ -559,8 +569,9 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
} else if (id == "Vector3") {
Vector<float> args;
Error err = _parse_construct<float>(p_stream, args, line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
if (args.size() != 3) {
r_err_str = "Expected 3 arguments for constructor";
@@ -571,8 +582,9 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
} else if (id == "Vector3i") {
Vector<int32_t> args;
Error err = _parse_construct<int32_t>(p_stream, args, line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
if (args.size() != 3) {
r_err_str = "Expected 3 arguments for constructor";
@@ -584,8 +596,9 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
Vector<float> args;
Error err = _parse_construct<float>(p_stream, args, line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
if (args.size() != 6) {
r_err_str = "Expected 6 arguments for constructor";
@@ -599,8 +612,9 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
} else if (id == "Plane") {
Vector<float> args;
Error err = _parse_construct<float>(p_stream, args, line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
if (args.size() != 4) {
r_err_str = "Expected 4 arguments for constructor";
@@ -611,8 +625,9 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
} else if (id == "Quat") {
Vector<float> args;
Error err = _parse_construct<float>(p_stream, args, line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
if (args.size() != 4) {
r_err_str = "Expected 4 arguments for constructor";
@@ -624,8 +639,9 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
} else if (id == "AABB" || id == "Rect3") {
Vector<float> args;
Error err = _parse_construct<float>(p_stream, args, line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
if (args.size() != 6) {
r_err_str = "Expected 6 arguments for constructor";
@@ -638,8 +654,9 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
Vector<float> args;
Error err = _parse_construct<float>(p_stream, args, line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
if (args.size() != 9) {
r_err_str = "Expected 9 arguments for constructor";
@@ -650,8 +667,9 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
} else if (id == "Transform") {
Vector<float> args;
Error err = _parse_construct<float>(p_stream, args, line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
if (args.size() != 12) {
r_err_str = "Expected 12 arguments for constructor";
@@ -663,8 +681,9 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
} else if (id == "Color") {
Vector<float> args;
Error err = _parse_construct<float>(p_stream, args, line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
if (args.size() != 4) {
r_err_str = "Expected 4 arguments for constructor";
@@ -758,8 +777,9 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
if (at_key) {
Error err = get_token(p_stream, token2, line, r_err_str);
- if (err != OK)
+ if (err != OK) {
return err;
+ }
if (token2.type == TK_PARENTHESIS_CLOSE) {
Reference *reference = Object::cast_to<Reference>(obj);
@@ -790,8 +810,9 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
err = get_token(p_stream, token2, line, r_err_str);
- if (err != OK)
+ if (err != OK) {
return err;
+ }
if (token2.type != TK_COLON) {
r_err_str = "Expected ':'";
return ERR_PARSE_ERROR;
@@ -799,13 +820,15 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
at_key = false;
} else {
Error err = get_token(p_stream, token2, line, r_err_str);
- if (err != OK)
+ if (err != OK) {
return err;
+ }
Variant v;
err = parse_value(token2, v, p_stream, line, r_err_str, p_res_parser);
- if (err)
+ if (err) {
return err;
+ }
obj->set(key, v);
need_comma = true;
at_key = true;
@@ -822,8 +845,9 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
if (p_res_parser && id == "Resource" && p_res_parser->func) {
RES res;
Error err = p_res_parser->func(p_res_parser->userdata, p_stream, res, line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
value = res;
@@ -831,8 +855,9 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
} else if (p_res_parser && id == "ExtResource" && p_res_parser->ext_func) {
RES res;
Error err = p_res_parser->ext_func(p_res_parser->userdata, p_stream, res, line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
value = res;
@@ -840,8 +865,9 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
} else if (p_res_parser && id == "SubResource" && p_res_parser->sub_func) {
RES res;
Error err = p_res_parser->sub_func(p_res_parser->userdata, p_stream, res, line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
value = res;
@@ -874,8 +900,9 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
} else if (id == "PackedByteArray" || id == "PoolByteArray" || id == "ByteArray") {
Vector<uint8_t> args;
Error err = _parse_construct<uint8_t>(p_stream, args, line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
Vector<uint8_t> arr;
{
@@ -894,8 +921,9 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
} else if (id == "PackedInt32Array" || id == "PackedIntArray" || id == "PoolIntArray" || id == "IntArray") {
Vector<int32_t> args;
Error err = _parse_construct<int32_t>(p_stream, args, line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
Vector<int32_t> arr;
{
@@ -914,8 +942,9 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
} else if (id == "PackedInt64Array") {
Vector<int64_t> args;
Error err = _parse_construct<int64_t>(p_stream, args, line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
Vector<int64_t> arr;
{
@@ -934,8 +963,9 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
} else if (id == "PackedFloat32Array" || id == "PackedRealArray" || id == "PoolRealArray" || id == "FloatArray") {
Vector<float> args;
Error err = _parse_construct<float>(p_stream, args, line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
Vector<float> arr;
{
@@ -953,8 +983,9 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
} else if (id == "PackedFloat64Array") {
Vector<double> args;
Error err = _parse_construct<double>(p_stream, args, line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
Vector<double> arr;
{
@@ -1021,8 +1052,9 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
} else if (id == "PackedVector2Array" || id == "PoolVector2Array" || id == "Vector2Array") {
Vector<float> args;
Error err = _parse_construct<float>(p_stream, args, line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
Vector<Vector2> arr;
{
@@ -1041,8 +1073,9 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
} else if (id == "PackedVector3Array" || id == "PoolVector3Array" || id == "Vector3Array") {
Vector<float> args;
Error err = _parse_construct<float>(p_stream, args, line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
Vector<Vector3> arr;
{
@@ -1061,8 +1094,9 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
} else if (id == "PackedColorArray" || id == "PoolColorArray" || id == "ColorArray") {
Vector<float> args;
Error err = _parse_construct<float>(p_stream, args, line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
Vector<Color> arr;
{
@@ -1113,8 +1147,9 @@ Error VariantParser::_parse_array(Array &array, Stream *p_stream, int &line, Str
}
Error err = get_token(p_stream, token, line, r_err_str);
- if (err != OK)
+ if (err != OK) {
return err;
+ }
if (token.type == TK_BRACKET_CLOSE) {
return OK;
@@ -1132,8 +1167,9 @@ Error VariantParser::_parse_array(Array &array, Stream *p_stream, int &line, Str
Variant v;
err = parse_value(token, v, p_stream, line, r_err_str, p_res_parser);
- if (err)
+ if (err) {
return err;
+ }
array.push_back(v);
need_comma = true;
@@ -1154,8 +1190,9 @@ Error VariantParser::_parse_dictionary(Dictionary &object, Stream *p_stream, int
if (at_key) {
Error err = get_token(p_stream, token, line, r_err_str);
- if (err != OK)
+ if (err != OK) {
return err;
+ }
if (token.type == TK_CURLY_BRACKET_CLOSE) {
return OK;
@@ -1173,13 +1210,15 @@ Error VariantParser::_parse_dictionary(Dictionary &object, Stream *p_stream, int
err = parse_value(token, key, p_stream, line, r_err_str, p_res_parser);
- if (err)
+ if (err) {
return err;
+ }
err = get_token(p_stream, token, line, r_err_str);
- if (err != OK)
+ if (err != OK) {
return err;
+ }
if (token.type != TK_COLON) {
r_err_str = "Expected ':'";
return ERR_PARSE_ERROR;
@@ -1187,13 +1226,15 @@ Error VariantParser::_parse_dictionary(Dictionary &object, Stream *p_stream, int
at_key = false;
} else {
Error err = get_token(p_stream, token, line, r_err_str);
- if (err != OK)
+ if (err != OK) {
return err;
+ }
Variant v;
err = parse_value(token, v, p_stream, line, r_err_str, p_res_parser);
- if (err)
+ if (err) {
return err;
+ }
object[key] = v;
need_comma = true;
at_key = true;
@@ -1219,8 +1260,9 @@ Error VariantParser::_parse_tag(Token &token, Stream *p_stream, int &line, Strin
r_err_str = "Unexpected EOF while parsing simple tag";
return ERR_PARSE_ERROR;
}
- if (c == ']')
+ if (c == ']') {
break;
+ }
r_tag.name += String::chr(c);
}
@@ -1246,8 +1288,9 @@ Error VariantParser::_parse_tag(Token &token, Stream *p_stream, int &line, Strin
}
get_token(p_stream, token, line, r_err_str);
- if (token.type == TK_BRACKET_CLOSE)
+ if (token.type == TK_BRACKET_CLOSE) {
break;
+ }
if (parsing_tag && token.type == TK_PERIOD) {
r_tag.name += "."; //support tags such as [someprop.Android] for specific platforms
@@ -1279,8 +1322,9 @@ Error VariantParser::_parse_tag(Token &token, Stream *p_stream, int &line, Strin
get_token(p_stream, token, line, r_err_str);
Variant value;
Error err = parse_value(token, value, p_stream, line, r_err_str, p_res_parser);
- if (err)
+ if (err) {
return err;
+ }
r_tag.fields[id] = value;
}
@@ -1319,8 +1363,9 @@ Error VariantParser::parse_tag_assign_eof(Stream *p_stream, int &line, String &r
c = p_stream->get_char();
}
- if (p_stream->is_eof())
+ if (p_stream->is_eof()) {
return ERR_FILE_EOF;
+ }
if (c == ';') { //comment
while (true) {
@@ -1328,8 +1373,9 @@ Error VariantParser::parse_tag_assign_eof(Stream *p_stream, int &line, String &r
if (p_stream->is_eof()) {
return ERR_FILE_EOF;
}
- if (ch == '\n')
+ if (ch == '\n') {
break;
+ }
}
continue;
}
@@ -1348,8 +1394,9 @@ Error VariantParser::parse_tag_assign_eof(Stream *p_stream, int &line, String &r
p_stream->saved = '"';
Token tk;
Error err = get_token(p_stream, tk, line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
if (tk.type != TK_STRING) {
r_err_str = "Error reading quoted string";
return ERR_INVALID_DATA;
@@ -1375,8 +1422,9 @@ Error VariantParser::parse_tag_assign_eof(Stream *p_stream, int &line, String &r
Error VariantParser::parse(Stream *p_stream, Variant &r_ret, String &r_err_str, int &r_err_line, ResourceParser *p_res_parser) {
Token token;
Error err = get_token(p_stream, token, r_err_line, r_err_str);
- if (err)
+ if (err) {
return err;
+ }
if (token.type == TK_EOF) {
return ERR_FILE_EOF;
@@ -1390,10 +1438,11 @@ Error VariantParser::parse(Stream *p_stream, Variant &r_ret, String &r_err_str,
////////////////////////////////////////////////////////////////////////////////
static String rtosfix(double p_value) {
- if (p_value == 0.0)
+ if (p_value == 0.0) {
return "0"; //avoid negative zero (-0) being written, which may annoy git, svn, etc. for changes when they don't exist.
- else
+ } else {
return rtoss(p_value);
+ }
}
Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_string_func, void *p_store_string_ud, EncodeResourceFunc p_encode_res_func, void *p_encode_res_ud) {
@@ -1410,8 +1459,9 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
case Variant::FLOAT: {
String s = rtosfix(p_variant.operator real_t());
if (s != "inf" && s != "nan") {
- if (s.find(".") == -1 && s.find("e") == -1)
+ if (s.find(".") == -1 && s.find("e") == -1) {
s += ".0";
+ }
}
p_store_string_func(p_store_string_ud, s);
} break;
@@ -1467,8 +1517,9 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
Transform2D m3 = p_variant;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 2; j++) {
- if (i != 0 || j != 0)
+ if (i != 0 || j != 0) {
s += ", ";
+ }
s += rtosfix(m3.elements[i][j]);
}
}
@@ -1481,8 +1532,9 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
Basis m3 = p_variant;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
- if (i != 0 || j != 0)
+ if (i != 0 || j != 0) {
s += ", ";
+ }
s += rtosfix(m3.elements[i][j]);
}
}
@@ -1496,8 +1548,9 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
Basis &m3 = t.basis;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
- if (i != 0 || j != 0)
+ if (i != 0 || j != 0) {
s += ", ";
+ }
s += rtosfix(m3.elements[i][j]);
}
}
@@ -1602,8 +1655,9 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
write(E->get(), p_store_string_func, p_store_string_ud, p_encode_res_func, p_encode_res_ud);
p_store_string_func(p_store_string_ud, ": ");
write(dict[E->get()], p_store_string_func, p_store_string_ud, p_encode_res_func, p_encode_res_ud);
- if (E->next())
+ if (E->next()) {
p_store_string_func(p_store_string_ud, ",\n");
+ }
}
p_store_string_func(p_store_string_ud, "\n}");
@@ -1614,8 +1668,9 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
Array array = p_variant;
int len = array.size();
for (int i = 0; i < len; i++) {
- if (i > 0)
+ if (i > 0) {
p_store_string_func(p_store_string_ud, ", ");
+ }
write(array[i], p_store_string_func, p_store_string_ud, p_encode_res_func, p_encode_res_ud);
}
p_store_string_func(p_store_string_ud, " ]");
@@ -1630,8 +1685,9 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
const uint8_t *ptr = data.ptr();
for (int i = 0; i < len; i++) {
- if (i > 0)
+ if (i > 0) {
p_store_string_func(p_store_string_ud, ", ");
+ }
p_store_string_func(p_store_string_ud, itos(ptr[i]));
}
@@ -1646,8 +1702,9 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
const int32_t *ptr = data.ptr();
for (int32_t i = 0; i < len; i++) {
- if (i > 0)
+ if (i > 0) {
p_store_string_func(p_store_string_ud, ", ");
+ }
p_store_string_func(p_store_string_ud, itos(ptr[i]));
}
@@ -1662,8 +1719,9 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
const int64_t *ptr = data.ptr();
for (int64_t i = 0; i < len; i++) {
- if (i > 0)
+ if (i > 0) {
p_store_string_func(p_store_string_ud, ", ");
+ }
p_store_string_func(p_store_string_ud, itos(ptr[i]));
}
@@ -1678,8 +1736,9 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
const float *ptr = data.ptr();
for (int i = 0; i < len; i++) {
- if (i > 0)
+ if (i > 0) {
p_store_string_func(p_store_string_ud, ", ");
+ }
p_store_string_func(p_store_string_ud, rtosfix(ptr[i]));
}
@@ -1693,8 +1752,9 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
const double *ptr = data.ptr();
for (int i = 0; i < len; i++) {
- if (i > 0)
+ if (i > 0) {
p_store_string_func(p_store_string_ud, ", ");
+ }
p_store_string_func(p_store_string_ud, rtosfix(ptr[i]));
}
@@ -1711,8 +1771,9 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
//write_string("\n");
for (int i = 0; i < len; i++) {
- if (i > 0)
+ if (i > 0) {
p_store_string_func(p_store_string_ud, ", ");
+ }
String str = ptr[i];
p_store_string_func(p_store_string_ud, "\"" + str.c_escape() + "\"");
}
@@ -1727,8 +1788,9 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
const Vector2 *ptr = data.ptr();
for (int i = 0; i < len; i++) {
- if (i > 0)
+ if (i > 0) {
p_store_string_func(p_store_string_ud, ", ");
+ }
p_store_string_func(p_store_string_ud, rtosfix(ptr[i].x) + ", " + rtosfix(ptr[i].y));
}
@@ -1742,8 +1804,9 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
const Vector3 *ptr = data.ptr();
for (int i = 0; i < len; i++) {
- if (i > 0)
+ if (i > 0) {
p_store_string_func(p_store_string_ud, ", ");
+ }
p_store_string_func(p_store_string_ud, rtosfix(ptr[i].x) + ", " + rtosfix(ptr[i].y) + ", " + rtosfix(ptr[i].z));
}
@@ -1758,8 +1821,9 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
const Color *ptr = data.ptr();
for (int i = 0; i < len; i++) {
- if (i > 0)
+ if (i > 0) {
p_store_string_func(p_store_string_ud, ", ");
+ }
p_store_string_func(p_store_string_ud, rtosfix(ptr[i].r) + ", " + rtosfix(ptr[i].g) + ", " + rtosfix(ptr[i].b) + ", " + rtosfix(ptr[i].a));
}
diff --git a/core/vector.h b/core/vector.h
index 4521b29339..696984ac28 100644
--- a/core/vector.h
+++ b/core/vector.h
@@ -70,8 +70,9 @@ public:
void remove(int p_index) { _cowdata.remove(p_index); }
void erase(const T &p_val) {
int idx = find(p_val);
- if (idx >= 0)
+ if (idx >= 0) {
remove(idx);
+ }
}
void invert();
@@ -94,8 +95,9 @@ public:
template <class C>
void sort_custom() {
int len = _cowdata.size();
- if (len == 0)
+ if (len == 0) {
return;
+ }
T *data = ptrw();
SortArray<T, C> sorter;
@@ -168,12 +170,14 @@ void Vector<T>::invert() {
template <class T>
void Vector<T>::append_array(Vector<T> p_other) {
const int ds = p_other.size();
- if (ds == 0)
+ if (ds == 0) {
return;
+ }
const int bs = size();
resize(bs + ds);
- for (int i = 0; i < ds; ++i)
+ for (int i = 0; i < ds; ++i) {
ptrw()[bs + i] = p_other[i];
+ }
}
template <class T>
diff --git a/core/vmap.h b/core/vmap.h
index 358b6260a4..c91ea9b3c9 100644
--- a/core/vmap.h
+++ b/core/vmap.h
@@ -54,8 +54,9 @@ private:
_FORCE_INLINE_ int _find(const T &p_val, bool &r_exact) const {
r_exact = false;
- if (_cowdata.empty())
+ if (_cowdata.empty()) {
return 0;
+ }
int low = 0;
int high = _cowdata.size() - 1;
@@ -63,8 +64,9 @@ private:
int middle = 0;
#ifdef DEBUG_ENABLED
- if (low > high)
+ if (low > high) {
ERR_PRINT("low > high, this may be a bug");
+ }
#endif
while (low <= high) {
middle = (low + high) / 2;
@@ -80,14 +82,16 @@ private:
}
//return the position where this would be inserted
- if (a[middle].key < p_val)
+ if (a[middle].key < p_val) {
middle++;
+ }
return middle;
}
_FORCE_INLINE_ int _find_exact(const T &p_val) const {
- if (_cowdata.empty())
+ if (_cowdata.empty()) {
return -1;
+ }
int low = 0;
int high = _cowdata.size() - 1;
@@ -127,8 +131,9 @@ public:
void erase(const T &p_val) {
int pos = _find_exact(p_val);
- if (pos < 0)
+ if (pos < 0) {
return;
+ }
_cowdata.remove(pos);
}
diff --git a/core/vset.h b/core/vset.h
index 45516bdb05..034b8fe851 100644
--- a/core/vset.h
+++ b/core/vset.h
@@ -40,8 +40,9 @@ class VSet {
_FORCE_INLINE_ int _find(const T &p_val, bool &r_exact) const {
r_exact = false;
- if (_data.empty())
+ if (_data.empty()) {
return 0;
+ }
int low = 0;
int high = _data.size() - 1;
@@ -49,8 +50,9 @@ class VSet {
int middle = 0;
#ifdef DEBUG_ENABLED
- if (low > high)
+ if (low > high) {
ERR_PRINT("low > high, this may be a bug");
+ }
#endif
while (low <= high) {
@@ -67,14 +69,16 @@ class VSet {
}
//return the position where this would be inserted
- if (a[middle] < p_val)
+ if (a[middle] < p_val) {
middle++;
+ }
return middle;
}
_FORCE_INLINE_ int _find_exact(const T &p_val) const {
- if (_data.empty())
+ if (_data.empty()) {
return -1;
+ }
int low = 0;
int high = _data.size() - 1;
@@ -100,8 +104,9 @@ public:
void insert(const T &p_val) {
bool exact;
int pos = _find(p_val, exact);
- if (exact)
+ if (exact) {
return;
+ }
_data.insert(pos, p_val);
}
@@ -111,8 +116,9 @@ public:
void erase(const T &p_val) {
int pos = _find_exact(p_val);
- if (pos < 0)
+ if (pos < 0) {
return;
+ }
_data.remove(pos);
}
diff --git a/drivers/alsa/audio_driver_alsa.cpp b/drivers/alsa/audio_driver_alsa.cpp
index 895a746b20..414b0c28e0 100644
--- a/drivers/alsa/audio_driver_alsa.cpp
+++ b/drivers/alsa/audio_driver_alsa.cpp
@@ -252,8 +252,9 @@ Array AudioDriverALSA::get_device_list() {
void **hints;
- if (snd_device_name_hint(-1, "pcm", &hints) < 0)
+ if (snd_device_name_hint(-1, "pcm", &hints) < 0) {
return list;
+ }
for (void **n = hints; *n != nullptr; n++) {
char *name = snd_device_name_get_hint(*n, "NAME");
@@ -267,10 +268,12 @@ Array AudioDriverALSA::get_device_list() {
}
}
- if (desc != nullptr)
+ if (desc != nullptr) {
free(desc);
- if (name != nullptr)
+ }
+ if (name != nullptr) {
free(name);
+ }
}
snd_device_name_free_hint(hints);
@@ -288,14 +291,16 @@ void AudioDriverALSA::set_device(String device) {
}
void AudioDriverALSA::lock() {
- if (!thread)
+ if (!thread) {
return;
+ }
mutex.lock();
}
void AudioDriverALSA::unlock() {
- if (!thread)
+ if (!thread) {
return;
+ }
mutex.unlock();
}
diff --git a/drivers/alsamidi/midi_driver_alsamidi.cpp b/drivers/alsamidi/midi_driver_alsamidi.cpp
index a4c9fbece8..69a6956c2b 100644
--- a/drivers/alsamidi/midi_driver_alsamidi.cpp
+++ b/drivers/alsamidi/midi_driver_alsamidi.cpp
@@ -127,8 +127,9 @@ void MIDIDriverALSAMidi::thread_func(void *p_udata) {
Error MIDIDriverALSAMidi::open() {
void **hints;
- if (snd_device_name_hint(-1, "rawmidi", &hints) < 0)
+ if (snd_device_name_hint(-1, "rawmidi", &hints) < 0) {
return ERR_CANT_OPEN;
+ }
int i = 0;
for (void **n = hints; *n != nullptr; n++) {
@@ -142,8 +143,9 @@ Error MIDIDriverALSAMidi::open() {
}
}
- if (name != nullptr)
+ if (name != nullptr) {
free(name);
+ }
}
snd_device_name_free_hint(hints);
diff --git a/drivers/png/png_driver_common.cpp b/drivers/png/png_driver_common.cpp
index 68faff30fc..77d5e68826 100644
--- a/drivers/png/png_driver_common.cpp
+++ b/drivers/png/png_driver_common.cpp
@@ -122,8 +122,9 @@ Error png_to_image(const uint8_t *p_source, size_t p_size, Ref<Image> p_image) {
Error image_to_png(const Ref<Image> &p_image, Vector<uint8_t> &p_buffer) {
Ref<Image> source_image = p_image->duplicate();
- if (source_image->is_compressed())
+ if (source_image->is_compressed()) {
source_image->decompress();
+ }
ERR_FAIL_COND_V(source_image->is_compressed(), FAILED);
diff --git a/drivers/pulseaudio/audio_driver_pulseaudio.cpp b/drivers/pulseaudio/audio_driver_pulseaudio.cpp
index 8d704dae7b..ce0b8ade95 100644
--- a/drivers/pulseaudio/audio_driver_pulseaudio.cpp
+++ b/drivers/pulseaudio/audio_driver_pulseaudio.cpp
@@ -581,14 +581,16 @@ void AudioDriverPulseAudio::set_device(String device) {
}
void AudioDriverPulseAudio::lock() {
- if (!thread)
+ if (!thread) {
return;
+ }
mutex.lock();
}
void AudioDriverPulseAudio::unlock() {
- if (!thread)
+ if (!thread) {
return;
+ }
mutex.unlock();
}
@@ -601,8 +603,9 @@ void AudioDriverPulseAudio::finish_device() {
}
void AudioDriverPulseAudio::finish() {
- if (!thread)
+ if (!thread) {
return;
+ }
exit_thread = true;
Thread::wait_to_finish(thread);
diff --git a/drivers/register_driver_types.cpp b/drivers/register_driver_types.cpp
index 6c1f50d8c2..f0deabec21 100644
--- a/drivers/register_driver_types.cpp
+++ b/drivers/register_driver_types.cpp
@@ -45,8 +45,9 @@ void register_core_driver_types() {
}
void unregister_core_driver_types() {
- if (image_loader_png)
+ if (image_loader_png) {
memdelete(image_loader_png);
+ }
ResourceSaver::remove_resource_format_saver(resource_saver_png);
resource_saver_png.unref();
diff --git a/drivers/unix/dir_access_unix.cpp b/drivers/unix/dir_access_unix.cpp
index 5d435d5176..325a88b573 100644
--- a/drivers/unix/dir_access_unix.cpp
+++ b/drivers/unix/dir_access_unix.cpp
@@ -61,8 +61,9 @@ Error DirAccessUnix::list_dir_begin() {
//chdir(current_path.utf8().get_data());
dir_stream = opendir(current_dir.utf8().get_data());
//chdir(real_current_dir_name);
- if (!dir_stream)
+ if (!dir_stream) {
return ERR_CANT_OPEN; //error!
+ }
return OK;
}
@@ -70,8 +71,9 @@ Error DirAccessUnix::list_dir_begin() {
bool DirAccessUnix::file_exists(String p_file) {
GLOBAL_LOCK_FUNCTION
- if (p_file.is_rel_path())
+ if (p_file.is_rel_path()) {
p_file = current_dir.plus_file(p_file);
+ }
p_file = fix_path(p_file);
@@ -88,8 +90,9 @@ bool DirAccessUnix::file_exists(String p_file) {
bool DirAccessUnix::dir_exists(String p_dir) {
GLOBAL_LOCK_FUNCTION
- if (p_dir.is_rel_path())
+ if (p_dir.is_rel_path()) {
p_dir = get_current_dir().plus_file(p_dir);
+ }
p_dir = fix_path(p_dir);
@@ -100,8 +103,9 @@ bool DirAccessUnix::dir_exists(String p_dir) {
}
uint64_t DirAccessUnix::get_modified_time(String p_file) {
- if (p_file.is_rel_path())
+ if (p_file.is_rel_path()) {
p_file = current_dir.plus_file(p_file);
+ }
p_file = fix_path(p_file);
@@ -117,8 +121,9 @@ uint64_t DirAccessUnix::get_modified_time(String p_file) {
};
String DirAccessUnix::get_next() {
- if (!dir_stream)
+ if (!dir_stream) {
return "";
+ }
dirent *entry = readdir(dir_stream);
@@ -161,8 +166,9 @@ bool DirAccessUnix::current_is_hidden() const {
}
void DirAccessUnix::list_dir_end() {
- if (dir_stream)
+ if (dir_stream) {
closedir(dir_stream);
+ }
dir_stream = nullptr;
_cisdir = false;
}
@@ -263,8 +269,9 @@ bool DirAccessUnix::drives_are_shortcuts() {
Error DirAccessUnix::make_dir(String p_dir) {
GLOBAL_LOCK_FUNCTION
- if (p_dir.is_rel_path())
+ if (p_dir.is_rel_path()) {
p_dir = get_current_dir().plus_file(p_dir);
+ }
p_dir = fix_path(p_dir);
@@ -291,8 +298,9 @@ Error DirAccessUnix::change_dir(String p_dir) {
String prev_dir;
char real_current_dir_name[2048];
ERR_FAIL_COND_V(getcwd(real_current_dir_name, 2048) == nullptr, ERR_BUG);
- if (prev_dir.parse_utf8(real_current_dir_name))
+ if (prev_dir.parse_utf8(real_current_dir_name)) {
prev_dir = real_current_dir_name; //no utf8, maybe latin?
+ }
// try_dir is the directory we are trying to change into
String try_dir = "";
@@ -330,22 +338,25 @@ String DirAccessUnix::get_current_dir(bool p_include_drive) {
String base = _get_root_path();
if (base != "") {
String bd = current_dir.replace_first(base, "");
- if (bd.begins_with("/"))
+ if (bd.begins_with("/")) {
return _get_root_string() + bd.substr(1, bd.length());
- else
+ } else {
return _get_root_string() + bd;
+ }
}
return current_dir;
}
Error DirAccessUnix::rename(String p_path, String p_new_path) {
- if (p_path.is_rel_path())
+ if (p_path.is_rel_path()) {
p_path = get_current_dir().plus_file(p_path);
+ }
p_path = fix_path(p_path);
- if (p_new_path.is_rel_path())
+ if (p_new_path.is_rel_path()) {
p_new_path = get_current_dir().plus_file(p_new_path);
+ }
p_new_path = fix_path(p_new_path);
@@ -353,19 +364,22 @@ Error DirAccessUnix::rename(String p_path, String p_new_path) {
}
Error DirAccessUnix::remove(String p_path) {
- if (p_path.is_rel_path())
+ if (p_path.is_rel_path()) {
p_path = get_current_dir().plus_file(p_path);
+ }
p_path = fix_path(p_path);
struct stat flags;
- if ((stat(p_path.utf8().get_data(), &flags) != 0))
+ if ((stat(p_path.utf8().get_data(), &flags) != 0)) {
return FAILED;
+ }
- if (S_ISDIR(flags.st_mode))
+ if (S_ISDIR(flags.st_mode)) {
return ::rmdir(p_path.utf8().get_data()) == 0 ? OK : FAILED;
- else
+ } else {
return ::unlink(p_path.utf8().get_data()) == 0 ? OK : FAILED;
+ }
}
size_t DirAccessUnix::get_space_left() {
@@ -395,8 +409,9 @@ DirAccessUnix::DirAccessUnix() {
// set current directory to an absolute path of the current directory
char real_current_dir_name[2048];
ERR_FAIL_COND(getcwd(real_current_dir_name, 2048) == nullptr);
- if (current_dir.parse_utf8(real_current_dir_name))
+ if (current_dir.parse_utf8(real_current_dir_name)) {
current_dir = real_current_dir_name;
+ }
change_dir(current_dir);
}
diff --git a/drivers/unix/file_access_unix.cpp b/drivers/unix/file_access_unix.cpp
index 7edafce9e5..06bad9f385 100644
--- a/drivers/unix/file_access_unix.cpp
+++ b/drivers/unix/file_access_unix.cpp
@@ -71,8 +71,9 @@ void FileAccessUnix::check_errors() const {
}
Error FileAccessUnix::_open(const String &p_path, int p_mode_flags) {
- if (f)
+ if (f) {
fclose(f);
+ }
f = nullptr;
path_src = p_path;
@@ -82,16 +83,17 @@ Error FileAccessUnix::_open(const String &p_path, int p_mode_flags) {
ERR_FAIL_COND_V_MSG(f, ERR_ALREADY_IN_USE, "File is already in use.");
const char *mode_string;
- if (p_mode_flags == READ)
+ if (p_mode_flags == READ) {
mode_string = "rb";
- else if (p_mode_flags == WRITE)
+ } else if (p_mode_flags == WRITE) {
mode_string = "wb";
- else if (p_mode_flags == READ_WRITE)
+ } else if (p_mode_flags == READ_WRITE) {
mode_string = "rb+";
- else if (p_mode_flags == WRITE_READ)
+ } else if (p_mode_flags == WRITE_READ) {
mode_string = "wb+";
- else
+ } else {
return ERR_INVALID_PARAMETER;
+ }
/* pretty much every implementation that uses fopen as primary
backend (unix-compatible mostly) supports utf8 encoding */
@@ -147,8 +149,9 @@ Error FileAccessUnix::_open(const String &p_path, int p_mode_flags) {
}
void FileAccessUnix::close() {
- if (!f)
+ if (!f) {
return;
+ }
fclose(f);
f = nullptr;
@@ -185,15 +188,17 @@ void FileAccessUnix::seek(size_t p_position) {
ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
last_error = OK;
- if (fseek(f, p_position, SEEK_SET))
+ if (fseek(f, p_position, SEEK_SET)) {
check_errors();
+ }
}
void FileAccessUnix::seek_end(int64_t p_position) {
ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
- if (fseek(f, p_position, SEEK_END))
+ if (fseek(f, p_position, SEEK_END)) {
check_errors();
+ }
}
size_t FileAccessUnix::get_position() const {
@@ -268,13 +273,15 @@ bool FileAccessUnix::file_exists(const String &p_path) {
// Does the name exist at all?
err = stat(filename.utf8().get_data(), &st);
- if (err)
+ if (err) {
return false;
+ }
#ifdef UNIX_ENABLED
// See if we have access to the file
- if (access(filename.utf8().get_data(), F_OK))
+ if (access(filename.utf8().get_data(), F_OK)) {
return false;
+ }
#else
if (_access(filename.utf8().get_data(), 4) == -1)
return false;
diff --git a/drivers/unix/ip_unix.cpp b/drivers/unix/ip_unix.cpp
index 2015a4041d..05eedccc1d 100644
--- a/drivers/unix/ip_unix.cpp
+++ b/drivers/unix/ip_unix.cpp
@@ -113,8 +113,9 @@ IP_Address IP_Unix::_resolve_hostname(const String &p_hostname, Type p_type) {
if (result == nullptr || result->ai_addr == nullptr) {
ERR_PRINT("Invalid response from getaddrinfo");
- if (result)
+ if (result) {
freeaddrinfo(result);
+ }
return IP_Address();
};
@@ -218,13 +219,15 @@ void IP_Unix::get_local_interfaces(Map<String, Interface_Info> *r_interfaces) co
getifaddrs(&ifAddrStruct);
for (ifa = ifAddrStruct; ifa != nullptr; ifa = ifa->ifa_next) {
- if (!ifa->ifa_addr)
+ if (!ifa->ifa_addr) {
continue;
+ }
family = ifa->ifa_addr->sa_family;
- if (family != AF_INET && family != AF_INET6)
+ if (family != AF_INET && family != AF_INET6) {
continue;
+ }
Map<String, Interface_Info>::Element *E = r_interfaces->find(ifa->ifa_name);
if (!E) {
@@ -240,8 +243,9 @@ void IP_Unix::get_local_interfaces(Map<String, Interface_Info> *r_interfaces) co
info.ip_addresses.push_front(_sockaddr2ip(ifa->ifa_addr));
}
- if (ifAddrStruct != nullptr)
+ if (ifAddrStruct != nullptr) {
freeifaddrs(ifAddrStruct);
+ }
}
#endif
diff --git a/drivers/unix/net_socket_posix.cpp b/drivers/unix/net_socket_posix.cpp
index 957a00703b..15ad187ab4 100644
--- a/drivers/unix/net_socket_posix.cpp
+++ b/drivers/unix/net_socket_posix.cpp
@@ -196,12 +196,15 @@ NetSocketPosix::NetError NetSocketPosix::_get_socket_error() const {
print_verbose("Socket error: " + itos(err));
return ERR_NET_OTHER;
#else
- if (errno == EISCONN)
+ if (errno == EISCONN) {
return ERR_NET_IS_CONNECTED;
- if (errno == EINPROGRESS || errno == EALREADY)
+ }
+ if (errno == EINPROGRESS || errno == EALREADY) {
return ERR_NET_IN_PROGRESS;
- if (errno == EAGAIN || errno == EWOULDBLOCK)
+ }
+ if (errno == EAGAIN || errno == EWOULDBLOCK) {
return ERR_NET_WOULD_BLOCK;
+ }
print_verbose("Socket error: " + itos(errno));
return ERR_NET_OTHER;
#endif
@@ -238,16 +241,19 @@ _FORCE_INLINE_ Error NetSocketPosix::_change_multicast_group(IP_Address p_ip, St
IP::get_singleton()->get_local_interfaces(&if_info);
for (Map<String, IP::Interface_Info>::Element *E = if_info.front(); E; E = E->next()) {
IP::Interface_Info &c = E->get();
- if (c.name != p_if_name)
+ if (c.name != p_if_name) {
continue;
+ }
if_v6id = (uint32_t)c.index.to_int64();
- if (type == IP::TYPE_IPV6)
+ if (type == IP::TYPE_IPV6) {
break; // IPv6 uses index.
+ }
for (List<IP_Address>::Element *F = c.ip_addresses.front(); F; F = F->next()) {
- if (!F->get().is_ipv4())
+ if (!F->get().is_ipv4()) {
continue; // Wrong IP type
+ }
if_ip = F->get();
break;
}
@@ -361,8 +367,9 @@ Error NetSocketPosix::open(Type p_sock_type, IP::Type &ip_type) {
}
void NetSocketPosix::close() {
- if (_sock != SOCK_EMPTY)
+ if (_sock != SOCK_EMPTY) {
SOCK_CLOSE(_sock);
+ }
_sock = SOCK_EMPTY;
_ip_type = IP::TYPE_NONE;
@@ -508,8 +515,9 @@ Error NetSocketPosix::poll(PollType p_type, int p_timeout) const {
return FAILED;
}
- if (ret == 0)
+ if (ret == 0) {
return ERR_BUSY;
+ }
return OK;
#endif
@@ -522,8 +530,9 @@ Error NetSocketPosix::recv(uint8_t *p_buffer, int p_len, int &r_read) {
if (r_read < 0) {
NetError err = _get_socket_error();
- if (err == ERR_NET_WOULD_BLOCK)
+ if (err == ERR_NET_WOULD_BLOCK) {
return ERR_BUSY;
+ }
return FAILED;
}
@@ -542,8 +551,9 @@ Error NetSocketPosix::recvfrom(uint8_t *p_buffer, int p_len, int &r_read, IP_Add
if (r_read < 0) {
NetError err = _get_socket_error();
- if (err == ERR_NET_WOULD_BLOCK)
+ if (err == ERR_NET_WOULD_BLOCK) {
return ERR_BUSY;
+ }
return FAILED;
}
@@ -569,15 +579,17 @@ Error NetSocketPosix::send(const uint8_t *p_buffer, int p_len, int &r_sent) {
int flags = 0;
#ifdef MSG_NOSIGNAL
- if (_is_stream)
+ if (_is_stream) {
flags = MSG_NOSIGNAL;
+ }
#endif
r_sent = ::send(_sock, SOCK_CBUF(p_buffer), p_len, flags);
if (r_sent < 0) {
NetError err = _get_socket_error();
- if (err == ERR_NET_WOULD_BLOCK)
+ if (err == ERR_NET_WOULD_BLOCK) {
return ERR_BUSY;
+ }
return FAILED;
}
@@ -594,8 +606,9 @@ Error NetSocketPosix::sendto(const uint8_t *p_buffer, int p_len, int &r_sent, IP
if (r_sent < 0) {
NetError err = _get_socket_error();
- if (err == ERR_NET_WOULD_BLOCK)
+ if (err == ERR_NET_WOULD_BLOCK) {
return ERR_BUSY;
+ }
return FAILED;
}
@@ -606,8 +619,9 @@ Error NetSocketPosix::sendto(const uint8_t *p_buffer, int p_len, int &r_sent, IP
Error NetSocketPosix::set_broadcasting_enabled(bool p_enabled) {
ERR_FAIL_COND_V(!is_open(), ERR_UNCONFIGURED);
// IPv6 has no broadcast support.
- if (_ip_type == IP::TYPE_IPV6)
+ if (_ip_type == IP::TYPE_IPV6) {
return ERR_UNAVAILABLE;
+ }
int par = p_enabled ? 1 : 0;
if (setsockopt(_sock, SOL_SOCKET, SO_BROADCAST, SOCK_CBUF(&par), sizeof(int)) != 0) {
@@ -626,14 +640,16 @@ void NetSocketPosix::set_blocking_enabled(bool p_enabled) {
ret = SOCK_IOCTL(_sock, FIONBIO, &par);
#else
int opts = fcntl(_sock, F_GETFL);
- if (p_enabled)
+ if (p_enabled) {
ret = fcntl(_sock, F_SETFL, opts & ~O_NONBLOCK);
- else
+ } else {
ret = fcntl(_sock, F_SETFL, opts | O_NONBLOCK);
+ }
#endif
- if (ret != 0)
+ if (ret != 0) {
WARN_PRINT("Unable to change non-block mode");
+ }
}
void NetSocketPosix::set_ipv6_only_enabled(bool p_enabled) {
diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp
index 3ba667b2f7..083cd64116 100644
--- a/drivers/unix/os_unix.cpp
+++ b/drivers/unix/os_unix.cpp
@@ -95,8 +95,9 @@ void OS_Unix::debug_break() {
};
static void handle_interrupt(int sig) {
- if (!EngineDebugger::is_active())
+ if (!EngineDebugger::is_active()) {
return;
+ }
EngineDebugger::get_script_debugger()->set_depth(-1);
EngineDebugger::get_script_debugger()->set_lines_left(1);
@@ -181,10 +182,11 @@ uint64_t OS_Unix::get_system_time_msecs() const {
OS::Date OS_Unix::get_date(bool utc) const {
time_t t = time(nullptr);
struct tm *lt;
- if (utc)
+ if (utc) {
lt = gmtime(&t);
- else
+ } else {
lt = localtime(&t);
+ }
Date ret;
ret.year = 1900 + lt->tm_year;
// Index starting at 1 to match OS_Unix::get_date
@@ -201,10 +203,11 @@ OS::Date OS_Unix::get_date(bool utc) const {
OS::Time OS_Unix::get_time(bool utc) const {
time_t t = time(nullptr);
struct tm *lt;
- if (utc)
+ if (utc) {
lt = gmtime(&t);
- else
+ } else {
lt = localtime(&t);
+ }
Time ret;
ret.hour = lt->tm_hour;
ret.min = lt->tm_min;
@@ -231,10 +234,11 @@ OS::TimeZoneInfo OS_Unix::get_time_zone_info() const {
// convert from ISO 8601 (1 minute=1, 1 hour=100) to minutes
int hour = (int)bias / 100;
int minutes = bias % 100;
- if (bias < 0)
+ if (bias < 0) {
ret.bias = hour * 60 - minutes;
- else
+ } else {
ret.bias = hour * 60 + minutes;
+ }
return ret;
}
@@ -295,8 +299,9 @@ Error OS_Unix::execute(const String &p_path, const List<String> &p_arguments, bo
}
}
int rv = pclose(f);
- if (r_exitcode)
+ if (r_exitcode) {
*r_exitcode = WEXITSTATUS(rv);
+ }
return OK;
}
@@ -315,12 +320,14 @@ Error OS_Unix::execute(const String &p_path, const List<String> &p_arguments, bo
Vector<CharString> cs;
cs.push_back(p_path.utf8());
- for (int i = 0; i < p_arguments.size(); i++)
+ for (int i = 0; i < p_arguments.size(); i++) {
cs.push_back(p_arguments[i].utf8());
+ }
Vector<char *> args;
- for (int i = 0; i < cs.size(); i++)
+ for (int i = 0; i < cs.size(); i++) {
args.push_back((char *)cs[i].get_data());
+ }
args.push_back(0);
execvp(p_path.utf8().get_data(), &args[0]);
@@ -332,12 +339,14 @@ Error OS_Unix::execute(const String &p_path, const List<String> &p_arguments, bo
if (p_blocking) {
int status;
waitpid(pid, &status, 0);
- if (r_exitcode)
+ if (r_exitcode) {
*r_exitcode = WEXITSTATUS(status);
+ }
} else {
- if (r_child_id)
+ if (r_child_id) {
*r_child_id = pid;
+ }
}
return OK;
@@ -363,13 +372,15 @@ bool OS_Unix::has_environment(const String &p_var) const {
}
String OS_Unix::get_locale() const {
- if (!has_environment("LANG"))
+ if (!has_environment("LANG")) {
return "en";
+ }
String locale = get_environment("LANG");
int tp = locale.find(".");
- if (tp != -1)
+ if (tp != -1) {
locale = locale.substr(0, tp);
+ }
return locale;
}
@@ -420,15 +431,17 @@ Error OS_Unix::get_dynamic_library_symbol_handle(void *p_library_handle, const S
}
Error OS_Unix::set_cwd(const String &p_cwd) {
- if (chdir(p_cwd.utf8().get_data()) != 0)
+ if (chdir(p_cwd.utf8().get_data()) != 0) {
return ERR_CANT_OPEN;
+ }
return OK;
}
String OS_Unix::get_environment(const String &p_var) const {
- if (getenv(p_var.utf8().get_data()))
+ if (getenv(p_var.utf8().get_data())) {
return getenv(p_var.utf8().get_data());
+ }
return "";
}
@@ -516,10 +529,11 @@ void UnixTerminalLogger::log_error(const char *p_function, const char *p_file, i
}
const char *err_details;
- if (p_rationale && p_rationale[0])
+ if (p_rationale && p_rationale[0]) {
err_details = p_rationale;
- else
+ } else {
err_details = p_code;
+ }
// Disable color codes if stdout is not a TTY.
// This prevents Godot from writing ANSI escape codes when redirecting
diff --git a/drivers/unix/syslog_logger.cpp b/drivers/unix/syslog_logger.cpp
index 8296d6ce30..a4c7070f0e 100644
--- a/drivers/unix/syslog_logger.cpp
+++ b/drivers/unix/syslog_logger.cpp
@@ -67,10 +67,11 @@ void SyslogLogger::print_error(const char *p_function, const char *p_file, int p
}
const char *err_details;
- if (p_rationale && *p_rationale)
+ if (p_rationale && *p_rationale) {
err_details = p_rationale;
- else
+ } else {
err_details = p_code;
+ }
syslog(p_type == ERR_WARNING ? LOG_WARNING : LOG_ERR, "%s: %s\n At: %s:%i:%s() - %s", err_type, err_details, p_file, p_line, p_function, p_code);
}
diff --git a/drivers/unix/thread_posix.cpp b/drivers/unix/thread_posix.cpp
index 16897883e8..aa1b5019ca 100644
--- a/drivers/unix/thread_posix.cpp
+++ b/drivers/unix/thread_posix.cpp
@@ -91,8 +91,9 @@ Thread *ThreadPosix::create_func_posix(ThreadCreateCallback p_callback, void *p_
Thread::ID ThreadPosix::get_thread_id_func_posix() {
void *value = pthread_getspecific(thread_id_key);
- if (value)
+ if (value) {
return *static_cast<ID *>(value);
+ }
ID new_id = atomic_increment(&next_thread_id);
pthread_setspecific(thread_id_key, (void *)memnew(ID(new_id)));
diff --git a/editor/animation_bezier_editor.cpp b/editor/animation_bezier_editor.cpp
index dededfb617..f880ece88b 100644
--- a/editor/animation_bezier_editor.cpp
+++ b/editor/animation_bezier_editor.cpp
@@ -70,8 +70,9 @@ void AnimationBezierTrackEdit::_draw_track(int p_track, const Color &p_color) {
for (Map<float, int>::Element *E = key_order.front(); E; E = E->next()) {
int i = E->get();
- if (!E->next())
+ if (!E->next()) {
break;
+ }
int i_n = E->next()->get();
@@ -111,11 +112,13 @@ void AnimationBezierTrackEdit::_draw_track(int p_track, const Color &p_color) {
int to_x = (offset_n - timeline->get_value()) * scale + limit;
int point_end = to_x;
- if (from_x > right_limit) //not visible
+ if (from_x > right_limit) { //not visible
continue;
+ }
- if (to_x < limit) //not visible
+ if (to_x < limit) { //not visible
continue;
+ }
from_x = MAX(from_x, limit);
to_x = MIN(to_x, right_limit);
@@ -182,17 +185,20 @@ void AnimationBezierTrackEdit::_draw_line_clipped(const Vector2 &p_from, const V
Vector2 from = p_from;
Vector2 to = p_to;
- if (from.x == to.x)
+ if (from.x == to.x) {
return;
+ }
if (to.x < from.x) {
SWAP(to, from);
}
- if (to.x < p_clip_left)
+ if (to.x < p_clip_left) {
return;
+ }
- if (from.x > p_clip_right)
+ if (from.x > p_clip_right) {
return;
+ }
if (to.x > p_clip_right) {
float c = (p_clip_right - from.x) / (to.x - from.x);
@@ -227,8 +233,9 @@ void AnimationBezierTrackEdit::_notification(int p_what) {
handle_mode_option->set_size(Vector2(timeline->get_buttons_width() - hsep * 2, handle_mode_option->get_combined_minimum_size().height));
}
if (p_what == NOTIFICATION_DRAW) {
- if (animation.is_null())
+ if (animation.is_null()) {
return;
+ }
int limit = timeline->get_name_limit();
@@ -309,11 +316,13 @@ void AnimationBezierTrackEdit::_notification(int p_what) {
subtracks.clear();
for (int i = 0; i < animation->get_track_count(); i++) {
- if (animation->track_get_type(i) != Animation::TYPE_BEZIER)
+ if (animation->track_get_type(i) != Animation::TYPE_BEZIER) {
continue;
+ }
String path = animation->track_get_path(i);
- if (!path.begins_with(base_path))
+ if (!path.begins_with(base_path)) {
continue; //another node
+ }
path = path.replace_first(base_path, "");
Color cc = color;
@@ -363,8 +372,9 @@ void AnimationBezierTrackEdit::_notification(int p_what) {
ofs += v_scroll;
int iv = int(ofs / scale);
- if (ofs < 0)
+ if (ofs < 0) {
iv -= 1;
+ }
if (!first && iv != prev_iv) {
Color lc = linecolor;
lc.a *= 0.5;
@@ -488,10 +498,12 @@ Ref<Animation> AnimationBezierTrackEdit::get_animation() const {
void AnimationBezierTrackEdit::set_animation_and_track(const Ref<Animation> &p_animation, int p_track) {
animation = p_animation;
track = p_track;
- if (is_connected_compat("select_key", editor, "_key_selected"))
+ if (is_connected_compat("select_key", editor, "_key_selected")) {
disconnect_compat("select_key", editor, "_key_selected");
- if (is_connected_compat("deselect_key", editor, "_key_deselected"))
+ }
+ if (is_connected_compat("deselect_key", editor, "_key_deselected")) {
disconnect_compat("deselect_key", editor, "_key_deselected");
+ }
connect_compat("select_key", editor, "_key_selected", varray(p_track), CONNECT_DEFERRED);
connect_compat("deselect_key", editor, "_key_deselected", varray(p_track), CONNECT_DEFERRED);
update();
@@ -516,8 +528,9 @@ void AnimationBezierTrackEdit::set_editor(AnimationTrackEditor *p_editor) {
}
void AnimationBezierTrackEdit::_play_position_draw() {
- if (!animation.is_valid() || play_position_pos < 0)
+ if (!animation.is_valid() || play_position_pos < 0) {
return;
+ }
float scale = timeline->get_zoom_scale();
int h = get_size().height;
@@ -558,15 +571,17 @@ void AnimationBezierTrackEdit::_clear_selection() {
}
void AnimationBezierTrackEdit::_clear_selection_for_anim(const Ref<Animation> &p_anim) {
- if (!(animation == p_anim))
+ if (!(animation == p_anim)) {
return;
+ }
//selection.clear();
_clear_selection();
}
void AnimationBezierTrackEdit::_select_at_anim(const Ref<Animation> &p_anim, int p_track, float p_pos) {
- if (!(animation == p_anim))
+ if (!(animation == p_anim)) {
return;
+ }
int idx = animation->track_find_key(p_track, p_pos, true);
ERR_FAIL_COND(idx < 0);
@@ -822,11 +837,13 @@ void AnimationBezierTrackEdit::_gui_input(const Ref<InputEvent> &p_event) {
float newtime = editor->snap_time(animation->track_get_key_time(track, E->get()) + moving_selection_offset.x);
int idx = animation->track_find_key(track, newtime, true);
- if (idx == -1)
+ if (idx == -1) {
continue;
+ }
- if (selection.has(idx))
+ if (selection.has(idx)) {
continue; //already in selection, don't save
+ }
undo_redo->add_do_method(animation.ptr(), "track_remove_key_at_position", track, newtime);
AnimMoveRestore amr;
@@ -902,10 +919,12 @@ void AnimationBezierTrackEdit::_gui_input(const Ref<InputEvent> &p_event) {
Ref<InputEventMouseMotion> mm = p_event;
if (mm.is_valid() && mm->get_button_mask() & BUTTON_MASK_MIDDLE) {
v_scroll += mm->get_relative().y * v_zoom;
- if (v_scroll > 100000)
+ if (v_scroll > 100000) {
v_scroll = 100000;
- if (v_scroll < -100000)
+ }
+ if (v_scroll < -100000) {
v_scroll = -100000;
+ }
int x = mm->get_position().x - timeline->get_name_limit();
float ofs = x / timeline->get_zoom_scale();
@@ -1021,14 +1040,16 @@ void AnimationBezierTrackEdit::_menu_selected(int p_index) {
}
void AnimationBezierTrackEdit::duplicate_selection() {
- if (selection.size() == 0)
+ if (selection.size() == 0) {
return;
+ }
float top_time = 1e10;
for (Set<int>::Element *E = selection.back(); E; E = E->prev()) {
float t = animation->track_get_key_time(track, E->get());
- if (t < top_time)
+ if (t < top_time) {
top_time = t;
+ }
}
undo_redo->create_action(TTR("Anim Duplicate Keys"));
@@ -1064,8 +1085,9 @@ void AnimationBezierTrackEdit::duplicate_selection() {
int existing_idx = animation->track_find_key(track, time, true);
- if (existing_idx == -1)
+ if (existing_idx == -1) {
continue;
+ }
selection.insert(existing_idx);
}
diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp
index 0808946b16..2a8e0d856e 100644
--- a/editor/animation_track_editor.cpp
+++ b/editor/animation_track_editor.cpp
@@ -65,8 +65,9 @@ public:
void _fix_node_path(Variant &value) {
NodePath np = value;
- if (np == NodePath())
+ if (np == NodePath()) {
return;
+ }
Node *root = EditorNode::get_singleton()->get_tree()->get_root();
@@ -80,20 +81,23 @@ public:
}
void _update_obj(const Ref<Animation> &p_anim) {
- if (setting || animation != p_anim)
+ if (setting || animation != p_anim) {
return;
+ }
notify_change();
}
void _key_ofs_changed(const Ref<Animation> &p_anim, float from, float to) {
- if (animation != p_anim || from != key_ofs)
+ if (animation != p_anim || from != key_ofs) {
return;
+ }
key_ofs = to;
- if (setting)
+ if (setting) {
return;
+ }
notify_change();
}
@@ -114,8 +118,9 @@ public:
new_time /= fps;
}
- if (new_time == key_ofs)
+ if (new_time == key_ofs) {
return true;
+ }
int existing = animation->track_find_key(track, new_time, true);
@@ -242,10 +247,11 @@ public:
}
}
- if (mergeable)
+ if (mergeable) {
undo_redo->create_action(TTR("Anim Change Call"), UndoRedo::MERGE_ENDS);
- else
+ } else {
undo_redo->create_action(TTR("Anim Change Call"));
+ }
setting = true;
undo_redo->add_do_method(animation.ptr(), "track_set_key_value", track, key, d_new);
@@ -255,8 +261,9 @@ public:
undo_redo->commit_action();
setting = false;
- if (change_notify_deserved)
+ if (change_notify_deserved) {
notify_change();
+ }
return true;
} break;
case Animation::TYPE_BEZIER: {
@@ -499,8 +506,9 @@ public:
return false;
}
void _get_property_list(List<PropertyInfo> *p_list) const {
- if (animation.is_null())
+ if (animation.is_null()) {
return;
+ }
ERR_FAIL_INDEX(track, animation->get_track_count());
int key = animation->track_find_key(track, key_ofs, true);
@@ -540,8 +548,9 @@ public:
}
}
- if (v.get_type() != Variant::NIL)
+ if (v.get_type() != Variant::NIL) {
p_list->push_back(PropertyInfo(v.get_type(), "value", hint, hint_string));
+ }
}
} break;
@@ -554,15 +563,17 @@ public:
Vector<Variant> args = d["args"];
String vtypes;
for (int i = 0; i < Variant::VARIANT_MAX; i++) {
- if (i > 0)
+ if (i > 0) {
vtypes += ",";
+ }
vtypes += Variant::get_type_name(Variant::Type(i));
}
for (int i = 0; i < args.size(); i++) {
p_list->push_back(PropertyInfo(Variant::INT, "args/" + itos(i) + "/type", PROPERTY_HINT_ENUM, vtypes));
- if (args[i].get_type() != Variant::NIL)
+ if (args[i].get_type() != Variant::NIL) {
p_list->push_back(PropertyInfo(args[i].get_type(), "args/" + itos(i) + "/value"));
+ }
}
} break;
@@ -668,8 +679,9 @@ public:
void _fix_node_path(Variant &value, NodePath &base) {
NodePath np = value;
- if (np == NodePath())
+ if (np == NodePath()) {
return;
+ }
Node *root = EditorNode::get_singleton()->get_tree()->get_root();
@@ -683,15 +695,17 @@ public:
}
void _update_obj(const Ref<Animation> &p_anim) {
- if (setting || animation != p_anim)
+ if (setting || animation != p_anim) {
return;
+ }
notify_change();
}
void _key_ofs_changed(const Ref<Animation> &p_anim, float from, float to) {
- if (animation != p_anim)
+ if (animation != p_anim) {
return;
+ }
for (Map<int, List<float>>::Element *E = key_ofs_map.front(); E; E = E->next()) {
int key = 0;
@@ -705,8 +719,9 @@ public:
int track = E->key();
key_ofs_map[track][key] = to;
- if (setting)
+ if (setting) {
return;
+ }
notify_change();
@@ -853,10 +868,11 @@ public:
Variant prev = animation->track_get_key_value(track, key);
if (!setting) {
- if (mergeable)
+ if (mergeable) {
undo_redo->create_action(TTR("Anim Multi Change Call"), UndoRedo::MERGE_ENDS);
- else
+ } else {
undo_redo->create_action(TTR("Anim Multi Change Call"));
+ }
setting = true;
}
@@ -964,8 +980,9 @@ public:
undo_redo->commit_action();
setting = false;
- if (change_notify_deserved)
+ if (change_notify_deserved) {
notify_change();
+ }
return true;
}
@@ -1099,8 +1116,9 @@ public:
return false;
}
void _get_property_list(List<PropertyInfo> *p_list) const {
- if (animation.is_null())
+ if (animation.is_null()) {
return;
+ }
int first_track = -1;
float first_key = -1.0;
@@ -1112,11 +1130,13 @@ public:
int track = E->key();
ERR_FAIL_INDEX(track, animation->get_track_count());
- if (first_track < 0)
+ if (first_track < 0) {
first_track = track;
+ }
- if (show_time && E->value().size() > 1)
+ if (show_time && E->value().size() > 1) {
show_time = false;
+ }
if (same_track_type) {
if (animation->track_get_type(first_track) != animation->track_get_type(track)) {
@@ -1127,11 +1147,13 @@ public:
for (List<float>::Element *F = E->value().front(); F; F = F->next()) {
int key = animation->track_find_key(track, F->get(), true);
ERR_FAIL_COND(key == -1);
- if (first_key < 0)
+ if (first_key < 0) {
first_key = key;
+ }
- if (animation->track_get_key_value(first_track, first_key).get_type() != animation->track_get_key_value(track, key).get_type())
+ if (animation->track_get_key_value(first_track, first_key).get_type() != animation->track_get_key_value(track, key).get_type()) {
same_key_type = false;
+ }
}
}
}
@@ -1153,8 +1175,9 @@ public:
p_list->push_back(PropertyInfo(Variant::VECTOR3, "scale"));
} break;
case Animation::TYPE_VALUE: {
- if (!same_key_type)
+ if (!same_key_type) {
break;
+ }
Variant v = animation->track_get_key_value(first_track, first_key);
@@ -1175,8 +1198,9 @@ public:
}
}
- if (v.get_type() != Variant::NIL)
+ if (v.get_type() != Variant::NIL) {
p_list->push_back(PropertyInfo(v.get_type(), "value", hint, hint_string));
+ }
}
p_list->push_back(PropertyInfo(Variant::FLOAT, "easing", PROPERTY_HINT_EXP_EASING));
@@ -1190,15 +1214,17 @@ public:
Vector<Variant> args = d["args"];
String vtypes;
for (int i = 0; i < Variant::VARIANT_MAX; i++) {
- if (i > 0)
+ if (i > 0) {
vtypes += ",";
+ }
vtypes += Variant::get_type_name(Variant::Type(i));
}
for (int i = 0; i < args.size(); i++) {
p_list->push_back(PropertyInfo(Variant::INT, "args/" + itos(i) + "/type", PROPERTY_HINT_ENUM, vtypes));
- if (args[i].get_type() != Variant::NIL)
+ if (args[i].get_type() != Variant::NIL) {
p_list->push_back(PropertyInfo(args[i].get_type(), "args/" + itos(i) + "/value"));
+ }
}
} break;
case Animation::TYPE_BEZIER: {
@@ -1212,8 +1238,9 @@ public:
p_list->push_back(PropertyInfo(Variant::FLOAT, "end_offset", PROPERTY_HINT_RANGE, "0,3600,0.01,or_greater"));
} break;
case Animation::TYPE_ANIMATION: {
- if (key_ofs_map.size() > 1)
+ if (key_ofs_map.size() > 1) {
break;
+ }
String animations;
@@ -1292,8 +1319,9 @@ float AnimationTimelineEdit::get_zoom_scale() const {
}
void AnimationTimelineEdit::_anim_length_changed(double p_new_len) {
- if (editing)
+ if (editing) {
return;
+ }
p_new_len = MAX(0.001, p_new_len);
if (use_fps && animation->get_step() > 0) {
@@ -1364,8 +1392,9 @@ void AnimationTimelineEdit::_notification(int p_what) {
if (p_what == NOTIFICATION_DRAW) {
int key_range = get_size().width - get_buttons_width() - get_name_limit();
- if (!animation.is_valid())
+ if (!animation.is_valid()) {
return;
+ }
Ref<Font> font = get_theme_font("font", "Label");
Color color = get_theme_color("font_color", "Label");
@@ -1375,8 +1404,9 @@ void AnimationTimelineEdit::_notification(int p_what) {
int h = get_size().height;
float l = animation->get_length();
- if (l <= 0)
+ if (l <= 0) {
l = 0.001; //avoid crashor
+ }
Ref<Texture2D> hsize_icon = get_theme_icon("Hsize", "EditorIcons");
hsize_rect = Rect2(get_name_limit() - hsize_icon->get_width() - 2 * EDSCALE, (get_size().height - hsize_icon->get_height()) / 2, hsize_icon->get_width(), hsize_icon->get_height());
@@ -1392,16 +1422,18 @@ void AnimationTimelineEdit::_notification(int p_what) {
beg += animation->bezier_track_get_key_in_handle(i, 0).x;
}* not worth it since they have no use */
- if (beg < time_min)
+ if (beg < time_min) {
time_min = beg;
+ }
float end = animation->track_get_key_time(i, animation->track_get_key_count(i) - 1);
/*if (animation->track_get_type(i) == Animation::TYPE_BEZIER) {
end += animation->bezier_track_get_key_out_handle(i, animation->track_get_key_count(i) - 1).x;
} not worth it since they have no use */
- if (end > time_max)
+ if (end > time_max) {
time_max = end;
+ }
}
}
@@ -1435,10 +1467,12 @@ void AnimationTimelineEdit::_notification(int p_what) {
draw_rect(Rect2(Point2(get_name_limit(), 0), Point2(zoomw - 1, h)), notimecol);
if (begin_px < zoomw && end_px > 0) {
- if (begin_px < 0)
+ if (begin_px < 0) {
begin_px = 0;
- if (end_px > zoomw)
+ }
+ if (end_px > zoomw) {
end_px = zoomw;
+ }
draw_rect(Rect2(Point2(get_name_limit() + begin_px, 0), Point2(end_px - begin_px - 1, h)), timecolor);
}
@@ -1465,8 +1499,9 @@ void AnimationTimelineEdit::_notification(int p_what) {
while (!step_found) {
min = max_sc_width;
- if (decimals > 0)
+ if (decimals > 0) {
min += period_width + max_digit_width * decimals;
+ }
static const int _multp[3] = { 1, 2, 5 };
for (int i = 0; i < 3; i++) {
@@ -1476,12 +1511,14 @@ void AnimationTimelineEdit::_notification(int p_what) {
break;
}
}
- if (step_found)
+ if (step_found) {
break;
+ }
dec *= 10;
decimals--;
- if (decimals < 0)
+ if (decimals < 0) {
decimals = 0;
+ }
}
if (use_fps) {
@@ -1574,8 +1611,9 @@ void AnimationTimelineEdit::update_play_position() {
}
void AnimationTimelineEdit::update_values() {
- if (!animation.is_valid() || editing)
+ if (!animation.is_valid() || editing) {
return;
+ }
editing = true;
if (use_fps && animation->get_step() > 0) {
@@ -1594,8 +1632,9 @@ void AnimationTimelineEdit::update_values() {
}
void AnimationTimelineEdit::_play_position_draw() {
- if (!animation.is_valid() || play_position_pos < 0)
+ if (!animation.is_valid() || play_position_pos < 0) {
return;
+ }
float scale = get_zoom_scale();
int h = play_position->get_size().height;
@@ -1764,8 +1803,9 @@ AnimationTimelineEdit::AnimationTimelineEdit() {
void AnimationTrackEdit::_notification(int p_what) {
if (p_what == NOTIFICATION_DRAW) {
- if (animation.is_null())
+ if (animation.is_null()) {
return;
+ }
ERR_FAIL_INDEX(track, animation->get_track_count());
int limit = timeline->get_name_limit();
@@ -2062,15 +2102,17 @@ void AnimationTrackEdit::_notification(int p_what) {
}
int AnimationTrackEdit::get_key_height() const {
- if (!animation.is_valid())
+ if (!animation.is_valid()) {
return 0;
+ }
return type_icon->get_height();
}
Rect2 AnimationTrackEdit::get_key_rect(int p_index, float p_pixels_sec) {
- if (!animation.is_valid())
+ if (!animation.is_valid()) {
return Rect2();
+ }
Rect2 rect = Rect2(-type_icon->get_width() / 2, 0, type_icon->get_width(), get_size().height);
//make it a big easier to click
@@ -2084,15 +2126,18 @@ bool AnimationTrackEdit::is_key_selectable_by_distance() const {
}
void AnimationTrackEdit::draw_key_link(int p_index, float p_pixels_sec, int p_x, int p_next_x, int p_clip_left, int p_clip_right) {
- if (p_next_x < p_clip_left)
+ if (p_next_x < p_clip_left) {
return;
- if (p_x > p_clip_right)
+ }
+ if (p_x > p_clip_right) {
return;
+ }
Variant current = animation->track_get_key_value(get_track(), p_index);
Variant next = animation->track_get_key_value(get_track(), p_index + 1);
- if (current != next)
+ if (current != next) {
return;
+ }
Color color = get_theme_color("font_color", "Label");
color.a = 0.5;
@@ -2104,11 +2149,13 @@ void AnimationTrackEdit::draw_key_link(int p_index, float p_pixels_sec, int p_x,
}
void AnimationTrackEdit::draw_key(int p_index, float p_pixels_sec, int p_x, bool p_selected, int p_clip_left, int p_clip_right) {
- if (!animation.is_valid())
+ if (!animation.is_valid()) {
return;
+ }
- if (p_x < p_clip_left || p_x > p_clip_right)
+ if (p_x < p_clip_left || p_x > p_clip_right) {
return;
+ }
Ref<Texture2D> icon_to_draw = p_selected ? selected_icon : type_icon;
@@ -2131,15 +2178,18 @@ void AnimationTrackEdit::draw_key(int p_index, float p_pixels_sec, int p_x, bool
Dictionary d = animation->track_get_key_value(track, p_index);
String text;
- if (d.has("method"))
+ if (d.has("method")) {
text += String(d["method"]);
+ }
text += "(";
Vector<Variant> args;
- if (d.has("args"))
+ if (d.has("args")) {
args = d["args"];
+ }
for (int i = 0; i < args.size(); i++) {
- if (i > 0)
+ if (i > 0) {
text += ", ";
+ }
text += String(args[i]);
}
text += ")";
@@ -2158,10 +2208,12 @@ void AnimationTrackEdit::draw_rect_clipped(const Rect2 &p_rect, const Color &p_c
int clip_left = timeline->get_name_limit();
int clip_right = get_size().width - timeline->get_buttons_width();
- if (p_rect.position.x > clip_right)
+ if (p_rect.position.x > clip_right) {
return;
- if (p_rect.position.x + p_rect.size.x < clip_left)
+ }
+ if (p_rect.position.x + p_rect.size.x < clip_left) {
return;
+ }
Rect2 clip = Rect2(clip_left, 0, clip_right - clip_left, get_size().height);
draw_rect(clip.clip(p_rect), p_color, p_filled);
}
@@ -2181,10 +2233,12 @@ void AnimationTrackEdit::draw_texture_region_clipped(const Ref<Texture2D> &p_tex
int clip_right = get_size().width - timeline->get_buttons_width();
//clip left and right
- if (clip_left > p_rect.position.x + p_rect.size.x)
+ if (clip_left > p_rect.position.x + p_rect.size.x) {
return;
- if (clip_right < p_rect.position.x)
+ }
+ if (clip_right < p_rect.position.x) {
return;
+ }
Rect2 rect = p_rect;
Rect2 region = p_region;
@@ -2270,8 +2324,9 @@ void AnimationTrackEdit::set_editor(AnimationTrackEditor *p_editor) {
}
void AnimationTrackEdit::_play_position_draw() {
- if (!animation.is_valid() || play_position_pos < 0)
+ if (!animation.is_valid() || play_position_pos < 0) {
return;
+ }
float scale = timeline->get_zoom_scale();
int h = get_size().height;
@@ -2311,8 +2366,9 @@ void AnimationTrackEdit::_path_entered(const String &p_text) {
}
bool AnimationTrackEdit::_is_value_key_valid(const Variant &p_key_value, Variant::Type &r_valid_type) const {
- if (root == nullptr)
+ if (root == nullptr) {
return false;
+ }
RES res;
Vector<StringName> leftover_path;
@@ -2394,12 +2450,15 @@ String AnimationTrackEdit::get_tooltip(const Point2 &p_pos) const {
switch (animation->track_get_type(track)) {
case Animation::TYPE_TRANSFORM: {
Dictionary d = animation->track_get_key_value(track, key_idx);
- if (d.has("location"))
+ if (d.has("location")) {
text += "Pos: " + String(d["location"]) + "\n";
- if (d.has("rotation"))
+ }
+ if (d.has("rotation")) {
text += "Rot: " + String(d["rotation"]) + "\n";
- if (d.has("scale"))
+ }
+ if (d.has("scale")) {
text += "Scale: " + String(d["scale"]) + "\n";
+ }
} break;
case Animation::TYPE_VALUE: {
const Variant &v = animation->track_get_key_value(track, key_idx);
@@ -2415,15 +2474,18 @@ String AnimationTrackEdit::get_tooltip(const Point2 &p_pos) const {
} break;
case Animation::TYPE_METHOD: {
Dictionary d = animation->track_get_key_value(track, key_idx);
- if (d.has("method"))
+ if (d.has("method")) {
text += String(d["method"]);
+ }
text += "(";
Vector<Variant> args;
- if (d.has("args"))
+ if (d.has("args")) {
args = d["args"];
+ }
for (int i = 0; i < args.size(); i++) {
- if (i > 0)
+ if (i > 0) {
text += ", ";
+ }
text += String(args[i]);
}
text += ")\n";
@@ -2713,8 +2775,9 @@ void AnimationTrackEdit::_gui_input(const Ref<InputEvent> &p_event) {
}
Variant AnimationTrackEdit::get_drag_data(const Point2 &p_point) {
- if (!clicking_on_name)
+ if (!clicking_on_name) {
return Variant();
+ }
Dictionary drag_data;
drag_data["type"] = "animation_track";
@@ -2868,10 +2931,11 @@ void AnimationTrackEdit::append_to_selection(const Rect2 &p_box, bool p_deselect
rect.position.x += offset;
if (select_rect.intersects(rect)) {
- if (p_deselection)
+ if (p_deselection) {
emit_signal("deselect_key", i);
- else
+ } else {
emit_signal("select_key", i, false);
+ }
}
}
}
@@ -3044,8 +3108,9 @@ AnimationTrackEditGroup::AnimationTrackEditGroup() {
//////////////////////////////////////
void AnimationTrackEditor::add_track_edit_plugin(const Ref<AnimationTrackEditPlugin> &p_plugin) {
- if (track_edit_plugins.find(p_plugin) != -1)
+ if (track_edit_plugins.find(p_plugin) != -1) {
return;
+ }
track_edit_plugins.push_back(p_plugin);
}
@@ -3129,8 +3194,9 @@ Node *AnimationTrackEditor::get_root() const {
void AnimationTrackEditor::update_keying() {
bool keying_enabled = is_visible_in_tree() && animation.is_valid();
- if (keying_enabled == keying)
+ if (keying_enabled == keying) {
return;
+ }
keying = keying_enabled;
//_update_menu();
@@ -3224,8 +3290,9 @@ void AnimationTrackEditor::_track_remove_request(int p_track) {
void AnimationTrackEditor::_track_grab_focus(int p_track) {
// Don't steal focus if not working with the track editor.
- if (Object::cast_to<AnimationTrackEdit>(get_focus_owner()))
+ if (Object::cast_to<AnimationTrackEdit>(get_focus_owner())) {
track_edits[p_track]->grab_focus();
+ }
}
void AnimationTrackEditor::set_anim_pos(float p_pos) {
@@ -3242,8 +3309,9 @@ void AnimationTrackEditor::set_anim_pos(float p_pos) {
void AnimationTrackEditor::_query_insert(const InsertData &p_id) {
if (insert_frame != Engine::get_singleton()->get_frames_drawn()) {
//clear insert list for the frame if frame changed
- if (insert_confirm->is_visible())
+ if (insert_confirm->is_visible()) {
return; //do nothing
+ }
insert_data.clear();
insert_query = false;
}
@@ -3251,8 +3319,9 @@ void AnimationTrackEditor::_query_insert(const InsertData &p_id) {
for (List<InsertData>::Element *E = insert_data.front(); E; E = E->next()) {
//prevent insertion of multiple tracks
- if (E->get().path == p_id.path)
+ if (E->get().path == p_id.path) {
return; //already inserted a track for this on this frame
+ }
}
insert_data.push_back(p_id);
@@ -3263,14 +3332,17 @@ void AnimationTrackEditor::_query_insert(const InsertData &p_id) {
int num_tracks = 0;
bool all_bezier = true;
for (int i = 0; i < insert_data.size(); i++) {
- if (insert_data[i].type != Animation::TYPE_VALUE && insert_data[i].type != Animation::TYPE_BEZIER)
+ if (insert_data[i].type != Animation::TYPE_VALUE && insert_data[i].type != Animation::TYPE_BEZIER) {
all_bezier = false;
+ }
- if (insert_data[i].track_idx == -1)
+ if (insert_data[i].track_idx == -1) {
++num_tracks;
+ }
- if (insert_data[i].type != Animation::TYPE_VALUE)
+ if (insert_data[i].type != Animation::TYPE_VALUE) {
continue;
+ }
switch (insert_data[i].value.get_type()) {
case Variant::INT:
@@ -3288,10 +3360,11 @@ void AnimationTrackEditor::_query_insert(const InsertData &p_id) {
}
}
- if (num_tracks == 1)
+ if (num_tracks == 1) {
insert_confirm_text->set_text(vformat(TTR("Create NEW track for %s and insert key?"), p_id.query));
- else
+ } else {
insert_confirm_text->set_text(vformat(TTR("Create %d NEW tracks and insert keys?"), num_tracks));
+ }
insert_confirm_bezier->set_visible(all_bezier);
insert_confirm->get_ok()->set_text(TTR("Create"));
@@ -3322,8 +3395,9 @@ void AnimationTrackEditor::_insert_delay() {
int last_track = animation->get_track_count();
bool advance = false;
while (insert_data.size()) {
- if (insert_data.front()->get().advance)
+ if (insert_data.front()->get().advance) {
advance = true;
+ }
last_track = _confirm_insert(insert_data.front()->get(), last_track);
insert_data.pop_front();
}
@@ -3332,14 +3406,16 @@ void AnimationTrackEditor::_insert_delay() {
if (advance) {
float step = animation->get_step();
- if (step == 0)
+ if (step == 0) {
step = 1;
+ }
float pos = timeline->get_play_position();
pos = Math::stepify(pos + step, step);
- if (pos > animation->get_length())
+ if (pos > animation->get_length()) {
pos = animation->get_length();
+ }
set_anim_pos(pos);
emit_signal("timeline_changed", pos, true);
}
@@ -3347,26 +3423,31 @@ void AnimationTrackEditor::_insert_delay() {
}
void AnimationTrackEditor::insert_transform_key(Node3D *p_node, const String &p_sub, const Transform &p_xform) {
- if (!keying)
+ if (!keying) {
return;
- if (!animation.is_valid())
+ }
+ if (!animation.is_valid()) {
return;
+ }
ERR_FAIL_COND(!root);
//let's build a node path
String path = root->get_path_to(p_node);
- if (p_sub != "")
+ if (p_sub != "") {
path += ":" + p_sub;
+ }
NodePath np = path;
int track_idx = -1;
for (int i = 0; i < animation->get_track_count(); i++) {
- if (animation->track_get_type(i) != Animation::TYPE_TRANSFORM)
+ if (animation->track_get_type(i) != Animation::TYPE_TRANSFORM) {
continue;
- if (animation->track_get_path(i) != np)
+ }
+ if (animation->track_get_path(i) != np) {
continue;
+ }
track_idx = i;
break;
@@ -3454,8 +3535,9 @@ void AnimationTrackEditor::insert_node_value_key(Node *p_node, const String &p_p
for (int i = 0; i < animation->get_track_count(); i++) {
if (animation->track_get_type(i) == Animation::TYPE_VALUE) {
- if (animation->track_get_path(i) != np)
+ if (animation->track_get_path(i) != np) {
continue;
+ }
InsertData id;
id.path = np;
@@ -3479,10 +3561,12 @@ void AnimationTrackEditor::insert_node_value_key(Node *p_node, const String &p_p
if (base_path == np) {
String value_name = track_path.substr(sep + 1);
value = p_value.get(value_name);
- } else
+ } else {
continue;
- } else
+ }
+ } else {
continue;
+ }
}
InsertData id;
@@ -3498,8 +3582,9 @@ void AnimationTrackEditor::insert_node_value_key(Node *p_node, const String &p_p
}
}
- if (inserted || p_only_if_exists)
+ if (inserted || p_only_if_exists) {
return;
+ }
InsertData id;
id.path = np;
id.track_idx = -1;
@@ -3549,8 +3634,9 @@ void AnimationTrackEditor::insert_value_key(const String &p_property, const Vari
for (int i = 0; i < animation->get_track_count(); i++) {
if (animation->track_get_type(i) == Animation::TYPE_VALUE) {
- if (animation->track_get_path(i) != np)
+ if (animation->track_get_path(i) != np) {
continue;
+ }
InsertData id;
id.path = np;
@@ -3728,8 +3814,9 @@ static Vector<String> _get_bezier_subindices_for_type(Variant::Type p_type, bool
}
int AnimationTrackEditor::_confirm_insert(InsertData p_id, int p_last_track, bool p_create_beziers) {
- if (p_last_track == -1)
+ if (p_last_track == -1) {
p_last_track = animation->get_track_count();
+ }
bool created = false;
if (p_id.track_idx < 0) {
@@ -3786,8 +3873,9 @@ int AnimationTrackEditor::_confirm_insert(InsertData p_id, int p_last_track, boo
undo_redo->add_do_method(animation.ptr(), "add_track", p_id.type);
undo_redo->add_do_method(animation.ptr(), "track_set_path", p_id.track_idx, p_id.path);
- if (p_id.type == Animation::TYPE_VALUE)
+ if (p_id.type == Animation::TYPE_VALUE) {
undo_redo->add_do_method(animation.ptr(), "value_track_set_update_mode", p_id.track_idx, update_mode);
+ }
} else {
undo_redo->create_action(TTR("Anim Insert Key"));
@@ -3879,8 +3967,9 @@ void AnimationTrackEditor::_update_tracks() {
track_edits.clear();
groups.clear();
- if (animation.is_null())
+ if (animation.is_null()) {
return;
+ }
Map<String, VBoxContainer *> group_sort;
@@ -4044,10 +4133,11 @@ void AnimationTrackEditor::_animation_changed() {
if (key_edit && key_edit->setting) {
//if editing a key, just update the edited track, makes refresh less costly
if (key_edit->track < track_edits.size()) {
- if (animation->track_get_type(key_edit->track) == Animation::TYPE_BEZIER)
+ if (animation->track_get_type(key_edit->track) == Animation::TYPE_BEZIER) {
bezier_edit->update();
- else
+ } else {
track_edits[key_edit->track]->update();
+ }
}
return;
}
@@ -4363,8 +4453,9 @@ void AnimationTrackEditor::_timeline_value_changed(double) {
int AnimationTrackEditor::_get_track_selected() {
for (int i = 0; i < track_edits.size(); i++) {
- if (track_edits[i]->has_focus())
+ if (track_edits[i]->has_focus()) {
return i;
+ }
}
return -1;
@@ -4608,8 +4699,9 @@ void AnimationTrackEditor::_clear_selection(bool p_update) {
void AnimationTrackEditor::_update_key_edit() {
_clear_key_edit();
- if (!animation.is_valid())
+ if (!animation.is_valid()) {
return;
+ }
if (selection.size() == 1) {
key_edit = memnew(AnimationTrackKeyEdit);
@@ -4636,8 +4728,9 @@ void AnimationTrackEditor::_update_key_edit() {
int first_track = -1;
for (Map<SelectedKey, KeyInfo>::Element *E = selection.front(); E; E = E->next()) {
int track = E->key().track;
- if (first_track < 0)
+ if (first_track < 0) {
first_track = track;
+ }
if (!key_ofs_map.has(track)) {
key_ofs_map[track] = List<float>();
@@ -4661,15 +4754,17 @@ void AnimationTrackEditor::_update_key_edit() {
}
void AnimationTrackEditor::_clear_selection_for_anim(const Ref<Animation> &p_anim) {
- if (animation != p_anim)
+ if (animation != p_anim) {
return;
+ }
_clear_selection();
}
void AnimationTrackEditor::_select_at_anim(const Ref<Animation> &p_anim, int p_track, float p_pos) {
- if (animation != p_anim)
+ if (animation != p_anim) {
return;
+ }
int idx = animation->track_find_key(p_track, p_pos, true);
ERR_FAIL_COND(idx < 0);
@@ -4697,13 +4792,15 @@ void AnimationTrackEditor::_move_selection_commit() {
for (Map<SelectedKey, KeyInfo>::Element *E = selection.back(); E; E = E->prev()) {
float newtime = snap_time(E->get().pos + motion);
int idx = animation->track_find_key(E->key().track, newtime, true);
- if (idx == -1)
+ if (idx == -1) {
continue;
+ }
SelectedKey sk;
sk.key = idx;
sk.track = E->key().track;
- if (selection.has(sk))
+ if (selection.has(sk)) {
continue; //already in selection, don't save
+ }
undo_redo->add_do_method(animation.ptr(), "track_remove_key_at_position", E->key().track, newtime);
_AnimMoveRestore amr;
@@ -4891,10 +4988,12 @@ void AnimationTrackEditor::_anim_duplicate_keys(bool transpose) {
const SelectedKey &sk = E->key();
float t = animation->track_get_key_time(sk.track, sk.key);
- if (t < top_time)
+ if (t < top_time) {
top_time = t;
- if (sk.track < top_track)
+ }
+ if (sk.track < top_track) {
top_track = sk.track;
+ }
}
ERR_FAIL_COND(top_track == 0x7FFFFFFF || top_time == 1e10);
@@ -4914,11 +5013,13 @@ void AnimationTrackEditor::_anim_duplicate_keys(bool transpose) {
float dst_time = t + (timeline->get_play_position() - top_time);
int dst_track = sk.track + (start_track - top_track);
- if (dst_track < 0 || dst_track >= animation->get_track_count())
+ if (dst_track < 0 || dst_track >= animation->get_track_count()) {
continue;
+ }
- if (animation->track_get_type(dst_track) != animation->track_get_type(sk.track))
+ if (animation->track_get_type(dst_track) != animation->track_get_type(sk.track)) {
continue;
+ }
int existing_idx = animation->track_find_key(dst_track, dst_time, true);
@@ -4946,8 +5047,9 @@ void AnimationTrackEditor::_anim_duplicate_keys(bool transpose) {
int existing_idx = animation->track_find_key(track, time, true);
- if (existing_idx == -1)
+ if (existing_idx == -1) {
continue;
+ }
SelectedKey sk2;
sk2.track = track;
sk2.key = existing_idx;
@@ -5111,8 +5213,9 @@ void AnimationTrackEditor::_edit_menu_pressed(int p_option) {
scale_dialog->popup_centered(Size2(200, 100) * EDSCALE);
} break;
case EDIT_SCALE_CONFIRM: {
- if (selection.empty())
+ if (selection.empty()) {
return;
+ }
float from_t = 1e20;
float to_t = -1e20;
@@ -5121,10 +5224,12 @@ void AnimationTrackEditor::_edit_menu_pressed(int p_option) {
for (Map<SelectedKey, KeyInfo>::Element *E = selection.front(); E; E = E->next()) {
float t = animation->track_get_key_time(E->key().track, E->key().key);
- if (t < from_t)
+ if (t < from_t) {
from_t = t;
- if (t > to_t)
+ }
+ if (t > to_t) {
to_t = t;
+ }
}
len = to_t - from_t;
@@ -5152,13 +5257,15 @@ void AnimationTrackEditor::_edit_menu_pressed(int p_option) {
for (Map<SelectedKey, KeyInfo>::Element *E = selection.back(); E; E = E->prev()) {
float newtime = (E->get().pos - from_t) * s + from_t;
int idx = animation->track_find_key(E->key().track, newtime, true);
- if (idx == -1)
+ if (idx == -1) {
continue;
+ }
SelectedKey sk;
sk.key = idx;
sk.track = E->key().track;
- if (selection.has(sk))
+ if (selection.has(sk)) {
continue; //already in selection, don't save
+ }
undo_redo->add_do_method(animation.ptr(), "track_remove_key_at_position", E->key().track, newtime);
_AnimMoveRestore amr;
@@ -5202,8 +5309,9 @@ void AnimationTrackEditor::_edit_menu_pressed(int p_option) {
for (Map<SelectedKey, KeyInfo>::Element *E = selection.back(); E; E = E->prev()) {
float oldpos = E->get().pos;
float newpos = _NEW_POS(oldpos);
- if (newpos >= 0)
+ if (newpos >= 0) {
undo_redo->add_do_method(this, "_select_at_anim", animation, E->key().track, newpos);
+ }
undo_redo->add_undo_method(this, "_select_at_anim", animation, E->key().track, oldpos);
}
#undef _NEW_POS
@@ -5243,33 +5351,39 @@ void AnimationTrackEditor::_edit_menu_pressed(int p_option) {
}
} break;
case EDIT_GOTO_NEXT_STEP: {
- if (animation.is_null())
+ if (animation.is_null()) {
break;
+ }
float step = animation->get_step();
- if (step == 0)
+ if (step == 0) {
step = 1;
+ }
float pos = timeline->get_play_position();
pos = Math::stepify(pos + step, step);
- if (pos > animation->get_length())
+ if (pos > animation->get_length()) {
pos = animation->get_length();
+ }
set_anim_pos(pos);
emit_signal("timeline_changed", pos, true);
} break;
case EDIT_GOTO_PREV_STEP: {
- if (animation.is_null())
+ if (animation.is_null()) {
break;
+ }
float step = animation->get_step();
- if (step == 0)
+ if (step == 0) {
step = 1;
+ }
float pos = timeline->get_play_position();
pos = Math::stepify(pos - step, step);
- if (pos < 0)
+ if (pos < 0) {
pos = 0;
+ }
set_anim_pos(pos);
emit_signal("timeline_changed", pos, true);
@@ -5330,8 +5444,9 @@ void AnimationTrackEditor::_cleanup_animation(Ref<Animation> p_animation) {
continue;
}
- if (!prop_exists || p_animation->track_get_type(i) != Animation::TYPE_VALUE || !cleanup_keys->is_pressed())
+ if (!prop_exists || p_animation->track_get_type(i) != Animation::TYPE_VALUE || !cleanup_keys->is_pressed()) {
continue;
+ }
for (int j = 0; j < p_animation->track_get_key_count(i); j++) {
Variant v = p_animation->track_get_key_value(i, j);
@@ -5382,10 +5497,11 @@ void AnimationTrackEditor::_selection_changed() {
float AnimationTrackEditor::snap_time(float p_value, bool p_relative) {
if (is_snap_enabled()) {
double snap_increment;
- if (timeline->is_using_fps() && step->get_value() > 0)
+ if (timeline->is_using_fps() && step->get_value() > 0) {
snap_increment = 1.0 / step->get_value();
- else
+ } else {
snap_increment = step->get_value();
+ }
if (p_relative) {
double rel = Math::fmod(timeline->get_value(), snap_increment);
@@ -5406,13 +5522,15 @@ void AnimationTrackEditor::_show_imported_anim_warning() {
void AnimationTrackEditor::_select_all_tracks_for_copy() {
TreeItem *track = track_copy_select->get_root()->get_children();
- if (!track)
+ if (!track) {
return;
+ }
bool all_selected = true;
while (track) {
- if (!track->is_checked(0))
+ if (!track->is_checked(0)) {
all_selected = false;
+ }
track = track->get_next();
}
diff --git a/editor/animation_track_editor_plugins.cpp b/editor/animation_track_editor_plugins.cpp
index ed64fb2415..9fc67000f9 100644
--- a/editor/animation_track_editor_plugins.cpp
+++ b/editor/animation_track_editor_plugins.cpp
@@ -60,11 +60,13 @@ void AnimationTrackEditBool::draw_key(int p_index, float p_pixels_sec, int p_x,
Vector2 ofs(p_x - icon->get_width() / 2, int(get_size().height - icon->get_height()) / 2);
- if (ofs.x + icon->get_width() / 2 < p_clip_left)
+ if (ofs.x + icon->get_width() / 2 < p_clip_left) {
return;
+ }
- if (ofs.x + icon->get_width() / 2 > p_clip_right)
+ if (ofs.x + icon->get_width() / 2 > p_clip_right) {
return;
+ }
draw_texture(icon, ofs);
@@ -99,8 +101,9 @@ void AnimationTrackEditColor::draw_key_link(int p_index, float p_pixels_sec, int
int x_to = p_next_x - fh / 2 + 1;
fh /= 3;
- if (x_from > p_clip_right || x_to < p_clip_left)
+ if (x_from > p_clip_right || x_to < p_clip_left) {
return;
+ }
Color color = get_animation()->track_get_key_value(get_track(), p_index);
Color color_next = get_animation()->track_get_key_value(get_track(), p_index + 1);
@@ -162,8 +165,9 @@ void AnimationTrackEditColor::draw_key(int p_index, float p_pixels_sec, int p_x,
void AnimationTrackEditAudio::_preview_changed(ObjectID p_which) {
Object *object = ObjectDB::get_instance(id);
- if (!object)
+ if (!object) {
return;
+ }
Ref<AudioStream> stream = object->call("get_stream");
@@ -251,11 +255,13 @@ void AnimationTrackEditAudio::draw_key(int p_index, float p_pixels_sec, int p_x,
int pixel_begin = p_x;
int pixel_end = p_x + pixel_len;
- if (pixel_end < p_clip_left)
+ if (pixel_end < p_clip_left) {
return;
+ }
- if (pixel_begin > p_clip_right)
+ if (pixel_begin > p_clip_right) {
return;
+ }
int from_x = MAX(pixel_begin, p_clip_left);
int to_x = MIN(pixel_end, p_clip_right);
@@ -266,8 +272,9 @@ void AnimationTrackEditAudio::draw_key(int p_index, float p_pixels_sec, int p_x,
to_x = MIN(limit_x, to_x);
}
- if (to_x <= from_x)
+ if (to_x <= from_x) {
return;
+ }
Ref<Font> font = get_theme_font("font", "Label");
float fh = int(font->get_height() * 1.5);
@@ -495,11 +502,13 @@ void AnimationTrackEditSpriteFrame::draw_key(int p_index, float p_pixels_sec, in
Rect2 rect(p_x, int(get_size().height - height) / 2, width, height);
- if (rect.position.x + rect.size.x < p_clip_left)
+ if (rect.position.x + rect.size.x < p_clip_left) {
return;
+ }
- if (rect.position.x > p_clip_right)
+ if (rect.position.x > p_clip_right) {
return;
+ }
Color accent = get_theme_color("accent_color", "Editor");
Color bg = accent;
@@ -596,17 +605,20 @@ void AnimationTrackEditSubAnim::draw_key(int p_index, float p_pixels_sec, int p_
int pixel_begin = p_x;
int pixel_end = p_x + pixel_len;
- if (pixel_end < p_clip_left)
+ if (pixel_end < p_clip_left) {
return;
+ }
- if (pixel_begin > p_clip_right)
+ if (pixel_begin > p_clip_right) {
return;
+ }
int from_x = MAX(pixel_begin, p_clip_left);
int to_x = MIN(pixel_end, p_clip_right);
- if (to_x <= from_x)
+ if (to_x <= from_x) {
return;
+ }
Ref<Font> font = get_theme_font("font", "Label");
int fh = font->get_height() * 1.5;
@@ -634,8 +646,9 @@ void AnimationTrackEditSubAnim::draw_key(int p_index, float p_pixels_sec, int p_
float ofs = animation->track_get_key_time(i, j);
int x = p_x + ofs * p_pixels_sec + 2;
- if (x < from_x || x >= (to_x - 4))
+ if (x < from_x || x >= (to_x - 4)) {
continue;
+ }
lines.push_back(Point2(x, y));
lines.push_back(Point2(x + 1, y));
@@ -705,8 +718,9 @@ void AnimationTrackEditVolumeDB::draw_fg(int p_clip_left, int p_clip_right) {
}
void AnimationTrackEditVolumeDB::draw_key_link(int p_index, float p_pixels_sec, int p_x, int p_next_x, int p_clip_left, int p_clip_right) {
- if (p_x > p_clip_right || p_next_x < p_clip_left)
+ if (p_x > p_clip_right || p_next_x < p_clip_left) {
return;
+ }
float db = get_animation()->track_get_key_value(get_track(), p_index);
float db_n = get_animation()->track_get_key_value(get_track(), p_index + 1);
@@ -809,12 +823,14 @@ void AnimationTrackEditTypeAudio::draw_key(int p_index, float p_pixels_sec, int
float ofs_local = -len_resizing_rel / get_timeline()->get_zoom_scale();
if (len_resizing_start) {
start_ofs += ofs_local;
- if (start_ofs < 0)
+ if (start_ofs < 0) {
start_ofs = 0;
+ }
} else {
end_ofs += ofs_local;
- if (end_ofs < 0)
+ if (end_ofs < 0) {
end_ofs = 0;
+ }
}
}
@@ -845,11 +861,13 @@ void AnimationTrackEditTypeAudio::draw_key(int p_index, float p_pixels_sec, int
int pixel_begin = p_x;
int pixel_end = p_x + pixel_len;
- if (pixel_end < p_clip_left)
+ if (pixel_end < p_clip_left) {
return;
+ }
- if (pixel_begin > p_clip_right)
+ if (pixel_begin > p_clip_right) {
return;
+ }
int from_x = MAX(pixel_begin, p_clip_left);
int to_x = MIN(pixel_end, p_clip_right);
@@ -1152,17 +1170,20 @@ void AnimationTrackEditTypeAnimation::draw_key(int p_index, float p_pixels_sec,
int pixel_begin = p_x;
int pixel_end = p_x + pixel_len;
- if (pixel_end < p_clip_left)
+ if (pixel_end < p_clip_left) {
return;
+ }
- if (pixel_begin > p_clip_right)
+ if (pixel_begin > p_clip_right) {
return;
+ }
int from_x = MAX(pixel_begin, p_clip_left);
int to_x = MIN(pixel_end, p_clip_right);
- if (to_x <= from_x)
+ if (to_x <= from_x) {
return;
+ }
Ref<Font> font = get_theme_font("font", "Label");
int fh = font->get_height() * 1.5;
@@ -1190,8 +1211,9 @@ void AnimationTrackEditTypeAnimation::draw_key(int p_index, float p_pixels_sec,
float ofs = animation->track_get_key_time(i, j);
int x = p_x + ofs * p_pixels_sec + 2;
- if (x < from_x || x >= (to_x - 4))
+ if (x < from_x || x >= (to_x - 4)) {
continue;
+ }
lines.push_back(Point2(x, y));
lines.push_back(Point2(x + 1, y));
diff --git a/editor/array_property_edit.cpp b/editor/array_property_edit.cpp
index 3832a93360..20f947e707 100644
--- a/editor/array_property_edit.cpp
+++ b/editor/array_property_edit.cpp
@@ -37,8 +37,9 @@
Variant ArrayPropertyEdit::get_array() const {
Object *o = ObjectDB::get_instance(obj);
- if (!o)
+ if (!o) {
return Array();
+ }
Variant arr = o->get(property);
if (!arr.is_array()) {
Callable::CallError ce;
@@ -59,8 +60,9 @@ void ArrayPropertyEdit::_set_size(int p_size) {
Variant arr = get_array();
arr.call("resize", p_size);
Object *o = ObjectDB::get_instance(obj);
- if (!o)
+ if (!o) {
return;
+ }
o->set(property, arr);
}
@@ -69,8 +71,9 @@ void ArrayPropertyEdit::_set_value(int p_idx, const Variant &p_value) {
Variant arr = get_array();
arr.set(p_idx, p_value);
Object *o = ObjectDB::get_instance(obj);
- if (!o)
+ if (!o) {
return;
+ }
o->set(property, arr);
}
@@ -84,8 +87,9 @@ bool ArrayPropertyEdit::_set(const StringName &p_name, const Variant &p_value) {
int size = arr.call("size");
int newsize = p_value;
- if (newsize == size)
+ if (newsize == size) {
return true;
+ }
UndoRedo *ur = EditorNode::get_undo_redo();
ur->create_action(TTR("Resize Array"));
@@ -184,8 +188,9 @@ bool ArrayPropertyEdit::_get(const StringName &p_name, Variant &r_ret) const {
int idx = pn.get_slicec('/', 1).get_slicec('_', 0).to_int();
bool valid;
r_ret = arr.get(idx, &valid);
- if (valid)
+ if (valid) {
r_ret = r_ret.get_type();
+ }
return valid;
} else {
@@ -210,8 +215,9 @@ void ArrayPropertyEdit::_get_property_list(List<PropertyInfo> *p_list) const {
p_list->push_back(PropertyInfo(Variant::INT, "array/size", PROPERTY_HINT_RANGE, "0,100000,1"));
int pages = size / ITEMS_PER_PAGE;
- if (pages > 0)
+ if (pages > 0) {
p_list->push_back(PropertyInfo(Variant::INT, "array/page", PROPERTY_HINT_RANGE, "0," + itos(pages) + ",1"));
+ }
int offset = page * ITEMS_PER_PAGE;
@@ -288,8 +294,9 @@ void ArrayPropertyEdit::_bind_methods() {
ArrayPropertyEdit::ArrayPropertyEdit() {
page = 0;
for (int i = 0; i < Variant::VARIANT_MAX; i++) {
- if (i > 0)
+ if (i > 0) {
vtypes += ",";
+ }
vtypes += Variant::get_type_name(Variant::Type(i));
}
default_type = Variant::NIL;
diff --git a/editor/audio_stream_preview.cpp b/editor/audio_stream_preview.cpp
index e0d5184aac..9e4e157c96 100644
--- a/editor/audio_stream_preview.cpp
+++ b/editor/audio_stream_preview.cpp
@@ -37,8 +37,9 @@ float AudioStreamPreview::get_length() const {
}
float AudioStreamPreview::get_max(float p_time, float p_time_next) const {
- if (length == 0)
+ if (length == 0) {
return 0;
+ }
int max = preview.size() / 2;
int time_from = p_time / length * max;
@@ -63,8 +64,9 @@ float AudioStreamPreview::get_max(float p_time, float p_time_next) const {
}
float AudioStreamPreview::get_min(float p_time, float p_time_next) const {
- if (length == 0)
+ if (length == 0) {
return 0;
+ }
int max = preview.size() / 2;
int time_from = p_time / length * max;
@@ -194,8 +196,9 @@ Ref<AudioStreamPreview> AudioStreamPreviewGenerator::generate_preview(const Ref<
preview->preview->preview = maxmin;
preview->preview->length = len_s;
- if (preview->playback.is_valid())
+ if (preview->playback.is_valid()) {
preview->thread = Thread::create(_preview_thread, preview);
+ }
return preview->preview;
}
diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp
index 381e3f8dfb..3ea970a0f0 100644
--- a/editor/code_editor.cpp
+++ b/editor/code_editor.cpp
@@ -54,8 +54,9 @@ int GotoLineDialog::get_line() const {
}
void GotoLineDialog::ok_pressed() {
- if (get_line() < 1 || get_line() > text_editor->get_line_count())
+ if (get_line() < 1 || get_line() > text_editor->get_line_count()) {
return;
+ }
text_editor->unfold_line(get_line() - 1);
text_editor->cursor_set_line(get_line() - 1);
hide();
@@ -285,14 +286,16 @@ void FindReplaceBar::_get_search_from(int &r_line, int &r_col) {
}
void FindReplaceBar::_update_results_count() {
- if (results_count != -1)
+ if (results_count != -1) {
return;
+ }
results_count = 0;
String searched = get_search_text();
- if (searched.empty())
+ if (searched.empty()) {
return;
+ }
String full_text = text_edit->get_text();
@@ -300,15 +303,18 @@ void FindReplaceBar::_update_results_count() {
while (true) {
int pos = is_case_sensitive() ? full_text.find(searched, from_pos) : full_text.findn(searched, from_pos);
- if (pos == -1)
+ if (pos == -1) {
break;
+ }
if (is_whole_words()) {
from_pos++; // Making sure we won't hit the same match next time, if we get out via a continue.
- if (pos > 0 && !is_symbol(full_text[pos - 1]))
+ if (pos > 0 && !is_symbol(full_text[pos - 1])) {
continue;
- if (pos + searched.length() < full_text.length() && !is_symbol(full_text[pos + searched.length()]))
+ }
+ if (pos + searched.length() < full_text.length() && !is_symbol(full_text[pos + searched.length()])) {
continue;
+ }
}
results_count++;
@@ -330,10 +336,12 @@ void FindReplaceBar::_update_matches_label() {
bool FindReplaceBar::search_current() {
uint32_t flags = 0;
- if (is_whole_words())
+ if (is_whole_words()) {
flags |= TextEdit::SEARCH_WHOLE_WORDS;
- if (is_case_sensitive())
+ }
+ if (is_case_sensitive()) {
flags |= TextEdit::SEARCH_MATCH_CASE;
+ }
int line, col;
_get_search_from(line, col);
@@ -342,29 +350,34 @@ bool FindReplaceBar::search_current() {
}
bool FindReplaceBar::search_prev() {
- if (!is_visible())
+ if (!is_visible()) {
popup_search(true);
+ }
uint32_t flags = 0;
String text = get_search_text();
- if (is_whole_words())
+ if (is_whole_words()) {
flags |= TextEdit::SEARCH_WHOLE_WORDS;
- if (is_case_sensitive())
+ }
+ if (is_case_sensitive()) {
flags |= TextEdit::SEARCH_MATCH_CASE;
+ }
flags |= TextEdit::SEARCH_BACKWARDS;
int line, col;
_get_search_from(line, col);
- if (text_edit->is_selection_active())
+ if (text_edit->is_selection_active()) {
col--; // Skip currently selected word.
+ }
col -= text.length();
if (col < 0) {
line -= 1;
- if (line < 0)
+ if (line < 0) {
line = text_edit->get_line_count() - 1;
+ }
col = text_edit->get_line(line).length();
}
@@ -372,20 +385,24 @@ bool FindReplaceBar::search_prev() {
}
bool FindReplaceBar::search_next() {
- if (!is_visible())
+ if (!is_visible()) {
popup_search(true);
+ }
uint32_t flags = 0;
String text;
- if (replace_all_mode)
+ if (replace_all_mode) {
text = get_replace_text();
- else
+ } else {
text = get_search_text();
+ }
- if (is_whole_words())
+ if (is_whole_words()) {
flags |= TextEdit::SEARCH_WHOLE_WORDS;
- if (is_case_sensitive())
+ }
+ if (is_case_sensitive()) {
flags |= TextEdit::SEARCH_MATCH_CASE;
+ }
int line, col;
_get_search_from(line, col);
@@ -394,8 +411,9 @@ bool FindReplaceBar::search_next() {
col += text.length();
if (col > text_edit->get_line(line).length()) {
line += 1;
- if (line >= text_edit->get_line_count())
+ if (line >= text_edit->get_line_count()) {
line = 0;
+ }
col = 0;
}
}
@@ -404,8 +422,9 @@ bool FindReplaceBar::search_next() {
}
void FindReplaceBar::_hide_bar() {
- if (replace_text->has_focus() || search_text->has_focus())
+ if (replace_text->has_focus() || search_text->has_focus()) {
text_edit->grab_focus();
+ }
text_edit->set_search_text("");
result_line = -1;
@@ -415,8 +434,9 @@ void FindReplaceBar::_hide_bar() {
void FindReplaceBar::_show_search(bool p_focus_replace, bool p_show_only) {
show();
- if (p_show_only)
+ if (p_show_only) {
return;
+ }
if (p_focus_replace) {
search_text->deselect();
@@ -637,8 +657,9 @@ FindReplaceBar::FindReplaceBar() {
// be handled too late if they weren't handled here.
void CodeTextEditor::_input(const Ref<InputEvent> &event) {
const Ref<InputEventKey> key_event = event;
- if (!key_event.is_valid() || !key_event->is_pressed())
+ if (!key_event.is_valid() || !key_event->is_pressed()) {
return;
+ }
if (ED_IS_SHORTCUT("script_text_editor/move_up", key_event)) {
move_lines_up();
@@ -719,8 +740,9 @@ void CodeTextEditor::_zoom_out() {
}
void CodeTextEditor::_zoom_changed() {
- if (font_resize_timer->get_time_left() == 0)
+ if (font_resize_timer->get_time_left() == 0) {
font_resize_timer->start();
+ }
}
void CodeTextEditor::_reset_zoom() {
@@ -763,8 +785,9 @@ void CodeTextEditor::_text_changed() {
}
void CodeTextEditor::_code_complete_timer_timeout() {
- if (!is_visible_in_tree())
+ if (!is_visible_in_tree()) {
return;
+ }
text_editor->query_code_comple();
}
@@ -776,8 +799,9 @@ void CodeTextEditor::_complete_request() {
if (code_complete_func) {
code_complete_func(code_complete_ud, ctext, &entries, forced);
}
- if (entries.size() == 0)
+ if (entries.size() == 0) {
return;
+ }
for (List<ScriptCodeCompletionOption>::Element *E = entries.front(); E; E = E->next()) {
E->get().icon = _get_completion_icon(E->get());
@@ -1035,10 +1059,12 @@ void CodeTextEditor::convert_case(CaseStyle p_case) {
for (int i = begin; i <= end; i++) {
int len = text_editor->get_line(i).length();
- if (i == end)
+ if (i == end) {
len = end_col;
- if (i == begin)
+ }
+ if (i == begin) {
len -= begin_col;
+ }
String new_line = text_editor->get_line(i).substr(i == begin ? begin_col : 0, len);
switch (p_case) {
@@ -1076,8 +1102,9 @@ void CodeTextEditor::move_lines_up() {
int line_id = i;
int next_id = i - 1;
- if (line_id == 0 || next_id < 0)
+ if (line_id == 0 || next_id < 0) {
return;
+ }
text_editor->unfold_line(line_id);
text_editor->unfold_line(next_id);
@@ -1092,8 +1119,9 @@ void CodeTextEditor::move_lines_up() {
int line_id = text_editor->cursor_get_line();
int next_id = line_id - 1;
- if (line_id == 0 || next_id < 0)
+ if (line_id == 0 || next_id < 0) {
return;
+ }
text_editor->unfold_line(line_id);
text_editor->unfold_line(next_id);
@@ -1117,8 +1145,9 @@ void CodeTextEditor::move_lines_down() {
int line_id = i;
int next_id = i + 1;
- if (line_id == text_editor->get_line_count() - 1 || next_id > text_editor->get_line_count())
+ if (line_id == text_editor->get_line_count() - 1 || next_id > text_editor->get_line_count()) {
return;
+ }
text_editor->unfold_line(line_id);
text_editor->unfold_line(next_id);
@@ -1133,8 +1162,9 @@ void CodeTextEditor::move_lines_down() {
int line_id = text_editor->cursor_get_line();
int next_id = line_id + 1;
- if (line_id == text_editor->get_line_count() - 1 || next_id > text_editor->get_line_count())
+ if (line_id == text_editor->get_line_count() - 1 || next_id > text_editor->get_line_count()) {
return;
+ }
text_editor->unfold_line(line_id);
text_editor->unfold_line(next_id);
@@ -1228,8 +1258,9 @@ void CodeTextEditor::toggle_inline_comment(const String &delimiter) {
int end = text_editor->get_selection_to_line();
// End of selection ends on the first column of the last line, ignore it.
- if (text_editor->get_selection_to_column() == 0)
+ if (text_editor->get_selection_to_column() == 0) {
end -= 1;
+ }
int col_to = text_editor->get_selection_to_column();
int cursor_pos = text_editor->cursor_get_column();
@@ -1261,14 +1292,17 @@ void CodeTextEditor::toggle_inline_comment(const String &delimiter) {
int offset = (is_commented ? -1 : 1) * delimiter.length();
int col_from = text_editor->get_selection_from_column() > 0 ? text_editor->get_selection_from_column() + offset : 0;
- if (is_commented && text_editor->cursor_get_column() == text_editor->get_line(text_editor->cursor_get_line()).length() + 1)
+ if (is_commented && text_editor->cursor_get_column() == text_editor->get_line(text_editor->cursor_get_line()).length() + 1) {
cursor_pos += 1;
+ }
- if (text_editor->get_selection_to_column() != 0 && col_to != text_editor->get_line(text_editor->get_selection_to_line()).length() + 1)
+ if (text_editor->get_selection_to_column() != 0 && col_to != text_editor->get_line(text_editor->get_selection_to_line()).length() + 1) {
col_to += offset;
+ }
- if (text_editor->cursor_get_column() != 0)
+ if (text_editor->cursor_get_column() != 0) {
cursor_pos += offset;
+ }
text_editor->select(begin, col_from, text_editor->get_selection_to_line(), col_to);
text_editor->cursor_set_column(cursor_pos);
@@ -1419,8 +1453,9 @@ void CodeTextEditor::_update_font() {
int count = status_bar->get_child_count();
for (int i = 0; i < count; i++) {
Control *n = Object::cast_to<Control>(status_bar->get_child(i));
- if (n)
+ if (n) {
n->add_theme_font_override("font", status_bar_font);
+ }
}
}
@@ -1511,8 +1546,9 @@ void CodeTextEditor::set_warning_nb(int p_warning_nb) {
warning_count_label->set_text(itos(p_warning_nb));
warning_count_label->set_visible(p_warning_nb > 0);
warning_button->set_visible(p_warning_nb > 0);
- if (!p_warning_nb)
+ if (!p_warning_nb) {
_set_show_warnings_panel(false);
+ }
}
void CodeTextEditor::toggle_bookmark() {
diff --git a/editor/connections_dialog.cpp b/editor/connections_dialog.cpp
index 2e47be32ca..62b5911ac1 100644
--- a/editor/connections_dialog.cpp
+++ b/editor/connections_dialog.cpp
@@ -69,8 +69,9 @@ public:
int which = name.get_slice("/", 1).to_int() - 1;
ERR_FAIL_INDEX_V(which, params.size(), false);
params.write[which] = p_value;
- } else
+ } else {
return false;
+ }
return true;
}
@@ -82,8 +83,9 @@ public:
int which = name.get_slice("/", 1).to_int() - 1;
ERR_FAIL_INDEX_V(which, params.size(), false);
r_ret = params[which];
- } else
+ } else {
return false;
+ }
return true;
}
@@ -144,8 +146,9 @@ void ConnectDialog::_text_entered(const String &p_text) {
void ConnectDialog::_tree_node_selected() {
Node *current = tree->get_selected();
- if (!current)
+ if (!current) {
return;
+ }
dst_path = source->get_path_to(current);
_update_ok_enabled();
@@ -155,8 +158,9 @@ void ConnectDialog::_tree_node_selected() {
* Adds a new parameter bind to connection.
*/
void ConnectDialog::_add_bind() {
- if (cdbinds->params.size() >= VARIANT_ARG_MAX)
+ if (cdbinds->params.size() >= VARIANT_ARG_MAX) {
return;
+ }
Variant::Type vt = (Variant::Type)type_list->get_item_id(type_list->get_selected());
Variant value;
@@ -220,8 +224,9 @@ void ConnectDialog::_add_bind() {
*/
void ConnectDialog::_remove_bind() {
String st = bind_editor->get_selected_path();
- if (st == "")
+ if (st == "") {
return;
+ }
int idx = st.get_slice("/", 1).to_int() - 1;
ERR_FAIL_INDEX(idx, cdbinds->params.size());
@@ -280,8 +285,9 @@ void ConnectDialog::set_dst_node(Node *p_node) {
StringName ConnectDialog::get_dst_method_name() const {
String txt = dst_method->get_text();
- if (txt.find("(") != -1)
+ if (txt.find("(") != -1) {
txt = txt.left(txt.find("(")).strip_edges();
+ }
return txt;
}
@@ -345,8 +351,9 @@ void ConnectDialog::init(ConnectionData c, bool bEdit) {
void ConnectDialog::popup_dialog(const String &p_for_signal) {
from_signal->set_text(p_for_signal);
error_label->add_theme_color_override("font_color", error_label->get_theme_color("error_color", "Editor"));
- if (!advanced->is_pressed())
+ if (!advanced->is_pressed()) {
error_label->set_visible(!_find_first_script(get_tree()->get_edited_scene_root(), get_tree()->get_edited_scene_root()));
+ }
popup_centered();
}
@@ -588,8 +595,9 @@ void ConnectionsDock::_connect(ConnectDialog::ConnectionData cToMake) {
Node *source = static_cast<Node *>(cToMake.source);
Node *target = static_cast<Node *>(cToMake.target);
- if (!source || !target)
+ if (!source || !target) {
return;
+ }
undo_redo->create_action(vformat(TTR("Connect '%s' to '%s'"), String(cToMake.signal), String(cToMake.method)));
@@ -633,8 +641,9 @@ void ConnectionsDock::_disconnect(TreeItem &item) {
void ConnectionsDock::_disconnect_all() {
TreeItem *item = tree->get_selected();
- if (!_is_item_signal(*item))
+ if (!_is_item_signal(*item)) {
return;
+ }
TreeItem *child = item->get_children();
String signalName = item->get_metadata(0).operator Dictionary()["name"];
@@ -674,8 +683,9 @@ void ConnectionsDock::_tree_item_activated() { // "Activation" on double-click.
TreeItem *item = tree->get_selected();
- if (!item)
+ if (!item) {
return;
+ }
if (_is_item_signal(*item)) {
_open_connection_dialog(*item);
@@ -746,20 +756,23 @@ void ConnectionsDock::_open_connection_dialog(ConnectDialog::ConnectionData cToE
* Open slot method location in script editor.
*/
void ConnectionsDock::_go_to_script(TreeItem &item) {
- if (_is_item_signal(item))
+ if (_is_item_signal(item)) {
return;
+ }
Connection cd = item.get_metadata(0);
ConnectDialog::ConnectionData c = cd;
ERR_FAIL_COND(c.source != selectedNode); //shouldn't happen but...bugcheck
- if (!c.target)
+ if (!c.target) {
return;
+ }
Ref<Script> script = c.target->get_script();
- if (script.is_null())
+ if (script.is_null()) {
return;
+ }
if (script.is_valid() && ScriptEditor::get_singleton()->script_goto_method(script, c.method)) {
editor->call("_editor_select", EditorNode::EDITOR_SCRIPT);
@@ -769,8 +782,9 @@ void ConnectionsDock::_go_to_script(TreeItem &item) {
void ConnectionsDock::_handle_signal_menu_option(int option) {
TreeItem *item = tree->get_selected();
- if (!item)
+ if (!item) {
return;
+ }
switch (option) {
case CONNECT: {
@@ -787,8 +801,9 @@ void ConnectionsDock::_handle_signal_menu_option(int option) {
void ConnectionsDock::_handle_slot_menu_option(int option) {
TreeItem *item = tree->get_selected();
- if (!item)
+ if (!item) {
return;
+ }
switch (option) {
case EDIT: {
@@ -808,8 +823,9 @@ void ConnectionsDock::_handle_slot_menu_option(int option) {
void ConnectionsDock::_rmb_pressed(Vector2 position) {
TreeItem *item = tree->get_selected();
- if (!item)
+ if (!item) {
return;
+ }
Vector2 global_position = tree->get_global_position() + position;
@@ -859,8 +875,9 @@ void ConnectionsDock::set_node(Node *p_node) {
void ConnectionsDock::update_tree() {
tree->clear();
- if (!selectedNode)
+ if (!selectedNode) {
return;
+ }
TreeItem *root = tree->create_item();
@@ -880,10 +897,11 @@ void ConnectionsDock::update_tree() {
Ref<Script> scr = selectedNode->get_script();
if (scr.is_valid()) {
scr->get_script_signal_list(&node_signals2);
- if (scr->get_path().is_resource_file())
+ if (scr->get_path().is_resource_file()) {
name = scr->get_path().get_file();
- else
+ } else {
name = scr->get_class();
+ }
if (has_theme_icon(scr->get_class(), "EditorIcons")) {
icon = get_theme_icon(scr->get_class(), "EditorIcons");
@@ -923,8 +941,9 @@ void ConnectionsDock::update_tree() {
for (int i = 0; i < mi.arguments.size(); i++) {
PropertyInfo &pi = mi.arguments[i];
- if (i > 0)
+ if (i > 0) {
signaldesc += ", ";
+ }
String tname = "var";
if (pi.type == Variant::OBJECT && pi.class_name != StringName()) {
tname = pi.class_name.operator String();
@@ -988,24 +1007,29 @@ void ConnectionsDock::update_tree() {
for (List<Object::Connection>::Element *F = connections.front(); F; F = F->next()) {
Connection cn = F->get();
- if (!(cn.flags & CONNECT_PERSIST))
+ if (!(cn.flags & CONNECT_PERSIST)) {
continue;
+ }
ConnectDialog::ConnectionData c = cn;
Node *target = Object::cast_to<Node>(c.target);
- if (!target)
+ if (!target) {
continue;
+ }
String path = String(selectedNode->get_path_to(target)) + " :: " + c.method + "()";
- if (c.flags & CONNECT_DEFERRED)
+ if (c.flags & CONNECT_DEFERRED) {
path += " (deferred)";
- if (c.flags & CONNECT_ONESHOT)
+ }
+ if (c.flags & CONNECT_ONESHOT) {
path += " (oneshot)";
+ }
if (c.binds.size()) {
path += " binds(";
for (int i = 0; i < c.binds.size(); i++) {
- if (i > 0)
+ if (i > 0) {
path += ", ";
+ }
path += c.binds[i].operator String();
}
path += ")";
diff --git a/editor/create_dialog.cpp b/editor/create_dialog.cpp
index 5f693fdbb6..75fff03297 100644
--- a/editor/create_dialog.cpp
+++ b/editor/create_dialog.cpp
@@ -132,30 +132,35 @@ void CreateDialog::_sbox_input(const Ref<InputEvent> &p_ie) {
}
void CreateDialog::add_type(const String &p_type, HashMap<String, TreeItem *> &p_types, TreeItem *p_root, TreeItem **to_select) {
- if (p_types.has(p_type))
+ if (p_types.has(p_type)) {
return;
+ }
bool cpp_type = ClassDB::class_exists(p_type);
EditorData &ed = EditorNode::get_editor_data();
- if (p_type == base_type)
+ if (p_type == base_type) {
return;
+ }
if (cpp_type) {
- if (!ClassDB::is_parent_class(p_type, base_type))
+ if (!ClassDB::is_parent_class(p_type, base_type)) {
return;
+ }
} else {
if (!search_loaded_scripts.has(p_type)) {
search_loaded_scripts[p_type] = ed.script_class_load_script(p_type);
}
- if (!ScriptServer::is_global_class(p_type) || !ed.script_class_is_parent(p_type, base_type))
+ if (!ScriptServer::is_global_class(p_type) || !ed.script_class_is_parent(p_type, base_type)) {
return;
+ }
String script_path = ScriptServer::get_global_class_path(p_type);
if (script_path.find("res://addons/", 0) != -1) {
- if (!EditorNode::get_singleton()->is_addon_plugin_enabled(script_path.get_slicec('/', 3)))
+ if (!EditorNode::get_singleton()->is_addon_plugin_enabled(script_path.get_slicec('/', 3))) {
return;
+ }
}
}
@@ -168,10 +173,11 @@ void CreateDialog::add_type(const String &p_type, HashMap<String, TreeItem *> &p
add_type(inherits, p_types, p_root, to_select);
}
- if (p_types.has(inherits))
+ if (p_types.has(inherits)) {
parent = p_types[inherits];
- else if (ScriptServer::is_global_class(inherits))
+ } else if (ScriptServer::is_global_class(inherits)) {
return;
+ }
}
bool can_instance = (cpp_type && ClassDB::can_instance(p_type)) || ScriptServer::is_global_class(p_type);
@@ -313,21 +319,25 @@ void CreateDialog::_update_search() {
}
bool cpp_type = ClassDB::class_exists(type);
- if (base_type == "Node" && type.begins_with("Editor"))
+ if (base_type == "Node" && type.begins_with("Editor")) {
continue; // do not show editor nodes
+ }
- if (cpp_type && !ClassDB::can_instance(type))
+ if (cpp_type && !ClassDB::can_instance(type)) {
continue; // can't create what can't be instanced
+ }
if (cpp_type) {
bool skip = false;
for (Set<StringName>::Element *E = type_blacklist.front(); E && !skip; E = E->next()) {
- if (ClassDB::is_parent_class(type, E->get()))
+ if (ClassDB::is_parent_class(type, E->get())) {
skip = true;
+ }
}
- if (skip)
+ if (skip) {
continue;
+ }
}
if (search_box->get_text() == "") {
@@ -365,17 +375,20 @@ void CreateDialog::_update_search() {
for (int i = 0; i < ct.size(); i++) {
bool show = search_box->get_text().is_subsequence_ofi(ct[i].name);
- if (!show)
+ if (!show) {
continue;
+ }
- if (!search_options_types.has(type))
+ if (!search_options_types.has(type)) {
add_type(type, search_options_types, root, &to_select);
+ }
TreeItem *ti;
- if (search_options_types.has(type))
+ if (search_options_types.has(type)) {
ti = search_options_types[type];
- else
+ } else {
ti = search_options->get_root();
+ }
TreeItem *item = search_options->create_item(ti);
item->set_metadata(0, type);
@@ -407,16 +420,18 @@ void CreateDialog::_update_search() {
void CreateDialog::_confirmed() {
TreeItem *ti = search_options->get_selected();
- if (!ti)
+ if (!ti) {
return;
+ }
FileAccess *f = FileAccess::open(EditorSettings::get_singleton()->get_project_settings_dir().plus_file("create_recent." + base_type), FileAccess::WRITE);
if (f) {
f->store_line(get_selected_type());
TreeItem *t = recent->get_root();
- if (t)
+ if (t) {
t = t->get_children();
+ }
int count = 0;
while (t) {
if (t->get_text(0) != get_selected_type()) {
@@ -463,10 +478,11 @@ void CreateDialog::_notification(int p_what) {
void CreateDialog::set_base_type(const String &p_base) {
base_type = p_base;
- if (is_replace_mode)
+ if (is_replace_mode) {
set_title(vformat(TTR("Change %s Type"), p_base));
- else
+ } else {
set_title(vformat(TTR("Create New %s"), p_base));
+ }
_update_search();
}
@@ -485,10 +501,11 @@ String CreateDialog::get_preferred_search_result_type() {
String CreateDialog::get_selected_type() {
TreeItem *selected = search_options->get_selected();
- if (selected)
+ if (selected) {
return selected->get_text(0);
- else
+ } else {
return String();
+ }
}
Object *CreateDialog::instance_selected() {
@@ -498,15 +515,17 @@ Object *CreateDialog::instance_selected() {
Variant md = selected->get_metadata(0);
String custom;
- if (md.get_type() != Variant::NIL)
+ if (md.get_type() != Variant::NIL) {
custom = md;
+ }
if (custom != String()) {
if (ScriptServer::is_global_class(custom)) {
Object *obj = EditorNode::get_editor_data().script_class_instance(custom);
Node *n = Object::cast_to<Node>(obj);
- if (n)
+ if (n) {
n->set_name(custom);
+ }
return obj;
}
return EditorNode::get_editor_data().instance_custom_type(selected->get_text(0), custom);
@@ -520,16 +539,18 @@ Object *CreateDialog::instance_selected() {
void CreateDialog::_item_selected() {
TreeItem *item = search_options->get_selected();
- if (!item)
+ if (!item) {
return;
+ }
String name = item->get_text(0);
favorite->set_disabled(false);
favorite->set_pressed(favorite_list.find(name) != -1);
- if (!EditorHelp::get_doc_data()->class_list.has(name))
+ if (!EditorHelp::get_doc_data()->class_list.has(name)) {
return;
+ }
help_bit->set_text(DTR(EditorHelp::get_doc_data()->class_list[name].brief_description));
@@ -542,8 +563,9 @@ void CreateDialog::_hide_requested() {
void CreateDialog::_favorite_toggled() {
TreeItem *item = search_options->get_selected();
- if (!item)
+ if (!item) {
return;
+ }
String name = item->get_text(0);
@@ -565,8 +587,9 @@ void CreateDialog::_save_favorite_list() {
for (int i = 0; i < favorite_list.size(); i++) {
String l = favorite_list[i];
String name = l.split(" ")[0];
- if (!(ClassDB::class_exists(name) || ScriptServer::is_global_class(name)))
+ if (!(ClassDB::class_exists(name) || ScriptServer::is_global_class(name))) {
continue;
+ }
f->store_line(l);
}
memdelete(f);
@@ -579,8 +602,9 @@ void CreateDialog::_update_favorite_list() {
for (int i = 0; i < favorite_list.size(); i++) {
String l = favorite_list[i];
String name = l.split(" ")[0];
- if (!((ClassDB::class_exists(name) || ScriptServer::is_global_class(name)) && !_is_class_disabled_by_feature_profile(name)))
+ if (!((ClassDB::class_exists(name) || ScriptServer::is_global_class(name)) && !_is_class_disabled_by_feature_profile(name))) {
continue;
+ }
TreeItem *ti = favorites->create_item(root);
ti->set_text(0, l);
ti->set_icon(0, EditorNode::get_singleton()->get_class_icon(l, base_type));
@@ -590,8 +614,9 @@ void CreateDialog::_update_favorite_list() {
void CreateDialog::_history_selected() {
TreeItem *item = recent->get_selected();
- if (!item)
+ if (!item) {
return;
+ }
search_box->set_text(item->get_text(0).get_slicec(' ', 0));
favorites->deselect_all();
@@ -600,8 +625,9 @@ void CreateDialog::_history_selected() {
void CreateDialog::_favorite_selected() {
TreeItem *item = favorites->get_selected();
- if (!item)
+ if (!item) {
return;
+ }
search_box->set_text(item->get_text(0).get_slicec(' ', 0));
recent->deselect_all();
@@ -650,21 +676,24 @@ void CreateDialog::drop_data_fw(const Point2 &p_point, const Variant &p_data, Co
Dictionary d = p_data;
TreeItem *ti = favorites->get_item_at_position(p_point);
- if (!ti)
+ if (!ti) {
return;
+ }
String drop_at = ti->get_text(0);
int ds = favorites->get_drop_section_at_position(p_point);
int drop_idx = favorite_list.find(drop_at);
- if (drop_idx < 0)
+ if (drop_idx < 0) {
return;
+ }
String type = d["class"];
int from_idx = favorite_list.find(type);
- if (from_idx < 0)
+ if (from_idx < 0) {
return;
+ }
if (drop_idx == from_idx) {
ds = -1; //cause it will be gone
diff --git a/editor/debugger/editor_debugger_inspector.cpp b/editor/debugger/editor_debugger_inspector.cpp
index 0c5fce91a6..125439d09b 100644
--- a/editor/debugger/editor_debugger_inspector.cpp
+++ b/editor/debugger/editor_debugger_inspector.cpp
@@ -36,8 +36,9 @@
#include "scene/debugger/scene_debugger.h"
bool EditorDebuggerRemoteObject::_set(const StringName &p_name, const Variant &p_value) {
- if (!editable || !prop_values.has(p_name) || String(p_name).begins_with("Constants/"))
+ if (!editable || !prop_values.has(p_name) || String(p_name).begins_with("Constants/")) {
return false;
+ }
prop_values[p_name] = p_value;
emit_signal("value_edited", remote_object_id, p_name, p_value);
@@ -45,8 +46,9 @@ bool EditorDebuggerRemoteObject::_set(const StringName &p_name, const Variant &p
}
bool EditorDebuggerRemoteObject::_get(const StringName &p_name, Variant &r_ret) const {
- if (!prop_values.has(p_name))
+ if (!prop_values.has(p_name)) {
return false;
+ }
r_ret = prop_values[p_name];
return true;
@@ -60,10 +62,11 @@ void EditorDebuggerRemoteObject::_get_property_list(List<PropertyInfo> *p_list)
}
String EditorDebuggerRemoteObject::get_title() {
- if (remote_object_id.is_valid())
+ if (remote_object_id.is_valid()) {
return TTR("Remote ") + String(type_name) + ": " + itos(remote_object_id);
- else
+ } else {
return "<null>";
+ }
}
Variant EditorDebuggerRemoteObject::get_variant(const StringName &p_name) {
@@ -211,8 +214,9 @@ void EditorDebuggerInspector::clear_cache() {
}
Object *EditorDebuggerInspector::get_object(ObjectID p_id) {
- if (remote_objects.has(p_id))
+ if (remote_objects.has(p_id)) {
return remote_objects[p_id];
+ }
return nullptr;
}
diff --git a/editor/debugger/editor_debugger_node.cpp b/editor/debugger/editor_debugger_node.cpp
index 76d1701372..a9c18138d8 100644
--- a/editor/debugger/editor_debugger_node.cpp
+++ b/editor/debugger/editor_debugger_node.cpp
@@ -50,8 +50,9 @@ void _for_all(TabContainer *p_node, const Func &p_func) {
EditorDebuggerNode *EditorDebuggerNode::singleton = nullptr;
EditorDebuggerNode::EditorDebuggerNode() {
- if (!singleton)
+ if (!singleton) {
singleton = this;
+ }
add_theme_constant_override("margin_left", -EditorNode::get_singleton()->get_gui_base()->get_theme_stylebox("BottomPanelDebuggerOverride", "EditorStyles")->get_margin(MARGIN_LEFT));
add_theme_constant_override("margin_right", -EditorNode::get_singleton()->get_gui_base()->get_theme_stylebox("BottomPanelDebuggerOverride", "EditorStyles")->get_margin(MARGIN_RIGHT));
@@ -119,8 +120,9 @@ ScriptEditorDebugger *EditorDebuggerNode::_add_debugger() {
void EditorDebuggerNode::_stack_frame_selected(int p_debugger) {
const ScriptEditorDebugger *dbg = get_debugger(p_debugger);
ERR_FAIL_COND(!dbg);
- if (dbg != get_current_debugger())
+ if (dbg != get_current_debugger()) {
return;
+ }
_text_editor_stack_goto(dbg);
}
@@ -131,8 +133,9 @@ void EditorDebuggerNode::_error_selected(const String &p_file, int p_line, int p
void EditorDebuggerNode::_text_editor_stack_goto(const ScriptEditorDebugger *p_debugger) {
const String file = p_debugger->get_stack_script_file();
- if (file.empty())
+ if (file.empty()) {
return;
+ }
stack_script = ResourceLoader::load(file);
const int line = p_debugger->get_stack_script_line() - 1;
emit_signal("goto_script_line", stack_script, line);
@@ -198,13 +201,15 @@ void EditorDebuggerNode::stop() {
}
// Also close all debugging sessions.
_for_all(tabs, [&](ScriptEditorDebugger *dbg) {
- if (dbg->is_session_active())
+ if (dbg->is_session_active()) {
dbg->stop();
+ }
});
_break_state_changed();
if (hide_on_stop) {
- if (is_visible_in_tree())
+ if (is_visible_in_tree()) {
EditorNode::get_singleton()->hide_bottom_panel();
+ }
}
breakpoints.clear();
set_process(false);
@@ -224,8 +229,9 @@ void EditorDebuggerNode::_notification(int p_what) {
break;
}
- if (p_what != NOTIFICATION_PROCESS || !server.is_valid())
+ if (p_what != NOTIFICATION_PROCESS || !server.is_valid()) {
return;
+ }
if (!server.is_valid() || !server->is_active()) {
stop();
@@ -285,8 +291,9 @@ void EditorDebuggerNode::_notification(int p_what) {
if (server->is_connection_available()) {
ScriptEditorDebugger *debugger = nullptr;
_for_all(tabs, [&](ScriptEditorDebugger *dbg) {
- if (debugger || dbg->is_session_active())
+ if (debugger || dbg->is_session_active()) {
return;
+ }
debugger = dbg;
});
if (debugger == nullptr) {
@@ -325,8 +332,9 @@ void EditorDebuggerNode::_debugger_stopped(int p_id) {
bool found = false;
_for_all(tabs, [&](ScriptEditorDebugger *p_debugger) {
- if (p_debugger->is_session_active())
+ if (p_debugger->is_session_active()) {
found = true;
+ }
});
if (!found) {
EditorNode::get_singleton()->get_pause_button()->set_pressed(false);
@@ -340,8 +348,9 @@ void EditorDebuggerNode::_debugger_stopped(int p_id) {
void EditorDebuggerNode::_debugger_wants_stop(int p_id) {
// Ask editor to kill PID.
int pid = get_debugger(p_id)->get_remote_pid();
- if (pid)
+ if (pid) {
EditorNode::get_singleton()->call_deferred("stop_child_process", pid);
+ }
}
void EditorDebuggerNode::_debugger_changed(int p_tab) {
@@ -380,12 +389,14 @@ void EditorDebuggerNode::set_script_debug_button(MenuButton *p_button) {
void EditorDebuggerNode::_break_state_changed() {
const bool breaked = get_current_debugger()->is_breaked();
const bool can_debug = get_current_debugger()->is_debuggable();
- if (breaked) // Show debugger.
+ if (breaked) { // Show debugger.
EditorNode::get_singleton()->make_bottom_panel_item_visible(this);
+ }
// Update script menu.
- if (!script_menu)
+ if (!script_menu) {
return;
+ }
PopupMenu *p = script_menu->get_popup();
p->set_item_disabled(p->get_item_index(DEBUG_NEXT), !(breaked && can_debug));
p->set_item_disabled(p->get_item_index(DEBUG_STEP), !(breaked && can_debug));
@@ -434,8 +445,9 @@ void EditorDebuggerNode::_paused() {
void EditorDebuggerNode::_breaked(bool p_breaked, bool p_can_debug, int p_debugger) {
if (get_current_debugger() != get_debugger(p_debugger)) {
- if (!p_breaked)
+ if (!p_breaked) {
return;
+ }
tabs->set_current_tab(p_debugger);
}
_break_state_changed();
@@ -486,58 +498,67 @@ void EditorDebuggerNode::request_remote_tree() {
}
void EditorDebuggerNode::_remote_tree_updated(int p_debugger) {
- if (p_debugger != tabs->get_current_tab())
+ if (p_debugger != tabs->get_current_tab()) {
return;
+ }
remote_scene_tree->clear();
remote_scene_tree->update_scene_tree(get_current_debugger()->get_remote_tree(), p_debugger);
}
void EditorDebuggerNode::_remote_object_updated(ObjectID p_id, int p_debugger) {
- if (p_debugger != tabs->get_current_tab())
+ if (p_debugger != tabs->get_current_tab()) {
return;
+ }
if (EditorDebuggerRemoteObject *obj = get_inspected_remote_object()) {
- if (obj->remote_object_id == p_id)
+ if (obj->remote_object_id == p_id) {
return; // Already being edited
+ }
}
EditorNode::get_singleton()->push_item(get_current_debugger()->get_remote_object(p_id));
}
void EditorDebuggerNode::_remote_object_property_updated(ObjectID p_id, const String &p_property, int p_debugger) {
- if (p_debugger != tabs->get_current_tab())
+ if (p_debugger != tabs->get_current_tab()) {
return;
+ }
if (EditorDebuggerRemoteObject *obj = get_inspected_remote_object()) {
- if (obj->remote_object_id != p_id)
+ if (obj->remote_object_id != p_id) {
return;
+ }
EditorNode::get_singleton()->get_inspector()->update_property(p_property);
}
}
void EditorDebuggerNode::_remote_object_requested(ObjectID p_id, int p_debugger) {
- if (p_debugger != tabs->get_current_tab())
+ if (p_debugger != tabs->get_current_tab()) {
return;
+ }
inspect_edited_object_timeout = 0.7; // Temporarily disable timeout to avoid multiple requests.
get_current_debugger()->request_remote_object(p_id);
}
void EditorDebuggerNode::_save_node_requested(ObjectID p_id, const String &p_file, int p_debugger) {
- if (p_debugger != tabs->get_current_tab())
+ if (p_debugger != tabs->get_current_tab()) {
return;
+ }
get_current_debugger()->save_node(p_id, p_file);
}
// Remote inspector/edit.
void EditorDebuggerNode::_method_changeds(void *p_ud, Object *p_base, const StringName &p_name, VARIANT_ARG_DECLARE) {
- if (!singleton)
+ if (!singleton) {
return;
+ }
_for_all(singleton->tabs, [&](ScriptEditorDebugger *dbg) {
dbg->_method_changed(p_base, p_name, VARIANT_ARG_PASS);
});
}
void EditorDebuggerNode::_property_changeds(void *p_ud, Object *p_base, const StringName &p_property, const Variant &p_value) {
- if (!singleton)
+ if (!singleton) {
return;
+ }
_for_all(singleton->tabs, [&](ScriptEditorDebugger *dbg) {
dbg->_property_changed(p_base, p_property, p_value);
});
diff --git a/editor/debugger/editor_debugger_node.h b/editor/debugger/editor_debugger_node.h
index 9138651147..ff9601c026 100644
--- a/editor/debugger/editor_debugger_node.h
+++ b/editor/debugger/editor_debugger_node.h
@@ -70,8 +70,9 @@ private:
int line = 0;
bool operator<(const Breakpoint &p_b) const {
- if (line == p_b.line)
+ if (line == p_b.line) {
return source < p_b.source;
+ }
return line < p_b.line;
}
diff --git a/editor/debugger/editor_debugger_tree.cpp b/editor/debugger/editor_debugger_tree.cpp
index ecffa0f05d..0b5f865a98 100644
--- a/editor/debugger/editor_debugger_tree.cpp
+++ b/editor/debugger/editor_debugger_tree.cpp
@@ -84,8 +84,9 @@ void EditorDebuggerTree::_scene_tree_folded(Object *p_obj) {
}
TreeItem *item = Object::cast_to<TreeItem>(p_obj);
- if (!item)
+ if (!item) {
return;
+ }
ObjectID id = ObjectID(uint64_t(item->get_metadata(0)));
if (unfold_cache.has(id)) {
@@ -97,8 +98,9 @@ void EditorDebuggerTree::_scene_tree_folded(Object *p_obj) {
void EditorDebuggerTree::_scene_tree_rmb_selected(const Vector2 &p_position) {
TreeItem *item = get_item_at_position(p_position);
- if (!item)
+ if (!item) {
return;
+ }
item->select(0);
@@ -176,12 +178,14 @@ void EditorDebuggerTree::update_scene_tree(const SceneDebuggerTree *p_tree, int
// Apply filters.
while (parent) {
const bool had_siblings = item->get_prev() || item->get_next();
- if (filter.is_subsequence_ofi(item->get_text(0)))
+ if (filter.is_subsequence_ofi(item->get_text(0))) {
break; // Filter matches, must survive.
+ }
parent->remove_child(item);
memdelete(item);
- if (had_siblings)
+ if (had_siblings) {
break; // Parent must survive.
+ }
item = parent;
parent = item->get_parent();
// Check if parent expects more children.
@@ -199,8 +203,9 @@ void EditorDebuggerTree::update_scene_tree(const SceneDebuggerTree *p_tree, int
}
String EditorDebuggerTree::get_selected_path() {
- if (!get_selected())
+ if (!get_selected()) {
return "";
+ }
return _get_path(get_selected());
}
@@ -256,7 +261,8 @@ void EditorDebuggerTree::_item_menu_id_pressed(int p_option) {
}
void EditorDebuggerTree::_file_selected(const String &p_file) {
- if (inspected_object_id.is_null())
+ if (inspected_object_id.is_null()) {
return;
+ }
emit_signal("save_node", inspected_object_id, p_file, debugger_id);
}
diff --git a/editor/debugger/editor_profiler.cpp b/editor/debugger/editor_profiler.cpp
index 0b10602c54..8bd21fff5c 100644
--- a/editor/debugger/editor_profiler.cpp
+++ b/editor/debugger/editor_profiler.cpp
@@ -45,8 +45,9 @@ void EditorProfiler::_make_metric_ptrs(Metric &m) {
void EditorProfiler::add_frame_metric(const Metric &p_metric, bool p_final) {
++last_metric;
- if (last_metric >= frame_metrics.size())
+ if (last_metric >= frame_metrics.size()) {
last_metric = 0;
+ }
frame_metrics.write[last_metric] = p_metric;
_make_metric_ptrs(frame_metrics.write[last_metric]);
@@ -134,19 +135,22 @@ Color EditorProfiler::_get_color_from_signature(const StringName &p_signature) c
}
void EditorProfiler::_item_edited() {
- if (updating_frame)
+ if (updating_frame) {
return;
+ }
TreeItem *item = variables->get_edited();
- if (!item)
+ if (!item) {
return;
+ }
StringName signature = item->get_metadata(0);
bool checked = item->is_checked(0);
- if (checked)
+ if (checked) {
plot_sigs.insert(signature);
- else
+ } else {
plot_sigs.erase(signature);
+ }
if (!frame_delay->is_processing()) {
frame_delay->set_wait_time(0.1);
@@ -185,8 +189,9 @@ void EditorProfiler::_update_plot() {
for (int i = 0; i < frame_metrics.size(); i++) {
const Metric &m = frame_metrics[i];
- if (!m.valid)
+ if (!m.valid) {
continue;
+ }
for (Set<StringName>::Element *E = plot_sigs.front(); E; E = E->next()) {
const Map<StringName, Metric::Category *>::Element *F = m.category_ptrs.find(E->get());
@@ -228,8 +233,9 @@ void EditorProfiler::_update_plot() {
if (next > frame_metrics.size()) {
next = frame_metrics.size();
}
- if (next == current)
+ if (next == current) {
next = current + 1; //just because for loop must work
+ }
for (Set<StringName>::Element *E = plot_sigs.front(); E; E = E->next()) {
int plot_pos = -1;
@@ -243,8 +249,9 @@ void EditorProfiler::_update_plot() {
//get
const Metric &m = frame_metrics[idx];
- if (!m.valid)
+ if (!m.valid) {
continue; //skip because invalid
+ }
float value = 0;
@@ -423,13 +430,15 @@ void EditorProfiler::_notification(int p_what) {
}
void EditorProfiler::_graph_tex_draw() {
- if (last_metric < 0)
+ if (last_metric < 0) {
return;
+ }
if (seeking) {
int max_frames = frame_metrics.size();
int frame = cursor_metric_edit->get_value() - (frame_metrics[last_metric].frame_number - max_frames + 1);
- if (frame < 0)
+ if (frame < 0) {
frame = 0;
+ }
int cur_x = frame * graph->get_size().x / max_frames;
@@ -439,8 +448,9 @@ void EditorProfiler::_graph_tex_draw() {
if (hover_metric != -1 && frame_metrics[hover_metric].valid) {
int max_frames = frame_metrics.size();
int frame = frame_metrics[hover_metric].frame_number - (frame_metrics[last_metric].frame_number - max_frames + 1);
- if (frame < 0)
+ if (frame < 0) {
frame = 0;
+ }
int cur_x = frame * graph->get_size().x / max_frames;
@@ -454,16 +464,18 @@ void EditorProfiler::_graph_tex_mouse_exit() {
}
void EditorProfiler::_cursor_metric_changed(double) {
- if (updating_frame)
+ if (updating_frame) {
return;
+ }
graph->update();
_update_frame();
}
void EditorProfiler::_graph_tex_input(const Ref<InputEvent> &p_ev) {
- if (last_metric < 0)
+ if (last_metric < 0) {
return;
+ }
Ref<InputEventMouse> me = p_ev;
Ref<InputEventMouseButton> mb = p_ev;
@@ -511,12 +523,14 @@ void EditorProfiler::_graph_tex_input(const Ref<InputEvent> &p_ev) {
}
metric++;
- if (metric >= frame_metrics.size())
+ if (metric >= frame_metrics.size()) {
metric = 0;
+ }
}
- if (valid)
+ if (valid) {
cursor_metric_edit->set_value(frame_metrics[metric].frame_number);
+ }
updating_frame = false;
@@ -539,10 +553,12 @@ void EditorProfiler::_graph_tex_input(const Ref<InputEvent> &p_ev) {
}
int EditorProfiler::_get_cursor_index() const {
- if (last_metric < 0)
+ if (last_metric < 0) {
return 0;
- if (!frame_metrics[last_metric].valid)
+ }
+ if (!frame_metrics[last_metric].valid) {
return 0;
+ }
int diff = (frame_metrics[last_metric].frame_number - cursor_metric_edit->get_value());
diff --git a/editor/debugger/editor_visual_profiler.cpp b/editor/debugger/editor_visual_profiler.cpp
index e1bd00f6f6..81b42da08e 100644
--- a/editor/debugger/editor_visual_profiler.cpp
+++ b/editor/debugger/editor_visual_profiler.cpp
@@ -36,8 +36,9 @@
void EditorVisualProfiler::add_frame_metric(const Metric &p_metric) {
++last_metric;
- if (last_metric >= frame_metrics.size())
+ if (last_metric >= frame_metrics.size()) {
last_metric = 0;
+ }
frame_metrics.write[last_metric] = p_metric;
// _make_metric_ptrs(frame_metrics.write[last_metric]);
@@ -130,12 +131,14 @@ Color EditorVisualProfiler::_get_color_from_signature(const StringName &p_signat
}
void EditorVisualProfiler::_item_selected() {
- if (updating_frame)
+ if (updating_frame) {
return;
+ }
TreeItem *item = variables->get_selected();
- if (!item)
+ if (!item) {
return;
+ }
selected_area = item->get_metadata(0);
_update_plot();
}
@@ -170,8 +173,9 @@ void EditorVisualProfiler::_update_plot() {
for (int i = 0; i < frame_metrics.size(); i++) {
const Metric &m = frame_metrics[i];
- if (!m.valid)
+ if (!m.valid) {
continue;
+ }
if (m.areas.size()) {
highest_cpu = MAX(highest_cpu, m.areas[m.areas.size() - 1].cpu_time);
@@ -216,8 +220,9 @@ void EditorVisualProfiler::_update_plot() {
if (next > frame_metrics.size()) {
next = frame_metrics.size();
}
- if (next == current)
+ if (next == current) {
next = current + 1; //just because for loop must work
+ }
for (int j = current; j < next; j++) {
//wrap
@@ -425,14 +430,16 @@ void EditorVisualProfiler::_notification(int p_what) {
}
void EditorVisualProfiler::_graph_tex_draw() {
- if (last_metric < 0)
+ if (last_metric < 0) {
return;
+ }
Ref<Font> font = get_theme_font("font", "Label");
if (seeking) {
int max_frames = frame_metrics.size();
int frame = cursor_metric_edit->get_value() - (frame_metrics[last_metric].frame_number - max_frames + 1);
- if (frame < 0)
+ if (frame < 0) {
frame = 0;
+ }
int half_width = graph->get_size().x / 2;
int cur_x = frame * half_width / max_frames;
@@ -488,16 +495,18 @@ void EditorVisualProfiler::_graph_tex_mouse_exit() {
}
void EditorVisualProfiler::_cursor_metric_changed(double) {
- if (updating_frame)
+ if (updating_frame) {
return;
+ }
graph->update();
_update_frame();
}
void EditorVisualProfiler::_graph_tex_input(const Ref<InputEvent> &p_ev) {
- if (last_metric < 0)
+ if (last_metric < 0) {
return;
+ }
Ref<InputEventMouse> me = p_ev;
Ref<InputEventMouseButton> mb = p_ev;
@@ -549,8 +558,9 @@ void EditorVisualProfiler::_graph_tex_input(const Ref<InputEvent> &p_ev) {
}
metric++;
- if (metric >= frame_metrics.size())
+ if (metric >= frame_metrics.size()) {
metric = 0;
+ }
}
if (!valid) {
@@ -610,10 +620,12 @@ void EditorVisualProfiler::_graph_tex_input(const Ref<InputEvent> &p_ev) {
}
int EditorVisualProfiler::_get_cursor_index() const {
- if (last_metric < 0)
+ if (last_metric < 0) {
return 0;
- if (!frame_metrics[last_metric].valid)
+ }
+ if (!frame_metrics[last_metric].valid) {
return 0;
+ }
int diff = (frame_metrics[last_metric].frame_number - cursor_metric_edit->get_value());
diff --git a/editor/debugger/script_editor_debugger.cpp b/editor/debugger/script_editor_debugger.cpp
index 867eef1c93..49137f76fa 100644
--- a/editor/debugger/script_editor_debugger.cpp
+++ b/editor/debugger/script_editor_debugger.cpp
@@ -74,17 +74,19 @@ void ScriptEditorDebugger::_put_msg(String p_message, Array p_data) {
void ScriptEditorDebugger::debug_copy() {
String msg = reason->get_text();
- if (msg == "")
+ if (msg == "") {
return;
+ }
DisplayServer::get_singleton()->clipboard_set(msg);
}
void ScriptEditorDebugger::debug_skip_breakpoints() {
skip_breakpoints_value = !skip_breakpoints_value;
- if (skip_breakpoints_value)
+ if (skip_breakpoints_value) {
skip_breakpoints->set_icon(get_theme_icon("DebugSkipBreakpointsOn", "EditorIcons"));
- else
+ } else {
skip_breakpoints->set_icon(get_theme_icon("DebugSkipBreakpointsOff", "EditorIcons"));
+ }
Array msg;
msg.push_back(skip_breakpoints_value);
@@ -115,8 +117,9 @@ void ScriptEditorDebugger::debug_continue() {
ERR_FAIL_COND(!breaked);
// Allow focus stealing only if we actually run this client for security.
- if (remote_pid && EditorNode::get_singleton()->has_child_process(remote_pid))
+ if (remote_pid && EditorNode::get_singleton()->has_child_process(remote_pid)) {
DisplayServer::get_singleton()->enable_for_stealing_focus(remote_pid);
+ }
_clear_execution();
_put_msg("continue", Array());
@@ -318,8 +321,9 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da
_update_buttons_state();
} else if (p_msg == "scene:inspect_object") {
ObjectID id = inspector->add_object(p_data);
- if (id.is_valid())
+ if (id.is_valid()) {
emit_signal("remote_object_updated", id);
+ }
} else if (p_msg == "memory:usage") {
vmem_tree->clear();
TreeItem *root = vmem_tree->create_item();
@@ -338,8 +342,9 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da
it->set_text(3, String::humanize_size(bytes));
total += bytes;
- if (has_theme_icon(type, "EditorIcons"))
+ if (has_theme_icon(type, "EditorIcons")) {
it->set_icon(0, get_theme_icon(type, "EditorIcons"));
+ }
}
vmem_total->set_tooltip(TTR("Bytes:") + " " + itos(total));
@@ -365,8 +370,9 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da
String line = itos(i) + " - " + String(d["file"]) + ":" + itos(d["line"]) + " - at function: " + d["function"];
s->set_text(0, line);
- if (i == 0)
+ if (i == 0) {
s->select(0);
+ }
}
} else if (p_msg == "stack_frame_vars") {
inspector->clear_stack_variables();
@@ -427,8 +433,9 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da
perf_items[i]->set_text(1, label);
perf_items[i]->set_tooltip(1, tooltip);
- if (p[i] > perf_max[i])
+ if (p[i] > perf_max[i]) {
perf_max.write[i] = p[i];
+ }
}
}
perf_history.push_front(p);
@@ -493,8 +500,9 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da
String error_title;
// Include method name, when given, in error title.
- if (!oe.source_func.empty())
+ if (!oe.source_func.empty()) {
error_title += oe.source_func + ": ";
+ }
// If we have a (custom) error message, use it as title, and add a C++ Error
// item with the original error condition.
error_title += oe.error_descr.empty() ? oe.error : oe.error_descr;
@@ -508,16 +516,18 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da
cpp_cond->set_text(1, oe.error);
cpp_cond->set_text_align(0, TreeItem::ALIGN_LEFT);
tooltip += TTR("C++ Error:") + " " + oe.error + "\n";
- if (source_is_project_file)
+ if (source_is_project_file) {
cpp_cond->set_metadata(0, source_meta);
+ }
}
Vector<uint8_t> v;
v.resize(100);
// Source of the error.
String source_txt = (source_is_project_file ? oe.source_file.get_file() : oe.source_file) + ":" + itos(oe.source_line);
- if (!oe.source_func.empty())
+ if (!oe.source_func.empty()) {
source_txt += " @ " + oe.source_func + "()";
+ }
TreeItem *cpp_source = error_tree->create_item(error);
cpp_source->set_text(0, "<" + (source_is_project_file ? TTR("Source") : TTR("C++ Source")) + ">");
@@ -554,10 +564,11 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da
stack_trace->set_text(1, infos[i].file.get_file() + ":" + itos(infos[i].line) + " @ " + infos[i].func + "()");
}
- if (oe.warning)
+ if (oe.warning) {
warning_count++;
- else
+ } else {
error_count++;
+ }
} else if (p_msg == "servers:function_signature") {
// Cache a profiler signature.
@@ -672,10 +683,11 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da
metric.categories.push_back(funcs);
- if (p_msg == "servers:profile_frame")
+ if (p_msg == "servers:profile_frame") {
profiler->add_frame_metric(metric, false);
- else
+ } else {
profiler->add_frame_metric(metric, true);
+ }
} else if (p_msg == "network:profile_frame") {
DebuggerMarshalls::NetworkProfilerFrame frame;
@@ -719,8 +731,9 @@ void ScriptEditorDebugger::_performance_select() {
void ScriptEditorDebugger::_performance_draw() {
Vector<int> which;
for (int i = 0; i < perf_items.size(); i++) {
- if (perf_items[i]->is_checked(0))
+ if (perf_items[i]->is_checked(0)) {
which.push_back(i);
+ }
}
if (which.empty()) {
@@ -735,8 +748,9 @@ void ScriptEditorDebugger::_performance_draw() {
int cols = Math::ceil(Math::sqrt((float)which.size()));
int rows = Math::ceil((float)which.size() / cols);
- if (which.size() == 1)
+ if (which.size() == 1) {
rows = 1;
+ }
int margin = 3;
int point_sep = 5;
@@ -768,13 +782,15 @@ void ScriptEditorDebugger::_performance_draw() {
float prev = -1;
while (from >= 0 && E) {
float m = perf_max[pi];
- if (m == 0)
+ if (m == 0) {
m = 0.00001;
+ }
float h2 = E->get()[pi] / m;
h2 = (1.0 - h2) * r.size.y;
- if (E != perf_history.front())
+ if (E != perf_history.front()) {
perf_draw->draw_line(r.position + Point2(from, h2), r.position + Point2(from + spacing, prev), c, Math::round(EDSCALE));
+ }
prev = h2;
E = E->next();
from -= spacing;
@@ -851,8 +867,9 @@ void ScriptEditorDebugger::_notification(int p_what) {
}
_parse_message(arr[0], arr[1]);
- if (OS::get_singleton()->get_ticks_msec() > until)
+ if (OS::get_singleton()->get_ticks_msec() > until) {
break;
+ }
}
if (!is_session_active()) {
_stop_and_notify();
@@ -877,8 +894,9 @@ void ScriptEditorDebugger::_notification(int p_what) {
void ScriptEditorDebugger::_clear_execution() {
TreeItem *ti = stack_dump->get_selected();
- if (!ti)
+ if (!ti) {
return;
+ }
Dictionary d = ti->get_metadata(0);
@@ -983,8 +1001,9 @@ void ScriptEditorDebugger::_profiler_activate(bool p_enable, int p_type) {
}
void ScriptEditorDebugger::_profiler_seeked() {
- if (breaked)
+ if (breaked) {
return;
+ }
debug_break();
}
@@ -1010,15 +1029,17 @@ void ScriptEditorDebugger::_export_csv() {
}
String ScriptEditorDebugger::get_var_value(const String &p_var) const {
- if (!breaked)
+ if (!breaked) {
return String();
+ }
return inspector->get_stack_variable(p_var);
}
int ScriptEditorDebugger::_get_node_path_cache(const NodePath &p_path) {
const int *r = node_path_cache.getptr(p_path);
- if (r)
+ if (r) {
return *r;
+ }
last_path_id++;
@@ -1034,8 +1055,9 @@ int ScriptEditorDebugger::_get_node_path_cache(const NodePath &p_path) {
int ScriptEditorDebugger::_get_res_path_cache(const String &p_path) {
Map<String, int>::Element *E = res_path_cache.find(p_path);
- if (E)
+ if (E) {
return E->get();
+ }
last_path_id++;
@@ -1049,8 +1071,9 @@ int ScriptEditorDebugger::_get_res_path_cache(const String &p_path) {
}
void ScriptEditorDebugger::_method_changed(Object *p_base, const StringName &p_name, VARIANT_ARG_DECLARE) {
- if (!p_base || !live_debug || !is_session_active() || !editor->get_edited_scene())
+ if (!p_base || !live_debug || !is_session_active() || !editor->get_edited_scene()) {
return;
+ }
Node *node = Object::cast_to<Node>(p_base);
@@ -1058,8 +1081,9 @@ void ScriptEditorDebugger::_method_changed(Object *p_base, const StringName &p_n
for (int i = 0; i < VARIANT_ARG_MAX; i++) {
//no pointers, sorry
- if (argptr[i] && (argptr[i]->get_type() == Variant::OBJECT || argptr[i]->get_type() == Variant::_RID))
+ if (argptr[i] && (argptr[i]->get_type() == Variant::OBJECT || argptr[i]->get_type() == Variant::_RID)) {
return;
+ }
}
if (node) {
@@ -1098,8 +1122,9 @@ void ScriptEditorDebugger::_method_changed(Object *p_base, const StringName &p_n
}
void ScriptEditorDebugger::_property_changed(Object *p_base, const StringName &p_property, const Variant &p_value) {
- if (!p_base || !live_debug || !editor->get_edited_scene())
+ if (!p_base || !live_debug || !editor->get_edited_scene()) {
return;
+ }
Node *node = Object::cast_to<Node>(p_base);
@@ -1156,24 +1181,27 @@ void ScriptEditorDebugger::_property_changed(Object *p_base, const StringName &p
String ScriptEditorDebugger::get_stack_script_file() const {
TreeItem *ti = stack_dump->get_selected();
- if (!ti)
+ if (!ti) {
return "";
+ }
Dictionary d = ti->get_metadata(0);
return d["file"];
}
int ScriptEditorDebugger::get_stack_script_line() const {
TreeItem *ti = stack_dump->get_selected();
- if (!ti)
+ if (!ti) {
return -1;
+ }
Dictionary d = ti->get_metadata(0);
return d["line"];
}
int ScriptEditorDebugger::get_stack_script_frame() const {
TreeItem *ti = stack_dump->get_selected();
- if (!ti)
+ if (!ti) {
return -1;
+ }
Dictionary d = ti->get_metadata(0);
return d["frame"];
}
@@ -1183,12 +1211,14 @@ void ScriptEditorDebugger::set_live_debugging(bool p_enable) {
}
void ScriptEditorDebugger::_live_edit_set() {
- if (!is_session_active() || !editor_remote_tree)
+ if (!is_session_active() || !editor_remote_tree) {
return;
+ }
TreeItem *ti = editor_remote_tree->get_selected();
- if (!ti)
+ if (!ti) {
return;
+ }
String path;
@@ -1217,10 +1247,11 @@ void ScriptEditorDebugger::update_live_edit_root() {
Array msg;
msg.push_back(np);
- if (editor->get_edited_scene())
+ if (editor->get_edited_scene()) {
msg.push_back(editor->get_edited_scene()->get_filename());
- else
+ } else {
msg.push_back("");
+ }
_put_msg("scene:live_set_root", msg);
live_edit_root->set_text(np);
}
@@ -1355,8 +1386,9 @@ void ScriptEditorDebugger::_error_selected() {
void ScriptEditorDebugger::_expand_errors_list() {
TreeItem *root = error_tree->get_root();
- if (!root)
+ if (!root) {
return;
+ }
TreeItem *item = root->get_children();
while (item) {
@@ -1367,8 +1399,9 @@ void ScriptEditorDebugger::_expand_errors_list() {
void ScriptEditorDebugger::_collapse_errors_list() {
TreeItem *root = error_tree->get_root();
- if (!root)
+ if (!root) {
return;
+ }
TreeItem *item = root->get_children();
while (item) {
@@ -1400,8 +1433,9 @@ void ScriptEditorDebugger::_error_tree_item_rmb_selected(const Vector2 &p_pos) {
void ScriptEditorDebugger::_item_menu_id_pressed(int p_option) {
TreeItem *ti = error_tree->get_selected();
- while (ti->get_parent() != error_tree->get_root())
+ while (ti->get_parent() != error_tree->get_root()) {
ti = ti->get_parent();
+ }
String type;
diff --git a/editor/dependency_editor.cpp b/editor/dependency_editor.cpp
index 9c8a7eaef0..c6977779bd 100644
--- a/editor/dependency_editor.cpp
+++ b/editor/dependency_editor.cpp
@@ -68,8 +68,9 @@ void DependencyEditor::_fix_and_find(EditorFileSystemDirectory *efsd, Map<String
for (int i = 0; i < efsd->get_file_count(); i++) {
String file = efsd->get_file(i);
- if (!candidates.has(file))
+ if (!candidates.has(file)) {
continue;
+ }
String path = efsd->get_file_path(i);
@@ -113,8 +114,9 @@ void DependencyEditor::_fix_and_find(EditorFileSystemDirectory *efsd, Map<String
}
void DependencyEditor::_fix_all() {
- if (!EditorFileSystem::get_singleton()->get_filesystem())
+ if (!EditorFileSystem::get_singleton()->get_filesystem()) {
return;
+ }
Map<String, Map<String, String>> candidates;
@@ -278,8 +280,9 @@ void DependencyEditorOwners::_file_option(int p_option) {
switch (p_option) {
case FILE_OPEN: {
int idx = owners->get_current();
- if (idx < 0 || idx >= owners->get_item_count())
+ if (idx < 0 || idx >= owners->get_item_count()) {
break;
+ }
_select_file(idx);
} break;
}
@@ -289,8 +292,9 @@ void DependencyEditorOwners::_bind_methods() {
}
void DependencyEditorOwners::_fill_owners(EditorFileSystemDirectory *efsd) {
- if (!efsd)
+ if (!efsd) {
return;
+ }
for (int i = 0; i < efsd->get_subdir_count(); i++) {
_fill_owners(efsd->get_subdir(i));
@@ -305,8 +309,9 @@ void DependencyEditorOwners::_fill_owners(EditorFileSystemDirectory *efsd) {
break;
}
}
- if (!found)
+ if (!found) {
continue;
+ }
Ref<Texture2D> icon = EditorNode::get_singleton()->get_class_icon(efsd->get_file_type(i));
@@ -341,8 +346,9 @@ DependencyEditorOwners::DependencyEditorOwners(EditorNode *p_editor) {
///////////////////////
void DependencyRemoveDialog::_find_files_in_removed_folder(EditorFileSystemDirectory *efsd, const String &p_folder) {
- if (!efsd)
+ if (!efsd) {
return;
+ }
for (int i = 0; i < efsd->get_subdir_count(); ++i) {
_find_files_in_removed_folder(efsd->get_subdir(i), p_folder);
@@ -355,8 +361,9 @@ void DependencyRemoveDialog::_find_files_in_removed_folder(EditorFileSystemDirec
}
void DependencyRemoveDialog::_find_all_removed_dependencies(EditorFileSystemDirectory *efsd, Vector<RemovedDependency> &p_removed) {
- if (!efsd)
+ if (!efsd) {
return;
+ }
for (int i = 0; i < efsd->get_subdir_count(); i++) {
_find_all_removed_dependencies(efsd->get_subdir(i), p_removed);
@@ -366,8 +373,9 @@ void DependencyRemoveDialog::_find_all_removed_dependencies(EditorFileSystemDire
const String path = efsd->get_file_path(i);
//It doesn't matter if a file we are about to delete will have some of its dependencies removed too
- if (all_remove_files.has(path))
+ if (all_remove_files.has(path)) {
continue;
+ }
Vector<String> all_deps = efsd->get_file_deps(i);
for (int j = 0; j < all_deps.size(); ++j) {
@@ -500,8 +508,9 @@ void DependencyRemoveDialog::ok_pressed() {
if (dirs_to_delete.size() == 0) {
// If we only deleted files we should only need to tell the file system about the files we touched.
- for (int i = 0; i < files_to_delete.size(); ++i)
+ for (int i = 0; i < files_to_delete.size(); ++i) {
EditorFileSystem::get_singleton()->update_file(files_to_delete[i]);
+ }
} else {
for (int i = 0; i < dirs_to_delete.size(); ++i) {
String path = OS::get_singleton()->get_resource_dir() + dirs_to_delete[i].replace_first("res://", "/");
@@ -523,11 +532,13 @@ void DependencyRemoveDialog::ok_pressed() {
for (int i = 0; i < previous_favorites.size(); ++i) {
if (previous_favorites[i].ends_with("/")) {
- if (dirs_to_delete.find(previous_favorites[i]) < 0)
+ if (dirs_to_delete.find(previous_favorites[i]) < 0) {
new_favorites.push_back(previous_favorites[i]);
+ }
} else {
- if (files_to_delete.find(previous_favorites[i]) < 0)
+ if (files_to_delete.find(previous_favorites[i]) < 0) {
new_favorites.push_back(previous_favorites[i]);
+ }
}
}
@@ -569,8 +580,9 @@ void DependencyErrorDialog::show(Mode p_mode, const String &p_for_file, const Ve
String dep;
String type = "Object";
dep = report[i].get_slice("::", 0);
- if (report[i].get_slice_count("::") > 0)
+ if (report[i].get_slice_count("::") > 0) {
type = report[i].get_slice("::", 1);
+ }
Ref<Texture2D> icon = EditorNode::get_singleton()->get_class_icon(type);
@@ -625,16 +637,18 @@ void OrphanResourcesDialog::ok_pressed() {
paths.clear();
_find_to_delete(files->get_root(), paths);
- if (paths.empty())
+ if (paths.empty()) {
return;
+ }
delete_confirm->set_text(vformat(TTR("Permanently delete %d item(s)? (No undo!)"), paths.size()));
delete_confirm->popup_centered();
}
bool OrphanResourcesDialog::_fill_owners(EditorFileSystemDirectory *efsd, HashMap<String, int> &refs, TreeItem *p_parent) {
- if (!efsd)
+ if (!efsd) {
return false;
+ }
bool has_children = false;
diff --git a/editor/dictionary_property_edit.cpp b/editor/dictionary_property_edit.cpp
index c92f62cf58..276cd12ded 100644
--- a/editor/dictionary_property_edit.cpp
+++ b/editor/dictionary_property_edit.cpp
@@ -47,19 +47,22 @@ void DictionaryPropertyEdit::_set_value(const Variant &p_key, const Variant &p_v
Dictionary dict = get_dictionary();
dict[p_key] = p_value;
Object *o = ObjectDB::get_instance(obj);
- if (!o)
+ if (!o) {
return;
+ }
o->set(property, dict);
}
Variant DictionaryPropertyEdit::get_dictionary() const {
Object *o = ObjectDB::get_instance(obj);
- if (!o)
+ if (!o) {
return Dictionary();
+ }
Variant dict = o->get(property);
- if (dict.get_type() != Variant::DICTIONARY)
+ if (dict.get_type() != Variant::DICTIONARY) {
return Dictionary();
+ }
return dict;
}
@@ -89,8 +92,9 @@ void DictionaryPropertyEdit::edit(Object *p_obj, const StringName &p_prop) {
Node *DictionaryPropertyEdit::get_node() {
Object *o = ObjectDB::get_instance(obj);
- if (!o)
+ if (!o) {
return nullptr;
+ }
return cast_to<Node>(o);
}
diff --git a/editor/doc_data.cpp b/editor/doc_data.cpp
index d45c9f5ff5..53641da0e9 100644
--- a/editor/doc_data.cpp
+++ b/editor/doc_data.cpp
@@ -47,8 +47,9 @@ void DocData::merge_from(const DocData &p_data) {
for (Map<String, ClassDoc>::Element *E = class_list.front(); E; E = E->next()) {
ClassDoc &c = E->get();
- if (!p_data.class_list.has(c.name))
+ if (!p_data.class_list.has(c.name)) {
continue;
+ }
const ClassDoc &cf = p_data.class_list[c.name];
@@ -60,32 +61,39 @@ void DocData::merge_from(const DocData &p_data) {
MethodDoc &m = c.methods.write[i];
for (int j = 0; j < cf.methods.size(); j++) {
- if (cf.methods[j].name != m.name)
+ if (cf.methods[j].name != m.name) {
continue;
- if (cf.methods[j].arguments.size() != m.arguments.size())
+ }
+ if (cf.methods[j].arguments.size() != m.arguments.size()) {
continue;
+ }
// since polymorphic functions are allowed we need to check the type of
// the arguments so we make sure they are different.
int arg_count = cf.methods[j].arguments.size();
Vector<bool> arg_used;
arg_used.resize(arg_count);
- for (int l = 0; l < arg_count; ++l)
+ for (int l = 0; l < arg_count; ++l) {
arg_used.write[l] = false;
+ }
// also there is no guarantee that argument ordering will match, so we
// have to check one by one so we make sure we have an exact match
for (int k = 0; k < arg_count; ++k) {
- for (int l = 0; l < arg_count; ++l)
+ for (int l = 0; l < arg_count; ++l) {
if (cf.methods[j].arguments[k].type == m.arguments[l].type && !arg_used[l]) {
arg_used.write[l] = true;
break;
}
+ }
}
bool not_the_same = false;
- for (int l = 0; l < arg_count; ++l)
- if (!arg_used[l]) // at least one of the arguments was different
+ for (int l = 0; l < arg_count; ++l) {
+ if (!arg_used[l]) { // at least one of the arguments was different
not_the_same = true;
- if (not_the_same)
+ }
+ }
+ if (not_the_same) {
continue;
+ }
const MethodDoc &mf = cf.methods[j];
@@ -98,8 +106,9 @@ void DocData::merge_from(const DocData &p_data) {
MethodDoc &m = c.signals.write[i];
for (int j = 0; j < cf.signals.size(); j++) {
- if (cf.signals[j].name != m.name)
+ if (cf.signals[j].name != m.name) {
continue;
+ }
const MethodDoc &mf = cf.signals[j];
m.description = mf.description;
@@ -111,8 +120,9 @@ void DocData::merge_from(const DocData &p_data) {
ConstantDoc &m = c.constants.write[i];
for (int j = 0; j < cf.constants.size(); j++) {
- if (cf.constants[j].name != m.name)
+ if (cf.constants[j].name != m.name) {
continue;
+ }
const ConstantDoc &mf = cf.constants[j];
m.description = mf.description;
@@ -124,8 +134,9 @@ void DocData::merge_from(const DocData &p_data) {
PropertyDoc &p = c.properties.write[i];
for (int j = 0; j < cf.properties.size(); j++) {
- if (cf.properties[j].name != p.name)
+ if (cf.properties[j].name != p.name) {
continue;
+ }
const PropertyDoc &pf = cf.properties[j];
p.description = pf.description;
@@ -137,8 +148,9 @@ void DocData::merge_from(const DocData &p_data) {
PropertyDoc &p = c.theme_properties.write[i];
for (int j = 0; j < cf.theme_properties.size(); j++) {
- if (cf.theme_properties[j].name != p.name)
+ if (cf.theme_properties[j].name != p.name) {
continue;
+ }
const PropertyDoc &pf = cf.theme_properties[j];
p.description = pf.description;
@@ -167,16 +179,18 @@ void DocData::merge_from(const DocData &p_data) {
void DocData::remove_from(const DocData &p_data) {
for (Map<String, ClassDoc>::Element *E = p_data.class_list.front(); E; E = E->next()) {
- if (class_list.has(E->key()))
+ if (class_list.has(E->key())) {
class_list.erase(E->key());
+ }
}
}
static void return_doc_from_retinfo(DocData::MethodDoc &p_method, const PropertyInfo &p_retinfo) {
if (p_retinfo.type == Variant::INT && p_retinfo.usage & PROPERTY_USAGE_CLASS_IS_ENUM) {
p_method.return_enum = p_retinfo.class_name;
- if (p_method.return_enum.begins_with("_")) //proxy class
+ if (p_method.return_enum.begins_with("_")) { //proxy class
p_method.return_enum = p_method.return_enum.substr(1, p_method.return_enum.length());
+ }
p_method.return_type = "int";
} else if (p_retinfo.class_name != StringName()) {
p_method.return_type = p_retinfo.class_name;
@@ -198,8 +212,9 @@ static void argument_doc_from_arginfo(DocData::ArgumentDoc &p_argument, const Pr
if (p_arginfo.type == Variant::INT && p_arginfo.usage & PROPERTY_USAGE_CLASS_IS_ENUM) {
p_argument.enumeration = p_arginfo.class_name;
- if (p_argument.enumeration.begins_with("_")) //proxy class
+ if (p_argument.enumeration.begins_with("_")) { //proxy class
p_argument.enumeration = p_argument.enumeration.substr(1, p_argument.enumeration.length());
+ }
p_argument.type = "int";
} else if (p_arginfo.class_name != StringName()) {
p_argument.type = p_arginfo.class_name;
@@ -228,8 +243,9 @@ static Variant get_documentation_default_value(const StringName &p_class_name, c
for (List<StringName>::Element *E2 = inheriting_classes.front(); E2; E2 = E2->next()) {
if (ClassDB::can_instance(E2->get())) {
default_value = ClassDB::class_get_default_property_value(E2->get(), p_property_name, &r_default_value_valid);
- if (r_default_value_valid)
+ if (r_default_value_valid) {
break;
+ }
}
}
}
@@ -257,8 +273,9 @@ void DocData::generate(bool p_basic_types) {
}
String cname = name;
- if (cname.begins_with("_")) //proxy class
+ if (cname.begins_with("_")) { //proxy class
cname = cname.substr(1, name.length());
+ }
class_list[cname] = ClassDoc();
ClassDoc &c = class_list[cname];
@@ -284,8 +301,9 @@ void DocData::generate(bool p_basic_types) {
EO = EO->next();
}
- if (E->get().usage & PROPERTY_USAGE_GROUP || E->get().usage & PROPERTY_USAGE_SUBGROUP || E->get().usage & PROPERTY_USAGE_CATEGORY || E->get().usage & PROPERTY_USAGE_INTERNAL)
+ if (E->get().usage & PROPERTY_USAGE_GROUP || E->get().usage & PROPERTY_USAGE_SUBGROUP || E->get().usage & PROPERTY_USAGE_CATEGORY || E->get().usage & PROPERTY_USAGE_INTERNAL) {
continue;
+ }
PropertyDoc prop;
@@ -312,8 +330,9 @@ void DocData::generate(bool p_basic_types) {
if (inherited) {
bool base_default_value_valid = false;
Variant base_default_value = get_documentation_default_value(ClassDB::get_parent_class(name), E->get().name, base_default_value_valid);
- if (!default_value_valid || !base_default_value_valid || default_value == base_default_value)
+ if (!default_value_valid || !base_default_value_valid || default_value == base_default_value) {
continue;
+ }
}
}
@@ -362,10 +381,11 @@ void DocData::generate(bool p_basic_types) {
}
if (!found_type) {
- if (E->get().type == Variant::OBJECT && E->get().hint == PROPERTY_HINT_RESOURCE_TYPE)
+ if (E->get().type == Variant::OBJECT && E->get().hint == PROPERTY_HINT_RESOURCE_TYPE) {
prop.type = E->get().hint_string;
- else
+ } else {
prop.type = Variant::get_type_name(E->get().type);
+ }
}
c.properties.push_back(prop);
@@ -376,8 +396,9 @@ void DocData::generate(bool p_basic_types) {
method_list.sort();
for (List<MethodInfo>::Element *E = method_list.front(); E; E = E->next()) {
- if (E->get().name == "" || (E->get().name[0] == '_' && !(E->get().flags & METHOD_FLAG_VIRTUAL)))
+ if (E->get().name == "" || (E->get().name[0] == '_' && !(E->get().flags & METHOD_FLAG_VIRTUAL))) {
continue; //hidden, don't count
+ }
if (skip_setter_getter_methods && setters_getters.has(E->get().name)) {
// Don't skip parametric setters and getters, i.e. method which require
@@ -392,16 +413,19 @@ void DocData::generate(bool p_basic_types) {
method.name = E->get().name;
- if (E->get().flags & METHOD_FLAG_VIRTUAL)
+ if (E->get().flags & METHOD_FLAG_VIRTUAL) {
method.qualifiers = "virtual";
+ }
if (E->get().flags & METHOD_FLAG_CONST) {
- if (method.qualifiers != "")
+ if (method.qualifiers != "") {
method.qualifiers += " ";
+ }
method.qualifiers += "const";
} else if (E->get().flags & METHOD_FLAG_VARARG) {
- if (method.qualifiers != "")
+ if (method.qualifiers != "") {
method.qualifiers += " ";
+ }
method.qualifiers += "vararg";
}
@@ -516,15 +540,18 @@ void DocData::generate(bool p_basic_types) {
class_list["Variant"].name = "Variant";
}
- if (!p_basic_types)
+ if (!p_basic_types) {
return;
+ }
// Add Variant types.
for (int i = 0; i < Variant::VARIANT_MAX; i++) {
- if (i == Variant::NIL)
+ if (i == Variant::NIL) {
continue; // Not exposed outside of 'null', should not be in class list.
- if (i == Variant::OBJECT)
+ }
+ if (i == Variant::OBJECT) {
continue; // Use the core type instead.
+ }
String cname = Variant::get_type_name(Variant::Type(i));
@@ -564,8 +591,9 @@ void DocData::generate(bool p_basic_types) {
return_doc_from_retinfo(method, mi.return_val);
if (mi.flags & METHOD_FLAG_VARARG) {
- if (method.qualifiers != "")
+ if (method.qualifiers != "") {
method.qualifiers += " ";
+ }
method.qualifiers += "vararg";
}
@@ -624,10 +652,12 @@ void DocData::generate(bool p_basic_types) {
}
pd.name = s.name;
pd.type = s.ptr->get_class();
- while (String(ClassDB::get_parent_class(pd.type)) != "Object")
+ while (String(ClassDB::get_parent_class(pd.type)) != "Object") {
pd.type = ClassDB::get_parent_class(pd.type);
- if (pd.type.begins_with("_"))
+ }
+ if (pd.type.begins_with("_")) {
pd.type = pd.type.substr(1, pd.type.length());
+ }
c.properties.push_back(pd);
}
}
@@ -652,8 +682,9 @@ void DocData::generate(bool p_basic_types) {
md.name = mi.name;
if (mi.flags & METHOD_FLAG_VARARG) {
- if (md.qualifiers != "")
+ if (md.qualifiers != "") {
md.qualifiers += " ";
+ }
md.qualifiers += "vararg";
}
@@ -698,8 +729,9 @@ static Error _parse_methods(Ref<XMLParser> &parser, Vector<DocData::MethodDoc> &
DocData::MethodDoc method;
ERR_FAIL_COND_V(!parser->has_attribute("name"), ERR_FILE_CORRUPT);
method.name = parser->get_attribute_value("name");
- if (parser->has_attribute("qualifiers"))
+ if (parser->has_attribute("qualifiers")) {
method.qualifiers = parser->get_attribute_value("qualifiers");
+ }
while (parser->read() == OK) {
if (parser->get_node_type() == XMLParser::NODE_ELEMENT) {
@@ -724,12 +756,14 @@ static Error _parse_methods(Ref<XMLParser> &parser, Vector<DocData::MethodDoc> &
} else if (name == "description") {
parser->read();
- if (parser->get_node_type() == XMLParser::NODE_TEXT)
+ if (parser->get_node_type() == XMLParser::NODE_TEXT) {
method.description = parser->get_node_data();
+ }
}
- } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == element)
+ } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == element) {
break;
+ }
}
methods.push_back(method);
@@ -738,8 +772,9 @@ static Error _parse_methods(Ref<XMLParser> &parser, Vector<DocData::MethodDoc> &
ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Invalid tag in doc file: " + parser->get_node_name() + ".");
}
- } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == section)
+ } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == section) {
break;
+ }
}
return OK;
@@ -759,8 +794,9 @@ Error DocData::load_classes(const String &p_dir) {
if (!da->current_is_dir() && path.ends_with("xml")) {
Ref<XMLParser> parser = memnew(XMLParser);
Error err2 = parser->open(p_dir.plus_file(path));
- if (err2)
+ if (err2) {
return err2;
+ }
_load(parser);
}
@@ -808,8 +844,9 @@ Error DocData::_load(Ref<XMLParser> parser) {
parser->skip_section();
}
- if (parser->get_node_type() != XMLParser::NODE_ELEMENT)
+ if (parser->get_node_type() != XMLParser::NODE_ELEMENT) {
continue; //no idea what this may be, but skipping anyway
+ }
ERR_FAIL_COND_V(parser->get_node_name() != "class", ERR_FILE_CORRUPT);
@@ -819,8 +856,9 @@ Error DocData::_load(Ref<XMLParser> parser) {
ClassDoc &c = class_list[name];
c.name = name;
- if (parser->has_attribute("inherits"))
+ if (parser->has_attribute("inherits")) {
c.inherits = parser->get_attribute_value("inherits");
+ }
while (parser->read() == OK) {
if (parser->get_node_type() == XMLParser::NODE_ELEMENT) {
@@ -828,13 +866,15 @@ Error DocData::_load(Ref<XMLParser> parser) {
if (name2 == "brief_description") {
parser->read();
- if (parser->get_node_type() == XMLParser::NODE_TEXT)
+ if (parser->get_node_type() == XMLParser::NODE_TEXT) {
c.brief_description = parser->get_node_data();
+ }
} else if (name2 == "description") {
parser->read();
- if (parser->get_node_type() == XMLParser::NODE_TEXT)
+ if (parser->get_node_type() == XMLParser::NODE_TEXT) {
c.description = parser->get_node_data();
+ }
} else if (name2 == "tutorials") {
while (parser->read() == OK) {
if (parser->get_node_type() == XMLParser::NODE_ELEMENT) {
@@ -842,13 +882,15 @@ Error DocData::_load(Ref<XMLParser> parser) {
if (name3 == "link") {
parser->read();
- if (parser->get_node_type() == XMLParser::NODE_TEXT)
+ if (parser->get_node_type() == XMLParser::NODE_TEXT) {
c.tutorials.push_back(parser->get_node_data().strip_edges());
+ }
} else {
ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Invalid tag in doc file: " + name3 + ".");
}
- } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == "tutorials")
+ } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == "tutorials") {
break; // End of <tutorials>.
+ }
}
} else if (name2 == "methods") {
Error err2 = _parse_methods(parser, c.methods);
@@ -869,24 +911,29 @@ Error DocData::_load(Ref<XMLParser> parser) {
prop2.name = parser->get_attribute_value("name");
ERR_FAIL_COND_V(!parser->has_attribute("type"), ERR_FILE_CORRUPT);
prop2.type = parser->get_attribute_value("type");
- if (parser->has_attribute("setter"))
+ if (parser->has_attribute("setter")) {
prop2.setter = parser->get_attribute_value("setter");
- if (parser->has_attribute("getter"))
+ }
+ if (parser->has_attribute("getter")) {
prop2.getter = parser->get_attribute_value("getter");
- if (parser->has_attribute("enum"))
+ }
+ if (parser->has_attribute("enum")) {
prop2.enumeration = parser->get_attribute_value("enum");
+ }
if (!parser->is_empty()) {
parser->read();
- if (parser->get_node_type() == XMLParser::NODE_TEXT)
+ if (parser->get_node_type() == XMLParser::NODE_TEXT) {
prop2.description = parser->get_node_data();
+ }
}
c.properties.push_back(prop2);
} else {
ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Invalid tag in doc file: " + name3 + ".");
}
- } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == "members")
+ } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == "members") {
break; // End of <members>.
+ }
}
} else if (name2 == "theme_items") {
@@ -903,16 +950,18 @@ Error DocData::_load(Ref<XMLParser> parser) {
prop2.type = parser->get_attribute_value("type");
if (!parser->is_empty()) {
parser->read();
- if (parser->get_node_type() == XMLParser::NODE_TEXT)
+ if (parser->get_node_type() == XMLParser::NODE_TEXT) {
prop2.description = parser->get_node_data();
+ }
}
c.theme_properties.push_back(prop2);
} else {
ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Invalid tag in doc file: " + name3 + ".");
}
- } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == "theme_items")
+ } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == "theme_items") {
break; // End of <theme_items>.
+ }
}
} else if (name2 == "constants") {
@@ -931,24 +980,27 @@ Error DocData::_load(Ref<XMLParser> parser) {
}
if (!parser->is_empty()) {
parser->read();
- if (parser->get_node_type() == XMLParser::NODE_TEXT)
+ if (parser->get_node_type() == XMLParser::NODE_TEXT) {
constant2.description = parser->get_node_data();
+ }
}
c.constants.push_back(constant2);
} else {
ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Invalid tag in doc file: " + name3 + ".");
}
- } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == "constants")
+ } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == "constants") {
break; // End of <constants>.
+ }
}
} else {
ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Invalid tag in doc file: " + name2 + ".");
}
- } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == "class")
+ } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == "class") {
break; // End of <class>.
+ }
}
}
@@ -956,11 +1008,13 @@ Error DocData::_load(Ref<XMLParser> parser) {
}
static void _write_string(FileAccess *f, int p_tablevel, const String &p_string) {
- if (p_string == "")
+ if (p_string == "") {
return;
+ }
String tab;
- for (int i = 0; i < p_tablevel; i++)
+ for (int i = 0; i < p_tablevel; i++) {
tab += "\t";
+ }
f->store_string(tab + p_string + "\n");
}
@@ -984,8 +1038,9 @@ Error DocData::save_classes(const String &p_default_path, const Map<String, Stri
_write_string(f, 0, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
String header = "<class name=\"" + c.name + "\"";
- if (c.inherits != "")
+ if (c.inherits != "") {
header += " inherits=\"" + c.inherits + "\"";
+ }
header += String(" version=\"") + VERSION_BRANCH + "\"";
header += ">";
_write_string(f, 0, header);
@@ -1012,8 +1067,9 @@ Error DocData::save_classes(const String &p_default_path, const Map<String, Stri
const MethodDoc &m = c.methods[i];
String qualifiers;
- if (m.qualifiers != "")
+ if (m.qualifiers != "") {
qualifiers += " qualifiers=\"" + m.qualifiers.xml_escape() + "\"";
+ }
_write_string(f, 2, "<method name=\"" + m.name + "\"" + qualifiers + ">");
@@ -1034,10 +1090,11 @@ Error DocData::save_classes(const String &p_default_path, const Map<String, Stri
enum_text = " enum=\"" + a.enumeration + "\"";
}
- if (a.default_value != "")
+ if (a.default_value != "") {
_write_string(f, 3, "<argument index=\"" + itos(j) + "\" name=\"" + a.name.xml_escape() + "\" type=\"" + a.type.xml_escape() + "\"" + enum_text + " default=\"" + a.default_value.xml_escape(true) + "\">");
- else
+ } else {
_write_string(f, 3, "<argument index=\"" + itos(j) + "\" name=\"" + a.name.xml_escape() + "\" type=\"" + a.type.xml_escape() + "\"" + enum_text + ">");
+ }
_write_string(f, 3, "</argument>");
}
@@ -1123,10 +1180,11 @@ Error DocData::save_classes(const String &p_default_path, const Map<String, Stri
for (int i = 0; i < c.theme_properties.size(); i++) {
const PropertyDoc &p = c.theme_properties[i];
- if (p.default_value != "")
+ if (p.default_value != "") {
_write_string(f, 2, "<theme_item name=\"" + p.name + "\" type=\"" + p.type + "\" default=\"" + p.default_value.xml_escape(true) + "\">");
- else
+ } else {
_write_string(f, 2, "<theme_item name=\"" + p.name + "\" type=\"" + p.type + "\">");
+ }
_write_string(f, 3, p.description.strip_edges().xml_escape());
@@ -1149,8 +1207,9 @@ Error DocData::load_compressed(const uint8_t *p_data, int p_compressed_size, int
Ref<XMLParser> parser = memnew(XMLParser);
Error err = parser->open_buffer(data);
- if (err)
+ if (err) {
return err;
+ }
_load(parser);
diff --git a/editor/editor_about.cpp b/editor/editor_about.cpp
index a41444a27f..d99726c57c 100644
--- a/editor/editor_about.cpp
+++ b/editor/editor_about.cpp
@@ -123,8 +123,9 @@ EditorAbout::EditorAbout() {
hbc->add_child(_logo);
String hash = String(VERSION_HASH);
- if (hash.length() != 0)
+ if (hash.length() != 0) {
hash = "." + hash.left(9);
+ }
Label *about_text = memnew(Label);
about_text->set_v_size_flags(Control::SIZE_SHRINK_CENTER);
diff --git a/editor/editor_asset_installer.cpp b/editor/editor_asset_installer.cpp
index 9b05826e92..b43ee0e245 100644
--- a/editor/editor_asset_installer.cpp
+++ b/editor/editor_asset_installer.cpp
@@ -55,12 +55,14 @@ void EditorAssetInstaller::_update_subitems(TreeItem *p_item, bool p_check, bool
}
void EditorAssetInstaller::_item_edited() {
- if (updating)
+ if (updating) {
return;
+ }
TreeItem *item = tree->get_edited();
- if (!item)
+ if (!item) {
return;
+ }
String path = item->get_metadata(0);
@@ -145,8 +147,9 @@ void EditorAssetInstaller::open(const String &p_path, int p_depth) {
depth--;
}
- if (skip || path == String())
+ if (skip || path == String()) {
continue;
+ }
bool isdir = false;
@@ -285,11 +288,13 @@ void EditorAssetInstaller::ok_pressed() {
}
msg += failed_files[i];
}
- if (EditorNode::get_singleton() != nullptr)
+ if (EditorNode::get_singleton() != nullptr) {
EditorNode::get_singleton()->show_warning(msg);
+ }
} else {
- if (EditorNode::get_singleton() != nullptr)
+ if (EditorNode::get_singleton() != nullptr) {
EditorNode::get_singleton()->show_warning(TTR("Package installed successfully!"), TTR("Success!"));
+ }
}
EditorFileSystem::get_singleton()->scan_changes();
}
diff --git a/editor/editor_atlas_packer.cpp b/editor/editor_atlas_packer.cpp
index 469a6c6de1..68abeb2cda 100644
--- a/editor/editor_atlas_packer.cpp
+++ b/editor/editor_atlas_packer.cpp
@@ -73,10 +73,11 @@ void EditorAtlasPacker::_plot_triangle(Ref<BitMap> p_bitmap, Vector2i *vertices)
}
}
xf += dx_far;
- if (yi < y[1])
+ if (yi < y[1]) {
xt += dx_upper;
- else
+ } else {
xt += dx_low;
+ }
}
}
@@ -158,11 +159,13 @@ void EditorAtlasPacker::chart_pack(Vector<Chart> &charts, int &r_width, int &r_h
for (int lx = x - 1; lx < x + 2 && !found_pixel; lx++) {
for (int ly = y - 1; ly < y + 2 && !found_pixel; ly++) {
int px = lx - 1;
- if (px < 0 || px >= w)
+ if (px < 0 || px >= w) {
continue;
+ }
int py = ly - 1;
- if (py < 0 || py >= h)
+ if (py < 0 || py >= h) {
continue;
+ }
if (src_bitmap->get_bit(Vector2(px, py))) {
found_pixel = true;
diff --git a/editor/editor_audio_buses.cpp b/editor/editor_audio_buses.cpp
index 1114ae9bb5..f8dec13a5c 100644
--- a/editor/editor_audio_buses.cpp
+++ b/editor/editor_audio_buses.cpp
@@ -207,8 +207,9 @@ void EditorAudioBus::update_send() {
}
void EditorAudioBus::update_bus() {
- if (updating_bus)
+ if (updating_bus) {
return;
+ }
updating_bus = true;
@@ -217,8 +218,9 @@ void EditorAudioBus::update_bus() {
float db_value = AudioServer::get_singleton()->get_bus_volume_db(index);
slider->set_value(_scaled_db_to_normalized_volume(db_value));
track_name->set_text(AudioServer::get_singleton()->get_bus_name(index));
- if (is_master)
+ if (is_master) {
track_name->set_editable(false);
+ }
solo->set_pressed(AudioServer::get_singleton()->is_bus_solo(index));
mute->set_pressed(AudioServer::get_singleton()->is_bus_mute(index));
@@ -250,8 +252,9 @@ void EditorAudioBus::update_bus() {
}
void EditorAudioBus::_name_changed(const String &p_new_name) {
- if (p_new_name == AudioServer::get_singleton()->get_bus_name(get_index()))
+ if (p_new_name == AudioServer::get_singleton()->get_bus_name(get_index())) {
return;
+ }
String attempt = p_new_name;
int attempts = 1;
@@ -301,8 +304,9 @@ void EditorAudioBus::_name_changed(const String &p_new_name) {
}
void EditorAudioBus::_volume_changed(float p_normalized) {
- if (updating_bus)
+ if (updating_bus) {
return;
+ }
updating_bus = true;
@@ -454,8 +458,9 @@ void EditorAudioBus::_send_selected(int p_which) {
void EditorAudioBus::_effect_selected() {
TreeItem *effect = effects->get_selected();
- if (!effect)
+ if (!effect) {
return;
+ }
updating_bus = true;
if (effect->get_metadata(0) != Variant()) {
@@ -470,12 +475,14 @@ void EditorAudioBus::_effect_selected() {
}
void EditorAudioBus::_effect_edited() {
- if (updating_bus)
+ if (updating_bus) {
return;
+ }
TreeItem *effect = effects->get_edited();
- if (!effect)
+ if (!effect) {
return;
+ }
if (effect->get_metadata(0) == Variant()) {
Rect2 area = effects->get_item_rect(effect);
@@ -500,8 +507,9 @@ void EditorAudioBus::_effect_edited() {
}
void EditorAudioBus::_effect_add(int p_which) {
- if (updating_bus)
+ if (updating_bus) {
return;
+ }
StringName name = effect_options->get_item_metadata(p_which);
@@ -617,12 +625,14 @@ Variant EditorAudioBus::get_drag_data_fw(const Point2 &p_point, Control *p_from)
bool EditorAudioBus::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
Dictionary d = p_data;
- if (!d.has("type") || String(d["type"]) != "audio_bus_effect")
+ if (!d.has("type") || String(d["type"]) != "audio_bus_effect") {
return false;
+ }
TreeItem *item = effects->get_item_at_position(p_point);
- if (!item)
+ if (!item) {
return false;
+ }
effects->set_drop_mode_flags(Tree::DROP_MODE_INBETWEEN);
@@ -633,8 +643,9 @@ void EditorAudioBus::drop_data_fw(const Point2 &p_point, const Variant &p_data,
Dictionary d = p_data;
TreeItem *item = effects->get_item_at_position(p_point);
- if (!item)
+ if (!item) {
return;
+ }
int pos = effects->get_drop_section_at_position(p_point);
Variant md = item->get_metadata(0);
@@ -644,8 +655,9 @@ void EditorAudioBus::drop_data_fw(const Point2 &p_point, const Variant &p_data,
if (md.get_type() == Variant::INT) {
paste_at = md;
- if (pos > 0)
+ if (pos > 0) {
paste_at++;
+ }
if (bus == get_index() && paste_at > effect) {
paste_at--;
@@ -688,11 +700,13 @@ void EditorAudioBus::drop_data_fw(const Point2 &p_point, const Variant &p_data,
void EditorAudioBus::_delete_effect_pressed(int p_option) {
TreeItem *item = effects->get_selected();
- if (!item)
+ if (!item) {
return;
+ }
- if (item->get_metadata(0).get_type() != Variant::INT)
+ if (item->get_metadata(0).get_type() != Variant::INT) {
return;
+ }
int index = item->get_metadata(0);
@@ -708,11 +722,13 @@ void EditorAudioBus::_delete_effect_pressed(int p_option) {
void EditorAudioBus::_effect_rmb(const Vector2 &p_pos) {
TreeItem *item = effects->get_selected();
- if (!item)
+ if (!item) {
return;
+ }
- if (item->get_metadata(0).get_type() != Variant::INT)
+ if (item->get_metadata(0).get_type() != Variant::INT) {
return;
+ }
delete_effect_popup->set_position(get_global_mouse_position());
delete_effect_popup->popup();
@@ -889,8 +905,9 @@ EditorAudioBus::EditorAudioBus(EditorAudioBuses *p_buses, bool p_is_master) {
ClassDB::get_inheriters_from_class("AudioEffect", &effects);
effects.sort_custom<StringName::AlphCompare>();
for (List<StringName>::Element *E = effects.front(); E; E = E->next()) {
- if (!ClassDB::can_instance(E->get()))
+ if (!ClassDB::can_instance(E->get())) {
continue;
+ }
Ref<Texture2D> icon = EditorNode::get_singleton()->get_class_icon(E->get());
String name = E->get().operator String().replace("AudioEffect", "");
@@ -1031,8 +1048,9 @@ void EditorAudioBuses::_add_bus() {
}
void EditorAudioBuses::_update_bus(int p_index) {
- if (p_index >= bus_hb->get_child_count())
+ if (p_index >= bus_hb->get_child_count()) {
return;
+ }
bus_hb->get_child(p_index)->call("update_bus");
}
diff --git a/editor/editor_autoload_settings.cpp b/editor/editor_autoload_settings.cpp
index 1132cda415..200ae7045f 100644
--- a/editor/editor_autoload_settings.cpp
+++ b/editor/editor_autoload_settings.cpp
@@ -64,23 +64,26 @@ void EditorAutoloadSettings::_notification(int p_what) {
bool EditorAutoloadSettings::_autoload_name_is_valid(const String &p_name, String *r_error) {
if (!p_name.is_valid_identifier()) {
- if (r_error)
+ if (r_error) {
*r_error = TTR("Invalid name.") + "\n" + TTR("Valid characters:") + " a-z, A-Z, 0-9 or _";
+ }
return false;
}
if (ClassDB::class_exists(p_name)) {
- if (r_error)
+ if (r_error) {
*r_error = TTR("Invalid name.") + "\n" + TTR("Must not collide with an existing engine class name.");
+ }
return false;
}
for (int i = 0; i < Variant::VARIANT_MAX; i++) {
if (Variant::get_type_name(Variant::Type(i)) == p_name) {
- if (r_error)
+ if (r_error) {
*r_error = TTR("Invalid name.") + "\n" + TTR("Must not collide with an existing built-in type name.");
+ }
return false;
}
@@ -88,8 +91,9 @@ bool EditorAutoloadSettings::_autoload_name_is_valid(const String &p_name, Strin
for (int i = 0; i < GlobalConstants::get_global_constant_count(); i++) {
if (GlobalConstants::get_global_constant_name(i) == p_name) {
- if (r_error)
+ if (r_error) {
*r_error = TTR("Invalid name.") + "\n" + TTR("Must not collide with an existing global constant name.");
+ }
return false;
}
@@ -100,8 +104,9 @@ bool EditorAutoloadSettings::_autoload_name_is_valid(const String &p_name, Strin
ScriptServer::get_language(i)->get_reserved_words(&keywords);
for (List<String>::Element *E = keywords.front(); E; E = E->next()) {
if (E->get() == p_name) {
- if (r_error)
+ if (r_error) {
*r_error = TTR("Invalid name.") + "\n" + TTR("Keyword cannot be used as an autoload name.");
+ }
return false;
}
@@ -112,8 +117,9 @@ bool EditorAutoloadSettings::_autoload_name_is_valid(const String &p_name, Strin
}
void EditorAutoloadSettings::_autoload_add() {
- if (autoload_add(autoload_add_name->get_text(), autoload_add_path->get_text()))
+ if (autoload_add(autoload_add_name->get_text(), autoload_add_path->get_text())) {
autoload_add_path->set_text("");
+ }
autoload_add_name->set_text("");
add_autoload->set_disabled(true);
@@ -122,15 +128,17 @@ void EditorAutoloadSettings::_autoload_add() {
void EditorAutoloadSettings::_autoload_selected() {
TreeItem *ti = tree->get_selected();
- if (!ti)
+ if (!ti) {
return;
+ }
selected_autoload = "autoload/" + ti->get_text(0);
}
void EditorAutoloadSettings::_autoload_edited() {
- if (updating_autoload)
+ if (updating_autoload) {
return;
+ }
TreeItem *ti = tree->get_edited();
int column = tree->get_edited_column();
@@ -141,8 +149,9 @@ void EditorAutoloadSettings::_autoload_edited() {
String name = ti->get_text(0);
String old_name = selected_autoload.get_slice("/", 1);
- if (name == old_name)
+ if (name == old_name) {
return;
+ }
String error;
if (!_autoload_name_is_valid(name, &error)) {
@@ -192,12 +201,14 @@ void EditorAutoloadSettings::_autoload_edited() {
int order = ProjectSettings::get_singleton()->get_order(base);
String path = ProjectSettings::get_singleton()->get(base);
- if (path.begins_with("*"))
+ if (path.begins_with("*")) {
path = path.substr(1, path.length());
+ }
// Singleton autoloads are represented with a leading "*" in their path.
- if (checked)
+ if (checked) {
path = "*" + path;
+ }
undo_redo->create_action(TTR("Toggle AutoLoad Globals"));
@@ -240,8 +251,9 @@ void EditorAutoloadSettings::_autoload_button_pressed(Object *p_item, int p_colu
swap = ti->get_next();
}
- if (!swap)
+ if (!swap) {
return;
+ }
String swap_name = "autoload/" + swap->get_text(0);
@@ -288,8 +300,9 @@ void EditorAutoloadSettings::_autoload_button_pressed(Object *p_item, int p_colu
void EditorAutoloadSettings::_autoload_activated() {
TreeItem *ti = tree->get_selected();
- if (!ti)
+ if (!ti) {
return;
+ }
_autoload_open(ti->get_text(1));
}
@@ -357,8 +370,9 @@ Node *EditorAutoloadSettings::_create_autoload(const String &p_path) {
}
void EditorAutoloadSettings::update_autoload() {
- if (updating_autoload)
+ if (updating_autoload) {
return;
+ }
updating_autoload = true;
@@ -381,14 +395,16 @@ void EditorAutoloadSettings::update_autoload() {
for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
const PropertyInfo &pi = E->get();
- if (!pi.name.begins_with("autoload/"))
+ if (!pi.name.begins_with("autoload/")) {
continue;
+ }
String name = pi.name.get_slice("/", 1);
String path = ProjectSettings::get_singleton()->get(pi.name);
- if (name.empty())
+ if (name.empty()) {
continue;
+ }
AutoLoadInfo info;
info.is_singleton = path.begins_with("*");
@@ -502,8 +518,9 @@ void EditorAutoloadSettings::update_autoload() {
}
Variant EditorAutoloadSettings::get_drag_data_fw(const Point2 &p_point, Control *p_control) {
- if (autoload_cache.size() <= 1)
+ if (autoload_cache.size() <= 1) {
return false;
+ }
PackedStringArray autoloads;
@@ -514,8 +531,9 @@ Variant EditorAutoloadSettings::get_drag_data_fw(const Point2 &p_point, Control
next = tree->get_next_selected(next);
}
- if (autoloads.size() == 0 || autoloads.size() == autoload_cache.size())
+ if (autoloads.size() == 0 || autoloads.size() == autoload_cache.size()) {
return Variant();
+ }
VBoxContainer *preview = memnew(VBoxContainer);
@@ -539,19 +557,22 @@ Variant EditorAutoloadSettings::get_drag_data_fw(const Point2 &p_point, Control
}
bool EditorAutoloadSettings::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_control) const {
- if (updating_autoload)
+ if (updating_autoload) {
return false;
+ }
Dictionary drop_data = p_data;
- if (!drop_data.has("type"))
+ if (!drop_data.has("type")) {
return false;
+ }
if (drop_data.has("type")) {
TreeItem *ti = tree->get_item_at_position(p_point);
- if (!ti)
+ if (!ti) {
return false;
+ }
int section = tree->get_drop_section_at_position(p_point);
@@ -564,13 +585,15 @@ bool EditorAutoloadSettings::can_drop_data_fw(const Point2 &p_point, const Varia
void EditorAutoloadSettings::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_control) {
TreeItem *ti = tree->get_item_at_position(p_point);
- if (!ti)
+ if (!ti) {
return;
+ }
int section = tree->get_drop_section_at_position(p_point);
- if (section < -1)
+ if (section < -1) {
return;
+ }
String name;
bool move_to_back = false;
@@ -736,14 +759,16 @@ EditorAutoloadSettings::EditorAutoloadSettings() {
for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
const PropertyInfo &pi = E->get();
- if (!pi.name.begins_with("autoload/"))
+ if (!pi.name.begins_with("autoload/")) {
continue;
+ }
String name = pi.name.get_slice("/", 1);
String path = ProjectSettings::get_singleton()->get(pi.name);
- if (name.empty())
+ if (name.empty()) {
continue;
+ }
AutoLoadInfo info;
info.is_singleton = path.begins_with("*");
diff --git a/editor/editor_data.cpp b/editor/editor_data.cpp
index 45c44a3a2b..130c330f5a 100644
--- a/editor/editor_data.cpp
+++ b/editor/editor_data.cpp
@@ -43,16 +43,19 @@ void EditorHistory::cleanup_history() {
bool fail = false;
for (int j = 0; j < history[i].path.size(); j++) {
- if (!history[i].path[j].ref.is_null())
+ if (!history[i].path[j].ref.is_null()) {
continue;
+ }
Object *obj = ObjectDB::get_instance(history[i].path[j].object);
if (obj) {
Node *n = Object::cast_to<Node>(obj);
- if (n && n->is_inside_tree())
+ if (n && n->is_inside_tree()) {
continue;
- if (!n) // Possibly still alive
+ }
+ if (!n) { // Possibly still alive
continue;
+ }
}
if (j <= history[i].level) {
@@ -72,8 +75,9 @@ void EditorHistory::cleanup_history() {
}
}
- if (current >= history.size())
+ if (current >= history.size()) {
current = history.size() - 1;
+ }
}
void EditorHistory::_add_object(ObjectID p_object, const String &p_property, int p_level_change, bool p_inspector_only) {
@@ -81,8 +85,9 @@ void EditorHistory::_add_object(ObjectID p_object, const String &p_property, int
ERR_FAIL_COND(!obj);
Reference *r = Object::cast_to<Reference>(obj);
Obj o;
- if (r)
+ if (r) {
o.ref = REF(r);
+ }
o.object = p_object;
o.property = p_property;
o.inspector_only = p_inspector_only;
@@ -165,10 +170,11 @@ bool EditorHistory::is_at_end() const {
bool EditorHistory::next() {
cleanup_history();
- if ((current + 1) < history.size())
+ if ((current + 1) < history.size()) {
current++;
- else
+ } else {
return false;
+ }
return true;
}
@@ -176,60 +182,68 @@ bool EditorHistory::next() {
bool EditorHistory::previous() {
cleanup_history();
- if (current > 0)
+ if (current > 0) {
current--;
- else
+ } else {
return false;
+ }
return true;
}
bool EditorHistory::is_current_inspector_only() const {
- if (current < 0 || current >= history.size())
+ if (current < 0 || current >= history.size()) {
return false;
+ }
const History &h = history[current];
return h.path[h.level].inspector_only;
}
ObjectID EditorHistory::get_current() {
- if (current < 0 || current >= history.size())
+ if (current < 0 || current >= history.size()) {
return ObjectID();
+ }
History &h = history.write[current];
Object *obj = ObjectDB::get_instance(h.path[h.level].object);
- if (!obj)
+ if (!obj) {
return ObjectID();
+ }
return obj->get_instance_id();
}
int EditorHistory::get_path_size() const {
- if (current < 0 || current >= history.size())
+ if (current < 0 || current >= history.size()) {
return 0;
+ }
const History &h = history[current];
return h.path.size();
}
ObjectID EditorHistory::get_path_object(int p_index) const {
- if (current < 0 || current >= history.size())
+ if (current < 0 || current >= history.size()) {
return ObjectID();
+ }
const History &h = history[current];
ERR_FAIL_INDEX_V(p_index, h.path.size(), ObjectID());
Object *obj = ObjectDB::get_instance(h.path[p_index].object);
- if (!obj)
+ if (!obj) {
return ObjectID();
+ }
return obj->get_instance_id();
}
String EditorHistory::get_path_property(int p_index) const {
- if (current < 0 || current >= history.size())
+ if (current < 0 || current >= history.size()) {
return "";
+ }
const History &h = history[current];
@@ -249,8 +263,9 @@ EditorHistory::EditorHistory() {
EditorPlugin *EditorData::get_editor(Object *p_object) {
for (int i = 0; i < editor_plugins.size(); i++) {
- if (editor_plugins[i]->has_main_screen() && editor_plugins[i]->handles(p_object))
+ if (editor_plugins[i]->has_main_screen() && editor_plugins[i]->handles(p_object)) {
return editor_plugins[i];
+ }
}
return nullptr;
@@ -258,8 +273,9 @@ EditorPlugin *EditorData::get_editor(Object *p_object) {
EditorPlugin *EditorData::get_subeditor(Object *p_object) {
for (int i = 0; i < editor_plugins.size(); i++) {
- if (!editor_plugins[i]->has_main_screen() && editor_plugins[i]->handles(p_object))
+ if (!editor_plugins[i]->has_main_screen() && editor_plugins[i]->handles(p_object)) {
return editor_plugins[i];
+ }
}
return nullptr;
@@ -277,8 +293,9 @@ Vector<EditorPlugin *> EditorData::get_subeditors(Object *p_object) {
EditorPlugin *EditorData::get_editor(String p_name) {
for (int i = 0; i < editor_plugins.size(); i++) {
- if (editor_plugins[i]->get_name() == p_name)
+ if (editor_plugins[i]->get_name() == p_name) {
return editor_plugins[i];
+ }
}
return nullptr;
@@ -291,8 +308,9 @@ void EditorData::copy_object_params(Object *p_object) {
p_object->get_property_list(&pinfo);
for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
- if (!(E->get().usage & PROPERTY_USAGE_EDITOR) || E->get().name == "script" || E->get().name == "scripts")
+ if (!(E->get().usage & PROPERTY_USAGE_EDITOR) || E->get().name == "script" || E->get().name == "scripts") {
continue;
+ }
PropertyData pd;
pd.name = E->get().name;
@@ -311,8 +329,9 @@ Dictionary EditorData::get_editor_states() const {
Dictionary metadata;
for (int i = 0; i < editor_plugins.size(); i++) {
Dictionary state = editor_plugins[i]->get_state();
- if (state.empty())
+ if (state.empty()) {
continue;
+ }
metadata[editor_plugins[i]->get_name()] = state;
}
@@ -340,8 +359,9 @@ void EditorData::set_editor_states(const Dictionary &p_states) {
}
}
- if (idx == -1)
+ if (idx == -1) {
continue;
+ }
editor_plugins[idx]->set_state(p_states[name]);
}
}
@@ -481,8 +501,9 @@ void EditorData::remove_custom_type(const String &p_type) {
}
int EditorData::add_edited_scene(int p_at_pos) {
- if (p_at_pos < 0)
+ if (p_at_pos < 0) {
p_at_pos = edited_scene.size();
+ }
EditedScene es;
es.root = nullptr;
es.path = String();
@@ -490,13 +511,15 @@ int EditorData::add_edited_scene(int p_at_pos) {
es.version = 0;
es.live_edit_root = NodePath(String("/root"));
- if (p_at_pos == edited_scene.size())
+ if (p_at_pos == edited_scene.size()) {
edited_scene.push_back(es);
- else
+ } else {
edited_scene.insert(p_at_pos, es);
+ }
- if (current_edited_scene < 0)
+ if (current_edited_scene < 0) {
current_edited_scene = 0;
+ }
return p_at_pos;
}
@@ -516,9 +539,9 @@ void EditorData::remove_scene(int p_idx) {
memdelete(edited_scene[p_idx].root);
}
- if (current_edited_scene > p_idx)
+ if (current_edited_scene > p_idx) {
current_edited_scene--;
- else if (current_edited_scene == p_idx && current_edited_scene > 0) {
+ } else if (current_edited_scene == p_idx && current_edited_scene > 0) {
current_edited_scene--;
}
@@ -554,8 +577,9 @@ bool EditorData::_find_updated_instances(Node *p_root, Node *p_node, Set<String>
for (int i = 0; i < p_node->get_child_count(); i++) {
bool found = _find_updated_instances(p_root, p_node->get_child(i), checked_paths);
- if (found)
+ if (found) {
return true;
+ }
}
return false;
@@ -563,8 +587,9 @@ bool EditorData::_find_updated_instances(Node *p_root, Node *p_node, Set<String>
bool EditorData::check_and_update_scene(int p_idx) {
ERR_FAIL_INDEX_V(p_idx, edited_scene.size(), false);
- if (!edited_scene[p_idx].root)
+ if (!edited_scene[p_idx].root) {
return false;
+ }
Set<String> checked_scenes;
@@ -588,16 +613,18 @@ bool EditorData::check_and_update_scene(int p_idx) {
for (List<Node *>::Element *E = edited_scene.write[p_idx].selection.front(); E; E = E->next()) {
NodePath p = edited_scene[p_idx].root->get_path_to(E->get());
Node *new_node = new_scene->get_node(p);
- if (new_node)
+ if (new_node) {
new_selection.push_back(new_node);
+ }
}
new_scene->set_filename(edited_scene[p_idx].root->get_filename());
memdelete(edited_scene[p_idx].root);
edited_scene.write[p_idx].root = new_scene;
- if (new_scene->get_filename() != "")
+ if (new_scene->get_filename() != "") {
edited_scene.write[p_idx].path = new_scene->get_filename();
+ }
edited_scene.write[p_idx].selection = new_selection;
return true;
@@ -630,10 +657,11 @@ void EditorData::set_edited_scene_root(Node *p_root) {
ERR_FAIL_INDEX(current_edited_scene, edited_scene.size());
edited_scene.write[current_edited_scene].root = p_root;
if (p_root) {
- if (p_root->get_filename() != "")
+ if (p_root->get_filename() != "") {
edited_scene.write[current_edited_scene].path = p_root->get_filename();
- else
+ } else {
p_root->set_filename(edited_scene[current_edited_scene].path);
+ }
}
}
@@ -673,8 +701,9 @@ uint64_t EditorData::get_scene_version(int p_idx) const {
String EditorData::get_scene_type(int p_idx) const {
ERR_FAIL_INDEX_V(p_idx, edited_scene.size(), String());
- if (!edited_scene[p_idx].root)
+ if (!edited_scene[p_idx].root) {
return "";
+ }
return edited_scene[p_idx].root->get_class();
}
@@ -690,8 +719,9 @@ void EditorData::move_edited_scene_to_index(int p_idx) {
Ref<Script> EditorData::get_scene_root_script(int p_idx) const {
ERR_FAIL_INDEX_V(p_idx, edited_scene.size(), Ref<Script>());
- if (!edited_scene[p_idx].root)
+ if (!edited_scene[p_idx].root) {
return Ref<Script>();
+ }
Ref<Script> s = edited_scene[p_idx].root->get_script();
if (!s.is_valid() && edited_scene[p_idx].root->get_child_count()) {
Node *n = edited_scene[p_idx].root->get_child(0);
@@ -705,10 +735,12 @@ Ref<Script> EditorData::get_scene_root_script(int p_idx) const {
String EditorData::get_scene_title(int p_idx) const {
ERR_FAIL_INDEX_V(p_idx, edited_scene.size(), String());
- if (!edited_scene[p_idx].root)
+ if (!edited_scene[p_idx].root) {
return TTR("[empty]");
- if (edited_scene[p_idx].root->get_filename() == "")
+ }
+ if (edited_scene[p_idx].root->get_filename() == "") {
return TTR("[unsaved]");
+ }
bool show_ext = EDITOR_DEF("interface/scene_tabs/show_extension", false);
String name = edited_scene[p_idx].root->get_filename().get_file();
if (!show_ext) {
@@ -721,8 +753,9 @@ void EditorData::set_scene_path(int p_idx, const String &p_path) {
ERR_FAIL_INDEX(p_idx, edited_scene.size());
edited_scene.write[p_idx].path = p_path;
- if (!edited_scene[p_idx].root)
+ if (!edited_scene[p_idx].root) {
return;
+ }
edited_scene[p_idx].root->set_filename(p_path);
}
@@ -730,10 +763,11 @@ String EditorData::get_scene_path(int p_idx) const {
ERR_FAIL_INDEX_V(p_idx, edited_scene.size(), String());
if (edited_scene[p_idx].root) {
- if (edited_scene[p_idx].root->get_filename() == "")
+ if (edited_scene[p_idx].root->get_filename() == "") {
edited_scene[p_idx].root->set_filename(edited_scene[p_idx].path);
- else
+ } else {
return edited_scene[p_idx].root->get_filename();
+ }
}
return edited_scene[p_idx].path;
@@ -801,8 +835,9 @@ void EditorData::get_plugin_window_layout(Ref<ConfigFile> p_layout) {
}
bool EditorData::script_class_is_parent(const String &p_class, const String &p_inherits) {
- if (!ScriptServer::is_global_class(p_class))
+ if (!ScriptServer::is_global_class(p_class)) {
return false;
+ }
String base = script_class_get_base(p_class);
Ref<Script> script = script_class_load_script(p_class);
Ref<Script> base_script = script->get_base_script();
@@ -823,8 +858,9 @@ bool EditorData::script_class_is_parent(const String &p_class, const String &p_i
StringName EditorData::script_class_get_base(const String &p_class) const {
Ref<Script> script = script_class_load_script(p_class);
- if (script.is_null())
+ if (script.is_null()) {
return StringName();
+ }
Ref<Script> base_script = script->get_base_script();
if (base_script.is_null()) {
@@ -839,8 +875,9 @@ Object *EditorData::script_class_instance(const String &p_class) {
Object *obj = ClassDB::instance(ScriptServer::get_global_class_native_base(p_class));
if (obj) {
Ref<Script> script = script_class_load_script(p_class);
- if (script.is_valid())
+ if (script.is_valid()) {
obj->set_script(script);
+ }
return obj;
}
}
@@ -848,8 +885,9 @@ Object *EditorData::script_class_instance(const String &p_class) {
}
Ref<Script> EditorData::script_class_load_script(const String &p_class) const {
- if (!ScriptServer::is_global_class(p_class))
+ if (!ScriptServer::is_global_class(p_class)) {
return Ref<Script>();
+ }
String path = ScriptServer::get_global_class_path(p_class);
return ResourceLoader::load(path, "Script");
@@ -860,15 +898,17 @@ void EditorData::script_class_set_icon_path(const String &p_class, const String
}
String EditorData::script_class_get_icon_path(const String &p_class) const {
- if (!ScriptServer::is_global_class(p_class))
+ if (!ScriptServer::is_global_class(p_class)) {
return String();
+ }
String current = p_class;
String ret = _script_class_icon_paths[current];
while (ret.empty()) {
current = script_class_get_base(current);
- if (!ScriptServer::is_global_class(current))
+ if (!ScriptServer::is_global_class(current)) {
return String();
+ }
ret = _script_class_icon_paths.has(current) ? _script_class_icon_paths[current] : String();
}
@@ -889,8 +929,9 @@ void EditorData::script_class_save_icon_paths() {
Dictionary d;
for (List<StringName>::Element *E = keys.front(); E; E = E->next()) {
- if (ScriptServer::is_global_class(E->get()))
+ if (ScriptServer::is_global_class(E->get())) {
d[E->get()] = _script_class_icon_paths[E->get()];
+ }
}
ProjectSettings::get_singleton()->set("_global_script_class_icons", d);
@@ -924,12 +965,14 @@ EditorData::EditorData() {
///////////
void EditorSelection::_node_removed(Node *p_node) {
- if (!selection.has(p_node))
+ if (!selection.has(p_node)) {
return;
+ }
Object *meta = selection[p_node];
- if (meta)
+ if (meta) {
memdelete(meta);
+ }
selection.erase(p_node);
changed = true;
nl_changed = true;
@@ -938,8 +981,9 @@ void EditorSelection::_node_removed(Node *p_node) {
void EditorSelection::add_node(Node *p_node) {
ERR_FAIL_NULL(p_node);
ERR_FAIL_COND(!p_node->is_inside_tree());
- if (selection.has(p_node))
+ if (selection.has(p_node)) {
return;
+ }
changed = true;
nl_changed = true;
@@ -960,14 +1004,16 @@ void EditorSelection::add_node(Node *p_node) {
void EditorSelection::remove_node(Node *p_node) {
ERR_FAIL_NULL(p_node);
- if (!selection.has(p_node))
+ if (!selection.has(p_node)) {
return;
+ }
changed = true;
nl_changed = true;
Object *meta = selection[p_node];
- if (meta)
+ if (meta) {
memdelete(meta);
+ }
selection.erase(p_node);
p_node->disconnect("tree_exiting", callable_mp(this, &EditorSelection::_node_removed));
//emit_signal("selection_changed");
@@ -1012,8 +1058,9 @@ void EditorSelection::add_editor_plugin(Object *p_object) {
}
void EditorSelection::_update_nl() {
- if (!nl_changed)
+ if (!nl_changed) {
return;
+ }
selected_node_list.clear();
@@ -1029,8 +1076,9 @@ void EditorSelection::_update_nl() {
parent = parent->get_parent();
}
- if (skip)
+ if (skip) {
continue;
+ }
selected_node_list.push_back(E->key());
}
@@ -1040,8 +1088,9 @@ void EditorSelection::_update_nl() {
void EditorSelection::update() {
_update_nl();
- if (!changed)
+ if (!changed) {
return;
+ }
changed = false;
if (!emitted) {
emitted = true;
@@ -1055,10 +1104,11 @@ void EditorSelection::_emit_change() {
}
List<Node *> &EditorSelection::get_selected_node_list() {
- if (changed)
+ if (changed) {
update();
- else
+ } else {
_update_nl();
+ }
return selected_node_list;
}
diff --git a/editor/editor_data.h b/editor/editor_data.h
index 1dd2214e53..8083dde09c 100644
--- a/editor/editor_data.h
+++ b/editor/editor_data.h
@@ -256,8 +256,9 @@ public:
template <class T>
T *get_node_editor_data(Node *p_node) {
- if (!selection.has(p_node))
+ if (!selection.has(p_node)) {
return nullptr;
+ }
return Object::cast_to<T>(selection[p_node]);
}
diff --git a/editor/editor_dir_dialog.cpp b/editor/editor_dir_dialog.cpp
index 3039c3adb5..3c1c3c8a86 100644
--- a/editor/editor_dir_dialog.cpp
+++ b/editor/editor_dir_dialog.cpp
@@ -107,13 +107,15 @@ void EditorDirDialog::_notification(int p_what) {
void EditorDirDialog::_item_collapsed(Object *p_item) {
TreeItem *item = Object::cast_to<TreeItem>(p_item);
- if (updating)
+ if (updating) {
return;
+ }
- if (item->is_collapsed())
+ if (item->is_collapsed()) {
opened_paths.erase(item->get_metadata(0));
- else
+ } else {
opened_paths.insert(item->get_metadata(0));
+ }
}
void EditorDirDialog::_item_activated() {
@@ -122,8 +124,9 @@ void EditorDirDialog::_item_activated() {
void EditorDirDialog::ok_pressed() {
TreeItem *ti = tree->get_selected();
- if (!ti)
+ if (!ti) {
return;
+ }
String dir = ti->get_metadata(0);
emit_signal("dir_selected", dir);
@@ -144,8 +147,9 @@ void EditorDirDialog::_make_dir() {
void EditorDirDialog::_make_dir_confirm() {
TreeItem *ti = tree->get_selected();
- if (!ti)
+ if (!ti) {
return;
+ }
String dir = ti->get_metadata(0);
diff --git a/editor/editor_export.cpp b/editor/editor_export.cpp
index 46740a0f6d..87ca499413 100644
--- a/editor/editor_export.cpp
+++ b/editor/editor_export.cpp
@@ -173,10 +173,11 @@ bool EditorExportPreset::has_export_file(const String &p_path) {
}
void EditorExportPreset::add_patch(const String &p_path, int p_at_pos) {
- if (p_at_pos < 0)
+ if (p_at_pos < 0) {
patches.push_back(p_path);
- else
+ } else {
patches.insert(p_at_pos, p_path);
+ }
EditorExport::singleton->save_presets();
}
@@ -233,8 +234,9 @@ void EditorExportPlatform::gen_debug_flags(Vector<String> &r_flags, int p_flags)
String host = EditorSettings::get_singleton()->get("network/debug/remote_host");
int remote_port = (int)EditorSettings::get_singleton()->get("network/debug/remote_port");
- if (p_flags & DEBUG_FLAG_REMOTE_DEBUG_LOCALHOST)
+ if (p_flags & DEBUG_FLAG_REMOTE_DEBUG_LOCALHOST) {
host = "localhost";
+ }
if (p_flags & DEBUG_FLAG_DUMB_CLIENT) {
int port = EditorSettings::get_singleton()->get("filesystem/file_server/port");
@@ -260,8 +262,9 @@ void EditorExportPlatform::gen_debug_flags(Vector<String> &r_flags, int p_flags)
String bpoints;
for (const List<String>::Element *E = breakpoints.front(); E; E = E->next()) {
bpoints += E->get().replace(" ", "%20");
- if (E->next())
+ if (E->next()) {
bpoints += ",";
+ }
}
r_flags.push_back(bpoints);
@@ -389,16 +392,18 @@ void EditorExportPlatform::_export_find_resources(EditorFileSystemDirectory *p_d
}
void EditorExportPlatform::_export_find_dependencies(const String &p_path, Set<String> &p_paths) {
- if (p_paths.has(p_path))
+ if (p_paths.has(p_path)) {
return;
+ }
p_paths.insert(p_path);
EditorFileSystemDirectory *dir;
int file_idx;
dir = EditorFileSystem::get_singleton()->find_file(p_path, &file_idx);
- if (!dir)
+ if (!dir) {
return;
+ }
Vector<String> deps = dir->get_file_deps(file_idx);
@@ -410,16 +415,17 @@ void EditorExportPlatform::_export_find_dependencies(const String &p_path, Set<S
void EditorExportPlatform::_edit_files_with_filter(DirAccess *da, const Vector<String> &p_filters, Set<String> &r_list, bool exclude) {
da->list_dir_begin();
String cur_dir = da->get_current_dir().replace("\\", "/");
- if (!cur_dir.ends_with("/"))
+ if (!cur_dir.ends_with("/")) {
cur_dir += "/";
+ }
String cur_dir_no_prefix = cur_dir.replace("res://", "");
Vector<String> dirs;
String f;
while ((f = da->get_next()) != "") {
- if (da->current_is_dir())
+ if (da->current_is_dir()) {
dirs.push_back(f);
- else {
+ } else {
String fullpath = cur_dir + f;
// Test also against path without res:// so that filters like `file.txt` can work.
String fullpath_no_prefix = cur_dir_no_prefix + f;
@@ -439,8 +445,9 @@ void EditorExportPlatform::_edit_files_with_filter(DirAccess *da, const Vector<S
for (int i = 0; i < dirs.size(); ++i) {
String dir = dirs[i];
- if (dir.begins_with("."))
+ if (dir.begins_with(".")) {
continue;
+ }
da->change_dir(dir);
_edit_files_with_filter(da, p_filters, r_list, exclude);
da->change_dir("..");
@@ -448,14 +455,16 @@ void EditorExportPlatform::_edit_files_with_filter(DirAccess *da, const Vector<S
}
void EditorExportPlatform::_edit_filter_list(Set<String> &r_list, const String &p_filter, bool exclude) {
- if (p_filter == "")
+ if (p_filter == "") {
return;
+ }
Vector<String> split = p_filter.split(",");
Vector<String> filters;
for (int i = 0; i < split.size(); i++) {
String f = split[i].strip_edges();
- if (f.empty())
+ if (f.empty()) {
continue;
+ }
filters.push_back(f);
}
@@ -649,8 +658,9 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &
Vector<String> files = p_preset->get_files_to_export();
for (int i = 0; i < files.size(); i++) {
- if (scenes_only && ResourceLoader::get_resource_type(files[i]) != "PackedScene")
+ if (scenes_only && ResourceLoader::get_resource_type(files[i]) != "PackedScene") {
continue;
+ }
_export_find_dependencies(files[i], paths);
}
@@ -777,8 +787,9 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &
}
export_plugins.write[i]->_clear();
- if (!do_export)
+ if (!do_export) {
break; //apologies, not exporting
+ }
}
//just store it as it comes
if (do_export) {
@@ -976,8 +987,9 @@ Error EditorExportPlatform::save_pack(const Ref<EditorExportPreset> &p_preset, c
while (true) {
int got = ftmp->get_buffer(buf, bufsize);
- if (got <= 0)
+ if (got <= 0) {
break;
+ }
f->store_buffer(buf, got);
}
@@ -1018,8 +1030,9 @@ Error EditorExportPlatform::save_zip(const Ref<EditorExportPreset> &p_preset, co
zd.zip = zip;
Error err = export_project_files(p_preset, _save_zip_file, &zd);
- if (err != OK && err != ERR_SKIP)
+ if (err != OK && err != ERR_SKIP) {
ERR_PRINT("Failed to export project files");
+ }
zipClose(zip, nullptr);
@@ -1040,8 +1053,9 @@ void EditorExportPlatform::gen_export_flags(Vector<String> &r_flags, int p_flags
String host = EditorSettings::get_singleton()->get("network/debug/remote_host");
int remote_port = (int)EditorSettings::get_singleton()->get("network/debug/remote_port");
- if (p_flags & DEBUG_FLAG_REMOTE_DEBUG_LOCALHOST)
+ if (p_flags & DEBUG_FLAG_REMOTE_DEBUG_LOCALHOST) {
host = "localhost";
+ }
if (p_flags & DEBUG_FLAG_DUMB_CLIENT) {
int port = EditorSettings::get_singleton()->get("filesystem/file_server/port");
@@ -1067,8 +1081,9 @@ void EditorExportPlatform::gen_export_flags(Vector<String> &r_flags, int p_flags
String bpoints;
for (const List<String>::Element *E = breakpoints.front(); E; E = E->next()) {
bpoints += E->get().replace(" ", "%20");
- if (E->next())
+ if (E->next()) {
bpoints += ",";
+ }
}
r_flags.push_back(bpoints);
@@ -1140,8 +1155,9 @@ void EditorExport::_save() {
}
void EditorExport::save_presets() {
- if (block_save)
+ if (block_save) {
return;
+ }
save_timer->start();
}
@@ -1163,10 +1179,11 @@ Ref<EditorExportPlatform> EditorExport::get_export_platform(int p_idx) {
}
void EditorExport::add_export_preset(const Ref<EditorExportPreset> &p_preset, int p_at_pos) {
- if (p_at_pos < 0)
+ if (p_at_pos < 0) {
export_presets.push_back(p_preset);
- else
+ } else {
export_presets.insert(p_at_pos, p_preset);
+ }
}
String EditorExportPlatform::test_etc2() const {
@@ -1221,16 +1238,18 @@ void EditorExport::load_config() {
Ref<ConfigFile> config;
config.instance();
Error err = config->load("res://export_presets.cfg");
- if (err != OK)
+ if (err != OK) {
return;
+ }
block_save = true;
int index = 0;
while (true) {
String section = "preset." + itos(index);
- if (!config->has_section(section))
+ if (!config->has_section(section)) {
break;
+ }
String platform = config->get_value(section, "platform");
@@ -1408,8 +1427,9 @@ bool EditorExportPlatformPC::can_export(const Ref<EditorExportPreset> &p_preset,
valid = dvalid || rvalid;
r_missing_templates = !valid;
- if (!err.empty())
+ if (!err.empty()) {
r_error = err;
+ }
return valid;
}
@@ -1597,8 +1617,9 @@ void EditorExportTextSceneToBinaryPlugin::_export_file(const String &p_path, con
}
bool convert = GLOBAL_GET("editor/convert_text_resources_to_binary_on_export");
- if (!convert)
+ if (!convert) {
return;
+ }
String tmp_path = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmpfile.res");
Error err = ResourceFormatLoaderText::convert_file_to_binary(p_path, tmp_path);
if (err != OK) {
diff --git a/editor/editor_feature_profile.cpp b/editor/editor_feature_profile.cpp
index f8c1c490d5..d3749477cc 100644
--- a/editor/editor_feature_profile.cpp
+++ b/editor/editor_feature_profile.cpp
@@ -504,8 +504,9 @@ void EditorFeatureProfileManager::_fill_classes_from(TreeItem *p_parent, const S
}
void EditorFeatureProfileManager::_class_list_item_selected() {
- if (updating_features)
+ if (updating_features) {
return;
+ }
property_list->clear();
@@ -549,8 +550,9 @@ void EditorFeatureProfileManager::_class_list_item_selected() {
for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
String name = E->get().name;
- if (!(E->get().usage & PROPERTY_USAGE_EDITOR))
+ if (!(E->get().usage & PROPERTY_USAGE_EDITOR)) {
continue;
+ }
TreeItem *property = property_list->create_item(properties);
property->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
property->set_editable(0, true);
@@ -566,8 +568,9 @@ void EditorFeatureProfileManager::_class_list_item_selected() {
}
void EditorFeatureProfileManager::_class_list_item_edited() {
- if (updating_features)
+ if (updating_features) {
return;
+ }
TreeItem *item = class_list->get_edited();
if (!item) {
@@ -590,8 +593,9 @@ void EditorFeatureProfileManager::_class_list_item_edited() {
}
void EditorFeatureProfileManager::_property_item_edited() {
- if (updating_features)
+ if (updating_features) {
return;
+ }
TreeItem *class_item = class_list->get_selected();
if (!class_item) {
diff --git a/editor/editor_file_dialog.cpp b/editor/editor_file_dialog.cpp
index 3b1c4d380a..5ae5d1cb31 100644
--- a/editor/editor_file_dialog.cpp
+++ b/editor/editor_file_dialog.cpp
@@ -74,8 +74,9 @@ void EditorFileDialog::_notification(int p_what) {
preview_wheel_timeout -= get_process_delta_time();
if (preview_wheel_timeout <= 0) {
preview_wheel_index++;
- if (preview_wheel_index >= 8)
+ if (preview_wheel_index >= 8) {
preview_wheel_index = 0;
+ }
Ref<Texture2D> frame = item_list->get_theme_icon("Progress" + itos(preview_wheel_index + 1), "EditorIcons");
preview->set_texture(frame);
preview_wheel_timeout = 0.1;
@@ -84,8 +85,9 @@ void EditorFileDialog::_notification(int p_what) {
} else if (p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) {
bool is_showing_hidden = EditorSettings::get_singleton()->get("filesystem/file_dialog/show_hidden_files");
- if (show_hidden_files != is_showing_hidden)
+ if (show_hidden_files != is_showing_hidden) {
set_show_hidden_files(is_showing_hidden);
+ }
set_display_mode((DisplayMode)EditorSettings::get_singleton()->get("filesystem/file_dialog/display_mode").operator int());
// update icons
@@ -184,8 +186,9 @@ void EditorFileDialog::set_enable_multiple_selection(bool p_enable) {
Vector<String> EditorFileDialog::get_selected_files() const {
Vector<String> list;
for (int i = 0; i < item_list->get_item_count(); i++) {
- if (item_list->is_selected(i))
+ if (item_list->is_selected(i)) {
list.push_back(item_list->get_item_text(i));
+ }
}
return list;
};
@@ -238,10 +241,11 @@ void EditorFileDialog::_post_popup() {
update_file_list();
invalidated = false;
}
- if (mode == FILE_MODE_SAVE_FILE)
+ if (mode == FILE_MODE_SAVE_FILE) {
file->grab_focus();
- else
+ } else {
item_list->grab_focus();
+ }
if (mode == FILE_MODE_OPEN_DIR) {
file_box->set_visible(false);
@@ -249,8 +253,9 @@ void EditorFileDialog::_post_popup() {
file_box->set_visible(true);
}
- if (is_visible() && get_current_file() != "")
+ if (is_visible() && get_current_file() != "") {
_request_single_thumbnail(get_current_dir().plus_file(get_current_file()));
+ }
if (is_visible()) {
Ref<Texture2D> folder = item_list->get_theme_icon("folder", "FileDialog");
@@ -261,8 +266,9 @@ void EditorFileDialog::_post_popup() {
Vector<String> recentd = EditorSettings::get_singleton()->get_recent_dirs();
for (int i = 0; i < recentd.size(); i++) {
bool cres = recentd[i].begins_with("res://");
- if (cres != res)
+ if (cres != res) {
continue;
+ }
String name = recentd[i];
if (res && name == "res://") {
name = "/";
@@ -286,8 +292,9 @@ void EditorFileDialog::_post_popup() {
}
void EditorFileDialog::_thumbnail_result(const String &p_path, const Ref<Texture2D> &p_preview, const Ref<Texture2D> &p_small_preview, const Variant &p_udata) {
- if (display_mode == DISPLAY_LIST || p_preview.is_null())
+ if (display_mode == DISPLAY_LIST || p_preview.is_null()) {
return;
+ }
for (int i = 0; i < item_list->get_item_count(); i++) {
Dictionary d = item_list->get_item_metadata(i);
@@ -318,8 +325,9 @@ void EditorFileDialog::_thumbnail_done(const String &p_path, const Ref<Texture2D
}
void EditorFileDialog::_request_single_thumbnail(const String &p_path) {
- if (!FileAccess::exists(p_path))
+ if (!FileAccess::exists(p_path)) {
return;
+ }
set_process(true);
preview_waiting = true;
@@ -333,8 +341,9 @@ void EditorFileDialog::_action_pressed() {
Vector<String> files;
for (int i = 0; i < item_list->get_item_count(); i++) {
- if (item_list->is_selected(i))
+ if (item_list->is_selected(i)) {
files.push_back(fbase.plus_file(item_list->get_item_text(i)));
+ }
}
if (files.size()) {
@@ -389,13 +398,15 @@ void EditorFileDialog::_action_pressed() {
break;
}
}
- if (valid)
+ if (valid) {
break;
+ }
}
} else {
int idx = filter->get_selected();
- if (filters.size() > 1)
+ if (filters.size() > 1) {
idx--;
+ }
if (idx >= 0 && idx < filters.size()) {
String flt = filters[idx].get_slice(";", 0);
int filterSliceCount = flt.get_slice_count(",");
@@ -443,8 +454,9 @@ void EditorFileDialog::_cancel_pressed() {
void EditorFileDialog::_item_selected(int p_item) {
int current = p_item;
- if (current < 0 || current >= item_list->get_item_count())
+ if (current < 0 || current >= item_list->get_item_count()) {
return;
+ }
Dictionary d = item_list->get_item_metadata(current);
@@ -460,8 +472,9 @@ void EditorFileDialog::_item_selected(int p_item) {
void EditorFileDialog::_multi_selected(int p_item, bool p_selected) {
int current = p_item;
- if (current < 0 || current >= item_list->get_item_count())
+ if (current < 0 || current >= item_list->get_item_count()) {
return;
+ }
Dictionary d = item_list->get_item_metadata(current);
@@ -509,8 +522,9 @@ void EditorFileDialog::_push_history() {
void EditorFileDialog::_item_dc_selected(int p_item) {
int current = p_item;
- if (current < 0 || current >= item_list->get_item_count())
+ if (current < 0 || current >= item_list->get_item_count()) {
return;
+ }
Dictionary d = item_list->get_item_metadata(current);
@@ -625,18 +639,21 @@ void EditorFileDialog::_item_menu_id_pressed(int p_option) {
}
bool EditorFileDialog::_is_open_should_be_disabled() {
- if (mode == FILE_MODE_OPEN_ANY || mode == FILE_MODE_SAVE_FILE)
+ if (mode == FILE_MODE_OPEN_ANY || mode == FILE_MODE_SAVE_FILE) {
return false;
+ }
Vector<int> items = item_list->get_selected_items();
- if (items.size() == 0)
+ if (items.size() == 0) {
return mode != FILE_MODE_OPEN_DIR; // In "Open folder" mode, having nothing selected picks the current folder.
+ }
for (int i = 0; i < items.size(); i++) {
Dictionary d = item_list->get_item_metadata(items.get(i));
- if (((mode == FILE_MODE_OPEN_FILE || mode == FILE_MODE_OPEN_FILES) && d["dir"]) || (mode == FILE_MODE_OPEN_DIR && !d["dir"]))
+ if (((mode == FILE_MODE_OPEN_FILE || mode == FILE_MODE_OPEN_FILES) && d["dir"]) || (mode == FILE_MODE_OPEN_DIR && !d["dir"])) {
return true;
+ }
}
return false;
@@ -645,8 +662,9 @@ bool EditorFileDialog::_is_open_should_be_disabled() {
void EditorFileDialog::update_file_name() {
int idx = filter->get_selected() - 1;
if ((idx == -1 && filter->get_item_count() == 2) || (filter->get_item_count() > 2 && idx >= 0 && idx < filter->get_item_count() - 2)) {
- if (idx == -1)
+ if (idx == -1) {
idx += 1;
+ }
String filter_str = filters[idx];
String file_str = file->get_text();
String base_name = file_str.get_basename();
@@ -695,8 +713,9 @@ void EditorFileDialog::update_file_list() {
item_list->set_max_text_lines(1);
item_list->set_fixed_column_width(0);
item_list->set_fixed_icon_size(Size2());
- if (preview->get_texture().is_valid())
+ if (preview->get_texture().is_valid()) {
preview_vb->show();
+ }
}
String cdir = dir_access->get_current_dir();
@@ -711,14 +730,16 @@ void EditorFileDialog::update_file_list() {
String item;
while ((item = dir_access->get_next()) != "") {
- if (item == "." || item == "..")
+ if (item == "." || item == "..") {
continue;
+ }
if (show_hidden_files || !dir_access->current_is_hidden()) {
- if (!dir_access->current_is_dir())
+ if (!dir_access->current_is_dir()) {
files.push_back(item);
- else
+ } else {
dirs.push_back(item);
+ }
}
}
@@ -761,8 +782,9 @@ void EditorFileDialog::update_file_list() {
}
} else {
int idx = filter->get_selected();
- if (filters.size() > 1)
+ if (filters.size() > 1) {
idx--;
+ }
if (idx >= 0 && idx < filters.size()) {
String f = filters[idx].get_slice(";", 0);
@@ -806,8 +828,9 @@ void EditorFileDialog::update_file_list() {
EditorResourcePreview::get_singleton()->queue_resource_preview(fullpath, this, "_thumbnail_result", fullpath);
}
- if (file->get_text() == files.front()->get())
+ if (file->get_text() == files.front()->get()) {
item_list->set_current(item_list->get_item_count() - 1);
+ }
}
files.pop_front();
@@ -851,23 +874,26 @@ void EditorFileDialog::update_filters() {
for (int i = 0; i < MIN(max_filters, filters.size()); i++) {
String flt = filters[i].get_slice(";", 0).strip_edges();
- if (i > 0)
+ if (i > 0) {
all_filters += ", ";
+ }
all_filters += flt;
}
- if (max_filters < filters.size())
+ if (max_filters < filters.size()) {
all_filters += ", ...";
+ }
filter->add_item(TTR("All Recognized") + " (" + all_filters + ")");
}
for (int i = 0; i < filters.size(); i++) {
String flt = filters[i].get_slice(";", 0).strip_edges();
String desc = filters[i].get_slice(";", 1).strip_edges();
- if (desc.length())
+ if (desc.length()) {
filter->add_item(desc + " (" + flt + ")");
- else
+ } else {
filter->add_item("(" + flt + ")");
+ }
}
filter->add_item(TTR("All Files (*)"));
@@ -898,8 +924,9 @@ String EditorFileDialog::get_current_path() const {
}
void EditorFileDialog::set_current_dir(const String &p_dir) {
- if (p_dir.is_rel_path())
+ if (p_dir.is_rel_path()) {
dir_access->change_dir(OS::get_singleton()->get_resource_dir());
+ }
dir_access->change_dir(p_dir);
update_dir();
invalidate();
@@ -915,13 +942,15 @@ void EditorFileDialog::set_current_file(const String &p_file) {
file->grab_focus();
}
- if (is_visible())
+ if (is_visible()) {
_request_single_thumbnail(get_current_dir().plus_file(get_current_file()));
+ }
}
void EditorFileDialog::set_current_path(const String &p_path) {
- if (!p_path.size())
+ if (!p_path.size()) {
return;
+ }
int pos = MAX(p_path.find_last("/"), p_path.find_last("\\"));
if (pos == -1) {
set_current_file(p_path);
@@ -982,8 +1011,9 @@ EditorFileDialog::FileMode EditorFileDialog::get_file_mode() const {
void EditorFileDialog::set_access(Access p_access) {
ERR_FAIL_INDEX(p_access, 3);
- if (access == p_access)
+ if (access == p_access) {
return;
+ }
memdelete(dir_access);
switch (p_access) {
case ACCESS_FILESYSTEM: {
@@ -1107,8 +1137,9 @@ void EditorFileDialog::_favorite_move_up() {
int a_idx = favorited.find(String(favorites->get_item_metadata(current - 1)));
int b_idx = favorited.find(String(favorites->get_item_metadata(current)));
- if (a_idx == -1 || b_idx == -1)
+ if (a_idx == -1 || b_idx == -1) {
return;
+ }
SWAP(favorited.write[a_idx], favorited.write[b_idx]);
EditorSettings::get_singleton()->set_favorites(favorited);
@@ -1127,8 +1158,9 @@ void EditorFileDialog::_favorite_move_down() {
int a_idx = favorited.find(String(favorites->get_item_metadata(current + 1)));
int b_idx = favorited.find(String(favorites->get_item_metadata(current)));
- if (a_idx == -1 || b_idx == -1)
+ if (a_idx == -1 || b_idx == -1) {
return;
+ }
SWAP(favorited.write[a_idx], favorited.write[b_idx]);
EditorSettings::get_singleton()->set_favorites(favorited);
@@ -1151,20 +1183,23 @@ void EditorFileDialog::_update_favorites() {
Vector<String> favorited = EditorSettings::get_singleton()->get_favorites();
for (int i = 0; i < favorited.size(); i++) {
bool cres = favorited[i].begins_with("res://");
- if (cres != res)
+ if (cres != res) {
continue;
+ }
String name = favorited[i];
bool setthis = false;
if (res && name == "res://") {
- if (name == current)
+ if (name == current) {
setthis = true;
+ }
name = "/";
favorites->add_item(name, folder_icon);
} else if (name.ends_with("/")) {
- if (name == current || name == current + "/")
+ if (name == current || name == current + "/") {
setthis = true;
+ }
name = name.substr(0, name.length() - 1);
name = name.get_file();
@@ -1188,16 +1223,18 @@ void EditorFileDialog::_favorite_pressed() {
bool res = access == ACCESS_RESOURCES;
String cd = get_current_dir();
- if (!cd.ends_with("/"))
+ if (!cd.ends_with("/")) {
cd += "/";
+ }
Vector<String> favorited = EditorSettings::get_singleton()->get_favorites();
bool found = false;
for (int i = 0; i < favorited.size(); i++) {
bool cres = favorited[i].begins_with("res://");
- if (cres != res)
+ if (cres != res) {
continue;
+ }
if (favorited[i] == cd) {
found = true;
@@ -1205,10 +1242,11 @@ void EditorFileDialog::_favorite_pressed() {
}
}
- if (found)
+ if (found) {
favorited.erase(cd);
- else
+ } else {
favorited.push_back(cd);
+ }
EditorSettings::get_singleton()->set_favorites(favorited);
@@ -1265,8 +1303,9 @@ bool EditorFileDialog::default_show_hidden_files = false;
EditorFileDialog::DisplayMode EditorFileDialog::default_display_mode = DISPLAY_THUMBNAILS;
void EditorFileDialog::set_display_mode(DisplayMode p_mode) {
- if (display_mode == p_mode)
+ if (display_mode == p_mode) {
return;
+ }
if (p_mode == DISPLAY_THUMBNAILS) {
mode_list->set_pressed(false);
mode_thumbnails->set_pressed(true);
@@ -1625,8 +1664,9 @@ EditorFileDialog::EditorFileDialog() {
vbox = vbc;
invalidated = true;
- if (register_func)
+ if (register_func) {
register_func(this);
+ }
preview_wheel_timeout = 0;
preview_wheel_index = 0;
@@ -1634,7 +1674,8 @@ EditorFileDialog::EditorFileDialog() {
}
EditorFileDialog::~EditorFileDialog() {
- if (unregister_func)
+ if (unregister_func) {
unregister_func(this);
+ }
memdelete(dir_access);
}
diff --git a/editor/editor_file_system.cpp b/editor/editor_file_system.cpp
index 77ba5b3f1d..d88c61d7b2 100644
--- a/editor/editor_file_system.cpp
+++ b/editor/editor_file_system.cpp
@@ -51,16 +51,18 @@ void EditorFileSystemDirectory::sort_files() {
int EditorFileSystemDirectory::find_file_index(const String &p_file) const {
for (int i = 0; i < files.size(); i++) {
- if (files[i]->file == p_file)
+ if (files[i]->file == p_file) {
return i;
+ }
}
return -1;
}
int EditorFileSystemDirectory::find_dir_index(const String &p_dir) const {
for (int i = 0; i < subdirs.size(); i++) {
- if (subdirs[i]->name == p_dir)
+ if (subdirs[i]->name == p_dir) {
return i;
+ }
}
return -1;
@@ -209,8 +211,9 @@ void EditorFileSystem::_scan_filesystem() {
first = false;
continue;
}
- if (l == String())
+ if (l == String()) {
continue;
+ }
if (l.begins_with("::")) {
Vector<String> split = l.split("::");
@@ -317,8 +320,9 @@ void EditorFileSystem::_thread_func(void *_userdata) {
}
bool EditorFileSystem::_test_for_reimport(const String &p_path, bool p_only_imported_files) {
- if (!reimport_on_missing_imported_files && p_only_imported_files)
+ if (!reimport_on_missing_imported_files && p_only_imported_files) {
return false;
+ }
if (!FileAccess::exists(p_path + ".import")) {
return true;
@@ -476,8 +480,9 @@ bool EditorFileSystem::_update_scan_actions() {
case ItemAction::ACTION_DIR_ADD: {
int idx = 0;
for (int i = 0; i < ia.dir->subdirs.size(); i++) {
- if (ia.new_dir->name < ia.dir->subdirs[i]->name)
+ if (ia.new_dir->name < ia.dir->subdirs[i]->name) {
break;
+ }
idx++;
}
if (idx == ia.dir->subdirs.size()) {
@@ -497,8 +502,9 @@ bool EditorFileSystem::_update_scan_actions() {
case ItemAction::ACTION_FILE_ADD: {
int idx = 0;
for (int i = 0; i < ia.dir->files.size(); i++) {
- if (ia.new_file->file < ia.dir->files[i]->file)
+ if (ia.new_file->file < ia.dir->files[i]->file) {
break;
+ }
idx++;
}
if (idx == ia.dir->files.size()) {
@@ -567,11 +573,13 @@ bool EditorFileSystem::_update_scan_actions() {
}
void EditorFileSystem::scan() {
- if (false /*&& bool(Globals::get_singleton()->get("debug/disable_scan"))*/)
+ if (false /*&& bool(Globals::get_singleton()->get("debug/disable_scan"))*/) {
return;
+ }
- if (scanning || scanning_changes || thread)
+ if (scanning || scanning_changes || thread) {
return;
+ }
_update_extensions();
@@ -580,8 +588,9 @@ void EditorFileSystem::scan() {
scanning = true;
scan_total = 0;
_scan_filesystem();
- if (filesystem)
+ if (filesystem) {
memdelete(filesystem);
+ }
//file_type_cache.clear();
filesystem = new_filesystem;
new_filesystem = nullptr;
@@ -629,20 +638,25 @@ void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir, DirAccess
da->list_dir_begin();
while (true) {
String f = da->get_next();
- if (f == "")
+ if (f == "") {
break;
+ }
- if (da->current_is_hidden())
+ if (da->current_is_hidden()) {
continue;
+ }
if (da->current_is_dir()) {
- if (f.begins_with(".")) // Ignore special and . / ..
+ if (f.begins_with(".")) { // Ignore special and . / ..
continue;
+ }
- if (FileAccess::exists(cd.plus_file(f).plus_file("project.godot"))) // skip if another project inside this
+ if (FileAccess::exists(cd.plus_file(f).plus_file("project.godot"))) { // skip if another project inside this
continue;
- if (FileAccess::exists(cd.plus_file(f).plus_file(".gdignore"))) // skip if another project inside this
+ }
+ if (FileAccess::exists(cd.plus_file(f).plus_file(".gdignore"))) { // skip if another project inside this
continue;
+ }
dirs.push_back(f);
@@ -675,8 +689,9 @@ void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir, DirAccess
int idx2 = 0;
for (int i = 0; i < p_dir->subdirs.size(); i++) {
- if (efd->name < p_dir->subdirs[i]->name)
+ if (efd->name < p_dir->subdirs[i]->name) {
break;
+ }
idx2++;
}
if (idx2 == p_dir->subdirs.size()) {
@@ -812,22 +827,27 @@ void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir, const
da->list_dir_begin();
while (true) {
String f = da->get_next();
- if (f == "")
+ if (f == "") {
break;
+ }
- if (da->current_is_hidden())
+ if (da->current_is_hidden()) {
continue;
+ }
if (da->current_is_dir()) {
- if (f.begins_with(".")) // Ignore special and . / ..
+ if (f.begins_with(".")) { // Ignore special and . / ..
continue;
+ }
int idx = p_dir->find_dir_index(f);
if (idx == -1) {
- if (FileAccess::exists(cd.plus_file(f).plus_file("project.godot"))) // skip if another project inside this
+ if (FileAccess::exists(cd.plus_file(f).plus_file("project.godot"))) { // skip if another project inside this
continue;
- if (FileAccess::exists(cd.plus_file(f).plus_file(".gdignore"))) // skip if another project inside this
+ }
+ if (FileAccess::exists(cd.plus_file(f).plus_file(".gdignore"))) { // skip if another project inside this
continue;
+ }
EditorFileSystemDirectory *efd = memnew(EditorFileSystemDirectory);
@@ -850,8 +870,9 @@ void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir, const
} else {
String ext = f.get_extension().to_lower();
- if (!valid_extensions.has(ext))
+ if (!valid_extensions.has(ext)) {
continue; //invalid
+ }
int idx = p_dir->find_file_index(f);
@@ -1019,8 +1040,9 @@ void EditorFileSystem::scan_changes() {
sp.low = 0;
scan_total = 0;
_scan_fs_changes(filesystem, sp);
- if (_update_scan_actions())
+ if (_update_scan_actions()) {
emit_signal("filesystem_changed");
+ }
}
scanning_changes = false;
scanning_changes_done = true;
@@ -1057,10 +1079,12 @@ void EditorFileSystem::_notification(int p_what) {
set_process(false);
}
- if (filesystem)
+ if (filesystem) {
memdelete(filesystem);
- if (new_filesystem)
+ }
+ if (new_filesystem) {
memdelete(new_filesystem);
+ }
filesystem = nullptr;
new_filesystem = nullptr;
@@ -1076,8 +1100,9 @@ void EditorFileSystem::_notification(int p_what) {
Thread::wait_to_finish(thread_sources);
memdelete(thread_sources);
thread_sources = nullptr;
- if (_update_scan_actions())
+ if (_update_scan_actions()) {
emit_signal("filesystem_changed");
+ }
emit_signal("sources_changed", sources_changed.size() > 0);
_queue_update_script_classes();
first_scan = false;
@@ -1085,8 +1110,9 @@ void EditorFileSystem::_notification(int p_what) {
} else if (!scanning) {
set_process(false);
- if (filesystem)
+ if (filesystem) {
memdelete(filesystem);
+ }
filesystem = new_filesystem;
new_filesystem = nullptr;
Thread::wait_to_finish(thread);
@@ -1121,8 +1147,9 @@ EditorFileSystemDirectory *EditorFileSystem::get_filesystem() {
}
void EditorFileSystem::_save_filesystem_cache(EditorFileSystemDirectory *p_dir, FileAccess *p_file) {
- if (!p_dir)
+ if (!p_dir) {
return; //none
+ }
p_file->store_line("::" + p_dir->get_path() + "::" + String::num(p_dir->modified_time));
for (int i = 0; i < p_dir->files.size(); i++) {
@@ -1132,8 +1159,9 @@ void EditorFileSystem::_save_filesystem_cache(EditorFileSystemDirectory *p_dir,
String s = p_dir->files[i]->file + "::" + p_dir->files[i]->type + "::" + itos(p_dir->files[i]->modified_time) + "::" + itos(p_dir->files[i]->import_modified_time) + "::" + itos(p_dir->files[i]->import_valid) + "::" + p_dir->files[i]->import_group_file + "::" + p_dir->files[i]->script_class_name + "<>" + p_dir->files[i]->script_class_extends + "<>" + p_dir->files[i]->script_class_icon_path;
s += "::";
for (int j = 0; j < p_dir->files[i]->deps.size(); j++) {
- if (j > 0)
+ if (j > 0) {
s += "<>";
+ }
s += p_dir->files[i]->deps[j];
}
@@ -1148,28 +1176,32 @@ void EditorFileSystem::_save_filesystem_cache(EditorFileSystemDirectory *p_dir,
bool EditorFileSystem::_find_file(const String &p_file, EditorFileSystemDirectory **r_d, int &r_file_pos) const {
//todo make faster
- if (!filesystem || scanning)
+ if (!filesystem || scanning) {
return false;
+ }
String f = ProjectSettings::get_singleton()->localize_path(p_file);
- if (!f.begins_with("res://"))
+ if (!f.begins_with("res://")) {
return false;
+ }
f = f.substr(6, f.length());
f = f.replace("\\", "/");
Vector<String> path = f.split("/");
- if (path.size() == 0)
+ if (path.size() == 0) {
return false;
+ }
String file = path[path.size() - 1];
path.resize(path.size() - 1);
EditorFileSystemDirectory *fs = filesystem;
for (int i = 0; i < path.size(); i++) {
- if (path[i].begins_with("."))
+ if (path[i].begins_with(".")) {
return false;
+ }
int idx = -1;
for (int j = 0; j < fs->get_subdir_count(); j++) {
@@ -1188,15 +1220,17 @@ bool EditorFileSystem::_find_file(const String &p_file, EditorFileSystemDirector
int idx2 = 0;
for (int j = 0; j < fs->get_subdir_count(); j++) {
- if (efsd->name < fs->get_subdir(j)->get_name())
+ if (efsd->name < fs->get_subdir(j)->get_name()) {
break;
+ }
idx2++;
}
- if (idx2 == fs->get_subdir_count())
+ if (idx2 == fs->get_subdir_count()) {
fs->subdirs.push_back(efsd);
- else
+ } else {
fs->subdirs.insert(idx2, efsd);
+ }
fs = efsd;
} else {
fs = fs->get_subdir(idx);
@@ -1229,8 +1263,9 @@ String EditorFileSystem::get_file_type(const String &p_file) const {
}
EditorFileSystemDirectory *EditorFileSystem::find_file(const String &p_file, int *r_index) const {
- if (!filesystem || scanning)
+ if (!filesystem || scanning) {
return nullptr;
+ }
EditorFileSystemDirectory *fs = nullptr;
int cpos = -1;
@@ -1238,33 +1273,39 @@ EditorFileSystemDirectory *EditorFileSystem::find_file(const String &p_file, int
return nullptr;
}
- if (r_index)
+ if (r_index) {
*r_index = cpos;
+ }
return fs;
}
EditorFileSystemDirectory *EditorFileSystem::get_filesystem_path(const String &p_path) {
- if (!filesystem || scanning)
+ if (!filesystem || scanning) {
return nullptr;
+ }
String f = ProjectSettings::get_singleton()->localize_path(p_path);
- if (!f.begins_with("res://"))
+ if (!f.begins_with("res://")) {
return nullptr;
+ }
f = f.substr(6, f.length());
f = f.replace("\\", "/");
- if (f == String())
+ if (f == String()) {
return filesystem;
+ }
- if (f.ends_with("/"))
+ if (f.ends_with("/")) {
f = f.substr(0, f.length() - 1);
+ }
Vector<String> path = f.split("/");
- if (path.size() == 0)
+ if (path.size() == 0) {
return nullptr;
+ }
EditorFileSystemDirectory *fs = filesystem;
@@ -1351,8 +1392,9 @@ void EditorFileSystem::_scan_script_classes(EditorFileSystemDirectory *p_dir) {
}
void EditorFileSystem::update_script_classes() {
- if (!update_script_classes_queued)
+ if (!update_script_classes_queued) {
return;
+ }
update_script_classes_queued = false;
ScriptServer::global_classes_clear();
@@ -1386,8 +1428,9 @@ void EditorFileSystem::update_file(const String &p_file) {
int cpos = -1;
if (!_find_file(p_file, &fs, cpos)) {
- if (!fs)
+ if (!fs) {
return;
+ }
}
if (!FileAccess::exists(p_file)) {
@@ -1412,8 +1455,9 @@ void EditorFileSystem::update_file(const String &p_file) {
int idx = 0;
for (int i = 0; i < fs->files.size(); i++) {
- if (p_file < fs->files[i]->file)
+ if (p_file < fs->files[i]->file) {
break;
+ }
idx++;
}
diff --git a/editor/editor_folding.cpp b/editor/editor_folding.cpp
index a1d65ac739..f0e6e3a799 100644
--- a/editor/editor_folding.cpp
+++ b/editor/editor_folding.cpp
@@ -132,8 +132,9 @@ void EditorFolding::save_scene_folding(const Node *p_scene, const String &p_path
ERR_FAIL_NULL(p_scene);
FileAccessRef file_check = FileAccess::create(FileAccess::ACCESS_RESOURCES);
- if (!file_check->file_exists(p_path)) //This can happen when creating scene from FilesystemDock. It has path, but no file.
+ if (!file_check->file_exists(p_path)) { //This can happen when creating scene from FilesystemDock. It has path, but no file.
return;
+ }
Ref<ConfigFile> config;
config.instance();
diff --git a/editor/editor_help.cpp b/editor/editor_help.cpp
index 16e49ad4e1..30cf7d1e7a 100644
--- a/editor/editor_help.cpp
+++ b/editor/editor_help.cpp
@@ -57,8 +57,9 @@ void EditorHelp::_init_colors() {
}
void EditorHelp::_unhandled_key_input(const Ref<InputEvent> &p_ev) {
- if (!is_visible_in_tree())
+ if (!is_visible_in_tree()) {
return;
+ }
Ref<InputEventKey> k = p_ev;
@@ -69,10 +70,11 @@ void EditorHelp::_unhandled_key_input(const Ref<InputEvent> &p_ev) {
}
void EditorHelp::_search(bool p_search_previous) {
- if (p_search_previous)
+ if (p_search_previous) {
find_bar->search_prev();
- else
+ } else {
find_bar->search_next();
+ }
}
void EditorHelp::_class_list_select(const String &p_select) {
@@ -177,8 +179,9 @@ void EditorHelp::_class_desc_resized() {
void EditorHelp::_add_type(const String &p_type, const String &p_enum) {
String t = p_type;
- if (t.empty())
+ if (t.empty()) {
t = "void";
+ }
bool can_ref = (t != "void") || !p_enum.empty();
if (!p_enum.empty()) {
@@ -270,8 +273,9 @@ void EditorHelp::_add_method(const DocData::MethodDoc &p_method, bool p_overview
for (int j = 0; j < p_method.arguments.size(); j++) {
class_desc->push_color(text_color);
- if (j > 0)
+ if (j > 0) {
class_desc->add_text(", ");
+ }
_add_text(p_method.arguments[j].name);
class_desc->add_text(": ");
@@ -290,8 +294,9 @@ void EditorHelp::_add_method(const DocData::MethodDoc &p_method, bool p_overview
if (is_vararg) {
class_desc->push_color(text_color);
- if (p_method.arguments.size())
+ if (p_method.arguments.size()) {
class_desc->add_text(", ");
+ }
class_desc->push_color(symbol_color);
class_desc->add_text("...");
class_desc->pop();
@@ -308,13 +313,15 @@ void EditorHelp::_add_method(const DocData::MethodDoc &p_method, bool p_overview
class_desc->pop();
}
- if (p_overview)
+ if (p_overview) {
class_desc->pop(); //cell
+ }
}
Error EditorHelp::_goto_desc(const String &p_class, int p_vscr) {
- if (!doc->class_list.has(p_class))
+ if (!doc->class_list.has(p_class)) {
return ERR_DOES_NOT_EXIST;
+ }
select_locked = true;
@@ -322,8 +329,9 @@ Error EditorHelp::_goto_desc(const String &p_class, int p_vscr) {
description_line = 0;
- if (p_class == edited_class)
+ if (p_class == edited_class) {
return OK; //already there
+ }
edited_class = p_class;
_update_doc();
@@ -331,8 +339,9 @@ Error EditorHelp::_goto_desc(const String &p_class, int p_vscr) {
}
void EditorHelp::_update_doc() {
- if (!doc->class_list.has(edited_class))
+ if (!doc->class_list.has(edited_class)) {
return;
+ }
scroll_locked = true;
@@ -594,8 +603,9 @@ void EditorHelp::_update_doc() {
}
if (methods.size()) {
- if (sort_methods)
+ if (sort_methods) {
methods.sort();
+ }
section_line.push_back(Pair<String, int>(TTR("Methods"), class_desc->get_line_count() - 2));
class_desc->push_color(title_color);
@@ -755,8 +765,9 @@ void EditorHelp::_update_doc() {
class_desc->pop();
for (int j = 0; j < cd.signals[i].arguments.size(); j++) {
class_desc->push_color(text_color);
- if (j > 0)
+ if (j > 0) {
class_desc->add_text(", ");
+ }
_add_text(cd.signals[i].arguments[j].name);
class_desc->add_text(": ");
@@ -849,8 +860,9 @@ void EditorHelp::_update_doc() {
int enumStartingLine = enum_line[E->key()];
for (int i = 0; i < enum_list.size(); i++) {
- if (cd.name == "@GlobalScope")
+ if (cd.name == "@GlobalScope") {
enumValuesContainer[enum_list[i].name] = enumStartingLine;
+ }
// Add the enum constant line to the constant_line map so we can locate it as a constant
constant_line[enum_list[i].name] = class_desc->get_line_count() - 2;
@@ -881,8 +893,9 @@ void EditorHelp::_update_doc() {
class_desc->add_newline();
}
- if (cd.name == "@GlobalScope")
+ if (cd.name == "@GlobalScope") {
enum_values_line[E->key()] = enumValuesContainer;
+ }
class_desc->pop();
@@ -963,8 +976,9 @@ void EditorHelp::_update_doc() {
class_desc->add_newline();
for (int i = 0; i < cd.properties.size(); i++) {
- if (cd.properties[i].overridden)
+ if (cd.properties[i].overridden) {
continue;
+ }
property_line[cd.properties[i].name] = class_desc->get_line_count() - 2;
@@ -1128,8 +1142,9 @@ void EditorHelp::_help_callback(const String &p_topic) {
String what = p_topic.get_slice(":", 0);
String clss = p_topic.get_slice(":", 1);
String name;
- if (p_topic.get_slice_count(":") == 3)
+ if (p_topic.get_slice_count(":") == 3) {
name = p_topic.get_slice(":", 2);
+ }
_request_help(clss); //first go to class
@@ -1138,36 +1153,43 @@ void EditorHelp::_help_callback(const String &p_topic) {
if (what == "class_desc") {
line = description_line;
} else if (what == "class_signal") {
- if (signal_line.has(name))
+ if (signal_line.has(name)) {
line = signal_line[name];
+ }
} else if (what == "class_method" || what == "class_method_desc") {
- if (method_line.has(name))
+ if (method_line.has(name)) {
line = method_line[name];
+ }
} else if (what == "class_property") {
- if (property_line.has(name))
+ if (property_line.has(name)) {
line = property_line[name];
+ }
} else if (what == "class_enum") {
- if (enum_line.has(name))
+ if (enum_line.has(name)) {
line = enum_line[name];
+ }
} else if (what == "class_theme_item") {
- if (theme_property_line.has(name))
+ if (theme_property_line.has(name)) {
line = theme_property_line[name];
+ }
} else if (what == "class_constant") {
- if (constant_line.has(name))
+ if (constant_line.has(name)) {
line = constant_line[name];
+ }
} else if (what == "class_global") {
- if (constant_line.has(name))
+ if (constant_line.has(name)) {
line = constant_line[name];
- else {
+ } else {
Map<String, Map<String, int>>::Element *iter = enum_values_line.front();
while (true) {
if (iter->value().has(name)) {
line = iter->value()[name];
break;
- } else if (iter == enum_values_line.back())
+ } else if (iter == enum_values_line.back()) {
break;
- else
+ } else {
iter = iter->next();
+ }
}
}
}
@@ -1204,25 +1226,29 @@ static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt) {
while (pos < bbcode.length()) {
int brk_pos = bbcode.find("[", pos);
- if (brk_pos < 0)
+ if (brk_pos < 0) {
brk_pos = bbcode.length();
+ }
if (brk_pos > pos) {
String text = bbcode.substr(pos, brk_pos - pos);
- if (!code_tag)
+ if (!code_tag) {
text = text.replace("\n", "\n\n");
+ }
p_rt->add_text(text);
}
- if (brk_pos == bbcode.length())
+ if (brk_pos == bbcode.length()) {
break; //nothing else to add
+ }
int brk_end = bbcode.find("]", brk_pos + 1);
if (brk_end == -1) {
String text = bbcode.substr(brk_pos, bbcode.length() - brk_pos);
- if (!code_tag)
+ if (!code_tag) {
text = text.replace("\n", "\n\n");
+ }
p_rt->add_text(text);
break;
@@ -1320,8 +1346,9 @@ static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt) {
} else if (tag == "url") {
int end = bbcode.find("[", brk_end);
- if (end == -1)
+ if (end == -1) {
end = bbcode.length();
+ }
String url = bbcode.substr(brk_end + 1, end - brk_end - 1);
p_rt->push_meta(url);
@@ -1334,13 +1361,15 @@ static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt) {
tag_stack.push_front("url");
} else if (tag == "img") {
int end = bbcode.find("[", brk_end);
- if (end == -1)
+ if (end == -1) {
end = bbcode.length();
+ }
String image = bbcode.substr(brk_end + 1, end - brk_end - 1);
Ref<Texture2D> texture = ResourceLoader::load(base_path.plus_file(image), "Texture2D");
- if (texture.is_valid())
+ if (texture.is_valid()) {
p_rt->add_image(texture);
+ }
pos = end;
tag_stack.push_front(tag);
@@ -1348,42 +1377,43 @@ static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt) {
String col = tag.substr(6, tag.length());
Color color;
- if (col.begins_with("#"))
+ if (col.begins_with("#")) {
color = Color::html(col);
- else if (col == "aqua")
+ } else if (col == "aqua") {
color = Color(0, 1, 1);
- else if (col == "black")
+ } else if (col == "black") {
color = Color(0, 0, 0);
- else if (col == "blue")
+ } else if (col == "blue") {
color = Color(0, 0, 1);
- else if (col == "fuchsia")
+ } else if (col == "fuchsia") {
color = Color(1, 0, 1);
- else if (col == "gray" || col == "grey")
+ } else if (col == "gray" || col == "grey") {
color = Color(0.5, 0.5, 0.5);
- else if (col == "green")
+ } else if (col == "green") {
color = Color(0, 0.5, 0);
- else if (col == "lime")
+ } else if (col == "lime") {
color = Color(0, 1, 0);
- else if (col == "maroon")
+ } else if (col == "maroon") {
color = Color(0.5, 0, 0);
- else if (col == "navy")
+ } else if (col == "navy") {
color = Color(0, 0, 0.5);
- else if (col == "olive")
+ } else if (col == "olive") {
color = Color(0.5, 0.5, 0);
- else if (col == "purple")
+ } else if (col == "purple") {
color = Color(0.5, 0, 0.5);
- else if (col == "red")
+ } else if (col == "red") {
color = Color(1, 0, 0);
- else if (col == "silver")
+ } else if (col == "silver") {
color = Color(0.75, 0.75, 0.75);
- else if (col == "teal")
+ } else if (col == "teal") {
color = Color(0, 0.5, 0.5);
- else if (col == "white")
+ } else if (col == "white") {
color = Color(1, 1, 1);
- else if (col == "yellow")
+ } else if (col == "yellow") {
color = Color(1, 1, 0);
- else
+ } else {
color = Color(0, 0, 0); //base_color;
+ }
p_rt->push_color(color);
pos = brk_end + 1;
@@ -1393,9 +1423,9 @@ static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt) {
String fnt = tag.substr(5, tag.length());
Ref<Font> font = ResourceLoader::load(base_path.plus_file(fnt), "Font");
- if (font.is_valid())
+ if (font.is_valid()) {
p_rt->push_font(font);
- else {
+ } else {
p_rt->push_font(doc_font);
}
@@ -1544,8 +1574,9 @@ void EditorHelpBit::_meta_clicked(String p_select) {
} else if (p_select.begins_with("@")) {
String m = p_select.substr(1, p_select.length());
- if (m.find(".") != -1)
+ if (m.find(".") != -1) {
_go_to_help("class_method:" + m.get_slice(".", 0) + ":" + m.get_slice(".", 0)); //must go somewhere else
+ }
}
}
@@ -1696,8 +1727,9 @@ void FindBar::_update_results_count() {
results_count = 0;
String searched = search_text->get_text();
- if (searched.empty())
+ if (searched.empty()) {
return;
+ }
String full_text = rich_text_label->get_text();
@@ -1705,8 +1737,9 @@ void FindBar::_update_results_count() {
while (true) {
int pos = full_text.find(searched, from_pos);
- if (pos == -1)
+ if (pos == -1) {
break;
+ }
results_count++;
from_pos = pos + searched.length();
@@ -1725,8 +1758,9 @@ void FindBar::_update_matches_label() {
}
void FindBar::_hide_bar() {
- if (search_text->has_focus())
+ if (search_text->has_focus()) {
rich_text_label->grab_focus();
+ }
hide();
}
diff --git a/editor/editor_help_search.cpp b/editor/editor_help_search.cpp
index 936288b176..5bfcbf06fc 100644
--- a/editor/editor_help_search.cpp
+++ b/editor/editor_help_search.cpp
@@ -42,18 +42,21 @@ void EditorHelpSearch::_update_icons() {
case_sensitive_button->set_icon(results_tree->get_theme_icon("MatchCase", "EditorIcons"));
hierarchy_button->set_icon(results_tree->get_theme_icon("ClassList", "EditorIcons"));
- if (is_visible())
+ if (is_visible()) {
_update_results();
+ }
}
void EditorHelpSearch::_update_results() {
String term = search_box->get_text();
int search_flags = filter_combo->get_selected_id();
- if (case_sensitive_button->is_pressed())
+ if (case_sensitive_button->is_pressed()) {
search_flags |= SEARCH_CASE_SENSITIVE;
- if (hierarchy_button->is_pressed())
+ }
+ if (hierarchy_button->is_pressed()) {
search_flags |= SEARCH_SHOW_HIERARCHY;
+ }
search = Ref<Runner>(memnew(Runner(results_tree, results_tree, term, search_flags)));
set_process(true);
@@ -85,8 +88,9 @@ void EditorHelpSearch::_filter_combo_item_selected(int p_option) {
void EditorHelpSearch::_confirmed() {
TreeItem *item = results_tree->get_selected();
- if (!item)
+ if (!item) {
return;
+ }
// Activate the script editor and emit the signal with the documentation link to display.
EditorNode::get_singleton()->set_visible_editor(EditorNode::EDITOR_SCRIPT);
@@ -120,10 +124,11 @@ void EditorHelpSearch::_notification(int p_what) {
// Search done.
// Only point to the perfect match if it's a new search, and not just reopening a old one.
- if (!old_search)
+ if (!old_search) {
results_tree->ensure_cursor_is_visible();
- else
+ } else {
old_search = false;
+ }
get_ok()->set_disabled(!results_tree->get_selected());
@@ -148,18 +153,20 @@ void EditorHelpSearch::popup_dialog() {
void EditorHelpSearch::popup_dialog(const String &p_term) {
// Restore valid window bounds or pop up at default size.
Rect2 saved_size = EditorSettings::get_singleton()->get_project_metadata("dialog_bounds", "search_help", Rect2());
- if (saved_size != Rect2())
+ if (saved_size != Rect2()) {
popup(saved_size);
- else
+ } else {
popup_centered_ratio(0.5F);
+ }
if (p_term == "") {
search_box->clear();
} else {
- if (old_term == p_term)
+ if (old_term == p_term) {
old_search = true;
- else
+ } else {
old_term = p_term;
+ }
search_box->set_text(p_term);
search_box->select_all();
@@ -291,8 +298,9 @@ bool EditorHelpSearch::Runner::_slice() {
return true;
};
- if (phase_done)
+ if (phase_done) {
phase++;
+ }
return false;
}
@@ -313,41 +321,58 @@ bool EditorHelpSearch::Runner::_phase_match_classes() {
match.doc = &class_doc;
// Match class name.
- if (search_flags & SEARCH_CLASSES)
+ if (search_flags & SEARCH_CLASSES) {
match.name = term == "" || _match_string(term, class_doc.name);
+ }
// Match members if the term is long enough.
if (term.length() > 1) {
- if (search_flags & SEARCH_METHODS)
+ if (search_flags & SEARCH_METHODS) {
for (int i = 0; i < class_doc.methods.size(); i++) {
String method_name = (search_flags & SEARCH_CASE_SENSITIVE) ? class_doc.methods[i].name : class_doc.methods[i].name.to_lower();
String aux_term = (search_flags & SEARCH_CASE_SENSITIVE) ? term : term.to_lower();
- if (aux_term.begins_with("."))
+ if (aux_term.begins_with(".")) {
aux_term = aux_term.right(1);
+ }
- if (aux_term.ends_with("("))
+ if (aux_term.ends_with("(")) {
aux_term = aux_term.left(aux_term.length() - 1).strip_edges();
+ }
- if (aux_term.is_subsequence_of(method_name))
+ if (aux_term.is_subsequence_of(method_name)) {
match.methods.push_back(const_cast<DocData::MethodDoc *>(&class_doc.methods[i]));
+ }
}
- if (search_flags & SEARCH_SIGNALS)
- for (int i = 0; i < class_doc.signals.size(); i++)
- if (_match_string(term, class_doc.signals[i].name))
+ }
+ if (search_flags & SEARCH_SIGNALS) {
+ for (int i = 0; i < class_doc.signals.size(); i++) {
+ if (_match_string(term, class_doc.signals[i].name)) {
match.signals.push_back(const_cast<DocData::MethodDoc *>(&class_doc.signals[i]));
- if (search_flags & SEARCH_CONSTANTS)
- for (int i = 0; i < class_doc.constants.size(); i++)
- if (_match_string(term, class_doc.constants[i].name))
+ }
+ }
+ }
+ if (search_flags & SEARCH_CONSTANTS) {
+ for (int i = 0; i < class_doc.constants.size(); i++) {
+ if (_match_string(term, class_doc.constants[i].name)) {
match.constants.push_back(const_cast<DocData::ConstantDoc *>(&class_doc.constants[i]));
- if (search_flags & SEARCH_PROPERTIES)
- for (int i = 0; i < class_doc.properties.size(); i++)
- if (_match_string(term, class_doc.properties[i].name) || _match_string(term, class_doc.properties[i].getter) || _match_string(term, class_doc.properties[i].setter))
+ }
+ }
+ }
+ if (search_flags & SEARCH_PROPERTIES) {
+ for (int i = 0; i < class_doc.properties.size(); i++) {
+ if (_match_string(term, class_doc.properties[i].name) || _match_string(term, class_doc.properties[i].getter) || _match_string(term, class_doc.properties[i].setter)) {
match.properties.push_back(const_cast<DocData::PropertyDoc *>(&class_doc.properties[i]));
- if (search_flags & SEARCH_THEME_ITEMS)
- for (int i = 0; i < class_doc.theme_properties.size(); i++)
- if (_match_string(term, class_doc.theme_properties[i].name))
+ }
+ }
+ }
+ if (search_flags & SEARCH_THEME_ITEMS) {
+ for (int i = 0; i < class_doc.theme_properties.size(); i++) {
+ if (_match_string(term, class_doc.theme_properties[i].name)) {
match.theme_properties.push_back(const_cast<DocData::PropertyDoc *>(&class_doc.theme_properties[i]));
+ }
+ }
+ }
}
}
@@ -369,11 +394,13 @@ bool EditorHelpSearch::Runner::_phase_class_items() {
ClassMatch &match = iterator_match->value();
if (search_flags & SEARCH_SHOW_HIERARCHY) {
- if (match.required())
+ if (match.required()) {
_create_class_hierarchy(match);
+ }
} else {
- if (match.name)
+ if (match.name) {
_create_class_item(root_item, match.doc, false);
+ }
}
iterator_match = iterator_match->next();
@@ -390,49 +417,59 @@ bool EditorHelpSearch::Runner::_phase_member_items() {
ClassMatch &match = iterator_match->value();
TreeItem *parent = (search_flags & SEARCH_SHOW_HIERARCHY) ? class_items[match.doc->name] : root_item;
- for (int i = 0; i < match.methods.size(); i++)
+ for (int i = 0; i < match.methods.size(); i++) {
_create_method_item(parent, match.doc, match.methods[i]);
- for (int i = 0; i < match.signals.size(); i++)
+ }
+ for (int i = 0; i < match.signals.size(); i++) {
_create_signal_item(parent, match.doc, match.signals[i]);
- for (int i = 0; i < match.constants.size(); i++)
+ }
+ for (int i = 0; i < match.constants.size(); i++) {
_create_constant_item(parent, match.doc, match.constants[i]);
- for (int i = 0; i < match.properties.size(); i++)
+ }
+ for (int i = 0; i < match.properties.size(); i++) {
_create_property_item(parent, match.doc, match.properties[i]);
- for (int i = 0; i < match.theme_properties.size(); i++)
+ }
+ for (int i = 0; i < match.theme_properties.size(); i++) {
_create_theme_property_item(parent, match.doc, match.theme_properties[i]);
+ }
iterator_match = iterator_match->next();
return !iterator_match;
}
bool EditorHelpSearch::Runner::_phase_select_match() {
- if (matched_item)
+ if (matched_item) {
matched_item->select(0);
+ }
return true;
}
bool EditorHelpSearch::Runner::_match_string(const String &p_term, const String &p_string) const {
- if (search_flags & SEARCH_CASE_SENSITIVE)
+ if (search_flags & SEARCH_CASE_SENSITIVE) {
return p_term.is_subsequence_of(p_string);
- else
+ } else {
return p_term.is_subsequence_ofi(p_string);
+ }
}
void EditorHelpSearch::Runner::_match_item(TreeItem *p_item, const String &p_text) {
if (!matched_item) {
if (search_flags & SEARCH_CASE_SENSITIVE) {
- if (p_text.casecmp_to(term) == 0)
+ if (p_text.casecmp_to(term) == 0) {
matched_item = p_item;
+ }
} else {
- if (p_text.nocasecmp_to(term) == 0)
+ if (p_text.nocasecmp_to(term) == 0) {
matched_item = p_item;
+ }
}
}
}
TreeItem *EditorHelpSearch::Runner::_create_class_hierarchy(const ClassMatch &p_match) {
- if (class_items.has(p_match.doc->name))
+ if (class_items.has(p_match.doc->name)) {
return class_items[p_match.doc->name];
+ }
// Ensure parent nodes are created first.
TreeItem *parent = root_item;
@@ -452,10 +489,11 @@ TreeItem *EditorHelpSearch::Runner::_create_class_hierarchy(const ClassMatch &p_
TreeItem *EditorHelpSearch::Runner::_create_class_item(TreeItem *p_parent, const DocData::ClassDoc *p_doc, bool p_gray) {
Ref<Texture2D> icon = empty_icon;
- if (ui_service->has_theme_icon(p_doc->name, "EditorIcons"))
+ if (ui_service->has_theme_icon(p_doc->name, "EditorIcons")) {
icon = ui_service->get_theme_icon(p_doc->name, "EditorIcons");
- else if (ClassDB::class_exists(p_doc->name) && ClassDB::is_parent_class(p_doc->name, "Object"))
+ } else if (ClassDB::class_exists(p_doc->name) && ClassDB::is_parent_class(p_doc->name, "Object")) {
icon = ui_service->get_theme_icon("Object", "EditorIcons");
+ }
String tooltip = p_doc->brief_description.strip_edges();
TreeItem *item = results_tree->create_item(p_parent);
@@ -480,10 +518,12 @@ TreeItem *EditorHelpSearch::Runner::_create_method_item(TreeItem *p_parent, cons
for (int i = 0; i < p_doc->arguments.size(); i++) {
const DocData::ArgumentDoc &arg = p_doc->arguments[i];
tooltip += arg.type + " " + arg.name;
- if (arg.default_value != "")
+ if (arg.default_value != "") {
tooltip += " = " + arg.default_value;
- if (i < p_doc->arguments.size() - 1)
+ }
+ if (i < p_doc->arguments.size() - 1) {
tooltip += ", ";
+ }
}
tooltip += ")";
return _create_member_item(p_parent, p_class_doc->name, "MemberMethod", p_doc->name, TTRC("Method"), "method", tooltip);
@@ -494,10 +534,12 @@ TreeItem *EditorHelpSearch::Runner::_create_signal_item(TreeItem *p_parent, cons
for (int i = 0; i < p_doc->arguments.size(); i++) {
const DocData::ArgumentDoc &arg = p_doc->arguments[i];
tooltip += arg.type + " " + arg.name;
- if (arg.default_value != "")
+ if (arg.default_value != "") {
tooltip += " = " + arg.default_value;
- if (i < p_doc->arguments.size() - 1)
+ }
+ if (i < p_doc->arguments.size() - 1) {
tooltip += ", ";
+ }
}
tooltip += ")";
return _create_member_item(p_parent, p_class_doc->name, "MemberSignal", p_doc->name, TTRC("Signal"), "signal", tooltip);
@@ -529,10 +571,10 @@ TreeItem *EditorHelpSearch::Runner::_create_member_item(TreeItem *p_parent, cons
} else {
icon = ui_service->get_theme_icon(p_icon, "EditorIcons");
/*// In flat mode, show the class icon.
- if (ui_service->has_icon(p_class_name, "EditorIcons"))
- icon = ui_service->get_icon(p_class_name, "EditorIcons");
- else if (ClassDB::is_parent_class(p_class_name, "Object"))
- icon = ui_service->get_icon("Object", "EditorIcons");*/
+if (ui_service->has_icon(p_class_name, "EditorIcons"))
+icon = ui_service->get_icon(p_class_name, "EditorIcons");
+else if (ClassDB::is_parent_class(p_class_name, "Object"))
+icon = ui_service->get_icon("Object", "EditorIcons");*/
text = p_class_name + "." + p_name;
}
@@ -552,9 +594,11 @@ TreeItem *EditorHelpSearch::Runner::_create_member_item(TreeItem *p_parent, cons
bool EditorHelpSearch::Runner::work(uint64_t slot) {
// Return true when the search has been completed, otherwise false.
const uint64_t until = OS::get_singleton()->get_ticks_usec() + slot;
- while (!_slice())
- if (OS::get_singleton()->get_ticks_usec() > until)
+ while (!_slice()) {
+ if (OS::get_singleton()->get_ticks_usec() > until) {
return false;
+ }
+ }
return true;
}
diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp
index 0e39d0f2ab..1b423f69b7 100644
--- a/editor/editor_inspector.cpp
+++ b/editor/editor_inspector.cpp
@@ -45,14 +45,18 @@ Size2 EditorProperty::get_minimum_size() const {
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c)
+ if (!c) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
- if (!c->is_visible())
+ }
+ if (!c->is_visible()) {
continue;
- if (c == bottom_editor)
+ }
+ if (c == bottom_editor) {
continue;
+ }
Size2 minsize = c->get_combined_minimum_size();
ms.width = MAX(ms.width, minsize.width);
@@ -110,12 +114,15 @@ void EditorProperty::_notification(int p_what) {
//compute room needed
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c)
+ if (!c) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
- if (c == bottom_editor)
+ }
+ if (c == bottom_editor) {
continue;
+ }
Size2 minsize = c->get_combined_minimum_size();
child_room = MAX(child_room, minsize.width);
@@ -169,12 +176,15 @@ void EditorProperty::_notification(int p_what) {
//set children
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c)
+ if (!c) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
- if (c == bottom_editor)
+ }
+ if (c == bottom_editor) {
continue;
+ }
fit_child_in_rect(c, rect);
right_child_rect = rect;
@@ -226,10 +236,11 @@ void EditorProperty::_notification(int p_what) {
if (checkable) {
Ref<Texture2D> checkbox;
- if (checked)
+ if (checked) {
checkbox = get_theme_icon("GuiChecked", "EditorIcons");
- else
+ } else {
checkbox = get_theme_icon("GuiUnchecked", "EditorIcons");
+ }
Color color2(1, 1, 1);
if (check_hover) {
@@ -327,8 +338,9 @@ StringName EditorProperty::get_edited_property() {
}
void EditorProperty::update_property() {
- if (get_script_instance())
+ if (get_script_instance()) {
get_script_instance()->call("update_property");
+ }
}
void EditorProperty::set_read_only(bool p_read_only) {
@@ -421,8 +433,9 @@ bool EditorPropertyRevert::is_node_property_different(Node *p_node, const Varian
//make sure there is an actual state
{
Node *node = p_node;
- if (!node)
+ if (!node) {
return false;
+ }
Node *edited_scene = EditorNode::get_singleton()->get_edited_scene();
bool found_state = false;
@@ -447,8 +460,9 @@ bool EditorPropertyRevert::is_node_property_different(Node *p_node, const Varian
node = node->get_owner();
}
- if (!found_state)
+ if (!found_state) {
return false; //pointless to check if we are not comparing against anything.
+ }
}
if (p_current.get_type() == Variant::FLOAT && p_orig.get_type() == Variant::FLOAT) {
@@ -507,8 +521,9 @@ bool EditorPropertyRevert::can_property_revert(Object *p_object, const StringNam
}
void EditorProperty::update_reload_status() {
- if (property == StringName())
+ if (property == StringName()) {
return; //no property, so nothing to do
+ }
bool has_reload = EditorPropertyRevert::can_property_revert(object, property);
@@ -582,8 +597,9 @@ bool EditorProperty::is_draw_red() const {
}
void EditorProperty::_focusable_focused(int p_index) {
- if (!selectable)
+ if (!selectable) {
return;
+ }
bool already_selected = selected;
selected = true;
selected_focusable = p_index;
@@ -625,8 +641,9 @@ bool EditorProperty::is_selected() const {
}
void EditorProperty::_gui_input(const Ref<InputEvent> &p_event) {
- if (property == StringName())
+ if (property == StringName()) {
return;
+ }
Ref<InputEventMouse> me = p_event;
@@ -744,8 +761,9 @@ void EditorProperty::set_bottom_editor(Control *p_control) {
}
Variant EditorProperty::get_drag_data(const Point2 &p_point) {
- if (property == StringName())
+ if (property == StringName()) {
return Variant();
+ }
Dictionary dp;
dp["type"] = "obj_property";
@@ -1112,12 +1130,15 @@ void EditorInspectorSection::_notification(int p_what) {
//set children
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c)
+ if (!c) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
- if (!c->is_visible_in_tree())
+ }
+ if (!c->is_visible_in_tree()) {
continue;
+ }
fit_child_in_rect(c, rect);
}
@@ -1160,12 +1181,15 @@ Size2 EditorInspectorSection::get_minimum_size() const {
Size2 ms;
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c)
+ if (!c) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
- if (!c->is_visible())
+ }
+ if (!c->is_visible()) {
continue;
+ }
Size2 minsize = c->get_combined_minimum_size();
ms.width = MAX(ms.width, minsize.width);
ms.height = MAX(ms.height, minsize.height);
@@ -1201,8 +1225,9 @@ void EditorInspectorSection::setup(const String &p_section, const String &p_labe
}
void EditorInspectorSection::_gui_input(const Ref<InputEvent> &p_event) {
- if (!foldable)
+ if (!foldable) {
return;
+ }
Ref<InputEventMouseButton> mb = p_event;
if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
@@ -1228,8 +1253,9 @@ VBoxContainer *EditorInspectorSection::get_vbox() {
}
void EditorInspectorSection::unfold() {
- if (!foldable)
+ if (!foldable) {
return;
+ }
_test_unfold();
@@ -1239,11 +1265,13 @@ void EditorInspectorSection::unfold() {
}
void EditorInspectorSection::fold() {
- if (!foldable)
+ if (!foldable) {
return;
+ }
- if (!vbox_added)
+ if (!vbox_added) {
return; //kinda pointless
+ }
object->editor_set_section_unfold(section, false);
vbox->hide();
@@ -1302,8 +1330,9 @@ void EditorInspector::add_inspector_plugin(const Ref<EditorInspectorPlugin> &p_p
ERR_FAIL_COND(inspector_plugin_count == MAX_PLUGINS);
for (int i = 0; i < inspector_plugin_count; i++) {
- if (inspector_plugins[i] == p_plugin)
+ if (inspector_plugins[i] == p_plugin) {
return; //already exists
+ }
}
inspector_plugins[inspector_plugin_count++] = p_plugin;
}
@@ -1324,8 +1353,9 @@ void EditorInspector::remove_inspector_plugin(const Ref<EditorInspectorPlugin> &
inspector_plugins[i] = inspector_plugins[i + 1];
}
- if (idx == inspector_plugin_count - 1)
+ if (idx == inspector_plugin_count - 1) {
inspector_plugins[idx] = Ref<EditorInspectorPlugin>();
+ }
inspector_plugin_count--;
}
@@ -1442,14 +1472,16 @@ void EditorInspector::update_tree() {
_clear();
- if (!object)
+ if (!object) {
return;
+ }
List<Ref<EditorInspectorPlugin>> valid_plugins;
for (int i = inspector_plugin_count - 1; i >= 0; i--) { //start by last, so lastly added can override newly added
- if (!inspector_plugins[i]->can_handle(object))
+ if (!inspector_plugins[i]->can_handle(object)) {
continue;
+ }
valid_plugins.push_back(inspector_plugins[i]);
}
@@ -1514,23 +1546,26 @@ void EditorInspector::update_tree() {
subgroup = "";
subgroup_base = "";
- if (!show_categories)
+ if (!show_categories) {
continue;
+ }
List<PropertyInfo>::Element *N = I->next();
bool valid = true;
//if no properties in category, skip
while (N) {
- if (N->get().usage & PROPERTY_USAGE_EDITOR)
+ if (N->get().usage & PROPERTY_USAGE_EDITOR) {
break;
+ }
if (N->get().usage & PROPERTY_USAGE_CATEGORY) {
valid = false;
break;
}
N = N->next();
}
- if (!valid)
+ if (!valid) {
continue; //empty, ignore
+ }
EditorInspectorCategory *category = memnew(EditorInspectorCategory);
main_vbox->add_child(category);
@@ -1564,11 +1599,13 @@ void EditorInspector::update_tree() {
continue;
- } else if (!(p.usage & PROPERTY_USAGE_EDITOR) || _is_property_disabled_by_feature_profile(p.name))
+ } else if (!(p.usage & PROPERTY_USAGE_EDITOR) || _is_property_disabled_by_feature_profile(p.name)) {
continue;
+ }
- if (p.usage & PROPERTY_USAGE_HIGH_END_GFX && RS::get_singleton()->is_low_end())
+ if (p.usage & PROPERTY_USAGE_HIGH_END_GFX && RS::get_singleton()->is_low_end()) {
continue; //do not show this property in low end gfx
+ }
if (p.name == "script" && (hide_script || bool(object->call("_hide_script_from_inspector")))) {
continue;
@@ -1626,11 +1663,13 @@ void EditorInspector::update_tree() {
if (use_filter && filter != "") {
String cat = path;
- if (capitalize_paths)
+ if (capitalize_paths) {
cat = cat.capitalize();
+ }
- if (!filter.is_subsequence_ofi(cat) && !filter.is_subsequence_ofi(name) && property_prefix.to_lower().find(filter.to_lower()) == -1)
+ if (!filter.is_subsequence_ofi(cat) && !filter.is_subsequence_ofi(name) && property_prefix.to_lower().find(filter.to_lower()) == -1) {
continue;
+ }
}
if (category_vbox == nullptr) {
@@ -1645,16 +1684,18 @@ void EditorInspector::update_tree() {
int level = 1;
for (int i = 0; i < path.get_slice_count("/"); i++) {
String path_name = path.get_slice("/", i);
- if (i > 0)
+ if (i > 0) {
acc_path += "/";
+ }
acc_path += path_name;
if (!item_path.has(acc_path)) {
EditorInspectorSection *section = memnew(EditorInspectorSection);
current_vbox->add_child(section);
sections.push_back(section);
- if (capitalize_paths)
+ if (capitalize_paths) {
path_name = path_name.capitalize();
+ }
Color c = sscolor;
c.a /= level;
@@ -1834,8 +1875,9 @@ void EditorInspector::update_tree() {
}
void EditorInspector::update_property(const String &p_prop) {
- if (!editor_property_map.has(p_prop))
+ if (!editor_property_map.has(p_prop)) {
return;
+ }
for (List<EditorProperty *>::Element *E = editor_property_map[p_prop].front(); E; E = E->next()) {
E->get()->update_property();
@@ -1856,8 +1898,9 @@ void EditorInspector::_clear() {
}
void EditorInspector::refresh() {
- if (refresh_countdown > 0 || changing)
+ if (refresh_countdown > 0 || changing) {
return;
+ }
refresh_countdown = EditorSettings::get_singleton()->get("docks/property_editor/auto_refresh_interval");
}
@@ -1866,8 +1909,9 @@ Object *EditorInspector::get_edited_object() {
}
void EditorInspector::edit(Object *p_object) {
- if (object == p_object)
+ if (object == p_object) {
return;
+ }
if (object) {
_clear();
object->remove_change_receptor(this);
@@ -1886,8 +1930,9 @@ void EditorInspector::edit(Object *p_object) {
}
void EditorInspector::set_keying(bool p_active) {
- if (keying == p_active)
+ if (keying == p_active) {
return;
+ }
keying = p_active;
update_tree();
}
@@ -1932,8 +1977,9 @@ void EditorInspector::set_use_filter(bool p_use) {
void EditorInspector::register_text_enter(Node *p_line_edit) {
search_box = Object::cast_to<LineEdit>(p_line_edit);
- if (search_box)
+ if (search_box) {
search_box->connect("text_changed", callable_mp(this, &EditorInspector::_filter_changed));
+ }
}
void EditorInspector::_filter_changed(const String &p_text) {
@@ -1987,8 +2033,9 @@ void EditorInspector::set_use_wide_editors(bool p_enable) {
void EditorInspector::set_sub_inspector(bool p_enable) {
sub_inspector = p_enable;
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
if (sub_inspector) {
add_theme_style_override("bg", get_theme_stylebox("sub_inspector_bg", "Editor"));
@@ -2002,15 +2049,17 @@ void EditorInspector::set_use_deletable_properties(bool p_enabled) {
}
void EditorInspector::_edit_request_change(Object *p_object, const String &p_property) {
- if (object != p_object) //may be undoing/redoing for a non edited object, so ignore
+ if (object != p_object) { //may be undoing/redoing for a non edited object, so ignore
return;
+ }
- if (changing)
+ if (changing) {
return;
+ }
- if (p_property == String())
+ if (p_property == String()) {
update_tree_pending = true;
- else {
+ } else {
pending.insert(p_property);
}
}
@@ -2026,10 +2075,11 @@ void EditorInspector::_edit_set(const String &p_name, const Variant &p_value, bo
if (!undo_redo || bool(object->call("_dont_undo_redo"))) {
object->set(p_name, p_value);
- if (p_refresh_all)
+ if (p_refresh_all) {
_edit_request_change(object, "");
- else
+ } else {
_edit_request_change(object, p_name);
+ }
emit_signal(_prop_edited, p_name);
@@ -2078,13 +2128,15 @@ void EditorInspector::_edit_set(const String &p_name, const Variant &p_value, bo
void EditorInspector::_property_changed(const String &p_path, const Variant &p_value, const String &p_name, bool p_changing) {
// The "changing" variable must be true for properties that trigger events as typing occurs,
// like "text_changed" signal. E.g. text property of Label, Button, RichTextLabel, etc.
- if (p_changing)
+ if (p_changing) {
this->changing++;
+ }
_edit_set(p_path, p_value, false, p_name);
- if (p_changing)
+ if (p_changing) {
this->changing--;
+ }
if (restart_request_props.has(p_path)) {
emit_signal("restart_requested");
@@ -2100,8 +2152,9 @@ void EditorInspector::_multiple_properties_changed(Vector<String> p_paths, Array
ERR_FAIL_COND(p_paths.size() != p_values.size());
String names;
for (int i = 0; i < p_paths.size(); i++) {
- if (i > 0)
+ if (i > 0) {
names += ",";
+ }
names += p_paths[i];
}
undo_redo->create_action(TTR("Set Multiple:") + " " + names, UndoRedo::MERGE_ENDS);
@@ -2117,30 +2170,34 @@ void EditorInspector::_multiple_properties_changed(Vector<String> p_paths, Array
}
void EditorInspector::_property_keyed(const String &p_path, bool p_advance) {
- if (!object)
+ if (!object) {
return;
+ }
emit_signal("property_keyed", p_path, object->get(p_path), p_advance); //second param is deprecated
}
void EditorInspector::_property_deleted(const String &p_path) {
print_line("deleted pressed?");
- if (!object)
+ if (!object) {
return;
+ }
emit_signal("property_deleted", p_path); //second param is deprecated
}
void EditorInspector::_property_keyed_with_value(const String &p_path, const Variant &p_value, bool p_advance) {
- if (!object)
+ if (!object) {
return;
+ }
emit_signal("property_keyed", p_path, p_value, p_advance); //second param is deprecated
}
void EditorInspector::_property_checked(const String &p_path, bool p_checked) {
- if (!object)
+ if (!object) {
return;
+ }
//property checked
if (autoclear) {
@@ -2177,11 +2234,13 @@ void EditorInspector::_property_selected(const String &p_path, int p_focusable)
property_focusable = p_focusable;
//deselect the others
for (Map<StringName, List<EditorProperty *>>::Element *F = editor_property_map.front(); F; F = F->next()) {
- if (F->key() == property_selected)
+ if (F->key() == property_selected) {
continue;
+ }
for (List<EditorProperty *>::Element *E = F->get().front(); E; E = E->next()) {
- if (E->get()->is_selected())
+ if (E->get()->is_selected()) {
E->get()->deselect();
+ }
}
}
@@ -2282,8 +2341,9 @@ void EditorInspector::_changed_callback(Object *p_changed, const char *p_prop) {
}
void EditorInspector::_vscroll_changed(double p_offset) {
- if (update_scroll_request >= 0) //waiting, do nothing
+ if (update_scroll_request >= 0) { //waiting, do nothing
return;
+ }
if (object) {
scroll_cache[object->get_instance_id()] = p_offset;
diff --git a/editor/editor_layouts_dialog.cpp b/editor/editor_layouts_dialog.cpp
index 4f48c5091b..14478b1386 100644
--- a/editor/editor_layouts_dialog.cpp
+++ b/editor/editor_layouts_dialog.cpp
@@ -41,14 +41,16 @@ void EditorLayoutsDialog::_line_gui_input(const Ref<InputEvent> &p_event) {
Ref<InputEventKey> k = p_event;
if (k.is_valid()) {
- if (!k->is_pressed())
+ if (!k->is_pressed()) {
return;
+ }
switch (k->get_keycode()) {
case KEY_KP_ENTER:
case KEY_ENTER: {
- if (get_hide_on_ok())
+ if (get_hide_on_ok()) {
hide();
+ }
ok_pressed();
set_input_as_handled();
} break;
diff --git a/editor/editor_log.cpp b/editor/editor_log.cpp
index 7adde6f114..ea5f73acd1 100644
--- a/editor/editor_log.cpp
+++ b/editor/editor_log.cpp
@@ -39,8 +39,9 @@
void EditorLog::_error_handler(void *p_self, const char *p_func, const char *p_file, int p_line, const char *p_error, const char *p_errorexp, ErrorHandlerType p_type) {
EditorLog *self = (EditorLog *)p_self;
- if (self->current != Thread::get_caller_id())
+ if (self->current != Thread::get_caller_id()) {
return;
+ }
String err_str;
if (p_errorexp && p_errorexp[0]) {
@@ -118,8 +119,9 @@ void EditorLog::add_message(const String &p_msg, MessageType p_type) {
log->add_text(p_msg);
- if (restore)
+ if (restore) {
log->pop();
+ }
}
void EditorLog::set_tool_button(ToolButton *p_tool_button) {
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp
index c8f07f4b8d..ca0e486259 100644
--- a/editor/editor_node.cpp
+++ b/editor/editor_node.cpp
@@ -230,8 +230,9 @@ void EditorNode::_update_scene_tabs() {
scene_tabs->add_child(scene_tab_add);
}
Rect2 last_tab = Rect2();
- if (scene_tabs->get_tab_count() != 0)
+ if (scene_tabs->get_tab_count() != 0) {
last_tab = scene_tabs->get_tab_rect(scene_tabs->get_tab_count() - 1);
+ }
scene_tab_add->set_position(Point2(last_tab.get_position().x + last_tab.get_size().x + 3, last_tab.get_position().y));
}
}
@@ -251,10 +252,12 @@ void EditorNode::_update_title() {
String appname = ProjectSettings::get_singleton()->get("application/config/name");
String title = appname.empty() ? String(VERSION_FULL_NAME) : String(VERSION_NAME + String(" - ") + appname);
String edited = editor_data.get_edited_scene_root() ? editor_data.get_edited_scene_root()->get_filename() : String();
- if (!edited.empty())
+ if (!edited.empty()) {
title += " - " + String(edited.get_file());
- if (unsaved_cache)
+ }
+ if (unsaved_cache) {
title += " (*)";
+ }
DisplayServer::get_singleton()->window_set_title(title);
}
@@ -303,8 +306,9 @@ void EditorNode::_unhandled_input(const Ref<InputEvent> &p_event) {
void EditorNode::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_PROCESS: {
- if (opening_prev && !confirmation->is_visible())
+ if (opening_prev && !confirmation->is_visible()) {
opening_prev = false;
+ }
if (unsaved_cache != (saved_version != editor_data.get_undo_redo().get_version())) {
unsaved_cache = (saved_version != editor_data.get_undo_redo().get_version());
@@ -322,8 +326,9 @@ void EditorNode::_notification(int p_what) {
if (frame != update_spinner_step_frame && (tick - update_spinner_step_msec) > (1000 / 8)) {
update_spinner_step++;
- if (update_spinner_step >= 8)
+ if (update_spinner_step >= 8) {
update_spinner_step = 0;
+ }
update_spinner_step_msec = tick;
update_spinner_step_frame = frame + 1;
@@ -474,8 +479,9 @@ void EditorNode::_notification(int p_what) {
recent_scenes->set_as_minsize();
// debugger area
- if (EditorDebuggerNode::get_singleton()->is_visible())
+ if (EditorDebuggerNode::get_singleton()->is_visible()) {
bottom_panel->add_theme_style_override("panel", gui_base->get_theme_stylebox("BottomPanelDebuggerOverride", "EditorStyles"));
+ }
// update_icons
for (int i = 0; i < singleton->main_editor_buttons.size(); i++) {
@@ -540,8 +546,9 @@ void EditorNode::_update_update_spinner() {
void EditorNode::_on_plugin_ready(Object *p_script, const String &p_activate_name) {
Ref<Script> script = Object::cast_to<Script>(p_script);
- if (script.is_null())
+ if (script.is_null()) {
return;
+ }
if (p_activate_name.length()) {
set_addon_plugin_enabled(p_activate_name, true);
}
@@ -560,12 +567,15 @@ void EditorNode::_resources_changed(const Vector<String> &p_resources) {
continue;
}
- if (!res->editor_can_reload_from_file())
+ if (!res->editor_can_reload_from_file()) {
continue;
- if (!res->get_path().is_resource_file() && !res->get_path().is_abs_path())
+ }
+ if (!res->get_path().is_resource_file() && !res->get_path().is_abs_path()) {
continue;
- if (!FileAccess::exists(res->get_path()))
+ }
+ if (!FileAccess::exists(res->get_path())) {
continue;
+ }
if (res->get_import_path() != String()) {
//this is an imported resource, will be reloaded if reimported via the _resources_reimported() callback
@@ -711,8 +721,9 @@ void EditorNode::_vp_resized() {
}
void EditorNode::_node_renamed() {
- if (get_inspector())
+ if (get_inspector()) {
get_inspector()->update_tree();
+ }
}
void EditorNode::_editor_select_next() {
@@ -773,8 +784,9 @@ void EditorNode::edit_node(Node *p_node) {
void EditorNode::save_resource_in_path(const Ref<Resource> &p_resource, const String &p_path) {
editor_data.apply_changes_in_editors();
int flg = 0;
- if (EditorSettings::get_singleton()->get("filesystem/on_save/compress_binary_resources"))
+ if (EditorSettings::get_singleton()->get("filesystem/on_save/compress_binary_resources")) {
flg |= ResourceSaver::FLAG_COMPRESS;
+ }
String path = ProjectSettings::get_singleton()->localize_path(p_path);
Error err = ResourceSaver::save(path, p_resource, flg | ResourceSaver::FLAG_REPLACE_SUBRESOURCE_PATHS);
@@ -912,8 +924,9 @@ void EditorNode::_dialog_display_load_error(String p_file, Error p_error) {
void EditorNode::_get_scene_metadata(const String &p_file) {
Node *scene = editor_data.get_edited_scene_root();
- if (!scene)
+ if (!scene) {
return;
+ }
String path = EditorSettings::get_singleton()->get_project_settings_dir().plus_file(p_file.get_file() + "-editstate-" + p_file.md5_text() + ".cfg");
@@ -921,8 +934,9 @@ void EditorNode::_get_scene_metadata(const String &p_file) {
cf.instance();
Error err = cf->load(path);
- if (err != OK || !cf->has_section("editor_states"))
+ if (err != OK || !cf->has_section("editor_states")) {
return; //must not exist
+ }
List<String> esl;
cf->get_section_keys("editor_states", &esl);
@@ -941,8 +955,9 @@ void EditorNode::_get_scene_metadata(const String &p_file) {
void EditorNode::_set_scene_metadata(const String &p_file, int p_idx) {
Node *scene = editor_data.get_edited_scene_root(p_idx);
- if (!scene)
+ if (!scene) {
return;
+ }
scene->set_meta("__editor_run_settings__", Variant()); //clear it (no point in keeping it)
scene->set_meta("__editor_plugin_states__", Variant());
@@ -972,8 +987,9 @@ void EditorNode::_set_scene_metadata(const String &p_file, int p_idx) {
}
bool EditorNode::_find_and_save_resource(RES p_res, Map<RES, bool> &processed, int32_t flags) {
- if (p_res.is_null())
+ if (p_res.is_null()) {
return false;
+ }
if (processed.has(p_res)) {
return processed[p_res];
@@ -1002,15 +1018,17 @@ bool EditorNode::_find_and_save_edited_subresources(Object *obj, Map<RES, bool>
List<PropertyInfo> pi;
obj->get_property_list(&pi);
for (List<PropertyInfo>::Element *E = pi.front(); E; E = E->next()) {
- if (!(E->get().usage & PROPERTY_USAGE_STORAGE))
+ if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) {
continue;
+ }
switch (E->get().type) {
case Variant::OBJECT: {
RES res = obj->get(E->get().name);
- if (_find_and_save_resource(res, processed, flags))
+ if (_find_and_save_resource(res, processed, flags)) {
ret_changed = true;
+ }
} break;
case Variant::ARRAY: {
@@ -1019,8 +1037,9 @@ bool EditorNode::_find_and_save_edited_subresources(Object *obj, Map<RES, bool>
for (int i = 0; i < len; i++) {
const Variant &v = varray.get(i);
RES res = v;
- if (_find_and_save_resource(res, processed, flags))
+ if (_find_and_save_resource(res, processed, flags)) {
ret_changed = true;
+ }
}
} break;
@@ -1031,8 +1050,9 @@ bool EditorNode::_find_and_save_edited_subresources(Object *obj, Map<RES, bool>
for (List<Variant>::Element *F = keys.front(); F; F = F->next()) {
Variant v = d[F->get()];
RES res = v;
- if (_find_and_save_resource(res, processed, flags))
+ if (_find_and_save_resource(res, processed, flags)) {
ret_changed = true;
+ }
}
} break;
default: {
@@ -1048,23 +1068,27 @@ void EditorNode::_save_edited_subresources(Node *scene, Map<RES, bool> &processe
for (int i = 0; i < scene->get_child_count(); i++) {
Node *n = scene->get_child(i);
- if (n->get_owner() != editor_data.get_edited_scene_root())
+ if (n->get_owner() != editor_data.get_edited_scene_root()) {
continue;
+ }
_save_edited_subresources(n, processed, flags);
}
}
void EditorNode::_find_node_types(Node *p_node, int &count_2d, int &count_3d) {
- if (p_node->is_class("Viewport") || (p_node != editor_data.get_edited_scene_root() && p_node->get_owner() != editor_data.get_edited_scene_root()))
+ if (p_node->is_class("Viewport") || (p_node != editor_data.get_edited_scene_root() && p_node->get_owner() != editor_data.get_edited_scene_root())) {
return;
+ }
- if (p_node->is_class("CanvasItem"))
+ if (p_node->is_class("CanvasItem")) {
count_2d++;
- else if (p_node->is_class("Node3D"))
+ } else if (p_node->is_class("Node3D")) {
count_3d++;
+ }
- for (int i = 0; i < p_node->get_child_count(); i++)
+ for (int i = 0; i < p_node->get_child_count(); i++) {
_find_node_types(p_node->get_child(i), count_2d, count_3d);
+ }
}
void EditorNode::_save_scene_with_preview(String p_file, int p_idx) {
@@ -1192,8 +1216,9 @@ int EditorNode::_save_external_resources() {
//save external resources and its subresources if any was modified
int flg = 0;
- if (EditorSettings::get_singleton()->get("filesystem/on_save/compress_binary_resources"))
+ if (EditorSettings::get_singleton()->get("filesystem/on_save/compress_binary_resources")) {
flg |= ResourceSaver::FLAG_COMPRESS;
+ }
flg |= ResourceSaver::FLAG_REPLACE_SUBRESOURCE_PATHS;
Set<Ref<Resource>> edited_subresources;
@@ -1202,8 +1227,9 @@ int EditorNode::_save_external_resources() {
ResourceCache::get_cached_resources(&cached);
for (List<Ref<Resource>>::Element *E = cached.front(); E; E = E->next()) {
Ref<Resource> res = E->get();
- if (!res->get_path().is_resource_file())
+ if (!res->get_path().is_resource_file()) {
continue;
+ }
//not only check if this resourec is edited, check contained subresources too
if (_find_edited_resources(res, edited_subresources)) {
ResourceSaver::save(res->get_path(), res, flg);
@@ -1248,10 +1274,11 @@ void EditorNode::_save_scene(String p_file, int idx) {
// old version still work for referencing changes in instanced or inherited scenes
sdata = Ref<PackedScene>(Object::cast_to<PackedScene>(ResourceCache::get(p_file)));
- if (sdata.is_valid())
+ if (sdata.is_valid()) {
sdata->recreate_state();
- else
+ } else {
sdata.instance();
+ }
} else {
sdata.instance();
}
@@ -1272,8 +1299,9 @@ void EditorNode::_save_scene(String p_file, int idx) {
memdelete(dummy_scene);
int flg = 0;
- if (EditorSettings::get_singleton()->get("filesystem/on_save/compress_binary_resources"))
+ if (EditorSettings::get_singleton()->get("filesystem/on_save/compress_binary_resources")) {
flg |= ResourceSaver::FLAG_COMPRESS;
+ }
flg |= ResourceSaver::FLAG_REPLACE_SUBRESOURCE_PATHS;
err = ResourceSaver::save(p_file, sdata, flg);
@@ -1283,10 +1311,11 @@ void EditorNode::_save_scene(String p_file, int idx) {
editor_data.save_editor_external_data();
if (err == OK) {
scene->set_filename(ProjectSettings::get_singleton()->localize_path(p_file));
- if (idx < 0 || idx == editor_data.get_edited_scene())
+ if (idx < 0 || idx == editor_data.get_edited_scene()) {
set_current_version(editor_data.get_undo_redo().get_version());
- else
+ } else {
editor_data.set_edited_scene_version(0, idx);
+ }
editor_folding.save_scene_folding(scene, p_file);
@@ -1337,10 +1366,11 @@ void EditorNode::_save_all_scenes() {
for (int i = 0; i < editor_data.get_edited_scene_count(); i++) {
Node *scene = editor_data.get_edited_scene_root(i);
if (scene && scene->get_filename() != "") {
- if (i != editor_data.get_edited_scene())
+ if (i != editor_data.get_edited_scene()) {
_save_scene(scene->get_filename(), i);
- else
+ } else {
_save_scene_with_preview(scene->get_filename());
+ }
} // else: ignore new scenes
}
@@ -1350,15 +1380,17 @@ void EditorNode::_save_all_scenes() {
void EditorNode::_mark_unsaved_scenes() {
for (int i = 0; i < editor_data.get_edited_scene_count(); i++) {
Node *node = editor_data.get_edited_scene_root(i);
- if (!node)
+ if (!node) {
continue;
+ }
String path = node->get_filename();
if (!(path == String() || FileAccess::exists(path))) {
- if (i == editor_data.get_edited_scene())
+ if (i == editor_data.get_edited_scene()) {
set_current_version(-1);
- else
+ } else {
editor_data.set_edited_scene_version(-1, i);
+ }
}
}
@@ -1371,8 +1403,9 @@ void EditorNode::_dialog_action(String p_file) {
case FILE_NEW_INHERITED_SCENE: {
Node *scene = editor_data.get_edited_scene_root();
// If the previous scene is rootless, just close it in favor of the new one.
- if (!scene)
+ if (!scene) {
_menu_option_confirm(FILE_CLOSE, true);
+ }
load_scene(p_file, false, true);
} break;
@@ -1401,8 +1434,9 @@ void EditorNode::_dialog_action(String p_file) {
if (file->get_file_mode() == EditorFileDialog::FILE_MODE_SAVE_FILE) {
bool same_open_scene = false;
for (int i = 0; i < editor_data.get_edited_scene_count(); i++) {
- if (editor_data.get_scene_path(i) == p_file && i != scene_idx)
+ if (editor_data.get_scene_path(i) == p_file && i != scene_idx) {
same_open_scene = true;
+ }
}
if (same_open_scene) {
@@ -1415,8 +1449,9 @@ void EditorNode::_dialog_action(String p_file) {
_add_to_recent_scenes(p_file);
save_layout();
- if (scene_idx != -1)
+ if (scene_idx != -1) {
_discard_changes();
+ }
}
} break;
@@ -1487,8 +1522,9 @@ void EditorNode::_dialog_action(String p_file) {
current_obj->_change_notify();
} break;
case SETTINGS_LAYOUT_SAVE: {
- if (p_file.empty())
+ if (p_file.empty()) {
return;
+ }
Ref<ConfigFile> config;
config.instance();
@@ -1514,8 +1550,9 @@ void EditorNode::_dialog_action(String p_file) {
} break;
case SETTINGS_LAYOUT_DELETE: {
- if (p_file.empty())
+ if (p_file.empty()) {
return;
+ }
Ref<ConfigFile> config;
config.instance();
@@ -1631,10 +1668,11 @@ void EditorNode::push_item(Object *p_object, const String &p_property, bool p_in
if (id != editor_history.get_current()) {
if (p_inspector_only) {
editor_history.add_object_inspector_only(id);
- } else if (p_property == "")
+ } else if (p_property == "") {
editor_history.add_object(id);
- else
+ } else {
editor_history.add_object(id, p_property);
+ }
}
_edit_current();
@@ -1671,8 +1709,9 @@ void EditorNode::_set_editing_top_editors(Object *p_current_object) {
static bool overrides_external_editor(Object *p_object) {
Script *script = Object::cast_to<Script>(p_object);
- if (!script)
+ if (!script) {
return false;
+ }
return script->get_language()->overrides_external_editor();
}
@@ -1814,16 +1853,18 @@ void EditorNode::_edit_current() {
if (main_plugin) {
// special case if use of external editor is true
if (main_plugin->get_name() == "Script" && current_obj->get_class_name() != StringName("VisualScript") && (bool(EditorSettings::get_singleton()->get("text_editor/external/use_external_editor")) || overrides_external_editor(current_obj))) {
- if (!changing_scene)
+ if (!changing_scene) {
main_plugin->edit(current_obj);
+ }
}
else if (main_plugin != editor_plugin_screen && (!ScriptEditor::get_singleton() || !ScriptEditor::get_singleton()->is_visible_in_tree() || ScriptEditor::get_singleton()->can_take_away_focus())) {
// update screen main_plugin
if (!changing_scene) {
- if (editor_plugin_screen)
+ if (editor_plugin_screen) {
editor_plugin_screen->make_visible(false);
+ }
editor_plugin_screen = main_plugin;
editor_plugin_screen->edit(current_obj);
@@ -1928,8 +1969,9 @@ void EditorNode::_run(bool p_current, const String &p_custom) {
editor_data.save_editor_external_data();
}
- if (!call_build())
+ if (!call_build()) {
return;
+ }
if (bool(EDITOR_GET("run/output/always_clear_output_on_play"))) {
log->clear();
@@ -1978,8 +2020,9 @@ void EditorNode::_run_native(const Ref<EditorExportPreset> &p_preset) {
if (run_native->is_deploy_debug_remote_enabled()) {
_menu_option_confirm(RUN_STOP, true);
- if (!call_build())
+ if (!call_build()) {
return; // build failed
+ }
EditorDebuggerNode::get_singleton()->start(p_preset->get_platform()->get_debug_protocol());
emit_signal("play_pressed");
@@ -1988,8 +2031,9 @@ void EditorNode::_run_native(const Ref<EditorExportPreset> &p_preset) {
}
void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
- if (!p_confirmed) //this may be a hack..
+ if (!p_confirmed) { //this may be a hack..
current_option = (MenuOptions)p_option;
+ }
switch (p_option) {
case FILE_NEW_SCENE: {
@@ -2030,8 +2074,9 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
} break;
case FILE_OPEN_PREV: {
- if (previous_scenes.empty())
+ if (previous_scenes.empty()) {
break;
+ }
opening_prev = true;
open_request(previous_scenes.back()->get());
previous_scenes.pop_back();
@@ -2045,14 +2090,16 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
next_tab %= editor_data.get_edited_scene_count();
_scene_tab_closed(next_tab, current_option);
} else {
- if (current_option != FILE_CLOSE_ALL)
+ if (current_option != FILE_CLOSE_ALL) {
current_option = -1;
- else
+ } else {
_scene_tab_closed(editor_data.get_edited_scene());
+ }
}
- if (p_confirmed)
+ if (p_confirmed) {
_menu_option_confirm(SCENE_TAB_CLOSE, true);
+ }
} break;
case FILE_CLOSE_ALL_AND_QUIT:
@@ -2085,13 +2132,15 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
Node *scene = editor_data.get_edited_scene_root(scene_idx);
if (scene && scene->get_filename() != "") {
- if (scene_idx != editor_data.get_edited_scene())
+ if (scene_idx != editor_data.get_edited_scene()) {
_save_scene_with_preview(scene->get_filename(), scene_idx);
- else
+ } else {
_save_scene_with_preview(scene->get_filename());
+ }
- if (scene_idx != -1)
+ if (scene_idx != -1) {
_discard_changes();
+ }
save_layout();
break;
@@ -2261,8 +2310,9 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
case EDIT_RELOAD_SAVED_SCENE: {
Node *scene = get_edited_scene();
- if (!scene)
+ if (!scene) {
break;
+ }
String filename = scene->get_filename();
@@ -2282,8 +2332,9 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
int cur_idx = editor_data.get_edited_scene();
_remove_edited_scene();
Error err = load_scene(filename);
- if (err != OK)
+ if (err != OK) {
ERR_PRINT("Failed to load scene");
+ }
editor_data.move_edited_scene_to_index(cur_idx);
get_undo_redo()->clear_history(false);
scene_tabs->set_current_tab(cur_idx);
@@ -2308,8 +2359,9 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
} break;
case RUN_STOP: {
- if (editor_run.get_status() == EditorRun::STATUS_STOP)
+ if (editor_run.get_status() == EditorRun::STATUS_STOP) {
break;
+ }
editor_run.stop();
run_custom_filename.clear();
@@ -2550,14 +2602,16 @@ void EditorNode::_tool_menu_option(int p_idx) {
int EditorNode::_next_unsaved_scene(bool p_valid_filename, int p_start) {
for (int i = p_start; i < editor_data.get_edited_scene_count(); i++) {
- if (!editor_data.get_edited_scene_root(i))
+ if (!editor_data.get_edited_scene_root(i)) {
continue;
+ }
int current = editor_data.get_edited_scene();
bool unsaved = (i == current) ? saved_version != editor_data.get_undo_redo().get_version() : editor_data.get_scene_version(i) != 0;
if (unsaved) {
String scene_filename = editor_data.get_edited_scene_root(i)->get_filename();
- if (p_valid_filename && scene_filename.length() == 0)
+ if (p_valid_filename && scene_filename.length() == 0) {
continue;
+ }
return i;
}
}
@@ -2658,13 +2712,15 @@ Control *EditorNode::get_viewport() {
void EditorNode::_editor_select(int p_which) {
static bool selecting = false;
- if (selecting || changing_scene)
+ if (selecting || changing_scene) {
return;
+ }
ERR_FAIL_INDEX(p_which, editor_table.size());
- if (!main_editor_buttons[p_which]->is_visible()) //button hidden, no editor
+ if (!main_editor_buttons[p_which]->is_visible()) { //button hidden, no editor
return;
+ }
selecting = true;
@@ -2677,8 +2733,9 @@ void EditorNode::_editor_select(int p_which) {
EditorPlugin *new_editor = editor_table[p_which];
ERR_FAIL_COND(!new_editor);
- if (editor_plugin_screen == new_editor)
+ if (editor_plugin_screen == new_editor) {
return;
+ }
if (editor_plugin_screen) {
editor_plugin_screen->make_visible(false);
@@ -2738,8 +2795,9 @@ void EditorNode::add_editor_plugin(EditorPlugin *p_editor, bool p_config_changed
}
singleton->editor_data.add_editor_plugin(p_editor);
singleton->add_child(p_editor);
- if (p_config_changed)
+ if (p_config_changed) {
p_editor->enable_plugin();
+ }
}
void EditorNode::remove_editor_plugin(EditorPlugin *p_editor, bool p_config_changed) {
@@ -2761,8 +2819,9 @@ void EditorNode::remove_editor_plugin(EditorPlugin *p_editor, bool p_config_chan
}
p_editor->make_visible(false);
p_editor->clear();
- if (p_config_changed)
+ if (p_config_changed) {
p_editor->disable_plugin();
+ }
singleton->editor_plugins_over->get_plugins_list().erase(p_editor);
singleton->remove_child(p_editor);
singleton->editor_data.remove_editor_plugin(p_editor);
@@ -2770,8 +2829,9 @@ void EditorNode::remove_editor_plugin(EditorPlugin *p_editor, bool p_config_chan
}
void EditorNode::_update_addon_config() {
- if (_initializing_addons)
+ if (_initializing_addons) {
return;
+ }
Vector<String> enabled_addons;
@@ -2889,8 +2949,9 @@ void EditorNode::_remove_edited_scene(bool p_change_tab) {
ScriptEditor::get_singleton()->close_builtin_scripts_from_scene(editor_data.get_scene_path(old_index));
}
- if (p_change_tab)
+ if (p_change_tab) {
_scene_tab_changed(new_index);
+ }
editor_data.remove_scene(old_index);
editor_data.get_undo_redo().clear_history(false);
_update_title();
@@ -2909,27 +2970,32 @@ void EditorNode::_remove_scene(int index, bool p_change_tab) {
void EditorNode::set_edited_scene(Node *p_scene) {
if (get_editor_data().get_edited_scene_root()) {
- if (get_editor_data().get_edited_scene_root()->get_parent() == scene_root)
+ if (get_editor_data().get_edited_scene_root()->get_parent() == scene_root) {
scene_root->remove_child(get_editor_data().get_edited_scene_root());
+ }
}
get_editor_data().set_edited_scene_root(p_scene);
- if (Object::cast_to<Popup>(p_scene))
+ if (Object::cast_to<Popup>(p_scene)) {
Object::cast_to<Popup>(p_scene)->show(); //show popups
+ }
scene_tree_dock->set_edited_scene(p_scene);
- if (get_tree())
+ if (get_tree()) {
get_tree()->set_edited_scene_root(p_scene);
+ }
if (p_scene) {
- if (p_scene->get_parent() != scene_root)
+ if (p_scene->get_parent() != scene_root) {
scene_root->add_child(p_scene);
+ }
}
}
int EditorNode::_get_current_main_editor() {
for (int i = 0; i < editor_table.size(); i++) {
- if (editor_table[i] == editor_plugin_screen)
+ if (editor_table[i] == editor_plugin_screen) {
return i;
+ }
}
return 0;
@@ -2946,8 +3012,9 @@ Dictionary EditorNode::_get_main_scene_state() {
}
void EditorNode::_set_main_scene_state(Dictionary p_state, Node *p_for_scene) {
- if (get_edited_scene() != p_for_scene && p_for_scene != nullptr)
+ if (get_edited_scene() != p_for_scene && p_for_scene != nullptr) {
return; //not for this scene
+ }
changing_scene = false;
@@ -2981,13 +3048,16 @@ void EditorNode::_set_main_scene_state(Dictionary p_state, Node *p_for_scene) {
}
}
- if (p_state.has("scene_tree_offset"))
+ if (p_state.has("scene_tree_offset")) {
scene_tree_dock->get_tree_editor()->get_scene_tree()->get_vscroll_bar()->set_value(p_state["scene_tree_offset"]);
- if (p_state.has("property_edit_offset"))
+ }
+ if (p_state.has("property_edit_offset")) {
get_inspector()->set_scroll_offset(p_state["property_edit_offset"]);
+ }
- if (p_state.has("node_filter"))
+ if (p_state.has("node_filter")) {
scene_tree_dock->set_filter(p_state["node_filter"]);
+ }
//this should only happen at the very end
@@ -3011,12 +3081,14 @@ void EditorNode::_clear_undo_history() {
void EditorNode::set_current_scene(int p_idx) {
//Save the folding in case the scene gets reloaded.
- if (editor_data.get_scene_path(p_idx) != "" && editor_data.get_edited_scene_root(p_idx))
+ if (editor_data.get_scene_path(p_idx) != "" && editor_data.get_edited_scene_root(p_idx)) {
editor_folding.save_scene_folding(editor_data.get_edited_scene_root(p_idx), editor_data.get_scene_path(p_idx));
+ }
if (editor_data.check_and_update_scene(p_idx)) {
- if (editor_data.get_scene_path(p_idx) != "")
+ if (editor_data.get_scene_path(p_idx) != "") {
editor_folding.load_scene_folding(editor_data.get_edited_scene_root(p_idx), editor_data.get_scene_path(p_idx));
+ }
call_deferred("_clear_undo_history");
}
@@ -3025,8 +3097,9 @@ void EditorNode::set_current_scene(int p_idx) {
editor_data.save_edited_scene_state(editor_selection, &editor_history, _get_main_scene_state());
if (get_editor_data().get_edited_scene_root()) {
- if (get_editor_data().get_edited_scene_root()->get_parent() == scene_root)
+ if (get_editor_data().get_edited_scene_root()->get_parent() == scene_root) {
scene_root->remove_child(get_editor_data().get_edited_scene_root());
+ }
}
editor_selection->clear();
@@ -3034,16 +3107,19 @@ void EditorNode::set_current_scene(int p_idx) {
Node *new_scene = editor_data.get_edited_scene_root();
- if (Object::cast_to<Popup>(new_scene))
+ if (Object::cast_to<Popup>(new_scene)) {
Object::cast_to<Popup>(new_scene)->show(); //show popups
+ }
scene_tree_dock->set_edited_scene(new_scene);
- if (get_tree())
+ if (get_tree()) {
get_tree()->set_edited_scene_root(new_scene);
+ }
if (new_scene) {
- if (new_scene->get_parent() != scene_root)
+ if (new_scene->get_parent() != scene_root) {
scene_root->add_child(new_scene);
+ }
}
Dictionary state = editor_data.restore_edited_scene_state(editor_selection, &editor_history);
@@ -3056,8 +3132,9 @@ void EditorNode::set_current_scene(int p_idx) {
bool EditorNode::is_scene_open(const String &p_path) {
for (int i = 0; i < editor_data.get_edited_scene_count(); i++) {
- if (editor_data.get_scene_path(i) == p_path)
+ if (editor_data.get_scene_path(i) == p_path) {
return true;
+ }
}
return false;
@@ -3098,8 +3175,9 @@ Error EditorNode::load_scene(const String &p_scene, bool p_ignore_broken_deps, b
}
}
- if (p_clear_errors)
+ if (p_clear_errors) {
load_errors->clear();
+ }
String lpath = ProjectSettings::get_singleton()->localize_path(p_scene);
@@ -3279,11 +3357,13 @@ void EditorNode::_show_messages() {
void EditorNode::_add_to_recent_scenes(const String &p_scene) {
Array rc = EditorSettings::get_singleton()->get_project_metadata("recent_files", "scenes", Array());
- if (rc.find(p_scene) != -1)
+ if (rc.find(p_scene) != -1) {
rc.erase(p_scene);
+ }
rc.push_front(p_scene);
- if (rc.size() > 10)
+ if (rc.size() > 10) {
rc.resize(10);
+ }
EditorSettings::get_singleton()->set_project_metadata("recent_files", "scenes", rc);
_update_recent_scenes();
@@ -3371,8 +3451,9 @@ bool EditorNode::_find_scene_in_use(Node *p_node, const String &p_path) const {
bool EditorNode::is_scene_in_use(const String &p_path) {
Node *es = get_edited_scene();
- if (es)
+ if (es) {
return _find_scene_in_use(es, p_path);
+ }
return false;
}
@@ -3419,8 +3500,9 @@ void EditorNode::unregister_editor_types() {
void EditorNode::stop_child_process(OS::ProcessID p_pid) {
if (has_child_process(p_pid)) {
editor_run.stop_child_process(p_pid);
- if (!editor_run.get_child_process_count()) // All children stopped. Closing.
+ if (!editor_run.get_child_process_count()) { // All children stopped. Closing.
_menu_option_confirm(RUN_STOP, false);
+ }
}
}
@@ -3467,8 +3549,9 @@ StringName EditorNode::get_object_custom_type_name(const Object *p_object) const
Ref<Script> base_script = script;
while (base_script.is_valid()) {
StringName name = EditorNode::get_editor_data().script_class_get_name(base_script->get_path());
- if (name != StringName())
+ if (name != StringName()) {
return name;
+ }
// should probably be deprecated in 4.x
StringName base = base_script->get_instance_base_type();
@@ -3534,14 +3617,17 @@ Ref<Texture2D> EditorNode::get_object_icon(const Object *p_object, const String
}
// should probably be deprecated in 4.x
- if (p_object->has_meta("_editor_icon"))
+ if (p_object->has_meta("_editor_icon")) {
return p_object->get_meta("_editor_icon");
+ }
- if (gui_base->has_theme_icon(p_object->get_class(), "EditorIcons"))
+ if (gui_base->has_theme_icon(p_object->get_class(), "EditorIcons")) {
return gui_base->get_theme_icon(p_object->get_class(), "EditorIcons");
+ }
- if (p_fallback.length())
+ if (p_fallback.length()) {
return gui_base->get_theme_icon(p_fallback, "EditorIcons");
+ }
return nullptr;
}
@@ -3591,8 +3677,9 @@ Ref<Texture2D> EditorNode::get_class_icon(const String &p_class, const String &p
}
}
- if (p_fallback.length() && gui_base->has_theme_icon(p_fallback, "EditorIcons"))
+ if (p_fallback.length() && gui_base->has_theme_icon(p_fallback, "EditorIcons")) {
return gui_base->get_theme_icon(p_fallback, "EditorIcons");
+ }
return nullptr;
}
@@ -3659,8 +3746,9 @@ void EditorNode::_build_icon_type_cache() {
StringName ei = "EditorIcons";
theme_base->get_theme()->get_icon_list(ei, &tl);
for (List<StringName>::Element *E = tl.front(); E; E = E->next()) {
- if (!ClassDB::class_exists(E->get()))
+ if (!ClassDB::class_exists(E->get())) {
continue;
+ }
icon_type_cache[E->get()] = theme_base->get_theme()->get_icon(E->get(), ei);
}
}
@@ -3784,16 +3872,18 @@ void EditorNode::_update_dock_containers() {
}
for (int i = 0; i < vsplits.size(); i++) {
bool in_use = dock_slot[i * 2 + 0]->get_tab_count() || dock_slot[i * 2 + 1]->get_tab_count();
- if (in_use)
+ if (in_use) {
vsplits[i]->show();
- else
+ } else {
vsplits[i]->hide();
+ }
}
- if (right_l_vsplit->is_visible() || right_r_vsplit->is_visible())
+ if (right_l_vsplit->is_visible() || right_r_vsplit->is_visible()) {
right_hsplit->show();
- else
+ } else {
right_hsplit->hide();
+ }
}
void EditorNode::_dock_select_input(const Ref<InputEvent> &p_input) {
@@ -3815,8 +3905,9 @@ void EditorNode::_dock_select_input(const Ref<InputEvent> &p_input) {
dock_select_rect_over = nrect;
}
- if (nrect == -1)
+ if (nrect == -1) {
return;
+ }
Ref<InputEventMouseButton> mb = me;
@@ -3856,12 +3947,14 @@ void EditorNode::_dock_pre_popup(int p_which) {
}
void EditorNode::_dock_move_left() {
- if (dock_popup_selected < 0 || dock_popup_selected >= DOCK_SLOT_MAX)
+ if (dock_popup_selected < 0 || dock_popup_selected >= DOCK_SLOT_MAX) {
return;
+ }
Control *current = dock_slot[dock_popup_selected]->get_tab_control(dock_slot[dock_popup_selected]->get_current_tab());
Control *prev = dock_slot[dock_popup_selected]->get_tab_control(dock_slot[dock_popup_selected]->get_current_tab() - 1);
- if (!current || !prev)
+ if (!current || !prev) {
return;
+ }
dock_slot[dock_popup_selected]->move_child(current, prev->get_index());
dock_slot[dock_popup_selected]->set_current_tab(dock_slot[dock_popup_selected]->get_current_tab() - 1);
dock_select->update();
@@ -3872,8 +3965,9 @@ void EditorNode::_dock_move_left() {
void EditorNode::_dock_move_right() {
Control *current = dock_slot[dock_popup_selected]->get_tab_control(dock_slot[dock_popup_selected]->get_current_tab());
Control *next = dock_slot[dock_popup_selected]->get_tab_control(dock_slot[dock_popup_selected]->get_current_tab() + 1);
- if (!current || !next)
+ if (!current || !next) {
return;
+ }
dock_slot[dock_popup_selected]->move_child(next, current->get_index());
dock_slot[dock_popup_selected]->set_current_tab(dock_slot[dock_popup_selected]->get_current_tab() + 1);
dock_select->update();
@@ -3959,8 +4053,9 @@ void EditorNode::_dock_select_draw() {
for (int j = 0; j < MIN(3, dock_slot[i]->get_child_count()); j++) {
int xofs = (r.size.width / 3) * j;
Color c = used;
- if (i == dock_popup_selected && (dock_slot[i]->get_current_tab() > 3 || dock_slot[i]->get_current_tab() == j))
+ if (i == dock_popup_selected && (dock_slot[i]->get_current_tab() > 3 || dock_slot[i]->get_current_tab() == j)) {
c = tab_selected;
+ }
dock_select->draw_rect(Rect2(2 + ofs.x + xofs, ofs.y, r.size.width / 3 - 1, 3), c);
}
}
@@ -3985,8 +4080,9 @@ void EditorNode::_save_docks_to_config(Ref<ConfigFile> p_layout, const String &p
String names;
for (int j = 0; j < dock_slot[i]->get_tab_count(); j++) {
String name = dock_slot[i]->get_tab_control(j)->get_name();
- if (names != "")
+ if (names != "") {
names += ",";
+ }
names += name;
}
@@ -4068,18 +4164,20 @@ void EditorNode::_update_dock_slots_visibility() {
tabs_visible++;
}
}
- if (tabs_visible)
+ if (tabs_visible) {
dock_slot[i]->show();
- else
+ } else {
dock_slot[i]->hide();
+ }
}
for (int i = 0; i < vsplits.size(); i++) {
bool in_use = dock_slot[i * 2 + 0]->get_tab_count() || dock_slot[i * 2 + 1]->get_tab_count();
- if (in_use)
+ if (in_use) {
vsplits[i]->show();
- else
+ } else {
vsplits[i]->hide();
+ }
}
for (int i = 0; i < DOCK_SLOT_MAX; i++) {
@@ -4089,10 +4187,11 @@ void EditorNode::_update_dock_slots_visibility() {
}
bottom_panel->show();
- if (right_l_vsplit->is_visible() || right_r_vsplit->is_visible())
+ if (right_l_vsplit->is_visible() || right_r_vsplit->is_visible()) {
right_hsplit->show();
- else
+ } else {
right_hsplit->hide();
+ }
}
}
@@ -4112,32 +4211,36 @@ void EditorNode::_dock_tab_changed(int p_tab) {
bottom_panel->hide();
} else {
for (int i = 0; i < DOCK_SLOT_MAX; i++) {
- if (dock_slot[i]->get_tab_count())
+ if (dock_slot[i]->get_tab_count()) {
dock_slot[i]->show();
- else
+ } else {
dock_slot[i]->hide();
+ }
}
for (int i = 0; i < vsplits.size(); i++) {
bool in_use = dock_slot[i * 2 + 0]->get_tab_count() || dock_slot[i * 2 + 1]->get_tab_count();
- if (in_use)
+ if (in_use) {
vsplits[i]->show();
- else
+ } else {
vsplits[i]->hide();
+ }
}
bottom_panel->show();
- if (right_l_vsplit->is_visible() || right_r_vsplit->is_visible())
+ if (right_l_vsplit->is_visible() || right_r_vsplit->is_visible()) {
right_hsplit->show();
- else
+ } else {
right_hsplit->hide();
+ }
}
}
void EditorNode::_load_docks_from_config(Ref<ConfigFile> p_layout, const String &p_section) {
for (int i = 0; i < DOCK_SLOT_MAX; i++) {
- if (!p_layout->has_section_key(p_section, "dock_" + itos(i + 1)))
+ if (!p_layout->has_section_key(p_section, "dock_" + itos(i + 1))) {
continue;
+ }
Vector<String> names = String(p_layout->get_value(p_section, "dock_" + itos(i + 1))).split(",");
@@ -4147,16 +4250,19 @@ void EditorNode::_load_docks_from_config(Ref<ConfigFile> p_layout, const String
int atidx = -1;
Control *node = nullptr;
for (int k = 0; k < DOCK_SLOT_MAX; k++) {
- if (!dock_slot[k]->has_node(name))
+ if (!dock_slot[k]->has_node(name)) {
continue;
+ }
node = Object::cast_to<Control>(dock_slot[k]->get_node(name));
- if (!node)
+ if (!node) {
continue;
+ }
atidx = k;
break;
}
- if (atidx == -1) //well, it's not anywhere
+ if (atidx == -1) { //well, it's not anywhere
continue;
+ }
if (atidx == i) {
node->raise();
@@ -4189,32 +4295,36 @@ void EditorNode::_load_docks_from_config(Ref<ConfigFile> p_layout, const String
}
for (int i = 0; i < vsplits.size(); i++) {
- if (!p_layout->has_section_key(p_section, "dock_split_" + itos(i + 1)))
+ if (!p_layout->has_section_key(p_section, "dock_split_" + itos(i + 1))) {
continue;
+ }
int ofs = p_layout->get_value(p_section, "dock_split_" + itos(i + 1));
vsplits[i]->set_split_offset(ofs);
}
for (int i = 0; i < hsplits.size(); i++) {
- if (!p_layout->has_section_key(p_section, "dock_hsplit_" + itos(i + 1)))
+ if (!p_layout->has_section_key(p_section, "dock_hsplit_" + itos(i + 1))) {
continue;
+ }
int ofs = p_layout->get_value(p_section, "dock_hsplit_" + itos(i + 1));
hsplits[i]->set_split_offset(ofs);
}
for (int i = 0; i < vsplits.size(); i++) {
bool in_use = dock_slot[i * 2 + 0]->get_tab_count() || dock_slot[i * 2 + 1]->get_tab_count();
- if (in_use)
+ if (in_use) {
vsplits[i]->show();
- else
+ } else {
vsplits[i]->hide();
+ }
}
- if (right_l_vsplit->is_visible() || right_r_vsplit->is_visible())
+ if (right_l_vsplit->is_visible() || right_r_vsplit->is_visible()) {
right_hsplit->show();
- else
+ } else {
right_hsplit->hide();
+ }
for (int i = 0; i < DOCK_SLOT_MAX; i++) {
if (dock_slot[i]->is_visible() && dock_slot[i]->get_tab_count()) {
@@ -4373,8 +4483,9 @@ void EditorNode::_layout_menu_option(int p_id) {
void EditorNode::_scene_tab_script_edited(int p_tab) {
Ref<Script> script = editor_data.get_scene_root_script(p_tab);
- if (script.is_valid())
+ if (script.is_valid()) {
inspector_dock->edit_resource(script);
+ }
}
void EditorNode::_scene_tab_closed(int p_tab, int option) {
@@ -4491,8 +4602,9 @@ void EditorNode::_scene_tab_changed(int p_tab) {
bool unsaved = (saved_version != editor_data.get_undo_redo().get_version());
- if (p_tab == editor_data.get_edited_scene())
+ if (p_tab == editor_data.get_edited_scene()) {
return; //pointless
+ }
uint64_t next_scene_version = editor_data.get_scene_version(p_tab);
@@ -4529,8 +4641,9 @@ ToolButton *EditorNode::add_bottom_panel_item(String p_text, Control *p_item) {
bool EditorNode::are_bottom_panels_hidden() const {
for (int i = 0; i < bottom_panel_items.size(); i++) {
- if (bottom_panel_items[i].button->is_pressed())
+ if (bottom_panel_items[i].button->is_pressed()) {
return false;
+ }
}
return true;
@@ -4810,8 +4923,9 @@ void EditorNode::add_tool_submenu_item(const String &p_name, PopupMenu *p_submen
void EditorNode::remove_tool_menu_item(const String &p_name) {
for (int i = 0; i < tool_menu->get_item_count(); i++) {
- if (tool_menu->get_item_id(i) != TOOLS_CUSTOM)
+ if (tool_menu->get_item_id(i) != TOOLS_CUSTOM) {
continue;
+ }
if (tool_menu->get_item_text(i) == p_name) {
if (tool_menu->get_item_submenu(i) != "") {
@@ -5087,8 +5201,9 @@ void EditorNode::_feature_profile_changed() {
main_editor_buttons[EDITOR_3D]->set_visible(!profile->is_feature_disabled(EditorFeatureProfile::FEATURE_3D));
main_editor_buttons[EDITOR_SCRIPT]->set_visible(!profile->is_feature_disabled(EditorFeatureProfile::FEATURE_SCRIPT));
- if (StreamPeerSSL::is_available())
+ if (StreamPeerSSL::is_available()) {
main_editor_buttons[EDITOR_ASSETLIB]->set_visible(!profile->is_feature_disabled(EditorFeatureProfile::FEATURE_ASSET_LIB));
+ }
if ((profile->is_feature_disabled(EditorFeatureProfile::FEATURE_3D) && singleton->main_editor_buttons[EDITOR_3D]->is_pressed()) ||
(profile->is_feature_disabled(EditorFeatureProfile::FEATURE_SCRIPT) && singleton->main_editor_buttons[EDITOR_SCRIPT]->is_pressed()) ||
(StreamPeerSSL::is_available() && profile->is_feature_disabled(EditorFeatureProfile::FEATURE_ASSET_LIB) && singleton->main_editor_buttons[EDITOR_ASSETLIB]->is_pressed())) {
@@ -5103,8 +5218,9 @@ void EditorNode::_feature_profile_changed() {
filesystem_dock->set_visible(true);
main_editor_buttons[EDITOR_3D]->set_visible(true);
main_editor_buttons[EDITOR_SCRIPT]->set_visible(true);
- if (StreamPeerSSL::is_available())
+ if (StreamPeerSSL::is_available()) {
main_editor_buttons[EDITOR_ASSETLIB]->set_visible(true);
+ }
}
_update_dock_slots_visibility();
@@ -5269,8 +5385,9 @@ EditorNode::EditorNode() {
TranslationServer::get_singleton()->set_enabled(false);
// load settings
- if (!EditorSettings::get_singleton())
+ if (!EditorSettings::get_singleton()) {
EditorSettings::create();
+ }
FileAccess::set_backup_save(EDITOR_GET("filesystem/on_save/safe_save_on_backup_then_rename"));
@@ -6142,8 +6259,9 @@ EditorNode::EditorNode() {
default_layout->set_value(docks_section, "dock_4", "FileSystem");
default_layout->set_value(docks_section, "dock_5", "Inspector,Node");
- for (int i = 0; i < vsplits.size(); i++)
+ for (int i = 0; i < vsplits.size(); i++) {
default_layout->set_value(docks_section, "dock_split_" + itos(i + 1), 0);
+ }
default_layout->set_value(docks_section, "dock_hsplit_1", 0);
default_layout->set_value(docks_section, "dock_hsplit_2", 70 * EDSCALE);
default_layout->set_value(docks_section, "dock_hsplit_3", -70 * EDSCALE);
@@ -6344,8 +6462,9 @@ EditorNode::EditorNode() {
add_editor_plugin(memnew(MeshEditorPlugin(this)));
add_editor_plugin(memnew(MaterialEditorPlugin(this)));
- for (int i = 0; i < EditorPlugins::get_plugin_count(); i++)
+ for (int i = 0; i < EditorPlugins::get_plugin_count(); i++) {
add_editor_plugin(EditorPlugins::create(i, this));
+ }
for (int i = 0; i < plugin_init_callback_count; i++) {
plugin_init_callbacks[i]();
@@ -6465,8 +6584,9 @@ EditorNode::EditorNode() {
pick_main_scene->get_ok()->set_text(TTR("Select"));
pick_main_scene->connect("confirmed", callable_mp(this, &EditorNode::_menu_option), varray(SETTINGS_PICK_MAIN_SCENE));
- for (int i = 0; i < _init_callbacks.size(); i++)
+ for (int i = 0; i < _init_callbacks.size(); i++) {
_init_callbacks[i]();
+ }
editor_data.add_edited_scene(-1);
editor_data.set_edited_scene(0);
diff --git a/editor/editor_node.h b/editor/editor_node.h
index a0f4d7db7c..dfe3d91c07 100644
--- a/editor/editor_node.h
+++ b/editor/editor_node.h
@@ -547,8 +547,9 @@ private:
static void _dependency_error_report(void *ud, const String &p_path, const String &p_dep, const String &p_type) {
EditorNode *en = (EditorNode *)ud;
- if (!en->dependency_errors.has(p_path))
+ if (!en->dependency_errors.has(p_path)) {
en->dependency_errors[p_path] = Set<String>();
+ }
en->dependency_errors[p_path].insert(p_dep + "::" + p_type);
}
@@ -801,10 +802,11 @@ public:
static void progress_end_task_bg(const String &p_task);
void save_scene_to_path(String p_file, bool p_with_preview = true) {
- if (p_with_preview)
+ if (p_with_preview) {
_save_scene_with_preview(p_file);
- else
+ } else {
_save_scene(p_file);
+ }
}
bool is_scene_in_use(const String &p_path);
diff --git a/editor/editor_path.cpp b/editor/editor_path.cpp
index 8d71dc6ca0..c249974f99 100644
--- a/editor/editor_path.cpp
+++ b/editor/editor_path.cpp
@@ -34,23 +34,28 @@
#include "editor_scale.h"
void EditorPath::_add_children_to_popup(Object *p_obj, int p_depth) {
- if (p_depth > 8)
+ if (p_depth > 8) {
return;
+ }
List<PropertyInfo> pinfo;
p_obj->get_property_list(&pinfo);
for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
- if (!(E->get().usage & PROPERTY_USAGE_EDITOR))
+ if (!(E->get().usage & PROPERTY_USAGE_EDITOR)) {
continue;
- if (E->get().hint != PROPERTY_HINT_RESOURCE_TYPE)
+ }
+ if (E->get().hint != PROPERTY_HINT_RESOURCE_TYPE) {
continue;
+ }
Variant value = p_obj->get(E->get().name);
- if (value.get_type() != Variant::OBJECT)
+ if (value.get_type() != Variant::OBJECT) {
continue;
+ }
Object *obj = value;
- if (!obj)
+ if (!obj) {
continue;
+ }
Ref<Texture2D> icon = EditorNode::get_singleton()->get_object_icon(obj);
@@ -65,8 +70,9 @@ void EditorPath::_add_children_to_popup(Object *p_obj, int p_depth) {
void EditorPath::_about_to_show() {
Object *obj = ObjectDB::get_instance(history->get_path_object(history->get_path_size() - 1));
- if (!obj)
+ if (!obj) {
return;
+ }
objects.clear();
get_popup()->clear();
@@ -82,32 +88,37 @@ void EditorPath::_about_to_show() {
void EditorPath::update_path() {
for (int i = 0; i < history->get_path_size(); i++) {
Object *obj = ObjectDB::get_instance(history->get_path_object(i));
- if (!obj)
+ if (!obj) {
continue;
+ }
Ref<Texture2D> icon = EditorNode::get_singleton()->get_object_icon(obj);
- if (icon.is_valid())
+ if (icon.is_valid()) {
set_icon(icon);
+ }
if (i == history->get_path_size() - 1) {
String name;
if (Object::cast_to<Resource>(obj)) {
Resource *r = Object::cast_to<Resource>(obj);
- if (r->get_path().is_resource_file())
+ if (r->get_path().is_resource_file()) {
name = r->get_path().get_file();
- else
+ } else {
name = r->get_name();
+ }
- if (name == "")
+ if (name == "") {
name = r->get_class();
- } else if (obj->is_class("EditorDebuggerRemoteObject"))
+ }
+ } else if (obj->is_class("EditorDebuggerRemoteObject")) {
name = obj->call("get_title");
- else if (Object::cast_to<Node>(obj))
+ } else if (Object::cast_to<Node>(obj)) {
name = Object::cast_to<Node>(obj)->get_name();
- else if (Object::cast_to<Resource>(obj) && Object::cast_to<Resource>(obj)->get_name() != "")
+ } else if (Object::cast_to<Resource>(obj) && Object::cast_to<Resource>(obj)->get_name() != "") {
name = Object::cast_to<Resource>(obj)->get_name();
- else
+ } else {
name = obj->get_class();
+ }
set_text(" " + name); // An extra space so the text is not too close of the icon.
set_tooltip(obj->get_class());
@@ -119,8 +130,9 @@ void EditorPath::_id_pressed(int p_idx) {
ERR_FAIL_INDEX(p_idx, objects.size());
Object *obj = ObjectDB::get_instance(objects[p_idx]);
- if (!obj)
+ if (!obj) {
return;
+ }
EditorNode::get_singleton()->push_item(obj);
}
diff --git a/editor/editor_plugin.cpp b/editor/editor_plugin.cpp
index f731a87cef..2365090f03 100644
--- a/editor/editor_plugin.cpp
+++ b/editor/editor_plugin.cpp
@@ -186,8 +186,9 @@ Array EditorInterface::get_open_scenes() const {
int scns_amount = scenes.size();
for (int idx_scn = 0; idx_scn < scns_amount; idx_scn++) {
- if (scenes[idx_scn].root == nullptr)
+ if (scenes[idx_scn].root == nullptr) {
continue;
+ }
ret.push_back(scenes[idx_scn].root->get_filename());
}
return ret;
@@ -250,10 +251,12 @@ EditorInspector *EditorInterface::get_inspector() const {
}
Error EditorInterface::save_scene() {
- if (!get_edited_scene_root())
+ if (!get_edited_scene_root()) {
return ERR_CANT_CREATE;
- if (get_edited_scene_root()->get_filename() == String())
+ }
+ if (get_edited_scene_root()->get_filename() == String()) {
return ERR_CANT_CREATE;
+ }
save_scene_as(get_edited_scene_root()->get_filename());
return OK;
@@ -481,8 +484,9 @@ void EditorPlugin::notify_scene_changed(const Node *scn_root) {
}
void EditorPlugin::notify_main_screen_changed(const String &screen_name) {
- if (screen_name == last_main_screen_name)
+ if (screen_name == last_main_screen_name) {
return;
+ }
emit_signal("main_screen_changed", screen_name);
last_main_screen_name = screen_name;
@@ -639,8 +643,9 @@ void EditorPlugin::apply_changes() {
void EditorPlugin::get_breakpoints(List<String> *p_breakpoints) {
if (get_script_instance() && get_script_instance()->has_method("get_breakpoints")) {
PackedStringArray arr = get_script_instance()->call("get_breakpoints");
- for (int i = 0; i < arr.size(); i++)
+ for (int i = 0; i < arr.size(); i++) {
p_breakpoints->push_back(arr[i]);
+ }
}
}
diff --git a/editor/editor_plugin_settings.cpp b/editor/editor_plugin_settings.cpp
index 764d1af451..b5f1133a9e 100644
--- a/editor/editor_plugin_settings.cpp
+++ b/editor/editor_plugin_settings.cpp
@@ -146,8 +146,9 @@ void EditorPluginSettings::update_plugins() {
}
void EditorPluginSettings::_plugin_activity_changed() {
- if (updating)
+ if (updating) {
return;
+ }
TreeItem *ti = plugin_list->get_edited();
ERR_FAIL_COND(!ti);
@@ -172,8 +173,9 @@ void EditorPluginSettings::_create_clicked() {
void EditorPluginSettings::_cell_button_pressed(Object *p_item, int p_column, int p_id) {
TreeItem *item = Object::cast_to<TreeItem>(p_item);
- if (!item)
+ if (!item) {
return;
+ }
if (p_id == BUTTON_PLUGIN_EDIT) {
if (p_column == 4) {
String dir = item->get_metadata(0);
diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp
index e5ca5d95e8..81c4e48974 100644
--- a/editor/editor_properties.cpp
+++ b/editor/editor_properties.cpp
@@ -51,8 +51,9 @@ EditorPropertyNil::EditorPropertyNil() {
///////////////////// TEXT /////////////////////////
void EditorPropertyText::_text_entered(const String &p_string) {
- if (updating)
+ if (updating) {
return;
+ }
if (text->has_focus()) {
text->release_focus();
@@ -61,8 +62,9 @@ void EditorPropertyText::_text_entered(const String &p_string) {
}
void EditorPropertyText::_text_changed(const String &p_string) {
- if (updating)
+ if (updating) {
return;
+ }
if (string_name) {
emit_changed(get_edited_property(), StringName(p_string), "", true);
@@ -366,16 +368,18 @@ void EditorPropertyMember::_property_select() {
type = Variant::Type(i);
}
}
- if (type != Variant::NIL)
+ if (type != Variant::NIL) {
selector->select_method_from_basic_type(type, current);
+ }
} else if (hint == MEMBER_METHOD_OF_BASE_TYPE) {
selector->select_method_from_base_type(hint_text, current);
} else if (hint == MEMBER_METHOD_OF_INSTANCE) {
Object *instance = ObjectDB::get_instance(ObjectID(hint_text.to_int64()));
- if (instance)
+ if (instance) {
selector->select_method_from_instance(instance, current);
+ }
} else if (hint == MEMBER_METHOD_OF_SCRIPT) {
Object *obj = ObjectDB::get_instance(ObjectID(hint_text.to_int64()));
@@ -386,24 +390,27 @@ void EditorPropertyMember::_property_select() {
} else if (hint == MEMBER_PROPERTY_OF_VARIANT_TYPE) {
Variant::Type type = Variant::NIL;
String tname = hint_text;
- if (tname.find(".") != -1)
+ if (tname.find(".") != -1) {
tname = tname.get_slice(".", 0);
+ }
for (int i = 0; i < Variant::VARIANT_MAX; i++) {
if (tname == Variant::get_type_name(Variant::Type(i))) {
type = Variant::Type(Variant::Type(i));
}
}
- if (type != Variant::NIL)
+ if (type != Variant::NIL) {
selector->select_property_from_basic_type(type, current);
+ }
} else if (hint == MEMBER_PROPERTY_OF_BASE_TYPE) {
selector->select_property_from_base_type(hint_text, current);
} else if (hint == MEMBER_PROPERTY_OF_INSTANCE) {
Object *instance = ObjectDB::get_instance(ObjectID(hint_text.to_int64()));
- if (instance)
+ if (instance) {
selector->select_property_from_instance(instance, current);
+ }
} else if (hint == MEMBER_PROPERTY_OF_SCRIPT) {
Object *obj = ObjectDB::get_instance(ObjectID(hint_text.to_int64()));
@@ -479,8 +486,9 @@ void EditorPropertyEnum::setup(const Vector<String> &p_options) {
int64_t current_val = 0;
for (int i = 0; i < p_options.size(); i++) {
Vector<String> text_split = p_options[i].split(":");
- if (text_split.size() != 1)
+ if (text_split.size() != 1) {
current_val = text_split[1].to_int64();
+ }
options->add_item(text_split[0]);
options->set_item_metadata(i, current_val);
current_val += 1;
@@ -619,14 +627,16 @@ public:
Color color = get_theme_color("highlight_color", "Editor");
for (int i = 0; i < 2; i++) {
Point2 ofs(4, vofs);
- if (i == 1)
+ if (i == 1) {
ofs.y += bsize + 1;
+ }
ofs += rect.position;
for (int j = 0; j < 10; j++) {
Point2 o = ofs + Point2(j * (bsize + 1), 0);
- if (j >= 5)
+ if (j >= 5) {
o.x += 1;
+ }
uint32_t idx = i * 10 + j;
bool on = value & (1 << idx);
@@ -756,8 +766,9 @@ EditorPropertyLayers::EditorPropertyLayers() {
///////////////////// INT /////////////////////////
void EditorPropertyInteger::_value_changed(int64_t val) {
- if (setting)
+ if (setting) {
return;
+ }
emit_changed(get_edited_property(), val);
}
@@ -802,8 +813,9 @@ void EditorPropertyObjectID::_edit_pressed() {
void EditorPropertyObjectID::update_property() {
String type = base_type;
- if (type == "")
+ if (type == "") {
type = "Object";
+ }
ObjectID id = get_edited_object()->get(get_edited_property());
if (id.is_valid()) {
@@ -834,8 +846,9 @@ EditorPropertyObjectID::EditorPropertyObjectID() {
///////////////////// FLOAT /////////////////////////
void EditorPropertyFloat::_value_changed(double val) {
- if (setting)
+ if (setting) {
return;
+ }
emit_changed(get_edited_property(), val);
}
@@ -898,15 +911,18 @@ void EditorPropertyEasing::_drag_easing(const Ref<InputEvent> &p_ev) {
if (mm.is_valid() && mm->get_button_mask() & BUTTON_MASK_LEFT) {
float rel = mm->get_relative().x;
- if (rel == 0)
+ if (rel == 0) {
return;
+ }
- if (flip)
+ if (flip) {
rel = -rel;
+ }
float val = get_edited_object()->get(get_edited_property());
- if (val == 0)
+ if (val == 0) {
return;
+ }
bool sg = val < 0;
val = Math::absf(val);
@@ -915,8 +931,9 @@ void EditorPropertyEasing::_drag_easing(const Ref<InputEvent> &p_ev) {
val += rel * 0.05;
val = Math::pow(2.0f, val);
- if (sg)
+ if (sg) {
val = -val;
+ }
emit_changed(get_edited_property(), val);
easing_draw->update();
@@ -983,8 +1000,9 @@ void EditorPropertyEasing::_setup_spin() {
}
void EditorPropertyEasing::_spin_value_changed(double p_value) {
- if (setting)
+ if (setting) {
return;
+ }
// 0 is a singularity, but both positive and negative values
// are otherwise allowed. Enforce 0+ as workaround.
@@ -1060,8 +1078,9 @@ EditorPropertyEasing::EditorPropertyEasing() {
///////////////////// VECTOR2 /////////////////////////
void EditorPropertyVector2::_value_changed(double val, const String &p_name) {
- if (setting)
+ if (setting) {
return;
+ }
Vector2 v2;
v2.x = spin[0]->get_value();
@@ -1141,8 +1160,9 @@ EditorPropertyVector2::EditorPropertyVector2(bool p_force_wide) {
///////////////////// RECT2 /////////////////////////
void EditorPropertyRect2::_value_changed(double val, const String &p_name) {
- if (setting)
+ if (setting) {
return;
+ }
Rect2 r2;
r2.position.x = spin[0]->get_value();
@@ -1226,8 +1246,9 @@ EditorPropertyRect2::EditorPropertyRect2(bool p_force_wide) {
///////////////////// VECTOR3 /////////////////////////
void EditorPropertyVector3::_value_changed(double val, const String &p_name) {
- if (setting)
+ if (setting) {
return;
+ }
Vector3 v3;
v3.x = spin[0]->get_value();
@@ -1309,8 +1330,9 @@ EditorPropertyVector3::EditorPropertyVector3(bool p_force_wide) {
///////////////////// VECTOR2i /////////////////////////
void EditorPropertyVector2i::_value_changed(double val, const String &p_name) {
- if (setting)
+ if (setting) {
return;
+ }
Vector2i v2;
v2.x = spin[0]->get_value();
@@ -1390,8 +1412,9 @@ EditorPropertyVector2i::EditorPropertyVector2i(bool p_force_wide) {
///////////////////// RECT2 /////////////////////////
void EditorPropertyRect2i::_value_changed(double val, const String &p_name) {
- if (setting)
+ if (setting) {
return;
+ }
Rect2i r2;
r2.position.x = spin[0]->get_value();
@@ -1475,8 +1498,9 @@ EditorPropertyRect2i::EditorPropertyRect2i(bool p_force_wide) {
///////////////////// VECTOR3 /////////////////////////
void EditorPropertyVector3i::_value_changed(double val, const String &p_name) {
- if (setting)
+ if (setting) {
return;
+ }
Vector3i v3;
v3.x = spin[0]->get_value();
@@ -1557,8 +1581,9 @@ EditorPropertyVector3i::EditorPropertyVector3i(bool p_force_wide) {
///////////////////// PLANE /////////////////////////
void EditorPropertyPlane::_value_changed(double val, const String &p_name) {
- if (setting)
+ if (setting) {
return;
+ }
Plane p;
p.normal.x = spin[0]->get_value();
@@ -1642,8 +1667,9 @@ EditorPropertyPlane::EditorPropertyPlane(bool p_force_wide) {
///////////////////// QUAT /////////////////////////
void EditorPropertyQuat::_value_changed(double val, const String &p_name) {
- if (setting)
+ if (setting) {
return;
+ }
Quat p;
p.x = spin[0]->get_value();
@@ -1724,8 +1750,9 @@ EditorPropertyQuat::EditorPropertyQuat() {
///////////////////// AABB /////////////////////////
void EditorPropertyAABB::_value_changed(double val, const String &p_name) {
- if (setting)
+ if (setting) {
return;
+ }
AABB p;
p.position.x = spin[0]->get_value();
@@ -1799,8 +1826,9 @@ EditorPropertyAABB::EditorPropertyAABB() {
///////////////////// TRANSFORM2D /////////////////////////
void EditorPropertyTransform2D::_value_changed(double val, const String &p_name) {
- if (setting)
+ if (setting) {
return;
+ }
Transform2D p;
p[0][0] = spin[0]->get_value();
@@ -1873,8 +1901,9 @@ EditorPropertyTransform2D::EditorPropertyTransform2D() {
///////////////////// BASIS /////////////////////////
void EditorPropertyBasis::_value_changed(double val, const String &p_name) {
- if (setting)
+ if (setting) {
return;
+ }
Basis p;
p[0][0] = spin[0]->get_value();
@@ -1953,8 +1982,9 @@ EditorPropertyBasis::EditorPropertyBasis() {
///////////////////// TRANSFORM /////////////////////////
void EditorPropertyTransform::_value_changed(double val, const String &p_name) {
- if (setting)
+ if (setting) {
return;
+ }
Transform p;
p.basis[0][0] = spin[0]->get_value();
@@ -2049,10 +2079,11 @@ void EditorPropertyColor::_popup_closed() {
void EditorPropertyColor::_picker_created() {
// get default color picker mode from editor settings
int default_color_mode = EDITOR_GET("interface/inspector/default_color_picker_mode");
- if (default_color_mode == 1)
+ if (default_color_mode == 1) {
picker->get_picker()->set_hsv_mode(true);
- else if (default_color_mode == 2)
+ } else if (default_color_mode == 2) {
picker->get_picker()->set_raw_mode(true);
+ }
}
void EditorPropertyColor::_bind_methods() {
@@ -2263,8 +2294,9 @@ void EditorPropertyResource::_file_selected(const String &p_path) {
}
}
- if (!any_type_matches)
+ if (!any_type_matches) {
EditorNode::get_singleton()->show_warning(vformat(TTR("The selected resource (%s) does not match any type expected for this property (%s)."), res->get_class(), property_types));
+ }
}
emit_changed(get_edited_property(), res);
@@ -2316,8 +2348,9 @@ void EditorPropertyResource::_menu_option(int p_which) {
case OBJ_MENU_MAKE_UNIQUE: {
RES res_orig = get_edited_object()->get(get_edited_property());
- if (res_orig.is_null())
+ if (res_orig.is_null()) {
return;
+ }
List<PropertyInfo> property_list;
res_orig->get_property_list(&property_list);
@@ -2354,8 +2387,9 @@ void EditorPropertyResource::_menu_option(int p_which) {
case OBJ_MENU_SAVE: {
RES res = get_edited_object()->get(get_edited_property());
- if (res.is_null())
+ if (res.is_null()) {
return;
+ }
EditorNode::get_singleton()->save_resource(res);
} break;
@@ -2556,20 +2590,23 @@ void EditorPropertyResource::_update_menu_items() {
for (int j = 0; j < custom_resources.size(); j++) {
if (custom_resources[j].name == t) {
is_custom_resource = true;
- if (custom_resources[j].icon.is_valid())
+ if (custom_resources[j].icon.is_valid()) {
icon = custom_resources[j].icon;
+ }
break;
}
}
}
- if (!is_custom_resource && !(ScriptServer::is_global_class(t) || ClassDB::can_instance(t)))
+ if (!is_custom_resource && !(ScriptServer::is_global_class(t) || ClassDB::can_instance(t))) {
continue;
+ }
inheritors_array.push_back(t);
- if (!icon.is_valid())
+ if (!icon.is_valid()) {
icon = get_theme_icon(has_theme_icon(t, "EditorIcons") ? t : "Object", "EditorIcons");
+ }
int id = TYPE_BASE_ID + idx;
menu->add_icon_item(icon, vformat(TTR("New %s"), t), id);
@@ -2578,8 +2615,9 @@ void EditorPropertyResource::_update_menu_items() {
}
}
- if (menu->get_item_count())
+ if (menu->get_item_count()) {
menu->add_separator();
+ }
}
menu->add_icon_item(get_theme_icon("Load", "EditorIcons"), TTR("Load"), OBJ_MENU_LOAD);
@@ -2599,14 +2637,16 @@ void EditorPropertyResource::_update_menu_items() {
RES cb = EditorSettings::get_singleton()->get_resource_clipboard();
bool paste_valid = false;
if (cb.is_valid()) {
- if (base_type == "")
+ if (base_type == "") {
paste_valid = true;
- else
- for (int i = 0; i < base_type.get_slice_count(","); i++)
+ } else {
+ for (int i = 0; i < base_type.get_slice_count(","); i++) {
if (ClassDB::is_parent_class(cb->get_class(), base_type.get_slice(",", i))) {
paste_valid = true;
break;
}
+ }
+ }
}
if (!res.is_null() || paste_valid) {
@@ -2691,8 +2731,9 @@ void EditorPropertyResource::_fold_other_editors(Object *p_self) {
RES res = get_edited_object()->get(get_edited_property());
- if (!res.is_valid())
+ if (!res.is_valid()) {
return;
+ }
bool use_editor = false;
for (int i = 0; i < EditorNode::get_editor_data().get_editor_plugin_count(); i++) {
EditorPlugin *ep = EditorNode::get_editor_data().get_editor_plugin(i);
@@ -2701,8 +2742,9 @@ void EditorPropertyResource::_fold_other_editors(Object *p_self) {
}
}
- if (!use_editor)
+ if (!use_editor) {
return;
+ }
bool unfolded = get_edited_object()->editor_is_section_unfolded(get_edited_property());
opened_editor = false;
diff --git a/editor/editor_properties_array_dict.cpp b/editor/editor_properties_array_dict.cpp
index cf2104bc08..51fac6acec 100644
--- a/editor/editor_properties_array_dict.cpp
+++ b/editor/editor_properties_array_dict.cpp
@@ -501,15 +501,17 @@ void EditorPropertyArray::_edit_pressed() {
}
void EditorPropertyArray::_page_changed(double p_page) {
- if (updating)
+ if (updating) {
return;
+ }
page_idx = p_page;
update_property();
}
void EditorPropertyArray::_length_changed(double p_page) {
- if (updating)
+ if (updating) {
return;
+ }
Variant array = object->get_array();
int previous_size = array.call("size");
@@ -1051,8 +1053,9 @@ void EditorPropertyDictionary::_edit_pressed() {
}
void EditorPropertyDictionary::_page_changed(double p_page) {
- if (updating)
+ if (updating) {
return;
+ }
page_idx = p_page;
update_property();
}
diff --git a/editor/editor_resource_preview.cpp b/editor/editor_resource_preview.cpp
index d389a076b7..7ac8fae156 100644
--- a/editor/editor_resource_preview.cpp
+++ b/editor/editor_resource_preview.cpp
@@ -61,8 +61,9 @@ Ref<Texture2D> EditorResourcePreviewGenerator::generate_from_path(const String &
}
RES res = ResourceLoader::load(p_path);
- if (!res.is_valid())
+ if (!res.is_valid()) {
return res;
+ }
return generate(res, p_size);
}
@@ -131,10 +132,11 @@ void EditorResourcePreview::_preview_ready(const String &p_str, const Ref<Textur
void EditorResourcePreview::_generate_preview(Ref<ImageTexture> &r_texture, Ref<ImageTexture> &r_small_texture, const QueueItem &p_item, const String &cache_base) {
String type;
- if (p_item.resource.is_valid())
+ if (p_item.resource.is_valid()) {
type = p_item.resource->get_class();
- else
+ } else {
type = ResourceLoader::get_resource_type(p_item.path);
+ }
if (type == "") {
r_texture = Ref<ImageTexture>();
@@ -149,8 +151,9 @@ void EditorResourcePreview::_generate_preview(Ref<ImageTexture> &r_texture, Ref<
r_small_texture = Ref<ImageTexture>();
for (int i = 0; i < preview_generators.size(); i++) {
- if (!preview_generators[i]->handles(type))
+ if (!preview_generators[i]->handles(type)) {
continue;
+ }
Ref<Texture2D> generated;
if (p_item.resource.is_valid()) {
diff --git a/editor/editor_run.cpp b/editor/editor_run.cpp
index 00befb89f2..1148a6c7ec 100644
--- a/editor/editor_run.cpp
+++ b/editor/editor_run.cpp
@@ -156,8 +156,9 @@ Error EditorRun::run(const String &p_scene, const String &p_custom_args, const L
String bpoints;
for (const List<String>::Element *E = p_breakpoints.front(); E; E = E->next()) {
bpoints += E->get().replace(" ", "%20");
- if (E->next())
+ if (E->next()) {
bpoints += ",";
+ }
}
args.push_back(bpoints);
@@ -201,8 +202,9 @@ Error EditorRun::run(const String &p_scene, const String &p_custom_args, const L
bool EditorRun::has_child_process(OS::ProcessID p_pid) const {
for (const List<OS::ProcessID>::Element *E = pids.front(); E; E = E->next()) {
- if (E->get() == p_pid)
+ if (E->get() == p_pid) {
return true;
+ }
}
return false;
}
diff --git a/editor/editor_run_native.cpp b/editor/editor_run_native.cpp
index 16b8d6d110..9a834977fd 100644
--- a/editor/editor_run_native.cpp
+++ b/editor/editor_run_native.cpp
@@ -38,8 +38,9 @@ void EditorRunNative::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE) {
for (int i = 0; i < EditorExport::get_singleton()->get_export_platform_count(); i++) {
Ref<EditorExportPlatform> eep = EditorExport::get_singleton()->get_export_platform(i);
- if (eep.is_null())
+ if (eep.is_null()) {
continue;
+ }
Ref<ImageTexture> icon = eep->get_run_icon();
if (!icon.is_null()) {
Ref<Image> im = icon->get_data();
@@ -133,14 +134,18 @@ void EditorRunNative::_run_native(int p_idx, int p_platform) {
bool debug_collisions = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_debug_collisons", false);
bool debug_navigation = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_debug_navigation", false);
- if (deploy_debug_remote)
+ if (deploy_debug_remote) {
flags |= EditorExportPlatform::DEBUG_FLAG_REMOTE_DEBUG;
- if (deploy_dumb)
+ }
+ if (deploy_dumb) {
flags |= EditorExportPlatform::DEBUG_FLAG_DUMB_CLIENT;
- if (debug_collisions)
+ }
+ if (debug_collisions) {
flags |= EditorExportPlatform::DEBUG_FLAG_VIEW_COLLISONS;
- if (debug_navigation)
+ }
+ if (debug_navigation) {
flags |= EditorExportPlatform::DEBUG_FLAG_VIEW_NAVIGATION;
+ }
eep->run(preset, p_idx, flags);
}
diff --git a/editor/editor_sectioned_inspector.cpp b/editor/editor_sectioned_inspector.cpp
index c5e0c091e8..eabbf6b0d8 100644
--- a/editor/editor_sectioned_inspector.cpp
+++ b/editor/editor_sectioned_inspector.cpp
@@ -40,8 +40,9 @@ class SectionedInspectorFilter : public Object {
bool allow_sub;
bool _set(const StringName &p_name, const Variant &p_value) {
- if (!edited)
+ if (!edited) {
return false;
+ }
String name = p_name;
if (section != "") {
@@ -54,8 +55,9 @@ class SectionedInspectorFilter : public Object {
}
bool _get(const StringName &p_name, Variant &r_ret) const {
- if (!edited)
+ if (!edited) {
return false;
+ }
String name = p_name;
if (section != "") {
@@ -68,8 +70,9 @@ class SectionedInspectorFilter : public Object {
return valid;
}
void _get_property_list(List<PropertyInfo> *p_list) const {
- if (!edited)
+ if (!edited) {
return;
+ }
List<PropertyInfo> pinfo;
edited->get_property_list(&pinfo);
@@ -77,8 +80,9 @@ class SectionedInspectorFilter : public Object {
PropertyInfo pi = E->get();
int sp = pi.name.find("/");
- if (pi.name == "resource_path" || pi.name == "resource_name" || pi.name == "resource_local_to_scene" || pi.name.begins_with("script/") || pi.name.begins_with("_global_script")) //skip resource stuff
+ if (pi.name == "resource_path" || pi.name == "resource_name" || pi.name == "resource_local_to_scene" || pi.name.begins_with("script/") || pi.name.begins_with("_global_script")) { //skip resource stuff
continue;
+ }
if (sp == -1) {
pi.name = "global/" + pi.name;
@@ -86,8 +90,9 @@ class SectionedInspectorFilter : public Object {
if (pi.name.begins_with(section + "/")) {
pi.name = pi.name.replace_first(section + "/", "");
- if (!allow_sub && pi.name.find("/") != -1)
+ if (!allow_sub && pi.name.find("/") != -1) {
continue;
+ }
p_list->push_back(pi);
}
}
@@ -129,8 +134,9 @@ void SectionedInspector::_bind_methods() {
}
void SectionedInspector::_section_selected() {
- if (!sections->get_selected())
+ if (!sections->get_selected()) {
return;
+ }
selected_category = sections->get_selected()->get_metadata(0);
filter->set_section(selected_category, sections->get_selected()->get_children() == nullptr);
@@ -144,19 +150,21 @@ void SectionedInspector::set_current_section(const String &p_section) {
}
String SectionedInspector::get_current_section() const {
- if (sections->get_selected())
+ if (sections->get_selected()) {
return sections->get_selected()->get_metadata(0);
- else
+ } else {
return "";
+ }
}
String SectionedInspector::get_full_item_path(const String &p_item) {
String base = get_current_section();
- if (base != "")
+ if (base != "") {
return base + "/" + p_item;
- else
+ } else {
return p_item;
+ }
}
void SectionedInspector::edit(Object *p_object) {
@@ -183,8 +191,9 @@ void SectionedInspector::edit(Object *p_object) {
TreeItem *first_item = sections->get_root();
if (first_item) {
- while (first_item->get_children())
+ while (first_item->get_children()) {
first_item = first_item->get_children();
+ }
first_item->select(0);
selected_category = first_item->get_metadata(0);
@@ -199,8 +208,9 @@ void SectionedInspector::update_category_list() {
Object *o = ObjectDB::get_instance(obj);
- if (!o)
+ if (!o) {
return;
+ }
List<PropertyInfo> pinfo;
o->get_property_list(&pinfo);
@@ -211,26 +221,31 @@ void SectionedInspector::update_category_list() {
section_map[""] = root;
String filter;
- if (search_box)
+ if (search_box) {
filter = search_box->get_text();
+ }
for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
PropertyInfo pi = E->get();
- if (pi.usage & PROPERTY_USAGE_CATEGORY)
+ if (pi.usage & PROPERTY_USAGE_CATEGORY) {
continue;
- else if (!(pi.usage & PROPERTY_USAGE_EDITOR))
+ } else if (!(pi.usage & PROPERTY_USAGE_EDITOR)) {
continue;
+ }
- if (pi.name.find(":") != -1 || pi.name == "script" || pi.name == "resource_name" || pi.name == "resource_path" || pi.name == "resource_local_to_scene" || pi.name.begins_with("_global_script"))
+ if (pi.name.find(":") != -1 || pi.name == "script" || pi.name == "resource_name" || pi.name == "resource_path" || pi.name == "resource_local_to_scene" || pi.name.begins_with("_global_script")) {
continue;
+ }
- if (!filter.empty() && !filter.is_subsequence_ofi(pi.name) && !filter.is_subsequence_ofi(pi.name.replace("/", " ").capitalize()))
+ if (!filter.empty() && !filter.is_subsequence_ofi(pi.name) && !filter.is_subsequence_ofi(pi.name.replace("/", " ").capitalize())) {
continue;
+ }
int sp = pi.name.find("/");
- if (sp == -1)
+ if (sp == -1) {
pi.name = "global/" + pi.name;
+ }
Vector<String> sectionarr = pi.name.split("/");
String metasection;
diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp
index bbb4881d14..a16605ab44 100644
--- a/editor/editor_settings.cpp
+++ b/editor/editor_settings.cpp
@@ -129,8 +129,9 @@ bool EditorSettings::_get(const StringName &p_name, Variant &r_ret) const {
}
Ref<InputEvent> original = sc->get_meta("original");
- if (sc->is_shortcut(original) || (original.is_null() && sc->get_shortcut().is_null()))
+ if (sc->is_shortcut(original) || (original.is_null() && sc->get_shortcut().is_null())) {
continue; //not changed from default, don't save
+ }
}
arr.push_back(E->key());
@@ -174,8 +175,9 @@ void EditorSettings::_get_property_list(List<PropertyInfo> *p_list) const {
while ((k = props.next(k))) {
const VariantContainer *v = props.getptr(*k);
- if (v->hide_from_editor)
+ if (v->hide_from_editor) {
continue;
+ }
_EVCSort vc;
vc.name = *k;
@@ -206,8 +208,9 @@ void EditorSettings::_get_property_list(List<PropertyInfo> *p_list) const {
PropertyInfo pi(E->get().type, E->get().name);
pi.usage = pinfo;
- if (hints.has(E->get().name))
+ if (hints.has(E->get().name)) {
pi = hints[E->get().name];
+ }
if (E->get().restart_if_changed) {
pi.usage |= PROPERTY_USAGE_RESTART_IF_CHANGED;
@@ -229,10 +232,12 @@ void EditorSettings::_add_property_info_bind(const Dictionary &p_info) {
pinfo.type = Variant::Type(p_info["type"].operator int());
ERR_FAIL_INDEX(pinfo.type, Variant::VARIANT_MAX);
- if (p_info.has("hint"))
+ if (p_info.has("hint")) {
pinfo.hint = PropertyHint(p_info["hint"].operator int());
- if (p_info.has("hint_string"))
+ }
+ if (p_info.has("hint_string")) {
pinfo.hint_string = p_info["hint_string"];
+ }
add_property_hint(pinfo);
}
@@ -241,8 +246,9 @@ void EditorSettings::_add_property_info_bind(const Dictionary &p_info) {
bool EditorSettings::has_default_value(const String &p_setting) const {
_THREAD_SAFE_METHOD_
- if (!props.has(p_setting))
+ if (!props.has(p_setting)) {
return false;
+ }
return props[p_setting].has_default_value;
}
@@ -757,8 +763,9 @@ EditorSettings *EditorSettings::get_singleton() {
}
void EditorSettings::create() {
- if (singleton.ptr())
+ if (singleton.ptr()) {
return; //pointless
+ }
DirAccess *dir = nullptr;
@@ -889,8 +896,9 @@ void EditorSettings::create() {
dir->change_dir("projects");
String project_config_dir = ProjectSettings::get_singleton()->get_resource_path();
- if (project_config_dir.ends_with("/"))
+ if (project_config_dir.ends_with("/")) {
project_config_dir = config_path.substr(0, project_config_dir.size() - 1);
+ }
project_config_dir = project_config_dir.get_file() + "-" + project_config_dir.md5_text();
if (dir->change_dir(project_config_dir) != OK) {
@@ -959,8 +967,9 @@ fail:
void EditorSettings::setup_language() {
String lang = get("interface/editor/editor_language");
- if (lang == "en")
+ if (lang == "en") {
return; // Default, nothing to do.
+ }
// Load editor translation for configured/detected locale.
EditorTranslationList *etl = _editor_translations;
@@ -1021,16 +1030,20 @@ void EditorSettings::setup_network() {
String ip = E->get();
// link-local IPv6 addresses don't work, skipping them
- if (ip.begins_with("fe80:0:0:0:")) // fe80::/64
+ if (ip.begins_with("fe80:0:0:0:")) { // fe80::/64
continue;
+ }
// Same goes for IPv4 link-local (APIPA) addresses.
- if (ip.begins_with("169.254.")) // 169.254.0.0/16
+ if (ip.begins_with("169.254.")) { // 169.254.0.0/16
continue;
+ }
// Select current IP (found)
- if (ip == current)
+ if (ip == current) {
selected = ip;
- if (hint != "")
+ }
+ if (hint != "") {
hint += ",";
+ }
hint += ip;
}
@@ -1043,8 +1056,9 @@ void EditorSettings::setup_network() {
void EditorSettings::save() {
//_THREAD_SAFE_METHOD_
- if (!singleton.ptr())
+ if (!singleton.ptr()) {
return;
+ }
if (singleton->config_file_path == "") {
ERR_PRINT("Cannot save EditorSettings config, no valid path");
@@ -1061,8 +1075,9 @@ void EditorSettings::save() {
}
void EditorSettings::destroy() {
- if (!singleton.ptr())
+ if (!singleton.ptr()) {
return;
+ }
save();
singleton = Ref<EditorSettings>();
}
@@ -1105,16 +1120,18 @@ void EditorSettings::raise_order(const String &p_setting) {
void EditorSettings::set_restart_if_changed(const StringName &p_setting, bool p_restart) {
_THREAD_SAFE_METHOD_
- if (!props.has(p_setting))
+ if (!props.has(p_setting)) {
return;
+ }
props[p_setting].restart_if_changed = p_restart;
}
void EditorSettings::set_initial_value(const StringName &p_setting, const Variant &p_value, bool p_update_current) {
_THREAD_SAFE_METHOD_
- if (!props.has(p_setting))
+ if (!props.has(p_setting)) {
return;
+ }
props[p_setting].initial = p_value;
props[p_setting].has_default_value = true;
if (p_update_current) {
@@ -1144,18 +1161,21 @@ Variant _EDITOR_GET(const String &p_setting) {
}
bool EditorSettings::property_can_revert(const String &p_setting) {
- if (!props.has(p_setting))
+ if (!props.has(p_setting)) {
return false;
+ }
- if (!props[p_setting].has_default_value)
+ if (!props[p_setting].has_default_value) {
return false;
+ }
return props[p_setting].initial != props[p_setting].variant;
}
Variant EditorSettings::property_get_revert(const String &p_setting) {
- if (!props.has(p_setting) || !props[p_setting].has_default_value)
+ if (!props.has(p_setting) || !props[p_setting].has_default_value) {
return Variant();
+ }
return props[p_setting].initial;
}
@@ -1235,8 +1255,9 @@ void EditorSettings::set_favorites(const Vector<String> &p_favorites) {
favorites = p_favorites;
FileAccess *f = FileAccess::open(get_project_settings_dir().plus_file("favorites"), FileAccess::WRITE);
if (f) {
- for (int i = 0; i < favorites.size(); i++)
+ for (int i = 0; i < favorites.size(); i++) {
f->store_line(favorites[i]);
+ }
memdelete(f);
}
}
@@ -1249,8 +1270,9 @@ void EditorSettings::set_recent_dirs(const Vector<String> &p_recent_dirs) {
recent_dirs = p_recent_dirs;
FileAccess *f = FileAccess::open(get_project_settings_dir().plus_file("recent_dirs"), FileAccess::WRITE);
if (f) {
- for (int i = 0; i < recent_dirs.size(); i++)
+ for (int i = 0; i < recent_dirs.size(); i++) {
f->store_line(recent_dirs[i]);
+ }
memdelete(f);
}
}
@@ -1448,8 +1470,9 @@ bool EditorSettings::is_shortcut(const String &p_name, const Ref<InputEvent> &p_
Ref<ShortCut> EditorSettings::get_shortcut(const String &p_name) const {
const Map<String, Ref<ShortCut>>::Element *E = shortcuts.find(p_name);
- if (!E)
+ if (!E) {
return Ref<ShortCut>();
+ }
return E->get();
}
diff --git a/editor/editor_settings.h b/editor/editor_settings.h
index 755d46f11b..13aebb7ea6 100644
--- a/editor/editor_settings.h
+++ b/editor/editor_settings.h
@@ -138,10 +138,11 @@ public:
void set_initial_value(const StringName &p_setting, const Variant &p_value, bool p_update_current = false);
void set_restart_if_changed(const StringName &p_setting, bool p_restart);
void set_manually(const StringName &p_setting, const Variant &p_value, bool p_emit_signal = false) {
- if (p_emit_signal)
+ if (p_emit_signal) {
_set(p_setting, p_value);
- else
+ } else {
_set_only(p_setting, p_value);
+ }
}
bool property_can_revert(const String &p_setting);
Variant property_get_revert(const String &p_setting);
diff --git a/editor/editor_spin_slider.cpp b/editor/editor_spin_slider.cpp
index e19fcfd55c..39e6746797 100644
--- a/editor/editor_spin_slider.cpp
+++ b/editor/editor_spin_slider.cpp
@@ -47,8 +47,9 @@ String EditorSpinSlider::get_text_value() const {
}
void EditorSpinSlider::_gui_input(const Ref<InputEvent> &p_event) {
- if (read_only)
+ if (read_only) {
return;
+ }
Ref<InputEventMouseButton> mb = p_event;
if (mb.is_valid()) {
@@ -84,8 +85,9 @@ void EditorSpinSlider::_gui_input(const Ref<InputEvent> &p_event) {
}
}
} else if (mb->get_button_index() == BUTTON_WHEEL_UP || mb->get_button_index() == BUTTON_WHEEL_DOWN) {
- if (grabber->is_visible())
+ if (grabber->is_visible()) {
call_deferred("update");
+ }
}
}
@@ -169,8 +171,9 @@ void EditorSpinSlider::_grabber_gui_input(const Ref<InputEvent> &p_event) {
Ref<InputEventMouseMotion> mm = p_event;
if (mm.is_valid() && grabbing_grabber) {
- if (mousewheel_over_grabber)
+ if (mousewheel_over_grabber) {
return;
+ }
float grabbing_ofs = (grabber->get_transform().xform(mm->get_position()).x - grabbing_from) / float(grabber_range);
set_as_ratio(grabbing_ratio + grabbing_ofs);
@@ -361,8 +364,9 @@ void EditorSpinSlider::_evaluate_input_text() {
}
Variant v = expr->execute(Array(), nullptr, false);
- if (v.get_type() == Variant::NIL)
+ if (v.get_type() == Variant::NIL) {
return;
+ }
set_value(v);
}
@@ -381,8 +385,9 @@ void EditorSpinSlider::_value_input_closed() {
//focus_exited signal
void EditorSpinSlider::_value_focus_exited() {
// discontinue because the focus_exit was caused by right-click context menu
- if (value_input->get_menu()->is_visible())
+ if (value_input->get_menu()->is_visible()) {
return;
+ }
_evaluate_input_text();
// focus is not on the same element after the vlalue_input was exited
diff --git a/editor/editor_sub_scene.cpp b/editor/editor_sub_scene.cpp
index 2170fd6380..a9b1a28092 100644
--- a/editor/editor_sub_scene.cpp
+++ b/editor/editor_sub_scene.cpp
@@ -47,17 +47,20 @@ void EditorSubScene::_path_changed(const String &p_path) {
scene = nullptr;
}
- if (p_path == "")
+ if (p_path == "") {
return;
+ }
Ref<PackedScene> ps = ResourceLoader::load(p_path, "PackedScene");
- if (ps.is_null())
+ if (ps.is_null()) {
return;
+ }
scene = ps->instance();
- if (!scene)
+ if (!scene) {
return;
+ }
_fill_tree(scene, nullptr);
}
@@ -84,8 +87,9 @@ void EditorSubScene::_fill_tree(Node *p_node, TreeItem *p_parent) {
for (int i = 0; i < p_node->get_child_count(); i++) {
Node *c = p_node->get_child(i);
- if (c->get_owner() != scene)
+ if (c->get_owner() != scene) {
continue;
+ }
_fill_tree(c, it);
}
}
@@ -108,8 +112,9 @@ void EditorSubScene::_item_multi_selected(Object *p_object, int p_cell, bool p_s
Node *n = item->get_metadata(0);
- if (!n)
+ if (!n) {
return;
+ }
if (p_selected) {
if (n == scene) {
is_root = true;
@@ -119,8 +124,9 @@ void EditorSubScene::_item_multi_selected(Object *p_object, int p_cell, bool p_s
} else {
List<Node *>::Element *E = selection.find(n);
- if (E)
+ if (E) {
selection.erase(E);
+ }
}
}
}
diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp
index a6ba624b64..4fdc3dc080 100644
--- a/editor/filesystem_dock.cpp
+++ b/editor/filesystem_dock.cpp
@@ -63,8 +63,9 @@ bool FileSystemDock::_create_tree(TreeItem *p_parent, EditorFileSystemDirectory
// Create a tree item for the subdirectory.
TreeItem *subdirectory_item = tree->create_item(p_parent);
String dname = p_dir->get_name();
- if (dname == "")
+ if (dname == "") {
dname = "res://";
+ }
subdirectory_item->set_text(0, dname);
subdirectory_item->set_icon(0, get_theme_icon("Folder", "EditorIcons"));
@@ -86,8 +87,9 @@ bool FileSystemDock::_create_tree(TreeItem *p_parent, EditorFileSystemDirectory
}
// Create items for all subdirectories.
- for (int i = 0; i < p_dir->get_subdir_count(); i++)
+ for (int i = 0; i < p_dir->get_subdir_count(); i++) {
parent_should_expand = (_create_tree(subdirectory_item, p_dir->get_subdir(i), uncollapsed_paths, p_select_in_favorites, p_unfold_path) || parent_should_expand);
+ }
// Create all items for the files in the subdirectory.
if (display_mode == DISPLAY_MODE_TREE_ONLY) {
@@ -195,8 +197,9 @@ void FileSystemDock::_update_tree(const Vector<String> &p_uncollapsed_paths, boo
Vector<String> favorite_paths = EditorSettings::get_singleton()->get_favorites();
for (int i = 0; i < favorite_paths.size(); i++) {
String fave = favorite_paths[i];
- if (!fave.begins_with("res://"))
+ if (!fave.begins_with("res://")) {
continue;
+ }
Ref<Texture2D> folder_icon = get_theme_icon("Folder", "EditorIcons");
const Color folder_color = get_theme_color("folder_icon_modulate", "FileDialog");
@@ -297,8 +300,9 @@ void FileSystemDock::_update_display_mode(bool p_force) {
void FileSystemDock::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
- if (initialized)
+ if (initialized) {
return;
+ }
initialized = true;
EditorFeatureProfileManager::get_singleton()->connect("current_feature_profile_changed", callable_mp(this, &FileSystemDock::_feature_profile_changed));
@@ -349,8 +353,9 @@ void FileSystemDock::_notification(int p_what) {
Dictionary dd = get_viewport()->gui_get_drag_data();
if (tree->is_visible_in_tree() && dd.has("type")) {
if (dd.has("favorite")) {
- if ((String(dd["favorite"]) == "all"))
+ if ((String(dd["favorite"]) == "all")) {
tree->set_drop_mode_flags(Tree::DROP_MODE_INBETWEEN);
+ }
} else if ((String(dd["type"]) == "files") || (String(dd["type"]) == "files_and_dirs") || (String(dd["type"]) == "resource")) {
tree->set_drop_mode_flags(Tree::DROP_MODE_ON_ITEM | Tree::DROP_MODE_INBETWEEN);
}
@@ -404,13 +409,15 @@ void FileSystemDock::_tree_multi_selected(Object *p_item, int p_column, bool p_s
call_deferred("_update_import_dock");
// Return if we don't select something new.
- if (!p_selected)
+ if (!p_selected) {
return;
+ }
// Tree item selected.
TreeItem *selected = tree->get_selected();
- if (!selected)
+ if (!selected) {
return;
+ }
TreeItem *favorites_item = tree->get_root()->get_children();
if (selected->get_parent() == favorites_item && !String(selected->get_metadata(0)).ends_with("/")) {
@@ -432,10 +439,11 @@ void FileSystemDock::_tree_multi_selected(Object *p_item, int p_column, bool p_s
}
String FileSystemDock::get_selected_path() const {
- if (path.ends_with("/"))
+ if (path.ends_with("/")) {
return path;
- else
+ } else {
return path.get_base_dir();
+ }
}
String FileSystemDock::get_current_path() const {
@@ -504,8 +512,9 @@ void FileSystemDock::_file_list_thumbnail_done(const String &p_path, const Ref<T
String file = uarr[1];
if (idx < files->get_item_count() && files->get_item_text(idx) == file && files->get_item_metadata(idx) == p_path) {
if (file_list_display_mode == FILE_LIST_DISPLAY_LIST) {
- if (p_small_preview.is_valid())
+ if (p_small_preview.is_valid()) {
files->set_item_icon(idx, p_small_preview);
+ }
} else {
files->set_item_icon(idx, p_preview);
}
@@ -563,8 +572,9 @@ bool FileSystemDock::_is_file_type_disabled_by_feature_profile(const StringName
}
void FileSystemDock::_search(EditorFileSystemDirectory *p_path, List<FileInfo> *matches, int p_max_items) {
- if (matches->size() > p_max_items)
+ if (matches->size() > p_max_items) {
return;
+ }
for (int i = 0; i < p_path->get_subdir_count(); i++) {
_search(p_path->get_subdir(i), matches, p_max_items);
@@ -586,8 +596,9 @@ void FileSystemDock::_search(EditorFileSystemDirectory *p_path, List<FileInfo> *
}
matches->push_back(fi);
- if (matches->size() > p_max_items)
+ if (matches->size() > p_max_items) {
return;
+ }
}
}
}
@@ -597,8 +608,9 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) {
Set<String> cselection;
if (p_keep_selection) {
for (int i = 0; i < files->get_item_count(); i++) {
- if (files->is_selected(i))
+ if (files->is_selected(i)) {
cselection.insert(files->get_item_text(i));
+ }
}
}
@@ -701,8 +713,9 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) {
file = path.get_file();
efd = EditorFileSystem::get_singleton()->get_filesystem_path(directory);
}
- if (!efd)
+ if (!efd) {
return;
+ }
if (searched_string.length() > 0) {
// Display the search results.
@@ -714,8 +727,9 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) {
files->add_item("..", folder_icon, true);
String bd = directory.get_base_dir();
- if (bd != "res://" && !bd.ends_with("/"))
+ if (bd != "res://" && !bd.ends_with("/")) {
bd += "/";
+ }
files->set_item_metadata(files->get_item_count() - 1, bd);
files->set_item_selectable(files->get_item_count() - 1, false);
@@ -801,8 +815,9 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) {
}
// Select the items.
- if (cselection.has(fname))
+ if (cselection.has(fname)) {
files->select(item_index, false);
+ }
if (!p_keep_selection && file != "" && fname == file) {
files->select(item_index, true);
@@ -902,15 +917,17 @@ void FileSystemDock::_set_scanning_mode() {
}
void FileSystemDock::_fw_history() {
- if (history_pos < history.size() - 1)
+ if (history_pos < history.size() - 1) {
history_pos++;
+ }
_update_history();
}
void FileSystemDock::_bw_history() {
- if (history_pos > 0)
+ if (history_pos > 0) {
history_pos--;
+ }
_update_history();
}
@@ -950,8 +967,9 @@ void FileSystemDock::_push_to_history() {
}
void FileSystemDock::_get_all_items_in_dir(EditorFileSystemDirectory *efsd, Vector<String> &files, Vector<String> &folders) const {
- if (efsd == nullptr)
+ if (efsd == nullptr) {
return;
+ }
for (int i = 0; i < efsd->get_subdir_count(); i++) {
folders.push_back(efsd->get_subdir(i)->get_path());
@@ -1106,8 +1124,9 @@ void FileSystemDock::_update_resource_paths_after_move(const Map<String, String>
for (int i = 0; i < EditorNode::get_editor_data().get_edited_scene_count(); i++) {
String path;
if (i == EditorNode::get_editor_data().get_edited_scene()) {
- if (!get_tree()->get_edited_scene_root())
+ if (!get_tree()->get_edited_scene_root()) {
continue;
+ }
path = get_tree()->get_edited_scene_root()->get_filename();
} else {
@@ -1138,8 +1157,9 @@ void FileSystemDock::_update_dependencies_after_move(const Map<String, String> &
print_verbose("Remapping dependencies for: " + file);
Error err = ResourceLoader::rename_dependencies(file, p_renames);
if (err == OK) {
- if (ResourceLoader::get_resource_type(file) == "PackedScene")
+ if (ResourceLoader::get_resource_type(file) == "PackedScene") {
editor->reload_scene(file);
+ }
} else {
EditorNode::get_singleton()->add_io_error(TTR("Unable to update dependencies:") + "\n" + remaps[i] + "\n");
}
@@ -1267,8 +1287,9 @@ void FileSystemDock::_make_scene_confirm() {
break;
}
}
- if (!extension_correct)
+ if (!extension_correct) {
scene_name = scene_name.get_basename() + ".tscn";
+ }
scene_name = directory.plus_file(scene_name);
@@ -1621,8 +1642,9 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected
}
EditorSettings::get_singleton()->set_favorites(favorites);
_update_tree(_compute_uncollapsed_paths());
- if (path == "Favorites")
+ if (path == "Favorites") {
_update_file_list(true);
+ }
} break;
case FILE_DEPENDENCIES: {
@@ -1807,10 +1829,11 @@ void FileSystemDock::_search_changed(const String &p_text, const Control *p_from
searched_string = p_text.to_lower();
- if (p_from == tree_search_box)
+ if (p_from == tree_search_box) {
file_list_search_box->set_text(searched_string);
- else // File_list_search_box.
+ } else { // File_list_search_box.
tree_search_box->set_text(searched_string);
+ }
bool unfold_path = (p_text == String() && path != String());
switch (display_mode) {
@@ -1843,8 +1866,9 @@ void FileSystemDock::focus_on_filter() {
}
void FileSystemDock::set_file_list_display_mode(FileListDisplayMode p_mode) {
- if (p_mode == file_list_display_mode)
+ if (p_mode == file_list_display_mode) {
return;
+ }
_toggle_file_display();
}
@@ -1885,8 +1909,9 @@ Variant FileSystemDock::get_drag_data_fw(const Point2 &p_point, Control *p_from)
all_not_favorites = true;
}
- if (paths.empty())
+ if (paths.empty()) {
return Variant();
+ }
Dictionary drag_data = EditorNode::get_singleton()->drag_files_and_dirs(paths, p_from);
if (!all_not_favorites) {
@@ -1905,8 +1930,9 @@ bool FileSystemDock::can_drop_data_fw(const Point2 &p_point, const Variant &p_da
// Moving favorite around.
TreeItem *ti = tree->get_item_at_position(p_point);
- if (!ti)
+ if (!ti) {
return false;
+ }
int drop_section = tree->get_drop_section_at_position(p_point);
TreeItem *favorites_item = tree->get_root()->get_children();
@@ -1940,19 +1966,22 @@ bool FileSystemDock::can_drop_data_fw(const Point2 &p_point, const Variant &p_da
bool favorite;
_get_drag_target_folder(to_dir, favorite, p_point, p_from);
- if (favorite)
+ if (favorite) {
return true;
+ }
- if (to_dir.empty())
+ if (to_dir.empty()) {
return false;
+ }
// Attempting to move a folder into itself will fail later,
// rather than bring up a message don't try to do it in the first place.
to_dir = to_dir.ends_with("/") ? to_dir : (to_dir + "/");
Vector<String> fnames = drag_data["files"];
for (int i = 0; i < fnames.size(); ++i) {
- if (fnames[i].ends_with("/") && to_dir.begins_with(fnames[i]))
+ if (fnames[i].ends_with("/") && to_dir.begins_with(fnames[i])) {
return false;
+ }
}
return true;
@@ -1962,8 +1991,9 @@ bool FileSystemDock::can_drop_data_fw(const Point2 &p_point, const Variant &p_da
}
void FileSystemDock::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
- if (!can_drop_data_fw(p_point, p_data, p_from))
+ if (!can_drop_data_fw(p_point, p_data, p_from)) {
return;
+ }
Dictionary drag_data = p_data;
Vector<String> dirs = EditorSettings::get_singleton()->get_favorites();
@@ -1974,8 +2004,9 @@ void FileSystemDock::drop_data_fw(const Point2 &p_point, const Variant &p_data,
}
// Moving favorite around.
TreeItem *ti = tree->get_item_at_position(p_point);
- if (!ti)
+ if (!ti) {
return;
+ }
int drop_section = tree->get_drop_section_at_position(p_point);
int drop_position;
@@ -2022,8 +2053,9 @@ void FileSystemDock::drop_data_fw(const Point2 &p_point, const Variant &p_data,
EditorSettings::get_singleton()->set_favorites(dirs);
_update_tree(_compute_uncollapsed_paths());
- if (display_mode == DISPLAY_MODE_SPLIT && path == "Favorites")
+ if (display_mode == DISPLAY_MODE_SPLIT && path == "Favorites") {
_update_file_list(true);
+ }
return;
}
@@ -2282,8 +2314,9 @@ void FileSystemDock::_file_list_rmb_select(int p_item, const Vector2 &p_pos) {
// Right click is pressed in the file list.
Vector<String> paths;
for (int i = 0; i < files->get_item_count(); i++) {
- if (!files->is_selected(i))
+ if (!files->is_selected(i)) {
continue;
+ }
if (files->get_item_text(p_item) == "..") {
files->unselect(i);
continue;
@@ -2303,8 +2336,9 @@ void FileSystemDock::_file_list_rmb_select(int p_item, const Vector2 &p_pos) {
void FileSystemDock::_file_list_rmb_pressed(const Vector2 &p_pos) {
// Right click on empty space for file list.
- if (searched_string.length() > 0)
+ if (searched_string.length() > 0) {
return;
+ }
file_list_popup->clear();
file_list_popup->set_size(Size2(1, 1));
@@ -2372,8 +2406,9 @@ void FileSystemDock::_file_list_gui_input(Ref<InputEvent> p_event) {
}
void FileSystemDock::_update_import_dock() {
- if (!import_dock_needs_update)
+ if (!import_dock_needs_update) {
return;
+ }
// List selected.
Vector<String> selected;
@@ -2384,8 +2419,9 @@ void FileSystemDock::_update_import_dock() {
} else {
// Use the file list.
for (int i = 0; i < files->get_item_count(); i++) {
- if (!files->is_selected(i))
+ if (!files->is_selected(i)) {
continue;
+ }
selected.push_back(files->get_item_metadata(i));
}
diff --git a/editor/find_in_files.cpp b/editor/find_in_files.cpp
index b2a8f7dba4..1bc0de1ab0 100644
--- a/editor/find_in_files.cpp
+++ b/editor/find_in_files.cpp
@@ -64,8 +64,9 @@ static bool find_next(const String &line, String pattern, int from, bool match_c
while (true) {
int begin = match_case ? line.find(pattern, end) : line.findn(pattern, end);
- if (begin == -1)
+ if (begin == -1) {
return false;
+ }
end = begin + pattern.length();
out_begin = begin;
@@ -156,8 +157,9 @@ void FindInFiles::_process() {
while (is_processing()) {
_iterate();
float elapsed = (os.get_ticks_msec() - time_before);
- if (elapsed > 1000.0 / 120.0)
+ if (elapsed > 1000.0 / 120.0) {
break;
+ }
}
}
@@ -227,19 +229,22 @@ void FindInFiles::_scan_dir(String path, PackedStringArray &out_folders) {
for (int i = 0; i < 1000; ++i) {
String file = dir->get_next();
- if (file == "")
+ if (file == "") {
break;
+ }
// Ignore special dirs (such as .git and .import)
- if (file == "." || file == ".." || file.begins_with("."))
+ if (file == "." || file == ".." || file.begins_with(".")) {
continue;
- if (dir->current_is_hidden())
+ }
+ if (dir->current_is_hidden()) {
continue;
+ }
- if (dir->current_is_dir())
+ if (dir->current_is_dir()) {
out_folders.push_back(file);
- else {
+ } else {
String file_ext = file.get_extension();
if (_extension_filter.has(file_ext)) {
_files_to_scan.push_back(path.plus_file(file));
@@ -399,8 +404,9 @@ void FindInFilesDialog::set_replace_text(String text) {
}
void FindInFilesDialog::set_find_in_files_mode(FindInFilesMode p_mode) {
- if (_mode == p_mode)
+ if (_mode == p_mode) {
return;
+ }
_mode = p_mode;
@@ -528,8 +534,9 @@ void FindInFilesDialog::_on_replace_text_entered(String text) {
void FindInFilesDialog::_on_folder_selected(String path) {
int i = path.find("://");
- if (i != -1)
+ if (i != -1) {
path = path.right(i + 3);
+ }
_folder_line_edit->set_text(path);
}
@@ -739,12 +746,14 @@ void FindInFilesPanel::_on_result_found(String fpath, int line_number, int begin
void FindInFilesPanel::draw_result_text(Object *item_obj, Rect2 rect) {
TreeItem *item = Object::cast_to<TreeItem>(item_obj);
- if (!item)
+ if (!item) {
return;
+ }
Map<TreeItem *, Result>::Element *E = _result_items.find(item);
- if (!E)
+ if (!E) {
return;
+ }
Result r = E->value();
Rect2 match_rect = rect;
@@ -791,8 +800,9 @@ void FindInFilesPanel::_on_result_selected() {
TreeItem *item = _results_display->get_selected();
Map<TreeItem *, Result>::Element *E = _result_items.find(item);
- if (E == nullptr)
+ if (E == nullptr) {
return;
+ }
Result r = E->value();
TreeItem *file_item = item->get_parent();
@@ -816,8 +826,9 @@ void FindInFilesPanel::_on_replace_all_clicked() {
Vector<Result> locations;
for (TreeItem *item = file_item->get_children(); item; item = item->get_next()) {
- if (!item->is_checked(0))
+ if (!item->is_checked(0)) {
continue;
+ }
Map<TreeItem *, Result>::Element *F = _result_items.find(item);
ERR_FAIL_COND(F == nullptr);
diff --git a/editor/groups_editor.cpp b/editor/groups_editor.cpp
index 692b41e921..98b216acda 100644
--- a/editor/groups_editor.cpp
+++ b/editor/groups_editor.cpp
@@ -300,8 +300,9 @@ void GroupDialog::_load_groups(Node *p_current) {
void GroupDialog::_delete_group_pressed(Object *p_item, int p_column, int p_id) {
TreeItem *ti = Object::cast_to<TreeItem>(p_item);
- if (!ti)
+ if (!ti) {
return;
+ }
String name = ti->get_text(0);
@@ -536,15 +537,18 @@ GroupDialog::GroupDialog() {
////////////////////////////////////////////////////////////////////////////////
void GroupsEditor::_add_group(const String &p_group) {
- if (!node)
+ if (!node) {
return;
+ }
const String name = group_name->get_text().strip_edges();
- if (name.empty())
+ if (name.empty()) {
return;
+ }
- if (node->is_in_group(name))
+ if (node->is_in_group(name)) {
return;
+ }
undo_redo->create_action(TTR("Add to Group"));
@@ -563,12 +567,14 @@ void GroupsEditor::_add_group(const String &p_group) {
}
void GroupsEditor::_remove_group(Object *p_item, int p_column, int p_id) {
- if (!node)
+ if (!node) {
return;
+ }
TreeItem *ti = Object::cast_to<TreeItem>(p_item);
- if (!ti)
+ if (!ti) {
return;
+ }
String name = ti->get_text(0);
@@ -595,8 +601,9 @@ struct _GroupInfoComparator {
void GroupsEditor::update_tree() {
tree->clear();
- if (!node)
+ if (!node) {
return;
+ }
List<Node::GroupInfo> groups;
node->get_groups(&groups);
@@ -606,8 +613,9 @@ void GroupsEditor::update_tree() {
for (List<GroupInfo>::Element *E = groups.front(); E; E = E->next()) {
Node::GroupInfo gi = E->get();
- if (!gi.persistent)
+ if (!gi.persistent) {
continue;
+ }
Node *n = node;
bool can_be_deleted = true;
diff --git a/editor/import/collada.cpp b/editor/import/collada.cpp
index e82e1bb098..41e71248a9 100644
--- a/editor/import/collada.cpp
+++ b/editor/import/collada.cpp
@@ -65,10 +65,11 @@ void Collada::Vertex::fix_unit_scale(Collada &state) {
}
static String _uri_to_id(const String &p_uri) {
- if (p_uri.begins_with("#"))
+ if (p_uri.begins_with("#")) {
return p_uri.substr(1, p_uri.size() - 1);
- else
+ } else {
return p_uri;
+ }
}
/** HELPER FUNCTIONS **/
@@ -79,10 +80,12 @@ Transform Collada::fix_transform(const Transform &p_transform) {
#ifndef NO_UP_AXIS_SWAP
if (state.up_axis != Vector3::AXIS_Y) {
- for (int i = 0; i < 3; i++)
+ for (int i = 0; i < 3; i++) {
SWAP(tr.basis[1][i], tr.basis[state.up_axis][i]);
- for (int i = 0; i < 3; i++)
+ }
+ for (int i = 0; i < 3; i++) {
SWAP(tr.basis[i][1], tr.basis[i][state.up_axis]);
+ }
SWAP(tr.origin[1], tr.origin[state.up_axis]);
@@ -167,10 +170,11 @@ Transform Collada::Node::get_transform() const {
}
Transform Collada::Node::get_global_transform() const {
- if (parent)
+ if (parent) {
return parent->get_global_transform() * default_transform;
- else
+ } else {
return default_transform;
+ }
}
Vector<float> Collada::AnimationTrack::get_value_at_time(float p_time) const {
@@ -178,14 +182,17 @@ Vector<float> Collada::AnimationTrack::get_value_at_time(float p_time) const {
int i = 0;
for (i = 0; i < keys.size(); i++) {
- if (keys[i].time > p_time)
+ if (keys[i].time > p_time) {
break;
+ }
}
- if (i == 0)
+ if (i == 0) {
return keys[0].data;
- if (i == keys.size())
+ }
+ if (i == keys.size()) {
return keys[keys.size() - 1].data;
+ }
switch (keys[i].interp_type) {
case INTERP_BEZIER: //wait for bezier
@@ -243,12 +250,15 @@ void Collada::_parse_asset(XMLParser &parser) {
if (name == "up_axis") {
parser.read();
- if (parser.get_node_data() == "X_UP")
+ if (parser.get_node_data() == "X_UP") {
state.up_axis = Vector3::AXIS_X;
- if (parser.get_node_data() == "Y_UP")
+ }
+ if (parser.get_node_data() == "Y_UP") {
state.up_axis = Vector3::AXIS_Y;
- if (parser.get_node_data() == "Z_UP")
+ }
+ if (parser.get_node_data() == "Z_UP") {
state.up_axis = Vector3::AXIS_Z;
+ }
COLLADA_PRINT("up axis: " + parser.get_node_data());
} else if (name == "unit") {
@@ -256,8 +266,9 @@ void Collada::_parse_asset(XMLParser &parser) {
COLLADA_PRINT("unit scale: " + rtos(state.unit_scale));
}
- } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "asset")
+ } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "asset") {
break; //end of <asset>
+ }
}
}
@@ -265,8 +276,9 @@ void Collada::_parse_image(XMLParser &parser) {
String id = parser.get_attribute_value("id");
if (!(state.import_flags & IMPORT_FLAG_SCENE)) {
- if (!parser.is_empty())
+ if (!parser.is_empty()) {
parser.skip_section();
+ }
return;
}
@@ -302,11 +314,13 @@ void Collada::_parse_image(XMLParser &parser) {
} else if (name == "data") {
ERR_PRINT("COLLADA Embedded image data not supported!");
- } else if (name == "extra" && !parser.is_empty())
+ } else if (name == "extra" && !parser.is_empty()) {
parser.skip_section();
+ }
- } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "image")
+ } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "image") {
break; //end of <asset>
+ }
}
}
@@ -315,16 +329,18 @@ void Collada::_parse_image(XMLParser &parser) {
void Collada::_parse_material(XMLParser &parser) {
if (!(state.import_flags & IMPORT_FLAG_SCENE)) {
- if (!parser.is_empty())
+ if (!parser.is_empty()) {
parser.skip_section();
+ }
return;
}
Material material;
String id = parser.get_attribute_value("id");
- if (parser.has_attribute("name"))
+ if (parser.has_attribute("name")) {
material.name = parser.get_attribute_value("name");
+ }
if (state.version < State::Version(1, 4, 0)) {
/* <1.4 */
@@ -333,8 +349,9 @@ void Collada::_parse_material(XMLParser &parser) {
while (parser.read() == OK) {
if (parser.get_node_type() == XMLParser::NODE_ELEMENT && parser.get_node_name() == "instance_effect") {
material.instance_effect = _uri_to_id(parser.get_attribute_value("url"));
- } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "material")
+ } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "material") {
break; //end of <asset>
+ }
}
}
@@ -343,8 +360,9 @@ void Collada::_parse_material(XMLParser &parser) {
//! reads floats from inside of xml element until end of xml element
Vector<float> Collada::_read_float_array(XMLParser &parser) {
- if (parser.is_empty())
+ if (parser.is_empty()) {
return Vector<float>();
+ }
Vector<String> splitters;
splitters.push_back(" ");
@@ -362,16 +380,18 @@ Vector<float> Collada::_read_float_array(XMLParser &parser) {
String str = parser.get_node_data();
array = str.split_floats_mk(splitters, false);
//array=str.split_floats(" ",false);
- } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END)
+ } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END) {
break; // end parsing text
+ }
}
return array;
}
Vector<String> Collada::_read_string_array(XMLParser &parser) {
- if (parser.is_empty())
+ if (parser.is_empty()) {
return Vector<String>();
+ }
Vector<String> array;
while (parser.read() == OK) {
@@ -382,16 +402,18 @@ Vector<String> Collada::_read_string_array(XMLParser &parser) {
// parse String data
String str = parser.get_node_data();
array = str.split_spaces();
- } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END)
+ } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END) {
break; // end parsing text
+ }
}
return array;
}
Transform Collada::_read_transform(XMLParser &parser) {
- if (parser.is_empty())
+ if (parser.is_empty()) {
return Transform();
+ }
Vector<String> array;
while (parser.read() == OK) {
@@ -402,8 +424,9 @@ Transform Collada::_read_transform(XMLParser &parser) {
// parse float data
String str = parser.get_node_data();
array = str.split_spaces();
- } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END)
+ } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END) {
break; // end parsing text
+ }
}
ERR_FAIL_COND_V(array.size() != 16, Transform());
@@ -419,21 +442,24 @@ Transform Collada::_read_transform(XMLParser &parser) {
String Collada::_read_empty_draw_type(XMLParser &parser) {
String empty_draw_type = "";
- if (parser.is_empty())
+ if (parser.is_empty()) {
return empty_draw_type;
+ }
while (parser.read() == OK) {
if (parser.get_node_type() == XMLParser::NODE_TEXT) {
empty_draw_type = parser.get_node_data();
- } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END)
+ } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END) {
break; // end parsing text
+ }
}
return empty_draw_type;
}
Variant Collada::_parse_param(XMLParser &parser) {
- if (parser.is_empty())
+ if (parser.is_empty()) {
return Variant();
+ }
String from = parser.get_node_name();
Variant data;
@@ -473,8 +499,9 @@ Variant Collada::_parse_param(XMLParser &parser) {
data = parser.get_node_data();
}
}
- } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "sampler2D")
+ } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "sampler2D") {
break;
+ }
}
} else if (parser.get_node_name() == "surface") {
while (parser.read() == OK) {
@@ -486,13 +513,15 @@ Variant Collada::_parse_param(XMLParser &parser) {
data = parser.get_node_data();
}
}
- } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "surface")
+ } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "surface") {
break;
+ }
}
}
- } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == from)
+ } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == from) {
break;
+ }
}
COLLADA_PRINT("newparam ending " + parser.get_node_name());
@@ -501,8 +530,9 @@ Variant Collada::_parse_param(XMLParser &parser) {
void Collada::_parse_effect_material(XMLParser &parser, Effect &effect, String &id) {
if (!(state.import_flags & IMPORT_FLAG_SCENE)) {
- if (!parser.is_empty())
+ if (!parser.is_empty()) {
parser.skip_section();
+ }
return;
}
@@ -544,12 +574,15 @@ void Collada::_parse_effect_material(XMLParser &parser, Effect &effect, String &
if (colorarr.size() >= 3) {
// alpha strangely not alright? maybe it needs to be multiplied by value as a channel intensity
Color color(colorarr[0], colorarr[1], colorarr[2], 1.0);
- if (what == "diffuse")
+ if (what == "diffuse") {
effect.diffuse.color = color;
- if (what == "specular")
+ }
+ if (what == "specular") {
effect.specular.color = color;
- if (what == "emission")
+ }
+ if (what == "emission") {
effect.emission.color = color;
+ }
COLLADA_PRINT(what + " color: " + color);
}
@@ -583,11 +616,13 @@ void Collada::_parse_effect_material(XMLParser &parser, Effect &effect, String &
COLLADA_PRINT(what + " texture: " + uri);
}
}
- } else if (!parser.is_empty())
+ } else if (!parser.is_empty()) {
parser.skip_section();
+ }
- } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == what)
+ } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == what) {
break;
+ }
}
} else if (what == "shininess") {
@@ -596,8 +631,9 @@ void Collada::_parse_effect_material(XMLParser &parser, Effect &effect, String &
} else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && (parser.get_node_name() == "constant" ||
parser.get_node_name() == "lambert" ||
parser.get_node_name() == "phong" ||
- parser.get_node_name() == "blinn"))
+ parser.get_node_name() == "blinn")) {
break;
+ }
}
} else if (parser.get_node_name() == "double_sided" || parser.get_node_name() == "show_double_sided") { // colladamax / google earth
@@ -633,36 +669,42 @@ void Collada::_parse_effect_material(XMLParser &parser, Effect &effect, String &
COLLADA_PRINT(" bump: " + uri);
}
}
- } else if (!parser.is_empty())
+ } else if (!parser.is_empty()) {
parser.skip_section();
+ }
- } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "bump")
+ } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "bump") {
break;
+ }
}
- } else if (!parser.is_empty())
+ } else if (!parser.is_empty()) {
parser.skip_section();
+ }
} else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END &&
(parser.get_node_name() == "effect" ||
parser.get_node_name() == "profile_COMMON" ||
parser.get_node_name() == "technique" ||
- parser.get_node_name() == "extra"))
+ parser.get_node_name() == "extra")) {
break;
+ }
}
}
void Collada::_parse_effect(XMLParser &parser) {
if (!(state.import_flags & IMPORT_FLAG_SCENE)) {
- if (!parser.is_empty())
+ if (!parser.is_empty()) {
parser.skip_section();
+ }
return;
}
String id = parser.get_attribute_value("id");
Effect effect;
- if (parser.has_attribute("name"))
+ if (parser.has_attribute("name")) {
effect.name = parser.get_attribute_value("name");
+ }
_parse_effect_material(parser, effect, id);
state.effect_map[id] = effect;
@@ -672,8 +714,9 @@ void Collada::_parse_effect(XMLParser &parser) {
void Collada::_parse_camera(XMLParser &parser) {
if (!(state.import_flags & IMPORT_FLAG_SCENE)) {
- if (!parser.is_empty())
+ if (!parser.is_empty()) {
parser.skip_section();
+ }
return;
}
@@ -717,8 +760,9 @@ void Collada::_parse_camera(XMLParser &parser) {
camera.z_far = parser.get_node_data().to_double();
}
- } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "camera")
+ } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "camera") {
break; //end of <asset>
+ }
}
COLLADA_PRINT("Camera ID:" + id);
@@ -726,8 +770,9 @@ void Collada::_parse_camera(XMLParser &parser) {
void Collada::_parse_light(XMLParser &parser) {
if (!(state.import_flags & IMPORT_FLAG_SCENE)) {
- if (!parser.is_empty())
+ if (!parser.is_empty()) {
parser.skip_section();
+ }
return;
}
@@ -777,8 +822,9 @@ void Collada::_parse_light(XMLParser &parser) {
light.spot_exp = parser.get_node_data().to_double();
}
- } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "light")
+ } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "light") {
break; //end of <asset>
+ }
}
COLLADA_PRINT("Light ID:" + id);
@@ -786,8 +832,9 @@ void Collada::_parse_light(XMLParser &parser) {
void Collada::_parse_curve_geometry(XMLParser &parser, String p_id, String p_name) {
if (!(state.import_flags & IMPORT_FLAG_SCENE)) {
- if (!parser.is_empty())
+ if (!parser.is_empty()) {
parser.skip_section();
+ }
return;
}
@@ -849,22 +896,25 @@ void Collada::_parse_curve_geometry(XMLParser &parser, String p_id, String p_nam
COLLADA_PRINT(section + " input semantic: " + semantic + " source: " + source);
}
- } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == section)
+ } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == section) {
break;
+ }
}
} else if (!parser.is_empty()) {
parser.skip_section();
}
- } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "spline")
+ } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "spline") {
break;
+ }
}
}
void Collada::_parse_mesh_geometry(XMLParser &parser, String p_id, String p_name) {
if (!(state.import_flags & IMPORT_FLAG_SCENE)) {
- if (!parser.is_empty())
+ if (!parser.is_empty()) {
parser.skip_section();
+ }
return;
}
@@ -922,8 +972,9 @@ void Collada::_parse_mesh_geometry(XMLParser &parser, String p_id, String p_name
COLLADA_PRINT(section + " input semantic: " + semantic + " source: " + source);
}
- } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == section)
+ } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == section) {
break;
+ }
}
meshdata.vertices[id] = vert;
@@ -935,8 +986,9 @@ void Collada::_parse_mesh_geometry(XMLParser &parser, String p_id, String p_name
}
MeshData::Primitives prim;
- if (parser.has_attribute("material"))
+ if (parser.has_attribute("material")) {
prim.material = parser.get_attribute_value("material");
+ }
prim.count = parser.get_attribute_value("count").to_int();
prim.vertex_size = 0;
int last_ref = 0;
@@ -973,8 +1025,9 @@ void Collada::_parse_mesh_geometry(XMLParser &parser, String p_id, String p_name
prim.polygons.push_back(values.size() / prim.vertex_size);
int from = prim.indices.size();
prim.indices.resize(from + values.size());
- for (int i = 0; i < values.size(); i++)
+ for (int i = 0; i < values.size(); i++) {
prim.indices.write[from + i] = values[i];
+ }
} else if (prim.vertex_size > 0) {
prim.indices = values;
@@ -988,8 +1041,9 @@ void Collada::_parse_mesh_geometry(XMLParser &parser, String p_id, String p_name
prim.polygons = values;
COLLADA_PRINT("read " + itos(values.size()) + " polygon values");
}
- } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == section)
+ } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == section) {
break;
+ }
}
meshdata.primitives.push_back(prim);
@@ -1004,8 +1058,9 @@ void Collada::_parse_mesh_geometry(XMLParser &parser, String p_id, String p_name
} else if (!parser.is_empty()) {
parser.skip_section();
}
- } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "mesh")
+ } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "mesh") {
break;
+ }
}
}
@@ -1044,14 +1099,16 @@ void Collada::_parse_skin_controller(XMLParser &parser, String p_id) {
} else if (section == "Name_array" || section == "IDREF_array") {
// create a new array and read it.
- if (section == "IDREF_array")
+ if (section == "IDREF_array") {
skindata.use_idrefs = true;
+ }
if (skindata.sources.has(current_source)) {
skindata.sources[current_source].sarray = _read_string_array(parser);
if (section == "IDREF_array") {
Vector<String> sa = skindata.sources[current_source].sarray;
- for (int i = 0; i < sa.size(); i++)
+ for (int i = 0; i < sa.size(); i++) {
state.idref_joints.insert(sa[i]);
+ }
}
COLLADA_PRINT("section: " + current_source + " read " + itos(skindata.sources[current_source].array.size()) + " values.");
}
@@ -1061,8 +1118,9 @@ void Collada::_parse_skin_controller(XMLParser &parser, String p_id) {
if (skindata.sources.has(current_source)) {
int stride = 1;
- if (parser.has_attribute("stride"))
+ if (parser.has_attribute("stride")) {
stride = parser.get_attribute_value("stride").to_int();
+ }
skindata.sources[current_source].stride = stride;
COLLADA_PRINT("section: " + current_source + " stride " + itos(skindata.sources[current_source].stride));
@@ -1081,8 +1139,9 @@ void Collada::_parse_skin_controller(XMLParser &parser, String p_id) {
COLLADA_PRINT(section + " input semantic: " + semantic + " source: " + source);
}
- } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == section)
+ } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == section) {
break;
+ }
}
skindata.joints = joint;
@@ -1119,8 +1178,9 @@ void Collada::_parse_skin_controller(XMLParser &parser, String p_id) {
weights.sets = values;
COLLADA_PRINT("read " + itos(values.size()) + " polygon values");
}
- } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == section)
+ } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == section) {
break;
+ }
}
skindata.weights = weights;
@@ -1130,8 +1190,9 @@ void Collada::_parse_skin_controller(XMLParser &parser, String p_id) {
parser.skip_section();
*/
- } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "skin")
+ } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "skin") {
break;
+ }
}
/* STORE REST MATRICES */
@@ -1209,8 +1270,9 @@ void Collada::_parse_morph_controller(XMLParser &parser, String p_id) {
if (morphdata.sources.has(current_source)) {
int stride = 1;
- if (parser.has_attribute("stride"))
+ if (parser.has_attribute("stride")) {
stride = parser.get_attribute_value("stride").to_int();
+ }
morphdata.sources[current_source].stride = stride;
COLLADA_PRINT("section: " + current_source + " stride " + itos(morphdata.sources[current_source].stride));
@@ -1227,8 +1289,9 @@ void Collada::_parse_morph_controller(XMLParser &parser, String p_id) {
COLLADA_PRINT(section + " input semantic: " + semantic + " source: " + source);
}
- } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == section)
+ } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == section) {
break;
+ }
}
}
/*
@@ -1236,8 +1299,9 @@ void Collada::_parse_morph_controller(XMLParser &parser, String p_id) {
parser.skip_section();
*/
- } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "morph")
+ } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "morph") {
break;
+ }
}
if (morphdata.targets.has("MORPH_WEIGHT")) {
@@ -1261,8 +1325,9 @@ void Collada::_parse_controller(XMLParser &parser) {
} else if (section == "morph") {
_parse_morph_controller(parser, id);
}
- } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "controller")
+ } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "controller") {
break;
+ }
}
}
@@ -1272,8 +1337,9 @@ Collada::Node *Collada::_parse_visual_instance_geometry(XMLParser &parser) {
geom->controller = type == "instance_controller";
geom->source = _uri_to_id(parser.get_attribute_value_safe("url"));
- if (parser.is_empty()) //nothing else to parse...
+ if (parser.is_empty()) { //nothing else to parse...
return geom;
+ }
// try to find also many materials and skeletons!
while (parser.read() == OK) {
if (parser.get_node_type() == XMLParser::NODE_ELEMENT) {
@@ -1293,8 +1359,9 @@ Collada::Node *Collada::_parse_visual_instance_geometry(XMLParser &parser) {
}
}
- } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == type)
+ } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == type) {
break;
+ }
}
if (geom->controller) {
@@ -1320,15 +1387,18 @@ Collada::Node *Collada::_parse_visual_instance_camera(XMLParser &parser) {
NodeCamera *cam = memnew(NodeCamera);
cam->camera = _uri_to_id(parser.get_attribute_value_safe("url"));
- if (state.up_axis == Vector3::AXIS_Z) //collada weirdness
+ if (state.up_axis == Vector3::AXIS_Z) { //collada weirdness
cam->post_transform.basis.rotate(Vector3(1, 0, 0), -Math_PI * 0.5);
+ }
- if (parser.is_empty()) //nothing else to parse...
+ if (parser.is_empty()) { //nothing else to parse...
return cam;
+ }
while (parser.read() == OK) {
- if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "instance_camera")
+ if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "instance_camera") {
break;
+ }
}
return cam;
@@ -1338,15 +1408,18 @@ Collada::Node *Collada::_parse_visual_instance_light(XMLParser &parser) {
NodeLight *cam = memnew(NodeLight);
cam->light = _uri_to_id(parser.get_attribute_value_safe("url"));
- if (state.up_axis == Vector3::AXIS_Z) //collada weirdness
+ if (state.up_axis == Vector3::AXIS_Z) { //collada weirdness
cam->post_transform.basis.rotate(Vector3(1, 0, 0), -Math_PI * 0.5);
+ }
- if (parser.is_empty()) //nothing else to parse...
+ if (parser.is_empty()) { //nothing else to parse...
return cam;
+ }
while (parser.read() == OK) {
- if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "instance_light")
+ if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "instance_light") {
break;
+ }
}
return cam;
@@ -1363,12 +1436,14 @@ Collada::Node *Collada::_parse_visual_node_instance_data(XMLParser &parser) {
return _parse_visual_instance_light(parser);
}
- if (parser.is_empty()) //nothing else to parse...
+ if (parser.is_empty()) { //nothing else to parse...
return nullptr;
+ }
while (parser.read() == OK) {
- if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == instance_type)
+ if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == instance_type) {
break;
+ }
}
return nullptr;
@@ -1475,8 +1550,9 @@ Collada::Node *Collada::_parse_visual_scene_node(XMLParser &parser) {
xf.data = matrix;
String mtx;
- for (int i = 0; i < matrix.size(); i++)
+ for (int i = 0; i < matrix.size(); i++) {
mtx += " " + rtos(matrix[i]);
+ }
xform_list.push_back(xf);
@@ -1514,8 +1590,9 @@ Collada::Node *Collada::_parse_visual_scene_node(XMLParser &parser) {
children.push_back(child);
}
- } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "node")
+ } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "node") {
break;
+ }
}
if (!node) {
@@ -1556,8 +1633,9 @@ void Collada::_parse_visual_scene(XMLParser &parser) {
state.visual_scene_map[id] = VisualScene();
VisualScene &vscene = state.visual_scene_map[id];
- if (parser.has_attribute("name"))
+ if (parser.has_attribute("name")) {
vscene.name = parser.get_attribute_value("name");
+ }
while (parser.read() == OK) {
if (parser.get_node_type() == XMLParser::NODE_ELEMENT) {
@@ -1567,8 +1645,9 @@ void Collada::_parse_visual_scene(XMLParser &parser) {
vscene.root_nodes.push_back(_parse_visual_scene_node(parser));
}
- } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "visual_scene")
+ } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "visual_scene") {
break;
+ }
}
COLLADA_PRINT("Scene ID:" + id);
@@ -1576,8 +1655,9 @@ void Collada::_parse_visual_scene(XMLParser &parser) {
void Collada::_parse_animation(XMLParser &parser) {
if (!(state.import_flags & IMPORT_FLAG_ANIMATION)) {
- if (!parser.is_empty())
+ if (!parser.is_empty()) {
parser.skip_section();
+ }
return;
}
@@ -1590,8 +1670,9 @@ void Collada::_parse_animation(XMLParser &parser) {
Map<String, Vector<String>> source_param_types;
String id = "";
- if (parser.has_attribute("id"))
+ if (parser.has_attribute("id")) {
id = parser.get_attribute_value("id");
+ }
String current_source;
String current_sampler;
@@ -1623,15 +1704,17 @@ void Collada::_parse_animation(XMLParser &parser) {
current_sampler = parser.get_attribute_value("id");
samplers[current_sampler] = Map<String, String>();
} else if (name == "param") {
- if (parser.has_attribute("name"))
+ if (parser.has_attribute("name")) {
source_param_names[current_source].push_back(parser.get_attribute_value("name"));
- else
+ } else {
source_param_names[current_source].push_back("");
+ }
- if (parser.has_attribute("type"))
+ if (parser.has_attribute("type")) {
source_param_types[current_source].push_back(parser.get_attribute_value("type"));
- else
+ } else {
source_param_types[current_source].push_back("");
+ }
} else if (name == "input") {
if (current_sampler != "") {
@@ -1643,8 +1726,9 @@ void Collada::_parse_animation(XMLParser &parser) {
channel_targets.push_back(parser.get_attribute_value("target"));
}
- } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "animation")
+ } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "animation") {
break; //end of <asset>
+ }
}
for (int i = 0; i < channel_sources.size(); i++) {
@@ -1686,8 +1770,9 @@ void Collada::_parse_animation(XMLParser &parser) {
int stride = 1;
- if (source_strides.has(output_id))
+ if (source_strides.has(output_id)) {
stride = source_strides[output_id];
+ }
int output_len = stride / names.size();
ERR_CONTINUE(output_len == 0);
@@ -1699,8 +1784,9 @@ void Collada::_parse_animation(XMLParser &parser) {
for (int j = 0; j < key_count; j++) {
track.keys.write[j].data.resize(output_len);
- for (int k = 0; k < output_len; k++)
+ for (int k = 0; k < output_len; k++) {
track.keys.write[j].data.write[k] = output[l + j * stride + k]; //super weird but should work:
+ }
}
if (sampler.has("INTERPOLATION")) {
@@ -1710,10 +1796,11 @@ void Collada::_parse_animation(XMLParser &parser) {
ERR_CONTINUE(interps.size() != key_count);
for (int j = 0; j < key_count; j++) {
- if (interps[j] == "BEZIER")
+ if (interps[j] == "BEZIER") {
track.keys.write[j].interp_type = AnimationTrack::INTERP_BEZIER;
- else
+ } else {
track.keys.write[j].interp_type = AnimationTrack::INTERP_LINEAR;
+ }
}
}
@@ -1739,8 +1826,9 @@ void Collada::_parse_animation(XMLParser &parser) {
if (target.find("/") != -1) { //transform component
track.target = target.get_slicec('/', 0);
track.param = target.get_slicec('/', 1);
- if (track.param.find(".") != -1)
+ if (track.param.find(".") != -1) {
track.component = track.param.get_slice(".", 1).to_upper();
+ }
track.param = track.param.get_slice(".", 0);
if (names.size() > 1 && track.component == "") {
//this is a guess because the collada spec is ambiguous here...
@@ -1753,14 +1841,16 @@ void Collada::_parse_animation(XMLParser &parser) {
state.animation_tracks.push_back(track);
- if (!state.referenced_tracks.has(target))
+ if (!state.referenced_tracks.has(target)) {
state.referenced_tracks[target] = Vector<int>();
+ }
state.referenced_tracks[target].push_back(state.animation_tracks.size() - 1);
if (id != "") {
- if (!state.by_id_tracks.has(id))
+ if (!state.by_id_tracks.has(id)) {
state.by_id_tracks[id] = Vector<int>();
+ }
state.by_id_tracks[id].push_back(state.animation_tracks.size() - 1);
}
@@ -1772,22 +1862,26 @@ void Collada::_parse_animation(XMLParser &parser) {
void Collada::_parse_animation_clip(XMLParser &parser) {
if (!(state.import_flags & IMPORT_FLAG_ANIMATION)) {
- if (!parser.is_empty())
+ if (!parser.is_empty()) {
parser.skip_section();
+ }
return;
}
AnimationClip clip;
- if (parser.has_attribute("name"))
+ if (parser.has_attribute("name")) {
clip.name = parser.get_attribute_value("name");
- else if (parser.has_attribute("id"))
+ } else if (parser.has_attribute("id")) {
clip.name = parser.get_attribute_value("id");
- if (parser.has_attribute("start"))
+ }
+ if (parser.has_attribute("start")) {
clip.begin = parser.get_attribute_value("start").to_double();
- if (parser.has_attribute("end"))
+ }
+ if (parser.has_attribute("end")) {
clip.end = parser.get_attribute_value("end").to_double();
+ }
while (parser.read() == OK) {
if (parser.get_node_type() == XMLParser::NODE_ELEMENT) {
@@ -1797,8 +1891,9 @@ void Collada::_parse_animation_clip(XMLParser &parser) {
clip.tracks.push_back(url);
}
- } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "animation_clip")
+ } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "animation_clip") {
break; //end of <asset>
+ }
}
state.animation_clips.push_back(clip);
@@ -1819,8 +1914,9 @@ void Collada::_parse_scene(XMLParser &parser) {
state.root_physics_scene = _uri_to_id(parser.get_attribute_value("url"));
}
- } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "scene")
+ } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "scene") {
break; //end of <asset>
+ }
}
}
@@ -1854,10 +1950,12 @@ void Collada::_parse_library(XMLParser &parser) {
} else if (parser.get_node_name() == "spline") {
state.mesh_name_map[id] = (name2 != "") ? name2 : id;
_parse_curve_geometry(parser, id, name2);
- } else if (!parser.is_empty())
+ } else if (!parser.is_empty()) {
parser.skip_section();
- } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "geometry")
+ }
+ } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name() == "geometry") {
break;
+ }
}
} else if (name == "controller") {
@@ -1869,11 +1967,13 @@ void Collada::_parse_library(XMLParser &parser) {
} else if (name == "visual_scene") {
COLLADA_PRINT("visual scene");
_parse_visual_scene(parser);
- } else if (!parser.is_empty())
+ } else if (!parser.is_empty()) {
parser.skip_section();
+ }
- } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name().begins_with("library_"))
+ } else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && parser.get_node_name().begins_with("library_")) {
break; //end of <asset>
+ }
}
}
@@ -1919,8 +2019,9 @@ bool Collada::_remove_node(Node *p_parent, Node *p_node) {
p_parent->children.remove(i);
return true;
}
- if (_remove_node(p_parent->children[i], p_node))
+ if (_remove_node(p_parent->children[i], p_node)) {
return true;
+ }
}
return false;
@@ -1932,8 +2033,9 @@ void Collada::_remove_node(VisualScene *p_vscene, Node *p_node) {
p_vscene->root_nodes.remove(i);
return;
}
- if (_remove_node(p_vscene->root_nodes[i], p_node))
+ if (_remove_node(p_vscene->root_nodes[i], p_node)) {
return;
+ }
}
ERR_PRINT("ERROR: Not found node to remove?");
@@ -2090,8 +2192,9 @@ bool Collada::_optimize_skeletons(VisualScene *p_vscene, Node *p_node) {
}
for (int i = 0; i < node->children.size(); i++) {
- if (_optimize_skeletons(p_vscene, node->children[i]))
+ if (_optimize_skeletons(p_vscene, node->children[i])) {
return false; //stop processing, go up
+ }
}
return false;
@@ -2103,8 +2206,9 @@ bool Collada::_move_geometry_to_skeletons(VisualScene *p_vscene, Node *p_node, L
if (p_node->type == Node::TYPE_GEOMETRY) {
NodeGeometry *ng = static_cast<NodeGeometry *>(p_node);
- if (ng->ignore_anim)
+ if (ng->ignore_anim) {
return false; //already made child of skeleton and processeg
+ }
if (ng->controller && ng->skeletons.size()) {
String nodeid = ng->skeletons[0];
@@ -2253,8 +2357,9 @@ Error Collada::load(const String &p_path, int p_flags) {
if (parser.get_node_type() == XMLParser::NODE_ELEMENT) {
if (parser.get_node_name() == "COLLADA") {
break;
- } else if (!parser.is_empty())
+ } else if (!parser.is_empty()) {
parser.skip_section(); // unknown section, likely headers
+ }
}
}
@@ -2274,8 +2379,9 @@ Error Collada::load(const String &p_path, int p_flags) {
while ((err = parser.read()) == OK) {
/* Read all the main sections.. */
- if (parser.get_node_type() != XMLParser::NODE_ELEMENT)
+ if (parser.get_node_type() != XMLParser::NODE_ELEMENT) {
continue; //no idea what this may be, but skipping anyway
+ }
String section = parser.get_node_name();
diff --git a/editor/import/collada.h b/editor/import/collada.h
index 02c3277911..90c6c47e0b 100644
--- a/editor/import/collada.h
+++ b/editor/import/collada.h
@@ -255,11 +255,14 @@ public:
//cap to 4 and make weights add up 1
weights.resize(4);
float total = 0;
- for (int i = 0; i < 4; i++)
+ for (int i = 0; i < 4; i++) {
total += weights[i].weight;
- if (total)
- for (int i = 0; i < 4; i++)
+ }
+ if (total) {
+ for (int i = 0; i < 4; i++) {
weights.write[i].weight /= total;
+ }
+ }
}
}
@@ -274,11 +277,13 @@ public:
if (!weights.empty() || !p_vert.weights.empty()) {
if (weights.size() == p_vert.weights.size()) {
for (int i = 0; i < weights.size(); i++) {
- if (weights[i].bone_idx != p_vert.weights[i].bone_idx)
+ if (weights[i].bone_idx != p_vert.weights[i].bone_idx) {
return weights[i].bone_idx < p_vert.weights[i].bone_idx;
+ }
- if (weights[i].weight != p_vert.weights[i].weight)
+ if (weights[i].weight != p_vert.weights[i].weight) {
return weights[i].weight < p_vert.weights[i].weight;
+ }
}
} else {
return weights.size() < p_vert.weights.size();
@@ -286,16 +291,21 @@ public:
}
return (color < p_vert.color);
- } else
+ } else {
return (uv2 < p_vert.uv2);
- } else
+ }
+ } else {
return (uv < p_vert.uv);
- } else
+ }
+ } else {
return (normal < p_vert.normal);
- } else
+ }
+ } else {
return vertex < p_vert.vertex;
- } else
+ }
+ } else {
return uid < p_vert.uid;
+ }
}
Vertex() {}
@@ -347,8 +357,9 @@ public:
Node() {}
virtual ~Node() {
- for (int i = 0; i < children.size(); i++)
+ for (int i = 0; i < children.size(); i++) {
memdelete(children[i]);
+ }
};
};
@@ -395,8 +406,9 @@ public:
Vector<Node *> root_nodes;
~VisualScene() {
- for (int i = 0; i < root_nodes.size(); i++)
+ for (int i = 0; i < root_nodes.size(); i++) {
memdelete(root_nodes[i]);
+ }
}
};
diff --git a/editor/import/editor_import_collada.cpp b/editor/import/editor_import_collada.cpp
index 54b4dc2972..12cbaaa885 100644
--- a/editor/import/editor_import_collada.cpp
+++ b/editor/import/editor_import_collada.cpp
@@ -109,14 +109,16 @@ struct ColladaImport {
};
Error ColladaImport::_populate_skeleton(Skeleton3D *p_skeleton, Collada::Node *p_node, int &r_bone, int p_parent) {
- if (p_node->type != Collada::Node::TYPE_JOINT)
+ if (p_node->type != Collada::Node::TYPE_JOINT) {
return OK;
+ }
Collada::NodeJoint *joint = static_cast<Collada::NodeJoint *>(p_node);
p_skeleton->add_bone(p_node->name);
- if (p_parent >= 0)
+ if (p_parent >= 0) {
p_skeleton->set_bone_parent(r_bone, p_parent);
+ }
NodeMap nm;
nm.node = p_skeleton;
@@ -136,8 +138,9 @@ Error ColladaImport::_populate_skeleton(Skeleton3D *p_skeleton, Collada::Node *p
int id = r_bone++;
for (int i = 0; i < p_node->children.size(); i++) {
Error err = _populate_skeleton(p_skeleton, p_node->children[i], r_bone, id);
- if (err)
+ if (err) {
return err;
+ }
}
return OK;
@@ -158,8 +161,9 @@ void ColladaImport::_pre_process_lights(Collada::Node *p_node) {
}
}
- for (int i = 0; i < p_node->children.size(); i++)
+ for (int i = 0; i < p_node->children.size(); i++) {
_pre_process_lights(p_node->children[i]);
+ }
}
Error ColladaImport::_create_scene_skeletons(Collada::Node *p_node) {
@@ -175,8 +179,9 @@ Error ColladaImport::_create_scene_skeletons(Collada::Node *p_node) {
for (int i = 0; i < p_node->children.size(); i++) {
Error err = _create_scene_skeletons(p_node->children[i]);
- if (err)
+ if (err) {
return err;
+ }
}
return OK;
}
@@ -198,11 +203,13 @@ Error ColladaImport::_create_scene(Collada::Node *p_node, Node3D *p_parent) {
Collada::LightData &ld = collada.state.light_data_map[light->light];
if (ld.mode == Collada::LightData::MODE_AMBIENT) {
- if (found_directional)
+ if (found_directional) {
return OK; //do nothing not needed
+ }
- if (!bool(GLOBAL_DEF("collada/use_ambient", false)))
+ if (!bool(GLOBAL_DEF("collada/use_ambient", false))) {
return OK;
+ }
//well, it's an ambient light..
Light3D *l = memnew(DirectionalLight3D);
//l->set_color(Light::COLOR_AMBIENT,ld.color);
@@ -224,9 +231,9 @@ Error ColladaImport::_create_scene(Collada::Node *p_node, Node3D *p_parent) {
} else {
Light3D *l;
- if (ld.mode == Collada::LightData::MODE_OMNI)
+ if (ld.mode == Collada::LightData::MODE_OMNI) {
l = memnew(OmniLight3D);
- else {
+ } else {
l = memnew(SpotLight3D);
//l->set_parameter(Light::PARAM_SPOT_ANGLE,ld.spot_angle);
//l->set_parameter(Light::PARAM_SPOT_ATTENUATION,ld.spot_exp);
@@ -295,8 +302,9 @@ Error ColladaImport::_create_scene(Collada::Node *p_node, Node3D *p_parent) {
} break;
}
- if (p_node->name != "")
+ if (p_node->name != "") {
node->set_name(p_node->name);
+ }
NodeMap nm;
nm.node = node;
node_map[p_node->id] = nm;
@@ -314,8 +322,9 @@ Error ColladaImport::_create_scene(Collada::Node *p_node, Node3D *p_parent) {
for (int i = 0; i < p_node->children.size(); i++) {
Error err = _create_scene(p_node->children[i], node);
- if (err)
+ if (err) {
return err;
+ }
}
return OK;
}
@@ -329,10 +338,11 @@ Error ColladaImport::_create_material(const String &p_target) {
Ref<StandardMaterial3D> material = memnew(StandardMaterial3D);
- if (src_mat.name != "")
+ if (src_mat.name != "") {
material->set_name(src_mat.name);
- else if (effect.name != "")
+ } else if (effect.name != "") {
material->set_name(effect.name);
+ }
// DIFFUSE
@@ -459,10 +469,11 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<ArrayMesh> &p_me
p_mesh->add_blend_shape(name);
}
- if (p_morph_data->mode == "RELATIVE")
+ if (p_morph_data->mode == "RELATIVE") {
p_mesh->set_blend_shape_mode(Mesh::BLEND_SHAPE_MODE_RELATIVE);
- else if (p_morph_data->mode == "NORMALIZED")
+ } else if (p_morph_data->mode == "NORMALIZED") {
p_mesh->set_blend_shape_mode(Mesh::BLEND_SHAPE_MODE_NORMALIZED);
+ }
}
int surface = 0;
@@ -594,8 +605,9 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<ArrayMesh> &p_me
w.weight = weight_src->array[weight_index];
int bone_index = p_skin_controller->weights.indices[read_from + joint_ofs];
- if (bone_index == -1)
+ if (bone_index == -1) {
continue; //ignore this weight (refers to bind shape)
+ }
ERR_FAIL_INDEX_V(bone_index, bone_remap.size(), ERR_INVALID_DATA);
w.bone_idx = bone_remap[bone_index];
@@ -614,11 +626,14 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<ArrayMesh> &p_me
//make sure weights always add up to 1
float total = 0;
- for (int i = 0; i < weights.size(); i++)
+ for (int i = 0; i < weights.size(); i++) {
total += weights[i].weight;
- if (total)
- for (int i = 0; i < weights.size(); i++)
+ }
+ if (total) {
+ for (int i = 0; i < weights.size(); i++) {
weights.write[i].weight /= total;
+ }
+ }
if (weights.size() == 0 || total == 0) { //if nothing, add a weight to bone 0
//no weights assigned
@@ -672,8 +687,9 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<ArrayMesh> &p_me
ERR_FAIL_INDEX_V(src, p.indices.size(), ERR_INVALID_DATA);
Collada::Vertex vertex;
- if (!p_optimize)
+ if (!p_optimize) {
vertex.uid = vertidx++;
+ }
int vertex_index = p.indices[src + vertex_ofs]; //used for index field (later used by controllers)
int vertex_pos = (vertex_src->stride ? vertex_src->stride : 3) * vertex_index;
@@ -752,8 +768,9 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<ArrayMesh> &p_me
}
//build triangles if needed
- if (j == 0)
+ if (j == 0) {
prev2[0] = index;
+ }
if (j >= 2) {
//insert indices in reverse order (collada uses CCW as frontface)
@@ -809,10 +826,12 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<ArrayMesh> &p_me
if (!material_cache.has(target)) {
Error err = _create_material(target);
- if (!err)
+ if (!err) {
material = material_cache[target];
- } else
+ }
+ } else {
material = material_cache[target];
+ }
} else if (p.material != "") {
WARN_PRINT("Collada: Unreferenced material in geometry instance: " + p.material);
@@ -961,8 +980,9 @@ Error ColladaImport::_create_resources(Collada::Node *p_node, bool p_use_compres
ERR_FAIL_COND_V(interps.stride != 1, ERR_INVALID_DATA);
const Collada::CurveData::Source *tilts = nullptr;
- if (cd.control_vertices.has("TILT") && cd.sources.has(cd.control_vertices["TILT"]))
+ if (cd.control_vertices.has("TILT") && cd.sources.has(cd.control_vertices["TILT"])) {
tilts = &cd.sources[cd.control_vertices["TILT"]];
+ }
int pc = vertices.array.size() / 3;
for (int i = 0; i < pc; i++) {
@@ -985,8 +1005,9 @@ Error ColladaImport::_create_resources(Collada::Node *p_node, bool p_use_compres
out *= collada.state.unit_scale;
c->add_point(pos, in - pos, out - pos);
- if (tilts)
+ if (tilts) {
c->set_point_tilt(i, tilts->array[i]);
+ }
}
curve_cache[ng->source] = c;
@@ -1088,8 +1109,9 @@ Error ColladaImport::_create_resources(Collada::Node *p_node, bool p_use_compres
}
}
- if (!valid)
+ if (!valid) {
morphs.clear();
+ }
ngsource = "";
}
}
@@ -1134,10 +1156,12 @@ Error ColladaImport::_create_resources(Collada::Node *p_node, bool p_use_compres
Ref<Material> material;
if (!material_cache.has(target)) {
Error err = _create_material(target);
- if (!err)
+ if (!err) {
material = material_cache[target];
- } else
+ }
+ } else {
material = material_cache[target];
+ }
mi->set_surface_material(i, material);
} else if (matname != "") {
@@ -1151,8 +1175,9 @@ Error ColladaImport::_create_resources(Collada::Node *p_node, bool p_use_compres
for (int i = 0; i < p_node->children.size(); i++) {
Error err = _create_resources(p_node->children[i], p_use_compression);
- if (err)
+ if (err) {
return err;
+ }
}
return OK;
}
@@ -1274,8 +1299,9 @@ void ColladaImport::_fix_param_animation_tracks() {
void ColladaImport::create_animations(bool p_make_tracks_in_all_bones, bool p_import_value_tracks) {
_fix_param_animation_tracks();
for (int i = 0; i < collada.state.animation_clips.size(); i++) {
- for (int j = 0; j < collada.state.animation_clips[i].tracks.size(); j++)
+ for (int j = 0; j < collada.state.animation_clips[i].tracks.size(); j++) {
tracks_in_clips.insert(collada.state.animation_clips[i].tracks[j]);
+ }
}
for (int i = 0; i < collada.state.animation_tracks.size(); i++) {
@@ -1304,8 +1330,9 @@ void ColladaImport::create_animations(bool p_make_tracks_in_all_bones, bool p_im
}
create_animation(-1, p_make_tracks_in_all_bones, p_import_value_tracks);
- for (int i = 0; i < collada.state.animation_clips.size(); i++)
+ for (int i = 0; i < collada.state.animation_clips.size(); i++) {
create_animation(i, p_make_tracks_in_all_bones, p_import_value_tracks);
+ }
}
void ColladaImport::create_animation(int p_clip, bool p_make_tracks_in_all_bones, bool p_import_value_tracks) {
@@ -1318,8 +1345,9 @@ void ColladaImport::create_animation(int p_clip, bool p_make_tracks_in_all_bones
}
for (Map<String, NodeMap>::Element *E = node_map.front(); E; E = E->next()) {
- if (E->get().bone < 0)
+ if (E->get().bone < 0) {
continue;
+ }
bones_with_animation[E->key()] = false;
}
//store and validate tracks
@@ -1365,8 +1393,9 @@ void ColladaImport::create_animation(int p_clip, bool p_make_tracks_in_all_bones
float snapshot_interval = 1.0 / bake_fps; //should be customizable somewhere...
float anim_length = collada.state.animation_length;
- if (p_clip >= 0 && collada.state.animation_clips[p_clip].end)
+ if (p_clip >= 0 && collada.state.animation_clips[p_clip].end) {
anim_length = collada.state.animation_clips[p_clip].end;
+ }
while (f < anim_length) {
base_snapshots.push_back(f);
@@ -1416,8 +1445,9 @@ void ColladaImport::create_animation(int p_clip, bool p_make_tracks_in_all_bones
//use snapshot keys from anim track instead, because this was most likely exported baked
const Collada::AnimationTrack &at = collada.state.animation_tracks[nm.anim_tracks.front()->get()];
snapshots.clear();
- for (int i = 0; i < at.keys.size(); i++)
+ for (int i = 0; i < at.keys.size(); i++) {
snapshots.push_back(at.keys[i].time);
+ }
}
for (int i = 0; i < snapshots.size(); i++) {
@@ -1429,8 +1459,9 @@ void ColladaImport::create_animation(int p_clip, bool p_make_tracks_in_all_bones
continue;
}
} else {
- if (!track_filter.has(ET->get()))
+ if (!track_filter.has(ET->get())) {
continue;
+ }
}
found_anim = true;
@@ -1494,13 +1525,14 @@ void ColladaImport::create_animation(int p_clip, bool p_make_tracks_in_all_bones
}
if (nm.bone >= 0) {
- if (found_anim)
+ if (found_anim) {
bones_with_animation[E->get()] = true;
+ }
}
- if (found_anim)
+ if (found_anim) {
tracks_found = true;
- else {
+ } else {
animation->remove_track(track);
}
}
@@ -1508,8 +1540,9 @@ void ColladaImport::create_animation(int p_clip, bool p_make_tracks_in_all_bones
if (p_make_tracks_in_all_bones) {
//some bones may lack animation, but since we don't store pose as a property, we must add keyframes!
for (Map<String, bool>::Element *E = bones_with_animation.front(); E; E = E->next()) {
- if (E->get())
+ if (E->get()) {
continue;
+ }
NodeMap &nm = node_map[E->key()];
String path = scene->get_path_to(nm.node);
@@ -1550,18 +1583,21 @@ void ColladaImport::create_animation(int p_clip, bool p_make_tracks_in_all_bones
int ti = valid_animated_properties[i];
if (p_clip == -1) {
- if (track_filter.has(ti))
+ if (track_filter.has(ti)) {
continue;
+ }
} else {
- if (!track_filter.has(ti))
+ if (!track_filter.has(ti)) {
continue;
+ }
}
const Collada::AnimationTrack &at = collada.state.animation_tracks[ti];
// take snapshots
- if (!collada.state.scene_map.has(at.target))
+ if (!collada.state.scene_map.has(at.target)) {
continue;
+ }
NodeMap &nm = node_map[at.target];
String path = scene->get_path_to(nm.node);
@@ -1615,8 +1651,9 @@ void EditorSceneImporterCollada::get_extensions(List<String> *r_extensions) cons
Node *EditorSceneImporterCollada::import_scene(const String &p_path, uint32_t p_flags, int p_bake_fps, List<String> *r_missing_deps, Error *r_err) {
ColladaImport state;
uint32_t flags = Collada::IMPORT_FLAG_SCENE;
- if (p_flags & IMPORT_ANIMATION)
+ if (p_flags & IMPORT_ANIMATION) {
flags |= Collada::IMPORT_FLAG_ANIMATION;
+ }
state.use_mesh_builtin_materials = !(p_flags & IMPORT_MATERIALS_IN_INSTANCES);
state.bake_fps = p_bake_fps;
@@ -1627,10 +1664,10 @@ Node *EditorSceneImporterCollada::import_scene(const String &p_path, uint32_t p_
if (state.missing_textures.size()) {
/*
- for(int i=0;i<state.missing_textures.size();i++) {
- EditorNode::add_io_error("Texture Not Found: "+state.missing_textures[i]);
- }
- */
+ for(int i=0;i<state.missing_textures.size();i++) {
+ EditorNode::add_io_error("Texture Not Found: "+state.missing_textures[i]);
+ }
+ */
if (r_missing_deps) {
for (int i = 0; i < state.missing_textures.size(); i++) {
@@ -1645,10 +1682,11 @@ Node *EditorSceneImporterCollada::import_scene(const String &p_path, uint32_t p_
AnimationPlayer *ap = memnew(AnimationPlayer);
for (int i = 0; i < state.animations.size(); i++) {
String name;
- if (state.animations[i]->get_name() == "")
+ if (state.animations[i]->get_name() == "") {
name = "default";
- else
+ } else {
name = state.animations[i]->get_name();
+ }
if (p_flags & IMPORT_ANIMATION_DETECT_LOOP) {
if (name.begins_with("loop") || name.ends_with("loop") || name.begins_with("cycle") || name.ends_with("cycle")) {
@@ -1674,11 +1712,13 @@ Ref<Animation> EditorSceneImporterCollada::import_animation(const String &p_path
ERR_FAIL_COND_V_MSG(err != OK, RES(), "Cannot load animation from file '" + p_path + "'.");
state.create_animations(p_flags & EditorSceneImporter::IMPORT_ANIMATION_FORCE_ALL_TRACKS_IN_ALL_CLIPS, p_flags & EditorSceneImporter::IMPORT_ANIMATION_KEEP_VALUE_TRACKS);
- if (state.scene)
+ if (state.scene) {
memdelete(state.scene);
+ }
- if (state.animations.size() == 0)
+ if (state.animations.size() == 0) {
return Ref<Animation>();
+ }
Ref<Animation> anim = state.animations[0];
String base = p_path.get_basename().to_lower();
if (p_flags & IMPORT_ANIMATION_DETECT_LOOP) {
diff --git a/editor/import/editor_scene_importer_gltf.cpp b/editor/import/editor_scene_importer_gltf.cpp
index 3c9f04322e..6ffff09ce5 100644
--- a/editor/import/editor_scene_importer_gltf.cpp
+++ b/editor/import/editor_scene_importer_gltf.cpp
@@ -355,8 +355,9 @@ static Vector<uint8_t> _parse_base64_uri(const String &uri) {
}
Error EditorSceneImporterGLTF::_parse_buffers(GLTFState &state, const String &p_base_path) {
- if (!state.json.has("buffers"))
+ if (!state.json.has("buffers")) {
return OK;
+ }
const Array &buffers = state.json["buffers"];
for (GLTFBufferIndex i = 0; i < buffers.size(); i++) {
@@ -426,22 +427,29 @@ Error EditorSceneImporterGLTF::_parse_buffer_views(GLTFState &state) {
}
EditorSceneImporterGLTF::GLTFType EditorSceneImporterGLTF::_get_type_from_str(const String &p_string) {
- if (p_string == "SCALAR")
+ if (p_string == "SCALAR") {
return TYPE_SCALAR;
+ }
- if (p_string == "VEC2")
+ if (p_string == "VEC2") {
return TYPE_VEC2;
- if (p_string == "VEC3")
+ }
+ if (p_string == "VEC3") {
return TYPE_VEC3;
- if (p_string == "VEC4")
+ }
+ if (p_string == "VEC4") {
return TYPE_VEC4;
+ }
- if (p_string == "MAT2")
+ if (p_string == "MAT2") {
return TYPE_MAT2;
- if (p_string == "MAT3")
+ }
+ if (p_string == "MAT3") {
return TYPE_MAT3;
- if (p_string == "MAT4")
+ }
+ if (p_string == "MAT4") {
return TYPE_MAT4;
+ }
ERR_FAIL_V(TYPE_SCALAR);
}
@@ -714,8 +722,9 @@ Vector<double> EditorSceneImporterGLTF::_decode_accessor(GLTFState &state, const
ERR_FAIL_INDEX_V(a.buffer_view, state.buffer_views.size(), Vector<double>());
const Error err = _decode_buffer_view(state, dst, a.buffer_view, skip_every, skip_bytes, element_size, a.count, a.type, component_count, a.component_type, component_size, a.normalized, a.byte_offset, p_for_vertex);
- if (err != OK)
+ if (err != OK) {
return Vector<double>();
+ }
} else {
//fill with zeros, as bufferview is not defined.
@@ -731,14 +740,16 @@ Vector<double> EditorSceneImporterGLTF::_decode_accessor(GLTFState &state, const
const int indices_component_size = _get_component_type_size(a.sparse_indices_component_type);
Error err = _decode_buffer_view(state, indices.ptrw(), a.sparse_indices_buffer_view, 0, 0, indices_component_size, a.sparse_count, TYPE_SCALAR, 1, a.sparse_indices_component_type, indices_component_size, false, a.sparse_indices_byte_offset, false);
- if (err != OK)
+ if (err != OK) {
return Vector<double>();
+ }
Vector<double> data;
data.resize(component_count * a.sparse_count);
err = _decode_buffer_view(state, data.ptrw(), a.sparse_values_buffer_view, skip_every, skip_bytes, element_size, a.sparse_count, a.type, component_count, a.component_type, component_size, a.normalized, a.sparse_values_byte_offset, p_for_vertex);
- if (err != OK)
+ if (err != OK) {
return Vector<double>();
+ }
for (int i = 0; i < indices.size(); i++) {
const int write_offset = int(indices[i]) * component_count;
@@ -756,8 +767,9 @@ Vector<int> EditorSceneImporterGLTF::_decode_accessor_as_ints(GLTFState &state,
const Vector<double> attribs = _decode_accessor(state, p_accessor, p_for_vertex);
Vector<int> ret;
- if (attribs.size() == 0)
+ if (attribs.size() == 0) {
return ret;
+ }
const double *attribs_ptr = attribs.ptr();
const int ret_size = attribs.size();
@@ -775,8 +787,9 @@ Vector<float> EditorSceneImporterGLTF::_decode_accessor_as_floats(GLTFState &sta
const Vector<double> attribs = _decode_accessor(state, p_accessor, p_for_vertex);
Vector<float> ret;
- if (attribs.size() == 0)
+ if (attribs.size() == 0) {
return ret;
+ }
const double *attribs_ptr = attribs.ptr();
const int ret_size = attribs.size();
@@ -794,8 +807,9 @@ Vector<Vector2> EditorSceneImporterGLTF::_decode_accessor_as_vec2(GLTFState &sta
const Vector<double> attribs = _decode_accessor(state, p_accessor, p_for_vertex);
Vector<Vector2> ret;
- if (attribs.size() == 0)
+ if (attribs.size() == 0) {
return ret;
+ }
ERR_FAIL_COND_V(attribs.size() % 2 != 0, ret);
const double *attribs_ptr = attribs.ptr();
@@ -814,8 +828,9 @@ Vector<Vector3> EditorSceneImporterGLTF::_decode_accessor_as_vec3(GLTFState &sta
const Vector<double> attribs = _decode_accessor(state, p_accessor, p_for_vertex);
Vector<Vector3> ret;
- if (attribs.size() == 0)
+ if (attribs.size() == 0) {
return ret;
+ }
ERR_FAIL_COND_V(attribs.size() % 3 != 0, ret);
const double *attribs_ptr = attribs.ptr();
@@ -834,8 +849,9 @@ Vector<Color> EditorSceneImporterGLTF::_decode_accessor_as_color(GLTFState &stat
const Vector<double> attribs = _decode_accessor(state, p_accessor, p_for_vertex);
Vector<Color> ret;
- if (attribs.size() == 0)
+ if (attribs.size() == 0) {
return ret;
+ }
const int type = state.accessors[p_accessor].type;
ERR_FAIL_COND_V(!(type == TYPE_VEC3 || type == TYPE_VEC4), ret);
@@ -861,8 +877,9 @@ Vector<Quat> EditorSceneImporterGLTF::_decode_accessor_as_quat(GLTFState &state,
const Vector<double> attribs = _decode_accessor(state, p_accessor, p_for_vertex);
Vector<Quat> ret;
- if (attribs.size() == 0)
+ if (attribs.size() == 0) {
return ret;
+ }
ERR_FAIL_COND_V(attribs.size() % 4 != 0, ret);
const double *attribs_ptr = attribs.ptr();
@@ -880,8 +897,9 @@ Vector<Transform2D> EditorSceneImporterGLTF::_decode_accessor_as_xform2d(GLTFSta
const Vector<double> attribs = _decode_accessor(state, p_accessor, p_for_vertex);
Vector<Transform2D> ret;
- if (attribs.size() == 0)
+ if (attribs.size() == 0) {
return ret;
+ }
ERR_FAIL_COND_V(attribs.size() % 4 != 0, ret);
ret.resize(attribs.size() / 4);
@@ -896,8 +914,9 @@ Vector<Basis> EditorSceneImporterGLTF::_decode_accessor_as_basis(GLTFState &stat
const Vector<double> attribs = _decode_accessor(state, p_accessor, p_for_vertex);
Vector<Basis> ret;
- if (attribs.size() == 0)
+ if (attribs.size() == 0) {
return ret;
+ }
ERR_FAIL_COND_V(attribs.size() % 9 != 0, ret);
ret.resize(attribs.size() / 9);
@@ -913,8 +932,9 @@ Vector<Transform> EditorSceneImporterGLTF::_decode_accessor_as_xform(GLTFState &
const Vector<double> attribs = _decode_accessor(state, p_accessor, p_for_vertex);
Vector<Transform> ret;
- if (attribs.size() == 0)
+ if (attribs.size() == 0) {
return ret;
+ }
ERR_FAIL_COND_V(attribs.size() % 16 != 0, ret);
ret.resize(attribs.size() / 16);
@@ -928,8 +948,9 @@ Vector<Transform> EditorSceneImporterGLTF::_decode_accessor_as_xform(GLTFState &
}
Error EditorSceneImporterGLTF::_parse_meshes(GLTFState &state) {
- if (!state.json.has("meshes"))
+ if (!state.json.has("meshes")) {
return OK;
+ }
Array meshes = state.json["meshes"];
for (GLTFMeshIndex i = 0; i < meshes.size(); i++) {
@@ -1214,8 +1235,9 @@ Error EditorSceneImporterGLTF::_parse_meshes(GLTFState &state) {
}
Error EditorSceneImporterGLTF::_parse_images(GLTFState &state, const String &p_base_path) {
- if (!state.json.has("images"))
+ if (!state.json.has("images")) {
return OK;
+ }
const Array &images = state.json["images"];
for (int i = 0; i < images.size(); i++) {
@@ -1307,8 +1329,9 @@ Error EditorSceneImporterGLTF::_parse_images(GLTFState &state, const String &p_b
}
Error EditorSceneImporterGLTF::_parse_textures(GLTFState &state) {
- if (!state.json.has("textures"))
+ if (!state.json.has("textures")) {
return OK;
+ }
const Array &textures = state.json["textures"];
for (GLTFTextureIndex i = 0; i < textures.size(); i++) {
@@ -1334,8 +1357,9 @@ Ref<Texture2D> EditorSceneImporterGLTF::_get_texture(GLTFState &state, const GLT
}
Error EditorSceneImporterGLTF::_parse_materials(GLTFState &state) {
- if (!state.json.has("materials"))
+ if (!state.json.has("materials")) {
return OK;
+ }
const Array &materials = state.json["materials"];
for (GLTFMaterialIndex i = 0; i < materials.size(); i++) {
@@ -1694,8 +1718,9 @@ Error EditorSceneImporterGLTF::_verify_skin(GLTFState &state, GLTFSkin &skin) {
}
Error EditorSceneImporterGLTF::_parse_skins(GLTFState &state) {
- if (!state.json.has("skins"))
+ if (!state.json.has("skins")) {
return OK;
+ }
const Array &skins = state.json["skins"];
@@ -1940,8 +1965,9 @@ Error EditorSceneImporterGLTF::_reparent_to_fake_joint(GLTFState &state, GLTFSke
state.nodes.push_back(fake_joint);
// We better not be a joint, or we messed up in our logic
- if (node->joint)
+ if (node->joint) {
return FAILED;
+ }
fake_joint->translation = node->translation;
fake_joint->rotation = node->rotation;
@@ -2217,8 +2243,9 @@ void EditorSceneImporterGLTF::_remove_duplicate_skins(GLTFState &state) {
}
Error EditorSceneImporterGLTF::_parse_cameras(GLTFState &state) {
- if (!state.json.has("cameras"))
+ if (!state.json.has("cameras")) {
return OK;
+ }
const Array &cameras = state.json["cameras"];
@@ -2263,8 +2290,9 @@ Error EditorSceneImporterGLTF::_parse_cameras(GLTFState &state) {
}
Error EditorSceneImporterGLTF::_parse_animations(GLTFState &state) {
- if (!state.json.has("animations"))
+ if (!state.json.has("animations")) {
return OK;
+ }
const Array &animations = state.json["animations"];
@@ -2273,8 +2301,9 @@ Error EditorSceneImporterGLTF::_parse_animations(GLTFState &state) {
GLTFAnimation animation;
- if (!d.has("channels") || !d.has("samplers"))
+ if (!d.has("channels") || !d.has("samplers")) {
continue;
+ }
Array channels = d["channels"];
Array samplers = d["samplers"];
@@ -2289,8 +2318,9 @@ Error EditorSceneImporterGLTF::_parse_animations(GLTFState &state) {
for (int j = 0; j < channels.size(); j++) {
const Dictionary &c = channels[j];
- if (!c.has("target"))
+ if (!c.has("target")) {
continue;
+ }
const Dictionary &t = c["target"];
if (!t.has("node") || !t.has("path")) {
@@ -2401,8 +2431,9 @@ void EditorSceneImporterGLTF::_assign_scene_names(GLTFState &state) {
GLTFNode *n = state.nodes[i];
// Any joints get unique names generated when the skeleton is made, unique to the skeleton
- if (n->skeleton >= 0)
+ if (n->skeleton >= 0) {
continue;
+ }
if (n->name.empty()) {
if (n->mesh >= 0) {
@@ -2599,8 +2630,9 @@ T EditorSceneImporterGLTF::_interpolate_track(const Vector<float> &p_times, cons
//could use binary search, worth it?
int idx = -1;
for (int i = 0; i < p_times.size(); i++) {
- if (p_times[i] > p_time)
+ if (p_times[i] > p_time) {
break;
+ }
idx++;
}
@@ -2900,13 +2932,15 @@ Node *EditorSceneImporterGLTF::import_scene(const String &p_path, uint32_t p_fla
//binary file
//text file
Error err = _parse_glb(p_path, state);
- if (err)
+ if (err) {
return nullptr;
+ }
} else {
//text file
Error err = _parse_json(p_path, state);
- if (err)
+ if (err) {
return nullptr;
+ }
}
ERR_FAIL_COND_V(!state.json.has("asset"), nullptr);
@@ -2923,78 +2957,93 @@ Node *EditorSceneImporterGLTF::import_scene(const String &p_path, uint32_t p_fla
/* STEP 0 PARSE SCENE */
Error err = _parse_scenes(state);
- if (err != OK)
+ if (err != OK) {
return nullptr;
+ }
/* STEP 1 PARSE NODES */
err = _parse_nodes(state);
- if (err != OK)
+ if (err != OK) {
return nullptr;
+ }
/* STEP 2 PARSE BUFFERS */
err = _parse_buffers(state, p_path.get_base_dir());
- if (err != OK)
+ if (err != OK) {
return nullptr;
+ }
/* STEP 3 PARSE BUFFER VIEWS */
err = _parse_buffer_views(state);
- if (err != OK)
+ if (err != OK) {
return nullptr;
+ }
/* STEP 4 PARSE ACCESSORS */
err = _parse_accessors(state);
- if (err != OK)
+ if (err != OK) {
return nullptr;
+ }
/* STEP 5 PARSE IMAGES */
err = _parse_images(state, p_path.get_base_dir());
- if (err != OK)
+ if (err != OK) {
return nullptr;
+ }
/* STEP 6 PARSE TEXTURES */
err = _parse_textures(state);
- if (err != OK)
+ if (err != OK) {
return nullptr;
+ }
/* STEP 7 PARSE TEXTURES */
err = _parse_materials(state);
- if (err != OK)
+ if (err != OK) {
return nullptr;
+ }
/* STEP 9 PARSE SKINS */
err = _parse_skins(state);
- if (err != OK)
+ if (err != OK) {
return nullptr;
+ }
/* STEP 10 DETERMINE SKELETONS */
err = _determine_skeletons(state);
- if (err != OK)
+ if (err != OK) {
return nullptr;
+ }
/* STEP 11 CREATE SKELETONS */
err = _create_skeletons(state);
- if (err != OK)
+ if (err != OK) {
return nullptr;
+ }
/* STEP 12 CREATE SKINS */
err = _create_skins(state);
- if (err != OK)
+ if (err != OK) {
return nullptr;
+ }
/* STEP 13 PARSE MESHES (we have enough info now) */
err = _parse_meshes(state);
- if (err != OK)
+ if (err != OK) {
return nullptr;
+ }
/* STEP 14 PARSE CAMERAS */
err = _parse_cameras(state);
- if (err != OK)
+ if (err != OK) {
return nullptr;
+ }
/* STEP 15 PARSE ANIMATIONS */
err = _parse_animations(state);
- if (err != OK)
+ if (err != OK) {
return nullptr;
+ }
/* STEP 16 ASSIGN SCENE NAMES */
_assign_scene_names(state);
diff --git a/editor/import/resource_importer_bitmask.cpp b/editor/import/resource_importer_bitmask.cpp
index 5e52a95e4e..da2d1c9bdf 100644
--- a/editor/import/resource_importer_bitmask.cpp
+++ b/editor/import/resource_importer_bitmask.cpp
@@ -80,8 +80,9 @@ Error ResourceImporterBitMap::import(const String &p_source_file, const String &
Ref<Image> image;
image.instance();
Error err = ImageLoader::load_image(p_source_file, image);
- if (err != OK)
+ if (err != OK) {
return err;
+ }
int w = image->get_width();
int h = image->get_height();
diff --git a/editor/import/resource_importer_layered_texture.cpp b/editor/import/resource_importer_layered_texture.cpp
index 2c9e7dcd3b..1f39a12c25 100644
--- a/editor/import/resource_importer_layered_texture.cpp
+++ b/editor/import/resource_importer_layered_texture.cpp
@@ -239,8 +239,9 @@ Error ResourceImporterLayeredTexture::import(const String &p_source_file, const
Ref<Image> image;
image.instance();
Error err = ImageLoader::load_image(p_source_file, image, nullptr, false, 1.0);
- if (err != OK)
+ if (err != OK) {
return err;
+ }
if (compress_mode == COMPRESS_BASIS_UNIVERSAL && image->get_format() >= Image::FORMAT_RF) {
//basis universal does not support float formats, fall back
diff --git a/editor/import/resource_importer_obj.cpp b/editor/import/resource_importer_obj.cpp
index 4316a9b512..49b47bf4be 100644
--- a/editor/import/resource_importer_obj.cpp
+++ b/editor/import/resource_importer_obj.cpp
@@ -290,23 +290,26 @@ static Error _parse_obj(const String &p_path, List<Ref<Mesh>> &r_meshes, bool p_
if (face[idx].size() == 3) {
int norm = face[idx][2].to_int() - 1;
- if (norm < 0)
+ if (norm < 0) {
norm += normals.size() + 1;
+ }
ERR_FAIL_INDEX_V(norm, normals.size(), ERR_FILE_CORRUPT);
surf_tool->add_normal(normals[norm]);
}
if (face[idx].size() >= 2 && face[idx][1] != String()) {
int uv = face[idx][1].to_int() - 1;
- if (uv < 0)
+ if (uv < 0) {
uv += uvs.size() + 1;
+ }
ERR_FAIL_INDEX_V(uv, uvs.size(), ERR_FILE_CORRUPT);
surf_tool->add_uv(uvs[uv]);
}
int vtx = face[idx][0].to_int() - 1;
- if (vtx < 0)
+ if (vtx < 0) {
vtx += vertices.size() + 1;
+ }
ERR_FAIL_INDEX_V(vtx, vertices.size(), ERR_FILE_CORRUPT);
Vector3 vertex = vertices[vtx];
@@ -319,10 +322,11 @@ static Error _parse_obj(const String &p_path, List<Ref<Mesh>> &r_meshes, bool p_
}
} else if (l.begins_with("s ")) { //smoothing
String what = l.substr(2, l.length()).strip_edges();
- if (what == "off")
+ if (what == "off") {
surf_tool->add_smooth_group(false);
- else
+ } else {
surf_tool->add_smooth_group(true);
+ }
} else if (/*l.begins_with("g ") ||*/ l.begins_with("usemtl ") || (l.begins_with("o ") || f->eof_reached())) { //commit group to mesh
//groups are too annoying
if (surf_tool->get_vertex_array().size()) {
diff --git a/editor/import/resource_importer_scene.cpp b/editor/import/resource_importer_scene.cpp
index f4fb0f9f0c..ec82f78e75 100644
--- a/editor/import/resource_importer_scene.cpp
+++ b/editor/import/resource_importer_scene.cpp
@@ -127,8 +127,9 @@ void EditorScenePostImport::_bind_methods() {
}
Node *EditorScenePostImport::post_import(Node *p_scene) {
- if (get_script_instance())
+ if (get_script_instance()) {
return get_script_instance()->call("post_import", p_scene);
+ }
return p_scene;
}
@@ -173,20 +174,24 @@ String ResourceImporterScene::get_resource_type() const {
bool ResourceImporterScene::get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const {
if (p_option.begins_with("animation/")) {
- if (p_option != "animation/import" && !bool(p_options["animation/import"]))
+ if (p_option != "animation/import" && !bool(p_options["animation/import"])) {
return false;
+ }
- if (p_option == "animation/keep_custom_tracks" && int(p_options["animation/storage"]) == 0)
+ if (p_option == "animation/keep_custom_tracks" && int(p_options["animation/storage"]) == 0) {
return false;
+ }
- if (p_option.begins_with("animation/optimizer/") && p_option != "animation/optimizer/enabled" && !bool(p_options["animation/optimizer/enabled"]))
+ if (p_option.begins_with("animation/optimizer/") && p_option != "animation/optimizer/enabled" && !bool(p_options["animation/optimizer/enabled"])) {
return false;
+ }
if (p_option.begins_with("animation/clip_")) {
int max_clip = p_options["animation/clips/amount"];
int clip = p_option.get_slice("/", 1).get_slice("_", 1).to_int() - 1;
- if (clip >= max_clip)
+ if (clip >= max_clip) {
return false;
+ }
}
}
@@ -240,12 +245,15 @@ static bool _teststr(const String &p_what, const String &p_str) {
what = what.substr(0, what.length() - 1);
}
- if (what.findn("$" + p_str) != -1) //blender and other stuff
+ if (what.findn("$" + p_str) != -1) { //blender and other stuff
return true;
- if (what.to_lower().ends_with("-" + p_str)) //collada only supports "_" and "-" besides letters
+ }
+ if (what.to_lower().ends_with("-" + p_str)) { //collada only supports "_" and "-" besides letters
return true;
- if (what.to_lower().ends_with("_" + p_str)) //collada only supports "_" and "-" besides letters
+ }
+ if (what.to_lower().ends_with("_" + p_str)) { //collada only supports "_" and "-" besides letters
return true;
+ }
return false;
}
@@ -259,12 +267,15 @@ static String _fixstr(const String &p_what, const String &p_str) {
String end = p_what.substr(what.length(), p_what.length() - what.length());
- if (what.findn("$" + p_str) != -1) //blender and other stuff
+ if (what.findn("$" + p_str) != -1) { //blender and other stuff
return what.replace("$" + p_str, "") + end;
- if (what.to_lower().ends_with("-" + p_str)) //collada only supports "_" and "-" besides letters
+ }
+ if (what.to_lower().ends_with("-" + p_str)) { //collada only supports "_" and "-" besides letters
return what.substr(0, what.length() - (p_str.length() + 1)) + end;
- if (what.to_lower().ends_with("_" + p_str)) //collada only supports "_" and "-" besides letters
+ }
+ if (what.to_lower().ends_with("_" + p_str)) { //collada only supports "_" and "-" besides letters
return what.substr(0, what.length() - (p_str.length() + 1)) + end;
+ }
return what;
}
@@ -308,8 +319,9 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh>
if (m.is_valid()) {
for (int i = 0; i < m->get_surface_count(); i++) {
Ref<StandardMaterial3D> mat = m->surface_get_material(i);
- if (!mat.is_valid())
+ if (!mat.is_valid()) {
continue;
+ }
if (_teststr(mat->get_name(), "alpha")) {
mat->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
@@ -353,8 +365,9 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh>
}
if (_teststr(name, "colonly") || _teststr(name, "convcolonly")) {
- if (isroot)
+ if (isroot) {
return p_node;
+ }
MeshInstance3D *mi = Object::cast_to<MeshInstance3D>(p_node);
if (mi) {
Ref<Mesh> mesh = mi->get_mesh();
@@ -436,8 +449,9 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh>
}
} else if (_teststr(name, "rigid") && Object::cast_to<MeshInstance3D>(p_node)) {
- if (isroot)
+ if (isroot) {
return p_node;
+ }
MeshInstance3D *mi = Object::cast_to<MeshInstance3D>(p_node);
Ref<Mesh> mesh = mi->get_mesh();
@@ -523,8 +537,9 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh>
}
} else if (_teststr(name, "navmesh") && Object::cast_to<MeshInstance3D>(p_node)) {
- if (isroot)
+ if (isroot) {
return p_node;
+ }
MeshInstance3D *mi = Object::cast_to<MeshInstance3D>(p_node);
@@ -541,8 +556,9 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh>
memdelete(p_node);
p_node = nmi;
} else if (_teststr(name, "vehicle")) {
- if (isroot)
+ if (isroot) {
return p_node;
+ }
Node *owner = p_node->get_owner();
Node3D *s = Object::cast_to<Node3D>(p_node);
@@ -560,8 +576,9 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh>
p_node = bv;
} else if (_teststr(name, "wheel")) {
- if (isroot)
+ if (isroot) {
return p_node;
+ }
Node *owner = p_node->get_owner();
Node3D *s = Object::cast_to<Node3D>(p_node);
@@ -622,16 +639,18 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh>
}
void ResourceImporterScene::_create_clips(Node *scene, const Array &p_clips, bool p_bake_all) {
- if (!scene->has_node(String("AnimationPlayer")))
+ if (!scene->has_node(String("AnimationPlayer"))) {
return;
+ }
Node *n = scene->get_node(String("AnimationPlayer"));
ERR_FAIL_COND(!n);
AnimationPlayer *anim = Object::cast_to<AnimationPlayer>(n);
ERR_FAIL_COND(!anim);
- if (!anim->has_animation("default"))
+ if (!anim->has_animation("default")) {
return;
+ }
Ref<Animation> default_anim = anim->get_animation("default");
@@ -640,8 +659,9 @@ void ResourceImporterScene::_create_clips(Node *scene, const Array &p_clips, boo
float from = p_clips[i + 1];
float to = p_clips[i + 2];
bool loop = p_clips[i + 3];
- if (from >= to)
+ if (from >= to) {
continue;
+ }
Ref<Animation> new_anim = memnew(Animation);
@@ -746,8 +766,9 @@ void ResourceImporterScene::_filter_anim_tracks(Ref<Animation> anim, Set<String>
}
void ResourceImporterScene::_filter_tracks(Node *scene, const String &p_text) {
- if (!scene->has_node(String("AnimationPlayer")))
+ if (!scene->has_node(String("AnimationPlayer"))) {
return;
+ }
Node *n = scene->get_node(String("AnimationPlayer"));
ERR_FAIL_COND(!n);
AnimationPlayer *anim = Object::cast_to<AnimationPlayer>(n);
@@ -779,55 +800,63 @@ void ResourceImporterScene::_filter_tracks(Node *scene, const String &p_text) {
Vector<String> filters = strings[i].substr(1, strings[i].length()).split(",");
for (int j = 0; j < filters.size(); j++) {
String fname = filters[j].strip_edges();
- if (fname == "")
+ if (fname == "") {
continue;
+ }
int fc = fname[0];
bool plus;
- if (fc == '+')
+ if (fc == '+') {
plus = true;
- else if (fc == '-')
+ } else if (fc == '-') {
plus = false;
- else
+ } else {
continue;
+ }
String filter = fname.substr(1, fname.length()).strip_edges();
- if (!name.matchn(filter))
+ if (!name.matchn(filter)) {
continue;
+ }
valid_for_this = plus;
}
- if (valid_for_this)
+ if (valid_for_this) {
valid = true;
+ }
} else if (valid_for_this) {
Ref<Animation> a = anim->get_animation(name);
- if (!a.is_valid())
+ if (!a.is_valid()) {
continue;
+ }
for (int j = 0; j < a->get_track_count(); j++) {
String path = a->track_get_path(j);
String tname = strings[i];
- if (tname == "")
+ if (tname == "") {
continue;
+ }
int fc = tname[0];
bool plus;
- if (fc == '+')
+ if (fc == '+') {
plus = true;
- else if (fc == '-')
+ } else if (fc == '-') {
plus = false;
- else
+ } else {
continue;
+ }
String filter = tname.substr(1, tname.length()).strip_edges();
- if (!path.matchn(filter))
+ if (!path.matchn(filter)) {
continue;
+ }
- if (plus)
+ if (plus) {
keep_local.insert(path);
- else if (!keep.has(path)) {
+ } else if (!keep.has(path)) {
keep_local.erase(path);
}
}
@@ -844,8 +873,9 @@ void ResourceImporterScene::_filter_tracks(Node *scene, const String &p_text) {
}
void ResourceImporterScene::_optimize_animations(Node *scene, float p_max_lin_error, float p_max_ang_error, float p_max_angle) {
- if (!scene->has_node(String("AnimationPlayer")))
+ if (!scene->has_node(String("AnimationPlayer"))) {
return;
+ }
Node *n = scene->get_node(String("AnimationPlayer"));
ERR_FAIL_COND(!n);
AnimationPlayer *anim = Object::cast_to<AnimationPlayer>(n);
@@ -1005,10 +1035,12 @@ void ResourceImporterScene::_make_external_resources(Node *p_node, const String
for (int i = 0; i < mesh->get_surface_count(); i++) {
mat = mesh->surface_get_material(i);
- if (!mat.is_valid())
+ if (!mat.is_valid()) {
continue;
- if (mat->get_name() == "")
+ }
+ if (mat->get_name() == "") {
continue;
+ }
if (!p_materials.has(mat)) {
String ext_name;
@@ -1072,8 +1104,9 @@ void ResourceImporterScene::get_import_options(List<ImportOption> *r_options, in
String script_ext_hint;
for (List<String>::Element *E = script_extentions.front(); E; E = E->next()) {
- if (script_ext_hint != "")
+ if (script_ext_hint != "") {
script_ext_hint += ",";
+ }
script_ext_hint += "*." + E->get();
}
@@ -1130,8 +1163,9 @@ Node *ResourceImporterScene::import_scene_from_other_importer(EditorSceneImporte
String ext = p_path.get_extension().to_lower();
for (Set<Ref<EditorSceneImporter>>::Element *E = importers.front(); E; E = E->next()) {
- if (E->get().ptr() == p_exception)
+ if (E->get().ptr() == p_exception) {
continue;
+ }
List<String> extensions;
E->get()->get_extensions(&extensions);
@@ -1142,8 +1176,9 @@ Node *ResourceImporterScene::import_scene_from_other_importer(EditorSceneImporte
}
}
- if (importer.is_valid())
+ if (importer.is_valid()) {
break;
+ }
}
ERR_FAIL_COND_V(!importer.is_valid(), nullptr);
@@ -1158,8 +1193,9 @@ Ref<Animation> ResourceImporterScene::import_animation_from_other_importer(Edito
String ext = p_path.get_extension().to_lower();
for (Set<Ref<EditorSceneImporter>>::Element *E = importers.front(); E; E = E->next()) {
- if (E->get().ptr() == p_exception)
+ if (E->get().ptr() == p_exception) {
continue;
+ }
List<String> extensions;
E->get()->get_extensions(&extensions);
@@ -1170,8 +1206,9 @@ Ref<Animation> ResourceImporterScene::import_animation_from_other_importer(Edito
}
}
- if (importer.is_valid())
+ if (importer.is_valid()) {
break;
+ }
}
ERR_FAIL_COND_V(!importer.is_valid(), nullptr);
@@ -1199,8 +1236,9 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p
}
}
- if (importer.is_valid())
+ if (importer.is_valid()) {
break;
+ }
}
ERR_FAIL_COND_V(!importer.is_valid(), ERR_FILE_UNRECOGNIZED);
@@ -1208,23 +1246,29 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p
float fps = p_options["animation/fps"];
int import_flags = EditorSceneImporter::IMPORT_ANIMATION_DETECT_LOOP;
- if (!bool(p_options["animation/optimizer/remove_unused_tracks"]))
+ if (!bool(p_options["animation/optimizer/remove_unused_tracks"])) {
import_flags |= EditorSceneImporter::IMPORT_ANIMATION_FORCE_ALL_TRACKS_IN_ALL_CLIPS;
+ }
- if (bool(p_options["animation/import"]))
+ if (bool(p_options["animation/import"])) {
import_flags |= EditorSceneImporter::IMPORT_ANIMATION;
+ }
- if (int(p_options["meshes/compress"]))
+ if (int(p_options["meshes/compress"])) {
import_flags |= EditorSceneImporter::IMPORT_USE_COMPRESSION;
+ }
- if (bool(p_options["meshes/ensure_tangents"]))
+ if (bool(p_options["meshes/ensure_tangents"])) {
import_flags |= EditorSceneImporter::IMPORT_GENERATE_TANGENT_ARRAYS;
+ }
- if (int(p_options["materials/location"]) == 0)
+ if (int(p_options["materials/location"]) == 0) {
import_flags |= EditorSceneImporter::IMPORT_MATERIALS_IN_INSTANCES;
+ }
- if (bool(p_options["skins/use_named_skins"]))
+ if (bool(p_options["skins/use_named_skins"])) {
import_flags |= EditorSceneImporter::IMPORT_USE_NAMED_SKIN_BINDS;
+ }
Error err = OK;
List<String> missing_deps; // for now, not much will be done with this
@@ -1262,10 +1306,11 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p
Object::cast_to<Node3D>(scene)->scale(Vector3(root_scale, root_scale, root_scale));
}
- if (p_options["nodes/root_name"] != "Scene Root")
+ if (p_options["nodes/root_name"] != "Scene Root") {
scene->set_name(p_options["nodes/root_name"]);
- else
+ } else {
scene->set_name(p_save_path.get_file().get_basename());
+ }
err = OK;
@@ -1345,8 +1390,9 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p
FileAccess *file = FileAccess::open(cache_file_path, FileAccess::READ, &err2);
if (err2) {
- if (file)
+ if (file) {
memdelete(file);
+ }
} else {
int cache_size = file->get_len();
cache_data.resize(cache_size);
@@ -1405,8 +1451,9 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p
FileAccess *file = FileAccess::open(cache_file_path, FileAccess::WRITE, &err2);
if (err2) {
- if (file)
+ if (file) {
memdelete(file);
+ }
} else {
// Store number of entries
file->store_32(used_unwraps.size());
@@ -1486,8 +1533,9 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p
//save sub-scenes as instances!
for (int i = 0; i < scene->get_child_count(); i++) {
Node *child = scene->get_child(i);
- if (child->get_owner() != scene)
+ if (child->get_owner() != scene) {
continue; //not a real child probably created by scene type (ig, a scrollbar)
+ }
_replace_owner(child, scene, child);
String cn = String(child->get_name()).strip_edges().replace(".", "_").replace(":", "_");
diff --git a/editor/import/resource_importer_texture.cpp b/editor/import/resource_importer_texture.cpp
index ab23ab6db6..a13324f0fc 100644
--- a/editor/import/resource_importer_texture.cpp
+++ b/editor/import/resource_importer_texture.cpp
@@ -314,16 +314,21 @@ void ResourceImporterTexture::_save_stex(const Ref<Image> &p_image, const String
f->store_32(p_image->get_height());
uint32_t flags = 0;
- if (p_streamable)
+ if (p_streamable) {
flags |= StreamTexture2D::FORMAT_BIT_STREAM;
- if (p_mipmaps)
+ }
+ if (p_mipmaps) {
flags |= StreamTexture2D::FORMAT_BIT_HAS_MIPMAPS; //mipmaps bit
- if (p_detect_3d)
+ }
+ if (p_detect_3d) {
flags |= StreamTexture2D::FORMAT_BIT_DETECT_3D;
- if (p_detect_roughness)
+ }
+ if (p_detect_roughness) {
flags |= StreamTexture2D::FORMAT_BIT_DETECT_ROUGNESS;
- if (p_detect_normal)
+ }
+ if (p_detect_normal) {
flags |= StreamTexture2D::FORMAT_BIT_DETECT_NORMAL;
+ }
f->store_32(flags);
f->store_32(p_limit_mipmap);
@@ -407,8 +412,9 @@ Error ResourceImporterTexture::import(const String &p_source_file, const String
Ref<Image> image;
image.instance();
Error err = ImageLoader::load_image(p_source_file, image, nullptr, hdr_as_srgb, scale);
- if (err != OK)
+ if (err != OK) {
return err;
+ }
Array formats_imported;
diff --git a/editor/import/resource_importer_texture_atlas.cpp b/editor/import/resource_importer_texture_atlas.cpp
index 0ef5d84eca..0818655c4c 100644
--- a/editor/import/resource_importer_texture_atlas.cpp
+++ b/editor/import/resource_importer_texture_atlas.cpp
@@ -176,10 +176,11 @@ static void _plot_triangle(Vector2 *vertices, const Vector2 &p_offset, bool p_tr
}
}
xf += dx_far;
- if (yi < y[1])
+ if (yi < y[1]) {
xt += dx_upper;
- else
+ } else {
xt += dx_low;
+ }
}
}
diff --git a/editor/import/resource_importer_wav.cpp b/editor/import/resource_importer_wav.cpp
index eace84400a..cb669b4c89 100644
--- a/editor/import/resource_importer_wav.cpp
+++ b/editor/import/resource_importer_wav.cpp
@@ -260,8 +260,9 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s
* 22:38 06.07.2017 GMT
**/
- for (int i = 0; i < 10; i++)
+ for (int i = 0; i < 10; i++) {
file->get_32(); // i wish to know why should i do this... no doc!
+ }
// only read 0x00 (loop forward), 0x01 (loop ping-pong) and 0x02 (loop backward)
// Skip anything else because it's not supported, reserved for future uses or sampler specific
@@ -361,8 +362,9 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s
float max = 0;
for (int i = 0; i < data.size(); i++) {
float amp = Math::abs(data[i]);
- if (amp > max)
+ if (amp > max) {
max = amp;
+ }
}
if (max > 0) {
diff --git a/editor/import/resource_importer_wav.h b/editor/import/resource_importer_wav.h
index b48c5f4c32..3ff3aea9f4 100644
--- a/editor/import/resource_importer_wav.h
+++ b/editor/import/resource_importer_wav.h
@@ -72,8 +72,9 @@ public:
int datalen = p_data.size();
int datamax = datalen;
- if (datalen & 1)
+ if (datalen & 1) {
datalen++;
+ }
dst_data.resize(datalen / 2 + 4);
uint8_t *w = dst_data.ptrw();
@@ -96,9 +97,9 @@ public:
uint8_t nibble;
int16_t xm_sample;
- if (i >= datamax)
+ if (i >= datamax) {
xm_sample = 0;
- else {
+ } else {
xm_sample = CLAMP(in[i] * 32767.0, -32768, 32767);
/*
if (xm_sample==32767 || xm_sample==-32768)
@@ -130,10 +131,11 @@ public:
mask >>= 1;
};
- if (nibble & 8)
+ if (nibble & 8) {
prev -= vpdiff;
- else
+ } else {
prev += vpdiff;
+ }
if (prev > 32767) {
//printf("%i,xms %i, prev %i,diff %i, vpdiff %i, clip up %i\n",i,xm_sample,prev,diff,vpdiff,prev);
@@ -144,10 +146,11 @@ public:
}
step_idx += _ima_adpcm_index_table[nibble];
- if (step_idx < 0)
+ if (step_idx < 0) {
step_idx = 0;
- else if (step_idx > 88)
+ } else if (step_idx > 88) {
step_idx = 88;
+ }
if (i & 1) {
*out |= nibble << 4;
diff --git a/editor/import_dock.cpp b/editor/import_dock.cpp
index 4a3011086f..1128b72c5a 100644
--- a/editor/import_dock.cpp
+++ b/editor/import_dock.cpp
@@ -66,8 +66,9 @@ public:
}
void _get_property_list(List<PropertyInfo> *p_list) const {
for (const List<PropertyInfo>::Element *E = properties.front(); E; E = E->next()) {
- if (!importer->get_option_visibility(E->get().name, values))
+ if (!importer->get_option_visibility(E->get().name, values)) {
continue;
+ }
PropertyInfo pi = E->get();
if (checking) {
pi.usage |= PROPERTY_USAGE_CHECKABLE;
@@ -367,8 +368,9 @@ void ImportDock::clear() {
}
static bool _find_owners(EditorFileSystemDirectory *efsd, const String &p_path) {
- if (!efsd)
+ if (!efsd) {
return false;
+ }
for (int i = 0; i < efsd->get_subdir_count(); i++) {
if (_find_owners(efsd->get_subdir(i), p_path)) {
@@ -378,8 +380,9 @@ static bool _find_owners(EditorFileSystemDirectory *efsd, const String &p_path)
for (int i = 0; i < efsd->get_file_count(); i++) {
Vector<String> deps = efsd->get_file_deps(i);
- if (deps.find(p_path) != -1)
+ if (deps.find(p_path) != -1) {
return true;
+ }
}
return false;
diff --git a/editor/inspector_dock.cpp b/editor/inspector_dock.cpp
index 8ada7e9ba5..2b26851140 100644
--- a/editor/inspector_dock.cpp
+++ b/editor/inspector_dock.cpp
@@ -68,14 +68,16 @@ void InspectorDock::_menu_option(int p_option) {
case OBJECT_COPY_PARAMS: {
editor_data->apply_changes_in_editors();
- if (current)
+ if (current) {
editor_data->copy_object_params(current);
+ }
} break;
case OBJECT_PASTE_PARAMS: {
editor_data->apply_changes_in_editors();
- if (current)
+ if (current) {
editor_data->paste_object_params(current);
+ }
} break;
case OBJECT_UNIQUE_RESOURCES: {
@@ -85,8 +87,9 @@ void InspectorDock::_menu_option(int p_option) {
current->get_property_list(&props);
Map<RES, RES> duplicates;
for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
- if (!(E->get().usage & PROPERTY_USAGE_STORAGE))
+ if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) {
continue;
+ }
Variant v = current->get(E->get().name);
if (v.is_ref()) {
@@ -169,10 +172,11 @@ void InspectorDock::_save_resource(bool save_as) const {
RES current_res = RES(Object::cast_to<Resource>(current_obj));
- if (save_as)
+ if (save_as) {
editor->save_resource_as(current_res);
- else
+ } else {
editor->save_resource(current_res);
+ }
}
void InspectorDock::_unref_resource() const {
@@ -233,9 +237,9 @@ void InspectorDock::_prepare_history() {
String text;
if (Object::cast_to<Resource>(obj)) {
Resource *r = Object::cast_to<Resource>(obj);
- if (r->get_path().is_resource_file())
+ if (r->get_path().is_resource_file()) {
text = r->get_path().get_file();
- else if (r->get_name() != String()) {
+ } else if (r->get_name() != String()) {
text = r->get_name();
} else {
text = r->get_class();
@@ -259,8 +263,9 @@ void InspectorDock::_select_history(int p_idx) {
//push it to the top, it is not correct, but it's more useful
ObjectID id = EditorNode::get_singleton()->get_editor_history()->get_history_obj(p_idx);
Object *obj = ObjectDB::get_instance(id);
- if (!obj)
+ if (!obj) {
return;
+ }
editor->push_item(obj);
}
@@ -276,22 +281,25 @@ void InspectorDock::_resource_created() {
}
void InspectorDock::_resource_selected(const RES &p_res, const String &p_property) {
- if (p_res.is_null())
+ if (p_res.is_null()) {
return;
+ }
RES r = p_res;
editor->push_item(r.operator->(), p_property);
}
void InspectorDock::_edit_forward() {
- if (EditorNode::get_singleton()->get_editor_history()->next())
+ if (EditorNode::get_singleton()->get_editor_history()->next()) {
editor->edit_current();
+ }
}
void InspectorDock::_edit_back() {
EditorHistory *editor_history = EditorNode::get_singleton()->get_editor_history();
- if ((current && editor_history->previous()) || editor_history->get_path_size() == 1)
+ if ((current && editor_history->previous()) || editor_history->get_path_size() == 1) {
editor->edit_current();
+ }
}
void InspectorDock::_menu_collapseall() {
@@ -308,8 +316,9 @@ void InspectorDock::_property_keyed(const String &p_keyed, const Variant &p_valu
void InspectorDock::_transform_keyed(Object *sp, const String &p_sub, const Transform &p_key) {
Node3D *s = Object::cast_to<Node3D>(sp);
- if (!s)
+ if (!s) {
return;
+ }
AnimationPlayerEditor::singleton->get_track_editor()->insert_transform_key(s, p_sub, p_key);
}
diff --git a/editor/multi_node_edit.cpp b/editor/multi_node_edit.cpp
index 0d795cc163..1077aca7b3 100644
--- a/editor/multi_node_edit.cpp
+++ b/editor/multi_node_edit.cpp
@@ -39,8 +39,9 @@ bool MultiNodeEdit::_set(const StringName &p_name, const Variant &p_value) {
bool MultiNodeEdit::_set_impl(const StringName &p_name, const Variant &p_value, const String &p_field) {
Node *es = EditorNode::get_singleton()->get_edited_scene();
- if (!es)
+ if (!es) {
return false;
+ }
String name = p_name;
@@ -52,12 +53,14 @@ bool MultiNodeEdit::_set_impl(const StringName &p_name, const Variant &p_value,
ur->create_action(TTR("MultiNode Set") + " " + String(name), UndoRedo::MERGE_ENDS);
for (const List<NodePath>::Element *E = nodes.front(); E; E = E->next()) {
- if (!es->has_node(E->get()))
+ if (!es->has_node(E->get())) {
continue;
+ }
Node *n = es->get_node(E->get());
- if (!n)
+ if (!n) {
continue;
+ }
if (p_value.get_type() == Variant::NODE_PATH) {
Node *tonode = n->get_node(p_value);
@@ -86,8 +89,9 @@ bool MultiNodeEdit::_set_impl(const StringName &p_name, const Variant &p_value,
bool MultiNodeEdit::_get(const StringName &p_name, Variant &r_ret) const {
Node *es = EditorNode::get_singleton()->get_edited_scene();
- if (!es)
+ if (!es) {
return false;
+ }
String name = p_name;
if (name == "scripts") { // script set is intercepted at object level (check Variant Object::get() ) ,so use a different name
@@ -95,17 +99,20 @@ bool MultiNodeEdit::_get(const StringName &p_name, Variant &r_ret) const {
}
for (const List<NodePath>::Element *E = nodes.front(); E; E = E->next()) {
- if (!es->has_node(E->get()))
+ if (!es->has_node(E->get())) {
continue;
+ }
const Node *n = es->get_node(E->get());
- if (!n)
+ if (!n) {
continue;
+ }
bool found;
r_ret = n->get(name, &found);
- if (found)
+ if (found) {
return true;
+ }
}
return false;
@@ -115,27 +122,31 @@ void MultiNodeEdit::_get_property_list(List<PropertyInfo> *p_list) const {
HashMap<String, PLData> usage;
Node *es = EditorNode::get_singleton()->get_edited_scene();
- if (!es)
+ if (!es) {
return;
+ }
int nc = 0;
List<PLData *> data_list;
for (const List<NodePath>::Element *E = nodes.front(); E; E = E->next()) {
- if (!es->has_node(E->get()))
+ if (!es->has_node(E->get())) {
continue;
+ }
Node *n = es->get_node(E->get());
- if (!n)
+ if (!n) {
continue;
+ }
List<PropertyInfo> plist;
n->get_property_list(&plist, true);
for (List<PropertyInfo>::Element *F = plist.front(); F; F = F->next()) {
- if (F->get().name == "script")
+ if (F->get().name == "script") {
continue; //added later manually, since this is intercepted before being set (check Variant Object::get() )
+ }
if (!usage.has(F->get().name)) {
PLData pld;
pld.uses = 0;
@@ -145,8 +156,9 @@ void MultiNodeEdit::_get_property_list(List<PropertyInfo> *p_list) const {
}
// Make sure only properties with the same exact PropertyInfo data will appear
- if (usage[F->get().name].info == F->get())
+ if (usage[F->get().name].info == F->get()) {
usage[F->get().name].uses++;
+ }
}
nc++;
diff --git a/editor/node_3d_editor_gizmos.cpp b/editor/node_3d_editor_gizmos.cpp
index 20b84f9358..0eb4e6036a 100644
--- a/editor/node_3d_editor_gizmos.cpp
+++ b/editor/node_3d_editor_gizmos.cpp
@@ -71,21 +71,25 @@
bool EditorNode3DGizmo::is_editable() const {
ERR_FAIL_COND_V(!spatial_node, false);
Node *edited_root = spatial_node->get_tree()->get_edited_scene_root();
- if (spatial_node == edited_root)
+ if (spatial_node == edited_root) {
return true;
- if (spatial_node->get_owner() == edited_root)
+ }
+ if (spatial_node->get_owner() == edited_root) {
return true;
+ }
- if (edited_root->is_editable_instance(spatial_node->get_owner()))
+ if (edited_root->is_editable_instance(spatial_node->get_owner())) {
return true;
+ }
return false;
}
void EditorNode3DGizmo::clear() {
for (int i = 0; i < instances.size(); i++) {
- if (instances[i].instance.is_valid())
+ if (instances[i].instance.is_valid()) {
RS::get_singleton()->free(instances[i].instance);
+ }
}
billboard_handle = false;
@@ -164,8 +168,9 @@ void EditorNode3DGizmo::Instance::create_instance(Node3D *p_base, bool p_hidden)
if (skin_reference.is_valid()) {
RS::get_singleton()->instance_attach_skeleton(instance, skin_reference->get_skeleton());
}
- if (extra_margin)
+ if (extra_margin) {
RS::get_singleton()->instance_set_extra_visibility_margin(instance, 1);
+ }
RS::get_singleton()->instance_geometry_set_cast_shadows_setting(instance, RS::SHADOW_CASTING_SETTING_OFF);
int layer = p_hidden ? 0 : 1 << Node3DEditorViewport::GIZMO_EDIT_LAYER;
RS::get_singleton()->instance_set_layer_mask(instance, layer); //gizmos are 26
@@ -209,10 +214,11 @@ void EditorNode3DGizmo::add_lines(const Vector<Vector3> &p_lines, const Ref<Mate
{
Color *w = color.ptrw();
for (int i = 0; i < p_lines.size(); i++) {
- if (is_selected())
+ if (is_selected()) {
w[i] = Color(1, 1, 1, 0.8) * p_modulate;
- else
+ } else {
w[i] = Color(1, 1, 1, 0.2) * p_modulate;
+ }
}
}
@@ -320,8 +326,9 @@ void EditorNode3DGizmo::add_collision_segments(const Vector<Vector3> &p_lines) {
void EditorNode3DGizmo::add_handles(const Vector<Vector3> &p_handles, const Ref<Material> &p_material, bool p_billboard, bool p_secondary) {
billboard_handle = p_billboard;
- if (!is_selected() || !is_editable())
+ if (!is_selected() || !is_editable()) {
return;
+ }
ERR_FAIL_COND(!spatial_node);
@@ -338,11 +345,13 @@ void EditorNode3DGizmo::add_handles(const Vector<Vector3> &p_handles, const Ref<
Color *w = colors.ptrw();
for (int i = 0; i < p_handles.size(); i++) {
Color col(1, 1, 1, 1);
- if (is_handle_highlighted(i))
+ if (is_handle_highlighted(i)) {
col = Color(0, 0, 1, 0.9);
+ }
- if (Node3DEditor::get_singleton()->get_over_gizmo_handle() != i)
+ if (Node3DEditor::get_singleton()->get_over_gizmo_handle() != i) {
col.a = 0.8;
+ }
w[i] = col;
}
@@ -410,8 +419,9 @@ bool EditorNode3DGizmo::intersect_frustum(const Camera3D *p_camera, const Vector
ERR_FAIL_COND_V(!spatial_node, false);
ERR_FAIL_COND_V(!valid, false);
- if (hidden && !gizmo_plugin->is_selectable_when_hidden())
+ if (hidden && !gizmo_plugin->is_selectable_when_hidden()) {
return false;
+ }
if (selectable_icon_size > 0.0f) {
Vector3 origin = spatial_node->get_global_transform().get_origin();
@@ -448,12 +458,14 @@ bool EditorNode3DGizmo::intersect_frustum(const Camera3D *p_camera, const Vector
break;
}
}
- if (any_out)
+ if (any_out) {
break;
+ }
}
- if (!any_out)
+ if (!any_out) {
return true;
+ }
}
if (collision_mesh.is_valid()) {
@@ -483,8 +495,9 @@ bool EditorNode3DGizmo::intersect_ray(Camera3D *p_camera, const Point2 &p_point,
ERR_FAIL_COND_V(!spatial_node, false);
ERR_FAIL_COND_V(!valid, false);
- if (hidden && !gizmo_plugin->is_selectable_when_hidden())
+ if (hidden && !gizmo_plugin->is_selectable_when_hidden()) {
return false;
+ }
if (r_gizmo_handle && !hidden) {
Transform t = spatial_node->get_global_transform();
@@ -618,8 +631,9 @@ bool EditorNode3DGizmo::intersect_ray(Camera3D *p_camera, const Point2 &p_point,
tcp = a;
}
- if (camp.distance_to(tcp) < p_camera->get_znear())
+ if (camp.distance_to(tcp) < p_camera->get_znear()) {
continue;
+ }
cp = tcp;
cpd = pd;
}
@@ -681,8 +695,9 @@ void EditorNode3DGizmo::free() {
ERR_FAIL_COND(!valid);
for (int i = 0; i < instances.size(); i++) {
- if (instances[i].instance.is_valid())
+ if (instances[i].instance.is_valid()) {
RS::get_singleton()->free(instances[i].instance);
+ }
instances.write[i].instance = RID();
}
@@ -743,8 +758,9 @@ EditorNode3DGizmo::EditorNode3DGizmo() {
}
EditorNode3DGizmo::~EditorNode3DGizmo() {
- if (gizmo_plugin != nullptr)
+ if (gizmo_plugin != nullptr) {
gizmo_plugin->unregister_gizmo(this);
+ }
clear();
}
@@ -783,18 +799,21 @@ int Light3DGizmoPlugin::get_priority() const {
}
String Light3DGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_idx) const {
- if (p_idx == 0)
+ if (p_idx == 0) {
return "Radius";
- else
+ } else {
return "Aperture";
+ }
}
Variant Light3DGizmoPlugin::get_handle_value(EditorNode3DGizmo *p_gizmo, int p_idx) const {
Light3D *light = Object::cast_to<Light3D>(p_gizmo->get_spatial_node());
- if (p_idx == 0)
+ if (p_idx == 0) {
return light->get_param(Light3D::PARAM_RANGE);
- if (p_idx == 1)
+ }
+ if (p_idx == 1) {
return light->get_param(Light3D::PARAM_SPOT_ANGLE);
+ }
return Variant();
}
@@ -845,8 +864,9 @@ void Light3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camer
d = Math::stepify(d, Node3DEditor::get_singleton()->get_translate_snap());
}
- if (d <= 0) // Equal is here for negative zero.
+ if (d <= 0) { // Equal is here for negative zero.
d = 0;
+ }
light->set_param(Light3D::PARAM_RANGE, d);
} else if (Object::cast_to<OmniLight3D>(light)) {
@@ -1429,8 +1449,9 @@ void MeshInstance3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
Ref<Mesh> m = mesh->get_mesh();
- if (!m.is_valid())
+ if (!m.is_valid()) {
return; //none
+ }
Ref<TriangleMesh> tm = m->generate_triangle_mesh();
if (tm.is_valid()) {
@@ -1591,8 +1612,9 @@ void Skeleton3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
for (int j = 0; j < 3; j++) {
float dp = Math::abs(grests[parent].basis[j].normalized().dot(d));
- if (j == 0 || dp > closest_d)
+ if (j == 0 || dp > closest_d) {
closest = j;
+ }
}
//find closest other
@@ -1610,8 +1632,9 @@ void Skeleton3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
surface_tool->add_color(rootcolor);
surface_tool->add_vertex(v0 + grests[parent].basis[j].normalized() * dist * 0.05);
- if (j == closest)
+ if (j == closest) {
continue;
+ }
Vector3 axis;
if (first == Vector3()) {
@@ -1622,8 +1645,9 @@ void Skeleton3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
}
for (int k = 0; k < 2; k++) {
- if (k == 1)
+ if (k == 1) {
axis = -axis;
+ }
Vector3 point = v0 + d * dist * 0.2;
point += axis * dist * 0.1;
@@ -1747,20 +1771,24 @@ void PhysicalBone3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
PhysicalBone3D *physical_bone = Object::cast_to<PhysicalBone3D>(p_gizmo->get_spatial_node());
- if (!physical_bone)
+ if (!physical_bone) {
return;
+ }
Skeleton3D *sk(physical_bone->find_skeleton_parent());
- if (!sk)
+ if (!sk) {
return;
+ }
PhysicalBone3D *pb(sk->get_physical_bone(physical_bone->get_bone_id()));
- if (!pb)
+ if (!pb) {
return;
+ }
PhysicalBone3D *pbp(sk->get_physical_bone_parent(physical_bone->get_bone_id()));
- if (!pbp)
+ if (!pbp) {
return;
+ }
Vector<Vector3> points;
@@ -2160,8 +2188,9 @@ void VisibilityNotifier3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int
d = Math::stepify(d, Node3DEditor::get_singleton()->get_translate_snap());
}
- if (d < 0.001)
+ if (d < 0.001) {
d = 0.001;
+ }
//resize
aabb.position[p_idx] = (aabb.position[p_idx] + aabb.size[p_idx] * 0.5) - d;
aabb.size[p_idx] = d * 2;
@@ -2350,8 +2379,9 @@ void GPUParticles3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx
d = Math::stepify(d, Node3DEditor::get_singleton()->get_translate_snap());
}
- if (d < 0.001)
+ if (d < 0.001) {
d = 0.001;
+ }
//resize
aabb.position[p_idx] = (aabb.position[p_idx] + aabb.size[p_idx] * 0.5) - d;
aabb.size[p_idx] = d * 2;
@@ -2499,8 +2529,9 @@ void ReflectionProbeGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_id
d = Math::stepify(d, Node3DEditor::get_singleton()->get_translate_snap());
}
- if (d < 0.001)
+ if (d < 0.001) {
d = 0.001;
+ }
extents[p_idx] = d;
probe->set_extents(extents);
@@ -2676,8 +2707,9 @@ void DecalGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camera3
d = Math::stepify(d, Node3DEditor::get_singleton()->get_translate_snap());
}
- if (d < 0.001)
+ if (d < 0.001) {
d = 0.001;
+ }
extents[p_idx] = d;
decal->set_extents(extents);
@@ -2816,8 +2848,9 @@ void GIProbeGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camer
d = Math::stepify(d, Node3DEditor::get_singleton()->get_translate_snap());
}
- if (d < 0.001)
+ if (d < 0.001) {
d = 0.001;
+ }
extents[p_idx] = d;
probe->set_extents(extents);
@@ -3239,8 +3272,9 @@ String CollisionShape3DGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_g
const CollisionShape3D *cs = Object::cast_to<CollisionShape3D>(p_gizmo->get_spatial_node());
Ref<Shape3D> s = cs->get_shape();
- if (s.is_null())
+ if (s.is_null()) {
return "";
+ }
if (Object::cast_to<SphereShape3D>(*s)) {
return "Radius";
@@ -3269,8 +3303,9 @@ Variant CollisionShape3DGizmoPlugin::get_handle_value(EditorNode3DGizmo *p_gizmo
CollisionShape3D *cs = Object::cast_to<CollisionShape3D>(p_gizmo->get_spatial_node());
Ref<Shape3D> s = cs->get_shape();
- if (s.is_null())
+ if (s.is_null()) {
return Variant();
+ }
if (Object::cast_to<SphereShape3D>(*s)) {
Ref<SphereShape3D> ss = s;
@@ -3304,8 +3339,9 @@ void CollisionShape3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_i
CollisionShape3D *cs = Object::cast_to<CollisionShape3D>(p_gizmo->get_spatial_node());
Ref<Shape3D> s = cs->get_shape();
- if (s.is_null())
+ if (s.is_null()) {
return;
+ }
Transform gt = cs->get_global_transform();
Transform gi = gt.affine_inverse();
@@ -3324,8 +3360,9 @@ void CollisionShape3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_i
d = Math::stepify(d, Node3DEditor::get_singleton()->get_translate_snap());
}
- if (d < 0.001)
+ if (d < 0.001) {
d = 0.001;
+ }
ss->set_radius(d);
}
@@ -3339,8 +3376,9 @@ void CollisionShape3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_i
d = Math::stepify(d, Node3DEditor::get_singleton()->get_translate_snap());
}
- if (d < 0.001)
+ if (d < 0.001) {
d = 0.001;
+ }
rs->set_length(d);
}
@@ -3356,8 +3394,9 @@ void CollisionShape3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_i
d = Math::stepify(d, Node3DEditor::get_singleton()->get_translate_snap());
}
- if (d < 0.001)
+ if (d < 0.001) {
d = 0.001;
+ }
Vector3 he = bs->get_extents();
he[p_idx] = d;
@@ -3371,20 +3410,23 @@ void CollisionShape3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_i
Vector3 ra, rb;
Geometry::get_closest_points_between_segments(Vector3(), axis * 4096, sg[0], sg[1], ra, rb);
float d = axis.dot(ra);
- if (p_idx == 1)
+ if (p_idx == 1) {
d -= cs2->get_radius();
+ }
if (Node3DEditor::get_singleton()->is_snap_enabled()) {
d = Math::stepify(d, Node3DEditor::get_singleton()->get_translate_snap());
}
- if (d < 0.001)
+ if (d < 0.001) {
d = 0.001;
+ }
- if (p_idx == 0)
+ if (p_idx == 0) {
cs2->set_radius(d);
- else if (p_idx == 1)
+ } else if (p_idx == 1) {
cs2->set_height(d * 2.0);
+ }
}
if (Object::cast_to<CylinderShape3D>(*s)) {
@@ -3398,13 +3440,15 @@ void CollisionShape3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_i
d = Math::stepify(d, Node3DEditor::get_singleton()->get_translate_snap());
}
- if (d < 0.001)
+ if (d < 0.001) {
d = 0.001;
+ }
- if (p_idx == 0)
+ if (p_idx == 0) {
cs2->set_radius(d);
- else if (p_idx == 1)
+ } else if (p_idx == 1) {
cs2->set_height(d * 2.0);
+ }
}
}
@@ -3412,8 +3456,9 @@ void CollisionShape3DGizmoPlugin::commit_handle(EditorNode3DGizmo *p_gizmo, int
CollisionShape3D *cs = Object::cast_to<CollisionShape3D>(p_gizmo->get_spatial_node());
Ref<Shape3D> s = cs->get_shape();
- if (s.is_null())
+ if (s.is_null()) {
return;
+ }
if (Object::cast_to<SphereShape3D>(*s)) {
Ref<SphereShape3D> ss = s;
@@ -3446,10 +3491,11 @@ void CollisionShape3DGizmoPlugin::commit_handle(EditorNode3DGizmo *p_gizmo, int
if (Object::cast_to<CapsuleShape3D>(*s)) {
Ref<CapsuleShape3D> ss = s;
if (p_cancel) {
- if (p_idx == 0)
+ if (p_idx == 0) {
ss->set_radius(p_restore);
- else
+ } else {
ss->set_height(p_restore);
+ }
return;
}
@@ -3470,10 +3516,11 @@ void CollisionShape3DGizmoPlugin::commit_handle(EditorNode3DGizmo *p_gizmo, int
if (Object::cast_to<CylinderShape3D>(*s)) {
Ref<CylinderShape3D> ss = s;
if (p_cancel) {
- if (p_idx == 0)
+ if (p_idx == 0) {
ss->set_radius(p_restore);
- else
+ } else {
ss->set_height(p_restore);
+ }
return;
}
@@ -3516,8 +3563,9 @@ void CollisionShape3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
p_gizmo->clear();
Ref<Shape3D> s = cs->get_shape();
- if (s.is_null())
+ if (s.is_null()) {
return;
+ }
const Ref<Material> material =
get_material(!cs->is_disabled() ? "shape_material" : "shape_material_disabled", p_gizmo);
@@ -3877,8 +3925,9 @@ void NavigationRegion3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
p_gizmo->clear();
Ref<NavigationMesh> navmeshie = navmesh->get_navigation_mesh();
- if (navmeshie.is_null())
+ if (navmeshie.is_null()) {
return;
+ }
Vector<Vector3> vertices = navmeshie->get_vertices();
const Vector3 *vr = vertices.ptr();
@@ -3896,8 +3945,9 @@ void NavigationRegion3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
}
}
- if (faces.empty())
+ if (faces.empty()) {
return;
+ }
Map<_EdgeKey, bool> edge_map;
Vector<Vector3> tmeshfaces;
@@ -3915,8 +3965,9 @@ void NavigationRegion3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
_EdgeKey ek;
ek.from = f.vertex[j].snapped(Vector3(CMP_EPSILON, CMP_EPSILON, CMP_EPSILON));
ek.to = f.vertex[(j + 1) % 3].snapped(Vector3(CMP_EPSILON, CMP_EPSILON, CMP_EPSILON));
- if (ek.from < ek.to)
+ if (ek.from < ek.to) {
SWAP(ek.from, ek.to);
+ }
Map<_EdgeKey, bool>::Element *F = edge_map.find(ek);
@@ -3941,8 +3992,9 @@ void NavigationRegion3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
Ref<TriangleMesh> tmesh = memnew(TriangleMesh);
tmesh->create(tmeshfaces);
- if (lines.size())
+ if (lines.size()) {
p_gizmo->add_lines(lines, navmesh->is_enabled() ? edge_material : edge_material_disabled);
+ }
p_gizmo->add_collision_triangles(tmesh);
Ref<ArrayMesh> m = memnew(ArrayMesh);
Array a;
@@ -4446,7 +4498,7 @@ void Joint3DGizmoPlugin::CreateSliderJointGizmo(const Transform &p_offset, const
r_points.push_back(p_offset.translated(Vector3(-cs * 2, 0, 0)).origin);
}
- if (r_body_a_points)
+ if (r_body_a_points) {
JointGizmosDrawer::draw_circle(
Vector3::AXIS_X,
BODY_A_RADIUS,
@@ -4455,8 +4507,9 @@ void Joint3DGizmoPlugin::CreateSliderJointGizmo(const Transform &p_offset, const
p_angular_limit_lower,
p_angular_limit_upper,
*r_body_a_points);
+ }
- if (r_body_b_points)
+ if (r_body_b_points) {
JointGizmosDrawer::draw_circle(
Vector3::AXIS_X,
BODY_B_RADIUS,
@@ -4466,24 +4519,27 @@ void Joint3DGizmoPlugin::CreateSliderJointGizmo(const Transform &p_offset, const
p_angular_limit_upper,
*r_body_b_points,
true);
+ }
}
void Joint3DGizmoPlugin::CreateConeTwistJointGizmo(const Transform &p_offset, const Transform &p_trs_joint, const Transform &p_trs_body_a, const Transform &p_trs_body_b, real_t p_swing, real_t p_twist, Vector<Vector3> *r_body_a_points, Vector<Vector3> *r_body_b_points) {
- if (r_body_a_points)
+ if (r_body_a_points) {
JointGizmosDrawer::draw_cone(
p_offset,
JointGizmosDrawer::look_body(p_trs_joint, p_trs_body_a),
p_swing,
p_twist,
*r_body_a_points);
+ }
- if (r_body_b_points)
+ if (r_body_b_points) {
JointGizmosDrawer::draw_cone(
p_offset,
JointGizmosDrawer::look_body(p_trs_joint, p_trs_body_b),
p_swing,
p_twist,
*r_body_b_points);
+ }
}
void Joint3DGizmoPlugin::CreateGeneric6DOFJointGizmo(
@@ -4603,7 +4659,7 @@ void Joint3DGizmoPlugin::CreateGeneric6DOFJointGizmo(
ul = -1;
}
- if (r_body_a_points)
+ if (r_body_a_points) {
JointGizmosDrawer::draw_circle(
static_cast<Vector3::Axis>(ax),
BODY_A_RADIUS,
@@ -4613,8 +4669,9 @@ void Joint3DGizmoPlugin::CreateGeneric6DOFJointGizmo(
ul,
*r_body_a_points,
true);
+ }
- if (r_body_b_points)
+ if (r_body_b_points) {
JointGizmosDrawer::draw_circle(
static_cast<Vector3::Axis>(ax),
BODY_B_RADIUS,
@@ -4623,6 +4680,7 @@ void Joint3DGizmoPlugin::CreateGeneric6DOFJointGizmo(
ll,
ul,
*r_body_b_points);
+ }
}
#undef ADD_VTX
diff --git a/editor/node_dock.cpp b/editor/node_dock.cpp
index aa3ebe5ce7..9b9cfad9eb 100644
--- a/editor/node_dock.cpp
+++ b/editor/node_dock.cpp
@@ -68,10 +68,11 @@ void NodeDock::set_node(Node *p_node) {
groups->set_current(p_node);
if (p_node) {
- if (connections_button->is_pressed())
+ if (connections_button->is_pressed()) {
connections->show();
- else
+ } else {
groups->show();
+ }
mode_hb->show();
select_a_node->hide();
diff --git a/editor/pane_drag.cpp b/editor/pane_drag.cpp
index 8cadc3925e..09f2b90b90 100644
--- a/editor/pane_drag.cpp
+++ b/editor/pane_drag.cpp
@@ -41,8 +41,9 @@ void PaneDrag::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_DRAW: {
Ref<Texture2D> icon = mouse_over ? get_theme_icon("PaneDragHover", "EditorIcons") : get_theme_icon("PaneDrag", "EditorIcons");
- if (!icon.is_null())
+ if (!icon.is_null()) {
icon->draw(get_canvas_item(), Point2(0, 0));
+ }
} break;
case NOTIFICATION_MOUSE_ENTER:
@@ -58,8 +59,9 @@ void PaneDrag::_notification(int p_what) {
Size2 PaneDrag::get_minimum_size() const {
Ref<Texture2D> icon = get_theme_icon("PaneDrag", "EditorIcons");
- if (!icon.is_null())
+ if (!icon.is_null()) {
return icon->get_size();
+ }
return Size2();
}
diff --git a/editor/plugin_config_dialog.cpp b/editor/plugin_config_dialog.cpp
index ac8f4a1ad5..3ad6938498 100644
--- a/editor/plugin_config_dialog.cpp
+++ b/editor/plugin_config_dialog.cpp
@@ -56,8 +56,9 @@ void PluginConfigDialog::_on_confirmed() {
if (!_edit_mode) {
DirAccess *d = DirAccess::create(DirAccess::ACCESS_RESOURCES);
- if (!d || d->make_dir_recursive(path) != OK)
+ if (!d || d->make_dir_recursive(path) != OK) {
return;
+ }
}
Ref<ConfigFile> cf = memnew(ConfigFile);
diff --git a/editor/plugins/abstract_polygon_2d_editor.cpp b/editor/plugins/abstract_polygon_2d_editor.cpp
index d3e4c20e50..1abba45f9e 100644
--- a/editor/plugins/abstract_polygon_2d_editor.cpp
+++ b/editor/plugins/abstract_polygon_2d_editor.cpp
@@ -47,16 +47,18 @@ bool AbstractPolygon2DEditor::Vertex::valid() const {
}
bool AbstractPolygon2DEditor::_is_empty() const {
- if (!_get_node())
+ if (!_get_node()) {
return true;
+ }
const int n = _get_polygon_count();
for (int i = 0; i < n; i++) {
Vector<Vector2> vertices = _get_polygon(i);
- if (vertices.size() != 0)
+ if (vertices.size() != 0) {
return false;
+ }
}
return true;
@@ -185,8 +187,9 @@ void AbstractPolygon2DEditor::_wip_cancel() {
}
void AbstractPolygon2DEditor::_wip_close() {
- if (!wip_active)
+ if (!wip_active) {
return;
+ }
if (_is_line()) {
_set_polygon(0, wip);
@@ -234,8 +237,9 @@ void AbstractPolygon2DEditor::disable_polygon_editing(bool p_disable, String p_r
}
bool AbstractPolygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
- if (!_get_node() || !_polygon_editing_enabled)
+ if (!_get_node() || !_polygon_editing_enabled) {
return false;
+ }
Ref<InputEventMouseButton> mb = p_event;
@@ -248,8 +252,9 @@ bool AbstractPolygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event)
}
CanvasItemEditor::Tool tool = CanvasItemEditor::get_singleton()->get_current_tool();
- if (tool != CanvasItemEditor::TOOL_SELECT)
+ if (tool != CanvasItemEditor::TOOL_SELECT) {
return false;
+ }
if (mb.is_valid()) {
Transform2D xform = canvas_item_editor->get_canvas_transform() * _get_node()->get_global_transform();
@@ -260,8 +265,9 @@ bool AbstractPolygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event)
if (mode == MODE_EDIT || (_is_line() && mode == MODE_CREATE)) {
if (mb->get_button_index() == BUTTON_LEFT) {
if (mb->is_pressed()) {
- if (mb->get_control() || mb->get_shift() || mb->get_alt())
+ if (mb->get_control() || mb->get_shift() || mb->get_alt()) {
return false;
+ }
const PosVertex insert = closest_edge_point(gpoint);
@@ -464,8 +470,9 @@ bool AbstractPolygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event)
}
void AbstractPolygon2DEditor::forward_canvas_draw_over_viewport(Control *p_overlay) {
- if (!_get_node())
+ if (!_get_node()) {
return;
+ }
Transform2D xform = canvas_item_editor->get_canvas_transform() * _get_node()->get_global_transform();
// All polygon points are sharp, so use the sharp handle icon
@@ -476,8 +483,9 @@ void AbstractPolygon2DEditor::forward_canvas_draw_over_viewport(Control *p_overl
const bool is_closed = !_is_line();
for (int j = -1; j < n_polygons; j++) {
- if (wip_active && wip_destructive && j != -1)
+ if (wip_active && wip_destructive && j != -1) {
continue;
+ }
Vector<Vector2> points;
Vector2 offset;
@@ -486,8 +494,9 @@ void AbstractPolygon2DEditor::forward_canvas_draw_over_viewport(Control *p_overl
points = Variant(wip);
offset = Vector2(0, 0);
} else {
- if (j == -1)
+ if (j == -1) {
continue;
+ }
points = _get_polygon(j);
offset = _get_offset(j);
}
@@ -519,10 +528,11 @@ void AbstractPolygon2DEditor::forward_canvas_draw_over_viewport(Control *p_overl
if (is_closed || i < n_points - 1) {
Vector2 p2;
if (j == edited_point.polygon &&
- ((wip_active && i == n_points - 1) || (((i + 1) % n_points) == edited_point.vertex)))
+ ((wip_active && i == n_points - 1) || (((i + 1) % n_points) == edited_point.vertex))) {
p2 = edited_point.pos;
- else
+ } else {
p2 = points[(i + 1) % n_points] + offset;
+ }
const Vector2 next_point = xform.xform(p2);
p_overlay->draw_line(point, next_point, col, Math::round(2 * EDSCALE));
@@ -554,17 +564,19 @@ void AbstractPolygon2DEditor::forward_canvas_draw_over_viewport(Control *p_overl
}
void AbstractPolygon2DEditor::edit(Node *p_polygon) {
- if (!canvas_item_editor)
+ if (!canvas_item_editor) {
canvas_item_editor = CanvasItemEditor::get_singleton();
+ }
if (p_polygon) {
_set_node(p_polygon);
// Enable the pencil tool if the polygon is empty.
- if (_is_empty())
+ if (_is_empty()) {
_menu_option(MODE_CREATE);
- else
+ } else {
_menu_option(MODE_EDIT);
+ }
wip.clear();
wip_active = false;
@@ -596,12 +608,14 @@ void AbstractPolygon2DEditor::remove_point(const Vertex &p_vertex) {
_commit_action();
}
- if (_is_empty())
+ if (_is_empty()) {
_menu_option(MODE_CREATE);
+ }
hover_point = Vertex();
- if (selected_point == p_vertex)
+ if (selected_point == p_vertex) {
selected_point = Vertex();
+ }
}
AbstractPolygon2DEditor::Vertex AbstractPolygon2DEditor::get_active_point() const {
@@ -659,8 +673,9 @@ AbstractPolygon2DEditor::PosVertex AbstractPolygon2DEditor::closest_edge_point(c
Vector2 cp = Geometry::get_closest_point_to_segment_2d(p_pos, segment);
- if (cp.distance_squared_to(segment[0]) < eps2 || cp.distance_squared_to(segment[1]) < eps2)
+ if (cp.distance_squared_to(segment[0]) < eps2 || cp.distance_squared_to(segment[1]) < eps2) {
continue; //not valid to reuse point
+ }
real_t d = cp.distance_to(p_pos);
if (d < closest_dist && d < grab_threshold) {
diff --git a/editor/plugins/animation_blend_space_1d_editor.cpp b/editor/plugins/animation_blend_space_1d_editor.cpp
index 64e5df084b..75eacf56ec 100644
--- a/editor/plugins/animation_blend_space_1d_editor.cpp
+++ b/editor/plugins/animation_blend_space_1d_editor.cpp
@@ -81,8 +81,9 @@ void AnimationNodeBlendSpace1DEditor::_blend_space_gui_input(const Ref<InputEven
for (List<StringName>::Element *E = classes.front(); E; E = E->next()) {
String name = String(E->get()).replace_first("AnimationNode", "");
- if (name == "Animation")
+ if (name == "Animation") {
continue;
+ }
int idx = menu->get_item_count();
menu->add_item(vformat("Add %s", name), idx);
@@ -300,8 +301,9 @@ void AnimationNodeBlendSpace1DEditor::_blend_space_draw() {
}
void AnimationNodeBlendSpace1DEditor::_update_space() {
- if (updating)
+ if (updating) {
return;
+ }
updating = true;
@@ -318,8 +320,9 @@ void AnimationNodeBlendSpace1DEditor::_update_space() {
}
void AnimationNodeBlendSpace1DEditor::_config_changed(double) {
- if (updating)
+ if (updating) {
return;
+ }
updating = true;
undo_redo->create_action(TTR("Change BlendSpace1D Limits"));
@@ -338,8 +341,9 @@ void AnimationNodeBlendSpace1DEditor::_config_changed(double) {
}
void AnimationNodeBlendSpace1DEditor::_labels_changed(String) {
- if (updating)
+ if (updating) {
return;
+ }
updating = true;
undo_redo->create_action(TTR("Change BlendSpace1D Labels"), UndoRedo::MERGE_ENDS);
@@ -438,8 +442,9 @@ void AnimationNodeBlendSpace1DEditor::_tool_switch(int p_tool) {
}
void AnimationNodeBlendSpace1DEditor::_update_edited_point_pos() {
- if (updating)
+ if (updating) {
return;
+ }
if (selected_point >= 0 && selected_point < blend_space->get_blend_point_count()) {
float pos = blend_space->get_blend_point_position(selected_point);
@@ -495,8 +500,9 @@ void AnimationNodeBlendSpace1DEditor::_erase_selected() {
}
void AnimationNodeBlendSpace1DEditor::_edit_point_pos(double) {
- if (updating)
+ if (updating) {
return;
+ }
updating = true;
undo_redo->create_action(TTR("Move BlendSpace1D Node Point"));
diff --git a/editor/plugins/animation_blend_space_2d_editor.cpp b/editor/plugins/animation_blend_space_2d_editor.cpp
index a308b5dddb..df67482dfb 100644
--- a/editor/plugins/animation_blend_space_2d_editor.cpp
+++ b/editor/plugins/animation_blend_space_2d_editor.cpp
@@ -105,8 +105,9 @@ void AnimationNodeBlendSpace2DEditor::_blend_space_gui_input(const Ref<InputEven
for (List<StringName>::Element *E = classes.front(); E; E = E->next()) {
String name = String(E->get()).replace_first("AnimationNode", "");
- if (name == "Animation")
+ if (name == "Animation") {
continue; // nope
+ }
int idx = menu->get_item_count();
menu->add_item(vformat("Add %s", name), idx);
menu->set_item_metadata(idx, E->get());
@@ -179,8 +180,9 @@ void AnimationNodeBlendSpace2DEditor::_blend_space_gui_input(const Ref<InputEven
selected_point = -1;
for (int i = 0; i < points.size(); i++) {
- if (making_triangle.find(i) != -1)
+ if (making_triangle.find(i) != -1) {
continue;
+ }
if (points[i].distance_to(mb->get_position()) < 10 * EDSCALE) {
making_triangle.push_back(i);
@@ -578,8 +580,9 @@ void AnimationNodeBlendSpace2DEditor::_snap_toggled() {
}
void AnimationNodeBlendSpace2DEditor::_update_space() {
- if (updating)
+ if (updating) {
return;
+ }
updating = true;
@@ -611,8 +614,9 @@ void AnimationNodeBlendSpace2DEditor::_update_space() {
}
void AnimationNodeBlendSpace2DEditor::_config_changed(double) {
- if (updating)
+ if (updating) {
return;
+ }
updating = true;
undo_redo->create_action(TTR("Change BlendSpace2D Limits"));
@@ -633,8 +637,9 @@ void AnimationNodeBlendSpace2DEditor::_config_changed(double) {
}
void AnimationNodeBlendSpace2DEditor::_labels_changed(String) {
- if (updating)
+ if (updating) {
return;
+ }
updating = true;
undo_redo->create_action(TTR("Change BlendSpace2D Labels"), UndoRedo::MERGE_ENDS);
@@ -687,8 +692,9 @@ void AnimationNodeBlendSpace2DEditor::_erase_selected() {
}
void AnimationNodeBlendSpace2DEditor::_update_edited_point_pos() {
- if (updating)
+ if (updating) {
return;
+ }
if (selected_point >= 0 && selected_point < blend_space->get_blend_point_count()) {
Vector2 pos = blend_space->get_blend_point_position(selected_point);
@@ -707,8 +713,9 @@ void AnimationNodeBlendSpace2DEditor::_update_edited_point_pos() {
}
void AnimationNodeBlendSpace2DEditor::_edit_point_pos(double) {
- if (updating)
+ if (updating) {
return;
+ }
updating = true;
undo_redo->create_action(TTR("Move Node Point"));
undo_redo->add_do_method(blend_space.ptr(), "set_blend_point_position", selected_point, Vector2(edit_x->get_value(), edit_y->get_value()));
diff --git a/editor/plugins/animation_blend_tree_editor_plugin.cpp b/editor/plugins/animation_blend_tree_editor_plugin.cpp
index 3363e1b804..82d942821f 100644
--- a/editor/plugins/animation_blend_tree_editor_plugin.cpp
+++ b/editor/plugins/animation_blend_tree_editor_plugin.cpp
@@ -99,8 +99,9 @@ void AnimationNodeBlendTreeEditor::_property_changed(const StringName &p_propert
}
void AnimationNodeBlendTreeEditor::_update_graph() {
- if (updating)
+ if (updating) {
return;
+ }
visible_properties.clear();
@@ -415,8 +416,9 @@ void AnimationNodeBlendTreeEditor::_delete_nodes_request() {
}
}
- if (to_erase.empty())
+ if (to_erase.empty()) {
return;
+ }
undo_redo->create_action(TTR("Delete Node(s)"));
@@ -482,8 +484,9 @@ void AnimationNodeBlendTreeEditor::_filter_edited() {
}
bool AnimationNodeBlendTreeEditor::_update_filters(const Ref<AnimationNode> &anode) {
- if (updating || _filter_edit != anode)
+ if (updating || _filter_edit != anode) {
return false;
+ }
NodePath player_path = AnimationTreeEditor::get_singleton()->get_tree()->get_animation_player();
@@ -582,8 +585,9 @@ bool AnimationNodeBlendTreeEditor::_update_filters(const Ref<AnimationNode> &ano
if (base->has_node(accum)) {
node = base->get_node(accum);
}
- if (!node)
+ if (!node) {
continue; //no node, can't edit
+ }
if (path.get_subname_count()) {
String concat = path.get_concatenated_subnames();
@@ -670,8 +674,9 @@ void AnimationNodeBlendTreeEditor::_edit_filters(const String &p_which) {
ERR_FAIL_COND(!anode.is_valid());
_filter_edit = anode;
- if (!_update_filters(anode))
+ if (!_update_filters(anode)) {
return;
+ }
filter_dialog->popup_centered(Size2(500, 500) * EDSCALE);
}
@@ -687,8 +692,9 @@ void AnimationNodeBlendTreeEditor::_notification(int p_what) {
error_panel->add_theme_style_override("panel", get_theme_stylebox("bg", "Tree"));
error_label->add_theme_color_override("font_color", get_theme_color("error_color", "Editor"));
- if (p_what == NOTIFICATION_THEME_CHANGED && is_visible_in_tree())
+ if (p_what == NOTIFICATION_THEME_CHANGED && is_visible_in_tree()) {
_update_graph();
+ }
}
if (p_what == NOTIFICATION_PROCESS) {
@@ -754,8 +760,9 @@ void AnimationNodeBlendTreeEditor::_notification(int p_what) {
}
void AnimationNodeBlendTreeEditor::_scroll_changed(const Vector2 &p_scroll) {
- if (updating)
+ if (updating) {
return;
+ }
updating = true;
blend_tree->set_graph_offset(p_scroll / EDSCALE);
updating = false;
diff --git a/editor/plugins/animation_player_editor_plugin.cpp b/editor/plugins/animation_player_editor_plugin.cpp
index 28d0e113d4..1e0a9535e2 100644
--- a/editor/plugins/animation_player_editor_plugin.cpp
+++ b/editor/plugins/animation_player_editor_plugin.cpp
@@ -59,8 +59,9 @@ void AnimationPlayerEditor::_node_removed(Node *p_node) {
void AnimationPlayerEditor::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_PROCESS: {
- if (!player)
+ if (!player) {
return;
+ }
updating = true;
@@ -139,8 +140,9 @@ void AnimationPlayerEditor::_notification(int p_what) {
}
void AnimationPlayerEditor::_autoplay_pressed() {
- if (updating)
+ if (updating) {
return;
+ }
if (animation->get_item_count() == 0) {
return;
}
@@ -173,8 +175,9 @@ void AnimationPlayerEditor::_play_pressed() {
}
if (current != "") {
- if (current == player->get_assigned_animation())
+ if (current == player->get_assigned_animation()) {
player->stop(); //so it won't blend with itself
+ }
player->play(current);
}
@@ -210,8 +213,9 @@ void AnimationPlayerEditor::_play_bw_pressed() {
}
if (current != "") {
- if (current == player->get_assigned_animation())
+ if (current == player->get_assigned_animation()) {
player->stop(); //so it won't blend with itself
+ }
player->play(current, -1, -1, true);
}
@@ -227,8 +231,9 @@ void AnimationPlayerEditor::_play_bw_from_pressed() {
if (current != "") {
float time = player->get_current_animation_position();
- if (current == player->get_assigned_animation())
+ if (current == player->get_assigned_animation()) {
player->stop(); //so it won't blend with itself
+ }
player->play(current, -1, -1, true);
player->seek(time);
@@ -249,8 +254,9 @@ void AnimationPlayerEditor::_stop_pressed() {
}
void AnimationPlayerEditor::_animation_selected(int p_which) {
- if (updating)
+ if (updating) {
return;
+ }
// when selecting an animation, the idea is that the only interesting behavior
// ui-wise is that it should play/blend the next one if currently playing
String current;
@@ -291,8 +297,9 @@ void AnimationPlayerEditor::_animation_new() {
String base = TTR("New Anim");
while (true) {
String attempt = base;
- if (count > 1)
+ if (count > 1) {
attempt += " (" + itos(count) + ")";
+ }
if (player->has_animation(attempt)) {
count++;
continue;
@@ -308,8 +315,9 @@ void AnimationPlayerEditor::_animation_new() {
}
void AnimationPlayerEditor::_animation_rename() {
- if (animation->get_item_count() == 0)
+ if (animation->get_item_count() == 0) {
return;
+ }
int selected = animation->get_selected();
String selected_name = animation->get_item_text(selected);
@@ -338,8 +346,9 @@ void AnimationPlayerEditor::_animation_load() {
void AnimationPlayerEditor::_animation_save_in_path(const Ref<Resource> &p_resource, const String &p_path) {
int flg = 0;
- if (EditorSettings::get_singleton()->get("filesystem/on_save/compress_binary_resources"))
+ if (EditorSettings::get_singleton()->get("filesystem/on_save/compress_binary_resources")) {
flg |= ResourceSaver::FLAG_COMPRESS;
+ }
String path = ProjectSettings::get_singleton()->localize_path(p_path);
Error err = ResourceSaver::save(path, p_resource, flg | ResourceSaver::FLAG_REPLACE_SUBRESOURCE_PATHS);
@@ -397,8 +406,9 @@ void AnimationPlayerEditor::_animation_save_as(const Ref<Resource> &p_resource)
}
void AnimationPlayerEditor::_animation_remove() {
- if (animation->get_item_count() == 0)
+ if (animation->get_item_count() == 0) {
return;
+ }
String current = animation->get_item_text(animation->get_selected());
@@ -516,8 +526,9 @@ void AnimationPlayerEditor::_animation_name_edited() {
}
void AnimationPlayerEditor::_blend_editor_next_changed(const int p_idx) {
- if (animation->get_item_count() == 0)
+ if (animation->get_item_count() == 0) {
return;
+ }
String current = animation->get_item_text(animation->get_selected());
@@ -530,13 +541,15 @@ void AnimationPlayerEditor::_blend_editor_next_changed(const int p_idx) {
}
void AnimationPlayerEditor::_animation_blend() {
- if (updating_blends)
+ if (updating_blends) {
return;
+ }
blend_editor.tree->clear();
- if (animation->get_item_count() == 0)
+ if (animation->get_item_count() == 0) {
return;
+ }
String current = animation->get_item_text(animation->get_selected());
@@ -584,17 +597,20 @@ void AnimationPlayerEditor::_animation_blend() {
}
void AnimationPlayerEditor::_blend_edited() {
- if (updating_blends)
+ if (updating_blends) {
return;
+ }
- if (animation->get_item_count() == 0)
+ if (animation->get_item_count() == 0) {
return;
+ }
String current = animation->get_item_text(animation->get_selected());
TreeItem *selected = blend_editor.tree->get_edited();
- if (!selected)
+ if (!selected) {
return;
+ }
updating_blends = true;
String to = selected->get_text(0);
@@ -611,8 +627,9 @@ void AnimationPlayerEditor::_blend_edited() {
}
void AnimationPlayerEditor::ensure_visibility() {
- if (player && pin->is_pressed())
+ if (player && pin->is_pressed()) {
return; // another player is pinned, don't reset
+ }
_animation_edit();
}
@@ -701,8 +718,9 @@ void AnimationPlayerEditor::_dialog_action(String p_file) {
p_file = p_file.substr(p_file.find_last("\\") + 1, p_file.length());
}
- if (p_file.find(".") != -1)
+ if (p_file.find(".") != -1) {
p_file = p_file.substr(0, p_file.find("."));
+ }
undo_redo->create_action(TTR("Load Animation"));
undo_redo->add_do_method(player, "add_animation", p_file, res);
@@ -765,8 +783,9 @@ void AnimationPlayerEditor::_update_animation() {
void AnimationPlayerEditor::_update_player() {
updating = true;
List<StringName> animlist;
- if (player)
+ if (player) {
player->get_animation_list(&animlist);
+ }
animation->clear();
@@ -801,13 +820,15 @@ void AnimationPlayerEditor::_update_player() {
int active_idx = -1;
for (List<StringName>::Element *E = animlist.front(); E; E = E->next()) {
- if (player->get_autoplay() == E->get())
+ if (player->get_autoplay() == E->get()) {
animation->add_icon_item(autoplay_icon, E->get());
- else
+ } else {
animation->add_item(E->get());
+ }
- if (player->get_assigned_animation() == E->get())
+ if (player->get_assigned_animation() == E->get()) {
active_idx = animation->get_item_count() - 1;
+ }
}
updating = false;
@@ -838,36 +859,41 @@ void AnimationPlayerEditor::_update_player() {
}
void AnimationPlayerEditor::edit(AnimationPlayer *p_player) {
- if (player && pin->is_pressed())
+ if (player && pin->is_pressed()) {
return; // Ignore, pinned.
+ }
player = p_player;
if (player) {
_update_player();
if (onion.enabled) {
- if (animation->get_item_count() > 0)
+ if (animation->get_item_count() > 0) {
_start_onion_skinning();
- else
+ } else {
_stop_onion_skinning();
+ }
}
track_editor->show_select_node_warning(false);
} else {
- if (onion.enabled)
+ if (onion.enabled) {
_stop_onion_skinning();
+ }
track_editor->show_select_node_warning(true);
}
}
void AnimationPlayerEditor::forward_canvas_force_draw_over_viewport(Control *p_overlay) {
- if (!onion.can_overlay)
+ if (!onion.can_overlay) {
return;
+ }
// Can happen on viewport resize, at least.
- if (!_are_onion_layers_valid())
+ if (!_are_onion_layers_valid()) {
return;
+ }
RID ci = p_overlay->get_canvas_item();
Rect2 src_rect = p_overlay->get_global_rect();
@@ -910,13 +936,15 @@ void AnimationPlayerEditor::forward_canvas_force_draw_over_viewport(Control *p_o
}
void AnimationPlayerEditor::_animation_duplicate() {
- if (!animation->get_item_count())
+ if (!animation->get_item_count()) {
return;
+ }
String current = animation->get_item_text(animation->get_selected());
Ref<Animation> anim = player->get_animation(current);
- if (!anim.is_valid())
+ if (!anim.is_valid()) {
return;
+ }
Ref<Animation> new_anim = memnew(Animation);
List<PropertyInfo> plist;
@@ -989,14 +1017,16 @@ void AnimationPlayerEditor::_seek_value_changed(float p_value, bool p_set) {
void AnimationPlayerEditor::_animation_player_changed(Object *p_pl) {
if (player == p_pl && is_visible_in_tree()) {
_update_player();
- if (blend_editor.dialog->is_visible())
+ if (blend_editor.dialog->is_visible()) {
_animation_blend(); // Update.
+ }
}
}
void AnimationPlayerEditor::_list_changed() {
- if (is_visible_in_tree())
+ if (is_visible_in_tree()) {
_update_player();
+ }
}
void AnimationPlayerEditor::_animation_key_editor_anim_len_changed(float p_len) {
@@ -1006,17 +1036,21 @@ void AnimationPlayerEditor::_animation_key_editor_anim_len_changed(float p_len)
void AnimationPlayerEditor::_animation_key_editor_seek(float p_pos, bool p_drag) {
timeline_position = p_pos;
- if (!is_visible_in_tree())
+ if (!is_visible_in_tree()) {
return;
+ }
- if (!player)
+ if (!player) {
return;
+ }
- if (player->is_playing())
+ if (player->is_playing()) {
return;
+ }
- if (!player->has_animation(player->get_assigned_animation()))
+ if (!player->has_animation(player->get_assigned_animation())) {
return;
+ }
updating = true;
frame->set_value(Math::stepify(p_pos, _get_editor_step()));
@@ -1130,10 +1164,11 @@ void AnimationPlayerEditor::_onion_skinning_menu(int p_option) {
case ONION_SKINNING_ENABLE: {
onion.enabled = !onion.enabled;
- if (onion.enabled)
+ if (onion.enabled) {
_start_onion_skinning();
- else
+ } else {
_stop_onion_skinning();
+ }
} break;
case ONION_SKINNING_PAST: {
@@ -1175,19 +1210,21 @@ void AnimationPlayerEditor::_unhandled_key_input(const Ref<InputEvent> &p_ev) {
if (is_visible_in_tree() && k.is_valid() && k->is_pressed() && !k->is_echo() && !k->get_alt() && !k->get_control() && !k->get_metakey()) {
switch (k->get_keycode()) {
case KEY_A: {
- if (!k->get_shift())
+ if (!k->get_shift()) {
_play_bw_from_pressed();
- else
+ } else {
_play_bw_pressed();
+ }
} break;
case KEY_S: {
_stop_pressed();
} break;
case KEY_D: {
- if (!k->get_shift())
+ if (!k->get_shift()) {
_play_from_pressed();
- else
+ } else {
_play_pressed();
+ }
} break;
}
}
@@ -1247,8 +1284,9 @@ void AnimationPlayerEditor::_free_onion_layers() {
void AnimationPlayerEditor::_prepare_onion_layers_1() {
// This would be called per viewport and we want to act once only.
int64_t frame = get_tree()->get_frame();
- if (frame == onion.last_frame)
+ if (frame == onion.last_frame) {
return;
+ }
if (!onion.enabled || !is_processing() || !is_visible() || !get_player()) {
_stop_onion_skinning();
@@ -1261,8 +1299,9 @@ void AnimationPlayerEditor::_prepare_onion_layers_1() {
onion.can_overlay = false;
plugin->update_overlays();
- if (player->is_playing())
+ if (player->is_playing()) {
return;
+ }
// And go to next step afterwards.
call_deferred("_prepare_onion_layers_2");
@@ -1274,11 +1313,13 @@ void AnimationPlayerEditor::_prepare_onion_layers_1_deferred() {
void AnimationPlayerEditor::_prepare_onion_layers_2() {
Ref<Animation> anim = player->get_animation(player->get_assigned_animation());
- if (!anim.is_valid())
+ if (!anim.is_valid()) {
return;
+ }
- if (!_are_onion_layers_valid())
+ if (!_are_onion_layers_valid()) {
_allocate_onion_layers();
+ }
// Hide superfluous elements that would make the overlay unnecessary cluttered.
Dictionary canvas_edit_state;
@@ -1351,8 +1392,9 @@ void AnimationPlayerEditor::_prepare_onion_layers_2() {
for (int step_off = step_off_a; step_off <= step_off_b; step_off++) {
if (step_off == 0) {
// Skip present step and switch to the color of future.
- if (!onion.force_white_modulate)
+ if (!onion.force_white_modulate) {
onion.capture.material->set_shader_param("dir_color", EDITOR_GET("editors/animation/onion_layers_future_color"));
+ }
continue;
}
@@ -1702,8 +1744,9 @@ void AnimationPlayerEditorPlugin::_notification(int p_what) {
void AnimationPlayerEditorPlugin::edit(Object *p_object) {
anim_editor->set_undo_redo(&get_undo_redo());
- if (!p_object)
+ if (!p_object) {
return;
+ }
anim_editor->edit(Object::cast_to<AnimationPlayer>(p_object));
}
diff --git a/editor/plugins/animation_state_machine_editor.cpp b/editor/plugins/animation_state_machine_editor.cpp
index bcd393957c..652754a146 100644
--- a/editor/plugins/animation_state_machine_editor.cpp
+++ b/editor/plugins/animation_state_machine_editor.cpp
@@ -61,8 +61,9 @@ void AnimationNodeStateMachineEditor::edit(const Ref<AnimationNode> &p_node) {
void AnimationNodeStateMachineEditor::_state_machine_gui_input(const Ref<InputEvent> &p_event) {
Ref<AnimationNodeStateMachinePlayback> playback = AnimationTreeEditor::get_singleton()->get_tree()->get(AnimationTreeEditor::get_singleton()->get_base_path() + "playback");
- if (playback.is_null())
+ if (playback.is_null()) {
return;
+ }
Ref<InputEventKey> k = p_event;
if (tool_select->is_pressed() && k.is_valid() && k->is_pressed() && k->get_keycode() == KEY_DELETE && !k->is_echo()) {
@@ -101,8 +102,9 @@ void AnimationNodeStateMachineEditor::_state_machine_gui_input(const Ref<InputEv
for (List<StringName>::Element *E = classes.front(); E; E = E->next()) {
String name = String(E->get()).replace_first("AnimationNode", "");
- if (name == "Animation")
+ if (name == "Animation") {
continue; // nope
+ }
int idx = menu->get_item_count();
menu->add_item(vformat("Add %s", name), idx);
menu->set_item_metadata(idx, E->get());
@@ -317,8 +319,9 @@ void AnimationNodeStateMachineEditor::_state_machine_gui_input(const Ref<InputEv
float best_d_y = 1e20;
for (List<StringName>::Element *E = nodes.front(); E; E = E->next()) {
- if (E->get() == selected_node)
+ if (E->get() == selected_node) {
continue;
+ }
Vector2 npos = state_machine->get_node_position(E->get());
float d_x = ABS(npos.x - cpos.x);
@@ -520,8 +523,9 @@ void AnimationNodeStateMachineEditor::_connection_draw(const Vector2 &p_from, co
}
void AnimationNodeStateMachineEditor::_clip_src_line_to_rect(Vector2 &r_from, Vector2 &r_to, const Rect2 &p_rect) {
- if (r_to == r_from)
+ if (r_to == r_from) {
return;
+ }
//this could be optimized...
Vector2 n = (r_to - r_from).normalized();
@@ -531,8 +535,9 @@ void AnimationNodeStateMachineEditor::_clip_src_line_to_rect(Vector2 &r_from, Ve
}
void AnimationNodeStateMachineEditor::_clip_dst_line_to_rect(Vector2 &r_from, Vector2 &r_to, const Rect2 &p_rect) {
- if (r_to == r_from)
+ if (r_to == r_from) {
return;
+ }
//this could be optimized...
Vector2 n = (r_to - r_from).normalized();
@@ -811,8 +816,9 @@ void AnimationNodeStateMachineEditor::_state_machine_draw() {
void AnimationNodeStateMachineEditor::_state_machine_pos_draw() {
Ref<AnimationNodeStateMachinePlayback> playback = AnimationTreeEditor::get_singleton()->get_tree()->get(AnimationTreeEditor::get_singleton()->get_base_path() + "playback");
- if (!playback.is_valid() || !playback->is_playing())
+ if (!playback.is_valid() || !playback->is_playing()) {
return;
+ }
int idx = -1;
for (int i = 0; i < node_rects.size(); i++) {
@@ -822,8 +828,9 @@ void AnimationNodeStateMachineEditor::_state_machine_pos_draw() {
}
}
- if (idx == -1)
+ if (idx == -1) {
return;
+ }
const NodeRect &nr = node_rects[idx];
@@ -855,8 +862,9 @@ void AnimationNodeStateMachineEditor::_state_machine_pos_draw() {
}
void AnimationNodeStateMachineEditor::_update_graph() {
- if (updating)
+ if (updating) {
return;
+ }
updating = true;
@@ -1071,15 +1079,17 @@ void AnimationNodeStateMachineEditor::_name_edited(const String &p_text) {
}
void AnimationNodeStateMachineEditor::_name_edited_focus_out() {
- if (updating)
+ if (updating) {
return;
+ }
_name_edited(name_edit->get_text());
}
void AnimationNodeStateMachineEditor::_scroll_changed(double) {
- if (updating)
+ if (updating) {
return;
+ }
state_machine->set_graph_offset(Vector2(h_scroll->get_value(), v_scroll->get_value()));
state_machine_draw->update();
diff --git a/editor/plugins/animation_tree_editor_plugin.cpp b/editor/plugins/animation_tree_editor_plugin.cpp
index 2512dbdfb2..ec3e25f999 100644
--- a/editor/plugins/animation_tree_editor_plugin.cpp
+++ b/editor/plugins/animation_tree_editor_plugin.cpp
@@ -48,8 +48,9 @@
#include "scene/scene_string_names.h"
void AnimationTreeEditor::edit(AnimationTree *p_tree) {
- if (tree == p_tree)
+ if (tree == p_tree) {
return;
+ }
tree = p_tree;
@@ -204,13 +205,15 @@ Vector<String> AnimationTreeEditor::get_animation_list() {
}
AnimationTree *tree = singleton->tree;
- if (!tree || !tree->has_node(tree->get_animation_player()))
+ if (!tree || !tree->has_node(tree->get_animation_player())) {
return Vector<String>();
+ }
AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(tree->get_node(tree->get_animation_player()));
- if (!ap)
+ if (!ap) {
return Vector<String>();
+ }
List<StringName> anims;
ap->get_animation_list(&anims);
@@ -261,8 +264,9 @@ void AnimationTreeEditorPlugin::make_visible(bool p_visible) {
editor->make_bottom_panel_item_visible(anim_tree_editor);
anim_tree_editor->set_process(true);
} else {
- if (anim_tree_editor->is_visible_in_tree())
+ if (anim_tree_editor->is_visible_in_tree()) {
editor->hide_bottom_panel();
+ }
button->hide();
anim_tree_editor->set_process(false);
}
diff --git a/editor/plugins/asset_library_editor_plugin.cpp b/editor/plugins/asset_library_editor_plugin.cpp
index ad2164b719..da170cd498 100644
--- a/editor/plugins/asset_library_editor_plugin.cpp
+++ b/editor/plugins/asset_library_editor_plugin.cpp
@@ -374,8 +374,9 @@ void EditorAssetLibraryItemDownload::configure(const String &p_title, int p_asse
title->set_text(p_title);
icon->set_texture(p_preview);
asset_id = p_asset_id;
- if (!p_preview.is_valid())
+ if (!p_preview.is_valid()) {
icon->set_texture(get_theme_icon("FileBrokenBigThumb", "EditorIcons"));
+ }
host = p_download_url;
sha256 = p_sha256_hash;
_make_request();
@@ -597,8 +598,9 @@ void EditorAssetLibrary::_install_asset() {
for (int i = 0; i < downloads_hb->get_child_count(); i++) {
EditorAssetLibraryItemDownload *d = Object::cast_to<EditorAssetLibraryItemDownload>(downloads_hb->get_child(i));
if (d && d->get_asset_id() == description->get_asset_id()) {
- if (EditorNode::get_singleton() != nullptr)
+ if (EditorNode::get_singleton() != nullptr) {
EditorNode::get_singleton()->show_warning(TTR("Download for this asset is already in progress!"));
+ }
return;
}
}
@@ -643,8 +645,9 @@ void EditorAssetLibrary::_select_author(int p_id) {
void EditorAssetLibrary::_select_category(int p_id) {
for (int i = 0; i < categories->get_item_count(); i++) {
- if (i == 0)
+ if (i == 0) {
continue;
+ }
int id = categories->get_item_metadata(i);
if (id == p_id) {
categories->select(i);
@@ -914,16 +917,19 @@ void EditorAssetLibrary::_search_text_entered(const String &p_text) {
HBoxContainer *EditorAssetLibrary::_make_pages(int p_page, int p_page_count, int p_page_len, int p_total_items, int p_current_items) {
HBoxContainer *hbc = memnew(HBoxContainer);
- if (p_page_count < 2)
+ if (p_page_count < 2) {
return hbc;
+ }
//do the mario
int from = p_page - 5;
- if (from < 0)
+ if (from < 0) {
from = 0;
+ }
int to = from + 10;
- if (to > p_page_count)
+ if (to > p_page_count) {
to = p_page_count;
+ }
hbc->add_spacer();
hbc->add_theme_constant_override("separation", 5 * EDSCALE);
@@ -1072,8 +1078,9 @@ void EditorAssetLibrary::_http_request_completed(int p_status, int p_code, const
Array clist = d["categories"];
for (int i = 0; i < clist.size(); i++) {
Dictionary cat = clist[i];
- if (!cat.has("name") || !cat.has("id"))
+ if (!cat.has("name") || !cat.has("id")) {
continue;
+ }
String name = cat["name"];
int id = cat["id"];
categories->add_item(name);
@@ -1297,8 +1304,9 @@ EditorAssetLibrary::EditorAssetLibrary(bool p_templates_only) {
search->connect("pressed", callable_mp(this, &EditorAssetLibrary::_search), make_binds(0));
search_hb->add_child(search);
- if (!p_templates_only)
+ if (!p_templates_only) {
search_hb->add_child(memnew(VSeparator));
+ }
Button *open_asset = memnew(Button);
open_asset->set_text(TTR("Import..."));
diff --git a/editor/plugins/audio_stream_editor_plugin.cpp b/editor/plugins/audio_stream_editor_plugin.cpp
index 44238323ea..3b7a9320f0 100644
--- a/editor/plugins/audio_stream_editor_plugin.cpp
+++ b/editor/plugins/audio_stream_editor_plugin.cpp
@@ -97,8 +97,9 @@ void AudioStreamEditor::_preview_changed(ObjectID p_which) {
}
void AudioStreamEditor::_changed_callback(Object *p_changed, const char *p_prop) {
- if (!is_visible())
+ if (!is_visible()) {
return;
+ }
update();
}
@@ -170,8 +171,9 @@ void AudioStreamEditor::_seek_to(real_t p_x) {
}
void AudioStreamEditor::edit(Ref<AudioStream> p_stream) {
- if (!stream.is_null())
+ if (!stream.is_null()) {
stream->remove_change_receptor(this);
+ }
stream = p_stream;
_player->set_stream(stream);
@@ -242,8 +244,9 @@ AudioStreamEditor::AudioStreamEditor() {
void AudioStreamEditorPlugin::edit(Object *p_object) {
AudioStream *s = Object::cast_to<AudioStream>(p_object);
- if (!s)
+ if (!s) {
return;
+ }
audio_editor->edit(Ref<AudioStream>(s));
}
diff --git a/editor/plugins/baked_lightmap_editor_plugin.cpp b/editor/plugins/baked_lightmap_editor_plugin.cpp
index 4f1b794c0c..8fbe1646f7 100644
--- a/editor/plugins/baked_lightmap_editor_plugin.cpp
+++ b/editor/plugins/baked_lightmap_editor_plugin.cpp
@@ -75,8 +75,9 @@ void BakedLightmapEditorPlugin::_bake() {
void BakedLightmapEditorPlugin::edit(Object *p_object) {
BakedLightmap *s = Object::cast_to<BakedLightmap>(p_object);
- if (!s)
+ if (!s) {
return;
+ }
lightmap = s;
}
diff --git a/editor/plugins/camera_3d_editor_plugin.cpp b/editor/plugins/camera_3d_editor_plugin.cpp
index 58ea5e45bb..48f9f208a5 100644
--- a/editor/plugins/camera_3d_editor_plugin.cpp
+++ b/editor/plugins/camera_3d_editor_plugin.cpp
@@ -55,10 +55,11 @@ void Camera3DEditor::edit(Node *p_camera) {
preview->set_pressed(false);
Node3DEditor::get_singleton()->set_custom_camera(nullptr);
} else {
- if (preview->is_pressed())
+ if (preview->is_pressed()) {
Node3DEditor::get_singleton()->set_custom_camera(p_camera);
- else
+ } else {
Node3DEditor::get_singleton()->set_custom_camera(nullptr);
+ }
}
}
diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp
index 2d7198bec8..744c7907af 100644
--- a/editor/plugins/canvas_item_editor_plugin.cpp
+++ b/editor/plugins/canvas_item_editor_plugin.cpp
@@ -472,8 +472,9 @@ float CanvasItemEditor::snap_angle(float p_target, float p_start) const {
void CanvasItemEditor::_unhandled_key_input(const Ref<InputEvent> &p_ev) {
Ref<InputEventKey> k = p_ev;
- if (!is_visible_in_tree())
+ if (!is_visible_in_tree()) {
return;
+ }
if (k->get_keycode() == KEY_CONTROL || k->get_keycode() == KEY_ALT || k->get_keycode() == KEY_SHIFT) {
viewport->update();
@@ -487,8 +488,9 @@ void CanvasItemEditor::_unhandled_key_input(const Ref<InputEvent> &p_ev) {
} else if ((grid_snap_active || show_grid) && divide_grid_step_shortcut.is_valid() && divide_grid_step_shortcut->is_shortcut(p_ev)) {
// Divide the grid size
Point2 new_grid_step = grid_step * Math::pow(2.0, grid_step_multiplier - 1);
- if (new_grid_step.x >= 1.0 && new_grid_step.y >= 1.0)
+ if (new_grid_step.x >= 1.0 && new_grid_step.y >= 1.0) {
grid_step_multiplier--;
+ }
viewport->update();
}
}
@@ -496,17 +498,19 @@ void CanvasItemEditor::_unhandled_key_input(const Ref<InputEvent> &p_ev) {
Object *CanvasItemEditor::_get_editor_data(Object *p_what) {
CanvasItem *ci = Object::cast_to<CanvasItem>(p_what);
- if (!ci)
+ if (!ci) {
return nullptr;
+ }
return memnew(CanvasItemEditorSelectedItem);
}
void CanvasItemEditor::_keying_changed() {
- if (AnimationPlayerEditor::singleton->get_track_editor()->is_visible_in_tree())
+ if (AnimationPlayerEditor::singleton->get_track_editor()->is_visible_in_tree()) {
animation_hb->show();
- else
+ } else {
animation_hb->hide();
+ }
}
Rect2 CanvasItemEditor::_get_encompassing_rect_from_list(List<CanvasItem *> p_list) {
@@ -532,10 +536,12 @@ Rect2 CanvasItemEditor::_get_encompassing_rect_from_list(List<CanvasItem *> p_li
}
void CanvasItemEditor::_expand_encompassing_rect_using_children(Rect2 &r_rect, const Node *p_node, bool &r_first, const Transform2D &p_parent_xform, const Transform2D &p_canvas_xform, bool include_locked_nodes) {
- if (!p_node)
+ if (!p_node) {
return;
- if (Object::cast_to<Viewport>(p_node))
+ }
+ if (Object::cast_to<Viewport>(p_node)) {
return;
+ }
const CanvasItem *canvas_item = Object::cast_to<CanvasItem>(p_node);
@@ -571,10 +577,12 @@ Rect2 CanvasItemEditor::_get_encompassing_rect(const Node *p_node) {
}
void CanvasItemEditor::_find_canvas_items_at_pos(const Point2 &p_pos, Node *p_node, Vector<_SelectResult> &r_items, const Transform2D &p_parent_xform, const Transform2D &p_canvas_xform) {
- if (!p_node)
+ if (!p_node) {
return;
- if (Object::cast_to<Viewport>(p_node))
+ }
+ if (Object::cast_to<Viewport>(p_node)) {
return;
+ }
const real_t grab_distance = EDITOR_GET("editors/poly_editor/point_grab_radius");
CanvasItem *canvas_item = Object::cast_to<CanvasItem>(p_node);
@@ -659,8 +667,9 @@ void CanvasItemEditor::_get_bones_at_pos(const Point2 &p_pos, Vector<_SelectResu
Node2D *from_node = Object::cast_to<Node2D>(ObjectDB::get_instance(E->key().from));
Vector<Vector2> bone_shape;
- if (!_get_bone_shape(&bone_shape, nullptr, E))
+ if (!_get_bone_shape(&bone_shape, nullptr, E)) {
continue;
+ }
// Check if the point is inside the Polygon2D
if (Geometry::is_point_in_polygon(screen_pos, bone_shape)) {
@@ -672,8 +681,9 @@ void CanvasItemEditor::_get_bones_at_pos(const Point2 &p_pos, Vector<_SelectResu
break;
}
}
- if (duplicate)
+ if (duplicate) {
continue;
+ }
// Else, add it
_SelectResult res;
@@ -692,21 +702,25 @@ bool CanvasItemEditor::_get_bone_shape(Vector<Vector2> *shape, Vector<Vector2> *
Node2D *from_node = Object::cast_to<Node2D>(ObjectDB::get_instance(bone->key().from));
Node2D *to_node = Object::cast_to<Node2D>(ObjectDB::get_instance(bone->key().to));
- if (!from_node)
+ if (!from_node) {
return false;
- if (!from_node->is_inside_tree())
+ }
+ if (!from_node->is_inside_tree()) {
return false; //may have been removed
+ }
- if (!to_node && bone->get().length == 0)
+ if (!to_node && bone->get().length == 0) {
return false;
+ }
Vector2 from = transform.xform(from_node->get_global_position());
Vector2 to;
- if (to_node)
+ if (to_node) {
to = transform.xform(to_node->get_global_position());
- else
+ } else {
to = transform.xform(from_node->get_global_transform().xform(Vector2(bone->get().length, 0)));
+ }
Vector2 rel = to - from;
Vector2 relt = rel.tangent().normalized() * bone_width;
@@ -734,10 +748,12 @@ bool CanvasItemEditor::_get_bone_shape(Vector<Vector2> *shape, Vector<Vector2> *
}
void CanvasItemEditor::_find_canvas_items_in_rect(const Rect2 &p_rect, Node *p_node, List<CanvasItem *> *r_items, const Transform2D &p_parent_xform, const Transform2D &p_canvas_xform) {
- if (!p_node)
+ if (!p_node) {
return;
- if (Object::cast_to<Viewport>(p_node))
+ }
+ if (Object::cast_to<Viewport>(p_node)) {
return;
+ }
CanvasItem *canvas_item = Object::cast_to<CanvasItem>(p_node);
Node *scene = editor->get_edited_scene();
@@ -852,10 +868,12 @@ Vector2 CanvasItemEditor::_position_to_anchor(const Control *p_control, Vector2
}
void CanvasItemEditor::_save_canvas_item_ik_chain(const CanvasItem *p_canvas_item, List<float> *p_bones_length, List<Dictionary> *p_bones_state) {
- if (p_bones_length)
+ if (p_bones_length) {
*p_bones_length = List<float>();
- if (p_bones_state)
+ }
+ if (p_bones_state) {
*p_bones_state = List<Dictionary>();
+ }
const Node2D *bone = Object::cast_to<Node2D>(p_canvas_item);
if (bone && bone->has_meta("_edit_bone_")) {
@@ -881,10 +899,12 @@ void CanvasItemEditor::_save_canvas_item_ik_chain(const CanvasItem *p_canvas_ite
for (List<const Node2D *>::Element *bone_E = bone_ik_list.front(); bone_E; bone_E = bone_E->next()) {
bone_xform = bone_xform * bone->get_transform().affine_inverse();
const Node2D *parent_bone = bone_E->get();
- if (p_bones_length)
+ if (p_bones_length) {
p_bones_length->push_back(parent_bone->get_global_transform().get_origin().distance_to(bone->get_global_position()));
- if (p_bones_state)
+ }
+ if (p_bones_state) {
p_bones_state->push_back(parent_bone->_edit_get_state());
+ }
bone = parent_bone;
}
}
@@ -956,13 +976,15 @@ void CanvasItemEditor::_snap_changed() {
}
void CanvasItemEditor::_selection_result_pressed(int p_result) {
- if (selection_results.size() <= p_result)
+ if (selection_results.size() <= p_result) {
return;
+ }
CanvasItem *item = selection_results[p_result].item;
- if (item)
+ if (item) {
_select_click_on_item(item, Point2(), selection_menu_additive_selection);
+ }
}
void CanvasItemEditor::_selection_menu_hide() {
@@ -1262,8 +1284,9 @@ bool CanvasItemEditor::_gui_input_zoom_or_pan(const Ref<InputEvent> &p_event, bo
}
}
- if (is_pan_key)
+ if (is_pan_key) {
pan_pressed = k->is_pressed();
+ }
}
Ref<InputEventMouseMotion> m = p_event;
@@ -1350,10 +1373,11 @@ bool CanvasItemEditor::_gui_input_pivot(const Ref<InputEvent> &p_event) {
drag_to = transform.affine_inverse().xform(m->get_position());
_restore_canvas_item_state(drag_selection);
Vector2 new_pos;
- if (drag_selection.size() == 1)
+ if (drag_selection.size() == 1) {
new_pos = snap_point(drag_to, SNAP_NODE_SIDES | SNAP_NODE_CENTER | SNAP_NODE_ANCHORS | SNAP_OTHER_NODES | SNAP_GRID | SNAP_PIXEL, 0, drag_selection[0]);
- else
+ } else {
new_pos = snap_point(drag_to, SNAP_OTHER_NODES | SNAP_GRID | SNAP_PIXEL);
+ }
for (List<CanvasItem *>::Element *E = drag_selection.front(); E; E = E->next()) {
CanvasItem *canvas_item = E->get();
canvas_item->_edit_set_pivot(canvas_item->get_global_transform_with_canvas().affine_inverse().xform(new_pos));
@@ -1462,8 +1486,9 @@ bool CanvasItemEditor::_gui_input_rotate(const Ref<InputEvent> &p_event) {
// Remove not movable nodes
for (List<CanvasItem *>::Element *E = selection.front(); E; E = E->next()) {
- if (!_is_node_movable(E->get(), true))
+ if (!_is_node_movable(E->get(), true)) {
selection.erase(E);
+ }
}
drag_selection = selection;
@@ -1611,28 +1636,36 @@ bool CanvasItemEditor::_gui_input_anchors(const Ref<InputEvent> &p_event) {
switch (drag_type) {
case DRAG_ANCHOR_TOP_LEFT:
- if (!use_single_axis || !use_y)
+ if (!use_single_axis || !use_y) {
control->set_anchor(MARGIN_LEFT, new_anchor.x, false, false);
- if (!use_single_axis || use_y)
+ }
+ if (!use_single_axis || use_y) {
control->set_anchor(MARGIN_TOP, new_anchor.y, false, false);
+ }
break;
case DRAG_ANCHOR_TOP_RIGHT:
- if (!use_single_axis || !use_y)
+ if (!use_single_axis || !use_y) {
control->set_anchor(MARGIN_RIGHT, new_anchor.x, false, false);
- if (!use_single_axis || use_y)
+ }
+ if (!use_single_axis || use_y) {
control->set_anchor(MARGIN_TOP, new_anchor.y, false, false);
+ }
break;
case DRAG_ANCHOR_BOTTOM_RIGHT:
- if (!use_single_axis || !use_y)
+ if (!use_single_axis || !use_y) {
control->set_anchor(MARGIN_RIGHT, new_anchor.x, false, false);
- if (!use_single_axis || use_y)
+ }
+ if (!use_single_axis || use_y) {
control->set_anchor(MARGIN_BOTTOM, new_anchor.y, false, false);
+ }
break;
case DRAG_ANCHOR_BOTTOM_LEFT:
- if (!use_single_axis || !use_y)
+ if (!use_single_axis || !use_y) {
control->set_anchor(MARGIN_LEFT, new_anchor.x, false, false);
- if (!use_single_axis || use_y)
+ }
+ if (!use_single_axis || use_y) {
control->set_anchor(MARGIN_BOTTOM, new_anchor.y, false, false);
+ }
break;
case DRAG_ANCHOR_ALL:
if (!use_single_axis || !use_y) {
@@ -1710,13 +1743,15 @@ bool CanvasItemEditor::_gui_input_resize(const Ref<InputEvent> &p_event) {
Vector2 ofs = ((endpoints[i] - endpoints[prev]).normalized() + ((endpoints[i] - endpoints[next]).normalized())).normalized();
ofs *= (select_handle->get_size().width / 2);
ofs += endpoints[i];
- if (ofs.distance_to(b->get_position()) < radius)
+ if (ofs.distance_to(b->get_position()) < radius) {
resize_drag = dragger[i * 2];
+ }
ofs = (endpoints[i] + endpoints[next]) / 2;
ofs += (endpoints[next] - endpoints[i]).tangent().normalized() * (select_handle->get_size().width / 2);
- if (ofs.distance_to(b->get_position()) < radius)
+ if (ofs.distance_to(b->get_position()) < radius) {
resize_drag = dragger[i * 2 + 1];
+ }
}
if (resize_drag != DRAG_NONE) {
@@ -2141,20 +2176,23 @@ bool CanvasItemEditor::_gui_input_move(const Ref<InputEvent> &p_event) {
bool move_local_base_rotated = k->get_control() || k->get_metakey();
Vector2 dir;
- if (k->get_keycode() == KEY_UP)
+ if (k->get_keycode() == KEY_UP) {
dir += Vector2(0, -1);
- else if (k->get_keycode() == KEY_DOWN)
+ } else if (k->get_keycode() == KEY_DOWN) {
dir += Vector2(0, 1);
- else if (k->get_keycode() == KEY_LEFT)
+ } else if (k->get_keycode() == KEY_LEFT) {
dir += Vector2(-1, 0);
- else if (k->get_keycode() == KEY_RIGHT)
+ } else if (k->get_keycode() == KEY_RIGHT) {
dir += Vector2(1, 0);
- if (k->get_shift())
+ }
+ if (k->get_shift()) {
dir *= grid_step * Math::pow(2.0, grid_step_multiplier);
+ }
drag_to += dir;
- if (k->get_shift())
+ if (k->get_shift()) {
drag_to = drag_to.snapped(grid_step * Math::pow(2.0, grid_step_multiplier));
+ }
Point2 previous_pos;
if (drag_selection.size() == 1) {
@@ -2293,8 +2331,9 @@ bool CanvasItemEditor::_gui_input_select(const Ref<InputEvent> &p_event) {
Point2 click = transform.affine_inverse().xform(b->get_position());
Node *scene = editor->get_edited_scene();
- if (!scene)
+ if (!scene) {
return true;
+ }
// Find the item to select
CanvasItem *canvas_item = nullptr;
@@ -2362,10 +2401,12 @@ bool CanvasItemEditor::_gui_input_select(const Ref<InputEvent> &p_event) {
Point2 bsfrom = drag_from;
Point2 bsto = box_selecting_to;
- if (bsfrom.x > bsto.x)
+ if (bsfrom.x > bsto.x) {
SWAP(bsfrom.x, bsto.x);
- if (bsfrom.y > bsto.y)
+ }
+ if (bsfrom.y > bsto.y) {
SWAP(bsfrom.y, bsto.y);
+ }
_find_canvas_items_in_rect(Rect2(bsfrom, bsto - bsfrom), scene, &selitems);
for (List<CanvasItem *>::Element *E = selitems.front(); E; E = E->next()) {
@@ -2402,15 +2443,17 @@ bool CanvasItemEditor::_gui_input_select(const Ref<InputEvent> &p_event) {
}
bool CanvasItemEditor::_gui_input_ruler_tool(const Ref<InputEvent> &p_event) {
- if (tool != TOOL_RULER)
+ if (tool != TOOL_RULER) {
return false;
+ }
Ref<InputEventMouseButton> b = p_event;
Ref<InputEventMouseMotion> m = p_event;
Point2 previous_origin = ruler_tool_origin;
- if (!ruler_tool_active)
+ if (!ruler_tool_active) {
ruler_tool_origin = snap_point(viewport->get_local_mouse_position() / zoom + view_offset);
+ }
if (b.is_valid() && b->get_button_index() == BUTTON_LEFT) {
if (b->is_pressed()) {
@@ -2446,8 +2489,9 @@ bool CanvasItemEditor::_gui_input_hover(const Ref<InputEvent> &p_event) {
for (int i = 0; i < hovering_results_items.size(); i++) {
CanvasItem *canvas_item = hovering_results_items[i].item;
- if (canvas_item->_edit_use_rect())
+ if (canvas_item->_edit_use_rect()) {
continue;
+ }
_HoverResult hover_result;
hover_result.position = canvas_item->get_global_transform_with_canvas().get_origin();
@@ -2516,8 +2560,9 @@ void CanvasItemEditor::_gui_input_viewport(const Ref<InputEvent> &p_event) {
accepted = (_gui_input_zoom_or_pan(p_event, accepted) || accepted);
- if (accepted)
+ if (accepted) {
accept_event();
+ }
// Handles the mouse hovering
_gui_input_hover(p_event);
@@ -2569,10 +2614,11 @@ void CanvasItemEditor::_gui_input_viewport(const Ref<InputEvent> &p_event) {
break;
}
- if (is_hovering_h_guide)
+ if (is_hovering_h_guide) {
c = CURSOR_VSIZE;
- else if (is_hovering_v_guide)
+ } else if (is_hovering_v_guide) {
c = CURSOR_HSIZE;
+ }
viewport->set_default_cursor_shape(c);
@@ -2633,8 +2679,9 @@ void CanvasItemEditor::_draw_guides() {
if (EditorNode::get_singleton()->get_edited_scene() && EditorNode::get_singleton()->get_edited_scene()->has_meta("_edit_vertical_guides_")) {
Array vguides = EditorNode::get_singleton()->get_edited_scene()->get_meta("_edit_vertical_guides_");
for (int i = 0; i < vguides.size(); i++) {
- if (drag_type == DRAG_V_GUIDE && i == dragged_guide_index)
+ if (drag_type == DRAG_V_GUIDE && i == dragged_guide_index) {
continue;
+ }
float x = xform.xform(Point2(vguides[i], 0)).x;
viewport->draw_line(Point2(x, 0), Point2(x, viewport->get_size().y), guide_color, Math::round(EDSCALE));
}
@@ -2643,8 +2690,9 @@ void CanvasItemEditor::_draw_guides() {
if (EditorNode::get_singleton()->get_edited_scene() && EditorNode::get_singleton()->get_edited_scene()->has_meta("_edit_horizontal_guides_")) {
Array hguides = EditorNode::get_singleton()->get_edited_scene()->get_meta("_edit_horizontal_guides_");
for (int i = 0; i < hguides.size(); i++) {
- if (drag_type == DRAG_H_GUIDE && i == dragged_guide_index)
+ if (drag_type == DRAG_H_GUIDE && i == dragged_guide_index) {
continue;
+ }
float y = xform.xform(Point2(0, hguides[i])).y;
viewport->draw_line(Point2(0, y), Point2(viewport->get_size().x, y), guide_color, Math::round(EDSCALE));
}
@@ -2844,8 +2892,9 @@ void CanvasItemEditor::_draw_grid() {
}
void CanvasItemEditor::_draw_ruler_tool() {
- if (tool != TOOL_RULER)
+ if (tool != TOOL_RULER) {
return;
+ }
if (ruler_tool_active) {
Color ruler_primary_color = get_theme_color("accent_color", "Editor");
@@ -3463,12 +3512,14 @@ void CanvasItemEditor::_draw_bones() {
for (Map<BoneKey, BoneList>::Element *E = bone_list.front(); E; E = E->next()) {
Vector<Vector2> bone_shape;
Vector<Vector2> bone_shape_outline;
- if (!_get_bone_shape(&bone_shape, &bone_shape_outline, E))
+ if (!_get_bone_shape(&bone_shape, &bone_shape_outline, E)) {
continue;
+ }
Node2D *from_node = Object::cast_to<Node2D>(ObjectDB::get_instance(E->key().from));
- if (!from_node->is_visible_in_tree())
+ if (!from_node->is_visible_in_tree()) {
continue;
+ }
Vector<Color> colors;
if (from_node->has_meta("_edit_ik_")) {
@@ -3511,11 +3562,13 @@ void CanvasItemEditor::_draw_invisible_nodes_positions(Node *p_node, const Trans
ERR_FAIL_COND(!p_node);
Node *scene = editor->get_edited_scene();
- if (p_node != scene && p_node->get_owner() != scene && !scene->is_editable_instance(p_node->get_owner()))
+ if (p_node != scene && p_node->get_owner() != scene && !scene->is_editable_instance(p_node->get_owner())) {
return;
+ }
CanvasItem *canvas_item = Object::cast_to<CanvasItem>(p_node);
- if (canvas_item && !canvas_item->is_visible())
+ if (canvas_item && !canvas_item->is_visible()) {
return;
+ }
Transform2D parent_xform = p_parent_xform;
Transform2D canvas_xform = p_canvas_xform;
@@ -3578,11 +3631,13 @@ void CanvasItemEditor::_draw_locks_and_groups(Node *p_node, const Transform2D &p
ERR_FAIL_COND(!p_node);
Node *scene = editor->get_edited_scene();
- if (p_node != scene && p_node->get_owner() != scene && !scene->is_editable_instance(p_node->get_owner()))
+ if (p_node != scene && p_node->get_owner() != scene && !scene->is_editable_instance(p_node->get_owner())) {
return;
+ }
CanvasItem *canvas_item = Object::cast_to<CanvasItem>(p_node);
- if (canvas_item && !canvas_item->is_visible())
+ if (canvas_item && !canvas_item->is_visible()) {
return;
+ }
Transform2D parent_xform = p_parent_xform;
Transform2D canvas_xform = p_canvas_xform;
@@ -3743,10 +3798,12 @@ void CanvasItemEditor::_draw_viewport() {
}
_draw_bones();
- if (show_rulers)
+ if (show_rulers) {
_draw_rulers();
- if (show_guides)
+ }
+ if (show_guides) {
_draw_guides();
+ }
_draw_smart_snapping();
_draw_focus();
_draw_hover();
@@ -3993,10 +4050,12 @@ void CanvasItemEditor::_selection_changed() {
List<Node *> selection = editor_selection->get_selected_node_list();
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
Control *control = Object::cast_to<Control>(E->get());
- if (!control)
+ if (!control) {
continue;
- if (Object::cast_to<Container>(control->get_parent()))
+ }
+ if (Object::cast_to<Container>(control->get_parent())) {
continue;
+ }
nbValidControls++;
if (control->has_meta("_edit_use_anchors_") && control->get_meta("_edit_use_anchors_")) {
@@ -4024,8 +4083,9 @@ void CanvasItemEditor::edit(CanvasItem *p_canvas_item) {
}
void CanvasItemEditor::_queue_update_bone_list() {
- if (bone_list_dirty)
+ if (bone_list_dirty) {
return;
+ }
call_deferred("_update_bone_list");
bone_list_dirty = true;
@@ -4180,8 +4240,9 @@ void CanvasItemEditor::_popup_warning_temporarily(Control *p_control, const floa
}
void CanvasItemEditor::_update_scroll(float) {
- if (updating_scroll)
+ if (updating_scroll) {
return;
+ }
view_offset.x = h_scroll->get_value();
view_offset.y = v_scroll->get_value();
@@ -4273,8 +4334,9 @@ void CanvasItemEditor::_set_anchors_preset(Control::LayoutPreset p_preset) {
}
void CanvasItemEditor::_zoom_on_position(float p_zoom, Point2 p_position) {
- if (p_zoom < MIN_ZOOM || p_zoom > MAX_ZOOM)
+ if (p_zoom < MIN_ZOOM || p_zoom > MAX_ZOOM) {
return;
+ }
float prev_zoom = zoom;
zoom = p_zoom;
@@ -4360,21 +4422,26 @@ void CanvasItemEditor::_insert_animation_keys(bool p_location, bool p_rotation,
for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) {
CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->key());
- if (!canvas_item || !canvas_item->is_visible_in_tree())
+ if (!canvas_item || !canvas_item->is_visible_in_tree()) {
continue;
+ }
- if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
+ if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root()) {
continue;
+ }
if (Object::cast_to<Node2D>(canvas_item)) {
Node2D *n2d = Object::cast_to<Node2D>(canvas_item);
- if (key_pos && p_location)
+ if (key_pos && p_location) {
AnimationPlayerEditor::singleton->get_track_editor()->insert_node_value_key(n2d, "position", n2d->get_position(), p_on_existing);
- if (key_rot && p_rotation)
+ }
+ if (key_rot && p_rotation) {
AnimationPlayerEditor::singleton->get_track_editor()->insert_node_value_key(n2d, "rotation_degrees", Math::rad2deg(n2d->get_rotation()), p_on_existing);
- if (key_scale && p_scale)
+ }
+ if (key_scale && p_scale) {
AnimationPlayerEditor::singleton->get_track_editor()->insert_node_value_key(n2d, "scale", n2d->get_scale(), p_on_existing);
+ }
if (n2d->has_meta("_edit_bone_") && n2d->get_parent_item()) {
//look for an IK chain
@@ -4390,19 +4457,23 @@ void CanvasItemEditor::_insert_animation_keys(bool p_location, bool p_rotation,
break;
}
- if (!n->get_parent_item())
+ if (!n->get_parent_item()) {
break;
+ }
n = Object::cast_to<Node2D>(n->get_parent_item());
}
if (has_chain && ik_chain.size()) {
for (List<Node2D *>::Element *F = ik_chain.front(); F; F = F->next()) {
- if (key_pos)
+ if (key_pos) {
AnimationPlayerEditor::singleton->get_track_editor()->insert_node_value_key(F->get(), "position", F->get()->get_position(), p_on_existing);
- if (key_rot)
+ }
+ if (key_rot) {
AnimationPlayerEditor::singleton->get_track_editor()->insert_node_value_key(F->get(), "rotation_degrees", Math::rad2deg(F->get()->get_rotation()), p_on_existing);
- if (key_scale)
+ }
+ if (key_scale) {
AnimationPlayerEditor::singleton->get_track_editor()->insert_node_value_key(F->get(), "scale", F->get()->get_scale(), p_on_existing);
+ }
}
}
}
@@ -4410,12 +4481,15 @@ void CanvasItemEditor::_insert_animation_keys(bool p_location, bool p_rotation,
} else if (Object::cast_to<Control>(canvas_item)) {
Control *ctrl = Object::cast_to<Control>(canvas_item);
- if (key_pos)
+ if (key_pos) {
AnimationPlayerEditor::singleton->get_track_editor()->insert_node_value_key(ctrl, "rect_position", ctrl->get_position(), p_on_existing);
- if (key_rot)
+ }
+ if (key_rot) {
AnimationPlayerEditor::singleton->get_track_editor()->insert_node_value_key(ctrl, "rect_rotation", ctrl->get_rotation_degrees(), p_on_existing);
- if (key_scale)
+ }
+ if (key_scale) {
AnimationPlayerEditor::singleton->get_track_editor()->insert_node_value_key(ctrl, "rect_size", ctrl->get_size(), p_on_existing);
+ }
}
}
}
@@ -4424,8 +4498,9 @@ void CanvasItemEditor::_button_toggle_anchor_mode(bool p_status) {
List<CanvasItem *> selection = _get_edited_canvas_items(false, false);
for (List<CanvasItem *>::Element *E = selection.front(); E; E = E->next()) {
Control *control = Object::cast_to<Control>(E->get());
- if (!control || Object::cast_to<Container>(control->get_parent()))
+ if (!control || Object::cast_to<Container>(control->get_parent())) {
continue;
+ }
control->set_meta("_edit_use_anchors_", p_status);
}
@@ -4564,10 +4639,12 @@ void CanvasItemEditor::_popup_callback(int p_op) {
List<Node *> selection = editor_selection->get_selected_node_list();
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->get());
- if (!canvas_item || !canvas_item->is_inside_tree())
+ if (!canvas_item || !canvas_item->is_inside_tree()) {
continue;
- if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
+ }
+ if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root()) {
continue;
+ }
undo_redo->add_do_method(canvas_item, "set_meta", "_edit_lock_", true);
undo_redo->add_undo_method(canvas_item, "remove_meta", "_edit_lock_");
@@ -4584,10 +4661,12 @@ void CanvasItemEditor::_popup_callback(int p_op) {
List<Node *> selection = editor_selection->get_selected_node_list();
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->get());
- if (!canvas_item || !canvas_item->is_inside_tree())
+ if (!canvas_item || !canvas_item->is_inside_tree()) {
continue;
- if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
+ }
+ if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root()) {
continue;
+ }
undo_redo->add_do_method(canvas_item, "remove_meta", "_edit_lock_");
undo_redo->add_undo_method(canvas_item, "set_meta", "_edit_lock_", true);
@@ -4604,10 +4683,12 @@ void CanvasItemEditor::_popup_callback(int p_op) {
List<Node *> selection = editor_selection->get_selected_node_list();
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->get());
- if (!canvas_item || !canvas_item->is_inside_tree())
+ if (!canvas_item || !canvas_item->is_inside_tree()) {
continue;
- if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
+ }
+ if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root()) {
continue;
+ }
undo_redo->add_do_method(canvas_item, "set_meta", "_edit_group_", true);
undo_redo->add_undo_method(canvas_item, "remove_meta", "_edit_group_");
@@ -4624,10 +4705,12 @@ void CanvasItemEditor::_popup_callback(int p_op) {
List<Node *> selection = editor_selection->get_selected_node_list();
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->get());
- if (!canvas_item || !canvas_item->is_inside_tree())
+ if (!canvas_item || !canvas_item->is_inside_tree()) {
continue;
- if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
+ }
+ if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root()) {
continue;
+ }
undo_redo->add_do_method(canvas_item, "remove_meta", "_edit_group_");
undo_redo->add_undo_method(canvas_item, "set_meta", "_edit_group_", true);
@@ -4762,11 +4845,13 @@ void CanvasItemEditor::_popup_callback(int p_op) {
for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) {
CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->key());
- if (!canvas_item || !canvas_item->is_visible_in_tree())
+ if (!canvas_item || !canvas_item->is_visible_in_tree()) {
continue;
+ }
- if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
+ if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root()) {
continue;
+ }
if (Object::cast_to<Node2D>(canvas_item)) {
Node2D *n2d = Object::cast_to<Node2D>(canvas_item);
@@ -4781,14 +4866,16 @@ void CanvasItemEditor::_popup_callback(int p_op) {
} break;
case ANIM_PASTE_POSE: {
- if (!pose_clipboard.size())
+ if (!pose_clipboard.size()) {
break;
+ }
undo_redo->create_action(TTR("Paste Pose"));
for (List<PoseClipboard>::Element *E = pose_clipboard.front(); E; E = E->next()) {
Node2D *n2d = Object::cast_to<Node2D>(ObjectDB::get_instance(E->get().id));
- if (!n2d)
+ if (!n2d) {
continue;
+ }
undo_redo->add_do_method(n2d, "set_position", E->get().pos);
undo_redo->add_do_method(n2d, "set_rotation", E->get().rot);
undo_redo->add_do_method(n2d, "set_scale", E->get().scale);
@@ -4804,26 +4891,32 @@ void CanvasItemEditor::_popup_callback(int p_op) {
for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) {
CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->key());
- if (!canvas_item || !canvas_item->is_visible_in_tree())
+ if (!canvas_item || !canvas_item->is_visible_in_tree()) {
continue;
+ }
- if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
+ if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root()) {
continue;
+ }
if (Object::cast_to<Node2D>(canvas_item)) {
Node2D *n2d = Object::cast_to<Node2D>(canvas_item);
- if (key_pos)
+ if (key_pos) {
n2d->set_position(Vector2());
- if (key_rot)
+ }
+ if (key_rot) {
n2d->set_rotation(0);
- if (key_scale)
+ }
+ if (key_scale) {
n2d->set_scale(Vector2(1, 1));
+ }
} else if (Object::cast_to<Control>(canvas_item)) {
Control *ctrl = Object::cast_to<Control>(canvas_item);
- if (key_pos)
+ if (key_pos) {
ctrl->set_position(Point2());
+ }
/*
if (key_scale)
AnimationPlayerEditor::singleton->get_track_editor()->insert_node_value_key(ctrl,"rect/size",ctrl->get_size());
@@ -4872,14 +4965,18 @@ void CanvasItemEditor::_popup_callback(int p_op) {
undo_redo->create_action(TTR("Create Custom Bone(s) from Node(s)"));
for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) {
Node2D *n2d = Object::cast_to<Node2D>(E->key());
- if (!n2d)
+ if (!n2d) {
continue;
- if (!n2d->is_visible_in_tree())
+ }
+ if (!n2d->is_visible_in_tree()) {
continue;
- if (!n2d->get_parent_item())
+ }
+ if (!n2d->get_parent_item()) {
continue;
- if (n2d->has_meta("_edit_bone_") && n2d->get_meta("_edit_bone_"))
+ }
+ if (n2d->has_meta("_edit_bone_") && n2d->get_meta("_edit_bone_")) {
continue;
+ }
undo_redo->add_do_method(n2d, "set_meta", "_edit_bone_", true);
undo_redo->add_undo_method(n2d, "remove_meta", "_edit_bone_");
@@ -4897,12 +4994,15 @@ void CanvasItemEditor::_popup_callback(int p_op) {
undo_redo->create_action(TTR("Clear Bones"));
for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) {
Node2D *n2d = Object::cast_to<Node2D>(E->key());
- if (!n2d)
+ if (!n2d) {
continue;
- if (!n2d->is_visible_in_tree())
+ }
+ if (!n2d->is_visible_in_tree()) {
continue;
- if (!n2d->has_meta("_edit_bone_"))
+ }
+ if (!n2d->has_meta("_edit_bone_")) {
continue;
+ }
undo_redo->add_do_method(n2d, "remove_meta", "_edit_bone_");
undo_redo->add_undo_method(n2d, "set_meta", "_edit_bone_", n2d->get_meta("_edit_bone_"));
@@ -4920,12 +5020,15 @@ void CanvasItemEditor::_popup_callback(int p_op) {
undo_redo->create_action(TTR("Make IK Chain"));
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->get());
- if (!canvas_item || !canvas_item->is_visible_in_tree())
+ if (!canvas_item || !canvas_item->is_visible_in_tree()) {
continue;
- if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
+ }
+ if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root()) {
continue;
- if (canvas_item->has_meta("_edit_ik_") && canvas_item->get_meta("_edit_ik_"))
+ }
+ if (canvas_item->has_meta("_edit_ik_") && canvas_item->get_meta("_edit_ik_")) {
continue;
+ }
undo_redo->add_do_method(canvas_item, "set_meta", "_edit_ik_", true);
undo_redo->add_undo_method(canvas_item, "remove_meta", "_edit_ik_");
@@ -4941,12 +5044,15 @@ void CanvasItemEditor::_popup_callback(int p_op) {
undo_redo->create_action(TTR("Clear IK Chain"));
for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) {
CanvasItem *n2d = Object::cast_to<CanvasItem>(E->key());
- if (!n2d)
+ if (!n2d) {
continue;
- if (!n2d->is_visible_in_tree())
+ }
+ if (!n2d->is_visible_in_tree()) {
continue;
- if (!n2d->has_meta("_edit_ik_"))
+ }
+ if (!n2d->has_meta("_edit_ik_")) {
continue;
+ }
undo_redo->add_do_method(n2d, "remove_meta", "_edit_ik_");
undo_redo->add_undo_method(n2d, "set_meta", "_edit_ik_", n2d->get_meta("_edit_ik_"));
@@ -4967,10 +5073,12 @@ void CanvasItemEditor::_focus_selection(int p_op) {
Map<Node *, Object *> &selection = editor_selection->get_selection();
for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) {
CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->key());
- if (!canvas_item)
+ if (!canvas_item) {
continue;
- if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
+ }
+ if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root()) {
continue;
+ }
// counting invisible items, for now
//if (!canvas_item->is_visible_in_tree()) continue;
@@ -4996,8 +5104,9 @@ void CanvasItemEditor::_focus_selection(int p_op) {
rect = rect.merge(canvas_item_rect);
}
};
- if (count == 0)
+ if (count == 0) {
return;
+ }
if (p_op == VIEW_CENTER_TO_SELECTION) {
center = rect.position + rect.size / 2;
@@ -5794,8 +5903,9 @@ void CanvasItemEditorViewport::_on_select_type(Object *selected) {
}
void CanvasItemEditorViewport::_on_change_type_confirmed() {
- if (!button_group->get_pressed_button())
+ if (!button_group->get_pressed_button()) {
return;
+ }
CheckBox *check = Object::cast_to<CheckBox>(button_group->get_pressed_button());
default_type = check->get_text();
@@ -5835,8 +5945,9 @@ void CanvasItemEditorViewport::_create_preview(const Vector<String> &files) cons
}
}
- if (add_preview)
+ if (add_preview) {
editor->get_scene_root()->add_child(preview_node);
+ }
}
void CanvasItemEditorViewport::_remove_preview() {
@@ -6010,20 +6121,21 @@ void CanvasItemEditorViewport::_perform_drop_data() {
Ref<Texture2D> texture = Ref<Texture2D>(Object::cast_to<Texture2D>(*res));
if (texture != nullptr && texture.is_valid()) {
Node *child;
- if (default_type == "Light2D")
+ if (default_type == "Light2D") {
child = memnew(Light2D);
- else if (default_type == "GPUParticles2D")
+ } else if (default_type == "GPUParticles2D") {
child = memnew(GPUParticles2D);
- else if (default_type == "Polygon2D")
+ } else if (default_type == "Polygon2D") {
child = memnew(Polygon2D);
- else if (default_type == "TouchScreenButton")
+ } else if (default_type == "TouchScreenButton") {
child = memnew(TouchScreenButton);
- else if (default_type == "TextureRect")
+ } else if (default_type == "TextureRect") {
child = memnew(TextureRect);
- else if (default_type == "NinePatchRect")
+ } else if (default_type == "NinePatchRect") {
child = memnew(NinePatchRect);
- else
+ } else {
child = memnew(Sprite2D); // default
+ }
_create_nodes(target_node, child, path, drop_pos);
}
@@ -6127,8 +6239,9 @@ void CanvasItemEditorViewport::drop_data(const Point2 &p_point, const Variant &p
if (d.has("type") && String(d["type"]) == "files") {
selected_files = d["files"];
}
- if (selected_files.size() == 0)
+ if (selected_files.size() == 0) {
return;
+ }
List<Node *> list = editor->get_editor_selection()->get_selected_node_list();
if (list.size() == 0) {
diff --git a/editor/plugins/canvas_item_editor_plugin.h b/editor/plugins/canvas_item_editor_plugin.h
index a4ef84f5f3..a686c98f65 100644
--- a/editor/plugins/canvas_item_editor_plugin.h
+++ b/editor/plugins/canvas_item_editor_plugin.h
@@ -318,10 +318,11 @@ private:
ObjectID from;
ObjectID to;
_FORCE_INLINE_ bool operator<(const BoneKey &p_key) const {
- if (from == p_key.from)
+ if (from == p_key.from) {
return to < p_key.to;
- else
+ } else {
return from < p_key.from;
+ }
}
};
diff --git a/editor/plugins/collision_polygon_3d_editor_plugin.cpp b/editor/plugins/collision_polygon_3d_editor_plugin.cpp
index 920a7f195a..c61d410d38 100644
--- a/editor/plugins/collision_polygon_3d_editor_plugin.cpp
+++ b/editor/plugins/collision_polygon_3d_editor_plugin.cpp
@@ -64,8 +64,9 @@ void CollisionPolygon3DEditor::_notification(int p_what) {
void CollisionPolygon3DEditor::_node_removed(Node *p_node) {
if (p_node == node) {
node = nullptr;
- if (imgeom->get_parent() == p_node)
+ if (imgeom->get_parent() == p_node) {
p_node->remove_child(imgeom);
+ }
hide();
set_process(false);
}
@@ -102,8 +103,9 @@ void CollisionPolygon3DEditor::_wip_close() {
}
bool CollisionPolygon3DEditor::forward_spatial_gui_input(Camera3D *p_camera, const Ref<InputEvent> &p_event) {
- if (!node)
+ if (!node) {
return false;
+ }
Transform gt = node->get_global_transform();
Transform gi = gt.affine_inverse();
@@ -120,8 +122,9 @@ bool CollisionPolygon3DEditor::forward_spatial_gui_input(Camera3D *p_camera, con
Vector3 spoint;
- if (!p.intersects_ray(ray_from, ray_dir, &spoint))
+ if (!p.intersects_ray(ray_from, ray_dir, &spoint)) {
return false;
+ }
spoint = gi.xform(spoint);
@@ -194,8 +197,9 @@ bool CollisionPolygon3DEditor::forward_spatial_gui_input(Camera3D *p_camera, con
};
Vector2 cp = Geometry::get_closest_point_to_segment_2d(gpoint, points);
- if (cp.distance_squared_to(points[0]) < CMP_EPSILON2 || cp.distance_squared_to(points[1]) < CMP_EPSILON2)
+ if (cp.distance_squared_to(points[0]) < CMP_EPSILON2 || cp.distance_squared_to(points[1]) < CMP_EPSILON2) {
continue; //not valid to reuse point
+ }
real_t d = cp.distance_to(gpoint);
if (d < closest_dist && d < grab_threshold) {
@@ -304,8 +308,9 @@ bool CollisionPolygon3DEditor::forward_spatial_gui_input(Camera3D *p_camera, con
Vector3 spoint;
- if (!p.intersects_ray(ray_from, ray_dir, &spoint))
+ if (!p.intersects_ray(ray_from, ray_dir, &spoint)) {
return false;
+ }
spoint = gi.xform(spoint);
@@ -330,22 +335,25 @@ bool CollisionPolygon3DEditor::forward_spatial_gui_input(Camera3D *p_camera, con
}
float CollisionPolygon3DEditor::_get_depth() {
- if (bool(node->call("_has_editable_3d_polygon_no_depth")))
+ if (bool(node->call("_has_editable_3d_polygon_no_depth"))) {
return 0;
+ }
return float(node->call("get_depth"));
}
void CollisionPolygon3DEditor::_polygon_draw() {
- if (!node)
+ if (!node) {
return;
+ }
Vector<Vector2> poly;
- if (wip_active)
+ if (wip_active) {
poly = wip;
- else
+ } else {
poly = node->call("get_polygon");
+ }
float depth = _get_depth() * 0.5;
@@ -358,15 +366,17 @@ void CollisionPolygon3DEditor::_polygon_draw() {
for (int i = 0; i < poly.size(); i++) {
Vector2 p, p2;
p = i == edited_point ? edited_point_pos : poly[i];
- if ((wip_active && i == poly.size() - 1) || (((i + 1) % poly.size()) == edited_point))
+ if ((wip_active && i == poly.size() - 1) || (((i + 1) % poly.size()) == edited_point)) {
p2 = edited_point_pos;
- else
+ } else {
p2 = poly[(i + 1) % poly.size()];
+ }
- if (i == 0)
+ if (i == 0) {
rect.position = p;
- else
+ } else {
rect.expand_to(p);
+ }
Vector3 point = Vector3(p.x, p.y, depth);
Vector3 next_point = Vector3(p2.x, p2.y, depth);
@@ -431,8 +441,9 @@ void CollisionPolygon3DEditor::_polygon_draw() {
m->clear_surfaces();
- if (poly.size() == 0)
+ if (poly.size() == 0) {
return;
+ }
Array a;
a.resize(Mesh::ARRAY_MAX);
@@ -471,8 +482,9 @@ void CollisionPolygon3DEditor::edit(Node *p_collision_polygon) {
} else {
node = nullptr;
- if (imgeom->get_parent())
+ if (imgeom->get_parent()) {
imgeom->get_parent()->remove_child(imgeom);
+ }
set_process(false);
}
diff --git a/editor/plugins/cpu_particles_2d_editor_plugin.cpp b/editor/plugins/cpu_particles_2d_editor_plugin.cpp
index a601c1440d..008de7cfb4 100644
--- a/editor/plugins/cpu_particles_2d_editor_plugin.cpp
+++ b/editor/plugins/cpu_particles_2d_editor_plugin.cpp
@@ -134,8 +134,9 @@ void CPUParticles2DEditorPlugin::_generate_emission_mask() {
}
}
- if (on_border)
+ if (on_border) {
break;
+ }
}
if (on_border) {
@@ -145,8 +146,9 @@ void CPUParticles2DEditorPlugin::_generate_emission_mask() {
Vector2 normal;
for (int x = i - 2; x <= i + 2; x++) {
for (int y = j - 2; y <= j + 2; y++) {
- if (x == i && y == j)
+ if (x == i && y == j) {
continue;
+ }
if (x < 0 || y < 0 || x >= s.width || y >= s.height || r[(y * s.width + x) * 4 + 3] <= 128) {
normal += Vector2(x - i, y - j).normalized();
diff --git a/editor/plugins/curve_editor_plugin.cpp b/editor/plugins/curve_editor_plugin.cpp
index 94059ea39d..539ab03f5b 100644
--- a/editor/plugins/curve_editor_plugin.cpp
+++ b/editor/plugins/curve_editor_plugin.cpp
@@ -65,8 +65,9 @@ CurveEditor::CurveEditor() {
}
void CurveEditor::set_curve(Ref<Curve> curve) {
- if (curve == _curve_ref)
+ if (curve == _curve_ref) {
return;
+ }
if (_curve_ref.is_valid()) {
_curve_ref->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &CurveEditor::_curve_changed));
@@ -95,8 +96,9 @@ Size2 CurveEditor::get_minimum_size() const {
}
void CurveEditor::_notification(int p_what) {
- if (p_what == NOTIFICATION_DRAW)
+ if (p_what == NOTIFICATION_DRAW) {
_draw();
+ }
}
void CurveEditor::on_gui_input(const Ref<InputEvent> &p_event) {
@@ -108,8 +110,9 @@ void CurveEditor::on_gui_input(const Ref<InputEvent> &p_event) {
Vector2 mpos = mb.get_position();
_selected_tangent = get_tangent_at(mpos);
- if (_selected_tangent == TANGENT_NONE)
+ if (_selected_tangent == TANGENT_NONE) {
set_selected_point(get_point_at(mpos));
+ }
switch (mb.get_button_index()) {
case BUTTON_RIGHT:
@@ -182,10 +185,11 @@ void CurveEditor::on_gui_input(const Ref<InputEvent> &p_event) {
set_selected_point(i);
// This is to prevent the user from losing a point out of view.
- if (point_pos.y < curve.get_min_value())
+ if (point_pos.y < curve.get_min_value()) {
point_pos.y = curve.get_min_value();
- else if (point_pos.y > curve.get_max_value())
+ } else if (point_pos.y > curve.get_max_value()) {
point_pos.y = curve.get_max_value();
+ }
curve.set_point_value(_selected_point, point_pos.y);
@@ -198,10 +202,11 @@ void CurveEditor::on_gui_input(const Ref<InputEvent> &p_event) {
Vector2 dir = (control_pos - point_pos).normalized();
real_t tangent;
- if (!Math::is_zero_approx(dir.x))
+ if (!Math::is_zero_approx(dir.x)) {
tangent = dir.y / dir.x;
- else
+ } else {
tangent = 9999 * (dir.y >= 0 ? 1 : -1);
+ }
bool link = !Input::get_singleton()->is_key_pressed(KEY_SHIFT);
@@ -209,14 +214,16 @@ void CurveEditor::on_gui_input(const Ref<InputEvent> &p_event) {
curve.set_point_left_tangent(_selected_point, tangent);
// Note: if a tangent is set to linear, it shouldn't be linked to the other
- if (link && _selected_point != (curve.get_point_count() - 1) && curve.get_point_right_mode(_selected_point) != Curve::TANGENT_LINEAR)
+ if (link && _selected_point != (curve.get_point_count() - 1) && curve.get_point_right_mode(_selected_point) != Curve::TANGENT_LINEAR) {
curve.set_point_right_tangent(_selected_point, tangent);
+ }
} else {
curve.set_point_right_tangent(_selected_point, tangent);
- if (link && _selected_point != 0 && curve.get_point_left_mode(_selected_point) != Curve::TANGENT_LINEAR)
+ if (link && _selected_point != 0 && curve.get_point_left_mode(_selected_point) != Curve::TANGENT_LINEAR) {
curve.set_point_left_tangent(_selected_point, tangent);
+ }
}
}
}
@@ -231,8 +238,9 @@ void CurveEditor::on_gui_input(const Ref<InputEvent> &p_event) {
const InputEventKey &key = **key_ref;
if (key.is_pressed() && _selected_point != -1) {
- if (key.get_keycode() == KEY_DELETE)
+ if (key.get_keycode() == KEY_DELETE) {
remove_point(_selected_point);
+ }
}
}
}
@@ -351,8 +359,9 @@ void CurveEditor::open_context_menu(Vector2 pos) {
_context_menu->set_item_checked(_context_menu->get_item_index(CONTEXT_LINEAR), is_linear);
} else {
- if (_selected_point > 0 || _selected_point + 1 < _curve_ref->get_point_count())
+ if (_selected_point > 0 || _selected_point + 1 < _curve_ref->get_point_count()) {
_context_menu->add_separator();
+ }
if (_selected_point > 0) {
_context_menu->add_check_item(TTR("Left Linear"), CONTEXT_LEFT_LINEAR);
@@ -377,8 +386,9 @@ void CurveEditor::open_context_menu(Vector2 pos) {
}
int CurveEditor::get_point_at(Vector2 pos) const {
- if (_curve_ref.is_null())
+ if (_curve_ref.is_null()) {
return -1;
+ }
const Curve &curve = **_curve_ref;
const float r = _hover_radius * _hover_radius;
@@ -394,8 +404,9 @@ int CurveEditor::get_point_at(Vector2 pos) const {
}
CurveEditor::TangentIndex CurveEditor::get_tangent_at(Vector2 pos) const {
- if (_curve_ref.is_null() || _selected_point < 0)
+ if (_curve_ref.is_null() || _selected_point < 0) {
return TANGENT_NONE;
+ }
if (_selected_point != 0) {
Vector2 control_pos = get_tangent_view_pos(_selected_point, TANGENT_LEFT);
@@ -421,10 +432,11 @@ void CurveEditor::add_point(Vector2 pos) {
ur.create_action(TTR("Remove Curve Point"));
Vector2 point_pos = get_world_pos(pos);
- if (point_pos.y < 0.0)
+ if (point_pos.y < 0.0) {
point_pos.y = 0.0;
- else if (point_pos.y > 1.0)
+ } else if (point_pos.y > 1.0) {
point_pos.y = 1.0;
+ }
// Small trick to get the point index to feed the undo method
int i = _curve_ref->add_point(point_pos);
@@ -447,11 +459,13 @@ void CurveEditor::remove_point(int index) {
ur.add_do_method(*_curve_ref, "remove_point", index);
ur.add_undo_method(*_curve_ref, "add_point", p.pos, p.left_tangent, p.right_tangent, p.left_mode, p.right_mode);
- if (index == _selected_point)
+ if (index == _selected_point) {
set_selected_point(-1);
+ }
- if (index == _hover_point)
+ if (index == _hover_point) {
set_hover_point_index(-1);
+ }
ur.commit_action();
}
@@ -462,8 +476,9 @@ void CurveEditor::toggle_linear(TangentIndex tangent) {
UndoRedo &ur = *EditorNode::get_singleton()->get_undo_redo();
ur.create_action(TTR("Toggle Curve Linear Tangent"));
- if (tangent == TANGENT_NONE)
+ if (tangent == TANGENT_NONE) {
tangent = _selected_tangent;
+ }
if (tangent == TANGENT_LEFT) {
bool is_linear = _curve_ref->get_point_left_mode(_selected_point) == Curve::TANGENT_LINEAR;
@@ -530,10 +545,11 @@ void CurveEditor::update_view_transform() {
Vector2 CurveEditor::get_tangent_view_pos(int i, TangentIndex tangent) const {
Vector2 dir;
- if (tangent == TANGENT_LEFT)
+ if (tangent == TANGENT_LEFT) {
dir = -Vector2(1, _curve_ref->get_point_left_tangent(i));
- else
+ } else {
dir = Vector2(1, _curve_ref->get_point_right_tangent(i));
+ }
Vector2 point_pos = get_view_pos(_curve_ref->get_point_position(i));
Vector2 control_pos = get_view_pos(_curve_ref->get_point_position(i) + dir);
@@ -605,8 +621,9 @@ struct CanvasItemPlotCurve {
};
void CurveEditor::_draw() {
- if (_curve_ref.is_null())
+ if (_curve_ref.is_null()) {
return;
+ }
Curve &curve = **_curve_ref;
update_view_transform();
diff --git a/editor/plugins/debugger_editor_plugin.cpp b/editor/plugins/debugger_editor_plugin.cpp
index da060c3093..0ca479555d 100644
--- a/editor/plugins/debugger_editor_plugin.cpp
+++ b/editor/plugins/debugger_editor_plugin.cpp
@@ -164,8 +164,9 @@ void DebuggerEditorPlugin::_menu_option(int p_option) {
}
void DebuggerEditorPlugin::_notification(int p_what) {
- if (p_what == NOTIFICATION_READY)
+ if (p_what == NOTIFICATION_READY) {
_update_debug_options();
+ }
}
void DebuggerEditorPlugin::_update_debug_options() {
@@ -177,18 +178,24 @@ void DebuggerEditorPlugin::_update_debug_options() {
bool check_reload_scripts = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_reload_scripts", false);
int instances = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_debug_instances", 1);
- if (check_deploy_remote)
+ if (check_deploy_remote) {
_menu_option(RUN_DEPLOY_REMOTE_DEBUG);
- if (check_file_server)
+ }
+ if (check_file_server) {
_menu_option(RUN_FILE_SERVER);
- if (check_debug_collisions)
+ }
+ if (check_debug_collisions) {
_menu_option(RUN_DEBUG_COLLISONS);
- if (check_debug_navigation)
+ }
+ if (check_debug_navigation) {
_menu_option(RUN_DEBUG_NAVIGATION);
- if (check_live_debug)
+ }
+ if (check_live_debug) {
_menu_option(RUN_LIVE_DEBUG);
- if (check_reload_scripts)
+ }
+ if (check_reload_scripts) {
_menu_option(RUN_RELOAD_SCRIPTS);
+ }
int len = instances_menu->get_item_count();
for (int idx = 0; idx < len; idx++) {
diff --git a/editor/plugins/editor_preview_plugins.cpp b/editor/plugins/editor_preview_plugins.cpp
index 0c0f014af6..9cb167b41c 100644
--- a/editor/plugins/editor_preview_plugins.cpp
+++ b/editor/plugins/editor_preview_plugins.cpp
@@ -43,8 +43,9 @@
#include "servers/audio/audio_stream.h"
void post_process_preview(Ref<Image> p_image) {
- if (p_image->get_format() != Image::FORMAT_RGBA8)
+ if (p_image->get_format() != Image::FORMAT_RGBA8) {
p_image->convert(Image::FORMAT_RGBA8);
+ }
const int w = p_image->get_width();
const int h = p_image->get_height();
@@ -105,14 +106,16 @@ Ref<Texture2D> EditorTexturePreviewPlugin::generate(const RES &p_from, const Siz
}
}
- if (img.is_null() || img->empty())
+ if (img.is_null() || img->empty()) {
return Ref<Texture2D>();
+ }
img->clear_mipmaps();
if (img->is_compressed()) {
- if (img->decompress() != OK)
+ if (img->decompress() != OK) {
return Ref<Texture2D>();
+ }
} else if (img->get_format() != Image::FORMAT_RGB8 && img->get_format() != Image::FORMAT_RGBA8) {
img->convert(Image::FORMAT_RGBA8);
}
@@ -146,15 +149,17 @@ bool EditorImagePreviewPlugin::handles(const String &p_type) const {
Ref<Texture2D> EditorImagePreviewPlugin::generate(const RES &p_from, const Size2 &p_size) const {
Ref<Image> img = p_from;
- if (img.is_null() || img->empty())
+ if (img.is_null() || img->empty()) {
return Ref<Image>();
+ }
img = img->duplicate();
img->clear_mipmaps();
if (img->is_compressed()) {
- if (img->decompress() != OK)
+ if (img->decompress() != OK) {
return Ref<Image>();
+ }
} else if (img->get_format() != Image::FORMAT_RGB8 && img->get_format() != Image::FORMAT_RGBA8) {
img->convert(Image::FORMAT_RGBA8);
}
@@ -220,8 +225,9 @@ Ref<Texture2D> EditorBitmapPreviewPlugin::generate(const RES &p_from, const Size
img->create(bm->get_size().width, bm->get_size().height, false, Image::FORMAT_L8, data);
if (img->is_compressed()) {
- if (img->decompress() != OK)
+ if (img->decompress() != OK) {
return Ref<Texture2D>();
+ }
} else if (img->get_format() != Image::FORMAT_RGB8 && img->get_format() != Image::FORMAT_RGBA8) {
img->convert(Image::FORMAT_RGBA8);
}
@@ -269,8 +275,9 @@ Ref<Texture2D> EditorPackedScenePreviewPlugin::generate_from_path(const String &
String path = cache_base + ".png";
- if (!FileAccess::exists(path))
+ if (!FileAccess::exists(path)) {
return Ref<Texture2D>();
+ }
Ref<Image> img;
img.instance();
@@ -468,12 +475,14 @@ bool EditorScriptPreviewPlugin::handles(const String &p_type) const {
Ref<Texture2D> EditorScriptPreviewPlugin::generate(const RES &p_from, const Size2 &p_size) const {
Ref<Script> scr = p_from;
- if (scr.is_null())
+ if (scr.is_null()) {
return Ref<Texture2D>();
+ }
String code = scr->get_source_code().strip_edges();
- if (code == "")
+ if (code == "") {
return Ref<Texture2D>();
+ }
List<String> kwors;
scr->get_language()->get_reserved_words(&kwors);
@@ -496,8 +505,9 @@ Ref<Texture2D> EditorScriptPreviewPlugin::generate(const RES &p_from, const Size
Color text_color = EditorSettings::get_singleton()->get("text_editor/highlighting/text_color");
Color symbol_color = EditorSettings::get_singleton()->get("text_editor/highlighting/symbol_color");
- if (bg_color.a == 0)
+ if (bg_color.a == 0) {
bg_color = Color(0, 0, 0, 0);
+ }
bg_color.a = MAX(bg_color.a, 0.2); // some background
for (int i = 0; i < thumbnail_size; i++) {
@@ -530,15 +540,17 @@ Ref<Texture2D> EditorScriptPreviewPlugin::generate(const RES &p_from, const Size
pos++;
}
String word = code.substr(i, pos - i);
- if (keywords.has(word))
+ if (keywords.has(word)) {
in_keyword = true;
+ }
} else if (!_is_text_char(c)) {
in_keyword = false;
}
- if (in_keyword)
+ if (in_keyword) {
color = keyword_color;
+ }
Color ul = color;
ul.a *= 0.5;
@@ -554,8 +566,9 @@ Ref<Texture2D> EditorScriptPreviewPlugin::generate(const RES &p_from, const Size
if (c == '\n') {
col = x0;
line++;
- if (line >= available_height / 2)
+ if (line >= available_height / 2) {
break;
+ }
} else if (c == '\t') {
col += 3;
}
@@ -686,8 +699,9 @@ Ref<Texture2D> EditorMeshPreviewPlugin::generate(const RES &p_from, const Size2
xform.basis = Basis().rotated(Vector3(1, 0, 0), Math_PI * 0.125) * xform.basis;
AABB rot_aabb = xform.xform(aabb);
float m = MAX(rot_aabb.size.x, rot_aabb.size.y) * 0.5;
- if (m == 0)
+ if (m == 0) {
return Ref<Texture2D>();
+ }
m = 1.0 / m;
m *= 0.5;
xform.basis.scale(Vector3(m, m, m));
diff --git a/editor/plugins/gi_probe_editor_plugin.cpp b/editor/plugins/gi_probe_editor_plugin.cpp
index 9669853f1b..94f771e643 100644
--- a/editor/plugins/gi_probe_editor_plugin.cpp
+++ b/editor/plugins/gi_probe_editor_plugin.cpp
@@ -50,8 +50,9 @@ void GIProbeEditorPlugin::_bake() {
void GIProbeEditorPlugin::edit(Object *p_object) {
GIProbe *s = Object::cast_to<GIProbe>(p_object);
- if (!s)
+ if (!s) {
return;
+ }
gi_probe = s;
}
diff --git a/editor/plugins/gpu_particles_2d_editor_plugin.cpp b/editor/plugins/gpu_particles_2d_editor_plugin.cpp
index fa97e3dcca..01420dac3e 100644
--- a/editor/plugins/gpu_particles_2d_editor_plugin.cpp
+++ b/editor/plugins/gpu_particles_2d_editor_plugin.cpp
@@ -61,10 +61,11 @@ void GPUParticles2DEditorPlugin::_menu_callback(int p_idx) {
switch (p_idx) {
case MENU_GENERATE_VISIBILITY_RECT: {
float gen_time = particles->get_lifetime();
- if (gen_time < 1.0)
+ if (gen_time < 1.0) {
generate_seconds->set_value(1.0);
- else
+ } else {
generate_seconds->set_value(trunc(gen_time) + 1.0);
+ }
generate_visibility_rect->popup_centered();
} break;
case MENU_LOAD_EMISSION_MASK: {
@@ -118,10 +119,11 @@ void GPUParticles2DEditorPlugin::_generate_visibility_rect() {
OS::get_singleton()->delay_usec(1000);
Rect2 capture = particles->capture_rect();
- if (rect == Rect2())
+ if (rect == Rect2()) {
rect = capture;
- else
+ } else {
rect = rect.merge(capture);
+ }
running += (OS::get_singleton()->get_ticks_usec() - ticks) / 1000000.0;
}
@@ -204,8 +206,9 @@ void GPUParticles2DEditorPlugin::_generate_emission_mask() {
}
}
- if (on_border)
+ if (on_border) {
break;
+ }
}
if (on_border) {
@@ -215,8 +218,9 @@ void GPUParticles2DEditorPlugin::_generate_emission_mask() {
Vector2 normal;
for (int x = i - 2; x <= i + 2; x++) {
for (int y = j - 2; y <= j + 2; y++) {
- if (x == i && y == j)
+ if (x == i && y == j) {
continue;
+ }
if (x < 0 || y < 0 || x >= s.width || y >= s.height || r[(y * s.width + x) * 4 + 3] <= 128) {
normal += Vector2(x - i, y - j).normalized();
diff --git a/editor/plugins/gpu_particles_3d_editor_plugin.cpp b/editor/plugins/gpu_particles_3d_editor_plugin.cpp
index da1bc89e33..fa507dd3d7 100644
--- a/editor/plugins/gpu_particles_3d_editor_plugin.cpp
+++ b/editor/plugins/gpu_particles_3d_editor_plugin.cpp
@@ -44,8 +44,9 @@ bool GPUParticles3DEditorBase::_generate(Vector<Vector3> &points, Vector<Vector3
for (int i = 0; i < geometry.size(); i++) {
float area = geometry[i].get_area();
- if (area < CMP_EPSILON)
+ if (area < CMP_EPSILON) {
continue;
+ }
triangle_area_map[area_accum] = i;
area_accum += area;
}
@@ -92,10 +93,11 @@ bool GPUParticles3DEditorBase::_generate(Vector<Vector3> &points, Vector<Vector3
for (int i = 0; i < gcount; i++) {
for (int j = 0; j < 3; j++) {
- if (i == 0 && j == 0)
+ if (i == 0 && j == 0) {
aabb.position = r[i].vertex[j];
- else
+ } else {
aabb.expand_to(r[i].vertex[j]);
+ }
}
}
@@ -125,15 +127,18 @@ bool GPUParticles3DEditorBase::_generate(Vector<Vector3> &points, Vector<Vector3
res -= ofs;
float d = dir.dot(res);
- if (d < min)
+ if (d < min) {
min = d;
- if (d > max)
+ }
+ if (d > max) {
max = d;
+ }
}
}
- if (max < min)
+ if (max < min) {
continue; //lost attempt
+ }
float val = min + (max - min) * Math::randf();
@@ -150,8 +155,9 @@ bool GPUParticles3DEditorBase::_generate(Vector<Vector3> &points, Vector<Vector3
void GPUParticles3DEditorBase::_node_selected(const NodePath &p_path) {
Node *sel = get_node(p_path);
- if (!sel)
+ if (!sel) {
return;
+ }
if (!sel->is_class("Node3D")) {
EditorNode::get_singleton()->show_warning(vformat(TTR("\"%s\" doesn't inherit from Node3D."), sel->get_name()));
@@ -234,10 +240,11 @@ void GPUParticles3DEditor::_menu_option(int p_option) {
case MENU_OPTION_GENERATE_AABB: {
float gen_time = node->get_lifetime();
- if (gen_time < 1.0)
+ if (gen_time < 1.0) {
generate_seconds->set_value(1.0);
- else
+ } else {
generate_seconds->set_value(trunc(gen_time) + 1.0);
+ }
generate_aabb->popup_centered();
} break;
case MENU_OPTION_CREATE_EMISSION_VOLUME_FROM_NODE: {
@@ -295,10 +302,11 @@ void GPUParticles3DEditor::_generate_aabb() {
OS::get_singleton()->delay_usec(1000);
AABB capture = node->capture_aabb();
- if (rect == AABB())
+ if (rect == AABB()) {
rect = capture;
- else
+ } else {
rect.merge_with(capture);
+ }
running += (OS::get_singleton()->get_ticks_usec() - ticks) / 1000000.0;
}
diff --git a/editor/plugins/gradient_editor_plugin.cpp b/editor/plugins/gradient_editor_plugin.cpp
index 1ccfeccf7a..13b5c8cef5 100644
--- a/editor/plugins/gradient_editor_plugin.cpp
+++ b/editor/plugins/gradient_editor_plugin.cpp
@@ -39,8 +39,9 @@ Size2 GradientEditor::get_minimum_size() const {
}
void GradientEditor::_gradient_changed() {
- if (editing)
+ if (editing) {
return;
+ }
editing = true;
Vector<Gradient::Point> points = gradient->get_points();
diff --git a/editor/plugins/item_list_editor_plugin.cpp b/editor/plugins/item_list_editor_plugin.cpp
index 2829b9bd5b..7402baad57 100644
--- a/editor/plugins/item_list_editor_plugin.cpp
+++ b/editor/plugins/item_list_editor_plugin.cpp
@@ -38,11 +38,11 @@ bool ItemListPlugin::_set(const StringName &p_name, const Variant &p_value) {
int idx = name.get_slice("/", 0).to_int();
String what = name.get_slice("/", 1);
- if (what == "text")
+ if (what == "text") {
set_item_text(idx, p_value);
- else if (what == "icon")
+ } else if (what == "icon") {
set_item_icon(idx, p_value);
- else if (what == "checkable") {
+ } else if (what == "checkable") {
// This keeps compatibility to/from versions where this property was a boolean, before radio buttons
switch ((int)p_value) {
case 0:
@@ -53,16 +53,17 @@ bool ItemListPlugin::_set(const StringName &p_name, const Variant &p_value) {
set_item_radio_checkable(idx, true);
break;
}
- } else if (what == "checked")
+ } else if (what == "checked") {
set_item_checked(idx, p_value);
- else if (what == "id")
+ } else if (what == "id") {
set_item_id(idx, p_value);
- else if (what == "enabled")
+ } else if (what == "enabled") {
set_item_enabled(idx, p_value);
- else if (what == "separator")
+ } else if (what == "separator") {
set_item_separator(idx, p_value);
- else
+ } else {
return false;
+ }
return true;
}
@@ -72,27 +73,28 @@ bool ItemListPlugin::_get(const StringName &p_name, Variant &r_ret) const {
int idx = name.get_slice("/", 0).to_int();
String what = name.get_slice("/", 1);
- if (what == "text")
+ if (what == "text") {
r_ret = get_item_text(idx);
- else if (what == "icon")
+ } else if (what == "icon") {
r_ret = get_item_icon(idx);
- else if (what == "checkable") {
+ } else if (what == "checkable") {
// This keeps compatibility to/from versions where this property was a boolean, before radio buttons
if (!is_item_checkable(idx)) {
r_ret = 0;
} else {
r_ret = is_item_radio_checkable(idx) ? 2 : 1;
}
- } else if (what == "checked")
+ } else if (what == "checked") {
r_ret = is_item_checked(idx);
- else if (what == "id")
+ } else if (what == "id") {
r_ret = get_item_id(idx);
- else if (what == "enabled")
+ } else if (what == "enabled") {
r_ret = is_item_enabled(idx);
- else if (what == "separator")
+ } else if (what == "separator") {
r_ret = is_item_separator(idx);
- else
+ } else {
return false;
+ }
return true;
}
@@ -111,14 +113,17 @@ void ItemListPlugin::_get_property_list(List<PropertyInfo> *p_list) const {
p_list->push_back(PropertyInfo(Variant::BOOL, base + "checked"));
}
- if (flags & FLAG_ID)
+ if (flags & FLAG_ID) {
p_list->push_back(PropertyInfo(Variant::INT, base + "id", PROPERTY_HINT_RANGE, "-1,4096"));
+ }
- if (flags & FLAG_ENABLE)
+ if (flags & FLAG_ENABLE) {
p_list->push_back(PropertyInfo(Variant::BOOL, base + "enabled"));
+ }
- if (flags & FLAG_SEPARATOR)
+ if (flags & FLAG_SEPARATOR) {
p_list->push_back(PropertyInfo(Variant::BOOL, base + "separator"));
+ }
}
}
@@ -159,10 +164,11 @@ ItemListOptionButtonPlugin::ItemListOptionButtonPlugin() {
///////////////////////////////////////////////////////////////
void ItemListPopupMenuPlugin::set_object(Object *p_object) {
- if (p_object->is_class("MenuButton"))
+ if (p_object->is_class("MenuButton")) {
pp = Object::cast_to<MenuButton>(p_object)->get_popup();
- else
+ } else {
pp = Object::cast_to<PopupMenu>(p_object);
+ }
}
bool ItemListPopupMenuPlugin::handles(Object *p_object) const {
@@ -245,20 +251,23 @@ void ItemListEditor::_notification(int p_notification) {
}
void ItemListEditor::_add_pressed() {
- if (selected_idx == -1)
+ if (selected_idx == -1) {
return;
+ }
item_plugins[selected_idx]->add_item();
}
void ItemListEditor::_delete_pressed() {
- if (selected_idx == -1)
+ if (selected_idx == -1) {
return;
+ }
String current_selected = (String)property_editor->get_selected_path();
- if (current_selected == "")
+ if (current_selected == "") {
return;
+ }
// FIXME: Currently relying on selecting a *property* to derive what item to delete
// e.g. you select "1/enabled" to delete item 1.
@@ -351,8 +360,9 @@ ItemListEditor::ItemListEditor() {
}
ItemListEditor::~ItemListEditor() {
- for (int i = 0; i < item_plugins.size(); i++)
+ for (int i = 0; i < item_plugins.size(); i++) {
memdelete(item_plugins[i]);
+ }
}
void ItemListEditorPlugin::edit(Object *p_object) {
diff --git a/editor/plugins/light_occluder_2d_editor_plugin.cpp b/editor/plugins/light_occluder_2d_editor_plugin.cpp
index 0cbb3f5d9d..e422140efa 100644
--- a/editor/plugins/light_occluder_2d_editor_plugin.cpp
+++ b/editor/plugins/light_occluder_2d_editor_plugin.cpp
@@ -49,26 +49,29 @@ void LightOccluder2DEditor::_set_node(Node *p_polygon) {
bool LightOccluder2DEditor::_is_line() const {
Ref<OccluderPolygon2D> occluder = node->get_occluder_polygon();
- if (occluder.is_valid())
+ if (occluder.is_valid()) {
return !occluder->is_closed();
- else
+ } else {
return false;
+ }
}
int LightOccluder2DEditor::_get_polygon_count() const {
Ref<OccluderPolygon2D> occluder = node->get_occluder_polygon();
- if (occluder.is_valid())
+ if (occluder.is_valid()) {
return occluder->get_polygon().size();
- else
+ } else {
return 0;
+ }
}
Variant LightOccluder2DEditor::_get_polygon(int p_idx) const {
Ref<OccluderPolygon2D> occluder = node->get_occluder_polygon();
- if (occluder.is_valid())
+ if (occluder.is_valid()) {
return occluder->get_polygon();
- else
+ } else {
return Variant(Vector<Vector2>());
+ }
}
void LightOccluder2DEditor::_set_polygon(int p_idx, const Variant &p_polygon) const {
@@ -87,8 +90,9 @@ bool LightOccluder2DEditor::_has_resource() const {
}
void LightOccluder2DEditor::_create_resource() {
- if (!node)
+ if (!node) {
return;
+ }
undo_redo->create_action(TTR("Create Occluder Polygon"));
undo_redo->add_do_method(node, "set_occluder_polygon", Ref<OccluderPolygon2D>(memnew(OccluderPolygon2D)));
diff --git a/editor/plugins/material_editor_plugin.cpp b/editor/plugins/material_editor_plugin.cpp
index 992f080cec..e49cfd51f7 100644
--- a/editor/plugins/material_editor_plugin.cpp
+++ b/editor/plugins/material_editor_plugin.cpp
@@ -203,8 +203,9 @@ MaterialEditor::MaterialEditor() {
bool EditorInspectorPluginMaterial::can_handle(Object *p_object) {
Material *material = Object::cast_to<Material>(p_object);
- if (!material)
+ if (!material) {
return false;
+ }
return material->get_shader_mode() == Shader::MODE_SPATIAL;
}
diff --git a/editor/plugins/mesh_editor_plugin.cpp b/editor/plugins/mesh_editor_plugin.cpp
index 7ac44cf53a..9d396467c3 100644
--- a/editor/plugins/mesh_editor_plugin.cpp
+++ b/editor/plugins/mesh_editor_plugin.cpp
@@ -37,9 +37,9 @@ void MeshEditor::_gui_input(Ref<InputEvent> p_event) {
if (mm.is_valid() && mm->get_button_mask() & BUTTON_MASK_LEFT) {
rot_x -= mm->get_relative().y * 0.01;
rot_y -= mm->get_relative().x * 0.01;
- if (rot_x < -Math_PI / 2)
+ if (rot_x < -Math_PI / 2) {
rot_x = -Math_PI / 2;
- else if (rot_x > Math_PI / 2) {
+ } else if (rot_x > Math_PI / 2) {
rot_x = Math_PI / 2;
}
_update_rotation();
diff --git a/editor/plugins/mesh_instance_3d_editor_plugin.cpp b/editor/plugins/mesh_instance_3d_editor_plugin.cpp
index 3c1554de27..1b65987af0 100644
--- a/editor/plugins/mesh_instance_3d_editor_plugin.cpp
+++ b/editor/plugins/mesh_instance_3d_editor_plugin.cpp
@@ -92,16 +92,19 @@ void MeshInstance3DEditor::_menu_option(int p_option) {
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
MeshInstance3D *instance = Object::cast_to<MeshInstance3D>(E->get());
- if (!instance)
+ if (!instance) {
continue;
+ }
Ref<Mesh> m = instance->get_mesh();
- if (m.is_null())
+ if (m.is_null()) {
continue;
+ }
Ref<Shape3D> shape = m->create_trimesh_shape();
- if (shape.is_null())
+ if (shape.is_null()) {
continue;
+ }
CollisionShape3D *cshape = memnew(CollisionShape3D);
cshape->set_shape(shape);
@@ -129,8 +132,9 @@ void MeshInstance3DEditor::_menu_option(int p_option) {
}
Ref<Shape3D> shape = mesh->create_trimesh_shape();
- if (shape.is_null())
+ if (shape.is_null()) {
return;
+ }
CollisionShape3D *cshape = memnew(CollisionShape3D);
cshape->set_shape(shape);
@@ -219,8 +223,9 @@ void MeshInstance3DEditor::_menu_option(int p_option) {
case MENU_OPTION_CREATE_NAVMESH: {
Ref<NavigationMesh> nmesh = memnew(NavigationMesh);
- if (nmesh.is_null())
+ if (nmesh.is_null()) {
return;
+ }
nmesh->create_from_mesh(mesh);
NavigationRegion3D *nmi = memnew(NavigationRegion3D);
@@ -284,10 +289,11 @@ struct MeshInstance3DEditorEdgeSort {
Vector2 b;
bool operator<(const MeshInstance3DEditorEdgeSort &p_b) const {
- if (a == p_b.a)
+ if (a == p_b.a) {
return b < p_b.b;
- else
+ } else {
return a < p_b.a;
+ }
}
MeshInstance3DEditorEdgeSort() {}
@@ -309,8 +315,9 @@ void MeshInstance3DEditor::_create_uv_lines(int p_layer) {
Set<MeshInstance3DEditorEdgeSort> edges;
uv_lines.clear();
for (int i = 0; i < mesh->get_surface_count(); i++) {
- if (mesh->surface_get_primitive_type(i) != Mesh::PRIMITIVE_TRIANGLES)
+ if (mesh->surface_get_primitive_type(i) != Mesh::PRIMITIVE_TRIANGLES) {
continue;
+ }
Array a = mesh->surface_get_arrays(i);
Vector<Vector2> uv = a[p_layer == 0 ? Mesh::ARRAY_TEX_UV : Mesh::ARRAY_TEX_UV2];
@@ -345,8 +352,9 @@ void MeshInstance3DEditor::_create_uv_lines(int p_layer) {
edge.b = r[j + ((k + 1) % 3)];
}
- if (edges.has(edge))
+ if (edges.has(edge)) {
continue;
+ }
uv_lines.push_back(edge.a);
uv_lines.push_back(edge.b);
@@ -359,8 +367,9 @@ void MeshInstance3DEditor::_create_uv_lines(int p_layer) {
}
void MeshInstance3DEditor::_debug_uv_draw() {
- if (uv_lines.size() == 0)
+ if (uv_lines.size() == 0) {
return;
+ }
debug_uv->set_clip_contents(true);
debug_uv->draw_rect(Rect2(Vector2(), debug_uv->get_size()), Color(0.2, 0.2, 0.0));
diff --git a/editor/plugins/mesh_library_editor_plugin.cpp b/editor/plugins/mesh_library_editor_plugin.cpp
index 30ffba0db4..7690beeee8 100644
--- a/editor/plugins/mesh_library_editor_plugin.cpp
+++ b/editor/plugins/mesh_library_editor_plugin.cpp
@@ -42,8 +42,9 @@
void MeshLibraryEditor::edit(const Ref<MeshLibrary> &p_mesh_library) {
mesh_library = p_mesh_library;
- if (mesh_library.is_valid())
+ if (mesh_library.is_valid()) {
menu->get_popup()->set_item_disabled(menu->get_popup()->get_item_index(MENU_OPTION_UPDATE_FROM_SCENE), !mesh_library->has_meta("_editor_source_scene"));
+ }
}
void MeshLibraryEditor::_menu_confirm() {
@@ -63,8 +64,9 @@ void MeshLibraryEditor::_menu_confirm() {
}
void MeshLibraryEditor::_import_scene(Node *p_scene, Ref<MeshLibrary> p_library, bool p_merge) {
- if (!p_merge)
+ if (!p_merge) {
p_library->clear();
+ }
Map<int, MeshInstance3D *> mesh_instances;
@@ -78,14 +80,16 @@ void MeshLibraryEditor::_import_scene(Node *p_scene, Ref<MeshLibrary> p_library,
continue;
}
- } else
+ } else {
continue;
+ }
}
MeshInstance3D *mi = Object::cast_to<MeshInstance3D>(child);
Ref<Mesh> mesh = mi->get_mesh();
- if (mesh.is_null())
+ if (mesh.is_null()) {
continue;
+ }
mesh = mesh->duplicate();
for (int j = 0; j < mesh->get_surface_count(); ++j) {
@@ -110,16 +114,18 @@ void MeshLibraryEditor::_import_scene(Node *p_scene, Ref<MeshLibrary> p_library,
for (int j = 0; j < mi->get_child_count(); j++) {
Node *child2 = mi->get_child(j);
- if (!Object::cast_to<StaticBody3D>(child2))
+ if (!Object::cast_to<StaticBody3D>(child2)) {
continue;
+ }
StaticBody3D *sb = Object::cast_to<StaticBody3D>(child2);
List<uint32_t> shapes;
sb->get_shape_owners(&shapes);
for (List<uint32_t>::Element *E = shapes.front(); E; E = E->next()) {
- if (sb->is_shape_owner_disabled(E->get()))
+ if (sb->is_shape_owner_disabled(E->get())) {
continue;
+ }
//Transform shape_transform = sb->shape_owner_get_transform(E->get());
@@ -127,8 +133,9 @@ void MeshLibraryEditor::_import_scene(Node *p_scene, Ref<MeshLibrary> p_library,
for (int k = 0; k < sb->shape_owner_get_shape_count(E->get()); k++) {
Ref<Shape3D> collision = sb->shape_owner_get_shape(E->get(), k);
- if (!collision.is_valid())
+ if (!collision.is_valid()) {
continue;
+ }
MeshLibrary::ShapeData shape_data;
shape_data.shape = collision;
shape_data.local_transform = sb->get_transform() * sb->shape_owner_get_transform(E->get());
@@ -143,13 +150,15 @@ void MeshLibraryEditor::_import_scene(Node *p_scene, Ref<MeshLibrary> p_library,
Transform navmesh_transform;
for (int j = 0; j < mi->get_child_count(); j++) {
Node *child2 = mi->get_child(j);
- if (!Object::cast_to<NavigationRegion3D>(child2))
+ if (!Object::cast_to<NavigationRegion3D>(child2)) {
continue;
+ }
NavigationRegion3D *sb = Object::cast_to<NavigationRegion3D>(child2);
navmesh = sb->get_navigation_mesh();
navmesh_transform = sb->get_transform();
- if (!navmesh.is_null())
+ if (!navmesh.is_null()) {
break;
+ }
}
if (!navmesh.is_null()) {
p_library->set_item_navmesh(id, navmesh);
@@ -265,8 +274,9 @@ void MeshLibraryEditorPlugin::edit(Object *p_node) {
if (Object::cast_to<MeshLibrary>(p_node)) {
mesh_library_editor->edit(Object::cast_to<MeshLibrary>(p_node));
mesh_library_editor->show();
- } else
+ } else {
mesh_library_editor->hide();
+ }
}
bool MeshLibraryEditorPlugin::handles(Object *p_node) const {
diff --git a/editor/plugins/multimesh_editor_plugin.cpp b/editor/plugins/multimesh_editor_plugin.cpp
index 9d4442174c..3904389e09 100644
--- a/editor/plugins/multimesh_editor_plugin.cpp
+++ b/editor/plugins/multimesh_editor_plugin.cpp
@@ -42,8 +42,9 @@ void MultiMeshEditor::_node_removed(Node *p_node) {
}
void MultiMeshEditor::_populate() {
- if (!node)
+ if (!node) {
return;
+ }
Ref<Mesh> mesh;
@@ -141,8 +142,9 @@ void MultiMeshEditor::_populate() {
Map<float, int> triangle_area_map;
for (int i = 0; i < facecount; i++) {
float area = r[i].get_area();
- if (area < CMP_EPSILON)
+ if (area < CMP_EPSILON) {
continue;
+ }
triangle_area_map[area_accum] = i;
area_accum += area;
}
@@ -214,10 +216,11 @@ void MultiMeshEditor::_populate() {
void MultiMeshEditor::_browsed(const NodePath &p_path) {
NodePath path = node->get_path_to(get_node(p_path));
- if (browsing_source)
+ if (browsing_source) {
mesh_source->set_text(path);
- else
+ } else {
surface_source->set_text(path);
+ }
}
void MultiMeshEditor::_menu_option(int p_option) {
@@ -249,10 +252,11 @@ void MultiMeshEditor::_browse(bool p_source) {
browsing_source = p_source;
std->get_scene_tree()->set_marked(node, false);
std->popup_centered_ratio();
- if (p_source)
+ if (p_source) {
std->set_title(TTR("Select a Source Mesh:"));
- else
+ } else {
std->set_title(TTR("Select a Target Surface:"));
+ }
}
void MultiMeshEditor::_bind_methods() {
diff --git a/editor/plugins/navigation_polygon_editor_plugin.cpp b/editor/plugins/navigation_polygon_editor_plugin.cpp
index d4cc96b7df..8cf9f01fa0 100644
--- a/editor/plugins/navigation_polygon_editor_plugin.cpp
+++ b/editor/plugins/navigation_polygon_editor_plugin.cpp
@@ -49,18 +49,20 @@ void NavigationPolygonEditor::_set_node(Node *p_polygon) {
int NavigationPolygonEditor::_get_polygon_count() const {
Ref<NavigationPolygon> navpoly = node->get_navigation_polygon();
- if (navpoly.is_valid())
+ if (navpoly.is_valid()) {
return navpoly->get_outline_count();
- else
+ } else {
return 0;
+ }
}
Variant NavigationPolygonEditor::_get_polygon(int p_idx) const {
Ref<NavigationPolygon> navpoly = node->get_navigation_polygon();
- if (navpoly.is_valid())
+ if (navpoly.is_valid()) {
return navpoly->get_outline(p_idx);
- else
+ } else {
return Variant(Vector<Vector2>());
+ }
}
void NavigationPolygonEditor::_set_polygon(int p_idx, const Variant &p_polygon) const {
@@ -98,8 +100,9 @@ bool NavigationPolygonEditor::_has_resource() const {
}
void NavigationPolygonEditor::_create_resource() {
- if (!node)
+ if (!node) {
return;
+ }
undo_redo->create_action(TTR("Create Navigation Polygon"));
undo_redo->add_do_method(node, "set_navigation_polygon", Ref<NavigationPolygon>(memnew(NavigationPolygon)));
diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp
index bfdd148e3f..3c12022854 100644
--- a/editor/plugins/node_3d_editor_plugin.cpp
+++ b/editor/plugins/node_3d_editor_plugin.cpp
@@ -364,10 +364,11 @@ Transform Node3DEditorViewport::to_camera_transform(const Cursor &p_cursor) cons
camera_transform.basis.rotate(Vector3(1, 0, 0), -p_cursor.x_rot);
camera_transform.basis.rotate(Vector3(0, 1, 0), -p_cursor.y_rot);
- if (orthogonal)
+ if (orthogonal) {
camera_transform.translate(0, 0, (get_zfar() - get_znear()) / 2.0);
- else
+ } else {
camera_transform.translate(0, 0, p_cursor.distance);
+ }
return camera_transform;
}
@@ -379,12 +380,14 @@ int Node3DEditorViewport::get_selected_count() const {
for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) {
Node3D *sp = Object::cast_to<Node3D>(E->key());
- if (!sp)
+ if (!sp) {
continue;
+ }
Node3DEditorSelectedItem *se = editor_selection->get_node_editor_data<Node3DEditorSelectedItem>(sp);
- if (!se)
+ if (!se) {
continue;
+ }
count++;
}
@@ -433,13 +436,15 @@ void Node3DEditorViewport::_clear_selected() {
}
void Node3DEditorViewport::_select_clicked(bool p_append, bool p_single, bool p_allow_locked) {
- if (clicked.is_null())
+ if (clicked.is_null()) {
return;
+ }
Node *node = Object::cast_to<Node>(ObjectDB::get_instance(clicked));
Node3D *selected = Object::cast_to<Node3D>(node);
- if (!selected)
+ if (!selected) {
return;
+ }
if (!p_allow_locked) {
// Replace the node by the group if grouped
@@ -470,14 +475,16 @@ void Node3DEditorViewport::_select(Node *p_node, bool p_append, bool p_single) {
}
if (p_single) {
- if (Engine::get_singleton()->is_editor_hint())
+ if (Engine::get_singleton()->is_editor_hint()) {
editor->call("edit_node", p_node);
+ }
}
}
ObjectID Node3DEditorViewport::_select_ray(const Point2 &p_pos, bool p_append, bool &r_includes_current, int *r_gizmo_handle, bool p_alt_select) {
- if (r_gizmo_handle)
+ if (r_gizmo_handle) {
*r_gizmo_handle = -1;
+ }
Vector3 ray = _get_ray(p_pos);
Vector3 pos = _get_ray_pos(p_pos);
@@ -495,8 +502,9 @@ ObjectID Node3DEditorViewport::_select_ray(const Point2 &p_pos, bool p_append, b
for (int i = 0; i < instances.size(); i++) {
Node3D *spat = Object::cast_to<Node3D>(ObjectDB::get_instance(instances[i]));
- if (!spat)
+ if (!spat) {
continue;
+ }
Ref<EditorNode3DGizmo> seg = spat->get_gizmo();
@@ -511,13 +519,15 @@ ObjectID Node3DEditorViewport::_select_ray(const Point2 &p_pos, bool p_append, b
int handle = -1;
bool inters = seg->intersect_ray(camera, shrinked_pos, point, normal, &handle, p_alt_select);
- if (!inters)
+ if (!inters) {
continue;
+ }
float dist = pos.distance_to(point);
- if (dist < 0)
+ if (dist < 0) {
continue;
+ }
if (dist < closest_dist) {
item = Object::cast_to<Node>(spat);
@@ -531,12 +541,14 @@ ObjectID Node3DEditorViewport::_select_ray(const Point2 &p_pos, bool p_append, b
}
}
- if (!item)
+ if (!item) {
return ObjectID();
+ }
if (!editor_selection->is_selected(item) || (r_gizmo_handle && selected_handle >= 0)) {
- if (r_gizmo_handle)
+ if (r_gizmo_handle) {
*r_gizmo_handle = selected_handle;
+ }
}
return closest;
@@ -554,16 +566,19 @@ void Node3DEditorViewport::_find_items_at_pos(const Point2 &p_pos, bool &r_inclu
for (int i = 0; i < instances.size(); i++) {
Node3D *spat = Object::cast_to<Node3D>(ObjectDB::get_instance(instances[i]));
- if (!spat)
+ if (!spat) {
continue;
+ }
Ref<EditorNode3DGizmo> seg = spat->get_gizmo();
- if (!seg.is_valid())
+ if (!seg.is_valid()) {
continue;
+ }
- if (found_gizmos.has(seg))
+ if (found_gizmos.has(seg)) {
continue;
+ }
found_gizmos.insert(seg);
Vector3 point;
@@ -572,16 +587,19 @@ void Node3DEditorViewport::_find_items_at_pos(const Point2 &p_pos, bool &r_inclu
int handle = -1;
bool inters = seg->intersect_ray(camera, p_pos, point, normal, nullptr, p_alt_select);
- if (!inters)
+ if (!inters) {
continue;
+ }
float dist = pos.distance_to(point);
- if (dist < 0)
+ if (dist < 0) {
continue;
+ }
- if (editor_selection->is_selected(spat))
+ if (editor_selection->is_selected(spat)) {
r_includes_current = true;
+ }
_RayResult res;
res.item = spat;
@@ -590,8 +608,9 @@ void Node3DEditorViewport::_find_items_at_pos(const Point2 &p_pos, bool &r_inclu
results.push_back(res);
}
- if (results.empty())
+ if (results.empty()) {
return;
+ }
results.sort();
}
@@ -615,8 +634,9 @@ Vector3 Node3DEditorViewport::_get_screen_to_space(const Vector3 &p_vector3) {
}
void Node3DEditorViewport::_select_region() {
- if (cursor.region_begin == cursor.region_end)
+ if (cursor.region_begin == cursor.region_end) {
return; //nothing really
+ }
float z_offset = MAX(0.0, 5.0 - get_znear());
@@ -668,8 +688,9 @@ void Node3DEditorViewport::_select_region() {
for (int i = 0; i < instances.size(); i++) {
Node3D *sp = Object::cast_to<Node3D>(ObjectDB::get_instance(instances[i]));
- if (!sp || _is_node_locked(sp))
+ if (!sp || _is_node_locked(sp)) {
continue;
+ }
Node *item = Object::cast_to<Node>(sp);
while (item->get_owner() && item->get_owner() != edited_scene && !edited_scene->is_editable_instance(item->get_owner())) {
@@ -689,16 +710,19 @@ void Node3DEditorViewport::_select_region() {
item = sel;
}
- if (selected.find(item) != -1)
+ if (selected.find(item) != -1) {
continue;
+ }
- if (_is_node_locked(item))
+ if (_is_node_locked(item)) {
continue;
+ }
Ref<EditorNode3DGizmo> seg = sp->get_gizmo();
- if (!seg.is_valid())
+ if (!seg.is_valid()) {
continue;
+ }
if (seg->intersect_frustum(camera, frustum)) {
selected.push_back(item);
@@ -718,10 +742,11 @@ void Node3DEditorViewport::_update_name() {
view_mode += " [auto]";
}
- if (name != "")
+ if (name != "") {
view_menu->set_text(name + " " + view_mode);
- else
+ } else {
view_menu->set_text(view_mode);
+ }
view_menu->set_size(Vector2(0, 0)); // resets the button size
}
@@ -737,12 +762,14 @@ void Node3DEditorViewport::_compute_edit(const Point2 &p_point) {
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
Node3D *sp = Object::cast_to<Node3D>(E->get());
- if (!sp)
+ if (!sp) {
continue;
+ }
Node3DEditorSelectedItem *se = editor_selection->get_node_editor_data<Node3DEditorSelectedItem>(sp);
- if (!se)
+ if (!se) {
continue;
+ }
se->original = se->sp->get_global_gizmo_transform();
se->original_local = se->sp->get_local_gizmo_transform();
@@ -766,23 +793,29 @@ static int _get_key_modifier_setting(const String &p_property) {
}
static int _get_key_modifier(Ref<InputEventWithModifiers> e) {
- if (e->get_shift())
+ if (e->get_shift()) {
return KEY_SHIFT;
- if (e->get_alt())
+ }
+ if (e->get_alt()) {
return KEY_ALT;
- if (e->get_control())
+ }
+ if (e->get_control()) {
return KEY_CONTROL;
- if (e->get_metakey())
+ }
+ if (e->get_metakey()) {
return KEY_META;
+ }
return 0;
}
bool Node3DEditorViewport::_gizmo_select(const Vector2 &p_screenpos, bool p_highlight_only) {
- if (!spatial_editor->is_gizmo_visible())
+ if (!spatial_editor->is_gizmo_visible()) {
return false;
+ }
if (get_selected_count() == 0) {
- if (p_highlight_only)
+ if (p_highlight_only) {
spatial_editor->select_gizmo_highlight_axis(-1);
+ }
return false;
}
@@ -861,8 +894,9 @@ bool Node3DEditorViewport::_gizmo_select(const Vector2 &p_screenpos, bool p_high
for (int i = 0; i < 3; i++) {
Plane plane(gt.origin, gt.basis.get_axis(i).normalized());
Vector3 r;
- if (!plane.intersects_ray(ray_pos, ray, &r))
+ if (!plane.intersects_ray(ray_pos, ray, &r)) {
continue;
+ }
float dist = r.distance_to(gt.origin);
@@ -950,15 +984,17 @@ bool Node3DEditorViewport::_gizmo_select(const Vector2 &p_screenpos, bool p_high
}
}
- if (p_highlight_only)
+ if (p_highlight_only) {
spatial_editor->select_gizmo_highlight_axis(-1);
+ }
return false;
}
void Node3DEditorViewport::_surface_mouse_enter() {
- if (!surface->has_focus() && (!get_focus_owner() || !get_focus_owner()->is_text_field()))
+ if (!surface->has_focus() && (!get_focus_owner() || !get_focus_owner()->is_text_field())) {
surface->grab_focus();
+ }
}
void Node3DEditorViewport::_surface_mouse_exit() {
@@ -1047,16 +1083,18 @@ void Node3DEditorViewport::_list_select(Ref<InputEventMouseButton> b) {
}
void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
- if (previewing)
+ if (previewing) {
return; //do NONE
+ }
{
EditorNode *en = editor;
EditorPluginList *force_input_forwarding_list = en->get_editor_plugins_force_input_forwarding();
if (!force_input_forwarding_list->empty()) {
bool discard = force_input_forwarding_list->forward_spatial_gui_input(camera, p_event, true);
- if (discard)
+ if (discard) {
return;
+ }
}
}
{
@@ -1064,8 +1102,9 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
EditorPluginList *over_plugin_list = en->get_editor_plugins_over();
if (!over_plugin_list->empty()) {
bool discard = over_plugin_list->forward_spatial_gui_input(camera, p_event, false);
- if (discard)
+ if (discard) {
return;
+ }
}
}
@@ -1077,17 +1116,19 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
float zoom_factor = 1 + (ZOOM_MULTIPLIER - 1) * b->get_factor();
switch (b->get_button_index()) {
case BUTTON_WHEEL_UP: {
- if (is_freelook_active())
+ if (is_freelook_active()) {
scale_freelook_speed(zoom_factor);
- else
+ } else {
scale_cursor_distance(1.0 / zoom_factor);
+ }
} break;
case BUTTON_WHEEL_DOWN: {
- if (is_freelook_active())
+ if (is_freelook_active()) {
scale_freelook_speed(1.0 / zoom_factor);
- else
+ } else {
scale_cursor_distance(zoom_factor);
+ }
} break;
case BUTTON_RIGHT: {
@@ -1101,8 +1142,9 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
if (_edit.mode == TRANSFORM_NONE && b->is_pressed()) {
if (b->get_alt()) {
- if (nav_scheme == NAVIGATION_MAYA)
+ if (nav_scheme == NAVIGATION_MAYA) {
break;
+ }
_list_select(b);
return;
@@ -1117,12 +1159,14 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
Node3D *sp = Object::cast_to<Node3D>(E->get());
- if (!sp)
+ if (!sp) {
continue;
+ }
Node3DEditorSelectedItem *se = editor_selection->get_node_editor_data<Node3DEditorSelectedItem>(sp);
- if (!se)
+ if (!se) {
continue;
+ }
sp->set_global_transform(se->original);
}
@@ -1220,16 +1264,18 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
}
}
- if (_gizmo_select(_edit.mouse_pos))
+ if (_gizmo_select(_edit.mouse_pos)) {
break;
+ }
clicked = ObjectID();
clicked_includes_current = false;
if ((spatial_editor->get_tool_mode() == Node3DEditor::TOOL_MODE_SELECT && b->get_control()) || spatial_editor->get_tool_mode() == Node3DEditor::TOOL_MODE_ROTATE) {
/* HANDLE ROTATION */
- if (get_selected_count() == 0)
+ if (get_selected_count() == 0) {
break; //bye
+ }
//handle rotate
_edit.mode = TRANSFORM_ROTATE;
_compute_edit(b->get_position());
@@ -1237,8 +1283,9 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
}
if (spatial_editor->get_tool_mode() == Node3DEditor::TOOL_MODE_MOVE) {
- if (get_selected_count() == 0)
+ if (get_selected_count() == 0) {
break; //bye
+ }
//handle translate
_edit.mode = TRANSFORM_TRANSLATE;
_compute_edit(b->get_position());
@@ -1246,8 +1293,9 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
}
if (spatial_editor->get_tool_mode() == Node3DEditor::TOOL_MODE_SCALE) {
- if (get_selected_count() == 0)
+ if (get_selected_count() == 0) {
break; //bye
+ }
//handle scale
_edit.mode = TRANSFORM_SCALE;
_compute_edit(b->get_position());
@@ -1265,8 +1313,9 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
clicked_wants_append = b->get_shift();
if (clicked.is_null()) {
- if (!clicked_wants_append)
+ if (!clicked_wants_append) {
_clear_selected();
+ }
//default to regionselect
cursor.region_select = true;
@@ -1301,8 +1350,9 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
}
if (cursor.region_select) {
- if (!clicked_wants_append)
+ if (!clicked_wants_append) {
_clear_selected();
+ }
_select_region();
cursor.region_select = false;
@@ -1317,12 +1367,14 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
Node3D *sp = Object::cast_to<Node3D>(E->get());
- if (!sp)
+ if (!sp) {
continue;
+ }
Node3DEditorSelectedItem *se = editor_selection->get_node_editor_data<Node3DEditorSelectedItem>(sp);
- if (!se)
+ if (!se) {
continue;
+ }
undo_redo->add_do_method(sp, "set_global_transform", sp->get_global_gizmo_transform());
undo_redo->add_undo_method(sp, "set_global_transform", se->original);
@@ -1360,8 +1412,9 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
if (selected_handle != spatial_editor->get_over_gizmo_handle()) {
spatial_editor->set_over_gizmo_handle(selected_handle);
spatial_editor->get_selected()->update_gizmo();
- if (selected_handle != -1)
+ if (selected_handle != -1) {
spatial_editor->select_gizmo_highlight_axis(-1);
+ }
}
}
}
@@ -1407,8 +1460,9 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
return;
}
- if (_edit.mode == TRANSFORM_NONE)
+ if (_edit.mode == TRANSFORM_NONE) {
return;
+ }
Vector3 ray_pos = _get_ray_pos(m->get_position());
Vector3 ray = _get_ray(m->get_position());
@@ -1456,12 +1510,14 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
}
Vector3 intersection;
- if (!plane.intersects_ray(ray_pos, ray, &intersection))
+ if (!plane.intersects_ray(ray_pos, ray, &intersection)) {
break;
+ }
Vector3 click;
- if (!plane.intersects_ray(_edit.click_ray_pos, _edit.click_ray, &click))
+ if (!plane.intersects_ray(_edit.click_ray_pos, _edit.click_ray, &click)) {
break;
+ }
Vector3 motion = intersection - click;
if (_edit.plane != TRANSFORM_VIEW) {
@@ -1478,8 +1534,9 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
} else {
float center_click_dist = click.distance_to(_edit.center);
float center_inters_dist = intersection.distance_to(_edit.center);
- if (center_click_dist == 0)
+ if (center_click_dist == 0) {
break;
+ }
float scale = center_inters_dist - center_click_dist;
motion = Vector3(scale, scale, scale);
@@ -1592,12 +1649,14 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
}
Vector3 intersection;
- if (!plane.intersects_ray(ray_pos, ray, &intersection))
+ if (!plane.intersects_ray(ray_pos, ray, &intersection)) {
break;
+ }
Vector3 click;
- if (!plane.intersects_ray(_edit.click_ray_pos, _edit.click_ray, &click))
+ if (!plane.intersects_ray(_edit.click_ray_pos, _edit.click_ray, &click)) {
break;
+ }
Vector3 motion = intersection - click;
if (_edit.plane != TRANSFORM_VIEW) {
@@ -1689,12 +1748,14 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
}
Vector3 intersection;
- if (!plane.intersects_ray(ray_pos, ray, &intersection))
+ if (!plane.intersects_ray(ray_pos, ray, &intersection)) {
break;
+ }
Vector3 click;
- if (!plane.intersects_ray(_edit.click_ray_pos, _edit.click_ray, &click))
+ if (!plane.intersects_ray(_edit.click_ray_pos, _edit.click_ray, &click)) {
break;
+ }
Vector3 y_axis = (click - _edit.center).normalized();
Vector3 x_axis = plane.normal.cross(y_axis).normalized();
@@ -1715,12 +1776,14 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
Node3D *sp = Object::cast_to<Node3D>(E->get());
- if (!sp)
+ if (!sp) {
continue;
+ }
Node3DEditorSelectedItem *se = editor_selection->get_node_editor_data<Node3DEditorSelectedItem>(sp);
- if (!se)
+ if (!se) {
continue;
+ }
if (sp->has_meta("_edit_lock_")) {
continue;
@@ -1783,8 +1846,9 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
}
} else if (nav_scheme == NAVIGATION_MAYA) {
- if (m->get_alt())
+ if (m->get_alt()) {
nav_mode = NAVIGATION_PAN;
+ }
}
} else if (EditorSettings::get_singleton()->get("editors/3d/navigation/emulate_3_button_mouse")) {
@@ -1831,10 +1895,11 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
Ref<InputEventMagnifyGesture> magnify_gesture = p_event;
if (magnify_gesture.is_valid()) {
- if (is_freelook_active())
+ if (is_freelook_active()) {
scale_freelook_speed(magnify_gesture->get_factor());
- else
+ } else {
scale_cursor_distance(1.0 / magnify_gesture->get_factor());
+ }
}
Ref<InputEventPanGesture> pan_gesture = p_event;
@@ -1855,8 +1920,9 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
}
} else if (nav_scheme == NAVIGATION_MAYA) {
- if (pan_gesture->get_alt())
+ if (pan_gesture->get_alt()) {
nav_mode = NAVIGATION_PAN;
+ }
}
switch (nav_mode) {
@@ -1888,8 +1954,9 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
Ref<InputEventKey> k = p_event;
if (k.is_valid()) {
- if (!k->is_pressed())
+ if (!k->is_pressed()) {
return;
+ }
if (ED_IS_SHORTCUT("spatial_editor/snap", p_event)) {
if (_edit.mode != TRANSFORM_NONE) {
@@ -1932,8 +1999,9 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
_menu_option(VIEW_ALIGN_ROTATION_WITH_VIEW);
}
if (ED_IS_SHORTCUT("spatial_editor/insert_anim_key", p_event)) {
- if (!get_selected_count() || _edit.mode != TRANSFORM_NONE)
+ if (!get_selected_count() || _edit.mode != TRANSFORM_NONE) {
return;
+ }
if (!AnimationPlayerEditor::singleton->get_track_editor()->has_keying()) {
set_message(TTR("Keying is disabled (no key inserted)."));
@@ -1944,8 +2012,9 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
Node3D *sp = Object::cast_to<Node3D>(E->get());
- if (!sp)
+ if (!sp) {
continue;
+ }
spatial_editor->emit_signal("transform_key_request", sp, "", sp->get_transform());
}
@@ -1962,15 +2031,17 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
}
if (k->get_keycode() == KEY_SPACE) {
- if (!k->is_pressed())
+ if (!k->is_pressed()) {
emit_signal("toggle_maximize_view", this);
+ }
}
}
// freelook uses most of the useful shortcuts, like save, so its ok
// to consider freelook active as end of the line for future events.
- if (freelook_active)
+ if (freelook_active) {
accept_event();
+ }
}
void Node3DEditorViewport::_nav_pan(Ref<InputEventWithModifiers> p_event, const Vector2 &p_relative) {
@@ -1978,8 +2049,9 @@ void Node3DEditorViewport::_nav_pan(Ref<InputEventWithModifiers> p_event, const
real_t pan_speed = 1 / 150.0;
int pan_speed_modifier = 10;
- if (nav_scheme == NAVIGATION_MAYA && p_event->get_shift())
+ if (nav_scheme == NAVIGATION_MAYA && p_event->get_shift()) {
pan_speed *= pan_speed_modifier;
+ }
Transform camera_transform;
@@ -1997,20 +2069,23 @@ void Node3DEditorViewport::_nav_zoom(Ref<InputEventWithModifiers> p_event, const
real_t zoom_speed = 1 / 80.0;
int zoom_speed_modifier = 10;
- if (nav_scheme == NAVIGATION_MAYA && p_event->get_shift())
+ if (nav_scheme == NAVIGATION_MAYA && p_event->get_shift()) {
zoom_speed *= zoom_speed_modifier;
+ }
NavigationZoomStyle zoom_style = (NavigationZoomStyle)EditorSettings::get_singleton()->get("editors/3d/navigation/zoom_style").operator int();
if (zoom_style == NAVIGATION_ZOOM_HORIZONTAL) {
- if (p_relative.x > 0)
+ if (p_relative.x > 0) {
scale_cursor_distance(1 - p_relative.x * zoom_speed);
- else if (p_relative.x < 0)
+ } else if (p_relative.x < 0) {
scale_cursor_distance(1.0 / (1 + p_relative.x * zoom_speed));
+ }
} else {
- if (p_relative.y > 0)
+ if (p_relative.y > 0) {
scale_cursor_distance(1 + p_relative.y * zoom_speed);
- else if (p_relative.y < 0)
+ } else if (p_relative.y < 0) {
scale_cursor_distance(1.0 / (1 - p_relative.y * zoom_speed));
+ }
}
}
@@ -2034,10 +2109,12 @@ void Node3DEditorViewport::_nav_orbit(Ref<InputEventWithModifiers> p_event, cons
cursor.x_rot += p_relative.y * radians_per_pixel;
}
cursor.y_rot += p_relative.x * radians_per_pixel;
- if (cursor.x_rot > Math_PI / 2.0)
+ if (cursor.x_rot > Math_PI / 2.0) {
cursor.x_rot = Math_PI / 2.0;
- if (cursor.x_rot < -Math_PI / 2.0)
+ }
+ if (cursor.x_rot < -Math_PI / 2.0) {
cursor.x_rot = -Math_PI / 2.0;
+ }
name = "";
_update_name();
}
@@ -2065,10 +2142,12 @@ void Node3DEditorViewport::_nav_look(Ref<InputEventWithModifiers> p_event, const
cursor.x_rot += p_relative.y * radians_per_pixel;
}
cursor.y_rot += p_relative.x * radians_per_pixel;
- if (cursor.x_rot > Math_PI / 2.0)
+ if (cursor.x_rot > Math_PI / 2.0) {
cursor.x_rot = Math_PI / 2.0;
- if (cursor.x_rot < -Math_PI / 2.0)
+ }
+ if (cursor.x_rot < -Math_PI / 2.0) {
cursor.x_rot = -Math_PI / 2.0;
+ }
// Look is like the opposite of Orbit: the focus point rotates around the camera
Transform camera_transform = to_camera_transform(cursor);
@@ -2114,13 +2193,15 @@ void Node3DEditorViewport::set_freelook_active(bool active_now) {
void Node3DEditorViewport::scale_cursor_distance(real_t scale) {
// Prevents zero distance which would short-circuit any scaling
- if (cursor.distance < ZOOM_MIN_DISTANCE)
+ if (cursor.distance < ZOOM_MIN_DISTANCE) {
cursor.distance = ZOOM_MIN_DISTANCE;
+ }
cursor.distance *= scale;
- if (cursor.distance < ZOOM_MIN_DISTANCE)
+ if (cursor.distance < ZOOM_MIN_DISTANCE) {
cursor.distance = ZOOM_MIN_DISTANCE;
+ }
zoom_indicator_delay = ZOOM_INDICATOR_DELAY_S;
surface->update();
@@ -2128,13 +2209,15 @@ void Node3DEditorViewport::scale_cursor_distance(real_t scale) {
void Node3DEditorViewport::scale_freelook_speed(real_t scale) {
// Prevents zero distance which would short-circuit any scaling
- if (freelook_speed < FREELOOK_MIN_SPEED)
+ if (freelook_speed < FREELOOK_MIN_SPEED) {
freelook_speed = FREELOOK_MIN_SPEED;
+ }
freelook_speed *= scale;
- if (freelook_speed < FREELOOK_MIN_SPEED)
+ if (freelook_speed < FREELOOK_MIN_SPEED) {
freelook_speed = FREELOOK_MIN_SPEED;
+ }
zoom_indicator_delay = ZOOM_INDICATOR_DELAY_S;
surface->update();
@@ -2304,18 +2387,21 @@ void Node3DEditorViewport::_notification(int p_what) {
for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) {
Node3D *sp = Object::cast_to<Node3D>(E->key());
- if (!sp)
+ if (!sp) {
continue;
+ }
Node3DEditorSelectedItem *se = editor_selection->get_node_editor_data<Node3DEditorSelectedItem>(sp);
- if (!se)
+ if (!se) {
continue;
+ }
Transform t = sp->get_global_gizmo_transform();
exist = true;
- if (se->last_xform == t && !se->last_xform_dirty)
+ if (se->last_xform == t && !se->last_xform_dirty) {
continue;
+ }
changed = true;
se->last_xform_dirty = false;
se->last_xform = t;
@@ -2345,8 +2431,9 @@ void Node3DEditorViewport::_notification(int p_what) {
}
message_time -= get_physics_process_delta_time();
- if (message_time < 0)
+ if (message_time < 0) {
surface->update();
+ }
}
//update shadow atlas if changed
@@ -2609,8 +2696,9 @@ void Node3DEditorViewport::_draw() {
// There is no real maximum speed so that factor can become negative,
// Let's make it look asymptotic instead (will decrease slower and slower).
- if (logscale_t < 0.25)
+ if (logscale_t < 0.25) {
logscale_t = 0.25 * Math::exp(4.0 * logscale_t - 1.0);
+ }
draw_indicator_bar(*surface, 1.0 - logscale_t, get_theme_icon("ViewportSpeed", "EditorIcons"));
}
@@ -2627,8 +2715,9 @@ void Node3DEditorViewport::_draw() {
// There is no real maximum distance so that factor can become negative,
// Let's make it look asymptotic instead (will decrease slower and slower).
- if (logscale_t < 0.25)
+ if (logscale_t < 0.25) {
logscale_t = 0.25 * Math::exp(4.0 * logscale_t - 1.0);
+ }
draw_indicator_bar(*surface, logscale_t, get_theme_icon("ViewportZoom", "EditorIcons"));
}
@@ -2702,8 +2791,9 @@ void Node3DEditorViewport::_menu_option(int p_option) {
} break;
case VIEW_ALIGN_TRANSFORM_WITH_VIEW: {
- if (!get_selected_count())
+ if (!get_selected_count()) {
break;
+ }
Transform camera_transform = camera->get_global_transform();
@@ -2713,12 +2803,14 @@ void Node3DEditorViewport::_menu_option(int p_option) {
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
Node3D *sp = Object::cast_to<Node3D>(E->get());
- if (!sp)
+ if (!sp) {
continue;
+ }
Node3DEditorSelectedItem *se = editor_selection->get_node_editor_data<Node3DEditorSelectedItem>(sp);
- if (!se)
+ if (!se) {
continue;
+ }
Transform xform;
if (orthogonal) {
@@ -2736,8 +2828,9 @@ void Node3DEditorViewport::_menu_option(int p_option) {
} break;
case VIEW_ALIGN_ROTATION_WITH_VIEW: {
- if (!get_selected_count())
+ if (!get_selected_count()) {
break;
+ }
Transform camera_transform = camera->get_global_transform();
@@ -2746,12 +2839,14 @@ void Node3DEditorViewport::_menu_option(int p_option) {
undo_redo->create_action(TTR("Align Rotation with View"));
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
Node3D *sp = Object::cast_to<Node3D>(E->get());
- if (!sp)
+ if (!sp) {
continue;
+ }
Node3DEditorSelectedItem *se = editor_selection->get_node_editor_data<Node3DEditorSelectedItem>(sp);
- if (!se)
+ if (!se) {
continue;
+ }
undo_redo->add_do_method(sp, "set_rotation", camera_transform.basis.get_rotation());
undo_redo->add_undo_method(sp, "set_rotation", sp->get_rotation());
@@ -2839,18 +2934,20 @@ void Node3DEditorViewport::_menu_option(int p_option) {
if (current) {
preview_camera->hide();
} else {
- if (previewing != nullptr)
+ if (previewing != nullptr) {
preview_camera->show();
+ }
}
} break;
case VIEW_GIZMOS: {
int idx = view_menu->get_popup()->get_item_index(VIEW_GIZMOS);
bool current = view_menu->get_popup()->is_item_checked(idx);
current = !current;
- if (current)
+ if (current) {
camera->set_cull_mask(((1 << 20) - 1) | (1 << (GIZMO_BASE_LAYER + index)) | (1 << GIZMO_EDIT_LAYER) | (1 << GIZMO_GRID_LAYER));
- else
+ } else {
camera->set_cull_mask(((1 << 20) - 1) | (1 << (GIZMO_BASE_LAYER + index)) | (1 << GIZMO_GRID_LAYER));
+ }
view_menu->get_popup()->set_item_checked(idx, current);
} break;
@@ -3026,8 +3123,9 @@ void Node3DEditorViewport::_toggle_camera_preview(bool p_activate) {
previewing->disconnect("tree_exiting", callable_mp(this, &Node3DEditorViewport::_preview_exited_scene));
previewing = nullptr;
RS::get_singleton()->viewport_attach_camera(viewport->get_viewport_rid(), camera->get_camera()); //restore
- if (!preview)
+ if (!preview) {
preview_camera->hide();
+ }
view_menu->set_disabled(false);
surface->update();
@@ -3043,8 +3141,9 @@ void Node3DEditorViewport::_toggle_camera_preview(bool p_activate) {
void Node3DEditorViewport::_toggle_cinema_preview(bool p_activate) {
previewing_cinema = p_activate;
if (!previewing_cinema) {
- if (previewing != nullptr)
+ if (previewing != nullptr) {
previewing->disconnect("tree_exited", callable_mp(this, &Node3DEditorViewport::_preview_exited_scene));
+ }
previewing = nullptr;
RS::get_singleton()->viewport_attach_camera(viewport->get_viewport_rid(), camera->get_camera()); //restore
@@ -3060,8 +3159,9 @@ void Node3DEditorViewport::_toggle_cinema_preview(bool p_activate) {
}
void Node3DEditorViewport::_selection_result_pressed(int p_result) {
- if (selection_results.size() <= p_result)
+ if (selection_results.size() <= p_result) {
return;
+ }
clicked = selection_results[p_result].item->get_instance_id();
@@ -3080,13 +3180,15 @@ void Node3DEditorViewport::_selection_menu_hide() {
void Node3DEditorViewport::set_can_preview(Camera3D *p_preview) {
preview = p_preview;
- if (!preview_camera->is_pressed() && !previewing_cinema)
+ if (!preview_camera->is_pressed() && !previewing_cinema) {
preview_camera->set_visible(p_preview);
+ }
}
void Node3DEditorViewport::update_transform_gizmo_view() {
- if (!is_visible_in_tree())
+ if (!is_visible_in_tree()) {
return;
+ }
Transform xform = spatial_editor->get_gizmo_transform();
@@ -3110,8 +3212,9 @@ void Node3DEditorViewport::update_transform_gizmo_view() {
float d0 = camera->unproject_position(camera_xform.origin + camz * gizmo_d).y;
float d1 = camera->unproject_position(camera_xform.origin + camz * gizmo_d + camy).y;
float dd = Math::abs(d0 - d1);
- if (dd == 0)
+ if (dd == 0) {
dd = 0.0001;
+ }
float gizmo_size = EditorSettings::get_singleton()->get("editors/3d/manipulator_gizmo_size");
// At low viewport heights, multiply the gizmo scale based on the viewport height.
@@ -3140,22 +3243,27 @@ void Node3DEditorViewport::update_transform_gizmo_view() {
}
void Node3DEditorViewport::set_state(const Dictionary &p_state) {
- if (p_state.has("position"))
+ if (p_state.has("position")) {
cursor.pos = p_state["position"];
- if (p_state.has("x_rotation"))
+ }
+ if (p_state.has("x_rotation")) {
cursor.x_rot = p_state["x_rotation"];
- if (p_state.has("y_rotation"))
+ }
+ if (p_state.has("y_rotation")) {
cursor.y_rot = p_state["y_rotation"];
- if (p_state.has("distance"))
+ }
+ if (p_state.has("distance")) {
cursor.distance = p_state["distance"];
+ }
if (p_state.has("use_orthogonal")) {
bool orth = p_state["use_orthogonal"];
- if (orth)
+ if (orth) {
_menu_option(VIEW_ORTHOGONAL);
- else
+ } else {
_menu_option(VIEW_PERSPECTIVE);
+ }
}
if (p_state.has("view_name")) {
name = p_state["view_name"];
@@ -3173,8 +3281,9 @@ void Node3DEditorViewport::set_state(const Dictionary &p_state) {
int display = p_state["display_mode"];
int idx = view_menu->get_popup()->get_item_index(display);
- if (!view_menu->get_popup()->is_item_checked(idx))
+ if (!view_menu->get_popup()->is_item_checked(idx)) {
_menu_option(display);
+ }
}
if (p_state.has("lock_rotation")) {
lock_rotation = p_state["lock_rotation"];
@@ -3185,8 +3294,9 @@ void Node3DEditorViewport::set_state(const Dictionary &p_state) {
if (p_state.has("use_environment")) {
bool env = p_state["use_environment"];
- if (env != camera->get_environment().is_valid())
+ if (env != camera->get_environment().is_valid()) {
_menu_option(VIEW_ENVIRONMENT);
+ }
}
if (p_state.has("listener")) {
bool listener = p_state["listener"];
@@ -3206,22 +3316,25 @@ void Node3DEditorViewport::set_state(const Dictionary &p_state) {
bool gizmos = p_state["gizmos"];
int idx = view_menu->get_popup()->get_item_index(VIEW_GIZMOS);
- if (view_menu->get_popup()->is_item_checked(idx) != gizmos)
+ if (view_menu->get_popup()->is_item_checked(idx) != gizmos) {
_menu_option(VIEW_GIZMOS);
+ }
}
if (p_state.has("information")) {
bool information = p_state["information"];
int idx = view_menu->get_popup()->get_item_index(VIEW_INFORMATION);
- if (view_menu->get_popup()->is_item_checked(idx) != information)
+ if (view_menu->get_popup()->is_item_checked(idx) != information) {
_menu_option(VIEW_INFORMATION);
+ }
}
if (p_state.has("frame_time")) {
bool fps = p_state["frame_time"];
int idx = view_menu->get_popup()->get_item_index(VIEW_FRAME_TIME);
- if (view_menu->get_popup()->is_item_checked(idx) != fps)
+ if (view_menu->get_popup()->is_item_checked(idx) != fps) {
_menu_option(VIEW_FRAME_TIME);
+ }
}
if (p_state.has("half_res")) {
bool half_res = p_state["half_res"];
@@ -3265,14 +3378,15 @@ Dictionary Node3DEditorViewport::get_state() const {
d["view_name"] = name;
d["auto_orthogonal"] = auto_orthogonal;
d["auto_orthogonal_enabled"] = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_AUTO_ORTHOGONAL));
- if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_NORMAL)))
+ if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_NORMAL))) {
d["display_mode"] = VIEW_DISPLAY_NORMAL;
- else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_WIREFRAME)))
+ } else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_WIREFRAME))) {
d["display_mode"] = VIEW_DISPLAY_WIREFRAME;
- else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_OVERDRAW)))
+ } else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_OVERDRAW))) {
d["display_mode"] = VIEW_DISPLAY_OVERDRAW;
- else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_SHADELESS)))
+ } else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_SHADELESS))) {
d["display_mode"] = VIEW_DISPLAY_SHADELESS;
+ }
d["listener"] = viewport->is_audio_listener();
d["doppler"] = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_AUDIO_DOPPLER));
d["gizmos"] = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_GIZMOS));
@@ -3280,10 +3394,12 @@ Dictionary Node3DEditorViewport::get_state() const {
d["frame_time"] = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_FRAME_TIME));
d["half_res"] = subviewport_container->get_stretch_shrink() > 1;
d["cinematic_preview"] = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_CINEMATIC_PREVIEW));
- if (previewing)
+ if (previewing) {
d["previewing"] = EditorNode::get_singleton()->get_edited_scene()->get_path_to(previewing);
- if (lock_rotation)
+ }
+ if (lock_rotation) {
d["lock_rotation"] = lock_rotation;
+ }
return d;
}
@@ -3315,8 +3431,9 @@ void Node3DEditorViewport::reset() {
}
void Node3DEditorViewport::focus_selection() {
- if (!get_selected_count())
+ if (!get_selected_count()) {
return;
+ }
Vector3 center;
int count = 0;
@@ -3325,12 +3442,14 @@ void Node3DEditorViewport::focus_selection() {
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
Node3D *sp = Object::cast_to<Node3D>(E->get());
- if (!sp)
+ if (!sp) {
continue;
+ }
Node3DEditorSelectedItem *se = editor_selection->get_node_editor_data<Node3DEditorSelectedItem>(sp);
- if (!se)
+ if (!se) {
continue;
+ }
center += sp->get_global_gizmo_transform().origin;
count++;
@@ -3366,8 +3485,9 @@ Vector3 Node3DEditorViewport::_get_instance_position(const Point2 &p_pos) const
for (int i = 0; i < instances.size(); i++) {
MeshInstance3D *mesh_instance = Object::cast_to<MeshInstance3D>(ObjectDB::get_instance(instances[i]));
- if (!mesh_instance)
+ if (!mesh_instance) {
continue;
+ }
Ref<EditorNode3DGizmo> seg = mesh_instance->get_gizmo();
@@ -3381,13 +3501,15 @@ Vector3 Node3DEditorViewport::_get_instance_position(const Point2 &p_pos) const
Vector3 hit_normal;
bool inters = seg->intersect_ray(camera, p_pos, hit_point, hit_normal, nullptr, false);
- if (!inters)
+ if (!inters) {
continue;
+ }
float dist = world_pos.distance_to(hit_point);
- if (dist < 0)
+ if (dist < 0) {
continue;
+ }
if (dist < closest_dist) {
closest_dist = dist;
@@ -3397,10 +3519,11 @@ Vector3 Node3DEditorViewport::_get_instance_position(const Point2 &p_pos) const
}
Vector3 offset = Vector3();
for (int i = 0; i < 3; i++) {
- if (normal[i] > 0.0)
+ if (normal[i] > 0.0) {
offset[i] = (preview_bounds->get_size()[i] - (preview_bounds->get_size()[i] + preview_bounds->get_position()[i]));
- else if (normal[i] < 0.0)
+ } else if (normal[i] < 0.0) {
offset[i] = -(preview_bounds->get_size()[i] + preview_bounds->get_position()[i]);
+ }
}
return point + offset;
}
@@ -3540,8 +3663,9 @@ bool Node3DEditorViewport::_create_instance(Node *parent, String &path, const Po
Transform global_transform;
Node3D *parent_spatial = Object::cast_to<Node3D>(parent);
- if (parent_spatial)
+ if (parent_spatial) {
global_transform = parent_spatial->get_global_gizmo_transform();
+ }
global_transform.origin = spatial_editor->snap_point(_get_instance_position(p_point));
@@ -3643,8 +3767,9 @@ bool Node3DEditorViewport::can_drop_data_fw(const Point2 &p_point, const Variant
}
void Node3DEditorViewport::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
- if (!can_drop_data_fw(p_point, p_data, p_from))
+ if (!can_drop_data_fw(p_point, p_data, p_from)) {
return;
+ }
bool is_shift = Input::get_singleton()->is_key_pressed(KEY_SHIFT);
@@ -4150,10 +4275,11 @@ void Node3DEditorViewportContainer::_notification(int p_what) {
} break;
case VIEW_USE_2_VIEWPORTS: {
for (int i = 0; i < 4; i++) {
- if (i == 1 || i == 3)
+ if (i == 1 || i == 3) {
viewports[i]->hide();
- else
+ } else {
viewports[i]->show();
+ }
}
fit_child_in_rect(viewports[0], Rect2(Vector2(), Vector2(size.width, size_top)));
@@ -4162,10 +4288,11 @@ void Node3DEditorViewportContainer::_notification(int p_what) {
} break;
case VIEW_USE_2_VIEWPORTS_ALT: {
for (int i = 0; i < 4; i++) {
- if (i == 1 || i == 3)
+ if (i == 1 || i == 3) {
viewports[i]->hide();
- else
+ } else {
viewports[i]->show();
+ }
}
fit_child_in_rect(viewports[0], Rect2(Vector2(), Vector2(size_left, size.height)));
fit_child_in_rect(viewports[2], Rect2(Vector2(mid_w + h_sep / 2, 0), Vector2(size_right, size.height)));
@@ -4173,10 +4300,11 @@ void Node3DEditorViewportContainer::_notification(int p_what) {
} break;
case VIEW_USE_3_VIEWPORTS: {
for (int i = 0; i < 4; i++) {
- if (i == 1)
+ if (i == 1) {
viewports[i]->hide();
- else
+ } else {
viewports[i]->show();
+ }
}
fit_child_in_rect(viewports[0], Rect2(Vector2(), Vector2(size.width, size_top)));
@@ -4186,10 +4314,11 @@ void Node3DEditorViewportContainer::_notification(int p_what) {
} break;
case VIEW_USE_3_VIEWPORTS_ALT: {
for (int i = 0; i < 4; i++) {
- if (i == 1)
+ if (i == 1) {
viewports[i]->hide();
- else
+ } else {
viewports[i]->show();
+ }
}
fit_child_in_rect(viewports[0], Rect2(Vector2(), Vector2(size_left, size_top)));
@@ -4242,8 +4371,9 @@ Node3DEditorViewportContainer::Node3DEditorViewportContainer() {
Node3DEditor *Node3DEditor::singleton = nullptr;
Node3DEditorSelectedItem::~Node3DEditorSelectedItem() {
- if (sbox_instance.is_valid())
+ if (sbox_instance.is_valid()) {
RenderingServer::get_singleton()->free(sbox_instance);
+ }
}
void Node3DEditor::select_gizmo_highlight_axis(int p_axis) {
@@ -4266,12 +4396,14 @@ void Node3DEditor::update_transform_gizmo() {
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
Node3D *sp = Object::cast_to<Node3D>(E->get());
- if (!sp)
+ if (!sp) {
continue;
+ }
Node3DEditorSelectedItem *se = editor_selection->get_node_editor_data<Node3DEditorSelectedItem>(sp);
- if (!se)
+ if (!se) {
continue;
+ }
Transform xf = se->sp->get_global_gizmo_transform();
@@ -4318,8 +4450,9 @@ void Node3DEditor::update_all_gizmos(Node *p_node) {
Object *Node3DEditor::_get_editor_data(Object *p_what) {
Node3D *sp = Object::cast_to<Node3D>(p_what);
- if (!sp)
+ if (!sp) {
return nullptr;
+ }
Node3DEditorSelectedItem *si = memnew(Node3DEditorSelectedItem);
@@ -4373,18 +4506,19 @@ Dictionary Node3DEditor::get_state() const {
d["local_coords"] = tool_option_button[TOOL_OPT_LOCAL_COORDS]->is_pressed();
int vc = 0;
- if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT)))
+ if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT))) {
vc = 1;
- else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS)))
+ } else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS))) {
vc = 2;
- else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS)))
+ } else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS))) {
vc = 3;
- else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_4_VIEWPORTS)))
+ } else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_4_VIEWPORTS))) {
vc = 4;
- else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS_ALT)))
+ } else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS_ALT))) {
vc = 5;
- else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS_ALT)))
+ } else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS_ALT))) {
vc = 6;
+ }
d["viewport_mode"] = vc;
Array vpdata;
@@ -4402,8 +4536,9 @@ Dictionary Node3DEditor::get_state() const {
Dictionary gizmos_status;
for (int i = 0; i < gizmo_plugins_by_name.size(); i++) {
- if (!gizmo_plugins_by_name[i]->can_be_hidden())
+ if (!gizmo_plugins_by_name[i]->can_be_hidden()) {
continue;
+ }
int state = gizmos_menu->get_item_state(gizmos_menu->get_item_index(i));
String name = gizmo_plugins_by_name[i]->get_name();
gizmos_status[name] = state;
@@ -4422,14 +4557,17 @@ void Node3DEditor::set_state(const Dictionary &p_state) {
tool_option_button[TOOL_OPT_USE_SNAP]->set_pressed(d["snap_enabled"]);
}
- if (d.has("translate_snap"))
+ if (d.has("translate_snap")) {
snap_translate_value = d["translate_snap"];
+ }
- if (d.has("rotate_snap"))
+ if (d.has("rotate_snap")) {
snap_rotate_value = d["rotate_snap"];
+ }
- if (d.has("scale_snap"))
+ if (d.has("scale_snap")) {
snap_scale_value = d["scale_snap"];
+ }
_snap_update();
@@ -4441,18 +4579,19 @@ void Node3DEditor::set_state(const Dictionary &p_state) {
if (d.has("viewport_mode")) {
int vc = d["viewport_mode"];
- if (vc == 1)
+ if (vc == 1) {
_menu_item_pressed(MENU_VIEW_USE_1_VIEWPORT);
- else if (vc == 2)
+ } else if (vc == 2) {
_menu_item_pressed(MENU_VIEW_USE_2_VIEWPORTS);
- else if (vc == 3)
+ } else if (vc == 3) {
_menu_item_pressed(MENU_VIEW_USE_3_VIEWPORTS);
- else if (vc == 4)
+ } else if (vc == 4) {
_menu_item_pressed(MENU_VIEW_USE_4_VIEWPORTS);
- else if (vc == 5)
+ } else if (vc == 5) {
_menu_item_pressed(MENU_VIEW_USE_2_VIEWPORTS_ALT);
- else if (vc == 6)
+ } else if (vc == 6) {
_menu_item_pressed(MENU_VIEW_USE_3_VIEWPORTS_ALT);
+ }
}
if (d.has("viewports")) {
@@ -4468,12 +4607,15 @@ void Node3DEditor::set_state(const Dictionary &p_state) {
}
}
- if (d.has("zfar"))
+ if (d.has("zfar")) {
settings_zfar->set_value(float(d["zfar"]));
- if (d.has("znear"))
+ }
+ if (d.has("znear")) {
settings_znear->set_value(float(d["znear"]));
- if (d.has("fov"))
+ }
+ if (d.has("fov")) {
settings_fov->set_value(float(d["fov"]));
+ }
if (d.has("show_grid")) {
bool use = d["show_grid"];
@@ -4497,8 +4639,9 @@ void Node3DEditor::set_state(const Dictionary &p_state) {
gizmos_status.get_key_list(&keys);
for (int j = 0; j < gizmo_plugins_by_name.size(); ++j) {
- if (!gizmo_plugins_by_name[j]->can_be_hidden())
+ if (!gizmo_plugins_by_name[j]->can_be_hidden()) {
continue;
+ }
int state = EditorNode3DGizmoPlugin::VISIBLE;
for (int i = 0; i < keys.size(); i++) {
if (gizmo_plugins_by_name.write[j]->get_name() == keys[i]) {
@@ -4571,19 +4714,21 @@ void Node3DEditor::_xform_dialog_action() {
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
Node3D *sp = Object::cast_to<Node3D>(E->get());
- if (!sp)
+ if (!sp) {
continue;
+ }
Node3DEditorSelectedItem *se = editor_selection->get_node_editor_data<Node3DEditorSelectedItem>(sp);
- if (!se)
+ if (!se) {
continue;
+ }
bool post = xform_type->get_selected() > 0;
Transform tr = sp->get_global_gizmo_transform();
- if (post)
+ if (post) {
tr = tr * t;
- else {
+ } else {
tr.basis = t.basis * tr.basis;
tr.origin += t.origin;
}
@@ -4659,8 +4804,9 @@ void Node3DEditor::_update_camera_override_button(bool p_game_running) {
void Node3DEditor::_update_camera_override_viewport(Object *p_viewport) {
Node3DEditorViewport *current_viewport = Object::cast_to<Node3DEditorViewport>(p_viewport);
- if (!current_viewport)
+ if (!current_viewport) {
return;
+ }
EditorDebuggerNode *const debugger = EditorDebuggerNode::get_singleton();
@@ -4679,8 +4825,9 @@ void Node3DEditor::_menu_item_pressed(int p_option) {
case MENU_TOOL_ROTATE:
case MENU_TOOL_SCALE:
case MENU_TOOL_LIST_SELECT: {
- for (int i = 0; i < TOOL_MAX; i++)
+ for (int i = 0; i < TOOL_MAX; i++) {
tool_button[i]->set_pressed(i == p_option);
+ }
tool_mode = (ToolMode)p_option;
update_transform_gizmo();
@@ -4803,11 +4950,13 @@ void Node3DEditor::_menu_item_pressed(int p_option) {
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
Node3D *spatial = Object::cast_to<Node3D>(E->get());
- if (!spatial || !spatial->is_visible_in_tree())
+ if (!spatial || !spatial->is_visible_in_tree()) {
continue;
+ }
- if (spatial->get_viewport() != EditorNode::get_singleton()->get_scene_root())
+ if (spatial->get_viewport() != EditorNode::get_singleton()->get_scene_root()) {
continue;
+ }
undo_redo->add_do_method(spatial, "set_meta", "_edit_lock_", true);
undo_redo->add_undo_method(spatial, "remove_meta", "_edit_lock_");
@@ -4826,11 +4975,13 @@ void Node3DEditor::_menu_item_pressed(int p_option) {
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
Node3D *spatial = Object::cast_to<Node3D>(E->get());
- if (!spatial || !spatial->is_visible_in_tree())
+ if (!spatial || !spatial->is_visible_in_tree()) {
continue;
+ }
- if (spatial->get_viewport() != EditorNode::get_singleton()->get_scene_root())
+ if (spatial->get_viewport() != EditorNode::get_singleton()->get_scene_root()) {
continue;
+ }
undo_redo->add_do_method(spatial, "remove_meta", "_edit_lock_");
undo_redo->add_undo_method(spatial, "set_meta", "_edit_lock_", true);
@@ -4849,11 +5000,13 @@ void Node3DEditor::_menu_item_pressed(int p_option) {
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
Node3D *spatial = Object::cast_to<Node3D>(E->get());
- if (!spatial || !spatial->is_visible_in_tree())
+ if (!spatial || !spatial->is_visible_in_tree()) {
continue;
+ }
- if (spatial->get_viewport() != EditorNode::get_singleton()->get_scene_root())
+ if (spatial->get_viewport() != EditorNode::get_singleton()->get_scene_root()) {
continue;
+ }
undo_redo->add_do_method(spatial, "set_meta", "_edit_group_", true);
undo_redo->add_undo_method(spatial, "remove_meta", "_edit_group_");
@@ -4871,11 +5024,13 @@ void Node3DEditor::_menu_item_pressed(int p_option) {
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
Node3D *spatial = Object::cast_to<Node3D>(E->get());
- if (!spatial || !spatial->is_visible_in_tree())
+ if (!spatial || !spatial->is_visible_in_tree()) {
continue;
+ }
- if (spatial->get_viewport() != EditorNode::get_singleton()->get_scene_root())
+ if (spatial->get_viewport() != EditorNode::get_singleton()->get_scene_root()) {
continue;
+ }
undo_redo->add_do_method(spatial, "remove_meta", "_edit_group_");
undo_redo->add_undo_method(spatial, "set_meta", "_edit_group_", true);
@@ -5220,8 +5375,9 @@ void Node3DEditor::_update_gizmos_menu() {
gizmos_menu->clear();
for (int i = 0; i < gizmo_plugins_by_name.size(); ++i) {
- if (!gizmo_plugins_by_name[i]->can_be_hidden())
+ if (!gizmo_plugins_by_name[i]->can_be_hidden()) {
continue;
+ }
String plugin_name = gizmo_plugins_by_name[i]->get_name();
const int plugin_state = gizmo_plugins_by_name[i]->get_state();
gizmos_menu->add_multistate_item(TTR(plugin_name), 3, plugin_state, i);
@@ -5242,8 +5398,9 @@ void Node3DEditor::_update_gizmos_menu() {
void Node3DEditor::_update_gizmos_menu_theme() {
for (int i = 0; i < gizmo_plugins_by_name.size(); ++i) {
- if (!gizmo_plugins_by_name[i]->can_be_hidden())
+ if (!gizmo_plugins_by_name[i]->can_be_hidden()) {
continue;
+ }
const int plugin_state = gizmo_plugins_by_name[i]->get_state();
const int idx = gizmos_menu->get_item_index(i);
switch (plugin_state) {
@@ -5334,8 +5491,9 @@ void Node3DEditor::_finish_grid() {
bool Node3DEditor::is_any_freelook_active() const {
for (unsigned int i = 0; i < VIEWPORTS_COUNT; ++i) {
- if (viewports[i]->is_freelook_active())
+ if (viewports[i]->is_freelook_active()) {
return true;
+ }
}
return false;
}
@@ -5512,8 +5670,9 @@ void Node3DEditor::snap_selected_nodes_to_floor() {
}
void Node3DEditor::_unhandled_key_input(Ref<InputEvent> p_event) {
- if (!is_visible_in_tree())
+ if (!is_visible_in_tree()) {
return;
+ }
snap_key_enabled = Input::get_singleton()->is_key_pressed(KEY_CONTROL);
}
@@ -5617,8 +5776,9 @@ HSplitContainer *Node3DEditor::get_palette_split() {
void Node3DEditor::_request_gizmo(Object *p_obj) {
Node3D *sp = Object::cast_to<Node3D>(p_obj);
- if (!sp)
+ if (!sp) {
return;
+ }
if (editor->get_edited_scene() && (sp == editor->get_edited_scene() || (sp->get_owner() && editor->get_edited_scene()->is_a_parent_of(sp)))) {
Ref<EditorNode3DGizmo> seg;
@@ -5640,54 +5800,62 @@ void Node3DEditor::_request_gizmo(Object *p_obj) {
}
void Node3DEditor::_toggle_maximize_view(Object *p_viewport) {
- if (!p_viewport)
+ if (!p_viewport) {
return;
+ }
Node3DEditorViewport *current_viewport = Object::cast_to<Node3DEditorViewport>(p_viewport);
- if (!current_viewport)
+ if (!current_viewport) {
return;
+ }
int index = -1;
bool maximized = false;
for (int i = 0; i < 4; i++) {
if (viewports[i] == current_viewport) {
index = i;
- if (current_viewport->get_global_rect() == viewport_base->get_global_rect())
+ if (current_viewport->get_global_rect() == viewport_base->get_global_rect()) {
maximized = true;
+ }
break;
}
}
- if (index == -1)
+ if (index == -1) {
return;
+ }
if (!maximized) {
for (uint32_t i = 0; i < VIEWPORTS_COUNT; i++) {
- if (i == (uint32_t)index)
+ if (i == (uint32_t)index) {
viewports[i]->set_anchors_and_margins_preset(Control::PRESET_WIDE);
- else
+ } else {
viewports[i]->hide();
+ }
}
} else {
- for (uint32_t i = 0; i < VIEWPORTS_COUNT; i++)
+ for (uint32_t i = 0; i < VIEWPORTS_COUNT; i++) {
viewports[i]->show();
+ }
- if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT)))
+ if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT))) {
_menu_item_pressed(MENU_VIEW_USE_1_VIEWPORT);
- else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS)))
+ } else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS))) {
_menu_item_pressed(MENU_VIEW_USE_2_VIEWPORTS);
- else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS_ALT)))
+ } else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS_ALT))) {
_menu_item_pressed(MENU_VIEW_USE_2_VIEWPORTS_ALT);
- else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS)))
+ } else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS))) {
_menu_item_pressed(MENU_VIEW_USE_3_VIEWPORTS);
- else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS_ALT)))
+ } else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS_ALT))) {
_menu_item_pressed(MENU_VIEW_USE_3_VIEWPORTS_ALT);
- else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_4_VIEWPORTS)))
+ } else if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_4_VIEWPORTS))) {
_menu_item_pressed(MENU_VIEW_USE_4_VIEWPORTS);
+ }
}
}
void Node3DEditor::_node_removed(Node *p_node) {
- if (p_node == selected)
+ if (p_node == selected) {
selected = nullptr;
+ }
}
void Node3DEditor::_register_all_gizmos() {
@@ -6353,8 +6521,9 @@ Ref<StandardMaterial3D> EditorNode3DGizmoPlugin::get_material(const String &p_na
ERR_FAIL_COND_V(!materials.has(p_name), Ref<StandardMaterial3D>());
ERR_FAIL_COND_V(materials[p_name].size() == 0, Ref<StandardMaterial3D>());
- if (p_gizmo.is_null() || materials[p_name].size() == 1)
+ if (p_gizmo.is_null() || materials[p_name].size() == 1) {
return materials[p_name][0];
+ }
int index = (p_gizmo->is_selected() ? 1 : 0) + (p_gizmo->is_editable() ? 2 : 0);
@@ -6390,8 +6559,9 @@ Ref<EditorNode3DGizmo> EditorNode3DGizmoPlugin::get_gizmo(Node3D *p_spatial) {
Ref<EditorNode3DGizmo> ref = create_gizmo(p_spatial);
- if (ref.is_null())
+ if (ref.is_null()) {
return ref;
+ }
ref->set_plugin(this);
ref->set_spatial_node(p_spatial);
@@ -6449,8 +6619,9 @@ Ref<EditorNode3DGizmo> EditorNode3DGizmoPlugin::create_gizmo(Node3D *p_spatial)
}
Ref<EditorNode3DGizmo> ref;
- if (has_gizmo(p_spatial))
+ if (has_gizmo(p_spatial)) {
ref.instance();
+ }
return ref;
}
diff --git a/editor/plugins/path_2d_editor_plugin.cpp b/editor/plugins/path_2d_editor_plugin.cpp
index d4f49100d6..a3dab665b8 100644
--- a/editor/plugins/path_2d_editor_plugin.cpp
+++ b/editor/plugins/path_2d_editor_plugin.cpp
@@ -58,14 +58,17 @@ void Path2DEditor::_node_removed(Node *p_node) {
}
bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
- if (!node)
+ if (!node) {
return false;
+ }
- if (!node->is_visible_in_tree())
+ if (!node->is_visible_in_tree()) {
return false;
+ }
- if (!node->get_curve().is_valid())
+ if (!node->get_curve().is_valid()) {
return false;
+ }
real_t grab_threshold = EDITOR_GET("editors/poly_editor/point_grab_radius");
@@ -176,11 +179,13 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
int len = curve->get_point_count();
for (int i = 0; i < len - 1; i++) {
float compareLength = curve->get_closest_offset(curve->get_point_position(i + 1));
- if (mbLength >= curve->get_closest_offset(curve->get_point_position(i)) && mbLength <= compareLength)
+ if (mbLength >= curve->get_closest_offset(curve->get_point_position(i)) && mbLength <= compareLength) {
insertion_point = i;
+ }
}
- if (insertion_point == -1)
+ if (insertion_point == -1) {
insertion_point = curve->get_point_count() - 2;
+ }
undo_redo->create_action(TTR("Split Curve"));
undo_redo->add_do_method(curve.ptr(), "add_point", xform.affine_inverse().xform(gpoint2), Vector2(0, 0), Vector2(0, 0), insertion_point + 1);
@@ -269,10 +274,12 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
Vector2 gpoint = mm->get_position();
Ref<Curve2D> curve = node->get_curve();
- if (curve == nullptr)
+ if (curve == nullptr) {
return true;
- if (curve->get_point_count() < 2)
+ }
+ if (curve->get_point_count() < 2) {
return true;
+ }
// Find edge
edge_point = xform.xform(curve->get_closest_point(xform.affine_inverse().xform(mm->get_position())));
@@ -328,15 +335,17 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
case ACTION_MOVING_IN: {
curve->set_point_in(action_point, new_pos);
- if (mirror_handle_angle)
+ if (mirror_handle_angle) {
curve->set_point_out(action_point, mirror_handle_length ? -new_pos : (-new_pos.normalized() * orig_out_length));
+ }
} break;
case ACTION_MOVING_OUT: {
curve->set_point_out(action_point, new_pos);
- if (mirror_handle_angle)
+ if (mirror_handle_angle) {
curve->set_point_in(action_point, mirror_handle_length ? -new_pos : (-new_pos.normalized() * orig_in_length));
+ }
} break;
}
@@ -349,8 +358,9 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
}
void Path2DEditor::forward_canvas_draw_over_viewport(Control *p_overlay) {
- if (!node || !node->is_visible_in_tree() || !node->get_curve().is_valid())
+ if (!node || !node->is_visible_in_tree() || !node->get_curve().is_valid()) {
return;
+ }
Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform();
@@ -407,8 +417,9 @@ void Path2DEditor::forward_canvas_draw_over_viewport(Control *p_overlay) {
}
void Path2DEditor::_node_visibility_changed() {
- if (!node)
+ if (!node) {
return;
+ }
canvas_item_editor->update_viewport();
}
@@ -420,13 +431,15 @@ void Path2DEditor::edit(Node *p_path2d) {
if (p_path2d) {
node = Object::cast_to<Path2D>(p_path2d);
- if (!node->is_connected("visibility_changed", callable_mp(this, &Path2DEditor::_node_visibility_changed)))
+ if (!node->is_connected("visibility_changed", callable_mp(this, &Path2DEditor::_node_visibility_changed))) {
node->connect("visibility_changed", callable_mp(this, &Path2DEditor::_node_visibility_changed));
+ }
} else {
// node may have been deleted at this point
- if (node && node->is_connected("visibility_changed", callable_mp(this, &Path2DEditor::_node_visibility_changed)))
+ if (node && node->is_connected("visibility_changed", callable_mp(this, &Path2DEditor::_node_visibility_changed))) {
node->disconnect("visibility_changed", callable_mp(this, &Path2DEditor::_node_visibility_changed));
+ }
node = nullptr;
}
}
@@ -459,15 +472,18 @@ void Path2DEditor::_mode_selected(int p_mode) {
} else if (p_mode == ACTION_CLOSE) {
//?
- if (!node->get_curve().is_valid())
+ if (!node->get_curve().is_valid()) {
return;
- if (node->get_curve()->get_point_count() < 3)
+ }
+ if (node->get_curve()->get_point_count() < 3) {
return;
+ }
Vector2 begin = node->get_curve()->get_point_position(0);
Vector2 end = node->get_curve()->get_point_position(node->get_curve()->get_point_count() - 1);
- if (begin.distance_to(end) < CMP_EPSILON)
+ if (begin.distance_to(end) < CMP_EPSILON) {
return;
+ }
undo_redo->create_action(TTR("Remove Point from Curve"));
undo_redo->add_do_method(node->get_curve().ptr(), "add_point", begin);
diff --git a/editor/plugins/path_3d_editor_plugin.cpp b/editor/plugins/path_3d_editor_plugin.cpp
index 0aee064c41..a44fe69ff6 100644
--- a/editor/plugins/path_3d_editor_plugin.cpp
+++ b/editor/plugins/path_3d_editor_plugin.cpp
@@ -36,8 +36,9 @@
String Path3DGizmo::get_handle_name(int p_idx) const {
Ref<Curve3D> c = path->get_curve();
- if (c.is_null())
+ if (c.is_null()) {
return "";
+ }
if (p_idx < c->get_point_count()) {
return TTR("Curve Point #") + itos(p_idx);
@@ -48,18 +49,20 @@ String Path3DGizmo::get_handle_name(int p_idx) const {
int idx = p_idx / 2;
int t = p_idx % 2;
String n = TTR("Curve Point #") + itos(idx);
- if (t == 0)
+ if (t == 0) {
n += " In";
- else
+ } else {
n += " Out";
+ }
return n;
}
Variant Path3DGizmo::get_handle_value(int p_idx) {
Ref<Curve3D> c = path->get_curve();
- if (c.is_null())
+ if (c.is_null()) {
return Variant();
+ }
if (p_idx < c->get_point_count()) {
original = c->get_point_position(p_idx);
@@ -72,10 +75,11 @@ Variant Path3DGizmo::get_handle_value(int p_idx) {
int t = p_idx % 2;
Vector3 ofs;
- if (t == 0)
+ if (t == 0) {
ofs = c->get_point_in(idx);
- else
+ } else {
ofs = c->get_point_out(idx);
+ }
original = ofs + c->get_point_position(idx);
@@ -84,8 +88,9 @@ Variant Path3DGizmo::get_handle_value(int p_idx) {
void Path3DGizmo::set_handle(int p_idx, Camera3D *p_camera, const Point2 &p_point) {
Ref<Curve3D> c = path->get_curve();
- if (c.is_null())
+ if (c.is_null()) {
return;
+ }
Transform gt = path->get_global_transform();
Transform gi = gt.affine_inverse();
@@ -138,20 +143,23 @@ void Path3DGizmo::set_handle(int p_idx, Camera3D *p_camera, const Point2 &p_poin
if (t == 0) {
c->set_point_in(idx, local);
- if (Path3DEditorPlugin::singleton->mirror_angle_enabled())
+ if (Path3DEditorPlugin::singleton->mirror_angle_enabled()) {
c->set_point_out(idx, Path3DEditorPlugin::singleton->mirror_length_enabled() ? -local : (-local.normalized() * orig_out_length));
+ }
} else {
c->set_point_out(idx, local);
- if (Path3DEditorPlugin::singleton->mirror_angle_enabled())
+ if (Path3DEditorPlugin::singleton->mirror_angle_enabled()) {
c->set_point_in(idx, Path3DEditorPlugin::singleton->mirror_length_enabled() ? -local : (-local.normalized() * orig_in_length));
+ }
}
}
}
void Path3DGizmo::commit_handle(int p_idx, const Variant &p_restore, bool p_cancel) {
Ref<Curve3D> c = path->get_curve();
- if (c.is_null())
+ if (c.is_null()) {
return;
+ }
UndoRedo *ur = Node3DEditor::get_singleton()->get_undo_redo();
@@ -216,15 +224,17 @@ void Path3DGizmo::redraw() {
Ref<StandardMaterial3D> handles_material = gizmo_plugin->get_material("handles");
Ref<Curve3D> c = path->get_curve();
- if (c.is_null())
+ if (c.is_null()) {
return;
+ }
Vector<Vector3> v3a = c->tessellate();
//Vector<Vector3> v3a=c->get_baked_points();
int v3s = v3a.size();
- if (v3s == 0)
+ if (v3s == 0) {
return;
+ }
Vector<Vector3> v3p;
const Vector3 *r = v3a.ptr();
@@ -280,11 +290,13 @@ Path3DGizmo::Path3DGizmo(Path3D *p_path) {
}
bool Path3DEditorPlugin::forward_spatial_gui_input(Camera3D *p_camera, const Ref<InputEvent> &p_event) {
- if (!path)
+ if (!path) {
return false;
+ }
Ref<Curve3D> c = path->get_curve();
- if (c.is_null())
+ if (c.is_null()) {
return false;
+ }
Transform gt = path->get_global_transform();
Transform it = gt.affine_inverse();
@@ -295,8 +307,9 @@ bool Path3DEditorPlugin::forward_spatial_gui_input(Camera3D *p_camera, const Ref
if (mb.is_valid()) {
Point2 mbpos(mb->get_position().x, mb->get_position().y);
- if (!mb->is_pressed())
+ if (!mb->is_pressed()) {
set_handle_clicked(false);
+ }
if (mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT && (curve_create->is_pressed() || (curve_edit->is_pressed() && mb->get_control()))) {
//click into curve, break it down
@@ -310,14 +323,16 @@ bool Path3DEditorPlugin::forward_spatial_gui_input(Camera3D *p_camera, const Ref
if (rc >= 2) {
const Vector3 *r = v3a.ptr();
- if (p_camera->unproject_position(gt.xform(c->get_point_position(0))).distance_to(mbpos) < click_dist)
+ if (p_camera->unproject_position(gt.xform(c->get_point_position(0))).distance_to(mbpos) < click_dist) {
return false; //nope, existing
+ }
for (int i = 0; i < c->get_point_count() - 1; i++) {
//find the offset and point index of the place to break up
int j = idx;
- if (p_camera->unproject_position(gt.xform(c->get_point_position(i + 1))).distance_to(mbpos) < click_dist)
+ if (p_camera->unproject_position(gt.xform(c->get_point_position(i + 1))).distance_to(mbpos) < click_dist) {
return false; //nope, existing
+ }
while (j < rc && c->get_point_position(i + 1) != r[j]) {
Vector3 from = r[j];
@@ -346,13 +361,15 @@ bool Path3DEditorPlugin::forward_spatial_gui_input(Camera3D *p_camera, const Ref
}
j++;
}
- if (idx == j)
+ if (idx == j) {
idx++; //force next
- else
+ } else {
idx = j; //swap
+ }
- if (j == rc)
+ if (j == rc) {
break;
+ }
}
}
@@ -368,10 +385,11 @@ bool Path3DEditorPlugin::forward_spatial_gui_input(Camera3D *p_camera, const Ref
} else {
Vector3 org;
- if (c->get_point_count() == 0)
+ if (c->get_point_count() == 0) {
org = path->get_transform().get_origin();
- else
+ } else {
org = gt.xform(c->get_point_position(c->get_point_count() - 1));
+ }
Plane p(org, p_camera->get_transform().basis.get_axis(2));
Vector3 ray_from = p_camera->project_ray_origin(mbpos);
Vector3 ray_dir = p_camera->project_ray_normal(mbpos);
@@ -481,10 +499,12 @@ void Path3DEditorPlugin::_mode_changed(int p_idx) {
void Path3DEditorPlugin::_close_curve() {
Ref<Curve3D> c = path->get_curve();
- if (c.is_null())
+ if (c.is_null()) {
return;
- if (c->get_point_count() < 2)
+ }
+ if (c->get_point_count() < 2) {
return;
+ }
c->add_point(c->get_point_position(0), c->get_point_in(0), c->get_point_out(0));
}
@@ -596,8 +616,9 @@ Ref<EditorNode3DGizmo> Path3DGizmoPlugin::create_gizmo(Node3D *p_spatial) {
Ref<Path3DGizmo> ref;
Path3D *path = Object::cast_to<Path3D>(p_spatial);
- if (path)
+ if (path) {
ref = Ref<Path3DGizmo>(memnew(Path3DGizmo(path)));
+ }
return ref;
}
diff --git a/editor/plugins/polygon_2d_editor_plugin.cpp b/editor/plugins/polygon_2d_editor_plugin.cpp
index 3fcf3131b0..7ee695b9fe 100644
--- a/editor/plugins/polygon_2d_editor_plugin.cpp
+++ b/editor/plugins/polygon_2d_editor_plugin.cpp
@@ -178,8 +178,9 @@ void Polygon2DEditor::_update_bone_list() {
cb->set_focus_mode(FOCUS_NONE);
bone_scroll_vb->add_child(cb);
- if (np == selected || bone_scroll_vb->get_child_count() < 2)
+ if (np == selected || bone_scroll_vb->get_child_count() < 2) {
cb->set_pressed(true);
+ }
cb->connect("pressed", callable_mp(this, &Polygon2DEditor::_bone_paint_selected), varray(i));
}
@@ -287,16 +288,18 @@ void Polygon2DEditor::_menu_option(int p_option) {
undo_redo->commit_action();
}
- if (EditorSettings::get_singleton()->has_setting("interface/dialogs/uv_editor_bounds"))
+ if (EditorSettings::get_singleton()->has_setting("interface/dialogs/uv_editor_bounds")) {
uv_edit->popup(EditorSettings::get_singleton()->get("interface/dialogs/uv_editor_bounds"));
- else
+ } else {
uv_edit->popup_centered_ratio(0.85);
+ }
_update_bone_list();
} break;
case UVEDIT_POLYGON_TO_UV: {
Vector<Vector2> points = node->get_polygon();
- if (points.size() == 0)
+ if (points.size() == 0) {
break;
+ }
Vector<Vector2> uvs = node->get_uv();
undo_redo->create_action(TTR("Create UV Map"));
undo_redo->add_do_method(node, "set_uv", points);
@@ -308,8 +311,9 @@ void Polygon2DEditor::_menu_option(int p_option) {
case UVEDIT_UV_TO_POLYGON: {
Vector<Vector2> points = node->get_polygon();
Vector<Vector2> uvs = node->get_uv();
- if (uvs.size() == 0)
+ if (uvs.size() == 0) {
break;
+ }
undo_redo->create_action(TTR("Create Polygon"));
undo_redo->add_do_method(node, "set_polygon", uvs);
@@ -320,8 +324,9 @@ void Polygon2DEditor::_menu_option(int p_option) {
} break;
case UVEDIT_UV_CLEAR: {
Vector<Vector2> uvs = node->get_uv();
- if (uvs.size() == 0)
+ if (uvs.size() == 0) {
break;
+ }
undo_redo->create_action(TTR("Create UV Map"));
undo_redo->add_do_method(node, "set_uv", Vector<Vector2>());
undo_redo->add_undo_method(node, "set_uv", uvs);
@@ -363,13 +368,15 @@ void Polygon2DEditor::_cancel_editing() {
}
void Polygon2DEditor::_update_polygon_editing_state() {
- if (!_get_node())
+ if (!_get_node()) {
return;
+ }
- if (node->get_internal_vertex_count() > 0)
+ if (node->get_internal_vertex_count() > 0) {
disable_polygon_editing(true, TTR("Polygon 2D has internal vertices, so it can no longer be edited in the viewport."));
- else
+ } else {
disable_polygon_editing(false, String());
+ }
}
void Polygon2DEditor::_commit_action() {
@@ -428,8 +435,9 @@ void Polygon2DEditor::_uv_mode(int p_mode) {
}
void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
- if (!_get_node())
+ if (!_get_node()) {
return;
+ }
Transform2D mtx;
mtx.elements[2] = -uv_draw_ofs;
@@ -554,8 +562,9 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
uv_create_bones_prev = node->call("_get_bones");
int internal_vertices = node->get_internal_vertex_count();
- if (internal_vertices <= 0)
+ if (internal_vertices <= 0) {
return;
+ }
int closest = -1;
float closest_dist = 1e20;
@@ -569,8 +578,9 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
}
}
- if (closest == -1)
+ if (closest == -1) {
return;
+ }
uv_create_poly_prev.remove(closest);
uv_create_uv_prev.remove(closest);
@@ -601,12 +611,13 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
}
if (uv_move_current == UV_MODE_EDIT_POINT) {
- if (mb->get_shift() && mb->get_command())
+ if (mb->get_shift() && mb->get_command()) {
uv_move_current = UV_MODE_SCALE;
- else if (mb->get_shift())
+ } else if (mb->get_shift()) {
uv_move_current = UV_MODE_MOVE;
- else if (mb->get_command())
+ } else if (mb->get_command()) {
uv_move_current = UV_MODE_ROTATE;
+ }
}
if (uv_move_current == UV_MODE_EDIT_POINT) {
@@ -676,8 +687,9 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
polys.resize(points.size());
for (int j = 0; j < polys.size(); j++) {
int idx = points[j];
- if (idx < 0 || idx >= points_prev.size())
+ if (idx < 0 || idx >= points_prev.size()) {
continue;
+ }
polys.write[j] = mtx.xform(points_prev[idx]);
}
@@ -746,8 +758,9 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
} else if (mb->get_button_index() == BUTTON_RIGHT && mb->is_pressed()) {
_cancel_editing();
- if (bone_painting)
+ if (bone_painting) {
node->set_bone_weights(bone_painting_bone, prev_weights);
+ }
uv_edit_draw->update();
@@ -789,8 +802,9 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
} break;
case UV_MODE_MOVE: {
Vector<Vector2> uv_new = points_prev;
- for (int i = 0; i < uv_new.size(); i++)
+ for (int i = 0; i < uv_new.size(); i++) {
uv_new.set(i, uv_new[i] + drag);
+ }
if (uv_edit_mode[0]->is_pressed()) { //edit uv
node->set_uv(uv_new);
@@ -802,8 +816,9 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
Vector2 center;
Vector<Vector2> uv_new = points_prev;
- for (int i = 0; i < uv_new.size(); i++)
+ for (int i = 0; i < uv_new.size(); i++) {
center += points_prev[i];
+ }
center /= uv_new.size();
float angle = (uv_drag_from - mtx.xform(center)).normalized().angle_to((uv_drag_to - mtx.xform(center)).normalized());
@@ -824,14 +839,16 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
Vector2 center;
Vector<Vector2> uv_new = points_prev;
- for (int i = 0; i < uv_new.size(); i++)
+ for (int i = 0; i < uv_new.size(); i++) {
center += points_prev[i];
+ }
center /= uv_new.size();
float from_dist = uv_drag_from.distance_to(mtx.xform(center));
float to_dist = uv_drag_to.distance_to(mtx.xform(center));
- if (from_dist < 2)
+ if (from_dist < 2) {
break;
+ }
float scale = to_dist / from_dist;
@@ -905,8 +922,9 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
}
void Polygon2DEditor::_uv_scroll_changed(float) {
- if (updating_uv_scroll)
+ if (updating_uv_scroll) {
return;
+ }
uv_draw_ofs.x = uv_hscroll->get_value();
uv_draw_ofs.y = uv_vscroll->get_value();
@@ -915,12 +933,14 @@ void Polygon2DEditor::_uv_scroll_changed(float) {
}
void Polygon2DEditor::_uv_draw() {
- if (!uv_edit->is_visible() || !_get_node())
+ if (!uv_edit->is_visible() || !_get_node()) {
return;
+ }
Ref<Texture2D> base_tex = node->get_texture();
- if (base_tex.is_null())
+ if (base_tex.is_null()) {
return;
+ }
String warning;
@@ -940,10 +960,12 @@ void Polygon2DEditor::_uv_draw() {
if (snap_step.x != 0) {
for (int i = 0; i < s.width; i++) {
int cell = Math::fast_ftoi(Math::floor((mtx.affine_inverse().xform(Vector2(i, 0)).x - snap_offset.x) / snap_step.x));
- if (i == 0)
+ if (i == 0) {
last_cell = cell;
- if (last_cell != cell)
+ }
+ if (last_cell != cell) {
uv_edit_draw->draw_line(Point2(i, 0), Point2(i, s.height), grid_color, Math::round(EDSCALE));
+ }
last_cell = cell;
}
}
@@ -951,10 +973,12 @@ void Polygon2DEditor::_uv_draw() {
if (snap_step.y != 0) {
for (int i = 0; i < s.height; i++) {
int cell = Math::fast_ftoi(Math::floor((mtx.affine_inverse().xform(Vector2(0, i)).y - snap_offset.y) / snap_step.y));
- if (i == 0)
+ if (i == 0) {
last_cell = cell;
- if (last_cell != cell)
+ }
+ if (last_cell != cell) {
uv_edit_draw->draw_line(Point2(0, i), Point2(s.width, i), grid_color, Math::round(EDSCALE));
+ }
last_cell = cell;
}
}
@@ -1036,12 +1060,14 @@ void Polygon2DEditor::_uv_draw() {
int idx = points[j];
int idx_next = points[next];
- if (idx < 0 || idx >= uvs.size())
+ if (idx < 0 || idx >= uvs.size()) {
continue;
+ }
polypoints.push_back(mtx.xform(uvs[idx]));
- if (idx_next < 0 || idx_next >= uvs.size())
+ if (idx_next < 0 || idx_next >= uvs.size()) {
continue;
+ }
uv_edit_draw->draw_line(mtx.xform(uvs[idx]), mtx.xform(uvs[idx_next]), polygon_line_color, Math::round(EDSCALE));
}
if (points.size() >= 3) {
@@ -1089,8 +1115,9 @@ void Polygon2DEditor::_uv_draw() {
if (skeleton) {
for (int i = 0; i < skeleton->get_bone_count(); i++) {
Bone2D *bone = skeleton->get_bone(i);
- if (bone->get_rest() == Transform2D(0, 0, 0, 0, 0, 0))
+ if (bone->get_rest() == Transform2D(0, 0, 0, 0, 0, 0)) {
continue; //not set
+ }
bool current = bone_path == skeleton->get_path_to(bone);
@@ -1098,8 +1125,9 @@ void Polygon2DEditor::_uv_draw() {
for (int j = 0; j < bone->get_child_count(); j++) {
Bone2D *n = Object::cast_to<Bone2D>(bone->get_child(j));
- if (!n)
+ if (!n) {
continue;
+ }
found_child = true;
diff --git a/editor/plugins/resource_preloader_editor_plugin.cpp b/editor/plugins/resource_preloader_editor_plugin.cpp
index 0d4ee492ee..75cb93ee76 100644
--- a/editor/plugins/resource_preloader_editor_plugin.cpp
+++ b/editor/plugins/resource_preloader_editor_plugin.cpp
@@ -90,8 +90,9 @@ void ResourcePreloaderEditor::_load_pressed() {
file->clear_filters();
List<String> extensions;
ResourceLoader::get_recognized_extensions_for_type("", &extensions);
- for (int i = 0; i < extensions.size(); i++)
+ for (int i = 0; i < extensions.size(); i++) {
file->add_filter("*." + extensions[i]);
+ }
file->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILES);
@@ -99,8 +100,9 @@ void ResourcePreloaderEditor::_load_pressed() {
}
void ResourcePreloaderEditor::_item_edited() {
- if (!tree->get_selected())
+ if (!tree->get_selected()) {
return;
+ }
TreeItem *s = tree->get_selected();
@@ -108,8 +110,9 @@ void ResourcePreloaderEditor::_item_edited() {
// renamed
String old_name = s->get_metadata(0);
String new_name = s->get_text(0);
- if (old_name == new_name)
+ if (old_name == new_name) {
return;
+ }
if (new_name == "" || new_name.find("\\") != -1 || new_name.find("/") != -1 || preloader->has_resource(new_name)) {
s->set_text(0, old_name);
@@ -148,10 +151,12 @@ void ResourcePreloaderEditor::_paste_pressed() {
}
String name = r->get_name();
- if (name == "")
+ if (name == "") {
name = r->get_path().get_file();
- if (name == "")
+ }
+ if (name == "") {
name = r->get_class();
+ }
String basename = name;
int counter = 1;
@@ -244,14 +249,16 @@ void ResourcePreloaderEditor::edit(ResourcePreloader *p_preloader) {
Variant ResourcePreloaderEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
TreeItem *ti = tree->get_item_at_position(p_point);
- if (!ti)
+ if (!ti) {
return Variant();
+ }
String name = ti->get_metadata(0);
RES res = preloader->get_resource(name);
- if (!res.is_valid())
+ if (!res.is_valid()) {
return Variant();
+ }
return EditorNode::get_singleton()->drag_resource(res, p_from);
}
@@ -259,11 +266,13 @@ Variant ResourcePreloaderEditor::get_drag_data_fw(const Point2 &p_point, Control
bool ResourcePreloaderEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
Dictionary d = p_data;
- if (!d.has("type"))
+ if (!d.has("type")) {
return false;
+ }
- if (d.has("from") && (Object *)(d["from"]) == tree)
+ if (d.has("from") && (Object *)(d["from"]) == tree) {
return false;
+ }
if (String(d["type"]) == "resource" && d.has("resource")) {
RES r = d["resource"];
@@ -280,13 +289,15 @@ bool ResourcePreloaderEditor::can_drop_data_fw(const Point2 &p_point, const Vari
}
void ResourcePreloaderEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
- if (!can_drop_data_fw(p_point, p_data, p_from))
+ if (!can_drop_data_fw(p_point, p_data, p_from)) {
return;
+ }
Dictionary d = p_data;
- if (!d.has("type"))
+ if (!d.has("type")) {
return;
+ }
if (String(d["type"]) == "resource" && d.has("resource")) {
RES r = d["resource"];
@@ -379,8 +390,9 @@ ResourcePreloaderEditor::ResourcePreloaderEditor() {
void ResourcePreloaderEditorPlugin::edit(Object *p_object) {
preloader_editor->set_undo_redo(&get_undo_redo());
ResourcePreloader *s = Object::cast_to<ResourcePreloader>(p_object);
- if (!s)
+ if (!s) {
return;
+ }
preloader_editor->edit(s);
}
@@ -396,8 +408,9 @@ void ResourcePreloaderEditorPlugin::make_visible(bool p_visible) {
editor->make_bottom_panel_item_visible(preloader_editor);
//preloader_editor->set_process(true);
} else {
- if (preloader_editor->is_visible_in_tree())
+ if (preloader_editor->is_visible_in_tree()) {
editor->hide_bottom_panel();
+ }
button->hide();
//preloader_editor->hide();
//preloader_editor->set_process(false);
diff --git a/editor/plugins/root_motion_editor_plugin.cpp b/editor/plugins/root_motion_editor_plugin.cpp
index 37e779fbbb..e107435373 100644
--- a/editor/plugins/root_motion_editor_plugin.cpp
+++ b/editor/plugins/root_motion_editor_plugin.cpp
@@ -34,8 +34,9 @@
void EditorPropertyRootMotion::_confirmed() {
TreeItem *ti = filters->get_selected();
- if (!ti)
+ if (!ti) {
return;
+ }
NodePath path = ti->get_metadata(0);
emit_changed(get_edited_property(), path);
@@ -117,8 +118,9 @@ void EditorPropertyRootMotion::_node_assign() {
if (base->has_node(accum)) {
node = base->get_node(accum);
}
- if (!node)
+ if (!node) {
continue; //no node, can't edit
+ }
if (path.get_subname_count()) {
String concat = path.get_concatenated_subnames();
diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp
index dbeb6e339b..8d6dac3907 100644
--- a/editor/plugins/script_editor_plugin.cpp
+++ b/editor/plugins/script_editor_plugin.cpp
@@ -141,10 +141,11 @@ public:
void ScriptEditorQuickOpen::popup_dialog(const Vector<String> &p_functions, bool p_dontclear) {
popup_centered_ratio(0.6);
- if (p_dontclear)
+ if (p_dontclear) {
search_box->select_all();
- else
+ } else {
search_box->clear();
+ }
search_box->grab_focus();
functions = p_functions;
_update_search();
@@ -175,8 +176,9 @@ void ScriptEditorQuickOpen::_update_search() {
if ((search_box->get_text() == "" || file.findn(search_box->get_text()) != -1)) {
TreeItem *ti = search_options->create_item(root);
ti->set_text(0, file);
- if (root->get_children() == ti)
+ if (root->get_children() == ti) {
ti->select(0);
+ }
}
}
@@ -185,8 +187,9 @@ void ScriptEditorQuickOpen::_update_search() {
void ScriptEditorQuickOpen::_confirmed() {
TreeItem *ti = search_options->get_selected();
- if (!ti)
+ if (!ti) {
return;
+ }
int line = ti->get_text(0).get_slice(":", 1).to_int();
emit_signal("goto_line", line - 1);
@@ -269,8 +272,9 @@ void ScriptEditor::_script_created(Ref<Script> p_script) {
void ScriptEditor::_goto_script_line2(int p_line) {
ScriptEditorBase *current = _get_current_editor();
- if (current)
+ if (current) {
current->goto_line(p_line);
+ }
}
void ScriptEditor::_goto_script_line(REF p_script, int p_line) {
@@ -294,8 +298,9 @@ void ScriptEditor::_set_execution(REF p_script, int p_line) {
if (script.is_valid() && (script->has_source_code() || script->get_path().is_resource_file())) {
for (int i = 0; i < tab_container->get_child_count(); i++) {
ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
- if (!se)
+ if (!se) {
continue;
+ }
if ((script != nullptr && se->get_edited_resource() == p_script) || se->get_edited_resource()->get_path() == script->get_path()) {
se->set_executing_line(p_line);
@@ -309,8 +314,9 @@ void ScriptEditor::_clear_execution(REF p_script) {
if (script.is_valid() && (script->has_source_code() || script->get_path().is_resource_file())) {
for (int i = 0; i < tab_container->get_child_count(); i++) {
ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
- if (!se)
+ if (!se) {
continue;
+ }
if ((script != nullptr && se->get_edited_resource() == p_script) || se->get_edited_resource()->get_path() == script->get_path()) {
se->clear_executing_line();
@@ -321,8 +327,9 @@ void ScriptEditor::_clear_execution(REF p_script) {
ScriptEditorBase *ScriptEditor::_get_current_editor() const {
int selected = tab_container->get_current_tab();
- if (selected < 0 || selected >= tab_container->get_child_count())
+ if (selected < 0 || selected >= tab_container->get_child_count()) {
return nullptr;
+ }
return Object::cast_to<ScriptEditorBase>(tab_container->get_child(selected));
}
@@ -364,8 +371,9 @@ void ScriptEditor::_go_to_tab(int p_idx) {
}
Control *c = Object::cast_to<Control>(tab_container->get_child(p_idx));
- if (!c)
+ if (!c) {
return;
+ }
if (history_pos >= 0 && history_pos < history.size() && history[history_pos].control == tab_container->get_current_tab_control()) {
Node *n = tab_container->get_current_tab_control();
@@ -393,8 +401,9 @@ void ScriptEditor::_go_to_tab(int p_idx) {
if (Object::cast_to<ScriptEditorBase>(c)) {
script_name_label->set_text(Object::cast_to<ScriptEditorBase>(c)->get_name());
script_icon->set_texture(Object::cast_to<ScriptEditorBase>(c)->get_theme_icon());
- if (is_visible_in_tree())
+ if (is_visible_in_tree()) {
Object::cast_to<ScriptEditorBase>(c)->ensure_focus();
+ }
Ref<Script> script = Object::cast_to<ScriptEditorBase>(c)->get_edited_resource();
if (script != nullptr) {
@@ -406,8 +415,9 @@ void ScriptEditor::_go_to_tab(int p_idx) {
if (Object::cast_to<EditorHelp>(c)) {
script_name_label->set_text(Object::cast_to<EditorHelp>(c)->get_class());
script_icon->set_texture(get_theme_icon("Help", "EditorIcons"));
- if (is_visible_in_tree())
+ if (is_visible_in_tree()) {
Object::cast_to<EditorHelp>(c)->set_focused();
+ }
}
c->set_meta("__editor_pass", ++edit_pass);
@@ -519,8 +529,9 @@ void ScriptEditor::_show_error_dialog(String p_path) {
void ScriptEditor::_close_tab(int p_idx, bool p_save, bool p_history_back) {
int selected = p_idx;
- if (selected < 0 || selected >= tab_container->get_child_count())
+ if (selected < 0 || selected >= tab_container->get_child_count()) {
return;
+ }
Node *tselected = tab_container->get_child(selected);
@@ -562,8 +573,9 @@ void ScriptEditor::_close_tab(int p_idx, bool p_save, bool p_history_back) {
current->clear_edit_menu();
}
memdelete(tselected);
- if (idx >= tab_container->get_child_count())
+ if (idx >= tab_container->get_child_count()) {
idx = tab_container->get_child_count() - 1;
+ }
if (idx >= 0) {
if (history_pos >= 0) {
idx = history[history_pos].control->get_index();
@@ -658,13 +670,15 @@ void ScriptEditor::_resave_scripts(const String &p_str) {
for (int i = 0; i < tab_container->get_child_count(); i++) {
ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
- if (!se)
+ if (!se) {
continue;
+ }
RES script = se->get_edited_resource();
- if (script->get_path() == "" || script->get_path().find("local://") != -1 || script->get_path().find("::") != -1)
+ if (script->get_path() == "" || script->get_path().find("local://") != -1 || script->get_path().find("::") != -1) {
continue; //internal script, who cares
+ }
if (trim_trailing_whitespace_on_save) {
se->trim_trailing_whitespace();
@@ -782,11 +796,13 @@ bool ScriptEditor::_test_script_times_on_disk(RES p_for_script) {
ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
if (se) {
RES edited_res = se->get_edited_resource();
- if (p_for_script.is_valid() && edited_res.is_valid() && p_for_script != edited_res)
+ if (p_for_script.is_valid() && edited_res.is_valid() && p_for_script != edited_res) {
continue;
+ }
- if (edited_res->get_path() == "" || edited_res->get_path().find("local://") != -1 || edited_res->get_path().find("::") != -1)
+ if (edited_res->get_path() == "" || edited_res->get_path().find("local://") != -1 || edited_res->get_path().find("::") != -1) {
continue; //internal script, who cares
+ }
uint64_t last_date = edited_res->get_last_modified_time();
uint64_t date = FileAccess::get_modified_time(edited_res->get_path());
@@ -948,8 +964,9 @@ void ScriptEditor::_menu_option(int p_option) {
return;
} break;
case FILE_REOPEN_CLOSED: {
- if (previous_scripts.empty())
+ if (previous_scripts.empty()) {
return;
+ }
String path = previous_scripts.back()->get();
previous_scripts.pop_back();
@@ -986,8 +1003,9 @@ void ScriptEditor::_menu_option(int p_option) {
} else {
Error error;
Ref<TextFile> text_file = _load_text_file(path, &error);
- if (error != OK)
+ if (error != OK) {
editor->show_warning(TTR("Could not load file at:") + "\n\n" + path, TTR("Error!"));
+ }
if (text_file.is_valid()) {
edit(text_file);
@@ -997,8 +1015,9 @@ void ScriptEditor::_menu_option(int p_option) {
}
} break;
case FILE_SAVE_ALL: {
- if (_test_script_times_on_disk())
+ if (_test_script_times_on_disk()) {
return;
+ }
save_all_scripts();
} break;
@@ -1040,11 +1059,13 @@ void ScriptEditor::_menu_option(int p_option) {
if (current) {
switch (p_option) {
case FILE_SAVE: {
- if (_test_script_times_on_disk())
+ if (_test_script_times_on_disk()) {
return;
+ }
- if (trim_trailing_whitespace_on_save)
+ if (trim_trailing_whitespace_on_save) {
current->trim_trailing_whitespace();
+ }
current->insert_final_newline();
@@ -1066,8 +1087,9 @@ void ScriptEditor::_menu_option(int p_option) {
} break;
case FILE_SAVE_AS: {
- if (trim_trailing_whitespace_on_save)
+ if (trim_trailing_whitespace_on_save) {
current->trim_trailing_whitespace();
+ }
current->insert_final_newline();
@@ -1340,10 +1362,11 @@ void ScriptEditor::_notification(int p_what) {
bool ScriptEditor::can_take_away_focus() const {
ScriptEditorBase *current = _get_current_editor();
- if (current)
+ if (current) {
return current->can_lose_focus_on_node_selection();
- else
+ } else {
return true;
+ }
}
void ScriptEditor::close_builtin_scripts_from_scene(const String &p_scene) {
@@ -1352,8 +1375,9 @@ void ScriptEditor::close_builtin_scripts_from_scene(const String &p_scene) {
if (se) {
Ref<Script> script = se->get_edited_resource();
- if (script == nullptr || !script.is_valid())
+ if (script == nullptr || !script.is_valid()) {
continue;
+ }
if (script->get_path().find("::") != -1 && script->get_path().begins_with(p_scene)) { //is an internal script and belongs to scene being closed
_close_tab(i);
@@ -1378,8 +1402,9 @@ void ScriptEditor::notify_script_changed(const Ref<Script> &p_script) {
void ScriptEditor::get_breakpoints(List<String> *p_breakpoints) {
for (int i = 0; i < tab_container->get_child_count(); i++) {
ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
- if (!se)
+ if (!se) {
continue;
+ }
Ref<Script> script = se->get_edited_resource();
if (script == nullptr) {
@@ -1398,12 +1423,14 @@ void ScriptEditor::get_breakpoints(List<String> *p_breakpoints) {
}
void ScriptEditor::ensure_focus_current() {
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
ScriptEditorBase *current = _get_current_editor();
- if (current)
+ if (current) {
current->ensure_focus();
+ }
}
void ScriptEditor::_members_overview_selected(int p_idx) {
@@ -1440,8 +1467,9 @@ void ScriptEditor::ensure_select_current() {
if (tab_container->get_child_count() && tab_container->get_current_tab() >= 0) {
ScriptEditorBase *se = _get_current_editor();
if (se) {
- if (!grab_focus_block && is_visible_in_tree())
+ if (!grab_focus_block && is_visible_in_tree()) {
se->ensure_focus();
+ }
}
}
@@ -1449,13 +1477,15 @@ void ScriptEditor::ensure_select_current() {
}
void ScriptEditor::_find_scripts(Node *p_base, Node *p_current, Set<Ref<Script>> &used) {
- if (p_current != p_base && p_current->get_owner() != p_base)
+ if (p_current != p_base && p_current->get_owner() != p_base) {
return;
+ }
if (p_current->get_script_instance()) {
Ref<Script> scr = p_current->get_script();
- if (scr.is_valid())
+ if (scr.is_valid()) {
used.insert(scr);
+ }
}
for (int i = 0; i < p_current->get_child_count(); i++) {
@@ -1568,8 +1598,9 @@ void ScriptEditor::_update_help_overview() {
help_overview->clear();
int selected = tab_container->get_current_tab();
- if (selected < 0 || selected >= tab_container->get_child_count())
+ if (selected < 0 || selected >= tab_container->get_child_count()) {
return;
+ }
Node *current = tab_container->get_child(tab_container->get_current_tab());
EditorHelp *se = Object::cast_to<EditorHelp>(current);
@@ -1595,8 +1626,9 @@ void ScriptEditor::_update_script_colors() {
for (int i = 0; i < script_list->get_item_count(); i++) {
int c = script_list->get_item_metadata(i);
Node *n = tab_container->get_child(c);
- if (!n)
+ if (!n) {
continue;
+ }
script_list->set_item_custom_bg_color(i, Color(0, 0, 0, 0));
@@ -1623,8 +1655,9 @@ void ScriptEditor::_update_script_colors() {
}
void ScriptEditor::_update_script_names() {
- if (restoring_layout)
+ if (restoring_layout) {
return;
+ }
Set<Ref<Script>> used;
Node *edited = EditorNode::get_singleton()->get_edited_scene();
@@ -1847,8 +1880,9 @@ Error ScriptEditor::_save_text_file(Ref<TextFile> p_text_file, const String &p_p
}
bool ScriptEditor::edit(const RES &p_resource, int p_line, int p_col, bool p_grab_focus) {
- if (p_resource.is_null())
+ if (p_resource.is_null()) {
return false;
+ }
Ref<Script> script = p_resource;
@@ -1863,8 +1897,9 @@ bool ScriptEditor::edit(const RES &p_resource, int p_line, int p_col, bool p_gra
if (script != nullptr && script->get_language()->overrides_external_editor()) {
if (should_open) {
Error err = script->get_language()->open_in_external_editor(script, p_line >= 0 ? p_line : 0, p_col);
- if (err != OK)
+ if (err != OK) {
ERR_PRINT("Couldn't open script in the overridden external text editor");
+ }
}
return false;
}
@@ -1923,15 +1958,17 @@ bool ScriptEditor::edit(const RES &p_resource, int p_line, int p_col, bool p_gra
}
Error err = OS::get_singleton()->execute(path, args, false);
- if (err == OK)
+ if (err == OK) {
return false;
+ }
WARN_PRINT("Couldn't open external text editor, using internal");
}
for (int i = 0; i < tab_container->get_child_count(); i++) {
ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
- if (!se)
+ if (!se) {
continue;
+ }
if ((script != nullptr && se->get_edited_resource() == p_resource) || se->get_edited_resource()->get_path() == p_resource->get_path()) {
if (should_open) {
@@ -1939,8 +1976,9 @@ bool ScriptEditor::edit(const RES &p_resource, int p_line, int p_col, bool p_gra
_go_to_tab(i);
_update_script_names();
}
- if (is_visible_in_tree())
+ if (is_visible_in_tree()) {
se->ensure_focus();
+ }
if (p_line > 0) {
se->goto_line(p_line - 1);
@@ -1958,8 +1996,9 @@ bool ScriptEditor::edit(const RES &p_resource, int p_line, int p_col, bool p_gra
for (int i = script_editor_func_count - 1; i >= 0; i--) {
se = script_editor_funcs[i](p_resource);
- if (se)
+ if (se) {
break;
+ }
}
ERR_FAIL_COND_V(!se, false);
@@ -2021,8 +2060,9 @@ bool ScriptEditor::edit(const RES &p_resource, int p_line, int p_col, bool p_gra
void ScriptEditor::save_all_scripts() {
for (int i = 0; i < tab_container->get_child_count(); i++) {
ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
- if (!se)
+ if (!se) {
continue;
+ }
if (convert_indent_on_save) {
if (use_space_indentation) {
@@ -2038,8 +2078,9 @@ void ScriptEditor::save_all_scripts() {
se->insert_final_newline();
- if (!se->is_unsaved())
+ if (!se->is_unsaved()) {
continue;
+ }
RES edited_res = se->get_edited_resource();
if (edited_res.is_valid()) {
@@ -2063,8 +2104,9 @@ void ScriptEditor::save_all_scripts() {
void ScriptEditor::apply_scripts() const {
for (int i = 0; i < tab_container->get_child_count(); i++) {
ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
- if (!se)
+ if (!se) {
continue;
+ }
se->apply_code();
}
}
@@ -2094,10 +2136,12 @@ void ScriptEditor::_add_callback(Object *p_obj, const String &p_function, const
for (int i = 0; i < tab_container->get_child_count(); i++) {
ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
- if (!se)
+ if (!se) {
continue;
- if (se->get_edited_resource() != script)
+ }
+ if (se->get_edited_resource() != script) {
continue;
+ }
se->add_callback(p_function, p_args);
@@ -2138,8 +2182,9 @@ void ScriptEditor::_editor_settings_changed() {
for (int i = 0; i < tab_container->get_child_count(); i++) {
ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
- if (!se)
+ if (!se) {
continue;
+ }
se->update_settings();
}
@@ -2168,8 +2213,9 @@ void ScriptEditor::_update_autosave_timer() {
}
void ScriptEditor::_tree_changed() {
- if (waiting_update_names)
+ if (waiting_update_names) {
return;
+ }
waiting_update_names = true;
call_deferred("_update_script_names");
@@ -2181,8 +2227,9 @@ void ScriptEditor::_script_split_dragged(float) {
}
Variant ScriptEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
- if (tab_container->get_child_count() == 0)
+ if (tab_container->get_child_count() == 0) {
return Variant();
+ }
Node *cur_node = tab_container->get_child(tab_container->get_current_tab());
@@ -2219,8 +2266,9 @@ Variant ScriptEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
bool ScriptEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
Dictionary d = p_data;
- if (!d.has("type"))
+ if (!d.has("type")) {
return false;
+ }
if (String(d["type"]) == "script_list_element") {
Node *node = d["script_list_element"];
@@ -2237,8 +2285,9 @@ bool ScriptEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data
if (String(d["type"]) == "nodes") {
Array nodes = d["nodes"];
- if (nodes.size() == 0)
+ if (nodes.size() == 0) {
return false;
+ }
Node *node = get_node((nodes[0]));
ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(node);
@@ -2254,13 +2303,15 @@ bool ScriptEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data
if (String(d["type"]) == "files") {
Vector<String> files = d["files"];
- if (files.size() == 0)
+ if (files.size() == 0) {
return false; //weird
+ }
for (int i = 0; i < files.size(); i++) {
String file = files[i];
- if (file == "" || !FileAccess::exists(file))
+ if (file == "" || !FileAccess::exists(file)) {
continue;
+ }
Ref<Script> scr = ResourceLoader::load(file);
if (scr.is_valid()) {
return true;
@@ -2273,12 +2324,14 @@ bool ScriptEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data
}
void ScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
- if (!can_drop_data_fw(p_point, p_data, p_from))
+ if (!can_drop_data_fw(p_point, p_data, p_from)) {
return;
+ }
Dictionary d = p_data;
- if (!d.has("type"))
+ if (!d.has("type")) {
return;
+ }
if (String(d["type"]) == "script_list_element") {
Node *node = d["script_list_element"];
@@ -2298,8 +2351,9 @@ void ScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Co
if (String(d["type"]) == "nodes") {
Array nodes = d["nodes"];
- if (nodes.size() == 0)
+ if (nodes.size() == 0) {
return;
+ }
Node *node = get_node(nodes[0]);
ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(node);
@@ -2325,8 +2379,9 @@ void ScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Co
int num_tabs_before = tab_container->get_child_count();
for (int i = 0; i < files.size(); i++) {
String file = files[i];
- if (file == "" || !FileAccess::exists(file))
+ if (file == "" || !FileAccess::exists(file)) {
continue;
+ }
Ref<Script> scr = ResourceLoader::load(file);
if (scr.is_valid()) {
edit(scr);
@@ -2344,8 +2399,9 @@ void ScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Co
}
void ScriptEditor::_unhandled_input(const Ref<InputEvent> &p_event) {
- if (!is_visible_in_tree() || !p_event->is_pressed() || p_event->is_echo())
+ if (!is_visible_in_tree() || !p_event->is_pressed() || p_event->is_echo()) {
return;
+ }
if (ED_IS_SHORTCUT("script_editor/next_script", p_event)) {
if (script_list->get_item_count() > 1) {
int next_tab = script_list->get_current() + 1;
@@ -2395,8 +2451,9 @@ void ScriptEditor::_make_script_list_context_menu() {
context_menu->clear();
int selected = tab_container->get_current_tab();
- if (selected < 0 || selected >= tab_container->get_child_count())
+ if (selected < 0 || selected >= tab_container->get_child_count()) {
return;
+ }
ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(selected));
if (se) {
@@ -2436,13 +2493,15 @@ void ScriptEditor::set_window_layout(Ref<ConfigFile> p_layout) {
return;
}
- if (!p_layout->has_section_key("ScriptEditor", "open_scripts") && !p_layout->has_section_key("ScriptEditor", "open_help"))
+ if (!p_layout->has_section_key("ScriptEditor", "open_scripts") && !p_layout->has_section_key("ScriptEditor", "open_help")) {
return;
+ }
Array scripts = p_layout->get_value("ScriptEditor", "open_scripts");
Array helps;
- if (p_layout->has_section_key("ScriptEditor", "open_help"))
+ if (p_layout->has_section_key("ScriptEditor", "open_help")) {
helps = p_layout->get_value("ScriptEditor", "open_help");
+ }
restoring_layout = true;
@@ -2457,8 +2516,9 @@ void ScriptEditor::set_window_layout(Ref<ConfigFile> p_layout) {
path = script_info["path"];
}
- if (!FileAccess::exists(path))
+ if (!FileAccess::exists(path)) {
continue;
+ }
if (extensions.find(path.get_extension())) {
Ref<Script> scr = ResourceLoader::load(path);
@@ -2516,8 +2576,9 @@ void ScriptEditor::get_window_layout(Ref<ConfigFile> p_layout) {
ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
if (se) {
String path = se->get_edited_resource()->get_path();
- if (!path.is_resource_file())
+ if (!path.is_resource_file()) {
continue;
+ }
Dictionary script_info;
script_info["path"] = path;
@@ -2539,8 +2600,9 @@ void ScriptEditor::get_window_layout(Ref<ConfigFile> p_layout) {
}
void ScriptEditor::_help_class_open(const String &p_class) {
- if (p_class == "")
+ if (p_class == "") {
return;
+ }
for (int i = 0; i < tab_container->get_child_count(); i++) {
EditorHelp *eh = Object::cast_to<EditorHelp>(tab_container->get_child(i));
@@ -2598,10 +2660,11 @@ void ScriptEditor::_update_selected_editor_menu() {
ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
if (se && se->get_edit_menu()) {
- if (current)
+ if (current) {
se->get_edit_menu()->show();
- else
+ } else {
se->get_edit_menu()->hide();
+ }
}
}
@@ -2677,8 +2740,9 @@ Vector<Ref<Script>> ScriptEditor::get_open_scripts() const {
for (int i = 0; i < tab_container->get_child_count(); i++) {
ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
- if (!se)
+ if (!se) {
continue;
+ }
Ref<Script> script = se->get_edited_resource();
if (script != nullptr) {
@@ -2692,8 +2756,9 @@ Vector<Ref<Script>> ScriptEditor::get_open_scripts() const {
void ScriptEditor::set_scene_root_script(Ref<Script> p_script) {
bool open_dominant = EditorSettings::get_singleton()->get("text_editor/files/open_dominant_script_on_scene_change");
- if (bool(EditorSettings::get_singleton()->get("text_editor/external/use_external_editor")))
+ if (bool(EditorSettings::get_singleton()->get("text_editor/external/use_external_editor"))) {
return;
+ }
if (open_dominant && p_script.is_valid()) {
edit(p_script);
@@ -2703,8 +2768,9 @@ void ScriptEditor::set_scene_root_script(Ref<Script> p_script) {
bool ScriptEditor::script_goto_method(Ref<Script> p_script, const String &p_method) {
int line = p_script->get_member_line(p_method);
- if (line == -1)
+ if (line == -1) {
return false;
+ }
return edit(p_script, line, 0);
}
diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp
index 1f916fb3ba..e7f8a56e5e 100644
--- a/editor/plugins/script_text_editor.cpp
+++ b/editor/plugins/script_text_editor.cpp
@@ -127,8 +127,9 @@ Vector<String> ScriptTextEditor::get_functions() {
}
void ScriptTextEditor::apply_code() {
- if (script.is_null())
+ if (script.is_null()) {
return;
+ }
script->set_source_code(code_editor->get_text_edit()->get_text());
script->update_exports();
_update_member_keywords();
@@ -161,17 +162,20 @@ void ScriptTextEditor::_update_member_keywords() {
StringName instance_base = script->get_instance_base_type();
- if (instance_base == StringName())
+ if (instance_base == StringName()) {
return;
+ }
List<PropertyInfo> plist;
ClassDB::get_property_list(instance_base, &plist);
for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) {
String name = E->get().name;
- if (E->get().usage & PROPERTY_USAGE_CATEGORY || E->get().usage & PROPERTY_USAGE_GROUP || E->get().usage & PROPERTY_USAGE_SUBGROUP)
+ if (E->get().usage & PROPERTY_USAGE_CATEGORY || E->get().usage & PROPERTY_USAGE_GROUP || E->get().usage & PROPERTY_USAGE_SUBGROUP) {
continue;
- if (name.find("/") != -1)
+ }
+ if (name.find("/") != -1) {
continue;
+ }
code_editor->get_text_edit()->add_member_keyword(name, member_variable_color);
}
@@ -264,13 +268,15 @@ void ScriptTextEditor::_load_theme_settings() {
colors_cache.string_color = string_color;
theme_loaded = true;
- if (!script.is_null())
+ if (!script.is_null()) {
_set_theme_for_script();
+ }
}
void ScriptTextEditor::_set_theme_for_script() {
- if (!theme_loaded)
+ if (!theme_loaded) {
return;
+ }
TextEdit *text_edit = code_editor->get_text_edit();
@@ -320,8 +326,9 @@ void ScriptTextEditor::_set_theme_for_script() {
for (List<StringName>::Element *E = types.front(); E; E = E->next()) {
String n = E->get();
- if (n.begins_with("_"))
+ if (n.begins_with("_")) {
n = n.substr(1, n.length());
+ }
text_edit->add_keyword_color(n, colors_cache.type_color);
}
@@ -519,10 +526,11 @@ String ScriptTextEditor::get_name() {
if (is_unsaved()) {
name += "(*)";
}
- } else if (script->get_name() != "")
+ } else if (script->get_name() != "") {
name = script->get_name();
- else
+ } else {
name = script->get_class() + "(" + itos(script->get_instance_id()) + ")";
+ }
return name;
}
@@ -710,27 +718,32 @@ static Vector<Node *> _find_all_node_for_script(Node *p_base, Node *p_current, c
}
static Node *_find_node_for_script(Node *p_base, Node *p_current, const Ref<Script> &p_script) {
- if (p_current->get_owner() != p_base && p_base != p_current)
+ if (p_current->get_owner() != p_base && p_base != p_current) {
return nullptr;
+ }
Ref<Script> c = p_current->get_script();
- if (c == p_script)
+ if (c == p_script) {
return p_current;
+ }
for (int i = 0; i < p_current->get_child_count(); i++) {
Node *found = _find_node_for_script(p_base, p_current->get_child(i), p_script);
- if (found)
+ if (found) {
return found;
+ }
}
return nullptr;
}
static void _find_changed_scripts_for_external_editor(Node *p_base, Node *p_current, Set<Ref<Script>> &r_scripts) {
- if (p_current->get_owner() != p_base && p_base != p_current)
+ if (p_current->get_owner() != p_base && p_base != p_current) {
return;
+ }
Ref<Script> c = p_current->get_script();
- if (c.is_valid())
+ if (c.is_valid()) {
r_scripts.insert(c);
+ }
for (int i = 0; i < p_current->get_child_count(); i++) {
_find_changed_scripts_for_external_editor(p_base, p_current->get_child(i), r_scripts);
@@ -738,8 +751,9 @@ static void _find_changed_scripts_for_external_editor(Node *p_base, Node *p_curr
}
void ScriptEditor::_update_modified_scripts_for_external_editor(Ref<Script> p_for_script) {
- if (!bool(EditorSettings::get_singleton()->get("text_editor/external/use_external_editor")))
+ if (!bool(EditorSettings::get_singleton()->get("text_editor/external/use_external_editor"))) {
return;
+ }
ERR_FAIL_COND(!get_tree());
@@ -753,8 +767,9 @@ void ScriptEditor::_update_modified_scripts_for_external_editor(Ref<Script> p_fo
for (Set<Ref<Script>>::Element *E = scripts.front(); E; E = E->next()) {
Ref<Script> script = E->get();
- if (p_for_script.is_valid() && p_for_script != script)
+ if (p_for_script.is_valid() && p_for_script != script) {
continue;
+ }
if (script->get_path() == "" || script->get_path().find("local://") != -1 || script->get_path().find("::") != -1) {
continue; //internal script, who cares, though weird
@@ -779,8 +794,9 @@ void ScriptTextEditor::_code_complete_scripts(void *p_ud, const String &p_code,
}
void ScriptTextEditor::_code_complete_script(const String &p_code, List<ScriptCodeCompletionOption> *r_options, bool &r_force) {
- if (color_panel->is_visible())
+ if (color_panel->is_visible()) {
return;
+ }
Node *base = get_tree()->get_edited_scene_root();
if (base) {
base = _find_node_for_script(base, base, script);
@@ -1105,15 +1121,17 @@ void ScriptTextEditor::_edit_option(int p_op) {
} break;
case EDIT_INDENT_LEFT: {
Ref<Script> scr = script;
- if (scr.is_null())
+ if (scr.is_null()) {
return;
+ }
tx->indent_left();
} break;
case EDIT_INDENT_RIGHT: {
Ref<Script> scr = script;
- if (scr.is_null())
+ if (scr.is_null()) {
return;
+ }
tx->indent_right();
} break;
@@ -1144,8 +1162,9 @@ void ScriptTextEditor::_edit_option(int p_op) {
case EDIT_AUTO_INDENT: {
String text = tx->get_text();
Ref<Script> scr = script;
- if (scr.is_null())
+ if (scr.is_null()) {
return;
+ }
tx->begin_complex_operation();
int begin, end;
@@ -1329,16 +1348,18 @@ void ScriptTextEditor::_edit_option(int p_op) {
} break;
case HELP_CONTEXTUAL: {
String text = tx->get_selection_text();
- if (text == "")
+ if (text == "") {
text = tx->get_word_under_cursor();
+ }
if (text != "") {
emit_signal("request_help", text);
}
} break;
case LOOKUP_SYMBOL: {
String text = tx->get_word_under_cursor();
- if (text == "")
+ if (text == "") {
text = tx->get_selection_text();
+ }
if (text != "") {
_lookup_symbol(text, tx->cursor_get_line(), tx->cursor_get_column());
}
@@ -1347,8 +1368,9 @@ void ScriptTextEditor::_edit_option(int p_op) {
}
void ScriptTextEditor::_edit_option_toggle_inline_comment() {
- if (script.is_null())
+ if (script.is_null()) {
return;
+ }
String delimiter = "#";
List<String> comment_delimiters;
@@ -1373,10 +1395,11 @@ void ScriptTextEditor::add_syntax_highlighter(SyntaxHighlighter *p_highlighter)
void ScriptTextEditor::set_syntax_highlighter(SyntaxHighlighter *p_highlighter) {
TextEdit *te = code_editor->get_text_edit();
te->_set_syntax_highlighting(p_highlighter);
- if (p_highlighter != nullptr)
+ if (p_highlighter != nullptr) {
highlighter_menu->set_item_checked(highlighter_menu->get_item_idx_from_text(p_highlighter->get_name()), true);
- else
+ } else {
highlighter_menu->set_item_checked(highlighter_menu->get_item_idx_from_text(TTR("Standard")), true);
+ }
}
void ScriptTextEditor::_change_syntax_highlighter(int p_idx) {
@@ -1408,8 +1431,9 @@ void ScriptTextEditor::clear_edit_menu() {
void ScriptTextEditor::reload(bool p_soft) {
TextEdit *te = code_editor->get_text_edit();
Ref<Script> scr = script;
- if (scr.is_null())
+ if (scr.is_null()) {
return;
+ }
scr->set_source_code(te->get_text());
bool soft = p_soft || scr->get_instance_base_type() == "EditorPlugin"; //always soft-reload editor plugins
@@ -1444,18 +1468,21 @@ bool ScriptTextEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_
}
static Node *_find_script_node(Node *p_edited_scene, Node *p_current_node, const Ref<Script> &script) {
- if (p_edited_scene != p_current_node && p_current_node->get_owner() != p_edited_scene)
+ if (p_edited_scene != p_current_node && p_current_node->get_owner() != p_edited_scene) {
return nullptr;
+ }
Ref<Script> scr = p_current_node->get_script();
- if (scr.is_valid() && scr == script)
+ if (scr.is_valid() && scr == script) {
return p_current_node;
+ }
for (int i = 0; i < p_current_node->get_child_count(); i++) {
Node *n = _find_script_node(p_edited_scene, p_current_node->get_child(i), script);
- if (n)
+ if (n) {
return n;
+ }
}
return nullptr;
@@ -1489,8 +1516,9 @@ void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data
String text_to_drop;
for (int i = 0; i < files.size(); i++) {
- if (i > 0)
+ if (i > 0) {
text_to_drop += ",";
+ }
text_to_drop += "\"" + String(files[i]).c_escape() + "\"";
}
@@ -1510,8 +1538,9 @@ void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data
Array nodes = d["nodes"];
String text_to_drop;
for (int i = 0; i < nodes.size(); i++) {
- if (i > 0)
+ if (i > 0) {
text_to_drop += ",";
+ }
NodePath np = nodes[i];
Node *node = get_node(np);
@@ -1568,10 +1597,12 @@ void ScriptTextEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) {
}
String word_at_pos = tx->get_word_at_pos(local_pos);
- if (word_at_pos == "")
+ if (word_at_pos == "") {
word_at_pos = tx->get_word_under_cursor();
- if (word_at_pos == "")
+ }
+ if (word_at_pos == "") {
word_at_pos = tx->get_selection_text();
+ }
bool has_color = (word_at_pos == "Color");
bool foldable = tx->can_fold(row) || tx->is_folded(row);
@@ -1672,15 +1703,18 @@ void ScriptTextEditor::_make_context_menu(bool p_selection, bool p_color, bool p
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/convert_to_lowercase"), EDIT_TO_LOWERCASE);
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/evaluate_selection"), EDIT_EVALUATE);
}
- if (p_foldable)
+ if (p_foldable) {
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_fold_line"), EDIT_TOGGLE_FOLD_LINE);
+ }
if (p_color || p_open_docs || p_goto_definition) {
context_menu->add_separator();
- if (p_open_docs)
+ if (p_open_docs) {
context_menu->add_item(TTR("Lookup Symbol"), LOOKUP_SYMBOL);
- if (p_color)
+ }
+ if (p_color) {
context_menu->add_item(TTR("Pick Color"), EDIT_PICK_COLOR);
+ }
}
context_menu->set_position(get_global_transform().xform(p_pos));
@@ -1747,10 +1781,11 @@ ScriptTextEditor::ScriptTextEditor() {
// get default color picker mode from editor settings
int default_color_mode = EDITOR_GET("interface/inspector/default_color_picker_mode");
- if (default_color_mode == 1)
+ if (default_color_mode == 1) {
color_picker->set_hsv_mode(true);
- else if (default_color_mode == 2)
+ } else if (default_color_mode == 2) {
color_picker->set_raw_mode(true);
+ }
edit_hb = memnew(HBoxContainer);
diff --git a/editor/plugins/shader_editor_plugin.cpp b/editor/plugins/shader_editor_plugin.cpp
index e0748f5237..0c3a44e4cd 100644
--- a/editor/plugins/shader_editor_plugin.cpp
+++ b/editor/plugins/shader_editor_plugin.cpp
@@ -217,13 +217,15 @@ void ShaderTextEditor::_validate_script() {
String error_text = "error(" + itos(sl.get_error_line()) + "): " + sl.get_error_text();
set_error(error_text);
set_error_pos(sl.get_error_line() - 1, 0);
- for (int i = 0; i < get_text_edit()->get_line_count(); i++)
+ for (int i = 0; i < get_text_edit()->get_line_count(); i++) {
get_text_edit()->set_line_as_marked(i, false);
+ }
get_text_edit()->set_line_as_marked(sl.get_error_line() - 1, true);
} else {
- for (int i = 0; i < get_text_edit()->get_line_count(); i++)
+ for (int i = 0; i < get_text_edit()->get_line_count(); i++) {
get_text_edit()->set_line_as_marked(i, false);
+ }
set_error("");
}
@@ -265,16 +267,18 @@ void ShaderEditor::_menu_option(int p_option) {
shader_editor->move_lines_down();
} break;
case EDIT_INDENT_LEFT: {
- if (shader.is_null())
+ if (shader.is_null()) {
return;
+ }
TextEdit *tx = shader_editor->get_text_edit();
tx->indent_left();
} break;
case EDIT_INDENT_RIGHT: {
- if (shader.is_null())
+ if (shader.is_null()) {
return;
+ }
TextEdit *tx = shader_editor->get_text_edit();
tx->indent_right();
@@ -287,8 +291,9 @@ void ShaderEditor::_menu_option(int p_option) {
shader_editor->clone_lines_down();
} break;
case EDIT_TOGGLE_COMMENT: {
- if (shader.is_null())
+ if (shader.is_null()) {
return;
+ }
shader_editor->toggle_inline_comment("//");
@@ -418,11 +423,13 @@ void ShaderEditor::_reload_shader_from_disk() {
}
void ShaderEditor::edit(const Ref<Shader> &p_shader) {
- if (p_shader.is_null() || !p_shader->is_text_shader())
+ if (p_shader.is_null() || !p_shader->is_text_shader()) {
return;
+ }
- if (shader == p_shader)
+ if (shader == p_shader) {
return;
+ }
shader = p_shader;
@@ -687,8 +694,9 @@ void ShaderEditorPlugin::make_visible(bool p_visible) {
} else {
button->hide();
- if (shader_editor->is_visible_in_tree())
+ if (shader_editor->is_visible_in_tree()) {
editor->hide_bottom_panel();
+ }
shader_editor->apply_shaders();
}
}
diff --git a/editor/plugins/shader_file_editor_plugin.cpp b/editor/plugins/shader_file_editor_plugin.cpp
index 2f9b00ee56..0ac29f68f6 100644
--- a/editor/plugins/shader_file_editor_plugin.cpp
+++ b/editor/plugins/shader_file_editor_plugin.cpp
@@ -224,8 +224,9 @@ void ShaderFileEditor::edit(const Ref<RDShaderFile> &p_shader) {
return;
}
- if (shader_file == p_shader)
+ if (shader_file == p_shader) {
return;
+ }
shader_file = p_shader;
@@ -304,8 +305,9 @@ void ShaderFileEditorPlugin::make_visible(bool p_visible) {
} else {
button->hide();
- if (shader_editor->is_visible_in_tree())
+ if (shader_editor->is_visible_in_tree()) {
editor->hide_bottom_panel();
+ }
}
}
diff --git a/editor/plugins/skeleton_ik_3d_editor_plugin.cpp b/editor/plugins/skeleton_ik_3d_editor_plugin.cpp
index 170a777523..8fc789b94a 100644
--- a/editor/plugins/skeleton_ik_3d_editor_plugin.cpp
+++ b/editor/plugins/skeleton_ik_3d_editor_plugin.cpp
@@ -33,11 +33,13 @@
#include "scene/3d/skeleton_ik_3d.h"
void SkeletonIK3DEditorPlugin::_play() {
- if (!skeleton_ik)
+ if (!skeleton_ik) {
return;
+ }
- if (!skeleton_ik->get_parent_skeleton())
+ if (!skeleton_ik->get_parent_skeleton()) {
return;
+ }
if (play_btn->is_pressed()) {
skeleton_ik->start();
@@ -56,8 +58,9 @@ void SkeletonIK3DEditorPlugin::edit(Object *p_object) {
}
SkeletonIK3D *s = Object::cast_to<SkeletonIK3D>(p_object);
- if (!s)
+ if (!s) {
return;
+ }
skeleton_ik = s;
}
@@ -67,10 +70,11 @@ bool SkeletonIK3DEditorPlugin::handles(Object *p_object) const {
}
void SkeletonIK3DEditorPlugin::make_visible(bool p_visible) {
- if (p_visible)
+ if (p_visible) {
play_btn->show();
- else
+ } else {
play_btn->hide();
+ }
}
void SkeletonIK3DEditorPlugin::_bind_methods() {
diff --git a/editor/plugins/sprite_2d_editor_plugin.cpp b/editor/plugins/sprite_2d_editor_plugin.cpp
index f09e4cb456..b21586a6b0 100644
--- a/editor/plugins/sprite_2d_editor_plugin.cpp
+++ b/editor/plugins/sprite_2d_editor_plugin.cpp
@@ -173,10 +173,11 @@ void Sprite2DEditor::_update_mesh_data() {
Ref<Image> image = texture->get_data();
ERR_FAIL_COND(image.is_null());
Rect2 rect;
- if (node->is_region())
+ if (node->is_region()) {
rect = node->get_region_rect();
- else
+ } else {
rect.size = Size2(image->get_width(), image->get_height());
+ }
Ref<BitMap> bm;
bm.instance();
@@ -218,13 +219,16 @@ void Sprite2DEditor::_update_mesh_data() {
vtx -= rect.position; //offset by rect position
//flip if flipped
- if (node->is_flipped_h())
+ if (node->is_flipped_h()) {
vtx.x = rect.size.x - vtx.x - 1.0;
- if (node->is_flipped_v())
+ }
+ if (node->is_flipped_v()) {
vtx.y = rect.size.y - vtx.y - 1.0;
+ }
- if (node->is_centered())
+ if (node->is_centered()) {
vtx -= rect.size / 2.0;
+ }
computed_vertices.push_back(vtx);
}
@@ -265,13 +269,16 @@ void Sprite2DEditor::_update_mesh_data() {
vtx -= rect.position; //offset by rect position
//flip if flipped
- if (node->is_flipped_h())
+ if (node->is_flipped_h()) {
vtx.x = rect.size.x - vtx.x - 1.0;
- if (node->is_flipped_v())
+ }
+ if (node->is_flipped_v()) {
vtx.y = rect.size.y - vtx.y - 1.0;
+ }
- if (node->is_centered())
+ if (node->is_centered()) {
vtx -= rect.size / 2.0;
+ }
col.write[i] = vtx;
}
@@ -341,8 +348,9 @@ void Sprite2DEditor::_convert_to_polygon_2d_node() {
Polygon2D *polygon_2d_instance = memnew(Polygon2D);
int total_point_count = 0;
- for (int i = 0; i < computed_outline_lines.size(); i++)
+ for (int i = 0; i < computed_outline_lines.size(); i++) {
total_point_count += computed_outline_lines[i].size();
+ }
PackedVector2Array polygon;
polygon.resize(total_point_count);
diff --git a/editor/plugins/sprite_frames_editor_plugin.cpp b/editor/plugins/sprite_frames_editor_plugin.cpp
index d869f9fcbc..859fec1628 100644
--- a/editor/plugins/sprite_frames_editor_plugin.cpp
+++ b/editor/plugins/sprite_frames_editor_plugin.cpp
@@ -153,8 +153,9 @@ void SpriteFramesEditor::_sheet_add_frames() {
Rect2 region_rect = Rect2();
- if (atlas_source && atlas_source->get_atlas().is_valid())
+ if (atlas_source && atlas_source->get_atlas().is_valid()) {
region_rect = atlas_source->get_region();
+ }
for (Set<int>::Element *E = frames_selected.front(); E; E = E->next()) {
int idx = E->get();
@@ -292,8 +293,9 @@ void SpriteFramesEditor::_load_pressed() {
file->clear_filters();
List<String> extensions;
ResourceLoader::get_recognized_extensions_for_type("Texture2D", &extensions);
- for (int i = 0; i < extensions.size(); i++)
+ for (int i = 0; i < extensions.size(); i++) {
file->add_filter("*." + extensions[i]);
+ }
file->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILES);
@@ -324,8 +326,9 @@ void SpriteFramesEditor::_paste_pressed() {
void SpriteFramesEditor::_copy_pressed() {
ERR_FAIL_COND(!frames->has_animation(edited_anim));
- if (tree->get_current() < 0)
+ if (tree->get_current() < 0) {
return;
+ }
Ref<Texture2D> r = frames->get_frame(edited_anim, tree->get_current());
if (!r.is_valid()) {
return;
@@ -383,12 +386,14 @@ void SpriteFramesEditor::_empty2_pressed() {
void SpriteFramesEditor::_up_pressed() {
ERR_FAIL_COND(!frames->has_animation(edited_anim));
- if (tree->get_current() < 0)
+ if (tree->get_current() < 0) {
return;
+ }
int to_move = tree->get_current();
- if (to_move < 1)
+ if (to_move < 1) {
return;
+ }
sel = to_move;
sel -= 1;
@@ -406,12 +411,14 @@ void SpriteFramesEditor::_up_pressed() {
void SpriteFramesEditor::_down_pressed() {
ERR_FAIL_COND(!frames->has_animation(edited_anim));
- if (tree->get_current() < 0)
+ if (tree->get_current() < 0) {
return;
+ }
int to_move = tree->get_current();
- if (to_move < 0 || to_move >= frames->get_frame_count(edited_anim) - 1)
+ if (to_move < 0 || to_move >= frames->get_frame_count(edited_anim) - 1) {
return;
+ }
sel = to_move;
sel += 1;
@@ -429,8 +436,9 @@ void SpriteFramesEditor::_down_pressed() {
void SpriteFramesEditor::_delete_pressed() {
ERR_FAIL_COND(!frames->has_animation(edited_anim));
- if (tree->get_current() < 0)
+ if (tree->get_current() < 0) {
return;
+ }
int to_delete = tree->get_current();
if (to_delete < 0 || to_delete >= frames->get_frame_count(edited_anim)) {
@@ -446,13 +454,15 @@ void SpriteFramesEditor::_delete_pressed() {
}
void SpriteFramesEditor::_animation_select() {
- if (updating)
+ if (updating) {
return;
+ }
if (frames->has_animation(edited_anim)) {
double value = anim_speed->get_line_edit()->get_text().to_double();
- if (!Math::is_equal_approx(value, frames->get_animation_speed(edited_anim)))
+ if (!Math::is_equal_approx(value, frames->get_animation_speed(edited_anim))) {
_animation_fps_changed(value);
+ }
}
TreeItem *selected = animations->get_selected();
@@ -463,10 +473,12 @@ void SpriteFramesEditor::_animation_select() {
static void _find_anim_sprites(Node *p_node, List<Node *> *r_nodes, Ref<SpriteFrames> p_sfames) {
Node *edited = EditorNode::get_singleton()->get_edited_scene();
- if (!edited)
+ if (!edited) {
return;
- if (p_node != edited && p_node->get_owner() != edited)
+ }
+ if (p_node != edited && p_node->get_owner() != edited) {
return;
+ }
{
AnimatedSprite2D *as = Object::cast_to<AnimatedSprite2D>(p_node);
@@ -488,20 +500,24 @@ static void _find_anim_sprites(Node *p_node, List<Node *> *r_nodes, Ref<SpriteFr
}
void SpriteFramesEditor::_animation_name_edited() {
- if (updating)
+ if (updating) {
return;
+ }
- if (!frames->has_animation(edited_anim))
+ if (!frames->has_animation(edited_anim)) {
return;
+ }
TreeItem *edited = animations->get_edited();
- if (!edited)
+ if (!edited) {
return;
+ }
String new_name = edited->get_text(0);
- if (new_name == String(edited_anim))
+ if (new_name == String(edited_anim)) {
return;
+ }
new_name = new_name.replace("/", "_").replace(",", " ");
@@ -563,11 +579,13 @@ void SpriteFramesEditor::_animation_add() {
}
void SpriteFramesEditor::_animation_remove() {
- if (updating)
+ if (updating) {
return;
+ }
- if (!frames->has_animation(edited_anim))
+ if (!frames->has_animation(edited_anim)) {
return;
+ }
delete_dialog->set_text(TTR("Delete Animation?"));
delete_dialog->popup_centered();
@@ -593,8 +611,9 @@ void SpriteFramesEditor::_animation_remove_confirmed() {
}
void SpriteFramesEditor::_animation_loop_changed() {
- if (updating)
+ if (updating) {
return;
+ }
undo_redo->create_action(TTR("Change Animation Loop"));
undo_redo->add_do_method(frames, "set_animation_loop", edited_anim, anim_loop->is_pressed());
@@ -605,8 +624,9 @@ void SpriteFramesEditor::_animation_loop_changed() {
}
void SpriteFramesEditor::_animation_fps_changed(double p_value) {
- if (updating)
+ if (updating) {
return;
+ }
undo_redo->create_action(TTR("Change Animation FPS"), UndoRedo::MERGE_ENDS);
undo_redo->add_do_method(frames, "set_animation_speed", edited_anim, p_value);
@@ -654,10 +674,11 @@ void SpriteFramesEditor::_update_library(bool p_skip_selector) {
return;
}
- if (sel >= frames->get_frame_count(edited_anim))
+ if (sel >= frames->get_frame_count(edited_anim)) {
sel = frames->get_frame_count(edited_anim) - 1;
- else if (sel < 0 && frames->get_frame_count(edited_anim))
+ } else if (sel < 0 && frames->get_frame_count(edited_anim)) {
sel = 0;
+ }
for (int i = 0; i < frames->get_frame_count(edited_anim); i++) {
String name;
@@ -672,10 +693,12 @@ void SpriteFramesEditor::_update_library(bool p_skip_selector) {
}
tree->add_item(name, icon);
- if (frames->get_frame(edited_anim, i).is_valid())
+ if (frames->get_frame(edited_anim, i).is_valid()) {
tree->set_item_tooltip(tree->get_item_count() - 1, frames->get_frame(edited_anim, i)->get_path());
- if (sel == i)
+ }
+ if (sel == i) {
tree->select(tree->get_item_count() - 1);
+ }
}
anim_speed->set_value(frames->get_animation_speed(edited_anim));
@@ -686,8 +709,9 @@ void SpriteFramesEditor::_update_library(bool p_skip_selector) {
}
void SpriteFramesEditor::edit(SpriteFrames *p_frames) {
- if (frames == p_frames)
+ if (frames == p_frames) {
return;
+ }
frames = p_frames;
@@ -710,18 +734,21 @@ void SpriteFramesEditor::edit(SpriteFrames *p_frames) {
}
Variant SpriteFramesEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
- if (!frames->has_animation(edited_anim))
+ if (!frames->has_animation(edited_anim)) {
return false;
+ }
int idx = tree->get_item_at_position(p_point, true);
- if (idx < 0 || idx >= frames->get_frame_count(edited_anim))
+ if (idx < 0 || idx >= frames->get_frame_count(edited_anim)) {
return Variant();
+ }
RES frame = frames->get_frame(edited_anim, idx);
- if (frame.is_null())
+ if (frame.is_null()) {
return Variant();
+ }
Dictionary drag_data = EditorNode::get_singleton()->drag_resource(frame, p_from);
drag_data["frame"] = idx; // store the frame, in case we want to reorder frames inside 'drop_data_fw'
@@ -731,12 +758,14 @@ Variant SpriteFramesEditor::get_drag_data_fw(const Point2 &p_point, Control *p_f
bool SpriteFramesEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
Dictionary d = p_data;
- if (!d.has("type"))
+ if (!d.has("type")) {
return false;
+ }
// reordering frames
- if (d.has("from") && (Object *)(d["from"]) == tree)
+ if (d.has("from") && (Object *)(d["from"]) == tree) {
return true;
+ }
if (String(d["type"]) == "resource" && d.has("resource")) {
RES r = d["resource"];
@@ -751,8 +780,9 @@ bool SpriteFramesEditor::can_drop_data_fw(const Point2 &p_point, const Variant &
if (String(d["type"]) == "files") {
Vector<String> files = d["files"];
- if (files.size() == 0)
+ if (files.size() == 0) {
return false;
+ }
for (int i = 0; i < files.size(); i++) {
String file = files[i];
@@ -769,13 +799,15 @@ bool SpriteFramesEditor::can_drop_data_fw(const Point2 &p_point, const Variant &
}
void SpriteFramesEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
- if (!can_drop_data_fw(p_point, p_data, p_from))
+ if (!can_drop_data_fw(p_point, p_data, p_from)) {
return;
+ }
Dictionary d = p_data;
- if (!d.has("type"))
+ if (!d.has("type")) {
return;
+ }
int at_pos = tree->get_item_at_position(p_point, true);
@@ -786,13 +818,15 @@ void SpriteFramesEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da
if (texture.is_valid()) {
bool reorder = false;
- if (d.has("from") && (Object *)(d["from"]) == tree)
+ if (d.has("from") && (Object *)(d["from"]) == tree) {
reorder = true;
+ }
if (reorder) { //drop is from reordering frames
int from_frame = -1;
- if (d.has("frame"))
+ if (d.has("frame")) {
from_frame = d["frame"];
+ }
undo_redo->create_action(TTR("Move Frame"));
undo_redo->add_do_method(frames, "remove_frame", edited_anim, from_frame == -1 ? frames->get_frame_count(edited_anim) : from_frame);
@@ -1060,8 +1094,9 @@ void SpriteFramesEditorPlugin::make_visible(bool p_visible) {
editor->make_bottom_panel_item_visible(frames_editor);
} else {
button->hide();
- if (frames_editor->is_visible_in_tree())
+ if (frames_editor->is_visible_in_tree()) {
editor->hide_bottom_panel();
+ }
}
}
diff --git a/editor/plugins/style_box_editor_plugin.cpp b/editor/plugins/style_box_editor_plugin.cpp
index 0d957bb101..3641052a4e 100644
--- a/editor/plugins/style_box_editor_plugin.cpp
+++ b/editor/plugins/style_box_editor_plugin.cpp
@@ -52,8 +52,9 @@ void EditorInspectorPluginStyleBox::parse_end() {
}
void StyleBoxPreview::edit(const Ref<StyleBox> &p_stylebox) {
- if (stylebox.is_valid())
+ if (stylebox.is_valid()) {
stylebox->disconnect("changed", callable_mp(this, &StyleBoxPreview::_sb_changed));
+ }
stylebox = p_stylebox;
if (p_stylebox.is_valid()) {
preview->add_theme_style_override("panel", stylebox);
diff --git a/editor/plugins/text_editor.cpp b/editor/plugins/text_editor.cpp
index f6603d268c..3ceb9bfd82 100644
--- a/editor/plugins/text_editor.cpp
+++ b/editor/plugins/text_editor.cpp
@@ -552,8 +552,9 @@ void TextEditor::_make_context_menu(bool p_selection, bool p_can_fold, bool p_is
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/convert_to_uppercase"), EDIT_TO_UPPERCASE);
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/convert_to_lowercase"), EDIT_TO_LOWERCASE);
}
- if (p_can_fold || p_is_folded)
+ if (p_can_fold || p_is_folded) {
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_fold_line"), EDIT_TOGGLE_FOLD_LINE);
+ }
context_menu->set_position(get_global_transform().xform(p_position));
context_menu->set_size(Vector2(1, 1));
diff --git a/editor/plugins/texture_editor_plugin.cpp b/editor/plugins/texture_editor_plugin.cpp
index bc4b97d40a..b728a6700c 100644
--- a/editor/plugins/texture_editor_plugin.cpp
+++ b/editor/plugins/texture_editor_plugin.cpp
@@ -57,10 +57,12 @@ void TextureEditor::_notification(int p_what) {
}
// Prevent the texture from being unpreviewable after the rescale, so that we can still see something
- if (tex_height <= 0)
+ if (tex_height <= 0) {
tex_height = 1;
- if (tex_width <= 0)
+ }
+ if (tex_width <= 0) {
tex_width = 1;
+ }
int ofs_x = (size.width - tex_width) / 2;
int ofs_y = (size.height - tex_height) / 2;
@@ -91,8 +93,9 @@ void TextureEditor::_notification(int p_what) {
Size2 rect = font->get_string_size(text);
Vector2 draw_from = size - rect + Size2(-2, font->get_ascent() - 2);
- if (draw_from.x < 0)
+ if (draw_from.x < 0) {
draw_from.x = 0;
+ }
draw_string(font, draw_from + Vector2(2, 2), text, Color(0, 0, 0, 0.5), size.width);
draw_string(font, draw_from - Vector2(2, 2), text, Color(0, 0, 0, 0.5), size.width);
@@ -101,14 +104,16 @@ void TextureEditor::_notification(int p_what) {
}
void TextureEditor::_changed_callback(Object *p_changed, const char *p_prop) {
- if (!is_visible())
+ if (!is_visible()) {
return;
+ }
update();
}
void TextureEditor::edit(Ref<Texture2D> p_texture) {
- if (!texture.is_null())
+ if (!texture.is_null()) {
texture->remove_change_receptor(this);
+ }
texture = p_texture;
diff --git a/editor/plugins/texture_layered_editor_plugin.cpp b/editor/plugins/texture_layered_editor_plugin.cpp
index e0e5bdb407..59e87fb273 100644
--- a/editor/plugins/texture_layered_editor_plugin.cpp
+++ b/editor/plugins/texture_layered_editor_plugin.cpp
@@ -64,8 +64,9 @@ void TextureLayeredEditor::_notification(int p_what) {
}
void TextureLayeredEditor::_changed_callback(Object *p_changed, const char *p_prop) {
- if (!is_visible())
+ if (!is_visible()) {
return;
+ }
update();
}
@@ -156,10 +157,12 @@ void TextureLayeredEditor::_texture_rect_update_area() {
}
// Prevent the texture from being unpreviewable after the rescale, so that we can still see something
- if (tex_height <= 0)
+ if (tex_height <= 0) {
tex_height = 1;
- if (tex_width <= 0)
+ }
+ if (tex_width <= 0) {
tex_width = 1;
+ }
int ofs_x = (size.width - tex_width) / 2;
int ofs_y = (size.height - tex_height) / 2;
@@ -169,8 +172,9 @@ void TextureLayeredEditor::_texture_rect_update_area() {
}
void TextureLayeredEditor::edit(Ref<TextureLayered> p_texture) {
- if (!texture.is_null())
+ if (!texture.is_null()) {
texture->remove_change_receptor(this);
+ }
texture = p_texture;
diff --git a/editor/plugins/texture_layered_editor_plugin.h b/editor/plugins/texture_layered_editor_plugin.h
index a620b1443c..4c5e06a5b8 100644
--- a/editor/plugins/texture_layered_editor_plugin.h
+++ b/editor/plugins/texture_layered_editor_plugin.h
@@ -35,6 +35,7 @@
#include "editor/editor_plugin.h"
#include "scene/resources/shader.h"
#include "scene/resources/texture.h"
+
class TextureLayeredEditor : public Control {
GDCLASS(TextureLayeredEditor, Control);
@@ -54,8 +55,9 @@ class TextureLayeredEditor : public Control {
void _update_material();
bool setting;
void _layer_changed(double) {
- if (!setting)
+ if (!setting) {
_update_material();
+ }
}
void _texture_rect_update_area();
diff --git a/editor/plugins/texture_region_editor_plugin.cpp b/editor/plugins/texture_region_editor_plugin.cpp
index 7176e4aa19..9b8b111be5 100644
--- a/editor/plugins/texture_region_editor_plugin.cpp
+++ b/editor/plugins/texture_region_editor_plugin.cpp
@@ -50,19 +50,21 @@ void draw_margin_line(Control *edit_draw, Vector2 from, Vector2 to) {
void TextureRegionEditor::_region_draw() {
Ref<Texture2D> base_tex = nullptr;
- if (node_sprite)
+ if (node_sprite) {
base_tex = node_sprite->get_texture();
- else if (node_sprite_3d)
+ } else if (node_sprite_3d) {
base_tex = node_sprite_3d->get_texture();
- else if (node_ninepatch)
+ } else if (node_ninepatch) {
base_tex = node_ninepatch->get_texture();
- else if (obj_styleBox.is_valid())
+ } else if (obj_styleBox.is_valid()) {
base_tex = obj_styleBox->get_texture();
- else if (atlas_tex.is_valid())
+ } else if (atlas_tex.is_valid()) {
base_tex = atlas_tex->get_atlas();
+ }
- if (base_tex.is_null())
+ if (base_tex.is_null()) {
return;
+ }
Transform2D mtx;
mtx.elements[2] = -draw_ofs * draw_zoom;
@@ -78,45 +80,55 @@ void TextureRegionEditor::_region_draw() {
int last_cell = 0;
if (snap_step.x != 0) {
- if (snap_separation.x == 0)
+ if (snap_separation.x == 0) {
for (int i = 0; i < s.width; i++) {
int cell = Math::fast_ftoi(Math::floor((mtx.affine_inverse().xform(Vector2(i, 0)).x - snap_offset.x) / snap_step.x));
- if (i == 0)
+ if (i == 0) {
last_cell = cell;
- if (last_cell != cell)
+ }
+ if (last_cell != cell) {
edit_draw->draw_line(Point2(i, 0), Point2(i, s.height), grid_color);
+ }
last_cell = cell;
}
- else
+ } else {
for (int i = 0; i < s.width; i++) {
int cell = Math::fast_ftoi(Math::floor((mtx.affine_inverse().xform(Vector2(i, 0)).x - snap_offset.x) / (snap_step.x + snap_separation.x)));
- if (i == 0)
+ if (i == 0) {
last_cell = cell;
- if (last_cell != cell)
+ }
+ if (last_cell != cell) {
edit_draw->draw_rect(Rect2(i - snap_separation.x * draw_zoom, 0, snap_separation.x * draw_zoom, s.height), grid_color);
+ }
last_cell = cell;
}
+ }
}
if (snap_step.y != 0) {
- if (snap_separation.y == 0)
+ if (snap_separation.y == 0) {
for (int i = 0; i < s.height; i++) {
int cell = Math::fast_ftoi(Math::floor((mtx.affine_inverse().xform(Vector2(0, i)).y - snap_offset.y) / snap_step.y));
- if (i == 0)
+ if (i == 0) {
last_cell = cell;
- if (last_cell != cell)
+ }
+ if (last_cell != cell) {
edit_draw->draw_line(Point2(0, i), Point2(s.width, i), grid_color);
+ }
last_cell = cell;
}
- else
+ } else {
for (int i = 0; i < s.height; i++) {
int cell = Math::fast_ftoi(Math::floor((mtx.affine_inverse().xform(Vector2(0, i)).y - snap_offset.y) / (snap_step.y + snap_separation.y)));
- if (i == 0)
+ if (i == 0) {
last_cell = cell;
- if (last_cell != cell)
+ }
+ if (last_cell != cell) {
edit_draw->draw_rect(Rect2(0, i - snap_separation.y * draw_zoom, s.width, snap_separation.y * draw_zoom), grid_color);
+ }
last_cell = cell;
}
+ }
}
} else if (snap_mode == SNAP_AUTOSLICE) {
for (List<Rect2>::Element *E = autoslice_cache.front(); E; E = E->next()) {
@@ -160,14 +172,16 @@ void TextureRegionEditor::_region_draw() {
edit_draw->draw_line(endpoints[i] - draw_ofs * draw_zoom, endpoints[next] - draw_ofs * draw_zoom, color, 2);
- if (snap_mode != SNAP_AUTOSLICE)
+ if (snap_mode != SNAP_AUTOSLICE) {
edit_draw->draw_texture(select_handle, (endpoints[i] + ofs - (select_handle->get_size() / 2)).floor() - draw_ofs * draw_zoom);
+ }
ofs = (endpoints[next] - endpoints[i]) / 2;
ofs += (endpoints[next] - endpoints[i]).tangent().normalized() * (select_handle->get_size().width / 2);
- if (snap_mode != SNAP_AUTOSLICE)
+ if (snap_mode != SNAP_AUTOSLICE) {
edit_draw->draw_texture(select_handle, (endpoints[i] + ofs - (select_handle->get_size() / 2)).floor() - draw_ofs * draw_zoom);
+ }
scroll_rect.expand_to(raw_endpoints[i]);
}
@@ -306,16 +320,17 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) {
rect = E->get();
if (Input::get_singleton()->is_key_pressed(KEY_CONTROL) && !(Input::get_singleton()->is_key_pressed(KEY_SHIFT | KEY_ALT))) {
Rect2 r;
- if (node_sprite)
+ if (node_sprite) {
r = node_sprite->get_region_rect();
- else if (node_sprite_3d)
+ } else if (node_sprite_3d) {
r = node_sprite_3d->get_region_rect();
- else if (node_ninepatch)
+ } else if (node_ninepatch) {
r = node_ninepatch->get_region_rect();
- else if (obj_styleBox.is_valid())
+ } else if (obj_styleBox.is_valid()) {
r = obj_styleBox->get_region_rect();
- else if (atlas_tex.is_valid())
+ } else if (atlas_tex.is_valid()) {
r = atlas_tex->get_region();
+ }
rect.expand_to(r.position);
rect.expand_to(r.position + r.size);
}
@@ -346,21 +361,23 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) {
}
} else if (edited_margin < 0) {
drag_from = mtx.affine_inverse().xform(Vector2(mb->get_position().x, mb->get_position().y));
- if (snap_mode == SNAP_PIXEL)
+ if (snap_mode == SNAP_PIXEL) {
drag_from = drag_from.snapped(Vector2(1, 1));
- else if (snap_mode == SNAP_GRID)
+ } else if (snap_mode == SNAP_GRID) {
drag_from = snap_point(drag_from);
+ }
drag = true;
- if (node_sprite)
+ if (node_sprite) {
rect_prev = node_sprite->get_region_rect();
- else if (node_sprite_3d)
+ } else if (node_sprite_3d) {
rect_prev = node_sprite_3d->get_region_rect();
- else if (node_ninepatch)
+ } else if (node_ninepatch) {
rect_prev = node_ninepatch->get_region_rect();
- else if (obj_styleBox.is_valid())
+ } else if (obj_styleBox.is_valid()) {
rect_prev = obj_styleBox->get_region_rect();
- else if (atlas_tex.is_valid())
+ } else if (atlas_tex.is_valid()) {
rect_prev = atlas_tex->get_region();
+ }
for (int i = 0; i < 8; i++) {
Vector2 tuv = endpoints[i];
@@ -422,10 +439,12 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) {
drag = false;
if (edited_margin >= 0) {
static Margin m[4] = { MARGIN_TOP, MARGIN_BOTTOM, MARGIN_LEFT, MARGIN_RIGHT };
- if (node_ninepatch)
+ if (node_ninepatch) {
node_ninepatch->set_patch_margin(m[edited_margin], prev_margin);
- if (obj_styleBox.is_valid())
+ }
+ if (obj_styleBox.is_valid()) {
obj_styleBox->set_margin_size(m[edited_margin], prev_margin);
+ }
edited_margin = -1;
} else {
apply_rect(rect_prev);
@@ -452,30 +471,35 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) {
} else if (drag) {
if (edited_margin >= 0) {
float new_margin = 0;
- if (edited_margin == 0)
+ if (edited_margin == 0) {
new_margin = prev_margin + (mm->get_position().y - drag_from.y) / draw_zoom;
- else if (edited_margin == 1)
+ } else if (edited_margin == 1) {
new_margin = prev_margin - (mm->get_position().y - drag_from.y) / draw_zoom;
- else if (edited_margin == 2)
+ } else if (edited_margin == 2) {
new_margin = prev_margin + (mm->get_position().x - drag_from.x) / draw_zoom;
- else if (edited_margin == 3)
+ } else if (edited_margin == 3) {
new_margin = prev_margin - (mm->get_position().x - drag_from.x) / draw_zoom;
- else
+ } else {
ERR_PRINT("Unexpected edited_margin");
+ }
- if (new_margin < 0)
+ if (new_margin < 0) {
new_margin = 0;
+ }
static Margin m[4] = { MARGIN_TOP, MARGIN_BOTTOM, MARGIN_LEFT, MARGIN_RIGHT };
- if (node_ninepatch)
+ if (node_ninepatch) {
node_ninepatch->set_patch_margin(m[edited_margin], new_margin);
- if (obj_styleBox.is_valid())
+ }
+ if (obj_styleBox.is_valid()) {
obj_styleBox->set_margin_size(m[edited_margin], new_margin);
+ }
} else {
Vector2 new_pos = mtx.affine_inverse().xform(mm->get_position());
- if (snap_mode == SNAP_PIXEL)
+ if (snap_mode == SNAP_PIXEL) {
new_pos = new_pos.snapped(Vector2(1, 1));
- else if (snap_mode == SNAP_GRID)
+ } else if (snap_mode == SNAP_GRID) {
new_pos = snap_point(new_pos);
+ }
if (creating) {
rect = Rect2(drag_from, Size2());
@@ -553,8 +577,9 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) {
}
void TextureRegionEditor::_scroll_changed(float) {
- if (updating_scroll)
+ if (updating_scroll) {
return;
+ }
draw_ofs.x = hscroll->get_value();
draw_ofs.y = vscroll->get_value();
@@ -564,10 +589,11 @@ void TextureRegionEditor::_scroll_changed(float) {
void TextureRegionEditor::_set_snap_mode(int p_mode) {
snap_mode = p_mode;
- if (snap_mode == SNAP_GRID)
+ if (snap_mode == SNAP_GRID) {
hb_grid->show();
- else
+ } else {
hb_grid->hide();
+ }
if (snap_mode == SNAP_AUTOSLICE && is_visible() && autoslice_is_dirty) {
_update_autoslice();
@@ -607,8 +633,9 @@ void TextureRegionEditor::_set_snap_sep_y(float p_val) {
}
void TextureRegionEditor::_zoom_on_position(float p_zoom, Point2 p_position) {
- if (p_zoom < 0.25 || p_zoom > 8)
+ if (p_zoom < 0.25 || p_zoom > 8) {
return;
+ }
float prev_zoom = draw_zoom;
draw_zoom = p_zoom;
@@ -633,32 +660,34 @@ void TextureRegionEditor::_zoom_out() {
}
void TextureRegionEditor::apply_rect(const Rect2 &p_rect) {
- if (node_sprite)
+ if (node_sprite) {
node_sprite->set_region_rect(p_rect);
- else if (node_sprite_3d)
+ } else if (node_sprite_3d) {
node_sprite_3d->set_region_rect(p_rect);
- else if (node_ninepatch)
+ } else if (node_ninepatch) {
node_ninepatch->set_region_rect(p_rect);
- else if (obj_styleBox.is_valid())
+ } else if (obj_styleBox.is_valid()) {
obj_styleBox->set_region_rect(p_rect);
- else if (atlas_tex.is_valid())
+ } else if (atlas_tex.is_valid()) {
atlas_tex->set_region(p_rect);
+ }
}
void TextureRegionEditor::_update_rect() {
- if (node_sprite)
+ if (node_sprite) {
rect = node_sprite->get_region_rect();
- else if (node_sprite_3d)
+ } else if (node_sprite_3d) {
rect = node_sprite_3d->get_region_rect();
- else if (node_ninepatch) {
+ } else if (node_ninepatch) {
rect = node_ninepatch->get_region_rect();
if (rect == Rect2()) {
rect = Rect2(Vector2(), node_ninepatch->get_texture()->get_size());
}
- } else if (obj_styleBox.is_valid())
+ } else if (obj_styleBox.is_valid()) {
rect = obj_styleBox->get_region_rect();
- else if (atlas_tex.is_valid())
+ } else if (atlas_tex.is_valid()) {
rect = atlas_tex->get_region();
+ }
}
void TextureRegionEditor::_update_autoslice() {
@@ -666,16 +695,17 @@ void TextureRegionEditor::_update_autoslice() {
autoslice_cache.clear();
Ref<Texture2D> texture = nullptr;
- if (node_sprite)
+ if (node_sprite) {
texture = node_sprite->get_texture();
- else if (node_sprite_3d)
+ } else if (node_sprite_3d) {
texture = node_sprite_3d->get_texture();
- else if (node_ninepatch)
+ } else if (node_ninepatch) {
texture = node_ninepatch->get_texture();
- else if (obj_styleBox.is_valid())
+ } else if (obj_styleBox.is_valid()) {
texture = obj_styleBox->get_texture();
- else if (atlas_tex.is_valid())
+ } else if (atlas_tex.is_valid()) {
texture = atlas_tex->get_atlas();
+ }
if (texture.is_null()) {
return;
@@ -700,8 +730,9 @@ void TextureRegionEditor::_update_autoslice() {
autoslice_cache.erase(F->prev());
queue_erase = false;
}
- if (F == E)
+ if (F == E) {
continue;
+ }
if (E->get().grow(1).intersects(F->get())) {
E->get().expand_to(F->get().position);
E->get().expand_to(F->get().position + F->get().size);
@@ -797,24 +828,31 @@ Sprite2D *TextureRegionEditor::get_sprite() {
}
void TextureRegionEditor::edit(Object *p_obj) {
- if (node_sprite)
+ if (node_sprite) {
node_sprite->remove_change_receptor(this);
- if (node_sprite_3d)
+ }
+ if (node_sprite_3d) {
node_sprite_3d->remove_change_receptor(this);
- if (node_ninepatch)
+ }
+ if (node_ninepatch) {
node_ninepatch->remove_change_receptor(this);
- if (obj_styleBox.is_valid())
+ }
+ if (obj_styleBox.is_valid()) {
obj_styleBox->remove_change_receptor(this);
- if (atlas_tex.is_valid())
+ }
+ if (atlas_tex.is_valid()) {
atlas_tex->remove_change_receptor(this);
+ }
if (p_obj) {
node_sprite = Object::cast_to<Sprite2D>(p_obj);
node_sprite_3d = Object::cast_to<Sprite3D>(p_obj);
node_ninepatch = Object::cast_to<NinePatchRect>(p_obj);
- if (Object::cast_to<StyleBoxTexture>(p_obj))
+ if (Object::cast_to<StyleBoxTexture>(p_obj)) {
obj_styleBox = Ref<StyleBoxTexture>(Object::cast_to<StyleBoxTexture>(p_obj));
- if (Object::cast_to<AtlasTexture>(p_obj))
+ }
+ if (Object::cast_to<AtlasTexture>(p_obj)) {
atlas_tex = Ref<AtlasTexture>(Object::cast_to<AtlasTexture>(p_obj));
+ }
p_obj->add_change_receptor(this);
_edit_region();
} else {
@@ -834,24 +872,27 @@ void TextureRegionEditor::edit(Object *p_obj) {
}
void TextureRegionEditor::_changed_callback(Object *p_changed, const char *p_prop) {
- if (!is_visible())
+ if (!is_visible()) {
return;
- if (p_prop == StringName("atlas") || p_prop == StringName("texture"))
+ }
+ if (p_prop == StringName("atlas") || p_prop == StringName("texture")) {
_edit_region();
+ }
}
void TextureRegionEditor::_edit_region() {
Ref<Texture2D> texture = nullptr;
- if (node_sprite)
+ if (node_sprite) {
texture = node_sprite->get_texture();
- else if (node_sprite_3d)
+ } else if (node_sprite_3d) {
texture = node_sprite_3d->get_texture();
- else if (node_ninepatch)
+ } else if (node_ninepatch) {
texture = node_ninepatch->get_texture();
- else if (obj_styleBox.is_valid())
+ } else if (obj_styleBox.is_valid()) {
texture = obj_styleBox->get_texture();
- else if (atlas_tex.is_valid())
+ } else if (atlas_tex.is_valid()) {
texture = atlas_tex->get_atlas();
+ }
if (texture.is_null()) {
_zoom_reset();
diff --git a/editor/plugins/theme_editor_plugin.cpp b/editor/plugins/theme_editor_plugin.cpp
index 90ef1e1507..eb028659fd 100644
--- a/editor/plugins/theme_editor_plugin.cpp
+++ b/editor/plugins/theme_editor_plugin.cpp
@@ -47,8 +47,9 @@ void ThemeEditor::_propagate_redraw(Control *p_at) {
p_at->update();
for (int i = 0; i < p_at->get_child_count(); i++) {
Control *a = Object::cast_to<Control>(p_at->get_child(i));
- if (a)
+ if (a) {
_propagate_redraw(a);
+ }
}
}
@@ -258,44 +259,50 @@ void ThemeEditor::_save_template_cbk(String fname) {
_TECategory &tc = E->get();
String underline = "; ";
- for (int i = 0; i < E->key().length(); i++)
+ for (int i = 0; i < E->key().length(); i++) {
underline += "*";
+ }
file->store_line("");
file->store_line(underline);
file->store_line("; " + E->key());
file->store_line(underline);
- if (tc.stylebox_items.size())
+ if (tc.stylebox_items.size()) {
file->store_line("\n; StyleBox Items:\n");
+ }
for (Set<_TECategory::RefItem<StyleBox>>::Element *F = tc.stylebox_items.front(); F; F = F->next()) {
file->store_line(E->key() + "." + F->get().name + " = default");
}
- if (tc.font_items.size())
+ if (tc.font_items.size()) {
file->store_line("\n; Font Items:\n");
+ }
for (Set<_TECategory::RefItem<Font>>::Element *F = tc.font_items.front(); F; F = F->next()) {
file->store_line(E->key() + "." + F->get().name + " = default");
}
- if (tc.icon_items.size())
+ if (tc.icon_items.size()) {
file->store_line("\n; Icon Items:\n");
+ }
for (Set<_TECategory::RefItem<Texture2D>>::Element *F = tc.icon_items.front(); F; F = F->next()) {
file->store_line(E->key() + "." + F->get().name + " = default");
}
- if (tc.color_items.size())
+ if (tc.color_items.size()) {
file->store_line("\n; Color Items:\n");
+ }
for (Set<_TECategory::Item<Color>>::Element *F = tc.color_items.front(); F; F = F->next()) {
file->store_line(E->key() + "." + F->get().name + " = default");
}
- if (tc.constant_items.size())
+ if (tc.constant_items.size()) {
file->store_line("\n; Constant Items:\n");
+ }
for (Set<_TECategory::Item<int>>::Element *F = tc.constant_items.front(); F; F = F->next()) {
file->store_line(E->key() + "." + F->get().name + " = default");
@@ -566,8 +573,9 @@ void ThemeEditor::_theme_menu_cbk(int p_option) {
}
}
- if (!found)
+ if (!found) {
types.push_back(F->get());
+ }
}
}
@@ -883,8 +891,9 @@ void ThemeEditorPlugin::make_visible(bool p_visible) {
editor->make_bottom_panel_item_visible(theme_editor);
} else {
theme_editor->set_process(false);
- if (theme_editor->is_visible_in_tree())
+ if (theme_editor->is_visible_in_tree()) {
editor->hide_bottom_panel();
+ }
button->hide();
}
diff --git a/editor/plugins/tile_map_editor_plugin.cpp b/editor/plugins/tile_map_editor_plugin.cpp
index 61eea6c15e..3010d72d81 100644
--- a/editor/plugins/tile_map_editor_plugin.cpp
+++ b/editor/plugins/tile_map_editor_plugin.cpp
@@ -116,8 +116,9 @@ void TileMapEditor::_update_button_tool() {
break;
}
- if (tool != TOOL_PICKING)
+ if (tool != TOOL_PICKING) {
last_tool = tool;
+ }
}
void TileMapEditor::_button_tool_select(int p_tool) {
@@ -145,8 +146,9 @@ void TileMapEditor::_menu_option(int p_option) {
}
} break;
case OPTION_ERASE_SELECTION: {
- if (!selection_active)
+ if (!selection_active) {
return;
+ }
_start_undo(TTR("Erase Selection"));
_erase_selection();
@@ -270,8 +272,9 @@ void TileMapEditor::_finish_undo() {
void TileMapEditor::_set_cell(const Point2i &p_pos, Vector<int> p_values, bool p_flip_h, bool p_flip_v, bool p_transpose, const Point2i &p_autotile_coord) {
ERR_FAIL_COND(!node);
- if (p_values.size() == 0)
+ if (p_values.size() == 0) {
return;
+ }
int p_value = p_values[Math::rand() % p_values.size()];
int prev_val = node->get_cell(p_pos.x, p_pos.y);
@@ -297,8 +300,9 @@ void TileMapEditor::_set_cell(const Point2i &p_pos, Vector<int> p_values, bool p
position = prev_position;
}
- if (p_value == prev_val && p_flip_h == prev_flip_h && p_flip_v == prev_flip_v && p_transpose == prev_transpose && prev_position == position)
+ if (p_value == prev_val && p_flip_h == prev_flip_h && p_flip_v == prev_flip_v && p_transpose == prev_transpose && prev_position == position) {
return; // Check that it's actually different.
+ }
for (int y = p_pos.y - 1; y <= p_pos.y + 1; y++) {
for (int x = p_pos.x - 1; x <= p_pos.x + 1; x++) {
@@ -311,8 +315,9 @@ void TileMapEditor::_set_cell(const Point2i &p_pos, Vector<int> p_values, bool p
node->_set_celld(p_pos, _create_cell_dictionary(p_value, p_flip_h, p_flip_v, p_transpose, p_autotile_coord));
- if (tool == TOOL_PASTING)
+ if (tool == TOOL_PASTING) {
return;
+ }
if (manual_autotile || (p_value != -1 && node->get_tileset()->tile_get_tile_mode(p_value) == TileSet::ATLAS_TILE)) {
if (current != -1) {
@@ -371,8 +376,9 @@ struct _PaletteEntry {
} // namespace
void TileMapEditor::_update_palette() {
- if (!node)
+ if (!node) {
return;
+ }
// Update the clear button.
clear_transform_button->set_disabled(!flip_h && !flip_v && !transpose);
@@ -398,8 +404,9 @@ void TileMapEditor::_update_palette() {
List<int> tiles;
tileset->get_tile_list(&tiles);
- if (tiles.empty())
+ if (tiles.empty()) {
return;
+ }
float min_size = EDITOR_DEF("editors/tile_map/preview_size", 64);
min_size *= EDSCALE;
@@ -435,8 +442,9 @@ void TileMapEditor::_update_palette() {
name = "#" + itos(E->get());
}
- if (filter != "" && !filter.is_subsequence_ofi(name))
+ if (filter != "" && !filter.is_subsequence_ofi(name)) {
continue;
+ }
const _PaletteEntry entry = { E->get(), name };
entries.push_back(entry);
@@ -474,8 +482,9 @@ void TileMapEditor::_update_palette() {
}
// Set region.
- if (region.size != Size2())
+ if (region.size != Size2()) {
palette->set_item_icon_region(palette->get_item_count() - 1, region);
+ }
// Set icon.
palette->set_item_icon(palette->get_item_count() - 1, tex);
@@ -523,8 +532,9 @@ void TileMapEditor::_update_palette() {
region.size = tileset->autotile_get_size(sel_tile); // !!
region.position += (region.size + Vector2(spacing, spacing)) * entries2[i];
- if (!region.has_no_area())
+ if (!region.has_no_area()) {
manual_palette->set_item_icon_region(manual_palette->get_item_count() - 1, region);
+ }
manual_palette->set_item_icon(manual_palette->get_item_count() - 1, tex);
}
@@ -535,10 +545,12 @@ void TileMapEditor::_update_palette() {
if (manual_palette->get_item_count() > 0) {
// Only show the manual palette if at least tile exists in it.
- if (selected_manual == -1 || selected_single != palette->get_current())
+ if (selected_manual == -1 || selected_single != palette->get_current()) {
selected_manual = 0;
- if (selected_manual < manual_palette->get_item_count())
+ }
+ if (selected_manual < manual_palette->get_item_count()) {
manual_palette->set_current(selected_manual);
+ }
manual_palette->show();
}
@@ -554,8 +566,9 @@ void TileMapEditor::_update_palette() {
void TileMapEditor::_pick_tile(const Point2 &p_pos) {
int id = node->get_cell(p_pos.x, p_pos.y);
- if (id == TileMap::INVALID_CELL)
+ if (id == TileMap::INVALID_CELL) {
return;
+ }
if (search_box->get_text() != "") {
search_box->set_text("");
@@ -586,8 +599,9 @@ Vector<Vector2> TileMapEditor::_bucket_fill(const Point2i &p_start, bool erase,
if (!erase) {
ids = get_selected_tiles();
- if (ids.size() == 0 || ids[0] == TileMap::INVALID_CELL)
+ if (ids.size() == 0 || ids[0] == TileMap::INVALID_CELL) {
return Vector<Vector2>();
+ }
} else if (prev_id == TileMap::INVALID_CELL) {
return Vector<Vector2>();
}
@@ -604,8 +618,9 @@ Vector<Vector2> TileMapEditor::_bucket_fill(const Point2i &p_start, bool erase,
// Test if we can re-use the result from preview bucket fill
bool invalidate_cache = false;
// Area changed
- if (r != bucket_cache_rect)
+ if (r != bucket_cache_rect) {
_clear_bucket_cache();
+ }
// Cache grid is not initialized
if (bucket_cache_visited == nullptr) {
bucket_cache_visited = new bool[area];
@@ -618,8 +633,9 @@ Vector<Vector2> TileMapEditor::_bucket_fill(const Point2i &p_start, bool erase,
invalidate_cache = true;
}
if (invalidate_cache) {
- for (int i = 0; i < area; ++i)
+ for (int i = 0; i < area; ++i) {
bucket_cache_visited[i] = false;
+ }
bucket_cache = Vector<Vector2>();
bucket_cache_tile = prev_id;
bucket_cache_rect = r;
@@ -644,19 +660,22 @@ Vector<Vector2> TileMapEditor::_bucket_fill(const Point2i &p_start, bool erase,
Point2i n = bucket_queue.front()->get();
bucket_queue.pop_front();
- if (!r.has_point(n))
+ if (!r.has_point(n)) {
continue;
+ }
if (node->get_cell(n.x, n.y) == prev_id) {
if (preview) {
int loc = (n.x - r.position.x) + (n.y - r.position.y) * r.get_size().x;
- if (bucket_cache_visited[loc])
+ if (bucket_cache_visited[loc]) {
continue;
+ }
bucket_cache_visited[loc] = true;
bucket_cache.push_back(n);
} else {
- if (non_preview_cache.find(n) >= 0)
+ if (non_preview_cache.find(n) >= 0) {
continue;
+ }
points.push_back(n);
non_preview_cache.push_back(n);
}
@@ -689,8 +708,9 @@ void TileMapEditor::_fill_points(const Vector<Vector2> &p_points, const Dictiona
_set_cell(pr[i], ids, xf, yf, tr);
node->make_bitmask_area_dirty(pr[i]);
}
- if (!manual_autotile)
+ if (!manual_autotile) {
node->update_dirty_bitmask();
+ }
}
void TileMapEditor::_erase_points(const Vector<Vector2> &p_points) {
@@ -720,8 +740,9 @@ void TileMapEditor::_select(const Point2i &p_from, const Point2i &p_to) {
}
void TileMapEditor::_erase_selection() {
- if (!selection_active)
+ if (!selection_active) {
return;
+ }
for (int i = rectangle.position.y; i <= rectangle.position.y + rectangle.size.y; i++) {
for (int j = rectangle.position.x; j <= rectangle.position.x + rectangle.size.x; j++) {
@@ -733,8 +754,9 @@ void TileMapEditor::_erase_selection() {
void TileMapEditor::_draw_cell(Control *p_viewport, int p_cell, const Point2i &p_point, bool p_flip_h, bool p_flip_v, bool p_transpose, const Point2i &p_autotile_coord, const Transform2D &p_xform) {
Ref<Texture2D> t = node->get_tileset()->tile_get_texture(p_cell);
- if (t.is_null())
+ if (t.is_null()) {
return;
+ }
Vector2 tile_ofs = node->get_tileset()->tile_get_texture_offset(p_cell);
@@ -771,11 +793,13 @@ void TileMapEditor::_draw_cell(Control *p_viewport, int p_cell, const Point2i &p
if (compatibility_mode_enabled && !centered_texture) {
if (rect.size.y > rect.size.x) {
- if ((p_flip_h && (p_flip_v || p_transpose)) || (p_flip_v && !p_transpose))
+ if ((p_flip_h && (p_flip_v || p_transpose)) || (p_flip_v && !p_transpose)) {
tile_ofs.y += rect.size.y - rect.size.x;
+ }
} else if (rect.size.y < rect.size.x) {
- if ((p_flip_v && (p_flip_h || p_transpose)) || (p_flip_h && !p_transpose))
+ if ((p_flip_v && (p_flip_h || p_transpose)) || (p_flip_h && !p_transpose)) {
tile_ofs.x += rect.size.x - rect.size.y;
+ }
}
}
@@ -806,29 +830,33 @@ void TileMapEditor::_draw_cell(Control *p_viewport, int p_cell, const Point2i &p
rect.position += tile_ofs;
if (p_transpose) {
- if (p_flip_h)
+ if (p_flip_h) {
rect.position.x -= cell_size.x;
- else
+ } else {
rect.position.x += cell_size.x;
+ }
} else {
- if (p_flip_v)
+ if (p_flip_v) {
rect.position.y -= cell_size.y;
- else
+ } else {
rect.position.y += cell_size.y;
+ }
}
} else if (node->get_tile_origin() == TileMap::TILE_ORIGIN_CENTER) {
rect.position += tile_ofs;
- if (p_flip_h)
+ if (p_flip_h) {
rect.position.x -= cell_size.x / 2;
- else
+ } else {
rect.position.x += cell_size.x / 2;
+ }
- if (p_flip_v)
+ if (p_flip_v) {
rect.position.y -= cell_size.y / 2;
- else
+ } else {
rect.position.y += cell_size.y / 2;
+ }
}
} else {
rect.position += tile_ofs;
@@ -867,8 +895,9 @@ void TileMapEditor::_clear_bucket_cache() {
void TileMapEditor::_update_copydata() {
copydata.clear();
- if (!selection_active)
+ if (!selection_active) {
return;
+ }
for (int i = rectangle.position.y; i <= rectangle.position.y + rectangle.size.y; i++) {
for (int j = rectangle.position.x; j <= rectangle.position.x + rectangle.size.x; j++) {
@@ -932,8 +961,9 @@ static inline Vector<Point2i> line(int x0, int x1, int y0, int y1) {
}
bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
- if (!node || !node->get_tileset().is_valid() || !node->is_visible_in_tree() || CanvasItemEditor::get_singleton()->get_current_tool() != CanvasItemEditor::TOOL_SELECT)
+ if (!node || !node->get_tileset().is_valid() || !node->is_visible_in_tree() || CanvasItemEditor::get_singleton()->get_current_tool() != CanvasItemEditor::TOOL_SELECT) {
return false;
+ }
Transform2D xform = CanvasItemEditor::get_singleton()->get_canvas_transform() * node->get_global_transform();
Transform2D xform_inv = xform.affine_inverse();
@@ -943,15 +973,17 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
if (mb.is_valid()) {
if (mb->get_button_index() == BUTTON_LEFT) {
if (mb->is_pressed()) {
- if (Input::get_singleton()->is_key_pressed(KEY_SPACE))
+ if (Input::get_singleton()->is_key_pressed(KEY_SPACE)) {
return false; // Drag.
+ }
if (tool == TOOL_NONE) {
if (mb->get_shift()) {
- if (mb->get_command())
+ if (mb->get_command()) {
tool = TOOL_RECTANGLE_PAINT;
- else
+ } else {
tool = TOOL_LINE_PAINT;
+ }
selection_active = false;
rectangle_begin = over_tile;
@@ -1051,8 +1083,9 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
} else if (tool == TOOL_BUCKET) {
Vector<Vector2> points = _bucket_fill(over_tile);
- if (points.size() == 0)
+ if (points.size() == 0) {
return false;
+ }
_start_undo(TTR("Bucket Fill"));
@@ -1109,10 +1142,11 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
_start_undo(TTR("Erase TileMap"));
if (mb->get_shift()) {
- if (mb->get_command())
+ if (mb->get_command()) {
tool = TOOL_RECTANGLE_ERASE;
- else
+ } else {
tool = TOOL_LINE_ERASE;
+ }
selection_active = false;
rectangle_begin = local;
@@ -1150,8 +1184,9 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
Vector<Vector2> points = _bucket_fill(over_tile, true);
- if (points.size() == 0)
+ if (points.size() == 0) {
return false;
+ }
undo_redo->create_action(TTR("Bucket Fill"));
@@ -1178,8 +1213,9 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
int tile_under = node->get_cell(over_tile.x, over_tile.y);
String tile_name = "none";
- if (node->get_tileset()->has_tile(tile_under))
+ if (node->get_tileset()->has_tile(tile_under)) {
tile_name = node->get_tileset()->tile_get_name(tile_under);
+ }
tile_info->show();
tile_info->set_text(String::num(over_tile.x) + ", " + String::num(over_tile.y) + " [" + tile_name + "]");
@@ -1243,8 +1279,9 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
for (int i = 0; i < points.size(); i++) {
paint_undo[points[i]] = _get_op_from_cell(points[i]);
- if (erasing)
+ if (erasing) {
_set_cell(points[i], invalid_cell);
+ }
}
CanvasItemEditor::get_singleton()->update_viewport();
@@ -1299,10 +1336,11 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
}
if (k->get_keycode() == KEY_ESCAPE) {
- if (tool == TOOL_PASTING)
+ if (tool == TOOL_PASTING) {
copydata.clear();
- else if (tool == TOOL_SELECTING || selection_active)
+ } else if (tool == TOOL_SELECTING || selection_active) {
selection_active = false;
+ }
tool = TOOL_NONE;
@@ -1439,8 +1477,9 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
}
void TileMapEditor::forward_canvas_draw_over_viewport(Control *p_overlay) {
- if (!node || CanvasItemEditor::get_singleton()->get_current_tool() != CanvasItemEditor::TOOL_SELECT)
+ if (!node || CanvasItemEditor::get_singleton()->get_current_tool() != CanvasItemEditor::TOOL_SELECT) {
return;
+ }
Transform2D cell_xf = node->get_cell_transform();
Transform2D xform = CanvasItemEditor::get_singleton()->get_canvas_transform() * node->get_global_transform();
@@ -1464,8 +1503,9 @@ void TileMapEditor::forward_canvas_draw_over_viewport(Control *p_overlay) {
Color col = i == 0 ? Color(1, 0.8, 0.2, 0.5) : Color(1, 0.3, 0.1, 0.2);
p_overlay->draw_line(from, to, col, 1);
- if (max_lines-- == 0)
+ if (max_lines-- == 0) {
break;
+ }
}
} else {
int max_lines = 10000; //avoid crash if size too small
@@ -1483,11 +1523,13 @@ void TileMapEditor::forward_canvas_draw_over_viewport(Control *p_overlay) {
Color col = i == 0 ? Color(1, 0.8, 0.2, 0.5) : Color(1, 0.3, 0.1, 0.2);
p_overlay->draw_line(from, to, col, 1);
- if (--max_lines == 0)
+ if (--max_lines == 0) {
break;
+ }
}
- if (max_lines == 0)
+ if (max_lines == 0) {
break;
+ }
}
}
@@ -1501,8 +1543,9 @@ void TileMapEditor::forward_canvas_draw_over_viewport(Control *p_overlay) {
Color col = i == 0 ? Color(1, 0.8, 0.2, 0.5) : Color(1, 0.3, 0.1, 0.2);
p_overlay->draw_line(from, to, col, 1);
- if (max_lines-- == 0)
+ if (max_lines-- == 0) {
break;
+ }
}
} else {
for (int i = (si.position.y) - 1; i <= (si.position.y + si.size.y); i++) {
@@ -1518,11 +1561,13 @@ void TileMapEditor::forward_canvas_draw_over_viewport(Control *p_overlay) {
Color col = i == 0 ? Color(1, 0.8, 0.2, 0.5) : Color(1, 0.3, 0.1, 0.2);
p_overlay->draw_line(from, to, col, 1);
- if (--max_lines == 0)
+ if (--max_lines == 0) {
break;
+ }
}
- if (max_lines == 0)
+ if (max_lines == 0) {
break;
+ }
}
}
}
@@ -1546,24 +1591,30 @@ void TileMapEditor::forward_canvas_draw_over_viewport(Control *p_overlay) {
};
for (int i = 0; i < 4; i++) {
- if (node->get_half_offset() == TileMap::HALF_OFFSET_X && ABS(over_tile.y) & 1)
+ if (node->get_half_offset() == TileMap::HALF_OFFSET_X && ABS(over_tile.y) & 1) {
endpoints[i] += cell_xf[0] * 0.5;
- if (node->get_half_offset() == TileMap::HALF_OFFSET_NEGATIVE_X && ABS(over_tile.y) & 1)
+ }
+ if (node->get_half_offset() == TileMap::HALF_OFFSET_NEGATIVE_X && ABS(over_tile.y) & 1) {
endpoints[i] += cell_xf[0] * -0.5;
- if (node->get_half_offset() == TileMap::HALF_OFFSET_Y && ABS(over_tile.x) & 1)
+ }
+ if (node->get_half_offset() == TileMap::HALF_OFFSET_Y && ABS(over_tile.x) & 1) {
endpoints[i] += cell_xf[1] * 0.5;
- if (node->get_half_offset() == TileMap::HALF_OFFSET_NEGATIVE_Y && ABS(over_tile.x) & 1)
+ }
+ if (node->get_half_offset() == TileMap::HALF_OFFSET_NEGATIVE_Y && ABS(over_tile.x) & 1) {
endpoints[i] += cell_xf[1] * -0.5;
+ }
endpoints[i] = xform.xform(endpoints[i]);
}
Color col;
- if (node->get_cell(over_tile.x, over_tile.y) != TileMap::INVALID_CELL)
+ if (node->get_cell(over_tile.x, over_tile.y) != TileMap::INVALID_CELL) {
col = Color(0.2, 0.8, 1.0, 0.8);
- else
+ } else {
col = Color(1.0, 0.4, 0.2, 0.8);
+ }
- for (int i = 0; i < 4; i++)
+ for (int i = 0; i < 4; i++) {
p_overlay->draw_line(endpoints[i], endpoints[(i + 1) % 4], col, 2);
+ }
bool bucket_preview = EditorSettings::get_singleton()->get("editors/tile_map/bucket_fill_preview");
if (tool == TOOL_SELECTING || tool == TOOL_PICKING || !bucket_preview) {
@@ -1571,13 +1622,15 @@ void TileMapEditor::forward_canvas_draw_over_viewport(Control *p_overlay) {
}
if (tool == TOOL_LINE_PAINT) {
- if (paint_undo.empty())
+ if (paint_undo.empty()) {
return;
+ }
Vector<int> ids = get_selected_tiles();
- if (ids.size() == 1 && ids[0] == TileMap::INVALID_CELL)
+ if (ids.size() == 1 && ids[0] == TileMap::INVALID_CELL) {
return;
+ }
for (Map<Point2i, CellOp>::Element *E = paint_undo.front(); E; E = E->next()) {
_draw_cell(p_overlay, ids[0], E->key(), flip_h, flip_v, transpose, autotile_coord, xform);
@@ -1586,8 +1639,9 @@ void TileMapEditor::forward_canvas_draw_over_viewport(Control *p_overlay) {
} else if (tool == TOOL_RECTANGLE_PAINT) {
Vector<int> ids = get_selected_tiles();
- if (ids.size() == 1 && ids[0] == TileMap::INVALID_CELL)
+ if (ids.size() == 1 && ids[0] == TileMap::INVALID_CELL) {
return;
+ }
for (int i = rectangle.position.y; i <= rectangle.position.y + rectangle.size.y; i++) {
for (int j = rectangle.position.x; j <= rectangle.position.x + rectangle.size.x; j++) {
@@ -1595,19 +1649,22 @@ void TileMapEditor::forward_canvas_draw_over_viewport(Control *p_overlay) {
}
}
} else if (tool == TOOL_PASTING) {
- if (copydata.empty())
+ if (copydata.empty()) {
return;
+ }
Ref<TileSet> ts = node->get_tileset();
- if (ts.is_null())
+ if (ts.is_null()) {
return;
+ }
Point2 ofs = over_tile - rectangle.position;
for (List<TileData>::Element *E = copydata.front(); E; E = E->next()) {
- if (!ts->has_tile(E->get().cell))
+ if (!ts->has_tile(E->get().cell)) {
continue;
+ }
TileData tcd = E->get();
@@ -1632,8 +1689,9 @@ void TileMapEditor::forward_canvas_draw_over_viewport(Control *p_overlay) {
} else {
Vector<int> st = get_selected_tiles();
- if (st.size() == 1 && st[0] == TileMap::INVALID_CELL)
+ if (st.size() == 1 && st[0] == TileMap::INVALID_CELL) {
return;
+ }
_draw_cell(p_overlay, st[0], over_tile, flip_h, flip_v, transpose, autotile_coord, xform);
}
@@ -1647,30 +1705,36 @@ void TileMapEditor::edit(Node *p_tile_map) {
canvas_item_editor_viewport = CanvasItemEditor::get_singleton()->get_viewport_control();
}
- if (node)
+ if (node) {
node->disconnect("settings_changed", callable_mp(this, &TileMapEditor::_tileset_settings_changed));
+ }
if (p_tile_map) {
node = Object::cast_to<TileMap>(p_tile_map);
- if (!canvas_item_editor_viewport->is_connected("mouse_entered", callable_mp(this, &TileMapEditor::_canvas_mouse_enter)))
+ if (!canvas_item_editor_viewport->is_connected("mouse_entered", callable_mp(this, &TileMapEditor::_canvas_mouse_enter))) {
canvas_item_editor_viewport->connect("mouse_entered", callable_mp(this, &TileMapEditor::_canvas_mouse_enter));
- if (!canvas_item_editor_viewport->is_connected("mouse_exited", callable_mp(this, &TileMapEditor::_canvas_mouse_exit)))
+ }
+ if (!canvas_item_editor_viewport->is_connected("mouse_exited", callable_mp(this, &TileMapEditor::_canvas_mouse_exit))) {
canvas_item_editor_viewport->connect("mouse_exited", callable_mp(this, &TileMapEditor::_canvas_mouse_exit));
+ }
_update_palette();
} else {
node = nullptr;
- if (canvas_item_editor_viewport->is_connected("mouse_entered", callable_mp(this, &TileMapEditor::_canvas_mouse_enter)))
+ if (canvas_item_editor_viewport->is_connected("mouse_entered", callable_mp(this, &TileMapEditor::_canvas_mouse_enter))) {
canvas_item_editor_viewport->disconnect("mouse_entered", callable_mp(this, &TileMapEditor::_canvas_mouse_enter));
- if (canvas_item_editor_viewport->is_connected("mouse_exited", callable_mp(this, &TileMapEditor::_canvas_mouse_exit)))
+ }
+ if (canvas_item_editor_viewport->is_connected("mouse_exited", callable_mp(this, &TileMapEditor::_canvas_mouse_exit))) {
canvas_item_editor_viewport->disconnect("mouse_exited", callable_mp(this, &TileMapEditor::_canvas_mouse_exit));
+ }
_update_palette();
}
- if (node)
+ if (node) {
node->connect("settings_changed", callable_mp(this, &TileMapEditor::_tileset_settings_changed));
+ }
_clear_bucket_cache();
}
@@ -1697,12 +1761,15 @@ TileMapEditor::CellOp TileMapEditor::_get_op_from_cell(const Point2i &p_pos) {
CellOp op;
op.idx = node->get_cell(p_pos.x, p_pos.y);
if (op.idx != TileMap::INVALID_CELL) {
- if (node->is_cell_x_flipped(p_pos.x, p_pos.y))
+ if (node->is_cell_x_flipped(p_pos.x, p_pos.y)) {
op.xf = true;
- if (node->is_cell_y_flipped(p_pos.x, p_pos.y))
+ }
+ if (node->is_cell_y_flipped(p_pos.x, p_pos.y)) {
op.yf = true;
- if (node->is_cell_transposed(p_pos.x, p_pos.y))
+ }
+ if (node->is_cell_transposed(p_pos.x, p_pos.y)) {
op.tr = true;
+ }
op.ac = node->get_cell_autotile_coord(p_pos.x, p_pos.y);
}
return op;
diff --git a/editor/plugins/tile_set_editor_plugin.cpp b/editor/plugins/tile_set_editor_plugin.cpp
index 9ab7e7ae8a..644facd5bd 100644
--- a/editor/plugins/tile_set_editor_plugin.cpp
+++ b/editor/plugins/tile_set_editor_plugin.cpp
@@ -63,8 +63,9 @@ void TileSetEditor::_import_node(Node *p_node, Ref<TileSet> p_library) {
Ref<Texture2D> normal_map = mi->get_normal_map();
Ref<ShaderMaterial> material = mi->get_material();
- if (texture.is_null())
+ if (texture.is_null()) {
continue;
+ }
int id = p_library->find_tile_by_name(mi->get_name());
if (id < 0) {
@@ -104,14 +105,17 @@ void TileSetEditor::_import_node(Node *p_node, Ref<TileSet> p_library) {
for (int j = 0; j < mi->get_child_count(); j++) {
Node *child2 = mi->get_child(j);
- if (Object::cast_to<NavigationRegion2D>(child2))
+ if (Object::cast_to<NavigationRegion2D>(child2)) {
nav_poly = Object::cast_to<NavigationRegion2D>(child2)->get_navigation_polygon();
+ }
- if (Object::cast_to<LightOccluder2D>(child2))
+ if (Object::cast_to<LightOccluder2D>(child2)) {
occluder = Object::cast_to<LightOccluder2D>(child2)->get_occluder_polygon();
+ }
- if (!Object::cast_to<StaticBody2D>(child2))
+ if (!Object::cast_to<StaticBody2D>(child2)) {
continue;
+ }
found_collisions = true;
@@ -121,8 +125,9 @@ void TileSetEditor::_import_node(Node *p_node, Ref<TileSet> p_library) {
sb->get_shape_owners(&shapes);
for (List<uint32_t>::Element *E = shapes.front(); E; E = E->next()) {
- if (sb->is_shape_owner_disabled(E->get()))
+ if (sb->is_shape_owner_disabled(E->get())) {
continue;
+ }
Transform2D shape_transform = sb->get_transform() * sb->shape_owner_get_transform(E->get());
bool one_way = sb->is_shape_owner_one_way_collision_enabled(E->get());
@@ -154,8 +159,9 @@ void TileSetEditor::_import_node(Node *p_node, Ref<TileSet> p_library) {
}
void TileSetEditor::_import_scene(Node *p_scene, Ref<TileSet> p_library, bool p_merge) {
- if (!p_merge)
+ if (!p_merge) {
p_library->clear();
+ }
_import_node(p_scene, p_library);
}
@@ -176,11 +182,13 @@ Variant TileSetEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from)
bool TileSetEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
Dictionary d = p_data;
- if (!d.has("type"))
+ if (!d.has("type")) {
return false;
+ }
- if (d.has("from") && (Object *)(d["from"]) == texture_list)
+ if (d.has("from") && (Object *)(d["from"]) == texture_list) {
return false;
+ }
if (String(d["type"]) == "resource" && d.has("resource")) {
RES r = d["resource"];
@@ -195,8 +203,9 @@ bool TileSetEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_dat
if (String(d["type"]) == "files") {
Vector<String> files = d["files"];
- if (files.size() == 0)
+ if (files.size() == 0) {
return false;
+ }
for (int i = 0; i < files.size(); i++) {
String file = files[i];
@@ -213,21 +222,24 @@ bool TileSetEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_dat
}
void TileSetEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
- if (!can_drop_data_fw(p_point, p_data, p_from))
+ if (!can_drop_data_fw(p_point, p_data, p_from)) {
return;
+ }
Dictionary d = p_data;
- if (!d.has("type"))
+ if (!d.has("type")) {
return;
+ }
if (String(d["type"]) == "resource" && d.has("resource")) {
RES r = d["resource"];
Ref<Texture2D> texture = r;
- if (texture.is_valid())
+ if (texture.is_valid()) {
add_texture(texture);
+ }
if (texture_list->get_item_count() > 0) {
update_texture_list_icon();
@@ -622,8 +634,9 @@ TileSetEditor::TileSetEditor(EditorNode *p_editor) {
}
TileSetEditor::~TileSetEditor() {
- if (helper)
+ if (helper) {
memdelete(helper);
+ }
}
void TileSetEditor::_on_tileset_toolbar_button_pressed(int p_index) {
@@ -675,8 +688,9 @@ void TileSetEditor::_on_tileset_toolbar_confirm() {
case TOOL_TILESET_CREATE_SCENE: {
EditorNode *en = editor;
Node *scene = en->get_edited_scene();
- if (!scene)
+ if (!scene) {
break;
+ }
List<int> ids;
tileset->get_tile_list(&ids);
@@ -871,8 +885,9 @@ void TileSetEditor::_on_workspace_mode_changed(int p_workspace_mode) {
}
void TileSetEditor::_on_workspace_draw() {
- if (tileset.is_null() || !get_current_texture().is_valid())
+ if (tileset.is_null() || !get_current_texture().is_valid()) {
return;
+ }
const Color COLOR_AUTOTILE = Color(0.3, 0.6, 1);
const Color COLOR_SINGLE = Color(1, 1, 0.3);
@@ -1031,12 +1046,13 @@ void TileSetEditor::_on_workspace_draw() {
Rect2i region = tileset->tile_get_region(t_id);
region.position += WORKSPACE_MARGIN;
Color c;
- if (tileset->tile_get_tile_mode(t_id) == TileSet::SINGLE_TILE)
+ if (tileset->tile_get_tile_mode(t_id) == TileSet::SINGLE_TILE) {
c = COLOR_SINGLE;
- else if (tileset->tile_get_tile_mode(t_id) == TileSet::AUTO_TILE)
+ } else if (tileset->tile_get_tile_mode(t_id) == TileSet::AUTO_TILE) {
c = COLOR_AUTOTILE;
- else if (tileset->tile_get_tile_mode(t_id) == TileSet::ATLAS_TILE)
+ } else if (tileset->tile_get_tile_mode(t_id) == TileSet::ATLAS_TILE) {
c = COLOR_ATLAS;
+ }
draw_tile_subdivision(t_id, COLOR_SUBDIVISION);
workspace->draw_rect(region, c, false);
}
@@ -1047,39 +1063,43 @@ void TileSetEditor::_on_workspace_draw() {
if (workspace_mode != WORKSPACE_EDIT) {
Rect2i region = edited_region;
Color c;
- if (workspace_mode == WORKSPACE_CREATE_SINGLE)
+ if (workspace_mode == WORKSPACE_CREATE_SINGLE) {
c = COLOR_SINGLE;
- else if (workspace_mode == WORKSPACE_CREATE_AUTOTILE)
+ } else if (workspace_mode == WORKSPACE_CREATE_AUTOTILE) {
c = COLOR_AUTOTILE;
- else if (workspace_mode == WORKSPACE_CREATE_ATLAS)
+ } else if (workspace_mode == WORKSPACE_CREATE_ATLAS) {
c = COLOR_ATLAS;
+ }
workspace->draw_rect(region, c, false);
draw_edited_region_subdivision();
} else {
int t_id = get_current_tile();
- if (t_id < 0)
+ if (t_id < 0) {
return;
+ }
Rect2i region;
- if (draw_edited_region)
+ if (draw_edited_region) {
region = edited_region;
- else {
+ } else {
region = tileset->tile_get_region(t_id);
region.position += WORKSPACE_MARGIN;
}
- if (draw_edited_region)
+ if (draw_edited_region) {
draw_edited_region_subdivision();
- else
+ } else {
draw_tile_subdivision(t_id, COLOR_SUBDIVISION);
+ }
Color c;
- if (tileset->tile_get_tile_mode(t_id) == TileSet::SINGLE_TILE)
+ if (tileset->tile_get_tile_mode(t_id) == TileSet::SINGLE_TILE) {
c = COLOR_SINGLE;
- else if (tileset->tile_get_tile_mode(t_id) == TileSet::AUTO_TILE)
+ } else if (tileset->tile_get_tile_mode(t_id) == TileSet::AUTO_TILE) {
c = COLOR_AUTOTILE;
- else if (tileset->tile_get_tile_mode(t_id) == TileSet::ATLAS_TILE)
+ } else if (tileset->tile_get_tile_mode(t_id) == TileSet::ATLAS_TILE) {
c = COLOR_ATLAS;
+ }
workspace->draw_rect(region, c, false);
}
}
@@ -1100,8 +1120,9 @@ void TileSetEditor::_on_workspace_process() {
}
void TileSetEditor::_on_workspace_overlay_draw() {
- if (!tileset.is_valid() || !get_current_texture().is_valid())
+ if (!tileset.is_valid() || !get_current_texture().is_valid()) {
return;
+ }
const Color COLOR_AUTOTILE = Color(0.266373, 0.565288, 0.988281);
const Color COLOR_SINGLE = Color(0.988281, 0.909323, 0.266373);
@@ -1113,19 +1134,21 @@ void TileSetEditor::_on_workspace_overlay_draw() {
tileset->get_tile_list(tiles);
for (List<int>::Element *E = tiles->front(); E; E = E->next()) {
int t_id = E->get();
- if (tileset->tile_get_texture(t_id)->get_rid() != current_texture_rid)
+ if (tileset->tile_get_texture(t_id)->get_rid() != current_texture_rid) {
continue;
+ }
Rect2 region = tileset->tile_get_region(t_id);
region.position += WORKSPACE_MARGIN;
region.position *= workspace->get_scale().x;
Color c;
- if (tileset->tile_get_tile_mode(t_id) == TileSet::SINGLE_TILE)
+ if (tileset->tile_get_tile_mode(t_id) == TileSet::SINGLE_TILE) {
c = COLOR_SINGLE;
- else if (tileset->tile_get_tile_mode(t_id) == TileSet::AUTO_TILE)
+ } else if (tileset->tile_get_tile_mode(t_id) == TileSet::AUTO_TILE) {
c = COLOR_AUTOTILE;
- else if (tileset->tile_get_tile_mode(t_id) == TileSet::ATLAS_TILE)
+ } else if (tileset->tile_get_tile_mode(t_id) == TileSet::ATLAS_TILE) {
c = COLOR_ATLAS;
+ }
String tile_id_name = String::num(t_id, 0) + ": " + tileset->tile_get_name(t_id);
Ref<Font> font = get_theme_font("font", "Label");
region.set_size(font->get_string_size(tile_id_name));
@@ -1138,8 +1161,9 @@ void TileSetEditor::_on_workspace_overlay_draw() {
}
int t_id = get_current_tile();
- if (t_id < 0)
+ if (t_id < 0) {
return;
+ }
Ref<Texture2D> handle = get_theme_icon("EditorHandle", "EditorIcons");
if (draw_handles) {
@@ -1175,8 +1199,9 @@ bool TileSetEditor::is_within_grabbing_distance_of_first_point(const Vector2 &p_
}
void TileSetEditor::_on_workspace_input(const Ref<InputEvent> &p_ie) {
- if (tileset.is_null() || !get_current_texture().is_valid())
+ if (tileset.is_null() || !get_current_texture().is_valid()) {
return;
+ }
static bool dragging;
static bool erasing;
@@ -1879,8 +1904,9 @@ void TileSetEditor::_on_tool_clicked(int p_tool) {
}
void TileSetEditor::_on_priority_changed(float val) {
- if ((int)val == tileset->autotile_get_subtile_priority(get_current_tile(), edited_shape_coord))
+ if ((int)val == tileset->autotile_get_subtile_priority(get_current_tile(), edited_shape_coord)) {
return;
+ }
undo_redo->create_action(TTR("Edit Tile Priority"));
undo_redo->add_do_method(tileset.ptr(), "autotile_set_subtile_priority", get_current_tile(), edited_shape_coord, (int)val);
@@ -1891,8 +1917,9 @@ void TileSetEditor::_on_priority_changed(float val) {
}
void TileSetEditor::_on_z_index_changed(float val) {
- if ((int)val == tileset->autotile_get_z_index(get_current_tile(), edited_shape_coord))
+ if ((int)val == tileset->autotile_get_z_index(get_current_tile(), edited_shape_coord)) {
return;
+ }
undo_redo->create_action(TTR("Edit Tile Z Index"));
undo_redo->add_do_method(tileset.ptr(), "autotile_set_z_index", get_current_tile(), edited_shape_coord, (int)val);
@@ -1948,8 +1975,9 @@ void TileSetEditor::_set_edited_shape_points(const Vector<Vector2> &points) {
void TileSetEditor::_update_tile_data() {
current_tile_data.clear();
- if (get_current_tile() < 0)
+ if (get_current_tile() < 0) {
return;
+ }
Vector<TileSet::ShapeData> sd = tileset->tile_get_shapes(get_current_tile());
if (tileset->tile_get_tile_mode(get_current_tile()) == TileSet::SINGLE_TILE) {
@@ -2293,8 +2321,9 @@ void TileSetEditor::_set_snap_sep(Vector2 p_val) {
}
void TileSetEditor::_validate_current_tile_id() {
- if (get_current_tile() >= 0 && !tileset->has_tile(get_current_tile()))
+ if (get_current_tile() >= 0 && !tileset->has_tile(get_current_tile())) {
set_current_tile(-1);
+ }
}
void TileSetEditor::_select_edited_shape_coord() {
@@ -2386,14 +2415,18 @@ void TileSetEditor::draw_highlight_current_tile() {
region = edited_region;
}
- if (region.position.y >= 0)
+ if (region.position.y >= 0) {
workspace->draw_rect(Rect2(0, 0, workspace->get_rect().size.x, region.position.y), shadow_color);
- if (region.position.x >= 0)
+ }
+ if (region.position.x >= 0) {
workspace->draw_rect(Rect2(0, MAX(0, region.position.y), region.position.x, MIN(workspace->get_rect().size.y - region.position.y, MIN(region.size.y, region.position.y + region.size.y))), shadow_color);
- if (region.position.x + region.size.x <= workspace->get_rect().size.x)
+ }
+ if (region.position.x + region.size.x <= workspace->get_rect().size.x) {
workspace->draw_rect(Rect2(region.position.x + region.size.x, MAX(0, region.position.y), workspace->get_rect().size.x - region.position.x - region.size.x, MIN(workspace->get_rect().size.y - region.position.y, MIN(region.size.y, region.position.y + region.size.y))), shadow_color);
- if (region.position.y + region.size.y <= workspace->get_rect().size.y)
+ }
+ if (region.position.y + region.size.y <= workspace->get_rect().size.y) {
workspace->draw_rect(Rect2(0, region.position.y + region.size.y, workspace->get_rect().size.x, workspace->get_rect().size.y - region.size.y - region.position.y), shadow_color);
+ }
} else {
workspace->draw_rect(Rect2(Point2(0, 0), workspace->get_rect().size), shadow_color);
}
@@ -2409,14 +2442,18 @@ void TileSetEditor::draw_highlight_subtile(Vector2 coord, const Vector<Vector2>
coord += region.position;
coord += WORKSPACE_MARGIN;
- if (coord.y >= 0)
+ if (coord.y >= 0) {
workspace->draw_rect(Rect2(0, 0, workspace->get_rect().size.x, coord.y), shadow_color);
- if (coord.x >= 0)
+ }
+ if (coord.x >= 0) {
workspace->draw_rect(Rect2(0, MAX(0, coord.y), coord.x, MIN(workspace->get_rect().size.y - coord.y, MIN(size.y, coord.y + size.y))), shadow_color);
- if (coord.x + size.x <= workspace->get_rect().size.x)
+ }
+ if (coord.x + size.x <= workspace->get_rect().size.x) {
workspace->draw_rect(Rect2(coord.x + size.x, MAX(0, coord.y), workspace->get_rect().size.x - coord.x - size.x, MIN(workspace->get_rect().size.y - coord.y, MIN(size.y, coord.y + size.y))), shadow_color);
- if (coord.y + size.y <= workspace->get_rect().size.y)
+ }
+ if (coord.y + size.y <= workspace->get_rect().size.y) {
workspace->draw_rect(Rect2(0, coord.y + size.y, workspace->get_rect().size.x, workspace->get_rect().size.y - size.y - coord.y), shadow_color);
+ }
coord += Vector2(1, 1) / workspace->get_scale().x;
workspace->draw_rect(Rect2(coord, size - Vector2(2, 2) / workspace->get_scale().x), Color(1, 0, 0), false);
@@ -2550,8 +2587,9 @@ void TileSetEditor::draw_grid_snap() {
void TileSetEditor::draw_polygon_shapes() {
int t_id = get_current_tile();
- if (t_id < 0)
+ if (t_id < 0) {
return;
+ }
switch (edit_mode) {
case EDITMODE_COLLISION: {
@@ -2607,8 +2645,9 @@ void TileSetEditor::draw_polygon_shapes() {
}
}
- if (polygon.size() < 3)
+ if (polygon.size() < 3) {
continue;
+ }
workspace->draw_polygon(polygon, colors);
@@ -2829,14 +2868,16 @@ void TileSetEditor::close_shape(const Vector2 &shape_anchor) {
for (int i = 0; i < current_shape.size(); i++) {
points.push_back(current_shape[i] - shape_anchor);
- if (i != current_shape.size() - 1)
+ if (i != current_shape.size() - 1) {
p_total += ((current_shape[i + 1].x - current_shape[i].x) * (-current_shape[i + 1].y + (-current_shape[i].y)));
- else
+ } else {
p_total += ((current_shape[0].x - current_shape[i].x) * (-current_shape[0].y + (-current_shape[i].y)));
+ }
}
- if (p_total < 0)
+ if (p_total < 0) {
points.invert();
+ }
shape->set_points(points);
@@ -2851,10 +2892,11 @@ void TileSetEditor::close_shape(const Vector2 &shape_anchor) {
}
}
undo_redo->add_do_method(tileset.ptr(), "tile_set_shapes", get_current_tile(), sd);
- if (tileset->tile_get_tile_mode(get_current_tile()) == TileSet::AUTO_TILE || tileset->tile_get_tile_mode(get_current_tile()) == TileSet::ATLAS_TILE)
+ if (tileset->tile_get_tile_mode(get_current_tile()) == TileSet::AUTO_TILE || tileset->tile_get_tile_mode(get_current_tile()) == TileSet::ATLAS_TILE) {
undo_redo->add_do_method(tileset.ptr(), "tile_add_shape", get_current_tile(), shape, Transform2D(), false, edited_shape_coord);
- else
+ } else {
undo_redo->add_do_method(tileset.ptr(), "tile_add_shape", get_current_tile(), shape, Transform2D());
+ }
tools[TOOL_SELECT]->set_pressed(true);
undo_redo->add_do_method(this, "_select_edited_shape_coord");
undo_redo->add_undo_method(this, "_select_edited_shape_coord");
@@ -2923,17 +2965,21 @@ void TileSetEditor::close_shape(const Vector2 &shape_anchor) {
void TileSetEditor::select_coord(const Vector2 &coord) {
_update_tile_data();
current_shape = PackedVector2Array();
- if (get_current_tile() == -1)
+ if (get_current_tile() == -1) {
return;
+ }
Rect2 current_tile_region = tileset->tile_get_region(get_current_tile());
current_tile_region.position += WORKSPACE_MARGIN;
if (tileset->tile_get_tile_mode(get_current_tile()) == TileSet::SINGLE_TILE) {
- if (edited_collision_shape != tileset->tile_get_shape(get_current_tile(), 0))
+ if (edited_collision_shape != tileset->tile_get_shape(get_current_tile(), 0)) {
_set_edited_collision_shape(tileset->tile_get_shape(get_current_tile(), 0));
- if (edited_occlusion_shape != tileset->tile_get_light_occluder(get_current_tile()))
+ }
+ if (edited_occlusion_shape != tileset->tile_get_light_occluder(get_current_tile())) {
edited_occlusion_shape = tileset->tile_get_light_occluder(get_current_tile());
- if (edited_navigation_shape != tileset->tile_get_navigation_polygon(get_current_tile()))
+ }
+ if (edited_navigation_shape != tileset->tile_get_navigation_polygon(get_current_tile())) {
edited_navigation_shape = tileset->tile_get_navigation_polygon(get_current_tile());
+ }
if (edit_mode == EDITMODE_COLLISION) {
current_shape.resize(0);
@@ -2965,18 +3011,22 @@ void TileSetEditor::select_coord(const Vector2 &coord) {
bool found_collision_shape = false;
for (int i = 0; i < sd.size(); i++) {
if (sd[i].autotile_coord == coord) {
- if (edited_collision_shape != sd[i].shape)
+ if (edited_collision_shape != sd[i].shape) {
_set_edited_collision_shape(sd[i].shape);
+ }
found_collision_shape = true;
break;
}
}
- if (!found_collision_shape)
+ if (!found_collision_shape) {
_set_edited_collision_shape(Ref<ConvexPolygonShape2D>(nullptr));
- if (edited_occlusion_shape != tileset->autotile_get_light_occluder(get_current_tile(), coord))
+ }
+ if (edited_occlusion_shape != tileset->autotile_get_light_occluder(get_current_tile(), coord)) {
edited_occlusion_shape = tileset->autotile_get_light_occluder(get_current_tile(), coord);
- if (edited_navigation_shape != tileset->autotile_get_navigation_polygon(get_current_tile(), coord))
+ }
+ if (edited_navigation_shape != tileset->autotile_get_navigation_polygon(get_current_tile(), coord)) {
edited_navigation_shape = tileset->autotile_get_navigation_polygon(get_current_tile(), coord);
+ }
int spacing = tileset->autotile_get_spacing(get_current_tile());
Vector2 size = tileset->autotile_get_size(get_current_tile());
@@ -3036,14 +3086,18 @@ Vector2 TileSetEditor::snap_point(const Vector2 &point) {
p.y = Math::snap_scalar_separation(snap_offset.y, snap_step.y, p.y, snap_separation.y);
}
if (tools[SHAPE_KEEP_INSIDE_TILE]->is_pressed()) {
- if (p.x < region.position.x)
+ if (p.x < region.position.x) {
p.x = region.position.x;
- if (p.y < region.position.y)
+ }
+ if (p.y < region.position.y) {
p.y = region.position.y;
- if (p.x > region.position.x + region.size.x)
+ }
+ if (p.x > region.position.x + region.size.x) {
p.x = region.position.x + region.size.x;
- if (p.y > region.position.y + region.size.y)
+ }
+ if (p.y > region.position.y + region.size.y) {
p.y = region.position.y + region.size.y;
+ }
}
return p;
}
@@ -3091,8 +3145,9 @@ void TileSetEditor::update_texture_list() {
if (texture_list->get_item_count() > 0 && selected_texture.is_valid()) {
texture_list->select(texture_list->find_metadata(selected_texture->get_rid()));
- if (texture_list->get_selected_items().size() > 0)
+ if (texture_list->get_selected_items().size() > 0) {
_on_texture_list_selected(texture_list->get_selected_items()[0]);
+ }
} else if (get_current_texture().is_valid()) {
_on_texture_list_selected(texture_list->find_metadata(get_current_texture()->get_rid()));
} else {
@@ -3190,19 +3245,21 @@ void TileSetEditor::update_workspace_tile_mode() {
tool_editmode[EDITMODE_PRIORITY]->hide();
tool_editmode[EDITMODE_Z_INDEX]->hide();
} else if (tileset->tile_get_tile_mode(get_current_tile()) == TileSet::AUTO_TILE) {
- if (edit_mode == EDITMODE_ICON)
+ if (edit_mode == EDITMODE_ICON) {
select_coord(tileset->autotile_get_icon_coordinate(get_current_tile()));
- else
+ } else {
_select_edited_shape_coord();
+ }
} else if (tileset->tile_get_tile_mode(get_current_tile()) == TileSet::ATLAS_TILE) {
if (tool_editmode[EDITMODE_PRIORITY]->is_pressed() || tool_editmode[EDITMODE_BITMASK]->is_pressed()) {
tool_editmode[EDITMODE_COLLISION]->set_pressed(true);
edit_mode = EDITMODE_COLLISION;
}
- if (edit_mode == EDITMODE_ICON)
+ if (edit_mode == EDITMODE_ICON) {
select_coord(tileset->autotile_get_icon_coordinate(get_current_tile()));
- else
+ } else {
_select_edited_shape_coord();
+ }
tool_editmode[EDITMODE_BITMASK]->hide();
}
@@ -3275,10 +3332,11 @@ void TileSetEditor::set_current_tile(int p_id) {
}
Ref<Texture2D> TileSetEditor::get_current_texture() {
- if (texture_list->get_selected_items().size() == 0)
+ if (texture_list->get_selected_items().size() == 0) {
return Ref<Texture2D>();
- else
+ } else {
return texture_map[texture_list->get_item_metadata(texture_list->get_selected_items()[0])];
+ }
}
void TilesetEditorContext::set_tileset(const Ref<TileSet> &p_tileset) {
@@ -3309,8 +3367,9 @@ bool TilesetEditorContext::_set(const StringName &p_name, const Variant &p_value
String name2 = p_name.operator String().right(5);
bool v = false;
- if (tileset_editor->get_current_tile() < 0 || tileset.is_null())
+ if (tileset_editor->get_current_tile() < 0 || tileset.is_null()) {
return false;
+ }
if (name2 == "autotile_bitmask_mode") {
tileset->set(String::num(tileset_editor->get_current_tile(), 0) + "/autotile/bitmask_mode", p_value, &v);
@@ -3371,10 +3430,12 @@ bool TilesetEditorContext::_get(const StringName &p_name, Variant &r_ret) const
} else if (name.left(5) == "tile_") {
name = name.right(5);
- if (tileset_editor->get_current_tile() < 0 || tileset.is_null())
+ if (tileset_editor->get_current_tile() < 0 || tileset.is_null()) {
return false;
- if (!tileset->has_tile(tileset_editor->get_current_tile()))
+ }
+ if (!tileset->has_tile(tileset_editor->get_current_tile())) {
return false;
+ }
if (name == "autotile_bitmask_mode") {
r_ret = tileset->get(String::num(tileset_editor->get_current_tile(), 0) + "/autotile/bitmask_mode", &v);
diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp
index 223cc249e1..92bdba93e7 100644
--- a/editor/plugins/visual_shader_editor_plugin.cpp
+++ b/editor/plugins/visual_shader_editor_plugin.cpp
@@ -103,8 +103,9 @@ void VisualShaderEditor::edit(VisualShader *p_visual_shader) {
}
void VisualShaderEditor::add_plugin(const Ref<VisualShaderNodePlugin> &p_plugin) {
- if (plugins.find(p_plugin) != -1)
+ if (plugins.find(p_plugin) != -1) {
return;
+ }
plugins.push_back(p_plugin);
}
@@ -127,8 +128,9 @@ void VisualShaderEditor::add_custom_type(const String &p_name, const Ref<Script>
for (int i = 0; i < add_options.size(); i++) {
if (add_options[i].is_custom) {
- if (add_options[i].script == p_script)
+ if (add_options[i].script == p_script) {
return;
+ }
}
}
@@ -365,10 +367,11 @@ void VisualShaderEditor::_update_options_menu() {
}
TreeItem *item = members->create_item(category);
- if (options[i].highend && low_driver)
+ if (options[i].highend && low_driver) {
item->set_custom_color(0, unsupported_color);
- else if (options[i].highend)
+ } else if (options[i].highend) {
item->set_custom_color(0, supported_color);
+ }
item->set_text(0, options[i].name);
if (is_first_item && use_filter) {
item->select(0);
@@ -407,8 +410,9 @@ Size2 VisualShaderEditor::get_minimum_size() const {
void VisualShaderEditor::_draw_color_over_button(Object *obj, Color p_color) {
Button *button = Object::cast_to<Button>(obj);
- if (!button)
+ if (!button) {
return;
+ }
Ref<StyleBox> normal = get_theme_stylebox("normal", "Button");
button->draw_rect(Rect2(normal->get_offset(), button->get_size() - normal->get_minimum_size()), p_color);
@@ -447,11 +451,13 @@ void VisualShaderEditor::_update_created_node(GraphNode *node) {
}
void VisualShaderEditor::_update_graph() {
- if (updating)
+ if (updating) {
return;
+ }
- if (visual_shader.is_null())
+ if (visual_shader.is_null()) {
return;
+ }
graph->set_scroll_ofs(visual_shader->get_graph_offset() * EDSCALE);
@@ -850,8 +856,9 @@ void VisualShaderEditor::_update_graph() {
if (!uniform.is_valid()) {
graph->add_child(node);
_update_created_node(node);
- if (is_group)
+ if (is_group) {
call_deferred("_set_node_size", (int)type, nodes[n_i], size);
+ }
}
}
@@ -1056,8 +1063,9 @@ void VisualShaderEditor::_expression_focus_out(Object *text_edit, int p_node) {
TextEdit *expression_box = Object::cast_to<TextEdit>(text_edit);
- if (node->get_expression() == expression_box->get_text())
+ if (node->get_expression() == expression_box->get_text()) {
return;
+ }
undo_redo->create_action(TTR("Set expression"));
undo_redo->add_do_method(node.ptr(), "set_expression", expression_box->get_text());
@@ -1095,8 +1103,9 @@ void VisualShaderEditor::_set_node_size(int p_type, int p_node, const Vector2 &p
if (edit_type->get_selected() == p_type) { // check - otherwise the error will be emitted
Node *node2 = graph->get_node(itos(p_node));
gn = Object::cast_to<GraphNode>(node2);
- if (!gn)
+ if (!gn) {
return;
+ }
gn->set_custom_minimum_size(size);
gn->set_size(Size2(1, 1));
@@ -1185,24 +1194,28 @@ void VisualShaderEditor::_port_name_focus_out(Object *line_edit, int p_node_id,
String text = Object::cast_to<LineEdit>(line_edit)->get_text();
if (!p_output) {
- if (node->get_input_port_name(p_port_id) == text)
+ if (node->get_input_port_name(p_port_id) == text) {
return;
+ }
} else {
- if (node->get_output_port_name(p_port_id) == text)
+ if (node->get_output_port_name(p_port_id) == text) {
return;
+ }
}
List<String> input_names;
List<String> output_names;
for (int i = 0; i < node->get_input_port_count(); i++) {
- if (!p_output && i == p_port_id)
+ if (!p_output && i == p_port_id) {
continue;
+ }
input_names.push_back(node->get_input_port_name(i));
}
for (int i = 0; i < node->get_output_port_count(); i++) {
- if (p_output && i == p_port_id)
+ if (p_output && i == p_port_id) {
continue;
+ }
output_names.push_back(node->get_output_port_name(i));
}
@@ -1290,8 +1303,9 @@ VisualShaderNode *VisualShaderEditor::_add_node(int p_idx, int p_op_idx) {
VisualShaderNodeFloatConstant *constant = Object::cast_to<VisualShaderNodeFloatConstant>(vsn);
if (constant) {
- if ((int)add_options[p_idx].value != -1)
+ if ((int)add_options[p_idx].value != -1) {
constant->set_constant(add_options[p_idx].value);
+ }
}
if (p_op_idx != -1) {
@@ -1698,22 +1712,25 @@ void VisualShaderEditor::_notification(int p_what) {
tools->set_icon(EditorNode::get_singleton()->get_gui_base()->get_theme_icon("Tools", "EditorIcons"));
- if (p_what == NOTIFICATION_THEME_CHANGED && is_visible_in_tree())
+ if (p_what == NOTIFICATION_THEME_CHANGED && is_visible_in_tree()) {
_update_graph();
+ }
}
}
void VisualShaderEditor::_scroll_changed(const Vector2 &p_scroll) {
- if (updating)
+ if (updating) {
return;
+ }
updating = true;
visual_shader->set_graph_offset(p_scroll / EDSCALE);
updating = false;
}
void VisualShaderEditor::_node_changed(int p_id) {
- if (updating)
+ if (updating) {
return;
+ }
if (is_visible_in_tree()) {
_update_graph();
@@ -1860,8 +1877,9 @@ void VisualShaderEditor::_duplicate_nodes() {
_dup_copy_nodes(type, nodes, excluded);
- if (nodes.empty())
+ if (nodes.empty()) {
return;
+ }
undo_redo->create_action(TTR("Duplicate Nodes"));
@@ -1877,8 +1895,9 @@ void VisualShaderEditor::_copy_nodes() {
}
void VisualShaderEditor::_paste_nodes(bool p_use_custom_position, const Vector2 &p_custom_position) {
- if (copy_nodes_buffer.empty())
+ if (copy_nodes_buffer.empty()) {
return;
+ }
int type = edit_type->get_selected();
@@ -1911,8 +1930,9 @@ void VisualShaderEditor::_delete_nodes() {
}
}
- if (to_erase.empty())
+ if (to_erase.empty()) {
return;
+ }
undo_redo->create_action(TTR("Delete Nodes"));
@@ -1975,8 +1995,9 @@ void VisualShaderEditor::_mode_selected(int p_id) {
void VisualShaderEditor::_input_select_item(Ref<VisualShaderNodeInput> input, String name) {
String prev_name = input->get_input_name();
- if (name == prev_name)
+ if (name == prev_name) {
return;
+ }
bool type_changed = input->get_input_type_by_name(name) != input->get_input_type_by_name(prev_name);
@@ -2101,10 +2122,12 @@ void VisualShaderEditor::_node_menu_id_pressed(int p_idx) {
Variant VisualShaderEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
if (p_from == members) {
TreeItem *it = members->get_item_at_position(p_point);
- if (!it)
+ if (!it) {
return Variant();
- if (!it->has_meta("id"))
+ }
+ if (!it->has_meta("id")) {
return Variant();
+ }
int id = it->get_meta("id");
AddOption op = add_options[id];
@@ -2875,8 +2898,9 @@ void VisualShaderEditorPlugin::make_visible(bool p_visible) {
visual_shader_editor->set_process_input(true);
//visual_shader_editor->set_process(true);
} else {
- if (visual_shader_editor->is_visible_in_tree())
+ if (visual_shader_editor->is_visible_in_tree()) {
editor->hide_bottom_panel();
+ }
button->hide();
visual_shader_editor->set_process_input(false);
//visual_shader_editor->set_process(false);
@@ -2945,8 +2969,9 @@ class VisualShaderNodePluginDefaultEditor : public VBoxContainer {
public:
void _property_changed(const String &p_property, const Variant &p_value, const String &p_field = "", bool p_changing = false) {
- if (p_changing)
+ if (p_changing) {
return;
+ }
UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo();
@@ -2978,8 +3003,9 @@ public:
}
void _node_changed() {
- if (updating)
+ if (updating) {
return;
+ }
for (int i = 0; i < properties.size(); i++) {
properties[i]->update_property();
}
@@ -3077,8 +3103,9 @@ Control *VisualShaderNodePluginDefault::create_editor(const Ref<Resource> &p_par
}
}
- if (pinfo.size() == 0)
+ if (pinfo.size() == 0) {
return nullptr;
+ }
properties.clear();
@@ -3087,8 +3114,9 @@ Control *VisualShaderNodePluginDefault::create_editor(const Ref<Resource> &p_par
for (int i = 0; i < pinfo.size(); i++) {
EditorProperty *prop = EditorInspector::instantiate_property_editor(node.ptr(), pinfo[i].type, pinfo[i].name, pinfo[i].hint, pinfo[i].hint_string, pinfo[i].usage);
- if (!prop)
+ if (!prop) {
return nullptr;
+ }
if (Object::cast_to<EditorPropertyResource>(prop)) {
Object::cast_to<EditorPropertyResource>(prop)->set_use_sub_inspector(false);
@@ -3116,8 +3144,9 @@ void EditorPropertyShaderMode::_option_selected(int p_which) {
Ref<VisualShader> visual_shader(Object::cast_to<VisualShader>(get_edited_object()));
- if (visual_shader->get_mode() == p_which)
+ if (visual_shader->get_mode() == p_which) {
return;
+ }
UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo();
undo_redo->create_action(TTR("Visual Shader Mode Changed"));
@@ -3247,8 +3276,9 @@ void VisualShaderNodePortPreview::_shader_changed() {
for (int i = EditorNode::get_singleton()->get_editor_history()->get_path_size() - 1; i >= 0; i--) {
Object *object = ObjectDB::get_instance(EditorNode::get_singleton()->get_editor_history()->get_path_object(i));
- if (!object)
+ if (!object) {
continue;
+ }
ShaderMaterial *src_mat = Object::cast_to<ShaderMaterial>(object);
if (src_mat && src_mat->get_shader().is_valid()) {
List<PropertyInfo> params;
diff --git a/editor/progress_dialog.cpp b/editor/progress_dialog.cpp
index 8487a3d1d2..541cba836b 100644
--- a/editor/progress_dialog.cpp
+++ b/editor/progress_dialog.cpp
@@ -78,10 +78,11 @@ void BackgroundProgress::_task_step(const String &p_task, int p_step) {
ERR_FAIL_COND(!tasks.has(p_task));
Task &t = tasks[p_task];
- if (p_step < 0)
+ if (p_step < 0) {
t.progress->set_value(t.progress->get_value() + 1);
- else
+ } else {
t.progress->set_value(p_step);
+ }
}
void BackgroundProgress::_end_task(const String &p_task) {
@@ -113,8 +114,9 @@ void BackgroundProgress::task_step(const String &p_task, int p_step) {
no_updates = updates.empty();
}
- if (no_updates)
+ if (no_updates) {
MessageQueue::get_singleton()->push_call(this, "_update");
+ }
{
_THREAD_SAFE_METHOD_
@@ -187,15 +189,17 @@ bool ProgressDialog::task_step(const String &p_task, const String &p_state, int
if (!p_force_redraw) {
uint64_t tus = OS::get_singleton()->get_ticks_usec();
- if (tus - last_progress_tick < 200000) //200ms
+ if (tus - last_progress_tick < 200000) { //200ms
return cancelled;
+ }
}
Task &t = tasks[p_task];
- if (p_step < 0)
+ if (p_step < 0) {
t.progress->set_value(t.progress->get_value() + 1);
- else
+ } else {
t.progress->set_value(p_step);
+ }
t.state->set_text(p_state);
last_progress_tick = OS::get_singleton()->get_ticks_usec();
@@ -214,10 +218,11 @@ void ProgressDialog::end_task(const String &p_task) {
memdelete(t.vb);
tasks.erase(p_task);
- if (tasks.empty())
+ if (tasks.empty()) {
hide();
- else
+ } else {
_popup();
+ }
}
void ProgressDialog::_cancel_pressed() {
diff --git a/editor/project_export.cpp b/editor/project_export.cpp
index bc4a1ee118..32a1cf2fa1 100644
--- a/editor/project_export.cpp
+++ b/editor/project_export.cpp
@@ -52,8 +52,9 @@ void ProjectExportDialog::_theme_changed() {
duplicate_preset->set_icon(presets->get_theme_icon("Duplicate", "EditorIcons"));
delete_preset->set_icon(presets->get_theme_icon("Remove", "EditorIcons"));
Control *panel = custom_feature_display->get_parent_control();
- if (panel)
+ if (panel) {
panel->add_theme_style_override("panel", patches->get_theme_stylebox("bg", "Tree"));
+ }
}
void ProjectExportDialog::_notification(int p_what) {
@@ -115,16 +116,18 @@ void ProjectExportDialog::_add_preset(int p_platform) {
}
}
- if (valid)
+ if (valid) {
break;
+ }
attempt++;
name = EditorExport::get_singleton()->get_export_platform(p_platform)->get_name() + " " + itos(attempt);
}
preset->set_name(name);
- if (make_runnable)
+ if (make_runnable) {
preset->set_runnable(make_runnable);
+ }
EditorExport::get_singleton()->add_export_preset(preset);
_update_presets();
_edit_preset(EditorExport::get_singleton()->get_export_preset_count() - 1);
@@ -138,8 +141,9 @@ void ProjectExportDialog::_update_presets() {
updating = true;
Ref<EditorExportPreset> current;
- if (presets->get_current() >= 0 && presets->get_current() < presets->get_item_count())
+ if (presets->get_current() >= 0 && presets->get_current() < presets->get_item_count()) {
current = get_current_preset();
+ }
int current_idx = -1;
presets->clear();
@@ -150,8 +154,9 @@ void ProjectExportDialog::_update_presets() {
}
String name = preset->get_name();
- if (preset->is_runnable())
+ if (preset->is_runnable()) {
name += " (" + TTR("Runnable") + ")";
+ }
presets->add_item(name, preset->get_platform()->get_logo());
}
@@ -238,8 +243,9 @@ void ProjectExportDialog::_edit_preset(int p_index) {
String file = patchlist[i].get_file();
patch->set_editable(0, true);
patch->set_text(0, file.get_file().replace("*", ""));
- if (file.ends_with("*"))
+ if (file.ends_with("*")) {
patch->set_checked(0, true);
+ }
patch->set_tooltip(0, patchlist[i]);
patch->set_metadata(0, i);
patch->add_button(0, presets->get_theme_icon("Remove", "EditorIcons"), 0);
@@ -248,10 +254,11 @@ void ProjectExportDialog::_edit_preset(int p_index) {
TreeItem *patch_add = patches->create_item(patch_root);
patch_add->set_metadata(0, patchlist.size());
- if (patchlist.size() == 0)
+ if (patchlist.size() == 0) {
patch_add->set_text(0, TTR("Add initial export..."));
- else
+ } else {
patch_add->set_text(0, TTR("Add previous patches..."));
+ }
patch_add->add_button(0, presets->get_theme_icon("folder", "FileDialog"), 1);
@@ -264,8 +271,9 @@ void ProjectExportDialog::_edit_preset(int p_index) {
Vector<String> items = error.split("\n", false);
error = "";
for (int i = 0; i < items.size(); i++) {
- if (i > 0)
+ if (i > 0) {
error += "\n";
+ }
error += " - " + items[i];
}
@@ -274,10 +282,11 @@ void ProjectExportDialog::_edit_preset(int p_index) {
} else {
export_error->hide();
}
- if (needs_templates)
+ if (needs_templates) {
export_templates_error->show();
- else
+ } else {
export_templates_error->hide();
+ }
export_button->set_disabled(true);
get_ok()->set_disabled(true);
@@ -352,8 +361,9 @@ void ProjectExportDialog::_update_feature_list() {
}
void ProjectExportDialog::_custom_features_changed(const String &p_text) {
- if (updating)
+ if (updating) {
return;
+ }
Ref<EditorExportPreset> current = get_current_preset();
ERR_FAIL_COND(current.is_null());
@@ -386,8 +396,9 @@ void ProjectExportDialog::_patch_button_pressed(Object *p_item, int p_column, in
void ProjectExportDialog::_patch_edited() {
TreeItem *item = patches->get_edited();
- if (!item)
+ if (!item) {
return;
+ }
int index = item->get_metadata(0);
Ref<EditorExportPreset> current = get_current_preset();
@@ -438,8 +449,9 @@ void ProjectExportDialog::_update_parameters(const String &p_edited_property) {
}
void ProjectExportDialog::_runnable_pressed() {
- if (updating)
+ if (updating) {
return;
+ }
Ref<EditorExportPreset> current = get_current_preset();
ERR_FAIL_COND(current.is_null());
@@ -459,8 +471,9 @@ void ProjectExportDialog::_runnable_pressed() {
}
void ProjectExportDialog::_name_changed(const String &p_string) {
- if (updating)
+ if (updating) {
return;
+ }
Ref<EditorExportPreset> current = get_current_preset();
ERR_FAIL_COND(current.is_null());
@@ -488,8 +501,9 @@ Ref<EditorExportPreset> ProjectExportDialog::get_current_preset() const {
}
void ProjectExportDialog::_export_path_changed(const StringName &p_property, const Variant &p_value, const String &p_field, bool p_changing) {
- if (updating)
+ if (updating) {
return;
+ }
Ref<EditorExportPreset> current = get_current_preset();
ERR_FAIL_COND(current.is_null());
@@ -499,8 +513,9 @@ void ProjectExportDialog::_export_path_changed(const StringName &p_property, con
}
void ProjectExportDialog::_script_export_mode_changed(int p_mode) {
- if (updating)
+ if (updating) {
return;
+ }
Ref<EditorExportPreset> current = get_current_preset();
ERR_FAIL_COND(current.is_null());
@@ -511,8 +526,9 @@ void ProjectExportDialog::_script_export_mode_changed(int p_mode) {
}
void ProjectExportDialog::_script_encryption_key_changed(const String &p_key) {
- if (updating)
+ if (updating) {
return;
+ }
Ref<EditorExportPreset> current = get_current_preset();
ERR_FAIL_COND(current.is_null());
@@ -535,8 +551,9 @@ bool ProjectExportDialog::_validate_script_encryption_key(const String &p_key) {
void ProjectExportDialog::_duplicate_preset() {
Ref<EditorExportPreset> current = get_current_preset();
- if (current.is_null())
+ if (current.is_null()) {
return;
+ }
Ref<EditorExportPreset> preset = current->get_platform()->create_preset();
ERR_FAIL_COND(!preset.is_valid());
@@ -557,15 +574,17 @@ void ProjectExportDialog::_duplicate_preset() {
}
}
- if (valid)
+ if (valid) {
break;
+ }
name += " (copy)";
}
preset->set_name(name);
- if (make_runnable)
+ if (make_runnable) {
preset->set_runnable(make_runnable);
+ }
preset->set_export_filter(current->get_export_filter());
preset->set_include_filter(current->get_include_filter());
preset->set_exclude_filter(current->get_exclude_filter());
@@ -586,8 +605,9 @@ void ProjectExportDialog::_duplicate_preset() {
void ProjectExportDialog::_delete_preset() {
Ref<EditorExportPreset> current = get_current_preset();
- if (current.is_null())
+ if (current.is_null()) {
return;
+ }
delete_confirm->set_text(vformat(TTR("Delete preset '%s'?"), current->get_name()));
delete_confirm->popup_centered();
@@ -646,15 +666,18 @@ Variant ProjectExportDialog::get_drag_data_fw(const Point2 &p_point, Control *p_
bool ProjectExportDialog::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
if (p_from == presets) {
Dictionary d = p_data;
- if (!d.has("type") || String(d["type"]) != "export_preset")
+ if (!d.has("type") || String(d["type"]) != "export_preset") {
return false;
+ }
- if (presets->get_item_at_position(p_point, true) < 0 && !presets->is_pos_at_end_of_items(p_point))
+ if (presets->get_item_at_position(p_point, true) < 0 && !presets->is_pos_at_end_of_items(p_point)) {
return false;
+ }
} else if (p_from == patches) {
Dictionary d = p_data;
- if (!d.has("type") || String(d["type"]) != "export_patch")
+ if (!d.has("type") || String(d["type"]) != "export_patch") {
return false;
+ }
patches->set_drop_mode_flags(Tree::DROP_MODE_ON_ITEM);
@@ -679,12 +702,13 @@ void ProjectExportDialog::drop_data_fw(const Point2 &p_point, const Variant &p_d
to_pos = presets->get_item_at_position(p_point, true);
}
- if (to_pos == -1 && !presets->is_pos_at_end_of_items(p_point))
+ if (to_pos == -1 && !presets->is_pos_at_end_of_items(p_point)) {
return;
+ }
- if (to_pos == from_pos)
+ if (to_pos == from_pos) {
return;
- else if (to_pos > from_pos) {
+ } else if (to_pos > from_pos) {
to_pos--;
}
@@ -693,26 +717,29 @@ void ProjectExportDialog::drop_data_fw(const Point2 &p_point, const Variant &p_d
EditorExport::get_singleton()->add_export_preset(preset, to_pos);
_update_presets();
- if (to_pos >= 0)
+ if (to_pos >= 0) {
_edit_preset(to_pos);
- else
+ } else {
_edit_preset(presets->get_item_count() - 1);
+ }
} else if (p_from == patches) {
Dictionary d = p_data;
- if (!d.has("type") || String(d["type"]) != "export_patch")
+ if (!d.has("type") || String(d["type"]) != "export_patch") {
return;
+ }
int from_pos = d["patch"];
TreeItem *item = patches->get_item_at_position(p_point);
- if (!item)
+ if (!item) {
return;
+ }
int to_pos = item->get_cell_mode(0) == TreeItem::CELL_MODE_CHECK ? int(item->get_metadata(0)) : -1;
- if (to_pos == from_pos)
+ if (to_pos == from_pos) {
return;
- else if (to_pos > from_pos) {
+ } else if (to_pos > from_pos) {
to_pos--;
}
@@ -726,12 +753,14 @@ void ProjectExportDialog::drop_data_fw(const Point2 &p_point, const Variant &p_d
}
void ProjectExportDialog::_export_type_changed(int p_which) {
- if (updating)
+ if (updating) {
return;
+ }
Ref<EditorExportPreset> current = get_current_preset();
- if (current.is_null())
+ if (current.is_null()) {
return;
+ }
current->set_export_filter(EditorExportPreset::ExportFilter(p_which));
updating = true;
@@ -740,12 +769,14 @@ void ProjectExportDialog::_export_type_changed(int p_which) {
}
void ProjectExportDialog::_filter_changed(const String &p_filter) {
- if (updating)
+ if (updating) {
return;
+ }
Ref<EditorExportPreset> current = get_current_preset();
- if (current.is_null())
+ if (current.is_null()) {
return;
+ }
current->set_include_filter(include_filters->get_text());
current->set_exclude_filter(exclude_filters->get_text());
@@ -757,8 +788,9 @@ void ProjectExportDialog::_fill_resource_tree() {
include_margin->hide();
Ref<EditorExportPreset> current = get_current_preset();
- if (current.is_null())
+ if (current.is_null()) {
return;
+ }
EditorExportPreset::ExportFilter f = current->get_export_filter();
@@ -790,8 +822,9 @@ bool ProjectExportDialog::_fill_tree(EditorFileSystemDirectory *p_dir, TreeItem
for (int i = 0; i < p_dir->get_file_count(); i++) {
String type = p_dir->get_file_type(i);
- if (p_only_scenes && type != "PackedScene")
+ if (p_only_scenes && type != "PackedScene") {
continue;
+ }
TreeItem *file = include_files->create_item(p_item);
file->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
@@ -811,16 +844,19 @@ bool ProjectExportDialog::_fill_tree(EditorFileSystemDirectory *p_dir, TreeItem
}
void ProjectExportDialog::_tree_changed() {
- if (updating)
+ if (updating) {
return;
+ }
Ref<EditorExportPreset> current = get_current_preset();
- if (current.is_null())
+ if (current.is_null()) {
return;
+ }
TreeItem *item = include_files->get_edited();
- if (!item)
+ if (!item) {
return;
+ }
String path = item->get_metadata(0);
bool added = item->is_checked(0);
@@ -859,10 +895,12 @@ void ProjectExportDialog::_validate_export_path(const String &p_path) {
bool invalid_path = (p_path.get_file().get_basename() == "");
// Check if state change before needlessly messing with signals
- if (invalid_path && export_project->get_ok()->is_disabled())
+ if (invalid_path && export_project->get_ok()->is_disabled()) {
return;
- if (!invalid_path && !export_project->get_ok()->is_disabled())
+ }
+ if (!invalid_path && !export_project->get_ok()->is_disabled()) {
return;
+ }
if (invalid_path) {
export_project->get_ok()->set_disabled(true);
diff --git a/editor/project_manager.cpp b/editor/project_manager.cpp
index 1e04b4e467..dc5ff6a5eb 100644
--- a/editor/project_manager.cpp
+++ b/editor/project_manager.cpp
@@ -300,8 +300,9 @@ private:
if (lidx != -1) {
sp = sp.substr(lidx + 1, sp.length()).capitalize();
}
- if (sp == "" && mode == MODE_IMPORT)
+ if (sp == "" && mode == MODE_IMPORT) {
sp = TTR("Imported Project");
+ }
project_name->set_text(sp);
_text_changed(sp);
@@ -404,13 +405,15 @@ private:
}
void _text_changed(const String &p_text) {
- if (mode != MODE_NEW)
+ if (mode != MODE_NEW) {
return;
+ }
_test_path();
- if (p_text == "")
+ if (p_text == "") {
set_message(TTR("It would be a good idea to name your project."), MESSAGE_WARNING);
+ }
}
void ok_pressed() {
@@ -578,8 +581,9 @@ private:
}
dir = dir.replace("\\", "/");
- if (dir.ends_with("/"))
+ if (dir.ends_with("/")) {
dir = dir.substr(0, dir.length() - 1);
+ }
String proj = get_project_key_from_path(dir);
EditorSettings::get_singleton()->set("projects/" + proj, dir);
EditorSettings::get_singleton()->save();
@@ -608,16 +612,19 @@ private:
project_name->clear();
_text_changed("");
- if (status_rect->get_texture() == msg->get_theme_icon("StatusError", "EditorIcons"))
+ if (status_rect->get_texture() == msg->get_theme_icon("StatusError", "EditorIcons")) {
msg->show();
+ }
- if (install_status_rect->get_texture() == msg->get_theme_icon("StatusError", "EditorIcons"))
+ if (install_status_rect->get_texture() == msg->get_theme_icon("StatusError", "EditorIcons")) {
msg->show();
+ }
}
void _notification(int p_what) {
- if (p_what == NOTIFICATION_WM_CLOSE_REQUEST)
+ if (p_what == NOTIFICATION_WM_CLOSE_REQUEST) {
_remove_created_folder();
+ }
}
protected:
@@ -1137,8 +1144,9 @@ void ProjectList::load_project_data(const String &p_property_key, Item &p_item,
String project_name = TTR("Unnamed Project");
if (cf_err == OK) {
String cf_project_name = static_cast<String>(cf->get_value("application", "config/name", ""));
- if (cf_project_name != "")
+ if (cf_project_name != "") {
project_name = cf_project_name.xml_unescape();
+ }
config_version = (int)cf->get_value("", "config_version", 0);
}
@@ -1161,8 +1169,9 @@ void ProjectList::load_project_data(const String &p_property_key, Item &p_item,
String fscache = path.plus_file(".fscache");
if (FileAccess::exists(fscache)) {
uint64_t cache_modified = FileAccess::get_modified_time(fscache);
- if (cache_modified > last_edited)
+ if (cache_modified > last_edited) {
last_edited = cache_modified;
+ }
}
} else {
grayed = true;
@@ -1208,8 +1217,9 @@ void ProjectList::load_projects() {
for (List<PropertyInfo>::Element *E = properties.front(); E; E = E->next()) {
// This is actually something like "projects/C:::Documents::Godot::Projects::MyGame"
String property_key = E->get().name;
- if (!property_key.begins_with("projects/"))
+ if (!property_key.begins_with("projects/")) {
continue;
+ }
String project_key = property_key.get_slice("/", 1);
bool favorite = favorites.has("favorite_projects/" + project_key);
@@ -1327,8 +1337,9 @@ void ProjectList::create_project_item_control(int p_index) {
hb->icon = tf;
VBoxContainer *vb = memnew(VBoxContainer);
- if (item.grayed)
+ if (item.grayed) {
vb->set_modulate(Color(1, 1, 1, 0.5));
+ }
vb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
hb->add_child(vb);
Control *ec = memnew(Control);
@@ -1792,8 +1803,9 @@ void ProjectManager::_notification(int p_what) {
}
} break;
case NOTIFICATION_READY: {
- if (_project_list->get_project_count() == 0 && StreamPeerSSL::is_available())
+ if (_project_list->get_project_count() == 0 && StreamPeerSSL::is_available()) {
open_templates->popup_centered();
+ }
if (_project_list->get_project_count() >= 1) {
// Focus on the search box immediately to allow the user
@@ -1859,8 +1871,9 @@ void ProjectManager::_unhandled_input(const Ref<InputEvent> &p_ev) {
}
#endif
- if (tabs->get_current_tab() != 0)
+ if (tabs->get_current_tab() != 0) {
return;
+ }
bool keycode_handled = true;
@@ -1886,8 +1899,9 @@ void ProjectManager::_unhandled_input(const Ref<InputEvent> &p_ev) {
} break;
case KEY_UP: {
- if (k->get_shift())
+ if (k->get_shift()) {
break;
+ }
int index = _project_list->get_single_selected_index();
if (index > 0) {
@@ -1899,8 +1913,9 @@ void ProjectManager::_unhandled_input(const Ref<InputEvent> &p_ev) {
break;
}
case KEY_DOWN: {
- if (k->get_shift())
+ if (k->get_shift()) {
break;
+ }
int index = _project_list->get_single_selected_index();
if (index + 1 < _project_list->get_project_count()) {
@@ -1911,10 +1926,11 @@ void ProjectManager::_unhandled_input(const Ref<InputEvent> &p_ev) {
} break;
case KEY_F: {
- if (k->get_command())
+ if (k->get_command()) {
this->project_filter->search_box->grab_focus();
- else
+ } else {
keycode_handled = false;
+ }
} break;
default: {
keycode_handled = false;
@@ -2176,8 +2192,9 @@ void ProjectManager::_erase_missing_projects_confirm() {
void ProjectManager::_erase_project() {
const Set<String> &selected_list = _project_list->get_selected_project_keys();
- if (selected_list.size() == 0)
+ if (selected_list.size() == 0) {
return;
+ }
String confirm_message;
if (selected_list.size() >= 2) {
@@ -2305,8 +2322,9 @@ void ProjectManager::_open_asset_library() {
ProjectManager::ProjectManager() {
// load settings
- if (!EditorSettings::get_singleton())
+ if (!EditorSettings::get_singleton()) {
EditorSettings::create();
+ }
EditorSettings::get_singleton()->set_optimize_save(false); //just write settings as they came
@@ -2626,14 +2644,16 @@ ProjectManager::ProjectManager() {
}
ProjectManager::~ProjectManager() {
- if (EditorSettings::get_singleton())
+ if (EditorSettings::get_singleton()) {
EditorSettings::destroy();
+ }
}
void ProjectListFilter::_setup_filters(Vector<String> options) {
filter_option->clear();
- for (int i = 0; i < options.size(); i++)
+ for (int i = 0; i < options.size(); i++) {
filter_option->add_item(options[i]);
+ }
}
void ProjectListFilter::_search_text_changed(const String &p_newtext) {
@@ -2657,8 +2677,9 @@ void ProjectListFilter::_filter_option_selected(int p_idx) {
FilterOption selected = (FilterOption)(filter_option->get_selected());
if (_current_filter != selected) {
_current_filter = selected;
- if (is_inside_tree())
+ if (is_inside_tree()) {
emit_signal("filter_changed");
+ }
}
}
diff --git a/editor/project_settings_editor.cpp b/editor/project_settings_editor.cpp
index 4f9c6c2cf3..a7c260c0f8 100644
--- a/editor/project_settings_editor.cpp
+++ b/editor/project_settings_editor.cpp
@@ -163,17 +163,20 @@ void ProjectSettingsEditor::_notification(int p_what) {
static bool _validate_action_name(const String &p_name) {
const CharType *cstr = p_name.c_str();
- for (int i = 0; cstr[i]; i++)
+ for (int i = 0; cstr[i]; i++) {
if (cstr[i] == '/' || cstr[i] == ':' || cstr[i] == '"' ||
- cstr[i] == '=' || cstr[i] == '\\' || cstr[i] < 32)
+ cstr[i] == '=' || cstr[i] == '\\' || cstr[i] < 32) {
return false;
+ }
+ }
return true;
}
void ProjectSettingsEditor::_action_selected() {
TreeItem *ti = input_editor->get_selected();
- if (!ti || !ti->is_editable(0))
+ if (!ti || !ti->is_editable(0)) {
return;
+ }
add_at = "input/" + ti->get_text(0);
edit_idx = -1;
@@ -181,15 +184,17 @@ void ProjectSettingsEditor::_action_selected() {
void ProjectSettingsEditor::_action_edited() {
TreeItem *ti = input_editor->get_selected();
- if (!ti)
+ if (!ti) {
return;
+ }
if (input_editor->get_selected_column() == 0) {
String new_name = ti->get_text(0);
String old_name = add_at.substr(add_at.find("/") + 1, add_at.length());
- if (new_name == old_name)
+ if (new_name == old_name) {
return;
+ }
if (new_name == "" || !_validate_action_name(new_name)) {
ti->set_text(0, old_name);
@@ -262,8 +267,9 @@ void ProjectSettingsEditor::_device_input_add() {
for (int i = 0; i < events.size(); i++) {
Ref<InputEventMouseButton> aie = events[i];
- if (aie.is_null())
+ if (aie.is_null()) {
continue;
+ }
if (aie->get_device() == mb->get_device() && aie->get_button_index() == mb->get_button_index()) {
return;
}
@@ -281,8 +287,9 @@ void ProjectSettingsEditor::_device_input_add() {
for (int i = 0; i < events.size(); i++) {
Ref<InputEventJoypadMotion> aie = events[i];
- if (aie.is_null())
+ if (aie.is_null()) {
continue;
+ }
if (aie->get_device() == jm->get_device() && aie->get_axis() == jm->get_axis() && aie->get_axis_value() == jm->get_axis_value()) {
return;
@@ -301,8 +308,9 @@ void ProjectSettingsEditor::_device_input_add() {
for (int i = 0; i < events.size(); i++) {
Ref<InputEventJoypadButton> aie = events[i];
- if (aie.is_null())
+ if (aie.is_null()) {
continue;
+ }
if (aie->get_device() == jb->get_device() && aie->get_button_index() == jb->get_button_index()) {
return;
}
@@ -342,14 +350,16 @@ int ProjectSettingsEditor::_get_current_device() {
}
String ProjectSettingsEditor::_get_device_string(int i_device) {
- if (i_device == InputMap::ALL_DEVICES)
+ if (i_device == InputMap::ALL_DEVICES) {
return TTR("All Devices");
+ }
return TTR("Device") + " " + itos(i_device);
}
void ProjectSettingsEditor::_press_a_key_confirm() {
- if (last_wait_for_key.is_null())
+ if (last_wait_for_key.is_null()) {
return;
+ }
Ref<InputEventKey> ie;
ie.instance();
@@ -374,8 +384,9 @@ void ProjectSettingsEditor::_press_a_key_confirm() {
for (int i = 0; i < events.size(); i++) {
Ref<InputEventKey> aie = events[i];
- if (aie.is_null())
+ if (aie.is_null()) {
continue;
+ }
if (!press_a_key_physical) {
if (aie->get_keycode_with_modifiers() == ie->get_keycode_with_modifiers()) {
return;
@@ -411,11 +422,13 @@ void ProjectSettingsEditor::_show_last_added(const Ref<InputEvent> &p_event, con
String name = p_name;
name.erase(0, 6);
- if (!r)
+ if (!r) {
return;
+ }
r = r->get_children();
- if (!r)
+ if (!r) {
return;
+ }
bool found = false;
while (r) {
if (r->get_text(0) != name) {
@@ -433,13 +446,15 @@ void ProjectSettingsEditor::_show_last_added(const Ref<InputEvent> &p_event, con
}
child = child->get_next();
}
- if (found)
+ if (found) {
break;
+ }
r = r->get_next();
}
- if (found)
+ if (found) {
input_editor->ensure_cursor_is_visible();
+ }
}
void ProjectSettingsEditor::_wait_for_key(const Ref<InputEvent> &p_event) {
@@ -528,8 +543,9 @@ void ProjectSettingsEditor::_add_item(int p_item, Ref<InputEvent> p_exiting_even
device_index->clear();
for (int i = 0; i < JOY_BUTTON_MAX; i++) {
String desc = TTR("Button") + " " + itos(i);
- if (i < JOY_SDL_BUTTONS)
+ if (i < JOY_SDL_BUTTONS) {
desc += " (" + TTR(_button_descriptions[i]) + ")";
+ }
device_index->add_item(desc);
}
device_input->popup_centered(Size2(350, 95) * EDSCALE);
@@ -579,8 +595,9 @@ void ProjectSettingsEditor::_edit_item(Ref<InputEvent> p_exiting_event) {
void ProjectSettingsEditor::_action_activated() {
TreeItem *ti = input_editor->get_selected();
- if (!ti || ti->get_parent() == input_editor->get_root())
+ if (!ti || ti->get_parent() == input_editor->get_root()) {
return;
+ }
String name = "input/" + ti->get_parent()->get_text(0);
int idx = ti->get_metadata(0);
@@ -589,8 +606,9 @@ void ProjectSettingsEditor::_action_activated() {
ERR_FAIL_INDEX(idx, events.size());
Ref<InputEvent> event = events[idx];
- if (event.is_null())
+ if (event.is_null()) {
return;
+ }
add_at = name;
edit_idx = idx;
@@ -673,8 +691,9 @@ void ProjectSettingsEditor::_action_button_pressed(Object *p_obj, int p_column,
Ref<InputEvent> event = events[idx];
- if (event.is_null())
+ if (event.is_null()) {
return;
+ }
ti->set_as_cursor(0);
add_at = name;
@@ -685,8 +704,9 @@ void ProjectSettingsEditor::_action_button_pressed(Object *p_obj, int p_column,
}
void ProjectSettingsEditor::_update_actions() {
- if (setting)
+ if (setting) {
return;
+ }
Map<String, bool> collapsed;
@@ -705,12 +725,14 @@ void ProjectSettingsEditor::_update_actions() {
for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
const PropertyInfo &pi = E->get();
- if (!pi.name.begins_with("input/"))
+ if (!pi.name.begins_with("input/")) {
continue;
+ }
String name = pi.name.get_slice("/", 1);
- if (name == "")
+ if (name == "") {
continue;
+ }
Dictionary action = ProjectSettings::get_singleton()->get(pi.name);
Array events = action["events"];
@@ -718,8 +740,9 @@ void ProjectSettingsEditor::_update_actions() {
TreeItem *item = input_editor->create_item(root);
item->set_text(0, name);
item->set_custom_bg_color(0, input_editor->get_theme_color("prop_subsection", "Editor"));
- if (collapsed.has(name))
+ if (collapsed.has(name)) {
item->set_collapsed(collapsed[name]);
+ }
item->set_editable(1, true);
item->set_cell_mode(1, TreeItem::CELL_MODE_RANGE);
@@ -744,8 +767,9 @@ void ProjectSettingsEditor::_update_actions() {
for (int i = 0; i < events.size(); i++) {
Ref<InputEvent> event = events[i];
- if (event.is_null())
+ if (event.is_null()) {
continue;
+ }
TreeItem *action2 = input_editor->create_item(item);
@@ -850,8 +874,9 @@ void ProjectSettingsEditor::update_plugins() {
void ProjectSettingsEditor::_item_selected(const String &p_path) {
const String &selected_path = p_path;
- if (selected_path == String())
+ if (selected_path == String()) {
return;
+ }
category->set_text(globals_editor->get_current_section());
property->set_text(selected_path);
popup_copy_to_feature->set_disabled(false);
@@ -985,13 +1010,16 @@ void ProjectSettingsEditor::_action_add() {
TreeItem *r = input_editor->get_root();
- if (!r)
+ if (!r) {
return;
+ }
r = r->get_children();
- if (!r)
+ if (!r) {
return;
- while (r->get_next())
+ }
+ while (r->get_next()) {
r = r->get_next();
+ }
r->select(0);
input_editor->ensure_cursor_is_visible();
@@ -1072,8 +1100,9 @@ void ProjectSettingsEditor::_copy_to_platform_about_to_show() {
Variant ProjectSettingsEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
TreeItem *selected = input_editor->get_selected();
- if (!selected || selected->get_parent() != input_editor->get_root())
+ if (!selected || selected->get_parent() != input_editor->get_root()) {
return Variant();
+ }
String name = selected->get_text(0);
VBoxContainer *vb = memnew(VBoxContainer);
@@ -1094,25 +1123,29 @@ Variant ProjectSettingsEditor::get_drag_data_fw(const Point2 &p_point, Control *
bool ProjectSettingsEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
Dictionary d = p_data;
- if (!d.has("type") || d["type"] != "nodes")
+ if (!d.has("type") || d["type"] != "nodes") {
return false;
+ }
TreeItem *selected = input_editor->get_selected();
TreeItem *item = input_editor->get_item_at_position(p_point);
- if (!selected || !item || item == selected || item->get_parent() == selected)
+ if (!selected || !item || item == selected || item->get_parent() == selected) {
return false;
+ }
return true;
}
void ProjectSettingsEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
- if (!can_drop_data_fw(p_point, p_data, p_from))
+ if (!can_drop_data_fw(p_point, p_data, p_from)) {
return;
+ }
TreeItem *selected = input_editor->get_selected();
TreeItem *item = input_editor->get_item_at_position(p_point);
- if (!item)
+ if (!item) {
return;
+ }
TreeItem *target = item->get_parent() == input_editor->get_root() ? item : item->get_parent();
String selected_name = "input/" + selected->get_text(0);
@@ -1188,8 +1221,9 @@ void ProjectSettingsEditor::_translation_add(const String &p_path) {
PackedStringArray translations = ProjectSettings::get_singleton()->get("locale/translations");
for (int i = 0; i < translations.size(); i++) {
- if (translations[i] == p_path)
+ if (translations[i] == p_path) {
return; //exists
+ }
}
translations.push_back(p_path);
@@ -1242,8 +1276,9 @@ void ProjectSettingsEditor::_translation_res_add(const String &p_path) {
prev = remaps;
}
- if (remaps.has(p_path))
+ if (remaps.has(p_path)) {
return; //pointless already has it
+ }
remaps[p_path] = PackedStringArray();
@@ -1287,18 +1322,21 @@ void ProjectSettingsEditor::_translation_res_option_add(const String &p_path) {
}
void ProjectSettingsEditor::_translation_res_select() {
- if (updating_translations)
+ if (updating_translations) {
return;
+ }
call_deferred("_update_translations");
}
void ProjectSettingsEditor::_translation_res_option_changed() {
- if (updating_translations)
+ if (updating_translations) {
return;
+ }
- if (!ProjectSettings::get_singleton()->has_setting("locale/translation_remaps"))
+ if (!ProjectSettings::get_singleton()->has_setting("locale/translation_remaps")) {
return;
+ }
Dictionary remaps = ProjectSettings::get_singleton()->get("locale/translation_remaps");
@@ -1339,11 +1377,13 @@ void ProjectSettingsEditor::_translation_res_option_changed() {
}
void ProjectSettingsEditor::_translation_res_delete(Object *p_item, int p_column, int p_button) {
- if (updating_translations)
+ if (updating_translations) {
return;
+ }
- if (!ProjectSettings::get_singleton()->has_setting("locale/translation_remaps"))
+ if (!ProjectSettings::get_singleton()->has_setting("locale/translation_remaps")) {
return;
+ }
Dictionary remaps = ProjectSettings::get_singleton()->get("locale/translation_remaps");
@@ -1365,11 +1405,13 @@ void ProjectSettingsEditor::_translation_res_delete(Object *p_item, int p_column
}
void ProjectSettingsEditor::_translation_res_option_delete(Object *p_item, int p_column, int p_button) {
- if (updating_translations)
+ if (updating_translations) {
return;
+ }
- if (!ProjectSettings::get_singleton()->has_setting("locale/translation_remaps"))
+ if (!ProjectSettings::get_singleton()->has_setting("locale/translation_remaps")) {
return;
+ }
Dictionary remaps = ProjectSettings::get_singleton()->get("locale/translation_remaps");
@@ -1480,8 +1522,9 @@ void ProjectSettingsEditor::_translation_filter_mode_changed(int p_mode) {
void ProjectSettingsEditor::_update_translations() {
//update translations
- if (updating_translations)
+ if (updating_translations) {
return;
+ }
updating_translations = true;
@@ -1539,8 +1582,9 @@ void ProjectSettingsEditor::_update_translations() {
String n = names[i];
String l = langs[i];
bool is_checked = l_filter.has(l);
- if (filter_mode == SHOW_ONLY_SELECTED_LOCALES && !is_checked)
+ if (filter_mode == SHOW_ONLY_SELECTED_LOCALES && !is_checked) {
continue;
+ }
TreeItem *t = translation_filter->create_item(root);
t->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
@@ -1582,16 +1626,18 @@ void ProjectSettingsEditor::_update_translations() {
if (filter_mode == SHOW_ONLY_SELECTED_LOCALES && fl_idx_count != 0) {
if (l_filter.size() > 0) {
if (l_filter.find(langs[i]) != -1) {
- if (langnames.length() > 0)
+ if (langnames.length() > 0) {
langnames += ",";
+ }
langnames += names[i];
translation_locales_idxs_remap.write[l_idx] = i;
l_idx++;
}
}
} else {
- if (i > 0)
+ if (i > 0) {
langnames += ",";
+ }
langnames += names[i];
}
}
@@ -1635,8 +1681,9 @@ void ProjectSettingsEditor::_update_translations() {
t2->set_editable(1, true);
t2->set_metadata(1, path);
int idx = langs.find(locale);
- if (idx < 0)
+ if (idx < 0) {
idx = 0;
+ }
int f_idx = translation_locales_idxs_remap.find(idx);
if (f_idx != -1 && fl_idx_count > 0 && filter_mode == SHOW_ONLY_SELECTED_LOCALES) {
@@ -1926,8 +1973,9 @@ ProjectSettingsEditor::ProjectSettingsEditor(EditorData *p_data) {
vbc_left->add_child(l);
device_id = memnew(OptionButton);
- for (int i = -1; i < 8; i++)
+ for (int i = -1; i < 8; i++) {
device_id->add_item(_get_device_string(i));
+ }
_set_current_device(0);
vbc_left->add_child(device_id);
diff --git a/editor/property_editor.cpp b/editor/property_editor.cpp
index e14d842b98..c6efcc944b 100644
--- a/editor/property_editor.cpp
+++ b/editor/property_editor.cpp
@@ -77,22 +77,25 @@ void EditorResourceConversionPlugin::_bind_methods() {
}
String EditorResourceConversionPlugin::converts_to() const {
- if (get_script_instance())
+ if (get_script_instance()) {
return get_script_instance()->call("_converts_to");
+ }
return "";
}
bool EditorResourceConversionPlugin::handles(const Ref<Resource> &p_resource) const {
- if (get_script_instance())
+ if (get_script_instance()) {
return get_script_instance()->call("_handles", p_resource);
+ }
return false;
}
Ref<Resource> EditorResourceConversionPlugin::convert(const Ref<Resource> &p_resource) const {
- if (get_script_instance())
+ if (get_script_instance()) {
return get_script_instance()->call("_convert", p_resource);
+ }
return Ref<Resource>();
}
@@ -168,8 +171,9 @@ void CustomPropertyEditor::_menu_option(int p_which) {
case OBJ_MENU_MAKE_UNIQUE: {
Ref<Resource> res_orig = v;
- if (res_orig.is_null())
+ if (res_orig.is_null()) {
return;
+ }
List<PropertyInfo> property_list;
res_orig->get_property_list(&property_list);
@@ -214,13 +218,15 @@ void CustomPropertyEditor::_menu_option(int p_which) {
} break;
case OBJ_MENU_NEW_SCRIPT: {
- if (Object::cast_to<Node>(owner))
+ if (Object::cast_to<Node>(owner)) {
EditorNode::get_singleton()->get_scene_tree_dock()->open_script_dialog(Object::cast_to<Node>(owner), false);
+ }
} break;
case OBJ_MENU_EXTEND_SCRIPT: {
- if (Object::cast_to<Node>(owner))
+ if (Object::cast_to<Node>(owner)) {
EditorNode::get_singleton()->get_scene_tree_dock()->open_script_dialog(Object::cast_to<Node>(owner), true);
+ }
} break;
case OBJ_MENU_SHOW_IN_FILE_SYSTEM: {
@@ -307,8 +313,9 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant::
hint = p_hint;
hint_text = p_hint_text;
type_button->hide();
- if (color_picker)
+ if (color_picker) {
color_picker->hide();
+ }
texture_preview->hide();
inheritors_array.clear();
text_edit->hide();
@@ -321,8 +328,9 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant::
for (int i = 0; i < MAX_VALUE_EDITORS; i++) {
value_editor[i]->hide();
value_label[i]->hide();
- if (i < 4)
+ if (i < 4) {
scroll[i]->hide();
+ }
}
for (int i = 0; i < MAX_ACTION_BUTTONS; i++) {
@@ -330,8 +338,9 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant::
}
checks20gc->hide();
- for (int i = 0; i < 20; i++)
+ for (int i = 0; i < 20; i++) {
checks20[i]->hide();
+ }
type = (p_variant.get_type() != Variant::NIL && p_variant.get_type() != Variant::_RID && p_type != Variant::OBJECT) ? p_variant.get_type() : p_type;
@@ -355,17 +364,20 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant::
int c = hint_text.get_slice_count(",");
float min = 0, max = 100, step = type == Variant::FLOAT ? .01 : 1;
if (c >= 1) {
- if (!hint_text.get_slice(",", 0).empty())
+ if (!hint_text.get_slice(",", 0).empty()) {
min = hint_text.get_slice(",", 0).to_double();
+ }
}
if (c >= 2) {
- if (!hint_text.get_slice(",", 1).empty())
+ if (!hint_text.get_slice(",", 1).empty()) {
max = hint_text.get_slice(",", 1).to_double();
+ }
}
if (c >= 3) {
- if (!hint_text.get_slice(",", 2).empty())
+ if (!hint_text.get_slice(",", 2).empty()) {
step = hint_text.get_slice(",", 2).to_double();
+ }
}
if (c >= 4 && hint_text.get_slice(",", 3) == "slider") {
@@ -389,8 +401,9 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant::
int current_val = 0;
for (int i = 0; i < options.size(); i++) {
Vector<String> text_split = options[i].split(":");
- if (text_split.size() != 1)
+ if (text_split.size() != 1) {
current_val = text_split[1].to_int();
+ }
menu->add_item(text_split[0]);
menu->set_item_metadata(i, current_val);
current_val += 1;
@@ -466,12 +479,14 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant::
Vector<String> flags = hint_text.split(",");
for (int i = 0; i < flags.size(); i++) {
String flag = flags[i];
- if (flag == "")
+ if (flag == "") {
continue;
+ }
menu->add_check_item(flag, i);
int f = v;
- if (f & (1 << i))
+ if (f & (1 << i)) {
menu->set_item_checked(menu->get_item_index(i), true);
+ }
}
menu->set_position(get_position());
menu->popup();
@@ -562,8 +577,9 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant::
type = Variant::Type(i);
}
}
- if (type != Variant::NIL)
+ if (type != Variant::NIL) {
property_select->select_method_from_basic_type(type, v);
+ }
updating = false;
return false;
@@ -579,8 +595,9 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant::
MAKE_PROPSELECT
Object *instance = ObjectDB::get_instance(ObjectID(hint_text.to_int64()));
- if (instance)
+ if (instance) {
property_select->select_method_from_instance(instance, v);
+ }
updating = false;
return false;
@@ -599,16 +616,18 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant::
MAKE_PROPSELECT
Variant::Type type = Variant::NIL;
String tname = hint_text;
- if (tname.find(".") != -1)
+ if (tname.find(".") != -1) {
tname = tname.get_slice(".", 0);
+ }
for (int i = 0; i < Variant::VARIANT_MAX; i++) {
if (tname == Variant::get_type_name(Variant::Type(i))) {
type = Variant::Type(Variant::Type(i));
}
}
- if (type != Variant::NIL)
+ if (type != Variant::NIL) {
property_select->select_property_from_basic_type(type, v);
+ }
updating = false;
return false;
@@ -625,8 +644,9 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant::
MAKE_PROPSELECT
Object *instance = ObjectDB::get_instance(ObjectID(hint_text.to_int64()));
- if (instance)
+ if (instance) {
property_select->select_property_from_instance(instance, v);
+ }
updating = false;
return false;
@@ -793,10 +813,11 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant::
// get default color picker mode from editor settings
int default_color_mode = EDITOR_GET("interface/inspector/default_color_picker_mode");
- if (default_color_mode == 1)
+ if (default_color_mode == 1) {
color_picker->set_hsv_mode(true);
- else if (default_color_mode == 2)
+ } else if (default_color_mode == 2) {
color_picker->set_raw_mode(true);
+ }
}
color_picker->show();
@@ -811,15 +832,17 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant::
names.push_back(TTR("Assign"));
names.push_back(TTR("Clear"));
- if (owner && owner->is_class("Node") && (v.get_type() == Variant::NODE_PATH) && Object::cast_to<Node>(owner)->has_node(v))
+ if (owner && owner->is_class("Node") && (v.get_type() == Variant::NODE_PATH) && Object::cast_to<Node>(owner)->has_node(v)) {
names.push_back(TTR("Select Node"));
+ }
config_action_buttons(names);
} break;
case Variant::OBJECT: {
- if (hint != PROPERTY_HINT_RESOURCE_TYPE)
+ if (hint != PROPERTY_HINT_RESOURCE_TYPE) {
break;
+ }
if (p_name == "script" && hint_text == "Script" && Object::cast_to<Node>(owner)) {
menu->add_item(TTR("New Script"), OBJ_MENU_NEW_SCRIPT);
@@ -860,15 +883,17 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant::
for (int k = 0; k < custom_resources.size(); k++) {
if (custom_resources[k].name == t) {
is_custom_resource = true;
- if (custom_resources[k].icon.is_valid())
+ if (custom_resources[k].icon.is_valid()) {
icon = custom_resources[k].icon;
+ }
break;
}
}
}
- if (!is_custom_resource && !ClassDB::can_instance(t))
+ if (!is_custom_resource && !ClassDB::can_instance(t)) {
continue;
+ }
inheritors_array.push_back(t);
@@ -880,8 +905,9 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant::
}
}
- if (menu->get_item_count())
+ if (menu->get_item_count()) {
menu->add_separator();
+ }
}
menu->add_item(TTR("Load"), OBJ_MENU_LOAD);
@@ -901,14 +927,16 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant::
RES cb = EditorSettings::get_singleton()->get_resource_clipboard();
bool paste_valid = false;
if (cb.is_valid()) {
- if (hint_text == "")
+ if (hint_text == "") {
paste_valid = true;
- else
- for (int i = 0; i < hint_text.get_slice_count(","); i++)
+ } else {
+ for (int i = 0; i < hint_text.get_slice_count(","); i++) {
if (ClassDB::is_parent_class(cb->get_class(), hint_text.get_slice(",", i))) {
paste_valid = true;
break;
}
+ }
+ }
}
if (!RES(v).is_null() || paste_valid) {
@@ -939,7 +967,6 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant::
hide();
updating = false;
return false;
-
} break;
case Variant::DICTIONARY: {
} break;
@@ -1089,12 +1116,13 @@ void CustomPropertyEditor::_node_path_selected(NodePath p_path) {
} else if (owner) {
Node *node = nullptr;
- if (owner->is_class("Node"))
+ if (owner->is_class("Node")) {
node = Object::cast_to<Node>(owner);
- else if (owner->is_class("ArrayPropertyEdit"))
+ } else if (owner->is_class("ArrayPropertyEdit")) {
node = Object::cast_to<ArrayPropertyEdit>(owner)->get_node();
- else if (owner->is_class("DictionaryPropertyEdit"))
+ } else if (owner->is_class("DictionaryPropertyEdit")) {
node = Object::cast_to<DictionaryPropertyEdit>(owner)->get_node();
+ }
if (!node) {
v = p_path;
emit_signal("variant_changed");
@@ -1114,8 +1142,9 @@ void CustomPropertyEditor::_node_path_selected(NodePath p_path) {
}
void CustomPropertyEditor::_action_pressed(int p_which) {
- if (updating)
+ if (updating) {
return;
+ }
switch (type) {
case Variant::BOOL: {
@@ -1125,10 +1154,11 @@ void CustomPropertyEditor::_action_pressed(int p_which) {
case Variant::INT: {
if (hint == PROPERTY_HINT_LAYERS_2D_PHYSICS || hint == PROPERTY_HINT_LAYERS_2D_RENDER || hint == PROPERTY_HINT_LAYERS_3D_PHYSICS || hint == PROPERTY_HINT_LAYERS_3D_RENDER) {
uint32_t f = v;
- if (checks20[p_which]->is_pressed())
+ if (checks20[p_which]->is_pressed()) {
f |= (1 << p_which);
- else
+ } else {
f &= ~(1 << p_which);
+ }
v = f;
emit_signal("variant_changed");
@@ -1141,10 +1171,11 @@ void CustomPropertyEditor::_action_pressed(int p_which) {
} else if (hint == PROPERTY_HINT_FILE || hint == PROPERTY_HINT_GLOBAL_FILE) {
if (p_which == 0) {
- if (hint == PROPERTY_HINT_FILE)
+ if (hint == PROPERTY_HINT_FILE) {
file->set_access(EditorFileDialog::ACCESS_RESOURCES);
- else
+ } else {
file->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
+ }
file->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE);
file->clear_filters();
@@ -1155,10 +1186,11 @@ void CustomPropertyEditor::_action_pressed(int p_which) {
Vector<String> extensions = hint_text.split(",");
for (int i = 0; i < extensions.size(); i++) {
String filter = extensions[i];
- if (filter.begins_with("."))
+ if (filter.begins_with(".")) {
filter = "*" + extensions[i];
- else if (!filter.begins_with("*"))
+ } else if (!filter.begins_with("*")) {
filter = "*." + extensions[i];
+ }
file->add_filter(filter + " ; " + extensions[i].to_upper());
}
@@ -1172,10 +1204,11 @@ void CustomPropertyEditor::_action_pressed(int p_which) {
} else if (hint == PROPERTY_HINT_DIR || hint == PROPERTY_HINT_GLOBAL_DIR) {
if (p_which == 0) {
- if (hint == PROPERTY_HINT_DIR)
+ if (hint == PROPERTY_HINT_DIR) {
file->set_access(EditorFileDialog::ACCESS_RESOURCES);
- else
+ } else {
file->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
+ }
file->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_DIR);
file->clear_filters();
file->popup_centered_ratio();
@@ -1261,8 +1294,9 @@ void CustomPropertyEditor::_action_pressed(int p_which) {
hide();
} else if (p_which == 4) {
Ref<Resource> res_orig = v;
- if (res_orig.is_null())
+ if (res_orig.is_null()) {
return;
+ }
List<PropertyInfo> property_list;
res_orig->get_property_list(&property_list);
@@ -1305,17 +1339,20 @@ void CustomPropertyEditor::_drag_easing(const Ref<InputEvent> &p_ev) {
if (mm.is_valid() && mm->get_button_mask() & BUTTON_MASK_LEFT) {
float rel = mm->get_relative().x;
- if (rel == 0)
+ if (rel == 0) {
return;
+ }
bool flip = hint_text == "attenuation";
- if (flip)
+ if (flip) {
rel = -rel;
+ }
float val = v;
- if (val == 0)
+ if (val == 0) {
return;
+ }
bool sg = val < 0;
val = Math::absf(val);
@@ -1324,8 +1361,9 @@ void CustomPropertyEditor::_drag_easing(const Ref<InputEvent> &p_ev) {
val += rel * 0.05;
val = Math::pow(2.0f, val);
- if (sg)
+ if (sg) {
val = -val;
+ }
v = val;
easing_draw->update();
@@ -1384,8 +1422,9 @@ void CustomPropertyEditor::_create_selected_property(const String &p_prop) {
}
void CustomPropertyEditor::_modified(String p_string) {
- if (updating)
+ if (updating) {
return;
+ }
updating = true;
switch (type) {
@@ -1632,8 +1671,9 @@ void CustomPropertyEditor::config_action_buttons(const List<String> &p_strings)
action_buttons[i]->set_text(p_strings[i]);
Size2 btn_m_size = action_buttons[i]->get_minimum_size();
- if (btn_m_size.width > max_width)
+ if (btn_m_size.width > max_width) {
max_width = btn_m_size.width;
+ }
} else {
action_buttons[i]->hide();
diff --git a/editor/property_selector.cpp b/editor/property_selector.cpp
index 870bf52a91..6888ebdc71 100644
--- a/editor/property_selector.cpp
+++ b/editor/property_selector.cpp
@@ -51,8 +51,9 @@ void PropertySelector::_sbox_input(const Ref<InputEvent> &p_ie) {
search_box->accept_event();
TreeItem *root = search_options->get_root();
- if (!root->get_children())
+ if (!root->get_children()) {
break;
+ }
TreeItem *current = search_options->get_selected();
@@ -70,12 +71,13 @@ void PropertySelector::_sbox_input(const Ref<InputEvent> &p_ie) {
}
void PropertySelector::_update_search() {
- if (properties)
+ if (properties) {
set_title(TTR("Select Property"));
- else if (virtuals_only)
+ } else if (virtuals_only) {
set_title(TTR("Select Virtual Method"));
- else
+ } else {
set_title(TTR("Select Method"));
+ }
search_options->clear();
help_bit->set_text("");
@@ -161,14 +163,17 @@ void PropertySelector::_update_search() {
continue;
}
- if (!(E->get().usage & PROPERTY_USAGE_EDITOR) && !(E->get().usage & PROPERTY_USAGE_SCRIPT_VARIABLE))
+ if (!(E->get().usage & PROPERTY_USAGE_EDITOR) && !(E->get().usage & PROPERTY_USAGE_SCRIPT_VARIABLE)) {
continue;
+ }
- if (search_box->get_text() != String() && E->get().name.find(search_box->get_text()) == -1)
+ if (search_box->get_text() != String() && E->get().name.find(search_box->get_text()) == -1) {
continue;
+ }
- if (type_filter.size() && type_filter.find(E->get().type) == -1)
+ if (type_filter.size() && type_filter.find(E->get().type) == -1) {
continue;
+ }
TreeItem *item = search_options->create_item(category ? category : root);
item->set_text(0, E->get().name);
@@ -238,17 +243,21 @@ void PropertySelector::_update_search() {
}
String name = E->get().name.get_slice(":", 0);
- if (!script_methods && name.begins_with("_") && !(E->get().flags & METHOD_FLAG_VIRTUAL))
+ if (!script_methods && name.begins_with("_") && !(E->get().flags & METHOD_FLAG_VIRTUAL)) {
continue;
+ }
- if (virtuals_only && !(E->get().flags & METHOD_FLAG_VIRTUAL))
+ if (virtuals_only && !(E->get().flags & METHOD_FLAG_VIRTUAL)) {
continue;
+ }
- if (!virtuals_only && (E->get().flags & METHOD_FLAG_VIRTUAL))
+ if (!virtuals_only && (E->get().flags & METHOD_FLAG_VIRTUAL)) {
continue;
+ }
- if (search_box->get_text() != String() && name.find(search_box->get_text()) == -1)
+ if (search_box->get_text() != String() && name.find(search_box->get_text()) == -1) {
continue;
+ }
TreeItem *item = search_options->create_item(category ? category : root);
@@ -258,35 +267,40 @@ void PropertySelector::_update_search() {
if (mi.name.find(":") != -1) {
desc = mi.name.get_slice(":", 1) + " ";
mi.name = mi.name.get_slice(":", 0);
- } else if (mi.return_val.type != Variant::NIL)
+ } else if (mi.return_val.type != Variant::NIL) {
desc = Variant::get_type_name(mi.return_val.type);
- else
+ } else {
desc = "void ";
+ }
desc += " " + mi.name + " ( ";
for (int i = 0; i < mi.arguments.size(); i++) {
- if (i > 0)
+ if (i > 0) {
desc += ", ";
+ }
- if (mi.arguments[i].type == Variant::NIL)
+ if (mi.arguments[i].type == Variant::NIL) {
desc += "var ";
- else if (mi.arguments[i].name.find(":") != -1) {
+ } else if (mi.arguments[i].name.find(":") != -1) {
desc += mi.arguments[i].name.get_slice(":", 1) + " ";
mi.arguments[i].name = mi.arguments[i].name.get_slice(":", 0);
- } else
+ } else {
desc += Variant::get_type_name(mi.arguments[i].type) + " ";
+ }
desc += mi.arguments[i].name;
}
desc += " )";
- if (E->get().flags & METHOD_FLAG_CONST)
+ if (E->get().flags & METHOD_FLAG_CONST) {
desc += " const";
+ }
- if (E->get().flags & METHOD_FLAG_VIRTUAL)
+ if (E->get().flags & METHOD_FLAG_VIRTUAL) {
desc += " virtual";
+ }
item->set_text(0, desc);
item->set_metadata(0, name);
@@ -308,8 +322,9 @@ void PropertySelector::_update_search() {
void PropertySelector::_confirmed() {
TreeItem *ti = search_options->get_selected();
- if (!ti)
+ if (!ti) {
return;
+ }
emit_signal("selected", ti->get_metadata(0));
hide();
}
@@ -318,8 +333,9 @@ void PropertySelector::_item_selected() {
help_bit->set_text("");
TreeItem *item = search_options->get_selected();
- if (!item)
+ if (!item) {
return;
+ }
String name = item->get_metadata(0);
String class_type;
@@ -365,8 +381,9 @@ void PropertySelector::_item_selected() {
}
}
- if (text == String())
+ if (text == String()) {
return;
+ }
help_bit->set_text(text);
}
@@ -437,8 +454,9 @@ void PropertySelector::select_method_from_instance(Object *p_instance, const Str
script = ObjectID();
{
Ref<Script> scr = p_instance->get_script();
- if (scr.is_valid())
+ if (scr.is_valid()) {
script = scr->get_instance_id();
+ }
}
properties = false;
instance = nullptr;
diff --git a/editor/pvrtc_compress.cpp b/editor/pvrtc_compress.cpp
index 8532ed23be..23bcf9540e 100644
--- a/editor/pvrtc_compress.cpp
+++ b/editor/pvrtc_compress.cpp
@@ -47,14 +47,16 @@ static void _compress_image(Image::CompressMode p_mode, Image *p_image) {
if (ttpath.strip_edges() == "" || !FileAccess::exists(ttpath)) {
switch (p_mode) {
case Image::COMPRESS_PVRTC2:
- if (_base_image_compress_pvrtc2_func)
+ if (_base_image_compress_pvrtc2_func) {
_base_image_compress_pvrtc2_func(p_image);
- else if (_base_image_compress_pvrtc4_func)
+ } else if (_base_image_compress_pvrtc4_func) {
_base_image_compress_pvrtc4_func(p_image);
+ }
break;
case Image::COMPRESS_PVRTC4:
- if (_base_image_compress_pvrtc4_func)
+ if (_base_image_compress_pvrtc4_func) {
_base_image_compress_pvrtc4_func(p_image);
+ }
break;
default:
ERR_FAIL_MSG("Unsupported Image compress mode used in PVRTC module.");
diff --git a/editor/quick_open.cpp b/editor/quick_open.cpp
index e16b1f61fb..bcef29dfa6 100644
--- a/editor/quick_open.cpp
+++ b/editor/quick_open.cpp
@@ -35,14 +35,16 @@
void EditorQuickOpen::popup_dialog(const StringName &p_base, bool p_enable_multi, bool p_add_dirs, bool p_dontclear) {
add_directories = p_add_dirs;
popup_centered_ratio(0.6);
- if (p_dontclear)
+ if (p_dontclear) {
search_box->select_all();
- else
+ } else {
search_box->clear();
- if (p_enable_multi)
+ }
+ if (p_enable_multi) {
search_options->set_select_mode(Tree::SELECT_MULTI);
- else
+ } else {
search_options->set_select_mode(Tree::SELECT_SINGLE);
+ }
search_box->grab_focus();
base_type = p_base;
_update_search();
@@ -50,8 +52,9 @@ void EditorQuickOpen::popup_dialog(const StringName &p_base, bool p_enable_multi
String EditorQuickOpen::get_selected() const {
TreeItem *ti = search_options->get_selected();
- if (!ti)
+ if (!ti) {
return String();
+ }
return "res://" + ti->get_text(0);
}
@@ -85,8 +88,9 @@ void EditorQuickOpen::_sbox_input(const Ref<InputEvent> &p_ie) {
search_box->accept_event();
TreeItem *root = search_options->get_root();
- if (!root->get_children())
+ if (!root->get_children()) {
break;
+ }
TreeItem *current = search_options->get_selected();
@@ -130,8 +134,9 @@ void EditorQuickOpen::_parse_fs(EditorFileSystemDirectory *efsd, Vector<Pair<Str
if (add_directories) {
String path = efsd->get_path();
- if (!path.ends_with("/"))
+ if (!path.ends_with("/")) {
path += "/";
+ }
if (path != "res://") {
path = path.substr(6, path.length());
if (search_text.is_subsequence_ofi(path)) {
@@ -180,13 +185,15 @@ Vector<Pair<String, Ref<Texture2D>>> EditorQuickOpen::_sort_fs(Vector<Pair<Strin
String search_text = search_box->get_text();
Vector<Pair<String, Ref<Texture2D>>> sorted_list;
- if (search_text == String() || list.size() == 0)
+ if (search_text == String() || list.size() == 0) {
return list;
+ }
Vector<float> scores;
scores.resize(list.size());
- for (int i = 0; i < list.size(); i++)
+ for (int i = 0; i < list.size(); i++) {
scores.write[i] = _path_cmp(search_text, list[i].first);
+ }
while (list.size() > 0) {
float best_score = 0.0f;
@@ -235,8 +242,9 @@ void EditorQuickOpen::_update_search() {
void EditorQuickOpen::_confirmed() {
TreeItem *ti = search_options->get_selected();
- if (!ti)
+ if (!ti) {
return;
+ }
emit_signal("quick_open");
hide();
}
diff --git a/editor/rename_dialog.cpp b/editor/rename_dialog.cpp
index fa44efda29..6a54894f40 100644
--- a/editor/rename_dialog.cpp
+++ b/editor/rename_dialog.cpp
@@ -381,8 +381,9 @@ void RenameDialog::_update_preview_int(int new_value) {
}
void RenameDialog::_update_preview(String new_text) {
- if (lock_preview_update || preview_node == nullptr)
+ if (lock_preview_update || preview_node == nullptr) {
return;
+ }
has_errors = false;
add_error_handler(&eh);
@@ -469,8 +470,9 @@ void RenameDialog::_error_handler(void *p_self, const char *p_func, const char *
String source_file(p_file);
// Only show first error that is related to "regex"
- if (self->has_errors || source_file.find("regex") < 0)
+ if (self->has_errors || source_file.find("regex") < 0) {
return;
+ }
String err_str;
if (p_errorexp && p_errorexp[0]) {
@@ -538,8 +540,9 @@ String RenameDialog::_postprocess(const String &subject) {
}
void RenameDialog::_iterate_scene(const Node *node, const Array &selection, int *counter) {
- if (!node)
+ if (!node) {
return;
+ }
if (selection.has(node)) {
String new_name = _apply_rename(node, *counter);
diff --git a/editor/run_settings_dialog.cpp b/editor/run_settings_dialog.cpp
index e8c3c2065c..b6dda4c5bb 100644
--- a/editor/run_settings_dialog.cpp
+++ b/editor/run_settings_dialog.cpp
@@ -47,10 +47,11 @@ void RunSettingsDialog::_bind_methods() {
}
void RunSettingsDialog::_run_mode_changed(int idx) {
- if (idx == 0)
+ if (idx == 0) {
arguments->set_editable(false);
- else
+ } else {
arguments->set_editable(true);
+ }
}
int RunSettingsDialog::get_run_mode() const {
diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp
index c385405a01..e73c52047b 100644
--- a/editor/scene_tree_dock.cpp
+++ b/editor/scene_tree_dock.cpp
@@ -72,11 +72,13 @@ void SceneTreeDock::_input(Ref<InputEvent> p_event) {
}
void SceneTreeDock::_unhandled_key_input(Ref<InputEvent> p_event) {
- if (get_focus_owner() && get_focus_owner()->is_text_field())
+ if (get_focus_owner() && get_focus_owner()->is_text_field()) {
return;
+ }
- if (!p_event->is_pressed() || p_event->is_echo())
+ if (!p_event->is_pressed() || p_event->is_echo()) {
return;
+ }
if (ED_IS_SHORTCUT("scene_tree/batch_rename", p_event)) {
_tool_selected(TOOL_BATCH_RENAME);
@@ -304,13 +306,16 @@ bool SceneTreeDock::_track_inherit(const String &p_target_scene_path, Node *p_de
Ref<PackedScene> data = ResourceLoader::load(path);
if (data.is_valid()) {
p = data->instance(PackedScene::GEN_EDIT_STATE_INSTANCE);
- if (!p)
+ if (!p) {
continue;
+ }
instances.push_back(p);
- } else
+ } else {
break;
- } else
+ }
+ } else {
break;
+ }
}
for (int i = 0; i < instances.size(); i++) {
memdelete(instances[i]);
@@ -349,10 +354,11 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
Node *current_edited_scene_root = EditorNode::get_singleton()->get_edited_scene();
if (current_edited_scene_root) {
- if (ClassDB::is_parent_class(current_edited_scene_root->get_class_name(), "Node2D"))
+ if (ClassDB::is_parent_class(current_edited_scene_root->get_class_name(), "Node2D")) {
preferred = "Node2D";
- else if (ClassDB::is_parent_class(current_edited_scene_root->get_class_name(), "Node3D"))
+ } else if (ClassDB::is_parent_class(current_edited_scene_root->get_class_name(), "Node3D")) {
preferred = "Node3D";
+ }
}
create_dialog->set_preferred_search_result_type(preferred);
create_dialog->popup_create(true);
@@ -373,14 +379,16 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
} break;
case TOOL_EXPAND_COLLAPSE: {
- if (!scene_tree->get_selected())
+ if (!scene_tree->get_selected()) {
break;
+ }
Tree *tree = scene_tree->get_scene_tree();
TreeItem *selected_item = tree->get_selected();
- if (!selected_item)
+ if (!selected_item) {
selected_item = tree->get_root();
+ }
bool collapsed = _is_collapsed_recursive(selected_item);
_set_collapsed_recursive(selected_item, !collapsed);
@@ -394,11 +402,13 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
}
Node *selected = scene_tree->get_selected();
- if (!selected && !editor_selection->get_selected_node_list().empty())
+ if (!selected && !editor_selection->get_selected_node_list().empty()) {
selected = editor_selection->get_selected_node_list().front()->get();
+ }
- if (selected)
+ if (selected) {
create_dialog->popup_create(false, true, selected->get_class());
+ }
} break;
case TOOL_EXTEND_SCRIPT: {
@@ -414,8 +424,9 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
Array selection = editor_selection->get_selected_nodes();
- if (selection.empty())
+ if (selection.empty()) {
return;
+ }
editor_data->get_undo_redo().create_action(TTR("Detach Script"));
editor_data->get_undo_redo().add_do_method(editor, "push_item", (Script *)nullptr);
@@ -441,8 +452,9 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
break;
}
- if (!scene_tree->get_selected())
+ if (!scene_tree->get_selected()) {
break;
+ }
if (scene_tree->get_selected() == edited_scene) {
current_option = -1;
@@ -451,8 +463,9 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
break;
}
- if (!_validate_no_foreign())
+ if (!_validate_no_foreign()) {
break;
+ }
bool MOVING_DOWN = (p_tool == TOOL_MOVE_DOWN);
bool MOVING_UP = !MOVING_DOWN;
@@ -460,30 +473,37 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
Node *common_parent = scene_tree->get_selected()->get_parent();
List<Node *> selection = editor_selection->get_selected_node_list();
selection.sort_custom<Node::Comparator>(); // sort by index
- if (MOVING_DOWN)
+ if (MOVING_DOWN) {
selection.invert();
+ }
int lowest_id = common_parent->get_child_count() - 1;
int highest_id = 0;
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
int index = E->get()->get_index();
- if (index > highest_id)
+ if (index > highest_id) {
highest_id = index;
- if (index < lowest_id)
+ }
+ if (index < lowest_id) {
lowest_id = index;
+ }
- if (E->get()->get_parent() != common_parent)
+ if (E->get()->get_parent() != common_parent) {
common_parent = nullptr;
+ }
}
- if (!common_parent || (MOVING_DOWN && highest_id >= common_parent->get_child_count() - MOVING_DOWN) || (MOVING_UP && lowest_id == 0))
+ if (!common_parent || (MOVING_DOWN && highest_id >= common_parent->get_child_count() - MOVING_DOWN) || (MOVING_UP && lowest_id == 0)) {
break; // one or more nodes can not be moved
+ }
- if (selection.size() == 1)
+ if (selection.size() == 1) {
editor_data->get_undo_redo().create_action(TTR("Move Node In Parent"));
- if (selection.size() > 1)
+ }
+ if (selection.size() > 1) {
editor_data->get_undo_redo().create_action(TTR("Move Nodes In Parent"));
+ }
for (int i = 0; i < selection.size(); i++) {
Node *top_node = selection[i];
@@ -507,8 +527,9 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
break;
}
- if (!edited_scene)
+ if (!edited_scene) {
break;
+ }
if (editor_selection->is_selected(edited_scene)) {
current_option = -1;
@@ -517,12 +538,14 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
break;
}
- if (!_validate_no_foreign())
+ if (!_validate_no_foreign()) {
break;
+ }
List<Node *> selection = editor_selection->get_selected_node_list();
- if (selection.size() == 0)
+ if (selection.size() == 0) {
break;
+ }
editor_data->get_undo_redo().create_action(TTR("Duplicate Node(s)"));
editor_data->get_undo_redo().add_do_method(editor_selection, "clear");
@@ -544,13 +567,15 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
Map<const Node *, Node *> duplimap;
Node *dup = node->duplicate_from_editor(duplimap);
- if (EditorNode::get_singleton()->get_edited_scene()->is_editable_instance(node))
+ if (EditorNode::get_singleton()->get_edited_scene()->is_editable_instance(node)) {
editable_children.push_back(dup);
+ }
ERR_CONTINUE(!dup);
- if (selection.size() == 1)
+ if (selection.size() == 1) {
dupsingle = dup;
+ }
dup->set_name(parent->validate_child_name(dup));
@@ -576,11 +601,13 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
editor_data->get_undo_redo().commit_action();
- if (dupsingle)
+ if (dupsingle) {
editor->push_item(dupsingle);
+ }
- for (List<Node *>::Element *E = editable_children.back(); E; E = E->prev())
+ for (List<Node *>::Element *E = editable_children.back(); E; E = E->prev()) {
_toggle_editable_children(E->get());
+ }
} break;
case TOOL_REPARENT: {
@@ -588,8 +615,9 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
break;
}
- if (!scene_tree->get_selected())
+ if (!scene_tree->get_selected()) {
break;
+ }
if (editor_selection->is_selected(edited_scene)) {
current_option = -1;
@@ -598,8 +626,9 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
break;
}
- if (!_validate_no_foreign())
+ if (!_validate_no_foreign()) {
break;
+ }
List<Node *> nodes = editor_selection->get_selected_node_list();
Set<Node *> nodeset;
@@ -621,8 +650,9 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
Node *node = nodes.front()->get();
Node *root = get_tree()->get_edited_scene_root();
- if (node == root)
+ if (node == root) {
return;
+ }
//check that from node to root, all owners are right
@@ -674,8 +704,9 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
}
Node *root = EditorNode::get_singleton()->get_edited_scene();
- if (!root)
+ if (!root) {
break;
+ }
Ref<MultiNodeEdit> mne = memnew(MultiNodeEdit);
for (const Map<Node *, Object *>::Element *E = EditorNode::get_singleton()->get_editor_selection()->get_selection().front(); E; E = E->next()) {
mne->add_node(root->get_path_to(E->key()));
@@ -692,11 +723,13 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
List<Node *> remove_list = editor_selection->get_selected_node_list();
- if (remove_list.empty())
+ if (remove_list.empty()) {
return;
+ }
- if (!_validate_no_foreign())
+ if (!_validate_no_foreign()) {
break;
+ }
if (p_confirm_override) {
_delete_confirm();
@@ -845,8 +878,9 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
placeholder = !placeholder;
- if (placeholder)
+ if (placeholder) {
EditorNode::get_singleton()->get_edited_scene()->set_editable_instance(node, false);
+ }
node->set_scene_instance_load_placeholder(placeholder);
scene_tree->update_tree();
@@ -865,8 +899,9 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
if (node) {
Node *root = EditorNode::get_singleton()->get_edited_scene();
UndoRedo *undo_redo = &editor_data->get_undo_redo();
- if (!root)
+ if (!root) {
break;
+ }
ERR_FAIL_COND(node->get_filename() == String());
undo_redo->create_action(TTR("Make Local"));
@@ -992,8 +1027,9 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
void SceneTreeDock::_node_collapsed(Object *p_obj) {
TreeItem *ti = Object::cast_to<TreeItem>(p_obj);
- if (!ti)
+ if (!ti) {
return;
+ }
if (Input::get_singleton()->is_key_pressed(KEY_SHIFT)) {
_set_collapsed_recursive(ti, ti->is_collapsed());
@@ -1003,8 +1039,9 @@ void SceneTreeDock::_node_collapsed(Object *p_obj) {
void SceneTreeDock::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_READY: {
- if (!first_enter)
+ if (!first_enter) {
break;
+ }
first_enter = false;
EditorFeatureProfileManager::get_singleton()->connect("current_feature_profile_changed", callable_mp(this, &SceneTreeDock::_feature_profile_changed));
@@ -1177,21 +1214,24 @@ void SceneTreeDock::_node_renamed() {
void SceneTreeDock::_set_owners(Node *p_owner, const Array &p_nodes) {
for (int i = 0; i < p_nodes.size(); i++) {
Node *n = Object::cast_to<Node>(p_nodes[i]);
- if (!n)
+ if (!n) {
continue;
+ }
n->set_owner(p_owner);
}
}
void SceneTreeDock::_fill_path_renames(Vector<StringName> base_path, Vector<StringName> new_base_path, Node *p_node, List<Pair<NodePath, NodePath>> *p_renames) {
base_path.push_back(p_node->get_name());
- if (new_base_path.size())
+ if (new_base_path.size()) {
new_base_path.push_back(p_node->get_name());
+ }
NodePath from(base_path, true);
NodePath to;
- if (new_base_path.size())
+ if (new_base_path.size()) {
to = NodePath(new_base_path, true);
+ }
Pair<NodePath, NodePath> npp;
npp.first = from;
@@ -1205,8 +1245,9 @@ void SceneTreeDock::_fill_path_renames(Vector<StringName> base_path, Vector<Stri
}
void SceneTreeDock::fill_path_renames(Node *p_node, Node *p_new_parent, List<Pair<NodePath, NodePath>> *p_renames) {
- if (!bool(EDITOR_DEF("editors/animation/autorename_animation_tracks", true)))
+ if (!bool(EDITOR_DEF("editors/animation/autorename_animation_tracks", true))) {
return;
+ }
Vector<StringName> base_path;
Node *n = p_node->get_parent();
@@ -1233,15 +1274,17 @@ void SceneTreeDock::fill_path_renames(Node *p_node, Node *p_new_parent, List<Pai
void SceneTreeDock::perform_node_renames(Node *p_base, List<Pair<NodePath, NodePath>> *p_renames, Map<Ref<Animation>, Set<int>> *r_rem_anims) {
Map<Ref<Animation>, Set<int>> rem_anims;
- if (!r_rem_anims)
+ if (!r_rem_anims) {
r_rem_anims = &rem_anims;
+ }
if (!p_base) {
p_base = edited_scene;
}
- if (!p_base)
+ if (!p_base) {
return;
+ }
// Renaming node paths used in script instances
if (p_base->get_script_instance()) {
@@ -1309,14 +1352,16 @@ void SceneTreeDock::perform_node_renames(Node *p_base, List<Pair<NodePath, NodeP
if (!r_rem_anims->has(anim)) {
r_rem_anims->insert(anim, Set<int>());
Set<int> &ran = r_rem_anims->find(anim)->get();
- for (int i = 0; i < anim->get_track_count(); i++)
+ for (int i = 0; i < anim->get_track_count(); i++) {
ran.insert(i);
+ }
}
Set<int> &ran = r_rem_anims->find(anim)->get();
- if (anim.is_null())
+ if (anim.is_null()) {
continue;
+ }
for (int i = 0; i < anim->get_track_count(); i++) {
NodePath track_np = anim->track_get_path(i);
@@ -1327,8 +1372,9 @@ void SceneTreeDock::perform_node_renames(Node *p_base, List<Pair<NodePath, NodeP
NodePath old_np = n->get_path();
- if (!ran.has(i))
+ if (!ran.has(i)) {
continue; //channel was removed
+ }
for (List<Pair<NodePath, NodePath>>::Element *F = p_renames->front(); F; F = F->next()) {
if (F->get().first == old_np) {
@@ -1359,8 +1405,9 @@ void SceneTreeDock::perform_node_renames(Node *p_base, List<Pair<NodePath, NodeP
NodePath rel_path = new_root_path.rel_path_to(F->get().second);
NodePath new_path = NodePath(rel_path.get_names(), track_np.get_subnames(), false);
- if (new_path == track_np)
+ if (new_path == track_np) {
continue; //bleh
+ }
editor_data->get_undo_redo().add_do_method(anim.ptr(), "track_set_path", i, new_path);
editor_data->get_undo_redo().add_undo_method(anim.ptr(), "track_set_path", i, track_np);
}
@@ -1372,8 +1419,9 @@ void SceneTreeDock::perform_node_renames(Node *p_base, List<Pair<NodePath, NodeP
}
}
- for (int i = 0; i < p_base->get_child_count(); i++)
+ for (int i = 0; i < p_base->get_child_count(); i++) {
perform_node_renames(p_base->get_child(i), p_renames, r_rem_anims);
+ }
}
void SceneTreeDock::_node_prerenamed(Node *p_node, const String &p_new_name) {
@@ -1397,8 +1445,9 @@ void SceneTreeDock::_node_prerenamed(Node *p_node, const String &p_new_name) {
npp.second = NodePath(new_base_path, true);
path_renames.push_back(npp);
- for (int i = 0; i < p_node->get_child_count(); i++)
+ for (int i = 0; i < p_node->get_child_count(); i++) {
_fill_path_renames(base_path, new_base_path, p_node->get_child(i), &path_renames);
+ }
perform_node_renames(nullptr, &path_renames);
}
@@ -1436,8 +1485,9 @@ void SceneTreeDock::_node_reparent(NodePath p_path, bool p_keep_global_xform) {
List<Node *> selection = editor_selection->get_selected_node_list();
- if (selection.empty())
+ if (selection.empty()) {
return; // Nothing to reparent.
+ }
Vector<Node *> nodes;
@@ -1452,22 +1502,26 @@ void SceneTreeDock::_do_reparent(Node *p_new_parent, int p_position_in_parent, V
Node *new_parent = p_new_parent;
ERR_FAIL_COND(!new_parent);
- if (p_nodes.size() == 0)
+ if (p_nodes.size() == 0) {
return; // Nothing to reparent.
+ }
p_nodes.sort_custom<Node::Comparator>(); //Makes result reliable.
bool no_change = true;
for (int ni = 0; ni < p_nodes.size(); ni++) {
- if (p_nodes[ni] == p_new_parent)
+ if (p_nodes[ni] == p_new_parent) {
return; // Attempt to reparent to itself.
+ }
- if (p_nodes[ni]->get_parent() != p_new_parent || p_position_in_parent + ni != p_nodes[ni]->get_index())
+ if (p_nodes[ni]->get_parent() != p_new_parent || p_position_in_parent + ni != p_nodes[ni]->get_index()) {
no_change = false;
+ }
}
- if (no_change)
+ if (no_change) {
return; // Position and parent didn't change.
+ }
Node *validate = new_parent;
while (validate) {
@@ -1499,14 +1553,16 @@ void SceneTreeDock::_do_reparent(Node *p_new_parent, int p_position_in_parent, V
owners.push_back(E->get());
}
- if (new_parent == node->get_parent() && node->get_index() < p_position_in_parent + ni)
+ if (new_parent == node->get_parent() && node->get_index() < p_position_in_parent + ni) {
inc--; // If the child will generate a gap when moved, adjust.
+ }
editor_data->get_undo_redo().add_do_method(node->get_parent(), "remove_child", node);
editor_data->get_undo_redo().add_do_method(new_parent, "add_child", node);
- if (p_position_in_parent >= 0)
+ if (p_position_in_parent >= 0) {
editor_data->get_undo_redo().add_do_method(new_parent, "move_child", node, p_position_in_parent + inc);
+ }
EditorDebuggerNode *ed = EditorDebuggerNode::get_singleton();
String old_name = former_names[ni];
@@ -1536,18 +1592,22 @@ void SceneTreeDock::_do_reparent(Node *p_new_parent, int p_position_in_parent, V
editor_data->get_undo_redo().add_undo_method(ed, "live_debug_reparent_node", NodePath(String(edited_scene->get_path_to(new_parent)).plus_file(new_name)), edited_scene->get_path_to(node->get_parent()), node->get_name(), node->get_index());
if (p_keep_global_xform) {
- if (Object::cast_to<Node2D>(node))
+ if (Object::cast_to<Node2D>(node)) {
editor_data->get_undo_redo().add_do_method(node, "set_global_transform", Object::cast_to<Node2D>(node)->get_global_transform());
- if (Object::cast_to<Node3D>(node))
+ }
+ if (Object::cast_to<Node3D>(node)) {
editor_data->get_undo_redo().add_do_method(node, "set_global_transform", Object::cast_to<Node3D>(node)->get_global_transform());
- if (Object::cast_to<Control>(node))
+ }
+ if (Object::cast_to<Control>(node)) {
editor_data->get_undo_redo().add_do_method(node, "set_global_position", Object::cast_to<Control>(node)->get_global_position());
+ }
}
editor_data->get_undo_redo().add_do_method(this, "_set_owners", edited_scene, owners);
- if (AnimationPlayerEditor::singleton->get_track_editor()->get_root() == node)
+ if (AnimationPlayerEditor::singleton->get_track_editor()->get_root() == node) {
editor_data->get_undo_redo().add_do_method(AnimationPlayerEditor::singleton->get_track_editor(), "set_root", node);
+ }
editor_data->get_undo_redo().add_undo_method(new_parent, "remove_child", node);
editor_data->get_undo_redo().add_undo_method(node, "set_name", former_names[ni]);
@@ -1571,16 +1631,20 @@ void SceneTreeDock::_do_reparent(Node *p_new_parent, int p_position_in_parent, V
editor_data->get_undo_redo().add_undo_method(node->get_parent(), "add_child", node);
editor_data->get_undo_redo().add_undo_method(node->get_parent(), "move_child", node, child_pos);
editor_data->get_undo_redo().add_undo_method(this, "_set_owners", edited_scene, owners);
- if (AnimationPlayerEditor::singleton->get_track_editor()->get_root() == node)
+ if (AnimationPlayerEditor::singleton->get_track_editor()->get_root() == node) {
editor_data->get_undo_redo().add_undo_method(AnimationPlayerEditor::singleton->get_track_editor(), "set_root", node);
+ }
if (p_keep_global_xform) {
- if (Object::cast_to<Node2D>(node))
+ if (Object::cast_to<Node2D>(node)) {
editor_data->get_undo_redo().add_undo_method(node, "set_transform", Object::cast_to<Node2D>(node)->get_transform());
- if (Object::cast_to<Node3D>(node))
+ }
+ if (Object::cast_to<Node3D>(node)) {
editor_data->get_undo_redo().add_undo_method(node, "set_transform", Object::cast_to<Node3D>(node)->get_transform());
- if (Object::cast_to<Control>(node))
+ }
+ if (Object::cast_to<Control>(node)) {
editor_data->get_undo_redo().add_undo_method(node, "set_position", Object::cast_to<Control>(node)->get_position());
+ }
}
}
@@ -1634,8 +1698,9 @@ void SceneTreeDock::_set_collapsed_recursive(TreeItem *p_item, bool p_collapsed)
void SceneTreeDock::_script_created(Ref<Script> p_script) {
List<Node *> selected = editor_selection->get_selected_node_list();
- if (selected.empty())
+ if (selected.empty()) {
return;
+ }
editor_data->get_undo_redo().create_action(TTR("Attach Script"));
for (List<Node *>::Element *E = selected.front(); E; E = E->next()) {
@@ -1687,8 +1752,9 @@ void SceneTreeDock::_toggle_editable_children(Node *p_node) {
if (p_node) {
bool editable = !EditorNode::get_singleton()->get_edited_scene()->is_editable_instance(p_node);
EditorNode::get_singleton()->get_edited_scene()->set_editable_instance(p_node, editable);
- if (editable)
+ if (editable) {
p_node->set_scene_instance_load_placeholder(false);
+ }
Node3DEditor::get_singleton()->update_all_gizmos(p_node);
@@ -1699,8 +1765,9 @@ void SceneTreeDock::_toggle_editable_children(Node *p_node) {
void SceneTreeDock::_delete_confirm() {
List<Node *> remove_list = editor_selection->get_selected_node_list();
- if (remove_list.empty())
+ if (remove_list.empty()) {
return;
+ }
editor->get_editor_plugins_over()->make_visible(false);
@@ -1728,8 +1795,9 @@ void SceneTreeDock::_delete_confirm() {
//delete from animation
for (List<Node *>::Element *E = remove_list.front(); E; E = E->next()) {
Node *n = E->get();
- if (!n->is_inside_tree() || !n->get_parent())
+ if (!n->is_inside_tree() || !n->get_parent()) {
continue;
+ }
fill_path_renames(n, nullptr, &path_renames);
}
@@ -1738,8 +1806,9 @@ void SceneTreeDock::_delete_confirm() {
//delete for read
for (List<Node *>::Element *E = remove_list.front(); E; E = E->next()) {
Node *n = E->get();
- if (!n->is_inside_tree() || !n->get_parent())
+ if (!n->is_inside_tree() || !n->get_parent()) {
continue;
+ }
List<Node *> owned;
n->get_owned_by(n->get_owner(), &owned);
@@ -1751,8 +1820,9 @@ void SceneTreeDock::_delete_confirm() {
editor_data->get_undo_redo().add_do_method(n->get_parent(), "remove_child", n);
editor_data->get_undo_redo().add_undo_method(n->get_parent(), "add_child", n);
editor_data->get_undo_redo().add_undo_method(n->get_parent(), "move_child", n, n->get_index());
- if (AnimationPlayerEditor::singleton->get_track_editor()->get_root() == n)
+ if (AnimationPlayerEditor::singleton->get_track_editor()->get_root() == n) {
editor_data->get_undo_redo().add_undo_method(AnimationPlayerEditor::singleton->get_track_editor(), "set_root", n);
+ }
editor_data->get_undo_redo().add_undo_method(this, "_set_owners", edited_scene, owners);
editor_data->get_undo_redo().add_undo_reference(n);
@@ -1764,8 +1834,9 @@ void SceneTreeDock::_delete_confirm() {
editor_data->get_undo_redo().commit_action();
// hack, force 2d editor viewport to refresh after deletion
- if (CanvasItemEditor *editor = CanvasItemEditor::get_singleton())
+ if (CanvasItemEditor *editor = CanvasItemEditor::get_singleton()) {
editor->get_viewport_control()->update();
+ }
editor->push_item(nullptr);
@@ -1825,10 +1896,11 @@ Node *SceneTreeDock::_get_selection_group_tail(Node *p_node, List<Node *> p_list
for (int i = p_node->get_index(); i < parent->get_child_count(); i++) {
Node *sibling = parent->get_child(i);
- if (p_list.find(sibling))
+ if (p_list.find(sibling)) {
tail = sibling;
- else
+ } else {
break;
+ }
}
return tail;
@@ -1872,10 +1944,12 @@ void SceneTreeDock::_do_create(Node *p_parent) {
Control *ct = Object::cast_to<Control>(c);
Size2 ms = ct->get_minimum_size();
- if (ms.width < 4)
+ if (ms.width < 4) {
ms.width = 40;
- if (ms.height < 4)
+ }
+ if (ms.height < 4) {
ms.height = 40;
+ }
ct->set_size(ms);
}
}
@@ -1887,8 +1961,9 @@ void SceneTreeDock::_create() {
if (edited_scene) {
// If root exists in edited scene
parent = scene_tree->get_selected();
- if (!parent)
+ if (!parent) {
parent = edited_scene;
+ }
} else {
// If no root exist in edited scene
@@ -1946,17 +2021,19 @@ void SceneTreeDock::_create() {
smaller_path_to_top = path_length;
only_one_top_node = true;
} else if (smaller_path_to_top == path_length) {
- if (only_one_top_node && top_node->get_parent() != n->get_parent())
+ if (only_one_top_node && top_node->get_parent() != n->get_parent()) {
only_one_top_node = false;
+ }
}
}
}
Node *parent = nullptr;
- if (only_one_top_node)
+ if (only_one_top_node) {
parent = top_node->get_parent();
- else
+ } else {
parent = top_node->get_parent()->get_parent();
+ }
_do_create(parent);
@@ -1983,10 +2060,12 @@ void SceneTreeDock::replace_node(Node *p_node, Node *p_by_node, bool p_keep_prop
n->get_property_list(&pinfo);
for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
- if (!(E->get().usage & PROPERTY_USAGE_STORAGE))
+ if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) {
continue;
- if (E->get().name == "__meta__")
+ }
+ if (E->get().name == "__meta__") {
continue;
+ }
if (default_oldnode->get(E->get().name) != n->get(E->get().name)) {
newnode->set(E->get().name, n->get(E->get().name));
}
@@ -2007,8 +2086,9 @@ void SceneTreeDock::replace_node(Node *p_node, Node *p_by_node, bool p_keep_prop
for (List<Object::Connection>::Element *F = cl.front(); F; F = F->next()) {
Object::Connection &c = F->get();
- if (!(c.flags & Object::CONNECT_PERSIST))
+ if (!(c.flags & Object::CONNECT_PERSIST)) {
continue;
+ }
newnode->connect(c.signal.get_name(), c.callable, c.binds, Object::CONNECT_PERSIST);
}
}
@@ -2035,8 +2115,9 @@ void SceneTreeDock::replace_node(Node *p_node, Node *p_by_node, bool p_keep_prop
c->call("set_transform", c->call("get_transform"));
}
//p_remove_old was added to support undo
- if (p_remove_old)
+ if (p_remove_old) {
editor_data->get_undo_redo().clear_history();
+ }
newnode->set_name(newname);
editor->push_item(newnode);
@@ -2106,8 +2187,9 @@ void SceneTreeDock::_new_scene_from(String p_file) {
}
int flg = 0;
- if (EditorSettings::get_singleton()->get("filesystem/on_save/compress_binary_resources"))
+ if (EditorSettings::get_singleton()->get("filesystem/on_save/compress_binary_resources")) {
flg |= ResourceSaver::FLAG_COMPRESS;
+ }
err = ResourceSaver::save(p_file, sdata, flg);
if (err != OK) {
@@ -2124,23 +2206,27 @@ void SceneTreeDock::_new_scene_from(String p_file) {
}
static bool _is_node_visible(Node *p_node) {
- if (!p_node->get_owner())
+ if (!p_node->get_owner()) {
return false;
- if (p_node->get_owner() != EditorNode::get_singleton()->get_edited_scene() && !EditorNode::get_singleton()->get_edited_scene()->is_editable_instance(p_node->get_owner()))
+ }
+ if (p_node->get_owner() != EditorNode::get_singleton()->get_edited_scene() && !EditorNode::get_singleton()->get_edited_scene()->is_editable_instance(p_node->get_owner())) {
return false;
+ }
return true;
}
static bool _has_visible_children(Node *p_node) {
bool collapsed = p_node->is_displayed_folded();
- if (collapsed)
+ if (collapsed) {
return false;
+ }
for (int i = 0; i < p_node->get_child_count(); i++) {
Node *child = p_node->get_child(i);
- if (!_is_node_visible(child))
+ if (!_is_node_visible(child)) {
continue;
+ }
return true;
}
@@ -2216,12 +2302,14 @@ void SceneTreeDock::_script_dropped(String p_file, NodePath p_to) {
void SceneTreeDock::_nodes_dragged(Array p_nodes, NodePath p_to, int p_type) {
List<Node *> selection = editor_selection->get_selected_node_list();
- if (selection.empty())
+ if (selection.empty()) {
return; //nothing to reparent
+ }
Node *to_node = get_node(p_to);
- if (!to_node)
+ if (!to_node) {
return;
+ }
Vector<Node *> nodes;
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
@@ -2235,23 +2323,28 @@ void SceneTreeDock::_nodes_dragged(Array p_nodes, NodePath p_to, int p_type) {
}
void SceneTreeDock::_add_children_to_popup(Object *p_obj, int p_depth) {
- if (p_depth > 8)
+ if (p_depth > 8) {
return;
+ }
List<PropertyInfo> pinfo;
p_obj->get_property_list(&pinfo);
for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
- if (!(E->get().usage & PROPERTY_USAGE_EDITOR))
+ if (!(E->get().usage & PROPERTY_USAGE_EDITOR)) {
continue;
- if (E->get().hint != PROPERTY_HINT_RESOURCE_TYPE)
+ }
+ if (E->get().hint != PROPERTY_HINT_RESOURCE_TYPE) {
continue;
+ }
Variant value = p_obj->get(E->get().name);
- if (value.get_type() != Variant::OBJECT)
+ if (value.get_type() != Variant::OBJECT) {
continue;
+ }
Object *obj = value;
- if (!obj)
+ if (!obj) {
continue;
+ }
Ref<Texture2D> icon = EditorNode::get_singleton()->get_object_icon(obj);
@@ -2284,8 +2377,9 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) {
List<Node *> selection = editor_selection->get_selected_node_list();
List<Node *> full_selection = editor_selection->get_full_selected_node_list(); // Above method only returns nodes with common parent.
- if (selection.size() == 0)
+ if (selection.size() == 0) {
return;
+ }
menu->clear();
@@ -2299,8 +2393,9 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) {
menu_subresources->clear();
menu_subresources->set_size(Size2(1, 1));
_add_children_to_popup(selection.front()->get(), 0);
- if (menu->get_item_count() > 0)
+ if (menu->get_item_count() > 0) {
menu->add_separator();
+ }
menu->add_icon_shortcut(get_theme_icon("Add", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/add_child_node"), TOOL_NEW);
menu->add_icon_shortcut(get_theme_icon("Instance", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/instance_scene"), TOOL_INSTANCE);
@@ -2454,12 +2549,14 @@ void SceneTreeDock::attach_script_to_selected(bool p_extend) {
}
List<Node *> selection = editor_selection->get_selected_node_list();
- if (selection.empty())
+ if (selection.empty()) {
return;
+ }
Node *selected = scene_tree->get_selected();
- if (!selected)
+ if (!selected) {
selected = selection.front()->get();
+ }
Ref<Script> existing = selected->get_script();
@@ -2533,8 +2630,9 @@ void SceneTreeDock::hide_tab_buttons() {
void SceneTreeDock::_remote_tree_selected() {
scene_tree->hide();
create_root_dialog->hide();
- if (remote_tree)
+ if (remote_tree) {
remote_tree->show();
+ }
edit_remote->set_pressed(true);
edit_local->set_pressed(false);
@@ -2543,8 +2641,9 @@ void SceneTreeDock::_remote_tree_selected() {
void SceneTreeDock::_local_tree_selected() {
scene_tree->show();
- if (remote_tree)
+ if (remote_tree) {
remote_tree->hide();
+ }
edit_remote->set_pressed(false);
edit_local->set_pressed(true);
}
@@ -2553,14 +2652,16 @@ void SceneTreeDock::_update_create_root_dialog() {
BaseButton *toggle = Object::cast_to<BaseButton>(create_root_dialog->get_node(String("NodeShortcutsTopRow/NodeShortcutsToggle")));
Node *node_shortcuts = create_root_dialog->get_node(String("NodeShortcuts"));
- if (!toggle || !node_shortcuts)
+ if (!toggle || !node_shortcuts) {
return;
+ }
Control *beginner_nodes = Object::cast_to<Control>(node_shortcuts->get_node(String("BeginnerNodeShortcuts")));
Control *favorite_nodes = Object::cast_to<Control>(node_shortcuts->get_node(String("FavoriteNodeShortcuts")));
- if (!beginner_nodes || !favorite_nodes)
+ if (!beginner_nodes || !favorite_nodes) {
return;
+ }
EditorSettings::get_singleton()->set_setting("_use_favorites_root_selection", toggle->is_pressed());
EditorSettings::get_singleton()->save();
@@ -2580,8 +2681,9 @@ void SceneTreeDock::_update_create_root_dialog() {
favorite_nodes->add_child(button);
button->set_text(TTR(l));
String name = l.get_slicec(' ', 0);
- if (ScriptServer::is_global_class(name))
+ if (ScriptServer::is_global_class(name)) {
name = ScriptServer::get_global_class_native_base(name);
+ }
button->set_icon(EditorNode::get_singleton()->get_class_icon(name));
button->connect("pressed", callable_mp(this, &SceneTreeDock::_favorite_root_selected), make_binds(l));
}
diff --git a/editor/scene_tree_editor.cpp b/editor/scene_tree_editor.cpp
index 757dff2552..1b818036e1 100644
--- a/editor/scene_tree_editor.cpp
+++ b/editor/scene_tree_editor.cpp
@@ -69,8 +69,9 @@ void SceneTreeEditor::_cell_button_pressed(Object *p_item, int p_column, int p_i
}
} else if (p_id == BUTTON_SCRIPT) {
Ref<Script> script_typed = n->get_script();
- if (!script_typed.is_null())
+ if (!script_typed.is_null()) {
emit_signal("open_script", script_typed);
+ }
} else if (p_id == BUTTON_VISIBILITY) {
undo_redo->create_action(TTR("Toggle Visible"));
@@ -119,8 +120,9 @@ void SceneTreeEditor::_cell_button_pressed(Object *p_item, int p_column, int p_i
undo_redo->commit_action();
} else if (p_id == BUTTON_WARNING) {
String config_err = n->get_configuration_warning();
- if (config_err == String())
+ if (config_err == String()) {
return;
+ }
config_err = config_err.word_wrap(80);
warning->set_text(config_err);
warning->popup_centered();
@@ -154,8 +156,9 @@ void SceneTreeEditor::_toggle_visible(Node *p_node) {
}
bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent) {
- if (!p_node)
+ if (!p_node) {
return false;
+ }
// only owned nodes are editable, since nodes can create their own (manually owned) child nodes,
// which the editor needs not to know about.
@@ -176,14 +179,16 @@ bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent) {
TreeItem *item = tree->create_item(p_parent);
item->set_text(0, p_node->get_name());
- if (can_rename && !part_of_subscene)
+ if (can_rename && !part_of_subscene) {
item->set_editable(0, true);
+ }
item->set_selectable(0, true);
if (can_rename) {
bool collapsed = p_node->is_displayed_folded();
- if (collapsed)
+ if (collapsed) {
item->set_collapsed(true);
+ }
}
Ref<Texture2D> icon = EditorNode::get_singleton()->get_object_icon(p_node, "Node");
@@ -310,8 +315,9 @@ bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent) {
if (can_open_instance && undo_redo) { //Show buttons only when necessary(SceneTreeDock) to avoid crashes
- if (!p_node->is_connected("script_changed", callable_mp(this, &SceneTreeEditor::_node_script_changed)))
+ if (!p_node->is_connected("script_changed", callable_mp(this, &SceneTreeEditor::_node_script_changed))) {
p_node->connect("script_changed", callable_mp(this, &SceneTreeEditor::_node_script_changed), varray(p_node));
+ }
Ref<Script> script = p_node->get_script();
if (!script.is_null()) {
@@ -323,40 +329,48 @@ bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent) {
if (p_node->is_class("CanvasItem")) {
bool is_locked = p_node->has_meta("_edit_lock_"); //_edit_group_
- if (is_locked)
+ if (is_locked) {
item->add_button(0, get_theme_icon("Lock", "EditorIcons"), BUTTON_LOCK, false, TTR("Node is locked.\nClick to unlock it."));
+ }
bool is_grouped = p_node->has_meta("_edit_group_");
- if (is_grouped)
+ if (is_grouped) {
item->add_button(0, get_theme_icon("Group", "EditorIcons"), BUTTON_GROUP, false, TTR("Children are not selectable.\nClick to make selectable."));
+ }
bool v = p_node->call("is_visible");
- if (v)
+ if (v) {
item->add_button(0, get_theme_icon("GuiVisibilityVisible", "EditorIcons"), BUTTON_VISIBILITY, false, TTR("Toggle Visibility"));
- else
+ } else {
item->add_button(0, get_theme_icon("GuiVisibilityHidden", "EditorIcons"), BUTTON_VISIBILITY, false, TTR("Toggle Visibility"));
+ }
- if (!p_node->is_connected("visibility_changed", callable_mp(this, &SceneTreeEditor::_node_visibility_changed)))
+ if (!p_node->is_connected("visibility_changed", callable_mp(this, &SceneTreeEditor::_node_visibility_changed))) {
p_node->connect("visibility_changed", callable_mp(this, &SceneTreeEditor::_node_visibility_changed), varray(p_node));
+ }
_update_visibility_color(p_node, item);
} else if (p_node->is_class("Node3D")) {
bool is_locked = p_node->has_meta("_edit_lock_");
- if (is_locked)
+ if (is_locked) {
item->add_button(0, get_theme_icon("Lock", "EditorIcons"), BUTTON_LOCK, false, TTR("Node is locked.\nClick to unlock it."));
+ }
bool is_grouped = p_node->has_meta("_edit_group_");
- if (is_grouped)
+ if (is_grouped) {
item->add_button(0, get_theme_icon("Group", "EditorIcons"), BUTTON_GROUP, false, TTR("Children are not selectable.\nClick to make selectable."));
+ }
bool v = p_node->call("is_visible");
- if (v)
+ if (v) {
item->add_button(0, get_theme_icon("GuiVisibilityVisible", "EditorIcons"), BUTTON_VISIBILITY, false, TTR("Toggle Visibility"));
- else
+ } else {
item->add_button(0, get_theme_icon("GuiVisibilityHidden", "EditorIcons"), BUTTON_VISIBILITY, false, TTR("Toggle Visibility"));
+ }
- if (!p_node->is_connected("visibility_changed", callable_mp(this, &SceneTreeEditor::_node_visibility_changed)))
+ if (!p_node->is_connected("visibility_changed", callable_mp(this, &SceneTreeEditor::_node_visibility_changed))) {
p_node->connect("visibility_changed", callable_mp(this, &SceneTreeEditor::_node_visibility_changed), varray(p_node));
+ }
_update_visibility_color(p_node, item);
} else if (p_node->is_class("AnimationPlayer")) {
@@ -375,8 +389,9 @@ bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent) {
}
if (selected == p_node) {
- if (!editor_selection)
+ if (!editor_selection) {
item->select(0);
+ }
item->set_as_cursor(0);
}
@@ -441,10 +456,11 @@ void SceneTreeEditor::_node_visibility_changed(Node *p_node) {
visible = p_node->call("is_visible");
}
- if (visible)
+ if (visible) {
item->set_button(0, idx, get_theme_icon("GuiVisibilityVisible", "EditorIcons"));
- else
+ } else {
item->set_button(0, idx, get_theme_icon("GuiVisibilityHidden", "EditorIcons"));
+ }
_update_visibility_color(p_node, item);
}
@@ -462,23 +478,27 @@ void SceneTreeEditor::_update_visibility_color(Node *p_node, TreeItem *p_item) {
}
void SceneTreeEditor::_node_script_changed(Node *p_node) {
- if (tree_dirty)
+ if (tree_dirty) {
return;
+ }
MessageQueue::get_singleton()->push_call(this, "_update_tree");
tree_dirty = true;
}
void SceneTreeEditor::_node_removed(Node *p_node) {
- if (EditorNode::get_singleton()->is_exiting())
+ if (EditorNode::get_singleton()->is_exiting()) {
return; //speed up exit
+ }
- if (p_node->is_connected("script_changed", callable_mp(this, &SceneTreeEditor::_node_script_changed)))
+ if (p_node->is_connected("script_changed", callable_mp(this, &SceneTreeEditor::_node_script_changed))) {
p_node->disconnect("script_changed", callable_mp(this, &SceneTreeEditor::_node_script_changed));
+ }
if (p_node->is_class("Node3D") || p_node->is_class("CanvasItem")) {
- if (p_node->is_connected("visibility_changed", callable_mp(this, &SceneTreeEditor::_node_visibility_changed)))
+ if (p_node->is_connected("visibility_changed", callable_mp(this, &SceneTreeEditor::_node_visibility_changed))) {
p_node->disconnect("visibility_changed", callable_mp(this, &SceneTreeEditor::_node_visibility_changed));
+ }
}
if (p_node == selected) {
@@ -516,8 +536,9 @@ void SceneTreeEditor::_update_tree() {
void SceneTreeEditor::_compute_hash(Node *p_node, uint64_t &hash) {
hash = hash_djb2_one_64(p_node->get_instance_id(), hash);
- if (p_node->get_parent())
+ if (p_node->get_parent()) {
hash = hash_djb2_one_64(p_node->get_parent()->get_instance_id(), hash); //so a reparent still produces a different hash
+ }
for (int i = 0; i < p_node->get_child_count(); i++) {
_compute_hash(p_node->get_child(i), hash);
@@ -527,30 +548,37 @@ void SceneTreeEditor::_compute_hash(Node *p_node, uint64_t &hash) {
void SceneTreeEditor::_test_update_tree() {
pending_test_update = false;
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
- if (tree_dirty)
+ if (tree_dirty) {
return; // don't even bother
+ }
uint64_t hash = hash_djb2_one_64(0);
- if (get_scene_node())
+ if (get_scene_node()) {
_compute_hash(get_scene_node(), hash);
+ }
//test hash
- if (hash == last_hash)
+ if (hash == last_hash) {
return; // did not change
+ }
MessageQueue::get_singleton()->push_call(this, "_update_tree");
tree_dirty = true;
}
void SceneTreeEditor::_tree_changed() {
- if (EditorNode::get_singleton()->is_exiting())
+ if (EditorNode::get_singleton()->is_exiting()) {
return; //speed up exit
- if (pending_test_update)
+ }
+ if (pending_test_update) {
return;
- if (tree_dirty)
+ }
+ if (tree_dirty) {
return;
+ }
MessageQueue::get_singleton()->push_call(this, "_test_update_tree");
pending_test_update = true;
@@ -563,8 +591,9 @@ void SceneTreeEditor::_selected_changed() {
Node *n = get_node(np);
- if (n == selected)
+ if (n == selected) {
return;
+ }
selected = get_node(np);
@@ -589,11 +618,13 @@ void SceneTreeEditor::_cell_multi_selected(Object *p_object, int p_cell, bool p_
Node *n = get_node(np);
- if (!n)
+ if (!n) {
return;
+ }
- if (!editor_selection)
+ if (!editor_selection) {
return;
+ }
if (p_selected) {
editor_selection->add_node(n);
@@ -630,18 +661,21 @@ void SceneTreeEditor::_notification(int p_what) {
}
TreeItem *SceneTreeEditor::_find(TreeItem *p_node, const NodePath &p_path) {
- if (!p_node)
+ if (!p_node) {
return nullptr;
+ }
NodePath np = p_node->get_metadata(0);
- if (np == p_path)
+ if (np == p_path) {
return p_node;
+ }
TreeItem *children = p_node->get_children();
while (children) {
TreeItem *n = _find(children, p_path);
- if (n)
+ if (n) {
return n;
+ }
children = children->get_next();
}
@@ -651,13 +685,16 @@ TreeItem *SceneTreeEditor::_find(TreeItem *p_node, const NodePath &p_path) {
void SceneTreeEditor::set_selected(Node *p_node, bool p_emit_selected) {
ERR_FAIL_COND(blocked > 0);
- if (pending_test_update)
+ if (pending_test_update) {
_test_update_tree();
- if (tree_dirty)
+ }
+ if (tree_dirty) {
_update_tree();
+ }
- if (selected == p_node)
+ if (selected == p_node) {
return;
+ }
TreeItem *item = p_node ? _find(tree->get_root(), p_node->get_path()) : nullptr;
@@ -674,8 +711,9 @@ void SceneTreeEditor::set_selected(Node *p_node, bool p_emit_selected) {
tree->ensure_cursor_is_visible();
} else {
- if (!p_node)
+ if (!p_node) {
selected = nullptr;
+ }
_update_tree();
selected = p_node;
}
@@ -726,8 +764,9 @@ void SceneTreeEditor::_renamed() {
which->set_text(0, new_name);
}
- if (new_name == n->get_name())
+ if (new_name == n->get_name()) {
return;
+ }
if (!undo_redo) {
n->set_name(new_name);
@@ -747,8 +786,9 @@ Node *SceneTreeEditor::get_selected() {
}
void SceneTreeEditor::set_marked(const Set<Node *> &p_marked, bool p_selectable, bool p_children_selectable) {
- if (tree_dirty)
+ if (tree_dirty) {
_update_tree();
+ }
marked = p_marked;
marked_selectable = p_selectable;
marked_children_selectable = p_children_selectable;
@@ -757,8 +797,9 @@ void SceneTreeEditor::set_marked(const Set<Node *> &p_marked, bool p_selectable,
void SceneTreeEditor::set_marked(Node *p_marked, bool p_selectable, bool p_children_selectable) {
Set<Node *> s;
- if (p_marked)
+ if (p_marked) {
s.insert(p_marked);
+ }
set_marked(s, p_selectable, p_children_selectable);
}
@@ -796,18 +837,21 @@ void SceneTreeEditor::_update_selection(TreeItem *item) {
NodePath np = item->get_metadata(0);
- if (!has_node(np))
+ if (!has_node(np)) {
return;
+ }
Node *n = get_node(np);
- if (!n)
+ if (!n) {
return;
+ }
- if (editor_selection->is_selected(n))
+ if (editor_selection->is_selected(n)) {
item->select(0);
- else
+ } else {
item->deselect(0);
+ }
TreeItem *c = item->get_children();
@@ -818,25 +862,30 @@ void SceneTreeEditor::_update_selection(TreeItem *item) {
}
void SceneTreeEditor::_selection_changed() {
- if (!editor_selection)
+ if (!editor_selection) {
return;
+ }
TreeItem *root = tree->get_root();
- if (!root)
+ if (!root) {
return;
+ }
_update_selection(root);
}
void SceneTreeEditor::_cell_collapsed(Object *p_obj) {
- if (updating_tree)
+ if (updating_tree) {
return;
- if (!can_rename)
+ }
+ if (!can_rename) {
return;
+ }
TreeItem *ti = Object::cast_to<TreeItem>(p_obj);
- if (!ti)
+ if (!ti) {
return;
+ }
bool collapsed = ti->is_collapsed();
@@ -849,8 +898,9 @@ void SceneTreeEditor::_cell_collapsed(Object *p_obj) {
}
Variant SceneTreeEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
- if (!can_rename)
+ if (!can_rename) {
return Variant(); //not editable tree
+ }
Vector<Node *> selected;
Vector<Ref<Texture2D>> icons;
@@ -869,8 +919,9 @@ Variant SceneTreeEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from
next = tree->get_next_selected(next);
}
- if (selected.empty())
+ if (selected.empty()) {
return Variant();
+ }
VBoxContainer *vb = memnew(VBoxContainer);
Array objs;
@@ -910,28 +961,34 @@ bool SceneTreeEditor::_is_script_type(const StringName &p_type) const {
}
bool SceneTreeEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
- if (!can_rename)
+ if (!can_rename) {
return false; //not editable tree
- if (filter != String())
+ }
+ if (filter != String()) {
return false; //can't rearrange tree with filter turned on
+ }
Dictionary d = p_data;
- if (!d.has("type"))
+ if (!d.has("type")) {
return false;
+ }
TreeItem *item = tree->get_item_at_position(p_point);
- if (!item)
+ if (!item) {
return false;
+ }
int section = tree->get_drop_section_at_position(p_point);
- if (section < -1 || (section == -1 && !item->get_parent()))
+ if (section < -1 || (section == -1 && !item->get_parent())) {
return false;
+ }
if (String(d["type"]) == "files") {
Vector<String> files = d["files"];
- if (files.size() == 0)
+ if (files.size() == 0) {
return false; //weird
+ }
if (_is_script_type(EditorFileSystem::get_singleton()->get_file_type(files[0]))) {
tree->set_drop_mode_flags(Tree::DROP_MODE_ON_ITEM);
@@ -941,8 +998,9 @@ bool SceneTreeEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_d
for (int i = 0; i < files.size(); i++) {
String file = files[i];
String ftype = EditorFileSystem::get_singleton()->get_file_type(file);
- if (ftype != "PackedScene")
+ if (ftype != "PackedScene") {
return false;
+ }
}
tree->set_drop_mode_flags(Tree::DROP_MODE_INBETWEEN | Tree::DROP_MODE_ON_ITEM); //so it works..
@@ -965,20 +1023,24 @@ bool SceneTreeEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_d
}
void SceneTreeEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
- if (!can_drop_data_fw(p_point, p_data, p_from))
+ if (!can_drop_data_fw(p_point, p_data, p_from)) {
return;
+ }
TreeItem *item = tree->get_item_at_position(p_point);
- if (!item)
+ if (!item) {
return;
+ }
int section = tree->get_drop_section_at_position(p_point);
- if (section < -1)
+ if (section < -1) {
return;
+ }
NodePath np = item->get_metadata(0);
Node *n = get_node(np);
- if (!n)
+ if (!n) {
return;
+ }
Dictionary d = p_data;
@@ -1131,8 +1193,9 @@ SceneTreeEditor::~SceneTreeEditor() {
void SceneTreeDialog::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_VISIBILITY_CHANGED: {
- if (is_visible())
+ if (is_visible()) {
tree->update_tree();
+ }
} break;
case NOTIFICATION_ENTER_TREE: {
connect("confirmed", callable_mp(this, &SceneTreeDialog::_select));
diff --git a/editor/script_create_dialog.cpp b/editor/script_create_dialog.cpp
index d0346a6c3e..04fbfdff9d 100644
--- a/editor/script_create_dialog.cpp
+++ b/editor/script_create_dialog.cpp
@@ -127,32 +127,37 @@ void ScriptCreateDialog::set_inheritance_base_type(const String &p_base) {
}
bool ScriptCreateDialog::_validate_parent(const String &p_string) {
- if (p_string.length() == 0)
+ if (p_string.length() == 0) {
return false;
+ }
if (can_inherit_from_file && p_string.is_quoted()) {
String p = p_string.substr(1, p_string.length() - 2);
- if (_validate_path(p, true) == "")
+ if (_validate_path(p, true) == "") {
return true;
+ }
}
return ClassDB::class_exists(p_string) || ScriptServer::is_global_class(p_string);
}
bool ScriptCreateDialog::_validate_class(const String &p_string) {
- if (p_string.length() == 0)
+ if (p_string.length() == 0) {
return false;
+ }
for (int i = 0; i < p_string.length(); i++) {
if (i == 0) {
- if (p_string[0] >= '0' && p_string[0] <= '9')
+ if (p_string[0] >= '0' && p_string[0] <= '9') {
return false; // no start with number plz
+ }
}
bool valid_char = (p_string[i] >= '0' && p_string[i] <= '9') || (p_string[i] >= 'a' && p_string[i] <= 'z') || (p_string[i] >= 'A' && p_string[i] <= 'Z') || p_string[i] == '_' || p_string[i] == '.';
- if (!valid_char)
+ if (!valid_char) {
return false;
+ }
}
return true;
@@ -161,14 +166,17 @@ bool ScriptCreateDialog::_validate_class(const String &p_string) {
String ScriptCreateDialog::_validate_path(const String &p_path, bool p_file_must_exist) {
String p = p_path.strip_edges();
- if (p == "")
+ if (p == "") {
return TTR("Path is empty.");
- if (p.get_file().get_basename() == "")
+ }
+ if (p.get_file().get_basename() == "") {
return TTR("Filename is empty.");
+ }
p = ProjectSettings::get_singleton()->localize_path(p);
- if (!p.begins_with("res://"))
+ if (!p.begins_with("res://")) {
return TTR("Path is not local.");
+ }
DirAccess *d = DirAccess::create(DirAccess::ACCESS_RESOURCES);
if (d->change_dir(p.get_base_dir()) != OK) {
@@ -213,15 +221,18 @@ String ScriptCreateDialog::_validate_path(const String &p_path, bool p_file_must
index++;
}
- if (!found)
+ if (!found) {
return TTR("Invalid extension.");
- if (!match)
+ }
+ if (!match) {
return TTR("Wrong extension chosen.");
+ }
/* Let ScriptLanguage do custom validation */
String path_error = ScriptServer::get_language(language_menu->get_selected())->validate_path(p);
- if (path_error != "")
+ if (path_error != "") {
return path_error;
+ }
/* All checks passed */
return "";
@@ -300,8 +311,9 @@ void ScriptCreateDialog::_create_new() {
if (has_named_classes) {
String cname = class_name->get_text();
- if (cname.length())
+ if (cname.length()) {
scr->set_name(cname);
+ }
}
if (!is_built_in) {
@@ -338,8 +350,9 @@ void ScriptCreateDialog::_lang_changed(int l) {
has_named_classes = language->has_named_classes();
can_inherit_from_file = language->can_inherit_from_file();
supports_built_in = language->supports_builtin_mode();
- if (!supports_built_in)
+ if (!supports_built_in) {
is_built_in = false;
+ }
String selected_ext = "." + language->get_extension();
String path = file_path->get_text();
diff --git a/editor/settings_config_dialog.cpp b/editor/settings_config_dialog.cpp
index b86db7d073..c461bf0410 100644
--- a/editor/settings_config_dialog.cpp
+++ b/editor/settings_config_dialog.cpp
@@ -41,8 +41,9 @@
#include "scene/gui/margin_container.h"
void EditorSettingsDialog::ok_pressed() {
- if (!EditorSettings::get_singleton())
+ if (!EditorSettings::get_singleton()) {
return;
+ }
_settings_save();
timer->stop();
@@ -68,15 +69,17 @@ void EditorSettingsDialog::_settings_save() {
}
void EditorSettingsDialog::cancel_pressed() {
- if (!EditorSettings::get_singleton())
+ if (!EditorSettings::get_singleton()) {
return;
+ }
EditorSettings::get_singleton()->notify_changes();
}
void EditorSettingsDialog::popup_edit_settings() {
- if (!EditorSettings::get_singleton())
+ if (!EditorSettings::get_singleton()) {
return;
+ }
EditorSettings::get_singleton()->list_text_editor_themes(); // make sure we have an up to date list of themes
@@ -142,8 +145,9 @@ void EditorSettingsDialog::_unhandled_input(const Ref<InputEvent> &p_event) {
if (ED_IS_SHORTCUT("editor/undo", p_event)) {
String action = undo_redo->get_current_action_name();
- if (action != "")
+ if (action != "") {
EditorNode::get_log()->add_message("Undo: " + action, EditorLog::MSG_TYPE_EDITOR);
+ }
undo_redo->undo();
handled = true;
}
@@ -151,8 +155,9 @@ void EditorSettingsDialog::_unhandled_input(const Ref<InputEvent> &p_event) {
if (ED_IS_SHORTCUT("editor/redo", p_event)) {
undo_redo->redo();
String action = undo_redo->get_current_action_name();
- if (action != "")
+ if (action != "") {
EditorNode::get_log()->add_message("Redo: " + action, EditorLog::MSG_TYPE_EDITOR);
+ }
handled = true;
}
@@ -198,8 +203,9 @@ void EditorSettingsDialog::_update_shortcuts() {
for (List<String>::Element *E = slist.front(); E; E = E->next()) {
Ref<ShortCut> sc = EditorSettings::get_singleton()->get_shortcut(E->get());
- if (!sc->has_meta("original"))
+ if (!sc->has_meta("original")) {
continue;
+ }
Ref<InputEvent> original = sc->get_meta("original");
@@ -274,8 +280,9 @@ void EditorSettingsDialog::_shortcut_button_pressed(Object *p_item, int p_column
shortcut_configured = item;
} else if (p_idx == 1) { //erase
- if (!sc.is_valid())
+ if (!sc.is_valid()) {
return; //pointless, there is nothing
+ }
undo_redo->create_action(TTR("Erase Shortcut"));
undo_redo->add_do_method(sc.ptr(), "set_shortcut", Ref<InputEvent>());
@@ -286,8 +293,9 @@ void EditorSettingsDialog::_shortcut_button_pressed(Object *p_item, int p_column
undo_redo->add_undo_method(this, "_settings_changed");
undo_redo->commit_action();
} else if (p_idx == 2) { //revert to original
- if (!sc.is_valid())
+ if (!sc.is_valid()) {
return; //pointless, there is nothing
+ }
Ref<InputEvent> original = sc->get_meta("original");
@@ -315,8 +323,9 @@ void EditorSettingsDialog::_wait_for_key(const Ref<InputEvent> &p_event) {
}
void EditorSettingsDialog::_press_a_key_confirm() {
- if (last_wait_for_key.is_null())
+ if (last_wait_for_key.is_null()) {
return;
+ }
Ref<InputEventKey> ie;
ie.instance();
@@ -345,10 +354,11 @@ void EditorSettingsDialog::_tabs_tab_changed(int p_tab) {
void EditorSettingsDialog::_focus_current_search_box() {
Control *tab = tabs->get_current_tab_control();
LineEdit *current_search_box = nullptr;
- if (tab == tab_general)
+ if (tab == tab_general) {
current_search_box = search_box;
- else if (tab == tab_shortcuts)
+ } else if (tab == tab_shortcuts) {
current_search_box = shortcut_search_box;
+ }
if (current_search_box) {
current_search_box->grab_focus();
diff --git a/main/main.cpp b/main/main.cpp
index ef632e197c..f35e73cdc2 100644
--- a/main/main.cpp
+++ b/main/main.cpp
@@ -177,8 +177,9 @@ static String unescape_cmdline(const String &p_str) {
static String get_full_version_string() {
String hash = String(VERSION_HASH);
- if (hash.length() != 0)
+ if (hash.length() != 0) {
hash = "." + hash.left(9);
+ }
return String(VERSION_FULL_BUILD) + hash;
}
@@ -458,8 +459,9 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
bool use_vsync = false;
packed_data = PackedData::get_singleton();
- if (!packed_data)
+ if (!packed_data) {
packed_data = memnew(PackedData);
+ }
#ifdef MINIZIP_ENABLED
@@ -696,12 +698,13 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
} else if (I->get() == "--render-thread") { // render thread mode
if (I->next()) {
- if (I->next()->get() == "safe")
+ if (I->next()->get() == "safe") {
rtm = OS::RENDER_THREAD_SAFE;
- else if (I->next()->get() == "unsafe")
+ } else if (I->next()->get() == "unsafe") {
rtm = OS::RENDER_THREAD_UNSAFE;
- else if (I->next()->get() == "separate")
+ } else if (I->next()->get() == "separate") {
rtm = OS::RENDER_SEPARATE_THREAD;
+ }
N = I->next()->next();
} else {
@@ -754,9 +757,9 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
String path;
String file = I->get();
int sep = MAX(file.find_last("/"), file.find_last("\\"));
- if (sep == -1)
+ if (sep == -1) {
path = ".";
- else {
+ } else {
path = file.substr(0, sep);
}
if (OS::get_singleton()->set_cwd(path) == OK) {
@@ -976,8 +979,9 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
_print_error_enabled = false;
};
- if (quiet_stdout)
+ if (quiet_stdout) {
_print_line_enabled = false;
+ }
OS::get_singleton()->set_cmdline(execpath, main_args);
@@ -1116,20 +1120,21 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
{
String orientation = GLOBAL_DEF("display/window/handheld/orientation", "landscape");
- if (orientation == "portrait")
+ if (orientation == "portrait") {
window_orientation = DisplayServer::SCREEN_PORTRAIT;
- else if (orientation == "reverse_landscape")
+ } else if (orientation == "reverse_landscape") {
window_orientation = DisplayServer::SCREEN_REVERSE_LANDSCAPE;
- else if (orientation == "reverse_portrait")
+ } else if (orientation == "reverse_portrait") {
window_orientation = DisplayServer::SCREEN_REVERSE_PORTRAIT;
- else if (orientation == "sensor_landscape")
+ } else if (orientation == "sensor_landscape") {
window_orientation = DisplayServer::SCREEN_SENSOR_LANDSCAPE;
- else if (orientation == "sensor_portrait")
+ } else if (orientation == "sensor_portrait") {
window_orientation = DisplayServer::SCREEN_SENSOR_PORTRAIT;
- else if (orientation == "sensor")
+ } else if (orientation == "sensor") {
window_orientation = DisplayServer::SCREEN_SENSOR;
- else
+ } else {
window_orientation = DisplayServer::SCREEN_LANDSCAPE;
+ }
}
Engine::get_singleton()->set_iterations_per_second(GLOBAL_DEF("physics/common/physics_fps", 60));
@@ -1160,8 +1165,9 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
message_queue = memnew(MessageQueue);
- if (p_second_phase)
+ if (p_second_phase) {
return setup2();
+ }
return OK;
@@ -1174,33 +1180,42 @@ error:
args.clear();
main_args.clear();
- if (show_help)
+ if (show_help) {
print_help(execpath);
+ }
EngineDebugger::deinitialize();
- if (performance)
+ if (performance) {
memdelete(performance);
- if (input_map)
+ }
+ if (input_map) {
memdelete(input_map);
- if (translation_server)
+ }
+ if (translation_server) {
memdelete(translation_server);
- if (globals)
+ }
+ if (globals) {
memdelete(globals);
- if (engine)
+ }
+ if (engine) {
memdelete(engine);
- if (packed_data)
+ }
+ if (packed_data) {
memdelete(packed_data);
- if (file_access_network_client)
+ }
+ if (file_access_network_client) {
memdelete(file_access_network_client);
+ }
unregister_core_driver_types();
unregister_core_types();
OS::get_singleton()->_cmdline.clear();
- if (message_queue)
+ if (message_queue) {
memdelete(message_queue);
+ }
OS::get_singleton()->finalize_core();
locale = String();
@@ -1333,8 +1348,9 @@ Error Main::setup2(Thread::ID p_main_tid_override) {
if (boot_logo_path != String()) {
boot_logo.instance();
Error load_err = ImageLoader::load_image(boot_logo_path, boot_logo);
- if (load_err)
+ if (load_err) {
ERR_PRINT("Non-existing or invalid boot splash at '" + boot_logo_path + "'. Loading default splash.");
+ }
}
Color boot_bg_color = GLOBAL_DEF("application/boot_splash/bg_color", boot_splash_bg_color);
@@ -1536,8 +1552,9 @@ bool Main::start() {
#ifdef TOOLS_ENABLED
} else if (args[i] == "--doctool") {
doc_tool = args[i + 1];
- for (int j = i + 2; j < args.size(); j++)
+ for (int j = i + 2; j < args.size(); j++) {
removal_docs.push_back(args[j]);
+ }
} else if (args[i] == "--export") {
editor = true; //needs editor
_export_preset = args[i + 1];
@@ -1653,8 +1670,9 @@ bool Main::start() {
#ifdef TOOLS_ENABLED
main_loop = test_main(test, args);
- if (!main_loop)
+ if (!main_loop) {
return false;
+ }
#endif
} else if (script != "") {
@@ -1673,8 +1691,9 @@ bool Main::start() {
Object *obj = ClassDB::instance(instance_type);
MainLoop *script_loop = Object::cast_to<MainLoop>(obj);
if (!script_loop) {
- if (obj)
+ if (obj) {
memdelete(obj);
+ }
ERR_FAIL_V_MSG(false, vformat("Can't load the script \"%s\" as it doesn't inherit from SceneTree or MainLoop.", script));
}
@@ -1688,8 +1707,9 @@ bool Main::start() {
main_loop_type = GLOBAL_DEF("application/run/main_loop_type", "");
}
- if (!main_loop && main_loop_type == "")
+ if (!main_loop && main_loop_type == "") {
main_loop_type = "SceneTree";
+ }
if (!main_loop) {
if (!ClassDB::class_exists(main_loop_type)) {
@@ -1736,8 +1756,9 @@ bool Main::start() {
//first pass, add the constants so they exist before any script is loaded
for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
String s = E->get().name;
- if (!s.begins_with("autoload/"))
+ if (!s.begins_with("autoload/")) {
continue;
+ }
String name = s.get_slicec('/', 1);
String path = ProjectSettings::get_singleton()->get(s);
bool global_var = false;
@@ -1756,8 +1777,9 @@ bool Main::start() {
List<Node *> to_add;
for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
String s = E->get().name;
- if (!s.begins_with("autoload/"))
+ if (!s.begins_with("autoload/")) {
continue;
+ }
String name = s.get_slicec('/', 1);
String path = ProjectSettings::get_singleton()->get(s);
bool global_var = false;
@@ -1831,20 +1853,22 @@ bool Main::start() {
Size2i stretch_size = Size2(GLOBAL_DEF("display/window/size/width", 0), GLOBAL_DEF("display/window/size/height", 0));
Window::ContentScaleMode cs_sm = Window::CONTENT_SCALE_MODE_DISABLED;
- if (stretch_mode == "objects")
+ if (stretch_mode == "objects") {
cs_sm = Window::CONTENT_SCALE_MODE_OBJECTS;
- else if (stretch_mode == "pixels")
+ } else if (stretch_mode == "pixels") {
cs_sm = Window::CONTENT_SCALE_MODE_PIXELS;
+ }
Window::ContentScaleAspect cs_aspect = Window::CONTENT_SCALE_ASPECT_IGNORE;
- if (stretch_aspect == "keep")
+ if (stretch_aspect == "keep") {
cs_aspect = Window::CONTENT_SCALE_ASPECT_KEEP;
- else if (stretch_aspect == "keep_width")
+ } else if (stretch_aspect == "keep_width") {
cs_aspect = Window::CONTENT_SCALE_ASPECT_KEEP_WIDTH;
- else if (stretch_aspect == "keep_height")
+ } else if (stretch_aspect == "keep_height") {
cs_aspect = Window::CONTENT_SCALE_ASPECT_KEEP_HEIGHT;
- else if (stretch_aspect == "expand")
+ } else if (stretch_aspect == "expand") {
cs_aspect = Window::CONTENT_SCALE_ASPECT_EXPAND;
+ }
sml->get_root()->set_content_scale_mode(cs_sm);
sml->get_root()->set_content_scale_aspect(cs_aspect);
@@ -1938,8 +1962,9 @@ bool Main::start() {
if (game_path != GLOBAL_GET("application/run/main_scene") || !editor_node->has_scenes_in_session()) {
Error serr = editor_node->load_scene(local_game_path);
- if (serr != OK)
+ if (serr != OK) {
ERR_PRINT("Failed to load scene");
+ }
}
DisplayServer::get_singleton()->set_context(DisplayServer::CONTEXT_EDITOR);
}
@@ -1957,8 +1982,9 @@ bool Main::start() {
if (game_path != "") {
Node *scene = nullptr;
Ref<PackedScene> scenedata = ResourceLoader::load(local_game_path);
- if (scenedata.is_valid())
+ if (scenedata.is_valid()) {
scene = scenedata->instance();
+ }
ERR_FAIL_COND_V_MSG(!scene, false, "Failed loading scene: " + local_game_path);
sml->add_current_scene(scene);
@@ -2155,8 +2181,9 @@ bool Main::iteration() {
AudioServer::get_singleton()->update();
- if (EngineDebugger::is_active())
+ if (EngineDebugger::is_active()) {
EngineDebugger::get_singleton()->iteration(frame_time, idle_process_ticks, physics_process_ticks, frame_slice);
+ }
frames++;
Engine::get_singleton()->_idle_frames++;
@@ -2182,15 +2209,17 @@ bool Main::iteration() {
iterating--;
- if (fixed_fps != -1)
+ if (fixed_fps != -1) {
return exit;
+ }
- if (OS::get_singleton()->is_in_low_processor_usage_mode() || !DisplayServer::get_singleton()->can_any_window_draw())
+ if (OS::get_singleton()->is_in_low_processor_usage_mode() || !DisplayServer::get_singleton()->can_any_window_draw()) {
OS::get_singleton()->delay_usec(OS::get_singleton()->get_low_processor_usage_mode_sleep_usec()); //apply some delay to force idle time
- else {
+ } else {
uint32_t frame_delay = Engine::get_singleton()->get_frame_delay();
- if (frame_delay)
+ if (frame_delay) {
OS::get_singleton()->delay_usec(Engine::get_singleton()->get_frame_delay() * 1000);
+ }
}
int target_fps = Engine::get_singleton()->get_target_fps();
@@ -2198,8 +2227,9 @@ bool Main::iteration() {
uint64_t time_step = 1000000L / target_fps;
target_ticks += time_step;
uint64_t current_ticks = OS::get_singleton()->get_ticks_usec();
- if (current_ticks < target_ticks)
+ if (current_ticks < target_ticks) {
OS::get_singleton()->delay_usec(target_ticks - current_ticks);
+ }
current_ticks = OS::get_singleton()->get_ticks_usec();
target_ticks = MIN(MAX(target_ticks, current_ticks - time_step), current_ticks + time_step);
}
@@ -2294,20 +2324,27 @@ void Main::cleanup() {
memdelete(input);
}
- if (packed_data)
+ if (packed_data) {
memdelete(packed_data);
- if (file_access_network_client)
+ }
+ if (file_access_network_client) {
memdelete(file_access_network_client);
- if (performance)
+ }
+ if (performance) {
memdelete(performance);
- if (input_map)
+ }
+ if (input_map) {
memdelete(input_map);
- if (translation_server)
+ }
+ if (translation_server) {
memdelete(translation_server);
- if (globals)
+ }
+ if (globals) {
memdelete(globals);
- if (engine)
+ }
+ if (engine) {
memdelete(engine);
+ }
if (OS::get_singleton()->is_restart_on_exit_set()) {
//attempt to restart with arguments
diff --git a/main/main_timer_sync.cpp b/main/main_timer_sync.cpp
index 469ef6f20a..5252ea005b 100644
--- a/main/main_timer_sync.cpp
+++ b/main/main_timer_sync.cpp
@@ -56,15 +56,17 @@ int MainTimerSync::get_average_physics_steps(float &p_min, float &p_max) {
for (int i = 1; i < CONTROL_STEPS; ++i) {
const float typical_lower = typical_physics_steps[i];
const float current_min = typical_lower / (i + 1);
- if (current_min > p_max)
+ if (current_min > p_max) {
return i; // bail out of further restrictions would void the interval
- else if (current_min > p_min)
+ } else if (current_min > p_min) {
p_min = current_min;
+ }
const float current_max = (typical_lower + 1) / (i + 1);
- if (current_max < p_min)
+ if (current_max < p_min) {
return i;
- else if (current_max < p_max)
+ } else if (current_max < p_max) {
p_max = current_max;
+ }
}
return CONTROL_STEPS;
@@ -95,10 +97,12 @@ MainFrameTime MainTimerSync::advance_core(float p_frame_slice, int p_iterations_
break;
}
- if (steps_left_to_match_typical > min_typical_steps)
+ if (steps_left_to_match_typical > min_typical_steps) {
min_typical_steps = steps_left_to_match_typical;
- if (steps_left_to_match_typical + 1 < max_typical_steps)
+ }
+ if (steps_left_to_match_typical + 1 < max_typical_steps) {
max_typical_steps = steps_left_to_match_typical + 1;
+ }
}
// try to keep it consistent with previous iterations
@@ -143,8 +147,9 @@ MainFrameTime MainTimerSync::advance_core(float p_frame_slice, int p_iterations_
// calls advance_core, keeps track of deficit it adds to animaption_step, make sure the deficit sum stays close to zero
MainFrameTime MainTimerSync::advance_checked(float p_frame_slice, int p_iterations_per_second, float p_idle_step) {
- if (fixed_fps != -1)
+ if (fixed_fps != -1) {
p_idle_step = 1.0 / fixed_fps;
+ }
// compensate for last deficit
p_idle_step += time_deficit;
diff --git a/main/performance.cpp b/main/performance.cpp
index 0894d68d3c..7e6b9fca64 100644
--- a/main/performance.cpp
+++ b/main/performance.cpp
@@ -78,8 +78,9 @@ void Performance::_bind_methods() {
float Performance::_get_node_count() const {
MainLoop *ml = OS::get_singleton()->get_main_loop();
SceneTree *sml = Object::cast_to<SceneTree>(ml);
- if (!sml)
+ if (!sml) {
return 0;
+ }
return sml->get_node_count();
}
diff --git a/main/tests/test_astar.cpp b/main/tests/test_astar.cpp
index 3cc754e230..fe335589b0 100644
--- a/main/tests/test_astar.cpp
+++ b/main/tests/test_astar.cpp
@@ -173,8 +173,9 @@ bool test_add_remove() {
for (int i = 0; i < 20000; i++) {
int u = Math::rand() % 5;
int v = Math::rand() % 4;
- if (u == v)
+ if (u == v) {
v = 4;
+ }
if (Math::rand() % 2 == 1) {
// Add a (possibly existing) directed edge and confirm connectivity
a.connect_points(u, v, false);
@@ -189,19 +190,22 @@ bool test_add_remove() {
// Random tests for point removal
for (int i = 0; i < 20000; i++) {
a.clear();
- for (int j = 0; j < 5; j++)
+ for (int j = 0; j < 5; j++) {
a.add_point(j, Vector3(0, 0, 0));
+ }
// Add or remove random edges
for (int j = 0; j < 10; j++) {
int u = Math::rand() % 5;
int v = Math::rand() % 4;
- if (u == v)
+ if (u == v) {
v = 4;
- if (Math::rand() % 2 == 1)
+ }
+ if (Math::rand() % 2 == 1) {
a.connect_points(u, v, false);
- else
+ } else {
a.disconnect_points(u, v, false);
+ }
}
// Remove point 0
@@ -241,8 +245,9 @@ bool test_solutions() {
int u, v;
u = Math::rand() % N;
v = Math::rand() % (N - 1);
- if (u == v)
+ if (u == v) {
v = N - 1;
+ }
// Pick a random operation
int op = Math::rand();
@@ -256,16 +261,18 @@ bool test_solutions() {
// Add edge (u, v); possibly bidirectional
a.connect_points(u, v, op % 2);
adj[u][v] = true;
- if (op % 2)
+ if (op % 2) {
adj[v][u] = true;
+ }
break;
case 6:
case 7:
// Remove edge (u, v); possibly bidirectional
a.disconnect_points(u, v, op % 2);
adj[u][v] = false;
- if (op % 2)
+ if (op % 2) {
adj[v][u] = false;
+ }
break;
case 8:
// Remove point u and add it back; clears adjacent edges and changes coordinates
@@ -274,42 +281,55 @@ bool test_solutions() {
p[u].y = Math::rand() % 100;
p[u].z = Math::rand() % 100;
a.add_point(u, p[u]);
- for (v = 0; v < N; v++)
+ for (v = 0; v < N; v++) {
adj[u][v] = adj[v][u] = false;
+ }
break;
}
}
// Floyd-Warshall
float d[N][N];
- for (int u = 0; u < N; u++)
- for (int v = 0; v < N; v++)
+ for (int u = 0; u < N; u++) {
+ for (int v = 0; v < N; v++) {
d[u][v] = (u == v || adj[u][v]) ? p[u].distance_to(p[v]) : INFINITY;
+ }
+ }
- for (int w = 0; w < N; w++)
- for (int u = 0; u < N; u++)
- for (int v = 0; v < N; v++)
- if (d[u][v] > d[u][w] + d[w][v])
+ for (int w = 0; w < N; w++) {
+ for (int u = 0; u < N; u++) {
+ for (int v = 0; v < N; v++) {
+ if (d[u][v] > d[u][w] + d[w][v]) {
d[u][v] = d[u][w] + d[w][v];
+ }
+ }
+ }
+ }
// Display statistics
int count = 0;
- for (int u = 0; u < N; u++)
- for (int v = 0; v < N; v++)
- if (adj[u][v])
+ for (int u = 0; u < N; u++) {
+ for (int v = 0; v < N; v++) {
+ if (adj[u][v]) {
count++;
+ }
+ }
+ }
printf("Test #%4d: %3d edges, ", test + 1, count);
count = 0;
- for (int u = 0; u < N; u++)
- for (int v = 0; v < N; v++)
- if (!Math::is_inf(d[u][v]))
+ for (int u = 0; u < N; u++) {
+ for (int v = 0; v < N; v++) {
+ if (!Math::is_inf(d[u][v])) {
count++;
+ }
+ }
+ }
printf("%3d/%d pairs of reachable points\n", count - N, N * (N - 1));
// Check A*'s output
bool match = true;
- for (int u = 0; u < N; u++)
- for (int v = 0; v < N; v++)
+ for (int u = 0; u < N; u++) {
+ for (int v = 0; v < N; v++) {
if (u != v) {
Vector<int> route = a.get_id_path(u, v);
if (!Math::is_inf(d[u][v])) {
@@ -344,10 +364,13 @@ bool test_solutions() {
}
}
}
+ }
+ }
exit:
- if (!match)
+ if (!match) {
return false;
+ }
}
return true;
}
@@ -367,11 +390,13 @@ MainLoop *test() {
int passed = 0;
while (true) {
- if (!test_funcs[count])
+ if (!test_funcs[count]) {
break;
+ }
bool pass = test_funcs[count]();
- if (pass)
+ if (pass) {
passed++;
+ }
OS::get_singleton()->print("\t%s\n", pass ? "PASS" : "FAILED");
count++;
diff --git a/main/tests/test_gdscript.cpp b/main/tests/test_gdscript.cpp
index ea6fcee1c0..10586c6495 100644
--- a/main/tests/test_gdscript.cpp
+++ b/main/tests/test_gdscript.cpp
@@ -57,13 +57,15 @@ static String _parser_extends(const GDScriptParser::ClassNode *p_class) {
String txt = "extends ";
if (String(p_class->extends_file) != "") {
txt += "\"" + p_class->extends_file + "\"";
- if (p_class->extends_class.size())
+ if (p_class->extends_class.size()) {
txt += ".";
+ }
}
for (int i = 0; i < p_class->extends_class.size(); i++) {
- if (i != 0)
+ if (i != 0) {
txt += ".";
+ }
txt += p_class->extends_class[i];
}
@@ -80,10 +82,11 @@ static String _parser_expr(const GDScriptParser::Node *p_expr) {
} break;
case GDScriptParser::Node::TYPE_CONSTANT: {
const GDScriptParser::ConstantNode *c_node = static_cast<const GDScriptParser::ConstantNode *>(p_expr);
- if (c_node->value.get_type() == Variant::STRING)
+ if (c_node->value.get_type() == Variant::STRING) {
txt = "\"" + String(c_node->value) + "\"";
- else
+ } else {
txt = c_node->value;
+ }
} break;
case GDScriptParser::Node::TYPE_SELF: {
@@ -93,8 +96,9 @@ static String _parser_expr(const GDScriptParser::Node *p_expr) {
const GDScriptParser::ArrayNode *arr_node = static_cast<const GDScriptParser::ArrayNode *>(p_expr);
txt += "[";
for (int i = 0; i < arr_node->elements.size(); i++) {
- if (i > 0)
+ if (i > 0) {
txt += ", ";
+ }
txt += _parser_expr(arr_node->elements[i]);
}
txt += "]";
@@ -103,8 +107,9 @@ static String _parser_expr(const GDScriptParser::Node *p_expr) {
const GDScriptParser::DictionaryNode *dict_node = static_cast<const GDScriptParser::DictionaryNode *>(p_expr);
txt += "{";
for (int i = 0; i < dict_node->elements.size(); i++) {
- if (i > 0)
+ if (i > 0) {
txt += ", ";
+ }
const GDScriptParser::DictionaryNode::Pair &p = dict_node->elements[i];
txt += _parser_expr(p.key);
@@ -137,8 +142,9 @@ static String _parser_expr(const GDScriptParser::Node *p_expr) {
nfunc = c_node->arguments[1];
ERR_FAIL_COND_V(nfunc->type != GDScriptParser::Node::TYPE_IDENTIFIER, "");
- if (c_node->arguments[0]->type != GDScriptParser::Node::TYPE_SELF)
+ if (c_node->arguments[0]->type != GDScriptParser::Node::TYPE_SELF) {
func_name = _parser_expr(c_node->arguments[0]) + ".";
+ }
func_name += _parser_expr(nfunc);
arg_ofs = 2;
@@ -148,8 +154,9 @@ static String _parser_expr(const GDScriptParser::Node *p_expr) {
for (int i = arg_ofs; i < c_node->arguments.size(); i++) {
const GDScriptParser::Node *arg = c_node->arguments[i];
- if (i > arg_ofs)
+ if (i > arg_ofs) {
txt += ", ";
+ }
txt += _parser_expr(arg);
}
@@ -346,10 +353,11 @@ static void _parser_show_block(const GDScriptParser::BlockNode *p_block, int p_i
_print_indent(p_indent, "break");
} break;
case GDScriptParser::ControlFlowNode::CF_RETURN: {
- if (cf_node->arguments.size())
+ if (cf_node->arguments.size()) {
_print_indent(p_indent, "return " + _parser_expr(cf_node->arguments[0]));
- else
+ } else {
_print_indent(p_indent, "return ");
+ }
} break;
}
@@ -368,18 +376,21 @@ static void _parser_show_block(const GDScriptParser::BlockNode *p_block, int p_i
static void _parser_show_function(const GDScriptParser::FunctionNode *p_func, int p_indent, GDScriptParser::BlockNode *p_initializer = nullptr) {
String txt;
- if (p_func->_static)
+ if (p_func->_static) {
txt = "static ";
+ }
txt += "func ";
- if (p_func->name == "") // initializer
+ if (p_func->name == "") { // initializer
txt += "[built-in-initializer]";
- else
+ } else {
txt += String(p_func->name);
+ }
txt += "(";
for (int i = 0; i < p_func->arguments.size(); i++) {
- if (i != 0)
+ if (i != 0) {
txt += ", ";
+ }
txt += "var " + String(p_func->arguments[i]);
if (i >= (p_func->arguments.size() - p_func->default_values.size())) {
int defarg = i - (p_func->arguments.size() - p_func->default_values.size());
@@ -395,8 +406,9 @@ static void _parser_show_function(const GDScriptParser::FunctionNode *p_func, in
txt += ":";
_print_indent(p_indent, txt);
- if (p_initializer)
+ if (p_initializer) {
_parser_show_block(p_initializer, p_indent + 1);
+ }
_parser_show_block(p_func->body, p_indent + 1);
}
@@ -409,8 +421,9 @@ static void _parser_show_class(const GDScriptParser::ClassNode *p_class, int p_i
for (int i = 0; i < p_class->subclasses.size(); i++) {
const GDScriptParser::ClassNode *subclass = p_class->subclasses[i];
String line = "class " + subclass->name;
- if (String(subclass->extends_file) != "" || subclass->extends_class.size())
+ if (String(subclass->extends_file) != "" || subclass->extends_class.size()) {
line += " " + _parser_extends(subclass);
+ }
line += ":";
_print_indent(p_indent, line);
_parser_show_class(subclass, p_indent + 1, p_code);
@@ -438,8 +451,9 @@ static void _parser_show_class(const GDScriptParser::ClassNode *p_class, int p_i
for (int i = 0; i < p_class->functions.size(); i++) {
if (String(p_class->functions[i]->name) == "_init") {
_parser_show_function(p_class->functions[i], p_indent, p_class->initializer);
- } else
+ } else {
_parser_show_function(p_class->functions[i], p_indent);
+ }
print_line("\n");
}
//_parser_show_function(p_class->initializer,p_indent);
@@ -465,10 +479,11 @@ static String _disassemble_addr(const Ref<GDScript> &p_script, const GDScriptFun
case GDScriptFunction::ADDR_TYPE_LOCAL_CONSTANT: {
Variant v = func.get_constant(addr);
String txt;
- if (v.get_type() == Variant::STRING || v.get_type() == Variant::NODE_PATH)
+ if (v.get_type() == Variant::STRING || v.get_type() == Variant::NODE_PATH) {
txt = "\"" + String(v) + "\"";
- else
+ } else {
txt = v;
+ }
return "const(" + txt + ")";
} break;
case GDScriptFunction::ADDR_TYPE_STACK: {
@@ -499,8 +514,9 @@ static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String
if (func.get_default_argument_count()) {
defargs = "defarg at: ";
for (int i = 0; i < func.get_default_argument_count(); i++) {
- if (i > 0)
+ if (i > 0) {
defargs += ",";
+ }
defargs += itos(func.get_default_argument_addr(i));
}
defargs += " ";
@@ -654,8 +670,9 @@ static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String
txt += Variant::get_type_name(t) + "(";
for (int i = 0; i < argc; i++) {
- if (i > 0)
+ if (i > 0) {
txt += ", ";
+ }
txt += DADDR(i + 3);
}
txt += ")";
@@ -670,8 +687,9 @@ static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String
txt += " = [ ";
for (int i = 0; i < argc; i++) {
- if (i > 0)
+ if (i > 0) {
txt += ", ";
+ }
txt += DADDR(2 + i);
}
@@ -687,8 +705,9 @@ static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String
txt += " = { ";
for (int i = 0; i < argc; i++) {
- if (i > 0)
+ if (i > 0) {
txt += ", ";
+ }
txt += DADDR(2 + i * 2 + 0);
txt += ":";
txt += DADDR(2 + i * 2 + 1);
@@ -704,10 +723,11 @@ static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String
case GDScriptFunction::OPCODE_CALL_RETURN: {
bool ret = code[ip] == GDScriptFunction::OPCODE_CALL_RETURN;
- if (ret)
+ if (ret) {
txt += " call-ret ";
- else
+ } else {
txt += " call ";
+ }
int argc = code[ip + 1];
if (ret) {
@@ -719,8 +739,9 @@ static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String
txt += "(";
for (int i = 0; i < argc; i++) {
- if (i > 0)
+ if (i > 0) {
txt += ", ";
+ }
txt += DADDR(4 + i);
}
txt += ")";
@@ -738,8 +759,9 @@ static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String
txt += "(";
for (int i = 0; i < argc; i++) {
- if (i > 0)
+ if (i > 0) {
txt += ", ";
+ }
txt += DADDR(3 + i);
}
txt += ")";
@@ -757,8 +779,9 @@ static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String
txt += "(";
for (int i = 0; i < argc; i++) {
- if (i > 0)
+ if (i > 0) {
txt += ", ";
+ }
txt += DADDR(3 + i);
}
txt += ")";
@@ -829,10 +852,11 @@ static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String
} break;
case GDScriptFunction::OPCODE_LINE: {
int line = code[ip + 1] - 1;
- if (line >= 0 && line < p_code.size())
+ if (line >= 0 && line < p_code.size()) {
txt = "\n" + itos(line + 1) + ": " + p_code[line] + "\n";
- else
+ } else {
txt = "";
+ }
incr += 2;
} break;
case GDScriptFunction::OPCODE_END: {
@@ -852,8 +876,9 @@ static void _disassemble_class(const Ref<GDScript> &p_class, const Vector<String
}
ip += incr;
- if (txt != "")
+ if (txt != "") {
print_line(txt);
+ }
}
}
}
@@ -899,24 +924,26 @@ MainLoop *test(TestType p_type) {
int line = -1;
while (tk.get_token() != GDScriptTokenizer::TK_EOF) {
String text;
- if (tk.get_token() == GDScriptTokenizer::TK_IDENTIFIER)
+ if (tk.get_token() == GDScriptTokenizer::TK_IDENTIFIER) {
text = "'" + tk.get_token_identifier() + "' (identifier)";
- else if (tk.get_token() == GDScriptTokenizer::TK_CONSTANT) {
+ } else if (tk.get_token() == GDScriptTokenizer::TK_CONSTANT) {
const Variant &c = tk.get_token_constant();
- if (c.get_type() == Variant::STRING)
+ if (c.get_type() == Variant::STRING) {
text = "\"" + String(c) + "\"";
- else
+ } else {
text = c;
+ }
text = text + " (" + Variant::get_type_name(c.get_type()) + " constant)";
- } else if (tk.get_token() == GDScriptTokenizer::TK_ERROR)
+ } else if (tk.get_token() == GDScriptTokenizer::TK_ERROR) {
text = "ERROR: " + tk.get_token_error();
- else if (tk.get_token() == GDScriptTokenizer::TK_NEWLINE)
+ } else if (tk.get_token() == GDScriptTokenizer::TK_NEWLINE) {
text = "newline (" + itos(tk.get_token_line()) + ") + indent: " + itos(tk.get_token_line_indent());
- else if (tk.get_token() == GDScriptTokenizer::TK_BUILT_IN_FUNC)
+ } else if (tk.get_token() == GDScriptTokenizer::TK_BUILT_IN_FUNC) {
text = "'" + String(GDScriptFunctions::get_func_name(tk.get_token_built_in_func())) + "' (built-in function)";
- else
+ } else {
text = tk.get_token_name(tk.get_token());
+ }
if (tk.get_token_line() != line) {
int from = line + 1;
diff --git a/main/tests/test_math.cpp b/main/tests/test_math.cpp
index 14ae81ad26..11aa164709 100644
--- a/main/tests/test_math.cpp
+++ b/main/tests/test_math.cpp
@@ -213,8 +213,9 @@ class GetClassAndNamespace {
tk_string += res;
} else {
- if (code[idx] == '\n')
+ if (code[idx] == '\n') {
line++;
+ }
tk_string += code[idx];
}
idx++;
@@ -338,8 +339,9 @@ public:
tk = get_token();
}
- if (error)
+ if (error) {
return ERR_PARSE_ERROR;
+ }
return OK;
}
@@ -571,8 +573,9 @@ MainLoop *test() {
break;
}
}
- if (success)
+ if (success) {
break;
+ }
}
print_line("DONE");
diff --git a/main/tests/test_oa_hash_map.cpp b/main/tests/test_oa_hash_map.cpp
index 27792c48e6..cae143bb5d 100644
--- a/main/tests/test_oa_hash_map.cpp
+++ b/main/tests/test_oa_hash_map.cpp
@@ -70,8 +70,9 @@ MainLoop *test() {
uint32_t num_elems = 0;
for (int i = 0; i < 500; i++) {
int tmp;
- if (map.lookup(i, tmp) && tmp == i * 2)
+ if (map.lookup(i, tmp) && tmp == i * 2) {
num_elems++;
+ }
}
OS::get_singleton()->print("elements %d == %d.\n", map.get_num_elements(), num_elems);
@@ -104,8 +105,9 @@ MainLoop *test() {
keys[i] = Math::rand();
map.set(keys[i], dummy);
- if (!map.lookup(keys[i], dummy))
+ if (!map.lookup(keys[i], dummy)) {
OS::get_singleton()->print("could not find 0x%X despite it was just inserted!\n", unsigned(keys[i]));
+ }
}
// check whether the keys are still present
diff --git a/main/tests/test_ordered_hash_map.cpp b/main/tests/test_ordered_hash_map.cpp
index aba222fbba..d18a3784be 100644
--- a/main/tests/test_ordered_hash_map.cpp
+++ b/main/tests/test_ordered_hash_map.cpp
@@ -150,11 +150,13 @@ MainLoop *test() {
int passed = 0;
while (true) {
- if (!test_funcs[count])
+ if (!test_funcs[count]) {
break;
+ }
bool pass = test_funcs[count]();
- if (pass)
+ if (pass) {
passed++;
+ }
OS::get_singleton()->print("\t%s\n", pass ? "PASS" : "FAILED");
count++;
diff --git a/main/tests/test_physics_2d.cpp b/main/tests/test_physics_2d.cpp
index 9b37033354..6cb9bf7b60 100644
--- a/main/tests/test_physics_2d.cpp
+++ b/main/tests/test_physics_2d.cpp
@@ -304,8 +304,9 @@ protected:
vs->canvas_item_clear(ray);
vs->canvas_item_add_line(ray, ray_from, ray_end, p_rid.is_valid() ? Color(0, 1, 0.4) : Color(1, 0.4, 0), 2);
- if (p_rid.is_valid())
+ if (p_rid.is_valid()) {
vs->canvas_item_add_line(ray, ray_end, ray_end + p_normal * 20, p_rid.is_valid() ? Color(0, 1, 0.4) : Color(1, 0.4, 0), 2);
+ }
}
static void _bind_methods() {
diff --git a/main/tests/test_render.cpp b/main/tests/test_render.cpp
index adae0283e5..afc09374b9 100644
--- a/main/tests/test_render.cpp
+++ b/main/tests/test_render.cpp
@@ -65,8 +65,9 @@ class TestMainLoop : public MainLoop {
protected:
public:
virtual void input_event(const Ref<InputEvent> &p_event) {
- if (p_event->is_pressed())
+ if (p_event->is_pressed()) {
quit = true;
+ }
}
virtual void init() {
diff --git a/main/tests/test_shader_lang.cpp b/main/tests/test_shader_lang.cpp
index 707a25699f..34ee3e3210 100644
--- a/main/tests/test_shader_lang.cpp
+++ b/main/tests/test_shader_lang.cpp
@@ -140,8 +140,9 @@ static String dump_node_code(SL::Node *p_node, int p_level) {
"white"
};
- if (E->get().hint)
+ if (E->get().hint) {
ucode += " : " + String(hint_name[E->get().hint]);
+ }
code += ucode + "\n";
}
@@ -160,8 +161,9 @@ static String dump_node_code(SL::Node *p_node, int p_level) {
String header;
header = _typestr(fnode->return_type) + " " + fnode->name + "(";
for (int j = 0; j < fnode->arguments.size(); j++) {
- if (j > 0)
+ if (j > 0) {
header += ", ";
+ }
header += _prestr(fnode->arguments[j].precision) + _typestr(fnode->arguments[j].type) + " " + fnode->arguments[j].name;
}
@@ -252,8 +254,9 @@ static String dump_node_code(SL::Node *p_node, int p_level) {
case SL::OP_CONSTRUCT:
code = dump_node_code(onode->arguments[0], p_level) + "(";
for (int i = 1; i < onode->arguments.size(); i++) {
- if (i > 1)
+ if (i > 1) {
code += ", ";
+ }
code += dump_node_code(onode->arguments[i], p_level);
}
code += ")";
@@ -323,8 +326,9 @@ MainLoop *test() {
while (true) {
CharType c = fa->get_8();
- if (fa->eof_reached())
+ if (fa->eof_reached()) {
break;
+ }
code += c;
}
diff --git a/main/tests/test_string.cpp b/main/tests/test_string.cpp
index ca66ef1cf7..775c039282 100644
--- a/main/tests/test_string.cpp
+++ b/main/tests/test_string.cpp
@@ -108,14 +108,17 @@ bool test_6() {
OS::get_singleton()->print("\tComparing to \"Test Compare\"\n");
- if (!(s == "Test Compare"))
+ if (!(s == "Test Compare")) {
return false;
+ }
- if (!(s == L"Test Compare"))
+ if (!(s == L"Test Compare")) {
return false;
+ }
- if (!(s == String("Test Compare")))
+ if (!(s == String("Test Compare"))) {
return false;
+ }
return true;
}
@@ -127,14 +130,17 @@ bool test_7() {
OS::get_singleton()->print("\tComparing to \"Test Compare\"\n");
- if (!(s != "Peanut"))
+ if (!(s != "Peanut")) {
return false;
+ }
- if (!(s != L"Coconut"))
+ if (!(s != L"Coconut")) {
return false;
+ }
- if (!(s != String("Butter")))
+ if (!(s != String("Butter"))) {
return false;
+ }
return true;
}
@@ -146,14 +152,17 @@ bool test_8() {
OS::get_singleton()->print("\tComparing to \"Bees\"\n");
- if (!(s < "Elephant"))
+ if (!(s < "Elephant")) {
return false;
+ }
- if (s < L"Amber")
+ if (s < L"Amber") {
return false;
+ }
- if (s < String("Beatrix"))
+ if (s < String("Beatrix")) {
return false;
+ }
return true;
}
@@ -179,14 +188,17 @@ bool test_9() {
bool test_10() {
OS::get_singleton()->print("\n\nTest 10: Misc funcs (size/length/empty/etc)\n");
- if (!String("").empty())
+ if (!String("").empty()) {
return false;
+ }
- if (String("Mellon").size() != 7)
+ if (String("Mellon").size() != 7) {
return false;
+ }
- if (String("Oranges").length() != 7)
+ if (String("Oranges").length() != 7) {
return false;
+ }
return true;
}
@@ -199,11 +211,13 @@ bool test_11() {
a[0] = 'S';
a[6] = 'C';
- if (a != "Sugar Cane")
+ if (a != "Sugar Cane") {
return false;
+ }
- if (a[1] != 'u')
+ if (a[1] != 'u') {
return false;
+ }
return true;
}
@@ -213,11 +227,13 @@ bool test_12() {
String a = "MoMoNgA";
- if (a.to_upper() != "MOMONGA")
+ if (a.to_upper() != "MOMONGA") {
return false;
+ }
- if (a.nocasecmp_to("momonga") != 0)
+ if (a.nocasecmp_to("momonga") != 0) {
return false;
+ }
return true;
}
@@ -265,11 +281,13 @@ bool test_16() {
OS::get_singleton()->print("\t\"tty\" is at %i pos.\n", s.find("tty"));
OS::get_singleton()->print("\t\"Revenge of the Monster Truck\" is at %i pos.\n", s.find("Revenge of the Monster Truck"));
- if (s.find("tty") != 3)
+ if (s.find("tty") != 3) {
return false;
+ }
- if (s.find("Revenge of the Monster Truck") != -1)
+ if (s.find("Revenge of the Monster Truck") != -1) {
return false;
+ }
return true;
}
@@ -282,11 +300,13 @@ bool test_17() {
OS::get_singleton()->print("\t\"WHA\" is at %i pos.\n", s.findn("WHA"));
OS::get_singleton()->print("\t\"Revenge of the Monster SawFish\" is at %i pos.\n", s.findn("Revenge of the Monster Truck"));
- if (s.findn("WHA") != 7)
+ if (s.findn("WHA") != 7) {
return false;
+ }
- if (s.findn("Revenge of the Monster SawFish") != -1)
+ if (s.findn("Revenge of the Monster SawFish") != -1) {
return false;
+ }
return true;
}
@@ -299,11 +319,13 @@ bool test_18() {
OS::get_singleton()->print("\t\"WHA\" is at %i pos.\n", s.findn("WHA"));
OS::get_singleton()->print("\t\"Revenge of the Monster SawFish\" is at %i pos.\n", s.findn("Revenge of the Monster Truck"));
- if (s.findn("WHA") != 7)
+ if (s.findn("WHA") != 7) {
return false;
+ }
- if (s.findn("Revenge of the Monster SawFish") != -1)
+ if (s.findn("Revenge of the Monster SawFish") != -1) {
return false;
+ }
return true;
}
@@ -350,8 +372,9 @@ bool test_22() {
for (int i = 0; i < 4; i++) {
OS::get_singleton()->print("\tString: \"%s\" as Int is %i\n", nums[i], String(nums[i]).to_int());
- if (String(nums[i]).to_int() != num[i])
+ if (String(nums[i]).to_int() != num[i]) {
return false;
+ }
}
return true;
@@ -366,8 +389,9 @@ bool test_23() {
for (int i = 0; i < 4; i++) {
OS::get_singleton()->print("\tString: \"%s\" as Float is %f\n", nums[i], String(nums[i]).to_double());
- if (ABS(String(nums[i]).to_double() - num[i]) > 0.00001)
+ if (ABS(String(nums[i]).to_double() - num[i]) > 0.00001) {
return false;
+ }
}
return true;
@@ -385,8 +409,9 @@ bool test_24() {
for (int i = 0; i < s.get_slice_count(","); i++) {
OS::get_singleton()->print("\t\t%i- %ls\n", i + 1, s.get_slice(",", i).c_str());
- if (s.get_slice(",", i) != slices[i])
+ if (s.get_slice(",", i) != slices[i]) {
return false;
+ }
}
return true;
@@ -942,26 +967,30 @@ bool test_31() {
String a = "";
success = a[0] == 0;
OS::get_singleton()->print("Is 0 String[0]:, %s\n", success ? "OK" : "FAIL");
- if (!success)
+ if (!success) {
state = false;
+ }
String b = "Godot";
success = b[b.size()] == 0;
OS::get_singleton()->print("Is 0 String[size()]:, %s\n", success ? "OK" : "FAIL");
- if (!success)
+ if (!success) {
state = false;
+ }
const String c = "";
success = c[0] == 0;
OS::get_singleton()->print("Is 0 const String[0]:, %s\n", success ? "OK" : "FAIL");
- if (!success)
+ if (!success) {
state = false;
+ }
const String d = "Godot";
success = d[d.size()] == 0;
OS::get_singleton()->print("Is 0 const String[size()]:, %s\n", success ? "OK" : "FAIL");
- if (!success)
+ if (!success) {
state = false;
+ }
return state;
};
@@ -1150,11 +1179,13 @@ MainLoop *test() {
int passed = 0;
while (true) {
- if (!test_funcs[count])
+ if (!test_funcs[count]) {
break;
+ }
bool pass = test_funcs[count]();
- if (pass)
+ if (pass) {
passed++;
+ }
OS::get_singleton()->print("\t%s\n", pass ? "PASS" : "FAILED");
count++;
diff --git a/modules/assimp/editor_scene_importer_assimp.cpp b/modules/assimp/editor_scene_importer_assimp.cpp
index 7f0e27b0ee..9c90faf66b 100644
--- a/modules/assimp/editor_scene_importer_assimp.cpp
+++ b/modules/assimp/editor_scene_importer_assimp.cpp
@@ -208,8 +208,9 @@ T EditorSceneImporterAssimp::_interpolate_track(const Vector<float> &p_times, co
//could use binary search, worth it?
int idx = -1;
for (int i = 0; i < p_times.size(); i++) {
- if (p_times[i] > p_time)
+ if (p_times[i] > p_time) {
break;
+ }
idx++;
}
diff --git a/modules/basis_universal/register_types.cpp b/modules/basis_universal/register_types.cpp
index d3cfcc0092..27b299a65d 100644
--- a/modules/basis_universal/register_types.cpp
+++ b/modules/basis_universal/register_types.cpp
@@ -240,8 +240,9 @@ static Ref<Image> basis_universal_unpacker(const Vector<uint8_t> &p_buffer) {
{
uint8_t *w = gpudata.ptrw();
uint8_t *dst = w;
- for (int i = 0; i < gpudata.size(); i++)
+ for (int i = 0; i < gpudata.size(); i++) {
dst[i] = 0x00;
+ }
int ofs = 0;
tr.start_transcoding(ptr, size);
diff --git a/modules/bmp/image_loader_bmp.cpp b/modules/bmp/image_loader_bmp.cpp
index 89947d1ef9..ac4e534983 100644
--- a/modules/bmp/image_loader_bmp.cpp
+++ b/modules/bmp/image_loader_bmp.cpp
@@ -37,8 +37,9 @@ Error ImageLoaderBMP::convert_to_image(Ref<Image> p_image,
const bmp_header_s &p_header) {
Error err = OK;
- if (p_buffer == nullptr)
+ if (p_buffer == nullptr) {
err = FAILED;
+ }
if (err == OK) {
size_t index = 0;
diff --git a/modules/bullet/area_bullet.cpp b/modules/bullet/area_bullet.cpp
index d5b03015a9..79d8e252f0 100644
--- a/modules/bullet/area_bullet.cpp
+++ b/modules/bullet/area_bullet.cpp
@@ -52,19 +52,22 @@ AreaBullet::AreaBullet() :
/// In order to use collision objects as trigger, you have to disable the collision response.
set_collision_enabled(false);
- for (int i = 0; i < 5; ++i)
+ for (int i = 0; i < 5; ++i) {
call_event_res_ptr[i] = &call_event_res[i];
+ }
}
AreaBullet::~AreaBullet() {
// signal are handled by godot, so just clear without notify
- for (int i = overlappingObjects.size() - 1; 0 <= i; --i)
+ for (int i = overlappingObjects.size() - 1; 0 <= i; --i) {
overlappingObjects[i].object->on_exit_area(this);
+ }
}
void AreaBullet::dispatch_callbacks() {
- if (!isScratched)
+ if (!isScratched) {
return;
+ }
isScratched = false;
// Reverse order because I've to remove EXIT objects
@@ -109,15 +112,17 @@ void AreaBullet::call_event(CollisionObjectBullet *p_otherObject, PhysicsServer3
}
void AreaBullet::scratch() {
- if (isScratched)
+ if (isScratched) {
return;
+ }
isScratched = true;
}
void AreaBullet::clear_overlaps(bool p_notify) {
for (int i = overlappingObjects.size() - 1; 0 <= i; --i) {
- if (p_notify)
+ if (p_notify) {
call_event(overlappingObjects[i].object, PhysicsServer3D::AREA_BODY_REMOVED);
+ }
overlappingObjects[i].object->on_exit_area(this);
}
overlappingObjects.clear();
@@ -126,8 +131,9 @@ void AreaBullet::clear_overlaps(bool p_notify) {
void AreaBullet::remove_overlap(CollisionObjectBullet *p_object, bool p_notify) {
for (int i = overlappingObjects.size() - 1; 0 <= i; --i) {
if (overlappingObjects[i].object == p_object) {
- if (p_notify)
+ if (p_notify) {
call_event(overlappingObjects[i].object, PhysicsServer3D::AREA_BODY_REMOVED);
+ }
overlappingObjects[i].object->on_exit_area(this);
overlappingObjects.remove(i);
break;
diff --git a/modules/bullet/btRayShape.cpp b/modules/bullet/btRayShape.cpp
index ee84354315..a754ca6a89 100644
--- a/modules/bullet/btRayShape.cpp
+++ b/modules/bullet/btRayShape.cpp
@@ -68,10 +68,11 @@ btVector3 btRayShape::localGetSupportingVertex(const btVector3 &vec) const {
}
btVector3 btRayShape::localGetSupportingVertexWithoutMargin(const btVector3 &vec) const {
- if (vec.z() > 0)
+ if (vec.z() > 0) {
return m_shapeAxis * m_cacheScaledLength;
- else
+ } else {
return btVector3(0, 0, 0);
+ }
}
void btRayShape::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3 *vectors, btVector3 *supportVerticesOut, int numVectors) const {
diff --git a/modules/bullet/bullet_physics_server.cpp b/modules/bullet/bullet_physics_server.cpp
index c20fade011..55686543f3 100644
--- a/modules/bullet/bullet_physics_server.cpp
+++ b/modules/bullet/bullet_physics_server.cpp
@@ -326,8 +326,9 @@ void BulletPhysicsServer3D::area_clear_shapes(RID p_area) {
AreaBullet *area = area_owner.getornull(p_area);
ERR_FAIL_COND(!area);
- for (int i = area->get_shape_count(); 0 < i; --i)
+ for (int i = area->get_shape_count(); 0 < i; --i) {
area->remove_shape_full(0);
+ }
}
void BulletPhysicsServer3D::area_set_shape_disabled(RID p_area, int p_shape_idx, bool p_disabled) {
@@ -443,8 +444,9 @@ RID BulletPhysicsServer3D::body_create(BodyMode p_mode, bool p_init_sleeping) {
body->set_mode(p_mode);
body->set_collision_layer(1);
body->set_collision_mask(1);
- if (p_init_sleeping)
+ if (p_init_sleeping) {
body->set_state(BODY_STATE_SLEEPING, p_init_sleeping);
+ }
CreateThenReturnRID(rigid_body_owner, body);
}
@@ -458,8 +460,9 @@ void BulletPhysicsServer3D::body_set_space(RID p_body, RID p_space) {
ERR_FAIL_COND(!space);
}
- if (body->get_space() == space)
+ if (body->get_space() == space) {
return; //pointles
+ }
body->set_space(space);
}
@@ -469,8 +472,9 @@ RID BulletPhysicsServer3D::body_get_space(RID p_body) const {
ERR_FAIL_COND_V(!body, RID());
SpaceBullet *space = body->get_space();
- if (!space)
+ if (!space) {
return RID();
+ }
return space->get_self();
}
@@ -870,8 +874,9 @@ RID BulletPhysicsServer3D::soft_body_create(bool p_init_sleeping) {
SoftBodyBullet *body = bulletnew(SoftBodyBullet);
body->set_collision_layer(1);
body->set_collision_mask(1);
- if (p_init_sleeping)
+ if (p_init_sleeping) {
body->set_activation_state(false);
+ }
CreateThenReturnRID(soft_body_owner, body);
}
@@ -892,8 +897,9 @@ void BulletPhysicsServer3D::soft_body_set_space(RID p_body, RID p_space) {
ERR_FAIL_COND(!space);
}
- if (body->get_space() == space)
+ if (body->get_space() == space) {
return; //pointles
+ }
body->set_space(space);
}
@@ -903,8 +909,9 @@ RID BulletPhysicsServer3D::soft_body_get_space(RID p_body) const {
ERR_FAIL_COND_V(!body, RID());
SpaceBullet *space = body->get_space();
- if (!space)
+ if (!space) {
return RID();
+ }
return space->get_self();
}
@@ -1535,8 +1542,9 @@ void BulletPhysicsServer3D::init() {
}
void BulletPhysicsServer3D::step(float p_deltaTime) {
- if (!active)
+ if (!active) {
return;
+ }
BulletPhysicsDirectBodyState3D::singleton_setDeltaTime(p_deltaTime);
diff --git a/modules/bullet/collision_object_bullet.cpp b/modules/bullet/collision_object_bullet.cpp
index 0d456a155a..a3158a15e5 100644
--- a/modules/bullet/collision_object_bullet.cpp
+++ b/modules/bullet/collision_object_bullet.cpp
@@ -80,10 +80,11 @@ btTransform CollisionObjectBullet::ShapeWrapper::get_adjusted_transform() const
void CollisionObjectBullet::ShapeWrapper::claim_bt_shape(const btVector3 &body_scale) {
if (!bt_shape) {
- if (active)
+ if (active) {
bt_shape = shape->create_bt_shape(scale * body_scale);
- else
+ } else {
bt_shape = ShapeBullet::create_shape_empty();
+ }
}
}
@@ -136,18 +137,21 @@ void CollisionObjectBullet::setupBulletCollisionObject(btCollisionObject *p_coll
void CollisionObjectBullet::add_collision_exception(const CollisionObjectBullet *p_ignoreCollisionObject) {
exceptions.insert(p_ignoreCollisionObject->get_self());
- if (!bt_collision_object)
+ if (!bt_collision_object) {
return;
+ }
bt_collision_object->setIgnoreCollisionCheck(p_ignoreCollisionObject->bt_collision_object, true);
- if (space)
+ if (space) {
space->get_broadphase()->getOverlappingPairCache()->cleanProxyFromPairs(bt_collision_object->getBroadphaseHandle(), space->get_dispatcher());
+ }
}
void CollisionObjectBullet::remove_collision_exception(const CollisionObjectBullet *p_ignoreCollisionObject) {
exceptions.erase(p_ignoreCollisionObject->get_self());
bt_collision_object->setIgnoreCollisionCheck(p_ignoreCollisionObject->bt_collision_object, false);
- if (space)
+ if (space) {
space->get_broadphase()->getOverlappingPairCache()->cleanProxyFromPairs(bt_collision_object->getBroadphaseHandle(), space->get_dispatcher());
+ }
}
bool CollisionObjectBullet::has_collision_exception(const CollisionObjectBullet *p_otherCollisionObject) const {
@@ -249,8 +253,9 @@ btCollisionShape *RigidCollisionObjectBullet::get_bt_shape(int p_index) const {
int RigidCollisionObjectBullet::find_shape(ShapeBullet *p_shape) const {
const int size = shapes.size();
for (int i = 0; i < size; ++i) {
- if (shapes[i].shape == p_shape)
+ if (shapes[i].shape == p_shape) {
return i;
+ }
}
return -1;
}
@@ -280,8 +285,9 @@ void RigidCollisionObjectBullet::remove_all_shapes(bool p_permanentlyFromThisBod
internal_shape_destroy(i, p_permanentlyFromThisBody);
}
shapes.clear();
- if (!p_force_not_reload)
+ if (!p_force_not_reload) {
reload_shapes();
+ }
}
void RigidCollisionObjectBullet::set_shape_transform(int p_index, const Transform &p_transform) {
@@ -302,8 +308,9 @@ Transform RigidCollisionObjectBullet::get_shape_transform(int p_index) const {
}
void RigidCollisionObjectBullet::set_shape_disabled(int p_index, bool p_disabled) {
- if (shapes[p_index].active != p_disabled)
+ if (shapes[p_index].active != p_disabled) {
return;
+ }
shapes.write[p_index].active = !p_disabled;
shape_changed(p_index);
}
diff --git a/modules/bullet/godot_ray_world_algorithm.cpp b/modules/bullet/godot_ray_world_algorithm.cpp
index fbb336ca56..a84f3511ba 100644
--- a/modules/bullet/godot_ray_world_algorithm.cpp
+++ b/modules/bullet/godot_ray_world_algorithm.cpp
@@ -98,12 +98,13 @@ void GodotRayWorldAlgorithm::processCollision(const btCollisionObjectWrapper *bo
if (btResult.hasHit()) {
btScalar depth(ray_shape->getScaledLength() * (btResult.m_closestHitFraction - 1));
- if (depth > -RAY_PENETRATION_DEPTH_EPSILON)
+ if (depth > -RAY_PENETRATION_DEPTH_EPSILON) {
depth = 0.0;
+ }
- if (ray_shape->getSlipsOnSlope())
+ if (ray_shape->getSlipsOnSlope()) {
resultOut->addContactPoint(btResult.m_hitNormalWorld, btResult.m_hitPointWorld, depth);
- else {
+ } else {
resultOut->addContactPoint((ray_transform.getOrigin() - to.getOrigin()).normalize(), btResult.m_hitPointWorld, depth);
}
}
diff --git a/modules/bullet/godot_ray_world_algorithm.h b/modules/bullet/godot_ray_world_algorithm.h
index 45344186f5..9786732d40 100644
--- a/modules/bullet/godot_ray_world_algorithm.h
+++ b/modules/bullet/godot_ray_world_algorithm.h
@@ -56,8 +56,9 @@ public:
virtual void getAllContactManifolds(btManifoldArray &manifoldArray) {
///should we use m_ownManifold to avoid adding duplicates?
- if (m_manifoldPtr && m_ownManifold)
+ if (m_manifoldPtr && m_ownManifold) {
manifoldArray.push_back(m_manifoldPtr);
+ }
}
struct CreateFunc : public btCollisionAlgorithmCreateFunc {
const btDiscreteDynamicsWorld *m_world;
diff --git a/modules/bullet/godot_result_callbacks.cpp b/modules/bullet/godot_result_callbacks.cpp
index b9c2a00b34..f82648d6ff 100644
--- a/modules/bullet/godot_result_callbacks.cpp
+++ b/modules/bullet/godot_result_callbacks.cpp
@@ -62,11 +62,13 @@ bool GodotClosestRayResultCallback::needsCollision(btBroadphaseProxy *proxy0) co
CollisionObjectBullet *gObj = static_cast<CollisionObjectBullet *>(btObj->getUserPointer());
if (CollisionObjectBullet::TYPE_AREA == gObj->getType()) {
- if (!collide_with_areas)
+ if (!collide_with_areas) {
return false;
+ }
} else {
- if (!collide_with_bodies)
+ if (!collide_with_bodies) {
return false;
+ }
}
if (m_pickRay && !gObj->is_ray_pickable()) {
@@ -84,8 +86,9 @@ bool GodotClosestRayResultCallback::needsCollision(btBroadphaseProxy *proxy0) co
}
bool GodotAllConvexResultCallback::needsCollision(btBroadphaseProxy *proxy0) const {
- if (count >= m_resultMax)
+ if (count >= m_resultMax) {
return false;
+ }
const bool needs = GodotFilterCallback::test_collision_filters(m_collisionFilterGroup, m_collisionFilterMask, proxy0->m_collisionFilterGroup, proxy0->m_collisionFilterMask);
if (needs) {
@@ -102,8 +105,9 @@ bool GodotAllConvexResultCallback::needsCollision(btBroadphaseProxy *proxy0) con
}
btScalar GodotAllConvexResultCallback::addSingleResult(btCollisionWorld::LocalConvexResult &convexResult, bool normalInWorldSpace) {
- if (count >= m_resultMax)
+ if (count >= m_resultMax) {
return 1; // not used by bullet
+ }
CollisionObjectBullet *gObj = static_cast<CollisionObjectBullet *>(convexResult.m_hitCollisionObject->getUserPointer());
@@ -127,14 +131,17 @@ bool GodotKinClosestConvexResultCallback::needsCollision(btBroadphaseProxy *prox
return false;
} else {
// A kinematic body can't be stopped by a rigid body since the mass of kinematic body is infinite
- if (m_infinite_inertia && !btObj->isStaticOrKinematicObject())
+ if (m_infinite_inertia && !btObj->isStaticOrKinematicObject()) {
return false;
+ }
- if (gObj->getType() == CollisionObjectBullet::TYPE_AREA)
+ if (gObj->getType() == CollisionObjectBullet::TYPE_AREA) {
return false;
+ }
- if (m_self_object->has_collision_exception(gObj) || gObj->has_collision_exception(m_self_object))
+ if (m_self_object->has_collision_exception(gObj) || gObj->has_collision_exception(m_self_object)) {
return false;
+ }
}
return true;
} else {
@@ -149,11 +156,13 @@ bool GodotClosestConvexResultCallback::needsCollision(btBroadphaseProxy *proxy0)
CollisionObjectBullet *gObj = static_cast<CollisionObjectBullet *>(btObj->getUserPointer());
if (CollisionObjectBullet::TYPE_AREA == gObj->getType()) {
- if (!collide_with_areas)
+ if (!collide_with_areas) {
return false;
+ }
} else {
- if (!collide_with_bodies)
+ if (!collide_with_bodies) {
return false;
+ }
}
if (m_exclude->has(gObj->get_self())) {
@@ -166,16 +175,18 @@ bool GodotClosestConvexResultCallback::needsCollision(btBroadphaseProxy *proxy0)
}
btScalar GodotClosestConvexResultCallback::addSingleResult(btCollisionWorld::LocalConvexResult &convexResult, bool normalInWorldSpace) {
- if (convexResult.m_localShapeInfo)
+ if (convexResult.m_localShapeInfo) {
m_shapeId = convexResult.m_localShapeInfo->m_triangleIndex; // "m_triangleIndex" Is a odd name but contains the compound shape ID
- else
+ } else {
m_shapeId = 0;
+ }
return btCollisionWorld::ClosestConvexResultCallback::addSingleResult(convexResult, normalInWorldSpace);
}
bool GodotAllContactResultCallback::needsCollision(btBroadphaseProxy *proxy0) const {
- if (m_count >= m_resultMax)
+ if (m_count >= m_resultMax) {
return false;
+ }
const bool needs = GodotFilterCallback::test_collision_filters(m_collisionFilterGroup, m_collisionFilterMask, proxy0->m_collisionFilterGroup, proxy0->m_collisionFilterMask);
if (needs) {
@@ -183,11 +194,13 @@ bool GodotAllContactResultCallback::needsCollision(btBroadphaseProxy *proxy0) co
CollisionObjectBullet *gObj = static_cast<CollisionObjectBullet *>(btObj->getUserPointer());
if (CollisionObjectBullet::TYPE_AREA == gObj->getType()) {
- if (!collide_with_areas)
+ if (!collide_with_areas) {
return false;
+ }
} else {
- if (!collide_with_bodies)
+ if (!collide_with_bodies) {
return false;
+ }
}
if (m_exclude->has(gObj->get_self())) {
@@ -200,8 +213,9 @@ bool GodotAllContactResultCallback::needsCollision(btBroadphaseProxy *proxy0) co
}
btScalar GodotAllContactResultCallback::addSingleResult(btManifoldPoint &cp, const btCollisionObjectWrapper *colObj0Wrap, int partId0, int index0, const btCollisionObjectWrapper *colObj1Wrap, int partId1, int index1) {
- if (m_count >= m_resultMax)
+ if (m_count >= m_resultMax) {
return cp.getDistance();
+ }
if (cp.getDistance() <= 0) {
PhysicsDirectSpaceState3D::ShapeResult &result = m_results[m_count];
@@ -226,8 +240,9 @@ btScalar GodotAllContactResultCallback::addSingleResult(btManifoldPoint &cp, con
}
bool GodotContactPairContactResultCallback::needsCollision(btBroadphaseProxy *proxy0) const {
- if (m_count >= m_resultMax)
+ if (m_count >= m_resultMax) {
return false;
+ }
const bool needs = GodotFilterCallback::test_collision_filters(m_collisionFilterGroup, m_collisionFilterMask, proxy0->m_collisionFilterGroup, proxy0->m_collisionFilterMask);
if (needs) {
@@ -235,11 +250,13 @@ bool GodotContactPairContactResultCallback::needsCollision(btBroadphaseProxy *pr
CollisionObjectBullet *gObj = static_cast<CollisionObjectBullet *>(btObj->getUserPointer());
if (CollisionObjectBullet::TYPE_AREA == gObj->getType()) {
- if (!collide_with_areas)
+ if (!collide_with_areas) {
return false;
+ }
} else {
- if (!collide_with_bodies)
+ if (!collide_with_bodies) {
return false;
+ }
}
if (m_exclude->has(gObj->get_self())) {
@@ -252,8 +269,9 @@ bool GodotContactPairContactResultCallback::needsCollision(btBroadphaseProxy *pr
}
btScalar GodotContactPairContactResultCallback::addSingleResult(btManifoldPoint &cp, const btCollisionObjectWrapper *colObj0Wrap, int partId0, int index0, const btCollisionObjectWrapper *colObj1Wrap, int partId1, int index1) {
- if (m_count >= m_resultMax)
+ if (m_count >= m_resultMax) {
return 1; // not used by bullet
+ }
if (m_self_object == colObj0Wrap->getCollisionObject()) {
B_TO_G(cp.m_localPointA, m_results[m_count * 2 + 0]); // Local contact
@@ -275,11 +293,13 @@ bool GodotRestInfoContactResultCallback::needsCollision(btBroadphaseProxy *proxy
CollisionObjectBullet *gObj = static_cast<CollisionObjectBullet *>(btObj->getUserPointer());
if (CollisionObjectBullet::TYPE_AREA == gObj->getType()) {
- if (!collide_with_areas)
+ if (!collide_with_areas) {
return false;
+ }
} else {
- if (!collide_with_bodies)
+ if (!collide_with_bodies) {
return false;
+ }
}
if (m_exclude->has(gObj->get_self())) {
diff --git a/modules/bullet/godot_result_callbacks.h b/modules/bullet/godot_result_callbacks.h
index 8636ca8eb6..1325542973 100644
--- a/modules/bullet/godot_result_callbacks.h
+++ b/modules/bullet/godot_result_callbacks.h
@@ -72,10 +72,11 @@ public:
virtual bool needsCollision(btBroadphaseProxy *proxy0) const;
virtual btScalar addSingleResult(btCollisionWorld::LocalRayResult &rayResult, bool normalInWorldSpace) {
- if (rayResult.m_localShapeInfo)
+ if (rayResult.m_localShapeInfo) {
m_shapeId = rayResult.m_localShapeInfo->m_triangleIndex; // "m_triangleIndex" Is a odd name but contains the compound shape ID
- else
+ } else {
m_shapeId = 0;
+ }
return btCollisionWorld::ClosestRayResultCallback::addSingleResult(rayResult, normalInWorldSpace);
}
};
diff --git a/modules/bullet/rigid_body_bullet.cpp b/modules/bullet/rigid_body_bullet.cpp
index f263893287..2fca7fe633 100644
--- a/modules/bullet/rigid_body_bullet.cpp
+++ b/modules/bullet/rigid_body_bullet.cpp
@@ -283,8 +283,9 @@ RigidBodyBullet::RigidBodyBullet() :
RigidBodyBullet::~RigidBodyBullet() {
bulletdelete(godotMotionState);
- if (force_integration_callback)
+ if (force_integration_callback) {
memdelete(force_integration_callback);
+ }
destroy_kinematic_utilities();
}
@@ -309,8 +310,9 @@ void RigidBodyBullet::main_shape_changed() {
void RigidBodyBullet::reload_body() {
if (space) {
space->remove_rigid_body(this);
- if (get_main_shape())
+ if (get_main_shape()) {
space->add_rigid_body(this);
+ }
}
}
@@ -336,8 +338,9 @@ void RigidBodyBullet::set_space(SpaceBullet *p_space) {
void RigidBodyBullet::dispatch_callbacks() {
/// The check isFirstTransformChanged is necessary in order to call integrated forces only when the first transform is sent
if ((btBody->isKinematicObject() || btBody->isActive() || previousActiveState != btBody->isActive()) && force_integration_callback && can_integrate_forces) {
- if (omit_forces_integration)
+ if (omit_forces_integration) {
btBody->clearForces();
+ }
BulletPhysicsDirectBodyState3D *bodyDirect = BulletPhysicsDirectBodyState3D::get_singleton(this);
@@ -431,8 +434,9 @@ bool RigidBodyBullet::add_collision_object(RigidBodyBullet *p_otherObject, const
bool RigidBodyBullet::was_colliding(RigidBodyBullet *p_other_object) {
for (int i = prev_collision_count - 1; 0 <= i; --i) {
- if ((*prev_collision_traces)[i] == p_other_object)
+ if ((*prev_collision_traces)[i] == p_other_object) {
return true;
+ }
}
return false;
}
@@ -607,8 +611,9 @@ Variant RigidBodyBullet::get_state(PhysicsServer3D::BodyState p_state) const {
void RigidBodyBullet::apply_central_impulse(const Vector3 &p_impulse) {
btVector3 btImpu;
G_TO_B(p_impulse, btImpu);
- if (Vector3() != p_impulse)
+ if (Vector3() != p_impulse) {
btBody->activate();
+ }
btBody->applyCentralImpulse(btImpu);
}
@@ -617,16 +622,18 @@ void RigidBodyBullet::apply_impulse(const Vector3 &p_pos, const Vector3 &p_impul
btVector3 btPos;
G_TO_B(p_impulse, btImpu);
G_TO_B(p_pos, btPos);
- if (Vector3() != p_impulse)
+ if (Vector3() != p_impulse) {
btBody->activate();
+ }
btBody->applyImpulse(btImpu, btPos);
}
void RigidBodyBullet::apply_torque_impulse(const Vector3 &p_impulse) {
btVector3 btImp;
G_TO_B(p_impulse, btImp);
- if (Vector3() != p_impulse)
+ if (Vector3() != p_impulse) {
btBody->activate();
+ }
btBody->applyTorqueImpulse(btImp);
}
@@ -635,32 +642,36 @@ void RigidBodyBullet::apply_force(const Vector3 &p_force, const Vector3 &p_pos)
btVector3 btPos;
G_TO_B(p_force, btForce);
G_TO_B(p_pos, btPos);
- if (Vector3() != p_force)
+ if (Vector3() != p_force) {
btBody->activate();
+ }
btBody->applyForce(btForce, btPos);
}
void RigidBodyBullet::apply_central_force(const Vector3 &p_force) {
btVector3 btForce;
G_TO_B(p_force, btForce);
- if (Vector3() != p_force)
+ if (Vector3() != p_force) {
btBody->activate();
+ }
btBody->applyCentralForce(btForce);
}
void RigidBodyBullet::apply_torque(const Vector3 &p_torque) {
btVector3 btTorq;
G_TO_B(p_torque, btTorq);
- if (Vector3() != p_torque)
+ if (Vector3() != p_torque) {
btBody->activate();
+ }
btBody->applyTorque(btTorq);
}
void RigidBodyBullet::set_applied_force(const Vector3 &p_force) {
btVector3 btVec = btBody->getTotalTorque();
- if (Vector3() != p_force)
+ if (Vector3() != p_force) {
btBody->activate();
+ }
btBody->clearForces();
btBody->applyTorque(btVec);
@@ -678,8 +689,9 @@ Vector3 RigidBodyBullet::get_applied_force() const {
void RigidBodyBullet::set_applied_torque(const Vector3 &p_torque) {
btVector3 btVec = btBody->getTotalForce();
- if (Vector3() != p_torque)
+ if (Vector3() != p_torque) {
btBody->activate();
+ }
btBody->clearForces();
btBody->applyCentralForce(btVec);
@@ -747,8 +759,9 @@ bool RigidBodyBullet::is_continuous_collision_detection_enabled() const {
void RigidBodyBullet::set_linear_velocity(const Vector3 &p_velocity) {
btVector3 btVec;
G_TO_B(p_velocity, btVec);
- if (Vector3() != p_velocity)
+ if (Vector3() != p_velocity) {
btBody->activate();
+ }
btBody->setLinearVelocity(btVec);
}
@@ -761,8 +774,9 @@ Vector3 RigidBodyBullet::get_linear_velocity() const {
void RigidBodyBullet::set_angular_velocity(const Vector3 &p_velocity) {
btVector3 btVec;
G_TO_B(p_velocity, btVec);
- if (Vector3() != p_velocity)
+ if (Vector3() != p_velocity) {
btBody->activate();
+ }
btBody->setAngularVelocity(btVec);
}
@@ -774,8 +788,9 @@ Vector3 RigidBodyBullet::get_angular_velocity() const {
void RigidBodyBullet::set_transform__bullet(const btTransform &p_global_transform) {
if (mode == PhysicsServer3D::BODY_MODE_KINEMATIC) {
- if (space && space->get_delta_time() != 0)
+ if (space && space->get_delta_time() != 0) {
btBody->setLinearVelocity((p_global_transform.getOrigin() - btBody->getWorldTransform().getOrigin()) / space->get_delta_time());
+ }
// The kinematic use MotionState class
godotMotionState->moveBody(p_global_transform);
} else {
@@ -804,8 +819,9 @@ void RigidBodyBullet::reload_shapes() {
// shapes incorrectly do not set the vector in calculateLocalIntertia.
// Arbitrary zero is preferable to undefined behaviour.
btVector3 inertia(0, 0, 0);
- if (EMPTY_SHAPE_PROXYTYPE != mainShape->getShapeType()) // Necessary to avoid assertion of the empty shape
+ if (EMPTY_SHAPE_PROXYTYPE != mainShape->getShapeType()) { // Necessary to avoid assertion of the empty shape
mainShape->calculateLocalInertia(mass, inertia);
+ }
btBody->setMassProps(mass, inertia);
}
btBody->updateInertiaTensor();
@@ -879,8 +895,9 @@ void RigidBodyBullet::on_exit_area(AreaBullet *p_area) {
void RigidBodyBullet::reload_space_override_modificator() {
// Make sure that kinematic bodies have their total gravity calculated
- if (!is_active() && PhysicsServer3D::BODY_MODE_KINEMATIC != mode)
+ if (!is_active() && PhysicsServer3D::BODY_MODE_KINEMATIC != mode) {
return;
+ }
Vector3 newGravity(0.0, 0.0, 0.0);
real_t newLinearDamp = MAX(0.0, linearDamp);
@@ -1001,12 +1018,14 @@ void RigidBodyBullet::_internal_set_mass(real_t p_mass) {
// Rigidbody is dynamic if and only if mass is non Zero, otherwise static
const bool isDynamic = p_mass != 0.f;
if (isDynamic) {
- if (PhysicsServer3D::BODY_MODE_RIGID != mode && PhysicsServer3D::BODY_MODE_CHARACTER != mode)
+ if (PhysicsServer3D::BODY_MODE_RIGID != mode && PhysicsServer3D::BODY_MODE_CHARACTER != mode) {
return;
+ }
m_isStatic = false;
- if (mainShape)
+ if (mainShape) {
mainShape->calculateLocalInertia(p_mass, localInertia);
+ }
if (PhysicsServer3D::BODY_MODE_RIGID == mode) {
btBody->setCollisionFlags(clearedCurrentFlags); // Just set the flags without Kin and Static
@@ -1020,8 +1039,9 @@ void RigidBodyBullet::_internal_set_mass(real_t p_mass) {
btBody->forceActivationState(DISABLE_DEACTIVATION); // DISABLE_DEACTIVATION 4
}
} else {
- if (PhysicsServer3D::BODY_MODE_STATIC != mode && PhysicsServer3D::BODY_MODE_KINEMATIC != mode)
+ if (PhysicsServer3D::BODY_MODE_STATIC != mode && PhysicsServer3D::BODY_MODE_KINEMATIC != mode) {
return;
+ }
m_isStatic = true;
if (PhysicsServer3D::BODY_MODE_STATIC == mode) {
diff --git a/modules/bullet/shape_bullet.cpp b/modules/bullet/shape_bullet.cpp
index 424daf7726..d53f1e7d17 100644
--- a/modules/bullet/shape_bullet.cpp
+++ b/modules/bullet/shape_bullet.cpp
@@ -80,8 +80,9 @@ void ShapeBullet::add_owner(ShapeOwnerBullet *p_owner) {
void ShapeBullet::remove_owner(ShapeOwnerBullet *p_owner, bool p_permanentlyFromThisBody) {
Map<ShapeOwnerBullet *, int>::Element *E = owners.find(p_owner);
- if (!E)
+ if (!E) {
return;
+ }
E->get()--;
if (p_permanentlyFromThisBody || 0 >= E->get()) {
owners.erase(E);
@@ -150,8 +151,9 @@ btHeightfieldTerrainShape *ShapeBullet::create_shape_height_field(Vector<real_t>
btHeightfieldTerrainShape *heightfield = bulletnew(btHeightfieldTerrainShape(p_width, p_depth, heightsPtr, ignoredHeightScale, p_min_height, p_max_height, YAxis, PHY_FLOAT, flipQuadEdges));
// The shape can be created without params when you do PhysicsServer3D.shape_create(PhysicsServer3D.SHAPE_HEIGHTMAP)
- if (heightsPtr)
+ if (heightsPtr) {
heightfield->buildAccelerator(16);
+ }
return heightfield;
}
@@ -348,9 +350,10 @@ void ConvexPolygonShapeBullet::setup(const Vector<Vector3> &p_vertices) {
}
btCollisionShape *ConvexPolygonShapeBullet::create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge) {
- if (!vertices.size())
+ if (!vertices.size()) {
// This is necessary since 0 vertices
return prepare(ShapeBullet::create_shape_empty());
+ }
btCollisionShape *cs(ShapeBullet::create_shape_convex(vertices));
cs->setLocalScaling(p_implicit_scale);
prepare(cs);
@@ -430,9 +433,10 @@ void ConcavePolygonShapeBullet::setup(Vector<Vector3> p_faces) {
btCollisionShape *ConcavePolygonShapeBullet::create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge) {
btCollisionShape *cs = ShapeBullet::create_shape_concave(meshShape);
- if (!cs)
+ if (!cs) {
// This is necessary since if 0 faces the creation of concave return null
cs = ShapeBullet::create_shape_empty();
+ }
cs->setLocalScaling(p_implicit_scale);
prepare(cs);
cs->setMargin(0);
@@ -455,10 +459,12 @@ void HeightMapShapeBullet::set_data(const Variant &p_data) {
real_t l_max_height = 0.0;
// If specified, min and max height will be used as precomputed values
- if (d.has("min_height"))
+ if (d.has("min_height")) {
l_min_height = d["min_height"];
- if (d.has("max_height"))
+ }
+ if (d.has("max_height")) {
l_max_height = d["max_height"];
+ }
ERR_FAIL_COND(l_min_height > l_max_height);
diff --git a/modules/bullet/soft_body_bullet.cpp b/modules/bullet/soft_body_bullet.cpp
index 3047a3eed1..6794d6c313 100644
--- a/modules/bullet/soft_body_bullet.cpp
+++ b/modules/bullet/soft_body_bullet.cpp
@@ -66,8 +66,9 @@ void SoftBodyBullet::on_enter_area(AreaBullet *p_area) {}
void SoftBodyBullet::on_exit_area(AreaBullet *p_area) {}
void SoftBodyBullet::update_rendering_server(SoftBodyRenderingServerHandler *p_rendering_server_handler) {
- if (!bt_soft_body)
+ if (!bt_soft_body) {
return;
+ }
/// Update visual server vertices
const btSoftBody::tNodeArray &nodes(bt_soft_body->m_nodes);
@@ -105,10 +106,11 @@ void SoftBodyBullet::update_rendering_server(SoftBodyRenderingServerHandler *p_r
}
void SoftBodyBullet::set_soft_mesh(const Ref<Mesh> &p_mesh) {
- if (p_mesh.is_null())
+ if (p_mesh.is_null()) {
soft_mesh.unref();
- else
+ } else {
soft_mesh = p_mesh;
+ }
if (soft_mesh.is_null()) {
destroy_soft_body();
@@ -121,8 +123,9 @@ void SoftBodyBullet::set_soft_mesh(const Ref<Mesh> &p_mesh) {
}
void SoftBodyBullet::destroy_soft_body() {
- if (!bt_soft_body)
+ if (!bt_soft_body) {
return;
+ }
if (space) {
/// Remove from world before deletion
@@ -139,8 +142,9 @@ void SoftBodyBullet::set_soft_transform(const Transform &p_transform) {
}
void SoftBodyBullet::move_all_nodes(const Transform &p_transform) {
- if (!bt_soft_body)
+ if (!bt_soft_body) {
return;
+ }
btTransform bt_transf;
G_TO_B(p_transform, bt_transf);
bt_soft_body->transform(bt_transf);
@@ -166,8 +170,9 @@ void SoftBodyBullet::get_node_position(int p_node_index, Vector3 &r_position) co
}
void SoftBodyBullet::get_node_offset(int p_node_index, Vector3 &r_offset) const {
- if (soft_mesh.is_null())
+ if (soft_mesh.is_null()) {
return;
+ }
Array arrays = soft_mesh->surface_get_arrays(0);
Vector<Vector3> vertices(arrays[RS::ARRAY_VERTEX]);
@@ -212,8 +217,9 @@ void SoftBodyBullet::reset_all_node_mass() {
}
void SoftBodyBullet::reset_all_node_positions() {
- if (soft_mesh.is_null())
+ if (soft_mesh.is_null()) {
return;
+ }
Array arrays = soft_mesh->surface_get_arrays(0);
Vector<Vector3> vs_vertices(arrays[RS::ARRAY_VERTEX]);
@@ -382,8 +388,9 @@ void SoftBodyBullet::set_trimesh_body_shape(Vector<int> p_indices, Vector<Vector
}
void SoftBodyBullet::setup_soft_body() {
- if (!bt_soft_body)
+ if (!bt_soft_body) {
return;
+ }
// Soft body setup
setupBulletCollisionObject(bt_soft_body);
diff --git a/modules/bullet/space_bullet.cpp b/modules/bullet/space_bullet.cpp
index 433f1109c9..99f58e7059 100644
--- a/modules/bullet/space_bullet.cpp
+++ b/modules/bullet/space_bullet.cpp
@@ -63,8 +63,9 @@ BulletPhysicsDirectSpaceState::BulletPhysicsDirectSpaceState(SpaceBullet *p_spac
space(p_space) {}
int BulletPhysicsDirectSpaceState::intersect_point(const Vector3 &p_point, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas) {
- if (p_result_max <= 0)
+ if (p_result_max <= 0) {
return 0;
+ }
btVector3 bt_point;
G_TO_B(p_point, bt_point);
@@ -117,8 +118,9 @@ bool BulletPhysicsDirectSpaceState::intersect_ray(const Vector3 &p_from, const V
}
int BulletPhysicsDirectSpaceState::intersect_shape(const RID &p_shape, const Transform &p_xform, float p_margin, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas) {
- if (p_result_max <= 0)
+ if (p_result_max <= 0) {
return 0;
+ }
ShapeBullet *shape = space->get_physics_server()->get_shape_owner()->getornull(p_shape);
@@ -202,8 +204,9 @@ bool BulletPhysicsDirectSpaceState::cast_motion(const RID &p_shape, const Transf
/// Returns the list of contacts pairs in this order: Local contact, other body contact
bool BulletPhysicsDirectSpaceState::collide_shape(RID p_shape, const Transform &p_shape_xform, float p_margin, Vector3 *r_results, int p_result_max, int &r_result_count, const Set<RID> &p_exclude, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas) {
- if (p_result_max <= 0)
+ if (p_result_max <= 0) {
return false;
+ }
ShapeBullet *shape = space->get_physics_server()->get_shape_owner()->getornull(p_shape);
@@ -650,8 +653,9 @@ void SpaceBullet::check_ghost_overlaps() {
btVector3 area_scale(area->get_bt_body_scale());
- if (!area->is_monitoring())
+ if (!area->is_monitoring()) {
continue;
+ }
/// 1. Reset all states
for (i = area->overlappingObjects.size() - 1; 0 <= i; --i) {
@@ -680,15 +684,18 @@ void SpaceBullet::check_ghost_overlaps() {
}
if (overlapped_bt_co->getUserIndex() == CollisionObjectBullet::TYPE_AREA) {
- if (!static_cast<AreaBullet *>(overlapped_bt_co->getUserPointer())->is_monitorable())
+ if (!static_cast<AreaBullet *>(overlapped_bt_co->getUserPointer())->is_monitorable()) {
continue;
- } else if (overlapped_bt_co->getUserIndex() != CollisionObjectBullet::TYPE_RIGID_BODY)
+ }
+ } else if (overlapped_bt_co->getUserIndex() != CollisionObjectBullet::TYPE_RIGID_BODY) {
continue;
+ }
// For each area shape
for (y = area->get_shape_count() - 1; 0 <= y; --y) {
- if (!area->get_bt_shape(y)->isConvex())
+ if (!area->get_bt_shape(y)->isConvex()) {
continue;
+ }
btTransform area_shape_treansform(area->get_bt_shape_transform(y));
area_shape_treansform.getOrigin() *= area_scale;
@@ -730,8 +737,9 @@ void SpaceBullet::check_ghost_overlaps() {
btCollisionAlgorithm *algorithm = dispatcher->findAlgorithm(&obA, &obB, nullptr, BT_CONTACT_POINT_ALGORITHMS);
- if (!algorithm)
+ if (!algorithm) {
continue;
+ }
GodotDeepPenetrationContactResultCallback contactPointResult(&obA, &obB);
algorithm->processCollision(&obA, &obB, dynamicsWorld->getDispatchInfo(), &contactPointResult);
@@ -749,8 +757,9 @@ void SpaceBullet::check_ghost_overlaps() {
} // ~For each area shape
collision_found:
- if (!hasOverlap)
+ if (!hasOverlap) {
continue;
+ }
indexOverlap = area->find_overlapping_object(otherObject);
if (-1 == indexOverlap) {
@@ -1195,8 +1204,9 @@ bool SpaceBullet::recover_from_penetration(RigidBodyBullet *p_body, const btTran
if (p_infinite_inertia && !otherObject->isStaticOrKinematicObject()) {
otherObject->activate(); // Force activation of hitten rigid, soft body
continue;
- } else if (!p_body->get_bt_collision_object()->checkCollideWith(otherObject) || !otherObject->checkCollideWith(p_body->get_bt_collision_object()))
+ } else if (!p_body->get_bt_collision_object()->checkCollideWith(otherObject) || !otherObject->checkCollideWith(p_body->get_bt_collision_object())) {
continue;
+ }
if (otherObject->getCollisionShape()->isCompound()) {
const btCompoundShape *cs = static_cast<const btCompoundShape *>(otherObject->getCollisionShape());
@@ -1384,8 +1394,9 @@ int SpaceBullet::recover_from_penetration_ray(RigidBodyBullet *p_body, const btT
if (p_infinite_inertia && !otherObject->isStaticOrKinematicObject()) {
otherObject->activate(); // Force activation of hitten rigid, soft body
continue;
- } else if (!p_body->get_bt_collision_object()->checkCollideWith(otherObject) || !otherObject->checkCollideWith(p_body->get_bt_collision_object()))
+ } else if (!p_body->get_bt_collision_object()->checkCollideWith(otherObject) || !otherObject->checkCollideWith(p_body->get_bt_collision_object())) {
continue;
+ }
if (otherObject->getCollisionShape()->isCompound()) {
const btCompoundShape *cs = static_cast<const btCompoundShape *>(otherObject->getCollisionShape());
diff --git a/modules/bullet/space_bullet.h b/modules/bullet/space_bullet.h
index 2dad965de8..5ff421ef52 100644
--- a/modules/bullet/space_bullet.h
+++ b/modules/bullet/space_bullet.h
@@ -169,8 +169,9 @@ public:
contactDebugCount = 0;
}
_FORCE_INLINE_ void add_debug_contact(const Vector3 &p_contact) {
- if (contactDebugCount < contactDebug.size())
+ if (contactDebugCount < contactDebug.size()) {
contactDebug.write[contactDebugCount++] = p_contact;
+ }
}
_FORCE_INLINE_ Vector<Vector3> get_debug_contacts() { return contactDebug; }
_FORCE_INLINE_ int get_debug_contact_count() { return contactDebugCount; }
diff --git a/modules/csg/csg.cpp b/modules/csg/csg.cpp
index ccd1b89fb5..df798623f9 100644
--- a/modules/csg/csg.cpp
+++ b/modules/csg/csg.cpp
@@ -42,8 +42,9 @@ inline static bool is_snapable(const Vector3 &p_point1, const Vector3 &p_point2,
inline static Vector2 interpolate_segment_uv(const Vector2 p_segement_points[2], const Vector2 p_uvs[2], const Vector2 &p_interpolation_point) {
float segment_length = (p_segement_points[1] - p_segement_points[0]).length();
- if (segment_length < CMP_EPSILON)
+ if (segment_length < CMP_EPSILON) {
return p_uvs[0];
+ }
float distance = (p_interpolation_point - p_segement_points[0]).length();
float fraction = distance / segment_length;
@@ -52,12 +53,15 @@ inline static Vector2 interpolate_segment_uv(const Vector2 p_segement_points[2],
}
inline static Vector2 interpolate_triangle_uv(const Vector2 p_vertices[3], const Vector2 p_uvs[3], const Vector2 &p_interpolation_point) {
- if (p_interpolation_point.distance_squared_to(p_vertices[0]) < CMP_EPSILON2)
+ if (p_interpolation_point.distance_squared_to(p_vertices[0]) < CMP_EPSILON2) {
return p_uvs[0];
- if (p_interpolation_point.distance_squared_to(p_vertices[1]) < CMP_EPSILON2)
+ }
+ if (p_interpolation_point.distance_squared_to(p_vertices[1]) < CMP_EPSILON2) {
return p_uvs[1];
- if (p_interpolation_point.distance_squared_to(p_vertices[2]) < CMP_EPSILON2)
+ }
+ if (p_interpolation_point.distance_squared_to(p_vertices[2]) < CMP_EPSILON2) {
return p_uvs[2];
+ }
Vector2 edge1 = p_vertices[1] - p_vertices[0];
Vector2 edge2 = p_vertices[2] - p_vertices[0];
@@ -69,8 +73,9 @@ inline static Vector2 interpolate_triangle_uv(const Vector2 p_vertices[3], const
float inter_on_edge1 = interpolation.dot(edge1);
float inter_on_edge2 = interpolation.dot(edge2);
float scale = (edge1_on_edge1 * edge2_on_edge2 - edge1_on_edge2 * edge1_on_edge2);
- if (scale == 0)
+ if (scale == 0) {
return p_uvs[0];
+ }
float v = (edge2_on_edge2 * inter_on_edge1 - edge1_on_edge2 * inter_on_edge2) / scale;
float w = (edge1_on_edge1 * inter_on_edge2 - edge1_on_edge2 * inter_on_edge1) / scale;
@@ -85,19 +90,22 @@ static inline bool ray_intersects_triangle(const Vector3 &p_from, const Vector3
Vector3 h = p_dir.cross(edge2);
real_t a = edge1.dot(h);
// Check if ray is parallel to triangle.
- if (Math::is_zero_approx(a))
+ if (Math::is_zero_approx(a)) {
return false;
+ }
real_t f = 1.0 / a;
Vector3 s = p_from - p_vertices[0];
real_t u = f * s.dot(h);
- if (u < 0.0 - p_tolerance || u > 1.0 + p_tolerance)
+ if (u < 0.0 - p_tolerance || u > 1.0 + p_tolerance) {
return false;
+ }
Vector3 q = s.cross(edge1);
real_t v = f * p_dir.dot(q);
- if (v < 0.0 - p_tolerance || u + v > 1.0 + p_tolerance)
+ if (v < 0.0 - p_tolerance || u + v > 1.0 + p_tolerance) {
return false;
+ }
// Ray intersects triangle.
// Calculate distance.
@@ -106,8 +114,9 @@ static inline bool ray_intersects_triangle(const Vector3 &p_from, const Vector3
if (t >= p_tolerance) {
r_intersection_point = p_from + p_dir * t;
return true;
- } else
+ } else {
return false;
+ }
}
inline bool is_point_in_triangle(const Vector3 &p_point, const Vector3 p_vertices[3], int p_shifted = 0) {
@@ -133,12 +142,14 @@ inline bool is_point_in_triangle(const Vector3 &p_point, const Vector3 p_vertice
lambda[2] = p_vertices[0].cross(p_vertices[1]).dot(p_point) / det;
// Point is in the plane if all lambdas sum to 1.
- if (!Math::is_equal_approx(lambda[0] + lambda[1] + lambda[2], 1))
+ if (!Math::is_equal_approx(lambda[0] + lambda[1] + lambda[2], 1)) {
return false;
+ }
// Point is inside the triangle if all lambdas are positive.
- if (lambda[0] < 0 || lambda[1] < 0 || lambda[2] < 0)
+ if (lambda[0] < 0 || lambda[1] < 0 || lambda[2] < 0) {
return false;
+ }
return true;
}
@@ -150,8 +161,9 @@ inline static bool are_segements_parallel(const Vector2 p_segment1_points[2], co
real_t segment2_length2 = segment2.dot(segment2);
real_t segment_onto_segment = segment2.dot(segment1);
- if (segment1_length2 < p_vertex_snap2 || segment2_length2 < p_vertex_snap2)
+ if (segment1_length2 < p_vertex_snap2 || segment2_length2 < p_vertex_snap2) {
return true;
+ }
real_t max_separation2;
if (segment1_length2 > segment2_length2) {
@@ -207,15 +219,17 @@ void CSGBrush::build_from_faces(const Vector<Vector3> &p_vertices, const Vector<
f.uvs[2] = ruv[i * 3 + 2];
}
- if (sc == vc / 3)
+ if (sc == vc / 3) {
f.smooth = rs[i];
- else
+ } else {
f.smooth = false;
+ }
- if (ic == vc / 3)
+ if (ic == vc / 3) {
f.invert = ri[i];
- else
+ } else {
f.invert = false;
+ }
if (mc == vc / 3) {
Ref<Material> mat = rm[i];
@@ -322,8 +336,9 @@ void CSGBrushOperation::merge_brushes(Operation p_operation, const CSGBrush &p_b
int outside_count = 0;
for (int i = 0; i < mesh_merge.faces.size(); i++) {
- if (mesh_merge.faces[i].inside)
+ if (mesh_merge.faces[i].inside) {
continue;
+ }
outside_count++;
}
@@ -332,8 +347,9 @@ void CSGBrushOperation::merge_brushes(Operation p_operation, const CSGBrush &p_b
outside_count = 0;
for (int i = 0; i < mesh_merge.faces.size(); i++) {
- if (mesh_merge.faces[i].inside)
+ if (mesh_merge.faces[i].inside) {
continue;
+ }
for (int j = 0; j < 3; j++) {
r_merged_brush.faces.write[outside_count].vertices[j] = mesh_merge.points[mesh_merge.faces[i].points[j]];
@@ -354,8 +370,9 @@ void CSGBrushOperation::merge_brushes(Operation p_operation, const CSGBrush &p_b
int inside_count = 0;
for (int i = 0; i < mesh_merge.faces.size(); i++) {
- if (!mesh_merge.faces[i].inside)
+ if (!mesh_merge.faces[i].inside) {
continue;
+ }
inside_count++;
}
@@ -364,8 +381,9 @@ void CSGBrushOperation::merge_brushes(Operation p_operation, const CSGBrush &p_b
inside_count = 0;
for (int i = 0; i < mesh_merge.faces.size(); i++) {
- if (!mesh_merge.faces[i].inside)
+ if (!mesh_merge.faces[i].inside) {
continue;
+ }
for (int j = 0; j < 3; j++) {
r_merged_brush.faces.write[inside_count].vertices[j] = mesh_merge.points[mesh_merge.faces[i].points[j]];
@@ -386,10 +404,12 @@ void CSGBrushOperation::merge_brushes(Operation p_operation, const CSGBrush &p_b
int face_count = 0;
for (int i = 0; i < mesh_merge.faces.size(); i++) {
- if (mesh_merge.faces[i].from_b && !mesh_merge.faces[i].inside)
+ if (mesh_merge.faces[i].from_b && !mesh_merge.faces[i].inside) {
continue;
- if (!mesh_merge.faces[i].from_b && mesh_merge.faces[i].inside)
+ }
+ if (!mesh_merge.faces[i].from_b && mesh_merge.faces[i].inside) {
continue;
+ }
face_count++;
}
@@ -398,10 +418,12 @@ void CSGBrushOperation::merge_brushes(Operation p_operation, const CSGBrush &p_b
face_count = 0;
for (int i = 0; i < mesh_merge.faces.size(); i++) {
- if (mesh_merge.faces[i].from_b && !mesh_merge.faces[i].inside)
+ if (mesh_merge.faces[i].from_b && !mesh_merge.faces[i].inside) {
continue;
- if (!mesh_merge.faces[i].from_b && mesh_merge.faces[i].inside)
+ }
+ if (!mesh_merge.faces[i].from_b && mesh_merge.faces[i].inside) {
continue;
+ }
for (int j = 0; j < 3; j++) {
r_merged_brush.faces.write[face_count].vertices[j] = mesh_merge.points[mesh_merge.faces[i].points[j]];
@@ -500,9 +522,11 @@ void CSGBrushOperation::MeshMerge::_add_distance(List<real_t> &r_intersectionsA,
List<real_t> &intersections = p_from_B ? r_intersectionsB : r_intersectionsA;
// Check if distance exists.
- for (const List<real_t>::Element *E = intersections.front(); E; E = E->next())
- if (Math::abs(**E - p_distance) < vertex_snap)
+ for (const List<real_t>::Element *E = intersections.front(); E; E = E->next()) {
+ if (Math::abs(**E - p_distance) < vertex_snap) {
return;
+ }
+ }
intersections.push_back(p_distance);
}
@@ -560,8 +584,9 @@ bool CSGBrushOperation::MeshMerge::_bvh_inside(FaceBVH *facebvhptr, int p_max_de
if ((current_normal - face_normal).length_squared() < CMP_EPSILON2 &&
is_point_in_triangle(face_center, current_points)) {
// Only add an intersection if checking a B face.
- if (face.from_b)
+ if (face.from_b) {
_add_distance(intersectionsA, intersectionsB, current_face.from_b, 0);
+ }
} else if (ray_intersects_triangle(face_center, face_normal, current_points, CMP_EPSILON, intersection_point)) {
real_t distance = (intersection_point - face_center).length();
_add_distance(intersectionsA, intersectionsB, current_face.from_b, distance);
@@ -607,14 +632,16 @@ bool CSGBrushOperation::MeshMerge::_bvh_inside(FaceBVH *facebvhptr, int p_max_de
if (level == 0) {
done = true;
break;
- } else
+ } else {
level--;
+ }
continue;
}
}
- if (done)
+ if (done) {
break;
+ }
}
// Inside if face normal intersects other faces an odd number of times.
@@ -667,8 +694,9 @@ void CSGBrushOperation::MeshMerge::mark_inside_faces() {
AABB intersection_aabb = aabb_a.intersection(aabb_b);
// Check if shape AABBs intersect.
- if (intersection_aabb.size == Vector3())
+ if (intersection_aabb.size == Vector3()) {
return;
+ }
Vector<FaceBVH *> bvhtrvec;
bvhtrvec.resize(faces.size());
@@ -683,11 +711,13 @@ void CSGBrushOperation::MeshMerge::mark_inside_faces() {
for (int i = 0; i < faces.size(); i++) {
// Check if face AABB intersects the intersection AABB.
- if (!intersection_aabb.intersects_inclusive(facebvh[i].aabb))
+ if (!intersection_aabb.intersects_inclusive(facebvh[i].aabb)) {
continue;
+ }
- if (_bvh_inside(facebvh, max_depth, max_alloc - 1, i))
+ if (_bvh_inside(facebvh, max_depth, max_alloc - 1, i)) {
faces.write[i].inside = true;
+ }
}
}
@@ -710,8 +740,9 @@ void CSGBrushOperation::MeshMerge::add_face(const Vector3 p_points[], const Vect
}
// Don't add degenerate faces.
- if (indices[0] == indices[2] || indices[0] == indices[1] || indices[1] == indices[2])
+ if (indices[0] == indices[2] || indices[0] == indices[1] || indices[1] == indices[2]) {
return;
+ }
MeshMerge::Face face;
face.from_b = p_from_b;
@@ -742,8 +773,9 @@ void CSGBrushOperation::MeshMerge::add_face(const Vector3 p_points[], const Vect
int CSGBrushOperation::Build2DFaces::_get_point_idx(const Vector2 &p_point) {
for (int vertex_idx = 0; vertex_idx < vertices.size(); ++vertex_idx) {
- if ((p_point - vertices[vertex_idx].point).length_squared() < vertex_snap2)
+ if ((p_point - vertices[vertex_idx].point).length_squared() < vertex_snap2) {
return vertex_idx;
+ }
}
return -1;
}
@@ -751,8 +783,9 @@ int CSGBrushOperation::Build2DFaces::_get_point_idx(const Vector2 &p_point) {
int CSGBrushOperation::Build2DFaces::_add_vertex(const Vertex2D &p_vertex) {
// Check if vertex exists.
int vertex_id = _get_point_idx(p_vertex.point);
- if (vertex_id != -1)
+ if (vertex_id != -1) {
return vertex_id;
+ }
vertices.push_back(p_vertex);
return vertices.size() - 1;
@@ -776,14 +809,16 @@ void CSGBrushOperation::Build2DFaces::_add_vertex_idx_sorted(Vector<int> &r_vert
// Sort along the axis with the greatest difference.
int axis = 0;
- if (Math::abs(new_point.x - first_point.x) < Math::abs(new_point.y - first_point.y))
+ if (Math::abs(new_point.x - first_point.x) < Math::abs(new_point.y - first_point.y)) {
axis = 1;
+ }
// Add it to the beginning or the end appropriately.
- if (new_point[axis] < first_point[axis])
+ if (new_point[axis] < first_point[axis]) {
r_vertex_indices.insert(0, p_new_vertex_index);
- else
+ } else {
r_vertex_indices.push_back(p_new_vertex_index);
+ }
return;
}
@@ -795,8 +830,9 @@ void CSGBrushOperation::Build2DFaces::_add_vertex_idx_sorted(Vector<int> &r_vert
// Determine axis being sorted against i.e. the axis with the greatest difference.
int axis = 0;
- if (Math::abs(last_point.x - first_point.x) < Math::abs(last_point.y - first_point.y))
+ if (Math::abs(last_point.x - first_point.x) < Math::abs(last_point.y - first_point.y)) {
axis = 1;
+ }
// Insert the point at the appropriate index.
for (int insert_idx = 0; insert_idx < r_vertex_indices.size(); ++insert_idx) {
@@ -814,8 +850,9 @@ void CSGBrushOperation::Build2DFaces::_add_vertex_idx_sorted(Vector<int> &r_vert
void CSGBrushOperation::Build2DFaces::_merge_faces(const Vector<int> &p_segment_indices) {
int segments = p_segment_indices.size() - 1;
- if (segments < 2)
+ if (segments < 2) {
return;
+ }
// Faces around an inner vertex are merged by moving the inner vertex to the first vertex.
for (int sorted_idx = 1; sorted_idx < segments; ++sorted_idx) {
@@ -853,8 +890,9 @@ void CSGBrushOperation::Build2DFaces::_merge_faces(const Vector<int> &p_segment_
// Skip flattened faces.
if (outer_edge_idx[0] == p_segment_indices[closest_idx] ||
- outer_edge_idx[1] == p_segment_indices[closest_idx])
+ outer_edge_idx[1] == p_segment_indices[closest_idx]) {
continue;
+ }
//Don't create degenerate triangles.
Vector2 edge1[2] = {
@@ -882,11 +920,13 @@ void CSGBrushOperation::Build2DFaces::_merge_faces(const Vector<int> &p_segment_
// Delete the old faces in reverse index order.
merge_faces_idx.sort();
merge_faces_idx.invert();
- for (int i = 0; i < merge_faces_idx.size(); ++i)
+ for (int i = 0; i < merge_faces_idx.size(); ++i) {
faces.remove(merge_faces_idx[i]);
+ }
- if (degenerate_points.size() == 0)
+ if (degenerate_points.size() == 0) {
continue;
+ }
// Split faces using degenerate points.
for (int face_idx = 0; face_idx < faces.size(); ++face_idx) {
@@ -914,8 +954,9 @@ void CSGBrushOperation::Build2DFaces::_merge_faces(const Vector<int> &p_segment_
break;
}
}
- if (existing)
+ if (existing) {
continue;
+ }
// Check if point is on an each edge.
for (int face_edge_idx = 0; face_edge_idx < 3; ++face_edge_idx) {
@@ -998,12 +1039,14 @@ void CSGBrushOperation::Build2DFaces::_find_edge_intersections(const Vector2 p_s
if (on_edge || Geometry::segment_intersects_segment_2d(p_segment_points[0], p_segment_points[1], edge_points[0], edge_points[1], &intersection_point)) {
// Check if intersection point is an edge point.
if ((intersection_point - edge_points[0]).length_squared() < vertex_snap2 ||
- (intersection_point - edge_points[1]).length_squared() < vertex_snap2)
+ (intersection_point - edge_points[1]).length_squared() < vertex_snap2) {
continue;
+ }
// Check if edge exists, by checking if the intersecting segment is parallel to the edge.
- if (are_segements_parallel(p_segment_points, edge_points, vertex_snap2))
+ if (are_segements_parallel(p_segment_points, edge_points, vertex_snap2)) {
continue;
+ }
// Add the intersection point as a new vertex.
Vertex2D new_vertex;
@@ -1032,8 +1075,9 @@ void CSGBrushOperation::Build2DFaces::_find_edge_intersections(const Vector2 p_s
// If opposite point is on the segemnt, add its index to segment indices too.
Vector2 closest_point = Geometry::get_closest_point_to_segment_2d(vertices[opposite_vertex_idx].point, p_segment_points);
- if ((closest_point - vertices[opposite_vertex_idx].point).length_squared() < vertex_snap2)
+ if ((closest_point - vertices[opposite_vertex_idx].point).length_squared() < vertex_snap2) {
_add_vertex_idx_sorted(r_segment_indices, opposite_vertex_idx);
+ }
// Create two new faces around the new edge and remove this face.
// The new edge is the last edge.
@@ -1080,8 +1124,9 @@ int CSGBrushOperation::Build2DFaces::_insert_point(const Vector2 &p_point) {
// Check if point is existing face vertex.
for (int i = 0; i < 3; ++i) {
- if ((p_point - face_vertices[i].point).length_squared() < vertex_snap2)
+ if ((p_point - face_vertices[i].point).length_squared() < vertex_snap2) {
return face.vertex_idx[i];
+ }
}
// Check if point is on an each edge.
@@ -1202,10 +1247,12 @@ void CSGBrushOperation::Build2DFaces::insert(const CSGBrush &p_brush, int p_face
} else {
Vector3 next_point_3D = p_brush.faces[p_face_idx].vertices[(i + 1) % 3];
- if (plane.has_point(next_point_3D))
+ if (plane.has_point(next_point_3D)) {
continue; // Next point is in plane, it will be added separately.
- if (plane.is_point_over(point_3D) == plane.is_point_over(next_point_3D))
+ }
+ if (plane.is_point_over(point_3D) == plane.is_point_over(next_point_3D)) {
continue; // Both points on the same side of the plane, ignore.
+ }
// Edge crosses the plane, find and add the intersection point.
Vector3 point_2D;
@@ -1330,8 +1377,9 @@ void CSGBrushOperation::update_faces(const CSGBrush &p_brush_a, const int p_face
p_collection.build2DFacesB[p_face_idx_b] = Build2DFaces();
has_degenerate = true;
}
- if (has_degenerate)
+ if (has_degenerate) {
return;
+ }
// Ensure B has points either side of or in the plane of A.
int in_plane_count = 0, over_count = 0, under_count = 0;
@@ -1339,16 +1387,18 @@ void CSGBrushOperation::update_faces(const CSGBrush &p_brush_a, const int p_face
ERR_FAIL_COND_MSG(plane_a.normal == Vector3(), "Couldn't form plane from Brush A face.");
for (int i = 0; i < 3; i++) {
- if (plane_a.has_point(vertices_b[i]))
+ if (plane_a.has_point(vertices_b[i])) {
in_plane_count++;
- else if (plane_a.is_point_over(vertices_b[i]))
+ } else if (plane_a.is_point_over(vertices_b[i])) {
over_count++;
- else
+ } else {
under_count++;
+ }
}
// If all points under or over the plane, there is no intesection.
- if (over_count == 3 || under_count == 3)
+ if (over_count == 3 || under_count == 3) {
return;
+ }
// Ensure A has points either side of or in the plane of B.
in_plane_count = 0;
@@ -1358,16 +1408,18 @@ void CSGBrushOperation::update_faces(const CSGBrush &p_brush_a, const int p_face
ERR_FAIL_COND_MSG(plane_b.normal == Vector3(), "Couldn't form plane from Brush B face.");
for (int i = 0; i < 3; i++) {
- if (plane_b.has_point(vertices_a[i]))
+ if (plane_b.has_point(vertices_a[i])) {
in_plane_count++;
- else if (plane_b.is_point_over(vertices_a[i]))
+ } else if (plane_b.is_point_over(vertices_a[i])) {
over_count++;
- else
+ } else {
under_count++;
+ }
}
// If all points under or over the plane, there is no intesection.
- if (over_count == 3 || under_count == 3)
+ if (over_count == 3 || under_count == 3) {
return;
+ }
// Check for intersection using the SAT theorem.
{
@@ -1379,8 +1431,9 @@ void CSGBrushOperation::update_faces(const CSGBrush &p_brush_a, const int p_face
Vector3 axis_b = (vertices_b[j] - vertices_b[(j + 1) % 3]).normalized();
Vector3 sep_axis = axis_a.cross(axis_b);
- if (sep_axis == Vector3())
+ if (sep_axis == Vector3()) {
continue; //colineal
+ }
sep_axis.normalize();
real_t min_a = 1e20, max_a = -1e20;
diff --git a/modules/csg/csg_gizmos.cpp b/modules/csg/csg_gizmos.cpp
index c9569a6d9c..9fa7dc1340 100644
--- a/modules/csg/csg_gizmos.cpp
+++ b/modules/csg/csg_gizmos.cpp
@@ -126,8 +126,9 @@ void CSGShape3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Ca
d = Math::stepify(d, Node3DEditor::get_singleton()->get_translate_snap());
}
- if (d < 0.001)
+ if (d < 0.001) {
d = 0.001;
+ }
s->set_radius(d);
}
@@ -144,8 +145,9 @@ void CSGShape3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Ca
d = Math::stepify(d, Node3DEditor::get_singleton()->get_translate_snap());
}
- if (d < 0.001)
+ if (d < 0.001) {
d = 0.001;
+ }
switch (p_idx) {
case 0:
@@ -172,13 +174,15 @@ void CSGShape3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Ca
d = Math::stepify(d, Node3DEditor::get_singleton()->get_translate_snap());
}
- if (d < 0.001)
+ if (d < 0.001) {
d = 0.001;
+ }
- if (p_idx == 0)
+ if (p_idx == 0) {
s->set_radius(d);
- else if (p_idx == 1)
+ } else if (p_idx == 1) {
s->set_height(d * 2.0);
+ }
}
if (Object::cast_to<CSGTorus3D>(cs)) {
@@ -193,13 +197,15 @@ void CSGShape3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Ca
d = Math::stepify(d, Node3DEditor::get_singleton()->get_translate_snap());
}
- if (d < 0.001)
+ if (d < 0.001) {
d = 0.001;
+ }
- if (p_idx == 0)
+ if (p_idx == 0) {
s->set_inner_radius(d);
- else if (p_idx == 1)
+ } else if (p_idx == 1) {
s->set_outer_radius(d);
+ }
}
}
@@ -261,10 +267,11 @@ void CSGShape3DGizmoPlugin::commit_handle(EditorNode3DGizmo *p_gizmo, int p_idx,
if (Object::cast_to<CSGCylinder3D>(cs)) {
CSGCylinder3D *s = Object::cast_to<CSGCylinder3D>(cs);
if (p_cancel) {
- if (p_idx == 0)
+ if (p_idx == 0) {
s->set_radius(p_restore);
- else
+ } else {
s->set_height(p_restore);
+ }
return;
}
@@ -285,10 +292,11 @@ void CSGShape3DGizmoPlugin::commit_handle(EditorNode3DGizmo *p_gizmo, int p_idx,
if (Object::cast_to<CSGTorus3D>(cs)) {
CSGTorus3D *s = Object::cast_to<CSGTorus3D>(cs);
if (p_cancel) {
- if (p_idx == 0)
+ if (p_idx == 0) {
s->set_inner_radius(p_restore);
- else
+ } else {
s->set_outer_radius(p_restore);
+ }
return;
}
diff --git a/modules/csg/csg_shape.cpp b/modules/csg/csg_shape.cpp
index a5ebb1f437..7df65b04c4 100644
--- a/modules/csg/csg_shape.cpp
+++ b/modules/csg/csg_shape.cpp
@@ -32,13 +32,15 @@
#include "scene/3d/path_3d.h"
void CSGShape3D::set_use_collision(bool p_enable) {
- if (use_collision == p_enable)
+ if (use_collision == p_enable) {
return;
+ }
use_collision = p_enable;
- if (!is_inside_tree() || !is_root_shape())
+ if (!is_inside_tree() || !is_root_shape()) {
return;
+ }
if (use_collision) {
root_collision_shape.instance();
@@ -86,10 +88,11 @@ uint32_t CSGShape3D::get_collision_mask() const {
void CSGShape3D::set_collision_mask_bit(int p_bit, bool p_value) {
uint32_t mask = get_collision_mask();
- if (p_value)
+ if (p_value) {
mask |= 1 << p_bit;
- else
+ } else {
mask &= ~(1 << p_bit);
+ }
set_collision_mask(mask);
}
@@ -99,10 +102,11 @@ bool CSGShape3D::get_collision_mask_bit(int p_bit) const {
void CSGShape3D::set_collision_layer_bit(int p_bit, bool p_value) {
uint32_t mask = get_collision_layer();
- if (p_value)
+ if (p_value) {
mask |= 1 << p_bit;
- else
+ } else {
mask &= ~(1 << p_bit);
+ }
set_collision_layer(mask);
}
@@ -123,8 +127,9 @@ float CSGShape3D::get_snap() const {
}
void CSGShape3D::_make_dirty() {
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
if (dirty) {
return;
@@ -151,14 +156,17 @@ CSGBrush *CSGShape3D::_get_brush() {
for (int i = 0; i < get_child_count(); i++) {
CSGShape3D *child = Object::cast_to<CSGShape3D>(get_child(i));
- if (!child)
+ if (!child) {
continue;
- if (!child->is_visible_in_tree())
+ }
+ if (!child->is_visible_in_tree()) {
continue;
+ }
CSGBrush *n2 = child->_get_brush();
- if (!n2)
+ if (!n2) {
continue;
+ }
if (!n) {
n = memnew(CSGBrush);
@@ -192,10 +200,11 @@ CSGBrush *CSGShape3D::_get_brush() {
AABB aabb;
for (int i = 0; i < n->faces.size(); i++) {
for (int j = 0; j < 3; j++) {
- if (i == 0 && j == 0)
+ if (i == 0 && j == 0) {
aabb.position = n->faces[i].vertices[j];
- else
+ } else {
aabb.expand_to(n->faces[i].vertices[j]);
+ }
}
}
node_aabb = aabb;
@@ -266,8 +275,9 @@ void CSGShape3D::mikktSetTSpaceDefault(const SMikkTSpaceContext *pContext, const
}
void CSGShape3D::_update_shape() {
- if (parent)
+ if (parent) {
return;
+ }
set_base(RID());
root_mesh.unref(); //byebye root mesh
@@ -422,8 +432,9 @@ void CSGShape3D::_update_shape() {
have_tangents = genTangSpaceDefault(&msc);
}
- if (surfaces[i].last_added == 0)
+ if (surfaces[i].last_added == 0) {
continue;
+ }
// and convert to surface array
Array array;
@@ -512,8 +523,9 @@ void CSGShape3D::_notification(int p_what) {
}
if (p_what == NOTIFICATION_EXIT_TREE) {
- if (parent)
+ if (parent) {
parent->_make_dirty();
+ }
parent = nullptr;
if (use_collision && is_root_shape() && root_collision_instance.is_valid()) {
@@ -666,8 +678,9 @@ void CSGPrimitive3D::_bind_methods() {
}
void CSGPrimitive3D::set_invert_faces(bool p_invert) {
- if (invert_faces == p_invert)
+ if (invert_faces == p_invert) {
return;
+ }
invert_faces = p_invert;
@@ -685,8 +698,9 @@ CSGPrimitive3D::CSGPrimitive3D() {
/////////////////////
CSGBrush *CSGMesh3D::_build_brush() {
- if (!mesh.is_valid())
+ if (!mesh.is_valid()) {
return nullptr;
+ }
Vector<Vector3> vertices;
Vector<bool> smooth;
@@ -707,8 +721,9 @@ CSGBrush *CSGMesh3D::_build_brush() {
}
Vector<Vector3> avertices = arrays[Mesh::ARRAY_VERTEX];
- if (avertices.size() == 0)
+ if (avertices.size() == 0) {
continue;
+ }
const Vector3 *vr = avertices.ptr();
@@ -822,8 +837,9 @@ CSGBrush *CSGMesh3D::_build_brush() {
}
}
- if (vertices.size() == 0)
+ if (vertices.size() == 0) {
return nullptr;
+ }
return _create_brush_from_arrays(vertices, uvs, smooth, materials);
}
@@ -834,8 +850,9 @@ void CSGMesh3D::_mesh_changed() {
}
void CSGMesh3D::set_material(const Ref<Material> &p_material) {
- if (material == p_material)
+ if (material == p_material) {
return;
+ }
material = p_material;
_make_dirty();
}
@@ -856,8 +873,9 @@ void CSGMesh3D::_bind_methods() {
}
void CSGMesh3D::set_mesh(const Ref<Mesh> &p_mesh) {
- if (mesh == p_mesh)
+ if (mesh == p_mesh) {
return;
+ }
if (mesh.is_valid()) {
mesh->disconnect("changed", callable_mp(this, &CSGMesh3D::_mesh_changed));
}
@@ -1119,10 +1137,11 @@ CSGBrush *CSGBox3D::_build_brush() {
v[2] = v[1] * (1 - 2 * (j & 1));
for (int k = 0; k < 3; k++) {
- if (i < 3)
+ if (i < 3) {
face_points[j][(i + k) % 3] = v[k];
- else
+ } else {
face_points[3 - j][(i + k) % 3] = -v[k];
+ }
}
}
@@ -1480,8 +1499,9 @@ CSGBrush *CSGTorus3D::_build_brush() {
float min_radius = inner_radius;
float max_radius = outer_radius;
- if (min_radius == max_radius)
+ if (min_radius == max_radius) {
return nullptr; //sorry, can't
+ }
if (min_radius > max_radius) {
SWAP(min_radius, max_radius);
@@ -1698,8 +1718,9 @@ CSGTorus3D::CSGTorus3D() {
CSGBrush *CSGPolygon3D::_build_brush() {
// set our bounding box
- if (polygon.size() < 3)
+ if (polygon.size() < 3) {
return nullptr;
+ }
Vector<Point2> final_polygon = polygon;
@@ -1709,8 +1730,9 @@ CSGBrush *CSGPolygon3D::_build_brush() {
Vector<int> triangles = Geometry::triangulate_polygon(final_polygon);
- if (triangles.size() < 3)
+ if (triangles.size() < 3) {
return nullptr;
+ }
Path3D *path = nullptr;
Ref<Curve3D> curve;
@@ -1724,28 +1746,35 @@ CSGBrush *CSGPolygon3D::_build_brush() {
final_polygon_min = p;
final_polygon_max = final_polygon_min;
} else {
- if (p.x < final_polygon_min.x)
+ if (p.x < final_polygon_min.x) {
final_polygon_min.x = p.x;
- if (p.y < final_polygon_min.y)
+ }
+ if (p.y < final_polygon_min.y) {
final_polygon_min.y = p.y;
+ }
- if (p.x > final_polygon_max.x)
+ if (p.x > final_polygon_max.x) {
final_polygon_max.x = p.x;
- if (p.y > final_polygon_max.y)
+ }
+ if (p.y > final_polygon_max.y) {
final_polygon_max.y = p.y;
+ }
}
}
Vector2 final_polygon_size = final_polygon_max - final_polygon_min;
if (mode == MODE_PATH) {
- if (!has_node(path_node))
+ if (!has_node(path_node)) {
return nullptr;
+ }
Node *n = get_node(path_node);
- if (!n)
+ if (!n) {
return nullptr;
+ }
path = Object::cast_to<Path3D>(n);
- if (!path)
+ if (!path) {
return nullptr;
+ }
if (path != path_cache) {
if (path_cache) {
@@ -1761,10 +1790,12 @@ CSGBrush *CSGPolygon3D::_build_brush() {
path_cache = nullptr;
}
curve = path->get_curve();
- if (curve.is_null())
+ if (curve.is_null()) {
return nullptr;
- if (curve->get_baked_length() <= 0)
+ }
+ if (curve->get_baked_length() <= 0) {
return nullptr;
+ }
}
CSGBrush *brush = memnew(CSGBrush);
diff --git a/modules/cvtt/image_compress_cvtt.cpp b/modules/cvtt/image_compress_cvtt.cpp
index 40e0f1a08f..2a4f836478 100644
--- a/modules/cvtt/image_compress_cvtt.cpp
+++ b/modules/cvtt/image_compress_cvtt.cpp
@@ -137,8 +137,9 @@ static void _digest_job_queue(void *p_job_queue) {
}
void image_compress_cvtt(Image *p_image, float p_lossy_quality, Image::UsedChannels p_channels) {
- if (p_image->get_format() >= Image::FORMAT_BPTC_RGBA)
+ if (p_image->get_format() >= Image::FORMAT_BPTC_RGBA) {
return; //do not compress, already compressed
+ }
int w = p_image->get_width();
int h = p_image->get_height();
@@ -153,16 +154,17 @@ void image_compress_cvtt(Image *p_image, float p_lossy_quality, Image::UsedChann
cvtt::Options options;
uint32_t flags = cvtt::Flags::Fastest;
- if (p_lossy_quality > 0.85)
+ if (p_lossy_quality > 0.85) {
flags = cvtt::Flags::Ultra;
- else if (p_lossy_quality > 0.75)
+ } else if (p_lossy_quality > 0.75) {
flags = cvtt::Flags::Better;
- else if (p_lossy_quality > 0.55)
+ } else if (p_lossy_quality > 0.55) {
flags = cvtt::Flags::Default;
- else if (p_lossy_quality > 0.35)
+ } else if (p_lossy_quality > 0.35) {
flags = cvtt::Flags::Fast;
- else if (p_lossy_quality > 0.15)
+ } else if (p_lossy_quality > 0.15) {
flags = cvtt::Flags::Faster;
+ }
flags |= cvtt::Flags::BC7_RespectPunchThrough;
diff --git a/modules/dds/texture_loader_dds.cpp b/modules/dds/texture_loader_dds.cpp
index 052f2c5e01..ba425371a8 100644
--- a/modules/dds/texture_loader_dds.cpp
+++ b/modules/dds/texture_loader_dds.cpp
@@ -95,17 +95,20 @@ static const DDSFormatInfo dds_format_info[DDS_MAX] = {
};
RES ResourceFormatDDS::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) {
- if (r_error)
+ if (r_error) {
*r_error = ERR_CANT_OPEN;
+ }
Error err;
FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err);
- if (!f)
+ if (!f) {
return RES();
+ }
FileAccessRef fref(f);
- if (r_error)
+ if (r_error) {
*r_error = ERR_FILE_CORRUPT;
+ }
ERR_FAIL_COND_V_MSG(err != OK, RES(), "Unable to open DDS texture file '" + p_path + "'.");
@@ -119,8 +122,9 @@ RES ResourceFormatDDS::load(const String &p_path, const String &p_original_path,
uint32_t mipmaps = f->get_32();
//skip 11
- for (int i = 0; i < 11; i++)
+ for (int i = 0; i < 11; i++) {
f->get_32();
+ }
//validate
@@ -155,8 +159,9 @@ RES ResourceFormatDDS::load(const String &p_path, const String &p_original_path,
*/
//must avoid this later
- while (f->get_position() < 128)
+ while (f->get_position() < 128) {
f->get_8();
+ }
DDSFormat dds_format;
@@ -200,8 +205,9 @@ RES ResourceFormatDDS::load(const String &p_path, const String &p_original_path,
ERR_FAIL_V_MSG(RES(), "Unrecognized or unsupported color layout in DDS '" + p_path + "'.");
}
- if (!(flags & DDSD_MIPMAPCOUNT))
+ if (!(flags & DDSD_MIPMAPCOUNT)) {
mipmaps = 1;
+ }
Vector<uint8_t> src_data;
@@ -241,8 +247,9 @@ RES ResourceFormatDDS::load(const String &p_path, const String &p_original_path,
int colsize = 3;
for (int i = 0; i < 256; i++) {
- if (palette[i * 4 + 3] < 255)
+ if (palette[i * 4 + 3] < 255) {
colsize = 4;
+ }
}
int w2 = width;
@@ -264,8 +271,9 @@ RES ResourceFormatDDS::load(const String &p_path, const String &p_original_path,
wb[dst_ofs + 0] = palette[src_ofs + 2];
wb[dst_ofs + 1] = palette[src_ofs + 1];
wb[dst_ofs + 2] = palette[src_ofs + 0];
- if (colsize == 4)
+ if (colsize == 4) {
wb[dst_ofs + 3] = palette[src_ofs + 3];
+ }
}
} else {
//uncompressed generic...
@@ -278,10 +286,11 @@ RES ResourceFormatDDS::load(const String &p_path, const String &p_original_path,
size += w * h * info.block_size;
}
- if (dds_format == DDS_BGR565)
+ if (dds_format == DDS_BGR565) {
size = size * 3 / 2;
- else if (dds_format == DDS_BGR5A1)
+ } else if (dds_format == DDS_BGR5A1) {
size = size * 2;
+ }
src_data.resize(size);
uint8_t *wb = src_data.ptrw();
@@ -404,8 +413,9 @@ RES ResourceFormatDDS::load(const String &p_path, const String &p_original_path,
Ref<ImageTexture> texture = memnew(ImageTexture);
texture->create_from_image(img);
- if (r_error)
+ if (r_error) {
*r_error = OK;
+ }
return texture;
}
@@ -419,7 +429,8 @@ bool ResourceFormatDDS::handles_type(const String &p_type) const {
}
String ResourceFormatDDS::get_resource_type(const String &p_path) const {
- if (p_path.get_extension().to_lower() == "dds")
+ if (p_path.get_extension().to_lower() == "dds") {
return "ImageTexture";
+ }
return "";
}
diff --git a/modules/enet/networked_multiplayer_enet.cpp b/modules/enet/networked_multiplayer_enet.cpp
index a53c2a2364..4e7698b67c 100644
--- a/modules/enet/networked_multiplayer_enet.cpp
+++ b/modules/enet/networked_multiplayer_enet.cpp
@@ -214,8 +214,9 @@ void NetworkedMultiplayerENet::poll() {
ENetEvent event;
/* Keep servicing until there are no available events left in queue. */
while (true) {
- if (!host || !active) // Might have been disconnected while emitting a notification
+ if (!host || !active) { // Might have been disconnected while emitting a notification
return;
+ }
int ret = enet_host_service(host, &event, 0);
@@ -259,13 +260,15 @@ void NetworkedMultiplayerENet::poll() {
if (server) {
// Do not notify other peers when server_relay is disabled.
- if (!server_relay)
+ if (!server_relay) {
break;
+ }
// Someone connected, notify all the peers available
for (Map<int, ENetPeer *>::Element *E = peer_map.front(); E; E = E->next()) {
- if (E->key() == *new_id)
+ if (E->key() == *new_id) {
continue;
+ }
// Send existing peers to new peer
ENetPacket *packet = enet_packet_create(nullptr, 8, ENET_PACKET_FLAG_RELIABLE);
encode_uint32(SYSMSG_ADD_PEER, &packet->data[0]);
@@ -303,8 +306,9 @@ void NetworkedMultiplayerENet::poll() {
} else if (server_relay) {
// Server just received a client disconnect and is in relay mode, notify everyone else.
for (Map<int, ENetPeer *>::Element *E = peer_map.front(); E; E = E->next()) {
- if (E->key() == *id)
+ if (E->key() == *id) {
continue;
+ }
ENetPacket *packet = enet_packet_create(nullptr, 8, ENET_PACKET_FLAG_RELIABLE);
encode_uint32(SYSMSG_REMOVE_PEER, &packet->data[0]);
@@ -373,8 +377,9 @@ void NetworkedMultiplayerENet::poll() {
incoming_packets.push_back(packet);
// And make copies for sending
for (Map<int, ENetPeer *>::Element *E = peer_map.front(); E; E = E->next()) {
- if (uint32_t(E->key()) == source) // Do not resend to self
+ if (uint32_t(E->key()) == source) { // Do not resend to self
continue;
+ }
ENetPacket *packet2 = enet_packet_create(packet.packet->data, packet.packet->dataLength, packet.packet->flags);
@@ -386,8 +391,9 @@ void NetworkedMultiplayerENet::poll() {
// And make copies for sending
for (Map<int, ENetPeer *>::Element *E = peer_map.front(); E; E = E->next()) {
- if (uint32_t(E->key()) == source || E->key() == -target) // Do not resend to self, also do not send to excluded
+ if (uint32_t(E->key()) == source || E->key() == -target) { // Do not resend to self, also do not send to excluded
continue;
+ }
ENetPacket *packet2 = enet_packet_create(packet.packet->data, packet.packet->dataLength, packet.packet->flags);
@@ -485,8 +491,9 @@ void NetworkedMultiplayerENet::disconnect_peer(int p_peer, bool now) {
}
}
- if (id)
+ if (id) {
memdelete(id);
+ }
emit_signal("peer_disconnected", p_peer);
peer_map.erase(p_peer);
@@ -522,10 +529,11 @@ Error NetworkedMultiplayerENet::put_packet(const uint8_t *p_buffer, int p_buffer
switch (transfer_mode) {
case TRANSFER_MODE_UNRELIABLE: {
- if (always_ordered)
+ if (always_ordered) {
packet_flags = 0;
- else
+ } else {
packet_flags = ENET_PACKET_FLAG_UNSEQUENCED;
+ }
channel = SYSCH_UNRELIABLE;
} break;
case TRANSFER_MODE_UNRELIABLE_ORDERED: {
@@ -538,8 +546,9 @@ Error NetworkedMultiplayerENet::put_packet(const uint8_t *p_buffer, int p_buffer
} break;
}
- if (transfer_channel > SYSCH_CONFIG)
+ if (transfer_channel > SYSCH_CONFIG) {
channel = transfer_channel;
+ }
Map<int, ENetPeer *>::Element *E = nullptr;
@@ -563,8 +572,9 @@ Error NetworkedMultiplayerENet::put_packet(const uint8_t *p_buffer, int p_buffer
int exclude = -target_peer;
for (Map<int, ENetPeer *>::Element *F = peer_map.front(); F; F = F->next()) {
- if (F->key() == exclude) // Exclude packet
+ if (F->key() == exclude) { // Exclude packet
continue;
+ }
ENetPacket *packet2 = enet_packet_create(packet->data, packet->dataLength, packet_flags);
@@ -685,11 +695,13 @@ size_t NetworkedMultiplayerENet::enet_compress(void *context, const ENetBuffer *
}
int ret = Compression::compress(enet->dst_compressor_mem.ptrw(), enet->src_compressor_mem.ptr(), ofs, mode);
- if (ret < 0)
+ if (ret < 0) {
return 0;
+ }
- if (ret > int(outLimit))
+ if (ret > int(outLimit)) {
return 0; // Do not bother
+ }
copymem(outData, enet->dst_compressor_mem.ptr(), ret);
diff --git a/modules/enet/register_types.cpp b/modules/enet/register_types.cpp
index e5e9628c26..18051f756a 100644
--- a/modules/enet/register_types.cpp
+++ b/modules/enet/register_types.cpp
@@ -45,6 +45,7 @@ void register_enet_types() {
}
void unregister_enet_types() {
- if (enet_ok)
+ if (enet_ok) {
enet_deinitialize();
+ }
}
diff --git a/modules/etc/image_etc.cpp b/modules/etc/image_etc.cpp
index 6bf4a7ef47..9b6d8a2d35 100644
--- a/modules/etc/image_etc.cpp
+++ b/modules/etc/image_etc.cpp
@@ -127,8 +127,9 @@ static void _compress_etc(Image *p_img, float p_lossy_quality, bool force_etc1_f
Ref<Image> img = p_img->duplicate();
- if (img->get_format() != Image::FORMAT_RGBA8)
+ if (img->get_format() != Image::FORMAT_RGBA8) {
img->convert(Image::FORMAT_RGBA8); //still uses RGBA to convert
+ }
if (img->has_mipmaps()) {
if (next_power_of_2(imgw) != imgw || next_power_of_2(imgh) != imgh) {
@@ -165,12 +166,13 @@ static void _compress_etc(Image *p_img, float p_lossy_quality, bool force_etc1_f
int encoding_time = 0;
float effort = 0.0; //default, reasonable time
- if (p_lossy_quality > 0.75)
+ if (p_lossy_quality > 0.75) {
effort = 0.4;
- else if (p_lossy_quality > 0.85)
+ } else if (p_lossy_quality > 0.85) {
effort = 0.6;
- else if (p_lossy_quality > 0.95)
+ } else if (p_lossy_quality > 0.95) {
effort = 0.8;
+ }
Etc::ErrorMetric error_metric = Etc::ErrorMetric::RGBX; // NOTE: we can experiment with other error metrics
Etc::Image::Format etc2comp_etc_format = _image_format_to_etc2comp_format(etc_format);
diff --git a/modules/etc/texture_loader_pkm.cpp b/modules/etc/texture_loader_pkm.cpp
index 78768c5ba9..c40e9612a8 100644
--- a/modules/etc/texture_loader_pkm.cpp
+++ b/modules/etc/texture_loader_pkm.cpp
@@ -43,17 +43,20 @@ struct ETC1Header {
};
RES ResourceFormatPKM::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) {
- if (r_error)
+ if (r_error) {
*r_error = ERR_CANT_OPEN;
+ }
Error err;
FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err);
- if (!f)
+ if (!f) {
return RES();
+ }
FileAccessRef fref(f);
- if (r_error)
+ if (r_error) {
*r_error = ERR_FILE_CORRUPT;
+ }
ERR_FAIL_COND_V_MSG(err != OK, RES(), "Unable to open PKM texture file '" + p_path + "'.");
@@ -86,8 +89,9 @@ RES ResourceFormatPKM::load(const String &p_path, const String &p_original_path,
Ref<ImageTexture> texture = memnew(ImageTexture);
texture->create_from_image(img);
- if (r_error)
+ if (r_error) {
*r_error = OK;
+ }
f->close();
memdelete(f);
@@ -103,7 +107,8 @@ bool ResourceFormatPKM::handles_type(const String &p_type) const {
}
String ResourceFormatPKM::get_resource_type(const String &p_path) const {
- if (p_path.get_extension().to_lower() == "pkm")
+ if (p_path.get_extension().to_lower() == "pkm") {
return "ImageTexture";
+ }
return "";
}
diff --git a/modules/gdnative/gdnative.cpp b/modules/gdnative/gdnative.cpp
index 7a231ac903..3d747ba41e 100644
--- a/modules/gdnative/gdnative.cpp
+++ b/modules/gdnative/gdnative.cpp
@@ -114,8 +114,9 @@ void GDNativeLibrary::_get_property_list(List<PropertyInfo> *p_list) const {
// set entries
List<String> entry_key_list;
- if (config_file->has_section("entry"))
+ if (config_file->has_section("entry")) {
config_file->get_section_keys("entry", &entry_key_list);
+ }
for (List<String>::Element *E = entry_key_list.front(); E; E = E->next()) {
String key = E->get();
@@ -131,8 +132,9 @@ void GDNativeLibrary::_get_property_list(List<PropertyInfo> *p_list) const {
// set dependencies
List<String> dependency_key_list;
- if (config_file->has_section("dependencies"))
+ if (config_file->has_section("dependencies")) {
config_file->get_section_keys("dependencies", &dependency_key_list);
+ }
for (List<String>::Element *E = dependency_key_list.front(); E; E = E->next()) {
String key = E->get();
@@ -156,8 +158,9 @@ void GDNativeLibrary::set_config_file(Ref<ConfigFile> p_config_file) {
{
List<String> entry_keys;
- if (p_config_file->has_section("entry"))
+ if (p_config_file->has_section("entry")) {
p_config_file->get_section_keys("entry", &entry_keys);
+ }
for (List<String>::Element *E = entry_keys.front(); E; E = E->next()) {
String key = E->get();
@@ -187,8 +190,9 @@ void GDNativeLibrary::set_config_file(Ref<ConfigFile> p_config_file) {
{
List<String> dependency_keys;
- if (p_config_file->has_section("dependencies"))
+ if (p_config_file->has_section("dependencies")) {
p_config_file->get_section_keys("dependencies", &dependency_keys);
+ }
for (List<String>::Element *E = dependency_keys.front(); E; E = E->next()) {
String key = E->get();
@@ -513,8 +517,9 @@ bool GDNativeLibraryResourceLoader::handles_type(const String &p_type) const {
String GDNativeLibraryResourceLoader::get_resource_type(const String &p_path) const {
String el = p_path.get_extension().to_lower();
- if (el == "gdnlib")
+ if (el == "gdnlib") {
return "GDNativeLibrary";
+ }
return "";
}
diff --git a/modules/gdnative/gdnative/gdnative.cpp b/modules/gdnative/gdnative/gdnative.cpp
index 234dbe9534..6b2b5b80a4 100644
--- a/modules/gdnative/gdnative/gdnative.cpp
+++ b/modules/gdnative/gdnative/gdnative.cpp
@@ -91,8 +91,9 @@ godot_variant GDAPI godot_method_bind_call(godot_method_bind *p_method_bind, god
godot_class_constructor GDAPI godot_get_class_constructor(const char *p_classname) {
ClassDB::ClassInfo *class_info = ClassDB::classes.getptr(StringName(p_classname));
- if (class_info)
+ if (class_info) {
return (godot_class_constructor)class_info->creation_func;
+ }
return nullptr;
}
@@ -175,8 +176,9 @@ void *godot_get_class_tag(const godot_string_name *p_class) {
}
godot_object *godot_object_cast_to(const godot_object *p_object, void *p_class_tag) {
- if (!p_object)
+ if (!p_object) {
return nullptr;
+ }
Object *o = (Object *)p_object;
return o->is_class_ptr(p_class_tag) ? (godot_object *)o : nullptr;
diff --git a/modules/gdnative/gdnative_library_editor_plugin.cpp b/modules/gdnative/gdnative_library_editor_plugin.cpp
index 278bc7217d..2a9836329e 100644
--- a/modules/gdnative/gdnative_library_editor_plugin.cpp
+++ b/modules/gdnative/gdnative_library_editor_plugin.cpp
@@ -128,8 +128,9 @@ void GDNativeLibraryEditor::_on_item_button(Object *item, int column, int id) {
if (id == BUTTON_SELECT_LIBRARY || id == BUTTON_SELECT_DEPENDENCES) {
EditorFileDialog::FileMode mode = EditorFileDialog::FILE_MODE_OPEN_FILE;
- if (id == BUTTON_SELECT_DEPENDENCES)
+ if (id == BUTTON_SELECT_DEPENDENCES) {
mode = EditorFileDialog::FILE_MODE_OPEN_FILES;
+ }
file_dialog->set_meta("target", target);
file_dialog->set_meta("section", section);
@@ -192,10 +193,11 @@ void GDNativeLibraryEditor::_on_create_new_entry() {
}
void GDNativeLibraryEditor::_set_target_value(const String &section, const String &target, Variant file) {
- if (section == "entry")
+ if (section == "entry") {
entry_configs[target].library = file;
- else if (section == "dependencies")
+ } else if (section == "dependencies") {
entry_configs[target].dependencies = file;
+ }
_translate_to_config_file();
_update_tree();
}
@@ -237,8 +239,9 @@ void GDNativeLibraryEditor::_translate_to_config_file() {
for (Map<String, NativePlatformConfig>::Element *E = platforms.front(); E; E = E->next()) {
for (List<String>::Element *it = E->value().entries.front(); it; it = it->next()) {
String target = E->key() + "." + it->get();
- if (entry_configs[target].library.empty() && entry_configs[target].dependencies.empty())
+ if (entry_configs[target].library.empty() && entry_configs[target].dependencies.empty()) {
continue;
+ }
config->set_value("entry", target, entry_configs[target].library);
config->set_value("dependencies", target, entry_configs[target].dependencies);
@@ -371,8 +374,9 @@ GDNativeLibraryEditor::GDNativeLibraryEditor() {
void GDNativeLibraryEditorPlugin::edit(Object *p_node) {
Ref<GDNativeLibrary> new_library = Object::cast_to<GDNativeLibrary>(p_node);
- if (new_library.is_valid())
+ if (new_library.is_valid()) {
library_editor->edit(new_library);
+ }
}
bool GDNativeLibraryEditorPlugin::handles(Object *p_node) const {
@@ -385,8 +389,9 @@ void GDNativeLibraryEditorPlugin::make_visible(bool p_visible) {
EditorNode::get_singleton()->make_bottom_panel_item_visible(library_editor);
} else {
- if (library_editor->is_visible_in_tree())
+ if (library_editor->is_visible_in_tree()) {
EditorNode::get_singleton()->hide_bottom_panel();
+ }
button->hide();
}
}
diff --git a/modules/gdnative/gdnative_library_singleton_editor.cpp b/modules/gdnative/gdnative_library_singleton_editor.cpp
index 27f18c91a8..409b6cbffe 100644
--- a/modules/gdnative/gdnative_library_singleton_editor.cpp
+++ b/modules/gdnative/gdnative_library_singleton_editor.cpp
@@ -135,19 +135,22 @@ void GDNativeLibrarySingletonEditor::_update_libraries() {
}
// The singletons list changed, we must update the settings
- if (updated_disabled.size() != singletons_disabled.size())
+ if (updated_disabled.size() != singletons_disabled.size()) {
ProjectSettings::get_singleton()->set("gdnative/singletons_disabled", updated_disabled);
+ }
updating = false;
}
void GDNativeLibrarySingletonEditor::_item_edited() {
- if (updating)
+ if (updating) {
return;
+ }
TreeItem *item = libraries->get_edited();
- if (!item)
+ if (!item) {
return;
+ }
bool enabled = item->get_range(1);
String path = item->get_metadata(0);
@@ -165,8 +168,9 @@ void GDNativeLibrarySingletonEditor::_item_edited() {
if (enabled) {
disabled_paths.erase(path);
} else {
- if (disabled_paths.find(path) == -1)
+ if (disabled_paths.find(path) == -1) {
disabled_paths.push_back(path);
+ }
}
undo_redo->create_action(enabled ? TTR("Enabled GDNative Singleton") : TTR("Disabled GDNative Singleton"));
diff --git a/modules/gdnative/nativescript/godot_nativescript.cpp b/modules/gdnative/nativescript/godot_nativescript.cpp
index ee944ee7cb..1bdac0dcb2 100644
--- a/modules/gdnative/nativescript/godot_nativescript.cpp
+++ b/modules/gdnative/nativescript/godot_nativescript.cpp
@@ -204,8 +204,9 @@ void GDAPI godot_nativescript_register_signal(void *p_gdnative_handle, const cha
void GDAPI *godot_nativescript_get_userdata(godot_object *p_instance) {
Object *instance = (Object *)p_instance;
- if (!instance)
+ if (!instance) {
return nullptr;
+ }
if (instance->get_script_instance() && instance->get_script_instance()->get_language() == NativeScriptLanguage::get_singleton()) {
return ((NativeScriptInstance *)instance->get_script_instance())->userdata;
}
@@ -320,8 +321,9 @@ const void GDAPI *godot_nativescript_get_type_tag(const godot_object *p_object)
return nullptr;
}
- if (script->get_script_desc())
+ if (script->get_script_desc()) {
return script->get_script_desc()->type_tag;
+ }
}
return nullptr;
diff --git a/modules/gdnative/nativescript/nativescript.cpp b/modules/gdnative/nativescript/nativescript.cpp
index fe9496702a..f3dfd0b68e 100644
--- a/modules/gdnative/nativescript/nativescript.cpp
+++ b/modules/gdnative/nativescript/nativescript.cpp
@@ -184,8 +184,9 @@ bool NativeScript::can_instance() const {
Ref<Script> NativeScript::get_base_script() const {
NativeScriptDesc *script_data = get_script_desc();
- if (!script_data)
+ if (!script_data) {
return Ref<Script>();
+ }
NativeScript *script = (NativeScript *)NSL->create_script();
Ref<NativeScript> ns = Ref<NativeScript>(script);
@@ -199,8 +200,9 @@ Ref<Script> NativeScript::get_base_script() const {
StringName NativeScript::get_instance_base_type() const {
NativeScriptDesc *script_data = get_script_desc();
- if (!script_data)
+ if (!script_data) {
return "";
+ }
return script_data->base_native_type;
}
@@ -272,8 +274,9 @@ bool NativeScript::has_method(const StringName &p_method) const {
NativeScriptDesc *script_data = get_script_desc();
while (script_data) {
- if (script_data->methods.has(p_method))
+ if (script_data->methods.has(p_method)) {
return true;
+ }
script_data = script_data->base_data;
}
@@ -283,14 +286,16 @@ bool NativeScript::has_method(const StringName &p_method) const {
MethodInfo NativeScript::get_method_info(const StringName &p_method) const {
NativeScriptDesc *script_data = get_script_desc();
- if (!script_data)
+ if (!script_data) {
return MethodInfo();
+ }
while (script_data) {
Map<StringName, NativeScriptDesc::Method>::Element *M = script_data->methods.find(p_method);
- if (M)
+ if (M) {
return M->get().info;
+ }
script_data = script_data->base_data;
}
@@ -304,8 +309,9 @@ bool NativeScript::is_valid() const {
bool NativeScript::is_tool() const {
NativeScriptDesc *script_data = get_script_desc();
- if (script_data)
+ if (script_data) {
return script_data->is_tool;
+ }
return false;
}
@@ -318,8 +324,9 @@ bool NativeScript::has_script_signal(const StringName &p_signal) const {
NativeScriptDesc *script_data = get_script_desc();
while (script_data) {
- if (script_data->signals_.has(p_signal))
+ if (script_data->signals_.has(p_signal)) {
return true;
+ }
script_data = script_data->base_data;
}
return false;
@@ -328,8 +335,9 @@ bool NativeScript::has_script_signal(const StringName &p_signal) const {
void NativeScript::get_script_signal_list(List<MethodInfo> *r_signals) const {
NativeScriptDesc *script_data = get_script_desc();
- if (!script_data)
+ if (!script_data) {
return;
+ }
Set<MethodInfo> signals_;
@@ -354,8 +362,9 @@ bool NativeScript::get_property_default_value(const StringName &p_property, Vari
P = script_data->properties.find(p_property);
script_data = script_data->base_data;
}
- if (!P)
+ if (!P) {
return false;
+ }
r_value = P.get().default_value;
return true;
@@ -367,8 +376,9 @@ void NativeScript::update_exports() {
void NativeScript::get_script_method_list(List<MethodInfo> *p_list) const {
NativeScriptDesc *script_data = get_script_desc();
- if (!script_data)
+ if (!script_data) {
return;
+ }
Set<MethodInfo> methods;
@@ -990,17 +1000,20 @@ String NativeScriptInstance::to_string(bool *r_valid) {
Variant ret = call(CoreStringNames::get_singleton()->_to_string, nullptr, 0, ce);
if (ce.error == Callable::CallError::CALL_OK) {
if (ret.get_type() != Variant::STRING) {
- if (r_valid)
+ if (r_valid) {
*r_valid = false;
+ }
ERR_FAIL_V_MSG(String(), "Wrong type for " + CoreStringNames::get_singleton()->_to_string + ", must be a String.");
}
- if (r_valid)
+ if (r_valid) {
*r_valid = true;
+ }
return ret.operator String();
}
}
- if (r_valid)
+ if (r_valid) {
*r_valid = false;
+ }
return String();
}
@@ -1102,8 +1115,9 @@ void NativeScriptInstance::call_multilevel_reversed(const StringName &p_method,
NativeScriptInstance::~NativeScriptInstance() {
NativeScriptDesc *script_data = GET_SCRIPT_DESC();
- if (!script_data)
+ if (!script_data) {
return;
+ }
script_data->destroy_func.destroy_func((godot_object *)owner, script_data->destroy_func.method_data, userdata);
@@ -1155,25 +1169,30 @@ void NativeScriptLanguage::_unload_stuff(bool p_reload) {
for (Map<StringName, NativeScriptDesc>::Element *C = classes.front(); C; C = C->next()) {
// free property stuff first
for (OrderedHashMap<StringName, NativeScriptDesc::Property>::Element P = C->get().properties.front(); P; P = P.next()) {
- if (P.get().getter.free_func)
+ if (P.get().getter.free_func) {
P.get().getter.free_func(P.get().getter.method_data);
+ }
- if (P.get().setter.free_func)
+ if (P.get().setter.free_func) {
P.get().setter.free_func(P.get().setter.method_data);
+ }
}
// free method stuff
for (Map<StringName, NativeScriptDesc::Method>::Element *M = C->get().methods.front(); M; M = M->next()) {
- if (M->get().method.free_func)
+ if (M->get().method.free_func) {
M->get().method.free_func(M->get().method.method_data);
+ }
}
// free constructor/destructor
- if (C->get().create_func.free_func)
+ if (C->get().create_func.free_func) {
C->get().create_func.free_func(C->get().create_func.method_data);
+ }
- if (C->get().destroy_func.free_func)
+ if (C->get().destroy_func.free_func) {
C->get().destroy_func.free_func(C->get().destroy_func.method_data);
+ }
}
erase_and_unload.insert(lib_path, gdn);
@@ -1407,8 +1426,9 @@ int NativeScriptLanguage::profiling_get_accumulated_data(ProfilingInfo *p_info_a
int current = 0;
for (Map<StringName, ProfileData>::Element *d = profile_data.front(); d; d = d->next()) {
- if (current >= p_info_max)
+ if (current >= p_info_max) {
break;
+ }
p_info_arr[current].call_count = d->get().call_count;
p_info_arr[current].self_time = d->get().self_time;
@@ -1430,8 +1450,9 @@ int NativeScriptLanguage::profiling_get_frame_data(ProfilingInfo *p_info_arr, in
int current = 0;
for (Map<StringName, ProfileData>::Element *d = profile_data.front(); d; d = d->next()) {
- if (current >= p_info_max)
+ if (current >= p_info_max) {
break;
+ }
if (d->get().last_frame_call_count) {
p_info_arr[current].call_count = d->get().last_frame_call_count;
@@ -1508,14 +1529,16 @@ void NativeScriptLanguage::unregister_binding_functions(int p_idx) {
for (Set<Vector<void *> *>::Element *E = binding_instances.front(); E; E = E->next()) {
Vector<void *> &binding_data = *E->get();
- if (p_idx < binding_data.size() && binding_data[p_idx] && binding_functions[p_idx].second.free_instance_binding_data)
+ if (p_idx < binding_data.size() && binding_data[p_idx] && binding_functions[p_idx].second.free_instance_binding_data) {
binding_functions[p_idx].second.free_instance_binding_data(binding_functions[p_idx].second.data, binding_data[p_idx]);
+ }
}
binding_functions.write[p_idx].first = false;
- if (binding_functions[p_idx].second.free_func)
+ if (binding_functions[p_idx].second.free_func) {
binding_functions[p_idx].second.free_func(binding_functions[p_idx].second.data);
+ }
}
void *NativeScriptLanguage::get_instance_binding_data(int p_idx, Object *p_object) {
@@ -1525,8 +1548,9 @@ void *NativeScriptLanguage::get_instance_binding_data(int p_idx, Object *p_objec
Vector<void *> *binding_data = (Vector<void *> *)p_object->get_script_instance_binding(lang_idx);
- if (!binding_data)
+ if (!binding_data) {
return nullptr; // should never happen.
+ }
if (binding_data->size() <= p_idx) {
// okay, add new elements here.
@@ -1564,14 +1588,16 @@ void *NativeScriptLanguage::alloc_instance_binding_data(Object *p_object) {
}
void NativeScriptLanguage::free_instance_binding_data(void *p_data) {
- if (!p_data)
+ if (!p_data) {
return;
+ }
Vector<void *> &binding_data = *(Vector<void *> *)p_data;
for (int i = 0; i < binding_data.size(); i++) {
- if (!binding_data[i])
+ if (!binding_data[i]) {
continue;
+ }
if (binding_functions[i].first && binding_functions[i].second.free_instance_binding_data) {
binding_functions[i].second.free_instance_binding_data(binding_functions[i].second.data, binding_data[i]);
@@ -1586,17 +1612,20 @@ void NativeScriptLanguage::free_instance_binding_data(void *p_data) {
void NativeScriptLanguage::refcount_incremented_instance_binding(Object *p_object) {
void *data = p_object->get_script_instance_binding(lang_idx);
- if (!data)
+ if (!data) {
return;
+ }
Vector<void *> &binding_data = *(Vector<void *> *)data;
for (int i = 0; i < binding_data.size(); i++) {
- if (!binding_data[i])
+ if (!binding_data[i]) {
continue;
+ }
- if (!binding_functions[i].first)
+ if (!binding_functions[i].first) {
continue;
+ }
if (binding_functions[i].second.refcount_incremented_instance_binding) {
binding_functions[i].second.refcount_incremented_instance_binding(binding_data[i], p_object);
@@ -1607,19 +1636,22 @@ void NativeScriptLanguage::refcount_incremented_instance_binding(Object *p_objec
bool NativeScriptLanguage::refcount_decremented_instance_binding(Object *p_object) {
void *data = p_object->get_script_instance_binding(lang_idx);
- if (!data)
+ if (!data) {
return true;
+ }
Vector<void *> &binding_data = *(Vector<void *> *)data;
bool can_die = true;
for (int i = 0; i < binding_data.size(); i++) {
- if (!binding_data[i])
+ if (!binding_data[i]) {
continue;
+ }
- if (!binding_functions[i].first)
+ if (!binding_functions[i].first) {
continue;
+ }
if (binding_functions[i].second.refcount_decremented_instance_binding) {
can_die = can_die && binding_functions[i].second.refcount_decremented_instance_binding(binding_data[i], p_object);
@@ -1640,13 +1672,15 @@ void NativeScriptLanguage::set_global_type_tag(int p_idx, StringName p_class_nam
}
const void *NativeScriptLanguage::get_global_type_tag(int p_idx, StringName p_class_name) const {
- if (!global_type_tags.has(p_idx))
+ if (!global_type_tags.has(p_idx)) {
return nullptr;
+ }
const HashMap<StringName, const void *> &tags = global_type_tags[p_idx];
- if (!tags.has(p_class_name))
+ if (!tags.has(p_class_name)) {
return nullptr;
+ }
const void *tag = tags.get(p_class_name);
@@ -1682,8 +1716,9 @@ void NativeScriptLanguage::init_library(const Ref<GDNativeLibrary> &lib) {
library_classes.insert(lib_path, Map<StringName, NativeScriptDesc>());
- if (!library_script_users.has(lib_path))
+ if (!library_script_users.has(lib_path)) {
library_script_users.insert(lib_path, Set<NativeScript *>());
+ }
void *proc_ptr;
@@ -1792,16 +1827,20 @@ String NativeScriptLanguage::get_global_class_name(const String &p_path, String
if (!p_path.empty()) {
Ref<NativeScript> script = ResourceLoader::load(p_path, "NativeScript");
if (script.is_valid()) {
- if (r_base_type)
+ if (r_base_type) {
*r_base_type = script->get_instance_base_type();
- if (r_icon_path)
+ }
+ if (r_icon_path) {
*r_icon_path = script->get_script_class_icon_path();
+ }
return script->get_script_class_name();
}
- if (r_base_type)
+ if (r_base_type) {
*r_base_type = String();
- if (r_icon_path)
+ }
+ if (r_icon_path) {
*r_icon_path = String();
+ }
}
return String();
}
@@ -1815,8 +1854,9 @@ void NativeReloadNode::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_WM_FOCUS_OUT: {
- if (unloaded)
+ if (unloaded) {
break;
+ }
MutexLock lock(NSL->mutex);
NSL->_unload_stuff(true);
@@ -1848,8 +1888,9 @@ void NativeReloadNode::_notification(int p_what) {
} break;
case NOTIFICATION_WM_FOCUS_IN: {
- if (!unloaded)
+ if (!unloaded) {
break;
+ }
MutexLock lock(NSL->mutex);
Set<StringName> libs_to_remove;
@@ -1891,8 +1932,9 @@ void NativeReloadNode::_notification(int p_what) {
for (Set<NativeScript *>::Element *S = U->get().front(); S; S = S->next()) {
NativeScript *script = S->get();
- if (script->placeholders.size() == 0)
+ if (script->placeholders.size() == 0) {
continue;
+ }
for (Set<PlaceHolderScriptInstance *>::Element *P = script->placeholders.front(); P; P = P->next()) {
script->_update_placeholder(P->get());
@@ -1928,8 +1970,9 @@ bool ResourceFormatLoaderNativeScript::handles_type(const String &p_type) const
String ResourceFormatLoaderNativeScript::get_resource_type(const String &p_path) const {
String el = p_path.get_extension().to_lower();
- if (el == "gdns")
+ if (el == "gdns") {
return "NativeScript";
+ }
return "";
}
diff --git a/modules/gdnative/pluginscript/pluginscript_loader.cpp b/modules/gdnative/pluginscript/pluginscript_loader.cpp
index 7ce124c16a..4feee4f4a5 100644
--- a/modules/gdnative/pluginscript/pluginscript_loader.cpp
+++ b/modules/gdnative/pluginscript/pluginscript_loader.cpp
@@ -40,8 +40,9 @@ ResourceFormatLoaderPluginScript::ResourceFormatLoaderPluginScript(PluginScriptL
}
RES ResourceFormatLoaderPluginScript::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) {
- if (r_error)
+ if (r_error) {
*r_error = ERR_FILE_CANT_OPEN;
+ }
PluginScript *script = memnew(PluginScript);
script->init(_language);
@@ -55,8 +56,9 @@ RES ResourceFormatLoaderPluginScript::load(const String &p_path, const String &p
script->reload();
- if (r_error)
+ if (r_error) {
*r_error = OK;
+ }
return scriptres;
}
@@ -71,8 +73,9 @@ bool ResourceFormatLoaderPluginScript::handles_type(const String &p_type) const
String ResourceFormatLoaderPluginScript::get_resource_type(const String &p_path) const {
String el = p_path.get_extension().to_lower();
- if (el == _language->get_extension())
+ if (el == _language->get_extension()) {
return _language->get_type();
+ }
return "";
}
diff --git a/modules/gdnative/pluginscript/pluginscript_script.cpp b/modules/gdnative/pluginscript/pluginscript_script.cpp
index d659ade876..87c6288806 100644
--- a/modules/gdnative/pluginscript/pluginscript_script.cpp
+++ b/modules/gdnative/pluginscript/pluginscript_script.cpp
@@ -154,10 +154,12 @@ Ref<Script> PluginScript::get_base_script() const {
}
StringName PluginScript::get_instance_base_type() const {
- if (_native_parent)
+ if (_native_parent) {
return _native_parent;
- if (_ref_base_parent.is_valid())
+ }
+ if (_ref_base_parent.is_valid()) {
return _ref_base_parent->get_instance_base_type();
+ }
return StringName();
}
@@ -226,8 +228,9 @@ String PluginScript::get_source_code() const {
}
void PluginScript::set_source_code(const String &p_code) {
- if (_source == p_code)
+ if (_source == p_code) {
return;
+ }
_source = p_code;
}
@@ -241,11 +244,13 @@ Error PluginScript::reload(bool p_keep_state) {
_valid = false;
String basedir = _path;
- if (basedir == "")
+ if (basedir == "") {
basedir = get_path();
+ }
- if (basedir != "")
+ if (basedir != "") {
basedir = basedir.get_base_dir();
+ }
if (_data) {
_desc->finish(_data);
@@ -471,11 +476,11 @@ void PluginScript::get_script_signal_list(List<MethodInfo> *r_signals) const {
int PluginScript::get_member_line(const StringName &p_member) const {
#ifdef TOOLS_ENABLED
- if (_member_lines.has(p_member))
+ if (_member_lines.has(p_member)) {
return _member_lines[p_member];
- else
+ }
#endif
- return -1;
+ return -1;
}
Vector<ScriptNetData> PluginScript::get_rpc_methods() const {
@@ -494,15 +499,17 @@ uint16_t PluginScript::get_rpc_method_id(const StringName &p_method) const {
StringName PluginScript::get_rpc_method(const uint16_t p_rpc_method_id) const {
ASSERT_SCRIPT_VALID_V(StringName());
- if (p_rpc_method_id >= _rpc_methods.size())
+ if (p_rpc_method_id >= _rpc_methods.size()) {
return StringName();
+ }
return _rpc_methods[p_rpc_method_id].name;
}
MultiplayerAPI::RPCMode PluginScript::get_rpc_mode_by_id(const uint16_t p_rpc_method_id) const {
ASSERT_SCRIPT_VALID_V(MultiplayerAPI::RPC_MODE_DISABLED);
- if (p_rpc_method_id >= _rpc_methods.size())
+ if (p_rpc_method_id >= _rpc_methods.size()) {
return MultiplayerAPI::RPC_MODE_DISABLED;
+ }
return _rpc_methods[p_rpc_method_id].mode;
}
@@ -527,15 +534,17 @@ uint16_t PluginScript::get_rset_property_id(const StringName &p_property) const
StringName PluginScript::get_rset_property(const uint16_t p_rset_property_id) const {
ASSERT_SCRIPT_VALID_V(StringName());
- if (p_rset_property_id >= _rpc_variables.size())
+ if (p_rset_property_id >= _rpc_variables.size()) {
return StringName();
+ }
return _rpc_variables[p_rset_property_id].name;
}
MultiplayerAPI::RPCMode PluginScript::get_rset_mode_by_id(const uint16_t p_rset_property_id) const {
ASSERT_SCRIPT_VALID_V(MultiplayerAPI::RPC_MODE_DISABLED);
- if (p_rset_property_id >= _rpc_variables.size())
+ if (p_rset_property_id >= _rpc_variables.size()) {
return MultiplayerAPI::RPC_MODE_DISABLED;
+ }
return _rpc_variables[p_rset_property_id].mode;
}
diff --git a/modules/gdnative/register_types.cpp b/modules/gdnative/register_types.cpp
index bffbb86526..136af5bd1e 100644
--- a/modules/gdnative/register_types.cpp
+++ b/modules/gdnative/register_types.cpp
@@ -254,8 +254,9 @@ void register_gdnative_types() {
for (int i = 0; i < singletons.size(); i++) {
String path = singletons[i];
- if (excluded.has(path))
+ if (excluded.has(path)) {
continue;
+ }
Ref<GDNativeLibrary> lib = ResourceLoader::load(path);
Ref<GDNative> singleton;
diff --git a/modules/gdnative/videodecoder/video_stream_gdnative.cpp b/modules/gdnative/videodecoder/video_stream_gdnative.cpp
index 476f44b185..9d9c5b6473 100644
--- a/modules/gdnative/videodecoder/video_stream_gdnative.cpp
+++ b/modules/gdnative/videodecoder/video_stream_gdnative.cpp
@@ -208,10 +208,12 @@ VideoStreamPlaybackGDNative::~VideoStreamPlaybackGDNative() {
}
void VideoStreamPlaybackGDNative::cleanup() {
- if (data_struct)
+ if (data_struct) {
interface->destructor(data_struct);
- if (pcm)
+ }
+ if (pcm) {
memfree(pcm);
+ }
pcm = nullptr;
time = 0;
num_channels = -1;
@@ -257,8 +259,9 @@ void VideoStreamPlaybackGDNative::stop() {
void VideoStreamPlaybackGDNative::seek(float p_time) {
ERR_FAIL_COND(interface == nullptr);
interface->seek(data_struct, p_time);
- if (p_time < time)
+ if (p_time < time) {
seek_backward = true;
+ }
time = p_time;
// reset audio buffers
memset(pcm, 0, num_channels * AUX_BUFFER_SIZE * sizeof(float));
@@ -320,12 +323,14 @@ int VideoStreamPlaybackGDNative::get_mix_rate() const {
Ref<VideoStreamPlayback> VideoStreamGDNative::instance_playback() {
Ref<VideoStreamPlaybackGDNative> pb = memnew(VideoStreamPlaybackGDNative);
VideoDecoderGDNative *decoder = decoder_server.get_decoder(file.get_extension().to_lower());
- if (decoder == nullptr)
+ if (decoder == nullptr) {
return nullptr;
+ }
pb->set_interface(decoder->interface);
pb->set_audio_track(audio_track);
- if (pb->open_file(file))
+ if (pb->open_file(file)) {
return pb;
+ }
return nullptr;
}
@@ -382,7 +387,8 @@ bool ResourceFormatLoaderVideoStreamGDNative::handles_type(const String &p_type)
String ResourceFormatLoaderVideoStreamGDNative::get_resource_type(const String &p_path) const {
String el = p_path.get_extension().to_lower();
- if (VideoDecoderServer::get_instance()->get_extensions().has(el))
+ if (VideoDecoderServer::get_instance()->get_extensions().has(el)) {
return "VideoStreamGDNative";
+ }
return "";
}
diff --git a/modules/gdnative/videodecoder/video_stream_gdnative.h b/modules/gdnative/videodecoder/video_stream_gdnative.h
index 2da63e96d6..53017a6a97 100644
--- a/modules/gdnative/videodecoder/video_stream_gdnative.h
+++ b/modules/gdnative/videodecoder/video_stream_gdnative.h
@@ -86,8 +86,9 @@ public:
}
VideoDecoderGDNative *get_decoder(const String &extension) {
- if (extensions.size() == 0 || !extensions.has(extension))
+ if (extensions.size() == 0 || !extensions.has(extension)) {
return nullptr;
+ }
return decoders[extensions[extension]];
}
diff --git a/modules/gdnavigation/gd_navigation_server.cpp b/modules/gdnavigation/gd_navigation_server.cpp
index 5aea9f8b9f..c80cdcfeab 100644
--- a/modules/gdnavigation/gd_navigation_server.cpp
+++ b/modules/gdnavigation/gd_navigation_server.cpp
@@ -249,8 +249,9 @@ COMMAND_2(region_set_map, RID, p_region, RID, p_map) {
ERR_FAIL_COND(region == nullptr);
if (region->get_map() != nullptr) {
- if (region->get_map()->get_self() == p_map)
+ if (region->get_map()->get_self() == p_map) {
return; // Pointless
+ }
region->get_map()->remove_region(region);
region->set_map(nullptr);
@@ -303,8 +304,9 @@ COMMAND_2(agent_set_map, RID, p_agent, RID, p_map) {
ERR_FAIL_COND(agent == nullptr);
if (agent->get_map()) {
- if (agent->get_map()->get_self() == p_map)
+ if (agent->get_map()->get_self() == p_map) {
return; // Pointless
+ }
agent->get_map()->remove_agent(agent);
}
diff --git a/modules/gdnavigation/nav_map.cpp b/modules/gdnavigation/nav_map.cpp
index e55a3deb8f..c7df6dc1fb 100644
--- a/modules/gdnavigation/nav_map.cpp
+++ b/modules/gdnavigation/nav_map.cpp
@@ -145,8 +145,9 @@ Vector<Vector3> NavMap::get_path(Vector3 p_origin, Vector3 p_destination, bool p
gd::NavigationPoly *least_cost_poly = &navigation_polys[least_cost_id];
const gd::Edge &edge = least_cost_poly->poly->edges[i];
- if (!edge.other_polygon)
+ if (!edge.other_polygon) {
continue;
+ }
#ifdef USE_ENTRY_POINT
Vector3 edge_line[2] = {
@@ -343,15 +344,17 @@ Vector<Vector3> NavMap::get_path(Vector3 p_origin, Vector3 p_destination, bool p
}
}
- if (p->prev_navigation_poly_id != -1)
+ if (p->prev_navigation_poly_id != -1) {
p = &navigation_polys[p->prev_navigation_poly_id];
- else
+ } else {
// The end
p = nullptr;
+ }
}
- if (path[path.size() - 1] != begin_point)
+ if (path[path.size() - 1] != begin_point) {
path.push_back(begin_point);
+ }
path.invert();
@@ -711,8 +714,9 @@ void NavMap::sync() {
if (agents_dirty) {
std::vector<RVO::Agent *> raw_agents;
raw_agents.reserve(agents.size());
- for (size_t i(0); i < agents.size(); i++)
+ for (size_t i(0); i < agents.size(); i++) {
raw_agents.push_back(agents[i]->get_agent());
+ }
rvo.buildAgentTree(raw_agents);
}
@@ -746,12 +750,14 @@ void NavMap::dispatch_callbacks() {
void NavMap::clip_path(const std::vector<gd::NavigationPoly> &p_navigation_polys, Vector<Vector3> &path, const gd::NavigationPoly *from_poly, const Vector3 &p_to_point, const gd::NavigationPoly *p_to_poly) const {
Vector3 from = path[path.size() - 1];
- if (from.distance_to(p_to_point) < CMP_EPSILON)
+ if (from.distance_to(p_to_point) < CMP_EPSILON) {
return;
+ }
Plane cut_plane;
cut_plane.normal = (from - p_to_point).cross(up);
- if (cut_plane.normal == Vector3())
+ if (cut_plane.normal == Vector3()) {
return;
+ }
cut_plane.normal.normalize();
cut_plane.d = cut_plane.normal.dot(from);
diff --git a/modules/gdnavigation/nav_region.cpp b/modules/gdnavigation/nav_region.cpp
index 3dff19cd65..51fba67cc3 100644
--- a/modules/gdnavigation/nav_region.cpp
+++ b/modules/gdnavigation/nav_region.cpp
@@ -70,13 +70,15 @@ void NavRegion::update_polygons() {
return;
}
- if (mesh.is_null())
+ if (mesh.is_null()) {
return;
+ }
Vector<Vector3> vertices = mesh->get_vertices();
int len = vertices.size();
- if (len == 0)
+ if (len == 0) {
return;
+ }
const Vector3 *vertices_r = vertices.ptr();
diff --git a/modules/gdnavigation/navigation_mesh_editor_plugin.cpp b/modules/gdnavigation/navigation_mesh_editor_plugin.cpp
index 379131864e..5fe1060aae 100644
--- a/modules/gdnavigation/navigation_mesh_editor_plugin.cpp
+++ b/modules/gdnavigation/navigation_mesh_editor_plugin.cpp
@@ -69,8 +69,9 @@ void NavigationMeshEditor::_bake_pressed() {
}
void NavigationMeshEditor::_clear_pressed() {
- if (node)
+ if (node) {
NavigationMeshGenerator::get_singleton()->clear(node->get_navigation_mesh());
+ }
button_bake->set_pressed(false);
bake_info->set_text("");
diff --git a/modules/gdnavigation/navigation_mesh_generator.cpp b/modules/gdnavigation/navigation_mesh_generator.cpp
index 78818fd990..7dc08fbf29 100644
--- a/modules/gdnavigation/navigation_mesh_generator.cpp
+++ b/modules/gdnavigation/navigation_mesh_generator.cpp
@@ -74,8 +74,9 @@ void NavigationMeshGenerator::_add_mesh(const Ref<Mesh> &p_mesh, const Transform
for (int i = 0; i < p_mesh->get_surface_count(); i++) {
current_vertex_count = p_verticies.size() / 3;
- if (p_mesh->surface_get_primitive_type(i) != Mesh::PRIMITIVE_TRIANGLES)
+ if (p_mesh->surface_get_primitive_type(i) != Mesh::PRIMITIVE_TRIANGLES) {
continue;
+ }
int index_count = 0;
if (p_mesh->surface_get_format(i) & Mesh::ARRAY_FORMAT_INDEX) {
@@ -314,8 +315,9 @@ void NavigationMeshGenerator::_build_recast_navigation_mesh(
rcContext ctx;
#ifdef TOOLS_ENABLED
- if (ep)
+ if (ep) {
ep->step(TTR("Setting up Configuration..."), 1);
+ }
#endif
const float *verts = vertices.ptr();
@@ -351,14 +353,16 @@ void NavigationMeshGenerator::_build_recast_navigation_mesh(
cfg.bmax[2] = bmax[2];
#ifdef TOOLS_ENABLED
- if (ep)
+ if (ep) {
ep->step(TTR("Calculating grid size..."), 2);
+ }
#endif
rcCalcGridSize(cfg.bmin, cfg.bmax, cfg.cs, &cfg.width, &cfg.height);
#ifdef TOOLS_ENABLED
- if (ep)
+ if (ep) {
ep->step(TTR("Creating heightfield..."), 3);
+ }
#endif
hf = rcAllocHeightfield();
@@ -366,8 +370,9 @@ void NavigationMeshGenerator::_build_recast_navigation_mesh(
ERR_FAIL_COND(!rcCreateHeightfield(&ctx, *hf, cfg.width, cfg.height, cfg.bmin, cfg.bmax, cfg.cs, cfg.ch));
#ifdef TOOLS_ENABLED
- if (ep)
+ if (ep) {
ep->step(TTR("Marking walkable triangles..."), 4);
+ }
#endif
{
Vector<unsigned char> tri_areas;
@@ -381,16 +386,20 @@ void NavigationMeshGenerator::_build_recast_navigation_mesh(
ERR_FAIL_COND(!rcRasterizeTriangles(&ctx, verts, nverts, tris, tri_areas.ptr(), ntris, *hf, cfg.walkableClimb));
}
- if (p_nav_mesh->get_filter_low_hanging_obstacles())
+ if (p_nav_mesh->get_filter_low_hanging_obstacles()) {
rcFilterLowHangingWalkableObstacles(&ctx, cfg.walkableClimb, *hf);
- if (p_nav_mesh->get_filter_ledge_spans())
+ }
+ if (p_nav_mesh->get_filter_ledge_spans()) {
rcFilterLedgeSpans(&ctx, cfg.walkableHeight, cfg.walkableClimb, *hf);
- if (p_nav_mesh->get_filter_walkable_low_height_spans())
+ }
+ if (p_nav_mesh->get_filter_walkable_low_height_spans()) {
rcFilterWalkableLowHeightSpans(&ctx, cfg.walkableHeight, *hf);
+ }
#ifdef TOOLS_ENABLED
- if (ep)
+ if (ep) {
ep->step(TTR("Constructing compact heightfield..."), 5);
+ }
#endif
chf = rcAllocCompactHeightfield();
@@ -402,15 +411,17 @@ void NavigationMeshGenerator::_build_recast_navigation_mesh(
hf = nullptr;
#ifdef TOOLS_ENABLED
- if (ep)
+ if (ep) {
ep->step(TTR("Eroding walkable area..."), 6);
+ }
#endif
ERR_FAIL_COND(!rcErodeWalkableArea(&ctx, cfg.walkableRadius, *chf));
#ifdef TOOLS_ENABLED
- if (ep)
+ if (ep) {
ep->step(TTR("Partitioning..."), 7);
+ }
#endif
if (p_nav_mesh->get_sample_partition_type() == NavigationMesh::SAMPLE_PARTITION_WATERSHED) {
@@ -423,8 +434,9 @@ void NavigationMeshGenerator::_build_recast_navigation_mesh(
}
#ifdef TOOLS_ENABLED
- if (ep)
+ if (ep) {
ep->step(TTR("Creating contours..."), 8);
+ }
#endif
cset = rcAllocContourSet();
@@ -433,8 +445,9 @@ void NavigationMeshGenerator::_build_recast_navigation_mesh(
ERR_FAIL_COND(!rcBuildContours(&ctx, *chf, cfg.maxSimplificationError, cfg.maxEdgeLen, *cset));
#ifdef TOOLS_ENABLED
- if (ep)
+ if (ep) {
ep->step(TTR("Creating polymesh..."), 9);
+ }
#endif
poly_mesh = rcAllocPolyMesh();
@@ -451,8 +464,9 @@ void NavigationMeshGenerator::_build_recast_navigation_mesh(
cset = nullptr;
#ifdef TOOLS_ENABLED
- if (ep)
+ if (ep) {
ep->step(TTR("Converting to native navigation mesh..."), 10);
+ }
#endif
_convert_detail_mesh_to_native_navigation_mesh(detail_mesh, p_nav_mesh);
@@ -483,8 +497,9 @@ void NavigationMeshGenerator::bake(Ref<NavigationMesh> p_nav_mesh, Node *p_node)
ep = memnew(EditorProgress("bake", TTR("Navigation Mesh Generator Setup:"), 11));
}
- if (ep)
+ if (ep) {
ep->step(TTR("Parsing Geometry..."), 0);
+ }
#endif
Vector<float> vertices;
@@ -543,11 +558,13 @@ void NavigationMeshGenerator::bake(Ref<NavigationMesh> p_nav_mesh, Node *p_node)
}
#ifdef TOOLS_ENABLED
- if (ep)
+ if (ep) {
ep->step(TTR("Done!"), 11);
+ }
- if (ep)
+ if (ep) {
memdelete(ep);
+ }
#endif
}
diff --git a/modules/gdscript/editor/gdscript_highlighter.cpp b/modules/gdscript/editor/gdscript_highlighter.cpp
index c3091a56a6..d0f27b632b 100644
--- a/modules/gdscript/editor/gdscript_highlighter.cpp
+++ b/modules/gdscript/editor/gdscript_highlighter.cpp
@@ -178,8 +178,9 @@ Map<int, TextEdit::HighlighterInfo> GDScriptSyntaxHighlighter::_get_line_syntax_
if (in_region == -1 && !in_keyword && is_char && !prev_is_char) {
int to = j;
- while (to < str.length() && _is_text_char(str[to]))
+ while (to < str.length() && _is_text_char(str[to])) {
to++;
+ }
String word = str.substr(j, to - j);
Color col = Color();
diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp
index 1d26e2148e..632407c61f 100644
--- a/modules/gdscript/gdscript.cpp
+++ b/modules/gdscript/gdscript.cpp
@@ -180,10 +180,12 @@ Ref<Script> GDScript::get_base_script() const {
}
StringName GDScript::get_instance_base_type() const {
- if (native.is_valid())
+ if (native.is_valid()) {
return native->get_name();
- if (base.is_valid() && base->is_valid())
+ }
+ if (base.is_valid() && base->is_valid()) {
return base->get_instance_base_type();
+ }
return StringName();
}
@@ -253,8 +255,9 @@ bool GDScript::has_method(const StringName &p_method) const {
MethodInfo GDScript::get_method_info(const StringName &p_method) const {
const Map<StringName, GDScriptFunction *>::Element *E = member_functions.find(p_method);
- if (!E)
+ if (!E) {
return MethodInfo();
+ }
GDScriptFunction *func = E->get();
MethodInfo mi;
@@ -285,8 +288,9 @@ bool GDScript::get_property_default_value(const StringName &p_property, Variant
ScriptInstance *GDScript::instance_create(Object *p_this) {
GDScript *top = this;
- while (top->_base)
+ while (top->_base) {
top = top->_base;
+ }
if (top->native.is_valid()) {
if (!ClassDB::is_parent_class(p_this->get_class_name(), top->native->get_name())) {
@@ -327,8 +331,9 @@ String GDScript::get_source_code() const {
}
void GDScript::set_source_code(const String &p_code) {
- if (source == p_code)
+ if (source == p_code) {
return;
+ }
source = p_code;
#ifdef TOOLS_ENABLED
source_changed_cache = true;
@@ -355,8 +360,9 @@ bool GDScript::_update_exports(bool *r_err, bool p_recursive_call) {
#ifdef TOOLS_ENABLED
static Vector<GDScript *> base_caches;
- if (!p_recursive_call)
+ if (!p_recursive_call) {
base_caches.clear();
+ }
base_caches.append(this);
bool changed = false;
@@ -367,11 +373,13 @@ bool GDScript::_update_exports(bool *r_err, bool p_recursive_call) {
String basedir = path;
- if (basedir == "")
+ if (basedir == "") {
basedir = get_path();
+ }
- if (basedir != "")
+ if (basedir != "") {
basedir = basedir.get_base_dir();
+ }
GDScriptParser parser;
Error err = parser.parse(source, basedir, true, path);
@@ -402,8 +410,9 @@ bool GDScript::_update_exports(bool *r_err, bool p_recursive_call) {
} else if (c->extends_class.size() != 0) {
String base = c->extends_class[0];
- if (ScriptServer::is_global_class(base))
+ if (ScriptServer::is_global_class(base)) {
path = ScriptServer::get_global_class_path(base);
+ }
}
if (path != "") {
@@ -424,8 +433,9 @@ bool GDScript::_update_exports(bool *r_err, bool p_recursive_call) {
member_default_values_cache.clear();
for (int i = 0; i < c->variables.size(); i++) {
- if (c->variables[i]._export.type == Variant::NIL)
+ if (c->variables[i]._export.type == Variant::NIL) {
continue;
+ }
members_cache.push_back(c->variables[i]._export);
member_default_values_cache[c->variables[i].identifier] = c->variables[i].default_value;
@@ -449,8 +459,9 @@ bool GDScript::_update_exports(bool *r_err, bool p_recursive_call) {
if (base_cache.is_valid() && base_cache->is_valid()) {
for (int i = 0; i < base_caches.size(); i++) {
if (base_caches[i] == base_cache.ptr()) {
- if (r_err)
+ if (r_err) {
*r_err = true;
+ }
valid = false; // to show error in the editor
base_cache->valid = false;
base_cache->inheriters_cache.clear(); // to prevent future stackoverflows
@@ -461,8 +472,9 @@ bool GDScript::_update_exports(bool *r_err, bool p_recursive_call) {
}
}
if (base_cache->_update_exports(r_err, true)) {
- if (r_err && *r_err)
+ if (r_err && *r_err) {
return false;
+ }
changed = true;
}
}
@@ -491,16 +503,18 @@ void GDScript::update_exports() {
bool cyclic_error = false;
_update_exports(&cyclic_error);
- if (cyclic_error)
+ if (cyclic_error) {
return;
+ }
Set<ObjectID> copy = inheriters_cache; //might get modified
for (Set<ObjectID>::Element *E = copy.front(); E; E = E->next()) {
Object *id = ObjectDB::get_instance(E->get());
GDScript *s = Object::cast_to<GDScript>(id);
- if (!s)
+ if (!s) {
continue;
+ }
s->update_exports();
}
@@ -526,11 +540,13 @@ Error GDScript::reload(bool p_keep_state) {
String basedir = path;
- if (basedir == "")
+ if (basedir == "") {
basedir = get_path();
+ }
- if (basedir != "")
+ if (basedir != "") {
basedir = basedir.get_base_dir();
+ }
if (source.find("%BASE%") != -1) {
//loading a template, don't parse
@@ -619,14 +635,16 @@ uint16_t GDScript::get_rpc_method_id(const StringName &p_method) const {
}
StringName GDScript::get_rpc_method(const uint16_t p_rpc_method_id) const {
- if (p_rpc_method_id >= rpc_functions.size())
+ if (p_rpc_method_id >= rpc_functions.size()) {
return StringName();
+ }
return rpc_functions[p_rpc_method_id].name;
}
MultiplayerAPI::RPCMode GDScript::get_rpc_mode_by_id(const uint16_t p_rpc_method_id) const {
- if (p_rpc_method_id >= rpc_functions.size())
+ if (p_rpc_method_id >= rpc_functions.size()) {
return MultiplayerAPI::RPC_MODE_DISABLED;
+ }
return rpc_functions[p_rpc_method_id].mode;
}
@@ -648,14 +666,16 @@ uint16_t GDScript::get_rset_property_id(const StringName &p_variable) const {
}
StringName GDScript::get_rset_property(const uint16_t p_rset_member_id) const {
- if (p_rset_member_id >= rpc_variables.size())
+ if (p_rset_member_id >= rpc_variables.size()) {
return StringName();
+ }
return rpc_variables[p_rset_member_id].name;
}
MultiplayerAPI::RPCMode GDScript::get_rset_mode_by_id(const uint16_t p_rset_member_id) const {
- if (p_rset_member_id >= rpc_variables.size())
+ if (p_rset_member_id >= rpc_variables.size()) {
return MultiplayerAPI::RPC_MODE_DISABLED;
+ }
return rpc_variables[p_rset_member_id].mode;
}
@@ -715,8 +735,9 @@ bool GDScript::_set(const StringName &p_name, const Variant &p_value) {
if (p_name == GDScriptLanguage::get_singleton()->strings._script_source) {
set_source_code(p_value);
reload();
- } else
+ } else {
return false;
+ }
return true;
}
@@ -776,11 +797,13 @@ Error GDScript::load_byte_code(const String &p_path) {
String basedir = path;
- if (basedir == "")
+ if (basedir == "") {
basedir = get_path();
+ }
- if (basedir != "")
+ if (basedir != "") {
basedir = basedir.get_base_dir();
+ }
valid = false;
GDScriptParser parser;
@@ -845,8 +868,9 @@ const Map<StringName, GDScriptFunction *> &GDScript::debug_get_member_functions(
StringName GDScript::debug_get_member_by_index(int p_idx) const {
for (const Map<StringName, MemberInfo>::Element *E = member_indices.front(); E; E = E->next()) {
- if (E->get().index == p_idx)
+ if (E->get().index == p_idx) {
return E->key();
+ }
}
return "<error>";
@@ -875,8 +899,9 @@ bool GDScript::inherits_script(const Ref<Script> &p_script) const {
}
bool GDScript::has_script_signal(const StringName &p_signal) const {
- if (_signals.has(p_signal))
+ if (_signals.has(p_signal)) {
return true;
+ }
if (base.is_valid()) {
return base->has_script_signal(p_signal);
}
@@ -957,8 +982,9 @@ void GDScript::_save_orphaned_subclasses() {
for (int i = 0; i < weak_subclasses.size(); i++) {
ClassRefWithName subclass = weak_subclasses[i];
Object *obj = ObjectDB::get_instance(subclass.id);
- if (!obj)
+ if (!obj) {
continue;
+ }
// subclass is not released
GDScriptLanguage::get_singleton()->add_orphan_subclass(subclass.fully_qualified_name, subclass.id);
}
@@ -999,13 +1025,15 @@ void GDScript::_init_rpc_methods_properties() {
}
}
- if (cscript != this)
+ if (cscript != this) {
sub_E = sub_E->next();
+ }
- if (sub_E)
+ if (sub_E) {
cscript = sub_E->get().ptr();
- else
+ } else {
cscript = nullptr;
+ }
}
// Sort so we are 100% that they are always the same.
@@ -1084,8 +1112,9 @@ bool GDScriptInstance::set(const StringName &p_name, const Variant &p_value) {
Callable::CallError err;
Variant ret = E->get()->call(this, (const Variant **)args, 2, err);
- if (err.error == Callable::CallError::CALL_OK && ret.get_type() == Variant::BOOL && ret.operator bool())
+ if (err.error == Callable::CallError::CALL_OK && ret.get_type() == Variant::BOOL && ret.operator bool()) {
return true;
+ }
}
sptr = sptr->_base;
}
@@ -1147,15 +1176,17 @@ Variant::Type GDScriptInstance::get_property_type(const StringName &p_name, bool
const GDScript *sptr = script.ptr();
while (sptr) {
if (sptr->member_info.has(p_name)) {
- if (r_is_valid)
+ if (r_is_valid) {
*r_is_valid = true;
+ }
return sptr->member_info[p_name].type;
}
sptr = sptr->_base;
}
- if (r_is_valid)
+ if (r_is_valid) {
*r_is_valid = false;
+ }
return Variant::NIL;
}
@@ -1183,12 +1214,15 @@ void GDScriptInstance::get_property_list(List<PropertyInfo> *p_properties) const
ERR_CONTINUE(pinfo.type < 0 || pinfo.type >= Variant::VARIANT_MAX);
pinfo.name = d["name"];
ERR_CONTINUE(pinfo.name == "");
- if (d.has("hint"))
+ if (d.has("hint")) {
pinfo.hint = PropertyHint(d["hint"].operator int());
- if (d.has("hint_string"))
+ }
+ if (d.has("hint_string")) {
pinfo.hint_string = d["hint_string"];
- if (d.has("usage"))
+ }
+ if (d.has("usage")) {
pinfo.usage = d["usage"];
+ }
props.push_back(pinfo);
}
@@ -1227,8 +1261,9 @@ void GDScriptInstance::get_method_list(List<MethodInfo> *p_list) const {
MethodInfo mi;
mi.name = E->key();
mi.flags |= METHOD_FLAG_FROM_SCRIPT;
- for (int i = 0; i < E->get()->get_argument_count(); i++)
+ for (int i = 0; i < E->get()->get_argument_count(); i++) {
mi.arguments.push_back(PropertyInfo(Variant::NIL, "arg" + itos(i)));
+ }
p_list->push_back(mi);
}
sptr = sptr->_base;
@@ -1239,8 +1274,9 @@ bool GDScriptInstance::has_method(const StringName &p_method) const {
const GDScript *sptr = script.ptr();
while (sptr) {
const Map<StringName, GDScriptFunction *>::Element *E = sptr->member_functions.find(p_method);
- if (E)
+ if (E) {
return true;
+ }
sptr = sptr->_base;
}
@@ -1274,8 +1310,9 @@ void GDScriptInstance::call_multilevel(const StringName &p_method, const Variant
}
void GDScriptInstance::_ml_call_reversed(GDScript *sptr, const StringName &p_method, const Variant **p_args, int p_argcount) {
- if (sptr->_base)
+ if (sptr->_base) {
_ml_call_reversed(sptr->_base, p_method, p_args, p_argcount);
+ }
Callable::CallError ce;
@@ -1316,17 +1353,20 @@ String GDScriptInstance::to_string(bool *r_valid) {
Variant ret = call(CoreStringNames::get_singleton()->_to_string, nullptr, 0, ce);
if (ce.error == Callable::CallError::CALL_OK) {
if (ret.get_type() != Variant::STRING) {
- if (r_valid)
+ if (r_valid) {
*r_valid = false;
+ }
ERR_FAIL_V_MSG(String(), "Wrong type for " + CoreStringNames::get_singleton()->_to_string + ", must be a String.");
}
- if (r_valid)
+ if (r_valid) {
*r_valid = true;
+ }
return ret.operator String();
}
}
- if (r_valid)
+ if (r_valid) {
*r_valid = false;
+ }
return String();
}
@@ -1477,11 +1517,13 @@ void GDScriptLanguage::init() {
for (List<StringName>::Element *E = class_list.front(); E; E = E->next()) {
StringName n = E->get();
String s = String(n);
- if (s.begins_with("_"))
+ if (s.begins_with("_")) {
n = s.substr(1, s.length());
+ }
- if (globals.has(n))
+ if (globals.has(n)) {
continue;
+ }
Ref<GDScriptNativeClass> nc = memnew(GDScriptNativeClass(E->get()));
_add_global(n, nc);
}
@@ -1549,8 +1591,9 @@ int GDScriptLanguage::profiling_get_accumulated_data(ProfilingInfo *p_info_arr,
SelfList<GDScriptFunction> *elem = function_list.first();
while (elem) {
- if (current >= p_info_max)
+ if (current >= p_info_max) {
break;
+ }
p_info_arr[current].call_count = elem->self()->profile.call_count;
p_info_arr[current].self_time = elem->self()->profile.self_time;
p_info_arr[current].total_time = elem->self()->profile.total_time;
@@ -1571,8 +1614,9 @@ int GDScriptLanguage::profiling_get_frame_data(ProfilingInfo *p_info_arr, int p_
SelfList<GDScriptFunction> *elem = function_list.first();
while (elem) {
- if (current >= p_info_max)
+ if (current >= p_info_max) {
break;
+ }
if (elem->self()->profile.last_frame_call_count > 0) {
p_info_arr[current].call_count = elem->self()->profile.last_frame_call_count;
p_info_arr[current].self_time = elem->self()->profile.last_frame_self_time;
@@ -1590,8 +1634,9 @@ int GDScriptLanguage::profiling_get_frame_data(ProfilingInfo *p_info_arr, int p_
struct GDScriptDepSort {
//must support sorting so inheritance works properly (parent must be reloaded first)
bool operator()(const Ref<GDScript> &A, const Ref<GDScript> &B) const {
- if (A == B)
+ if (A == B) {
return false; //shouldn't happen but..
+ }
const GDScript *I = B->get_base().ptr();
while (I) {
if (I == A.ptr()) {
@@ -1662,8 +1707,9 @@ void GDScriptLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_so
for (List<Ref<GDScript>>::Element *E = scripts.front(); E; E = E->next()) {
bool reload = E->get() == p_script || to_reload.has(E->get()->get_base());
- if (!reload)
+ if (!reload) {
continue;
+ }
to_reload.insert(E->get(), Map<ObjectID, List<Pair<StringName, Variant>>>());
@@ -1717,8 +1763,9 @@ void GDScriptLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_so
List<Pair<StringName, Variant>> &saved_state = F->get();
Object *obj = ObjectDB::get_instance(F->key());
- if (!obj)
+ if (!obj) {
continue;
+ }
if (!p_soft_reload) {
//clear it just in case (may be a pending reload state)
@@ -1872,10 +1919,11 @@ String GDScriptLanguage::get_global_class_name(const String &p_path, String *r_b
if (parser.get_parse_tree() && parser.get_parse_tree()->type == GDScriptParser::Node::TYPE_CLASS) {
const GDScriptParser::ClassNode *c = static_cast<const GDScriptParser::ClassNode *>(parser.get_parse_tree());
if (r_icon_path) {
- if (c->icon_path.empty() || c->icon_path.is_abs_path())
+ if (c->icon_path.empty() || c->icon_path.is_abs_path()) {
*r_icon_path = c->icon_path;
- else if (c->icon_path.is_rel_path())
+ } else if (c->icon_path.is_rel_path()) {
*r_icon_path = p_path.get_base_dir().plus_file(c->icon_path).simplify_path();
+ }
}
if (r_base_type) {
const GDScriptParser::ClassNode *subclass = c;
@@ -2175,21 +2223,24 @@ void GDScriptLanguage::add_orphan_subclass(const String &p_qualified_name, const
Ref<GDScript> GDScriptLanguage::get_orphan_subclass(const String &p_qualified_name) {
Map<String, ObjectID>::Element *orphan_subclass_element = orphan_subclasses.find(p_qualified_name);
- if (!orphan_subclass_element)
+ if (!orphan_subclass_element) {
return Ref<GDScript>();
+ }
ObjectID orphan_subclass = orphan_subclass_element->get();
Object *obj = ObjectDB::get_instance(orphan_subclass);
orphan_subclasses.erase(orphan_subclass_element);
- if (!obj)
+ if (!obj) {
return Ref<GDScript>();
+ }
return Ref<GDScript>(Object::cast_to<GDScript>(obj));
}
/*************** RESOURCE ***************/
RES ResourceFormatLoaderGDScript::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) {
- if (r_error)
+ if (r_error) {
*r_error = ERR_FILE_CANT_OPEN;
+ }
GDScript *script = memnew(GDScript);
@@ -2210,8 +2261,9 @@ RES ResourceFormatLoaderGDScript::load(const String &p_path, const String &p_ori
script->reload();
}
- if (r_error)
+ if (r_error) {
*r_error = OK;
+ }
return scriptres;
}
@@ -2228,8 +2280,9 @@ bool ResourceFormatLoaderGDScript::handles_type(const String &p_type) const {
String ResourceFormatLoaderGDScript::get_resource_type(const String &p_path) const {
String el = p_path.get_extension().to_lower();
- if (el == "gd" || el == "gdc" || el == "gde")
+ if (el == "gd" || el == "gdc" || el == "gde") {
return "GDScript";
+ }
return "";
}
diff --git a/modules/gdscript/gdscript.h b/modules/gdscript/gdscript.h
index ecaa2257ca..e770dc3abd 100644
--- a/modules/gdscript/gdscript.h
+++ b/modules/gdscript/gdscript.h
@@ -209,11 +209,11 @@ public:
virtual int get_member_line(const StringName &p_member) const {
#ifdef TOOLS_ENABLED
- if (member_lines.has(p_member))
+ if (member_lines.has(p_member)) {
return member_lines[p_member];
- else
+ }
#endif
- return -1;
+ return -1;
}
virtual void get_constants(Map<StringName, Variant> *p_constants);
@@ -396,11 +396,13 @@ public:
bool debug_break_parse(const String &p_file, int p_line, const String &p_error);
_FORCE_INLINE_ void enter_function(GDScriptInstance *p_instance, GDScriptFunction *p_function, Variant *p_stack, int *p_ip, int *p_line) {
- if (Thread::get_main_id() != Thread::get_caller_id())
+ if (Thread::get_main_id() != Thread::get_caller_id()) {
return; //no support for other threads than main for now
+ }
- if (EngineDebugger::get_script_debugger()->get_lines_left() > 0 && EngineDebugger::get_script_debugger()->get_depth() >= 0)
+ if (EngineDebugger::get_script_debugger()->get_lines_left() > 0 && EngineDebugger::get_script_debugger()->get_depth() >= 0) {
EngineDebugger::get_script_debugger()->set_depth(EngineDebugger::get_script_debugger()->get_depth() + 1);
+ }
if (_debug_call_stack_pos >= _debug_max_call_stack) {
//stack overflow
@@ -418,11 +420,13 @@ public:
}
_FORCE_INLINE_ void exit_function() {
- if (Thread::get_main_id() != Thread::get_caller_id())
+ if (Thread::get_main_id() != Thread::get_caller_id()) {
return; //no support for other threads than main for now
+ }
- if (EngineDebugger::get_script_debugger()->get_lines_left() > 0 && EngineDebugger::get_script_debugger()->get_depth() >= 0)
+ if (EngineDebugger::get_script_debugger()->get_lines_left() > 0 && EngineDebugger::get_script_debugger()->get_depth() >= 0) {
EngineDebugger::get_script_debugger()->set_depth(EngineDebugger::get_script_debugger()->get_depth() - 1);
+ }
if (_debug_call_stack_pos == 0) {
_debug_error = "Stack Underflow (Engine Bug)";
@@ -434,8 +438,9 @@ public:
}
virtual Vector<StackInfo> debug_get_current_stack_info() {
- if (Thread::get_main_id() != Thread::get_caller_id())
+ if (Thread::get_main_id() != Thread::get_caller_id()) {
return Vector<StackInfo>();
+ }
Vector<StackInfo> csi;
csi.resize(_debug_call_stack_pos);
diff --git a/modules/gdscript/gdscript_compiler.cpp b/modules/gdscript/gdscript_compiler.cpp
index deb725ea81..bc095ae1f9 100644
--- a/modules/gdscript/gdscript_compiler.cpp
+++ b/modules/gdscript/gdscript_compiler.cpp
@@ -33,11 +33,13 @@
#include "gdscript.h"
bool GDScriptCompiler::_is_class_member_property(CodeGen &codegen, const StringName &p_name) {
- if (codegen.function_node && codegen.function_node->_static)
+ if (codegen.function_node && codegen.function_node->_static) {
return false;
+ }
- if (codegen.stack_identifiers.has(p_name))
+ if (codegen.stack_identifiers.has(p_name)) {
return false; //shadowed
+ }
return _is_class_member_property(codegen.script, p_name);
}
@@ -46,8 +48,9 @@ bool GDScriptCompiler::_is_class_member_property(GDScript *owner, const StringNa
GDScript *scr = owner;
GDScriptNativeClass *nc = nullptr;
while (scr) {
- if (scr->native.is_valid())
+ if (scr->native.is_valid()) {
nc = scr->native.ptr();
+ }
scr = scr->_base;
}
@@ -57,8 +60,9 @@ bool GDScriptCompiler::_is_class_member_property(GDScript *owner, const StringNa
}
void GDScriptCompiler::_set_error(const String &p_error, const GDScriptParser::Node *p_node) {
- if (error != "")
+ if (error != "") {
return;
+ }
error = p_error;
if (p_node) {
@@ -74,8 +78,9 @@ bool GDScriptCompiler::_create_unary_operator(CodeGen &codegen, const GDScriptPa
ERR_FAIL_COND_V(on->arguments.size() != 1, false);
int src_address_a = _parse_expression(codegen, on->arguments[0], p_stack_level);
- if (src_address_a < 0)
+ if (src_address_a < 0) {
return false;
+ }
codegen.opcodes.push_back(GDScriptFunction::OPCODE_OPERATOR); // perform operator
codegen.opcodes.push_back(op); //which operator
@@ -89,14 +94,17 @@ bool GDScriptCompiler::_create_binary_operator(CodeGen &codegen, const GDScriptP
ERR_FAIL_COND_V(on->arguments.size() != 2, false);
int src_address_a = _parse_expression(codegen, on->arguments[0], p_stack_level, false, p_initializer, p_index_addr);
- if (src_address_a < 0)
+ if (src_address_a < 0) {
return false;
- if (src_address_a & GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS)
+ }
+ if (src_address_a & GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS) {
p_stack_level++; //uses stack for return, increase stack
+ }
int src_address_b = _parse_expression(codegen, on->arguments[1], p_stack_level, false, p_initializer);
- if (src_address_b < 0)
+ if (src_address_b < 0) {
return false;
+ }
codegen.opcodes.push_back(GDScriptFunction::OPCODE_OPERATOR); // perform operator
codegen.opcodes.push_back(op); //which operator
@@ -214,8 +222,9 @@ int GDScriptCompiler::_parse_assign_right_expression(CodeGen &codegen, const GDS
return _parse_expression(codegen, p_expression->arguments[1], p_stack_level, false, initializer);
}
- if (!_create_binary_operator(codegen, p_expression, var_op, p_stack_level, initializer, p_index_addr))
+ if (!_create_binary_operator(codegen, p_expression, var_op, p_stack_level, initializer, p_index_addr)) {
return -1;
+ }
int dst_addr = (p_stack_level) | (GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS);
codegen.opcodes.push_back(dst_addr); // append the stack level as destination address of the opcode
@@ -276,8 +285,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser::
int idx = codegen.get_name_map_pos(identifier);
return idx | (GDScriptFunction::ADDR_TYPE_CLASS_CONSTANT << GDScriptFunction::ADDR_BITS); //argument (stack root)
}
- if (scr->native.is_valid())
+ if (scr->native.is_valid()) {
nc = scr->native.ptr();
+ }
scr = scr->_base;
}
@@ -394,8 +404,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser::
for (int i = 0; i < an->elements.size(); i++) {
int ret = _parse_expression(codegen, an->elements[i], slevel);
- if (ret < 0)
+ if (ret < 0) {
return ret;
+ }
if ((ret >> GDScriptFunction::ADDR_BITS & GDScriptFunction::ADDR_TYPE_STACK) == GDScriptFunction::ADDR_TYPE_STACK) {
slevel++;
codegen.alloc_stack(slevel);
@@ -406,8 +417,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser::
codegen.opcodes.push_back(GDScriptFunction::OPCODE_CONSTRUCT_ARRAY);
codegen.opcodes.push_back(values.size());
- for (int i = 0; i < values.size(); i++)
+ for (int i = 0; i < values.size(); i++) {
codegen.opcodes.push_back(values[i]);
+ }
int dst_addr = (p_stack_level) | (GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS);
codegen.opcodes.push_back(dst_addr); // append the stack level as destination address of the opcode
@@ -423,8 +435,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser::
for (int i = 0; i < dn->elements.size(); i++) {
int ret = _parse_expression(codegen, dn->elements[i].key, slevel);
- if (ret < 0)
+ if (ret < 0) {
return ret;
+ }
if ((ret >> GDScriptFunction::ADDR_BITS & GDScriptFunction::ADDR_TYPE_STACK) == GDScriptFunction::ADDR_TYPE_STACK) {
slevel++;
codegen.alloc_stack(slevel);
@@ -433,8 +446,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser::
values.push_back(ret);
ret = _parse_expression(codegen, dn->elements[i].value, slevel);
- if (ret < 0)
+ if (ret < 0) {
return ret;
+ }
if ((ret >> GDScriptFunction::ADDR_BITS & GDScriptFunction::ADDR_TYPE_STACK) == GDScriptFunction::ADDR_TYPE_STACK) {
slevel++;
codegen.alloc_stack(slevel);
@@ -445,8 +459,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser::
codegen.opcodes.push_back(GDScriptFunction::OPCODE_CONSTRUCT_DICTIONARY);
codegen.opcodes.push_back(dn->elements.size());
- for (int i = 0; i < values.size(); i++)
+ for (int i = 0; i < values.size(); i++) {
codegen.opcodes.push_back(values[i]);
+ }
int dst_addr = (p_stack_level) | (GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS);
codegen.opcodes.push_back(dst_addr); // append the stack level as destination address of the opcode
@@ -459,8 +474,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser::
int slevel = p_stack_level;
int src_addr = _parse_expression(codegen, cn->source_node, slevel);
- if (src_addr < 0)
+ if (src_addr < 0) {
return src_addr;
+ }
if (src_addr & GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS) {
slevel++;
codegen.alloc_stack(slevel);
@@ -522,8 +538,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser::
int slevel = p_stack_level;
for (int i = 1; i < on->arguments.size(); i++) {
int ret = _parse_expression(codegen, on->arguments[i], slevel);
- if (ret < 0)
+ if (ret < 0) {
return ret;
+ }
if ((ret >> GDScriptFunction::ADDR_BITS & GDScriptFunction::ADDR_TYPE_STACK) == GDScriptFunction::ADDR_TYPE_STACK) {
slevel++;
codegen.alloc_stack(slevel);
@@ -537,8 +554,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser::
codegen.opcodes.push_back(codegen.get_name_map_pos(in->name)); //instance
codegen.opcodes.push_back(arguments.size()); //argument count
codegen.alloc_call(arguments.size());
- for (int i = 0; i < arguments.size(); i++)
+ for (int i = 0; i < arguments.size(); i++) {
codegen.opcodes.push_back(arguments[i]); //arguments
+ }
} break;
case GDScriptParser::OperatorNode::OP_CALL: {
@@ -553,8 +571,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser::
int slevel = p_stack_level;
for (int i = 1; i < on->arguments.size(); i++) {
int ret = _parse_expression(codegen, on->arguments[i], slevel);
- if (ret < 0)
+ if (ret < 0) {
return ret;
+ }
if ((ret >> GDScriptFunction::ADDR_BITS & GDScriptFunction::ADDR_TYPE_STACK) == GDScriptFunction::ADDR_TYPE_STACK) {
slevel++;
codegen.alloc_stack(slevel);
@@ -567,8 +586,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser::
codegen.opcodes.push_back(vtype); //instance
codegen.opcodes.push_back(arguments.size()); //argument count
codegen.alloc_call(arguments.size());
- for (int i = 0; i < arguments.size(); i++)
+ for (int i = 0; i < arguments.size(); i++) {
codegen.opcodes.push_back(arguments[i]); //arguments
+ }
} else if (on->arguments[0]->type == GDScriptParser::Node::TYPE_BUILT_IN_FUNCTION) {
//built in function
@@ -579,8 +599,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser::
int slevel = p_stack_level;
for (int i = 1; i < on->arguments.size(); i++) {
int ret = _parse_expression(codegen, on->arguments[i], slevel);
- if (ret < 0)
+ if (ret < 0) {
return ret;
+ }
if ((ret >> GDScriptFunction::ADDR_BITS & GDScriptFunction::ADDR_TYPE_STACK) == GDScriptFunction::ADDR_TYPE_STACK) {
slevel++;
@@ -594,8 +615,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser::
codegen.opcodes.push_back(static_cast<const GDScriptParser::BuiltInFunctionNode *>(on->arguments[0])->function);
codegen.opcodes.push_back(on->arguments.size() - 1);
codegen.alloc_call(on->arguments.size() - 1);
- for (int i = 0; i < arguments.size(); i++)
+ for (int i = 0; i < arguments.size(); i++) {
codegen.opcodes.push_back(arguments[i]);
+ }
} else {
//regular function
@@ -626,8 +648,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser::
} else {
ret = _parse_expression(codegen, on->arguments[i], slevel);
- if (ret < 0)
+ if (ret < 0) {
return ret;
+ }
if ((ret >> GDScriptFunction::ADDR_BITS & GDScriptFunction::ADDR_TYPE_STACK) == GDScriptFunction::ADDR_TYPE_STACK) {
slevel++;
codegen.alloc_stack(slevel);
@@ -639,8 +662,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser::
codegen.opcodes.push_back(p_root ? GDScriptFunction::OPCODE_CALL : GDScriptFunction::OPCODE_CALL_RETURN); // perform operator
codegen.opcodes.push_back(on->arguments.size() - 2);
codegen.alloc_call(on->arguments.size() - 2);
- for (int i = 0; i < arguments.size(); i++)
+ for (int i = 0; i < arguments.size(); i++) {
codegen.opcodes.push_back(arguments[i]);
+ }
}
} break;
case GDScriptParser::OperatorNode::OP_YIELD: {
@@ -650,8 +674,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser::
int slevel = p_stack_level;
for (int i = 0; i < on->arguments.size(); i++) {
int ret = _parse_expression(codegen, on->arguments[i], slevel);
- if (ret < 0)
+ if (ret < 0) {
return ret;
+ }
if ((ret >> GDScriptFunction::ADDR_BITS & GDScriptFunction::ADDR_TYPE_STACK) == GDScriptFunction::ADDR_TYPE_STACK) {
slevel++;
codegen.alloc_stack(slevel);
@@ -661,8 +686,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser::
//push call bytecode
codegen.opcodes.push_back(arguments.size() == 0 ? GDScriptFunction::OPCODE_YIELD : GDScriptFunction::OPCODE_YIELD_SIGNAL); // basic type constructor
- for (int i = 0; i < arguments.size(); i++)
+ for (int i = 0; i < arguments.size(); i++) {
codegen.opcodes.push_back(arguments[i]); //arguments
+ }
codegen.opcodes.push_back(GDScriptFunction::OPCODE_YIELD_RESUME);
//next will be where to place the result :)
@@ -677,8 +703,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser::
bool named = (on->op == GDScriptParser::OperatorNode::OP_INDEX_NAMED);
int from = _parse_expression(codegen, on->arguments[0], slevel);
- if (from < 0)
+ if (from < 0) {
return from;
+ }
int index;
if (p_index_addr != 0) {
@@ -719,8 +746,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser::
}
index = _parse_expression(codegen, on->arguments[1], slevel);
- if (index < 0)
+ if (index < 0) {
return index;
+ }
}
}
@@ -733,16 +761,18 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser::
// AND operator with early out on failure
int res = _parse_expression(codegen, on->arguments[0], p_stack_level);
- if (res < 0)
+ if (res < 0) {
return res;
+ }
codegen.opcodes.push_back(GDScriptFunction::OPCODE_JUMP_IF_NOT);
codegen.opcodes.push_back(res);
int jump_fail_pos = codegen.opcodes.size();
codegen.opcodes.push_back(0);
res = _parse_expression(codegen, on->arguments[1], p_stack_level);
- if (res < 0)
+ if (res < 0) {
return res;
+ }
codegen.opcodes.push_back(GDScriptFunction::OPCODE_JUMP_IF_NOT);
codegen.opcodes.push_back(res);
@@ -765,16 +795,18 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser::
// OR operator with early out on success
int res = _parse_expression(codegen, on->arguments[0], p_stack_level);
- if (res < 0)
+ if (res < 0) {
return res;
+ }
codegen.opcodes.push_back(GDScriptFunction::OPCODE_JUMP_IF);
codegen.opcodes.push_back(res);
int jump_success_pos = codegen.opcodes.size();
codegen.opcodes.push_back(0);
res = _parse_expression(codegen, on->arguments[1], p_stack_level);
- if (res < 0)
+ if (res < 0) {
return res;
+ }
codegen.opcodes.push_back(GDScriptFunction::OPCODE_JUMP_IF);
codegen.opcodes.push_back(res);
@@ -798,16 +830,18 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser::
// x IF a ELSE y operator with early out on failure
int res = _parse_expression(codegen, on->arguments[0], p_stack_level);
- if (res < 0)
+ if (res < 0) {
return res;
+ }
codegen.opcodes.push_back(GDScriptFunction::OPCODE_JUMP_IF_NOT);
codegen.opcodes.push_back(res);
int jump_fail_pos = codegen.opcodes.size();
codegen.opcodes.push_back(0);
res = _parse_expression(codegen, on->arguments[1], p_stack_level);
- if (res < 0)
+ if (res < 0) {
return res;
+ }
codegen.alloc_stack(p_stack_level); //it will be used..
codegen.opcodes.push_back(GDScriptFunction::OPCODE_ASSIGN);
@@ -819,8 +853,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser::
codegen.opcodes.write[jump_fail_pos] = codegen.opcodes.size();
res = _parse_expression(codegen, on->arguments[2], p_stack_level);
- if (res < 0)
+ if (res < 0) {
return res;
+ }
codegen.opcodes.push_back(GDScriptFunction::OPCODE_ASSIGN);
codegen.opcodes.push_back(p_stack_level | GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS);
@@ -833,92 +868,113 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser::
} break;
//unary operators
case GDScriptParser::OperatorNode::OP_NEG: {
- if (!_create_unary_operator(codegen, on, Variant::OP_NEGATE, p_stack_level))
+ if (!_create_unary_operator(codegen, on, Variant::OP_NEGATE, p_stack_level)) {
return -1;
+ }
} break;
case GDScriptParser::OperatorNode::OP_POS: {
- if (!_create_unary_operator(codegen, on, Variant::OP_POSITIVE, p_stack_level))
+ if (!_create_unary_operator(codegen, on, Variant::OP_POSITIVE, p_stack_level)) {
return -1;
+ }
} break;
case GDScriptParser::OperatorNode::OP_NOT: {
- if (!_create_unary_operator(codegen, on, Variant::OP_NOT, p_stack_level))
+ if (!_create_unary_operator(codegen, on, Variant::OP_NOT, p_stack_level)) {
return -1;
+ }
} break;
case GDScriptParser::OperatorNode::OP_BIT_INVERT: {
- if (!_create_unary_operator(codegen, on, Variant::OP_BIT_NEGATE, p_stack_level))
+ if (!_create_unary_operator(codegen, on, Variant::OP_BIT_NEGATE, p_stack_level)) {
return -1;
+ }
} break;
//binary operators (in precedence order)
case GDScriptParser::OperatorNode::OP_IN: {
- if (!_create_binary_operator(codegen, on, Variant::OP_IN, p_stack_level))
+ if (!_create_binary_operator(codegen, on, Variant::OP_IN, p_stack_level)) {
return -1;
+ }
} break;
case GDScriptParser::OperatorNode::OP_EQUAL: {
- if (!_create_binary_operator(codegen, on, Variant::OP_EQUAL, p_stack_level))
+ if (!_create_binary_operator(codegen, on, Variant::OP_EQUAL, p_stack_level)) {
return -1;
+ }
} break;
case GDScriptParser::OperatorNode::OP_NOT_EQUAL: {
- if (!_create_binary_operator(codegen, on, Variant::OP_NOT_EQUAL, p_stack_level))
+ if (!_create_binary_operator(codegen, on, Variant::OP_NOT_EQUAL, p_stack_level)) {
return -1;
+ }
} break;
case GDScriptParser::OperatorNode::OP_LESS: {
- if (!_create_binary_operator(codegen, on, Variant::OP_LESS, p_stack_level))
+ if (!_create_binary_operator(codegen, on, Variant::OP_LESS, p_stack_level)) {
return -1;
+ }
} break;
case GDScriptParser::OperatorNode::OP_LESS_EQUAL: {
- if (!_create_binary_operator(codegen, on, Variant::OP_LESS_EQUAL, p_stack_level))
+ if (!_create_binary_operator(codegen, on, Variant::OP_LESS_EQUAL, p_stack_level)) {
return -1;
+ }
} break;
case GDScriptParser::OperatorNode::OP_GREATER: {
- if (!_create_binary_operator(codegen, on, Variant::OP_GREATER, p_stack_level))
+ if (!_create_binary_operator(codegen, on, Variant::OP_GREATER, p_stack_level)) {
return -1;
+ }
} break;
case GDScriptParser::OperatorNode::OP_GREATER_EQUAL: {
- if (!_create_binary_operator(codegen, on, Variant::OP_GREATER_EQUAL, p_stack_level))
+ if (!_create_binary_operator(codegen, on, Variant::OP_GREATER_EQUAL, p_stack_level)) {
return -1;
+ }
} break;
case GDScriptParser::OperatorNode::OP_ADD: {
- if (!_create_binary_operator(codegen, on, Variant::OP_ADD, p_stack_level))
+ if (!_create_binary_operator(codegen, on, Variant::OP_ADD, p_stack_level)) {
return -1;
+ }
} break;
case GDScriptParser::OperatorNode::OP_SUB: {
- if (!_create_binary_operator(codegen, on, Variant::OP_SUBTRACT, p_stack_level))
+ if (!_create_binary_operator(codegen, on, Variant::OP_SUBTRACT, p_stack_level)) {
return -1;
+ }
} break;
case GDScriptParser::OperatorNode::OP_MUL: {
- if (!_create_binary_operator(codegen, on, Variant::OP_MULTIPLY, p_stack_level))
+ if (!_create_binary_operator(codegen, on, Variant::OP_MULTIPLY, p_stack_level)) {
return -1;
+ }
} break;
case GDScriptParser::OperatorNode::OP_DIV: {
- if (!_create_binary_operator(codegen, on, Variant::OP_DIVIDE, p_stack_level))
+ if (!_create_binary_operator(codegen, on, Variant::OP_DIVIDE, p_stack_level)) {
return -1;
+ }
} break;
case GDScriptParser::OperatorNode::OP_MOD: {
- if (!_create_binary_operator(codegen, on, Variant::OP_MODULE, p_stack_level))
+ if (!_create_binary_operator(codegen, on, Variant::OP_MODULE, p_stack_level)) {
return -1;
+ }
} break;
//case GDScriptParser::OperatorNode::OP_SHIFT_LEFT: { if (!_create_binary_operator(codegen,on,Variant::OP_SHIFT_LEFT,p_stack_level)) return -1;} break;
//case GDScriptParser::OperatorNode::OP_SHIFT_RIGHT: { if (!_create_binary_operator(codegen,on,Variant::OP_SHIFT_RIGHT,p_stack_level)) return -1;} break;
case GDScriptParser::OperatorNode::OP_BIT_AND: {
- if (!_create_binary_operator(codegen, on, Variant::OP_BIT_AND, p_stack_level))
+ if (!_create_binary_operator(codegen, on, Variant::OP_BIT_AND, p_stack_level)) {
return -1;
+ }
} break;
case GDScriptParser::OperatorNode::OP_BIT_OR: {
- if (!_create_binary_operator(codegen, on, Variant::OP_BIT_OR, p_stack_level))
+ if (!_create_binary_operator(codegen, on, Variant::OP_BIT_OR, p_stack_level)) {
return -1;
+ }
} break;
case GDScriptParser::OperatorNode::OP_BIT_XOR: {
- if (!_create_binary_operator(codegen, on, Variant::OP_BIT_XOR, p_stack_level))
+ if (!_create_binary_operator(codegen, on, Variant::OP_BIT_XOR, p_stack_level)) {
return -1;
+ }
} break;
//shift
case GDScriptParser::OperatorNode::OP_SHIFT_LEFT: {
- if (!_create_binary_operator(codegen, on, Variant::OP_SHIFT_LEFT, p_stack_level))
+ if (!_create_binary_operator(codegen, on, Variant::OP_SHIFT_LEFT, p_stack_level)) {
return -1;
+ }
} break;
case GDScriptParser::OperatorNode::OP_SHIFT_RIGHT: {
- if (!_create_binary_operator(codegen, on, Variant::OP_SHIFT_RIGHT, p_stack_level))
+ if (!_create_binary_operator(codegen, on, Variant::OP_SHIFT_RIGHT, p_stack_level)) {
return -1;
+ }
} break;
//assignment operators
case GDScriptParser::OperatorNode::OP_ASSIGN_ADD:
@@ -978,8 +1034,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser::
break;
}
n = static_cast<GDScriptParser::OperatorNode *>(n->arguments[0]);
- if (n->op != GDScriptParser::OperatorNode::OP_INDEX && n->op != GDScriptParser::OperatorNode::OP_INDEX_NAMED)
+ if (n->op != GDScriptParser::OperatorNode::OP_INDEX && n->op != GDScriptParser::OperatorNode::OP_INDEX_NAMED) {
break;
+ }
}
}
@@ -987,8 +1044,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser::
//get at (potential) root stack pos, so it can be returned
int prev_pos = _parse_expression(codegen, chain.back()->get()->arguments[0], slevel);
- if (prev_pos < 0)
+ if (prev_pos < 0) {
return prev_pos;
+ }
int retval = prev_pos;
if (retval & GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS) {
@@ -1008,8 +1066,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser::
}
for (List<GDScriptParser::OperatorNode *>::Element *E = chain.back(); E; E = E->prev()) {
- if (E == chain.front()) //ignore first
+ if (E == chain.front()) { //ignore first
break;
+ }
bool named = E->get()->op == GDScriptParser::OperatorNode::OP_INDEX_NAMED;
int key_idx;
@@ -1031,8 +1090,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser::
//stack was raised here if retval was stack but..
}
- if (key_idx < 0) //error
+ if (key_idx < 0) { //error
return key_idx;
+ }
codegen.opcodes.push_back(named ? GDScriptFunction::OPCODE_GET_NAMED : GDScriptFunction::OPCODE_GET);
codegen.opcodes.push_back(prev_pos);
@@ -1066,8 +1126,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser::
named = false;
}
- if (set_index < 0) //error
+ if (set_index < 0) { //error
return set_index;
+ }
if (set_index & GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS) {
slevel++;
@@ -1075,8 +1136,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser::
}
int set_value = _parse_assign_right_expression(codegen, on, slevel + 1, named ? 0 : set_index);
- if (set_value < 0) //error
+ if (set_value < 0) { //error
return set_value;
+ }
codegen.opcodes.push_back(named ? GDScriptFunction::OPCODE_SET_NAMED : GDScriptFunction::OPCODE_SET);
codegen.opcodes.push_back(prev_pos);
@@ -1095,8 +1157,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser::
int slevel = p_stack_level;
int src_address = _parse_assign_right_expression(codegen, on, slevel);
- if (src_address < 0)
+ if (src_address < 0) {
return -1;
+ }
StringName name = static_cast<GDScriptParser::IdentifierNode *>(on->arguments[0])->name;
@@ -1111,8 +1174,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser::
int slevel = p_stack_level;
int dst_address_a = _parse_expression(codegen, on->arguments[0], slevel, false, on->op == GDScriptParser::OperatorNode::OP_INIT_ASSIGN);
- if (dst_address_a < 0)
+ if (dst_address_a < 0) {
return -1;
+ }
if (dst_address_a & GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS) {
slevel++;
@@ -1120,8 +1184,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser::
}
int src_address_b = _parse_assign_right_expression(codegen, on, slevel);
- if (src_address_b < 0)
+ if (src_address_b < 0) {
return -1;
+ }
GDScriptDataType assign_type = _gdtype_from_datatype(on->arguments[0]->get_datatype());
@@ -1183,15 +1248,18 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser::
int slevel = p_stack_level;
int src_address_a = _parse_expression(codegen, on->arguments[0], slevel);
- if (src_address_a < 0)
+ if (src_address_a < 0) {
return -1;
+ }
- if (src_address_a & GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS)
+ if (src_address_a & GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS) {
slevel++; //uses stack for return, increase stack
+ }
int src_address_b = _parse_expression(codegen, on->arguments[1], slevel);
- if (src_address_b < 0)
+ if (src_address_b < 0) {
return -1;
+ }
codegen.opcodes.push_back(GDScriptFunction::OPCODE_EXTENDS_TEST); // perform operator
codegen.opcodes.push_back(src_address_a); // argument 1
@@ -1205,11 +1273,13 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser::
int slevel = p_stack_level;
int src_address_a = _parse_expression(codegen, on->arguments[0], slevel);
- if (src_address_a < 0)
+ if (src_address_a < 0) {
return -1;
+ }
- if (src_address_a & GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS)
+ if (src_address_a & GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS) {
slevel++; //uses stack for return, increase stack
+ }
const GDScriptParser::TypeNode *tn = static_cast<const GDScriptParser::TypeNode *>(on->arguments[1]);
@@ -1332,8 +1402,9 @@ Error GDScriptCompiler::_parse_block(CodeGen &codegen, const GDScriptParser::Blo
case GDScriptParser::ControlFlowNode::CF_IF: {
int ret2 = _parse_expression(codegen, cf->arguments[0], p_stack_level, false);
- if (ret2 < 0)
+ if (ret2 < 0) {
return ERR_PARSE_ERROR;
+ }
codegen.opcodes.push_back(GDScriptFunction::OPCODE_JUMP_IF_NOT);
codegen.opcodes.push_back(ret2);
@@ -1341,8 +1412,9 @@ Error GDScriptCompiler::_parse_block(CodeGen &codegen, const GDScriptParser::Blo
codegen.opcodes.push_back(0); //temporary
Error err = _parse_block(codegen, cf->body, p_stack_level, p_break_addr, p_continue_addr);
- if (err)
+ if (err) {
return err;
+ }
if (cf->body_else) {
codegen.opcodes.push_back(GDScriptFunction::OPCODE_JUMP);
@@ -1351,8 +1423,9 @@ Error GDScriptCompiler::_parse_block(CodeGen &codegen, const GDScriptParser::Blo
codegen.opcodes.write[else_addr] = codegen.opcodes.size();
Error err2 = _parse_block(codegen, cf->body_else, p_stack_level, p_break_addr, p_continue_addr);
- if (err2)
+ if (err2) {
return err2;
+ }
codegen.opcodes.write[end_addr] = codegen.opcodes.size();
} else {
@@ -1373,8 +1446,9 @@ Error GDScriptCompiler::_parse_block(CodeGen &codegen, const GDScriptParser::Blo
codegen.add_stack_identifier(static_cast<const GDScriptParser::IdentifierNode *>(cf->arguments[0])->name, iter_stack_pos);
int ret2 = _parse_expression(codegen, cf->arguments[1], slevel, false);
- if (ret2 < 0)
+ if (ret2 < 0) {
return ERR_COMPILATION_FAILED;
+ }
//assign container
codegen.opcodes.push_back(GDScriptFunction::OPCODE_ASSIGN);
@@ -1402,8 +1476,9 @@ Error GDScriptCompiler::_parse_block(CodeGen &codegen, const GDScriptParser::Blo
codegen.opcodes.push_back(iterator_pos);
Error err = _parse_block(codegen, cf->body, slevel, break_pos, continue_pos);
- if (err)
+ if (err) {
return err;
+ }
codegen.opcodes.push_back(GDScriptFunction::OPCODE_JUMP);
codegen.opcodes.push_back(continue_pos);
@@ -1421,14 +1496,16 @@ Error GDScriptCompiler::_parse_block(CodeGen &codegen, const GDScriptParser::Blo
int continue_addr = codegen.opcodes.size();
int ret2 = _parse_expression(codegen, cf->arguments[0], p_stack_level, false);
- if (ret2 < 0)
+ if (ret2 < 0) {
return ERR_PARSE_ERROR;
+ }
codegen.opcodes.push_back(GDScriptFunction::OPCODE_JUMP_IF_NOT);
codegen.opcodes.push_back(ret2);
codegen.opcodes.push_back(break_addr);
Error err = _parse_block(codegen, cf->body, p_stack_level, break_addr, continue_addr);
- if (err)
+ if (err) {
return err;
+ }
codegen.opcodes.push_back(GDScriptFunction::OPCODE_JUMP);
codegen.opcodes.push_back(continue_addr);
@@ -1459,8 +1536,9 @@ Error GDScriptCompiler::_parse_block(CodeGen &codegen, const GDScriptParser::Blo
if (cf->arguments.size()) {
ret2 = _parse_expression(codegen, cf->arguments[0], p_stack_level, false);
- if (ret2 < 0)
+ if (ret2 < 0) {
return ERR_PARSE_ERROR;
+ }
} else {
ret2 = GDScriptFunction::ADDR_TYPE_NIL << GDScriptFunction::ADDR_BITS;
@@ -1479,14 +1557,16 @@ Error GDScriptCompiler::_parse_block(CodeGen &codegen, const GDScriptParser::Blo
const GDScriptParser::AssertNode *as = static_cast<const GDScriptParser::AssertNode *>(s);
int ret2 = _parse_expression(codegen, as->condition, p_stack_level, false);
- if (ret2 < 0)
+ if (ret2 < 0) {
return ERR_PARSE_ERROR;
+ }
int message_ret = 0;
if (as->message) {
message_ret = _parse_expression(codegen, as->message, p_stack_level + 1, false);
- if (message_ret < 0)
+ if (message_ret < 0) {
return ERR_PARSE_ERROR;
+ }
}
codegen.opcodes.push_back(GDScriptFunction::OPCODE_ASSERT);
@@ -1518,8 +1598,9 @@ Error GDScriptCompiler::_parse_block(CodeGen &codegen, const GDScriptParser::Blo
default: {
//expression
int ret2 = _parse_expression(codegen, s, p_stack_level, true);
- if (ret2 < 0)
+ if (ret2 < 0) {
return ERR_PARSE_ERROR;
+ }
} break;
}
}
@@ -1575,8 +1656,9 @@ Error GDScriptCompiler::_parse_function(GDScript *p_script, const GDScriptParser
codegen.opcodes.push_back((GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS) | 0);
}
Error err = _parse_block(codegen, p_class->initializer, stack_level);
- if (err)
+ if (err) {
return err;
+ }
is_initializer = true;
}
@@ -1584,8 +1666,9 @@ Error GDScriptCompiler::_parse_function(GDScript *p_script, const GDScriptParser
//parse initializer for class members
if (p_class->ready->statements.size()) {
Error err = _parse_block(codegen, p_class->ready, stack_level);
- if (err)
+ if (err) {
return err;
+ }
}
}
@@ -1607,15 +1690,17 @@ Error GDScriptCompiler::_parse_function(GDScript *p_script, const GDScriptParser
}
Error err = _parse_block(codegen, p_func->body, stack_level);
- if (err)
+ if (err) {
return err;
+ }
func_name = p_func->name;
} else {
- if (p_for_ready)
+ if (p_for_ready) {
func_name = "_ready";
- else
+ } else {
func_name = "_init";
+ }
}
codegen.opcodes.push_back(GDScriptFunction::OPCODE_END);
@@ -1716,8 +1801,9 @@ Error GDScriptCompiler::_parse_function(GDScript *p_script, const GDScriptParser
if (EngineDebugger::is_active()) {
String signature;
//path
- if (p_script->get_path() != String())
+ if (p_script->get_path() != String()) {
signature += p_script->get_path();
+ }
//loc
if (p_func) {
signature += "::" + itos(p_func->body->line);
@@ -1757,11 +1843,13 @@ Error GDScriptCompiler::_parse_function(GDScript *p_script, const GDScriptParser
gdfunc->_initial_line = 0;
}
- if (codegen.debug_stack)
+ if (codegen.debug_stack) {
gdfunc->stack_debug = codegen.stack_debug;
+ }
- if (is_initializer)
+ if (is_initializer) {
p_script->initializer = gdfunc;
+ }
return OK;
}
@@ -1931,8 +2019,9 @@ Error GDScriptCompiler::_parse_class_level(GDScript *p_script, const GDScriptPar
// Subclass might still be parsing, just skip it
if (!parsed_classes.has(subclass_ptr) && !parsing_classes.has(subclass_ptr)) {
Error err = _parse_class_level(subclass_ptr, p_class->subclasses[i], p_keep_state);
- if (err)
+ if (err) {
return err;
+ }
}
#ifdef TOOLS_ENABLED
@@ -1953,35 +2042,41 @@ Error GDScriptCompiler::_parse_class_blocks(GDScript *p_script, const GDScriptPa
bool has_ready = false;
for (int i = 0; i < p_class->functions.size(); i++) {
- if (!has_initializer && p_class->functions[i]->name == "_init")
+ if (!has_initializer && p_class->functions[i]->name == "_init") {
has_initializer = true;
- if (!has_ready && p_class->functions[i]->name == "_ready")
+ }
+ if (!has_ready && p_class->functions[i]->name == "_ready") {
has_ready = true;
+ }
Error err = _parse_function(p_script, p_class, p_class->functions[i]);
- if (err)
+ if (err) {
return err;
+ }
}
//parse static methods
for (int i = 0; i < p_class->static_functions.size(); i++) {
Error err = _parse_function(p_script, p_class, p_class->static_functions[i]);
- if (err)
+ if (err) {
return err;
+ }
}
if (!has_initializer) {
//create a constructor
Error err = _parse_function(p_script, p_class, nullptr);
- if (err)
+ if (err) {
return err;
+ }
}
if (!has_ready && p_class->ready->statements.size()) {
//create a constructor
Error err = _parse_function(p_script, p_class, nullptr, true);
- if (err)
+ if (err) {
return err;
+ }
}
#ifdef DEBUG_ENABLED
@@ -2101,13 +2196,15 @@ Error GDScriptCompiler::compile(const GDScriptParser *p_parser, GDScript *p_scri
p_script->_owner = nullptr;
Error err = _parse_class_level(p_script, static_cast<const GDScriptParser::ClassNode *>(root), p_keep_state);
- if (err)
+ if (err) {
return err;
+ }
err = _parse_class_blocks(p_script, static_cast<const GDScriptParser::ClassNode *>(root), p_keep_state);
- if (err)
+ if (err) {
return err;
+ }
return OK;
}
diff --git a/modules/gdscript/gdscript_compiler.h b/modules/gdscript/gdscript_compiler.h
index 3a362c75bc..315d4f1842 100644
--- a/modules/gdscript/gdscript_compiler.h
+++ b/modules/gdscript/gdscript_compiler.h
@@ -110,8 +110,9 @@ class GDScriptCompiler {
}
int get_constant_pos(const Variant &p_constant) {
- if (constant_map.has(p_constant))
+ if (constant_map.has(p_constant)) {
return constant_map[p_constant];
+ }
int pos = constant_map.size();
constant_map[p_constant] = pos;
return pos;
@@ -119,12 +120,14 @@ class GDScriptCompiler {
Vector<int> opcodes;
void alloc_stack(int p_level) {
- if (p_level >= stack_max)
+ if (p_level >= stack_max) {
stack_max = p_level + 1;
+ }
}
void alloc_call(int p_params) {
- if (p_params >= call_max)
+ if (p_params >= call_max) {
call_max = p_params;
+ }
}
int current_line;
diff --git a/modules/gdscript/gdscript_editor.cpp b/modules/gdscript/gdscript_editor.cpp
index 8aa7809347..7433c4a5bc 100644
--- a/modules/gdscript/gdscript_editor.cpp
+++ b/modules/gdscript/gdscript_editor.cpp
@@ -232,15 +232,17 @@ String GDScriptLanguage::debug_get_error() const {
}
int GDScriptLanguage::debug_get_stack_level_count() const {
- if (_debug_parse_err_line >= 0)
+ if (_debug_parse_err_line >= 0) {
return 1;
+ }
return _debug_call_stack_pos;
}
int GDScriptLanguage::debug_get_stack_level_line(int p_level) const {
- if (_debug_parse_err_line >= 0)
+ if (_debug_parse_err_line >= 0) {
return _debug_parse_err_line;
+ }
ERR_FAIL_INDEX_V(p_level, _debug_call_stack_pos, -1);
@@ -250,8 +252,9 @@ int GDScriptLanguage::debug_get_stack_level_line(int p_level) const {
}
String GDScriptLanguage::debug_get_stack_level_function(int p_level) const {
- if (_debug_parse_err_line >= 0)
+ if (_debug_parse_err_line >= 0) {
return "";
+ }
ERR_FAIL_INDEX_V(p_level, _debug_call_stack_pos, "");
int l = _debug_call_stack_pos - p_level - 1;
@@ -259,8 +262,9 @@ String GDScriptLanguage::debug_get_stack_level_function(int p_level) const {
}
String GDScriptLanguage::debug_get_stack_level_source(int p_level) const {
- if (_debug_parse_err_line >= 0)
+ if (_debug_parse_err_line >= 0) {
return _debug_parse_err_file;
+ }
ERR_FAIL_INDEX_V(p_level, _debug_call_stack_pos, "");
int l = _debug_call_stack_pos - p_level - 1;
@@ -268,8 +272,9 @@ String GDScriptLanguage::debug_get_stack_level_source(int p_level) const {
}
void GDScriptLanguage::debug_get_stack_level_locals(int p_level, List<String> *p_locals, List<Variant> *p_values, int p_max_subitems, int p_max_depth) {
- if (_debug_parse_err_line >= 0)
+ if (_debug_parse_err_line >= 0) {
return;
+ }
ERR_FAIL_INDEX(p_level, _debug_call_stack_pos);
int l = _debug_call_stack_pos - p_level - 1;
@@ -286,16 +291,18 @@ void GDScriptLanguage::debug_get_stack_level_locals(int p_level, List<String> *p
}
void GDScriptLanguage::debug_get_stack_level_members(int p_level, List<String> *p_members, List<Variant> *p_values, int p_max_subitems, int p_max_depth) {
- if (_debug_parse_err_line >= 0)
+ if (_debug_parse_err_line >= 0) {
return;
+ }
ERR_FAIL_INDEX(p_level, _debug_call_stack_pos);
int l = _debug_call_stack_pos - p_level - 1;
GDScriptInstance *instance = _call_stack[l].instance;
- if (!instance)
+ if (!instance) {
return;
+ }
Ref<GDScript> script = instance->get_script();
ERR_FAIL_COND(script.is_null());
@@ -309,8 +316,9 @@ void GDScriptLanguage::debug_get_stack_level_members(int p_level, List<String> *
}
ScriptInstance *GDScriptLanguage::debug_get_stack_level_instance(int p_level) {
- if (_debug_parse_err_line >= 0)
+ if (_debug_parse_err_line >= 0) {
return nullptr;
+ }
ERR_FAIL_INDEX_V(p_level, _debug_call_stack_pos, nullptr);
@@ -328,8 +336,9 @@ void GDScriptLanguage::debug_get_globals(List<String> *p_globals, List<Variant>
get_public_constants(&cinfo);
for (const Map<StringName, int>::Element *E = name_idx.front(); E; E = E->next()) {
- if (ClassDB::class_exists(E->key()) || Engine::get_singleton()->has_singleton(E->key()))
+ if (ClassDB::class_exists(E->key()) || Engine::get_singleton()->has_singleton(E->key())) {
continue;
+ }
bool is_script_constant = false;
for (List<Pair<String, Variant>>::Element *CE = cinfo.front(); CE; CE = CE->next()) {
@@ -338,13 +347,15 @@ void GDScriptLanguage::debug_get_globals(List<String> *p_globals, List<Variant>
break;
}
}
- if (is_script_constant)
+ if (is_script_constant) {
continue;
+ }
const Variant &var = globals[E->value()];
if (Object *obj = var) {
- if (Object::cast_to<GDScriptNativeClass>(obj))
+ if (Object::cast_to<GDScriptNativeClass>(obj)) {
continue;
+ }
}
bool skip = false;
@@ -354,8 +365,9 @@ void GDScriptLanguage::debug_get_globals(List<String> *p_globals, List<Variant>
break;
}
}
- if (skip)
+ if (skip) {
continue;
+ }
p_globals->push_back(E->key());
p_values->push_back(var);
@@ -436,8 +448,9 @@ String GDScriptLanguage::make_function(const String &p_class, const String &p_na
String s = "func " + p_name + "(";
if (p_args.size()) {
for (int i = 0; i < p_args.size(); i++) {
- if (i > 0)
+ if (i > 0) {
s += ", ";
+ }
s += p_args[i].get_slice(":", 0);
if (th) {
String type = p_args[i].get_slice(":", 1);
@@ -2994,8 +3007,9 @@ void GDScriptLanguage::auto_indent_code(String &p_code, int p_from_line, int p_t
}
String st = l.substr(tc, l.length()).strip_edges();
- if (st == "" || st.begins_with("#"))
+ if (st == "" || st.begins_with("#")) {
continue; //ignore!
+ }
int ilevel = 0;
if (indent_stack.size()) {
@@ -3009,8 +3023,9 @@ void GDScriptLanguage::auto_indent_code(String &p_code, int p_from_line, int p_t
indent_stack.pop_back();
}
- if (indent_stack.size() && indent_stack.back()->get() != tc)
+ if (indent_stack.size() && indent_stack.back()->get() != tc) {
indent_stack.push_back(tc); //this is not right but gets the job done
+ }
}
if (i >= p_from_line) {
@@ -3029,8 +3044,9 @@ void GDScriptLanguage::auto_indent_code(String &p_code, int p_from_line, int p_t
p_code = "";
for (int i = 0; i < lines.size(); i++) {
- if (i > 0)
+ if (i > 0) {
p_code += "\n";
+ }
p_code += lines[i];
}
}
@@ -3349,8 +3365,9 @@ Error GDScriptLanguage::lookup_code(const String &p_code, const String &p_symbol
for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
String s = E->get().name;
- if (!s.begins_with("autoload/"))
+ if (!s.begins_with("autoload/")) {
continue;
+ }
String name = s.get_slice("/", 1);
if (name == String(p_symbol)) {
String path = ProjectSettings::get_singleton()->get(s);
diff --git a/modules/gdscript/gdscript_function.cpp b/modules/gdscript/gdscript_function.cpp
index aa2ea149f5..92e07ab874 100644
--- a/modules/gdscript/gdscript_function.cpp
+++ b/modules/gdscript/gdscript_function.cpp
@@ -140,10 +140,11 @@ static String _get_var_type(const Variant *p_var) {
basestr = "previously freed";
}
} else {
- if (bobj->get_script_instance())
+ if (bobj->get_script_instance()) {
basestr = bobj->get_class() + " (" + bobj->get_script_instance()->get_script()->get_path().get_file() + ")";
- else
+ } else {
basestr = bobj->get_class();
+ }
}
} else {
@@ -366,8 +367,9 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
#ifdef DEBUG_ENABLED
- if (EngineDebugger::is_active())
+ if (EngineDebugger::is_active()) {
GDScriptLanguage::get_singleton()->enter_function(p_instance, this, stack, &ip, &line);
+ }
#define GD_ERR_BREAK(m_cond) \
{ \
@@ -1149,8 +1151,9 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
while (gds->base.ptr()) {
gds = gds->base.ptr();
E = gds->member_functions.find(*methodname);
- if (E)
+ if (E) {
break;
+ }
}
Callable::CallError err;
@@ -1466,14 +1469,17 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
bool do_break = false;
if (EngineDebugger::get_script_debugger()->get_lines_left() > 0) {
- if (EngineDebugger::get_script_debugger()->get_depth() <= 0)
+ if (EngineDebugger::get_script_debugger()->get_depth() <= 0) {
EngineDebugger::get_script_debugger()->set_lines_left(EngineDebugger::get_script_debugger()->get_lines_left() - 1);
- if (EngineDebugger::get_script_debugger()->get_lines_left() <= 0)
+ }
+ if (EngineDebugger::get_script_debugger()->get_lines_left() <= 0) {
do_break = true;
+ }
}
- if (EngineDebugger::get_script_debugger()->is_breakpoint(line, source))
+ if (EngineDebugger::get_script_debugger()->is_breakpoint(line, source)) {
do_break = true;
+ }
if (do_break) {
GDScriptLanguage::get_singleton()->debug_break("Breakpoint", true);
@@ -1501,20 +1507,24 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
OPCODES_END
#ifdef DEBUG_ENABLED
- if (exit_ok)
+ if (exit_ok) {
OPCODE_OUT;
+ }
//error
// function, file, line, error, explanation
String err_file;
- if (p_instance && ObjectDB::get_instance(p_instance->owner_id) != nullptr && p_instance->script->is_valid() && p_instance->script->path != "")
+ if (p_instance && ObjectDB::get_instance(p_instance->owner_id) != nullptr && p_instance->script->is_valid() && p_instance->script->path != "") {
err_file = p_instance->script->path;
- else if (script)
+ } else if (script) {
err_file = script->path;
- if (err_file == "")
+ }
+ if (err_file == "") {
err_file = "<built-in>";
+ }
String err_func = name;
- if (p_instance && ObjectDB::get_instance(p_instance->owner_id) != nullptr && p_instance->script->is_valid() && p_instance->script->name != "")
+ if (p_instance && ObjectDB::get_instance(p_instance->owner_id) != nullptr && p_instance->script->is_valid() && p_instance->script->name != "") {
err_func = p_instance->script->name + "." + err_func;
+ }
int err_line = line;
if (err_text == "") {
err_text = "Internal Script Error! - opcode #" + itos(last_opcode) + " (report please).";
@@ -1546,14 +1556,16 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
// When it's the last resume it will postpone the exit from stack,
// so the debugger knows which function triggered the resume of the next function (if any)
if (!p_state || yielded) {
- if (EngineDebugger::is_active())
+ if (EngineDebugger::is_active()) {
GDScriptLanguage::get_singleton()->exit_function();
+ }
#endif
if (_stack_size) {
//free stack
- for (int i = 0; i < _stack_size; i++)
+ for (int i = 0; i < _stack_size; i++) {
stack[i].~Variant();
+ }
}
#ifdef DEBUG_ENABLED
@@ -1627,8 +1639,9 @@ void GDScriptFunction::debug_get_stack_member_state(int p_line, List<Pair<String
Map<StringName, _GDFKC> sdmap;
for (const List<StackDebug>::Element *E = stack_debug.front(); E; E = E->next()) {
const StackDebug &sd = E->get();
- if (sd.line > p_line)
+ if (sd.line > p_line) {
break;
+ }
if (sd.added) {
if (!sdmap.has(sd.identifier)) {
@@ -1644,8 +1657,9 @@ void GDScriptFunction::debug_get_stack_member_state(int p_line, List<Pair<String
ERR_CONTINUE(!sdmap.has(sd.identifier));
sdmap[sd.identifier].pos.pop_back();
- if (sdmap[sd.identifier].pos.empty())
+ if (sdmap[sd.identifier].pos.empty()) {
sdmap.erase(sd.identifier);
+ }
}
}
@@ -1740,8 +1754,9 @@ Variant GDScriptFunctionState::_signal_callback(const Variant **p_args, int p_ar
}
bool GDScriptFunctionState::is_valid(bool p_extended_check) const {
- if (function == nullptr)
+ if (function == nullptr) {
return false;
+ }
if (p_extended_check) {
MutexLock lock(GDScriptLanguage::get_singleton()->lock);
@@ -1812,8 +1827,9 @@ Variant GDScriptFunctionState::resume(const Variant &p_arg) {
}
#ifdef DEBUG_ENABLED
- if (EngineDebugger::is_active())
+ if (EngineDebugger::is_active()) {
GDScriptLanguage::get_singleton()->exit_function();
+ }
#endif
}
@@ -1823,8 +1839,9 @@ Variant GDScriptFunctionState::resume(const Variant &p_arg) {
void GDScriptFunctionState::_clear_stack() {
if (state.stack_size) {
Variant *stack = (Variant *)state.stack.ptr();
- for (int i = 0; i < state.stack_size; i++)
+ for (int i = 0; i < state.stack_size; i++) {
stack[i].~Variant();
+ }
state.stack_size = 0;
}
}
diff --git a/modules/gdscript/gdscript_function.h b/modules/gdscript/gdscript_function.h
index 490da102c0..583eab744a 100644
--- a/modules/gdscript/gdscript_function.h
+++ b/modules/gdscript/gdscript_function.h
@@ -59,8 +59,9 @@ struct GDScriptDataType {
Ref<Script> script_type;
bool is_type(const Variant &p_variant, bool p_allow_implicit_conversion = false) const {
- if (!has_type)
+ if (!has_type) {
return true; // Can't type check
+ }
switch (kind) {
case UNINITIALIZED:
diff --git a/modules/gdscript/gdscript_functions.cpp b/modules/gdscript/gdscript_functions.cpp
index 5df2c79df5..d4258c385e 100644
--- a/modules/gdscript/gdscript_functions.cpp
+++ b/modules/gdscript/gdscript_functions.cpp
@@ -672,10 +672,11 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_
for (int i = 0; i < p_arg_count; i++) {
String os = p_args[i]->operator String();
- if (i == 0)
+ if (i == 0) {
str = os;
- else
+ } else {
str += os;
+ }
}
r_ret = str;
@@ -694,8 +695,9 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_
case TEXT_PRINT_TABBED: {
String str;
for (int i = 0; i < p_arg_count; i++) {
- if (i)
+ if (i) {
str += "\t";
+ }
str += p_args[i]->operator String();
}
@@ -706,8 +708,9 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_
case TEXT_PRINT_SPACED: {
String str;
for (int i = 0; i < p_arg_count; i++) {
- if (i)
+ if (i) {
str += " ";
+ }
str += p_args[i]->operator String();
}
@@ -936,8 +939,9 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_
r_ret = Variant();
return;
}
- for (int i = from; i < to; i++)
+ for (int i = from; i < to; i++) {
arr[i - from] = i;
+ }
r_ret = arr;
} break;
case 3: {
diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp
index 09f5b13e22..d8f2c16638 100644
--- a/modules/gdscript/gdscript_parser.cpp
+++ b/modules/gdscript/gdscript_parser.cpp
@@ -47,8 +47,9 @@ T *GDScriptParser::alloc_node() {
t->next = list;
list = t;
- if (!head)
+ if (!head) {
head = t;
+ }
t->line = tokenizer->get_token_line();
t->column = tokenizer->get_token_column();
@@ -269,8 +270,9 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s
parenthesis++;
Node *subexpr = _parse_expression(p_parent, p_static, p_allow_assign, p_parsing_constant);
parenthesis--;
- if (!subexpr)
+ if (!subexpr) {
return nullptr;
+ }
if (tokenizer->get_token() != GDScriptTokenizer::TK_PARENTHESIS_CLOSE) {
_set_error("Expected ')' in expression");
@@ -463,8 +465,9 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s
return nullptr;
}
- if (!path.is_abs_path() && base_path != "")
+ if (!path.is_abs_path() && base_path != "") {
path = base_path.plus_file(path);
+ }
path = path.replace("///", "//").simplify_path();
if (path == self_path) {
_set_error("Can't preload itself (use 'get_script()').");
@@ -543,8 +546,9 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s
parenthesis++;
Node *object = _parse_and_reduce_expression(p_parent, p_static);
- if (!object)
+ if (!object) {
return nullptr;
+ }
yield->arguments.push_back(object);
if (tokenizer->get_token() != GDScriptTokenizer::TK_COMMA) {
@@ -568,8 +572,9 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s
}
Node *signal = _parse_and_reduce_expression(p_parent, p_static);
- if (!signal)
+ if (!signal) {
return nullptr;
+ }
yield->arguments.push_back(signal);
if (tokenizer->get_token() != GDScriptTokenizer::TK_PARENTHESIS_CLOSE) {
@@ -628,8 +633,9 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s
id->name = identifier;
op->arguments.push_back(id);
- if (!_parse_arguments(op, op->arguments, p_static, true, p_parsing_constant))
+ if (!_parse_arguments(op, op->arguments, p_static, true, p_parsing_constant)) {
return nullptr;
+ }
expr = op;
} else {
@@ -724,8 +730,9 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s
}
}
if (!replaced) {
- if (!_parse_arguments(op, op->arguments, p_static, true, p_parsing_constant))
+ if (!_parse_arguments(op, op->arguments, p_static, true, p_parsing_constant)) {
return nullptr;
+ }
expr = op;
}
} else if (tokenizer->is_token_literal(0, true)) {
@@ -961,8 +968,9 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s
return nullptr;
}
Node *n = _parse_expression(arr, p_static, p_allow_assign, p_parsing_constant);
- if (!n)
+ if (!n) {
return nullptr;
+ }
arr->elements.push_back(n);
expecting_comma = true;
}
@@ -1063,16 +1071,18 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s
} else {
//python/js style more flexible
key = _parse_expression(dict, p_static, p_allow_assign, p_parsing_constant);
- if (!key)
+ if (!key) {
return nullptr;
+ }
expecting = DICT_EXPECT_COLON;
}
}
if (expecting == DICT_EXPECT_VALUE) {
Node *value = _parse_expression(dict, p_static, p_allow_assign, p_parsing_constant);
- if (!value)
+ if (!value) {
return nullptr;
+ }
expecting = DICT_EXPECT_COMMA;
if (key->type == GDScriptParser::Node::TYPE_CONSTANT) {
@@ -1183,8 +1193,9 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s
_make_completable_call(0);
completion_node = op;
}
- if (!_parse_arguments(op, op->arguments, p_static, true, p_parsing_constant))
+ if (!_parse_arguments(op, op->arguments, p_static, true, p_parsing_constant)) {
return nullptr;
+ }
expr = op;
} else {
@@ -1235,8 +1246,9 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s
tokenizer->advance(1);
expr = op;
- } else
+ } else {
break;
+ }
}
/*****************/
@@ -1720,8 +1732,9 @@ GDScriptParser::Node *GDScriptParser::_reduce_expression(Node *p_node, bool p_to
for (int i = 0; i < an->elements.size(); i++) {
an->elements.write[i] = _reduce_expression(an->elements[i], p_to_const);
- if (an->elements[i]->type != Node::TYPE_CONSTANT)
+ if (an->elements[i]->type != Node::TYPE_CONSTANT) {
all_constants = false;
+ }
}
if (all_constants && p_to_const) {
@@ -1748,11 +1761,13 @@ GDScriptParser::Node *GDScriptParser::_reduce_expression(Node *p_node, bool p_to
for (int i = 0; i < dn->elements.size(); i++) {
dn->elements.write[i].key = _reduce_expression(dn->elements[i].key, p_to_const);
- if (dn->elements[i].key->type != Node::TYPE_CONSTANT)
+ if (dn->elements[i].key->type != Node::TYPE_CONSTANT) {
all_constants = false;
+ }
dn->elements.write[i].value = _reduce_expression(dn->elements[i].value, p_to_const);
- if (dn->elements[i].value->type != Node::TYPE_CONSTANT)
+ if (dn->elements[i].value->type != Node::TYPE_CONSTANT) {
all_constants = false;
+ }
}
if (all_constants && p_to_const) {
@@ -1952,8 +1967,9 @@ GDScriptParser::Node *GDScriptParser::_reduce_expression(Node *p_node, bool p_to
}
}
//now se if all are constants
- if (!all_constants)
+ if (!all_constants) {
return op; //nothing to reduce from here on
+ }
#define _REDUCE_UNARY(m_vop) \
bool valid = false; \
Variant res; \
@@ -2075,11 +2091,13 @@ GDScriptParser::Node *GDScriptParser::_reduce_expression(Node *p_node, bool p_to
GDScriptParser::Node *GDScriptParser::_parse_and_reduce_expression(Node *p_parent, bool p_static, bool p_reduce_const, bool p_allow_assign) {
Node *expr = _parse_expression(p_parent, p_static, p_allow_assign, p_reduce_const);
- if (!expr || error_set)
+ if (!expr || error_set) {
return nullptr;
+ }
expr = _reduce_expression(expr, p_reduce_const);
- if (!expr || error_set)
+ if (!expr || error_set) {
return nullptr;
+ }
return expr;
}
@@ -2087,8 +2105,9 @@ bool GDScriptParser::_reduce_export_var_type(Variant &p_value, int p_line) {
if (p_value.get_type() == Variant::ARRAY) {
Array arr = p_value;
for (int i = 0; i < arr.size(); i++) {
- if (!_reduce_export_var_type(arr[i], p_line))
+ if (!_reduce_export_var_type(arr[i], p_line)) {
return false;
+ }
}
return true;
}
@@ -2097,8 +2116,9 @@ bool GDScriptParser::_reduce_export_var_type(Variant &p_value, int p_line) {
Dictionary dict = p_value;
for (int i = 0; i < dict.size(); i++) {
Variant value = dict.get_value_at_index(i);
- if (!_reduce_export_var_type(value, p_line))
+ if (!_reduce_export_var_type(value, p_line)) {
return false;
+ }
}
return true;
}
@@ -2137,8 +2157,9 @@ GDScriptParser::PatternNode *GDScriptParser::_parse_pattern(bool p_static) {
PatternNode *pattern = alloc_node<PatternNode>();
GDScriptTokenizer::Token token = tokenizer->get_token();
- if (error_set)
+ if (error_set) {
return nullptr;
+ }
if (token == GDScriptTokenizer::TK_EOF) {
return nullptr;
@@ -2333,12 +2354,14 @@ void GDScriptParser::_parse_pattern_block(BlockNode *p_block, Vector<PatternBran
bool catch_all_appeared = false;
while (true) {
- while (tokenizer->get_token() == GDScriptTokenizer::TK_NEWLINE && _parse_newline())
+ while (tokenizer->get_token() == GDScriptTokenizer::TK_NEWLINE && _parse_newline()) {
;
+ }
// GDScriptTokenizer::Token token = tokenizer->get_token();
- if (error_set)
+ if (error_set) {
return;
+ }
if (current_level.indent > indent_level.back()->get().indent) {
break; // go back a level
@@ -2820,8 +2843,9 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) {
is_first_line = false;
GDScriptTokenizer::Token token = tokenizer->get_token();
- if (error_set)
+ if (error_set) {
return;
+ }
if (current_level.indent > indent_level.back()->get().indent) {
p_block->end_line = tokenizer->get_token_line();
@@ -3007,16 +3031,18 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) {
_parse_block(cf_if->body, p_static);
current_block = p_block;
- if (error_set)
+ if (error_set) {
return;
+ }
p_block->statements.push_back(cf_if);
bool all_have_return = cf_if->body->has_return;
bool have_else = false;
while (true) {
- while (tokenizer->get_token() == GDScriptTokenizer::TK_NEWLINE && _parse_newline())
+ while (tokenizer->get_token() == GDScriptTokenizer::TK_NEWLINE && _parse_newline()) {
;
+ }
if (indent_level.back()->get().indent < current_level.indent) { //not at current indent level
p_block->end_line = tokenizer->get_token_line();
@@ -3064,8 +3090,9 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) {
current_block = cf_else->body;
_parse_block(cf_else->body, p_static);
current_block = p_block;
- if (error_set)
+ if (error_set) {
return;
+ }
all_have_return = all_have_return && cf_else->body->has_return;
@@ -3088,16 +3115,18 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) {
current_block = cf_if->body_else;
_parse_block(cf_if->body_else, p_static);
current_block = p_block;
- if (error_set)
+ if (error_set) {
return;
+ }
all_have_return = all_have_return && cf_if->body_else->has_return;
have_else = true;
break; //after else, exit
- } else
+ } else {
break;
+ }
}
cf_if->body->has_return = all_have_return;
@@ -3133,8 +3162,9 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) {
current_block = cf_while->body;
_parse_block(cf_while->body, p_static);
current_block = p_block;
- if (error_set)
+ if (error_set) {
return;
+ }
p_block->has_return = cf_while->body->has_return;
p_block->statements.push_back(cf_while);
} break;
@@ -3271,8 +3301,9 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) {
_parse_block(cf_for->body, p_static);
current_block = p_block;
- if (error_set)
+ if (error_set) {
return;
+ }
p_block->has_return = cf_for->body->has_return;
p_block->statements.push_back(cf_for);
} break;
@@ -3358,8 +3389,9 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) {
_parse_pattern_block(compiled_branches, match_node->branches, p_static);
- if (error_set)
+ if (error_set) {
return;
+ }
ControlFlowNode *match_cf_node = alloc_node<ControlFlowNode>();
match_cf_node->cf_type = ControlFlowNode::CF_MATCH;
@@ -3538,8 +3570,9 @@ void GDScriptParser::_parse_extends(ClassNode *p_class) {
if (tokenizer->get_token() != GDScriptTokenizer::TK_PERIOD) {
return;
- } else
+ } else {
tokenizer->advance();
+ }
}
while (true) {
@@ -3576,8 +3609,9 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
while (true) {
GDScriptTokenizer::Token token = tokenizer->get_token();
- if (error_set)
+ if (error_set) {
return;
+ }
if (current_level.indent > indent_level.back()->get().indent) {
p_class->end_line = tokenizer->get_token_line();
@@ -3606,8 +3640,9 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
case GDScriptTokenizer::TK_PR_EXTENDS: {
_mark_line_as_safe(tokenizer->get_token_line());
_parse_extends(p_class);
- if (error_set)
+ if (error_set) {
return;
+ }
if (!_end_statement()) {
_set_end_statement_error("extends");
return;
@@ -3754,8 +3789,9 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
if (tokenizer->get_token() == GDScriptTokenizer::TK_PR_EXTENDS) {
_parse_extends(newclass);
- if (error_set)
+ if (error_set) {
return;
+ }
}
if (!_enter_indent_block()) {
@@ -3899,8 +3935,9 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
defaulting = true;
tokenizer->advance(1);
Node *defval = _parse_and_reduce_expression(p_class, _static);
- if (!defval || error_set)
+ if (!defval || error_set) {
return;
+ }
OperatorNode *on = alloc_node<OperatorNode>();
on->op = OperatorNode::OP_ASSIGN;
@@ -4025,10 +4062,11 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
function->return_type = return_type;
- if (_static)
+ if (_static) {
p_class->static_functions.push_back(function);
- else
+ } else {
p_class->functions.push_back(function);
+ }
current_function = function;
function->body = block;
@@ -4160,16 +4198,18 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
}
String c = tokenizer->get_token_constant();
- if (!first)
+ if (!first) {
current_export.hint_string += ",";
- else
+ } else {
first = false;
+ }
current_export.hint_string += c.xml_escape();
_ADVANCE_AND_CONSUME_NEWLINES;
- if (tokenizer->get_token() == GDScriptTokenizer::TK_PARENTHESIS_CLOSE)
+ if (tokenizer->get_token() == GDScriptTokenizer::TK_PARENTHESIS_CLOSE) {
break;
+ }
if (tokenizer->get_token() != GDScriptTokenizer::TK_COMMA) {
current_export = PropertyInfo();
@@ -4234,16 +4274,18 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
}
String c = tokenizer->get_token_constant();
- if (!first)
+ if (!first) {
current_export.hint_string += ",";
- else
+ } else {
first = false;
+ }
current_export.hint_string += c.xml_escape();
_ADVANCE_AND_CONSUME_NEWLINES;
- if (tokenizer->get_token() == GDScriptTokenizer::TK_PARENTHESIS_CLOSE)
+ if (tokenizer->get_token() == GDScriptTokenizer::TK_PARENTHESIS_CLOSE) {
break;
+ }
if (tokenizer->get_token() != GDScriptTokenizer::TK_COMMA) {
current_export = PropertyInfo();
@@ -4275,15 +4317,16 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
current_export.hint = PROPERTY_HINT_EXP_RANGE;
_ADVANCE_AND_CONSUME_NEWLINES;
- if (tokenizer->get_token() == GDScriptTokenizer::TK_PARENTHESIS_CLOSE)
+ if (tokenizer->get_token() == GDScriptTokenizer::TK_PARENTHESIS_CLOSE) {
break;
- else if (tokenizer->get_token() != GDScriptTokenizer::TK_COMMA) {
+ } else if (tokenizer->get_token() != GDScriptTokenizer::TK_COMMA) {
_set_error("Expected \")\" or \",\" in the exponential range hint.");
return;
}
_ADVANCE_AND_CONSUME_NEWLINES;
- } else
+ } else {
current_export.hint = PROPERTY_HINT_RANGE;
+ }
float sign = 1.0;
@@ -4328,8 +4371,9 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
current_export.hint_string += "," + rtos(sign * double(tokenizer->get_token_constant()));
_ADVANCE_AND_CONSUME_NEWLINES;
- if (tokenizer->get_token() == GDScriptTokenizer::TK_PARENTHESIS_CLOSE)
+ if (tokenizer->get_token() == GDScriptTokenizer::TK_PARENTHESIS_CLOSE) {
break;
+ }
if (tokenizer->get_token() != GDScriptTokenizer::TK_COMMA) {
current_export = PropertyInfo();
@@ -4367,15 +4411,17 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
}
String c = tokenizer->get_token_constant();
- if (!first)
+ if (!first) {
current_export.hint_string += ",";
- else
+ } else {
first = false;
+ }
current_export.hint_string += c.xml_escape();
_ADVANCE_AND_CONSUME_NEWLINES;
- if (tokenizer->get_token() == GDScriptTokenizer::TK_PARENTHESIS_CLOSE)
+ if (tokenizer->get_token() == GDScriptTokenizer::TK_PARENTHESIS_CLOSE) {
break;
+ }
if (tokenizer->get_token() != GDScriptTokenizer::TK_COMMA) {
current_export = PropertyInfo();
@@ -4391,9 +4437,9 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
if (tokenizer->get_token() == GDScriptTokenizer::TK_IDENTIFIER && tokenizer->get_token_identifier() == "DIR") {
_ADVANCE_AND_CONSUME_NEWLINES;
- if (tokenizer->get_token() == GDScriptTokenizer::TK_PARENTHESIS_CLOSE)
+ if (tokenizer->get_token() == GDScriptTokenizer::TK_PARENTHESIS_CLOSE) {
current_export.hint = PROPERTY_HINT_DIR;
- else if (tokenizer->get_token() == GDScriptTokenizer::TK_COMMA) {
+ } else if (tokenizer->get_token() == GDScriptTokenizer::TK_COMMA) {
_ADVANCE_AND_CONSUME_NEWLINES;
if (tokenizer->get_token() != GDScriptTokenizer::TK_IDENTIFIER || !(tokenizer->get_token_identifier() == "GLOBAL")) {
@@ -4433,21 +4479,22 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
current_export.hint = PROPERTY_HINT_GLOBAL_FILE;
_ADVANCE_AND_CONSUME_NEWLINES;
- if (tokenizer->get_token() == GDScriptTokenizer::TK_PARENTHESIS_CLOSE)
+ if (tokenizer->get_token() == GDScriptTokenizer::TK_PARENTHESIS_CLOSE) {
break;
- else if (tokenizer->get_token() == GDScriptTokenizer::TK_COMMA)
+ } else if (tokenizer->get_token() == GDScriptTokenizer::TK_COMMA) {
_ADVANCE_AND_CONSUME_NEWLINES;
- else {
+ } else {
_set_error("Expected \")\" or \",\" in the hint.");
return;
}
}
if (tokenizer->get_token() != GDScriptTokenizer::TK_CONSTANT || tokenizer->get_token_constant().get_type() != Variant::STRING) {
- if (current_export.hint == PROPERTY_HINT_GLOBAL_FILE)
+ if (current_export.hint == PROPERTY_HINT_GLOBAL_FILE) {
_set_error("Expected string constant with filter.");
- else
+ } else {
_set_error("Expected \"GLOBAL\" or string constant with filter.");
+ }
return;
}
current_export.hint_string = tokenizer->get_token_constant();
@@ -4559,10 +4606,11 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
bool first = true;
for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
if (enum_values[E->get()].get_type() == Variant::INT) {
- if (!first)
+ if (!first) {
current_export.hint_string += ",";
- else
+ } else {
first = false;
+ }
current_export.hint_string += E->get().operator String().camelcase_to_underscore(true).capitalize().xml_escape();
if (!is_flags) {
@@ -4678,10 +4726,11 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
//may be fallthrough from export, ignore if so
tokenizer->advance();
if (tokenizer->get_token() != GDScriptTokenizer::TK_PR_VAR && tokenizer->get_token() != GDScriptTokenizer::TK_PR_FUNCTION) {
- if (current_export.type)
+ if (current_export.type) {
_set_error("Expected \"var\".");
- else
+ } else {
_set_error("Expected \"var\" or \"func\".");
+ }
return;
}
@@ -4692,10 +4741,11 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
//may be fallthrough from export, ignore if so
tokenizer->advance();
if (tokenizer->get_token() != GDScriptTokenizer::TK_PR_VAR && tokenizer->get_token() != GDScriptTokenizer::TK_PR_FUNCTION) {
- if (current_export.type)
+ if (current_export.type) {
_set_error("Expected \"var\".");
- else
+ } else {
_set_error("Expected \"var\" or \"func\".");
+ }
return;
}
@@ -4706,10 +4756,11 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
//may be fallthrough from export, ignore if so
tokenizer->advance();
if (tokenizer->get_token() != GDScriptTokenizer::TK_PR_VAR && tokenizer->get_token() != GDScriptTokenizer::TK_PR_FUNCTION) {
- if (current_export.type)
+ if (current_export.type) {
_set_error("Expected \"var\".");
- else
+ } else {
_set_error("Expected \"var\" or \"func\".");
+ }
return;
}
@@ -4859,8 +4910,9 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
return;
}
- if (!_reduce_export_var_type(cn->value, member.line))
+ if (!_reduce_export_var_type(cn->value, member.line)) {
return;
+ }
member._export.type = cn->value.get_type();
member._export.usage |= PROPERTY_USAGE_SCRIPT_VARIABLE;
@@ -4906,15 +4958,17 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
#ifdef DEBUG_ENABLED
NewLineNode *nl2 = alloc_node<NewLineNode>();
nl2->line = line;
- if (onready)
+ if (onready) {
p_class->ready->statements.push_back(nl2);
- else
+ } else {
p_class->initializer->statements.push_back(nl2);
+ }
#endif
- if (onready)
+ if (onready) {
p_class->ready->statements.push_back(op);
- else
+ } else {
p_class->initializer->statements.push_back(op);
+ }
member.initial_assignment = op;
@@ -5360,10 +5414,12 @@ void GDScriptParser::_determine_inheritance(ClassNode *p_class, bool p_recursive
}
}
- if (base_class)
+ if (base_class) {
break;
- if (found)
+ }
+ if (found) {
continue;
+ }
if (p->constant_expressions.has(base)) {
if (p->constant_expressions[base].expression->type != Node::TYPE_CONSTANT) {
@@ -5457,12 +5513,14 @@ void GDScriptParser::_determine_inheritance(ClassNode *p_class, bool p_recursive
}
String GDScriptParser::DataType::to_string() const {
- if (!has_type)
+ if (!has_type) {
return "var";
+ }
switch (kind) {
case BUILTIN: {
- if (builtin_type == Variant::NIL)
+ if (builtin_type == Variant::NIL) {
return "null";
+ }
return Variant::get_type_name(builtin_type);
} break;
case NATIVE: {
@@ -5626,10 +5684,12 @@ bool GDScriptParser::_parse_type(DataType &r_type, bool p_can_be_void) {
}
GDScriptParser::DataType GDScriptParser::_resolve_type(const DataType &p_source, int p_line) {
- if (!p_source.has_type)
+ if (!p_source.has_type) {
return p_source;
- if (p_source.kind != DataType::UNRESOLVED)
+ }
+ if (p_source.kind != DataType::UNRESOLVED) {
return p_source;
+ }
Vector<String> full_name = p_source.native_type.operator String().split(".", false);
int name_part = 0;
@@ -6861,8 +6921,9 @@ bool GDScriptParser::_get_function_signature(DataType &p_base_type, const String
native = "_" + native.operator String();
}
if (!ClassDB::class_exists(native)) {
- if (!check_types)
+ if (!check_types) {
return false;
+ }
ERR_FAIL_V_MSG(false, "Parser bug: Class '" + String(native) + "' not found.");
}
@@ -6953,8 +7014,9 @@ GDScriptParser::DataType GDScriptParser::_reduce_function_call_type(const Operat
par_types.write[i - 1] = _reduce_node_type(p_call->arguments[i]);
}
- if (error_set)
+ if (error_set) {
return DataType();
+ }
// Special case: check copy constructor. Those are defined implicitly in Variant.
if (par_types.size() == 1) {
@@ -7022,8 +7084,9 @@ GDScriptParser::DataType GDScriptParser::_reduce_function_call_type(const Operat
err += "' matches the signature '";
err += Variant::get_type_name(tn->vtype) + "(";
for (int i = 0; i < par_types.size(); i++) {
- if (i > 0)
+ if (i > 0) {
err += ", ";
+ }
err += par_types[i].to_string();
}
err += ")'.";
@@ -7263,8 +7326,9 @@ bool GDScriptParser::_get_member_type(const DataType &p_base_type, const StringN
while (base) {
if (base->constant_expressions.has(p_member)) {
- if (r_is_const)
+ if (r_is_const) {
*r_is_const = true;
+ }
r_member_type = base->constant_expressions[p_member].expression->get_datatype();
return true;
}
@@ -7383,8 +7447,9 @@ bool GDScriptParser::_get_member_type(const DataType &p_base_type, const StringN
native = "_" + native.operator String();
}
if (!ClassDB::class_exists(native)) {
- if (!check_types)
+ if (!check_types) {
return false;
+ }
ERR_FAIL_V_MSG(false, "Parser bug: Class \"" + String(native) + "\" not found.");
}
@@ -7680,14 +7745,16 @@ void GDScriptParser::_check_class_level_types(ClassNode *p_class) {
// Function declarations
for (int i = 0; i < p_class->static_functions.size(); i++) {
_check_function_types(p_class->static_functions[i]);
- if (error_set)
+ if (error_set) {
return;
+ }
}
for (int i = 0; i < p_class->functions.size(); i++) {
_check_function_types(p_class->functions[i]);
- if (error_set)
+ if (error_set) {
return;
+ }
}
// Class variables
@@ -7763,8 +7830,9 @@ void GDScriptParser::_check_class_level_types(ClassNode *p_class) {
}
// Setter and getter
- if (v.setter == StringName() && v.getter == StringName())
+ if (v.setter == StringName() && v.getter == StringName()) {
continue;
+ }
bool found_getter = false;
bool found_setter = false;
@@ -7807,12 +7875,14 @@ void GDScriptParser::_check_class_level_types(ClassNode *p_class) {
return;
}
}
- if (found_getter && found_setter)
+ if (found_getter && found_setter) {
break;
+ }
}
- if ((found_getter || v.getter == StringName()) && (found_setter || v.setter == StringName()))
+ if ((found_getter || v.getter == StringName()) && (found_setter || v.setter == StringName())) {
continue;
+ }
// Check for static functions
for (int j = 0; j < p_class->static_functions.size(); j++) {
@@ -7843,8 +7913,9 @@ void GDScriptParser::_check_class_level_types(ClassNode *p_class) {
for (int i = 0; i < p_class->subclasses.size(); i++) {
current_class = p_class->subclasses[i];
_check_class_level_types(current_class);
- if (error_set)
+ if (error_set) {
return;
+ }
current_class = p_class;
}
}
@@ -7979,8 +8050,9 @@ void GDScriptParser::_check_class_blocks_types(ClassNode *p_class) {
_check_block_types(current_block);
current_block = nullptr;
current_function = nullptr;
- if (error_set)
+ if (error_set) {
return;
+ }
}
for (int i = 0; i < p_class->functions.size(); i++) {
@@ -7990,8 +8062,9 @@ void GDScriptParser::_check_class_blocks_types(ClassNode *p_class) {
_check_block_types(current_block);
current_block = nullptr;
current_function = nullptr;
- if (error_set)
+ if (error_set) {
return;
+ }
}
#ifdef DEBUG_ENABLED
@@ -8012,8 +8085,9 @@ void GDScriptParser::_check_class_blocks_types(ClassNode *p_class) {
for (int i = 0; i < p_class->subclasses.size(); i++) {
current_class = p_class->subclasses[i];
_check_class_blocks_types(current_class);
- if (error_set)
+ if (error_set) {
return;
+ }
current_class = p_class;
}
}
@@ -8280,8 +8354,9 @@ void GDScriptParser::_check_block_types(BlockNode *p_block) {
_add_warning(GDScriptWarning::RETURN_VALUE_DISCARDED, op->line, func_name);
}
#endif // DEBUG_ENABLED
- if (error_set)
+ if (error_set) {
return;
+ }
} break;
case OperatorNode::OP_YIELD: {
_mark_line_as_safe(op->line);
@@ -8316,8 +8391,9 @@ void GDScriptParser::_check_block_types(BlockNode *p_block) {
}
}
- if (!function_type.has_type)
+ if (!function_type.has_type) {
break;
+ }
if (function_type.kind == DataType::BUILTIN && function_type.builtin_type == Variant::NIL) {
// Return void, should not have arguments
@@ -8377,8 +8453,9 @@ void GDScriptParser::_check_block_types(BlockNode *p_block) {
current_block = p_block->sub_blocks[i];
_check_block_types(current_block);
current_block = p_block;
- if (error_set)
+ if (error_set) {
return;
+ }
}
#ifdef DEBUG_ENABLED
@@ -8397,8 +8474,9 @@ void GDScriptParser::_check_block_types(BlockNode *p_block) {
}
void GDScriptParser::_set_error(const String &p_error, int p_line, int p_column) {
- if (error_set)
+ if (error_set) {
return; //allow no further errors
+ }
error = p_error;
error_line = p_line < 0 ? tokenizer->get_token_line() : p_line;
@@ -8517,8 +8595,9 @@ Error GDScriptParser::_parse(const String &p_base_path) {
current_function = nullptr;
current_block = nullptr;
- if (for_completion)
+ if (for_completion) {
check_types = false;
+ }
// Resolve all class-level stuff before getting into function blocks
_check_class_level_types(main_class);
diff --git a/modules/gdscript/gdscript_parser.h b/modules/gdscript/gdscript_parser.h
index 4332fa7569..cfcca9584e 100644
--- a/modules/gdscript/gdscript_parser.h
+++ b/modules/gdscript/gdscript_parser.h
@@ -641,14 +641,16 @@ private:
void _check_block_types(BlockNode *p_block);
_FORCE_INLINE_ void _mark_line_as_safe(int p_line) const {
#ifdef DEBUG_ENABLED
- if (safe_lines)
+ if (safe_lines) {
safe_lines->insert(p_line);
+ }
#endif // DEBUG_ENABLED
}
_FORCE_INLINE_ void _mark_line_as_unsafe(int p_line) const {
#ifdef DEBUG_ENABLED
- if (safe_lines)
+ if (safe_lines) {
safe_lines->erase(p_line);
+ }
#endif // DEBUG_ENABLED
}
diff --git a/modules/gdscript/gdscript_tokenizer.cpp b/modules/gdscript/gdscript_tokenizer.cpp
index 9854b8d185..2db42601c6 100644
--- a/modules/gdscript/gdscript_tokenizer.cpp
+++ b/modules/gdscript/gdscript_tokenizer.cpp
@@ -574,8 +574,9 @@ void GDScriptTokenizerText::_advance() {
_make_token(TK_OP_EQUAL);
INCPOS(1);
- } else
+ } else {
_make_token(TK_OP_ASSIGN);
+ }
} break;
case '<': {
@@ -590,8 +591,9 @@ void GDScriptTokenizerText::_advance() {
_make_token(TK_OP_SHIFT_LEFT);
}
INCPOS(1);
- } else
+ } else {
_make_token(TK_OP_LESS);
+ }
} break;
case '>': {
@@ -741,8 +743,9 @@ void GDScriptTokenizerText::_advance() {
[[fallthrough]];
case '\'':
case '"': {
- if (GETCHAR(0) == '\'')
+ if (GETCHAR(0) == '\'') {
string_mode = STRING_SINGLE_QUOTE;
+ }
int i = 1;
if (string_mode == STRING_DOUBLE_QUOTE && GETCHAR(i) == '"' && GETCHAR(i + 1) == '"') {
@@ -851,8 +854,9 @@ void GDScriptTokenizerText::_advance() {
} break;
}
- if (next != '\n')
+ if (next != '\n') {
str += res;
+ }
} else {
if (CharType(GETCHAR(i)) == '\n') {
@@ -933,8 +937,9 @@ void GDScriptTokenizerText::_advance() {
} else if (GETCHAR(i) == '_') {
i++;
continue; // Included for readability, shouldn't be a part of the string
- } else
+ } else {
break;
+ }
str += CharType(GETCHAR(i));
i++;
@@ -1034,8 +1039,9 @@ void GDScriptTokenizerText::_advance() {
}
}
- if (!found)
+ if (!found) {
identifier = true;
+ }
}
if (identifier) {
@@ -1073,8 +1079,9 @@ void GDScriptTokenizerText::set_code(const String &p_code) {
ignore_warnings = false;
#endif // DEBUG_ENABLED
last_error = "";
- for (int i = 0; i < MAX_LOOKAHEAD + 1; i++)
+ for (int i = 0; i < MAX_LOOKAHEAD + 1; i++) {
_advance();
+ }
}
GDScriptTokenizerText::Token GDScriptTokenizerText::get_token(int p_offset) const {
@@ -1166,8 +1173,9 @@ String GDScriptTokenizerText::get_token_error(int p_offset) const {
void GDScriptTokenizerText::advance(int p_amount) {
ERR_FAIL_COND(p_amount <= 0);
- for (int i = 0; i < p_amount; i++)
+ for (int i = 0; i < p_amount; i++) {
_advance();
+ }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -1215,8 +1223,9 @@ Error GDScriptTokenizerBuffer::set_code_buffer(const Vector<uint8_t> &p_buffer)
int len;
// An object cannot be constant, never decode objects
Error err = decode_variant(v, b, total_len, &len, false);
- if (err)
+ if (err) {
return err;
+ }
b += len;
total_len -= len;
constants.write[i] = v;
@@ -1311,8 +1320,9 @@ Vector<uint8_t> GDScriptTokenizerBuffer::parse_code_string(const String &p_code)
token_array.push_back(token);
- if (tt.get_token() == TK_EOF)
+ if (tt.get_token() == TK_EOF) {
break;
+ }
tt.advance();
}
@@ -1352,8 +1362,9 @@ Vector<uint8_t> GDScriptTokenizerBuffer::parse_code_string(const String &p_code)
CharString cs = String(E->get()).utf8();
int len = cs.length() + 1;
int extra = 4 - (len % 4);
- if (extra == 4)
+ if (extra == 4) {
extra = 0;
+ }
uint8_t ibuf[4];
encode_uint32(len + extra, ibuf);
@@ -1382,8 +1393,9 @@ Vector<uint8_t> GDScriptTokenizerBuffer::parse_code_string(const String &p_code)
uint8_t ibuf[8];
encode_uint32(E->key(), &ibuf[0]);
encode_uint32(E->get(), &ibuf[4]);
- for (int i = 0; i < 8; i++)
+ for (int i = 0; i < 8; i++) {
buf.push_back(ibuf[i]);
+ }
}
for (int i = 0; i < token_array.size(); i++) {
@@ -1406,8 +1418,9 @@ Vector<uint8_t> GDScriptTokenizerBuffer::parse_code_string(const String &p_code)
GDScriptTokenizerBuffer::Token GDScriptTokenizerBuffer::get_token(int p_offset) const {
int offset = token + p_offset;
- if (offset < 0 || offset >= tokens.size())
+ if (offset < 0 || offset >= tokens.size()) {
return TK_EOF;
+ }
return GDScriptTokenizerBuffer::Token(tokens[offset] & TOKEN_MASK);
}
@@ -1439,10 +1452,12 @@ int GDScriptTokenizerBuffer::get_token_line(int p_offset) const {
int offset = token + p_offset;
int pos = lines.find_nearest(offset);
- if (pos < 0)
+ if (pos < 0) {
return -1;
- if (pos >= lines.size())
+ }
+ if (pos >= lines.size()) {
pos = lines.size() - 1;
+ }
uint32_t l = lines.getv(pos);
return l & TOKEN_LINE_MASK;
@@ -1451,10 +1466,12 @@ int GDScriptTokenizerBuffer::get_token_line(int p_offset) const {
int GDScriptTokenizerBuffer::get_token_column(int p_offset) const {
int offset = token + p_offset;
int pos = lines.find_nearest(offset);
- if (pos < 0)
+ if (pos < 0) {
return -1;
- if (pos >= lines.size())
+ }
+ if (pos >= lines.size()) {
pos = lines.size() - 1;
+ }
uint32_t l = lines.getv(pos);
return l >> TOKEN_LINE_BITS;
diff --git a/modules/gdscript/language_server/gdscript_extend_parser.cpp b/modules/gdscript/language_server/gdscript_extend_parser.cpp
index 9338dcadbe..f87e8687e5 100644
--- a/modules/gdscript/language_server/gdscript_extend_parser.cpp
+++ b/modules/gdscript/language_server/gdscript_extend_parser.cpp
@@ -144,8 +144,9 @@ void ExtendGDScriptParser::parse_class_symbol(const GDScriptParser::ClassNode *p
r_symbol.script_path = path;
r_symbol.children.clear();
r_symbol.name = p_class->name;
- if (r_symbol.name.empty())
+ if (r_symbol.name.empty()) {
r_symbol.name = path.get_file();
+ }
r_symbol.kind = lsp::SymbolKind::Class;
r_symbol.deprecated = false;
r_symbol.range.start.line = LINE_NUMBER_TO_INDEX(p_class->line);
@@ -378,8 +379,9 @@ String ExtendGDScriptParser::parse_documentation(int p_line, bool p_docs_down) {
int step = p_docs_down ? 1 : -1;
int start_line = p_docs_down ? p_line : p_line - 1;
for (int i = start_line; true; i += step) {
- if (i < 0 || i >= lines.size())
+ if (i < 0 || i >= lines.size()) {
break;
+ }
String line_comment = lines[i].strip_edges(true, false);
if (line_comment.begins_with("#")) {
@@ -413,8 +415,9 @@ String ExtendGDScriptParser::get_text_for_completion(const lsp::Position &p_curs
longthing += lines[i];
}
- if (i != len - 1)
+ if (i != len - 1) {
longthing += "\n";
+ }
}
return longthing;
@@ -450,8 +453,9 @@ String ExtendGDScriptParser::get_text_for_lookup_symbol(const lsp::Position &p_c
longthing += lines[i];
}
- if (i != len - 1)
+ if (i != len - 1) {
longthing += "\n";
+ }
}
return longthing;
diff --git a/modules/gdscript/language_server/gdscript_language_protocol.cpp b/modules/gdscript/language_server/gdscript_language_protocol.cpp
index c5bce5bb87..35bf4287b8 100644
--- a/modules/gdscript/language_server/gdscript_language_protocol.cpp
+++ b/modules/gdscript/language_server/gdscript_language_protocol.cpp
@@ -47,10 +47,11 @@ Error GDScriptLanguageProtocol::LSPeer::handle_data() {
ERR_FAIL_COND_V_MSG(true, ERR_OUT_OF_MEMORY, "Response header too big");
}
Error err = connection->get_partial_data(&req_buf[req_pos], 1, read);
- if (err != OK)
+ if (err != OK) {
return FAILED;
- else if (read != 1) // Busy, wait until next poll
+ } else if (read != 1) { // Busy, wait until next poll
return ERR_BUSY;
+ }
char *r = (char *)req_buf;
int l = req_pos;
@@ -75,10 +76,11 @@ Error GDScriptLanguageProtocol::LSPeer::handle_data() {
ERR_FAIL_COND_V_MSG(req_pos >= LSP_MAX_BUFFER_SIZE, ERR_OUT_OF_MEMORY, "Response content too big");
}
Error err = connection->get_partial_data(&req_buf[req_pos], 1, read);
- if (err != OK)
+ if (err != OK) {
return FAILED;
- else if (read != 1)
+ } else if (read != 1) {
return ERR_BUSY;
+ }
req_pos++;
}
diff --git a/modules/gdscript/language_server/gdscript_workspace.cpp b/modules/gdscript/language_server/gdscript_workspace.cpp
index 7c432bfc80..9285d88157 100644
--- a/modules/gdscript/language_server/gdscript_workspace.cpp
+++ b/modules/gdscript/language_server/gdscript_workspace.cpp
@@ -184,8 +184,9 @@ Array GDScriptWorkspace::symbol(const Dictionary &p_params) {
}
Error GDScriptWorkspace::initialize() {
- if (initialized)
+ if (initialized) {
return OK;
+ }
DocData *doc = EditorHelp::get_doc_data();
for (Map<String, DocData::ClassDoc>::Element *E = doc->class_list.front(); E; E = E->next()) {
@@ -374,8 +375,9 @@ void GDScriptWorkspace::publish_diagnostics(const String &p_path) {
}
void GDScriptWorkspace::_get_owners(EditorFileSystemDirectory *efsd, String p_path, List<String> &owners) {
- if (!efsd)
+ if (!efsd) {
return;
+ }
for (int i = 0; i < efsd->get_subdir_count(); i++) {
_get_owners(efsd->get_subdir(i), p_path, owners);
@@ -390,8 +392,9 @@ void GDScriptWorkspace::_get_owners(EditorFileSystemDirectory *efsd, String p_pa
break;
}
}
- if (!found)
+ if (!found) {
continue;
+ }
owners.push_back(efsd->get_file_path(i));
}
diff --git a/modules/gdscript/language_server/lsp.hpp b/modules/gdscript/language_server/lsp.hpp
index f979171b6e..44a0076107 100644
--- a/modules/gdscript/language_server/lsp.hpp
+++ b/modules/gdscript/language_server/lsp.hpp
@@ -280,8 +280,9 @@ struct Command {
Dictionary dict;
dict["title"] = title;
dict["command"] = command;
- if (arguments.size())
+ if (arguments.size()) {
dict["arguments"] = arguments;
+ }
return dict;
}
};
@@ -945,20 +946,24 @@ struct CompletionItem {
dict["preselect"] = preselect;
dict["sortText"] = sortText;
dict["filterText"] = filterText;
- if (commitCharacters.size())
+ if (commitCharacters.size()) {
dict["commitCharacters"] = commitCharacters;
+ }
dict["command"] = command.to_json();
}
return dict;
}
void load(const Dictionary &p_dict) {
- if (p_dict.has("label"))
+ if (p_dict.has("label")) {
label = p_dict["label"];
- if (p_dict.has("kind"))
+ }
+ if (p_dict.has("kind")) {
kind = p_dict["kind"];
- if (p_dict.has("detail"))
+ }
+ if (p_dict.has("detail")) {
detail = p_dict["detail"];
+ }
if (p_dict.has("documentation")) {
Variant doc = p_dict["documentation"];
if (doc.get_type() == Variant::STRING) {
@@ -968,18 +973,24 @@ struct CompletionItem {
documentation.value = v["value"];
}
}
- if (p_dict.has("deprecated"))
+ if (p_dict.has("deprecated")) {
deprecated = p_dict["deprecated"];
- if (p_dict.has("preselect"))
+ }
+ if (p_dict.has("preselect")) {
preselect = p_dict["preselect"];
- if (p_dict.has("sortText"))
+ }
+ if (p_dict.has("sortText")) {
sortText = p_dict["sortText"];
- if (p_dict.has("filterText"))
+ }
+ if (p_dict.has("filterText")) {
filterText = p_dict["filterText"];
- if (p_dict.has("insertText"))
+ }
+ if (p_dict.has("insertText")) {
insertText = p_dict["insertText"];
- if (p_dict.has("data"))
+ }
+ if (p_dict.has("data")) {
data = p_dict["data"];
+ }
}
};
diff --git a/modules/gdscript/register_types.cpp b/modules/gdscript/register_types.cpp
index 161ab692c9..0625123530 100644
--- a/modules/gdscript/register_types.cpp
+++ b/modules/gdscript/register_types.cpp
@@ -68,12 +68,14 @@ public:
script_key = preset->get_script_encryption_key().to_lower();
}
- if (!p_path.ends_with(".gd") || script_mode == EditorExportPreset::MODE_SCRIPT_TEXT)
+ if (!p_path.ends_with(".gd") || script_mode == EditorExportPreset::MODE_SCRIPT_TEXT) {
return;
+ }
Vector<uint8_t> file = FileAccess::get_file_as_array(p_path);
- if (file.empty())
+ if (file.empty()) {
return;
+ }
String txt;
txt.parse_utf8((const char *)file.ptr(), file.size());
@@ -90,19 +92,21 @@ public:
int v = 0;
if (i * 2 < script_key.length()) {
CharType ct = script_key[i * 2];
- if (ct >= '0' && ct <= '9')
+ if (ct >= '0' && ct <= '9') {
ct = ct - '0';
- else if (ct >= 'a' && ct <= 'f')
+ } else if (ct >= 'a' && ct <= 'f') {
ct = 10 + ct - 'a';
+ }
v |= ct << 4;
}
if (i * 2 + 1 < script_key.length()) {
CharType ct = script_key[i * 2 + 1];
- if (ct >= '0' && ct <= '9')
+ if (ct >= '0' && ct <= '9') {
ct = ct - '0';
- else if (ct >= 'a' && ct <= 'f')
+ } else if (ct >= 'a' && ct <= 'f') {
ct = 10 + ct - 'a';
+ }
v |= ct;
}
key.write[i] = v;
@@ -166,8 +170,9 @@ void register_gdscript_types() {
void unregister_gdscript_types() {
ScriptServer::unregister_language(script_language_gd);
- if (script_language_gd)
+ if (script_language_gd) {
memdelete(script_language_gd);
+ }
ResourceLoader::remove_resource_format_loader(resource_loader_gd);
resource_loader_gd.unref();
diff --git a/modules/gridmap/grid_map.cpp b/modules/gridmap/grid_map.cpp
index 02258d706a..2975a97bfe 100644
--- a/modules/gridmap/grid_map.cpp
+++ b/modules/gridmap/grid_map.cpp
@@ -118,8 +118,9 @@ bool GridMap::_get(const StringName &p_name, Variant &r_ret) const {
}
r_ret = ret;
- } else
+ } else {
return false;
+ }
return true;
}
@@ -152,10 +153,11 @@ uint32_t GridMap::get_collision_mask() const {
void GridMap::set_collision_mask_bit(int p_bit, bool p_value) {
uint32_t mask = get_collision_mask();
- if (p_value)
+ if (p_value) {
mask |= 1 << p_bit;
- else
+ } else {
mask &= ~(1 << p_bit);
+ }
set_collision_mask(mask);
}
@@ -165,10 +167,11 @@ bool GridMap::get_collision_mask_bit(int p_bit) const {
void GridMap::set_collision_layer_bit(int p_bit, bool p_value) {
uint32_t mask = get_collision_layer();
- if (p_value)
+ if (p_value) {
mask |= 1 << p_bit;
- else
+ } else {
mask &= ~(1 << p_bit);
+ }
set_collision_layer(mask);
}
@@ -177,11 +180,13 @@ bool GridMap::get_collision_layer_bit(int p_bit) const {
}
void GridMap::set_mesh_library(const Ref<MeshLibrary> &p_mesh_library) {
- if (!mesh_library.is_null())
+ if (!mesh_library.is_null()) {
mesh_library->unregister_owner(this);
+ }
mesh_library = p_mesh_library;
- if (!mesh_library.is_null())
+ if (!mesh_library.is_null()) {
mesh_library->register_owner(this);
+ }
_recreate_octant_data();
_change_notify("mesh_library");
@@ -323,8 +328,9 @@ int GridMap::get_cell_item(int p_x, int p_y, int p_z) const {
key.y = p_y;
key.z = p_z;
- if (!cell_map.has(key))
+ if (!cell_map.has(key)) {
return INVALID_CELL_ITEM;
+ }
return cell_map[key].item;
}
@@ -338,8 +344,9 @@ int GridMap::get_cell_item_orientation(int p_x, int p_y, int p_z) const {
key.y = p_y;
key.z = p_z;
- if (!cell_map.has(key))
+ if (!cell_map.has(key)) {
return -1;
+ }
return cell_map[key].rot;
}
@@ -377,8 +384,9 @@ void GridMap::_octant_transform(const OctantKey &p_key) {
bool GridMap::_octant_update(const OctantKey &p_key) {
ERR_FAIL_COND_V(!octant_map.has(p_key), false);
Octant &g = *octant_map[p_key];
- if (!g.dirty)
+ if (!g.dirty) {
return false;
+ }
//erase body shapes
PhysicsServer3D::get_singleton()->body_clear_shapes(g.static_body);
@@ -422,8 +430,9 @@ bool GridMap::_octant_update(const OctantKey &p_key) {
ERR_CONTINUE(!cell_map.has(E->get()));
const Cell &c = cell_map[E->get()];
- if (!mesh_library.is_valid() || !mesh_library->has_item(c.item))
+ if (!mesh_library.is_valid() || !mesh_library->has_item(c.item)) {
continue;
+ }
Vector3 cellpos = Vector3(E->get().x, E->get().y, E->get().z);
Vector3 ofs = _get_offset();
@@ -450,8 +459,9 @@ bool GridMap::_octant_update(const OctantKey &p_key) {
// add the item's shape at given xform to octant's static_body
for (int i = 0; i < shapes.size(); i++) {
// add the item's shape
- if (!shapes[i].shape.is_valid())
+ if (!shapes[i].shape.is_valid()) {
continue;
+ }
PhysicsServer3D::get_singleton()->body_add_shape(g.static_body, shapes[i].shape->get_rid(), xform * shapes[i].local_transform);
if (g.collision_debug.is_valid()) {
shapes.write[i].shape->add_vertices_to_array(col_debug, xform * shapes[i].local_transform);
@@ -598,10 +608,12 @@ void GridMap::_octant_clean_up(const OctantKey &p_key) {
ERR_FAIL_COND(!octant_map.has(p_key));
Octant &g = *octant_map[p_key];
- if (g.collision_debug.is_valid())
+ if (g.collision_debug.is_valid()) {
RS::get_singleton()->free(g.collision_debug);
- if (g.collision_debug_instance.is_valid())
+ }
+ if (g.collision_debug_instance.is_valid()) {
RS::get_singleton()->free(g.collision_debug_instance);
+ }
PhysicsServer3D::get_singleton()->free(g.static_body);
@@ -647,8 +659,9 @@ void GridMap::_notification(int p_what) {
} break;
case NOTIFICATION_TRANSFORM_CHANGED: {
Transform new_xform = get_global_transform();
- if (new_xform == last_transform)
+ if (new_xform == last_transform) {
break;
+ }
//update run
for (Map<OctantKey, Octant *>::Element *E = octant_map.front(); E; E = E->next()) {
_octant_transform(E->key());
@@ -683,8 +696,9 @@ void GridMap::_notification(int p_what) {
}
void GridMap::_update_visibility() {
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
_change_notify("visible");
@@ -698,8 +712,9 @@ void GridMap::_update_visibility() {
}
void GridMap::_queue_octants_dirty() {
- if (awaiting_update)
+ if (awaiting_update) {
return;
+ }
MessageQueue::get_singleton()->push_call(this, "_update_octants_callback");
awaiting_update = true;
@@ -717,8 +732,9 @@ void GridMap::_recreate_octant_data() {
void GridMap::_clear_internal() {
for (Map<OctantKey, Octant *>::Element *E = octant_map.front(); E; E = E->next()) {
- if (is_inside_world())
+ if (is_inside_world()) {
_octant_exit_world(E->key());
+ }
_octant_clean_up(E->key());
memdelete(E->get());
@@ -738,8 +754,9 @@ void GridMap::resource_changed(const RES &p_res) {
}
void GridMap::_update_octants_callback() {
- if (!awaiting_update)
+ if (!awaiting_update) {
return;
+ }
List<OctantKey> to_delete;
for (Map<OctantKey, Octant *>::Element *E = octant_map.front(); E; E = E->next()) {
@@ -830,10 +847,12 @@ void GridMap::_bind_methods() {
}
void GridMap::set_clip(bool p_enabled, bool p_clip_above, int p_floor, Vector3::Axis p_axis) {
- if (!p_enabled && !clip)
+ if (!p_enabled && !clip) {
return;
- if (clip && p_enabled && clip_floor == p_floor && p_clip_above == clip_above && p_axis == clip_axis)
+ }
+ if (clip && p_enabled && clip_floor == p_floor && p_clip_above == clip_above && p_axis == clip_axis) {
return;
+ }
clip = p_enabled;
clip_floor = p_floor;
@@ -871,19 +890,22 @@ Array GridMap::get_used_cells() const {
}
Array GridMap::get_meshes() {
- if (mesh_library.is_null())
+ if (mesh_library.is_null()) {
return Array();
+ }
Vector3 ofs = _get_offset();
Array meshes;
for (Map<IndexKey, Cell>::Element *E = cell_map.front(); E; E = E->next()) {
int id = E->get().item;
- if (!mesh_library->has_item(id))
+ if (!mesh_library->has_item(id)) {
continue;
+ }
Ref<Mesh> mesh = mesh_library->get_item_mesh(id);
- if (mesh.is_null())
+ if (mesh.is_null()) {
continue;
+ }
IndexKey ik = E->key();
@@ -920,8 +942,9 @@ void GridMap::clear_baked_meshes() {
}
void GridMap::make_baked_meshes(bool p_gen_lightmap_uv, float p_lightmap_uv_texel_size) {
- if (!mesh_library.is_valid())
+ if (!mesh_library.is_valid()) {
return;
+ }
//generate
Map<OctantKey, Map<Ref<Material>, Ref<SurfaceTool>>> surface_map;
@@ -930,12 +953,14 @@ void GridMap::make_baked_meshes(bool p_gen_lightmap_uv, float p_lightmap_uv_texe
IndexKey key = E->key();
int item = E->get().item;
- if (!mesh_library->has_item(item))
+ if (!mesh_library->has_item(item)) {
continue;
+ }
Ref<Mesh> mesh = mesh_library->get_item_mesh(item);
- if (!mesh.is_valid())
+ if (!mesh.is_valid()) {
continue;
+ }
Vector3 cellpos = Vector3(key.x, key.y, key.z);
Vector3 ofs = _get_offset();
@@ -958,8 +983,9 @@ void GridMap::make_baked_meshes(bool p_gen_lightmap_uv, float p_lightmap_uv_texe
Map<Ref<Material>, Ref<SurfaceTool>> &mat_map = surface_map[ok];
for (int i = 0; i < mesh->get_surface_count(); i++) {
- if (mesh->surface_get_primitive_type(i) != Mesh::PRIMITIVE_TRIANGLES)
+ if (mesh->surface_get_primitive_type(i) != Mesh::PRIMITIVE_TRIANGLES) {
continue;
+ }
Ref<Material> surf_mat = mesh->surface_get_material(i);
if (!mat_map.has(surf_mat)) {
@@ -1043,8 +1069,9 @@ GridMap::GridMap() {
}
GridMap::~GridMap() {
- if (!mesh_library.is_null())
+ if (!mesh_library.is_null()) {
mesh_library->unregister_owner(this);
+ }
clear();
}
diff --git a/modules/gridmap/grid_map_editor_plugin.cpp b/modules/gridmap/grid_map_editor_plugin.cpp
index e8f7d09bb2..2bae43510a 100644
--- a/modules/gridmap/grid_map_editor_plugin.cpp
+++ b/modules/gridmap/grid_map_editor_plugin.cpp
@@ -40,13 +40,15 @@
#include "scene/main/window.h"
void GridMapEditor::_node_removed(Node *p_node) {
- if (p_node == node)
+ if (p_node == node) {
node = nullptr;
+ }
}
void GridMapEditor::_configure() {
- if (!node)
+ if (!node) {
return;
+ }
update_grid();
}
@@ -213,8 +215,9 @@ void GridMapEditor::_menu_option(int p_option) {
case MENU_OPTION_SELECTION_DUPLICATE:
case MENU_OPTION_SELECTION_CUT: {
- if (!(selection.active && input_action == INPUT_NONE))
+ if (!(selection.active && input_action == INPUT_NONE)) {
break;
+ }
_set_clipboard_data();
@@ -231,15 +234,17 @@ void GridMapEditor::_menu_option(int p_option) {
_update_paste_indicator();
} break;
case MENU_OPTION_SELECTION_CLEAR: {
- if (!selection.active)
+ if (!selection.active) {
break;
+ }
_delete_selection();
} break;
case MENU_OPTION_SELECTION_FILL: {
- if (!selection.active)
+ if (!selection.active) {
return;
+ }
_fill_selection();
@@ -303,17 +308,21 @@ void GridMapEditor::_update_selection_transform() {
}
void GridMapEditor::_validate_selection() {
- if (!selection.active)
+ if (!selection.active) {
return;
+ }
selection.begin = selection.click;
selection.end = selection.current;
- if (selection.begin.x > selection.end.x)
+ if (selection.begin.x > selection.end.x) {
SWAP(selection.begin.x, selection.end.x);
- if (selection.begin.y > selection.end.y)
+ }
+ if (selection.begin.y > selection.end.y) {
SWAP(selection.begin.y, selection.end.y);
- if (selection.begin.z > selection.end.z)
+ }
+ if (selection.begin.z > selection.end.z) {
SWAP(selection.begin.z, selection.end.z);
+ }
_update_selection_transform();
}
@@ -336,16 +345,20 @@ void GridMapEditor::_set_selection(bool p_active, const Vector3 &p_begin, const
}
bool GridMapEditor::do_input_action(Camera3D *p_camera, const Point2 &p_point, bool p_click) {
- if (!spatial_editor)
+ if (!spatial_editor) {
return false;
+ }
- if (selected_palette < 0 && input_action != INPUT_PICK && input_action != INPUT_SELECT && input_action != INPUT_PASTE)
+ if (selected_palette < 0 && input_action != INPUT_PICK && input_action != INPUT_SELECT && input_action != INPUT_PASTE) {
return false;
+ }
Ref<MeshLibrary> mesh_library = node->get_mesh_library();
- if (mesh_library.is_null())
+ if (mesh_library.is_null()) {
return false;
- if (input_action != INPUT_PICK && input_action != INPUT_SELECT && input_action != INPUT_PASTE && !mesh_library->has_item(selected_palette))
+ }
+ if (input_action != INPUT_PICK && input_action != INPUT_SELECT && input_action != INPUT_PASTE && !mesh_library->has_item(selected_palette)) {
return false;
+ }
Camera3D *camera = p_camera;
Vector3 from = camera->project_ray_origin(p_point);
@@ -360,27 +373,30 @@ bool GridMapEditor::do_input_action(Camera3D *p_camera, const Point2 &p_point, b
p.d = edit_floor[edit_axis] * node->get_cell_size()[edit_axis];
Vector3 inters;
- if (!p.intersects_segment(from, from + normal * settings_pick_distance->get_value(), &inters))
+ if (!p.intersects_segment(from, from + normal * settings_pick_distance->get_value(), &inters)) {
return false;
+ }
// Make sure the intersection is inside the frustum planes, to avoid
// Painting on invisible regions.
for (int i = 0; i < planes.size(); i++) {
Plane fp = local_xform.xform(planes[i]);
- if (fp.is_point_over(inters))
+ if (fp.is_point_over(inters)) {
return false;
+ }
}
int cell[3];
float cell_size[3] = { node->get_cell_size().x, node->get_cell_size().y, node->get_cell_size().z };
for (int i = 0; i < 3; i++) {
- if (i == edit_axis)
+ if (i == edit_axis) {
cell[i] = edit_floor[i];
- else {
+ } else {
cell[i] = inters[i] / node->get_cell_size()[i];
- if (inters[i] < 0)
+ if (inters[i] < 0) {
cell[i] -= 1; // Compensate negative.
+ }
grid_ofs[i] = cell[i] * cell_size[i];
}
}
@@ -404,8 +420,9 @@ bool GridMapEditor::do_input_action(Camera3D *p_camera, const Point2 &p_point, b
} else if (input_action == INPUT_SELECT) {
selection.current = Vector3(cell[0], cell[1], cell[2]);
- if (p_click)
+ if (p_click) {
selection.click = selection.current;
+ }
selection.active = true;
_validate_selection();
@@ -446,8 +463,9 @@ bool GridMapEditor::do_input_action(Camera3D *p_camera, const Point2 &p_point, b
}
void GridMapEditor::_delete_selection() {
- if (!selection.active)
+ if (!selection.active) {
return;
+ }
undo_redo->create_action(TTR("GridMap Delete Selection"));
for (int i = selection.begin.x; i <= selection.end.x; i++) {
@@ -464,8 +482,9 @@ void GridMapEditor::_delete_selection() {
}
void GridMapEditor::_fill_selection() {
- if (!selection.active)
+ if (!selection.active) {
return;
+ }
undo_redo->create_action(TTR("GridMap Fill Selection"));
for (int i = selection.begin.x; i <= selection.end.x; i++) {
@@ -498,8 +517,9 @@ void GridMapEditor::_set_clipboard_data() {
for (int j = selection.begin.y; j <= selection.end.y; j++) {
for (int k = selection.begin.z; k <= selection.end.z; k++) {
int itm = node->get_cell_item(i, j, k);
- if (itm == GridMap::INVALID_CELL_ITEM)
+ if (itm == GridMap::INVALID_CELL_ITEM) {
continue;
+ }
Ref<Mesh> mesh = meshLibrary->get_item_mesh(itm);
@@ -593,13 +613,15 @@ bool GridMapEditor::forward_spatial_input_event(Camera3D *p_camera, const Ref<In
if (mb.is_valid()) {
if (mb->get_button_index() == BUTTON_WHEEL_UP && (mb->get_command() || mb->get_shift())) {
- if (mb->is_pressed())
+ if (mb->is_pressed()) {
floor->set_value(floor->get_value() + mb->get_factor());
+ }
return true; // Eaten.
} else if (mb->get_button_index() == BUTTON_WHEEL_DOWN && (mb->get_command() || mb->get_shift())) {
- if (mb->is_pressed())
+ if (mb->is_pressed()) {
floor->set_value(floor->get_value() - mb->get_factor());
+ }
return true;
}
@@ -859,8 +881,9 @@ void GridMapEditor::update_palette() {
name = "#" + itos(id);
}
- if (filter != "" && !filter.is_subsequence_ofi(name))
+ if (filter != "" && !filter.is_subsequence_ofi(name)) {
continue;
+ }
mesh_library_palette->add_item("");
if (!preview.is_null()) {
@@ -881,8 +904,9 @@ void GridMapEditor::update_palette() {
}
void GridMapEditor::edit(GridMap *p_gridmap) {
- if (!p_gridmap && node)
+ if (!p_gridmap && node) {
node->disconnect("cell_size_changed", callable_mp(this, &GridMapEditor::_draw_grids));
+ }
node = p_gridmap;
@@ -921,10 +945,11 @@ void GridMapEditor::edit(GridMap *p_gridmap) {
void GridMapEditor::_update_clip() {
node->set_meta("_editor_clip_", clip_mode);
- if (clip_mode == CLIP_DISABLED)
+ if (clip_mode == CLIP_DISABLED) {
node->set_clip(false);
- else
+ } else {
node->set_clip(true, clip_mode == CLIP_ABOVE, edit_floor[edit_axis], edit_axis);
+ }
}
void GridMapEditor::update_grid() {
@@ -1045,8 +1070,9 @@ void GridMapEditor::_notification(int p_what) {
grid_xform = xf;
}
Ref<MeshLibrary> cgmt = node->get_mesh_library();
- if (cgmt.operator->() != last_mesh_library)
+ if (cgmt.operator->() != last_mesh_library) {
update_palette();
+ }
if (lock_view) {
EditorNode *editor = Object::cast_to<EditorNode>(get_tree()->get_root()->get_child(0));
@@ -1057,8 +1083,9 @@ void GridMapEditor::_notification(int p_what) {
p = node->get_transform().xform(p); // plane to snap
Node3DEditorPlugin *sep = Object::cast_to<Node3DEditorPlugin>(editor->get_editor_plugin_screen());
- if (sep)
+ if (sep) {
sep->snap_cursor_to_plane(p);
+ }
}
} break;
@@ -1074,8 +1101,9 @@ void GridMapEditor::_update_cursor_instance() {
return;
}
- if (cursor_instance.is_valid())
+ if (cursor_instance.is_valid()) {
RenderingServer::get_singleton()->free(cursor_instance);
+ }
cursor_instance = RID();
if (selected_palette >= 0) {
@@ -1096,8 +1124,9 @@ void GridMapEditor::_item_selected_cbk(int idx) {
}
void GridMapEditor::_floor_changed(float p_value) {
- if (updating)
+ if (updating) {
return;
+ }
edit_floor[edit_axis] = p_value;
node->set_meta("_editor_floor_", Vector3(edit_floor[0], edit_floor[1], edit_floor[2]));
@@ -1284,10 +1313,11 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) {
v[2] = v[1] * (1 - 2 * (j & 1));
for (int k = 0; k < 3; k++) {
- if (i < 3)
+ if (i < 3) {
face_points[j][(i + k) % 3] = v[k];
- else
+ } else {
face_points[3 - j][(i + k) % 3] = -v[k];
+ }
}
}
@@ -1395,25 +1425,32 @@ GridMapEditor::~GridMapEditor() {
_clear_clipboard_data();
for (int i = 0; i < 3; i++) {
- if (grid[i].is_valid())
+ if (grid[i].is_valid()) {
RenderingServer::get_singleton()->free(grid[i]);
- if (grid_instance[i].is_valid())
+ }
+ if (grid_instance[i].is_valid()) {
RenderingServer::get_singleton()->free(grid_instance[i]);
- if (cursor_instance.is_valid())
+ }
+ if (cursor_instance.is_valid()) {
RenderingServer::get_singleton()->free(cursor_instance);
- if (selection_level_instance[i].is_valid())
+ }
+ if (selection_level_instance[i].is_valid()) {
RenderingServer::get_singleton()->free(selection_level_instance[i]);
- if (selection_level_mesh[i].is_valid())
+ }
+ if (selection_level_mesh[i].is_valid()) {
RenderingServer::get_singleton()->free(selection_level_mesh[i]);
+ }
}
RenderingServer::get_singleton()->free(selection_mesh);
- if (selection_instance.is_valid())
+ if (selection_instance.is_valid()) {
RenderingServer::get_singleton()->free(selection_instance);
+ }
RenderingServer::get_singleton()->free(paste_mesh);
- if (paste_instance.is_valid())
+ if (paste_instance.is_valid()) {
RenderingServer::get_singleton()->free(paste_instance);
+ }
}
void GridMapEditorPlugin::_notification(int p_what) {
diff --git a/modules/hdr/image_loader_hdr.cpp b/modules/hdr/image_loader_hdr.cpp
index 19cd8ae584..333b1cf377 100644
--- a/modules/hdr/image_loader_hdr.cpp
+++ b/modules/hdr/image_loader_hdr.cpp
@@ -41,8 +41,9 @@ Error ImageLoaderHDR::load_image(Ref<Image> p_image, FileAccess *f, bool p_force
while (true) {
String line = f->get_line();
ERR_FAIL_COND_V(f->eof_reached(), ERR_FILE_UNRECOGNIZED);
- if (line == "") // empty line indicates end of header
+ if (line == "") { // empty line indicates end of header
break;
+ }
if (line.begins_with("FORMAT=")) { // leave option to implement other commands
ERR_FAIL_COND_V_MSG(line != "FORMAT=32-bit_rle_rgbe", ERR_FILE_UNRECOGNIZED, "Only 32-bit_rle_rgbe is supported for HDR files.");
} else if (!line.begins_with("#")) { // not comment
@@ -107,12 +108,14 @@ Error ImageLoaderHDR::load_image(Ref<Image> p_image, FileAccess *f, bool p_force
// Run
int value = f->get_8();
count -= 128;
- for (int z = 0; z < count; ++z)
+ for (int z = 0; z < count; ++z) {
ptr[(j * width + i++) * 4 + k] = uint8_t(value);
+ }
} else {
// Dump
- for (int z = 0; z < count; ++z)
+ for (int z = 0; z < count; ++z) {
ptr[(j * width + i++) * 4 + k] = f->get_8();
+ }
}
}
}
diff --git a/modules/jpg/image_loader_jpegd.cpp b/modules/jpg/image_loader_jpegd.cpp
index 16ebd65147..9c7ace5cf2 100644
--- a/modules/jpg/image_loader_jpegd.cpp
+++ b/modules/jpg/image_loader_jpegd.cpp
@@ -48,11 +48,13 @@ Error jpeg_load_image_from_buffer(Image *p_image, const uint8_t *p_buffer, int p
const int image_width = decoder.get_width();
const int image_height = decoder.get_height();
const int comps = decoder.get_num_components();
- if (comps != 1 && comps != 3)
+ if (comps != 1 && comps != 3) {
return ERR_FILE_CORRUPT;
+ }
- if (decoder.begin_decoding() != jpgd::JPGD_SUCCESS)
+ if (decoder.begin_decoding() != jpgd::JPGD_SUCCESS) {
return ERR_FILE_CORRUPT;
+ }
const int dst_bpl = image_width * comps;
@@ -90,10 +92,11 @@ Error jpeg_load_image_from_buffer(Image *p_image, const uint8_t *p_buffer, int p
//all good
Image::Format fmt;
- if (comps == 1)
+ if (comps == 1) {
fmt = Image::FORMAT_L8;
- else
+ } else {
fmt = Image::FORMAT_RGB8;
+ }
p_image->create(image_width, image_height, false, fmt, data);
diff --git a/modules/jsonrpc/jsonrpc.cpp b/modules/jsonrpc/jsonrpc.cpp
index f744dd50d2..6ab5f2d9b3 100644
--- a/modules/jsonrpc/jsonrpc.cpp
+++ b/modules/jsonrpc/jsonrpc.cpp
@@ -147,8 +147,9 @@ Variant JSONRPC::process_action(const Variant &p_action, bool p_process_arr_elem
}
String JSONRPC::process_string(const String &p_input) {
- if (p_input.empty())
+ if (p_input.empty()) {
return String();
+ }
Variant ret;
Variant input;
diff --git a/modules/mbedtls/packet_peer_mbed_dtls.cpp b/modules/mbedtls/packet_peer_mbed_dtls.cpp
index 210c9877df..8206d739ae 100644
--- a/modules/mbedtls/packet_peer_mbed_dtls.cpp
+++ b/modules/mbedtls/packet_peer_mbed_dtls.cpp
@@ -35,8 +35,9 @@
#include "core/os/file_access.h"
int PacketPeerMbedDTLS::bio_send(void *ctx, const unsigned char *buf, size_t len) {
- if (buf == nullptr || len <= 0)
+ if (buf == nullptr || len <= 0) {
return 0;
+ }
PacketPeerMbedDTLS *sp = (PacketPeerMbedDTLS *)ctx;
@@ -52,8 +53,9 @@ int PacketPeerMbedDTLS::bio_send(void *ctx, const unsigned char *buf, size_t len
}
int PacketPeerMbedDTLS::bio_recv(void *ctx, unsigned char *buf, size_t len) {
- if (buf == nullptr || len <= 0)
+ if (buf == nullptr || len <= 0) {
return 0;
+ }
PacketPeerMbedDTLS *sp = (PacketPeerMbedDTLS *)ctx;
@@ -167,8 +169,9 @@ Error PacketPeerMbedDTLS::accept_peer(Ref<PacketPeerUDP> p_base, Ref<CryptoKey>
Error PacketPeerMbedDTLS::put_packet(const uint8_t *p_buffer, int p_bytes) {
ERR_FAIL_COND_V(status != STATUS_CONNECTED, ERR_UNCONFIGURED);
- if (p_bytes == 0)
+ if (p_bytes == 0) {
return OK;
+ }
int ret = mbedtls_ssl_write(ssl_ctx->get_context(), p_buffer, p_bytes);
if (ret == MBEDTLS_ERR_SSL_WANT_READ || ret == MBEDTLS_ERR_SSL_WANT_WRITE) {
@@ -251,15 +254,16 @@ PacketPeerMbedDTLS::~PacketPeerMbedDTLS() {
}
void PacketPeerMbedDTLS::disconnect_from_peer() {
- if (status != STATUS_CONNECTED && status != STATUS_HANDSHAKING)
+ if (status != STATUS_CONNECTED && status != STATUS_HANDSHAKING) {
return;
+ }
if (status == STATUS_CONNECTED) {
int ret = 0;
// Send SSL close notification, blocking, but ignore other errors.
- do
+ do {
ret = mbedtls_ssl_close_notify(ssl_ctx->get_context());
- while (ret == MBEDTLS_ERR_SSL_WANT_WRITE);
+ } while (ret == MBEDTLS_ERR_SSL_WANT_WRITE);
}
_cleanup();
diff --git a/modules/mbedtls/ssl_context_mbedtls.cpp b/modules/mbedtls/ssl_context_mbedtls.cpp
index b0ca4a9e44..a2200e0644 100644
--- a/modules/mbedtls/ssl_context_mbedtls.cpp
+++ b/modules/mbedtls/ssl_context_mbedtls.cpp
@@ -67,8 +67,9 @@ Error CookieContextMbedTLS::setup() {
}
void CookieContextMbedTLS::clear() {
- if (!inited)
+ if (!inited) {
return;
+ }
mbedtls_ctr_drbg_free(&ctr_drbg);
mbedtls_entropy_free(&entropy);
mbedtls_ssl_cookie_free(&cookie_ctx);
@@ -120,10 +121,12 @@ Error SSLContextMbedTLS::init_server(int p_transport, int p_authmode, Ref<Crypto
// Locking key and certificate(s)
pkey = p_pkey;
certs = p_cert;
- if (pkey.is_valid())
+ if (pkey.is_valid()) {
pkey->lock();
- if (certs.is_valid())
+ }
+ if (certs.is_valid()) {
certs->lock();
+ }
// Adding key and certificate
int ret = mbedtls_ssl_conf_own_cert(&conf, &(certs->cert), &(pkey->pkey));
@@ -175,19 +178,22 @@ Error SSLContextMbedTLS::init_client(int p_transport, int p_authmode, Ref<X509Ce
}
void SSLContextMbedTLS::clear() {
- if (!inited)
+ if (!inited) {
return;
+ }
mbedtls_ssl_free(&ssl);
mbedtls_ssl_config_free(&conf);
mbedtls_ctr_drbg_free(&ctr_drbg);
mbedtls_entropy_free(&entropy);
// Unlock and key and certificates
- if (certs.is_valid())
+ if (certs.is_valid()) {
certs->unlock();
+ }
certs = Ref<X509Certificate>();
- if (pkey.is_valid())
+ if (pkey.is_valid()) {
pkey->unlock();
+ }
pkey = Ref<CryptoKeyMbedTLS>();
cookies = Ref<CookieContextMbedTLS>();
inited = false;
diff --git a/modules/mbedtls/stream_peer_mbedtls.cpp b/modules/mbedtls/stream_peer_mbedtls.cpp
index c6b0846716..e9a610b7ee 100644
--- a/modules/mbedtls/stream_peer_mbedtls.cpp
+++ b/modules/mbedtls/stream_peer_mbedtls.cpp
@@ -34,8 +34,9 @@
#include "core/os/file_access.h"
int StreamPeerMbedTLS::bio_send(void *ctx, const unsigned char *buf, size_t len) {
- if (buf == nullptr || len <= 0)
+ if (buf == nullptr || len <= 0) {
return 0;
+ }
StreamPeerMbedTLS *sp = (StreamPeerMbedTLS *)ctx;
@@ -53,8 +54,9 @@ int StreamPeerMbedTLS::bio_send(void *ctx, const unsigned char *buf, size_t len)
}
int StreamPeerMbedTLS::bio_recv(void *ctx, unsigned char *buf, size_t len) {
- if (buf == nullptr || len <= 0)
+ if (buf == nullptr || len <= 0) {
return 0;
+ }
StreamPeerMbedTLS *sp = (StreamPeerMbedTLS *)ctx;
@@ -167,8 +169,9 @@ Error StreamPeerMbedTLS::put_partial_data(const uint8_t *p_data, int p_bytes, in
r_sent = 0;
- if (p_bytes == 0)
+ if (p_bytes == 0) {
return OK;
+ }
int ret = mbedtls_ssl_write(ssl_ctx->get_context(), p_data, p_bytes);
if (ret == MBEDTLS_ERR_SSL_WANT_READ || ret == MBEDTLS_ERR_SSL_WANT_WRITE) {
@@ -279,8 +282,9 @@ StreamPeerMbedTLS::~StreamPeerMbedTLS() {
}
void StreamPeerMbedTLS::disconnect_from_stream() {
- if (status != STATUS_CONNECTED && status != STATUS_HANDSHAKING)
+ if (status != STATUS_CONNECTED && status != STATUS_HANDSHAKING) {
return;
+ }
Ref<StreamPeerTCP> tcp = base;
if (tcp.is_valid() && tcp->get_status() == StreamPeerTCP::STATUS_CONNECTED) {
diff --git a/modules/mobile_vr/mobile_vr_interface.cpp b/modules/mobile_vr/mobile_vr_interface.cpp
index 6d10de0096..eebb3af709 100644
--- a/modules/mobile_vr/mobile_vr_interface.cpp
+++ b/modules/mobile_vr/mobile_vr_interface.cpp
@@ -61,19 +61,25 @@ Vector3 MobileVRInterface::scale_magneto(const Vector3 &p_magnetometer) {
};
// adjust our min and max
- if (mag_raw.x > mag_next_max.x)
+ if (mag_raw.x > mag_next_max.x) {
mag_next_max.x = mag_raw.x;
- if (mag_raw.y > mag_next_max.y)
+ }
+ if (mag_raw.y > mag_next_max.y) {
mag_next_max.y = mag_raw.y;
- if (mag_raw.z > mag_next_max.z)
+ }
+ if (mag_raw.z > mag_next_max.z) {
mag_next_max.z = mag_raw.z;
+ }
- if (mag_raw.x < mag_next_min.x)
+ if (mag_raw.x < mag_next_min.x) {
mag_next_min.x = mag_raw.x;
- if (mag_raw.y < mag_next_min.y)
+ }
+ if (mag_raw.y < mag_next_min.y) {
mag_next_min.y = mag_raw.y;
- if (mag_raw.z < mag_next_min.z)
+ }
+ if (mag_raw.z < mag_next_min.z) {
mag_next_min.z = mag_raw.z;
+ }
// scale our x, y and z
if (!(mag_current_max.x - mag_current_min.x)) {
diff --git a/modules/opensimplex/noise_texture.cpp b/modules/opensimplex/noise_texture.cpp
index 2ded998b60..1181e69cd3 100644
--- a/modules/opensimplex/noise_texture.cpp
+++ b/modules/opensimplex/noise_texture.cpp
@@ -124,8 +124,9 @@ void NoiseTexture::_thread_function(void *p_ud) {
}
void NoiseTexture::_queue_update() {
- if (update_queued)
+ if (update_queued) {
return;
+ }
update_queued = true;
call_deferred("_update_texture");
@@ -179,8 +180,9 @@ void NoiseTexture::_update_texture() {
}
void NoiseTexture::set_noise(Ref<OpenSimplexNoise> p_noise) {
- if (p_noise == noise)
+ if (p_noise == noise) {
return;
+ }
if (noise.is_valid()) {
noise->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &NoiseTexture::_queue_update));
}
@@ -196,22 +198,25 @@ Ref<OpenSimplexNoise> NoiseTexture::get_noise() {
}
void NoiseTexture::set_width(int p_width) {
- if (p_width == size.x)
+ if (p_width == size.x) {
return;
+ }
size.x = p_width;
_queue_update();
}
void NoiseTexture::set_height(int p_height) {
- if (p_height == size.y)
+ if (p_height == size.y) {
return;
+ }
size.y = p_height;
_queue_update();
}
void NoiseTexture::set_seamless(bool p_seamless) {
- if (p_seamless == seamless)
+ if (p_seamless == seamless) {
return;
+ }
seamless = p_seamless;
_queue_update();
}
@@ -221,8 +226,9 @@ bool NoiseTexture::get_seamless() {
}
void NoiseTexture::set_as_normalmap(bool p_as_normalmap) {
- if (p_as_normalmap == as_normalmap)
+ if (p_as_normalmap == as_normalmap) {
return;
+ }
as_normalmap = p_as_normalmap;
_queue_update();
_change_notify();
@@ -233,11 +239,13 @@ bool NoiseTexture::is_normalmap() {
}
void NoiseTexture::set_bump_strength(float p_bump_strength) {
- if (p_bump_strength == bump_strength)
+ if (p_bump_strength == bump_strength) {
return;
+ }
bump_strength = p_bump_strength;
- if (as_normalmap)
+ if (as_normalmap) {
_queue_update();
+ }
}
float NoiseTexture::get_bump_strength() {
diff --git a/modules/opensimplex/open_simplex_noise.cpp b/modules/opensimplex/open_simplex_noise.cpp
index 97b66f2c07..00b3d47db9 100644
--- a/modules/opensimplex/open_simplex_noise.cpp
+++ b/modules/opensimplex/open_simplex_noise.cpp
@@ -52,8 +52,9 @@ void OpenSimplexNoise::_init_seeds() {
}
void OpenSimplexNoise::set_seed(int p_seed) {
- if (seed == p_seed)
+ if (seed == p_seed) {
return;
+ }
seed = p_seed;
@@ -67,8 +68,9 @@ int OpenSimplexNoise::get_seed() {
}
void OpenSimplexNoise::set_octaves(int p_octaves) {
- if (p_octaves == octaves)
+ if (p_octaves == octaves) {
return;
+ }
ERR_FAIL_COND_MSG(p_octaves > MAX_OCTAVES, vformat("The number of OpenSimplexNoise octaves is limited to %d; ignoring the new value.", MAX_OCTAVES));
@@ -77,22 +79,25 @@ void OpenSimplexNoise::set_octaves(int p_octaves) {
}
void OpenSimplexNoise::set_period(float p_period) {
- if (p_period == period)
+ if (p_period == period) {
return;
+ }
period = p_period;
emit_changed();
}
void OpenSimplexNoise::set_persistence(float p_persistence) {
- if (p_persistence == persistence)
+ if (p_persistence == persistence) {
return;
+ }
persistence = p_persistence;
emit_changed();
}
void OpenSimplexNoise::set_lacunarity(float p_lacunarity) {
- if (p_lacunarity == lacunarity)
+ if (p_lacunarity == lacunarity) {
return;
+ }
lacunarity = p_lacunarity;
emit_changed();
}
diff --git a/modules/pvr/texture_loader_pvr.cpp b/modules/pvr/texture_loader_pvr.cpp
index 20f46e1f7a..36c0913f62 100644
--- a/modules/pvr/texture_loader_pvr.cpp
+++ b/modules/pvr/texture_loader_pvr.cpp
@@ -52,20 +52,23 @@ enum PVRFLags {
};
RES ResourceFormatPVR::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) {
- if (r_error)
+ if (r_error) {
*r_error = ERR_CANT_OPEN;
+ }
Error err;
FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err);
- if (!f)
+ if (!f) {
return RES();
+ }
FileAccessRef faref(f);
ERR_FAIL_COND_V(err, RES());
- if (r_error)
+ if (r_error) {
*r_error = ERR_FILE_CORRUPT;
+ }
uint32_t hsize = f->get_32();
@@ -160,8 +163,9 @@ RES ResourceFormatPVR::load(const String &p_path, const String &p_original_path,
Ref<ImageTexture> texture = memnew(ImageTexture);
texture->create_from_image(image);
- if (r_error)
+ if (r_error) {
*r_error = OK;
+ }
return texture;
}
@@ -175,8 +179,9 @@ bool ResourceFormatPVR::handles_type(const String &p_type) const {
}
String ResourceFormatPVR::get_resource_type(const String &p_path) const {
- if (p_path.get_extension().to_lower() == "pvr")
+ if (p_path.get_extension().to_lower() == "pvr") {
return "Texture2D";
+ }
return "";
}
@@ -189,8 +194,9 @@ static void _compress_pvrtc4(Image *p_img) {
img->resize_to_po2(true);
}
img->convert(Image::FORMAT_RGBA8);
- if (!img->has_mipmaps() && make_mipmaps)
+ if (!img->has_mipmaps() && make_mipmaps) {
img->generate_mipmaps();
+ }
bool use_alpha = img->detect_alpha();
@@ -253,8 +259,9 @@ struct PVRTCBlock {
};
_FORCE_INLINE_ bool is_po2(uint32_t p_input) {
- if (p_input == 0)
+ if (p_input == 0) {
return false;
+ }
uint32_t minus1 = p_input - 1;
return ((p_input | minus1) == (p_input ^ minus1)) ? true : false;
}
@@ -269,8 +276,9 @@ static void unpack_5554(const PVRTCBlock *p_block, int p_ab_colors[2][4]) {
p_ab_colors[i][0] = (raw_bits[i] >> 10) & 0x1F;
p_ab_colors[i][1] = (raw_bits[i] >> 5) & 0x1F;
p_ab_colors[i][2] = raw_bits[i] & 0x1F;
- if (i == 0)
+ if (i == 0) {
p_ab_colors[0][2] |= p_ab_colors[0][2] >> 4;
+ }
p_ab_colors[i][3] = 0xF;
} else {
p_ab_colors[i][0] = (raw_bits[i] >> (8 - 1)) & 0x1E;
@@ -281,10 +289,11 @@ static void unpack_5554(const PVRTCBlock *p_block, int p_ab_colors[2][4]) {
p_ab_colors[i][2] = (raw_bits[i] & 0xF) << 1;
- if (i == 0)
+ if (i == 0) {
p_ab_colors[0][2] |= p_ab_colors[0][2] >> 3;
- else
+ } else {
p_ab_colors[0][2] |= p_ab_colors[0][2] >> 4;
+ }
p_ab_colors[i][3] = (raw_bits[i] >> 11) & 0xE;
}
@@ -312,10 +321,11 @@ static void unpack_modulations(const PVRTCBlock *p_block, const int p_2bit, int
for (int x = 0; x < BLK_X_2BPP; x++) {
p_modulation_modes[y + p_y][x + p_x] = block_mod_mode;
- if (modulation_bits & 1)
+ if (modulation_bits & 1) {
p_modulation[y + p_y][x + p_x] = 0x3;
- else
+ } else {
p_modulation[y + p_y][x + p_x] = 0x0;
+ }
modulation_bits >>= 1;
}
@@ -350,10 +360,11 @@ static void interpolate_colors(const int p_colorp[4], const int p_colorq[4], con
v = (y & 0x3) | ((~y & 0x2) << 1);
- if (p_2bit)
+ if (p_2bit) {
u = (x & 0x7) | ((~x & 0x4) << 1);
- else
+ } else {
u = (x & 0x3) | ((~x & 0x2) << 1);
+ }
v = v - BLK_Y_SIZE / 2;
@@ -409,19 +420,20 @@ static void get_modulation_value(int x, int y, const int p_2bit, const int p_mod
y = (y & 0x3) | ((~y & 0x2) << 1);
- if (p_2bit)
+ if (p_2bit) {
x = (x & 0x7) | ((~x & 0x4) << 1);
- else
+ } else {
x = (x & 0x3) | ((~x & 0x2) << 1);
+ }
*p_dopt = 0;
if (p_modulation_modes[y][x] == 0) {
mod_val = rep_vals0[p_modulation[y][x]];
} else if (p_2bit) {
- if (((x ^ y) & 1) == 0)
+ if (((x ^ y) & 1) == 0) {
mod_val = rep_vals0[p_modulation[y][x]];
- else if (p_modulation_modes[y][x] == 1) {
+ } else if (p_modulation_modes[y][x] == 1) {
mod_val = (rep_vals0[p_modulation[y - 1][x]] +
rep_vals0[p_modulation[y + 1][x]] +
rep_vals0[p_modulation[y][x - 1]] +
@@ -472,8 +484,9 @@ static uint32_t twiddle_uv(uint32_t p_height, uint32_t p_width, uint32_t p_y, ui
max_value = p_y;
}
- if (disable_twiddling)
+ if (disable_twiddling) {
return (p_y * p_width + p_x);
+ }
scr_bit_pos = 1;
dst_bit_pos = 1;
@@ -533,10 +546,11 @@ static void decompress_pvrtc(PVRTCBlock *p_comp_img, const int p_2bit, const int
int r_result[4];
- if (p_2bit)
+ if (p_2bit) {
x_block_size = BLK_X_2BPP;
- else
+ } else {
x_block_size = BLK_X_4BPP;
+ }
block_width = MAX(2, p_width / x_block_size);
block_height = MAX(2, p_height / BLK_Y_SIZE);
@@ -607,8 +621,9 @@ static void decompress_pvrtc(PVRTCBlock *p_comp_img, const int p_2bit, const int
r_result[i] >>= 3;
}
- if (DoPT)
+ if (DoPT) {
r_result[3] = 0;
+ }
u_pos = (x + y * p_width) << 2;
p_dst[u_pos + 0] = (uint8_t)r_result[0];
@@ -635,6 +650,7 @@ static void _pvrtc_decompress(Image *p_img) {
bool make_mipmaps = p_img->has_mipmaps();
p_img->create(p_img->get_width(), p_img->get_height(), false, Image::FORMAT_RGBA8, newdata);
- if (make_mipmaps)
+ if (make_mipmaps) {
p_img->generate_mipmaps();
+ }
}
diff --git a/modules/regex/regex.cpp b/modules/regex/regex.cpp
index c0627b8f25..50ca01067b 100644
--- a/modules/regex/regex.cpp
+++ b/modules/regex/regex.cpp
@@ -46,14 +46,16 @@ static void _regex_free(void *ptr, void *user) {
int RegExMatch::_find(const Variant &p_name) const {
if (p_name.is_num()) {
int i = (int)p_name;
- if (i >= data.size())
+ if (i >= data.size()) {
return -1;
+ }
return i;
} else if (p_name.get_type() == Variant::STRING) {
const Map<String, int>::Element *found = names.find((String)p_name);
- if (found)
+ if (found) {
return found->value();
+ }
}
return -1;
@@ -64,8 +66,9 @@ String RegExMatch::get_subject() const {
}
int RegExMatch::get_group_count() const {
- if (data.size() == 0)
+ if (data.size() == 0) {
return 0;
+ }
return data.size() - 1;
}
@@ -103,13 +106,15 @@ Array RegExMatch::get_strings() const {
String RegExMatch::get_string(const Variant &p_name) const {
int id = _find(p_name);
- if (id < 0)
+ if (id < 0) {
return String();
+ }
int start = data[id].start;
- if (start == -1)
+ if (start == -1) {
return String();
+ }
int length = data[id].end - start;
@@ -119,8 +124,9 @@ String RegExMatch::get_string(const Variant &p_name) const {
int RegExMatch::get_start(const Variant &p_name) const {
int id = _find(p_name);
- if (id < 0)
+ if (id < 0) {
return -1;
+ }
return data[id].start;
}
@@ -128,8 +134,9 @@ int RegExMatch::get_start(const Variant &p_name) const {
int RegExMatch::get_end(const Variant &p_name) const {
int id = _find(p_name);
- if (id < 0)
+ if (id < 0) {
return -1;
+ }
return data[id].end;
}
@@ -223,8 +230,9 @@ Ref<RegExMatch> RegEx::search(const String &p_subject, int p_offset, int p_end)
Ref<RegExMatch> result = memnew(RegExMatch);
int length = p_subject.length();
- if (p_end >= 0 && p_end < length)
+ if (p_end >= 0 && p_end < length) {
length = p_end;
+ }
if (sizeof(CharType) == 2) {
pcre2_code_16 *c = (pcre2_code_16 *)code;
@@ -297,11 +305,13 @@ Ref<RegExMatch> RegEx::search(const String &p_subject, int p_offset, int p_end)
for (uint32_t i = 0; i < count; i++) {
CharType id = table[i * entry_size];
- if (result->data[id].start == -1)
+ if (result->data[id].start == -1) {
continue;
+ }
String name = &table[i * entry_size + 1];
- if (result->names.has(name))
+ if (result->names.has(name)) {
continue;
+ }
result->names.insert(name, id);
}
@@ -314,8 +324,9 @@ Array RegEx::search_all(const String &p_subject, int p_offset, int p_end) const
Array result;
Ref<RegExMatch> match = search(p_subject, p_offset, p_end);
while (match.is_valid()) {
- if (last_end == match->get_end(0))
+ if (last_end == match->get_end(0)) {
break;
+ }
result.push_back(match);
last_end = match->get_end(0);
match = search(p_subject, match->get_end(0), p_end);
@@ -337,12 +348,14 @@ String RegEx::sub(const String &p_subject, const String &p_replacement, bool p_a
output.resize(olength + safety_zone);
uint32_t flags = PCRE2_SUBSTITUTE_OVERFLOW_LENGTH;
- if (p_all)
+ if (p_all) {
flags |= PCRE2_SUBSTITUTE_GLOBAL;
+ }
PCRE2_SIZE length = p_subject.length();
- if (p_end >= 0 && (uint32_t)p_end < length)
+ if (p_end >= 0 && (uint32_t)p_end < length) {
length = p_end;
+ }
if (sizeof(CharType) == 2) {
pcre2_code_16 *c = (pcre2_code_16 *)code;
@@ -365,8 +378,9 @@ String RegEx::sub(const String &p_subject, const String &p_replacement, bool p_a
pcre2_match_data_free_16(match);
pcre2_match_context_free_16(mctx);
- if (res < 0)
+ if (res < 0) {
return String();
+ }
} else {
pcre2_code_32 *c = (pcre2_code_32 *)code;
@@ -389,8 +403,9 @@ String RegEx::sub(const String &p_subject, const String &p_replacement, bool p_a
pcre2_match_data_free_32(match);
pcre2_match_context_free_32(mctx);
- if (res < 0)
+ if (res < 0) {
return String();
+ }
}
return String(output.ptr(), olength);
@@ -460,13 +475,15 @@ RegEx::RegEx(const String &p_pattern) {
RegEx::~RegEx() {
if (sizeof(CharType) == 2) {
- if (code)
+ if (code) {
pcre2_code_free_16((pcre2_code_16 *)code);
+ }
pcre2_general_context_free_16((pcre2_general_context_16 *)general_ctx);
} else {
- if (code)
+ if (code) {
pcre2_code_free_32((pcre2_code_32 *)code);
+ }
pcre2_general_context_free_32((pcre2_general_context_32 *)general_ctx);
}
}
diff --git a/modules/squish/image_compress_squish.cpp b/modules/squish/image_compress_squish.cpp
index a19f3158c4..c510779317 100644
--- a/modules/squish/image_compress_squish.cpp
+++ b/modules/squish/image_compress_squish.cpp
@@ -78,8 +78,9 @@ void image_decompress_squish(Image *p_image) {
}
void image_compress_squish(Image *p_image, float p_lossy_quality, Image::UsedChannels p_channels) {
- if (p_image->get_format() >= Image::FORMAT_DXT1)
+ if (p_image->get_format() >= Image::FORMAT_DXT1) {
return; //do not compress, already compressed
+ }
int w = p_image->get_width();
int h = p_image->get_height();
@@ -87,10 +88,11 @@ void image_compress_squish(Image *p_image, float p_lossy_quality, Image::UsedCha
if (p_image->get_format() <= Image::FORMAT_RGBA8) {
int squish_comp = squish::kColourRangeFit;
- if (p_lossy_quality > 0.85)
+ if (p_lossy_quality > 0.85) {
squish_comp = squish::kColourIterativeClusterFit;
- else if (p_lossy_quality > 0.75)
+ } else if (p_lossy_quality > 0.75) {
squish_comp = squish::kColourClusterFit;
+ }
Image::Format target_format = Image::FORMAT_RGBA8;
diff --git a/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp b/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp
index 775a2f23c7..3aceaf11c5 100644
--- a/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp
+++ b/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp
@@ -102,8 +102,9 @@ float AudioStreamPlaybackOGGVorbis::get_playback_position() const {
}
void AudioStreamPlaybackOGGVorbis::seek(float p_time) {
- if (!active)
+ if (!active) {
return;
+ }
if (p_time >= vorbis_stream->get_length()) {
p_time = 0;
diff --git a/modules/tga/image_loader_tga.cpp b/modules/tga/image_loader_tga.cpp
index 53c6a8c269..ce889a4928 100644
--- a/modules/tga/image_loader_tga.cpp
+++ b/modules/tga/image_loader_tga.cpp
@@ -38,8 +38,9 @@ Error ImageLoaderTGA::decode_tga_rle(const uint8_t *p_compressed_buffer, size_t
Vector<uint8_t> pixels;
error = pixels.resize(p_pixel_size);
- if (error != OK)
+ if (error != OK) {
return error;
+ }
uint8_t *pixels_w = pixels.ptrw();
@@ -232,8 +233,9 @@ Error ImageLoaderTGA::load_image(Ref<Image> p_image, FileAccess *f, bool p_force
bool has_color_map = (tga_header.image_type == TGA_TYPE_RLE_INDEXED || tga_header.image_type == TGA_TYPE_INDEXED);
bool is_monochrome = (tga_header.image_type == TGA_TYPE_RLE_MONOCHROME || tga_header.image_type == TGA_TYPE_MONOCHROME);
- if (tga_header.image_type == TGA_TYPE_NO_DATA)
+ if (tga_header.image_type == TGA_TYPE_NO_DATA) {
err = FAILED;
+ }
if (has_color_map) {
if (tga_header.color_map_length > 256 || (tga_header.color_map_depth != 24) || tga_header.color_map_type != 1) {
@@ -245,8 +247,9 @@ Error ImageLoaderTGA::load_image(Ref<Image> p_image, FileAccess *f, bool p_force
}
}
- if (tga_header.image_width <= 0 || tga_header.image_height <= 0)
+ if (tga_header.image_width <= 0 || tga_header.image_height <= 0) {
err = FAILED;
+ }
if (!(tga_header.pixel_depth == 8 || tga_header.pixel_depth == 24 || tga_header.pixel_depth == 32)) {
err = FAILED;
diff --git a/modules/theora/video_stream_theora.cpp b/modules/theora/video_stream_theora.cpp
index 7df204ff51..4d83e6a4a5 100644
--- a/modules/theora/video_stream_theora.cpp
+++ b/modules/theora/video_stream_theora.cpp
@@ -68,13 +68,15 @@ int VideoStreamPlaybackTheora::buffer_data() {
int VideoStreamPlaybackTheora::queue_page(ogg_page *page) {
if (theora_p) {
ogg_stream_pagein(&to, page);
- if (to.e_o_s)
+ if (to.e_o_s) {
theora_eos = true;
+ }
}
if (vorbis_p) {
ogg_stream_pagein(&vo, page);
- if (vo.e_o_s)
+ if (vo.e_o_s) {
vorbis_eos = true;
+ }
}
return 0;
}
@@ -112,8 +114,9 @@ void VideoStreamPlaybackTheora::video_write() {
}
void VideoStreamPlaybackTheora::clear() {
- if (!file)
+ if (!file) {
return;
+ }
if (vorbis_p) {
ogg_stream_clear(&vo);
@@ -203,8 +206,9 @@ void VideoStreamPlaybackTheora::set_file(const String &p_file) {
while (!stateflag) {
int ret = buffer_data();
- if (ret == 0)
+ if (ret == 0) {
break;
+ }
while (ogg_sync_pageout(&oy, &og) > 0) {
ogg_stream_state test;
@@ -280,8 +284,9 @@ void VideoStreamPlaybackTheora::set_file(const String &p_file) {
return;
}
vorbis_p++;
- if (vorbis_p == 3)
+ if (vorbis_p == 3) {
break;
+ }
}
/* The header pages/packets will arrive before anything else we
@@ -371,8 +376,9 @@ Ref<Texture2D> VideoStreamPlaybackTheora::get_texture() const {
}
void VideoStreamPlaybackTheora::update(float p_delta) {
- if (!file)
+ if (!file) {
return;
+ }
if (!playing || paused) {
//printf("not playing\n");
@@ -450,8 +456,9 @@ void VideoStreamPlaybackTheora::update(float p_delta) {
audio_done = videobuf_time < (audio_frames_wrote / float(vi.rate));
- if (buffer_full)
+ if (buffer_full) {
break;
+ }
}
while (theora_p && !frame_done) {
@@ -542,9 +549,9 @@ void VideoStreamPlaybackTheora::update(float p_delta) {
};
void VideoStreamPlaybackTheora::play() {
- if (!playing)
+ if (!playing) {
time = 0;
- else {
+ } else {
stop();
}
@@ -679,8 +686,9 @@ VideoStreamPlaybackTheora::~VideoStreamPlaybackTheora() {
#endif
clear();
- if (file)
+ if (file) {
memdelete(file);
+ }
};
void VideoStreamTheora::_bind_methods() {
@@ -725,7 +733,8 @@ bool ResourceFormatLoaderTheora::handles_type(const String &p_type) const {
String ResourceFormatLoaderTheora::get_resource_type(const String &p_path) const {
String el = p_path.get_extension().to_lower();
- if (el == "ogv")
+ if (el == "ogv") {
return "VideoStreamTheora";
+ }
return "";
}
diff --git a/modules/tinyexr/image_loader_tinyexr.cpp b/modules/tinyexr/image_loader_tinyexr.cpp
index dc34fe3003..9e7266b95a 100644
--- a/modules/tinyexr/image_loader_tinyexr.cpp
+++ b/modules/tinyexr/image_loader_tinyexr.cpp
@@ -212,8 +212,9 @@ Error ImageLoaderTinyEXR::load_image(Ref<Image> p_image, FileAccess *f, bool p_f
for (int x = 0; x < tw; x++) {
Color color(*r_channel++, *g_channel++, *b_channel++);
- if (p_force_linear)
+ if (p_force_linear) {
color = color.to_linear();
+ }
*row_w++ = Math::make_half_float(color.r);
*row_w++ = Math::make_half_float(color.g);
diff --git a/modules/visual_script/register_types.cpp b/modules/visual_script/register_types.cpp
index 42d0fb37fe..8afed1229f 100644
--- a/modules/visual_script/register_types.cpp
+++ b/modules/visual_script/register_types.cpp
@@ -134,6 +134,7 @@ void unregister_visual_script_types() {
memdelete(vs_editor_singleton);
}
#endif
- if (visual_script_language)
+ if (visual_script_language) {
memdelete(visual_script_language);
+ }
}
diff --git a/modules/visual_script/visual_script.cpp b/modules/visual_script/visual_script.cpp
index 4d5e5200b6..f387c0f288 100644
--- a/modules/visual_script/visual_script.cpp
+++ b/modules/visual_script/visual_script.cpp
@@ -133,8 +133,9 @@ VisualScriptNode::TypeGuess VisualScriptNode::guess_output_type(TypeGuess *p_inp
}
Ref<VisualScript> VisualScriptNode::get_visual_script() const {
- if (scripts_used.size())
+ if (scripts_used.size()) {
return Ref<VisualScript>(scripts_used.front()->get());
+ }
return Ref<VisualScript>();
}
@@ -194,8 +195,9 @@ void VisualScript::remove_function(const StringName &p_name) {
void VisualScript::rename_function(const StringName &p_name, const StringName &p_new_name) {
ERR_FAIL_COND(instances.size());
ERR_FAIL_COND(!functions.has(p_name));
- if (p_new_name == p_name)
+ if (p_new_name == p_name) {
return;
+ }
ERR_FAIL_COND(!String(p_new_name).is_valid_identifier());
@@ -506,8 +508,9 @@ bool VisualScript::is_input_value_port_connected(const StringName &p_func, int p
const Function &func = functions[p_func];
for (const Set<DataConnection>::Element *E = func.data_connections.front(); E; E = E->next()) {
- if (E->get().to_node == p_node && E->get().to_port == p_port)
+ if (E->get().to_node == p_node && E->get().to_port == p_port) {
return true;
+ }
}
return false;
@@ -620,16 +623,21 @@ bool VisualScript::get_variable_export(const StringName &p_name) const {
void VisualScript::_set_variable_info(const StringName &p_name, const Dictionary &p_info) {
PropertyInfo pinfo;
- if (p_info.has("type"))
+ if (p_info.has("type")) {
pinfo.type = Variant::Type(int(p_info["type"]));
- if (p_info.has("name"))
+ }
+ if (p_info.has("name")) {
pinfo.name = p_info["name"];
- if (p_info.has("hint"))
+ }
+ if (p_info.has("hint")) {
pinfo.hint = PropertyHint(int(p_info["hint"]));
- if (p_info.has("hint_string"))
+ }
+ if (p_info.has("hint_string")) {
pinfo.hint_string = p_info["hint_string"];
- if (p_info.has("usage"))
+ }
+ if (p_info.has("usage")) {
pinfo.usage = p_info["usage"];
+ }
set_variable_info(p_name, pinfo);
}
@@ -662,8 +670,9 @@ void VisualScript::set_instance_base_type(const StringName &p_type) {
void VisualScript::rename_variable(const StringName &p_name, const StringName &p_new_name) {
ERR_FAIL_COND(instances.size());
ERR_FAIL_COND(!variables.has(p_name));
- if (p_new_name == p_name)
+ if (p_new_name == p_name) {
return;
+ }
ERR_FAIL_COND(!String(p_new_name).is_valid_identifier());
@@ -682,13 +691,15 @@ void VisualScript::rename_variable(const StringName &p_name, const StringName &p
for (List<int>::Element *E = ids.front(); E; E = E->next()) {
Ref<VisualScriptVariableGet> nodeget = get_node(F->get(), E->get());
if (nodeget.is_valid()) {
- if (nodeget->get_variable() == p_name)
+ if (nodeget->get_variable() == p_name) {
nodeget->set_variable(p_new_name);
+ }
} else {
Ref<VisualScriptVariableSet> nodeset = get_node(F->get(), E->get());
if (nodeset.is_valid()) {
- if (nodeset->get_variable() == p_name)
+ if (nodeset->get_variable() == p_name) {
nodeset->set_variable(p_new_name);
+ }
}
}
}
@@ -713,10 +724,11 @@ void VisualScript::custom_signal_add_argument(const StringName &p_func, Variant:
Argument arg;
arg.type = p_type;
arg.name = p_name;
- if (p_index < 0)
+ if (p_index < 0) {
custom_signals[p_func].push_back(arg);
- else
+ } else {
custom_signals[p_func].insert(0, arg);
+ }
}
void VisualScript::custom_signal_set_argument_type(const StringName &p_func, int p_argidx, Variant::Type p_type) {
@@ -775,8 +787,9 @@ void VisualScript::remove_custom_signal(const StringName &p_name) {
void VisualScript::rename_custom_signal(const StringName &p_name, const StringName &p_new_name) {
ERR_FAIL_COND(instances.size());
ERR_FAIL_COND(!custom_signals.has(p_name));
- if (p_new_name == p_name)
+ if (p_new_name == p_name) {
return;
+ }
ERR_FAIL_COND(!String(p_new_name).is_valid_identifier());
@@ -799,8 +812,9 @@ void VisualScript::get_custom_signal_list(List<StringName> *r_custom_signals) co
int VisualScript::get_available_id() const {
int max_id = 0;
for (Map<StringName, Function>::Element *E = functions.front(); E; E = E->next()) {
- if (E->get().nodes.empty())
+ if (E->get().nodes.empty()) {
continue;
+ }
int last_id = E->get().nodes.back()->key();
max_id = MAX(max_id, last_id + 1);
@@ -829,14 +843,16 @@ void VisualScript::_placeholder_erased(PlaceHolderScriptInstance *p_placeholder)
}
void VisualScript::_update_placeholders() {
- if (placeholders.size() == 0)
+ if (placeholders.size() == 0) {
return; //no bother if no placeholders
+ }
List<PropertyInfo> pinfo;
Map<StringName, Variant> values;
for (Map<StringName, Variable>::Element *E = variables.front(); E; E = E->next()) {
- if (!E->get()._export)
+ if (!E->get()._export) {
continue;
+ }
PropertyInfo p = E->get().info;
p.name = String(E->key());
@@ -862,8 +878,9 @@ ScriptInstance *VisualScript::instance_create(Object *p_this) {
Map<StringName, Variant> values;
for (Map<StringName, Variable>::Element *E = variables.front(); E; E = E->next()) {
- if (!E->get()._export)
+ if (!E->get()._export) {
continue;
+ }
PropertyInfo p = E->get().info;
p.name = String(E->key());
@@ -940,8 +957,9 @@ void VisualScript::get_script_signal_list(List<MethodInfo> *r_signals) const {
}
bool VisualScript::get_property_default_value(const StringName &p_property, Variant &r_value) const {
- if (!variables.has(p_property))
+ if (!variables.has(p_property)) {
return false;
+ }
r_value = variables[p_property].default_value;
return true;
@@ -973,8 +991,9 @@ bool VisualScript::has_method(const StringName &p_method) const {
MethodInfo VisualScript::get_method_info(const StringName &p_method) const {
const Map<StringName, Function>::Element *E = functions.find(p_method);
- if (!E)
+ if (!E) {
return MethodInfo();
+ }
MethodInfo mi;
mi.name = E->key();
@@ -1014,8 +1033,9 @@ int VisualScript::get_member_line(const StringName &p_member) const {
#ifdef TOOLS_ENABLED
if (has_function(p_member)) {
for (Map<int, Function::NodeData>::Element *E = functions[p_member].nodes.front(); E; E = E->next()) {
- if (Object::cast_to<VisualScriptFunction>(E->get().node.ptr()))
+ if (Object::cast_to<VisualScriptFunction>(E->get().node.ptr())) {
return E->key();
+ }
}
}
#endif
@@ -1092,8 +1112,9 @@ MultiplayerAPI::RPCMode VisualScript::get_rset_mode(const StringName &p_variable
void VisualScript::_set_data(const Dictionary &p_data) {
Dictionary d = p_data;
- if (d.has("base_type"))
+ if (d.has("base_type")) {
base_type = d["base_type"];
+ }
variables.clear();
Array vars = d["variables"];
@@ -1184,10 +1205,11 @@ void VisualScript::_set_data(const Dictionary &p_data) {
}
}
- if (d.has("is_tool_script"))
+ if (d.has("is_tool_script")) {
is_tool_script = d["is_tool_script"];
- else
+ } else {
is_tool_script = false;
+ }
// Takes all the rpc methods
rpc_functions.clear();
@@ -1390,8 +1412,9 @@ VisualScript::~VisualScript() {
bool VisualScriptInstance::set(const StringName &p_name, const Variant &p_value) {
Map<StringName, Variant>::Element *E = variables.find(p_name);
- if (!E)
+ if (!E) {
return false;
+ }
E->get() = p_value;
@@ -1400,8 +1423,9 @@ bool VisualScriptInstance::set(const StringName &p_name, const Variant &p_value)
bool VisualScriptInstance::get(const StringName &p_name, Variant &r_ret) const {
const Map<StringName, Variant>::Element *E = variables.find(p_name);
- if (!E)
+ if (!E) {
return false;
+ }
r_ret = E->get();
return true;
@@ -1409,8 +1433,9 @@ bool VisualScriptInstance::get(const StringName &p_name, Variant &r_ret) const {
void VisualScriptInstance::get_property_list(List<PropertyInfo> *p_properties) const {
for (const Map<StringName, VisualScript::Variable>::Element *E = script->variables.front(); E; E = E->next()) {
- if (!E->get()._export)
+ if (!E->get()._export) {
continue;
+ }
PropertyInfo p = E->get().info;
p.name = String(E->key());
p.usage |= PROPERTY_USAGE_SCRIPT_VARIABLE;
@@ -1421,13 +1446,15 @@ void VisualScriptInstance::get_property_list(List<PropertyInfo> *p_properties) c
Variant::Type VisualScriptInstance::get_property_type(const StringName &p_name, bool *r_is_valid) const {
const Map<StringName, VisualScript::Variable>::Element *E = script->variables.find(p_name);
if (!E) {
- if (r_is_valid)
+ if (r_is_valid) {
*r_is_valid = false;
+ }
ERR_FAIL_V(Variant::NIL);
}
- if (r_is_valid)
+ if (r_is_valid) {
*r_is_valid = true;
+ }
return E->get().info.type;
}
@@ -1462,8 +1489,9 @@ void VisualScriptInstance::get_method_list(List<MethodInfo> *p_list) const {
}
bool VisualScriptInstance::has_method(const StringName &p_method) const {
- if (p_method == script->get_default_func())
+ if (p_method == script->get_default_func()) {
return false;
+ }
return script->functions.has(p_method);
}
@@ -1474,8 +1502,9 @@ bool VisualScriptInstance::has_method(const StringName &p_method) const {
void VisualScriptInstance::_dependency_step(VisualScriptNodeInstance *node, int p_pass, int *pass_stack, const Variant **input_args, Variant **output_args, Variant *variant_stack, Callable::CallError &r_error, String &error_str, VisualScriptNodeInstance **r_error_node) {
ERR_FAIL_COND(node->pass_idx == -1);
- if (pass_stack[node->pass_idx] == p_pass)
+ if (pass_stack[node->pass_idx] == p_pass) {
return;
+ }
pass_stack[node->pass_idx] = p_pass;
@@ -1485,8 +1514,9 @@ void VisualScriptInstance::_dependency_step(VisualScriptNodeInstance *node, int
for (int i = 0; i < dc; i++) {
_dependency_step(deps[i], p_pass, pass_stack, input_args, output_args, variant_stack, r_error, error_str, r_error_node);
- if (r_error.error != Callable::CallError::CALL_OK)
+ if (r_error.error != Callable::CallError::CALL_OK) {
return;
+ }
}
}
@@ -1599,8 +1629,9 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p
}
}
- if (error)
+ if (error) {
break;
+ }
//setup output pointers
@@ -1684,14 +1715,17 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p
bool do_break = false;
if (EngineDebugger::get_script_debugger()->get_lines_left() > 0) {
- if (EngineDebugger::get_script_debugger()->get_depth() <= 0)
+ if (EngineDebugger::get_script_debugger()->get_depth() <= 0) {
EngineDebugger::get_script_debugger()->set_lines_left(EngineDebugger::get_script_debugger()->get_lines_left() - 1);
- if (EngineDebugger::get_script_debugger()->get_lines_left() <= 0)
+ }
+ if (EngineDebugger::get_script_debugger()->get_lines_left() <= 0) {
do_break = true;
+ }
}
- if (EngineDebugger::get_script_debugger()->is_breakpoint(current_node_id, source))
+ if (EngineDebugger::get_script_debugger()->is_breakpoint(current_node_id, source)) {
do_break = true;
+ }
if (do_break) {
VisualScriptLanguage::singleton->debug_break("Breakpoint", true);
@@ -1988,17 +2022,20 @@ String VisualScriptInstance::to_string(bool *r_valid) {
Variant ret = call(CoreStringNames::get_singleton()->_to_string, nullptr, 0, ce);
if (ce.error == Callable::CallError::CALL_OK) {
if (ret.get_type() != Variant::STRING) {
- if (r_valid)
+ if (r_valid) {
*r_valid = false;
+ }
ERR_FAIL_V_MSG(String(), "Wrong type for " + CoreStringNames::get_singleton()->_to_string + ", must be a String.");
}
- if (r_valid)
+ if (r_valid) {
*r_valid = true;
+ }
return ret.operator String();
}
}
- if (r_valid)
+ if (r_valid) {
*r_valid = false;
+ }
return String();
}
@@ -2057,16 +2094,21 @@ void VisualScriptInstance::create(const Ref<VisualScript> &p_script, Object *p_o
if (Object::cast_to<Node>(p_owner)) {
//turn on these if they exist and base is a node
Node *node = Object::cast_to<Node>(p_owner);
- if (p_script->functions.has("_process"))
+ if (p_script->functions.has("_process")) {
node->set_process(true);
- if (p_script->functions.has("_physics_process"))
+ }
+ if (p_script->functions.has("_physics_process")) {
node->set_physics_process(true);
- if (p_script->functions.has("_input"))
+ }
+ if (p_script->functions.has("_input")) {
node->set_process_input(true);
- if (p_script->functions.has("_unhandled_input"))
+ }
+ if (p_script->functions.has("_unhandled_input")) {
node->set_process_unhandled_input(true);
- if (p_script->functions.has("_unhandled_key_input"))
+ }
+ if (p_script->functions.has("_unhandled_key_input")) {
node->set_process_unhandled_key_input(true);
+ }
}
for (const Map<StringName, VisualScript::Variable>::Element *E = script->variables.front(); E; E = E->next()) {
@@ -2156,10 +2198,11 @@ void VisualScriptInstance::create(const Ref<VisualScript> &p_script, Object *p_o
StringName var_name;
- if (Object::cast_to<VisualScriptLocalVar>(*node))
+ if (Object::cast_to<VisualScriptLocalVar>(*node)) {
var_name = String(Object::cast_to<VisualScriptLocalVar>(*node)->get_var_name()).strip_edges();
- else
+ } else {
var_name = String(Object::cast_to<VisualScriptLocalVarSet>(*node)->get_var_name()).strip_edges();
+ }
if (!local_var_indices.has(var_name)) {
local_var_indices[var_name] = function.max_stack;
@@ -2491,15 +2534,17 @@ String VisualScriptLanguage::debug_get_error() const {
}
int VisualScriptLanguage::debug_get_stack_level_count() const {
- if (_debug_parse_err_node >= 0)
+ if (_debug_parse_err_node >= 0) {
return 1;
+ }
return _debug_call_stack_pos;
}
int VisualScriptLanguage::debug_get_stack_level_line(int p_level) const {
- if (_debug_parse_err_node >= 0)
+ if (_debug_parse_err_node >= 0) {
return _debug_parse_err_node;
+ }
ERR_FAIL_INDEX_V(p_level, _debug_call_stack_pos, -1);
@@ -2509,8 +2554,9 @@ int VisualScriptLanguage::debug_get_stack_level_line(int p_level) const {
}
String VisualScriptLanguage::debug_get_stack_level_function(int p_level) const {
- if (_debug_parse_err_node >= 0)
+ if (_debug_parse_err_node >= 0) {
return "";
+ }
ERR_FAIL_INDEX_V(p_level, _debug_call_stack_pos, "");
int l = _debug_call_stack_pos - p_level - 1;
@@ -2518,8 +2564,9 @@ String VisualScriptLanguage::debug_get_stack_level_function(int p_level) const {
}
String VisualScriptLanguage::debug_get_stack_level_source(int p_level) const {
- if (_debug_parse_err_node >= 0)
+ if (_debug_parse_err_node >= 0) {
return _debug_parse_err_file;
+ }
ERR_FAIL_INDEX_V(p_level, _debug_call_stack_pos, "");
int l = _debug_call_stack_pos - p_level - 1;
@@ -2527,8 +2574,9 @@ String VisualScriptLanguage::debug_get_stack_level_source(int p_level) const {
}
void VisualScriptLanguage::debug_get_stack_level_locals(int p_level, List<String> *p_locals, List<Variant> *p_values, int p_max_subitems, int p_max_depth) {
- if (_debug_parse_err_node >= 0)
+ if (_debug_parse_err_node >= 0) {
return;
+ }
ERR_FAIL_INDEX(p_level, _debug_call_stack_pos);
@@ -2601,15 +2649,17 @@ void VisualScriptLanguage::debug_get_stack_level_locals(int p_level, List<String
}
void VisualScriptLanguage::debug_get_stack_level_members(int p_level, List<String> *p_members, List<Variant> *p_values, int p_max_subitems, int p_max_depth) {
- if (_debug_parse_err_node >= 0)
+ if (_debug_parse_err_node >= 0) {
return;
+ }
ERR_FAIL_INDEX(p_level, _debug_call_stack_pos);
int l = _debug_call_stack_pos - p_level - 1;
Ref<VisualScript> vs = _call_stack[l].instance->get_script();
- if (vs.is_null())
+ if (vs.is_null()) {
return;
+ }
List<StringName> vars;
vs->get_variable_list(&vars);
diff --git a/modules/visual_script/visual_script.h b/modules/visual_script/visual_script.h
index d47f7f2a4b..d54b1faf42 100644
--- a/modules/visual_script/visual_script.h
+++ b/modules/visual_script/visual_script.h
@@ -424,8 +424,9 @@ public:
bool set_variable(const StringName &p_variable, const Variant &p_value) {
Map<StringName, Variant>::Element *E = variables.find(p_variable);
- if (!E)
+ if (!E) {
return false;
+ }
E->get() = p_value;
return true;
@@ -433,8 +434,9 @@ public:
bool get_variable(const StringName &p_variable, Variant *r_variable) const {
const Map<StringName, Variant>::Element *E = variables.find(p_variable);
- if (!E)
+ if (!E) {
return false;
+ }
*r_variable = E->get();
return true;
@@ -527,11 +529,13 @@ public:
bool debug_break_parse(const String &p_file, int p_node, const String &p_error);
_FORCE_INLINE_ void enter_function(VisualScriptInstance *p_instance, const StringName *p_function, Variant *p_stack, Variant **p_work_mem, int *current_id) {
- if (Thread::get_main_id() != Thread::get_caller_id())
+ if (Thread::get_main_id() != Thread::get_caller_id()) {
return; //no support for other threads than main for now
+ }
- if (EngineDebugger::get_script_debugger()->get_lines_left() > 0 && EngineDebugger::get_script_debugger()->get_depth() >= 0)
+ if (EngineDebugger::get_script_debugger()->get_lines_left() > 0 && EngineDebugger::get_script_debugger()->get_depth() >= 0) {
EngineDebugger::get_script_debugger()->set_depth(EngineDebugger::get_script_debugger()->get_depth() + 1);
+ }
if (_debug_call_stack_pos >= _debug_max_call_stack) {
//stack overflow
@@ -549,11 +553,13 @@ public:
}
_FORCE_INLINE_ void exit_function() {
- if (Thread::get_main_id() != Thread::get_caller_id())
+ if (Thread::get_main_id() != Thread::get_caller_id()) {
return; //no support for other threads than main for now
+ }
- if (EngineDebugger::get_script_debugger()->get_lines_left() > 0 && EngineDebugger::get_script_debugger()->get_depth() >= 0)
+ if (EngineDebugger::get_script_debugger()->get_lines_left() > 0 && EngineDebugger::get_script_debugger()->get_depth() >= 0) {
EngineDebugger::get_script_debugger()->set_depth(EngineDebugger::get_script_debugger()->get_depth() - 1);
+ }
if (_debug_call_stack_pos == 0) {
_debug_error = "Stack Underflow (Engine Bug)";
diff --git a/modules/visual_script/visual_script_builtin_funcs.cpp b/modules/visual_script/visual_script_builtin_funcs.cpp
index 953d9a5fed..a0dcd76d10 100644
--- a/modules/visual_script/visual_script_builtin_funcs.cpp
+++ b/modules/visual_script/visual_script_builtin_funcs.cpp
@@ -111,8 +111,9 @@ const char *VisualScriptBuiltinFunc::func_name[VisualScriptBuiltinFunc::FUNC_MAX
VisualScriptBuiltinFunc::BuiltinFunc VisualScriptBuiltinFunc::find_function(const String &p_string) {
for (int i = 0; i < FUNC_MAX; i++) {
- if (p_string == func_name[i])
+ if (p_string == func_name[i]) {
return BuiltinFunc(i);
+ }
}
return FUNC_MAX;
@@ -269,95 +270,106 @@ PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const
return PropertyInfo(Variant::FLOAT, "s");
} break;
case MATH_ATAN2: {
- if (p_idx == 0)
+ if (p_idx == 0) {
return PropertyInfo(Variant::FLOAT, "y");
- else
+ } else {
return PropertyInfo(Variant::FLOAT, "x");
+ }
} break;
case MATH_FMOD:
case MATH_FPOSMOD:
case LOGIC_MAX:
case LOGIC_MIN: {
- if (p_idx == 0)
+ if (p_idx == 0) {
return PropertyInfo(Variant::FLOAT, "a");
- else
+ } else {
return PropertyInfo(Variant::FLOAT, "b");
+ }
} break;
case MATH_POSMOD: {
- if (p_idx == 0)
+ if (p_idx == 0) {
return PropertyInfo(Variant::INT, "a");
- else
+ } else {
return PropertyInfo(Variant::INT, "b");
+ }
} break;
case MATH_POW: {
- if (p_idx == 0)
+ if (p_idx == 0) {
return PropertyInfo(Variant::FLOAT, "base");
- else
+ } else {
return PropertyInfo(Variant::FLOAT, "exp");
+ }
} break;
case MATH_EASE: {
- if (p_idx == 0)
+ if (p_idx == 0) {
return PropertyInfo(Variant::FLOAT, "s");
- else
+ } else {
return PropertyInfo(Variant::FLOAT, "curve");
+ }
} break;
case MATH_STEP_DECIMALS: {
return PropertyInfo(Variant::FLOAT, "step");
} break;
case MATH_STEPIFY: {
- if (p_idx == 0)
+ if (p_idx == 0) {
return PropertyInfo(Variant::FLOAT, "s");
- else
+ } else {
return PropertyInfo(Variant::FLOAT, "steps");
+ }
} break;
case MATH_LERP:
case MATH_LERP_ANGLE:
case MATH_INVERSE_LERP:
case MATH_SMOOTHSTEP: {
- if (p_idx == 0)
+ if (p_idx == 0) {
return PropertyInfo(Variant::FLOAT, "from");
- else if (p_idx == 1)
+ } else if (p_idx == 1) {
return PropertyInfo(Variant::FLOAT, "to");
- else
+ } else {
return PropertyInfo(Variant::FLOAT, "weight");
+ }
} break;
case MATH_RANGE_LERP: {
- if (p_idx == 0)
+ if (p_idx == 0) {
return PropertyInfo(Variant::FLOAT, "value");
- else if (p_idx == 1)
+ } else if (p_idx == 1) {
return PropertyInfo(Variant::FLOAT, "istart");
- else if (p_idx == 2)
+ } else if (p_idx == 2) {
return PropertyInfo(Variant::FLOAT, "istop");
- else if (p_idx == 3)
+ } else if (p_idx == 3) {
return PropertyInfo(Variant::FLOAT, "ostart");
- else
+ } else {
return PropertyInfo(Variant::FLOAT, "ostop");
+ }
} break;
case MATH_MOVE_TOWARD: {
- if (p_idx == 0)
+ if (p_idx == 0) {
return PropertyInfo(Variant::FLOAT, "from");
- else if (p_idx == 1)
+ } else if (p_idx == 1) {
return PropertyInfo(Variant::FLOAT, "to");
- else
+ } else {
return PropertyInfo(Variant::FLOAT, "delta");
+ }
} break;
case MATH_DECTIME: {
- if (p_idx == 0)
+ if (p_idx == 0) {
return PropertyInfo(Variant::FLOAT, "value");
- else if (p_idx == 1)
+ } else if (p_idx == 1) {
return PropertyInfo(Variant::FLOAT, "amount");
- else
+ } else {
return PropertyInfo(Variant::FLOAT, "step");
+ }
} break;
case MATH_RANDOMIZE:
case MATH_RAND:
case MATH_RANDF: {
} break;
case MATH_RANDOM: {
- if (p_idx == 0)
+ if (p_idx == 0) {
return PropertyInfo(Variant::FLOAT, "from");
- else
+ } else {
return PropertyInfo(Variant::FLOAT, "to");
+ }
} break;
case MATH_SEED:
case MATH_RANDSEED: {
@@ -376,33 +388,37 @@ PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const
return PropertyInfo(Variant::FLOAT, "db");
} break;
case MATH_POLAR2CARTESIAN: {
- if (p_idx == 0)
+ if (p_idx == 0) {
return PropertyInfo(Variant::FLOAT, "r");
- else
+ } else {
return PropertyInfo(Variant::FLOAT, "th");
+ }
} break;
case MATH_CARTESIAN2POLAR: {
- if (p_idx == 0)
+ if (p_idx == 0) {
return PropertyInfo(Variant::FLOAT, "x");
- else
+ } else {
return PropertyInfo(Variant::FLOAT, "y");
+ }
} break;
case MATH_WRAP: {
- if (p_idx == 0)
+ if (p_idx == 0) {
return PropertyInfo(Variant::INT, "value");
- else if (p_idx == 1)
+ } else if (p_idx == 1) {
return PropertyInfo(Variant::INT, "min");
- else
+ } else {
return PropertyInfo(Variant::INT, "max");
+ }
} break;
case MATH_WRAPF:
case LOGIC_CLAMP: {
- if (p_idx == 0)
+ if (p_idx == 0) {
return PropertyInfo(Variant::FLOAT, "value");
- else if (p_idx == 1)
+ } else if (p_idx == 1) {
return PropertyInfo(Variant::FLOAT, "min");
- else
+ } else {
return PropertyInfo(Variant::FLOAT, "max");
+ }
} break;
case LOGIC_NEAREST_PO2: {
return PropertyInfo(Variant::INT, "value");
@@ -411,16 +427,18 @@ PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const
return PropertyInfo(Variant::OBJECT, "source");
} break;
case FUNC_FUNCREF: {
- if (p_idx == 0)
+ if (p_idx == 0) {
return PropertyInfo(Variant::OBJECT, "instance");
- else
+ } else {
return PropertyInfo(Variant::STRING, "funcname");
+ }
} break;
case TYPE_CONVERT: {
- if (p_idx == 0)
+ if (p_idx == 0) {
return PropertyInfo(Variant::NIL, "what");
- else
+ } else {
return PropertyInfo(Variant::STRING, "type");
+ }
} break;
case TYPE_OF: {
return PropertyInfo(Variant::NIL, "what");
@@ -445,23 +463,26 @@ PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const
} break;
case VAR_TO_STR:
case VAR_TO_BYTES: {
- if (p_idx == 0)
+ if (p_idx == 0) {
return PropertyInfo(Variant::NIL, "var");
- else
+ } else {
return PropertyInfo(Variant::BOOL, "full_objects");
+ }
} break;
case BYTES_TO_VAR: {
- if (p_idx == 0)
+ if (p_idx == 0) {
return PropertyInfo(Variant::PACKED_BYTE_ARRAY, "bytes");
- else
+ } else {
return PropertyInfo(Variant::BOOL, "allow_objects");
+ }
} break;
case COLORN: {
- if (p_idx == 0)
+ if (p_idx == 0) {
return PropertyInfo(Variant::STRING, "name");
- else
+ } else {
return PropertyInfo(Variant::FLOAT, "alpha");
+ }
} break;
case FUNC_MAX: {
}
@@ -540,10 +561,11 @@ PropertyInfo VisualScriptBuiltinFunc::get_output_value_port_info(int p_idx) cons
case MATH_SEED: {
} break;
case MATH_RANDSEED: {
- if (p_idx == 0)
+ if (p_idx == 0) {
return PropertyInfo(Variant::INT, "rnd");
- else
+ } else {
return PropertyInfo(Variant::INT, "seed");
+ }
} break;
case MATH_DEG2RAD:
case MATH_RAD2DEG:
@@ -603,15 +625,17 @@ PropertyInfo VisualScriptBuiltinFunc::get_output_value_port_info(int p_idx) cons
case STR_TO_VAR: {
} break;
case VAR_TO_BYTES: {
- if (p_idx == 0)
+ if (p_idx == 0) {
t = Variant::PACKED_BYTE_ARRAY;
- else
+ } else {
t = Variant::BOOL;
+ }
} break;
case BYTES_TO_VAR: {
- if (p_idx == 1)
+ if (p_idx == 1) {
t = Variant::BOOL;
+ }
} break;
case COLORN: {
t = Variant::COLOR;
@@ -1220,8 +1244,9 @@ void VisualScriptBuiltinFunc::_bind_methods() {
String cc;
for (int i = 0; i < FUNC_MAX; i++) {
- if (i > 0)
+ if (i > 0) {
cc += ",";
+ }
cc += func_name[i];
}
ADD_PROPERTY(PropertyInfo(Variant::INT, "function", PROPERTY_HINT_ENUM, cc), "set_func", "get_func");
diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp
index fb8aac9a01..fea7d151df 100644
--- a/modules/visual_script/visual_script_editor.cpp
+++ b/modules/visual_script/visual_script_editor.cpp
@@ -66,14 +66,16 @@ protected:
}
bool _set(const StringName &p_name, const Variant &p_value) {
- if (sig == StringName())
+ if (sig == StringName()) {
return false;
+ }
if (p_name == "argument_count") {
int new_argc = p_value;
int argc = script->custom_signal_get_argument_count(sig);
- if (argc == new_argc)
+ if (argc == new_argc) {
return true;
+ }
undo_redo->create_action(TTR("Change Signal Arguments"));
@@ -126,8 +128,9 @@ protected:
}
bool _get(const StringName &p_name, Variant &r_ret) const {
- if (sig == StringName())
+ if (sig == StringName()) {
return false;
+ }
if (p_name == "argument_count") {
r_ret = script->custom_signal_get_argument_count(sig);
@@ -150,8 +153,9 @@ protected:
return false;
}
void _get_property_list(List<PropertyInfo> *p_list) const {
- if (sig == StringName())
+ if (sig == StringName()) {
return;
+ }
p_list->push_back(PropertyInfo(Variant::INT, "argument_count", PROPERTY_HINT_RANGE, "0,256"));
String argt = "Variant";
@@ -200,8 +204,9 @@ protected:
}
bool _set(const StringName &p_name, const Variant &p_value) {
- if (var == StringName())
+ if (var == StringName()) {
return false;
+ }
if (String(p_name) == "value") {
undo_redo->create_action(TTR("Set Variable Default Value"));
@@ -262,8 +267,9 @@ protected:
}
bool _get(const StringName &p_name, Variant &r_ret) const {
- if (var == StringName())
+ if (var == StringName()) {
return false;
+ }
if (String(p_name) == "value") {
r_ret = script->get_variable_default_value(var);
@@ -293,8 +299,9 @@ protected:
return false;
}
void _get_property_list(List<PropertyInfo> *p_list) const {
- if (var == StringName())
+ if (var == StringName()) {
return;
+ }
String argt = "Variant";
for (int i = 1; i < Variant::VARIANT_MAX; i++) {
@@ -319,7 +326,7 @@ public:
static Color _color_from_type(Variant::Type p_type, bool dark_theme = true) {
Color color;
- if (dark_theme)
+ if (dark_theme) {
switch (p_type) {
case Variant::NIL:
color = Color(0.41, 0.93, 0.74);
@@ -425,7 +432,7 @@ static Color _color_from_type(Variant::Type p_type, bool dark_theme = true) {
default:
color.set_hsv(p_type / float(Variant::VARIANT_MAX), 0.7, 0.7);
}
- else
+ } else {
switch (p_type) {
case Variant::NIL:
color = Color(0.15, 0.89, 0.63);
@@ -531,6 +538,7 @@ static Color _color_from_type(Variant::Type p_type, bool dark_theme = true) {
default:
color.set_hsv(p_type / float(Variant::VARIANT_MAX), 0.3, 0.3);
}
+ }
return color;
}
@@ -575,8 +583,9 @@ void VisualScriptEditor::_update_graph_connections() {
}
void VisualScriptEditor::_update_graph(int p_only_id) {
- if (updating_graph)
+ if (updating_graph) {
return;
+ }
updating_graph = true;
@@ -584,8 +593,9 @@ void VisualScriptEditor::_update_graph(int p_only_id) {
if (p_only_id >= 0) {
if (graph->has_node(itos(p_only_id))) {
Node *gid = graph->get_node(itos(p_only_id));
- if (gid)
+ if (gid) {
memdelete(gid);
+ }
}
} else {
for (int i = 0; i < graph->get_child_count(); i++) {
@@ -653,8 +663,9 @@ void VisualScriptEditor::_update_graph(int p_only_id) {
StringName editor_icons = "EditorIcons";
for (List<int>::Element *E = ids.front(); E; E = E->next()) {
- if (p_only_id >= 0 && p_only_id != E->get())
+ if (p_only_id >= 0 && p_only_id != E->get()) {
continue;
+ }
Ref<VisualScriptNode> node = script->get_node(F->get(), E->get());
Vector2 pos = script->get_node_position(F->get(), E->get());
@@ -692,8 +703,9 @@ void VisualScriptEditor::_update_graph(int p_only_id) {
btn->connect("pressed", callable_mp(this, &VisualScriptEditor::_add_input_port), varray(E->get()), CONNECT_DEFERRED);
}
if (nd_list->is_output_port_editable()) {
- if (nd_list->is_input_port_editable())
+ if (nd_list->is_input_port_editable()) {
hbnc->add_spacer();
+ }
has_gnode_text = true;
Button *btn = memnew(Button);
btn->set_text(TTR("Add Output Port"));
@@ -729,8 +741,9 @@ void VisualScriptEditor::_update_graph(int p_only_id) {
if (node_styles.has(node->get_category())) {
Ref<StyleBoxFlat> sbf = node_styles[node->get_category()];
- if (gnode->is_comment())
+ if (gnode->is_comment()) {
sbf = EditorNode::get_singleton()->get_theme_base()->get_theme()->get_stylebox("comment", "GraphNode");
+ }
Color c = sbf->get_border_color();
Color ic = c;
@@ -983,8 +996,9 @@ void VisualScriptEditor::_change_port_type(int p_select, int p_id, int p_port, b
StringName func = _get_function_of_node(p_id);
Ref<VisualScriptLists> vsn = script->get_node(func, p_id);
- if (!vsn.is_valid())
+ if (!vsn.is_valid()) {
return;
+ }
undo_redo->create_action("Change Port Type");
if (is_input) {
@@ -999,23 +1013,26 @@ void VisualScriptEditor::_change_port_type(int p_select, int p_id, int p_port, b
void VisualScriptEditor::_update_node_size(int p_id) {
Node *node = graph->get_node(itos(p_id));
- if (Object::cast_to<Control>(node))
+ if (Object::cast_to<Control>(node)) {
Object::cast_to<Control>(node)->set_size(Vector2(1, 1)); //shrink if text is smaller
+ }
}
void VisualScriptEditor::_port_name_focus_out(const Node *p_name_box, int p_id, int p_port, bool is_input) {
StringName func = _get_function_of_node(p_id);
Ref<VisualScriptLists> vsn = script->get_node(func, p_id);
- if (!vsn.is_valid())
+ if (!vsn.is_valid()) {
return;
+ }
String text;
- if (Object::cast_to<LineEdit>(p_name_box))
+ if (Object::cast_to<LineEdit>(p_name_box)) {
text = Object::cast_to<LineEdit>(p_name_box)->get_text();
- else
+ } else {
return;
+ }
undo_redo->create_action("Change Port Name");
if (is_input) {
@@ -1055,8 +1072,9 @@ void VisualScriptEditor::_update_members() {
ti->set_selectable(0, true);
ti->set_metadata(0, E->get());
ti->add_button(0, Control::get_theme_icon("Edit", "EditorIcons"), 0);
- if (selected == E->get())
+ if (selected == E->get()) {
ti->select(0);
+ }
}
TreeItem *variables = members->create_item(root);
@@ -1113,8 +1131,9 @@ void VisualScriptEditor::_update_members() {
ti->set_selectable(0, true);
ti->set_editable(0, true);
ti->set_metadata(0, E->get());
- if (selected == E->get())
+ if (selected == E->get()) {
ti->select(0);
+ }
}
TreeItem *_signals = members->create_item(root);
@@ -1131,8 +1150,9 @@ void VisualScriptEditor::_update_members() {
ti->set_selectable(0, true);
ti->set_editable(0, true);
ti->set_metadata(0, E->get());
- if (selected == E->get())
+ if (selected == E->get()) {
ti->select(0);
+ }
}
String base_type = script->get_instance_base_type();
@@ -1148,8 +1168,9 @@ void VisualScriptEditor::_update_members() {
}
void VisualScriptEditor::_member_selected() {
- if (updating_members)
+ if (updating_members) {
return;
+ }
TreeItem *ti = members->get_selected();
ERR_FAIL_COND(!ti);
@@ -1170,8 +1191,9 @@ void VisualScriptEditor::_member_selected() {
}
void VisualScriptEditor::_member_edited() {
- if (updating_members)
+ if (updating_members) {
return;
+ }
TreeItem *ti = members->get_edited();
ERR_FAIL_COND(!ti);
@@ -1179,8 +1201,9 @@ void VisualScriptEditor::_member_edited() {
String name = ti->get_metadata(0);
String new_name = ti->get_text(0);
- if (name == new_name)
+ if (name == new_name) {
return;
+ }
if (!new_name.is_valid_identifier()) {
EditorNode::get_singleton()->show_warning(TTR("Name is not a valid identifier:") + " " + new_name);
@@ -1224,8 +1247,9 @@ void VisualScriptEditor::_member_edited() {
script->get_node_list(E->get(), &lst);
for (List<int>::Element *F = lst.front(); F; F = F->next()) {
Ref<VisualScriptFunctionCall> fncall = script->get_node(E->get(), F->get());
- if (!fncall.is_valid())
+ if (!fncall.is_valid()) {
continue;
+ }
if (fncall->get_function() == name) {
undo_redo->add_do_method(fncall.ptr(), "set_function", new_name);
undo_redo->add_undo_method(fncall.ptr(), "set_function", name);
@@ -1297,8 +1321,9 @@ void VisualScriptEditor::_create_function() {
for (int i = 0; i < func_input_vbox->get_child_count(); i++) {
OptionButton *opbtn = Object::cast_to<OptionButton>(func_input_vbox->get_child(i)->get_child(3));
LineEdit *lne = Object::cast_to<LineEdit>(func_input_vbox->get_child(i)->get_child(1));
- if (!opbtn || !lne)
+ if (!opbtn || !lne) {
continue;
+ }
Variant::Type arg_type = Variant::Type(opbtn->get_selected());
String arg_name = lne->get_text();
func_node->add_argument(arg_type, arg_name);
@@ -1343,8 +1368,9 @@ void VisualScriptEditor::_add_func_input() {
OptionButton *type_box = memnew(OptionButton);
type_box->set_custom_minimum_size(Size2(120 * EDSCALE, 0));
- for (int i = Variant::NIL; i < Variant::VARIANT_MAX; i++)
+ for (int i = Variant::NIL; i < Variant::VARIANT_MAX; i++) {
type_box->add_item(Variant::get_type_name(Variant::Type(i)));
+ }
type_box->select(1);
hbox->add_child(type_box);
@@ -1376,8 +1402,9 @@ void VisualScriptEditor::_deselect_input_names() {
int cn = func_input_vbox->get_child_count();
for (int i = 0; i < cn; i++) {
LineEdit *lne = Object::cast_to<LineEdit>(func_input_vbox->get_child(i)->get_child(1));
- if (lne)
+ if (lne) {
lne->deselect();
+ }
}
}
@@ -1466,8 +1493,9 @@ void VisualScriptEditor::_add_input_port(int p_id) {
StringName func = _get_function_of_node(p_id);
Ref<VisualScriptLists> vsn = script->get_node(func, p_id);
- if (!vsn.is_valid())
+ if (!vsn.is_valid()) {
return;
+ }
updating_graph = true;
@@ -1487,8 +1515,9 @@ void VisualScriptEditor::_add_output_port(int p_id) {
StringName func = _get_function_of_node(p_id);
Ref<VisualScriptLists> vsn = script->get_node(func, p_id);
- if (!vsn.is_valid())
+ if (!vsn.is_valid()) {
return;
+ }
updating_graph = true;
@@ -1508,8 +1537,9 @@ void VisualScriptEditor::_remove_input_port(int p_id, int p_port) {
StringName func = _get_function_of_node(p_id);
Ref<VisualScriptLists> vsn = script->get_node(func, p_id);
- if (!vsn.is_valid())
+ if (!vsn.is_valid()) {
return;
+ }
updating_graph = true;
@@ -1518,14 +1548,16 @@ void VisualScriptEditor::_remove_input_port(int p_id, int p_port) {
int conn_from = -1, conn_port = -1;
script->get_input_value_port_connection_source(func, p_id, p_port, &conn_from, &conn_port);
- if (conn_from != -1)
+ if (conn_from != -1) {
undo_redo->add_do_method(script.ptr(), "data_disconnect", func, conn_from, conn_port, p_id, p_port);
+ }
undo_redo->add_do_method(vsn.ptr(), "remove_input_data_port", p_port);
undo_redo->add_do_method(this, "_update_graph", p_id);
- if (conn_from != -1)
+ if (conn_from != -1) {
undo_redo->add_undo_method(script.ptr(), "data_connect", func, conn_from, conn_port, p_id, p_port);
+ }
undo_redo->add_undo_method(vsn.ptr(), "add_input_data_port", vsn->get_input_value_port_info(p_port).type, vsn->get_input_value_port_info(p_port).name, p_port);
undo_redo->add_undo_method(this, "_update_graph", p_id);
@@ -1539,8 +1571,9 @@ void VisualScriptEditor::_remove_output_port(int p_id, int p_port) {
StringName func = _get_function_of_node(p_id);
Ref<VisualScriptLists> vsn = script->get_node(func, p_id);
- if (!vsn.is_valid())
+ if (!vsn.is_valid()) {
return;
+ }
updating_graph = true;
@@ -1553,8 +1586,9 @@ void VisualScriptEditor::_remove_output_port(int p_id, int p_port) {
for (const List<VisualScript::DataConnection>::Element *E = data_connections.front(); E; E = E->next()) {
if (E->get().from_node == p_id && E->get().from_port == p_port) {
// push into the connections map
- if (!conn_map.has(E->get().to_node))
+ if (!conn_map.has(E->get().to_node)) {
conn_map.set(E->get().to_node, Set<int>());
+ }
conn_map[E->get().to_node].insert(E->get().to_port);
}
}
@@ -1582,8 +1616,9 @@ void VisualScriptEditor::_expression_text_changed(const String &p_text, int p_id
StringName func = _get_function_of_node(p_id);
Ref<VisualScriptExpression> vse = script->get_node(func, p_id);
- if (!vse.is_valid())
+ if (!vse.is_valid()) {
return;
+ }
updating_graph = true;
@@ -1595,15 +1630,17 @@ void VisualScriptEditor::_expression_text_changed(const String &p_text, int p_id
undo_redo->commit_action();
Node *node = graph->get_node(itos(p_id));
- if (Object::cast_to<Control>(node))
+ if (Object::cast_to<Control>(node)) {
Object::cast_to<Control>(node)->set_size(Vector2(1, 1)); //shrink if text is smaller
+ }
updating_graph = false;
}
Vector2 VisualScriptEditor::_get_available_pos(bool centered, Vector2 ofs) const {
- if (centered)
+ if (centered) {
ofs = graph->get_scroll_ofs() + graph->get_size() * 0.5;
+ }
if (graph->is_using_snap()) {
int snap = graph->get_snap();
@@ -1629,8 +1666,9 @@ Vector2 VisualScriptEditor::_get_available_pos(bool centered, Vector2 ofs) const
}
}
}
- if (exists)
+ if (exists) {
continue;
+ }
break;
}
@@ -1670,8 +1708,9 @@ void VisualScriptEditor::_on_nodes_delete() {
}
}
- if (to_erase.empty())
+ if (to_erase.empty()) {
return;
+ }
undo_redo->create_action(TTR("Remove VisualScript Nodes"));
@@ -1722,8 +1761,9 @@ void VisualScriptEditor::_on_nodes_duplicate() {
}
}
- if (to_duplicate.empty())
+ if (to_duplicate.empty()) {
return;
+ }
undo_redo->create_action(TTR("Duplicate VisualScript Nodes"));
int idc = script->get_available_id() + 1;
@@ -1783,10 +1823,11 @@ void VisualScriptEditor::_on_nodes_duplicate() {
}
void VisualScriptEditor::_generic_search(String p_base_type, Vector2 pos, bool node_centered) {
- if (node_centered)
+ if (node_centered) {
port_action_pos = graph->get_size() / 2.0f;
- else
+ } else {
port_action_pos = graph->get_viewport()->get_mouse_position() - graph->get_global_position();
+ }
new_connect_node_select->select_from_visual_script(p_base_type, false, false); // neither connecting nor reset text
@@ -1795,8 +1836,9 @@ void VisualScriptEditor::_generic_search(String p_base_type, Vector2 pos, bool n
pos.x = pos.x > bounds.x ? bounds.x : pos.x;
pos.y = pos.y > bounds.y ? bounds.y : pos.y;
- if (pos != Vector2())
+ if (pos != Vector2()) {
new_connect_node_select->set_position(pos);
+ }
}
void VisualScriptEditor::_input(const Ref<InputEvent> &p_event) {
@@ -1849,8 +1891,9 @@ void VisualScriptEditor::_members_gui_input(const Ref<InputEvent> &p_event) {
Ref<InputEventMouseButton> btn = p_event;
if (btn.is_valid() && btn->is_doubleclick()) {
TreeItem *ti = members->get_selected();
- if (ti && ti->get_parent() == members->get_root()->get_children()) // to check if it's a function
+ if (ti && ti->get_parent() == members->get_root()->get_children()) { // to check if it's a function
_center_on_node(ti->get_metadata(0), script->get_function_node_id(ti->get_metadata(0)));
+ }
}
}
@@ -1886,8 +1929,9 @@ void VisualScriptEditor::_rename_function(const String &name, const String &new_
script->get_node_list(E->get(), &lst);
for (List<int>::Element *F = lst.front(); F; F = F->next()) {
Ref<VisualScriptFunctionCall> fncall = script->get_node(E->get(), F->get());
- if (!fncall.is_valid())
+ if (!fncall.is_valid()) {
continue;
+ }
if (fncall->get_function() == name) {
undo_redo->add_do_method(fncall.ptr(), "set_function", new_name);
undo_redo->add_undo_method(fncall.ptr(), "set_function", name);
@@ -1905,8 +1949,9 @@ void VisualScriptEditor::_rename_function(const String &name, const String &new_
}
void VisualScriptEditor::_fn_name_box_input(const Ref<InputEvent> &p_event) {
- if (!function_name_edit->is_visible())
+ if (!function_name_edit->is_visible()) {
return;
+ }
Ref<InputEventKey> key = p_event;
if (key.is_valid() && key->is_pressed() && key->get_keycode() == KEY_ENTER) {
@@ -1919,13 +1964,15 @@ void VisualScriptEditor::_fn_name_box_input(const Ref<InputEvent> &p_event) {
Variant VisualScriptEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
if (p_from == members) {
TreeItem *it = members->get_item_at_position(p_point);
- if (!it)
+ if (!it) {
return Variant();
+ }
String type = it->get_metadata(0);
- if (type == String())
+ if (type == String()) {
return Variant();
+ }
Dictionary dd;
TreeItem *root = members->get_root();
@@ -1996,18 +2043,21 @@ bool VisualScriptEditor::can_drop_data_fw(const Point2 &p_point, const Variant &
}
static Node *_find_script_node(Node *p_edited_scene, Node *p_current_node, const Ref<Script> &script) {
- if (p_edited_scene != p_current_node && p_current_node->get_owner() != p_edited_scene)
+ if (p_edited_scene != p_current_node && p_current_node->get_owner() != p_edited_scene) {
return nullptr;
+ }
Ref<Script> scr = p_current_node->get_script();
- if (scr.is_valid() && scr == script)
+ if (scr.is_valid() && scr == script) {
return p_current_node;
+ }
for (int i = 0; i < p_current_node->get_child_count(); i++) {
Node *n = _find_script_node(p_edited_scene, p_current_node->get_child(i), script);
- if (n)
+ if (n) {
return n;
+ }
}
return nullptr;
@@ -2199,8 +2249,9 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da
for (int i = 0; i < files.size(); i++) {
Ref<Resource> res = ResourceLoader::load(files[i]);
- if (!res.is_valid())
+ if (!res.is_valid()) {
continue;
+ }
Ref<VisualScriptPreload> prnode;
prnode.instance();
@@ -2305,8 +2356,9 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da
Object *obj = d["object"];
- if (!obj)
+ if (!obj) {
return;
+ }
Node *node = Object::cast_to<Node>(obj);
Vector2 ofs = graph->get_scroll_ofs() + p_point;
@@ -2324,10 +2376,11 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da
#endif
if (!node || Input::get_singleton()->is_key_pressed(KEY_SHIFT)) {
- if (use_get)
+ if (use_get) {
undo_redo->create_action(TTR("Add Getter Property"));
- else
+ } else {
undo_redo->create_action(TTR("Add Setter Property"));
+ }
int base_id = script->get_available_id();
@@ -2365,10 +2418,11 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da
undo_redo->commit_action();
} else {
- if (use_get)
+ if (use_get) {
undo_redo->create_action(TTR("Add Getter Property"));
- else
+ } else {
undo_redo->create_action(TTR("Add Setter Property"));
+ }
int base_id = script->get_available_id();
@@ -2412,15 +2466,17 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da
void VisualScriptEditor::_selected_method(const String &p_method, const String &p_type, const bool p_connecting) {
Ref<VisualScriptFunctionCall> vsfc = script->get_node(default_func, selecting_method_id);
- if (!vsfc.is_valid())
+ if (!vsfc.is_valid()) {
return;
+ }
vsfc->set_function(p_method);
}
void VisualScriptEditor::_draw_color_over_button(Object *obj, Color p_color) {
Button *button = Object::cast_to<Button>(obj);
- if (!button)
+ if (!button) {
return;
+ }
Ref<StyleBox> normal = get_theme_stylebox("normal", "Button");
button->draw_rect(Rect2(normal->get_offset(), button->get_size() - normal->get_minimum_size()), p_color);
@@ -2433,8 +2489,9 @@ void VisualScriptEditor::_button_resource_previewed(const String &p_path, const
ObjectID id = ud[0];
Object *obj = ObjectDB::get_instance(id);
- if (!obj)
+ if (!obj) {
return;
+ }
Button *b = Object::cast_to<Button>(obj);
ERR_FAIL_COND(!b);
@@ -2491,10 +2548,11 @@ String VisualScriptEditor::get_name() {
if (is_unsaved()) {
name += "(*)";
}
- } else if (script->get_name() != "")
+ } else if (script->get_name() != "") {
name = script->get_name();
- else
+ } else {
name = script->get_class() + "(" + itos(script->get_instance_id()) + ")";
+ }
return name;
}
@@ -2547,8 +2605,9 @@ void VisualScriptEditor::_center_on_node(const StringName &p_func, int p_id) {
// clear selection
for (int i = 0; i < graph->get_child_count(); i++) {
GraphNode *gnd = Object::cast_to<GraphNode>(graph->get_child(i));
- if (gnd)
+ if (gnd) {
gnd->set_selected(false);
+ }
}
if (gn) {
@@ -2563,8 +2622,9 @@ void VisualScriptEditor::_center_on_node(const StringName &p_func, int p_id) {
void VisualScriptEditor::goto_line(int p_line, bool p_with_error) {
p_line += 1; //add one because script lines begin from 0.
- if (p_with_error)
+ if (p_with_error) {
error_line = p_line;
+ }
List<StringName> functions;
script->get_function_list(&functions);
@@ -2713,8 +2773,9 @@ void VisualScriptEditor::_change_base_type_callback() {
void VisualScriptEditor::_node_selected(Node *p_node) {
Ref<VisualScriptNode> vnode = p_node->get_meta("__vnode");
- if (vnode.is_null())
+ if (vnode.is_null()) {
return;
+ }
EditorNode::get_singleton()->push_item(vnode.ptr()); //edit node in inspector
}
@@ -2755,13 +2816,15 @@ void VisualScriptEditor::_end_node_move() {
}
void VisualScriptEditor::_move_node(const StringName &p_func, int p_id, const Vector2 &p_to) {
- if (!script->has_function(p_func))
+ if (!script->has_function(p_func)) {
return;
+ }
Node *node = graph->get_node(itos(p_id));
- if (Object::cast_to<GraphNode>(node))
+ if (Object::cast_to<GraphNode>(node)) {
Object::cast_to<GraphNode>(node)->set_offset(p_to);
+ }
script->set_node_position(p_func, p_id, p_to / EDSCALE);
}
@@ -2829,8 +2892,9 @@ bool VisualScriptEditor::node_has_sequence_connections(const StringName &p_func,
int from = E->get().from_node;
int to = E->get().to_node;
- if (to == p_id || from == p_id)
+ if (to == p_id || from == p_id) {
return true;
+ }
}
return false;
@@ -2845,8 +2909,9 @@ void VisualScriptEditor::_graph_connected(const String &p_from, int p_from_slot,
bool from_seq;
int from_port;
- if (!_get_out_slot(from_node, p_from_slot, from_port, from_seq))
+ if (!_get_out_slot(from_node, p_from_slot, from_port, from_seq)) {
return; //can't connect this, it's invalid
+ }
StringName to_func = _get_function_of_node(p_to.to_int());
@@ -2856,8 +2921,9 @@ void VisualScriptEditor::_graph_connected(const String &p_from, int p_from_slot,
bool to_seq;
int to_port;
- if (!_get_in_slot(to_node, p_to_slot, to_port, to_seq))
+ if (!_get_in_slot(to_node, p_to_slot, to_port, to_seq)) {
return; //can't connect this, it's invalid
+ }
ERR_FAIL_COND(from_seq != to_seq);
@@ -2958,19 +3024,21 @@ void VisualScriptEditor::_graph_connected(const String &p_from, int p_from_slot,
Vector2 constructor_pos;
if ((to_node_pos.x - from_node_pos.x) < 0) {
// to is behind from node
- if (to_node_pos.x > (from_node_pos.x - to_node_size.x - 240))
+ if (to_node_pos.x > (from_node_pos.x - to_node_size.x - 240)) {
new_to_node_pos.x = from_node_pos.x - to_node_size.x - 240; // approx size of constructor node + padding
- else
+ } else {
new_to_node_pos.x = to_node_pos.x;
+ }
new_to_node_pos.y = to_node_pos.y;
constructor_pos.x = from_node_pos.x - 210;
constructor_pos.y = to_node_pos.y;
} else {
// to is ahead of from node
- if (to_node_pos.x < (from_node_size.x + from_node_pos.x + 240))
+ if (to_node_pos.x < (from_node_size.x + from_node_pos.x + 240)) {
new_to_node_pos.x = from_node_size.x + from_node_pos.x + 240; // approx size of constructor node + padding
- else
+ } else {
new_to_node_pos.x = to_node_pos.x;
+ }
new_to_node_pos.y = to_node_pos.y;
constructor_pos.x = from_node_size.x + from_node_pos.x + 10;
constructor_pos.y = to_node_pos.y;
@@ -3043,8 +3111,9 @@ void VisualScriptEditor::_graph_disconnected(const String &p_from, int p_from_sl
bool from_seq;
int from_port;
- if (!_get_out_slot(from_node, p_from_slot, from_port, from_seq))
+ if (!_get_out_slot(from_node, p_from_slot, from_port, from_seq)) {
return; //can't connect this, it's invalid
+ }
Ref<VisualScriptNode> to_node = script->get_node(func, p_to.to_int());
ERR_FAIL_COND(!to_node.is_valid());
@@ -3052,8 +3121,9 @@ void VisualScriptEditor::_graph_disconnected(const String &p_from, int p_from_sl
bool to_seq;
int to_port;
- if (!_get_in_slot(to_node, p_to_slot, to_port, to_seq))
+ if (!_get_in_slot(to_node, p_to_slot, to_port, to_seq)) {
return; //can't connect this, it's invalid
+ }
ERR_FAIL_COND(from_seq != to_seq);
@@ -3098,8 +3168,9 @@ void VisualScriptEditor::_move_nodes_with_rescan(const StringName &p_func_from,
int from = E->get().from_node;
int to = E->get().to_node;
int out_p = E->get().from_output;
- if (!seqcons.has(from))
+ if (!seqcons.has(from)) {
seqcons.set(from, Map<int, int>());
+ }
seqcons[from].insert(out_p, to);
sequence_connections.insert(to);
sequence_connections.insert(from);
@@ -3122,12 +3193,14 @@ void VisualScriptEditor::_move_nodes_with_rescan(const StringName &p_func_from,
}
continue;
}
- if (!seen.has(conn))
+ if (!seen.has(conn)) {
seen.set(conn, Set<int>());
+ }
seen[conn].insert(E->key());
stack.push_back(conn);
- if (!seqconns_to_move.has(conn))
+ if (!seqconns_to_move.has(conn)) {
seqconns_to_move.set(conn, Map<int, int>());
+ }
seqconns_to_move[conn].insert(E->key(), E->get());
conn = E->get();
nodes_to_move.insert(conn);
@@ -3152,8 +3225,9 @@ void VisualScriptEditor::_move_nodes_with_rescan(const StringName &p_func_from,
int out_p = E->get().from_port;
int in_p = E->get().to_port;
- if (!connections.has(to))
+ if (!connections.has(to)) {
connections.set(to, Map<int, Pair<int, int>>());
+ }
connections[to].insert(in_p, Pair<int, int>(from, out_p));
}
@@ -3190,12 +3264,14 @@ void VisualScriptEditor::_move_nodes_with_rescan(const StringName &p_func_from,
}
}
- if (!seen.has(id))
+ if (!seen.has(id)) {
seen.set(id, Set<int>());
+ }
seen[id].insert(E->key());
stack.push_back(id);
- if (!dataconns_to_move.has(id))
+ if (!dataconns_to_move.has(id)) {
dataconns_to_move.set(id, Map<int, Pair<int, int>>());
+ }
dataconns_to_move[id].insert(E->key(), Pair<int, int>(E->get().first, E->get().second));
id = E->get().first;
nodes_to_be_added.insert(id);
@@ -3293,14 +3369,16 @@ void VisualScriptEditor::_move_nodes_with_rescan(const StringName &p_func_from,
void VisualScriptEditor::_graph_connect_to_empty(const String &p_from, int p_from_slot, const Vector2 &p_release_pos) {
Node *node = graph->get_node(p_from);
GraphNode *gn = Object::cast_to<GraphNode>(node);
- if (!gn)
+ if (!gn) {
return;
+ }
StringName func = _get_function_of_node(p_from.to_int());
Ref<VisualScriptNode> vsn = script->get_node(func, p_from.to_int());
- if (!vsn.is_valid())
+ if (!vsn.is_valid()) {
return;
+ }
port_action_pos = p_release_pos;
@@ -3319,8 +3397,9 @@ VisualScriptNode::TypeGuess VisualScriptEditor::_guess_output_type(int p_port_ac
VisualScriptNode::TypeGuess tg;
tg.type = Variant::NIL;
- if (visited_nodes.has(p_port_action_node))
+ if (visited_nodes.has(p_port_action_node)) {
return tg; //no loop
+ }
visited_nodes.insert(p_port_action_node);
@@ -3486,8 +3565,9 @@ void VisualScriptEditor::_selected_connect_node(const String &p_text, const Stri
if (p_category == "visualscript") {
Ref<VisualScriptNode> vnode_new = VisualScriptLanguage::singleton->create_node_from_name(p_text);
Ref<VisualScriptNode> vnode_old;
- if (port_node_exists)
+ if (port_node_exists) {
vnode_old = script->get_node(func, port_action_node);
+ }
int new_id = script->get_available_id();
if (Object::cast_to<VisualScriptOperator>(vnode_new.ptr()) && vnode_old.is_valid()) {
@@ -3578,8 +3658,9 @@ void VisualScriptEditor::_selected_connect_node(const String &p_text, const Stri
undo_redo->add_undo_method(this, "_update_graph", new_id);
undo_redo->commit_action();
- if (script_prop_set.is_valid())
+ if (script_prop_set.is_valid()) {
script_prop_set->set_property(p_text);
+ }
port_action_new_node = new_id;
@@ -3690,8 +3771,9 @@ void VisualScriptEditor::_selected_connect_node(const String &p_text, const Stri
}
}
_update_graph(port_action_new_node);
- if (port_node_exists)
+ if (port_node_exists) {
_update_graph_connections();
+ }
}
void VisualScriptEditor::connect_seq(Ref<VisualScriptNode> vnode_old, Ref<VisualScriptNode> vnode_new, int new_id) {
@@ -3805,8 +3887,9 @@ void VisualScriptEditor::_cancel_connect_node() {
int VisualScriptEditor::_create_new_node_from_name(const String &p_text, const Vector2 &p_point, const StringName &p_func) {
StringName func = default_func;
- if (p_func != StringName())
+ if (p_func != StringName()) {
func = p_func;
+ }
Ref<VisualScriptNode> vnode = VisualScriptLanguage::singleton->create_node_from_name(p_text);
int new_id = script->get_available_id();
@@ -3821,8 +3904,9 @@ int VisualScriptEditor::_create_new_node_from_name(const String &p_text, const V
void VisualScriptEditor::_default_value_changed() {
Ref<VisualScriptNode> vsn = script->get_node(_get_function_of_node(editing_id), editing_id);
- if (vsn.is_null())
+ if (vsn.is_null()) {
return;
+ }
undo_redo->create_action(TTR("Change Input Value"));
undo_redo->add_do_method(vsn.ptr(), "set_default_input_value", editing_input, default_value_edit->get_variant());
@@ -3835,8 +3919,9 @@ void VisualScriptEditor::_default_value_changed() {
void VisualScriptEditor::_default_value_edited(Node *p_button, int p_id, int p_input_port) {
Ref<VisualScriptNode> vsn = script->get_node(_get_function_of_node(p_id), p_id);
- if (vsn.is_null())
+ if (vsn.is_null()) {
return;
+ }
PropertyInfo pinfo = vsn->get_input_value_port_info(p_input_port);
Variant existing = vsn->get_default_input_value(p_input_port);
@@ -3867,10 +3952,11 @@ void VisualScriptEditor::_default_value_edited(Node *p_button, int p_id, int p_i
}
if (default_value_edit->edit(nullptr, pinfo.name, pinfo.type, existing, pinfo.hint, pinfo.hint_string)) {
- if (pinfo.hint == PROPERTY_HINT_MULTILINE_TEXT)
+ if (pinfo.hint == PROPERTY_HINT_MULTILINE_TEXT) {
default_value_edit->popup_centered_ratio();
- else
+ } else {
default_value_edit->popup();
+ }
}
editing_id = p_id;
@@ -3950,8 +4036,9 @@ void VisualScriptEditor::_notification(int p_what) {
}
void VisualScriptEditor::_graph_ofs_changed(const Vector2 &p_ofs) {
- if (updating_graph || !script.is_valid())
+ if (updating_graph || !script.is_valid()) {
return;
+ }
updating_graph = true;
@@ -3964,19 +4051,22 @@ void VisualScriptEditor::_graph_ofs_changed(const Vector2 &p_ofs) {
}
void VisualScriptEditor::_comment_node_resized(const Vector2 &p_new_size, int p_node) {
- if (updating_graph)
+ if (updating_graph) {
return;
+ }
StringName func = _get_function_of_node(p_node);
Ref<VisualScriptComment> vsc = script->get_node(func, p_node);
- if (vsc.is_null())
+ if (vsc.is_null()) {
return;
+ }
Node *node = graph->get_node(itos(p_node));
GraphNode *gn = Object::cast_to<GraphNode>(node);
- if (!gn)
+ if (!gn) {
return;
+ }
updating_graph = true;
@@ -4028,8 +4118,9 @@ void VisualScriptEditor::_menu_option(int p_what) {
} break;
case EDIT_COPY_NODES:
case EDIT_CUT_NODES: {
- if (!script->has_function(default_func))
+ if (!script->has_function(default_func)) {
break;
+ }
clipboard->nodes.clear();
clipboard->data_connections.clear();
@@ -4056,8 +4147,9 @@ void VisualScriptEditor::_menu_option(int p_what) {
}
}
- if (clipboard->nodes.empty())
+ if (clipboard->nodes.empty()) {
break;
+ }
for (Set<String>::Element *F = funcs.front(); F; F = F->next()) {
List<VisualScript::SequenceConnection> sequence_connections;
@@ -4086,8 +4178,9 @@ void VisualScriptEditor::_menu_option(int p_what) {
} break;
case EDIT_PASTE_NODES: {
- if (!script->has_function(default_func))
+ if (!script->has_function(default_func)) {
break;
+ }
if (clipboard->nodes.empty()) {
EditorNode::get_singleton()->show_warning(TTR("Clipboard is empty!"));
@@ -4199,9 +4292,9 @@ void VisualScriptEditor::_menu_option(int p_what) {
Set<int> end_nodes;
if (nodes.size() == 1) {
Ref<VisualScriptNode> nd = script->get_node(function, nodes.front()->key());
- if (nd.is_valid() && nd->has_input_sequence_port())
+ if (nd.is_valid() && nd->has_input_sequence_port()) {
start_node = nodes.front()->key();
- else {
+ } else {
EditorNode::get_singleton()->show_warning(TTR("Select at least one node with sequence port."));
return;
}
@@ -4230,9 +4323,9 @@ void VisualScriptEditor::_menu_option(int p_what) {
}
}
Ref<VisualScriptNode> nd = script->get_node(function, top_nd);
- if (nd.is_valid() && nd->has_input_sequence_port())
+ if (nd.is_valid() && nd->has_input_sequence_port()) {
start_node = top_nd;
- else {
+ } else {
EditorNode::get_singleton()->show_warning(TTR("Select at least one node with sequence port."));
return;
}
@@ -4837,8 +4930,9 @@ static ScriptEditorBase *create_editor(const RES &p_resource) {
VisualScriptEditor::Clipboard *VisualScriptEditor::clipboard = nullptr;
void VisualScriptEditor::free_clipboard() {
- if (clipboard)
+ if (clipboard) {
memdelete(clipboard);
+ }
}
static void register_editor_callback() {
diff --git a/modules/visual_script/visual_script_expression.cpp b/modules/visual_script/visual_script_expression.cpp
index ee166082bd..bd41117497 100644
--- a/modules/visual_script/visual_script_expression.cpp
+++ b/modules/visual_script/visual_script_expression.cpp
@@ -466,8 +466,9 @@ Error VisualScriptExpression::_get_token(Token &r_token) {
exp_beg = true;
} else if ((c == '-' || c == '+') && !exp_sign && !exp_beg) {
- if (c == '-')
+ if (c == '-') {
is_float = true;
+ }
exp_sign = true;
} else {
@@ -476,8 +477,9 @@ Error VisualScriptExpression::_get_token(Token &r_token) {
} break;
}
- if (reading == READING_DONE)
+ if (reading == READING_DONE) {
break;
+ }
num += String::chr(c);
c = GET_CHAR();
}
@@ -486,10 +488,11 @@ Error VisualScriptExpression::_get_token(Token &r_token) {
r_token.type = TK_CONSTANT;
- if (is_float)
+ if (is_float) {
r_token.value = num.to_double();
- else
+ } else {
r_token.value = num.to_int();
+ }
return OK;
} else if ((cchar >= 'A' && cchar <= 'Z') || (cchar >= 'a' && cchar <= 'z') || cchar == '_') {
@@ -618,8 +621,9 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() {
Token tk;
_get_token(tk);
- if (error_set)
+ if (error_set) {
return nullptr;
+ }
switch (tk.type) {
case TK_CURLY_BRACKET_OPEN: {
@@ -635,8 +639,9 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() {
str_ofs = cofs; //revert
//parse an expression
ENode *expr2 = _parse_expression();
- if (!expr2)
+ if (!expr2) {
return nullptr;
+ }
dn->dict.push_back(expr2);
_get_token(tk);
@@ -646,8 +651,9 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() {
}
expr2 = _parse_expression();
- if (!expr2)
+ if (!expr2) {
return nullptr;
+ }
dn->dict.push_back(expr2);
@@ -678,8 +684,9 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() {
str_ofs = cofs; //revert
//parse an expression
ENode *expr2 = _parse_expression();
- if (!expr2)
+ if (!expr2) {
return nullptr;
+ }
an->array.push_back(expr2);
cofs = str_ofs;
@@ -698,8 +705,9 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() {
case TK_PARENTHESIS_OPEN: {
//a suexpression
ENode *e = _parse_expression();
- if (error_set)
+ if (error_set) {
return nullptr;
+ }
_get_token(tk);
if (tk.type != TK_PARENTHESIS_CLOSE) {
_set_error("Expected ')'");
@@ -759,8 +767,9 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() {
str_ofs = cofs; //revert
//parse an expression
ENode *expr2 = _parse_expression();
- if (!expr2)
+ if (!expr2) {
return nullptr;
+ }
constructor->arguments.push_back(expr2);
@@ -799,8 +808,9 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() {
str_ofs = cofs; //revert
//parse an expression
ENode *expr2 = _parse_expression();
- if (!expr2)
+ if (!expr2) {
return nullptr;
+ }
bifunc->arguments.push_back(expr2);
@@ -849,8 +859,9 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() {
while (true) {
int cofs2 = str_ofs;
_get_token(tk);
- if (error_set)
+ if (error_set) {
return nullptr;
+ }
bool done = false;
@@ -862,8 +873,9 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() {
index->base = expr;
ENode *what = _parse_expression();
- if (!what)
+ if (!what) {
return nullptr;
+ }
index->index = what;
@@ -902,8 +914,9 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() {
str_ofs = cofs3; //revert
//parse an expression
ENode *expr2 = _parse_expression();
- if (!expr2)
+ if (!expr2) {
return nullptr;
+ }
func_call->arguments.push_back(expr2);
@@ -936,8 +949,9 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() {
} break;
}
- if (done)
+ if (done) {
break;
+ }
}
//push expression
@@ -952,8 +966,9 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() {
int cofs = str_ofs;
_get_token(tk);
- if (error_set)
+ if (error_set) {
return nullptr;
+ }
Variant::Operator op = Variant::OP_MAX;
@@ -1216,8 +1231,9 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() {
}
bool VisualScriptExpression::_compile_expression() {
- if (!expression_dirty)
+ if (!expression_dirty) {
return error_set;
+ }
if (nodes) {
memdelete(nodes);
@@ -1270,15 +1286,17 @@ public:
Variant a;
bool ret = _execute(p_inputs, op->nodes[0], a, r_error_str, ce);
- if (ret)
+ if (ret) {
return true;
+ }
Variant b;
if (op->nodes[1]) {
ret = _execute(p_inputs, op->nodes[1], b, r_error_str, ce);
- if (ret)
+ if (ret) {
return true;
+ }
}
bool valid = true;
@@ -1294,14 +1312,16 @@ public:
Variant base;
bool ret = _execute(p_inputs, index->base, base, r_error_str, ce);
- if (ret)
+ if (ret) {
return true;
+ }
Variant idx;
ret = _execute(p_inputs, index->index, idx, r_error_str, ce);
- if (ret)
+ if (ret) {
return true;
+ }
bool valid;
r_ret = base.get(idx, &valid);
@@ -1316,8 +1336,9 @@ public:
Variant base;
bool ret = _execute(p_inputs, index->base, base, r_error_str, ce);
- if (ret)
+ if (ret) {
return true;
+ }
bool valid;
r_ret = base.get_named(index->name, &valid);
@@ -1335,8 +1356,9 @@ public:
for (int i = 0; i < array->array.size(); i++) {
Variant value;
bool ret = _execute(p_inputs, array->array[i], value, r_error_str, ce);
- if (ret)
+ if (ret) {
return true;
+ }
arr[i] = value;
}
@@ -1350,13 +1372,15 @@ public:
for (int i = 0; i < dictionary->dict.size(); i += 2) {
Variant key;
bool ret = _execute(p_inputs, dictionary->dict[i + 0], key, r_error_str, ce);
- if (ret)
+ if (ret) {
return true;
+ }
Variant value;
ret = _execute(p_inputs, dictionary->dict[i + 1], value, r_error_str, ce);
- if (ret)
+ if (ret) {
return true;
+ }
d[key] = value;
}
@@ -1374,8 +1398,9 @@ public:
for (int i = 0; i < constructor->arguments.size(); i++) {
Variant value;
bool ret = _execute(p_inputs, constructor->arguments[i], value, r_error_str, ce);
- if (ret)
+ if (ret) {
return true;
+ }
arr.write[i] = value;
argp.write[i] = &arr[i];
}
@@ -1399,8 +1424,9 @@ public:
for (int i = 0; i < bifunc->arguments.size(); i++) {
Variant value;
bool ret = _execute(p_inputs, bifunc->arguments[i], value, r_error_str, ce);
- if (ret)
+ if (ret) {
return true;
+ }
arr.write[i] = value;
argp.write[i] = &arr[i];
}
@@ -1418,8 +1444,9 @@ public:
Variant base;
bool ret = _execute(p_inputs, call->base, base, r_error_str, ce);
- if (ret)
+ if (ret) {
return true;
+ }
Vector<Variant> arr;
Vector<const Variant *> argp;
@@ -1429,8 +1456,9 @@ public:
for (int i = 0; i < call->arguments.size(); i++) {
Variant value;
bool ret2 = _execute(p_inputs, call->arguments[i], value, r_error_str, ce);
- if (ret2)
+ if (ret2) {
return true;
+ }
arr.write[i] = value;
argp.write[i] = &arr[i];
}
diff --git a/modules/visual_script/visual_script_expression.h b/modules/visual_script/visual_script_expression.h
index ed0857ab9f..dee0213d54 100644
--- a/modules/visual_script/visual_script_expression.h
+++ b/modules/visual_script/visual_script_expression.h
@@ -104,8 +104,9 @@ class VisualScriptExpression : public VisualScriptNode {
};
void _set_error(const String &p_err) {
- if (error_set)
+ if (error_set) {
return;
+ }
error_str = p_err;
error_set = true;
}
diff --git a/modules/visual_script/visual_script_flow_control.cpp b/modules/visual_script/visual_script_flow_control.cpp
index 96616c281e..3ed20fab35 100644
--- a/modules/visual_script/visual_script_flow_control.cpp
+++ b/modules/visual_script/visual_script_flow_control.cpp
@@ -78,8 +78,9 @@ String VisualScriptReturn::get_text() const {
}
void VisualScriptReturn::set_return_type(Variant::Type p_type) {
- if (type == p_type)
+ if (type == p_type) {
return;
+ }
type = p_type;
ports_changed_notify();
}
@@ -89,8 +90,9 @@ Variant::Type VisualScriptReturn::get_return_type() const {
}
void VisualScriptReturn::set_enable_return_value(bool p_enable) {
- if (with_value == p_enable)
+ if (with_value == p_enable) {
return;
+ }
with_value = p_enable;
ports_changed_notify();
@@ -178,12 +180,13 @@ int VisualScriptCondition::get_output_value_port_count() const {
}
String VisualScriptCondition::get_output_sequence_port_text(int p_port) const {
- if (p_port == 0)
+ if (p_port == 0) {
return "true";
- else if (p_port == 1)
+ } else if (p_port == 1) {
return "false";
- else
+ } else {
return "done";
+ }
}
PropertyInfo VisualScriptCondition::get_input_value_port_info(int p_idx) const {
@@ -218,12 +221,13 @@ public:
//virtual bool get_output_port_unsequenced(int p_idx,Variant* r_value,Variant* p_working_mem,String &r_error) const { return true; }
virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) {
- if (p_start_mode == START_MODE_CONTINUE_SEQUENCE)
+ if (p_start_mode == START_MODE_CONTINUE_SEQUENCE) {
return 2;
- else if (p_inputs[0]->operator bool())
+ } else if (p_inputs[0]->operator bool()) {
return 0 | STEP_FLAG_PUSH_STACK_BIT;
- else
+ } else {
return 1 | STEP_FLAG_PUSH_STACK_BIT;
+ }
}
};
@@ -258,10 +262,11 @@ int VisualScriptWhile::get_output_value_port_count() const {
}
String VisualScriptWhile::get_output_sequence_port_text(int p_port) const {
- if (p_port == 0)
+ if (p_port == 0) {
return "repeat";
- else
+ } else {
return "exit";
+ }
}
PropertyInfo VisualScriptWhile::get_input_value_port_info(int p_idx) const {
@@ -298,10 +303,11 @@ public:
virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) {
bool keep_going = p_inputs[0]->operator bool();
- if (keep_going)
+ if (keep_going) {
return 0 | STEP_FLAG_PUSH_STACK_BIT;
- else
+ } else {
return 1;
+ }
}
};
@@ -336,10 +342,11 @@ int VisualScriptIterator::get_output_value_port_count() const {
}
String VisualScriptIterator::get_output_sequence_port_text(int p_port) const {
- if (p_port == 0)
+ if (p_port == 0) {
return "each";
- else
+ } else {
return "exit";
+ }
}
PropertyInfo VisualScriptIterator::get_input_value_port_info(int p_idx) const {
@@ -388,8 +395,9 @@ public:
return 0;
}
- if (!can_iter)
+ if (!can_iter) {
return 1; //nothing to iterate
+ }
*p_outputs[0] = p_working_mem[0].iter_get(p_working_mem[1], valid);
@@ -410,8 +418,9 @@ public:
return 0;
}
- if (!can_iter)
+ if (!can_iter) {
return 1; //nothing to iterate
+ }
*p_outputs[0] = p_working_mem[0].iter_get(p_working_mem[1], valid);
@@ -478,8 +487,9 @@ String VisualScriptSequence::get_text() const {
void VisualScriptSequence::set_steps(int p_steps) {
ERR_FAIL_COND(p_steps < 1);
- if (steps == p_steps)
+ if (steps == p_steps) {
return;
+ }
steps = p_steps;
ports_changed_notify();
@@ -515,9 +525,9 @@ public:
*p_outputs[0] = step;
- if (step + 1 == steps)
+ if (step + 1 == steps) {
return step;
- else {
+ } else {
p_working_mem[0] = step + 1;
return step | STEP_FLAG_PUSH_STACK_BIT;
}
@@ -557,8 +567,9 @@ int VisualScriptSwitch::get_output_value_port_count() const {
}
String VisualScriptSwitch::get_output_sequence_port_text(int p_port) const {
- if (p_port == case_values.size())
+ if (p_port == case_values.size()) {
return "done";
+ }
return String();
}
@@ -566,8 +577,9 @@ String VisualScriptSwitch::get_output_sequence_port_text(int p_port) const {
PropertyInfo VisualScriptSwitch::get_input_value_port_info(int p_idx) const {
if (p_idx < case_values.size()) {
return PropertyInfo(case_values[p_idx].type, " =");
- } else
+ } else {
return PropertyInfo(Variant::NIL, "input");
+ }
}
PropertyInfo VisualScriptSwitch::get_output_value_port_info(int p_idx) const {
@@ -708,15 +720,17 @@ String VisualScriptTypeCast::get_caption() const {
}
String VisualScriptTypeCast::get_text() const {
- if (script != String())
+ if (script != String()) {
return "Is " + script.get_file() + "?";
- else
+ } else {
return "Is " + base_type + "?";
+ }
}
void VisualScriptTypeCast::set_base_type(const StringName &p_type) {
- if (base_type == p_type)
+ if (base_type == p_type) {
return;
+ }
base_type = p_type;
_change_notify();
@@ -728,8 +742,9 @@ StringName VisualScriptTypeCast::get_base_type() const {
}
void VisualScriptTypeCast::set_base_script(const String &p_path) {
- if (script == p_path)
+ if (script == p_path) {
return;
+ }
script = p_path;
_change_notify();
@@ -806,8 +821,9 @@ public:
if (ClassDB::is_parent_class(obj->get_class_name(), base_type)) {
*p_outputs[0] = *p_inputs[0]; //copy
return 0;
- } else
+ } else {
return 1;
+ }
}
};
@@ -833,8 +849,9 @@ void VisualScriptTypeCast::_bind_methods() {
String script_ext_hint;
for (List<String>::Element *E = script_extensions.front(); E; E = E->next()) {
- if (script_ext_hint != String())
+ if (script_ext_hint != String()) {
script_ext_hint += ",";
+ }
script_ext_hint += "*." + E->get();
}
diff --git a/modules/visual_script/visual_script_func_nodes.cpp b/modules/visual_script/visual_script_func_nodes.cpp
index e7cb2f5473..f13377f3c8 100644
--- a/modules/visual_script/visual_script_func_nodes.cpp
+++ b/modules/visual_script/visual_script_func_nodes.cpp
@@ -42,10 +42,11 @@
//////////////////////////////////////////
int VisualScriptFunctionCall::get_output_sequence_port_count() const {
- if ((method_cache.flags & METHOD_FLAG_CONST && call_mode != CALL_MODE_INSTANCE) || (call_mode == CALL_MODE_BASIC_TYPE && Variant::is_method_const(basic_type, function)))
+ if ((method_cache.flags & METHOD_FLAG_CONST && call_mode != CALL_MODE_INSTANCE) || (call_mode == CALL_MODE_BASIC_TYPE && Variant::is_method_const(basic_type, function))) {
return 0;
- else
+ } else {
return 1;
+ }
}
bool VisualScriptFunctionCall::has_input_sequence_port() const {
@@ -54,18 +55,21 @@ bool VisualScriptFunctionCall::has_input_sequence_port() const {
#ifdef TOOLS_ENABLED
static Node *_find_script_node(Node *p_edited_scene, Node *p_current_node, const Ref<Script> &script) {
- if (p_edited_scene != p_current_node && p_current_node->get_owner() != p_edited_scene)
+ if (p_edited_scene != p_current_node && p_current_node->get_owner() != p_edited_scene) {
return nullptr;
+ }
Ref<Script> scr = p_current_node->get_script();
- if (scr.is_valid() && scr == script)
+ if (scr.is_valid() && scr == script) {
return p_current_node;
+ }
for (int i = 0; i < p_current_node->get_child_count(); i++) {
Node *n = _find_script_node(p_edited_scene, p_current_node->get_child(i), script);
- if (n)
+ if (n) {
return n;
+ }
}
return nullptr;
@@ -75,27 +79,32 @@ static Node *_find_script_node(Node *p_edited_scene, Node *p_current_node, const
Node *VisualScriptFunctionCall::_get_base_node() const {
#ifdef TOOLS_ENABLED
Ref<Script> script = get_visual_script();
- if (!script.is_valid())
+ if (!script.is_valid()) {
return nullptr;
+ }
MainLoop *main_loop = OS::get_singleton()->get_main_loop();
SceneTree *scene_tree = Object::cast_to<SceneTree>(main_loop);
- if (!scene_tree)
+ if (!scene_tree) {
return nullptr;
+ }
Node *edited_scene = scene_tree->get_edited_scene_root();
- if (!edited_scene)
+ if (!edited_scene) {
return nullptr;
+ }
Node *script_node = _find_script_node(edited_scene, edited_scene, script);
- if (!script_node)
+ if (!script_node) {
return nullptr;
+ }
- if (!script_node->has_node(base_path))
+ if (!script_node->has_node(base_path)) {
return nullptr;
+ }
Node *path_to = script_node->get_node(base_path);
@@ -107,12 +116,13 @@ Node *VisualScriptFunctionCall::_get_base_node() const {
}
StringName VisualScriptFunctionCall::_get_base_type() const {
- if (call_mode == CALL_MODE_SELF && get_visual_script().is_valid())
+ if (call_mode == CALL_MODE_SELF && get_visual_script().is_valid()) {
return get_visual_script()->get_instance_base_type();
- else if (call_mode == CALL_MODE_NODE_PATH && get_visual_script().is_valid()) {
+ } else if (call_mode == CALL_MODE_NODE_PATH && get_visual_script().is_valid()) {
Node *path = _get_base_node();
- if (path)
+ if (path) {
return path->get_class();
+ }
}
return base_type;
@@ -146,8 +156,9 @@ int VisualScriptFunctionCall::get_output_value_port_count() const {
MethodBind *mb = ClassDB::get_method(_get_base_type(), function);
if (mb) {
ret = mb->has_return() ? 1 : 0;
- } else
+ } else {
ret = 1; //it is assumed that script always returns something
+ }
if (call_mode == CALL_MODE_INSTANCE) {
ret++;
@@ -244,16 +255,18 @@ PropertyInfo VisualScriptFunctionCall::get_output_value_port_info(int p_idx) con
}
String VisualScriptFunctionCall::get_caption() const {
- if (call_mode == CALL_MODE_SELF)
+ if (call_mode == CALL_MODE_SELF) {
return " " + String(function) + "()";
- if (call_mode == CALL_MODE_SINGLETON)
+ }
+ if (call_mode == CALL_MODE_SINGLETON) {
return String(singleton) + ":" + String(function) + "()";
- else if (call_mode == CALL_MODE_BASIC_TYPE)
+ } else if (call_mode == CALL_MODE_BASIC_TYPE) {
return Variant::get_type_name(basic_type) + "." + String(function) + "()";
- else if (call_mode == CALL_MODE_NODE_PATH)
+ } else if (call_mode == CALL_MODE_NODE_PATH) {
return " [" + String(base_path.simplified()) + "]." + String(function) + "()";
- else
+ } else {
return " " + base_type + "." + String(function) + "()";
+ }
}
String VisualScriptFunctionCall::get_text() const {
@@ -264,8 +277,9 @@ String VisualScriptFunctionCall::get_text() const {
}
void VisualScriptFunctionCall::set_basic_type(Variant::Type p_type) {
- if (basic_type == p_type)
+ if (basic_type == p_type) {
return;
+ }
basic_type = p_type;
_change_notify();
@@ -277,8 +291,9 @@ Variant::Type VisualScriptFunctionCall::get_basic_type() const {
}
void VisualScriptFunctionCall::set_base_type(const StringName &p_type) {
- if (base_type == p_type)
+ if (base_type == p_type) {
return;
+ }
base_type = p_type;
_change_notify();
@@ -290,8 +305,9 @@ StringName VisualScriptFunctionCall::get_base_type() const {
}
void VisualScriptFunctionCall::set_base_script(const String &p_path) {
- if (base_script == p_path)
+ if (base_script == p_path) {
return;
+ }
base_script = p_path;
_change_notify();
@@ -303,8 +319,9 @@ String VisualScriptFunctionCall::get_base_script() const {
}
void VisualScriptFunctionCall::set_singleton(const StringName &p_type) {
- if (singleton == p_type)
+ if (singleton == p_type) {
return;
+ }
singleton = p_type;
Object *obj = Engine::get_singleton()->get_singleton_object(singleton);
@@ -395,8 +412,9 @@ void VisualScriptFunctionCall::_update_method_cache() {
}
void VisualScriptFunctionCall::set_function(const StringName &p_type) {
- if (function == p_type)
+ if (function == p_type) {
return;
+ }
function = p_type;
@@ -417,8 +435,9 @@ StringName VisualScriptFunctionCall::get_function() const {
}
void VisualScriptFunctionCall::set_base_path(const NodePath &p_type) {
- if (base_path == p_type)
+ if (base_path == p_type) {
return;
+ }
base_path = p_type;
_change_notify();
@@ -430,8 +449,9 @@ NodePath VisualScriptFunctionCall::get_base_path() const {
}
void VisualScriptFunctionCall::set_call_mode(CallMode p_mode) {
- if (call_mode == p_mode)
+ if (call_mode == p_mode) {
return;
+ }
call_mode = p_mode;
_change_notify();
@@ -443,16 +463,18 @@ VisualScriptFunctionCall::CallMode VisualScriptFunctionCall::get_call_mode() con
}
void VisualScriptFunctionCall::set_use_default_args(int p_amount) {
- if (use_default_args == p_amount)
+ if (use_default_args == p_amount) {
return;
+ }
use_default_args = p_amount;
ports_changed_notify();
}
void VisualScriptFunctionCall::set_rpc_call_mode(VisualScriptFunctionCall::RPCCallMode p_mode) {
- if (rpc_call_mode == p_mode)
+ if (rpc_call_mode == p_mode) {
return;
+ }
rpc_call_mode = p_mode;
ports_changed_notify();
_change_notify();
@@ -511,8 +533,9 @@ void VisualScriptFunctionCall::_validate_property(PropertyInfo &property) const
property.hint = PROPERTY_HINT_ENUM;
String sl;
for (List<Engine::Singleton>::Element *E = names.front(); E; E = E->next()) {
- if (sl != String())
+ if (sl != String()) {
sl += ",";
+ }
sl += E->get().name;
}
property.hint_string = sl;
@@ -641,8 +664,9 @@ void VisualScriptFunctionCall::_bind_methods() {
String bt;
for (int i = 0; i < Variant::VARIANT_MAX; i++) {
- if (i > 0)
+ if (i > 0) {
bt += ",";
+ }
bt += Variant::get_type_name(Variant::Type(i));
}
@@ -654,8 +678,9 @@ void VisualScriptFunctionCall::_bind_methods() {
String script_ext_hint;
for (List<String>::Element *E = script_extensions.front(); E; E = E->next()) {
- if (script_ext_hint != String())
+ if (script_ext_hint != String()) {
script_ext_hint += ",";
+ }
script_ext_hint += "*." + E->get();
}
@@ -703,12 +728,14 @@ public:
//virtual bool get_output_port_unsequenced(int p_idx,Variant* r_value,Variant* p_working_mem,String &r_error) const { return true; }
_FORCE_INLINE_ bool call_rpc(Object *p_base, const Variant **p_args, int p_argcount) {
- if (!p_base)
+ if (!p_base) {
return false;
+ }
Node *node = Object::cast_to<Node>(p_base);
- if (!node)
+ if (!node) {
return false;
+ }
int to_id = 0;
bool reliable = true;
@@ -881,28 +908,33 @@ bool VisualScriptPropertySet::has_input_sequence_port() const {
Node *VisualScriptPropertySet::_get_base_node() const {
#ifdef TOOLS_ENABLED
Ref<Script> script = get_visual_script();
- if (!script.is_valid())
+ if (!script.is_valid()) {
return nullptr;
+ }
MainLoop *main_loop = OS::get_singleton()->get_main_loop();
SceneTree *scene_tree = Object::cast_to<SceneTree>(main_loop);
- if (!scene_tree)
+ if (!scene_tree) {
return nullptr;
+ }
Node *edited_scene = scene_tree->get_edited_scene_root();
- if (!edited_scene)
+ if (!edited_scene) {
return nullptr;
+ }
Node *script_node = _find_script_node(edited_scene, edited_scene, script);
- if (!script_node)
+ if (!script_node) {
return nullptr;
+ }
- if (!script_node->has_node(base_path))
+ if (!script_node->has_node(base_path)) {
return nullptr;
+ }
Node *path_to = script_node->get_node(base_path);
@@ -914,12 +946,13 @@ Node *VisualScriptPropertySet::_get_base_node() const {
}
StringName VisualScriptPropertySet::_get_base_type() const {
- if (call_mode == CALL_MODE_SELF && get_visual_script().is_valid())
+ if (call_mode == CALL_MODE_SELF && get_visual_script().is_valid()) {
return get_visual_script()->get_instance_base_type();
- else if (call_mode == CALL_MODE_NODE_PATH && get_visual_script().is_valid()) {
+ } else if (call_mode == CALL_MODE_NODE_PATH && get_visual_script().is_valid()) {
Node *path = _get_base_node();
- if (path)
+ if (path) {
return path->get_class();
+ }
}
return base_type;
@@ -1028,8 +1061,9 @@ void VisualScriptPropertySet::_update_base_type() {
}
void VisualScriptPropertySet::set_basic_type(Variant::Type p_type) {
- if (basic_type == p_type)
+ if (basic_type == p_type) {
return;
+ }
basic_type = p_type;
_change_notify();
@@ -1042,8 +1076,9 @@ Variant::Type VisualScriptPropertySet::get_basic_type() const {
}
void VisualScriptPropertySet::set_base_type(const StringName &p_type) {
- if (base_type == p_type)
+ if (base_type == p_type) {
return;
+ }
base_type = p_type;
_change_notify();
@@ -1055,8 +1090,9 @@ StringName VisualScriptPropertySet::get_base_type() const {
}
void VisualScriptPropertySet::set_base_script(const String &p_path) {
- if (base_script == p_path)
+ if (base_script == p_path) {
return;
+ }
base_script = p_path;
_change_notify();
@@ -1068,11 +1104,13 @@ String VisualScriptPropertySet::get_base_script() const {
}
void VisualScriptPropertySet::_update_cache() {
- if (!Object::cast_to<SceneTree>(OS::get_singleton()->get_main_loop()))
+ if (!Object::cast_to<SceneTree>(OS::get_singleton()->get_main_loop())) {
return;
+ }
- if (!Engine::get_singleton()->is_editor_hint()) //only update cache if editor exists, it's pointless otherwise
+ if (!Engine::get_singleton()->is_editor_hint()) { //only update cache if editor exists, it's pointless otherwise
return;
+ }
if (call_mode == CALL_MODE_BASIC_TYPE) {
//not super efficient..
@@ -1145,8 +1183,9 @@ void VisualScriptPropertySet::_update_cache() {
}
void VisualScriptPropertySet::set_property(const StringName &p_type) {
- if (property == p_type)
+ if (property == p_type) {
return;
+ }
property = p_type;
index = StringName();
@@ -1160,8 +1199,9 @@ StringName VisualScriptPropertySet::get_property() const {
}
void VisualScriptPropertySet::set_base_path(const NodePath &p_type) {
- if (base_path == p_type)
+ if (base_path == p_type) {
return;
+ }
base_path = p_type;
_update_base_type();
@@ -1174,8 +1214,9 @@ NodePath VisualScriptPropertySet::get_base_path() const {
}
void VisualScriptPropertySet::set_call_mode(CallMode p_mode) {
- if (call_mode == p_mode)
+ if (call_mode == p_mode) {
return;
+ }
call_mode = p_mode;
_update_base_type();
@@ -1196,8 +1237,9 @@ Dictionary VisualScriptPropertySet::_get_type_cache() const {
}
void VisualScriptPropertySet::set_index(const StringName &p_type) {
- if (index == p_type)
+ if (index == p_type) {
return;
+ }
index = p_type;
_update_cache();
_change_notify();
@@ -1210,8 +1252,9 @@ StringName VisualScriptPropertySet::get_index() const {
void VisualScriptPropertySet::set_assign_op(AssignOp p_op) {
ERR_FAIL_INDEX(p_op, ASSIGN_OP_MAX);
- if (assign_op == p_op)
+ if (assign_op == p_op) {
return;
+ }
assign_op = p_op;
_update_cache();
@@ -1304,8 +1347,9 @@ void VisualScriptPropertySet::_validate_property(PropertyInfo &property) const {
property.hint = PROPERTY_HINT_ENUM;
property.hint_string = options;
property.type = Variant::STRING;
- if (options == "")
+ if (options == "") {
property.usage = 0; //hide if type has no usable index
+ }
}
}
@@ -1339,8 +1383,9 @@ void VisualScriptPropertySet::_bind_methods() {
String bt;
for (int i = 0; i < Variant::VARIANT_MAX; i++) {
- if (i > 0)
+ if (i > 0) {
bt += ",";
+ }
bt += Variant::get_type_name(Variant::Type(i));
}
@@ -1352,8 +1397,9 @@ void VisualScriptPropertySet::_bind_methods() {
String script_ext_hint;
for (List<String>::Element *E = script_extensions.front(); E; E = E->next()) {
- if (script_ext_hint != String())
+ if (script_ext_hint != String()) {
script_ext_hint += ",";
+ }
script_ext_hint += "*." + E->get();
}
@@ -1602,28 +1648,33 @@ void VisualScriptPropertyGet::_update_base_type() {
Node *VisualScriptPropertyGet::_get_base_node() const {
#ifdef TOOLS_ENABLED
Ref<Script> script = get_visual_script();
- if (!script.is_valid())
+ if (!script.is_valid()) {
return nullptr;
+ }
MainLoop *main_loop = OS::get_singleton()->get_main_loop();
SceneTree *scene_tree = Object::cast_to<SceneTree>(main_loop);
- if (!scene_tree)
+ if (!scene_tree) {
return nullptr;
+ }
Node *edited_scene = scene_tree->get_edited_scene_root();
- if (!edited_scene)
+ if (!edited_scene) {
return nullptr;
+ }
Node *script_node = _find_script_node(edited_scene, edited_scene, script);
- if (!script_node)
+ if (!script_node) {
return nullptr;
+ }
- if (!script_node->has_node(base_path))
+ if (!script_node->has_node(base_path)) {
return nullptr;
+ }
Node *path_to = script_node->get_node(base_path);
@@ -1635,12 +1686,13 @@ Node *VisualScriptPropertyGet::_get_base_node() const {
}
StringName VisualScriptPropertyGet::_get_base_type() const {
- if (call_mode == CALL_MODE_SELF && get_visual_script().is_valid())
+ if (call_mode == CALL_MODE_SELF && get_visual_script().is_valid()) {
return get_visual_script()->get_instance_base_type();
- else if (call_mode == CALL_MODE_NODE_PATH && get_visual_script().is_valid()) {
+ } else if (call_mode == CALL_MODE_NODE_PATH && get_visual_script().is_valid()) {
Node *path = _get_base_node();
- if (path)
+ if (path) {
return path->get_class();
+ }
}
return base_type;
@@ -1701,8 +1753,9 @@ String VisualScriptPropertyGet::get_text() const {
}
void VisualScriptPropertyGet::set_base_type(const StringName &p_type) {
- if (base_type == p_type)
+ if (base_type == p_type) {
return;
+ }
base_type = p_type;
_change_notify();
@@ -1714,8 +1767,9 @@ StringName VisualScriptPropertyGet::get_base_type() const {
}
void VisualScriptPropertyGet::set_base_script(const String &p_path) {
- if (base_script == p_path)
+ if (base_script == p_path) {
return;
+ }
base_script = p_path;
_change_notify();
@@ -1808,8 +1862,9 @@ void VisualScriptPropertyGet::_update_cache() {
}
void VisualScriptPropertyGet::set_property(const StringName &p_type) {
- if (property == p_type)
+ if (property == p_type) {
return;
+ }
property = p_type;
@@ -1823,8 +1878,9 @@ StringName VisualScriptPropertyGet::get_property() const {
}
void VisualScriptPropertyGet::set_base_path(const NodePath &p_type) {
- if (base_path == p_type)
+ if (base_path == p_type) {
return;
+ }
base_path = p_type;
_change_notify();
@@ -1837,8 +1893,9 @@ NodePath VisualScriptPropertyGet::get_base_path() const {
}
void VisualScriptPropertyGet::set_call_mode(CallMode p_mode) {
- if (call_mode == p_mode)
+ if (call_mode == p_mode) {
return;
+ }
call_mode = p_mode;
_change_notify();
@@ -1851,8 +1908,9 @@ VisualScriptPropertyGet::CallMode VisualScriptPropertyGet::get_call_mode() const
}
void VisualScriptPropertyGet::set_basic_type(Variant::Type p_type) {
- if (basic_type == p_type)
+ if (basic_type == p_type) {
return;
+ }
basic_type = p_type;
_change_notify();
@@ -1872,8 +1930,9 @@ Variant::Type VisualScriptPropertyGet::_get_type_cache() const {
}
void VisualScriptPropertyGet::set_index(const StringName &p_type) {
- if (index == p_type)
+ if (index == p_type) {
return;
+ }
index = p_type;
_update_cache();
_change_notify();
@@ -1964,8 +2023,9 @@ void VisualScriptPropertyGet::_validate_property(PropertyInfo &property) const {
property.hint = PROPERTY_HINT_ENUM;
property.hint_string = options;
property.type = Variant::STRING;
- if (options == "")
+ if (options == "") {
property.usage = 0; //hide if type has no usable index
+ }
}
}
@@ -1996,8 +2056,9 @@ void VisualScriptPropertyGet::_bind_methods() {
String bt;
for (int i = 0; i < Variant::VARIANT_MAX; i++) {
- if (i > 0)
+ if (i > 0) {
bt += ",";
+ }
bt += Variant::get_type_name(Variant::Type(i));
}
@@ -2009,8 +2070,9 @@ void VisualScriptPropertyGet::_bind_methods() {
String script_ext_hint;
for (List<String>::Element *E = script_extensions.front(); E; E = E->next()) {
- if (script_ext_hint != String())
+ if (script_ext_hint != String()) {
script_ext_hint += ",";
+ }
script_ext_hint += "." + E->get();
}
@@ -2149,8 +2211,9 @@ bool VisualScriptEmitSignal::has_input_sequence_port() const {
int VisualScriptEmitSignal::get_input_value_port_count() const {
Ref<VisualScript> vs = get_visual_script();
if (vs.is_valid()) {
- if (!vs->has_custom_signal(name))
+ if (!vs->has_custom_signal(name)) {
return 0;
+ }
return vs->custom_signal_get_argument_count(name);
}
@@ -2169,8 +2232,9 @@ String VisualScriptEmitSignal::get_output_sequence_port_text(int p_port) const {
PropertyInfo VisualScriptEmitSignal::get_input_value_port_info(int p_idx) const {
Ref<VisualScript> vs = get_visual_script();
if (vs.is_valid()) {
- if (!vs->has_custom_signal(name))
+ if (!vs->has_custom_signal(name)) {
return PropertyInfo();
+ }
return PropertyInfo(vs->custom_signal_get_argument_type(name, p_idx), vs->custom_signal_get_argument_name(name, p_idx));
}
@@ -2187,8 +2251,9 @@ String VisualScriptEmitSignal::get_caption() const {
}
void VisualScriptEmitSignal::set_signal(const StringName &p_type) {
- if (name == p_type)
+ if (name == p_type) {
return;
+ }
name = p_type;
@@ -2213,8 +2278,9 @@ void VisualScriptEmitSignal::_validate_property(PropertyInfo &property) const {
String ml;
for (List<StringName>::Element *E = sigs.front(); E; E = E->next()) {
- if (ml != String())
+ if (ml != String()) {
ml += ",";
+ }
ml += E->get();
}
diff --git a/modules/visual_script/visual_script_nodes.cpp b/modules/visual_script/visual_script_nodes.cpp
index 8d35da2685..87aa64211e 100644
--- a/modules/visual_script/visual_script_nodes.cpp
+++ b/modules/visual_script/visual_script_nodes.cpp
@@ -46,8 +46,9 @@ bool VisualScriptFunction::_set(const StringName &p_name, const Variant &p_value
if (p_name == "argument_count") {
int new_argc = p_value;
int argc = arguments.size();
- if (argc == new_argc)
+ if (argc == new_argc) {
return true;
+ }
arguments.resize(new_argc);
@@ -213,10 +214,11 @@ void VisualScriptFunction::add_argument(Variant::Type p_type, const String &p_na
arg.type = p_type;
arg.hint = p_hint;
arg.hint_string = p_hint_string;
- if (p_index >= 0)
+ if (p_index >= 0) {
arguments.insert(p_index, arg);
- else
+ } else {
arguments.push_back(arg);
+ }
ports_changed_notify();
}
@@ -339,8 +341,9 @@ int VisualScriptFunction::get_stack_size() const {
//////////////////////////////////////////
int VisualScriptLists::get_output_sequence_port_count() const {
- if (sequenced)
+ if (sequenced) {
return 1;
+ }
return 0;
}
@@ -407,8 +410,9 @@ bool VisualScriptLists::_set(const StringName &p_name, const Variant &p_value) {
if (p_name == "input_count" && is_input_port_editable()) {
int new_argc = p_value;
int argc = inputports.size();
- if (argc == new_argc)
+ if (argc == new_argc) {
return true;
+ }
inputports.resize(new_argc);
@@ -442,8 +446,9 @@ bool VisualScriptLists::_set(const StringName &p_name, const Variant &p_value) {
if (p_name == "output_count" && is_output_port_editable()) {
int new_argc = p_value;
int argc = outputports.size();
- if (argc == new_argc)
+ if (argc == new_argc) {
return true;
+ }
outputports.resize(new_argc);
@@ -559,24 +564,27 @@ void VisualScriptLists::_get_property_list(List<PropertyInfo> *p_list) const {
// input data port interaction
void VisualScriptLists::add_input_data_port(Variant::Type p_type, const String &p_name, int p_index) {
- if (!is_input_port_editable())
+ if (!is_input_port_editable()) {
return;
+ }
Port inp;
inp.name = p_name;
inp.type = p_type;
- if (p_index >= 0)
+ if (p_index >= 0) {
inputports.insert(p_index, inp);
- else
+ } else {
inputports.push_back(inp);
+ }
ports_changed_notify();
_change_notify();
}
void VisualScriptLists::set_input_data_port_type(int p_idx, Variant::Type p_type) {
- if (!is_input_port_type_editable())
+ if (!is_input_port_type_editable()) {
return;
+ }
ERR_FAIL_INDEX(p_idx, inputports.size());
@@ -586,8 +594,9 @@ void VisualScriptLists::set_input_data_port_type(int p_idx, Variant::Type p_type
}
void VisualScriptLists::set_input_data_port_name(int p_idx, const String &p_name) {
- if (!is_input_port_name_editable())
+ if (!is_input_port_name_editable()) {
return;
+ }
ERR_FAIL_INDEX(p_idx, inputports.size());
@@ -597,8 +606,9 @@ void VisualScriptLists::set_input_data_port_name(int p_idx, const String &p_name
}
void VisualScriptLists::remove_input_data_port(int p_argidx) {
- if (!is_input_port_editable())
+ if (!is_input_port_editable()) {
return;
+ }
ERR_FAIL_INDEX(p_argidx, inputports.size());
@@ -610,24 +620,27 @@ void VisualScriptLists::remove_input_data_port(int p_argidx) {
// output data port interaction
void VisualScriptLists::add_output_data_port(Variant::Type p_type, const String &p_name, int p_index) {
- if (!is_output_port_editable())
+ if (!is_output_port_editable()) {
return;
+ }
Port out;
out.name = p_name;
out.type = p_type;
- if (p_index >= 0)
+ if (p_index >= 0) {
outputports.insert(p_index, out);
- else
+ } else {
outputports.push_back(out);
+ }
ports_changed_notify();
_change_notify();
}
void VisualScriptLists::set_output_data_port_type(int p_idx, Variant::Type p_type) {
- if (!is_output_port_type_editable())
+ if (!is_output_port_type_editable()) {
return;
+ }
ERR_FAIL_INDEX(p_idx, outputports.size());
@@ -637,8 +650,9 @@ void VisualScriptLists::set_output_data_port_type(int p_idx, Variant::Type p_typ
}
void VisualScriptLists::set_output_data_port_name(int p_idx, const String &p_name) {
- if (!is_output_port_name_editable())
+ if (!is_output_port_name_editable()) {
return;
+ }
ERR_FAIL_INDEX(p_idx, outputports.size());
@@ -648,8 +662,9 @@ void VisualScriptLists::set_output_data_port_name(int p_idx, const String &p_nam
}
void VisualScriptLists::remove_output_data_port(int p_argidx) {
- if (!is_output_port_editable())
+ if (!is_output_port_editable()) {
return;
+ }
ERR_FAIL_INDEX(p_argidx, outputports.size());
@@ -661,8 +676,9 @@ void VisualScriptLists::remove_output_data_port(int p_argidx) {
// sequences
void VisualScriptLists::set_sequenced(bool p_enable) {
- if (sequenced == p_enable)
+ if (sequenced == p_enable) {
return;
+ }
sequenced = p_enable;
ports_changed_notify();
}
@@ -694,8 +710,9 @@ void VisualScriptLists::_bind_methods() {
//////////////////////////////////////////
int VisualScriptComposeArray::get_output_sequence_port_count() const {
- if (sequenced)
+ if (sequenced) {
return 1;
+ }
return 0;
}
@@ -747,8 +764,9 @@ public:
virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) {
if (input_count > 0) {
Array arr;
- for (int i = 0; i < input_count; i++)
+ for (int i = 0; i < input_count; i++) {
arr.push_back((*p_inputs[i]));
+ }
Variant va = Variant(arr);
*p_outputs[0] = va;
@@ -832,8 +850,9 @@ PropertyInfo VisualScriptOperator::get_input_value_port_info(int p_idx) const {
PropertyInfo pinfo;
pinfo.name = p_idx == 0 ? "A" : "B";
pinfo.type = port_types[op][p_idx];
- if (pinfo.type == Variant::NIL)
+ if (pinfo.type == Variant::NIL) {
pinfo.type = typed;
+ }
return pinfo;
}
@@ -874,8 +893,9 @@ PropertyInfo VisualScriptOperator::get_output_value_port_info(int p_idx) const {
PropertyInfo pinfo;
pinfo.name = "";
pinfo.type = port_types[op];
- if (pinfo.type == Variant::NIL)
+ if (pinfo.type == Variant::NIL) {
pinfo.type = typed;
+ }
return pinfo;
}
@@ -949,8 +969,9 @@ String VisualScriptOperator::get_caption() const {
}
void VisualScriptOperator::set_operator(Variant::Operator p_op) {
- if (op == p_op)
+ if (op == p_op) {
return;
+ }
op = p_op;
ports_changed_notify();
}
@@ -960,8 +981,9 @@ Variant::Operator VisualScriptOperator::get_operator() const {
}
void VisualScriptOperator::set_typed(Variant::Type p_op) {
- if (typed == p_op)
+ if (typed == p_op) {
return;
+ }
typed = p_op;
ports_changed_notify();
@@ -980,8 +1002,9 @@ void VisualScriptOperator::_bind_methods() {
String types;
for (int i = 0; i < Variant::OP_MAX; i++) {
- if (i > 0)
+ if (i > 0) {
types += ",";
+ }
types += op_names[i];
}
@@ -1014,10 +1037,11 @@ public:
if (p_outputs[0]->get_type() == Variant::STRING) {
r_error_str = *p_outputs[0];
} else {
- if (unary)
+ if (unary) {
r_error_str = String(op_names[op]) + RTR(": Invalid argument of type: ") + Variant::get_type_name(p_inputs[0]->get_type());
- else
+ } else {
r_error_str = String(op_names[op]) + RTR(": Invalid arguments: ") + "A: " + Variant::get_type_name(p_inputs[0]->get_type()) + " B: " + Variant::get_type_name(p_inputs[1]->get_type());
+ }
}
}
@@ -1092,8 +1116,9 @@ String VisualScriptSelect::get_text() const {
}
void VisualScriptSelect::set_typed(Variant::Type p_op) {
- if (typed == p_op)
+ if (typed == p_op) {
return;
+ }
typed = p_op;
ports_changed_notify();
@@ -1121,10 +1146,11 @@ public:
virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) {
bool cond = *p_inputs[0];
- if (cond)
+ if (cond) {
*p_outputs[0] = *p_inputs[1];
- else
+ } else {
*p_outputs[0] = *p_inputs[2];
+ }
return 0;
}
@@ -1184,8 +1210,9 @@ String VisualScriptVariableGet::get_caption() const {
}
void VisualScriptVariableGet::set_variable(StringName p_variable) {
- if (variable == p_variable)
+ if (variable == p_variable) {
return;
+ }
variable = p_variable;
ports_changed_notify();
}
@@ -1202,8 +1229,9 @@ void VisualScriptVariableGet::_validate_property(PropertyInfo &property) const {
String vhint;
for (List<StringName>::Element *E = vars.front(); E; E = E->next()) {
- if (vhint != String())
+ if (vhint != String()) {
vhint += ",";
+ }
vhint += E->get().operator String();
}
@@ -1292,8 +1320,9 @@ String VisualScriptVariableSet::get_caption() const {
}
void VisualScriptVariableSet::set_variable(StringName p_variable) {
- if (variable == p_variable)
+ if (variable == p_variable) {
return;
+ }
variable = p_variable;
ports_changed_notify();
}
@@ -1310,8 +1339,9 @@ void VisualScriptVariableSet::_validate_property(PropertyInfo &property) const {
String vhint;
for (List<StringName>::Element *E = vars.front(); E; E = E->next()) {
- if (vhint != String())
+ if (vhint != String()) {
vhint += ",";
+ }
vhint += E->get().operator String();
}
@@ -1397,8 +1427,9 @@ String VisualScriptConstant::get_caption() const {
}
void VisualScriptConstant::set_constant_type(Variant::Type p_type) {
- if (type == p_type)
+ if (type == p_type) {
return;
+ }
type = p_type;
Callable::CallError ce;
@@ -1412,8 +1443,9 @@ Variant::Type VisualScriptConstant::get_constant_type() const {
}
void VisualScriptConstant::set_constant_value(Variant p_value) {
- if (value == p_value)
+ if (value == p_value) {
return;
+ }
value = p_value;
ports_changed_notify();
@@ -1426,8 +1458,9 @@ Variant VisualScriptConstant::get_constant_value() const {
void VisualScriptConstant::_validate_property(PropertyInfo &property) const {
if (property.name == "value") {
property.type = type;
- if (type == Variant::NIL)
+ if (type == Variant::NIL) {
property.usage = 0; //do not save if nil
+ }
}
}
@@ -1521,8 +1554,9 @@ String VisualScriptPreload::get_caption() const {
}
void VisualScriptPreload::set_preload(const Ref<Resource> &p_preload) {
- if (preload == p_preload)
+ if (preload == p_preload) {
return;
+ }
preload = p_preload;
ports_changed_notify();
@@ -1762,8 +1796,9 @@ void VisualScriptGlobalConstant::_bind_methods() {
String cc;
for (int i = 0; i < GlobalConstants::get_global_constant_count(); i++) {
- if (i > 0)
+ if (i > 0) {
cc += ",";
+ }
cc += GlobalConstants::get_global_constant_name(i);
}
ADD_PROPERTY(PropertyInfo(Variant::INT, "constant", PROPERTY_HINT_ENUM, cc), "set_global_constant", "get_global_constant");
@@ -2137,8 +2172,9 @@ void VisualScriptMathConstant::_bind_methods() {
String cc;
for (int i = 0; i < MATH_CONSTANT_MAX; i++) {
- if (i > 0)
+ if (i > 0) {
cc += ",";
+ }
cc += const_name[i];
}
ADD_PROPERTY(PropertyInfo(Variant::INT, "constant", PROPERTY_HINT_ENUM, cc), "set_math_constant", "get_math_constant");
@@ -2243,11 +2279,13 @@ void VisualScriptEngineSingleton::_validate_property(PropertyInfo &property) con
Engine::get_singleton()->get_singletons(&singletons);
for (List<Engine::Singleton>::Element *E = singletons.front(); E; E = E->next()) {
- if (E->get().name == "VS" || E->get().name == "PS" || E->get().name == "PS2D" || E->get().name == "AS" || E->get().name == "TS" || E->get().name == "SS" || E->get().name == "SS2D")
+ if (E->get().name == "VS" || E->get().name == "PS" || E->get().name == "PS2D" || E->get().name == "AS" || E->get().name == "TS" || E->get().name == "SS" || E->get().name == "SS2D") {
continue; //skip these, too simple named
+ }
- if (cc != String())
+ if (cc != String()) {
cc += ",";
+ }
cc += E->get().name;
}
@@ -2352,18 +2390,21 @@ VisualScriptNodeInstance *VisualScriptSceneNode::instance(VisualScriptInstance *
#ifdef TOOLS_ENABLED
static Node *_find_script_node(Node *p_edited_scene, Node *p_current_node, const Ref<Script> &script) {
- if (p_edited_scene != p_current_node && p_current_node->get_owner() != p_edited_scene)
+ if (p_edited_scene != p_current_node && p_current_node->get_owner() != p_edited_scene) {
return nullptr;
+ }
Ref<Script> scr = p_current_node->get_script();
- if (scr.is_valid() && scr == script)
+ if (scr.is_valid() && scr == script) {
return p_current_node;
+ }
for (int i = 0; i < p_current_node->get_child_count(); i++) {
Node *n = _find_script_node(p_edited_scene, p_current_node->get_child(i), script);
- if (n)
+ if (n) {
return n;
+ }
}
return nullptr;
@@ -2378,24 +2419,28 @@ VisualScriptSceneNode::TypeGuess VisualScriptSceneNode::guess_output_type(TypeGu
#ifdef TOOLS_ENABLED
Ref<Script> script = get_visual_script();
- if (!script.is_valid())
+ if (!script.is_valid()) {
return tg;
+ }
MainLoop *main_loop = OS::get_singleton()->get_main_loop();
SceneTree *scene_tree = Object::cast_to<SceneTree>(main_loop);
- if (!scene_tree)
+ if (!scene_tree) {
return tg;
+ }
Node *edited_scene = scene_tree->get_edited_scene_root();
- if (!edited_scene)
+ if (!edited_scene) {
return tg;
+ }
Node *script_node = _find_script_node(edited_scene, edited_scene, script);
- if (!script_node)
+ if (!script_node) {
return tg;
+ }
Node *another = script_node->get_node(path);
@@ -2411,24 +2456,28 @@ void VisualScriptSceneNode::_validate_property(PropertyInfo &property) const {
#ifdef TOOLS_ENABLED
if (property.name == "node_path") {
Ref<Script> script = get_visual_script();
- if (!script.is_valid())
+ if (!script.is_valid()) {
return;
+ }
MainLoop *main_loop = OS::get_singleton()->get_main_loop();
SceneTree *scene_tree = Object::cast_to<SceneTree>(main_loop);
- if (!scene_tree)
+ if (!scene_tree) {
return;
+ }
Node *edited_scene = scene_tree->get_edited_scene_root();
- if (!edited_scene)
+ if (!edited_scene) {
return;
+ }
Node *script_node = _find_script_node(edited_scene, edited_scene, script);
- if (!script_node)
+ if (!script_node) {
return;
+ }
property.hint_string = script_node->get_path();
}
@@ -2638,10 +2687,11 @@ PropertyInfo VisualScriptSelf::get_input_value_port_info(int p_idx) const {
PropertyInfo VisualScriptSelf::get_output_value_port_info(int p_idx) const {
String type_name;
- if (get_visual_script().is_valid())
+ if (get_visual_script().is_valid()) {
type_name = get_visual_script()->get_instance_base_type();
- else
+ } else {
type_name = "instance";
+ }
return PropertyInfo(Variant::OBJECT, type_name);
}
@@ -2674,8 +2724,9 @@ VisualScriptSelf::TypeGuess VisualScriptSelf::guess_output_type(TypeGuess *p_inp
tg.gdclass = "Object";
Ref<Script> script = get_visual_script();
- if (!script.is_valid())
+ if (!script.is_valid()) {
return tg;
+ }
tg.gdclass = script->get_instance_base_type();
tg.script = script;
@@ -2958,10 +3009,12 @@ String VisualScriptSubCall::get_caption() const {
String VisualScriptSubCall::get_text() const {
Ref<Script> script = get_script();
if (script.is_valid()) {
- if (script->get_name() != String())
+ if (script->get_name() != String()) {
return script->get_name();
- if (script->get_path().is_resource_file())
+ }
+ if (script->get_path().is_resource_file()) {
return script->get_path().get_file();
+ }
return script->get_class();
}
return "";
@@ -3054,8 +3107,9 @@ String VisualScriptComment::get_text() const {
}
void VisualScriptComment::set_title(const String &p_title) {
- if (title == p_title)
+ if (title == p_title) {
return;
+ }
title = p_title;
ports_changed_notify();
}
@@ -3065,8 +3119,9 @@ String VisualScriptComment::get_title() const {
}
void VisualScriptComment::set_description(const String &p_description) {
- if (description == p_description)
+ if (description == p_description) {
return;
+ }
description = p_description;
ports_changed_notify();
}
@@ -3076,8 +3131,9 @@ String VisualScriptComment::get_description() const {
}
void VisualScriptComment::set_size(const Size2 &p_size) {
- if (size == p_size)
+ if (size == p_size) {
return;
+ }
size = p_size;
ports_changed_notify();
}
@@ -3168,8 +3224,9 @@ String VisualScriptConstructor::get_category() const {
}
void VisualScriptConstructor::set_constructor_type(Variant::Type p_type) {
- if (type == p_type)
+ if (type == p_type) {
return;
+ }
type = p_type;
ports_changed_notify();
@@ -3284,8 +3341,9 @@ String VisualScriptLocalVar::get_category() const {
}
void VisualScriptLocalVar::set_var_name(const StringName &p_name) {
- if (name == p_name)
+ if (name == p_name) {
return;
+ }
name = p_name;
ports_changed_notify();
@@ -3390,8 +3448,9 @@ String VisualScriptLocalVarSet::get_category() const {
}
void VisualScriptLocalVarSet::set_var_name(const StringName &p_name) {
- if (name == p_name)
+ if (name == p_name) {
return;
+ }
name = p_name;
ports_changed_notify();
@@ -3509,8 +3568,9 @@ String VisualScriptInputAction::get_category() const {
}
void VisualScriptInputAction::set_action_name(const StringName &p_name) {
- if (name == p_name)
+ if (name == p_name) {
return;
+ }
name = p_name;
ports_changed_notify();
@@ -3521,8 +3581,9 @@ StringName VisualScriptInputAction::get_action_name() const {
}
void VisualScriptInputAction::set_action_mode(Mode p_mode) {
- if (mode == p_mode)
+ if (mode == p_mode) {
return;
+ }
mode = p_mode;
ports_changed_notify();
@@ -3579,8 +3640,9 @@ void VisualScriptInputAction::_validate_property(PropertyInfo &property) const {
for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
const PropertyInfo &pi = E->get();
- if (!pi.name.begins_with("input/"))
+ if (!pi.name.begins_with("input/")) {
continue;
+ }
String name = pi.name.substr(pi.name.find("/") + 1, pi.name.length());
@@ -3590,8 +3652,9 @@ void VisualScriptInputAction::_validate_property(PropertyInfo &property) const {
al.sort();
for (int i = 0; i < al.size(); i++) {
- if (actions != String())
+ if (actions != String()) {
actions += ",";
+ }
actions += al[i];
}
@@ -3678,8 +3741,9 @@ void VisualScriptDeconstruct::_update_elements() {
}
void VisualScriptDeconstruct::set_deconstruct_type(Variant::Type p_type) {
- if (type == p_type)
+ if (type == p_type) {
return;
+ }
type = p_type;
_update_elements();
diff --git a/modules/visual_script/visual_script_property_selector.cpp b/modules/visual_script/visual_script_property_selector.cpp
index 3cdf3f5d75..f14c9ce49d 100644
--- a/modules/visual_script/visual_script_property_selector.cpp
+++ b/modules/visual_script/visual_script_property_selector.cpp
@@ -58,8 +58,9 @@ void VisualScriptPropertySelector::_sbox_input(const Ref<InputEvent> &p_ie) {
search_box->accept_event();
TreeItem *root = search_options->get_root();
- if (!root->get_children())
+ if (!root->get_children()) {
break;
+ }
TreeItem *current = search_options->get_selected();
@@ -150,11 +151,13 @@ void VisualScriptPropertySelector::_update_search() {
}
}
for (List<PropertyInfo>::Element *F = props.front(); F; F = F->next()) {
- if (!(F->get().usage & PROPERTY_USAGE_EDITOR) && !(F->get().usage & PROPERTY_USAGE_SCRIPT_VARIABLE))
+ if (!(F->get().usage & PROPERTY_USAGE_EDITOR) && !(F->get().usage & PROPERTY_USAGE_SCRIPT_VARIABLE)) {
continue;
+ }
- if (type_filter.size() && type_filter.find(F->get().type) == -1)
+ if (type_filter.size() && type_filter.find(F->get().type) == -1) {
continue;
+ }
// capitalize() also converts underscore to space, we'll match again both possible styles
String get_text_raw = String(vformat(TTR("Get %s"), F->get().name));
@@ -206,14 +209,17 @@ void VisualScriptPropertySelector::_update_search() {
}
for (List<MethodInfo>::Element *M = methods.front(); M; M = M->next()) {
String name = M->get().name.get_slice(":", 0);
- if (name.begins_with("_") && !(M->get().flags & METHOD_FLAG_VIRTUAL))
+ if (name.begins_with("_") && !(M->get().flags & METHOD_FLAG_VIRTUAL)) {
continue;
+ }
- if (virtuals_only && !(M->get().flags & METHOD_FLAG_VIRTUAL))
+ if (virtuals_only && !(M->get().flags & METHOD_FLAG_VIRTUAL)) {
continue;
+ }
- if (!virtuals_only && (M->get().flags & METHOD_FLAG_VIRTUAL))
+ if (!virtuals_only && (M->get().flags & METHOD_FLAG_VIRTUAL)) {
continue;
+ }
MethodInfo mi = M->get();
String desc_arguments;
@@ -353,8 +359,9 @@ void VisualScriptPropertySelector::get_visual_node_names(const String &root_filt
bool in_modifier = p_modifiers.empty();
for (Set<String>::Element *F = p_modifiers.front(); F && in_modifier; F = F->next()) {
- if (E->get().findn(F->get()) != -1)
+ if (E->get().findn(F->get()) != -1) {
in_modifier = true;
+ }
}
if (!in_modifier) {
continue;
@@ -406,8 +413,9 @@ void VisualScriptPropertySelector::get_visual_node_names(const String &root_filt
void VisualScriptPropertySelector::_confirmed() {
TreeItem *ti = search_options->get_selected();
- if (!ti)
+ if (!ti) {
return;
+ }
emit_signal("selected", ti->get_metadata(0), ti->get_metadata(1), ti->get_metadata(2));
set_visible(false);
}
@@ -416,8 +424,9 @@ void VisualScriptPropertySelector::_item_selected() {
help_bit->set_text("");
TreeItem *item = search_options->get_selected();
- if (!item)
+ if (!item) {
return;
+ }
String name = item->get_metadata(0);
String class_type;
@@ -502,8 +511,9 @@ void VisualScriptPropertySelector::_item_selected() {
memdelete(names);
- if (text == String())
+ if (text == String()) {
return;
+ }
help_bit->set_text(text);
}
@@ -527,10 +537,11 @@ void VisualScriptPropertySelector::select_method_from_base_type(const String &p_
virtuals_only = p_virtuals_only;
show_window(.5f);
- if (clear_text)
+ if (clear_text) {
search_box->set_text("");
- else
+ } else {
search_box->select_all();
+ }
search_box->grab_focus();
connecting = p_connecting;
@@ -551,10 +562,11 @@ void VisualScriptPropertySelector::select_from_base_type(const String &p_base, c
virtuals_only = p_virtuals_only;
show_window(.5f);
- if (clear_text)
+ if (clear_text) {
search_box->set_text("");
- else
+ } else {
search_box->select_all();
+ }
search_box->grab_focus();
seq_connect = p_seq_connect;
connecting = p_connecting;
@@ -575,10 +587,11 @@ void VisualScriptPropertySelector::select_from_script(const Ref<Script> &p_scrip
virtuals_only = false;
show_window(.5f);
- if (clear_text)
+ if (clear_text) {
search_box->set_text("");
- else
+ } else {
search_box->select_all();
+ }
search_box->grab_focus();
seq_connect = false;
connecting = p_connecting;
@@ -597,10 +610,11 @@ void VisualScriptPropertySelector::select_from_basic_type(Variant::Type p_type,
virtuals_only = false;
show_window(.5f);
- if (clear_text)
+ if (clear_text) {
search_box->set_text("");
- else
+ } else {
search_box->select_all();
+ }
search_box->grab_focus();
seq_connect = false;
connecting = p_connecting;
@@ -618,10 +632,11 @@ void VisualScriptPropertySelector::select_from_action(const String &p_type, cons
virtuals_only = false;
show_window(.5f);
- if (clear_text)
+ if (clear_text) {
search_box->set_text("");
- else
+ } else {
search_box->select_all();
+ }
search_box->grab_focus();
seq_connect = true;
connecting = p_connecting;
@@ -639,10 +654,11 @@ void VisualScriptPropertySelector::select_from_instance(Object *p_instance, cons
virtuals_only = false;
show_window(.5f);
- if (clear_text)
+ if (clear_text) {
search_box->set_text("");
- else
+ } else {
search_box->select_all();
+ }
search_box->grab_focus();
seq_connect = false;
connecting = p_connecting;
@@ -659,10 +675,11 @@ void VisualScriptPropertySelector::select_from_visual_script(const String &p_bas
instance = nullptr;
virtuals_only = false;
show_window(.5f);
- if (clear_text)
+ if (clear_text) {
search_box->set_text("");
- else
+ } else {
search_box->select_all();
+ }
search_box->grab_focus();
connecting = p_connecting;
diff --git a/modules/visual_script/visual_script_yield_nodes.cpp b/modules/visual_script/visual_script_yield_nodes.cpp
index a035efd25d..dd07cc45a7 100644
--- a/modules/visual_script/visual_script_yield_nodes.cpp
+++ b/modules/visual_script/visual_script_yield_nodes.cpp
@@ -147,8 +147,9 @@ VisualScriptNodeInstance *VisualScriptYield::instance(VisualScriptInstance *p_in
}
void VisualScriptYield::set_yield_mode(YieldMode p_mode) {
- if (yield_mode == p_mode)
+ if (yield_mode == p_mode) {
return;
+ }
yield_mode = p_mode;
ports_changed_notify();
_change_notify();
@@ -159,8 +160,9 @@ VisualScriptYield::YieldMode VisualScriptYield::get_yield_mode() {
}
void VisualScriptYield::set_wait_time(float p_time) {
- if (wait_time == p_time)
+ if (wait_time == p_time) {
return;
+ }
wait_time = p_time;
ports_changed_notify();
}
@@ -219,18 +221,21 @@ bool VisualScriptYieldSignal::has_input_sequence_port() const {
#ifdef TOOLS_ENABLED
static Node *_find_script_node(Node *p_edited_scene, Node *p_current_node, const Ref<Script> &script) {
- if (p_edited_scene != p_current_node && p_current_node->get_owner() != p_edited_scene)
+ if (p_edited_scene != p_current_node && p_current_node->get_owner() != p_edited_scene) {
return nullptr;
+ }
Ref<Script> scr = p_current_node->get_script();
- if (scr.is_valid() && scr == script)
+ if (scr.is_valid() && scr == script) {
return p_current_node;
+ }
for (int i = 0; i < p_current_node->get_child_count(); i++) {
Node *n = _find_script_node(p_edited_scene, p_current_node->get_child(i), script);
- if (n)
+ if (n) {
return n;
+ }
}
return nullptr;
@@ -240,27 +245,32 @@ static Node *_find_script_node(Node *p_edited_scene, Node *p_current_node, const
Node *VisualScriptYieldSignal::_get_base_node() const {
#ifdef TOOLS_ENABLED
Ref<Script> script = get_visual_script();
- if (!script.is_valid())
+ if (!script.is_valid()) {
return nullptr;
+ }
MainLoop *main_loop = OS::get_singleton()->get_main_loop();
SceneTree *scene_tree = Object::cast_to<SceneTree>(main_loop);
- if (!scene_tree)
+ if (!scene_tree) {
return nullptr;
+ }
Node *edited_scene = scene_tree->get_edited_scene_root();
- if (!edited_scene)
+ if (!edited_scene) {
return nullptr;
+ }
Node *script_node = _find_script_node(edited_scene, edited_scene, script);
- if (!script_node)
+ if (!script_node) {
return nullptr;
+ }
- if (!script_node->has_node(base_path))
+ if (!script_node->has_node(base_path)) {
return nullptr;
+ }
Node *path_to = script_node->get_node(base_path);
@@ -272,29 +282,32 @@ Node *VisualScriptYieldSignal::_get_base_node() const {
}
StringName VisualScriptYieldSignal::_get_base_type() const {
- if (call_mode == CALL_MODE_SELF && get_visual_script().is_valid())
+ if (call_mode == CALL_MODE_SELF && get_visual_script().is_valid()) {
return get_visual_script()->get_instance_base_type();
- else if (call_mode == CALL_MODE_NODE_PATH && get_visual_script().is_valid()) {
+ } else if (call_mode == CALL_MODE_NODE_PATH && get_visual_script().is_valid()) {
Node *path = _get_base_node();
- if (path)
+ if (path) {
return path->get_class();
+ }
}
return base_type;
}
int VisualScriptYieldSignal::get_input_value_port_count() const {
- if (call_mode == CALL_MODE_INSTANCE)
+ if (call_mode == CALL_MODE_INSTANCE) {
return 1;
- else
+ } else {
return 0;
+ }
}
int VisualScriptYieldSignal::get_output_value_port_count() const {
MethodInfo sr;
- if (!ClassDB::get_signal(_get_base_type(), signal, &sr))
+ if (!ClassDB::get_signal(_get_base_type(), signal, &sr)) {
return 0;
+ }
return sr.arguments.size();
}
@@ -304,17 +317,19 @@ String VisualScriptYieldSignal::get_output_sequence_port_text(int p_port) const
}
PropertyInfo VisualScriptYieldSignal::get_input_value_port_info(int p_idx) const {
- if (call_mode == CALL_MODE_INSTANCE)
+ if (call_mode == CALL_MODE_INSTANCE) {
return PropertyInfo(Variant::OBJECT, "instance");
- else
+ } else {
return PropertyInfo();
+ }
}
PropertyInfo VisualScriptYieldSignal::get_output_value_port_info(int p_idx) const {
MethodInfo sr;
- if (!ClassDB::get_signal(_get_base_type(), signal, &sr))
+ if (!ClassDB::get_signal(_get_base_type(), signal, &sr)) {
return PropertyInfo(); //no signal
+ }
ERR_FAIL_INDEX_V(p_idx, sr.arguments.size(), PropertyInfo());
return sr.arguments[p_idx];
}
@@ -330,15 +345,17 @@ String VisualScriptYieldSignal::get_caption() const {
}
String VisualScriptYieldSignal::get_text() const {
- if (call_mode == CALL_MODE_SELF)
+ if (call_mode == CALL_MODE_SELF) {
return " " + String(signal) + "()";
- else
+ } else {
return " " + _get_base_type() + "." + String(signal) + "()";
+ }
}
void VisualScriptYieldSignal::set_base_type(const StringName &p_type) {
- if (base_type == p_type)
+ if (base_type == p_type) {
return;
+ }
base_type = p_type;
@@ -351,8 +368,9 @@ StringName VisualScriptYieldSignal::get_base_type() const {
}
void VisualScriptYieldSignal::set_signal(const StringName &p_type) {
- if (signal == p_type)
+ if (signal == p_type) {
return;
+ }
signal = p_type;
@@ -365,8 +383,9 @@ StringName VisualScriptYieldSignal::get_signal() const {
}
void VisualScriptYieldSignal::set_base_path(const NodePath &p_type) {
- if (base_path == p_type)
+ if (base_path == p_type) {
return;
+ }
base_path = p_type;
@@ -379,8 +398,9 @@ NodePath VisualScriptYieldSignal::get_base_path() const {
}
void VisualScriptYieldSignal::set_call_mode(CallMode p_mode) {
- if (call_mode == p_mode)
+ if (call_mode == p_mode) {
return;
+ }
call_mode = p_mode;
@@ -419,8 +439,9 @@ void VisualScriptYieldSignal::_validate_property(PropertyInfo &property) const {
List<String> mstring;
for (List<MethodInfo>::Element *E = methods.front(); E; E = E->next()) {
- if (E->get().name.begins_with("_"))
+ if (E->get().name.begins_with("_")) {
continue;
+ }
mstring.push_back(E->get().name.get_slice(":", 0));
}
@@ -428,8 +449,9 @@ void VisualScriptYieldSignal::_validate_property(PropertyInfo &property) const {
String ml;
for (List<String>::Element *E = mstring.front(); E; E = E->next()) {
- if (ml != String())
+ if (ml != String()) {
ml += ",";
+ }
ml += E->get();
}
@@ -452,8 +474,9 @@ void VisualScriptYieldSignal::_bind_methods() {
String bt;
for (int i = 0; i < Variant::VARIANT_MAX; i++) {
- if (i > 0)
+ if (i > 0) {
bt += ",";
+ }
bt += Variant::get_type_name(Variant::Type(i));
}
diff --git a/modules/webm/video_stream_webm.cpp b/modules/webm/video_stream_webm.cpp
index 47c54b61e9..832e14d91a 100644
--- a/modules/webm/video_stream_webm.cpp
+++ b/modules/webm/video_stream_webm.cpp
@@ -55,16 +55,19 @@ public:
ERR_FAIL_COND_MSG(!file, "Failed loading resource: '" + p_file + "'.");
}
~MkvReader() {
- if (file)
+ if (file) {
memdelete(file);
+ }
}
virtual int Read(long long pos, long len, unsigned char *buf) {
if (file) {
- if (file->get_position() != (size_t)pos)
+ if (file->get_position() != (size_t)pos) {
file->seek(pos);
- if (file->get_buffer(buf, len) == len)
+ }
+ if (file->get_buffer(buf, len) == len) {
return 0;
+ }
}
return -1;
}
@@ -72,10 +75,12 @@ public:
virtual int Length(long long *total, long long *available) {
if (file) {
const size_t len = file->get_len();
- if (total)
+ if (total) {
*total = len;
- if (available)
+ }
+ if (available) {
*available = len;
+ }
return 0;
}
return -1;
@@ -178,8 +183,9 @@ bool VideoStreamPlaybackWebm::has_loop() const {
}
float VideoStreamPlaybackWebm::get_length() const {
- if (webm)
+ if (webm) {
return webm->getLength();
+ }
return 0.0f;
}
@@ -200,8 +206,9 @@ Ref<Texture2D> VideoStreamPlaybackWebm::get_texture() const {
}
void VideoStreamPlaybackWebm::update(float p_delta) {
- if ((!playing || paused) || !video)
+ if ((!playing || paused) || !video) {
return;
+ }
time += p_delta;
@@ -244,11 +251,13 @@ void VideoStreamPlaybackWebm::update(float p_delta) {
}
video_frame = video_frames[video_frames_pos];
- if (!webm->readFrame(video_frame, audio_frame)) //This will invalidate frames
+ if (!webm->readFrame(video_frame, audio_frame)) { //This will invalidate frames
break; //Can't demux, EOS?
+ }
- if (video_frame->isValid())
+ if (video_frame->isValid()) {
++video_frames_pos;
+ }
};
bool video_frame_done = false;
@@ -315,8 +324,9 @@ void VideoStreamPlaybackWebm::update(float p_delta) {
video_frames[video_frames_pos] = video_frame;
}
- if (video_frames_pos == 0 && webm->isEOS())
+ if (video_frames_pos == 0 && webm->isEOS()) {
stop();
+ }
}
void VideoStreamPlaybackWebm::set_mix_callback(VideoStreamPlayback::AudioMixCallback p_callback, void *p_userdata) {
@@ -325,14 +335,16 @@ void VideoStreamPlaybackWebm::set_mix_callback(VideoStreamPlayback::AudioMixCall
}
int VideoStreamPlaybackWebm::get_channels() const {
- if (audio)
+ if (audio) {
return webm->getChannels();
+ }
return 0;
}
int VideoStreamPlaybackWebm::get_mix_rate() const {
- if (audio)
+ if (audio) {
return webm->getSampleRate();
+ }
return 0;
}
@@ -357,24 +369,30 @@ bool VideoStreamPlaybackWebm::should_process(WebMFrame &video_frame) {
}
void VideoStreamPlaybackWebm::delete_pointers() {
- if (pcm)
+ if (pcm) {
memfree(pcm);
+ }
- if (audio_frame)
+ if (audio_frame) {
memdelete(audio_frame);
+ }
if (video_frames) {
- for (int i = 0; i < video_frames_capacity; ++i)
+ for (int i = 0; i < video_frames_capacity; ++i) {
memdelete(video_frames[i]);
+ }
memfree(video_frames);
}
- if (video)
+ if (video) {
memdelete(video);
- if (audio)
+ }
+ if (audio) {
memdelete(audio);
+ }
- if (webm)
+ if (webm) {
memdelete(webm);
+ }
}
/**/
@@ -384,8 +402,9 @@ VideoStreamWebm::VideoStreamWebm() {}
Ref<VideoStreamPlayback> VideoStreamWebm::instance_playback() {
Ref<VideoStreamPlaybackWebm> pb = memnew(VideoStreamPlaybackWebm);
pb->set_audio_track(audio_track);
- if (pb->open_file(file))
+ if (pb->open_file(file)) {
return pb;
+ }
return nullptr;
}
@@ -443,7 +462,8 @@ bool ResourceFormatLoaderWebm::handles_type(const String &p_type) const {
String ResourceFormatLoaderWebm::get_resource_type(const String &p_path) const {
String el = p_path.get_extension().to_lower();
- if (el == "webm")
+ if (el == "webm") {
return "VideoStreamWebm";
+ }
return "";
}
diff --git a/modules/webp/image_loader_webp.cpp b/modules/webp/image_loader_webp.cpp
index 744b7ef8b9..d5c80e7909 100644
--- a/modules/webp/image_loader_webp.cpp
+++ b/modules/webp/image_loader_webp.cpp
@@ -42,10 +42,11 @@ static Vector<uint8_t> _webp_lossy_pack(const Ref<Image> &p_image, float p_quali
ERR_FAIL_COND_V(p_image.is_null() || p_image->empty(), Vector<uint8_t>());
Ref<Image> img = p_image->duplicate();
- if (img->detect_alpha())
+ if (img->detect_alpha()) {
img->convert(Image::FORMAT_RGBA8);
- else
+ } else {
img->convert(Image::FORMAT_RGB8);
+ }
Size2 s(img->get_width(), img->get_height());
Vector<uint8_t> data = img->get_data();
diff --git a/modules/webrtc/webrtc_multiplayer.cpp b/modules/webrtc/webrtc_multiplayer.cpp
index 72115628ed..e0c0cad68c 100644
--- a/modules/webrtc/webrtc_multiplayer.cpp
+++ b/modules/webrtc/webrtc_multiplayer.cpp
@@ -65,8 +65,9 @@ bool WebRTCMultiplayer::is_server() const {
}
void WebRTCMultiplayer::poll() {
- if (peer_map.size() == 0)
+ if (peer_map.size() == 0) {
return;
+ }
List<int> remove;
List<int> add;
@@ -113,15 +114,17 @@ void WebRTCMultiplayer::poll() {
// Remove disconnected peers
for (List<int>::Element *E = remove.front(); E; E = E->next()) {
remove_peer(E->get());
- if (next_packet_peer == E->get())
+ if (next_packet_peer == E->get()) {
next_packet_peer = 0;
+ }
}
// Signal newly connected peers
for (List<int>::Element *E = add.front(); E; E = E->next()) {
// Already connected to server: simply notify new peer.
// NOTE: Mesh is always connected.
- if (connection_status == CONNECTION_CONNECTED)
+ if (connection_status == CONNECTION_CONNECTED) {
emit_signal("peer_connected", E->get());
+ }
// Server emulation mode suppresses peer_conencted until server connects.
if (server_compat && E->get() == TARGET_PEER_SERVER) {
@@ -131,21 +134,24 @@ void WebRTCMultiplayer::poll() {
emit_signal("connection_succeeded");
// Notify of all previously connected peers
for (Map<int, Ref<ConnectedPeer>>::Element *F = peer_map.front(); F; F = F->next()) {
- if (F->key() != 1 && F->get()->connected)
+ if (F->key() != 1 && F->get()->connected) {
emit_signal("peer_connected", F->key());
+ }
}
break; // Because we already notified of all newly added peers.
}
}
// Fetch next packet
- if (next_packet_peer == 0)
+ if (next_packet_peer == 0) {
_find_next_peer();
+ }
}
void WebRTCMultiplayer::_find_next_peer() {
Map<int, Ref<ConnectedPeer>>::Element *E = peer_map.find(next_packet_peer);
- if (E)
+ if (E) {
E = E->next();
+ }
// After last.
while (E) {
for (List<Ref<WebRTCDataChannel>>::Element *F = E->get()->channels.front(); F; F = F->next()) {
@@ -165,8 +171,9 @@ void WebRTCMultiplayer::_find_next_peer() {
return;
}
}
- if (E->key() == (int)next_packet_peer)
+ if (E->key() == (int)next_packet_peer) {
break;
+ }
E = E->next();
}
// No packet found
@@ -191,10 +198,11 @@ Error WebRTCMultiplayer::initialize(int p_self_id, bool p_server_compat) {
server_compat = p_server_compat;
// Mesh and server are always connected
- if (!server_compat || p_self_id == 1)
+ if (!server_compat || p_self_id == 1) {
connection_status = CONNECTION_CONNECTED;
- else
+ } else {
connection_status = CONNECTION_CONNECTING;
+ }
return OK;
}
@@ -332,8 +340,9 @@ Error WebRTCMultiplayer::put_packet(const uint8_t *p_buffer, int p_buffer_size)
for (Map<int, Ref<ConnectedPeer>>::Element *F = peer_map.front(); F; F = F->next()) {
// Exclude packet. If target_peer == 0 then don't exclude any packets
- if (target_peer != 0 && F->key() == exclude)
+ if (target_peer != 0 && F->key() == exclude) {
continue;
+ }
ERR_CONTINUE(F->value()->channels.size() <= ch || !F->value()->channels[ch].is_valid());
F->value()->channels[ch]->put_packet(p_buffer, p_buffer_size);
@@ -343,8 +352,9 @@ Error WebRTCMultiplayer::put_packet(const uint8_t *p_buffer, int p_buffer_size)
}
int WebRTCMultiplayer::get_available_packet_count() const {
- if (next_packet_peer == 0)
+ if (next_packet_peer == 0) {
return 0; // To be sure next call to get_packet works if size > 0 .
+ }
int size = 0;
for (Map<int, Ref<ConnectedPeer>>::Element *E = peer_map.front(); E; E = E->next()) {
for (List<Ref<WebRTCDataChannel>>::Element *F = E->get()->channels.front(); F; F = F->next()) {
diff --git a/modules/webrtc/webrtc_multiplayer.h b/modules/webrtc/webrtc_multiplayer.h
index 876e2c6fe9..906b90a1b6 100644
--- a/modules/webrtc/webrtc_multiplayer.h
+++ b/modules/webrtc/webrtc_multiplayer.h
@@ -56,8 +56,9 @@ private:
ConnectedPeer() {
connected = false;
- for (int i = 0; i < CH_RESERVED_MAX; i++)
+ for (int i = 0; i < CH_RESERVED_MAX; i++) {
channels.push_front(Ref<WebRTCDataChannel>());
+ }
}
};
diff --git a/modules/webrtc/webrtc_peer_connection.cpp b/modules/webrtc/webrtc_peer_connection.cpp
index f71dcc956c..670924bca2 100644
--- a/modules/webrtc/webrtc_peer_connection.cpp
+++ b/modules/webrtc/webrtc_peer_connection.cpp
@@ -37,8 +37,9 @@ Ref<WebRTCPeerConnection> WebRTCPeerConnection::create_ref() {
}
WebRTCPeerConnection *WebRTCPeerConnection::create() {
- if (!_create)
+ if (!_create) {
return nullptr;
+ }
return _create();
}
diff --git a/modules/websocket/editor_debugger_server_websocket.cpp b/modules/websocket/editor_debugger_server_websocket.cpp
index 66f3dac907..95ea7ceafa 100644
--- a/modules/websocket/editor_debugger_server_websocket.cpp
+++ b/modules/websocket/editor_debugger_server_websocket.cpp
@@ -39,8 +39,9 @@ void EditorDebuggerServerWebSocket::_peer_connected(int p_id, String _protocol)
}
void EditorDebuggerServerWebSocket::_peer_disconnected(int p_id, bool p_was_clean) {
- if (pending_peers.find(p_id))
+ if (pending_peers.find(p_id)) {
pending_peers.erase(p_id);
+ }
}
void EditorDebuggerServerWebSocket::poll() {
diff --git a/modules/websocket/remote_debugger_peer_websocket.cpp b/modules/websocket/remote_debugger_peer_websocket.cpp
index a0629ecf00..a67a959e31 100644
--- a/modules/websocket/remote_debugger_peer_websocket.cpp
+++ b/modules/websocket/remote_debugger_peer_websocket.cpp
@@ -88,8 +88,9 @@ Array RemoteDebuggerPeerWebSocket::get_message() {
}
Error RemoteDebuggerPeerWebSocket::put_message(const Array &p_arr) {
- if (out_queue.size() >= max_queued_messages)
+ if (out_queue.size() >= max_queued_messages) {
return ERR_OUT_OF_MEMORY;
+ }
out_queue.push_back(p_arr);
return OK;
}
diff --git a/modules/websocket/websocket_client.cpp b/modules/websocket/websocket_client.cpp
index 7cf3bf74bb..3900180739 100644
--- a/modules/websocket/websocket_client.cpp
+++ b/modules/websocket/websocket_client.cpp
@@ -53,8 +53,9 @@ Error WebSocketClient::connect_to_url(String p_url, const Vector<String> p_proto
port = 443;
} else {
ssl = false;
- if (host.begins_with("ws://"))
+ if (host.begins_with("ws://")) {
host = host.substr(5, host.length() - 5);
+ }
}
// Path
diff --git a/modules/websocket/websocket_multiplayer_peer.cpp b/modules/websocket/websocket_multiplayer_peer.cpp
index e0462c74a1..fa2fe891a5 100644
--- a/modules/websocket/websocket_multiplayer_peer.cpp
+++ b/modules/websocket/websocket_multiplayer_peer.cpp
@@ -70,8 +70,9 @@ int WebSocketMultiplayerPeer::_gen_unique_id() const {
void WebSocketMultiplayerPeer::_clear() {
_peer_map.clear();
- if (_current_packet.data != nullptr)
+ if (_current_packet.data != nullptr) {
memfree(_current_packet.data);
+ }
for (List<Packet>::Element *E = _incoming_packets.front(); E; E = E->next()) {
memfree(E->get().data);
@@ -193,8 +194,9 @@ void WebSocketMultiplayerPeer::_send_add(int32_t p_peer_id) {
for (Map<int, Ref<WebSocketPeer>>::Element *E = _peer_map.front(); E; E = E->next()) {
int32_t id = E->key();
- if (p_peer_id == id)
+ if (p_peer_id == id) {
continue; // Skip the newwly added peer (already confirmed)
+ }
// Send new peer to others
_send_sys(get_peer(id), SYS_ADD, p_peer_id);
@@ -206,8 +208,9 @@ void WebSocketMultiplayerPeer::_send_add(int32_t p_peer_id) {
void WebSocketMultiplayerPeer::_send_del(int32_t p_peer_id) {
for (Map<int, Ref<WebSocketPeer>>::Element *E = _peer_map.front(); E; E = E->next()) {
int32_t id = E->key();
- if (p_peer_id != id)
+ if (p_peer_id != id) {
_send_sys(get_peer(id), SYS_DEL, p_peer_id);
+ }
}
}
@@ -228,15 +231,17 @@ Error WebSocketMultiplayerPeer::_server_relay(int32_t p_from, int32_t p_to, cons
} else if (p_to == 0) {
for (Map<int, Ref<WebSocketPeer>>::Element *E = _peer_map.front(); E; E = E->next()) {
- if (E->key() != p_from)
+ if (E->key() != p_from) {
E->get()->put_packet(p_buffer, p_buffer_size);
+ }
}
return OK; // Sent to all but sender
} else if (p_to < 0) {
for (Map<int, Ref<WebSocketPeer>>::Element *E = _peer_map.front(); E; E = E->next()) {
- if (E->key() != p_from && E->key() != -p_to)
+ if (E->key() != p_from && E->key() != -p_to) {
E->get()->put_packet(p_buffer, p_buffer_size);
+ }
}
return OK; // Sent to all but sender and excluded
@@ -286,8 +291,9 @@ void WebSocketMultiplayerPeer::_process_multiplayer(Ref<WebSocketPeer> p_peer, u
} else if (to < 0) {
// All but one, for us if not excluded
- if (_peer_id != -(int32_t)p_peer_id)
+ if (_peer_id != -(int32_t)p_peer_id) {
_store_pkt(from, to, in_buffer, data_size);
+ }
}
// Relay if needed (i.e. "to" includes a peer that is not the server)
_server_relay(from, to, in_buffer, size);
@@ -308,8 +314,9 @@ void WebSocketMultiplayerPeer::_process_multiplayer(Ref<WebSocketPeer> p_peer, u
case SYS_ADD: // Add peer
_peer_map[id] = Ref<WebSocketPeer>();
emit_signal("peer_connected", id);
- if (id == 1) // We just connected to the server
+ if (id == 1) { // We just connected to the server
emit_signal("connection_succeeded");
+ }
break;
case SYS_DEL: // Remove peer
diff --git a/modules/websocket/websocket_server.cpp b/modules/websocket/websocket_server.cpp
index 4c1fcff626..b20b925dec 100644
--- a/modules/websocket/websocket_server.cpp
+++ b/modules/websocket/websocket_server.cpp
@@ -109,8 +109,9 @@ void WebSocketServer::set_ca_chain(Ref<X509Certificate> p_ca_chain) {
}
NetworkedMultiplayerPeer::ConnectionStatus WebSocketServer::get_connection_status() const {
- if (is_listening())
+ if (is_listening()) {
return CONNECTION_CONNECTED;
+ }
return CONNECTION_DISCONNECTED;
}
diff --git a/modules/websocket/wsl_client.cpp b/modules/websocket/wsl_client.cpp
index 271e475786..7d16c2e99f 100644
--- a/modules/websocket/wsl_client.cpp
+++ b/modules/websocket/wsl_client.cpp
@@ -117,10 +117,11 @@ bool WSLClient::_verify_headers(String &r_protocol) {
ERR_FAIL_COND_V_MSG(header.size() != 2, false, "Invalid header -> " + psa[i] + ".");
String name = header[0].to_lower();
String value = header[1].strip_edges();
- if (headers.has(name))
+ if (headers.has(name)) {
headers[name] += "," + value;
- else
+ } else {
headers[name] = value;
+ }
}
#define _WSL_CHECK(NAME, VALUE) \
@@ -142,13 +143,15 @@ bool WSLClient::_verify_headers(String &r_protocol) {
r_protocol = headers["sec-websocket-protocol"];
bool valid = false;
for (int i = 0; i < _protocols.size(); i++) {
- if (_protocols[i] != r_protocol)
+ if (_protocols[i] != r_protocol) {
continue;
+ }
valid = true;
break;
}
- if (!valid)
+ if (!valid) {
return false;
+ }
}
return true;
}
@@ -199,8 +202,9 @@ Error WSLClient::connect_to_host(String p_host, String p_path, uint16_t p_port,
if (p_protocols.size() > 0) {
request += "Sec-WebSocket-Protocol: ";
for (int i = 0; i < p_protocols.size(); i++) {
- if (i != 0)
+ if (i != 0) {
request += ",";
+ }
request += p_protocols[i];
}
request += "\r\n";
@@ -228,8 +232,9 @@ void WSLClient::poll() {
return;
}
- if (_connection.is_null())
+ if (_connection.is_null()) {
return; // Not connected.
+ }
switch (_tcp->get_status()) {
case StreamPeerTCP::STATUS_NONE:
@@ -256,9 +261,9 @@ void WSLClient::poll() {
ERR_FAIL_COND(ssl.is_null()); // Bug?
ssl->poll();
}
- if (ssl->get_status() == StreamPeerSSL::STATUS_HANDSHAKING)
+ if (ssl->get_status() == StreamPeerSSL::STATUS_HANDSHAKING) {
return; // Need more polling.
- else if (ssl->get_status() != StreamPeerSSL::STATUS_CONNECTED) {
+ } else if (ssl->get_status() != StreamPeerSSL::STATUS_CONNECTED) {
disconnect_from_host();
_on_error();
return; // Error.
@@ -283,11 +288,13 @@ Ref<WebSocketPeer> WSLClient::get_peer(int p_peer_id) const {
}
NetworkedMultiplayerPeer::ConnectionStatus WSLClient::get_connection_status() const {
- if (_peer->is_connected_to_host())
+ if (_peer->is_connected_to_host()) {
return CONNECTION_CONNECTED;
+ }
- if (_tcp->is_connected_to_host())
+ if (_tcp->is_connected_to_host()) {
return CONNECTION_CONNECTING;
+ }
return CONNECTION_DISCONNECTED;
}
diff --git a/modules/websocket/wsl_peer.cpp b/modules/websocket/wsl_peer.cpp
index 98dff6fec9..bf1ba43f8a 100644
--- a/modules/websocket/wsl_peer.cpp
+++ b/modules/websocket/wsl_peer.cpp
@@ -60,8 +60,9 @@ String WSLPeer::compute_key_response(String p_key) {
}
void WSLPeer::_wsl_destroy(struct PeerData **p_data) {
- if (!p_data || !(*p_data))
+ if (!p_data || !(*p_data)) {
return;
+ }
struct PeerData *data = *p_data;
if (data->polling) {
data->destroy = true;
@@ -147,8 +148,9 @@ void wsl_msg_recv_callback(wslay_event_context_ptr ctx, const struct wslay_event
}
WSLPeer *peer = (WSLPeer *)peer_data->peer;
- if (peer->parse_message(arg) != OK)
+ if (peer->parse_message(arg) != OK) {
return;
+ }
if (peer_data->is_server) {
WSLServer *helper = (WSLServer *)peer_data->obj;
@@ -209,10 +211,11 @@ void WSLPeer::make_context(PeerData *p_data, unsigned int p_in_buf_size, unsigne
_data->peer = this;
_data->valid = true;
- if (_data->is_server)
+ if (_data->is_server) {
wslay_event_context_server_init(&(_data->ctx), &wsl_callbacks, _data);
- else
+ } else {
wslay_event_context_client_init(&(_data->ctx), &wsl_callbacks, _data);
+ }
wslay_event_config_set_max_recv_msg_length(_data->ctx, (1ULL << p_in_buf_size));
}
@@ -225,8 +228,9 @@ WSLPeer::WriteMode WSLPeer::get_write_mode() const {
}
void WSLPeer::poll() {
- if (!_data)
+ if (!_data) {
return;
+ }
if (_wsl_poll(_data)) {
_data = nullptr;
@@ -254,8 +258,9 @@ Error WSLPeer::get_packet(const uint8_t **r_buffer, int &r_buffer_size) {
ERR_FAIL_COND_V(!is_connected_to_host(), FAILED);
- if (_in_buffer.packets_left() == 0)
+ if (_in_buffer.packets_left() == 0) {
return ERR_UNAVAILABLE;
+ }
int read = 0;
uint8_t *rw = _packet_buffer.ptrw();
@@ -268,8 +273,9 @@ Error WSLPeer::get_packet(const uint8_t **r_buffer, int &r_buffer_size) {
}
int WSLPeer::get_available_packet_count() const {
- if (!is_connected_to_host())
+ if (!is_connected_to_host()) {
return 0;
+ }
return _in_buffer.packets_left();
}
@@ -317,8 +323,9 @@ void WSLPeer::set_no_delay(bool p_enabled) {
}
void WSLPeer::invalidate() {
- if (_data)
+ if (_data) {
_data->valid = false;
+ }
}
WSLPeer::WSLPeer() {
diff --git a/modules/websocket/wsl_server.cpp b/modules/websocket/wsl_server.cpp
index a3f4349f04..da7bfc70c0 100644
--- a/modules/websocket/wsl_server.cpp
+++ b/modules/websocket/wsl_server.cpp
@@ -60,10 +60,11 @@ bool WSLServer::PendingPeer::_parse_request(const Vector<String> p_protocols) {
ERR_FAIL_COND_V_MSG(header.size() != 2, false, "Invalid header -> " + psa[i]);
String name = header[0].to_lower();
String value = header[1].strip_edges();
- if (headers.has(name))
+ if (headers.has(name)) {
headers[name] += "," + value;
- else
+ } else {
headers[name] = value;
+ }
}
#define _WSL_CHECK(NAME, VALUE) \
ERR_FAIL_COND_V_MSG(!headers.has(NAME) || headers[NAME].to_lower() != VALUE, false, \
@@ -83,44 +84,52 @@ bool WSLServer::PendingPeer::_parse_request(const Vector<String> p_protocols) {
String proto = protos[i].strip_edges();
// Check if we have the given protocol
for (int j = 0; j < p_protocols.size(); j++) {
- if (proto != p_protocols[j])
+ if (proto != p_protocols[j]) {
continue;
+ }
protocol = proto;
break;
}
// Found a protocol
- if (protocol != "")
+ if (protocol != "") {
break;
+ }
}
- if (protocol == "") // Invalid protocol(s) requested
+ if (protocol == "") { // Invalid protocol(s) requested
return false;
- } else if (p_protocols.size() > 0) // No protocol requested, but we need one
+ }
+ } else if (p_protocols.size() > 0) { // No protocol requested, but we need one
return false;
+ }
return true;
}
Error WSLServer::PendingPeer::do_handshake(const Vector<String> p_protocols) {
- if (OS::get_singleton()->get_ticks_msec() - time > WSL_SERVER_TIMEOUT)
+ if (OS::get_singleton()->get_ticks_msec() - time > WSL_SERVER_TIMEOUT) {
return ERR_TIMEOUT;
+ }
if (use_ssl) {
Ref<StreamPeerSSL> ssl = static_cast<Ref<StreamPeerSSL>>(connection);
- if (ssl.is_null())
+ if (ssl.is_null()) {
return FAILED;
+ }
ssl->poll();
- if (ssl->get_status() == StreamPeerSSL::STATUS_HANDSHAKING)
+ if (ssl->get_status() == StreamPeerSSL::STATUS_HANDSHAKING) {
return ERR_BUSY;
- else if (ssl->get_status() != StreamPeerSSL::STATUS_CONNECTED)
+ } else if (ssl->get_status() != StreamPeerSSL::STATUS_CONNECTED) {
return FAILED;
+ }
}
if (!has_request) {
int read = 0;
while (true) {
ERR_FAIL_COND_V_MSG(req_pos >= WSL_MAX_HEADER_SIZE, ERR_OUT_OF_MEMORY, "Response headers too big.");
Error err = connection->get_partial_data(&req_buf[req_pos], 1, read);
- if (err != OK) // Got an error
+ if (err != OK) { // Got an error
return FAILED;
- else if (read != 1) // Busy, wait next poll
+ } else if (read != 1) { // Busy, wait next poll
return ERR_BUSY;
+ }
char *r = (char *)req_buf;
int l = req_pos;
if (l > 3 && r[l] == '\n' && r[l - 1] == '\r' && r[l - 2] == '\n' && r[l - 3] == '\r') {
@@ -132,8 +141,9 @@ Error WSLServer::PendingPeer::do_handshake(const Vector<String> p_protocols) {
s += "Upgrade: websocket\r\n";
s += "Connection: Upgrade\r\n";
s += "Sec-WebSocket-Accept: " + WSLPeer::compute_key_response(key) + "\r\n";
- if (protocol != "")
+ if (protocol != "") {
s += "Sec-WebSocket-Protocol: " + protocol + "\r\n";
+ }
s += "\r\n";
response = s.utf8();
has_request = true;
@@ -150,8 +160,9 @@ Error WSLServer::PendingPeer::do_handshake(const Vector<String> p_protocols) {
}
response_sent += sent;
}
- if (response_sent < response.size() - 1)
+ if (response_sent < response.size() - 1) {
return ERR_BUSY;
+ }
return OK;
}
@@ -216,13 +227,15 @@ void WSLServer::poll() {
}
remove_peers.clear();
- if (!_server->is_listening())
+ if (!_server->is_listening()) {
return;
+ }
while (_server->is_connection_available()) {
Ref<StreamPeerTCP> conn = _server->take_connection();
- if (is_refusing_new_connections())
+ if (is_refusing_new_connections()) {
continue; // Conn will go out-of-scope and be closed.
+ }
Ref<PendingPeer> peer = memnew(PendingPeer);
if (private_key.is_valid() && ssl_cert.is_valid()) {
diff --git a/platform/android/export/export.cpp b/platform/android/export/export.cpp
index 329798b497..0b6c6990f3 100644
--- a/platform/android/export/export.cpp
+++ b/platform/android/export/export.cpp
@@ -275,8 +275,9 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
for (int i = 1; i < ds.size(); i++) {
String d = ds[i];
int dpos = d.find("device");
- if (dpos == -1)
+ if (dpos == -1) {
continue;
+ }
d = d.substr(0, dpos).strip_edges();
ldevices.push_back(d);
}
@@ -359,8 +360,9 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
}
d.name = vendor + " " + device;
- if (device == String())
+ if (device == String()) {
continue;
+ }
}
ndevices.push_back(d);
@@ -376,8 +378,9 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
uint64_t time = OS::get_singleton()->get_ticks_usec();
while (OS::get_singleton()->get_ticks_usec() - time < wait) {
OS::get_singleton()->delay_usec(1000 * sleep);
- if (ea->quit_request)
+ if (ea->quit_request) {
break;
+ }
}
}
@@ -425,8 +428,9 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
first = false;
}
}
- if (name == "")
+ if (name == "") {
name = "noname";
+ }
pname = pname.replace("$genname", name);
@@ -677,8 +681,9 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
const char **aperms = android_perms;
while (*aperms) {
bool enabled = p_preset->get("permissions/" + String(*aperms).to_lower());
- if (enabled)
+ if (enabled) {
perms.push_back("android.permission." + String(*aperms));
+ }
aperms++;
}
@@ -692,8 +697,9 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
}
if (p_give_internet) {
- if (perms.find("android.permission.INTERNET") == -1)
+ if (perms.find("android.permission.INTERNET") == -1) {
perms.push_back("android.permission.INTERNET");
+ }
}
while (ofs < (uint32_t)p_manifest.size()) {
@@ -779,8 +785,9 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
if (tname == "manifest" && attrname == "versionName") {
if (attr_value == 0xFFFFFFFF) {
WARN_PRINT("Version name in a resource, should be plain text");
- } else
+ } else {
string_table.write[attr_value] = version_name;
+ }
}
if (tname == "instrumentation" && attrname == "targetPackage") {
@@ -1120,18 +1127,21 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
}
//pad
- while (ret.size() % 4)
+ while (ret.size() % 4) {
ret.push_back(0);
+ }
uint32_t new_stable_end = ret.size();
uint32_t extra = (p_manifest.size() - string_table_ends);
ret.resize(new_stable_end + extra);
- for (uint32_t i = 0; i < extra; i++)
+ for (uint32_t i = 0; i < extra; i++) {
ret.write[new_stable_end + i] = p_manifest[string_table_ends + i];
+ }
- while (ret.size() % 4)
+ while (ret.size() % 4) {
ret.push_back(0);
+ }
encode_uint32(ret.size(), &ret.write[4]); //update new file size
encode_uint32(new_stable_end - 8, &ret.write[12]); //update new string table size
@@ -1147,10 +1157,11 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
if (p_utf8) {
uint8_t byte = p_bytes[offset];
- if (byte & 0x80)
+ if (byte & 0x80) {
offset += 2;
- else
+ } else {
offset += 1;
+ }
byte = p_bytes[offset];
offset++;
if (byte & 0x80) {
@@ -1184,8 +1195,9 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
String str;
for (uint32_t i = 0; i < len; i++) {
CharType c = decode_uint16(&p_bytes[offset + i * 2]);
- if (c == 0)
+ if (c == 0) {
break;
+ }
str += String::chr(c);
}
return str;
@@ -1257,8 +1269,9 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
}
//pad
- while (ret.size() % 4)
+ while (ret.size() % 4) {
ret.push_back(0);
+ }
//change flags to not use utf8
encode_uint32(string_flags & ~0x100, &ret.write[28]);
@@ -1457,8 +1470,9 @@ public:
const bool use_remote = (p_debug_flags & DEBUG_FLAG_REMOTE_DEBUG) || (p_debug_flags & DEBUG_FLAG_DUMB_CLIENT);
const bool use_reverse = devices[p_device].api_level >= 21;
- if (use_reverse)
+ if (use_reverse) {
p_debug_flags |= DEBUG_FLAG_REMOTE_DEBUG_LOCALHOST;
+ }
String tmp_export_path = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmpexport.apk");
@@ -1779,10 +1793,11 @@ public:
}
} else {
- if (p_debug)
+ if (p_debug) {
src_apk = p_preset->get("custom_template/debug");
- else
+ } else {
src_apk = p_preset->get("custom_template/release");
+ }
src_apk = src_apk.strip_edges();
if (src_apk == "") {
@@ -2031,14 +2046,17 @@ public:
cl.push_back("--xr_mode_regular");
}
- if (use_32_fb)
+ if (use_32_fb) {
cl.push_back("--use_depth_32");
+ }
- if (immersive)
+ if (immersive) {
cl.push_back("--use_immersive");
+ }
- if (debug_opengl)
+ if (debug_opengl) {
cl.push_back("--debug_opengl");
+ }
if (cl.size()) {
//add comandline
@@ -2050,8 +2068,9 @@ public:
CharString txt = cl[i].utf8();
int base = clf.size();
int length = txt.length();
- if (!length)
+ if (!length) {
continue;
+ }
clf.resize(base + 4 + length);
encode_uint32(length, &clf.write[base]);
copymem(&clf.write[base + 4], txt.ptr(), length);
diff --git a/platform/iphone/export/export.cpp b/platform/iphone/export/export.cpp
index e5e9f7764b..63c3cb8c23 100644
--- a/platform/iphone/export/export.cpp
+++ b/platform/iphone/export/export.cpp
@@ -415,8 +415,9 @@ String EditorExportPlatformIOS::_get_linker_flags() {
String result;
for (int i = 0; i < export_plugins.size(); ++i) {
String flags = export_plugins[i]->get_ios_linker_flags();
- if (flags.length() == 0)
+ if (flags.length() == 0) {
continue;
+ }
if (result.length() > 0) {
result += ' ';
}
@@ -448,10 +449,12 @@ void EditorExportPlatformIOS::_blend_and_rotate(Ref<Image> &p_dst, Ref<Image> &p
int xs = (x_pos >= 0) ? 0 : -x_pos;
int ys = (y_pos >= 0) ? 0 : -y_pos;
- if (sw + x_pos > p_dst->get_width())
+ if (sw + x_pos > p_dst->get_width()) {
sw = p_dst->get_width() - x_pos;
- if (sh + y_pos > p_dst->get_height())
+ }
+ if (sh + y_pos > p_dst->get_height()) {
sh = p_dst->get_height() - y_pos;
+ }
for (int y = ys; y < sh; y++) {
for (int x = xs; x < sw; x++) {
@@ -921,8 +924,9 @@ Error EditorExportPlatformIOS::_export_additional_assets(const String &p_out_dir
ERR_FAIL_COND_V(err, err);
Vector<String> project_static_libs = export_plugins[i]->get_ios_project_static_libs();
- for (int j = 0; j < project_static_libs.size(); j++)
+ for (int j = 0; j < project_static_libs.size(); j++) {
project_static_libs.write[j] = project_static_libs[j].get_file(); // Only the file name as it's copied to the project
+ }
err = _export_additional_assets(p_out_dir, project_static_libs, true, r_exported_assets);
ERR_FAIL_COND_V(err, err);
@@ -981,10 +985,11 @@ Error EditorExportPlatformIOS::export_project(const Ref<EditorExportPreset> &p_p
String team_id = p_preset->get("application/app_store_team_id");
ERR_FAIL_COND_V_MSG(team_id.length() == 0, ERR_CANT_OPEN, "App Store Team ID not specified - cannot configure the project.");
- if (p_debug)
+ if (p_debug) {
src_pkg_name = p_preset->get("custom_template/debug");
- else
+ } else {
src_pkg_name = p_preset->get("custom_template/release");
+ }
if (src_pkg_name == "") {
String err;
@@ -1030,8 +1035,9 @@ Error EditorExportPlatformIOS::export_project(const Ref<EditorExportPreset> &p_p
String pack_path = dest_dir + binary_name + ".pck";
Vector<SharedObject> libraries;
Error err = save_pack(p_preset, pack_path, &libraries);
- if (err)
+ if (err) {
return err;
+ }
if (ep.step("Extracting and configuring Xcode project", 1)) {
return ERR_SKIP;
@@ -1041,12 +1047,13 @@ Error EditorExportPlatformIOS::export_project(const Ref<EditorExportPreset> &p_p
print_line("Static library: " + library_to_use);
String pkg_name;
- if (p_preset->get("application/name") != "")
+ if (p_preset->get("application/name") != "") {
pkg_name = p_preset->get("application/name"); // app_name
- else if (String(ProjectSettings::get_singleton()->get("application/config/name")) != "")
+ } else if (String(ProjectSettings::get_singleton()->get("application/config/name")) != "") {
pkg_name = String(ProjectSettings::get_singleton()->get("application/config/name"));
- else
+ } else {
pkg_name = "Unnamed";
+ }
bool found_library = false;
int total_size = 0;
@@ -1225,16 +1232,19 @@ Error EditorExportPlatformIOS::export_project(const Ref<EditorExportPreset> &p_p
err = tmp_app_path->make_dir_recursive(iconset_dir);
}
memdelete(tmp_app_path);
- if (err)
+ if (err) {
return err;
+ }
err = _export_icons(p_preset, iconset_dir);
- if (err)
+ if (err) {
return err;
+ }
err = _export_loading_screens(p_preset, dest_dir + binary_name + "/Images.xcassets/LaunchImage.launchimage/");
- if (err)
+ if (err) {
return err;
+ }
print_line("Exporting additional assets");
Vector<IOSExportAsset> assets;
@@ -1361,8 +1371,9 @@ bool EditorExportPlatformIOS::can_export(const Ref<EditorExportPreset> &p_preset
err += etc_error;
}
- if (!err.empty())
+ if (!err.empty()) {
r_error = err;
+ }
return valid;
}
diff --git a/platform/javascript/export/export.cpp b/platform/javascript/export/export.cpp
index b5172651d0..3573ddac95 100644
--- a/platform/javascript/export/export.cpp
+++ b/platform/javascript/export/export.cpp
@@ -148,11 +148,13 @@ public:
}
void poll() {
- if (!server->is_listening())
+ if (!server->is_listening()) {
return;
+ }
if (connection.is_null()) {
- if (!server->is_connection_available())
+ if (!server->is_connection_available()) {
return;
+ }
connection = server->take_connection();
time = OS::get_singleton()->get_ticks_usec();
}
@@ -160,8 +162,9 @@ public:
_clear_client();
return;
}
- if (connection->get_status() != StreamPeerTCP::STATUS_CONNECTED)
+ if (connection->get_status() != StreamPeerTCP::STATUS_CONNECTED) {
return;
+ }
while (true) {
char *r = (char *)req_buf;
@@ -339,8 +342,9 @@ bool EditorExportPlatformJavaScript::can_export(const Ref<EditorExportPreset> &p
}
}
- if (!err.empty())
+ if (!err.empty()) {
r_error = err;
+ }
return valid;
}
@@ -363,10 +367,11 @@ Error EditorExportPlatformJavaScript::export_project(const Ref<EditorExportPrese
template_path = template_path.strip_edges();
if (template_path == String()) {
- if (p_debug)
+ if (p_debug) {
template_path = find_export_template(EXPORT_TEMPLATE_WEBASSEMBLY_DEBUG);
- else
+ } else {
template_path = find_export_template(EXPORT_TEMPLATE_WEBASSEMBLY_RELEASE);
+ }
}
if (!DirAccess::exists(p_path.get_base_dir())) {
@@ -618,10 +623,11 @@ EditorExportPlatformJavaScript::EditorExportPlatformJavaScript() {
run_icon->create_from_image(img);
Ref<Theme> theme = EditorNode::get_singleton()->get_editor_theme();
- if (theme.is_valid())
+ if (theme.is_valid()) {
stop_icon = theme->get_icon("Stop", "EditorIcons");
- else
+ } else {
stop_icon.instance();
+ }
menu_options = 0;
}
diff --git a/platform/linuxbsd/crash_handler_linuxbsd.cpp b/platform/linuxbsd/crash_handler_linuxbsd.cpp
index dbdb15918e..b3553e961a 100644
--- a/platform/linuxbsd/crash_handler_linuxbsd.cpp
+++ b/platform/linuxbsd/crash_handler_linuxbsd.cpp
@@ -63,8 +63,9 @@ static void handle_crash(int sig) {
// Dump the backtrace to stderr with a message to the user
fprintf(stderr, "%s: Program crashed with signal %d\n", __FUNCTION__, sig);
- if (OS::get_singleton()->get_main_loop())
+ if (OS::get_singleton()->get_main_loop()) {
OS::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_CRASH);
+ }
fprintf(stderr, "Dumping the backtrace. %ls\n", msg.c_str());
char **strings = backtrace_symbols(bt_buffer, size);
@@ -85,8 +86,9 @@ static void handle_crash(int sig) {
snprintf(fname, 1024, "%s", demangled);
}
- if (demangled)
+ if (demangled) {
free(demangled);
+ }
}
}
@@ -128,8 +130,9 @@ CrashHandler::~CrashHandler() {
}
void CrashHandler::disable() {
- if (disabled)
+ if (disabled) {
return;
+ }
#ifdef CRASH_HANDLER_ENABLED
signal(SIGSEGV, nullptr);
diff --git a/platform/linuxbsd/display_server_x11.cpp b/platform/linuxbsd/display_server_x11.cpp
index 813acc5b0e..ef5ac66b34 100644
--- a/platform/linuxbsd/display_server_x11.cpp
+++ b/platform/linuxbsd/display_server_x11.cpp
@@ -149,8 +149,9 @@ void DisplayServerX11::alert(const String &p_alert, const String &p_title) {
}
}
- if (program.length())
+ if (program.length()) {
break;
+ }
}
List<String> args;
@@ -245,10 +246,12 @@ bool DisplayServerX11::_refresh_device_info() {
for (int i = 0; i < dev_count; i++) {
XIDeviceInfo *dev = &info[i];
- if (!dev->enabled)
+ if (!dev->enabled) {
continue;
- if (!(dev->use == XIMasterPointer || dev->use == XIFloatingSlave))
+ }
+ if (!(dev->use == XIMasterPointer || dev->use == XIFloatingSlave)) {
continue;
+ }
bool direct_touch = false;
bool absolute_mode = false;
@@ -356,11 +359,13 @@ void DisplayServerX11::_flush_mouse_motion() {
void DisplayServerX11::mouse_set_mode(MouseMode p_mode) {
_THREAD_SAFE_METHOD_
- if (p_mode == mouse_mode)
+ if (p_mode == mouse_mode) {
return;
+ }
- if (mouse_mode == MOUSE_MODE_CAPTURED || mouse_mode == MOUSE_MODE_CONFINED)
+ if (mouse_mode == MOUSE_MODE_CAPTURED || mouse_mode == MOUSE_MODE_CONFINED) {
XUngrabPointer(x11_display, CurrentTime);
+ }
// The only modes that show a cursor are VISIBLE and CONFINED
bool showCursor = (p_mode == MOUSE_MODE_VISIBLE || p_mode == MOUSE_MODE_CONFINED);
@@ -499,8 +504,9 @@ static String _clipboard_get_impl(Atom p_source, Window x11_window, ::Display *x
&len, &dummy, &data);
if (result == Success) {
ret.parse_utf8((const char *)data);
- } else
+ } else {
printf("FAIL\n");
+ }
if (data) {
XFree(data);
}
@@ -541,8 +547,9 @@ int DisplayServerX11::get_screen_count() const {
// Using Xinerama Extension
int event_base, error_base;
const Bool ext_okay = XineramaQueryExtension(x11_display, &event_base, &error_base);
- if (!ext_okay)
+ if (!ext_okay) {
return 0;
+ }
int count;
XineramaScreenInfo *xsi = XineramaQueryScreens(x11_display, &count);
@@ -591,13 +598,15 @@ Rect2i DisplayServerX11::screen_get_usable_rect(int p_screen) const {
// Using Xinerama Extension
int event_base, error_base;
const Bool ext_okay = XineramaQueryExtension(x11_display, &event_base, &error_base);
- if (!ext_okay)
+ if (!ext_okay) {
return Rect2i(0, 0, 0, 0);
+ }
int count;
XineramaScreenInfo *xsi = XineramaQueryScreens(x11_display, &count);
- if (p_screen >= count)
+ if (p_screen >= count) {
return Rect2i(0, 0, 0, 0);
+ }
Rect2i rect = Rect2i(xsi[p_screen].x_org, xsi[p_screen].y_org, xsi[p_screen].width, xsi[p_screen].height);
XFree(xsi);
@@ -641,8 +650,9 @@ int DisplayServerX11::screen_get_dpi(int p_screen) const {
int height_mm = DisplayHeightMM(x11_display, p_screen);
double xdpi = (width_mm ? sc.width / (double)width_mm * 25.4 : 0);
double ydpi = (height_mm ? sc.height / (double)height_mm * 25.4 : 0);
- if (xdpi || ydpi)
+ if (xdpi || ydpi) {
return (xdpi + ydpi) / (xdpi && ydpi ? 2 : 1);
+ }
//could not get dpi
return 96;
@@ -795,8 +805,9 @@ int DisplayServerX11::window_get_current_screen(WindowID p_window) const {
for (int i = 0; i < count; i++) {
Point2i pos = screen_get_position(i);
Size2i size = screen_get_size(i);
- if ((x >= pos.x && x < pos.x + size.width) && (y >= pos.y && y < pos.y + size.height))
+ if ((x >= pos.x && x < pos.x + size.width) && (y >= pos.y && y < pos.y + size.height)) {
return i;
+ }
}
return 0;
}
@@ -808,8 +819,9 @@ void DisplayServerX11::window_set_current_screen(int p_screen, WindowID p_window
WindowData &wd = windows[p_window];
int count = get_screen_count();
- if (p_screen >= count)
+ if (p_screen >= count) {
return;
+ }
if (window_get_mode(p_window) == WINDOW_MODE_FULLSCREEN) {
Point2i position = screen_get_position(p_screen);
@@ -995,8 +1007,9 @@ void DisplayServerX11::window_set_size(const Size2i p_size, WindowID p_window) {
WindowData &wd = windows[p_window];
- if (wd.size.width == size.width && wd.size.height == size.height)
+ if (wd.size.width == size.width && wd.size.height == size.height) {
return;
+ }
XWindowAttributes xwa;
XSync(x11_display, False);
@@ -1039,8 +1052,9 @@ void DisplayServerX11::window_set_size(const Size2i p_size, WindowID p_window) {
XSync(x11_display, False);
XGetWindowAttributes(x11_display, wd.x11_window, &xwa);
- if (old_w != xwa.width || old_h != xwa.height)
+ if (old_w != xwa.width || old_h != xwa.height) {
break;
+ }
usleep(10000);
}
@@ -1119,13 +1133,16 @@ bool DisplayServerX11::window_is_maximize_allowed(WindowID p_window) const {
bool found_wm_act_max_vert = false;
for (uint64_t i = 0; i < len; i++) {
- if (atoms[i] == wm_act_max_horz)
+ if (atoms[i] == wm_act_max_horz) {
found_wm_act_max_horz = true;
- if (atoms[i] == wm_act_max_vert)
+ }
+ if (atoms[i] == wm_act_max_vert) {
found_wm_act_max_vert = true;
+ }
- if (found_wm_act_max_horz || found_wm_act_max_vert)
+ if (found_wm_act_max_horz || found_wm_act_max_vert) {
return true;
+ }
}
XFree(atoms);
}
@@ -1400,10 +1417,12 @@ DisplayServer::WindowMode DisplayServerX11::window_get_mode(WindowID p_window) c
bool found_wm_max_vert = false;
for (uint64_t i = 0; i < len; i++) {
- if (atoms[i] == wm_max_horz)
+ if (atoms[i] == wm_max_horz) {
found_wm_max_horz = true;
- if (atoms[i] == wm_max_vert)
+ }
+ if (atoms[i] == wm_max_vert) {
found_wm_max_vert = true;
+ }
if (found_wm_max_horz && found_wm_max_vert) {
retval = true;
@@ -1659,8 +1678,9 @@ void DisplayServerX11::window_set_ime_active(const bool p_active, WindowID p_win
wd.im_active = p_active;
- if (!wd.xic)
+ if (!wd.xic) {
return;
+ }
if (p_active) {
XSetICFocus(wd.xic);
@@ -1678,8 +1698,9 @@ void DisplayServerX11::window_set_ime_position(const Point2i &p_pos, WindowID p_
wd.im_position = p_pos;
- if (!wd.xic)
+ if (!wd.xic) {
return;
+ }
::XPoint spot;
spot.x = short(p_pos.x);
@@ -1870,8 +1891,9 @@ DisplayServerX11::Property DisplayServerX11::_read_property(Display *p_display,
//Keep trying to read the property until there are no
//bytes unread.
do {
- if (ret != nullptr)
+ if (ret != nullptr) {
XFree(ret);
+ }
XGetWindowProperty(p_display, p_window, p_property, 0, read_bytes, False, AnyPropertyType,
&actual_type, &actual_format, &nitems, &bytes_after,
@@ -1892,22 +1914,26 @@ static Atom pick_target_from_list(Display *p_display, Atom *p_list, int p_count)
for (int i = 0; i < p_count; i++) {
Atom atom = p_list[i];
- if (atom != None && String(XGetAtomName(p_display, atom)) == target_type)
+ if (atom != None && String(XGetAtomName(p_display, atom)) == target_type) {
return atom;
+ }
}
return None;
}
static Atom pick_target_from_atoms(Display *p_disp, Atom p_t1, Atom p_t2, Atom p_t3) {
static const char *target_type = "text/uri-list";
- if (p_t1 != None && String(XGetAtomName(p_disp, p_t1)) == target_type)
+ if (p_t1 != None && String(XGetAtomName(p_disp, p_t1)) == target_type) {
return p_t1;
+ }
- if (p_t2 != None && String(XGetAtomName(p_disp, p_t2)) == target_type)
+ if (p_t2 != None && String(XGetAtomName(p_disp, p_t2)) == target_type) {
return p_t2;
+ }
- if (p_t3 != None && String(XGetAtomName(p_disp, p_t3)) == target_type)
+ if (p_t3 != None && String(XGetAtomName(p_disp, p_t3)) == target_type) {
return p_t3;
+ }
return None;
}
@@ -1994,8 +2020,9 @@ void DisplayServerX11::_handle_key_event(WindowID p_window, XKeyEvent *p_event,
unsigned int keycode = KeyMappingX11::get_keycode(keysym_keycode);
unsigned int physical_keycode = KeyMappingX11::get_scancode(xkeyevent->keycode);
- if (keycode >= 'a' && keycode <= 'z')
+ if (keycode >= 'a' && keycode <= 'z') {
keycode -= 'a' - 'A';
+ }
String tmp;
tmp.parse_utf8(utf8string, utf8bytes);
@@ -2143,8 +2170,9 @@ void DisplayServerX11::_handle_key_event(WindowID p_window, XKeyEvent *p_event,
k->set_pressed(keypress);
- if (keycode >= 'a' && keycode <= 'z')
+ if (keycode >= 'a' && keycode <= 'z') {
keycode -= 'a' - 'A';
+ }
k->set_keycode(keycode);
k->set_physical_keycode(physical_keycode);
@@ -2161,14 +2189,15 @@ void DisplayServerX11::_handle_key_event(WindowID p_window, XKeyEvent *p_event,
//don't set mod state if modifier keys are released by themselves
//else event.is_action() will not work correctly here
if (!k->is_pressed()) {
- if (k->get_keycode() == KEY_SHIFT)
+ if (k->get_keycode() == KEY_SHIFT) {
k->set_shift(false);
- else if (k->get_keycode() == KEY_CONTROL)
+ } else if (k->get_keycode() == KEY_CONTROL) {
k->set_control(false);
- else if (k->get_keycode() == KEY_ALT)
+ } else if (k->get_keycode() == KEY_ALT) {
k->set_alt(false);
- else if (k->get_keycode() == KEY_META)
+ } else if (k->get_keycode() == KEY_META) {
k->set_metakey(false);
+ }
}
bool last_is_pressed = Input::get_singleton()->is_key_pressed(k->get_keycode());
@@ -2441,8 +2470,9 @@ void DisplayServerX11::process_events() {
st->set_pressed(is_begin);
if (is_begin) {
- if (xi.state.has(index)) // Defensive
+ if (xi.state.has(index)) { // Defensive
break;
+ }
xi.state[index] = pos;
if (xi.state.size() == 1) {
// X11 may send a motion event when a touch gesture begins, that would result
@@ -2451,8 +2481,9 @@ void DisplayServerX11::process_events() {
}
Input::get_singleton()->accumulate_input_event(st);
} else {
- if (!xi.state.has(index)) // Defensive
+ if (!xi.state.has(index)) { // Defensive
break;
+ }
xi.state.erase(index);
Input::get_singleton()->accumulate_input_event(st);
}
@@ -2516,10 +2547,11 @@ void DisplayServerX11::process_events() {
// Show and update the cursor if confined and the window regained focus.
for (Map<WindowID, WindowData>::Element *E = windows.front(); E; E = E->next()) {
- if (mouse_mode == MOUSE_MODE_CONFINED)
+ if (mouse_mode == MOUSE_MODE_CONFINED) {
XUndefineCursor(x11_display, E->get().x11_window);
- else if (mouse_mode == MOUSE_MODE_CAPTURED) // or re-hide it in captured mode
+ } else if (mouse_mode == MOUSE_MODE_CAPTURED) { // or re-hide it in captured mode
XDefineCursor(x11_display, E->get().x11_window, null_cursor);
+ }
XGrabPointer(
x11_display, E->get().x11_window, True,
@@ -2594,10 +2626,11 @@ void DisplayServerX11::process_events() {
mb->set_window_id(window_id);
_get_key_modifier_state(event.xbutton.state, mb);
mb->set_button_index(event.xbutton.button);
- if (mb->get_button_index() == 2)
+ if (mb->get_button_index() == 2) {
mb->set_button_index(3);
- else if (mb->get_button_index() == 3)
+ } else if (mb->get_button_index() == 3) {
mb->set_button_index(2);
+ }
mb->set_button_mask(_get_mouse_button_state(mb->get_button_index(), event.xbutton.type));
mb->set_position(Vector2(event.xbutton.x, event.xbutton.y));
mb->set_global_position(mb->get_position());
@@ -2740,8 +2773,9 @@ void DisplayServerX11::process_events() {
// Don't propagate the motion event unless we have focus
// this is so that the relative motion doesn't get messed up
// after we regain focus.
- if (window_has_focus || !mouse_mode_grab)
+ if (window_has_focus || !mouse_mode_grab) {
Input::get_singleton()->accumulate_input_event(mm);
+ }
} break;
case KeyPress:
@@ -2797,8 +2831,9 @@ void DisplayServerX11::process_events() {
} else {
char *targetname = XGetAtomName(x11_display, req->target);
printf("No Target '%s'\n", targetname);
- if (targetname)
+ if (targetname) {
XFree(targetname);
+ }
respond.xselection.property = None;
}
@@ -2860,8 +2895,9 @@ void DisplayServerX11::process_events() {
if (more_than_3) {
Property p = _read_property(x11_display, source, XInternAtom(x11_display, "XdndTypeList", False));
requested = pick_target_from_list(x11_display, (Atom *)p.data, p.nitems);
- } else
+ } else {
requested = pick_target_from_atoms(x11_display, event.xclient.data.l[2], event.xclient.data.l[3], event.xclient.data.l[4]);
+ }
} else if ((unsigned int)event.xclient.message_type == (unsigned int)xdnd_position) {
//xdnd position event, reply with an XDND status message
//just depending on type of data for now
@@ -2883,10 +2919,11 @@ void DisplayServerX11::process_events() {
} else if ((unsigned int)event.xclient.message_type == (unsigned int)xdnd_drop) {
if (requested != None) {
xdnd_source_window = event.xclient.data.l[0];
- if (xdnd_version >= 1)
+ if (xdnd_version >= 1) {
XConvertSelection(x11_display, xdnd_selection, requested, XInternAtom(x11_display, "PRIMARY", 0), windows[window_id].x11_window, event.xclient.data.l[2]);
- else
+ } else {
XConvertSelection(x11_display, xdnd_selection, requested, XInternAtom(x11_display, "PRIMARY", 0), windows[window_id].x11_window, CurrentTime);
+ }
} else {
//Reply that we're not interested.
XClientMessageEvent m;
@@ -3060,8 +3097,9 @@ void DisplayServerX11::set_icon(const Ref<Image> &p_icon) {
XChangeProperty(x11_display, wd.x11_window, net_wm_icon, XA_CARDINAL, 32, PropModeReplace, (unsigned char *)pd.ptr(), pd.size());
- if (!g_set_icon_error)
+ if (!g_set_icon_error) {
break;
+ }
}
} else {
XDeleteProperty(x11_display, wd.x11_window, net_wm_icon);
@@ -3755,19 +3793,23 @@ DisplayServerX11::~DisplayServerX11() {
memdelete(rendering_device_vulkan);
}
- if (context_vulkan)
+ if (context_vulkan) {
memdelete(context_vulkan);
+ }
}
#endif
- if (xrandr_handle)
+ if (xrandr_handle) {
dlclose(xrandr_handle);
+ }
for (int i = 0; i < CURSOR_MAX; i++) {
- if (cursors[i] != None)
+ if (cursors[i] != None) {
XFreeCursor(x11_display, cursors[i]);
- if (img[i] != nullptr)
+ }
+ if (img[i] != nullptr) {
XcursorImageDestroy(img[i]);
+ }
};
if (xim) {
@@ -3775,8 +3817,9 @@ DisplayServerX11::~DisplayServerX11() {
}
XCloseDisplay(x11_display);
- if (xmbstring)
+ if (xmbstring) {
memfree(xmbstring);
+ }
}
void DisplayServerX11::register_x11_driver() {
diff --git a/platform/linuxbsd/godot_linuxbsd.cpp b/platform/linuxbsd/godot_linuxbsd.cpp
index 6a0c2a4a5d..3ed64e9d46 100644
--- a/platform/linuxbsd/godot_linuxbsd.cpp
+++ b/platform/linuxbsd/godot_linuxbsd.cpp
@@ -51,8 +51,9 @@ int main(int argc, char *argv[]) {
return 255;
}
- if (Main::start())
+ if (Main::start()) {
os.run(); // it is actually the OS that decides how to run
+ }
Main::cleanup();
if (ret) { // Previous getcwd was successful
diff --git a/platform/linuxbsd/joypad_linux.cpp b/platform/linuxbsd/joypad_linux.cpp
index e74371ca52..5edaf35c50 100644
--- a/platform/linuxbsd/joypad_linux.cpp
+++ b/platform/linuxbsd/joypad_linux.cpp
@@ -219,8 +219,9 @@ void JoypadLinux::close_joypad(int p_id) {
close_joypad(i);
};
return;
- } else if (p_id < 0)
+ } else if (p_id < 0) {
return;
+ }
Joypad &joy = joypads[p_id];
@@ -434,8 +435,9 @@ void JoypadLinux::process_joypads() {
return;
}
for (int i = 0; i < JOYPADS_MAX; i++) {
- if (joypads[i].fd == -1)
+ if (joypads[i].fd == -1) {
continue;
+ }
input_event events[32];
Joypad *joy = &joypads[i];
@@ -449,8 +451,9 @@ void JoypadLinux::process_joypads() {
// ev may be tainted and out of MAX_KEY range, which will cause
// joy->key_map[ev.code] to crash
- if (ev.code >= MAX_KEY)
+ if (ev.code >= MAX_KEY) {
return;
+ }
switch (ev.type) {
case EV_KEY:
@@ -462,31 +465,36 @@ void JoypadLinux::process_joypads() {
switch (ev.code) {
case ABS_HAT0X:
if (ev.value != 0) {
- if (ev.value < 0)
+ if (ev.value < 0) {
joy->dpad |= Input::HAT_MASK_LEFT;
- else
+ } else {
joy->dpad |= Input::HAT_MASK_RIGHT;
- } else
+ }
+ } else {
joy->dpad &= ~(Input::HAT_MASK_LEFT | Input::HAT_MASK_RIGHT);
+ }
input->joy_hat(i, joy->dpad);
break;
case ABS_HAT0Y:
if (ev.value != 0) {
- if (ev.value < 0)
+ if (ev.value < 0) {
joy->dpad |= Input::HAT_MASK_UP;
- else
+ } else {
joy->dpad |= Input::HAT_MASK_DOWN;
- } else
+ }
+ } else {
joy->dpad &= ~(Input::HAT_MASK_UP | Input::HAT_MASK_DOWN);
+ }
input->joy_hat(i, joy->dpad);
break;
default:
- if (ev.code >= MAX_ABS)
+ if (ev.code >= MAX_ABS) {
return;
+ }
if (joy->abs_map[ev.code] != -1 && joy->abs_info[ev.code]) {
Input::JoyAxis value = axis_correct(joy->abs_info[ev.code], ev.value);
joy->curr_axis[joy->abs_map[ev.code]] = value;
diff --git a/platform/linuxbsd/key_mapping_x11.cpp b/platform/linuxbsd/key_mapping_x11.cpp
index daf7326024..77512b1a9e 100644
--- a/platform/linuxbsd/key_mapping_x11.cpp
+++ b/platform/linuxbsd/key_mapping_x11.cpp
@@ -313,13 +313,15 @@ unsigned int KeyMappingX11::get_scancode(unsigned int p_code) {
unsigned int KeyMappingX11::get_keycode(KeySym p_keysym) {
// kinda bruteforce.. could optimize.
- if (p_keysym < 0x100) // Latin 1, maps 1-1
+ if (p_keysym < 0x100) { // Latin 1, maps 1-1
return p_keysym;
+ }
// look for special key
for (int idx = 0; _xkeysym_to_keycode[idx].keysym != 0; idx++) {
- if (_xkeysym_to_keycode[idx].keysym == p_keysym)
+ if (_xkeysym_to_keycode[idx].keysym == p_keysym) {
return _xkeysym_to_keycode[idx].keycode;
+ }
}
return 0;
@@ -328,13 +330,15 @@ unsigned int KeyMappingX11::get_keycode(KeySym p_keysym) {
KeySym KeyMappingX11::get_keysym(unsigned int p_code) {
// kinda bruteforce.. could optimize.
- if (p_code < 0x100) // Latin 1, maps 1-1
+ if (p_code < 0x100) { // Latin 1, maps 1-1
return p_code;
+ }
// look for special key
for (int idx = 0; _xkeysym_to_keycode[idx].keysym != 0; idx++) {
- if (_xkeysym_to_keycode[idx].keycode == p_code)
+ if (_xkeysym_to_keycode[idx].keycode == p_code) {
return _xkeysym_to_keycode[idx].keysym;
+ }
}
return 0;
@@ -1117,28 +1121,34 @@ static _XTranslateUnicodePair _xkeysym_to_unicode[_KEYSYM_MAX] = {
unsigned int KeyMappingX11::get_unicode_from_keysym(KeySym p_keysym) {
/* Latin-1 */
- if (p_keysym >= 0x20 && p_keysym <= 0x7e)
+ if (p_keysym >= 0x20 && p_keysym <= 0x7e) {
return p_keysym;
- if (p_keysym >= 0xa0 && p_keysym <= 0xff)
+ }
+ if (p_keysym >= 0xa0 && p_keysym <= 0xff) {
return p_keysym;
+ }
// keypad to latin1 is easy
- if (p_keysym >= 0xffaa && p_keysym <= 0xffb9)
+ if (p_keysym >= 0xffaa && p_keysym <= 0xffb9) {
return p_keysym - 0xff80;
+ }
/* Unicode (may be present)*/
- if ((p_keysym & 0xff000000) == 0x01000000)
+ if ((p_keysym & 0xff000000) == 0x01000000) {
return p_keysym & 0x00ffffff;
+ }
int middle, low = 0, high = _KEYSYM_MAX - 1;
do {
middle = (high + low) / 2;
- if (_xkeysym_to_unicode[middle].keysym == p_keysym)
+ if (_xkeysym_to_unicode[middle].keysym == p_keysym) {
return _xkeysym_to_unicode[middle].unicode;
- if (_xkeysym_to_unicode[middle].keysym <= p_keysym)
+ }
+ if (_xkeysym_to_unicode[middle].keysym <= p_keysym) {
low = middle + 1;
- else
+ } else {
high = middle - 1;
+ }
} while (high >= low);
return 0;
@@ -1910,21 +1920,25 @@ static _XTranslateUnicodePairReverse _unicode_to_xkeysym[_UNICODE_MAX] = {
KeySym KeyMappingX11::get_keysym_from_unicode(unsigned int p_unicode) {
/* Latin 1 */
- if (p_unicode >= 0x20 && p_unicode <= 0x7e)
+ if (p_unicode >= 0x20 && p_unicode <= 0x7e) {
return p_unicode;
+ }
- if (p_unicode >= 0xa0 && p_unicode <= 0xff)
+ if (p_unicode >= 0xa0 && p_unicode <= 0xff) {
return p_unicode;
+ }
int middle, low = 0, high = _UNICODE_MAX - 1;
do {
middle = (high + low) / 2;
- if (_unicode_to_xkeysym[middle].keysym == p_unicode)
+ if (_unicode_to_xkeysym[middle].keysym == p_unicode) {
return _unicode_to_xkeysym[middle].keysym;
- if (_unicode_to_xkeysym[middle].keysym <= p_unicode)
+ }
+ if (_unicode_to_xkeysym[middle].keysym <= p_unicode) {
low = middle + 1;
- else
+ } else {
high = middle - 1;
+ }
} while (high >= low);
// if not found, let's hope X understands it as unicode
diff --git a/platform/linuxbsd/os_linuxbsd.cpp b/platform/linuxbsd/os_linuxbsd.cpp
index 7c7a27add0..09a5eca914 100644
--- a/platform/linuxbsd/os_linuxbsd.cpp
+++ b/platform/linuxbsd/os_linuxbsd.cpp
@@ -81,8 +81,9 @@ String OS_LinuxBSD::get_unique_id() const {
}
void OS_LinuxBSD::finalize() {
- if (main_loop)
+ if (main_loop) {
memdelete(main_loop);
+ }
main_loop = nullptr;
#ifdef ALSAMIDI_ENABLED
@@ -99,8 +100,9 @@ MainLoop *OS_LinuxBSD::get_main_loop() const {
}
void OS_LinuxBSD::delete_main_loop() {
- if (main_loop)
+ if (main_loop) {
memdelete(main_loop);
+ }
main_loop = nullptr;
}
@@ -125,11 +127,13 @@ Error OS_LinuxBSD::shell_open(String p_uri) {
List<String> args;
args.push_back(p_uri);
ok = execute("xdg-open", args, false);
- if (ok == OK)
+ if (ok == OK) {
return OK;
+ }
ok = execute("gnome-open", args, false);
- if (ok == OK)
+ if (ok == OK) {
return OK;
+ }
ok = execute("kde-open", args, false);
return ok;
}
@@ -209,16 +213,18 @@ String OS_LinuxBSD::get_system_dir(SystemDir p_dir) const {
List<String> arg;
arg.push_back(xdgparam);
Error err = const_cast<OS_LinuxBSD *>(this)->execute("xdg-user-dir", arg, true, nullptr, &pipe);
- if (err != OK)
+ if (err != OK) {
return ".";
+ }
return pipe.strip_edges();
}
void OS_LinuxBSD::run() {
force_quit = false;
- if (!main_loop)
+ if (!main_loop) {
return;
+ }
main_loop->init();
@@ -232,8 +238,9 @@ void OS_LinuxBSD::run() {
#ifdef JOYDEV_ENABLED
joypad->process_joypads();
#endif
- if (Main::iteration())
+ if (Main::iteration()) {
break;
+ }
};
main_loop->finish();
diff --git a/platform/osx/export/export.cpp b/platform/osx/export/export.cpp
index 24c80dccf5..b2ef9c0038 100644
--- a/platform/osx/export/export.cpp
+++ b/platform/osx/export/export.cpp
@@ -451,10 +451,11 @@ Error EditorExportPlatformOSX::export_project(const Ref<EditorExportPreset> &p_p
EditorProgress ep("export", "Exporting for OSX", 3, true);
- if (p_debug)
+ if (p_debug) {
src_pkg_name = p_preset->get("custom_template/debug");
- else
+ } else {
src_pkg_name = p_preset->get("custom_template/release");
+ }
if (src_pkg_name == "") {
String err;
@@ -487,12 +488,13 @@ Error EditorExportPlatformOSX::export_project(const Ref<EditorExportPreset> &p_p
String binary_to_use = "godot_osx_" + String(p_debug ? "debug" : "release") + ".64";
String pkg_name;
- if (p_preset->get("application/name") != "")
+ if (p_preset->get("application/name") != "") {
pkg_name = p_preset->get("application/name"); // app_name
- else if (String(ProjectSettings::get_singleton()->get("application/config/name")) != "")
+ } else if (String(ProjectSettings::get_singleton()->get("application/config/name")) != "") {
pkg_name = String(ProjectSettings::get_singleton()->get("application/config/name"));
- else
+ } else {
pkg_name = "Unnamed";
+ }
String pkg_name_safe = OS::get_singleton()->get_safe_dir_name(pkg_name);
@@ -580,10 +582,11 @@ Error EditorExportPlatformOSX::export_project(const Ref<EditorExportPreset> &p_p
if (file == "Contents/Resources/icon.icns") {
//see if there is an icon
String iconpath;
- if (p_preset->get("application/icon") != "")
+ if (p_preset->get("application/icon") != "") {
iconpath = p_preset->get("application/icon");
- else
+ } else {
iconpath = ProjectSettings::get_singleton()->get("application/config/icon");
+ }
if (iconpath != "") {
if (iconpath.get_extension() == "icns") {
@@ -761,8 +764,9 @@ Error EditorExportPlatformOSX::export_project(const Ref<EditorExportPreset> &p_p
while (true) {
int r = pf->get_buffer(buf, BSIZE);
- if (r <= 0)
+ if (r <= 0) {
break;
+ }
zipWriteInFileInZip(dst_pkg_zip, buf, r);
}
@@ -832,8 +836,9 @@ bool EditorExportPlatformOSX::can_export(const Ref<EditorExportPreset> &p_preset
valid = dvalid || rvalid;
r_missing_templates = !valid;
- if (!err.empty())
+ if (!err.empty()) {
r_error = err;
+ }
return valid;
}
diff --git a/platform/uwp/export/export.cpp b/platform/uwp/export/export.cpp
index 3d099b44ef..db42908f89 100644
--- a/platform/uwp/export/export.cpp
+++ b/platform/uwp/export/export.cpp
@@ -211,8 +211,9 @@ void AppxPackager::make_block_map(const String &p_path) {
for (int j = 0; j < file.hashes.size(); j++) {
tmp_file->store_string("<Block Hash=\"" + file.hashes[j].base64_hash + "\" ");
- if (file.compressed)
+ if (file.compressed) {
tmp_file->store_string("Size=\"" + itos(file.hashes[j].compressed_size) + "\" ");
+ }
tmp_file->store_string("/>");
}
@@ -226,16 +227,17 @@ void AppxPackager::make_block_map(const String &p_path) {
}
String AppxPackager::content_type(String p_extension) {
- if (p_extension == "png")
+ if (p_extension == "png") {
return "image/png";
- else if (p_extension == "jpg")
+ } else if (p_extension == "jpg") {
return "image/jpg";
- else if (p_extension == "xml")
+ } else if (p_extension == "xml") {
return "application/xml";
- else if (p_extension == "exe" || p_extension == "dll")
+ } else if (p_extension == "exe" || p_extension == "dll") {
return "application/x-msdownload";
- else
+ } else {
return "application/octet-stream";
+ }
}
void AppxPackager::make_content_types(const String &p_path) {
@@ -249,8 +251,9 @@ void AppxPackager::make_content_types(const String &p_path) {
for (int i = 0; i < file_metadata.size(); i++) {
String ext = file_metadata[i].name.get_extension();
- if (types.has(ext))
+ if (types.has(ext)) {
continue;
+ }
types[ext] = content_type(ext);
@@ -501,15 +504,17 @@ Error AppxPackager::add_file(String p_file_name, const uint8_t *p_buffer, size_t
//package->store_buffer(strm_out.ptr(), strm.total_out - total_out_before);
int start = file_buffer.size();
file_buffer.resize(file_buffer.size() + bh.compressed_size);
- for (uint64_t i = 0; i < bh.compressed_size; i++)
+ for (uint64_t i = 0; i < bh.compressed_size; i++) {
file_buffer.write[start + i] = strm_out[i];
+ }
} else {
bh.compressed_size = block_size;
//package->store_buffer(strm_in.ptr(), block_size);
int start = file_buffer.size();
file_buffer.resize(file_buffer.size() + block_size);
- for (uint64_t i = 0; i < bh.compressed_size; i++)
+ for (uint64_t i = 0; i < bh.compressed_size; i++) {
file_buffer.write[start + i] = strm_in[i];
+ }
}
meta.hashes.push_back(bh);
@@ -530,8 +535,9 @@ Error AppxPackager::add_file(String p_file_name, const uint8_t *p_buffer, size_t
//package->store_buffer(strm_out.ptr(), strm.total_out - total_out_before);
int start = file_buffer.size();
file_buffer.resize(file_buffer.size() + (strm.total_out - total_out_before));
- for (uint64_t i = 0; i < (strm.total_out - total_out_before); i++)
+ for (uint64_t i = 0; i < (strm.total_out - total_out_before); i++) {
file_buffer.write[start + i] = strm_out[i];
+ }
deflateEnd(&strm);
meta.compressed_size = strm.total_out;
@@ -636,10 +642,12 @@ class EditorExportPlatformUWP : public EditorExportPlatform {
};
bool _valid_resource_name(const String &p_name) const {
- if (p_name.empty())
+ if (p_name.empty()) {
return false;
- if (p_name.ends_with("."))
+ }
+ if (p_name.ends_with(".")) {
return false;
+ }
static const char *invalid_names[] = {
"CON", "PRN", "AUX", "NUL", "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7",
@@ -649,8 +657,9 @@ class EditorExportPlatformUWP : public EditorExportPlatform {
const char **t = invalid_names;
while (*t) {
- if (p_name == *t)
+ if (p_name == *t) {
return false;
+ }
t++;
}
@@ -660,24 +669,31 @@ class EditorExportPlatformUWP : public EditorExportPlatform {
bool _valid_guid(const String &p_guid) const {
Vector<String> parts = p_guid.split("-");
- if (parts.size() != 5)
+ if (parts.size() != 5) {
return false;
- if (parts[0].length() != 8)
+ }
+ if (parts[0].length() != 8) {
return false;
- for (int i = 1; i < 4; i++)
- if (parts[i].length() != 4)
+ }
+ for (int i = 1; i < 4; i++) {
+ if (parts[i].length() != 4) {
return false;
- if (parts[4].length() != 12)
+ }
+ }
+ if (parts[4].length() != 12) {
return false;
+ }
return true;
}
bool _valid_bgcolor(const String &p_color) const {
- if (p_color.empty())
+ if (p_color.empty()) {
return true;
- if (p_color.begins_with("#") && p_color.is_valid_html_color())
+ }
+ if (p_color.begins_with("#") && p_color.is_valid_html_color()) {
return true;
+ }
// Colors from https://msdn.microsoft.com/en-us/library/windows/apps/dn934817.aspx
static const char *valid_colors[] = {
@@ -711,8 +727,9 @@ class EditorExportPlatformUWP : public EditorExportPlatform {
const char **color = valid_colors;
while (*color) {
- if (p_color == *color)
+ if (p_color == *color) {
return true;
+ }
color++;
}
@@ -734,10 +751,12 @@ class EditorExportPlatformUWP : public EditorExportPlatform {
int w = ceil(p_width * scales[i]);
int h = ceil(p_height * scales[i]);
- if (w == p_image->get_width())
+ if (w == p_image->get_width()) {
valid_w = true;
- if (h == p_image->get_height())
+ }
+ if (h == p_image->get_height()) {
valid_h = true;
+ }
}
return valid_w && valid_h;
@@ -844,8 +863,9 @@ class EditorExportPlatformUWP : public EditorExportPlatform {
Vector<uint8_t> r_ret;
r_ret.resize(result.length());
- for (int i = 0; i < result.length(); i++)
+ for (int i = 0; i < result.length(); i++) {
r_ret.write[i] = result.utf8().get(i);
+ }
return r_ret;
}
@@ -872,8 +892,9 @@ class EditorExportPlatformUWP : public EditorExportPlatform {
ERR_PRINT("Unable to load logo");
}
- if (!image)
+ if (!image) {
return data;
+ }
String tmp_path = EditorSettings::get_singleton()->get_cache_dir().plus_file("uwp_tmp_logo.png");
@@ -908,15 +929,15 @@ class EditorExportPlatformUWP : public EditorExportPlatform {
static bool _should_compress_asset(const String &p_path, const Vector<uint8_t> &p_data) {
/* TODO: This was copied verbatim from Android export. It should be
- * refactored to the parent class and also be used for .zip export.
- */
+ * refactored to the parent class and also be used for .zip export.
+ */
/*
- * By not compressing files with little or not benefit in doing so,
- * a performance gain is expected at runtime. Moreover, if the APK is
- * zip-aligned, assets stored as they are can be efficiently read by
- * Android by memory-mapping them.
- */
+ * By not compressing files with little or not benefit in doing so,
+ * a performance gain is expected at runtime. Moreover, if the APK is
+ * zip-aligned, assets stored as they are can be efficiently read by
+ * Android by memory-mapping them.
+ */
// -- Unconditional uncompress to mimic AAPT plus some other
@@ -1177,10 +1198,11 @@ public:
EditorProgress ep("export", "Exporting for Windows Universal", 7, true);
- if (p_debug)
+ if (p_debug) {
src_appx = p_preset->get("custom_template/debug");
- else
+ } else {
src_appx = p_preset->get("custom_template/release");
+ }
src_appx = src_appx.strip_edges();
@@ -1269,8 +1291,9 @@ public:
path = path.replace(".scale-100", "");
data = _get_image_data(p_preset, path);
- if (data.size() > 0)
+ if (data.size() > 0) {
do_read = false;
+ }
}
//read
diff --git a/scene/2d/animated_sprite_2d.cpp b/scene/2d/animated_sprite_2d.cpp
index 54477758f4..3268544519 100644
--- a/scene/2d/animated_sprite_2d.cpp
+++ b/scene/2d/animated_sprite_2d.cpp
@@ -70,8 +70,9 @@ bool AnimatedSprite2D::_edit_use_rect() const {
return false;
}
Ref<Texture2D> t;
- if (animation)
+ if (animation) {
t = frames->get_frame(animation, frame);
+ }
return t.is_valid();
}
#endif
@@ -86,18 +87,22 @@ Rect2 AnimatedSprite2D::_get_rect() const {
}
Ref<Texture2D> t;
- if (animation)
+ if (animation) {
t = frames->get_frame(animation, frame);
- if (t.is_null())
+ }
+ if (t.is_null()) {
return Rect2();
+ }
Size2 s = t->get_size();
Point2 ofs = offset;
- if (centered)
+ if (centered) {
ofs -= Size2(s) / 2;
+ }
- if (s == Size2(0, 0))
+ if (s == Size2(0, 0)) {
s = Size2(1, 1);
+ }
return Rect2(ofs, s);
}
@@ -106,10 +111,11 @@ void SpriteFrames::add_frame(const StringName &p_anim, const Ref<Texture2D> &p_f
Map<StringName, Anim>::Element *E = animations.find(p_anim);
ERR_FAIL_COND_MSG(!E, "Animation '" + String(p_anim) + "' doesn't exist.");
- if (p_at_pos >= 0 && p_at_pos < E->get().frames.size())
+ if (p_at_pos >= 0 && p_at_pos < E->get().frames.size()) {
E->get().frames.insert(p_at_pos, p_frame);
- else
+ } else {
E->get().frames.push_back(p_frame);
+ }
emit_changed();
}
@@ -226,8 +232,9 @@ void SpriteFrames::_set_frames(const Array &p_frames) {
ERR_FAIL_COND(!E);
E->get().frames.resize(p_frames.size());
- for (int i = 0; i < E->get().frames.size(); i++)
+ for (int i = 0; i < E->get().frames.size(); i++) {
E->get().frames.write[i] = p_frames[i];
+ }
}
Array SpriteFrames::_get_frames() const {
@@ -313,8 +320,9 @@ SpriteFrames::SpriteFrames() {
}
void AnimatedSprite2D::_validate_property(PropertyInfo &property) const {
- if (!frames.is_valid())
+ if (!frames.is_valid()) {
return;
+ }
if (property.name == "animation") {
property.hint = PROPERTY_HINT_ENUM;
List<StringName> names;
@@ -355,16 +363,20 @@ void AnimatedSprite2D::_validate_property(PropertyInfo &property) const {
void AnimatedSprite2D::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_INTERNAL_PROCESS: {
- if (frames.is_null())
+ if (frames.is_null()) {
return;
- if (!frames->has_animation(animation))
+ }
+ if (!frames->has_animation(animation)) {
return;
- if (frame < 0)
+ }
+ if (frame < 0) {
return;
+ }
float speed = frames->get_animation_speed(animation) * speed_scale;
- if (speed == 0)
+ if (speed == 0) {
return; //do nothing
+ }
float remaining = get_process_delta_time();
@@ -375,17 +387,19 @@ void AnimatedSprite2D::_notification(int p_what) {
int fc = frames->get_frame_count(animation);
if ((!backwards && frame >= fc - 1) || (backwards && frame <= 0)) {
if (frames->get_animation_loop(animation)) {
- if (backwards)
+ if (backwards) {
frame = fc - 1;
- else
+ } else {
frame = 0;
+ }
emit_signal(SceneStringNames::get_singleton()->animation_finished);
} else {
- if (backwards)
+ if (backwards) {
frame = 0;
- else
+ } else {
frame = fc - 1;
+ }
if (!is_over) {
is_over = true;
@@ -393,10 +407,11 @@ void AnimatedSprite2D::_notification(int p_what) {
}
}
} else {
- if (backwards)
+ if (backwards) {
frame--;
- else
+ } else {
frame++;
+ }
}
update();
@@ -411,16 +426,20 @@ void AnimatedSprite2D::_notification(int p_what) {
} break;
case NOTIFICATION_DRAW: {
- if (frames.is_null())
+ if (frames.is_null()) {
return;
- if (frame < 0)
+ }
+ if (frame < 0) {
return;
- if (!frames->has_animation(animation))
+ }
+ if (!frames->has_animation(animation)) {
return;
+ }
Ref<Texture2D> texture = frames->get_frame(animation, frame);
- if (texture.is_null())
+ if (texture.is_null()) {
return;
+ }
Ref<Texture2D> normal = frames->get_normal_frame(animation, frame);
Ref<Texture2D> specular = frames->get_specular_frame(animation, frame);
@@ -430,18 +449,21 @@ void AnimatedSprite2D::_notification(int p_what) {
Size2i s;
s = texture->get_size();
Point2 ofs = offset;
- if (centered)
+ if (centered) {
ofs -= s / 2;
+ }
if (Engine::get_singleton()->get_use_pixel_snap()) {
ofs = ofs.floor();
}
Rect2 dst_rect(ofs, s);
- if (hflip)
+ if (hflip) {
dst_rect.size.x = -dst_rect.size.x;
- if (vflip)
+ }
+ if (vflip) {
dst_rect.size.y = -dst_rect.size.y;
+ }
texture->draw_rect_region(ci, dst_rect, Rect2(Vector2(), texture->get_size()), Color(1, 1, 1), false, normal, specular, Color(specular_color.r, specular_color.g, specular_color.b, shininess));
@@ -450,11 +472,13 @@ void AnimatedSprite2D::_notification(int p_what) {
}
void AnimatedSprite2D::set_sprite_frames(const Ref<SpriteFrames> &p_frames) {
- if (frames.is_valid())
+ if (frames.is_valid()) {
frames->disconnect("changed", callable_mp(this, &AnimatedSprite2D::_res_changed));
+ }
frames = p_frames;
- if (frames.is_valid())
+ if (frames.is_valid()) {
frames->connect("changed", callable_mp(this, &AnimatedSprite2D::_res_changed));
+ }
if (!frames.is_valid()) {
frame = 0;
@@ -479,15 +503,18 @@ void AnimatedSprite2D::set_frame(int p_frame) {
if (frames->has_animation(animation)) {
int limit = frames->get_frame_count(animation);
- if (p_frame >= limit)
+ if (p_frame >= limit) {
p_frame = limit - 1;
+ }
}
- if (p_frame < 0)
+ if (p_frame < 0) {
p_frame = 0;
+ }
- if (frame == p_frame)
+ if (frame == p_frame) {
return;
+ }
frame = p_frame;
_reset_timeout();
@@ -561,8 +588,9 @@ void AnimatedSprite2D::_res_changed() {
}
void AnimatedSprite2D::_set_playing(bool p_playing) {
- if (playing == p_playing)
+ if (playing == p_playing) {
return;
+ }
playing = p_playing;
_reset_timeout();
set_process_internal(playing);
@@ -577,8 +605,9 @@ void AnimatedSprite2D::play(const StringName &p_animation, const bool p_backward
if (p_animation) {
set_animation(p_animation);
- if (backwards && get_frame() == 0)
+ if (backwards && get_frame() == 0) {
set_frame(frames->get_frame_count(p_animation) - 1);
+ }
}
_set_playing(true);
@@ -603,8 +632,9 @@ float AnimatedSprite2D::_get_frame_duration() {
}
void AnimatedSprite2D::_reset_timeout() {
- if (!playing)
+ if (!playing) {
return;
+ }
timeout = _get_frame_duration();
is_over = false;
@@ -614,8 +644,9 @@ void AnimatedSprite2D::set_animation(const StringName &p_animation) {
ERR_FAIL_COND_MSG(frames == nullptr, vformat("There is no animation with name '%s'.", p_animation));
ERR_FAIL_COND_MSG(frames->get_animation_names().find(p_animation) == -1, vformat("There is no animation with name '%s'.", p_animation));
- if (animation == p_animation)
+ if (animation == p_animation) {
return;
+ }
animation = p_animation;
_reset_timeout();
diff --git a/scene/2d/animated_sprite_2d.h b/scene/2d/animated_sprite_2d.h
index fae334498d..5e8344ec4c 100644
--- a/scene/2d/animated_sprite_2d.h
+++ b/scene/2d/animated_sprite_2d.h
@@ -88,8 +88,9 @@ public:
const Map<StringName, Anim>::Element *E = animations.find(p_anim);
ERR_FAIL_COND_V_MSG(!E, Ref<Texture2D>(), "Animation '" + String(p_anim) + "' doesn't exist.");
ERR_FAIL_COND_V(p_idx < 0, Ref<Texture2D>());
- if (p_idx >= E->get().frames.size())
+ if (p_idx >= E->get().frames.size()) {
return Ref<Texture2D>();
+ }
return E->get().frames[p_idx];
}
@@ -101,8 +102,9 @@ public:
const Map<StringName, Anim>::Element *EN = animations.find(E->get().normal_name);
- if (!EN || p_idx >= EN->get().frames.size())
+ if (!EN || p_idx >= EN->get().frames.size()) {
return Ref<Texture2D>();
+ }
return EN->get().frames[p_idx];
}
@@ -114,8 +116,9 @@ public:
const Map<StringName, Anim>::Element *EN = animations.find(E->get().specular_name);
- if (!EN || p_idx >= EN->get().frames.size())
+ if (!EN || p_idx >= EN->get().frames.size()) {
return Ref<Texture2D>();
+ }
return EN->get().frames[p_idx];
}
@@ -124,8 +127,9 @@ public:
Map<StringName, Anim>::Element *E = animations.find(p_anim);
ERR_FAIL_COND_MSG(!E, "Animation '" + String(p_anim) + "' doesn't exist.");
ERR_FAIL_COND(p_idx < 0);
- if (p_idx >= E->get().frames.size())
+ if (p_idx >= E->get().frames.size()) {
return;
+ }
E->get().frames.write[p_idx] = p_frame;
}
void remove_frame(const StringName &p_anim, int p_idx);
diff --git a/scene/2d/area_2d.cpp b/scene/2d/area_2d.cpp
index 9a3b6c2611..ebfcb9cad6 100644
--- a/scene/2d/area_2d.cpp
+++ b/scene/2d/area_2d.cpp
@@ -165,8 +165,9 @@ void Area2D::_body_inout(int p_status, const RID &p_body, ObjectID p_instance, i
}
}
E->get().rc++;
- if (node)
+ if (node) {
E->get().shapes.insert(ShapePair(p_body_shape, p_area_shape));
+ }
if (!node || E->get().in_tree) {
emit_signal(SceneStringNames::get_singleton()->body_shape_entered, objid, node, p_body_shape, p_area_shape);
@@ -175,8 +176,9 @@ void Area2D::_body_inout(int p_status, const RID &p_body, ObjectID p_instance, i
} else {
E->get().rc--;
- if (node)
+ if (node) {
E->get().shapes.erase(ShapePair(p_body_shape, p_area_shape));
+ }
bool eraseit = false;
@@ -184,8 +186,9 @@ void Area2D::_body_inout(int p_status, const RID &p_body, ObjectID p_instance, i
if (node) {
node->disconnect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &Area2D::_body_enter_tree));
node->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &Area2D::_body_exit_tree));
- if (E->get().in_tree)
+ if (E->get().in_tree) {
emit_signal(SceneStringNames::get_singleton()->body_exited, obj);
+ }
}
eraseit = true;
@@ -194,8 +197,9 @@ void Area2D::_body_inout(int p_status, const RID &p_body, ObjectID p_instance, i
emit_signal(SceneStringNames::get_singleton()->body_shape_exited, objid, obj, p_body_shape, p_area_shape);
}
- if (eraseit)
+ if (eraseit) {
body_map.erase(E);
+ }
}
locked = false;
@@ -259,8 +263,9 @@ void Area2D::_area_inout(int p_status, const RID &p_area, ObjectID p_instance, i
}
}
E->get().rc++;
- if (node)
+ if (node) {
E->get().shapes.insert(AreaShapePair(p_area_shape, p_self_shape));
+ }
if (!node || E->get().in_tree) {
emit_signal(SceneStringNames::get_singleton()->area_shape_entered, objid, node, p_area_shape, p_self_shape);
@@ -269,8 +274,9 @@ void Area2D::_area_inout(int p_status, const RID &p_area, ObjectID p_instance, i
} else {
E->get().rc--;
- if (node)
+ if (node) {
E->get().shapes.erase(AreaShapePair(p_area_shape, p_self_shape));
+ }
bool eraseit = false;
@@ -278,8 +284,9 @@ void Area2D::_area_inout(int p_status, const RID &p_area, ObjectID p_instance, i
if (node) {
node->disconnect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &Area2D::_area_enter_tree));
node->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &Area2D::_area_exit_tree));
- if (E->get().in_tree)
+ if (E->get().in_tree) {
emit_signal(SceneStringNames::get_singleton()->area_exited, obj);
+ }
}
eraseit = true;
@@ -288,8 +295,9 @@ void Area2D::_area_inout(int p_status, const RID &p_area, ObjectID p_instance, i
emit_signal(SceneStringNames::get_singleton()->area_shape_exited, objid, obj, p_area_shape, p_self_shape);
}
- if (eraseit)
+ if (eraseit) {
area_map.erase(E);
+ }
}
locked = false;
@@ -307,14 +315,16 @@ void Area2D::_clear_monitoring() {
Object *obj = ObjectDB::get_instance(E->key());
Node *node = Object::cast_to<Node>(obj);
- if (!node) //node may have been deleted in previous frame or at other legitimate point
+ if (!node) { //node may have been deleted in previous frame or at other legitimate point
continue;
+ }
node->disconnect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &Area2D::_body_enter_tree));
node->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &Area2D::_body_exit_tree));
- if (!E->get().in_tree)
+ if (!E->get().in_tree) {
continue;
+ }
for (int i = 0; i < E->get().shapes.size(); i++) {
emit_signal(SceneStringNames::get_singleton()->body_shape_exited, E->key(), node, E->get().shapes[i].body_shape, E->get().shapes[i].area_shape);
@@ -333,14 +343,16 @@ void Area2D::_clear_monitoring() {
Object *obj = ObjectDB::get_instance(E->key());
Node *node = Object::cast_to<Node>(obj);
- if (!node) //node may have been deleted in previous frame or at other legitimate point
+ if (!node) { //node may have been deleted in previous frame or at other legitimate point
continue;
+ }
node->disconnect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &Area2D::_area_enter_tree));
node->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &Area2D::_area_exit_tree));
- if (!E->get().in_tree)
+ if (!E->get().in_tree) {
continue;
+ }
for (int i = 0; i < E->get().shapes.size(); i++) {
emit_signal(SceneStringNames::get_singleton()->area_shape_exited, E->key(), node, E->get().shapes[i].area_shape, E->get().shapes[i].self_shape);
@@ -360,8 +372,9 @@ void Area2D::_notification(int p_what) {
}
void Area2D::set_monitoring(bool p_enable) {
- if (p_enable == monitoring)
+ if (p_enable == monitoring) {
return;
+ }
ERR_FAIL_COND_MSG(locked, "Function blocked during in/out signal. Use set_deferred(\"monitoring\", true/false).");
monitoring = p_enable;
@@ -384,8 +397,9 @@ bool Area2D::is_monitoring() const {
void Area2D::set_monitorable(bool p_enable) {
ERR_FAIL_COND_MSG(locked || (is_inside_tree() && PhysicsServer2D::get_singleton()->is_flushing_queries()), "Function blocked during in/out signal. Use set_deferred(\"monitorable\", true/false).");
- if (p_enable == monitorable)
+ if (p_enable == monitorable) {
return;
+ }
monitorable = p_enable;
@@ -433,16 +447,18 @@ TypedArray<Area2D> Area2D::get_overlapping_areas() const {
bool Area2D::overlaps_area(Node *p_area) const {
ERR_FAIL_NULL_V(p_area, false);
const Map<ObjectID, AreaState>::Element *E = area_map.find(p_area->get_instance_id());
- if (!E)
+ if (!E) {
return false;
+ }
return E->get().in_tree;
}
bool Area2D::overlaps_body(Node *p_body) const {
ERR_FAIL_NULL_V(p_body, false);
const Map<ObjectID, BodyState>::Element *E = body_map.find(p_body->get_instance_id());
- if (!E)
+ if (!E) {
return false;
+ }
return E->get().in_tree;
}
@@ -466,10 +482,11 @@ uint32_t Area2D::get_collision_layer() const {
void Area2D::set_collision_mask_bit(int p_bit, bool p_value) {
uint32_t mask = get_collision_mask();
- if (p_value)
+ if (p_value) {
mask |= 1 << p_bit;
- else
+ } else {
mask &= ~(1 << p_bit);
+ }
set_collision_mask(mask);
}
@@ -479,10 +496,11 @@ bool Area2D::get_collision_mask_bit(int p_bit) const {
void Area2D::set_collision_layer_bit(int p_bit, bool p_value) {
uint32_t layer = get_collision_layer();
- if (p_value)
+ if (p_value) {
layer |= 1 << p_bit;
- else
+ } else {
layer &= ~(1 << p_bit);
+ }
set_collision_layer(layer);
}
@@ -515,8 +533,9 @@ void Area2D::_validate_property(PropertyInfo &property) const {
if (property.name == "audio_bus_name") {
String options;
for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) {
- if (i > 0)
+ if (i > 0) {
options += ",";
+ }
String name = AudioServer::get_singleton()->get_bus_name(i);
options += name;
}
diff --git a/scene/2d/area_2d.h b/scene/2d/area_2d.h
index 3b9b57cab4..0d0293dd12 100644
--- a/scene/2d/area_2d.h
+++ b/scene/2d/area_2d.h
@@ -70,10 +70,11 @@ private:
int body_shape;
int area_shape;
bool operator<(const ShapePair &p_sp) const {
- if (body_shape == p_sp.body_shape)
+ if (body_shape == p_sp.body_shape) {
return area_shape < p_sp.area_shape;
- else
+ } else {
return body_shape < p_sp.body_shape;
+ }
}
ShapePair() {}
@@ -100,10 +101,11 @@ private:
int area_shape;
int self_shape;
bool operator<(const AreaShapePair &p_sp) const {
- if (area_shape == p_sp.area_shape)
+ if (area_shape == p_sp.area_shape) {
return self_shape < p_sp.self_shape;
- else
+ } else {
return area_shape < p_sp.area_shape;
+ }
}
AreaShapePair() {}
diff --git a/scene/2d/audio_stream_player_2d.cpp b/scene/2d/audio_stream_player_2d.cpp
index eca48406ce..5b89ac15b1 100644
--- a/scene/2d/audio_stream_player_2d.cpp
+++ b/scene/2d/audio_stream_player_2d.cpp
@@ -90,8 +90,9 @@ void AudioStreamPlayer2D::_mix_audio() {
int cc = AudioServer::get_singleton()->get_channel_count();
if (cc == 1) {
- if (!AudioServer::get_singleton()->thread_has_channel_mix_buffer(current.bus_index, 0))
+ if (!AudioServer::get_singleton()->thread_has_channel_mix_buffer(current.bus_index, 0)) {
continue; //may have been removed
+ }
AudioFrame *target = AudioServer::get_singleton()->thread_get_channel_mix_buffer(current.bus_index, 0);
@@ -113,8 +114,9 @@ void AudioStreamPlayer2D::_mix_audio() {
targets[k] = AudioServer::get_singleton()->thread_get_channel_mix_buffer(current.bus_index, k);
}
- if (!valid)
+ if (!valid) {
continue;
+ }
for (int j = 0; j < buffer_size; j++) {
AudioFrame frame = buffer[j] * vol;
@@ -187,11 +189,13 @@ void AudioStreamPlayer2D::_notification(int p_what) {
for (int i = 0; i < areas; i++) {
Area2D *area2d = Object::cast_to<Area2D>(sr[i].collider);
- if (!area2d)
+ if (!area2d) {
continue;
+ }
- if (!area2d->is_overriding_audio_bus())
+ if (!area2d->is_overriding_audio_bus()) {
continue;
+ }
StringName bus_name = area2d->get_audio_bus_name();
bus_index = AudioServer::get_singleton()->thread_find_bus_index(bus_name);
@@ -211,8 +215,9 @@ void AudioStreamPlayer2D::_notification(int p_what) {
float dist = global_pos.distance_to(screen_in_global); //distance to screen center
- if (dist > max_distance)
+ if (dist > max_distance) {
continue; //can't hear this sound in this viewport
+ }
float multiplier = Math::pow(1.0f - dist / max_distance, attenuation);
multiplier *= Math::db2linear(volume_db); //also apply player volume!
@@ -229,8 +234,9 @@ void AudioStreamPlayer2D::_notification(int p_what) {
outputs[new_output_count].bus_index = bus_index;
outputs[new_output_count].viewport = vp; //keep pointer only for reference
new_output_count++;
- if (new_output_count == MAX_OUTPUTS)
+ if (new_output_count == MAX_OUTPUTS) {
break;
+ }
}
}
@@ -371,10 +377,11 @@ bool AudioStreamPlayer2D::is_autoplay_enabled() {
}
void AudioStreamPlayer2D::_set_playing(bool p_enable) {
- if (p_enable)
+ if (p_enable) {
play();
- else
+ } else {
stop();
+ }
}
bool AudioStreamPlayer2D::_is_active() const {
@@ -385,8 +392,9 @@ void AudioStreamPlayer2D::_validate_property(PropertyInfo &property) const {
if (property.name == "bus") {
String options;
for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) {
- if (i > 0)
+ if (i > 0) {
options += ",";
+ }
String name = AudioServer::get_singleton()->get_bus_name(i);
options += name;
}
diff --git a/scene/2d/camera_2d.cpp b/scene/2d/camera_2d.cpp
index fc691c9ca6..8f69676da4 100644
--- a/scene/2d/camera_2d.cpp
+++ b/scene/2d/camera_2d.cpp
@@ -36,16 +36,18 @@
#include "servers/rendering_server.h"
void Camera2D::_update_scroll() {
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
if (Engine::get_singleton()->is_editor_hint()) {
update(); //will just be drawn
return;
}
- if (!viewport)
+ if (!viewport) {
return;
+ }
if (current) {
ERR_FAIL_COND(custom_viewport && !ObjectDB::get_instance(custom_viewport_id));
@@ -86,8 +88,9 @@ Vector2 Camera2D::get_zoom() const {
};
Transform2D Camera2D::get_camera_transform() {
- if (!get_tree())
+ if (!get_tree()) {
return Transform2D();
+ }
ERR_FAIL_COND_V(custom_viewport && !ObjectDB::get_instance(custom_viewport_id), Transform2D());
@@ -133,17 +136,21 @@ Transform2D Camera2D::get_camera_transform() {
Rect2 screen_rect(-screen_offset + camera_pos, screen_size * zoom);
if (limit_smoothing_enabled) {
- if (screen_rect.position.x < limit[MARGIN_LEFT])
+ if (screen_rect.position.x < limit[MARGIN_LEFT]) {
camera_pos.x -= screen_rect.position.x - limit[MARGIN_LEFT];
+ }
- if (screen_rect.position.x + screen_rect.size.x > limit[MARGIN_RIGHT])
+ if (screen_rect.position.x + screen_rect.size.x > limit[MARGIN_RIGHT]) {
camera_pos.x -= screen_rect.position.x + screen_rect.size.x - limit[MARGIN_RIGHT];
+ }
- if (screen_rect.position.y + screen_rect.size.y > limit[MARGIN_BOTTOM])
+ if (screen_rect.position.y + screen_rect.size.y > limit[MARGIN_BOTTOM]) {
camera_pos.y -= screen_rect.position.y + screen_rect.size.y - limit[MARGIN_BOTTOM];
+ }
- if (screen_rect.position.y < limit[MARGIN_TOP])
+ if (screen_rect.position.y < limit[MARGIN_TOP]) {
camera_pos.y -= screen_rect.position.y - limit[MARGIN_TOP];
+ }
}
if (smoothing_enabled && !Engine::get_singleton()->is_editor_hint()) {
@@ -168,20 +175,25 @@ Transform2D Camera2D::get_camera_transform() {
}
Rect2 screen_rect(-screen_offset + ret_camera_pos, screen_size * zoom);
- if (screen_rect.position.x < limit[MARGIN_LEFT])
+ if (screen_rect.position.x < limit[MARGIN_LEFT]) {
screen_rect.position.x = limit[MARGIN_LEFT];
+ }
- if (screen_rect.position.x + screen_rect.size.x > limit[MARGIN_RIGHT])
+ if (screen_rect.position.x + screen_rect.size.x > limit[MARGIN_RIGHT]) {
screen_rect.position.x = limit[MARGIN_RIGHT] - screen_rect.size.x;
+ }
- if (screen_rect.position.y + screen_rect.size.y > limit[MARGIN_BOTTOM])
+ if (screen_rect.position.y + screen_rect.size.y > limit[MARGIN_BOTTOM]) {
screen_rect.position.y = limit[MARGIN_BOTTOM] - screen_rect.size.y;
+ }
- if (screen_rect.position.y < limit[MARGIN_TOP])
+ if (screen_rect.position.y < limit[MARGIN_TOP]) {
screen_rect.position.y = limit[MARGIN_TOP];
+ }
- if (offset != Vector2())
+ if (offset != Vector2()) {
screen_rect.position += offset;
+ }
camera_screen_center = screen_rect.position + screen_rect.size * 0.5;
@@ -211,8 +223,9 @@ void Camera2D::_notification(int p_what) {
} break;
case NOTIFICATION_TRANSFORM_CHANGED: {
- if (!is_processing_internal() && !is_physics_processing_internal())
+ if (!is_processing_internal() && !is_physics_processing_internal()) {
_update_scroll();
+ }
} break;
case NOTIFICATION_ENTER_TREE: {
@@ -248,8 +261,9 @@ void Camera2D::_notification(int p_what) {
} break;
case NOTIFICATION_DRAW: {
- if (!is_inside_tree() || !Engine::get_singleton()->is_editor_hint())
+ if (!is_inside_tree() || !Engine::get_singleton()->is_editor_hint()) {
break;
+ }
if (screen_drawing_enabled) {
Color area_axis_color(0.5, 0.42, 0.87, 0.63);
@@ -355,8 +369,9 @@ bool Camera2D::is_rotating() const {
}
void Camera2D::set_process_mode(Camera2DProcessMode p_mode) {
- if (process_mode == p_mode)
+ if (process_mode == p_mode) {
return;
+ }
process_mode = p_mode;
_update_process_mode();
@@ -375,8 +390,9 @@ void Camera2D::_make_current(Object *p_which) {
}
void Camera2D::_set_current(bool p_current) {
- if (p_current)
+ if (p_current) {
make_current();
+ }
current = p_current;
update();
@@ -472,10 +488,11 @@ void Camera2D::align() {
void Camera2D::set_follow_smoothing(float p_speed) {
smoothing = p_speed;
- if (smoothing > 0 && !(is_inside_tree() && Engine::get_singleton()->is_editor_hint()))
+ if (smoothing > 0 && !(is_inside_tree() && Engine::get_singleton()->is_editor_hint())) {
set_process_internal(true);
- else
+ } else {
set_process_internal(false);
+ }
}
float Camera2D::get_follow_smoothing() const {
@@ -554,10 +571,11 @@ void Camera2D::set_custom_viewport(Node *p_viewport) {
}
if (is_inside_tree()) {
- if (custom_viewport)
+ if (custom_viewport) {
viewport = custom_viewport;
- else
+ } else {
viewport = get_viewport();
+ }
RID vp = viewport->get_viewport_rid();
group_name = "__cameras_" + itos(vp.get_id());
diff --git a/scene/2d/canvas_modulate.cpp b/scene/2d/canvas_modulate.cpp
index 41db3f771a..56643542a8 100644
--- a/scene/2d/canvas_modulate.cpp
+++ b/scene/2d/canvas_modulate.cpp
@@ -74,8 +74,9 @@ Color CanvasModulate::get_color() const {
}
String CanvasModulate::get_configuration_warning() const {
- if (!is_visible_in_tree() || !is_inside_tree())
+ if (!is_visible_in_tree() || !is_inside_tree()) {
return String();
+ }
List<Node *> nodes;
get_tree()->get_nodes_in_group("_canvas_modulate_" + itos(get_canvas().get_id()), &nodes);
diff --git a/scene/2d/collision_object_2d.cpp b/scene/2d/collision_object_2d.cpp
index aa1c107dea..fe16d4089a 100644
--- a/scene/2d/collision_object_2d.cpp
+++ b/scene/2d/collision_object_2d.cpp
@@ -38,16 +38,18 @@ void CollisionObject2D::_notification(int p_what) {
case NOTIFICATION_ENTER_TREE: {
Transform2D global_transform = get_global_transform();
- if (area)
+ if (area) {
PhysicsServer2D::get_singleton()->area_set_transform(rid, global_transform);
- else
+ } else {
PhysicsServer2D::get_singleton()->body_set_state(rid, PhysicsServer2D::BODY_STATE_TRANSFORM, global_transform);
+ }
RID space = get_world_2d()->get_space();
if (area) {
PhysicsServer2D::get_singleton()->area_set_space(rid, space);
- } else
+ } else {
PhysicsServer2D::get_singleton()->body_set_space(rid, space);
+ }
_update_pickable();
@@ -55,10 +57,11 @@ void CollisionObject2D::_notification(int p_what) {
} break;
case NOTIFICATION_ENTER_CANVAS: {
- if (area)
+ if (area) {
PhysicsServer2D::get_singleton()->area_attach_canvas_instance_id(rid, get_canvas_layer_instance_id());
- else
+ } else {
PhysicsServer2D::get_singleton()->body_attach_canvas_instance_id(rid, get_canvas_layer_instance_id());
+ }
} break;
case NOTIFICATION_VISIBILITY_CHANGED: {
@@ -71,25 +74,28 @@ void CollisionObject2D::_notification(int p_what) {
Transform2D global_transform = get_global_transform();
- if (area)
+ if (area) {
PhysicsServer2D::get_singleton()->area_set_transform(rid, global_transform);
- else
+ } else {
PhysicsServer2D::get_singleton()->body_set_state(rid, PhysicsServer2D::BODY_STATE_TRANSFORM, global_transform);
+ }
} break;
case NOTIFICATION_EXIT_TREE: {
if (area) {
PhysicsServer2D::get_singleton()->area_set_space(rid, RID());
- } else
+ } else {
PhysicsServer2D::get_singleton()->body_set_space(rid, RID());
+ }
} break;
case NOTIFICATION_EXIT_CANVAS: {
- if (area)
+ if (area) {
PhysicsServer2D::get_singleton()->area_attach_canvas_instance_id(rid, ObjectID());
- else
+ } else {
PhysicsServer2D::get_singleton()->body_attach_canvas_instance_id(rid, ObjectID());
+ }
} break;
}
}
@@ -140,8 +146,9 @@ bool CollisionObject2D::is_shape_owner_disabled(uint32_t p_owner) const {
}
void CollisionObject2D::shape_owner_set_one_way_collision(uint32_t p_owner, bool p_enable) {
- if (area)
+ if (area) {
return; //not for areas
+ }
ERR_FAIL_COND(!shapes.has(p_owner));
@@ -159,8 +166,9 @@ bool CollisionObject2D::is_shape_owner_one_way_collision_enabled(uint32_t p_owne
}
void CollisionObject2D::shape_owner_set_one_way_collision_margin(uint32_t p_owner, float p_margin) {
- if (area)
+ if (area) {
return; //not for areas
+ }
ERR_FAIL_COND(!shapes.has(p_owner));
@@ -305,8 +313,9 @@ uint32_t CollisionObject2D::shape_find_owner(int p_shape_index) const {
}
void CollisionObject2D::set_pickable(bool p_enabled) {
- if (pickable == p_enabled)
+ if (pickable == p_enabled) {
return;
+ }
pickable = p_enabled;
_update_pickable();
@@ -342,14 +351,16 @@ void CollisionObject2D::set_only_update_transform_changes(bool p_enable) {
}
void CollisionObject2D::_update_pickable() {
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
bool is_pickable = pickable && is_visible_in_tree();
- if (area)
+ if (area) {
PhysicsServer2D::get_singleton()->area_set_pickable(rid, is_pickable);
- else
+ } else {
PhysicsServer2D::get_singleton()->body_set_pickable(rid, is_pickable);
+ }
}
String CollisionObject2D::get_configuration_warning() const {
diff --git a/scene/2d/collision_polygon_2d.cpp b/scene/2d/collision_polygon_2d.cpp
index ebbda63e7b..4919ef8304 100644
--- a/scene/2d/collision_polygon_2d.cpp
+++ b/scene/2d/collision_polygon_2d.cpp
@@ -40,8 +40,9 @@
void CollisionPolygon2D::_build_polygon() {
parent->shape_owner_clear_shapes(owner_id);
- if (polygon.size() == 0)
+ if (polygon.size() == 0) {
return;
+ }
bool solids = build_mode == BUILD_SOLIDS;
@@ -80,8 +81,9 @@ Vector<Vector<Vector2>> CollisionPolygon2D::_decompose_in_convex() {
void CollisionPolygon2D::_update_in_shape_owner(bool p_xform_only) {
parent->shape_owner_set_transform(owner_id, get_transform());
- if (p_xform_only)
+ if (p_xform_only) {
return;
+ }
parent->shape_owner_set_disabled(owner_id, disabled);
parent->shape_owner_set_one_way_collision(owner_id, one_way_collision);
parent->shape_owner_set_one_way_collision_margin(owner_id, one_way_collision_margin);
@@ -160,8 +162,9 @@ void CollisionPolygon2D::_notification(int p_what) {
pts.push_back(line_to + (Vector2(Math_SQRT12 * tsize, 0)));
pts.push_back(line_to + (Vector2(-Math_SQRT12 * tsize, 0)));
Vector<Color> cols;
- for (int i = 0; i < 3; i++)
+ for (int i = 0; i < 3; i++) {
cols.push_back(dcol);
+ }
draw_primitive(pts, cols, Vector<Vector2>()); //small arrow
}
@@ -174,10 +177,11 @@ void CollisionPolygon2D::set_polygon(const Vector<Point2> &p_polygon) {
{
for (int i = 0; i < polygon.size(); i++) {
- if (i == 0)
+ if (i == 0) {
aabb = Rect2(polygon[i], Size2());
- else
+ } else {
aabb.expand_to(polygon[i]);
+ }
}
if (aabb == Rect2()) {
aabb = Rect2(-10, -10, 20, 20);
diff --git a/scene/2d/collision_shape_2d.cpp b/scene/2d/collision_shape_2d.cpp
index 43c8db18be..88d124536c 100644
--- a/scene/2d/collision_shape_2d.cpp
+++ b/scene/2d/collision_shape_2d.cpp
@@ -46,8 +46,9 @@ void CollisionShape2D::_shape_changed() {
void CollisionShape2D::_update_in_shape_owner(bool p_xform_only) {
parent->shape_owner_set_transform(owner_id, get_transform());
- if (p_xform_only)
+ if (p_xform_only) {
return;
+ }
parent->shape_owner_set_disabled(owner_id, disabled);
parent->shape_owner_set_one_way_collision(owner_id, one_way_collision);
parent->shape_owner_set_one_way_collision_margin(owner_id, one_way_collision_margin);
@@ -129,8 +130,9 @@ void CollisionShape2D::_notification(int p_what) {
pts.push_back(line_to + (Vector2(Math_SQRT12 * tsize, 0)));
pts.push_back(line_to + (Vector2(-Math_SQRT12 * tsize, 0)));
Vector<Color> cols;
- for (int i = 0; i < 3; i++)
+ for (int i = 0; i < 3; i++) {
cols.push_back(draw_col);
+ }
draw_primitive(pts, cols, Vector<Vector2>());
}
@@ -139,8 +141,9 @@ void CollisionShape2D::_notification(int p_what) {
}
void CollisionShape2D::set_shape(const Ref<Shape2D> &p_shape) {
- if (shape.is_valid())
+ if (shape.is_valid()) {
shape->disconnect("changed", callable_mp(this, &CollisionShape2D::_shape_changed));
+ }
shape = p_shape;
update();
if (parent) {
@@ -150,8 +153,9 @@ void CollisionShape2D::set_shape(const Ref<Shape2D> &p_shape) {
}
}
- if (shape.is_valid())
+ if (shape.is_valid()) {
shape->connect("changed", callable_mp(this, &CollisionShape2D::_shape_changed));
+ }
update_configuration_warning();
}
@@ -161,8 +165,9 @@ Ref<Shape2D> CollisionShape2D::get_shape() const {
}
bool CollisionShape2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const {
- if (!shape.is_valid())
+ if (!shape.is_valid()) {
return false;
+ }
return shape->_edit_is_selected_on_click(p_point, p_tolerance);
}
diff --git a/scene/2d/cpu_particles_2d.cpp b/scene/2d/cpu_particles_2d.cpp
index e7129f39e7..526951976e 100644
--- a/scene/2d/cpu_particles_2d.cpp
+++ b/scene/2d/cpu_particles_2d.cpp
@@ -37,12 +37,14 @@
#include "servers/rendering_server.h"
void CPUParticles2D::set_emitting(bool p_emitting) {
- if (emitting == p_emitting)
+ if (emitting == p_emitting) {
return;
+ }
emitting = p_emitting;
- if (emitting)
+ if (emitting) {
set_process_internal(true);
+ }
}
void CPUParticles2D::set_amount(int p_amount) {
@@ -197,16 +199,19 @@ void CPUParticles2D::_update_mesh_texture() {
}
void CPUParticles2D::set_texture(const Ref<Texture2D> &p_texture) {
- if (p_texture == texture)
+ if (p_texture == texture) {
return;
+ }
- if (texture.is_valid())
+ if (texture.is_valid()) {
texture->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &CPUParticles2D::_texture_changed));
+ }
texture = p_texture;
- if (texture.is_valid())
+ if (texture.is_valid()) {
texture->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &CPUParticles2D::_texture_changed));
+ }
update();
_update_mesh_texture();
@@ -256,8 +261,9 @@ String CPUParticles2D::get_configuration_warning() const {
if (get_material().is_null() || (mat && !mat->get_particles_animation())) {
if (get_param(PARAM_ANIM_SPEED) != 0.0 || get_param(PARAM_ANIM_OFFSET) != 0.0 ||
get_param_curve(PARAM_ANIM_SPEED).is_valid() || get_param_curve(PARAM_ANIM_OFFSET).is_valid()) {
- if (warnings != String())
+ if (warnings != String()) {
warnings += "\n";
+ }
warnings += "- " + TTR("CPUParticles2D animation requires the usage of a CanvasItemMaterial with \"Particles Animation\" enabled.");
}
}
@@ -326,8 +332,9 @@ float CPUParticles2D::get_param_randomness(Parameter p_param) const {
static void _adjust_curve_range(const Ref<Curve> &p_curve, float p_min, float p_max) {
Ref<Curve> curve = p_curve;
- if (!curve.is_valid())
+ if (!curve.is_valid()) {
return;
+ }
curve->ensure_default_setup(p_min, p_max);
}
@@ -507,12 +514,14 @@ static uint32_t idhash(uint32_t x) {
static float rand_from_seed(uint32_t &seed) {
int k;
int s = int(seed);
- if (s == 0)
+ if (s == 0) {
s = 305420679;
+ }
k = s / 127773;
s = 16807 * (s - k * 127773) - 2836 * k;
- if (s < 0)
+ if (s < 0) {
s += 2147483647;
+ }
seed = uint32_t(s);
return float(seed % uint32_t(65536)) / 65535.0;
}
@@ -544,10 +553,11 @@ void CPUParticles2D::_update_internal() {
if (time == 0 && pre_process_time > 0.0) {
float frame_time;
- if (fixed_fps > 0)
+ if (fixed_fps > 0) {
frame_time = 1.0 / fixed_fps;
- else
+ } else {
frame_time = 1.0 / 30.0;
+ }
float todo = pre_process_time;
@@ -615,8 +625,9 @@ void CPUParticles2D::_particles_process(float p_delta) {
for (int i = 0; i < pcount; i++) {
Particle &p = parray[i];
- if (!emitting && !p.active)
+ if (!emitting && !p.active) {
continue;
+ }
float local_delta = p_delta;
@@ -729,8 +740,9 @@ void CPUParticles2D::_particles_process(float p_delta) {
case EMISSION_SHAPE_POINTS:
case EMISSION_SHAPE_DIRECTED_POINTS: {
int pc = emission_points.size();
- if (pc == 0)
+ if (pc == 0) {
break;
+ }
int random_idx = Math::rand() % pc;
@@ -911,8 +923,9 @@ void CPUParticles2D::_particles_process(float p_delta) {
//scale by scale
float base_scale = tex_scale * Math::lerp(parameters[PARAM_SCALE], 1.0f, p.scale_rand * randomness[PARAM_SCALE]);
- if (base_scale < 0.000001)
+ if (base_scale < 0.000001) {
base_scale = 0.000001;
+ }
p.transform.elements[0] *= base_scale;
p.transform.elements[1] *= base_scale;
@@ -987,8 +1000,9 @@ void CPUParticles2D::_update_particle_data_buffer() {
}
void CPUParticles2D::_set_redraw(bool p_redraw) {
- if (redraw == p_redraw)
+ if (redraw == p_redraw) {
return;
+ }
redraw = p_redraw;
{
@@ -1029,11 +1043,13 @@ void CPUParticles2D::_notification(int p_what) {
if (p_what == NOTIFICATION_DRAW) {
// first update before rendering to avoid one frame delay after emitting starts
- if (emitting && (time == 0))
+ if (emitting && (time == 0)) {
_update_internal();
+ }
- if (!redraw)
+ if (!redraw) {
return; // don't add to render list
+ }
RID texrid;
if (texture.is_valid()) {
@@ -1109,8 +1125,9 @@ void CPUParticles2D::convert_from_particles(Node *p_particles) {
}
Ref<ParticlesMaterial> material = particles->get_process_material();
- if (material.is_null())
+ if (material.is_null()) {
return;
+ }
Vector3 dir = material->get_direction();
set_direction(Vector2(dir.x, dir.y));
diff --git a/scene/2d/gpu_particles_2d.cpp b/scene/2d/gpu_particles_2d.cpp
index dc50ea8f19..0814fbb549 100644
--- a/scene/2d/gpu_particles_2d.cpp
+++ b/scene/2d/gpu_particles_2d.cpp
@@ -66,12 +66,14 @@ void GPUParticles2D::set_one_shot(bool p_enable) {
if (is_emitting()) {
set_process_internal(true);
- if (!one_shot)
+ if (!one_shot) {
RenderingServer::get_singleton()->particles_restart(particles);
+ }
}
- if (!one_shot)
+ if (!one_shot) {
set_process_internal(false);
+ }
}
void GPUParticles2D::set_pre_process_time(float p_time) {
@@ -131,8 +133,9 @@ void GPUParticles2D::set_process_material(const Ref<Material> &p_material) {
pm->set_gravity(Vector3(0, 98, 0));
}
RID material_rid;
- if (process_material.is_valid())
+ if (process_material.is_valid()) {
material_rid = process_material->get_rid();
+ }
RS::get_singleton()->particles_set_process_material(particles, material_rid);
update_configuration_warning();
@@ -222,8 +225,9 @@ String GPUParticles2D::get_configuration_warning() const {
String warnings;
if (process_material.is_null()) {
- if (warnings != String())
+ if (warnings != String()) {
warnings += "\n";
+ }
warnings += "- " + TTR("A material to process the particles is not assigned, so no behavior is imprinted.");
} else {
CanvasItemMaterial *mat = Object::cast_to<CanvasItemMaterial>(get_material().ptr());
@@ -233,8 +237,9 @@ String GPUParticles2D::get_configuration_warning() const {
if (process &&
(process->get_param(ParticlesMaterial::PARAM_ANIM_SPEED) != 0.0 || process->get_param(ParticlesMaterial::PARAM_ANIM_OFFSET) != 0.0 ||
process->get_param_texture(ParticlesMaterial::PARAM_ANIM_SPEED).is_valid() || process->get_param_texture(ParticlesMaterial::PARAM_ANIM_OFFSET).is_valid())) {
- if (warnings != String())
+ if (warnings != String()) {
warnings += "\n";
+ }
warnings += "- " + TTR("Particles2D animation requires the usage of a CanvasItemMaterial with \"Particles Animation\" enabled.");
}
}
@@ -282,11 +287,13 @@ void GPUParticles2D::restart() {
void GPUParticles2D::_notification(int p_what) {
if (p_what == NOTIFICATION_DRAW) {
RID texture_rid;
- if (texture.is_valid())
+ if (texture.is_valid()) {
texture_rid = texture->get_rid();
+ }
RID normal_rid;
- if (normal_map.is_valid())
+ if (normal_map.is_valid()) {
normal_rid = normal_map->get_rid();
+ }
RS::get_singleton()->canvas_item_add_particles(get_canvas_item(), particles, texture_rid, normal_rid);
diff --git a/scene/2d/joints_2d.cpp b/scene/2d/joints_2d.cpp
index a67b951155..0d126b949d 100644
--- a/scene/2d/joints_2d.cpp
+++ b/scene/2d/joints_2d.cpp
@@ -36,8 +36,9 @@
void Joint2D::_update_joint(bool p_only_free) {
if (joint.is_valid()) {
- if (ba.is_valid() && bb.is_valid() && exclude_from_collision)
+ if (ba.is_valid() && bb.is_valid() && exclude_from_collision) {
PhysicsServer2D::get_singleton()->joint_disable_collisions_between_bodies(joint, false);
+ }
PhysicsServer2D::get_singleton()->free(joint);
joint = RID();
@@ -45,25 +46,29 @@ void Joint2D::_update_joint(bool p_only_free) {
bb = RID();
}
- if (p_only_free || !is_inside_tree())
+ if (p_only_free || !is_inside_tree()) {
return;
+ }
Node *node_a = has_node(get_node_a()) ? get_node(get_node_a()) : (Node *)nullptr;
Node *node_b = has_node(get_node_b()) ? get_node(get_node_b()) : (Node *)nullptr;
- if (!node_a || !node_b)
+ if (!node_a || !node_b) {
return;
+ }
PhysicsBody2D *body_a = Object::cast_to<PhysicsBody2D>(node_a);
PhysicsBody2D *body_b = Object::cast_to<PhysicsBody2D>(node_b);
- if (!body_a || !body_b)
+ if (!body_a || !body_b) {
return;
+ }
joint = _configure_joint(body_a, body_b);
- if (!joint.is_valid())
+ if (!joint.is_valid()) {
return;
+ }
PhysicsServer2D::get_singleton()->get_singleton()->joint_set_param(joint, PhysicsServer2D::JOINT_PARAM_BIAS, bias);
@@ -74,8 +79,9 @@ void Joint2D::_update_joint(bool p_only_free) {
}
void Joint2D::set_node_a(const NodePath &p_node_a) {
- if (a == p_node_a)
+ if (a == p_node_a) {
return;
+ }
a = p_node_a;
_update_joint();
@@ -86,8 +92,9 @@ NodePath Joint2D::get_node_a() const {
}
void Joint2D::set_node_b(const NodePath &p_node_b) {
- if (b == p_node_b)
+ if (b == p_node_b) {
return;
+ }
b = p_node_b;
_update_joint();
}
@@ -111,8 +118,9 @@ void Joint2D::_notification(int p_what) {
void Joint2D::set_bias(real_t p_bias) {
bias = p_bias;
- if (joint.is_valid())
+ if (joint.is_valid()) {
PhysicsServer2D::get_singleton()->get_singleton()->joint_set_param(joint, PhysicsServer2D::JOINT_PARAM_BIAS, bias);
+ }
}
real_t Joint2D::get_bias() const {
@@ -120,8 +128,9 @@ real_t Joint2D::get_bias() const {
}
void Joint2D::set_exclude_nodes_from_collision(bool p_enable) {
- if (exclude_from_collision == p_enable)
+ if (exclude_from_collision == p_enable) {
return;
+ }
_update_joint(true);
exclude_from_collision = p_enable;
@@ -163,8 +172,9 @@ Joint2D::Joint2D() {
void PinJoint2D::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_DRAW: {
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
break;
+ }
if (!Engine::get_singleton()->is_editor_hint() && !get_tree()->is_debugging_collisions_hint()) {
break;
@@ -185,8 +195,9 @@ RID PinJoint2D::_configure_joint(PhysicsBody2D *body_a, PhysicsBody2D *body_b) {
void PinJoint2D::set_softness(real_t p_softness) {
softness = p_softness;
update();
- if (get_joint().is_valid())
+ if (get_joint().is_valid()) {
PhysicsServer2D::get_singleton()->pin_joint_set_param(get_joint(), PhysicsServer2D::PIN_JOINT_SOFTNESS, p_softness);
+ }
}
real_t PinJoint2D::get_softness() const {
@@ -211,8 +222,9 @@ PinJoint2D::PinJoint2D() {
void GrooveJoint2D::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_DRAW: {
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
break;
+ }
if (!Engine::get_singleton()->is_editor_hint() && !get_tree()->is_debugging_collisions_hint()) {
break;
@@ -275,8 +287,9 @@ GrooveJoint2D::GrooveJoint2D() {
void DampedSpringJoint2D::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_DRAW: {
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
break;
+ }
if (!Engine::get_singleton()->is_editor_hint() && !get_tree()->is_debugging_collisions_hint()) {
break;
@@ -295,8 +308,9 @@ RID DampedSpringJoint2D::_configure_joint(PhysicsBody2D *body_a, PhysicsBody2D *
Vector2 anchor_B = gt.xform(Vector2(0, length));
RID dsj = PhysicsServer2D::get_singleton()->damped_spring_joint_create(anchor_A, anchor_B, body_a->get_rid(), body_b->get_rid());
- if (rest_length)
+ if (rest_length) {
PhysicsServer2D::get_singleton()->damped_string_joint_set_param(dsj, PhysicsServer2D::DAMPED_STRING_REST_LENGTH, rest_length);
+ }
PhysicsServer2D::get_singleton()->damped_string_joint_set_param(dsj, PhysicsServer2D::DAMPED_STRING_STIFFNESS, stiffness);
PhysicsServer2D::get_singleton()->damped_string_joint_set_param(dsj, PhysicsServer2D::DAMPED_STRING_DAMPING, damping);
@@ -315,8 +329,9 @@ real_t DampedSpringJoint2D::get_length() const {
void DampedSpringJoint2D::set_rest_length(real_t p_rest_length) {
rest_length = p_rest_length;
update();
- if (get_joint().is_valid())
+ if (get_joint().is_valid()) {
PhysicsServer2D::get_singleton()->damped_string_joint_set_param(get_joint(), PhysicsServer2D::DAMPED_STRING_REST_LENGTH, p_rest_length ? p_rest_length : length);
+ }
}
real_t DampedSpringJoint2D::get_rest_length() const {
@@ -326,8 +341,9 @@ real_t DampedSpringJoint2D::get_rest_length() const {
void DampedSpringJoint2D::set_stiffness(real_t p_stiffness) {
stiffness = p_stiffness;
update();
- if (get_joint().is_valid())
+ if (get_joint().is_valid()) {
PhysicsServer2D::get_singleton()->damped_string_joint_set_param(get_joint(), PhysicsServer2D::DAMPED_STRING_STIFFNESS, p_stiffness);
+ }
}
real_t DampedSpringJoint2D::get_stiffness() const {
@@ -337,8 +353,9 @@ real_t DampedSpringJoint2D::get_stiffness() const {
void DampedSpringJoint2D::set_damping(real_t p_damping) {
damping = p_damping;
update();
- if (get_joint().is_valid())
+ if (get_joint().is_valid()) {
PhysicsServer2D::get_singleton()->damped_string_joint_set_param(get_joint(), PhysicsServer2D::DAMPED_STRING_DAMPING, p_damping);
+ }
}
real_t DampedSpringJoint2D::get_damping() const {
diff --git a/scene/2d/light_2d.cpp b/scene/2d/light_2d.cpp
index 2bae6bbd48..1e7e9f6b6a 100644
--- a/scene/2d/light_2d.cpp
+++ b/scene/2d/light_2d.cpp
@@ -59,8 +59,9 @@ bool Light2D::_edit_use_pivot() const {
}
Rect2 Light2D::_edit_get_rect() const {
- if (texture.is_null())
+ if (texture.is_null()) {
return Rect2();
+ }
Size2 s = texture->get_size() * _scale;
return Rect2(texture_offset - s / 2.0, s);
@@ -72,16 +73,18 @@ bool Light2D::_edit_use_rect() const {
#endif
Rect2 Light2D::get_anchorable_rect() const {
- if (texture.is_null())
+ if (texture.is_null()) {
return Rect2();
+ }
Size2 s = texture->get_size() * _scale;
return Rect2(texture_offset - s / 2.0, s);
}
void Light2D::_update_light_visibility() {
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
bool editor_ok = true;
@@ -122,10 +125,11 @@ bool Light2D::is_editor_only() const {
void Light2D::set_texture(const Ref<Texture2D> &p_texture) {
texture = p_texture;
- if (texture.is_valid())
+ if (texture.is_valid()) {
RS::get_singleton()->canvas_light_set_texture(canvas_light, texture->get_rid());
- else
+ } else {
RS::get_singleton()->canvas_light_set_texture(canvas_light, RID());
+ }
update_configuration_warning();
}
diff --git a/scene/2d/light_occluder_2d.cpp b/scene/2d/light_occluder_2d.cpp
index 80a0c0c40a..0f4880f69a 100644
--- a/scene/2d/light_occluder_2d.cpp
+++ b/scene/2d/light_occluder_2d.cpp
@@ -42,10 +42,11 @@ Rect2 OccluderPolygon2D::_edit_get_rect() const {
item_rect = Rect2();
for (int i = 0; i < polygon.size(); i++) {
Vector2 pos = r[i];
- if (i == 0)
+ if (i == 0) {
item_rect.position = pos;
- else
+ } else {
item_rect.expand_to(pos);
+ }
}
rect_cache_dirty = false;
} else {
@@ -73,8 +74,9 @@ bool OccluderPolygon2D::_edit_is_selected_on_click(const Point2 &p_point, double
const Vector2 *points = polygon.ptr();
for (int i = 0; i < polygon.size() - 1; i++) {
Vector2 p = Geometry::get_closest_point_to_segment_2d(p_point, &points[i]);
- if (p.distance_to(p_point) <= d)
+ if (p.distance_to(p_point) <= d) {
return true;
+ }
}
return false;
@@ -94,11 +96,13 @@ Vector<Vector2> OccluderPolygon2D::get_polygon() const {
}
void OccluderPolygon2D::set_closed(bool p_closed) {
- if (closed == p_closed)
+ if (closed == p_closed) {
return;
+ }
closed = p_closed;
- if (polygon.size())
+ if (polygon.size()) {
RS::get_singleton()->canvas_occluder_polygon_set_shape(occ_polygon, polygon, closed);
+ }
emit_changed();
}
@@ -207,19 +211,22 @@ bool LightOccluder2D::_edit_is_selected_on_click(const Point2 &p_point, double p
void LightOccluder2D::set_occluder_polygon(const Ref<OccluderPolygon2D> &p_polygon) {
#ifdef DEBUG_ENABLED
- if (occluder_polygon.is_valid())
+ if (occluder_polygon.is_valid()) {
occluder_polygon->disconnect("changed", callable_mp(this, &LightOccluder2D::_poly_changed));
+ }
#endif
occluder_polygon = p_polygon;
- if (occluder_polygon.is_valid())
+ if (occluder_polygon.is_valid()) {
RS::get_singleton()->canvas_light_occluder_set_polygon(occluder, occluder_polygon->get_rid());
- else
+ } else {
RS::get_singleton()->canvas_light_occluder_set_polygon(occluder, RID());
+ }
#ifdef DEBUG_ENABLED
- if (occluder_polygon.is_valid())
+ if (occluder_polygon.is_valid()) {
occluder_polygon->connect("changed", callable_mp(this, &LightOccluder2D::_poly_changed));
+ }
update();
#endif
}
diff --git a/scene/2d/line_2d.cpp b/scene/2d/line_2d.cpp
index 0ec58ec176..28183403f2 100644
--- a/scene/2d/line_2d.cpp
+++ b/scene/2d/line_2d.cpp
@@ -52,8 +52,9 @@ Line2D::Line2D() {
#ifdef TOOLS_ENABLED
Rect2 Line2D::_edit_get_rect() const {
- if (_points.size() == 0)
+ if (_points.size() == 0) {
return Rect2(0, 0, 0, 0);
+ }
Vector2 d = Vector2(_width, _width);
Rect2 aabb = Rect2(_points[0] - d, 2 * d);
for (int i = 1; i < _points.size(); i++) {
@@ -72,8 +73,9 @@ bool Line2D::_edit_is_selected_on_click(const Point2 &p_point, double p_toleranc
const Vector2 *points = _points.ptr();
for (int i = 0; i < _points.size() - 1; i++) {
Vector2 p = Geometry::get_closest_point_to_segment_2d(p_point, &points[i]);
- if (p.distance_to(p_point) <= d)
+ if (p.distance_to(p_point) <= d) {
return true;
+ }
}
return false;
@@ -86,8 +88,9 @@ void Line2D::set_points(const Vector<Vector2> &p_points) {
}
void Line2D::set_width(float p_width) {
- if (p_width < 0.0)
+ if (p_width < 0.0) {
p_width = 0.0;
+ }
_width = p_width;
update();
}
@@ -239,8 +242,9 @@ void Line2D::_notification(int p_what) {
}
void Line2D::set_sharp_limit(float p_limit) {
- if (p_limit < 0.f)
+ if (p_limit < 0.f) {
p_limit = 0.f;
+ }
_sharp_limit = p_limit;
update();
}
@@ -250,8 +254,9 @@ float Line2D::get_sharp_limit() const {
}
void Line2D::set_round_precision(int p_precision) {
- if (p_precision < 1)
+ if (p_precision < 1) {
p_precision = 1;
+ }
_round_precision = p_precision;
update();
}
@@ -270,8 +275,9 @@ bool Line2D::get_antialiased() const {
}
void Line2D::_draw() {
- if (_points.size() <= 1 || _width == 0.f)
+ if (_points.size() <= 1 || _width == 0.f) {
return;
+ }
// TODO Is this really needed?
// Copy points for faster access
diff --git a/scene/2d/line_builder.cpp b/scene/2d/line_builder.cpp
index 56293a7b8d..f1522dbaeb 100644
--- a/scene/2d/line_builder.cpp
+++ b/scene/2d/line_builder.cpp
@@ -53,8 +53,9 @@ static SegmentIntersectionResult segment_intersection(
float ub = (ab.x * (a.y - c.y) - ab.y * (a.x - c.x)) / div;
*out_intersection = a + ua * ab;
if (ua >= 0.f && ua <= 1.f &&
- ub >= 0.f && ub <= 1.f)
+ ub >= 0.f && ub <= 1.f) {
return SEGMENT_INTERSECT;
+ }
return SEGMENT_NO_INTERSECT;
}
@@ -157,28 +158,32 @@ void LineBuilder::build() {
//Adjust totalDistance.
// The line's outer length will be a little higher due to begin and end caps
if (begin_cap_mode == Line2D::LINE_CAP_BOX || begin_cap_mode == Line2D::LINE_CAP_ROUND) {
- if (retrieve_curve)
+ if (retrieve_curve) {
total_distance += width * curve->interpolate_baked(0.f) * 0.5f;
- else
+ } else {
total_distance += width * 0.5f;
+ }
}
if (end_cap_mode == Line2D::LINE_CAP_BOX || end_cap_mode == Line2D::LINE_CAP_ROUND) {
- if (retrieve_curve)
+ if (retrieve_curve) {
total_distance += width * curve->interpolate_baked(1.f) * 0.5f;
- else
+ } else {
total_distance += width * 0.5f;
+ }
}
}
- if (_interpolate_color)
+ if (_interpolate_color) {
color0 = gradient->get_color(0);
- else
+ } else {
colors.push_back(default_color);
+ }
float uvx0 = 0.f;
float uvx1 = 0.f;
- if (retrieve_curve)
+ if (retrieve_curve) {
width_factor = curve->interpolate_baked(0.f);
+ }
pos_up0 += u0 * hw * width_factor;
pos_down0 -= u0 * hw * width_factor;
@@ -269,10 +274,10 @@ void LineBuilder::build() {
pos1 + inner_normal1, pos2 + inner_normal1,
&corner_pos_in);
- if (intersection_result == SEGMENT_INTERSECT)
+ if (intersection_result == SEGMENT_INTERSECT) {
// Inner parts of the segments intersect
corner_pos_out = 2.f * pos1 - corner_pos_in;
- else {
+ } else {
// No intersection, segments are either parallel or too sharp
corner_pos_in = pos1 + inner_normal0;
corner_pos_out = pos1 - inner_normal0;
@@ -383,10 +388,11 @@ void LineBuilder::build() {
strip_add_arc(pos1, vbegin.angle_to(vend), orientation);
}
- if (intersection_result != SEGMENT_INTERSECT)
+ if (intersection_result != SEGMENT_INTERSECT) {
// In this case the joint is too corrputed to be re-used,
// start again the strip with fallback points
strip_begin(pos_up0, pos_down0, color1, uvx1);
+ }
}
}
// Last (or only) segment
@@ -547,8 +553,9 @@ void LineBuilder::strip_add_arc(Vector2 center, float angle_delta, Orientation o
float angle_step = Math_PI / static_cast<float>(round_precision);
float steps = Math::abs(angle_delta) / angle_step;
- if (angle_delta < 0.f)
+ if (angle_delta < 0.f) {
angle_step = -angle_step;
+ }
float t = Vector2(1, 0).angle_to(vbegin);
float end_angle = t + angle_delta;
@@ -573,8 +580,9 @@ void LineBuilder::new_arc(Vector2 center, Vector2 vbegin, float angle_delta, Col
float angle_step = Math_PI / static_cast<float>(round_precision);
float steps = Math::abs(angle_delta) / angle_step;
- if (angle_delta < 0.f)
+ if (angle_delta < 0.f) {
angle_step = -angle_step;
+ }
float t = Vector2(1, 0).angle_to(vbegin);
float end_angle = t + angle_delta;
@@ -585,10 +593,12 @@ void LineBuilder::new_arc(Vector2 center, Vector2 vbegin, float angle_delta, Col
// Center vertice
int vi = vertices.size();
vertices.push_back(center);
- if (_interpolate_color)
+ if (_interpolate_color) {
colors.push_back(color);
- if (texture_mode != Line2D::LINE_TEXTURE_NONE)
+ }
+ if (texture_mode != Line2D::LINE_TEXTURE_NONE) {
uvs.push_back(interpolate(uv_rect, Vector2(0.5f, 0.5f)));
+ }
// Arc vertices
for (int ti = 0; ti < steps; ++ti, t += angle_step) {
@@ -596,8 +606,9 @@ void LineBuilder::new_arc(Vector2 center, Vector2 vbegin, float angle_delta, Col
rpos = center + sc * radius;
vertices.push_back(rpos);
- if (_interpolate_color)
+ if (_interpolate_color) {
colors.push_back(color);
+ }
if (texture_mode != Line2D::LINE_TEXTURE_NONE) {
Vector2 tsc = Vector2(Math::cos(tt), Math::sin(tt));
uvs.push_back(interpolate(uv_rect, 0.5f * (tsc + Vector2(1.f, 1.f))));
@@ -609,8 +620,9 @@ void LineBuilder::new_arc(Vector2 center, Vector2 vbegin, float angle_delta, Col
Vector2 sc = Vector2(Math::cos(end_angle), Math::sin(end_angle));
rpos = center + sc * radius;
vertices.push_back(rpos);
- if (_interpolate_color)
+ if (_interpolate_color) {
colors.push_back(color);
+ }
if (texture_mode != Line2D::LINE_TEXTURE_NONE) {
tt = tt_begin + angle_delta;
Vector2 tsc = Vector2(Math::cos(tt), Math::sin(tt));
diff --git a/scene/2d/mesh_instance_2d.cpp b/scene/2d/mesh_instance_2d.cpp
index b4dd09c513..897595ad1f 100644
--- a/scene/2d/mesh_instance_2d.cpp
+++ b/scene/2d/mesh_instance_2d.cpp
@@ -65,8 +65,9 @@ Ref<Mesh> MeshInstance2D::get_mesh() const {
}
void MeshInstance2D::set_texture(const Ref<Texture2D> &p_texture) {
- if (p_texture == texture)
+ if (p_texture == texture) {
return;
+ }
texture = p_texture;
update();
emit_signal("texture_changed");
diff --git a/scene/2d/multimesh_instance_2d.cpp b/scene/2d/multimesh_instance_2d.cpp
index d99d5b9b30..b99c0a3fa9 100644
--- a/scene/2d/multimesh_instance_2d.cpp
+++ b/scene/2d/multimesh_instance_2d.cpp
@@ -65,8 +65,9 @@ Ref<MultiMesh> MultiMeshInstance2D::get_multimesh() const {
}
void MultiMeshInstance2D::set_texture(const Ref<Texture2D> &p_texture) {
- if (p_texture == texture)
+ if (p_texture == texture) {
return;
+ }
texture = p_texture;
update();
emit_signal("texture_changed");
diff --git a/scene/2d/navigation_agent_2d.cpp b/scene/2d/navigation_agent_2d.cpp
index 42dabeb488..cb2dbba0fe 100644
--- a/scene/2d/navigation_agent_2d.cpp
+++ b/scene/2d/navigation_agent_2d.cpp
@@ -100,10 +100,11 @@ void NavigationAgent2D::_notification(int p_what) {
Node *p = get_parent();
while (p != nullptr) {
nav = Object::cast_to<Navigation2D>(p);
- if (nav != nullptr)
+ if (nav != nullptr) {
p = nullptr;
- else
+ } else {
p = p->get_parent();
+ }
}
set_navigation(nav);
@@ -145,8 +146,9 @@ NavigationAgent2D::~NavigationAgent2D() {
}
void NavigationAgent2D::set_navigation(Navigation2D *p_nav) {
- if (navigation == p_nav)
+ if (navigation == p_nav) {
return; // Pointless
+ }
navigation = p_nav;
NavigationServer2D::get_singleton()->agent_set_map(agent, navigation == nullptr ? RID() : navigation->get_rid());
@@ -276,12 +278,15 @@ String NavigationAgent2D::get_configuration_warning() const {
}
void NavigationAgent2D::update_navigation() {
- if (agent_parent == nullptr)
+ if (agent_parent == nullptr) {
return;
- if (navigation == nullptr)
+ }
+ if (navigation == nullptr) {
return;
- if (update_frame_id == Engine::get_singleton()->get_physics_frames())
+ }
+ if (update_frame_id == Engine::get_singleton()->get_physics_frames()) {
return;
+ }
update_frame_id = Engine::get_singleton()->get_physics_frames();
@@ -314,8 +319,9 @@ void NavigationAgent2D::update_navigation() {
emit_signal("path_changed");
}
- if (navigation_path.size() == 0)
+ if (navigation_path.size() == 0) {
return;
+ }
// Check if we can advance the navigation path
if (navigation_finished == false) {
diff --git a/scene/2d/navigation_obstacle_2d.cpp b/scene/2d/navigation_obstacle_2d.cpp
index 2352064ae6..568023bbe2 100644
--- a/scene/2d/navigation_obstacle_2d.cpp
+++ b/scene/2d/navigation_obstacle_2d.cpp
@@ -51,10 +51,11 @@ void NavigationObstacle2D::_notification(int p_what) {
Node *p = get_parent();
while (p != nullptr) {
nav = Object::cast_to<Navigation2D>(p);
- if (nav != nullptr)
+ if (nav != nullptr) {
p = nullptr;
- else
+ } else {
p = p->get_parent();
+ }
}
set_navigation(nav);
@@ -86,8 +87,9 @@ NavigationObstacle2D::~NavigationObstacle2D() {
}
void NavigationObstacle2D::set_navigation(Navigation2D *p_nav) {
- if (navigation == p_nav)
+ if (navigation == p_nav) {
return; // Pointless
+ }
navigation = p_nav;
NavigationServer2D::get_singleton()->agent_set_map(agent, navigation == nullptr ? RID() : navigation->get_rid());
@@ -138,8 +140,9 @@ void NavigationObstacle2D::update_agent_shape() {
radius *= MAX(s.x, s.y);
}
- if (radius == 0.0)
+ if (radius == 0.0) {
radius = 1.0; // Never a 0 radius
+ }
// Initialize the Agent as an object
NavigationServer2D::get_singleton()->agent_set_neighbor_dist(agent, 0.0);
diff --git a/scene/2d/navigation_region_2d.cpp b/scene/2d/navigation_region_2d.cpp
index 1ab414c7ea..72bde17428 100644
--- a/scene/2d/navigation_region_2d.cpp
+++ b/scene/2d/navigation_region_2d.cpp
@@ -47,8 +47,9 @@ Rect2 NavigationPolygon::_edit_get_rect() const {
for (int i = 0; i < outlines.size(); i++) {
const Vector<Vector2> &outline = outlines[i];
const int outline_size = outline.size();
- if (outline_size < 3)
+ if (outline_size < 3) {
continue;
+ }
const Vector2 *p = outline.ptr();
for (int j = 0; j < outline_size; j++) {
if (first) {
@@ -69,10 +70,12 @@ bool NavigationPolygon::_edit_is_selected_on_click(const Point2 &p_point, double
for (int i = 0; i < outlines.size(); i++) {
const Vector<Vector2> &outline = outlines[i];
const int outline_size = outline.size();
- if (outline_size < 3)
+ if (outline_size < 3) {
continue;
- if (Geometry::is_point_in_polygon(p_point, Variant(outline)))
+ }
+ if (Geometry::is_point_in_polygon(p_point, Variant(outline))) {
return true;
+ }
}
return false;
}
@@ -231,8 +234,9 @@ void NavigationPolygon::make_polygons_from_outlines() {
for (int i = 0; i < outlines.size(); i++) {
Vector<Vector2> ol = outlines[i];
int olsize = ol.size();
- if (olsize < 3)
+ if (olsize < 3) {
continue;
+ }
const Vector2 *r = ol.ptr();
for (int j = 0; j < olsize; j++) {
outside_point.x = MAX(r[j].x, outside_point.x);
@@ -245,20 +249,23 @@ void NavigationPolygon::make_polygons_from_outlines() {
for (int i = 0; i < outlines.size(); i++) {
Vector<Vector2> ol = outlines[i];
int olsize = ol.size();
- if (olsize < 3)
+ if (olsize < 3) {
continue;
+ }
const Vector2 *r = ol.ptr();
int interscount = 0;
//test if this is an outer outline
for (int k = 0; k < outlines.size(); k++) {
- if (i == k)
+ if (i == k) {
continue; //no self intersect
+ }
Vector<Vector2> ol2 = outlines[k];
int olsize2 = ol2.size();
- if (olsize2 < 3)
+ if (olsize2 < 3) {
continue;
+ }
const Vector2 *r2 = ol2.ptr();
for (int l = 0; l < olsize2; l++) {
@@ -276,9 +283,9 @@ void NavigationPolygon::make_polygons_from_outlines() {
tp[j] = r[j];
}
- if (outer)
+ if (outer) {
tp.SetOrientation(TRIANGULATOR_CCW);
- else {
+ } else {
tp.SetOrientation(TRIANGULATOR_CW);
tp.SetHole(true);
}
@@ -346,12 +353,14 @@ void NavigationPolygon::_bind_methods() {
}
void NavigationRegion2D::set_enabled(bool p_enabled) {
- if (enabled == p_enabled)
+ if (enabled == p_enabled) {
return;
+ }
enabled = p_enabled;
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
if (!enabled) {
NavigationServer2D::get_singleton()->region_set_map(region, RID());
@@ -361,8 +370,9 @@ void NavigationRegion2D::set_enabled(bool p_enabled) {
}
}
- if (Engine::get_singleton()->is_editor_hint() || get_tree()->is_debugging_navigation_hint())
+ if (Engine::get_singleton()->is_editor_hint() || get_tree()->is_debugging_navigation_hint()) {
update();
+ }
}
bool NavigationRegion2D::is_enabled() const {
@@ -411,8 +421,9 @@ void NavigationRegion2D::_notification(int p_what) {
if (is_inside_tree() && (Engine::get_singleton()->is_editor_hint() || get_tree()->is_debugging_navigation_hint()) && navpoly.is_valid()) {
Vector<Vector2> verts = navpoly->get_vertices();
int vsize = verts.size();
- if (vsize < 3)
+ if (vsize < 3) {
return;
+ }
Color color;
if (enabled) {
@@ -478,13 +489,15 @@ Ref<NavigationPolygon> NavigationRegion2D::get_navigation_polygon() const {
}
void NavigationRegion2D::_navpoly_changed() {
- if (is_inside_tree() && (Engine::get_singleton()->is_editor_hint() || get_tree()->is_debugging_navigation_hint()))
+ if (is_inside_tree() && (Engine::get_singleton()->is_editor_hint() || get_tree()->is_debugging_navigation_hint())) {
update();
+ }
}
String NavigationRegion2D::get_configuration_warning() const {
- if (!is_visible_in_tree() || !is_inside_tree())
+ if (!is_visible_in_tree() || !is_inside_tree()) {
return String();
+ }
if (!navpoly.is_valid()) {
return TTR("A NavigationPolygon resource must be set or created for this node to work. Please set a property or draw a polygon.");
diff --git a/scene/2d/node_2d.cpp b/scene/2d/node_2d.cpp
index 388d64334d..72250e96b3 100644
--- a/scene/2d/node_2d.cpp
+++ b/scene/2d/node_2d.cpp
@@ -98,17 +98,21 @@ void Node2D::_edit_set_rect(const Rect2 &p_edit_rect) {
Rect2 r = _edit_get_rect();
Vector2 zero_offset;
- if (r.size.x != 0)
+ if (r.size.x != 0) {
zero_offset.x = -r.position.x / r.size.x;
- if (r.size.y != 0)
+ }
+ if (r.size.y != 0) {
zero_offset.y = -r.position.y / r.size.y;
+ }
Size2 new_scale(1, 1);
- if (r.size.x != 0)
+ if (r.size.x != 0) {
new_scale.x = p_edit_rect.size.x / r.size.x;
- if (r.size.y != 0)
+ }
+ if (r.size.y != 0) {
new_scale.y = p_edit_rect.size.y / r.size.y;
+ }
Point2 new_pos = p_edit_rect.position + p_edit_rect.size * zero_offset;
@@ -139,23 +143,26 @@ void Node2D::_update_transform() {
RenderingServer::get_singleton()->canvas_item_set_transform(get_canvas_item(), _mat);
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
_notify_transform();
}
void Node2D::set_position(const Point2 &p_pos) {
- if (_xform_dirty)
+ if (_xform_dirty) {
((Node2D *)this)->_update_xform_values();
+ }
pos = p_pos;
_update_transform();
_change_notify("position");
}
void Node2D::set_rotation(float p_radians) {
- if (_xform_dirty)
+ if (_xform_dirty) {
((Node2D *)this)->_update_xform_values();
+ }
angle = p_radians;
_update_transform();
_change_notify("rotation");
@@ -163,8 +170,9 @@ void Node2D::set_rotation(float p_radians) {
}
void Node2D::set_skew(float p_radians) {
- if (_xform_dirty)
+ if (_xform_dirty) {
((Node2D *)this)->_update_xform_values();
+ }
skew = p_radians;
_update_transform();
_change_notify("skew");
@@ -180,34 +188,40 @@ void Node2D::set_skew_degrees(float p_degrees) {
}
void Node2D::set_scale(const Size2 &p_scale) {
- if (_xform_dirty)
+ if (_xform_dirty) {
((Node2D *)this)->_update_xform_values();
+ }
_scale = p_scale;
// Avoid having 0 scale values, can lead to errors in physics and rendering.
- if (_scale.x == 0)
+ if (_scale.x == 0) {
_scale.x = CMP_EPSILON;
- if (_scale.y == 0)
+ }
+ if (_scale.y == 0) {
_scale.y = CMP_EPSILON;
+ }
_update_transform();
_change_notify("scale");
}
Point2 Node2D::get_position() const {
- if (_xform_dirty)
+ if (_xform_dirty) {
((Node2D *)this)->_update_xform_values();
+ }
return pos;
}
float Node2D::get_rotation() const {
- if (_xform_dirty)
+ if (_xform_dirty) {
((Node2D *)this)->_update_xform_values();
+ }
return angle;
}
float Node2D::get_skew() const {
- if (_xform_dirty)
+ if (_xform_dirty) {
((Node2D *)this)->_update_xform_values();
+ }
return skew;
}
@@ -221,8 +235,9 @@ float Node2D::get_skew_degrees() const {
}
Size2 Node2D::get_scale() const {
- if (_xform_dirty)
+ if (_xform_dirty) {
((Node2D *)this)->_update_xform_values();
+ }
return _scale;
}
@@ -250,16 +265,18 @@ void Node2D::apply_scale(const Size2 &p_amount) {
void Node2D::move_x(float p_delta, bool p_scaled) {
Transform2D t = get_transform();
Vector2 m = t[0];
- if (!p_scaled)
+ if (!p_scaled) {
m.normalize();
+ }
set_position(t[2] + m * p_delta);
}
void Node2D::move_y(float p_delta, bool p_scaled) {
Transform2D t = get_transform();
Vector2 m = t[1];
- if (!p_scaled)
+ if (!p_scaled) {
m.normalize();
+ }
set_position(t[2] + m * p_delta);
}
@@ -320,18 +337,20 @@ void Node2D::set_transform(const Transform2D &p_transform) {
RenderingServer::get_singleton()->canvas_item_set_transform(get_canvas_item(), _mat);
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
_notify_transform();
}
void Node2D::set_global_transform(const Transform2D &p_transform) {
CanvasItem *pi = get_parent_item();
- if (pi)
+ if (pi) {
set_transform(pi->get_global_transform().affine_inverse() * p_transform);
- else
+ } else {
set_transform(p_transform);
+ }
}
void Node2D::set_z_index(int p_z) {
@@ -343,8 +362,9 @@ void Node2D::set_z_index(int p_z) {
}
void Node2D::set_z_as_relative(bool p_enabled) {
- if (z_relative == p_enabled)
+ if (z_relative == p_enabled) {
return;
+ }
z_relative = p_enabled;
RS::get_singleton()->canvas_item_set_z_as_relative_to_parent(get_canvas_item(), p_enabled);
}
@@ -358,16 +378,18 @@ int Node2D::get_z_index() const {
}
Transform2D Node2D::get_relative_transform_to_parent(const Node *p_parent) const {
- if (p_parent == this)
+ if (p_parent == this) {
return Transform2D();
+ }
Node2D *parent_2d = Object::cast_to<Node2D>(get_parent());
ERR_FAIL_COND_V(!parent_2d, Transform2D());
- if (p_parent == parent_2d)
+ if (p_parent == parent_2d) {
return get_transform();
- else
+ } else {
return parent_2d->get_relative_transform_to_parent(p_parent) * get_transform();
+ }
}
void Node2D::look_at(const Vector2 &p_pos) {
diff --git a/scene/2d/parallax_background.cpp b/scene/2d/parallax_background.cpp
index 6930307840..416622e6d5 100644
--- a/scene/2d/parallax_background.cpp
+++ b/scene/2d/parallax_background.cpp
@@ -66,8 +66,9 @@ void ParallaxBackground::set_scroll_offset(const Point2 &p_ofs) {
}
void ParallaxBackground::_update_scroll() {
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
Vector2 ofs = base_offset + offset * base_scale;
@@ -75,17 +76,19 @@ void ParallaxBackground::_update_scroll() {
ofs = -ofs;
if (limit_begin.x < limit_end.x) {
- if (ofs.x < limit_begin.x)
+ if (ofs.x < limit_begin.x) {
ofs.x = limit_begin.x;
- else if (ofs.x + vps.x > limit_end.x)
+ } else if (ofs.x + vps.x > limit_end.x) {
ofs.x = limit_end.x - vps.x;
+ }
}
if (limit_begin.y < limit_end.y) {
- if (ofs.y < limit_begin.y)
+ if (ofs.y < limit_begin.y) {
ofs.y = limit_begin.y;
- else if (ofs.y + vps.y > limit_end.y)
+ } else if (ofs.y + vps.y > limit_end.y) {
ofs.y = limit_end.y - vps.y;
+ }
}
ofs = -ofs;
@@ -93,13 +96,15 @@ void ParallaxBackground::_update_scroll() {
for (int i = 0; i < get_child_count(); i++) {
ParallaxLayer *l = Object::cast_to<ParallaxLayer>(get_child(i));
- if (!l)
+ if (!l) {
continue;
+ }
- if (ignore_camera_zoom)
+ if (ignore_camera_zoom) {
l->set_base_offset_and_scale(ofs, 1.0, screen_offset);
- else
+ } else {
l->set_base_offset_and_scale(ofs, scale, screen_offset);
+ }
}
}
diff --git a/scene/2d/parallax_layer.cpp b/scene/2d/parallax_layer.cpp
index ffc6e50da2..4ed335dec8 100644
--- a/scene/2d/parallax_layer.cpp
+++ b/scene/2d/parallax_layer.cpp
@@ -64,8 +64,9 @@ Size2 ParallaxLayer::get_motion_offset() const {
}
void ParallaxLayer::_update_mirroring() {
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
ParallaxBackground *pb = Object::cast_to<ParallaxBackground>(get_parent());
if (pb) {
@@ -78,10 +79,12 @@ void ParallaxLayer::_update_mirroring() {
void ParallaxLayer::set_mirroring(const Size2 &p_mirroring) {
mirroring = p_mirroring;
- if (mirroring.x < 0)
+ if (mirroring.x < 0) {
mirroring.x = 0;
- if (mirroring.y < 0)
+ }
+ if (mirroring.y < 0) {
mirroring.y = 0;
+ }
_update_mirroring();
}
@@ -107,10 +110,12 @@ void ParallaxLayer::_notification(int p_what) {
void ParallaxLayer::set_base_offset_and_scale(const Point2 &p_offset, float p_scale, const Point2 &p_screen_offset) {
screen_offset = p_screen_offset;
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
- if (Engine::get_singleton()->is_editor_hint())
+ }
+ if (Engine::get_singleton()->is_editor_hint()) {
return;
+ }
Point2 new_ofs = (screen_offset + (p_offset - screen_offset) * motion_scale) + motion_offset * p_scale + orig_offset * p_scale;
diff --git a/scene/2d/path_2d.cpp b/scene/2d/path_2d.cpp
index a914da8fe0..046e4dbd41 100644
--- a/scene/2d/path_2d.cpp
+++ b/scene/2d/path_2d.cpp
@@ -39,8 +39,9 @@
#ifdef TOOLS_ENABLED
Rect2 Path2D::_edit_get_rect() const {
- if (!curve.is_valid() || curve->get_point_count() == 0)
+ if (!curve.is_valid() || curve->get_point_count() == 0) {
return Rect2(0, 0, 0, 0);
+ }
Rect2 aabb = Rect2(curve->get_point_position(0), Vector2(0, 0));
@@ -73,8 +74,9 @@ bool Path2D::_edit_is_selected_on_click(const Point2 &p_point, double p_toleranc
s[1] = curve->interpolate(i, frac);
Vector2 p = Geometry::get_closest_point_to_segment_2d(p_point, s);
- if (p.distance_to(p_point) <= p_tolerance)
+ if (p.distance_to(p_point) <= p_tolerance) {
return true;
+ }
s[0] = s[1];
}
@@ -156,12 +158,14 @@ Path2D::Path2D() {
/////////////////////////////////////////////////////////////////////////////////
void PathFollow2D::_update_transform() {
- if (!path)
+ if (!path) {
return;
+ }
Ref<Curve2D> c = path->get_curve();
- if (!c.is_valid())
+ if (!c.is_valid()) {
return;
+ }
float path_length = c->get_baked_length();
if (path_length == 0) {
@@ -240,16 +244,18 @@ bool PathFollow2D::get_cubic_interpolation() const {
void PathFollow2D::_validate_property(PropertyInfo &property) const {
if (property.name == "offset") {
float max = 10000;
- if (path && path->get_curve().is_valid())
+ if (path && path->get_curve().is_valid()) {
max = path->get_curve()->get_baked_length();
+ }
property.hint_string = "0," + rtos(max) + ",0.01,or_lesser,or_greater";
}
}
String PathFollow2D::get_configuration_warning() const {
- if (!is_visible_in_tree() || !is_inside_tree())
+ if (!is_visible_in_tree() || !is_inside_tree()) {
return String();
+ }
if (!Object::cast_to<Path2D>(get_parent())) {
return TTR("PathFollow2D only works when set as a child of a Path2D node.");
@@ -317,8 +323,9 @@ void PathFollow2D::set_offset(float p_offset) {
void PathFollow2D::set_h_offset(float p_h_offset) {
h_offset = p_h_offset;
- if (path)
+ if (path) {
_update_transform();
+ }
}
float PathFollow2D::get_h_offset() const {
@@ -327,8 +334,9 @@ float PathFollow2D::get_h_offset() const {
void PathFollow2D::set_v_offset(float p_v_offset) {
v_offset = p_v_offset;
- if (path)
+ if (path) {
_update_transform();
+ }
}
float PathFollow2D::get_v_offset() const {
@@ -340,15 +348,17 @@ float PathFollow2D::get_offset() const {
}
void PathFollow2D::set_unit_offset(float p_unit_offset) {
- if (path && path->get_curve().is_valid() && path->get_curve()->get_baked_length())
+ if (path && path->get_curve().is_valid() && path->get_curve()->get_baked_length()) {
set_offset(p_unit_offset * path->get_curve()->get_baked_length());
+ }
}
float PathFollow2D::get_unit_offset() const {
- if (path && path->get_curve().is_valid() && path->get_curve()->get_baked_length())
+ if (path && path->get_curve().is_valid() && path->get_curve()->get_baked_length()) {
return get_offset() / path->get_curve()->get_baked_length();
- else
+ } else {
return 0;
+ }
}
void PathFollow2D::set_lookahead(float p_lookahead) {
diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp
index 0225fd55c2..ae448129bc 100644
--- a/scene/2d/physics_body_2d.cpp
+++ b/scene/2d/physics_body_2d.cpp
@@ -96,10 +96,11 @@ uint32_t PhysicsBody2D::get_collision_mask() const {
void PhysicsBody2D::set_collision_mask_bit(int p_bit, bool p_value) {
uint32_t mask = get_collision_mask();
- if (p_value)
+ if (p_value) {
mask |= 1 << p_bit;
- else
+ } else {
mask &= ~(1 << p_bit);
+ }
set_collision_mask(mask);
}
@@ -109,10 +110,11 @@ bool PhysicsBody2D::get_collision_mask_bit(int p_bit) const {
void PhysicsBody2D::set_collision_layer_bit(int p_bit, bool p_value) {
uint32_t collision_layer = get_collision_layer();
- if (p_value)
+ if (p_value) {
collision_layer |= 1 << p_bit;
- else
+ } else {
collision_layer &= ~(1 << p_bit);
+ }
set_collision_layer(collision_layer);
}
@@ -296,8 +298,9 @@ void RigidBody2D::_body_inout(int p_status, ObjectID p_instance, int p_body_shap
//E->get().rc++;
}
- if (node)
+ if (node) {
E->get().shapes.insert(ShapePair(p_body_shape, p_local_shape));
+ }
if (E->get().in_scene) {
emit_signal(SceneStringNames::get_singleton()->body_shape_entered, objid, node, p_body_shape, p_local_shape);
@@ -306,8 +309,9 @@ void RigidBody2D::_body_inout(int p_status, ObjectID p_instance, int p_body_shap
} else {
//E->get().rc--;
- if (node)
+ if (node) {
E->get().shapes.erase(ShapePair(p_body_shape, p_local_shape));
+ }
bool in_scene = E->get().in_scene;
@@ -315,8 +319,9 @@ void RigidBody2D::_body_inout(int p_status, ObjectID p_instance, int p_body_shap
if (node) {
node->disconnect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &RigidBody2D::_body_enter_tree));
node->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &RigidBody2D::_body_exit_tree));
- if (in_scene)
+ if (in_scene) {
emit_signal(SceneStringNames::get_singleton()->body_exited, node);
+ }
}
contact_monitor->body_map.erase(E);
@@ -335,8 +340,9 @@ struct _RigidBody2DInOut {
bool RigidBody2D::_test_motion(const Vector2 &p_motion, bool p_infinite_inertia, float p_margin, const Ref<PhysicsTestMotionResult2D> &p_result) {
PhysicsServer2D::MotionResult *r = nullptr;
- if (p_result.is_valid())
+ if (p_result.is_valid()) {
r = p_result->get_result_ptr();
+ }
return PhysicsServer2D::get_singleton()->body_test_motion(get_rid(), get_global_transform(), p_motion, p_infinite_inertia, p_margin, r);
}
@@ -348,16 +354,18 @@ void RigidBody2D::_direct_state_changed(Object *p_state) {
#endif
set_block_transform_notify(true); // don't want notify (would feedback loop)
- if (mode != MODE_KINEMATIC)
+ if (mode != MODE_KINEMATIC) {
set_global_transform(state->get_transform());
+ }
linear_velocity = state->get_linear_velocity();
angular_velocity = state->get_angular_velocity();
if (sleeping != state->is_sleeping()) {
sleeping = state->is_sleeping();
emit_signal(SceneStringNames::get_singleton()->sleeping_state_changed);
}
- if (get_script_instance())
+ if (get_script_instance()) {
get_script_instance()->call("_integrate_forces", state);
+ }
set_block_transform_notify(false); // want it back
if (contact_monitor) {
@@ -555,9 +563,9 @@ void RigidBody2D::set_axis_velocity(const Vector2 &p_axis) {
void RigidBody2D::set_linear_velocity(const Vector2 &p_velocity) {
linear_velocity = p_velocity;
- if (state)
+ if (state) {
state->set_linear_velocity(linear_velocity);
- else {
+ } else {
PhysicsServer2D::get_singleton()->body_set_state(get_rid(), PhysicsServer2D::BODY_STATE_LINEAR_VELOCITY, linear_velocity);
}
}
@@ -568,10 +576,11 @@ Vector2 RigidBody2D::get_linear_velocity() const {
void RigidBody2D::set_angular_velocity(real_t p_velocity) {
angular_velocity = p_velocity;
- if (state)
+ if (state) {
state->set_angular_velocity(angular_velocity);
- else
+ } else {
PhysicsServer2D::get_singleton()->body_set_state(get_rid(), PhysicsServer2D::BODY_STATE_ANGULAR_VELOCITY, angular_velocity);
+ }
}
real_t RigidBody2D::get_angular_velocity() const {
@@ -579,8 +588,9 @@ real_t RigidBody2D::get_angular_velocity() const {
}
void RigidBody2D::set_use_custom_integrator(bool p_enable) {
- if (custom_integrator == p_enable)
+ if (custom_integrator == p_enable) {
return;
+ }
custom_integrator = p_enable;
PhysicsServer2D::get_singleton()->body_set_omit_force_integration(get_rid(), p_enable);
@@ -685,8 +695,9 @@ TypedArray<Node2D> RigidBody2D::get_colliding_bodies() const {
}
void RigidBody2D::set_contact_monitor(bool p_enabled) {
- if (p_enabled == is_contact_monitor_enabled())
+ if (p_enabled == is_contact_monitor_enabled()) {
return;
+ }
if (!p_enabled) {
ERR_FAIL_COND_MSG(contact_monitor->locked, "Can't disable contact monitoring during in/out callback. Use call_deferred(\"set_contact_monitor\", false) instead.");
@@ -881,8 +892,9 @@ RigidBody2D::RigidBody2D() :
}
RigidBody2D::~RigidBody2D() {
- if (contact_monitor)
+ if (contact_monitor) {
memdelete(contact_monitor);
+ }
}
void RigidBody2D::_reload_physics_characteristics() {
@@ -1062,8 +1074,9 @@ Vector2 KinematicBody2D::move_and_slide(const Vector2 &p_linear_velocity, const
}
}
- if (!found_collision || motion == Vector2())
+ if (!found_collision || motion == Vector2()) {
break;
+ }
--p_max_slides;
}
@@ -1174,8 +1187,9 @@ void KinematicBody2D::set_sync_to_physics(bool p_enable) {
}
sync_to_physics = p_enable;
- if (Engine::get_singleton()->is_editor_hint())
+ if (Engine::get_singleton()->is_editor_hint()) {
return;
+ }
if (p_enable) {
PhysicsServer2D::get_singleton()->body_set_force_integration_callback(get_rid(), this, "_direct_state_changed");
@@ -1193,8 +1207,9 @@ bool KinematicBody2D::is_sync_to_physics_enabled() const {
}
void KinematicBody2D::_direct_state_changed(Object *p_state) {
- if (!sync_to_physics)
+ if (!sync_to_physics) {
return;
+ }
PhysicsDirectBodyState2D *state = Object::cast_to<PhysicsDirectBodyState2D>(p_state);
@@ -1297,8 +1312,9 @@ Vector2 KinematicCollision2D::get_remainder() const {
}
Object *KinematicCollision2D::get_local_shape() const {
- if (!owner)
+ if (!owner) {
return nullptr;
+ }
uint32_t ownerid = owner->shape_find_owner(collision.local_shape);
return owner->shape_owner_get_owner(ownerid);
}
diff --git a/scene/2d/physics_body_2d.h b/scene/2d/physics_body_2d.h
index f3bdeb4528..cde4398ad3 100644
--- a/scene/2d/physics_body_2d.h
+++ b/scene/2d/physics_body_2d.h
@@ -144,8 +144,9 @@ private:
int local_shape;
bool tagged;
bool operator<(const ShapePair &p_sp) const {
- if (body_shape == p_sp.body_shape)
+ if (body_shape == p_sp.body_shape) {
return local_shape < p_sp.local_shape;
+ }
return body_shape < p_sp.body_shape;
}
diff --git a/scene/2d/polygon_2d.cpp b/scene/2d/polygon_2d.cpp
index b4e3b9bc40..62c66dbb29 100644
--- a/scene/2d/polygon_2d.cpp
+++ b/scene/2d/polygon_2d.cpp
@@ -65,10 +65,11 @@ Rect2 Polygon2D::_edit_get_rect() const {
item_rect = Rect2();
for (int i = 0; i < l; i++) {
Vector2 pos = r[i] + offset;
- if (i == 0)
+ if (i == 0) {
item_rect.position = pos;
- else
+ } else {
item_rect.expand_to(pos);
+ }
}
rect_cache_dirty = false;
}
@@ -96,8 +97,9 @@ void Polygon2D::_skeleton_bone_setup_changed() {
void Polygon2D::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_DRAW: {
- if (polygon.size() < 3)
+ if (polygon.size() < 3) {
return;
+ }
Skeleton2D *skeleton_node = nullptr;
if (has_node(skeleton)) {
@@ -156,10 +158,11 @@ void Polygon2D::_notification(int p_what) {
float sum = 0;
for (int i = 0; i < len; i++) {
- if (i == 0)
+ if (i == 0) {
bounds.position = points[i];
- else
+ } else {
bounds.expand_to(points[i]);
+ }
if (points[i].y > highest_y) {
highest_idx = i;
highest_y = points[i].y;
@@ -249,8 +252,9 @@ void Polygon2D::_notification(int p_what) {
int bone_index = bone->get_index_in_skeleton();
const float *r = bone_weights[i].weights.ptr();
for (int j = 0; j < vc; j++) {
- if (r[j] == 0.0)
+ if (r[j] == 0.0) {
continue; //weight is unpainted, skip
+ }
//find an index with a weight
for (int k = 0; k < 4; k++) {
if (weightsw[j * 4 + k] < r[j]) {
@@ -273,8 +277,9 @@ void Polygon2D::_notification(int p_what) {
for (int j = 0; j < 4; j++) {
tw += weightsw[i * 4 + j];
}
- if (tw == 0)
+ if (tw == 0) {
continue; //unpainted, do nothing
+ }
//normalize
for (int j = 0; j < 4; j++) {
@@ -305,8 +310,9 @@ void Polygon2D::_notification(int p_what) {
for (int i = 0; i < polygons.size(); i++) {
Vector<int> src_indices = polygons[i];
int ic = src_indices.size();
- if (ic < 3)
+ if (ic < 3) {
continue;
+ }
const int *r = src_indices.ptr();
Vector<Vector2> tmp_points;
@@ -580,8 +586,9 @@ void Polygon2D::_set_bones(const Array &p_bones) {
}
void Polygon2D::set_skeleton(const NodePath &p_skeleton) {
- if (skeleton == p_skeleton)
+ if (skeleton == p_skeleton) {
return;
+ }
skeleton = p_skeleton;
update();
}
diff --git a/scene/2d/position_2d.cpp b/scene/2d/position_2d.cpp
index 4cd46171c6..a94a9f7085 100644
--- a/scene/2d/position_2d.cpp
+++ b/scene/2d/position_2d.cpp
@@ -59,10 +59,12 @@ void Position2D::_notification(int p_what) {
update();
} break;
case NOTIFICATION_DRAW: {
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
break;
- if (Engine::get_singleton()->is_editor_hint())
+ }
+ if (Engine::get_singleton()->is_editor_hint()) {
_draw_cross();
+ }
} break;
}
diff --git a/scene/2d/ray_cast_2d.cpp b/scene/2d/ray_cast_2d.cpp
index 50d437f78b..5020940c5c 100644
--- a/scene/2d/ray_cast_2d.cpp
+++ b/scene/2d/ray_cast_2d.cpp
@@ -37,8 +37,9 @@
void RayCast2D::set_cast_to(const Vector2 &p_point) {
cast_to = p_point;
- if (is_inside_tree() && (Engine::get_singleton()->is_editor_hint() || get_tree()->is_debugging_collisions_hint()))
+ if (is_inside_tree() && (Engine::get_singleton()->is_editor_hint() || get_tree()->is_debugging_collisions_hint())) {
update();
+ }
}
Vector2 RayCast2D::get_cast_to() const {
@@ -55,10 +56,11 @@ uint32_t RayCast2D::get_collision_mask() const {
void RayCast2D::set_collision_mask_bit(int p_bit, bool p_value) {
uint32_t mask = get_collision_mask();
- if (p_value)
+ if (p_value) {
mask |= 1 << p_bit;
- else
+ } else {
mask &= ~(1 << p_bit);
+ }
set_collision_mask(mask);
}
@@ -71,8 +73,9 @@ bool RayCast2D::is_colliding() const {
}
Object *RayCast2D::get_collider() const {
- if (against.is_null())
+ if (against.is_null()) {
return nullptr;
+ }
return ObjectDB::get_instance(against);
}
@@ -92,10 +95,12 @@ Vector2 RayCast2D::get_collision_normal() const {
void RayCast2D::set_enabled(bool p_enabled) {
enabled = p_enabled;
update();
- if (is_inside_tree() && !Engine::get_singleton()->is_editor_hint())
+ if (is_inside_tree() && !Engine::get_singleton()->is_editor_hint()) {
set_physics_process_internal(p_enabled);
- if (!p_enabled)
+ }
+ if (!p_enabled) {
collided = false;
+ }
}
bool RayCast2D::is_enabled() const {
@@ -103,19 +108,22 @@ bool RayCast2D::is_enabled() const {
}
void RayCast2D::set_exclude_parent_body(bool p_exclude_parent_body) {
- if (exclude_parent_body == p_exclude_parent_body)
+ if (exclude_parent_body == p_exclude_parent_body) {
return;
+ }
exclude_parent_body = p_exclude_parent_body;
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
if (Object::cast_to<CollisionObject2D>(get_parent())) {
- if (exclude_parent_body)
+ if (exclude_parent_body) {
exclude.insert(Object::cast_to<CollisionObject2D>(get_parent())->get_rid());
- else
+ } else {
exclude.erase(Object::cast_to<CollisionObject2D>(get_parent())->get_rid());
+ }
}
}
@@ -126,27 +134,31 @@ bool RayCast2D::get_exclude_parent_body() const {
void RayCast2D::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
- if (enabled && !Engine::get_singleton()->is_editor_hint())
+ if (enabled && !Engine::get_singleton()->is_editor_hint()) {
set_physics_process_internal(true);
- else
+ } else {
set_physics_process_internal(false);
+ }
if (Object::cast_to<CollisionObject2D>(get_parent())) {
- if (exclude_parent_body)
+ if (exclude_parent_body) {
exclude.insert(Object::cast_to<CollisionObject2D>(get_parent())->get_rid());
- else
+ } else {
exclude.erase(Object::cast_to<CollisionObject2D>(get_parent())->get_rid());
+ }
}
} break;
case NOTIFICATION_EXIT_TREE: {
- if (enabled)
+ if (enabled) {
set_physics_process_internal(false);
+ }
} break;
case NOTIFICATION_DRAW: {
- if (!Engine::get_singleton()->is_editor_hint() && !get_tree()->is_debugging_collisions_hint())
+ if (!Engine::get_singleton()->is_editor_hint() && !get_tree()->is_debugging_collisions_hint()) {
break;
+ }
Transform2D xf;
xf.rotate(cast_to.angle());
xf.translate(Vector2(cast_to.length(), 0));
@@ -166,16 +178,18 @@ void RayCast2D::_notification(int p_what) {
pts.push_back(xf.xform(Vector2(0, Math_SQRT12 * tsize)));
pts.push_back(xf.xform(Vector2(0, -Math_SQRT12 * tsize)));
Vector<Color> cols;
- for (int i = 0; i < 3; i++)
+ for (int i = 0; i < 3; i++) {
cols.push_back(draw_col);
+ }
draw_primitive(pts, cols, Vector<Vector2>());
} break;
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
- if (!enabled)
+ if (!enabled) {
break;
+ }
_update_raycast_state();
@@ -193,8 +207,9 @@ void RayCast2D::_update_raycast_state() {
Transform2D gt = get_global_transform();
Vector2 to = cast_to;
- if (to == Vector2())
+ if (to == Vector2()) {
to = Vector2(0, 0.01);
+ }
PhysicsDirectSpaceState2D::RayResult rr;
@@ -222,8 +237,9 @@ void RayCast2D::add_exception_rid(const RID &p_rid) {
void RayCast2D::add_exception(const Object *p_object) {
ERR_FAIL_NULL(p_object);
const CollisionObject2D *co = Object::cast_to<CollisionObject2D>(p_object);
- if (!co)
+ if (!co) {
return;
+ }
add_exception_rid(co->get_rid());
}
@@ -234,8 +250,9 @@ void RayCast2D::remove_exception_rid(const RID &p_rid) {
void RayCast2D::remove_exception(const Object *p_object) {
ERR_FAIL_NULL(p_object);
const CollisionObject2D *co = Object::cast_to<CollisionObject2D>(p_object);
- if (!co)
+ if (!co) {
return;
+ }
remove_exception_rid(co->get_rid());
}
diff --git a/scene/2d/remote_transform_2d.cpp b/scene/2d/remote_transform_2d.cpp
index d9b73a5e6e..3104436dbe 100644
--- a/scene/2d/remote_transform_2d.cpp
+++ b/scene/2d/remote_transform_2d.cpp
@@ -44,18 +44,22 @@ void RemoteTransform2D::_update_cache() {
}
void RemoteTransform2D::_update_remote() {
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
- if (cache.is_null())
+ if (cache.is_null()) {
return;
+ }
Node2D *n = Object::cast_to<Node2D>(ObjectDB::get_instance(cache));
- if (!n)
+ if (!n) {
return;
+ }
- if (!n->is_inside_tree())
+ if (!n->is_inside_tree()) {
return;
+ }
//todo make faster
if (use_global_coordinates) {
@@ -66,17 +70,20 @@ void RemoteTransform2D::_update_remote() {
Transform2D our_trans = get_global_transform();
Vector2 n_scale = n->get_scale();
- if (!update_remote_position)
+ if (!update_remote_position) {
our_trans.set_origin(n_trans.get_origin());
- if (!update_remote_rotation)
+ }
+ if (!update_remote_rotation) {
our_trans.set_rotation(n_trans.get_rotation());
+ }
n->set_global_transform(our_trans);
- if (update_remote_scale)
+ if (update_remote_scale) {
n->set_scale(get_global_scale());
- else
+ } else {
n->set_scale(n_scale);
+ }
}
} else {
@@ -87,17 +94,20 @@ void RemoteTransform2D::_update_remote() {
Transform2D our_trans = get_transform();
Vector2 n_scale = n->get_scale();
- if (!update_remote_position)
+ if (!update_remote_position) {
our_trans.set_origin(n_trans.get_origin());
- if (!update_remote_rotation)
+ }
+ if (!update_remote_rotation) {
our_trans.set_rotation(n_trans.get_rotation());
+ }
n->set_transform(our_trans);
- if (update_remote_scale)
+ if (update_remote_scale) {
n->set_scale(get_scale());
- else
+ } else {
n->set_scale(n_scale);
+ }
}
}
}
@@ -109,8 +119,9 @@ void RemoteTransform2D::_notification(int p_what) {
} break;
case NOTIFICATION_TRANSFORM_CHANGED: {
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
break;
+ }
if (cache.is_valid()) {
_update_remote();
diff --git a/scene/2d/skeleton_2d.cpp b/scene/2d/skeleton_2d.cpp
index 2c041f7449..ea37c8dfe7 100644
--- a/scene/2d/skeleton_2d.cpp
+++ b/scene/2d/skeleton_2d.cpp
@@ -37,10 +37,12 @@ void Bone2D::_notification(int p_what) {
skeleton = nullptr;
while (parent) {
skeleton = Object::cast_to<Skeleton2D>(parent);
- if (skeleton)
+ if (skeleton) {
break;
- if (!Object::cast_to<Bone2D>(parent))
+ }
+ if (!Object::cast_to<Bone2D>(parent)) {
break; //skeletons must be chained to Bone2Ds.
+ }
parent = parent->get_parent();
}
@@ -94,8 +96,9 @@ void Bone2D::_bind_methods() {
void Bone2D::set_rest(const Transform2D &p_rest) {
rest = p_rest;
- if (skeleton)
+ if (skeleton) {
skeleton->_make_bone_setup_dirty();
+ }
update_configuration_warning();
}
@@ -168,8 +171,9 @@ Bone2D::Bone2D() {
//////////////////////////////////////
void Skeleton2D::_make_bone_setup_dirty() {
- if (bone_setup_dirty)
+ if (bone_setup_dirty) {
return;
+ }
bone_setup_dirty = true;
if (is_inside_tree()) {
call_deferred("_update_bone_setup");
@@ -177,8 +181,9 @@ void Skeleton2D::_make_bone_setup_dirty() {
}
void Skeleton2D::_update_bone_setup() {
- if (!bone_setup_dirty)
+ if (!bone_setup_dirty) {
return;
+ }
bone_setup_dirty = false;
RS::get_singleton()->skeleton_allocate(skeleton, bones.size(), true);
@@ -202,8 +207,9 @@ void Skeleton2D::_update_bone_setup() {
}
void Skeleton2D::_make_transform_dirty() {
- if (transform_dirty)
+ if (transform_dirty) {
return;
+ }
transform_dirty = true;
if (is_inside_tree()) {
call_deferred("_update_transform");
@@ -215,8 +221,9 @@ void Skeleton2D::_update_transform() {
_update_bone_setup();
return; //above will update transform anyway
}
- if (!transform_dirty)
+ if (!transform_dirty) {
return;
+ }
transform_dirty = false;
@@ -254,10 +261,12 @@ Bone2D *Skeleton2D::get_bone(int p_idx) {
void Skeleton2D::_notification(int p_what) {
if (p_what == NOTIFICATION_READY) {
- if (bone_setup_dirty)
+ if (bone_setup_dirty) {
_update_bone_setup();
- if (transform_dirty)
+ }
+ if (transform_dirty) {
_update_transform();
+ }
request_ready();
}
diff --git a/scene/2d/sprite_2d.cpp b/scene/2d/sprite_2d.cpp
index ce350f167e..7e07019578 100644
--- a/scene/2d/sprite_2d.cpp
+++ b/scene/2d/sprite_2d.cpp
@@ -96,25 +96,29 @@ void Sprite2D::_get_rects(Rect2 &r_src_rect, Rect2 &r_dst_rect, bool &r_filter_c
r_src_rect.position = base_rect.position + frame_offset;
Point2 dest_offset = offset;
- if (centered)
+ if (centered) {
dest_offset -= frame_size / 2;
+ }
if (Engine::get_singleton()->get_use_pixel_snap()) {
dest_offset = dest_offset.floor();
}
r_dst_rect = Rect2(dest_offset, frame_size);
- if (hflip)
+ if (hflip) {
r_dst_rect.size.x = -r_dst_rect.size.x;
- if (vflip)
+ }
+ if (vflip) {
r_dst_rect.size.y = -r_dst_rect.size.y;
+ }
}
void Sprite2D::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_DRAW: {
- if (texture.is_null())
+ if (texture.is_null()) {
return;
+ }
RID ci = get_canvas_item();
@@ -133,16 +137,19 @@ void Sprite2D::_notification(int p_what) {
}
void Sprite2D::set_texture(const Ref<Texture2D> &p_texture) {
- if (p_texture == texture)
+ if (p_texture == texture) {
return;
+ }
- if (texture.is_valid())
+ if (texture.is_valid()) {
texture->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &Sprite2D::_texture_changed));
+ }
texture = p_texture;
- if (texture.is_valid())
+ if (texture.is_valid()) {
texture->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &Sprite2D::_texture_changed));
+ }
update();
emit_signal("texture_changed");
@@ -230,8 +237,9 @@ bool Sprite2D::is_flipped_v() const {
}
void Sprite2D::set_region(bool p_region) {
- if (p_region == region)
+ if (p_region == region) {
return;
+ }
region = p_region;
update();
@@ -242,13 +250,15 @@ bool Sprite2D::is_region() const {
}
void Sprite2D::set_region_rect(const Rect2 &p_region_rect) {
- if (region_rect == p_region_rect)
+ if (region_rect == p_region_rect) {
return;
+ }
region_rect = p_region_rect;
- if (region)
+ if (region) {
item_rect_changed();
+ }
_change_notify("region_rect");
}
@@ -269,8 +279,9 @@ bool Sprite2D::is_region_filter_clip_enabled() const {
void Sprite2D::set_frame(int p_frame) {
ERR_FAIL_INDEX(p_frame, vframes * hframes);
- if (frame != p_frame)
+ if (frame != p_frame) {
item_rect_changed();
+ }
frame = p_frame;
@@ -319,25 +330,30 @@ int Sprite2D::get_hframes() const {
}
bool Sprite2D::is_pixel_opaque(const Point2 &p_point) const {
- if (texture.is_null())
+ if (texture.is_null()) {
return false;
+ }
- if (texture->get_size().width == 0 || texture->get_size().height == 0)
+ if (texture->get_size().width == 0 || texture->get_size().height == 0) {
return false;
+ }
Rect2 src_rect, dst_rect;
bool filter_clip;
_get_rects(src_rect, dst_rect, filter_clip);
dst_rect.size = dst_rect.size.abs();
- if (!dst_rect.has_point(p_point))
+ if (!dst_rect.has_point(p_point)) {
return false;
+ }
Vector2 q = (p_point - dst_rect.position) / dst_rect.size;
- if (hflip)
+ if (hflip) {
q.x = 1.0f - q.x;
- if (vflip)
+ }
+ if (vflip) {
q.y = 1.0f - q.y;
+ }
q = q * src_rect.size + src_rect.position;
#ifndef _MSC_VER
#warning this need to be obtained from CanvasItem new repeat mode (but it needs to guess it from hierarchy, need to add a function for that)
@@ -368,8 +384,9 @@ bool Sprite2D::is_pixel_opaque(const Point2 &p_point) const {
}
Rect2 Sprite2D::get_rect() const {
- if (texture.is_null())
+ if (texture.is_null()) {
return Rect2(0, 0, 1, 1);
+ }
Size2i s;
@@ -382,11 +399,13 @@ Rect2 Sprite2D::get_rect() const {
s = s / Point2(hframes, vframes);
Point2 ofs = offset;
- if (centered)
+ if (centered) {
ofs -= Size2(s) / 2;
+ }
- if (s == Size2(0, 0))
+ if (s == Size2(0, 0)) {
s = Size2(1, 1);
+ }
return Rect2(ofs, s);
}
diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp
index 7af3acd83e..c7a809f6d8 100644
--- a/scene/2d/tile_map.cpp
+++ b/scene/2d/tile_map.cpp
@@ -39,10 +39,11 @@
#include "servers/physics_server_2d.h"
int TileMap::_get_quadrant_size() const {
- if (use_y_sort)
+ if (use_y_sort) {
return 1;
- else
+ } else {
return quadrant_size;
+ }
}
void TileMap::_notification(int p_what) {
@@ -124,18 +125,21 @@ void TileMap::_update_quadrant_space(const RID &p_space) {
}
void TileMap::_update_quadrant_transform() {
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
Transform2D global_transform = get_global_transform();
Transform2D local_transform;
- if (collision_parent)
+ if (collision_parent) {
local_transform = get_transform();
+ }
Transform2D nav_rel;
- if (navigation)
+ if (navigation) {
nav_rel = get_relative_transform_to_parent(navigation);
+ }
for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) {
Quadrant &q = E->get();
@@ -303,8 +307,9 @@ void TileMap::_add_shape(int &shape_idx, const Quadrant &p_q, const Ref<Shape2D>
}
void TileMap::update_dirty_quadrants() {
- if (!pending_update)
+ if (!pending_update) {
return;
+ }
if (!is_inside_tree() || !tile_set.is_valid()) {
pending_update = false;
return;
@@ -314,8 +319,9 @@ void TileMap::update_dirty_quadrants() {
PhysicsServer2D *ps = PhysicsServer2D::get_singleton();
Vector2 tofs = get_cell_draw_offset();
Transform2D nav_rel;
- if (navigation)
+ if (navigation) {
nav_rel = get_relative_transform_to_parent(navigation);
+ }
Vector2 qofs;
@@ -369,16 +375,18 @@ void TileMap::update_dirty_quadrants() {
Map<PosKey, Cell>::Element *E = tile_map.find(q.cells[i]);
Cell &c = E->get();
//moment of truth
- if (!tile_set->has_tile(c.id))
+ if (!tile_set->has_tile(c.id)) {
continue;
+ }
Ref<Texture2D> tex = tile_set->tile_get_texture(c.id);
Vector2 tile_ofs = tile_set->tile_get_texture_offset(c.id);
Vector2 wofs = _map_to_world(E->key().x, E->key().y);
Vector2 offset = wofs - q.pos + tofs;
- if (!tex.is_valid())
+ if (!tex.is_valid()) {
continue;
+ }
Ref<ShaderMaterial> mat = tile_set->tile_get_material(c.id);
int z_index = tile_set->tile_get_z_index(c.id);
@@ -393,8 +401,9 @@ void TileMap::update_dirty_quadrants() {
if (prev_canvas_item == RID() || prev_material != mat || prev_z_index != z_index) {
canvas_item = vs->canvas_item_create();
- if (mat.is_valid())
+ if (mat.is_valid()) {
vs->canvas_item_set_material(canvas_item, mat->get_rid());
+ }
vs->canvas_item_set_parent(canvas_item, get_canvas_item());
_update_item_material_state(canvas_item);
Transform2D xform;
@@ -433,10 +442,11 @@ void TileMap::update_dirty_quadrants() {
}
Size2 s;
- if (r == Rect2())
+ if (r == Rect2()) {
s = tex->get_size();
- else
+ } else {
s = r.size;
+ }
Rect2 rect;
rect.position = offset.floor();
@@ -446,11 +456,13 @@ void TileMap::update_dirty_quadrants() {
if (compatibility_mode && !centered_textures) {
if (rect.size.y > rect.size.x) {
- if ((c.flip_h && (c.flip_v || c.transpose)) || (c.flip_v && !c.transpose))
+ if ((c.flip_h && (c.flip_v || c.transpose)) || (c.flip_v && !c.transpose)) {
tile_ofs.y += rect.size.y - rect.size.x;
+ }
} else if (rect.size.y < rect.size.x) {
- if ((c.flip_v && (c.flip_h || c.transpose)) || (c.flip_h && !c.transpose))
+ if ((c.flip_v && (c.flip_h || c.transpose)) || (c.flip_h && !c.transpose)) {
tile_ofs.x += rect.size.x - rect.size.y;
+ }
}
}
@@ -482,29 +494,33 @@ void TileMap::update_dirty_quadrants() {
rect.position += tile_ofs;
if (c.transpose) {
- if (c.flip_h)
+ if (c.flip_h) {
rect.position.x -= cell_size.x;
- else
+ } else {
rect.position.x += cell_size.x;
+ }
} else {
- if (c.flip_v)
+ if (c.flip_v) {
rect.position.y -= cell_size.y;
- else
+ } else {
rect.position.y += cell_size.y;
+ }
}
} else if (tile_origin == TILE_ORIGIN_CENTER) {
rect.position += tile_ofs;
- if (c.flip_h)
+ if (c.flip_h) {
rect.position.x -= cell_size.x / 2;
- else
+ } else {
rect.position.x += cell_size.x / 2;
+ }
- if (c.flip_v)
+ if (c.flip_v) {
rect.position.y -= cell_size.y / 2;
- else
+ } else {
rect.position.y += cell_size.y / 2;
+ }
}
} else {
rect.position += tile_ofs;
@@ -687,8 +703,9 @@ void TileMap::update_dirty_quadrants() {
void TileMap::_recompute_rect_cache() {
#ifdef DEBUG_ENABLED
- if (!rect_cache_dirty)
+ if (!rect_cache_dirty) {
return;
+ }
Rect2 r_total;
for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) {
@@ -697,10 +714,11 @@ void TileMap::_recompute_rect_cache() {
r.expand_to(_map_to_world(E->key().x * _get_quadrant_size() + _get_quadrant_size(), E->key().y * _get_quadrant_size()));
r.expand_to(_map_to_world(E->key().x * _get_quadrant_size() + _get_quadrant_size(), E->key().y * _get_quadrant_size() + _get_quadrant_size()));
r.expand_to(_map_to_world(E->key().x * _get_quadrant_size(), E->key().y * _get_quadrant_size() + _get_quadrant_size()));
- if (E == quadrant_map.front())
+ if (E == quadrant_map.front()) {
r_total = r;
- else
+ } else {
r_total = r_total.merge(r);
+ }
}
rect_cache = r_total;
@@ -717,10 +735,11 @@ Map<TileMap::PosKey, TileMap::Quadrant>::Element *TileMap::_create_quadrant(cons
Quadrant q;
q.pos = _map_to_world(p_qk.x * _get_quadrant_size(), p_qk.y * _get_quadrant_size());
q.pos += get_cell_draw_offset();
- if (tile_origin == TILE_ORIGIN_CENTER)
+ if (tile_origin == TILE_ORIGIN_CENTER) {
q.pos += cell_size / 2;
- else if (tile_origin == TILE_ORIGIN_BOTTOM_LEFT)
+ } else if (tile_origin == TILE_ORIGIN_BOTTOM_LEFT) {
q.pos.y += cell_size.y;
+ }
xform.set_origin(q.pos);
//q.canvas_item = RenderingServer::get_singleton()->canvas_item_create();
@@ -765,8 +784,9 @@ void TileMap::_erase_quadrant(Map<PosKey, Quadrant>::Element *Q) {
RenderingServer::get_singleton()->free(E->get());
}
q.canvas_items.clear();
- if (q.dirty_list.in_list())
+ if (q.dirty_list.in_list()) {
dirty_quadrant_list.remove(&q.dirty_list);
+ }
if (navigation) {
for (Map<PosKey, Quadrant::NavPoly>::Element *E = q.navpoly_ids.front(); E; E = E->next()) {
@@ -786,14 +806,17 @@ void TileMap::_erase_quadrant(Map<PosKey, Quadrant>::Element *Q) {
void TileMap::_make_quadrant_dirty(Map<PosKey, Quadrant>::Element *Q, bool update) {
Quadrant &q = Q->get();
- if (!q.dirty_list.in_list())
+ if (!q.dirty_list.in_list()) {
dirty_quadrant_list.add(&q.dirty_list);
+ }
- if (pending_update)
+ if (pending_update) {
return;
+ }
pending_update = true;
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
if (update) {
call_deferred("update_dirty_quadrants");
@@ -815,8 +838,9 @@ void TileMap::set_cell(int p_x, int p_y, int p_tile, bool p_flip_x, bool p_flip_
PosKey pk(p_x, p_y);
Map<PosKey, Cell>::Element *E = tile_map.find(pk);
- if (!E && p_tile == INVALID_CELL)
+ if (!E && p_tile == INVALID_CELL) {
return; //nothing to do
+ }
PosKey qk = pk.to_quadrant(_get_quadrant_size());
if (p_tile == INVALID_CELL) {
@@ -826,10 +850,11 @@ void TileMap::set_cell(int p_x, int p_y, int p_tile, bool p_flip_x, bool p_flip_
ERR_FAIL_COND(!Q);
Quadrant &q = Q->get();
q.cells.erase(pk);
- if (q.cells.size() == 0)
+ if (q.cells.size() == 0) {
_erase_quadrant(Q);
- else
+ } else {
_make_quadrant_dirty(Q);
+ }
used_size_cache_dirty = true;
return;
@@ -847,8 +872,9 @@ void TileMap::set_cell(int p_x, int p_y, int p_tile, bool p_flip_x, bool p_flip_
} else {
ERR_FAIL_COND(!Q); // quadrant should exist...
- if (E->get().id == p_tile && E->get().flip_h == p_flip_x && E->get().flip_v == p_flip_y && E->get().transpose == p_transpose && E->get().autotile_coord_x == (uint16_t)p_autotile_coord.x && E->get().autotile_coord_y == (uint16_t)p_autotile_coord.y)
+ if (E->get().id == p_tile && E->get().flip_h == p_flip_x && E->get().flip_v == p_flip_y && E->get().transpose == p_transpose && E->get().autotile_coord_x == (uint16_t)p_autotile_coord.x && E->get().autotile_coord_y == (uint16_t)p_autotile_coord.y) {
return; //nothing changed
+ }
}
Cell &c = E->get();
@@ -1009,8 +1035,9 @@ int TileMap::get_cell(int p_x, int p_y) const {
const Map<PosKey, Cell>::Element *E = tile_map.find(pk);
- if (!E)
+ if (!E) {
return INVALID_CELL;
+ }
return E->get().id;
}
@@ -1020,8 +1047,9 @@ bool TileMap::is_cell_x_flipped(int p_x, int p_y) const {
const Map<PosKey, Cell>::Element *E = tile_map.find(pk);
- if (!E)
+ if (!E) {
return false;
+ }
return E->get().flip_h;
}
@@ -1031,8 +1059,9 @@ bool TileMap::is_cell_y_flipped(int p_x, int p_y) const {
const Map<PosKey, Cell>::Element *E = tile_map.find(pk);
- if (!E)
+ if (!E) {
return false;
+ }
return E->get().flip_v;
}
@@ -1042,8 +1071,9 @@ bool TileMap::is_cell_transposed(int p_x, int p_y) const {
const Map<PosKey, Cell>::Element *E = tile_map.find(pk);
- if (!E)
+ if (!E) {
return false;
+ }
return E->get().transpose;
}
@@ -1053,8 +1083,9 @@ void TileMap::set_cell_autotile_coord(int p_x, int p_y, const Vector2 &p_coord)
const Map<PosKey, Cell>::Element *E = tile_map.find(pk);
- if (!E)
+ if (!E) {
return;
+ }
Cell c = E->get();
c.autotile_coord_x = p_coord.x;
@@ -1064,8 +1095,9 @@ void TileMap::set_cell_autotile_coord(int p_x, int p_y, const Vector2 &p_coord)
PosKey qk = pk.to_quadrant(_get_quadrant_size());
Map<PosKey, Quadrant>::Element *Q = quadrant_map.find(qk);
- if (!Q)
+ if (!Q) {
return;
+ }
_make_quadrant_dirty(Q);
}
@@ -1075,8 +1107,9 @@ Vector2 TileMap::get_cell_autotile_coord(int p_x, int p_y) const {
const Map<PosKey, Cell>::Element *E = tile_map.find(pk);
- if (!E)
+ if (!E) {
return Vector2();
+ }
return Vector2(E->get().autotile_coord_x, E->get().autotile_coord_y);
}
@@ -1146,8 +1179,9 @@ void TileMap::_set_tile_data(const Vector<int> &p_data) {
for (int i = 0; i < c; i += offset) {
const uint8_t *ptr = (const uint8_t *)&r[i];
uint8_t local[12];
- for (int j = 0; j < ((format == FORMAT_2) ? 12 : 8); j++)
+ for (int j = 0; j < ((format == FORMAT_2) ? 12 : 8); j++) {
local[j] = ptr[j];
+ }
#ifdef BIG_ENDIAN_ENABLED
@@ -1193,12 +1227,15 @@ Vector<int> TileMap::_get_tile_data() const {
encode_uint16(E->key().x, &ptr[0]);
encode_uint16(E->key().y, &ptr[2]);
uint32_t val = E->get().id;
- if (E->get().flip_h)
+ if (E->get().flip_h) {
val |= (1 << 29);
- if (E->get().flip_v)
+ }
+ if (E->get().flip_v) {
val |= (1 << 30);
- if (E->get().transpose)
+ }
+ if (E->get().transpose) {
val |= (1 << 31);
+ }
encode_uint32(val, &ptr[4]);
encode_uint16(E->get().autotile_coord_x, &ptr[8]);
encode_uint16(E->get().autotile_coord_y, &ptr[10]);
@@ -1241,19 +1278,21 @@ void TileMap::set_collision_mask(uint32_t p_mask) {
void TileMap::set_collision_layer_bit(int p_bit, bool p_value) {
uint32_t layer = get_collision_layer();
- if (p_value)
+ if (p_value) {
layer |= 1 << p_bit;
- else
+ } else {
layer &= ~(1 << p_bit);
+ }
set_collision_layer(layer);
}
void TileMap::set_collision_mask_bit(int p_bit, bool p_value) {
uint32_t mask = get_collision_mask();
- if (p_value)
+ if (p_value) {
mask |= 1 << p_bit;
- else
+ } else {
mask &= ~(1 << p_bit);
+ }
set_collision_mask(mask);
}
@@ -1272,8 +1311,9 @@ bool TileMap::get_collision_use_parent() const {
}
void TileMap::set_collision_use_parent(bool p_use_parent) {
- if (use_parent == p_use_parent)
+ if (use_parent == p_use_parent) {
return;
+ }
_clear_quadrants();
@@ -1634,8 +1674,9 @@ void TileMap::set_light_mask(int p_light_mask) {
}
void TileMap::set_clip_uv(bool p_enable) {
- if (clip_uv == p_enable)
+ if (clip_uv == p_enable) {
return;
+ }
_clear_quadrants();
clip_uv = p_enable;
@@ -1837,8 +1878,9 @@ TileMap::TileMap() {
}
TileMap::~TileMap() {
- if (tile_set.is_valid())
+ if (tile_set.is_valid()) {
tile_set->remove_change_receptor(this);
+ }
clear();
}
diff --git a/scene/2d/touch_screen_button.cpp b/scene/2d/touch_screen_button.cpp
index 2d8a47ee98..4597300db8 100644
--- a/scene/2d/touch_screen_button.cpp
+++ b/scene/2d/touch_screen_button.cpp
@@ -62,13 +62,15 @@ Ref<BitMap> TouchScreenButton::get_bitmask() const {
}
void TouchScreenButton::set_shape(const Ref<Shape2D> &p_shape) {
- if (shape.is_valid())
+ if (shape.is_valid()) {
shape->disconnect("changed", callable_mp((CanvasItem *)this, &CanvasItem::update));
+ }
shape = p_shape;
- if (shape.is_valid())
+ if (shape.is_valid()) {
shape->connect("changed", callable_mp((CanvasItem *)this, &CanvasItem::update));
+ }
update();
}
@@ -98,26 +100,32 @@ bool TouchScreenButton::is_shape_centered() const {
void TouchScreenButton::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_DRAW: {
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
- if (!Engine::get_singleton()->is_editor_hint() && !!DisplayServer::get_singleton()->screen_is_touchscreen(DisplayServer::get_singleton()->window_get_current_screen(get_viewport()->get_window_id())) && visibility == VISIBILITY_TOUCHSCREEN_ONLY)
+ }
+ if (!Engine::get_singleton()->is_editor_hint() && !!DisplayServer::get_singleton()->screen_is_touchscreen(DisplayServer::get_singleton()->window_get_current_screen(get_viewport()->get_window_id())) && visibility == VISIBILITY_TOUCHSCREEN_ONLY) {
return;
+ }
if (finger_pressed != -1) {
- if (texture_pressed.is_valid())
+ if (texture_pressed.is_valid()) {
draw_texture(texture_pressed, Point2());
- else if (texture.is_valid())
+ } else if (texture.is_valid()) {
draw_texture(texture, Point2());
+ }
} else {
- if (texture.is_valid())
+ if (texture.is_valid()) {
draw_texture(texture, Point2());
+ }
}
- if (!shape_visible)
+ if (!shape_visible) {
return;
- if (!Engine::get_singleton()->is_editor_hint() && !get_tree()->is_debugging_collisions_hint())
+ }
+ if (!Engine::get_singleton()->is_editor_hint() && !get_tree()->is_debugging_collisions_hint()) {
return;
+ }
if (shape.is_valid()) {
Color draw_col = get_tree()->get_debug_collisions_color();
@@ -129,32 +137,38 @@ void TouchScreenButton::_notification(int p_what) {
} break;
case NOTIFICATION_ENTER_TREE: {
- if (!Engine::get_singleton()->is_editor_hint() && !!DisplayServer::get_singleton()->screen_is_touchscreen(DisplayServer::get_singleton()->window_get_current_screen(get_viewport()->get_window_id())) && visibility == VISIBILITY_TOUCHSCREEN_ONLY)
+ if (!Engine::get_singleton()->is_editor_hint() && !!DisplayServer::get_singleton()->screen_is_touchscreen(DisplayServer::get_singleton()->window_get_current_screen(get_viewport()->get_window_id())) && visibility == VISIBILITY_TOUCHSCREEN_ONLY) {
return;
+ }
update();
- if (!Engine::get_singleton()->is_editor_hint())
+ if (!Engine::get_singleton()->is_editor_hint()) {
set_process_input(is_visible_in_tree());
+ }
} break;
case NOTIFICATION_EXIT_TREE: {
- if (is_pressed())
+ if (is_pressed()) {
_release(true);
+ }
} break;
case NOTIFICATION_VISIBILITY_CHANGED: {
- if (Engine::get_singleton()->is_editor_hint())
+ if (Engine::get_singleton()->is_editor_hint()) {
break;
+ }
if (is_visible_in_tree()) {
set_process_input(true);
} else {
set_process_input(false);
- if (is_pressed())
+ if (is_pressed()) {
_release();
+ }
}
} break;
case NOTIFICATION_PAUSED: {
- if (is_pressed())
+ if (is_pressed()) {
_release();
+ }
} break;
}
}
@@ -172,11 +186,13 @@ String TouchScreenButton::get_action() const {
}
void TouchScreenButton::_input(const Ref<InputEvent> &p_event) {
- if (!get_tree())
+ if (!get_tree()) {
return;
+ }
- if (p_event->get_device() != 0)
+ if (p_event->get_device() != 0) {
return;
+ }
ERR_FAIL_COND(!is_visible_in_tree());
@@ -210,8 +226,9 @@ void TouchScreenButton::_input(const Ref<InputEvent> &p_event) {
if (st) {
if (st->is_pressed()) {
const bool can_press = finger_pressed == -1;
- if (!can_press)
+ if (!can_press) {
return; //already fingering
+ }
if (_is_point_inside(st->get_position())) {
_press(st->get_index());
@@ -242,14 +259,16 @@ bool TouchScreenButton::_is_point_inside(const Point2 &p_point) {
if (bitmask.is_valid()) {
check_rect = false;
if (!touched && Rect2(Point2(), bitmask->get_size()).has_point(coord)) {
- if (bitmask->get_bit(coord))
+ if (bitmask->get_bit(coord)) {
touched = true;
+ }
}
}
if (!touched && check_rect) {
- if (texture.is_valid())
+ if (texture.is_valid()) {
touched = Rect2(Size2(), texture->get_size()).has_point(coord);
+ }
}
return touched;
@@ -293,8 +312,9 @@ void TouchScreenButton::_release(bool p_exiting_tree) {
#ifdef TOOLS_ENABLED
Rect2 TouchScreenButton::_edit_get_rect() const {
- if (texture.is_null())
+ if (texture.is_null()) {
return CanvasItem::_edit_get_rect();
+ }
return Rect2(Size2(), texture->get_size());
}
@@ -305,8 +325,9 @@ bool TouchScreenButton::_edit_use_rect() const {
#endif
Rect2 TouchScreenButton::get_anchorable_rect() const {
- if (texture.is_null())
+ if (texture.is_null()) {
return CanvasItem::get_anchorable_rect();
+ }
return Rect2(Size2(), texture->get_size());
}
diff --git a/scene/2d/visibility_notifier_2d.cpp b/scene/2d/visibility_notifier_2d.cpp
index 1f250bbdf6..75154c7acb 100644
--- a/scene/2d/visibility_notifier_2d.cpp
+++ b/scene/2d/visibility_notifier_2d.cpp
@@ -52,8 +52,9 @@ void VisibilityNotifier2D::_enter_viewport(Viewport *p_viewport) {
ERR_FAIL_COND(viewports.has(p_viewport));
viewports.insert(p_viewport);
- if (is_inside_tree() && Engine::get_singleton()->is_editor_hint())
+ if (is_inside_tree() && Engine::get_singleton()->is_editor_hint()) {
return;
+ }
if (viewports.size() == 1) {
emit_signal(SceneStringNames::get_singleton()->screen_entered);
@@ -67,8 +68,9 @@ void VisibilityNotifier2D::_exit_viewport(Viewport *p_viewport) {
ERR_FAIL_COND(!viewports.has(p_viewport));
viewports.erase(p_viewport);
- if (is_inside_tree() && Engine::get_singleton()->is_editor_hint())
+ if (is_inside_tree() && Engine::get_singleton()->is_editor_hint()) {
return;
+ }
emit_signal(SceneStringNames::get_singleton()->viewport_exited, p_viewport);
if (viewports.size() == 0) {
@@ -145,10 +147,12 @@ void VisibilityEnabler2D::_screen_enter() {
_change_node_state(E->key(), true);
}
- if (enabler[ENABLER_PARENT_PHYSICS_PROCESS] && get_parent())
+ if (enabler[ENABLER_PARENT_PHYSICS_PROCESS] && get_parent()) {
get_parent()->set_physics_process(true);
- if (enabler[ENABLER_PARENT_PROCESS] && get_parent())
+ }
+ if (enabler[ENABLER_PARENT_PROCESS] && get_parent()) {
get_parent()->set_process(true);
+ }
visible = true;
}
@@ -158,10 +162,12 @@ void VisibilityEnabler2D::_screen_exit() {
_change_node_state(E->key(), false);
}
- if (enabler[ENABLER_PARENT_PHYSICS_PROCESS] && get_parent())
+ if (enabler[ENABLER_PARENT_PHYSICS_PROCESS] && get_parent()) {
get_parent()->set_physics_process(false);
- if (enabler[ENABLER_PARENT_PROCESS] && get_parent())
+ }
+ if (enabler[ENABLER_PARENT_PROCESS] && get_parent()) {
get_parent()->set_process(false);
+ }
visible = false;
}
@@ -207,8 +213,9 @@ void VisibilityEnabler2D::_find_nodes(Node *p_node) {
for (int i = 0; i < p_node->get_child_count(); i++) {
Node *c = p_node->get_child(i);
- if (c->get_filename() != String())
+ if (c->get_filename() != String()) {
continue; //skip, instance
+ }
_find_nodes(c);
}
@@ -216,13 +223,15 @@ void VisibilityEnabler2D::_find_nodes(Node *p_node) {
void VisibilityEnabler2D::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE) {
- if (Engine::get_singleton()->is_editor_hint())
+ if (Engine::get_singleton()->is_editor_hint()) {
return;
+ }
Node *from = this;
//find where current scene starts
- while (from->get_parent() && from->get_filename() == String())
+ while (from->get_parent() && from->get_filename() == String()) {
from = from->get_parent();
+ }
_find_nodes(from);
@@ -242,12 +251,14 @@ void VisibilityEnabler2D::_notification(int p_what) {
}
if (p_what == NOTIFICATION_EXIT_TREE) {
- if (Engine::get_singleton()->is_editor_hint())
+ if (Engine::get_singleton()->is_editor_hint()) {
return;
+ }
for (Map<Node *, Variant>::Element *E = nodes.front(); E; E = E->next()) {
- if (!visible)
+ if (!visible) {
_change_node_state(E->key(), true);
+ }
E->key()->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &VisibilityEnabler2D::_node_removed));
}
@@ -277,10 +288,11 @@ void VisibilityEnabler2D::_change_node_state(Node *p_node, bool p_enabled) {
AnimatedSprite2D *as = Object::cast_to<AnimatedSprite2D>(p_node);
if (as) {
- if (p_enabled)
+ if (p_enabled) {
as->play();
- else
+ } else {
as->stop();
+ }
}
}
@@ -294,8 +306,9 @@ void VisibilityEnabler2D::_change_node_state(Node *p_node, bool p_enabled) {
}
void VisibilityEnabler2D::_node_removed(Node *p_node) {
- if (!visible)
+ if (!visible) {
_change_node_state(p_node, true);
+ }
nodes.erase(p_node);
}
@@ -340,8 +353,9 @@ bool VisibilityEnabler2D::is_enabler_enabled(Enabler p_enabler) const {
}
VisibilityEnabler2D::VisibilityEnabler2D() {
- for (int i = 0; i < ENABLER_MAX; i++)
+ for (int i = 0; i < ENABLER_MAX; i++) {
enabler[i] = true;
+ }
enabler[ENABLER_PARENT_PROCESS] = false;
enabler[ENABLER_PARENT_PHYSICS_PROCESS] = false;
diff --git a/scene/3d/area_3d.cpp b/scene/3d/area_3d.cpp
index 3b5b6c0dd6..a024757927 100644
--- a/scene/3d/area_3d.cpp
+++ b/scene/3d/area_3d.cpp
@@ -165,8 +165,9 @@ void Area3D::_body_inout(int p_status, const RID &p_body, ObjectID p_instance, i
}
}
E->get().rc++;
- if (node)
+ if (node) {
E->get().shapes.insert(ShapePair(p_body_shape, p_area_shape));
+ }
if (E->get().in_tree) {
emit_signal(SceneStringNames::get_singleton()->body_shape_entered, objid, node, p_body_shape, p_area_shape);
@@ -175,8 +176,9 @@ void Area3D::_body_inout(int p_status, const RID &p_body, ObjectID p_instance, i
} else {
E->get().rc--;
- if (node)
+ if (node) {
E->get().shapes.erase(ShapePair(p_body_shape, p_area_shape));
+ }
bool eraseit = false;
@@ -184,8 +186,9 @@ void Area3D::_body_inout(int p_status, const RID &p_body, ObjectID p_instance, i
if (node) {
node->disconnect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &Area3D::_body_enter_tree));
node->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &Area3D::_body_exit_tree));
- if (E->get().in_tree)
+ if (E->get().in_tree) {
emit_signal(SceneStringNames::get_singleton()->body_exited, obj);
+ }
}
eraseit = true;
@@ -194,8 +197,9 @@ void Area3D::_body_inout(int p_status, const RID &p_body, ObjectID p_instance, i
emit_signal(SceneStringNames::get_singleton()->body_shape_exited, objid, obj, p_body_shape, p_area_shape);
}
- if (eraseit)
+ if (eraseit) {
body_map.erase(E);
+ }
}
locked = false;
@@ -213,12 +217,14 @@ void Area3D::_clear_monitoring() {
Object *obj = ObjectDB::get_instance(E->key());
Node *node = Object::cast_to<Node>(obj);
- if (!node) //node may have been deleted in previous frame or at other legiminate point
+ if (!node) { //node may have been deleted in previous frame or at other legiminate point
continue;
+ }
//ERR_CONTINUE(!node);
- if (!E->get().in_tree)
+ if (!E->get().in_tree) {
continue;
+ }
for (int i = 0; i < E->get().shapes.size(); i++) {
emit_signal(SceneStringNames::get_singleton()->body_shape_exited, E->key(), node, E->get().shapes[i].body_shape, E->get().shapes[i].area_shape);
@@ -240,12 +246,14 @@ void Area3D::_clear_monitoring() {
Object *obj = ObjectDB::get_instance(E->key());
Node *node = Object::cast_to<Node>(obj);
- if (!node) //node may have been deleted in previous frame or at other legiminate point
+ if (!node) { //node may have been deleted in previous frame or at other legiminate point
continue;
+ }
//ERR_CONTINUE(!node);
- if (!E->get().in_tree)
+ if (!E->get().in_tree) {
continue;
+ }
for (int i = 0; i < E->get().shapes.size(); i++) {
emit_signal(SceneStringNames::get_singleton()->area_shape_exited, E->key(), node, E->get().shapes[i].area_shape, E->get().shapes[i].self_shape);
@@ -268,8 +276,9 @@ void Area3D::_notification(int p_what) {
void Area3D::set_monitoring(bool p_enable) {
ERR_FAIL_COND_MSG(locked, "Function blocked during in/out signal. Use set_deferred(\"monitoring\", true/false).");
- if (p_enable == monitoring)
+ if (p_enable == monitoring) {
return;
+ }
monitoring = p_enable;
@@ -342,8 +351,9 @@ void Area3D::_area_inout(int p_status, const RID &p_area, ObjectID p_instance, i
}
}
E->get().rc++;
- if (node)
+ if (node) {
E->get().shapes.insert(AreaShapePair(p_area_shape, p_self_shape));
+ }
if (!node || E->get().in_tree) {
emit_signal(SceneStringNames::get_singleton()->area_shape_entered, objid, node, p_area_shape, p_self_shape);
@@ -352,8 +362,9 @@ void Area3D::_area_inout(int p_status, const RID &p_area, ObjectID p_instance, i
} else {
E->get().rc--;
- if (node)
+ if (node) {
E->get().shapes.erase(AreaShapePair(p_area_shape, p_self_shape));
+ }
bool eraseit = false;
@@ -372,8 +383,9 @@ void Area3D::_area_inout(int p_status, const RID &p_area, ObjectID p_instance, i
emit_signal(SceneStringNames::get_singleton()->area_shape_exited, objid, obj, p_area_shape, p_self_shape);
}
- if (eraseit)
+ if (eraseit) {
area_map.erase(E);
+ }
}
locked = false;
@@ -403,8 +415,9 @@ TypedArray<Node3D> Area3D::get_overlapping_bodies() const {
void Area3D::set_monitorable(bool p_enable) {
ERR_FAIL_COND_MSG(locked || (is_inside_tree() && PhysicsServer3D::get_singleton()->is_flushing_queries()), "Function blocked during in/out signal. Use set_deferred(\"monitorable\", true/false).");
- if (p_enable == monitorable)
+ if (p_enable == monitorable) {
return;
+ }
monitorable = p_enable;
@@ -435,16 +448,18 @@ TypedArray<Area3D> Area3D::get_overlapping_areas() const {
bool Area3D::overlaps_area(Node *p_area) const {
ERR_FAIL_NULL_V(p_area, false);
const Map<ObjectID, AreaState>::Element *E = area_map.find(p_area->get_instance_id());
- if (!E)
+ if (!E) {
return false;
+ }
return E->get().in_tree;
}
bool Area3D::overlaps_body(Node *p_body) const {
ERR_FAIL_NULL_V(p_body, false);
const Map<ObjectID, BodyState>::Element *E = body_map.find(p_body->get_instance_id());
- if (!E)
+ if (!E) {
return false;
+ }
return E->get().in_tree;
}
@@ -468,10 +483,11 @@ uint32_t Area3D::get_collision_layer() const {
void Area3D::set_collision_mask_bit(int p_bit, bool p_value) {
uint32_t mask = get_collision_mask();
- if (p_value)
+ if (p_value) {
mask |= 1 << p_bit;
- else
+ } else {
mask &= ~(1 << p_bit);
+ }
set_collision_mask(mask);
}
@@ -481,10 +497,11 @@ bool Area3D::get_collision_mask_bit(int p_bit) const {
void Area3D::set_collision_layer_bit(int p_bit, bool p_value) {
uint32_t layer = get_collision_layer();
- if (p_value)
+ if (p_value) {
layer |= 1 << p_bit;
- else
+ } else {
layer &= ~(1 << p_bit);
+ }
set_collision_layer(layer);
}
@@ -554,8 +571,9 @@ void Area3D::_validate_property(PropertyInfo &property) const {
if (property.name == "audio_bus_name" || property.name == "reverb_bus_name") {
String options;
for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) {
- if (i > 0)
+ if (i > 0) {
options += ",";
+ }
String name = AudioServer::get_singleton()->get_bus_name(i);
options += name;
}
diff --git a/scene/3d/area_3d.h b/scene/3d/area_3d.h
index 377cf3ccbb..98f337d3e4 100644
--- a/scene/3d/area_3d.h
+++ b/scene/3d/area_3d.h
@@ -70,10 +70,11 @@ private:
int body_shape;
int area_shape;
bool operator<(const ShapePair &p_sp) const {
- if (body_shape == p_sp.body_shape)
+ if (body_shape == p_sp.body_shape) {
return area_shape < p_sp.area_shape;
- else
+ } else {
return body_shape < p_sp.body_shape;
+ }
}
ShapePair() {}
@@ -100,10 +101,11 @@ private:
int area_shape;
int self_shape;
bool operator<(const AreaShapePair &p_sp) const {
- if (area_shape == p_sp.area_shape)
+ if (area_shape == p_sp.area_shape) {
return self_shape < p_sp.self_shape;
- else
+ } else {
return area_shape < p_sp.area_shape;
+ }
}
AreaShapePair() {}
diff --git a/scene/3d/audio_stream_player_3d.cpp b/scene/3d/audio_stream_player_3d.cpp
index 4f37087d7e..6e4db8f382 100644
--- a/scene/3d/audio_stream_player_3d.cpp
+++ b/scene/3d/audio_stream_player_3d.cpp
@@ -213,8 +213,9 @@ void AudioStreamPlayer3D::_mix_audio() {
AudioFrame vol_inc = (target_volume - vol_prev) / float(buffer_size);
AudioFrame vol = vol_prev;
- if (!AudioServer::get_singleton()->thread_has_channel_mix_buffer(current.bus_index, k))
+ if (!AudioServer::get_singleton()->thread_has_channel_mix_buffer(current.bus_index, k)) {
continue; //may have been deleted, will be updated on process
+ }
AudioFrame *target = AudioServer::get_singleton()->thread_get_channel_mix_buffer(current.bus_index, k);
current.filter.set_mode(AudioFilterSW::HIGHSHELF);
@@ -258,8 +259,9 @@ void AudioStreamPlayer3D::_mix_audio() {
}
if (current.reverb_bus_index >= 0) {
- if (!AudioServer::get_singleton()->thread_has_channel_mix_buffer(current.reverb_bus_index, k))
+ if (!AudioServer::get_singleton()->thread_has_channel_mix_buffer(current.reverb_bus_index, k)) {
continue; //may have been deleted, will be updated on process
+ }
AudioFrame *rtarget = AudioServer::get_singleton()->thread_get_channel_mix_buffer(current.reverb_bus_index, k);
@@ -388,15 +390,18 @@ void AudioStreamPlayer3D::_notification(int p_what) {
Area3D *area = nullptr;
for (int i = 0; i < areas; i++) {
- if (!sr[i].collider)
+ if (!sr[i].collider) {
continue;
+ }
Area3D *tarea = Object::cast_to<Area3D>(sr[i].collider);
- if (!tarea)
+ if (!tarea) {
continue;
+ }
- if (!tarea->is_overriding_audio_bus() && !tarea->is_using_reverb_bus())
+ if (!tarea->is_overriding_audio_bus() && !tarea->is_using_reverb_bus()) {
continue;
+ }
area = tarea;
break;
@@ -408,8 +413,9 @@ void AudioStreamPlayer3D::_notification(int p_what) {
for (List<Camera3D *>::Element *E = cameras.front(); E; E = E->next()) {
Camera3D *camera = E->get();
Viewport *vp = camera->get_viewport();
- if (!vp->is_audio_listener())
+ if (!vp->is_audio_listener()) {
continue;
+ }
bool listener_is_camera = true;
Node3D *listener_node = camera;
@@ -459,8 +465,9 @@ void AudioStreamPlayer3D::_notification(int p_what) {
Vector3 listenertopos = global_pos - listener_node->get_global_transform().origin;
float c = listenertopos.normalized().dot(get_global_transform().basis.get_axis(2).normalized()); //it's z negative
float angle = Math::rad2deg(Math::acos(c));
- if (angle > emission_angle)
+ if (angle > emission_angle) {
db_att -= -emission_angle_filter_attenuation_db;
+ }
}
output.filter_gain = Math::db2linear(db_att);
@@ -587,8 +594,9 @@ void AudioStreamPlayer3D::_notification(int p_what) {
outputs[new_output_count] = output;
new_output_count++;
- if (new_output_count == MAX_OUTPUTS)
+ if (new_output_count == MAX_OUTPUTS) {
break;
+ }
}
output_count = new_output_count;
@@ -744,10 +752,11 @@ bool AudioStreamPlayer3D::is_autoplay_enabled() {
}
void AudioStreamPlayer3D::_set_playing(bool p_enable) {
- if (p_enable)
+ if (p_enable) {
play();
- else
+ } else {
stop();
+ }
}
bool AudioStreamPlayer3D::_is_active() const {
@@ -758,8 +767,9 @@ void AudioStreamPlayer3D::_validate_property(PropertyInfo &property) const {
if (property.name == "bus") {
String options;
for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) {
- if (i > 0)
+ if (i > 0) {
options += ",";
+ }
String name = AudioServer::get_singleton()->get_bus_name(i);
options += name;
}
@@ -852,8 +862,9 @@ AudioStreamPlayer3D::OutOfRangeMode AudioStreamPlayer3D::get_out_of_range_mode()
}
void AudioStreamPlayer3D::set_doppler_tracking(DopplerTracking p_tracking) {
- if (doppler_tracking == p_tracking)
+ if (doppler_tracking == p_tracking) {
return;
+ }
doppler_tracking = p_tracking;
diff --git a/scene/3d/baked_lightmap.cpp b/scene/3d/baked_lightmap.cpp
index 33db919d49..e2f1b3807d 100644
--- a/scene/3d/baked_lightmap.cpp
+++ b/scene/3d/baked_lightmap.cpp
@@ -275,8 +275,9 @@ void BakedLightmap::_find_meshes_and_lights(Node *p_at_node, Vector<MeshesFound>
Transform xf = get_global_transform().affine_inverse() * s->get_global_transform();
for (int i = 0; i < bmeshes.size(); i += 2) {
Ref<Mesh> mesh = bmeshes[i];
- if (!mesh.is_valid())
+ if (!mesh.is_valid()) {
continue;
+ }
MeshesFound mf;
@@ -310,8 +311,9 @@ void BakedLightmap::_find_meshes_and_lights(Node *p_at_node, Vector<MeshesFound>
for (int i = 0; i < p_at_node->get_child_count(); i++) {
Node *child = p_at_node->get_child(i);
- if (!child->get_owner())
+ if (!child->get_owner()) {
continue; //maybe a helper
+ }
_find_meshes_and_lights(child, meshes, lights, probes);
}
@@ -557,8 +559,9 @@ void BakedLightmap::_plot_triangle_into_octree(GenProbesOctree *p_cell, float p_
subcell.position = Vector3(pos) * p_cell_size;
subcell.size = Vector3(half_size, half_size, half_size) * p_cell_size;
- if (!Geometry::triangle_box_overlap(subcell.position + subcell.size * 0.5, subcell.size * 0.5, p_triangle))
+ if (!Geometry::triangle_box_overlap(subcell.position + subcell.size * 0.5, subcell.size * 0.5, p_triangle)) {
continue;
+ }
if (p_cell->children[i] == nullptr) {
GenProbesOctree *child = memnew(GenProbesOctree);
diff --git a/scene/3d/bone_attachment_3d.cpp b/scene/3d/bone_attachment_3d.cpp
index 5e4b995aa1..68303bbfe5 100644
--- a/scene/3d/bone_attachment_3d.cpp
+++ b/scene/3d/bone_attachment_3d.cpp
@@ -37,8 +37,9 @@ void BoneAttachment3D::_validate_property(PropertyInfo &property) const {
if (parent) {
String names;
for (int i = 0; i < parent->get_bone_count(); i++) {
- if (i > 0)
+ if (i > 0) {
names += ",";
+ }
names += parent->get_bone_name(i);
}
@@ -77,13 +78,15 @@ void BoneAttachment3D::_check_unbind() {
}
void BoneAttachment3D::set_bone_name(const String &p_name) {
- if (is_inside_tree())
+ if (is_inside_tree()) {
_check_unbind();
+ }
bone_name = p_name;
- if (is_inside_tree())
+ if (is_inside_tree()) {
_check_bind();
+ }
}
String BoneAttachment3D::get_bone_name() const {
diff --git a/scene/3d/camera_3d.cpp b/scene/3d/camera_3d.cpp
index 99d3b68996..8dc5cd4aba 100644
--- a/scene/3d/camera_3d.cpp
+++ b/scene/3d/camera_3d.cpp
@@ -75,8 +75,9 @@ void Camera3D::_validate_property(PropertyInfo &p_property) const {
}
void Camera3D::_update_camera() {
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
RenderingServer::get_singleton()->camera_set_transform(camera, get_camera_transform());
@@ -86,8 +87,9 @@ void Camera3D::_update_camera() {
get_viewport()->_camera_transform_changed_notify();
*/
- if (get_tree()->is_node_being_edited(this) || !is_current())
+ if (get_tree()->is_node_being_edited(this) || !is_current()) {
return;
+ }
get_viewport()->_camera_transform_changed_notify();
@@ -106,8 +108,9 @@ void Camera3D::_notification(int p_what) {
ERR_FAIL_COND(!viewport);
bool first_camera = viewport->_camera_add(this);
- if (current || first_camera)
+ if (current || first_camera) {
viewport->_camera_set(this);
+ }
} break;
case NOTIFICATION_TRANSFORM_CHANGED: {
@@ -154,8 +157,9 @@ Transform Camera3D::get_camera_transform() const {
}
void Camera3D::set_perspective(float p_fovy_degrees, float p_z_near, float p_z_far) {
- if (!force_change && fov == p_fovy_degrees && p_z_near == near && p_z_far == far && mode == PROJECTION_PERSPECTIVE)
+ if (!force_change && fov == p_fovy_degrees && p_z_near == near && p_z_far == far && mode == PROJECTION_PERSPECTIVE) {
return;
+ }
fov = p_fovy_degrees;
near = p_z_near;
@@ -168,8 +172,9 @@ void Camera3D::set_perspective(float p_fovy_degrees, float p_z_near, float p_z_f
}
void Camera3D::set_orthogonal(float p_size, float p_z_near, float p_z_far) {
- if (!force_change && size == p_size && p_z_near == near && p_z_far == far && mode == PROJECTION_ORTHOGONAL)
+ if (!force_change && size == p_size && p_z_near == near && p_z_far == far && mode == PROJECTION_ORTHOGONAL) {
return;
+ }
size = p_size;
@@ -183,8 +188,9 @@ void Camera3D::set_orthogonal(float p_size, float p_z_near, float p_z_far) {
}
void Camera3D::set_frustum(float p_size, Vector2 p_offset, float p_z_near, float p_z_far) {
- if (!force_change && size == p_size && frustum_offset == p_offset && p_z_near == near && p_z_far == far && mode == PROJECTION_FRUSTUM)
+ if (!force_change && size == p_size && frustum_offset == p_offset && p_z_near == near && p_z_far == far && mode == PROJECTION_FRUSTUM) {
return;
+ }
size = p_size;
frustum_offset = p_offset;
@@ -213,8 +219,9 @@ RID Camera3D::get_camera() const {
void Camera3D::make_current() {
current = true;
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
get_viewport()->_camera_set(this);
@@ -223,8 +230,9 @@ void Camera3D::make_current() {
void Camera3D::clear_current(bool p_enable_next) {
current = false;
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
if (get_viewport()->get_camera() == this) {
get_viewport()->_camera_set(nullptr);
@@ -246,8 +254,9 @@ void Camera3D::set_current(bool p_current) {
bool Camera3D::is_current() const {
if (is_inside_tree() && !get_tree()->is_node_being_edited(this)) {
return get_viewport()->get_camera() == this;
- } else
+ } else {
return current;
+ }
}
bool Camera3D::_can_gizmo_scale() const {
@@ -320,10 +329,11 @@ Vector<Vector3> Camera3D::get_near_plane_points() const {
CameraMatrix cm;
- if (mode == PROJECTION_ORTHOGONAL)
+ if (mode == PROJECTION_ORTHOGONAL) {
cm.set_orthogonal(size, viewport_size.aspect(), near, far, keep_aspect == KEEP_WIDTH);
- else
+ } else {
cm.set_perspective(fov, viewport_size.aspect(), near, far, keep_aspect == KEEP_WIDTH);
+ }
Vector3 endpoints[8];
cm.get_endpoints(Transform(), endpoints);
@@ -343,10 +353,11 @@ Point2 Camera3D::unproject_position(const Vector3 &p_pos) const {
CameraMatrix cm;
- if (mode == PROJECTION_ORTHOGONAL)
+ if (mode == PROJECTION_ORTHOGONAL) {
cm.set_orthogonal(size, viewport_size.aspect(), near, far, keep_aspect == KEEP_WIDTH);
- else
+ } else {
cm.set_perspective(fov, viewport_size.aspect(), near, far, keep_aspect == KEEP_WIDTH);
+ }
Plane p(get_camera_transform().xform_inv(p_pos), 1.0);
@@ -370,10 +381,11 @@ Vector3 Camera3D::project_position(const Point2 &p_point, float p_z_depth) const
CameraMatrix cm;
- if (mode == PROJECTION_ORTHOGONAL)
+ if (mode == PROJECTION_ORTHOGONAL) {
cm.set_orthogonal(size, viewport_size.aspect(), p_z_depth, far, keep_aspect == KEEP_WIDTH);
- else
+ } else {
cm.set_perspective(fov, viewport_size.aspect(), p_z_depth, far, keep_aspect == KEEP_WIDTH);
+ }
Vector2 vp_he = cm.get_viewport_half_extents();
@@ -389,10 +401,11 @@ Vector3 Camera3D::project_position(const Point2 &p_point, float p_z_depth) const
void Camera3D::set_environment(const Ref<Environment> &p_environment) {
environment = p_environment;
- if (environment.is_valid())
+ if (environment.is_valid()) {
RS::get_singleton()->camera_set_environment(camera, environment->get_rid());
- else
+ } else {
RS::get_singleton()->camera_set_environment(camera, RID());
+ }
_update_camera_mode();
}
@@ -402,10 +415,11 @@ Ref<Environment> Camera3D::get_environment() const {
void Camera3D::set_effects(const Ref<CameraEffects> &p_effects) {
effects = p_effects;
- if (effects.is_valid())
+ if (effects.is_valid()) {
RS::get_singleton()->camera_set_camera_effects(camera, effects->get_rid());
- else
+ } else {
RS::get_singleton()->camera_set_camera_effects(camera, RID());
+ }
_update_camera_mode();
}
@@ -425,8 +439,9 @@ Camera3D::KeepAspect Camera3D::get_keep_aspect_mode() const {
}
void Camera3D::set_doppler_tracking(DopplerTracking p_tracking) {
- if (doppler_tracking == p_tracking)
+ if (doppler_tracking == p_tracking) {
return;
+ }
doppler_tracking = p_tracking;
if (p_tracking != DOPPLER_TRACKING_DISABLED) {
@@ -600,10 +615,11 @@ Vector<Plane> Camera3D::get_frustum() const {
Size2 viewport_size = get_viewport()->get_visible_rect().size;
CameraMatrix cm;
- if (mode == PROJECTION_PERSPECTIVE)
+ if (mode == PROJECTION_PERSPECTIVE) {
cm.set_perspective(fov, viewport_size.aspect(), near, far, keep_aspect == KEEP_WIDTH);
- else
+ } else {
cm.set_orthogonal(size, viewport_size.aspect(), near, far, keep_aspect == KEEP_WIDTH);
+ }
return cm.get_projection_planes(get_camera_transform());
}
@@ -761,10 +777,11 @@ uint32_t ClippedCamera3D::get_collision_mask() const {
void ClippedCamera3D::set_collision_mask_bit(int p_bit, bool p_value) {
uint32_t mask = get_collision_mask();
- if (p_value)
+ if (p_value) {
mask |= 1 << p_bit;
- else
+ } else {
mask &= ~(1 << p_bit);
+ }
set_collision_mask(mask);
}
@@ -779,8 +796,9 @@ void ClippedCamera3D::add_exception_rid(const RID &p_rid) {
void ClippedCamera3D::add_exception(const Object *p_object) {
ERR_FAIL_NULL(p_object);
const CollisionObject3D *co = Object::cast_to<CollisionObject3D>(p_object);
- if (!co)
+ if (!co) {
return;
+ }
add_exception_rid(co->get_rid());
}
@@ -791,8 +809,9 @@ void ClippedCamera3D::remove_exception_rid(const RID &p_rid) {
void ClippedCamera3D::remove_exception(const Object *p_object) {
ERR_FAIL_NULL(p_object);
const CollisionObject3D *co = Object::cast_to<CollisionObject3D>(p_object);
- if (!co)
+ if (!co) {
return;
+ }
remove_exception_rid(co->get_rid());
}
diff --git a/scene/3d/collision_object_3d.cpp b/scene/3d/collision_object_3d.cpp
index f1ca3770e0..356992e922 100644
--- a/scene/3d/collision_object_3d.cpp
+++ b/scene/3d/collision_object_3d.cpp
@@ -36,26 +36,29 @@
void CollisionObject3D::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_WORLD: {
- if (area)
+ if (area) {
PhysicsServer3D::get_singleton()->area_set_transform(rid, get_global_transform());
- else
+ } else {
PhysicsServer3D::get_singleton()->body_set_state(rid, PhysicsServer3D::BODY_STATE_TRANSFORM, get_global_transform());
+ }
RID space = get_world_3d()->get_space();
if (area) {
PhysicsServer3D::get_singleton()->area_set_space(rid, space);
- } else
+ } else {
PhysicsServer3D::get_singleton()->body_set_space(rid, space);
+ }
_update_pickable();
//get space
} break;
case NOTIFICATION_TRANSFORM_CHANGED: {
- if (area)
+ if (area) {
PhysicsServer3D::get_singleton()->area_set_transform(rid, get_global_transform());
- else
+ } else {
PhysicsServer3D::get_singleton()->body_set_state(rid, PhysicsServer3D::BODY_STATE_TRANSFORM, get_global_transform());
+ }
} break;
case NOTIFICATION_VISIBILITY_CHANGED: {
@@ -65,8 +68,9 @@ void CollisionObject3D::_notification(int p_what) {
case NOTIFICATION_EXIT_WORLD: {
if (area) {
PhysicsServer3D::get_singleton()->area_set_space(rid, RID());
- } else
+ } else {
PhysicsServer3D::get_singleton()->body_set_space(rid, RID());
+ }
} break;
}
@@ -94,14 +98,16 @@ void CollisionObject3D::_mouse_exit() {
}
void CollisionObject3D::_update_pickable() {
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
bool pickable = ray_pickable && is_visible_in_tree();
- if (area)
+ if (area) {
PhysicsServer3D::get_singleton()->area_set_ray_pickable(rid, pickable);
- else
+ } else {
PhysicsServer3D::get_singleton()->body_set_ray_pickable(rid, pickable);
+ }
}
void CollisionObject3D::set_ray_pickable(bool p_ray_pickable) {
diff --git a/scene/3d/collision_polygon_3d.cpp b/scene/3d/collision_polygon_3d.cpp
index 4a87ce0def..bad4a1fddd 100644
--- a/scene/3d/collision_polygon_3d.cpp
+++ b/scene/3d/collision_polygon_3d.cpp
@@ -35,17 +35,20 @@
#include "scene/resources/convex_polygon_shape_3d.h"
void CollisionPolygon3D::_build_polygon() {
- if (!parent)
+ if (!parent) {
return;
+ }
parent->shape_owner_clear_shapes(owner_id);
- if (polygon.size() == 0)
+ if (polygon.size() == 0) {
return;
+ }
Vector<Vector<Vector2>> decomp = Geometry::decompose_polygon_in_convex(polygon);
- if (decomp.size() == 0)
+ if (decomp.size() == 0) {
return;
+ }
//here comes the sun, lalalala
//decompose concave into multiple convex polygons and add them
@@ -73,8 +76,9 @@ void CollisionPolygon3D::_build_polygon() {
void CollisionPolygon3D::_update_in_shape_owner(bool p_xform_only) {
parent->shape_owner_set_transform(owner_id, get_transform());
- if (p_xform_only)
+ if (p_xform_only) {
return;
+ }
parent->shape_owner_set_disabled(owner_id, disabled);
}
diff --git a/scene/3d/collision_shape_3d.cpp b/scene/3d/collision_shape_3d.cpp
index 711dfd6fb9..56367e9bdd 100644
--- a/scene/3d/collision_shape_3d.cpp
+++ b/scene/3d/collision_shape_3d.cpp
@@ -46,8 +46,9 @@
void CollisionShape3D::make_convex_from_brothers() {
Node *p = get_parent();
- if (!p)
+ if (!p) {
return;
+ }
for (int i = 0; i < p->get_child_count(); i++) {
Node *n = p->get_child(i);
@@ -64,8 +65,9 @@ void CollisionShape3D::make_convex_from_brothers() {
void CollisionShape3D::_update_in_shape_owner(bool p_xform_only) {
parent->shape_owner_set_transform(owner_id, get_transform());
- if (p_xform_only)
+ if (p_xform_only) {
return;
+ }
parent->shape_owner_set_disabled(owner_id, disabled);
}
@@ -162,8 +164,9 @@ void CollisionShape3D::set_shape(const Ref<Shape3D> &p_shape) {
}
}
- if (is_inside_tree())
+ if (is_inside_tree()) {
_shape_changed();
+ }
update_configuration_warning();
}
@@ -193,8 +196,9 @@ CollisionShape3D::CollisionShape3D() {
}
CollisionShape3D::~CollisionShape3D() {
- if (!shape.is_null())
+ if (!shape.is_null()) {
shape->unregister_owner(this);
+ }
//RenderingServer::get_singleton()->free(indicator);
}
@@ -207,8 +211,9 @@ void CollisionShape3D::_update_debug_shape() {
}
Ref<Shape3D> s = get_shape();
- if (s.is_null())
+ if (s.is_null()) {
return;
+ }
Ref<Mesh> mesh = s->get_debug_mesh();
MeshInstance3D *mi = memnew(MeshInstance3D);
diff --git a/scene/3d/cpu_particles_3d.cpp b/scene/3d/cpu_particles_3d.cpp
index cd80607692..4244a11592 100644
--- a/scene/3d/cpu_particles_3d.cpp
+++ b/scene/3d/cpu_particles_3d.cpp
@@ -44,16 +44,18 @@ Vector<Face3> CPUParticles3D::get_faces(uint32_t p_usage_flags) const {
}
void CPUParticles3D::set_emitting(bool p_emitting) {
- if (emitting == p_emitting)
+ if (emitting == p_emitting) {
return;
+ }
emitting = p_emitting;
if (emitting) {
set_process_internal(true);
// first update before rendering to avoid one frame delay after emitting starts
- if (time == 0)
+ if (time == 0) {
_update_internal();
+ }
}
}
@@ -206,15 +208,17 @@ String CPUParticles3D::get_configuration_warning() const {
anim_material_found = anim_material_found || (spat && spat->get_billboard_mode() == StandardMaterial3D::BILLBOARD_PARTICLES);
if (!mesh_found) {
- if (warnings != String())
+ if (warnings != String()) {
warnings += "\n";
+ }
warnings += "- " + TTR("Nothing is visible because no mesh has been assigned.");
}
if (!anim_material_found && (get_param(PARAM_ANIM_SPEED) != 0.0 || get_param(PARAM_ANIM_OFFSET) != 0.0 ||
get_param_curve(PARAM_ANIM_SPEED).is_valid() || get_param_curve(PARAM_ANIM_OFFSET).is_valid())) {
- if (warnings != String())
+ if (warnings != String()) {
warnings += "\n";
+ }
warnings += "- " + TTR("CPUParticles3D animation requires the usage of a StandardMaterial3D whose Billboard Mode is set to \"Particle Billboard\".");
}
@@ -290,8 +294,9 @@ float CPUParticles3D::get_param_randomness(Parameter p_param) const {
static void _adjust_curve_range(const Ref<Curve> &p_curve, float p_min, float p_max) {
Ref<Curve> curve = p_curve;
- if (!curve.is_valid())
+ if (!curve.is_valid()) {
return;
+ }
curve->ensure_default_setup(p_min, p_max);
}
@@ -469,12 +474,14 @@ static uint32_t idhash(uint32_t x) {
static float rand_from_seed(uint32_t &seed) {
int k;
int s = int(seed);
- if (s == 0)
+ if (s == 0) {
s = 305420679;
+ }
k = s / 127773;
s = 16807 * (s - k * 127773) - 2836 * k;
- if (s < 0)
+ if (s < 0) {
s += 2147483647;
+ }
seed = uint32_t(s);
return float(seed % uint32_t(65536)) / 65535.0;
}
@@ -508,10 +515,11 @@ void CPUParticles3D::_update_internal() {
if (time == 0 && pre_process_time > 0.0) {
float frame_time;
- if (fixed_fps > 0)
+ if (fixed_fps > 0) {
frame_time = 1.0 / fixed_fps;
- else
+ } else {
frame_time = 1.0 / 30.0;
+ }
float todo = pre_process_time;
@@ -583,8 +591,9 @@ void CPUParticles3D::_particles_process(float p_delta) {
for (int i = 0; i < pcount; i++) {
Particle &p = parray[i];
- if (!emitting && !p.active)
+ if (!emitting && !p.active) {
continue;
+ }
float local_delta = p_delta;
@@ -707,8 +716,9 @@ void CPUParticles3D::_particles_process(float p_delta) {
case EMISSION_SHAPE_POINTS:
case EMISSION_SHAPE_DIRECTED_POINTS: {
int pc = emission_points.size();
- if (pc == 0)
+ if (pc == 0) {
break;
+ }
int random_idx = Math::rand() % pc;
@@ -955,8 +965,9 @@ void CPUParticles3D::_particles_process(float p_delta) {
//scale by scale
float base_scale = tex_scale * Math::lerp(parameters[PARAM_SCALE], 1.0f, p.scale_rand * randomness[PARAM_SCALE]);
- if (base_scale < 0.000001)
+ if (base_scale < 0.000001) {
base_scale = 0.000001;
+ }
p.transform.basis.scale(Vector3(1, 1, 1) * base_scale);
@@ -1058,8 +1069,9 @@ void CPUParticles3D::_update_particle_data_buffer() {
}
void CPUParticles3D::_set_redraw(bool p_redraw) {
- if (redraw == p_redraw)
+ if (redraw == p_redraw) {
return;
+ }
redraw = p_redraw;
{
@@ -1093,8 +1105,9 @@ void CPUParticles3D::_notification(int p_what) {
set_process_internal(emitting);
// first update before rendering to avoid one frame delay after emitting starts
- if (emitting && (time == 0))
+ if (emitting && (time == 0)) {
_update_internal();
+ }
}
if (p_what == NOTIFICATION_EXIT_TREE) {
@@ -1103,8 +1116,9 @@ void CPUParticles3D::_notification(int p_what) {
if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
// first update before rendering to avoid one frame delay after emitting starts
- if (emitting && (time == 0))
+ if (emitting && (time == 0)) {
_update_internal();
+ }
}
if (p_what == NOTIFICATION_INTERNAL_PROCESS) {
@@ -1168,8 +1182,9 @@ void CPUParticles3D::convert_from_particles(Node *p_particles) {
set_mesh(particles->get_draw_pass_mesh(0));
Ref<ParticlesMaterial> material = particles->get_process_material();
- if (material.is_null())
+ if (material.is_null()) {
return;
+ }
set_direction(material->get_direction());
set_spread(material->get_spread());
diff --git a/scene/3d/gi_probe.cpp b/scene/3d/gi_probe.cpp
index 97040f55ef..1b6f9b45b9 100644
--- a/scene/3d/gi_probe.cpp
+++ b/scene/3d/gi_probe.cpp
@@ -371,8 +371,9 @@ void GIProbe::_find_meshes(Node *p_at_node, List<PlotMesh> &plot_meshes) {
for (int i = 0; i < meshes.size(); i += 2) {
Transform mxf = meshes[i];
Ref<Mesh> mesh = meshes[i + 1];
- if (!mesh.is_valid())
+ if (!mesh.is_valid()) {
continue;
+ }
AABB aabb = mesh->get_aabb();
@@ -407,8 +408,9 @@ Vector3i GIProbe::get_estimated_cell_size() const {
axis_cell_size[longest_axis] = 1 << cell_subdiv;
for (int i = 0; i < 3; i++) {
- if (i == longest_axis)
+ if (i == longest_axis) {
continue;
+ }
axis_cell_size[i] = axis_cell_size[longest_axis];
float axis_size = bounds.size[longest_axis];
@@ -474,8 +476,9 @@ void GIProbe::bake(Node *p_from_node, bool p_create_visual_debug) {
} else {
Ref<GIProbeData> probe_data = get_probe_data();
- if (probe_data.is_null())
+ if (probe_data.is_null()) {
probe_data.instance();
+ }
if (bake_step_function) {
bake_step_function(pmc++, RTR("Generating Distance Field"));
diff --git a/scene/3d/gpu_particles_3d.cpp b/scene/3d/gpu_particles_3d.cpp
index a87b57bd4d..c4480e3ed2 100644
--- a/scene/3d/gpu_particles_3d.cpp
+++ b/scene/3d/gpu_particles_3d.cpp
@@ -71,12 +71,14 @@ void GPUParticles3D::set_one_shot(bool p_one_shot) {
if (is_emitting()) {
set_process_internal(true);
- if (!one_shot)
+ if (!one_shot) {
RenderingServer::get_singleton()->particles_restart(particles);
+ }
}
- if (!one_shot)
+ if (!one_shot) {
set_process_internal(false);
+ }
}
void GPUParticles3D::set_pre_process_time(float p_time) {
@@ -109,8 +111,9 @@ void GPUParticles3D::set_use_local_coordinates(bool p_enable) {
void GPUParticles3D::set_process_material(const Ref<Material> &p_material) {
process_material = p_material;
RID material_rid;
- if (process_material.is_valid())
+ if (process_material.is_valid()) {
material_rid = process_material->get_rid();
+ }
RS::get_singleton()->particles_set_process_material(particles, material_rid);
update_configuration_warning();
@@ -191,8 +194,9 @@ void GPUParticles3D::set_draw_pass_mesh(int p_pass, const Ref<Mesh> &p_mesh) {
draw_passes.write[p_pass] = p_mesh;
RID mesh_rid;
- if (p_mesh.is_valid())
+ if (p_mesh.is_valid()) {
mesh_rid = p_mesh->get_rid();
+ }
RS::get_singleton()->particles_set_draw_pass_mesh(particles, p_pass, mesh_rid);
@@ -241,8 +245,9 @@ String GPUParticles3D::get_configuration_warning() const {
StandardMaterial3D *spat = Object::cast_to<StandardMaterial3D>(draw_passes[i]->surface_get_material(j).ptr());
anim_material_found = anim_material_found || (spat && spat->get_billboard_mode() == StandardMaterial3D::BILLBOARD_PARTICLES);
}
- if (anim_material_found)
+ if (anim_material_found) {
break;
+ }
}
}
@@ -251,22 +256,25 @@ String GPUParticles3D::get_configuration_warning() const {
anim_material_found = anim_material_found || (spat && spat->get_billboard_mode() == StandardMaterial3D::BILLBOARD_PARTICLES);
if (!meshes_found) {
- if (warnings != String())
+ if (warnings != String()) {
warnings += "\n";
+ }
warnings += "- " + TTR("Nothing is visible because meshes have not been assigned to draw passes.");
}
if (process_material.is_null()) {
- if (warnings != String())
+ if (warnings != String()) {
warnings += "\n";
+ }
warnings += "- " + TTR("A material to process the particles is not assigned, so no behavior is imprinted.");
} else {
const ParticlesMaterial *process = Object::cast_to<ParticlesMaterial>(process_material.ptr());
if (!anim_material_found && process &&
(process->get_param(ParticlesMaterial::PARAM_ANIM_SPEED) != 0.0 || process->get_param(ParticlesMaterial::PARAM_ANIM_OFFSET) != 0.0 ||
process->get_param_texture(ParticlesMaterial::PARAM_ANIM_SPEED).is_valid() || process->get_param_texture(ParticlesMaterial::PARAM_ANIM_OFFSET).is_valid())) {
- if (warnings != String())
+ if (warnings != String()) {
warnings += "\n";
+ }
warnings += "- " + TTR("Particles animation requires the usage of a StandardMaterial3D whose Billboard Mode is set to \"Particle Billboard\".");
}
}
diff --git a/scene/3d/immediate_geometry_3d.cpp b/scene/3d/immediate_geometry_3d.cpp
index 7f90176271..7ccfd527a1 100644
--- a/scene/3d/immediate_geometry_3d.cpp
+++ b/scene/3d/immediate_geometry_3d.cpp
@@ -32,8 +32,9 @@
void ImmediateGeometry3D::begin(Mesh::PrimitiveType p_primitive, const Ref<Texture2D> &p_texture) {
RS::get_singleton()->immediate_begin(im, (RS::PrimitiveType)p_primitive, p_texture.is_valid() ? p_texture->get_rid() : RID());
- if (p_texture.is_valid())
+ if (p_texture.is_valid()) {
cached_textures.push_back(p_texture);
+ }
}
void ImmediateGeometry3D::set_normal(const Vector3 &p_normal) {
diff --git a/scene/3d/light_3d.cpp b/scene/3d/light_3d.cpp
index e1ac562e94..814e911372 100644
--- a/scene/3d/light_3d.cpp
+++ b/scene/3d/light_3d.cpp
@@ -163,8 +163,9 @@ Ref<Texture2D> Light3D::get_projector() const {
}
void Light3D::_update_visibility() {
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
bool editor_ok = true;
@@ -356,8 +357,9 @@ Light3D::Light3D() {
Light3D::~Light3D() {
RS::get_singleton()->instance_set_base(get_instance(), RID());
- if (light.is_valid())
+ if (light.is_valid()) {
RenderingServer::get_singleton()->free(light);
+ }
}
/////////////////////////////////////////
diff --git a/scene/3d/listener_3d.cpp b/scene/3d/listener_3d.cpp
index 2015662401..0a5b9ad09f 100644
--- a/scene/3d/listener_3d.cpp
+++ b/scene/3d/listener_3d.cpp
@@ -46,8 +46,9 @@ bool Listener3D::_set(const StringName &p_name, const Variant &p_value) {
} else {
clear_current();
}
- } else
+ } else {
return false;
+ }
return true;
}
@@ -59,8 +60,9 @@ bool Listener3D::_get(const StringName &p_name, Variant &r_ret) const {
} else {
r_ret = is_current();
}
- } else
+ } else {
return false;
+ }
return true;
}
@@ -79,8 +81,9 @@ void Listener3D::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_WORLD: {
bool first_listener = get_viewport()->_listener_add(this);
- if (!get_tree()->is_node_being_edited(this) && (current || first_listener))
+ if (!get_tree()->is_node_being_edited(this) && (current || first_listener)) {
make_current();
+ }
} break;
case NOTIFICATION_TRANSFORM_CHANGED: {
_request_listener_update();
@@ -109,16 +112,18 @@ Transform Listener3D::get_listener_transform() const {
void Listener3D::make_current() {
current = true;
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
get_viewport()->_listener_set(this);
}
void Listener3D::clear_current() {
current = false;
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
if (get_viewport()->get_listener() == this) {
get_viewport()->_listener_set(nullptr);
@@ -129,8 +134,9 @@ void Listener3D::clear_current() {
bool Listener3D::is_current() const {
if (is_inside_tree() && !get_tree()->is_node_being_edited(this)) {
return get_viewport()->get_listener() == this;
- } else
+ } else {
return current;
+ }
return false;
}
diff --git a/scene/3d/mesh_instance_3d.cpp b/scene/3d/mesh_instance_3d.cpp
index 2e79f08bcd..13f40aed4f 100644
--- a/scene/3d/mesh_instance_3d.cpp
+++ b/scene/3d/mesh_instance_3d.cpp
@@ -40,8 +40,9 @@ bool MeshInstance3D::_set(const StringName &p_name, const Variant &p_value) {
//this is not _too_ bad performance wise, really. it only arrives here if the property was not set anywhere else.
//add to it that it's probably found on first call to _set anyway.
- if (!get_instance().is_valid())
+ if (!get_instance().is_valid()) {
return false;
+ }
Map<StringName, BlendShapeTrack>::Element *E = blend_shape_tracks.find(p_name);
if (E) {
@@ -52,8 +53,9 @@ bool MeshInstance3D::_set(const StringName &p_name, const Variant &p_value) {
if (p_name.operator String().begins_with("material/")) {
int idx = p_name.operator String().get_slicec('/', 1).to_int();
- if (idx >= materials.size() || idx < 0)
+ if (idx >= materials.size() || idx < 0) {
return false;
+ }
set_surface_material(idx, p_value);
return true;
@@ -63,8 +65,9 @@ bool MeshInstance3D::_set(const StringName &p_name, const Variant &p_value) {
}
bool MeshInstance3D::_get(const StringName &p_name, Variant &r_ret) const {
- if (!get_instance().is_valid())
+ if (!get_instance().is_valid()) {
return false;
+ }
const Map<StringName, BlendShapeTrack>::Element *E = blend_shape_tracks.find(p_name);
if (E) {
@@ -74,8 +77,9 @@ bool MeshInstance3D::_get(const StringName &p_name, Variant &r_ret) const {
if (p_name.operator String().begins_with("material/")) {
int idx = p_name.operator String().get_slicec('/', 1).to_int();
- if (idx >= materials.size() || idx < 0)
+ if (idx >= materials.size() || idx < 0) {
return false;
+ }
r_ret = materials[idx];
return true;
}
@@ -102,8 +106,9 @@ void MeshInstance3D::_get_property_list(List<PropertyInfo> *p_list) const {
}
void MeshInstance3D::set_mesh(const Ref<Mesh> &p_mesh) {
- if (mesh == p_mesh)
+ if (mesh == p_mesh) {
return;
+ }
if (mesh.is_valid()) {
mesh->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &MeshInstance3D::_mesh_changed));
@@ -165,8 +170,9 @@ void MeshInstance3D::_resolve_skeleton_path() {
void MeshInstance3D::set_skin(const Ref<Skin> &p_skin) {
skin_internal = p_skin;
skin = p_skin;
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
_resolve_skeleton_path();
}
@@ -176,8 +182,9 @@ Ref<Skin> MeshInstance3D::get_skin() const {
void MeshInstance3D::set_skeleton_path(const NodePath &p_skeleton) {
skeleton_path = p_skeleton;
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
_resolve_skeleton_path();
}
@@ -186,29 +193,34 @@ NodePath MeshInstance3D::get_skeleton_path() {
}
AABB MeshInstance3D::get_aabb() const {
- if (!mesh.is_null())
+ if (!mesh.is_null()) {
return mesh->get_aabb();
+ }
return AABB();
}
Vector<Face3> MeshInstance3D::get_faces(uint32_t p_usage_flags) const {
- if (!(p_usage_flags & (FACES_SOLID | FACES_ENCLOSING)))
+ if (!(p_usage_flags & (FACES_SOLID | FACES_ENCLOSING))) {
return Vector<Face3>();
+ }
- if (mesh.is_null())
+ if (mesh.is_null()) {
return Vector<Face3>();
+ }
return mesh->get_faces();
}
Node *MeshInstance3D::create_trimesh_collision_node() {
- if (mesh.is_null())
+ if (mesh.is_null()) {
return nullptr;
+ }
Ref<Shape3D> shape = mesh->create_trimesh_shape();
- if (shape.is_null())
+ if (shape.is_null()) {
return nullptr;
+ }
StaticBody3D *static_body = memnew(StaticBody3D);
CollisionShape3D *cshape = memnew(CollisionShape3D);
@@ -231,12 +243,14 @@ void MeshInstance3D::create_trimesh_collision() {
}
Node *MeshInstance3D::create_convex_collision_node() {
- if (mesh.is_null())
+ if (mesh.is_null()) {
return nullptr;
+ }
Ref<Shape3D> shape = mesh->create_convex_shape();
- if (shape.is_null())
+ if (shape.is_null()) {
return nullptr;
+ }
StaticBody3D *static_body = memnew(StaticBody3D);
CollisionShape3D *cshape = memnew(CollisionShape3D);
@@ -273,10 +287,11 @@ void MeshInstance3D::set_surface_material(int p_surface, const Ref<Material> &p_
materials.write[p_surface] = p_material;
- if (materials[p_surface].is_valid())
+ if (materials[p_surface].is_valid()) {
RS::get_singleton()->instance_set_surface_material(get_instance(), p_surface, materials[p_surface]->get_rid());
- else
+ } else {
RS::get_singleton()->instance_set_surface_material(get_instance(), p_surface, RID());
+ }
}
Ref<Material> MeshInstance3D::get_surface_material(int p_surface) const {
@@ -313,18 +328,21 @@ void MeshInstance3D::create_debug_tangents() {
Vector<Color> colors;
Ref<Mesh> mesh = get_mesh();
- if (!mesh.is_valid())
+ if (!mesh.is_valid()) {
return;
+ }
for (int i = 0; i < mesh->get_surface_count(); i++) {
Array arrays = mesh->surface_get_arrays(i);
Vector<Vector3> verts = arrays[Mesh::ARRAY_VERTEX];
Vector<Vector3> norms = arrays[Mesh::ARRAY_NORMAL];
- if (norms.size() == 0)
+ if (norms.size() == 0) {
continue;
+ }
Vector<float> tangents = arrays[Mesh::ARRAY_TANGENT];
- if (tangents.size() == 0)
+ if (tangents.size() == 0) {
continue;
+ }
for (int j = 0; j < verts.size(); j++) {
Vector3 v = verts[j];
@@ -373,10 +391,11 @@ void MeshInstance3D::create_debug_tangents() {
add_child(mi);
#ifdef TOOLS_ENABLED
- if (this == get_tree()->get_edited_scene_root())
+ if (this == get_tree()->get_edited_scene_root()) {
mi->set_owner(this);
- else
+ } else {
mi->set_owner(get_owner());
+ }
#endif
}
}
diff --git a/scene/3d/multimesh_instance_3d.cpp b/scene/3d/multimesh_instance_3d.cpp
index 9892323173..88dff111f7 100644
--- a/scene/3d/multimesh_instance_3d.cpp
+++ b/scene/3d/multimesh_instance_3d.cpp
@@ -38,10 +38,11 @@ void MultiMeshInstance3D::_bind_methods() {
void MultiMeshInstance3D::set_multimesh(const Ref<MultiMesh> &p_multimesh) {
multimesh = p_multimesh;
- if (multimesh.is_valid())
+ if (multimesh.is_valid()) {
set_base(multimesh->get_rid());
- else
+ } else {
set_base(RID());
+ }
}
Ref<MultiMesh> MultiMeshInstance3D::get_multimesh() const {
@@ -53,10 +54,11 @@ Vector<Face3> MultiMeshInstance3D::get_faces(uint32_t p_usage_flags) const {
}
AABB MultiMeshInstance3D::get_aabb() const {
- if (multimesh.is_null())
+ if (multimesh.is_null()) {
return AABB();
- else
+ } else {
return multimesh->get_aabb();
+ }
}
MultiMeshInstance3D::MultiMeshInstance3D() {
diff --git a/scene/3d/navigation_agent_3d.cpp b/scene/3d/navigation_agent_3d.cpp
index 4b1e602f77..f8d44506b6 100644
--- a/scene/3d/navigation_agent_3d.cpp
+++ b/scene/3d/navigation_agent_3d.cpp
@@ -108,10 +108,11 @@ void NavigationAgent3D::_notification(int p_what) {
Node *p = get_parent();
while (p != nullptr) {
nav = Object::cast_to<Navigation3D>(p);
- if (nav != nullptr)
+ if (nav != nullptr) {
p = nullptr;
- else
+ } else {
p = p->get_parent();
+ }
}
set_navigation(nav);
@@ -154,8 +155,9 @@ NavigationAgent3D::~NavigationAgent3D() {
}
void NavigationAgent3D::set_navigation(Navigation3D *p_nav) {
- if (navigation == p_nav)
+ if (navigation == p_nav) {
return; // Pointless
+ }
navigation = p_nav;
NavigationServer3D::get_singleton()->agent_set_map(agent, navigation == nullptr ? RID() : navigation->get_rid());
@@ -293,12 +295,15 @@ String NavigationAgent3D::get_configuration_warning() const {
}
void NavigationAgent3D::update_navigation() {
- if (agent_parent == nullptr)
+ if (agent_parent == nullptr) {
return;
- if (navigation == nullptr)
+ }
+ if (navigation == nullptr) {
return;
- if (update_frame_id == Engine::get_singleton()->get_physics_frames())
+ }
+ if (update_frame_id == Engine::get_singleton()->get_physics_frames()) {
return;
+ }
update_frame_id = Engine::get_singleton()->get_physics_frames();
@@ -333,8 +338,9 @@ void NavigationAgent3D::update_navigation() {
emit_signal("path_changed");
}
- if (navigation_path.size() == 0)
+ if (navigation_path.size() == 0) {
return;
+ }
// Check if we can advance the navigation path
if (navigation_finished == false) {
diff --git a/scene/3d/navigation_obstacle_3d.cpp b/scene/3d/navigation_obstacle_3d.cpp
index daa9222d84..69fd5b02fc 100644
--- a/scene/3d/navigation_obstacle_3d.cpp
+++ b/scene/3d/navigation_obstacle_3d.cpp
@@ -51,10 +51,11 @@ void NavigationObstacle3D::_notification(int p_what) {
Node *p = get_parent();
while (p != nullptr) {
nav = Object::cast_to<Navigation3D>(p);
- if (nav != nullptr)
+ if (nav != nullptr) {
p = nullptr;
- else
+ } else {
p = p->get_parent();
+ }
}
set_navigation(nav);
@@ -93,8 +94,9 @@ NavigationObstacle3D::~NavigationObstacle3D() {
}
void NavigationObstacle3D::set_navigation(Navigation3D *p_nav) {
- if (navigation == p_nav)
+ if (navigation == p_nav) {
return; // Pointless
+ }
navigation = p_nav;
NavigationServer3D::get_singleton()->agent_set_map(agent, navigation == nullptr ? RID() : navigation->get_rid());
@@ -145,8 +147,9 @@ void NavigationObstacle3D::update_agent_shape() {
radius *= MAX(s.x, MAX(s.y, s.z));
}
- if (radius == 0.0)
+ if (radius == 0.0) {
radius = 1.0; // Never a 0 radius
+ }
// Initialize the Agent as an object
NavigationServer3D::get_singleton()->agent_set_neighbor_dist(agent, 0.0);
diff --git a/scene/3d/navigation_region_3d.cpp b/scene/3d/navigation_region_3d.cpp
index bc13b7097f..15ed448a65 100644
--- a/scene/3d/navigation_region_3d.cpp
+++ b/scene/3d/navigation_region_3d.cpp
@@ -36,12 +36,14 @@
#include "servers/navigation_server_3d.h"
void NavigationRegion3D::set_enabled(bool p_enabled) {
- if (enabled == p_enabled)
+ if (enabled == p_enabled) {
return;
+ }
enabled = p_enabled;
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
if (!enabled) {
NavigationServer3D::get_singleton()->region_set_map(region, RID());
@@ -117,8 +119,9 @@ void NavigationRegion3D::_notification(int p_what) {
}
void NavigationRegion3D::set_navigation_mesh(const Ref<NavigationMesh> &p_navmesh) {
- if (p_navmesh == navmesh)
+ if (p_navmesh == navmesh) {
return;
+ }
if (navmesh.is_valid()) {
navmesh->remove_change_receptor(this);
@@ -182,16 +185,18 @@ void NavigationRegion3D::_bake_finished(Ref<NavigationMesh> p_nav_mesh) {
}
String NavigationRegion3D::get_configuration_warning() const {
- if (!is_visible_in_tree() || !is_inside_tree())
+ if (!is_visible_in_tree() || !is_inside_tree()) {
return String();
+ }
if (!navmesh.is_valid()) {
return TTR("A NavigationMesh resource must be set or created for this node to work.");
}
const Node3D *c = this;
while (c) {
- if (Object::cast_to<Navigation3D>(c))
+ if (Object::cast_to<Navigation3D>(c)) {
return String();
+ }
c = Object::cast_to<Node3D>(c->get_parent());
}
@@ -227,7 +232,8 @@ NavigationRegion3D::NavigationRegion3D() {
}
NavigationRegion3D::~NavigationRegion3D() {
- if (navmesh.is_valid())
+ if (navmesh.is_valid()) {
navmesh->remove_change_receptor(this);
+ }
NavigationServer3D::get_singleton()->free(region);
}
diff --git a/scene/3d/node_3d.cpp b/scene/3d/node_3d.cpp
index 2a1b35ae39..73f17060df 100644
--- a/scene/3d/node_3d.cpp
+++ b/scene/3d/node_3d.cpp
@@ -103,8 +103,9 @@ void Node3D::_propagate_transform_changed(Node3D *p_origin) {
data.children_lock++;
for (List<Node3D *>::Element *E = data.children.front(); E; E = E->next()) {
- if (E->get()->data.toplevel_active)
+ if (E->get()->data.toplevel_active) {
continue; //don't propagate to a toplevel
+ }
E->get()->_propagate_transform_changed(p_origin);
}
#ifdef TOOLS_ENABLED
@@ -125,13 +126,15 @@ void Node3D::_notification(int p_what) {
ERR_FAIL_COND(!get_tree());
Node *p = get_parent();
- if (p)
+ if (p) {
data.parent = Object::cast_to<Node3D>(p);
+ }
- if (data.parent)
+ if (data.parent) {
data.C = data.parent->data.children.push_back(this);
- else
+ } else {
data.C = nullptr;
+ }
if (data.toplevel && !Engine::get_singleton()->is_editor_hint()) {
if (data.parent) {
@@ -149,10 +152,12 @@ void Node3D::_notification(int p_what) {
} break;
case NOTIFICATION_EXIT_TREE: {
notification(NOTIFICATION_EXIT_WORLD, true);
- if (xform_change.in_list())
+ if (xform_change.in_list()) {
get_tree()->xform_change_list.remove(&xform_change);
- if (data.C)
+ }
+ if (data.C) {
data.parent->data.children.erase(data.C);
+ }
data.parent = nullptr;
data.C = nullptr;
data.toplevel_active = false;
@@ -287,15 +292,17 @@ Node3D *Node3D::get_parent_spatial() const {
}
Transform Node3D::get_relative_transform(const Node *p_parent) const {
- if (p_parent == this)
+ if (p_parent == this) {
return Transform();
+ }
ERR_FAIL_COND_V(!data.parent, Transform());
- if (p_parent == data.parent)
+ if (p_parent == data.parent) {
return get_transform();
- else
+ } else {
return data.parent->get_relative_transform(p_parent) * get_transform();
+ }
}
void Node3D::set_translation(const Vector3 &p_translation) {
@@ -373,14 +380,18 @@ Vector3 Node3D::get_scale() const {
void Node3D::update_gizmo() {
#ifdef TOOLS_ENABLED
- if (!is_inside_world())
+ if (!is_inside_world()) {
return;
- if (!data.gizmo.is_valid())
+ }
+ if (!data.gizmo.is_valid()) {
get_tree()->call_group_flags(SceneTree::GROUP_CALL_REALTIME, SceneStringNames::get_singleton()->_spatial_editor_group, SceneStringNames::get_singleton()->_request_gizmo, this);
- if (!data.gizmo.is_valid())
+ }
+ if (!data.gizmo.is_valid()) {
return;
- if (data.gizmo_dirty)
+ }
+ if (data.gizmo_dirty) {
return;
+ }
data.gizmo_dirty = true;
MessageQueue::get_singleton()->push_call(this, "_update_gizmo");
#endif
@@ -389,10 +400,12 @@ void Node3D::update_gizmo() {
void Node3D::set_gizmo(const Ref<Node3DGizmo> &p_gizmo) {
#ifdef TOOLS_ENABLED
- if (data.gizmo_disabled)
+ if (data.gizmo_disabled) {
return;
- if (data.gizmo.is_valid() && is_inside_world())
+ }
+ if (data.gizmo.is_valid() && is_inside_world()) {
data.gizmo->free();
+ }
data.gizmo = p_gizmo;
if (data.gizmo.is_valid() && is_inside_world()) {
data.gizmo->create();
@@ -417,14 +430,16 @@ Ref<Node3DGizmo> Node3D::get_gizmo() const {
void Node3D::_update_gizmo() {
#ifdef TOOLS_ENABLED
- if (!is_inside_world())
+ if (!is_inside_world()) {
return;
+ }
data.gizmo_dirty = false;
if (data.gizmo.is_valid()) {
- if (is_visible_in_tree())
+ if (is_visible_in_tree()) {
data.gizmo->redraw();
- else
+ } else {
data.gizmo->clear();
+ }
}
#endif
}
@@ -432,8 +447,9 @@ void Node3D::_update_gizmo() {
#ifdef TOOLS_ENABLED
void Node3D::set_disable_gizmo(bool p_enabled) {
data.gizmo_disabled = p_enabled;
- if (!p_enabled && data.gizmo.is_valid())
+ if (!p_enabled && data.gizmo.is_valid()) {
data.gizmo = Ref<Node3DGizmo>();
+ }
}
#endif
@@ -447,13 +463,15 @@ bool Node3D::is_scale_disabled() const {
}
void Node3D::set_as_toplevel(bool p_enabled) {
- if (data.toplevel == p_enabled)
+ if (data.toplevel == p_enabled) {
return;
+ }
if (is_inside_tree() && !Engine::get_singleton()->is_editor_hint()) {
- if (p_enabled)
+ if (p_enabled) {
set_transform(get_global_transform());
- else if (data.parent)
+ } else if (data.parent) {
set_transform(data.parent->get_global_transform().affine_inverse() * get_global_transform());
+ }
data.toplevel = p_enabled;
data.toplevel_active = p_enabled;
@@ -479,38 +497,44 @@ void Node3D::_propagate_visibility_changed() {
emit_signal(SceneStringNames::get_singleton()->visibility_changed);
_change_notify("visible");
#ifdef TOOLS_ENABLED
- if (data.gizmo.is_valid())
+ if (data.gizmo.is_valid()) {
_update_gizmo();
+ }
#endif
for (List<Node3D *>::Element *E = data.children.front(); E; E = E->next()) {
Node3D *c = E->get();
- if (!c || !c->data.visible)
+ if (!c || !c->data.visible) {
continue;
+ }
c->_propagate_visibility_changed();
}
}
void Node3D::show() {
- if (data.visible)
+ if (data.visible) {
return;
+ }
data.visible = true;
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
_propagate_visibility_changed();
}
void Node3D::hide() {
- if (!data.visible)
+ if (!data.visible) {
return;
+ }
data.visible = false;
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
_propagate_visibility_changed();
}
@@ -529,10 +553,11 @@ bool Node3D::is_visible_in_tree() const {
}
void Node3D::set_visible(bool p_visible) {
- if (p_visible)
+ if (p_visible) {
show();
- else
+ } else {
hide();
+ }
}
bool Node3D::is_visible() const {
diff --git a/scene/3d/path_3d.cpp b/scene/3d/path_3d.cpp
index 6f57bf81c4..dcfdf8efcf 100644
--- a/scene/3d/path_3d.cpp
+++ b/scene/3d/path_3d.cpp
@@ -37,8 +37,9 @@ void Path3D::_notification(int p_what) {
}
void Path3D::_curve_changed() {
- if (is_inside_tree() && Engine::get_singleton()->is_editor_hint())
+ if (is_inside_tree() && Engine::get_singleton()->is_editor_hint()) {
update_gizmo();
+ }
if (is_inside_tree()) {
emit_signal("curve_changed");
}
@@ -88,12 +89,14 @@ Path3D::Path3D() {
//////////////
void PathFollow3D::_update_transform() {
- if (!path)
+ if (!path) {
return;
+ }
Ref<Curve3D> c = path->get_curve();
- if (!c.is_valid())
+ if (!c.is_valid()) {
return;
+ }
if (delta_offset == 0) {
return;
@@ -120,10 +123,11 @@ void PathFollow3D::_update_transform() {
if (rotation_mode == ROTATION_ORIENTED) {
Vector3 forward = c->interpolate_baked(o_next, cubic) - pos;
- if (forward.length_squared() < CMP_EPSILON2)
+ if (forward.length_squared() < CMP_EPSILON2) {
forward = Vector3(0, 0, 1);
- else
+ } else {
forward.normalize();
+ }
Vector3 up = c->interpolate_baked_up_vector(offset, true);
@@ -131,10 +135,11 @@ void PathFollow3D::_update_transform() {
Vector3 up1 = c->interpolate_baked_up_vector(o_next, true);
Vector3 axis = up.cross(up1);
- if (axis.length_squared() < CMP_EPSILON2)
+ if (axis.length_squared() < CMP_EPSILON2) {
axis = forward;
- else
+ } else {
axis.normalize();
+ }
up.rotate(axis, up.angle_to(up1) * 0.5f);
}
@@ -234,16 +239,18 @@ bool PathFollow3D::get_cubic_interpolation() const {
void PathFollow3D::_validate_property(PropertyInfo &property) const {
if (property.name == "offset") {
float max = 10000;
- if (path && path->get_curve().is_valid())
+ if (path && path->get_curve().is_valid()) {
max = path->get_curve()->get_baked_length();
+ }
property.hint_string = "0," + rtos(max) + ",0.01,or_lesser,or_greater";
}
}
String PathFollow3D::get_configuration_warning() const {
- if (!is_visible_in_tree() || !is_inside_tree())
+ if (!is_visible_in_tree() || !is_inside_tree()) {
return String();
+ }
if (!Object::cast_to<Path3D>(get_parent())) {
return TTR("PathFollow3D only works when set as a child of a Path3D node.");
@@ -320,8 +327,9 @@ void PathFollow3D::set_offset(float p_offset) {
void PathFollow3D::set_h_offset(float p_h_offset) {
h_offset = p_h_offset;
- if (path)
+ if (path) {
_update_transform();
+ }
}
float PathFollow3D::get_h_offset() const {
@@ -330,8 +338,9 @@ float PathFollow3D::get_h_offset() const {
void PathFollow3D::set_v_offset(float p_v_offset) {
v_offset = p_v_offset;
- if (path)
+ if (path) {
_update_transform();
+ }
}
float PathFollow3D::get_v_offset() const {
@@ -343,15 +352,17 @@ float PathFollow3D::get_offset() const {
}
void PathFollow3D::set_unit_offset(float p_unit_offset) {
- if (path && path->get_curve().is_valid() && path->get_curve()->get_baked_length())
+ if (path && path->get_curve().is_valid() && path->get_curve()->get_baked_length()) {
set_offset(p_unit_offset * path->get_curve()->get_baked_length());
+ }
}
float PathFollow3D::get_unit_offset() const {
- if (path && path->get_curve().is_valid() && path->get_curve()->get_baked_length())
+ if (path && path->get_curve().is_valid() && path->get_curve()->get_baked_length()) {
return get_offset() / path->get_curve()->get_baked_length();
- else
+ } else {
return 0;
+ }
}
void PathFollow3D::set_rotation_mode(RotationMode p_rotation_mode) {
diff --git a/scene/3d/physics_body_3d.cpp b/scene/3d/physics_body_3d.cpp
index 68a13f5612..385b4e81a8 100644
--- a/scene/3d/physics_body_3d.cpp
+++ b/scene/3d/physics_body_3d.cpp
@@ -76,10 +76,11 @@ uint32_t PhysicsBody3D::get_collision_mask() const {
void PhysicsBody3D::set_collision_mask_bit(int p_bit, bool p_value) {
uint32_t mask = get_collision_mask();
- if (p_value)
+ if (p_value) {
mask |= 1 << p_bit;
- else
+ } else {
mask &= ~(1 << p_bit);
+ }
set_collision_mask(mask);
}
@@ -89,10 +90,11 @@ bool PhysicsBody3D::get_collision_mask_bit(int p_bit) const {
void PhysicsBody3D::set_collision_layer_bit(int p_bit, bool p_value) {
uint32_t mask = get_collision_layer();
- if (p_value)
+ if (p_value) {
mask |= 1 << p_bit;
- else
+ } else {
mask &= ~(1 << p_bit);
+ }
set_collision_layer(mask);
}
@@ -305,8 +307,9 @@ void RigidBody3D::_body_inout(int p_status, ObjectID p_instance, int p_body_shap
}
}
//E->get().rc++;
- if (node)
+ if (node) {
E->get().shapes.insert(ShapePair(p_body_shape, p_local_shape));
+ }
if (E->get().in_tree) {
emit_signal(SceneStringNames::get_singleton()->body_shape_entered, objid, node, p_body_shape, p_local_shape);
@@ -315,8 +318,9 @@ void RigidBody3D::_body_inout(int p_status, ObjectID p_instance, int p_body_shap
} else {
//E->get().rc--;
- if (node)
+ if (node) {
E->get().shapes.erase(ShapePair(p_body_shape, p_local_shape));
+ }
bool in_tree = E->get().in_tree;
@@ -324,8 +328,9 @@ void RigidBody3D::_body_inout(int p_status, ObjectID p_instance, int p_body_shap
if (node) {
node->disconnect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &RigidBody3D::_body_enter_tree));
node->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &RigidBody3D::_body_exit_tree));
- if (in_tree)
+ if (in_tree) {
emit_signal(SceneStringNames::get_singleton()->body_exited, node);
+ }
}
contact_monitor->body_map.erase(E);
@@ -357,8 +362,9 @@ void RigidBody3D::_direct_state_changed(Object *p_state) {
sleeping = state->is_sleeping();
emit_signal(SceneStringNames::get_singleton()->sleeping_state_changed);
}
- if (get_script_instance())
+ if (get_script_instance()) {
get_script_instance()->call("_integrate_forces", state);
+ }
set_ignore_transform_notification(false);
if (contact_monitor) {
@@ -564,10 +570,11 @@ void RigidBody3D::set_axis_velocity(const Vector3 &p_axis) {
void RigidBody3D::set_linear_velocity(const Vector3 &p_velocity) {
linear_velocity = p_velocity;
- if (state)
+ if (state) {
state->set_linear_velocity(linear_velocity);
- else
+ } else {
PhysicsServer3D::get_singleton()->body_set_state(get_rid(), PhysicsServer3D::BODY_STATE_LINEAR_VELOCITY, linear_velocity);
+ }
}
Vector3 RigidBody3D::get_linear_velocity() const {
@@ -576,10 +583,11 @@ Vector3 RigidBody3D::get_linear_velocity() const {
void RigidBody3D::set_angular_velocity(const Vector3 &p_velocity) {
angular_velocity = p_velocity;
- if (state)
+ if (state) {
state->set_angular_velocity(angular_velocity);
- else
+ } else {
PhysicsServer3D::get_singleton()->body_set_state(get_rid(), PhysicsServer3D::BODY_STATE_ANGULAR_VELOCITY, angular_velocity);
+ }
}
Vector3 RigidBody3D::get_angular_velocity() const {
@@ -587,8 +595,9 @@ Vector3 RigidBody3D::get_angular_velocity() const {
}
void RigidBody3D::set_use_custom_integrator(bool p_enable) {
- if (custom_integrator == p_enable)
+ if (custom_integrator == p_enable) {
return;
+ }
custom_integrator = p_enable;
PhysicsServer3D::get_singleton()->body_set_omit_force_integration(get_rid(), p_enable);
@@ -659,8 +668,9 @@ bool RigidBody3D::is_using_continuous_collision_detection() const {
}
void RigidBody3D::set_contact_monitor(bool p_enabled) {
- if (p_enabled == is_contact_monitor_enabled())
+ if (p_enabled == is_contact_monitor_enabled()) {
return;
+ }
if (!p_enabled) {
ERR_FAIL_COND_MSG(contact_monitor->locked, "Can't disable contact monitoring during in/out callback. Use call_deferred(\"set_contact_monitor\", false) instead.");
@@ -855,8 +865,9 @@ RigidBody3D::RigidBody3D() :
}
RigidBody3D::~RigidBody3D() {
- if (contact_monitor)
+ if (contact_monitor) {
memdelete(contact_monitor);
+ }
}
void RigidBody3D::_reload_physics_characteristics() {
@@ -1014,8 +1025,9 @@ Vector3 KinematicBody3D::move_and_slide(const Vector3 &p_linear_velocity, const
}
}
- if (!found_collision || motion == Vector3())
+ if (!found_collision || motion == Vector3()) {
break;
+ }
--p_max_slides;
}
@@ -1259,8 +1271,9 @@ Vector3 KinematicCollision3D::get_remainder() const {
}
Object *KinematicCollision3D::get_local_shape() const {
- if (!owner)
+ if (!owner) {
return nullptr;
+ }
uint32_t ownerid = owner->shape_find_owner(collision.local_shape);
return owner->shape_owner_get_owner(ownerid);
}
@@ -1380,18 +1393,21 @@ bool PhysicalBone3D::PinJointData::_set(const StringName &p_name, const Variant
if ("joint_constraints/bias" == p_name) {
bias = p_value;
- if (j.is_valid())
+ if (j.is_valid()) {
PhysicsServer3D::get_singleton()->pin_joint_set_param(j, PhysicsServer3D::PIN_JOINT_BIAS, bias);
+ }
} else if ("joint_constraints/damping" == p_name) {
damping = p_value;
- if (j.is_valid())
+ if (j.is_valid()) {
PhysicsServer3D::get_singleton()->pin_joint_set_param(j, PhysicsServer3D::PIN_JOINT_DAMPING, damping);
+ }
} else if ("joint_constraints/impulse_clamp" == p_name) {
impulse_clamp = p_value;
- if (j.is_valid())
+ if (j.is_valid()) {
PhysicsServer3D::get_singleton()->pin_joint_set_param(j, PhysicsServer3D::PIN_JOINT_IMPULSE_CLAMP, impulse_clamp);
+ }
} else {
return false;
@@ -1433,28 +1449,33 @@ bool PhysicalBone3D::ConeJointData::_set(const StringName &p_name, const Variant
if ("joint_constraints/swing_span" == p_name) {
swing_span = Math::deg2rad(real_t(p_value));
- if (j.is_valid())
+ if (j.is_valid()) {
PhysicsServer3D::get_singleton()->cone_twist_joint_set_param(j, PhysicsServer3D::CONE_TWIST_JOINT_SWING_SPAN, swing_span);
+ }
} else if ("joint_constraints/twist_span" == p_name) {
twist_span = Math::deg2rad(real_t(p_value));
- if (j.is_valid())
+ if (j.is_valid()) {
PhysicsServer3D::get_singleton()->cone_twist_joint_set_param(j, PhysicsServer3D::CONE_TWIST_JOINT_TWIST_SPAN, twist_span);
+ }
} else if ("joint_constraints/bias" == p_name) {
bias = p_value;
- if (j.is_valid())
+ if (j.is_valid()) {
PhysicsServer3D::get_singleton()->cone_twist_joint_set_param(j, PhysicsServer3D::CONE_TWIST_JOINT_BIAS, bias);
+ }
} else if ("joint_constraints/softness" == p_name) {
softness = p_value;
- if (j.is_valid())
+ if (j.is_valid()) {
PhysicsServer3D::get_singleton()->cone_twist_joint_set_param(j, PhysicsServer3D::CONE_TWIST_JOINT_SOFTNESS, softness);
+ }
} else if ("joint_constraints/relaxation" == p_name) {
relaxation = p_value;
- if (j.is_valid())
+ if (j.is_valid()) {
PhysicsServer3D::get_singleton()->cone_twist_joint_set_param(j, PhysicsServer3D::CONE_TWIST_JOINT_RELAXATION, relaxation);
+ }
} else {
return false;
@@ -1502,33 +1523,39 @@ bool PhysicalBone3D::HingeJointData::_set(const StringName &p_name, const Varian
if ("joint_constraints/angular_limit_enabled" == p_name) {
angular_limit_enabled = p_value;
- if (j.is_valid())
+ if (j.is_valid()) {
PhysicsServer3D::get_singleton()->hinge_joint_set_flag(j, PhysicsServer3D::HINGE_JOINT_FLAG_USE_LIMIT, angular_limit_enabled);
+ }
} else if ("joint_constraints/angular_limit_upper" == p_name) {
angular_limit_upper = Math::deg2rad(real_t(p_value));
- if (j.is_valid())
+ if (j.is_valid()) {
PhysicsServer3D::get_singleton()->hinge_joint_set_param(j, PhysicsServer3D::HINGE_JOINT_LIMIT_UPPER, angular_limit_upper);
+ }
} else if ("joint_constraints/angular_limit_lower" == p_name) {
angular_limit_lower = Math::deg2rad(real_t(p_value));
- if (j.is_valid())
+ if (j.is_valid()) {
PhysicsServer3D::get_singleton()->hinge_joint_set_param(j, PhysicsServer3D::HINGE_JOINT_LIMIT_LOWER, angular_limit_lower);
+ }
} else if ("joint_constraints/angular_limit_bias" == p_name) {
angular_limit_bias = p_value;
- if (j.is_valid())
+ if (j.is_valid()) {
PhysicsServer3D::get_singleton()->hinge_joint_set_param(j, PhysicsServer3D::HINGE_JOINT_LIMIT_BIAS, angular_limit_bias);
+ }
} else if ("joint_constraints/angular_limit_softness" == p_name) {
angular_limit_softness = p_value;
- if (j.is_valid())
+ if (j.is_valid()) {
PhysicsServer3D::get_singleton()->hinge_joint_set_param(j, PhysicsServer3D::HINGE_JOINT_LIMIT_SOFTNESS, angular_limit_softness);
+ }
} else if ("joint_constraints/angular_limit_relaxation" == p_name) {
angular_limit_relaxation = p_value;
- if (j.is_valid())
+ if (j.is_valid()) {
PhysicsServer3D::get_singleton()->hinge_joint_set_param(j, PhysicsServer3D::HINGE_JOINT_LIMIT_RELAXATION, angular_limit_relaxation);
+ }
} else {
return false;
@@ -1579,53 +1606,63 @@ bool PhysicalBone3D::SliderJointData::_set(const StringName &p_name, const Varia
if ("joint_constraints/linear_limit_upper" == p_name) {
linear_limit_upper = p_value;
- if (j.is_valid())
+ if (j.is_valid()) {
PhysicsServer3D::get_singleton()->slider_joint_set_param(j, PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_UPPER, linear_limit_upper);
+ }
} else if ("joint_constraints/linear_limit_lower" == p_name) {
linear_limit_lower = p_value;
- if (j.is_valid())
+ if (j.is_valid()) {
PhysicsServer3D::get_singleton()->slider_joint_set_param(j, PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_LOWER, linear_limit_lower);
+ }
} else if ("joint_constraints/linear_limit_softness" == p_name) {
linear_limit_softness = p_value;
- if (j.is_valid())
+ if (j.is_valid()) {
PhysicsServer3D::get_singleton()->slider_joint_set_param(j, PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_SOFTNESS, linear_limit_softness);
+ }
} else if ("joint_constraints/linear_limit_restitution" == p_name) {
linear_limit_restitution = p_value;
- if (j.is_valid())
+ if (j.is_valid()) {
PhysicsServer3D::get_singleton()->slider_joint_set_param(j, PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_RESTITUTION, linear_limit_restitution);
+ }
} else if ("joint_constraints/linear_limit_damping" == p_name) {
linear_limit_damping = p_value;
- if (j.is_valid())
+ if (j.is_valid()) {
PhysicsServer3D::get_singleton()->slider_joint_set_param(j, PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_DAMPING, linear_limit_restitution);
+ }
} else if ("joint_constraints/angular_limit_upper" == p_name) {
angular_limit_upper = Math::deg2rad(real_t(p_value));
- if (j.is_valid())
+ if (j.is_valid()) {
PhysicsServer3D::get_singleton()->slider_joint_set_param(j, PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_UPPER, angular_limit_upper);
+ }
} else if ("joint_constraints/angular_limit_lower" == p_name) {
angular_limit_lower = Math::deg2rad(real_t(p_value));
- if (j.is_valid())
+ if (j.is_valid()) {
PhysicsServer3D::get_singleton()->slider_joint_set_param(j, PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_LOWER, angular_limit_lower);
+ }
} else if ("joint_constraints/angular_limit_softness" == p_name) {
angular_limit_softness = p_value;
- if (j.is_valid())
+ if (j.is_valid()) {
PhysicsServer3D::get_singleton()->slider_joint_set_param(j, PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_SOFTNESS, angular_limit_softness);
+ }
} else if ("joint_constraints/angular_limit_restitution" == p_name) {
angular_limit_restitution = p_value;
- if (j.is_valid())
+ if (j.is_valid()) {
PhysicsServer3D::get_singleton()->slider_joint_set_param(j, PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_SOFTNESS, angular_limit_softness);
+ }
} else if ("joint_constraints/angular_limit_damping" == p_name) {
angular_limit_damping = p_value;
- if (j.is_valid())
+ if (j.is_valid()) {
PhysicsServer3D::get_singleton()->slider_joint_set_param(j, PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_DAMPING, angular_limit_damping);
+ }
} else {
return false;
@@ -1707,108 +1744,129 @@ bool PhysicalBone3D::SixDOFJointData::_set(const StringName &p_name, const Varia
if ("linear_limit_enabled" == var_name) {
axis_data[axis].linear_limit_enabled = p_value;
- if (j.is_valid())
+ if (j.is_valid()) {
PhysicsServer3D::get_singleton()->generic_6dof_joint_set_flag(j, axis, PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_LINEAR_LIMIT, axis_data[axis].linear_limit_enabled);
+ }
} else if ("linear_limit_upper" == var_name) {
axis_data[axis].linear_limit_upper = p_value;
- if (j.is_valid())
+ if (j.is_valid()) {
PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer3D::G6DOF_JOINT_LINEAR_UPPER_LIMIT, axis_data[axis].linear_limit_upper);
+ }
} else if ("linear_limit_lower" == var_name) {
axis_data[axis].linear_limit_lower = p_value;
- if (j.is_valid())
+ if (j.is_valid()) {
PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer3D::G6DOF_JOINT_LINEAR_LOWER_LIMIT, axis_data[axis].linear_limit_lower);
+ }
} else if ("linear_limit_softness" == var_name) {
axis_data[axis].linear_limit_softness = p_value;
- if (j.is_valid())
+ if (j.is_valid()) {
PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer3D::G6DOF_JOINT_LINEAR_LIMIT_SOFTNESS, axis_data[axis].linear_limit_softness);
+ }
} else if ("linear_spring_enabled" == var_name) {
axis_data[axis].linear_spring_enabled = p_value;
- if (j.is_valid())
+ if (j.is_valid()) {
PhysicsServer3D::get_singleton()->generic_6dof_joint_set_flag(j, axis, PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_LINEAR_SPRING, axis_data[axis].linear_spring_enabled);
+ }
} else if ("linear_spring_stiffness" == var_name) {
axis_data[axis].linear_spring_stiffness = p_value;
- if (j.is_valid())
+ if (j.is_valid()) {
PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer3D::G6DOF_JOINT_LINEAR_SPRING_STIFFNESS, axis_data[axis].linear_spring_stiffness);
+ }
} else if ("linear_spring_damping" == var_name) {
axis_data[axis].linear_spring_damping = p_value;
- if (j.is_valid())
+ if (j.is_valid()) {
PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer3D::G6DOF_JOINT_LINEAR_SPRING_DAMPING, axis_data[axis].linear_spring_damping);
+ }
} else if ("linear_equilibrium_point" == var_name) {
axis_data[axis].linear_equilibrium_point = p_value;
- if (j.is_valid())
+ if (j.is_valid()) {
PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer3D::G6DOF_JOINT_LINEAR_SPRING_EQUILIBRIUM_POINT, axis_data[axis].linear_equilibrium_point);
+ }
} else if ("linear_restitution" == var_name) {
axis_data[axis].linear_restitution = p_value;
- if (j.is_valid())
+ if (j.is_valid()) {
PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer3D::G6DOF_JOINT_LINEAR_RESTITUTION, axis_data[axis].linear_restitution);
+ }
} else if ("linear_damping" == var_name) {
axis_data[axis].linear_damping = p_value;
- if (j.is_valid())
+ if (j.is_valid()) {
PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer3D::G6DOF_JOINT_LINEAR_DAMPING, axis_data[axis].linear_damping);
+ }
} else if ("angular_limit_enabled" == var_name) {
axis_data[axis].angular_limit_enabled = p_value;
- if (j.is_valid())
+ if (j.is_valid()) {
PhysicsServer3D::get_singleton()->generic_6dof_joint_set_flag(j, axis, PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_ANGULAR_LIMIT, axis_data[axis].angular_limit_enabled);
+ }
} else if ("angular_limit_upper" == var_name) {
axis_data[axis].angular_limit_upper = Math::deg2rad(real_t(p_value));
- if (j.is_valid())
+ if (j.is_valid()) {
PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer3D::G6DOF_JOINT_ANGULAR_UPPER_LIMIT, axis_data[axis].angular_limit_upper);
+ }
} else if ("angular_limit_lower" == var_name) {
axis_data[axis].angular_limit_lower = Math::deg2rad(real_t(p_value));
- if (j.is_valid())
+ if (j.is_valid()) {
PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer3D::G6DOF_JOINT_ANGULAR_LOWER_LIMIT, axis_data[axis].angular_limit_lower);
+ }
} else if ("angular_limit_softness" == var_name) {
axis_data[axis].angular_limit_softness = p_value;
- if (j.is_valid())
+ if (j.is_valid()) {
PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer3D::G6DOF_JOINT_ANGULAR_LIMIT_SOFTNESS, axis_data[axis].angular_limit_softness);
+ }
} else if ("angular_restitution" == var_name) {
axis_data[axis].angular_restitution = p_value;
- if (j.is_valid())
+ if (j.is_valid()) {
PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer3D::G6DOF_JOINT_ANGULAR_RESTITUTION, axis_data[axis].angular_restitution);
+ }
} else if ("angular_damping" == var_name) {
axis_data[axis].angular_damping = p_value;
- if (j.is_valid())
+ if (j.is_valid()) {
PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer3D::G6DOF_JOINT_ANGULAR_DAMPING, axis_data[axis].angular_damping);
+ }
} else if ("erp" == var_name) {
axis_data[axis].erp = p_value;
- if (j.is_valid())
+ if (j.is_valid()) {
PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer3D::G6DOF_JOINT_ANGULAR_ERP, axis_data[axis].erp);
+ }
} else if ("angular_spring_enabled" == var_name) {
axis_data[axis].angular_spring_enabled = p_value;
- if (j.is_valid())
+ if (j.is_valid()) {
PhysicsServer3D::get_singleton()->generic_6dof_joint_set_flag(j, axis, PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_ANGULAR_SPRING, axis_data[axis].angular_spring_enabled);
+ }
} else if ("angular_spring_stiffness" == var_name) {
axis_data[axis].angular_spring_stiffness = p_value;
- if (j.is_valid())
+ if (j.is_valid()) {
PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer3D::G6DOF_JOINT_ANGULAR_SPRING_STIFFNESS, axis_data[axis].angular_spring_stiffness);
+ }
} else if ("angular_spring_damping" == var_name) {
axis_data[axis].angular_spring_damping = p_value;
- if (j.is_valid())
+ if (j.is_valid()) {
PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer3D::G6DOF_JOINT_ANGULAR_SPRING_DAMPING, axis_data[axis].angular_spring_damping);
+ }
} else if ("angular_equilibrium_point" == var_name) {
axis_data[axis].angular_equilibrium_point = p_value;
- if (j.is_valid())
+ if (j.is_valid()) {
PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer3D::G6DOF_JOINT_ANGULAR_SPRING_EQUILIBRIUM_POINT, axis_data[axis].angular_equilibrium_point);
+ }
} else {
return false;
@@ -1925,8 +1983,9 @@ bool PhysicalBone3D::_set(const StringName &p_name, const Variant &p_value) {
if (joint_data) {
if (joint_data->_set(p_name, p_value)) {
#ifdef TOOLS_ENABLED
- if (get_gizmo().is_valid())
+ if (get_gizmo().is_valid()) {
get_gizmo()->redraw();
+ }
#endif
return true;
}
@@ -1954,8 +2013,9 @@ void PhysicalBone3D::_get_property_list(List<PropertyInfo> *p_list) const {
if (parent) {
String names;
for (int i = 0; i < parent->get_bone_count(); i++) {
- if (i > 0)
+ if (i > 0) {
names += ",";
+ }
names += parent->get_bone_name(i);
}
@@ -2130,8 +2190,9 @@ void PhysicalBone3D::_update_joint_offset() {
set_ignore_transform_notification(false);
#ifdef TOOLS_ENABLED
- if (get_gizmo().is_valid())
+ if (get_gizmo().is_valid()) {
get_gizmo()->redraw();
+ }
#endif
}
@@ -2269,11 +2330,13 @@ Skeleton3D *PhysicalBone3D::find_skeleton_parent() {
}
void PhysicalBone3D::set_joint_type(JointType p_joint_type) {
- if (p_joint_type == get_joint_type())
+ if (p_joint_type == get_joint_type()) {
return;
+ }
- if (joint_data)
+ if (joint_data) {
memdelete(joint_data);
+ }
joint_data = nullptr;
switch (p_joint_type) {
case JOINT_TYPE_PIN:
@@ -2299,8 +2362,9 @@ void PhysicalBone3D::set_joint_type(JointType p_joint_type) {
#ifdef TOOLS_ENABLED
_change_notify();
- if (get_gizmo().is_valid())
+ if (get_gizmo().is_valid()) {
get_gizmo()->redraw();
+ }
#endif
}
@@ -2470,8 +2534,9 @@ PhysicalBone3D::PhysicalBone3D() :
}
PhysicalBone3D::~PhysicalBone3D() {
- if (joint_data)
+ if (joint_data) {
memdelete(joint_data);
+ }
}
void PhysicalBone3D::update_bone_id() {
@@ -2501,8 +2566,9 @@ void PhysicalBone3D::update_offset() {
#ifdef TOOLS_ENABLED
if (parent_skeleton) {
Transform bone_transform(parent_skeleton->get_global_transform());
- if (-1 != bone_id)
+ if (-1 != bone_id) {
bone_transform *= parent_skeleton->get_bone_global_pose(bone_id);
+ }
if (gizmo_move_joint) {
bone_transform *= body_offset;
diff --git a/scene/3d/physics_body_3d.h b/scene/3d/physics_body_3d.h
index 3a5b94e3b7..4c58c73942 100644
--- a/scene/3d/physics_body_3d.h
+++ b/scene/3d/physics_body_3d.h
@@ -139,10 +139,11 @@ protected:
int local_shape;
bool tagged;
bool operator<(const ShapePair &p_sp) const {
- if (body_shape == p_sp.body_shape)
+ if (body_shape == p_sp.body_shape) {
return local_shape < p_sp.local_shape;
- else
+ } else {
return body_shape < p_sp.body_shape;
+ }
}
ShapePair() {}
diff --git a/scene/3d/physics_joint_3d.cpp b/scene/3d/physics_joint_3d.cpp
index 99d0473d9b..af4d6ae152 100644
--- a/scene/3d/physics_joint_3d.cpp
+++ b/scene/3d/physics_joint_3d.cpp
@@ -32,8 +32,9 @@
void Joint3D::_update_joint(bool p_only_free) {
if (joint.is_valid()) {
- if (ba.is_valid() && bb.is_valid())
+ if (ba.is_valid() && bb.is_valid()) {
PhysicsServer3D::get_singleton()->body_remove_collision_exception(ba, bb);
+ }
PhysicsServer3D::get_singleton()->free(joint);
joint = RID();
@@ -41,8 +42,9 @@ void Joint3D::_update_joint(bool p_only_free) {
bb = RID();
}
- if (p_only_free || !is_inside_tree())
+ if (p_only_free || !is_inside_tree()) {
return;
+ }
Node *node_a = has_node(get_node_a()) ? get_node(get_node_a()) : (Node *)nullptr;
Node *node_b = has_node(get_node_b()) ? get_node(get_node_b()) : (Node *)nullptr;
@@ -50,29 +52,34 @@ void Joint3D::_update_joint(bool p_only_free) {
PhysicsBody3D *body_a = Object::cast_to<PhysicsBody3D>(node_a);
PhysicsBody3D *body_b = Object::cast_to<PhysicsBody3D>(node_b);
- if (!body_a && body_b)
+ if (!body_a && body_b) {
SWAP(body_a, body_b);
+ }
- if (!body_a)
+ if (!body_a) {
return;
+ }
joint = _configure_joint(body_a, body_b);
- if (!joint.is_valid())
+ if (!joint.is_valid()) {
return;
+ }
PhysicsServer3D::get_singleton()->joint_set_solver_priority(joint, solver_priority);
ba = body_a->get_rid();
- if (body_b)
+ if (body_b) {
bb = body_b->get_rid();
+ }
PhysicsServer3D::get_singleton()->joint_disable_collisions_between_bodies(joint, exclude_from_collision);
}
void Joint3D::set_node_a(const NodePath &p_node_a) {
- if (a == p_node_a)
+ if (a == p_node_a) {
return;
+ }
a = p_node_a;
_update_joint();
@@ -83,8 +90,9 @@ NodePath Joint3D::get_node_a() const {
}
void Joint3D::set_node_b(const NodePath &p_node_b) {
- if (b == p_node_b)
+ if (b == p_node_b) {
return;
+ }
b = p_node_b;
_update_joint();
}
@@ -95,8 +103,9 @@ NodePath Joint3D::get_node_b() const {
void Joint3D::set_solver_priority(int p_priority) {
solver_priority = p_priority;
- if (joint.is_valid())
+ if (joint.is_valid()) {
PhysicsServer3D::get_singleton()->joint_set_solver_priority(joint, solver_priority);
+ }
}
int Joint3D::get_solver_priority() const {
@@ -117,8 +126,9 @@ void Joint3D::_notification(int p_what) {
}
void Joint3D::set_exclude_nodes_from_collision(bool p_enable) {
- if (exclude_from_collision == p_enable)
+ if (exclude_from_collision == p_enable) {
return;
+ }
exclude_from_collision = p_enable;
_update_joint();
}
@@ -171,8 +181,9 @@ void PinJoint3D::_bind_methods() {
void PinJoint3D::set_param(Param p_param, float p_value) {
ERR_FAIL_INDEX(p_param, 3);
params[p_param] = p_value;
- if (get_joint().is_valid())
+ if (get_joint().is_valid()) {
PhysicsServer3D::get_singleton()->pin_joint_set_param(get_joint(), PhysicsServer3D::PinJointParam(p_param), p_value);
+ }
}
float PinJoint3D::get_param(Param p_param) const {
@@ -185,10 +196,11 @@ RID PinJoint3D::_configure_joint(PhysicsBody3D *body_a, PhysicsBody3D *body_b) {
Vector3 local_a = body_a->get_global_transform().affine_inverse().xform(pinpos);
Vector3 local_b;
- if (body_b)
+ if (body_b) {
local_b = body_b->get_global_transform().affine_inverse().xform(pinpos);
- else
+ } else {
local_b = pinpos;
+ }
RID j = PhysicsServer3D::get_singleton()->joint_create_pin(body_a->get_rid(), local_a, body_b ? body_b->get_rid() : RID(), local_b);
for (int i = 0; i < 3; i++) {
@@ -267,8 +279,9 @@ void HingeJoint3D::_bind_methods() {
void HingeJoint3D::set_param(Param p_param, float p_value) {
ERR_FAIL_INDEX(p_param, PARAM_MAX);
params[p_param] = p_value;
- if (get_joint().is_valid())
+ if (get_joint().is_valid()) {
PhysicsServer3D::get_singleton()->hinge_joint_set_param(get_joint(), PhysicsServer3D::HingeJointParam(p_param), p_value);
+ }
update_gizmo();
}
@@ -281,8 +294,9 @@ float HingeJoint3D::get_param(Param p_param) const {
void HingeJoint3D::set_flag(Flag p_flag, bool p_value) {
ERR_FAIL_INDEX(p_flag, FLAG_MAX);
flags[p_flag] = p_value;
- if (get_joint().is_valid())
+ if (get_joint().is_valid()) {
PhysicsServer3D::get_singleton()->hinge_joint_set_flag(get_joint(), PhysicsServer3D::HingeJointFlag(p_flag), p_value);
+ }
update_gizmo();
}
@@ -416,8 +430,9 @@ void SliderJoint3D::_bind_methods() {
void SliderJoint3D::set_param(Param p_param, float p_value) {
ERR_FAIL_INDEX(p_param, PARAM_MAX);
params[p_param] = p_value;
- if (get_joint().is_valid())
+ if (get_joint().is_valid()) {
PhysicsServer3D::get_singleton()->slider_joint_set_param(get_joint(), PhysicsServer3D::SliderJointParam(p_param), p_value);
+ }
update_gizmo();
}
@@ -521,8 +536,9 @@ void ConeTwistJoint3D::_bind_methods() {
void ConeTwistJoint3D::set_param(Param p_param, float p_value) {
ERR_FAIL_INDEX(p_param, PARAM_MAX);
params[p_param] = p_value;
- if (get_joint().is_valid())
+ if (get_joint().is_valid()) {
PhysicsServer3D::get_singleton()->cone_twist_joint_set_param(get_joint(), PhysicsServer3D::ConeTwistJointParam(p_param), p_value);
+ }
update_gizmo();
}
@@ -782,8 +798,9 @@ void Generic6DOFJoint3D::_bind_methods() {
void Generic6DOFJoint3D::set_param_x(Param p_param, float p_value) {
ERR_FAIL_INDEX(p_param, PARAM_MAX);
params_x[p_param] = p_value;
- if (get_joint().is_valid())
+ if (get_joint().is_valid()) {
PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(get_joint(), Vector3::AXIS_X, PhysicsServer3D::G6DOFJointAxisParam(p_param), p_value);
+ }
update_gizmo();
}
@@ -796,8 +813,9 @@ float Generic6DOFJoint3D::get_param_x(Param p_param) const {
void Generic6DOFJoint3D::set_param_y(Param p_param, float p_value) {
ERR_FAIL_INDEX(p_param, PARAM_MAX);
params_y[p_param] = p_value;
- if (get_joint().is_valid())
+ if (get_joint().is_valid()) {
PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(get_joint(), Vector3::AXIS_Y, PhysicsServer3D::G6DOFJointAxisParam(p_param), p_value);
+ }
update_gizmo();
}
@@ -809,8 +827,9 @@ float Generic6DOFJoint3D::get_param_y(Param p_param) const {
void Generic6DOFJoint3D::set_param_z(Param p_param, float p_value) {
ERR_FAIL_INDEX(p_param, PARAM_MAX);
params_z[p_param] = p_value;
- if (get_joint().is_valid())
+ if (get_joint().is_valid()) {
PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(get_joint(), Vector3::AXIS_Z, PhysicsServer3D::G6DOFJointAxisParam(p_param), p_value);
+ }
update_gizmo();
}
@@ -822,8 +841,9 @@ float Generic6DOFJoint3D::get_param_z(Param p_param) const {
void Generic6DOFJoint3D::set_flag_x(Flag p_flag, bool p_enabled) {
ERR_FAIL_INDEX(p_flag, FLAG_MAX);
flags_x[p_flag] = p_enabled;
- if (get_joint().is_valid())
+ if (get_joint().is_valid()) {
PhysicsServer3D::get_singleton()->generic_6dof_joint_set_flag(get_joint(), Vector3::AXIS_X, PhysicsServer3D::G6DOFJointAxisFlag(p_flag), p_enabled);
+ }
update_gizmo();
}
@@ -835,8 +855,9 @@ bool Generic6DOFJoint3D::get_flag_x(Flag p_flag) const {
void Generic6DOFJoint3D::set_flag_y(Flag p_flag, bool p_enabled) {
ERR_FAIL_INDEX(p_flag, FLAG_MAX);
flags_y[p_flag] = p_enabled;
- if (get_joint().is_valid())
+ if (get_joint().is_valid()) {
PhysicsServer3D::get_singleton()->generic_6dof_joint_set_flag(get_joint(), Vector3::AXIS_Y, PhysicsServer3D::G6DOFJointAxisFlag(p_flag), p_enabled);
+ }
update_gizmo();
}
@@ -848,8 +869,9 @@ bool Generic6DOFJoint3D::get_flag_y(Flag p_flag) const {
void Generic6DOFJoint3D::set_flag_z(Flag p_flag, bool p_enabled) {
ERR_FAIL_INDEX(p_flag, FLAG_MAX);
flags_z[p_flag] = p_enabled;
- if (get_joint().is_valid())
+ if (get_joint().is_valid()) {
PhysicsServer3D::get_singleton()->generic_6dof_joint_set_flag(get_joint(), Vector3::AXIS_Z, PhysicsServer3D::G6DOFJointAxisFlag(p_flag), p_enabled);
+ }
update_gizmo();
}
diff --git a/scene/3d/proximity_group_3d.cpp b/scene/3d/proximity_group_3d.cpp
index cef3381fc1..cdc88abf4c 100644
--- a/scene/3d/proximity_group_3d.cpp
+++ b/scene/3d/proximity_group_3d.cpp
@@ -58,8 +58,9 @@ void ProximityGroup3D::clear_groups() {
};
void ProximityGroup3D::update_groups() {
- if (grid_radius == Vector3(0, 0, 0))
+ if (grid_radius == Vector3(0, 0, 0)) {
return;
+ }
++group_version;
diff --git a/scene/3d/ray_cast_3d.cpp b/scene/3d/ray_cast_3d.cpp
index 1b91e58f8f..68f4b3132c 100644
--- a/scene/3d/ray_cast_3d.cpp
+++ b/scene/3d/ray_cast_3d.cpp
@@ -37,10 +37,12 @@
void RayCast3D::set_cast_to(const Vector3 &p_point) {
cast_to = p_point;
- if (is_inside_tree() && (Engine::get_singleton()->is_editor_hint() || get_tree()->is_debugging_collisions_hint()))
+ if (is_inside_tree() && (Engine::get_singleton()->is_editor_hint() || get_tree()->is_debugging_collisions_hint())) {
update_gizmo();
- if (is_inside_tree() && get_tree()->is_debugging_collisions_hint())
+ }
+ if (is_inside_tree() && get_tree()->is_debugging_collisions_hint()) {
_update_debug_shape();
+ }
}
Vector3 RayCast3D::get_cast_to() const {
@@ -57,10 +59,11 @@ uint32_t RayCast3D::get_collision_mask() const {
void RayCast3D::set_collision_mask_bit(int p_bit, bool p_value) {
uint32_t mask = get_collision_mask();
- if (p_value)
+ if (p_value) {
mask |= 1 << p_bit;
- else
+ } else {
mask &= ~(1 << p_bit);
+ }
set_collision_mask(mask);
}
@@ -73,8 +76,9 @@ bool RayCast3D::is_colliding() const {
}
Object *RayCast3D::get_collider() const {
- if (against.is_null())
+ if (against.is_null()) {
return nullptr;
+ }
return ObjectDB::get_instance(against);
}
@@ -95,16 +99,19 @@ void RayCast3D::set_enabled(bool p_enabled) {
enabled = p_enabled;
update_gizmo();
- if (is_inside_tree() && !Engine::get_singleton()->is_editor_hint())
+ if (is_inside_tree() && !Engine::get_singleton()->is_editor_hint()) {
set_physics_process_internal(p_enabled);
- if (!p_enabled)
+ }
+ if (!p_enabled) {
collided = false;
+ }
if (is_inside_tree() && get_tree()->is_debugging_collisions_hint()) {
- if (p_enabled)
+ if (p_enabled) {
_update_debug_shape();
- else
+ } else {
_clear_debug_shape();
+ }
}
}
@@ -113,19 +120,22 @@ bool RayCast3D::is_enabled() const {
}
void RayCast3D::set_exclude_parent_body(bool p_exclude_parent_body) {
- if (exclude_parent_body == p_exclude_parent_body)
+ if (exclude_parent_body == p_exclude_parent_body) {
return;
+ }
exclude_parent_body = p_exclude_parent_body;
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
if (Object::cast_to<CollisionObject3D>(get_parent())) {
- if (exclude_parent_body)
+ if (exclude_parent_body) {
exclude.insert(Object::cast_to<CollisionObject3D>(get_parent())->get_rid());
- else
+ } else {
exclude.erase(Object::cast_to<CollisionObject3D>(get_parent())->get_rid());
+ }
}
}
@@ -139,16 +149,19 @@ void RayCast3D::_notification(int p_what) {
if (enabled && !Engine::get_singleton()->is_editor_hint()) {
set_physics_process_internal(true);
- if (get_tree()->is_debugging_collisions_hint())
+ if (get_tree()->is_debugging_collisions_hint()) {
_update_debug_shape();
- } else
+ }
+ } else {
set_physics_process_internal(false);
+ }
if (Object::cast_to<CollisionObject3D>(get_parent())) {
- if (exclude_parent_body)
+ if (exclude_parent_body) {
exclude.insert(Object::cast_to<CollisionObject3D>(get_parent())->get_rid());
- else
+ } else {
exclude.erase(Object::cast_to<CollisionObject3D>(get_parent())->get_rid());
+ }
}
} break;
@@ -157,13 +170,15 @@ void RayCast3D::_notification(int p_what) {
set_physics_process_internal(false);
}
- if (debug_shape)
+ if (debug_shape) {
_clear_debug_shape();
+ }
} break;
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
- if (!enabled)
+ if (!enabled) {
break;
+ }
bool prev_collision_state = collided;
_update_raycast_state();
@@ -188,8 +203,9 @@ void RayCast3D::_update_raycast_state() {
Transform gt = get_global_transform();
Vector3 to = cast_to;
- if (to == Vector3())
+ if (to == Vector3()) {
to = Vector3(0, 0.01, 0);
+ }
PhysicsDirectSpaceState3D::RayResult rr;
@@ -217,8 +233,9 @@ void RayCast3D::add_exception_rid(const RID &p_rid) {
void RayCast3D::add_exception(const Object *p_object) {
ERR_FAIL_NULL(p_object);
const CollisionObject3D *co = Object::cast_to<CollisionObject3D>(p_object);
- if (!co)
+ if (!co) {
return;
+ }
add_exception_rid(co->get_rid());
}
@@ -229,8 +246,9 @@ void RayCast3D::remove_exception_rid(const RID &p_rid) {
void RayCast3D::remove_exception(const Object *p_object) {
ERR_FAIL_NULL(p_object);
const CollisionObject3D *co = Object::cast_to<CollisionObject3D>(p_object);
- if (!co)
+ if (!co) {
return;
+ }
remove_exception_rid(co->get_rid());
}
@@ -321,15 +339,18 @@ void RayCast3D::_create_debug_shape() {
}
void RayCast3D::_update_debug_shape() {
- if (!enabled)
+ if (!enabled) {
return;
+ }
- if (!debug_shape)
+ if (!debug_shape) {
_create_debug_shape();
+ }
MeshInstance3D *mi = static_cast<MeshInstance3D *>(debug_shape);
- if (!mi->get_mesh().is_valid())
+ if (!mi->get_mesh().is_valid()) {
return;
+ }
Ref<ArrayMesh> mesh = mi->get_mesh();
mesh->clear_surfaces();
@@ -347,14 +368,16 @@ void RayCast3D::_update_debug_shape() {
}
void RayCast3D::_clear_debug_shape() {
- if (!debug_shape)
+ if (!debug_shape) {
return;
+ }
MeshInstance3D *mi = static_cast<MeshInstance3D *>(debug_shape);
- if (mi->is_inside_tree())
+ if (mi->is_inside_tree()) {
mi->queue_delete();
- else
+ } else {
memdelete(mi);
+ }
debug_shape = nullptr;
}
diff --git a/scene/3d/remote_transform_3d.cpp b/scene/3d/remote_transform_3d.cpp
index 7872a8ee1c..95fce6b802 100644
--- a/scene/3d/remote_transform_3d.cpp
+++ b/scene/3d/remote_transform_3d.cpp
@@ -43,18 +43,22 @@ void RemoteTransform3D::_update_cache() {
}
void RemoteTransform3D::_update_remote() {
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
- if (cache.is_null())
+ if (cache.is_null()) {
return;
+ }
Node3D *n = Object::cast_to<Node3D>(ObjectDB::get_instance(cache));
- if (!n)
+ if (!n) {
return;
+ }
- if (!n->is_inside_tree())
+ if (!n->is_inside_tree()) {
return;
+ }
//todo make faster
if (use_global_coordinates) {
@@ -63,11 +67,13 @@ void RemoteTransform3D::_update_remote() {
} else {
Transform our_trans = get_global_transform();
- if (update_remote_rotation)
+ if (update_remote_rotation) {
n->set_rotation(our_trans.basis.get_rotation());
+ }
- if (update_remote_scale)
+ if (update_remote_scale) {
n->set_scale(our_trans.basis.get_scale());
+ }
if (update_remote_position) {
Transform n_trans = n->get_global_transform();
@@ -83,11 +89,13 @@ void RemoteTransform3D::_update_remote() {
} else {
Transform our_trans = get_transform();
- if (update_remote_rotation)
+ if (update_remote_rotation) {
n->set_rotation(our_trans.basis.get_rotation());
+ }
- if (update_remote_scale)
+ if (update_remote_scale) {
n->set_scale(our_trans.basis.get_scale());
+ }
if (update_remote_position) {
Transform n_trans = n->get_transform();
@@ -106,8 +114,9 @@ void RemoteTransform3D::_notification(int p_what) {
} break;
case NOTIFICATION_TRANSFORM_CHANGED: {
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
break;
+ }
if (cache.is_valid()) {
_update_remote();
diff --git a/scene/3d/skeleton_3d.cpp b/scene/3d/skeleton_3d.cpp
index 899579fdbc..7516cf95b0 100644
--- a/scene/3d/skeleton_3d.cpp
+++ b/scene/3d/skeleton_3d.cpp
@@ -69,8 +69,9 @@ SkinReference::~SkinReference() {
bool Skeleton3D::_set(const StringName &p_path, const Variant &p_value) {
String path = p_path;
- if (!path.begins_with("bones/"))
+ if (!path.begins_with("bones/")) {
return false;
+ }
int which = path.get_slicec('/', 1).to_int();
String what = path.get_slicec('/', 2);
@@ -82,15 +83,15 @@ bool Skeleton3D::_set(const StringName &p_path, const Variant &p_value) {
ERR_FAIL_INDEX_V(which, bones.size(), false);
- if (what == "parent")
+ if (what == "parent") {
set_bone_parent(which, p_value);
- else if (what == "rest")
+ } else if (what == "rest") {
set_bone_rest(which, p_value);
- else if (what == "enabled")
+ } else if (what == "enabled") {
set_bone_enabled(which, p_value);
- else if (what == "pose")
+ } else if (what == "pose") {
set_bone_pose(which, p_value);
- else if (what == "bound_children") {
+ } else if (what == "bound_children") {
Array children = p_value;
if (is_inside_tree()) {
@@ -114,25 +115,26 @@ bool Skeleton3D::_set(const StringName &p_path, const Variant &p_value) {
bool Skeleton3D::_get(const StringName &p_path, Variant &r_ret) const {
String path = p_path;
- if (!path.begins_with("bones/"))
+ if (!path.begins_with("bones/")) {
return false;
+ }
int which = path.get_slicec('/', 1).to_int();
String what = path.get_slicec('/', 2);
ERR_FAIL_INDEX_V(which, bones.size(), false);
- if (what == "name")
+ if (what == "name") {
r_ret = get_bone_name(which);
- else if (what == "parent")
+ } else if (what == "parent") {
r_ret = get_bone_parent(which);
- else if (what == "rest")
+ } else if (what == "rest") {
r_ret = get_bone_rest(which);
- else if (what == "enabled")
+ } else if (what == "enabled") {
r_ret = is_bone_enabled(which);
- else if (what == "pose")
+ } else if (what == "pose") {
r_ret = get_bone_pose(which);
- else if (what == "bound_children") {
+ } else if (what == "bound_children") {
Array children;
for (const List<ObjectID>::Element *E = bones[which].nodes_bound.front(); E; E = E->next()) {
@@ -145,8 +147,9 @@ bool Skeleton3D::_get(const StringName &p_path, Variant &r_ret) const {
}
r_ret = children;
- } else
+ } else {
return false;
+ }
return true;
}
@@ -164,8 +167,9 @@ void Skeleton3D::_get_property_list(List<PropertyInfo> *p_list) const {
}
void Skeleton3D::_update_process_order() {
- if (!process_order_dirty)
+ if (!process_order_dirty) {
return;
+ }
Bone *bonesptr = bones.ptrw();
int len = bones.size();
@@ -189,8 +193,9 @@ void Skeleton3D::_update_process_order() {
bool swapped = false;
for (int i = 0; i < len; i++) {
int parent_idx = bonesptr[order[i]].parent;
- if (parent_idx < 0)
+ if (parent_idx < 0) {
continue; //do nothing because it has no parent
+ }
//swap indices
int parent_order = bonesptr[parent_idx].sort_index;
if (parent_order > i) {
@@ -202,8 +207,9 @@ void Skeleton3D::_update_process_order() {
}
}
- if (!swapped)
+ if (!swapped) {
break;
+ }
pass_count++;
}
@@ -387,8 +393,9 @@ void Skeleton3D::set_bone_global_pose_override(int p_bone, const Transform &p_po
Transform Skeleton3D::get_bone_global_pose(int p_bone) const {
ERR_FAIL_INDEX_V(p_bone, bones.size(), Transform());
- if (dirty)
+ if (dirty) {
const_cast<Skeleton3D *>(this)->notification(NOTIFICATION_UPDATE_SKELETON);
+ }
return bones[p_bone].pose_global;
}
@@ -411,8 +418,9 @@ void Skeleton3D::add_bone(const String &p_name) {
int Skeleton3D::find_bone(const String &p_name) const {
for (int i = 0; i < bones.size(); i++) {
- if (bones[i].name == p_name)
+ if (bones[i].name == p_name) {
return i;
+ }
}
return -1;
@@ -427,11 +435,13 @@ String Skeleton3D::get_bone_name(int p_bone) const {
bool Skeleton3D::is_bone_parent_of(int p_bone, int p_parent_bone_id) const {
int parent_of_bone = get_bone_parent(p_bone);
- if (-1 == parent_of_bone)
+ if (-1 == parent_of_bone) {
return false;
+ }
- if (parent_of_bone == p_parent_bone_id)
+ if (parent_of_bone == p_parent_bone_id) {
return true;
+ }
return is_bone_parent_of(parent_of_bone, p_parent_bone_id);
}
@@ -514,8 +524,9 @@ void Skeleton3D::bind_child_node_to_bone(int p_bone, Node *p_node) {
ObjectID id = p_node->get_instance_id();
for (const List<ObjectID>::Element *E = bones[p_bone].nodes_bound.front(); E; E = E->next()) {
- if (E->get() == id)
+ if (E->get() == id) {
return; // already here
+ }
}
bones.write[p_bone].nodes_bound.push_back(id);
@@ -578,8 +589,9 @@ Transform Skeleton3D::get_bone_custom_pose(int p_bone) const {
}
void Skeleton3D::_make_dirty() {
- if (dirty)
+ if (dirty) {
return;
+ }
MessageQueue::get_singleton()->push_notification(this, NOTIFICATION_UPDATE_SKELETON);
dirty = true;
@@ -679,8 +691,9 @@ void Skeleton3D::_rebuild_physical_bones_cache() {
PhysicalBone3D *parent_pb = _get_physical_bone_parent(i);
if (parent_pb != bones[i].physical_bone) {
bones.write[i].cache_parent_physical_bone = parent_pb;
- if (bones[i].physical_bone)
+ if (bones[i].physical_bone) {
bones[i].physical_bone->_on_bone_parent_changed();
+ }
}
}
}
@@ -730,8 +743,9 @@ void Skeleton3D::physical_bones_start_simulation_on(const TypedArray<StringName>
int c = 0;
for (int i = sim_bones.size() - 1; 0 <= i; --i) {
int bone_id = find_bone(p_bones[i]);
- if (bone_id != -1)
+ if (bone_id != -1) {
sim_bones.write[c++] = bone_id;
+ }
}
sim_bones.resize(c);
}
diff --git a/scene/3d/skeleton_ik_3d.cpp b/scene/3d/skeleton_ik_3d.cpp
index 40c91fca69..9023f3c68a 100644
--- a/scene/3d/skeleton_ik_3d.cpp
+++ b/scene/3d/skeleton_ik_3d.cpp
@@ -113,8 +113,9 @@ bool FabrikInverseKinematic::build_chain(Task *p_task, bool p_force_simple_chain
}
}
- if (!middle_chain_item_id)
+ if (!middle_chain_item_id) {
chain.middle_chain_item = nullptr;
+ }
// Initialize current tip
chain.tips.write[x].chain_item = sub_chain;
@@ -132,8 +133,9 @@ bool FabrikInverseKinematic::build_chain(Task *p_task, bool p_force_simple_chain
}
void FabrikInverseKinematic::update_chain(const Skeleton3D *p_sk, ChainItem *p_chain_item) {
- if (!p_chain_item)
+ if (!p_chain_item) {
return;
+ }
p_chain_item->initial_transform = p_sk->get_bone_global_pose(p_chain_item->bone);
p_chain_item->current_pos = p_chain_item->initial_transform.origin;
@@ -246,8 +248,9 @@ FabrikInverseKinematic::Task *FabrikInverseKinematic::create_simple_task(Skeleto
}
void FabrikInverseKinematic::free_task(Task *p_task) {
- if (p_task)
+ if (p_task) {
memdelete(p_task);
+ }
}
void FabrikInverseKinematic::set_goal(Task *p_task, const Transform &p_goal) {
@@ -309,18 +312,20 @@ void FabrikInverseKinematic::solve(Task *p_task, real_t blending_delta, bool ove
}
} else {
// Set target orientation to tip
- if (override_tip_basis)
+ if (override_tip_basis) {
new_bone_pose.basis = p_task->chain.tips[0].end_effector->goal_transform.basis;
- else
+ } else {
new_bone_pose.basis = new_bone_pose.basis * p_task->chain.tips[0].end_effector->goal_transform.basis;
+ }
}
p_task->skeleton->set_bone_global_pose_override(ci->bone, new_bone_pose, 1.0, true);
- if (!ci->children.empty())
+ if (!ci->children.empty()) {
ci = &ci->children.write[0];
- else
+ } else {
ci = nullptr;
+ }
}
}
@@ -329,8 +334,9 @@ void SkeletonIK3D::_validate_property(PropertyInfo &property) const {
if (skeleton) {
String names("--,");
for (int i = 0; i < skeleton->get_bone_count(); i++) {
- if (i > 0)
+ if (i > 0) {
names += ",";
+ }
names += skeleton->get_bone_name(i);
}
@@ -400,8 +406,9 @@ void SkeletonIK3D::_notification(int p_what) {
reload_chain();
} break;
case NOTIFICATION_INTERNAL_PROCESS: {
- if (target_node_override)
+ if (target_node_override) {
reload_goal();
+ }
_solve_chain();
@@ -515,21 +522,24 @@ void SkeletonIK3D::stop() {
}
Transform SkeletonIK3D::_get_target_transform() {
- if (!target_node_override && !target_node_path_override.is_empty())
+ if (!target_node_override && !target_node_path_override.is_empty()) {
target_node_override = Object::cast_to<Node3D>(get_node(target_node_path_override));
+ }
- if (target_node_override)
+ if (target_node_override) {
return target_node_override->get_global_transform();
- else
+ } else {
return target;
+ }
}
void SkeletonIK3D::reload_chain() {
FabrikInverseKinematic::free_task(task);
task = nullptr;
- if (!skeleton)
+ if (!skeleton) {
return;
+ }
task = FabrikInverseKinematic::create_simple_task(skeleton, skeleton->find_bone(root_bone), skeleton->find_bone(tip_bone), _get_target_transform());
if (task) {
@@ -539,15 +549,17 @@ void SkeletonIK3D::reload_chain() {
}
void SkeletonIK3D::reload_goal() {
- if (!task)
+ if (!task) {
return;
+ }
FabrikInverseKinematic::set_goal(task, _get_target_transform());
}
void SkeletonIK3D::_solve_chain() {
- if (!task)
+ if (!task) {
return;
+ }
FabrikInverseKinematic::solve(task, interpolation, override_tip_basis, use_magnet, magnet_position);
}
diff --git a/scene/3d/soft_body_3d.cpp b/scene/3d/soft_body_3d.cpp
index 47c568e9b4..a267c57f5e 100644
--- a/scene/3d/soft_body_3d.cpp
+++ b/scene/3d/soft_body_3d.cpp
@@ -115,8 +115,9 @@ SoftBody3D::PinnedPoint SoftBody3D::PinnedPoint::operator=(const PinnedPoint &ob
}
void SoftBody3D::_update_pickable() {
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
bool pickable = ray_pickable && is_visible_in_tree();
PhysicsServer3D::get_singleton()->soft_body_set_ray_pickable(physics_rid, pickable);
}
@@ -196,8 +197,9 @@ bool SoftBody3D::_set_property_pinned_points_indices(const Array &p_indices) {
for (int i = 0; i < p_indices_size; ++i) {
point_index = p_indices.get(i);
if (w[i].point_index != point_index) {
- if (-1 != w[i].point_index)
+ if (-1 != w[i].point_index) {
pin_point(w[i].point_index, false);
+ }
w[i].point_index = point_index;
pin_point(w[i].point_index, true);
}
@@ -265,8 +267,9 @@ void SoftBody3D::_notification(int p_what) {
prepare_physics_server();
} break;
case NOTIFICATION_READY: {
- if (!parent_collision_ignore.is_empty())
+ if (!parent_collision_ignore.is_empty()) {
add_collision_exception_with(get_node(parent_collision_ignore));
+ }
} break;
case NOTIFICATION_TRANSFORM_CHANGED: {
@@ -377,16 +380,18 @@ String SoftBody3D::get_configuration_warning() const {
String warning = MeshInstance3D::get_configuration_warning();
if (get_mesh().is_null()) {
- if (!warning.empty())
+ if (!warning.empty()) {
warning += "\n\n";
+ }
warning += TTR("This body will be ignored until you set a mesh.");
}
Transform t = get_transform();
if ((ABS(t.basis.get_axis(0).length() - 1.0) > 0.05 || ABS(t.basis.get_axis(1).length() - 1.0) > 0.05 || ABS(t.basis.get_axis(2).length() - 1.0) > 0.05)) {
- if (!warning.empty())
+ if (!warning.empty()) {
warning += "\n\n";
+ }
warning += TTR("Size changes to SoftBody3D will be overridden by the physics engine when running.\nChange the size in children collision shapes instead.");
}
@@ -395,8 +400,9 @@ String SoftBody3D::get_configuration_warning() const {
}
void SoftBody3D::_update_physics_server() {
- if (!simulation_started)
+ if (!simulation_started) {
return;
+ }
_update_cache_pin_points_datas();
// Submit bone attachment
@@ -410,8 +416,9 @@ void SoftBody3D::_update_physics_server() {
}
void SoftBody3D::_draw_soft_mesh() {
- if (get_mesh().is_null())
+ if (get_mesh().is_null()) {
return;
+ }
if (!rendering_server_handler.is_ready()) {
rendering_server_handler.prepare(get_mesh()->get_rid(), 0);
@@ -433,10 +440,11 @@ void SoftBody3D::_draw_soft_mesh() {
void SoftBody3D::prepare_physics_server() {
if (Engine::get_singleton()->is_editor_hint()) {
- if (get_mesh().is_valid())
+ if (get_mesh().is_valid()) {
PhysicsServer3D::get_singleton()->soft_body_set_mesh(physics_rid, get_mesh());
- else
+ } else {
PhysicsServer3D::get_singleton()->soft_body_set_mesh(physics_rid, nullptr);
+ }
return;
}
@@ -454,8 +462,9 @@ void SoftBody3D::prepare_physics_server() {
}
void SoftBody3D::become_mesh_owner() {
- if (mesh.is_null())
+ if (mesh.is_null()) {
return;
+ }
if (!mesh_owner) {
mesh_owner = true;
@@ -507,10 +516,11 @@ uint32_t SoftBody3D::get_collision_layer() const {
void SoftBody3D::set_collision_mask_bit(int p_bit, bool p_value) {
uint32_t mask = get_collision_mask();
- if (p_value)
+ if (p_value) {
mask |= 1 << p_bit;
- else
+ } else {
mask &= ~(1 << p_bit);
+ }
set_collision_mask(mask);
}
@@ -520,10 +530,11 @@ bool SoftBody3D::get_collision_mask_bit(int p_bit) const {
void SoftBody3D::set_collision_layer_bit(int p_bit, bool p_value) {
uint32_t layer = get_collision_layer();
- if (p_value)
+ if (p_value) {
layer |= 1 << p_bit;
- else
+ } else {
layer &= ~(1 << p_bit);
+ }
set_collision_layer(layer);
}
@@ -702,8 +713,9 @@ void SoftBody3D::_make_cache_dirty() {
}
void SoftBody3D::_update_cache_pin_points_datas() {
- if (!pinned_points_cache_dirty)
+ if (!pinned_points_cache_dirty) {
return;
+ }
pinned_points_cache_dirty = false;
@@ -749,17 +761,20 @@ void SoftBody3D::_add_pinned_point(int p_point_index, const NodePath &p_spatial_
}
void SoftBody3D::_reset_points_offsets() {
- if (!Engine::get_singleton()->is_editor_hint())
+ if (!Engine::get_singleton()->is_editor_hint()) {
return;
+ }
const PinnedPoint *r = pinned_points.ptr();
PinnedPoint *w = pinned_points.ptrw();
for (int i = pinned_points.size() - 1; 0 <= i; --i) {
- if (!r[i].spatial_attachment)
+ if (!r[i].spatial_attachment) {
w[i].spatial_attachment = Object::cast_to<Node3D>(get_node(r[i].spatial_attachment_path));
+ }
- if (!r[i].spatial_attachment)
+ if (!r[i].spatial_attachment) {
continue;
+ }
w[i].offset = (r[i].spatial_attachment->get_global_transform().affine_inverse() * get_global_transform()).xform(PhysicsServer3D::get_singleton()->soft_body_get_point_global_position(physics_rid, r[i].point_index));
}
diff --git a/scene/3d/spring_arm_3d.cpp b/scene/3d/spring_arm_3d.cpp
index 3f94645bae..9775ecc6c6 100644
--- a/scene/3d/spring_arm_3d.cpp
+++ b/scene/3d/spring_arm_3d.cpp
@@ -83,8 +83,9 @@ float SpringArm3D::get_length() const {
}
void SpringArm3D::set_length(float p_length) {
- if (is_inside_tree() && (Engine::get_singleton()->is_editor_hint() || get_tree()->is_debugging_collisions_hint()))
+ if (is_inside_tree() && (Engine::get_singleton()->is_editor_hint() || get_tree()->is_debugging_collisions_hint())) {
update_gizmo();
+ }
spring_length = p_length;
}
diff --git a/scene/3d/sprite_3d.cpp b/scene/3d/sprite_3d.cpp
index b6f71fcbf8..3b76cb6499 100644
--- a/scene/3d/sprite_3d.cpp
+++ b/scene/3d/sprite_3d.cpp
@@ -34,13 +34,15 @@
#include "scene/scene_string_names.h"
Color SpriteBase3D::_get_color_accum() {
- if (!color_dirty)
+ if (!color_dirty) {
return color_accum;
+ }
- if (parent_sprite)
+ if (parent_sprite) {
color_accum = parent_sprite->_get_color_accum();
- else
+ } else {
color_accum = Color(1, 1, 1, 1);
+ }
color_accum.r *= modulate.r;
color_accum.g *= modulate.g;
@@ -51,8 +53,9 @@ Color SpriteBase3D::_get_color_accum() {
}
void SpriteBase3D::_propagate_color_changed() {
- if (color_dirty)
+ if (color_dirty) {
return;
+ }
color_dirty = true;
_queue_update();
@@ -64,8 +67,9 @@ void SpriteBase3D::_propagate_color_changed() {
void SpriteBase3D::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE) {
- if (!pending_update)
+ if (!pending_update) {
_im_update();
+ }
parent_sprite = Object::cast_to<SpriteBase3D>(get_parent());
if (parent_sprite) {
@@ -163,8 +167,9 @@ void SpriteBase3D::_im_update() {
}
void SpriteBase3D::_queue_update() {
- if (pending_update)
+ if (pending_update) {
return;
+ }
triangle_mesh.unref();
update_gizmo();
@@ -182,8 +187,9 @@ Vector<Face3> SpriteBase3D::get_faces(uint32_t p_usage_flags) const {
}
Ref<TriangleMesh> SpriteBase3D::generate_triangle_mesh() const {
- if (triangle_mesh.is_valid())
+ if (triangle_mesh.is_valid()) {
return triangle_mesh;
+ }
Vector<Vector3> faces;
faces.resize(6);
@@ -191,8 +197,9 @@ Ref<TriangleMesh> SpriteBase3D::generate_triangle_mesh() const {
Rect2 final_rect = get_item_rect();
- if (final_rect.size.x == 0 || final_rect.size.y == 0)
+ if (final_rect.size.x == 0 || final_rect.size.y == 0) {
return Ref<TriangleMesh>();
+ }
float pixel_size = get_pixel_size();
@@ -340,8 +347,9 @@ SpriteBase3D::SpriteBase3D() {
parent_sprite = nullptr;
pI = nullptr;
- for (int i = 0; i < FLAG_MAX; i++)
+ for (int i = 0; i < FLAG_MAX; i++) {
flags[i] = i == FLAG_TRANSPARENT || i == FLAG_DOUBLE_SIDED;
+ }
alpha_cut = ALPHA_CUT_DISABLED;
billboard_mode = StandardMaterial3D::BILLBOARD_DISABLED;
@@ -364,35 +372,41 @@ void Sprite3D::_draw() {
RID immediate = get_immediate();
RS::get_singleton()->immediate_clear(immediate);
- if (!texture.is_valid())
+ if (!texture.is_valid()) {
return;
+ }
Vector2 tsize = texture->get_size();
- if (tsize.x == 0 || tsize.y == 0)
+ if (tsize.x == 0 || tsize.y == 0) {
return;
+ }
Rect2 base_rect;
- if (region)
+ if (region) {
base_rect = region_rect;
- else
+ } else {
base_rect = Rect2(0, 0, texture->get_width(), texture->get_height());
+ }
Size2 frame_size = base_rect.size / Size2(hframes, vframes);
Point2 frame_offset = Point2(frame % hframes, frame / hframes);
frame_offset *= frame_size;
Point2 dest_offset = get_offset();
- if (is_centered())
+ if (is_centered()) {
dest_offset -= frame_size / 2;
+ }
Rect2 src_rect(base_rect.position + frame_offset, frame_size);
Rect2 final_dst_rect(dest_offset, frame_size);
Rect2 final_rect;
Rect2 final_src_rect;
- if (!texture->get_rect_region(final_dst_rect, src_rect, final_rect, final_src_rect))
+ if (!texture->get_rect_region(final_dst_rect, src_rect, final_rect, final_src_rect)) {
return;
+ }
- if (final_rect.size.x == 0 || final_rect.size.y == 0)
+ if (final_rect.size.x == 0 || final_rect.size.y == 0) {
return;
+ }
Color color = _get_color_accum();
color.a *= get_opacity();
@@ -496,8 +510,9 @@ void Sprite3D::_texture_changed() {
}
void Sprite3D::set_texture(const Ref<Texture2D> &p_texture) {
- if (p_texture == texture)
+ if (p_texture == texture) {
return;
+ }
if (texture.is_valid()) {
texture->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &Sprite3D::_texture_changed));
}
@@ -513,8 +528,9 @@ Ref<Texture2D> Sprite3D::get_texture() const {
}
void Sprite3D::set_region(bool p_region) {
- if (p_region == region)
+ if (p_region == region) {
return;
+ }
region = p_region;
_queue_update();
@@ -586,8 +602,9 @@ int Sprite3D::get_hframes() const {
}
Rect2 Sprite3D::get_item_rect() const {
- if (texture.is_null())
+ if (texture.is_null()) {
return Rect2(0, 0, 1, 1);
+ }
/*
if (texture.is_null())
return CanvasItem::get_item_rect();
@@ -603,11 +620,13 @@ Rect2 Sprite3D::get_item_rect() const {
}
Point2 ofs = get_offset();
- if (is_centered())
+ if (is_centered()) {
ofs -= s / 2;
+ }
- if (s == Size2(0, 0))
+ if (s == Size2(0, 0)) {
s = Size2(1, 1);
+ }
return Rect2(ofs, s);
}
@@ -685,11 +704,13 @@ void AnimatedSprite3D::_draw() {
}
Ref<Texture2D> texture = frames->get_frame(animation, frame);
- if (!texture.is_valid())
+ if (!texture.is_valid()) {
return; //no texuture no life
+ }
Vector2 tsize = texture->get_size();
- if (tsize.x == 0 || tsize.y == 0)
+ if (tsize.x == 0 || tsize.y == 0) {
return;
+ }
Size2i s = tsize;
Rect2 src_rect;
@@ -697,18 +718,21 @@ void AnimatedSprite3D::_draw() {
src_rect.size = s;
Point2 ofs = get_offset();
- if (is_centered())
+ if (is_centered()) {
ofs -= s / 2;
+ }
Rect2 dst_rect(ofs, s);
Rect2 final_rect;
Rect2 final_src_rect;
- if (!texture->get_rect_region(dst_rect, src_rect, final_rect, final_src_rect))
+ if (!texture->get_rect_region(dst_rect, src_rect, final_rect, final_src_rect)) {
return;
+ }
- if (final_rect.size.x == 0 || final_rect.size.y == 0)
+ if (final_rect.size.x == 0 || final_rect.size.y == 0) {
return;
+ }
Color color = _get_color_accum();
color.a *= get_opacity();
@@ -812,8 +836,9 @@ void AnimatedSprite3D::_draw() {
}
void AnimatedSprite3D::_validate_property(PropertyInfo &property) const {
- if (!frames.is_valid())
+ if (!frames.is_valid()) {
return;
+ }
if (property.name == "animation") {
property.hint = PROPERTY_HINT_ENUM;
List<StringName> names;
@@ -854,16 +879,20 @@ void AnimatedSprite3D::_validate_property(PropertyInfo &property) const {
void AnimatedSprite3D::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_INTERNAL_PROCESS: {
- if (frames.is_null())
+ if (frames.is_null()) {
return;
- if (!frames->has_animation(animation))
+ }
+ if (!frames->has_animation(animation)) {
return;
- if (frame < 0)
+ }
+ if (frame < 0) {
return;
+ }
float speed = frames->get_animation_speed(animation);
- if (speed == 0)
+ if (speed == 0) {
return; //do nothing
+ }
float remaining = get_process_delta_time();
@@ -895,11 +924,13 @@ void AnimatedSprite3D::_notification(int p_what) {
}
void AnimatedSprite3D::set_sprite_frames(const Ref<SpriteFrames> &p_frames) {
- if (frames.is_valid())
+ if (frames.is_valid()) {
frames->disconnect("changed", callable_mp(this, &AnimatedSprite3D::_res_changed));
+ }
frames = p_frames;
- if (frames.is_valid())
+ if (frames.is_valid()) {
frames->connect("changed", callable_mp(this, &AnimatedSprite3D::_res_changed));
+ }
if (!frames.is_valid()) {
frame = 0;
@@ -924,15 +955,18 @@ void AnimatedSprite3D::set_frame(int p_frame) {
if (frames->has_animation(animation)) {
int limit = frames->get_frame_count(animation);
- if (p_frame >= limit)
+ if (p_frame >= limit) {
p_frame = limit - 1;
+ }
}
- if (p_frame < 0)
+ if (p_frame < 0) {
p_frame = 0;
+ }
- if (frame == p_frame)
+ if (frame == p_frame) {
return;
+ }
frame = p_frame;
_reset_timeout();
@@ -951,18 +985,22 @@ Rect2 AnimatedSprite3D::get_item_rect() const {
}
Ref<Texture2D> t;
- if (animation)
+ if (animation) {
t = frames->get_frame(animation, frame);
- if (t.is_null())
+ }
+ if (t.is_null()) {
return Rect2(0, 0, 1, 1);
+ }
Size2i s = t->get_size();
Point2 ofs = get_offset();
- if (centered)
+ if (centered) {
ofs -= s / 2;
+ }
- if (s == Size2(0, 0))
+ if (s == Size2(0, 0)) {
s = Size2(1, 1);
+ }
return Rect2(ofs, s);
}
@@ -975,8 +1013,9 @@ void AnimatedSprite3D::_res_changed() {
}
void AnimatedSprite3D::_set_playing(bool p_playing) {
- if (playing == p_playing)
+ if (playing == p_playing) {
return;
+ }
playing = p_playing;
_reset_timeout();
set_process_internal(playing);
@@ -987,8 +1026,9 @@ bool AnimatedSprite3D::_is_playing() const {
}
void AnimatedSprite3D::play(const StringName &p_animation) {
- if (p_animation)
+ if (p_animation) {
set_animation(p_animation);
+ }
_set_playing(true);
}
@@ -1001,8 +1041,9 @@ bool AnimatedSprite3D::is_playing() const {
}
void AnimatedSprite3D::_reset_timeout() {
- if (!playing)
+ if (!playing) {
return;
+ }
if (frames.is_valid() && frames->has_animation(animation)) {
float speed = frames->get_animation_speed(animation);
@@ -1017,8 +1058,9 @@ void AnimatedSprite3D::_reset_timeout() {
}
void AnimatedSprite3D::set_animation(const StringName &p_animation) {
- if (animation == p_animation)
+ if (animation == p_animation) {
return;
+ }
animation = p_animation;
_reset_timeout();
diff --git a/scene/3d/vehicle_body_3d.cpp b/scene/3d/vehicle_body_3d.cpp
index 1e70b30d66..9c6b940b00 100644
--- a/scene/3d/vehicle_body_3d.cpp
+++ b/scene/3d/vehicle_body_3d.cpp
@@ -81,8 +81,9 @@ public:
void VehicleWheel3D::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE) {
VehicleBody3D *cb = Object::cast_to<VehicleBody3D>(get_parent());
- if (!cb)
+ if (!cb) {
return;
+ }
body = cb;
local_xform = get_transform();
cb->wheels.push_back(this);
@@ -93,8 +94,9 @@ void VehicleWheel3D::_notification(int p_what) {
}
if (p_what == NOTIFICATION_EXIT_TREE) {
VehicleBody3D *cb = Object::cast_to<VehicleBody3D>(get_parent());
- if (!cb)
+ if (!cb) {
return;
+ }
cb->wheels.erase(this);
body = nullptr;
}
@@ -434,8 +436,9 @@ real_t VehicleBody3D::_ray_cast(int p_idx, PhysicsDirectBodyState3D *s) {
wheel.m_raycastInfo.m_contactNormalWS = rr.normal;
wheel.m_raycastInfo.m_isInContact = true;
- if (rr.collider)
+ if (rr.collider) {
wheel.m_raycastInfo.m_groundObject = Object::cast_to<PhysicsBody3D>(rr.collider);
+ }
real_t hitDistance = param * raylen;
wheel.m_raycastInfo.m_suspensionLength = hitDistance - wheel.m_wheelRadius;
@@ -541,15 +544,17 @@ void VehicleBody3D::_resolve_single_bilateral(PhysicsDirectBodyState3D *s, const
Vector3 rel_pos1 = pos1 - s->get_transform().origin;
Vector3 rel_pos2;
- if (body2)
+ if (body2) {
rel_pos2 = pos2 - body2->get_global_transform().origin;
+ }
//this jacobian entry could be re-used for all iterations
Vector3 vel1 = s->get_linear_velocity() + (s->get_angular_velocity()).cross(rel_pos1); // * mPos);
Vector3 vel2;
- if (body2)
+ if (body2) {
vel2 = body2->get_linear_velocity() + body2->get_angular_velocity().cross(rel_pos2);
+ }
Vector3 vel = vel1 - vel2;
@@ -644,8 +649,9 @@ real_t VehicleBody3D::_calc_rolling_friction(btVehicleWheelContactPoint &contact
Vector3 rel_pos1 = contactPosWorld - contactPoint.m_s->get_transform().origin;
Vector3 rel_pos2;
- if (contactPoint.m_body1)
+ if (contactPoint.m_body1) {
rel_pos2 = contactPosWorld - contactPoint.m_body1->get_global_transform().origin;
+ }
real_t maxImpulse = contactPoint.m_maxImpulse;
@@ -670,8 +676,9 @@ static const real_t sideFrictionStiffness2 = real_t(1.0);
void VehicleBody3D::_update_friction(PhysicsDirectBodyState3D *s) {
//calculate the impulse, so that the wheels don't move sidewards
int numWheel = wheels.size();
- if (!numWheel)
+ if (!numWheel) {
return;
+ }
m_forwardWS.resize(numWheel);
m_axle.resize(numWheel);
@@ -885,8 +892,9 @@ void VehicleBody3D::set_engine_force(float p_engine_force) {
engine_force = p_engine_force;
for (int i = 0; i < wheels.size(); i++) {
VehicleWheel3D &wheelInfo = *wheels[i];
- if (wheelInfo.engine_traction)
+ if (wheelInfo.engine_traction) {
wheelInfo.m_engineForce = p_engine_force;
+ }
}
}
@@ -910,8 +918,9 @@ void VehicleBody3D::set_steering(float p_steering) {
m_steeringValue = p_steering;
for (int i = 0; i < wheels.size(); i++) {
VehicleWheel3D &wheelInfo = *wheels[i];
- if (wheelInfo.steers)
+ if (wheelInfo.steers) {
wheelInfo.m_steering = p_steering;
+ }
}
}
diff --git a/scene/3d/velocity_tracker_3d.cpp b/scene/3d/velocity_tracker_3d.cpp
index 216330939a..db10f3273b 100644
--- a/scene/3d/velocity_tracker_3d.cpp
+++ b/scene/3d/velocity_tracker_3d.cpp
@@ -88,8 +88,9 @@ Vector3 VelocityTracker3D::get_tracked_linear_velocity() const {
delta = double(diff) / 1000000.0;
}
- if (base_time + time_accum + delta > max_time)
+ if (base_time + time_accum + delta > max_time) {
break;
+ }
distance_accum += distance;
time_accum += delta;
diff --git a/scene/3d/visibility_notifier_3d.cpp b/scene/3d/visibility_notifier_3d.cpp
index afc7293b13..a64b0df1cc 100644
--- a/scene/3d/visibility_notifier_3d.cpp
+++ b/scene/3d/visibility_notifier_3d.cpp
@@ -60,8 +60,9 @@ void VisibilityNotifier3D::_exit_camera(Camera3D *p_camera) {
}
void VisibilityNotifier3D::set_aabb(const AABB &p_aabb) {
- if (aabb == p_aabb)
+ if (aabb == p_aabb) {
return;
+ }
aabb = p_aabb;
if (is_inside_world()) {
@@ -157,8 +158,9 @@ void VisibilityEnabler3D::_find_nodes(Node *p_node) {
for (int i = 0; i < p_node->get_child_count(); i++) {
Node *c = p_node->get_child(i);
- if (c->get_filename() != String())
+ if (c->get_filename() != String()) {
continue; //skip, instance
+ }
_find_nodes(c);
}
@@ -166,24 +168,28 @@ void VisibilityEnabler3D::_find_nodes(Node *p_node) {
void VisibilityEnabler3D::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE) {
- if (Engine::get_singleton()->is_editor_hint())
+ if (Engine::get_singleton()->is_editor_hint()) {
return;
+ }
Node *from = this;
//find where current scene starts
- while (from->get_parent() && from->get_filename() == String())
+ while (from->get_parent() && from->get_filename() == String()) {
from = from->get_parent();
+ }
_find_nodes(from);
}
if (p_what == NOTIFICATION_EXIT_TREE) {
- if (Engine::get_singleton()->is_editor_hint())
+ if (Engine::get_singleton()->is_editor_hint()) {
return;
+ }
for (Map<Node *, Variant>::Element *E = nodes.front(); E; E = E->next()) {
- if (!visible)
+ if (!visible) {
_change_node_state(E->key(), true);
+ }
E->key()->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &VisibilityEnabler3D::_node_removed));
}
@@ -196,9 +202,9 @@ void VisibilityEnabler3D::_change_node_state(Node *p_node, bool p_enabled) {
if (enabler[ENABLER_FREEZE_BODIES]) {
RigidBody3D *rb = Object::cast_to<RigidBody3D>(p_node);
- if (rb)
-
+ if (rb) {
rb->set_sleeping(!p_enabled);
+ }
}
if (enabler[ENABLER_PAUSE_ANIMATIONS]) {
@@ -211,8 +217,9 @@ void VisibilityEnabler3D::_change_node_state(Node *p_node, bool p_enabled) {
}
void VisibilityEnabler3D::_node_removed(Node *p_node) {
- if (!visible)
+ if (!visible) {
_change_node_state(p_node, true);
+ }
nodes.erase(p_node);
}
@@ -239,8 +246,9 @@ bool VisibilityEnabler3D::is_enabler_enabled(Enabler p_enabler) const {
}
VisibilityEnabler3D::VisibilityEnabler3D() {
- for (int i = 0; i < ENABLER_MAX; i++)
+ for (int i = 0; i < ENABLER_MAX; i++) {
enabler[i] = true;
+ }
visible = false;
}
diff --git a/scene/3d/visual_instance_3d.cpp b/scene/3d/visual_instance_3d.cpp
index cf67ba71c9..a1c498e8ab 100644
--- a/scene/3d/visual_instance_3d.cpp
+++ b/scene/3d/visual_instance_3d.cpp
@@ -39,8 +39,9 @@ AABB VisualInstance3D::get_transformed_aabb() const {
}
void VisualInstance3D::_update_visibility() {
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
_change_notify("visible");
RS::get_singleton()->instance_set_visible(get_instance(), is_visible_in_tree());
diff --git a/scene/3d/voxelizer.cpp b/scene/3d/voxelizer.cpp
index 886ec89c28..9fc3feb49a 100644
--- a/scene/3d/voxelizer.cpp
+++ b/scene/3d/voxelizer.cpp
@@ -151,8 +151,9 @@ void Voxelizer::_plot_face(int p_idx, int p_level, int p_x, int p_y, int p_z, co
Vector2 uv;
Vector3 lnormal;
get_uv_and_normal(intersection, p_vtx, p_uv, p_normal, uv, lnormal);
- if (lnormal == Vector3()) //just in case normal as nor provided
+ if (lnormal == Vector3()) { //just in case normal as nor provided
lnormal = normal;
+ }
int uv_x = CLAMP(int(Math::fposmod(uv.x, 1.0f) * bake_texture_size), 0, bake_texture_size - 1);
int uv_y = CLAMP(int(Math::fposmod(uv.y, 1.0f) * bake_texture_size), 0, bake_texture_size - 1);
@@ -182,8 +183,9 @@ void Voxelizer::_plot_face(int p_idx, int p_level, int p_x, int p_y, int p_z, co
Vector3 lnormal;
Vector2 uv;
get_uv_and_normal(inters, p_vtx, p_uv, p_normal, uv, normal);
- if (lnormal == Vector3()) //just in case normal as nor provided
+ if (lnormal == Vector3()) { //just in case normal as nor provided
lnormal = normal;
+ }
int uv_x = CLAMP(Math::fposmod(uv.x, 1.0f) * bake_texture_size, 0, bake_texture_size - 1);
int uv_y = CLAMP(Math::fposmod(uv.y, 1.0f) * bake_texture_size, 0, bake_texture_size - 1);
@@ -256,8 +258,9 @@ void Voxelizer::_plot_face(int p_idx, int p_level, int p_x, int p_y, int p_z, co
nz += half;
}
//make sure to not plot beyond limits
- if (nx < 0 || nx >= axis_cell_size[0] || ny < 0 || ny >= axis_cell_size[1] || nz < 0 || nz >= axis_cell_size[2])
+ if (nx < 0 || nx >= axis_cell_size[0] || ny < 0 || ny >= axis_cell_size[1] || nz < 0 || nz >= axis_cell_size[2]) {
continue;
+ }
{
AABB test_aabb = aabb;
@@ -377,8 +380,9 @@ Voxelizer::MaterialCache Voxelizer::_get_material_cache(Ref<Material> p_material
void Voxelizer::plot_mesh(const Transform &p_xform, Ref<Mesh> &p_mesh, const Vector<Ref<Material>> &p_materials, const Ref<Material> &p_override_material) {
for (int i = 0; i < p_mesh->get_surface_count(); i++) {
- if (p_mesh->surface_get_primitive_type(i) != Mesh::PRIMITIVE_TRIANGLES)
+ if (p_mesh->surface_get_primitive_type(i) != Mesh::PRIMITIVE_TRIANGLES) {
continue; //only triangles
+ }
Ref<Material> src_material;
@@ -435,8 +439,9 @@ void Voxelizer::plot_mesh(const Transform &p_xform, Ref<Mesh> &p_mesh, const Vec
}
//test against original bounds
- if (!Geometry::triangle_box_overlap(original_bounds.position + original_bounds.size * 0.5, original_bounds.size * 0.5, vtxs))
+ if (!Geometry::triangle_box_overlap(original_bounds.position + original_bounds.size * 0.5, original_bounds.size * 0.5, vtxs)) {
continue;
+ }
//plot
_plot_face(0, 0, 0, 0, 0, vtxs, normal, uvs, material, po2_bounds);
}
@@ -466,8 +471,9 @@ void Voxelizer::plot_mesh(const Transform &p_xform, Ref<Mesh> &p_mesh, const Vec
}
//test against original bounds
- if (!Geometry::triangle_box_overlap(original_bounds.position + original_bounds.size * 0.5, original_bounds.size * 0.5, vtxs))
+ if (!Geometry::triangle_box_overlap(original_bounds.position + original_bounds.size * 0.5, original_bounds.size * 0.5, vtxs)) {
continue;
+ }
//plot face
_plot_face(0, 0, 0, 0, 0, vtxs, normal, uvs, material, po2_bounds);
}
@@ -597,8 +603,9 @@ void Voxelizer::_fixup_plot(int p_idx, int p_level) {
for (int i = 0; i < 8; i++) {
uint32_t child = bake_cells[p_idx].children[i];
- if (child == CHILD_EMPTY)
+ if (child == CHILD_EMPTY) {
continue;
+ }
_fixup_plot(child, p_level + 1);
alpha_average += bake_cells[child].alpha;
@@ -625,8 +632,9 @@ void Voxelizer::begin_bake(int p_subdiv, const AABB &p_bounds) {
leaf_voxel_count = 0;
for (int i = 0; i < 3; i++) {
- if (i == longest_axis)
+ if (i == longest_axis) {
continue;
+ }
axis_cell_size[i] = axis_cell_size[longest_axis];
float axis_size = po2_bounds.size[longest_axis];
@@ -798,8 +806,9 @@ static void edt(float *f, int stride, int n) {
k = 0;
for (int q = 0; q <= n - 1; q++) {
- while (z[k + 1] < q)
+ while (z[k + 1] < q) {
k++;
+ }
d[q] = square(q - v[k]) + f[v[k] * stride];
}
@@ -898,18 +907,22 @@ void Voxelizer::_debug_mesh(int p_idx, int p_level, const AABB &p_aabb, Ref<Mult
for (int i = 0; i < 8; i++) {
uint32_t child = bake_cells[p_idx].children[i];
- if (child == CHILD_EMPTY || child >= (uint32_t)max_original_cells)
+ if (child == CHILD_EMPTY || child >= (uint32_t)max_original_cells) {
continue;
+ }
AABB aabb = p_aabb;
aabb.size *= 0.5;
- if (i & 1)
+ if (i & 1) {
aabb.position.x += aabb.size.x;
- if (i & 2)
+ }
+ if (i & 2) {
aabb.position.y += aabb.size.y;
- if (i & 4)
+ }
+ if (i & 4) {
aabb.position.z += aabb.size.z;
+ }
_debug_mesh(bake_cells[p_idx].children[i], p_level + 1, aabb, p_multimesh, idx);
}
@@ -948,10 +961,11 @@ Ref<MultiMesh> Voxelizer::create_debug_multimesh() {
v[2] = v[1] * (1 - 2 * (j & 1));
for (int k = 0; k < 3; k++) {
- if (i < 3)
+ if (i < 3) {
face_points[j][(i + k) % 3] = v[k];
- else
+ } else {
face_points[3 - j][(i + k) % 3] = -v[k];
+ }
}
}
diff --git a/scene/3d/world_environment.cpp b/scene/3d/world_environment.cpp
index ac314e005b..24071f31f3 100644
--- a/scene/3d/world_environment.cpp
+++ b/scene/3d/world_environment.cpp
@@ -113,8 +113,9 @@ String WorldEnvironment::get_configuration_warning() const {
return TTR("WorldEnvironment requires its \"Environment\" property to contain an Environment to have a visible effect.");
}
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return String();
+ }
List<Node *> nodes;
get_tree()->get_nodes_in_group("_world_environment_" + itos(get_viewport()->find_world_3d()->get_scenario().get_id()), &nodes);
diff --git a/scene/3d/xr_nodes.cpp b/scene/3d/xr_nodes.cpp
index 1d01a8b5b4..f9f6b6905c 100644
--- a/scene/3d/xr_nodes.cpp
+++ b/scene/3d/xr_nodes.cpp
@@ -55,8 +55,9 @@ void XRCamera3D::_notification(int p_what) {
};
String XRCamera3D::get_configuration_warning() const {
- if (!is_visible() || !is_inside_tree())
+ if (!is_visible() || !is_inside_tree()) {
return String();
+ }
// must be child node of XROrigin3D!
XROrigin3D *origin = Object::cast_to<XROrigin3D>(get_parent());
@@ -364,8 +365,9 @@ XRPositionalTracker::TrackerHand XRController3D::get_hand() const {
};
String XRController3D::get_configuration_warning() const {
- if (!is_visible() || !is_inside_tree())
+ if (!is_visible() || !is_inside_tree()) {
return String();
+ }
// must be child node of XROrigin!
XROrigin3D *origin = Object::cast_to<XROrigin3D>(get_parent());
@@ -490,8 +492,9 @@ bool XRAnchor3D::get_is_active() const {
};
String XRAnchor3D::get_configuration_warning() const {
- if (!is_visible() || !is_inside_tree())
+ if (!is_visible() || !is_inside_tree()) {
return String();
+ }
// must be child node of XROrigin3D!
XROrigin3D *origin = Object::cast_to<XROrigin3D>(get_parent());
@@ -531,11 +534,13 @@ XRAnchor3D::~XRAnchor3D(){
////////////////////////////////////////////////////////////////////////////////////////////////////
String XROrigin3D::get_configuration_warning() const {
- if (!is_visible() || !is_inside_tree())
+ if (!is_visible() || !is_inside_tree()) {
return String();
+ }
- if (tracked_camera == nullptr)
+ if (tracked_camera == nullptr) {
return TTR("XROrigin3D requires an XRCamera3D child node.");
+ }
return String();
};
diff --git a/scene/animation/animation_blend_space_2d.cpp b/scene/animation/animation_blend_space_2d.cpp
index 436ff553ec..003a4fad90 100644
--- a/scene/animation/animation_blend_space_2d.cpp
+++ b/scene/animation/animation_blend_space_2d.cpp
@@ -171,8 +171,9 @@ bool AnimationNodeBlendSpace2D::has_triangle(int p_x, int p_y, int p_z) const {
break;
}
}
- if (all_equal)
+ if (all_equal) {
return true;
+ }
}
return false;
@@ -290,8 +291,9 @@ void AnimationNodeBlendSpace2D::_add_blend_point(int p_index, const Ref<Animatio
}
void AnimationNodeBlendSpace2D::_set_triangles(const Vector<int> &p_triangles) {
- if (auto_triangles)
+ if (auto_triangles) {
return;
+ }
ERR_FAIL_COND(p_triangles.size() % 3 != 0);
for (int i = 0; i < p_triangles.size(); i += 3) {
add_triangle(p_triangles[i + 0], p_triangles[i + 1], p_triangles[i + 2]);
@@ -300,8 +302,9 @@ void AnimationNodeBlendSpace2D::_set_triangles(const Vector<int> &p_triangles) {
Vector<int> AnimationNodeBlendSpace2D::_get_triangles() const {
Vector<int> t;
- if (auto_triangles && trianges_dirty)
+ if (auto_triangles && trianges_dirty) {
return t;
+ }
t.resize(triangles.size() * 3);
for (int i = 0; i < triangles.size(); i++) {
@@ -322,8 +325,9 @@ void AnimationNodeBlendSpace2D::_queue_auto_triangles() {
}
void AnimationNodeBlendSpace2D::_update_triangles() {
- if (!auto_triangles || !trianges_dirty)
+ if (!auto_triangles || !trianges_dirty) {
return;
+ }
trianges_dirty = false;
triangles.clear();
@@ -349,8 +353,9 @@ void AnimationNodeBlendSpace2D::_update_triangles() {
Vector2 AnimationNodeBlendSpace2D::get_closest_point(const Vector2 &p_point) {
_update_triangles();
- if (triangles.size() == 0)
+ if (triangles.size() == 0) {
return Vector2();
+ }
Vector2 best_point;
bool first = true;
@@ -435,8 +440,9 @@ float AnimationNodeBlendSpace2D::process(float p_time, bool p_seek) {
float mind = 0; //time of min distance point
if (blend_mode == BLEND_MODE_INTERPOLATED) {
- if (triangles.size() == 0)
+ if (triangles.size() == 0) {
return 0;
+ }
Vector2 best_point;
bool first = true;
diff --git a/scene/animation/animation_blend_tree.cpp b/scene/animation/animation_blend_tree.cpp
index 2fa9aaa4da..56995c0c13 100644
--- a/scene/animation/animation_blend_tree.cpp
+++ b/scene/animation/animation_blend_tree.cpp
@@ -235,8 +235,9 @@ float AnimationNodeOneShot::process(float p_time, bool p_seek) {
bool os_seek = p_seek;
- if (p_seek)
+ if (p_seek) {
time = p_time;
+ }
bool do_start = !prev_active;
if (do_start) {
@@ -248,18 +249,21 @@ float AnimationNodeOneShot::process(float p_time, bool p_seek) {
float blend;
if (time < fade_in) {
- if (fade_in > 0)
+ if (fade_in > 0) {
blend = time / fade_in;
- else
+ } else {
blend = 0; //wtf
+ }
} else if (!do_start && remaining < fade_out) {
- if (fade_out)
+ if (fade_out) {
blend = (remaining / fade_out);
- else
+ } else {
blend = 1.0;
- } else
+ }
+ } else {
blend = 1.0;
+ }
float main_rem;
if (mix == MIX_MODE_ADD) {
@@ -730,10 +734,11 @@ float AnimationNodeTransition::process(float p_time, bool p_seek) {
rem = blend_input(current, p_time, p_seek, 1.0, FILTER_IGNORE, false);
- if (p_seek)
+ if (p_seek) {
time = p_time;
- else
+ } else {
time += p_time;
+ }
if (inputs[current].auto_advance && rem <= xfade) {
set_parameter(this->current, (current + 1) % enabled_inputs);
diff --git a/scene/animation/animation_cache.cpp b/scene/animation/animation_cache.cpp
index 1eea73fab8..abb2cf1b65 100644
--- a/scene/animation/animation_cache.cpp
+++ b/scene/animation/animation_cache.cpp
@@ -38,8 +38,9 @@ void AnimationCache::_node_exit_tree(Node *p_node) {
connected_nodes.erase(p_node);
for (int i = 0; i < path_cache.size(); i++) {
- if (path_cache[i].node != p_node)
+ if (path_cache[i].node != p_node) {
continue;
+ }
path_cache.write[i].valid = false; //invalidate path cache
}
@@ -167,14 +168,16 @@ void AnimationCache::_update_cache() {
}
void AnimationCache::set_track_transform(int p_idx, const Transform &p_transform) {
- if (cache_dirty)
+ if (cache_dirty) {
_update_cache();
+ }
ERR_FAIL_COND(!cache_valid);
ERR_FAIL_INDEX(p_idx, path_cache.size());
Path &p = path_cache.write[p_idx];
- if (!p.valid)
+ if (!p.valid) {
return;
+ }
ERR_FAIL_COND(!p.node);
ERR_FAIL_COND(!p.spatial);
@@ -187,36 +190,41 @@ void AnimationCache::set_track_transform(int p_idx, const Transform &p_transform
}
void AnimationCache::set_track_value(int p_idx, const Variant &p_value) {
- if (cache_dirty)
+ if (cache_dirty) {
_update_cache();
+ }
ERR_FAIL_COND(!cache_valid);
ERR_FAIL_INDEX(p_idx, path_cache.size());
Path &p = path_cache.write[p_idx];
- if (!p.valid)
+ if (!p.valid) {
return;
+ }
ERR_FAIL_COND(!p.object);
p.object->set_indexed(p.subpath, p_value);
}
void AnimationCache::call_track(int p_idx, const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
- if (cache_dirty)
+ if (cache_dirty) {
_update_cache();
+ }
ERR_FAIL_COND(!cache_valid);
ERR_FAIL_INDEX(p_idx, path_cache.size());
Path &p = path_cache.write[p_idx];
- if (!p.valid)
+ if (!p.valid) {
return;
+ }
ERR_FAIL_COND(!p.object);
p.object->call(p_method, p_args, p_argcount, r_error);
}
void AnimationCache::set_all(float p_time, float p_delta) {
- if (cache_dirty)
+ if (cache_dirty) {
_update_cache();
+ }
ERR_FAIL_COND(!cache_valid);
@@ -280,13 +288,15 @@ void AnimationCache::set_all(float p_time, float p_delta) {
void AnimationCache::set_animation(const Ref<Animation> &p_animation) {
_clear_cache();
- if (animation.is_valid())
+ if (animation.is_valid()) {
animation->disconnect("changed", callable_mp(this, &AnimationCache::_animation_changed));
+ }
animation = p_animation;
- if (animation.is_valid())
+ if (animation.is_valid()) {
animation->connect("changed", callable_mp(this, &AnimationCache::_animation_changed));
+ }
}
void AnimationCache::_bind_methods() {
diff --git a/scene/animation/animation_node_state_machine.cpp b/scene/animation/animation_node_state_machine.cpp
index 7c4f84b373..17ce05f130 100644
--- a/scene/animation/animation_node_state_machine.cpp
+++ b/scene/animation/animation_node_state_machine.cpp
@@ -186,8 +186,9 @@ bool AnimationNodeStateMachinePlayback::_travel(AnimationNodeStateMachine *p_sta
path.clear(); //a new one will be needed
- if (current == p_travel)
+ if (current == p_travel) {
return true; //nothing to do
+ }
loops_current = 0; // reset loops, so fade does not happen immediately
@@ -698,16 +699,18 @@ void AnimationNodeStateMachine::get_node_list(List<StringName> *r_nodes) const {
bool AnimationNodeStateMachine::has_transition(const StringName &p_from, const StringName &p_to) const {
for (int i = 0; i < transitions.size(); i++) {
- if (transitions[i].from == p_from && transitions[i].to == p_to)
+ if (transitions[i].from == p_from && transitions[i].to == p_to) {
return true;
+ }
}
return false;
}
int AnimationNodeStateMachine::find_transition(const StringName &p_from, const StringName &p_to) const {
for (int i = 0; i < transitions.size(); i++) {
- if (transitions[i].from == p_from && transitions[i].to == p_to)
+ if (transitions[i].from == p_from && transitions[i].to == p_to) {
return i;
+ }
}
return -1;
}
diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp
index b8d7cbc823..4e56f1acf0 100644
--- a/scene/animation/animation_player.cpp
+++ b/scene/animation/animation_player.cpp
@@ -83,8 +83,9 @@ bool AnimationPlayer::_set(const StringName &p_name, const Variant &p_value) {
set_blend_time(from, to, time);
}
- } else
+ } else {
return false;
+ }
return true;
}
@@ -119,8 +120,9 @@ bool AnimationPlayer::_get(const StringName &p_name, Variant &r_ret) const {
}
r_ret = array;
- } else
+ } else {
return false;
+ }
return true;
}
@@ -136,8 +138,9 @@ void AnimationPlayer::_validate_property(PropertyInfo &property) const {
names.push_front("[stop]");
String hint;
for (List<String>::Element *E = names.front(); E; E = E->next()) {
- if (E != names.front())
+ if (E != names.front()) {
hint += ",";
+ }
hint += E->get();
}
@@ -150,8 +153,9 @@ void AnimationPlayer::_get_property_list(List<PropertyInfo> *p_list) const {
for (Map<StringName, AnimationData>::Element *E = animation_set.front(); E; E = E->next()) {
anim_names.push_back(PropertyInfo(Variant::OBJECT, "anims/" + String(E->key()), PROPERTY_HINT_RESOURCE_TYPE, "Animation", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_DO_NOT_SHARE_ON_DUPLICATE));
- if (E->get().next != StringName())
+ if (E->get().next != StringName()) {
anim_names.push_back(PropertyInfo(Variant::STRING, "next/" + String(E->key()), PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
+ }
}
anim_names.sort();
@@ -186,18 +190,22 @@ void AnimationPlayer::_notification(int p_what) {
}
} break;
case NOTIFICATION_INTERNAL_PROCESS: {
- if (animation_process_mode == ANIMATION_PROCESS_PHYSICS)
+ if (animation_process_mode == ANIMATION_PROCESS_PHYSICS) {
break;
+ }
- if (processing)
+ if (processing) {
_animation_process(get_process_delta_time());
+ }
} break;
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
- if (animation_process_mode == ANIMATION_PROCESS_IDLE)
+ if (animation_process_mode == ANIMATION_PROCESS_IDLE) {
break;
+ }
- if (processing)
+ if (processing) {
_animation_process(get_physics_process_delta_time());
+ }
} break;
case NOTIFICATION_EXIT_TREE: {
clear_caches();
@@ -207,8 +215,9 @@ void AnimationPlayer::_notification(int p_what) {
void AnimationPlayer::_ensure_node_caches(AnimationData *p_anim) {
// Already cached?
- if (p_anim->node_cache.size() == p_anim->animation->get_track_count())
+ if (p_anim->node_cache.size() == p_anim->animation->get_track_count()) {
return;
+ }
Node *parent = get_node(root);
@@ -236,16 +245,18 @@ void AnimationPlayer::_ensure_node_caches(AnimationData *p_anim) {
}
{
- if (!child->is_connected("tree_exiting", callable_mp(this, &AnimationPlayer::_node_removed)))
+ if (!child->is_connected("tree_exiting", callable_mp(this, &AnimationPlayer::_node_removed))) {
child->connect("tree_exiting", callable_mp(this, &AnimationPlayer::_node_removed), make_binds(child), CONNECT_ONESHOT);
+ }
}
TrackNodeCacheKey key;
key.id = id;
key.bone_idx = bone_idx;
- if (!node_cache_map.has(key))
+ if (!node_cache_map.has(key)) {
node_cache_map[key] = TrackNodeCache();
+ }
p_anim->node_cache.write[i] = &node_cache_map[key];
p_anim->node_cache[i]->path = a->track_get_path(i);
@@ -285,12 +296,13 @@ void AnimationPlayer::_ensure_node_caches(AnimationData *p_anim) {
pa.special = SP_NONE;
pa.owner = p_anim->node_cache[i];
if (false && p_anim->node_cache[i]->node_2d) {
- if (leftover_path.size() == 1 && leftover_path[0] == SceneStringNames::get_singleton()->transform_pos)
+ if (leftover_path.size() == 1 && leftover_path[0] == SceneStringNames::get_singleton()->transform_pos) {
pa.special = SP_NODE2D_POS;
- else if (leftover_path.size() == 1 && leftover_path[0] == SceneStringNames::get_singleton()->transform_rot)
+ } else if (leftover_path.size() == 1 && leftover_path[0] == SceneStringNames::get_singleton()->transform_rot) {
pa.special = SP_NODE2D_ROT;
- else if (leftover_path.size() == 1 && leftover_path[0] == SceneStringNames::get_singleton()->transform_scale)
+ } else if (leftover_path.size() == 1 && leftover_path[0] == SceneStringNames::get_singleton()->transform_scale) {
pa.special = SP_NODE2D_SCALE;
+ }
}
p_anim->node_cache[i]->property_anim[a->track_get_path(i).get_concatenated_subnames()] = pa;
}
@@ -325,19 +337,23 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, float
TrackNodeCache *nc = p_anim->node_cache[i];
- if (!nc)
+ if (!nc) {
continue; // no node cache for this track, skip it
+ }
- if (!a->track_is_enabled(i))
+ if (!a->track_is_enabled(i)) {
continue; // do nothing if the track is disabled
+ }
- if (a->track_get_key_count(i) == 0)
+ if (a->track_get_key_count(i) == 0) {
continue; // do nothing if track is empty
+ }
switch (a->track_get_type(i)) {
case Animation::TYPE_TRANSFORM: {
- if (!nc->spatial)
+ if (!nc->spatial) {
continue;
+ }
Vector3 loc;
Quat rot;
@@ -346,8 +362,9 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, float
Error err = a->transform_track_interpolate(i, p_time, &loc, &rot, &scale);
//ERR_CONTINUE(err!=OK); //used for testing, should be removed
- if (err != OK)
+ if (err != OK) {
continue;
+ }
if (nc->accum_pass != accum_pass) {
ERR_CONTINUE(cache_update_size >= NODE_CACHE_UPDATE_MAX);
@@ -365,8 +382,9 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, float
} break;
case Animation::TYPE_VALUE: {
- if (!nc->node)
+ if (!nc->node) {
continue;
+ }
//StringName property=a->track_get_path(i).get_property();
@@ -383,8 +401,9 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, float
}
int key_count = a->track_get_key_count(i);
- if (key_count == 0)
+ if (key_count == 0) {
continue; //eeh not worth it
+ }
float first_key_time = a->track_get_key_time(i, 0);
float transition = 1.0;
@@ -392,8 +411,9 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, float
if (first_key_time == 0.0) {
//ignore, use for transition
- if (key_count == 1)
+ if (key_count == 1) {
continue; //with one key we can't do anything
+ }
transition = a->track_get_key_transition(i, 0);
first_key_time = a->track_get_key_time(i, 1);
first_key = 1;
@@ -422,8 +442,9 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, float
Variant value = a->value_track_interpolate(i, p_time);
- if (value == Variant())
+ if (value == Variant()) {
continue;
+ }
//thanks to trigger mode, this should be solved now..
/*
@@ -488,13 +509,15 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, float
} break;
case Animation::TYPE_METHOD: {
- if (!nc->node)
+ if (!nc->node) {
continue;
+ }
if (p_delta == 0) {
continue;
}
- if (!p_is_current)
+ if (!p_is_current) {
break;
+ }
List<int> indices;
@@ -537,8 +560,9 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, float
} break;
case Animation::TYPE_BEZIER: {
- if (!nc->node)
+ if (!nc->node) {
continue;
+ }
Map<StringName, TrackNodeCache::BezierAnim>::Element *E = nc->bezier_anim.find(a->track_get_path(i).get_concatenated_subnames());
ERR_CONTINUE(!E); //should it continue, or create a new one?
@@ -557,8 +581,9 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, float
} break;
case Animation::TYPE_AUDIO: {
- if (!nc->node)
+ if (!nc->node) {
continue;
+ }
if (p_delta == 0) {
continue;
}
@@ -566,8 +591,9 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, float
if (p_seeked) {
//find whathever should be playing
int idx = a->track_find_key(i, p_time);
- if (idx < 0)
+ if (idx < 0) {
continue;
+ }
Ref<AudioStream> stream = a->audio_track_get_key_stream(i, idx);
if (!stream.is_valid()) {
@@ -658,20 +684,23 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, float
} break;
case Animation::TYPE_ANIMATION: {
AnimationPlayer *player = Object::cast_to<AnimationPlayer>(nc->node);
- if (!player)
+ if (!player) {
continue;
+ }
if (p_delta == 0 || p_seeked) {
//seek
int idx = a->track_find_key(i, p_time);
- if (idx < 0)
+ if (idx < 0) {
continue;
+ }
float pos = a->track_get_key_time(i, idx);
StringName anim_name = a->animation_track_get_key_animation(i, idx);
- if (String(anim_name) == "[stop]" || !player->has_animation(anim_name))
+ if (String(anim_name) == "[stop]" || !player->has_animation(anim_name)) {
continue;
+ }
Ref<Animation> anim = player->get_animation(anim_name);
@@ -727,10 +756,11 @@ void AnimationPlayer::_animation_process_data(PlaybackData &cd, float p_delta, f
bool loop = cd.from->animation->has_loop();
if (!loop) {
- if (next_pos < 0)
+ if (next_pos < 0) {
next_pos = 0;
- else if (next_pos > len)
+ } else if (next_pos > len) {
next_pos = len;
+ }
// fix delta
delta = next_pos - cd.pos;
@@ -887,14 +917,16 @@ void AnimationPlayer::_animation_process(float p_delta) {
play(queued.front()->get());
String new_name = playback.assigned;
queued.pop_front();
- if (end_notify)
+ if (end_notify) {
emit_signal(SceneStringNames::get_singleton()->animation_changed, old, new_name);
+ }
} else {
//stop();
playing = false;
_set_process(false);
- if (end_notify)
+ if (end_notify) {
emit_signal(SceneStringNames::get_singleton()->animation_finished, playback.assigned);
+ }
}
end_reached = false;
}
@@ -988,8 +1020,9 @@ void AnimationPlayer::rename_animation(const StringName &p_name, const StringNam
to_insert.erase(to_insert.front());
}
- if (autoplay == p_name)
+ if (autoplay == p_name) {
autoplay = p_new_name;
+ }
clear_caches();
_change_notify();
@@ -1027,10 +1060,11 @@ void AnimationPlayer::set_blend_time(const StringName &p_animation1, const Strin
BlendKey bk;
bk.from = p_animation1;
bk.to = p_animation2;
- if (p_time == 0)
+ if (p_time == 0) {
blend_times.erase(bk);
- else
+ } else {
blend_times[bk] = p_time;
+ }
}
float AnimationPlayer::get_blend_time(const StringName &p_animation1, const StringName &p_animation2) const {
@@ -1038,17 +1072,19 @@ float AnimationPlayer::get_blend_time(const StringName &p_animation1, const Stri
bk.from = p_animation1;
bk.to = p_animation2;
- if (blend_times.has(bk))
+ if (blend_times.has(bk)) {
return blend_times[bk];
- else
+ } else {
return 0;
+ }
}
void AnimationPlayer::queue(const StringName &p_name) {
- if (!is_playing())
+ if (!is_playing()) {
play(p_name);
- else
+ } else {
queued.push_back(p_name);
+ }
}
Vector<String> AnimationPlayer::get_queue() {
@@ -1071,8 +1107,9 @@ void AnimationPlayer::play_backwards(const StringName &p_name, float p_custom_bl
void AnimationPlayer::play(const StringName &p_name, float p_custom_blend, float p_custom_scale, bool p_from_end) {
StringName name = p_name;
- if (String(name) == "")
+ if (String(name) == "") {
name = playback.assigned;
+ }
ERR_FAIL_COND_MSG(!animation_set.has(name), "Animation not found: " + name + ".");
@@ -1103,8 +1140,9 @@ void AnimationPlayer::play(const StringName &p_name, float p_custom_blend, float
}
}
- if (p_custom_blend < 0 && blend_time == 0 && default_blend_time)
+ if (p_custom_blend < 0 && blend_time == 0 && default_blend_time) {
blend_time = default_blend_time;
+ }
if (blend_time > 0) {
Blend b;
b.data = c.current;
@@ -1136,15 +1174,17 @@ void AnimationPlayer::play(const StringName &p_name, float p_custom_blend, float
c.seeked = false;
c.started = true;
- if (!end_reached)
+ if (!end_reached) {
queued.clear();
+ }
_set_process(true); // always process when starting an animation
playing = true;
emit_signal(SceneStringNames::get_singleton()->animation_started, c.assigned);
- if (is_inside_tree() && Engine::get_singleton()->is_editor_hint())
+ if (is_inside_tree() && Engine::get_singleton()->is_editor_hint()) {
return; // no next in this case
+ }
StringName next = animation_get_next(p_name);
if (next != StringName() && animation_set.has(next)) {
@@ -1240,8 +1280,9 @@ void AnimationPlayer::seek_delta(float p_time, float p_delta) {
}
playback.current.pos = p_time - p_delta;
- if (speed_scale != 0.0)
+ if (speed_scale != 0.0) {
p_delta /= speed_scale;
+ }
_animation_process(p_delta);
//playback.current.pos=p_time;
}
@@ -1275,8 +1316,9 @@ void AnimationPlayer::_stop_playing_caches() {
}
if (E->get()->node && E->get()->animation_playing) {
AnimationPlayer *player = Object::cast_to<AnimationPlayer>(E->get()->node);
- if (!player)
+ if (!player) {
continue;
+ }
player->stop();
}
}
@@ -1303,8 +1345,9 @@ void AnimationPlayer::clear_caches() {
}
void AnimationPlayer::set_active(bool p_active) {
- if (active == p_active)
+ if (active == p_active) {
return;
+ }
active = p_active;
_set_process(processing, true);
@@ -1316,16 +1359,18 @@ bool AnimationPlayer::is_active() const {
StringName AnimationPlayer::find_animation(const Ref<Animation> &p_animation) const {
for (Map<StringName, AnimationData>::Element *E = animation_set.front(); E; E = E->next()) {
- if (E->get().animation == p_animation)
+ if (E->get().animation == p_animation) {
return E->key();
+ }
}
return "";
}
void AnimationPlayer::set_autoplay(const String &p_name) {
- if (is_inside_tree() && !Engine::get_singleton()->is_editor_hint())
+ if (is_inside_tree() && !Engine::get_singleton()->is_editor_hint()) {
WARN_PRINT("Setting autoplay after the node has been added to the scene has no effect.");
+ }
autoplay = p_name;
}
@@ -1335,15 +1380,18 @@ String AnimationPlayer::get_autoplay() const {
}
void AnimationPlayer::set_animation_process_mode(AnimationProcessMode p_mode) {
- if (animation_process_mode == p_mode)
+ if (animation_process_mode == p_mode) {
return;
+ }
bool pr = processing;
- if (pr)
+ if (pr) {
_set_process(false);
+ }
animation_process_mode = p_mode;
- if (pr)
+ if (pr) {
_set_process(true);
+ }
}
AnimationPlayer::AnimationProcessMode AnimationPlayer::get_animation_process_mode() const {
@@ -1359,8 +1407,9 @@ AnimationPlayer::AnimationMethodCallMode AnimationPlayer::get_method_call_mode()
}
void AnimationPlayer::_set_process(bool p_process, bool p_force) {
- if (processing == p_process && !p_force)
+ if (processing == p_process && !p_force) {
return;
+ }
switch (animation_process_mode) {
case ANIMATION_PROCESS_PHYSICS:
@@ -1382,8 +1431,9 @@ void AnimationPlayer::animation_set_next(const StringName &p_animation, const St
}
StringName AnimationPlayer::animation_get_next(const StringName &p_animation) const {
- if (!animation_set.has(p_animation))
+ if (!animation_set.has(p_animation)) {
return StringName();
+ }
return animation_set[p_animation].next;
}
@@ -1424,8 +1474,9 @@ void AnimationPlayer::get_argument_options(const StringName &p_function, int p_i
#ifdef TOOLS_ENABLED
AnimatedValuesBackup AnimationPlayer::backup_animated_values() {
- if (!playback.current.from)
+ if (!playback.current.from) {
return AnimatedValuesBackup();
+ }
_ensure_node_caches(playback.current.from);
@@ -1433,12 +1484,14 @@ AnimatedValuesBackup AnimationPlayer::backup_animated_values() {
for (int i = 0; i < playback.current.from->node_cache.size(); i++) {
TrackNodeCache *nc = playback.current.from->node_cache[i];
- if (!nc)
+ if (!nc) {
continue;
+ }
if (nc->skeleton) {
- if (nc->bone_idx == -1)
+ if (nc->bone_idx == -1) {
continue;
+ }
AnimatedValuesBackup::Entry entry;
entry.object = nc->skeleton;
@@ -1461,8 +1514,9 @@ AnimatedValuesBackup AnimationPlayer::backup_animated_values() {
bool valid;
entry.value = E->value().object->get_indexed(E->value().subpath, &valid);
entry.bone_idx = -1;
- if (valid)
+ if (valid) {
backup.entries.push_back(entry);
+ }
}
}
}
diff --git a/scene/animation/animation_player.h b/scene/animation/animation_player.h
index c7b3d7fc7b..1a66665803 100644
--- a/scene/animation/animation_player.h
+++ b/scene/animation/animation_player.h
@@ -140,10 +140,11 @@ private:
int bone_idx;
inline bool operator<(const TrackNodeCacheKey &p_right) const {
- if (id == p_right.id)
+ if (id == p_right.id) {
return bone_idx < p_right.bone_idx;
- else
+ } else {
return id < p_right.id;
+ }
}
};
diff --git a/scene/animation/animation_tree.cpp b/scene/animation/animation_tree.cpp
index 671c87eb58..466536db10 100644
--- a/scene/animation/animation_tree.cpp
+++ b/scene/animation/animation_tree.cpp
@@ -210,8 +210,9 @@ float AnimationNode::_blend_node(const StringName &p_subpath, const Vector<Strin
case FILTER_PASS: {
//values filtered pass, the rest don't
for (int i = 0; i < blend_count; i++) {
- if (blendw[i] == 0) //not filtered, does not pass
+ if (blendw[i] == 0) { //not filtered, does not pass
continue;
+ }
blendw[i] = blendr[i] * p_blend;
if (blendw[i] > CMP_EPSILON) {
@@ -224,8 +225,9 @@ float AnimationNode::_blend_node(const StringName &p_subpath, const Vector<Strin
//values filtered don't pass, the rest are blended
for (int i = 0; i < blend_count; i++) {
- if (blendw[i] > 0) //filtered, does not pass
+ if (blendw[i] > 0) { //filtered, does not pass
continue;
+ }
blendw[i] = blendr[i] * p_blend;
if (blendw[i] > CMP_EPSILON) {
@@ -268,8 +270,9 @@ float AnimationNode::_blend_node(const StringName &p_subpath, const Vector<Strin
}
}
- if (!p_seek && p_optimize && !any_valid) //pointless to go on, all are zero
+ if (!p_seek && p_optimize && !any_valid) { //pointless to go on, all are zero
return 0;
+ }
String new_path;
AnimationNode *new_parent;
@@ -467,8 +470,9 @@ Ref<AnimationNode> AnimationTree::get_tree_root() const {
}
void AnimationTree::set_active(bool p_active) {
- if (active == p_active)
+ if (active == p_active) {
return;
+ }
active = p_active;
started = active;
@@ -495,8 +499,9 @@ bool AnimationTree::is_active() const {
}
void AnimationTree::set_process_mode(AnimationProcessMode p_mode) {
- if (process_mode == p_mode)
+ if (process_mode == p_mode) {
return;
+ }
bool was_active = is_active();
if (was_active) {
@@ -837,8 +842,9 @@ void AnimationTree::_process_graph(float p_delta) {
float blend = (*as.track_blends)[blend_idx];
- if (blend < CMP_EPSILON)
+ if (blend < CMP_EPSILON) {
continue; //nothing to blend
+ }
switch (track->type) {
case Animation::TYPE_TRANSFORM: {
@@ -912,8 +918,9 @@ void AnimationTree::_process_graph(float p_delta) {
t->scale = scale;
}
- if (err != OK)
+ if (err != OK) {
continue;
+ }
t->loc = t->loc.lerp(loc, blend);
if (t->rot_blend_accum == 0) {
@@ -937,8 +944,9 @@ void AnimationTree::_process_graph(float p_delta) {
Variant value = a->value_track_interpolate(i, time);
- if (value == Variant())
+ if (value == Variant()) {
continue;
+ }
if (t->process_pass != process_pass) {
t->value = value;
@@ -1006,8 +1014,9 @@ void AnimationTree::_process_graph(float p_delta) {
if (seeked) {
//find whathever should be playing
int idx = a->track_find_key(i, time);
- if (idx < 0)
+ if (idx < 0) {
continue;
+ }
Ref<AudioStream> stream = a->audio_track_get_key_stream(i, idx);
if (!stream.is_valid()) {
@@ -1107,20 +1116,23 @@ void AnimationTree::_process_graph(float p_delta) {
AnimationPlayer *player2 = Object::cast_to<AnimationPlayer>(t->object);
- if (!player2)
+ if (!player2) {
continue;
+ }
if (delta == 0 || seeked) {
//seek
int idx = a->track_find_key(i, time);
- if (idx < 0)
+ if (idx < 0) {
continue;
+ }
float pos = a->track_get_key_time(i, idx);
StringName anim_name = a->animation_track_get_key_animation(i, idx);
- if (String(anim_name) == "[stop]" || !player2->has_animation(anim_name))
+ if (String(anim_name) == "[stop]" || !player2->has_animation(anim_name)) {
continue;
+ }
Ref<Animation> anim = player2->get_animation(anim_name);
@@ -1174,8 +1186,9 @@ void AnimationTree::_process_graph(float p_delta) {
const NodePath *K = nullptr;
while ((K = track_cache.next(K))) {
TrackCache *track = track_cache[*K];
- if (track->process_pass != process_pass)
+ if (track->process_pass != process_pass) {
continue; //not processed, ignore
+ }
switch (track->type) {
case Animation::TYPE_TRANSFORM: {
diff --git a/scene/animation/tween.cpp b/scene/animation/tween.cpp
index d94cbfa08c..854db5fee2 100644
--- a/scene/animation/tween.cpp
+++ b/scene/animation/tween.cpp
@@ -42,50 +42,61 @@ void Tween::_add_pending_command(StringName p_key, const Variant &p_arg1, const
// Determine command argument count
int &count = cmd.args;
- if (p_arg10.get_type() != Variant::NIL)
+ if (p_arg10.get_type() != Variant::NIL) {
count = 10;
- else if (p_arg9.get_type() != Variant::NIL)
+ } else if (p_arg9.get_type() != Variant::NIL) {
count = 9;
- else if (p_arg8.get_type() != Variant::NIL)
+ } else if (p_arg8.get_type() != Variant::NIL) {
count = 8;
- else if (p_arg7.get_type() != Variant::NIL)
+ } else if (p_arg7.get_type() != Variant::NIL) {
count = 7;
- else if (p_arg6.get_type() != Variant::NIL)
+ } else if (p_arg6.get_type() != Variant::NIL) {
count = 6;
- else if (p_arg5.get_type() != Variant::NIL)
+ } else if (p_arg5.get_type() != Variant::NIL) {
count = 5;
- else if (p_arg4.get_type() != Variant::NIL)
+ } else if (p_arg4.get_type() != Variant::NIL) {
count = 4;
- else if (p_arg3.get_type() != Variant::NIL)
+ } else if (p_arg3.get_type() != Variant::NIL) {
count = 3;
- else if (p_arg2.get_type() != Variant::NIL)
+ } else if (p_arg2.get_type() != Variant::NIL) {
count = 2;
- else if (p_arg1.get_type() != Variant::NIL)
+ } else if (p_arg1.get_type() != Variant::NIL) {
count = 1;
- else
+ } else {
count = 0;
+ }
// Add the specified arguments to the command
- if (count > 0)
+ if (count > 0) {
cmd.arg[0] = p_arg1;
- if (count > 1)
+ }
+ if (count > 1) {
cmd.arg[1] = p_arg2;
- if (count > 2)
+ }
+ if (count > 2) {
cmd.arg[2] = p_arg3;
- if (count > 3)
+ }
+ if (count > 3) {
cmd.arg[3] = p_arg4;
- if (count > 4)
+ }
+ if (count > 4) {
cmd.arg[4] = p_arg5;
- if (count > 5)
+ }
+ if (count > 5) {
cmd.arg[5] = p_arg6;
- if (count > 6)
+ }
+ if (count > 6) {
cmd.arg[6] = p_arg7;
- if (count > 7)
+ }
+ if (count > 7) {
cmd.arg[7] = p_arg8;
- if (count > 8)
+ }
+ if (count > 8) {
cmd.arg[8] = p_arg9;
- if (count > 9)
+ }
+ if (count > 9) {
cmd.arg[9] = p_arg10;
+ }
}
void Tween::_process_pending_commands() {
@@ -179,26 +190,30 @@ void Tween::_notification(int p_what) {
case NOTIFICATION_INTERNAL_PROCESS: {
// Are we processing during physics time?
- if (tween_process_mode == TWEEN_PROCESS_PHYSICS)
+ if (tween_process_mode == TWEEN_PROCESS_PHYSICS) {
// Do nothing since we aren't aligned with physics when we should be
break;
+ }
// Should we update?
- if (is_active())
+ if (is_active()) {
// Update the tweens
_tween_process(get_process_delta_time());
+ }
} break;
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
// Are we processing during 'regular' time?
- if (tween_process_mode == TWEEN_PROCESS_IDLE)
+ if (tween_process_mode == TWEEN_PROCESS_IDLE) {
// Do nothing since we would only process during idle time
break;
+ }
// Should we update?
- if (is_active())
+ if (is_active()) {
// Update the tweens
_tween_process(get_physics_process_delta_time());
+ }
} break;
case NOTIFICATION_EXIT_TREE: {
@@ -346,8 +361,9 @@ Variant Tween::_get_final_val(const InterpolateData &p_data) const {
// If we're looking at an INT value, instead convert it to a FLOAT
// This is better for interpolation
- if (final_val.get_type() == Variant::INT)
+ if (final_val.get_type() == Variant::INT) {
final_val = final_val.operator real_t();
+ }
return final_val;
}
@@ -388,8 +404,9 @@ Variant &Tween::_get_delta_val(InterpolateData &p_data) {
// If we're looking at an INT value, instead convert it to a FLOAT
// This is better for interpolation
- if (final_val.get_type() == Variant::INT)
+ if (final_val.get_type() == Variant::INT) {
final_val = final_val.operator real_t();
+ }
// Calculate the delta based on the initial value and the final value
_calc_delta_val(p_data.initial_val, final_val, p_data.delta_val);
@@ -403,8 +420,9 @@ Variant &Tween::_get_delta_val(InterpolateData &p_data) {
// If we're looking at an INT value, instead convert it to a FLOAT
// This is better for interpolation
- if (initial_val.get_type() == Variant::INT)
+ if (initial_val.get_type() == Variant::INT) {
initial_val = initial_val.operator real_t();
+ }
// Calculate the delta based on the initial value and the final value
_calc_delta_val(initial_val, p_data.final_val, p_data.delta_val);
@@ -652,8 +670,9 @@ void Tween::_tween_process(float p_delta) {
_process_pending_commands();
// If the scale is 0, make no progress on the tweens
- if (speed_scale == 0)
+ if (speed_scale == 0) {
return;
+ }
// Update the delta and whether we are pending an update
p_delta *= speed_scale;
@@ -676,8 +695,9 @@ void Tween::_tween_process(float p_delta) {
}
// If we are all finished, we can reset all of the tweens
- if (repeats_finished)
+ if (repeats_finished) {
reset_all();
+ }
}
// Are all of the tweens complete?
@@ -692,20 +712,22 @@ void Tween::_tween_process(float p_delta) {
all_finished = all_finished && data.finish;
// Is the data not active or already finished? No need to go any further
- if (!data.active || data.finish)
+ if (!data.active || data.finish) {
continue;
+ }
// Get the target object for this interpolation
Object *object = ObjectDB::get_instance(data.id);
- if (object == nullptr)
+ if (object == nullptr) {
continue;
+ }
// Are we still delaying this tween?
bool prev_delaying = data.elapsed <= data.delay;
data.elapsed += p_delta;
- if (data.elapsed < data.delay)
+ if (data.elapsed < data.delay) {
continue;
- else if (prev_delaying) {
+ } else if (prev_delaying) {
// We can apply the tween's value to the data and emit that the tween has started
_apply_tween_value(data, data.initial_val);
emit_signal("tween_started", object, NodePath(Vector<StringName>(), data.key, false));
@@ -778,8 +800,9 @@ void Tween::_tween_process(float p_delta) {
emit_signal("tween_completed", object, NodePath(Vector<StringName>(), data.key, false));
// If we are not repeating the tween, remove it
- if (!repeat)
+ if (!repeat) {
call_deferred("_remove_by_uid", data.uid);
+ }
} else if (!repeat) {
// Check whether all tweens are finished
all_finished = all_finished && data.finish;
@@ -809,8 +832,9 @@ bool Tween::is_active() const {
void Tween::set_active(bool p_active) {
// Do nothing if it's the same active mode that we currently are
- if (is_active() == p_active)
+ if (is_active() == p_active) {
return;
+ }
// Depending on physics or idle, set processing
switch (tween_process_mode) {
@@ -860,8 +884,9 @@ void Tween::reset(Object *p_object, StringName p_key) {
// Get the target object
InterpolateData &data = E->get();
Object *object = ObjectDB::get_instance(data.id);
- if (object == nullptr)
+ if (object == nullptr) {
continue;
+ }
// Do we have the correct object and key?
if (object == p_object && (data.concatenated_key == p_key || p_key == "")) {
@@ -870,8 +895,9 @@ void Tween::reset(Object *p_object, StringName p_key) {
data.finish = false;
// Also apply the initial state if there isn't a delay
- if (data.delay == 0)
+ if (data.delay == 0) {
_apply_tween_value(data, data.initial_val);
+ }
}
}
pending_update--;
@@ -887,8 +913,9 @@ void Tween::reset_all() {
data.finish = false;
// If there isn't a delay, apply the value to the object
- if (data.delay == 0)
+ if (data.delay == 0) {
_apply_tween_value(data, data.initial_val);
+ }
}
pending_update--;
}
@@ -900,13 +927,15 @@ void Tween::stop(Object *p_object, StringName p_key) {
// Get the object the tween is targeting
InterpolateData &data = E->get();
Object *object = ObjectDB::get_instance(data.id);
- if (object == nullptr)
+ if (object == nullptr) {
continue;
+ }
// Is this the correct object and does it have the given key?
- if (object == p_object && (data.concatenated_key == p_key || p_key == ""))
+ if (object == p_object && (data.concatenated_key == p_key || p_key == "")) {
// Disable the tween
data.active = false;
+ }
}
pending_update--;
}
@@ -936,12 +965,14 @@ void Tween::resume(Object *p_object, StringName p_key) {
// Grab the object
InterpolateData &data = E->get();
Object *object = ObjectDB::get_instance(data.id);
- if (object == nullptr)
+ if (object == nullptr) {
continue;
+ }
// If the object and string key match, activate it
- if (object == p_object && (data.concatenated_key == p_key || p_key == ""))
+ if (object == p_object && (data.concatenated_key == p_key || p_key == "")) {
data.active = true;
+ }
}
pending_update--;
}
@@ -974,8 +1005,9 @@ void Tween::remove(Object *p_object, StringName p_key) {
// Get the target object
InterpolateData &data = E->get();
Object *object = ObjectDB::get_instance(data.id);
- if (object == nullptr)
+ if (object == nullptr) {
continue;
+ }
// If the target object and string key match, queue it for removal
if (object == p_object && (data.concatenated_key == p_key || p_key == "")) {
@@ -1076,9 +1108,10 @@ real_t Tween::tell() const {
for (const List<InterpolateData>::Element *E = interpolates.front(); E; E = E->next()) {
// Get the data and figure out if it's position is further along than the previous ones
const InterpolateData &data = E->get();
- if (data.elapsed > pos)
+ if (data.elapsed > pos) {
// Save it if so
pos = data.elapsed;
+ }
}
pending_update--;
return pos;
@@ -1098,9 +1131,10 @@ real_t Tween::get_runtime() const {
// Get the tween data and see if it's runtime is greater than the previous tweens
const InterpolateData &data = E->get();
real_t t = data.delay + data.duration;
- if (t > runtime)
+ if (t > runtime) {
// This is the longest running tween
runtime = t;
+ }
}
pending_update--;
@@ -1305,8 +1339,9 @@ void Tween::_build_interpolation(InterpolateType p_interpolation_type, Object *p
}
// Is there not a valid delta?
- if (!_calc_delta_val(data.initial_val, data.final_val, data.delta_val))
+ if (!_calc_delta_val(data.initial_val, data.final_val, data.delta_val)) {
return;
+ }
// Add this interpolation to the total
_push_interpolate_data(data);
@@ -1324,14 +1359,17 @@ void Tween::interpolate_property(Object *p_object, NodePath p_property, Variant
// If no initial value given, grab the initial value from the object
// TODO: Is this documented? This is very useful and removes a lot of clutter from tweens!
- if (p_initial_val.get_type() == Variant::NIL)
+ if (p_initial_val.get_type() == Variant::NIL) {
p_initial_val = p_object->get_indexed(p_property.get_subnames());
+ }
// Convert any integers into REALs as they are better for interpolation
- if (p_initial_val.get_type() == Variant::INT)
+ if (p_initial_val.get_type() == Variant::INT) {
p_initial_val = p_initial_val.operator real_t();
- if (p_final_val.get_type() == Variant::INT)
+ }
+ if (p_final_val.get_type() == Variant::INT) {
p_final_val = p_final_val.operator real_t();
+ }
// Build the interpolation data
_build_interpolation(INTER_PROPERTY, p_object, &p_property, nullptr, p_initial_val, p_final_val, p_duration, p_trans_type, p_ease_type, p_delay);
@@ -1345,10 +1383,12 @@ void Tween::interpolate_method(Object *p_object, StringName p_method, Variant p_
}
// Convert any integers into REALs as they are better for interpolation
- if (p_initial_val.get_type() == Variant::INT)
+ if (p_initial_val.get_type() == Variant::INT) {
p_initial_val = p_initial_val.operator real_t();
- if (p_final_val.get_type() == Variant::INT)
+ }
+ if (p_final_val.get_type() == Variant::INT) {
p_final_val = p_final_val.operator real_t();
+ }
// Build the interpolation data
_build_interpolation(INTER_METHOD, p_object, nullptr, &p_method, p_initial_val, p_final_val, p_duration, p_trans_type, p_ease_type, p_delay);
@@ -1387,18 +1427,19 @@ void Tween::interpolate_callback(Object *p_object, real_t p_duration, String p_c
// Add arguments to the interpolation
int args = 0;
- if (p_arg5.get_type() != Variant::NIL)
+ if (p_arg5.get_type() != Variant::NIL) {
args = 5;
- else if (p_arg4.get_type() != Variant::NIL)
+ } else if (p_arg4.get_type() != Variant::NIL) {
args = 4;
- else if (p_arg3.get_type() != Variant::NIL)
+ } else if (p_arg3.get_type() != Variant::NIL) {
args = 3;
- else if (p_arg2.get_type() != Variant::NIL)
+ } else if (p_arg2.get_type() != Variant::NIL) {
args = 2;
- else if (p_arg1.get_type() != Variant::NIL)
+ } else if (p_arg1.get_type() != Variant::NIL) {
args = 1;
- else
+ } else {
args = 0;
+ }
data.args = args;
data.arg[0] = p_arg1;
@@ -1444,18 +1485,19 @@ void Tween::interpolate_deferred_callback(Object *p_object, real_t p_duration, S
// Collect arguments for the callback
int args = 0;
- if (p_arg5.get_type() != Variant::NIL)
+ if (p_arg5.get_type() != Variant::NIL) {
args = 5;
- else if (p_arg4.get_type() != Variant::NIL)
+ } else if (p_arg4.get_type() != Variant::NIL) {
args = 4;
- else if (p_arg3.get_type() != Variant::NIL)
+ } else if (p_arg3.get_type() != Variant::NIL) {
args = 3;
- else if (p_arg2.get_type() != Variant::NIL)
+ } else if (p_arg2.get_type() != Variant::NIL) {
args = 2;
- else if (p_arg1.get_type() != Variant::NIL)
+ } else if (p_arg1.get_type() != Variant::NIL) {
args = 1;
- else
+ } else {
args = 0;
+ }
data.args = args;
data.arg[0] = p_arg1;
@@ -1481,12 +1523,14 @@ void Tween::follow_property(Object *p_object, NodePath p_property, Variant p_ini
// If no initial value is given, grab it from the source object
// TODO: Is this documented? It's really helpful for decluttering tweens
- if (p_initial_val.get_type() == Variant::NIL)
+ if (p_initial_val.get_type() == Variant::NIL) {
p_initial_val = p_object->get_indexed(p_property.get_subnames());
+ }
// Convert initial INT values to FLOAT as they are better for interpolation
- if (p_initial_val.get_type() == Variant::INT)
+ if (p_initial_val.get_type() == Variant::INT) {
p_initial_val = p_initial_val.operator real_t();
+ }
// Confirm the source and target objects are valid
ERR_FAIL_COND(p_object == nullptr);
@@ -1512,8 +1556,9 @@ void Tween::follow_property(Object *p_object, NodePath p_property, Variant p_ini
ERR_FAIL_COND(!target_prop_valid);
// Convert target INT to FLOAT since it is better for interpolation
- if (target_val.get_type() == Variant::INT)
+ if (target_val.get_type() == Variant::INT) {
target_val = target_val.operator real_t();
+ }
// Verify that the target value and initial value are the same type
ERR_FAIL_COND(target_val.get_type() != p_initial_val.get_type());
@@ -1548,8 +1593,9 @@ void Tween::follow_method(Object *p_object, StringName p_method, Variant p_initi
return;
}
// Convert initial INT values to FLOAT as they are better for interpolation
- if (p_initial_val.get_type() == Variant::INT)
+ if (p_initial_val.get_type() == Variant::INT) {
p_initial_val = p_initial_val.operator real_t();
+ }
// Verify the source and target objects are valid
ERR_FAIL_COND(p_object == nullptr);
@@ -1575,8 +1621,9 @@ void Tween::follow_method(Object *p_object, StringName p_method, Variant p_initi
ERR_FAIL_COND(error.error != Callable::CallError::CALL_OK);
// Convert target INT values to FLOAT as they are better for interpolation
- if (target_val.get_type() == Variant::INT)
+ if (target_val.get_type() == Variant::INT) {
target_val = target_val.operator real_t();
+ }
ERR_FAIL_COND(target_val.get_type() != p_initial_val.get_type());
// Make the new InterpolateData for the method follow
@@ -1613,8 +1660,9 @@ void Tween::targeting_property(Object *p_object, NodePath p_property, Object *p_
p_initial_property = p_initial_property.get_as_property_path();
// Convert the initial INT values to FLOAT as they are better for Interpolation
- if (p_final_val.get_type() == Variant::INT)
+ if (p_final_val.get_type() == Variant::INT) {
p_final_val = p_final_val.operator real_t();
+ }
// Verify both objects are valid
ERR_FAIL_COND(p_object == nullptr);
@@ -1640,8 +1688,9 @@ void Tween::targeting_property(Object *p_object, NodePath p_property, Object *p_
ERR_FAIL_COND(!initial_prop_valid);
// Convert the initial INT value to FLOAT as it is better for interpolation
- if (initial_val.get_type() == Variant::INT)
+ if (initial_val.get_type() == Variant::INT) {
initial_val = initial_val.operator real_t();
+ }
ERR_FAIL_COND(initial_val.get_type() != p_final_val.get_type());
// Build the InterpolateData object
@@ -1681,8 +1730,9 @@ void Tween::targeting_method(Object *p_object, StringName p_method, Object *p_in
}
// Convert final INT values to FLOAT as they are better for interpolation
- if (p_final_val.get_type() == Variant::INT)
+ if (p_final_val.get_type() == Variant::INT) {
p_final_val = p_final_val.operator real_t();
+ }
// Make sure the given objects are valid
ERR_FAIL_COND(p_object == nullptr);
@@ -1708,8 +1758,9 @@ void Tween::targeting_method(Object *p_object, StringName p_method, Object *p_in
ERR_FAIL_COND(error.error != Callable::CallError::CALL_OK);
// Convert initial INT values to FLOAT as they aer better for interpolation
- if (initial_val.get_type() == Variant::INT)
+ if (initial_val.get_type() == Variant::INT) {
initial_val = initial_val.operator real_t();
+ }
ERR_FAIL_COND(initial_val.get_type() != p_final_val.get_type());
// Build the new InterpolateData object
diff --git a/scene/audio/audio_stream_player.cpp b/scene/audio/audio_stream_player.cpp
index 660d148516..48f70e88cb 100644
--- a/scene/audio/audio_stream_player.cpp
+++ b/scene/audio/audio_stream_player.cpp
@@ -56,8 +56,9 @@ void AudioStreamPlayer::_mix_to_bus(const AudioFrame *p_frames, int p_amount) {
}
for (int c = 0; c < 4; c++) {
- if (!targets[c])
+ if (!targets[c]) {
break;
+ }
for (int i = 0; i < p_amount; i++) {
targets[c][i] += p_frames[i];
}
@@ -305,10 +306,11 @@ AudioStreamPlayer::MixTarget AudioStreamPlayer::get_mix_target() const {
}
void AudioStreamPlayer::_set_playing(bool p_enable) {
- if (p_enable)
+ if (p_enable) {
play();
- else
+ } else {
stop();
+ }
}
bool AudioStreamPlayer::_is_active() const {
@@ -330,8 +332,9 @@ void AudioStreamPlayer::_validate_property(PropertyInfo &property) const {
if (property.name == "bus") {
String options;
for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) {
- if (i > 0)
+ if (i > 0) {
options += ",";
+ }
String name = AudioServer::get_singleton()->get_bus_name(i);
options += name;
}
diff --git a/scene/debugger/scene_debugger.cpp b/scene/debugger/scene_debugger.cpp
index 879f891cc9..0222585948 100644
--- a/scene/debugger/scene_debugger.cpp
+++ b/scene/debugger/scene_debugger.cpp
@@ -48,8 +48,9 @@ void SceneDebugger::deinitialize() {
#ifdef DEBUG_ENABLED
if (LiveEditor::singleton) {
// Should be removed automatically when deiniting debugger, but just in case
- if (EngineDebugger::has_capture("scene"))
+ if (EngineDebugger::has_capture("scene")) {
EngineDebugger::unregister_message_capture("scene");
+ }
memdelete(LiveEditor::singleton);
LiveEditor::singleton = nullptr;
}
@@ -59,11 +60,13 @@ void SceneDebugger::deinitialize() {
#ifdef DEBUG_ENABLED
Error SceneDebugger::parse_message(void *p_user, const String &p_msg, const Array &p_args, bool &r_captured) {
SceneTree *scene_tree = SceneTree::get_singleton();
- if (!scene_tree)
+ if (!scene_tree) {
return ERR_UNCONFIGURED;
+ }
LiveEditor *live_editor = LiveEditor::get_singleton();
- if (!live_editor)
+ if (!live_editor) {
return ERR_UNCONFIGURED;
+ }
r_captured = true;
if (p_msg == "request_scene_tree") { // Scene tree
@@ -193,8 +196,9 @@ void SceneDebugger::_save_node(ObjectID id, const String &p_path) {
void SceneDebugger::_send_object_id(ObjectID p_id, int p_max_size) {
SceneDebuggerObject obj(p_id);
- if (obj.id.is_null())
+ if (obj.id.is_null()) {
return;
+ }
Array arr;
obj.serialize(arr);
@@ -203,8 +207,9 @@ void SceneDebugger::_send_object_id(ObjectID p_id, int p_max_size) {
void SceneDebugger::_set_object_property(ObjectID p_id, const String &p_property, const Variant &p_value) {
Object *obj = ObjectDB::get_instance(p_id);
- if (!obj)
+ if (!obj) {
return;
+ }
String prop_name = p_property;
if (p_property.begins_with("Members/")) {
@@ -217,8 +222,9 @@ void SceneDebugger::_set_object_property(ObjectID p_id, const String &p_property
void SceneDebugger::add_to_cache(const String &p_filename, Node *p_node) {
LiveEditor *debugger = LiveEditor::get_singleton();
- if (!debugger)
+ if (!debugger) {
return;
+ }
if (EngineDebugger::get_script_debugger() && p_filename != String()) {
debugger->live_scene_edit_cache[p_filename].insert(p_node);
@@ -227,8 +233,9 @@ void SceneDebugger::add_to_cache(const String &p_filename, Node *p_node) {
void SceneDebugger::remove_from_cache(const String &p_filename, Node *p_node) {
LiveEditor *debugger = LiveEditor::get_singleton();
- if (!debugger)
+ if (!debugger) {
return;
+ }
Map<String, Set<Node *>> &edit_cache = debugger->live_scene_edit_cache;
Map<String, Set<Node *>>::Element *E = edit_cache.find(p_filename);
@@ -253,8 +260,9 @@ void SceneDebugger::remove_from_cache(const String &p_filename, Node *p_node) {
SceneDebuggerObject::SceneDebuggerObject(ObjectID p_id) {
id = ObjectID();
Object *obj = ObjectDB::get_instance(p_id);
- if (!obj)
+ if (!obj) {
return;
+ }
id = p_id;
class_name = obj->get_class();
@@ -483,8 +491,9 @@ LiveEditor *LiveEditor::get_singleton() {
void LiveEditor::_send_tree() {
SceneTree *scene_tree = SceneTree::get_singleton();
- if (!scene_tree)
+ if (!scene_tree) {
return;
+ }
Array arr;
// Encoded as a flat list depth fist.
@@ -503,29 +512,35 @@ void LiveEditor::_res_path_func(const String &p_path, int p_id) {
void LiveEditor::_node_set_func(int p_id, const StringName &p_prop, const Variant &p_value) {
SceneTree *scene_tree = SceneTree::get_singleton();
- if (!scene_tree)
+ if (!scene_tree) {
return;
+ }
- if (!live_edit_node_path_cache.has(p_id))
+ if (!live_edit_node_path_cache.has(p_id)) {
return;
+ }
NodePath np = live_edit_node_path_cache[p_id];
Node *base = nullptr;
- if (scene_tree->root->has_node(live_edit_root))
+ if (scene_tree->root->has_node(live_edit_root)) {
base = scene_tree->root->get_node(live_edit_root);
+ }
Map<String, Set<Node *>>::Element *E = live_scene_edit_cache.find(live_edit_scene);
- if (!E)
+ if (!E) {
return; //scene not editable
+ }
for (Set<Node *>::Element *F = E->get().front(); F; F = F->next()) {
Node *n = F->get();
- if (base && !base->is_a_parent_of(n))
+ if (base && !base->is_a_parent_of(n)) {
continue;
+ }
- if (!n->has_node(np))
+ if (!n->has_node(np)) {
continue;
+ }
Node *n2 = n->get_node(np);
n2->set(p_prop, p_value);
@@ -534,35 +549,42 @@ void LiveEditor::_node_set_func(int p_id, const StringName &p_prop, const Varian
void LiveEditor::_node_set_res_func(int p_id, const StringName &p_prop, const String &p_value) {
RES r = ResourceLoader::load(p_value);
- if (!r.is_valid())
+ if (!r.is_valid()) {
return;
+ }
_node_set_func(p_id, p_prop, r);
}
void LiveEditor::_node_call_func(int p_id, const StringName &p_method, VARIANT_ARG_DECLARE) {
SceneTree *scene_tree = SceneTree::get_singleton();
- if (!scene_tree)
+ if (!scene_tree) {
return;
- if (!live_edit_node_path_cache.has(p_id))
+ }
+ if (!live_edit_node_path_cache.has(p_id)) {
return;
+ }
NodePath np = live_edit_node_path_cache[p_id];
Node *base = nullptr;
- if (scene_tree->root->has_node(live_edit_root))
+ if (scene_tree->root->has_node(live_edit_root)) {
base = scene_tree->root->get_node(live_edit_root);
+ }
Map<String, Set<Node *>>::Element *E = live_scene_edit_cache.find(live_edit_scene);
- if (!E)
+ if (!E) {
return; //scene not editable
+ }
for (Set<Node *>::Element *F = E->get().front(); F; F = F->next()) {
Node *n = F->get();
- if (base && !base->is_a_parent_of(n))
+ if (base && !base->is_a_parent_of(n)) {
continue;
+ }
- if (!n->has_node(np))
+ if (!n->has_node(np)) {
continue;
+ }
Node *n2 = n->get_node(np);
n2->call(p_method, VARIANT_ARG_PASS);
@@ -570,40 +592,47 @@ void LiveEditor::_node_call_func(int p_id, const StringName &p_method, VARIANT_A
}
void LiveEditor::_res_set_func(int p_id, const StringName &p_prop, const Variant &p_value) {
- if (!live_edit_resource_cache.has(p_id))
+ if (!live_edit_resource_cache.has(p_id)) {
return;
+ }
String resp = live_edit_resource_cache[p_id];
- if (!ResourceCache::has(resp))
+ if (!ResourceCache::has(resp)) {
return;
+ }
RES r = ResourceCache::get(resp);
- if (!r.is_valid())
+ if (!r.is_valid()) {
return;
+ }
r->set(p_prop, p_value);
}
void LiveEditor::_res_set_res_func(int p_id, const StringName &p_prop, const String &p_value) {
RES r = ResourceLoader::load(p_value);
- if (!r.is_valid())
+ if (!r.is_valid()) {
return;
+ }
_res_set_func(p_id, p_prop, r);
}
void LiveEditor::_res_call_func(int p_id, const StringName &p_method, VARIANT_ARG_DECLARE) {
- if (!live_edit_resource_cache.has(p_id))
+ if (!live_edit_resource_cache.has(p_id)) {
return;
+ }
String resp = live_edit_resource_cache[p_id];
- if (!ResourceCache::has(resp))
+ if (!ResourceCache::has(resp)) {
return;
+ }
RES r = ResourceCache::get(resp);
- if (!r.is_valid())
+ if (!r.is_valid()) {
return;
+ }
r->call(p_method, VARIANT_ARG_PASS);
}
@@ -615,25 +644,30 @@ void LiveEditor::_root_func(const NodePath &p_scene_path, const String &p_scene_
void LiveEditor::_create_node_func(const NodePath &p_parent, const String &p_type, const String &p_name) {
SceneTree *scene_tree = SceneTree::get_singleton();
- if (!scene_tree)
+ if (!scene_tree) {
return;
+ }
Node *base = nullptr;
- if (scene_tree->root->has_node(live_edit_root))
+ if (scene_tree->root->has_node(live_edit_root)) {
base = scene_tree->root->get_node(live_edit_root);
+ }
Map<String, Set<Node *>>::Element *E = live_scene_edit_cache.find(live_edit_scene);
- if (!E)
+ if (!E) {
return; //scene not editable
+ }
for (Set<Node *>::Element *F = E->get().front(); F; F = F->next()) {
Node *n = F->get();
- if (base && !base->is_a_parent_of(n))
+ if (base && !base->is_a_parent_of(n)) {
continue;
+ }
- if (!n->has_node(p_parent))
+ if (!n->has_node(p_parent)) {
continue;
+ }
Node *n2 = n->get_node(p_parent);
Node *no = Object::cast_to<Node>(ClassDB::instance(p_type));
@@ -648,30 +682,36 @@ void LiveEditor::_create_node_func(const NodePath &p_parent, const String &p_typ
void LiveEditor::_instance_node_func(const NodePath &p_parent, const String &p_path, const String &p_name) {
SceneTree *scene_tree = SceneTree::get_singleton();
- if (!scene_tree)
+ if (!scene_tree) {
return;
+ }
Ref<PackedScene> ps = ResourceLoader::load(p_path);
- if (!ps.is_valid())
+ if (!ps.is_valid()) {
return;
+ }
Node *base = nullptr;
- if (scene_tree->root->has_node(live_edit_root))
+ if (scene_tree->root->has_node(live_edit_root)) {
base = scene_tree->root->get_node(live_edit_root);
+ }
Map<String, Set<Node *>>::Element *E = live_scene_edit_cache.find(live_edit_scene);
- if (!E)
+ if (!E) {
return; //scene not editable
+ }
for (Set<Node *>::Element *F = E->get().front(); F; F = F->next()) {
Node *n = F->get();
- if (base && !base->is_a_parent_of(n))
+ if (base && !base->is_a_parent_of(n)) {
continue;
+ }
- if (!n->has_node(p_parent))
+ if (!n->has_node(p_parent)) {
continue;
+ }
Node *n2 = n->get_node(p_parent);
Node *no = ps->instance();
@@ -686,27 +726,32 @@ void LiveEditor::_instance_node_func(const NodePath &p_parent, const String &p_p
void LiveEditor::_remove_node_func(const NodePath &p_at) {
SceneTree *scene_tree = SceneTree::get_singleton();
- if (!scene_tree)
+ if (!scene_tree) {
return;
+ }
Node *base = nullptr;
- if (scene_tree->root->has_node(live_edit_root))
+ if (scene_tree->root->has_node(live_edit_root)) {
base = scene_tree->root->get_node(live_edit_root);
+ }
Map<String, Set<Node *>>::Element *E = live_scene_edit_cache.find(live_edit_scene);
- if (!E)
+ if (!E) {
return; //scene not editable
+ }
for (Set<Node *>::Element *F = E->get().front(); F;) {
Set<Node *>::Element *N = F->next();
Node *n = F->get();
- if (base && !base->is_a_parent_of(n))
+ if (base && !base->is_a_parent_of(n)) {
continue;
+ }
- if (!n->has_node(p_at))
+ if (!n->has_node(p_at)) {
continue;
+ }
Node *n2 = n->get_node(p_at);
memdelete(n2);
@@ -717,27 +762,32 @@ void LiveEditor::_remove_node_func(const NodePath &p_at) {
void LiveEditor::_remove_and_keep_node_func(const NodePath &p_at, ObjectID p_keep_id) {
SceneTree *scene_tree = SceneTree::get_singleton();
- if (!scene_tree)
+ if (!scene_tree) {
return;
+ }
Node *base = nullptr;
- if (scene_tree->root->has_node(live_edit_root))
+ if (scene_tree->root->has_node(live_edit_root)) {
base = scene_tree->root->get_node(live_edit_root);
+ }
Map<String, Set<Node *>>::Element *E = live_scene_edit_cache.find(live_edit_scene);
- if (!E)
+ if (!E) {
return; //scene not editable
+ }
for (Set<Node *>::Element *F = E->get().front(); F;) {
Set<Node *>::Element *N = F->next();
Node *n = F->get();
- if (base && !base->is_a_parent_of(n))
+ if (base && !base->is_a_parent_of(n)) {
continue;
+ }
- if (!n->has_node(p_at))
+ if (!n->has_node(p_at)) {
continue;
+ }
Node *n2 = n->get_node(p_at);
@@ -751,38 +801,45 @@ void LiveEditor::_remove_and_keep_node_func(const NodePath &p_at, ObjectID p_kee
void LiveEditor::_restore_node_func(ObjectID p_id, const NodePath &p_at, int p_at_pos) {
SceneTree *scene_tree = SceneTree::get_singleton();
- if (!scene_tree)
+ if (!scene_tree) {
return;
+ }
Node *base = nullptr;
- if (scene_tree->root->has_node(live_edit_root))
+ if (scene_tree->root->has_node(live_edit_root)) {
base = scene_tree->root->get_node(live_edit_root);
+ }
Map<String, Set<Node *>>::Element *E = live_scene_edit_cache.find(live_edit_scene);
- if (!E)
+ if (!E) {
return; //scene not editable
+ }
for (Set<Node *>::Element *F = E->get().front(); F;) {
Set<Node *>::Element *N = F->next();
Node *n = F->get();
- if (base && !base->is_a_parent_of(n))
+ if (base && !base->is_a_parent_of(n)) {
continue;
+ }
- if (!n->has_node(p_at))
+ if (!n->has_node(p_at)) {
continue;
+ }
Node *n2 = n->get_node(p_at);
Map<Node *, Map<ObjectID, Node *>>::Element *EN = live_edit_remove_list.find(n);
- if (!EN)
+ if (!EN) {
continue;
+ }
Map<ObjectID, Node *>::Element *FN = EN->get().find(p_id);
- if (!FN)
+ if (!FN) {
continue;
+ }
n2->add_child(FN->get());
EN->get().erase(FN);
@@ -797,31 +854,37 @@ void LiveEditor::_restore_node_func(ObjectID p_id, const NodePath &p_at, int p_a
void LiveEditor::_duplicate_node_func(const NodePath &p_at, const String &p_new_name) {
SceneTree *scene_tree = SceneTree::get_singleton();
- if (!scene_tree)
+ if (!scene_tree) {
return;
+ }
Node *base = nullptr;
- if (scene_tree->root->has_node(live_edit_root))
+ if (scene_tree->root->has_node(live_edit_root)) {
base = scene_tree->root->get_node(live_edit_root);
+ }
Map<String, Set<Node *>>::Element *E = live_scene_edit_cache.find(live_edit_scene);
- if (!E)
+ if (!E) {
return; //scene not editable
+ }
for (Set<Node *>::Element *F = E->get().front(); F; F = F->next()) {
Node *n = F->get();
- if (base && !base->is_a_parent_of(n))
+ if (base && !base->is_a_parent_of(n)) {
continue;
+ }
- if (!n->has_node(p_at))
+ if (!n->has_node(p_at)) {
continue;
+ }
Node *n2 = n->get_node(p_at);
Node *dup = n2->duplicate(Node::DUPLICATE_SIGNALS | Node::DUPLICATE_GROUPS | Node::DUPLICATE_SCRIPTS);
- if (!dup)
+ if (!dup) {
continue;
+ }
dup->set_name(p_new_name);
n2->get_parent()->add_child(dup);
@@ -830,37 +893,44 @@ void LiveEditor::_duplicate_node_func(const NodePath &p_at, const String &p_new_
void LiveEditor::_reparent_node_func(const NodePath &p_at, const NodePath &p_new_place, const String &p_new_name, int p_at_pos) {
SceneTree *scene_tree = SceneTree::get_singleton();
- if (!scene_tree)
+ if (!scene_tree) {
return;
+ }
Node *base = nullptr;
- if (scene_tree->root->has_node(live_edit_root))
+ if (scene_tree->root->has_node(live_edit_root)) {
base = scene_tree->root->get_node(live_edit_root);
+ }
Map<String, Set<Node *>>::Element *E = live_scene_edit_cache.find(live_edit_scene);
- if (!E)
+ if (!E) {
return; //scene not editable
+ }
for (Set<Node *>::Element *F = E->get().front(); F; F = F->next()) {
Node *n = F->get();
- if (base && !base->is_a_parent_of(n))
+ if (base && !base->is_a_parent_of(n)) {
continue;
+ }
- if (!n->has_node(p_at))
+ if (!n->has_node(p_at)) {
continue;
+ }
Node *nfrom = n->get_node(p_at);
- if (!n->has_node(p_new_place))
+ if (!n->has_node(p_new_place)) {
continue;
+ }
Node *nto = n->get_node(p_new_place);
nfrom->get_parent()->remove_child(nfrom);
nfrom->set_name(p_new_name);
nto->add_child(nfrom);
- if (p_at_pos >= 0)
+ if (p_at_pos >= 0) {
nto->move_child(nfrom, p_at_pos);
+ }
}
}
diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp
index 79e1102f6b..d8229b5f43 100644
--- a/scene/gui/base_button.cpp
+++ b/scene/gui/base_button.cpp
@@ -35,24 +35,27 @@
#include "scene/scene_string_names.h"
void BaseButton::_unpress_group() {
- if (!button_group.is_valid())
+ if (!button_group.is_valid()) {
return;
+ }
if (toggle_mode) {
status.pressed = true;
}
for (Set<BaseButton *>::Element *E = button_group->buttons.front(); E; E = E->next()) {
- if (E->get() == this)
+ if (E->get() == this) {
continue;
+ }
E->get()->set_pressed(false);
}
}
void BaseButton::_gui_input(Ref<InputEvent> p_event) {
- if (status.disabled) // no interaction with disabled button
+ if (status.disabled) { // no interaction with disabled button
return;
+ }
Ref<InputEventMouseButton> mouse_button = p_event;
bool ui_accept = p_event->is_action("ui_accept") && !p_event->is_echo();
@@ -183,8 +186,9 @@ void BaseButton::toggled(bool p_pressed) {
}
void BaseButton::set_disabled(bool p_disabled) {
- if (status.disabled == p_disabled)
+ if (status.disabled == p_disabled) {
return;
+ }
status.disabled = p_disabled;
if (p_disabled) {
@@ -203,10 +207,12 @@ bool BaseButton::is_disabled() const {
}
void BaseButton::set_pressed(bool p_pressed) {
- if (!toggle_mode)
+ if (!toggle_mode) {
return;
- if (status.pressed == p_pressed)
+ }
+ if (status.pressed == p_pressed) {
return;
+ }
_change_notify("pressed");
status.pressed = p_pressed;
@@ -236,8 +242,9 @@ BaseButton::DrawMode BaseButton::get_draw_mode() const {
};
if (!status.press_attempt && status.hovering) {
- if (status.pressed)
+ if (status.pressed) {
return DRAW_HOVER_PRESSED;
+ }
return DRAW_HOVER;
} else {
@@ -246,16 +253,18 @@ BaseButton::DrawMode BaseButton::get_draw_mode() const {
bool pressing;
if (status.press_attempt) {
pressing = (status.pressing_inside || keep_pressed_outside);
- if (status.pressed)
+ if (status.pressed) {
pressing = !pressing;
+ }
} else {
pressing = status.pressed;
}
- if (pressing)
+ if (pressing) {
return DRAW_PRESSED;
- else
+ } else {
return DRAW_NORMAL;
+ }
}
return DRAW_NORMAL;
@@ -451,8 +460,9 @@ Array ButtonGroup::_get_buttons() {
BaseButton *ButtonGroup::get_pressed_button() {
for (Set<BaseButton *>::Element *E = buttons.front(); E; E = E->next()) {
- if (E->get()->is_pressed())
+ if (E->get()->is_pressed()) {
return E->get();
+ }
}
return nullptr;
diff --git a/scene/gui/box_container.cpp b/scene/gui/box_container.cpp
index 5252f3f2f2..75d04dba61 100644
--- a/scene/gui/box_container.cpp
+++ b/scene/gui/box_container.cpp
@@ -54,10 +54,12 @@ void BoxContainer::_resort() {
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c || !c->is_visible_in_tree())
+ if (!c || !c->is_visible_in_tree()) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
+ }
Size2i size = c->get_combined_minimum_size();
_MinSizeCache msc;
@@ -82,8 +84,9 @@ void BoxContainer::_resort() {
children_count++;
}
- if (children_count == 0)
+ if (children_count == 0) {
return;
+ }
int stretch_max = (vertical ? new_size.height : new_size.width) - (children_count - 1) * sep;
int stretch_diff = stretch_max - stretch_min;
@@ -104,10 +107,12 @@ void BoxContainer::_resort() {
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c || !c->is_visible_in_tree())
+ if (!c || !c->is_visible_in_tree()) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
+ }
ERR_FAIL_COND(!min_size_cache.has(c));
_MinSizeCache &msc = min_size_cache[c];
@@ -131,8 +136,9 @@ void BoxContainer::_resort() {
}
}
- if (refit_successful) //uf refit went well, break
+ if (refit_successful) { //uf refit went well, break
break;
+ }
}
/** Final pass, draw and stretch elements **/
@@ -156,17 +162,20 @@ void BoxContainer::_resort() {
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c || !c->is_visible_in_tree())
+ if (!c || !c->is_visible_in_tree()) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
+ }
_MinSizeCache &msc = min_size_cache[c];
- if (first)
+ if (first) {
first = false;
- else
+ } else {
ofs += sep;
+ }
int from = ofs;
int to = ofs + msc.final_size;
@@ -205,10 +214,12 @@ Size2 BoxContainer::get_minimum_size() const {
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c)
+ if (!c) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
+ }
if (!c->is_visible()) {
continue;
@@ -263,14 +274,16 @@ void BoxContainer::add_spacer(bool p_begin) {
Control *c = memnew(Control);
c->set_mouse_filter(MOUSE_FILTER_PASS); //allow spacer to pass mouse events
- if (vertical)
+ if (vertical) {
c->set_v_size_flags(SIZE_EXPAND_FILL);
- else
+ } else {
c->set_h_size_flags(SIZE_EXPAND_FILL);
+ }
add_child(c);
- if (p_begin)
+ if (p_begin) {
move_child(c, 0);
+ }
}
BoxContainer::BoxContainer(bool p_vertical) {
@@ -298,8 +311,9 @@ MarginContainer *VBoxContainer::add_margin_child(const String &p_label, Control
mc->add_theme_constant_override("margin_left", 0);
mc->add_child(p_control);
add_child(mc);
- if (p_expand)
+ if (p_expand) {
mc->set_v_size_flags(SIZE_EXPAND_FILL);
+ }
return mc;
}
diff --git a/scene/gui/button.cpp b/scene/gui/button.cpp
index e761b2bf40..e400801b66 100644
--- a/scene/gui/button.cpp
+++ b/scene/gui/button.cpp
@@ -35,21 +35,24 @@
Size2 Button::get_minimum_size() const {
Size2 minsize = get_theme_font("font")->get_string_size(xl_text);
- if (clip_text)
+ if (clip_text) {
minsize.width = 0;
+ }
if (!expand_icon) {
Ref<Texture2D> _icon;
- if (icon.is_null() && has_theme_icon("icon"))
+ if (icon.is_null() && has_theme_icon("icon")) {
_icon = Control::get_theme_icon("icon");
- else
+ } else {
_icon = icon;
+ }
if (!_icon.is_null()) {
minsize.height = MAX(minsize.height, _icon->get_height());
minsize.width += _icon->get_width();
- if (xl_text != "")
+ if (xl_text != "") {
minsize.width += get_theme_constant("hseparation");
+ }
}
}
@@ -78,23 +81,28 @@ void Button::_notification(int p_what) {
switch (get_draw_mode()) {
case DRAW_NORMAL: {
style = get_theme_stylebox("normal");
- if (!flat)
+ if (!flat) {
style->draw(ci, Rect2(Point2(0, 0), size));
+ }
color = get_theme_color("font_color");
- if (has_theme_color("icon_color_normal"))
+ if (has_theme_color("icon_color_normal")) {
color_icon = get_theme_color("icon_color_normal");
+ }
} break;
case DRAW_HOVER_PRESSED: {
if (has_theme_stylebox("hover_pressed") && has_theme_stylebox_override("hover_pressed")) {
style = get_theme_stylebox("hover_pressed");
- if (!flat)
+ if (!flat) {
style->draw(ci, Rect2(Point2(0, 0), size));
- if (has_theme_color("font_color_hover_pressed"))
+ }
+ if (has_theme_color("font_color_hover_pressed")) {
color = get_theme_color("font_color_hover_pressed");
- else
+ } else {
color = get_theme_color("font_color");
- if (has_theme_color("icon_color_hover_pressed"))
+ }
+ if (has_theme_color("icon_color_hover_pressed")) {
color_icon = get_theme_color("icon_color_hover_pressed");
+ }
break;
}
@@ -102,32 +110,39 @@ void Button::_notification(int p_what) {
}
case DRAW_PRESSED: {
style = get_theme_stylebox("pressed");
- if (!flat)
+ if (!flat) {
style->draw(ci, Rect2(Point2(0, 0), size));
- if (has_theme_color("font_color_pressed"))
+ }
+ if (has_theme_color("font_color_pressed")) {
color = get_theme_color("font_color_pressed");
- else
+ } else {
color = get_theme_color("font_color");
- if (has_theme_color("icon_color_pressed"))
+ }
+ if (has_theme_color("icon_color_pressed")) {
color_icon = get_theme_color("icon_color_pressed");
+ }
} break;
case DRAW_HOVER: {
style = get_theme_stylebox("hover");
- if (!flat)
+ if (!flat) {
style->draw(ci, Rect2(Point2(0, 0), size));
+ }
color = get_theme_color("font_color_hover");
- if (has_theme_color("icon_color_hover"))
+ if (has_theme_color("icon_color_hover")) {
color_icon = get_theme_color("icon_color_hover");
+ }
} break;
case DRAW_DISABLED: {
style = get_theme_stylebox("disabled");
- if (!flat)
+ if (!flat) {
style->draw(ci, Rect2(Point2(0, 0), size));
+ }
color = get_theme_color("font_color_disabled");
- if (has_theme_color("icon_color_disabled"))
+ if (has_theme_color("icon_color_disabled")) {
color_icon = get_theme_color("icon_color_disabled");
+ }
} break;
}
@@ -139,10 +154,11 @@ void Button::_notification(int p_what) {
Ref<Font> font = get_theme_font("font");
Ref<Texture2D> _icon;
- if (icon.is_null() && has_theme_icon("icon"))
+ if (icon.is_null() && has_theme_icon("icon")) {
_icon = Control::get_theme_icon("icon");
- else
+ } else {
_icon = icon;
+ }
Rect2 icon_region = Rect2();
if (!_icon.is_null()) {
@@ -159,8 +175,9 @@ void Button::_notification(int p_what) {
if (expand_icon) {
Size2 _size = get_size() - style->get_offset() * 2;
_size.width -= get_theme_constant("hseparation") + icon_ofs_region;
- if (!clip_text)
+ if (!clip_text) {
_size.width -= get_theme_font("font")->get_string_size(xl_text).width;
+ }
float icon_width = _icon->get_width() * _size.height / _icon->get_height();
float icon_height = _size.height;
@@ -196,8 +213,9 @@ void Button::_notification(int p_what) {
text_ofs.y += style->get_offset().y;
} break;
case ALIGN_CENTER: {
- if (text_ofs.x < 0)
+ if (text_ofs.x < 0) {
text_ofs.x = 0;
+ }
text_ofs += icon_ofs;
text_ofs += style->get_offset();
} break;
@@ -222,8 +240,9 @@ void Button::_notification(int p_what) {
}
void Button::set_text(const String &p_text) {
- if (text == p_text)
+ if (text == p_text) {
return;
+ }
text = p_text;
xl_text = tr(p_text);
update();
@@ -236,8 +255,9 @@ String Button::get_text() const {
}
void Button::set_icon(const Ref<Texture2D> &p_icon) {
- if (icon == p_icon)
+ if (icon == p_icon) {
return;
+ }
icon = p_icon;
update();
_change_notify("icon");
diff --git a/scene/gui/center_container.cpp b/scene/gui/center_container.cpp
index ff2b5ea17e..f8f9bec3d7 100644
--- a/scene/gui/center_container.cpp
+++ b/scene/gui/center_container.cpp
@@ -31,17 +31,21 @@
#include "center_container.h"
Size2 CenterContainer::get_minimum_size() const {
- if (use_top_left)
+ if (use_top_left) {
return Size2();
+ }
Size2 ms;
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c)
+ if (!c) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
- if (!c->is_visible())
+ }
+ if (!c->is_visible()) {
continue;
+ }
Size2 minsize = c->get_combined_minimum_size();
ms.width = MAX(ms.width, minsize.width);
ms.height = MAX(ms.height, minsize.height);
@@ -70,10 +74,12 @@ void CenterContainer::_notification(int p_what) {
Size2 size = get_size();
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c)
+ if (!c) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
+ }
Size2 minsize = c->get_combined_minimum_size();
Point2 ofs = use_top_left ? (-minsize * 0.5).floor() : ((size - minsize) / 2.0).floor();
diff --git a/scene/gui/check_box.cpp b/scene/gui/check_box.cpp
index 8681b9bda7..df6f38f65d 100644
--- a/scene/gui/check_box.cpp
+++ b/scene/gui/check_box.cpp
@@ -39,14 +39,18 @@ Size2 CheckBox::get_icon_size() const {
Ref<Texture2D> radio_unchecked = Control::get_theme_icon("radio_unchecked");
Size2 tex_size = Size2(0, 0);
- if (!checked.is_null())
+ if (!checked.is_null()) {
tex_size = Size2(checked->get_width(), checked->get_height());
- if (!unchecked.is_null())
+ }
+ if (!unchecked.is_null()) {
tex_size = Size2(MAX(tex_size.width, unchecked->get_width()), MAX(tex_size.height, unchecked->get_height()));
- if (!radio_checked.is_null())
+ }
+ if (!radio_checked.is_null()) {
tex_size = Size2(MAX(tex_size.width, radio_checked->get_width()), MAX(tex_size.height, radio_checked->get_height()));
- if (!radio_unchecked.is_null())
+ }
+ if (!radio_unchecked.is_null()) {
tex_size = Size2(MAX(tex_size.width, radio_unchecked->get_width()), MAX(tex_size.height, radio_unchecked->get_height()));
+ }
return tex_size;
}
@@ -77,10 +81,11 @@ void CheckBox::_notification(int p_what) {
ofs.x = sb->get_margin(MARGIN_LEFT);
ofs.y = int((get_size().height - get_icon_size().height) / 2) + get_theme_constant("check_vadjust");
- if (is_pressed())
+ if (is_pressed()) {
on->draw(ci, ofs);
- else
+ } else {
off->draw(ci, ofs);
+ }
}
}
diff --git a/scene/gui/check_button.cpp b/scene/gui/check_button.cpp
index 041a28a0be..1ddc730dd1 100644
--- a/scene/gui/check_button.cpp
+++ b/scene/gui/check_button.cpp
@@ -37,10 +37,12 @@ Size2 CheckButton::get_icon_size() const {
Ref<Texture2D> on = Control::get_theme_icon(is_disabled() ? "on_disabled" : "on");
Ref<Texture2D> off = Control::get_theme_icon(is_disabled() ? "off_disabled" : "off");
Size2 tex_size = Size2(0, 0);
- if (!on.is_null())
+ if (!on.is_null()) {
tex_size = Size2(on->get_width(), on->get_height());
- if (!off.is_null())
+ }
+ if (!off.is_null()) {
tex_size = Size2(MAX(tex_size.width, off->get_width()), MAX(tex_size.height, off->get_height()));
+ }
return tex_size;
}
@@ -49,8 +51,9 @@ Size2 CheckButton::get_minimum_size() const {
Size2 minsize = Button::get_minimum_size();
Size2 tex_size = get_icon_size();
minsize.width += tex_size.width;
- if (get_text().length() > 0)
+ if (get_text().length() > 0) {
minsize.width += get_theme_constant("hseparation");
+ }
Ref<StyleBox> sb = get_theme_stylebox("normal");
minsize.height = MAX(minsize.height, tex_size.height + sb->get_margin(MARGIN_TOP) + sb->get_margin(MARGIN_BOTTOM));
@@ -73,10 +76,11 @@ void CheckButton::_notification(int p_what) {
ofs.x = get_size().width - (tex_size.width + sb->get_margin(MARGIN_RIGHT));
ofs.y = (get_size().height - tex_size.height) / 2 + get_theme_constant("check_vadjust");
- if (is_pressed())
+ if (is_pressed()) {
on->draw(ci, ofs);
- else
+ } else {
off->draw(ci, ofs);
+ }
}
}
diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp
index f150028c47..88710289c7 100644
--- a/scene/gui/color_picker.cpp
+++ b/scene/gui/color_picker.cpp
@@ -65,17 +65,20 @@ void ColorPicker::_notification(int p_what) {
#endif
} break;
case NOTIFICATION_PARENTED: {
- for (int i = 0; i < 4; i++)
+ for (int i = 0; i < 4; i++) {
set_margin((Margin)i, get_theme_constant("margin"));
+ }
} break;
case NOTIFICATION_VISIBILITY_CHANGED: {
Popup *p = Object::cast_to<Popup>(get_parent());
- if (p)
+ if (p) {
p->set_size(Size2(get_combined_minimum_size().width + get_theme_constant("margin") * 2, get_combined_minimum_size().height + get_theme_constant("margin") * 2));
+ }
} break;
case NOTIFICATION_WM_CLOSE_REQUEST: {
- if (screen != nullptr && screen->is_visible())
+ if (screen != nullptr && screen->is_visible()) {
screen->hide();
+ }
} break;
}
}
@@ -89,11 +92,13 @@ void ColorPicker::_update_controls() {
const char *hsv[3] = { "H", "S", "V" };
if (hsv_mode_enabled) {
- for (int i = 0; i < 3; i++)
+ for (int i = 0; i < 3; i++) {
labels[i]->set_text(hsv[i]);
+ }
} else {
- for (int i = 0; i < 3; i++)
+ for (int i = 0; i < 3; i++) {
labels[i]->set_text(rgb[i]);
+ }
}
if (hsv_mode_enabled) {
@@ -127,8 +132,9 @@ void ColorPicker::_set_pick_color(const Color &p_color, bool p_update_sliders) {
last_hsv = color;
}
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
_update_color(p_update_sliders);
}
@@ -141,8 +147,9 @@ void ColorPicker::set_edit_alpha(bool p_show) {
edit_alpha = p_show;
_update_controls();
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
_update_color();
sample->update();
@@ -153,8 +160,9 @@ bool ColorPicker::is_editing_alpha() const {
}
void ColorPicker::_value_changed(double) {
- if (updating)
+ if (updating) {
return;
+ }
if (hsv_mode_enabled) {
color.set_hsv(scroll[0]->get_value() / 360.0,
@@ -172,16 +180,19 @@ void ColorPicker::_value_changed(double) {
}
void ColorPicker::_html_entered(const String &p_html) {
- if (updating || text_is_constructor || !c_text->is_visible())
+ if (updating || text_is_constructor || !c_text->is_visible()) {
return;
+ }
float last_alpha = color.a;
color = Color::html(p_html);
- if (!is_editing_alpha())
+ if (!is_editing_alpha()) {
color.a = last_alpha;
+ }
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
set_pick_color(color);
emit_signal("color_changed", color);
@@ -209,8 +220,9 @@ void ColorPicker::_update_color(bool p_update_sliders) {
if (raw_mode_enabled) {
scroll[i]->set_step(0.01);
scroll[i]->set_max(100);
- if (i == 3)
+ if (i == 3) {
scroll[i]->set_max(1);
+ }
scroll[i]->set_value(color.components[i]);
} else {
scroll[i]->set_step(1);
@@ -309,14 +321,17 @@ PackedColorArray ColorPicker::get_presets() const {
}
void ColorPicker::set_hsv_mode(bool p_enabled) {
- if (hsv_mode_enabled == p_enabled || raw_mode_enabled)
+ if (hsv_mode_enabled == p_enabled || raw_mode_enabled) {
return;
+ }
hsv_mode_enabled = p_enabled;
- if (btn_hsv->is_pressed() != p_enabled)
+ if (btn_hsv->is_pressed() != p_enabled) {
btn_hsv->set_pressed(p_enabled);
+ }
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
_update_controls();
_update_color();
@@ -327,14 +342,17 @@ bool ColorPicker::is_hsv_mode() const {
}
void ColorPicker::set_raw_mode(bool p_enabled) {
- if (raw_mode_enabled == p_enabled || hsv_mode_enabled)
+ if (raw_mode_enabled == p_enabled || hsv_mode_enabled) {
return;
+ }
raw_mode_enabled = p_enabled;
- if (btn_raw->is_pressed() != p_enabled)
+ if (btn_raw->is_pressed() != p_enabled) {
btn_raw->set_pressed(p_enabled);
+ }
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
_update_controls();
_update_color();
@@ -356,10 +374,11 @@ void ColorPicker::_update_text_value() {
bool visible = true;
if (text_is_constructor) {
String t = "Color(" + String::num(color.r) + ", " + String::num(color.g) + ", " + String::num(color.b);
- if (edit_alpha && color.a < 1)
+ if (edit_alpha && color.a < 1) {
t += ", " + String::num(color.a) + ")";
- else
+ } else {
t += ")";
+ }
c_text->set_text(t);
}
@@ -389,8 +408,9 @@ void ColorPicker::_sample_draw() {
}
void ColorPicker::_hsv_draw(int p_which, Control *c) {
- if (!c)
+ if (!c) {
return;
+ }
if (p_which == 0) {
Vector<Point2> points;
points.push_back(Vector2());
@@ -446,8 +466,9 @@ void ColorPicker::_uv_input(const Ref<InputEvent> &p_event) {
last_hsv = color;
set_pick_color(color);
_update_color();
- if (!deferred_mode_enabled)
+ if (!deferred_mode_enabled) {
emit_signal("color_changed", color);
+ }
} else if (deferred_mode_enabled && !bev->is_pressed() && bev->get_button_index() == BUTTON_LEFT) {
emit_signal("color_changed", color);
changing_color = false;
@@ -459,8 +480,9 @@ void ColorPicker::_uv_input(const Ref<InputEvent> &p_event) {
Ref<InputEventMouseMotion> mev = p_event;
if (mev.is_valid()) {
- if (!changing_color)
+ if (!changing_color) {
return;
+ }
float x = CLAMP((float)mev->get_position().x, 0, uv_edit->get_size().width);
float y = CLAMP((float)mev->get_position().y, 0, uv_edit->get_size().height);
s = x / uv_edit->get_size().width;
@@ -469,8 +491,9 @@ void ColorPicker::_uv_input(const Ref<InputEvent> &p_event) {
last_hsv = color;
set_pick_color(color);
_update_color();
- if (!deferred_mode_enabled)
+ if (!deferred_mode_enabled) {
emit_signal("color_changed", color);
+ }
}
}
@@ -489,25 +512,28 @@ void ColorPicker::_w_input(const Ref<InputEvent> &p_event) {
last_hsv = color;
set_pick_color(color);
_update_color();
- if (!deferred_mode_enabled)
+ if (!deferred_mode_enabled) {
emit_signal("color_changed", color);
- else if (!bev->is_pressed() && bev->get_button_index() == BUTTON_LEFT)
+ } else if (!bev->is_pressed() && bev->get_button_index() == BUTTON_LEFT) {
emit_signal("color_changed", color);
+ }
}
Ref<InputEventMouseMotion> mev = p_event;
if (mev.is_valid()) {
- if (!changing_color)
+ if (!changing_color) {
return;
+ }
float y = CLAMP((float)mev->get_position().y, 0, w_edit->get_size().height);
h = y / w_edit->get_size().height;
color.set_hsv(h, s, v, color.a);
last_hsv = color;
set_pick_color(color);
_update_color();
- if (!deferred_mode_enabled)
+ if (!deferred_mode_enabled) {
emit_signal("color_changed", color);
+ }
}
}
@@ -543,8 +569,9 @@ void ColorPicker::_preset_input(const Ref<InputEvent> &p_event) {
if (preset->get_size().x != 0) {
index /= preset->get_size().x;
}
- if (index < 0 || index >= presets.size())
+ if (index < 0 || index >= presets.size()) {
return;
+ }
preset->set_tooltip(vformat(RTR("Color: #%s\nLMB: Set color\nRMB: Remove preset"), presets[index].to_html(presets[index].a < 1)));
}
}
@@ -559,8 +586,9 @@ void ColorPicker::_screen_input(const Ref<InputEvent> &p_event) {
Ref<InputEventMouseMotion> mev = p_event;
if (mev.is_valid()) {
Viewport *r = get_tree()->get_root();
- if (!r->get_visible_rect().has_point(Point2(mev->get_global_position().x, mev->get_global_position().y)))
+ if (!r->get_visible_rect().has_point(Point2(mev->get_global_position().x, mev->get_global_position().y))) {
return;
+ }
Ref<Image> img = r->get_texture()->get_data();
if (img.is_valid() && !img->empty()) {
@@ -615,15 +643,17 @@ void ColorPicker::_focus_enter() {
void ColorPicker::_focus_exit() {
for (int i = 0; i < 4; i++) {
- if (!values[i]->get_line_edit()->get_menu()->is_visible())
+ if (!values[i]->get_line_edit()->get_menu()->is_visible()) {
values[i]->get_line_edit()->select(0, 0);
+ }
}
c_text->select(0, 0);
}
void ColorPicker::_html_focus_exit() {
- if (c_text->get_menu()->is_visible())
+ if (c_text->get_menu()->is_visible()) {
return;
+ }
_html_entered(c_text->get_text());
_focus_exit();
}
@@ -889,8 +919,9 @@ void ColorPickerButton::_notification(int p_what) {
}
} break;
case NOTIFICATION_WM_CLOSE_REQUEST: {
- if (popup)
+ if (popup) {
popup->hide();
+ }
} break;
}
diff --git a/scene/gui/container.cpp b/scene/gui/container.cpp
index 5bde293648..18a84ce348 100644
--- a/scene/gui/container.cpp
+++ b/scene/gui/container.cpp
@@ -43,8 +43,9 @@ void Container::add_child_notify(Node *p_child) {
Control::add_child_notify(p_child);
Control *control = Object::cast_to<Control>(p_child);
- if (!control)
+ if (!control) {
return;
+ }
control->connect("size_flags_changed", callable_mp(this, &Container::queue_sort));
control->connect("minimum_size_changed", callable_mp(this, &Container::_child_minsize_changed));
@@ -57,8 +58,9 @@ void Container::add_child_notify(Node *p_child) {
void Container::move_child_notify(Node *p_child) {
Control::move_child_notify(p_child);
- if (!Object::cast_to<Control>(p_child))
+ if (!Object::cast_to<Control>(p_child)) {
return;
+ }
minimum_size_changed();
queue_sort();
@@ -68,8 +70,9 @@ void Container::remove_child_notify(Node *p_child) {
Control::remove_child_notify(p_child);
Control *control = Object::cast_to<Control>(p_child);
- if (!control)
+ if (!control) {
return;
+ }
control->disconnect("size_flags_changed", callable_mp(this, &Container::queue_sort));
control->disconnect("minimum_size_changed", callable_mp(this, &Container::_child_minsize_changed));
@@ -80,8 +83,9 @@ void Container::remove_child_notify(Node *p_child) {
}
void Container::_sort_children() {
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
notification(NOTIFICATION_SORT_CHILDREN);
emit_signal(SceneStringNames::get_singleton()->sort_children);
@@ -117,8 +121,9 @@ void Container::fit_child_in_rect(Control *p_child, const Rect2 &p_rect) {
}
}
- for (int i = 0; i < 4; i++)
+ for (int i = 0; i < 4; i++) {
p_child->set_anchor(Margin(i), ANCHOR_BEGIN);
+ }
p_child->set_position(r.position);
p_child->set_size(r.size);
@@ -127,11 +132,13 @@ void Container::fit_child_in_rect(Control *p_child, const Rect2 &p_rect) {
}
void Container::queue_sort() {
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
- if (pending_sort)
+ if (pending_sort) {
return;
+ }
MessageQueue::get_singleton()->push_call(this, "_sort_children");
pending_sort = true;
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp
index 02be8f23fb..96aaec6ae9 100644
--- a/scene/gui/control.cpp
+++ b/scene/gui/control.cpp
@@ -160,8 +160,9 @@ Size2 Control::_edit_get_minimum_size() const {
#endif
void Control::set_custom_minimum_size(const Size2 &p_custom) {
- if (p_custom == data.custom_minimum_size)
+ if (p_custom == data.custom_minimum_size) {
return;
+ }
data.custom_minimum_size = p_custom;
minimum_size_changed();
}
@@ -176,14 +177,16 @@ void Control::_update_minimum_size_cache() {
minsize.y = MAX(minsize.y, data.custom_minimum_size.y);
bool size_changed = false;
- if (data.minimum_size_cache != minsize)
+ if (data.minimum_size_cache != minsize) {
size_changed = true;
+ }
data.minimum_size_cache = minsize;
data.minimum_size_valid = true;
- if (size_changed)
+ if (size_changed) {
minimum_size_changed();
+ }
}
Size2 Control::get_combined_minimum_size() const {
@@ -245,8 +248,9 @@ bool Control::_set(const StringName &p_name, const Variant &p_value) {
String dname = name.get_slicec('/', 1);
data.constant_override.erase(dname);
notification(NOTIFICATION_THEME_CHANGED);
- } else
+ } else {
return false;
+ }
} else {
if (name.begins_with("custom_icons/")) {
@@ -267,15 +271,17 @@ bool Control::_set(const StringName &p_name, const Variant &p_value) {
} else if (name.begins_with("custom_constants/")) {
String dname = name.get_slicec('/', 1);
add_theme_constant_override(dname, p_value);
- } else
+ } else {
return false;
+ }
}
return true;
}
void Control::_update_minimum_size() {
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
Size2 minsize = get_combined_minimum_size();
if (minsize.x > data.size_cache.x ||
@@ -321,8 +327,9 @@ bool Control::_get(const StringName &p_name, Variant &r_ret) const {
String name = sname.get_slicec('/', 1);
r_ret = data.constant_override.has(name) ? Variant(data.constant_override[name]) : Variant();
- } else
+ } else {
return false;
+ }
return true;
}
@@ -343,8 +350,9 @@ void Control::_get_property_list(List<PropertyInfo> *p_list) const {
theme->get_icon_list(get_class_name(), &names);
for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
uint32_t hint = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
- if (data.icon_override.has(E->get()))
+ if (data.icon_override.has(E->get())) {
hint |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
+ }
p_list->push_back(PropertyInfo(Variant::OBJECT, "custom_icons/" + E->get(), PROPERTY_HINT_RESOURCE_TYPE, "Texture2D", hint));
}
@@ -354,8 +362,9 @@ void Control::_get_property_list(List<PropertyInfo> *p_list) const {
theme->get_shader_list(get_class_name(), &names);
for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
uint32_t hint = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
- if (data.shader_override.has(E->get()))
+ if (data.shader_override.has(E->get())) {
hint |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
+ }
p_list->push_back(PropertyInfo(Variant::OBJECT, "custom_shaders/" + E->get(), PROPERTY_HINT_RESOURCE_TYPE, "Shader,VisualShader", hint));
}
@@ -365,8 +374,9 @@ void Control::_get_property_list(List<PropertyInfo> *p_list) const {
theme->get_stylebox_list(get_class_name(), &names);
for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
uint32_t hint = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
- if (data.style_override.has(E->get()))
+ if (data.style_override.has(E->get())) {
hint |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
+ }
p_list->push_back(PropertyInfo(Variant::OBJECT, "custom_styles/" + E->get(), PROPERTY_HINT_RESOURCE_TYPE, "StyleBox", hint));
}
@@ -376,8 +386,9 @@ void Control::_get_property_list(List<PropertyInfo> *p_list) const {
theme->get_font_list(get_class_name(), &names);
for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
uint32_t hint = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
- if (data.font_override.has(E->get()))
+ if (data.font_override.has(E->get())) {
hint |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
+ }
p_list->push_back(PropertyInfo(Variant::OBJECT, "custom_fonts/" + E->get(), PROPERTY_HINT_RESOURCE_TYPE, "Font", hint));
}
@@ -387,8 +398,9 @@ void Control::_get_property_list(List<PropertyInfo> *p_list) const {
theme->get_color_list(get_class_name(), &names);
for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
uint32_t hint = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
- if (data.color_override.has(E->get()))
+ if (data.color_override.has(E->get())) {
hint |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
+ }
p_list->push_back(PropertyInfo(Variant::COLOR, "custom_colors/" + E->get(), PROPERTY_HINT_NONE, "", hint));
}
@@ -398,8 +410,9 @@ void Control::_get_property_list(List<PropertyInfo> *p_list) const {
theme->get_constant_list(get_class_name(), &names);
for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
uint32_t hint = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
- if (data.constant_override.has(E->get()))
+ if (data.constant_override.has(E->get())) {
hint |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
+ }
p_list->push_back(PropertyInfo(Variant::INT, "custom_constants/" + E->get(), PROPERTY_HINT_RANGE, "-16384,16384", hint));
}
@@ -474,8 +487,9 @@ void Control::_notification(int p_notification) {
while (parent) {
parent = parent->get_parent();
- if (!parent)
+ if (!parent) {
break;
+ }
CanvasItem *ci = Object::cast_to<CanvasItem>(parent);
if (ci && ci->is_set_as_toplevel()) {
@@ -534,8 +548,9 @@ void Control::_notification(int p_notification) {
case NOTIFICATION_MOVED_IN_PARENT: {
// some parents need to know the order of the childrens to draw (like TabContainer)
// update if necessary
- if (data.parent)
+ if (data.parent) {
data.parent->update();
+ }
update();
if (data.RI) {
@@ -574,8 +589,9 @@ void Control::_notification(int p_notification) {
} break;
case NOTIFICATION_VISIBILITY_CHANGED: {
if (!is_visible_in_tree()) {
- if (get_viewport() != nullptr)
+ if (get_viewport() != nullptr) {
get_viewport()->_gui_hid_control(this);
+ }
//remove key focus
@@ -613,10 +629,11 @@ bool Control::has_point(const Point2 &p_point) const {
}
void Control::set_drag_forwarding(Control *p_target) {
- if (p_target)
+ if (p_target) {
data.drag_owner = p_target->get_instance_id();
- else
+ } else {
data.drag_owner = ObjectID();
+ }
}
Variant Control::get_drag_data(const Point2 &p_point) {
@@ -633,8 +650,9 @@ Variant Control::get_drag_data(const Point2 &p_point) {
const Variant *p = &v;
Callable::CallError ce;
Variant ret = get_script_instance()->call(SceneStringNames::get_singleton()->get_drag_data, &p, 1, ce);
- if (ce.error == Callable::CallError::CALL_OK)
+ if (ce.error == Callable::CallError::CALL_OK) {
return ret;
+ }
}
return Variant();
@@ -654,8 +672,9 @@ bool Control::can_drop_data(const Point2 &p_point, const Variant &p_data) const
const Variant *p[2] = { &v, &p_data };
Callable::CallError ce;
Variant ret = get_script_instance()->call(SceneStringNames::get_singleton()->can_drop_data, p, 2, ce);
- if (ce.error == Callable::CallError::CALL_OK)
+ if (ce.error == Callable::CallError::CALL_OK) {
return ret;
+ }
}
return Variant();
@@ -676,8 +695,9 @@ void Control::drop_data(const Point2 &p_point, const Variant &p_data) {
const Variant *p[2] = { &v, &p_data };
Callable::CallError ce;
Variant ret = get_script_instance()->call(SceneStringNames::get_singleton()->drop_data, p, 2, ce);
- if (ce.error == Callable::CallError::CALL_OK)
+ if (ce.error == Callable::CallError::CALL_OK) {
return;
+ }
}
}
@@ -699,8 +719,9 @@ Size2 Control::get_minimum_size() const {
if (si) {
Callable::CallError ce;
Variant s = si->call(SceneStringNames::get_singleton()->_get_minimum_size, nullptr, 0, ce);
- if (ce.error == Callable::CallError::CALL_OK)
+ if (ce.error == Callable::CallError::CALL_OK) {
return s;
+ }
}
return Size2();
}
@@ -793,8 +814,9 @@ bool Control::_has_theme_item(Control *p_theme_owner, Window *p_theme_owner_wind
Ref<Texture2D> Control::get_theme_icon(const StringName &p_name, const StringName &p_type) const {
if (p_type == StringName() || p_type == get_class_name()) {
const Ref<Texture2D> *tex = data.icon_override.getptr(p_name);
- if (tex)
+ if (tex) {
return *tex;
+ }
}
StringName type = p_type ? p_type : get_class_name();
@@ -821,8 +843,9 @@ Ref<Texture2D> Control::get_icons(Control *p_theme_owner, Window *p_theme_owner_
Ref<Shader> Control::get_theme_shader(const StringName &p_name, const StringName &p_type) const {
if (p_type == StringName() || p_type == get_class_name()) {
const Ref<Shader> *sdr = data.shader_override.getptr(p_name);
- if (sdr)
+ if (sdr) {
return *sdr;
+ }
}
StringName type = p_type ? p_type : get_class_name();
@@ -849,8 +872,9 @@ Ref<Shader> Control::get_shaders(Control *p_theme_owner, Window *p_theme_owner_w
Ref<StyleBox> Control::get_theme_stylebox(const StringName &p_name, const StringName &p_type) const {
if (p_type == StringName() || p_type == get_class_name()) {
const Ref<StyleBox> *style = data.style_override.getptr(p_name);
- if (style)
+ if (style) {
return *style;
+ }
}
StringName type = p_type ? p_type : get_class_name();
@@ -877,8 +901,9 @@ Ref<StyleBox> Control::get_styleboxs(Control *p_theme_owner, Window *p_theme_own
Ref<Font> Control::get_theme_font(const StringName &p_name, const StringName &p_type) const {
if (p_type == StringName() || p_type == get_class_name()) {
const Ref<Font> *font = data.font_override.getptr(p_name);
- if (font)
+ if (font) {
return *font;
+ }
}
StringName type = p_type ? p_type : get_class_name();
@@ -905,8 +930,9 @@ Ref<Font> Control::get_fonts(Control *p_theme_owner, Window *p_theme_owner_windo
Color Control::get_theme_color(const StringName &p_name, const StringName &p_type) const {
if (p_type == StringName() || p_type == get_class_name()) {
const Color *color = data.color_override.getptr(p_name);
- if (color)
+ if (color) {
return *color;
+ }
}
StringName type = p_type ? p_type : get_class_name();
@@ -932,8 +958,9 @@ Color Control::get_colors(Control *p_theme_owner, Window *p_theme_owner_window,
int Control::get_theme_constant(const StringName &p_name, const StringName &p_type) const {
if (p_type == StringName() || p_type == get_class_name()) {
const int *constant = data.constant_override.getptr(p_name);
- if (constant)
+ if (constant) {
return *constant;
+ }
}
StringName type = p_type ? p_type : get_class_name();
@@ -988,8 +1015,9 @@ bool Control::has_theme_constant_override(const StringName &p_name) const {
bool Control::has_theme_icon(const StringName &p_name, const StringName &p_type) const {
if (p_type == StringName() || p_type == get_class_name()) {
- if (has_theme_icon_override(p_name))
+ if (has_theme_icon_override(p_name)) {
return true;
+ }
}
StringName type = p_type ? p_type : get_class_name();
@@ -1012,8 +1040,9 @@ bool Control::has_icons(Control *p_theme_owner, Window *p_theme_owner_window, co
bool Control::has_theme_shader(const StringName &p_name, const StringName &p_type) const {
if (p_type == StringName() || p_type == get_class_name()) {
- if (has_theme_shader_override(p_name))
+ if (has_theme_shader_override(p_name)) {
return true;
+ }
}
StringName type = p_type ? p_type : get_class_name();
@@ -1036,8 +1065,9 @@ bool Control::has_shaders(Control *p_theme_owner, Window *p_theme_owner_window,
bool Control::has_theme_stylebox(const StringName &p_name, const StringName &p_type) const {
if (p_type == StringName() || p_type == get_class_name()) {
- if (has_theme_stylebox_override(p_name))
+ if (has_theme_stylebox_override(p_name)) {
return true;
+ }
}
StringName type = p_type ? p_type : get_class_name();
@@ -1060,8 +1090,9 @@ bool Control::has_styleboxs(Control *p_theme_owner, Window *p_theme_owner_window
bool Control::has_theme_font(const StringName &p_name, const StringName &p_type) const {
if (p_type == StringName() || p_type == get_class_name()) {
- if (has_theme_font_override(p_name))
+ if (has_theme_font_override(p_name)) {
return true;
+ }
}
StringName type = p_type ? p_type : get_class_name();
@@ -1084,8 +1115,9 @@ bool Control::has_fonts(Control *p_theme_owner, Window *p_theme_owner_window, co
bool Control::has_theme_color(const StringName &p_name, const StringName &p_type) const {
if (p_type == StringName() || p_type == get_class_name()) {
- if (has_theme_color_override(p_name))
+ if (has_theme_color_override(p_name)) {
return true;
+ }
}
StringName type = p_type ? p_type : get_class_name();
@@ -1108,8 +1140,9 @@ bool Control::has_colors(Control *p_theme_owner, Window *p_theme_owner_window, c
bool Control::has_theme_constant(const StringName &p_name, const StringName &p_type) const {
if (p_type == StringName() || p_type == get_class_name()) {
- if (has_theme_constant_override(p_name))
+ if (has_theme_constant_override(p_name)) {
return true;
+ }
}
StringName type = p_type ? p_type : get_class_name();
@@ -1131,8 +1164,9 @@ bool Control::has_constants(Control *p_theme_owner, Window *p_theme_owner_window
}
Rect2 Control::get_parent_anchorable_rect() const {
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return Rect2();
+ }
Rect2 parent_rect;
if (data.parent_canvas_item) {
@@ -1623,10 +1657,12 @@ void Control::_set_size(const Size2 &p_size) {
void Control::set_size(const Size2 &p_size, bool p_keep_margins) {
Size2 new_size = p_size;
Size2 min = get_combined_minimum_size();
- if (new_size.x < min.x)
+ if (new_size.x < min.x) {
new_size.x = min.x;
- if (new_size.y < min.y)
+ }
+ if (new_size.y < min.y) {
new_size.y = min.y;
+ }
if (p_keep_margins) {
_compute_anchors(Rect2(data.pos_cache, new_size), data.margin, data.anchor);
@@ -1761,15 +1797,17 @@ void Control::add_theme_constant_override(const StringName &p_name, int p_consta
void Control::set_focus_mode(FocusMode p_focus_mode) {
ERR_FAIL_INDEX((int)p_focus_mode, 3);
- if (is_inside_tree() && p_focus_mode == FOCUS_NONE && data.focus_mode != FOCUS_NONE && has_focus())
+ if (is_inside_tree() && p_focus_mode == FOCUS_NONE && data.focus_mode != FOCUS_NONE && has_focus()) {
release_focus();
+ }
data.focus_mode = p_focus_mode;
}
static Control *_next_control(Control *p_from) {
- if (p_from->is_set_as_toplevel())
+ if (p_from->is_set_as_toplevel()) {
return nullptr; // can't go above
+ }
Control *parent = Object::cast_to<Control>(p_from->get_parent());
@@ -1781,8 +1819,9 @@ static Control *_next_control(Control *p_from) {
ERR_FAIL_INDEX_V(next, parent->get_child_count(), nullptr);
for (int i = (next + 1); i < parent->get_child_count(); i++) {
Control *c = Object::cast_to<Control>(parent->get_child(i));
- if (!c || !c->is_visible_in_tree() || c->is_set_as_toplevel())
+ if (!c || !c->is_visible_in_tree() || c->is_set_as_toplevel()) {
continue;
+ }
return c;
}
@@ -1806,8 +1845,9 @@ Control *Control::find_next_valid_focus() const {
} else {
return nullptr;
}
- if (c->is_visible() && c->get_focus_mode() != FOCUS_NONE)
+ if (c->is_visible() && c->get_focus_mode() != FOCUS_NONE) {
return c;
+ }
}
// find next child
@@ -1835,22 +1875,26 @@ Control *Control::find_next_valid_focus() const {
if (!next_child) {
next_child = const_cast<Control *>(this);
while (next_child) {
- if (next_child->data.RI)
+ if (next_child->data.RI) {
break;
+ }
next_child = next_child->get_parent_control();
}
}
}
}
- if (next_child == this) // no next control->
+ if (next_child == this) { // no next control->
return (get_focus_mode() == FOCUS_ALL) ? next_child : nullptr;
+ }
if (next_child) {
- if (next_child->get_focus_mode() == FOCUS_ALL)
+ if (next_child->get_focus_mode() == FOCUS_ALL) {
return next_child;
+ }
from = next_child;
- } else
+ } else {
break;
+ }
}
return nullptr;
@@ -1860,15 +1904,17 @@ static Control *_prev_control(Control *p_from) {
Control *child = nullptr;
for (int i = p_from->get_child_count() - 1; i >= 0; i--) {
Control *c = Object::cast_to<Control>(p_from->get_child(i));
- if (!c || !c->is_visible_in_tree() || c->is_set_as_toplevel())
+ if (!c || !c->is_visible_in_tree() || c->is_set_as_toplevel()) {
continue;
+ }
child = c;
break;
}
- if (!child)
+ if (!child) {
return p_from;
+ }
//no prev in parent, try the same in parent
return _prev_control(child);
@@ -1889,8 +1935,9 @@ Control *Control::find_prev_valid_focus() const {
} else {
return nullptr;
}
- if (c->is_visible() && c->get_focus_mode() != FOCUS_NONE)
+ if (c->is_visible() && c->get_focus_mode() != FOCUS_NONE) {
return c;
+ }
}
// find prev child
@@ -1921,11 +1968,13 @@ Control *Control::find_prev_valid_focus() const {
}
}
- if (prev_child == this) // no prev control->
+ if (prev_child == this) { // no prev control->
return (get_focus_mode() == FOCUS_ALL) ? prev_child : nullptr;
+ }
- if (prev_child->get_focus_mode() == FOCUS_ALL)
+ if (prev_child->get_focus_mode() == FOCUS_ALL) {
return prev_child;
+ }
from = prev_child;
}
@@ -1955,8 +2004,9 @@ void Control::grab_focus() {
void Control::release_focus() {
ERR_FAIL_COND(!is_inside_tree());
- if (!has_focus())
+ if (!has_focus()) {
return;
+ }
get_viewport()->_gui_remove_focus();
update();
@@ -1969,13 +2019,15 @@ bool Control::is_toplevel_control() const {
void Control::_propagate_theme_changed(Node *p_at, Control *p_owner, Window *p_owner_window, bool p_assign) {
Control *c = Object::cast_to<Control>(p_at);
- if (c && c != p_owner && c->data.theme.is_valid()) // has a theme, this can't be propagated
+ if (c && c != p_owner && c->data.theme.is_valid()) { // has a theme, this can't be propagated
return;
+ }
Window *w = c == nullptr ? Object::cast_to<Window>(p_at) : nullptr;
- if (w && w != p_owner_window && w->theme.is_valid()) // has a theme, this can't be propagated
+ if (w && w != p_owner_window && w->theme.is_valid()) { // has a theme, this can't be propagated
return;
+ }
for (int i = 0; i < p_at->get_child_count(); i++) {
CanvasItem *child = Object::cast_to<CanvasItem>(p_at->get_child(i));
@@ -2013,8 +2065,9 @@ void Control::_theme_changed() {
}
void Control::set_theme(const Ref<Theme> &p_theme) {
- if (data.theme == p_theme)
+ if (data.theme == p_theme) {
return;
+ }
if (data.theme.is_valid()) {
data.theme->disconnect("changed", callable_mp(this, &Control::_theme_changed));
@@ -2046,8 +2099,9 @@ void Control::set_theme(const Ref<Theme> &p_theme) {
}
void Control::accept_event() {
- if (is_inside_tree())
+ if (is_inside_tree()) {
get_viewport()->_gui_accept_event();
+ }
}
Ref<Theme> Control::get_theme() const {
@@ -2125,8 +2179,9 @@ NodePath Control::get_focus_previous() const {
Control *Control::_get_focus_neighbour(Margin p_margin, int p_count) {
ERR_FAIL_INDEX_V((int)p_margin, 4, nullptr);
- if (p_count >= MAX_NEIGHBOUR_SEARCH_COUNT)
+ if (p_count >= MAX_NEIGHBOUR_SEARCH_COUNT) {
return nullptr;
+ }
if (!data.focus_neighbour[p_margin].is_empty()) {
Control *c = nullptr;
Node *n = get_node(data.focus_neighbour[p_margin]);
@@ -2137,12 +2192,15 @@ Control *Control::_get_focus_neighbour(Margin p_margin, int p_count) {
return nullptr;
}
bool valid = true;
- if (!c->is_visible())
+ if (!c->is_visible()) {
valid = false;
- if (c->get_focus_mode() == FOCUS_NONE)
+ }
+ if (c->get_focus_mode() == FOCUS_NONE) {
valid = false;
- if (valid)
+ }
+ if (valid) {
return c;
+ }
c = c->_get_focus_neighbour(p_margin, p_count + 1);
return c;
@@ -2173,8 +2231,9 @@ Control *Control::_get_focus_neighbour(Margin p_margin, int p_count) {
for (int i = 0; i < 4; i++) {
float d = vdir.dot(points[i]);
- if (d > maxd)
+ if (d > maxd) {
maxd = d;
+ }
}
Node *base = this;
@@ -2182,14 +2241,16 @@ Control *Control::_get_focus_neighbour(Margin p_margin, int p_count) {
while (base) {
Control *c = Object::cast_to<Control>(base);
if (c) {
- if (c->data.RI)
+ if (c->data.RI) {
break;
+ }
}
base = base->get_parent();
}
- if (!base)
+ if (!base) {
return nullptr;
+ }
_window_find_focus_neighbour(vdir, base, points, maxd, dist, &result);
@@ -2197,8 +2258,9 @@ Control *Control::_get_focus_neighbour(Margin p_margin, int p_count) {
}
void Control::_window_find_focus_neighbour(const Vector2 &p_dir, Node *p_at, const Point2 *p_points, float p_min, float &r_closest_dist, Control **r_closest) {
- if (Object::cast_to<Viewport>(p_at))
+ if (Object::cast_to<Viewport>(p_at)) {
return; //bye
+ }
Control *c = Object::cast_to<Control>(p_at);
@@ -2216,8 +2278,9 @@ void Control::_window_find_focus_neighbour(const Vector2 &p_dir, Node *p_at, con
for (int i = 0; i < 4; i++) {
float d = p_dir.dot(points[i]);
- if (d < min)
+ if (d < min) {
min = d;
+ }
}
if (min > (p_min - CMP_EPSILON)) {
@@ -2244,15 +2307,17 @@ void Control::_window_find_focus_neighbour(const Vector2 &p_dir, Node *p_at, con
for (int i = 0; i < p_at->get_child_count(); i++) {
Node *child = p_at->get_child(i);
Control *childc = Object::cast_to<Control>(child);
- if (childc && childc->data.RI)
+ if (childc && childc->data.RI) {
continue; //subwindow, ignore
+ }
_window_find_focus_neighbour(p_dir, p_at->get_child(i), p_points, p_min, r_closest_dist, r_closest);
}
}
void Control::set_h_size_flags(int p_flags) {
- if (data.h_size_flags == p_flags)
+ if (data.h_size_flags == p_flags) {
return;
+ }
data.h_size_flags = p_flags;
emit_signal(SceneStringNames::get_singleton()->size_flags_changed);
}
@@ -2262,15 +2327,17 @@ int Control::get_h_size_flags() const {
}
void Control::set_v_size_flags(int p_flags) {
- if (data.v_size_flags == p_flags)
+ if (data.v_size_flags == p_flags) {
return;
+ }
data.v_size_flags = p_flags;
emit_signal(SceneStringNames::get_singleton()->size_flags_changed);
}
void Control::set_stretch_ratio(float p_ratio) {
- if (data.expand == p_ratio)
+ if (data.expand == p_ratio) {
return;
+ }
data.expand = p_ratio;
emit_signal(SceneStringNames::get_singleton()->size_flags_changed);
@@ -2287,16 +2354,18 @@ void Control::grab_click_focus() {
}
void Control::minimum_size_changed() {
- if (!is_inside_tree() || data.block_minimum_size_adjust)
+ if (!is_inside_tree() || data.block_minimum_size_adjust) {
return;
+ }
Control *invalidate = this;
//invalidate cache upwards
while (invalidate && invalidate->data.minimum_size_valid) {
invalidate->data.minimum_size_valid = false;
- if (invalidate->is_set_as_toplevel())
+ if (invalidate->is_set_as_toplevel()) {
break; // do not go further up
+ }
if (!invalidate->data.parent && get_parent()) {
Window *parent_window = Object::cast_to<Window>(get_parent());
if (parent_window && parent_window->is_wrapping_controls()) {
@@ -2306,11 +2375,13 @@ void Control::minimum_size_changed() {
invalidate = invalidate->data.parent;
}
- if (!is_visible_in_tree())
+ if (!is_visible_in_tree()) {
return;
+ }
- if (data.updating_last_minimum_size)
+ if (data.updating_last_minimum_size) {
return;
+ }
data.updating_last_minimum_size = true;
@@ -2394,10 +2465,12 @@ Vector2 Control::get_pivot_offset() const {
void Control::set_scale(const Vector2 &p_scale) {
data.scale = p_scale;
// Avoid having 0 scale values, can lead to errors in physics and rendering.
- if (data.scale.x == 0)
+ if (data.scale.x == 0) {
data.scale.x = CMP_EPSILON;
- if (data.scale.y == 0)
+ }
+ if (data.scale.y == 0) {
data.scale.y = CMP_EPSILON;
+ }
update();
_notify_transform();
}
@@ -2415,8 +2488,9 @@ Control *Control::get_root_parent_control() const {
if (c) {
root = c;
- if (c->data.RI || c->is_toplevel_control())
+ if (c->data.RI || c->is_toplevel_control()) {
break;
+ }
}
ci = ci->get_parent_item();
diff --git a/scene/gui/control.h b/scene/gui/control.h
index 5a4c64492b..10d6ad168f 100644
--- a/scene/gui/control.h
+++ b/scene/gui/control.h
@@ -132,8 +132,9 @@ public:
private:
struct CComparator {
bool operator()(const Control *p_a, const Control *p_b) const {
- if (p_a->get_canvas_layer() == p_b->get_canvas_layer())
+ if (p_a->get_canvas_layer() == p_b->get_canvas_layer()) {
return p_b->is_greater_than(p_a);
+ }
return p_a->get_canvas_layer() < p_b->get_canvas_layer();
}
diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp
index 37d6784e35..c6897fc684 100644
--- a/scene/gui/dialogs.cpp
+++ b/scene/gui/dialogs.cpp
@@ -100,8 +100,9 @@ void AcceptDialog::_text_entered(const String &p_text) {
}
void AcceptDialog::_ok_pressed() {
- if (hide_on_ok)
+ if (hide_on_ok) {
set_visible(false);
+ }
ok_pressed();
emit_signal("confirmed");
}
@@ -155,8 +156,9 @@ bool AcceptDialog::has_autowrap() {
void AcceptDialog::register_text_enter(Node *p_line_edit) {
ERR_FAIL_NULL(p_line_edit);
LineEdit *line_edit = Object::cast_to<LineEdit>(p_line_edit);
- if (line_edit)
+ if (line_edit) {
line_edit->connect("text_entered", callable_mp(this, &AcceptDialog::_text_entered));
+ }
}
void AcceptDialog::_update_child_rects() {
@@ -173,11 +175,13 @@ void AcceptDialog::_update_child_rects() {
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c)
+ if (!c) {
continue;
+ }
- if (c == hbc || c == label || c == bg || c->is_set_as_toplevel())
+ if (c == hbc || c == label || c == bg || c->is_set_as_toplevel()) {
continue;
+ }
c->set_position(cpos);
c->set_size(csize);
@@ -199,11 +203,13 @@ Size2 AcceptDialog::_get_contents_minimum_size() const {
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c)
+ if (!c) {
continue;
+ }
- if (c == hbc || c == label || c->is_set_as_toplevel())
+ if (c == hbc || c == label || c->is_set_as_toplevel()) {
continue;
+ }
Size2 cminsize = c->get_combined_minimum_size();
minsize.x = MAX(cminsize.x, minsize.x);
@@ -247,8 +253,9 @@ Button *AcceptDialog::add_button(const String &p_text, bool p_right, const Strin
Button *AcceptDialog::add_cancel(const String &p_cancel) {
String c = p_cancel;
- if (p_cancel == "")
+ if (p_cancel == "") {
c = RTR("Cancel");
+ }
Button *b = swap_ok_cancel ? add_button(c, true) : add_button(c);
b->connect("pressed", callable_mp(this, &AcceptDialog::_cancel_pressed));
return b;
diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp
index 158662e0fc..be6b542ae1 100644
--- a/scene/gui/file_dialog.cpp
+++ b/scene/gui/file_dialog.cpp
@@ -102,8 +102,9 @@ void FileDialog::_unhandled_input(const Ref<InputEvent> &p_event) {
}
}
- if (handled)
+ if (handled) {
set_input_as_handled();
+ }
}
}
}
@@ -157,10 +158,11 @@ void FileDialog::_post_popup() {
update_file_list();
invalidated = false;
}
- if (mode == FILE_MODE_SAVE_FILE)
+ if (mode == FILE_MODE_SAVE_FILE) {
file->grab_focus();
- else
+ } else {
tree->grab_focus();
+ }
set_process_unhandled_input(true);
@@ -229,13 +231,15 @@ void FileDialog::_action_pressed() {
break;
}
}
- if (valid)
+ if (valid) {
break;
+ }
}
} else {
int idx = filter->get_selected();
- if (filters.size() > 1)
+ if (filters.size() > 1) {
idx--;
+ }
if (idx >= 0 && idx < filters.size()) {
String flt = filters[idx].get_slice(";", 0);
int filterSliceCount = flt.get_slice_count(",");
@@ -280,19 +284,22 @@ void FileDialog::_cancel_pressed() {
}
bool FileDialog::_is_open_should_be_disabled() {
- if (mode == FILE_MODE_OPEN_ANY || mode == FILE_MODE_SAVE_FILE)
+ if (mode == FILE_MODE_OPEN_ANY || mode == FILE_MODE_SAVE_FILE) {
return false;
+ }
TreeItem *ti = tree->get_next_selected(tree->get_root());
while (ti) {
TreeItem *prev_ti = ti;
ti = tree->get_next_selected(tree->get_root());
- if (ti == prev_ti)
+ if (ti == prev_ti) {
break;
+ }
}
// We have something that we can't select?
- if (!ti)
+ if (!ti) {
return mode != FILE_MODE_OPEN_DIR; // In "Open folder" mode, having nothing selected picks the current folder.
+ }
Dictionary d = ti->get_metadata(0);
@@ -337,8 +344,9 @@ void FileDialog::_tree_multi_selected(Object *p_object, int p_cell, bool p_selec
void FileDialog::_tree_selected() {
TreeItem *ti = tree->get_selected();
- if (!ti)
+ if (!ti) {
return;
+ }
Dictionary d = ti->get_metadata(0);
if (!d["dir"]) {
@@ -352,15 +360,17 @@ void FileDialog::_tree_selected() {
void FileDialog::_tree_item_activated() {
TreeItem *ti = tree->get_selected();
- if (!ti)
+ if (!ti) {
return;
+ }
Dictionary d = ti->get_metadata(0);
if (d["dir"]) {
dir_access->change_dir(d["name"]);
- if (mode == FILE_MODE_OPEN_FILE || mode == FILE_MODE_OPEN_FILES || mode == FILE_MODE_OPEN_DIR || mode == FILE_MODE_OPEN_ANY)
+ if (mode == FILE_MODE_OPEN_FILE || mode == FILE_MODE_OPEN_FILES || mode == FILE_MODE_OPEN_DIR || mode == FILE_MODE_OPEN_ANY) {
file->set_text("");
+ }
call_deferred("_update_file_list");
call_deferred("_update_dir");
} else {
@@ -371,8 +381,9 @@ void FileDialog::_tree_item_activated() {
void FileDialog::update_file_name() {
int idx = filter->get_selected() - 1;
if ((idx == -1 && filter->get_item_count() == 2) || (filter->get_item_count() > 2 && idx >= 0 && idx < filter->get_item_count() - 2)) {
- if (idx == -1)
+ if (idx == -1) {
idx += 1;
+ }
String filter_str = filters[idx];
String file_str = file->get_text();
String base_name = file_str.get_basename();
@@ -399,16 +410,18 @@ void FileDialog::update_file_list() {
String item;
while ((item = dir_access->get_next()) != "") {
- if (item == "." || item == "..")
+ if (item == "." || item == "..") {
continue;
+ }
is_hidden = dir_access->current_is_hidden();
if (show_hidden_files || !is_hidden) {
- if (!dir_access->current_is_dir())
+ if (!dir_access->current_is_dir()) {
files.push_back(item);
- else
+ } else {
dirs.push_back(item);
+ }
}
}
@@ -445,8 +458,9 @@ void FileDialog::update_file_list() {
}
} else {
int idx = filter->get_selected();
- if (filters.size() > 1)
+ if (filters.size() > 1) {
idx--;
+ }
if (idx >= 0 && idx < filters.size()) {
String f = filters[idx].get_slice(";", 0);
@@ -488,15 +502,17 @@ void FileDialog::update_file_list() {
d["dir"] = false;
ti->set_metadata(0, d);
- if (file->get_text() == files.front()->get() || match_str == files.front()->get())
+ if (file->get_text() == files.front()->get() || match_str == files.front()->get()) {
ti->select(0);
+ }
}
files.pop_front();
}
- if (tree->get_root() && tree->get_root()->get_children() && tree->get_selected() == nullptr)
+ if (tree->get_root() && tree->get_root()->get_children() && tree->get_selected() == nullptr) {
tree->get_root()->get_children()->select(0);
+ }
}
void FileDialog::_filter_selected(int) {
@@ -514,23 +530,26 @@ void FileDialog::update_filters() {
for (int i = 0; i < MIN(max_filters, filters.size()); i++) {
String flt = filters[i].get_slice(";", 0).strip_edges();
- if (i > 0)
+ if (i > 0) {
all_filters += ", ";
+ }
all_filters += flt;
}
- if (max_filters < filters.size())
+ if (max_filters < filters.size()) {
all_filters += ", ...";
+ }
filter->add_item(RTR("All Recognized") + " (" + all_filters + ")");
}
for (int i = 0; i < filters.size(); i++) {
String flt = filters[i].get_slice(";", 0).strip_edges();
String desc = filters[i].get_slice(";", 1).strip_edges();
- if (desc.length())
+ if (desc.length()) {
filter->add_item(String(tr(desc)) + " (" + flt + ")");
- else
+ } else {
filter->add_item("(" + flt + ")");
+ }
}
filter->add_item(RTR("All Files (*)"));
@@ -583,14 +602,16 @@ void FileDialog::set_current_file(const String &p_file) {
int lp = p_file.find_last(".");
if (lp != -1) {
file->select(0, lp);
- if (file->is_inside_tree() && !get_tree()->is_node_being_edited(file))
+ if (file->is_inside_tree() && !get_tree()->is_node_being_edited(file)) {
file->grab_focus();
+ }
}
}
void FileDialog::set_current_path(const String &p_path) {
- if (!p_path.size())
+ if (!p_path.size()) {
return;
+ }
int pos = MAX(p_path.find_last("/"), p_path.find_last("\\"));
if (pos == -1) {
set_current_file(p_path);
@@ -617,32 +638,37 @@ void FileDialog::set_file_mode(FileMode p_mode) {
switch (mode) {
case FILE_MODE_OPEN_FILE:
get_ok()->set_text(RTR("Open"));
- if (mode_overrides_title)
+ if (mode_overrides_title) {
set_title(RTR("Open a File"));
+ }
makedir->hide();
break;
case FILE_MODE_OPEN_FILES:
get_ok()->set_text(RTR("Open"));
- if (mode_overrides_title)
+ if (mode_overrides_title) {
set_title(RTR("Open File(s)"));
+ }
makedir->hide();
break;
case FILE_MODE_OPEN_DIR:
get_ok()->set_text(RTR("Select Current Folder"));
- if (mode_overrides_title)
+ if (mode_overrides_title) {
set_title(RTR("Open a Directory"));
+ }
makedir->show();
break;
case FILE_MODE_OPEN_ANY:
get_ok()->set_text(RTR("Open"));
- if (mode_overrides_title)
+ if (mode_overrides_title) {
set_title(RTR("Open a File or Directory"));
+ }
makedir->show();
break;
case FILE_MODE_SAVE_FILE:
get_ok()->set_text(RTR("Save"));
- if (mode_overrides_title)
+ if (mode_overrides_title) {
set_title(RTR("Save a File"));
+ }
makedir->show();
break;
}
@@ -660,8 +686,9 @@ FileDialog::FileMode FileDialog::get_file_mode() const {
void FileDialog::set_access(Access p_access) {
ERR_FAIL_INDEX(p_access, 3);
- if (access == p_access)
+ if (access == p_access) {
return;
+ }
memdelete(dir_access);
switch (p_access) {
case ACCESS_FILESYSTEM: {
@@ -926,12 +953,14 @@ FileDialog::FileDialog() {
set_hide_on_ok(false);
invalidated = true;
- if (register_func)
+ if (register_func) {
register_func(this);
+ }
}
FileDialog::~FileDialog() {
- if (unregister_func)
+ if (unregister_func) {
unregister_func(this);
+ }
memdelete(dir_access);
}
diff --git a/scene/gui/gradient_edit.cpp b/scene/gui/gradient_edit.cpp
index 1617405dd3..ecd4ad17ea 100644
--- a/scene/gui/gradient_edit.cpp
+++ b/scene/gui/gradient_edit.cpp
@@ -73,8 +73,9 @@ int GradientEdit::_get_point_from_pos(int x) {
}
void GradientEdit::_show_color_picker() {
- if (grabbed == -1)
+ if (grabbed == -1) {
return;
+ }
picker->set_pick_color(points[grabbed].color);
Size2 minsize = popup->get_contents_minimum_size();
bool show_above = false;
@@ -178,8 +179,9 @@ void GradientEdit::_gui_input(const Ref<InputEvent> &p_event) {
int pos = -1;
for (int i = 0; i < points.size(); i++) {
- if (points[i].offset < newPoint.offset)
+ if (points[i].offset < newPoint.offset) {
pos = i;
+ }
}
if (pos == -1) {
@@ -248,17 +250,19 @@ void GradientEdit::_gui_input(const Ref<InputEvent> &p_event) {
if (temp_ofs < smallest_ofs) {
smallest_ofs = temp_ofs;
nearest_point = i;
- if (found)
+ if (found) {
break;
+ }
found = true;
}
}
}
if (found) {
- if (points[nearest_point].offset < newofs)
+ if (points[nearest_point].offset < newofs) {
newofs = points[nearest_point].offset + 0.00001;
- else
+ } else {
newofs = points[nearest_point].offset - 0.00001;
+ }
newofs = CLAMP(newofs, 0, 1);
}
}
@@ -300,8 +304,9 @@ void GradientEdit::_notification(int p_what) {
int w = get_size().x;
int h = get_size().y;
- if (w == 0 || h == 0)
+ if (w == 0 || h == 0) {
return; //Safety check. We have division by 'h'. And in any case there is nothing to draw with such size
+ }
int total_w = get_size().width - get_size().height - SPACING;
@@ -311,19 +316,21 @@ void GradientEdit::_notification(int p_what) {
//Draw color ramp
Gradient::Point prev;
prev.offset = 0;
- if (points.size() == 0)
+ if (points.size() == 0) {
prev.color = Color(0, 0, 0); //Draw black rectangle if we have no points
- else
+ } else {
prev.color = points[0].color; //Extend color of first point to the beginning.
+ }
for (int i = -1; i < points.size(); i++) {
Gradient::Point next;
//If there is no next point
if (i + 1 == points.size()) {
- if (points.size() == 0)
+ if (points.size() == 0) {
next.color = Color(0, 0, 0); //Draw black rectangle if we have no points
- else
+ } else {
next.color = points[i].color; //Extend color of last point to the end.
+ }
next.offset = 1;
} else {
next = points[i + 1];
@@ -424,8 +431,9 @@ Size2 GradientEdit::get_minimum_size() const {
}
void GradientEdit::_color_changed(const Color &p_color) {
- if (grabbed == -1)
+ if (grabbed == -1) {
return;
+ }
points.write[grabbed].color = p_color;
update();
emit_signal("ramp_changed");
@@ -447,21 +455,24 @@ void GradientEdit::set_ramp(const Vector<float> &p_offsets, const Vector<Color>
Vector<float> GradientEdit::get_offsets() const {
Vector<float> ret;
- for (int i = 0; i < points.size(); i++)
+ for (int i = 0; i < points.size(); i++) {
ret.push_back(points[i].offset);
+ }
return ret;
}
Vector<Color> GradientEdit::get_colors() const {
Vector<Color> ret;
- for (int i = 0; i < points.size(); i++)
+ for (int i = 0; i < points.size(); i++) {
ret.push_back(points[i].color);
+ }
return ret;
}
void GradientEdit::set_points(Vector<Gradient::Point> &p_points) {
- if (points.size() != p_points.size())
+ if (points.size() != p_points.size()) {
grabbed = -1;
+ }
points.clear();
points = p_points;
}
diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp
index 02363e909c..5489638125 100644
--- a/scene/gui/graph_edit.cpp
+++ b/scene/gui/graph_edit.cpp
@@ -52,8 +52,9 @@ GraphEditFilter::GraphEditFilter(GraphEdit *p_edit) {
}
Error GraphEdit::connect_node(const StringName &p_from, int p_from_port, const StringName &p_to, int p_to_port) {
- if (is_node_connected(p_from, p_from_port, p_to, p_to_port))
+ if (is_node_connected(p_from, p_from_port, p_to, p_to_port)) {
return OK;
+ }
Connection c;
c.from = p_from;
c.from_port = p_from_port;
@@ -70,8 +71,9 @@ 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<Connection>::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 (E->get().from == p_from && E->get().from_port == p_from_port && E->get().to == p_to && E->get().to_port == p_to_port) {
return true;
+ }
}
return false;
@@ -127,8 +129,9 @@ void GraphEdit::_update_scroll_offset() {
for (int i = 0; i < get_child_count(); i++) {
GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
- if (!gn)
+ if (!gn) {
continue;
+ }
Point2 pos = gn->get_offset() * zoom;
pos -= Point2(h_scroll->get_value(), v_scroll->get_value());
@@ -144,8 +147,9 @@ void GraphEdit::_update_scroll_offset() {
}
void GraphEdit::_update_scroll() {
- if (updating)
+ if (updating) {
return;
+ }
updating = true;
@@ -154,8 +158,9 @@ void GraphEdit::_update_scroll() {
Rect2 screen;
for (int i = 0; i < get_child_count(); i++) {
GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
- if (!gn)
+ if (!gn) {
continue;
+ }
Rect2 r;
r.position = gn->get_offset() * zoom;
@@ -169,19 +174,21 @@ void GraphEdit::_update_scroll() {
h_scroll->set_min(screen.position.x);
h_scroll->set_max(screen.position.x + screen.size.x);
h_scroll->set_page(get_size().x);
- if (h_scroll->get_max() - h_scroll->get_min() <= h_scroll->get_page())
+ if (h_scroll->get_max() - h_scroll->get_min() <= h_scroll->get_page()) {
h_scroll->hide();
- else
+ } else {
h_scroll->show();
+ }
v_scroll->set_min(screen.position.y);
v_scroll->set_max(screen.position.y + screen.size.y);
v_scroll->set_page(get_size().y);
- if (v_scroll->get_max() - v_scroll->get_min() <= v_scroll->get_page())
+ if (v_scroll->get_max() - v_scroll->get_min() <= v_scroll->get_page()) {
v_scroll->hide();
- else
+ } else {
v_scroll->show();
+ }
Size2 hmin = h_scroll->get_combined_minimum_size();
Size2 vmin = v_scroll->get_combined_minimum_size();
@@ -301,10 +308,11 @@ void GraphEdit::_notification(int p_what) {
for (int i = from.x; i < from.x + len.x; i++) {
Color color;
- if (ABS(i) % 10 == 0)
+ if (ABS(i) % 10 == 0) {
color = grid_major;
- else
+ } else {
color = grid_minor;
+ }
float base_ofs = i * snap * zoom - offset.x * zoom;
draw_line(Vector2(base_ofs, 0), Vector2(base_ofs, get_size().height), color);
@@ -313,10 +321,11 @@ void GraphEdit::_notification(int p_what) {
for (int i = from.y; i < from.y + len.y; i++) {
Color color;
- if (ABS(i) % 10 == 0)
+ if (ABS(i) % 10 == 0) {
color = grid_major;
- else
+ } else {
color = grid_minor;
+ }
float base_ofs = i * snap * zoom - offset.y * zoom;
draw_line(Vector2(0, base_ofs), Vector2(get_size().width, base_ofs), color);
@@ -335,13 +344,15 @@ bool GraphEdit::_filter_input(const Point2 &p_point) {
for (int i = get_child_count() - 1; i >= 0; i--) {
GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
- if (!gn)
+ if (!gn) {
continue;
+ }
for (int j = 0; j < gn->get_connection_output_count(); j++) {
Vector2 pos = gn->get_connection_output_position(j) + gn->get_position();
- if (is_in_hot_zone(pos, p_point))
+ if (is_in_hot_zone(pos, p_point)) {
return true;
+ }
}
for (int j = 0; j < gn->get_connection_input_count(); j++) {
@@ -362,8 +373,9 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) {
Vector2 mpos(mb->get_position().x, mb->get_position().y);
for (int i = get_child_count() - 1; i >= 0; i--) {
GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
- if (!gn)
+ if (!gn) {
continue;
+ }
for (int j = 0; j < gn->get_connection_output_count(); j++) {
Vector2 pos = gn->get_connection_output_position(j) + gn->get_position();
@@ -462,8 +474,9 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) {
Vector2 mpos = mm->get_position();
for (int i = get_child_count() - 1; i >= 0; i--) {
GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
- if (!gn)
+ if (!gn) {
continue;
+ }
if (!connecting_out) {
for (int j = 0; j < gn->get_connection_output_count(); j++) {
@@ -526,15 +539,17 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) {
}
bool GraphEdit::_check_clickable_control(Control *p_control, const Vector2 &pos) {
- if (p_control->is_set_as_toplevel() || !p_control->is_visible())
+ if (p_control->is_set_as_toplevel() || !p_control->is_visible()) {
return false;
+ }
if (!p_control->has_point(pos) || p_control->get_mouse_filter() == MOUSE_FILTER_IGNORE) {
//test children
for (int i = 0; i < p_control->get_child_count(); i++) {
Control *subchild = Object::cast_to<Control>(p_control->get_child(i));
- if (!subchild)
+ if (!subchild) {
continue;
+ }
if (_check_clickable_control(subchild, pos - subchild->get_position())) {
return true;
}
@@ -547,13 +562,15 @@ bool GraphEdit::_check_clickable_control(Control *p_control, const Vector2 &pos)
}
bool GraphEdit::is_in_hot_zone(const Vector2 &pos, const Vector2 &p_mouse_pos) {
- if (!Rect2(pos.x - port_grab_distance_horizontal, pos.y - port_grab_distance_vertical, port_grab_distance_horizontal * 2, port_grab_distance_vertical * 2).has_point(p_mouse_pos))
+ if (!Rect2(pos.x - port_grab_distance_horizontal, pos.y - port_grab_distance_vertical, port_grab_distance_horizontal * 2, port_grab_distance_vertical * 2).has_point(p_mouse_pos)) {
return false;
+ }
for (int i = 0; i < get_child_count(); i++) {
Control *child = Object::cast_to<Control>(get_child(i));
- if (!child)
+ if (!child) {
continue;
+ }
Rect2 rect = child->get_rect();
if (rect.has_point(p_mouse_pos)) {
//check sub-controls
@@ -561,8 +578,9 @@ bool GraphEdit::is_in_hot_zone(const Vector2 &pos, const Vector2 &p_mouse_pos) {
for (int j = 0; j < child->get_child_count(); j++) {
Control *subchild = Object::cast_to<Control>(child->get_child(j));
- if (!subchild)
+ if (!subchild) {
continue;
+ }
if (_check_clickable_control(subchild, subpos - subchild->get_position())) {
return false;
@@ -700,10 +718,11 @@ void GraphEdit::_top_layer_draw() {
GraphNode *from = Object::cast_to<GraphNode>(fromn);
ERR_FAIL_COND(!from);
Vector2 pos;
- if (connecting_out)
+ if (connecting_out) {
pos = from->get_connection_output_position(connecting_index);
- else
+ } else {
pos = from->get_connection_input_position(connecting_index);
+ }
pos += from->get_position();
Vector2 topos;
@@ -732,8 +751,9 @@ void GraphEdit::_top_layer_draw() {
void GraphEdit::set_selected(Node *p_child) {
for (int i = get_child_count() - 1; i >= 0; i--) {
GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
- if (!gn)
+ if (!gn) {
continue;
+ }
gn->set_selected(gn == p_child);
}
@@ -778,17 +798,19 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
for (int i = get_child_count() - 1; i >= 0; i--) {
GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
- if (!gn)
+ if (!gn) {
continue;
+ }
Rect2 r = gn->get_rect();
r.size *= zoom;
bool in_box = r.intersects(box_selecting_rect);
- if (in_box)
+ if (in_box) {
gn->set_selected(box_selection_mode_additive);
- else
+ } else {
gn->set_selected(previus_selected.find(gn) != nullptr);
+ }
}
top_layer->update();
@@ -801,8 +823,9 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
box_selecting = false;
for (int i = get_child_count() - 1; i >= 0; i--) {
GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
- if (!gn)
+ if (!gn) {
continue;
+ }
gn->set_selected(previus_selected.find(gn) != nullptr);
}
@@ -826,8 +849,9 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
if (gn) {
Rect2 r = gn->get_rect();
r.size *= zoom;
- if (r.has_point(get_local_mouse_position()))
+ if (r.has_point(get_local_mouse_position())) {
gn->set_selected(false);
+ }
}
}
}
@@ -837,8 +861,9 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
for (int i = get_child_count() - 1; i >= 0; i--) {
GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
- if (gn && gn->is_selected())
+ if (gn && gn->is_selected()) {
gn->set_drag(false);
+ }
}
emit_signal("_end_node_move");
@@ -858,8 +883,9 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
GraphNode *gn_selected = Object::cast_to<GraphNode>(get_child(i));
if (gn_selected) {
- if (gn_selected->is_resizing())
+ if (gn_selected->is_resizing()) {
continue;
+ }
if (gn_selected->has_point(gn_selected->get_local_mouse_position())) {
gn = gn_selected;
@@ -869,8 +895,9 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
}
if (gn) {
- if (_filter_input(b->get_position()))
+ if (_filter_input(b->get_position())) {
return;
+ }
dragging = true;
drag_accum = Vector2();
@@ -895,17 +922,21 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
gn->set_selected(true);
for (int i = 0; i < get_child_count(); i++) {
GraphNode *o_gn = Object::cast_to<GraphNode>(get_child(i));
- if (!o_gn)
+ if (!o_gn) {
continue;
- if (o_gn->is_selected())
+ }
+ if (o_gn->is_selected()) {
o_gn->set_drag(true);
+ }
}
} else {
- if (_filter_input(b->get_position()))
+ if (_filter_input(b->get_position())) {
return;
- if (Input::get_singleton()->is_key_pressed(KEY_SPACE))
+ }
+ if (Input::get_singleton()->is_key_pressed(KEY_SPACE)) {
return;
+ }
box_selecting = true;
box_selecting_from = get_local_mouse_position();
@@ -914,8 +945,9 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
previus_selected.clear();
for (int i = get_child_count() - 1; i >= 0; i--) {
GraphNode *gn2 = Object::cast_to<GraphNode>(get_child(i));
- if (!gn2 || !gn2->is_selected())
+ if (!gn2 || !gn2->is_selected()) {
continue;
+ }
previus_selected.push_back(gn2);
}
@@ -924,8 +956,9 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
previus_selected.clear();
for (int i = get_child_count() - 1; i >= 0; i--) {
GraphNode *gn2 = Object::cast_to<GraphNode>(get_child(i));
- if (!gn2 || !gn2->is_selected())
+ if (!gn2 || !gn2->is_selected()) {
continue;
+ }
previus_selected.push_back(gn2);
}
@@ -934,8 +967,9 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
previus_selected.clear();
for (int i = get_child_count() - 1; i >= 0; i--) {
GraphNode *gn2 = Object::cast_to<GraphNode>(get_child(i));
- if (!gn2)
+ if (!gn2) {
continue;
+ }
if (gn2->is_selected()) {
emit_signal("node_unselected", gn2);
}
@@ -1036,8 +1070,9 @@ void GraphEdit::set_zoom(float p_zoom) {
void GraphEdit::set_zoom_custom(float p_zoom, const Vector2 &p_center) {
p_zoom = CLAMP(p_zoom, MIN_ZOOM, MAX_ZOOM);
- if (zoom == p_zoom)
+ if (zoom == p_zoom) {
return;
+ }
zoom_minus->set_disabled(zoom == MIN_ZOOM);
zoom_plus->set_disabled(zoom == MAX_ZOOM);
diff --git a/scene/gui/graph_node.cpp b/scene/gui/graph_node.cpp
index c2203364d0..b6a96238dc 100644
--- a/scene/gui/graph_node.cpp
+++ b/scene/gui/graph_node.cpp
@@ -33,30 +33,33 @@
#include "core/method_bind_ext.gen.inc"
bool GraphNode::_set(const StringName &p_name, const Variant &p_value) {
- if (!p_name.operator String().begins_with("slot/"))
+ if (!p_name.operator String().begins_with("slot/")) {
return false;
+ }
int idx = p_name.operator String().get_slice("/", 1).to_int();
String what = p_name.operator String().get_slice("/", 2);
Slot si;
- if (slot_info.has(idx))
+ if (slot_info.has(idx)) {
si = slot_info[idx];
+ }
- if (what == "left_enabled")
+ if (what == "left_enabled") {
si.enable_left = p_value;
- else if (what == "left_type")
+ } else if (what == "left_type") {
si.type_left = p_value;
- else if (what == "left_color")
+ } else if (what == "left_color") {
si.color_left = p_value;
- else if (what == "right_enabled")
+ } else if (what == "right_enabled") {
si.enable_right = p_value;
- else if (what == "right_type")
+ } else if (what == "right_type") {
si.type_right = p_value;
- else if (what == "right_color")
+ } else if (what == "right_color") {
si.color_right = p_value;
- else
+ } else {
return false;
+ }
set_slot(idx, si.enable_left, si.type_left, si.color_left, si.enable_right, si.type_right, si.color_right);
update();
@@ -72,23 +75,25 @@ bool GraphNode::_get(const StringName &p_name, Variant &r_ret) const {
String what = p_name.operator String().get_slice("/", 2);
Slot si;
- if (slot_info.has(idx))
+ if (slot_info.has(idx)) {
si = slot_info[idx];
+ }
- if (what == "left_enabled")
+ if (what == "left_enabled") {
r_ret = si.enable_left;
- else if (what == "left_type")
+ } else if (what == "left_type") {
r_ret = si.type_left;
- else if (what == "left_color")
+ } else if (what == "left_color") {
r_ret = si.color_left;
- else if (what == "right_enabled")
+ } else if (what == "right_enabled") {
r_ret = si.enable_right;
- else if (what == "right_type")
+ } else if (what == "right_type") {
r_ret = si.type_right;
- else if (what == "right_color")
+ } else if (what == "right_color") {
r_ret = si.color_right;
- else
+ } else {
return false;
+ }
return true;
}
@@ -97,8 +102,9 @@ void GraphNode::_get_property_list(List<PropertyInfo> *p_list) const {
int idx = 0;
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c || c->is_set_as_toplevel())
+ if (!c || c->is_set_as_toplevel()) {
continue;
+ }
String base = "slot/" + itos(idx) + "/";
@@ -122,20 +128,23 @@ void GraphNode::_resort() {
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c)
+ if (!c) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
+ }
Size2i size = c->get_combined_minimum_size();
minsize.y += size.y;
minsize.x = MAX(minsize.x, size.x);
- if (first)
+ if (first) {
first = false;
- else
+ } else {
minsize.y += sep;
+ }
}
int vofs = 0;
@@ -144,10 +153,12 @@ void GraphNode::_resort() {
cache_y.clear();
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c)
+ if (!c) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
+ }
Size2i size = c->get_combined_minimum_size();
@@ -228,8 +239,9 @@ void GraphNode::_notification(int p_what) {
int w = get_size().width - sb->get_minimum_size().x;
- if (show_close)
+ if (show_close) {
w -= close->get_width();
+ }
draw_string(title_font, Point2(sb->get_margin(MARGIN_LEFT) + title_h_offset, -title_font->get_height() + title_font->get_ascent() + title_offset), title, title_color, w);
if (show_close) {
@@ -242,10 +254,12 @@ void GraphNode::_notification(int p_what) {
}
for (Map<int, Slot>::Element *E = slot_info.front(); E; E = E->next()) {
- if (E->key() < 0 || E->key() >= cache_y.size())
+ if (E->key() < 0 || E->key() >= cache_y.size()) {
continue;
- if (!slot_info.has(E->key()))
+ }
+ if (!slot_info.has(E->key())) {
continue;
+ }
const Slot &s = slot_info[E->key()];
//left
if (s.enable_left) {
@@ -314,38 +328,44 @@ void GraphNode::clear_all_slots() {
}
bool GraphNode::is_slot_enabled_left(int p_idx) const {
- if (!slot_info.has(p_idx))
+ if (!slot_info.has(p_idx)) {
return false;
+ }
return slot_info[p_idx].enable_left;
}
int GraphNode::get_slot_type_left(int p_idx) const {
- if (!slot_info.has(p_idx))
+ if (!slot_info.has(p_idx)) {
return 0;
+ }
return slot_info[p_idx].type_left;
}
Color GraphNode::get_slot_color_left(int p_idx) const {
- if (!slot_info.has(p_idx))
+ if (!slot_info.has(p_idx)) {
return Color(1, 1, 1, 1);
+ }
return slot_info[p_idx].color_left;
}
bool GraphNode::is_slot_enabled_right(int p_idx) const {
- if (!slot_info.has(p_idx))
+ if (!slot_info.has(p_idx)) {
return false;
+ }
return slot_info[p_idx].enable_right;
}
int GraphNode::get_slot_type_right(int p_idx) const {
- if (!slot_info.has(p_idx))
+ if (!slot_info.has(p_idx)) {
return 0;
+ }
return slot_info[p_idx].type_right;
}
Color GraphNode::get_slot_color_right(int p_idx) const {
- if (!slot_info.has(p_idx))
+ if (!slot_info.has(p_idx)) {
return Color(1, 1, 1, 1);
+ }
return slot_info[p_idx].color_right;
}
@@ -365,28 +385,32 @@ Size2 GraphNode::get_minimum_size() const {
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c)
+ if (!c) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
+ }
Size2i size = c->get_combined_minimum_size();
minsize.y += size.y;
minsize.x = MAX(minsize.x, size.x);
- if (first)
+ if (first) {
first = false;
- else
+ } else {
minsize.y += sep;
+ }
}
return minsize + sb->get_minimum_size();
}
void GraphNode::set_title(const String &p_title) {
- if (title == p_title)
+ if (title == p_title) {
return;
+ }
title = p_title;
update();
_change_notify("title");
@@ -417,10 +441,11 @@ bool GraphNode::is_selected() {
}
void GraphNode::set_drag(bool p_drag) {
- if (p_drag)
+ if (p_drag) {
drag_from = get_offset();
- else
+ } else {
emit_signal("dragged", drag_from, get_offset()); //useful for undo/redo
+ }
}
Vector2 GraphNode::get_drag_from() {
@@ -449,10 +474,12 @@ void GraphNode::_connpos_update() {
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c)
+ if (!c) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
+ }
Size2i size = c->get_combined_minimum_size();
@@ -476,8 +503,9 @@ void GraphNode::_connpos_update() {
}
}
- if (vofs > 0)
+ if (vofs > 0) {
vofs += sep;
+ }
vofs += size.y;
idx++;
}
@@ -486,22 +514,25 @@ void GraphNode::_connpos_update() {
}
int GraphNode::get_connection_input_count() {
- if (connpos_dirty)
+ if (connpos_dirty) {
_connpos_update();
+ }
return conn_input_cache.size();
}
int GraphNode::get_connection_output_count() {
- if (connpos_dirty)
+ if (connpos_dirty) {
_connpos_update();
+ }
return conn_output_cache.size();
}
Vector2 GraphNode::get_connection_input_position(int p_idx) {
- if (connpos_dirty)
+ if (connpos_dirty) {
_connpos_update();
+ }
ERR_FAIL_INDEX_V(p_idx, conn_input_cache.size(), Vector2());
Vector2 pos = conn_input_cache[p_idx].pos;
@@ -511,24 +542,27 @@ Vector2 GraphNode::get_connection_input_position(int p_idx) {
}
int GraphNode::get_connection_input_type(int p_idx) {
- if (connpos_dirty)
+ if (connpos_dirty) {
_connpos_update();
+ }
ERR_FAIL_INDEX_V(p_idx, conn_input_cache.size(), 0);
return conn_input_cache[p_idx].type;
}
Color GraphNode::get_connection_input_color(int p_idx) {
- if (connpos_dirty)
+ if (connpos_dirty) {
_connpos_update();
+ }
ERR_FAIL_INDEX_V(p_idx, conn_input_cache.size(), Color());
return conn_input_cache[p_idx].color;
}
Vector2 GraphNode::get_connection_output_position(int p_idx) {
- if (connpos_dirty)
+ if (connpos_dirty) {
_connpos_update();
+ }
ERR_FAIL_INDEX_V(p_idx, conn_output_cache.size(), Vector2());
Vector2 pos = conn_output_cache[p_idx].pos;
@@ -538,16 +572,18 @@ Vector2 GraphNode::get_connection_output_position(int p_idx) {
}
int GraphNode::get_connection_output_type(int p_idx) {
- if (connpos_dirty)
+ if (connpos_dirty) {
_connpos_update();
+ }
ERR_FAIL_INDEX_V(p_idx, conn_output_cache.size(), 0);
return conn_output_cache[p_idx].type;
}
Color GraphNode::get_connection_output_color(int p_idx) {
- if (connpos_dirty)
+ if (connpos_dirty) {
_connpos_update();
+ }
ERR_FAIL_INDEX_V(p_idx, conn_output_cache.size(), Color());
return conn_output_cache[p_idx].color;
diff --git a/scene/gui/grid_container.cpp b/scene/gui/grid_container.cpp
index 1ba761e7a1..2f37461c4d 100644
--- a/scene/gui/grid_container.cpp
+++ b/scene/gui/grid_container.cpp
@@ -47,22 +47,25 @@ void GridContainer::_notification(int p_what) {
int valid_controls_index = 0;
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c || !c->is_visible_in_tree())
+ if (!c || !c->is_visible_in_tree()) {
continue;
+ }
int row = valid_controls_index / columns;
int col = valid_controls_index % columns;
valid_controls_index++;
Size2i ms = c->get_combined_minimum_size();
- if (col_minw.has(col))
+ if (col_minw.has(col)) {
col_minw[col] = MAX(col_minw[col], ms.width);
- else
+ } else {
col_minw[col] = ms.width;
- if (row_minh.has(row))
+ }
+ if (row_minh.has(row)) {
row_minh[row] = MAX(row_minh[row], ms.height);
- else
+ } else {
row_minh[row] = ms.height;
+ }
if (c->get_h_size_flags() & SIZE_EXPAND) {
col_expanded.insert(col);
@@ -80,13 +83,15 @@ void GridContainer::_notification(int p_what) {
// Evaluate the remaining space for expanded columns/rows.
Size2 remaining_space = get_size();
for (Map<int, int>::Element *E = col_minw.front(); E; E = E->next()) {
- if (!col_expanded.has(E->key()))
+ if (!col_expanded.has(E->key())) {
remaining_space.width -= E->get();
+ }
}
for (Map<int, int>::Element *E = row_minh.front(); E; E = E->next()) {
- if (!row_expanded.has(E->key()))
+ if (!row_expanded.has(E->key())) {
remaining_space.height -= E->get();
+ }
}
remaining_space.height -= vsep * MAX(max_row - 1, 0);
remaining_space.width -= hsep * MAX(max_col - 1, 0);
@@ -143,16 +148,18 @@ void GridContainer::_notification(int p_what) {
valid_controls_index = 0;
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c || !c->is_visible_in_tree())
+ if (!c || !c->is_visible_in_tree()) {
continue;
+ }
int row = valid_controls_index / columns;
int col = valid_controls_index % columns;
valid_controls_index++;
if (col == 0) {
col_ofs = 0;
- if (row > 0)
+ if (row > 0) {
row_ofs += (row_expanded.has(row - 1) ? row_expand : row_minh[row - 1]) + vsep;
+ }
}
Point2 p(col_ofs, row_ofs);
@@ -201,22 +208,25 @@ Size2 GridContainer::get_minimum_size() const {
int valid_controls_index = 0;
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c || !c->is_visible())
+ if (!c || !c->is_visible()) {
continue;
+ }
int row = valid_controls_index / columns;
int col = valid_controls_index % columns;
valid_controls_index++;
Size2i ms = c->get_combined_minimum_size();
- if (col_minw.has(col))
+ if (col_minw.has(col)) {
col_minw[col] = MAX(col_minw[col], ms.width);
- else
+ } else {
col_minw[col] = ms.width;
+ }
- if (row_minh.has(row))
+ if (row_minh.has(row)) {
row_minh[row] = MAX(row_minh[row], ms.height);
- else
+ } else {
row_minh[row] = ms.height;
+ }
max_col = MAX(col, max_col);
max_row = MAX(row, max_row);
}
diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp
index 06a4534e22..54150d130d 100644
--- a/scene/gui/item_list.cpp
+++ b/scene/gui/item_list.cpp
@@ -268,8 +268,9 @@ void ItemList::unselect(int p_idx) {
}
void ItemList::unselect_all() {
- if (items.size() < 1)
+ if (items.size() < 1) {
return;
+ }
for (int i = 0; i < items.size(); i++) {
items.write[i].selected = false;
@@ -287,9 +288,9 @@ bool ItemList::is_selected(int p_idx) const {
void ItemList::set_current(int p_current) {
ERR_FAIL_INDEX(p_current, items.size());
- if (select_mode == SELECT_SINGLE)
+ if (select_mode == SELECT_SINGLE) {
select(p_current, true);
- else {
+ } else {
current = p_current;
update();
}
@@ -410,12 +411,14 @@ Size2 ItemList::get_fixed_icon_size() const {
}
Size2 ItemList::Item::get_icon_size() const {
- if (icon.is_null())
+ if (icon.is_null()) {
return Size2();
+ }
Size2 size_result = Size2(icon_region.size).abs();
- if (icon_region.size.x == 0 || icon_region.size.y == 0)
+ if (icon_region.size.x == 0 || icon_region.size.y == 0) {
size_result = icon->get_size();
+ }
if (icon_transposed) {
Size2 size_tmp = size_result;
@@ -482,8 +485,9 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
for (int j = from; j <= to; j++) {
bool selected = !items[j].selected;
select(j, false);
- if (selected)
+ if (selected) {
emit_signal("multi_selected", j, true);
+ }
}
if (mb->get_button_index() == BUTTON_RIGHT) {
@@ -505,8 +509,9 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
if (!selected || allow_reselect) {
if (select_mode == SELECT_SINGLE) {
emit_signal("item_selected", i);
- } else
+ } else {
emit_signal("multi_selected", i, true);
+ }
}
if (mb->get_button_index() == BUTTON_RIGHT) {
@@ -677,19 +682,22 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
search_string = "";
}
- if (String::chr(k->get_unicode()) != search_string)
+ if (String::chr(k->get_unicode()) != search_string) {
search_string += String::chr(k->get_unicode());
+ }
for (int i = current + 1; i <= items.size(); i++) {
if (i == items.size()) {
- if (current == 0 || current == -1)
+ if (current == 0 || current == -1) {
break;
- else
+ } else {
i = 0;
+ }
}
- if (i == current)
+ if (i == current) {
break;
+ }
if (items[i].text.findn(search_string) == 0) {
set_current(i);
@@ -709,8 +717,9 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
scroll_bar->set_value(scroll_bar->get_value() + scroll_bar->get_page() * pan_gesture->get_delta().y / 8);
}
- if (scroll_bar->get_value() != prev_scroll)
+ if (scroll_bar->get_value() != prev_scroll) {
accept_event(); //accept event if scroll changed
+ }
}
void ItemList::ensure_current_is_visible() {
@@ -825,8 +834,9 @@ void ItemList::_notification(int p_what) {
}
}
- if (fixed_column_width > 0)
+ if (fixed_column_width > 0) {
minsize.x = fixed_column_width;
+ }
max_column_width = MAX(max_column_width, minsize.x);
// elements need to adapt to the selected size
@@ -840,8 +850,9 @@ void ItemList::_notification(int p_what) {
//2-attempt best fit
current_columns = 0x7FFFFFFF;
- if (max_columns > 0)
+ if (max_columns > 0) {
current_columns = max_columns;
+ }
while (true) {
//repeat until all fits
@@ -858,15 +869,17 @@ void ItemList::_notification(int p_what) {
break;
}
- if (same_column_width)
+ if (same_column_width) {
items.write[i].rect_cache.size.x = max_column_width;
+ }
items.write[i].rect_cache.position = ofs;
max_h = MAX(max_h, items[i].rect_cache.size.y);
ofs.x += items[i].rect_cache.size.x + hseparation;
col++;
if (col == current_columns) {
- if (i < items.size() - 1)
+ if (i < items.size() - 1) {
separators.push_back(ofs.y + max_h + vseparation / 2);
+ }
for (int j = i; j >= 0 && col > 0; j--, col--) {
items.write[j].rect_cache.size.y = max_h;
@@ -886,8 +899,9 @@ void ItemList::_notification(int p_what) {
if (all_fit) {
float page = MAX(0, size.height - bg->get_minimum_size().height);
float max = MAX(page, ofs.y + max_h);
- if (auto_height)
+ if (auto_height) {
auto_height_value = ofs.y + max_h + bg->get_minimum_size().height;
+ }
scroll_bar->set_max(max);
scroll_bar->set_page(page);
if (max <= page) {
@@ -896,8 +910,9 @@ void ItemList::_notification(int p_what) {
} else {
scroll_bar->show();
- if (do_autoscroll_to_bottom)
+ if (do_autoscroll_to_bottom) {
scroll_bar->set_value(max);
+ }
}
break;
}
@@ -951,11 +966,13 @@ void ItemList::_notification(int p_what) {
for (int i = first_item_visible; i < items.size(); i++) {
Rect2 rcache = items[i].rect_cache;
- if (rcache.position.y > clip.position.y + clip.size.y)
+ if (rcache.position.y > clip.position.y + clip.size.y) {
break; // done
+ }
- if (!clip.intersects(rcache))
+ if (!clip.intersects(rcache)) {
continue;
+ }
if (current_columns == 1) {
rcache.size.width = width - rcache.position.x;
@@ -1020,8 +1037,9 @@ void ItemList::_notification(int p_what) {
}
Color modulate = items[i].icon_modulate;
- if (items[i].disabled)
+ if (items[i].disabled) {
modulate.a *= 0.5;
+ }
// If the icon is transposed, we have to switch the size so that it is drawn correctly
if (items[i].icon_transposed) {
@@ -1042,16 +1060,18 @@ void ItemList::_notification(int p_what) {
int max_len = -1;
Vector2 size2 = font->get_string_size(items[i].text);
- if (fixed_column_width)
+ if (fixed_column_width) {
max_len = fixed_column_width;
- else if (same_column_width)
+ } else if (same_column_width) {
max_len = items[i].rect_cache.size.x;
- else
+ } else {
max_len = size2.x;
+ }
Color modulate = items[i].selected ? font_color_selected : (items[i].custom_fg != Color() ? items[i].custom_fg : font_color);
- if (items[i].disabled)
+ if (items[i].disabled) {
modulate.a *= 0.5;
+ }
if (icon_mode == ICON_MODE_TOP && max_text_lines > 0) {
int ss = items[i].text.length();
@@ -1064,8 +1084,9 @@ void ItemList::_notification(int p_what) {
line_size_cache.write[line] = ofs;
line++;
ofs = 0;
- if (line >= max_text_lines)
+ if (line >= max_text_lines) {
break;
+ }
} else {
ofs += cs;
}
@@ -1084,16 +1105,18 @@ void ItemList::_notification(int p_what) {
if (j == line_limit_cache[line]) {
line++;
ofs = 0;
- if (line >= max_text_lines)
+ if (line >= max_text_lines) {
break;
+ }
}
ofs += drawer.draw_char(get_canvas_item(), text_ofs + Vector2(ofs + (max_len - line_size_cache[line]) / 2, line * (font_height + line_separation)).floor(), items[i].text[j], items[i].text[j + 1], modulate);
}
//special multiline mode
} else {
- if (fixed_column_width > 0)
+ if (fixed_column_width > 0) {
size2.x = MIN(size2.x, fixed_column_width);
+ }
if (icon_mode == ICON_MODE_TOP) {
text_ofs.x += (items[i].rect_cache.size.width - size2.x) / 2;
@@ -1138,8 +1161,9 @@ void ItemList::_notification(int p_what) {
}
for (int i = first_visible_separator; i < separators.size(); i++) {
- if (separators[i] > clip.position.y + clip.size.y)
+ if (separators[i] > clip.position.y + clip.size.y) {
break; // done
+ }
const int y = base_ofs.y + separators[i];
draw_line(Vector2(bg->get_margin(MARGIN_LEFT), y), Vector2(width, y), guide_color);
@@ -1182,8 +1206,9 @@ int ItemList::get_item_at_position(const Point2 &p_pos, bool p_exact) const {
}
bool ItemList::is_pos_at_end_of_items(const Point2 &p_pos) const {
- if (items.empty())
+ if (items.empty()) {
return true;
+ }
Vector2 pos = p_pos;
Ref<StyleBox> bg = get_theme_stylebox("bg");
@@ -1276,8 +1301,9 @@ Vector<int> ItemList::get_selected_items() {
bool ItemList::is_anything_selected() {
for (int i = 0; i < items.size(); i++) {
- if (items[i].selected)
+ if (items[i].selected) {
return true;
+ }
}
return false;
diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp
index f5487a49be..f49acc1b96 100644
--- a/scene/gui/label.cpp
+++ b/scene/gui/label.cpp
@@ -69,8 +69,9 @@ int Label::get_line_height() const {
void Label::_notification(int p_what) {
if (p_what == NOTIFICATION_TRANSLATION_CHANGED) {
String new_text = tr(text);
- if (new_text == xl_text)
+ if (new_text == xl_text) {
return; //nothing new
+ }
xl_text = new_text;
regenerate_word_cache();
@@ -82,8 +83,9 @@ void Label::_notification(int p_what) {
RenderingServer::get_singleton()->canvas_item_set_clip(get_canvas_item(), true);
}
- if (word_cache_dirty)
+ if (word_cache_dirty) {
regenerate_word_cache();
+ }
RID ci = get_canvas_item();
@@ -147,21 +149,25 @@ void Label::_notification(int p_what) {
}
WordCache *wc = word_cache;
- if (!wc)
+ if (!wc) {
return;
+ }
int line = 0;
int line_to = lines_skipped + (lines_visible > 0 ? lines_visible : 1);
FontDrawer drawer(font, font_outline_modulate);
while (wc) {
/* handle lines not meant to be drawn quickly */
- if (line >= line_to)
+ if (line >= line_to) {
break;
+ }
if (line < lines_skipped) {
- while (wc && wc->char_pos >= 0)
+ while (wc && wc->char_pos >= 0) {
wc = wc->next;
- if (wc)
+ }
+ if (wc) {
wc = wc->next;
+ }
line++;
continue;
}
@@ -285,12 +291,13 @@ Size2 Label::get_minimum_size() const {
const_cast<Label *>(this)->regenerate_word_cache();
}
- if (autowrap)
+ if (autowrap) {
return Size2(1, clip ? 1 : minsize.height) + min_style;
- else {
+ } else {
Size2 ms = minsize;
- if (clip)
+ if (clip) {
ms.width = 1;
+ }
return ms + min_style;
}
}
@@ -302,13 +309,15 @@ int Label::get_longest_line_width() const {
for (int i = 0; i < xl_text.size(); i++) {
CharType current = xl_text[i];
- if (uppercase)
+ if (uppercase) {
current = String::char_uppercase(current);
+ }
if (current < 32) {
if (current == '\n') {
- if (line_width > max_line_width)
+ if (line_width > max_line_width) {
max_line_width = line_width;
+ }
line_width = 0;
}
} else {
@@ -317,18 +326,21 @@ int Label::get_longest_line_width() const {
}
}
- if (line_width > max_line_width)
+ if (line_width > max_line_width) {
max_line_width = line_width;
+ }
// ceiling to ensure autowrapping does not cut text
return Math::ceil(max_line_width);
}
int Label::get_line_count() const {
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return 1;
- if (word_cache_dirty)
+ }
+ if (word_cache_dirty) {
const_cast<Label *>(this)->regenerate_word_cache();
+ }
return line_count;
}
@@ -338,11 +350,13 @@ int Label::get_visible_line_count() const {
int font_h = get_theme_font("font")->get_height() + line_spacing;
int lines_visible = (get_size().height - get_theme_stylebox("normal")->get_minimum_size().height + line_spacing) / font_h;
- if (lines_visible > line_count)
+ if (lines_visible > line_count) {
lines_visible = line_count;
+ }
- if (max_lines_visible >= 0 && lines_visible > max_lines_visible)
+ if (max_lines_visible >= 0 && lines_visible > max_lines_visible) {
lines_visible = max_lines_visible;
+ }
return lines_visible;
}
@@ -378,8 +392,9 @@ void Label::regenerate_word_cache() {
for (int i = 0; i <= xl_text.length(); i++) {
CharType current = i < xl_text.length() ? xl_text[i] : L' '; //always a space at the end, so the algo works
- if (uppercase)
+ if (uppercase) {
current = String::char_uppercase(current);
+ }
// ranges taken from http://www.unicodemap.org/
// if your language is not well supported, consider helping improve
@@ -475,8 +490,9 @@ void Label::regenerate_word_cache() {
}
}
- if (!autowrap)
+ if (!autowrap) {
minsize.width = width;
+ }
if (max_lines_visible > 0 && line_count > max_lines_visible) {
minsize.height = (font->get_height() * max_lines_visible) + (line_spacing * (max_lines_visible - 1));
@@ -512,13 +528,15 @@ Label::VAlign Label::get_valign() const {
}
void Label::set_text(const String &p_string) {
- if (text == p_string)
+ if (text == p_string) {
return;
+ }
text = p_string;
xl_text = tr(p_string);
word_cache_dirty = true;
- if (percent_visible < 1)
+ if (percent_visible < 1) {
visible_chars = get_total_character_count() * percent_visible;
+ }
update();
}
@@ -585,8 +603,9 @@ int Label::get_max_lines_visible() const {
}
int Label::get_total_character_count() const {
- if (word_cache_dirty)
+ if (word_cache_dirty) {
const_cast<Label *>(this)->regenerate_word_cache();
+ }
return total_char_cache;
}
diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp
index fa08f6f512..e3c75491f7 100644
--- a/scene/gui/line_edit.cpp
+++ b/scene/gui/line_edit.cpp
@@ -60,8 +60,9 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
return;
}
- if (b->get_button_index() != BUTTON_LEFT)
+ if (b->get_button_index() != BUTTON_LEFT) {
return;
+ }
_reset_caret_blink_timer();
if (b->is_pressed()) {
@@ -117,8 +118,9 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
selection.creating = false;
selection.doubleclick = false;
- if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_VIRTUAL_KEYBOARD))
+ if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_VIRTUAL_KEYBOARD)) {
DisplayServer::get_singleton()->virtual_keyboard_show(text, get_global_rect(), max_length);
+ }
}
update();
@@ -146,8 +148,9 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
Ref<InputEventKey> k = p_event;
if (k.is_valid()) {
- if (!k->is_pressed())
+ if (!k->is_pressed()) {
return;
+ }
#ifdef APPLE_STYLE_KEYS
if (k->get_control() && !k->get_shift() && !k->get_alt() && !k->get_command()) {
@@ -286,14 +289,16 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
case KEY_KP_ENTER:
case KEY_ENTER: {
emit_signal("text_entered", text);
- if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_VIRTUAL_KEYBOARD))
+ if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_VIRTUAL_KEYBOARD)) {
DisplayServer::get_singleton()->virtual_keyboard_hide();
+ }
} break;
case KEY_BACKSPACE: {
- if (!editable)
+ if (!editable) {
break;
+ }
if (selection.enabled) {
selection_delete();
@@ -314,8 +319,9 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
while (cc > 0) {
bool ischar = _is_text_char(text[cc - 1]);
- if (prev_char && !ischar)
+ if (prev_char && !ischar) {
break;
+ }
prev_char = ischar;
cc--;
@@ -369,8 +375,9 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
while (cc > 0) {
bool ischar = _is_text_char(text[cc - 1]);
- if (prev_char && !ischar)
+ if (prev_char && !ischar) {
break;
+ }
prev_char = ischar;
cc--;
@@ -424,8 +431,9 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
while (cc < text.length()) {
bool ischar = _is_text_char(text[cc]);
- if (prev_char && !ischar)
+ if (prev_char && !ischar) {
break;
+ }
prev_char = ischar;
cc++;
@@ -442,21 +450,24 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
} break;
case KEY_UP: {
shift_selection_check_pre(k->get_shift());
- if (get_cursor_position() == 0)
+ if (get_cursor_position() == 0) {
handled = false;
+ }
set_cursor_position(0);
shift_selection_check_post(k->get_shift());
} break;
case KEY_DOWN: {
shift_selection_check_pre(k->get_shift());
- if (get_cursor_position() == text.length())
+ if (get_cursor_position() == text.length()) {
handled = false;
+ }
set_cursor_position(text.length());
shift_selection_check_post(k->get_shift());
} break;
case KEY_DELETE: {
- if (!editable)
+ if (!editable) {
break;
+ }
if (k->get_shift() && !k->get_command() && !k->get_alt()) {
cut_text();
@@ -470,8 +481,9 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
int text_len = text.length();
- if (cursor_pos == text_len)
+ if (cursor_pos == text_len) {
break; // Nothing to do.
+ }
#ifdef APPLE_STYLE_KEYS
if (k->get_alt()) {
@@ -488,8 +500,9 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
while (cc < text.length()) {
bool ischar = _is_text_char(text[cc]);
- if (prev_char && !ischar)
+ if (prev_char && !ischar) {
break;
+ }
prev_char = ischar;
cc++;
}
@@ -602,8 +615,9 @@ void LineEdit::drop_data(const Point2 &p_point, const Variant &p_data) {
Ref<Font> font = get_theme_font("font");
if (font != nullptr) {
- for (int i = selection.begin; i < selection.end; i++)
+ for (int i = selection.begin; i < selection.end; i++) {
cached_width -= font->get_char_size(pass ? secret_character[0] : text[i]).width;
+ }
}
text.erase(selection.begin, selected);
@@ -701,10 +715,11 @@ void LineEdit::_notification(int p_what) {
x_ofs = style->get_offset().x;
} break;
case ALIGN_CENTER: {
- if (window_pos != 0)
+ if (window_pos != 0) {
x_ofs = style->get_offset().x;
- else
+ } else {
x_ofs = MAX(style->get_margin(MARGIN_LEFT), int(size.width - (cached_text_width)) / 2);
+ }
} break;
case ALIGN_RIGHT: {
x_ofs = MAX(style->get_margin(MARGIN_LEFT), int(size.width - style->get_margin(MARGIN_RIGHT) - (cached_text_width)));
@@ -726,8 +741,9 @@ void LineEdit::_notification(int p_what) {
const String &t = using_placeholder ? placeholder_translated : text;
// Draw placeholder color.
- if (using_placeholder)
+ if (using_placeholder) {
font_color.a *= placeholder_alpha;
+ }
bool display_clear_icon = !using_placeholder && is_editable() && clear_button_enabled;
if (right_icon.is_valid() || display_clear_icon) {
@@ -758,22 +774,25 @@ void LineEdit::_notification(int p_what) {
FontDrawer drawer(font, Color(1, 1, 1));
while (true) {
// End of string, break.
- if (char_ofs >= t.length())
+ if (char_ofs >= t.length()) {
break;
+ }
if (char_ofs == cursor_pos) {
if (ime_text.length() > 0) {
int ofs = 0;
while (true) {
- if (ofs >= ime_text.length())
+ if (ofs >= ime_text.length()) {
break;
+ }
CharType cchar = (pass && !text.empty()) ? secret_character[0] : ime_text[ofs];
CharType next = (pass && !text.empty()) ? secret_character[0] : ime_text[ofs + 1];
int im_char_width = font->get_char_size(cchar, next).width;
- if ((x_ofs + im_char_width) > ofs_max)
+ if ((x_ofs + im_char_width) > ofs_max) {
break;
+ }
bool selected = ofs >= ime_selection.x && ofs < ime_selection.x + ime_selection.y;
if (selected) {
@@ -795,13 +814,15 @@ void LineEdit::_notification(int p_what) {
int char_width = font->get_char_size(cchar, next).width;
// End of widget, break.
- if ((x_ofs + char_width) > ofs_max)
+ if ((x_ofs + char_width) > ofs_max) {
break;
+ }
bool selected = selection.enabled && char_ofs >= selection.begin && char_ofs < selection.end;
- if (selected)
+ if (selected) {
RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(x_ofs, y_ofs), Size2(char_width, caret_height)), selection_color);
+ }
int yofs = y_ofs + (caret_height - font->get_height()) / 2;
drawer.draw_char(ci, Point2(x_ofs, yofs + font_ascent), cchar, next, selected ? font_color_selected : font_color);
@@ -824,15 +845,17 @@ void LineEdit::_notification(int p_what) {
if (ime_text.length() > 0) {
int ofs = 0;
while (true) {
- if (ofs >= ime_text.length())
+ if (ofs >= ime_text.length()) {
break;
+ }
CharType cchar = (pass && !text.empty()) ? secret_character[0] : ime_text[ofs];
CharType next = (pass && !text.empty()) ? secret_character[0] : ime_text[ofs + 1];
int im_char_width = font->get_char_size(cchar, next).width;
- if ((x_ofs + im_char_width) > ofs_max)
+ if ((x_ofs + im_char_width) > ofs_max) {
break;
+ }
bool selected = ofs >= ime_selection.x && ofs < ime_selection.x + ime_selection.y;
if (selected) {
@@ -894,8 +917,9 @@ void LineEdit::_notification(int p_what) {
DisplayServer::get_singleton()->window_set_ime_position(get_global_position() + cursor_pos, get_viewport()->get_window_id());
}
- if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_VIRTUAL_KEYBOARD))
+ if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_VIRTUAL_KEYBOARD)) {
DisplayServer::get_singleton()->virtual_keyboard_show(text, get_global_rect(), max_length);
+ }
} break;
case NOTIFICATION_FOCUS_EXIT: {
@@ -910,8 +934,9 @@ void LineEdit::_notification(int p_what) {
ime_text = "";
ime_selection = Point2();
- if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_VIRTUAL_KEYBOARD))
+ if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_VIRTUAL_KEYBOARD)) {
DisplayServer::get_singleton()->virtual_keyboard_hide();
+ }
} break;
case MainLoop::NOTIFICATION_OS_IME_UPDATE: {
@@ -943,8 +968,9 @@ void LineEdit::paste_text() {
if (paste_buffer != "") {
int prev_len = text.length();
- if (selection.enabled)
+ if (selection.enabled) {
selection_delete();
+ }
append_at_cursor(paste_buffer);
if (!text_changed_dirty) {
@@ -972,8 +998,9 @@ void LineEdit::undo() {
window_pos = op.window_pos;
set_cursor_position(op.cursor_pos);
- if (expand_to_text_length)
+ if (expand_to_text_length) {
minimum_size_changed();
+ }
_emit_text_change();
}
@@ -992,8 +1019,9 @@ void LineEdit::redo() {
window_pos = op.window_pos;
set_cursor_position(op.cursor_pos);
- if (expand_to_text_length)
+ if (expand_to_text_length) {
minimum_size_changed();
+ }
_emit_text_change();
}
@@ -1002,13 +1030,15 @@ void LineEdit::shift_selection_check_pre(bool p_shift) {
if (!selection.enabled && p_shift) {
selection.cursor_start = cursor_pos;
}
- if (!p_shift)
+ if (!p_shift) {
deselect();
+ }
}
void LineEdit::shift_selection_check_post(bool p_shift) {
- if (p_shift)
+ if (p_shift) {
selection_fill_at_cursor();
+ }
}
void LineEdit::set_cursor_at_pixel_pos(int p_x) {
@@ -1026,19 +1056,22 @@ void LineEdit::set_cursor_at_pixel_pos(int p_x) {
pixel_ofs = int(style->get_offset().x);
} break;
case ALIGN_CENTER: {
- if (window_pos != 0)
+ if (window_pos != 0) {
pixel_ofs = int(style->get_offset().x);
- else
+ } else {
pixel_ofs = int(size.width - (cached_width)) / 2;
+ }
- if (display_clear_icon)
+ if (display_clear_icon) {
pixel_ofs -= int(r_icon_width / 2 + style->get_margin(MARGIN_RIGHT));
+ }
} break;
case ALIGN_RIGHT: {
pixel_ofs = int(size.width - style->get_margin(MARGIN_RIGHT) - (cached_width));
- if (display_clear_icon)
+ if (display_clear_icon) {
pixel_ofs -= int(r_icon_width + style->get_margin(MARGIN_RIGHT));
+ }
} break;
}
@@ -1074,19 +1107,22 @@ int LineEdit::get_cursor_pixel_pos() {
pixel_ofs = int(style->get_offset().x);
} break;
case ALIGN_CENTER: {
- if (window_pos != 0)
+ if (window_pos != 0) {
pixel_ofs = int(style->get_offset().x);
- else
+ } else {
pixel_ofs = int(size.width - (cached_width)) / 2;
+ }
- if (display_clear_icon)
+ if (display_clear_icon) {
pixel_ofs -= int(r_icon_width / 2 + style->get_margin(MARGIN_RIGHT));
+ }
} break;
case ALIGN_RIGHT: {
pixel_ofs = int(size.width - style->get_margin(MARGIN_RIGHT) - (cached_width));
- if (display_clear_icon)
+ if (display_clear_icon) {
pixel_ofs -= int(r_icon_width + style->get_margin(MARGIN_RIGHT));
+ }
} break;
}
@@ -1146,8 +1182,9 @@ void LineEdit::_toggle_draw_caret() {
}
void LineEdit::delete_char() {
- if ((text.length() <= 0) || (cursor_pos == 0))
+ if ((text.length() <= 0) || (cursor_pos == 0)) {
return;
+ }
Ref<Font> font = get_theme_font("font");
if (font != nullptr) {
@@ -1169,8 +1206,9 @@ void LineEdit::delete_text(int p_from_column, int p_to_column) {
if (text.size() > 0) {
Ref<Font> font = get_theme_font("font");
if (font != nullptr) {
- for (int i = p_from_column; i < p_to_column; i++)
+ for (int i = p_from_column; i < p_to_column; i++) {
cached_width -= font->get_char_size(pass ? secret_character[0] : text[i]).width;
+ }
}
} else {
cached_width = 0;
@@ -1241,11 +1279,13 @@ float LineEdit::get_placeholder_alpha() const {
}
void LineEdit::set_cursor_position(int p_pos) {
- if (p_pos > (int)text.length())
+ if (p_pos > (int)text.length()) {
p_pos = text.length();
+ }
- if (p_pos < 0)
+ if (p_pos < 0) {
p_pos = 0;
+ }
cursor_pos = p_pos;
@@ -1269,8 +1309,9 @@ void LineEdit::set_cursor_position(int p_pos) {
window_width -= r_icon->get_width();
}
- if (window_width < 0)
+ if (window_width < 0) {
return;
+ }
int wp = window_pos;
if (font.is_valid()) {
@@ -1287,15 +1328,17 @@ void LineEdit::set_cursor_position(int p_pos) {
accum_width += font->get_char_size(text[i], i + 1 < text.length() ? text[i + 1] : 0).width; // Anything should do.
}
}
- if (accum_width > window_width)
+ if (accum_width > window_width) {
break;
+ }
wp = i;
}
}
- if (wp != window_pos)
+ if (wp != window_pos) {
set_window_pos(wp);
+ }
}
update();
}
@@ -1306,8 +1349,9 @@ int LineEdit::get_cursor_position() const {
void LineEdit::set_window_pos(int p_pos) {
window_pos = p_pos;
- if (window_pos < 0)
+ if (window_pos < 0) {
window_pos = 0;
+ }
}
void LineEdit::append_at_cursor(String p_text) {
@@ -1374,8 +1418,9 @@ void LineEdit::deselect() {
}
void LineEdit::selection_delete() {
- if (selection.enabled)
+ if (selection.enabled) {
delete_text(selection.begin, selection.end);
+ }
deselect();
}
@@ -1391,8 +1436,9 @@ int LineEdit::get_max_length() const {
}
void LineEdit::selection_fill_at_cursor() {
- if (!selecting_enabled)
+ if (!selecting_enabled) {
return;
+ }
selection.begin = cursor_pos;
selection.end = selection.cursor_start;
@@ -1407,11 +1453,13 @@ void LineEdit::selection_fill_at_cursor() {
}
void LineEdit::select_all() {
- if (!selecting_enabled)
+ if (!selecting_enabled) {
return;
+ }
- if (!text.length())
+ if (!text.length()) {
return;
+ }
selection.begin = 0;
selection.end = text.length();
@@ -1420,8 +1468,9 @@ void LineEdit::select_all() {
}
void LineEdit::set_editable(bool p_editable) {
- if (editable == p_editable)
+ if (editable == p_editable) {
return;
+ }
editable = p_editable;
_generate_context_menu();
@@ -1459,8 +1508,9 @@ String LineEdit::get_secret_character() const {
}
void LineEdit::select(int p_from, int p_to) {
- if (!selecting_enabled)
+ if (!selecting_enabled) {
return;
+ }
if (p_from == 0 && p_to == 0) {
deselect();
@@ -1468,15 +1518,19 @@ void LineEdit::select(int p_from, int p_to) {
}
int len = text.length();
- if (p_from < 0)
+ if (p_from < 0) {
p_from = 0;
- if (p_from > len)
+ }
+ if (p_from > len) {
p_from = len;
- if (p_to < 0 || p_to > len)
+ }
+ if (p_to < 0 || p_to > len) {
p_to = len;
+ }
- if (p_from >= p_to)
+ if (p_from >= p_to) {
return;
+ }
selection.enabled = true;
selection.begin = p_from;
@@ -1581,8 +1635,9 @@ bool LineEdit::is_shortcut_keys_enabled() const {
void LineEdit::set_selecting_enabled(bool p_enabled) {
selecting_enabled = p_enabled;
- if (!selecting_enabled)
+ if (!selecting_enabled) {
deselect();
+ }
_generate_context_menu();
}
@@ -1605,8 +1660,9 @@ Ref<Texture2D> LineEdit::get_right_icon() {
}
void LineEdit::_text_changed() {
- if (expand_to_text_length)
+ if (expand_to_text_length) {
minimum_size_changed();
+ }
_emit_text_change();
_clear_redo();
@@ -1672,14 +1728,17 @@ void LineEdit::_create_undo_state() {
void LineEdit::_generate_context_menu() {
// Reorganize context menu.
menu->clear();
- if (editable)
+ if (editable) {
menu->add_item(RTR("Cut"), MENU_CUT, is_shortcut_keys_enabled() ? KEY_MASK_CMD | KEY_X : 0);
+ }
menu->add_item(RTR("Copy"), MENU_COPY, is_shortcut_keys_enabled() ? KEY_MASK_CMD | KEY_C : 0);
- if (editable)
+ if (editable) {
menu->add_item(RTR("Paste"), MENU_PASTE, is_shortcut_keys_enabled() ? KEY_MASK_CMD | KEY_V : 0);
+ }
menu->add_separator();
- if (is_selecting_enabled())
+ if (is_selecting_enabled()) {
menu->add_item(RTR("Select All"), MENU_SELECT_ALL, is_shortcut_keys_enabled() ? KEY_MASK_CMD | KEY_A : 0);
+ }
if (editable) {
menu->add_item(RTR("Clear"), MENU_CLEAR);
menu->add_separator();
diff --git a/scene/gui/link_button.cpp b/scene/gui/link_button.cpp
index d772b257fc..f8c8bd4caf 100644
--- a/scene/gui/link_button.cpp
+++ b/scene/gui/link_button.cpp
@@ -68,10 +68,11 @@ void LinkButton::_notification(int p_what) {
} break;
case DRAW_HOVER_PRESSED:
case DRAW_PRESSED: {
- if (has_theme_color("font_color_pressed"))
+ if (has_theme_color("font_color_pressed")) {
color = get_theme_color("font_color_pressed");
- else
+ } else {
color = get_theme_color("font_color");
+ }
do_underline = underline_mode != UNDERLINE_MODE_NEVER;
diff --git a/scene/gui/margin_container.cpp b/scene/gui/margin_container.cpp
index 3f5bc43d93..0299065f77 100644
--- a/scene/gui/margin_container.cpp
+++ b/scene/gui/margin_container.cpp
@@ -40,18 +40,23 @@ Size2 MarginContainer::get_minimum_size() const {
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c)
+ if (!c) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
- if (!c->is_visible())
+ }
+ if (!c->is_visible()) {
continue;
+ }
Size2 s = c->get_combined_minimum_size();
- if (s.width > max.width)
+ if (s.width > max.width) {
max.width = s.width;
- if (s.height > max.height)
+ }
+ if (s.height > max.height) {
max.height = s.height;
+ }
}
max.width += (margin_left + margin_right);
@@ -72,10 +77,12 @@ void MarginContainer::_notification(int p_what) {
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c)
+ if (!c) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
+ }
int w = s.width - margin_left - margin_right;
int h = s.height - margin_top - margin_bottom;
diff --git a/scene/gui/menu_button.cpp b/scene/gui/menu_button.cpp
index 2593784cbd..aa69fb39e7 100644
--- a/scene/gui/menu_button.cpp
+++ b/scene/gui/menu_button.cpp
@@ -34,18 +34,21 @@
#include "scene/main/window.h"
void MenuButton::_unhandled_key_input(Ref<InputEvent> p_event) {
- if (disable_shortcuts)
+ if (disable_shortcuts) {
return;
+ }
if (p_event->is_pressed() && !p_event->is_echo() && (Object::cast_to<InputEventKey>(p_event.ptr()) || Object::cast_to<InputEventJoypadButton>(p_event.ptr()) || Object::cast_to<InputEventAction>(*p_event))) {
- if (!get_parent() || !is_visible_in_tree() || is_disabled())
+ if (!get_parent() || !is_visible_in_tree() || is_disabled()) {
return;
+ }
//bool global_only = (get_viewport()->get_modal_stack_top() && !get_viewport()->get_modal_stack_top()->is_a_parent_of(this));
//if (popup->activate_item_by_event(p_event, global_only))
// accept_event();
- if (popup->activate_item_by_event(p_event, false))
+ if (popup->activate_item_by_event(p_event, false)) {
accept_event();
+ }
}
}
diff --git a/scene/gui/nine_patch_rect.cpp b/scene/gui/nine_patch_rect.cpp
index 4d94bbf5d9..bc71ae94f5 100644
--- a/scene/gui/nine_patch_rect.cpp
+++ b/scene/gui/nine_patch_rect.cpp
@@ -34,8 +34,9 @@
void NinePatchRect::_notification(int p_what) {
if (p_what == NOTIFICATION_DRAW) {
- if (texture.is_null())
+ if (texture.is_null()) {
return;
+ }
Rect2 rect = Rect2(Point2(), get_size());
Rect2 src_rect = region_rect;
@@ -86,8 +87,9 @@ void NinePatchRect::_bind_methods() {
}
void NinePatchRect::set_texture(const Ref<Texture2D> &p_tex) {
- if (texture == p_tex)
+ if (texture == p_tex) {
return;
+ }
texture = p_tex;
update();
/*
@@ -130,8 +132,9 @@ int NinePatchRect::get_patch_margin(Margin p_margin) const {
}
void NinePatchRect::set_region_rect(const Rect2 &p_region_rect) {
- if (region_rect == p_region_rect)
+ if (region_rect == p_region_rect) {
return;
+ }
region_rect = p_region_rect;
diff --git a/scene/gui/option_button.cpp b/scene/gui/option_button.cpp
index bc4eec5ba3..e7de0f0912 100644
--- a/scene/gui/option_button.cpp
+++ b/scene/gui/option_button.cpp
@@ -52,8 +52,9 @@ Size2 OptionButton::get_minimum_size() const {
void OptionButton::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_DRAW: {
- if (!has_theme_icon("arrow"))
+ if (!has_theme_icon("arrow")) {
return;
+ }
RID ci = get_canvas_item();
Ref<Texture2D> arrow = Control::get_theme_icon("arrow");
@@ -109,28 +110,32 @@ void OptionButton::pressed() {
void OptionButton::add_icon_item(const Ref<Texture2D> &p_icon, const String &p_label, int p_id) {
popup->add_icon_radio_check_item(p_icon, p_label, p_id);
- if (popup->get_item_count() == 1)
+ if (popup->get_item_count() == 1) {
select(0);
+ }
}
void OptionButton::add_item(const String &p_label, int p_id) {
popup->add_radio_check_item(p_label, p_id);
- if (popup->get_item_count() == 1)
+ if (popup->get_item_count() == 1) {
select(0);
+ }
}
void OptionButton::set_item_text(int p_idx, const String &p_text) {
popup->set_item_text(p_idx, p_text);
- if (current == p_idx)
+ if (current == p_idx) {
set_text(p_text);
+ }
}
void OptionButton::set_item_icon(int p_idx, const Ref<Texture2D> &p_icon) {
popup->set_item_icon(p_idx, p_icon);
- if (current == p_idx)
+ if (current == p_idx) {
set_icon(p_icon);
+ }
}
void OptionButton::set_item_id(int p_idx, int p_id) {
@@ -184,10 +189,12 @@ void OptionButton::clear() {
}
void OptionButton::_select(int p_which, bool p_emit) {
- if (p_which < 0)
+ if (p_which < 0) {
return;
- if (p_which == current)
+ }
+ if (p_which == current) {
return;
+ }
ERR_FAIL_INDEX(p_which, popup->get_item_count());
@@ -199,13 +206,15 @@ void OptionButton::_select(int p_which, bool p_emit) {
set_text(popup->get_item_text(current));
set_icon(popup->get_item_icon(current));
- if (is_inside_tree() && p_emit)
+ if (is_inside_tree() && p_emit) {
emit_signal("item_selected", current);
+ }
}
void OptionButton::_select_int(int p_which) {
- if (p_which < 0 || p_which >= popup->get_item_count())
+ if (p_which < 0 || p_which >= popup->get_item_count()) {
return;
+ }
_select(p_which, false);
}
@@ -219,15 +228,17 @@ int OptionButton::get_selected() const {
int OptionButton::get_selected_id() const {
int idx = get_selected();
- if (idx < 0)
+ if (idx < 0) {
return 0;
+ }
return get_item_id(current);
}
Variant OptionButton::get_selected_metadata() const {
int idx = get_selected();
- if (idx < 0)
+ if (idx < 0) {
return Variant();
+ }
return get_item_metadata(current);
}
diff --git a/scene/gui/panel_container.cpp b/scene/gui/panel_container.cpp
index 6cac15d9f0..9abdfac009 100644
--- a/scene/gui/panel_container.cpp
+++ b/scene/gui/panel_container.cpp
@@ -33,26 +33,30 @@
Size2 PanelContainer::get_minimum_size() const {
Ref<StyleBox> style;
- if (has_theme_stylebox("panel"))
+ if (has_theme_stylebox("panel")) {
style = get_theme_stylebox("panel");
- else
+ } else {
style = get_theme_stylebox("panel", "PanelContainer");
+ }
Size2 ms;
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c || !c->is_visible())
+ if (!c || !c->is_visible()) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
+ }
Size2 minsize = c->get_combined_minimum_size();
ms.width = MAX(ms.width, minsize.width);
ms.height = MAX(ms.height, minsize.height);
}
- if (style.is_valid())
+ if (style.is_valid()) {
ms += style->get_minimum_size();
+ }
return ms;
}
@@ -61,10 +65,11 @@ void PanelContainer::_notification(int p_what) {
RID ci = get_canvas_item();
Ref<StyleBox> style;
- if (has_theme_stylebox("panel"))
+ if (has_theme_stylebox("panel")) {
style = get_theme_stylebox("panel");
- else
+ } else {
style = get_theme_stylebox("panel", "PanelContainer");
+ }
style->draw(ci, Rect2(Point2(), get_size()));
}
@@ -72,10 +77,11 @@ void PanelContainer::_notification(int p_what) {
if (p_what == NOTIFICATION_SORT_CHILDREN) {
Ref<StyleBox> style;
- if (has_theme_stylebox("panel"))
+ if (has_theme_stylebox("panel")) {
style = get_theme_stylebox("panel");
- else
+ } else {
style = get_theme_stylebox("panel", "PanelContainer");
+ }
Size2 size = get_size();
Point2 ofs;
@@ -86,10 +92,12 @@ void PanelContainer::_notification(int p_what) {
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c || !c->is_visible_in_tree())
+ if (!c || !c->is_visible_in_tree()) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
+ }
fit_child_in_rect(c, Rect2(ofs, size));
}
diff --git a/scene/gui/popup.cpp b/scene/gui/popup.cpp
index e1fcb8c2fc..5fc5f9b669 100644
--- a/scene/gui/popup.cpp
+++ b/scene/gui/popup.cpp
@@ -151,11 +151,13 @@ Size2 PopupPanel::_get_contents_minimum_size() const {
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c || c == panel)
+ if (!c || c == panel) {
continue;
+ }
- if (c->is_set_as_toplevel())
+ if (c->is_set_as_toplevel()) {
continue;
+ }
Size2 cms = c->get_combined_minimum_size();
ms.x = MAX(cms.x, ms.x);
@@ -173,11 +175,13 @@ void PopupPanel::_update_child_rects() {
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c)
+ if (!c) {
continue;
+ }
- if (c->is_set_as_toplevel())
+ if (c->is_set_as_toplevel()) {
continue;
+ }
if (c == panel) {
c->set_position(Vector2());
diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp
index c5c6305315..b439d85983 100644
--- a/scene/gui/popup_menu.cpp
+++ b/scene/gui/popup_menu.cpp
@@ -40,10 +40,11 @@
String PopupMenu::_get_accel_text(int p_item) const {
ERR_FAIL_INDEX_V(p_item, items.size(), String());
- if (items[p_item].shortcut.is_valid())
+ if (items[p_item].shortcut.is_valid()) {
return items[p_item].shortcut->get_as_text();
- else if (items[p_item].accel)
+ } else if (items[p_item].accel) {
return keycode_get_string(items[p_item].accel);
+ }
return String();
}
@@ -73,13 +74,15 @@ Size2 PopupMenu::_get_contents_minimum_size() const {
size.width += items[i].h_ofs;
- if (items[i].checkable_type)
+ if (items[i].checkable_type) {
has_check = true;
+ }
String text = items[i].xl_text;
size.width += font->get_string_size(text).width;
- if (i > 0)
+ if (i > 0) {
size.height += vseparation;
+ }
if (items[i].accel || (items[i].shortcut.is_valid() && items[i].shortcut->is_valid())) {
int accel_w = hseparation * 2;
@@ -87,8 +90,9 @@ Size2 PopupMenu::_get_contents_minimum_size() const {
accel_max_w = MAX(accel_w, accel_max_w);
}
- if (items[i].submenu != "")
+ if (items[i].submenu != "") {
size.width += get_theme_icon("submenu")->get_width();
+ }
max_w = MAX(max_w, size.width);
@@ -96,22 +100,25 @@ Size2 PopupMenu::_get_contents_minimum_size() const {
}
minsize.width += max_w + icon_w + accel_max_w;
- if (has_check)
+ if (has_check) {
minsize.width += check_w;
+ }
return minsize;
}
int PopupMenu::_get_mouse_over(const Point2 &p_over) const {
- if (p_over.x < 0 || p_over.x >= get_size().width)
+ if (p_over.x < 0 || p_over.x >= get_size().width) {
return -1;
+ }
Ref<StyleBox> style = get_theme_stylebox("panel");
Point2 ofs = style->get_offset();
- if (ofs.y > p_over.y)
+ if (ofs.y > p_over.y) {
return -1;
+ }
Ref<Font> font = get_theme_font("font");
int vseparation = get_theme_constant("vseparation");
@@ -142,8 +149,9 @@ void PopupMenu::_activate_submenu(int over) {
ERR_FAIL_COND_MSG(!n, "Item subnode does not exist: " + items[over].submenu + ".");
Popup *pm = Object::cast_to<Popup>(n);
ERR_FAIL_COND_MSG(!pm, "Item subnode is not a Popup: " + items[over].submenu + ".");
- if (pm->is_visible())
+ if (pm->is_visible()) {
return; //already visible!
+ }
Point2 p = get_position();
Rect2 pr(p, get_size());
@@ -152,8 +160,9 @@ void PopupMenu::_activate_submenu(int over) {
Point2 pos = p + Point2(get_size().width, items[over]._ofs_cache - style->get_offset().y);
Size2 size = pm->get_size();
// fix pos
- if (pos.x + size.width > get_parent_rect().size.width)
+ if (pos.x + size.width > get_parent_rect().size.width) {
pos.x = p.x - size.width;
+ }
pm->set_position(pos);
// pm->set_scale(get_global_transform().get_scale());
@@ -175,8 +184,9 @@ void PopupMenu::_submenu_timeout() {
//if (!has_focus()) {
// return; //do not activate if not has focus
//}
- if (mouse_over == submenu_over)
+ if (mouse_over == submenu_over) {
_activate_submenu(mouse_over);
+ }
submenu_over = -1;
}
@@ -214,12 +224,14 @@ void PopupMenu::_scroll(float p_factor, const Point2 &p_over) {
void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) {
if (p_event->is_action("ui_down") && p_event->is_pressed()) {
int search_from = mouse_over + 1;
- if (search_from >= items.size())
+ if (search_from >= items.size()) {
search_from = 0;
+ }
for (int i = search_from; i < items.size(); i++) {
- if (i < 0 || i >= items.size())
+ if (i < 0 || i >= items.size()) {
continue;
+ }
if (!items[i].separator && !items[i].disabled) {
mouse_over = i;
@@ -231,12 +243,14 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) {
}
} else if (p_event->is_action("ui_up") && p_event->is_pressed()) {
int search_from = mouse_over - 1;
- if (search_from < 0)
+ if (search_from < 0) {
search_from = items.size() - 1;
+ }
for (int i = search_from; i >= 0; i--) {
- if (i >= items.size())
+ if (i >= items.size()) {
continue;
+ }
if (!items[i].separator && !items[i].disabled) {
mouse_over = i;
@@ -271,8 +285,9 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) {
Ref<InputEventMouseButton> b = p_event;
if (b.is_valid()) {
- if (b->is_pressed())
+ if (b->is_pressed()) {
return;
+ }
int button_idx = b->get_button_index();
switch (button_idx) {
@@ -302,8 +317,9 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) {
break; //non-activable
}
- if (items[over].separator || items[over].disabled)
+ if (items[over].separator || items[over].disabled) {
break;
+ }
if (items[over].submenu != "") {
_activate_submenu(over);
@@ -322,8 +338,9 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) {
if (m.is_valid()) {
if (invalidated_click) {
moved += m->get_relative();
- if (moved.length() > 4)
+ if (moved.length() > 4) {
invalidated_click = false;
+ }
}
for (List<Rect2>::Element *E = autohide_areas.front(); E; E = E->next()) {
@@ -370,19 +387,22 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) {
search_string = "";
}
- if (String::chr(k->get_unicode()) != search_string)
+ if (String::chr(k->get_unicode()) != search_string) {
search_string += String::chr(k->get_unicode());
+ }
for (int i = mouse_over + 1; i <= items.size(); i++) {
if (i == items.size()) {
- if (mouse_over <= 0)
+ if (mouse_over <= 0) {
break;
- else
+ } else {
i = 0;
+ }
}
- if (i == mouse_over)
+ if (i == mouse_over) {
break;
+ }
if (items[i].text.findn(search_string) == 0) {
mouse_over = i;
@@ -424,22 +444,27 @@ void PopupMenu::_draw() {
float icon_ofs = 0.0;
bool has_check = false;
for (int i = 0; i < items.size(); i++) {
- if (!items[i].icon.is_null())
+ if (!items[i].icon.is_null()) {
icon_ofs = MAX(items[i].icon->get_size().width, icon_ofs);
+ }
- if (items[i].checkable_type)
+ if (items[i].checkable_type) {
has_check = true;
+ }
}
- if (icon_ofs > 0.0)
+ if (icon_ofs > 0.0) {
icon_ofs += hseparation;
+ }
float check_ofs = 0.0;
- if (has_check)
+ if (has_check) {
check_ofs = MAX(get_theme_icon("checked")->get_width(), get_theme_icon("radio_checked")->get_width()) + hseparation;
+ }
for (int i = 0; i < items.size(); i++) {
- if (i > 0)
+ if (i > 0) {
ofs.y += vseparation;
+ }
Point2 item_ofs = ofs;
Size2 icon_size;
float h;
@@ -570,16 +595,19 @@ void PopupMenu::_notification(int p_what) {
}
for (int i = 0; i < items.size(); i++) {
- if (items[i].submenu == "")
+ if (items[i].submenu == "") {
continue;
+ }
Node *n = get_node(items[i].submenu);
- if (!n)
+ if (!n) {
continue;
+ }
PopupMenu *pm = Object::cast_to<PopupMenu>(n);
- if (!pm || !pm->is_visible())
+ if (!pm || !pm->is_visible()) {
continue;
+ }
pm->hide();
}
@@ -826,8 +854,9 @@ String PopupMenu::get_item_text(int p_idx) const {
int PopupMenu::get_item_idx_from_text(const String &text) const {
for (int idx = 0; idx < items.size(); idx++) {
- if (items[idx].text == text)
+ if (items[idx].text == text) {
return idx;
+ }
}
return -1;
@@ -865,8 +894,9 @@ int PopupMenu::get_item_id(int p_idx) const {
int PopupMenu::get_item_index(int p_id) const {
for (int i = 0; i < items.size(); i++) {
- if (items[i].id == p_id)
+ if (items[i].id == p_id) {
return i;
+ }
}
return -1;
@@ -962,8 +992,9 @@ void PopupMenu::toggle_item_multistate(int p_idx) {
}
++items.write[p_idx].state;
- if (items.write[p_idx].max_states <= items[p_idx].state)
+ if (items.write[p_idx].max_states <= items[p_idx].state) {
items.write[p_idx].state = 0;
+ }
control->update();
}
@@ -997,21 +1028,27 @@ bool PopupMenu::activate_item_by_event(const Ref<InputEvent> &p_event, bool p_fo
if (k.is_valid()) {
code = k->get_keycode();
- if (code == 0)
+ if (code == 0) {
code = k->get_unicode();
- if (k->get_control())
+ }
+ if (k->get_control()) {
code |= KEY_MASK_CTRL;
- if (k->get_alt())
+ }
+ if (k->get_alt()) {
code |= KEY_MASK_ALT;
- if (k->get_metakey())
+ }
+ if (k->get_metakey()) {
code |= KEY_MASK_META;
- if (k->get_shift())
+ }
+ if (k->get_shift()) {
code |= KEY_MASK_SHIFT;
+ }
}
for (int i = 0; i < items.size(); i++) {
- if (is_item_disabled(i) || items[i].shortcut_is_disabled)
+ if (is_item_disabled(i) || items[i].shortcut_is_disabled) {
continue;
+ }
if (items[i].shortcut.is_valid() && items[i].shortcut->is_shortcut(p_event) && (items[i].shortcut_is_global || !p_for_global_only)) {
activate_item(i);
@@ -1025,12 +1062,14 @@ bool PopupMenu::activate_item_by_event(const Ref<InputEvent> &p_event, bool p_fo
if (items[i].submenu != "") {
Node *n = get_node(items[i].submenu);
- if (!n)
+ if (!n) {
continue;
+ }
PopupMenu *pm = Object::cast_to<PopupMenu>(n);
- if (!pm)
+ if (!pm) {
continue;
+ }
if (pm->activate_item_by_event(p_event, p_for_global_only)) {
return true;
@@ -1053,13 +1092,16 @@ void PopupMenu::activate_item(int p_item) {
// with hide_on_item_selection enabled
if (items[p_item].checkable_type) {
- if (!hide_on_checkable_item_selection || !pop->is_hide_on_checkable_item_selection())
+ if (!hide_on_checkable_item_selection || !pop->is_hide_on_checkable_item_selection()) {
break;
+ }
} else if (0 < items[p_item].max_states) {
- if (!hide_on_multistate_item_selection || !pop->is_hide_on_multistate_item_selection())
+ if (!hide_on_multistate_item_selection || !pop->is_hide_on_multistate_item_selection()) {
break;
- } else if (!hide_on_item_selection || !pop->is_hide_on_item_selection())
+ }
+ } else if (!hide_on_item_selection || !pop->is_hide_on_item_selection()) {
break;
+ }
pop->hide();
next = next->get_parent();
@@ -1072,13 +1114,16 @@ void PopupMenu::activate_item(int p_item) {
bool need_hide = true;
if (items[p_item].checkable_type) {
- if (!hide_on_checkable_item_selection)
+ if (!hide_on_checkable_item_selection) {
need_hide = false;
+ }
} else if (0 < items[p_item].max_states) {
- if (!hide_on_multistate_item_selection)
+ if (!hide_on_multistate_item_selection) {
need_hide = false;
- } else if (!hide_on_item_selection)
+ }
+ } else if (!hide_on_item_selection) {
need_hide = false;
+ }
emit_signal("id_pressed", id);
emit_signal("index_pressed", p_item);
@@ -1228,8 +1273,9 @@ bool PopupMenu::is_hide_on_multistate_item_selection() const {
}
void PopupMenu::set_submenu_popup_delay(float p_time) {
- if (p_time <= 0)
+ if (p_time <= 0) {
p_time = 0.01;
+ }
submenu_timer->set_wait_time(p_time);
}
@@ -1248,8 +1294,9 @@ bool PopupMenu::get_allow_search() const {
String PopupMenu::get_tooltip(const Point2 &p_pos) const {
int over = _get_mouse_over(p_pos);
- if (over < 0 || over >= items.size())
+ if (over < 0 || over >= items.size()) {
return "";
+ }
return items[over].tooltip;
}
@@ -1259,8 +1306,9 @@ void PopupMenu::set_parent_rect(const Rect2 &p_rect) {
void PopupMenu::get_translatable_strings(List<String> *p_strings) const {
for (int i = 0; i < items.size(); i++) {
- if (items[i].xl_text != "")
+ if (items[i].xl_text != "") {
p_strings->push_back(items[i].xl_text);
+ }
}
}
diff --git a/scene/gui/range.cpp b/scene/gui/range.cpp
index 9e30063c5b..59e26d9e38 100644
--- a/scene/gui/range.cpp
+++ b/scene/gui/range.cpp
@@ -53,8 +53,9 @@ void Range::_value_changed_notify() {
void Range::Shared::emit_value_changed() {
for (Set<Range *>::Element *E = owners.front(); E; E = E->next()) {
Range *r = E->get();
- if (!r->is_inside_tree())
+ if (!r->is_inside_tree()) {
continue;
+ }
r->_value_changed_notify();
}
}
@@ -68,27 +69,33 @@ void Range::_changed_notify(const char *p_what) {
void Range::Shared::emit_changed(const char *p_what) {
for (Set<Range *>::Element *E = owners.front(); E; E = E->next()) {
Range *r = E->get();
- if (!r->is_inside_tree())
+ if (!r->is_inside_tree()) {
continue;
+ }
r->_changed_notify(p_what);
}
}
void Range::set_value(double p_val) {
- if (shared->step > 0)
+ if (shared->step > 0) {
p_val = Math::round(p_val / shared->step) * shared->step;
+ }
- if (_rounded_values)
+ if (_rounded_values) {
p_val = Math::round(p_val);
+ }
- if (!shared->allow_greater && p_val > shared->max - shared->page)
+ if (!shared->allow_greater && p_val > shared->max - shared->page) {
p_val = shared->max - shared->page;
+ }
- if (!shared->allow_lesser && p_val < shared->min)
+ if (!shared->allow_lesser && p_val < shared->min) {
p_val = shared->min;
+ }
- if (shared->val == p_val)
+ if (shared->val == p_val) {
return;
+ }
shared->val = p_val;
@@ -209,8 +216,9 @@ void Range::unshare() {
}
void Range::_ref_shared(Shared *p_shared) {
- if (shared && p_shared == shared)
+ if (shared && p_shared == shared) {
return;
+ }
_unref_shared();
shared = p_shared;
diff --git a/scene/gui/reference_rect.cpp b/scene/gui/reference_rect.cpp
index 0f6ff4da26..27c57c684a 100644
--- a/scene/gui/reference_rect.cpp
+++ b/scene/gui/reference_rect.cpp
@@ -34,10 +34,12 @@
void ReferenceRect::_notification(int p_what) {
if (p_what == NOTIFICATION_DRAW) {
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
- if (Engine::get_singleton()->is_editor_hint() || !editor_only)
+ }
+ if (Engine::get_singleton()->is_editor_hint() || !editor_only) {
draw_rect(Rect2(Point2(), get_size()), border_color, false);
+ }
}
}
diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp
index d73c61f0f2..a57408b83b 100644
--- a/scene/gui/rich_text_label.cpp
+++ b/scene/gui/rich_text_label.cpp
@@ -59,10 +59,11 @@ RichTextLabel::Item *RichTextLabel::_get_next_item(Item *p_item, bool p_free) {
p_item = p_item->parent;
}
- if (p_item->parent)
+ if (p_item->parent) {
return p_item->E->next()->get();
- else
+ } else {
return nullptr;
+ }
}
} else {
@@ -78,10 +79,11 @@ RichTextLabel::Item *RichTextLabel::_get_next_item(Item *p_item, bool p_free) {
p_item = p_item->parent;
}
- if (p_item->type != ITEM_FRAME)
+ if (p_item->type != ITEM_FRAME) {
return p_item->E->next()->get();
- else
+ } else {
return nullptr;
+ }
}
}
@@ -102,10 +104,11 @@ RichTextLabel::Item *RichTextLabel::_get_prev_item(Item *p_item, bool p_free) {
p_item = p_item->parent;
}
- if (p_item->parent)
+ if (p_item->parent) {
return p_item->E->prev()->get();
- else
+ } else {
return nullptr;
+ }
}
} else {
@@ -121,10 +124,11 @@ RichTextLabel::Item *RichTextLabel::_get_prev_item(Item *p_item, bool p_free) {
p_item = p_item->parent;
}
- if (p_item->type != ITEM_FRAME)
+ if (p_item->type != ITEM_FRAME) {
return p_item->E->prev()->get();
- else
+ } else {
return nullptr;
+ }
}
}
@@ -140,13 +144,15 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
ERR_FAIL_INDEX_V((int)p_mode, 3, 0);
RID ci;
- if (r_outside)
+ if (r_outside) {
*r_outside = false;
+ }
if (p_mode == PROCESS_DRAW) {
ci = get_canvas_item();
- if (r_click_item)
+ if (r_click_item) {
*r_click_item = nullptr;
+ }
}
Line &l = p_frame->lines.write[p_line];
Item *it = l.from;
@@ -178,14 +184,16 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
int spaces_size = 0;
int align_ofs = 0;
- if (p_mode != PROCESS_CACHE && align != ALIGN_FILL)
+ if (p_mode != PROCESS_CACHE && align != ALIGN_FILL) {
wofs += line_ofs;
+ }
int begin = wofs;
Ref<Font> cfont = _find_font(it);
- if (cfont.is_null())
+ if (cfont.is_null()) {
cfont = p_base_font;
+ }
//line height should be the font height for the first time, this ensures that an empty line will never have zero height and successive newlines are displayed
int line_height = cfont->get_height();
@@ -337,8 +345,9 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
ItemText *text = static_cast<ItemText *>(it);
Ref<Font> font = _find_font(it);
- if (font.is_null())
+ if (font.is_null()) {
font = p_base_font;
+ }
const CharType *c = text->text.c_str();
const CharType *cf = c;
@@ -542,8 +551,9 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
w += font->get_char_size(c[i], c[i + 1]).x;
}
- if (c[i] == '\t')
+ if (c[i] == '\t') {
visible = false;
+ }
if (visible) {
if (selected) {
@@ -611,25 +621,29 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
} break;
case ITEM_IMAGE: {
lh = 0;
- if (p_mode != PROCESS_CACHE)
+ if (p_mode != PROCESS_CACHE) {
lh = line < l.height_caches.size() ? l.height_caches[line] : 1;
- else
+ } else {
l.char_count += 1; //images count as chars too
+ }
ItemImage *img = static_cast<ItemImage *>(it);
Ref<Font> font = _find_font(it);
- if (font.is_null())
+ if (font.is_null()) {
font = p_base_font;
+ }
- if (p_mode == PROCESS_POINTER && r_click_char)
+ if (p_mode == PROCESS_POINTER && r_click_char) {
*r_click_char = 0;
+ }
ENSURE_WIDTH(img->size.width);
bool visible = visible_characters < 0 || (p_char_count < visible_characters && YRANGE_VISIBLE(y + lh - font->get_descent() - img->size.height, img->size.height));
- if (visible)
+ if (visible) {
line_is_blank = false;
+ }
if (p_mode == PROCESS_DRAW && visible) {
img->image->draw_rect(ci, Rect2(p_ofs + Point2(align_ofs + wofs, y + lh - font->get_descent() - img->size.height), img->size));
@@ -695,17 +709,20 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
for (int i = 0; i < table->columns.size(); i++) {
remaining_width -= table->columns[i].min_width;
- if (table->columns[i].max_width > table->columns[i].min_width)
+ if (table->columns[i].max_width > table->columns[i].min_width) {
table->columns.write[i].expand = true;
- if (table->columns[i].expand)
+ }
+ if (table->columns[i].expand) {
total_ratio += table->columns[i].expand_ratio;
+ }
}
//assign actual widths
for (int i = 0; i < table->columns.size(); i++) {
table->columns.write[i].width = table->columns[i].min_width;
- if (table->columns[i].expand && total_ratio > 0)
+ if (table->columns[i].expand && total_ratio > 0) {
table->columns.write[i].width += table->columns[i].expand_ratio * remaining_width / total_ratio;
+ }
table->total_width += table->columns[i].width + hseparation;
}
@@ -715,8 +732,9 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
table_need_fit = false;
//fit slim
for (int i = 0; i < table->columns.size(); i++) {
- if (!table->columns[i].expand)
+ if (!table->columns[i].expand) {
continue;
+ }
int dif = table->columns[i].width - table->columns[i].max_width;
if (dif > 0) {
table_need_fit = true;
@@ -778,8 +796,9 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
int lines_ofs = p_ofs.y + offset.y + draw_ofs.y;
bool visible = lines_ofs < get_size().height && lines_ofs + lines_h >= 0;
- if (visible)
+ if (visible) {
line_is_blank = false;
+ }
for (int i = 0; i < frame->lines.size(); i++) {
if (visible) {
@@ -831,8 +850,9 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
if (it && (p_line + 1 < p_frame->lines.size()) && p_frame->lines[p_line + 1].from == it) {
if (p_mode == PROCESS_POINTER && r_click_item && p_click_pos.y >= p_ofs.y + y && p_click_pos.y <= p_ofs.y + y + lh) {
//went to next line, but pointer was on the previous one
- if (r_outside)
+ if (r_outside) {
*r_outside = true;
+ }
*r_click_item = itp;
*r_click_char = rchar;
RETURN;
@@ -853,13 +873,15 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
}
void RichTextLabel::_scroll_changed(double) {
- if (updating_scroll || !scroll_active)
+ if (updating_scroll || !scroll_active) {
return;
+ }
- if (scroll_follow && vscroll->get_value() >= (vscroll->get_max() - vscroll->get_page()))
+ if (scroll_follow && vscroll->get_value() >= (vscroll->get_max() - vscroll->get_page())) {
scroll_following = true;
- else
+ } else {
scroll_following = false;
+ }
scroll_updated = true;
@@ -938,8 +960,9 @@ void RichTextLabel::_notification(int p_what) {
} break;
case NOTIFICATION_ENTER_TREE: {
- if (bbcode != "")
+ if (bbcode != "") {
set_bbcode(bbcode);
+ }
main->first_invalid_line = 0; //invalidate ALL
update();
@@ -973,14 +996,16 @@ void RichTextLabel::_notification(int p_what) {
int from_line = 0;
int total_chars = 0;
while (from_line < main->lines.size()) {
- if (main->lines[from_line].height_accum_cache + _get_text_rect().get_position().y >= ofs)
+ if (main->lines[from_line].height_accum_cache + _get_text_rect().get_position().y >= ofs) {
break;
+ }
total_chars += main->lines[from_line].char_count;
from_line++;
}
- if (from_line >= main->lines.size())
+ if (from_line >= main->lines.size()) {
break; //nothing to draw
+ }
int y = (main->lines[from_line].height_accum_cache - main->lines[from_line].height_cache) - ofs;
Ref<Font> base_font = get_theme_font("normal_font");
Color base_color = get_theme_color("default_color");
@@ -1006,8 +1031,9 @@ void RichTextLabel::_notification(int p_what) {
}
void RichTextLabel::_find_click(ItemFrame *p_frame, const Point2i &p_click, Item **r_click_item, int *r_click_char, bool *r_outside) {
- if (r_click_item)
+ if (r_click_item) {
*r_click_item = nullptr;
+ }
Rect2 text_rect = _get_text_rect();
int ofs = vscroll->get_value();
@@ -1019,13 +1045,15 @@ void RichTextLabel::_find_click(ItemFrame *p_frame, const Point2i &p_click, Item
int from_line = 0;
while (from_line < p_frame->lines.size()) {
- if (p_frame->lines[from_line].height_accum_cache >= ofs)
+ if (p_frame->lines[from_line].height_accum_cache >= ofs) {
break;
+ }
from_line++;
}
- if (from_line >= p_frame->lines.size())
+ if (from_line >= p_frame->lines.size()) {
return;
+ }
int y = (p_frame->lines[from_line].height_accum_cache - p_frame->lines[from_line].height_cache) - ofs;
Ref<Font> base_font = get_theme_font("normal_font");
@@ -1033,29 +1061,34 @@ void RichTextLabel::_find_click(ItemFrame *p_frame, const Point2i &p_click, Item
while (y < text_rect.get_size().height && from_line < p_frame->lines.size()) {
_process_line(p_frame, text_rect.get_position(), y, text_rect.get_size().width - scroll_w, from_line, PROCESS_POINTER, base_font, base_color, font_color_shadow, use_outline, shadow_ofs, p_click, r_click_item, r_click_char, r_outside);
- if (r_click_item && *r_click_item)
+ if (r_click_item && *r_click_item) {
return;
+ }
from_line++;
}
}
Control::CursorShape RichTextLabel::get_cursor_shape(const Point2 &p_pos) const {
- if (!underline_meta)
+ if (!underline_meta) {
return CURSOR_ARROW;
+ }
- if (selection.click)
+ if (selection.click) {
return CURSOR_IBEAM;
+ }
- if (main->first_invalid_line < main->lines.size())
+ if (main->first_invalid_line < main->lines.size()) {
return CURSOR_ARROW; //invalid
+ }
int line = 0;
Item *item = nullptr;
bool outside;
((RichTextLabel *)(this))->_find_click(main, p_pos, &item, &line, &outside);
- if (item && !outside && ((RichTextLabel *)(this))->_find_meta(item, nullptr))
+ if (item && !outside && ((RichTextLabel *)(this))->_find_meta(item, nullptr)) {
return CURSOR_POINTING_HAND;
+ }
return CURSOR_ARROW;
}
@@ -1064,8 +1097,9 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) {
Ref<InputEventMouseButton> b = p_event;
if (b.is_valid()) {
- if (main->first_invalid_line < main->lines.size())
+ if (main->first_invalid_line < main->lines.size()) {
return;
+ }
if (b->get_button_index() == BUTTON_LEFT) {
if (b->is_pressed() && !b->is_doubleclick()) {
@@ -1141,20 +1175,22 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) {
}
if (b->get_button_index() == BUTTON_WHEEL_UP) {
- if (scroll_active)
+ if (scroll_active) {
vscroll->set_value(vscroll->get_value() - vscroll->get_page() * b->get_factor() * 0.5 / 8);
+ }
}
if (b->get_button_index() == BUTTON_WHEEL_DOWN) {
- if (scroll_active)
+ if (scroll_active) {
vscroll->set_value(vscroll->get_value() + vscroll->get_page() * b->get_factor() * 0.5 / 8);
+ }
}
}
Ref<InputEventPanGesture> pan_gesture = p_event;
if (pan_gesture.is_valid()) {
- if (scroll_active)
-
+ if (scroll_active) {
vscroll->set_value(vscroll->get_value() + vscroll->get_page() * pan_gesture->get_delta().y * 0.5 / 8);
+ }
return;
}
@@ -1211,16 +1247,18 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) {
} break;
}
- if (handled)
+ if (handled) {
accept_event();
+ }
}
}
Ref<InputEventMouseMotion> m = p_event;
if (m.is_valid()) {
- if (main->first_invalid_line < main->lines.size())
+ if (main->first_invalid_line < main->lines.size()) {
return;
+ }
int line = 0;
Item *item = nullptr;
@@ -1228,8 +1266,9 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) {
_find_click(main, m->get_position(), &item, &line, &outside);
if (selection.click) {
- if (!item)
+ if (!item) {
return; // do not update
+ }
selection.from = selection.click;
selection.from_char = selection.click_char;
@@ -1238,12 +1277,12 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) {
selection.to_char = line;
bool swap = false;
- if (selection.from->index > selection.to->index)
+ if (selection.from->index > selection.to->index) {
swap = true;
- else if (selection.from->index == selection.to->index) {
- if (selection.from_char > selection.to_char)
+ } else if (selection.from->index == selection.to->index) {
+ if (selection.from_char > selection.to_char) {
swap = true;
- else if (selection.from_char == selection.to_char) {
+ } else if (selection.from_char == selection.to_char) {
selection.active = false;
return;
}
@@ -1300,8 +1339,9 @@ int RichTextLabel::_find_margin(Item *p_item, const Ref<Font> &p_base_font) {
while (item) {
if (item->type == ITEM_INDENT) {
Ref<Font> font = _find_font(item);
- if (font.is_null())
+ if (font.is_null()) {
font = p_base_font;
+ }
ItemIndent *indent = static_cast<ItemIndent *>(item);
@@ -1309,8 +1349,9 @@ int RichTextLabel::_find_margin(Item *p_item, const Ref<Font> &p_base_font) {
} else if (item->type == ITEM_LIST) {
Ref<Font> font = _find_font(item);
- if (font.is_null())
+ if (font.is_null()) {
font = p_base_font;
+ }
}
item = item->parent;
@@ -1408,10 +1449,12 @@ bool RichTextLabel::_find_meta(Item *p_item, Variant *r_meta, ItemMeta **r_item)
while (item) {
if (item->type == ITEM_META) {
ItemMeta *meta = static_cast<ItemMeta *>(item);
- if (r_meta)
+ if (r_meta) {
*r_meta = meta->meta;
- if (r_item)
+ }
+ if (r_item) {
*r_item = meta;
+ }
return true;
}
@@ -1423,14 +1466,16 @@ bool RichTextLabel::_find_meta(Item *p_item, Variant *r_meta, ItemMeta **r_item)
bool RichTextLabel::_find_layout_subitem(Item *from, Item *to) {
if (from && from != to) {
- if (from->type != ITEM_FONT && from->type != ITEM_COLOR && from->type != ITEM_UNDERLINE && from->type != ITEM_STRIKETHROUGH)
+ if (from->type != ITEM_FONT && from->type != ITEM_COLOR && from->type != ITEM_UNDERLINE && from->type != ITEM_STRIKETHROUGH) {
return true;
+ }
for (List<Item *>::Element *E = from->subitems.front(); E; E = E->next()) {
bool layout = _find_layout_subitem(E->get(), to);
- if (layout)
+ if (layout) {
return true;
+ }
}
}
@@ -1438,8 +1483,9 @@ bool RichTextLabel::_find_layout_subitem(Item *from, Item *to) {
}
void RichTextLabel::_validate_line_caches(ItemFrame *p_frame) {
- if (p_frame->first_invalid_line == p_frame->lines.size())
+ if (p_frame->first_invalid_line == p_frame->lines.size()) {
return;
+ }
//validate invalid lines
Size2 size = get_size();
@@ -1459,21 +1505,24 @@ void RichTextLabel::_validate_line_caches(ItemFrame *p_frame) {
p_frame->lines.write[i].height_cache = y;
p_frame->lines.write[i].height_accum_cache = y;
- if (i > 0)
+ if (i > 0) {
p_frame->lines.write[i].height_accum_cache += p_frame->lines[i - 1].height_accum_cache;
+ }
}
int total_height = 0;
- if (p_frame->lines.size())
+ if (p_frame->lines.size()) {
total_height = p_frame->lines[p_frame->lines.size() - 1].height_accum_cache + get_theme_stylebox("normal")->get_minimum_size().height;
+ }
main->first_invalid_line = p_frame->lines.size();
updating_scroll = true;
vscroll->set_max(total_height);
vscroll->set_page(size.height);
- if (scroll_follow && scroll_following)
+ if (scroll_follow && scroll_following) {
vscroll->set_value(total_height - size.height);
+ }
updating_scroll = false;
}
@@ -1486,8 +1535,9 @@ void RichTextLabel::_invalidate_current_line(ItemFrame *p_frame) {
}
void RichTextLabel::add_text(const String &p_text) {
- if (current->type == ITEM_TABLE)
+ if (current->type == ITEM_TABLE) {
return; //can't add anything here
+ }
int pos = 0;
@@ -1501,10 +1551,11 @@ void RichTextLabel::add_text(const String &p_text) {
eol = true;
}
- if (pos == 0 && end == p_text.length())
+ if (pos == 0 && end == p_text.length()) {
line = p_text;
- else
+ } else {
line = p_text.substr(pos, end - pos);
+ }
if (line.length() > 0) {
if (current->subitems.size() && current->subitems.back()->get()->type == ITEM_TEXT) {
@@ -1526,8 +1577,9 @@ void RichTextLabel::add_text(const String &p_text) {
item->line = current_frame->lines.size();
_add_item(item, false);
current_frame->lines.resize(current_frame->lines.size() + 1);
- if (item->type != ITEM_NEWLINE)
+ if (item->type != ITEM_NEWLINE) {
current_frame->lines.write[current_frame->lines.size() - 1].from = item;
+ }
_invalidate_current_line(current_frame);
}
@@ -1540,8 +1592,9 @@ void RichTextLabel::_add_item(Item *p_item, bool p_enter, bool p_ensure_newline)
p_item->E = current->subitems.push_back(p_item);
p_item->index = current_idx++;
- if (p_enter)
+ if (p_enter) {
current = p_item;
+ }
if (p_ensure_newline) {
Item *from = current_frame->lines[current_frame->lines.size() - 1].from;
@@ -1571,8 +1624,9 @@ void RichTextLabel::_remove_item(Item *p_item, const int p_line, const int p_sub
if (p_item->type == ITEM_NEWLINE) {
current_frame->lines.remove(p_line);
for (int i = p_subitem_line; i < current->subitems.size(); i++) {
- if (current->subitems[i]->line > 0)
+ if (current->subitems[i]->line > 0) {
current->subitems[i]->line--;
+ }
}
}
} else {
@@ -1583,8 +1637,9 @@ void RichTextLabel::_remove_item(Item *p_item, const int p_line, const int p_sub
}
void RichTextLabel::add_image(const Ref<Texture2D> &p_image, const int p_width, const int p_height) {
- if (current->type == ITEM_TABLE)
+ if (current->type == ITEM_TABLE) {
return;
+ }
ERR_FAIL_COND(p_image.is_null());
ItemImage *item = memnew(ItemImage);
@@ -1618,8 +1673,9 @@ void RichTextLabel::add_image(const Ref<Texture2D> &p_image, const int p_width,
}
void RichTextLabel::add_newline() {
- if (current->type == ITEM_TABLE)
+ if (current->type == ITEM_TABLE) {
return;
+ }
ItemNewline *item = memnew(ItemNewline);
item->line = current_frame->lines.size();
_add_item(item, false);
@@ -1628,8 +1684,9 @@ void RichTextLabel::add_newline() {
}
bool RichTextLabel::remove_line(const int p_line) {
- if (p_line >= current_frame->lines.size() || p_line < 0)
+ if (p_line >= current_frame->lines.size() || p_line < 0) {
return false;
+ }
int i = 0;
while (i < current->subitems.size() && current->subitems[i]->line < p_line) {
@@ -1640,8 +1697,9 @@ bool RichTextLabel::remove_line(const int p_line) {
while (i < current->subitems.size()) {
was_newline = current->subitems[i]->type == ITEM_NEWLINE;
_remove_item(current->subitems[i], current->subitems[i]->line, p_line);
- if (was_newline)
+ if (was_newline) {
break;
+ }
}
if (!was_newline) {
@@ -1651,8 +1709,9 @@ bool RichTextLabel::remove_line(const int p_line) {
}
}
- if (p_line == 0 && current->subitems.size() > 0)
+ if (p_line == 0 && current->subitems.size() > 0) {
main->lines.write[0].from = main;
+ }
main->first_invalid_line = 0;
@@ -1903,8 +1962,9 @@ void RichTextLabel::set_offset(int p_pixel) {
}
void RichTextLabel::set_scroll_active(bool p_active) {
- if (scroll_active == p_active)
+ if (scroll_active == p_active) {
return;
+ }
scroll_active = p_active;
update();
@@ -1916,8 +1976,9 @@ bool RichTextLabel::is_scroll_active() const {
void RichTextLabel::set_scroll_follow(bool p_follow) {
scroll_follow = p_follow;
- if (!vscroll->is_visible_in_tree() || vscroll->get_value() >= (vscroll->get_max() - vscroll->get_page()))
+ if (!vscroll->is_visible_in_tree() || vscroll->get_value() >= (vscroll->get_max() - vscroll->get_page())) {
scroll_following = true;
+ }
}
bool RichTextLabel::is_scroll_following() const {
@@ -1951,15 +2012,17 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
while (pos < p_bbcode.length()) {
int brk_pos = p_bbcode.find("[", pos);
- if (brk_pos < 0)
+ if (brk_pos < 0) {
brk_pos = p_bbcode.length();
+ }
if (brk_pos > pos) {
add_text(p_bbcode.substr(pos, brk_pos - pos));
}
- if (brk_pos == p_bbcode.length())
+ if (brk_pos == p_bbcode.length()) {
break; //nothing else to add
+ }
int brk_end = p_bbcode.find("]", brk_pos + 1);
@@ -1975,12 +2038,15 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
if (tag.begins_with("/") && tag_stack.size()) {
bool tag_ok = tag_stack.size() && tag_stack.front()->get() == tag.substr(1, tag.length());
- if (tag_stack.front()->get() == "b")
+ if (tag_stack.front()->get() == "b") {
in_bold = false;
- if (tag_stack.front()->get() == "i")
+ }
+ if (tag_stack.front()->get() == "i") {
in_italics = false;
- if (tag_stack.front()->get() == "indent")
+ }
+ if (tag_stack.front()->get() == "indent") {
indent_level--;
+ }
if (!tag_ok) {
add_text("[" + tag);
@@ -1990,25 +2056,28 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
tag_stack.pop_front();
pos = brk_end + 1;
- if (tag != "/img")
+ if (tag != "/img") {
pop();
+ }
} else if (tag == "b") {
//use bold font
in_bold = true;
- if (in_italics)
+ if (in_italics) {
push_font(bold_italics_font);
- else
+ } else {
push_font(bold_font);
+ }
pos = brk_end + 1;
tag_stack.push_front(tag);
} else if (tag == "i") {
//use italics font
in_italics = true;
- if (in_bold)
+ if (in_bold) {
push_font(bold_italics_font);
- else
+ } else {
push_font(italics_font);
+ }
pos = brk_end + 1;
tag_stack.push_front(tag);
} else if (tag == "code") {
@@ -2018,8 +2087,9 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
tag_stack.push_front(tag);
} else if (tag.begins_with("table=")) {
int columns = tag.substr(6, tag.length()).to_int();
- if (columns < 1)
+ if (columns < 1) {
columns = 1;
+ }
push_table(columns);
pos = brk_end + 1;
@@ -2030,8 +2100,9 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
tag_stack.push_front(tag);
} else if (tag.begins_with("cell=")) {
int ratio = tag.substr(5, tag.length()).to_int();
- if (ratio < 1)
+ if (ratio < 1) {
ratio = 1;
+ }
set_table_column_expand(get_current_table_column(), true, ratio);
push_cell();
@@ -2075,8 +2146,9 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
} else if (tag == "url") {
int end = p_bbcode.find("[", brk_end);
- if (end == -1)
+ if (end == -1) {
end = p_bbcode.length();
+ }
String url = p_bbcode.substr(brk_end + 1, end - brk_end - 1);
push_meta(url);
@@ -2090,14 +2162,16 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
tag_stack.push_front("url");
} else if (tag == "img") {
int end = p_bbcode.find("[", brk_end);
- if (end == -1)
+ if (end == -1) {
end = p_bbcode.length();
+ }
String image = p_bbcode.substr(brk_end + 1, end - brk_end - 1);
Ref<Texture2D> texture = ResourceLoader::load(image, "Texture2D");
- if (texture.is_valid())
+ if (texture.is_valid()) {
add_image(texture);
+ }
pos = end;
tag_stack.push_front(tag);
@@ -2115,14 +2189,16 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
}
int end = p_bbcode.find("[", brk_end);
- if (end == -1)
+ if (end == -1) {
end = p_bbcode.length();
+ }
String image = p_bbcode.substr(brk_end + 1, end - brk_end - 1);
Ref<Texture2D> texture = ResourceLoader::load(image, "Texture");
- if (texture.is_valid())
+ if (texture.is_valid()) {
add_image(texture, width, height);
+ }
pos = end;
tag_stack.push_front("img");
@@ -2130,42 +2206,43 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
String col = tag.substr(6, tag.length());
Color color;
- if (col.begins_with("#"))
+ if (col.begins_with("#")) {
color = Color::html(col);
- else if (col == "aqua")
+ } else if (col == "aqua") {
color = Color(0, 1, 1);
- else if (col == "black")
+ } else if (col == "black") {
color = Color(0, 0, 0);
- else if (col == "blue")
+ } else if (col == "blue") {
color = Color(0, 0, 1);
- else if (col == "fuchsia")
+ } else if (col == "fuchsia") {
color = Color(1, 0, 1);
- else if (col == "gray" || col == "grey")
+ } else if (col == "gray" || col == "grey") {
color = Color(0.5, 0.5, 0.5);
- else if (col == "green")
+ } else if (col == "green") {
color = Color(0, 0.5, 0);
- else if (col == "lime")
+ } else if (col == "lime") {
color = Color(0, 1, 0);
- else if (col == "maroon")
+ } else if (col == "maroon") {
color = Color(0.5, 0, 0);
- else if (col == "navy")
+ } else if (col == "navy") {
color = Color(0, 0, 0.5);
- else if (col == "olive")
+ } else if (col == "olive") {
color = Color(0.5, 0.5, 0);
- else if (col == "purple")
+ } else if (col == "purple") {
color = Color(0.5, 0, 0.5);
- else if (col == "red")
+ } else if (col == "red") {
color = Color(1, 0, 0);
- else if (col == "silver")
+ } else if (col == "silver") {
color = Color(0.75, 0.75, 0.75);
- else if (col == "teal")
+ } else if (col == "teal") {
color = Color(0, 0.5, 0.5);
- else if (col == "white")
+ } else if (col == "white") {
color = Color(1, 1, 1);
- else if (col == "yellow")
+ } else if (col == "yellow") {
color = Color(1, 1, 0);
- else
+ } else {
color = base_color;
+ }
push_color(color);
pos = brk_end + 1;
@@ -2175,10 +2252,11 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
String fnt = tag.substr(5, tag.length());
Ref<Font> font = ResourceLoader::load(fnt, "Font");
- if (font.is_valid())
+ if (font.is_valid()) {
push_font(font);
- else
+ } else {
push_font(normal_font);
+ }
pos = brk_end + 1;
tag_stack.push_front("font");
@@ -2334,8 +2412,9 @@ int RichTextLabel::get_line_count() const {
}
int RichTextLabel::get_visible_line_count() const {
- if (!is_visible())
+ if (!is_visible()) {
return 0;
+ }
return visible_line_count;
}
@@ -2398,10 +2477,11 @@ bool RichTextLabel::search(const String &p_string, bool p_from_selection, bool p
}
}
- if (p_search_previous)
+ if (p_search_previous) {
it = _get_prev_item(it, true);
- else
+ } else {
it = _get_next_item(it, true);
+ }
charidx = 0;
}
@@ -2409,8 +2489,9 @@ bool RichTextLabel::search(const String &p_string, bool p_from_selection, bool p
}
void RichTextLabel::selection_copy() {
- if (!selection.active || !selection.enabled)
+ if (!selection.active || !selection.enabled) {
return;
+ }
String text;
@@ -2432,8 +2513,9 @@ void RichTextLabel::selection_copy() {
} else if (item->type == ITEM_NEWLINE) {
text += "\n";
}
- if (item == selection.to)
+ if (item == selection.to) {
break;
+ }
item = _get_next_item(item, true);
}
@@ -2449,9 +2531,9 @@ bool RichTextLabel::is_selection_enabled() const {
void RichTextLabel::set_bbcode(const String &p_bbcode) {
bbcode = p_bbcode;
- if (is_inside_tree() && use_bbcode)
+ if (is_inside_tree() && use_bbcode) {
parse_bbcode(p_bbcode);
- else { // raw text
+ } else { // raw text
clear();
add_text(p_bbcode);
}
@@ -2462,8 +2544,9 @@ String RichTextLabel::get_bbcode() const {
}
void RichTextLabel::set_use_bbcode(bool p_enable) {
- if (use_bbcode == p_enable)
+ if (use_bbcode == p_enable) {
return;
+ }
use_bbcode = p_enable;
set_bbcode(bbcode);
}
@@ -2540,8 +2623,9 @@ void RichTextLabel::install_effect(const Variant effect) {
int RichTextLabel::get_content_height() {
int total_height = 0;
- if (main->lines.size())
+ if (main->lines.size()) {
total_height = main->lines[main->lines.size() - 1].height_accum_cache + get_theme_stylebox("normal")->get_minimum_size().height;
+ }
return total_height;
}
@@ -2687,8 +2771,9 @@ int RichTextLabel::get_visible_characters() const {
int RichTextLabel::get_total_character_count() const {
int tc = 0;
- for (int i = 0; i < current_frame->lines.size(); i++)
+ for (int i = 0; i < current_frame->lines.size(); i++) {
tc += current_frame->lines[i].char_count;
+ }
return tc;
}
@@ -2709,8 +2794,9 @@ Size2 RichTextLabel::get_minimum_size() const {
Ref<RichTextEffect> RichTextLabel::_get_custom_effect_by_code(String p_bbcode_identifier) {
for (int i = 0; i < custom_effects.size(); i++) {
- if (!custom_effects[i].is_valid())
+ if (!custom_effects[i].is_valid()) {
continue;
+ }
if (custom_effects[i]->get_bbcode() == p_bbcode_identifier) {
return custom_effects[i];
diff --git a/scene/gui/scroll_bar.cpp b/scene/gui/scroll_bar.cpp
index 98b6de0696..e7950bec98 100644
--- a/scene/gui/scroll_bar.cpp
+++ b/scene/gui/scroll_bar.cpp
@@ -62,8 +62,9 @@ void ScrollBar::_gui_input(Ref<InputEvent> p_event) {
accept_event();
}
- if (b->get_button_index() != BUTTON_LEFT)
+ if (b->get_button_index() != BUTTON_LEFT) {
return;
+ }
if (b->is_pressed()) {
double ofs = orientation == VERTICAL ? b->get_position().y : b->get_position().x;
@@ -175,24 +176,28 @@ void ScrollBar::_gui_input(Ref<InputEvent> p_event) {
if (p_event->is_pressed()) {
if (p_event->is_action("ui_left")) {
- if (orientation != HORIZONTAL)
+ if (orientation != HORIZONTAL) {
return;
+ }
set_value(get_value() - (custom_step >= 0 ? custom_step : get_step()));
} else if (p_event->is_action("ui_right")) {
- if (orientation != HORIZONTAL)
+ if (orientation != HORIZONTAL) {
return;
+ }
set_value(get_value() + (custom_step >= 0 ? custom_step : get_step()));
} else if (p_event->is_action("ui_up")) {
- if (orientation != VERTICAL)
+ if (orientation != VERTICAL) {
return;
+ }
set_value(get_value() - (custom_step >= 0 ? custom_step : get_step()));
} else if (p_event->is_action("ui_down")) {
- if (orientation != VERTICAL)
+ if (orientation != VERTICAL) {
return;
+ }
set_value(get_value() + (custom_step >= 0 ? custom_step : get_step()));
} else if (p_event->is_action("ui_home")) {
@@ -213,35 +218,39 @@ void ScrollBar::_notification(int p_what) {
Ref<StyleBox> bg = has_focus() ? get_theme_stylebox("scroll_focus") : get_theme_stylebox("scroll");
Ref<StyleBox> grabber;
- if (drag.active)
+ if (drag.active) {
grabber = get_theme_stylebox("grabber_pressed");
- else if (highlight == HIGHLIGHT_RANGE)
+ } else if (highlight == HIGHLIGHT_RANGE) {
grabber = get_theme_stylebox("grabber_highlight");
- else
+ } else {
grabber = get_theme_stylebox("grabber");
+ }
Point2 ofs;
decr->draw(ci, Point2());
- if (orientation == HORIZONTAL)
+ if (orientation == HORIZONTAL) {
ofs.x += decr->get_width();
- else
+ } else {
ofs.y += decr->get_height();
+ }
Size2 area = get_size();
- if (orientation == HORIZONTAL)
+ if (orientation == HORIZONTAL) {
area.width -= incr->get_width() + decr->get_width();
- else
+ } else {
area.height -= incr->get_height() + decr->get_height();
+ }
bg->draw(ci, Rect2(ofs, area));
- if (orientation == HORIZONTAL)
+ if (orientation == HORIZONTAL) {
ofs.width += area.width;
- else
+ } else {
ofs.height += area.height;
+ }
incr->draw(ci, ofs);
Rect2 grabber_rect;
@@ -385,8 +394,9 @@ double ScrollBar::get_grabber_min_size() const {
double ScrollBar::get_grabber_size() const {
float range = get_max() - get_min();
- if (range <= 0)
+ if (range <= 0) {
return 0;
+ }
float page = (get_page() > 0) ? get_page() : 0;
/*
@@ -444,10 +454,11 @@ double ScrollBar::get_click_pos(const Point2 &p_pos) const {
pos -= get_area_offset();
float area = get_area_size();
- if (area == 0)
+ if (area == 0) {
return 0;
- else
+ } else {
return pos / area;
+ }
}
double ScrollBar::get_grabber_offset() const {
@@ -498,8 +509,9 @@ void ScrollBar::_drag_node_input(const Ref<InputEvent> &p_input) {
Ref<InputEventMouseButton> mb = p_input;
if (mb.is_valid()) {
- if (mb->get_button_index() != 1)
+ if (mb->get_button_index() != 1) {
return;
+ }
if (mb->is_pressed()) {
drag_node_speed = Vector2();
@@ -537,11 +549,13 @@ void ScrollBar::_drag_node_input(const Ref<InputEvent> &p_input) {
drag_node_accum -= motion;
Vector2 diff = drag_node_from + drag_node_accum;
- if (orientation == HORIZONTAL)
+ if (orientation == HORIZONTAL) {
set_value(diff.x);
+ }
- if (orientation == VERTICAL)
+ if (orientation == VERTICAL) {
set_value(diff.y);
+ }
time_since_motion = 0;
}
@@ -610,8 +624,9 @@ ScrollBar::ScrollBar(Orientation p_orientation) {
target_scroll = 0;
smooth_scroll_enabled = false;
- if (focus_by_default)
+ if (focus_by_default) {
set_focus_mode(FOCUS_ALL);
+ }
set_step(0);
}
diff --git a/scene/gui/scroll_container.cpp b/scene/gui/scroll_container.cpp
index 0b00883a71..b72b913af0 100644
--- a/scene/gui/scroll_container.cpp
+++ b/scene/gui/scroll_container.cpp
@@ -42,12 +42,15 @@ Size2 ScrollContainer::get_minimum_size() const {
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c)
+ if (!c) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
- if (c == h_scroll || c == v_scroll)
+ }
+ if (c == h_scroll || c == v_scroll) {
continue;
+ }
Size2 minsize = c->get_combined_minimum_size();
if (!scroll_h) {
@@ -121,14 +124,17 @@ void ScrollContainer::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
}
- if (v_scroll->get_value() != prev_v_scroll || h_scroll->get_value() != prev_h_scroll)
+ if (v_scroll->get_value() != prev_v_scroll || h_scroll->get_value() != prev_h_scroll) {
accept_event(); //accept event if scroll changed
+ }
- if (!DisplayServer::get_singleton()->screen_is_touchscreen(DisplayServer::get_singleton()->window_get_current_screen(get_viewport()->get_window_id())))
+ if (!DisplayServer::get_singleton()->screen_is_touchscreen(DisplayServer::get_singleton()->window_get_current_screen(get_viewport()->get_window_id()))) {
return;
+ }
- if (mb->get_button_index() != BUTTON_LEFT)
+ if (mb->get_button_index() != BUTTON_LEFT) {
return;
+ }
if (mb->is_pressed()) {
if (drag_touching) {
@@ -176,14 +182,16 @@ void ScrollContainer::_gui_input(const Ref<InputEvent> &p_gui_input) {
drag_accum = -motion;
}
Vector2 diff = drag_from + drag_accum;
- if (scroll_h)
+ if (scroll_h) {
h_scroll->set_value(diff.x);
- else
+ } else {
drag_accum.x = 0;
- if (scroll_v)
+ }
+ if (scroll_v) {
v_scroll->set_value(diff.y);
- else
+ } else {
drag_accum.y = 0;
+ }
time_since_motion = 0;
}
}
@@ -199,8 +207,9 @@ void ScrollContainer::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
}
- if (v_scroll->get_value() != prev_v_scroll || h_scroll->get_value() != prev_h_scroll)
+ if (v_scroll->get_value() != prev_v_scroll || h_scroll->get_value() != prev_h_scroll) {
accept_event(); //accept event if scroll changed
+ }
}
void ScrollContainer::_update_scrollbar_position() {
@@ -263,20 +272,25 @@ void ScrollContainer::_notification(int p_what) {
size -= sb->get_minimum_size();
ofs += sb->get_offset();
- if (h_scroll->is_visible_in_tree() && h_scroll->get_parent() == this) //scrolls may have been moved out for reasons
+ if (h_scroll->is_visible_in_tree() && h_scroll->get_parent() == this) { //scrolls may have been moved out for reasons
size.y -= h_scroll->get_minimum_size().y;
+ }
- if (v_scroll->is_visible_in_tree() && v_scroll->get_parent() == this) //scrolls may have been moved out for reasons
+ if (v_scroll->is_visible_in_tree() && v_scroll->get_parent() == this) { //scrolls may have been moved out for reasons
size.x -= v_scroll->get_minimum_size().x;
+ }
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c)
+ if (!c) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
- if (c == h_scroll || c == v_scroll)
+ }
+ if (c == h_scroll || c == v_scroll) {
continue;
+ }
Size2 minsize = c->get_combined_minimum_size();
child_max_size.x = MAX(child_max_size.x, minsize.x);
child_max_size.y = MAX(child_max_size.y, minsize.y);
@@ -284,17 +298,19 @@ void ScrollContainer::_notification(int p_what) {
Rect2 r = Rect2(-scroll, minsize);
if (!scroll_h || (!h_scroll->is_visible_in_tree() && c->get_h_size_flags() & SIZE_EXPAND)) {
r.position.x = 0;
- if (c->get_h_size_flags() & SIZE_EXPAND)
+ if (c->get_h_size_flags() & SIZE_EXPAND) {
r.size.width = MAX(size.width, minsize.width);
- else
+ } else {
r.size.width = minsize.width;
+ }
}
if (!scroll_v || (!v_scroll->is_visible_in_tree() && c->get_v_size_flags() & SIZE_EXPAND)) {
r.position.y = 0;
- if (c->get_v_size_flags() & SIZE_EXPAND)
+ if (c->get_v_size_flags() & SIZE_EXPAND) {
r.size.height = MAX(size.height, minsize.height);
- else
+ } else {
r.size.height = minsize.height;
+ }
}
r.position += ofs;
fit_child_in_rect(c, r);
@@ -337,10 +353,12 @@ void ScrollContainer::_notification(int p_what) {
turnoff_v = true;
}
- if (scroll_h)
+ if (scroll_h) {
h_scroll->set_value(pos.x);
- if (scroll_v)
+ }
+ if (scroll_v) {
v_scroll->set_value(pos.y);
+ }
float sgn_x = drag_speed.x < 0 ? -1 : 1;
float val_x = Math::abs(drag_speed.x);
@@ -506,20 +524,24 @@ String ScrollContainer::get_configuration_warning() const {
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c)
+ if (!c) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
- if (c == h_scroll || c == v_scroll)
+ }
+ if (c == h_scroll || c == v_scroll) {
continue;
+ }
found++;
}
- if (found != 1)
+ if (found != 1) {
return TTR("ScrollContainer is intended to work with a single child control.\nUse a container as child (VBox, HBox, etc.), or a Control and set the custom minimum size manually.");
- else
+ } else {
return "";
+ }
}
HScrollBar *ScrollContainer::get_h_scrollbar() {
diff --git a/scene/gui/shortcut.cpp b/scene/gui/shortcut.cpp
index a529c52065..9f5b9c40c2 100644
--- a/scene/gui/shortcut.cpp
+++ b/scene/gui/shortcut.cpp
@@ -46,10 +46,11 @@ bool ShortCut::is_shortcut(const Ref<InputEvent> &p_event) const {
}
String ShortCut::get_as_text() const {
- if (shortcut.is_valid())
+ if (shortcut.is_valid()) {
return shortcut->as_text();
- else
+ } else {
return "None";
+ }
}
bool ShortCut::is_valid() const {
diff --git a/scene/gui/slider.cpp b/scene/gui/slider.cpp
index b48922bf32..3dd5e022f0 100644
--- a/scene/gui/slider.cpp
+++ b/scene/gui/slider.cpp
@@ -38,10 +38,11 @@ Size2 Slider::get_minimum_size() const {
Ref<Texture2D> grabber = get_theme_icon("grabber");
Size2i rs = grabber->get_size();
- if (orientation == HORIZONTAL)
+ if (orientation == HORIZONTAL) {
return Size2i(ss.width, MAX(ss.height, rs.height));
- else
+ } else {
return Size2i(MAX(ss.width, rs.width), ss.height);
+ }
}
void Slider::_gui_input(Ref<InputEvent> p_event) {
@@ -60,10 +61,11 @@ void Slider::_gui_input(Ref<InputEvent> p_event) {
double grab_width = (double)grabber->get_size().width;
double grab_height = (double)grabber->get_size().height;
double max = orientation == VERTICAL ? get_size().height - grab_height : get_size().width - grab_width;
- if (orientation == VERTICAL)
+ if (orientation == VERTICAL) {
set_as_ratio(1 - (((double)grab.pos - (grab_height / 2.0)) / max));
- else
+ } else {
set_as_ratio(((double)grab.pos - (grab_width / 2.0)) / max);
+ }
grab.active = true;
grab.uvalue = get_as_ratio();
} else {
@@ -85,11 +87,13 @@ void Slider::_gui_input(Ref<InputEvent> p_event) {
Size2i size = get_size();
Ref<Texture2D> grabber = get_theme_icon("grabber");
float motion = (orientation == VERTICAL ? mm->get_position().y : mm->get_position().x) - grab.pos;
- if (orientation == VERTICAL)
+ if (orientation == VERTICAL) {
motion = -motion;
+ }
float areasize = orientation == VERTICAL ? size.height - grabber->get_size().height : size.width - grabber->get_size().width;
- if (areasize <= 0)
+ if (areasize <= 0) {
return;
+ }
float umotion = motion / float(areasize);
set_as_ratio(grab.uvalue + umotion);
}
@@ -97,24 +101,28 @@ void Slider::_gui_input(Ref<InputEvent> p_event) {
if (!mm.is_valid() && !mb.is_valid()) {
if (p_event->is_action_pressed("ui_left", true)) {
- if (orientation != HORIZONTAL)
+ if (orientation != HORIZONTAL) {
return;
+ }
set_value(get_value() - (custom_step >= 0 ? custom_step : get_step()));
accept_event();
} else if (p_event->is_action_pressed("ui_right", true)) {
- if (orientation != HORIZONTAL)
+ if (orientation != HORIZONTAL) {
return;
+ }
set_value(get_value() + (custom_step >= 0 ? custom_step : get_step()));
accept_event();
} else if (p_event->is_action_pressed("ui_up", true)) {
- if (orientation != VERTICAL)
+ if (orientation != VERTICAL) {
return;
+ }
set_value(get_value() + (custom_step >= 0 ? custom_step : get_step()));
accept_event();
} else if (p_event->is_action_pressed("ui_down", true)) {
- if (orientation != VERTICAL)
+ if (orientation != VERTICAL) {
return;
+ }
set_value(get_value() - (custom_step >= 0 ? custom_step : get_step()));
accept_event();
} else if (p_event->is_action("ui_home") && p_event->is_pressed()) {
@@ -165,8 +173,9 @@ void Slider::_notification(int p_what) {
if (ticks > 1) {
int grabber_offset = (grabber->get_size().height / 2 - tick->get_height() / 2);
for (int i = 0; i < ticks; i++) {
- if (!ticks_on_borders && (i == 0 || i + 1 == ticks))
+ if (!ticks_on_borders && (i == 0 || i + 1 == ticks)) {
continue;
+ }
int ofs = (i * areasize / (ticks - 1)) + grabber_offset;
tick->draw(ci, Point2i((size.width - widget_width) / 2, ofs));
}
@@ -182,8 +191,9 @@ void Slider::_notification(int p_what) {
if (ticks > 1) {
int grabber_offset = (grabber->get_size().width / 2 - tick->get_width() / 2);
for (int i = 0; i < ticks; i++) {
- if ((!ticks_on_borders) && ((i == 0) || ((i + 1) == ticks)))
+ if ((!ticks_on_borders) && ((i == 0) || ((i + 1) == ticks))) {
continue;
+ }
int ofs = (i * areasize / (ticks - 1)) + grabber_offset;
tick->draw(ci, Point2i(ofs, (size.height - widget_height) / 2));
}
diff --git a/scene/gui/spin_box.cpp b/scene/gui/spin_box.cpp
index a82e9f7009..3670f13705 100644
--- a/scene/gui/spin_box.cpp
+++ b/scene/gui/spin_box.cpp
@@ -41,10 +41,12 @@ Size2 SpinBox::get_minimum_size() const {
void SpinBox::_value_changed(double) {
String value = String::num(get_value(), Math::range_step_decimals(get_step()));
- if (prefix != "")
+ if (prefix != "") {
value = prefix + " " + value;
- if (suffix != "")
+ }
+ if (suffix != "") {
value += " " + suffix;
+ }
line_edit->set_text(value);
}
@@ -159,8 +161,9 @@ void SpinBox::_gui_input(const Ref<InputEvent> &p_event) {
void SpinBox::_line_edit_focus_exit() {
// discontinue because the focus_exit was caused by right-click context menu
- if (line_edit->get_menu()->is_visible())
+ if (line_edit->get_menu()->is_visible()) {
return;
+ }
_text_entered(line_edit->get_text());
}
diff --git a/scene/gui/split_container.cpp b/scene/gui/split_container.cpp
index 14a4edc609..5c60153d91 100644
--- a/scene/gui/split_container.cpp
+++ b/scene/gui/split_container.cpp
@@ -38,13 +38,16 @@ Control *SplitContainer::_getch(int p_idx) const {
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c || !c->is_visible_in_tree())
+ if (!c || !c->is_visible_in_tree()) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
+ }
- if (idx == p_idx)
+ if (idx == p_idx) {
return c;
+ }
idx++;
}
@@ -126,14 +129,16 @@ Size2 SplitContainer::get_minimum_size() const {
sep = (dragger_visibility != DRAGGER_HIDDEN_COLLAPSED) ? MAX(sep, vertical ? g->get_height() : g->get_width()) : 0;
for (int i = 0; i < 2; i++) {
- if (!_getch(i))
+ if (!_getch(i)) {
break;
+ }
if (i == 1) {
- if (vertical)
+ if (vertical) {
minimum.height += sep;
- else
+ } else {
minimum.width += sep;
+ }
}
Size2 ms = _getch(i)->get_combined_minimum_size();
@@ -157,27 +162,32 @@ void SplitContainer::_notification(int p_what) {
} break;
case NOTIFICATION_MOUSE_EXIT: {
mouse_inside = false;
- if (get_theme_constant("autohide"))
+ if (get_theme_constant("autohide")) {
update();
+ }
} break;
case NOTIFICATION_DRAW: {
- if (!_getch(0) || !_getch(1))
+ if (!_getch(0) || !_getch(1)) {
return;
+ }
- if (collapsed || (!dragging && !mouse_inside && get_theme_constant("autohide")))
+ if (collapsed || (!dragging && !mouse_inside && get_theme_constant("autohide"))) {
return;
+ }
- if (dragger_visibility != DRAGGER_VISIBLE)
+ if (dragger_visibility != DRAGGER_VISIBLE) {
return;
+ }
int sep = dragger_visibility != DRAGGER_HIDDEN_COLLAPSED ? get_theme_constant("separation") : 0;
Ref<Texture2D> tex = get_theme_icon("grabber");
Size2 size = get_size();
- if (vertical)
+ if (vertical) {
draw_texture(tex, Point2i((size.x - tex->get_width()) / 2, middle_sep + (sep - tex->get_height()) / 2));
- else
+ } else {
draw_texture(tex, Point2i(middle_sep + (sep - tex->get_width()) / 2, (size.y - tex->get_height()) / 2));
+ }
} break;
case NOTIFICATION_THEME_CHANGED: {
minimum_size_changed();
@@ -186,8 +196,9 @@ void SplitContainer::_notification(int p_what) {
}
void SplitContainer::_gui_input(const Ref<InputEvent> &p_event) {
- if (collapsed || !_getch(0) || !_getch(1) || dragger_visibility != DRAGGER_VISIBLE)
+ if (collapsed || !_getch(0) || !_getch(1) || dragger_visibility != DRAGGER_VISIBLE) {
return;
+ }
Ref<InputEventMouseButton> mb = p_event;
@@ -219,19 +230,22 @@ void SplitContainer::_gui_input(const Ref<InputEvent> &p_event) {
if (mm.is_valid()) {
bool mouse_inside_state = false;
- if (vertical)
+ if (vertical) {
mouse_inside_state = mm->get_position().y > middle_sep && mm->get_position().y < middle_sep + get_theme_constant("separation");
- else
+ } else {
mouse_inside_state = mm->get_position().x > middle_sep && mm->get_position().x < middle_sep + get_theme_constant("separation");
+ }
if (mouse_inside != mouse_inside_state) {
mouse_inside = mouse_inside_state;
- if (get_theme_constant("autohide"))
+ if (get_theme_constant("autohide")) {
update();
+ }
}
- if (!dragging)
+ if (!dragging) {
return;
+ }
split_offset = drag_ofs + ((vertical ? mm->get_position().y : mm->get_position().x) - drag_from);
should_clamp_split_offset = true;
@@ -241,18 +255,21 @@ void SplitContainer::_gui_input(const Ref<InputEvent> &p_event) {
}
Control::CursorShape SplitContainer::get_cursor_shape(const Point2 &p_pos) const {
- if (dragging)
+ if (dragging) {
return (vertical ? CURSOR_VSPLIT : CURSOR_HSPLIT);
+ }
if (!collapsed && _getch(0) && _getch(1) && dragger_visibility == DRAGGER_VISIBLE) {
int sep = get_theme_constant("separation");
if (vertical) {
- if (p_pos.y > middle_sep && p_pos.y < middle_sep + sep)
+ if (p_pos.y > middle_sep && p_pos.y < middle_sep + sep) {
return CURSOR_VSPLIT;
+ }
} else {
- if (p_pos.x > middle_sep && p_pos.x < middle_sep + sep)
+ if (p_pos.x > middle_sep && p_pos.x < middle_sep + sep) {
return CURSOR_HSPLIT;
+ }
}
}
@@ -260,8 +277,9 @@ Control::CursorShape SplitContainer::get_cursor_shape(const Point2 &p_pos) const
}
void SplitContainer::set_split_offset(int p_offset) {
- if (split_offset == p_offset)
+ if (split_offset == p_offset) {
return;
+ }
split_offset = p_offset;
@@ -279,8 +297,9 @@ void SplitContainer::clamp_split_offset() {
}
void SplitContainer::set_collapsed(bool p_collapsed) {
- if (collapsed == p_collapsed)
+ if (collapsed == p_collapsed) {
return;
+ }
collapsed = p_collapsed;
queue_sort();
diff --git a/scene/gui/subviewport_container.cpp b/scene/gui/subviewport_container.cpp
index 7d0dabeaca..4e1ad2ae05 100644
--- a/scene/gui/subviewport_container.cpp
+++ b/scene/gui/subviewport_container.cpp
@@ -34,13 +34,15 @@
#include "scene/main/viewport.h"
Size2 SubViewportContainer::get_minimum_size() const {
- if (stretch)
+ if (stretch) {
return Size2();
+ }
Size2 ms;
for (int i = 0; i < get_child_count(); i++) {
SubViewport *c = Object::cast_to<SubViewport>(get_child(i));
- if (!c)
+ if (!c) {
continue;
+ }
Size2 minsize = c->get_size();
ms.width = MAX(ms.width, minsize.width);
@@ -62,18 +64,21 @@ bool SubViewportContainer::is_stretch_enabled() const {
void SubViewportContainer::set_stretch_shrink(int p_shrink) {
ERR_FAIL_COND(p_shrink < 1);
- if (shrink == p_shrink)
+ if (shrink == p_shrink) {
return;
+ }
shrink = p_shrink;
- if (!stretch)
+ if (!stretch) {
return;
+ }
for (int i = 0; i < get_child_count(); i++) {
SubViewport *c = Object::cast_to<SubViewport>(get_child(i));
- if (!c)
+ if (!c) {
continue;
+ }
c->set_size(get_size() / shrink);
}
@@ -87,13 +92,15 @@ int SubViewportContainer::get_stretch_shrink() const {
void SubViewportContainer::_notification(int p_what) {
if (p_what == NOTIFICATION_RESIZED) {
- if (!stretch)
+ if (!stretch) {
return;
+ }
for (int i = 0; i < get_child_count(); i++) {
SubViewport *c = Object::cast_to<SubViewport>(get_child(i));
- if (!c)
+ if (!c) {
continue;
+ }
c->set_size(get_size() / shrink);
}
@@ -102,13 +109,15 @@ void SubViewportContainer::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_VISIBILITY_CHANGED) {
for (int i = 0; i < get_child_count(); i++) {
SubViewport *c = Object::cast_to<SubViewport>(get_child(i));
- if (!c)
+ if (!c) {
continue;
+ }
- if (is_visible_in_tree())
+ if (is_visible_in_tree()) {
c->set_update_mode(SubViewport::UPDATE_ALWAYS);
- else
+ } else {
c->set_update_mode(SubViewport::UPDATE_DISABLED);
+ }
c->set_handle_input_locally(false); //do not handle input locally here
}
@@ -117,20 +126,23 @@ void SubViewportContainer::_notification(int p_what) {
if (p_what == NOTIFICATION_DRAW) {
for (int i = 0; i < get_child_count(); i++) {
SubViewport *c = Object::cast_to<SubViewport>(get_child(i));
- if (!c)
+ if (!c) {
continue;
+ }
- if (stretch)
+ if (stretch) {
draw_texture_rect(c->get_texture(), Rect2(Vector2(), get_size()));
- else
+ } else {
draw_texture_rect(c->get_texture(), Rect2(Vector2(), c->get_size()));
+ }
}
}
}
void SubViewportContainer::_input(const Ref<InputEvent> &p_event) {
- if (Engine::get_singleton()->is_editor_hint())
+ if (Engine::get_singleton()->is_editor_hint()) {
return;
+ }
Transform2D xform = get_global_transform();
@@ -144,16 +156,18 @@ void SubViewportContainer::_input(const Ref<InputEvent> &p_event) {
for (int i = 0; i < get_child_count(); i++) {
SubViewport *c = Object::cast_to<SubViewport>(get_child(i));
- if (!c || c->is_input_disabled())
+ if (!c || c->is_input_disabled()) {
continue;
+ }
c->input(ev);
}
}
void SubViewportContainer::_unhandled_input(const Ref<InputEvent> &p_event) {
- if (Engine::get_singleton()->is_editor_hint())
+ if (Engine::get_singleton()->is_editor_hint()) {
return;
+ }
Transform2D xform = get_global_transform();
@@ -167,8 +181,9 @@ void SubViewportContainer::_unhandled_input(const Ref<InputEvent> &p_event) {
for (int i = 0; i < get_child_count(); i++) {
SubViewport *c = Object::cast_to<SubViewport>(get_child(i));
- if (!c || c->is_input_disabled())
+ if (!c || c->is_input_disabled()) {
continue;
+ }
c->unhandled_input(ev);
}
diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp
index 4d861f380d..97b8362214 100644
--- a/scene/gui/tab_container.cpp
+++ b/scene/gui/tab_container.cpp
@@ -36,8 +36,9 @@
#include "scene/gui/texture_rect.h"
int TabContainer::_get_top_margin() const {
- if (!tabs_visible)
+ if (!tabs_visible) {
return 0;
+ }
// Respect the minimum tab height.
Ref<StyleBox> tab_bg = get_theme_stylebox("tab_bg");
@@ -53,12 +54,14 @@ int TabContainer::_get_top_margin() const {
Vector<Control *> tabs = _get_tabs();
for (int i = 0; i < tabs.size(); i++) {
Control *c = tabs[i];
- if (!c->has_meta("_tab_icon"))
+ if (!c->has_meta("_tab_icon")) {
continue;
+ }
Ref<Texture2D> tex = c->get_meta("_tab_icon");
- if (!tex.is_valid())
+ if (!tex.is_valid()) {
continue;
+ }
content_height = MAX(content_height, tex->get_size().height);
}
@@ -73,8 +76,9 @@ void TabContainer::_gui_input(const Ref<InputEvent> &p_event) {
Size2 size = get_size();
// Click must be on tabs in the tab header area.
- if (pos.x < tabs_ofs_cache || pos.y > _get_top_margin())
+ if (pos.x < tabs_ofs_cache || pos.y > _get_top_margin()) {
return;
+ }
// Handle menu button.
Ref<Texture2D> menu = get_theme_icon("menu");
@@ -91,8 +95,9 @@ void TabContainer::_gui_input(const Ref<InputEvent> &p_event) {
}
// Do not activate tabs when tabs is empty.
- if (get_tab_count() == 0)
+ if (get_tab_count() == 0) {
return;
+ }
Vector<Control *> tabs = _get_tabs();
@@ -218,12 +223,15 @@ void TabContainer::_notification(int p_what) {
int header_width = get_size().width - side_margin * 2;
// Find the width of the header area.
- if (popup)
+ if (popup) {
header_width -= menu->get_width();
- if (buttons_visible_cache)
+ }
+ if (buttons_visible_cache) {
header_width -= increment->get_width() + decrement->get_width();
- if (popup || buttons_visible_cache)
+ }
+ if (popup || buttons_visible_cache) {
header_width += side_margin;
+ }
// Find the width of all tabs after first_tab_cache.
int all_tabs_width = 0;
@@ -236,8 +244,9 @@ void TabContainer::_notification(int p_what) {
for (int i = first_tab_cache - 1; i >= 0; i--) {
int tab_width = _get_tab_width(i);
- if (all_tabs_width + tab_width > header_width)
+ if (all_tabs_width + tab_width > header_width) {
break;
+ }
all_tabs_width += tab_width;
first_tab_cache--;
@@ -275,8 +284,9 @@ void TabContainer::_notification(int p_what) {
int header_x = side_margin;
int header_width = size.width - side_margin * 2;
int header_height = _get_top_margin();
- if (popup)
+ if (popup) {
header_width -= menu->get_width();
+ }
// Check if all tabs would fit into the header area.
int all_tabs_width = 0;
@@ -313,8 +323,9 @@ void TabContainer::_notification(int p_what) {
continue;
}
int tab_width = _get_tab_width(i);
- if (all_tabs_width + tab_width > header_width && tab_widths.size() > 0)
+ if (all_tabs_width + tab_width > header_width && tab_widths.size() > 0) {
break;
+ }
all_tabs_width += tab_width;
tab_widths.push_back(tab_width);
}
@@ -373,8 +384,9 @@ void TabContainer::_notification(int p_what) {
if (icon.is_valid()) {
int y = y_center - (icon->get_height() / 2);
icon->draw(canvas, Point2i(x_content, y));
- if (text != "")
+ if (text != "") {
x_content += icon->get_width() + icon_text_distance;
+ }
}
}
@@ -390,10 +402,11 @@ void TabContainer::_notification(int p_what) {
x = get_size().width;
if (popup) {
x -= menu->get_width();
- if (menu_hovered)
+ if (menu_hovered) {
menu_hl->draw(get_canvas_item(), Size2(x, (header_height - menu_hl->get_height()) / 2));
- else
+ } else {
menu->draw(get_canvas_item(), Size2(x, (header_height - menu->get_height()) / 2));
+ }
}
// Draw the navigation buttons.
@@ -437,8 +450,9 @@ void TabContainer::_on_mouse_exited() {
int TabContainer::_get_tab_width(int p_index) const {
ERR_FAIL_INDEX_V(p_index, get_tab_count(), 0);
Control *control = Object::cast_to<Control>(_get_tabs()[p_index]);
- if (!control || control->is_set_as_toplevel() || get_tab_hidden(p_index))
+ if (!control || control->is_set_as_toplevel() || get_tab_hidden(p_index)) {
return 0;
+ }
// Get the width of the text displayed on the tab.
Ref<Font> font = get_theme_font("font");
@@ -450,8 +464,9 @@ int TabContainer::_get_tab_width(int p_index) const {
Ref<Texture2D> icon = control->get_meta("_tab_icon");
if (icon.is_valid()) {
width += icon->get_width();
- if (text != "")
+ if (text != "") {
width += get_theme_constant("hseparation");
+ }
}
}
@@ -474,8 +489,9 @@ Vector<Control *> TabContainer::_get_tabs() const {
Vector<Control *> controls;
for (int i = 0; i < get_child_count(); i++) {
Control *control = Object::cast_to<Control>(get_child(i));
- if (!control || control->is_toplevel_control())
+ if (!control || control->is_toplevel_control()) {
continue;
+ }
controls.push_back(control);
}
@@ -490,16 +506,18 @@ void TabContainer::add_child_notify(Node *p_child) {
Container::add_child_notify(p_child);
Control *c = Object::cast_to<Control>(p_child);
- if (!c)
+ if (!c) {
return;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
return;
+ }
bool first = false;
- if (get_tab_count() != 1)
+ if (get_tab_count() != 1) {
c->hide();
- else {
+ } else {
c->show();
//call_deferred("set_current_tab",0);
first = true;
@@ -507,8 +525,9 @@ void TabContainer::add_child_notify(Node *p_child) {
previous = 0;
}
c->set_anchors_and_margins_preset(Control::PRESET_WIDE);
- if (tabs_visible)
+ if (tabs_visible) {
c->set_margin(MARGIN_TOP, _get_top_margin());
+ }
Ref<StyleBox> sb = get_theme_stylebox("panel");
c->set_margin(Margin(MARGIN_TOP), c->get_margin(Margin(MARGIN_TOP)) + sb->get_margin(Margin(MARGIN_TOP)));
c->set_margin(Margin(MARGIN_LEFT), c->get_margin(Margin(MARGIN_LEFT)) + sb->get_margin(Margin(MARGIN_LEFT)));
@@ -517,8 +536,9 @@ void TabContainer::add_child_notify(Node *p_child) {
update();
p_child->connect("renamed", callable_mp(this, &TabContainer::_child_renamed_callback));
- if (first && is_inside_tree())
+ if (first && is_inside_tree()) {
emit_signal("tab_changed", current);
+ }
}
int TabContainer::get_tab_count() const {
@@ -538,22 +558,24 @@ void TabContainer::set_current_tab(int p_current) {
if (i == current) {
c->show();
c->set_anchors_and_margins_preset(Control::PRESET_WIDE);
- if (tabs_visible)
+ if (tabs_visible) {
c->set_margin(MARGIN_TOP, _get_top_margin());
+ }
c->set_margin(Margin(MARGIN_TOP), c->get_margin(Margin(MARGIN_TOP)) + sb->get_margin(Margin(MARGIN_TOP)));
c->set_margin(Margin(MARGIN_LEFT), c->get_margin(Margin(MARGIN_LEFT)) + sb->get_margin(Margin(MARGIN_LEFT)));
c->set_margin(Margin(MARGIN_RIGHT), c->get_margin(Margin(MARGIN_RIGHT)) - sb->get_margin(Margin(MARGIN_RIGHT)));
c->set_margin(Margin(MARGIN_BOTTOM), c->get_margin(Margin(MARGIN_BOTTOM)) - sb->get_margin(Margin(MARGIN_BOTTOM)));
- } else
+ } else {
c->hide();
+ }
}
_change_notify("current_tab");
- if (pending_previous == current)
+ if (pending_previous == current) {
emit_signal("tab_selected", current);
- else {
+ } else {
previous = pending_previous;
emit_signal("tab_selected", current);
emit_signal("tab_changed", current);
@@ -572,18 +594,20 @@ int TabContainer::get_previous_tab() const {
Control *TabContainer::get_tab_control(int p_idx) const {
Vector<Control *> tabs = _get_tabs();
- if (p_idx >= 0 && p_idx < tabs.size())
+ if (p_idx >= 0 && p_idx < tabs.size()) {
return tabs[p_idx];
- else
+ } else {
return nullptr;
+ }
}
Control *TabContainer::get_current_tab_control() const {
Vector<Control *> tabs = _get_tabs();
- if (current >= 0 && current < tabs.size())
+ if (current >= 0 && current < tabs.size()) {
return tabs[current];
- else
+ } else {
return nullptr;
+ }
}
void TabContainer::remove_child_notify(Node *p_child) {
@@ -598,22 +622,26 @@ void TabContainer::remove_child_notify(Node *p_child) {
void TabContainer::_update_current_tab() {
int tc = get_tab_count();
- if (current >= tc)
+ if (current >= tc) {
current = tc - 1;
- if (current < 0)
+ }
+ if (current < 0) {
current = 0;
- else
+ } else {
set_current_tab(current);
+ }
}
Variant TabContainer::get_drag_data(const Point2 &p_point) {
- if (!drag_to_rearrange_enabled)
+ if (!drag_to_rearrange_enabled) {
return Variant();
+ }
int tab_over = get_tab_idx_at_point(p_point);
- if (tab_over < 0)
+ if (tab_over < 0) {
return Variant();
+ }
HBoxContainer *drag_preview = memnew(HBoxContainer);
@@ -635,12 +663,14 @@ Variant TabContainer::get_drag_data(const Point2 &p_point) {
}
bool TabContainer::can_drop_data(const Point2 &p_point, const Variant &p_data) const {
- if (!drag_to_rearrange_enabled)
+ if (!drag_to_rearrange_enabled) {
return false;
+ }
Dictionary d = p_data;
- if (!d.has("type"))
+ if (!d.has("type")) {
return false;
+ }
if (String(d["type"]) == "tabc_element") {
NodePath from_path = d["from_path"];
@@ -660,22 +690,25 @@ bool TabContainer::can_drop_data(const Point2 &p_point, const Variant &p_data) c
}
void TabContainer::drop_data(const Point2 &p_point, const Variant &p_data) {
- if (!drag_to_rearrange_enabled)
+ if (!drag_to_rearrange_enabled) {
return;
+ }
int hover_now = get_tab_idx_at_point(p_point);
Dictionary d = p_data;
- if (!d.has("type"))
+ if (!d.has("type")) {
return;
+ }
if (String(d["type"]) == "tabc_element") {
int tab_from_id = d["tabc_element"];
NodePath from_path = d["from_path"];
NodePath to_path = get_path();
if (from_path == to_path) {
- if (hover_now < 0)
+ if (hover_now < 0) {
hover_now = get_tab_count() - 1;
+ }
move_child(get_tab_control(tab_from_id), hover_now);
set_current_tab(hover_now);
} else if (get_tabs_rearrange_group() != -1) {
@@ -686,8 +719,9 @@ void TabContainer::drop_data(const Point2 &p_point, const Variant &p_data) {
Control *moving_tabc = from_tabc->get_tab_control(tab_from_id);
from_tabc->remove_child(moving_tabc);
add_child(moving_tabc);
- if (hover_now < 0)
+ if (hover_now < 0) {
hover_now = get_tab_count() - 1;
+ }
move_child(moving_tabc, hover_now);
set_current_tab(hover_now);
emit_signal("tab_changed", hover_now);
@@ -698,12 +732,14 @@ void TabContainer::drop_data(const Point2 &p_point, const Variant &p_data) {
}
int TabContainer::get_tab_idx_at_point(const Point2 &p_point) const {
- if (get_tab_count() == 0)
+ if (get_tab_count() == 0) {
return -1;
+ }
// must be on tabs in the tab header area.
- if (p_point.x < tabs_ofs_cache || p_point.y > _get_top_margin())
+ if (p_point.x < tabs_ofs_cache || p_point.y > _get_top_margin()) {
return -1;
+ }
Size2 size = get_size();
int right_ofs = 0;
@@ -748,18 +784,20 @@ TabContainer::TabAlign TabContainer::get_tab_align() const {
}
void TabContainer::set_tabs_visible(bool p_visible) {
- if (p_visible == tabs_visible)
+ if (p_visible == tabs_visible) {
return;
+ }
tabs_visible = p_visible;
Vector<Control *> tabs = _get_tabs();
for (int i = 0; i < tabs.size(); i++) {
Control *c = tabs[i];
- if (p_visible)
+ if (p_visible) {
c->set_margin(MARGIN_TOP, _get_top_margin());
- else
+ } else {
c->set_margin(MARGIN_TOP, 0);
+ }
}
update();
@@ -784,10 +822,11 @@ void TabContainer::set_tab_title(int p_tab, const String &p_title) {
String TabContainer::get_tab_title(int p_tab) const {
Control *child = _get_tab(p_tab);
ERR_FAIL_COND_V(!child, "");
- if (child->has_meta("_tab_name"))
+ if (child->has_meta("_tab_name")) {
return child->get_meta("_tab_name");
- else
+ } else {
return child->get_name();
+ }
}
void TabContainer::set_tab_icon(int p_tab, const Ref<Texture2D> &p_icon) {
@@ -800,10 +839,11 @@ void TabContainer::set_tab_icon(int p_tab, const Ref<Texture2D> &p_icon) {
Ref<Texture2D> TabContainer::get_tab_icon(int p_tab) const {
Control *child = _get_tab(p_tab);
ERR_FAIL_COND_V(!child, Ref<Texture2D>());
- if (child->has_meta("_tab_icon"))
+ if (child->has_meta("_tab_icon")) {
return child->get_meta("_tab_icon");
- else
+ } else {
return Ref<Texture2D>();
+ }
}
void TabContainer::set_tab_disabled(int p_tab, bool p_disabled) {
@@ -816,10 +856,11 @@ void TabContainer::set_tab_disabled(int p_tab, bool p_disabled) {
bool TabContainer::get_tab_disabled(int p_tab) const {
Control *child = _get_tab(p_tab);
ERR_FAIL_COND_V(!child, false);
- if (child->has_meta("_tab_disabled"))
+ if (child->has_meta("_tab_disabled")) {
return child->get_meta("_tab_disabled");
- else
+ } else {
return false;
+ }
}
void TabContainer::set_tab_hidden(int p_tab, bool p_hidden) {
@@ -844,10 +885,11 @@ void TabContainer::set_tab_hidden(int p_tab, bool p_hidden) {
bool TabContainer::get_tab_hidden(int p_tab) const {
Control *child = _get_tab(p_tab);
ERR_FAIL_COND_V(!child, false);
- if (child->has_meta("_tab_hidden"))
+ if (child->has_meta("_tab_hidden")) {
return child->get_meta("_tab_hidden");
- else
+ } else {
return false;
+ }
}
void TabContainer::get_translatable_strings(List<String> *p_strings) const {
@@ -855,13 +897,15 @@ void TabContainer::get_translatable_strings(List<String> *p_strings) const {
for (int i = 0; i < tabs.size(); i++) {
Control *c = tabs[i];
- if (!c->has_meta("_tab_name"))
+ if (!c->has_meta("_tab_name")) {
continue;
+ }
String name = c->get_meta("_tab_name");
- if (name != "")
+ if (name != "") {
p_strings->push_back(name);
+ }
}
}
@@ -872,8 +916,9 @@ Size2 TabContainer::get_minimum_size() const {
for (int i = 0; i < tabs.size(); i++) {
Control *c = tabs[i];
- if (!c->is_visible_in_tree() && !use_hidden_tabs_for_min_size)
+ if (!c->is_visible_in_tree() && !use_hidden_tabs_for_min_size) {
continue;
+ }
Size2 cms = c->get_combined_minimum_size();
ms.x = MAX(ms.x, cms.x);
diff --git a/scene/gui/tabs.cpp b/scene/gui/tabs.cpp
index 4c3fa2f038..8f71aa7cab 100644
--- a/scene/gui/tabs.cpp
+++ b/scene/gui/tabs.cpp
@@ -47,18 +47,20 @@ Size2 Tabs::get_minimum_size() const {
Ref<Texture2D> tex = tabs[i].icon;
if (tex.is_valid()) {
ms.height = MAX(ms.height, tex->get_size().height);
- if (tabs[i].text != "")
+ if (tabs[i].text != "") {
ms.width += get_theme_constant("hseparation");
+ }
}
ms.width += Math::ceil(font->get_string_size(tabs[i].xl_text).width);
- if (tabs[i].disabled)
+ if (tabs[i].disabled) {
ms.width += tab_disabled->get_minimum_size().width;
- else if (current == i)
+ } else if (current == i) {
ms.width += tab_fg->get_minimum_size().width;
- else
+ } else {
ms.width += tab_bg->get_minimum_size().width;
+ }
if (tabs[i].right_button.is_valid()) {
Ref<Texture2D> rb = tabs[i].right_button;
@@ -293,8 +295,9 @@ void Tabs::_notification(int p_what) {
Ref<Texture2D> icon = tabs[i].icon;
if (icon.is_valid()) {
icon->draw(ci, Point2i(w, sb->get_margin(MARGIN_TOP) + ((sb_rect.size.y - sb_ms.y) - icon->get_height()) / 2));
- if (tabs[i].text != "")
+ if (tabs[i].text != "") {
w += icon->get_width() + get_theme_constant("hseparation");
+ }
}
font->draw(ci, Point2i(w, sb->get_margin(MARGIN_TOP) + ((sb_rect.size.y - sb_ms.y) - font->get_height()) / 2 + font->get_ascent()), tabs[i].xl_text, col, tabs[i].size_text);
@@ -313,10 +316,11 @@ void Tabs::_notification(int p_what) {
rb_rect.position.y = sb->get_margin(MARGIN_TOP) + ((sb_rect.size.y - sb_ms.y) - (rb_rect.size.y)) / 2;
if (rb_hover == i) {
- if (rb_pressing)
+ if (rb_pressing) {
get_theme_stylebox("button_pressed")->draw(ci, rb_rect);
- else
+ } else {
style->draw(ci, rb_rect);
+ }
}
rb->draw(ci, Point2i(w + style->get_margin(MARGIN_LEFT), rb_rect.position.y + style->get_margin(MARGIN_TOP)));
@@ -336,10 +340,11 @@ void Tabs::_notification(int p_what) {
cb_rect.position.y = sb->get_margin(MARGIN_TOP) + ((sb_rect.size.y - sb_ms.y) - (cb_rect.size.y)) / 2;
if (!tabs[i].disabled && cb_hover == i) {
- if (cb_pressing)
+ if (cb_pressing) {
get_theme_stylebox("button_pressed")->draw(ci, cb_rect);
- else
+ } else {
style->draw(ci, cb_rect);
+ }
}
cb->draw(ci, Point2i(w + style->get_margin(MARGIN_LEFT), cb_rect.position.y + style->get_margin(MARGIN_TOP)));
@@ -353,15 +358,17 @@ void Tabs::_notification(int p_what) {
if (offset > 0 || missing_right) {
int vofs = (get_size().height - incr->get_size().height) / 2;
- if (offset > 0)
+ if (offset > 0) {
draw_texture(highlight_arrow == 0 ? decr_hl : decr, Point2(limit, vofs));
- else
+ } else {
draw_texture(decr, Point2(limit, vofs), Color(1, 1, 1, 0.5));
+ }
- if (missing_right)
+ if (missing_right) {
draw_texture(highlight_arrow == 1 ? incr_hl : incr, Point2(limit + decr->get_size().width, vofs));
- else
+ } else {
draw_texture(incr, Point2(limit + decr->get_size().width, vofs), Color(1, 1, 1, 0.5));
+ }
buttons_visible = true;
} else {
@@ -376,8 +383,9 @@ int Tabs::get_tab_count() const {
}
void Tabs::set_current_tab(int p_current) {
- if (current == p_current)
+ if (current == p_current) {
return;
+ }
ERR_FAIL_INDEX(p_current, get_tab_count());
current = p_current;
@@ -587,29 +595,34 @@ void Tabs::clear_tabs() {
void Tabs::remove_tab(int p_idx) {
ERR_FAIL_INDEX(p_idx, tabs.size());
tabs.remove(p_idx);
- if (current >= p_idx)
+ if (current >= p_idx) {
current--;
+ }
_update_cache();
call_deferred("_update_hover");
update();
minimum_size_changed();
- if (current < 0)
+ if (current < 0) {
current = 0;
- if (current >= tabs.size())
+ }
+ if (current >= tabs.size()) {
current = tabs.size() - 1;
+ }
_ensure_no_over_offset();
}
Variant Tabs::get_drag_data(const Point2 &p_point) {
- if (!drag_to_rearrange_enabled)
+ if (!drag_to_rearrange_enabled) {
return Variant();
+ }
int tab_over = get_tab_idx_at_point(p_point);
- if (tab_over < 0)
+ if (tab_over < 0) {
return Variant();
+ }
HBoxContainer *drag_preview = memnew(HBoxContainer);
@@ -635,12 +648,14 @@ Variant Tabs::get_drag_data(const Point2 &p_point) {
}
bool Tabs::can_drop_data(const Point2 &p_point, const Variant &p_data) const {
- if (!drag_to_rearrange_enabled)
+ if (!drag_to_rearrange_enabled) {
return false;
+ }
Dictionary d = p_data;
- if (!d.has("type"))
+ if (!d.has("type")) {
return false;
+ }
if (String(d["type"]) == "tab_element") {
NodePath from_path = d["from_path"];
@@ -660,22 +675,25 @@ bool Tabs::can_drop_data(const Point2 &p_point, const Variant &p_data) const {
}
void Tabs::drop_data(const Point2 &p_point, const Variant &p_data) {
- if (!drag_to_rearrange_enabled)
+ if (!drag_to_rearrange_enabled) {
return;
+ }
int hover_now = get_tab_idx_at_point(p_point);
Dictionary d = p_data;
- if (!d.has("type"))
+ if (!d.has("type")) {
return;
+ }
if (String(d["type"]) == "tab_element") {
int tab_from_id = d["tab_element"];
NodePath from_path = d["from_path"];
NodePath to_path = get_path();
if (from_path == to_path) {
- if (hover_now < 0)
+ if (hover_now < 0) {
hover_now = get_tab_count() - 1;
+ }
move_tab(tab_from_id, hover_now);
emit_signal("reposition_active_tab_request", hover_now);
set_current_tab(hover_now);
@@ -684,11 +702,13 @@ void Tabs::drop_data(const Point2 &p_point, const Variant &p_data) {
Node *from_node = get_node(from_path);
Tabs *from_tabs = Object::cast_to<Tabs>(from_node);
if (from_tabs && from_tabs->get_tabs_rearrange_group() == get_tabs_rearrange_group()) {
- if (tab_from_id >= from_tabs->get_tab_count())
+ if (tab_from_id >= from_tabs->get_tab_count()) {
return;
+ }
Tab moving_tab = from_tabs->tabs[tab_from_id];
- if (hover_now < 0)
+ if (hover_now < 0) {
hover_now = get_tab_count();
+ }
tabs.insert(hover_now, moving_tab);
from_tabs->remove_tab(tab_from_id);
set_current_tab(hover_now);
@@ -723,8 +743,9 @@ Tabs::TabAlign Tabs::get_tab_align() const {
}
void Tabs::move_tab(int from, int to) {
- if (from == to)
+ if (from == to) {
return;
+ }
ERR_FAIL_INDEX(from, tabs.size());
ERR_FAIL_INDEX(to, tabs.size());
@@ -750,18 +771,20 @@ int Tabs::get_tab_width(int p_idx) const {
Ref<Texture2D> tex = tabs[p_idx].icon;
if (tex.is_valid()) {
x += tex->get_width();
- if (tabs[p_idx].text != "")
+ if (tabs[p_idx].text != "") {
x += get_theme_constant("hseparation");
+ }
}
x += Math::ceil(font->get_string_size(tabs[p_idx].xl_text).width);
- if (tabs[p_idx].disabled)
+ if (tabs[p_idx].disabled) {
x += tab_disabled->get_minimum_size().width;
- else if (current == p_idx)
+ } else if (current == p_idx) {
x += tab_fg->get_minimum_size().width;
- else
+ } else {
x += tab_bg->get_minimum_size().width;
+ }
if (tabs[p_idx].right_button.is_valid()) {
Ref<Texture2D> rb = tabs[p_idx].right_button;
@@ -779,8 +802,9 @@ int Tabs::get_tab_width(int p_idx) const {
}
void Tabs::_ensure_no_over_offset() {
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
Ref<Texture2D> incr = get_theme_icon("increment");
Ref<Texture2D> decr = get_theme_icon("decrement");
@@ -803,11 +827,13 @@ void Tabs::_ensure_no_over_offset() {
}
void Tabs::ensure_tab_visible(int p_idx) {
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
- if (tabs.size() == 0)
+ if (tabs.size() == 0) {
return;
+ }
ERR_FAIL_INDEX(p_idx, tabs.size());
if (p_idx == offset) {
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index c5067c9efd..52aee8f089 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -89,23 +89,29 @@ static bool _is_pair_symbol(CharType c) {
}
static CharType _get_right_pair_symbol(CharType c) {
- if (c == '"')
+ if (c == '"') {
return '"';
- if (c == '\'')
+ }
+ if (c == '\'') {
return '\'';
- if (c == '(')
+ }
+ if (c == '(') {
return ')';
- if (c == '[')
+ }
+ if (c == '[') {
return ']';
- if (c == '{')
+ }
+ if (c == '{') {
return '}';
+ }
return 0;
}
static int _find_first_non_whitespace_column_of_line(const String &line) {
int left = 0;
- while (left < line.length() && _is_whitespace(line[left]))
+ while (left < line.length() && _is_whitespace(line[left])) {
left++;
+ }
return left;
}
@@ -138,8 +144,9 @@ void TextEdit::Text::_update_line_cache(int p_line) const {
text.write[p_line].region_info.clear();
for (int i = 0; i < len; i++) {
- if (!_is_symbol(str[i]))
+ if (!_is_symbol(str[i])) {
continue;
+ }
if (str[i] == '\\') {
i++; // Skip quoted anything.
continue;
@@ -269,8 +276,9 @@ int TextEdit::Text::get_max_width(bool p_exclude_hidden) const {
int max = 0;
for (int i = 0; i < text.size(); i++) {
- if (!p_exclude_hidden || !is_hidden(i))
+ if (!p_exclude_hidden || !is_hidden(i)) {
max = MAX(max, get_line_width(i));
+ }
}
return max;
}
@@ -307,10 +315,11 @@ int TextEdit::Text::get_char_width(CharType c, CharType next_c, int px) const {
if (c == '\t') {
int left = px % tab_w;
- if (left == 0)
+ if (left == 0) {
w = tab_w;
- else
+ } else {
w = tab_w - px % tab_w; // Is right.
+ }
} else {
w = font->get_char_size(c, next_c).width;
}
@@ -337,8 +346,9 @@ void TextEdit::_update_scrollbars() {
int visible_width = size.width - cache.style_normal->get_minimum_size().width;
int total_width = text.get_max_width(true) + vmin.x;
- if (line_numbers)
+ if (line_numbers) {
total_width += cache.line_number_w;
+ }
if (draw_breakpoint_gutter || draw_bookmark_gutter) {
total_width += cache.breakpoint_gutter_width;
@@ -397,8 +407,9 @@ void TextEdit::_update_scrollbars() {
h_scroll->show();
h_scroll->set_max(total_width);
h_scroll->set_page(visible_width);
- if (cursor.x_ofs > (total_width - visible_width))
+ if (cursor.x_ofs > (total_width - visible_width)) {
cursor.x_ofs = (total_width - visible_width);
+ }
if (fabs(h_scroll->get_value() - (double)cursor.x_ofs) >= 1) {
h_scroll->set_value(cursor.x_ofs);
}
@@ -586,10 +597,12 @@ void TextEdit::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
_update_caches();
- if (cursor_changed_dirty)
+ if (cursor_changed_dirty) {
MessageQueue::get_singleton()->push_call(this, "_cursor_changed_emit");
- if (text_changed_dirty)
+ }
+ if (text_changed_dirty) {
MessageQueue::get_singleton()->push_call(this, "_text_changed_emit");
+ }
_update_wrap_at();
} break;
case NOTIFICATION_RESIZED: {
@@ -705,8 +718,9 @@ void TextEdit::_notification(int p_what) {
cache.style_readonly->draw(ci, Rect2(Point2(), size));
draw_caret = false;
}
- if (has_focus())
+ if (has_focus()) {
cache.style_focus->draw(ci, Rect2(Point2(), size));
+ }
int ascent = cache.font->get_ascent();
@@ -787,10 +801,11 @@ void TextEdit::_notification(int p_what) {
}
}
} while (cc != quotation);
- } else if (cc == c)
+ } else if (cc == c) {
stack++;
- else if (cc == closec)
+ } else if (cc == closec) {
stack--;
+ }
if (stack == 0) {
brace_open_match_line = i;
@@ -800,12 +815,14 @@ void TextEdit::_notification(int p_what) {
break;
}
}
- if (brace_open_match_line != -1)
+ if (brace_open_match_line != -1) {
break;
+ }
}
- if (!brace_open_matching)
+ if (!brace_open_matching) {
brace_open_mismatch = true;
+ }
}
}
@@ -850,10 +867,11 @@ void TextEdit::_notification(int p_what) {
}
}
} while (cc != quotation);
- } else if (cc == c)
+ } else if (cc == c) {
stack++;
- else if (cc == closec)
+ } else if (cc == closec) {
stack--;
+ }
if (stack == 0) {
brace_close_match_line = i;
@@ -863,12 +881,14 @@ void TextEdit::_notification(int p_what) {
break;
}
}
- if (brace_close_match_line != -1)
+ if (brace_close_match_line != -1) {
break;
+ }
}
- if (!brace_close_matching)
+ if (!brace_close_matching) {
brace_close_mismatch = true;
+ }
}
}
}
@@ -951,8 +971,9 @@ void TextEdit::_notification(int p_what) {
for (int line_wrap_index = 0; line_wrap_index < line_wrap_amount + 1; line_wrap_index++) {
if (line_wrap_index != 0) {
i++;
- if (i >= minimap_draw_amount)
+ if (i >= minimap_draw_amount) {
break;
+ }
}
const String &str = wrap_rows[line_wrap_index];
@@ -1039,8 +1060,9 @@ void TextEdit::_notification(int p_what) {
for (int i = 0; i < draw_amount; i++) {
line++;
- if (line < 0 || line >= (int)text.size())
+ if (line < 0 || line >= (int)text.size()) {
continue;
+ }
while (is_line_hidden(line)) {
line++;
@@ -1049,8 +1071,9 @@ void TextEdit::_notification(int p_what) {
}
}
- if (line < 0 || line >= (int)text.size())
+ if (line < 0 || line >= (int)text.size()) {
continue;
+ }
const String &fullstr = text[line];
@@ -1070,8 +1093,9 @@ void TextEdit::_notification(int p_what) {
for (int line_wrap_index = 0; line_wrap_index < line_wrap_amount + 1; line_wrap_index++) {
if (line_wrap_index != 0) {
i++;
- if (i >= draw_amount)
+ if (i >= draw_amount) {
break;
+ }
}
const String &str = wrap_rows[line_wrap_index];
@@ -1080,8 +1104,9 @@ void TextEdit::_notification(int p_what) {
indent_px = 0;
}
- if (line_wrap_index > 0)
+ if (line_wrap_index > 0) {
last_wrap_column += wrap_rows[line_wrap_index - 1].length();
+ }
int char_margin = xmargin_beg - cursor.x_ofs;
char_margin += indent_px;
@@ -1096,19 +1121,22 @@ void TextEdit::_notification(int p_what) {
int ofs_y = (i * get_row_height() + cache.line_spacing / 2) + ofs_readonly;
ofs_y -= cursor.wrap_ofs * get_row_height();
- if (smooth_scroll_enabled)
+ if (smooth_scroll_enabled) {
ofs_y += (-get_v_scroll_offset()) * get_row_height();
+ }
// Check if line contains highlighted word.
int highlighted_text_col = -1;
int search_text_col = -1;
int highlighted_word_col = -1;
- if (!search_text.empty())
+ if (!search_text.empty()) {
search_text_col = _get_column_pos_of_word(search_text, str, search_flags, 0);
+ }
- if (highlighted_text.length() != 0 && highlighted_text != search_text)
+ if (highlighted_text.length() != 0 && highlighted_text != search_text) {
highlighted_text_col = _get_column_pos_of_word(highlighted_text, str, SEARCH_MATCH_CASE | SEARCH_WHOLE_WORDS, 0);
+ }
if (select_identifiers_enabled && highlighted_word.length() != 0) {
if (_is_char(highlighted_word[0]) || highlighted_word[0] == '.') {
@@ -1283,8 +1311,9 @@ void TextEdit::_notification(int p_what) {
if (search_text_col != -1) {
// If we are at the end check for new search result on same line.
- if (j >= search_text_col + search_text.length())
+ if (j >= search_text_col + search_text.length()) {
search_text_col = _get_column_pos_of_word(search_text, str, search_flags, j);
+ }
in_search_result = j >= search_text_col && j < search_text_col + search_text.length();
@@ -1321,10 +1350,12 @@ void TextEdit::_notification(int p_what) {
RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(char_ofs + char_margin + ofs_x, ofs_y), Size2i(char_w, 1)), border_color);
RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(char_ofs + char_margin + ofs_x, ofs_y + get_row_height() - 1), Size2i(char_w, 1)), border_color);
- if (j == search_text_col)
+ if (j == search_text_col) {
RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(char_ofs + char_margin + ofs_x, ofs_y), Size2i(1, get_row_height())), border_color);
- if (j == search_text_col + search_text.length() - 1)
+ }
+ if (j == search_text_col + search_text.length() - 1) {
RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(char_ofs + char_margin + char_w + ofs_x - 1, ofs_y), Size2i(1, get_row_height())), border_color);
+ }
}
if (highlight_all_occurrences && !only_whitespaces_highlighted) {
@@ -1358,15 +1389,17 @@ void TextEdit::_notification(int p_what) {
int yofs = ofs_y + (get_row_height() - cache.font->get_height()) / 2;
if ((brace_open_match_line == line && brace_open_match_column == last_wrap_column + j) ||
(cursor.column == last_wrap_column + j && cursor.line == line && cursor_wrap_index == line_wrap_index && (brace_open_matching || brace_open_mismatch))) {
- if (brace_open_mismatch)
+ if (brace_open_mismatch) {
color = cache.brace_mismatch_color;
+ }
drawer.draw_char(ci, Point2i(char_ofs + char_margin + ofs_x, yofs + ascent), '_', str[j + 1], in_selection && override_selected_font_color ? cache.font_color_selected : color);
}
if ((brace_close_match_line == line && brace_close_match_column == last_wrap_column + j) ||
(cursor.column == last_wrap_column + j + 1 && cursor.line == line && cursor_wrap_index == line_wrap_index && (brace_close_matching || brace_close_mismatch))) {
- if (brace_close_mismatch)
+ if (brace_close_mismatch) {
color = cache.brace_mismatch_color;
+ }
drawer.draw_char(ci, Point2i(char_ofs + char_margin + ofs_x, yofs + ascent), '_', str[j + 1], in_selection && override_selected_font_color ? cache.font_color_selected : color);
}
}
@@ -1384,15 +1417,17 @@ void TextEdit::_notification(int p_what) {
if (ime_text.length() > 0) {
int ofs = 0;
while (true) {
- if (ofs >= ime_text.length())
+ if (ofs >= ime_text.length()) {
break;
+ }
CharType cchar = ime_text[ofs];
CharType next = ime_text[ofs + 1];
int im_char_width = cache.font->get_char_size(cchar, next).width;
- if ((char_ofs + char_margin + im_char_width) >= xmargin_end)
+ if ((char_ofs + char_margin + im_char_width) >= xmargin_end) {
break;
+ }
bool selected = ofs >= ime_selection.x && ofs < ime_selection.x + ime_selection.y;
if (selected) {
@@ -1478,15 +1513,17 @@ void TextEdit::_notification(int p_what) {
if (ime_text.length() > 0) {
int ofs = 0;
while (true) {
- if (ofs >= ime_text.length())
+ if (ofs >= ime_text.length()) {
break;
+ }
CharType cchar = ime_text[ofs];
CharType next = ime_text[ofs + 1];
int im_char_width = cache.font->get_char_size(cchar, next).width;
- if ((char_ofs + char_margin + im_char_width) >= xmargin_end)
+ if ((char_ofs + char_margin + im_char_width) >= xmargin_end) {
break;
+ }
bool selected = ofs >= ime_selection.x && ofs < ime_selection.x + ime_selection.y;
if (selected) {
@@ -1545,8 +1582,9 @@ void TextEdit::_notification(int p_what) {
if (completion_options_size < 50) {
for (int i = 0; i < completion_options_size; i++) {
int w2 = MIN(cache.font->get_string_size(completion_options[i].display).x, cmax_width);
- if (w2 > w)
+ if (w2 > w) {
w = w2;
+ }
}
} else {
w = cmax_width;
@@ -1574,8 +1612,9 @@ void TextEdit::_notification(int p_what) {
completion_rect.size.width = w + 2;
completion_rect.size.height = h;
- if (completion_options_size <= maxlines)
+ if (completion_options_size <= maxlines) {
scrollw = 0;
+ }
draw_style_box(csb, Rect2(completion_rect.position - csb->get_offset(), completion_rect.size + csb->get_minimum_size() + Size2(scrollw, 0)));
@@ -1716,8 +1755,9 @@ void TextEdit::_notification(int p_what) {
DisplayServer::get_singleton()->window_set_ime_position(get_global_position() + cursor_pos, get_viewport()->get_window_id());
}
- if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_VIRTUAL_KEYBOARD))
+ if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_VIRTUAL_KEYBOARD)) {
DisplayServer::get_singleton()->virtual_keyboard_show(get_text(), get_global_rect());
+ }
} break;
case NOTIFICATION_FOCUS_EXIT: {
if (caret_blink_enabled) {
@@ -1731,8 +1771,9 @@ void TextEdit::_notification(int p_what) {
ime_text = "";
ime_selection = Point2();
- if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_VIRTUAL_KEYBOARD))
+ if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_VIRTUAL_KEYBOARD)) {
DisplayServer::get_singleton()->virtual_keyboard_hide();
+ }
} break;
case MainLoop::NOTIFICATION_OS_IME_UPDATE: {
if (has_focus()) {
@@ -1760,8 +1801,9 @@ void TextEdit::_consume_pair_symbol(CharType ch) {
&new_line, &new_column);
int to_col_offset = 0;
- if (get_selection_from_line() == get_selection_to_line())
+ if (get_selection_from_line() == get_selection_to_line()) {
to_col_offset = 1;
+ }
_insert_text(get_selection_to_line(),
get_selection_to_column() + to_col_offset,
@@ -1868,20 +1910,24 @@ void TextEdit::_consume_backspace_for_pair_symbol(int prev_line, int prev_column
}
void TextEdit::backspace_at_cursor() {
- if (readonly)
+ if (readonly) {
return;
+ }
- if (cursor.column == 0 && cursor.line == 0)
+ if (cursor.column == 0 && cursor.line == 0) {
return;
+ }
int prev_line = cursor.column ? cursor.line : cursor.line - 1;
int prev_column = cursor.column ? (cursor.column - 1) : (text[cursor.line - 1].length());
- if (is_line_hidden(cursor.line))
+ if (is_line_hidden(cursor.line)) {
set_line_as_hidden(prev_line, true);
+ }
if (is_line_set_as_breakpoint(cursor.line)) {
- if (!text.is_breakpoint(prev_line))
+ if (!text.is_breakpoint(prev_line)) {
emit_signal("breakpoint_toggled", prev_line);
+ }
set_line_as_breakpoint(prev_line, true);
}
@@ -1956,8 +2002,9 @@ void TextEdit::indent_right() {
int spaces_to_add = _calculate_spaces_till_next_right_indent(left);
// Since we will add this much spaces we want move whole selection and cursor by this much.
selection_offset = spaces_to_add;
- for (int j = 0; j < spaces_to_add; j++)
+ for (int j = 0; j < spaces_to_add; j++) {
line_text = ' ' + line_text;
+ }
} else {
line_text = '\t' + line_text;
}
@@ -2034,8 +2081,9 @@ void TextEdit::indent_left() {
int TextEdit::_calculate_spaces_till_next_left_indent(int column) {
int spaces_till_indent = column % indent_size;
- if (spaces_till_indent == 0)
+ if (spaces_till_indent == 0) {
spaces_till_indent = indent_size;
+ }
return spaces_till_indent;
}
@@ -2054,14 +2102,16 @@ void TextEdit::_get_mouse_pos(const Point2i &p_mouse, int &r_row, int &r_col) co
if (is_wrap_enabled() || is_hiding_enabled()) {
int f_ofs = num_lines_from_rows(first_vis_line, cursor.wrap_ofs, rows + (1 * SGN(rows)), wrap_index) - 1;
- if (rows < 0)
+ if (rows < 0) {
row = first_vis_line - f_ofs;
- else
+ } else {
row = first_vis_line + f_ofs;
+ }
}
- if (row < 0)
+ if (row < 0) {
row = 0; // TODO.
+ }
int col = 0;
@@ -2079,8 +2129,9 @@ void TextEdit::_get_mouse_pos(const Point2i &p_mouse, int &r_row, int &r_col) co
for (int i = 0; i < wrap_index + 1; i++) {
row_end_col += rows2[i].length();
}
- if (col >= row_end_col)
+ if (col >= row_end_col) {
col -= 1;
+ }
}
}
@@ -2187,8 +2238,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
if (mb.is_valid()) {
if (completion_active && completion_rect.has_point(mb->get_position())) {
- if (!mb->is_pressed())
+ if (!mb->is_pressed()) {
return;
+ }
if (mb->get_button_index() == BUTTON_WHEEL_UP) {
if (completion_index > 0) {
@@ -2210,8 +2262,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
completion_current = completion_options[completion_index];
update();
- if (mb->is_doubleclick())
+ if (mb->is_doubleclick()) {
_confirm_completion();
+ }
}
return;
} else {
@@ -2431,8 +2484,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
_scroll_down(delta);
}
h_scroll->set_value(h_scroll->get_value() + pan_gesture->get_delta().x * 100);
- if (v_scroll->get_value() != prev_v_scroll || h_scroll->get_value() != prev_h_scroll)
+ if (v_scroll->get_value() != prev_v_scroll || h_scroll->get_value() != prev_h_scroll) {
accept_event(); // Accept event if scroll changed.
+ }
return;
}
@@ -2479,8 +2533,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
}
- if (v_scroll->get_value() != prev_v_scroll || h_scroll->get_value() != prev_h_scroll)
+ if (v_scroll->get_value() != prev_v_scroll || h_scroll->get_value() != prev_h_scroll) {
accept_event(); // Accept event if scroll changed.
+ }
Ref<InputEventKey> k = p_gui_input;
@@ -2502,16 +2557,19 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
}
- if (!k->is_pressed())
+ if (!k->is_pressed()) {
return;
+ }
if (completion_active) {
- if (readonly)
+ if (readonly) {
return;
+ }
bool valid = true;
- if (k->get_command() || k->get_metakey())
+ if (k->get_command() || k->get_metakey()) {
valid = false;
+ }
if (valid) {
if (!k->get_alt()) {
@@ -2543,8 +2601,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
if (k->get_keycode() == KEY_PAGEUP) {
completion_index -= get_theme_constant("completion_lines");
- if (completion_index < 0)
+ if (completion_index < 0) {
completion_index = 0;
+ }
completion_current = completion_options[completion_index];
update();
accept_event();
@@ -2553,8 +2612,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
if (k->get_keycode() == KEY_PAGEDOWN) {
completion_index += get_theme_constant("completion_lines");
- if (completion_index >= completion_options.size())
+ if (completion_index >= completion_options.size()) {
completion_index = completion_options.size() - 1;
+ }
completion_current = completion_options[completion_index];
update();
accept_event();
@@ -2722,16 +2782,19 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
case KEY_HOME:
case KEY_END:
// Ignore arrows if any modifiers are held (shift = selecting, others may be used for editor hotkeys).
- if (k->get_command() || k->get_shift() || k->get_alt())
+ if (k->get_command() || k->get_shift() || k->get_alt()) {
break;
+ }
unselect = true;
break;
default:
- if (k->get_unicode() >= 32 && !k->get_command() && !k->get_alt() && !k->get_metakey())
+ if (k->get_unicode() >= 32 && !k->get_command() && !k->get_alt() && !k->get_metakey()) {
clear = true;
- if (auto_brace_completion_enabled && _is_pair_left_symbol(k->get_unicode()))
+ }
+ if (auto_brace_completion_enabled && _is_pair_left_symbol(k->get_unicode())) {
clear = false;
+ }
}
if (unselect) {
@@ -2750,8 +2813,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
cursor_set_column(selection.from_column);
update();
}
- if (dobreak)
+ if (dobreak) {
return;
+ }
}
selection.selecting_text = false;
@@ -2763,8 +2827,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
switch (k->get_keycode()) {
case KEY_KP_ENTER:
case KEY_ENTER: {
- if (readonly)
+ if (readonly) {
break;
+ }
String ins = "\n";
@@ -2794,8 +2859,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
}
- if (is_folded(cursor.line))
+ if (is_folded(cursor.line)) {
unfold_line(cursor.line);
+ }
bool brace_indent = false;
@@ -2883,11 +2949,13 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
} break;
case KEY_TAB: {
- if (k->get_command())
+ if (k->get_command()) {
break; // Avoid tab when command.
+ }
- if (readonly)
+ if (readonly) {
break;
+ }
if (is_selection_active()) {
if (k->get_shift()) {
@@ -2904,23 +2972,26 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
int left = _find_first_non_whitespace_column_of_line(line);
cc = MIN(cc, left);
- while (cc < indent_size && cc < left && line[cc] == ' ')
+ while (cc < indent_size && cc < left && line[cc] == ' ') {
cc++;
+ }
if (cc > 0 && cc <= text[cursor.line].length()) {
if (text[cursor.line][cc - 1] == '\t') {
// Tabs unindentation.
_remove_text(cursor.line, cc - 1, cursor.line, cc);
- if (cursor.column >= left)
+ if (cursor.column >= left) {
cursor_set_column(MAX(0, cursor.column - 1));
+ }
update();
} else {
// Spaces unindentation.
int spaces_to_remove = _calculate_spaces_till_next_left_indent(cc);
if (spaces_to_remove > 0) {
_remove_text(cursor.line, cc - spaces_to_remove, cursor.line, cc);
- if (cursor.column > left - spaces_to_remove) // Inside text?
+ if (cursor.column > left - spaces_to_remove) { // Inside text?
cursor_set_column(MAX(0, cursor.column - spaces_to_remove));
+ }
update();
}
}
@@ -2934,8 +3005,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
// Insert only as much spaces as needed till next indentation level.
int spaces_to_add = _calculate_spaces_till_next_right_indent(cursor.column);
String indent_to_insert = String();
- for (int i = 0; i < spaces_to_add; i++)
+ for (int i = 0; i < spaces_to_add; i++) {
indent_to_insert = ' ' + indent_to_insert;
+ }
_insert_text_at_cursor(indent_to_insert);
} else {
_insert_text_at_cursor("\t");
@@ -2945,8 +3017,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
} break;
case KEY_BACKSPACE: {
- if (readonly)
+ if (readonly) {
break;
+ }
#ifdef APPLE_STYLE_KEYS
if (k->get_alt() && cursor.column > 1) {
@@ -3001,8 +3074,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
_remove_text(cursor.line, 0, cursor.line, cursor_current_column);
#endif
} else {
- if (cursor.line > 0 && is_line_hidden(cursor.line - 1))
+ if (cursor.line > 0 && is_line_hidden(cursor.line - 1)) {
unfold_line(cursor.line - 1);
+ }
backspace_at_cursor();
}
@@ -3015,14 +3089,15 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
[[fallthrough]];
}
case KEY_LEFT: {
- if (k->get_shift())
+ if (k->get_shift()) {
_pre_shift_selection();
#ifdef APPLE_STYLE_KEYS
- else
+ } else {
#else
- else if (!k->get_alt())
+ } else if (!k->get_alt()) {
#endif
deselect();
+ }
#ifdef APPLE_STYLE_KEYS
if (k->get_command()) {
@@ -3059,8 +3134,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
while (cc > 0) {
bool ischar = _is_text_char(text[cursor.line][cc - 1]);
- if (prev_char && !ischar)
+ if (prev_char && !ischar) {
break;
+ }
prev_char = ischar;
cc--;
@@ -3077,8 +3153,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
cursor_set_column(cursor_get_column() - 1);
}
- if (k->get_shift())
+ if (k->get_shift()) {
_post_shift_selection();
+ }
} break;
case KEY_KP_6: {
@@ -3089,14 +3166,15 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
[[fallthrough]];
}
case KEY_RIGHT: {
- if (k->get_shift())
+ if (k->get_shift()) {
_pre_shift_selection();
#ifdef APPLE_STYLE_KEYS
- else
+ } else {
#else
- else if (!k->get_alt())
+ } else if (!k->get_alt()) {
#endif
deselect();
+ }
#ifdef APPLE_STYLE_KEYS
if (k->get_command()) {
@@ -3119,8 +3197,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
while (cc < text[cursor.line].length()) {
bool ischar = _is_text_char(text[cursor.line][cc]);
- if (prev_char && !ischar)
+ if (prev_char && !ischar) {
break;
+ }
prev_char = ischar;
cc++;
}
@@ -3136,8 +3215,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
cursor_set_column(cursor_get_column() + 1);
}
- if (k->get_shift())
+ if (k->get_shift()) {
_post_shift_selection();
+ }
} break;
case KEY_KP_8: {
@@ -3186,8 +3266,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
}
- if (k->get_shift())
+ if (k->get_shift()) {
_post_shift_selection();
+ }
_cancel_code_hint();
} break;
@@ -3233,14 +3314,16 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
}
- if (k->get_shift())
+ if (k->get_shift()) {
_post_shift_selection();
+ }
_cancel_code_hint();
} break;
case KEY_DELETE: {
- if (readonly)
+ if (readonly) {
break;
+ }
if (k->get_shift() && !k->get_command() && !k->get_alt() && is_shortcut_keys_enabled()) {
cut();
@@ -3249,8 +3332,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
int curline_len = text[cursor.line].length();
- if (cursor.line == text.size() - 1 && cursor.column == curline_len)
+ if (cursor.line == text.size() - 1 && cursor.column == curline_len) {
break; // Nothing to do.
+ }
int next_line = cursor.column < curline_len ? cursor.line : cursor.line + 1;
int next_column;
@@ -3331,8 +3415,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
else if (k->get_command() || k->get_control())
deselect();
#else
- if (k->get_shift())
+ if (k->get_shift()) {
_pre_shift_selection();
+ }
if (k->get_command()) {
cursor_set_line(0);
@@ -3350,24 +3435,27 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
int current_line_whitespace_len = 0;
while (current_line_whitespace_len < text[cursor.line].length()) {
CharType c = text[cursor.line][current_line_whitespace_len];
- if (c != '\t' && c != ' ')
+ if (c != '\t' && c != ' ') {
break;
+ }
current_line_whitespace_len++;
}
- if (cursor_get_column() == current_line_whitespace_len)
+ if (cursor_get_column() == current_line_whitespace_len) {
cursor_set_column(0);
- else
+ } else {
cursor_set_column(current_line_whitespace_len);
+ }
} else {
cursor_set_column(row_start_col);
}
}
- if (k->get_shift())
+ if (k->get_shift()) {
_post_shift_selection();
- else if (k->get_command() || k->get_control())
+ } else if (k->get_command() || k->get_control()) {
deselect();
+ }
_cancel_completion();
completion_hint = "";
#endif
@@ -3391,11 +3479,13 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
else if (k->get_command() || k->get_control())
deselect();
#else
- if (k->get_shift())
+ if (k->get_shift()) {
_pre_shift_selection();
+ }
- if (k->get_command())
+ if (k->get_command()) {
cursor_set_line(get_last_unhidden_line(), true, false, 9999);
+ }
// Move cursor column to end of wrapped row and then to end of text.
Vector<String> rows = get_wrap_rows_text(cursor.line);
@@ -3410,10 +3500,11 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
cursor_set_column(row_end_col);
}
- if (k->get_shift())
+ if (k->get_shift()) {
_post_shift_selection();
- else if (k->get_command() || k->get_control())
+ } else if (k->get_command() || k->get_control()) {
deselect();
+ }
_cancel_completion();
completion_hint = "";
@@ -3427,15 +3518,17 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
[[fallthrough]];
}
case KEY_PAGEUP: {
- if (k->get_shift())
+ if (k->get_shift()) {
_pre_shift_selection();
+ }
int wi;
int n_line = cursor.line - num_lines_from_rows(cursor.line, get_cursor_wrap_index(), -get_visible_rows(), wi) + 1;
cursor_set_line(n_line, true, false, wi);
- if (k->get_shift())
+ if (k->get_shift()) {
_post_shift_selection();
+ }
_cancel_completion();
completion_hint = "";
@@ -3449,15 +3542,17 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
[[fallthrough]];
}
case KEY_PAGEDOWN: {
- if (k->get_shift())
+ if (k->get_shift()) {
_pre_shift_selection();
+ }
int wi;
int n_line = cursor.line + num_lines_from_rows(cursor.line, get_cursor_wrap_index(), get_visible_rows(), wi) - 1;
cursor_set_line(n_line, true, false, wi);
- if (k->get_shift())
+ if (k->get_shift()) {
_post_shift_selection();
+ }
_cancel_completion();
completion_hint = "";
@@ -3559,10 +3654,11 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
if (is_shortcut_keys_enabled()) {
- if (k->get_shift())
+ if (k->get_shift()) {
redo();
- else
+ } else {
undo();
+ }
}
} break;
case KEY_Y: {
@@ -3623,8 +3719,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
} break;
}
- if (keycode_handled)
+ if (keycode_handled) {
accept_event();
+ }
if (k->get_keycode() == KEY_INSERT) {
set_insert_mode(!insert_mode);
@@ -3635,8 +3732,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
if (!keycode_handled && !k->get_command()) { // For German keyboards.
if (k->get_unicode() >= 32) {
- if (readonly)
+ if (readonly) {
return;
+ }
// Remove the old character if in insert mode and no selection.
if (insert_mode && !had_selection) {
@@ -3808,10 +3906,12 @@ void TextEdit::_base_insert_text(int p_line, int p_char, const String &p_text, i
int lines = substrings.size() - 1;
for (; i < text.size(); i++) {
if (text.is_breakpoint(i)) {
- if ((i - lines < p_line || !text.is_breakpoint(i - lines)) || (i - lines == p_line && !shift_first_line))
+ if ((i - lines < p_line || !text.is_breakpoint(i - lines)) || (i - lines == p_line && !shift_first_line)) {
emit_signal("breakpoint_toggled", i);
- if (i + lines >= text.size() || !text.is_breakpoint(i + lines))
+ }
+ if (i + lines >= text.size() || !text.is_breakpoint(i + lines)) {
emit_signal("breakpoint_toggled", i + lines);
+ }
}
}
@@ -3857,8 +3957,9 @@ void TextEdit::_base_insert_text(int p_line, int p_char, const String &p_text, i
r_end_column = text[r_end_line].length() - postinsert_text.length();
if (!text_changed_dirty && !setting_text) {
- if (is_inside_tree())
+ if (is_inside_tree()) {
MessageQueue::get_singleton()->push_call(this, "_text_changed_emit");
+ }
text_changed_dirty = true;
}
_line_edited_from(p_line);
@@ -3878,8 +3979,9 @@ String TextEdit::_base_get_text(int p_from_line, int p_from_column, int p_to_lin
int begin = (i == p_from_line) ? p_from_column : 0;
int end = (i == p_to_line) ? p_to_column : text[i].length();
- if (i > p_from_line)
+ if (i > p_from_line) {
ret += "\n";
+ }
ret += text[i].substr(begin, end - begin);
}
@@ -3901,10 +4003,12 @@ void TextEdit::_base_remove_text(int p_from_line, int p_from_column, int p_to_li
for (int i = p_from_line + 1; i < text.size(); i++) {
if (text.is_breakpoint(i)) {
- if (i + lines >= text.size() || !text.is_breakpoint(i + lines))
+ if (i + lines >= text.size() || !text.is_breakpoint(i + lines)) {
emit_signal("breakpoint_toggled", i);
- if (i > p_to_line && (i - lines < 0 || !text.is_breakpoint(i - lines)))
+ }
+ if (i > p_to_line && (i - lines < 0 || !text.is_breakpoint(i - lines))) {
emit_signal("breakpoint_toggled", i - lines);
+ }
}
}
@@ -3916,16 +4020,18 @@ void TextEdit::_base_remove_text(int p_from_line, int p_from_column, int p_to_li
text.set_line_wrap_amount(p_from_line, -1);
if (!text_changed_dirty && !setting_text) {
- if (is_inside_tree())
+ if (is_inside_tree()) {
MessageQueue::get_singleton()->push_call(this, "_text_changed_emit");
+ }
text_changed_dirty = true;
}
_line_edited_from(p_from_line);
}
void TextEdit::_insert_text(int p_line, int p_char, const String &p_text, int *r_end_line, int *r_end_char) {
- if (!setting_text && idle_detect->is_inside_tree())
+ if (!setting_text && idle_detect->is_inside_tree()) {
idle_detect->start();
+ }
if (undo_enabled) {
_clear_redo();
@@ -3933,13 +4039,16 @@ void TextEdit::_insert_text(int p_line, int p_char, const String &p_text, int *r
int retline, retchar;
_base_insert_text(p_line, p_char, p_text, retline, retchar);
- if (r_end_line)
+ if (r_end_line) {
*r_end_line = retline;
- if (r_end_char)
+ }
+ if (r_end_char) {
*r_end_char = retchar;
+ }
- if (!undo_enabled)
+ if (!undo_enabled) {
return;
+ }
/* UNDO!! */
TextOperation op;
@@ -3977,8 +4086,9 @@ void TextEdit::_insert_text(int p_line, int p_char, const String &p_text, int *r
}
void TextEdit::_remove_text(int p_from_line, int p_from_column, int p_to_line, int p_to_column) {
- if (!setting_text && idle_detect->is_inside_tree())
+ if (!setting_text && idle_detect->is_inside_tree()) {
idle_detect->start();
+ }
String text;
if (undo_enabled) {
@@ -3988,8 +4098,9 @@ void TextEdit::_remove_text(int p_from_line, int p_from_column, int p_to_line, i
_base_remove_text(p_from_line, p_from_column, p_to_line, p_to_column);
- if (!undo_enabled)
+ if (!undo_enabled) {
return;
+ }
/* UNDO! */
TextOperation op;
@@ -4054,8 +4165,9 @@ int TextEdit::get_char_count() {
int totalsize = 0;
for (int i = 0; i < text.size(); i++) {
- if (i > 0)
+ if (i > 0) {
totalsize++; // Include \n.
+ }
totalsize += text[i].length();
}
@@ -4078,14 +4190,17 @@ int TextEdit::_get_control_height() const {
void TextEdit::_generate_context_menu() {
// Reorganize context menu.
menu->clear();
- if (!readonly)
+ if (!readonly) {
menu->add_item(RTR("Cut"), MENU_CUT, is_shortcut_keys_enabled() ? KEY_MASK_CMD | KEY_X : 0);
+ }
menu->add_item(RTR("Copy"), MENU_COPY, is_shortcut_keys_enabled() ? KEY_MASK_CMD | KEY_C : 0);
- if (!readonly)
+ if (!readonly) {
menu->add_item(RTR("Paste"), MENU_PASTE, is_shortcut_keys_enabled() ? KEY_MASK_CMD | KEY_V : 0);
+ }
menu->add_separator();
- if (is_selecting_enabled())
+ if (is_selecting_enabled()) {
menu->add_item(RTR("Select All"), MENU_SELECT_ALL, is_shortcut_keys_enabled() ? KEY_MASK_CMD | KEY_A : 0);
+ }
if (!readonly) {
menu->add_item(RTR("Clear"), MENU_CLEAR);
menu->add_separator();
@@ -4105,8 +4220,9 @@ int TextEdit::_get_minimap_visible_rows() const {
int TextEdit::get_total_visible_rows() const {
// Returns the total amount of rows we need in the editor.
// This skips hidden lines and counts each wrapping of a line.
- if (!is_hiding_enabled() && !is_wrap_enabled())
+ if (!is_hiding_enabled() && !is_wrap_enabled()) {
return text.size();
+ }
int total_rows = 0;
for (int i = 0; i < text.size(); i++) {
@@ -4125,8 +4241,9 @@ void TextEdit::_update_wrap_at() {
for (int i = 0; i < text.size(); i++) {
// Update all values that wrap.
- if (!line_wraps(i))
+ if (!line_wraps(i)) {
continue;
+ }
Vector<String> rows = get_wrap_rows_text(i);
text.set_line_wrap_amount(i, rows.size() - 1);
}
@@ -4154,19 +4271,22 @@ void TextEdit::adjust_viewport_to_cursor() {
}
int visible_width = get_size().width - cache.style_normal->get_minimum_size().width - cache.line_number_w - cache.breakpoint_gutter_width - cache.fold_gutter_width - cache.info_gutter_width - cache.minimap_width;
- if (v_scroll->is_visible_in_tree())
+ if (v_scroll->is_visible_in_tree()) {
visible_width -= v_scroll->get_combined_minimum_size().width;
+ }
visible_width -= 20; // Give it a little more space.
if (!is_wrap_enabled()) {
// Adjust x offset.
int cursor_x = get_column_x_offset(cursor.column, text[cursor.line]);
- if (cursor_x > (cursor.x_ofs + visible_width))
+ if (cursor_x > (cursor.x_ofs + visible_width)) {
cursor.x_ofs = cursor_x - visible_width + 1;
+ }
- if (cursor_x < cursor.x_ofs)
+ if (cursor_x < cursor.x_ofs) {
cursor.x_ofs = cursor_x;
+ }
} else {
cursor.x_ofs = 0;
}
@@ -4180,24 +4300,28 @@ void TextEdit::center_viewport_to_cursor() {
scrolling = false;
minimap_clicked = false;
- if (is_line_hidden(cursor.line))
+ if (is_line_hidden(cursor.line)) {
unfold_line(cursor.line);
+ }
set_line_as_center_visible(cursor.line, get_cursor_wrap_index());
int visible_width = get_size().width - cache.style_normal->get_minimum_size().width - cache.line_number_w - cache.breakpoint_gutter_width - cache.fold_gutter_width - cache.info_gutter_width - cache.minimap_width;
- if (v_scroll->is_visible_in_tree())
+ if (v_scroll->is_visible_in_tree()) {
visible_width -= v_scroll->get_combined_minimum_size().width;
+ }
visible_width -= 20; // Give it a little more space.
if (is_wrap_enabled()) {
// Center x offset.
int cursor_x = get_column_x_offset_for_line(cursor.column, cursor.line);
- if (cursor_x > (cursor.x_ofs + visible_width))
+ if (cursor_x > (cursor.x_ofs + visible_width)) {
cursor.x_ofs = cursor_x - visible_width + 1;
+ }
- if (cursor_x < cursor.x_ofs)
+ if (cursor_x < cursor.x_ofs) {
cursor.x_ofs = cursor_x;
+ }
} else {
cursor.x_ofs = 0;
}
@@ -4218,15 +4342,17 @@ void TextEdit::update_cursor_wrap_offset() {
bool TextEdit::line_wraps(int line) const {
ERR_FAIL_INDEX_V(line, text.size(), 0);
- if (!is_wrap_enabled())
+ if (!is_wrap_enabled()) {
return false;
+ }
return text.get_line_width(line) > wrap_at;
}
int TextEdit::times_line_wraps(int line) const {
ERR_FAIL_INDEX_V(line, text.size(), 0);
- if (!line_wraps(line))
+ if (!line_wraps(line)) {
return 0;
+ }
int wrap_amount = text.get_line_wrap_amount(line);
if (wrap_amount == -1) {
@@ -4318,8 +4444,9 @@ int TextEdit::get_cursor_wrap_index() const {
int TextEdit::get_line_wrap_index_at_col(int p_line, int p_column) const {
ERR_FAIL_INDEX_V(p_line, text.size(), 0);
- if (!line_wraps(p_line))
+ if (!line_wraps(p_line)) {
return 0;
+ }
// Loop through wraps in the line text until we get to the column.
int wrap_index = 0;
@@ -4329,42 +4456,50 @@ int TextEdit::get_line_wrap_index_at_col(int p_line, int p_column) const {
wrap_index = i;
String s = rows[wrap_index];
col += s.length();
- if (col > p_column)
+ if (col > p_column) {
break;
+ }
}
return wrap_index;
}
void TextEdit::cursor_set_column(int p_col, bool p_adjust_viewport) {
- if (p_col < 0)
+ if (p_col < 0) {
p_col = 0;
+ }
cursor.column = p_col;
- if (cursor.column > get_line(cursor.line).length())
+ if (cursor.column > get_line(cursor.line).length()) {
cursor.column = get_line(cursor.line).length();
+ }
cursor.last_fit_x = get_column_x_offset_for_line(cursor.column, cursor.line);
- if (p_adjust_viewport)
+ if (p_adjust_viewport) {
adjust_viewport_to_cursor();
+ }
if (!cursor_changed_dirty) {
- if (is_inside_tree())
+ if (is_inside_tree()) {
MessageQueue::get_singleton()->push_call(this, "_cursor_changed_emit");
+ }
cursor_changed_dirty = true;
}
}
void TextEdit::cursor_set_line(int p_row, bool p_adjust_viewport, bool p_can_be_hidden, int p_wrap_index) {
- if (setting_row)
+ if (setting_row) {
return;
+ }
setting_row = true;
- if (p_row < 0)
+ if (p_row < 0) {
p_row = 0;
+ }
- if (p_row >= text.size())
+ if (p_row >= text.size()) {
p_row = text.size() - 1;
+ }
if (!p_can_be_hidden) {
if (is_line_hidden(CLAMP(p_row, 0, text.size() - 1))) {
@@ -4390,19 +4525,22 @@ void TextEdit::cursor_set_line(int p_row, bool p_adjust_viewport, bool p_can_be_
for (int i = 0; i < p_wrap_index + 1; i++) {
row_end_col += rows[i].length();
}
- if (n_col >= row_end_col)
+ if (n_col >= row_end_col) {
n_col -= 1;
+ }
}
cursor.column = n_col;
- if (p_adjust_viewport)
+ if (p_adjust_viewport) {
adjust_viewport_to_cursor();
+ }
setting_row = false;
if (!cursor_changed_dirty) {
- if (is_inside_tree())
+ if (is_inside_tree()) {
MessageQueue::get_singleton()->push_call(this, "_cursor_changed_emit");
+ }
cursor_changed_dirty = true;
}
}
@@ -4465,11 +4603,13 @@ void TextEdit::_v_scroll_input() {
}
void TextEdit::_scroll_moved(double p_to_val) {
- if (updating_scrolls)
+ if (updating_scrolls) {
return;
+ }
- if (h_scroll->is_visible_in_tree())
+ if (h_scroll->is_visible_in_tree()) {
cursor.x_ofs = h_scroll->get_value();
+ }
if (v_scroll->is_visible_in_tree()) {
// Set line ofs and wrap ofs.
int v_scroll_i = floor(get_v_scroll());
@@ -4479,8 +4619,9 @@ void TextEdit::_scroll_moved(double p_to_val) {
if (!is_line_hidden(n_line)) {
sc++;
sc += times_line_wraps(n_line);
- if (sc > v_scroll_i)
+ if (sc > v_scroll_i) {
break;
+ }
}
}
n_line = MIN(n_line, text.size() - 1);
@@ -4507,12 +4648,14 @@ int TextEdit::get_char_pos_for_line(int p_px, int p_line, int p_wrap_index) cons
if (wrap_offset_px >= wrap_at) {
wrap_offset_px = 0;
}
- if (p_wrap_index > line_wrap_amount)
+ if (p_wrap_index > line_wrap_amount) {
p_wrap_index = line_wrap_amount;
- if (p_wrap_index > 0)
+ }
+ if (p_wrap_index > 0) {
p_px -= wrap_offset_px;
- else
+ } else {
p_wrap_index = 0;
+ }
Vector<String> rows = get_wrap_rows_text(p_line);
int c_pos = get_char_pos_for(p_px, rows[p_wrap_index]);
for (int i = 0; i < p_wrap_index; i++) {
@@ -4538,8 +4681,9 @@ int TextEdit::get_column_x_offset_for_line(int p_char, int p_line) const {
wrap_index = i;
String s = rows[wrap_index];
col += s.length();
- if (col > p_char)
+ if (col > p_char) {
break;
+ }
n_char -= s.length();
}
int px = get_column_x_offset(n_char, rows[wrap_index]);
@@ -4548,8 +4692,9 @@ int TextEdit::get_column_x_offset_for_line(int p_char, int p_line) const {
if (wrap_offset_px >= wrap_at) {
wrap_offset_px = 0;
}
- if (wrap_index != 0)
+ if (wrap_index != 0) {
px += wrap_offset_px;
+ }
return px;
} else {
@@ -4564,8 +4709,9 @@ int TextEdit::get_char_pos_for(int p_px, String p_str) const {
while (c < p_str.length()) {
int w = text.get_char_width(p_str[c], p_str[c + 1], px);
- if (p_px < (px + w / 2))
+ if (p_px < (px + w / 2)) {
break;
+ }
px += w;
c++;
}
@@ -4577,8 +4723,9 @@ int TextEdit::get_column_x_offset(int p_char, String p_str) const {
int px = 0;
for (int i = 0; i < p_char; i++) {
- if (i >= p_str.length())
+ if (i >= p_str.length()) {
break;
+ }
px += text.get_char_width(p_str[i], p_str[i + 1], px);
}
@@ -4601,8 +4748,9 @@ void TextEdit::insert_text_at_cursor(const String &p_text) {
}
Control::CursorShape TextEdit::get_cursor_shape(const Point2 &p_pos) const {
- if (highlighted_word != String())
+ if (highlighted_word != String()) {
return CURSOR_POINTING_HAND;
+ }
int gutter = cache.style_normal->get_margin(MARGIN_LEFT) + cache.line_number_w + cache.breakpoint_gutter_width + cache.fold_gutter_width + cache.info_gutter_width;
if ((completion_active && completion_rect.has_point(p_pos))) {
@@ -4629,10 +4777,11 @@ Control::CursorShape TextEdit::get_cursor_shape(const Point2 &p_pos) const {
// Fold icon.
if (draw_fold_gutter && p_pos.x > gutter_left + cache.line_number_w - 6 && p_pos.x <= gutter_left + cache.line_number_w + cache.fold_gutter_width - 3) {
- if (is_folded(row) || can_fold(row))
+ if (is_folded(row) || can_fold(row)) {
return CURSOR_POINTING_HAND;
- else
+ } else {
return CURSOR_ARROW;
+ }
}
return CURSOR_ARROW;
@@ -4687,8 +4836,9 @@ String TextEdit::get_text() {
int len = text.size();
for (int i = 0; i < len; i++) {
longthing += text[i];
- if (i != len - 1)
+ if (i != len - 1) {
longthing += "\n";
+ }
}
return longthing;
@@ -4709,8 +4859,9 @@ String TextEdit::get_text_for_lookup_completion() {
longthing += text[i];
}
- if (i != len - 1)
+ if (i != len - 1) {
longthing += "\n";
+ }
}
return longthing;
@@ -4728,16 +4879,18 @@ String TextEdit::get_text_for_completion() {
longthing += text[i];
}
- if (i != len - 1)
+ if (i != len - 1) {
longthing += "\n";
+ }
}
return longthing;
};
String TextEdit::get_line(int line) const {
- if (line < 0 || line >= text.size())
+ if (line < 0 || line >= text.size()) {
return "";
+ }
return text[line];
};
@@ -4761,8 +4914,9 @@ void TextEdit::clear() {
};
void TextEdit::set_readonly(bool p_readonly) {
- if (readonly == p_readonly)
+ if (readonly == p_readonly) {
return;
+ }
readonly = p_readonly;
_generate_context_menu();
@@ -5094,11 +5248,13 @@ void TextEdit::paste() {
}
void TextEdit::select_all() {
- if (!selecting_enabled)
+ if (!selecting_enabled) {
return;
+ }
- if (text.size() == 1 && text[0].length() == 0)
+ if (text.size() == 1 && text[0].length() == 0) {
return;
+ }
selection.active = true;
selection.from_line = 0;
selection.from_column = 0;
@@ -5119,26 +5275,33 @@ void TextEdit::deselect() {
}
void TextEdit::select(int p_from_line, int p_from_column, int p_to_line, int p_to_column) {
- if (!selecting_enabled)
+ if (!selecting_enabled) {
return;
+ }
- if (p_from_line < 0)
+ if (p_from_line < 0) {
p_from_line = 0;
- else if (p_from_line >= text.size())
+ } else if (p_from_line >= text.size()) {
p_from_line = text.size() - 1;
- if (p_from_column >= text[p_from_line].length())
+ }
+ if (p_from_column >= text[p_from_line].length()) {
p_from_column = text[p_from_line].length();
- if (p_from_column < 0)
+ }
+ if (p_from_column < 0) {
p_from_column = 0;
+ }
- if (p_to_line < 0)
+ if (p_to_line < 0) {
p_to_line = 0;
- else if (p_to_line >= text.size())
+ } else if (p_to_line >= text.size()) {
p_to_line = text.size() - 1;
- if (p_to_column >= text[p_to_line].length())
+ }
+ if (p_to_column >= text[p_to_line].length()) {
p_to_column = text[p_to_line].length();
- if (p_to_column < 0)
+ }
+ if (p_to_column < 0) {
p_to_column = 0;
+ }
selection.from_line = p_from_line;
selection.from_column = p_from_column;
@@ -5200,8 +5363,9 @@ int TextEdit::get_selection_to_column() const {
}
String TextEdit::get_selection_text() const {
- if (!selection.active)
+ if (!selection.active) {
return "";
+ }
return _base_get_text(selection.from_line, selection.from_column, selection.to_line, selection.to_column);
}
@@ -5210,20 +5374,23 @@ String TextEdit::get_word_under_cursor() const {
int prev_cc = cursor.column;
while (prev_cc > 0) {
bool is_char = _is_text_char(text[cursor.line][prev_cc - 1]);
- if (!is_char)
+ if (!is_char) {
break;
+ }
--prev_cc;
}
int next_cc = cursor.column;
while (next_cc < text[cursor.line].length()) {
bool is_char = _is_text_char(text[cursor.line][next_cc]);
- if (!is_char)
+ if (!is_char) {
break;
+ }
++next_cc;
}
- if (prev_cc == cursor.column || next_cc == cursor.column)
+ if (prev_cc == cursor.column || next_cc == cursor.column) {
return "";
+ }
return text[cursor.line].substr(prev_cc, next_cc - prev_cc);
}
@@ -5297,8 +5464,9 @@ Vector<int> TextEdit::_search_bind(const String &p_key, uint32_t p_search_flags,
}
bool TextEdit::search(const String &p_key, uint32_t p_search_flags, int p_from_line, int p_from_column, int &r_line, int &r_column) const {
- if (p_key.length() == 0)
+ if (p_key.length() == 0) {
return false;
+ }
ERR_FAIL_INDEX_V(p_from_line, text.size(), false);
ERR_FAIL_INDEX_V(p_from_column, text[p_from_line].length() + 1, false);
@@ -5332,10 +5500,11 @@ bool TextEdit::search(const String &p_key, uint32_t p_search_flags, int p_from_l
}
} else {
- if (p_search_flags & SEARCH_BACKWARDS)
+ if (p_search_flags & SEARCH_BACKWARDS) {
from_column = text_line.length() - 1;
- else
+ } else {
from_column = 0;
+ }
}
pos = -1;
@@ -5369,10 +5538,11 @@ bool TextEdit::search(const String &p_key, uint32_t p_search_flags, int p_from_l
if (pos != -1 && (p_search_flags & SEARCH_WHOLE_WORDS)) {
// Validate for whole words.
- if (pos > 0 && _is_text_char(text_line[pos - 1]))
+ if (pos > 0 && _is_text_char(text_line[pos - 1])) {
is_match = false;
- else if (pos + p_key.length() < text_line.length() && _is_text_char(text_line[pos + p_key.length()]))
+ } else if (pos + p_key.length() < text_line.length() && _is_text_char(text_line[pos + p_key.length()])) {
is_match = false;
+ }
}
if (pos_from == -1) {
@@ -5387,13 +5557,15 @@ bool TextEdit::search(const String &p_key, uint32_t p_search_flags, int p_from_l
pos = -1;
}
- if (pos != -1)
+ if (pos != -1) {
break;
+ }
- if (p_search_flags & SEARCH_BACKWARDS)
+ if (p_search_flags & SEARCH_BACKWARDS) {
line--;
- else
+ } else {
line++;
+ }
}
if (pos == -1) {
@@ -5459,16 +5631,18 @@ void TextEdit::set_line_as_bookmark(int p_line, bool p_bookmark) {
void TextEdit::get_bookmarks(List<int> *p_bookmarks) const {
for (int i = 0; i < text.size(); i++) {
- if (text.is_bookmark(i))
+ if (text.is_bookmark(i)) {
p_bookmarks->push_back(i);
+ }
}
}
Array TextEdit::get_bookmarks_array() const {
Array arr;
for (int i = 0; i < text.size(); i++) {
- if (text.is_bookmark(i))
+ if (text.is_bookmark(i)) {
arr.append(i);
+ }
}
return arr;
}
@@ -5486,25 +5660,28 @@ void TextEdit::set_line_as_breakpoint(int p_line, bool p_breakpoint) {
void TextEdit::get_breakpoints(List<int> *p_breakpoints) const {
for (int i = 0; i < text.size(); i++) {
- if (text.is_breakpoint(i))
+ if (text.is_breakpoint(i)) {
p_breakpoints->push_back(i);
+ }
}
}
Array TextEdit::get_breakpoints_array() const {
Array arr;
for (int i = 0; i < text.size(); i++) {
- if (text.is_breakpoint(i))
+ if (text.is_breakpoint(i)) {
arr.append(i);
+ }
}
return arr;
}
void TextEdit::remove_breakpoints() {
for (int i = 0; i < text.size(); i++) {
- if (text.is_breakpoint(i))
+ if (text.is_breakpoint(i)) {
/* Should "breakpoint_toggled" be fired when breakpoints are removed this way? */
text.set_breakpoint(i, false);
+ }
}
}
@@ -5521,8 +5698,9 @@ void TextEdit::clear_info_icons() {
void TextEdit::set_line_as_hidden(int p_line, bool p_hidden) {
ERR_FAIL_INDEX(p_line, text.size());
- if (is_hiding_enabled() || !p_hidden)
+ if (is_hiding_enabled() || !p_hidden) {
text.set_hidden(p_line, p_hidden);
+ }
update();
}
@@ -5551,8 +5729,9 @@ int TextEdit::num_lines_from(int p_line_from, int visible_amount) const {
// Returns the number of lines (hidden and unhidden) from p_line_from to (p_line_from + visible_amount of unhidden lines).
ERR_FAIL_INDEX_V(p_line_from, text.size(), ABS(visible_amount));
- if (!is_hiding_enabled())
+ if (!is_hiding_enabled()) {
return ABS(visible_amount);
+ }
int num_visible = 0;
int num_total = 0;
@@ -5562,8 +5741,9 @@ int TextEdit::num_lines_from(int p_line_from, int visible_amount) const {
if (!is_line_hidden(i)) {
num_visible++;
}
- if (num_visible >= visible_amount)
+ if (num_visible >= visible_amount) {
break;
+ }
}
} else {
visible_amount = ABS(visible_amount);
@@ -5572,8 +5752,9 @@ int TextEdit::num_lines_from(int p_line_from, int visible_amount) const {
if (!is_line_hidden(i)) {
num_visible++;
}
- if (num_visible >= visible_amount)
+ if (num_visible >= visible_amount) {
break;
+ }
}
}
return num_total;
@@ -5585,8 +5766,9 @@ int TextEdit::num_lines_from_rows(int p_line_from, int p_wrap_index_from, int vi
wrap_index = 0;
ERR_FAIL_INDEX_V(p_line_from, text.size(), ABS(visible_amount));
- if (!is_hiding_enabled() && !is_wrap_enabled())
+ if (!is_hiding_enabled() && !is_wrap_enabled()) {
return ABS(visible_amount);
+ }
int num_visible = 0;
int num_total = 0;
@@ -5602,8 +5784,9 @@ int TextEdit::num_lines_from_rows(int p_line_from, int p_wrap_index_from, int vi
num_visible++;
num_visible += times_line_wraps(i);
}
- if (num_visible >= visible_amount)
+ if (num_visible >= visible_amount) {
break;
+ }
}
wrap_index = times_line_wraps(MIN(i, text.size() - 1)) - (num_visible - visible_amount);
} else {
@@ -5616,8 +5799,9 @@ int TextEdit::num_lines_from_rows(int p_line_from, int p_wrap_index_from, int vi
num_visible++;
num_visible += times_line_wraps(i);
}
- if (num_visible >= visible_amount)
+ if (num_visible >= visible_amount) {
break;
+ }
}
wrap_index = (num_visible - visible_amount);
}
@@ -5627,8 +5811,9 @@ int TextEdit::num_lines_from_rows(int p_line_from, int p_wrap_index_from, int vi
int TextEdit::get_last_unhidden_line() const {
// Returns the last line in the text that is not hidden.
- if (!is_hiding_enabled())
+ if (!is_hiding_enabled()) {
return text.size() - 1;
+ }
int last_line;
for (last_line = text.size() - 1; last_line > 0; last_line--) {
@@ -5680,24 +5865,31 @@ bool TextEdit::is_line_comment(int p_line) const {
bool TextEdit::can_fold(int p_line) const {
ERR_FAIL_INDEX_V(p_line, text.size(), false);
- if (!is_hiding_enabled())
+ if (!is_hiding_enabled()) {
return false;
- if (p_line + 1 >= text.size())
+ }
+ if (p_line + 1 >= text.size()) {
return false;
- if (text[p_line].strip_edges().size() == 0)
+ }
+ if (text[p_line].strip_edges().size() == 0) {
return false;
- if (is_folded(p_line))
+ }
+ if (is_folded(p_line)) {
return false;
- if (is_line_hidden(p_line))
+ }
+ if (is_line_hidden(p_line)) {
return false;
- if (is_line_comment(p_line))
+ }
+ if (is_line_comment(p_line)) {
return false;
+ }
int start_indent = get_indent_level(p_line);
for (int i = p_line + 1; i < text.size(); i++) {
- if (text[i].strip_edges().size() == 0)
+ if (text[i].strip_edges().size() == 0) {
continue;
+ }
int next_indent = get_indent_level(i);
if (is_line_comment(i)) {
continue;
@@ -5713,8 +5905,9 @@ bool TextEdit::can_fold(int p_line) const {
bool TextEdit::is_folded(int p_line) const {
ERR_FAIL_INDEX_V(p_line, text.size(), false);
- if (p_line + 1 >= text.size())
+ if (p_line + 1 >= text.size()) {
return false;
+ }
return !is_line_hidden(p_line) && is_line_hidden(p_line + 1);
}
@@ -5731,10 +5924,12 @@ Vector<int> TextEdit::get_folded_lines() const {
void TextEdit::fold_line(int p_line) {
ERR_FAIL_INDEX(p_line, text.size());
- if (!is_hiding_enabled())
+ if (!is_hiding_enabled()) {
return;
- if (!can_fold(p_line))
+ }
+ if (!can_fold(p_line)) {
return;
+ }
// Hide lines below this one.
int start_indent = get_indent_level(p_line);
@@ -5777,12 +5972,14 @@ void TextEdit::fold_line(int p_line) {
void TextEdit::unfold_line(int p_line) {
ERR_FAIL_INDEX(p_line, text.size());
- if (!is_folded(p_line) && !is_line_hidden(p_line))
+ if (!is_folded(p_line) && !is_line_hidden(p_line)) {
return;
+ }
int fold_start;
for (fold_start = p_line; fold_start > 0; fold_start--) {
- if (is_folded(fold_start))
+ if (is_folded(fold_start)) {
break;
+ }
}
fold_start = is_folded(fold_start) ? fold_start : p_line;
@@ -5800,10 +5997,11 @@ void TextEdit::unfold_line(int p_line) {
void TextEdit::toggle_fold_line(int p_line) {
ERR_FAIL_INDEX(p_line, text.size());
- if (!is_folded(p_line))
+ if (!is_folded(p_line)) {
fold_line(p_line);
- else
+ } else {
unfold_line(p_line);
+ }
}
int TextEdit::get_line_count() const {
@@ -5814,8 +6012,9 @@ void TextEdit::_do_text_op(const TextOperation &p_op, bool p_reverse) {
ERR_FAIL_COND(p_op.type == TextOperation::TYPE_NONE);
bool insert = p_op.type == TextOperation::TYPE_INSERT;
- if (p_reverse)
+ if (p_reverse) {
insert = !insert;
+ }
if (insert) {
int check_line;
@@ -5829,8 +6028,9 @@ void TextEdit::_do_text_op(const TextOperation &p_op, bool p_reverse) {
}
void TextEdit::_clear_redo() {
- if (undo_stack_pos == nullptr)
+ if (undo_stack_pos == nullptr) {
return; // Nothing to clear.
+ }
_push_current_op();
@@ -5845,22 +6045,25 @@ void TextEdit::undo() {
_push_current_op();
if (undo_stack_pos == nullptr) {
- if (!undo_stack.size())
+ if (!undo_stack.size()) {
return; // Nothing to undo.
+ }
undo_stack_pos = undo_stack.back();
- } else if (undo_stack_pos == undo_stack.front())
+ } else if (undo_stack_pos == undo_stack.front()) {
return; // At the bottom of the undo stack.
- else
+ } else {
undo_stack_pos = undo_stack_pos->prev();
+ }
deselect();
TextOperation op = undo_stack_pos->get();
_do_text_op(op, true);
- if (op.type != TextOperation::TYPE_INSERT && (op.from_line != op.to_line || op.to_column != op.from_column + 1))
+ if (op.type != TextOperation::TYPE_INSERT && (op.from_line != op.to_line || op.to_column != op.from_column + 1)) {
select(op.from_line, op.from_column, op.to_line, op.to_column);
+ }
current_op.version = op.prev_version;
if (undo_stack_pos->get().chain_backward) {
@@ -5891,8 +6094,9 @@ void TextEdit::undo() {
void TextEdit::redo() {
_push_current_op();
- if (undo_stack_pos == nullptr)
+ if (undo_stack_pos == nullptr) {
return; // Nothing to do.
+ }
deselect();
@@ -5906,8 +6110,9 @@ void TextEdit::redo() {
op = undo_stack_pos->get();
_do_text_op(op, false);
current_op.version = op.version;
- if (undo_stack_pos->get().chain_backward)
+ if (undo_stack_pos->get().chain_backward) {
break;
+ }
}
}
@@ -5943,8 +6148,9 @@ void TextEdit::end_complex_operation() {
}
void TextEdit::_push_current_op() {
- if (current_op.type == TextOperation::TYPE_NONE)
+ if (current_op.type == TextOperation::TYPE_NONE) {
return; // Nothing to do.
+ }
if (next_operation_is_complex) {
current_op.chain_forward = true;
@@ -6037,8 +6243,9 @@ void TextEdit::tag_saved_version() {
}
double TextEdit::get_scroll_pos_for_line(int p_line, int p_wrap_index) const {
- if (!is_wrap_enabled() && !is_hiding_enabled())
+ if (!is_wrap_enabled() && !is_hiding_enabled()) {
return p_line;
+ }
// Count the number of visible lines up to this line.
double new_line_scroll_pos = 0;
@@ -6112,8 +6319,9 @@ double TextEdit::get_v_scroll() const {
void TextEdit::set_v_scroll(double p_scroll) {
v_scroll->set_value(p_scroll);
int max_v_scroll = v_scroll->get_max() - v_scroll->get_page();
- if (p_scroll >= max_v_scroll - 1.0)
+ if (p_scroll >= max_v_scroll - 1.0) {
_scroll_moved(v_scroll->get_value());
+ }
}
int TextEdit::get_h_scroll() const {
@@ -6147,8 +6355,9 @@ float TextEdit::get_v_scroll_speed() const {
void TextEdit::set_completion(bool p_enabled, const Vector<String> &p_prefixes) {
completion_prefixes.clear();
completion_enabled = p_enabled;
- for (int i = 0; i < p_prefixes.size(); i++)
+ for (int i = 0; i < p_prefixes.size(); i++) {
completion_prefixes.insert(p_prefixes[i]);
+ }
}
void TextEdit::_confirm_completion() {
@@ -6197,8 +6406,9 @@ void TextEdit::_cancel_code_hint() {
}
void TextEdit::_cancel_completion() {
- if (!completion_active)
+ if (!completion_active) {
return;
+ }
completion_active = false;
completion_forced = false;
@@ -6225,8 +6435,9 @@ void TextEdit::_update_completion_candidates() {
while (c >= 0) {
if (l[c] == '"' || l[c] == '\'') {
inquote = !inquote;
- if (first_quote == -1)
+ if (first_quote == -1) {
first_quote = c;
+ }
restore_quotes = 0;
} else if (restore_quotes == 0 && l[c] == '$') {
restore_quotes = 1;
@@ -6247,8 +6458,9 @@ void TextEdit::_update_completion_candidates() {
} else if (cofs > 0 && l[cofs - 1] == ' ') {
int kofs = cofs - 1;
String kw;
- while (kofs >= 0 && l[kofs] == ' ')
+ while (kofs >= 0 && l[kofs] == ' ') {
kofs--;
+ }
while (kofs >= 0 && l[kofs] > 32 && _is_completable(l[kofs])) {
kw = String::chr(l[kofs]) + kw;
@@ -6260,8 +6472,9 @@ void TextEdit::_update_completion_candidates() {
} else {
while (cofs > 0 && l[cofs - 1] > 32 && (l[cofs - 1] == '/' || _is_completable(l[cofs - 1]))) {
s = String::chr(l[cofs - 1]) + s;
- if (l[cofs - 1] == '\'' || l[cofs - 1] == '"' || l[cofs - 1] == '$')
+ if (l[cofs - 1] == '\'' || l[cofs - 1] == '"' || l[cofs - 1] == '$') {
break;
+ }
cofs--;
}
@@ -6274,11 +6487,13 @@ void TextEdit::_update_completion_candidates() {
update();
bool prev_is_prefix = false;
- if (cofs > 0 && completion_prefixes.has(String::chr(l[cofs - 1])))
+ if (cofs > 0 && completion_prefixes.has(String::chr(l[cofs - 1]))) {
prev_is_prefix = true;
+ }
// Check with one space before prefix, to allow indent.
- if (cofs > 1 && l[cofs - 1] == ' ' && completion_prefixes.has(String::chr(l[cofs - 2])))
+ if (cofs > 1 && l[cofs - 1] == ' ' && completion_prefixes.has(String::chr(l[cofs - 2]))) {
prev_is_prefix = true;
+ }
if (cancel || (!pre_keyword && s == "" && (cofs == 0 || !prev_is_prefix))) {
// None to complete, cancel.
@@ -6396,8 +6611,9 @@ void TextEdit::query_code_comple() {
int c = ofs - 1;
while (c >= 0) {
- if (l[c] == '"' || l[c] == '\'')
+ if (l[c] == '"' || l[c] == '\'') {
inquote = !inquote;
+ }
c--;
}
@@ -6420,10 +6636,11 @@ void TextEdit::query_code_comple() {
}
if (!ignored) {
- if (ofs > 0 && (inquote || _is_completable(l[ofs - 1]) || completion_prefixes.has(String::chr(l[ofs - 1]))))
+ if (ofs > 0 && (inquote || _is_completable(l[ofs - 1]) || completion_prefixes.has(String::chr(l[ofs - 1])))) {
emit_signal("request_completion");
- else if (ofs > 1 && l[ofs - 1] == ' ' && completion_prefixes.has(String::chr(l[ofs - 2]))) // Make it work with a space too, it's good enough.
+ } else if (ofs > 1 && l[ofs - 1] == ' ' && completion_prefixes.has(String::chr(l[ofs - 2]))) { // Make it work with a space too, it's good enough.
emit_signal("request_completion");
+ }
}
}
@@ -6447,8 +6664,9 @@ String TextEdit::get_word_at_pos(const Vector2 &p_pos) const {
_get_mouse_pos(p_pos, row, col);
String s = text[row];
- if (s.length() == 0)
+ if (s.length() == 0) {
return "";
+ }
int beg, end;
if (select_word(s, col, beg, end)) {
bool inside_quotes = false;
@@ -6480,14 +6698,16 @@ String TextEdit::get_word_at_pos(const Vector2 &p_pos) const {
}
String TextEdit::get_tooltip(const Point2 &p_pos) const {
- if (!tooltip_obj)
+ if (!tooltip_obj) {
return Control::get_tooltip(p_pos);
+ }
int row, col;
_get_mouse_pos(p_pos, row, col);
String s = text[row];
- if (s.length() == 0)
+ if (s.length() == 0) {
return Control::get_tooltip(p_pos);
+ }
int beg, end;
if (select_word(s, col, beg, end)) {
String tt = tooltip_obj->call(tooltip_func, s.substr(beg, end - beg), tooltip_ud);
@@ -6505,8 +6725,9 @@ void TextEdit::set_tooltip_request_func(Object *p_obj, const StringName &p_funct
}
void TextEdit::set_line(int line, String new_text) {
- if (line < 0 || line > text.size())
+ if (line < 0 || line > text.size()) {
return;
+ }
_remove_text(line, 0, line, text[line].length());
_insert_text(line, 0, new_text);
if (cursor.line == line) {
@@ -6646,8 +6867,9 @@ int TextEdit::get_minimap_width() const {
}
void TextEdit::set_hiding_enabled(bool p_enabled) {
- if (!p_enabled)
+ if (!p_enabled) {
unhide_all_lines();
+ }
hiding_enabled = p_enabled;
update();
}
@@ -6731,8 +6953,9 @@ void TextEdit::set_shortcut_keys_enabled(bool p_enabled) {
void TextEdit::set_selecting_enabled(bool p_enabled) {
selecting_enabled = p_enabled;
- if (!selecting_enabled)
+ if (!selecting_enabled) {
deselect();
+ }
_generate_context_menu();
}
@@ -7185,8 +7408,9 @@ Map<int, TextEdit::HighlighterInfo> TextEdit::_get_line_syntax_highlighting(int
if (in_region == -1 && !in_keyword && is_char && !prev_is_char) {
int to = j;
- while (to < str.length() && _is_text_char(str[to]))
+ while (to < str.length() && _is_text_char(str[to])) {
to++;
+ }
uint32_t hash = String::hash(&str[j], to - j);
StrRange range(&str[j], to - j);
@@ -7246,18 +7470,19 @@ Map<int, TextEdit::HighlighterInfo> TextEdit::_get_line_syntax_highlighting(int
in_member_variable = false;
}
- if (in_region >= 0)
+ if (in_region >= 0) {
color = color_regions[in_region].color;
- else if (in_keyword)
+ } else if (in_keyword) {
color = keyword_color;
- else if (in_member_variable)
+ } else if (in_member_variable) {
color = cache.member_variable_color;
- else if (in_function_name)
+ } else if (in_function_name) {
color = cache.function_color;
- else if (is_symbol)
+ } else if (is_symbol) {
color = cache.symbol_color;
- else if (is_number)
+ } else if (is_number) {
color = cache.number_color;
+ }
prev_is_char = is_char;
prev_is_number = is_number;
diff --git a/scene/gui/texture_button.cpp b/scene/gui/texture_button.cpp
index 0cc0e50a00..6e86f0f299 100644
--- a/scene/gui/texture_button.cpp
+++ b/scene/gui/texture_button.cpp
@@ -38,18 +38,22 @@ Size2 TextureButton::get_minimum_size() const {
if (!expand) {
if (normal.is_null()) {
if (pressed.is_null()) {
- if (hover.is_null())
- if (click_mask.is_null())
+ if (hover.is_null()) {
+ if (click_mask.is_null()) {
rscale = Size2();
- else
+ } else {
rscale = click_mask->get_size();
- else
+ }
+ } else {
rscale = hover->get_size();
- } else
+ }
+ } else {
rscale = pressed->get_size();
+ }
- } else
+ } else {
rscale = normal->get_size();
+ }
}
return rscale.abs();
@@ -121,36 +125,44 @@ void TextureButton::_notification(int p_what) {
switch (draw_mode) {
case DRAW_NORMAL: {
- if (normal.is_valid())
+ if (normal.is_valid()) {
texdraw = normal;
+ }
} break;
case DRAW_HOVER_PRESSED:
case DRAW_PRESSED: {
if (pressed.is_null()) {
if (hover.is_null()) {
- if (normal.is_valid())
+ if (normal.is_valid()) {
texdraw = normal;
- } else
+ }
+ } else {
texdraw = hover;
+ }
- } else
+ } else {
texdraw = pressed;
+ }
} break;
case DRAW_HOVER: {
if (hover.is_null()) {
- if (pressed.is_valid() && is_pressed())
+ if (pressed.is_valid() && is_pressed()) {
texdraw = pressed;
- else if (normal.is_valid())
+ } else if (normal.is_valid()) {
texdraw = normal;
- } else
+ }
+ } else {
texdraw = hover;
+ }
} break;
case DRAW_DISABLED: {
if (disabled.is_null()) {
- if (normal.is_valid())
+ if (normal.is_valid()) {
texdraw = normal;
- } else
+ }
+ } else {
texdraw = disabled;
+ }
} break;
}
diff --git a/scene/gui/texture_progress.cpp b/scene/gui/texture_progress.cpp
index 5edb10958c..484b14d11c 100644
--- a/scene/gui/texture_progress.cpp
+++ b/scene/gui/texture_progress.cpp
@@ -77,14 +77,15 @@ bool TextureProgress::get_nine_patch_stretch() const {
}
Size2 TextureProgress::get_minimum_size() const {
- if (nine_patch_stretch)
+ if (nine_patch_stretch) {
return Size2(stretch_margin[MARGIN_LEFT] + stretch_margin[MARGIN_RIGHT], stretch_margin[MARGIN_TOP] + stretch_margin[MARGIN_BOTTOM]);
- else if (under.is_valid())
+ } else if (under.is_valid()) {
return under->get_size();
- else if (over.is_valid())
+ } else if (over.is_valid()) {
return over->get_size();
- else if (progress.is_valid())
+ } else if (progress.is_valid()) {
return progress->get_size();
+ }
return Size2(1, 1);
}
@@ -127,13 +128,16 @@ Color TextureProgress::get_tint_over() const {
}
Point2 TextureProgress::unit_val_to_uv(float val) {
- if (progress.is_null())
+ if (progress.is_null()) {
return Point2();
+ }
- if (val < 0)
+ if (val < 0) {
val += 1;
- if (val > 1)
+ }
+ if (val > 1) {
val -= 1;
+ }
Point2 p = get_relative_center();
@@ -151,40 +155,46 @@ Point2 TextureProgress::unit_val_to_uv(float val) {
for (int edge = 0; edge < 4; edge++) {
if (edge == 0) {
- if (dir.x > 0)
+ if (dir.x > 0) {
continue;
+ }
cq = -(edgeLeft - p.x);
dir.x *= 2.0 * cq;
cp = -dir.x;
} else if (edge == 1) {
- if (dir.x < 0)
+ if (dir.x < 0) {
continue;
+ }
cq = (edgeRight - p.x);
dir.x *= 2.0 * cq;
cp = dir.x;
} else if (edge == 2) {
- if (dir.y > 0)
+ if (dir.y > 0) {
continue;
+ }
cq = -(edgeBottom - p.y);
dir.y *= 2.0 * cq;
cp = -dir.y;
} else if (edge == 3) {
- if (dir.y < 0)
+ if (dir.y < 0) {
continue;
+ }
cq = (edgeTop - p.y);
dir.y *= 2.0 * cq;
cp = dir.y;
}
cr = cq / cp;
- if (cr >= 0 && cr < t1)
+ if (cr >= 0 && cr < t1) {
t1 = cr;
+ }
}
return (p + t1 * dir);
}
Point2 TextureProgress::get_relative_center() {
- if (progress.is_null())
+ if (progress.is_null()) {
return Point2();
+ }
Point2 p = progress->get_size() / 2;
p += rad_center_off;
p.x /= progress->get_width();
@@ -311,8 +321,9 @@ void TextureProgress::_notification(int p_what) {
draw_nine_patch_stretched(over, FILL_LEFT_TO_RIGHT, 1.0, tint_over);
}
} else {
- if (under.is_valid())
+ if (under.is_valid()) {
draw_texture(under, Point2(), tint_under);
+ }
if (progress.is_valid()) {
Size2 s = progress->get_size();
switch (mode) {
@@ -335,8 +346,9 @@ void TextureProgress::_notification(int p_what) {
case FILL_CLOCKWISE:
case FILL_COUNTER_CLOCKWISE:
case FILL_CLOCKWISE_AND_COUNTER_CLOCKWISE: {
- if (nine_patch_stretch)
+ if (nine_patch_stretch) {
s = get_size();
+ }
float val = get_as_ratio() * rad_max_degrees / 360;
if (val == 1) {
@@ -358,9 +370,11 @@ void TextureProgress::_notification(int p_what) {
pts.append(end);
float from = MIN(start, end);
float to = MAX(start, end);
- for (int i = 0; i < 12; i++)
- if (corners[i] > from && corners[i] < to)
+ for (int i = 0; i < 12; i++) {
+ if (corners[i] > from && corners[i] < to) {
pts.append(corners[i]);
+ }
+ }
pts.sort();
Vector<Point2> uvs;
Vector<Point2> points;
@@ -368,8 +382,9 @@ void TextureProgress::_notification(int p_what) {
points.push_back(Point2(s.x * get_relative_center().x, s.y * get_relative_center().y));
for (int i = 0; i < pts.size(); i++) {
Point2 uv = unit_val_to_uv(pts[i]);
- if (uvs.find(uv) >= 0)
+ if (uvs.find(uv) >= 0) {
continue;
+ }
uvs.push_back(uv);
points.push_back(Point2(uv.x * s.x, uv.y * s.y));
}
@@ -380,10 +395,11 @@ void TextureProgress::_notification(int p_what) {
if (Engine::get_singleton()->is_editor_hint()) {
Point2 p;
- if (nine_patch_stretch)
+ if (nine_patch_stretch) {
p = get_size();
- else
+ } else {
p = progress->get_size();
+ }
p.x *= get_relative_center().x;
p.y *= get_relative_center().y;
@@ -404,10 +420,10 @@ void TextureProgress::_notification(int p_what) {
draw_texture_rect_region(progress, Rect2(Point2(), Size2(s.x * get_as_ratio(), s.y)), Rect2(Point2(), Size2(s.x * get_as_ratio(), s.y)), tint_progress);
}
}
- if (over.is_valid())
+ if (over.is_valid()) {
draw_texture(over, Point2(), tint_over);
+ }
}
-
} break;
}
}
@@ -423,10 +439,12 @@ int TextureProgress::get_fill_mode() {
}
void TextureProgress::set_radial_initial_angle(float p_angle) {
- while (p_angle > 360)
+ while (p_angle > 360) {
p_angle -= 360;
- while (p_angle < 0)
+ }
+ while (p_angle < 0) {
p_angle += 360;
+ }
rad_init_angle = p_angle;
update();
}
diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp
index df4420ca8c..45fcb448f8 100644
--- a/scene/gui/tree.cpp
+++ b/scene/gui/tree.cpp
@@ -47,8 +47,9 @@
#include <limits.h>
void TreeItem::move_to_top() {
- if (!parent || parent->children == this)
+ if (!parent || parent->children == this) {
return; //already on top
+ }
TreeItem *prev = get_prev();
prev->next = next;
next = parent->children;
@@ -56,13 +57,15 @@ void TreeItem::move_to_top() {
}
void TreeItem::move_to_bottom() {
- if (!parent || !next)
+ if (!parent || !next) {
return;
+ }
TreeItem *prev = get_prev();
TreeItem *last = next;
- while (last->next)
+ while (last->next) {
last = last->next;
+ }
if (prev) {
prev->next = next;
@@ -74,17 +77,20 @@ void TreeItem::move_to_bottom() {
}
Size2 TreeItem::Cell::get_icon_size() const {
- if (icon.is_null())
+ if (icon.is_null()) {
return Size2();
- if (icon_region == Rect2i())
+ }
+ if (icon_region == Rect2i()) {
return icon->get_size();
- else
+ } else {
return icon_region.size;
+ }
}
void TreeItem::Cell::draw_icon(const RID &p_where, const Point2 &p_pos, const Size2 &p_size, const Color &p_color) const {
- if (icon.is_null())
+ if (icon.is_null()) {
return;
+ }
Size2i dsize = (p_size == Size2()) ? icon->get_size() : p_size;
@@ -229,12 +235,15 @@ int TreeItem::get_icon_max_width(int p_column) const {
/* range works for mode number or mode combo */
void TreeItem::set_range(int p_column, double p_value) {
ERR_FAIL_INDEX(p_column, cells.size());
- if (cells[p_column].step > 0)
+ if (cells[p_column].step > 0) {
p_value = Math::stepify(p_value, cells[p_column].step);
- if (p_value < cells[p_column].min)
+ }
+ if (p_value < cells[p_column].min) {
p_value = cells[p_column].min;
- if (p_value > cells[p_column].max)
+ }
+ if (p_value > cells[p_column].max) {
p_value = cells[p_column].max;
+ }
cells.write[p_column].val = p_value;
_changed_notify(p_column);
@@ -286,8 +295,9 @@ void TreeItem::set_custom_draw(int p_column, Object *p_object, const StringName
}
void TreeItem::set_collapsed(bool p_collapsed) {
- if (collapsed == p_collapsed || !tree)
+ if (collapsed == p_collapsed || !tree) {
return;
+ }
collapsed = p_collapsed;
TreeItem *ci = tree->selected_item;
if (ci) {
@@ -329,12 +339,14 @@ TreeItem *TreeItem::get_next() {
}
TreeItem *TreeItem::get_prev() {
- if (!parent || parent->children == this)
+ if (!parent || parent->children == this) {
return nullptr;
+ }
TreeItem *prev = parent->children;
- while (prev && prev->next != this)
+ while (prev && prev->next != this) {
prev = prev->next;
+ }
return prev;
}
@@ -374,8 +386,9 @@ TreeItem *TreeItem::get_prev_visible(bool p_wrap) {
//go to the very end
current = current->children;
- while (current->next)
+ while (current->next) {
current = current->next;
+ }
}
}
@@ -396,10 +409,11 @@ TreeItem *TreeItem::get_next_visible(bool p_wrap) {
}
if (!current) {
- if (p_wrap)
+ if (p_wrap) {
return tree->root;
- else
+ } else {
return nullptr;
+ }
} else {
current = current->next;
}
@@ -445,10 +459,12 @@ bool TreeItem::is_selected(int p_column) {
void TreeItem::set_as_cursor(int p_column) {
ERR_FAIL_INDEX(p_column, cells.size());
- if (!tree)
+ if (!tree) {
return;
- if (tree->select_mode != Tree::SELECT_MULTI)
+ }
+ if (tree->select_mode != Tree::SELECT_MULTI) {
return;
+ }
tree->selected_item = this;
tree->selected_col = p_column;
tree->update();
@@ -469,8 +485,9 @@ void TreeItem::add_button(int p_column, const Ref<Texture2D> &p_button, int p_id
ERR_FAIL_COND(!p_button.is_valid());
TreeItem::Cell::Button button;
button.texture = p_button;
- if (p_id < 0)
+ if (p_id < 0) {
p_id = cells[p_column].buttons.size();
+ }
button.id = p_id;
button.disabled = p_disabled;
button.tooltip = p_tooltip;
@@ -511,8 +528,9 @@ void TreeItem::erase_button(int p_column, int p_idx) {
int TreeItem::get_button_by_id(int p_column, int p_id) const {
ERR_FAIL_INDEX_V(p_column, cells.size(), -1);
for (int i = 0; i < cells[p_column].buttons.size(); i++) {
- if (cells[p_column].buttons[i].id == p_id)
+ if (cells[p_column].buttons[i].id == p_id) {
return i;
+ }
}
return -1;
@@ -568,8 +586,9 @@ void TreeItem::set_custom_color(int p_column, const Color &p_color) {
Color TreeItem::get_custom_color(int p_column) const {
ERR_FAIL_INDEX_V(p_column, cells.size(), Color());
- if (!cells[p_column].custom_color)
+ if (!cells[p_column].custom_color) {
return Color();
+ }
return cells[p_column].color;
}
@@ -607,8 +626,9 @@ void TreeItem::clear_custom_bg_color(int p_column) {
Color TreeItem::get_custom_bg_color(int p_column) const {
ERR_FAIL_INDEX_V(p_column, cells.size(), Color());
- if (!cells[p_column].custom_bg_color)
+ if (!cells[p_column].custom_bg_color) {
return Color();
+ }
return cells[p_column].bg_color;
}
@@ -832,8 +852,9 @@ TreeItem::TreeItem(Tree *p_tree) {
TreeItem::~TreeItem() {
clear_children();
- if (parent)
+ if (parent) {
parent->remove_child(this);
+ }
if (tree && tree->root == this) {
tree->root = nullptr;
@@ -848,14 +869,17 @@ TreeItem::~TreeItem() {
tree->cache.hover_item = nullptr;
}
- if (tree && tree->selected_item == this)
+ if (tree && tree->selected_item == this) {
tree->selected_item = nullptr;
+ }
- if (tree && tree->drop_mode_over == this)
+ if (tree && tree->drop_mode_over == this) {
tree->drop_mode_over = nullptr;
+ }
- if (tree && tree->single_select_defer == this)
+ if (tree && tree->single_select_defer == this) {
tree->single_select_defer = nullptr;
+ }
if (tree && tree->edited_item == this) {
tree->edited_item = nullptr;
@@ -915,8 +939,9 @@ void Tree::update_cache() {
}
int Tree::compute_item_height(TreeItem *p_item) const {
- if (p_item == root && hide_root)
+ if (p_item == root && hide_root) {
return 0;
+ }
ERR_FAIL_COND_V(cache.font.is_null(), 0);
int height = cache.font->get_height();
@@ -925,15 +950,17 @@ int Tree::compute_item_height(TreeItem *p_item) const {
for (int j = 0; j < p_item->cells[i].buttons.size(); j++) {
Size2i s; // = cache.button_pressed->get_minimum_size();
s += p_item->cells[i].buttons[j].texture->get_size();
- if (s.height > height)
+ if (s.height > height) {
height = s.height;
+ }
}
switch (p_item->cells[i].mode) {
case TreeItem::CELL_MODE_CHECK: {
int check_icon_h = cache.checked->get_height();
- if (height < check_icon_h)
+ if (height < check_icon_h) {
height = check_icon_h;
+ }
[[fallthrough]];
}
case TreeItem::CELL_MODE_STRING:
@@ -945,8 +972,9 @@ int Tree::compute_item_height(TreeItem *p_item) const {
if (p_item->cells[i].icon_max_w > 0 && s.width > p_item->cells[i].icon_max_w) {
s.height = s.height * p_item->cells[i].icon_max_w / s.width;
}
- if (s.height > height)
+ if (s.height > height) {
height = s.height;
+ }
}
if (p_item->cells[i].mode == TreeItem::CELL_MODE_CUSTOM && p_item->cells[i].custom_button) {
height += cache.custom_button->get_minimum_size().height;
@@ -958,8 +986,9 @@ int Tree::compute_item_height(TreeItem *p_item) const {
}
}
int item_min_height = p_item->get_custom_minimum_height();
- if (height < item_min_height)
+ if (height < item_min_height) {
height = item_min_height;
+ }
height += cache.vseparation;
@@ -990,8 +1019,9 @@ void Tree::draw_item_rect(const TreeItem::Cell &p_cell, const Rect2i &p_rect, co
Rect2i rect = p_rect;
Ref<Font> font = cache.font;
String text = p_cell.text;
- if (p_cell.suffix != String())
+ if (p_cell.suffix != String()) {
text += " " + p_cell.suffix;
+ }
int w = 0;
if (!p_cell.icon.is_null()) {
@@ -1034,8 +1064,9 @@ void Tree::draw_item_rect(const TreeItem::Cell &p_cell, const Rect2i &p_rect, co
}
int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 &p_draw_size, TreeItem *p_item) {
- if (p_pos.y - cache.offset.y > (p_draw_size.height))
+ if (p_pos.y - cache.offset.y > (p_draw_size.height)) {
return -1; //draw no more!
+ }
RID ci = get_canvas_item();
@@ -1094,8 +1125,9 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
for (int j = p_item->cells[i].buttons.size() - 1; j >= 0; j--) {
Ref<Texture2D> b = p_item->cells[i].buttons[j].texture;
Size2 s = b->get_size() + cache.button_pressed->get_minimum_size();
- if (s.height < label_h)
+ if (s.height < label_h) {
s.height = label_h;
+ }
Point2i o = Point2i(ofs + w - s.width, p_pos.y) - cache.offset + p_draw_ofs;
@@ -1128,10 +1160,11 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
Rect2i row_rect = Rect2i(Point2i(cache.bg->get_margin(MARGIN_LEFT), item_rect.position.y), Size2i(get_size().width - cache.bg->get_minimum_size().width, item_rect.size.y));
//Rect2 r = Rect2i(row_rect.pos,row_rect.size);
//r.grow(cache.selected->get_margin(MARGIN_LEFT));
- if (has_focus())
+ if (has_focus()) {
cache.selected_focus->draw(ci, row_rect);
- else
+ } else {
cache.selected->draw(ci, row_rect);
+ }
}
}
@@ -1224,8 +1257,9 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
} break;
case TreeItem::CELL_MODE_RANGE: {
if (p_item->cells[i].text != "") {
- if (!p_item->cells[i].editable)
+ if (!p_item->cells[i].editable) {
break;
+ }
int option = (int)p_item->cells[i].val;
@@ -1242,8 +1276,9 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
}
}
- if (p_item->cells[i].suffix != String())
+ if (p_item->cells[i].suffix != String()) {
s += " " + p_item->cells[i].suffix;
+ }
Ref<Texture2D> downarrow = cache.select_arrow;
@@ -1259,13 +1294,15 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
String valtext = String::num(p_item->cells[i].val, Math::range_step_decimals(p_item->cells[i].step));
- if (p_item->cells[i].suffix != String())
+ if (p_item->cells[i].suffix != String()) {
valtext += " " + p_item->cells[i].suffix;
+ }
font->draw(ci, text_pos, valtext, col, item_rect.size.x - updown->get_width());
- if (!p_item->cells[i].editable)
+ if (!p_item->cells[i].editable) {
break;
+ }
Point2i updown_pos = item_rect.position;
updown_pos.x += item_rect.size.x - updown->get_width();
@@ -1276,8 +1313,9 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
} break;
case TreeItem::CELL_MODE_ICON: {
- if (p_item->cells[i].icon.is_null())
+ if (p_item->cells[i].icon.is_null()) {
break;
+ }
Size2i icon_size = p_item->cells[i].get_icon_size();
if (p_item->cells[i].icon_max_w > 0 && icon_size.width > p_item->cells[i].icon_max_w) {
icon_size.height = icon_size.height * p_item->cells[i].icon_max_w / icon_size.width;
@@ -1293,8 +1331,9 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
case TreeItem::CELL_MODE_CUSTOM: {
if (p_item->cells[i].custom_draw_obj.is_valid()) {
Object *cdo = ObjectDB::get_instance(p_item->cells[i].custom_draw_obj);
- if (cdo)
+ if (cdo) {
cdo->call(p_item->cells[i].custom_draw_callback, p_item, Rect2(item_rect));
+ }
}
if (!p_item->cells[i].editable) {
@@ -1340,10 +1379,11 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
}
if (select_mode == SELECT_MULTI && selected_item == p_item && selected_col == i) {
- if (has_focus())
+ if (has_focus()) {
cache.cursor->draw(ci, cell_rect);
- else
+ } else {
cache.cursor_unfocus->draw(ci, cell_rect);
+ }
}
}
@@ -1381,8 +1421,9 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
int parent_ofs = p_pos.x + ((p_item->disable_folding || hide_folding) ? cache.hseparation : cache.item_margin);
Point2i root_pos = Point2i(root_ofs, children_pos.y + label_h / 2) - cache.offset + p_draw_ofs;
- if (c->get_children() != nullptr)
+ if (c->get_children() != nullptr) {
root_pos -= Point2i(cache.arrow->get_width(), 0);
+ }
float line_width = 1.0;
#ifdef TOOLS_ENABLED
@@ -1428,8 +1469,9 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
int Tree::_count_selected_items(TreeItem *p_from) const {
int count = 0;
for (int i = 0; i < columns.size(); i++) {
- if (p_from->is_selected(i))
+ if (p_from->is_selected(i)) {
count++;
+ }
}
if (p_from->get_children()) {
@@ -1457,8 +1499,9 @@ void Tree::select_single_item(TreeItem *p_selected, TreeItem *p_current, int p_c
for (int i = 0; i < columns.size(); i++) {
TreeItem::Cell &c = p_current->cells.write[i];
- if (!c.selectable)
+ if (!c.selectable) {
continue;
+ }
if (select_mode == SELECT_ROW) {
if (p_selected == p_current && (!c.selected || allow_reselect)) {
@@ -1487,10 +1530,11 @@ void Tree::select_single_item(TreeItem *p_selected, TreeItem *p_current, int p_c
selected_col = i;
emit_signal("cell_selected");
- if (select_mode == SELECT_MULTI)
+ if (select_mode == SELECT_MULTI) {
emit_signal("multi_selected", p_current, i, true);
- else if (select_mode == SELECT_SINGLE)
+ } else if (select_mode == SELECT_SINGLE) {
emit_signal("item_selected");
+ }
} else if (select_mode == SELECT_MULTI && (selected_item != p_selected || selected_col != i)) {
selected_item = p_selected;
@@ -1505,8 +1549,9 @@ void Tree::select_single_item(TreeItem *p_selected, TreeItem *p_current, int p_c
}
} else if (!r_in_range || p_force_deselect) {
- if (select_mode == SELECT_MULTI && c.selected)
+ if (select_mode == SELECT_MULTI && c.selected) {
emit_signal("multi_selected", p_current, i, false);
+ }
c.selected = false;
}
//p_current->deselected_signal.call(p_col);
@@ -1558,8 +1603,9 @@ void Tree::_range_click_timeout() {
range_click_timer->start();
}
- if (!click_handled)
+ if (!click_handled) {
range_click_timer->stop();
+ }
if (propagate_mouse_activated) {
emit_signal("item_activated");
@@ -1584,8 +1630,9 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool
}
if (!p_item->disable_folding && !hide_folding && (p_pos.x >= x_ofs && p_pos.x < (x_ofs + cache.item_margin))) {
- if (p_item->children)
+ if (p_item->children) {
p_item->set_collapsed(!p_item->is_collapsed());
+ }
return -1; //handled!
}
@@ -1617,9 +1664,9 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool
break;
}
- if (col == -1)
+ if (col == -1) {
return -1;
- else if (col == 0) {
+ } else if (col == 0) {
int margin = x_ofs + cache.item_margin; //-cache.hseparation;
//int lm = cache.bg->get_margin(MARGIN_LEFT);
col_width -= margin;
@@ -1726,8 +1773,9 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool
}
}
- if (!c.editable)
+ if (!c.editable) {
return -1; // if cell is not editable, don't bother
+ }
/* editing */
@@ -1813,8 +1861,9 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool
} else {
editor_text = String::num(p_item->cells[col].val, Math::range_step_decimals(p_item->cells[col].step));
- if (select_mode == SELECT_MULTI && get_tree()->get_event_count() == focus_in_id)
+ if (select_mode == SELECT_MULTI && get_tree()->get_event_count() == focus_in_id) {
bring_up_editor = false;
+ }
}
}
click_handled = true;
@@ -1842,8 +1891,9 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool
} break;
};
- if (!bring_up_editor || p_button != BUTTON_LEFT)
+ if (!bring_up_editor || p_button != BUTTON_LEFT) {
return -1;
+ }
click_handled = true;
popup_edited_item = p_item;
@@ -1871,8 +1921,9 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool
while (c) {
int child_h = propagate_mouse_event(new_pos, x_ofs, y_ofs, p_doubleclick, c, p_button, p_mod);
- if (child_h < 0)
+ if (child_h < 0) {
return -1; // break, stop propagating, no need to anymore
+ }
new_pos.y -= child_h;
y_ofs += child_h;
@@ -1895,8 +1946,9 @@ void Tree::_text_editor_modal_close() {
return;
}
- if (value_editor->has_point(value_editor->get_local_mouse_position()))
+ if (value_editor->has_point(value_editor->get_local_mouse_position())) {
return;
+ }
_text_editor_enter(text_editor->get_text());
}
@@ -1904,11 +1956,13 @@ void Tree::_text_editor_modal_close() {
void Tree::_text_editor_enter(String p_text) {
popup_editor->hide();
- if (!popup_edited_item)
+ if (!popup_edited_item) {
return;
+ }
- if (popup_edited_item_col < 0 || popup_edited_item_col > columns.size())
+ if (popup_edited_item_col < 0 || popup_edited_item_col > columns.size()) {
return;
+ }
TreeItem::Cell &c = popup_edited_item->cells.write[popup_edited_item_col];
switch (c.mode) {
@@ -1918,12 +1972,14 @@ void Tree::_text_editor_enter(String p_text) {
} break;
case TreeItem::CELL_MODE_RANGE: {
c.val = p_text.to_double();
- if (c.step > 0)
+ if (c.step > 0) {
c.val = Math::stepify(c.val, c.step);
- if (c.val < c.min)
+ }
+ if (c.val < c.min) {
c.val = c.min;
- else if (c.val > c.max)
+ } else if (c.val > c.max) {
c.val = c.max;
+ }
//popup_edited_item->edited_signal.call( popup_edited_item_col );
} break;
@@ -1951,11 +2007,13 @@ void Tree::value_editor_changed(double p_value) {
}
void Tree::popup_select(int p_option) {
- if (!popup_edited_item)
+ if (!popup_edited_item) {
return;
+ }
- if (popup_edited_item_col < 0 || popup_edited_item_col > columns.size())
+ if (popup_edited_item_col < 0 || popup_edited_item_col > columns.size()) {
return;
+ }
popup_edited_item->cells.write[popup_edited_item_col].val = p_option;
//popup_edited_item->edited_signal.call( popup_edited_item_col );
@@ -2031,17 +2089,20 @@ void Tree::_go_up() {
}
if (select_mode == SELECT_MULTI) {
- if (!prev)
+ if (!prev) {
return;
+ }
selected_item = prev;
emit_signal("cell_selected");
update();
} else {
int col = selected_col < 0 ? 0 : selected_col;
- while (prev && !prev->cells[col].selectable)
+ while (prev && !prev->cells[col].selectable) {
prev = prev->get_prev_visible();
- if (!prev)
+ }
+ if (!prev) {
return; // do nothing..
+ }
prev->select(col);
}
@@ -2080,8 +2141,9 @@ void Tree::_go_down() {
} else {
int col = selected_col < 0 ? 0 : selected_col;
- while (next && !next->cells[col].selectable)
+ while (next && !next->cells[col].selectable) {
next = next->get_next_visible();
+ }
if (!next) {
return; // do nothing..
}
@@ -2097,8 +2159,9 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
bool is_command = k.is_valid() && k->get_command();
if (p_event->is_action("ui_right") && p_event->is_pressed()) {
- if (!cursor_can_exit_tree)
+ if (!cursor_can_exit_tree) {
accept_event();
+ }
if (!selected_item || select_mode == SELECT_ROW || selected_col > (columns.size() - 1)) {
return;
@@ -2114,8 +2177,9 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
_go_right();
}
} else if (p_event->is_action("ui_left") && p_event->is_pressed()) {
- if (!cursor_can_exit_tree)
+ if (!cursor_can_exit_tree) {
accept_event();
+ }
if (!selected_item || select_mode == SELECT_ROW || selected_col < 0) {
return;
@@ -2133,24 +2197,28 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
}
} else if (p_event->is_action("ui_up") && p_event->is_pressed() && !is_command) {
- if (!cursor_can_exit_tree)
+ if (!cursor_can_exit_tree) {
accept_event();
+ }
_go_up();
} else if (p_event->is_action("ui_down") && p_event->is_pressed() && !is_command) {
- if (!cursor_can_exit_tree)
+ if (!cursor_can_exit_tree) {
accept_event();
+ }
_go_down();
} else if (p_event->is_action("ui_page_down") && p_event->is_pressed()) {
- if (!cursor_can_exit_tree)
+ if (!cursor_can_exit_tree) {
accept_event();
+ }
TreeItem *next = nullptr;
- if (!selected_item)
+ if (!selected_item) {
return;
+ }
next = selected_item;
for (int i = 0; i < 10; i++) {
@@ -2161,16 +2229,18 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
break;
}
}
- if (next == selected_item)
+ if (next == selected_item) {
return;
+ }
if (select_mode == SELECT_MULTI) {
selected_item = next;
emit_signal("cell_selected");
update();
} else {
- while (next && !next->cells[selected_col].selectable)
+ while (next && !next->cells[selected_col].selectable) {
next = next->get_next_visible();
+ }
if (!next) {
return; // do nothing..
}
@@ -2179,12 +2249,14 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
ensure_cursor_is_visible();
} else if (p_event->is_action("ui_page_up") && p_event->is_pressed()) {
- if (!cursor_can_exit_tree)
+ if (!cursor_can_exit_tree) {
accept_event();
+ }
TreeItem *prev = nullptr;
- if (!selected_item)
+ if (!selected_item) {
return;
+ }
prev = selected_item;
for (int i = 0; i < 10; i++) {
@@ -2195,16 +2267,18 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
break;
}
}
- if (prev == selected_item)
+ if (prev == selected_item) {
return;
+ }
if (select_mode == SELECT_MULTI) {
selected_item = prev;
emit_signal("cell_selected");
update();
} else {
- while (prev && !prev->cells[selected_col].selectable)
+ while (prev && !prev->cells[selected_col].selectable) {
prev = prev->get_prev_visible();
+ }
if (!prev) {
return; // do nothing..
}
@@ -2222,8 +2296,9 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
accept_event();
} else if (p_event->is_action("ui_select") && p_event->is_pressed()) {
if (select_mode == SELECT_MULTI) {
- if (!selected_item)
+ if (!selected_item) {
return;
+ }
if (selected_item->is_selected(selected_col)) {
selected_item->deselect(selected_col);
emit_signal("multi_selected", selected_item, selected_col, false);
@@ -2237,15 +2312,19 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
if (k.is_valid()) { // Incremental search
- if (!k->is_pressed())
+ if (!k->is_pressed()) {
return;
- if (k->get_command() || (k->get_shift() && k->get_unicode() == 0) || k->get_metakey())
+ }
+ if (k->get_command() || (k->get_shift() && k->get_unicode() == 0) || k->get_metakey()) {
return;
- if (!root)
+ }
+ if (!root) {
return;
+ }
- if (hide_root && !root->get_next_visible())
+ if (hide_root && !root->get_next_visible()) {
return;
+ }
if (k->get_unicode() > 0) {
_do_incr_search(String::chr(k->get_unicode()));
@@ -2253,16 +2332,18 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
return;
} else {
- if (k->get_keycode() != KEY_SHIFT)
+ if (k->get_keycode() != KEY_SHIFT) {
last_keypress = 0;
+ }
}
}
Ref<InputEventMouseMotion> mm = p_event;
if (mm.is_valid()) {
- if (cache.font.is_null()) // avoid a strange case that may corrupt stuff
+ if (cache.font.is_null()) { // avoid a strange case that may corrupt stuff
update_cache();
+ }
Ref<StyleBox> bg = cache.bg;
@@ -2295,10 +2376,12 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
mpos -= cache.bg->get_offset();
mpos.y -= _get_title_button_height();
if (mpos.y >= 0) {
- if (h_scroll->is_visible_in_tree())
+ if (h_scroll->is_visible_in_tree()) {
mpos.x += h_scroll->get_value();
- if (v_scroll->is_visible_in_tree())
+ }
+ if (v_scroll->is_visible_in_tree()) {
mpos.y += v_scroll->get_value();
+ }
int col, h, section;
TreeItem *it = _find_item_at_pos(root, mpos, col, h, section);
@@ -2362,8 +2445,9 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
Ref<InputEventMouseButton> b = p_event;
if (b.is_valid()) {
- if (cache.font.is_null()) // avoid a strange case that may corrupt stuff
+ if (cache.font.is_null()) { // avoid a strange case that may corrupt stuff
update_cache();
+ }
if (!b->is_pressed()) {
if (b->get_button_index() == BUTTON_LEFT) {
@@ -2434,8 +2518,9 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
return;
}
- if (range_drag_enabled)
+ if (range_drag_enabled) {
return;
+ }
switch (b->get_button_index()) {
case BUTTON_RIGHT:
@@ -2484,8 +2569,9 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
pressing_pos = b->get_position();
}
- if (b->get_button_index() == BUTTON_RIGHT)
+ if (b->get_button_index() == BUTTON_RIGHT) {
break;
+ }
if (drag_touching) {
set_physics_process_internal(false);
@@ -2507,8 +2593,9 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
}
if (b->get_button_index() == BUTTON_LEFT) {
- if (get_item_at_position(b->get_position()) == nullptr && !b->get_shift() && !b->get_control() && !b->get_command())
+ if (get_item_at_position(b->get_position()) == nullptr && !b->get_shift() && !b->get_control() && !b->get_command()) {
emit_signal("nothing_selected");
+ }
}
}
@@ -2558,8 +2645,9 @@ bool Tree::edit_selected() {
int col = get_selected_column();
ERR_FAIL_INDEX_V_MSG(col, columns.size(), false, "No item column selected.");
- if (!s->cells[col].editable)
+ if (!s->cells[col].editable) {
return false;
+ }
Rect2 rect = s->get_meta("__focus_rect");
popup_edited_item = s;
@@ -2636,8 +2724,9 @@ bool Tree::edit_selected() {
Size2 Tree::get_internal_min_size() const {
Size2i size = cache.bg->get_offset();
- if (root)
+ if (root) {
size.height += get_item_height(root);
+ }
for (int i = 0; i < columns.size(); i++) {
size.width += columns[i].min_width;
}
@@ -2873,10 +2962,11 @@ TreeItem *Tree::create_item(TreeItem *p_parent, int p_idx) {
c = c->next;
}
- if (prev)
+ if (prev) {
prev->next = ti;
- else
+ } else {
p_parent->children = ti;
+ }
ti->parent = p_parent;
} else {
@@ -2904,12 +2994,13 @@ TreeItem *Tree::get_last_item() {
TreeItem *last = root;
while (last) {
- if (last->next)
+ if (last->next) {
last = last->next;
- else if (last->children)
+ } else if (last->children) {
last = last->children;
- else
+ } else {
break;
+ }
}
return last;
@@ -2918,10 +3009,11 @@ TreeItem *Tree::get_last_item() {
void Tree::item_edited(int p_column, TreeItem *p_item, bool p_lmb) {
edited_item = p_item;
edited_col = p_column;
- if (p_lmb)
+ if (p_lmb) {
emit_signal("item_edited");
- else
+ } else {
emit_signal("item_rmb_edited");
+ }
}
void Tree::item_changed(int p_column, TreeItem *p_item) {
@@ -2930,8 +3022,9 @@ void Tree::item_changed(int p_column, TreeItem *p_item) {
void Tree::item_selected(int p_column, TreeItem *p_item) {
if (select_mode == SELECT_MULTI) {
- if (!p_item->cells[p_column].selectable)
+ if (!p_item->cells[p_column].selectable) {
return;
+ }
p_item->cells.write[p_column].selected = true;
//emit_signal("multi_selected",p_item,p_column,true); - NO this is for TreeItem::select
@@ -3013,8 +3106,9 @@ bool Tree::is_root_hidden() const {
void Tree::set_column_min_width(int p_column, int p_min_width) {
ERR_FAIL_INDEX(p_column, columns.size());
- if (p_min_width < 1)
+ if (p_min_width < 1) {
return;
+ }
columns.write[p_column].min_width = p_min_width;
update();
}
@@ -3047,8 +3141,9 @@ TreeItem *Tree::get_next_selected(TreeItem *p_item) {
if (!p_item)
return nullptr;
*/
- if (!root)
+ if (!root) {
return nullptr;
+ }
while (true) {
if (!p_item) {
@@ -3062,17 +3157,20 @@ TreeItem *Tree::get_next_selected(TreeItem *p_item) {
} else {
while (!p_item->next) {
p_item = p_item->parent;
- if (p_item == nullptr)
+ if (p_item == nullptr) {
return nullptr;
+ }
}
p_item = p_item->next;
}
}
- for (int i = 0; i < columns.size(); i++)
- if (p_item->cells[i].selected)
+ for (int i = 0; i < columns.size(); i++) {
+ if (p_item->cells[i].selected) {
return p_item;
+ }
+ }
}
return nullptr;
@@ -3081,15 +3179,17 @@ TreeItem *Tree::get_next_selected(TreeItem *p_item) {
int Tree::get_column_width(int p_column) const {
ERR_FAIL_INDEX_V(p_column, columns.size(), -1);
- if (!columns[p_column].expand)
+ if (!columns[p_column].expand) {
return columns[p_column].min_width;
+ }
Ref<StyleBox> bg = cache.bg;
int expand_area = get_size().width - (bg->get_margin(MARGIN_LEFT) + bg->get_margin(MARGIN_RIGHT));
- if (v_scroll->is_visible_in_tree())
+ if (v_scroll->is_visible_in_tree()) {
expand_area -= v_scroll->get_combined_minimum_size().width;
+ }
int expanding_columns = 0;
int expanding_total = 0;
@@ -3103,8 +3203,9 @@ int Tree::get_column_width(int p_column) const {
}
}
- if (expand_area < expanding_total)
+ if (expand_area < expanding_total) {
return columns[p_column].min_width;
+ }
ERR_FAIL_COND_V(expanding_columns == 0, -1); // shouldn't happen
@@ -3126,10 +3227,12 @@ void Tree::set_columns(int p_columns) {
ERR_FAIL_COND(blocked > 0);
columns.resize(p_columns);
- if (root)
+ if (root) {
propagate_set_columns(root);
- if (selected_col >= p_columns)
+ }
+ if (selected_col >= p_columns) {
selected_col = p_columns - 1;
+ }
update();
}
@@ -3148,12 +3251,14 @@ Rect2 Tree::get_custom_popup_rect() const {
int Tree::get_item_offset(TreeItem *p_item) const {
TreeItem *it = root;
int ofs = _get_title_button_height();
- if (!it)
+ if (!it) {
return 0;
+ }
while (true) {
- if (it == p_item)
+ if (it == p_item) {
return ofs;
+ }
ofs += compute_item_height(it);
if (it != root || !hide_root) {
@@ -3168,8 +3273,9 @@ int Tree::get_item_offset(TreeItem *p_item) const {
} else {
while (!it->next) {
it = it->parent;
- if (it == nullptr)
+ if (it == nullptr) {
return 0;
+ }
}
it = it->next;
@@ -3279,10 +3385,12 @@ String Tree::get_column_title(int p_column) const {
Point2 Tree::get_scroll() const {
Point2 ofs;
- if (h_scroll->is_visible_in_tree())
+ if (h_scroll->is_visible_in_tree()) {
ofs.x = h_scroll->get_value();
- if (v_scroll->is_visible_in_tree())
+ }
+ if (v_scroll->is_visible_in_tree()) {
ofs.y = v_scroll->get_value();
+ }
return ofs;
}
@@ -3309,19 +3417,22 @@ TreeItem *Tree::_search_item_text(TreeItem *p_at, const String &p_find, int *r_c
while (p_at) {
for (int i = 0; i < columns.size(); i++) {
if (p_at->get_text(i).findn(p_find) == 0 && (!p_selectable || p_at->is_selectable(i))) {
- if (r_col)
+ if (r_col) {
*r_col = i;
+ }
return p_at;
}
}
- if (p_backwards)
+ if (p_backwards) {
p_at = p_at->get_prev_visible(true);
- else
+ } else {
p_at = p_at->get_next_visible(true);
+ }
- if ((p_at) == from)
+ if ((p_at) == from) {
break;
+ }
}
return nullptr;
@@ -3330,10 +3441,12 @@ TreeItem *Tree::_search_item_text(TreeItem *p_at, const String &p_find, int *r_c
TreeItem *Tree::search_item_text(const String &p_find, int *r_col, bool p_selectable) {
TreeItem *from = get_selected();
- if (!from)
+ if (!from) {
from = root;
- if (!from)
+ }
+ if (!from) {
return nullptr;
+ }
return _search_item_text(from->get_next_visible(true), p_find, r_col, p_selectable);
}
@@ -3352,16 +3465,18 @@ TreeItem *Tree::get_item_with_text(const String &p_find) const {
void Tree::_do_incr_search(const String &p_add) {
uint64_t time = OS::get_singleton()->get_ticks_usec() / 1000; // convert to msec
uint64_t diff = time - last_keypress;
- if (diff > uint64_t(GLOBAL_DEF("gui/timers/incremental_search_max_interval_msec", 2000)))
+ if (diff > uint64_t(GLOBAL_DEF("gui/timers/incremental_search_max_interval_msec", 2000))) {
incr_search = p_add;
- else if (incr_search != p_add)
+ } else if (incr_search != p_add) {
incr_search += p_add;
+ }
last_keypress = time;
int col;
TreeItem *item = search_item_text(incr_search, &col, true);
- if (!item)
+ if (!item) {
return;
+ }
item->select(col);
ensure_cursor_is_visible();
@@ -3403,8 +3518,9 @@ TreeItem *Tree::_find_item_at_pos(TreeItem *p_item, const Point2 &p_pos, int &r_
h = 0;
}
- if (p_item->is_collapsed())
+ if (p_item->is_collapsed()) {
return nullptr; // do not try children, it's collapsed
+ }
TreeItem *n = p_item->get_children();
while (n) {
@@ -3412,8 +3528,9 @@ TreeItem *Tree::_find_item_at_pos(TreeItem *p_item, const Point2 &p_pos, int &r_
TreeItem *r = _find_item_at_pos(n, pos, r_column, ch, section);
pos.y -= ch;
h += ch;
- if (r)
+ if (r) {
return r;
+ }
n = n->get_next();
}
@@ -3425,13 +3542,16 @@ int Tree::get_column_at_position(const Point2 &p_pos) const {
Point2 pos = p_pos;
pos -= cache.bg->get_offset();
pos.y -= _get_title_button_height();
- if (pos.y < 0)
+ if (pos.y < 0) {
return -1;
+ }
- if (h_scroll->is_visible_in_tree())
+ if (h_scroll->is_visible_in_tree()) {
pos.x += h_scroll->get_value();
- if (v_scroll->is_visible_in_tree())
+ }
+ if (v_scroll->is_visible_in_tree()) {
pos.y += v_scroll->get_value();
+ }
int col, h, section;
TreeItem *it = _find_item_at_pos(root, pos, col, h, section);
@@ -3449,13 +3569,16 @@ int Tree::get_drop_section_at_position(const Point2 &p_pos) const {
Point2 pos = p_pos;
pos -= cache.bg->get_offset();
pos.y -= _get_title_button_height();
- if (pos.y < 0)
+ if (pos.y < 0) {
return -100;
+ }
- if (h_scroll->is_visible_in_tree())
+ if (h_scroll->is_visible_in_tree()) {
pos.x += h_scroll->get_value();
- if (v_scroll->is_visible_in_tree())
+ }
+ if (v_scroll->is_visible_in_tree()) {
pos.y += v_scroll->get_value();
+ }
int col, h, section;
TreeItem *it = _find_item_at_pos(root, pos, col, h, section);
@@ -3473,13 +3596,16 @@ TreeItem *Tree::get_item_at_position(const Point2 &p_pos) const {
Point2 pos = p_pos;
pos -= cache.bg->get_offset();
pos.y -= _get_title_button_height();
- if (pos.y < 0)
+ if (pos.y < 0) {
return nullptr;
+ }
- if (h_scroll->is_visible_in_tree())
+ if (h_scroll->is_visible_in_tree()) {
pos.x += h_scroll->get_value();
- if (v_scroll->is_visible_in_tree())
+ }
+ if (v_scroll->is_visible_in_tree()) {
pos.y += v_scroll->get_value();
+ }
int col, h, section;
TreeItem *it = _find_item_at_pos(root, pos, col, h, section);
@@ -3497,13 +3623,16 @@ String Tree::get_tooltip(const Point2 &p_pos) const {
Point2 pos = p_pos;
pos -= cache.bg->get_offset();
pos.y -= _get_title_button_height();
- if (pos.y < 0)
+ if (pos.y < 0) {
return Control::get_tooltip(p_pos);
+ }
- if (h_scroll->is_visible_in_tree())
+ if (h_scroll->is_visible_in_tree()) {
pos.x += h_scroll->get_value();
- if (v_scroll->is_visible_in_tree())
+ }
+ if (v_scroll->is_visible_in_tree()) {
pos.y += v_scroll->get_value();
+ }
int col, h, section;
TreeItem *it = _find_item_at_pos(root, pos, col, h, section);
@@ -3512,8 +3641,9 @@ String Tree::get_tooltip(const Point2 &p_pos) const {
const TreeItem::Cell &c = it->cells[col];
int col_width = get_column_width(col);
- for (int i = 0; i < col; i++)
+ for (int i = 0; i < col; i++) {
pos.x -= get_column_width(i);
+ }
for (int j = c.buttons.size() - 1; j >= 0; j--) {
Ref<Texture2D> b = c.buttons[j].texture;
@@ -3527,10 +3657,11 @@ String Tree::get_tooltip(const Point2 &p_pos) const {
col_width -= size.width;
}
String ret;
- if (it->get_tooltip(col) == "")
+ if (it->get_tooltip(col) == "") {
ret = it->get_text(col);
- else
+ } else {
ret = it->get_tooltip(col);
+ }
return ret;
}
}
@@ -3556,8 +3687,9 @@ bool Tree::is_folding_hidden() const {
}
void Tree::set_drop_mode_flags(int p_flags) {
- if (drop_mode_flags == p_flags)
+ if (drop_mode_flags == p_flags) {
return;
+ }
drop_mode_flags = p_flags;
if (drop_mode_flags == 0) {
drop_mode_over = nullptr;
diff --git a/scene/gui/video_player.cpp b/scene/gui/video_player.cpp
index 52538203dd..881df06d8f 100644
--- a/scene/gui/video_player.cpp
+++ b/scene/gui/video_player.cpp
@@ -93,8 +93,9 @@ void VideoPlayer::_mix_audio() {
int buffer_size = mix_buffer.size();
// Resample
- if (!mix(buffer, buffer_size))
+ if (!mix(buffer, buffer_size)) {
return;
+ }
AudioFrame vol = AudioFrame(volume, volume);
@@ -144,16 +145,18 @@ void VideoPlayer::_notification(int p_notification) {
case NOTIFICATION_INTERNAL_PROCESS: {
bus_index = AudioServer::get_singleton()->thread_find_bus_index(bus);
- if (stream.is_null() || paused || playback.is_null() || !playback->is_playing())
+ if (stream.is_null() || paused || playback.is_null() || !playback->is_playing()) {
return;
+ }
double audio_time = USEC_TO_SEC(OS::get_singleton()->get_ticks_usec());
double delta = last_audio_time == 0 ? 0 : audio_time - last_audio_time;
last_audio_time = audio_time;
- if (delta == 0)
+ if (delta == 0) {
return;
+ }
playback->update(delta); // playback->is_playing() returns false in the last video frame
@@ -164,10 +167,12 @@ void VideoPlayer::_notification(int p_notification) {
} break;
case NOTIFICATION_DRAW: {
- if (texture.is_null())
+ if (texture.is_null()) {
return;
- if (texture->get_width() == 0)
+ }
+ if (texture->get_width() == 0) {
return;
+ }
Size2 s = expand ? get_size() : texture->get_size();
draw_texture_rect(texture, Rect2(Point2(), s), false);
@@ -177,10 +182,11 @@ void VideoPlayer::_notification(int p_notification) {
};
Size2 VideoPlayer::get_minimum_size() const {
- if (!expand && !texture.is_null())
+ if (!expand && !texture.is_null()) {
return texture->get_size();
- else
+ } else {
return Size2();
+ }
}
void VideoPlayer::set_expand(bool p_expand) {
@@ -215,14 +221,16 @@ void VideoPlayer::set_stream(const Ref<VideoStream> &p_stream) {
const int channels = playback->get_channels();
AudioServer::get_singleton()->lock();
- if (channels > 0)
+ if (channels > 0) {
resampler.setup(channels, playback->get_mix_rate(), AudioServer::get_singleton()->get_mix_rate(), buffering_ms, 0);
- else
+ } else {
resampler.clear();
+ }
AudioServer::get_singleton()->unlock();
- if (channels > 0)
+ if (channels > 0) {
playback->set_mix_callback(_audio_mix_callback, this);
+ }
} else {
texture.unref();
@@ -244,8 +252,9 @@ Ref<VideoStream> VideoPlayer::get_stream() const {
void VideoPlayer::play() {
ERR_FAIL_COND(!is_inside_tree());
- if (playback.is_null())
+ if (playback.is_null()) {
return;
+ }
playback->stop();
playback->play();
set_process_internal(true);
@@ -255,10 +264,12 @@ void VideoPlayer::play() {
};
void VideoPlayer::stop() {
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
- if (playback.is_null())
+ }
+ if (playback.is_null()) {
return;
+ }
playback->stop();
// AudioServer::get_singleton()->stream_set_active(stream_rid,false);
@@ -268,8 +279,9 @@ void VideoPlayer::stop() {
};
bool VideoPlayer::is_playing() const {
- if (playback.is_null())
+ if (playback.is_null()) {
return false;
+ }
return playback->is_playing();
};
@@ -312,39 +324,45 @@ float VideoPlayer::get_volume() const {
};
void VideoPlayer::set_volume_db(float p_db) {
- if (p_db < -79)
+ if (p_db < -79) {
set_volume(0);
- else
+ } else {
set_volume(Math::db2linear(p_db));
+ }
};
float VideoPlayer::get_volume_db() const {
- if (volume == 0)
+ if (volume == 0) {
return -80;
- else
+ } else {
return Math::linear2db(volume);
+ }
};
String VideoPlayer::get_stream_name() const {
- if (stream.is_null())
+ if (stream.is_null()) {
return "<No Stream>";
+ }
return stream->get_name();
};
float VideoPlayer::get_stream_position() const {
- if (playback.is_null())
+ if (playback.is_null()) {
return 0;
+ }
return playback->get_playback_position();
};
void VideoPlayer::set_stream_position(float p_position) {
- if (playback.is_valid())
+ if (playback.is_valid()) {
playback->seek(p_position);
+ }
}
Ref<Texture2D> VideoPlayer::get_video_texture() const {
- if (playback.is_valid())
+ if (playback.is_valid()) {
return playback->get_texture();
+ }
return Ref<Texture2D>();
}
@@ -377,8 +395,9 @@ void VideoPlayer::_validate_property(PropertyInfo &p_property) const {
if (p_property.name == "bus") {
String options;
for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) {
- if (i > 0)
+ if (i > 0) {
options += ",";
+ }
String name = AudioServer::get_singleton()->get_bus_name(i);
options += name;
}
diff --git a/scene/main/canvas_item.cpp b/scene/main/canvas_item.cpp
index 24a9d24e0e..524ff346d1 100644
--- a/scene/main/canvas_item.cpp
+++ b/scene/main/canvas_item.cpp
@@ -67,8 +67,9 @@ void CanvasItemMaterial::_update_shader() {
dirty_materials->remove(&element);
MaterialKey mk = _compute_key();
- if (mk.key == current_key.key)
+ if (mk.key == current_key.key) {
return; //no update required in the end
+ }
if (shader_map.has(current_key)) {
shader_map[current_key].users--;
@@ -335,14 +336,16 @@ Transform2D CanvasItem::_edit_get_transform() const {
#endif
bool CanvasItem::is_visible_in_tree() const {
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return false;
+ }
const CanvasItem *p = this;
while (p) {
- if (!p->visible)
+ if (!p->visible) {
return false;
+ }
if (p->window && !p->window->is_visible()) {
return false;
}
@@ -358,45 +361,51 @@ void CanvasItem::_propagate_visibility_changed(bool p_visible) {
}
notification(NOTIFICATION_VISIBILITY_CHANGED);
- if (p_visible)
+ if (p_visible) {
update(); //todo optimize
- else
+ } else {
emit_signal(SceneStringNames::get_singleton()->hide);
+ }
_block();
for (int i = 0; i < get_child_count(); i++) {
CanvasItem *c = Object::cast_to<CanvasItem>(get_child(i));
- if (c && c->visible) //should the toplevels stop propagation? i think so but..
+ if (c && c->visible) { //should the toplevels stop propagation? i think so but..
c->_propagate_visibility_changed(p_visible);
+ }
}
_unblock();
}
void CanvasItem::show() {
- if (visible)
+ if (visible) {
return;
+ }
visible = true;
RenderingServer::get_singleton()->canvas_item_set_visible(canvas_item, true);
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
_propagate_visibility_changed(true);
_change_notify("visible");
}
void CanvasItem::hide() {
- if (!visible)
+ if (!visible) {
return;
+ }
visible = false;
RenderingServer::get_singleton()->canvas_item_set_visible(canvas_item, false);
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
_propagate_visibility_changed(false);
_change_notify("visible");
@@ -435,12 +444,13 @@ void CanvasItem::_update_callback() {
}
Transform2D CanvasItem::get_global_transform_with_canvas() const {
- if (canvas_layer)
+ if (canvas_layer) {
return canvas_layer->get_transform() * get_global_transform();
- else if (is_inside_tree())
+ } else if (is_inside_tree()) {
return get_viewport()->get_canvas_transform() * get_global_transform();
- else
+ } else {
return get_global_transform();
+ }
}
Transform2D CanvasItem::get_screen_transform() const {
@@ -464,10 +474,11 @@ Transform2D CanvasItem::get_global_transform() const {
#endif
if (global_invalid) {
const CanvasItem *pi = get_parent_item();
- if (pi)
+ if (pi) {
global_transform = pi->get_global_transform() * get_transform();
- else
+ } else {
global_transform = get_transform();
+ }
global_invalid = false;
}
@@ -476,13 +487,15 @@ Transform2D CanvasItem::get_global_transform() const {
}
void CanvasItem::_toplevel_raise_self() {
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
- if (canvas_layer)
+ if (canvas_layer) {
RenderingServer::get_singleton()->canvas_item_set_draw_index(canvas_item, canvas_layer->get_sort_index());
- else
+ } else {
RenderingServer::get_singleton()->canvas_item_set_draw_index(canvas_item, get_viewport()->gui_get_canvas_sort_index());
+ }
}
void CanvasItem::_enter_canvas() {
@@ -503,20 +516,22 @@ void CanvasItem::_enter_canvas() {
}
RID canvas;
- if (canvas_layer)
+ if (canvas_layer) {
canvas = canvas_layer->get_canvas();
- else
+ } else {
canvas = get_viewport()->find_world_2d()->get_canvas();
+ }
RenderingServer::get_singleton()->canvas_item_set_parent(canvas_item, canvas);
group = "root_canvas" + itos(canvas.get_id());
add_to_group(group);
- if (canvas_layer)
+ if (canvas_layer) {
canvas_layer->reset_sort_index();
- else
+ } else {
get_viewport()->gui_reset_canvas_sort_index();
+ }
get_tree()->call_group_flags(SceneTree::GROUP_CALL_UNIQUE, group, "_toplevel_raise_self");
@@ -550,8 +565,9 @@ void CanvasItem::_notification(int p_what) {
Node *parent = get_parent();
if (parent) {
CanvasItem *ci = Object::cast_to<CanvasItem>(parent);
- if (ci)
+ if (ci) {
C = ci->children_items.push_back(this);
+ }
if (!ci) {
//look for a window
Viewport *viewport = nullptr;
@@ -578,8 +594,9 @@ void CanvasItem::_notification(int p_what) {
}
} break;
case NOTIFICATION_MOVED_IN_PARENT: {
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
break;
+ }
if (group != "") {
get_tree()->call_group_flags(SceneTree::GROUP_CALL_UNIQUE, group, "_toplevel_raise_self");
@@ -591,8 +608,9 @@ void CanvasItem::_notification(int p_what) {
} break;
case NOTIFICATION_EXIT_TREE: {
- if (xform_change.in_list())
+ if (xform_change.in_list()) {
get_tree()->xform_change_list.remove(&xform_change);
+ }
_exit_canvas();
if (C) {
Object::cast_to<CanvasItem>(get_parent())->children_items.erase(C);
@@ -613,10 +631,11 @@ void CanvasItem::_notification(int p_what) {
}
void CanvasItem::set_visible(bool p_visible) {
- if (p_visible)
+ if (p_visible) {
show();
- else
+ } else {
hide();
+ }
}
void CanvasItem::_window_visibility_changed() {
@@ -630,10 +649,12 @@ bool CanvasItem::is_visible() const {
}
void CanvasItem::update() {
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
- if (pending_update)
+ }
+ if (pending_update) {
return;
+ }
pending_update = true;
@@ -641,8 +662,9 @@ void CanvasItem::update() {
}
void CanvasItem::set_modulate(const Color &p_modulate) {
- if (modulate == p_modulate)
+ if (modulate == p_modulate) {
return;
+ }
modulate = p_modulate;
RenderingServer::get_singleton()->canvas_item_set_modulate(canvas_item, modulate);
@@ -653,8 +675,9 @@ Color CanvasItem::get_modulate() const {
}
void CanvasItem::set_as_toplevel(bool p_toplevel) {
- if (toplevel == p_toplevel)
+ if (toplevel == p_toplevel) {
return;
+ }
if (!is_inside_tree()) {
toplevel = p_toplevel;
@@ -671,15 +694,17 @@ bool CanvasItem::is_set_as_toplevel() const {
}
CanvasItem *CanvasItem::get_parent_item() const {
- if (toplevel)
+ if (toplevel) {
return nullptr;
+ }
return Object::cast_to<CanvasItem>(get_parent());
}
void CanvasItem::set_self_modulate(const Color &p_self_modulate) {
- if (self_modulate == p_self_modulate)
+ if (self_modulate == p_self_modulate) {
return;
+ }
self_modulate = p_self_modulate;
RenderingServer::get_singleton()->canvas_item_set_self_modulate(canvas_item, self_modulate);
@@ -690,8 +715,9 @@ Color CanvasItem::get_self_modulate() const {
}
void CanvasItem::set_light_mask(int p_light_mask) {
- if (light_mask == p_light_mask)
+ if (light_mask == p_light_mask) {
return;
+ }
light_mask = p_light_mask;
RS::get_singleton()->canvas_item_set_light_mask(canvas_item, p_light_mask);
@@ -702,8 +728,9 @@ int CanvasItem::get_light_mask() const {
}
void CanvasItem::item_rect_changed(bool p_size_changed) {
- if (p_size_changed)
+ if (p_size_changed) {
update();
+ }
emit_signal(SceneStringNames::get_singleton()->item_rect_changed);
}
@@ -932,15 +959,17 @@ void CanvasItem::_notify_transform(CanvasItem *p_node) {
if (p_node->notify_transform && !p_node->xform_change.in_list()) {
if (!p_node->block_transform_notify) {
- if (p_node->is_inside_tree())
+ if (p_node->is_inside_tree()) {
get_tree()->xform_change_list.add(&p_node->xform_change);
+ }
}
}
for (List<CanvasItem *>::Element *E = p_node->children_items.front(); E; E = E->next()) {
CanvasItem *ci = E->get();
- if (ci->toplevel)
+ if (ci->toplevel) {
continue;
+ }
_notify_transform(ci);
}
}
@@ -953,10 +982,11 @@ Rect2 CanvasItem::get_viewport_rect() const {
RID CanvasItem::get_canvas() const {
ERR_FAIL_COND_V(!is_inside_tree(), RID());
- if (canvas_layer)
+ if (canvas_layer) {
return canvas_layer->get_canvas();
- else
+ } else {
return get_viewport()->find_world_2d()->get_canvas();
+ }
}
ObjectID CanvasItem::get_canvas_layer_instance_id() const {
@@ -1002,8 +1032,9 @@ bool CanvasItem::is_block_transform_notify_enabled() const {
}
void CanvasItem::set_draw_behind_parent(bool p_enable) {
- if (behind == p_enable)
+ if (behind == p_enable) {
return;
+ }
behind = p_enable;
RenderingServer::get_singleton()->canvas_item_set_draw_behind_parent(canvas_item, behind);
}
@@ -1015,8 +1046,9 @@ bool CanvasItem::is_draw_behind_parent_enabled() const {
void CanvasItem::set_material(const Ref<Material> &p_material) {
material = p_material;
RID rid;
- if (material.is_valid())
+ if (material.is_valid()) {
rid = material->get_rid();
+ }
RS::get_singleton()->canvas_item_set_material(canvas_item, rid);
_change_notify(); //properties for material exposed
}
@@ -1230,12 +1262,13 @@ void CanvasItem::_bind_methods() {
Transform2D CanvasItem::get_canvas_transform() const {
ERR_FAIL_COND_V(!is_inside_tree(), Transform2D());
- if (canvas_layer)
+ if (canvas_layer) {
return canvas_layer->get_transform();
- else if (Object::cast_to<CanvasItem>(get_parent()))
+ } else if (Object::cast_to<CanvasItem>(get_parent())) {
return Object::cast_to<CanvasItem>(get_parent())->get_canvas_transform();
- else
+ } else {
return get_viewport()->get_canvas_transform();
+ }
}
Transform2D CanvasItem::get_viewport_transform() const {
@@ -1262,8 +1295,9 @@ bool CanvasItem::is_local_transform_notification_enabled() const {
}
void CanvasItem::set_notify_transform(bool p_enable) {
- if (notify_transform == p_enable)
+ if (notify_transform == p_enable) {
return;
+ }
notify_transform = p_enable;
@@ -1278,10 +1312,11 @@ bool CanvasItem::is_transform_notification_enabled() const {
}
int CanvasItem::get_canvas_layer() const {
- if (canvas_layer)
+ if (canvas_layer) {
return canvas_layer->get_layer();
- else
+ } else {
return 0;
+ }
}
void CanvasItem::_update_texture_filter_changed(bool p_propagate) {
diff --git a/scene/main/canvas_item.h b/scene/main/canvas_item.h
index 5ba014b735..31edd424a1 100644
--- a/scene/main/canvas_item.h
+++ b/scene/main/canvas_item.h
@@ -243,11 +243,13 @@ private:
protected:
_FORCE_INLINE_ void _notify_transform() {
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
_notify_transform(this);
- if (!block_transform_notify && notify_local_transform)
+ if (!block_transform_notify && notify_local_transform) {
notification(NOTIFICATION_LOCAL_TRANSFORM_CHANGED);
+ }
}
void item_rect_changed(bool p_size_changed = true);
diff --git a/scene/main/canvas_layer.cpp b/scene/main/canvas_layer.cpp
index bee62246db..46cfb968f8 100644
--- a/scene/main/canvas_layer.cpp
+++ b/scene/main/canvas_layer.cpp
@@ -33,8 +33,9 @@
void CanvasLayer::set_layer(int p_xform) {
layer = p_xform;
- if (viewport.is_valid())
+ if (viewport.is_valid()) {
RenderingServer::get_singleton()->viewport_set_canvas_stacking(viewport, canvas, layer, get_index());
+ }
}
int CanvasLayer::get_layer() const {
@@ -44,8 +45,9 @@ int CanvasLayer::get_layer() const {
void CanvasLayer::set_transform(const Transform2D &p_xform) {
transform = p_xform;
locrotscale_dirty = true;
- if (viewport.is_valid())
+ if (viewport.is_valid()) {
RenderingServer::get_singleton()->viewport_set_canvas_transform(viewport, canvas, transform);
+ }
}
Transform2D CanvasLayer::get_transform() const {
@@ -55,8 +57,9 @@ Transform2D CanvasLayer::get_transform() const {
void CanvasLayer::_update_xform() {
transform.set_rotation_and_scale(rot, scale);
transform.set_origin(ofs);
- if (viewport.is_valid())
+ if (viewport.is_valid()) {
RenderingServer::get_singleton()->viewport_set_canvas_transform(viewport, canvas, transform);
+ }
}
void CanvasLayer::_update_locrotscale() {
@@ -67,31 +70,35 @@ void CanvasLayer::_update_locrotscale() {
}
void CanvasLayer::set_offset(const Vector2 &p_offset) {
- if (locrotscale_dirty)
+ if (locrotscale_dirty) {
_update_locrotscale();
+ }
ofs = p_offset;
_update_xform();
}
Vector2 CanvasLayer::get_offset() const {
- if (locrotscale_dirty)
+ if (locrotscale_dirty) {
const_cast<CanvasLayer *>(this)->_update_locrotscale();
+ }
return ofs;
}
void CanvasLayer::set_rotation(real_t p_radians) {
- if (locrotscale_dirty)
+ if (locrotscale_dirty) {
_update_locrotscale();
+ }
rot = p_radians;
_update_xform();
}
real_t CanvasLayer::get_rotation() const {
- if (locrotscale_dirty)
+ if (locrotscale_dirty) {
const_cast<CanvasLayer *>(this)->_update_locrotscale();
+ }
return rot;
}
@@ -105,16 +112,18 @@ real_t CanvasLayer::get_rotation_degrees() const {
}
void CanvasLayer::set_scale(const Vector2 &p_scale) {
- if (locrotscale_dirty)
+ if (locrotscale_dirty) {
_update_locrotscale();
+ }
scale = p_scale;
_update_xform();
}
Vector2 CanvasLayer::get_scale() const {
- if (locrotscale_dirty)
+ if (locrotscale_dirty) {
const_cast<CanvasLayer *>(this)->_update_locrotscale();
+ }
return scale;
}
@@ -146,16 +155,18 @@ void CanvasLayer::_notification(int p_what) {
} break;
case NOTIFICATION_MOVED_IN_PARENT: {
- if (is_inside_tree())
+ if (is_inside_tree()) {
RenderingServer::get_singleton()->viewport_set_canvas_stacking(viewport, canvas, layer, get_index());
+ }
} break;
}
}
Size2 CanvasLayer::get_viewport_size() const {
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return Size2(1, 1);
+ }
Rect2 r = vp->get_visible_rect();
return r.size;
@@ -182,10 +193,11 @@ void CanvasLayer::set_custom_viewport(Node *p_viewport) {
}
if (is_inside_tree()) {
- if (custom_viewport)
+ if (custom_viewport) {
vp = custom_viewport;
- else
+ } else {
vp = Node::get_viewport();
+ }
vp->_canvas_layer_add(this);
viewport = vp->get_viewport_rid();
diff --git a/scene/main/http_request.cpp b/scene/main/http_request.cpp
index 1603ad66be..82ee4dde50 100644
--- a/scene/main/http_request.cpp
+++ b/scene/main/http_request.cpp
@@ -94,8 +94,9 @@ Error HTTPRequest::request(const String &p_url, const Vector<String> &p_custom_h
method = p_method;
Error err = _parse_url(p_url);
- if (err)
+ if (err) {
return err;
+ }
validate_ssl = p_ssl_validate_domain;
@@ -134,8 +135,9 @@ void HTTPRequest::_thread_func(void *p_userdata) {
} else {
while (!hr->thread_request_quit) {
bool exit = hr->_update_connection();
- if (exit)
+ if (exit) {
break;
+ }
OS::get_singleton()->delay_usec(1);
}
}
@@ -146,8 +148,9 @@ void HTTPRequest::_thread_func(void *p_userdata) {
void HTTPRequest::cancel_request() {
timer->stop();
- if (!requesting)
+ if (!requesting) {
return;
+ }
if (!use_threads) {
set_process_internal(false);
@@ -266,8 +269,9 @@ bool HTTPRequest::_update_connection() {
bool ret_value;
- if (_handle_response(&ret_value))
+ if (_handle_response(&ret_value)) {
return ret_value;
+ }
call_deferred("_request_done", RESULT_SUCCESS, response_code, response_headers, PackedByteArray());
return true;
@@ -304,8 +308,9 @@ bool HTTPRequest::_update_connection() {
if (!got_response) {
bool ret_value;
- if (_handle_response(&ret_value))
+ if (_handle_response(&ret_value)) {
return ret_value;
+ }
if (!client->is_response_chunked() && client->get_response_body_length() == 0) {
call_deferred("_request_done", RESULT_SUCCESS, response_code, response_headers, PackedByteArray());
@@ -384,8 +389,9 @@ void HTTPRequest::_request_done(int p_status, int p_code, const PackedStringArra
void HTTPRequest::_notification(int p_what) {
if (p_what == NOTIFICATION_INTERNAL_PROCESS) {
- if (use_threads)
+ if (use_threads) {
return;
+ }
bool done = _update_connection();
if (done) {
set_process_internal(false);
@@ -556,6 +562,7 @@ HTTPRequest::HTTPRequest() {
}
HTTPRequest::~HTTPRequest() {
- if (file)
+ if (file) {
memdelete(file);
+ }
}
diff --git a/scene/main/instance_placeholder.cpp b/scene/main/instance_placeholder.cpp
index d81cd777d8..ca8d5a2ca0 100644
--- a/scene/main/instance_placeholder.cpp
+++ b/scene/main/instance_placeholder.cpp
@@ -74,20 +74,24 @@ Node *InstancePlaceholder::create_instance(bool p_replace, const Ref<PackedScene
ERR_FAIL_COND_V(!is_inside_tree(), nullptr);
Node *base = get_parent();
- if (!base)
+ if (!base) {
return nullptr;
+ }
Ref<PackedScene> ps;
- if (p_custom_scene.is_valid())
+ if (p_custom_scene.is_valid()) {
ps = p_custom_scene;
- else
+ } else {
ps = ResourceLoader::load(path, "PackedScene");
+ }
- if (!ps.is_valid())
+ if (!ps.is_valid()) {
return nullptr;
+ }
Node *scene = ps->instance();
- if (!scene)
+ if (!scene) {
return nullptr;
+ }
scene->set_name(get_name());
int pos = get_index();
@@ -112,12 +116,14 @@ Dictionary InstancePlaceholder::get_stored_values(bool p_with_order) {
for (List<PropSet>::Element *E = stored_values.front(); E; E = E->next()) {
ret[E->get().name] = E->get().value;
- if (p_with_order)
+ if (p_with_order) {
order.push_back(E->get().name);
+ }
};
- if (p_with_order)
+ if (p_with_order) {
ret[".order"] = order;
+ }
return ret;
};
diff --git a/scene/main/node.cpp b/scene/main/node.cpp
index 4e08057577..ad4d3c54be 100644
--- a/scene/main/node.cpp
+++ b/scene/main/node.cpp
@@ -72,20 +72,24 @@ void Node::_notification(int p_notification) {
ERR_FAIL_COND(!get_tree());
if (data.pause_mode == PAUSE_MODE_INHERIT) {
- if (data.parent)
+ if (data.parent) {
data.pause_owner = data.parent->data.pause_owner;
- else
+ } else {
data.pause_owner = nullptr;
+ }
} else {
data.pause_owner = this;
}
- if (data.input)
+ if (data.input) {
add_to_group("_vp_input" + itos(get_viewport()->get_instance_id()));
- if (data.unhandled_input)
+ }
+ if (data.unhandled_input) {
add_to_group("_vp_unhandled_input" + itos(get_viewport()->get_instance_id()));
- if (data.unhandled_key_input)
+ }
+ if (data.unhandled_key_input) {
add_to_group("_vp_unhandled_key_input" + itos(get_viewport()->get_instance_id()));
+ }
get_tree()->node_count++;
orphan_node_count--;
@@ -98,12 +102,15 @@ void Node::_notification(int p_notification) {
get_tree()->node_count--;
orphan_node_count++;
- if (data.input)
+ if (data.input) {
remove_from_group("_vp_input" + itos(get_viewport()->get_instance_id()));
- if (data.unhandled_input)
+ }
+ if (data.unhandled_input) {
remove_from_group("_vp_unhandled_input" + itos(get_viewport()->get_instance_id()));
- if (data.unhandled_key_input)
+ }
+ if (data.unhandled_key_input) {
remove_from_group("_vp_unhandled_key_input" + itos(get_viewport()->get_instance_id()));
+ }
data.pause_owner = nullptr;
if (data.path_cache) {
@@ -196,8 +203,9 @@ void Node::_propagate_enter_tree() {
}
data.viewport = Object::cast_to<Viewport>(this);
- if (!data.viewport && data.parent)
+ if (!data.viewport && data.parent) {
data.viewport = data.parent->data.viewport;
+ }
data.inside_tree = true;
@@ -219,8 +227,9 @@ void Node::_propagate_enter_tree() {
//block while adding children
for (int i = 0; i < data.children.size(); i++) {
- if (!data.children[i]->is_inside_tree()) // could have been added in enter_tree
+ if (!data.children[i]->is_inside_tree()) { // could have been added in enter_tree
data.children[i]->_propagate_enter_tree();
+ }
}
data.blocked--;
@@ -260,8 +269,9 @@ void Node::_propagate_exit_tree() {
emit_signal(SceneStringNames::get_singleton()->tree_exiting);
notification(NOTIFICATION_EXIT_TREE, true);
- if (data.tree)
+ if (data.tree) {
data.tree->node_removed(this);
+ }
// exit groups
@@ -272,8 +282,9 @@ void Node::_propagate_exit_tree() {
data.viewport = nullptr;
- if (data.tree)
+ if (data.tree) {
data.tree->tree_changed();
+ }
data.inside_tree = false;
data.ready_notified = false;
@@ -289,11 +300,13 @@ void Node::move_child(Node *p_child, int p_pos) {
// Specifying one place beyond the end
// means the same as moving to the last position
- if (p_pos == data.children.size())
+ if (p_pos == data.children.size()) {
p_pos--;
+ }
- if (p_child->data.pos == p_pos)
+ if (p_child->data.pos == p_pos) {
return; //do nothing
+ }
int motion_from = MIN(p_pos, p_child->data.pos);
int motion_to = MAX(p_pos, p_child->data.pos);
@@ -316,16 +329,18 @@ void Node::move_child(Node *p_child, int p_pos) {
data.children[i]->notification(NOTIFICATION_MOVED_IN_PARENT);
}
for (const Map<StringName, GroupData>::Element *E = p_child->data.grouped.front(); E; E = E->next()) {
- if (E->get().group)
+ if (E->get().group) {
E->get().group->changed = true;
+ }
}
data.blocked--;
}
void Node::raise() {
- if (!data.parent)
+ if (!data.parent) {
return;
+ }
data.parent->move_child(this, data.parent->data.children.size() - 1);
}
@@ -343,15 +358,17 @@ void Node::move_child_notify(Node *p_child) {
}
void Node::set_physics_process(bool p_process) {
- if (data.physics_process == p_process)
+ if (data.physics_process == p_process) {
return;
+ }
data.physics_process = p_process;
- if (data.physics_process)
+ if (data.physics_process) {
add_to_group("physics_process", false);
- else
+ } else {
remove_from_group("physics_process");
+ }
_change_notify("physics_process");
}
@@ -361,15 +378,17 @@ bool Node::is_physics_processing() const {
}
void Node::set_physics_process_internal(bool p_process_internal) {
- if (data.physics_process_internal == p_process_internal)
+ if (data.physics_process_internal == p_process_internal) {
return;
+ }
data.physics_process_internal = p_process_internal;
- if (data.physics_process_internal)
+ if (data.physics_process_internal) {
add_to_group("physics_process_internal", false);
- else
+ } else {
remove_from_group("physics_process_internal");
+ }
_change_notify("physics_process_internal");
}
@@ -379,21 +398,25 @@ bool Node::is_physics_processing_internal() const {
}
void Node::set_pause_mode(PauseMode p_mode) {
- if (data.pause_mode == p_mode)
+ if (data.pause_mode == p_mode) {
return;
+ }
bool prev_inherits = data.pause_mode == PAUSE_MODE_INHERIT;
data.pause_mode = p_mode;
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return; //pointless
- if ((data.pause_mode == PAUSE_MODE_INHERIT) == prev_inherits)
+ }
+ if ((data.pause_mode == PAUSE_MODE_INHERIT) == prev_inherits) {
return; ///nothing changed
+ }
Node *owner = nullptr;
if (data.pause_mode == PAUSE_MODE_INHERIT) {
- if (data.parent)
+ if (data.parent) {
owner = data.parent->data.pause_owner;
+ }
} else {
owner = this;
}
@@ -406,8 +429,9 @@ Node::PauseMode Node::get_pause_mode() const {
}
void Node::_propagate_pause_owner(Node *p_owner) {
- if (this != p_owner && data.pause_mode != PAUSE_MODE_INHERIT)
+ if (this != p_owner && data.pause_mode != PAUSE_MODE_INHERIT) {
return;
+ }
data.pause_owner = p_owner;
for (int i = 0; i < data.children.size(); i++) {
data.children[i]->_propagate_pause_owner(p_owner);
@@ -475,8 +499,9 @@ void Node::rpc(const StringName &p_method, VARIANT_ARG_DECLARE) {
int argc = 0;
for (int i = 0; i < VARIANT_ARG_MAX; i++) {
- if (argptr[i]->get_type() == Variant::NIL)
+ if (argptr[i]->get_type() == Variant::NIL) {
break;
+ }
argc++;
}
@@ -488,8 +513,9 @@ void Node::rpc_id(int p_peer_id, const StringName &p_method, VARIANT_ARG_DECLARE
int argc = 0;
for (int i = 0; i < VARIANT_ARG_MAX; i++) {
- if (argptr[i]->get_type() == Variant::NIL)
+ if (argptr[i]->get_type() == Variant::NIL) {
break;
+ }
argc++;
}
@@ -501,8 +527,9 @@ void Node::rpc_unreliable(const StringName &p_method, VARIANT_ARG_DECLARE) {
int argc = 0;
for (int i = 0; i < VARIANT_ARG_MAX; i++) {
- if (argptr[i]->get_type() == Variant::NIL)
+ if (argptr[i]->get_type() == Variant::NIL) {
break;
+ }
argc++;
}
@@ -514,8 +541,9 @@ void Node::rpc_unreliable_id(int p_peer_id, const StringName &p_method, VARIANT_
int argc = 0;
for (int i = 0; i < VARIANT_ARG_MAX; i++) {
- if (argptr[i]->get_type() == Variant::NIL)
+ if (argptr[i]->get_type() == Variant::NIL) {
break;
+ }
argc++;
}
@@ -655,10 +683,12 @@ void Node::rset_unreliable_id(int p_peer_id, const StringName &p_property, const
//////////// end of rpc
Ref<MultiplayerAPI> Node::get_multiplayer() const {
- if (multiplayer.is_valid())
+ if (multiplayer.is_valid()) {
return multiplayer;
- if (!is_inside_tree())
+ }
+ if (!is_inside_tree()) {
return Ref<MultiplayerAPI>();
+ }
return get_tree()->get_multiplayer();
}
@@ -685,8 +715,9 @@ StringName Node::get_node_rpc_method(const uint16_t p_rpc_method_id) const {
// Make sure this is a node generated ID.
if (((1 << 15) & p_rpc_method_id) > 0) {
int mid = (~(1 << 15)) & p_rpc_method_id;
- if (mid < data.rpc_methods.size())
+ if (mid < data.rpc_methods.size()) {
return data.rpc_methods[mid].name;
+ }
}
return StringName();
}
@@ -695,8 +726,9 @@ MultiplayerAPI::RPCMode Node::get_node_rpc_mode_by_id(const uint16_t p_rpc_metho
// Make sure this is a node generated ID.
if (((1 << 15) & p_rpc_method_id) > 0) {
int mid = (~(1 << 15)) & p_rpc_method_id;
- if (mid < data.rpc_methods.size())
+ if (mid < data.rpc_methods.size()) {
return data.rpc_methods[mid].mode;
+ }
}
return MultiplayerAPI::RPC_MODE_DISABLED;
}
@@ -720,8 +752,9 @@ StringName Node::get_node_rset_property(const uint16_t p_rset_property_id) const
// Make sure this is a node generated ID.
if (((1 << 15) & p_rset_property_id) > 0) {
int mid = (~(1 << 15)) & p_rset_property_id;
- if (mid < data.rpc_properties.size())
+ if (mid < data.rpc_properties.size()) {
return data.rpc_properties[mid].name;
+ }
}
return StringName();
}
@@ -729,8 +762,9 @@ StringName Node::get_node_rset_property(const uint16_t p_rset_property_id) const
MultiplayerAPI::RPCMode Node::get_node_rset_mode_by_id(const uint16_t p_rset_property_id) const {
if (((1 << 15) & p_rset_property_id) > 0) {
int mid = (~(1 << 15)) & p_rset_property_id;
- if (mid < data.rpc_properties.size())
+ if (mid < data.rpc_properties.size()) {
return data.rpc_properties[mid].mode;
+ }
}
return MultiplayerAPI::RPC_MODE_DISABLED;
}
@@ -779,19 +813,24 @@ bool Node::can_process() const {
ERR_FAIL_COND_V(!is_inside_tree(), false);
if (get_tree()->is_paused()) {
- if (data.pause_mode == PAUSE_MODE_STOP)
+ if (data.pause_mode == PAUSE_MODE_STOP) {
return false;
- if (data.pause_mode == PAUSE_MODE_PROCESS)
+ }
+ if (data.pause_mode == PAUSE_MODE_PROCESS) {
return true;
+ }
if (data.pause_mode == PAUSE_MODE_INHERIT) {
- if (!data.pause_owner)
+ if (!data.pause_owner) {
return false; //clearly no pause owner by default
+ }
- if (data.pause_owner->data.pause_mode == PAUSE_MODE_PROCESS)
+ if (data.pause_owner->data.pause_mode == PAUSE_MODE_PROCESS) {
return true;
+ }
- if (data.pause_owner->data.pause_mode == PAUSE_MODE_STOP)
+ if (data.pause_owner->data.pause_mode == PAUSE_MODE_STOP) {
return false;
+ }
}
}
@@ -799,29 +838,33 @@ bool Node::can_process() const {
}
float Node::get_physics_process_delta_time() const {
- if (data.tree)
+ if (data.tree) {
return data.tree->get_physics_process_time();
- else
+ } else {
return 0;
+ }
}
float Node::get_process_delta_time() const {
- if (data.tree)
+ if (data.tree) {
return data.tree->get_idle_process_time();
- else
+ } else {
return 0;
+ }
}
void Node::set_process(bool p_idle_process) {
- if (data.idle_process == p_idle_process)
+ if (data.idle_process == p_idle_process) {
return;
+ }
data.idle_process = p_idle_process;
- if (data.idle_process)
+ if (data.idle_process) {
add_to_group("idle_process", false);
- else
+ } else {
remove_from_group("idle_process");
+ }
_change_notify("idle_process");
}
@@ -831,15 +874,17 @@ bool Node::is_processing() const {
}
void Node::set_process_internal(bool p_idle_process_internal) {
- if (data.idle_process_internal == p_idle_process_internal)
+ if (data.idle_process_internal == p_idle_process_internal) {
return;
+ }
data.idle_process_internal = p_idle_process_internal;
- if (data.idle_process_internal)
+ if (data.idle_process_internal) {
add_to_group("idle_process_internal", false);
- else
+ } else {
remove_from_group("idle_process_internal");
+ }
_change_notify("idle_process_internal");
}
@@ -878,17 +923,20 @@ int Node::get_process_priority() const {
}
void Node::set_process_input(bool p_enable) {
- if (p_enable == data.input)
+ if (p_enable == data.input) {
return;
+ }
data.input = p_enable;
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
- if (p_enable)
+ if (p_enable) {
add_to_group("_vp_input" + itos(get_viewport()->get_instance_id()));
- else
+ } else {
remove_from_group("_vp_input" + itos(get_viewport()->get_instance_id()));
+ }
}
bool Node::is_processing_input() const {
@@ -896,16 +944,19 @@ bool Node::is_processing_input() const {
}
void Node::set_process_unhandled_input(bool p_enable) {
- if (p_enable == data.unhandled_input)
+ if (p_enable == data.unhandled_input) {
return;
+ }
data.unhandled_input = p_enable;
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
- if (p_enable)
+ if (p_enable) {
add_to_group("_vp_unhandled_input" + itos(get_viewport()->get_instance_id()));
- else
+ } else {
remove_from_group("_vp_unhandled_input" + itos(get_viewport()->get_instance_id()));
+ }
}
bool Node::is_processing_unhandled_input() const {
@@ -913,16 +964,19 @@ bool Node::is_processing_unhandled_input() const {
}
void Node::set_process_unhandled_key_input(bool p_enable) {
- if (p_enable == data.unhandled_key_input)
+ if (p_enable == data.unhandled_key_input) {
return;
+ }
data.unhandled_key_input = p_enable;
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
- if (p_enable)
+ if (p_enable) {
add_to_group("_vp_unhandled_key_input" + itos(get_viewport()->get_instance_id()));
- else
+ } else {
remove_from_group("_vp_unhandled_key_input" + itos(get_viewport()->get_instance_id()));
+ }
}
bool Node::is_processing_unhandled_key_input() const {
@@ -1015,8 +1069,9 @@ void Node::_validate_child_name(Node *p_child, bool p_force_human_readable) {
int cc = data.children.size();
for (int i = 0; i < cc; i++) {
- if (children[i] == p_child)
+ if (children[i] == p_child) {
continue;
+ }
if (children[i]->data.name == p_child->data.name) {
unique = false;
break;
@@ -1288,8 +1343,9 @@ Node *Node::_get_child_by_name(const StringName &p_name) const {
Node *const *cd = data.children.ptr();
for (int i = 0; i < cc; i++) {
- if (cd[i]->data.name == p_name)
+ if (cd[i]->data.name == p_name) {
return cd[i];
+ }
}
return nullptr;
@@ -1309,8 +1365,9 @@ Node *Node::get_node_or_null(const NodePath &p_path) const {
current = const_cast<Node *>(this); //start from this
} else {
root = const_cast<Node *>(this);
- while (root->data.parent)
+ while (root->data.parent) {
root = root->data.parent; //start from root
+ }
}
for (int i = 0; i < p_path.get_name_count(); i++) {
@@ -1323,13 +1380,15 @@ Node *Node::get_node_or_null(const NodePath &p_path) const {
} else if (name == SceneStringNames::get_singleton()->doubledot) { // ..
- if (current == nullptr || !current->data.parent)
+ if (current == nullptr || !current->data.parent) {
return nullptr;
+ }
next = current->data.parent;
} else if (current == nullptr) {
- if (name == root->get_name())
+ if (name == root->get_name()) {
next = root;
+ }
} else {
next = nullptr;
@@ -1366,17 +1425,21 @@ Node *Node::find_node(const String &p_mask, bool p_recursive, bool p_owned) cons
Node *const *cptr = data.children.ptr();
int ccount = data.children.size();
for (int i = 0; i < ccount; i++) {
- if (p_owned && !cptr[i]->data.owner)
+ if (p_owned && !cptr[i]->data.owner) {
continue;
- if (cptr[i]->data.name.operator String().match(p_mask))
+ }
+ if (cptr[i]->data.name.operator String().match(p_mask)) {
return cptr[i];
+ }
- if (!p_recursive)
+ if (!p_recursive) {
continue;
+ }
Node *ret = cptr[i]->find_node(p_mask, true, p_owned);
- if (ret)
+ if (ret) {
return ret;
+ }
}
return nullptr;
}
@@ -1388,8 +1451,9 @@ Node *Node::get_parent() const {
Node *Node::find_parent(const String &p_mask) const {
Node *p = data.parent;
while (p) {
- if (p->data.name.operator String().match(p_mask))
+ if (p->data.name.operator String().match(p_mask)) {
return p;
+ }
p = p->data.parent;
}
@@ -1400,8 +1464,9 @@ bool Node::is_a_parent_of(const Node *p_node) const {
ERR_FAIL_NULL_V(p_node, false);
Node *p = p_node->data.parent;
while (p) {
- if (p == this)
+ if (p == this) {
return true;
+ }
p = p->data.parent;
}
@@ -1472,16 +1537,19 @@ bool Node::is_greater_than(const Node *p_node) const {
}
void Node::get_owned_by(Node *p_by, List<Node *> *p_owned) {
- if (data.owner == p_by)
+ if (data.owner == p_by) {
p_owned->push_back(this);
+ }
- for (int i = 0; i < get_child_count(); i++)
+ for (int i = 0; i < get_child_count(); i++) {
get_child(i)->get_owned_by(p_by, p_owned);
+ }
}
void Node::_set_owner_nocheck(Node *p_owner) {
- if (data.owner == p_owner)
+ if (data.owner == p_owner) {
return;
+ }
ERR_FAIL_COND(data.owner);
data.owner = p_owner;
@@ -1498,8 +1566,9 @@ void Node::set_owner(Node *p_owner) {
ERR_FAIL_COND(p_owner == this);
- if (!p_owner)
+ if (!p_owner) {
return;
+ }
Node *check = this->get_parent();
bool owner_valid = false;
@@ -1523,8 +1592,9 @@ Node *Node::get_owner() const {
}
Node *Node::find_common_parent_with(const Node *p_node) const {
- if (this == p_node)
+ if (this == p_node) {
return const_cast<Node *>(p_node);
+ }
Set<const Node *> visited;
@@ -1538,13 +1608,15 @@ Node *Node::find_common_parent_with(const Node *p_node) const {
const Node *common_parent = p_node;
while (common_parent) {
- if (visited.has(common_parent))
+ if (visited.has(common_parent)) {
break;
+ }
common_parent = common_parent->data.parent;
}
- if (!common_parent)
+ if (!common_parent) {
return nullptr;
+ }
return const_cast<Node *>(common_parent);
}
@@ -1552,8 +1624,9 @@ Node *Node::find_common_parent_with(const Node *p_node) const {
NodePath Node::get_path_to(const Node *p_node) const {
ERR_FAIL_NULL_V(p_node, NodePath());
- if (this == p_node)
+ if (this == p_node) {
return NodePath(".");
+ }
Set<const Node *> visited;
@@ -1567,8 +1640,9 @@ NodePath Node::get_path_to(const Node *p_node) const {
const Node *common_parent = p_node;
while (common_parent) {
- if (visited.has(common_parent))
+ if (visited.has(common_parent)) {
break;
+ }
common_parent = common_parent->data.parent;
}
@@ -1601,8 +1675,9 @@ NodePath Node::get_path_to(const Node *p_node) const {
NodePath Node::get_path() const {
ERR_FAIL_COND_V_MSG(!is_inside_tree(), NodePath(), "Cannot get path of node as it is not in a scene tree.");
- if (data.path_cache)
+ if (data.path_cache) {
return *data.path_cache;
+ }
const Node *n = this;
@@ -1627,8 +1702,9 @@ bool Node::is_in_group(const StringName &p_identifier) const {
void Node::add_to_group(const StringName &p_identifier, bool p_persistent) {
ERR_FAIL_COND(!p_identifier.operator String().length());
- if (data.grouped.has(p_identifier))
+ if (data.grouped.has(p_identifier)) {
return;
+ }
GroupData gd;
@@ -1650,8 +1726,9 @@ void Node::remove_from_group(const StringName &p_identifier) {
ERR_FAIL_COND(!E);
- if (data.tree)
+ if (data.tree) {
data.tree->remove_from_group(E->key(), this);
+ }
data.grouped.erase(E);
}
@@ -1707,8 +1784,9 @@ void Node::print_tree() {
void Node::_print_tree(const Node *p_node) {
print_line(String(p_node->get_path_to(this)));
- for (int i = 0; i < data.children.size(); i++)
+ for (int i = 0; i < data.children.size(); i++) {
data.children[i]->_print_tree(p_node);
+ }
}
void Node::_propagate_reverse_notification(int p_notification) {
@@ -1726,15 +1804,17 @@ void Node::_propagate_deferred_notification(int p_notification, bool p_reverse)
data.blocked++;
- if (!p_reverse)
+ if (!p_reverse) {
MessageQueue::get_singleton()->push_notification(this, p_notification);
+ }
for (int i = 0; i < data.children.size(); i++) {
data.children[i]->_propagate_deferred_notification(p_notification, p_reverse);
}
- if (p_reverse)
+ if (p_reverse) {
MessageQueue::get_singleton()->push_notification(this, p_notification);
+ }
data.blocked--;
}
@@ -1752,26 +1832,30 @@ void Node::propagate_notification(int p_notification) {
void Node::propagate_call(const StringName &p_method, const Array &p_args, const bool p_parent_first) {
data.blocked++;
- if (p_parent_first && has_method(p_method))
+ if (p_parent_first && has_method(p_method)) {
callv(p_method, p_args);
+ }
for (int i = 0; i < data.children.size(); i++) {
data.children[i]->propagate_call(p_method, p_args, p_parent_first);
}
- if (!p_parent_first && has_method(p_method))
+ if (!p_parent_first && has_method(p_method)) {
callv(p_method, p_args);
+ }
data.blocked--;
}
void Node::_propagate_replace_owner(Node *p_owner, Node *p_by_owner) {
- if (get_owner() == p_owner)
+ if (get_owner() == p_owner) {
set_owner(p_by_owner);
+ }
data.blocked++;
- for (int i = 0; i < data.children.size(); i++)
+ for (int i = 0; i < data.children.size(); i++) {
data.children[i]->_propagate_replace_owner(p_owner, p_by_owner);
+ }
data.blocked--;
}
@@ -1790,8 +1874,9 @@ void Node::remove_and_skip() {
bool clear = true;
for (int i = 0; i < data.children.size(); i++) {
Node *c_node = data.children[i];
- if (!c_node->get_owner())
+ if (!c_node->get_owner()) {
continue;
+ }
remove_child(c_node);
c_node->_propagate_replace_owner(this, nullptr);
@@ -1800,8 +1885,9 @@ void Node::remove_and_skip() {
break;
}
- if (clear)
+ if (clear) {
break;
+ }
}
while (!children.empty()) {
@@ -1849,8 +1935,9 @@ void Node::set_editable_instance(Node *p_node, bool p_editable) {
}
bool Node::is_editable_instance(const Node *p_node) const {
- if (!p_node)
+ if (!p_node) {
return false; //easier, null is never editable :)
+ }
ERR_FAIL_COND_V(!is_a_parent_of(p_node), false);
NodePath p = get_path_to(p_node);
return data.editable_instances.has(p);
@@ -1904,8 +1991,9 @@ Node *Node::_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap) const
ERR_FAIL_COND_V(res.is_null(), nullptr);
PackedScene::GenEditState ges = PackedScene::GEN_EDIT_STATE_DISABLED;
#ifdef TOOLS_ENABLED
- if (p_flags & DUPLICATE_FROM_EDITOR)
+ if (p_flags & DUPLICATE_FROM_EDITOR) {
ges = PackedScene::GEN_EDIT_STATE_INSTANCE;
+ }
#endif
node = res->instance(ges);
ERR_FAIL_COND_V(!node, nullptr);
@@ -1916,8 +2004,9 @@ Node *Node::_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap) const
Object *obj = ClassDB::instance(get_class());
ERR_FAIL_COND_V(!obj, nullptr);
node = Object::cast_to<Node>(obj);
- if (!node)
+ if (!node) {
memdelete(obj);
+ }
ERR_FAIL_COND_V(!node, nullptr);
}
@@ -1941,8 +2030,9 @@ Node *Node::_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap) const
// Skip nodes not really belonging to the instanced hierarchy; they'll be processed normally later
// but remember non-instanced nodes that are hidden below instanced ones
if (descendant->data.owner != this) {
- if (descendant->get_parent() && descendant->get_parent() != this && descendant->get_parent()->data.owner == this && descendant->data.owner != descendant->get_parent())
+ if (descendant->get_parent() && descendant->get_parent() != this && descendant->get_parent()->data.owner == this && descendant->data.owner != descendant->get_parent()) {
hidden_roots.push_back(descendant);
+ }
continue;
}
@@ -1967,11 +2057,13 @@ Node *Node::_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap) const
N->get()->get_property_list(&plist);
for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) {
- if (!(E->get().usage & PROPERTY_USAGE_STORAGE))
+ if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) {
continue;
+ }
String name = E->get().name;
- if (name == script_property_name)
+ if (name == script_property_name) {
continue;
+ }
Variant value = N->get()->get(name).duplicate(true);
@@ -1992,8 +2084,9 @@ Node *Node::_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap) const
}
#ifdef TOOLS_ENABLED
- if ((p_flags & DUPLICATE_FROM_EDITOR) && r_duplimap)
+ if ((p_flags & DUPLICATE_FROM_EDITOR) && r_duplimap) {
r_duplimap->insert(this, node);
+ }
#endif
if (p_flags & DUPLICATE_GROUPS) {
@@ -2001,8 +2094,9 @@ Node *Node::_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap) const
get_groups(&gi);
for (List<GroupInfo>::Element *E = gi.front(); E; E = E->next()) {
#ifdef TOOLS_ENABLED
- if ((p_flags & DUPLICATE_FROM_EDITOR) && !E->get().persistent)
+ if ((p_flags & DUPLICATE_FROM_EDITOR) && !E->get().persistent) {
continue;
+ }
#endif
node->add_to_group(E->get().name, E->get().persistent);
@@ -2010,10 +2104,12 @@ Node *Node::_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap) const
}
for (int i = 0; i < get_child_count(); i++) {
- if (get_child(i)->data.parent_owned)
+ if (get_child(i)->data.parent_owned) {
continue;
- if (instanced && get_child(i)->data.owner == this)
+ }
+ if (instanced && get_child(i)->data.owner == this) {
continue; //part of instance
+ }
Node *dup = get_child(i)->_duplicate(p_flags, r_duplimap);
if (!dup) {
@@ -2075,8 +2171,9 @@ Node *Node::duplicate_from_editor(Map<const Node *, Node *> &r_duplimap) const {
#endif
void Node::_duplicate_and_reown(Node *p_new_parent, const Map<Node *, Node *> &p_reown_map) const {
- if (get_owner() != get_parent()->get_owner())
+ if (get_owner() != get_parent()->get_owner()) {
return;
+ }
Node *node = nullptr;
@@ -2100,8 +2197,9 @@ void Node::_duplicate_and_reown(Node *p_new_parent, const Map<Node *, Node *> &p
get_property_list(&plist);
for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) {
- if (!(E->get().usage & PROPERTY_USAGE_STORAGE))
+ if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) {
continue;
+ }
String name = E->get().name;
Variant value = get(name).duplicate(true);
@@ -2112,16 +2210,18 @@ void Node::_duplicate_and_reown(Node *p_new_parent, const Map<Node *, Node *> &p
List<GroupInfo> groups;
get_groups(&groups);
- for (List<GroupInfo>::Element *E = groups.front(); E; E = E->next())
+ for (List<GroupInfo>::Element *E = groups.front(); E; E = E->next()) {
node->add_to_group(E->get().name, E->get().persistent);
+ }
node->set_name(get_name());
p_new_parent->add_child(node);
Node *owner = get_owner();
- if (p_reown_map.has(owner))
+ if (p_reown_map.has(owner)) {
owner = p_reown_map[owner];
+ }
if (owner) {
NodePath p = get_path_to(owner);
@@ -2142,8 +2242,9 @@ void Node::_duplicate_and_reown(Node *p_new_parent, const Map<Node *, Node *> &p
// because re-targeting of connections from some descendant to another is not possible
// if the emitter node comes later in tree order than the receiver
void Node::_duplicate_signals(const Node *p_original, Node *p_copy) const {
- if (this != p_original && (get_owner() != p_original && get_owner() != p_original->get_owner()))
+ if (this != p_original && (get_owner() != p_original && get_owner() != p_original->get_owner())) {
return;
+ }
List<Connection> conns;
get_all_signal_connections(&conns);
@@ -2166,8 +2267,9 @@ void Node::_duplicate_signals(const Node *p_original, Node *p_copy) const {
// of the duplicated and not yet parented hierarchy then at least try to connect
// to the same target as the original
- if (p_copy->has_node(ptarget))
+ if (p_copy->has_node(ptarget)) {
copytarget = p_copy->get_node(ptarget);
+ }
if (copy && copytarget) {
const Callable copy_callable = Callable(copytarget, E->get().callable.get_method());
@@ -2201,8 +2303,9 @@ Node *Node::duplicate_and_reown(const Map<Node *, Node *> &p_reown_map) const {
get_property_list(&plist);
for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) {
- if (!(E->get().usage & PROPERTY_USAGE_STORAGE))
+ if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) {
continue;
+ }
String name = E->get().name;
node->set(name, get(name));
}
@@ -2210,8 +2313,9 @@ Node *Node::duplicate_and_reown(const Map<Node *, Node *> &p_reown_map) const {
List<GroupInfo> groups;
get_groups(&groups);
- for (List<GroupInfo>::Element *E = groups.front(); E; E = E->next())
+ for (List<GroupInfo>::Element *E = groups.front(); E; E = E->next()) {
node->add_to_group(E->get().name, E->get().persistent);
+ }
for (int i = 0; i < get_child_count(); i++) {
get_child(i)->_duplicate_and_reown(node, p_reown_map);
@@ -2225,8 +2329,9 @@ Node *Node::duplicate_and_reown(const Map<Node *, Node *> &p_reown_map) const {
}
static void find_owned_by(Node *p_by, Node *p_node, List<Node *> *p_owned) {
- if (p_node->get_owner() == p_by)
+ if (p_node->get_owner() == p_by) {
p_owned->push_back(p_node);
+ }
for (int i = 0; i < p_node->get_child_count(); i++) {
find_owned_by(p_by, p_node->get_child(i), p_owned);
@@ -2254,8 +2359,9 @@ void Node::replace_by(Node *p_node, bool p_keep_data) {
for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) {
_NodeReplaceByPair rd;
- if (!(E->get().usage & PROPERTY_USAGE_STORAGE))
+ if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) {
continue;
+ }
rd.name = E->get().name;
rd.value = get(rd.name);
}
@@ -2263,15 +2369,17 @@ void Node::replace_by(Node *p_node, bool p_keep_data) {
List<GroupInfo> groups;
get_groups(&groups);
- for (List<GroupInfo>::Element *E = groups.front(); E; E = E->next())
+ for (List<GroupInfo>::Element *E = groups.front(); E; E = E->next()) {
p_node->add_to_group(E->get().name, E->get().persistent);
+ }
}
_replace_connections_target(p_node);
if (data.owner) {
- for (int i = 0; i < get_child_count(); i++)
+ for (int i = 0; i < get_child_count(); i++) {
find_owned_by(data.owner, get_child(i), &owned_by_owner);
+ }
}
Node *parent = data.parent;
@@ -2293,11 +2401,13 @@ void Node::replace_by(Node *p_node, bool p_keep_data) {
}
p_node->set_owner(owner);
- for (int i = 0; i < owned.size(); i++)
+ for (int i = 0; i < owned.size(); i++) {
owned[i]->set_owner(p_node);
+ }
- for (int i = 0; i < owned_by_owner.size(); i++)
+ for (int i = 0; i < owned_by_owner.size(); i++) {
owned_by_owner[i]->set_owner(owner);
+ }
p_node->set_filename(get_filename());
@@ -2325,37 +2435,43 @@ void Node::_replace_connections_target(Node *p_new_target) {
Vector<Variant> Node::make_binds(VARIANT_ARG_DECLARE) {
Vector<Variant> ret;
- if (p_arg1.get_type() == Variant::NIL)
+ if (p_arg1.get_type() == Variant::NIL) {
return ret;
- else
+ } else {
ret.push_back(p_arg1);
+ }
- if (p_arg2.get_type() == Variant::NIL)
+ if (p_arg2.get_type() == Variant::NIL) {
return ret;
- else
+ } else {
ret.push_back(p_arg2);
+ }
- if (p_arg3.get_type() == Variant::NIL)
+ if (p_arg3.get_type() == Variant::NIL) {
return ret;
- else
+ } else {
ret.push_back(p_arg3);
+ }
- if (p_arg4.get_type() == Variant::NIL)
+ if (p_arg4.get_type() == Variant::NIL) {
return ret;
- else
+ } else {
ret.push_back(p_arg4);
+ }
- if (p_arg5.get_type() == Variant::NIL)
+ if (p_arg5.get_type() == Variant::NIL) {
return ret;
- else
+ } else {
ret.push_back(p_arg5);
+ }
return ret;
}
bool Node::has_node_and_resource(const NodePath &p_path) const {
- if (!has_node(p_path))
+ if (!has_node(p_path)) {
return false;
+ }
RES res;
Vector<StringName> leftover_path;
Node *node = get_node_and_resource(p_path, res, leftover_path, false);
@@ -2369,15 +2485,17 @@ Array Node::_get_node_and_resource(const NodePath &p_path) {
Node *node = get_node_and_resource(p_path, res, leftover_path, false);
Array result;
- if (node)
+ if (node) {
result.push_back(node);
- else
+ } else {
result.push_back(Variant());
+ }
- if (res.is_valid())
+ if (res.is_valid()) {
result.push_back(res);
- else
+ } else {
result.push_back(Variant());
+ }
result.push_back(NodePath(Vector<StringName>(), leftover_path, false));
@@ -2388,8 +2506,9 @@ Node *Node::get_node_and_resource(const NodePath &p_path, RES &r_res, Vector<Str
Node *node = get_node(p_path);
r_res = RES();
r_leftover_subpath = Vector<StringName>();
- if (!node)
+ if (!node) {
return nullptr;
+ }
if (p_path.get_subname_count()) {
int j = 0;
@@ -2441,20 +2560,24 @@ void Node::_set_tree(SceneTree *p_tree) {
tree_changed_b = data.tree;
}
- if (tree_changed_a)
+ if (tree_changed_a) {
tree_changed_a->tree_changed();
- if (tree_changed_b)
+ }
+ if (tree_changed_b) {
tree_changed_b->tree_changed();
+ }
}
#ifdef DEBUG_ENABLED
static void _Node_debug_sn(Object *p_obj) {
Node *n = Object::cast_to<Node>(p_obj);
- if (!n)
+ if (!n) {
return;
+ }
- if (n->is_inside_tree())
+ if (n->is_inside_tree()) {
return;
+ }
Node *p = n;
while (p->get_parent()) {
@@ -2462,10 +2585,11 @@ static void _Node_debug_sn(Object *p_obj) {
}
String path;
- if (p == n)
+ if (p == n) {
path = n->get_name();
- else
+ } else {
path = String(p->get_name()) + "/" + p->get_path_to(n);
+ }
print_line(itos(p_obj->get_instance_id()) + " - Stray Node: " + path + " (Type: " + n->get_class() + ")");
}
#endif // DEBUG_ENABLED
@@ -2492,8 +2616,9 @@ TypedArray<Node> Node::_get_children() const {
TypedArray<Node> arr;
int cc = get_child_count();
arr.resize(cc);
- for (int i = 0; i < cc; i++)
+ for (int i = 0; i < cc; i++) {
arr[i] = get_child(i);
+ }
return arr;
}
@@ -2519,8 +2644,9 @@ static void _add_nodes_to_options(const Node *p_base, const Node *p_node, List<S
const String quote_style = "\"";
#endif
- if (p_node != p_base && !p_node->get_owner())
+ if (p_node != p_base && !p_node->get_owner()) {
return;
+ }
String n = p_base->get_path_to(p_node);
r_options->push_back(quote_style + n + quote_style);
for (int i = 0; i < p_node->get_child_count(); i++) {
@@ -2553,8 +2679,9 @@ String Node::get_configuration_warning() const {
void Node::update_configuration_warning() {
#ifdef TOOLS_ENABLED
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
if (get_tree()->get_edited_scene_root() && (get_tree()->get_edited_scene_root() == this || get_tree()->get_edited_scene_root()->is_a_parent_of(this))) {
get_tree()->emit_signal(SceneStringNames::get_singleton()->node_configuration_warning_changed, this);
}
diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp
index 41fc830f48..a0e10f30c0 100644
--- a/scene/main/scene_tree.cpp
+++ b/scene/main/scene_tree.cpp
@@ -109,8 +109,9 @@ void SceneTree::node_removed(Node *p_node) {
current_scene = nullptr;
}
emit_signal(node_removed_name, p_node);
- if (call_lock > 0)
+ if (call_lock > 0) {
call_skip.insert(p_node);
+ }
}
void SceneTree::node_renamed(Node *p_node) {
@@ -135,14 +136,16 @@ void SceneTree::remove_from_group(const StringName &p_group, Node *p_node) {
ERR_FAIL_COND(!E);
E->get().nodes.erase(p_node);
- if (E->get().nodes.empty())
+ if (E->get().nodes.empty()) {
group_map.erase(E);
+ }
}
void SceneTree::make_group_changed(const StringName &p_group) {
Map<StringName, Group>::Element *E = group_map.find(p_group);
- if (E)
+ if (E) {
E->get().changed = true;
+ }
}
void SceneTree::flush_transform_notifications() {
@@ -163,8 +166,9 @@ void SceneTree::_flush_ugc() {
Map<UGCall, Vector<Variant>>::Element *E = unique_group_calls.front();
Variant v[VARIANT_ARG_MAX];
- for (int i = 0; i < E->get().size(); i++)
+ for (int i = 0; i < E->get().size(); i++) {
v[i] = E->get()[i];
+ }
call_group_flags(GROUP_CALL_REALTIME, E->key().group, E->key().call, v[0], v[1], v[2], v[3], v[4]);
@@ -175,10 +179,12 @@ void SceneTree::_flush_ugc() {
}
void SceneTree::_update_group_order(Group &g, bool p_use_priority) {
- if (!g.changed)
+ if (!g.changed) {
return;
- if (g.nodes.empty())
+ }
+ if (g.nodes.empty()) {
return;
+ }
Node **nodes = g.nodes.ptrw();
int node_count = g.nodes.size();
@@ -195,11 +201,13 @@ void SceneTree::_update_group_order(Group &g, bool p_use_priority) {
void SceneTree::call_group_flags(uint32_t p_call_flags, const StringName &p_group, const StringName &p_function, VARIANT_ARG_DECLARE) {
Map<StringName, Group>::Element *E = group_map.find(p_group);
- if (!E)
+ if (!E) {
return;
+ }
Group &g = E->get();
- if (g.nodes.empty())
+ if (g.nodes.empty()) {
return;
+ }
if (p_call_flags & GROUP_CALL_UNIQUE && !(p_call_flags & GROUP_CALL_REALTIME)) {
ERR_FAIL_COND(ugc_locked);
@@ -208,15 +216,17 @@ void SceneTree::call_group_flags(uint32_t p_call_flags, const StringName &p_grou
ug.call = p_function;
ug.group = p_group;
- if (unique_group_calls.has(ug))
+ if (unique_group_calls.has(ug)) {
return;
+ }
VARIANT_ARGPTRS;
Vector<Variant> args;
for (int i = 0; i < VARIANT_ARG_MAX; i++) {
- if (argptr[i]->get_type() == Variant::NIL)
+ if (argptr[i]->get_type() == Variant::NIL) {
break;
+ }
args.push_back(*argptr[i]);
}
@@ -234,45 +244,54 @@ void SceneTree::call_group_flags(uint32_t p_call_flags, const StringName &p_grou
if (p_call_flags & GROUP_CALL_REVERSE) {
for (int i = node_count - 1; i >= 0; i--) {
- if (call_lock && call_skip.has(nodes[i]))
+ if (call_lock && call_skip.has(nodes[i])) {
continue;
+ }
if (p_call_flags & GROUP_CALL_REALTIME) {
- if (p_call_flags & GROUP_CALL_MULTILEVEL)
+ if (p_call_flags & GROUP_CALL_MULTILEVEL) {
nodes[i]->call_multilevel(p_function, VARIANT_ARG_PASS);
- else
+ } else {
nodes[i]->call(p_function, VARIANT_ARG_PASS);
- } else
+ }
+ } else {
MessageQueue::get_singleton()->push_call(nodes[i], p_function, VARIANT_ARG_PASS);
+ }
}
} else {
for (int i = 0; i < node_count; i++) {
- if (call_lock && call_skip.has(nodes[i]))
+ if (call_lock && call_skip.has(nodes[i])) {
continue;
+ }
if (p_call_flags & GROUP_CALL_REALTIME) {
- if (p_call_flags & GROUP_CALL_MULTILEVEL)
+ if (p_call_flags & GROUP_CALL_MULTILEVEL) {
nodes[i]->call_multilevel(p_function, VARIANT_ARG_PASS);
- else
+ } else {
nodes[i]->call(p_function, VARIANT_ARG_PASS);
- } else
+ }
+ } else {
MessageQueue::get_singleton()->push_call(nodes[i], p_function, VARIANT_ARG_PASS);
+ }
}
}
call_lock--;
- if (call_lock == 0)
+ if (call_lock == 0) {
call_skip.clear();
+ }
}
void SceneTree::notify_group_flags(uint32_t p_call_flags, const StringName &p_group, int p_notification) {
Map<StringName, Group>::Element *E = group_map.find(p_group);
- if (!E)
+ if (!E) {
return;
+ }
Group &g = E->get();
- if (g.nodes.empty())
+ if (g.nodes.empty()) {
return;
+ }
_update_group_order(g);
@@ -284,39 +303,46 @@ void SceneTree::notify_group_flags(uint32_t p_call_flags, const StringName &p_gr
if (p_call_flags & GROUP_CALL_REVERSE) {
for (int i = node_count - 1; i >= 0; i--) {
- if (call_lock && call_skip.has(nodes[i]))
+ if (call_lock && call_skip.has(nodes[i])) {
continue;
+ }
- if (p_call_flags & GROUP_CALL_REALTIME)
+ if (p_call_flags & GROUP_CALL_REALTIME) {
nodes[i]->notification(p_notification);
- else
+ } else {
MessageQueue::get_singleton()->push_notification(nodes[i], p_notification);
+ }
}
} else {
for (int i = 0; i < node_count; i++) {
- if (call_lock && call_skip.has(nodes[i]))
+ if (call_lock && call_skip.has(nodes[i])) {
continue;
+ }
- if (p_call_flags & GROUP_CALL_REALTIME)
+ if (p_call_flags & GROUP_CALL_REALTIME) {
nodes[i]->notification(p_notification);
- else
+ } else {
MessageQueue::get_singleton()->push_notification(nodes[i], p_notification);
+ }
}
}
call_lock--;
- if (call_lock == 0)
+ if (call_lock == 0) {
call_skip.clear();
+ }
}
void SceneTree::set_group_flags(uint32_t p_call_flags, const StringName &p_group, const String &p_name, const Variant &p_value) {
Map<StringName, Group>::Element *E = group_map.find(p_group);
- if (!E)
+ if (!E) {
return;
+ }
Group &g = E->get();
- if (g.nodes.empty())
+ if (g.nodes.empty()) {
return;
+ }
_update_group_order(g);
@@ -328,30 +354,35 @@ void SceneTree::set_group_flags(uint32_t p_call_flags, const StringName &p_group
if (p_call_flags & GROUP_CALL_REVERSE) {
for (int i = node_count - 1; i >= 0; i--) {
- if (call_lock && call_skip.has(nodes[i]))
+ if (call_lock && call_skip.has(nodes[i])) {
continue;
+ }
- if (p_call_flags & GROUP_CALL_REALTIME)
+ if (p_call_flags & GROUP_CALL_REALTIME) {
nodes[i]->set(p_name, p_value);
- else
+ } else {
MessageQueue::get_singleton()->push_set(nodes[i], p_name, p_value);
+ }
}
} else {
for (int i = 0; i < node_count; i++) {
- if (call_lock && call_skip.has(nodes[i]))
+ if (call_lock && call_skip.has(nodes[i])) {
continue;
+ }
- if (p_call_flags & GROUP_CALL_REALTIME)
+ if (p_call_flags & GROUP_CALL_REALTIME) {
nodes[i]->set(p_name, p_value);
- else
+ } else {
MessageQueue::get_singleton()->push_set(nodes[i], p_name, p_value);
+ }
}
}
call_lock--;
- if (call_lock == 0)
+ if (call_lock == 0) {
call_skip.clear();
+ }
}
void SceneTree::call_group(const StringName &p_group, const StringName &p_function, VARIANT_ARG_DECLARE) {
@@ -631,8 +662,9 @@ Color SceneTree::get_debug_navigation_disabled_color() const {
}
Ref<Material> SceneTree::get_debug_navigation_material() {
- if (navigation_material.is_valid())
+ if (navigation_material.is_valid()) {
return navigation_material;
+ }
Ref<StandardMaterial3D> line_material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
line_material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
@@ -647,8 +679,9 @@ Ref<Material> SceneTree::get_debug_navigation_material() {
}
Ref<Material> SceneTree::get_debug_navigation_disabled_material() {
- if (navigation_disabled_material.is_valid())
+ if (navigation_disabled_material.is_valid()) {
return navigation_disabled_material;
+ }
Ref<StandardMaterial3D> line_material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
line_material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
@@ -663,8 +696,9 @@ Ref<Material> SceneTree::get_debug_navigation_disabled_material() {
}
Ref<Material> SceneTree::get_debug_collision_material() {
- if (collision_material.is_valid())
+ if (collision_material.is_valid()) {
return collision_material;
+ }
Ref<StandardMaterial3D> line_material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
line_material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
@@ -679,8 +713,9 @@ Ref<Material> SceneTree::get_debug_collision_material() {
}
Ref<ArrayMesh> SceneTree::get_debug_contact_mesh() {
- if (debug_contact_mesh.is_valid())
+ if (debug_contact_mesh.is_valid()) {
return debug_contact_mesh;
+ }
debug_contact_mesh = Ref<ArrayMesh>(memnew(ArrayMesh));
@@ -714,12 +749,14 @@ Ref<ArrayMesh> SceneTree::get_debug_contact_mesh() {
/* clang-format on */
Vector<int> indices;
- for (int i = 0; i < 8 * 3; i++)
+ for (int i = 0; i < 8 * 3; i++) {
indices.push_back(diamond_faces[i]);
+ }
Vector<Vector3> vertices;
- for (int i = 0; i < 6; i++)
+ for (int i = 0; i < 6; i++) {
vertices.push_back(diamond[i] * 0.1);
+ }
Array arr;
arr.resize(Mesh::ARRAY_MAX);
@@ -733,14 +770,16 @@ Ref<ArrayMesh> SceneTree::get_debug_contact_mesh() {
}
void SceneTree::set_pause(bool p_enabled) {
- if (p_enabled == pause)
+ if (p_enabled == pause) {
return;
+ }
pause = p_enabled;
NavigationServer3D::get_singleton()->set_active(!p_enabled);
PhysicsServer3D::get_singleton()->set_active(!p_enabled);
PhysicsServer2D::get_singleton()->set_active(!p_enabled);
- if (get_root())
+ if (get_root()) {
get_root()->propagate_notification(p_enabled ? Node::NOTIFICATION_PAUSED : Node::NOTIFICATION_UNPAUSED);
+ }
}
bool SceneTree::is_paused() const {
@@ -749,11 +788,13 @@ bool SceneTree::is_paused() const {
void SceneTree::_notify_group_pause(const StringName &p_group, int p_notification) {
Map<StringName, Group>::Element *E = group_map.find(p_group);
- if (!E)
+ if (!E) {
return;
+ }
Group &g = E->get();
- if (g.nodes.empty())
+ if (g.nodes.empty()) {
return;
+ }
_update_group_order(g, p_notification == Node::NOTIFICATION_PROCESS || p_notification == Node::NOTIFICATION_INTERNAL_PROCESS || p_notification == Node::NOTIFICATION_PHYSICS_PROCESS || p_notification == Node::NOTIFICATION_INTERNAL_PHYSICS_PROCESS);
@@ -768,21 +809,25 @@ void SceneTree::_notify_group_pause(const StringName &p_group, int p_notificatio
for (int i = 0; i < node_count; i++) {
Node *n = nodes[i];
- if (call_lock && call_skip.has(n))
+ if (call_lock && call_skip.has(n)) {
continue;
+ }
- if (!n->can_process())
+ if (!n->can_process()) {
continue;
- if (!n->can_process_notification(p_notification))
+ }
+ if (!n->can_process_notification(p_notification)) {
continue;
+ }
n->notification(p_notification);
//ERR_FAIL_COND(node_count != g.nodes.size());
}
call_lock--;
- if (call_lock == 0)
+ if (call_lock == 0) {
call_skip.clear();
+ }
}
/*
@@ -799,11 +844,13 @@ void SceneMainLoop::_update_listener_2d() {
void SceneTree::_call_input_pause(const StringName &p_group, const StringName &p_method, const Ref<InputEvent> &p_input, Viewport *p_viewport) {
Map<StringName, Group>::Element *E = group_map.find(p_group);
- if (!E)
+ if (!E) {
return;
+ }
Group &g = E->get();
- if (g.nodes.empty())
+ if (g.nodes.empty()) {
return;
+ }
_update_group_order(g);
@@ -820,23 +867,27 @@ void SceneTree::_call_input_pause(const StringName &p_group, const StringName &p
call_lock++;
for (int i = node_count - 1; i >= 0; i--) {
- if (p_viewport->is_input_handled())
+ if (p_viewport->is_input_handled()) {
break;
+ }
Node *n = nodes[i];
- if (call_lock && call_skip.has(n))
+ if (call_lock && call_skip.has(n)) {
continue;
+ }
- if (!n->can_process())
+ if (!n->can_process()) {
continue;
+ }
n->call_multilevel(p_method, (const Variant **)v, 1);
//ERR_FAIL_COND(node_count != g.nodes.size());
}
call_lock--;
- if (call_lock == 0)
+ if (call_lock == 0) {
call_skip.clear();
+ }
}
Variant SceneTree::_call_group_flags(const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
@@ -890,13 +941,15 @@ int64_t SceneTree::get_event_count() const {
Array SceneTree::_get_nodes_in_group(const StringName &p_group) {
Array ret;
Map<StringName, Group>::Element *E = group_map.find(p_group);
- if (!E)
+ if (!E) {
return ret;
+ }
_update_group_order(E->get()); //update order just in case
int nc = E->get().nodes.size();
- if (nc == 0)
+ if (nc == 0) {
return ret;
+ }
ret.resize(nc);
@@ -914,13 +967,15 @@ bool SceneTree::has_group(const StringName &p_identifier) const {
void SceneTree::get_nodes_in_group(const StringName &p_group, List<Node *> *p_list) {
Map<StringName, Group>::Element *E = group_map.find(p_group);
- if (!E)
+ if (!E) {
return;
+ }
_update_group_order(E->get()); //update order just in case
int nc = E->get().nodes.size();
- if (nc == 0)
+ if (nc == 0) {
return;
+ }
Node **ptr = E->get().nodes.ptrw();
for (int i = 0; i < nc; i++) {
p_list->push_back(ptr[i]);
@@ -995,8 +1050,9 @@ void SceneTree::_change_scene(Node *p_to) {
Error SceneTree::change_scene(const String &p_path) {
Ref<PackedScene> new_scene = ResourceLoader::load(p_path);
- if (new_scene.is_null())
+ if (new_scene.is_null()) {
return ERR_CANT_OPEN;
+ }
return change_scene_to(new_scene);
}
@@ -1276,8 +1332,9 @@ void SceneTree::get_argument_options(const StringName &p_function, int p_idx, Li
}
SceneTree::SceneTree() {
- if (singleton == nullptr)
+ if (singleton == nullptr) {
singleton = this;
+ }
_quit = false;
accept_quit = true;
quit_on_go_back = true;
@@ -1314,8 +1371,9 @@ SceneTree::SceneTree() {
root = memnew(Window);
root->set_name("root");
- if (!root->get_world_3d().is_valid())
+ if (!root->get_world_3d().is_valid()) {
root->set_world_3d(Ref<World3D>(memnew(World3D)));
+ }
// Initialize network state
multiplayer_poll = true;
@@ -1340,8 +1398,9 @@ SceneTree::SceneTree() {
ResourceLoader::get_recognized_extensions_for_type("Environment", &exts);
String ext_hint;
for (List<String>::Element *E = exts.front(); E; E = E->next()) {
- if (ext_hint != String())
+ if (ext_hint != String()) {
ext_hint += ",";
+ }
ext_hint += "*." + E->get();
}
//get path
@@ -1383,6 +1442,7 @@ SceneTree::~SceneTree() {
memdelete(root);
}
- if (singleton == this)
+ if (singleton == this) {
singleton = nullptr;
+ }
}
diff --git a/scene/main/timer.cpp b/scene/main/timer.cpp
index 286f332ba5..fb55892b54 100644
--- a/scene/main/timer.cpp
+++ b/scene/main/timer.cpp
@@ -37,38 +37,43 @@ void Timer::_notification(int p_what) {
case NOTIFICATION_READY: {
if (autostart) {
#ifdef TOOLS_ENABLED
- if (Engine::get_singleton()->is_editor_hint() && get_tree()->get_edited_scene_root() && (get_tree()->get_edited_scene_root() == this || get_tree()->get_edited_scene_root()->is_a_parent_of(this)))
+ if (Engine::get_singleton()->is_editor_hint() && get_tree()->get_edited_scene_root() && (get_tree()->get_edited_scene_root() == this || get_tree()->get_edited_scene_root()->is_a_parent_of(this))) {
break;
+ }
#endif
start();
autostart = false;
}
} break;
case NOTIFICATION_INTERNAL_PROCESS: {
- if (timer_process_mode == TIMER_PROCESS_PHYSICS || !is_processing_internal())
+ if (timer_process_mode == TIMER_PROCESS_PHYSICS || !is_processing_internal()) {
return;
+ }
time_left -= get_process_delta_time();
if (time_left < 0) {
- if (!one_shot)
+ if (!one_shot) {
time_left += wait_time;
- else
+ } else {
stop();
+ }
emit_signal("timeout");
}
} break;
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
- if (timer_process_mode == TIMER_PROCESS_IDLE || !is_physics_processing_internal())
+ if (timer_process_mode == TIMER_PROCESS_IDLE || !is_physics_processing_internal()) {
return;
+ }
time_left -= get_physics_process_delta_time();
if (time_left < 0) {
- if (!one_shot)
+ if (!one_shot) {
time_left += wait_time;
- else
+ } else {
stop();
+ }
emit_signal("timeout");
}
@@ -118,8 +123,9 @@ void Timer::stop() {
}
void Timer::set_paused(bool p_paused) {
- if (paused == p_paused)
+ if (paused == p_paused) {
return;
+ }
paused = p_paused;
_set_process(processing);
@@ -138,8 +144,9 @@ float Timer::get_time_left() const {
}
void Timer::set_timer_process_mode(TimerProcessMode p_mode) {
- if (timer_process_mode == p_mode)
+ if (timer_process_mode == p_mode) {
return;
+ }
switch (timer_process_mode) {
case TIMER_PROCESS_PHYSICS:
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index 8d22ebb7ae..8544d67ecc 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -86,8 +86,9 @@ void ViewportTexture::setup_local_to_scene() {
}
void ViewportTexture::set_viewport_path_in_scene(const NodePath &p_path) {
- if (path == p_path)
+ if (path == p_path) {
return;
+ }
path = p_path;
@@ -195,8 +196,9 @@ Viewport::GUI::GUI() {
/////////////////////////////////////
void Viewport::update_worlds() {
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
Rect2 abstracted_rect = Rect2(Vector2(), get_visible_rect().size);
Rect2 xformed_rect = (global_canvas_transform * canvas_transform).affine_inverse().xform(abstracted_rect);
@@ -474,8 +476,9 @@ void Viewport::_notification(int p_what) {
}
}
- if (first)
+ if (first) {
first->make_current();
+ }
}
if (cameras.size() && !camera) {
@@ -487,8 +490,9 @@ void Viewport::_notification(int p_what) {
}
}
- if (first)
+ if (first) {
first->make_current();
+ }
}
#endif
@@ -499,8 +503,9 @@ void Viewport::_notification(int p_what) {
} break;
case NOTIFICATION_EXIT_TREE: {
_gui_cancel_tooltip();
- if (world_2d.is_valid())
+ if (world_2d.is_valid()) {
world_2d->_remove_viewport(this);
+ }
RenderingServer::get_singleton()->viewport_set_scenario(viewport, RID());
RenderingServer::get_singleton()->viewport_remove_canvas(viewport, current_canvas);
@@ -825,15 +830,17 @@ RID Viewport::get_viewport_rid() const {
}
void Viewport::update_canvas_items() {
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
_update_canvas_items(this);
}
void Viewport::_set_size(const Size2i &p_size, const Size2i &p_size_2d_override, const Rect2i &p_to_screen_rect, const Transform2D &p_stretch_transform, bool p_allocated) {
- if (size == p_size && size_allocated == p_allocated && stretch_transform == p_stretch_transform && p_size_2d_override == size_2d_override && to_screen_rect != p_to_screen_rect)
+ if (size == p_size && size_allocated == p_allocated && stretch_transform == p_stretch_transform && p_size_2d_override == size_2d_override && to_screen_rect != p_to_screen_rect) {
return;
+ }
size = p_size;
size_allocated = p_allocated;
@@ -894,8 +901,9 @@ void Viewport::_update_listener_2d() {
}
void Viewport::set_as_audio_listener(bool p_enable) {
- if (p_enable == audio_listener)
+ if (p_enable == audio_listener) {
return;
+ }
audio_listener = p_enable;
_update_listener();
@@ -906,8 +914,9 @@ bool Viewport::is_audio_listener() const {
}
void Viewport::set_as_audio_listener_2d(bool p_enable) {
- if (p_enable == audio_listener_2d)
+ if (p_enable == audio_listener_2d) {
return;
+ }
audio_listener_2d = p_enable;
@@ -984,8 +993,9 @@ void Viewport::_listener_transform_changed_notify() {
void Viewport::_listener_set(Listener3D *p_listener) {
#ifndef _3D_DISABLED
- if (listener == p_listener)
+ if (listener == p_listener) {
return;
+ }
listener = p_listener;
@@ -1010,12 +1020,15 @@ void Viewport::_listener_remove(Listener3D *p_listener) {
void Viewport::_listener_make_next_current(Listener3D *p_exclude) {
if (listeners.size() > 0) {
for (Set<Listener3D *>::Element *E = listeners.front(); E; E = E->next()) {
- if (p_exclude == E->get())
+ if (p_exclude == E->get()) {
continue;
- if (!E->get()->is_inside_tree())
+ }
+ if (!E->get()->is_inside_tree()) {
continue;
- if (listener != nullptr)
+ }
+ if (listener != nullptr) {
return;
+ }
E->get()->make_current();
}
@@ -1037,8 +1050,9 @@ void Viewport::_camera_transform_changed_notify() {
void Viewport::_camera_set(Camera3D *p_camera) {
#ifndef _3D_DISABLED
- if (camera == p_camera)
+ if (camera == p_camera) {
return;
+ }
if (camera) {
camera->notification(Camera3D::NOTIFICATION_LOST_CURRENT);
@@ -1047,10 +1061,11 @@ void Viewport::_camera_set(Camera3D *p_camera) {
camera = p_camera;
if (!camera_override) {
- if (camera)
+ if (camera) {
RenderingServer::get_singleton()->viewport_attach_camera(viewport, camera->get_camera());
- else
+ } else {
RenderingServer::get_singleton()->viewport_attach_camera(viewport, RID());
+ }
}
if (camera) {
@@ -1078,12 +1093,15 @@ void Viewport::_camera_remove(Camera3D *p_camera) {
#ifndef _3D_DISABLED
void Viewport::_camera_make_next_current(Camera3D *p_exclude) {
for (Set<Camera3D *>::Element *E = cameras.front(); E; E = E->next()) {
- if (p_exclude == E->get())
+ if (p_exclude == E->get()) {
continue;
- if (!E->get()->is_inside_tree())
+ }
+ if (!E->get()->is_inside_tree()) {
continue;
- if (camera != nullptr)
+ }
+ if (camera != nullptr) {
return;
+ }
E->get()->make_current();
}
@@ -1108,8 +1126,9 @@ bool Viewport::has_transparent_background() const {
}
void Viewport::set_world_2d(const Ref<World2D> &p_world_2d) {
- if (world_2d == p_world_2d)
+ if (world_2d == p_world_2d) {
return;
+ }
if (parent && parent->find_world_2d() == p_world_2d) {
WARN_PRINT("Unable to use parent world_3d as world_2d");
@@ -1121,9 +1140,9 @@ void Viewport::set_world_2d(const Ref<World2D> &p_world_2d) {
RenderingServer::get_singleton()->viewport_remove_canvas(viewport, current_canvas);
}
- if (p_world_2d.is_valid())
+ if (p_world_2d.is_valid()) {
world_2d = p_world_2d;
- else {
+ } else {
WARN_PRINT("Invalid world_3d");
world_2d = Ref<World2D>(memnew(World2D));
}
@@ -1138,18 +1157,20 @@ void Viewport::set_world_2d(const Ref<World2D> &p_world_2d) {
}
Ref<World2D> Viewport::find_world_2d() const {
- if (world_2d.is_valid())
+ if (world_2d.is_valid()) {
return world_2d;
- else if (parent)
+ } else if (parent) {
return parent->find_world_2d();
- else
+ } else {
return Ref<World2D>();
+ }
}
void Viewport::_propagate_enter_world(Node *p_node) {
if (p_node != this) {
- if (!p_node->is_inside_tree()) //may not have entered scene yet
+ if (!p_node->is_inside_tree()) { //may not have entered scene yet
return;
+ }
#ifndef _3D_DISABLED
if (Object::cast_to<Node3D>(p_node) || Object::cast_to<WorldEnvironment>(p_node)) {
@@ -1158,8 +1179,9 @@ void Viewport::_propagate_enter_world(Node *p_node) {
#endif
Viewport *v = Object::cast_to<Viewport>(p_node);
if (v) {
- if (v->world_3d.is_valid() || v->own_world_3d.is_valid())
+ if (v->world_3d.is_valid() || v->own_world_3d.is_valid()) {
return;
+ }
}
#ifndef _3D_DISABLED
}
@@ -1175,16 +1197,18 @@ void Viewport::_propagate_viewport_notification(Node *p_node, int p_what) {
p_node->notification(p_what);
for (int i = 0; i < p_node->get_child_count(); i++) {
Node *c = p_node->get_child(i);
- if (Object::cast_to<Viewport>(c))
+ if (Object::cast_to<Viewport>(c)) {
continue;
+ }
_propagate_viewport_notification(c, p_what);
}
}
void Viewport::_propagate_exit_world(Node *p_node) {
if (p_node != this) {
- if (!p_node->is_inside_tree()) //may have exited scene already
+ if (!p_node->is_inside_tree()) { //may have exited scene already
return;
+ }
#ifndef _3D_DISABLED
if (Object::cast_to<Node3D>(p_node) || Object::cast_to<WorldEnvironment>(p_node)) {
@@ -1193,8 +1217,9 @@ void Viewport::_propagate_exit_world(Node *p_node) {
#endif
Viewport *v = Object::cast_to<Viewport>(p_node);
if (v) {
- if (v->world_3d.is_valid() || v->own_world_3d.is_valid())
+ if (v->world_3d.is_valid() || v->own_world_3d.is_valid()) {
return;
+ }
}
#ifndef _3D_DISABLED
}
@@ -1207,11 +1232,13 @@ void Viewport::_propagate_exit_world(Node *p_node) {
}
void Viewport::set_world_3d(const Ref<World3D> &p_world_3d) {
- if (world_3d == p_world_3d)
+ if (world_3d == p_world_3d) {
return;
+ }
- if (is_inside_tree())
+ if (is_inside_tree()) {
_propagate_exit_world(this);
+ }
if (own_world_3d.is_valid() && world_3d.is_valid()) {
world_3d->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &Viewport::_own_world_3d_changed));
@@ -1228,8 +1255,9 @@ void Viewport::set_world_3d(const Ref<World3D> &p_world_3d) {
}
}
- if (is_inside_tree())
+ if (is_inside_tree()) {
_propagate_enter_world(this);
+ }
if (is_inside_tree()) {
RenderingServer::get_singleton()->viewport_set_scenario(viewport, find_world_3d()->get_scenario());
@@ -1247,14 +1275,15 @@ Ref<World2D> Viewport::get_world_2d() const {
}
Ref<World3D> Viewport::find_world_3d() const {
- if (own_world_3d.is_valid())
+ if (own_world_3d.is_valid()) {
return own_world_3d;
- else if (world_3d.is_valid())
+ } else if (world_3d.is_valid()) {
return world_3d;
- else if (parent)
+ } else if (parent) {
return parent->find_world_3d();
- else
+ } else {
return Ref<World3D>();
+ }
}
Listener3D *Viewport::get_listener() const {
@@ -1310,8 +1339,9 @@ Transform Viewport::get_camera_override_transform() const {
void Viewport::set_camera_override_perspective(float p_fovy_degrees, float p_z_near, float p_z_far) {
if (camera_override) {
if (camera_override.fov == p_fovy_degrees && camera_override.z_near == p_z_near &&
- camera_override.z_far == p_z_far && camera_override.projection == CameraOverrideData::PROJECTION_PERSPECTIVE)
+ camera_override.z_far == p_z_far && camera_override.projection == CameraOverrideData::PROJECTION_PERSPECTIVE) {
return;
+ }
camera_override.fov = p_fovy_degrees;
camera_override.z_near = p_z_near;
@@ -1325,8 +1355,9 @@ void Viewport::set_camera_override_perspective(float p_fovy_degrees, float p_z_n
void Viewport::set_camera_override_orthogonal(float p_size, float p_z_near, float p_z_far) {
if (camera_override) {
if (camera_override.size == p_size && camera_override.z_near == p_z_near &&
- camera_override.z_far == p_z_far && camera_override.projection == CameraOverrideData::PROJECTION_ORTHOGONAL)
+ camera_override.z_far == p_z_far && camera_override.projection == CameraOverrideData::PROJECTION_ORTHOGONAL) {
return;
+ }
camera_override.size = p_size;
camera_override.z_near = p_z_near;
@@ -1344,8 +1375,9 @@ Transform2D Viewport::get_final_transform() const {
void Viewport::_update_canvas_items(Node *p_node) {
if (p_node != this) {
Viewport *vp = Object::cast_to<Viewport>(p_node);
- if (vp)
+ if (vp) {
return;
+ }
CanvasItem *ci = Object::cast_to<CanvasItem>(p_node);
if (ci) {
@@ -1365,8 +1397,9 @@ Ref<ViewportTexture> Viewport::get_texture() const {
}
void Viewport::set_shadow_atlas_size(int p_size) {
- if (shadow_atlas_size == p_size)
+ if (shadow_atlas_size == p_size) {
return;
+ }
shadow_atlas_size = p_size;
RS::get_singleton()->viewport_set_shadow_atlas_size(viewport, p_size);
@@ -1380,8 +1413,9 @@ void Viewport::set_shadow_atlas_quadrant_subdiv(int p_quadrant, ShadowAtlasQuadr
ERR_FAIL_INDEX(p_quadrant, 4);
ERR_FAIL_INDEX(p_subdiv, SHADOW_ATLAS_QUADRANT_SUBDIV_MAX);
- if (shadow_atlas_quadrant_subdiv[p_quadrant] == p_subdiv)
+ if (shadow_atlas_quadrant_subdiv[p_quadrant] == p_subdiv) {
return;
+ }
shadow_atlas_quadrant_subdiv[p_quadrant] = p_subdiv;
static const int subdiv[SHADOW_ATLAS_QUADRANT_SUBDIV_MAX] = { 0, 1, 4, 16, 64, 256, 1024 };
@@ -1421,8 +1455,9 @@ void Viewport::warp_mouse(const Vector2 &p_pos) {
}
void Viewport::_gui_sort_roots() {
- if (!gui.roots_order_dirty)
+ if (!gui.roots_order_dirty) {
return;
+ }
gui.roots.sort_custom<Control::CComparator>();
@@ -1450,14 +1485,17 @@ String Viewport::_gui_get_tooltip(Control *p_control, const Vector2 &p_pos, Cont
*r_which = p_control;
}
- if (tooltip != String())
+ if (tooltip != String()) {
break;
+ }
pos = p_control->get_transform().xform(pos);
- if (p_control->data.mouse_filter == Control::MOUSE_FILTER_STOP)
+ if (p_control->data.mouse_filter == Control::MOUSE_FILTER_STOP) {
break;
- if (p_control->is_set_as_toplevel())
+ }
+ if (p_control->is_set_as_toplevel()) {
break;
+ }
p_control = p_control->get_parent_control();
}
@@ -1473,8 +1511,9 @@ void Viewport::_gui_show_tooltip() {
Control *which = nullptr;
String tooltip = _gui_get_tooltip(gui.tooltip, gui.tooltip->get_global_transform().xform_inv(gui.tooltip_pos), &which);
tooltip = tooltip.strip_edges();
- if (tooltip.length() == 0)
+ if (tooltip.length() == 0) {
return; // bye
+ }
if (gui.tooltip_popup) {
memdelete(gui.tooltip_popup);
@@ -1516,15 +1555,17 @@ void Viewport::_gui_show_tooltip() {
Rect2i vr = gui.tooltip_popup->get_parent_visible_window()->get_usable_parent_rect();
- if (r.size.x + r.position.x > vr.size.x + vr.position.x)
+ if (r.size.x + r.position.x > vr.size.x + vr.position.x) {
r.position.x = vr.position.x + vr.size.x - r.size.x;
- else if (r.position.x < vr.position.x)
+ } else if (r.position.x < vr.position.x) {
r.position.x = vr.position.x;
+ }
- if (r.size.y + r.position.y > vr.size.y + vr.position.y)
+ if (r.size.y + r.position.y > vr.size.y + vr.position.y) {
r.position.y = vr.position.y + vr.size.y - r.size.y;
- else if (r.position.y < vr.position.y)
+ } else if (r.position.y < vr.position.y) {
r.position.y = vr.position.y;
+ }
gui.tooltip_popup->set_position(r.position);
gui.tooltip_popup->set_size(r.size);
@@ -1558,25 +1599,31 @@ void Viewport::_gui_call_input(Control *p_control, const Ref<InputEvent> &p_inpu
if (control->data.mouse_filter != Control::MOUSE_FILTER_IGNORE) {
control->emit_signal(SceneStringNames::get_singleton()->gui_input, ev); //signal should be first, so it's possible to override an event (and then accept it)
}
- if (gui.key_event_accepted)
+ if (gui.key_event_accepted) {
break;
- if (!control->is_inside_tree())
+ }
+ if (!control->is_inside_tree()) {
break;
+ }
if (control->data.mouse_filter != Control::MOUSE_FILTER_IGNORE) {
control->call_multilevel(SceneStringNames::get_singleton()->_gui_input, ev);
}
- if (!control->is_inside_tree() || control->is_set_as_toplevel())
+ if (!control->is_inside_tree() || control->is_set_as_toplevel()) {
break;
- if (gui.key_event_accepted)
+ }
+ if (gui.key_event_accepted) {
break;
- if (!cant_stop_me_now && control->data.mouse_filter == Control::MOUSE_FILTER_STOP && ismouse)
+ }
+ if (!cant_stop_me_now && control->data.mouse_filter == Control::MOUSE_FILTER_STOP && ismouse) {
break;
+ }
}
- if (ci->is_set_as_toplevel())
+ if (ci->is_set_as_toplevel()) {
break;
+ }
ev = ev->xformed_by(ci->get_transform()); //transform event upwards
ci = ci->get_parent_item();
@@ -1594,17 +1641,21 @@ void Viewport::_gui_call_notification(Control *p_control, int p_what) {
control->notification(p_what);
}
- if (!control->is_inside_tree())
+ if (!control->is_inside_tree()) {
break;
+ }
- if (!control->is_inside_tree() || control->is_set_as_toplevel())
+ if (!control->is_inside_tree() || control->is_set_as_toplevel()) {
break;
- if (control->data.mouse_filter == Control::MOUSE_FILTER_STOP)
+ }
+ if (control->data.mouse_filter == Control::MOUSE_FILTER_STOP) {
break;
+ }
}
- if (ci->is_set_as_toplevel())
+ if (ci->is_set_as_toplevel()) {
break;
+ }
ci = ci->get_parent_item();
}
@@ -1618,27 +1669,31 @@ Control *Viewport::_gui_find_control(const Point2 &p_global) {
for (List<Control *>::Element *E = gui.roots.back(); E; E = E->prev()) {
Control *sw = E->get();
- if (!sw->is_visible_in_tree())
+ if (!sw->is_visible_in_tree()) {
continue;
+ }
Transform2D xform;
CanvasItem *pci = sw->get_parent_item();
- if (pci)
+ if (pci) {
xform = pci->get_global_transform_with_canvas();
- else
+ } else {
xform = sw->get_canvas_transform();
+ }
Control *ret = _gui_find_control_at_pos(sw, p_global, xform, gui.focus_inv_xform);
- if (ret)
+ if (ret) {
return ret;
+ }
}
return nullptr;
}
Control *Viewport::_gui_find_control_at_pos(CanvasItem *p_node, const Point2 &p_global, const Transform2D &p_xform, Transform2D &r_inv_xform) {
- if (Object::cast_to<Viewport>(p_node))
+ if (Object::cast_to<Viewport>(p_node)) {
return nullptr;
+ }
if (!p_node->is_visible()) {
//return _find_next_visible_control_at_pos(p_node,p_global,r_inv_xform);
@@ -1647,25 +1702,29 @@ Control *Viewport::_gui_find_control_at_pos(CanvasItem *p_node, const Point2 &p_
Transform2D matrix = p_xform * p_node->get_transform();
// matrix.basis_determinant() == 0.0f implies that node does not exist on scene
- if (matrix.basis_determinant() == 0.0f)
+ if (matrix.basis_determinant() == 0.0f) {
return nullptr;
+ }
Control *c = Object::cast_to<Control>(p_node);
if (!c || !c->clips_input() || c->has_point(matrix.affine_inverse().xform(p_global))) {
for (int i = p_node->get_child_count() - 1; i >= 0; i--) {
CanvasItem *ci = Object::cast_to<CanvasItem>(p_node->get_child(i));
- if (!ci || ci->is_set_as_toplevel())
+ if (!ci || ci->is_set_as_toplevel()) {
continue;
+ }
Control *ret = _gui_find_control_at_pos(ci, p_global, matrix, r_inv_xform);
- if (ret)
+ if (ret) {
return ret;
+ }
}
}
- if (!c)
+ if (!c) {
return nullptr;
+ }
matrix.affine_invert();
@@ -1673,8 +1732,9 @@ Control *Viewport::_gui_find_control_at_pos(CanvasItem *p_node, const Point2 &p_
if (c->data.mouse_filter != Control::MOUSE_FILTER_IGNORE && c->has_point(matrix.xform(p_global)) && (!gui.drag_preview || (c != gui.drag_preview && !gui.drag_preview->is_a_parent_of(c)))) {
r_inv_xform = matrix;
return c;
- } else
+ } else {
return nullptr;
+ }
}
bool Viewport::_gui_drop(Control *p_at_control, Point2 p_at_pos, bool p_just_check) {
@@ -1691,14 +1751,16 @@ bool Viewport::_gui_drop(Control *p_at_control, Point2 p_at_pos, bool p_just_che
return true;
}
- if (control->data.mouse_filter == Control::MOUSE_FILTER_STOP)
+ if (control->data.mouse_filter == Control::MOUSE_FILTER_STOP) {
break;
+ }
}
p_at_pos = ci->get_transform().xform(p_at_pos);
- if (ci->is_set_as_toplevel())
+ if (ci->is_set_as_toplevel()) {
break;
+ }
ci = ci->get_parent_item();
}
@@ -1788,12 +1850,14 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
break;
}
- if (control->data.mouse_filter == Control::MOUSE_FILTER_STOP)
+ if (control->data.mouse_filter == Control::MOUSE_FILTER_STOP) {
break;
+ }
}
- if (ci->is_set_as_toplevel())
+ if (ci->is_set_as_toplevel()) {
break;
+ }
ci = ci->get_parent_item();
}
@@ -1914,12 +1978,14 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
gui.dragging = false;
}
- if (control->data.mouse_filter == Control::MOUSE_FILTER_STOP)
+ if (control->data.mouse_filter == Control::MOUSE_FILTER_STOP) {
break;
+ }
}
- if (ci->is_set_as_toplevel())
+ if (ci->is_set_as_toplevel()) {
break;
+ }
ci = ci->get_parent_item();
}
@@ -1979,9 +2045,9 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
if (can_tooltip && gui.tooltip) {
String tooltip = _gui_get_tooltip(over, gui.tooltip->get_global_transform().xform_inv(mpos));
- if (tooltip.length() == 0)
+ if (tooltip.length() == 0) {
_gui_cancel_tooltip();
- else if (gui.tooltip_label) {
+ } else if (gui.tooltip_label) {
if (tooltip == gui.tooltip_label->get_text()) {
is_tooltip_shown = true;
}
@@ -1996,8 +2062,9 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
is_tooltip_shown = true; //well, nothing to compare against, likely using custom control, so if it changes there is nothing we can do
}
}
- } else
+ } else {
_gui_cancel_tooltip();
+ }
}
if (can_tooltip && !is_tooltip_shown) {
@@ -2018,12 +2085,15 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
while (c) {
cursor_shape = c->get_cursor_shape(cpos);
cpos = c->get_transform().xform(cpos);
- if (cursor_shape != Control::CURSOR_ARROW)
+ if (cursor_shape != Control::CURSOR_ARROW) {
break;
- if (c->data.mouse_filter == Control::MOUSE_FILTER_STOP)
+ }
+ if (c->data.mouse_filter == Control::MOUSE_FILTER_STOP) {
break;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
break;
+ }
c = c->get_parent_control();
}
}
@@ -2233,8 +2303,9 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
gui.key_event_accepted = false;
if (gui.key_focus->can_process()) {
gui.key_focus->call_multilevel(SceneStringNames::get_singleton()->_gui_input, p_event);
- if (gui.key_focus) //maybe lost it
+ if (gui.key_focus) { //maybe lost it
gui.key_focus->emit_signal(SceneStringNames::get_singleton()->gui_input, p_event);
+ }
}
if (gui.key_event_accepted) {
@@ -2342,14 +2413,18 @@ void Viewport::_gui_hid_control(Control *p_control) {
_drop_mouse_focus();
}
- if (gui.key_focus == p_control)
+ if (gui.key_focus == p_control) {
_gui_remove_focus();
- if (gui.mouse_over == p_control)
+ }
+ if (gui.mouse_over == p_control) {
gui.mouse_over = nullptr;
- if (gui.drag_mouse_over == p_control)
+ }
+ if (gui.drag_mouse_over == p_control) {
gui.drag_mouse_over = nullptr;
- if (gui.tooltip == p_control)
+ }
+ if (gui.tooltip == p_control) {
_gui_cancel_tooltip();
+ }
}
void Viewport::_gui_remove_control(Control *p_control) {
@@ -2361,14 +2436,18 @@ void Viewport::_gui_remove_control(Control *p_control) {
if (gui.last_mouse_focus == p_control) {
gui.last_mouse_focus = nullptr;
}
- if (gui.key_focus == p_control)
+ if (gui.key_focus == p_control) {
gui.key_focus = nullptr;
- if (gui.mouse_over == p_control)
+ }
+ if (gui.mouse_over == p_control) {
gui.mouse_over = nullptr;
- if (gui.drag_mouse_over == p_control)
+ }
+ if (gui.drag_mouse_over == p_control) {
gui.drag_mouse_over = nullptr;
- if (gui.tooltip == p_control)
+ }
+ if (gui.tooltip == p_control) {
gui.tooltip = nullptr;
+ }
}
void Viewport::_gui_remove_focus() {
@@ -2385,8 +2464,9 @@ bool Viewport::_gui_control_has_focus(const Control *p_control) {
void Viewport::_gui_control_grab_focus(Control *p_control) {
//no need for change
- if (gui.key_focus && gui.key_focus == p_control)
+ if (gui.key_focus && gui.key_focus == p_control) {
return;
+ }
get_tree()->call_group_flags(SceneTree::GROUP_CALL_REALTIME, "_viewports", "_gui_remove_focus");
gui.key_focus = p_control;
emit_signal("gui_focus_changed", p_control);
@@ -2396,8 +2476,9 @@ void Viewport::_gui_control_grab_focus(Control *p_control) {
void Viewport::_gui_accept_event() {
gui.key_event_accepted = true;
- if (is_inside_tree())
+ if (is_inside_tree()) {
set_input_as_handled();
+ }
}
void Viewport::_drop_mouse_focus() {
@@ -2463,8 +2544,9 @@ void Viewport::_post_gui_grab_click_focus() {
gui.mouse_click_grabber = nullptr;
if (gui.mouse_focus) {
- if (gui.mouse_focus == focus_grabber)
+ if (gui.mouse_focus == focus_grabber) {
return;
+ }
int mask = gui.mouse_focus_mask;
Point2 click = gui.mouse_focus->get_global_transform_with_canvas().affine_inverse().xform(gui.last_mouse_pos);
@@ -2809,8 +2891,9 @@ bool Viewport::_sub_windows_forward_input(const Ref<InputEvent> &p_event) {
void Viewport::input(const Ref<InputEvent> &p_event, bool p_local_coords) {
ERR_FAIL_COND(!is_inside_tree());
- if (disable_input)
+ if (disable_input) {
return;
+ }
if (Engine::get_singleton()->is_editor_hint() && get_tree()->get_edited_scene_root() && get_tree()->get_edited_scene_root()->is_a_parent_of(this)) {
return;
@@ -2843,8 +2926,9 @@ void Viewport::input(const Ref<InputEvent> &p_event, bool p_local_coords) {
void Viewport::unhandled_input(const Ref<InputEvent> &p_event, bool p_local_coords) {
ERR_FAIL_COND(!is_inside_tree());
- if (disable_input)
+ if (disable_input) {
return;
+ }
if (Engine::get_singleton()->is_editor_hint() && get_tree()->get_edited_scene_root() && get_tree()->get_edited_scene_root()->is_a_parent_of(this)) {
return;
@@ -2879,11 +2963,13 @@ void Viewport::unhandled_input(const Ref<InputEvent> &p_event, bool p_local_coor
}
void Viewport::set_use_own_world_3d(bool p_world_3d) {
- if (p_world_3d == own_world_3d.is_valid())
+ if (p_world_3d == own_world_3d.is_valid()) {
return;
+ }
- if (is_inside_tree())
+ if (is_inside_tree()) {
_propagate_exit_world(this);
+ }
if (!p_world_3d) {
own_world_3d = Ref<World3D>();
@@ -2899,8 +2985,9 @@ void Viewport::set_use_own_world_3d(bool p_world_3d) {
}
}
- if (is_inside_tree())
+ if (is_inside_tree()) {
_propagate_enter_world(this);
+ }
if (is_inside_tree()) {
RenderingServer::get_singleton()->viewport_set_scenario(viewport, find_world_3d()->get_scenario());
@@ -2967,8 +3054,9 @@ int Viewport::gui_get_canvas_sort_index() {
void Viewport::set_msaa(MSAA p_msaa) {
ERR_FAIL_INDEX(p_msaa, MSAA_MAX);
- if (msaa == p_msaa)
+ if (msaa == p_msaa) {
return;
+ }
msaa = p_msaa;
RS::get_singleton()->viewport_set_msaa(viewport, RS::ViewportMSAA(p_msaa));
}
@@ -2979,8 +3067,9 @@ Viewport::MSAA Viewport::get_msaa() const {
void Viewport::set_screen_space_aa(ScreenSpaceAA p_screen_space_aa) {
ERR_FAIL_INDEX(p_screen_space_aa, SCREEN_SPACE_AA_MAX);
- if (screen_space_aa == p_screen_space_aa)
+ if (screen_space_aa == p_screen_space_aa) {
return;
+ }
screen_space_aa = p_screen_space_aa;
RS::get_singleton()->viewport_set_screen_space_aa(viewport, RS::ViewportScreenSpaceAA(p_screen_space_aa));
}
diff --git a/scene/main/window.cpp b/scene/main/window.cpp
index 0a38df5769..6565f02503 100644
--- a/scene/main/window.cpp
+++ b/scene/main/window.cpp
@@ -53,8 +53,9 @@ String Window::get_title() const {
void Window::set_current_screen(int p_screen) {
current_screen = p_screen;
- if (window_id == DisplayServer::INVALID_WINDOW_ID)
+ if (window_id == DisplayServer::INVALID_WINDOW_ID) {
return;
+ }
DisplayServer::get_singleton()->window_set_current_screen(p_screen, window_id);
}
@@ -862,8 +863,9 @@ void Window::child_controls_changed() {
}
void Window::_window_input(const Ref<InputEvent> &p_ev) {
- if (Engine::get_singleton()->is_editor_hint() && (Object::cast_to<InputEventJoypadButton>(p_ev.ptr()) || Object::cast_to<InputEventJoypadMotion>(*p_ev)))
+ if (Engine::get_singleton()->is_editor_hint() && (Object::cast_to<InputEventJoypadButton>(p_ev.ptr()) || Object::cast_to<InputEventJoypadMotion>(*p_ev))) {
return; //avoid joy input on editor
+ }
if (EngineDebugger::is_active()) {
//quit from game window using F8
@@ -1096,8 +1098,9 @@ void Window::remove_child_notify(Node *p_child) {
}
void Window::set_theme(const Ref<Theme> &p_theme) {
- if (theme == p_theme)
+ if (theme == p_theme) {
return;
+ }
theme = p_theme;
diff --git a/scene/resources/animation.cpp b/scene/resources/animation.cpp
index fb22b99b26..c9fc68233d 100644
--- a/scene/resources/animation.cpp
+++ b/scene/resources/animation.cpp
@@ -66,17 +66,17 @@ bool Animation::_set(const StringName &p_name, const Variant &p_value) {
ERR_FAIL_INDEX_V(track, tracks.size(), false);
- if (what == "path")
+ if (what == "path") {
track_set_path(track, p_value);
- else if (what == "interp")
+ } else if (what == "interp") {
track_set_interpolation_type(track, InterpolationType(p_value.operator int()));
- else if (what == "loop_wrap")
+ } else if (what == "loop_wrap") {
track_set_interpolation_loop_wrap(track, p_value);
- else if (what == "imported")
+ } else if (what == "imported") {
track_set_imported(track, p_value);
- else if (what == "enabled")
+ } else if (what == "enabled") {
track_set_enabled(track, p_value);
- else if (what == "keys" || what == "key_values") {
+ } else if (what == "keys" || what == "key_values") {
if (track_get_type(track) == TYPE_TRANSFORM) {
TransformTrack *tt = static_cast<TransformTrack *>(tracks[track]);
Vector<float> values = p_value;
@@ -119,10 +119,11 @@ bool Animation::_set(const StringName &p_name, const Variant &p_value) {
if (d.has("update")) {
int um = d["update"];
- if (um < 0)
+ if (um < 0) {
um = 0;
- else if (um > 3)
+ } else if (um > 3) {
um = 3;
+ }
vt->update_mode = UpdateMode(um);
}
@@ -158,8 +159,9 @@ bool Animation::_set(const StringName &p_name, const Variant &p_value) {
return true;
} else if (track_get_type(track) == TYPE_METHOD) {
- while (track_get_key_count(track))
+ while (track_get_key_count(track)) {
track_remove_key(track, 0); //well shouldn't be set anyway
+ }
Dictionary d = p_value;
ERR_FAIL_COND_V(!d.has("times"), false);
@@ -241,12 +243,15 @@ bool Animation::_set(const StringName &p_name, const Variant &p_value) {
for (int i = 0; i < valcount; i++) {
Dictionary d2 = clips[i];
- if (!d2.has("start_offset"))
+ if (!d2.has("start_offset")) {
continue;
- if (!d2.has("end_offset"))
+ }
+ if (!d2.has("end_offset")) {
continue;
- if (!d2.has("stream"))
+ }
+ if (!d2.has("stream")) {
continue;
+ }
TKey<AudioKey> ak;
ak.time = rt[i];
@@ -290,10 +295,12 @@ bool Animation::_set(const StringName &p_name, const Variant &p_value) {
} else {
return false;
}
- } else
+ } else {
return false;
- } else
+ }
+ } else {
return false;
+ }
return true;
}
@@ -301,13 +308,13 @@ bool Animation::_set(const StringName &p_name, const Variant &p_value) {
bool Animation::_get(const StringName &p_name, Variant &r_ret) const {
String name = p_name;
- if (name == "length")
+ if (name == "length") {
r_ret = length;
- else if (name == "loop")
+ } else if (name == "loop") {
r_ret = loop;
- else if (name == "step")
+ } else if (name == "step") {
r_ret = step;
- else if (name.begins_with("tracks/")) {
+ } else if (name.begins_with("tracks/")) {
int track = name.get_slicec('/', 1).to_int();
String what = name.get_slicec('/', 2);
ERR_FAIL_INDEX_V(track, tracks.size(), false);
@@ -335,17 +342,17 @@ bool Animation::_get(const StringName &p_name, Variant &r_ret) const {
return true;
- } else if (what == "path")
+ } else if (what == "path") {
r_ret = track_get_path(track);
- else if (what == "interp")
+ } else if (what == "interp") {
r_ret = track_get_interpolation_type(track);
- else if (what == "loop_wrap")
+ } else if (what == "loop_wrap") {
r_ret = track_get_interpolation_loop_wrap(track);
- else if (what == "imported")
+ } else if (what == "imported") {
r_ret = track_is_imported(track);
- else if (what == "enabled")
+ } else if (what == "enabled") {
r_ret = track_is_enabled(track);
- else if (what == "keys") {
+ } else if (what == "keys") {
if (track_get_type(track) == TYPE_TRANSFORM) {
Vector<float> keys;
int kk = track_get_key_count(track);
@@ -553,10 +560,12 @@ bool Animation::_get(const StringName &p_name, Variant &r_ret) const {
return true;
}
- } else
+ } else {
return false;
- } else
+ }
+ } else {
return false;
+ }
return true;
}
@@ -574,8 +583,9 @@ void Animation::_get_property_list(List<PropertyInfo> *p_list) const {
}
int Animation::add_track(TrackType p_type, int p_at_pos) {
- if (p_at_pos < 0 || p_at_pos >= tracks.size())
+ if (p_at_pos < 0 || p_at_pos >= tracks.size()) {
p_at_pos = tracks.size();
+ }
switch (p_type) {
case TYPE_TRANSFORM: {
@@ -677,8 +687,9 @@ NodePath Animation::track_get_path(int p_track) const {
int Animation::find_track(const NodePath &p_path) const {
for (int i = 0; i < tracks.size(); i++) {
- if (tracks[i]->path == p_path)
+ if (tracks[i]->path == p_path) {
return i;
+ }
};
return -1;
};
@@ -769,12 +780,15 @@ Error Animation::transform_track_get_key(int p_track, int p_key, Vector3 *r_loc,
ERR_FAIL_COND_V(t->type != TYPE_TRANSFORM, ERR_INVALID_PARAMETER);
ERR_FAIL_INDEX_V(p_key, tt->transforms.size(), ERR_INVALID_PARAMETER);
- if (r_loc)
+ if (r_loc) {
*r_loc = tt->transforms[p_key].value.loc;
- if (r_rot)
+ }
+ if (r_rot) {
*r_rot = tt->transforms[p_key].value.rot;
- if (r_scale)
+ }
+ if (r_scale) {
*r_scale = tt->transforms[p_key].value.scale;
+ }
return OK;
}
@@ -857,60 +871,72 @@ int Animation::track_find_key(int p_track, float p_time, bool p_exact) const {
case TYPE_TRANSFORM: {
TransformTrack *tt = static_cast<TransformTrack *>(t);
int k = _find(tt->transforms, p_time);
- if (k < 0 || k >= tt->transforms.size())
+ if (k < 0 || k >= tt->transforms.size()) {
return -1;
- if (tt->transforms[k].time != p_time && p_exact)
+ }
+ if (tt->transforms[k].time != p_time && p_exact) {
return -1;
+ }
return k;
} break;
case TYPE_VALUE: {
ValueTrack *vt = static_cast<ValueTrack *>(t);
int k = _find(vt->values, p_time);
- if (k < 0 || k >= vt->values.size())
+ if (k < 0 || k >= vt->values.size()) {
return -1;
- if (vt->values[k].time != p_time && p_exact)
+ }
+ if (vt->values[k].time != p_time && p_exact) {
return -1;
+ }
return k;
} break;
case TYPE_METHOD: {
MethodTrack *mt = static_cast<MethodTrack *>(t);
int k = _find(mt->methods, p_time);
- if (k < 0 || k >= mt->methods.size())
+ if (k < 0 || k >= mt->methods.size()) {
return -1;
- if (mt->methods[k].time != p_time && p_exact)
+ }
+ if (mt->methods[k].time != p_time && p_exact) {
return -1;
+ }
return k;
} break;
case TYPE_BEZIER: {
BezierTrack *bt = static_cast<BezierTrack *>(t);
int k = _find(bt->values, p_time);
- if (k < 0 || k >= bt->values.size())
+ if (k < 0 || k >= bt->values.size()) {
return -1;
- if (bt->values[k].time != p_time && p_exact)
+ }
+ if (bt->values[k].time != p_time && p_exact) {
return -1;
+ }
return k;
} break;
case TYPE_AUDIO: {
AudioTrack *at = static_cast<AudioTrack *>(t);
int k = _find(at->values, p_time);
- if (k < 0 || k >= at->values.size())
+ if (k < 0 || k >= at->values.size()) {
return -1;
- if (at->values[k].time != p_time && p_exact)
+ }
+ if (at->values[k].time != p_time && p_exact) {
return -1;
+ }
return k;
} break;
case TYPE_ANIMATION: {
AnimationTrack *at = static_cast<AnimationTrack *>(t);
int k = _find(at->values, p_time);
- if (k < 0 || k >= at->values.size())
+ if (k < 0 || k >= at->values.size()) {
return -1;
- if (at->values[k].time != p_time && p_exact)
+ }
+ if (at->values[k].time != p_time && p_exact) {
return -1;
+ }
return k;
} break;
@@ -927,16 +953,19 @@ void Animation::track_insert_key(int p_track, float p_time, const Variant &p_key
case TYPE_TRANSFORM: {
Dictionary d = p_key;
Vector3 loc;
- if (d.has("location"))
+ if (d.has("location")) {
loc = d["location"];
+ }
Quat rot;
- if (d.has("rotation"))
+ if (d.has("rotation")) {
rot = d["rotation"];
+ }
Vector3 scale;
- if (d.has("scale"))
+ if (d.has("scale")) {
scale = d["scale"];
+ }
int idx = transform_track_insert_key(p_track, p_time, loc, rot, scale);
track_set_key_transition(p_track, idx, p_transition);
@@ -1277,12 +1306,15 @@ void Animation::track_set_key_value(int p_track, int p_key_idx, const Variant &p
Dictionary d = p_value;
- if (d.has("location"))
+ if (d.has("location")) {
tt->transforms.write[p_key_idx].value.loc = d["location"];
- if (d.has("rotation"))
+ }
+ if (d.has("rotation")) {
tt->transforms.write[p_key_idx].value.rot = d["rotation"];
- if (d.has("scale"))
+ }
+ if (d.has("scale")) {
tt->transforms.write[p_key_idx].value.scale = d["scale"];
+ }
} break;
case TYPE_VALUE: {
@@ -1298,10 +1330,12 @@ void Animation::track_set_key_value(int p_track, int p_key_idx, const Variant &p
Dictionary d = p_value;
- if (d.has("method"))
+ if (d.has("method")) {
mt->methods.write[p_key_idx].method = d["method"];
- if (d.has("args"))
+ }
+ if (d.has("args")) {
mt->methods.write[p_key_idx].params = d["args"];
+ }
} break;
case TYPE_BEZIER: {
@@ -1379,16 +1413,18 @@ void Animation::track_set_key_transition(int p_track, int p_key_idx, float p_tra
template <class K>
int Animation::_find(const Vector<K> &p_keys, float p_time) const {
int len = p_keys.size();
- if (len == 0)
+ if (len == 0) {
return -2;
+ }
int low = 0;
int high = len - 1;
int middle = 0;
#ifdef DEBUG_ENABLED
- if (low > high)
+ if (low > high) {
ERR_PRINT("low > high, this may be a bug");
+ }
#endif
const K *keys = &p_keys[0];
@@ -1398,14 +1434,16 @@ int Animation::_find(const Vector<K> &p_keys, float p_time) const {
if (Math::is_equal_approx(p_time, keys[middle].time)) { //match
return middle;
- } else if (p_time < keys[middle].time)
+ } else if (p_time < keys[middle].time) {
high = middle - 1; //search low end of array
- else
+ } else {
low = middle + 1; //search high end of array
+ }
}
- if (keys[middle].time > p_time)
+ if (keys[middle].time > p_time) {
middle--;
+ }
return middle;
}
@@ -1551,13 +1589,15 @@ T Animation::_interpolate(const Vector<TKey<T>> &p_keys, float p_time, Interpola
if (len <= 0) {
// (-1 or -2 returned originally) (plus one above)
// meaning no keys, or only key time is larger than length
- if (p_ok)
+ if (p_ok) {
*p_ok = false;
+ }
return T();
} else if (len == 1) { // one key found (0+1), return it
- if (p_ok)
+ if (p_ok) {
*p_ok = true;
+ }
return p_keys[0].value;
}
@@ -1578,20 +1618,22 @@ T Animation::_interpolate(const Vector<TKey<T>> &p_keys, float p_time, Interpola
float delta = p_keys[next].time - p_keys[idx].time;
float from = p_time - p_keys[idx].time;
- if (Math::is_zero_approx(delta))
+ if (Math::is_zero_approx(delta)) {
c = 0;
- else
+ } else {
c = from / delta;
+ }
} else {
next = 0;
float delta = (length - p_keys[idx].time) + p_keys[next].time;
float from = p_time - p_keys[idx].time;
- if (Math::is_zero_approx(delta))
+ if (Math::is_zero_approx(delta)) {
c = 0;
- else
+ } else {
c = from / delta;
+ }
}
} else {
@@ -1599,15 +1641,17 @@ T Animation::_interpolate(const Vector<TKey<T>> &p_keys, float p_time, Interpola
idx = len - 1;
next = 0;
float endtime = (length - p_keys[idx].time);
- if (endtime < 0) // may be keys past the end
+ if (endtime < 0) { // may be keys past the end
endtime = 0;
+ }
float delta = endtime + p_keys[next].time;
float from = endtime + p_time;
- if (Math::is_zero_approx(delta))
+ if (Math::is_zero_approx(delta)) {
c = 0;
- else
+ } else {
c = from / delta;
+ }
}
} else { // no loop
@@ -1618,10 +1662,11 @@ T Animation::_interpolate(const Vector<TKey<T>> &p_keys, float p_time, Interpola
float delta = p_keys[next].time - p_keys[idx].time;
float from = p_time - p_keys[idx].time;
- if (Math::is_zero_approx(delta))
+ if (Math::is_zero_approx(delta)) {
c = 0;
- else
+ } else {
c = from / delta;
+ }
} else {
next = idx;
@@ -1629,17 +1674,20 @@ T Animation::_interpolate(const Vector<TKey<T>> &p_keys, float p_time, Interpola
} else {
// only allow extending first key to anim start if looping
- if (loop)
+ if (loop) {
idx = next = 0;
- else
+ } else {
result = false;
+ }
}
}
- if (p_ok)
+ if (p_ok) {
*p_ok = result;
- if (!result)
+ }
+ if (!result) {
return T();
+ }
float tr = p_keys[idx].transition;
@@ -1661,11 +1709,13 @@ T Animation::_interpolate(const Vector<TKey<T>> &p_keys, float p_time, Interpola
} break;
case INTERPOLATION_CUBIC: {
int pre = idx - 1;
- if (pre < 0)
+ if (pre < 0) {
pre = 0;
+ }
int post = next + 1;
- if (post >= len)
+ if (post >= len) {
post = next;
+ }
return _cubic_interpolate(p_keys[pre].value, p_keys[idx].value, p_keys[next].value, p_keys[post].value, c);
@@ -1688,17 +1738,21 @@ Error Animation::transform_track_interpolate(int p_track, float p_time, Vector3
TransformKey tk = _interpolate(tt->transforms, p_time, tt->interpolation, tt->loop_wrap, &ok);
- if (!ok)
+ if (!ok) {
return ERR_UNAVAILABLE;
+ }
- if (r_loc)
+ if (r_loc) {
*r_loc = tk.loc;
+ }
- if (r_rot)
+ if (r_rot) {
*r_rot = tk.rot;
+ }
- if (r_scale)
+ if (r_scale) {
*r_scale = tk.scale;
+ }
return OK;
}
@@ -1721,8 +1775,9 @@ Variant Animation::value_track_interpolate(int p_track, float p_time) const {
}
void Animation::_value_track_get_key_indices_in_range(const ValueTrack *vt, float from_time, float to_time, List<int> *p_indices) const {
- if (from_time != length && to_time == length)
+ if (from_time != length && to_time == length) {
to_time = length * 1.001; //include a little more if at the end
+ }
int to = _find(vt->values, to_time);
if (to >= 0 && from_time == to_time && vt->values[to].time == from_time) {
@@ -1733,17 +1788,20 @@ void Animation::_value_track_get_key_indices_in_range(const ValueTrack *vt, floa
// can't really send the events == time, will be sent in the next frame.
// if event>=len then it will probably never be requested by the anim player.
- if (to >= 0 && vt->values[to].time >= to_time)
+ if (to >= 0 && vt->values[to].time >= to_time) {
to--;
+ }
- if (to < 0)
+ if (to < 0) {
return; // not bother
+ }
int from = _find(vt->values, from_time);
// position in the right first event.+
- if (from < 0 || vt->values[from].time < from_time)
+ if (from < 0 || vt->values[from].time < from_time) {
from++;
+ }
int max = vt->values.size();
@@ -1763,8 +1821,9 @@ void Animation::value_track_get_key_indices(int p_track, float p_time, float p_d
float from_time = p_time - p_delta;
float to_time = p_time;
- if (from_time > to_time)
+ if (from_time > to_time) {
SWAP(from_time, to_time);
+ }
if (loop) {
from_time = Math::fposmod(from_time, length);
@@ -1777,15 +1836,19 @@ void Animation::value_track_get_key_indices(int p_track, float p_time, float p_d
return;
}
} else {
- if (from_time < 0)
+ if (from_time < 0) {
from_time = 0;
- if (from_time > length)
+ }
+ if (from_time > length) {
from_time = length;
+ }
- if (to_time < 0)
+ if (to_time < 0) {
to_time = 0;
- if (to_time > length)
+ }
+ if (to_time > length) {
to_time = length;
+ }
}
_value_track_get_key_indices_in_range(vt, from_time, to_time, p_indices);
@@ -1812,25 +1875,29 @@ Animation::UpdateMode Animation::value_track_get_update_mode(int p_track) const
template <class T>
void Animation::_track_get_key_indices_in_range(const Vector<T> &p_array, float from_time, float to_time, List<int> *p_indices) const {
- if (from_time != length && to_time == length)
+ if (from_time != length && to_time == length) {
to_time = length * 1.01; //include a little more if at the end
+ }
int to = _find(p_array, to_time);
// can't really send the events == time, will be sent in the next frame.
// if event>=len then it will probably never be requested by the anim player.
- if (to >= 0 && p_array[to].time >= to_time)
+ if (to >= 0 && p_array[to].time >= to_time) {
to--;
+ }
- if (to < 0)
+ if (to < 0) {
return; // not bother
+ }
int from = _find(p_array, from_time);
// position in the right first event.+
- if (from < 0 || p_array[from].time < from_time)
+ if (from < 0 || p_array[from].time < from_time) {
from++;
+ }
int max = p_array.size();
@@ -1847,15 +1914,18 @@ void Animation::track_get_key_indices_in_range(int p_track, float p_time, float
float from_time = p_time - p_delta;
float to_time = p_time;
- if (from_time > to_time)
+ if (from_time > to_time) {
SWAP(from_time, to_time);
+ }
if (loop) {
- if (from_time > length || from_time < 0)
+ if (from_time > length || from_time < 0) {
from_time = Math::fposmod(from_time, length);
+ }
- if (to_time > length || to_time < 0)
+ if (to_time > length || to_time < 0) {
to_time = Math::fposmod(to_time, length);
+ }
if (from_time > to_time) {
// handle loop by splitting
@@ -1901,15 +1971,19 @@ void Animation::track_get_key_indices_in_range(int p_track, float p_time, float
return;
}
} else {
- if (from_time < 0)
+ if (from_time < 0) {
from_time = 0;
- if (from_time > length)
+ }
+ if (from_time > length) {
from_time = length;
+ }
- if (to_time < 0)
+ if (to_time < 0) {
to_time = 0;
- if (to_time > length)
+ }
+ if (to_time > length) {
to_time = length;
+ }
}
switch (t->type) {
@@ -1947,25 +2021,29 @@ void Animation::track_get_key_indices_in_range(int p_track, float p_time, float
}
void Animation::_method_track_get_key_indices_in_range(const MethodTrack *mt, float from_time, float to_time, List<int> *p_indices) const {
- if (from_time != length && to_time == length)
+ if (from_time != length && to_time == length) {
to_time = length * 1.01; //include a little more if at the end
+ }
int to = _find(mt->methods, to_time);
// can't really send the events == time, will be sent in the next frame.
// if event>=len then it will probably never be requested by the anim player.
- if (to >= 0 && mt->methods[to].time >= to_time)
+ if (to >= 0 && mt->methods[to].time >= to_time) {
to--;
+ }
- if (to < 0)
+ if (to < 0) {
return; // not bother
+ }
int from = _find(mt->methods, from_time);
// position in the right first event.+
- if (from < 0 || mt->methods[from].time < from_time)
+ if (from < 0 || mt->methods[from].time < from_time) {
from++;
+ }
int max = mt->methods.size();
@@ -1985,15 +2063,18 @@ void Animation::method_track_get_key_indices(int p_track, float p_time, float p_
float from_time = p_time - p_delta;
float to_time = p_time;
- if (from_time > to_time)
+ if (from_time > to_time) {
SWAP(from_time, to_time);
+ }
if (loop) {
- if (from_time > length || from_time < 0)
+ if (from_time > length || from_time < 0) {
from_time = Math::fposmod(from_time, length);
+ }
- if (to_time > length || to_time < 0)
+ if (to_time > length || to_time < 0) {
to_time = Math::fposmod(to_time, length);
+ }
if (from_time > to_time) {
// handle loop by splitting
@@ -2002,15 +2083,19 @@ void Animation::method_track_get_key_indices(int p_track, float p_time, float p_
return;
}
} else {
- if (from_time < 0)
+ if (from_time < 0) {
from_time = 0;
- if (from_time > length)
+ }
+ if (from_time > length) {
from_time = length;
+ }
- if (to_time < 0)
+ if (to_time < 0) {
to_time = 0;
- if (to_time > length)
+ }
+ if (to_time > length) {
to_time = length;
+ }
}
_method_track_get_key_indices_in_range(mt, from_time, to_time, p_indices);
@@ -2237,11 +2322,13 @@ int Animation::audio_track_insert_key(int p_track, float p_time, const RES &p_st
k.time = p_time;
k.value.stream = p_stream;
k.value.start_offset = p_start_offset;
- if (k.value.start_offset < 0)
+ if (k.value.start_offset < 0) {
k.value.start_offset = 0;
+ }
k.value.end_offset = p_end_offset;
- if (k.value.end_offset < 0)
+ if (k.value.end_offset < 0) {
k.value.end_offset = 0;
+ }
int key = _insert(p_time, at->values, k);
@@ -2273,8 +2360,9 @@ void Animation::audio_track_set_key_start_offset(int p_track, int p_key, float p
ERR_FAIL_INDEX(p_key, at->values.size());
- if (p_offset < 0)
+ if (p_offset < 0) {
p_offset = 0;
+ }
at->values.write[p_key].value.start_offset = p_offset;
@@ -2290,8 +2378,9 @@ void Animation::audio_track_set_key_end_offset(int p_track, int p_key, float p_o
ERR_FAIL_INDEX(p_key, at->values.size());
- if (p_offset < 0)
+ if (p_offset < 0) {
p_offset = 0;
+ }
at->values.write[p_key].value.end_offset = p_offset;
@@ -2443,8 +2532,9 @@ void Animation::track_move_down(int p_track) {
void Animation::track_move_to(int p_track, int p_to_index) {
ERR_FAIL_INDEX(p_track, tracks.size());
ERR_FAIL_INDEX(p_to_index, tracks.size() + 1);
- if (p_track == p_to_index || p_track == p_to_index - 1)
+ if (p_track == p_to_index || p_track == p_to_index - 1) {
return;
+ }
Track *track = tracks.get(p_track);
tracks.remove(p_track);
@@ -2458,8 +2548,9 @@ void Animation::track_move_to(int p_track, int p_to_index) {
void Animation::track_swap(int p_track, int p_with_track) {
ERR_FAIL_INDEX(p_track, tracks.size());
ERR_FAIL_INDEX(p_with_track, tracks.size());
- if (p_track == p_with_track)
+ if (p_track == p_with_track) {
return;
+ }
SWAP(tracks.write[p_track], tracks.write[p_with_track]);
emit_changed();
@@ -2602,8 +2693,9 @@ void Animation::_bind_methods() {
}
void Animation::clear() {
- for (int i = 0; i < tracks.size(); i++)
+ for (int i = 0; i < tracks.size(); i++) {
memdelete(tracks[i]);
+ }
tracks.clear();
loop = false;
length = 1;
@@ -2644,8 +2736,9 @@ bool Animation::_transform_track_optimize_key(const TKey<TransformKey> &t0, cons
return false; //beyond allowed error for colinearity
}
- if (p_norm != Vector3() && Math::acos(pd.normalized().dot(p_norm)) > p_alowed_angular_err)
+ if (p_norm != Vector3() && Math::acos(pd.normalized().dot(p_norm)) > p_alowed_angular_err) {
return false;
+ }
t[0] = (d1 - d0) / (d2 - d0);
}
@@ -2660,8 +2753,9 @@ bool Animation::_transform_track_optimize_key(const TKey<TransformKey> &t0, cons
//localize both to rotation from q0
if (q0.is_equal_approx(q2)) {
- if (!q0.is_equal_approx(q1))
+ if (!q0.is_equal_approx(q1)) {
return false;
+ }
} else {
Quat r02 = (q0.inverse() * q2).normalized();
@@ -2673,8 +2767,9 @@ bool Animation::_transform_track_optimize_key(const TKey<TransformKey> &t0, cons
r02.get_axis_angle(v02, a02);
r01.get_axis_angle(v01, a01);
- if (Math::abs(a02) > p_max_optimizable_angle)
+ if (Math::abs(a02) > p_max_optimizable_angle) {
return false;
+ }
if (v01.dot(v02) < 0) {
//make sure both rotations go the same way to compare
@@ -2694,8 +2789,9 @@ bool Animation::_transform_track_optimize_key(const TKey<TransformKey> &t0, cons
}
real_t tr = a01 / a02;
- if (tr < 0 || tr > 1)
+ if (tr < 0 || tr > 1) {
return false; //rotating too much or too less
+ }
t[1] = tr;
}
@@ -2746,8 +2842,9 @@ bool Animation::_transform_track_optimize_key(const TKey<TransformKey> &t0, cons
lt = t[j]; //official t
//validate rest
for (int k = j + 1; k < 3; k++) {
- if (t[k] == -1)
+ if (t[k] == -1) {
continue;
+ }
if (Math::abs(lt - t[k]) > p_alowed_linear_err) {
erase = false;
@@ -2815,8 +2912,9 @@ void Animation::_transform_track_optimize(int p_idx, float p_allowed_linear_err,
void Animation::optimize(float p_allowed_linear_err, float p_allowed_angular_err, float p_max_optimizable_angle) {
for (int i = 0; i < tracks.size(); i++) {
- if (tracks[i]->type == TYPE_TRANSFORM)
+ if (tracks[i]->type == TYPE_TRANSFORM) {
_transform_track_optimize(i, p_allowed_linear_err, p_allowed_angular_err, p_max_optimizable_angle);
+ }
}
}
@@ -2827,6 +2925,7 @@ Animation::Animation() {
}
Animation::~Animation() {
- for (int i = 0; i < tracks.size(); i++)
+ for (int i = 0; i < tracks.size(); i++) {
memdelete(tracks[i]);
+ }
}
diff --git a/scene/resources/audio_stream_sample.cpp b/scene/resources/audio_stream_sample.cpp
index dafcf12183..f02e7987a9 100644
--- a/scene/resources/audio_stream_sample.cpp
+++ b/scene/resources/audio_stream_sample.cpp
@@ -72,8 +72,9 @@ float AudioStreamPlaybackSample::get_playback_position() const {
}
void AudioStreamPlaybackSample::seek(float p_time) {
- if (base->format == AudioStreamSample::FORMAT_IMA_ADPCM)
+ if (base->format == AudioStreamSample::FORMAT_IMA_ADPCM) {
return; //no seeking in ima-adpcm
+ }
float max = base->get_length();
if (p_time < 0) {
@@ -93,8 +94,9 @@ void AudioStreamPlaybackSample::do_resample(const Depth *p_src, AudioFrame *p_ds
while (amount) {
amount--;
int64_t pos = offset >> MIX_FRAC_BITS;
- if (is_stereo && !is_ima_adpcm)
+ if (is_stereo && !is_ima_adpcm) {
pos <<= 1;
+ }
if (is_ima_adpcm) {
int64_t sample_pos = pos + ima_adpcm[0].window_ofs;
@@ -129,26 +131,33 @@ void AudioStreamPlaybackSample::do_resample(const Depth *p_src, AudioFrame *p_ds
step = _ima_adpcm_step_table[ima_adpcm[i].step_index];
ima_adpcm[i].step_index += _ima_adpcm_index_table[nibble];
- if (ima_adpcm[i].step_index < 0)
+ if (ima_adpcm[i].step_index < 0) {
ima_adpcm[i].step_index = 0;
- if (ima_adpcm[i].step_index > 88)
+ }
+ if (ima_adpcm[i].step_index > 88) {
ima_adpcm[i].step_index = 88;
+ }
diff = step >> 3;
- if (nibble & 1)
+ if (nibble & 1) {
diff += step >> 2;
- if (nibble & 2)
+ }
+ if (nibble & 2) {
diff += step >> 1;
- if (nibble & 4)
+ }
+ if (nibble & 4) {
diff += step;
- if (nibble & 8)
+ }
+ if (nibble & 8) {
diff = -diff;
+ }
ima_adpcm[i].predictor += diff;
- if (ima_adpcm[i].predictor < -0x8000)
+ if (ima_adpcm[i].predictor < -0x8000) {
ima_adpcm[i].predictor = -0x8000;
- else if (ima_adpcm[i].predictor > 0x7FFF)
+ } else if (ima_adpcm[i].predictor > 0x7FFF) {
ima_adpcm[i].predictor = 0x7FFF;
+ }
/* store loop if there */
if (ima_adpcm[i].last_nibble == ima_adpcm[i].loop_pos) {
@@ -167,13 +176,15 @@ void AudioStreamPlaybackSample::do_resample(const Depth *p_src, AudioFrame *p_ds
} else {
final = p_src[pos];
- if (is_stereo)
+ if (is_stereo) {
final_r = p_src[pos + 1];
+ }
if (sizeof(Depth) == 1) { /* conditions will not exist anymore when compiled! */
final <<= 8;
- if (is_stereo)
+ if (is_stereo) {
final_r <<= 8;
+ }
}
if (is_stereo) {
@@ -185,15 +196,17 @@ void AudioStreamPlaybackSample::do_resample(const Depth *p_src, AudioFrame *p_ds
if (sizeof(Depth) == 1) {
next <<= 8;
- if (is_stereo)
+ if (is_stereo) {
next_r <<= 8;
+ }
}
int32_t frac = int64_t(offset & MIX_FRAC_MASK);
final = final + ((next - final) * frac >> MIX_FRAC_BITS);
- if (is_stereo)
+ if (is_stereo) {
final_r = final_r + ((next_r - final_r) * frac >> MIX_FRAC_BITS);
+ }
}
if (!is_stereo) {
@@ -353,23 +366,26 @@ void AudioStreamPlaybackSample::mix(AudioFrame *p_buffer, float p_rate_scale, in
switch (base->format) {
case AudioStreamSample::FORMAT_8_BITS: {
- if (is_stereo)
+ if (is_stereo) {
do_resample<int8_t, true, false>((int8_t *)data, dst_buff, offset, increment, target, ima_adpcm);
- else
+ } else {
do_resample<int8_t, false, false>((int8_t *)data, dst_buff, offset, increment, target, ima_adpcm);
+ }
} break;
case AudioStreamSample::FORMAT_16_BITS: {
- if (is_stereo)
+ if (is_stereo) {
do_resample<int16_t, true, false>((int16_t *)data, dst_buff, offset, increment, target, ima_adpcm);
- else
+ } else {
do_resample<int16_t, false, false>((int16_t *)data, dst_buff, offset, increment, target, ima_adpcm);
+ }
} break;
case AudioStreamSample::FORMAT_IMA_ADPCM: {
- if (is_stereo)
+ if (is_stereo) {
do_resample<int8_t, true, true>((int8_t *)data, dst_buff, offset, increment, target, ima_adpcm);
- else
+ } else {
do_resample<int8_t, false, true>((int8_t *)data, dst_buff, offset, increment, target, ima_adpcm);
+ }
} break;
}
diff --git a/scene/resources/bit_map.cpp b/scene/resources/bit_map.cpp
index e23e3f4c4d..10f0de8ff8 100644
--- a/scene/resources/bit_map.cpp
+++ b/scene/resources/bit_map.cpp
@@ -74,10 +74,11 @@ void BitMap::set_bit_rect(const Rect2 &p_rect, bool p_value) {
uint8_t b = data[bbyte];
- if (p_value)
+ if (p_value) {
b |= (1 << bbit);
- else
+ } else {
b &= ~(1 << bbit);
+ }
data[bbyte] = b;
}
@@ -118,10 +119,11 @@ void BitMap::set_bit(const Point2 &p_pos, bool p_value) {
uint8_t b = bitmask[bbyte];
- if (p_value)
+ if (p_value) {
b |= (1 << bbit);
- else
+ } else {
b &= ~(1 << bbit);
+ }
bitmask.write[bbyte] = b;
}
@@ -339,8 +341,9 @@ static float perpendicular_distance(const Vector2 &i, const Vector2 &start, cons
}
static Vector<Vector2> rdp(const Vector<Vector2> &v, float optimization) {
- if (v.size() < 3)
+ if (v.size() < 3) {
return v;
+ }
int index = -1;
float dist = 0;
@@ -436,15 +439,17 @@ static void fill_bits(const BitMap *p_src, Ref<BitMap> &p_map, const Point2i &p_
continue;
}
- if (i < rect.position.x || i >= rect.position.x + rect.size.x)
+ if (i < rect.position.x || i >= rect.position.x + rect.size.x) {
continue;
- if (j < rect.position.y || j >= rect.position.y + rect.size.y)
+ }
+ if (j < rect.position.y || j >= rect.position.y + rect.size.y) {
continue;
+ }
- if (p_map->get_bit(Vector2(i, j)))
+ if (p_map->get_bit(Vector2(i, j))) {
continue;
- else if (p_src->get_bit(Vector2(i, j))) {
+ } else if (p_src->get_bit(Vector2(i, j))) {
p_map->set_bit(Vector2(i, j), true);
FillBitsStackEntry se = { pos, i, j };
@@ -526,8 +531,9 @@ void BitMap::grow_mask(int p_pixels, const Rect2 &p_rect) {
for (int i = r.position.y; i < r.position.y + r.size.height; i++) {
for (int j = r.position.x; j < r.position.x + r.size.width; j++) {
- if (bit_value == get_bit(Point2(j, i)))
+ if (bit_value == get_bit(Point2(j, i))) {
continue;
+ }
bool found = false;
@@ -537,23 +543,26 @@ void BitMap::grow_mask(int p_pixels, const Rect2 &p_rect) {
if ((x < p_rect.position.x) || (x >= p_rect.position.x + p_rect.size.x) || (y < p_rect.position.y) || (y >= p_rect.position.y + p_rect.size.y)) {
// outside of rectangle counts as bit not set
- if (!bit_value)
+ if (!bit_value) {
outside = true;
- else
+ } else {
continue;
+ }
}
float d = Point2(j, i).distance_to(Point2(x, y)) - CMP_EPSILON;
- if (d > p_pixels)
+ if (d > p_pixels) {
continue;
+ }
if (outside || (bit_value == copy->get_bit(Point2(x, y)))) {
found = true;
break;
}
}
- if (found)
+ if (found) {
break;
+ }
}
if (found) {
@@ -634,10 +643,12 @@ void BitMap::blit(const Vector2 &p_pos, const Ref<BitMap> &p_bitmap) {
for (int j = 0; j < h; j++) {
int px = x + i;
int py = y + j;
- if (px < 0 || px >= width)
+ if (px < 0 || px >= width) {
continue;
- if (py < 0 || py >= height)
+ }
+ if (py < 0 || py >= height) {
continue;
+ }
if (p_bitmap->get_bit(Vector2(i, j))) {
set_bit(Vector2(x, y), true);
}
diff --git a/scene/resources/capsule_shape_2d.cpp b/scene/resources/capsule_shape_2d.cpp
index 1054365459..0e784e04ff 100644
--- a/scene/resources/capsule_shape_2d.cpp
+++ b/scene/resources/capsule_shape_2d.cpp
@@ -39,8 +39,9 @@ Vector<Vector2> CapsuleShape2D::_get_points() const {
Vector2 ofs = Vector2(0, (i > 6 && i <= 18) ? -get_height() * 0.5 : get_height() * 0.5);
points.push_back(Vector2(Math::sin(i * Math_PI * 2 / 24.0), Math::cos(i * Math_PI * 2 / 24.0)) * get_radius() + ofs);
- if (i == 6 || i == 18)
+ if (i == 6 || i == 18) {
points.push_back(Vector2(Math::sin(i * Math_PI * 2 / 24.0), Math::cos(i * Math_PI * 2 / 24.0)) * get_radius() - ofs);
+ }
}
return points;
@@ -66,8 +67,9 @@ real_t CapsuleShape2D::get_radius() const {
void CapsuleShape2D::set_height(real_t p_height) {
height = p_height;
- if (height < 0)
+ if (height < 0) {
height = 0;
+ }
_update_shape();
}
diff --git a/scene/resources/concave_polygon_shape_2d.cpp b/scene/resources/concave_polygon_shape_2d.cpp
index 9cc8ea0fac..2154633111 100644
--- a/scene/resources/concave_polygon_shape_2d.cpp
+++ b/scene/resources/concave_polygon_shape_2d.cpp
@@ -36,14 +36,16 @@
bool ConcavePolygonShape2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const {
Vector<Vector2> s = get_segments();
int len = s.size();
- if (len == 0 || (len % 2) == 1)
+ if (len == 0 || (len % 2) == 1) {
return false;
+ }
const Vector2 *r = s.ptr();
for (int i = 0; i < len; i += 2) {
Vector2 closest = Geometry::get_closest_point_to_segment_2d(p_point, &r[i]);
- if (p_point.distance_to(closest) < p_tolerance)
+ if (p_point.distance_to(closest) < p_tolerance) {
return true;
+ }
}
return false;
@@ -61,8 +63,9 @@ Vector<Vector2> ConcavePolygonShape2D::get_segments() const {
void ConcavePolygonShape2D::draw(const RID &p_to_rid, const Color &p_color) {
Vector<Vector2> s = get_segments();
int len = s.size();
- if (len == 0 || (len % 2) == 1)
+ if (len == 0 || (len % 2) == 1) {
return;
+ }
const Vector2 *r = s.ptr();
for (int i = 0; i < len; i += 2) {
@@ -73,17 +76,19 @@ void ConcavePolygonShape2D::draw(const RID &p_to_rid, const Color &p_color) {
Rect2 ConcavePolygonShape2D::get_rect() const {
Vector<Vector2> s = get_segments();
int len = s.size();
- if (len == 0)
+ if (len == 0) {
return Rect2();
+ }
Rect2 rect;
const Vector2 *r = s.ptr();
for (int i = 0; i < len; i++) {
- if (i == 0)
+ if (i == 0) {
rect.position = r[i];
- else
+ } else {
rect.expand_to(r[i]);
+ }
}
return rect;
diff --git a/scene/resources/concave_polygon_shape_3d.h b/scene/resources/concave_polygon_shape_3d.h
index 3646724131..c268ed9f37 100644
--- a/scene/resources/concave_polygon_shape_3d.h
+++ b/scene/resources/concave_polygon_shape_3d.h
@@ -40,10 +40,11 @@ class ConcavePolygonShape3D : public Shape3D {
Vector3 a;
Vector3 b;
bool operator<(const DrawEdge &p_edge) const {
- if (a == p_edge.a)
+ if (a == p_edge.a) {
return b < p_edge.b;
- else
+ } else {
return a < p_edge.a;
+ }
}
DrawEdge(const Vector3 &p_a = Vector3(), const Vector3 &p_b = Vector3()) {
diff --git a/scene/resources/convex_polygon_shape_2d.cpp b/scene/resources/convex_polygon_shape_2d.cpp
index 59b2e3a9cd..7df7c3ac72 100644
--- a/scene/resources/convex_polygon_shape_2d.cpp
+++ b/scene/resources/convex_polygon_shape_2d.cpp
@@ -80,10 +80,11 @@ void ConvexPolygonShape2D::draw(const RID &p_to_rid, const Color &p_color) {
Rect2 ConvexPolygonShape2D::get_rect() const {
Rect2 rect;
for (int i = 0; i < points.size(); i++) {
- if (i == 0)
+ if (i == 0) {
rect.position = points[i];
- else
+ } else {
rect.expand_to(points[i]);
+ }
}
return rect;
diff --git a/scene/resources/curve.cpp b/scene/resources/curve.cpp
index 9c3e5ad437..de076670cf 100644
--- a/scene/resources/curve.cpp
+++ b/scene/resources/curve.cpp
@@ -58,10 +58,11 @@ int Curve::add_point(Vector2 p_pos, real_t left_tangent, real_t right_tangent, T
// Add a point and preserve order
// Curve bounds is in 0..1
- if (p_pos.x > MAX_X)
+ if (p_pos.x > MAX_X) {
p_pos.x = MAX_X;
- else if (p_pos.x < MIN_X)
+ } else if (p_pos.x < MIN_X) {
p_pos.x = MIN_X;
+ }
int ret = -1;
@@ -128,8 +129,9 @@ int Curve::get_index(real_t offset) const {
}
// Will happen if the offset is out of bounds
- if (offset > _points[imax].pos.x)
+ if (offset > _points[imax].pos.x) {
return imax;
+ }
return imin;
}
@@ -145,8 +147,9 @@ void Curve::clean_dupes() {
}
}
- if (dirty)
+ if (dirty) {
mark_dirty();
+ }
}
void Curve::set_point_left_tangent(int i, real_t tangent) {
@@ -234,8 +237,9 @@ int Curve::set_point_offset(int p_index, float offset) {
_points.write[i].right_tangent = p.right_tangent;
_points.write[i].left_mode = p.left_mode;
_points.write[i].right_mode = p.right_mode;
- if (p_index != i)
+ if (p_index != i) {
update_auto_tangents(p_index);
+ }
update_auto_tangents(i);
return i;
}
@@ -301,20 +305,24 @@ void Curve::set_max_value(float p_max) {
}
real_t Curve::interpolate(real_t offset) const {
- if (_points.size() == 0)
+ if (_points.size() == 0) {
return 0;
- if (_points.size() == 1)
+ }
+ if (_points.size() == 1) {
return _points[0].pos.y;
+ }
int i = get_index(offset);
- if (i == _points.size() - 1)
+ if (i == _points.size() - 1) {
return _points[i].pos.y;
+ }
real_t local = offset - _points[i].pos.x;
- if (i == 0 && local <= 0)
+ if (i == 0 && local <= 0) {
return _points[0].pos.y;
+ }
return interpolate_local_nocheck(i, local);
}
@@ -339,8 +347,9 @@ real_t Curve::interpolate_local_nocheck(int index, real_t local_offset) const {
// Control points are chosen at equal distances
real_t d = b.pos.x - a.pos.x;
- if (Math::abs(d) <= CMP_EPSILON)
+ if (Math::abs(d) <= CMP_EPSILON) {
return b.pos.y;
+ }
local_offset /= d;
d /= 3.0;
real_t yac = a.pos.y + d * a.right_tangent;
@@ -449,8 +458,9 @@ real_t Curve::interpolate_baked(real_t offset) {
// Special cases if the cache is too small
if (_baked_cache.size() == 0) {
- if (_points.size() == 0)
+ if (_points.size() == 0) {
return 0;
+ }
return _points[0].pos.y;
} else if (_baked_cache.size() == 1) {
return _baked_cache[0];
@@ -535,10 +545,11 @@ void Curve2D::add_point(const Vector2 &p_pos, const Vector2 &p_in, const Vector2
n.pos = p_pos;
n.in = p_in;
n.out = p_out;
- if (p_atpos >= 0 && p_atpos < points.size())
+ if (p_atpos >= 0 && p_atpos < points.size()) {
points.insert(p_atpos, n);
- else
+ } else {
points.push_back(n);
+ }
baked_cache_dirty = true;
emit_signal(CoreStringNames::get_singleton()->changed);
@@ -602,10 +613,11 @@ Vector2 Curve2D::interpolate(int p_index, float p_offset) const {
int pc = points.size();
ERR_FAIL_COND_V(pc == 0, Vector2());
- if (p_index >= pc - 1)
+ if (p_index >= pc - 1) {
return points[pc - 1].pos;
- else if (p_index < 0)
+ } else if (p_index < 0) {
return points[0].pos;
+ }
Vector2 p0 = points[p_index].pos;
Vector2 p1 = p0 + points[p_index].out;
@@ -616,10 +628,11 @@ Vector2 Curve2D::interpolate(int p_index, float p_offset) const {
}
Vector2 Curve2D::interpolatef(real_t p_findex) const {
- if (p_findex < 0)
+ if (p_findex < 0) {
p_findex = 0;
- else if (p_findex >= points.size())
+ } else if (p_findex >= points.size()) {
p_findex = points.size();
+ }
return interpolate((int)p_findex, Math::fmod(p_findex, (real_t)1.0));
}
@@ -645,8 +658,9 @@ void Curve2D::_bake_segment2d(Map<float, Vector2> &r_bake, float p_begin, float
}
void Curve2D::_bake() const {
- if (!baked_cache_dirty)
+ if (!baked_cache_dirty) {
return;
+ }
baked_max_ofs = 0;
baked_cache_dirty = false;
@@ -673,8 +687,9 @@ void Curve2D::_bake() const {
while (p < 1.0) {
float np = p + step;
- if (np > 1.0)
+ if (np > 1.0) {
np = 1.0;
+ }
Vector2 npp = _bezier_interp(np, points[i].pos, points[i].pos + points[i].out, points[i + 1].pos + points[i + 1].in, points[i + 1].pos);
float d = pos.distance_to(npp);
@@ -692,10 +707,11 @@ void Curve2D::_bake() const {
npp = _bezier_interp(mid, points[i].pos, points[i].pos + points[i].out, points[i + 1].pos + points[i + 1].in, points[i + 1].pos);
d = pos.distance_to(npp);
- if (bake_interval < d)
+ if (bake_interval < d) {
hi = mid;
- else
+ } else {
low = mid;
+ }
mid = low + (hi - low) * 0.5;
}
@@ -725,30 +741,35 @@ void Curve2D::_bake() const {
}
float Curve2D::get_baked_length() const {
- if (baked_cache_dirty)
+ if (baked_cache_dirty) {
_bake();
+ }
return baked_max_ofs;
}
Vector2 Curve2D::interpolate_baked(float p_offset, bool p_cubic) const {
- if (baked_cache_dirty)
+ if (baked_cache_dirty) {
_bake();
+ }
//validate//
int pc = baked_point_cache.size();
ERR_FAIL_COND_V_MSG(pc == 0, Vector2(), "No points in Curve2D.");
- if (pc == 1)
+ if (pc == 1) {
return baked_point_cache.get(0);
+ }
int bpc = baked_point_cache.size();
const Vector2 *r = baked_point_cache.ptr();
- if (p_offset < 0)
+ if (p_offset < 0) {
return r[0];
- if (p_offset >= baked_max_ofs)
+ }
+ if (p_offset >= baked_max_ofs) {
return r[bpc - 1];
+ }
int idx = Math::floor((double)p_offset / (double)bake_interval);
float frac = Math::fmod(p_offset, (float)bake_interval);
@@ -756,8 +777,9 @@ Vector2 Curve2D::interpolate_baked(float p_offset, bool p_cubic) const {
if (idx >= bpc - 1) {
return r[bpc - 1];
} else if (idx == bpc - 2) {
- if (frac > 0)
+ if (frac > 0) {
frac /= Math::fmod(baked_max_ofs, bake_interval);
+ }
} else {
frac /= bake_interval;
}
@@ -772,8 +794,9 @@ Vector2 Curve2D::interpolate_baked(float p_offset, bool p_cubic) const {
}
PackedVector2Array Curve2D::get_baked_points() const {
- if (baked_cache_dirty)
+ if (baked_cache_dirty) {
_bake();
+ }
return baked_point_cache;
}
@@ -791,15 +814,17 @@ float Curve2D::get_bake_interval() const {
Vector2 Curve2D::get_closest_point(const Vector2 &p_to_point) const {
// Brute force method
- if (baked_cache_dirty)
+ if (baked_cache_dirty) {
_bake();
+ }
//validate//
int pc = baked_point_cache.size();
ERR_FAIL_COND_V_MSG(pc == 0, Vector2(), "No points in Curve2D.");
- if (pc == 1)
+ if (pc == 1) {
return baked_point_cache.get(0);
+ }
const Vector2 *r = baked_point_cache.ptr();
@@ -827,15 +852,17 @@ Vector2 Curve2D::get_closest_point(const Vector2 &p_to_point) const {
float Curve2D::get_closest_offset(const Vector2 &p_to_point) const {
// Brute force method
- if (baked_cache_dirty)
+ if (baked_cache_dirty) {
_bake();
+ }
//validate//
int pc = baked_point_cache.size();
ERR_FAIL_COND_V_MSG(pc == 0, 0.0f, "No points in Curve2D.");
- if (pc == 1)
+ if (pc == 1) {
return 0.0f;
+ }
const Vector2 *r = baked_point_cache.ptr();
@@ -990,10 +1017,11 @@ void Curve3D::add_point(const Vector3 &p_pos, const Vector3 &p_in, const Vector3
n.pos = p_pos;
n.in = p_in;
n.out = p_out;
- if (p_atpos >= 0 && p_atpos < points.size())
+ if (p_atpos >= 0 && p_atpos < points.size()) {
points.insert(p_atpos, n);
- else
+ } else {
points.push_back(n);
+ }
baked_cache_dirty = true;
emit_signal(CoreStringNames::get_singleton()->changed);
@@ -1070,10 +1098,11 @@ Vector3 Curve3D::interpolate(int p_index, float p_offset) const {
int pc = points.size();
ERR_FAIL_COND_V(pc == 0, Vector3());
- if (p_index >= pc - 1)
+ if (p_index >= pc - 1) {
return points[pc - 1].pos;
- else if (p_index < 0)
+ } else if (p_index < 0) {
return points[0].pos;
+ }
Vector3 p0 = points[p_index].pos;
Vector3 p1 = p0 + points[p_index].out;
@@ -1084,10 +1113,11 @@ Vector3 Curve3D::interpolate(int p_index, float p_offset) const {
}
Vector3 Curve3D::interpolatef(real_t p_findex) const {
- if (p_findex < 0)
+ if (p_findex < 0) {
p_findex = 0;
- else if (p_findex >= points.size())
+ } else if (p_findex >= points.size()) {
p_findex = points.size();
+ }
return interpolate((int)p_findex, Math::fmod(p_findex, (real_t)1.0));
}
@@ -1112,8 +1142,9 @@ void Curve3D::_bake_segment3d(Map<float, Vector3> &r_bake, float p_begin, float
}
void Curve3D::_bake() const {
- if (!baked_cache_dirty)
+ if (!baked_cache_dirty) {
return;
+ }
baked_max_ofs = 0;
baked_cache_dirty = false;
@@ -1134,8 +1165,9 @@ void Curve3D::_bake() const {
if (up_vector_enabled) {
baked_up_vector_cache.resize(1);
baked_up_vector_cache.set(0, Vector3(0, 1, 0));
- } else
+ } else {
baked_up_vector_cache.resize(0);
+ }
return;
}
@@ -1150,8 +1182,9 @@ void Curve3D::_bake() const {
while (p < 1.0) {
float np = p + step;
- if (np > 1.0)
+ if (np > 1.0) {
np = 1.0;
+ }
Vector3 npp = _bezier_interp(np, points[i].pos, points[i].pos + points[i].out, points[i + 1].pos + points[i + 1].in, points[i + 1].pos);
float d = pos.distance_to(npp);
@@ -1169,10 +1202,11 @@ void Curve3D::_bake() const {
npp = _bezier_interp(mid, points[i].pos, points[i].pos + points[i].out, points[i + 1].pos + points[i + 1].in, points[i + 1].pos);
d = pos.distance_to(npp);
- if (bake_interval < d)
+ if (bake_interval < d) {
hi = mid;
- else
+ } else {
low = mid;
+ }
mid = low + (hi - low) * 0.5;
}
@@ -1237,8 +1271,9 @@ void Curve3D::_bake() const {
up = forward.cross(sideways).normalized();
}
- if (idx == 1)
+ if (idx == 1) {
up_write[0] = up;
+ }
up_write[idx] = up;
@@ -1251,30 +1286,35 @@ void Curve3D::_bake() const {
}
float Curve3D::get_baked_length() const {
- if (baked_cache_dirty)
+ if (baked_cache_dirty) {
_bake();
+ }
return baked_max_ofs;
}
Vector3 Curve3D::interpolate_baked(float p_offset, bool p_cubic) const {
- if (baked_cache_dirty)
+ if (baked_cache_dirty) {
_bake();
+ }
//validate//
int pc = baked_point_cache.size();
ERR_FAIL_COND_V_MSG(pc == 0, Vector3(), "No points in Curve3D.");
- if (pc == 1)
+ if (pc == 1) {
return baked_point_cache.get(0);
+ }
int bpc = baked_point_cache.size();
const Vector3 *r = baked_point_cache.ptr();
- if (p_offset < 0)
+ if (p_offset < 0) {
return r[0];
- if (p_offset >= baked_max_ofs)
+ }
+ if (p_offset >= baked_max_ofs) {
return r[bpc - 1];
+ }
int idx = Math::floor((double)p_offset / (double)bake_interval);
float frac = Math::fmod(p_offset, bake_interval);
@@ -1282,8 +1322,9 @@ Vector3 Curve3D::interpolate_baked(float p_offset, bool p_cubic) const {
if (idx >= bpc - 1) {
return r[bpc - 1];
} else if (idx == bpc - 2) {
- if (frac > 0)
+ if (frac > 0) {
frac /= Math::fmod(baked_max_ofs, bake_interval);
+ }
} else {
frac /= bake_interval;
}
@@ -1298,23 +1339,27 @@ Vector3 Curve3D::interpolate_baked(float p_offset, bool p_cubic) const {
}
float Curve3D::interpolate_baked_tilt(float p_offset) const {
- if (baked_cache_dirty)
+ if (baked_cache_dirty) {
_bake();
+ }
//validate//
int pc = baked_tilt_cache.size();
ERR_FAIL_COND_V_MSG(pc == 0, 0, "No tilts in Curve3D.");
- if (pc == 1)
+ if (pc == 1) {
return baked_tilt_cache.get(0);
+ }
int bpc = baked_tilt_cache.size();
const real_t *r = baked_tilt_cache.ptr();
- if (p_offset < 0)
+ if (p_offset < 0) {
return r[0];
- if (p_offset >= baked_max_ofs)
+ }
+ if (p_offset >= baked_max_ofs) {
return r[bpc - 1];
+ }
int idx = Math::floor((double)p_offset / (double)bake_interval);
float frac = Math::fmod(p_offset, bake_interval);
@@ -1322,8 +1367,9 @@ float Curve3D::interpolate_baked_tilt(float p_offset) const {
if (idx >= bpc - 1) {
return r[bpc - 1];
} else if (idx == bpc - 2) {
- if (frac > 0)
+ if (frac > 0) {
frac /= Math::fmod(baked_max_ofs, bake_interval);
+ }
} else {
frac /= bake_interval;
}
@@ -1332,16 +1378,18 @@ float Curve3D::interpolate_baked_tilt(float p_offset) const {
}
Vector3 Curve3D::interpolate_baked_up_vector(float p_offset, bool p_apply_tilt) const {
- if (baked_cache_dirty)
+ if (baked_cache_dirty) {
_bake();
+ }
//validate//
// curve may not have baked up vectors
int count = baked_up_vector_cache.size();
ERR_FAIL_COND_V_MSG(count == 0, Vector3(0, 1, 0), "No up vectors in Curve3D.");
- if (count == 1)
+ if (count == 1) {
return baked_up_vector_cache.get(0);
+ }
const Vector3 *r = baked_up_vector_cache.ptr();
const Vector3 *rp = baked_point_cache.ptr();
@@ -1352,8 +1400,9 @@ Vector3 Curve3D::interpolate_baked_up_vector(float p_offset, bool p_apply_tilt)
int idx = Math::floor((double)offset / (double)bake_interval);
float frac = Math::fmod(offset, bake_interval) / bake_interval;
- if (idx == count - 1)
+ if (idx == count - 1) {
return p_apply_tilt ? r[idx].rotated((rp[idx] - rp[idx - 1]).normalized(), rt[idx]) : r[idx];
+ }
Vector3 forward = (rp[idx + 1] - rp[idx]).normalized();
Vector3 up = r[idx];
@@ -1366,31 +1415,35 @@ Vector3 Curve3D::interpolate_baked_up_vector(float p_offset, bool p_apply_tilt)
Vector3 axis = up.cross(up1);
- if (axis.length_squared() < CMP_EPSILON2)
+ if (axis.length_squared() < CMP_EPSILON2) {
axis = forward;
- else
+ } else {
axis.normalize();
+ }
return up.rotated(axis, up.angle_to(up1) * frac);
}
PackedVector3Array Curve3D::get_baked_points() const {
- if (baked_cache_dirty)
+ if (baked_cache_dirty) {
_bake();
+ }
return baked_point_cache;
}
PackedFloat32Array Curve3D::get_baked_tilts() const {
- if (baked_cache_dirty)
+ if (baked_cache_dirty) {
_bake();
+ }
return baked_tilt_cache;
}
PackedVector3Array Curve3D::get_baked_up_vectors() const {
- if (baked_cache_dirty)
+ if (baked_cache_dirty) {
_bake();
+ }
return baked_up_vector_cache;
}
@@ -1398,15 +1451,17 @@ PackedVector3Array Curve3D::get_baked_up_vectors() const {
Vector3 Curve3D::get_closest_point(const Vector3 &p_to_point) const {
// Brute force method
- if (baked_cache_dirty)
+ if (baked_cache_dirty) {
_bake();
+ }
//validate//
int pc = baked_point_cache.size();
ERR_FAIL_COND_V_MSG(pc == 0, Vector3(), "No points in Curve3D.");
- if (pc == 1)
+ if (pc == 1) {
return baked_point_cache.get(0);
+ }
const Vector3 *r = baked_point_cache.ptr();
@@ -1434,15 +1489,17 @@ Vector3 Curve3D::get_closest_point(const Vector3 &p_to_point) const {
float Curve3D::get_closest_offset(const Vector3 &p_to_point) const {
// Brute force method
- if (baked_cache_dirty)
+ if (baked_cache_dirty) {
_bake();
+ }
//validate//
int pc = baked_point_cache.size();
ERR_FAIL_COND_V_MSG(pc == 0, 0.0f, "No points in Curve3D.");
- if (pc == 1)
+ if (pc == 1) {
return 0.0f;
+ }
const Vector3 *r = baked_point_cache.ptr();
diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp
index 9f7fdc2316..67617a946f 100644
--- a/scene/resources/default_theme/default_theme.cpp
+++ b/scene/resources/default_theme/default_theme.cpp
@@ -770,8 +770,9 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const
// TooltipPanel
Ref<StyleBoxTexture> style_tt = make_stylebox(tooltip_bg_png, 4, 4, 4, 4);
- for (int i = 0; i < 4; i++)
+ for (int i = 0; i < 4; i++) {
style_tt->set_expand_margin_size((Margin)i, 4 * scale);
+ }
theme->set_stylebox("panel", "TooltipPanel", style_tt);
diff --git a/scene/resources/dynamic_font.cpp b/scene/resources/dynamic_font.cpp
index 3581fffdba..3b4e4b73f8 100644
--- a/scene/resources/dynamic_font.cpp
+++ b/scene/resources/dynamic_font.cpp
@@ -247,15 +247,17 @@ const Pair<const DynamicFontAtSize::Character *, DynamicFontAtSize *> DynamicFon
//not found, try in fallbacks
for (int i = 0; i < p_fallbacks.size(); i++) {
DynamicFontAtSize *fb = const_cast<DynamicFontAtSize *>(p_fallbacks[i].ptr());
- if (!fb->valid)
+ if (!fb->valid) {
continue;
+ }
fb->_update_char(p_char);
const Character *fallback_chr = fb->char_map.getptr(p_char);
ERR_CONTINUE(!fallback_chr);
- if (!fallback_chr->found)
+ if (!fallback_chr->found) {
continue;
+ }
return Pair<const Character *, DynamicFontAtSize *>(fallback_chr, fb);
}
@@ -270,8 +272,9 @@ const Pair<const DynamicFontAtSize::Character *, DynamicFontAtSize *> DynamicFon
}
Size2 DynamicFontAtSize::get_char_size(CharType p_char, CharType p_next, const Vector<Ref<DynamicFontAtSize>> &p_fallbacks) const {
- if (!valid)
+ if (!valid) {
return Size2(1, 1);
+ }
const_cast<DynamicFontAtSize *>(this)->_update_char(p_char);
Pair<const Character *, DynamicFontAtSize *> char_pair_with_font = _find_char_with_font(p_char, p_fallbacks);
@@ -288,8 +291,9 @@ Size2 DynamicFontAtSize::get_char_size(CharType p_char, CharType p_next, const V
}
float DynamicFontAtSize::draw_char(RID p_canvas_item, const Point2 &p_pos, CharType p_char, CharType p_next, const Color &p_modulate, const Vector<Ref<DynamicFontAtSize>> &p_fallbacks, bool p_advance_only, bool p_outline) const {
- if (!valid)
+ if (!valid) {
return 0;
+ }
const_cast<DynamicFontAtSize *>(this)->_update_char(p_char);
@@ -344,8 +348,9 @@ unsigned long DynamicFontAtSize::_ft_stream_io(FT_Stream stream, unsigned long o
f->seek(offset);
}
- if (count == 0)
+ if (count == 0) {
return 0;
+ }
return f->get_buffer(buffer, count);
}
@@ -378,11 +383,13 @@ DynamicFontAtSize::TexturePosition DynamicFontAtSize::_find_texture_pos_for_glyp
for (int i = 0; i < textures.size(); i++) {
const CharTexture &ct = textures[i];
- if (ct.texture->get_format() != p_image_format)
+ if (ct.texture->get_format() != p_image_format) {
continue;
+ }
- if (mw > ct.texture_size || mh > ct.texture_size) //too big for this texture
+ if (mw > ct.texture_size || mh > ct.texture_size) { //too big for this texture
continue;
+ }
ret.y = 0x7FFFFFFF;
ret.x = 0;
@@ -392,8 +399,9 @@ DynamicFontAtSize::TexturePosition DynamicFontAtSize::_find_texture_pos_for_glyp
for (int k = j; k < j + mw; k++) {
int y = ct.offsets[k];
- if (y > max_y)
+ if (y > max_y) {
max_y = y;
+ }
}
if (max_y < ret.y) {
@@ -402,8 +410,9 @@ DynamicFontAtSize::TexturePosition DynamicFontAtSize::_find_texture_pos_for_glyp
}
}
- if (ret.y == 0x7FFFFFFF || ret.y + mh > ct.texture_size)
+ if (ret.y == 0x7FFFFFFF || ret.y + mh > ct.texture_size) {
continue; //fail, could not fit it here
+ }
ret.index = i;
break;
@@ -415,10 +424,12 @@ DynamicFontAtSize::TexturePosition DynamicFontAtSize::_find_texture_pos_for_glyp
ret.y = 0;
int texsize = MAX(id.size * oversampling * 8, 256);
- if (mw > texsize)
+ if (mw > texsize) {
texsize = mw; //special case, adapt to it?
- if (mh > texsize)
+ }
+ if (mh > texsize) {
texsize = mh; //special case, adapt to it?
+ }
texsize = next_power_of_2(texsize);
@@ -437,8 +448,9 @@ DynamicFontAtSize::TexturePosition DynamicFontAtSize::_find_texture_pos_for_glyp
}
}
tex.offsets.resize(texsize);
- for (int i = 0; i < texsize; i++) //zero offsets
+ for (int i = 0; i < texsize; i++) { //zero offsets
tex.offsets.write[i] = 0;
+ }
textures.push_back(tex);
ret.index = textures.size() - 1;
@@ -536,23 +548,28 @@ DynamicFontAtSize::Character DynamicFontAtSize::_bitmap_to_character(FT_Bitmap b
DynamicFontAtSize::Character DynamicFontAtSize::_make_outline_char(CharType p_char) {
Character ret = Character::not_found();
- if (FT_Load_Char(face, p_char, FT_LOAD_NO_BITMAP | (font->force_autohinter ? FT_LOAD_FORCE_AUTOHINT : 0)) != 0)
+ if (FT_Load_Char(face, p_char, FT_LOAD_NO_BITMAP | (font->force_autohinter ? FT_LOAD_FORCE_AUTOHINT : 0)) != 0) {
return ret;
+ }
FT_Stroker stroker;
- if (FT_Stroker_New(library, &stroker) != 0)
+ if (FT_Stroker_New(library, &stroker) != 0) {
return ret;
+ }
FT_Stroker_Set(stroker, (int)(id.outline_size * oversampling * 64.0), FT_STROKER_LINECAP_BUTT, FT_STROKER_LINEJOIN_ROUND, 0);
FT_Glyph glyph;
FT_BitmapGlyph glyph_bitmap;
- if (FT_Get_Glyph(face->glyph, &glyph) != 0)
+ if (FT_Get_Glyph(face->glyph, &glyph) != 0) {
goto cleanup_stroker;
- if (FT_Glyph_Stroke(&glyph, stroker, 1) != 0)
+ }
+ if (FT_Glyph_Stroke(&glyph, stroker, 1) != 0) {
goto cleanup_glyph;
- if (FT_Glyph_To_Bitmap(&glyph, FT_RENDER_MODE_NORMAL, nullptr, 1) != 0)
+ }
+ if (FT_Glyph_To_Bitmap(&glyph, FT_RENDER_MODE_NORMAL, nullptr, 1) != 0) {
goto cleanup_glyph;
+ }
glyph_bitmap = (FT_BitmapGlyph)glyph;
ret = _bitmap_to_character(glyph_bitmap->bitmap, glyph_bitmap->top, glyph_bitmap->left, glyph->advance.x / 65536.0);
@@ -565,8 +582,9 @@ cleanup_stroker:
}
void DynamicFontAtSize::_update_char(CharType p_char) {
- if (char_map.has(p_char))
+ if (char_map.has(p_char)) {
return;
+ }
_THREAD_SAFE_METHOD_
@@ -603,16 +621,18 @@ void DynamicFontAtSize::_update_char(CharType p_char) {
character = _make_outline_char(p_char);
} else {
error = FT_Render_Glyph(face->glyph, font->antialiased ? FT_RENDER_MODE_NORMAL : FT_RENDER_MODE_MONO);
- if (!error)
+ if (!error) {
character = _bitmap_to_character(slot->bitmap, slot->bitmap_top, slot->bitmap_left, slot->advance.x / 64.0);
+ }
}
char_map[p_char] = character;
}
void DynamicFontAtSize::update_oversampling() {
- if (oversampling == font_oversampling || !valid)
+ if (oversampling == font_oversampling || !valid) {
return;
+ }
FT_Done_FreeType(library);
textures.clear();
@@ -664,8 +684,9 @@ void DynamicFont::_reload_cache() {
for (int i = 0; i < fallbacks.size(); i++) {
fallback_data_at_size.write[i] = fallbacks.write[i]->_get_dynamic_font_at_size(cache_id);
- if (outline_cache_id.outline_size > 0)
+ if (outline_cache_id.outline_size > 0) {
fallback_outline_data_at_size.write[i] = fallbacks.write[i]->_get_dynamic_font_at_size(outline_cache_id);
+ }
}
emit_changed();
@@ -685,8 +706,9 @@ Ref<DynamicFontData> DynamicFont::get_font_data() const {
}
void DynamicFont::set_size(int p_size) {
- if (cache_id.size == p_size)
+ if (cache_id.size == p_size) {
return;
+ }
cache_id.size = p_size;
outline_cache_id.size = p_size;
_reload_cache();
@@ -697,8 +719,9 @@ int DynamicFont::get_size() const {
}
void DynamicFont::set_outline_size(int p_size) {
- if (outline_cache_id.outline_size == p_size)
+ if (outline_cache_id.outline_size == p_size) {
return;
+ }
ERR_FAIL_COND(p_size < 0 || p_size > UINT8_MAX);
outline_cache_id.outline_size = p_size;
_reload_cache();
@@ -725,8 +748,9 @@ bool DynamicFontData::is_antialiased() const {
}
void DynamicFontData::set_antialiased(bool p_antialiased) {
- if (antialiased == p_antialiased)
+ if (antialiased == p_antialiased) {
return;
+ }
antialiased = p_antialiased;
}
@@ -735,8 +759,9 @@ DynamicFontData::Hinting DynamicFontData::get_hinting() const {
}
void DynamicFontData::set_hinting(Hinting p_hinting) {
- if (hinting == p_hinting)
+ if (hinting == p_hinting) {
return;
+ }
hinting = p_hinting;
}
@@ -770,49 +795,56 @@ void DynamicFont::set_spacing(int p_type, int p_value) {
}
float DynamicFont::get_height() const {
- if (!data_at_size.is_valid())
+ if (!data_at_size.is_valid()) {
return 1;
+ }
return data_at_size->get_height() + spacing_top + spacing_bottom;
}
float DynamicFont::get_ascent() const {
- if (!data_at_size.is_valid())
+ if (!data_at_size.is_valid()) {
return 1;
+ }
return data_at_size->get_ascent() + spacing_top;
}
float DynamicFont::get_descent() const {
- if (!data_at_size.is_valid())
+ if (!data_at_size.is_valid()) {
return 1;
+ }
return data_at_size->get_descent() + spacing_bottom;
}
float DynamicFont::get_underline_position() const {
- if (!data_at_size.is_valid())
+ if (!data_at_size.is_valid()) {
return 2;
+ }
return data_at_size->get_underline_position();
}
float DynamicFont::get_underline_thickness() const {
- if (!data_at_size.is_valid())
+ if (!data_at_size.is_valid()) {
return 1;
+ }
return data_at_size->get_underline_thickness();
}
Size2 DynamicFont::get_char_size(CharType p_char, CharType p_next) const {
- if (!data_at_size.is_valid())
+ if (!data_at_size.is_valid()) {
return Size2(1, 1);
+ }
Size2 ret = data_at_size->get_char_size(p_char, p_next, fallback_data_at_size);
- if (p_char == ' ')
+ if (p_char == ' ') {
ret.width += spacing_space + spacing_char;
- else if (p_next)
+ } else if (p_next) {
ret.width += spacing_char;
+ }
return ret;
}
@@ -828,8 +860,9 @@ bool DynamicFont::has_outline() const {
float DynamicFont::draw_char(RID p_canvas_item, const Point2 &p_pos, CharType p_char, CharType p_next, const Color &p_modulate, bool p_outline) const {
const Ref<DynamicFontAtSize> &font_at_size = p_outline && outline_cache_id.outline_size > 0 ? outline_data_at_size : data_at_size;
- if (!font_at_size.is_valid())
+ if (!font_at_size.is_valid()) {
return 0;
+ }
const Vector<Ref<DynamicFontAtSize>> &fallbacks = p_outline && outline_cache_id.outline_size > 0 ? fallback_outline_data_at_size : fallback_data_at_size;
Color color = p_outline && outline_cache_id.outline_size > 0 ? p_modulate * outline_color : p_modulate;
@@ -850,8 +883,9 @@ void DynamicFont::add_fallback(const Ref<DynamicFontData> &p_data) {
ERR_FAIL_COND(p_data.is_null());
fallbacks.push_back(p_data);
fallback_data_at_size.push_back(fallbacks.write[fallbacks.size() - 1]->_get_dynamic_font_at_size(cache_id)); //const..
- if (outline_cache_id.outline_size > 0)
+ if (outline_cache_id.outline_size > 0) {
fallback_outline_data_at_size.push_back(fallbacks.write[fallbacks.size() - 1]->_get_dynamic_font_at_size(outline_cache_id));
+ }
_change_notify();
emit_changed();
@@ -1038,15 +1072,17 @@ void DynamicFont::update_oversampling() {
/////////////////////////
RES ResourceFormatLoaderDynamicFont::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) {
- if (r_error)
+ if (r_error) {
*r_error = ERR_FILE_CANT_OPEN;
+ }
Ref<DynamicFontData> dfont;
dfont.instance();
dfont->set_font_path(p_path);
- if (r_error)
+ if (r_error) {
*r_error = OK;
+ }
return dfont;
}
@@ -1062,8 +1098,9 @@ bool ResourceFormatLoaderDynamicFont::handles_type(const String &p_type) const {
String ResourceFormatLoaderDynamicFont::get_resource_type(const String &p_path) const {
String el = p_path.get_extension().to_lower();
- if (el == "ttf" || el == "otf")
+ if (el == "ttf" || el == "otf") {
return "DynamicFontData";
+ }
return "";
}
diff --git a/scene/resources/environment.cpp b/scene/resources/environment.cpp
index 5356b5bea2..80ee0c148d 100644
--- a/scene/resources/environment.cpp
+++ b/scene/resources/environment.cpp
@@ -47,8 +47,9 @@ void Environment::set_sky(const Ref<Sky> &p_sky) {
bg_sky = p_sky;
RID sb_rid;
- if (bg_sky.is_valid())
+ if (bg_sky.is_valid()) {
sb_rid = bg_sky->get_rid();
+ }
RS::get_singleton()->environment_set_sky(environment, sb_rid);
}
@@ -504,10 +505,11 @@ bool Environment::is_glow_enabled() const {
void Environment::set_glow_level(int p_level, bool p_enabled) {
ERR_FAIL_INDEX(p_level, RS::MAX_GLOW_LEVELS);
- if (p_enabled)
+ if (p_enabled) {
glow_levels |= (1 << p_level);
- else
+ } else {
glow_levels &= ~(1 << p_level);
+ }
RS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_mix, glow_bloom, RS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_threshold, glow_hdr_bleed_threshold, glow_hdr_luminance_cap);
}
diff --git a/scene/resources/font.cpp b/scene/resources/font.cpp
index e0cd1be456..1878b174e8 100644
--- a/scene/resources/font.cpp
+++ b/scene/resources/font.cpp
@@ -67,8 +67,9 @@ void Font::draw(RID p_canvas_item, const Point2 &p_pos, const String &p_text, co
for (int i = 0; i < p_text.length(); i++) {
int width = get_char_size(p_text[i]).width;
- if (p_clip_w >= 0 && (ofs.x + width) > p_clip_w)
+ if (p_clip_w >= 0 && (ofs.x + width) > p_clip_w) {
break; //clip
+ }
ofs.x += draw_char(p_canvas_item, p_pos + ofs, p_text[i], p_text[i + 1], with_outline ? p_outline_modulate : p_modulate, with_outline);
++chars_drawn;
@@ -108,8 +109,9 @@ void BitmapFont::_set_chars(const Vector<int> &p_chars) {
int len = p_chars.size();
//char 1 charsize 1 texture, 4 rect, 2 align, advance 1
ERR_FAIL_COND(len % 9);
- if (!len)
+ if (!len) {
return; //none to do
+ }
int chars = len / 9;
const int *r = p_chars.ptr();
@@ -145,8 +147,9 @@ Vector<int> BitmapFont::_get_chars() const {
void BitmapFont::_set_kernings(const Vector<int> &p_kernings) {
int len = p_kernings.size();
ERR_FAIL_COND(len % 3);
- if (!len)
+ if (!len) {
return;
+ }
const int *r = p_kernings.ptr();
for (int i = 0; i < len / 3; i++) {
@@ -178,8 +181,9 @@ void BitmapFont::_set_textures(const Vector<Variant> &p_textures) {
Vector<Variant> BitmapFont::_get_textures() const {
Vector<Variant> rtextures;
- for (int i = 0; i < textures.size(); i++)
+ for (int i = 0; i < textures.size(); i++) {
rtextures.push_back(textures[i]);
+ }
return rtextures;
}
@@ -201,51 +205,59 @@ Error BitmapFont::create_from_fnt(const String &p_file) {
int pos = delimiter + 1;
Map<String, String> keys;
- while (pos < line.size() && line[pos] == ' ')
+ while (pos < line.size() && line[pos] == ' ') {
pos++;
+ }
while (pos < line.size()) {
int eq = line.find("=", pos);
- if (eq == -1)
+ if (eq == -1) {
break;
+ }
String key = line.substr(pos, eq - pos);
int end = -1;
String value;
if (line[eq + 1] == '"') {
end = line.find("\"", eq + 2);
- if (end == -1)
+ if (end == -1) {
break;
+ }
value = line.substr(eq + 2, end - 1 - eq - 1);
pos = end + 1;
} else {
end = line.find(" ", eq + 1);
- if (end == -1)
+ if (end == -1) {
end = line.size();
+ }
value = line.substr(eq + 1, end - eq);
pos = end;
}
- while (pos < line.size() && line[pos] == ' ')
+ while (pos < line.size() && line[pos] == ' ') {
pos++;
+ }
keys[key] = value;
}
if (type == "info") {
- if (keys.has("face"))
+ if (keys.has("face")) {
set_name(keys["face"]);
+ }
/*
if (keys.has("size"))
font->set_height(keys["size"].to_int());
*/
} else if (type == "common") {
- if (keys.has("lineHeight"))
+ if (keys.has("lineHeight")) {
set_height(keys["lineHeight"].to_int());
- if (keys.has("base"))
+ }
+ if (keys.has("base")) {
set_ascent(keys["base"].to_int());
+ }
} else if (type == "page") {
if (keys.has("file")) {
@@ -260,33 +272,42 @@ Error BitmapFont::create_from_fnt(const String &p_file) {
}
} else if (type == "char") {
CharType idx = 0;
- if (keys.has("id"))
+ if (keys.has("id")) {
idx = keys["id"].to_int();
+ }
Rect2 rect;
- if (keys.has("x"))
+ if (keys.has("x")) {
rect.position.x = keys["x"].to_int();
- if (keys.has("y"))
+ }
+ if (keys.has("y")) {
rect.position.y = keys["y"].to_int();
- if (keys.has("width"))
+ }
+ if (keys.has("width")) {
rect.size.width = keys["width"].to_int();
- if (keys.has("height"))
+ }
+ if (keys.has("height")) {
rect.size.height = keys["height"].to_int();
+ }
Point2 ofs;
- if (keys.has("xoffset"))
+ if (keys.has("xoffset")) {
ofs.x = keys["xoffset"].to_int();
- if (keys.has("yoffset"))
+ }
+ if (keys.has("yoffset")) {
ofs.y = keys["yoffset"].to_int();
+ }
int texture = 0;
- if (keys.has("page"))
+ if (keys.has("page")) {
texture = keys["page"].to_int();
+ }
int advance = -1;
- if (keys.has("xadvance"))
+ if (keys.has("xadvance")) {
advance = keys["xadvance"].to_int();
+ }
add_char(idx, texture, rect, ofs, advance);
@@ -294,18 +315,22 @@ Error BitmapFont::create_from_fnt(const String &p_file) {
CharType first = 0, second = 0;
int k = 0;
- if (keys.has("first"))
+ if (keys.has("first")) {
first = keys["first"].to_int();
- if (keys.has("second"))
+ }
+ if (keys.has("second")) {
second = keys["second"].to_int();
- if (keys.has("amount"))
+ }
+ if (keys.has("amount")) {
k = keys["amount"].to_int();
+ }
add_kerning_pair(first, second, -k);
}
- if (f->eof_reached())
+ if (f->eof_reached()) {
break;
+ }
}
memdelete(f);
@@ -380,8 +405,9 @@ BitmapFont::Character BitmapFont::get_character(CharType p_char) const {
};
void BitmapFont::add_char(CharType p_char, int p_texture_idx, const Rect2 &p_rect, const Size2 &p_align, float p_advance) {
- if (p_advance < 0)
+ if (p_advance < 0) {
p_advance = p_rect.size.width;
+ }
Character c;
c.rect = p_rect;
@@ -423,8 +449,9 @@ int BitmapFont::get_kerning_pair(CharType p_A, CharType p_B) const {
kpk.B = p_B;
const Map<KerningPairKey, int>::Element *E = kerning_map.find(kpk);
- if (E)
+ if (E) {
return E->get();
+ }
return 0;
}
@@ -451,8 +478,9 @@ Size2 Font::get_string_size(const String &p_string) const {
float w = 0;
int l = p_string.length();
- if (l == 0)
+ if (l == 0) {
return Size2(0, get_height());
+ }
const CharType *sptr = &p_string[0];
for (int i = 0; i < l; i++) {
@@ -466,8 +494,9 @@ Size2 Font::get_wordwrap_string_size(const String &p_string, float p_width) cons
ERR_FAIL_COND_V(p_width <= 0, Vector2(0, get_height()));
int l = p_string.length();
- if (l == 0)
+ if (l == 0) {
return Size2(p_width, get_height());
+ }
float line_w = 0;
float h = 0;
@@ -508,8 +537,9 @@ float BitmapFont::draw_char(RID p_canvas_item, const Point2 &p_pos, CharType p_c
const Character *c = char_map.getptr(p_char);
if (!c) {
- if (fallback.is_valid())
+ if (fallback.is_valid()) {
return fallback->draw_char(p_canvas_item, p_pos, p_char, p_next, p_modulate, p_outline);
+ }
return 0;
}
@@ -529,8 +559,9 @@ Size2 BitmapFont::get_char_size(CharType p_char, CharType p_next) const {
const Character *c = char_map.getptr(p_char);
if (!c) {
- if (fallback.is_valid())
+ if (fallback.is_valid()) {
return fallback->get_char_size(p_char, p_next);
+ }
return Size2();
}
@@ -604,8 +635,9 @@ BitmapFont::~BitmapFont() {
////////////
RES ResourceFormatLoaderBMFont::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) {
- if (r_error)
+ if (r_error) {
*r_error = ERR_FILE_CANT_OPEN;
+ }
Ref<BitmapFont> font;
font.instance();
@@ -613,8 +645,9 @@ RES ResourceFormatLoaderBMFont::load(const String &p_path, const String &p_origi
Error err = font->create_from_fnt(p_path);
if (err) {
- if (r_error)
+ if (r_error) {
*r_error = err;
+ }
return RES();
}
@@ -631,7 +664,8 @@ bool ResourceFormatLoaderBMFont::handles_type(const String &p_type) const {
String ResourceFormatLoaderBMFont::get_resource_type(const String &p_path) const {
String el = p_path.get_extension().to_lower();
- if (el == "fnt")
+ if (el == "fnt") {
return "BitmapFont";
+ }
return "";
}
diff --git a/scene/resources/gradient.cpp b/scene/resources/gradient.cpp
index 2ccabe0b80..d271c906ff 100644
--- a/scene/resources/gradient.cpp
+++ b/scene/resources/gradient.cpp
@@ -103,8 +103,9 @@ void Gradient::set_offsets(const Vector<float> &p_offsets) {
}
void Gradient::set_colors(const Vector<Color> &p_colors) {
- if (points.size() < p_colors.size())
+ if (points.size() < p_colors.size()) {
is_sorted = false;
+ }
points.resize(p_colors.size());
for (int i = 0; i < points.size(); i++) {
points.write[i].color = p_colors[i];
@@ -141,8 +142,9 @@ void Gradient::set_points(Vector<Gradient::Point> &p_points) {
void Gradient::set_offset(int pos, const float offset) {
ERR_FAIL_COND(pos < 0);
- if (points.size() <= pos)
+ if (points.size() <= pos) {
points.resize(pos + 1);
+ }
points.write[pos].offset = offset;
is_sorted = false;
emit_signal(CoreStringNames::get_singleton()->changed);
diff --git a/scene/resources/gradient.h b/scene/resources/gradient.h
index fa654cf31d..d40dcc8d44 100644
--- a/scene/resources/gradient.h
+++ b/scene/resources/gradient.h
@@ -76,8 +76,9 @@ public:
Vector<Color> get_colors() const;
_FORCE_INLINE_ Color get_color_at_offset(float p_offset) {
- if (points.empty())
+ if (points.empty()) {
return Color(0, 0, 0, 1);
+ }
if (!is_sorted) {
points.sort();
@@ -90,8 +91,9 @@ public:
int middle = 0;
#ifdef DEBUG_ENABLED
- if (low > high)
+ if (low > high) {
ERR_PRINT("low > high, this may be a bug");
+ }
#endif
while (low <= high) {
@@ -112,10 +114,12 @@ public:
}
int first = middle;
int second = middle + 1;
- if (second >= points.size())
+ if (second >= points.size()) {
return points[points.size() - 1].color;
- if (first < 0)
+ }
+ if (first < 0) {
return points[0].color;
+ }
const Point &pointFirst = points[first];
const Point &pointSecond = points[second];
return pointFirst.color.lerp(pointSecond.color, (p_offset - pointFirst.offset) / (pointSecond.offset - pointFirst.offset));
diff --git a/scene/resources/height_map_shape_3d.cpp b/scene/resources/height_map_shape_3d.cpp
index 5450d78426..e112c6b436 100644
--- a/scene/resources/height_map_shape_3d.cpp
+++ b/scene/resources/height_map_shape_3d.cpp
@@ -159,11 +159,13 @@ void HeightMapShape3D::set_map_data(PackedFloat32Array p_new) {
min_height = val;
max_height = val;
} else {
- if (min_height > val)
+ if (min_height > val) {
min_height = val;
+ }
- if (max_height < val)
+ if (max_height < val) {
max_height = val;
+ }
}
}
diff --git a/scene/resources/line_shape_2d.cpp b/scene/resources/line_shape_2d.cpp
index 22dd426295..802ccaaee6 100644
--- a/scene/resources/line_shape_2d.cpp
+++ b/scene/resources/line_shape_2d.cpp
@@ -39,8 +39,9 @@ bool LineShape2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tol
for (int i = 0; i < 2; i++) {
Vector2 closest = Geometry::get_closest_point_to_segment_2d(p_point, l[i]);
- if (p_point.distance_to(closest) < p_tolerance)
+ if (p_point.distance_to(closest) < p_tolerance) {
return true;
+ }
}
return false;
diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp
index 3a3fb77f02..1e95a35726 100644
--- a/scene/resources/material.cpp
+++ b/scene/resources/material.cpp
@@ -43,13 +43,15 @@ void Material::set_next_pass(const Ref<Material> &p_pass) {
ERR_FAIL_COND_MSG(pass_child == this, "Can't set as next_pass one of its parents to prevent crashes due to recursive loop.");
}
- if (next_pass == p_pass)
+ if (next_pass == p_pass) {
return;
+ }
next_pass = p_pass;
RID next_pass_rid;
- if (next_pass.is_valid())
+ if (next_pass.is_valid()) {
next_pass_rid = next_pass->get_rid();
+ }
RS::get_singleton()->material_set_next_pass(material, next_pass_rid);
}
@@ -252,10 +254,11 @@ bool ShaderMaterial::_can_do_next_pass() const {
}
Shader::Mode ShaderMaterial::get_shader_mode() const {
- if (shader.is_valid())
+ if (shader.is_valid()) {
return shader->get_mode();
- else
+ } else {
return Shader::MODE_SPATIAL;
+ }
}
ShaderMaterial::ShaderMaterial() {
@@ -365,8 +368,9 @@ void BaseMaterial3D::_update_shader() {
dirty_materials->remove(&element);
MaterialKey mk = _compute_key();
- if (mk == current_key)
+ if (mk == current_key) {
return; //no update required in the end
+ }
if (shader_map.has(current_key)) {
shader_map[current_key].users--;
@@ -1372,8 +1376,9 @@ float BaseMaterial3D::get_refraction() const {
}
void BaseMaterial3D::set_detail_uv(DetailUV p_detail_uv) {
- if (detail_uv == p_detail_uv)
+ if (detail_uv == p_detail_uv) {
return;
+ }
detail_uv = p_detail_uv;
_queue_shader_change();
@@ -1384,8 +1389,9 @@ BaseMaterial3D::DetailUV BaseMaterial3D::get_detail_uv() const {
}
void BaseMaterial3D::set_blend_mode(BlendMode p_mode) {
- if (blend_mode == p_mode)
+ if (blend_mode == p_mode) {
return;
+ }
blend_mode = p_mode;
_queue_shader_change();
@@ -1433,8 +1439,9 @@ BaseMaterial3D::ShadingMode BaseMaterial3D::get_shading_mode() const {
}
void BaseMaterial3D::set_depth_draw_mode(DepthDrawMode p_mode) {
- if (depth_draw_mode == p_mode)
+ if (depth_draw_mode == p_mode) {
return;
+ }
depth_draw_mode = p_mode;
_queue_shader_change();
@@ -1445,8 +1452,9 @@ BaseMaterial3D::DepthDrawMode BaseMaterial3D::get_depth_draw_mode() const {
}
void BaseMaterial3D::set_cull_mode(CullMode p_mode) {
- if (cull_mode == p_mode)
+ if (cull_mode == p_mode) {
return;
+ }
cull_mode = p_mode;
_queue_shader_change();
@@ -1457,8 +1465,9 @@ BaseMaterial3D::CullMode BaseMaterial3D::get_cull_mode() const {
}
void BaseMaterial3D::set_diffuse_mode(DiffuseMode p_mode) {
- if (diffuse_mode == p_mode)
+ if (diffuse_mode == p_mode) {
return;
+ }
diffuse_mode = p_mode;
_queue_shader_change();
@@ -1469,8 +1478,9 @@ BaseMaterial3D::DiffuseMode BaseMaterial3D::get_diffuse_mode() const {
}
void BaseMaterial3D::set_specular_mode(SpecularMode p_mode) {
- if (specular_mode == p_mode)
+ if (specular_mode == p_mode) {
return;
+ }
specular_mode = p_mode;
_queue_shader_change();
@@ -1483,8 +1493,9 @@ BaseMaterial3D::SpecularMode BaseMaterial3D::get_specular_mode() const {
void BaseMaterial3D::set_flag(Flags p_flag, bool p_enabled) {
ERR_FAIL_INDEX(p_flag, FLAG_MAX);
- if (flags[p_flag] == p_enabled)
+ if (flags[p_flag] == p_enabled) {
return;
+ }
flags[p_flag] = p_enabled;
if (p_flag == FLAG_USE_SHADOW_TO_OPACITY || p_flag == FLAG_USE_TEXTURE_REPEAT || p_flag == FLAG_SUBSURFACE_MODE_SKIN) {
@@ -1500,8 +1511,9 @@ bool BaseMaterial3D::get_flag(Flags p_flag) const {
void BaseMaterial3D::set_feature(Feature p_feature, bool p_enabled) {
ERR_FAIL_INDEX(p_feature, FEATURE_MAX);
- if (features[p_feature] == p_enabled)
+ if (features[p_feature] == p_enabled) {
return;
+ }
features[p_feature] = p_enabled;
_change_notify();
@@ -1530,8 +1542,9 @@ Ref<Texture2D> BaseMaterial3D::get_texture(TextureParam p_param) const {
Ref<Texture2D> BaseMaterial3D::get_texture_by_name(StringName p_name) const {
for (int i = 0; i < (int)BaseMaterial3D::TEXTURE_MAX; i++) {
TextureParam param = TextureParam(i);
- if (p_name == shader_names->texture_names[param])
+ if (p_name == shader_names->texture_names[param]) {
return textures[param];
+ }
}
return Ref<Texture2D>();
}
@@ -1895,20 +1908,27 @@ BaseMaterial3D::TextureChannel BaseMaterial3D::get_refraction_texture_channel()
RID BaseMaterial3D::get_material_rid_for_2d(bool p_shaded, bool p_transparent, bool p_double_sided, bool p_cut_alpha, bool p_opaque_prepass, bool p_billboard, bool p_billboard_y) {
int version = 0;
- if (p_shaded)
+ if (p_shaded) {
version = 1;
- if (p_transparent)
+ }
+ if (p_transparent) {
version |= 2;
- if (p_cut_alpha)
+ }
+ if (p_cut_alpha) {
version |= 4;
- if (p_opaque_prepass)
+ }
+ if (p_opaque_prepass) {
version |= 8;
- if (p_double_sided)
+ }
+ if (p_double_sided) {
version |= 16;
- if (p_billboard)
+ }
+ if (p_billboard) {
version |= 32;
- if (p_billboard_y)
+ }
+ if (p_billboard_y) {
version |= 64;
+ }
if (materials_for_2d[version].is_valid()) {
return materials_for_2d[version]->get_rid();
@@ -1986,8 +2006,9 @@ float BaseMaterial3D::get_distance_fade_min_distance() const {
}
void BaseMaterial3D::set_emission_operator(EmissionOperator p_op) {
- if (emission_op == p_op)
+ if (emission_op == p_op) {
return;
+ }
emission_op = p_op;
_queue_shader_change();
}
diff --git a/scene/resources/mesh.cpp b/scene/resources/mesh.cpp
index e293a421b9..10f0a040d0 100644
--- a/scene/resources/mesh.cpp
+++ b/scene/resources/mesh.cpp
@@ -40,14 +40,16 @@
Mesh::ConvexDecompositionFunc Mesh::convex_composition_function = nullptr;
Ref<TriangleMesh> Mesh::generate_triangle_mesh() const {
- if (triangle_mesh.is_valid())
+ if (triangle_mesh.is_valid()) {
return triangle_mesh;
+ }
int facecount = 0;
for (int i = 0; i < get_surface_count(); i++) {
- if (surface_get_primitive_type(i) != PRIMITIVE_TRIANGLES)
+ if (surface_get_primitive_type(i) != PRIMITIVE_TRIANGLES) {
continue;
+ }
if (surface_get_format(i) & ARRAY_FORMAT_INDEX) {
facecount += surface_get_array_index_len(i);
@@ -56,8 +58,9 @@ Ref<TriangleMesh> Mesh::generate_triangle_mesh() const {
}
}
- if (facecount == 0 || (facecount % 3) != 0)
+ if (facecount == 0 || (facecount % 3) != 0) {
return triangle_mesh;
+ }
Vector<Vector3> faces;
faces.resize(facecount);
@@ -66,8 +69,9 @@ Ref<TriangleMesh> Mesh::generate_triangle_mesh() const {
int widx = 0;
for (int i = 0; i < get_surface_count(); i++) {
- if (surface_get_primitive_type(i) != PRIMITIVE_TRIANGLES)
+ if (surface_get_primitive_type(i) != PRIMITIVE_TRIANGLES) {
continue;
+ }
Array a = surface_get_arrays(i);
ERR_FAIL_COND_V(a.empty(), Ref<TriangleMesh>());
@@ -87,8 +91,9 @@ Ref<TriangleMesh> Mesh::generate_triangle_mesh() const {
}
} else {
- for (int j = 0; j < vc; j++)
+ for (int j = 0; j < vc; j++) {
facesw[widx++] = vr[j];
+ }
}
}
@@ -105,8 +110,9 @@ void Mesh::generate_debug_mesh_lines(Vector<Vector3> &r_lines) {
}
Ref<TriangleMesh> tm = generate_triangle_mesh();
- if (tm.is_null())
+ if (tm.is_null()) {
return;
+ }
Vector<int> triangle_indices;
tm->get_indices(&triangle_indices);
@@ -136,8 +142,9 @@ void Mesh::generate_debug_mesh_lines(Vector<Vector3> &r_lines) {
void Mesh::generate_debug_mesh_indices(Vector<Vector3> &r_points) {
Ref<TriangleMesh> tm = generate_triangle_mesh();
- if (tm.is_null())
+ if (tm.is_null()) {
return;
+ }
Vector<Vector3> vertices = tm->get_vertices();
@@ -155,8 +162,9 @@ bool Mesh::surface_is_softbody_friendly(int p_idx) const {
Vector<Face3> Mesh::get_faces() const {
Ref<TriangleMesh> tm = generate_triangle_mesh();
- if (tm.is_valid())
+ if (tm.is_valid()) {
return tm->get_faces();
+ }
return Vector<Face3>();
/*
for (int i=0;i<surfaces.size();i++) {
@@ -235,8 +243,9 @@ Ref<Shape3D> Mesh::create_convex_shape() const {
Ref<Shape3D> Mesh::create_trimesh_shape() const {
Vector<Face3> faces = get_faces();
- if (faces.size() == 0)
+ if (faces.size() == 0) {
return Ref<Shape3D>();
+ }
Vector<Vector3> face_points;
face_points.resize(faces.size() * 3);
@@ -257,8 +266,9 @@ Ref<Mesh> Mesh::create_outline(float p_margin) const {
Array arrays;
int index_accum = 0;
for (int i = 0; i < get_surface_count(); i++) {
- if (surface_get_primitive_type(i) != PRIMITIVE_TRIANGLES)
+ if (surface_get_primitive_type(i) != PRIMITIVE_TRIANGLES) {
continue;
+ }
Array a = surface_get_arrays(i);
ERR_FAIL_COND_V(a.empty(), Ref<ArrayMesh>());
@@ -281,8 +291,9 @@ Ref<Mesh> Mesh::create_outline(float p_margin) const {
case ARRAY_NORMAL: {
Vector<Vector3> dst = arrays[j];
Vector<Vector3> src = a[j];
- if (j == ARRAY_VERTEX)
+ if (j == ARRAY_VERTEX) {
vcount = src.size();
+ }
if (dst.size() == 0 || src.size() == 0) {
arrays[j] = Variant();
continue;
@@ -392,8 +403,9 @@ Ref<Mesh> Mesh::create_outline(float p_margin) const {
normal_accum[t[j]] = n;
} else {
float d = n.dot(E->get());
- if (d < 1.0)
+ if (d < 1.0) {
E->get() += n * (1.0 - d);
+ }
//E->get()+=n;
}
}
@@ -672,8 +684,9 @@ bool ArrayMesh::_set(const StringName &p_name, const Variant &p_value) {
Vector<String> sk = p_value;
int sz = sk.size();
const String *r = sk.ptr();
- for (int i = 0; i < sz; i++)
+ for (int i = 0; i < sz; i++) {
add_blend_shape(r[i]);
+ }
return true;
}
@@ -684,21 +697,24 @@ bool ArrayMesh::_set(const StringName &p_name, const Variant &p_value) {
if (sname.begins_with("surface_")) {
int sl = sname.find("/");
- if (sl == -1)
+ if (sl == -1) {
return false;
+ }
int idx = sname.substr(8, sl - 8).to_int() - 1;
String what = sname.get_slicec('/', 1);
- if (what == "material")
+ if (what == "material") {
surface_set_material(idx, p_value);
- else if (what == "name")
+ } else if (what == "name") {
surface_set_name(idx, p_value);
+ }
return true;
}
#ifndef DISABLE_DEPRECATED
// Kept for compatibility from 3.x to 4.0.
- if (!sname.begins_with("surfaces"))
+ if (!sname.begins_with("surfaces")) {
return false;
+ }
WARN_DEPRECATED_MSG("Mesh uses old surface format, which is deprecated (and loads slower). Consider re-importing or re-saving the scene.");
@@ -720,8 +736,9 @@ bool ArrayMesh::_set(const StringName &p_name, const Variant &p_value) {
//older format (3.x)
Vector<uint8_t> array_data = d["array_data"];
Vector<uint8_t> array_index_data;
- if (d.has("array_index_data"))
+ if (d.has("array_index_data")) {
array_index_data = d["array_index_data"];
+ }
ERR_FAIL_COND_V(!d.has("format"), false);
uint32_t format = d["format"];
@@ -746,8 +763,9 @@ bool ArrayMesh::_set(const StringName &p_name, const Variant &p_value) {
array_data = _fix_array_compatibility(array_data, format, vertex_count);
int index_count = 0;
- if (d.has("index_count"))
+ if (d.has("index_count")) {
index_count = d["index_count"];
+ }
Vector<Vector<uint8_t>> blend_shapes;
@@ -989,15 +1007,17 @@ void ArrayMesh::_set_surfaces(const Array &p_surfaces) {
}
bool ArrayMesh::_get(const StringName &p_name, Variant &r_ret) const {
- if (_is_generated())
+ if (_is_generated()) {
return false;
+ }
String sname = p_name;
if (p_name == "blend_shape/names") {
Vector<String> sk;
- for (int i = 0; i < blend_shapes.size(); i++)
+ for (int i = 0; i < blend_shapes.size(); i++) {
sk.push_back(blend_shapes[i]);
+ }
r_ret = sk;
return true;
} else if (p_name == "blend_shape/mode") {
@@ -1005,14 +1025,16 @@ bool ArrayMesh::_get(const StringName &p_name, Variant &r_ret) const {
return true;
} else if (sname.begins_with("surface_")) {
int sl = sname.find("/");
- if (sl == -1)
+ if (sl == -1) {
return false;
+ }
int idx = sname.substr(8, sl - 8).to_int() - 1;
String what = sname.get_slicec('/', 1);
- if (what == "material")
+ if (what == "material") {
r_ret = surface_get_material(idx);
- else if (what == "name")
+ } else if (what == "name") {
r_ret = surface_get_name(idx);
+ }
return true;
}
@@ -1020,8 +1042,9 @@ bool ArrayMesh::_get(const StringName &p_name, Variant &r_ret) const {
}
void ArrayMesh::_get_property_list(List<PropertyInfo> *p_list) const {
- if (_is_generated())
+ if (_is_generated()) {
return;
+ }
if (blend_shapes.size()) {
p_list->push_back(PropertyInfo(Variant::PACKED_STRING_ARRAY, "blend_shape/names", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
@@ -1043,10 +1066,11 @@ void ArrayMesh::_recompute_aabb() {
aabb = AABB();
for (int i = 0; i < surfaces.size(); i++) {
- if (i == 0)
+ if (i == 0) {
aabb = surfaces[i].aabb;
- else
+ } else {
aabb.merge_with(surfaces[i].aabb);
+ }
}
}
#ifndef _MSC_VER
@@ -1188,8 +1212,9 @@ ArrayMesh::PrimitiveType ArrayMesh::surface_get_primitive_type(int p_idx) const
void ArrayMesh::surface_set_material(int p_idx, const Ref<Material> &p_material) {
ERR_FAIL_INDEX(p_idx, surfaces.size());
- if (surfaces[p_idx].material == p_material)
+ if (surfaces[p_idx].material == p_material) {
return;
+ }
surfaces.write[p_idx].material = p_material;
RenderingServer::get_singleton()->mesh_surface_set_material(mesh, p_idx, p_material.is_null() ? RID() : p_material->get_rid());
@@ -1363,8 +1388,9 @@ Error ArrayMesh::lightmap_unwrap_cached(int *&r_cache_data, unsigned int &r_cach
if (ic == 0) {
for (int j = 0; j < vc / 3; j++) {
- if (Face3(r[j * 3 + 0], r[j * 3 + 1], r[j * 3 + 2]).is_degenerate())
+ if (Face3(r[j * 3 + 0], r[j * 3 + 1], r[j * 3 + 2]).is_degenerate()) {
continue;
+ }
indices.push_back(vertex_ofs + j * 3 + 0);
indices.push_back(vertex_ofs + j * 3 + 1);
@@ -1375,8 +1401,9 @@ Error ArrayMesh::lightmap_unwrap_cached(int *&r_cache_data, unsigned int &r_cach
const int *ri = rindices.ptr();
for (int j = 0; j < ic / 3; j++) {
- if (Face3(r[ri[j * 3 + 0]], r[ri[j * 3 + 1]], r[ri[j * 3 + 2]]).is_degenerate())
+ if (Face3(r[ri[j * 3 + 0]], r[ri[j * 3 + 1]], r[ri[j * 3 + 2]]).is_degenerate()) {
continue;
+ }
indices.push_back(vertex_ofs + ri[j * 3 + 0]);
indices.push_back(vertex_ofs + ri[j * 3 + 1]);
indices.push_back(vertex_ofs + ri[j * 3 + 2]);
diff --git a/scene/resources/mesh_data_tool.cpp b/scene/resources/mesh_data_tool.cpp
index 3176b83bb8..a5c360f123 100644
--- a/scene/resources/mesh_data_tool.cpp
+++ b/scene/resources/mesh_data_tool.cpp
@@ -57,47 +57,59 @@ Error MeshDataTool::create_from_surface(const Ref<ArrayMesh> &p_mesh, int p_surf
const Vector3 *vr = varray.ptr();
const Vector3 *nr = nullptr;
- if (arrays[Mesh::ARRAY_NORMAL].get_type() != Variant::NIL)
+ if (arrays[Mesh::ARRAY_NORMAL].get_type() != Variant::NIL) {
nr = arrays[Mesh::ARRAY_NORMAL].operator Vector<Vector3>().ptr();
+ }
const real_t *ta = nullptr;
- if (arrays[Mesh::ARRAY_TANGENT].get_type() != Variant::NIL)
+ if (arrays[Mesh::ARRAY_TANGENT].get_type() != Variant::NIL) {
ta = arrays[Mesh::ARRAY_TANGENT].operator Vector<real_t>().ptr();
+ }
const Vector2 *uv = nullptr;
- if (arrays[Mesh::ARRAY_TEX_UV].get_type() != Variant::NIL)
+ if (arrays[Mesh::ARRAY_TEX_UV].get_type() != Variant::NIL) {
uv = arrays[Mesh::ARRAY_TEX_UV].operator Vector<Vector2>().ptr();
+ }
const Vector2 *uv2 = nullptr;
- if (arrays[Mesh::ARRAY_TEX_UV2].get_type() != Variant::NIL)
+ if (arrays[Mesh::ARRAY_TEX_UV2].get_type() != Variant::NIL) {
uv2 = arrays[Mesh::ARRAY_TEX_UV2].operator Vector<Vector2>().ptr();
+ }
const Color *col = nullptr;
- if (arrays[Mesh::ARRAY_COLOR].get_type() != Variant::NIL)
+ if (arrays[Mesh::ARRAY_COLOR].get_type() != Variant::NIL) {
col = arrays[Mesh::ARRAY_COLOR].operator Vector<Color>().ptr();
+ }
const int *bo = nullptr;
- if (arrays[Mesh::ARRAY_BONES].get_type() != Variant::NIL)
+ if (arrays[Mesh::ARRAY_BONES].get_type() != Variant::NIL) {
bo = arrays[Mesh::ARRAY_BONES].operator Vector<int>().ptr();
+ }
const real_t *we = nullptr;
- if (arrays[Mesh::ARRAY_WEIGHTS].get_type() != Variant::NIL)
+ if (arrays[Mesh::ARRAY_WEIGHTS].get_type() != Variant::NIL) {
we = arrays[Mesh::ARRAY_WEIGHTS].operator Vector<real_t>().ptr();
+ }
vertices.resize(vcount);
for (int i = 0; i < vcount; i++) {
Vertex v;
v.vertex = vr[i];
- if (nr)
+ if (nr) {
v.normal = nr[i];
- if (ta)
+ }
+ if (ta) {
v.tangent = Plane(ta[i * 4 + 0], ta[i * 4 + 1], ta[i * 4 + 2], ta[i * 4 + 3]);
- if (uv)
+ }
+ if (uv) {
v.uv = uv[i];
- if (uv2)
+ }
+ if (uv2) {
v.uv2 = uv2[i];
- if (col)
+ }
+ if (col) {
v.color = col[i];
+ }
if (we) {
v.weights.push_back(we[i * 4 + 0]);
@@ -124,8 +136,9 @@ Error MeshDataTool::create_from_surface(const Ref<ArrayMesh> &p_mesh, int p_surf
//make code simpler
indices.resize(vcount);
int *iw = indices.ptrw();
- for (int i = 0; i < vcount; i++)
+ for (int i = 0; i < vcount; i++) {
iw[i] = i;
+ }
}
int icount = indices.size();
@@ -238,20 +251,24 @@ Error MeshDataTool::commit_to_surface(const Ref<ArrayMesh> &p_mesh) {
const Vertex &vtx = vertices[i];
vr[i] = vtx.vertex;
- if (nr)
+ if (nr) {
nr[i] = vtx.normal;
+ }
if (ta) {
ta[i * 4 + 0] = vtx.tangent.normal.x;
ta[i * 4 + 1] = vtx.tangent.normal.y;
ta[i * 4 + 2] = vtx.tangent.normal.z;
ta[i * 4 + 3] = vtx.tangent.d;
}
- if (uv)
+ if (uv) {
uv[i] = vtx.uv;
- if (uv2)
+ }
+ if (uv2) {
uv2[i] = vtx.uv2;
- if (col)
+ }
+ if (col) {
col[i] = vtx.color;
+ }
if (we) {
we[i * 4 + 0] = vtx.weights[0];
@@ -280,20 +297,27 @@ Error MeshDataTool::commit_to_surface(const Ref<ArrayMesh> &p_mesh) {
arr[Mesh::ARRAY_VERTEX] = v;
arr[Mesh::ARRAY_INDEX] = in;
- if (n.size())
+ if (n.size()) {
arr[Mesh::ARRAY_NORMAL] = n;
- if (c.size())
+ }
+ if (c.size()) {
arr[Mesh::ARRAY_COLOR] = c;
- if (u.size())
+ }
+ if (u.size()) {
arr[Mesh::ARRAY_TEX_UV] = u;
- if (u2.size())
+ }
+ if (u2.size()) {
arr[Mesh::ARRAY_TEX_UV2] = u2;
- if (t.size())
+ }
+ if (t.size()) {
arr[Mesh::ARRAY_TANGENT] = t;
- if (b.size())
+ }
+ if (b.size()) {
arr[Mesh::ARRAY_BONES] = b;
- if (w.size())
+ }
+ if (w.size()) {
arr[Mesh::ARRAY_WEIGHTS] = w;
+ }
Ref<ArrayMesh> ncmesh = p_mesh;
int sc = ncmesh->get_surface_count();
diff --git a/scene/resources/mesh_library.cpp b/scene/resources/mesh_library.cpp
index 0f2fd939ec..09b0d4b038 100644
--- a/scene/resources/mesh_library.cpp
+++ b/scene/resources/mesh_library.cpp
@@ -35,14 +35,15 @@ bool MeshLibrary::_set(const StringName &p_name, const Variant &p_value) {
if (name.begins_with("item/")) {
int idx = name.get_slicec('/', 1).to_int();
String what = name.get_slicec('/', 2);
- if (!item_map.has(idx))
+ if (!item_map.has(idx)) {
create_item(idx);
+ }
- if (what == "name")
+ if (what == "name") {
set_item_name(idx, p_value);
- else if (what == "mesh")
+ } else if (what == "mesh") {
set_item_mesh(idx, p_value);
- else if (what == "shape") {
+ } else if (what == "shape") {
Vector<ShapeData> shapes;
ShapeData sd;
sd.shape = p_value;
@@ -50,14 +51,15 @@ bool MeshLibrary::_set(const StringName &p_name, const Variant &p_value) {
set_item_shapes(idx, shapes);
} else if (what == "shapes") {
_set_item_shapes(idx, p_value);
- } else if (what == "preview")
+ } else if (what == "preview") {
set_item_preview(idx, p_value);
- else if (what == "navmesh")
+ } else if (what == "navmesh") {
set_item_navmesh(idx, p_value);
- else if (what == "navmesh_transform")
+ } else if (what == "navmesh_transform") {
set_item_navmesh_transform(idx, p_value);
- else
+ } else {
return false;
+ }
return true;
}
@@ -71,20 +73,21 @@ bool MeshLibrary::_get(const StringName &p_name, Variant &r_ret) const {
ERR_FAIL_COND_V(!item_map.has(idx), false);
String what = name.get_slicec('/', 2);
- if (what == "name")
+ if (what == "name") {
r_ret = get_item_name(idx);
- else if (what == "mesh")
+ } else if (what == "mesh") {
r_ret = get_item_mesh(idx);
- else if (what == "shapes")
+ } else if (what == "shapes") {
r_ret = _get_item_shapes(idx);
- else if (what == "navmesh")
+ } else if (what == "navmesh") {
r_ret = get_item_navmesh(idx);
- else if (what == "navmesh_transform")
+ } else if (what == "navmesh_transform") {
r_ret = get_item_navmesh_transform(idx);
- else if (what == "preview")
+ } else if (what == "preview") {
r_ret = get_item_preview(idx);
- else
+ } else {
return false;
+ }
return true;
}
@@ -219,17 +222,19 @@ Vector<int> MeshLibrary::get_item_list() const {
int MeshLibrary::find_item_by_name(const String &p_name) const {
for (Map<int, Item>::Element *E = item_map.front(); E; E = E->next()) {
- if (E->get().name == p_name)
+ if (E->get().name == p_name) {
return E->key();
+ }
}
return -1;
}
int MeshLibrary::get_last_unused_item_id() const {
- if (!item_map.size())
+ if (!item_map.size()) {
return 0;
- else
+ } else {
return item_map.back()->key() + 1;
+ }
}
void MeshLibrary::_set_item_shapes(int p_item, const Array &p_shapes) {
diff --git a/scene/resources/multimesh.cpp b/scene/resources/multimesh.cpp
index 10b9e24fbd..f71cf383e5 100644
--- a/scene/resources/multimesh.cpp
+++ b/scene/resources/multimesh.cpp
@@ -36,14 +36,16 @@
// Kept for compatibility from 3.x to 4.0.
void MultiMesh::_set_transform_array(const Vector<Vector3> &p_array) {
- if (transform_format != TRANSFORM_3D)
+ if (transform_format != TRANSFORM_3D) {
return;
+ }
const Vector<Vector3> &xforms = p_array;
int len = xforms.size();
ERR_FAIL_COND((len / 4) != instance_count);
- if (len == 0)
+ if (len == 0) {
return;
+ }
const Vector3 *r = xforms.ptr();
@@ -59,11 +61,13 @@ void MultiMesh::_set_transform_array(const Vector<Vector3> &p_array) {
}
Vector<Vector3> MultiMesh::_get_transform_array() const {
- if (transform_format != TRANSFORM_3D)
+ if (transform_format != TRANSFORM_3D) {
return Vector<Vector3>();
+ }
- if (instance_count == 0)
+ if (instance_count == 0) {
return Vector<Vector3>();
+ }
Vector<Vector3> xforms;
xforms.resize(instance_count * 4);
@@ -82,14 +86,16 @@ Vector<Vector3> MultiMesh::_get_transform_array() const {
}
void MultiMesh::_set_transform_2d_array(const Vector<Vector2> &p_array) {
- if (transform_format != TRANSFORM_2D)
+ if (transform_format != TRANSFORM_2D) {
return;
+ }
const Vector<Vector2> &xforms = p_array;
int len = xforms.size();
ERR_FAIL_COND((len / 3) != instance_count);
- if (len == 0)
+ if (len == 0) {
return;
+ }
const Vector2 *r = xforms.ptr();
@@ -104,11 +110,13 @@ void MultiMesh::_set_transform_2d_array(const Vector<Vector2> &p_array) {
}
Vector<Vector2> MultiMesh::_get_transform_2d_array() const {
- if (transform_format != TRANSFORM_2D)
+ if (transform_format != TRANSFORM_2D) {
return Vector<Vector2>();
+ }
- if (instance_count == 0)
+ if (instance_count == 0) {
return Vector<Vector2>();
+ }
Vector<Vector2> xforms;
xforms.resize(instance_count * 3);
@@ -128,8 +136,9 @@ Vector<Vector2> MultiMesh::_get_transform_2d_array() const {
void MultiMesh::_set_color_array(const Vector<Color> &p_array) {
const Vector<Color> &colors = p_array;
int len = colors.size();
- if (len == 0)
+ if (len == 0) {
return;
+ }
ERR_FAIL_COND(len != instance_count);
const Color *r = colors.ptr();
@@ -140,8 +149,9 @@ void MultiMesh::_set_color_array(const Vector<Color> &p_array) {
}
Vector<Color> MultiMesh::_get_color_array() const {
- if (instance_count == 0 || !use_colors)
+ if (instance_count == 0 || !use_colors) {
return Vector<Color>();
+ }
Vector<Color> colors;
colors.resize(instance_count);
@@ -156,8 +166,9 @@ Vector<Color> MultiMesh::_get_color_array() const {
void MultiMesh::_set_custom_data_array(const Vector<Color> &p_array) {
const Vector<Color> &custom_datas = p_array;
int len = custom_datas.size();
- if (len == 0)
+ if (len == 0) {
return;
+ }
ERR_FAIL_COND(len != instance_count);
const Color *r = custom_datas.ptr();
@@ -168,8 +179,9 @@ void MultiMesh::_set_custom_data_array(const Vector<Color> &p_array) {
}
Vector<Color> MultiMesh::_get_custom_data_array() const {
- if (instance_count == 0 || !use_custom_data)
+ if (instance_count == 0 || !use_custom_data) {
return Vector<Color>();
+ }
Vector<Color> custom_datas;
custom_datas.resize(instance_count);
@@ -192,10 +204,11 @@ Vector<float> MultiMesh::get_buffer() const {
void MultiMesh::set_mesh(const Ref<Mesh> &p_mesh) {
mesh = p_mesh;
- if (!mesh.is_null())
+ if (!mesh.is_null()) {
RenderingServer::get_singleton()->multimesh_set_mesh(multimesh, mesh->get_rid());
- else
+ } else {
RenderingServer::get_singleton()->multimesh_set_mesh(multimesh, RID());
+ }
}
Ref<Mesh> MultiMesh::get_mesh() const {
diff --git a/scene/resources/navigation_mesh.cpp b/scene/resources/navigation_mesh.cpp
index 13d818188d..e815da5d45 100644
--- a/scene/resources/navigation_mesh.cpp
+++ b/scene/resources/navigation_mesh.cpp
@@ -35,13 +35,15 @@ void NavigationMesh::create_from_mesh(const Ref<Mesh> &p_mesh) {
clear_polygons();
for (int i = 0; i < p_mesh->get_surface_count(); i++) {
- if (p_mesh->surface_get_primitive_type(i) != Mesh::PRIMITIVE_TRIANGLES)
+ if (p_mesh->surface_get_primitive_type(i) != Mesh::PRIMITIVE_TRIANGLES) {
continue;
+ }
Array arr = p_mesh->surface_get_arrays(i);
Vector<Vector3> varr = arr[Mesh::ARRAY_VERTEX];
Vector<int> iarr = arr[Mesh::ARRAY_INDEX];
- if (varr.size() == 0 || iarr.size() == 0)
+ if (varr.size() == 0 || iarr.size() == 0) {
continue;
+ }
int from = vertices.size();
vertices.append_array(varr);
@@ -89,10 +91,11 @@ uint32_t NavigationMesh::get_collision_mask() const {
void NavigationMesh::set_collision_mask_bit(int p_bit, bool p_value) {
uint32_t mask = get_collision_mask();
- if (p_value)
+ if (p_value) {
mask |= 1 << p_bit;
- else
+ } else {
mask &= ~(1 << p_bit);
+ }
set_collision_mask(mask);
}
@@ -294,8 +297,9 @@ void NavigationMesh::clear_polygons() {
}
Ref<Mesh> NavigationMesh::get_debug_mesh() {
- if (debug_mesh.is_valid())
+ if (debug_mesh.is_valid()) {
return debug_mesh;
+ }
Vector<Vector3> vertices = get_vertices();
const Vector3 *vr = vertices.ptr();
@@ -329,8 +333,9 @@ Ref<Mesh> NavigationMesh::get_debug_mesh() {
_EdgeKey ek;
ek.from = f.vertex[j].snapped(Vector3(CMP_EPSILON, CMP_EPSILON, CMP_EPSILON));
ek.to = f.vertex[(j + 1) % 3].snapped(Vector3(CMP_EPSILON, CMP_EPSILON, CMP_EPSILON));
- if (ek.from < ek.to)
+ if (ek.from < ek.to) {
SWAP(ek.from, ek.to);
+ }
Map<_EdgeKey, bool>::Element *F = edge_map.find(ek);
diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp
index ba2cdf75e4..058e89cf2e 100644
--- a/scene/resources/packed_scene.cpp
+++ b/scene/resources/packed_scene.cpp
@@ -64,13 +64,15 @@ Node *SceneState::instance(GenEditState p_edit_state) const {
const StringName *snames = nullptr;
int sname_count = names.size();
- if (sname_count)
+ if (sname_count) {
snames = &names[0];
+ }
const Variant *props = nullptr;
int prop_count = variants.size();
- if (prop_count)
+ if (prop_count) {
props = &variants[0];
+ }
//Vector<Variant> properties;
@@ -256,8 +258,9 @@ Node *SceneState::instance(GenEditState p_edit_state) const {
if (i > 0) {
if (parent) {
parent->_add_child_nocheck(node, snames[n.name]);
- if (n.index >= 0 && n.index < parent->get_child_count() - 1)
+ if (n.index >= 0 && n.index < parent->get_child_count() - 1) {
parent->move_child(node, n.index);
+ }
} else {
//it may be possible that an instanced scene has changed
//and the node has nowhere to go anymore
@@ -275,8 +278,9 @@ Node *SceneState::instance(GenEditState p_edit_state) const {
if (n.owner >= 0) {
NODE_FROM_ID(owner, n.owner);
- if (owner)
+ if (owner) {
node->_set_owner_nocheck(owner);
+ }
}
}
@@ -305,14 +309,16 @@ Node *SceneState::instance(GenEditState p_edit_state) const {
NODE_FROM_ID(cfrom, c.from);
NODE_FROM_ID(cto, c.to);
- if (!cfrom || !cto)
+ if (!cfrom || !cto) {
continue;
+ }
Vector<Variant> binds;
if (c.binds.size()) {
binds.resize(c.binds.size());
- for (int j = 0; j < c.binds.size(); j++)
+ for (int j = 0; j < c.binds.size(); j++) {
binds.write[j] = props[c.binds[j]];
+ }
}
cfrom->connect(snames[c.signal], Callable(cto, snames[c.method]), binds, CONNECT_PERSIST | c.flags);
@@ -337,8 +343,9 @@ Node *SceneState::instance(GenEditState p_edit_state) const {
}
static int _nm_get_string(const String &p_string, Map<StringName, int> &name_map) {
- if (name_map.has(p_string))
+ if (name_map.has(p_string)) {
return name_map[p_string];
+ }
int idx = name_map.size();
name_map[p_string] = idx;
@@ -346,8 +353,9 @@ static int _nm_get_string(const String &p_string, Map<StringName, int> &name_map
}
static int _vm_get_variant(const Variant &p_variant, HashMap<Variant, int, VariantHasher, VariantComparator> &variant_map) {
- if (variant_map.has(p_variant))
+ if (variant_map.has(p_variant)) {
return variant_map[p_variant];
+ }
int idx = variant_map.size();
variant_map[p_variant] = idx;
@@ -361,13 +369,15 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map
// document it. if you fail to understand something, please ask!
//discard nodes that do not belong to be processed
- if (p_node != p_owner && p_node->get_owner() != p_owner && !p_owner->is_editable_instance(p_node->get_owner()))
+ if (p_node != p_owner && p_node->get_owner() != p_owner && !p_owner->is_editable_instance(p_node->get_owner())) {
return OK;
+ }
// save the child instanced scenes that are chosen as editable, so they can be restored
// upon load back
- if (p_node != p_owner && p_node->get_filename() != String() && p_owner->is_editable_instance(p_node))
+ if (p_node != p_owner && p_node->get_filename() != String() && p_owner->is_editable_instance(p_node)) {
editable_instances.push_back(p_owner->get_path_to(p_node));
+ }
NodeData nd;
@@ -513,8 +523,9 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map
float a = value;
float b = original;
- if (Math::is_equal_approx(a, b))
+ if (Math::is_equal_approx(a, b)) {
continue;
+ }
} else if (bool(Variant::evaluate(Variant::OP_EQUAL, value, original))) {
continue;
}
@@ -547,8 +558,9 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map
for (List<Node::GroupInfo>::Element *E = groups.front(); E; E = E->next()) {
Node::GroupInfo &gi = E->get();
- if (!gi.persistent)
+ if (!gi.persistent) {
continue;
+ }
/*
if (instance_state_node>=0 && instance_state->is_node_in_group(instance_state_node,gi.name))
continue; //group was instanced, don't add here
@@ -564,8 +576,9 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map
}
}
- if (skip)
+ if (skip) {
continue;
+ }
nd.groups.push_back(_nm_get_string(gi.name, name_map));
}
@@ -636,16 +649,18 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map
for (int i = 0; i < p_node->get_child_count(); i++) {
Node *c = p_node->get_child(i);
Error err = _parse_node(p_owner, c, parent_node, name_map, variant_map, node_map, nodepath_map);
- if (err)
+ if (err) {
return err;
+ }
}
return OK;
}
Error SceneState::_parse_connections(Node *p_owner, Node *p_node, Map<StringName, int> &name_map, HashMap<Variant, int, VariantHasher, VariantComparator> &variant_map, Map<Node *, int> &node_map, Map<Node *, int> &nodepath_map) {
- if (p_node != p_owner && p_node->get_owner() && p_node->get_owner() != p_owner && !p_owner->is_editable_instance(p_node->get_owner()))
+ if (p_node != p_owner && p_node->get_owner() && p_node->get_owner() != p_owner && !p_owner->is_editable_instance(p_node->get_owner())) {
return OK;
+ }
List<MethodInfo> _signals;
p_node->get_signal_list(&_signals);
@@ -663,8 +678,9 @@ Error SceneState::_parse_connections(Node *p_owner, Node *p_node, Map<StringName
for (List<Node::Connection>::Element *F = conns.front(); F; F = F->next()) {
const Node::Connection &c = F->get();
- if (!(c.flags & CONNECT_PERSIST)) //only persistent connections get saved
+ if (!(c.flags & CONNECT_PERSIST)) { //only persistent connections get saved
continue;
+ }
// only connections that originate or end into main saved scene are saved
// everything else is discarded
@@ -690,10 +706,11 @@ Error SceneState::_parse_connections(Node *p_owner, Node *p_node, Map<StringName
while (common_parent) {
Ref<SceneState> ps;
- if (common_parent == p_owner)
+ if (common_parent == p_owner) {
ps = common_parent->get_scene_inherited_state();
- else
+ } else {
ps = common_parent->get_scene_instance_state();
+ }
if (ps.is_valid()) {
NodePath signal_from = common_parent->get_path_to(p_node);
@@ -705,10 +722,11 @@ Error SceneState::_parse_connections(Node *p_owner, Node *p_node, Map<StringName
}
}
- if (common_parent == p_owner)
+ if (common_parent == p_owner) {
break;
- else
+ } else {
common_parent = common_parent->get_owner();
+ }
}
if (exists) { //already exists (comes from instance or inheritance), so don't save
@@ -807,8 +825,9 @@ Error SceneState::_parse_connections(Node *p_owner, Node *p_node, Map<StringName
for (int i = 0; i < p_node->get_child_count(); i++) {
Node *c = p_node->get_child(i);
Error err = _parse_connections(p_owner, c, name_map, variant_map, node_map, nodepath_map);
- if (err)
+ if (err) {
return err;
+ }
}
return OK;
@@ -973,8 +992,9 @@ bool SceneState::is_node_in_group(int p_node, const StringName &p_group) const {
if (p_node < nodes.size()) {
const StringName *namep = names.ptr();
for (int i = 0; i < nodes[p_node].groups.size(); i++) {
- if (namep[nodes[p_node].groups[i]] == p_group)
+ if (namep[nodes[p_node].groups[i]] == p_group) {
return true;
+ }
}
}
@@ -1034,8 +1054,9 @@ void SceneState::set_bundled_scene(const Dictionary &p_dictionary) {
//ERR_FAIL_COND( !p_dictionary.has("path"));
int version = 1;
- if (p_dictionary.has("version"))
+ if (p_dictionary.has("version")) {
version = p_dictionary["version"];
+ }
ERR_FAIL_COND_MSG(version > PACKED_SCENE_VERSION, "Save format version too new.");
@@ -1052,8 +1073,9 @@ void SceneState::set_bundled_scene(const Dictionary &p_dictionary) {
int namecount = snames.size();
names.resize(namecount);
const String *r = snames.ptr();
- for (int i = 0; i < names.size(); i++)
+ for (int i = 0; i < names.size(); i++) {
names.write[i] = r[i];
+ }
}
Array svariants = p_dictionary["variants"];
@@ -1147,8 +1169,9 @@ Dictionary SceneState::get_bundled_scene() const {
if (names.size()) {
String *r = rnames.ptrw();
- for (int i = 0; i < names.size(); i++)
+ for (int i = 0; i < names.size(); i++) {
r[i] = names[i];
+ }
}
Dictionary d;
@@ -1193,8 +1216,9 @@ Dictionary SceneState::get_bundled_scene() const {
rconns.push_back(cd.method);
rconns.push_back(cd.flags);
rconns.push_back(cd.binds.size());
- for (int j = 0; j < cd.binds.size(); j++)
+ for (int j = 0; j < cd.binds.size(); j++) {
rconns.push_back(cd.binds[j]);
+ }
}
d["conns"] = rconns;
@@ -1227,8 +1251,9 @@ int SceneState::get_node_count() const {
StringName SceneState::get_node_type(int p_idx) const {
ERR_FAIL_INDEX_V(p_idx, nodes.size(), StringName());
- if (nodes[p_idx].type == TYPE_INSTANCED)
+ if (nodes[p_idx].type == TYPE_INSTANCED) {
return StringName();
+ }
return names[nodes[p_idx].type];
}
@@ -1252,10 +1277,11 @@ Ref<PackedScene> SceneState::get_node_instance(int p_idx) const {
ERR_FAIL_INDEX_V(p_idx, nodes.size(), Ref<PackedScene>());
if (nodes[p_idx].instance >= 0) {
- if (nodes[p_idx].instance & FLAG_INSTANCE_IS_PLACEHOLDER)
+ if (nodes[p_idx].instance & FLAG_INSTANCE_IS_PLACEHOLDER) {
return Ref<PackedScene>();
- else
+ } else {
return variants[nodes[p_idx].instance & FLAG_MASK];
+ }
} else if (nodes[p_idx].parent < 0 || nodes[p_idx].parent == NO_PARENT_SAVED) {
if (base_scene_idx >= 0) {
return variants[base_scene_idx];
@@ -1347,8 +1373,9 @@ Variant SceneState::get_node_property_value(int p_idx, int p_prop) const {
NodePath SceneState::get_node_owner_path(int p_idx) const {
ERR_FAIL_INDEX_V(p_idx, nodes.size(), NodePath());
- if (nodes[p_idx].owner < 0 || nodes[p_idx].owner == NO_PARENT_SAVED)
+ if (nodes[p_idx].owner < 0 || nodes[p_idx].owner == NO_PARENT_SAVED) {
return NodePath(); //root likely
+ }
if (nodes[p_idx].owner & FLAG_ID_IS_PATH) {
return node_paths[nodes[p_idx].owner & FLAG_MASK];
} else {
@@ -1453,8 +1480,9 @@ int SceneState::add_name(const StringName &p_name) {
int SceneState::find_name(const StringName &p_name) const {
for (int i = 0; i < names.size(); i++) {
- if (names[i] == p_name)
+ if (names[i] == p_name) {
return i;
+ }
}
return -1;
@@ -1531,8 +1559,9 @@ Vector<String> SceneState::_get_node_groups(int p_idx) const {
Vector<StringName> groups = get_node_groups(p_idx);
Vector<String> ret;
- for (int i = 0; i < groups.size(); i++)
+ for (int i = 0; i < groups.size(); i++) {
ret.push_back(groups[i]);
+ }
return ret;
}
@@ -1599,15 +1628,17 @@ Node *PackedScene::instance(GenEditState p_edit_state) const {
#endif
Node *s = state->instance((SceneState::GenEditState)p_edit_state);
- if (!s)
+ if (!s) {
return nullptr;
+ }
if (p_edit_state != GEN_EDIT_STATE_DISABLED) {
s->set_scene_instance_state(state);
}
- if (get_path() != "" && get_path().find("::") == -1)
+ if (get_path() != "" && get_path().find("::") == -1) {
s->set_filename(get_path());
+ }
s->notification(Node::NOTIFICATION_INSTANCED);
diff --git a/scene/resources/particles_material.cpp b/scene/resources/particles_material.cpp
index 2f65c92181..fc92a721db 100644
--- a/scene/resources/particles_material.cpp
+++ b/scene/resources/particles_material.cpp
@@ -111,8 +111,9 @@ void ParticlesMaterial::_update_shader() {
dirty_materials->remove(&element);
MaterialKey mk = _compute_key();
- if (mk.key == current_key.key)
+ if (mk.key == current_key.key) {
return; //no update required in the end
+ }
if (shader_map.has(current_key)) {
shader_map[current_key].users--;
@@ -197,33 +198,46 @@ void ParticlesMaterial::_update_shader() {
code += "uniform vec3 gravity;\n";
- if (color_ramp.is_valid())
+ if (color_ramp.is_valid()) {
code += "uniform sampler2D color_ramp;\n";
+ }
- if (tex_parameters[PARAM_INITIAL_LINEAR_VELOCITY].is_valid())
+ if (tex_parameters[PARAM_INITIAL_LINEAR_VELOCITY].is_valid()) {
code += "uniform sampler2D linear_velocity_texture;\n";
- if (tex_parameters[PARAM_ORBIT_VELOCITY].is_valid())
+ }
+ if (tex_parameters[PARAM_ORBIT_VELOCITY].is_valid()) {
code += "uniform sampler2D orbit_velocity_texture;\n";
- if (tex_parameters[PARAM_ANGULAR_VELOCITY].is_valid())
+ }
+ if (tex_parameters[PARAM_ANGULAR_VELOCITY].is_valid()) {
code += "uniform sampler2D angular_velocity_texture;\n";
- if (tex_parameters[PARAM_LINEAR_ACCEL].is_valid())
+ }
+ if (tex_parameters[PARAM_LINEAR_ACCEL].is_valid()) {
code += "uniform sampler2D linear_accel_texture;\n";
- if (tex_parameters[PARAM_RADIAL_ACCEL].is_valid())
+ }
+ if (tex_parameters[PARAM_RADIAL_ACCEL].is_valid()) {
code += "uniform sampler2D radial_accel_texture;\n";
- if (tex_parameters[PARAM_TANGENTIAL_ACCEL].is_valid())
+ }
+ if (tex_parameters[PARAM_TANGENTIAL_ACCEL].is_valid()) {
code += "uniform sampler2D tangent_accel_texture;\n";
- if (tex_parameters[PARAM_DAMPING].is_valid())
+ }
+ if (tex_parameters[PARAM_DAMPING].is_valid()) {
code += "uniform sampler2D damping_texture;\n";
- if (tex_parameters[PARAM_ANGLE].is_valid())
+ }
+ if (tex_parameters[PARAM_ANGLE].is_valid()) {
code += "uniform sampler2D angle_texture;\n";
- if (tex_parameters[PARAM_SCALE].is_valid())
+ }
+ if (tex_parameters[PARAM_SCALE].is_valid()) {
code += "uniform sampler2D scale_texture;\n";
- if (tex_parameters[PARAM_HUE_VARIATION].is_valid())
+ }
+ if (tex_parameters[PARAM_HUE_VARIATION].is_valid()) {
code += "uniform sampler2D hue_variation_texture;\n";
- if (tex_parameters[PARAM_ANIM_SPEED].is_valid())
+ }
+ if (tex_parameters[PARAM_ANIM_SPEED].is_valid()) {
code += "uniform sampler2D anim_speed_texture;\n";
- if (tex_parameters[PARAM_ANIM_OFFSET].is_valid())
+ }
+ if (tex_parameters[PARAM_ANIM_OFFSET].is_valid()) {
code += "uniform sampler2D anim_offset_texture;\n";
+ }
if (trail_size_modifier.is_valid()) {
code += "uniform sampler2D trail_size_modifier;\n";
@@ -285,20 +299,23 @@ void ParticlesMaterial::_update_shader() {
code += " }\n\n";
code += " if (RESTART || restart) {\n";
- if (tex_parameters[PARAM_INITIAL_LINEAR_VELOCITY].is_valid())
+ if (tex_parameters[PARAM_INITIAL_LINEAR_VELOCITY].is_valid()) {
code += " float tex_linear_velocity = textureLod(linear_velocity_texture, vec2(0.0, 0.0), 0.0).r;\n";
- else
+ } else {
code += " float tex_linear_velocity = 0.0;\n";
+ }
- if (tex_parameters[PARAM_ANGLE].is_valid())
+ if (tex_parameters[PARAM_ANGLE].is_valid()) {
code += " float tex_angle = textureLod(angle_texture, vec2(0.0, 0.0), 0.0).r;\n";
- else
+ } else {
code += " float tex_angle = 0.0;\n";
+ }
- if (tex_parameters[PARAM_ANIM_OFFSET].is_valid())
+ if (tex_parameters[PARAM_ANIM_OFFSET].is_valid()) {
code += " float tex_anim_offset = textureLod(anim_offset_texture, vec2(0.0, 0.0), 0.0).r;\n";
- else
+ } else {
code += " float tex_anim_offset = 0.0;\n";
+ }
code += " float spread_rad = spread * degree_to_rad;\n";
@@ -374,57 +391,67 @@ void ParticlesMaterial::_update_shader() {
code += " } else {\n";
code += " CUSTOM.y += DELTA / LIFETIME;\n";
- if (tex_parameters[PARAM_INITIAL_LINEAR_VELOCITY].is_valid())
+ if (tex_parameters[PARAM_INITIAL_LINEAR_VELOCITY].is_valid()) {
code += " float tex_linear_velocity = textureLod(linear_velocity_texture, vec2(CUSTOM.y, 0.0), 0.0).r;\n";
- else
+ } else {
code += " float tex_linear_velocity = 0.0;\n";
+ }
if (flags[FLAG_DISABLE_Z]) {
- if (tex_parameters[PARAM_ORBIT_VELOCITY].is_valid())
+ if (tex_parameters[PARAM_ORBIT_VELOCITY].is_valid()) {
code += " float tex_orbit_velocity = textureLod(orbit_velocity_texture, vec2(CUSTOM.y, 0.0), 0.0).r;\n";
- else
+ } else {
code += " float tex_orbit_velocity = 0.0;\n";
+ }
}
- if (tex_parameters[PARAM_ANGULAR_VELOCITY].is_valid())
+ if (tex_parameters[PARAM_ANGULAR_VELOCITY].is_valid()) {
code += " float tex_angular_velocity = textureLod(angular_velocity_texture, vec2(CUSTOM.y, 0.0), 0.0).r;\n";
- else
+ } else {
code += " float tex_angular_velocity = 0.0;\n";
+ }
- if (tex_parameters[PARAM_LINEAR_ACCEL].is_valid())
+ if (tex_parameters[PARAM_LINEAR_ACCEL].is_valid()) {
code += " float tex_linear_accel = textureLod(linear_accel_texture, vec2(CUSTOM.y, 0.0), 0.0).r;\n";
- else
+ } else {
code += " float tex_linear_accel = 0.0;\n";
+ }
- if (tex_parameters[PARAM_RADIAL_ACCEL].is_valid())
+ if (tex_parameters[PARAM_RADIAL_ACCEL].is_valid()) {
code += " float tex_radial_accel = textureLod(radial_accel_texture, vec2(CUSTOM.y, 0.0), 0.0).r;\n";
- else
+ } else {
code += " float tex_radial_accel = 0.0;\n";
+ }
- if (tex_parameters[PARAM_TANGENTIAL_ACCEL].is_valid())
+ if (tex_parameters[PARAM_TANGENTIAL_ACCEL].is_valid()) {
code += " float tex_tangent_accel = textureLod(tangent_accel_texture, vec2(CUSTOM.y, 0.0), 0.0).r;\n";
- else
+ } else {
code += " float tex_tangent_accel = 0.0;\n";
+ }
- if (tex_parameters[PARAM_DAMPING].is_valid())
+ if (tex_parameters[PARAM_DAMPING].is_valid()) {
code += " float tex_damping = textureLod(damping_texture, vec2(CUSTOM.y, 0.0), 0.0).r;\n";
- else
+ } else {
code += " float tex_damping = 0.0;\n";
+ }
- if (tex_parameters[PARAM_ANGLE].is_valid())
+ if (tex_parameters[PARAM_ANGLE].is_valid()) {
code += " float tex_angle = textureLod(angle_texture, vec2(CUSTOM.y, 0.0), 0.0).r;\n";
- else
+ } else {
code += " float tex_angle = 0.0;\n";
+ }
- if (tex_parameters[PARAM_ANIM_SPEED].is_valid())
+ if (tex_parameters[PARAM_ANIM_SPEED].is_valid()) {
code += " float tex_anim_speed = textureLod(anim_speed_texture, vec2(CUSTOM.y, 0.0), 0.0).r;\n";
- else
+ } else {
code += " float tex_anim_speed = 0.0;\n";
+ }
- if (tex_parameters[PARAM_ANIM_OFFSET].is_valid())
+ if (tex_parameters[PARAM_ANIM_OFFSET].is_valid()) {
code += " float tex_anim_offset = textureLod(anim_offset_texture, vec2(CUSTOM.y, 0.0), 0.0).r;\n";
- else
+ } else {
code += " float tex_anim_offset = 0.0;\n";
+ }
code += " vec3 force = gravity;\n";
code += " vec3 pos = TRANSFORM[3].xyz;\n";
@@ -478,15 +505,17 @@ void ParticlesMaterial::_update_shader() {
code += " }\n";
// apply color
// apply hue rotation
- if (tex_parameters[PARAM_SCALE].is_valid())
+ if (tex_parameters[PARAM_SCALE].is_valid()) {
code += " float tex_scale = textureLod(scale_texture, vec2(CUSTOM.y, 0.0), 0.0).r;\n";
- else
+ } else {
code += " float tex_scale = 1.0;\n";
+ }
- if (tex_parameters[PARAM_HUE_VARIATION].is_valid())
+ if (tex_parameters[PARAM_HUE_VARIATION].is_valid()) {
code += " float tex_hue_variation = textureLod(hue_variation_texture, vec2(CUSTOM.y, 0.0), 0.0).r;\n";
- else
+ } else {
code += " float tex_hue_variation = 0.0;\n";
+ }
code += " float hue_rot_angle = (hue_variation + tex_hue_variation) * pi * 2.0 * mix(1.0, hue_rot_rand * 2.0 - 1.0, hue_variation_random);\n";
code += " float hue_rot_c = cos(hue_rot_angle);\n";
@@ -750,8 +779,9 @@ float ParticlesMaterial::get_param_randomness(Parameter p_param) const {
static void _adjust_curve_range(const Ref<Texture2D> &p_texture, float p_min, float p_max) {
Ref<CurveTexture> curve_tex = p_texture;
- if (!curve_tex.is_valid())
+ if (!curve_tex.is_valid()) {
return;
+ }
curve_tex->ensure_default_setup(p_min, p_max);
}
diff --git a/scene/resources/polygon_path_finder.cpp b/scene/resources/polygon_path_finder.cpp
index 8e65ae8bed..0546c92948 100644
--- a/scene/resources/polygon_path_finder.cpp
+++ b/scene/resources/polygon_path_finder.cpp
@@ -92,21 +92,24 @@ void PolygonPathFinder::setup(const Vector<Vector2> &p_points, const Vector<int>
for (int i = 0; i < point_count; i++) {
for (int j = i + 1; j < point_count; j++) {
- if (edges.has(Edge(i, j)))
+ if (edges.has(Edge(i, j))) {
continue; //if in edge ignore
+ }
Vector2 from = points[i].pos;
Vector2 to = points[j].pos;
- if (!_is_point_inside(from * 0.5 + to * 0.5)) //connection between points in inside space
+ if (!_is_point_inside(from * 0.5 + to * 0.5)) { //connection between points in inside space
continue;
+ }
bool valid = true;
for (Set<Edge>::Element *E = edges.front(); E; E = E->next()) {
const Edge &e = E->get();
- if (e.points[0] == i || e.points[1] == i || e.points[0] == j || e.points[1] == j)
+ if (e.points[0] == i || e.points[1] == i || e.points[0] == j || e.points[1] == j) {
continue;
+ }
Vector2 a = points[e.points[0]].pos;
Vector2 b = points[e.points[1]].pos;
@@ -187,10 +190,12 @@ Vector<Vector2> PolygonPathFinder::find_path(const Vector2 &p_from, const Vector
for (Set<Edge>::Element *E = edges.front(); E; E = E->next()) {
const Edge &e = E->get();
- if (e.points[0] == ignore_from_edge.points[0] && e.points[1] == ignore_from_edge.points[1])
+ if (e.points[0] == ignore_from_edge.points[0] && e.points[1] == ignore_from_edge.points[1]) {
continue;
- if (e.points[0] == ignore_to_edge.points[0] && e.points[1] == ignore_to_edge.points[1])
+ }
+ if (e.points[0] == ignore_to_edge.points[0] && e.points[1] == ignore_to_edge.points[1]) {
continue;
+ }
Vector2 a = points[e.points[0]].pos;
Vector2 b = points[e.points[1]].pos;
@@ -238,8 +243,9 @@ Vector<Vector2> PolygonPathFinder::find_path(const Vector2 &p_from, const Vector
for (Set<Edge>::Element *E = edges.front(); E; E = E->next()) {
const Edge &e = E->get();
- if (e.points[0] == i || e.points[1] == i)
+ if (e.points[0] == i || e.points[1] == i) {
continue;
+ }
Vector2 a = points[e.points[0]].pos;
Vector2 b = points[e.points[1]].pos;
@@ -266,8 +272,9 @@ Vector<Vector2> PolygonPathFinder::find_path(const Vector2 &p_from, const Vector
}
}
- if (!valid_a && !valid_b)
+ if (!valid_a && !valid_b) {
break;
+ }
}
if (valid_a) {
@@ -346,8 +353,9 @@ Vector<Vector2> PolygonPathFinder::find_path(const Vector2 &p_from, const Vector
}
}
- if (found_route)
+ if (found_route) {
break;
+ }
open_list.erase(least_cost_point);
}
@@ -390,8 +398,9 @@ void PolygonPathFinder::_set_data(const Dictionary &p_data) {
Array c = p_data["connections"];
ERR_FAIL_COND(c.size() != p.size());
- if (c.size())
+ if (c.size()) {
return;
+ }
int pc = p.size();
points.resize(pc + 2);
diff --git a/scene/resources/polygon_path_finder.h b/scene/resources/polygon_path_finder.h
index f29299055e..baee4dc20d 100644
--- a/scene/resources/polygon_path_finder.h
+++ b/scene/resources/polygon_path_finder.h
@@ -48,10 +48,11 @@ class PolygonPathFinder : public Resource {
int points[2];
_FORCE_INLINE_ bool operator<(const Edge &p_edge) const {
- if (points[0] == p_edge.points[0])
+ if (points[0] == p_edge.points[0]) {
return points[1] < p_edge.points[1];
- else
+ } else {
return points[0] < p_edge.points[0];
+ }
}
Edge(int a = 0, int b = 0) {
diff --git a/scene/resources/primitive_meshes.cpp b/scene/resources/primitive_meshes.cpp
index 6e662b1085..99edf26dc1 100644
--- a/scene/resources/primitive_meshes.cpp
+++ b/scene/resources/primitive_meshes.cpp
@@ -48,10 +48,11 @@ void PrimitiveMesh::_update() const {
{
const Vector3 *r = points.ptr();
for (int i = 0; i < pc; i++) {
- if (i == 0)
+ if (i == 0) {
aabb.position = r[i];
- else
+ } else {
aabb.expand_to(r[i]);
+ }
}
}
@@ -96,8 +97,9 @@ void PrimitiveMesh::_update() const {
}
void PrimitiveMesh::_request_update() {
- if (pending_request)
+ if (pending_request) {
return;
+ }
_update();
}
diff --git a/scene/resources/resource_format_text.cpp b/scene/resources/resource_format_text.cpp
index f758427bd6..93db8b725f 100644
--- a/scene/resources/resource_format_text.cpp
+++ b/scene/resources/resource_format_text.cpp
@@ -253,8 +253,9 @@ Ref<PackedScene> ResourceLoaderText::_parse_node_tag(VariantParser::ResourcePars
if (next_tag.fields.has("owner")) {
owner = packed_scene->get_state()->add_node_path(next_tag.fields["owner"]);
} else {
- if (parent != -1 && !(type == SceneState::TYPE_INSTANCED && instance == -1))
+ if (parent != -1 && !(type == SceneState::TYPE_INSTANCED && instance == -1)) {
owner = 0; //if no owner, owner is root
+ }
}
if (next_tag.fields.has("index")) {
@@ -391,8 +392,9 @@ Ref<PackedScene> ResourceLoaderText::_parse_node_tag(VariantParser::ResourcePars
}
Error ResourceLoaderText::load() {
- if (error != OK)
+ if (error != OK) {
return error;
+ }
while (true) {
if (next_tag.name != "ext_resource") {
@@ -659,8 +661,9 @@ Error ResourceLoaderText::load() {
Ref<PackedScene> packed_scene = _parse_node_tag(rp);
- if (!packed_scene.is_valid())
+ if (!packed_scene.is_valid()) {
return error;
+ }
error = OK;
//get it here
@@ -784,8 +787,9 @@ Error ResourceLoaderText::rename_dependencies(FileAccess *p_f, const String &p_p
if (next_tag.name != "ext_resource") {
//nothing was done
- if (!fw)
+ if (!fw) {
return OK;
+ }
break;
@@ -939,8 +943,9 @@ static void bs_save_unicode_string(FileAccess *f, const String &p_string, bool p
}
Error ResourceLoaderText::save_as_binary(FileAccess *p_f, const String &p_path) {
- if (error)
+ if (error) {
return error;
+ }
FileAccessRef wf = FileAccess::open(p_path, FileAccess::WRITE);
if (!wf) {
@@ -960,8 +965,9 @@ Error ResourceLoaderText::save_as_binary(FileAccess *p_f, const String &p_path)
bs_save_unicode_string(wf.f, is_scene ? "PackedScene" : resource_type);
wf->store_64(0); //offset to import metadata, this is no longer used
- for (int i = 0; i < 14; i++)
+ for (int i = 0; i < 14; i++) {
wf->store_32(0); // reserved
+ }
wf->store_32(0); //string table size, will not be in use
size_t ext_res_count_pos = wf->get_position();
@@ -1130,8 +1136,9 @@ Error ResourceLoaderText::save_as_binary(FileAccess *p_f, const String &p_path)
Ref<PackedScene> packed_scene = _parse_node_tag(rp);
- if (!packed_scene.is_valid())
+ if (!packed_scene.is_valid()) {
return error;
+ }
error = OK;
//get it here
@@ -1150,8 +1157,9 @@ Error ResourceLoaderText::save_as_binary(FileAccess *p_f, const String &p_path)
int prop_count = 0;
for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
- if (!(E->get().usage & PROPERTY_USAGE_STORAGE))
+ if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) {
continue;
+ }
String name = E->get().name;
Variant value = packed_scene->get(name);
@@ -1221,11 +1229,13 @@ String ResourceLoaderText::recognize(FileAccess *p_f) {
}
}
- if (tag.name == "gd_scene")
+ if (tag.name == "gd_scene") {
return "PackedScene";
+ }
- if (tag.name != "gd_resource")
+ if (tag.name != "gd_resource") {
return "";
+ }
if (!tag.fields.has("type")) {
error_text = "Missing 'type' field in 'gd_resource' tag";
@@ -1239,8 +1249,9 @@ String ResourceLoaderText::recognize(FileAccess *p_f) {
/////////////////////
RES ResourceFormatLoaderText::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) {
- if (r_error)
+ if (r_error) {
*r_error = ERR_CANT_OPEN;
+ }
Error err;
@@ -1274,10 +1285,11 @@ void ResourceFormatLoaderText::get_recognized_extensions_for_type(const String &
return;
}
- if (p_type == "PackedScene")
+ if (p_type == "PackedScene") {
p_extensions->push_back("tscn");
- else
+ } else {
p_extensions->push_back("tres");
+ }
}
void ResourceFormatLoaderText::get_recognized_extensions(List<String> *p_extensions) const {
@@ -1291,10 +1303,11 @@ bool ResourceFormatLoaderText::handles_type(const String &p_type) const {
String ResourceFormatLoaderText::get_resource_type(const String &p_path) const {
String ext = p_path.get_extension().to_lower();
- if (ext == "tscn")
+ if (ext == "tscn") {
return "PackedScene";
- else if (ext != "tres")
+ } else if (ext != "tres") {
return String();
+ }
//for anyhting else must test..
@@ -1395,8 +1408,9 @@ void ResourceFormatSaverTextInstance::_find_resources(const Variant &p_variant,
case Variant::OBJECT: {
RES res = p_variant;
- if (res.is_null() || external_resources.has(res))
+ if (res.is_null() || external_resources.has(res)) {
return;
+ }
if (!p_main && (!bundle_resources) && res->get_path().length() && res->get_path().find("::") == -1) {
if (res->get_path() == local_path) {
@@ -1408,8 +1422,9 @@ void ResourceFormatSaverTextInstance::_find_resources(const Variant &p_variant,
return;
}
- if (resource_set.has(res))
+ if (resource_set.has(res)) {
return;
+ }
List<PropertyInfo> property_list;
@@ -1495,8 +1510,9 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r
if (packed_scene.is_valid()) {
//add instances to external resources if saving a packed scene
for (int i = 0; i < packed_scene->get_state()->get_node_count(); i++) {
- if (packed_scene->get_state()->is_node_instance_placeholder(i))
+ if (packed_scene->get_state()->is_node_instance_placeholder(i)) {
continue;
+ }
Ref<PackedScene> instance = packed_scene->get_state()->get_node_instance(i);
if (instance.is_valid() && !external_resources.has(instance)) {
@@ -1508,8 +1524,9 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r
{
String title = packed_scene.is_valid() ? "[gd_scene " : "[gd_resource ";
- if (packed_scene.is_null())
+ if (packed_scene.is_null()) {
title += "type=\"" + p_resource->get_class() + "\" ";
+ }
int load_steps = saved_resources.size() + external_resources.size();
/*
if (packed_scene.is_valid()) {
@@ -1580,8 +1597,9 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r
f->store_string("[ext_resource path=\"" + p + "\" type=\"" + sorted_er[i].resource->get_save_class() + "\" id=" + itos(sorted_er[i].index) + "]\n"); //bundled
}
- if (external_resources.size())
+ if (external_resources.size()) {
f->store_line(String()); //separate
+ }
Set<int> used_indices;
@@ -1603,8 +1621,9 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r
ERR_CONTINUE(!resource_set.has(res));
bool main = (E->next() == nullptr);
- if (main && packed_scene.is_valid())
+ if (main && packed_scene.is_valid()) {
break; //save as a scene
+ }
if (main) {
f->store_line("[resource]");
@@ -1637,8 +1656,9 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r
res->get_property_list(&property_list);
//property_list.sort();
for (List<PropertyInfo>::Element *PE = property_list.front(); PE; PE = PE->next()) {
- if (skip_editor && PE->get().name.begins_with("__editor"))
+ if (skip_editor && PE->get().name.begins_with("__editor")) {
continue;
+ }
if (PE->get().usage & PROPERTY_USAGE_STORAGE) {
String name = PE->get().name;
@@ -1659,8 +1679,9 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r
continue;
}
- if (PE->get().type == Variant::OBJECT && value.is_zero() && !(PE->get().usage & PROPERTY_USAGE_STORE_IF_NULL))
+ if (PE->get().type == Variant::OBJECT && value.is_zero() && !(PE->get().usage & PROPERTY_USAGE_STORE_IF_NULL)) {
continue;
+ }
String vars;
VariantWriter::write_to_string(value, vars, _write_resources, this);
@@ -1668,8 +1689,9 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r
}
}
- if (E->next())
+ if (E->next()) {
f->store_line(String());
+ }
}
if (packed_scene.is_valid()) {
@@ -1735,8 +1757,9 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r
f->store_string(String(state->get_node_property_name(i, j)).property_name_encode() + " = " + vars + "\n");
}
- if (i < state->get_node_count() - 1)
+ if (i < state->get_node_count() - 1) {
f->store_line(String());
+ }
}
for (int i = 0; i < state->get_connection_count(); i++) {
@@ -1792,10 +1815,11 @@ bool ResourceFormatSaverText::recognize(const RES &p_resource) const {
}
void ResourceFormatSaverText::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const {
- if (p_resource->get_class() == "PackedScene")
+ if (p_resource->get_class() == "PackedScene") {
p_extensions->push_back("tscn"); //text scene
- else
+ } else {
p_extensions->push_back("tres"); //text resource
+ }
}
ResourceFormatSaverText *ResourceFormatSaverText::singleton = nullptr;
diff --git a/scene/resources/segment_shape_2d.cpp b/scene/resources/segment_shape_2d.cpp
index 2f7fbfb311..7b409eebbb 100644
--- a/scene/resources/segment_shape_2d.cpp
+++ b/scene/resources/segment_shape_2d.cpp
@@ -117,8 +117,9 @@ void RayShape2D::draw(const RID &p_to_rid, const Color &p_color) {
pts.push_back(tip + Vector2(Math_SQRT12 * tsize, 0));
pts.push_back(tip + Vector2(-Math_SQRT12 * tsize, 0));
Vector<Color> cols;
- for (int i = 0; i < 3; i++)
+ for (int i = 0; i < 3; i++) {
cols.push_back(p_color);
+ }
RS::get_singleton()->canvas_item_add_primitive(p_to_rid, pts, cols, Vector<Point2>(), RID());
}
diff --git a/scene/resources/shader.cpp b/scene/resources/shader.cpp
index 341139e1c4..4ca8032d65 100644
--- a/scene/resources/shader.cpp
+++ b/scene/resources/shader.cpp
@@ -80,8 +80,9 @@ void Shader::get_param_list(List<PropertyInfo> *p_params) const {
params_cache[pi.name] = E->get().name;
if (p_params) {
//small little hack
- if (pi.type == Variant::_RID)
+ if (pi.type == Variant::_RID) {
pi.type = Variant::OBJECT;
+ }
p_params->push_back(pi);
}
}
@@ -106,10 +107,11 @@ void Shader::set_default_texture_param(const StringName &p_param, const Ref<Text
}
Ref<Texture2D> Shader::get_default_texture_param(const StringName &p_param) const {
- if (default_textures.has(p_param))
+ if (default_textures.has(p_param)) {
return default_textures[p_param];
- else
+ } else {
return Ref<Texture2D>();
+ }
}
void Shader::get_default_texture_param_list(List<StringName> *r_textures) const {
@@ -163,8 +165,9 @@ Shader::~Shader() {
////////////
RES ResourceFormatLoaderShader::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) {
- if (r_error)
+ if (r_error) {
*r_error = ERR_FILE_CANT_OPEN;
+ }
Ref<Shader> shader;
shader.instance();
@@ -176,8 +179,9 @@ RES ResourceFormatLoaderShader::load(const String &p_path, const String &p_origi
shader->set_code(str);
- if (r_error)
+ if (r_error) {
*r_error = OK;
+ }
return shader;
}
@@ -192,8 +196,9 @@ bool ResourceFormatLoaderShader::handles_type(const String &p_type) const {
String ResourceFormatLoaderShader::get_resource_type(const String &p_path) const {
String el = p_path.get_extension().to_lower();
- if (el == "shader")
+ if (el == "shader") {
return "Shader";
+ }
return "";
}
diff --git a/scene/resources/shader.h b/scene/resources/shader.h
index 9fa8a9ae95..2cdc2ec93f 100644
--- a/scene/resources/shader.h
+++ b/scene/resources/shader.h
@@ -82,12 +82,14 @@ public:
virtual bool is_text_shader() const;
_FORCE_INLINE_ StringName remap_param(const StringName &p_param) const {
- if (params_cache_dirty)
+ if (params_cache_dirty) {
get_param_list(nullptr);
+ }
const Map<StringName, StringName>::Element *E = params_cache.find(p_param);
- if (E)
+ if (E) {
return E->get();
+ }
return StringName();
}
diff --git a/scene/resources/shape_2d.cpp b/scene/resources/shape_2d.cpp
index 60c796f9f9..99e8020e34 100644
--- a/scene/resources/shape_2d.cpp
+++ b/scene/resources/shape_2d.cpp
@@ -61,8 +61,9 @@ Array Shape2D::collide_with_motion_and_get_contacts(const Transform2D &p_local_x
Vector2 result[max_contacts * 2];
int contacts = 0;
- if (!PhysicsServer2D::get_singleton()->shape_collide(get_rid(), p_local_xform, p_local_motion, p_shape->get_rid(), p_shape_xform, p_shape_motion, result, max_contacts, contacts))
+ if (!PhysicsServer2D::get_singleton()->shape_collide(get_rid(), p_local_xform, p_local_motion, p_shape->get_rid(), p_shape_xform, p_shape_motion, result, max_contacts, contacts)) {
return Array();
+ }
Array results;
results.resize(contacts * 2);
@@ -79,8 +80,9 @@ Array Shape2D::collide_and_get_contacts(const Transform2D &p_local_xform, const
Vector2 result[max_contacts * 2];
int contacts = 0;
- if (!PhysicsServer2D::get_singleton()->shape_collide(get_rid(), p_local_xform, Vector2(), p_shape->get_rid(), p_shape_xform, Vector2(), result, max_contacts, contacts))
+ if (!PhysicsServer2D::get_singleton()->shape_collide(get_rid(), p_local_xform, Vector2(), p_shape->get_rid(), p_shape_xform, Vector2(), result, max_contacts, contacts)) {
return Array();
+ }
Array results;
results.resize(contacts * 2);
diff --git a/scene/resources/shape_3d.cpp b/scene/resources/shape_3d.cpp
index 110543723c..59766f4f1f 100644
--- a/scene/resources/shape_3d.cpp
+++ b/scene/resources/shape_3d.cpp
@@ -58,8 +58,9 @@ void Shape3D::set_margin(real_t p_margin) {
}
Ref<ArrayMesh> Shape3D::get_debug_mesh() {
- if (debug_mesh_cache.is_valid())
+ if (debug_mesh_cache.is_valid()) {
return debug_mesh_cache;
+ }
Vector<Vector3> lines = get_debug_mesh_lines();
diff --git a/scene/resources/sky.cpp b/scene/resources/sky.cpp
index e7ca12162b..54b6cde8bd 100644
--- a/scene/resources/sky.cpp
+++ b/scene/resources/sky.cpp
@@ -58,8 +58,9 @@ Sky::ProcessMode Sky::get_process_mode() const {
void Sky::set_material(const Ref<Material> &p_material) {
sky_material = p_material;
RID material_rid;
- if (sky_material.is_valid())
+ if (sky_material.is_valid()) {
material_rid = sky_material->get_rid();
+ }
RS::get_singleton()->sky_set_material(sky, material_rid);
}
diff --git a/scene/resources/style_box.cpp b/scene/resources/style_box.cpp
index b7c26dd3c3..eb65f10ec9 100644
--- a/scene/resources/style_box.cpp
+++ b/scene/resources/style_box.cpp
@@ -54,10 +54,11 @@ float StyleBox::get_default_margin(Margin p_margin) const {
float StyleBox::get_margin(Margin p_margin) const {
ERR_FAIL_INDEX_V((int)p_margin, 4, 0.0);
- if (margin[p_margin] < 0)
+ if (margin[p_margin] < 0) {
return get_style_margin(p_margin);
- else
+ } else {
return margin[p_margin];
+ }
}
CanvasItem *StyleBox::get_current_item_drawn() const {
@@ -111,8 +112,9 @@ StyleBox::StyleBox() {
}
void StyleBoxTexture::set_texture(Ref<Texture2D> p_texture) {
- if (texture == p_texture)
+ if (texture == p_texture) {
return;
+ }
texture = p_texture;
if (p_texture.is_null()) {
region_rect = Rect2(0, 0, 0, 0);
@@ -129,8 +131,9 @@ Ref<Texture2D> StyleBoxTexture::get_texture() const {
}
void StyleBoxTexture::set_normal_map(Ref<Texture2D> p_normal_map) {
- if (normal_map == p_normal_map)
+ if (normal_map == p_normal_map) {
return;
+ }
normal_map = p_normal_map;
emit_changed();
}
@@ -170,8 +173,9 @@ Rect2 StyleBoxTexture::get_draw_rect(const Rect2 &p_rect) const {
}
void StyleBoxTexture::draw(RID p_canvas_item, const Rect2 &p_rect) const {
- if (texture.is_null())
+ if (texture.is_null()) {
return;
+ }
Rect2 rect = p_rect;
Rect2 src_rect = region_rect;
@@ -184,8 +188,9 @@ void StyleBoxTexture::draw(RID p_canvas_item, const Rect2 &p_rect) const {
rect.size.y += expand_margin[MARGIN_TOP] + expand_margin[MARGIN_BOTTOM];
RID normal_rid;
- if (normal_map.is_valid())
+ if (normal_map.is_valid()) {
normal_rid = normal_map->get_rid();
+ }
RenderingServer::get_singleton()->canvas_item_add_nine_patch(p_canvas_item, rect, src_rect, texture->get_rid(), Vector2(margin[MARGIN_LEFT], margin[MARGIN_TOP]), Vector2(margin[MARGIN_RIGHT], margin[MARGIN_BOTTOM]), RS::NinePatchAxisMode(axis_h), RS::NinePatchAxisMode(axis_v), draw_center, modulate, normal_rid);
}
@@ -200,8 +205,9 @@ bool StyleBoxTexture::is_draw_center_enabled() const {
}
Size2 StyleBoxTexture::get_center_size() const {
- if (texture.is_null())
+ if (texture.is_null()) {
return Size2();
+ }
return region_rect.size - get_minimum_size();
}
@@ -233,8 +239,9 @@ float StyleBoxTexture::get_expand_margin_size(Margin p_expand_margin) const {
}
void StyleBoxTexture::set_region_rect(const Rect2 &p_region_rect) {
- if (region_rect == p_region_rect)
+ if (region_rect == p_region_rect) {
return;
+ }
region_rect = p_region_rect;
emit_changed();
@@ -265,8 +272,9 @@ StyleBoxTexture::AxisStretchMode StyleBoxTexture::get_v_axis_stretch_mode() cons
}
void StyleBoxTexture::set_modulate(const Color &p_modulate) {
- if (modulate == p_modulate)
+ if (modulate == p_modulate) {
return;
+ }
modulate = p_modulate;
emit_changed();
}
diff --git a/scene/resources/surface_tool.cpp b/scene/resources/surface_tool.cpp
index feba8c6c70..1a2dcc84bb 100644
--- a/scene/resources/surface_tool.cpp
+++ b/scene/resources/surface_tool.cpp
@@ -36,35 +36,44 @@
#define EQ_VERTEX_DIST 0.00001
bool SurfaceTool::Vertex::operator==(const Vertex &p_vertex) const {
- if (vertex != p_vertex.vertex)
+ if (vertex != p_vertex.vertex) {
return false;
+ }
- if (uv != p_vertex.uv)
+ if (uv != p_vertex.uv) {
return false;
+ }
- if (uv2 != p_vertex.uv2)
+ if (uv2 != p_vertex.uv2) {
return false;
+ }
- if (normal != p_vertex.normal)
+ if (normal != p_vertex.normal) {
return false;
+ }
- if (binormal != p_vertex.binormal)
+ if (binormal != p_vertex.binormal) {
return false;
+ }
- if (color != p_vertex.color)
+ if (color != p_vertex.color) {
return false;
+ }
- if (bones.size() != p_vertex.bones.size())
+ if (bones.size() != p_vertex.bones.size()) {
return false;
+ }
for (int i = 0; i < bones.size(); i++) {
- if (bones[i] != p_vertex.bones[i])
+ if (bones[i] != p_vertex.bones[i]) {
return false;
+ }
}
for (int i = 0; i < weights.size(); i++) {
- if (weights[i] != p_vertex.weights[i])
+ if (weights[i] != p_vertex.weights[i]) {
return false;
+ }
}
return true;
@@ -266,8 +275,9 @@ Array SurfaceTool::commit_to_arrays() {
a.resize(Mesh::ARRAY_MAX);
for (int i = 0; i < Mesh::ARRAY_MAX; i++) {
- if (!(format & (1 << i)))
+ if (!(format & (1 << i))) {
continue; //not in format
+ }
switch (i) {
case Mesh::ARRAY_VERTEX:
@@ -412,15 +422,17 @@ Array SurfaceTool::commit_to_arrays() {
Ref<ArrayMesh> SurfaceTool::commit(const Ref<ArrayMesh> &p_existing, uint32_t p_flags) {
Ref<ArrayMesh> mesh;
- if (p_existing.is_valid())
+ if (p_existing.is_valid()) {
mesh = p_existing;
- else
+ } else {
mesh.instance();
+ }
int varr_len = vertex_array.size();
- if (varr_len == 0)
+ if (varr_len == 0) {
return mesh;
+ }
int surface = mesh->get_surface_count();
@@ -428,15 +440,17 @@ Ref<ArrayMesh> SurfaceTool::commit(const Ref<ArrayMesh> &p_existing, uint32_t p_
mesh->add_surface_from_arrays(primitive, a, Array(), Dictionary(), p_flags);
- if (material.is_valid())
+ if (material.is_valid()) {
mesh->surface_set_material(surface, material);
+ }
return mesh;
}
void SurfaceTool::index() {
- if (index_array.size())
+ if (index_array.size()) {
return; //already indexed
+ }
HashMap<Vertex, int, VertexHasher> indices;
List<Vertex> new_vertices;
@@ -462,8 +476,9 @@ void SurfaceTool::index() {
}
void SurfaceTool::deindex() {
- if (index_array.size() == 0)
+ if (index_array.size() == 0) {
return; //nothing to deindex
+ }
Vector<Vertex> varr;
varr.resize(vertex_array.size());
int idx = 0;
@@ -498,8 +513,9 @@ Vector<SurfaceTool::Vertex> SurfaceTool::create_vertex_array_from_triangle_array
Vector<float> warr = p_arrays[RS::ARRAY_WEIGHTS];
int vc = varr.size();
- if (vc == 0)
+ if (vc == 0) {
return ret;
+ }
int lformat = 0;
if (varr.size()) {
@@ -529,21 +545,26 @@ Vector<SurfaceTool::Vertex> SurfaceTool::create_vertex_array_from_triangle_array
for (int i = 0; i < vc; i++) {
Vertex v;
- if (lformat & RS::ARRAY_FORMAT_VERTEX)
+ if (lformat & RS::ARRAY_FORMAT_VERTEX) {
v.vertex = varr[i];
- if (lformat & RS::ARRAY_FORMAT_NORMAL)
+ }
+ if (lformat & RS::ARRAY_FORMAT_NORMAL) {
v.normal = narr[i];
+ }
if (lformat & RS::ARRAY_FORMAT_TANGENT) {
Plane p(tarr[i * 4 + 0], tarr[i * 4 + 1], tarr[i * 4 + 2], tarr[i * 4 + 3]);
v.tangent = p.normal;
v.binormal = p.normal.cross(v.tangent).normalized() * p.d;
}
- if (lformat & RS::ARRAY_FORMAT_COLOR)
+ if (lformat & RS::ARRAY_FORMAT_COLOR) {
v.color = carr[i];
- if (lformat & RS::ARRAY_FORMAT_TEX_UV)
+ }
+ if (lformat & RS::ARRAY_FORMAT_TEX_UV) {
v.uv = uvarr[i];
- if (lformat & RS::ARRAY_FORMAT_TEX_UV2)
+ }
+ if (lformat & RS::ARRAY_FORMAT_TEX_UV2) {
v.uv2 = uv2arr[i];
+ }
if (lformat & RS::ARRAY_FORMAT_BONES) {
Vector<int> b;
b.resize(4);
@@ -580,8 +601,9 @@ void SurfaceTool::_create_list_from_arrays(Array arr, List<Vertex> *r_vertex, Li
Vector<float> warr = arr[RS::ARRAY_WEIGHTS];
int vc = varr.size();
- if (vc == 0)
+ if (vc == 0) {
return;
+ }
lformat = 0;
if (varr.size()) {
@@ -611,21 +633,26 @@ void SurfaceTool::_create_list_from_arrays(Array arr, List<Vertex> *r_vertex, Li
for (int i = 0; i < vc; i++) {
Vertex v;
- if (lformat & RS::ARRAY_FORMAT_VERTEX)
+ if (lformat & RS::ARRAY_FORMAT_VERTEX) {
v.vertex = varr[i];
- if (lformat & RS::ARRAY_FORMAT_NORMAL)
+ }
+ if (lformat & RS::ARRAY_FORMAT_NORMAL) {
v.normal = narr[i];
+ }
if (lformat & RS::ARRAY_FORMAT_TANGENT) {
Plane p(tarr[i * 4 + 0], tarr[i * 4 + 1], tarr[i * 4 + 2], tarr[i * 4 + 3]);
v.tangent = p.normal;
v.binormal = p.normal.cross(v.tangent).normalized() * p.d;
}
- if (lformat & RS::ARRAY_FORMAT_COLOR)
+ if (lformat & RS::ARRAY_FORMAT_COLOR) {
v.color = carr[i];
- if (lformat & RS::ARRAY_FORMAT_TEX_UV)
+ }
+ if (lformat & RS::ARRAY_FORMAT_TEX_UV) {
v.uv = uvarr[i];
- if (lformat & RS::ARRAY_FORMAT_TEX_UV2)
+ }
+ if (lformat & RS::ARRAY_FORMAT_TEX_UV2) {
v.uv2 = uv2arr[i];
+ }
if (lformat & RS::ARRAY_FORMAT_BONES) {
Vector<int> b;
b.resize(4);
@@ -869,8 +896,9 @@ void SurfaceTool::generate_normals(bool p_flip) {
int count = 0;
bool smooth = false;
- if (smooth_groups.has(0))
+ if (smooth_groups.has(0)) {
smooth = smooth_groups[0];
+ }
List<Vertex>::Element *B = vertex_array.front();
for (List<Vertex>::Element *E = B; E;) {
@@ -883,10 +911,11 @@ void SurfaceTool::generate_normals(bool p_flip) {
E = v[2]->next();
Vector3 normal;
- if (!p_flip)
+ if (!p_flip) {
normal = Plane(v[0]->get().vertex, v[1]->get().vertex, v[2]->get().vertex).normal;
- else
+ } else {
normal = Plane(v[2]->get().vertex, v[1]->get().vertex, v[0]->get().vertex).normal;
+ }
if (smooth) {
for (int i = 0; i < 3; i++) {
diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp
index b549bea4f4..331cffed5d 100644
--- a/scene/resources/texture.cpp
+++ b/scene/resources/texture.cpp
@@ -91,8 +91,9 @@ Texture2D::Texture2D() {
void ImageTexture::reload_from_file() {
String path = ResourceLoader::path_remap(get_path());
- if (!path.is_resource_file())
+ if (!path.is_resource_file()) {
return;
+ }
Ref<Image> img;
img.instance();
@@ -107,26 +108,28 @@ void ImageTexture::reload_from_file() {
}
bool ImageTexture::_set(const StringName &p_name, const Variant &p_value) {
- if (p_name == "image")
+ if (p_name == "image") {
create_from_image(p_value);
- else if (p_name == "size") {
+ } else if (p_name == "size") {
Size2 s = p_value;
w = s.width;
h = s.height;
RenderingServer::get_singleton()->texture_set_size_override(texture, w, h);
- } else
+ } else {
return false;
+ }
return true;
}
bool ImageTexture::_get(const StringName &p_name, Variant &r_ret) const {
- if (p_name == "image")
+ if (p_name == "image") {
r_ret = get_data();
- else if (p_name == "size")
+ } else if (p_name == "size") {
r_ret = Size2(w, h);
- else
+ } else {
return false;
+ }
return true;
}
@@ -138,8 +141,9 @@ void ImageTexture::_get_property_list(List<PropertyInfo> *p_list) const {
void ImageTexture::_reload_hook(const RID &p_hook) {
String path = get_path();
- if (!path.is_resource_file())
+ if (!path.is_resource_file()) {
return;
+ }
Ref<Image> img;
img.instance();
@@ -230,24 +234,27 @@ bool ImageTexture::has_alpha() const {
}
void ImageTexture::draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat) const {
- if ((w | h) == 0)
+ if ((w | h) == 0) {
return;
+ }
RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID();
RID specular_rid = p_specular_map.is_valid() ? p_specular_map->get_rid() : RID();
RenderingServer::get_singleton()->canvas_item_add_texture_rect(p_canvas_item, Rect2(p_pos, Size2(w, h)), texture, false, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, p_texture_filter, p_texture_repeat);
}
void ImageTexture::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat) const {
- if ((w | h) == 0)
+ if ((w | h) == 0) {
return;
+ }
RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID();
RID specular_rid = p_specular_map.is_valid() ? p_specular_map->get_rid() : RID();
RenderingServer::get_singleton()->canvas_item_add_texture_rect(p_canvas_item, p_rect, texture, p_tile, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, p_texture_filter, p_texture_repeat);
}
void ImageTexture::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat, bool p_clip_uv) const {
- if ((w | h) == 0)
+ if ((w | h) == 0) {
return;
+ }
RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID();
RID specular_rid = p_specular_map.is_valid() ? p_specular_map->get_rid() : RID();
RenderingServer::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, p_rect, texture, p_src_rect, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, p_clip_uv, p_texture_filter, p_texture_repeat);
@@ -288,10 +295,12 @@ bool ImageTexture::is_pixel_opaque(int p_x, int p_y) const {
void ImageTexture::set_size_override(const Size2 &p_size) {
Size2 s = p_size;
- if (s.x != 0)
+ if (s.x != 0) {
w = s.x;
- if (s.y != 0)
+ }
+ if (s.y != 0) {
h = s.y;
+ }
RenderingServer::get_singleton()->texture_set_size_override(texture, w, h);
}
@@ -568,8 +577,9 @@ Error StreamTexture2D::load(const String &p_path) {
int mipmap_limit;
Error err = _load_data(p_path, lw, lh, lwc, lhc, image, request_3d, request_normal, request_roughness, mipmap_limit);
- if (err)
+ if (err) {
return err;
+ }
if (texture.is_valid()) {
RID new_texture = RS::get_singleton()->texture_2d_create(image);
@@ -643,24 +653,27 @@ RID StreamTexture2D::get_rid() const {
}
void StreamTexture2D::draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat) const {
- if ((w | h) == 0)
+ if ((w | h) == 0) {
return;
+ }
RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID();
RID specular_rid = p_specular_map.is_valid() ? p_specular_map->get_rid() : RID();
RenderingServer::get_singleton()->canvas_item_add_texture_rect(p_canvas_item, Rect2(p_pos, Size2(w, h)), texture, false, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, p_texture_filter, p_texture_repeat);
}
void StreamTexture2D::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat) const {
- if ((w | h) == 0)
+ if ((w | h) == 0) {
return;
+ }
RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID();
RID specular_rid = p_specular_map.is_valid() ? p_specular_map->get_rid() : RID();
RenderingServer::get_singleton()->canvas_item_add_texture_rect(p_canvas_item, p_rect, texture, p_tile, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, p_texture_filter, p_texture_repeat);
}
void StreamTexture2D::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat, bool p_clip_uv) const {
- if ((w | h) == 0)
+ if ((w | h) == 0) {
return;
+ }
RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID();
RID specular_rid = p_specular_map.is_valid() ? p_specular_map->get_rid() : RID();
RenderingServer::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, p_rect, texture, p_src_rect, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, p_clip_uv, p_texture_filter, p_texture_repeat);
@@ -714,13 +727,15 @@ bool StreamTexture2D::is_pixel_opaque(int p_x, int p_y) const {
void StreamTexture2D::reload_from_file() {
String path = get_path();
- if (!path.is_resource_file())
+ if (!path.is_resource_file()) {
return;
+ }
path = ResourceLoader::path_remap(path); //remap for translation
path = ResourceLoader::import_remap(path); //remap for import
- if (!path.is_resource_file())
+ if (!path.is_resource_file()) {
return;
+ }
load(path);
}
@@ -751,10 +766,12 @@ RES ResourceFormatLoaderStreamTexture2D::load(const String &p_path, const String
Ref<StreamTexture2D> st;
st.instance();
Error err = st->load(p_path);
- if (r_error)
+ if (r_error) {
*r_error = err;
- if (err != OK)
+ }
+ if (err != OK) {
return RES();
+ }
return st;
}
@@ -768,8 +785,9 @@ bool ResourceFormatLoaderStreamTexture2D::handles_type(const String &p_type) con
}
String ResourceFormatLoaderStreamTexture2D::get_resource_type(const String &p_path) const {
- if (p_path.get_extension().to_lower() == "stex")
+ if (p_path.get_extension().to_lower() == "stex") {
return "StreamTexture2D";
+ }
return "";
}
@@ -777,8 +795,9 @@ String ResourceFormatLoaderStreamTexture2D::get_resource_type(const String &p_pa
int AtlasTexture::get_width() const {
if (region.size.width == 0) {
- if (atlas.is_valid())
+ if (atlas.is_valid()) {
return atlas->get_width();
+ }
return 1;
} else {
return region.size.width + margin.size.width;
@@ -787,8 +806,9 @@ int AtlasTexture::get_width() const {
int AtlasTexture::get_height() const {
if (region.size.height == 0) {
- if (atlas.is_valid())
+ if (atlas.is_valid()) {
return atlas->get_height();
+ }
return 1;
} else {
return region.size.height + margin.size.height;
@@ -796,23 +816,26 @@ int AtlasTexture::get_height() const {
}
RID AtlasTexture::get_rid() const {
- if (atlas.is_valid())
+ if (atlas.is_valid()) {
return atlas->get_rid();
+ }
return RID();
}
bool AtlasTexture::has_alpha() const {
- if (atlas.is_valid())
+ if (atlas.is_valid()) {
return atlas->has_alpha();
+ }
return false;
}
void AtlasTexture::set_atlas(const Ref<Texture2D> &p_atlas) {
ERR_FAIL_COND(p_atlas == this);
- if (atlas == p_atlas)
+ if (atlas == p_atlas) {
return;
+ }
atlas = p_atlas;
emit_changed();
_change_notify("atlas");
@@ -823,8 +846,9 @@ Ref<Texture2D> AtlasTexture::get_atlas() const {
}
void AtlasTexture::set_region(const Rect2 &p_region) {
- if (region == p_region)
+ if (region == p_region) {
return;
+ }
region = p_region;
emit_changed();
_change_notify("region");
@@ -835,8 +859,9 @@ Rect2 AtlasTexture::get_region() const {
}
void AtlasTexture::set_margin(const Rect2 &p_margin) {
- if (margin == p_margin)
+ if (margin == p_margin) {
return;
+ }
margin = p_margin;
emit_changed();
_change_notify("margin");
@@ -876,8 +901,9 @@ void AtlasTexture::_bind_methods() {
}
void AtlasTexture::draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat) const {
- if (!atlas.is_valid())
+ if (!atlas.is_valid()) {
return;
+ }
Rect2 rc = region;
@@ -895,8 +921,9 @@ void AtlasTexture::draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_m
}
void AtlasTexture::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat) const {
- if (!atlas.is_valid())
+ if (!atlas.is_valid()) {
return;
+ }
Rect2 rc = region;
@@ -918,8 +945,9 @@ void AtlasTexture::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile
void AtlasTexture::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat, bool p_clip_uv) const {
//this might not necessarily work well if using a rect, needs to be fixed properly
- if (!atlas.is_valid())
+ if (!atlas.is_valid()) {
return;
+ }
Rect2 dr;
Rect2 src_c;
@@ -931,8 +959,9 @@ void AtlasTexture::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, cons
}
bool AtlasTexture::get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect, Rect2 &r_rect, Rect2 &r_src_rect) const {
- if (!atlas.is_valid())
+ if (!atlas.is_valid()) {
return false;
+ }
Rect2 rc = region;
@@ -944,8 +973,9 @@ bool AtlasTexture::get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect,
src.position += (rc.position - margin.position);
Rect2 src_c = rc.clip(src);
- if (src_c.size == Size2())
+ if (src_c.size == Size2()) {
return false;
+ }
Vector2 ofs = (src_c.position - src.position);
if (scale.x < 0) {
@@ -966,17 +996,20 @@ bool AtlasTexture::get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect,
}
bool AtlasTexture::is_pixel_opaque(int p_x, int p_y) const {
- if (!atlas.is_valid())
+ if (!atlas.is_valid()) {
return true;
+ }
int x = p_x + region.position.x - margin.position.x;
int y = p_y + region.position.y - margin.position.y;
// margin edge may outside of atlas
- if (x < 0 || x >= atlas->get_width())
+ if (x < 0 || x >= atlas->get_width()) {
return false;
- if (y < 0 || y >= atlas->get_height())
+ }
+ if (y < 0 || y >= atlas->get_height()) {
return false;
+ }
return atlas->is_pixel_opaque(x, y);
}
@@ -1132,8 +1165,9 @@ RID LargeTexture::get_rid() const {
bool LargeTexture::has_alpha() const {
for (int i = 0; i < pieces.size(); i++) {
- if (pieces[i].texture->has_alpha())
+ if (pieces[i].texture->has_alpha()) {
return true;
+ }
}
return false;
@@ -1240,8 +1274,9 @@ void LargeTexture::draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_m
void LargeTexture::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat) const {
//tiling not supported for this
- if (size.x == 0 || size.y == 0)
+ if (size.x == 0 || size.y == 0) {
return;
+ }
Size2 scale = p_rect.size / size;
@@ -1253,16 +1288,18 @@ void LargeTexture::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile
void LargeTexture::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat, bool p_clip_uv) const {
//tiling not supported for this
- if (p_src_rect.size.x == 0 || p_src_rect.size.y == 0)
+ if (p_src_rect.size.x == 0 || p_src_rect.size.y == 0) {
return;
+ }
Size2 scale = p_rect.size / p_src_rect.size;
for (int i = 0; i < pieces.size(); i++) {
// TODO
Rect2 rect(pieces[i].offset, pieces[i].texture->get_size());
- if (!p_src_rect.intersects(rect))
+ if (!p_src_rect.intersects(rect)) {
continue;
+ }
Rect2 local = p_src_rect.clip(rect);
Rect2 target = local;
target.size *= scale;
@@ -1275,8 +1312,9 @@ void LargeTexture::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, cons
bool LargeTexture::is_pixel_opaque(int p_x, int p_y) const {
for (int i = 0; i < pieces.size(); i++) {
// TODO
- if (!pieces[i].texture.is_valid())
+ if (!pieces[i].texture.is_valid()) {
continue;
+ }
Rect2 rect(pieces[i].offset, pieces[i].texture->get_size());
if (rect.has_point(Point2(p_x, p_y))) {
@@ -1429,8 +1467,9 @@ void GradientTexture::_bind_methods() {
}
void GradientTexture::set_gradient(Ref<Gradient> p_gradient) {
- if (p_gradient == gradient)
+ if (p_gradient == gradient) {
return;
+ }
if (gradient.is_valid()) {
gradient->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &GradientTexture::_update));
}
@@ -1447,8 +1486,9 @@ Ref<Gradient> GradientTexture::get_gradient() const {
}
void GradientTexture::_queue_update() {
- if (update_pending)
+ if (update_pending) {
return;
+ }
update_pending = true;
call_deferred("_update");
@@ -1457,8 +1497,9 @@ void GradientTexture::_queue_update() {
void GradientTexture::_update() {
update_pending = false;
- if (gradient.is_null())
+ if (gradient.is_null()) {
return;
+ }
Vector<uint8_t> data;
data.resize(width * 4);
@@ -1536,14 +1577,16 @@ Ref<Texture2D> ProxyTexture::get_base() const {
}
int ProxyTexture::get_width() const {
- if (base.is_valid())
+ if (base.is_valid()) {
return base->get_width();
+ }
return 1;
}
int ProxyTexture::get_height() const {
- if (base.is_valid())
+ if (base.is_valid()) {
return base->get_height();
+ }
return 1;
}
@@ -1556,8 +1599,9 @@ RID ProxyTexture::get_rid() const {
}
bool ProxyTexture::has_alpha() const {
- if (base.is_valid())
+ if (base.is_valid()) {
return base->has_alpha();
+ }
return false;
}
@@ -2061,8 +2105,9 @@ Error StreamTextureLayered::load(const String &p_path) {
int mipmap_limit;
Error err = _load_data(p_path, images, mipmap_limit);
- if (err)
+ if (err) {
return err;
+ }
if (texture.is_valid()) {
RID new_texture = RS::get_singleton()->texture_2d_layered_create(images, RS::TextureLayeredType(layered_type));
@@ -2130,13 +2175,15 @@ Ref<Image> StreamTextureLayered::get_layer_data(int p_layer) const {
void StreamTextureLayered::reload_from_file() {
String path = get_path();
- if (!path.is_resource_file())
+ if (!path.is_resource_file()) {
return;
+ }
path = ResourceLoader::path_remap(path); //remap for translation
path = ResourceLoader::import_remap(path); //remap for import
- if (!path.is_resource_file())
+ if (!path.is_resource_file()) {
return;
+ }
load(path);
}
@@ -2189,10 +2236,12 @@ RES ResourceFormatLoaderStreamTextureLayered::load(const String &p_path, const S
return RES();
}
Error err = st->load(p_path);
- if (r_error)
+ if (r_error) {
*r_error = err;
- if (err != OK)
+ }
+ if (err != OK) {
return RES();
+ }
return st;
}
@@ -2208,12 +2257,15 @@ bool ResourceFormatLoaderStreamTextureLayered::handles_type(const String &p_type
}
String ResourceFormatLoaderStreamTextureLayered::get_resource_type(const String &p_path) const {
- if (p_path.get_extension().to_lower() == "stexarray")
+ if (p_path.get_extension().to_lower() == "stexarray") {
return "StreamTexture2DArray";
- if (p_path.get_extension().to_lower() == "scube")
+ }
+ if (p_path.get_extension().to_lower() == "scube") {
return "StreamCubemap";
- if (p_path.get_extension().to_lower() == "scubearray")
+ }
+ if (p_path.get_extension().to_lower() == "scubearray") {
return "StreamCubemapArray";
+ }
return "";
}
diff --git a/scene/resources/theme.cpp b/scene/resources/theme.cpp
index 7a2abffed0..6a85d357ff 100644
--- a/scene/resources/theme.cpp
+++ b/scene/resources/theme.cpp
@@ -159,8 +159,9 @@ bool Theme::_set(const StringName &p_name, const Variant &p_value) {
set_color(name, node_type, p_value);
} else if (type == "constants") {
set_constant(name, node_type, p_value);
- } else
+ } else {
return false;
+ }
return true;
}
@@ -177,26 +178,30 @@ bool Theme::_get(const StringName &p_name, Variant &r_ret) const {
String name = sname.get_slicec('/', 2);
if (type == "icons") {
- if (!has_icon(name, node_type))
+ if (!has_icon(name, node_type)) {
r_ret = Ref<Texture2D>();
- else
+ } else {
r_ret = get_icon(name, node_type);
+ }
} else if (type == "styles") {
- if (!has_stylebox(name, node_type))
+ if (!has_stylebox(name, node_type)) {
r_ret = Ref<StyleBox>();
- else
+ } else {
r_ret = get_stylebox(name, node_type);
+ }
} else if (type == "fonts") {
- if (!has_font(name, node_type))
+ if (!has_font(name, node_type)) {
r_ret = Ref<Font>();
- else
+ } else {
r_ret = get_font(name, node_type);
+ }
} else if (type == "colors") {
r_ret = get_color(name, node_type);
} else if (type == "constants") {
r_ret = get_constant(name, node_type);
- } else
+ } else {
return false;
+ }
return true;
}
@@ -264,8 +269,9 @@ void Theme::_get_property_list(List<PropertyInfo> *p_list) const {
}
void Theme::set_default_theme_font(const Ref<Font> &p_default_font) {
- if (default_theme_font == p_default_font)
+ if (default_theme_font == p_default_font) {
return;
+ }
if (default_theme_font.is_valid()) {
default_theme_font->disconnect("changed", callable_mp(this, &Theme::_emit_theme_changed));
@@ -369,8 +375,9 @@ void Theme::clear_icon(const StringName &p_name, const StringName &p_type) {
void Theme::get_icon_list(StringName p_type, List<StringName> *p_list) const {
ERR_FAIL_NULL(p_list);
- if (!icon_map.has(p_type))
+ if (!icon_map.has(p_type)) {
return;
+ }
const StringName *key = nullptr;
@@ -414,8 +421,9 @@ void Theme::clear_shader(const StringName &p_name, const StringName &p_type) {
void Theme::get_shader_list(const StringName &p_type, List<StringName> *p_list) const {
ERR_FAIL_NULL(p_list);
- if (!shader_map.has(p_type))
+ if (!shader_map.has(p_type)) {
return;
+ }
const StringName *key = nullptr;
@@ -439,8 +447,9 @@ void Theme::set_stylebox(const StringName &p_name, const StringName &p_type, con
style_map[p_type][p_name]->connect("changed", callable_mp(this, &Theme::_emit_theme_changed), varray(), CONNECT_REFERENCE_COUNTED);
}
- if (new_value)
+ if (new_value) {
_change_notify();
+ }
emit_changed();
}
@@ -473,8 +482,9 @@ void Theme::clear_stylebox(const StringName &p_name, const StringName &p_type) {
void Theme::get_stylebox_list(StringName p_type, List<StringName> *p_list) const {
ERR_FAIL_NULL(p_list);
- if (!style_map.has(p_type))
+ if (!style_map.has(p_type)) {
return;
+ }
const StringName *key = nullptr;
@@ -514,12 +524,13 @@ void Theme::set_font(const StringName &p_name, const StringName &p_type, const R
}
Ref<Font> Theme::get_font(const StringName &p_name, const StringName &p_type) const {
- if (font_map.has(p_type) && font_map[p_type].has(p_name) && font_map[p_type][p_name].is_valid())
+ if (font_map.has(p_type) && font_map[p_type].has(p_name) && font_map[p_type][p_name].is_valid()) {
return font_map[p_type][p_name];
- else if (default_theme_font.is_valid())
+ } else if (default_theme_font.is_valid()) {
return default_theme_font;
- else
+ } else {
return default_font;
+ }
}
bool Theme::has_font(const StringName &p_name, const StringName &p_type) const {
@@ -542,8 +553,9 @@ void Theme::clear_font(const StringName &p_name, const StringName &p_type) {
void Theme::get_font_list(StringName p_type, List<StringName> *p_list) const {
ERR_FAIL_NULL(p_list);
- if (!font_map.has(p_type))
+ if (!font_map.has(p_type)) {
return;
+ }
const StringName *key = nullptr;
@@ -564,10 +576,11 @@ void Theme::set_color(const StringName &p_name, const StringName &p_type, const
}
Color Theme::get_color(const StringName &p_name, const StringName &p_type) const {
- if (color_map.has(p_type) && color_map[p_type].has(p_name))
+ if (color_map.has(p_type) && color_map[p_type].has(p_name)) {
return color_map[p_type][p_name];
- else
+ } else {
return Color();
+ }
}
bool Theme::has_color(const StringName &p_name, const StringName &p_type) const {
@@ -586,8 +599,9 @@ void Theme::clear_color(const StringName &p_name, const StringName &p_type) {
void Theme::get_color_list(StringName p_type, List<StringName> *p_list) const {
ERR_FAIL_NULL(p_list);
- if (!color_map.has(p_type))
+ if (!color_map.has(p_type)) {
return;
+ }
const StringName *key = nullptr;
@@ -607,9 +621,9 @@ void Theme::set_constant(const StringName &p_name, const StringName &p_type, int
}
int Theme::get_constant(const StringName &p_name, const StringName &p_type) const {
- if (constant_map.has(p_type) && constant_map[p_type].has(p_name))
+ if (constant_map.has(p_type) && constant_map[p_type].has(p_name)) {
return constant_map[p_type][p_name];
- else {
+ } else {
return 0;
}
}
@@ -630,8 +644,9 @@ void Theme::clear_constant(const StringName &p_name, const StringName &p_type) {
void Theme::get_constant_list(StringName p_type, List<StringName> *p_list) const {
ERR_FAIL_NULL(p_list);
- if (!constant_map.has(p_type))
+ if (!constant_map.has(p_type)) {
return;
+ }
const StringName *key = nullptr;
diff --git a/scene/resources/tile_set.cpp b/scene/resources/tile_set.cpp
index 38e50e35f1..c17b6f8817 100644
--- a/scene/resources/tile_set.cpp
+++ b/scene/resources/tile_set.cpp
@@ -35,47 +35,50 @@
bool TileSet::_set(const StringName &p_name, const Variant &p_value) {
String n = p_name;
int slash = n.find("/");
- if (slash == -1)
+ if (slash == -1) {
return false;
+ }
int id = String::to_int(n.c_str(), slash);
- if (!tile_map.has(id))
+ if (!tile_map.has(id)) {
create_tile(id);
+ }
String what = n.substr(slash + 1, n.length());
- if (what == "name")
+ if (what == "name") {
tile_set_name(id, p_value);
- else if (what == "texture")
+ } else if (what == "texture") {
tile_set_texture(id, p_value);
- else if (what == "normal_map")
+ } else if (what == "normal_map") {
tile_set_normal_map(id, p_value);
- else if (what == "tex_offset")
+ } else if (what == "tex_offset") {
tile_set_texture_offset(id, p_value);
- else if (what == "material")
+ } else if (what == "material") {
tile_set_material(id, p_value);
- else if (what == "modulate")
+ } else if (what == "modulate") {
tile_set_modulate(id, p_value);
- else if (what == "region")
+ } else if (what == "region") {
tile_set_region(id, p_value);
- else if (what == "tile_mode")
+ } else if (what == "tile_mode") {
tile_set_tile_mode(id, (TileMode)((int)p_value));
- else if (what == "is_autotile") {
+ } else if (what == "is_autotile") {
// backward compatibility for Godot 3.0.x
// autotile used to be a bool, it's now an enum
bool is_autotile = p_value;
- if (is_autotile)
+ if (is_autotile) {
tile_set_tile_mode(id, AUTO_TILE);
+ }
} else if (what.left(9) == "autotile/") {
what = what.right(9);
- if (what == "bitmask_mode")
+ if (what == "bitmask_mode") {
autotile_set_bitmask_mode(id, (BitmaskMode)((int)p_value));
- else if (what == "icon_coordinate")
+ } else if (what == "icon_coordinate") {
autotile_set_icon_coordinate(id, p_value);
- else if (what == "tile_size")
+ } else if (what == "tile_size") {
autotile_set_size(id, p_value);
- else if (what == "spacing")
+ } else if (what == "spacing") {
autotile_set_spacing(id, p_value);
- else if (what == "bitmask_flags") {
+ } else if (what == "bitmask_flags") {
tile_map[id].autotile_data.flags.clear();
if (p_value.is_array()) {
Array p = p_value;
@@ -146,7 +149,7 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) {
p.pop_front();
}
}
- } else if (what == "shape")
+ } else if (what == "shape") {
if (tile_get_shape_count(id) > 0) {
for (int i = 0; i < tile_get_shape_count(id); i++) {
tile_set_shape(id, i, p_value);
@@ -154,7 +157,7 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) {
} else {
tile_set_shape(id, 0, p_value);
}
- else if (what == "shape_offset")
+ } else if (what == "shape_offset") {
if (tile_get_shape_count(id) > 0) {
for (int i = 0; i < tile_get_shape_count(id); i++) {
tile_set_shape_offset(id, i, p_value);
@@ -162,7 +165,7 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) {
} else {
tile_set_shape_offset(id, 0, p_value);
}
- else if (what == "shape_transform")
+ } else if (what == "shape_transform") {
if (tile_get_shape_count(id) > 0) {
for (int i = 0; i < tile_get_shape_count(id); i++) {
tile_set_shape_transform(id, i, p_value);
@@ -170,7 +173,7 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) {
} else {
tile_set_shape_transform(id, 0, p_value);
}
- else if (what == "shape_one_way")
+ } else if (what == "shape_one_way") {
if (tile_get_shape_count(id) > 0) {
for (int i = 0; i < tile_get_shape_count(id); i++) {
tile_set_shape_one_way(id, i, p_value);
@@ -178,7 +181,7 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) {
} else {
tile_set_shape_one_way(id, 0, p_value);
}
- else if (what == "shape_one_way_margin")
+ } else if (what == "shape_one_way_margin") {
if (tile_get_shape_count(id) > 0) {
for (int i = 0; i < tile_get_shape_count(id); i++) {
tile_set_shape_one_way_margin(id, i, p_value);
@@ -186,20 +189,21 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) {
} else {
tile_set_shape_one_way_margin(id, 0, p_value);
}
- else if (what == "shapes")
+ } else if (what == "shapes") {
_tile_set_shapes(id, p_value);
- else if (what == "occluder")
+ } else if (what == "occluder") {
tile_set_light_occluder(id, p_value);
- else if (what == "occluder_offset")
+ } else if (what == "occluder_offset") {
tile_set_occluder_offset(id, p_value);
- else if (what == "navigation")
+ } else if (what == "navigation") {
tile_set_navigation_polygon(id, p_value);
- else if (what == "navigation_offset")
+ } else if (what == "navigation_offset") {
tile_set_navigation_polygon_offset(id, p_value);
- else if (what == "z_index")
+ } else if (what == "z_index") {
tile_set_z_index(id, p_value);
- else
+ } else {
return false;
+ }
return true;
}
@@ -207,41 +211,42 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) {
bool TileSet::_get(const StringName &p_name, Variant &r_ret) const {
String n = p_name;
int slash = n.find("/");
- if (slash == -1)
+ if (slash == -1) {
return false;
+ }
int id = String::to_int(n.c_str(), slash);
ERR_FAIL_COND_V(!tile_map.has(id), false);
String what = n.substr(slash + 1, n.length());
- if (what == "name")
+ if (what == "name") {
r_ret = tile_get_name(id);
- else if (what == "texture")
+ } else if (what == "texture") {
r_ret = tile_get_texture(id);
- else if (what == "normal_map")
+ } else if (what == "normal_map") {
r_ret = tile_get_normal_map(id);
- else if (what == "tex_offset")
+ } else if (what == "tex_offset") {
r_ret = tile_get_texture_offset(id);
- else if (what == "material")
+ } else if (what == "material") {
r_ret = tile_get_material(id);
- else if (what == "modulate")
+ } else if (what == "modulate") {
r_ret = tile_get_modulate(id);
- else if (what == "region")
+ } else if (what == "region") {
r_ret = tile_get_region(id);
- else if (what == "tile_mode")
+ } else if (what == "tile_mode") {
r_ret = tile_get_tile_mode(id);
- else if (what.left(9) == "autotile/") {
+ } else if (what.left(9) == "autotile/") {
what = what.right(9);
- if (what == "bitmask_mode")
+ if (what == "bitmask_mode") {
r_ret = autotile_get_bitmask_mode(id);
- else if (what == "icon_coordinate")
+ } else if (what == "icon_coordinate") {
r_ret = autotile_get_icon_coordinate(id);
- else if (what == "tile_size")
+ } else if (what == "tile_size") {
r_ret = autotile_get_size(id);
- else if (what == "spacing")
+ } else if (what == "spacing") {
r_ret = autotile_get_spacing(id);
- else if (what == "bitmask_flags") {
+ } else if (what == "bitmask_flags") {
Array p;
for (Map<Vector2, uint32_t>::Element *E = tile_map[id].autotile_data.flags.front(); E; E = E->next()) {
p.push_back(E->key());
@@ -289,30 +294,31 @@ bool TileSet::_get(const StringName &p_name, Variant &r_ret) const {
}
r_ret = p;
}
- } else if (what == "shape")
+ } else if (what == "shape") {
r_ret = tile_get_shape(id, 0);
- else if (what == "shape_offset")
+ } else if (what == "shape_offset") {
r_ret = tile_get_shape_offset(id, 0);
- else if (what == "shape_transform")
+ } else if (what == "shape_transform") {
r_ret = tile_get_shape_transform(id, 0);
- else if (what == "shape_one_way")
+ } else if (what == "shape_one_way") {
r_ret = tile_get_shape_one_way(id, 0);
- else if (what == "shape_one_way_margin")
+ } else if (what == "shape_one_way_margin") {
r_ret = tile_get_shape_one_way_margin(id, 0);
- else if (what == "shapes")
+ } else if (what == "shapes") {
r_ret = _tile_get_shapes(id);
- else if (what == "occluder")
+ } else if (what == "occluder") {
r_ret = tile_get_light_occluder(id);
- else if (what == "occluder_offset")
+ } else if (what == "occluder_offset") {
r_ret = tile_get_occluder_offset(id);
- else if (what == "navigation")
+ } else if (what == "navigation") {
r_ret = tile_get_navigation_polygon(id);
- else if (what == "navigation_offset")
+ } else if (what == "navigation_offset") {
r_ret = tile_get_navigation_polygon_offset(id);
- else if (what == "z_index")
+ } else if (what == "z_index") {
r_ret = tile_get_z_index(id);
- else
+ } else {
return false;
+ }
return true;
}
@@ -547,8 +553,9 @@ const Map<Vector2, int> &TileSet::autotile_get_z_index_map(int p_id) const {
void TileSet::autotile_set_bitmask(int p_id, Vector2 p_coord, uint32_t p_flag) {
ERR_FAIL_COND(!tile_map.has(p_id));
if (p_flag == 0) {
- if (tile_map[p_id].autotile_data.flags.has(p_coord))
+ if (tile_map[p_id].autotile_data.flags.has(p_coord)) {
tile_map[p_id].autotile_data.flags.erase(p_coord);
+ }
} else {
tile_map[p_id].autotile_data.flags[p_coord] = p_flag;
}
@@ -577,8 +584,9 @@ const Map<Vector2, uint32_t> &TileSet::autotile_get_bitmask_map(int p_id) {
}
}
return dummy_atlas;
- } else
+ } else {
return tile_map[p_id].autotile_data.flags;
+ }
}
Vector2 TileSet::autotile_get_subtile_for_bitmask(int p_id, uint16_t p_bitmask, const Node *p_tilemap_node, const Vector2 &p_tile_location) {
@@ -709,8 +717,9 @@ void TileSet::tile_set_shape(int p_id, int p_shape_id, const Ref<Shape2D> &p_sha
ERR_FAIL_COND(!tile_map.has(p_id));
ERR_FAIL_COND(p_shape_id < 0);
- if (p_shape_id >= tile_map[p_id].shapes_data.size())
+ if (p_shape_id >= tile_map[p_id].shapes_data.size()) {
tile_map[p_id].shapes_data.resize(p_shape_id + 1);
+ }
tile_map[p_id].shapes_data.write[p_shape_id].shape = p_shape;
_decompose_convex_shape(p_shape);
emit_changed();
@@ -720,8 +729,9 @@ Ref<Shape2D> TileSet::tile_get_shape(int p_id, int p_shape_id) const {
ERR_FAIL_COND_V(!tile_map.has(p_id), Ref<Shape2D>());
ERR_FAIL_COND_V(p_shape_id < 0, Ref<Shape2D>());
- if (p_shape_id < tile_map[p_id].shapes_data.size())
+ if (p_shape_id < tile_map[p_id].shapes_data.size()) {
return tile_map[p_id].shapes_data[p_shape_id].shape;
+ }
return Ref<Shape2D>();
}
@@ -730,8 +740,9 @@ void TileSet::tile_set_shape_transform(int p_id, int p_shape_id, const Transform
ERR_FAIL_COND(!tile_map.has(p_id));
ERR_FAIL_COND(p_shape_id < 0);
- if (p_shape_id >= tile_map[p_id].shapes_data.size())
+ if (p_shape_id >= tile_map[p_id].shapes_data.size()) {
tile_map[p_id].shapes_data.resize(p_shape_id + 1);
+ }
tile_map[p_id].shapes_data.write[p_shape_id].shape_transform = p_offset;
emit_changed();
}
@@ -740,8 +751,9 @@ Transform2D TileSet::tile_get_shape_transform(int p_id, int p_shape_id) const {
ERR_FAIL_COND_V(!tile_map.has(p_id), Transform2D());
ERR_FAIL_COND_V(p_shape_id < 0, Transform2D());
- if (p_shape_id < tile_map[p_id].shapes_data.size())
+ if (p_shape_id < tile_map[p_id].shapes_data.size()) {
return tile_map[p_id].shapes_data[p_shape_id].shape_transform;
+ }
return Transform2D();
}
@@ -760,8 +772,9 @@ void TileSet::tile_set_shape_one_way(int p_id, int p_shape_id, const bool p_one_
ERR_FAIL_COND(!tile_map.has(p_id));
ERR_FAIL_COND(p_shape_id < 0);
- if (p_shape_id >= tile_map[p_id].shapes_data.size())
+ if (p_shape_id >= tile_map[p_id].shapes_data.size()) {
tile_map[p_id].shapes_data.resize(p_shape_id + 1);
+ }
tile_map[p_id].shapes_data.write[p_shape_id].one_way_collision = p_one_way;
emit_changed();
}
@@ -770,8 +783,9 @@ bool TileSet::tile_get_shape_one_way(int p_id, int p_shape_id) const {
ERR_FAIL_COND_V(!tile_map.has(p_id), false);
ERR_FAIL_COND_V(p_shape_id < 0, false);
- if (p_shape_id < tile_map[p_id].shapes_data.size())
+ if (p_shape_id < tile_map[p_id].shapes_data.size()) {
return tile_map[p_id].shapes_data[p_shape_id].one_way_collision;
+ }
return false;
}
@@ -780,8 +794,9 @@ void TileSet::tile_set_shape_one_way_margin(int p_id, int p_shape_id, float p_ma
ERR_FAIL_COND(!tile_map.has(p_id));
ERR_FAIL_COND(p_shape_id < 0);
- if (p_shape_id >= tile_map[p_id].shapes_data.size())
+ if (p_shape_id >= tile_map[p_id].shapes_data.size()) {
tile_map[p_id].shapes_data.resize(p_shape_id + 1);
+ }
tile_map[p_id].shapes_data.write[p_shape_id].one_way_collision_margin = p_margin;
emit_changed();
}
@@ -790,8 +805,9 @@ float TileSet::tile_get_shape_one_way_margin(int p_id, int p_shape_id) const {
ERR_FAIL_COND_V(!tile_map.has(p_id), 0);
ERR_FAIL_COND_V(p_shape_id < 0, 0);
- if (p_shape_id < tile_map[p_id].shapes_data.size())
+ if (p_shape_id < tile_map[p_id].shapes_data.size()) {
return tile_map[p_id].shapes_data[p_shape_id].one_way_collision_margin;
+ }
return 0;
}
@@ -926,8 +942,9 @@ void TileSet::_tile_set_shapes(int p_id, const Array &p_shapes) {
if (p_shapes[i].get_type() == Variant::OBJECT) {
Ref<Shape2D> shape = p_shapes[i];
- if (shape.is_null())
+ if (shape.is_null()) {
continue;
+ }
s.shape = shape;
s.shape_transform = default_transform;
@@ -939,30 +956,35 @@ void TileSet::_tile_set_shapes(int p_id, const Array &p_shapes) {
if (d.has("shape") && d["shape"].get_type() == Variant::OBJECT) {
s.shape = d["shape"];
_decompose_convex_shape(s.shape);
- } else
+ } else {
continue;
+ }
- if (d.has("shape_transform") && d["shape_transform"].get_type() == Variant::TRANSFORM2D)
+ if (d.has("shape_transform") && d["shape_transform"].get_type() == Variant::TRANSFORM2D) {
s.shape_transform = d["shape_transform"];
- else if (d.has("shape_offset") && d["shape_offset"].get_type() == Variant::VECTOR2)
+ } else if (d.has("shape_offset") && d["shape_offset"].get_type() == Variant::VECTOR2) {
s.shape_transform = Transform2D(0, (Vector2)d["shape_offset"]);
- else
+ } else {
s.shape_transform = default_transform;
+ }
- if (d.has("one_way") && d["one_way"].get_type() == Variant::BOOL)
+ if (d.has("one_way") && d["one_way"].get_type() == Variant::BOOL) {
s.one_way_collision = d["one_way"];
- else
+ } else {
s.one_way_collision = default_one_way;
+ }
- if (d.has("one_way_margin") && d["one_way_margin"].is_num())
+ if (d.has("one_way_margin") && d["one_way_margin"].is_num()) {
s.one_way_collision_margin = d["one_way_margin"];
- else
+ } else {
s.one_way_collision_margin = 1.0;
+ }
- if (d.has("autotile_coord") && d["autotile_coord"].get_type() == Variant::VECTOR2)
+ if (d.has("autotile_coord") && d["autotile_coord"].get_type() == Variant::VECTOR2) {
s.autotile_coord = d["autotile_coord"];
- else
+ } else {
s.autotile_coord = default_autotile_coord;
+ }
} else {
ERR_CONTINUE_MSG(true, "Expected an array of objects or dictionaries for tile_set_shapes.");
@@ -1004,11 +1026,13 @@ Array TileSet::_get_tiles_ids() const {
}
void TileSet::_decompose_convex_shape(Ref<Shape2D> p_shape) {
- if (Engine::get_singleton()->is_editor_hint())
+ if (Engine::get_singleton()->is_editor_hint()) {
return;
+ }
Ref<ConvexPolygonShape2D> convex = p_shape;
- if (!convex.is_valid())
+ if (!convex.is_valid()) {
return;
+ }
Vector<Vector<Vector2>> decomp = Geometry::decompose_polygon_in_convex(convex->get_points());
if (decomp.size() > 1) {
Array sub_shapes;
@@ -1055,16 +1079,18 @@ void TileSet::remove_tile(int p_id) {
}
int TileSet::get_last_unused_tile_id() const {
- if (tile_map.size())
+ if (tile_map.size()) {
return tile_map.back()->key() + 1;
- else
+ } else {
return 0;
+ }
}
int TileSet::find_tile_by_name(const String &p_name) const {
for (Map<int, TileData>::Element *E = tile_map.front(); E; E = E->next()) {
- if (p_name == E->get().name)
+ if (p_name == E->get().name) {
return E->key();
+ }
}
return -1;
}
diff --git a/scene/resources/visual_shader.cpp b/scene/resources/visual_shader.cpp
index 5faa256abd..77d4dee21e 100644
--- a/scene/resources/visual_shader.cpp
+++ b/scene/resources/visual_shader.cpp
@@ -400,8 +400,9 @@ int VisualShader::get_valid_node_id(Type p_type) const {
int VisualShader::find_node_id(Type p_type, const Ref<VisualShaderNode> &p_node) const {
for (const Map<int, Node>::Element *E = graph[p_type].nodes.front(); E; E = E->next()) {
- if (E->get().node == p_node)
+ if (E->get().node == p_node) {
return E->key();
+ }
}
return NODE_ID_INVALID;
@@ -471,20 +472,25 @@ bool VisualShader::can_connect_nodes(Type p_type, int p_from_node, int p_from_po
ERR_FAIL_INDEX_V(p_type, TYPE_MAX, false);
const Graph *g = &graph[p_type];
- if (!g->nodes.has(p_from_node))
+ if (!g->nodes.has(p_from_node)) {
return false;
+ }
- if (p_from_node == p_to_node)
+ if (p_from_node == p_to_node) {
return false;
+ }
- if (p_from_port < 0 || p_from_port >= g->nodes[p_from_node].node->get_output_port_count())
+ if (p_from_port < 0 || p_from_port >= g->nodes[p_from_node].node->get_output_port_count()) {
return false;
+ }
- if (!g->nodes.has(p_to_node))
+ if (!g->nodes.has(p_to_node)) {
return false;
+ }
- if (p_to_port < 0 || p_to_port >= g->nodes[p_to_node].node->get_input_port_count())
+ if (p_to_port < 0 || p_to_port >= g->nodes[p_to_node].node->get_input_port_count()) {
return false;
+ }
VisualShaderNode::PortType from_port_type = g->nodes[p_from_node].node->get_output_port_type(p_from_port);
VisualShaderNode::PortType to_port_type = g->nodes[p_to_node].node->get_input_port_type(p_to_port);
@@ -499,8 +505,9 @@ bool VisualShader::can_connect_nodes(Type p_type, int p_from_node, int p_from_po
}
}
- if (is_nodes_connected_relatively(g, p_from_node, p_to_node))
+ if (is_nodes_connected_relatively(g, p_from_node, p_to_node)) {
return false;
+ }
return true;
}
@@ -1090,8 +1097,9 @@ Error VisualShader::_write_node(Type type, StringBuilder &global_code, StringBui
}
Error err = _write_node(type, global_code, global_code_per_node, global_code_per_func, code, def_tex_params, input_connections, output_connections, from_node, processed, for_preview, r_classes);
- if (err)
+ if (err) {
return err;
+ }
}
}
@@ -1280,8 +1288,9 @@ Error VisualShader::_write_node(Type type, StringBuilder &global_code, StringBui
}
void VisualShader::_update_shader() const {
- if (!dirty)
+ if (!dirty) {
return;
+ }
dirty = false;
@@ -2207,8 +2216,9 @@ Vector2 VisualShaderNodeGroupBase::get_size() const {
}
void VisualShaderNodeGroupBase::set_inputs(const String &p_inputs) {
- if (inputs == p_inputs)
+ if (inputs == p_inputs) {
return;
+ }
clear_input_ports();
@@ -2238,8 +2248,9 @@ String VisualShaderNodeGroupBase::get_inputs() const {
}
void VisualShaderNodeGroupBase::set_outputs(const String &p_outputs) {
- if (outputs == p_outputs)
+ if (outputs == p_outputs) {
return;
+ }
clear_output_ports();
@@ -2433,8 +2444,9 @@ void VisualShaderNodeGroupBase::set_input_port_type(int p_id, int p_type) {
ERR_FAIL_COND(!has_input_port(p_id));
ERR_FAIL_COND(p_type < 0 || p_type >= PORT_TYPE_MAX);
- if (input_ports[p_id].type == p_type)
+ if (input_ports[p_id].type == p_type) {
return;
+ }
Vector<String> inputs_strings = inputs.split(";", false);
int count = 0;
@@ -2467,8 +2479,9 @@ void VisualShaderNodeGroupBase::set_input_port_name(int p_id, const String &p_na
ERR_FAIL_COND(!has_input_port(p_id));
ERR_FAIL_COND(!is_valid_port_name(p_name));
- if (input_ports[p_id].name == p_name)
+ if (input_ports[p_id].name == p_name) {
return;
+ }
Vector<String> inputs_strings = inputs.split(";", false);
int count = 0;
@@ -2501,8 +2514,9 @@ void VisualShaderNodeGroupBase::set_output_port_type(int p_id, int p_type) {
ERR_FAIL_COND(!has_output_port(p_id));
ERR_FAIL_COND(p_type < 0 || p_type >= PORT_TYPE_MAX);
- if (output_ports[p_id].type == p_type)
+ if (output_ports[p_id].type == p_type) {
return;
+ }
Vector<String> output_strings = outputs.split(";", false);
int count = 0;
@@ -2535,8 +2549,9 @@ void VisualShaderNodeGroupBase::set_output_port_name(int p_id, const String &p_n
ERR_FAIL_COND(!has_output_port(p_id));
ERR_FAIL_COND(!is_valid_port_name(p_name));
- if (output_ports[p_id].name == p_name)
+ if (output_ports[p_id].name == p_name) {
return;
+ }
Vector<String> output_strings = outputs.split(";", false);
int count = 0;
diff --git a/scene/resources/visual_shader_nodes.cpp b/scene/resources/visual_shader_nodes.cpp
index b89f069211..87720cf110 100644
--- a/scene/resources/visual_shader_nodes.cpp
+++ b/scene/resources/visual_shader_nodes.cpp
@@ -441,14 +441,16 @@ int VisualShaderNodeTexture::get_output_port_count() const {
}
VisualShaderNodeTexture::PortType VisualShaderNodeTexture::get_output_port_type(int p_port) const {
- if (p_port == 0 && source == SOURCE_DEPTH)
+ if (p_port == 0 && source == SOURCE_DEPTH) {
return PORT_TYPE_SCALAR;
+ }
return p_port == 0 ? PORT_TYPE_VECTOR : PORT_TYPE_SCALAR;
}
String VisualShaderNodeTexture::get_output_port_name(int p_port) const {
- if (p_port == 0 && source == SOURCE_DEPTH)
+ if (p_port == 0 && source == SOURCE_DEPTH) {
return "depth";
+ }
return p_port == 0 ? "rgb" : "alpha";
}
@@ -2429,12 +2431,13 @@ VisualShaderNodeScalarClamp::PortType VisualShaderNodeScalarClamp::get_input_por
}
String VisualShaderNodeScalarClamp::get_input_port_name(int p_port) const {
- if (p_port == 0)
+ if (p_port == 0) {
return "";
- else if (p_port == 1)
+ } else if (p_port == 1) {
return "min";
- else if (p_port == 2)
+ } else if (p_port == 2) {
return "max";
+ }
return "";
}
@@ -2475,12 +2478,13 @@ VisualShaderNodeVectorClamp::PortType VisualShaderNodeVectorClamp::get_input_por
}
String VisualShaderNodeVectorClamp::get_input_port_name(int p_port) const {
- if (p_port == 0)
+ if (p_port == 0) {
return "";
- else if (p_port == 1)
+ } else if (p_port == 1) {
return "min";
- else if (p_port == 2)
+ } else if (p_port == 2) {
return "max";
+ }
return "";
}
@@ -2619,10 +2623,11 @@ VisualShaderNodeVectorScalarStep::PortType VisualShaderNodeVectorScalarStep::get
}
String VisualShaderNodeVectorScalarStep::get_input_port_name(int p_port) const {
- if (p_port == 0)
+ if (p_port == 0) {
return "edge";
- else if (p_port == 1)
+ } else if (p_port == 1) {
return "x";
+ }
return "";
}
@@ -2662,12 +2667,13 @@ VisualShaderNodeScalarSmoothStep::PortType VisualShaderNodeScalarSmoothStep::get
}
String VisualShaderNodeScalarSmoothStep::get_input_port_name(int p_port) const {
- if (p_port == 0)
+ if (p_port == 0) {
return "edge0";
- else if (p_port == 1)
+ } else if (p_port == 1) {
return "edge1";
- else if (p_port == 2)
+ } else if (p_port == 2) {
return "x";
+ }
return "";
}
@@ -2708,12 +2714,13 @@ VisualShaderNodeVectorSmoothStep::PortType VisualShaderNodeVectorSmoothStep::get
}
String VisualShaderNodeVectorSmoothStep::get_input_port_name(int p_port) const {
- if (p_port == 0)
+ if (p_port == 0) {
return "edge0";
- else if (p_port == 1)
+ } else if (p_port == 1) {
return "edge1";
- else if (p_port == 2)
+ } else if (p_port == 2) {
return "x";
+ }
return "";
}
@@ -2759,12 +2766,13 @@ VisualShaderNodeVectorScalarSmoothStep::PortType VisualShaderNodeVectorScalarSmo
}
String VisualShaderNodeVectorScalarSmoothStep::get_input_port_name(int p_port) const {
- if (p_port == 0)
+ if (p_port == 0) {
return "edge0";
- else if (p_port == 1)
+ } else if (p_port == 1) {
return "edge1";
- else if (p_port == 2)
+ } else if (p_port == 2) {
return "x";
+ }
return "";
}
@@ -2988,8 +2996,9 @@ int VisualShaderNodeVectorScalarMix::get_input_port_count() const {
}
VisualShaderNodeVectorScalarMix::PortType VisualShaderNodeVectorScalarMix::get_input_port_type(int p_port) const {
- if (p_port == 2)
+ if (p_port == 2) {
return PORT_TYPE_SCALAR;
+ }
return PORT_TYPE_VECTOR;
}
@@ -3705,16 +3714,18 @@ String VisualShaderNodeTextureUniform::generate_global(Shader::Mode p_mode, Visu
switch (texture_type) {
case TYPE_DATA:
- if (color_default == COLOR_DEFAULT_BLACK)
+ if (color_default == COLOR_DEFAULT_BLACK) {
code += " : hint_black;\n";
- else
+ } else {
code += ";\n";
+ }
break;
case TYPE_COLOR:
- if (color_default == COLOR_DEFAULT_BLACK)
+ if (color_default == COLOR_DEFAULT_BLACK) {
code += " : hint_black_albedo;\n";
- else
+ } else {
code += " : hint_albedo;\n";
+ }
break;
case TYPE_NORMALMAP:
code += " : hint_normal;\n";
@@ -3954,16 +3965,18 @@ String VisualShaderNodeCubemapUniform::generate_global(Shader::Mode p_mode, Visu
switch (texture_type) {
case TYPE_DATA:
- if (color_default == COLOR_DEFAULT_BLACK)
+ if (color_default == COLOR_DEFAULT_BLACK) {
code += " : hint_black;\n";
- else
+ } else {
code += ";\n";
+ }
break;
case TYPE_COLOR:
- if (color_default == COLOR_DEFAULT_BLACK)
+ if (color_default == COLOR_DEFAULT_BLACK) {
code += " : hint_black_albedo;\n";
- else
+ } else {
code += " : hint_albedo;\n";
+ }
break;
case TYPE_NORMALMAP:
code += " : hint_normal;\n";
@@ -4311,8 +4324,9 @@ int VisualShaderNodeCompare::get_input_port_count() const {
}
VisualShaderNodeCompare::PortType VisualShaderNodeCompare::get_input_port_type(int p_port) const {
- if (p_port == 2)
+ if (p_port == 2) {
return PORT_TYPE_SCALAR;
+ }
switch (ctype) {
case CTYPE_SCALAR:
return PORT_TYPE_SCALAR;
@@ -4329,12 +4343,13 @@ VisualShaderNodeCompare::PortType VisualShaderNodeCompare::get_input_port_type(i
}
String VisualShaderNodeCompare::get_input_port_name(int p_port) const {
- if (p_port == 0)
+ if (p_port == 0) {
return "a";
- else if (p_port == 1)
+ } else if (p_port == 1) {
return "b";
- else if (p_port == 2)
+ } else if (p_port == 2) {
return "tolerance";
+ }
return "";
}
@@ -4347,8 +4362,9 @@ VisualShaderNodeCompare::PortType VisualShaderNodeCompare::get_output_port_type(
}
String VisualShaderNodeCompare::get_output_port_name(int p_port) const {
- if (p_port == 0)
+ if (p_port == 0) {
return "result";
+ }
return "";
}
@@ -4410,14 +4426,16 @@ String VisualShaderNodeCompare::generate_code(Shader::Mode p_mode, VisualShader:
break;
case CTYPE_BOOLEAN:
- if (func > FUNC_NOT_EQUAL)
+ if (func > FUNC_NOT_EQUAL) {
return "\t" + p_output_vars[0] + " = false;\n";
+ }
code += "\t" + p_output_vars[0] + " = " + (p_input_vars[0] + " $ " + p_input_vars[1]).replace("$", ops[func]) + ";\n";
break;
case CTYPE_TRANSFORM:
- if (func > FUNC_NOT_EQUAL)
+ if (func > FUNC_NOT_EQUAL) {
return "\t" + p_output_vars[0] + " = false;\n";
+ }
code += "\t" + p_output_vars[0] + " = " + (p_input_vars[0] + " $ " + p_input_vars[1]).replace("$", ops[func]) + ";\n";
break;
@@ -4486,8 +4504,9 @@ Vector<StringName> VisualShaderNodeCompare::get_editable_properties() const {
Vector<StringName> props;
props.push_back("type");
props.push_back("function");
- if (ctype == CTYPE_VECTOR)
+ if (ctype == CTYPE_VECTOR) {
props.push_back("condition");
+ }
return props;
}
diff --git a/scene/resources/world_2d.cpp b/scene/resources/world_2d.cpp
index 368a9d351d..1c753fdb91 100644
--- a/scene/resources/world_2d.cpp
+++ b/scene/resources/world_2d.cpp
@@ -103,8 +103,9 @@ struct SpatialIndexer2D {
Map<CellKey, CellData>::Element *E = cells.find(ck);
if (p_add) {
- if (!E)
+ if (!E) {
E = cells.insert(ck, CellData());
+ }
E->get().notifiers[p_notifier].inc();
} else {
ERR_CONTINUE(!E);
@@ -129,8 +130,9 @@ struct SpatialIndexer2D {
void _notifier_update(VisibilityNotifier2D *p_notifier, const Rect2 &p_rect) {
Map<VisibilityNotifier2D *, Rect2>::Element *E = notifiers.find(p_notifier);
ERR_FAIL_COND(!E);
- if (E->get() == p_rect)
+ if (E->get() == p_rect) {
return;
+ }
_notifier_update_cells(p_notifier, p_rect, true);
_notifier_update_cells(p_notifier, E->get(), false);
@@ -173,8 +175,9 @@ struct SpatialIndexer2D {
void _update_viewport(Viewport *p_viewport, const Rect2 &p_rect) {
Map<Viewport *, ViewportData>::Element *E = viewports.find(p_viewport);
ERR_FAIL_COND(!E);
- if (E->get().rect == p_rect)
+ if (E->get().rect == p_rect) {
return;
+ }
E->get().rect = p_rect;
changed = true;
}
@@ -195,8 +198,9 @@ struct SpatialIndexer2D {
}
void _update() {
- if (!changed)
+ if (!changed) {
return;
+ }
for (Map<Viewport *, ViewportData>::Element *E = viewports.front(); E; E = E->next()) {
Point2i begin = E->get().rect.position;
@@ -215,10 +219,12 @@ struct SpatialIndexer2D {
for (Map<CellKey, CellData>::Element *F = cells.front(); F; F = F->next()) {
const CellKey &ck = F->key();
- if (ck.x < begin.x || ck.x > end.x)
+ if (ck.x < begin.x || ck.x > end.x) {
continue;
- if (ck.y < begin.y || ck.y > end.y)
+ }
+ if (ck.y < begin.y || ck.y > end.y) {
continue;
+ }
//notifiers in cell
for (Map<VisibilityNotifier2D *, CellRef>::Element *G = F->get().notifiers.front(); G; G = G->next()) {
@@ -260,8 +266,9 @@ struct SpatialIndexer2D {
}
for (Map<VisibilityNotifier2D *, uint64_t>::Element *F = E->get().notifiers.front(); F; F = F->next()) {
- if (F->get() != pass)
+ if (F->get() != pass) {
removed.push_back(F->key());
+ }
}
while (!added.empty()) {
diff --git a/scene/resources/world_3d.cpp b/scene/resources/world_3d.cpp
index f53a24596a..8100f150ef 100644
--- a/scene/resources/world_3d.cpp
+++ b/scene/resources/world_3d.cpp
@@ -71,8 +71,9 @@ struct SpatialIndexer {
void _notifier_update(VisibilityNotifier3D *p_notifier, const AABB &p_rect) {
Map<VisibilityNotifier3D *, NotifierData>::Element *E = notifiers.find(p_notifier);
ERR_FAIL_COND(!E);
- if (E->get().aabb == p_rect)
+ if (E->get().aabb == p_rect) {
return;
+ }
E->get().aabb = p_rect;
octree.move(E->get().id, E->get().aabb);
@@ -133,12 +134,14 @@ struct SpatialIndexer {
}
void _update(uint64_t p_frame) {
- if (p_frame == last_frame)
+ if (p_frame == last_frame) {
return;
+ }
last_frame = p_frame;
- if (!changed)
+ if (!changed) {
return;
+ }
for (Map<Camera3D *, CameraData>::Element *E = cameras.front(); E; E = E->next()) {
pass++;
@@ -167,8 +170,9 @@ struct SpatialIndexer {
}
for (Map<VisibilityNotifier3D *, uint64_t>::Element *F = E->get().notifiers.front(); F; F = F->next()) {
- if (F->get() != pass)
+ if (F->get() != pass) {
removed.push_back(F->key());
+ }
}
while (!added.empty()) {
@@ -249,10 +253,11 @@ void World3D::set_environment(const Ref<Environment> &p_environment) {
}
environment = p_environment;
- if (environment.is_valid())
+ if (environment.is_valid()) {
RS::get_singleton()->scenario_set_environment(scenario, environment->get_rid());
- else
+ } else {
RS::get_singleton()->scenario_set_environment(scenario, RID());
+ }
emit_changed();
}
@@ -267,10 +272,11 @@ void World3D::set_fallback_environment(const Ref<Environment> &p_environment) {
}
fallback_environment = p_environment;
- if (fallback_environment.is_valid())
+ if (fallback_environment.is_valid()) {
RS::get_singleton()->scenario_set_fallback_environment(scenario, p_environment->get_rid());
- else
+ } else {
RS::get_singleton()->scenario_set_fallback_environment(scenario, RID());
+ }
emit_changed();
}
@@ -281,10 +287,11 @@ Ref<Environment> World3D::get_fallback_environment() const {
void World3D::set_camera_effects(const Ref<CameraEffects> &p_camera_effects) {
camera_effects = p_camera_effects;
- if (camera_effects.is_valid())
+ if (camera_effects.is_valid()) {
RS::get_singleton()->scenario_set_camera_effects(scenario, camera_effects->get_rid());
- else
+ } else {
RS::get_singleton()->scenario_set_camera_effects(scenario, RID());
+ }
}
Ref<CameraEffects> World3D::get_camera_effects() const {
diff --git a/servers/audio/audio_driver_dummy.cpp b/servers/audio/audio_driver_dummy.cpp
index 5560385fd3..70d5ebbded 100644
--- a/servers/audio/audio_driver_dummy.cpp
+++ b/servers/audio/audio_driver_dummy.cpp
@@ -86,20 +86,23 @@ AudioDriver::SpeakerMode AudioDriverDummy::get_speaker_mode() const {
};
void AudioDriverDummy::lock() {
- if (!thread)
+ if (!thread) {
return;
+ }
mutex.lock();
};
void AudioDriverDummy::unlock() {
- if (!thread)
+ if (!thread) {
return;
+ }
mutex.unlock();
};
void AudioDriverDummy::finish() {
- if (!thread)
+ if (!thread) {
return;
+ }
exit_thread = true;
Thread::wait_to_finish(thread);
diff --git a/servers/audio/audio_filter_sw.cpp b/servers/audio/audio_filter_sw.cpp
index b6759649cc..f5eafb7e60 100644
--- a/servers/audio/audio_filter_sw.cpp
+++ b/servers/audio/audio_filter_sw.cpp
@@ -54,8 +54,9 @@ void AudioFilterSW::prepare_coefficients(Coeffs *p_coeffs) {
int sr_limit = (sampling_rate / 2) + 512;
double final_cutoff = (cutoff > sr_limit) ? sr_limit : cutoff;
- if (final_cutoff < 1)
+ if (final_cutoff < 1) {
final_cutoff = 1; //don't allow less than this
+ }
double omega = 2.0 * Math_PI * final_cutoff / sampling_rate;
@@ -67,15 +68,17 @@ void AudioFilterSW::prepare_coefficients(Coeffs *p_coeffs) {
Q = 0.0001;
}
- if (mode == BANDPASS)
+ if (mode == BANDPASS) {
Q *= 2.0;
- else if (mode == PEAK)
+ } else if (mode == PEAK) {
Q *= 3.0;
+ }
double tmpgain = gain;
- if (tmpgain < 0.001)
+ if (tmpgain < 0.001) {
tmpgain = 0.001;
+ }
if (stages > 1) {
Q = (Q > 1.0 ? Math::pow(Q, 1.0 / stages) : Q);
@@ -142,8 +145,9 @@ void AudioFilterSW::prepare_coefficients(Coeffs *p_coeffs) {
} break;
case LOWSHELF: {
double tmpq = Math::sqrt(Q);
- if (tmpq <= 0)
+ if (tmpq <= 0) {
tmpq = 0.001;
+ }
double beta = Math::sqrt(tmpgain) / tmpq;
a0 = (tmpgain + 1.0) + (tmpgain - 1.0) * cos_v + beta * sin_v;
@@ -156,8 +160,9 @@ void AudioFilterSW::prepare_coefficients(Coeffs *p_coeffs) {
} break;
case HIGHSHELF: {
double tmpq = Math::sqrt(Q);
- if (tmpq <= 0)
+ if (tmpq <= 0) {
tmpq = 0.001;
+ }
double beta = Math::sqrt(tmpgain) / tmpq;
a0 = (tmpgain + 1.0) - (tmpgain - 1.0) * cos_v + beta * sin_v;
@@ -235,8 +240,9 @@ void AudioFilterSW::Processor::set_filter(AudioFilterSW *p_filter, bool p_clear_
}
void AudioFilterSW::Processor::update_coeffs(int p_interp_buffer_len) {
- if (!filter)
+ if (!filter) {
return;
+ }
if (p_interp_buffer_len) { //interpolate
Coeffs old_coeffs = coeffs;
@@ -253,8 +259,9 @@ void AudioFilterSW::Processor::update_coeffs(int p_interp_buffer_len) {
}
void AudioFilterSW::Processor::process(float *p_samples, int p_amount, int p_stride, bool p_interpolate) {
- if (!filter)
+ if (!filter) {
return;
+ }
if (p_interpolate) {
for (int i = 0; i < p_amount; i++) {
diff --git a/servers/audio/audio_rb_resampler.cpp b/servers/audio/audio_rb_resampler.cpp
index a7542fab03..7613e70e64 100644
--- a/servers/audio/audio_rb_resampler.cpp
+++ b/servers/audio/audio_rb_resampler.cpp
@@ -34,8 +34,9 @@
#include "servers/audio_server.h"
int AudioRBResampler::get_channel_count() const {
- if (!rb)
+ if (!rb) {
return 0;
+ }
return channels;
}
@@ -101,8 +102,9 @@ uint32_t AudioRBResampler::_resample(AudioFrame *p_dest, int p_todo, int32_t p_i
}
bool AudioRBResampler::mix(AudioFrame *p_dest, int p_frames) {
- if (!rb)
+ if (!rb) {
return false;
+ }
int32_t increment = (src_mix_rate * MIX_FRAC_LEN) / target_mix_rate;
int read_space = get_reader_space();
@@ -125,8 +127,9 @@ bool AudioRBResampler::mix(AudioFrame *p_dest, int p_frames) {
break;
}
- if (src_read > read_space)
+ if (src_read > read_space) {
src_read = read_space;
+ }
rb_read_pos = (rb_read_pos + src_read) & rb_mask;
@@ -147,8 +150,9 @@ bool AudioRBResampler::mix(AudioFrame *p_dest, int p_frames) {
}
int AudioRBResampler::get_num_of_ready_frames() {
- if (!is_ready())
+ if (!is_ready()) {
return 0;
+ }
int32_t increment = (src_mix_rate * MIX_FRAC_LEN) / target_mix_rate;
int read_space = get_reader_space();
return (int64_t(read_space) << MIX_FRAC_BITS) / increment;
@@ -192,8 +196,9 @@ Error AudioRBResampler::setup(int p_channels, int p_src_mix_rate, int p_target_m
}
void AudioRBResampler::clear() {
- if (!rb)
+ if (!rb) {
return;
+ }
//should be stopped at this point but just in case
memdelete_arr(rb);
diff --git a/servers/audio/audio_stream.cpp b/servers/audio/audio_stream.cpp
index 11b96edb8d..2cc2f5c291 100644
--- a/servers/audio/audio_stream.cpp
+++ b/servers/audio/audio_stream.cpp
@@ -244,8 +244,9 @@ Ref<AudioStream> AudioStreamRandomPitch::get_audio_stream() const {
}
void AudioStreamRandomPitch::set_random_pitch(float p_pitch) {
- if (p_pitch < 1)
+ if (p_pitch < 1) {
p_pitch = 1;
+ }
random_pitch = p_pitch;
}
@@ -256,8 +257,9 @@ float AudioStreamRandomPitch::get_random_pitch() const {
Ref<AudioStreamPlayback> AudioStreamRandomPitch::instance_playback() {
Ref<AudioStreamPlaybackRandomPitch> playback;
playback.instance();
- if (audio_stream.is_valid())
+ if (audio_stream.is_valid()) {
playback->playback = audio_stream->instance_playback();
+ }
playbacks.insert(playback.ptr());
playback->random_pitch = Ref<AudioStreamRandomPitch>((AudioStreamRandomPitch *)this);
diff --git a/servers/audio/effects/audio_effect_chorus.cpp b/servers/audio/effects/audio_effect_chorus.cpp
index 48f050c5ab..2b530475f0 100644
--- a/servers/audio/effects/audio_effect_chorus.cpp
+++ b/servers/audio/effects/audio_effect_chorus.cpp
@@ -81,8 +81,9 @@ void AudioEffectChorusInstance::_process_chunk(const AudioFrame *p_src_frames, A
}
//low pass filter
- if (v.cutoff == 0)
+ if (v.cutoff == 0) {
continue;
+ }
float auxlp = expf(-2.0 * Math_PI * v.cutoff / mix_rate);
float c1 = 1.0 - auxlp;
float c2 = auxlp;
diff --git a/servers/audio/effects/audio_effect_compressor.cpp b/servers/audio/effects/audio_effect_compressor.cpp
index b0f829b679..4b0b4dabea 100644
--- a/servers/audio/effects/audio_effect_compressor.cpp
+++ b/servers/audio/effects/audio_effect_compressor.cpp
@@ -66,11 +66,13 @@ void AudioEffectCompressorInstance::process(const AudioFrame *p_src_frames, Audi
float overdb = 2.08136898f * Math::linear2db(peak / threshold);
- if (overdb < 0.0) //we only care about what goes over to compress
+ if (overdb < 0.0) { //we only care about what goes over to compress
overdb = 0.0;
+ }
- if (overdb - rundb > 5) // diffeence is too large
+ if (overdb - rundb > 5) { // diffeence is too large
averatio = 4;
+ }
if (overdb > rundb) {
rundb = overdb + atcoef * (rundb - overdb);
@@ -101,8 +103,9 @@ void AudioEffectCompressorInstance::process(const AudioFrame *p_src_frames, Audi
gr_meter = grv;
} else {
gr_meter *= gr_meter_decay;
- if (gr_meter > 1)
+ if (gr_meter > 1) {
gr_meter = 1;
+ }
}
p_dst_frames[i] = p_src_frames[i] * grv * makeup * mix + p_src_frames[i] * (1.0 - mix);
diff --git a/servers/audio/effects/audio_effect_delay.cpp b/servers/audio/effects/audio_effect_delay.cpp
index 00cf7a0e70..d6ab14be89 100644
--- a/servers/audio/effects/audio_effect_delay.cpp
+++ b/servers/audio/effects/audio_effect_delay.cpp
@@ -105,8 +105,9 @@ void AudioEffectDelayInstance::_process_chunk(const AudioFrame *p_src_frames, Au
ring_buffer_pos++;
- if ((++feedback_buffer_pos) >= feedback_delay_frames)
+ if ((++feedback_buffer_pos) >= feedback_delay_frames) {
feedback_buffer_pos = 0;
+ }
}
}
diff --git a/servers/audio/effects/audio_effect_distortion.cpp b/servers/audio/effects/audio_effect_distortion.cpp
index da4c34ce82..dc5c2cc16f 100644
--- a/servers/audio/effects/audio_effect_distortion.cpp
+++ b/servers/audio/effects/audio_effect_distortion.cpp
@@ -59,10 +59,11 @@ void AudioEffectDistortionInstance::process(const AudioFrame *p_src_frames, Audi
switch (base->mode) {
case AudioEffectDistortion::MODE_CLIP: {
a = powf(a, 1.0001 - drive_f);
- if (a > 1.0)
+ if (a > 1.0) {
a = 1.0;
- else if (a < (-1.0))
+ } else if (a < (-1.0)) {
a = -1.0;
+ }
} break;
case AudioEffectDistortion::MODE_ATAN: {
diff --git a/servers/audio/effects/audio_effect_filter.cpp b/servers/audio/effects/audio_effect_filter.cpp
index cf6d0fa896..a5135ee1a6 100644
--- a/servers/audio/effects/audio_effect_filter.cpp
+++ b/servers/audio/effects/audio_effect_filter.cpp
@@ -36,12 +36,15 @@ void AudioEffectFilterInstance::_process_filter(const AudioFrame *p_src_frames,
for (int i = 0; i < p_frame_count; i++) {
float f = p_src_frames[i].l;
filter_process[0][0].process_one(f);
- if (S > 1)
+ if (S > 1) {
filter_process[0][1].process_one(f);
- if (S > 2)
+ }
+ if (S > 2) {
filter_process[0][2].process_one(f);
- if (S > 3)
+ }
+ if (S > 3) {
filter_process[0][3].process_one(f);
+ }
p_dst_frames[i].l = f;
}
@@ -49,12 +52,15 @@ void AudioEffectFilterInstance::_process_filter(const AudioFrame *p_src_frames,
for (int i = 0; i < p_frame_count; i++) {
float f = p_src_frames[i].r;
filter_process[1][0].process_one(f);
- if (S > 1)
+ if (S > 1) {
filter_process[1][1].process_one(f);
- if (S > 2)
+ }
+ if (S > 2) {
filter_process[1][2].process_one(f);
- if (S > 3)
+ }
+ if (S > 3) {
filter_process[1][3].process_one(f);
+ }
p_dst_frames[i].r = f;
}
diff --git a/servers/audio/effects/audio_effect_filter.h b/servers/audio/effects/audio_effect_filter.h
index c439c5a5b5..b11a4e3623 100644
--- a/servers/audio/effects/audio_effect_filter.h
+++ b/servers/audio/effects/audio_effect_filter.h
@@ -99,8 +99,9 @@ class AudioEffectLowPassFilter : public AudioEffectFilter {
GDCLASS(AudioEffectLowPassFilter, AudioEffectFilter);
void _validate_property(PropertyInfo &property) const {
- if (property.name == "gain")
+ if (property.name == "gain") {
property.usage = 0;
+ }
}
public:
@@ -111,8 +112,9 @@ public:
class AudioEffectHighPassFilter : public AudioEffectFilter {
GDCLASS(AudioEffectHighPassFilter, AudioEffectFilter);
void _validate_property(PropertyInfo &property) const {
- if (property.name == "gain")
+ if (property.name == "gain") {
property.usage = 0;
+ }
}
public:
@@ -123,8 +125,9 @@ public:
class AudioEffectBandPassFilter : public AudioEffectFilter {
GDCLASS(AudioEffectBandPassFilter, AudioEffectFilter);
void _validate_property(PropertyInfo &property) const {
- if (property.name == "gain")
+ if (property.name == "gain") {
property.usage = 0;
+ }
}
public:
diff --git a/servers/audio/effects/audio_effect_pitch_shift.cpp b/servers/audio/effects/audio_effect_pitch_shift.cpp
index a8f25ac325..fb6b56d984 100644
--- a/servers/audio/effects/audio_effect_pitch_shift.cpp
+++ b/servers/audio/effects/audio_effect_pitch_shift.cpp
@@ -94,7 +94,9 @@ void SMBPitchShift::PitchShift(float pitchShift, long numSampsToProcess, long ff
freqPerBin = sampleRate/(double)fftFrameSize;
expct = 2.*Math_PI*(double)stepSize/(double)fftFrameSize;
inFifoLatency = fftFrameSize-stepSize;
- if (gRover == 0) gRover = inFifoLatency;
+ if (gRover == 0) { gRover = inFifoLatency;
+
+}
/* initialize our static arrays */
@@ -142,8 +144,10 @@ void SMBPitchShift::PitchShift(float pitchShift, long numSampsToProcess, long ff
/* map delta phase into +/- Pi interval */
qpd = tmp/Math_PI;
- if (qpd >= 0) qpd += qpd&1;
- else qpd -= qpd&1;
+ if (qpd >= 0) { qpd += qpd&1;
+ } else { qpd -= qpd&1;
+
+}
tmp -= Math_PI*(double)qpd;
/* get deviation from bin frequency from the +/- Pi interval */
@@ -200,7 +204,9 @@ void SMBPitchShift::PitchShift(float pitchShift, long numSampsToProcess, long ff
}
/* zero negative frequencies */
- for (k = fftFrameSize+2; k < 2*fftFrameSize; k++) gFFTworksp[k] = 0.;
+ for (k = fftFrameSize+2; k < 2*fftFrameSize; k++) { gFFTworksp[k] = 0.;
+
+}
/* do inverse transform */
smbFft(gFFTworksp, fftFrameSize, 1);
@@ -210,13 +216,17 @@ void SMBPitchShift::PitchShift(float pitchShift, long numSampsToProcess, long ff
window = -.5*cos(2.*Math_PI*(double)k/(double)fftFrameSize)+.5;
gOutputAccum[k] += 2.*window*gFFTworksp[2*k]/(fftFrameSize2*osamp);
}
- for (k = 0; k < stepSize; k++) gOutFIFO[k] = gOutputAccum[k];
+ for (k = 0; k < stepSize; k++) { gOutFIFO[k] = gOutputAccum[k];
+
+}
/* shift accumulator */
memmove(gOutputAccum, gOutputAccum+stepSize, fftFrameSize*sizeof(float));
/* move input FIFO */
- for (k = 0; k < inFifoLatency; k++) gInFIFO[k] = gInFIFO[k+stepSize];
+ for (k = 0; k < inFifoLatency; k++) { gInFIFO[k] = gInFIFO[k+stepSize];
+
+}
}
}
@@ -245,7 +255,9 @@ void SMBPitchShift::smbFft(float *fftBuffer, long fftFrameSize, long sign)
for (i = 2; i < 2*fftFrameSize-2; i += 2) {
for (bitm = 2, j = 0; bitm < 2*fftFrameSize; bitm <<= 1) {
- if (i & bitm) j++;
+ if (i & bitm) { j++;
+
+}
j <<= 1;
}
if (i < j) {
diff --git a/servers/audio/effects/audio_effect_spectrum_analyzer.cpp b/servers/audio/effects/audio_effect_spectrum_analyzer.cpp
index a3fd11c6c0..e744dbf9b0 100644
--- a/servers/audio/effects/audio_effect_spectrum_analyzer.cpp
+++ b/servers/audio/effects/audio_effect_spectrum_analyzer.cpp
@@ -50,8 +50,9 @@ static void smbFft(float *fftBuffer, long fftFrameSize, long sign)
for (i = 2; i < 2 * fftFrameSize - 2; i += 2) {
for (bitm = 2, j = 0; bitm < 2 * fftFrameSize; bitm <<= 1) {
- if (i & bitm)
+ if (i & bitm) {
j++;
+ }
j <<= 1;
}
if (i < j) {
diff --git a/servers/audio/effects/eq.cpp b/servers/audio/effects/eq.cpp
index 59b3ba2d0b..08a6cf55fa 100644
--- a/servers/audio/effects/eq.cpp
+++ b/servers/audio/effects/eq.cpp
@@ -42,22 +42,25 @@ static int solve_quadratic(double a, double b, double c, double *r1, double *r2)
//solves quadractic and returns number of roots
double base = 2 * a;
- if (base == 0.0f)
+ if (base == 0.0f) {
return 0;
+ }
double squared = b * b - 4 * a * c;
- if (squared < 0.0)
+ if (squared < 0.0) {
return 0;
+ }
squared = sqrt(squared);
*r1 = (-b + squared) / base;
*r2 = (-b - squared) / base;
- if (*r1 == *r2)
+ if (*r1 == *r2) {
return 1;
- else
+ } else {
return 2;
+ }
}
EQ::BandProcess::BandProcess() {
diff --git a/servers/audio/effects/reverb.cpp b/servers/audio/effects/reverb.cpp
index 99f60557e1..7c35d88ced 100644
--- a/servers/audio/effects/reverb.cpp
+++ b/servers/audio/effects/reverb.cpp
@@ -57,22 +57,27 @@ const float Reverb::allpass_tunings[MAX_ALLPASS] = {
};
void Reverb::process(float *p_src, float *p_dst, int p_frames) {
- if (p_frames > INPUT_BUFFER_MAX_SIZE)
+ if (p_frames > INPUT_BUFFER_MAX_SIZE) {
p_frames = INPUT_BUFFER_MAX_SIZE;
+ }
int predelay_frames = lrint((params.predelay / 1000.0) * params.mix_rate);
- if (predelay_frames < 10)
+ if (predelay_frames < 10) {
predelay_frames = 10;
- if (predelay_frames >= echo_buffer_size)
+ }
+ if (predelay_frames >= echo_buffer_size) {
predelay_frames = echo_buffer_size - 1;
+ }
for (int i = 0; i < p_frames; i++) {
- if (echo_buffer_pos >= echo_buffer_size)
+ if (echo_buffer_pos >= echo_buffer_size) {
echo_buffer_pos = 0;
+ }
int read_pos = echo_buffer_pos - predelay_frames;
- while (read_pos < 0)
+ while (read_pos < 0) {
read_pos += echo_buffer_size;
+ }
float in = undenormalise(echo_buffer[read_pos] * params.predelay_fb + p_src[i]);
@@ -104,8 +109,9 @@ void Reverb::process(float *p_src, float *p_dst, int p_frames) {
int size_limit = c.size - lrintf((float)c.extra_spread_frames * (1.0 - params.extra_spread));
for (int j = 0; j < p_frames; j++) {
- if (c.pos >= size_limit) //reset this now just in case
+ if (c.pos >= size_limit) { //reset this now just in case
c.pos = 0;
+ }
float out = undenormalise(c.buffer[c.pos] * c.feedback);
out = out * (1.0 - c.damp) + c.damp_h * c.damp; //lowpass
@@ -156,8 +162,9 @@ void Reverb::process(float *p_src, float *p_dst, int p_frames) {
int size_limit = a.size - lrintf((float)a.extra_spread_frames * (1.0 - params.extra_spread));
for (int j = 0; j < p_frames; j++) {
- if (a.pos >= size_limit)
+ if (a.pos >= size_limit) {
a.pos = 0;
+ }
float aux = a.buffer[a.pos];
a.buffer[a.pos] = undenormalise(allpass_feedback * aux + p_dst[j]);
@@ -200,10 +207,12 @@ void Reverb::set_predelay_feedback(float p_predelay_fb) {
}
void Reverb::set_highpass(float p_frq) {
- if (p_frq > 1)
+ if (p_frq > 1) {
p_frq = 1;
- if (p_frq < 0)
+ }
+ if (p_frq < 0) {
p_frq = 0;
+ }
params.hpf = p_frq;
}
@@ -230,13 +239,15 @@ void Reverb::configure_buffers() {
c.extra_spread_frames = lrint(params.extra_spread_base * params.mix_rate);
int len = lrint(comb_tunings[i] * params.mix_rate) + c.extra_spread_frames;
- if (len < 5)
+ if (len < 5) {
len = 5; //may this happen?
+ }
c.buffer = memnew_arr(float, len);
c.pos = 0;
- for (int j = 0; j < len; j++)
+ for (int j = 0; j < len; j++) {
c.buffer[j] = 0;
+ }
c.size = len;
}
@@ -246,13 +257,15 @@ void Reverb::configure_buffers() {
a.extra_spread_frames = lrint(params.extra_spread_base * params.mix_rate);
int len = lrint(allpass_tunings[i] * params.mix_rate) + a.extra_spread_frames;
- if (len < 5)
+ if (len < 5) {
len = 5; //may this happen?
+ }
a.buffer = memnew_arr(float, len);
a.pos = 0;
- for (int j = 0; j < len; j++)
+ for (int j = 0; j < len; j++) {
a.buffer[j] = 0;
+ }
a.size = len;
}
@@ -273,10 +286,11 @@ void Reverb::update_parameters() {
for (int i = 0; i < MAX_COMBS; i++) {
Comb &c = comb[i];
c.feedback = room_offset + params.room_size * room_scale;
- if (c.feedback < room_offset)
+ if (c.feedback < room_offset) {
c.feedback = room_offset;
- else if (c.feedback > (room_offset + room_scale))
+ } else if (c.feedback > (room_offset + room_scale)) {
c.feedback = (room_offset + room_scale);
+ }
float auxdmp = params.damp / 2.0 + 0.5; //only half the range (0.5 .. 1.0 is enough)
auxdmp *= auxdmp;
@@ -286,19 +300,22 @@ void Reverb::update_parameters() {
}
void Reverb::clear_buffers() {
- if (echo_buffer)
+ if (echo_buffer) {
memdelete_arr(echo_buffer);
+ }
for (int i = 0; i < MAX_COMBS; i++) {
- if (comb[i].buffer)
+ if (comb[i].buffer) {
memdelete_arr(comb[i].buffer);
+ }
comb[i].buffer = nullptr;
}
for (int i = 0; i < MAX_ALLPASS; i++) {
- if (allpass[i].buffer)
+ if (allpass[i].buffer) {
memdelete_arr(allpass[i].buffer);
+ }
allpass[i].buffer = nullptr;
}
diff --git a/servers/audio_server.cpp b/servers/audio_server.cpp
index edccd7507c..7b1ac534b4 100644
--- a/servers/audio_server.cpp
+++ b/servers/audio_server.cpp
@@ -55,17 +55,20 @@ void AudioDriver::set_singleton() {
}
void AudioDriver::audio_server_process(int p_frames, int32_t *p_buffer, bool p_update_mix_time) {
- if (p_update_mix_time)
+ if (p_update_mix_time) {
update_mix_time(p_frames);
+ }
- if (AudioServer::get_singleton())
+ if (AudioServer::get_singleton()) {
AudioServer::get_singleton()->_driver_process(p_frames, p_buffer);
+ }
}
void AudioDriver::update_mix_time(int p_frames) {
_last_mix_frames = p_frames;
- if (OS::get_singleton())
+ if (OS::get_singleton()) {
_last_mix_time = OS::get_singleton()->get_ticks_usec();
+ }
}
double AudioDriver::get_time_since_last_mix() const {
@@ -340,23 +343,26 @@ void AudioServer::_mix_step() {
//process effects
if (!bus->bypass) {
for (int j = 0; j < bus->effects.size(); j++) {
- if (!bus->effects[j].enabled)
+ if (!bus->effects[j].enabled) {
continue;
+ }
#ifdef DEBUG_ENABLED
uint64_t ticks = OS::get_singleton()->get_ticks_usec();
#endif
for (int k = 0; k < bus->channels.size(); k++) {
- if (!(bus->channels[k].active || bus->channels[k].effect_instances[j]->process_silence()))
+ if (!(bus->channels[k].active || bus->channels[k].effect_instances[j]->process_silence())) {
continue;
+ }
bus->channels.write[k].effect_instances.write[j]->process(bus->channels[k].buffer.ptr(), temp_buffer.write[k].ptrw(), buffer_size);
}
//swap buffers, so internal buffer always has the right data
for (int k = 0; k < bus->channels.size(); k++) {
- if (!(buses[i]->channels[k].active || bus->channels[k].effect_instances[j]->process_silence()))
+ if (!(buses[i]->channels[k].active || bus->channels[k].effect_instances[j]->process_silence())) {
continue;
+ }
SWAP(bus->channels.write[k].buffer, temp_buffer.write[k]);
}
@@ -383,8 +389,9 @@ void AudioServer::_mix_step() {
}
for (int k = 0; k < bus->channels.size(); k++) {
- if (!bus->channels[k].active)
+ if (!bus->channels[k].active) {
continue;
+ }
AudioFrame *buf = bus->channels.write[k].buffer.ptrw();
@@ -445,10 +452,12 @@ void AudioServer::_mix_step() {
}
bool AudioServer::thread_has_channel_mix_buffer(int p_bus, int p_buffer) const {
- if (p_bus < 0 || p_bus >= buses.size())
+ if (p_bus < 0 || p_bus >= buses.size()) {
return false;
- if (p_buffer < 0 || p_buffer >= buses[p_bus]->channels.size())
+ }
+ if (p_buffer < 0 || p_buffer >= buses[p_bus]->channels.size()) {
return false;
+ }
return true;
}
@@ -563,10 +572,11 @@ void AudioServer::add_bus(int p_at_pos) {
if (p_at_pos >= buses.size()) {
p_at_pos = -1;
} else if (p_at_pos == 0) {
- if (buses.size() > 1)
+ if (buses.size() > 1) {
p_at_pos = 1;
- else
+ } else {
p_at_pos = -1;
+ }
}
String attempt = "New Bus";
@@ -601,10 +611,11 @@ void AudioServer::add_bus(int p_at_pos) {
bus_map[attempt] = bus;
- if (p_at_pos == -1)
+ if (p_at_pos == -1) {
buses.push_back(bus);
- else
+ } else {
buses.insert(p_at_pos, bus);
+ }
emit_signal("bus_layout_changed");
}
@@ -615,8 +626,9 @@ void AudioServer::move_bus(int p_bus, int p_to_pos) {
MARK_EDITED
- if (p_bus == p_to_pos)
+ if (p_bus == p_to_pos) {
return;
+ }
Bus *bus = buses[p_bus];
buses.remove(p_bus);
@@ -638,8 +650,9 @@ int AudioServer::get_bus_count() const {
void AudioServer::set_bus_name(int p_bus, const String &p_name) {
ERR_FAIL_INDEX(p_bus, buses.size());
- if (p_bus == 0 && p_name != "Master")
+ if (p_bus == 0 && p_name != "Master") {
return; //bus 0 is always master
+ }
MARK_EDITED
@@ -923,8 +936,9 @@ void AudioServer::init() {
set_bus_count(1);
set_bus_name(0, "Master");
- if (AudioDriver::get_singleton())
+ if (AudioDriver::get_singleton()) {
AudioDriver::get_singleton()->start();
+ }
#ifdef TOOLS_ENABLED
set_edited(false); //avoid editors from thinking this was edited
@@ -942,28 +956,33 @@ void AudioServer::update() {
uint64_t server_time = prof_time;
// Subtract the server time from the driver time
- if (driver_time > server_time)
+ if (driver_time > server_time) {
driver_time -= server_time;
+ }
Array values;
for (int i = buses.size() - 1; i >= 0; i--) {
Bus *bus = buses[i];
- if (bus->bypass)
+ if (bus->bypass) {
continue;
+ }
for (int j = 0; j < bus->effects.size(); j++) {
- if (!bus->effects[j].enabled)
+ if (!bus->effects[j].enabled) {
continue;
+ }
values.push_back(String(bus->name) + bus->effects[j].effect->get_name());
values.push_back(USEC_TO_SEC(bus->effects[j].prof_time));
// Subtract the effect time from the driver and server times
- if (driver_time > bus->effects[j].prof_time)
+ if (driver_time > bus->effects[j].prof_time) {
driver_time -= bus->effects[j].prof_time;
- if (server_time > bus->effects[j].prof_time)
+ }
+ if (server_time > bus->effects[j].prof_time) {
server_time -= bus->effects[j].prof_time;
+ }
}
}
@@ -979,12 +998,14 @@ void AudioServer::update() {
// Reset profiling times
for (int i = buses.size() - 1; i >= 0; i--) {
Bus *bus = buses[i];
- if (bus->bypass)
+ if (bus->bypass) {
continue;
+ }
for (int j = 0; j < bus->effects.size(); j++) {
- if (!bus->effects[j].enabled)
+ if (!bus->effects[j].enabled) {
continue;
+ }
bus->effects.write[j].prof_time = 0;
}
@@ -1348,8 +1369,9 @@ bool AudioBusLayout::_get(const StringName &p_name, Variant &r_ret) const {
String s = p_name;
if (s.begins_with("bus/")) {
int index = s.get_slice("/", 1).to_int();
- if (index < 0 || index >= buses.size())
+ if (index < 0 || index >= buses.size()) {
return false;
+ }
const Bus &bus = buses[index];
diff --git a/servers/physics_2d/area_2d_sw.cpp b/servers/physics_2d/area_2d_sw.cpp
index db2ae36067..acbbb7e1e8 100644
--- a/servers/physics_2d/area_2d_sw.cpp
+++ b/servers/physics_2d/area_2d_sw.cpp
@@ -47,13 +47,15 @@ Area2DSW::BodyKey::BodyKey(Area2DSW *p_body, uint32_t p_body_shape, uint32_t p_a
}
void Area2DSW::_shapes_changed() {
- if (!moved_list.in_list() && get_space())
+ if (!moved_list.in_list() && get_space()) {
get_space()->area_add_to_moved_list(&moved_list);
+ }
}
void Area2DSW::set_transform(const Transform2D &p_transform) {
- if (!moved_list.in_list() && get_space())
+ if (!moved_list.in_list() && get_space()) {
get_space()->area_add_to_moved_list(&moved_list);
+ }
_set_transform(p_transform);
_set_inv_transform(p_transform.affine_inverse());
@@ -61,10 +63,12 @@ void Area2DSW::set_transform(const Transform2D &p_transform) {
void Area2DSW::set_space(Space2DSW *p_space) {
if (get_space()) {
- if (monitor_query_list.in_list())
+ if (monitor_query_list.in_list()) {
get_space()->area_remove_from_monitor_query_list(&monitor_query_list);
- if (moved_list.in_list())
+ }
+ if (moved_list.in_list()) {
get_space()->area_remove_from_moved_list(&moved_list);
+ }
}
monitored_bodies.clear();
@@ -89,8 +93,9 @@ void Area2DSW::set_monitor_callback(ObjectID p_id, const StringName &p_method) {
_shape_changed();
- if (!moved_list.in_list() && get_space())
+ if (!moved_list.in_list() && get_space()) {
get_space()->area_add_to_moved_list(&moved_list);
+ }
}
void Area2DSW::set_area_monitor_callback(ObjectID p_id, const StringName &p_method) {
@@ -109,14 +114,16 @@ void Area2DSW::set_area_monitor_callback(ObjectID p_id, const StringName &p_meth
_shape_changed();
- if (!moved_list.in_list() && get_space())
+ if (!moved_list.in_list() && get_space()) {
get_space()->area_add_to_moved_list(&moved_list);
+ }
}
void Area2DSW::set_space_override_mode(PhysicsServer2D::AreaSpaceOverrideMode p_mode) {
bool do_override = p_mode != PhysicsServer2D::AREA_SPACE_OVERRIDE_DISABLED;
- if (do_override == (space_override_mode != PhysicsServer2D::AREA_SPACE_OVERRIDE_DISABLED))
+ if (do_override == (space_override_mode != PhysicsServer2D::AREA_SPACE_OVERRIDE_DISABLED)) {
return;
+ }
_unregister_shapes();
space_override_mode = p_mode;
_shape_changed();
@@ -177,13 +184,15 @@ Variant Area2DSW::get_param(PhysicsServer2D::AreaParameter p_param) const {
void Area2DSW::_queue_monitor_update() {
ERR_FAIL_COND(!get_space());
- if (!monitor_query_list.in_list())
+ if (!monitor_query_list.in_list()) {
get_space()->area_add_to_monitor_query_list(&monitor_query_list);
+ }
}
void Area2DSW::set_monitorable(bool p_monitorable) {
- if (monitorable == p_monitorable)
+ if (monitorable == p_monitorable) {
return;
+ }
monitorable = p_monitorable;
_set_static(!monitorable);
@@ -193,8 +202,9 @@ void Area2DSW::call_queries() {
if (monitor_callback_id.is_valid() && !monitored_bodies.empty()) {
Variant res[5];
Variant *resptr[5];
- for (int i = 0; i < 5; i++)
+ for (int i = 0; i < 5; i++) {
resptr[i] = &res[i];
+ }
Object *obj = ObjectDB::get_instance(monitor_callback_id);
if (!obj) {
@@ -204,8 +214,9 @@ void Area2DSW::call_queries() {
}
for (Map<BodyKey, BodyState>::Element *E = monitored_bodies.front(); E; E = E->next()) {
- if (E->get().state == 0)
+ if (E->get().state == 0) {
continue; //nothing happened
+ }
res[0] = E->get().state > 0 ? PhysicsServer2D::AREA_BODY_ADDED : PhysicsServer2D::AREA_BODY_REMOVED;
res[1] = E->key().rid;
@@ -223,8 +234,9 @@ void Area2DSW::call_queries() {
if (area_monitor_callback_id.is_valid() && !monitored_areas.empty()) {
Variant res[5];
Variant *resptr[5];
- for (int i = 0; i < 5; i++)
+ for (int i = 0; i < 5; i++) {
resptr[i] = &res[i];
+ }
Object *obj = ObjectDB::get_instance(area_monitor_callback_id);
if (!obj) {
@@ -234,8 +246,9 @@ void Area2DSW::call_queries() {
}
for (Map<BodyKey, BodyState>::Element *E = monitored_areas.front(); E; E = E->next()) {
- if (E->get().state == 0)
+ if (E->get().state == 0) {
continue; //nothing happened
+ }
res[0] = E->get().state > 0 ? PhysicsServer2D::AREA_BODY_ADDED : PhysicsServer2D::AREA_BODY_REMOVED;
res[1] = E->key().rid;
diff --git a/servers/physics_2d/area_2d_sw.h b/servers/physics_2d/area_2d_sw.h
index 8deeb82174..f14466f582 100644
--- a/servers/physics_2d/area_2d_sw.h
+++ b/servers/physics_2d/area_2d_sw.h
@@ -71,10 +71,12 @@ class Area2DSW : public CollisionObject2DSW {
if (rid == p_key.rid) {
if (body_shape == p_key.body_shape) {
return area_shape < p_key.area_shape;
- } else
+ } else {
return body_shape < p_key.body_shape;
- } else
+ }
+ } else {
return rid < p_key.rid;
+ }
}
_FORCE_INLINE_ BodyKey() {}
@@ -166,29 +168,33 @@ public:
void Area2DSW::add_body_to_query(Body2DSW *p_body, uint32_t p_body_shape, uint32_t p_area_shape) {
BodyKey bk(p_body, p_body_shape, p_area_shape);
monitored_bodies[bk].inc();
- if (!monitor_query_list.in_list())
+ if (!monitor_query_list.in_list()) {
_queue_monitor_update();
+ }
}
void Area2DSW::remove_body_from_query(Body2DSW *p_body, uint32_t p_body_shape, uint32_t p_area_shape) {
BodyKey bk(p_body, p_body_shape, p_area_shape);
monitored_bodies[bk].dec();
- if (!monitor_query_list.in_list())
+ if (!monitor_query_list.in_list()) {
_queue_monitor_update();
+ }
}
void Area2DSW::add_area_to_query(Area2DSW *p_area, uint32_t p_area_shape, uint32_t p_self_shape) {
BodyKey bk(p_area, p_area_shape, p_self_shape);
monitored_areas[bk].inc();
- if (!monitor_query_list.in_list())
+ if (!monitor_query_list.in_list()) {
_queue_monitor_update();
+ }
}
void Area2DSW::remove_area_from_query(Area2DSW *p_area, uint32_t p_area_shape, uint32_t p_self_shape) {
BodyKey bk(p_area, p_area_shape, p_self_shape);
monitored_areas[bk].dec();
- if (!monitor_query_list.in_list())
+ if (!monitor_query_list.in_list()) {
_queue_monitor_update();
+ }
}
#endif // AREA_2D_SW_H
diff --git a/servers/physics_2d/area_pair_2d_sw.cpp b/servers/physics_2d/area_pair_2d_sw.cpp
index a3d5e403c1..d7bceb9f02 100644
--- a/servers/physics_2d/area_pair_2d_sw.cpp
+++ b/servers/physics_2d/area_pair_2d_sw.cpp
@@ -42,16 +42,20 @@ bool AreaPair2DSW::setup(real_t p_step) {
if (result != colliding) {
if (result) {
- if (area->get_space_override_mode() != PhysicsServer2D::AREA_SPACE_OVERRIDE_DISABLED)
+ if (area->get_space_override_mode() != PhysicsServer2D::AREA_SPACE_OVERRIDE_DISABLED) {
body->add_area(area);
- if (area->has_monitor_callback())
+ }
+ if (area->has_monitor_callback()) {
area->add_body_to_query(body, body_shape, area_shape);
+ }
} else {
- if (area->get_space_override_mode() != PhysicsServer2D::AREA_SPACE_OVERRIDE_DISABLED)
+ if (area->get_space_override_mode() != PhysicsServer2D::AREA_SPACE_OVERRIDE_DISABLED) {
body->remove_area(area);
- if (area->has_monitor_callback())
+ }
+ if (area->has_monitor_callback()) {
area->remove_body_from_query(body, body_shape, area_shape);
+ }
}
colliding = result;
@@ -71,16 +75,19 @@ AreaPair2DSW::AreaPair2DSW(Body2DSW *p_body, int p_body_shape, Area2DSW *p_area,
colliding = false;
body->add_constraint(this, 0);
area->add_constraint(this);
- if (p_body->get_mode() == PhysicsServer2D::BODY_MODE_KINEMATIC) //need to be active to process pair
+ if (p_body->get_mode() == PhysicsServer2D::BODY_MODE_KINEMATIC) { //need to be active to process pair
p_body->set_active(true);
+ }
}
AreaPair2DSW::~AreaPair2DSW() {
if (colliding) {
- if (area->get_space_override_mode() != PhysicsServer2D::AREA_SPACE_OVERRIDE_DISABLED)
+ if (area->get_space_override_mode() != PhysicsServer2D::AREA_SPACE_OVERRIDE_DISABLED) {
body->remove_area(area);
- if (area->has_monitor_callback())
+ }
+ if (area->has_monitor_callback()) {
area->remove_body_from_query(body, body_shape, area_shape);
+ }
}
body->remove_constraint(this);
area->remove_constraint(this);
@@ -98,18 +105,22 @@ bool Area2Pair2DSW::setup(real_t p_step) {
if (result != colliding) {
if (result) {
- if (area_b->has_area_monitor_callback() && area_a->is_monitorable())
+ if (area_b->has_area_monitor_callback() && area_a->is_monitorable()) {
area_b->add_area_to_query(area_a, shape_a, shape_b);
+ }
- if (area_a->has_area_monitor_callback() && area_b->is_monitorable())
+ if (area_a->has_area_monitor_callback() && area_b->is_monitorable()) {
area_a->add_area_to_query(area_b, shape_b, shape_a);
+ }
} else {
- if (area_b->has_area_monitor_callback() && area_a->is_monitorable())
+ if (area_b->has_area_monitor_callback() && area_a->is_monitorable()) {
area_b->remove_area_from_query(area_a, shape_a, shape_b);
+ }
- if (area_a->has_area_monitor_callback() && area_b->is_monitorable())
+ if (area_a->has_area_monitor_callback() && area_b->is_monitorable()) {
area_a->remove_area_from_query(area_b, shape_b, shape_a);
+ }
}
colliding = result;
@@ -133,11 +144,13 @@ Area2Pair2DSW::Area2Pair2DSW(Area2DSW *p_area_a, int p_shape_a, Area2DSW *p_area
Area2Pair2DSW::~Area2Pair2DSW() {
if (colliding) {
- if (area_b->has_area_monitor_callback())
+ if (area_b->has_area_monitor_callback()) {
area_b->remove_area_from_query(area_a, shape_a, shape_b);
+ }
- if (area_a->has_area_monitor_callback())
+ if (area_a->has_area_monitor_callback()) {
area_a->remove_area_from_query(area_b, shape_b, shape_a);
+ }
}
area_a->remove_constraint(this);
diff --git a/servers/physics_2d/body_2d_sw.cpp b/servers/physics_2d/body_2d_sw.cpp
index 498972f538..856bba78f7 100644
--- a/servers/physics_2d/body_2d_sw.cpp
+++ b/servers/physics_2d/body_2d_sw.cpp
@@ -34,8 +34,9 @@
#include "space_2d_sw.h"
void Body2DSW::_update_inertia() {
- if (!user_inertia && get_space() && !inertia_update_list.in_list())
+ if (!user_inertia && get_space() && !inertia_update_list.in_list()) {
get_space()->body_add_to_inertia_update_list(&inertia_update_list);
+ }
}
void Body2DSW::update_inertias() {
@@ -74,10 +75,11 @@ void Body2DSW::update_inertias() {
_inv_inertia = inertia > 0 ? (1.0 / inertia) : 0;
- if (mass)
+ if (mass) {
_inv_mass = 1.0 / mass;
- else
+ } else {
_inv_mass = 0;
+ }
} break;
case PhysicsServer2D::BODY_MODE_KINEMATIC:
@@ -97,18 +99,22 @@ void Body2DSW::update_inertias() {
}
void Body2DSW::set_active(bool p_active) {
- if (active == p_active)
+ if (active == p_active) {
return;
+ }
active = p_active;
if (!p_active) {
- if (get_space())
+ if (get_space()) {
get_space()->body_remove_from_active_list(&active_list);
+ }
} else {
- if (mode == PhysicsServer2D::BODY_MODE_STATIC)
+ if (mode == PhysicsServer2D::BODY_MODE_STATIC) {
return; //static bodies can't become active
- if (get_space())
+ }
+ if (get_space()) {
get_space()->body_add_to_active_list(&active_list);
+ }
//still_time=0;
}
@@ -265,8 +271,9 @@ void Body2DSW::set_state(PhysicsServer2D::BodyState p_state, const Variant &p_va
Transform2D t = p_variant;
t.orthonormalize();
new_transform = get_transform(); //used as old to compute motion
- if (t == new_transform)
+ if (t == new_transform) {
break;
+ }
_set_transform(t);
_set_inv_transform(get_transform().inverse());
}
@@ -293,8 +300,9 @@ void Body2DSW::set_state(PhysicsServer2D::BodyState p_state, const Variant &p_va
} break;
case PhysicsServer2D::BODY_STATE_SLEEPING: {
//?
- if (mode == PhysicsServer2D::BODY_MODE_STATIC || mode == PhysicsServer2D::BODY_MODE_KINEMATIC)
+ if (mode == PhysicsServer2D::BODY_MODE_STATIC || mode == PhysicsServer2D::BODY_MODE_KINEMATIC) {
break;
+ }
bool do_sleep = p_variant;
if (do_sleep) {
linear_velocity = Vector2();
@@ -303,14 +311,16 @@ void Body2DSW::set_state(PhysicsServer2D::BodyState p_state, const Variant &p_va
//biased_angular_velocity=Vector3();
set_active(false);
} else {
- if (mode != PhysicsServer2D::BODY_MODE_STATIC)
+ if (mode != PhysicsServer2D::BODY_MODE_STATIC) {
set_active(true);
+ }
}
} break;
case PhysicsServer2D::BODY_STATE_CAN_SLEEP: {
can_sleep = p_variant;
- if (mode == PhysicsServer2D::BODY_MODE_RIGID && !active && !can_sleep)
+ if (mode == PhysicsServer2D::BODY_MODE_RIGID && !active && !can_sleep) {
set_active(true);
+ }
} break;
}
@@ -342,20 +352,24 @@ void Body2DSW::set_space(Space2DSW *p_space) {
if (get_space()) {
wakeup_neighbours();
- if (inertia_update_list.in_list())
+ if (inertia_update_list.in_list()) {
get_space()->body_remove_from_inertia_update_list(&inertia_update_list);
- if (active_list.in_list())
+ }
+ if (active_list.in_list()) {
get_space()->body_remove_from_active_list(&active_list);
- if (direct_state_query_list.in_list())
+ }
+ if (direct_state_query_list.in_list()) {
get_space()->body_remove_from_state_query_list(&direct_state_query_list);
+ }
}
_set_space(p_space);
if (get_space()) {
_update_inertia();
- if (active)
+ if (active) {
get_space()->body_add_to_active_list(&active_list);
+ }
/*
_update_queries();
if (is_active()) {
@@ -385,8 +399,9 @@ void Body2DSW::_compute_area_gravity_and_dampenings(const Area2DSW *p_area) {
}
void Body2DSW::integrate_forces(real_t p_step) {
- if (mode == PhysicsServer2D::BODY_MODE_STATIC)
+ if (mode == PhysicsServer2D::BODY_MODE_STATIC) {
return;
+ }
Area2DSW *def_area = get_space()->get_default_area();
// Area2DSW *damp_area = def_area;
@@ -428,15 +443,17 @@ void Body2DSW::integrate_forces(real_t p_step) {
gravity *= gravity_scale;
// If less than 0, override dampenings with that of the Body2D
- if (angular_damp >= 0)
+ if (angular_damp >= 0) {
area_angular_damp = angular_damp;
+ }
/*
else
area_angular_damp=damp_area->get_angular_damp();
*/
- if (linear_damp >= 0)
+ if (linear_damp >= 0) {
area_linear_damp = linear_damp;
+ }
/*
else
area_linear_damp=damp_area->get_linear_damp();
@@ -472,13 +489,15 @@ void Body2DSW::integrate_forces(real_t p_step) {
real_t damp = 1.0 - p_step * area_linear_damp;
- if (damp < 0) // reached zero in the given time
+ if (damp < 0) { // reached zero in the given time
damp = 0;
+ }
real_t angular_damp = 1.0 - p_step * area_angular_damp;
- if (angular_damp < 0) // reached zero in the given time
+ if (angular_damp < 0) { // reached zero in the given time
angular_damp = 0;
+ }
linear_velocity *= damp;
angular_velocity *= angular_damp;
@@ -509,17 +528,20 @@ void Body2DSW::integrate_forces(real_t p_step) {
}
void Body2DSW::integrate_velocities(real_t p_step) {
- if (mode == PhysicsServer2D::BODY_MODE_STATIC)
+ if (mode == PhysicsServer2D::BODY_MODE_STATIC) {
return;
+ }
- if (fi_callback)
+ if (fi_callback) {
get_space()->body_add_to_state_query_list(&direct_state_query_list);
+ }
if (mode == PhysicsServer2D::BODY_MODE_KINEMATIC) {
_set_transform(new_transform, false);
_set_inv_transform(new_transform.affine_inverse());
- if (contacts.size() == 0 && linear_velocity == Vector2() && angular_velocity == 0)
+ if (contacts.size() == 0 && linear_velocity == Vector2() && angular_velocity == 0) {
set_active(false); //stopped moving, deactivate
+ }
return;
}
@@ -532,8 +554,9 @@ void Body2DSW::integrate_velocities(real_t p_step) {
_set_transform(Transform2D(angle, pos), continuous_cd_mode == PhysicsServer2D::CCD_MODE_DISABLED);
_set_inv_transform(get_transform().inverse());
- if (continuous_cd_mode != PhysicsServer2D::CCD_MODE_DISABLED)
+ if (continuous_cd_mode != PhysicsServer2D::CCD_MODE_DISABLED) {
new_transform = get_transform();
+ }
//_update_inertia_tensor();
}
@@ -545,14 +568,17 @@ void Body2DSW::wakeup_neighbours() {
int bc = c->get_body_count();
for (int i = 0; i < bc; i++) {
- if (i == E->get())
+ if (i == E->get()) {
continue;
+ }
Body2DSW *b = n[i];
- if (b->mode != PhysicsServer2D::BODY_MODE_RIGID)
+ if (b->mode != PhysicsServer2D::BODY_MODE_RIGID) {
continue;
+ }
- if (!b->is_active())
+ if (!b->is_active()) {
b->set_active(true);
+ }
}
}
}
@@ -581,12 +607,13 @@ void Body2DSW::call_queries() {
}
bool Body2DSW::sleep_test(real_t p_step) {
- if (mode == PhysicsServer2D::BODY_MODE_STATIC || mode == PhysicsServer2D::BODY_MODE_KINEMATIC)
+ if (mode == PhysicsServer2D::BODY_MODE_STATIC || mode == PhysicsServer2D::BODY_MODE_KINEMATIC) {
return true; //
- else if (mode == PhysicsServer2D::BODY_MODE_CHARACTER)
+ } else if (mode == PhysicsServer2D::BODY_MODE_CHARACTER) {
return !active; // characters and kinematic bodies don't sleep unless asked to sleep
- else if (!can_sleep)
+ } else if (!can_sleep) {
return false;
+ }
if (Math::abs(angular_velocity) < get_space()->get_body_angular_velocity_sleep_threshold() && Math::abs(linear_velocity.length_squared()) < get_space()->get_body_linear_velocity_sleep_threshold() * get_space()->get_body_linear_velocity_sleep_threshold()) {
still_time += p_step;
@@ -650,8 +677,9 @@ Body2DSW::Body2DSW() :
}
Body2DSW::~Body2DSW() {
- if (fi_callback)
+ if (fi_callback) {
memdelete(fi_callback);
+ }
}
PhysicsDirectBodyState2DSW *PhysicsDirectBodyState2DSW::singleton = nullptr;
diff --git a/servers/physics_2d/body_2d_sw.h b/servers/physics_2d/body_2d_sw.h
index c1fc4e2bb5..2300c9cdee 100644
--- a/servers/physics_2d/body_2d_sw.h
+++ b/servers/physics_2d/body_2d_sw.h
@@ -146,16 +146,18 @@ public:
int index = areas.find(AreaCMP(p_area));
if (index > -1) {
areas.write[index].refCount -= 1;
- if (areas[index].refCount < 1)
+ if (areas[index].refCount < 1) {
areas.remove(index);
+ }
}
}
_FORCE_INLINE_ void set_max_contacts_reported(int p_size) {
contacts.resize(p_size);
contact_count = 0;
- if (mode == PhysicsServer2D::BODY_MODE_KINEMATIC && p_size)
+ if (mode == PhysicsServer2D::BODY_MODE_KINEMATIC && p_size) {
set_active(true);
+ }
}
_FORCE_INLINE_ int get_max_contacts_reported() const { return contacts.size(); }
@@ -219,8 +221,9 @@ public:
_FORCE_INLINE_ bool is_active() const { return active; }
_FORCE_INLINE_ void wakeup() {
- if ((!get_space()) || mode == PhysicsServer2D::BODY_MODE_STATIC || mode == PhysicsServer2D::BODY_MODE_KINEMATIC)
+ if ((!get_space()) || mode == PhysicsServer2D::BODY_MODE_STATIC || mode == PhysicsServer2D::BODY_MODE_KINEMATIC) {
return;
+ }
set_active(true);
}
@@ -293,8 +296,9 @@ public:
void Body2DSW::add_contact(const Vector2 &p_local_pos, const Vector2 &p_local_normal, real_t p_depth, int p_local_shape, const Vector2 &p_collider_pos, int p_collider_shape, ObjectID p_collider_instance_id, const RID &p_collider, const Vector2 &p_collider_velocity_at_pos) {
int c_max = contacts.size();
- if (c_max == 0)
+ if (c_max == 0) {
return;
+ }
Contact *c = contacts.ptrw();
@@ -315,8 +319,9 @@ void Body2DSW::add_contact(const Vector2 &p_local_pos, const Vector2 &p_local_no
if (least_deep >= 0 && least_depth < p_depth) {
idx = least_deep;
}
- if (idx == -1)
+ if (idx == -1) {
return; //none least deepe than this
+ }
}
c[idx].local_pos = p_local_pos;
diff --git a/servers/physics_2d/body_pair_2d_sw.cpp b/servers/physics_2d/body_pair_2d_sw.cpp
index 32a3dd2504..e483ddf1cc 100644
--- a/servers/physics_2d/body_pair_2d_sw.cpp
+++ b/servers/physics_2d/body_pair_2d_sw.cpp
@@ -161,8 +161,9 @@ void BodyPair2DSW::_validate_contacts() {
bool BodyPair2DSW::_test_ccd(real_t p_step, Body2DSW *p_A, int p_shape_A, const Transform2D &p_xform_A, Body2DSW *p_B, int p_shape_B, const Transform2D &p_xform_B, bool p_swap_result) {
Vector2 motion = p_A->get_linear_velocity() * p_step;
real_t mlen = motion.length();
- if (mlen < CMP_EPSILON)
+ if (mlen < CMP_EPSILON) {
return false;
+ }
Vector2 mnormal = motion / mlen;
@@ -188,8 +189,9 @@ bool BodyPair2DSW::_test_ccd(real_t p_step, Body2DSW *p_A, int p_shape_A, const
Vector2 local_to = from_inv.xform(to);
Vector2 rpos, rnorm;
- if (!p_B->get_shape(p_shape_B)->intersect_segment(local_from, local_to, rpos, rnorm))
+ if (!p_B->get_shape(p_shape_B)->intersect_segment(local_from, local_to, rpos, rnorm)) {
return false;
+ }
//ray hit something
@@ -200,10 +202,11 @@ bool BodyPair2DSW::_test_ccd(real_t p_step, Body2DSW *p_A, int p_shape_A, const
//create a contact
- if (p_swap_result)
+ if (p_swap_result) {
_contact_added_callback(contact_B, contact_A);
- else
+ } else {
_contact_added_callback(contact_A, contact_B);
+ }
return true;
}
@@ -261,13 +264,15 @@ bool BodyPair2DSW::setup(real_t p_step) {
//test ccd (currently just a raycast)
if (A->get_continuous_collision_detection_mode() == PhysicsServer2D::CCD_MODE_CAST_RAY && A->get_mode() > PhysicsServer2D::BODY_MODE_KINEMATIC) {
- if (_test_ccd(p_step, A, shape_A, xform_A, B, shape_B, xform_B))
+ if (_test_ccd(p_step, A, shape_A, xform_A, B, shape_B, xform_B)) {
collided = true;
+ }
}
if (B->get_continuous_collision_detection_mode() == PhysicsServer2D::CCD_MODE_CAST_RAY && B->get_mode() > PhysicsServer2D::BODY_MODE_KINEMATIC) {
- if (_test_ccd(p_step, B, shape_B, xform_B, A, shape_A, xform_A, true))
+ if (_test_ccd(p_step, B, shape_B, xform_B, A, shape_A, xform_A, true)) {
collided = true;
+ }
}
if (!collided) {
@@ -276,8 +281,9 @@ bool BodyPair2DSW::setup(real_t p_step) {
}
}
- if (oneway_disabled)
+ if (oneway_disabled) {
return false;
+ }
//if (!prev_collided) {
{
@@ -287,10 +293,12 @@ bool BodyPair2DSW::setup(real_t p_step) {
if (B->get_linear_velocity().dot(direction) >= 0) {
for (int i = 0; i < contact_count; i++) {
Contact &c = contacts[i];
- if (!c.reused)
+ if (!c.reused) {
continue;
- if (c.normal.dot(direction) > 0) //greater (normal inverted)
+ }
+ if (c.normal.dot(direction) > 0) { //greater (normal inverted)
continue;
+ }
valid = true;
break;
@@ -310,10 +318,12 @@ bool BodyPair2DSW::setup(real_t p_step) {
if (A->get_linear_velocity().dot(direction) >= 0) {
for (int i = 0; i < contact_count; i++) {
Contact &c = contacts[i];
- if (!c.reused)
+ if (!c.reused) {
continue;
- if (c.normal.dot(direction) < 0) //less (normal ok)
+ }
+ if (c.normal.dot(direction) < 0) { //less (normal ok)
continue;
+ }
valid = true;
break;
@@ -331,12 +341,13 @@ bool BodyPair2DSW::setup(real_t p_step) {
real_t bias = 0.3;
if (shape_A_ptr->get_custom_bias() || shape_B_ptr->get_custom_bias()) {
- if (shape_A_ptr->get_custom_bias() == 0)
+ if (shape_A_ptr->get_custom_bias() == 0) {
bias = shape_B_ptr->get_custom_bias();
- else if (shape_B_ptr->get_custom_bias() == 0)
+ } else if (shape_B_ptr->get_custom_bias() == 0) {
bias = shape_A_ptr->get_custom_bias();
- else
+ } else {
bias = (shape_B_ptr->get_custom_bias() + shape_A_ptr->get_custom_bias()) * 0.5;
+ }
}
cc = 0;
@@ -437,15 +448,17 @@ bool BodyPair2DSW::setup(real_t p_step) {
}
void BodyPair2DSW::solve(real_t p_step) {
- if (!collided)
+ if (!collided) {
return;
+ }
for (int i = 0; i < contact_count; ++i) {
Contact &c = contacts[i];
cc++;
- if (!c.active)
+ if (!c.active) {
continue;
+ }
// Relative velocity at contact
diff --git a/servers/physics_2d/broad_phase_2d_basic.cpp b/servers/physics_2d/broad_phase_2d_basic.cpp
index a6bcae11e9..8c7e715a09 100644
--- a/servers/physics_2d/broad_phase_2d_basic.cpp
+++ b/servers/physics_2d/broad_phase_2d_basic.cpp
@@ -87,8 +87,9 @@ int BroadPhase2DBasic::cull_segment(const Vector2 &p_from, const Vector2 &p_to,
p_results[rc] = E->get().owner;
p_result_indices[rc] = E->get().subindex;
rc++;
- if (rc >= p_max_results)
+ if (rc >= p_max_results) {
break;
+ }
}
}
@@ -104,8 +105,9 @@ int BroadPhase2DBasic::cull_aabb(const Rect2 &p_aabb, CollisionObject2DSW **p_re
p_results[rc] = E->get().owner;
p_result_indices[rc] = E->get().subindex;
rc++;
- if (rc >= p_max_results)
+ if (rc >= p_max_results) {
break;
+ }
}
}
@@ -129,8 +131,9 @@ void BroadPhase2DBasic::update() {
Element *elem_A = &I->get();
Element *elem_B = &J->get();
- if (elem_A->owner == elem_B->owner)
+ if (elem_A->owner == elem_B->owner) {
continue;
+ }
bool pair_ok = elem_A->aabb.intersects(elem_B->aabb) && (!elem_A->_static || !elem_B->_static);
@@ -139,15 +142,17 @@ void BroadPhase2DBasic::update() {
Map<PairKey, void *>::Element *E = pair_map.find(key);
if (!pair_ok && E) {
- if (unpair_callback)
+ if (unpair_callback) {
unpair_callback(elem_A->owner, elem_A->subindex, elem_B->owner, elem_B->subindex, E->get(), unpair_userdata);
+ }
pair_map.erase(key);
}
if (pair_ok && !E) {
void *data = nullptr;
- if (pair_callback)
+ if (pair_callback) {
data = pair_callback(elem_A->owner, elem_A->subindex, elem_B->owner, elem_B->subindex, unpair_userdata);
+ }
pair_map.insert(key, data);
}
}
diff --git a/servers/physics_2d/broad_phase_2d_hash_grid.cpp b/servers/physics_2d/broad_phase_2d_hash_grid.cpp
index e3a841366e..ae549ed2e4 100644
--- a/servers/physics_2d/broad_phase_2d_hash_grid.cpp
+++ b/servers/physics_2d/broad_phase_2d_hash_grid.cpp
@@ -93,12 +93,15 @@ void BroadPhase2DHashGrid::_enter_grid(Element *p_elem, const Rect2 &p_rect, boo
if (sz.width * sz.height > large_object_min_surface) {
//large object, do not use grid, must check against all elements
for (Map<ID, Element>::Element *E = element_map.front(); E; E = E->next()) {
- if (E->key() == p_elem->self)
+ if (E->key() == p_elem->self) {
continue; // do not pair against itself
- if (E->get().owner == p_elem->owner)
+ }
+ if (E->get().owner == p_elem->owner) {
continue;
- if (E->get()._static && p_static)
+ }
+ if (E->get()._static && p_static) {
continue;
+ }
_pair_attempt(p_elem, &E->get());
}
@@ -149,15 +152,17 @@ void BroadPhase2DHashGrid::_enter_grid(Element *p_elem, const Rect2 &p_rect, boo
if (entered) {
for (Map<Element *, RC>::Element *E = pb->object_set.front(); E; E = E->next()) {
- if (E->key()->owner == p_elem->owner)
+ if (E->key()->owner == p_elem->owner) {
continue;
+ }
_pair_attempt(p_elem, E->key());
}
if (!p_static) {
for (Map<Element *, RC>::Element *E = pb->static_object_set.front(); E; E = E->next()) {
- if (E->key()->owner == p_elem->owner)
+ if (E->key()->owner == p_elem->owner) {
continue;
+ }
_pair_attempt(p_elem, E->key());
}
}
@@ -168,12 +173,15 @@ void BroadPhase2DHashGrid::_enter_grid(Element *p_elem, const Rect2 &p_rect, boo
//pair separatedly with large elements
for (Map<Element *, RC>::Element *E = large_elements.front(); E; E = E->next()) {
- if (E->key() == p_elem)
+ if (E->key() == p_elem) {
continue; // do not pair against itself
- if (E->key()->owner == p_elem->owner)
+ }
+ if (E->key()->owner == p_elem->owner) {
continue;
- if (E->key()->_static && p_static)
+ }
+ if (E->key()->_static && p_static) {
continue;
+ }
_pair_attempt(E->key(), p_elem);
}
@@ -234,15 +242,17 @@ void BroadPhase2DHashGrid::_exit_grid(Element *p_elem, const Rect2 &p_rect, bool
if (exited) {
for (Map<Element *, RC>::Element *E = pb->object_set.front(); E; E = E->next()) {
- if (E->key()->owner == p_elem->owner)
+ if (E->key()->owner == p_elem->owner) {
continue;
+ }
_unpair_attempt(p_elem, E->key());
}
if (!p_static) {
for (Map<Element *, RC>::Element *E = pb->static_object_set.front(); E; E = E->next()) {
- if (E->key()->owner == p_elem->owner)
+ if (E->key()->owner == p_elem->owner) {
continue;
+ }
_unpair_attempt(p_elem, E->key());
}
}
@@ -272,12 +282,15 @@ void BroadPhase2DHashGrid::_exit_grid(Element *p_elem, const Rect2 &p_rect, bool
}
for (Map<Element *, RC>::Element *E = large_elements.front(); E; E = E->next()) {
- if (E->key() == p_elem)
+ if (E->key() == p_elem) {
continue; // do not pair against itself
- if (E->key()->owner == p_elem->owner)
+ }
+ if (E->key()->owner == p_elem->owner) {
continue;
- if (E->key()->_static && p_static)
+ }
+ if (E->key()->_static && p_static) {
continue;
+ }
//unpair from large elements
_unpair_attempt(p_elem, E->key());
@@ -304,8 +317,9 @@ void BroadPhase2DHashGrid::move(ID p_id, const Rect2 &p_aabb) {
Element &e = E->get();
- if (p_aabb == e.aabb)
+ if (p_aabb == e.aabb) {
return;
+ }
if (p_aabb != Rect2()) {
_enter_grid(&e, p_aabb, e._static);
@@ -328,11 +342,13 @@ void BroadPhase2DHashGrid::set_static(ID p_id, bool p_static) {
Element &e = E->get();
- if (e._static == p_static)
+ if (e._static == p_static) {
return;
+ }
- if (e.aabb != Rect2())
+ if (e.aabb != Rect2()) {
_exit_grid(&e, e.aabb, e._static);
+ }
e._static = p_static;
@@ -348,8 +364,9 @@ void BroadPhase2DHashGrid::remove(ID p_id) {
Element &e = E->get();
- if (e.aabb != Rect2())
+ if (e.aabb != Rect2()) {
_exit_grid(&e, e.aabb, e._static);
+ }
element_map.erase(p_id);
}
@@ -389,22 +406,27 @@ void BroadPhase2DHashGrid::_cull(const Point2i p_cell, const Rect2 &p_aabb, cons
pb = pb->next;
}
- if (!pb)
+ if (!pb) {
return;
+ }
for (Map<Element *, RC>::Element *E = pb->object_set.front(); E; E = E->next()) {
- if (index >= p_max_results)
+ if (index >= p_max_results) {
break;
- if (E->key()->pass == pass)
+ }
+ if (E->key()->pass == pass) {
continue;
+ }
E->key()->pass = pass;
- if (use_aabb && !p_aabb.intersects(E->key()->aabb))
+ if (use_aabb && !p_aabb.intersects(E->key()->aabb)) {
continue;
+ }
- if (use_segment && !E->key()->aabb.intersects_segment(p_from, p_to))
+ if (use_segment && !E->key()->aabb.intersects_segment(p_from, p_to)) {
continue;
+ }
p_results[index] = E->key()->owner;
p_result_indices[index] = E->key()->subindex;
@@ -412,17 +434,20 @@ void BroadPhase2DHashGrid::_cull(const Point2i p_cell, const Rect2 &p_aabb, cons
}
for (Map<Element *, RC>::Element *E = pb->static_object_set.front(); E; E = E->next()) {
- if (index >= p_max_results)
+ if (index >= p_max_results) {
break;
- if (E->key()->pass == pass)
+ }
+ if (E->key()->pass == pass) {
continue;
+ }
if (use_aabb && !p_aabb.intersects(E->key()->aabb)) {
continue;
}
- if (use_segment && !E->key()->aabb.intersects_segment(p_from, p_to))
+ if (use_segment && !E->key()->aabb.intersects_segment(p_from, p_to)) {
continue;
+ }
E->key()->pass = pass;
p_results[index] = E->key()->owner;
@@ -435,14 +460,17 @@ int BroadPhase2DHashGrid::cull_segment(const Vector2 &p_from, const Vector2 &p_t
pass++;
Vector2 dir = (p_to - p_from);
- if (dir == Vector2())
+ if (dir == Vector2()) {
return 0;
+ }
//avoid divisions by zero
dir.normalize();
- if (dir.x == 0.0)
+ if (dir.x == 0.0) {
dir.x = 0.000001;
- if (dir.y == 0.0)
+ }
+ if (dir.y == 0.0) {
dir.y = 0.000001;
+ }
Vector2 delta = dir.abs();
delta.x = cell_size / delta.x;
@@ -455,15 +483,17 @@ int BroadPhase2DHashGrid::cull_segment(const Vector2 &p_from, const Vector2 &p_t
Vector2 max;
- if (dir.x < 0)
+ if (dir.x < 0) {
max.x = (Math::floor((double)pos.x) * cell_size - p_from.x) / dir.x;
- else
+ } else {
max.x = (Math::floor((double)pos.x + 1) * cell_size - p_from.x) / dir.x;
+ }
- if (dir.y < 0)
+ if (dir.y < 0) {
max.y = (Math::floor((double)pos.y) * cell_size - p_from.y) / dir.y;
- else
+ } else {
max.y = (Math::floor((double)pos.y + 1) * cell_size - p_from.y) / dir.y;
+ }
int cullcount = 0;
_cull<false, true>(pos, Rect2(), p_from, p_to, p_results, p_max_results, p_result_indices, cullcount);
@@ -481,30 +511,35 @@ int BroadPhase2DHashGrid::cull_segment(const Vector2 &p_from, const Vector2 &p_t
}
if (step.x > 0) {
- if (pos.x >= end.x)
+ if (pos.x >= end.x) {
reached_x = true;
+ }
} else if (pos.x <= end.x) {
reached_x = true;
}
if (step.y > 0) {
- if (pos.y >= end.y)
+ if (pos.y >= end.y) {
reached_y = true;
+ }
} else if (pos.y <= end.y) {
reached_y = true;
}
_cull<false, true>(pos, Rect2(), p_from, p_to, p_results, p_max_results, p_result_indices, cullcount);
- if (reached_x && reached_y)
+ if (reached_x && reached_y) {
break;
+ }
}
for (Map<Element *, RC>::Element *E = large_elements.front(); E; E = E->next()) {
- if (cullcount >= p_max_results)
+ if (cullcount >= p_max_results) {
break;
- if (E->key()->pass == pass)
+ }
+ if (E->key()->pass == pass) {
continue;
+ }
E->key()->pass = pass;
@@ -513,8 +548,9 @@ int BroadPhase2DHashGrid::cull_segment(const Vector2 &p_from, const Vector2 &p_t
continue;
*/
- if (!E->key()->aabb.intersects_segment(p_from, p_to))
+ if (!E->key()->aabb.intersects_segment(p_from, p_to)) {
continue;
+ }
p_results[cullcount] = E->key()->owner;
p_result_indices[cullcount] = E->key()->subindex;
@@ -538,15 +574,18 @@ int BroadPhase2DHashGrid::cull_aabb(const Rect2 &p_aabb, CollisionObject2DSW **p
}
for (Map<Element *, RC>::Element *E = large_elements.front(); E; E = E->next()) {
- if (cullcount >= p_max_results)
+ if (cullcount >= p_max_results) {
break;
- if (E->key()->pass == pass)
+ }
+ if (E->key()->pass == pass) {
continue;
+ }
E->key()->pass = pass;
- if (!p_aabb.intersects(E->key()->aabb))
+ if (!p_aabb.intersects(E->key()->aabb)) {
continue;
+ }
/*
if (!E->key()->aabb.intersects_segment(p_from,p_to))
@@ -589,8 +628,9 @@ BroadPhase2DHashGrid::BroadPhase2DHashGrid() {
large_object_min_surface = GLOBAL_DEF("physics/2d/large_object_surface_threshold_in_cells", 512);
ProjectSettings::get_singleton()->set_custom_property_info("physics/2d/large_object_surface_threshold_in_cells", PropertyInfo(Variant::INT, "physics/2d/large_object_surface_threshold_in_cells", PROPERTY_HINT_RANGE, "0,1024,1,or_greater"));
- for (uint32_t i = 0; i < hash_table_size; i++)
+ for (uint32_t i = 0; i < hash_table_size; i++) {
hash_table[i] = nullptr;
+ }
pass = 1;
current = 0;
diff --git a/servers/physics_2d/collision_object_2d_sw.cpp b/servers/physics_2d/collision_object_2d_sw.cpp
index 696100ccc3..6931d96fe4 100644
--- a/servers/physics_2d/collision_object_2d_sw.cpp
+++ b/servers/physics_2d/collision_object_2d_sw.cpp
@@ -87,13 +87,15 @@ void CollisionObject2DSW::set_shape_as_disabled(int p_idx, bool p_disabled) {
ERR_FAIL_INDEX(p_idx, shapes.size());
CollisionObject2DSW::Shape &shape = shapes.write[p_idx];
- if (shape.disabled == p_disabled)
+ if (shape.disabled == p_disabled) {
return;
+ }
shape.disabled = p_disabled;
- if (!space)
+ if (!space) {
return;
+ }
if (p_disabled && shape.bpid != 0) {
space->get_broadphase()->remove(shape.bpid);
@@ -124,8 +126,9 @@ void CollisionObject2DSW::remove_shape(int p_index) {
//remove anything from shape to be erased to end, so subindices don't change
ERR_FAIL_INDEX(p_index, shapes.size());
for (int i = p_index; i < shapes.size(); i++) {
- if (shapes[i].bpid == 0)
+ if (shapes[i].bpid == 0) {
continue;
+ }
//should never get here with a null owner
space->get_broadphase()->remove(shapes[i].bpid);
shapes.write[i].bpid = 0;
@@ -141,12 +144,14 @@ void CollisionObject2DSW::remove_shape(int p_index) {
}
void CollisionObject2DSW::_set_static(bool p_static) {
- if (_static == p_static)
+ if (_static == p_static) {
return;
+ }
_static = p_static;
- if (!space)
+ if (!space) {
return;
+ }
for (int i = 0; i < get_shape_count(); i++) {
const Shape &s = shapes[i];
if (s.bpid > 0) {
@@ -166,14 +171,16 @@ void CollisionObject2DSW::_unregister_shapes() {
}
void CollisionObject2DSW::_update_shapes() {
- if (!space)
+ if (!space) {
return;
+ }
for (int i = 0; i < shapes.size(); i++) {
Shape &s = shapes.write[i];
- if (s.disabled)
+ if (s.disabled) {
continue;
+ }
if (s.bpid == 0) {
s.bpid = space->get_broadphase()->create(this, i);
@@ -192,13 +199,15 @@ void CollisionObject2DSW::_update_shapes() {
}
void CollisionObject2DSW::_update_shapes_with_motion(const Vector2 &p_motion) {
- if (!space)
+ if (!space) {
return;
+ }
for (int i = 0; i < shapes.size(); i++) {
Shape &s = shapes.write[i];
- if (s.disabled)
+ if (s.disabled) {
continue;
+ }
if (s.bpid == 0) {
s.bpid = space->get_broadphase()->create(this, i);
diff --git a/servers/physics_2d/collision_solver_2d_sat.cpp b/servers/physics_2d/collision_solver_2d_sat.cpp
index 58cba28fe1..2cada2bf50 100644
--- a/servers/physics_2d/collision_solver_2d_sat.cpp
+++ b/servers/physics_2d/collision_solver_2d_sat.cpp
@@ -45,10 +45,11 @@ struct _CollectorCallback2D {
if (normal.dot(p_point_A) >= normal.dot(p_point_B))
return;
*/
- if (swap)
+ if (swap) {
callback(p_point_B, p_point_A, userdata);
- else
+ } else {
callback(p_point_A, p_point_B, userdata);
+ }
}
};
@@ -113,14 +114,16 @@ _FORCE_INLINE_ static void _generate_contacts_edge_edge(const Vector2 *p_points_
if (dvec[i].a) {
Vector2 a = p_points_A[dvec[i].idx];
Vector2 b = n.plane_project(dB, a);
- if (n.dot(a) > n.dot(b) - CMP_EPSILON)
+ if (n.dot(a) > n.dot(b) - CMP_EPSILON) {
continue;
+ }
p_collector->call(a, b);
} else {
Vector2 b = p_points_B[dvec[i].idx];
Vector2 a = n.plane_project(dA, b);
- if (n.dot(a) > n.dot(b) - CMP_EPSILON)
+ if (n.dot(a) > n.dot(b) - CMP_EPSILON) {
continue;
+ }
p_collector->call(a, b);
}
}
@@ -203,18 +206,22 @@ public:
_FORCE_INLINE_ bool test_cast() {
if (castA) {
Vector2 na = motion_A.normalized();
- if (!test_axis(na))
+ if (!test_axis(na)) {
return false;
- if (!test_axis(na.tangent()))
+ }
+ if (!test_axis(na.tangent())) {
return false;
+ }
}
if (castB) {
Vector2 nb = motion_B.normalized();
- if (!test_axis(nb))
+ if (!test_axis(nb)) {
return false;
- if (!test_axis(nb.tangent()))
+ }
+ if (!test_axis(nb.tangent())) {
return false;
+ }
}
return true;
@@ -231,15 +238,17 @@ public:
real_t min_A, max_A, min_B, max_B;
- if (castA)
+ if (castA) {
shape_A->project_range_cast(motion_A, axis, *transform_A, min_A, max_A);
- else
+ } else {
shape_A->project_range(axis, *transform_A, min_A, max_A);
+ }
- if (castB)
+ if (castB) {
shape_B->project_range_cast(motion_B, axis, *transform_B, min_B, max_B);
- else
+ } else {
shape_B->project_range(axis, *transform_B, min_B, max_B);
+ }
if (withMargin) {
min_A -= margin_A;
@@ -255,8 +264,9 @@ public:
real_t dmax = max_B - (min_A + max_A) * 0.5;
if (dmin > 0.0 || dmax < 0.0) {
- if (callback && callback->sep_axis)
+ if (callback && callback->sep_axis) {
*callback->sep_axis = axis;
+ }
#ifdef DEBUG_ENABLED
best_axis_count++;
#endif
@@ -295,14 +305,16 @@ public:
_FORCE_INLINE_ void generate_contacts() {
// nothing to do, don't generate
- if (best_axis == Vector2(0.0, 0.0))
+ if (best_axis == Vector2(0.0, 0.0)) {
return;
+ }
if (callback) {
callback->collided = true;
- if (!callback->callback)
+ if (!callback->callback) {
return; //only collide, no callback
+ }
}
static const int max_supports = 2;
@@ -343,8 +355,9 @@ public:
callback->normal = best_axis;
_generate_contacts_from_supports(supports_A, support_count_A, supports_B, support_count_B, callback);
- if (callback->sep_axis && *callback->sep_axis != Vector2())
+ if (callback->sep_axis && *callback->sep_axis != Vector2()) {
*callback->sep_axis = Vector2(); //invalidate previous axis (no test)
+ }
}
}
@@ -384,29 +397,37 @@ static void _collision_segment_segment(const Shape2DSW *p_a, const Transform2D &
SeparatorAxisTest2D<SegmentShape2DSW, SegmentShape2DSW, castA, castB, withMargin> separator(segment_A, p_transform_a, segment_B, p_transform_b, p_collector, p_motion_a, p_motion_b, p_margin_A, p_margin_B);
- if (!separator.test_previous_axis())
+ if (!separator.test_previous_axis()) {
return;
+ }
//this collision is kind of pointless
- if (!separator.test_cast())
+ if (!separator.test_cast()) {
return;
+ }
- if (!separator.test_axis(segment_A->get_xformed_normal(p_transform_a)))
+ if (!separator.test_axis(segment_A->get_xformed_normal(p_transform_a))) {
return;
- if (!separator.test_axis(segment_B->get_xformed_normal(p_transform_b)))
+ }
+ if (!separator.test_axis(segment_B->get_xformed_normal(p_transform_b))) {
return;
+ }
if (withMargin) {
//points grow to circles
- if (TEST_POINT(p_transform_a.xform(segment_A->get_a()), p_transform_b.xform(segment_B->get_a())))
+ if (TEST_POINT(p_transform_a.xform(segment_A->get_a()), p_transform_b.xform(segment_B->get_a()))) {
return;
- if (TEST_POINT(p_transform_a.xform(segment_A->get_a()), p_transform_b.xform(segment_B->get_b())))
+ }
+ if (TEST_POINT(p_transform_a.xform(segment_A->get_a()), p_transform_b.xform(segment_B->get_b()))) {
return;
- if (TEST_POINT(p_transform_a.xform(segment_A->get_b()), p_transform_b.xform(segment_B->get_a())))
+ }
+ if (TEST_POINT(p_transform_a.xform(segment_A->get_b()), p_transform_b.xform(segment_B->get_a()))) {
return;
- if (TEST_POINT(p_transform_a.xform(segment_A->get_b()), p_transform_b.xform(segment_B->get_b())))
+ }
+ if (TEST_POINT(p_transform_a.xform(segment_A->get_b()), p_transform_b.xform(segment_B->get_b()))) {
return;
+ }
}
separator.generate_contacts();
@@ -419,23 +440,28 @@ static void _collision_segment_circle(const Shape2DSW *p_a, const Transform2D &p
SeparatorAxisTest2D<SegmentShape2DSW, CircleShape2DSW, castA, castB, withMargin> separator(segment_A, p_transform_a, circle_B, p_transform_b, p_collector, p_motion_a, p_motion_b, p_margin_A, p_margin_B);
- if (!separator.test_previous_axis())
+ if (!separator.test_previous_axis()) {
return;
+ }
- if (!separator.test_cast())
+ if (!separator.test_cast()) {
return;
+ }
//segment normal
if (!separator.test_axis(
- (p_transform_a.xform(segment_A->get_b()) - p_transform_a.xform(segment_A->get_a())).normalized().tangent()))
+ (p_transform_a.xform(segment_A->get_b()) - p_transform_a.xform(segment_A->get_a())).normalized().tangent())) {
return;
+ }
//endpoint a vs circle
- if (TEST_POINT(p_transform_a.xform(segment_A->get_a()), p_transform_b.get_origin()))
+ if (TEST_POINT(p_transform_a.xform(segment_A->get_a()), p_transform_b.get_origin())) {
return;
+ }
//endpoint b vs circle
- if (TEST_POINT(p_transform_a.xform(segment_A->get_b()), p_transform_b.get_origin()))
+ if (TEST_POINT(p_transform_a.xform(segment_A->get_b()), p_transform_b.get_origin())) {
return;
+ }
separator.generate_contacts();
}
@@ -447,20 +473,25 @@ static void _collision_segment_rectangle(const Shape2DSW *p_a, const Transform2D
SeparatorAxisTest2D<SegmentShape2DSW, RectangleShape2DSW, castA, castB, withMargin> separator(segment_A, p_transform_a, rectangle_B, p_transform_b, p_collector, p_motion_a, p_motion_b, p_margin_A, p_margin_B);
- if (!separator.test_previous_axis())
+ if (!separator.test_previous_axis()) {
return;
+ }
- if (!separator.test_cast())
+ if (!separator.test_cast()) {
return;
+ }
- if (!separator.test_axis(segment_A->get_xformed_normal(p_transform_a)))
+ if (!separator.test_axis(segment_A->get_xformed_normal(p_transform_a))) {
return;
+ }
- if (!separator.test_axis(p_transform_b.elements[0].normalized()))
+ if (!separator.test_axis(p_transform_b.elements[0].normalized())) {
return;
+ }
- if (!separator.test_axis(p_transform_b.elements[1].normalized()))
+ if (!separator.test_axis(p_transform_b.elements[1].normalized())) {
return;
+ }
if (withMargin) {
Transform2D inv = p_transform_b.affine_inverse();
@@ -468,30 +499,38 @@ static void _collision_segment_rectangle(const Shape2DSW *p_a, const Transform2D
Vector2 a = p_transform_a.xform(segment_A->get_a());
Vector2 b = p_transform_a.xform(segment_A->get_b());
- if (!separator.test_axis(rectangle_B->get_circle_axis(p_transform_b, inv, a)))
+ if (!separator.test_axis(rectangle_B->get_circle_axis(p_transform_b, inv, a))) {
return;
- if (!separator.test_axis(rectangle_B->get_circle_axis(p_transform_b, inv, b)))
+ }
+ if (!separator.test_axis(rectangle_B->get_circle_axis(p_transform_b, inv, b))) {
return;
+ }
if (castA) {
- if (!separator.test_axis(rectangle_B->get_circle_axis(p_transform_b, inv, a + p_motion_a)))
+ if (!separator.test_axis(rectangle_B->get_circle_axis(p_transform_b, inv, a + p_motion_a))) {
return;
- if (!separator.test_axis(rectangle_B->get_circle_axis(p_transform_b, inv, b + p_motion_a)))
+ }
+ if (!separator.test_axis(rectangle_B->get_circle_axis(p_transform_b, inv, b + p_motion_a))) {
return;
+ }
}
if (castB) {
- if (!separator.test_axis(rectangle_B->get_circle_axis(p_transform_b, inv, a - p_motion_b)))
+ if (!separator.test_axis(rectangle_B->get_circle_axis(p_transform_b, inv, a - p_motion_b))) {
return;
- if (!separator.test_axis(rectangle_B->get_circle_axis(p_transform_b, inv, b - p_motion_b)))
+ }
+ if (!separator.test_axis(rectangle_B->get_circle_axis(p_transform_b, inv, b - p_motion_b))) {
return;
+ }
}
if (castA && castB) {
- if (!separator.test_axis(rectangle_B->get_circle_axis(p_transform_b, inv, a - p_motion_b + p_motion_a)))
+ if (!separator.test_axis(rectangle_B->get_circle_axis(p_transform_b, inv, a - p_motion_b + p_motion_a))) {
return;
- if (!separator.test_axis(rectangle_B->get_circle_axis(p_transform_b, inv, b - p_motion_b + p_motion_a)))
+ }
+ if (!separator.test_axis(rectangle_B->get_circle_axis(p_transform_b, inv, b - p_motion_b + p_motion_a))) {
return;
+ }
}
}
@@ -505,26 +544,34 @@ static void _collision_segment_capsule(const Shape2DSW *p_a, const Transform2D &
SeparatorAxisTest2D<SegmentShape2DSW, CapsuleShape2DSW, castA, castB, withMargin> separator(segment_A, p_transform_a, capsule_B, p_transform_b, p_collector, p_motion_a, p_motion_b, p_margin_A, p_margin_B);
- if (!separator.test_previous_axis())
+ if (!separator.test_previous_axis()) {
return;
+ }
- if (!separator.test_cast())
+ if (!separator.test_cast()) {
return;
+ }
- if (!separator.test_axis(segment_A->get_xformed_normal(p_transform_a)))
+ if (!separator.test_axis(segment_A->get_xformed_normal(p_transform_a))) {
return;
+ }
- if (!separator.test_axis(p_transform_b.elements[0].normalized()))
+ if (!separator.test_axis(p_transform_b.elements[0].normalized())) {
return;
+ }
- if (TEST_POINT(p_transform_a.xform(segment_A->get_a()), (p_transform_b.get_origin() + p_transform_b.elements[1] * capsule_B->get_height() * 0.5)))
+ if (TEST_POINT(p_transform_a.xform(segment_A->get_a()), (p_transform_b.get_origin() + p_transform_b.elements[1] * capsule_B->get_height() * 0.5))) {
return;
- if (TEST_POINT(p_transform_a.xform(segment_A->get_a()), (p_transform_b.get_origin() + p_transform_b.elements[1] * capsule_B->get_height() * -0.5)))
+ }
+ if (TEST_POINT(p_transform_a.xform(segment_A->get_a()), (p_transform_b.get_origin() + p_transform_b.elements[1] * capsule_B->get_height() * -0.5))) {
return;
- if (TEST_POINT(p_transform_a.xform(segment_A->get_b()), (p_transform_b.get_origin() + p_transform_b.elements[1] * capsule_B->get_height() * 0.5)))
+ }
+ if (TEST_POINT(p_transform_a.xform(segment_A->get_b()), (p_transform_b.get_origin() + p_transform_b.elements[1] * capsule_B->get_height() * 0.5))) {
return;
- if (TEST_POINT(p_transform_a.xform(segment_A->get_b()), (p_transform_b.get_origin() + p_transform_b.elements[1] * capsule_B->get_height() * -0.5)))
+ }
+ if (TEST_POINT(p_transform_a.xform(segment_A->get_b()), (p_transform_b.get_origin() + p_transform_b.elements[1] * capsule_B->get_height() * -0.5))) {
return;
+ }
separator.generate_contacts();
}
@@ -536,24 +583,30 @@ static void _collision_segment_convex_polygon(const Shape2DSW *p_a, const Transf
SeparatorAxisTest2D<SegmentShape2DSW, ConvexPolygonShape2DSW, castA, castB, withMargin> separator(segment_A, p_transform_a, convex_B, p_transform_b, p_collector, p_motion_a, p_motion_b, p_margin_A, p_margin_B);
- if (!separator.test_previous_axis())
+ if (!separator.test_previous_axis()) {
return;
+ }
- if (!separator.test_cast())
+ if (!separator.test_cast()) {
return;
+ }
- if (!separator.test_axis(segment_A->get_xformed_normal(p_transform_a)))
+ if (!separator.test_axis(segment_A->get_xformed_normal(p_transform_a))) {
return;
+ }
for (int i = 0; i < convex_B->get_point_count(); i++) {
- if (!separator.test_axis(convex_B->get_xformed_segment_normal(p_transform_b, i)))
+ if (!separator.test_axis(convex_B->get_xformed_segment_normal(p_transform_b, i))) {
return;
+ }
if (withMargin) {
- if (TEST_POINT(p_transform_a.xform(segment_A->get_a()), p_transform_b.xform(convex_B->get_point(i))))
+ if (TEST_POINT(p_transform_a.xform(segment_A->get_a()), p_transform_b.xform(convex_B->get_point(i)))) {
return;
- if (TEST_POINT(p_transform_a.xform(segment_A->get_b()), p_transform_b.xform(convex_B->get_point(i))))
+ }
+ if (TEST_POINT(p_transform_a.xform(segment_A->get_b()), p_transform_b.xform(convex_B->get_point(i)))) {
return;
+ }
}
}
@@ -569,14 +622,17 @@ static void _collision_circle_circle(const Shape2DSW *p_a, const Transform2D &p_
SeparatorAxisTest2D<CircleShape2DSW, CircleShape2DSW, castA, castB, withMargin> separator(circle_A, p_transform_a, circle_B, p_transform_b, p_collector, p_motion_a, p_motion_b, p_margin_A, p_margin_B);
- if (!separator.test_previous_axis())
+ if (!separator.test_previous_axis()) {
return;
+ }
- if (!separator.test_cast())
+ if (!separator.test_cast()) {
return;
+ }
- if (TEST_POINT(p_transform_a.get_origin(), p_transform_b.get_origin()))
+ if (TEST_POINT(p_transform_a.get_origin(), p_transform_b.get_origin())) {
return;
+ }
separator.generate_contacts();
}
@@ -588,44 +644,52 @@ static void _collision_circle_rectangle(const Shape2DSW *p_a, const Transform2D
SeparatorAxisTest2D<CircleShape2DSW, RectangleShape2DSW, castA, castB, withMargin> separator(circle_A, p_transform_a, rectangle_B, p_transform_b, p_collector, p_motion_a, p_motion_b, p_margin_A, p_margin_B);
- if (!separator.test_previous_axis())
+ if (!separator.test_previous_axis()) {
return;
+ }
- if (!separator.test_cast())
+ if (!separator.test_cast()) {
return;
+ }
const Vector2 &sphere = p_transform_a.elements[2];
const Vector2 *axis = &p_transform_b.elements[0];
//const Vector2& half_extents = rectangle_B->get_half_extents();
- if (!separator.test_axis(axis[0].normalized()))
+ if (!separator.test_axis(axis[0].normalized())) {
return;
+ }
- if (!separator.test_axis(axis[1].normalized()))
+ if (!separator.test_axis(axis[1].normalized())) {
return;
+ }
Transform2D binv = p_transform_b.affine_inverse();
{
- if (!separator.test_axis(rectangle_B->get_circle_axis(p_transform_b, binv, sphere)))
+ if (!separator.test_axis(rectangle_B->get_circle_axis(p_transform_b, binv, sphere))) {
return;
+ }
}
if (castA) {
Vector2 sphereofs = sphere + p_motion_a;
- if (!separator.test_axis(rectangle_B->get_circle_axis(p_transform_b, binv, sphereofs)))
+ if (!separator.test_axis(rectangle_B->get_circle_axis(p_transform_b, binv, sphereofs))) {
return;
+ }
}
if (castB) {
Vector2 sphereofs = sphere - p_motion_b;
- if (!separator.test_axis(rectangle_B->get_circle_axis(p_transform_b, binv, sphereofs)))
+ if (!separator.test_axis(rectangle_B->get_circle_axis(p_transform_b, binv, sphereofs))) {
return;
+ }
}
if (castA && castB) {
Vector2 sphereofs = sphere - p_motion_b + p_motion_a;
- if (!separator.test_axis(rectangle_B->get_circle_axis(p_transform_b, binv, sphereofs)))
+ if (!separator.test_axis(rectangle_B->get_circle_axis(p_transform_b, binv, sphereofs))) {
return;
+ }
}
separator.generate_contacts();
@@ -638,21 +702,26 @@ static void _collision_circle_capsule(const Shape2DSW *p_a, const Transform2D &p
SeparatorAxisTest2D<CircleShape2DSW, CapsuleShape2DSW, castA, castB, withMargin> separator(circle_A, p_transform_a, capsule_B, p_transform_b, p_collector, p_motion_a, p_motion_b, p_margin_A, p_margin_B);
- if (!separator.test_previous_axis())
+ if (!separator.test_previous_axis()) {
return;
+ }
- if (!separator.test_cast())
+ if (!separator.test_cast()) {
return;
+ }
//capsule axis
- if (!separator.test_axis(p_transform_b.elements[0].normalized()))
+ if (!separator.test_axis(p_transform_b.elements[0].normalized())) {
return;
+ }
//capsule endpoints
- if (TEST_POINT(p_transform_a.get_origin(), (p_transform_b.get_origin() + p_transform_b.elements[1] * capsule_B->get_height() * 0.5)))
+ if (TEST_POINT(p_transform_a.get_origin(), (p_transform_b.get_origin() + p_transform_b.elements[1] * capsule_B->get_height() * 0.5))) {
return;
- if (TEST_POINT(p_transform_a.get_origin(), (p_transform_b.get_origin() + p_transform_b.elements[1] * capsule_B->get_height() * -0.5)))
+ }
+ if (TEST_POINT(p_transform_a.get_origin(), (p_transform_b.get_origin() + p_transform_b.elements[1] * capsule_B->get_height() * -0.5))) {
return;
+ }
separator.generate_contacts();
}
@@ -664,19 +733,23 @@ static void _collision_circle_convex_polygon(const Shape2DSW *p_a, const Transfo
SeparatorAxisTest2D<CircleShape2DSW, ConvexPolygonShape2DSW, castA, castB, withMargin> separator(circle_A, p_transform_a, convex_B, p_transform_b, p_collector, p_motion_a, p_motion_b, p_margin_A, p_margin_B);
- if (!separator.test_previous_axis())
+ if (!separator.test_previous_axis()) {
return;
+ }
- if (!separator.test_cast())
+ if (!separator.test_cast()) {
return;
+ }
//poly faces and poly points vs circle
for (int i = 0; i < convex_B->get_point_count(); i++) {
- if (TEST_POINT(p_transform_a.get_origin(), p_transform_b.xform(convex_B->get_point(i))))
+ if (TEST_POINT(p_transform_a.get_origin(), p_transform_b.xform(convex_B->get_point(i)))) {
return;
+ }
- if (!separator.test_axis(convex_B->get_xformed_segment_normal(p_transform_b, i)))
+ if (!separator.test_axis(convex_B->get_xformed_segment_normal(p_transform_b, i))) {
return;
+ }
}
separator.generate_contacts();
@@ -691,32 +764,39 @@ static void _collision_rectangle_rectangle(const Shape2DSW *p_a, const Transform
SeparatorAxisTest2D<RectangleShape2DSW, RectangleShape2DSW, castA, castB, withMargin> separator(rectangle_A, p_transform_a, rectangle_B, p_transform_b, p_collector, p_motion_a, p_motion_b, p_margin_A, p_margin_B);
- if (!separator.test_previous_axis())
+ if (!separator.test_previous_axis()) {
return;
+ }
- if (!separator.test_cast())
+ if (!separator.test_cast()) {
return;
+ }
//box faces A
- if (!separator.test_axis(p_transform_a.elements[0].normalized()))
+ if (!separator.test_axis(p_transform_a.elements[0].normalized())) {
return;
+ }
- if (!separator.test_axis(p_transform_a.elements[1].normalized()))
+ if (!separator.test_axis(p_transform_a.elements[1].normalized())) {
return;
+ }
//box faces B
- if (!separator.test_axis(p_transform_b.elements[0].normalized()))
+ if (!separator.test_axis(p_transform_b.elements[0].normalized())) {
return;
+ }
- if (!separator.test_axis(p_transform_b.elements[1].normalized()))
+ if (!separator.test_axis(p_transform_b.elements[1].normalized())) {
return;
+ }
if (withMargin) {
Transform2D invA = p_transform_a.affine_inverse();
Transform2D invB = p_transform_b.affine_inverse();
- if (!separator.test_axis(rectangle_A->get_box_axis(p_transform_a, invA, rectangle_B, p_transform_b, invB)))
+ if (!separator.test_axis(rectangle_A->get_box_axis(p_transform_a, invA, rectangle_B, p_transform_b, invB))) {
return;
+ }
if (castA || castB) {
Transform2D aofs = p_transform_a;
@@ -729,18 +809,21 @@ static void _collision_rectangle_rectangle(const Shape2DSW *p_a, const Transform
Transform2D bofsinv = bofs.affine_inverse();
if (castA) {
- if (!separator.test_axis(rectangle_A->get_box_axis(aofs, aofsinv, rectangle_B, p_transform_b, invB)))
+ if (!separator.test_axis(rectangle_A->get_box_axis(aofs, aofsinv, rectangle_B, p_transform_b, invB))) {
return;
+ }
}
if (castB) {
- if (!separator.test_axis(rectangle_A->get_box_axis(p_transform_a, invA, rectangle_B, bofs, bofsinv)))
+ if (!separator.test_axis(rectangle_A->get_box_axis(p_transform_a, invA, rectangle_B, bofs, bofsinv))) {
return;
+ }
}
if (castA && castB) {
- if (!separator.test_axis(rectangle_A->get_box_axis(aofs, aofsinv, rectangle_B, bofs, bofsinv)))
+ if (!separator.test_axis(rectangle_A->get_box_axis(aofs, aofsinv, rectangle_B, bofs, bofsinv))) {
return;
+ }
}
}
}
@@ -755,22 +838,27 @@ static void _collision_rectangle_capsule(const Shape2DSW *p_a, const Transform2D
SeparatorAxisTest2D<RectangleShape2DSW, CapsuleShape2DSW, castA, castB, withMargin> separator(rectangle_A, p_transform_a, capsule_B, p_transform_b, p_collector, p_motion_a, p_motion_b, p_margin_A, p_margin_B);
- if (!separator.test_previous_axis())
+ if (!separator.test_previous_axis()) {
return;
+ }
- if (!separator.test_cast())
+ if (!separator.test_cast()) {
return;
+ }
//box faces
- if (!separator.test_axis(p_transform_a.elements[0].normalized()))
+ if (!separator.test_axis(p_transform_a.elements[0].normalized())) {
return;
+ }
- if (!separator.test_axis(p_transform_a.elements[1].normalized()))
+ if (!separator.test_axis(p_transform_a.elements[1].normalized())) {
return;
+ }
//capsule axis
- if (!separator.test_axis(p_transform_b.elements[0].normalized()))
+ if (!separator.test_axis(p_transform_b.elements[0].normalized())) {
return;
+ }
//box endpoints to capsule circles
@@ -780,24 +868,27 @@ static void _collision_rectangle_capsule(const Shape2DSW *p_a, const Transform2D
{
Vector2 capsule_endpoint = p_transform_b.get_origin() + p_transform_b.elements[1] * capsule_B->get_height() * (i == 0 ? 0.5 : -0.5);
- if (!separator.test_axis(rectangle_A->get_circle_axis(p_transform_a, boxinv, capsule_endpoint)))
+ if (!separator.test_axis(rectangle_A->get_circle_axis(p_transform_a, boxinv, capsule_endpoint))) {
return;
+ }
}
if (castA) {
Vector2 capsule_endpoint = p_transform_b.get_origin() + p_transform_b.elements[1] * capsule_B->get_height() * (i == 0 ? 0.5 : -0.5);
capsule_endpoint -= p_motion_a;
- if (!separator.test_axis(rectangle_A->get_circle_axis(p_transform_a, boxinv, capsule_endpoint)))
+ if (!separator.test_axis(rectangle_A->get_circle_axis(p_transform_a, boxinv, capsule_endpoint))) {
return;
+ }
}
if (castB) {
Vector2 capsule_endpoint = p_transform_b.get_origin() + p_transform_b.elements[1] * capsule_B->get_height() * (i == 0 ? 0.5 : -0.5);
capsule_endpoint += p_motion_b;
- if (!separator.test_axis(rectangle_A->get_circle_axis(p_transform_a, boxinv, capsule_endpoint)))
+ if (!separator.test_axis(rectangle_A->get_circle_axis(p_transform_a, boxinv, capsule_endpoint))) {
return;
+ }
}
if (castA && castB) {
@@ -805,8 +896,9 @@ static void _collision_rectangle_capsule(const Shape2DSW *p_a, const Transform2D
capsule_endpoint -= p_motion_a;
capsule_endpoint += p_motion_b;
- if (!separator.test_axis(rectangle_A->get_circle_axis(p_transform_a, boxinv, capsule_endpoint)))
+ if (!separator.test_axis(rectangle_A->get_circle_axis(p_transform_a, boxinv, capsule_endpoint))) {
return;
+ }
}
}
@@ -820,18 +912,22 @@ static void _collision_rectangle_convex_polygon(const Shape2DSW *p_a, const Tran
SeparatorAxisTest2D<RectangleShape2DSW, ConvexPolygonShape2DSW, castA, castB, withMargin> separator(rectangle_A, p_transform_a, convex_B, p_transform_b, p_collector, p_motion_a, p_motion_b, p_margin_A, p_margin_B);
- if (!separator.test_previous_axis())
+ if (!separator.test_previous_axis()) {
return;
+ }
- if (!separator.test_cast())
+ if (!separator.test_cast()) {
return;
+ }
//box faces
- if (!separator.test_axis(p_transform_a.elements[0].normalized()))
+ if (!separator.test_axis(p_transform_a.elements[0].normalized())) {
return;
+ }
- if (!separator.test_axis(p_transform_a.elements[1].normalized()))
+ if (!separator.test_axis(p_transform_a.elements[1].normalized())) {
return;
+ }
//convex faces
Transform2D boxinv;
@@ -839,24 +935,29 @@ static void _collision_rectangle_convex_polygon(const Shape2DSW *p_a, const Tran
boxinv = p_transform_a.affine_inverse();
}
for (int i = 0; i < convex_B->get_point_count(); i++) {
- if (!separator.test_axis(convex_B->get_xformed_segment_normal(p_transform_b, i)))
+ if (!separator.test_axis(convex_B->get_xformed_segment_normal(p_transform_b, i))) {
return;
+ }
if (withMargin) {
//all points vs all points need to be tested if margin exist
- if (!separator.test_axis(rectangle_A->get_circle_axis(p_transform_a, boxinv, p_transform_b.xform(convex_B->get_point(i)))))
+ if (!separator.test_axis(rectangle_A->get_circle_axis(p_transform_a, boxinv, p_transform_b.xform(convex_B->get_point(i))))) {
return;
+ }
if (castA) {
- if (!separator.test_axis(rectangle_A->get_circle_axis(p_transform_a, boxinv, p_transform_b.xform(convex_B->get_point(i)) - p_motion_a)))
+ if (!separator.test_axis(rectangle_A->get_circle_axis(p_transform_a, boxinv, p_transform_b.xform(convex_B->get_point(i)) - p_motion_a))) {
return;
+ }
}
if (castB) {
- if (!separator.test_axis(rectangle_A->get_circle_axis(p_transform_a, boxinv, p_transform_b.xform(convex_B->get_point(i)) + p_motion_b)))
+ if (!separator.test_axis(rectangle_A->get_circle_axis(p_transform_a, boxinv, p_transform_b.xform(convex_B->get_point(i)) + p_motion_b))) {
return;
+ }
}
if (castA && castB) {
- if (!separator.test_axis(rectangle_A->get_circle_axis(p_transform_a, boxinv, p_transform_b.xform(convex_B->get_point(i)) + p_motion_b - p_motion_a)))
+ if (!separator.test_axis(rectangle_A->get_circle_axis(p_transform_a, boxinv, p_transform_b.xform(convex_B->get_point(i)) + p_motion_b - p_motion_a))) {
return;
+ }
}
}
}
@@ -873,19 +974,23 @@ static void _collision_capsule_capsule(const Shape2DSW *p_a, const Transform2D &
SeparatorAxisTest2D<CapsuleShape2DSW, CapsuleShape2DSW, castA, castB, withMargin> separator(capsule_A, p_transform_a, capsule_B, p_transform_b, p_collector, p_motion_a, p_motion_b, p_margin_A, p_margin_B);
- if (!separator.test_previous_axis())
+ if (!separator.test_previous_axis()) {
return;
+ }
- if (!separator.test_cast())
+ if (!separator.test_cast()) {
return;
+ }
//capsule axis
- if (!separator.test_axis(p_transform_b.elements[0].normalized()))
+ if (!separator.test_axis(p_transform_b.elements[0].normalized())) {
return;
+ }
- if (!separator.test_axis(p_transform_a.elements[0].normalized()))
+ if (!separator.test_axis(p_transform_a.elements[0].normalized())) {
return;
+ }
//capsule endpoints
@@ -895,8 +1000,9 @@ static void _collision_capsule_capsule(const Shape2DSW *p_a, const Transform2D &
for (int j = 0; j < 2; j++) {
Vector2 capsule_endpoint_B = p_transform_b.get_origin() + p_transform_b.elements[1] * capsule_B->get_height() * (j == 0 ? 0.5 : -0.5);
- if (TEST_POINT(capsule_endpoint_A, capsule_endpoint_B))
+ if (TEST_POINT(capsule_endpoint_A, capsule_endpoint_B)) {
return;
+ }
}
}
@@ -910,16 +1016,19 @@ static void _collision_capsule_convex_polygon(const Shape2DSW *p_a, const Transf
SeparatorAxisTest2D<CapsuleShape2DSW, ConvexPolygonShape2DSW, castA, castB, withMargin> separator(capsule_A, p_transform_a, convex_B, p_transform_b, p_collector, p_motion_a, p_motion_b, p_margin_A, p_margin_B);
- if (!separator.test_previous_axis())
+ if (!separator.test_previous_axis()) {
return;
+ }
- if (!separator.test_cast())
+ if (!separator.test_cast()) {
return;
+ }
//capsule axis
- if (!separator.test_axis(p_transform_a.elements[0].normalized()))
+ if (!separator.test_axis(p_transform_a.elements[0].normalized())) {
return;
+ }
//poly vs capsule
for (int i = 0; i < convex_B->get_point_count(); i++) {
@@ -928,12 +1037,14 @@ static void _collision_capsule_convex_polygon(const Shape2DSW *p_a, const Transf
for (int j = 0; j < 2; j++) {
Vector2 capsule_endpoint_A = p_transform_a.get_origin() + p_transform_a.elements[1] * capsule_A->get_height() * (j == 0 ? 0.5 : -0.5);
- if (TEST_POINT(capsule_endpoint_A, cpoint))
+ if (TEST_POINT(capsule_endpoint_A, cpoint)) {
return;
+ }
}
- if (!separator.test_axis(convex_B->get_xformed_segment_normal(p_transform_b, i)))
+ if (!separator.test_axis(convex_B->get_xformed_segment_normal(p_transform_b, i))) {
return;
+ }
}
separator.generate_contacts();
@@ -948,27 +1059,32 @@ static void _collision_convex_polygon_convex_polygon(const Shape2DSW *p_a, const
SeparatorAxisTest2D<ConvexPolygonShape2DSW, ConvexPolygonShape2DSW, castA, castB, withMargin> separator(convex_A, p_transform_a, convex_B, p_transform_b, p_collector, p_motion_a, p_motion_b, p_margin_A, p_margin_B);
- if (!separator.test_previous_axis())
+ if (!separator.test_previous_axis()) {
return;
+ }
- if (!separator.test_cast())
+ if (!separator.test_cast()) {
return;
+ }
for (int i = 0; i < convex_A->get_point_count(); i++) {
- if (!separator.test_axis(convex_A->get_xformed_segment_normal(p_transform_a, i)))
+ if (!separator.test_axis(convex_A->get_xformed_segment_normal(p_transform_a, i))) {
return;
+ }
}
for (int i = 0; i < convex_B->get_point_count(); i++) {
- if (!separator.test_axis(convex_B->get_xformed_segment_normal(p_transform_b, i)))
+ if (!separator.test_axis(convex_B->get_xformed_segment_normal(p_transform_b, i))) {
return;
+ }
}
if (withMargin) {
for (int i = 0; i < convex_A->get_point_count(); i++) {
for (int j = 0; j < convex_B->get_point_count(); j++) {
- if (TEST_POINT(p_transform_a.xform(convex_A->get_point(i)), p_transform_b.xform(convex_B->get_point(j))))
+ if (TEST_POINT(p_transform_a.xform(convex_A->get_point(i)), p_transform_b.xform(convex_B->get_point(j)))) {
return;
+ }
}
}
}
diff --git a/servers/physics_2d/collision_solver_2d_sw.cpp b/servers/physics_2d/collision_solver_2d_sw.cpp
index 636b288358..beba709807 100644
--- a/servers/physics_2d/collision_solver_2d_sw.cpp
+++ b/servers/physics_2d/collision_solver_2d_sw.cpp
@@ -36,8 +36,9 @@
bool CollisionSolver2DSW::solve_static_line(const Shape2DSW *p_shape_A, const Transform2D &p_transform_A, const Shape2DSW *p_shape_B, const Transform2D &p_transform_B, CallbackResult p_result_callback, void *p_userdata, bool p_swap_result) {
const LineShape2DSW *line = static_cast<const LineShape2DSW *>(p_shape_A);
- if (p_shape_B->get_type() == PhysicsServer2D::SHAPE_LINE)
+ if (p_shape_B->get_type() == PhysicsServer2D::SHAPE_LINE) {
return false;
+ }
Vector2 n = p_transform_A.basis_xform(line->get_normal()).normalized();
Vector2 p = p_transform_A.xform(line->get_normal() * line->get_d());
@@ -53,17 +54,19 @@ bool CollisionSolver2DSW::solve_static_line(const Shape2DSW *p_shape_A, const Tr
for (int i = 0; i < support_count; i++) {
supports[i] = p_transform_B.xform(supports[i]);
real_t pd = n.dot(supports[i]);
- if (pd >= d)
+ if (pd >= d) {
continue;
+ }
found = true;
Vector2 support_A = supports[i] - n * (pd - d);
if (p_result_callback) {
- if (p_swap_result)
+ if (p_swap_result) {
p_result_callback(supports[i], support_A, p_userdata);
- else
+ } else {
p_result_callback(support_A, supports[i], p_userdata);
+ }
}
}
@@ -72,8 +75,9 @@ bool CollisionSolver2DSW::solve_static_line(const Shape2DSW *p_shape_A, const Tr
bool CollisionSolver2DSW::solve_raycast(const Shape2DSW *p_shape_A, const Vector2 &p_motion_A, const Transform2D &p_transform_A, const Shape2DSW *p_shape_B, const Transform2D &p_transform_B, CallbackResult p_result_callback, void *p_userdata, bool p_swap_result, Vector2 *sep_axis) {
const RayShape2DSW *ray = static_cast<const RayShape2DSW *>(p_shape_A);
- if (p_shape_B->get_type() == PhysicsServer2D::SHAPE_RAY)
+ if (p_shape_B->get_type() == PhysicsServer2D::SHAPE_RAY) {
return false;
+ }
Vector2 from = p_transform_A.get_origin();
Vector2 to = from + p_transform_A[1] * ray->get_length();
@@ -90,8 +94,9 @@ bool CollisionSolver2DSW::solve_raycast(const Shape2DSW *p_shape_A, const Vector
Vector2 p, n;
if (!p_shape_B->intersect_segment(from, to, p, n)) {
- if (sep_axis)
+ if (sep_axis) {
*sep_axis = p_transform_A[1].normalized();
+ }
return false;
}
@@ -102,10 +107,11 @@ bool CollisionSolver2DSW::solve_raycast(const Shape2DSW *p_shape_A, const Vector
}
if (p_result_callback) {
- if (p_swap_result)
+ if (p_swap_result) {
p_result_callback(support_B, support_A, p_userdata);
- else
+ } else {
p_result_callback(support_A, support_B, p_userdata);
+ }
}
return true;
}
@@ -130,12 +136,14 @@ struct _ConcaveCollisionInfo2D {
void CollisionSolver2DSW::concave_callback(void *p_userdata, Shape2DSW *p_convex) {
_ConcaveCollisionInfo2D &cinfo = *(_ConcaveCollisionInfo2D *)(p_userdata);
cinfo.aabb_tests++;
- if (!cinfo.result_callback && cinfo.collided)
+ if (!cinfo.result_callback && cinfo.collided) {
return; //already collided and no contacts requested, don't test anymore
+ }
bool collided = collision_solver(cinfo.shape_A, *cinfo.transform_A, cinfo.motion_A, p_convex, *cinfo.transform_B, cinfo.motion_B, cinfo.result_callback, cinfo.userdata, cinfo.swap_result, cinfo.sep_axis, cinfo.margin_A, cinfo.margin_B);
- if (!collided)
+ if (!collided) {
return;
+ }
cinfo.collided = true;
cinfo.collisions++;
@@ -224,13 +232,15 @@ bool CollisionSolver2DSW::solve(const Shape2DSW *p_shape_A, const Transform2D &p
}
} else if (concave_B) {
- if (concave_A)
+ if (concave_A) {
return false;
+ }
- if (!swap)
+ if (!swap) {
return solve_concave(p_shape_A, p_transform_A, p_motion_A, p_shape_B, p_transform_B, p_motion_B, p_result_callback, p_userdata, false, sep_axis, margin_A, margin_B);
- else
+ } else {
return solve_concave(p_shape_B, p_transform_B, p_motion_B, p_shape_A, p_transform_A, p_motion_A, p_result_callback, p_userdata, true, sep_axis, margin_A, margin_B);
+ }
} else {
return collision_solver(p_shape_A, p_transform_A, p_motion_A, p_shape_B, p_transform_B, p_motion_B, p_result_callback, p_userdata, false, sep_axis, margin_A, margin_B);
diff --git a/servers/physics_2d/joints_2d_sw.cpp b/servers/physics_2d/joints_2d_sw.cpp
index 73d916138b..eda0b923a2 100644
--- a/servers/physics_2d/joints_2d_sw.cpp
+++ b/servers/physics_2d/joints_2d_sw.cpp
@@ -76,10 +76,11 @@ static inline real_t k_scalar(Body2DSW *a, Body2DSW *b, const Vector2 &rA, const
static inline Vector2
relative_velocity(Body2DSW *a, Body2DSW *b, Vector2 rA, Vector2 rB) {
Vector2 sum = a->get_linear_velocity() - rA.tangent() * a->get_angular_velocity();
- if (b)
+ if (b) {
return (b->get_linear_velocity() - rB.tangent() * b->get_angular_velocity()) - sum;
- else
+ } else {
return -sum;
+ }
}
static inline real_t
@@ -136,8 +137,9 @@ bool PinJoint2DSW::setup(real_t p_step) {
// apply accumulated impulse
A->apply_impulse(rA, -P);
- if (B)
+ if (B) {
B->apply_impulse(rB, P);
+ }
return true;
}
@@ -151,28 +153,32 @@ void PinJoint2DSW::solve(real_t p_step) {
Vector2 vA = A->get_linear_velocity() - custom_cross(rA, A->get_angular_velocity());
Vector2 rel_vel;
- if (B)
+ if (B) {
rel_vel = B->get_linear_velocity() - custom_cross(rB, B->get_angular_velocity()) - vA;
- else
+ } else {
rel_vel = -vA;
+ }
Vector2 impulse = M.basis_xform(bias - rel_vel - Vector2(softness, softness) * P);
A->apply_impulse(rA, -impulse);
- if (B)
+ if (B) {
B->apply_impulse(rB, impulse);
+ }
P += impulse;
}
void PinJoint2DSW::set_param(PhysicsServer2D::PinJointParam p_param, real_t p_value) {
- if (p_param == PhysicsServer2D::PIN_JOINT_SOFTNESS)
+ if (p_param == PhysicsServer2D::PIN_JOINT_SOFTNESS) {
softness = p_value;
+ }
}
real_t PinJoint2DSW::get_param(PhysicsServer2D::PinJointParam p_param) const {
- if (p_param == PhysicsServer2D::PIN_JOINT_SOFTNESS)
+ if (p_param == PhysicsServer2D::PIN_JOINT_SOFTNESS) {
return softness;
+ }
ERR_FAIL_V(0);
}
@@ -186,15 +192,18 @@ PinJoint2DSW::PinJoint2DSW(const Vector2 &p_pos, Body2DSW *p_body_a, Body2DSW *p
softness = 0;
p_body_a->add_constraint(this, 0);
- if (p_body_b)
+ if (p_body_b) {
p_body_b->add_constraint(this, 1);
+ }
}
PinJoint2DSW::~PinJoint2DSW() {
- if (A)
+ if (A) {
A->remove_constraint(this);
- if (B)
+ }
+ if (B) {
B->remove_constraint(this);
+ }
}
//////////////////////////////////////////////
@@ -345,10 +354,11 @@ bool DampedSpringJoint2DSW::setup(real_t p_step) {
Vector2 delta = (B->get_transform().get_origin() + rB) - (A->get_transform().get_origin() + rA);
real_t dist = delta.length();
- if (dist)
+ if (dist) {
n = delta / dist;
- else
+ } else {
n = Vector2();
+ }
real_t k = k_scalar(A, B, rA, rB, n);
n_mass = 1.0f / k;
diff --git a/servers/physics_2d/physics_server_2d_sw.cpp b/servers/physics_2d/physics_server_2d_sw.cpp
index a35283d76d..e9b2ac6875 100644
--- a/servers/physics_2d/physics_server_2d_sw.cpp
+++ b/servers/physics_2d/physics_server_2d_sw.cpp
@@ -145,8 +145,9 @@ real_t PhysicsServer2DSW::shape_get_custom_solver_bias(RID p_shape) const {
void PhysicsServer2DSW::_shape_col_cbk(const Vector2 &p_point_A, const Vector2 &p_point_B, void *p_userdata) {
CollCbkData *cbk = (CollCbkData *)p_userdata;
- if (cbk->max == 0)
+ if (cbk->max == 0) {
return;
+ }
if (cbk->valid_dir != Vector2()) {
if (p_point_A.distance_squared_to(p_point_B) > cbk->valid_depth * cbk->valid_depth) {
@@ -182,8 +183,9 @@ void PhysicsServer2DSW::_shape_col_cbk(const Vector2 &p_point_A, const Vector2 &
}
real_t d = p_point_A.distance_squared_to(p_point_B);
- if (d < min_depth)
+ if (d < min_depth) {
return;
+ }
cbk->ptr[min_depth_idx * 2 + 0] = p_point_A;
cbk->ptr[min_depth_idx * 2 + 1] = p_point_B;
cbk->passed++;
@@ -234,10 +236,11 @@ RID PhysicsServer2DSW::space_create() {
void PhysicsServer2DSW::space_set_active(RID p_space, bool p_active) {
Space2DSW *space = space_owner.getornull(p_space);
ERR_FAIL_COND(!space);
- if (p_active)
+ if (p_active) {
active_spaces.insert(space);
- else
+ } else {
active_spaces.erase(space);
+ }
}
bool PhysicsServer2DSW::space_is_active(RID p_space) const {
@@ -303,8 +306,9 @@ void PhysicsServer2DSW::area_set_space(RID p_area, RID p_space) {
ERR_FAIL_COND(!space);
}
- if (area->get_space() == space)
+ if (area->get_space() == space) {
return; //pointless
+ }
area->clear_constraints();
area->set_space(space);
@@ -315,8 +319,9 @@ RID PhysicsServer2DSW::area_get_space(RID p_area) const {
ERR_FAIL_COND_V(!area, RID());
Space2DSW *space = area->get_space();
- if (!space)
+ if (!space) {
return RID();
+ }
return space->get_self();
};
@@ -406,8 +411,9 @@ void PhysicsServer2DSW::area_clear_shapes(RID p_area) {
Area2DSW *area = area_owner.getornull(p_area);
ERR_FAIL_COND(!area);
- while (area->get_shape_count())
+ while (area->get_shape_count()) {
area->remove_shape(0);
+ }
}
void PhysicsServer2DSW::area_attach_object_instance_id(RID p_area, ObjectID p_id) {
@@ -544,8 +550,9 @@ void PhysicsServer2DSW::body_set_space(RID p_body, RID p_space) {
ERR_FAIL_COND(!space);
}
- if (body->get_space() == space)
+ if (body->get_space() == space) {
return; //pointless
+ }
body->clear_constraint_map();
body->set_space(space);
@@ -556,8 +563,9 @@ RID PhysicsServer2DSW::body_get_space(RID p_body) const {
ERR_FAIL_COND_V(!body, RID());
Space2DSW *space = body->get_space();
- if (!space)
+ if (!space) {
return RID();
+ }
return space->get_self();
};
@@ -651,8 +659,9 @@ void PhysicsServer2DSW::body_clear_shapes(RID p_body) {
Body2DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND(!body);
- while (body->get_shape_count())
+ while (body->get_shape_count()) {
body->remove_shape(0);
+ }
}
void PhysicsServer2DSW::body_set_shape_disabled(RID p_body, int p_shape_idx, bool p_disabled) {
@@ -966,8 +975,9 @@ int PhysicsServer2DSW::body_test_ray_separation(RID p_body, const Transform2D &p
PhysicsDirectBodyState2D *PhysicsServer2DSW::body_get_direct_state(RID p_body) {
ERR_FAIL_COND_V_MSG((using_threads && !doing_sync), nullptr, "Body state is inaccessible right now, wait for iteration or physics process notification.");
- if (!body_owner.owns(p_body))
+ if (!body_owner.owns(p_body)) {
return nullptr;
+ }
Body2DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND_V(!body, nullptr);
@@ -1213,8 +1223,9 @@ void PhysicsServer2DSW::init() {
};
void PhysicsServer2DSW::step(real_t p_step) {
- if (!active)
+ if (!active) {
return;
+ }
_update_shapes();
@@ -1238,8 +1249,9 @@ void PhysicsServer2DSW::sync() {
};
void PhysicsServer2DSW::flush_queries() {
- if (!active)
+ if (!active) {
return;
+ }
flushing_queries = true;
diff --git a/servers/physics_2d/physics_server_2d_wrap_mt.cpp b/servers/physics_2d/physics_server_2d_wrap_mt.cpp
index 86d5755ec5..49c38c6ce0 100644
--- a/servers/physics_2d/physics_server_2d_wrap_mt.cpp
+++ b/servers/physics_2d/physics_server_2d_wrap_mt.cpp
@@ -77,10 +77,11 @@ void PhysicsServer2DWrapMT::step(real_t p_step) {
void PhysicsServer2DWrapMT::sync() {
if (thread) {
- if (first_frame)
+ if (first_frame) {
first_frame = false;
- else
+ } else {
step_sem.wait(); //must not wait if a step was not issued
+ }
}
physics_2d_server->sync();
}
diff --git a/servers/physics_2d/physics_server_2d_wrap_mt.h b/servers/physics_2d/physics_server_2d_wrap_mt.h
index dbfdb077ab..c2ae288f95 100644
--- a/servers/physics_2d/physics_server_2d_wrap_mt.h
+++ b/servers/physics_2d/physics_server_2d_wrap_mt.h
@@ -318,12 +318,13 @@ public:
template <class T>
static PhysicsServer2D *init_server() {
int tm = GLOBAL_DEF("physics/2d/thread_model", 1);
- if (tm == 0) // single unsafe
+ if (tm == 0) { // single unsafe
return memnew(T);
- else if (tm == 1) // single safe
+ } else if (tm == 1) { // single safe
return memnew(PhysicsServer2DWrapMT(memnew(T), false));
- else // multi threaded
+ } else { // multi threaded
return memnew(PhysicsServer2DWrapMT(memnew(T), true));
+ }
}
#undef ServerNameWrapMT
diff --git a/servers/physics_2d/shape_2d_sw.cpp b/servers/physics_2d/shape_2d_sw.cpp
index 1fb53cf065..c0589b9804 100644
--- a/servers/physics_2d/shape_2d_sw.cpp
+++ b/servers/physics_2d/shape_2d_sw.cpp
@@ -146,10 +146,11 @@ Variant LineShape2DSW::get_data() const {
void RayShape2DSW::get_supports(const Vector2 &p_normal, Vector2 *r_supports, int &r_amount) const {
r_amount = 1;
- if (p_normal.y > 0)
+ if (p_normal.y > 0) {
*r_supports = Vector2(0, length);
- else
+ } else {
*r_supports = Vector2();
+ }
}
bool RayShape2DSW::contains_point(const Vector2 &p_point) const {
@@ -191,10 +192,11 @@ void SegmentShape2DSW::get_supports(const Vector2 &p_normal, Vector2 *r_supports
}
real_t dp = p_normal.dot(b - a);
- if (dp > 0)
+ if (dp > 0) {
*r_supports = b;
- else
+ } else {
*r_supports = a;
+ }
r_amount = 1;
}
@@ -203,8 +205,9 @@ bool SegmentShape2DSW::contains_point(const Vector2 &p_point) const {
}
bool SegmentShape2DSW::intersect_segment(const Vector2 &p_begin, const Vector2 &p_end, Vector2 &r_point, Vector2 &r_normal) const {
- if (!Geometry::segment_intersects_segment_2d(p_begin, p_end, a, b, &r_point))
+ if (!Geometry::segment_intersects_segment_2d(p_begin, p_end, a, b, &r_point)) {
return false;
+ }
if (n.dot(p_begin) > n.dot(a)) {
r_normal = n;
@@ -230,10 +233,12 @@ void SegmentShape2DSW::set_data(const Variant &p_data) {
Rect2 aabb;
aabb.position = a;
aabb.expand_to(b);
- if (aabb.size.x == 0)
+ if (aabb.size.x == 0) {
aabb.size.x = 0.001;
- if (aabb.size.y == 0)
+ }
+ if (aabb.size.y == 0) {
aabb.size.y = 0.001;
+ }
configure(aabb);
}
@@ -268,8 +273,9 @@ bool CircleShape2DSW::intersect_segment(const Vector2 &p_begin, const Vector2 &p
real_t sqrtterm = b * b - 4 * a * c;
- if (sqrtterm < 0)
+ if (sqrtterm < 0) {
return false;
+ }
sqrtterm = Math::sqrt(sqrtterm);
real_t res = (-b - sqrtterm) / (2 * a);
@@ -307,8 +313,9 @@ void RectangleShape2DSW::get_supports(const Vector2 &p_normal, Vector2 *r_suppor
Vector2 ag;
ag[i] = 1.0;
real_t dp = ag.dot(p_normal);
- if (Math::abs(dp) < _SEGMENT_IS_VALID_SUPPORT_THRESHOLD)
+ if (Math::abs(dp) < _SEGMENT_IS_VALID_SUPPORT_THRESHOLD) {
continue;
+ }
real_t sgn = dp > 0 ? 1.0 : -1.0;
@@ -394,8 +401,9 @@ bool CapsuleShape2DSW::contains_point(const Vector2 &p_point) const {
Vector2 p = p_point;
p.y = Math::abs(p.y);
p.y -= height * 0.5;
- if (p.y < 0)
+ if (p.y < 0) {
p.y = 0;
+ }
return p.length_squared() < radius * radius;
}
@@ -423,8 +431,9 @@ bool CapsuleShape2DSW::intersect_segment(const Vector2 &p_begin, const Vector2 &
real_t sqrtterm = b * b - 4 * a * c;
- if (sqrtterm < 0)
+ if (sqrtterm < 0) {
continue;
+ }
sqrtterm = Math::sqrt(sqrtterm);
real_t res = (-b - sqrtterm) / (2 * a);
@@ -523,10 +532,11 @@ bool ConvexPolygonShape2DSW::contains_point(const Vector2 &p_point) const {
for (int i = 0; i < point_count; i++) {
real_t d = points[i].normal.dot(p_point) - points[i].normal.dot(points[i].pos);
- if (d > 0)
+ if (d > 0) {
out = true;
- else
+ } else {
in = true;
+ }
}
return in != out;
@@ -546,8 +556,9 @@ bool ConvexPolygonShape2DSW::intersect_segment(const Vector2 &p_begin, const Vec
Vector2 res;
- if (!Geometry::segment_intersects_segment_2d(p_begin, p_end, points[i].pos, points[(i + 1) % point_count].pos, &res))
+ if (!Geometry::segment_intersects_segment_2d(p_begin, p_end, points[i].pos, points[(i + 1) % point_count].pos, &res)) {
continue;
+ }
real_t nd = n.dot(res);
if (nd < d) {
@@ -559,8 +570,9 @@ bool ConvexPolygonShape2DSW::intersect_segment(const Vector2 &p_begin, const Vec
}
if (inters) {
- if (n.dot(r_normal) > 0)
+ if (n.dot(r_normal) > 0) {
r_normal = -r_normal;
+ }
}
//return get_aabb().intersects_segment(p_begin,p_end,&r_point,&r_normal);
@@ -580,8 +592,9 @@ real_t ConvexPolygonShape2DSW::get_moment_of_inertia(real_t p_mass, const Size2
void ConvexPolygonShape2DSW::set_data(const Variant &p_data) {
ERR_FAIL_COND(p_data.get_type() != Variant::PACKED_VECTOR2_ARRAY && p_data.get_type() != Variant::PACKED_FLOAT32_ARRAY);
- if (points)
+ if (points) {
memdelete_arr(points);
+ }
points = nullptr;
point_count = 0;
@@ -621,8 +634,9 @@ void ConvexPolygonShape2DSW::set_data(const Variant &p_data) {
ERR_FAIL_COND(point_count == 0);
Rect2 aabb;
aabb.position = points[0].pos;
- for (int i = 1; i < point_count; i++)
+ for (int i = 1; i < point_count; i++) {
aabb.expand_to(points[i].pos);
+ }
configure(aabb);
}
@@ -645,8 +659,9 @@ ConvexPolygonShape2DSW::ConvexPolygonShape2DSW() {
}
ConvexPolygonShape2DSW::~ConvexPolygonShape2DSW() {
- if (points)
+ if (points) {
memdelete_arr(points);
+ }
}
//////////////////////////////////////////////////
@@ -754,19 +769,22 @@ bool ConcavePolygonShape2DSW::intersect_segment(const Vector2 &p_begin, const Ve
if (level == 0) {
done = true;
break;
- } else
+ } else {
level--;
+ }
}
continue;
}
- if (done)
+ if (done) {
break;
+ }
}
if (inters) {
- if (n.dot(r_normal) > 0)
+ if (n.dot(r_normal) > 0) {
r_normal = -r_normal;
+ }
}
return inters;
@@ -966,10 +984,11 @@ void ConcavePolygonShape2DSW::cull(const Rect2 &p_local_aabb, Callback p_callbac
}
continue;
case VISIT_DONE_BIT: {
- if (level == 0)
+ if (level == 0) {
return;
- else
+ } else {
level--;
+ }
}
continue;
}
diff --git a/servers/physics_2d/shape_2d_sw.h b/servers/physics_2d/shape_2d_sw.h
index 97a051ca65..eca284f7a4 100644
--- a/servers/physics_2d/shape_2d_sw.h
+++ b/servers/physics_2d/shape_2d_sw.h
@@ -100,8 +100,9 @@ public:
_FORCE_INLINE_ void get_supports_transformed_cast(const Vector2 &p_cast, const Vector2 &p_normal, const Transform2D &p_xform, Vector2 *r_supports, int &r_amount) const {
get_supports(p_xform.basis_xform_inv(p_normal).normalized(), r_supports, r_amount);
- for (int i = 0; i < r_amount; i++)
+ for (int i = 0; i < r_amount; i++) {
r_supports[i] = p_xform.xform(r_supports[i]);
+ }
if (r_amount == 1) {
if (Math::abs(p_normal.dot(p_cast.normalized())) < (1.0 - _SEGMENT_IS_VALID_SUPPORT_THRESHOLD)) {
@@ -325,10 +326,12 @@ public:
for (int i = 0; i < 4; i++) {
real_t d = p_normal.dot(p_transform.xform(Vector2(((i & 1) * 2 - 1) * half_extents.x, ((i >> 1) * 2 - 1) * half_extents.y)));
- if (d > r_max)
+ if (d > r_max) {
r_max = d;
- if (d < r_min)
+ }
+ if (d < r_min) {
r_min = d;
+ }
}
}
@@ -452,10 +455,12 @@ public:
r_min = r_max = p_normal.dot(p_transform.xform(points[0].pos));
for (int i = 1; i < point_count; i++) {
real_t d = p_normal.dot(p_transform.xform(points[i].pos));
- if (d > r_max)
+ if (d > r_max) {
r_max = d;
- if (d < r_min)
+ }
+ if (d < r_min) {
r_min = d;
+ }
}
}
diff --git a/servers/physics_2d/space_2d_sw.cpp b/servers/physics_2d/space_2d_sw.cpp
index 97bbc0f8f2..f4a21da254 100644
--- a/servers/physics_2d/space_2d_sw.cpp
+++ b/servers/physics_2d/space_2d_sw.cpp
@@ -39,18 +39,21 @@ _FORCE_INLINE_ static bool _can_collide_with(CollisionObject2DSW *p_object, uint
return false;
}
- if (p_object->get_type() == CollisionObject2DSW::TYPE_AREA && !p_collide_with_areas)
+ if (p_object->get_type() == CollisionObject2DSW::TYPE_AREA && !p_collide_with_areas) {
return false;
+ }
- if (p_object->get_type() == CollisionObject2DSW::TYPE_BODY && !p_collide_with_bodies)
+ if (p_object->get_type() == CollisionObject2DSW::TYPE_BODY && !p_collide_with_bodies) {
return false;
+ }
return true;
}
int PhysicsDirectSpaceState2DSW::_intersect_point_impl(const Vector2 &p_point, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas, bool p_pick_point, bool p_filter_by_canvas, ObjectID p_canvas_instance_id) {
- if (p_result_max <= 0)
+ if (p_result_max <= 0) {
return 0;
+ }
Rect2 aabb;
aabb.position = p_point - Vector2(0.00001, 0.00001);
@@ -61,19 +64,23 @@ int PhysicsDirectSpaceState2DSW::_intersect_point_impl(const Vector2 &p_point, S
int cc = 0;
for (int i = 0; i < amount; i++) {
- if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas))
+ if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas)) {
continue;
+ }
- if (p_exclude.has(space->intersection_query_results[i]->get_self()))
+ if (p_exclude.has(space->intersection_query_results[i]->get_self())) {
continue;
+ }
const CollisionObject2DSW *col_obj = space->intersection_query_results[i];
- if (p_pick_point && !col_obj->is_pickable())
+ if (p_pick_point && !col_obj->is_pickable()) {
continue;
+ }
- if (p_filter_by_canvas && col_obj->get_canvas_instance_id() != p_canvas_instance_id)
+ if (p_filter_by_canvas && col_obj->get_canvas_instance_id() != p_canvas_instance_id) {
continue;
+ }
int shape_idx = space->intersection_query_subindex_results[i];
@@ -81,15 +88,18 @@ int PhysicsDirectSpaceState2DSW::_intersect_point_impl(const Vector2 &p_point, S
Vector2 local_point = (col_obj->get_transform() * col_obj->get_shape_transform(shape_idx)).affine_inverse().xform(p_point);
- if (!shape->contains_point(local_point))
+ if (!shape->contains_point(local_point)) {
continue;
+ }
- if (cc >= p_result_max)
+ if (cc >= p_result_max) {
continue;
+ }
r_results[cc].collider_id = col_obj->get_instance_id();
- if (r_results[cc].collider_id.is_valid())
+ if (r_results[cc].collider_id.is_valid()) {
r_results[cc].collider = ObjectDB::get_instance(r_results[cc].collider_id);
+ }
r_results[cc].rid = col_obj->get_self();
r_results[cc].shape = shape_idx;
r_results[cc].metadata = col_obj->get_shape_metadata(shape_idx);
@@ -128,11 +138,13 @@ bool PhysicsDirectSpaceState2DSW::intersect_ray(const Vector2 &p_from, const Vec
real_t min_d = 1e10;
for (int i = 0; i < amount; i++) {
- if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas))
+ if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas)) {
continue;
+ }
- if (p_exclude.has(space->intersection_query_results[i]->get_self()))
+ if (p_exclude.has(space->intersection_query_results[i]->get_self())) {
continue;
+ }
const CollisionObject2DSW *col_obj = space->intersection_query_results[i];
@@ -169,12 +181,14 @@ bool PhysicsDirectSpaceState2DSW::intersect_ray(const Vector2 &p_from, const Vec
}
}
- if (!collided)
+ if (!collided) {
return false;
+ }
r_result.collider_id = res_obj->get_instance_id();
- if (r_result.collider_id.is_valid())
+ if (r_result.collider_id.is_valid()) {
r_result.collider = ObjectDB::get_instance(r_result.collider_id);
+ }
r_result.normal = res_normal;
r_result.metadata = res_obj->get_shape_metadata(res_shape);
r_result.position = res_point;
@@ -185,8 +199,9 @@ bool PhysicsDirectSpaceState2DSW::intersect_ray(const Vector2 &p_from, const Vec
}
int PhysicsDirectSpaceState2DSW::intersect_shape(const RID &p_shape, const Transform2D &p_xform, const Vector2 &p_motion, real_t p_margin, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas) {
- if (p_result_max <= 0)
+ if (p_result_max <= 0) {
return 0;
+ }
Shape2DSW *shape = PhysicsServer2DSW::singletonsw->shape_owner.getornull(p_shape);
ERR_FAIL_COND_V(!shape, 0);
@@ -199,24 +214,29 @@ int PhysicsDirectSpaceState2DSW::intersect_shape(const RID &p_shape, const Trans
int cc = 0;
for (int i = 0; i < amount; i++) {
- if (cc >= p_result_max)
+ if (cc >= p_result_max) {
break;
+ }
- if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas))
+ if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas)) {
continue;
+ }
- if (p_exclude.has(space->intersection_query_results[i]->get_self()))
+ if (p_exclude.has(space->intersection_query_results[i]->get_self())) {
continue;
+ }
const CollisionObject2DSW *col_obj = space->intersection_query_results[i];
int shape_idx = space->intersection_query_subindex_results[i];
- if (!CollisionSolver2DSW::solve(shape, p_xform, p_motion, col_obj->get_shape(shape_idx), col_obj->get_transform() * col_obj->get_shape_transform(shape_idx), Vector2(), nullptr, nullptr, nullptr, p_margin))
+ if (!CollisionSolver2DSW::solve(shape, p_xform, p_motion, col_obj->get_shape(shape_idx), col_obj->get_transform() * col_obj->get_shape_transform(shape_idx), Vector2(), nullptr, nullptr, nullptr, p_margin)) {
continue;
+ }
r_results[cc].collider_id = col_obj->get_instance_id();
- if (r_results[cc].collider_id.is_valid())
+ if (r_results[cc].collider_id.is_valid()) {
r_results[cc].collider = ObjectDB::get_instance(r_results[cc].collider_id);
+ }
r_results[cc].rid = col_obj->get_self();
r_results[cc].shape = shape_idx;
r_results[cc].metadata = col_obj->get_shape_metadata(shape_idx);
@@ -241,11 +261,13 @@ bool PhysicsDirectSpaceState2DSW::cast_motion(const RID &p_shape, const Transfor
real_t best_unsafe = 1;
for (int i = 0; i < amount; i++) {
- if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas))
+ if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas)) {
continue;
+ }
- if (p_exclude.has(space->intersection_query_results[i]->get_self()))
+ if (p_exclude.has(space->intersection_query_results[i]->get_self())) {
continue; //ignore excluded
+ }
const CollisionObject2DSW *col_obj = space->intersection_query_results[i];
int shape_idx = space->intersection_query_subindex_results[i];
@@ -293,8 +315,9 @@ bool PhysicsDirectSpaceState2DSW::cast_motion(const RID &p_shape, const Transfor
}
bool PhysicsDirectSpaceState2DSW::collide_shape(RID p_shape, const Transform2D &p_shape_xform, const Vector2 &p_motion, real_t p_margin, Vector2 *r_results, int p_result_max, int &r_result_count, const Set<RID> &p_exclude, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas) {
- if (p_result_max <= 0)
+ if (p_result_max <= 0) {
return false;
+ }
Shape2DSW *shape = PhysicsServer2DSW::singletonsw->shape_owner.getornull(p_shape);
ERR_FAIL_COND_V(!shape, 0);
@@ -318,14 +341,16 @@ bool PhysicsDirectSpaceState2DSW::collide_shape(RID p_shape, const Transform2D &
PhysicsServer2DSW::CollCbkData *cbkptr = &cbk;
for (int i = 0; i < amount; i++) {
- if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas))
+ if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas)) {
continue;
+ }
const CollisionObject2DSW *col_obj = space->intersection_query_results[i];
int shape_idx = space->intersection_query_subindex_results[i];
- if (p_exclude.has(col_obj->get_self()))
+ if (p_exclude.has(col_obj->get_self())) {
continue;
+ }
cbk.valid_dir = Vector2();
cbk.valid_depth = 0;
@@ -359,20 +384,24 @@ static void _rest_cbk_result(const Vector2 &p_point_A, const Vector2 &p_point_B,
_RestCallbackData2D *rd = (_RestCallbackData2D *)p_userdata;
if (rd->valid_dir != Vector2()) {
- if (p_point_A.distance_squared_to(p_point_B) > rd->valid_depth * rd->valid_depth)
+ if (p_point_A.distance_squared_to(p_point_B) > rd->valid_depth * rd->valid_depth) {
return;
- if (rd->valid_dir.dot((p_point_A - p_point_B).normalized()) < Math_PI * 0.25)
+ }
+ if (rd->valid_dir.dot((p_point_A - p_point_B).normalized()) < Math_PI * 0.25) {
return;
+ }
}
Vector2 contact_rel = p_point_B - p_point_A;
real_t len = contact_rel.length();
- if (len < rd->min_allowed_depth)
+ if (len < rd->min_allowed_depth) {
return;
+ }
- if (len <= rd->best_len)
+ if (len <= rd->best_len) {
return;
+ }
rd->best_len = len;
rd->best_contact = p_point_B;
@@ -399,14 +428,16 @@ bool PhysicsDirectSpaceState2DSW::rest_info(RID p_shape, const Transform2D &p_sh
rcd.min_allowed_depth = space->test_motion_min_contact_depth;
for (int i = 0; i < amount; i++) {
- if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas))
+ if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas)) {
continue;
+ }
const CollisionObject2DSW *col_obj = space->intersection_query_results[i];
int shape_idx = space->intersection_query_subindex_results[i];
- if (p_exclude.has(col_obj->get_self()))
+ if (p_exclude.has(col_obj->get_self())) {
continue;
+ }
rcd.valid_dir = Vector2();
rcd.valid_depth = 0;
@@ -414,12 +445,14 @@ bool PhysicsDirectSpaceState2DSW::rest_info(RID p_shape, const Transform2D &p_sh
rcd.shape = shape_idx;
rcd.local_shape = 0;
bool sc = CollisionSolver2DSW::solve(shape, p_shape_xform, p_motion, col_obj->get_shape(shape_idx), col_obj->get_transform() * col_obj->get_shape_transform(shape_idx), Vector2(), _rest_cbk_result, &rcd, nullptr, p_margin);
- if (!sc)
+ if (!sc) {
continue;
+ }
}
- if (rcd.best_len == 0 || !rcd.best_object)
+ if (rcd.best_len == 0 || !rcd.best_object) {
return false;
+ }
r_info->collider_id = rcd.best_object->get_instance_id();
r_info->shape = rcd.best_shape;
@@ -451,16 +484,17 @@ int Space2DSW::_cull_aabb_for_body(Body2DSW *p_body, const Rect2 &p_aabb) {
for (int i = 0; i < amount; i++) {
bool keep = true;
- if (intersection_query_results[i] == p_body)
+ if (intersection_query_results[i] == p_body) {
keep = false;
- else if (intersection_query_results[i]->get_type() == CollisionObject2DSW::TYPE_AREA)
+ } else if (intersection_query_results[i]->get_type() == CollisionObject2DSW::TYPE_AREA) {
keep = false;
- else if ((static_cast<Body2DSW *>(intersection_query_results[i])->test_collision_mask(p_body)) == 0)
+ } else if ((static_cast<Body2DSW *>(intersection_query_results[i])->test_collision_mask(p_body)) == 0) {
keep = false;
- else if (static_cast<Body2DSW *>(intersection_query_results[i])->has_exception(p_body->get_self()) || p_body->has_exception(intersection_query_results[i]->get_self()))
+ } else if (static_cast<Body2DSW *>(intersection_query_results[i])->has_exception(p_body->get_self()) || p_body->has_exception(intersection_query_results[i]->get_self())) {
keep = false;
- else if (static_cast<Body2DSW *>(intersection_query_results[i])->is_shape_set_as_disabled(intersection_query_subindex_results[i]))
+ } else if (static_cast<Body2DSW *>(intersection_query_results[i])->is_shape_set_as_disabled(intersection_query_subindex_results[i])) {
keep = false;
+ }
if (!keep) {
if (i < amount - 1) {
@@ -482,11 +516,13 @@ int Space2DSW::test_body_ray_separation(Body2DSW *p_body, const Transform2D &p_t
bool shapes_found = false;
for (int i = 0; i < p_body->get_shape_count(); i++) {
- if (p_body->is_shape_set_as_disabled(i))
+ if (p_body->is_shape_set_as_disabled(i)) {
continue;
+ }
- if (p_body->get_shape(i)->get_type() != PhysicsServer2D::SHAPE_RAY)
+ if (p_body->get_shape(i)->get_type() != PhysicsServer2D::SHAPE_RAY) {
continue;
+ }
if (!shapes_found) {
body_aabb = p_body->get_shape_aabb(i);
@@ -532,13 +568,15 @@ int Space2DSW::test_body_ray_separation(Body2DSW *p_body, const Transform2D &p_t
int amount = _cull_aabb_for_body(p_body, body_aabb);
for (int j = 0; j < p_body->get_shape_count(); j++) {
- if (p_body->is_shape_set_as_disabled(j))
+ if (p_body->is_shape_set_as_disabled(j)) {
continue;
+ }
Shape2DSW *body_shape = p_body->get_shape(j);
- if (body_shape->get_type() != PhysicsServer2D::SHAPE_RAY)
+ if (body_shape->get_type() != PhysicsServer2D::SHAPE_RAY) {
continue;
+ }
Transform2D body_shape_xform = body_transform * p_body->get_shape_transform(j);
@@ -671,11 +709,13 @@ bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, co
bool shapes_found = false;
for (int i = 0; i < p_body->get_shape_count(); i++) {
- if (p_body->is_shape_set_as_disabled(i))
+ if (p_body->is_shape_set_as_disabled(i)) {
continue;
+ }
- if (p_exclude_raycast_shapes && p_body->get_shape(i)->get_type() == PhysicsServer2D::SHAPE_RAY)
+ if (p_exclude_raycast_shapes && p_body->get_shape(i)->get_type() == PhysicsServer2D::SHAPE_RAY) {
continue;
+ }
if (!shapes_found) {
body_aabb = p_body->get_shape_aabb(i);
@@ -729,8 +769,9 @@ bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, co
int amount = _cull_aabb_for_body(p_body, body_aabb);
for (int j = 0; j < p_body->get_shape_count(); j++) {
- if (p_body->is_shape_set_as_disabled(j))
+ if (p_body->is_shape_set_as_disabled(j)) {
continue;
+ }
Shape2DSW *body_shape = p_body->get_shape(j);
if (p_exclude_raycast_shapes && body_shape->get_type() == PhysicsServer2D::SHAPE_RAY) {
@@ -840,8 +881,9 @@ bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, co
int amount = _cull_aabb_for_body(p_body, motion_aabb);
for (int body_shape_idx = 0; body_shape_idx < p_body->get_shape_count(); body_shape_idx++) {
- if (p_body->is_shape_set_as_disabled(body_shape_idx))
+ if (p_body->is_shape_set_as_disabled(body_shape_idx)) {
continue;
+ }
Shape2DSW *body_shape = p_body->get_shape(body_shape_idx);
if (p_exclude_raycast_shapes && body_shape->get_type() == PhysicsServer2D::SHAPE_RAY) {
@@ -977,8 +1019,9 @@ bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, co
int to_shape = best_shape != -1 ? best_shape + 1 : p_body->get_shape_count();
for (int j = from_shape; j < to_shape; j++) {
- if (p_body->is_shape_set_as_disabled(j))
+ if (p_body->is_shape_set_as_disabled(j)) {
continue;
+ }
Transform2D body_shape_xform = ugt * p_body->get_shape_transform(j);
Shape2DSW *body_shape = p_body->get_shape(j);
@@ -1011,8 +1054,9 @@ bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, co
break;
}
}
- if (excluded)
+ if (excluded) {
continue;
+ }
Transform2D col_obj_shape_xform = col_obj->get_transform() * col_obj->get_shape_transform(shape_idx);
@@ -1028,8 +1072,9 @@ bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, co
rcd.shape = shape_idx;
rcd.local_shape = j;
bool sc = CollisionSolver2DSW::solve(body_shape, body_shape_xform, Vector2(), against_shape, col_obj_shape_xform, Vector2(), _rest_cbk_result, &rcd, nullptr, p_margin);
- if (!sc)
+ if (!sc) {
continue;
+ }
}
}
@@ -1291,8 +1336,9 @@ Space2DSW::Space2DSW() {
direct_access = memnew(PhysicsDirectSpaceState2DSW);
direct_access->space = this;
- for (int i = 0; i < ELAPSED_TIME_MAX; i++)
+ for (int i = 0; i < ELAPSED_TIME_MAX; i++) {
elapsed_time[i] = 0;
+ }
}
Space2DSW::~Space2DSW() {
diff --git a/servers/physics_2d/space_2d_sw.h b/servers/physics_2d/space_2d_sw.h
index 79c38fd638..0a96f2f495 100644
--- a/servers/physics_2d/space_2d_sw.h
+++ b/servers/physics_2d/space_2d_sw.h
@@ -190,8 +190,9 @@ public:
void set_debug_contacts(int p_amount) { contact_debug.resize(p_amount); }
_FORCE_INLINE_ bool is_debugging_contacts() const { return !contact_debug.empty(); }
_FORCE_INLINE_ void add_debug_contact(const Vector2 &p_contact) {
- if (contact_debug_count < contact_debug.size())
+ if (contact_debug_count < contact_debug.size()) {
contact_debug.write[contact_debug_count++] = p_contact;
+ }
}
_FORCE_INLINE_ Vector<Vector2> get_debug_contacts() { return contact_debug; }
_FORCE_INLINE_ int get_debug_contact_count() { return contact_debug_count; }
diff --git a/servers/physics_2d/step_2d_sw.cpp b/servers/physics_2d/step_2d_sw.cpp
index b184e652c7..c7711bcd1d 100644
--- a/servers/physics_2d/step_2d_sw.cpp
+++ b/servers/physics_2d/step_2d_sw.cpp
@@ -38,18 +38,21 @@ void Step2DSW::_populate_island(Body2DSW *p_body, Body2DSW **p_island, Constrain
for (Map<Constraint2DSW *, int>::Element *E = p_body->get_constraint_map().front(); E; E = E->next()) {
Constraint2DSW *c = (Constraint2DSW *)E->key();
- if (c->get_island_step() == _step)
+ if (c->get_island_step() == _step) {
continue; //already processed
+ }
c->set_island_step(_step);
c->set_island_next(*p_constraint_island);
*p_constraint_island = c;
for (int i = 0; i < c->get_body_count(); i++) {
- if (i == E->get())
+ if (i == E->get()) {
continue;
+ }
Body2DSW *b = c->get_body_ptr()[i];
- if (b->get_island_step() == _step || b->get_mode() == PhysicsServer2D::BODY_MODE_STATIC || b->get_mode() == PhysicsServer2D::BODY_MODE_KINEMATIC)
+ if (b->get_island_step() == _step || b->get_mode() == PhysicsServer2D::BODY_MODE_STATIC || b->get_mode() == PhysicsServer2D::BODY_MODE_KINEMATIC) {
continue; //no go
+ }
_populate_island(c->get_body_ptr()[i], p_island, p_constraint_island);
}
}
@@ -99,8 +102,9 @@ void Step2DSW::_check_suspend(Body2DSW *p_island, real_t p_delta) {
continue; //ignore for static
}
- if (!b->sleep_test(p_delta))
+ if (!b->sleep_test(p_delta)) {
can_sleep = false;
+ }
b = b->get_island_next();
}
@@ -116,8 +120,9 @@ void Step2DSW::_check_suspend(Body2DSW *p_island, real_t p_delta) {
bool active = b->is_active();
- if (active == can_sleep)
+ if (active == can_sleep) {
b->set_active(!can_sleep);
+ }
b = b->get_island_next();
}
@@ -187,8 +192,9 @@ void Step2DSW::step(Space2DSW *p_space, real_t p_delta, int p_iterations) {
while (aml.first()) {
for (const Set<Constraint2DSW *>::Element *E = aml.first()->self()->get_constraints().front(); E; E = E->next()) {
Constraint2DSW *c = E->get();
- if (c->get_island_step() == _step)
+ if (c->get_island_step() == _step) {
continue;
+ }
c->set_island_step(_step);
c->set_island_next(nullptr);
c->set_island_list_next(constraint_island_list);
diff --git a/servers/physics_3d/area_3d_sw.cpp b/servers/physics_3d/area_3d_sw.cpp
index de4399330d..98237dd91c 100644
--- a/servers/physics_3d/area_3d_sw.cpp
+++ b/servers/physics_3d/area_3d_sw.cpp
@@ -47,13 +47,15 @@ Area3DSW::BodyKey::BodyKey(Area3DSW *p_body, uint32_t p_body_shape, uint32_t p_a
}
void Area3DSW::_shapes_changed() {
- if (!moved_list.in_list() && get_space())
+ if (!moved_list.in_list() && get_space()) {
get_space()->area_add_to_moved_list(&moved_list);
+ }
}
void Area3DSW::set_transform(const Transform &p_transform) {
- if (!moved_list.in_list() && get_space())
+ if (!moved_list.in_list() && get_space()) {
get_space()->area_add_to_moved_list(&moved_list);
+ }
_set_transform(p_transform);
_set_inv_transform(p_transform.affine_inverse());
@@ -61,10 +63,12 @@ void Area3DSW::set_transform(const Transform &p_transform) {
void Area3DSW::set_space(Space3DSW *p_space) {
if (get_space()) {
- if (monitor_query_list.in_list())
+ if (monitor_query_list.in_list()) {
get_space()->area_remove_from_monitor_query_list(&monitor_query_list);
- if (moved_list.in_list())
+ }
+ if (moved_list.in_list()) {
get_space()->area_remove_from_moved_list(&moved_list);
+ }
}
monitored_bodies.clear();
@@ -89,8 +93,9 @@ void Area3DSW::set_monitor_callback(ObjectID p_id, const StringName &p_method) {
_shape_changed();
- if (!moved_list.in_list() && get_space())
+ if (!moved_list.in_list() && get_space()) {
get_space()->area_add_to_moved_list(&moved_list);
+ }
}
void Area3DSW::set_area_monitor_callback(ObjectID p_id, const StringName &p_method) {
@@ -109,14 +114,16 @@ void Area3DSW::set_area_monitor_callback(ObjectID p_id, const StringName &p_meth
_shape_changed();
- if (!moved_list.in_list() && get_space())
+ if (!moved_list.in_list() && get_space()) {
get_space()->area_add_to_moved_list(&moved_list);
+ }
}
void Area3DSW::set_space_override_mode(PhysicsServer3D::AreaSpaceOverrideMode p_mode) {
bool do_override = p_mode != PhysicsServer3D::AREA_SPACE_OVERRIDE_DISABLED;
- if (do_override == (space_override_mode != PhysicsServer3D::AREA_SPACE_OVERRIDE_DISABLED))
+ if (do_override == (space_override_mode != PhysicsServer3D::AREA_SPACE_OVERRIDE_DISABLED)) {
return;
+ }
_unregister_shapes();
space_override_mode = p_mode;
_shape_changed();
@@ -177,13 +184,15 @@ Variant Area3DSW::get_param(PhysicsServer3D::AreaParameter p_param) const {
void Area3DSW::_queue_monitor_update() {
ERR_FAIL_COND(!get_space());
- if (!monitor_query_list.in_list())
+ if (!monitor_query_list.in_list()) {
get_space()->area_add_to_monitor_query_list(&monitor_query_list);
+ }
}
void Area3DSW::set_monitorable(bool p_monitorable) {
- if (monitorable == p_monitorable)
+ if (monitorable == p_monitorable) {
return;
+ }
monitorable = p_monitorable;
_set_static(!monitorable);
@@ -193,8 +202,9 @@ void Area3DSW::call_queries() {
if (monitor_callback_id.is_valid() && !monitored_bodies.empty()) {
Variant res[5];
Variant *resptr[5];
- for (int i = 0; i < 5; i++)
+ for (int i = 0; i < 5; i++) {
resptr[i] = &res[i];
+ }
Object *obj = ObjectDB::get_instance(monitor_callback_id);
if (!obj) {
@@ -204,8 +214,9 @@ void Area3DSW::call_queries() {
}
for (Map<BodyKey, BodyState>::Element *E = monitored_bodies.front(); E; E = E->next()) {
- if (E->get().state == 0)
+ if (E->get().state == 0) {
continue; //nothing happened
+ }
res[0] = E->get().state > 0 ? PhysicsServer3D::AREA_BODY_ADDED : PhysicsServer3D::AREA_BODY_REMOVED;
res[1] = E->key().rid;
@@ -223,8 +234,9 @@ void Area3DSW::call_queries() {
if (area_monitor_callback_id.is_valid() && !monitored_areas.empty()) {
Variant res[5];
Variant *resptr[5];
- for (int i = 0; i < 5; i++)
+ for (int i = 0; i < 5; i++) {
resptr[i] = &res[i];
+ }
Object *obj = ObjectDB::get_instance(area_monitor_callback_id);
if (!obj) {
@@ -234,8 +246,9 @@ void Area3DSW::call_queries() {
}
for (Map<BodyKey, BodyState>::Element *E = monitored_areas.front(); E; E = E->next()) {
- if (E->get().state == 0)
+ if (E->get().state == 0) {
continue; //nothing happened
+ }
res[0] = E->get().state > 0 ? PhysicsServer3D::AREA_BODY_ADDED : PhysicsServer3D::AREA_BODY_REMOVED;
res[1] = E->key().rid;
diff --git a/servers/physics_3d/area_3d_sw.h b/servers/physics_3d/area_3d_sw.h
index d85a7fc509..6af3976167 100644
--- a/servers/physics_3d/area_3d_sw.h
+++ b/servers/physics_3d/area_3d_sw.h
@@ -71,10 +71,12 @@ class Area3DSW : public CollisionObject3DSW {
if (rid == p_key.rid) {
if (body_shape == p_key.body_shape) {
return area_shape < p_key.area_shape;
- } else
+ } else {
return body_shape < p_key.body_shape;
- } else
+ }
+ } else {
return rid < p_key.rid;
+ }
}
_FORCE_INLINE_ BodyKey() {}
@@ -167,29 +169,33 @@ public:
void Area3DSW::add_body_to_query(Body3DSW *p_body, uint32_t p_body_shape, uint32_t p_area_shape) {
BodyKey bk(p_body, p_body_shape, p_area_shape);
monitored_bodies[bk].inc();
- if (!monitor_query_list.in_list())
+ if (!monitor_query_list.in_list()) {
_queue_monitor_update();
+ }
}
void Area3DSW::remove_body_from_query(Body3DSW *p_body, uint32_t p_body_shape, uint32_t p_area_shape) {
BodyKey bk(p_body, p_body_shape, p_area_shape);
monitored_bodies[bk].dec();
- if (!monitor_query_list.in_list())
+ if (!monitor_query_list.in_list()) {
_queue_monitor_update();
+ }
}
void Area3DSW::add_area_to_query(Area3DSW *p_area, uint32_t p_area_shape, uint32_t p_self_shape) {
BodyKey bk(p_area, p_area_shape, p_self_shape);
monitored_areas[bk].inc();
- if (!monitor_query_list.in_list())
+ if (!monitor_query_list.in_list()) {
_queue_monitor_update();
+ }
}
void Area3DSW::remove_area_from_query(Area3DSW *p_area, uint32_t p_area_shape, uint32_t p_self_shape) {
BodyKey bk(p_area, p_area_shape, p_self_shape);
monitored_areas[bk].dec();
- if (!monitor_query_list.in_list())
+ if (!monitor_query_list.in_list()) {
_queue_monitor_update();
+ }
}
#endif // AREA__SW_H
diff --git a/servers/physics_3d/area_pair_3d_sw.cpp b/servers/physics_3d/area_pair_3d_sw.cpp
index 36d460675e..a5fb20fe2b 100644
--- a/servers/physics_3d/area_pair_3d_sw.cpp
+++ b/servers/physics_3d/area_pair_3d_sw.cpp
@@ -42,16 +42,20 @@ bool AreaPair3DSW::setup(real_t p_step) {
if (result != colliding) {
if (result) {
- if (area->get_space_override_mode() != PhysicsServer3D::AREA_SPACE_OVERRIDE_DISABLED)
+ if (area->get_space_override_mode() != PhysicsServer3D::AREA_SPACE_OVERRIDE_DISABLED) {
body->add_area(area);
- if (area->has_monitor_callback())
+ }
+ if (area->has_monitor_callback()) {
area->add_body_to_query(body, body_shape, area_shape);
+ }
} else {
- if (area->get_space_override_mode() != PhysicsServer3D::AREA_SPACE_OVERRIDE_DISABLED)
+ if (area->get_space_override_mode() != PhysicsServer3D::AREA_SPACE_OVERRIDE_DISABLED) {
body->remove_area(area);
- if (area->has_monitor_callback())
+ }
+ if (area->has_monitor_callback()) {
area->remove_body_from_query(body, body_shape, area_shape);
+ }
}
colliding = result;
@@ -71,16 +75,19 @@ AreaPair3DSW::AreaPair3DSW(Body3DSW *p_body, int p_body_shape, Area3DSW *p_area,
colliding = false;
body->add_constraint(this, 0);
area->add_constraint(this);
- if (p_body->get_mode() == PhysicsServer3D::BODY_MODE_KINEMATIC)
+ if (p_body->get_mode() == PhysicsServer3D::BODY_MODE_KINEMATIC) {
p_body->set_active(true);
+ }
}
AreaPair3DSW::~AreaPair3DSW() {
if (colliding) {
- if (area->get_space_override_mode() != PhysicsServer3D::AREA_SPACE_OVERRIDE_DISABLED)
+ if (area->get_space_override_mode() != PhysicsServer3D::AREA_SPACE_OVERRIDE_DISABLED) {
body->remove_area(area);
- if (area->has_monitor_callback())
+ }
+ if (area->has_monitor_callback()) {
area->remove_body_from_query(body, body_shape, area_shape);
+ }
}
body->remove_constraint(this);
area->remove_constraint(this);
@@ -98,18 +105,22 @@ bool Area2Pair3DSW::setup(real_t p_step) {
if (result != colliding) {
if (result) {
- if (area_b->has_area_monitor_callback() && area_a->is_monitorable())
+ if (area_b->has_area_monitor_callback() && area_a->is_monitorable()) {
area_b->add_area_to_query(area_a, shape_a, shape_b);
+ }
- if (area_a->has_area_monitor_callback() && area_b->is_monitorable())
+ if (area_a->has_area_monitor_callback() && area_b->is_monitorable()) {
area_a->add_area_to_query(area_b, shape_b, shape_a);
+ }
} else {
- if (area_b->has_area_monitor_callback() && area_a->is_monitorable())
+ if (area_b->has_area_monitor_callback() && area_a->is_monitorable()) {
area_b->remove_area_from_query(area_a, shape_a, shape_b);
+ }
- if (area_a->has_area_monitor_callback() && area_b->is_monitorable())
+ if (area_a->has_area_monitor_callback() && area_b->is_monitorable()) {
area_a->remove_area_from_query(area_b, shape_b, shape_a);
+ }
}
colliding = result;
@@ -133,11 +144,13 @@ Area2Pair3DSW::Area2Pair3DSW(Area3DSW *p_area_a, int p_shape_a, Area3DSW *p_area
Area2Pair3DSW::~Area2Pair3DSW() {
if (colliding) {
- if (area_b->has_area_monitor_callback())
+ if (area_b->has_area_monitor_callback()) {
area_b->remove_area_from_query(area_a, shape_a, shape_b);
+ }
- if (area_a->has_area_monitor_callback())
+ if (area_a->has_area_monitor_callback()) {
area_a->remove_area_from_query(area_b, shape_b, shape_a);
+ }
}
area_a->remove_constraint(this);
diff --git a/servers/physics_3d/body_3d_sw.cpp b/servers/physics_3d/body_3d_sw.cpp
index c01e55c4dd..a3bdc96c9f 100644
--- a/servers/physics_3d/body_3d_sw.cpp
+++ b/servers/physics_3d/body_3d_sw.cpp
@@ -33,8 +33,9 @@
#include "space_3d_sw.h"
void Body3DSW::_update_inertia() {
- if (get_space() && !inertia_update_list.in_list())
+ if (get_space() && !inertia_update_list.in_list()) {
get_space()->body_add_to_inertia_update_list(&inertia_update_list);
+ }
}
void Body3DSW::_update_transform_dependant() {
@@ -105,10 +106,11 @@ void Body3DSW::update_inertias() {
principal_inertia_axes_local = inertia_tensor.diagonalize().transposed();
_inv_inertia = inertia_tensor.get_main_diagonal().inverse();
- if (mass)
+ if (mass) {
_inv_mass = 1.0 / mass;
- else
+ } else {
_inv_mass = 0;
+ }
} break;
@@ -130,18 +132,22 @@ void Body3DSW::update_inertias() {
}
void Body3DSW::set_active(bool p_active) {
- if (active == p_active)
+ if (active == p_active) {
return;
+ }
active = p_active;
if (!p_active) {
- if (get_space())
+ if (get_space()) {
get_space()->body_remove_from_active_list(&active_list);
+ }
} else {
- if (mode == PhysicsServer3D::BODY_MODE_STATIC)
+ if (mode == PhysicsServer3D::BODY_MODE_STATIC) {
return; //static bodies can't become active
- if (get_space())
+ }
+ if (get_space()) {
get_space()->body_add_to_active_list(&active_list);
+ }
//still_time=0;
}
@@ -284,8 +290,9 @@ void Body3DSW::set_state(PhysicsServer3D::BodyState p_state, const Variant &p_va
Transform t = p_variant;
t.orthonormalize();
new_transform = get_transform(); //used as old to compute motion
- if (new_transform == t)
+ if (new_transform == t) {
break;
+ }
_set_transform(t);
_set_inv_transform(get_transform().inverse());
}
@@ -311,8 +318,9 @@ void Body3DSW::set_state(PhysicsServer3D::BodyState p_state, const Variant &p_va
} break;
case PhysicsServer3D::BODY_STATE_SLEEPING: {
//?
- if (mode == PhysicsServer3D::BODY_MODE_STATIC || mode == PhysicsServer3D::BODY_MODE_KINEMATIC)
+ if (mode == PhysicsServer3D::BODY_MODE_STATIC || mode == PhysicsServer3D::BODY_MODE_KINEMATIC) {
break;
+ }
bool do_sleep = p_variant;
if (do_sleep) {
linear_velocity = Vector3();
@@ -326,8 +334,9 @@ void Body3DSW::set_state(PhysicsServer3D::BodyState p_state, const Variant &p_va
} break;
case PhysicsServer3D::BODY_STATE_CAN_SLEEP: {
can_sleep = p_variant;
- if (mode == PhysicsServer3D::BODY_MODE_RIGID && !active && !can_sleep)
+ if (mode == PhysicsServer3D::BODY_MODE_RIGID && !active && !can_sleep) {
set_active(true);
+ }
} break;
}
@@ -357,20 +366,24 @@ Variant Body3DSW::get_state(PhysicsServer3D::BodyState p_state) const {
void Body3DSW::set_space(Space3DSW *p_space) {
if (get_space()) {
- if (inertia_update_list.in_list())
+ if (inertia_update_list.in_list()) {
get_space()->body_remove_from_inertia_update_list(&inertia_update_list);
- if (active_list.in_list())
+ }
+ if (active_list.in_list()) {
get_space()->body_remove_from_active_list(&active_list);
- if (direct_state_query_list.in_list())
+ }
+ if (direct_state_query_list.in_list()) {
get_space()->body_remove_from_state_query_list(&direct_state_query_list);
+ }
}
_set_space(p_space);
if (get_space()) {
_update_inertia();
- if (active)
+ if (active) {
get_space()->body_add_to_active_list(&active_list);
+ }
/*
_update_queries();
if (is_active()) {
@@ -412,8 +425,9 @@ bool Body3DSW::is_axis_locked(PhysicsServer3D::BodyAxis p_axis) const {
}
void Body3DSW::integrate_forces(real_t p_step) {
- if (mode == PhysicsServer3D::BODY_MODE_STATIC)
+ if (mode == PhysicsServer3D::BODY_MODE_STATIC) {
return;
+ }
Area3DSW *def_area = get_space()->get_default_area();
// AreaSW *damp_area = def_area;
@@ -458,15 +472,17 @@ void Body3DSW::integrate_forces(real_t p_step) {
gravity *= gravity_scale;
// If less than 0, override dampenings with that of the Body
- if (angular_damp >= 0)
+ if (angular_damp >= 0) {
area_angular_damp = angular_damp;
+ }
/*
else
area_angular_damp=damp_area->get_angular_damp();
*/
- if (linear_damp >= 0)
+ if (linear_damp >= 0) {
area_linear_damp = linear_damp;
+ }
/*
else
area_linear_damp=damp_area->get_linear_damp();
@@ -501,13 +517,15 @@ void Body3DSW::integrate_forces(real_t p_step) {
real_t damp = 1.0 - p_step * area_linear_damp;
- if (damp < 0) // reached zero in the given time
+ if (damp < 0) { // reached zero in the given time
damp = 0;
+ }
real_t angular_damp = 1.0 - p_step * area_angular_damp;
- if (angular_damp < 0) // reached zero in the given time
+ if (angular_damp < 0) { // reached zero in the given time
angular_damp = 0;
+ }
linear_velocity *= damp;
angular_velocity *= angular_damp;
@@ -540,11 +558,13 @@ void Body3DSW::integrate_forces(real_t p_step) {
}
void Body3DSW::integrate_velocities(real_t p_step) {
- if (mode == PhysicsServer3D::BODY_MODE_STATIC)
+ if (mode == PhysicsServer3D::BODY_MODE_STATIC) {
return;
+ }
- if (fi_callback)
+ if (fi_callback) {
get_space()->body_add_to_state_query_list(&direct_state_query_list);
+ }
//apply axis lock linear
for (int i = 0; i < 3; i++) {
@@ -565,8 +585,9 @@ void Body3DSW::integrate_velocities(real_t p_step) {
if (mode == PhysicsServer3D::BODY_MODE_KINEMATIC) {
_set_transform(new_transform, false);
_set_inv_transform(new_transform.affine_inverse());
- if (contacts.size() == 0 && linear_velocity == Vector3() && angular_velocity == Vector3())
+ if (contacts.size() == 0 && linear_velocity == Vector3() && angular_velocity == Vector3()) {
set_active(false); //stopped moving, deactivate
+ }
return;
}
@@ -647,14 +668,17 @@ void Body3DSW::wakeup_neighbours() {
int bc = c->get_body_count();
for (int i = 0; i < bc; i++) {
- if (i == E->get())
+ if (i == E->get()) {
continue;
+ }
Body3DSW *b = n[i];
- if (b->mode != PhysicsServer3D::BODY_MODE_RIGID)
+ if (b->mode != PhysicsServer3D::BODY_MODE_RIGID) {
continue;
+ }
- if (!b->is_active())
+ if (!b->is_active()) {
b->set_active(true);
+ }
}
}
}
@@ -680,12 +704,13 @@ void Body3DSW::call_queries() {
}
bool Body3DSW::sleep_test(real_t p_step) {
- if (mode == PhysicsServer3D::BODY_MODE_STATIC || mode == PhysicsServer3D::BODY_MODE_KINEMATIC)
+ if (mode == PhysicsServer3D::BODY_MODE_STATIC || mode == PhysicsServer3D::BODY_MODE_KINEMATIC) {
return true; //
- else if (mode == PhysicsServer3D::BODY_MODE_CHARACTER)
+ } else if (mode == PhysicsServer3D::BODY_MODE_CHARACTER) {
return !active; // characters don't sleep unless asked to sleep
- else if (!can_sleep)
+ } else if (!can_sleep) {
return false;
+ }
if (Math::abs(angular_velocity.length()) < get_space()->get_body_angular_velocity_sleep_threshold() && Math::abs(linear_velocity.length_squared()) < get_space()->get_body_linear_velocity_sleep_threshold() * get_space()->get_body_linear_velocity_sleep_threshold()) {
still_time += p_step;
@@ -753,8 +778,9 @@ Body3DSW::Body3DSW() :
}
Body3DSW::~Body3DSW() {
- if (fi_callback)
+ if (fi_callback) {
memdelete(fi_callback);
+ }
}
PhysicsDirectBodyState3DSW *PhysicsDirectBodyState3DSW::singleton = nullptr;
diff --git a/servers/physics_3d/body_3d_sw.h b/servers/physics_3d/body_3d_sw.h
index 2ce8f99428..483ea58620 100644
--- a/servers/physics_3d/body_3d_sw.h
+++ b/servers/physics_3d/body_3d_sw.h
@@ -163,16 +163,18 @@ public:
int index = areas.find(AreaCMP(p_area));
if (index > -1) {
areas.write[index].refCount -= 1;
- if (areas[index].refCount < 1)
+ if (areas[index].refCount < 1) {
areas.remove(index);
+ }
}
}
_FORCE_INLINE_ void set_max_contacts_reported(int p_size) {
contacts.resize(p_size);
contact_count = 0;
- if (mode == PhysicsServer3D::BODY_MODE_KINEMATIC && p_size)
+ if (mode == PhysicsServer3D::BODY_MODE_KINEMATIC && p_size) {
set_active(true);
+ }
}
_FORCE_INLINE_ int get_max_contacts_reported() const { return contacts.size(); }
@@ -259,8 +261,9 @@ public:
_FORCE_INLINE_ bool is_active() const { return active; }
_FORCE_INLINE_ void wakeup() {
- if ((!get_space()) || mode == PhysicsServer3D::BODY_MODE_STATIC || mode == PhysicsServer3D::BODY_MODE_KINEMATIC)
+ if ((!get_space()) || mode == PhysicsServer3D::BODY_MODE_STATIC || mode == PhysicsServer3D::BODY_MODE_KINEMATIC) {
return;
+ }
set_active(true);
}
@@ -332,8 +335,9 @@ public:
void Body3DSW::add_contact(const Vector3 &p_local_pos, const Vector3 &p_local_normal, real_t p_depth, int p_local_shape, const Vector3 &p_collider_pos, int p_collider_shape, ObjectID p_collider_instance_id, const RID &p_collider, const Vector3 &p_collider_velocity_at_pos) {
int c_max = contacts.size();
- if (c_max == 0)
+ if (c_max == 0) {
return;
+ }
Contact *c = contacts.ptrw();
@@ -354,8 +358,9 @@ void Body3DSW::add_contact(const Vector3 &p_local_pos, const Vector3 &p_local_no
if (least_deep >= 0 && least_depth < p_depth) {
idx = least_deep;
}
- if (idx == -1)
+ if (idx == -1) {
return; //none least deepe than this
+ }
}
c[idx].local_pos = p_local_pos;
diff --git a/servers/physics_3d/body_pair_3d_sw.cpp b/servers/physics_3d/body_pair_3d_sw.cpp
index e7c6738698..a4f86badbe 100644
--- a/servers/physics_3d/body_pair_3d_sw.cpp
+++ b/servers/physics_3d/body_pair_3d_sw.cpp
@@ -162,8 +162,9 @@ void BodyPair3DSW::validate_contacts() {
bool BodyPair3DSW::_test_ccd(real_t p_step, Body3DSW *p_A, int p_shape_A, const Transform &p_xform_A, Body3DSW *p_B, int p_shape_B, const Transform &p_xform_B) {
Vector3 motion = p_A->get_linear_velocity() * p_step;
real_t mlen = motion.length();
- if (mlen < CMP_EPSILON)
+ if (mlen < CMP_EPSILON) {
return false;
+ }
Vector3 mnormal = motion / mlen;
@@ -257,12 +258,13 @@ bool BodyPair3DSW::setup(real_t p_step) {
real_t bias = (real_t)0.3;
if (shape_A_ptr->get_custom_bias() || shape_B_ptr->get_custom_bias()) {
- if (shape_A_ptr->get_custom_bias() == 0)
+ if (shape_A_ptr->get_custom_bias() == 0) {
bias = shape_B_ptr->get_custom_bias();
- else if (shape_B_ptr->get_custom_bias() == 0)
+ } else if (shape_B_ptr->get_custom_bias() == 0) {
bias = shape_A_ptr->get_custom_bias();
- else
+ } else {
bias = (shape_B_ptr->get_custom_bias() + shape_A_ptr->get_custom_bias()) * 0.5;
+ }
}
real_t inv_dt = 1.0 / p_step;
@@ -338,13 +340,15 @@ bool BodyPair3DSW::setup(real_t p_step) {
}
void BodyPair3DSW::solve(real_t p_step) {
- if (!collided)
+ if (!collided) {
return;
+ }
for (int i = 0; i < contact_count; i++) {
Contact &c = contacts[i];
- if (!c.active)
+ if (!c.active) {
continue;
+ }
c.active = false; //try to deactivate, will activate itself if still needed
diff --git a/servers/physics_3d/broad_phase_3d_basic.cpp b/servers/physics_3d/broad_phase_3d_basic.cpp
index 68bf0da53e..0f271b33af 100644
--- a/servers/physics_3d/broad_phase_3d_basic.cpp
+++ b/servers/physics_3d/broad_phase_3d_basic.cpp
@@ -107,8 +107,9 @@ int BroadPhase3DBasic::cull_point(const Vector3 &p_point, CollisionObject3DSW **
p_results[rc] = E->get().owner;
p_result_indices[rc] = E->get().subindex;
rc++;
- if (rc >= p_max_results)
+ if (rc >= p_max_results) {
break;
+ }
}
}
@@ -124,8 +125,9 @@ int BroadPhase3DBasic::cull_segment(const Vector3 &p_from, const Vector3 &p_to,
p_results[rc] = E->get().owner;
p_result_indices[rc] = E->get().subindex;
rc++;
- if (rc >= p_max_results)
+ if (rc >= p_max_results) {
break;
+ }
}
}
@@ -141,8 +143,9 @@ int BroadPhase3DBasic::cull_aabb(const AABB &p_aabb, CollisionObject3DSW **p_res
p_results[rc] = E->get().owner;
p_result_indices[rc] = E->get().subindex;
rc++;
- if (rc >= p_max_results)
+ if (rc >= p_max_results) {
break;
+ }
}
}
@@ -166,8 +169,9 @@ void BroadPhase3DBasic::update() {
Element *elem_A = &I->get();
Element *elem_B = &J->get();
- if (elem_A->owner == elem_B->owner)
+ if (elem_A->owner == elem_B->owner) {
continue;
+ }
bool pair_ok = elem_A->aabb.intersects(elem_B->aabb) && (!elem_A->_static || !elem_B->_static);
@@ -176,15 +180,17 @@ void BroadPhase3DBasic::update() {
Map<PairKey, void *>::Element *E = pair_map.find(key);
if (!pair_ok && E) {
- if (unpair_callback)
+ if (unpair_callback) {
unpair_callback(elem_A->owner, elem_A->subindex, elem_B->owner, elem_B->subindex, E->get(), unpair_userdata);
+ }
pair_map.erase(key);
}
if (pair_ok && !E) {
void *data = nullptr;
- if (pair_callback)
+ if (pair_callback) {
data = pair_callback(elem_A->owner, elem_A->subindex, elem_B->owner, elem_B->subindex, unpair_userdata);
+ }
pair_map.insert(key, data);
}
}
diff --git a/servers/physics_3d/broad_phase_octree.cpp b/servers/physics_3d/broad_phase_octree.cpp
index ffa1802bc8..1ace1a4fcf 100644
--- a/servers/physics_3d/broad_phase_octree.cpp
+++ b/servers/physics_3d/broad_phase_octree.cpp
@@ -77,16 +77,18 @@ int BroadPhaseOctree::cull_aabb(const AABB &p_aabb, CollisionObject3DSW **p_resu
void *BroadPhaseOctree::_pair_callback(void *self, OctreeElementID p_A, CollisionObject3DSW *p_object_A, int subindex_A, OctreeElementID p_B, CollisionObject3DSW *p_object_B, int subindex_B) {
BroadPhaseOctree *bpo = (BroadPhaseOctree *)(self);
- if (!bpo->pair_callback)
+ if (!bpo->pair_callback) {
return nullptr;
+ }
return bpo->pair_callback(p_object_A, subindex_A, p_object_B, subindex_B, bpo->pair_userdata);
}
void BroadPhaseOctree::_unpair_callback(void *self, OctreeElementID p_A, CollisionObject3DSW *p_object_A, int subindex_A, OctreeElementID p_B, CollisionObject3DSW *p_object_B, int subindex_B, void *pairdata) {
BroadPhaseOctree *bpo = (BroadPhaseOctree *)(self);
- if (!bpo->unpair_callback)
+ if (!bpo->unpair_callback) {
return;
+ }
bpo->unpair_callback(p_object_A, subindex_A, p_object_B, subindex_B, pairdata, bpo->unpair_userdata);
}
diff --git a/servers/physics_3d/collision_object_3d_sw.cpp b/servers/physics_3d/collision_object_3d_sw.cpp
index 22a8235744..e12f0659e2 100644
--- a/servers/physics_3d/collision_object_3d_sw.cpp
+++ b/servers/physics_3d/collision_object_3d_sw.cpp
@@ -95,8 +95,9 @@ void CollisionObject3DSW::remove_shape(int p_index) {
//remove anything from shape to be erased to end, so subindices don't change
ERR_FAIL_INDEX(p_index, shapes.size());
for (int i = p_index; i < shapes.size(); i++) {
- if (shapes[i].bpid == 0)
+ if (shapes[i].bpid == 0) {
continue;
+ }
//should never get here with a null owner
space->get_broadphase()->remove(shapes[i].bpid);
shapes.write[i].bpid = 0;
@@ -112,12 +113,14 @@ void CollisionObject3DSW::remove_shape(int p_index) {
}
void CollisionObject3DSW::_set_static(bool p_static) {
- if (_static == p_static)
+ if (_static == p_static) {
return;
+ }
_static = p_static;
- if (!space)
+ if (!space) {
return;
+ }
for (int i = 0; i < get_shape_count(); i++) {
const Shape &s = shapes[i];
if (s.bpid > 0) {
@@ -137,8 +140,9 @@ void CollisionObject3DSW::_unregister_shapes() {
}
void CollisionObject3DSW::_update_shapes() {
- if (!space)
+ if (!space) {
return;
+ }
for (int i = 0; i < shapes.size(); i++) {
Shape &s = shapes.write[i];
@@ -162,8 +166,9 @@ void CollisionObject3DSW::_update_shapes() {
}
void CollisionObject3DSW::_update_shapes_with_motion(const Vector3 &p_motion) {
- if (!space)
+ if (!space) {
return;
+ }
for (int i = 0; i < shapes.size(); i++) {
Shape &s = shapes.write[i];
diff --git a/servers/physics_3d/collision_object_3d_sw.h b/servers/physics_3d/collision_object_3d_sw.h
index 0c320b3275..9506f14402 100644
--- a/servers/physics_3d/collision_object_3d_sw.h
+++ b/servers/physics_3d/collision_object_3d_sw.h
@@ -91,8 +91,9 @@ protected:
#endif
transform = p_transform;
- if (p_update_shapes)
+ if (p_update_shapes) {
_update_shapes();
+ }
}
_FORCE_INLINE_ void _set_inv_transform(const Transform &p_transform) { inv_transform = p_transform; }
void _set_static(bool p_static);
diff --git a/servers/physics_3d/collision_solver_3d_sat.cpp b/servers/physics_3d/collision_solver_3d_sat.cpp
index b4902af8ec..736222c7d9 100644
--- a/servers/physics_3d/collision_solver_3d_sat.cpp
+++ b/servers/physics_3d/collision_solver_3d_sat.cpp
@@ -42,10 +42,11 @@ struct _CollectorCallback {
Vector3 *prev_axis;
_FORCE_INLINE_ void call(const Vector3 &p_point_A, const Vector3 &p_point_B) {
- if (swap)
+ if (swap) {
callback(p_point_B, p_point_A, userdata);
- else
+ } else {
callback(p_point_A, p_point_B, userdata);
+ }
}
};
@@ -116,10 +117,11 @@ static void _generate_contacts_edge_edge(const Vector3 *p_points_A, int p_point_
real_t d = (c.dot(p_points_B[0]) - p_points_A[0].dot(c)) / rel_A.dot(c);
- if (d < 0.0)
+ if (d < 0.0) {
d = 0.0;
- else if (d > 1.0)
+ } else if (d > 1.0) {
d = 1.0;
+ }
Vector3 closest_A = p_points_A[0] + rel_A * d;
Vector3 closest_B = Geometry::get_closest_point_to_segment_uncapped(closest_A, p_points_B);
@@ -207,8 +209,9 @@ static void _generate_contacts_face_face(const Vector3 *p_points_A, int p_point_
Vector3 closest_B = clipbuf_src[i] - plane_B.normal * d;
- if (p_callback->normal.dot(clipbuf_src[i]) >= p_callback->normal.dot(closest_B))
+ if (p_callback->normal.dot(clipbuf_src[i]) >= p_callback->normal.dot(closest_B)) {
continue;
+ }
p_callback->call(clipbuf_src[i], closest_B);
}
@@ -282,10 +285,11 @@ class SeparatorAxisTest {
public:
_FORCE_INLINE_ bool test_previous_axis() {
- if (callback && callback->prev_axis && *callback->prev_axis != Vector3())
+ if (callback && callback->prev_axis && *callback->prev_axis != Vector3()) {
return test_axis(*callback->prev_axis);
- else
+ } else {
return true;
+ }
}
_FORCE_INLINE_ bool test_axis(const Vector3 &p_axis) {
@@ -344,14 +348,16 @@ public:
_FORCE_INLINE_ void generate_contacts() {
// nothing to do, don't generate
- if (best_axis == Vector3(0.0, 0.0, 0.0))
+ if (best_axis == Vector3(0.0, 0.0, 0.0)) {
return;
+ }
if (!callback->callback) {
//just was checking intersection?
callback->collided = true;
- if (callback->prev_axis)
+ if (callback->prev_axis) {
*callback->prev_axis = best_axis;
+ }
return;
}
@@ -384,8 +390,9 @@ public:
}
callback->normal = best_axis;
- if (callback->prev_axis)
+ if (callback->prev_axis) {
*callback->prev_axis = best_axis;
+ }
_generate_contacts_from_supports(supports_A, support_count_A, supports_B, support_count_B, callback);
callback->collided = true;
@@ -416,11 +423,13 @@ static void _collision_sphere_sphere(const Shape3DSW *p_a, const Transform &p_tr
// previous axis
- if (!separator.test_previous_axis())
+ if (!separator.test_previous_axis()) {
return;
+ }
- if (!separator.test_axis((p_transform_a.origin - p_transform_b.origin).normalized()))
+ if (!separator.test_axis((p_transform_a.origin - p_transform_b.origin).normalized())) {
return;
+ }
separator.generate_contacts();
}
@@ -432,16 +441,18 @@ static void _collision_sphere_box(const Shape3DSW *p_a, const Transform &p_trans
SeparatorAxisTest<SphereShape3DSW, BoxShape3DSW, withMargin> separator(sphere_A, p_transform_a, box_B, p_transform_b, p_collector, p_margin_a, p_margin_b);
- if (!separator.test_previous_axis())
+ if (!separator.test_previous_axis()) {
return;
+ }
// test faces
for (int i = 0; i < 3; i++) {
Vector3 axis = p_transform_b.basis.get_axis(i).normalized();
- if (!separator.test_axis(axis))
+ if (!separator.test_axis(axis)) {
return;
+ }
}
// calculate closest point to sphere
@@ -457,16 +468,18 @@ static void _collision_sphere_box(const Shape3DSW *p_a, const Transform &p_trans
// use point to test axis
Vector3 point_axis = (p_transform_a.origin - cpoint).normalized();
- if (!separator.test_axis(point_axis))
+ if (!separator.test_axis(point_axis)) {
return;
+ }
// test edges
for (int i = 0; i < 3; i++) {
Vector3 axis = point_axis.cross(p_transform_b.basis.get_axis(i)).cross(p_transform_b.basis.get_axis(i)).normalized();
- if (!separator.test_axis(axis))
+ if (!separator.test_axis(axis)) {
return;
+ }
}
separator.generate_contacts();
@@ -479,8 +492,9 @@ static void _collision_sphere_capsule(const Shape3DSW *p_a, const Transform &p_t
SeparatorAxisTest<SphereShape3DSW, CapsuleShape3DSW, withMargin> separator(sphere_A, p_transform_a, capsule_B, p_transform_b, p_collector, p_margin_a, p_margin_b);
- if (!separator.test_previous_axis())
+ if (!separator.test_previous_axis()) {
return;
+ }
//capsule sphere 1, sphere
@@ -488,15 +502,17 @@ static void _collision_sphere_capsule(const Shape3DSW *p_a, const Transform &p_t
Vector3 capsule_ball_1 = p_transform_b.origin + capsule_axis;
- if (!separator.test_axis((capsule_ball_1 - p_transform_a.origin).normalized()))
+ if (!separator.test_axis((capsule_ball_1 - p_transform_a.origin).normalized())) {
return;
+ }
//capsule sphere 2, sphere
Vector3 capsule_ball_2 = p_transform_b.origin - capsule_axis;
- if (!separator.test_axis((capsule_ball_2 - p_transform_a.origin).normalized()))
+ if (!separator.test_axis((capsule_ball_2 - p_transform_a.origin).normalized())) {
return;
+ }
//capsule edge, sphere
@@ -504,8 +520,9 @@ static void _collision_sphere_capsule(const Shape3DSW *p_a, const Transform &p_t
Vector3 axis = b2a.cross(capsule_axis).cross(capsule_axis).normalized();
- if (!separator.test_axis(axis))
+ if (!separator.test_axis(axis)) {
return;
+ }
separator.generate_contacts();
}
@@ -521,8 +538,9 @@ static void _collision_sphere_convex_polygon(const Shape3DSW *p_a, const Transfo
SeparatorAxisTest<SphereShape3DSW, ConvexPolygonShape3DSW, withMargin> separator(sphere_A, p_transform_a, convex_polygon_B, p_transform_b, p_collector, p_margin_a, p_margin_b);
- if (!separator.test_previous_axis())
+ if (!separator.test_previous_axis()) {
return;
+ }
const Geometry::MeshData &mesh = convex_polygon_B->get_mesh();
@@ -537,8 +555,9 @@ static void _collision_sphere_convex_polygon(const Shape3DSW *p_a, const Transfo
for (int i = 0; i < face_count; i++) {
Vector3 axis = p_transform_b.xform(faces[i].plane).normal;
- if (!separator.test_axis(axis))
+ if (!separator.test_axis(axis)) {
return;
+ }
}
// edges of B
@@ -552,8 +571,9 @@ static void _collision_sphere_convex_polygon(const Shape3DSW *p_a, const Transfo
Vector3 axis = n1.cross(n2).cross(n1).normalized();
- if (!separator.test_axis(axis))
+ if (!separator.test_axis(axis)) {
return;
+ }
}
// vertices of B
@@ -563,8 +583,9 @@ static void _collision_sphere_convex_polygon(const Shape3DSW *p_a, const Transfo
Vector3 axis = (v2 - v1).normalized();
- if (!separator.test_axis(axis))
+ if (!separator.test_axis(axis)) {
return;
+ }
}
separator.generate_contacts();
@@ -583,8 +604,9 @@ static void _collision_sphere_face(const Shape3DSW *p_a, const Transform &p_tran
p_transform_b.xform(face_B->vertex[2]),
};
- if (!separator.test_axis((vertex[0] - vertex[2]).cross(vertex[0] - vertex[1]).normalized()))
+ if (!separator.test_axis((vertex[0] - vertex[2]).cross(vertex[0] - vertex[1]).normalized())) {
return;
+ }
// edges and points of B
for (int i = 0; i < 3; i++) {
@@ -613,16 +635,18 @@ static void _collision_box_box(const Shape3DSW *p_a, const Transform &p_transfor
SeparatorAxisTest<BoxShape3DSW, BoxShape3DSW, withMargin> separator(box_A, p_transform_a, box_B, p_transform_b, p_collector, p_margin_a, p_margin_b);
- if (!separator.test_previous_axis())
+ if (!separator.test_previous_axis()) {
return;
+ }
// test faces of A
for (int i = 0; i < 3; i++) {
Vector3 axis = p_transform_a.basis.get_axis(i).normalized();
- if (!separator.test_axis(axis))
+ if (!separator.test_axis(axis)) {
return;
+ }
}
// test faces of B
@@ -630,8 +654,9 @@ static void _collision_box_box(const Shape3DSW *p_a, const Transform &p_transfor
for (int i = 0; i < 3; i++) {
Vector3 axis = p_transform_b.basis.get_axis(i).normalized();
- if (!separator.test_axis(axis))
+ if (!separator.test_axis(axis)) {
return;
+ }
}
// test combined edges
@@ -639,8 +664,9 @@ static void _collision_box_box(const Shape3DSW *p_a, const Transform &p_transfor
for (int j = 0; j < 3; j++) {
Vector3 axis = p_transform_a.basis.get_axis(i).cross(p_transform_b.basis.get_axis(j));
- if (Math::is_zero_approx(axis.length_squared()))
+ if (Math::is_zero_approx(axis.length_squared())) {
continue;
+ }
axis.normalize();
if (!separator.test_axis(axis)) {
@@ -684,14 +710,16 @@ static void _collision_box_box(const Shape3DSW *p_a, const Transform &p_transfor
//a ->b
Vector3 axis_a = p_transform_a.basis.get_axis(i);
- if (!separator.test_axis(axis_ab.cross(axis_a).cross(axis_a).normalized()))
+ if (!separator.test_axis(axis_ab.cross(axis_a).cross(axis_a).normalized())) {
return;
+ }
//b ->a
Vector3 axis_b = p_transform_b.basis.get_axis(i);
- if (!separator.test_axis(axis_ab.cross(axis_b).cross(axis_b).normalized()))
+ if (!separator.test_axis(axis_ab.cross(axis_b).cross(axis_b).normalized())) {
return;
+ }
}
}
@@ -705,15 +733,17 @@ static void _collision_box_capsule(const Shape3DSW *p_a, const Transform &p_tran
SeparatorAxisTest<BoxShape3DSW, CapsuleShape3DSW, withMargin> separator(box_A, p_transform_a, capsule_B, p_transform_b, p_collector, p_margin_a, p_margin_b);
- if (!separator.test_previous_axis())
+ if (!separator.test_previous_axis()) {
return;
+ }
// faces of A
for (int i = 0; i < 3; i++) {
Vector3 axis = p_transform_a.basis.get_axis(i);
- if (!separator.test_axis(axis))
+ if (!separator.test_axis(axis)) {
return;
+ }
}
Vector3 cyl_axis = p_transform_b.basis.get_axis(2).normalized();
@@ -724,11 +754,13 @@ static void _collision_box_capsule(const Shape3DSW *p_a, const Transform &p_tran
// cylinder
Vector3 box_axis = p_transform_a.basis.get_axis(i);
Vector3 axis = box_axis.cross(cyl_axis);
- if (Math::is_zero_approx(axis.length_squared()))
+ if (Math::is_zero_approx(axis.length_squared())) {
continue;
+ }
- if (!separator.test_axis(axis.normalized()))
+ if (!separator.test_axis(axis.normalized())) {
return;
+ }
}
// points of A, capsule cylinder
@@ -742,14 +774,16 @@ static void _collision_box_capsule(const Shape3DSW *p_a, const Transform &p_tran
he.y *= (j * 2 - 1);
he.z *= (k * 2 - 1);
Vector3 point = p_transform_a.origin;
- for (int l = 0; l < 3; l++)
+ for (int l = 0; l < 3; l++) {
point += p_transform_a.basis.get_axis(l) * he[l];
+ }
//Vector3 axis = (point - cyl_axis * cyl_axis.dot(point)).normalized();
Vector3 axis = Plane(cyl_axis, 0).project(point).normalized();
- if (!separator.test_axis(axis))
+ if (!separator.test_axis(axis)) {
return;
+ }
}
}
}
@@ -772,16 +806,18 @@ static void _collision_box_capsule(const Shape3DSW *p_a, const Transform &p_tran
// use point to test axis
Vector3 point_axis = (sphere_pos - cpoint).normalized();
- if (!separator.test_axis(point_axis))
+ if (!separator.test_axis(point_axis)) {
return;
+ }
// test edges of A
for (int j = 0; j < 3; j++) {
Vector3 axis = point_axis.cross(p_transform_a.basis.get_axis(j)).cross(p_transform_a.basis.get_axis(j)).normalized();
- if (!separator.test_axis(axis))
+ if (!separator.test_axis(axis)) {
return;
+ }
}
}
@@ -799,8 +835,9 @@ static void _collision_box_convex_polygon(const Shape3DSW *p_a, const Transform
SeparatorAxisTest<BoxShape3DSW, ConvexPolygonShape3DSW, withMargin> separator(box_A, p_transform_a, convex_polygon_B, p_transform_b, p_collector, p_margin_a, p_margin_b);
- if (!separator.test_previous_axis())
+ if (!separator.test_previous_axis()) {
return;
+ }
const Geometry::MeshData &mesh = convex_polygon_B->get_mesh();
@@ -815,16 +852,18 @@ static void _collision_box_convex_polygon(const Shape3DSW *p_a, const Transform
for (int i = 0; i < 3; i++) {
Vector3 axis = p_transform_a.basis.get_axis(i).normalized();
- if (!separator.test_axis(axis))
+ if (!separator.test_axis(axis)) {
return;
+ }
}
// faces of B
for (int i = 0; i < face_count; i++) {
Vector3 axis = p_transform_b.xform(faces[i].plane).normal;
- if (!separator.test_axis(axis))
+ if (!separator.test_axis(axis)) {
return;
+ }
}
// A<->B edges
@@ -836,8 +875,9 @@ static void _collision_box_convex_polygon(const Shape3DSW *p_a, const Transform
Vector3 axis = e1.cross(e2).normalized();
- if (!separator.test_axis(axis))
+ if (!separator.test_axis(axis)) {
return;
+ }
}
}
@@ -867,8 +907,9 @@ static void _collision_box_convex_polygon(const Shape3DSW *p_a, const Transform
//a ->b
Vector3 axis_a = p_transform_a.basis.get_axis(i);
- if (!separator.test_axis(axis_ab.cross(axis_a).cross(axis_a).normalized()))
+ if (!separator.test_axis(axis_ab.cross(axis_a).cross(axis_a).normalized())) {
return;
+ }
}
}
@@ -881,16 +922,18 @@ static void _collision_box_convex_polygon(const Shape3DSW *p_a, const Transform
he.y *= (j * 2 - 1);
he.z *= (k * 2 - 1);
Vector3 point = p_transform_a.origin;
- for (int l = 0; l < 3; l++)
+ for (int l = 0; l < 3; l++) {
point += p_transform_a.basis.get_axis(l) * he[l];
+ }
for (int e = 0; e < edge_count; e++) {
Vector3 p1 = p_transform_b.xform(vertices[edges[e].a]);
Vector3 p2 = p_transform_b.xform(vertices[edges[e].b]);
Vector3 n = (p2 - p1);
- if (!separator.test_axis((point - p2).cross(n).cross(n).normalized()))
+ if (!separator.test_axis((point - p2).cross(n).cross(n).normalized())) {
return;
+ }
}
}
}
@@ -913,15 +956,17 @@ static void _collision_box_face(const Shape3DSW *p_a, const Transform &p_transfo
p_transform_b.xform(face_B->vertex[2]),
};
- if (!separator.test_axis((vertex[0] - vertex[2]).cross(vertex[0] - vertex[1]).normalized()))
+ if (!separator.test_axis((vertex[0] - vertex[2]).cross(vertex[0] - vertex[1]).normalized())) {
return;
+ }
// faces of A
for (int i = 0; i < 3; i++) {
Vector3 axis = p_transform_a.basis.get_axis(i).normalized();
- if (!separator.test_axis(axis))
+ if (!separator.test_axis(axis)) {
return;
+ }
}
// combined edges
@@ -932,8 +977,9 @@ static void _collision_box_face(const Shape3DSW *p_a, const Transform &p_transfo
for (int j = 0; j < 3; j++) {
Vector3 axis = p_transform_a.basis.get_axis(j);
- if (!separator.test_axis(e.cross(axis).normalized()))
+ if (!separator.test_axis(e.cross(axis).normalized())) {
return;
+ }
}
}
@@ -962,8 +1008,9 @@ static void _collision_box_face(const Shape3DSW *p_a, const Transform &p_transfo
//a ->b
Vector3 axis_a = p_transform_a.basis.get_axis(i);
- if (!separator.test_axis(axis_ab.cross(axis_a).cross(axis_a).normalized()))
+ if (!separator.test_axis(axis_ab.cross(axis_a).cross(axis_a).normalized())) {
return;
+ }
}
}
@@ -976,8 +1023,9 @@ static void _collision_box_face(const Shape3DSW *p_a, const Transform &p_transfo
he.y *= (j * 2 - 1);
he.z *= (k * 2 - 1);
Vector3 point = p_transform_a.origin;
- for (int l = 0; l < 3; l++)
+ for (int l = 0; l < 3; l++) {
point += p_transform_a.basis.get_axis(l) * he[l];
+ }
for (int e = 0; e < 3; e++) {
Vector3 p1 = vertex[e];
@@ -985,8 +1033,9 @@ static void _collision_box_face(const Shape3DSW *p_a, const Transform &p_transfo
Vector3 n = (p2 - p1);
- if (!separator.test_axis((point - p2).cross(n).cross(n).normalized()))
+ if (!separator.test_axis((point - p2).cross(n).cross(n).normalized())) {
return;
+ }
}
}
}
@@ -1003,8 +1052,9 @@ static void _collision_capsule_capsule(const Shape3DSW *p_a, const Transform &p_
SeparatorAxisTest<CapsuleShape3DSW, CapsuleShape3DSW, withMargin> separator(capsule_A, p_transform_a, capsule_B, p_transform_b, p_collector, p_margin_a, p_margin_b);
- if (!separator.test_previous_axis())
+ if (!separator.test_previous_axis()) {
return;
+ }
// some values
@@ -1018,34 +1068,43 @@ static void _collision_capsule_capsule(const Shape3DSW *p_a, const Transform &p_
//balls-balls
- if (!separator.test_axis((capsule_A_ball_1 - capsule_B_ball_1).normalized()))
+ if (!separator.test_axis((capsule_A_ball_1 - capsule_B_ball_1).normalized())) {
return;
- if (!separator.test_axis((capsule_A_ball_1 - capsule_B_ball_2).normalized()))
+ }
+ if (!separator.test_axis((capsule_A_ball_1 - capsule_B_ball_2).normalized())) {
return;
+ }
- if (!separator.test_axis((capsule_A_ball_2 - capsule_B_ball_1).normalized()))
+ if (!separator.test_axis((capsule_A_ball_2 - capsule_B_ball_1).normalized())) {
return;
- if (!separator.test_axis((capsule_A_ball_2 - capsule_B_ball_2).normalized()))
+ }
+ if (!separator.test_axis((capsule_A_ball_2 - capsule_B_ball_2).normalized())) {
return;
+ }
// edges-balls
- if (!separator.test_axis((capsule_A_ball_1 - capsule_B_ball_1).cross(capsule_A_axis).cross(capsule_A_axis).normalized()))
+ if (!separator.test_axis((capsule_A_ball_1 - capsule_B_ball_1).cross(capsule_A_axis).cross(capsule_A_axis).normalized())) {
return;
+ }
- if (!separator.test_axis((capsule_A_ball_1 - capsule_B_ball_2).cross(capsule_A_axis).cross(capsule_A_axis).normalized()))
+ if (!separator.test_axis((capsule_A_ball_1 - capsule_B_ball_2).cross(capsule_A_axis).cross(capsule_A_axis).normalized())) {
return;
+ }
- if (!separator.test_axis((capsule_B_ball_1 - capsule_A_ball_1).cross(capsule_B_axis).cross(capsule_B_axis).normalized()))
+ if (!separator.test_axis((capsule_B_ball_1 - capsule_A_ball_1).cross(capsule_B_axis).cross(capsule_B_axis).normalized())) {
return;
+ }
- if (!separator.test_axis((capsule_B_ball_1 - capsule_A_ball_2).cross(capsule_B_axis).cross(capsule_B_axis).normalized()))
+ if (!separator.test_axis((capsule_B_ball_1 - capsule_A_ball_2).cross(capsule_B_axis).cross(capsule_B_axis).normalized())) {
return;
+ }
// edges
- if (!separator.test_axis(capsule_A_axis.cross(capsule_B_axis).normalized()))
+ if (!separator.test_axis(capsule_A_axis.cross(capsule_B_axis).normalized())) {
return;
+ }
separator.generate_contacts();
}
@@ -1061,8 +1120,9 @@ static void _collision_capsule_convex_polygon(const Shape3DSW *p_a, const Transf
SeparatorAxisTest<CapsuleShape3DSW, ConvexPolygonShape3DSW, withMargin> separator(capsule_A, p_transform_a, convex_polygon_B, p_transform_b, p_collector, p_margin_a, p_margin_b);
- if (!separator.test_previous_axis())
+ if (!separator.test_previous_axis()) {
return;
+ }
const Geometry::MeshData &mesh = convex_polygon_B->get_mesh();
@@ -1076,8 +1136,9 @@ static void _collision_capsule_convex_polygon(const Shape3DSW *p_a, const Transf
for (int i = 0; i < face_count; i++) {
Vector3 axis = p_transform_b.xform(faces[i].plane).normal;
- if (!separator.test_axis(axis))
+ if (!separator.test_axis(axis)) {
return;
+ }
}
// edges of B, capsule cylinder
@@ -1087,8 +1148,9 @@ static void _collision_capsule_convex_polygon(const Shape3DSW *p_a, const Transf
Vector3 edge_axis = p_transform_b.basis.xform(vertices[edges[i].a]) - p_transform_b.basis.xform(vertices[edges[i].b]);
Vector3 axis = edge_axis.cross(p_transform_a.basis.get_axis(2)).normalized();
- if (!separator.test_axis(axis))
+ if (!separator.test_axis(axis)) {
return;
+ }
}
// capsule balls, edges of B
@@ -1106,8 +1168,9 @@ static void _collision_capsule_convex_polygon(const Shape3DSW *p_a, const Transf
Vector3 axis = n1.cross(n2).cross(n2).normalized();
- if (!separator.test_axis(axis))
+ if (!separator.test_axis(axis)) {
return;
+ }
}
}
@@ -1127,8 +1190,9 @@ static void _collision_capsule_face(const Shape3DSW *p_a, const Transform &p_tra
p_transform_b.xform(face_B->vertex[2]),
};
- if (!separator.test_axis((vertex[0] - vertex[2]).cross(vertex[0] - vertex[1]).normalized()))
+ if (!separator.test_axis((vertex[0] - vertex[2]).cross(vertex[0] - vertex[1]).normalized())) {
return;
+ }
// edges of B, capsule cylinder
@@ -1139,11 +1203,13 @@ static void _collision_capsule_face(const Shape3DSW *p_a, const Transform &p_tra
Vector3 edge_axis = vertex[i] - vertex[(i + 1) % 3];
Vector3 axis = edge_axis.cross(capsule_axis).normalized();
- if (!separator.test_axis(axis))
+ if (!separator.test_axis(axis)) {
return;
+ }
- if (!separator.test_axis((p_transform_a.origin - vertex[i]).cross(capsule_axis).cross(capsule_axis).normalized()))
+ if (!separator.test_axis((p_transform_a.origin - vertex[i]).cross(capsule_axis).cross(capsule_axis).normalized())) {
return;
+ }
for (int j = 0; j < 2; j++) {
// point-spheres
@@ -1151,15 +1217,17 @@ static void _collision_capsule_face(const Shape3DSW *p_a, const Transform &p_tra
Vector3 n1 = sphere_pos - vertex[i];
- if (!separator.test_axis(n1.normalized()))
+ if (!separator.test_axis(n1.normalized())) {
return;
+ }
Vector3 n2 = edge_axis;
axis = n1.cross(n2).cross(n2);
- if (!separator.test_axis(axis.normalized()))
+ if (!separator.test_axis(axis.normalized())) {
return;
+ }
}
}
@@ -1185,8 +1253,9 @@ static void _collision_convex_polygon_convex_polygon(const Shape3DSW *p_a, const
SeparatorAxisTest<ConvexPolygonShape3DSW, ConvexPolygonShape3DSW, withMargin> separator(convex_polygon_A, p_transform_a, convex_polygon_B, p_transform_b, p_collector, p_margin_a, p_margin_b);
- if (!separator.test_previous_axis())
+ if (!separator.test_previous_axis()) {
return;
+ }
const Geometry::MeshData &mesh_A = convex_polygon_A->get_mesh();
@@ -1211,8 +1280,9 @@ static void _collision_convex_polygon_convex_polygon(const Shape3DSW *p_a, const
Vector3 axis = p_transform_a.xform(faces_A[i].plane).normal;
//Vector3 axis = p_transform_a.basis.xform( faces_A[i].plane.normal ).normalized();
- if (!separator.test_axis(axis))
+ if (!separator.test_axis(axis)) {
return;
+ }
}
// faces of B
@@ -1220,8 +1290,9 @@ static void _collision_convex_polygon_convex_polygon(const Shape3DSW *p_a, const
Vector3 axis = p_transform_b.xform(faces_B[i].plane).normal;
//Vector3 axis = p_transform_b.basis.xform( faces_B[i].plane.normal ).normalized();
- if (!separator.test_axis(axis))
+ if (!separator.test_axis(axis)) {
return;
+ }
}
// A<->B edges
@@ -1233,8 +1304,9 @@ static void _collision_convex_polygon_convex_polygon(const Shape3DSW *p_a, const
Vector3 axis = e1.cross(e2).normalized();
- if (!separator.test_axis(axis))
+ if (!separator.test_axis(axis)) {
return;
+ }
}
}
@@ -1244,8 +1316,9 @@ static void _collision_convex_polygon_convex_polygon(const Shape3DSW *p_a, const
Vector3 va = p_transform_a.xform(vertices_A[i]);
for (int j = 0; j < vertex_count_B; j++) {
- if (!separator.test_axis((va - p_transform_b.xform(vertices_B[j])).normalized()))
+ if (!separator.test_axis((va - p_transform_b.xform(vertices_B[j])).normalized())) {
return;
+ }
}
}
//edge-vertex (shell)
@@ -1258,8 +1331,9 @@ static void _collision_convex_polygon_convex_polygon(const Shape3DSW *p_a, const
for (int j = 0; j < vertex_count_B; j++) {
Vector3 e3 = p_transform_b.xform(vertices_B[j]);
- if (!separator.test_axis((e1 - e3).cross(n).cross(n).normalized()))
+ if (!separator.test_axis((e1 - e3).cross(n).cross(n).normalized())) {
return;
+ }
}
}
@@ -1271,8 +1345,9 @@ static void _collision_convex_polygon_convex_polygon(const Shape3DSW *p_a, const
for (int j = 0; j < vertex_count_A; j++) {
Vector3 e3 = p_transform_a.xform(vertices_A[j]);
- if (!separator.test_axis((e1 - e3).cross(n).cross(n).normalized()))
+ if (!separator.test_axis((e1 - e3).cross(n).cross(n).normalized())) {
return;
+ }
}
}
}
@@ -1302,16 +1377,18 @@ static void _collision_convex_polygon_face(const Shape3DSW *p_a, const Transform
p_transform_b.xform(face_B->vertex[2]),
};
- if (!separator.test_axis((vertex[0] - vertex[2]).cross(vertex[0] - vertex[1]).normalized()))
+ if (!separator.test_axis((vertex[0] - vertex[2]).cross(vertex[0] - vertex[1]).normalized())) {
return;
+ }
// faces of A
for (int i = 0; i < face_count; i++) {
//Vector3 axis = p_transform_a.xform( faces[i].plane ).normal;
Vector3 axis = p_transform_a.basis.xform(faces[i].plane.normal).normalized();
- if (!separator.test_axis(axis))
+ if (!separator.test_axis(axis)) {
return;
+ }
}
// A<->B edges
@@ -1323,8 +1400,9 @@ static void _collision_convex_polygon_face(const Shape3DSW *p_a, const Transform
Vector3 axis = e1.cross(e2).normalized();
- if (!separator.test_axis(axis))
+ if (!separator.test_axis(axis)) {
return;
+ }
}
}
@@ -1334,8 +1412,9 @@ static void _collision_convex_polygon_face(const Shape3DSW *p_a, const Transform
Vector3 va = p_transform_a.xform(vertices[i]);
for (int j = 0; j < 3; j++) {
- if (!separator.test_axis((va - vertex[j]).normalized()))
+ if (!separator.test_axis((va - vertex[j]).normalized())) {
return;
+ }
}
}
//edge-vertex (shell)
@@ -1348,8 +1427,9 @@ static void _collision_convex_polygon_face(const Shape3DSW *p_a, const Transform
for (int j = 0; j < 3; j++) {
Vector3 e3 = vertex[j];
- if (!separator.test_axis((e1 - e3).cross(n).cross(n).normalized()))
+ if (!separator.test_axis((e1 - e3).cross(n).cross(n).normalized())) {
return;
+ }
}
}
@@ -1361,8 +1441,9 @@ static void _collision_convex_polygon_face(const Shape3DSW *p_a, const Transform
for (int j = 0; j < vertex_count; j++) {
Vector3 e3 = p_transform_a.xform(vertices[j]);
- if (!separator.test_axis((e1 - e3).cross(n).cross(n).normalized()))
+ if (!separator.test_axis((e1 - e3).cross(n).cross(n).normalized())) {
return;
+ }
}
}
}
diff --git a/servers/physics_3d/collision_solver_3d_sw.cpp b/servers/physics_3d/collision_solver_3d_sw.cpp
index 43e62ee452..e2bfaf990d 100644
--- a/servers/physics_3d/collision_solver_3d_sw.cpp
+++ b/servers/physics_3d/collision_solver_3d_sw.cpp
@@ -38,8 +38,9 @@
bool CollisionSolver3DSW::solve_static_plane(const Shape3DSW *p_shape_A, const Transform &p_transform_A, const Shape3DSW *p_shape_B, const Transform &p_transform_B, CallbackResult p_result_callback, void *p_userdata, bool p_swap_result) {
const PlaneShape3DSW *plane = static_cast<const PlaneShape3DSW *>(p_shape_A);
- if (p_shape_B->get_type() == PhysicsServer3D::SHAPE_PLANE)
+ if (p_shape_B->get_type() == PhysicsServer3D::SHAPE_PLANE) {
return false;
+ }
Plane p = p_transform_A.xform(plane->get_plane());
static const int max_supports = 16;
@@ -52,17 +53,19 @@ bool CollisionSolver3DSW::solve_static_plane(const Shape3DSW *p_shape_A, const T
for (int i = 0; i < support_count; i++) {
supports[i] = p_transform_B.xform(supports[i]);
- if (p.distance_to(supports[i]) >= 0)
+ if (p.distance_to(supports[i]) >= 0) {
continue;
+ }
found = true;
Vector3 support_A = p.project(supports[i]);
if (p_result_callback) {
- if (p_swap_result)
+ if (p_swap_result) {
p_result_callback(supports[i], support_A, p_userdata);
- else
+ } else {
p_result_callback(support_A, supports[i], p_userdata);
+ }
}
}
@@ -82,8 +85,9 @@ bool CollisionSolver3DSW::solve_ray(const Shape3DSW *p_shape_A, const Transform
to = ai.xform(to);
Vector3 p, n;
- if (!p_shape_B->intersect_segment(from, to, p, n))
+ if (!p_shape_B->intersect_segment(from, to, p, n)) {
return false;
+ }
Vector3 support_B = p_transform_B.xform(p);
if (ray->get_slips_on_slope()) {
@@ -92,10 +96,11 @@ bool CollisionSolver3DSW::solve_ray(const Shape3DSW *p_shape_A, const Transform
}
if (p_result_callback) {
- if (p_swap_result)
+ if (p_swap_result) {
p_result_callback(support_B, support_A, p_userdata);
- else
+ } else {
p_result_callback(support_A, support_B, p_userdata);
+ }
}
return true;
}
@@ -121,8 +126,9 @@ void CollisionSolver3DSW::concave_callback(void *p_userdata, Shape3DSW *p_convex
cinfo.aabb_tests++;
bool collided = collision_solver(cinfo.shape_A, *cinfo.transform_A, p_convex, *cinfo.transform_B, cinfo.result_callback, cinfo.userdata, cinfo.swap_result, nullptr, cinfo.margin_A, cinfo.margin_B);
- if (!collided)
+ if (!collided) {
return;
+ }
cinfo.collided = true;
cinfo.collisions++;
@@ -187,8 +193,9 @@ bool CollisionSolver3DSW::solve_static(const Shape3DSW *p_shape_A, const Transfo
}
if (type_A == PhysicsServer3D::SHAPE_PLANE) {
- if (type_B == PhysicsServer3D::SHAPE_PLANE)
+ if (type_B == PhysicsServer3D::SHAPE_PLANE) {
return false;
+ }
if (type_B == PhysicsServer3D::SHAPE_RAY) {
return false;
}
@@ -200,8 +207,9 @@ bool CollisionSolver3DSW::solve_static(const Shape3DSW *p_shape_A, const Transfo
}
} else if (type_A == PhysicsServer3D::SHAPE_RAY) {
- if (type_B == PhysicsServer3D::SHAPE_RAY)
+ if (type_B == PhysicsServer3D::SHAPE_RAY) {
return false;
+ }
if (swap) {
return solve_ray(p_shape_B, p_transform_B, p_shape_A, p_transform_A, p_result_callback, p_userdata, true);
@@ -210,13 +218,15 @@ bool CollisionSolver3DSW::solve_static(const Shape3DSW *p_shape_A, const Transfo
}
} else if (concave_B) {
- if (concave_A)
+ if (concave_A) {
return false;
+ }
- if (!swap)
+ if (!swap) {
return solve_concave(p_shape_A, p_transform_A, p_shape_B, p_transform_B, p_result_callback, p_userdata, false, p_margin_A, p_margin_B);
- else
+ } else {
return solve_concave(p_shape_B, p_transform_B, p_shape_A, p_transform_A, p_result_callback, p_userdata, true, p_margin_A, p_margin_B);
+ }
} else {
return collision_solver(p_shape_A, p_transform_A, p_shape_B, p_transform_B, p_result_callback, p_userdata, false, r_sep_axis, p_margin_A, p_margin_B);
@@ -226,14 +236,16 @@ bool CollisionSolver3DSW::solve_static(const Shape3DSW *p_shape_A, const Transfo
void CollisionSolver3DSW::concave_distance_callback(void *p_userdata, Shape3DSW *p_convex) {
_ConcaveCollisionInfo &cinfo = *(_ConcaveCollisionInfo *)(p_userdata);
cinfo.aabb_tests++;
- if (cinfo.collided)
+ if (cinfo.collided) {
return;
+ }
Vector3 close_A, close_B;
cinfo.collided = !gjk_epa_calculate_distance(cinfo.shape_A, *cinfo.transform_A, p_convex, *cinfo.transform_B, close_A, close_B);
- if (cinfo.collided)
+ if (cinfo.collided) {
return;
+ }
if (!cinfo.tested || close_A.distance_squared_to(close_B) < cinfo.close_A.distance_squared_to(cinfo.close_B)) {
cinfo.close_A = close_A;
cinfo.close_B = close_B;
@@ -245,8 +257,9 @@ void CollisionSolver3DSW::concave_distance_callback(void *p_userdata, Shape3DSW
bool CollisionSolver3DSW::solve_distance_plane(const Shape3DSW *p_shape_A, const Transform &p_transform_A, const Shape3DSW *p_shape_B, const Transform &p_transform_B, Vector3 &r_point_A, Vector3 &r_point_B) {
const PlaneShape3DSW *plane = static_cast<const PlaneShape3DSW *>(p_shape_A);
- if (p_shape_B->get_type() == PhysicsServer3D::SHAPE_PLANE)
+ if (p_shape_B->get_type() == PhysicsServer3D::SHAPE_PLANE) {
return false;
+ }
Plane p = p_transform_A.xform(plane->get_plane());
static const int max_supports = 16;
@@ -265,8 +278,9 @@ bool CollisionSolver3DSW::solve_distance_plane(const Shape3DSW *p_shape_A, const
if (i == 0 || d < closest_d) {
closest = supports[i];
closest_d = d;
- if (d <= 0)
+ if (d <= 0) {
collided = true;
+ }
}
}
@@ -277,8 +291,9 @@ bool CollisionSolver3DSW::solve_distance_plane(const Shape3DSW *p_shape_A, const
}
bool CollisionSolver3DSW::solve_distance(const Shape3DSW *p_shape_A, const Transform &p_transform_A, const Shape3DSW *p_shape_B, const Transform &p_transform_B, Vector3 &r_point_A, Vector3 &r_point_B, const AABB &p_concave_hint, Vector3 *r_sep_axis) {
- if (p_shape_A->is_concave())
+ if (p_shape_A->is_concave()) {
return false;
+ }
if (p_shape_B->get_type() == PhysicsServer3D::SHAPE_PLANE) {
Vector3 a, b;
@@ -288,8 +303,9 @@ bool CollisionSolver3DSW::solve_distance(const Shape3DSW *p_shape_A, const Trans
return !col;
} else if (p_shape_B->is_concave()) {
- if (p_shape_A->is_concave())
+ if (p_shape_A->is_concave()) {
return false;
+ }
const ConcaveShape3DSW *concave_B = static_cast<const ConcaveShape3DSW *>(p_shape_B);
diff --git a/servers/physics_3d/gjk_epa.cpp b/servers/physics_3d/gjk_epa.cpp
index 7f7fc0f55b..d99a2532f8 100644
--- a/servers/physics_3d/gjk_epa.cpp
+++ b/servers/physics_3d/gjk_epa.cpp
@@ -123,10 +123,12 @@ struct MinkowskiDiff {
_FORCE_INLINE_ Vector3 Support ( const Vector3& d,U index ) const
{
- if ( index )
+ if ( index ) {
return ( Support1 ( d ) );
- else
+ } else {
return ( Support0 ( d ) );
+
+}
}
};
@@ -278,7 +280,9 @@ struct GJK
m_free[m_nfree++] = cs.c[i];
}
}
- if(mask==15) m_status=eStatus::Inside;
+ if(mask==15) { m_status=eStatus::Inside;
+
+}
}
else
{/* Return old simplex */
@@ -307,10 +311,14 @@ struct GJK
Vector3 axis=Vector3(0,0,0);
axis[i]=1;
appendvertice(*m_simplex, axis);
- if(EncloseOrigin()) return(true);
+ if(EncloseOrigin()) { return(true);
+
+}
removevertice(*m_simplex);
appendvertice(*m_simplex,-axis);
- if(EncloseOrigin()) return(true);
+ if(EncloseOrigin()) { return(true);
+
+}
removevertice(*m_simplex);
}
}
@@ -326,10 +334,14 @@ struct GJK
if(p.length_squared()>0)
{
appendvertice(*m_simplex, p);
- if(EncloseOrigin()) return(true);
+ if(EncloseOrigin()) { return(true);
+
+}
removevertice(*m_simplex);
appendvertice(*m_simplex,-p);
- if(EncloseOrigin()) return(true);
+ if(EncloseOrigin()) { return(true);
+
+}
removevertice(*m_simplex);
}
}
@@ -342,10 +354,14 @@ struct GJK
if(n.length_squared()>0)
{
appendvertice(*m_simplex,n);
- if(EncloseOrigin()) return(true);
+ if(EncloseOrigin()) { return(true);
+
+}
removevertice(*m_simplex);
appendvertice(*m_simplex,-n);
- if(EncloseOrigin()) return(true);
+ if(EncloseOrigin()) { return(true);
+
+}
removevertice(*m_simplex);
}
}
@@ -354,8 +370,10 @@ struct GJK
{
if(Math::abs(det( m_simplex->c[0]->w-m_simplex->c[3]->w,
m_simplex->c[1]->w-m_simplex->c[3]->w,
- m_simplex->c[2]->w-m_simplex->c[3]->w))>0)
+ m_simplex->c[2]->w-m_simplex->c[3]->w))>0) {
return(true);
+
+}
}
break;
}
@@ -561,15 +579,23 @@ struct GJK
{
face->l[0] = nullptr;
face->l[1] = list.root;
- if(list.root) list.root->l[0]=face;
+ if(list.root) { list.root->l[0]=face;
+
+}
list.root = face;
++list.count;
}
static inline void remove(sList& list,sFace* face)
{
- if(face->l[1]) face->l[1]->l[0]=face->l[0];
- if(face->l[0]) face->l[0]->l[1]=face->l[1];
- if(face==list.root) list.root=face->l[1];
+ if(face->l[1]) { face->l[1]->l[0]=face->l[0];
+
+}
+ if(face->l[0]) { face->l[0]->l[1]=face->l[1];
+
+}
+ if(face==list.root) { list.root=face->l[1];
+
+}
--list.count;
}
@@ -650,7 +676,9 @@ struct GJK
remove(m_hull,best);
append(m_stock,best);
best=findbest();
- if(best->p>=outer.p) outer=*best;
+ if(best->p>=outer.p) { outer=*best;
+
+}
} else { m_status=eStatus::InvalidHull;break; }
} else { m_status=eStatus::AccuraryReached;break; }
} else { m_status=eStatus::OutOfVertices;break; }
@@ -679,10 +707,12 @@ struct GJK
m_status = eStatus::FallBack;
m_normal = -guess;
const real_t nl=m_normal.length();
- if(nl>0)
+ if(nl>0) {
m_normal = m_normal/nl;
- else
+ } else {
m_normal = Vector3(1,0,0);
+
+}
m_depth = 0;
m_result.rank=1;
m_result.c[0]=simplex.c[0];
@@ -716,8 +746,12 @@ struct GJK
if(forced||(face->d>=-EPA_PLANE_EPS))
{
return(face);
- } else m_status=eStatus::NonConvex;
- } else m_status=eStatus::Degenerated;
+ } else { m_status=eStatus::NonConvex;
+
+}
+ } else { m_status=eStatus::Degenerated;
+
+}
remove(m_hull,face);
append(m_stock,face);
return(nullptr);
@@ -758,7 +792,9 @@ struct GJK
if(nf)
{
bind(nf,0,f,e);
- if(horizon.cf) bind(horizon.cf,1,nf,2); else horizon.ff=nf;
+ if(horizon.cf) { bind(horizon.cf,1,nf,2); } else { horizon.ff=nf;
+
+}
horizon.cf=nf;
++horizon.nf;
return(true);
@@ -880,7 +916,9 @@ bool Penetration( const Shape3DSW* shape0,
results.normal = -epa.m_normal;
results.distance = -epa.m_depth;
return(true);
- } else results.status=sResults::EPA_Failed;
+ } else { results.status=sResults::EPA_Failed;
+
+}
}
break;
case GJK::eStatus::Failed:
@@ -933,10 +971,11 @@ bool gjk_epa_calculate_penetration(const Shape3DSW *p_shape_A, const Transform &
if (GjkEpa2::Penetration(p_shape_A, p_transform_A, p_shape_B, p_transform_B, p_transform_B.origin - p_transform_A.origin, res)) {
if (p_result_callback) {
- if (p_swap)
+ if (p_swap) {
p_result_callback(res.witnesses[1], res.witnesses[0], p_userdata);
- else
+ } else {
p_result_callback(res.witnesses[0], res.witnesses[1], p_userdata);
+ }
}
return true;
}
diff --git a/servers/physics_3d/joints/generic_6dof_joint_3d_sw.cpp b/servers/physics_3d/joints/generic_6dof_joint_3d_sw.cpp
index 97310a5924..423bbc0dfd 100644
--- a/servers/physics_3d/joints/generic_6dof_joint_3d_sw.cpp
+++ b/servers/physics_3d/joints/generic_6dof_joint_3d_sw.cpp
@@ -83,8 +83,9 @@ int G6DOFRotationalLimitMotor3DSW::testLimitValue(real_t test_value) {
real_t G6DOFRotationalLimitMotor3DSW::solveAngularLimits(
real_t timeStep, Vector3 &axis, real_t jacDiagABInv,
Body3DSW *body0, Body3DSW *body1) {
- if (!needApplyTorques())
+ if (!needApplyTorques()) {
return 0.0f;
+ }
real_t target_velocity = m_targetVelocity;
real_t maxMotorForce = m_maxMotorForce;
@@ -138,8 +139,9 @@ real_t G6DOFRotationalLimitMotor3DSW::solveAngularLimits(
Vector3 motorImp = clippedMotorImpulse * axis;
body0->apply_torque_impulse(motorImp);
- if (body1)
+ if (body1) {
body1->apply_torque_impulse(-motorImp);
+ }
return clippedMotorImpulse;
}
@@ -325,10 +327,11 @@ bool Generic6DOFJoint3DSW::setup(real_t p_timestep) {
//linear part
for (i = 0; i < 3; i++) {
if (m_linearLimits.enable_limit[i] && m_linearLimits.isLimited(i)) {
- if (m_useLinearReferenceFrameA)
+ if (m_useLinearReferenceFrameA) {
normalWorld = m_calculatedTransformA.basis.get_axis(i);
- else
+ } else {
normalWorld = m_calculatedTransformB.basis.get_axis(i);
+ }
buildLinearJacobian(
m_jacLinear[i], normalWorld,
@@ -367,10 +370,11 @@ void Generic6DOFJoint3DSW::solve(real_t p_timestep) {
if (m_linearLimits.enable_limit[i] && m_linearLimits.isLimited(i)) {
jacDiagABInv = real_t(1.) / m_jacLinear[i].getDiagonal();
- if (m_useLinearReferenceFrameA)
+ if (m_useLinearReferenceFrameA) {
linear_axis = m_calculatedTransformA.basis.get_axis(i);
- else
+ } else {
linear_axis = m_calculatedTransformB.basis.get_axis(i);
+ }
m_linearLimits.solveLinearAxis(
m_timeStep,
diff --git a/servers/physics_3d/joints/pin_joint_3d_sw.cpp b/servers/physics_3d/joints/pin_joint_3d_sw.cpp
index 3f3c0f367d..230904408b 100644
--- a/servers/physics_3d/joints/pin_joint_3d_sw.cpp
+++ b/servers/physics_3d/joints/pin_joint_3d_sw.cpp
@@ -109,10 +109,12 @@ void PinJoint3DSW::solve(real_t p_step) {
real_t impulseClamp = m_impulseClamp;
if (impulseClamp > 0) {
- if (impulse < -impulseClamp)
+ if (impulse < -impulseClamp) {
impulse = -impulseClamp;
- if (impulse > impulseClamp)
+ }
+ if (impulse > impulseClamp) {
impulse = impulseClamp;
+ }
}
m_appliedImpulse += impulse;
diff --git a/servers/physics_3d/physics_server_3d_sw.cpp b/servers/physics_3d/physics_server_3d_sw.cpp
index d05001e636..b625ae2271 100644
--- a/servers/physics_3d/physics_server_3d_sw.cpp
+++ b/servers/physics_3d/physics_server_3d_sw.cpp
@@ -144,10 +144,11 @@ RID PhysicsServer3DSW::space_create() {
void PhysicsServer3DSW::space_set_active(RID p_space, bool p_active) {
Space3DSW *space = space_owner.getornull(p_space);
ERR_FAIL_COND(!space);
- if (p_active)
+ if (p_active) {
active_spaces.insert(space);
- else
+ } else {
active_spaces.erase(space);
+ }
}
bool PhysicsServer3DSW::space_is_active(RID p_space) const {
@@ -213,8 +214,9 @@ void PhysicsServer3DSW::area_set_space(RID p_area, RID p_space) {
ERR_FAIL_COND(!space);
}
- if (area->get_space() == space)
+ if (area->get_space() == space) {
return; //pointless
+ }
area->clear_constraints();
area->set_space(space);
@@ -225,8 +227,9 @@ RID PhysicsServer3DSW::area_get_space(RID p_area) const {
ERR_FAIL_COND_V(!area, RID());
Space3DSW *space = area->get_space();
- if (!space)
+ if (!space) {
return RID();
+ }
return space->get_self();
};
@@ -307,8 +310,9 @@ void PhysicsServer3DSW::area_clear_shapes(RID p_area) {
Area3DSW *area = area_owner.getornull(p_area);
ERR_FAIL_COND(!area);
- while (area->get_shape_count())
+ while (area->get_shape_count()) {
area->remove_shape(0);
+ }
}
void PhysicsServer3DSW::area_set_shape_disabled(RID p_area, int p_shape_idx, bool p_disabled) {
@@ -427,10 +431,12 @@ void PhysicsServer3DSW::area_set_area_monitor_callback(RID p_area, Object *p_rec
RID PhysicsServer3DSW::body_create(BodyMode p_mode, bool p_init_sleeping) {
Body3DSW *body = memnew(Body3DSW);
- if (p_mode != BODY_MODE_RIGID)
+ if (p_mode != BODY_MODE_RIGID) {
body->set_mode(p_mode);
- if (p_init_sleeping)
+ }
+ if (p_init_sleeping) {
body->set_state(BODY_STATE_SLEEPING, p_init_sleeping);
+ }
RID rid = body_owner.make_rid(body);
body->set_self(rid);
return rid;
@@ -446,8 +452,9 @@ void PhysicsServer3DSW::body_set_space(RID p_body, RID p_space) {
ERR_FAIL_COND(!space);
}
- if (body->get_space() == space)
+ if (body->get_space() == space) {
return; //pointless
+ }
body->clear_constraint_map();
body->set_space(space);
@@ -458,8 +465,9 @@ RID PhysicsServer3DSW::body_get_space(RID p_body) const {
ERR_FAIL_COND_V(!body, RID());
Space3DSW *space = body->get_space();
- if (!space)
+ if (!space) {
return RID();
+ }
return space->get_self();
};
@@ -549,8 +557,9 @@ void PhysicsServer3DSW::body_clear_shapes(RID p_body) {
Body3DSW *body = body_owner.getornull(p_body);
ERR_FAIL_COND(!body);
- while (body->get_shape_count())
+ while (body->get_shape_count()) {
body->remove_shape(0);
+ }
}
void PhysicsServer3DSW::body_set_enable_continuous_collision_detection(RID p_body, bool p_enable) {
@@ -1288,8 +1297,9 @@ void PhysicsServer3DSW::init() {
void PhysicsServer3DSW::step(real_t p_step) {
#ifndef _3D_DISABLED
- if (!active)
+ if (!active) {
return;
+ }
_update_shapes();
@@ -1317,8 +1327,9 @@ void PhysicsServer3DSW::sync(){
void PhysicsServer3DSW::flush_queries() {
#ifndef _3D_DISABLED
- if (!active)
+ if (!active) {
return;
+ }
doing_sync = true;
@@ -1399,8 +1410,9 @@ void PhysicsServer3DSW::_update_shapes() {
void PhysicsServer3DSW::_shape_col_cbk(const Vector3 &p_point_A, const Vector3 &p_point_B, void *p_userdata) {
CollCbkData *cbk = (CollCbkData *)p_userdata;
- if (cbk->max == 0)
+ if (cbk->max == 0) {
return;
+ }
if (cbk->amount == cbk->max) {
//find least deep
@@ -1415,8 +1427,9 @@ void PhysicsServer3DSW::_shape_col_cbk(const Vector3 &p_point_A, const Vector3 &
}
real_t d = p_point_A.distance_squared_to(p_point_B);
- if (d < min_depth)
+ if (d < min_depth) {
return;
+ }
cbk->ptr[min_depth_idx * 2 + 0] = p_point_A;
cbk->ptr[min_depth_idx * 2 + 1] = p_point_B;
diff --git a/servers/physics_3d/shape_3d_sw.cpp b/servers/physics_3d/shape_3d_sw.cpp
index a44244f7d5..eb0e87cec0 100644
--- a/servers/physics_3d/shape_3d_sw.cpp
+++ b/servers/physics_3d/shape_3d_sw.cpp
@@ -105,8 +105,9 @@ Vector3 PlaneShape3DSW::get_support(const Vector3 &p_normal) const {
bool PlaneShape3DSW::intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal) const {
bool inters = plane.intersects_segment(p_begin, p_end, &r_result);
- if (inters)
+ if (inters) {
r_normal = plane.normal;
+ }
return inters;
}
@@ -159,10 +160,11 @@ void RayShape3DSW::project_range(const Vector3 &p_normal, const Transform &p_tra
}
Vector3 RayShape3DSW::get_support(const Vector3 &p_normal) const {
- if (p_normal.z > 0)
+ if (p_normal.z > 0) {
return Vector3(0, 0, length);
- else
+ } else {
return Vector3(0, 0, 0);
+ }
}
void RayShape3DSW::get_supports(const Vector3 &p_normal, int p_max, Vector3 *r_supports, int &r_amount) const {
@@ -260,8 +262,9 @@ bool SphereShape3DSW::intersect_point(const Vector3 &p_point) const {
Vector3 SphereShape3DSW::get_closest_point_to(const Vector3 &p_point) const {
Vector3 p = p_point;
float l = p.length();
- if (l < radius)
+ if (l < radius) {
return p_point;
+ }
return (p / l) * radius;
}
@@ -418,11 +421,13 @@ Vector3 BoxShape3DSW::get_closest_point_to(const Vector3 &p_point) const {
}
}
- if (!outside)
+ if (!outside) {
return p_point; //it's inside, don't do anything else
+ }
- if (outside == 1) //if only above one plane, this plane clearly wins
+ if (outside == 1) { //if only above one plane, this plane clearly wins
return min_point;
+ }
//check segments
float min_distance = 1e20;
@@ -597,8 +602,9 @@ Vector3 CapsuleShape3DSW::get_closest_point_to(const Vector3 &p_point) const {
Vector3 p = Geometry::get_closest_point_to_segment(p_point, s);
- if (p.distance_to(p_point) < radius)
+ if (p.distance_to(p_point) < radius) {
return p_point;
+ }
return p + (p_point - p).normalized() * radius;
}
@@ -641,18 +647,21 @@ CapsuleShape3DSW::CapsuleShape3DSW() {
void ConvexPolygonShape3DSW::project_range(const Vector3 &p_normal, const Transform &p_transform, real_t &r_min, real_t &r_max) const {
int vertex_count = mesh.vertices.size();
- if (vertex_count == 0)
+ if (vertex_count == 0) {
return;
+ }
const Vector3 *vrts = &mesh.vertices[0];
for (int i = 0; i < vertex_count; i++) {
real_t d = p_normal.dot(p_transform.xform(vrts[i]));
- if (i == 0 || d > r_max)
+ if (i == 0 || d > r_max) {
r_max = d;
- if (i == 0 || d < r_min)
+ }
+ if (i == 0 || d < r_min) {
r_min = d;
+ }
}
}
@@ -663,8 +672,9 @@ Vector3 ConvexPolygonShape3DSW::get_support(const Vector3 &p_normal) const {
real_t support_max = 0;
int vertex_count = mesh.vertices.size();
- if (vertex_count == 0)
+ if (vertex_count == 0) {
return Vector3();
+ }
const Vector3 *vrts = &mesh.vertices[0];
@@ -716,8 +726,9 @@ void ConvexPolygonShape3DSW::get_supports(const Vector3 &p_normal, int p_max, Ve
}
}
- if (!valid)
+ if (!valid) {
continue;
+ }
int m = MIN(p_max, ic);
for (int j = 0; j < m; j++) {
@@ -754,8 +765,9 @@ bool ConvexPolygonShape3DSW::intersect_segment(const Vector3 &p_begin, const Vec
bool col = false;
for (int i = 0; i < fc; i++) {
- if (faces[i].plane.normal.dot(n) > 0)
+ if (faces[i].plane.normal.dot(n) > 0) {
continue; //opposing face
+ }
int ic = faces[i].indices.size();
const int *ind = faces[i].indices.ptr();
@@ -785,8 +797,9 @@ bool ConvexPolygonShape3DSW::intersect_point(const Vector3 &p_point) const {
int fc = mesh.faces.size();
for (int i = 0; i < fc; i++) {
- if (faces[i].plane.distance_to(p_point) >= 0)
+ if (faces[i].plane.distance_to(p_point) >= 0) {
return false;
+ }
}
return true;
@@ -799,8 +812,9 @@ Vector3 ConvexPolygonShape3DSW::get_closest_point_to(const Vector3 &p_point) con
bool all_inside = true;
for (int i = 0; i < fc; i++) {
- if (!faces[i].plane.is_point_over(p_point))
+ if (!faces[i].plane.is_point_over(p_point)) {
continue;
+ }
all_inside = false;
bool is_inside = true;
@@ -861,16 +875,18 @@ Vector3 ConvexPolygonShape3DSW::get_moment_of_inertia(real_t p_mass) const {
void ConvexPolygonShape3DSW::_setup(const Vector<Vector3> &p_vertices) {
Error err = QuickHull::build(p_vertices, mesh);
- if (err != OK)
+ if (err != OK) {
ERR_PRINT("Failed to build QuickHull");
+ }
AABB _aabb;
for (int i = 0; i < mesh.vertices.size(); i++) {
- if (i == 0)
+ if (i == 0) {
_aabb.position = mesh.vertices[i];
- else
+ } else {
_aabb.expand_to(mesh.vertices[i]);
+ }
}
configure(_aabb);
@@ -894,11 +910,13 @@ void FaceShape3DSW::project_range(const Vector3 &p_normal, const Transform &p_tr
Vector3 v = p_transform.xform(vertex[i]);
real_t d = p_normal.dot(v);
- if (i == 0 || d > r_max)
+ if (i == 0 || d > r_max) {
r_max = d;
+ }
- if (i == 0 || d < r_min)
+ if (i == 0 || d < r_min) {
r_min = d;
+ }
}
}
@@ -948,8 +966,9 @@ void FaceShape3DSW::get_supports(const Vector3 &p_normal, int p_max, Vector3 *r_
for (int i = 0; i < 3; i++) {
int nx = (i + 1) % 3;
- if (i != vert_support_idx && nx != vert_support_idx)
+ if (i != vert_support_idx && nx != vert_support_idx) {
continue;
+ }
// check if edge is valid as a support
real_t dot = (vertex[i] - vertex[nx]).normalized().dot(n);
@@ -1021,17 +1040,20 @@ void ConcavePolygonShape3DSW::project_range(const Vector3 &p_normal, const Trans
for (int i = 0; i < count; i++) {
real_t d = p_normal.dot(p_transform.xform(vptr[i]));
- if (i == 0 || d > r_max)
+ if (i == 0 || d > r_max) {
r_max = d;
- if (i == 0 || d < r_min)
+ }
+ if (i == 0 || d < r_min) {
r_min = d;
+ }
}
}
Vector3 ConcavePolygonShape3DSW::get_support(const Vector3 &p_normal) const {
int count = vertices.size();
- if (count == 0)
+ if (count == 0) {
return Vector3();
+ }
const Vector3 *vptr = vertices.ptr();
@@ -1091,16 +1113,19 @@ void ConcavePolygonShape3DSW::_cull_segment(int p_idx, _SegmentCullParams *p_par
}
} else {
- if (bvh->left >= 0)
+ if (bvh->left >= 0) {
_cull_segment(bvh->left, p_params);
- if (bvh->right >= 0)
+ }
+ if (bvh->right >= 0) {
_cull_segment(bvh->right, p_params);
+ }
}
}
bool ConcavePolygonShape3DSW::intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal) const {
- if (faces.size() == 0)
+ if (faces.size() == 0) {
return false;
+ }
// unlock data
const Face *fr = faces.ptr();
@@ -1141,8 +1166,9 @@ Vector3 ConcavePolygonShape3DSW::get_closest_point_to(const Vector3 &p_point) co
void ConcavePolygonShape3DSW::_cull(int p_idx, _CullParams *p_params) const {
const BVH *bvh = &p_params->bvh[p_idx];
- if (!p_params->aabb.intersects(bvh->aabb))
+ if (!p_params->aabb.intersects(bvh->aabb)) {
return;
+ }
if (bvh->face_index >= 0) {
const Face *f = &p_params->faces[bvh->face_index];
@@ -1166,8 +1192,9 @@ void ConcavePolygonShape3DSW::_cull(int p_idx, _CullParams *p_params) const {
void ConcavePolygonShape3DSW::cull(const AABB &p_local_aabb, Callback p_callback, void *p_userdata) const {
// make matrix local to concave
- if (faces.size() == 0)
+ if (faces.size() == 0) {
return;
+ }
AABB local_aabb = p_local_aabb;
@@ -1250,10 +1277,11 @@ _VolumeSW_BVH *_volume_sw_build_bvh(_VolumeSW_BVH_Element *p_elements, int p_siz
AABB aabb;
for (int i = 0; i < p_size; i++) {
- if (i == 0)
+ if (i == 0) {
aabb = p_elements[i].aabb;
- else
+ } else {
aabb.merge_with(p_elements[i].aabb);
+ }
}
bvh->aabb = aabb;
switch (aabb.get_longest_axis_index()) {
@@ -1345,10 +1373,11 @@ void ConcavePolygonShape3DSW::_setup(Vector<Vector3> p_faces) {
verticesw[i * 3 + 0] = face.vertex[0];
verticesw[i * 3 + 1] = face.vertex[1];
verticesw[i * 3 + 2] = face.vertex[2];
- if (i == 0)
+ if (i == 0) {
_aabb = bvh_arrayw[i].aabb;
- else
+ } else {
_aabb.merge_with(bvh_arrayw[i].aabb);
+ }
}
int count = 0;
@@ -1443,10 +1472,11 @@ void HeightMapShape3DSW::_setup(Vector<real_t> p_heights, int p_width, int p_dep
real_t h = r[i * width + j];
Vector3 pos(j * cell_size, h, i * cell_size);
- if (i == 0 || j == 0)
+ if (i == 0 || j == 0) {
aabb.position = pos;
- else
+ } else {
aabb.expand_to(pos);
+ }
}
}
diff --git a/servers/physics_3d/space_3d_sw.cpp b/servers/physics_3d/space_3d_sw.cpp
index 066945d808..4d272bdabd 100644
--- a/servers/physics_3d/space_3d_sw.cpp
+++ b/servers/physics_3d/space_3d_sw.cpp
@@ -39,11 +39,13 @@ _FORCE_INLINE_ static bool _can_collide_with(CollisionObject3DSW *p_object, uint
return false;
}
- if (p_object->get_type() == CollisionObject3DSW::TYPE_AREA && !p_collide_with_areas)
+ if (p_object->get_type() == CollisionObject3DSW::TYPE_AREA && !p_collide_with_areas) {
return false;
+ }
- if (p_object->get_type() == CollisionObject3DSW::TYPE_BODY && !p_collide_with_bodies)
+ if (p_object->get_type() == CollisionObject3DSW::TYPE_BODY && !p_collide_with_bodies) {
return false;
+ }
return true;
}
@@ -56,16 +58,19 @@ int PhysicsDirectSpaceState3DSW::intersect_point(const Vector3 &p_point, ShapeRe
//Transform ai = p_xform.affine_inverse();
for (int i = 0; i < amount; i++) {
- if (cc >= p_result_max)
+ if (cc >= p_result_max) {
break;
+ }
- if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas))
+ if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas)) {
continue;
+ }
//area can't be picked by ray (default)
- if (p_exclude.has(space->intersection_query_results[i]->get_self()))
+ if (p_exclude.has(space->intersection_query_results[i]->get_self())) {
continue;
+ }
const CollisionObject3DSW *col_obj = space->intersection_query_results[i];
int shape_idx = space->intersection_query_subindex_results[i];
@@ -73,14 +78,16 @@ int PhysicsDirectSpaceState3DSW::intersect_point(const Vector3 &p_point, ShapeRe
Transform inv_xform = col_obj->get_transform() * col_obj->get_shape_transform(shape_idx);
inv_xform.affine_invert();
- if (!col_obj->get_shape(shape_idx)->intersect_point(inv_xform.xform(p_point)))
+ if (!col_obj->get_shape(shape_idx)->intersect_point(inv_xform.xform(p_point))) {
continue;
+ }
r_results[cc].collider_id = col_obj->get_instance_id();
- if (r_results[cc].collider_id.is_valid())
+ if (r_results[cc].collider_id.is_valid()) {
r_results[cc].collider = ObjectDB::get_instance(r_results[cc].collider_id);
- else
+ } else {
r_results[cc].collider = nullptr;
+ }
r_results[cc].rid = col_obj->get_self();
r_results[cc].shape = shape_idx;
@@ -110,14 +117,17 @@ bool PhysicsDirectSpaceState3DSW::intersect_ray(const Vector3 &p_from, const Vec
real_t min_d = 1e10;
for (int i = 0; i < amount; i++) {
- if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas))
+ if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas)) {
continue;
+ }
- if (p_pick_ray && !(space->intersection_query_results[i]->is_ray_pickable()))
+ if (p_pick_ray && !(space->intersection_query_results[i]->is_ray_pickable())) {
continue;
+ }
- if (p_exclude.has(space->intersection_query_results[i]->get_self()))
+ if (p_exclude.has(space->intersection_query_results[i]->get_self())) {
continue;
+ }
const CollisionObject3DSW *col_obj = space->intersection_query_results[i];
@@ -148,14 +158,16 @@ bool PhysicsDirectSpaceState3DSW::intersect_ray(const Vector3 &p_from, const Vec
}
}
- if (!collided)
+ if (!collided) {
return false;
+ }
r_result.collider_id = res_obj->get_instance_id();
- if (r_result.collider_id.is_valid())
+ if (r_result.collider_id.is_valid()) {
r_result.collider = ObjectDB::get_instance(r_result.collider_id);
- else
+ } else {
r_result.collider = nullptr;
+ }
r_result.normal = res_normal;
r_result.position = res_point;
r_result.rid = res_obj->get_self();
@@ -165,8 +177,9 @@ bool PhysicsDirectSpaceState3DSW::intersect_ray(const Vector3 &p_from, const Vec
}
int PhysicsDirectSpaceState3DSW::intersect_shape(const RID &p_shape, const Transform &p_xform, real_t p_margin, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas) {
- if (p_result_max <= 0)
+ if (p_result_max <= 0) {
return 0;
+ }
Shape3DSW *shape = static_cast<PhysicsServer3DSW *>(PhysicsServer3D::get_singleton())->shape_owner.getornull(p_shape);
ERR_FAIL_COND_V(!shape, 0);
@@ -180,29 +193,34 @@ int PhysicsDirectSpaceState3DSW::intersect_shape(const RID &p_shape, const Trans
//Transform ai = p_xform.affine_inverse();
for (int i = 0; i < amount; i++) {
- if (cc >= p_result_max)
+ if (cc >= p_result_max) {
break;
+ }
- if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas))
+ if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas)) {
continue;
+ }
//area can't be picked by ray (default)
- if (p_exclude.has(space->intersection_query_results[i]->get_self()))
+ if (p_exclude.has(space->intersection_query_results[i]->get_self())) {
continue;
+ }
const CollisionObject3DSW *col_obj = space->intersection_query_results[i];
int shape_idx = space->intersection_query_subindex_results[i];
- if (!CollisionSolver3DSW::solve_static(shape, p_xform, col_obj->get_shape(shape_idx), col_obj->get_transform() * col_obj->get_shape_transform(shape_idx), nullptr, nullptr, nullptr, p_margin, 0))
+ if (!CollisionSolver3DSW::solve_static(shape, p_xform, col_obj->get_shape(shape_idx), col_obj->get_transform() * col_obj->get_shape_transform(shape_idx), nullptr, nullptr, nullptr, p_margin, 0)) {
continue;
+ }
if (r_results) {
r_results[cc].collider_id = col_obj->get_instance_id();
- if (r_results[cc].collider_id.is_valid())
+ if (r_results[cc].collider_id.is_valid()) {
r_results[cc].collider = ObjectDB::get_instance(r_results[cc].collider_id);
- else
+ } else {
r_results[cc].collider = nullptr;
+ }
r_results[cc].rid = col_obj->get_self();
r_results[cc].shape = shape_idx;
}
@@ -236,11 +254,13 @@ bool PhysicsDirectSpaceState3DSW::cast_motion(const RID &p_shape, const Transfor
Vector3 closest_A, closest_B;
for (int i = 0; i < amount; i++) {
- if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas))
+ if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas)) {
continue;
+ }
- if (p_exclude.has(space->intersection_query_results[i]->get_self()))
+ if (p_exclude.has(space->intersection_query_results[i]->get_self())) {
continue; //ignore excluded
+ }
const CollisionObject3DSW *col_obj = space->intersection_query_results[i];
int shape_idx = space->intersection_query_subindex_results[i];
@@ -316,8 +336,9 @@ bool PhysicsDirectSpaceState3DSW::cast_motion(const RID &p_shape, const Transfor
}
bool PhysicsDirectSpaceState3DSW::collide_shape(RID p_shape, const Transform &p_shape_xform, real_t p_margin, Vector3 *r_results, int p_result_max, int &r_result_count, const Set<RID> &p_exclude, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas) {
- if (p_result_max <= 0)
+ if (p_result_max <= 0) {
return false;
+ }
Shape3DSW *shape = static_cast<PhysicsServer3DSW *>(PhysicsServer3D::get_singleton())->shape_owner.getornull(p_shape);
ERR_FAIL_COND_V(!shape, 0);
@@ -339,8 +360,9 @@ bool PhysicsDirectSpaceState3DSW::collide_shape(RID p_shape, const Transform &p_
PhysicsServer3DSW::CollCbkData *cbkptr = &cbk;
for (int i = 0; i < amount; i++) {
- if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas))
+ if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas)) {
continue;
+ }
const CollisionObject3DSW *col_obj = space->intersection_query_results[i];
int shape_idx = space->intersection_query_subindex_results[i];
@@ -375,10 +397,12 @@ static void _rest_cbk_result(const Vector3 &p_point_A, const Vector3 &p_point_B,
Vector3 contact_rel = p_point_B - p_point_A;
real_t len = contact_rel.length();
- if (len < rd->min_allowed_depth)
+ if (len < rd->min_allowed_depth) {
return;
- if (len <= rd->best_len)
+ }
+ if (len <= rd->best_len) {
return;
+ }
rd->best_len = len;
rd->best_contact = p_point_B;
@@ -403,24 +427,28 @@ bool PhysicsDirectSpaceState3DSW::rest_info(RID p_shape, const Transform &p_shap
rcd.min_allowed_depth = space->test_motion_min_contact_depth;
for (int i = 0; i < amount; i++) {
- if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas))
+ if (!_can_collide_with(space->intersection_query_results[i], p_collision_mask, p_collide_with_bodies, p_collide_with_areas)) {
continue;
+ }
const CollisionObject3DSW *col_obj = space->intersection_query_results[i];
int shape_idx = space->intersection_query_subindex_results[i];
- if (p_exclude.has(col_obj->get_self()))
+ if (p_exclude.has(col_obj->get_self())) {
continue;
+ }
rcd.object = col_obj;
rcd.shape = shape_idx;
bool sc = CollisionSolver3DSW::solve_static(shape, p_shape_xform, col_obj->get_shape(shape_idx), col_obj->get_transform() * col_obj->get_shape_transform(shape_idx), _rest_cbk_result, &rcd, nullptr, p_margin);
- if (!sc)
+ if (!sc) {
continue;
+ }
}
- if (rcd.best_len == 0 || !rcd.best_object)
+ if (rcd.best_len == 0 || !rcd.best_object) {
return false;
+ }
r_info->collider_id = rcd.best_object->get_instance_id();
r_info->shape = rcd.best_shape;
@@ -454,8 +482,9 @@ Vector3 PhysicsDirectSpaceState3DSW::get_closest_point_to_object_volume(RID p_ob
bool shapes_found = false;
for (int i = 0; i < obj->get_shape_count(); i++) {
- if (obj->is_shape_set_as_disabled(i))
+ if (obj->is_shape_set_as_disabled(i)) {
continue;
+ }
Transform shape_xform = obj->get_transform() * obj->get_shape_transform(i);
Shape3DSW *shape = obj->get_shape(i);
@@ -490,16 +519,17 @@ int Space3DSW::_cull_aabb_for_body(Body3DSW *p_body, const AABB &p_aabb) {
for (int i = 0; i < amount; i++) {
bool keep = true;
- if (intersection_query_results[i] == p_body)
+ if (intersection_query_results[i] == p_body) {
keep = false;
- else if (intersection_query_results[i]->get_type() == CollisionObject3DSW::TYPE_AREA)
+ } else if (intersection_query_results[i]->get_type() == CollisionObject3DSW::TYPE_AREA) {
keep = false;
- else if ((static_cast<Body3DSW *>(intersection_query_results[i])->test_collision_mask(p_body)) == 0)
+ } else if ((static_cast<Body3DSW *>(intersection_query_results[i])->test_collision_mask(p_body)) == 0) {
keep = false;
- else if (static_cast<Body3DSW *>(intersection_query_results[i])->has_exception(p_body->get_self()) || p_body->has_exception(intersection_query_results[i]->get_self()))
+ } else if (static_cast<Body3DSW *>(intersection_query_results[i])->has_exception(p_body->get_self()) || p_body->has_exception(intersection_query_results[i]->get_self())) {
keep = false;
- else if (static_cast<Body3DSW *>(intersection_query_results[i])->is_shape_set_as_disabled(intersection_query_subindex_results[i]))
+ } else if (static_cast<Body3DSW *>(intersection_query_results[i])->is_shape_set_as_disabled(intersection_query_subindex_results[i])) {
keep = false;
+ }
if (!keep) {
if (i < amount - 1) {
@@ -521,8 +551,9 @@ int Space3DSW::test_body_ray_separation(Body3DSW *p_body, const Transform &p_tra
bool shapes_found = false;
for (int i = 0; i < p_body->get_shape_count(); i++) {
- if (p_body->is_shape_set_as_disabled(i))
+ if (p_body->is_shape_set_as_disabled(i)) {
continue;
+ }
if (!shapes_found) {
body_aabb = p_body->get_shape_aabb(i);
@@ -567,13 +598,15 @@ int Space3DSW::test_body_ray_separation(Body3DSW *p_body, const Transform &p_tra
int amount = _cull_aabb_for_body(p_body, body_aabb);
for (int j = 0; j < p_body->get_shape_count(); j++) {
- if (p_body->is_shape_set_as_disabled(j))
+ if (p_body->is_shape_set_as_disabled(j)) {
continue;
+ }
Shape3DSW *body_shape = p_body->get_shape(j);
- if (body_shape->get_type() != PhysicsServer3D::SHAPE_RAY)
+ if (body_shape->get_type() != PhysicsServer3D::SHAPE_RAY) {
continue;
+ }
Transform body_shape_xform = body_transform * p_body->get_shape_transform(j);
@@ -681,8 +714,9 @@ bool Space3DSW::test_body_motion(Body3DSW *p_body, const Transform &p_from, cons
bool shapes_found = false;
for (int i = 0; i < p_body->get_shape_count(); i++) {
- if (p_body->is_shape_set_as_disabled(i))
+ if (p_body->is_shape_set_as_disabled(i)) {
continue;
+ }
if (!shapes_found) {
body_aabb = p_body->get_shape_aabb(i);
@@ -728,8 +762,9 @@ bool Space3DSW::test_body_motion(Body3DSW *p_body, const Transform &p_from, cons
int amount = _cull_aabb_for_body(p_body, body_aabb);
for (int j = 0; j < p_body->get_shape_count(); j++) {
- if (p_body->is_shape_set_as_disabled(j))
+ if (p_body->is_shape_set_as_disabled(j)) {
continue;
+ }
Transform body_shape_xform = body_transform * p_body->get_shape_transform(j);
Shape3DSW *body_shape = p_body->get_shape(j);
@@ -786,8 +821,9 @@ bool Space3DSW::test_body_motion(Body3DSW *p_body, const Transform &p_from, cons
int amount = _cull_aabb_for_body(p_body, motion_aabb);
for (int j = 0; j < p_body->get_shape_count(); j++) {
- if (p_body->is_shape_set_as_disabled(j))
+ if (p_body->is_shape_set_as_disabled(j)) {
continue;
+ }
Transform body_shape_xform = body_transform * p_body->get_shape_transform(j);
Shape3DSW *body_shape = p_body->get_shape(j);
@@ -910,8 +946,9 @@ bool Space3DSW::test_body_motion(Body3DSW *p_body, const Transform &p_from, cons
rcd.object = col_obj;
rcd.shape = shape_idx;
bool sc = CollisionSolver3DSW::solve_static(body_shape, body_shape_xform, col_obj->get_shape(shape_idx), col_obj->get_transform() * col_obj->get_shape_transform(shape_idx), _rest_cbk_result, &rcd, nullptr, p_margin);
- if (!sc)
+ if (!sc) {
continue;
+ }
}
if (rcd.best_len != 0) {
@@ -1179,8 +1216,9 @@ Space3DSW::Space3DSW() {
direct_access = memnew(PhysicsDirectSpaceState3DSW);
direct_access->space = this;
- for (int i = 0; i < ELAPSED_TIME_MAX; i++)
+ for (int i = 0; i < ELAPSED_TIME_MAX; i++) {
elapsed_time[i] = 0;
+ }
}
Space3DSW::~Space3DSW() {
diff --git a/servers/physics_3d/space_3d_sw.h b/servers/physics_3d/space_3d_sw.h
index c8b1ad32c1..f9198e3d40 100644
--- a/servers/physics_3d/space_3d_sw.h
+++ b/servers/physics_3d/space_3d_sw.h
@@ -185,8 +185,9 @@ public:
void set_debug_contacts(int p_amount) { contact_debug.resize(p_amount); }
_FORCE_INLINE_ bool is_debugging_contacts() const { return !contact_debug.empty(); }
_FORCE_INLINE_ void add_debug_contact(const Vector3 &p_contact) {
- if (contact_debug_count < contact_debug.size())
+ if (contact_debug_count < contact_debug.size()) {
contact_debug.write[contact_debug_count++] = p_contact;
+ }
}
_FORCE_INLINE_ Vector<Vector3> get_debug_contacts() { return contact_debug; }
_FORCE_INLINE_ int get_debug_contact_count() { return contact_debug_count; }
diff --git a/servers/physics_3d/step_3d_sw.cpp b/servers/physics_3d/step_3d_sw.cpp
index 5c84eb05d0..9a2a0073a1 100644
--- a/servers/physics_3d/step_3d_sw.cpp
+++ b/servers/physics_3d/step_3d_sw.cpp
@@ -40,18 +40,21 @@ void Step3DSW::_populate_island(Body3DSW *p_body, Body3DSW **p_island, Constrain
for (Map<Constraint3DSW *, int>::Element *E = p_body->get_constraint_map().front(); E; E = E->next()) {
Constraint3DSW *c = (Constraint3DSW *)E->key();
- if (c->get_island_step() == _step)
+ if (c->get_island_step() == _step) {
continue; //already processed
+ }
c->set_island_step(_step);
c->set_island_next(*p_constraint_island);
*p_constraint_island = c;
for (int i = 0; i < c->get_body_count(); i++) {
- if (i == E->get())
+ if (i == E->get()) {
continue;
+ }
Body3DSW *b = c->get_body_ptr()[i];
- if (b->get_island_step() == _step || b->get_mode() == PhysicsServer3D::BODY_MODE_STATIC || b->get_mode() == PhysicsServer3D::BODY_MODE_KINEMATIC)
+ if (b->get_island_step() == _step || b->get_mode() == PhysicsServer3D::BODY_MODE_STATIC || b->get_mode() == PhysicsServer3D::BODY_MODE_KINEMATIC) {
continue; //no go
+ }
_populate_island(c->get_body_ptr()[i], p_island, p_constraint_island);
}
}
@@ -110,8 +113,9 @@ void Step3DSW::_check_suspend(Body3DSW *p_island, real_t p_delta) {
continue; //ignore for static
}
- if (!b->sleep_test(p_delta))
+ if (!b->sleep_test(p_delta)) {
can_sleep = false;
+ }
b = b->get_island_next();
}
@@ -127,8 +131,9 @@ void Step3DSW::_check_suspend(Body3DSW *p_island, real_t p_delta) {
bool active = b->is_active();
- if (active == can_sleep)
+ if (active == can_sleep) {
b->set_active(!can_sleep);
+ }
b = b->get_island_next();
}
@@ -198,8 +203,9 @@ void Step3DSW::step(Space3DSW *p_space, real_t p_delta, int p_iterations) {
while (aml.first()) {
for (const Set<Constraint3DSW *>::Element *E = aml.first()->self()->get_constraints().front(); E; E = E->next()) {
Constraint3DSW *c = E->get();
- if (c->get_island_step() == _step)
+ if (c->get_island_step() == _step) {
continue;
+ }
c->set_island_step(_step);
c->set_island_next(nullptr);
c->set_island_list_next(constraint_island_list);
diff --git a/servers/physics_server_2d.cpp b/servers/physics_server_2d.cpp
index e3051c8fba..c2de7fbd00 100644
--- a/servers/physics_server_2d.cpp
+++ b/servers/physics_server_2d.cpp
@@ -45,15 +45,17 @@ void PhysicsDirectBodyState2D::integrate_forces() {
float damp = 1.0 - step * get_total_linear_damp();
- if (damp < 0) // reached zero in the given time
+ if (damp < 0) { // reached zero in the given time
damp = 0;
+ }
lv *= damp;
damp = 1.0 - step * get_total_angular_damp();
- if (damp < 0) // reached zero in the given time
+ if (damp < 0) { // reached zero in the given time
damp = 0;
+ }
av *= damp;
@@ -177,8 +179,9 @@ int PhysicsShapeQueryParameters2D::get_collision_mask() const {
void PhysicsShapeQueryParameters2D::set_exclude(const Vector<RID> &p_exclude) {
exclude.clear();
- for (int i = 0; i < p_exclude.size(); i++)
+ for (int i = 0; i < p_exclude.size(); i++) {
exclude.insert(p_exclude[i]);
+ }
}
Vector<RID> PhysicsShapeQueryParameters2D::get_exclude() const {
@@ -254,13 +257,15 @@ PhysicsShapeQueryParameters2D::PhysicsShapeQueryParameters2D() {
Dictionary PhysicsDirectSpaceState2D::_intersect_ray(const Vector2 &p_from, const Vector2 &p_to, const Vector<RID> &p_exclude, uint32_t p_layers, bool p_collide_with_bodies, bool p_collide_with_areas) {
RayResult inters;
Set<RID> exclude;
- for (int i = 0; i < p_exclude.size(); i++)
+ for (int i = 0; i < p_exclude.size(); i++) {
exclude.insert(p_exclude[i]);
+ }
bool res = intersect_ray(p_from, p_to, inters, exclude, p_layers, p_collide_with_bodies, p_collide_with_areas);
- if (!res)
+ if (!res) {
return Dictionary();
+ }
Dictionary d;
d["position"] = inters.position;
@@ -300,8 +305,9 @@ Array PhysicsDirectSpaceState2D::_cast_motion(const Ref<PhysicsShapeQueryParamet
float closest_safe, closest_unsafe;
bool res = cast_motion(p_shape_query->shape, p_shape_query->transform, p_shape_query->motion, p_shape_query->margin, closest_safe, closest_unsafe, p_shape_query->exclude, p_shape_query->collision_mask, p_shape_query->collide_with_bodies, p_shape_query->collide_with_areas);
- if (!res)
+ if (!res) {
return Array();
+ }
Array ret;
ret.resize(2);
ret[0] = closest_safe;
@@ -311,20 +317,23 @@ Array PhysicsDirectSpaceState2D::_cast_motion(const Ref<PhysicsShapeQueryParamet
Array PhysicsDirectSpaceState2D::_intersect_point_impl(const Vector2 &p_point, int p_max_results, const Vector<RID> &p_exclude, uint32_t p_layers, bool p_collide_with_bodies, bool p_collide_with_areas, bool p_filter_by_canvas, ObjectID p_canvas_instance_id) {
Set<RID> exclude;
- for (int i = 0; i < p_exclude.size(); i++)
+ for (int i = 0; i < p_exclude.size(); i++) {
exclude.insert(p_exclude[i]);
+ }
Vector<ShapeResult> ret;
ret.resize(p_max_results);
int rc;
- if (p_filter_by_canvas)
+ if (p_filter_by_canvas) {
rc = intersect_point(p_point, ret.ptrw(), ret.size(), exclude, p_layers, p_collide_with_bodies, p_collide_with_areas);
- else
+ } else {
rc = intersect_point_on_canvas(p_point, p_canvas_instance_id, ret.ptrw(), ret.size(), exclude, p_layers, p_collide_with_bodies, p_collide_with_areas);
+ }
- if (rc == 0)
+ if (rc == 0) {
return Array();
+ }
Array r;
r.resize(rc);
@@ -355,12 +364,14 @@ Array PhysicsDirectSpaceState2D::_collide_shape(const Ref<PhysicsShapeQueryParam
ret.resize(p_max_results * 2);
int rc = 0;
bool res = collide_shape(p_shape_query->shape, p_shape_query->transform, p_shape_query->motion, p_shape_query->margin, ret.ptrw(), p_max_results, rc, p_shape_query->exclude, p_shape_query->collision_mask, p_shape_query->collide_with_bodies, p_shape_query->collide_with_areas);
- if (!res)
+ if (!res) {
return Array();
+ }
Array r;
r.resize(rc * 2);
- for (int i = 0; i < rc * 2; i++)
+ for (int i = 0; i < rc * 2; i++) {
r[i] = ret[i];
+ }
return r;
}
@@ -371,8 +382,9 @@ Dictionary PhysicsDirectSpaceState2D::_get_rest_info(const Ref<PhysicsShapeQuery
bool res = rest_info(p_shape_query->shape, p_shape_query->transform, p_shape_query->motion, p_shape_query->margin, &sri, p_shape_query->exclude, p_shape_query->collision_mask, p_shape_query->collide_with_bodies, p_shape_query->collide_with_areas);
Dictionary r;
- if (!res)
+ if (!res) {
return r;
+ }
r["point"] = sri.point;
r["normal"] = sri.normal;
@@ -499,8 +511,9 @@ PhysicsTestMotionResult2D::PhysicsTestMotionResult2D() {
bool PhysicsServer2D::_body_test_motion(RID p_body, const Transform2D &p_from, const Vector2 &p_motion, bool p_infinite_inertia, float p_margin, const Ref<PhysicsTestMotionResult2D> &p_result) {
MotionResult *r = nullptr;
- if (p_result.is_valid())
+ if (p_result.is_valid()) {
r = p_result->get_result_ptr();
+ }
return body_test_motion(p_body, p_from, p_motion, p_infinite_inertia, p_margin, r);
}
diff --git a/servers/physics_server_3d.cpp b/servers/physics_server_3d.cpp
index c8f5ae985e..2dd8ea3edb 100644
--- a/servers/physics_server_3d.cpp
+++ b/servers/physics_server_3d.cpp
@@ -45,13 +45,15 @@ void PhysicsDirectBodyState3D::integrate_forces() {
float linear_damp = 1.0 - step * get_total_linear_damp();
- if (linear_damp < 0) // reached zero in the given time
+ if (linear_damp < 0) { // reached zero in the given time
linear_damp = 0;
+ }
float angular_damp = 1.0 - step * get_total_angular_damp();
- if (angular_damp < 0) // reached zero in the given time
+ if (angular_damp < 0) { // reached zero in the given time
angular_damp = 0;
+ }
lv *= linear_damp;
av *= angular_damp;
@@ -173,8 +175,9 @@ int PhysicsShapeQueryParameters3D::get_collision_mask() const {
void PhysicsShapeQueryParameters3D::set_exclude(const Vector<RID> &p_exclude) {
exclude.clear();
- for (int i = 0; i < p_exclude.size(); i++)
+ for (int i = 0; i < p_exclude.size(); i++) {
exclude.insert(p_exclude[i]);
+ }
}
Vector<RID> PhysicsShapeQueryParameters3D::get_exclude() const {
@@ -248,13 +251,15 @@ PhysicsShapeQueryParameters3D::PhysicsShapeQueryParameters3D() {
Dictionary PhysicsDirectSpaceState3D::_intersect_ray(const Vector3 &p_from, const Vector3 &p_to, const Vector<RID> &p_exclude, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas) {
RayResult inters;
Set<RID> exclude;
- for (int i = 0; i < p_exclude.size(); i++)
+ for (int i = 0; i < p_exclude.size(); i++) {
exclude.insert(p_exclude[i]);
+ }
bool res = intersect_ray(p_from, p_to, inters, exclude, p_collision_mask, p_collide_with_bodies, p_collide_with_areas);
- if (!res)
+ if (!res) {
return Dictionary();
+ }
Dictionary d;
d["position"] = inters.position;
@@ -292,8 +297,9 @@ Array PhysicsDirectSpaceState3D::_cast_motion(const Ref<PhysicsShapeQueryParamet
float closest_safe, closest_unsafe;
bool res = cast_motion(p_shape_query->shape, p_shape_query->transform, p_motion, p_shape_query->margin, closest_safe, closest_unsafe, p_shape_query->exclude, p_shape_query->collision_mask, p_shape_query->collide_with_bodies, p_shape_query->collide_with_areas);
- if (!res)
+ if (!res) {
return Array();
+ }
Array ret;
ret.resize(2);
ret[0] = closest_safe;
@@ -308,12 +314,14 @@ Array PhysicsDirectSpaceState3D::_collide_shape(const Ref<PhysicsShapeQueryParam
ret.resize(p_max_results * 2);
int rc = 0;
bool res = collide_shape(p_shape_query->shape, p_shape_query->transform, p_shape_query->margin, ret.ptrw(), p_max_results, rc, p_shape_query->exclude, p_shape_query->collision_mask, p_shape_query->collide_with_bodies, p_shape_query->collide_with_areas);
- if (!res)
+ if (!res) {
return Array();
+ }
Array r;
r.resize(rc * 2);
- for (int i = 0; i < rc * 2; i++)
+ for (int i = 0; i < rc * 2; i++) {
r[i] = ret[i];
+ }
return r;
}
@@ -324,8 +332,9 @@ Dictionary PhysicsDirectSpaceState3D::_get_rest_info(const Ref<PhysicsShapeQuery
bool res = rest_info(p_shape_query->shape, p_shape_query->transform, p_shape_query->margin, &sri, p_shape_query->exclude, p_shape_query->collision_mask, p_shape_query->collide_with_bodies, p_shape_query->collide_with_areas);
Dictionary r;
- if (!res)
+ if (!res) {
return r;
+ }
r["point"] = sri.point;
r["normal"] = sri.normal;
diff --git a/servers/rendering/rasterizer.h b/servers/rendering/rasterizer.h
index d262e2ba81..e0d4432fd5 100644
--- a/servers/rendering/rasterizer.h
+++ b/servers/rendering/rasterizer.h
@@ -855,8 +855,9 @@ public:
_FORCE_INLINE_ TextureBinding() { binding_id = 0; }
_FORCE_INLINE_ ~TextureBinding() {
- if (binding_id)
+ if (binding_id) {
singleton->free_texture_binding(binding_id);
+ }
}
};
@@ -884,8 +885,9 @@ public:
_FORCE_INLINE_ Polygon() { polygon_id = 0; }
_FORCE_INLINE_ ~Polygon() {
- if (polygon_id)
+ if (polygon_id) {
singleton->free_polygon(polygon_id);
+ }
}
};
@@ -1054,8 +1056,9 @@ public:
Rect2 global_rect_cache;
const Rect2 &get_rect() const {
- if (custom_rect || (!rect_dirty && !update_when_visible))
+ if (custom_rect || (!rect_dirty && !update_when_visible)) {
return rect;
+ }
//must update rect
@@ -1265,8 +1268,9 @@ public:
for (int i = 0; i < blocks.size(); i++) {
memfree(blocks[i].memory);
}
- if (copy_back_buffer)
+ if (copy_back_buffer) {
memdelete(copy_back_buffer);
+ }
if (custom_data) {
memdelete(custom_data);
}
diff --git a/servers/rendering/rasterizer_rd/rasterizer_scene_high_end_rd.cpp b/servers/rendering/rasterizer_rd/rasterizer_scene_high_end_rd.cpp
index 2b747cd04a..7d351f249a 100644
--- a/servers/rendering/rasterizer_rd/rasterizer_scene_high_end_rd.cpp
+++ b/servers/rendering/rasterizer_rd/rasterizer_scene_high_end_rd.cpp
@@ -1297,8 +1297,9 @@ void RasterizerSceneHighEndRD::_add_geometry(InstanceBase *p_instance, uint32_t
while (material->next_pass.is_valid()) {
material = (MaterialData *)storage->material_get_data(material->next_pass, RasterizerStorageRD::SHADER_TYPE_3D);
- if (!material || !material->shader_data->valid)
+ if (!material || !material->shader_data->valid) {
break;
+ }
_add_geometry_with_material(p_instance, p_surface, material, material->next_pass, p_pass_mode, p_geometry_index);
}
}
@@ -1347,8 +1348,9 @@ void RasterizerSceneHighEndRD::_add_geometry_with_material(InstanceBase *p_insta
RenderList::Element *e = (has_alpha || p_material->shader_data->depth_test == ShaderData::DEPTH_TEST_DISABLED) ? render_list.add_alpha_element() : render_list.add_element();
- if (!e)
+ if (!e) {
return;
+ }
e->instance = p_instance;
e->material = p_material;
diff --git a/servers/rendering/rasterizer_rd/rasterizer_scene_high_end_rd.h b/servers/rendering/rasterizer_rd/rasterizer_scene_high_end_rd.h
index 38bb5e5396..8438a4f730 100644
--- a/servers/rendering/rasterizer_rd/rasterizer_scene_high_end_rd.h
+++ b/servers/rendering/rasterizer_rd/rasterizer_scene_high_end_rd.h
@@ -576,15 +576,17 @@ class RasterizerSceneHighEndRD : public RasterizerSceneRD {
}
_FORCE_INLINE_ Element *add_element() {
- if (element_count + alpha_element_count >= max_elements)
+ if (element_count + alpha_element_count >= max_elements) {
return nullptr;
+ }
elements[element_count] = &base_elements[element_count];
return elements[element_count++];
}
_FORCE_INLINE_ Element *add_alpha_element() {
- if (element_count + alpha_element_count >= max_elements)
+ if (element_count + alpha_element_count >= max_elements) {
return nullptr;
+ }
int idx = max_elements - alpha_element_count - 1;
elements[idx] = &base_elements[idx];
alpha_element_count++;
@@ -596,8 +598,9 @@ class RasterizerSceneHighEndRD : public RasterizerSceneRD {
alpha_element_count = 0;
elements = memnew_arr(Element *, max_elements);
base_elements = memnew_arr(Element, max_elements);
- for (int i = 0; i < max_elements; i++)
+ for (int i = 0; i < max_elements; i++) {
elements[i] = &base_elements[i]; // assign elements
+ }
}
RenderList() {
diff --git a/servers/rendering/rasterizer_rd/rasterizer_scene_rd.cpp b/servers/rendering/rasterizer_rd/rasterizer_scene_rd.cpp
index ac986fab58..689552be2f 100644
--- a/servers/rendering/rasterizer_rd/rasterizer_scene_rd.cpp
+++ b/servers/rendering/rasterizer_rd/rasterizer_scene_rd.cpp
@@ -1676,8 +1676,9 @@ void RasterizerSceneRD::shadow_atlas_set_size(RID p_atlas, int p_size) {
ERR_FAIL_COND(p_size < 0);
p_size = next_power_of_2(p_size);
- if (p_size == shadow_atlas->size)
+ if (p_size == shadow_atlas->size) {
return;
+ }
// erasing atlas
if (shadow_atlas->depth.is_valid()) {
@@ -1728,8 +1729,9 @@ void RasterizerSceneRD::shadow_atlas_set_quadrant_subdivision(RID p_atlas, int p
//obtain the number that will be x*x
- if (shadow_atlas->quadrants[p_quadrant].subdivision == subdiv)
+ if (shadow_atlas->quadrants[p_quadrant].subdivision == subdiv) {
return;
+ }
//erase all data from quadrant
for (int i = 0; i < shadow_atlas->quadrants[p_quadrant].shadows.size(); i++) {
@@ -1801,8 +1803,9 @@ bool RasterizerSceneRD::_shadow_atlas_find_shadow(ShadowAtlas *shadow_atlas, int
if (sli->last_scene_pass != scene_pass) {
//was just allocated, don't kill it so soon, wait a bit..
- if (p_tick - sarr[j].alloc_tick < shadow_atlas_realloc_tolerance_msec)
+ if (p_tick - sarr[j].alloc_tick < shadow_atlas_realloc_tolerance_msec) {
continue;
+ }
if (found_used_idx == -1 || sli->last_scene_pass < min_pass) {
found_used_idx = j;
@@ -1811,8 +1814,9 @@ bool RasterizerSceneRD::_shadow_atlas_find_shadow(ShadowAtlas *shadow_atlas, int
}
}
- if (found_free_idx == -1 && found_used_idx == -1)
+ if (found_free_idx == -1 && found_used_idx == -1) {
continue; //nothing found
+ }
if (found_free_idx == -1 && found_used_idx != -1) {
found_free_idx = found_used_idx;
@@ -1850,13 +1854,15 @@ bool RasterizerSceneRD::shadow_atlas_update_light(RID p_atlas, RID p_light_intan
for (int i = 0; i < 4; i++) {
int q = shadow_atlas->size_order[i];
int sd = shadow_atlas->quadrants[q].subdivision;
- if (sd == 0)
+ if (sd == 0) {
continue; //unused
+ }
int max_fit = quad_size / sd;
- if (best_size != -1 && max_fit > best_size)
+ if (best_size != -1 && max_fit > best_size) {
break; //too large
+ }
valid_quadrants[valid_quadrant_count++] = q;
best_subdiv = sd;
diff --git a/servers/rendering/rasterizer_rd/rasterizer_storage_rd.cpp b/servers/rendering/rasterizer_rd/rasterizer_storage_rd.cpp
index c04bbc6c06..4f216d7cb5 100644
--- a/servers/rendering/rasterizer_rd/rasterizer_storage_rd.cpp
+++ b/servers/rendering/rasterizer_rd/rasterizer_storage_rd.cpp
@@ -1006,16 +1006,17 @@ void RasterizerStorageRD::shader_set_code(RID p_shader, const String &p_code) {
String mode_string = ShaderLanguage::get_shader_type(p_code);
ShaderType new_type;
- if (mode_string == "canvas_item")
+ if (mode_string == "canvas_item") {
new_type = SHADER_TYPE_2D;
- else if (mode_string == "particles")
+ } else if (mode_string == "particles") {
new_type = SHADER_TYPE_PARTICLES;
- else if (mode_string == "spatial")
+ } else if (mode_string == "spatial") {
new_type = SHADER_TYPE_3D;
- else if (mode_string == "sky")
+ } else if (mode_string == "sky") {
new_type = SHADER_TYPE_SKY;
- else
+ } else {
new_type = SHADER_TYPE_MAX;
+ }
if (new_type != shader->type) {
if (shader->data) {
@@ -1341,10 +1342,11 @@ _FORCE_INLINE_ static void _fill_std140_variant_ubo_value(ShaderLanguage::DataTy
const int *r = iv.ptr();
for (int i = 0; i < 2; i++) {
- if (i < s)
+ if (i < s) {
gui[i] = r[i];
- else
+ } else {
gui[i] = 0;
+ }
}
} break;
@@ -1356,10 +1358,11 @@ _FORCE_INLINE_ static void _fill_std140_variant_ubo_value(ShaderLanguage::DataTy
const int *r = iv.ptr();
for (int i = 0; i < 3; i++) {
- if (i < s)
+ if (i < s) {
gui[i] = r[i];
- else
+ } else {
gui[i] = 0;
+ }
}
} break;
case ShaderLanguage::TYPE_IVEC4: {
@@ -1370,10 +1373,11 @@ _FORCE_INLINE_ static void _fill_std140_variant_ubo_value(ShaderLanguage::DataTy
const int *r = iv.ptr();
for (int i = 0; i < 4; i++) {
- if (i < s)
+ if (i < s) {
gui[i] = r[i];
- else
+ } else {
gui[i] = 0;
+ }
}
} break;
case ShaderLanguage::TYPE_UINT: {
@@ -1390,10 +1394,11 @@ _FORCE_INLINE_ static void _fill_std140_variant_ubo_value(ShaderLanguage::DataTy
const int *r = iv.ptr();
for (int i = 0; i < 2; i++) {
- if (i < s)
+ if (i < s) {
gui[i] = r[i];
- else
+ } else {
gui[i] = 0;
+ }
}
} break;
case ShaderLanguage::TYPE_UVEC3: {
@@ -1404,10 +1409,11 @@ _FORCE_INLINE_ static void _fill_std140_variant_ubo_value(ShaderLanguage::DataTy
const int *r = iv.ptr();
for (int i = 0; i < 3; i++) {
- if (i < s)
+ if (i < s) {
gui[i] = r[i];
- else
+ } else {
gui[i] = 0;
+ }
}
} break;
@@ -1419,10 +1425,11 @@ _FORCE_INLINE_ static void _fill_std140_variant_ubo_value(ShaderLanguage::DataTy
const int *r = iv.ptr();
for (int i = 0; i < 4; i++) {
- if (i < s)
+ if (i < s) {
gui[i] = r[i];
- else
+ } else {
gui[i] = 0;
+ }
}
} break;
case ShaderLanguage::TYPE_FLOAT: {
@@ -1735,8 +1742,9 @@ void RasterizerStorageRD::MaterialData::update_uniform_buffer(const Map<StringNa
bool uses_global_buffer = false;
for (Map<StringName, ShaderLanguage::ShaderNode::Uniform>::Element *E = p_uniforms.front(); E; E = E->next()) {
- if (E->get().order < 0)
+ if (E->get().order < 0) {
continue; // texture, does not go here
+ }
if (E->get().scope == ShaderLanguage::ShaderNode::Uniform::SCOPE_INSTANCE) {
continue; //instance uniforms don't appear in the bufferr
@@ -2280,8 +2288,9 @@ AABB RasterizerStorageRD::mesh_get_aabb(RID p_mesh, RID p_skeleton) {
if (skeleton->use_2d) {
for (int j = 0; j < bs; j++) {
- if (skbones[0].size == Vector3())
+ if (skbones[0].size == Vector3()) {
continue; //bone is unused
+ }
const float *dataptr = baseptr + j * 8;
@@ -2306,8 +2315,9 @@ AABB RasterizerStorageRD::mesh_get_aabb(RID p_mesh, RID p_skeleton) {
}
} else {
for (int j = 0; j < bs; j++) {
- if (skbones[0].size == Vector3())
+ if (skbones[0].size == Vector3()) {
continue; //bone is unused
+ }
const float *dataptr = baseptr + j * 12;
@@ -3109,8 +3119,9 @@ void RasterizerStorageRD::skeleton_allocate(RID p_skeleton, int p_bones, bool p_
ERR_FAIL_COND(!skeleton);
ERR_FAIL_COND(p_bones < 0);
- if (skeleton->size == p_bones && skeleton->use_2d == p_2d_skeleton)
+ if (skeleton->size == p_bones && skeleton->use_2d == p_2d_skeleton) {
return;
+ }
skeleton->size = p_bones;
skeleton->use_2d = p_2d_skeleton;
diff --git a/servers/rendering/rasterizer_rd/shader_compiler_rd.cpp b/servers/rendering/rasterizer_rd/shader_compiler_rd.cpp
index b24874345e..d0b91df470 100644
--- a/servers/rendering/rasterizer_rd/shader_compiler_rd.cpp
+++ b/servers/rendering/rasterizer_rd/shader_compiler_rd.cpp
@@ -265,8 +265,9 @@ static String get_constant_text(SL::DataType p_type, const Vector<SL::ConstantNo
case SL::TYPE_BVEC4: {
String text = "bvec" + itos(p_type - SL::TYPE_BOOL + 1) + "(";
for (int i = 0; i < p_values.size(); i++) {
- if (i > 0)
+ if (i > 0) {
text += ",";
+ }
text += p_values[i].boolean ? "true" : "false";
}
@@ -281,8 +282,9 @@ static String get_constant_text(SL::DataType p_type, const Vector<SL::ConstantNo
case SL::TYPE_IVEC4: {
String text = "ivec" + itos(p_type - SL::TYPE_INT + 1) + "(";
for (int i = 0; i < p_values.size(); i++) {
- if (i > 0)
+ if (i > 0) {
text += ",";
+ }
text += itos(p_values[i].sint);
}
@@ -297,8 +299,9 @@ static String get_constant_text(SL::DataType p_type, const Vector<SL::ConstantNo
case SL::TYPE_UVEC4: {
String text = "uvec" + itos(p_type - SL::TYPE_UINT + 1) + "(";
for (int i = 0; i < p_values.size(); i++) {
- if (i > 0)
+ if (i > 0) {
text += ",";
+ }
text += itos(p_values[i].uint) + "u";
}
@@ -312,8 +315,9 @@ static String get_constant_text(SL::DataType p_type, const Vector<SL::ConstantNo
case SL::TYPE_VEC4: {
String text = "vec" + itos(p_type - SL::TYPE_FLOAT + 1) + "(";
for (int i = 0; i < p_values.size(); i++) {
- if (i > 0)
+ if (i > 0) {
text += ",";
+ }
text += f2sp0(p_values[i].real);
}
@@ -326,8 +330,9 @@ static String get_constant_text(SL::DataType p_type, const Vector<SL::ConstantNo
case SL::TYPE_MAT4: {
String text = "mat" + itos(p_type - SL::TYPE_MAT2 + 2) + "(";
for (int i = 0; i < p_values.size(); i++) {
- if (i > 0)
+ if (i > 0) {
text += ",";
+ }
text += f2sp0(p_values[i].real);
}
@@ -391,8 +396,9 @@ void ShaderCompilerRD::_dump_function_deps(const SL::ShaderNode *p_node, const S
header = _typestr(fnode->return_type) + " " + _mkid(fnode->name) + "(";
}
for (int i = 0; i < fnode->arguments.size(); i++) {
- if (i > 0)
+ if (i > 0) {
header += ", ";
+ }
if (fnode->arguments[i].type == SL::TYPE_STRUCT) {
header += _qualstr(fnode->arguments[i].qualifier) + _mkid(fnode->arguments[i].type_str) + " " + _mkid(fnode->arguments[i].name);
} else {
@@ -828,9 +834,9 @@ String ShaderCompilerRD::_dump_node_code(const SL::Node *p_node, int p_level, Ge
used_flag_pointers.insert(vnode->name);
}
- if (p_default_actions.renames.has(vnode->name))
+ if (p_default_actions.renames.has(vnode->name)) {
code = p_default_actions.renames[vnode->name];
- else {
+ } else {
if (shader->uniforms.has(vnode->name)) {
//its a uniform!
const ShaderLanguage::ShaderNode::Uniform &u = shader->uniforms[vnode->name];
@@ -953,10 +959,11 @@ String ShaderCompilerRD::_dump_node_code(const SL::Node *p_node, int p_level, Ge
used_flag_pointers.insert(anode->name);
}
- if (p_default_actions.renames.has(anode->name))
+ if (p_default_actions.renames.has(anode->name)) {
code = p_default_actions.renames[anode->name];
- else
+ } else {
code = _mkid(anode->name);
+ }
if (anode->call_expression != nullptr) {
code += ".";
@@ -1038,8 +1045,9 @@ String ShaderCompilerRD::_dump_node_code(const SL::Node *p_node, int p_level, Ge
code += "(";
for (int i = 1; i < onode->arguments.size(); i++) {
- if (i > 1)
+ if (i > 1) {
code += ", ";
+ }
String node_code = _dump_node_code(onode->arguments[i], p_level, r_gen_code, p_actions, p_default_actions, p_assigning);
if (is_texture_func && i == 1 && onode->arguments[i]->type == SL::Node::TYPE_VARIABLE) {
//need to map from texture to sampler in order to sample
diff --git a/servers/rendering/rendering_server_canvas.cpp b/servers/rendering/rendering_server_canvas.cpp
index 324765a217..0c9290a765 100644
--- a/servers/rendering/rendering_server_canvas.cpp
+++ b/servers/rendering/rendering_server_canvas.cpp
@@ -52,8 +52,9 @@ void RenderingServerCanvas::_render_canvas_item_tree(RID p_to_render_target, Can
RasterizerCanvas::Item *list_end = nullptr;
for (int i = 0; i < z_range; i++) {
- if (!z_list[i])
+ if (!z_list[i]) {
continue;
+ }
if (!list) {
list = z_list[i];
list_end = z_last_list[i];
@@ -82,8 +83,9 @@ void _collect_ysort_children(RenderingServerCanvas::Item *p_canvas_item, Transfo
r_index++;
- if (child_items[i]->sort_y)
+ if (child_items[i]->sort_y) {
_collect_ysort_children(child_items[i], p_transform * child_items[i]->xform, child_items[i]->use_parent_material ? p_material_owner : child_items[i], r_items, r_index);
+ }
}
}
}
@@ -98,8 +100,9 @@ void _mark_ysort_dirty(RenderingServerCanvas::Item *ysort_owner, RID_PtrOwner<Re
void RenderingServerCanvas::_cull_canvas_item(Item *p_canvas_item, const Transform2D &p_transform, const Rect2 &p_clip_rect, const Color &p_modulate, int p_z, RasterizerCanvas::Item **z_list, RasterizerCanvas::Item **z_last_list, Item *p_canvas_clip, Item *p_material_owner) {
Item *ci = p_canvas_item;
- if (!ci->visible)
+ if (!ci->visible) {
return;
+ }
if (ci->children_order_dirty) {
ci->child_items.sort_custom<ItemIndexSort>();
@@ -111,17 +114,18 @@ void RenderingServerCanvas::_cull_canvas_item(Item *p_canvas_item, const Transfo
Rect2 global_rect = xform.xform(rect);
global_rect.position += p_clip_rect.position;
- if (ci->use_parent_material && p_material_owner)
+ if (ci->use_parent_material && p_material_owner) {
ci->material_owner = p_material_owner;
- else {
+ } else {
p_material_owner = ci;
ci->material_owner = nullptr;
}
Color modulate(ci->modulate.r * p_modulate.r, ci->modulate.g * p_modulate.g, ci->modulate.b * p_modulate.b, ci->modulate.a * p_modulate.a);
- if (modulate.a < 0.007)
+ if (modulate.a < 0.007) {
return;
+ }
int child_item_count = ci->child_items.size();
Item **child_items = ci->child_items.ptrw();
@@ -154,14 +158,16 @@ void RenderingServerCanvas::_cull_canvas_item(Item *p_canvas_item, const Transfo
sorter.sort(child_items, child_item_count);
}
- if (ci->z_relative)
+ if (ci->z_relative) {
p_z = CLAMP(p_z + ci->z_index, RS::CANVAS_ITEM_Z_MIN, RS::CANVAS_ITEM_Z_MAX);
- else
+ } else {
p_z = ci->z_index;
+ }
for (int i = 0; i < child_item_count; i++) {
- if (!child_items[i]->behind || (ci->sort_y && child_items[i]->sort_y))
+ if (!child_items[i]->behind || (ci->sort_y && child_items[i]->sort_y)) {
continue;
+ }
if (ci->sort_y) {
_cull_canvas_item(child_items[i], xform * child_items[i]->ysort_xform, p_clip_rect, modulate, p_z, z_list, z_last_list, (Item *)ci->final_clip_owner, (Item *)child_items[i]->material_owner);
} else {
@@ -202,8 +208,9 @@ void RenderingServerCanvas::_cull_canvas_item(Item *p_canvas_item, const Transfo
}
for (int i = 0; i < child_item_count; i++) {
- if (child_items[i]->behind || (ci->sort_y && child_items[i]->sort_y))
+ if (child_items[i]->behind || (ci->sort_y && child_items[i]->sort_y)) {
continue;
+ }
if (ci->sort_y) {
_cull_canvas_item(child_items[i], xform * child_items[i]->ysort_xform, p_clip_rect, modulate, p_z, z_list, z_last_list, (Item *)ci->final_clip_owner, (Item *)child_items[i]->material_owner);
} else {
@@ -213,8 +220,9 @@ void RenderingServerCanvas::_cull_canvas_item(Item *p_canvas_item, const Transfo
}
void RenderingServerCanvas::_light_mask_canvas_items(int p_z, RasterizerCanvas::Item *p_canvas_item, RasterizerCanvas::Light *p_masked_lights) {
- if (!p_masked_lights)
+ if (!p_masked_lights) {
return;
+ }
RasterizerCanvas::Item *ci = p_canvas_item;
@@ -960,8 +968,9 @@ void RenderingServerCanvas::canvas_light_attach_to_canvas(RID p_light, RID p_can
canvas->lights.erase(clight);
}
- if (!canvas_owner.owns(p_canvas))
+ if (!canvas_owner.owns(p_canvas)) {
p_canvas = RID();
+ }
clight->canvas = p_canvas;
@@ -1085,8 +1094,9 @@ void RenderingServerCanvas::canvas_light_set_shadow_buffer_size(RID p_light, int
ERR_FAIL_COND(!clight);
int new_size = next_power_of_2(p_size);
- if (new_size == clight->shadow_buffer_size)
+ if (new_size == clight->shadow_buffer_size) {
return;
+ }
clight->shadow_buffer_size = next_power_of_2(p_size);
clight->version++;
@@ -1129,8 +1139,9 @@ void RenderingServerCanvas::canvas_light_occluder_attach_to_canvas(RID p_occlude
canvas->occluders.erase(occluder);
}
- if (!canvas_owner.owns(p_canvas))
+ if (!canvas_owner.owns(p_canvas)) {
p_canvas = RID();
+ }
occluder->canvas = p_canvas;
@@ -1234,10 +1245,11 @@ void RenderingServerCanvas::canvas_occluder_polygon_set_shape_as_lines(RID p_occ
{
const Vector2 *r = p_shape.ptr();
for (int i = 0; i < lc; i++) {
- if (i == 0)
+ if (i == 0) {
occluder_poly->aabb.position = r[i];
- else
+ } else {
occluder_poly->aabb.expand_to(r[i]);
+ }
}
}
@@ -1327,8 +1339,9 @@ bool RenderingServerCanvas::free(RID p_rid) {
if (canvas_light->canvas.is_valid()) {
Canvas *canvas = canvas_owner.getornull(canvas_light->canvas);
- if (canvas)
+ if (canvas) {
canvas->lights.erase(canvas_light);
+ }
}
RSG::canvas_render->free(canvas_light->light_internal);
diff --git a/servers/rendering/rendering_server_canvas.h b/servers/rendering/rendering_server_canvas.h
index e5eb6b024f..59c0d1fa52 100644
--- a/servers/rendering/rendering_server_canvas.h
+++ b/servers/rendering/rendering_server_canvas.h
@@ -82,8 +82,9 @@ public:
struct ItemPtrSort {
_FORCE_INLINE_ bool operator()(const Item *p_left, const Item *p_right) const {
- if (Math::is_equal_approx(p_left->ysort_pos.y, p_right->ysort_pos.y))
+ if (Math::is_equal_approx(p_left->ysort_pos.y, p_right->ysort_pos.y)) {
return p_left->ysort_pos.x < p_right->ysort_pos.x;
+ }
return p_left->ysort_pos.y < p_right->ysort_pos.y;
}
@@ -128,15 +129,17 @@ public:
int find_item(Item *p_item) {
for (int i = 0; i < child_items.size(); i++) {
- if (child_items[i].item == p_item)
+ if (child_items[i].item == p_item) {
return i;
+ }
}
return -1;
}
void erase_item(Item *p_item) {
int idx = find_item(p_item);
- if (idx >= 0)
+ if (idx >= 0) {
child_items.remove(idx);
+ }
}
Canvas() {
diff --git a/servers/rendering/rendering_server_raster.cpp b/servers/rendering/rendering_server_raster.cpp
index a301d81691..d30160702b 100644
--- a/servers/rendering/rendering_server_raster.cpp
+++ b/servers/rendering/rendering_server_raster.cpp
@@ -65,16 +65,21 @@ void RenderingServerRaster::_draw_margins() {
/* FREE */
void RenderingServerRaster::free(RID p_rid) {
- if (RSG::storage->free(p_rid))
+ if (RSG::storage->free(p_rid)) {
return;
- if (RSG::canvas->free(p_rid))
+ }
+ if (RSG::canvas->free(p_rid)) {
return;
- if (RSG::viewport->free(p_rid))
+ }
+ if (RSG::viewport->free(p_rid)) {
return;
- if (RSG::scene->free(p_rid))
+ }
+ if (RSG::scene->free(p_rid)) {
return;
- if (RSG::scene_render->free(p_rid))
+ }
+ if (RSG::scene_render->free(p_rid)) {
return;
+ }
}
/* EVENT QUEUING */
diff --git a/servers/rendering/rendering_server_scene.cpp b/servers/rendering/rendering_server_scene.cpp
index 06217b3f0e..7b8504036e 100644
--- a/servers/rendering/rendering_server_scene.cpp
+++ b/servers/rendering/rendering_server_scene.cpp
@@ -328,13 +328,16 @@ void RenderingServerScene::scenario_set_reflection_atlas_size(RID p_scenario, in
/* INSTANCING API */
void RenderingServerScene::_instance_queue_update(Instance *p_instance, bool p_update_aabb, bool p_update_dependencies) {
- if (p_update_aabb)
+ if (p_update_aabb) {
p_instance->update_aabb = true;
- if (p_update_dependencies)
+ }
+ if (p_update_dependencies) {
p_instance->update_dependencies = true;
+ }
- if (p_instance->update_item.in_list())
+ if (p_instance->update_item.in_list()) {
return;
+ }
_instance_update_list.add(&p_instance->update_item);
}
@@ -597,8 +600,9 @@ void RenderingServerScene::instance_set_transform(RID p_instance, const Transfor
Instance *instance = instance_owner.getornull(p_instance);
ERR_FAIL_COND(!instance);
- if (instance->transform == p_transform)
+ if (instance->transform == p_transform) {
return; //must be checked to avoid worst evil
+ }
#ifdef DEBUG_ENABLED
@@ -656,8 +660,9 @@ void RenderingServerScene::instance_set_visible(RID p_instance, bool p_visible)
Instance *instance = instance_owner.getornull(p_instance);
ERR_FAIL_COND(!instance);
- if (instance->visible == p_visible)
+ if (instance->visible == p_visible) {
return;
+ }
instance->visible = p_visible;
@@ -708,8 +713,9 @@ void RenderingServerScene::instance_set_custom_aabb(RID p_instance, AABB p_aabb)
if (p_aabb != AABB()) {
// Set custom AABB
- if (instance->custom_aabb == nullptr)
+ if (instance->custom_aabb == nullptr) {
instance->custom_aabb = memnew(AABB);
+ }
*instance->custom_aabb = p_aabb;
} else {
@@ -720,16 +726,18 @@ void RenderingServerScene::instance_set_custom_aabb(RID p_instance, AABB p_aabb)
}
}
- if (instance->scenario)
+ if (instance->scenario) {
_instance_queue_update(instance, true, false);
+ }
}
void RenderingServerScene::instance_attach_skeleton(RID p_instance, RID p_skeleton) {
Instance *instance = instance_owner.getornull(p_instance);
ERR_FAIL_COND(!instance);
- if (instance->skeleton == p_skeleton)
+ if (instance->skeleton == p_skeleton) {
return;
+ }
instance->skeleton = p_skeleton;
@@ -765,8 +773,9 @@ Vector<ObjectID> RenderingServerScene::instances_cull_aabb(const AABB &p_aabb, R
for (int i = 0; i < culled; i++) {
Instance *instance = cull[i];
ERR_CONTINUE(!instance);
- if (instance->object_id.is_null())
+ if (instance->object_id.is_null()) {
continue;
+ }
instances.push_back(instance->object_id);
}
@@ -787,8 +796,9 @@ Vector<ObjectID> RenderingServerScene::instances_cull_ray(const Vector3 &p_from,
for (int i = 0; i < culled; i++) {
Instance *instance = cull[i];
ERR_CONTINUE(!instance);
- if (instance->object_id.is_null())
+ if (instance->object_id.is_null()) {
continue;
+ }
instances.push_back(instance->object_id);
}
@@ -810,8 +820,9 @@ Vector<ObjectID> RenderingServerScene::instances_cull_convex(const Vector<Plane>
for (int i = 0; i < culled; i++) {
Instance *instance = cull[i];
ERR_CONTINUE(!instance);
- if (instance->object_id.is_null())
+ if (instance->object_id.is_null()) {
continue;
+ }
instances.push_back(instance->object_id);
}
@@ -1079,32 +1090,36 @@ void RenderingServerScene::_update_instance_aabb(Instance *p_instance) {
// do nothing
} break;
case RenderingServer::INSTANCE_MESH: {
- if (p_instance->custom_aabb)
+ if (p_instance->custom_aabb) {
new_aabb = *p_instance->custom_aabb;
- else
+ } else {
new_aabb = RSG::storage->mesh_get_aabb(p_instance->base, p_instance->skeleton);
+ }
} break;
case RenderingServer::INSTANCE_MULTIMESH: {
- if (p_instance->custom_aabb)
+ if (p_instance->custom_aabb) {
new_aabb = *p_instance->custom_aabb;
- else
+ } else {
new_aabb = RSG::storage->multimesh_get_aabb(p_instance->base);
+ }
} break;
case RenderingServer::INSTANCE_IMMEDIATE: {
- if (p_instance->custom_aabb)
+ if (p_instance->custom_aabb) {
new_aabb = *p_instance->custom_aabb;
- else
+ } else {
new_aabb = RSG::storage->immediate_get_aabb(p_instance->base);
+ }
} break;
case RenderingServer::INSTANCE_PARTICLES: {
- if (p_instance->custom_aabb)
+ if (p_instance->custom_aabb) {
new_aabb = *p_instance->custom_aabb;
- else
+ } else {
new_aabb = RSG::storage->particles_get_aabb(p_instance->base);
+ }
} break;
case RenderingServer::INSTANCE_LIGHT: {
@@ -1132,8 +1147,9 @@ void RenderingServerScene::_update_instance_aabb(Instance *p_instance) {
}
// <Zylann> This is why I didn't re-use Instance::aabb to implement custom AABBs
- if (p_instance->extra_margin)
+ if (p_instance->extra_margin) {
new_aabb.grow_by(p_instance->extra_margin);
+ }
p_instance->aabb = new_aabb;
}
@@ -1364,20 +1380,26 @@ bool RenderingServerScene::_light_instance_update_shadow(Instance *p_instance, c
real_t d_y = y_vec.dot(endpoints[j]);
real_t d_z = z_vec.dot(endpoints[j]);
- if (j == 0 || d_x < x_min)
+ if (j == 0 || d_x < x_min) {
x_min = d_x;
- if (j == 0 || d_x > x_max)
+ }
+ if (j == 0 || d_x > x_max) {
x_max = d_x;
+ }
- if (j == 0 || d_y < y_min)
+ if (j == 0 || d_y < y_min) {
y_min = d_y;
- if (j == 0 || d_y > y_max)
+ }
+ if (j == 0 || d_y > y_max) {
y_max = d_y;
+ }
- if (j == 0 || d_z < z_min)
+ if (j == 0 || d_z < z_min) {
z_min = d_z;
- if (j == 0 || d_z > z_max)
+ }
+ if (j == 0 || d_z > z_max) {
z_max = d_z;
+ }
}
real_t radius = 0;
@@ -1396,8 +1418,9 @@ bool RenderingServerScene::_light_instance_update_shadow(Instance *p_instance, c
for (int j = 0; j < 8; j++) {
real_t d = center.distance_to(endpoints[j]);
- if (d > radius)
+ if (d > radius) {
radius = d;
+ }
}
radius *= texture_size / (texture_size - 2.0); //add a texel by each side
@@ -1524,8 +1547,9 @@ bool RenderingServerScene::_light_instance_update_shadow(Instance *p_instance, c
real_t d_z = z_vec.dot(endpoints_square[j]);
- if (j == 0 || d_z > z_max_square)
+ if (j == 0 || d_z > z_max_square) {
z_max_square = d_z;
+ }
}
if (cull_max > z_max_square) {
@@ -1538,8 +1562,9 @@ bool RenderingServerScene::_light_instance_update_shadow(Instance *p_instance, c
for (int j = 0; j < 8; j++) {
real_t d = center_square.distance_to(endpoints_square[j]);
- if (d > radius_square)
+ if (d > radius_square) {
radius_square = d;
+ }
}
radius_square *= texture_size / (texture_size - 2.0); //add a texel by each side
@@ -2073,8 +2098,9 @@ void RenderingServerScene::_prepare_scene(const Transform p_cam_transform, const
break;
}
- if (!E->get()->visible)
+ if (!E->get()->visible) {
continue;
+ }
InstanceLightData *light = static_cast<InstanceLightData *>(E->get()->base_data);
@@ -2107,8 +2133,9 @@ void RenderingServerScene::_prepare_scene(const Transform p_cam_transform, const
for (int i = 0; i < light_cull_count; i++) {
Instance *ins = light_cull_result[i];
- if (!p_shadow_atlas.is_valid() || !RSG::storage->light_has_shadow(ins->base))
+ if (!p_shadow_atlas.is_valid() || !RSG::storage->light_has_shadow(ins->base)) {
continue;
+ }
InstanceLightData *light = static_cast<InstanceLightData *>(ins->base_data);
@@ -2205,12 +2232,13 @@ void RenderingServerScene::_render_scene(RID p_render_buffers, const Transform p
/* ENVIRONMENT */
RID environment;
- if (p_force_environment.is_valid()) //camera has more environment priority
+ if (p_force_environment.is_valid()) { //camera has more environment priority
environment = p_force_environment;
- else if (scenario->environment.is_valid())
+ } else if (scenario->environment.is_valid()) {
environment = scenario->environment;
- else
+ } else {
environment = scenario->fallback_environment;
+ }
RID camera_effects;
if (p_force_camera_effects.is_valid()) {
@@ -2230,10 +2258,11 @@ void RenderingServerScene::render_empty_scene(RID p_render_buffers, RID p_scenar
Scenario *scenario = scenario_owner.getornull(p_scenario);
RID environment;
- if (scenario->environment.is_valid())
+ if (scenario->environment.is_valid()) {
environment = scenario->environment;
- else
+ } else {
environment = scenario->fallback_environment;
+ }
RENDER_TIMESTAMP("Render Empty Scene ");
RSG::scene_render->render_scene(p_render_buffers, Transform(), CameraMatrix(), true, nullptr, 0, nullptr, 0, nullptr, 0, nullptr, 0, nullptr, 0, nullptr, 0, environment, RID(), p_shadow_atlas, scenario->reflection_atlas, RID(), 0);
#endif
@@ -2321,8 +2350,9 @@ void RenderingServerScene::render_probes() {
switch (RSG::storage->reflection_probe_get_update_mode(base)) {
case RS::REFLECTION_PROBE_UPDATE_ONCE: {
- if (busy) //already rendering something
+ if (busy) { //already rendering something
break;
+ }
bool done = _render_reflection_probe_step(ref_probe->self()->owner, ref_probe->self()->render_step);
if (done) {
@@ -2707,8 +2737,9 @@ void RenderingServerScene::_update_dirty_instance(Instance *p_instance) {
for (int i = 0; i < dp; i++) {
RID mesh = RSG::storage->particles_get_draw_pass_mesh(p_instance->base, i);
- if (!mesh.is_valid())
+ if (!mesh.is_valid()) {
continue;
+ }
int sc = RSG::storage->mesh_get_surface_count(mesh);
for (int j = 0; j < sc; j++) {
diff --git a/servers/rendering/rendering_server_scene.h b/servers/rendering/rendering_server_scene.h
index d036979587..f59028603f 100644
--- a/servers/rendering/rendering_server_scene.h
+++ b/servers/rendering/rendering_server_scene.h
@@ -217,10 +217,12 @@ public:
}
~Instance() {
- if (base_data)
+ if (base_data) {
memdelete(base_data);
- if (custom_aabb)
+ }
+ if (custom_aabb) {
memdelete(custom_aabb);
+ }
}
};
diff --git a/servers/rendering/rendering_server_viewport.cpp b/servers/rendering/rendering_server_viewport.cpp
index 4491f699dc..48be6ca13b 100644
--- a/servers/rendering/rendering_server_viewport.cpp
+++ b/servers/rendering/rendering_server_viewport.cpp
@@ -205,8 +205,9 @@ void RenderingServerViewport::_draw_viewport(Viewport *p_viewport, XRInterface::
Transform2D xf = _canvas_get_transform(p_viewport, canvas, &E->get(), clip_rect.size);
for (Set<RasterizerCanvas::LightOccluderInstance *>::Element *F = canvas->occluders.front(); F; F = F->next()) {
- if (!F->get()->enabled)
+ if (!F->get()->enabled) {
continue;
+ }
F->get()->xform_cache = xf * F->get()->xform;
if (shadow_rect.intersects_transformed(F->get()->xform_cache, F->get()->aabb_cache)) {
F->get()->next = occluders;
@@ -321,8 +322,9 @@ void RenderingServerViewport::draw_viewports() {
Viewport *vp = active_viewports[i];
- if (vp->update_mode == RS::VIEWPORT_UPDATE_DISABLED)
+ if (vp->update_mode == RS::VIEWPORT_UPDATE_DISABLED) {
continue;
+ }
if (!vp->render_target.is_valid()) {
continue;
@@ -550,8 +552,9 @@ void RenderingServerViewport::viewport_set_render_direct_to_screen(RID p_viewpor
Viewport *viewport = viewport_owner.getornull(p_viewport);
ERR_FAIL_COND(!viewport);
- if (p_enable == viewport->viewport_render_direct_to_screen)
+ if (p_enable == viewport->viewport_render_direct_to_screen) {
return;
+ }
// if disabled, reset render_target size and position
if (!p_enable) {
@@ -722,8 +725,9 @@ int RenderingServerViewport::viewport_get_render_info(RID p_viewport, RS::Viewpo
ERR_FAIL_INDEX_V(p_info, RS::VIEWPORT_RENDER_INFO_MAX, -1);
Viewport *viewport = viewport_owner.getornull(p_viewport);
- if (!viewport)
+ if (!viewport) {
return 0; //there should be a lock here..
+ }
return viewport->render_info[p_info];
}
diff --git a/servers/rendering/rendering_server_viewport.h b/servers/rendering/rendering_server_viewport.h
index 6950db6127..0b90646e4f 100644
--- a/servers/rendering/rendering_server_viewport.h
+++ b/servers/rendering/rendering_server_viewport.h
@@ -91,8 +91,9 @@ public:
int64_t stacking;
RID canvas;
bool operator<(const CanvasKey &p_canvas) const {
- if (stacking == p_canvas.stacking)
+ if (stacking == p_canvas.stacking) {
return canvas < p_canvas.canvas;
+ }
return stacking < p_canvas.stacking;
}
CanvasKey() {
diff --git a/servers/rendering/shader_language.cpp b/servers/rendering/shader_language.cpp
index 5db9e44084..2ec65b7ea8 100644
--- a/servers/rendering/shader_language.cpp
+++ b/servers/rendering/shader_language.cpp
@@ -549,31 +549,38 @@ ShaderLanguage::Token ShaderLanguage::_get_token() {
while (true) {
if (GETCHAR(i) == '.') {
- if (period_found || exponent_found || hexa_found || float_suffix_found)
+ if (period_found || exponent_found || hexa_found || float_suffix_found) {
return _make_token(TK_ERROR, "Invalid numeric constant");
+ }
period_found = true;
} else if (GETCHAR(i) == 'x') {
- if (hexa_found || str.length() != 1 || str[0] != '0')
+ if (hexa_found || str.length() != 1 || str[0] != '0') {
return _make_token(TK_ERROR, "Invalid numeric constant");
+ }
hexa_found = true;
} else if (GETCHAR(i) == 'e') {
- if (hexa_found || exponent_found || float_suffix_found)
+ if (hexa_found || exponent_found || float_suffix_found) {
return _make_token(TK_ERROR, "Invalid numeric constant");
+ }
exponent_found = true;
} else if (GETCHAR(i) == 'f') {
- if (hexa_found || exponent_found)
+ if (hexa_found || exponent_found) {
return _make_token(TK_ERROR, "Invalid numeric constant");
+ }
float_suffix_found = true;
} else if (_is_number(GETCHAR(i))) {
- if (float_suffix_found)
+ if (float_suffix_found) {
return _make_token(TK_ERROR, "Invalid numeric constant");
+ }
} else if (hexa_found && _is_hex(GETCHAR(i))) {
} else if ((GETCHAR(i) == '-' || GETCHAR(i) == '+') && exponent_found) {
- if (sign_found)
+ if (sign_found) {
return _make_token(TK_ERROR, "Invalid numeric constant");
+ }
sign_found = true;
- } else
+ } else {
break;
+ }
str += CharType(GETCHAR(i));
i++;
@@ -629,10 +636,11 @@ ShaderLanguage::Token ShaderLanguage::_get_token() {
char_idx += str.length();
Token tk;
- if (period_found || exponent_found || float_suffix_found)
+ if (period_found || exponent_found || float_suffix_found) {
tk.type = TK_REAL_CONSTANT;
- else
+ } else {
tk.type = TK_INT_CONSTANT;
+ }
if (hexa_found) {
tk.constant = (double)str.hex_to_int64(true);
@@ -675,10 +683,11 @@ ShaderLanguage::Token ShaderLanguage::_get_token() {
return _make_token(TK_IDENTIFIER, str);
}
- if (GETCHAR(0) > 32)
+ if (GETCHAR(0) > 32) {
return _make_token(TK_ERROR, "Tokenizer: Unknown character #" + itos(GETCHAR(0)) + ": '" + String::chr(GETCHAR(0)) + "'");
- else
+ } else {
return _make_token(TK_ERROR, "Tokenizer: Unknown character #" + itos(GETCHAR(0)));
+ }
} break;
}
@@ -775,10 +784,11 @@ bool ShaderLanguage::is_token_interpolation(TokenType p_type) {
}
ShaderLanguage::DataInterpolation ShaderLanguage::get_token_interpolation(TokenType p_type) {
- if (p_type == TK_INTERPOLATION_FLAT)
+ if (p_type == TK_INTERPOLATION_FLAT) {
return INTERPOLATION_FLAT;
- else
+ } else {
return INTERPOLATION_SMOOTH;
+ }
}
bool ShaderLanguage::is_token_precision(TokenType p_type) {
@@ -789,12 +799,13 @@ bool ShaderLanguage::is_token_precision(TokenType p_type) {
}
ShaderLanguage::DataPrecision ShaderLanguage::get_token_precision(TokenType p_type) {
- if (p_type == TK_PRECISION_LOW)
+ if (p_type == TK_PRECISION_LOW) {
return PRECISION_LOWP;
- else if (p_type == TK_PRECISION_HIGH)
+ } else if (p_type == TK_PRECISION_HIGH) {
return PRECISION_HIGHP;
- else
+ } else {
return PRECISION_MEDIUMP;
+ }
}
String ShaderLanguage::get_precision_name(DataPrecision p_type) {
@@ -1013,8 +1024,9 @@ bool ShaderLanguage::_find_identifier(const BlockNode *p_block, bool p_allow_rea
}
for (int i = 0; i < shader->functions.size(); i++) {
- if (!shader->functions[i].callable)
+ if (!shader->functions[i].callable) {
continue;
+ }
if (shader->functions[i].name == p_identifier) {
if (r_data_type) {
@@ -1400,8 +1412,9 @@ bool ShaderLanguage::_validate_operator(OperatorNode *p_op, DataType *r_ret_type
}
}
- if (r_ret_type)
+ if (r_ret_type) {
*r_ret_type = ret_type;
+ }
return valid;
}
@@ -2179,8 +2192,9 @@ bool ShaderLanguage::_validate_function_call(BlockNode *p_block, const Map<Strin
}
}
- if (!fail && argcount < 4 && builtin_func_defs[idx].args[argcount] != TYPE_VOID)
+ if (!fail && argcount < 4 && builtin_func_defs[idx].args[argcount] != TYPE_VOID) {
fail = true; //make sure the number of arguments matches
+ }
if (!fail) {
//make sure its not an out argument used in the wrong way
@@ -2293,8 +2307,9 @@ bool ShaderLanguage::_validate_function_call(BlockNode *p_block, const Map<Strin
p_func->arguments.write[i + 1] = conversion;
}
- if (r_ret_type)
+ if (r_ret_type) {
*r_ret_type = builtin_func_defs[idx].rettype;
+ }
return true;
}
@@ -2321,8 +2336,9 @@ bool ShaderLanguage::_validate_function_call(BlockNode *p_block, const Map<Strin
if (failed_builtin) {
String err = "Invalid arguments for built-in function: " + String(name) + "(";
for (int i = 0; i < argcount; i++) {
- if (i > 0)
+ if (i > 0) {
err += ",";
+ }
if (p_func->arguments[i + 1]->type == Node::TYPE_CONSTANT && p_func->arguments[i + 1]->get_datatype() == TYPE_INT && static_cast<ConstantNode *>(p_func->arguments[i + 1])->values[0].sint < 0) {
err += "-";
@@ -2352,8 +2368,9 @@ bool ShaderLanguage::_validate_function_call(BlockNode *p_block, const Map<Strin
}
for (int i = 0; i < shader->functions.size(); i++) {
- if (name != shader->functions[i].name)
+ if (name != shader->functions[i].name) {
continue;
+ }
if (!shader->functions[i].callable) {
_set_error("Function '" + String(name) + " can't be called from source code.");
@@ -2362,8 +2379,9 @@ bool ShaderLanguage::_validate_function_call(BlockNode *p_block, const Map<Strin
FunctionNode *pfunc = shader->functions[i].function;
- if (pfunc->arguments.size() != args.size())
+ if (pfunc->arguments.size() != args.size()) {
continue;
+ }
bool fail = false;
@@ -2541,8 +2559,9 @@ bool ShaderLanguage::convert_constant(ConstantNode *p_constant, DataType p_to_ty
p_value->sint = p_constant->values[0].uint;
}
return true;
- } else
+ } else {
return false;
+ }
}
bool ShaderLanguage::is_scalar_type(DataType p_type) {
@@ -2997,8 +3016,9 @@ bool ShaderLanguage::_validate_assign(Node *p_node, const Map<StringName, BuiltI
return _validate_assign(op->arguments[1], p_builtin_types, r_message);
} else if (op->op == OP_CALL) {
- if (r_message)
+ if (r_message) {
*r_message = RTR("Assignment to function.");
+ }
return false;
}
@@ -3006,8 +3026,9 @@ bool ShaderLanguage::_validate_assign(Node *p_node, const Map<StringName, BuiltI
MemberNode *member = static_cast<MemberNode *>(p_node);
if (member->has_swizzling_duplicates) {
- if (r_message)
+ if (r_message) {
*r_message = RTR("Swizzling assignment contains duplicates.");
+ }
return false;
}
@@ -3017,20 +3038,23 @@ bool ShaderLanguage::_validate_assign(Node *p_node, const Map<StringName, BuiltI
VariableNode *var = static_cast<VariableNode *>(p_node);
if (shader->uniforms.has(var->name)) {
- if (r_message)
+ if (r_message) {
*r_message = RTR("Assignment to uniform.");
+ }
return false;
}
if (shader->varyings.has(var->name) && current_function != String("vertex")) {
- if (r_message)
+ if (r_message) {
*r_message = RTR("Varyings can only be assigned in vertex function.");
+ }
return false;
}
if (shader->constants.has(var->name) || var->is_const) {
- if (r_message)
+ if (r_message) {
*r_message = RTR("Constants cannot be modified.");
+ }
return false;
}
@@ -3041,22 +3065,25 @@ bool ShaderLanguage::_validate_assign(Node *p_node, const Map<StringName, BuiltI
ArrayNode *arr = static_cast<ArrayNode *>(p_node);
if (arr->is_const) {
- if (r_message)
+ if (r_message) {
*r_message = RTR("Constants cannot be modified.");
+ }
return false;
}
if (shader->varyings.has(arr->name) && current_function != String("vertex")) {
- if (r_message)
+ if (r_message) {
*r_message = RTR("Varyings can only be assigned in vertex function.");
+ }
return false;
}
return true;
}
- if (r_message)
+ if (r_message) {
*r_message = "Assignment to constant expression.";
+ }
return false;
}
@@ -3145,8 +3172,9 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons
//handle subexpression
expr = _parse_and_reduce_expression(p_block, p_builtin_types);
- if (!expr)
+ if (!expr) {
return nullptr;
+ }
tk = _get_token();
@@ -3226,8 +3254,9 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons
completion_argument = carg;
}
- if (!ok)
+ if (!ok) {
return nullptr;
+ }
if (!_validate_function_call(p_block, p_builtin_types, func, &func->return_cache, &func->struct_name)) {
_set_error("No matching constructor found for: '" + String(funcname->name) + "'");
@@ -3387,10 +3416,11 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons
an->initializer.push_back(n);
break;
} else {
- if (auto_size)
+ if (auto_size) {
_set_error("Expected '}' or ','");
- else
+ } else {
_set_error("Expected ')' or ','");
+ }
return nullptr;
}
}
@@ -3485,8 +3515,9 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons
completion_argument = carg;
}
- if (!ok)
+ if (!ok) {
return nullptr;
+ }
if (!_validate_function_call(p_block, p_builtin_types, func, &func->return_cache, &func->struct_name)) {
_set_error("No matching function found for: '" + String(funcname->name) + "'");
@@ -3653,14 +3684,16 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons
p_block->block_tag = SubClassTag::TAG_ARRAY;
call_expression = _parse_and_reduce_expression(p_block, p_builtin_types);
p_block->block_tag = SubClassTag::TAG_GLOBAL;
- if (!call_expression)
+ if (!call_expression) {
return nullptr;
+ }
data_type = call_expression->get_datatype();
} else { // indexing
index_expression = _parse_and_reduce_expression(p_block, p_builtin_types);
- if (!index_expression)
+ if (!index_expression) {
return nullptr;
+ }
if (index_expression->get_datatype() != TYPE_INT && index_expression->get_datatype() != TYPE_UINT) {
_set_error("Only integer expressions are allowed for indexing");
@@ -4038,8 +4071,9 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons
return nullptr;
} else if (tk.type == TK_BRACKET_OPEN) {
Node *index_expression = _parse_and_reduce_expression(p_block, p_builtin_types);
- if (!index_expression)
+ if (!index_expression) {
return nullptr;
+ }
if (index_expression->get_datatype() != TYPE_INT && index_expression->get_datatype() != TYPE_UINT) {
_set_error("Only integer expressions are allowed for indexing");
@@ -4086,8 +4120,9 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons
*/
} else if (tk.type == TK_BRACKET_OPEN) {
Node *index = _parse_and_reduce_expression(p_block, p_builtin_types);
- if (!index)
+ if (!index) {
return nullptr;
+ }
if (index->get_datatype() != TYPE_INT && index->get_datatype() != TYPE_UINT) {
_set_error("Only integer datatypes are allowed for indexing");
@@ -4536,8 +4571,9 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons
if (!_validate_operator(op, &op->return_cache)) {
String at;
for (int j = 0; j < op->arguments.size(); j++) {
- if (j > 0)
+ if (j > 0) {
at += " and ";
+ }
at += get_datatype_name(op->arguments[j]->get_datatype());
}
_set_error("Invalid arguments to unary operator '" + get_operator_text(op->op) + "' :" + at);
@@ -4568,8 +4604,9 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons
if (!_validate_operator(op, &op->return_cache)) {
String at;
for (int i = 0; i < op->arguments.size(); i++) {
- if (i > 0)
+ if (i > 0) {
at += " and ";
+ }
at += get_datatype_name(op->arguments[i]->get_datatype());
}
_set_error("Invalid argument to ternary ?: operator: " + at);
@@ -4620,8 +4657,9 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons
if (!_validate_operator(op, &op->return_cache)) {
String at;
for (int i = 0; i < op->arguments.size(); i++) {
- if (i > 0)
+ if (i > 0) {
at += " and ";
+ }
if (op->arguments[i]->get_datatype() == TYPE_STRUCT) {
at += op->arguments[i]->get_datatype_name();
} else {
@@ -4641,8 +4679,9 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons
}
ShaderLanguage::Node *ShaderLanguage::_reduce_expression(BlockNode *p_block, ShaderLanguage::Node *p_node) {
- if (p_node->type != Node::TYPE_OPERATOR)
+ if (p_node->type != Node::TYPE_OPERATOR) {
return p_node;
+ }
//for now only reduce simple constructors
OperatorNode *op = static_cast<OperatorNode *>(p_node);
@@ -4750,8 +4789,9 @@ ShaderLanguage::Node *ShaderLanguage::_reduce_expression(BlockNode *p_block, Sha
ShaderLanguage::Node *ShaderLanguage::_parse_and_reduce_expression(BlockNode *p_block, const Map<StringName, BuiltInInfo> &p_builtin_types) {
ShaderLanguage::Node *expr = _parse_expression(p_block, p_builtin_types);
- if (!expr) //errored
+ if (!expr) { //errored
return nullptr;
+ }
expr = _reduce_expression(p_block, expr);
@@ -5068,10 +5108,11 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const Map<StringName, Bui
decl.initializer.push_back(n);
break;
} else {
- if (curly)
+ if (curly) {
_set_error("Expected '}' or ','");
- else
+ } else {
_set_error("Expected ')' or ','");
+ }
return ERR_PARSE_ERROR;
}
}
@@ -5114,8 +5155,9 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const Map<StringName, Bui
//variable created with assignment! must parse an expression
Node *n = _parse_and_reduce_expression(p_block, p_builtin_types);
- if (!n)
+ if (!n) {
return ERR_PARSE_ERROR;
+ }
if (node->is_const && n->type == Node::TYPE_OPERATOR && ((OperatorNode *)n)->op == OP_CALL) {
_set_error("Expected constant expression after '='");
return ERR_PARSE_ERROR;
@@ -5187,8 +5229,9 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const Map<StringName, Bui
ControlFlowNode *cf = alloc_node<ControlFlowNode>();
cf->flow_op = FLOW_OP_IF;
Node *n = _parse_and_reduce_expression(p_block, p_builtin_types);
- if (!n)
+ if (!n) {
return ERR_PARSE_ERROR;
+ }
if (n->get_datatype() != TYPE_BOOL) {
_set_error("Expected boolean expression");
@@ -5208,8 +5251,9 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const Map<StringName, Bui
p_block->statements.push_back(cf);
Error err = _parse_block(block, p_builtin_types, true, p_can_break, p_can_continue);
- if (err)
+ if (err) {
return err;
+ }
pos = _get_tkpos();
tk = _get_token();
@@ -5237,8 +5281,9 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const Map<StringName, Bui
ControlFlowNode *cf = alloc_node<ControlFlowNode>();
cf->flow_op = FLOW_OP_SWITCH;
Node *n = _parse_and_reduce_expression(p_block, p_builtin_types);
- if (!n)
+ if (!n) {
return ERR_PARSE_ERROR;
+ }
if (n->get_datatype() != TYPE_INT) {
_set_error("Expected integer expression");
return ERR_PARSE_ERROR;
@@ -5365,8 +5410,9 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const Map<StringName, Bui
p_block->statements.push_back(cf);
Error err = _parse_block(case_block, p_builtin_types, false, true, false);
- if (err)
+ if (err) {
return err;
+ }
return OK;
@@ -5398,8 +5444,9 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const Map<StringName, Bui
p_block->statements.push_back(cf);
Error err = _parse_block(default_block, p_builtin_types, false, true, false);
- if (err)
+ if (err) {
return err;
+ }
return OK;
@@ -5414,8 +5461,9 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const Map<StringName, Bui
do_block->parent_block = p_block;
Error err = _parse_block(do_block, p_builtin_types, true, true, true);
- if (err)
+ if (err) {
return err;
+ }
tk = _get_token();
if (tk.type != TK_CF_WHILE) {
@@ -5437,8 +5485,9 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const Map<StringName, Bui
cf->flow_op = FLOW_OP_WHILE;
}
Node *n = _parse_and_reduce_expression(p_block, p_builtin_types);
- if (!n)
+ if (!n) {
return ERR_PARSE_ERROR;
+ }
tk = _get_token();
if (tk.type != TK_PARENTHESIS_CLOSE) {
@@ -5453,8 +5502,9 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const Map<StringName, Bui
p_block->statements.push_back(cf);
Error err = _parse_block(block, p_builtin_types, true, true, true);
- if (err)
+ if (err) {
return err;
+ }
} else {
cf->expressions.push_back(n);
cf->blocks.push_back(do_block);
@@ -5487,8 +5537,9 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const Map<StringName, Bui
}
Node *n = _parse_and_reduce_expression(init_block, p_builtin_types);
- if (!n)
+ if (!n) {
return ERR_PARSE_ERROR;
+ }
if (n->get_datatype() != TYPE_BOOL) {
_set_error("Middle expression is expected to be boolean.");
@@ -5504,8 +5555,9 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const Map<StringName, Bui
cf->expressions.push_back(n);
n = _parse_and_reduce_expression(init_block, p_builtin_types);
- if (!n)
+ if (!n) {
return ERR_PARSE_ERROR;
+ }
cf->expressions.push_back(n);
@@ -5521,8 +5573,9 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const Map<StringName, Bui
p_block->statements.push_back(cf);
Error err = _parse_block(block, p_builtin_types, true, true, true);
- if (err)
+ if (err) {
return err;
+ }
} else if (tk.type == TK_CF_RETURN) {
//check return type
@@ -5550,8 +5603,9 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const Map<StringName, Bui
} else {
_set_tkpos(pos); //rollback, wants expression
Node *expr = _parse_and_reduce_expression(p_block, p_builtin_types);
- if (!expr)
+ if (!expr) {
return ERR_PARSE_ERROR;
+ }
if (b->parent_function->return_type != expr->get_datatype()) {
_set_error("Expected return expression of type '" + get_datatype_name(b->parent_function->return_type) + "'");
@@ -5651,8 +5705,9 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const Map<StringName, Bui
//nothing else, so expression
_set_tkpos(pos); //rollback
Node *expr = _parse_and_reduce_expression(p_block, p_builtin_types);
- if (!expr)
+ if (!expr) {
return ERR_PARSE_ERROR;
+ }
p_block->statements.push_back(expr);
tk = _get_token();
@@ -5662,8 +5717,9 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const Map<StringName, Bui
}
}
- if (p_just_one)
+ if (p_just_one) {
break;
+ }
}
return OK;
@@ -6239,8 +6295,9 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct
if (tk.type == TK_OP_ASSIGN) {
Node *expr = _parse_and_reduce_expression(nullptr, Map<StringName, BuiltInInfo>());
- if (!expr)
+ if (!expr) {
return ERR_PARSE_ERROR;
+ }
if (expr->type != Node::TYPE_CONSTANT) {
_set_error("Expected constant expression after '='");
return ERR_PARSE_ERROR;
@@ -6397,8 +6454,9 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct
//variable created with assignment! must parse an expression
Node *expr = _parse_and_reduce_expression(nullptr, Map<StringName, BuiltInInfo>());
- if (!expr)
+ if (!expr) {
return ERR_PARSE_ERROR;
+ }
if (expr->type == Node::TYPE_OPERATOR && ((OperatorNode *)expr)->op == OP_CALL) {
_set_error("Expected constant expression after '='");
return ERR_PARSE_ERROR;
@@ -6633,8 +6691,9 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct
current_function = name;
Error err = _parse_block(func_node->body, builtin_types);
- if (err)
+ if (err) {
return err;
+ }
if (func_node->return_type != DataType::TYPE_VOID) {
BlockNode *block = func_node->body;
@@ -6730,8 +6789,9 @@ static int _get_first_ident_pos(const String &p_code) {
if (GETCHAR(0) == '/' && GETCHAR(1) == '/') {
idx += 2;
while (true) {
- if (GETCHAR(0) == 0)
+ if (GETCHAR(0) == 0) {
return 0;
+ }
if (GETCHAR(0) == '\n') {
idx++;
break; // loop
@@ -6741,8 +6801,9 @@ static int _get_first_ident_pos(const String &p_code) {
} else if (GETCHAR(0) == '/' && GETCHAR(1) == '*') {
idx += 2;
while (true) {
- if (GETCHAR(0) == 0)
+ if (GETCHAR(0) == 0) {
return 0;
+ }
if (GETCHAR(0) == '*' && GETCHAR(1) == '/') {
idx += 2;
break; // loop
@@ -6793,8 +6854,9 @@ String ShaderLanguage::get_shader_type(const String &p_code) {
}
}
- if (reading_type)
+ if (reading_type) {
return cur_identifier;
+ }
return String();
}
@@ -6917,8 +6979,9 @@ Error ShaderLanguage::complete(const String &p_code, const Map<StringName, Funct
}
for (int i = 0; i < shader->functions.size(); i++) {
- if (!shader->functions[i].callable || shader->functions[i].name == skip_function)
+ if (!shader->functions[i].callable || shader->functions[i].name == skip_function) {
continue;
+ }
matches.insert(String(shader->functions[i].name), ScriptCodeCompletionOption::KIND_FUNCTION);
}
@@ -6962,8 +7025,9 @@ Error ShaderLanguage::complete(const String &p_code, const Map<StringName, Funct
} break;
case COMPLETION_CALL_ARGUMENTS: {
for (int i = 0; i < shader->functions.size(); i++) {
- if (!shader->functions[i].callable)
+ if (!shader->functions[i].callable) {
continue;
+ }
if (shader->functions[i].name == completion_function) {
String calltip;
@@ -6973,10 +7037,11 @@ Error ShaderLanguage::complete(const String &p_code, const Map<StringName, Funct
calltip += "(";
for (int j = 0; j < shader->functions[i].function->arguments.size(); j++) {
- if (j > 0)
+ if (j > 0) {
calltip += ", ";
- else
+ } else {
calltip += " ";
+ }
if (j == completion_argument) {
calltip += CharType(0xFFFF);
@@ -6999,8 +7064,9 @@ Error ShaderLanguage::complete(const String &p_code, const Map<StringName, Funct
}
}
- if (shader->functions[i].function->arguments.size())
+ if (shader->functions[i].function->arguments.size()) {
calltip += " ";
+ }
calltip += ")";
r_call_hint = calltip;
@@ -7035,8 +7101,9 @@ Error ShaderLanguage::complete(const String &p_code, const Map<StringName, Funct
continue;
}
- if (calltip.length())
+ if (calltip.length()) {
calltip += "\n";
+ }
calltip += get_datatype_name(builtin_func_defs[idx].rettype);
calltip += " ";
@@ -7045,13 +7112,15 @@ Error ShaderLanguage::complete(const String &p_code, const Map<StringName, Funct
bool found_arg = false;
for (int i = 0; i < 4; i++) {
- if (builtin_func_defs[idx].args[i] == TYPE_VOID)
+ if (builtin_func_defs[idx].args[i] == TYPE_VOID) {
break;
+ }
- if (i > 0)
+ if (i > 0) {
calltip += ", ";
- else
+ } else {
calltip += " ";
+ }
if (i == completion_argument) {
calltip += CharType(0xFFFF);
@@ -7070,8 +7139,9 @@ Error ShaderLanguage::complete(const String &p_code, const Map<StringName, Funct
found_arg = true;
}
- if (found_arg)
+ if (found_arg) {
calltip += " ";
+ }
calltip += ")";
}
idx++;
diff --git a/servers/rendering/shader_language.h b/servers/rendering/shader_language.h
index 253261910b..020a5e3e6f 100644
--- a/servers/rendering/shader_language.h
+++ b/servers/rendering/shader_language.h
@@ -770,8 +770,9 @@ private:
}
void _set_error(const String &p_str) {
- if (error_set)
+ if (error_set) {
return;
+ }
error_line = tk_line;
error_set = true;
diff --git a/servers/rendering_server.cpp b/servers/rendering_server.cpp
index d5bc1cb4ef..906946f074 100644
--- a/servers/rendering_server.cpp
+++ b/servers/rendering_server.cpp
@@ -43,8 +43,9 @@ RenderingServer *RenderingServer::get_singleton() {
RenderingServer *RenderingServer::create() {
ERR_FAIL_COND_V(singleton, nullptr);
- if (create_func)
+ if (create_func) {
return create_func();
+ }
return nullptr;
}
@@ -148,12 +149,15 @@ RID RenderingServer::get_test_texture() {
}
void RenderingServer::_free_internal_rids() {
- if (test_texture.is_valid())
+ if (test_texture.is_valid()) {
free(test_texture);
- if (white_texture.is_valid())
+ }
+ if (white_texture.is_valid()) {
free(white_texture);
- if (test_material.is_valid())
+ }
+ if (test_material.is_valid()) {
free(test_material);
+ }
}
RID RenderingServer::_make_test_cube() {
@@ -183,10 +187,11 @@ RID RenderingServer::_make_test_cube() {
v[2] = v[1] * (1 - 2 * (j & 1));
for (int k = 0; k < 3; k++) {
- if (i < 3)
+ if (i < 3) {
face_points[j][(i + k) % 3] = v[k];
- else
+ } else {
face_points[3 - j][(i + k) % 3] = -v[k];
+ }
}
normal_points[j] = Vector3();
normal_points[j][i % 3] = (i >= 3 ? -1 : 1);
@@ -213,8 +218,9 @@ RID RenderingServer::_make_test_cube() {
Vector<int> indices;
indices.resize(vertices.size());
- for (int i = 0; i < vertices.size(); i++)
+ for (int i = 0; i < vertices.size(); i++) {
indices.set(i, i);
+ }
d[RenderingServer::ARRAY_INDEX] = indices;
mesh_add_surface_from_arrays(test_cube, PRIMITIVE_TRIANGLES, d);
@@ -290,15 +296,17 @@ RID RenderingServer::make_sphere_mesh(int p_lats, int p_lons, float p_radius) {
}
RID RenderingServer::get_white_texture() {
- if (white_texture.is_valid())
+ if (white_texture.is_valid()) {
return white_texture;
+ }
Vector<uint8_t> wt;
wt.resize(16 * 3);
{
uint8_t *w = wt.ptrw();
- for (int i = 0; i < 16 * 3; i++)
+ for (int i = 0; i < 16 * 3; i++) {
w[i] = 255;
+ }
}
Ref<Image> white = memnew(Image(4, 4, 0, Image::FORMAT_RGB8, wt));
white_texture = texture_2d_create(white);
@@ -319,8 +327,9 @@ Error RenderingServer::_surface_set_data(Array p_arrays, uint32_t p_format, uint
int max_bone = 0;
for (int ai = 0; ai < RS::ARRAY_MAX; ai++) {
- if (!(p_format & (1 << ai))) // no array
+ if (!(p_format & (1 << ai))) { // no array
continue;
+ }
switch (ai) {
case RS::ARRAY_VERTEX: {
@@ -621,8 +630,9 @@ Error RenderingServer::_surface_set_data(Array p_arrays, uint32_t p_format, uint
for (int j = 0; j < 4; j++) {
int idx = rb[i * 4 + j];
float w = rw[i * 4 + j];
- if (w == 0)
+ if (w == 0) {
continue; //break;
+ }
ERR_FAIL_INDEX_V(idx, total_bones, ERR_INVALID_DATA);
if (bptr[idx].size.x < 0) {
@@ -660,8 +670,9 @@ uint32_t RenderingServer::mesh_surface_make_offsets_from_format(uint32_t p_forma
for (int i = 0; i < RS::ARRAY_MAX; i++) {
r_offsets[i] = 0; //reset
- if (!(p_format & (1 << i))) // no array
+ if (!(p_format & (1 << i))) { // no array
continue;
+ }
int elem_size = 0;
@@ -768,8 +779,9 @@ Error RenderingServer::mesh_create_surface_data_from_arrays(SurfaceData *r_surfa
int array_len = 0;
for (int i = 0; i < p_arrays.size(); i++) {
- if (p_arrays[i].get_type() == Variant::NIL)
+ if (p_arrays[i].get_type() == Variant::NIL) {
continue;
+ }
format |= (1 << i);
@@ -802,8 +814,9 @@ Error RenderingServer::mesh_create_surface_data_from_arrays(SurfaceData *r_surfa
uint32_t bsformat = 0;
Array arr = p_blend_shapes[i];
for (int j = 0; j < arr.size(); j++) {
- if (arr[j].get_type() != Variant::NIL)
+ if (arr[j].get_type() != Variant::NIL) {
bsformat |= (1 << j);
+ }
}
ERR_FAIL_COND_V((bsformat) != (format & (RS::ARRAY_FORMAT_INDEX - 1)), ERR_INVALID_PARAMETER);
@@ -817,8 +830,9 @@ Error RenderingServer::mesh_create_surface_data_from_arrays(SurfaceData *r_surfa
for (int i = 0; i < RS::ARRAY_MAX; i++) {
offsets[i] = 0; //reset
- if (!(format & (1 << i))) // no array
+ if (!(format & (1 << i))) { // no array
continue;
+ }
int elem_size = 0;
@@ -1018,8 +1032,9 @@ Array RenderingServer::_get_array_from_surface(uint32_t p_format, Vector<uint8_t
for (int i = 0; i < RS::ARRAY_MAX; i++) {
offsets[i] = 0; //reset
- if (!(p_format & (1 << i))) // no array
+ if (!(p_format & (1 << i))) { // no array
continue;
+ }
int elem_size = 0;
@@ -1115,8 +1130,9 @@ Array RenderingServer::_get_array_from_surface(uint32_t p_format, Vector<uint8_t
const uint8_t *r = p_vertex_data.ptr();
for (int i = 0; i < RS::ARRAY_MAX; i++) {
- if (!(p_format & (1 << i)))
+ if (!(p_format & (1 << i))) {
continue;
+ }
switch (i) {
case RS::ARRAY_VERTEX: {