From 0be6d925dc3c6413bce7a3ccb49631b8e4a6e67a Mon Sep 17 00:00:00 2001 From: Rémi Verschelde Date: Thu, 14 May 2020 13:23:58 +0200 Subject: Style: clang-format: Disable KeepEmptyLinesAtTheStartOfBlocks Which means that reduz' beloved style which we all became used to will now be changed automatically to remove the first empty line. This makes us lean closer to 1TBS (the one true brace style) instead of hybridating it with some Allman-inspired spacing. There's still the case of braces around single-statement blocks that needs to be addressed (but clang-format can't help with that, but clang-tidy may if we agree about it). Part of #33027. --- modules/gdnative/pluginscript/pluginscript_loader.cpp | 2 -- modules/gdnative/pluginscript/pluginscript_loader.h | 2 -- modules/gdnative/pluginscript/pluginscript_script.cpp | 5 ----- modules/gdnative/pluginscript/pluginscript_script.h | 1 - 4 files changed, 10 deletions(-) (limited to 'modules/gdnative/pluginscript') diff --git a/modules/gdnative/pluginscript/pluginscript_loader.cpp b/modules/gdnative/pluginscript/pluginscript_loader.cpp index 64582cc517..7ce124c16a 100644 --- a/modules/gdnative/pluginscript/pluginscript_loader.cpp +++ b/modules/gdnative/pluginscript/pluginscript_loader.cpp @@ -101,13 +101,11 @@ Error ResourceFormatSaverPluginScript::save(const String &p_path, const RES &p_r } void ResourceFormatSaverPluginScript::get_recognized_extensions(const RES &p_resource, List *p_extensions) const { - if (Object::cast_to(*p_resource)) { p_extensions->push_back(_language->get_extension()); } } bool ResourceFormatSaverPluginScript::recognize(const RES &p_resource) const { - return Object::cast_to(*p_resource) != nullptr; } diff --git a/modules/gdnative/pluginscript/pluginscript_loader.h b/modules/gdnative/pluginscript/pluginscript_loader.h index e47754490a..35fc79c2ca 100644 --- a/modules/gdnative/pluginscript/pluginscript_loader.h +++ b/modules/gdnative/pluginscript/pluginscript_loader.h @@ -39,7 +39,6 @@ class PluginScriptLanguage; class ResourceFormatLoaderPluginScript : public ResourceFormatLoader { - PluginScriptLanguage *_language; public: @@ -51,7 +50,6 @@ public: }; class ResourceFormatSaverPluginScript : public ResourceFormatSaver { - PluginScriptLanguage *_language; public: diff --git a/modules/gdnative/pluginscript/pluginscript_script.cpp b/modules/gdnative/pluginscript/pluginscript_script.cpp index 9b00d654d1..d659ade876 100644 --- a/modules/gdnative/pluginscript/pluginscript_script.cpp +++ b/modules/gdnative/pluginscript/pluginscript_script.cpp @@ -56,7 +56,6 @@ void PluginScript::_bind_methods() { } PluginScriptInstance *PluginScript::_create_instance(const Variant **p_args, int p_argcount, Object *p_owner, Callable::CallError &r_error) { - r_error.error = Callable::CallError::CALL_OK; // Create instance @@ -84,7 +83,6 @@ PluginScriptInstance *PluginScript::_create_instance(const Variant **p_args, int } Variant PluginScript::_new(const Variant **p_args, int p_argcount, Callable::CallError &r_error) { - r_error.error = Callable::CallError::CALL_OK; if (!_valid) { @@ -167,7 +165,6 @@ void PluginScript::update_exports() { #ifdef TOOLS_ENABLED ASSERT_SCRIPT_VALID(); if (placeholders.size()) { - //update placeholders if any Map propdefvalues; List propinfos; @@ -281,7 +278,6 @@ Error PluginScript::reload(bool p_keep_state) { // ClassDB name (i.e. `Node2D`) or a resource path (i.e. `res://foo/bar.gd`) StringName *base_name = (StringName *)&manifest.base; if (*base_name) { - if (ClassDB::class_exists(*base_name)) { _native_parent = *base_name; } else { @@ -434,7 +430,6 @@ ScriptLanguage *PluginScript::get_language() const { } Error PluginScript::load_source_code(const String &p_path) { - Vector sourcef; Error err; FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err); diff --git a/modules/gdnative/pluginscript/pluginscript_script.h b/modules/gdnative/pluginscript/pluginscript_script.h index 287f42bf7b..659289ef9b 100644 --- a/modules/gdnative/pluginscript/pluginscript_script.h +++ b/modules/gdnative/pluginscript/pluginscript_script.h @@ -38,7 +38,6 @@ #include class PluginScript : public Script { - GDCLASS(PluginScript, Script); friend class PluginScriptInstance; -- cgit v1.2.3 From 0ee0fa42e6639b6fa474b7cf6afc6b1a78142185 Mon Sep 17 00:00:00 2001 From: Rémi Verschelde Date: Thu, 14 May 2020 16:41:43 +0200 Subject: Style: Enforce braces around if blocks and loops Using clang-tidy's `readability-braces-around-statements`. https://clang.llvm.org/extra/clang-tidy/checks/readability-braces-around-statements.html --- .clang-tidy | 6 +- core/array.cpp | 30 +- core/bind/core_bind.cpp | 86 ++- core/class_db.cpp | 120 ++-- core/color.cpp | 44 +- core/color.h | 9 +- core/color_names.inc | 3 +- core/command_queue_mt.cpp | 6 +- core/command_queue_mt.h | 19 +- core/compressed_translation.cpp | 18 +- core/compressed_translation.h | 3 +- core/cowdata.h | 35 +- core/crypto/crypto.cpp | 23 +- core/crypto/hashing_context.cpp | 3 +- core/debugger/debugger_marshalls.cpp | 3 +- core/debugger/engine_debugger.cpp | 24 +- core/debugger/local_debugger.cpp | 21 +- core/debugger/remote_debugger.cpp | 84 ++- core/debugger/remote_debugger_peer.cpp | 14 +- core/debugger/script_debugger.cpp | 12 +- core/dictionary.cpp | 30 +- core/engine.cpp | 9 +- core/error_macros.cpp | 5 +- core/func_ref.cpp | 6 +- core/hash_map.h | 63 +- core/hashfuncs.h | 13 +- core/image.cpp | 315 +++++---- core/input/input.cpp | 63 +- core/input/input_event.cpp | 81 ++- core/input/input_map.cpp | 30 +- core/io/compression.cpp | 9 +- core/io/config_file.cpp | 27 +- core/io/file_access_compressed.cpp | 33 +- core/io/file_access_encrypted.cpp | 22 +- core/io/file_access_memory.cpp | 8 +- core/io/file_access_network.cpp | 18 +- core/io/file_access_pack.cpp | 32 +- core/io/file_access_pack.h | 6 +- core/io/file_access_zip.cpp | 15 +- core/io/http_client.cpp | 32 +- core/io/image_loader.cpp | 15 +- core/io/ip.cpp | 16 +- core/io/ip_address.cpp | 15 +- core/io/ip_address.h | 25 +- core/io/json.cpp | 44 +- core/io/logger.cpp | 5 +- core/io/marshalls.cpp | 157 +++-- core/io/marshalls.h | 3 +- core/io/multiplayer_api.cpp | 57 +- core/io/net_socket.cpp | 3 +- core/io/packet_peer.cpp | 39 +- core/io/packet_peer_udp.cpp | 32 +- core/io/pck_packer.cpp | 11 +- core/io/resource_format_binary.cpp | 84 ++- core/io/resource_importer.cpp | 21 +- core/io/resource_loader.cpp | 117 ++-- core/io/resource_loader.h | 6 +- core/io/resource_saver.cpp | 27 +- core/io/stream_peer.cpp | 15 +- core/io/stream_peer_ssl.cpp | 3 +- core/io/stream_peer_tcp.cpp | 9 +- core/io/tcp_server.cpp | 9 +- core/io/translation_loader_po.cpp | 32 +- core/io/udp_server.cpp | 9 +- core/io/xml_parser.cpp | 95 ++- core/io/zip_io.cpp | 3 +- core/list.h | 70 +- core/local_vector.h | 6 +- core/map.h | 135 ++-- core/math/a_star.cpp | 44 +- core/math/aabb.cpp | 35 +- core/math/aabb.h | 96 ++- core/math/basis.cpp | 31 +- core/math/camera_matrix.cpp | 21 +- core/math/delaunay_3d.h | 9 +- core/math/disjoint_set.h | 3 +- core/math/expression.cpp | 92 ++- core/math/expression.h | 3 +- core/math/face3.cpp | 44 +- core/math/face3.h | 15 +- core/math/geometry.cpp | 132 ++-- core/math/geometry.h | 281 +++++--- core/math/math_funcs.cpp | 14 +- core/math/math_funcs.h | 11 +- core/math/octree.h | 151 ++-- core/math/plane.cpp | 8 +- core/math/plane.h | 5 +- core/math/quat.cpp | 7 +- core/math/quick_hull.cpp | 38 +- core/math/random_number_generator.h | 5 +- core/math/rect2.cpp | 75 +- core/math/rect2.h | 95 ++- core/math/transform_2d.cpp | 6 +- core/math/triangle_mesh.cpp | 65 +- core/math/triangulate.cpp | 35 +- core/math/vector3.cpp | 6 +- core/math/vector3.h | 20 +- core/math/vector3i.h | 20 +- core/message_queue.cpp | 30 +- core/method_bind.cpp | 3 +- core/method_bind.h | 13 +- core/node_path.cpp | 81 ++- core/node_path.h | 3 +- core/object.cpp | 215 ++++-- core/object.h | 52 +- core/os/dir_access.cpp | 29 +- core/os/dir_access.h | 3 +- core/os/file_access.cpp | 64 +- core/os/file_access.h | 3 +- core/os/main_loop.cpp | 12 +- core/os/memory.h | 18 +- core/os/os.cpp | 35 +- core/os/rw_lock.h | 12 +- core/os/semaphore.h | 3 +- core/os/thread.cpp | 9 +- core/os/threaded_array_processor.h | 3 +- core/packed_data_container.cpp | 25 +- core/pool_allocator.cpp | 36 +- core/pool_allocator.h | 3 +- core/print_string.cpp | 11 +- core/project_settings.cpp | 113 +-- core/reference.cpp | 6 +- core/reference.h | 12 +- core/register_core_types.cpp | 3 +- core/resource.cpp | 42 +- core/ring_buffer.h | 9 +- core/safe_refcount.h | 18 +- core/script_language.cpp | 57 +- core/script_language.h | 3 +- core/self_list.h | 6 +- core/set.h | 123 ++-- core/sort_array.h | 66 +- core/string_buffer.h | 3 +- core/string_builder.cpp | 6 +- core/string_name.cpp | 42 +- core/string_name.h | 20 +- core/translation.cpp | 23 +- core/type_info.h | 3 +- core/typedefs.h | 3 +- core/undo_redo.cpp | 66 +- core/ustring.cpp | 757 +++++++++++++-------- core/ustring.h | 20 +- core/variant.cpp | 324 +++++---- core/variant.h | 3 +- core/variant_call.cpp | 105 ++- core/variant_op.cpp | 276 +++++--- core/variant_parser.cpp | 208 ++++-- core/vector.h | 12 +- core/vmap.h | 15 +- core/vset.h | 18 +- drivers/alsa/audio_driver_alsa.cpp | 15 +- drivers/alsamidi/midi_driver_alsamidi.cpp | 6 +- drivers/png/png_driver_common.cpp | 3 +- drivers/pulseaudio/audio_driver_pulseaudio.cpp | 9 +- drivers/register_driver_types.cpp | 3 +- drivers/unix/dir_access_unix.cpp | 49 +- drivers/unix/file_access_unix.cpp | 29 +- drivers/unix/ip_unix.cpp | 12 +- drivers/unix/net_socket_posix.cpp | 50 +- drivers/unix/os_unix.cpp | 50 +- drivers/unix/syslog_logger.cpp | 5 +- drivers/unix/thread_posix.cpp | 3 +- editor/animation_bezier_editor.cpp | 66 +- editor/animation_track_editor.cpp | 366 ++++++---- editor/animation_track_editor_plugins.cpp | 66 +- editor/array_property_edit.cpp | 21 +- editor/audio_stream_preview.cpp | 9 +- editor/code_editor.cpp | 110 ++- editor/connections_dialog.cpp | 74 +- editor/create_dialog.cpp | 95 ++- editor/debugger/editor_debugger_inspector.cpp | 14 +- editor/debugger/editor_debugger_node.cpp | 63 +- editor/debugger/editor_debugger_node.h | 3 +- editor/debugger/editor_debugger_tree.cpp | 18 +- editor/debugger/editor_profiler.cpp | 50 +- editor/debugger/editor_visual_profiler.cpp | 36 +- editor/debugger/script_editor_debugger.cpp | 110 +-- editor/dependency_editor.cpp | 42 +- editor/dictionary_property_edit.cpp | 12 +- editor/doc_data.cpp | 183 +++-- editor/editor_about.cpp | 3 +- editor/editor_asset_installer.cpp | 15 +- editor/editor_atlas_packer.cpp | 11 +- editor/editor_audio_buses.cpp | 54 +- editor/editor_autoload_settings.cpp | 75 +- editor/editor_data.cpp | 166 +++-- editor/editor_data.h | 3 +- editor/editor_dir_dialog.cpp | 14 +- editor/editor_export.cpp | 71 +- editor/editor_feature_profile.cpp | 12 +- editor/editor_file_dialog.cpp | 131 ++-- editor/editor_file_system.cpp | 134 ++-- editor/editor_folding.cpp | 3 +- editor/editor_help.cpp | 148 ++-- editor/editor_help_search.cpp | 150 ++-- editor/editor_inspector.cpp | 188 +++-- editor/editor_layouts_dialog.cpp | 6 +- editor/editor_log.cpp | 6 +- editor/editor_node.cpp | 396 +++++++---- editor/editor_node.h | 8 +- editor/editor_path.cpp | 44 +- editor/editor_plugin.cpp | 15 +- editor/editor_plugin_settings.cpp | 6 +- editor/editor_properties.cpp | 130 ++-- editor/editor_properties_array_dict.cpp | 9 +- editor/editor_resource_preview.cpp | 11 +- editor/editor_run.cpp | 6 +- editor/editor_run_native.cpp | 15 +- editor/editor_sectioned_inspector.cpp | 51 +- editor/editor_settings.cpp | 69 +- editor/editor_settings.h | 5 +- editor/editor_spin_slider.cpp | 15 +- editor/editor_sub_scene.cpp | 18 +- editor/filesystem_dock.cpp | 112 +-- editor/find_in_files.cpp | 37 +- editor/groups_editor.cpp | 24 +- editor/import/collada.cpp | 330 ++++++--- editor/import/collada.h | 36 +- editor/import/editor_import_collada.cpp | 142 ++-- editor/import/editor_scene_importer_gltf.cpp | 147 ++-- editor/import/resource_importer_bitmask.cpp | 3 +- .../import/resource_importer_layered_texture.cpp | 3 +- editor/import/resource_importer_obj.cpp | 14 +- editor/import/resource_importer_scene.cpp | 158 +++-- editor/import/resource_importer_texture.cpp | 18 +- editor/import/resource_importer_texture_atlas.cpp | 5 +- editor/import/resource_importer_wav.cpp | 6 +- editor/import/resource_importer_wav.h | 17 +- editor/import_dock.cpp | 9 +- editor/inspector_dock.cpp | 33 +- editor/multi_node_edit.cpp | 36 +- editor/node_3d_editor_gizmos.cpp | 186 +++-- editor/node_dock.cpp | 5 +- editor/pane_drag.cpp | 6 +- editor/plugin_config_dialog.cpp | 3 +- editor/plugins/abstract_polygon_2d_editor.cpp | 49 +- editor/plugins/animation_blend_space_1d_editor.cpp | 18 +- editor/plugins/animation_blend_space_2d_editor.cpp | 21 +- .../plugins/animation_blend_tree_editor_plugin.cpp | 21 +- editor/plugins/animation_player_editor_plugin.cpp | 139 ++-- editor/plugins/animation_state_machine_editor.cpp | 30 +- editor/plugins/animation_tree_editor_plugin.cpp | 12 +- editor/plugins/asset_library_editor_plugin.cpp | 24 +- editor/plugins/audio_stream_editor_plugin.cpp | 9 +- editor/plugins/baked_lightmap_editor_plugin.cpp | 3 +- editor/plugins/camera_3d_editor_plugin.cpp | 5 +- editor/plugins/canvas_item_editor_plugin.cpp | 365 ++++++---- editor/plugins/canvas_item_editor_plugin.h | 5 +- .../plugins/collision_polygon_3d_editor_plugin.cpp | 42 +- editor/plugins/cpu_particles_2d_editor_plugin.cpp | 6 +- editor/plugins/curve_editor_plugin.cpp | 59 +- editor/plugins/debugger_editor_plugin.cpp | 21 +- editor/plugins/editor_preview_plugins.cpp | 42 +- editor/plugins/gi_probe_editor_plugin.cpp | 3 +- editor/plugins/gpu_particles_2d_editor_plugin.cpp | 16 +- editor/plugins/gpu_particles_3d_editor_plugin.cpp | 30 +- editor/plugins/gradient_editor_plugin.cpp | 3 +- editor/plugins/item_list_editor_plugin.cpp | 60 +- editor/plugins/light_occluder_2d_editor_plugin.cpp | 18 +- editor/plugins/material_editor_plugin.cpp | 3 +- editor/plugins/mesh_editor_plugin.cpp | 4 +- editor/plugins/mesh_instance_3d_editor_plugin.cpp | 29 +- editor/plugins/mesh_library_editor_plugin.cpp | 30 +- editor/plugins/multimesh_editor_plugin.cpp | 16 +- .../plugins/navigation_polygon_editor_plugin.cpp | 13 +- editor/plugins/node_3d_editor_plugin.cpp | 583 ++++++++++------ editor/plugins/path_2d_editor_plugin.cpp | 48 +- editor/plugins/path_3d_editor_plugin.cpp | 71 +- editor/plugins/polygon_2d_editor_plugin.cpp | 92 ++- .../plugins/resource_preloader_editor_plugin.cpp | 39 +- editor/plugins/root_motion_editor_plugin.cpp | 6 +- editor/plugins/script_editor_plugin.cpp | 204 ++++-- editor/plugins/script_text_editor.cpp | 111 +-- editor/plugins/shader_editor_plugin.cpp | 24 +- editor/plugins/shader_file_editor_plugin.cpp | 6 +- editor/plugins/skeleton_ik_3d_editor_plugin.cpp | 14 +- editor/plugins/sprite_2d_editor_plugin.cpp | 26 +- editor/plugins/sprite_frames_editor_plugin.cpp | 107 ++- editor/plugins/style_box_editor_plugin.cpp | 3 +- editor/plugins/text_editor.cpp | 3 +- editor/plugins/texture_editor_plugin.cpp | 15 +- editor/plugins/texture_layered_editor_plugin.cpp | 12 +- editor/plugins/texture_layered_editor_plugin.h | 4 +- editor/plugins/texture_region_editor_plugin.cpp | 197 +++--- editor/plugins/theme_editor_plugin.cpp | 27 +- editor/plugins/tile_map_editor_plugin.cpp | 217 ++++-- editor/plugins/tile_set_editor_plugin.cpp | 215 +++--- editor/plugins/visual_shader_editor_plugin.cpp | 92 ++- editor/progress_dialog.cpp | 21 +- editor/project_export.cpp | 128 ++-- editor/project_manager.cpp | 65 +- editor/project_settings_editor.cpp | 144 ++-- editor/property_editor.cpp | 140 ++-- editor/property_selector.cpp | 64 +- editor/pvrtc_compress.cpp | 8 +- editor/quick_open.cpp | 28 +- editor/rename_dialog.cpp | 9 +- editor/run_settings_dialog.cpp | 5 +- editor/scene_tree_dock.cpp | 312 ++++++--- editor/scene_tree_editor.cpp | 197 ++++-- editor/script_create_dialog.cpp | 39 +- editor/settings_config_dialog.cpp | 32 +- main/main.cpp | 143 ++-- main/main_timer_sync.cpp | 19 +- main/performance.cpp | 3 +- main/tests/test_astar.cpp | 77 ++- main/tests/test_gdscript.cpp | 105 +-- main/tests/test_math.cpp | 9 +- main/tests/test_oa_hash_map.cpp | 6 +- main/tests/test_ordered_hash_map.cpp | 6 +- main/tests/test_physics_2d.cpp | 3 +- main/tests/test_render.cpp | 3 +- main/tests/test_shader_lang.cpp | 12 +- main/tests/test_string.cpp | 93 ++- modules/assimp/editor_scene_importer_assimp.cpp | 3 +- modules/basis_universal/register_types.cpp | 3 +- modules/bmp/image_loader_bmp.cpp | 3 +- modules/bullet/area_bullet.cpp | 18 +- modules/bullet/btRayShape.cpp | 5 +- modules/bullet/bullet_physics_server.cpp | 24 +- modules/bullet/collision_object_bullet.cpp | 23 +- modules/bullet/godot_ray_world_algorithm.cpp | 7 +- modules/bullet/godot_ray_world_algorithm.h | 3 +- modules/bullet/godot_result_callbacks.cpp | 62 +- modules/bullet/godot_result_callbacks.h | 5 +- modules/bullet/rigid_body_bullet.cpp | 60 +- modules/bullet/shape_bullet.cpp | 18 +- modules/bullet/soft_body_bullet.cpp | 23 +- modules/bullet/space_bullet.cpp | 33 +- modules/bullet/space_bullet.h | 3 +- modules/csg/csg.cpp | 173 +++-- modules/csg/csg_gizmos.cpp | 32 +- modules/csg/csg_shape.cpp | 101 ++- modules/cvtt/image_compress_cvtt.cpp | 14 +- modules/dds/texture_loader_dds.cpp | 35 +- modules/enet/networked_multiplayer_enet.cpp | 38 +- modules/enet/register_types.cpp | 3 +- modules/etc/image_etc.cpp | 10 +- modules/etc/texture_loader_pkm.cpp | 15 +- modules/gdnative/gdnative.cpp | 15 +- modules/gdnative/gdnative/gdnative.cpp | 6 +- .../gdnative/gdnative_library_editor_plugin.cpp | 17 +- .../gdnative/gdnative_library_singleton_editor.cpp | 12 +- .../gdnative/nativescript/godot_nativescript.cpp | 6 +- modules/gdnative/nativescript/nativescript.cpp | 129 ++-- .../gdnative/pluginscript/pluginscript_loader.cpp | 9 +- .../gdnative/pluginscript/pluginscript_script.cpp | 33 +- modules/gdnative/register_types.cpp | 3 +- .../videodecoder/video_stream_gdnative.cpp | 18 +- .../gdnative/videodecoder/video_stream_gdnative.h | 3 +- modules/gdnavigation/gd_navigation_server.cpp | 6 +- modules/gdnavigation/nav_map.cpp | 20 +- modules/gdnavigation/nav_region.cpp | 6 +- .../gdnavigation/navigation_mesh_editor_plugin.cpp | 3 +- modules/gdnavigation/navigation_mesh_generator.cpp | 51 +- modules/gdscript/editor/gdscript_highlighter.cpp | 3 +- modules/gdscript/gdscript.cpp | 163 +++-- modules/gdscript/gdscript.h | 21 +- modules/gdscript/gdscript_compiler.cpp | 293 +++++--- modules/gdscript/gdscript_compiler.h | 9 +- modules/gdscript/gdscript_editor.cpp | 51 +- modules/gdscript/gdscript_function.cpp | 55 +- modules/gdscript/gdscript_function.h | 3 +- modules/gdscript/gdscript_functions.cpp | 14 +- modules/gdscript/gdscript_parser.cpp | 273 +++++--- modules/gdscript/gdscript_parser.h | 6 +- modules/gdscript/gdscript_tokenizer.cpp | 51 +- .../language_server/gdscript_extend_parser.cpp | 12 +- .../language_server/gdscript_language_protocol.cpp | 10 +- .../language_server/gdscript_workspace.cpp | 9 +- modules/gdscript/language_server/lsp.hpp | 33 +- modules/gdscript/register_types.cpp | 19 +- modules/gridmap/grid_map.cpp | 85 ++- modules/gridmap/grid_map_editor_plugin.cpp | 119 ++-- modules/hdr/image_loader_hdr.cpp | 9 +- modules/jpg/image_loader_jpegd.cpp | 11 +- modules/jsonrpc/jsonrpc.cpp | 3 +- modules/mbedtls/packet_peer_mbed_dtls.cpp | 16 +- modules/mbedtls/ssl_context_mbedtls.cpp | 18 +- modules/mbedtls/stream_peer_mbedtls.cpp | 12 +- modules/mobile_vr/mobile_vr_interface.cpp | 18 +- modules/opensimplex/noise_texture.cpp | 24 +- modules/opensimplex/open_simplex_noise.cpp | 15 +- modules/pvr/texture_loader_pvr.cpp | 62 +- modules/regex/regex.cpp | 51 +- modules/squish/image_compress_squish.cpp | 8 +- modules/stb_vorbis/audio_stream_ogg_vorbis.cpp | 3 +- modules/tga/image_loader_tga.cpp | 9 +- modules/theora/video_stream_theora.cpp | 31 +- modules/tinyexr/image_loader_tinyexr.cpp | 3 +- modules/visual_script/register_types.cpp | 3 +- modules/visual_script/visual_script.cpp | 156 +++-- modules/visual_script/visual_script.h | 18 +- .../visual_script/visual_script_builtin_funcs.cpp | 135 ++-- modules/visual_script/visual_script_editor.cpp | 308 ++++++--- modules/visual_script/visual_script_expression.cpp | 86 ++- modules/visual_script/visual_script_expression.h | 3 +- .../visual_script/visual_script_flow_control.cpp | 71 +- modules/visual_script/visual_script_func_nodes.cpp | 218 +++--- modules/visual_script/visual_script_nodes.cpp | 204 ++++-- .../visual_script_property_selector.cpp | 65 +- .../visual_script/visual_script_yield_nodes.cpp | 79 ++- modules/webm/video_stream_webm.cpp | 60 +- modules/webp/image_loader_webp.cpp | 5 +- modules/webrtc/webrtc_multiplayer.cpp | 32 +- modules/webrtc/webrtc_multiplayer.h | 3 +- modules/webrtc/webrtc_peer_connection.cpp | 3 +- .../websocket/editor_debugger_server_websocket.cpp | 3 +- .../websocket/remote_debugger_peer_websocket.cpp | 3 +- modules/websocket/websocket_client.cpp | 3 +- modules/websocket/websocket_multiplayer_peer.cpp | 21 +- modules/websocket/websocket_server.cpp | 3 +- modules/websocket/wsl_client.cpp | 27 +- modules/websocket/wsl_peer.cpp | 23 +- modules/websocket/wsl_server.cpp | 45 +- platform/android/export/export.cpp | 61 +- platform/iphone/export/export.cpp | 39 +- platform/javascript/export/export.cpp | 22 +- platform/linuxbsd/crash_handler_linuxbsd.cpp | 9 +- platform/linuxbsd/display_server_x11.cpp | 141 ++-- platform/linuxbsd/godot_linuxbsd.cpp | 3 +- platform/linuxbsd/joypad_linux.cpp | 28 +- platform/linuxbsd/key_mapping_x11.cpp | 46 +- platform/linuxbsd/os_linuxbsd.cpp | 21 +- platform/osx/export/export.cpp | 23 +- platform/uwp/export/export.cpp | 93 ++- scene/2d/animated_sprite_2d.cpp | 101 ++- scene/2d/animated_sprite_2d.h | 12 +- scene/2d/area_2d.cpp | 61 +- scene/2d/area_2d.h | 10 +- scene/2d/audio_stream_player_2d.cpp | 26 +- scene/2d/camera_2d.cpp | 58 +- scene/2d/canvas_modulate.cpp | 3 +- scene/2d/collision_object_2d.cpp | 43 +- scene/2d/collision_polygon_2d.cpp | 14 +- scene/2d/collision_shape_2d.cpp | 15 +- scene/2d/cpu_particles_2d.cpp | 53 +- scene/2d/gpu_particles_2d.cpp | 21 +- scene/2d/joints_2d.cpp | 51 +- scene/2d/light_2d.cpp | 14 +- scene/2d/light_occluder_2d.cpp | 25 +- scene/2d/line_2d.cpp | 18 +- scene/2d/line_builder.cpp | 46 +- scene/2d/mesh_instance_2d.cpp | 3 +- scene/2d/multimesh_instance_2d.cpp | 3 +- scene/2d/navigation_agent_2d.cpp | 20 +- scene/2d/navigation_obstacle_2d.cpp | 11 +- scene/2d/navigation_region_2d.cpp | 43 +- scene/2d/node_2d.cpp | 70 +- scene/2d/parallax_background.cpp | 21 +- scene/2d/parallax_layer.cpp | 15 +- scene/2d/path_2d.cpp | 32 +- scene/2d/physics_body_2d.cpp | 58 +- scene/2d/physics_body_2d.h | 3 +- scene/2d/polygon_2d.cpp | 25 +- scene/2d/position_2d.cpp | 6 +- scene/2d/ray_cast_2d.cpp | 59 +- scene/2d/remote_transform_2d.cpp | 37 +- scene/2d/skeleton_2d.cpp | 27 +- scene/2d/sprite_2d.cpp | 57 +- scene/2d/tile_map.cpp | 148 ++-- scene/2d/touch_screen_button.cpp | 65 +- scene/2d/visibility_notifier_2d.cpp | 44 +- scene/3d/area_3d.cpp | 58 +- scene/3d/area_3d.h | 10 +- scene/3d/audio_stream_player_3d.cpp | 35 +- scene/3d/baked_lightmap.cpp | 9 +- scene/3d/bone_attachment_3d.cpp | 9 +- scene/3d/camera_3d.cpp | 71 +- scene/3d/collision_object_3d.cpp | 24 +- scene/3d/collision_polygon_3d.cpp | 12 +- scene/3d/collision_shape_3d.cpp | 15 +- scene/3d/cpu_particles_3d.cpp | 47 +- scene/3d/gi_probe.cpp | 9 +- scene/3d/gpu_particles_3d.cpp | 24 +- scene/3d/immediate_geometry_3d.cpp | 3 +- scene/3d/light_3d.cpp | 6 +- scene/3d/listener_3d.cpp | 18 +- scene/3d/mesh_instance_3d.cpp | 61 +- scene/3d/multimesh_instance_3d.cpp | 10 +- scene/3d/navigation_agent_3d.cpp | 20 +- scene/3d/navigation_obstacle_3d.cpp | 11 +- scene/3d/navigation_region_3d.cpp | 18 +- scene/3d/node_3d.cpp | 85 ++- scene/3d/path_3d.cpp | 39 +- scene/3d/physics_body_3d.cpp | 206 ++++-- scene/3d/physics_body_3d.h | 5 +- scene/3d/physics_joint_3d.cpp | 68 +- scene/3d/proximity_group_3d.cpp | 3 +- scene/3d/ray_cast_3d.cpp | 79 ++- scene/3d/remote_transform_3d.cpp | 27 +- scene/3d/skeleton_3d.cpp | 64 +- scene/3d/skeleton_ik_3d.cpp | 42 +- scene/3d/soft_body_3d.cpp | 51 +- scene/3d/spring_arm_3d.cpp | 3 +- scene/3d/sprite_3d.cpp | 130 ++-- scene/3d/vehicle_body_3d.cpp | 27 +- scene/3d/velocity_tracker_3d.cpp | 3 +- scene/3d/visibility_notifier_3d.cpp | 28 +- scene/3d/visual_instance_3d.cpp | 3 +- scene/3d/voxelizer.cpp | 44 +- scene/3d/world_environment.cpp | 3 +- scene/3d/xr_nodes.cpp | 15 +- scene/animation/animation_blend_space_2d.cpp | 18 +- scene/animation/animation_blend_tree.cpp | 21 +- scene/animation/animation_cache.cpp | 30 +- scene/animation/animation_node_state_machine.cpp | 9 +- scene/animation/animation_player.cpp | 174 +++-- scene/animation/animation_player.h | 5 +- scene/animation/animation_tree.cpp | 39 +- scene/animation/tween.cpp | 197 ++++-- scene/audio/audio_stream_player.cpp | 11 +- scene/debugger/scene_debugger.cpp | 210 ++++-- scene/gui/base_button.cpp | 32 +- scene/gui/box_container.cpp | 46 +- scene/gui/button.cpp | 68 +- scene/gui/center_container.cpp | 18 +- scene/gui/check_box.cpp | 17 +- scene/gui/check_button.cpp | 14 +- scene/gui/color_picker.cpp | 97 ++- scene/gui/container.cpp | 21 +- scene/gui/control.cpp | 224 ++++-- scene/gui/control.h | 3 +- scene/gui/dialogs.cpp | 21 +- scene/gui/file_dialog.cpp | 93 ++- scene/gui/gradient_edit.cpp | 39 +- scene/gui/graph_edit.cpp | 117 ++-- scene/gui/graph_node.cpp | 138 ++-- scene/gui/grid_container.cpp | 38 +- scene/gui/item_list.cpp | 88 ++- scene/gui/label.cpp | 61 +- scene/gui/line_edit.cpp | 183 +++-- scene/gui/link_button.cpp | 5 +- scene/gui/margin_container.cpp | 21 +- scene/gui/menu_button.cpp | 9 +- scene/gui/nine_patch_rect.cpp | 9 +- scene/gui/option_button.cpp | 33 +- scene/gui/panel_container.cpp | 30 +- scene/gui/popup.cpp | 12 +- scene/gui/popup_menu.cpp | 148 ++-- scene/gui/range.cpp | 24 +- scene/gui/reference_rect.cpp | 6 +- scene/gui/rich_text_label.cpp | 330 +++++---- scene/gui/scroll_bar.cpp | 57 +- scene/gui/scroll_container.cpp | 76 ++- scene/gui/shortcut.cpp | 5 +- scene/gui/slider.cpp | 34 +- scene/gui/spin_box.cpp | 9 +- scene/gui/split_container.cpp | 63 +- scene/gui/subviewport_container.cpp | 49 +- scene/gui/tab_container.cpp | 161 +++-- scene/gui/tabs.cpp | 94 ++- scene/gui/text_edit.cpp | 729 +++++++++++++------- scene/gui/texture_button.cpp | 42 +- scene/gui/texture_progress.cpp | 66 +- scene/gui/tree.cpp | 426 ++++++++---- scene/gui/video_player.cpp | 65 +- scene/main/canvas_item.cpp | 129 ++-- scene/main/canvas_item.h | 6 +- scene/main/canvas_layer.cpp | 38 +- scene/main/http_request.cpp | 21 +- scene/main/instance_placeholder.cpp | 20 +- scene/main/node.cpp | 417 ++++++++---- scene/main/scene_tree.cpp | 192 ++++-- scene/main/timer.cpp | 25 +- scene/main/viewport.cpp | 293 +++++--- scene/main/window.cpp | 9 +- scene/resources/animation.cpp | 343 ++++++---- scene/resources/audio_stream_sample.cpp | 56 +- scene/resources/bit_map.cpp | 43 +- scene/resources/capsule_shape_2d.cpp | 6 +- scene/resources/concave_polygon_shape_2d.cpp | 17 +- scene/resources/concave_polygon_shape_3d.h | 5 +- scene/resources/convex_polygon_shape_2d.cpp | 5 +- scene/resources/curve.cpp | 191 ++++-- scene/resources/default_theme/default_theme.cpp | 3 +- scene/resources/dynamic_font.cpp | 113 +-- scene/resources/environment.cpp | 8 +- scene/resources/font.cpp | 102 ++- scene/resources/gradient.cpp | 6 +- scene/resources/gradient.h | 12 +- scene/resources/height_map_shape_3d.cpp | 6 +- scene/resources/line_shape_2d.cpp | 3 +- scene/resources/material.cpp | 65 +- scene/resources/mesh.cpp | 87 ++- scene/resources/mesh_data_tool.cpp | 72 +- scene/resources/mesh_library.cpp | 41 +- scene/resources/multimesh.cpp | 41 +- scene/resources/navigation_mesh.cpp | 17 +- scene/resources/packed_scene.cpp | 99 ++- scene/resources/particles_material.cpp | 120 ++-- scene/resources/polygon_path_finder.cpp | 27 +- scene/resources/polygon_path_finder.h | 5 +- scene/resources/primitive_meshes.cpp | 8 +- scene/resources/resource_format_text.cpp | 78 ++- scene/resources/segment_shape_2d.cpp | 3 +- scene/resources/shader.cpp | 17 +- scene/resources/shader.h | 6 +- scene/resources/shape_2d.cpp | 6 +- scene/resources/shape_3d.cpp | 3 +- scene/resources/sky.cpp | 3 +- scene/resources/style_box.cpp | 26 +- scene/resources/surface_tool.cpp | 91 ++- scene/resources/texture.cpp | 164 +++-- scene/resources/theme.cpp | 61 +- scene/resources/tile_set.cpp | 190 +++--- scene/resources/visual_shader.cpp | 45 +- scene/resources/visual_shader_nodes.cpp | 91 ++- scene/resources/world_2d.cpp | 21 +- scene/resources/world_3d.cpp | 27 +- servers/audio/audio_driver_dummy.cpp | 9 +- servers/audio/audio_filter_sw.cpp | 23 +- servers/audio/audio_rb_resampler.cpp | 15 +- servers/audio/audio_stream.cpp | 6 +- servers/audio/effects/audio_effect_chorus.cpp | 3 +- servers/audio/effects/audio_effect_compressor.cpp | 9 +- servers/audio/effects/audio_effect_delay.cpp | 3 +- servers/audio/effects/audio_effect_distortion.cpp | 5 +- servers/audio/effects/audio_effect_filter.cpp | 18 +- servers/audio/effects/audio_effect_filter.h | 9 +- servers/audio/effects/audio_effect_pitch_shift.cpp | 26 +- .../effects/audio_effect_spectrum_analyzer.cpp | 3 +- servers/audio/effects/eq.cpp | 11 +- servers/audio/effects/reverb.cpp | 53 +- servers/audio_server.cpp | 70 +- servers/physics_2d/area_2d_sw.cpp | 39 +- servers/physics_2d/area_2d_sw.h | 18 +- servers/physics_2d/area_pair_2d_sw.cpp | 39 +- servers/physics_2d/body_2d_sw.cpp | 90 ++- servers/physics_2d/body_2d_sw.h | 15 +- servers/physics_2d/body_pair_2d_sw.cpp | 45 +- servers/physics_2d/broad_phase_2d_basic.cpp | 15 +- servers/physics_2d/broad_phase_2d_hash_grid.cpp | 124 ++-- servers/physics_2d/collision_object_2d_sw.cpp | 27 +- servers/physics_2d/collision_solver_2d_sat.cpp | 354 ++++++---- servers/physics_2d/collision_solver_2d_sw.cpp | 36 +- servers/physics_2d/joints_2d_sw.cpp | 36 +- servers/physics_2d/physics_server_2d_sw.cpp | 38 +- servers/physics_2d/physics_server_2d_wrap_mt.cpp | 5 +- servers/physics_2d/physics_server_2d_wrap_mt.h | 7 +- servers/physics_2d/shape_2d_sw.cpp | 65 +- servers/physics_2d/shape_2d_sw.h | 15 +- servers/physics_2d/space_2d_sw.cpp | 146 ++-- servers/physics_2d/space_2d_sw.h | 3 +- servers/physics_2d/step_2d_sw.cpp | 18 +- servers/physics_3d/area_3d_sw.cpp | 39 +- servers/physics_3d/area_3d_sw.h | 18 +- servers/physics_3d/area_pair_3d_sw.cpp | 39 +- servers/physics_3d/body_3d_sw.cpp | 84 ++- servers/physics_3d/body_3d_sw.h | 15 +- servers/physics_3d/body_pair_3d_sw.cpp | 16 +- servers/physics_3d/broad_phase_3d_basic.cpp | 18 +- servers/physics_3d/broad_phase_octree.cpp | 6 +- servers/physics_3d/collision_object_3d_sw.cpp | 15 +- servers/physics_3d/collision_object_3d_sw.h | 3 +- servers/physics_3d/collision_solver_3d_sat.cpp | 249 ++++--- servers/physics_3d/collision_solver_3d_sw.cpp | 54 +- servers/physics_3d/gjk_epa.cpp | 85 ++- .../physics_3d/joints/generic_6dof_joint_3d_sw.cpp | 16 +- servers/physics_3d/joints/pin_joint_3d_sw.cpp | 6 +- servers/physics_3d/physics_server_3d_sw.cpp | 41 +- servers/physics_3d/shape_3d_sw.cpp | 100 ++- servers/physics_3d/space_3d_sw.cpp | 128 ++-- servers/physics_3d/space_3d_sw.h | 3 +- servers/physics_3d/step_3d_sw.cpp | 18 +- servers/physics_server_2d.cpp | 41 +- servers/physics_server_3d.cpp | 27 +- servers/rendering/rasterizer.h | 12 +- .../rasterizer_rd/rasterizer_scene_high_end_rd.cpp | 6 +- .../rasterizer_rd/rasterizer_scene_high_end_rd.h | 9 +- .../rasterizer_rd/rasterizer_scene_rd.cpp | 18 +- .../rasterizer_rd/rasterizer_storage_rd.cpp | 53 +- .../rendering/rasterizer_rd/shader_compiler_rd.cpp | 30 +- servers/rendering/rendering_server_canvas.cpp | 47 +- servers/rendering/rendering_server_canvas.h | 9 +- servers/rendering/rendering_server_raster.cpp | 15 +- servers/rendering/rendering_server_scene.cpp | 107 +-- servers/rendering/rendering_server_scene.h | 6 +- servers/rendering/rendering_server_viewport.cpp | 12 +- servers/rendering/rendering_server_viewport.h | 3 +- servers/rendering/shader_language.cpp | 228 ++++--- servers/rendering/shader_language.h | 3 +- servers/rendering_server.cpp | 50 +- 683 files changed, 22790 insertions(+), 12212 deletions(-) (limited to 'modules/gdnative/pluginscript') 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 &p_arguments, bool p OS::ProcessID pid = -2; int exitcode = 0; List 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>::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 &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 _Geometry::segment_intersects_sphere(const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_sphere_pos, real_t p_sphere_radius) { Vector 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 _Geometry::segment_intersects_sphere(const Vector3 &p_from, cons Vector _Geometry::segment_intersects_cylinder(const Vector3 &p_from, const Vector3 &p_to, float p_height, float p_radius) { Vector 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 _Geometry::segment_intersects_cylinder(const Vector3 &p_from, co Vector _Geometry::segment_intersects_convex(const Vector3 &p_from, const Vector3 &p_to, const Vector &p_planes) { Vector 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 &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 _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 _File::get_buffer(int p_length) const { int len = f->get_buffer(&w[0], p_length); ERR_FAIL_COND_V(len < 0, Vector()); - if (len < p_length) + if (len < p_length) { data.resize(p_length); + } return data; } @@ -1352,8 +1368,9 @@ Vector _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 &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(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, Listpush_back(*k); + } } } @@ -285,8 +287,9 @@ void ClassDB::get_direct_inheriters_from_class(const StringName &p_class, Listpush_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::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 *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 *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 *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 *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 while (type) { #ifdef DEBUG_METHODS_ENABLED - for (List::Element *E = type->constant_order.front(); E; E = E->next()) + for (List::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 } #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 &constants_list = type->enum_map.get(*k); const List::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 *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 *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 *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 *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 *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 _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 &p_from) { const Vector> &b = buckets[i]; Map &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(_ptr) - 2; } _FORCE_INLINE_ uint32_t *_get_size() const { - if (!_ptr) + if (!_ptr) { return nullptr; + } return reinterpret_cast(_ptr) - 1; } _FORCE_INLINE_ T *_get_data() const { - if (!_ptr) + if (!_ptr) { return nullptr; + } return reinterpret_cast(_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 void CowData::_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::_unref(void *p_data) { template void CowData::_copy_on_write() { - if (!_ptr) + if (!_ptr) { return; + } uint32_t *refc = _get_refcount(); @@ -243,8 +251,9 @@ Error CowData::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::_ref(const CowData *p_from) { template void CowData::_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::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 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(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::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 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(ObjectDB::get_instance(p_node))->get_path(); @@ -218,10 +219,11 @@ struct RemoteDebugger::ScriptsProfiler { void write_frame_data(Vector &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 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 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(); + } 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 *p_keys) const { - if (_p->variant_map.empty()) + if (_p->variant_map.empty()) { return; + } for (OrderedHashMap::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::ConstElement E = ((const OrderedHashMap *)&_p->variant_map)->find(p_key); - if (!E) + if (!E) { return nullptr; + } return &E.get(); } Variant *Dictionary::getptr(const Variant &p_key) { OrderedHashMap::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::ConstElement E = ((const OrderedHashMap *)&_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::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 *p_singletons) { - for (List::Element *E = singletons.front(); E; E = E->next()) + for (List::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(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(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(get_element(p_key)); - if (e) + if (e) { return &e->pair.data; + } return nullptr; } @@ -319,8 +330,9 @@ public: template _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 _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(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 *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 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(&wp[prev_ofs], &wp[ofs], prev_w, prev_h); break; case FORMAT_RGB8: - if (p_renormalize) + if (p_renormalize) { _generate_po2_mipmap(&wp[prev_ofs], &wp[ofs], prev_w, prev_h); - else + } else { _generate_po2_mipmap(&wp[prev_ofs], &wp[ofs], prev_w, prev_h); + } break; case FORMAT_RGBA8: - if (p_renormalize) + if (p_renormalize) { _generate_po2_mipmap(&wp[prev_ofs], &wp[ofs], prev_w, prev_h); - else + } else { _generate_po2_mipmap(&wp[prev_ofs], &wp[ofs], prev_w, prev_h); + } break; case FORMAT_RF: _generate_po2_mipmap(reinterpret_cast(&wp[prev_ofs]), reinterpret_cast(&wp[ofs]), prev_w, prev_h); @@ -1628,17 +1658,19 @@ Error Image::generate_mipmaps(bool p_renormalize) { _generate_po2_mipmap(reinterpret_cast(&wp[prev_ofs]), reinterpret_cast(&wp[ofs]), prev_w, prev_h); break; case FORMAT_RGBF: - if (p_renormalize) + if (p_renormalize) { _generate_po2_mipmap(reinterpret_cast(&wp[prev_ofs]), reinterpret_cast(&wp[ofs]), prev_w, prev_h); - else + } else { _generate_po2_mipmap(reinterpret_cast(&wp[prev_ofs]), reinterpret_cast(&wp[ofs]), prev_w, prev_h); + } break; case FORMAT_RGBAF: - if (p_renormalize) + if (p_renormalize) { _generate_po2_mipmap(reinterpret_cast(&wp[prev_ofs]), reinterpret_cast(&wp[ofs]), prev_w, prev_h); - else + } else { _generate_po2_mipmap(reinterpret_cast(&wp[prev_ofs]), reinterpret_cast(&wp[ofs]), prev_w, prev_h); + } break; case FORMAT_RH: @@ -1648,24 +1680,27 @@ Error Image::generate_mipmaps(bool p_renormalize) { _generate_po2_mipmap(reinterpret_cast(&wp[prev_ofs]), reinterpret_cast(&wp[ofs]), prev_w, prev_h); break; case FORMAT_RGBH: - if (p_renormalize) + if (p_renormalize) { _generate_po2_mipmap(reinterpret_cast(&wp[prev_ofs]), reinterpret_cast(&wp[ofs]), prev_w, prev_h); - else + } else { _generate_po2_mipmap(reinterpret_cast(&wp[prev_ofs]), reinterpret_cast(&wp[ofs]), prev_w, prev_h); + } break; case FORMAT_RGBAH: - if (p_renormalize) + if (p_renormalize) { _generate_po2_mipmap(reinterpret_cast(&wp[prev_ofs]), reinterpret_cast(&wp[ofs]), prev_w, prev_h); - else + } else { _generate_po2_mipmap(reinterpret_cast(&wp[prev_ofs]), reinterpret_cast(&wp[ofs]), prev_w, prev_h); + } break; case FORMAT_RGBE9995: - if (p_renormalize) + if (p_renormalize) { _generate_po2_mipmap(reinterpret_cast(&wp[prev_ofs]), reinterpret_cast(&wp[ofs]), prev_w, prev_h); - else + } else { _generate_po2_mipmap(reinterpret_cast(&wp[prev_ofs]), reinterpret_cast(&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 *)this)); } @@ -2218,8 +2265,9 @@ Vector 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 *)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::get_rect(const Rect2 &p_area) const { @@ -2391,13 +2448,16 @@ void Image::blit_rect(const Ref &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 &p_src, const Ref &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 &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 &p_src, const Ref &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::rgbe_to_srgb() { - if (data.size() == 0) + if (data.size() == 0) { return Ref(); + } ERR_FAIL_COND_V(format != FORMAT_RGBE9995, Ref()); @@ -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 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::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::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::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::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 &p_event, bool p_is_em Ref 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 mb = p_event; @@ -568,10 +574,11 @@ void Input::_parse_input_event_impl(const Ref &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 jm = p_event; @@ -603,8 +610,9 @@ void Input::_parse_input_event_impl(const Ref &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::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 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 &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const { Ref 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 &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 &p_event) const { Ref 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 InputEventMouseButton::xformed_by(const Transform2D &p_xform, co bool InputEventMouseButton::action_match(const Ref &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const { Ref 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 &p_event) { Ref 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 &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const { Ref 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 &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const { Ref 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 &p_event, bool * bool InputEventJoypadButton::shortcut_match(const Ref &p_event) const { Ref 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 &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 &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const { Ref 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 actions = get_actions(); - if (actions.empty()) + if (actions.empty()) { return ret; + } for (const List::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 &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>::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> *InputMap::get_action_list(const StringName &p_action) { const Map::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 &p_event, const Str Ref 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 &p_event, const Str float strength; List>::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::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 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 &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>::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::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 &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 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 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 &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::Element *E = p_dir->subdirs.front(); E; E = E->next()) + for (Map::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::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 *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 *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::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 extensions; get_recognized_extensions(&extensions); for (List::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 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 *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 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 keys; d.get_key_list(&keys); - if (p_sort_keys) + if (p_sort_keys) { keys.sort(); + } for (List::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::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::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 &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 peers_to_add; // If one is missing, take note to add it. for (Set::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::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::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::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 &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 &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(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 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 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 *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 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 resources; @@ -1795,8 +1821,9 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p E->get()->get_property_list(&property_list); for (List::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 *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 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::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 *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 *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 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 *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 Maplocalize_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 Maplocalize_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 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 remaps = ProjectSettings::get_singleton()->get("path_remap/remapped_paths"); int rc = remaps.size(); @@ -1007,8 +1036,9 @@ Ref 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 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 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 extensions; bool recognized = false; saver[i]->get_recognized_extensions(p_resource, &extensions); for (List::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 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 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 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 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 &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 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 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 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(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 = Ref(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(const_cast(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 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 void sort_custom() { U len = count; - if (len == 0) + if (len == 0) { return; + } SortArray 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(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::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::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 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(); + } Point *p = end_point; int pc = 1; // Begin point @@ -475,8 +483,9 @@ Vector 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(); + } 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 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(); + } AStar::Point *p = end_point; int pc = 1; // Begin point @@ -743,8 +755,9 @@ Vector 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(); + } AStar::Point *p = end_point; int pc = 1; // Begin point @@ -775,8 +788,9 @@ Vector 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::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 arr; Vector 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> Geometry::separate_objects(Vector 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> Geometry::separate_objects(Vector p_array) { Vector *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 Geometry::wrap_geometry(Vector 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 Geometry::wrap_geometry(Vector 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 &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 &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 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 &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 &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 &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 &p_rects, Vector &r_resu int w = 1 << i; int max_h = 0; int max_w = 0; - if (w < widest) + if (w < widest) { continue; + } Vector 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 &p_rects, Vector &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(); // Empty. } @@ -818,15 +873,17 @@ public: static Vector triangulate_polygon(const Vector &p_polygon) { Vector triangles; - if (!Triangulate::triangulate(p_polygon, triangles)) + if (!Triangulate::triangulate(p_polygon, triangles)) { return Vector(); //fail + } return triangles; } static bool is_polygon_clockwise(const Vector &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 &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(p_octant); @@ -423,12 +428,15 @@ void Octree::_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::_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::_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::_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::_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::_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::_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::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::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::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::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::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::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::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::erase(OctreeElementID p_id) { template void Octree::_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 *I; @@ -923,8 +950,9 @@ void Octree::_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::_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::_cull_convex(Octant *p_octant, _CullConvexData *p template void Octree::_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 *I; @@ -978,15 +1008,17 @@ void Octree::_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::_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::_cull_aabb(Octant *p_octant, const AABB &p_aabb, template void Octree::_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 *I; @@ -1037,15 +1072,17 @@ void Octree::_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::_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::_cull_segment(Octant *p_octant, const Vector3 &p_ template void Octree::_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 *I; @@ -1099,15 +1139,17 @@ void Octree::_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::_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::_cull_point(Octant *p_octant, const Vector3 &p_po template int Octree::cull_convex(const Vector &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 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::cull_convex(const Vector &p_convex, T **p_r template int Octree::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::cull_aabb(const AABB &p_aabb, T **p_result_array, template int Octree::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::cull_segment(const Vector3 &p_from, const Vector3 template int Octree::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 &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 &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 &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 &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::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 &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::Element *>::Element *E = new_faces.front(); E; E = E->next()) { @@ -397,10 +406,11 @@ Error QuickHull::build(const Vector &p_points, Geometry::MeshData &r_me Map::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 &p_points, Geometry::MeshData &r_me // remove all edge connections to this face for (Map::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 *r_triangles_indices) const { - if (!valid) + if (!valid) { return; + } const int triangles_num = triangles.size(); @@ -139,10 +140,11 @@ void TriangleMesh::create(const Vector &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 TriangleMesh::get_faces() const { - if (!valid) + if (!valid) { return Vector(); + } Vector 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 &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 &contour, Vector &resul /* allocate and initialize list of Vertices in polygon */ int n = contour.size(); - if (n < 3) + if (n < 3) { return false; + } Vector 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 &contour, Vector &resul /* three consecutive vertices in current polygon, */ 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 &contour, Vector &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 { #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 NodePath::get_names() const { - if (data) + if (data) { return data->path; + } return Vector(); } Vector NodePath::get_subnames() const { - if (data) + if (data) { return data->subpath; + } return Vector(); } @@ -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 &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 &p_path, bool p_absolute) { } NodePath::NodePath(const Vector &p_path, const Vector &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 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(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 &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 &p_names, const Variant &p_val } bool valid = false; - if (!r_valid) + if (!r_valid) { r_valid = &valid; + } List value_stack; @@ -554,8 +583,9 @@ void Object::set_indexed(const Vector &p_names, const Variant &p_val Variant Object::get_indexed(const Vector &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 &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