From b5e1e05ef2df27f0e7690439ac9606b0bdea08be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Tue, 4 May 2021 14:41:06 +0200 Subject: [PATCH] Style: clang-format: Disable KeepEmptyLinesAtTheStartOfBlocks --- .clang-format | 2 +- core/array.cpp | 45 -- core/array.h | 1 - core/bind/core_bind.cpp | 276 --------- core/bind/core_bind.h | 8 - core/class_db.cpp | 117 ---- core/class_db.h | 18 - core/color.cpp | 40 -- core/color.h | 10 - core/command_queue_mt.cpp | 9 - core/command_queue_mt.h | 9 - core/compressed_translation.cpp | 16 - core/compressed_translation.h | 5 - core/core_string_names.h | 1 - core/cowdata.h | 17 - core/crypto/crypto.cpp | 8 - core/crypto/crypto_core.h | 5 - core/crypto/hashing_context.cpp | 1 - core/dictionary.cpp | 26 - core/dictionary.h | 1 - core/engine.cpp | 13 - core/engine.h | 1 - core/error_macros.cpp | 7 - core/error_macros.h | 1 - core/func_ref.cpp | 5 - core/func_ref.h | 1 - core/global_constants.cpp | 8 - core/hash_map.h | 48 -- core/hashfuncs.h | 7 - core/image.cpp | 203 ------- core/input_map.cpp | 20 - core/input_map.h | 1 - core/io/compression.cpp | 10 - core/io/compression.h | 1 - core/io/config_file.cpp | 26 - core/io/config_file.h | 1 - core/io/dtls_server.cpp | 2 - core/io/file_access_compressed.cpp | 30 - core/io/file_access_compressed.h | 1 - core/io/file_access_encrypted.cpp | 33 -- core/io/file_access_memory.cpp | 18 - core/io/file_access_memory.h | 1 - core/io/file_access_network.cpp | 41 -- core/io/file_access_network.h | 3 - core/io/file_access_pack.cpp | 52 -- core/io/file_access_pack.h | 10 - core/io/file_access_zip.cpp | 36 -- core/io/file_access_zip.h | 3 - core/io/http_client.cpp | 49 -- core/io/http_client.h | 1 - core/io/image_loader.cpp | 16 - core/io/image_loader.h | 1 - core/io/ip.cpp | 21 - core/io/ip_address.cpp | 16 - core/io/ip_address.h | 1 - core/io/json.cpp | 43 -- core/io/json.h | 2 - core/io/logger.h | 1 - core/io/marshalls.cpp | 95 ---- core/io/marshalls.h | 21 - core/io/multiplayer_api.cpp | 41 -- core/io/multiplayer_api.h | 1 - core/io/net_socket.cpp | 1 - core/io/net_socket.h | 1 - core/io/networked_multiplayer_peer.cpp | 1 - core/io/networked_multiplayer_peer.h | 1 - core/io/packet_peer.cpp | 26 - core/io/packet_peer.h | 2 - core/io/packet_peer_dtls.cpp | 2 - core/io/packet_peer_udp.cpp | 16 - core/io/pck_packer.cpp | 12 - core/io/pck_packer.h | 2 - core/io/resource_format_binary.cpp | 143 ----- core/io/resource_format_binary.h | 3 - core/io/resource_importer.cpp | 32 -- core/io/resource_importer.h | 2 - core/io/resource_loader.cpp | 61 -- core/io/resource_loader.h | 4 - core/io/resource_saver.cpp | 17 - core/io/resource_saver.h | 1 - core/io/stream_peer.cpp | 50 -- core/io/stream_peer.h | 1 - core/io/stream_peer_ssl.cpp | 2 - core/io/stream_peer_tcp.cpp | 32 -- core/io/stream_peer_tcp.h | 1 - core/io/tcp_server.cpp | 7 - core/io/tcp_server.h | 1 - core/io/translation_loader_po.cpp | 11 - core/io/udp_server.cpp | 6 - core/io/xml_parser.cpp | 25 - core/io/xml_parser.h | 1 - core/io/zip_io.cpp | 12 - core/list.h | 54 -- core/map.h | 46 -- core/math/a_star.cpp | 39 -- core/math/a_star.h | 2 - core/math/aabb.cpp | 34 -- core/math/aabb.h | 17 - core/math/audio_frame.h | 2 - core/math/basis.cpp | 31 - core/math/basis.h | 18 - core/math/bsp_tree.cpp | 44 -- core/math/bsp_tree.h | 3 - core/math/bvh.h | 9 - core/math/bvh_abb.h | 1 - core/math/bvh_cull.inc | 22 - core/math/bvh_logic.inc | 1 - core/math/bvh_refit.inc | 2 - core/math/camera_matrix.cpp | 31 - core/math/camera_matrix.h | 3 - core/math/delaunay.h | 4 - core/math/disjoint_set.h | 2 - core/math/expression.cpp | 159 ------ core/math/expression.h | 8 - core/math/face3.cpp | 28 - core/math/face3.h | 15 - core/math/geometry.cpp | 91 --- core/math/geometry.h | 42 -- core/math/math_fieldwise.cpp | 1 - core/math/math_funcs.cpp | 2 - core/math/math_funcs.h | 7 - core/math/octree_definition.inc | 137 ----- core/math/plane.cpp | 12 - core/math/plane.h | 7 - core/math/quat.cpp | 5 - core/math/quat.h | 2 - core/math/quick_hull.cpp | 31 - core/math/quick_hull.h | 5 - core/math/rect2.cpp | 5 - core/math/rect2.h | 14 - core/math/transform.cpp | 21 - core/math/transform.h | 11 - core/math/transform_2d.cpp | 22 - core/math/transform_2d.h | 10 - core/math/triangle_mesh.cpp | 67 --- core/math/triangle_mesh.h | 9 - core/math/triangulate.cpp | 1 - core/math/vector2.cpp | 34 -- core/math/vector2.h | 21 - core/math/vector3.cpp | 10 - core/math/vector3.h | 41 -- core/message_queue.cpp | 28 - core/message_queue.h | 2 - core/method_bind.cpp | 7 - core/method_bind.h | 18 - core/method_ptrcall.h | 6 - core/node_path.cpp | 43 -- core/node_path.h | 3 - core/oa_hash_map.h | 10 - core/object.cpp | 136 ----- core/object.h | 11 - core/os/dir_access.cpp | 39 -- core/os/dir_access.h | 4 - core/os/file_access.cpp | 72 --- core/os/file_access.h | 5 - core/os/input.cpp | 5 - core/os/input.h | 1 - core/os/input_event.cpp | 149 ----- core/os/input_event.h | 10 - core/os/keyboard.cpp | 11 - core/os/main_loop.cpp | 10 - core/os/main_loop.h | 1 - core/os/memory.cpp | 12 - core/os/memory.h | 9 - core/os/midi_driver.cpp | 5 - core/os/midi_driver.h | 1 - core/os/os.cpp | 67 --- core/os/os.h | 4 - core/os/rw_lock.h | 2 - core/os/threaded_array_processor.h | 3 - core/packed_data_container.cpp | 44 -- core/packed_data_container.h | 1 - core/pair.h | 2 - core/pool_allocator.cpp | 50 -- core/pool_allocator.h | 2 - core/pool_vector.cpp | 3 - core/pool_vector.h | 34 -- core/print_string.cpp | 9 - core/print_string.h | 1 - core/project_settings.cpp | 64 --- core/project_settings.h | 1 - core/ref_ptr.cpp | 9 - core/ref_ptr.h | 1 - core/reference.cpp | 11 - core/reference.h | 38 -- core/register_core_types.cpp | 3 - core/resource.cpp | 51 -- core/resource.h | 1 - core/rid.cpp | 1 - core/rid.h | 15 - core/ring_buffer.h | 5 - core/script_debugger_local.cpp | 39 -- core/script_debugger_local.h | 1 - core/script_language.cpp | 46 -- core/script_language.h | 4 - core/self_list.h | 6 - core/set.h | 43 -- core/simple_type.h | 3 - core/sort_array.h | 28 - core/string_buffer.h | 1 - core/string_builder.cpp | 4 - core/string_builder.h | 1 - core/string_name.cpp | 31 - core/string_name.h | 10 - core/translation.cpp | 35 -- core/translation.h | 2 - core/type_info.h | 4 - core/typedefs.h | 10 - core/ucaps.h | 2 - core/undo_redo.cpp | 43 -- core/undo_redo.h | 2 - core/ustring.cpp | 301 ---------- core/ustring.h | 9 - core/variant.cpp | 417 -------------- core/variant.h | 6 - core/variant_call.cpp | 80 --- core/variant_op.cpp | 153 ----- core/variant_parser.cpp | 149 ----- core/variant_parser.h | 6 - core/vector.h | 5 - core/vmap.h | 17 - core/vset.h | 9 - drivers/alsa/audio_driver_alsa.cpp | 12 - drivers/alsa/audio_driver_alsa.h | 1 - drivers/alsamidi/midi_driver_alsamidi.cpp | 7 - drivers/alsamidi/midi_driver_alsamidi.h | 1 - drivers/coreaudio/audio_driver_coreaudio.cpp | 15 - drivers/coreaudio/audio_driver_coreaudio.h | 1 - drivers/coremidi/midi_driver_coremidi.cpp | 4 - drivers/coremidi/midi_driver_coremidi.h | 1 - drivers/dummy/rasterizer_dummy.h | 6 - .../gles2/rasterizer_canvas_base_gles2.cpp | 32 -- drivers/gles2/rasterizer_canvas_gles2.cpp | 66 --- drivers/gles2/rasterizer_canvas_gles2.h | 1 - drivers/gles2/rasterizer_gles2.cpp | 17 - drivers/gles2/rasterizer_gles2.h | 1 - drivers/gles2/rasterizer_scene_gles2.cpp | 115 ---- drivers/gles2/rasterizer_scene_gles2.h | 6 - drivers/gles2/rasterizer_storage_gles2.cpp | 252 --------- drivers/gles2/rasterizer_storage_gles2.h | 26 - drivers/gles2/shader_compiler_gles2.cpp | 35 -- drivers/gles2/shader_compiler_gles2.h | 3 - drivers/gles2/shader_gles2.cpp | 27 - drivers/gles2/shader_gles2.h | 10 - drivers/gles2/shaders/blend_shape.glsl | 1 - drivers/gles2/shaders/canvas.glsl | 5 - drivers/gles2/shaders/canvas_shadow.glsl | 2 - drivers/gles2/shaders/copy.glsl | 3 - drivers/gles2/shaders/cube_to_dp.glsl | 2 - drivers/gles2/shaders/cubemap_filter.glsl | 4 - drivers/gles2/shaders/effect_blur.glsl | 4 - drivers/gles2/shaders/exposure.glsl | 2 - drivers/gles2/shaders/lens_distorted.glsl | 1 - drivers/gles2/shaders/particles.glsl | 6 - drivers/gles2/shaders/resolve.glsl | 2 - drivers/gles2/shaders/scene.glsl | 21 - .../shaders/screen_space_reflection.glsl | 5 - drivers/gles2/shaders/ssao.glsl | 2 - drivers/gles2/shaders/ssao_blur.glsl | 3 - drivers/gles2/shaders/ssao_minify.glsl | 2 - drivers/gles2/shaders/subsurf_scattering.glsl | 3 - .../gles3/rasterizer_canvas_base_gles3.cpp | 48 -- drivers/gles3/rasterizer_canvas_base_gles3.h | 4 - drivers/gles3/rasterizer_canvas_gles3.cpp | 98 ---- drivers/gles3/rasterizer_gles3.cpp | 20 - drivers/gles3/rasterizer_gles3.h | 1 - drivers/gles3/rasterizer_scene_gles3.cpp | 237 -------- drivers/gles3/rasterizer_scene_gles3.h | 24 - drivers/gles3/rasterizer_storage_gles3.cpp | 529 ------------------ drivers/gles3/rasterizer_storage_gles3.h | 41 -- drivers/gles3/shader_compiler_gles3.cpp | 53 -- drivers/gles3/shader_compiler_gles3.h | 3 - drivers/gles3/shader_gles3.cpp | 49 -- drivers/gles3/shader_gles3.h | 29 - drivers/gles3/shaders/blend_shape.glsl | 1 - drivers/gles3/shaders/canvas.glsl | 9 - drivers/gles3/shaders/canvas_shadow.glsl | 2 - drivers/gles3/shaders/copy.glsl | 3 - drivers/gles3/shaders/cube_to_dp.glsl | 2 - drivers/gles3/shaders/cubemap_filter.glsl | 5 - drivers/gles3/shaders/effect_blur.glsl | 4 - drivers/gles3/shaders/exposure.glsl | 2 - drivers/gles3/shaders/lens_distorted.glsl | 1 - drivers/gles3/shaders/particles.glsl | 6 - drivers/gles3/shaders/resolve.glsl | 2 - drivers/gles3/shaders/scene.glsl | 41 -- .../shaders/screen_space_reflection.glsl | 5 - drivers/gles3/shaders/ssao.glsl | 1 - drivers/gles3/shaders/ssao_blur.glsl | 3 - drivers/gles3/shaders/ssao_minify.glsl | 2 - drivers/gles3/shaders/subsurf_scattering.glsl | 3 - drivers/gles_common/batch_diagnose.inc | 1 - .../gles_common/rasterizer_canvas_batcher.h | 31 - drivers/png/image_loader_png.cpp | 6 - drivers/png/png_driver_common.cpp | 2 - drivers/png/resource_saver_png.cpp | 6 - .../pulseaudio/audio_driver_pulseaudio.cpp | 23 - drivers/pulseaudio/audio_driver_pulseaudio.h | 1 - drivers/register_driver_types.cpp | 2 - drivers/unix/dir_access_unix.cpp | 24 - drivers/unix/dir_access_unix.h | 1 - drivers/unix/file_access_unix.cpp | 23 - drivers/unix/file_access_unix.h | 1 - drivers/unix/ip_unix.cpp | 10 - drivers/unix/net_socket_posix.cpp | 13 - drivers/unix/net_socket_posix.h | 1 - drivers/unix/os_unix.cpp | 27 - drivers/unix/os_unix.h | 1 - drivers/wasapi/audio_driver_wasapi.cpp | 28 - drivers/wasapi/audio_driver_wasapi.h | 1 - drivers/windows/dir_access_windows.cpp | 26 - drivers/windows/dir_access_windows.h | 1 - drivers/windows/file_access_windows.cpp | 25 - drivers/windows/file_access_windows.h | 1 - drivers/winmidi/midi_driver_winmidi.cpp | 5 - drivers/winmidi/midi_driver_winmidi.h | 1 - drivers/xaudio2/audio_driver_xaudio2.cpp | 13 - drivers/xaudio2/audio_driver_xaudio2.h | 2 - editor/animation_bezier_editor.cpp | 49 -- editor/animation_bezier_editor.h | 2 - editor/animation_track_editor.cpp | 330 ----------- editor/animation_track_editor.h | 4 - editor/animation_track_editor_plugins.cpp | 76 --- editor/array_property_edit.cpp | 18 - editor/array_property_edit.h | 1 - editor/audio_stream_preview.cpp | 7 - editor/code_editor.cpp | 57 -- editor/code_editor.h | 3 - editor/collada/collada.cpp | 281 ---------- editor/collada/collada.h | 40 -- editor/connections_dialog.cpp | 57 -- editor/connections_dialog.h | 3 - editor/create_dialog.cpp | 38 -- editor/create_dialog.h | 1 - editor/dependency_editor.cpp | 48 -- editor/dictionary_property_edit.cpp | 12 - editor/doc/doc_data.cpp | 92 --- editor/doc/doc_data.h | 5 - editor/editor_about.cpp | 12 - editor/editor_about.h | 1 - editor/editor_asset_installer.cpp | 14 - editor/editor_asset_installer.h | 1 - editor/editor_atlas_packer.cpp | 12 - editor/editor_audio_buses.cpp | 85 --- editor/editor_audio_buses.h | 4 - editor/editor_autoload_settings.cpp | 23 - editor/editor_autoload_settings.h | 1 - editor/editor_data.cpp | 103 ---- editor/editor_data.h | 8 - editor/editor_dir_dialog.cpp | 11 - editor/editor_export.cpp | 107 ---- editor/editor_export.h | 7 - editor/editor_feature_profile.cpp | 30 - editor/editor_feature_profile.h | 1 - editor/editor_file_dialog.cpp | 109 ---- editor/editor_file_dialog.h | 2 - editor/editor_file_system.cpp | 136 ----- editor/editor_file_system.h | 5 - editor/editor_folding.cpp | 12 - editor/editor_folding.h | 1 - editor/editor_help.cpp | 102 ---- editor/editor_help.h | 2 - editor/editor_help_search.cpp | 35 -- editor/editor_help_search.h | 1 - editor/editor_inspector.cpp | 123 ---- editor/editor_inspector.h | 1 - editor/editor_layouts_dialog.cpp | 12 - editor/editor_layouts_dialog.h | 1 - editor/editor_log.cpp | 8 - editor/editor_log.h | 1 - editor/editor_network_profiler.cpp | 7 - editor/editor_network_profiler.h | 1 - editor/editor_node.cpp | 359 ------------ editor/editor_node.h | 3 - editor/editor_path.cpp | 10 - editor/editor_path.h | 1 - editor/editor_plugin.cpp | 68 --- editor/editor_plugin.h | 3 - editor/editor_plugin_settings.cpp | 6 - editor/editor_plugin_settings.h | 1 - editor/editor_profiler.cpp | 38 -- editor/editor_profiler.h | 4 - editor/editor_properties.cpp | 151 ----- editor/editor_properties_array_dict.cpp | 57 -- editor/editor_properties_array_dict.h | 2 - editor/editor_resource_preview.cpp | 32 -- editor/editor_resource_preview.h | 2 - editor/editor_run.cpp | 13 - editor/editor_run_native.cpp | 18 - editor/editor_run_native.h | 1 - editor/editor_run_script.cpp | 8 - editor/editor_run_script.h | 1 - editor/editor_scale.cpp | 2 - editor/editor_sectioned_inspector.cpp | 24 - editor/editor_sectioned_inspector.h | 1 - editor/editor_settings.cpp | 75 --- editor/editor_settings.h | 2 - editor/editor_spin_slider.cpp | 23 - editor/editor_sub_scene.cpp | 14 - editor/editor_sub_scene.h | 1 - editor/editor_themes.cpp | 3 - editor/editor_vcs_interface.cpp | 26 - editor/editor_vcs_interface.h | 1 - editor/export_template_manager.cpp | 23 - editor/fileserver/editor_file_server.cpp | 19 - editor/fileserver/editor_file_server.h | 1 - editor/filesystem_dock.cpp | 8 - editor/find_in_files.cpp | 28 - editor/groups_editor.cpp | 11 - editor/groups_editor.h | 2 - editor/import/editor_import_collada.cpp | 162 ------ editor/import/editor_import_collada.h | 1 - editor/import/editor_import_plugin.cpp | 3 - editor/import/editor_scene_importer_gltf.cpp | 92 --- editor/import/editor_scene_importer_gltf.h | 7 - editor/import/resource_importer_bitmask.cpp | 9 - .../resource_importer_csv_translation.cpp | 11 - editor/import/resource_importer_image.cpp | 7 - .../resource_importer_layered_texture.cpp | 22 - editor/import/resource_importer_obj.cpp | 19 - editor/import/resource_importer_obj.h | 1 - editor/import/resource_importer_scene.cpp | 108 ---- editor/import/resource_importer_scene.h | 2 - editor/import/resource_importer_texture.cpp | 27 - .../resource_importer_texture_atlas.cpp | 18 - editor/import/resource_importer_wav.cpp | 28 - editor/import/resource_importer_wav.h | 3 - editor/import_dock.cpp | 30 - editor/inspector_dock.cpp | 10 - editor/inspector_dock.h | 1 - editor/multi_node_edit.cpp | 5 - editor/multi_node_edit.h | 1 - editor/node_dock.cpp | 7 - editor/node_dock.h | 1 - editor/pane_drag.cpp | 8 - editor/pane_drag.h | 1 - editor/plugin_config_dialog.cpp | 1 - editor/plugin_config_dialog.h | 1 - editor/plugins/abstract_polygon_2d_editor.cpp | 101 ---- editor/plugins/abstract_polygon_2d_editor.h | 2 - .../animation_blend_space_1d_editor.cpp | 12 - .../plugins/animation_blend_space_1d_editor.h | 1 - .../animation_blend_space_2d_editor.cpp | 34 -- .../plugins/animation_blend_space_2d_editor.h | 1 - .../animation_blend_tree_editor_plugin.cpp | 40 -- .../animation_blend_tree_editor_plugin.h | 1 - .../animation_player_editor_plugin.cpp | 123 ---- .../plugins/animation_player_editor_plugin.h | 3 - .../animation_state_machine_editor.cpp | 57 -- .../plugins/animation_state_machine_editor.h | 1 - .../plugins/animation_tree_editor_plugin.cpp | 12 - editor/plugins/animation_tree_editor_plugin.h | 2 - .../animation_tree_player_editor_plugin.cpp | 114 ---- .../animation_tree_player_editor_plugin.h | 2 - .../plugins/asset_library_editor_plugin.cpp | 71 --- editor/plugins/asset_library_editor_plugin.h | 5 - editor/plugins/audio_stream_editor_plugin.cpp | 15 - editor/plugins/audio_stream_editor_plugin.h | 2 - .../plugins/baked_lightmap_editor_plugin.cpp | 6 - editor/plugins/baked_lightmap_editor_plugin.h | 1 - editor/plugins/camera_editor_plugin.cpp | 10 - editor/plugins/camera_editor_plugin.h | 2 - editor/plugins/canvas_item_editor_plugin.cpp | 97 ---- editor/plugins/canvas_item_editor_plugin.h | 6 - .../collision_polygon_2d_editor_plugin.cpp | 2 - .../collision_polygon_2d_editor_plugin.h | 2 - .../collision_polygon_editor_plugin.cpp | 47 -- .../plugins/collision_polygon_editor_plugin.h | 2 - .../collision_shape_2d_editor_plugin.cpp | 24 - .../cpu_particles_2d_editor_plugin.cpp | 21 - .../plugins/cpu_particles_2d_editor_plugin.h | 1 - .../plugins/cpu_particles_editor_plugin.cpp | 15 - editor/plugins/cpu_particles_editor_plugin.h | 2 - editor/plugins/curve_editor_plugin.cpp | 17 - editor/plugins/editor_preview_plugins.cpp | 42 -- editor/plugins/editor_preview_plugins.h | 4 - editor/plugins/gi_probe_editor_plugin.cpp | 9 - editor/plugins/gi_probe_editor_plugin.h | 1 - editor/plugins/gradient_editor_plugin.cpp | 6 - editor/plugins/gradient_editor_plugin.h | 1 - editor/plugins/item_list_editor_plugin.cpp | 43 -- editor/plugins/item_list_editor_plugin.h | 6 - .../light_occluder_2d_editor_plugin.cpp | 12 - .../plugins/light_occluder_2d_editor_plugin.h | 2 - editor/plugins/line_2d_editor_plugin.cpp | 6 - editor/plugins/line_2d_editor_plugin.h | 2 - editor/plugins/material_editor_plugin.cpp | 21 - editor/plugins/material_editor_plugin.h | 2 - editor/plugins/mesh_editor_plugin.cpp | 12 - editor/plugins/mesh_editor_plugin.h | 2 - .../plugins/mesh_instance_editor_plugin.cpp | 25 - editor/plugins/mesh_instance_editor_plugin.h | 2 - editor/plugins/mesh_library_editor_plugin.cpp | 30 - editor/plugins/mesh_library_editor_plugin.h | 2 - editor/plugins/multimesh_editor_plugin.cpp | 29 - editor/plugins/multimesh_editor_plugin.h | 2 - .../navigation_polygon_editor_plugin.cpp | 12 - .../navigation_polygon_editor_plugin.h | 2 - editor/plugins/particles_2d_editor_plugin.cpp | 27 - editor/plugins/particles_2d_editor_plugin.h | 1 - editor/plugins/particles_editor_plugin.cpp | 39 -- editor/plugins/particles_editor_plugin.h | 3 - editor/plugins/path_2d_editor_plugin.cpp | 39 -- editor/plugins/path_2d_editor_plugin.h | 2 - editor/plugins/path_editor_plugin.cpp | 39 -- editor/plugins/path_editor_plugin.h | 3 - editor/plugins/physical_bone_plugin.cpp | 5 - editor/plugins/polygon_2d_editor_plugin.cpp | 70 --- editor/plugins/polygon_2d_editor_plugin.h | 2 - .../resource_preloader_editor_plugin.cpp | 27 - .../resource_preloader_editor_plugin.h | 2 - editor/plugins/root_motion_editor_plugin.cpp | 12 - editor/plugins/script_editor_plugin.cpp | 218 -------- editor/plugins/script_editor_plugin.h | 5 - editor/plugins/script_text_editor.cpp | 114 ---- editor/plugins/script_text_editor.h | 2 - editor/plugins/shader_editor_plugin.cpp | 51 -- editor/plugins/shader_editor_plugin.h | 3 - editor/plugins/skeleton_2d_editor_plugin.cpp | 11 - editor/plugins/skeleton_2d_editor_plugin.h | 2 - editor/plugins/skeleton_editor_plugin.cpp | 9 - editor/plugins/skeleton_editor_plugin.h | 1 - editor/plugins/skeleton_ik_editor_plugin.cpp | 6 - editor/plugins/skeleton_ik_editor_plugin.h | 1 - editor/plugins/spatial_editor_plugin.cpp | 316 ----------- editor/plugins/spatial_editor_plugin.h | 12 - editor/plugins/sprite_editor_plugin.cpp | 27 - editor/plugins/sprite_editor_plugin.h | 2 - .../plugins/sprite_frames_editor_plugin.cpp | 53 -- editor/plugins/sprite_frames_editor_plugin.h | 2 - editor/plugins/style_box_editor_plugin.cpp | 6 - editor/plugins/style_box_editor_plugin.h | 2 - editor/plugins/text_editor.cpp | 59 -- editor/plugins/text_editor.h | 1 - editor/plugins/texture_editor_plugin.cpp | 10 - editor/plugins/texture_editor_plugin.h | 2 - .../plugins/texture_region_editor_plugin.cpp | 11 - editor/plugins/texture_region_editor_plugin.h | 1 - editor/plugins/theme_editor_plugin.cpp | 41 -- editor/plugins/theme_editor_plugin.h | 2 - editor/plugins/tile_map_editor_plugin.cpp | 138 ----- editor/plugins/tile_map_editor_plugin.h | 2 - editor/plugins/tile_set_editor_plugin.cpp | 46 -- editor/plugins/tile_set_editor_plugin.h | 3 - .../plugins/version_control_editor_plugin.cpp | 56 -- .../plugins/version_control_editor_plugin.h | 1 - .../plugins/visual_shader_editor_plugin.cpp | 108 ---- editor/plugins/visual_shader_editor_plugin.h | 4 - editor/progress_dialog.cpp | 17 - editor/progress_dialog.h | 4 - editor/project_export.cpp | 45 -- editor/project_manager.cpp | 106 ---- editor/project_manager.h | 2 - editor/project_settings_editor.cpp | 99 ---- editor/project_settings_editor.h | 1 - editor/property_editor.cpp | 178 ------ editor/property_editor.h | 2 - editor/property_selector.cpp | 30 - editor/quick_open.cpp | 17 - editor/quick_open.h | 1 - editor/rename_dialog.cpp | 19 - editor/rename_dialog.h | 1 - editor/reparent_dialog.cpp | 10 - editor/reparent_dialog.h | 1 - editor/run_settings_dialog.cpp | 8 - editor/run_settings_dialog.h | 1 - editor/scene_tree_dock.cpp | 139 ----- editor/scene_tree_dock.h | 1 - editor/scene_tree_editor.cpp | 69 --- editor/scene_tree_editor.h | 2 - editor/script_create_dialog.cpp | 28 - editor/script_editor_debugger.cpp | 129 ----- editor/script_editor_debugger.h | 1 - editor/settings_config_dialog.cpp | 20 - editor/settings_config_dialog.h | 1 - editor/spatial_editor_gizmos.cpp | 235 -------- editor/spatial_editor_gizmos.h | 22 - main/input_default.cpp | 69 --- main/input_default.h | 4 - main/main.cpp | 58 -- main/main.h | 1 - main/performance.cpp | 6 - main/performance.h | 1 - main/tests/test_gdscript.cpp | 95 ---- main/tests/test_gui.cpp | 4 - main/tests/test_main.cpp | 19 - main/tests/test_math.cpp | 26 - main/tests/test_oa_hash_map.cpp | 2 - main/tests/test_ordered_hash_map.cpp | 1 - main/tests/test_physics.cpp | 27 - main/tests/test_physics_2d.cpp | 31 - main/tests/test_render.cpp | 8 - main/tests/test_shader_lang.cpp | 23 - main/tests/test_string.cpp | 32 -- modules/bmp/image_loader_bmp.cpp | 2 - modules/bullet/area_bullet.cpp | 2 - modules/bullet/btRayShape.cpp | 3 - modules/bullet/btRayShape.h | 1 - modules/bullet/bullet_physics_server.cpp | 21 - modules/bullet/collision_object_bullet.cpp | 2 - modules/bullet/cone_twist_joint_bullet.cpp | 2 - modules/bullet/constraint_bullet.h | 1 - modules/bullet/generic_6dof_joint_bullet.cpp | 1 - .../bullet/godot_collision_configuration.cpp | 22 - modules/bullet/godot_motion_state.h | 1 - modules/bullet/godot_ray_world_algorithm.cpp | 4 - modules/bullet/godot_ray_world_algorithm.h | 3 - modules/bullet/godot_result_callbacks.cpp | 5 - modules/bullet/hinge_joint_bullet.cpp | 5 - modules/bullet/joint_bullet.h | 1 - modules/bullet/pin_joint_bullet.cpp | 1 - modules/bullet/rigid_body_bullet.cpp | 19 - modules/bullet/rigid_body_bullet.h | 2 - modules/bullet/shape_bullet.cpp | 5 - modules/bullet/shape_bullet.h | 9 - modules/bullet/slider_joint_bullet.cpp | 2 - modules/bullet/soft_body_bullet.cpp | 6 - modules/bullet/soft_body_bullet.h | 1 - modules/bullet/space_bullet.cpp | 40 -- modules/bullet/space_bullet.h | 1 - modules/csg/csg.cpp | 69 --- modules/csg/csg.h | 4 - modules/csg/csg_gizmos.cpp | 18 - modules/csg/csg_gizmos.h | 1 - modules/csg/csg_shape.cpp | 82 --- modules/csg/csg_shape.h | 5 - modules/csg/register_types.cpp | 1 - modules/cvtt/image_compress_cvtt.cpp | 4 - modules/cvtt/register_types.cpp | 1 - modules/dds/register_types.cpp | 2 - modules/dds/texture_loader_dds.cpp | 42 -- modules/enet/networked_multiplayer_enet.cpp | 60 -- modules/enet/networked_multiplayer_enet.h | 2 - modules/enet/register_types.cpp | 2 - modules/etc/image_compress_etc.cpp | 3 - modules/etc/register_types.cpp | 2 - modules/etc/texture_loader_pkm.cpp | 4 - modules/fbx/data/fbx_material.cpp | 5 - modules/fbx/data/fbx_mesh_data.cpp | 13 - modules/fbx/data/pivot_transform.h | 1 - modules/fbx/editor_scene_importer_fbx.cpp | 16 - modules/fbx/editor_scene_importer_fbx.h | 1 - modules/fbx/fbx_parser/ByteSwapper.h | 1 - modules/fbx/fbx_parser/FBXAnimation.cpp | 3 - modules/fbx/fbx_parser/FBXBinaryTokenizer.cpp | 1 - modules/fbx/fbx_parser/FBXDocument.cpp | 1 - modules/fbx/fbx_parser/FBXMaterial.cpp | 1 - modules/fbx/fbx_parser/FBXMeshGeometry.cpp | 1 - modules/fbx/fbx_parser/FBXModel.cpp | 2 - modules/fbx/fbx_parser/FBXProperties.cpp | 1 - modules/fbx/fbx_parser/FBXTokenizer.cpp | 1 - modules/fbx/register_types.cpp | 1 - modules/fbx/tools/import_utils.cpp | 1 - .../gdnative/arvr/arvr_interface_gdnative.cpp | 9 - modules/gdnative/gdnative.cpp | 7 - modules/gdnative/gdnative/color.cpp | 2 - modules/gdnative/gdnative/gdnative.cpp | 2 - modules/gdnative/gdnative/plane.cpp | 1 - modules/gdnative/gdnative/quat.cpp | 1 - modules/gdnative/gdnative/rect2.cpp | 1 - modules/gdnative/gdnative/vector2.cpp | 1 - modules/gdnative/gdnative/vector3.cpp | 1 - .../gdnative_library_editor_plugin.cpp | 23 - .../gdnative/gdnative_library_editor_plugin.h | 2 - .../gdnative_library_singleton_editor.cpp | 6 - modules/gdnative/include/net/godot_net.h | 1 - .../gdnative/nativescript/api_generator.cpp | 7 - .../nativescript/godot_nativescript.cpp | 6 - .../gdnative/nativescript/nativescript.cpp | 39 -- modules/gdnative/nativescript/nativescript.h | 3 - .../gdnative/nativescript/register_types.cpp | 1 - .../net/multiplayer_peer_gdnative.cpp | 1 - modules/gdnative/net/packet_peer_gdnative.cpp | 1 - modules/gdnative/net/stream_peer_gdnative.h | 1 - .../pluginscript/pluginscript_loader.cpp | 2 - .../pluginscript/pluginscript_loader.h | 2 - .../pluginscript/pluginscript_script.cpp | 5 - .../pluginscript/pluginscript_script.h | 1 - modules/gdnative/register_types.cpp | 8 - .../gdnative/videodecoder/register_types.cpp | 2 - .../videodecoder/video_stream_gdnative.cpp | 8 - .../videodecoder/video_stream_gdnative.h | 2 - .../gdscript/editor/gdscript_highlighter.cpp | 6 - modules/gdscript/gdscript.cpp | 149 ----- modules/gdscript/gdscript.h | 8 - modules/gdscript/gdscript_compiler.cpp | 108 ---- modules/gdscript/gdscript_compiler.h | 4 - modules/gdscript/gdscript_editor.cpp | 66 --- modules/gdscript/gdscript_function.cpp | 104 ---- modules/gdscript/gdscript_function.h | 3 - modules/gdscript/gdscript_functions.cpp | 112 ---- modules/gdscript/gdscript_parser.cpp | 282 ---------- modules/gdscript/gdscript_parser.h | 12 - modules/gdscript/gdscript_tokenizer.cpp | 73 --- modules/gdscript/gdscript_tokenizer.h | 2 - .../gdscript_extend_parser.cpp | 21 - .../language_server/gdscript_extend_parser.h | 1 - .../gdscript_language_protocol.cpp | 5 - .../gdscript_language_server.cpp | 1 - .../gdscript_text_document.cpp | 17 - .../language_server/gdscript_workspace.cpp | 21 - modules/gdscript/language_server/lsp.hpp | 11 - modules/gdscript/register_types.cpp | 8 - modules/gridmap/grid_map.cpp | 73 --- modules/gridmap/grid_map.h | 9 - modules/gridmap/grid_map_editor_plugin.cpp | 104 ---- modules/gridmap/grid_map_editor_plugin.h | 5 - modules/gridmap/register_types.cpp | 1 - modules/hdr/image_loader_hdr.cpp | 4 - modules/hdr/image_loader_hdr.h | 1 - modules/hdr/register_types.cpp | 2 - modules/jpg/image_loader_jpegd.cpp | 5 - modules/jpg/image_loader_jpegd.h | 1 - modules/jpg/register_types.cpp | 2 - modules/jsonrpc/jsonrpc.cpp | 1 - modules/lightmapper_cpu/lightmapper_cpu.cpp | 25 - modules/mbedtls/crypto_mbedtls.cpp | 1 - modules/mbedtls/crypto_mbedtls.h | 3 - modules/mbedtls/dtls_server_mbedtls.cpp | 2 - modules/mbedtls/dtls_server_mbedtls.h | 1 - modules/mbedtls/packet_peer_mbed_dtls.cpp | 15 - modules/mbedtls/register_types.cpp | 2 - modules/mbedtls/ssl_context_mbedtls.cpp | 1 - modules/mbedtls/ssl_context_mbedtls.h | 2 - modules/mbedtls/stream_peer_mbedtls.cpp | 18 - modules/mono/class_db_api_json.cpp | 6 - modules/mono/csharp_script.cpp | 128 ----- modules/mono/csharp_script.h | 4 - modules/mono/editor/bindings_generator.cpp | 32 -- modules/mono/editor/bindings_generator.h | 2 - modules/mono/editor/csharp_project.cpp | 1 - modules/mono/editor/editor_internal_calls.cpp | 1 - modules/mono/editor/script_class_parser.cpp | 9 - modules/mono/editor/script_class_parser.h | 1 - modules/mono/glue/arguments_vector.h | 1 - modules/mono/glue/gd_glue.cpp | 1 - modules/mono/godotsharp_dirs.cpp | 1 - modules/mono/mono_gc_handle.cpp | 9 - modules/mono/mono_gc_handle.h | 1 - modules/mono/mono_gd/gd_mono.cpp | 44 -- modules/mono/mono_gd/gd_mono.h | 2 - modules/mono/mono_gd/gd_mono_assembly.cpp | 15 - modules/mono/mono_gd/gd_mono_assembly.h | 1 - modules/mono/mono_gd/gd_mono_cache.cpp | 4 - modules/mono/mono_gd/gd_mono_cache.h | 1 - modules/mono/mono_gd/gd_mono_class.cpp | 23 - modules/mono/mono_gd/gd_mono_field.h | 1 - modules/mono/mono_gd/gd_mono_internals.cpp | 1 - modules/mono/mono_gd/gd_mono_log.cpp | 9 - modules/mono/mono_gd/gd_mono_log.h | 1 - modules/mono/mono_gd/gd_mono_marshal.cpp | 1 - modules/mono/mono_gd/gd_mono_method.cpp | 1 - modules/mono/mono_gd/gd_mono_method.h | 1 - modules/mono/mono_gd/gd_mono_method_thunk.h | 4 - modules/mono/mono_gd/gd_mono_property.h | 1 - modules/mono/mono_gd/gd_mono_utils.cpp | 1 - modules/mono/signal_awaiter_utils.cpp | 5 - modules/mono/signal_awaiter_utils.h | 1 - modules/mono/utils/mono_reg_utils.cpp | 6 - modules/mono/utils/mono_reg_utils.h | 1 - modules/mono/utils/osx_utils.cpp | 1 - modules/mono/utils/string_utils.cpp | 1 - modules/mono/utils/thread_local.cpp | 1 - modules/mono/utils/thread_local.h | 3 - modules/opensimplex/noise_texture.cpp | 11 - modules/opensimplex/open_simplex_noise.cpp | 11 - modules/opensimplex/register_types.cpp | 1 - modules/pvr/image_compress_pvrtc.cpp | 1 - modules/pvr/register_types.cpp | 2 - modules/pvr/texture_loader_pvr.cpp | 18 - modules/raycast/lightmap_raycaster.cpp | 2 - .../recast/navigation_mesh_editor_plugin.cpp | 12 - .../recast/navigation_mesh_editor_plugin.h | 1 - modules/recast/navigation_mesh_generator.cpp | 8 - modules/regex/regex.cpp | 48 -- modules/regex/regex.h | 2 - modules/regex/register_types.cpp | 1 - modules/squish/image_compress_squish.cpp | 9 - modules/squish/register_types.cpp | 1 - .../stb_vorbis/audio_stream_ogg_vorbis.cpp | 19 - modules/stb_vorbis/audio_stream_ogg_vorbis.h | 2 - modules/stb_vorbis/register_types.cpp | 1 - .../resource_importer_ogg_vorbis.cpp | 8 - modules/svg/image_loader_svg.cpp | 7 - modules/svg/image_loader_svg.h | 1 - modules/svg/register_types.cpp | 2 - modules/tga/image_loader_tga.cpp | 4 - modules/tga/register_types.cpp | 2 - modules/theora/register_types.cpp | 2 - modules/theora/video_stream_theora.cpp | 39 -- modules/theora/video_stream_theora.h | 2 - modules/tinyexr/image_loader_tinyexr.cpp | 2 - modules/tinyexr/register_types.cpp | 2 - modules/upnp/register_types.cpp | 1 - modules/upnp/upnp.h | 1 - modules/upnp/upnp_device.h | 1 - modules/vhacd/register_types.cpp | 1 - modules/visual_script/register_types.cpp | 2 - modules/visual_script/visual_script.cpp | 209 ------- modules/visual_script/visual_script.h | 17 - .../visual_script_builtin_funcs.cpp | 119 ---- .../visual_script_builtin_funcs.h | 1 - .../visual_script/visual_script_editor.cpp | 199 ------- modules/visual_script/visual_script_editor.h | 1 - .../visual_script_expression.cpp | 93 --- .../visual_script/visual_script_expression.h | 9 - .../visual_script_flow_control.cpp | 98 ---- .../visual_script_flow_control.h | 7 - .../visual_script_func_nodes.cpp | 215 ------- .../visual_script/visual_script_func_nodes.h | 4 - modules/visual_script/visual_script_nodes.cpp | 422 -------------- modules/visual_script/visual_script_nodes.h | 28 - .../visual_script_property_selector.cpp | 16 - .../visual_script_yield_nodes.cpp | 53 -- .../visual_script/visual_script_yield_nodes.h | 2 - modules/webm/register_types.cpp | 2 - modules/webm/video_stream_webm.cpp | 55 -- modules/webm/video_stream_webm.h | 2 - modules/webp/image_loader_webp.cpp | 7 - modules/webp/image_loader_webp.h | 1 - modules/webp/register_types.cpp | 2 - modules/webrtc/webrtc_data_channel_js.cpp | 1 - modules/webrtc/webrtc_multiplayer.cpp | 2 - modules/webrtc/webrtc_multiplayer.h | 2 - modules/webrtc/webrtc_peer_connection.cpp | 2 - .../webrtc_peer_connection_gdnative.cpp | 1 - modules/webrtc/webrtc_peer_connection_js.h | 1 - modules/websocket/emws_client.cpp | 7 - modules/websocket/emws_client.h | 1 - modules/websocket/emws_peer.cpp | 12 - modules/websocket/emws_peer.h | 1 - modules/websocket/emws_server.cpp | 3 - modules/websocket/emws_server.h | 1 - modules/websocket/packet_buffer.h | 1 - modules/websocket/websocket_client.cpp | 11 - modules/websocket/websocket_client.h | 1 - .../websocket/websocket_multiplayer_peer.cpp | 28 - .../websocket/websocket_multiplayer_peer.h | 1 - modules/websocket/websocket_peer.h | 1 - modules/websocket/websocket_server.cpp | 6 - modules/websocket/websocket_server.h | 1 - modules/websocket/wsl_client.cpp | 7 - modules/websocket/wsl_client.h | 1 - modules/websocket/wsl_peer.cpp | 9 - modules/websocket/wsl_peer.h | 1 - modules/websocket/wsl_server.cpp | 1 - modules/websocket/wsl_server.h | 2 - modules/xatlas_unwrap/register_types.cpp | 2 - platform/android/android_keys_utils.cpp | 2 - platform/android/android_keys_utils.h | 1 - platform/android/api/api.cpp | 3 - platform/android/api/java_class_wrapper.h | 6 - platform/android/api/jni_singleton.h | 19 - platform/android/audio_driver_jandroid.cpp | 16 - platform/android/audio_driver_jandroid.h | 1 - platform/android/audio_driver_opensl.cpp | 19 - platform/android/audio_driver_opensl.h | 1 - platform/android/dir_access_jandroid.cpp | 20 - platform/android/dir_access_jandroid.h | 1 - platform/android/export/export.cpp | 71 --- platform/android/file_access_android.cpp | 15 - platform/android/file_access_android.h | 1 - .../java/app/src/com/godot/game/GodotApp.java | 1 - .../src/org/godotengine/godot/Dictionary.java | 6 - .../godotengine/godot/FullScreenGodotApp.java | 1 - .../lib/src/org/godotengine/godot/Godot.java | 17 - .../godot/GodotDownloaderAlarmReceiver.java | 1 - .../src/org/godotengine/godot/GodotHost.java | 1 - .../src/org/godotengine/godot/GodotIO.java | 35 -- .../src/org/godotengine/godot/GodotLib.java | 1 - .../org/godotengine/godot/GodotRenderer.java | 1 - .../src/org/godotengine/godot/GodotView.java | 3 - .../godot/input/GodotGestureHandler.java | 1 - .../godot/input/GodotInputHandler.java | 1 - .../godot/input/InputManagerCompat.java | 1 - .../godot/input/InputManagerV16.java | 1 - .../godotengine/godot/plugin/GodotPlugin.java | 1 - .../godot/plugin/GodotPluginInfoProvider.java | 1 - .../godot/plugin/GodotPluginRegistry.java | 1 - .../godotengine/godot/plugin/SignalInfo.java | 1 - .../org/godotengine/godot/utils/Crypt.java | 1 - .../org/godotengine/godot/utils/GLUtils.java | 1 - .../godot/utils/GodotNetUtils.java | 1 - .../godot/utils/PermissionsUtil.java | 1 - .../godot/xr/ovr/OvrConfigChooser.java | 1 - .../godot/xr/ovr/OvrContextFactory.java | 1 - .../godot/xr/ovr/OvrWindowSurfaceFactory.java | 1 - .../xr/regular/RegularConfigChooser.java | 3 - .../regular/RegularFallbackConfigChooser.java | 1 - platform/android/java_class_wrapper.cpp | 94 ---- platform/android/java_godot_lib_jni.cpp | 14 - platform/android/jni_utils.cpp | 34 -- platform/android/jni_utils.h | 1 - platform/android/net_socket_android.cpp | 1 - platform/android/net_socket_android.h | 1 - platform/android/os_android.cpp | 63 --- platform/android/os_android.h | 1 - platform/android/plugin/godot_plugin_config.h | 1 - platform/android/plugin/godot_plugin_jni.cpp | 5 - platform/android/power_android.h | 1 - platform/iphone/export/export.cpp | 10 - platform/iphone/ios.h | 1 - platform/iphone/ios.mm | 1 - platform/iphone/os_iphone.h | 1 - platform/iphone/os_iphone.mm | 8 - platform/iphone/plugin/godot_plugin_config.h | 1 - .../javascript/http_client_javascript.cpp | 1 - platform/javascript/javascript_eval.cpp | 2 - platform/javascript/os_javascript.cpp | 69 --- platform/osx/crash_handler_osx.h | 1 - platform/osx/dir_access_osx.mm | 1 - platform/osx/export/export.cpp | 12 - platform/osx/joypad_osx.cpp | 8 - platform/osx/joypad_osx.h | 1 - platform/osx/os_osx.mm | 91 --- platform/osx/power_osx.h | 1 - platform/server/godot_server.cpp | 1 - platform/server/os_server.cpp | 32 -- platform/server/os_server.h | 1 - platform/uwp/app.cpp | 25 - platform/uwp/context_egl_uwp.cpp | 10 - platform/uwp/context_egl_uwp.h | 1 - platform/uwp/export/export.cpp | 40 -- platform/uwp/joypad_uwp.cpp | 13 - platform/uwp/joypad_uwp.h | 2 - platform/uwp/os_uwp.cpp | 74 --- platform/uwp/os_uwp.h | 2 - platform/uwp/power_uwp.h | 1 - platform/windows/context_gl_windows.cpp | 11 - platform/windows/context_gl_windows.h | 1 - platform/windows/crash_handler_windows.h | 1 - platform/windows/export/export.cpp | 4 - platform/windows/godot_windows.cpp | 1 - platform/windows/joypad_windows.cpp | 49 -- platform/windows/joypad_windows.h | 2 - platform/windows/key_mapping_windows.cpp | 3 - platform/windows/key_mapping_windows.h | 1 - platform/windows/os_windows.cpp | 162 ------ platform/windows/os_windows.h | 2 - platform/windows/power_windows.h | 1 - platform/windows/windows_terminal_logger.cpp | 3 - platform/x11/context_gl_x11.cpp | 11 - platform/x11/context_gl_x11.h | 1 - platform/x11/crash_handler_x11.h | 1 - platform/x11/export/export.cpp | 3 - platform/x11/godot_x11.cpp | 1 - platform/x11/joypad_linux.cpp | 30 - platform/x11/key_mapping_x11.cpp | 9 - platform/x11/os_x11.cpp | 93 --- platform/x11/os_x11.h | 1 - platform/x11/power_x11.h | 1 - scene/2d/animated_sprite.cpp | 54 -- scene/2d/animated_sprite.h | 5 - scene/2d/area_2d.cpp | 63 --- scene/2d/area_2d.h | 5 - scene/2d/audio_stream_player_2d.cpp | 39 -- scene/2d/audio_stream_player_2d.h | 2 - scene/2d/back_buffer_copy.cpp | 12 - scene/2d/camera_2d.cpp | 61 -- scene/2d/camera_2d.h | 1 - scene/2d/canvas_item.cpp | 101 ---- scene/2d/canvas_item.h | 4 - scene/2d/canvas_modulate.cpp | 8 - scene/2d/canvas_modulate.h | 1 - scene/2d/collision_object_2d.cpp | 38 -- scene/2d/collision_object_2d.h | 2 - scene/2d/collision_polygon_2d.cpp | 18 - scene/2d/collision_polygon_2d.h | 1 - scene/2d/collision_shape_2d.cpp | 14 - scene/2d/collision_shape_2d.h | 1 - scene/2d/cpu_particles_2d.cpp | 80 --- scene/2d/cpu_particles_2d.h | 1 - scene/2d/joints_2d.cpp | 44 -- scene/2d/joints_2d.h | 4 - scene/2d/light_2d.cpp | 49 -- scene/2d/light_2d.h | 1 - scene/2d/light_occluder_2d.cpp | 33 -- scene/2d/light_occluder_2d.h | 1 - scene/2d/line_2d.cpp | 4 - scene/2d/line_2d.h | 1 - scene/2d/line_builder.cpp | 5 - scene/2d/mesh_instance_2d.cpp | 9 - scene/2d/multimesh_instance_2d.cpp | 9 - scene/2d/navigation_2d.cpp | 55 -- scene/2d/navigation_2d.h | 9 - scene/2d/navigation_polygon.cpp | 52 -- scene/2d/navigation_polygon.h | 2 - scene/2d/node_2d.cpp | 38 -- scene/2d/node_2d.h | 1 - scene/2d/parallax_background.cpp | 26 - scene/2d/parallax_background.h | 1 - scene/2d/parallax_layer.cpp | 13 - scene/2d/parallax_layer.h | 1 - scene/2d/particles_2d.cpp | 37 -- scene/2d/path_2d.cpp | 38 -- scene/2d/path_2d.h | 2 - scene/2d/physics_body_2d.cpp | 127 ----- scene/2d/physics_body_2d.h | 9 - scene/2d/polygon_2d.cpp | 44 -- scene/2d/polygon_2d.h | 1 - scene/2d/position_2d.cpp | 6 - scene/2d/position_2d.h | 1 - scene/2d/ray_cast_2d.cpp | 33 -- scene/2d/ray_cast_2d.h | 1 - scene/2d/remote_transform_2d.cpp | 13 - scene/2d/remote_transform_2d.h | 1 - scene/2d/skeleton_2d.cpp | 17 - scene/2d/sprite.cpp | 33 -- scene/2d/sprite.h | 1 - scene/2d/tile_map.cpp | 141 ----- scene/2d/tile_map.h | 4 - scene/2d/touch_screen_button.cpp | 39 -- scene/2d/touch_screen_button.h | 1 - scene/2d/visibility_notifier_2d.cpp | 34 -- scene/2d/visibility_notifier_2d.h | 2 - scene/2d/y_sort.cpp | 4 - scene/3d/area.cpp | 69 --- scene/3d/area.h | 5 - scene/3d/arvr_nodes.cpp | 1 - scene/3d/arvr_nodes.h | 3 - scene/3d/audio_stream_player_3d.cpp | 70 --- scene/3d/audio_stream_player_3d.h | 2 - scene/3d/baked_lightmap.cpp | 47 -- scene/3d/baked_lightmap.h | 1 - scene/3d/bone_attachment.cpp | 14 - scene/3d/bone_attachment.h | 1 - scene/3d/camera.cpp | 63 --- scene/3d/camera.h | 2 - scene/3d/collision_object.cpp | 33 -- scene/3d/collision_object.h | 2 - scene/3d/collision_polygon.cpp | 15 - scene/3d/collision_polygon.h | 1 - scene/3d/collision_shape.cpp | 13 - scene/3d/collision_shape.h | 1 - scene/3d/cpu_particles.cpp | 80 --- scene/3d/cpu_particles.h | 1 - scene/3d/gi_probe.cpp | 59 -- scene/3d/gi_probe.h | 1 - scene/3d/immediate_geometry.cpp | 16 - scene/3d/immediate_geometry.h | 1 - scene/3d/interpolated_camera.cpp | 18 - scene/3d/interpolated_camera.h | 1 - scene/3d/light.cpp | 43 -- scene/3d/light.h | 4 - scene/3d/listener.cpp | 16 - scene/3d/listener.h | 1 - scene/3d/mesh_instance.cpp | 26 - scene/3d/mesh_instance.h | 2 - scene/3d/multimesh_instance.cpp | 5 - scene/3d/navigation.cpp | 56 -- scene/3d/navigation.h | 9 - scene/3d/navigation_mesh.cpp | 40 -- scene/3d/navigation_mesh.h | 3 - scene/3d/particles.cpp | 42 -- scene/3d/path.cpp | 29 - scene/3d/path.h | 2 - scene/3d/physics_body.cpp | 145 ----- scene/3d/physics_body.h | 10 - scene/3d/physics_joint.cpp | 77 --- scene/3d/physics_joint.h | 6 - scene/3d/position_3d.h | 1 - scene/3d/proximity_group.cpp | 23 - scene/3d/proximity_group.h | 1 - scene/3d/ray_cast.cpp | 35 -- scene/3d/ray_cast.h | 1 - scene/3d/reflection_probe.cpp | 27 - scene/3d/remote_transform.cpp | 11 - scene/3d/skeleton.cpp | 66 --- scene/3d/skeleton.h | 4 - scene/3d/soft_body.cpp | 26 - scene/3d/soft_body.h | 1 - scene/3d/spatial.cpp | 66 --- scene/3d/spatial.h | 3 - scene/3d/spatial_velocity_tracker.cpp | 6 - scene/3d/spring_arm.cpp | 2 - scene/3d/sprite_3d.cpp | 79 --- scene/3d/sprite_3d.h | 3 - scene/3d/vehicle_body.cpp | 55 -- scene/3d/vehicle_body.h | 2 - scene/3d/visibility_notifier.cpp | 29 - scene/3d/visibility_notifier.h | 2 - scene/3d/visual_instance.cpp | 35 -- scene/3d/visual_instance.h | 2 - scene/3d/voxel_light_baker.cpp | 66 --- scene/3d/voxel_light_baker.h | 1 - scene/3d/world_environment.cpp | 7 - scene/3d/world_environment.h | 1 - scene/animation/animation_blend_space_1d.cpp | 5 - scene/animation/animation_blend_space_2d.cpp | 23 - scene/animation/animation_blend_tree.cpp | 79 --- scene/animation/animation_blend_tree.h | 2 - scene/animation/animation_cache.cpp | 35 -- scene/animation/animation_cache.h | 2 - .../animation_node_state_machine.cpp | 48 -- .../animation/animation_node_state_machine.h | 2 - scene/animation/animation_player.cpp | 131 ----- scene/animation/animation_player.h | 13 - scene/animation/animation_tree.cpp | 74 --- scene/animation/animation_tree.h | 9 - scene/animation/animation_tree_player.cpp | 163 ------ scene/animation/animation_tree_player.h | 17 - scene/animation/root_motion_view.cpp | 6 - scene/animation/skeleton_ik.cpp | 23 - scene/animation/skeleton_ik.h | 2 - scene/animation/tween.cpp | 17 - scene/animation/tween.h | 1 - scene/audio/audio_stream_player.cpp | 32 -- scene/audio/audio_stream_player.h | 1 - scene/debugger/script_debugger_remote.cpp | 83 --- scene/debugger/script_debugger_remote.h | 6 - scene/gui/base_button.cpp | 43 -- scene/gui/base_button.h | 3 - scene/gui/box_container.cpp | 15 - scene/gui/box_container.h | 3 - scene/gui/button.cpp | 27 - scene/gui/button.h | 1 - scene/gui/center_container.cpp | 9 - scene/gui/center_container.h | 1 - scene/gui/check_box.cpp | 5 - scene/gui/check_box.h | 1 - scene/gui/check_button.cpp | 6 - scene/gui/check_button.h | 1 - scene/gui/color_picker.cpp | 50 -- scene/gui/color_picker.h | 2 - scene/gui/color_rect.cpp | 5 - scene/gui/container.cpp | 15 - scene/gui/container.h | 1 - scene/gui/control.cpp | 211 ------- scene/gui/control.h | 3 - scene/gui/dialogs.cpp | 39 -- scene/gui/dialogs.h | 4 - scene/gui/file_dialog.cpp | 81 --- scene/gui/file_dialog.h | 2 - scene/gui/gradient_edit.cpp | 18 - scene/gui/gradient_edit.h | 1 - scene/gui/graph_edit.cpp | 91 --- scene/gui/graph_edit.h | 3 - scene/gui/graph_node.cpp | 52 -- scene/gui/graph_node.h | 1 - scene/gui/grid_container.cpp | 10 - scene/gui/grid_container.h | 1 - scene/gui/item_list.cpp | 125 ----- scene/gui/item_list.h | 2 - scene/gui/label.cpp | 58 -- scene/gui/label.h | 2 - scene/gui/line_edit.cpp | 97 ---- scene/gui/line_edit.h | 2 - scene/gui/link_button.cpp | 14 - scene/gui/link_button.h | 1 - scene/gui/margin_container.cpp | 6 - scene/gui/menu_button.cpp | 13 - scene/gui/menu_button.h | 1 - scene/gui/nine_patch_rect.cpp | 15 - scene/gui/nine_patch_rect.h | 1 - scene/gui/option_button.cpp | 39 -- scene/gui/option_button.h | 1 - scene/gui/panel.cpp | 3 - scene/gui/panel.h | 1 - scene/gui/panel_container.cpp | 6 - scene/gui/panel_container.h | 1 - scene/gui/popup.cpp | 22 - scene/gui/popup.h | 2 - scene/gui/popup_menu.cpp | 132 ----- scene/gui/popup_menu.h | 1 - scene/gui/progress_bar.cpp | 8 - scene/gui/progress_bar.h | 1 - scene/gui/range.cpp | 33 -- scene/gui/range.h | 1 - scene/gui/reference_rect.cpp | 2 - scene/gui/reference_rect.h | 1 - scene/gui/rich_text_effect.cpp | 1 - scene/gui/rich_text_label.cpp | 174 ------ scene/gui/rich_text_label.h | 3 - scene/gui/scroll_bar.cpp | 62 -- scene/gui/scroll_bar.h | 3 - scene/gui/scroll_container.cpp | 40 -- scene/gui/scroll_container.h | 1 - scene/gui/separator.cpp | 8 - scene/gui/separator.h | 3 - scene/gui/shortcut.cpp | 6 - scene/gui/shortcut.h | 1 - scene/gui/slider.cpp | 27 - scene/gui/slider.h | 3 - scene/gui/spin_box.cpp | 33 -- scene/gui/spin_box.h | 1 - scene/gui/split_container.cpp | 35 -- scene/gui/split_container.h | 3 - scene/gui/tab_container.cpp | 55 -- scene/gui/tab_container.h | 1 - scene/gui/tabs.cpp | 57 -- scene/gui/tabs.h | 2 - scene/gui/text_edit.cpp | 315 ----------- scene/gui/text_edit.h | 7 - scene/gui/texture_button.cpp | 22 - scene/gui/texture_button.h | 1 - scene/gui/texture_progress.cpp | 10 - scene/gui/texture_progress.h | 1 - scene/gui/texture_rect.cpp | 16 - scene/gui/texture_rect.h | 1 - scene/gui/tree.cpp | 344 ------------ scene/gui/tree.h | 6 - scene/gui/video_player.cpp | 43 -- scene/gui/video_player.h | 2 - scene/gui/viewport_container.cpp | 18 - scene/gui/viewport_container.h | 1 - scene/main/canvas_layer.cpp | 30 - scene/main/canvas_layer.h | 1 - scene/main/http_request.cpp | 37 -- scene/main/http_request.h | 1 - scene/main/instance_placeholder.cpp | 8 - scene/main/instance_placeholder.h | 1 - scene/main/node.cpp | 224 -------- scene/main/node.h | 6 - scene/main/resource_preloader.cpp | 16 - scene/main/resource_preloader.h | 1 - scene/main/scene_tree.cpp | 148 ----- scene/main/scene_tree.h | 3 - scene/main/timer.cpp | 13 - scene/main/timer.h | 1 - scene/main/viewport.cpp | 264 --------- scene/main/viewport.h | 3 - scene/register_scene_types.cpp | 2 - scene/resources/animation.cpp | 277 --------- scene/resources/animation.h | 16 - scene/resources/audio_stream_sample.cpp | 39 -- scene/resources/audio_stream_sample.h | 2 - scene/resources/bit_map.cpp | 29 - scene/resources/bit_map.h | 1 - scene/resources/box_shape.cpp | 6 - scene/resources/box_shape.h | 1 - scene/resources/capsule_shape.cpp | 10 - scene/resources/capsule_shape.h | 1 - scene/resources/capsule_shape_2d.cpp | 11 - scene/resources/circle_shape_2d.cpp | 8 - scene/resources/concave_polygon_shape.cpp | 8 - scene/resources/concave_polygon_shape.h | 2 - scene/resources/concave_polygon_shape_2d.cpp | 6 - scene/resources/convex_polygon_shape.cpp | 6 - scene/resources/convex_polygon_shape.h | 1 - scene/resources/convex_polygon_shape_2d.cpp | 7 - scene/resources/curve.cpp | 90 --- scene/resources/curve.h | 7 - scene/resources/cylinder_shape.cpp | 10 - scene/resources/cylinder_shape.h | 1 - .../resources/default_theme/default_theme.cpp | 11 - scene/resources/dynamic_font.cpp | 61 -- scene/resources/dynamic_font.h | 5 - scene/resources/environment.cpp | 160 ------ scene/resources/environment.h | 1 - scene/resources/font.cpp | 58 -- scene/resources/font.h | 4 - scene/resources/gradient.cpp | 3 - scene/resources/gradient.h | 2 - scene/resources/height_map_shape.cpp | 3 - scene/resources/line_shape_2d.cpp | 10 - scene/resources/material.cpp | 161 ------ scene/resources/material.h | 5 - scene/resources/mesh.cpp | 87 --- scene/resources/mesh.h | 1 - scene/resources/mesh_data_tool.cpp | 50 -- scene/resources/mesh_data_tool.h | 3 - scene/resources/mesh_library.cpp | 29 - scene/resources/mesh_library.h | 1 - scene/resources/multimesh.cpp | 39 -- scene/resources/multimesh.h | 1 - scene/resources/packed_scene.cpp | 112 ---- scene/resources/packed_scene.h | 5 - scene/resources/particles_material.cpp | 59 -- scene/resources/particles_material.h | 3 - scene/resources/physics_material.cpp | 1 - scene/resources/physics_material.h | 1 - scene/resources/plane_shape.cpp | 6 - scene/resources/plane_shape.h | 1 - scene/resources/polygon_path_finder.cpp | 42 -- scene/resources/polygon_path_finder.h | 4 - scene/resources/primitive_meshes.cpp | 8 - scene/resources/primitive_meshes.h | 8 - scene/resources/ray_shape.cpp | 7 - scene/resources/ray_shape.h | 1 - scene/resources/rectangle_shape_2d.cpp | 7 - scene/resources/resource_format_text.cpp | 95 ---- scene/resources/resource_format_text.h | 3 - scene/resources/segment_shape_2d.cpp | 18 - scene/resources/shader.cpp | 22 - scene/resources/shader.h | 1 - scene/resources/shape.cpp | 8 - scene/resources/shape.h | 1 - scene/resources/shape_2d.cpp | 8 - scene/resources/skin.cpp | 3 - scene/resources/sky.cpp | 53 -- scene/resources/sphere_shape.cpp | 7 - scene/resources/sphere_shape.h | 1 - scene/resources/style_box.cpp | 59 -- scene/resources/style_box.h | 5 - scene/resources/surface_tool.cpp | 70 --- scene/resources/surface_tool.h | 2 - scene/resources/text_file.cpp | 1 - scene/resources/text_file.h | 1 - scene/resources/texture.cpp | 184 ------ scene/resources/texture.h | 14 - scene/resources/theme.cpp | 87 --- scene/resources/theme.h | 1 - scene/resources/tile_set.cpp | 79 --- scene/resources/tile_set.h | 2 - scene/resources/video_stream.h | 2 - scene/resources/visual_shader.cpp | 73 --- scene/resources/visual_shader.h | 1 - scene/resources/visual_shader_nodes.cpp | 131 ----- scene/resources/world.cpp | 33 -- scene/resources/world_2d.cpp | 46 -- scene/resources/world_2d.h | 1 - scene/scene_string_names.cpp | 1 - scene/scene_string_names.h | 1 - servers/arvr_server.cpp | 7 - servers/audio/audio_driver_dummy.cpp | 10 - servers/audio/audio_driver_dummy.h | 1 - servers/audio/audio_filter_sw.cpp | 21 - servers/audio/audio_filter_sw.h | 3 - servers/audio/audio_rb_resampler.cpp | 15 - servers/audio/audio_rb_resampler.h | 10 - servers/audio/audio_stream.cpp | 13 - servers/audio/audio_stream.h | 7 - .../audio/effects/audio_effect_amplify.cpp | 3 - servers/audio/effects/audio_effect_chorus.cpp | 25 - servers/audio/effects/audio_effect_chorus.h | 2 - .../audio/effects/audio_effect_compressor.cpp | 20 - servers/audio/effects/audio_effect_delay.cpp | 31 - .../audio/effects/audio_effect_distortion.cpp | 17 - servers/audio/effects/audio_effect_eq.cpp | 9 - servers/audio/effects/audio_effect_filter.cpp | 12 - .../audio/effects/audio_effect_limiter.cpp | 11 - servers/audio/effects/audio_effect_panner.cpp | 4 - servers/audio/effects/audio_effect_phaser.cpp | 13 - .../effects/audio_effect_pitch_shift.cpp | 4 - .../audio/effects/audio_effect_pitch_shift.h | 1 - servers/audio/effects/audio_effect_record.cpp | 3 - servers/audio/effects/audio_effect_reverb.cpp | 20 - .../audio_effect_spectrum_analyzer.cpp | 7 - .../effects/audio_effect_stereo_enhance.cpp | 12 - .../audio/effects/audio_stream_generator.cpp | 10 - .../audio/effects/audio_stream_generator.h | 1 - servers/audio/effects/eq.cpp | 18 - servers/audio/effects/eq.h | 3 - servers/audio/effects/reverb.cpp | 29 - servers/audio/effects/reverb.h | 3 - servers/audio_server.cpp | 106 ---- servers/audio_server.h | 7 - servers/physics/area_pair_sw.cpp | 14 - servers/physics/area_pair_sw.h | 2 - servers/physics/area_sw.cpp | 15 - servers/physics/area_sw.h | 10 - servers/physics/body_pair_sw.cpp | 25 - servers/physics/body_pair_sw.h | 1 - servers/physics/body_sw.cpp | 52 -- servers/physics/body_sw.h | 18 - servers/physics/broad_phase_basic.cpp | 27 - servers/physics/broad_phase_basic.h | 3 - servers/physics/broad_phase_bvh.cpp | 15 - servers/physics/broad_phase_bvh.h | 1 - servers/physics/broad_phase_octree.cpp | 15 - servers/physics/broad_phase_octree.h | 1 - servers/physics/broad_phase_sw.h | 1 - servers/physics/collision_object_sw.cpp | 17 - servers/physics/collision_object_sw.h | 1 - servers/physics/collision_solver_sat.cpp | 97 ---- servers/physics/collision_solver_sw.cpp | 21 - servers/physics/constraint_sw.h | 1 - servers/physics/gjk_epa.cpp | 3 - .../physics/joints/cone_twist_joint_sw.cpp | 15 - .../physics/joints/generic_6dof_joint_sw.cpp | 39 -- servers/physics/joints/hinge_joint_sw.cpp | 10 - servers/physics/joints/hinge_joint_sw.h | 1 - servers/physics/joints/pin_joint_sw.cpp | 4 - servers/physics/joints/pin_joint_sw.h | 1 - servers/physics/joints/slider_joint_sw.cpp | 4 - servers/physics/joints_sw.h | 1 - servers/physics/physics_server_sw.cpp | 159 ------ servers/physics/physics_server_sw.h | 2 - servers/physics/shape_sw.cpp | 160 ------ servers/physics/shape_sw.h | 18 - servers/physics/space_sw.cpp | 82 --- servers/physics/space_sw.h | 2 - servers/physics/step_sw.cpp | 17 - servers/physics/step_sw.h | 1 - servers/physics_2d/area_2d_sw.cpp | 15 - servers/physics_2d/area_2d_sw.h | 10 - servers/physics_2d/area_pair_2d_sw.cpp | 14 - servers/physics_2d/area_pair_2d_sw.h | 2 - servers/physics_2d/body_2d_sw.cpp | 58 -- servers/physics_2d/body_2d_sw.h | 13 - servers/physics_2d/body_pair_2d_sw.cpp | 22 - servers/physics_2d/body_pair_2d_sw.h | 2 - servers/physics_2d/broad_phase_2d_basic.cpp | 21 - servers/physics_2d/broad_phase_2d_basic.h | 3 - servers/physics_2d/broad_phase_2d_bvh.cpp | 14 - servers/physics_2d/broad_phase_2d_bvh.h | 1 - .../physics_2d/broad_phase_2d_hash_grid.cpp | 48 -- servers/physics_2d/broad_phase_2d_hash_grid.h | 7 - servers/physics_2d/broad_phase_2d_sw.h | 1 - servers/physics_2d/collision_object_2d_sw.cpp | 20 - servers/physics_2d/collision_object_2d_sw.h | 2 - .../physics_2d/collision_solver_2d_sat.cpp | 64 --- servers/physics_2d/collision_solver_2d_sw.cpp | 14 - servers/physics_2d/constraint_2d_sw.h | 1 - servers/physics_2d/joints_2d_sw.cpp | 25 - servers/physics_2d/joints_2d_sw.h | 4 - servers/physics_2d/physics_2d_server_sw.cpp | 153 ----- servers/physics_2d/physics_2d_server_sw.h | 2 - .../physics_2d/physics_2d_server_wrap_mt.cpp | 17 - .../physics_2d/physics_2d_server_wrap_mt.h | 9 - servers/physics_2d/shape_2d_sw.cpp | 104 ---- servers/physics_2d/shape_2d_sw.h | 31 - servers/physics_2d/space_2d_sw.cpp | 89 --- servers/physics_2d/space_2d_sw.h | 2 - servers/physics_2d/step_2d_sw.cpp | 18 - servers/physics_2d/step_2d_sw.h | 1 - servers/physics_2d_server.cpp | 54 -- servers/physics_2d_server.h | 11 - servers/physics_server.cpp | 37 -- servers/physics_server.h | 10 - servers/register_server_types.cpp | 5 - servers/visual/rasterizer.cpp | 2 - servers/visual/rasterizer.h | 38 -- servers/visual/shader_language.cpp | 191 ------- servers/visual/shader_language.h | 2 - servers/visual/shader_types.cpp | 3 - servers/visual/shader_types.h | 2 - servers/visual/visual_server_canvas.cpp | 130 ----- servers/visual/visual_server_canvas.h | 8 - servers/visual/visual_server_raster.cpp | 19 - servers/visual/visual_server_raster.h | 2 - servers/visual/visual_server_scene.cpp | 226 -------- servers/visual/visual_server_scene.h | 24 - servers/visual/visual_server_viewport.cpp | 57 -- servers/visual/visual_server_viewport.h | 5 - servers/visual/visual_server_wrap_mt.cpp | 20 - servers/visual/visual_server_wrap_mt.h | 1 - servers/visual_server.cpp | 167 ------ servers/visual_server.h | 1 - 1439 files changed, 1 insertion(+), 34187 deletions(-) diff --git a/.clang-format b/.clang-format index 14b9930c1dc..09436d0f885 100644 --- a/.clang-format +++ b/.clang-format @@ -76,7 +76,7 @@ IndentWidth: 4 # IndentWrappedFunctionNames: false # JavaScriptQuotes: Leave # JavaScriptWrapImports: true -# KeepEmptyLinesAtTheStartOfBlocks: true +KeepEmptyLinesAtTheStartOfBlocks: false # MacroBlockBegin: '' # MacroBlockEnd: '' # MaxEmptyLinesToKeep: 1 diff --git a/core/array.cpp b/core/array.cpp index 2bebcff18cb..774d761236b 100644 --- a/core/array.cpp +++ b/core/array.cpp @@ -42,7 +42,6 @@ public: }; void Array::_ref(const Array &p_from) const { - ArrayPrivate *_fp = p_from._p; ERR_FAIL_COND(!_fp); // should NOT happen. @@ -60,7 +59,6 @@ void Array::_ref(const Array &p_from) const { } void Array::_unref() const { - if (!_p) return; @@ -71,69 +69,55 @@ void Array::_unref() const { } Variant &Array::operator[](int p_idx) { - return _p->array.write[p_idx]; } const Variant &Array::operator[](int p_idx) const { - return _p->array[p_idx]; } int Array::size() const { - return _p->array.size(); } bool Array::empty() const { - return _p->array.empty(); } void Array::clear() { - _p->array.clear(); } bool Array::operator==(const Array &p_array) const { - return _p == p_array._p; } uint32_t Array::hash() const { - uint32_t h = hash_djb2_one_32(0); for (int i = 0; i < _p->array.size(); i++) { - h = hash_djb2_one_32(_p->array[i].hash(), h); } return h; } void Array::operator=(const Array &p_array) { - _ref(p_array); } void Array::push_back(const Variant &p_value) { - _p->array.push_back(p_value); } void Array::append_array(const Array &p_array) { - _p->array.append_array(p_array._p->array); } Error Array::resize(int p_new_size) { - return _p->array.resize(p_new_size); } void Array::insert(int p_pos, const Variant &p_value) { - _p->array.insert(p_pos, p_value); } void Array::erase(const Variant &p_value) { - _p->array.erase(p_value); } @@ -148,12 +132,10 @@ Variant Array::back() const { } int Array::find(const Variant &p_value, int p_from) const { - return _p->array.find(p_value, p_from); } int Array::rfind(const Variant &p_value, int p_from) const { - if (_p->array.size() == 0) return -1; @@ -167,7 +149,6 @@ int Array::rfind(const Variant &p_value, int p_from) const { } for (int i = p_from; i >= 0; i--) { - if (_p->array[i] == p_value) { return i; } @@ -177,18 +158,15 @@ int Array::rfind(const Variant &p_value, int p_from) const { } int Array::find_last(const Variant &p_value) const { - return rfind(p_value); } int Array::count(const Variant &p_value) const { - if (_p->array.size() == 0) return 0; int amount = 0; for (int i = 0; i < _p->array.size(); i++) { - if (_p->array[i] == p_value) { amount++; } @@ -202,22 +180,18 @@ bool Array::has(const Variant &p_value) const { } void Array::remove(int p_pos) { - _p->array.remove(p_pos); } void Array::set(int p_idx, const Variant &p_value) { - operator[](p_idx) = p_value; } const Variant &Array::get(int p_idx) const { - return operator[](p_idx); } Array Array::duplicate(bool p_deep) const { - Array new_arr; int element_count = size(); new_arr.resize(element_count); @@ -229,7 +203,6 @@ Array Array::duplicate(bool p_deep) const { } int Array::_clamp_slice_index(int p_index) const { - int arr_size = size(); int fixed_index = CLAMP(p_index, -arr_size, arr_size - 1); if (fixed_index < 0) { @@ -278,7 +251,6 @@ Array Array::slice(int p_begin, int p_end, int p_step, bool p_deep) const { // l } struct _ArrayVariantSort { - _FORCE_INLINE_ bool operator()(const Variant &p_l, const Variant &p_r) const { bool valid = false; Variant res; @@ -290,18 +262,15 @@ struct _ArrayVariantSort { }; Array &Array::sort() { - _p->array.sort_custom<_ArrayVariantSort>(); return *this; } struct _ArrayVariantSortCustom { - Object *obj; StringName func; _FORCE_INLINE_ bool operator()(const Variant &p_l, const Variant &p_r) const { - const Variant *args[2] = { &p_l, &p_r }; Variant::CallError err; bool res = obj->call(func, args, 2, err); @@ -311,7 +280,6 @@ struct _ArrayVariantSortCustom { } }; Array &Array::sort_custom(Object *p_obj, const StringName &p_function) { - ERR_FAIL_NULL_V(p_obj, *this); SortArray avs; @@ -322,7 +290,6 @@ Array &Array::sort_custom(Object *p_obj, const StringName &p_function) { } void Array::shuffle() { - const int n = _p->array.size(); if (n < 2) return; @@ -337,7 +304,6 @@ void Array::shuffle() { template _FORCE_INLINE_ int bisect(const Vector &p_array, const Variant &p_value, bool p_before, const Less &p_less) { - int lo = 0; int hi = p_array.size(); if (p_before) { @@ -363,12 +329,10 @@ _FORCE_INLINE_ int bisect(const Vector &p_array, const Variant &p_value } int Array::bsearch(const Variant &p_value, bool p_before) { - return bisect(_p->array, p_value, p_before, _ArrayVariantSort()); } int Array::bsearch_custom(const Variant &p_value, Object *p_obj, const StringName &p_function, bool p_before) { - ERR_FAIL_NULL_V(p_obj, 0); _ArrayVariantSortCustom less; @@ -379,18 +343,15 @@ int Array::bsearch_custom(const Variant &p_value, Object *p_obj, const StringNam } Array &Array::invert() { - _p->array.invert(); return *this; } void Array::push_front(const Variant &p_value) { - _p->array.insert(0, p_value); } Variant Array::pop_back() { - if (!_p->array.empty()) { int n = _p->array.size() - 1; Variant ret = _p->array.get(n); @@ -401,7 +362,6 @@ Variant Array::pop_back() { } Variant Array::pop_front() { - if (!_p->array.empty()) { Variant ret = _p->array.get(0); _p->array.remove(0); @@ -411,7 +371,6 @@ Variant Array::pop_front() { } Variant Array::min() const { - Variant minval; for (int i = 0; i < size(); i++) { if (i == 0) { @@ -434,7 +393,6 @@ Variant Array::min() const { } Variant Array::max() const { - Variant maxval; for (int i = 0; i < size(); i++) { if (i == 0) { @@ -461,17 +419,14 @@ const void *Array::id() const { } Array::Array(const Array &p_from) { - _p = NULL; _ref(p_from); } Array::Array() { - _p = memnew(ArrayPrivate); _p->refcount.init(); } Array::~Array() { - _unref(); } diff --git a/core/array.h b/core/array.h index f7f16f926d4..562568872bf 100644 --- a/core/array.h +++ b/core/array.h @@ -39,7 +39,6 @@ class Object; class StringName; class Array { - mutable ArrayPrivate *_p; void _ref(const Array &p_from) const; void _unref() const; diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index 7c365ff169d..33c77ca0d61 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -69,7 +69,6 @@ Ref _ResourceLoader::load_interactive(const String &p } RES _ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p_no_cache) { - Error err = OK; RES ret = ResourceLoader::load(p_path, p_type_hint, p_no_cache, &err); @@ -78,12 +77,10 @@ RES _ResourceLoader::load(const String &p_path, const String &p_type_hint, bool } PoolVector _ResourceLoader::get_recognized_extensions_for_type(const String &p_type) { - List exts; ResourceLoader::get_recognized_extensions_for_type(p_type, &exts); PoolVector ret; for (List::Element *E = exts.front(); E; E = E->next()) { - ret.push_back(E->get()); } @@ -91,12 +88,10 @@ PoolVector _ResourceLoader::get_recognized_extensions_for_type(const Str } void _ResourceLoader::set_abort_on_missing_resources(bool p_abort) { - ResourceLoader::set_abort_on_missing_resources(p_abort); } PoolStringArray _ResourceLoader::get_dependencies(const String &p_path) { - List deps; ResourceLoader::get_dependencies(p_path, &deps); @@ -116,7 +111,6 @@ bool _ResourceLoader::has(const String &p_path) { #endif // DISABLE_DEPRECATED bool _ResourceLoader::has_cached(const String &p_path) { - String local_path = ProjectSettings::get_singleton()->localize_path(p_path); return ResourceCache::has(local_path); } @@ -126,7 +120,6 @@ bool _ResourceLoader::exists(const String &p_path, const String &p_type_hint) { } void _ResourceLoader::_bind_methods() { - ClassDB::bind_method(D_METHOD("load_interactive", "path", "type_hint"), &_ResourceLoader::load_interactive, DEFVAL("")); ClassDB::bind_method(D_METHOD("load", "path", "type_hint", "no_cache"), &_ResourceLoader::load, DEFVAL(""), DEFVAL(false)); ClassDB::bind_method(D_METHOD("get_recognized_extensions_for_type", "type"), &_ResourceLoader::get_recognized_extensions_for_type); @@ -140,7 +133,6 @@ void _ResourceLoader::_bind_methods() { } _ResourceLoader::_ResourceLoader() { - singleton = this; } @@ -150,13 +142,11 @@ Error _ResourceSaver::save(const String &p_path, const RES &p_resource, SaverFla } PoolVector _ResourceSaver::get_recognized_extensions(const RES &p_resource) { - ERR_FAIL_COND_V_MSG(p_resource.is_null(), PoolVector(), "It's not a reference to a valid Resource object."); List exts; ResourceSaver::get_recognized_extensions(p_resource, &exts); PoolVector ret; for (List::Element *E = exts.front(); E; E = E->next()) { - ret.push_back(E->get()); } return ret; @@ -165,7 +155,6 @@ PoolVector _ResourceSaver::get_recognized_extensions(const RES &p_resour _ResourceSaver *_ResourceSaver::singleton = NULL; void _ResourceSaver::_bind_methods() { - ClassDB::bind_method(D_METHOD("save", "path", "resource", "flags"), &_ResourceSaver::save, DEFVAL(0)); ClassDB::bind_method(D_METHOD("get_recognized_extensions", "type"), &_ResourceSaver::get_recognized_extensions); @@ -179,49 +168,40 @@ void _ResourceSaver::_bind_methods() { } _ResourceSaver::_ResourceSaver() { - singleton = this; } /////////////////OS void _OS::global_menu_add_item(const String &p_menu, const String &p_label, const Variant &p_signal, const Variant &p_meta) { - OS::get_singleton()->global_menu_add_item(p_menu, p_label, p_signal, p_meta); } void _OS::global_menu_add_separator(const String &p_menu) { - OS::get_singleton()->global_menu_add_separator(p_menu); } void _OS::global_menu_remove_item(const String &p_menu, int p_idx) { - OS::get_singleton()->global_menu_remove_item(p_menu, p_idx); } void _OS::global_menu_clear(const String &p_menu) { - OS::get_singleton()->global_menu_clear(p_menu); } Point2 _OS::get_mouse_position() const { - return OS::get_singleton()->get_mouse_position(); } void _OS::set_window_title(const String &p_title) { - OS::get_singleton()->set_window_title(p_title); } void _OS::set_window_mouse_passthrough(const PoolVector2Array &p_region) { - OS::get_singleton()->set_window_mouse_passthrough(p_region); } int _OS::get_mouse_button_state() const { - return OS::get_singleton()->get_mouse_button_state(); } @@ -230,17 +210,14 @@ String _OS::get_unique_id() const { } bool _OS::has_touchscreen_ui_hint() const { - return OS::get_singleton()->has_touchscreen_ui_hint(); } void _OS::set_clipboard(const String &p_text) { - OS::get_singleton()->set_clipboard(p_text); } String _OS::get_clipboard() const { - return OS::get_singleton()->get_clipboard(); } @@ -277,7 +254,6 @@ void _OS::close_midi_inputs() { } void _OS::set_video_mode(const Size2 &p_size, bool p_fullscreen, bool p_resizeable, int p_screen) { - OS::VideoMode vm; vm.width = p_size.width; vm.height = p_size.height; @@ -287,14 +263,12 @@ void _OS::set_video_mode(const Size2 &p_size, bool p_fullscreen, bool p_resizeab } Size2 _OS::get_video_mode(int p_screen) const { - OS::VideoMode vm; vm = OS::get_singleton()->get_video_mode(p_screen); return Size2(vm.width, vm.height); } bool _OS::is_video_mode_fullscreen(int p_screen) const { - OS::VideoMode vm; vm = OS::get_singleton()->get_video_mode(p_screen); return vm.fullscreen; @@ -321,7 +295,6 @@ Size2 _OS::get_screen_size(int p_screen) const { } int _OS::get_screen_dpi(int p_screen) const { - return OS::get_singleton()->get_screen_dpi(p_screen); } @@ -434,12 +407,10 @@ bool _OS::get_borderless_window() const { } void _OS::set_ime_active(const bool p_active) { - OS::get_singleton()->set_ime_active(p_active); } void _OS::set_ime_position(const Point2 &p_pos) { - OS::get_singleton()->set_ime_position(p_pos); } @@ -452,24 +423,20 @@ String _OS::get_ime_text() const { } void _OS::set_use_file_access_save_and_swap(bool p_enable) { - FileAccess::set_backup_save(p_enable); } bool _OS::is_video_mode_resizable(int p_screen) const { - OS::VideoMode vm; vm = OS::get_singleton()->get_video_mode(p_screen); return vm.resizable; } Array _OS::get_fullscreen_mode_list(int p_screen) const { - List vmlist; OS::get_singleton()->get_fullscreen_mode_list(&vmlist, p_screen); Array vmarr; for (List::Element *E = vmlist.front(); E; E = E->next()) { - vmarr.push_back(Size2(E->get().width, E->get().height)); } @@ -477,31 +444,25 @@ Array _OS::get_fullscreen_mode_list(int p_screen) const { } void _OS::set_low_processor_usage_mode(bool p_enabled) { - OS::get_singleton()->set_low_processor_usage_mode(p_enabled); } bool _OS::is_in_low_processor_usage_mode() const { - return OS::get_singleton()->is_in_low_processor_usage_mode(); } void _OS::set_low_processor_usage_mode_sleep_usec(int p_usec) { - OS::get_singleton()->set_low_processor_usage_mode_sleep_usec(p_usec); } int _OS::get_low_processor_usage_mode_sleep_usec() const { - return OS::get_singleton()->get_low_processor_usage_mode_sleep_usec(); } String _OS::get_executable_path() const { - return OS::get_singleton()->get_executable_path(); } Error _OS::shell_open(String p_uri) { - if (p_uri.begins_with("res://")) { WARN_PRINT("Attempting to open an URL with the \"res://\" protocol. Use `ProjectSettings.globalize_path()` to convert a Godot-specific path to a system path before opening it with `OS.shell_open()`."); } else if (p_uri.begins_with("user://")) { @@ -511,7 +472,6 @@ Error _OS::shell_open(String p_uri) { }; int _OS::execute(const String &p_path, const Vector &p_arguments, bool p_blocking, Array p_output, bool p_read_stderr) { - OS::ProcessID pid = -2; int exitcode = 0; List args; @@ -530,39 +490,31 @@ int _OS::execute(const String &p_path, const Vector &p_arguments, bool p } Error _OS::kill(int p_pid) { - return OS::get_singleton()->kill(p_pid); } int _OS::get_process_id() const { - return OS::get_singleton()->get_process_id(); }; bool _OS::has_environment(const String &p_var) const { - return OS::get_singleton()->has_environment(p_var); } String _OS::get_environment(const String &p_var) const { - return OS::get_singleton()->get_environment(p_var); } bool _OS::set_environment(const String &p_var, const String &p_value) const { - return OS::get_singleton()->set_environment(p_var, p_value); } String _OS::get_name() const { - return OS::get_singleton()->get_name(); } Vector _OS::get_cmdline_args() { - List cmdline = OS::get_singleton()->get_cmdline_args(); Vector cmdlinev; for (List::Element *E = cmdline.front(); E; E = E->next()) { - cmdlinev.push_back(E->get()); } @@ -570,7 +522,6 @@ Vector _OS::get_cmdline_args() { } String _OS::get_locale() const { - return OS::get_singleton()->get_locale(); } @@ -616,17 +567,14 @@ String _OS::keyboard_get_layout_name(int p_index) const { } String _OS::get_model_name() const { - return OS::get_singleton()->get_model_name(); } bool _OS::is_ok_left_and_cancel_right() const { - return OS::get_singleton()->get_swap_ok_cancel(); } Error _OS::set_thread_name(const String &p_name) { - return Thread::set_name(p_name); }; @@ -635,7 +583,6 @@ void _OS::set_use_vsync(bool p_enable) { } bool _OS::is_vsync_enabled() const { - return OS::get_singleton()->is_vsync_enabled(); } @@ -644,7 +591,6 @@ void _OS::set_vsync_via_compositor(bool p_enable) { } bool _OS::is_vsync_via_compositor_enabled() const { - return OS::get_singleton()->is_vsync_via_compositor_enabled(); } @@ -665,7 +611,6 @@ Thread::ID _OS::get_thread_caller_id() const { }; bool _OS::has_feature(const String &p_feature) const { - return OS::get_singleton()->has_feature(p_feature); } @@ -714,37 +659,30 @@ struct Time { */ uint64_t _OS::get_static_memory_usage() const { - return OS::get_singleton()->get_static_memory_usage(); } uint64_t _OS::get_static_memory_peak_usage() const { - return OS::get_singleton()->get_static_memory_peak_usage(); } uint64_t _OS::get_dynamic_memory_usage() const { - return OS::get_singleton()->get_dynamic_memory_usage(); } void _OS::set_native_icon(const String &p_filename) { - OS::get_singleton()->set_native_icon(p_filename); } void _OS::set_icon(const Ref &p_icon) { - OS::get_singleton()->set_icon(p_icon); } int _OS::get_exit_code() const { - return OS::get_singleton()->get_exit_code(); } void _OS::set_exit_code(int p_code) { - if (p_code < 0 || p_code > 125) { WARN_PRINT("For portability reasons, the exit code should be set between 0 and 125 (inclusive)."); } @@ -757,7 +695,6 @@ void _OS::set_exit_code(int p_code) { * dst */ Dictionary _OS::get_datetime(bool utc) const { - Dictionary dated = get_date(utc); Dictionary timed = get_time(utc); @@ -772,7 +709,6 @@ Dictionary _OS::get_datetime(bool utc) const { } Dictionary _OS::get_date(bool utc) const { - OS::Date date = OS::get_singleton()->get_date(utc); Dictionary dated; dated[YEAR_KEY] = date.year; @@ -784,7 +720,6 @@ Dictionary _OS::get_date(bool utc) const { } Dictionary _OS::get_time(bool utc) const { - OS::Time time = OS::get_singleton()->get_time(utc); Dictionary timed; timed[HOUR_KEY] = time.hour; @@ -881,7 +816,6 @@ int64_t _OS::get_unix_time_from_datetime(Dictionary datetime) const { * @return dictionary of date and time values */ Dictionary _OS::get_datetime_from_unix_time(int64_t unix_time_val) const { - OS::Date date; OS::Time time; @@ -945,7 +879,6 @@ Dictionary _OS::get_time_zone_info() const { } uint64_t _OS::get_unix_time() const { - return OS::get_singleton()->get_unix_time(); } @@ -974,52 +907,42 @@ void _OS::delay_msec(int p_msec) const { } uint32_t _OS::get_ticks_msec() const { - return OS::get_singleton()->get_ticks_msec(); } uint64_t _OS::get_ticks_usec() const { - return OS::get_singleton()->get_ticks_usec(); } uint32_t _OS::get_splash_tick_msec() const { - return OS::get_singleton()->get_splash_tick_msec(); } bool _OS::can_use_threads() const { - return OS::get_singleton()->can_use_threads(); } bool _OS::can_draw() const { - return OS::get_singleton()->can_draw(); } bool _OS::is_userfs_persistent() const { - return OS::get_singleton()->is_userfs_persistent(); } int _OS::get_processor_count() const { - return OS::get_singleton()->get_processor_count(); } bool _OS::is_stdout_verbose() const { - return OS::get_singleton()->is_stdout_verbose(); } void _OS::dump_memory_to_file(const String &p_file) { - OS::get_singleton()->dump_memory_to_file(p_file.utf8().get_data()); } struct _OSCoreBindImg { - String path; Size2 size; int fmt; @@ -1029,7 +952,6 @@ struct _OSCoreBindImg { }; void _OS::print_all_textures_by_size() { - List<_OSCoreBindImg> imgs; uint64_t total = 0; { @@ -1037,7 +959,6 @@ 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")) continue; @@ -1058,20 +979,17 @@ void _OS::print_all_textures_by_size() { imgs.sort(); for (List<_OSCoreBindImg>::Element *E = imgs.front(); E; E = E->next()) { - total -= E->get().vram; } } void _OS::print_resources_by_type(const Vector &p_types) { - Map type_count; List> resources; ResourceCache::get_cached_resources(&resources); for (List>::Element *E = resources.front(); E; E = E->next()) { - Ref r = E->get(); bool found = false; @@ -1108,37 +1026,30 @@ int _OS::get_virtual_keyboard_height() { } void _OS::print_all_resources(const String &p_to_file) { - OS::get_singleton()->print_all_resources(p_to_file); } void _OS::print_resources_in_use(bool p_short) { - OS::get_singleton()->print_resources_in_use(p_short); } void _OS::dump_resources_to_file(const String &p_file) { - OS::get_singleton()->dump_resources_to_file(p_file.utf8().get_data()); } String _OS::get_user_data_dir() const { - return OS::get_singleton()->get_user_data_dir(); }; Error _OS::native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track) { - return OS::get_singleton()->native_video_play(p_path, p_volume, p_audio_track, p_subtitle_track); }; bool _OS::native_video_is_playing() { - return OS::get_singleton()->native_video_is_playing(); }; void _OS::native_video_pause() { - OS::get_singleton()->native_video_pause(); }; @@ -1147,32 +1058,26 @@ void _OS::native_video_unpause() { }; void _OS::native_video_stop() { - OS::get_singleton()->native_video_stop(); }; void _OS::request_attention() { - OS::get_singleton()->request_attention(); } void _OS::center_window() { - OS::get_singleton()->center_window(); } void _OS::move_window_to_foreground() { - OS::get_singleton()->move_window_to_foreground(); } int64_t _OS::get_native_handle(HandleType p_handle_type) { - return (int64_t)OS::get_singleton()->get_native_handle(p_handle_type); } bool _OS::is_debug_build() const { - #ifdef DEBUG_ENABLED return true; #else @@ -1181,60 +1086,48 @@ bool _OS::is_debug_build() const { } void _OS::set_screen_orientation(ScreenOrientation p_orientation) { - OS::get_singleton()->set_screen_orientation(OS::ScreenOrientation(p_orientation)); } _OS::ScreenOrientation _OS::get_screen_orientation() const { - return ScreenOrientation(OS::get_singleton()->get_screen_orientation()); } void _OS::set_keep_screen_on(bool p_enabled) { - OS::get_singleton()->set_keep_screen_on(p_enabled); } bool _OS::is_keep_screen_on() const { - return OS::get_singleton()->is_keep_screen_on(); } String _OS::get_system_dir(SystemDir p_dir) const { - return OS::get_singleton()->get_system_dir(OS::SystemDir(p_dir)); } String _OS::get_scancode_string(uint32_t p_code) const { - return keycode_get_string(p_code); } bool _OS::is_scancode_unicode(uint32_t p_unicode) const { - return keycode_has_unicode(p_unicode); } int _OS::find_scancode_from_string(const String &p_code) const { - return find_keycode(p_code); } void _OS::alert(const String &p_alert, const String &p_title) { - OS::get_singleton()->alert(p_alert, p_title); } bool _OS::request_permission(const String &p_name) { - return OS::get_singleton()->request_permission(p_name); } bool _OS::request_permissions() { - return OS::get_singleton()->request_permissions(); } Vector _OS::get_granted_permissions() const { - return OS::get_singleton()->get_granted_permissions(); } @@ -1257,7 +1150,6 @@ void _OS::set_current_tablet_driver(const String &p_driver) { _OS *_OS::singleton = NULL; void _OS::_bind_methods() { - //ClassDB::bind_method(D_METHOD("get_mouse_position"),&_OS::get_mouse_position); //ClassDB::bind_method(D_METHOD("is_mouse_grab_enabled"),&_OS::is_mouse_grab_enabled); @@ -1565,7 +1457,6 @@ void _OS::_bind_methods() { } _OS::_OS() { - singleton = this; } @@ -1574,39 +1465,31 @@ _OS::_OS() { _Geometry *_Geometry::singleton = NULL; _Geometry *_Geometry::get_singleton() { - return singleton; } PoolVector _Geometry::build_box_planes(const Vector3 &p_extents) { - return Geometry::build_box_planes(p_extents); } PoolVector _Geometry::build_cylinder_planes(float p_radius, float p_height, int p_sides, Vector3::Axis p_axis) { - return Geometry::build_cylinder_planes(p_radius, p_height, p_sides, p_axis); } PoolVector _Geometry::build_capsule_planes(float p_radius, float p_height, int p_sides, int p_lats, Vector3::Axis p_axis) { - return Geometry::build_capsule_planes(p_radius, p_height, p_sides, p_lats, p_axis); } bool _Geometry::is_point_in_circle(const Vector2 &p_point, const Vector2 &p_circle_pos, real_t p_circle_radius) { - return Geometry::is_point_in_circle(p_point, p_circle_pos, p_circle_radius); } real_t _Geometry::segment_intersects_circle(const Vector2 &p_from, const Vector2 &p_to, const Vector2 &p_circle_pos, real_t p_circle_radius) { - return Geometry::segment_intersects_circle(p_from, p_to, p_circle_pos, p_circle_radius); } Variant _Geometry::segment_intersects_segment_2d(const Vector2 &p_from_a, const Vector2 &p_to_a, const Vector2 &p_from_b, const Vector2 &p_to_b) { - Vector2 result; if (Geometry::segment_intersects_segment_2d(p_from_a, p_to_a, p_from_b, p_to_b, &result)) { - return result; } else { return Variant(); @@ -1614,7 +1497,6 @@ Variant _Geometry::segment_intersects_segment_2d(const Vector2 &p_from_a, const }; Variant _Geometry::line_intersects_line_2d(const Vector2 &p_from_a, const Vector2 &p_dir_a, const Vector2 &p_from_b, const Vector2 &p_dir_b) { - Vector2 result; if (Geometry::line_intersects_line_2d(p_from_a, p_dir_a, p_from_b, p_dir_b, result)) { return result; @@ -1624,7 +1506,6 @@ Variant _Geometry::line_intersects_line_2d(const Vector2 &p_from_a, const Vector } PoolVector _Geometry::get_closest_points_between_segments_2d(const Vector2 &p1, const Vector2 &q1, const Vector2 &p2, const Vector2 &q2) { - Vector2 r1, r2; Geometry::get_closest_points_between_segments(p1, q1, p2, q2, r1, r2); PoolVector r; @@ -1635,7 +1516,6 @@ PoolVector _Geometry::get_closest_points_between_segments_2d(const Vect } PoolVector _Geometry::get_closest_points_between_segments(const Vector3 &p1, const Vector3 &p2, const Vector3 &q1, const Vector3 &q2) { - Vector3 r1, r2; Geometry::get_closest_points_between_segments(p1, p2, q1, q2, r1, r2); PoolVector r; @@ -1645,27 +1525,22 @@ PoolVector _Geometry::get_closest_points_between_segments(const Vector3 return r; } Vector2 _Geometry::get_closest_point_to_segment_2d(const Vector2 &p_point, const Vector2 &p_a, const Vector2 &p_b) { - Vector2 s[2] = { p_a, p_b }; return Geometry::get_closest_point_to_segment_2d(p_point, s); } Vector3 _Geometry::get_closest_point_to_segment(const Vector3 &p_point, const Vector3 &p_a, const Vector3 &p_b) { - Vector3 s[2] = { p_a, p_b }; return Geometry::get_closest_point_to_segment(p_point, s); } Vector2 _Geometry::get_closest_point_to_segment_uncapped_2d(const Vector2 &p_point, const Vector2 &p_a, const Vector2 &p_b) { - Vector2 s[2] = { p_a, p_b }; return Geometry::get_closest_point_to_segment_uncapped_2d(p_point, s); } Vector3 _Geometry::get_closest_point_to_segment_uncapped(const Vector3 &p_point, const Vector3 &p_a, const Vector3 &p_b) { - Vector3 s[2] = { p_a, p_b }; return Geometry::get_closest_point_to_segment_uncapped(p_point, s); } 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)) return res; @@ -1673,7 +1548,6 @@ Variant _Geometry::ray_intersects_triangle(const Vector3 &p_from, const Vector3 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)) return res; @@ -1682,12 +1556,10 @@ Variant _Geometry::segment_intersects_triangle(const Vector3 &p_from, const Vect } bool _Geometry::point_is_inside_triangle(const Vector2 &s, const Vector2 &a, const Vector2 &b, const Vector2 &c) const { - return Geometry::is_point_in_triangle(s, a, b, c); } PoolVector _Geometry::segment_intersects_sphere(const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_sphere_pos, real_t p_sphere_radius) { - PoolVector r; Vector3 res, norm; if (!Geometry::segment_intersects_sphere(p_from, p_to, p_sphere_pos, p_sphere_radius, &res, &norm)) @@ -1699,7 +1571,6 @@ PoolVector _Geometry::segment_intersects_sphere(const Vector3 &p_from, return r; } PoolVector _Geometry::segment_intersects_cylinder(const Vector3 &p_from, const Vector3 &p_to, float p_height, float p_radius) { - PoolVector r; Vector3 res, norm; if (!Geometry::segment_intersects_cylinder(p_from, p_to, p_height, p_radius, &res, &norm)) @@ -1711,7 +1582,6 @@ PoolVector _Geometry::segment_intersects_cylinder(const Vector3 &p_from return r; } PoolVector _Geometry::segment_intersects_convex(const Vector3 &p_from, const Vector3 &p_to, const Vector &p_planes) { - PoolVector r; Vector3 res, norm; if (!Geometry::segment_intersects_convex(p_from, p_to, p_planes.ptr(), p_planes.size(), &res, &norm)) @@ -1724,37 +1594,30 @@ PoolVector _Geometry::segment_intersects_convex(const Vector3 &p_from, } bool _Geometry::is_polygon_clockwise(const Vector &p_polygon) { - return Geometry::is_polygon_clockwise(p_polygon); } bool _Geometry::is_point_in_polygon(const Point2 &p_point, const Vector &p_polygon) { - return Geometry::is_point_in_polygon(p_point, p_polygon); } Vector _Geometry::triangulate_polygon(const Vector &p_polygon) { - return Geometry::triangulate_polygon(p_polygon); } Vector _Geometry::triangulate_delaunay_2d(const Vector &p_points) { - return Geometry::triangulate_delaunay_2d(p_points); } Vector _Geometry::convex_hull_2d(const Vector &p_points) { - return Geometry::convex_hull_2d(p_points); } Vector _Geometry::clip_polygon(const Vector &p_points, const Plane &p_plane) { - return Geometry::clip_polygon(p_points, p_plane); } Array _Geometry::merge_polygons_2d(const Vector &p_polygon_a, const Vector &p_polygon_b) { - Vector> polys = Geometry::merge_polygons_2d(p_polygon_a, p_polygon_b); Array ret; @@ -1766,7 +1629,6 @@ Array _Geometry::merge_polygons_2d(const Vector &p_polygon_a, const Vec } Array _Geometry::clip_polygons_2d(const Vector &p_polygon_a, const Vector &p_polygon_b) { - Vector> polys = Geometry::clip_polygons_2d(p_polygon_a, p_polygon_b); Array ret; @@ -1778,7 +1640,6 @@ Array _Geometry::clip_polygons_2d(const Vector &p_polygon_a, const Vect } Array _Geometry::intersect_polygons_2d(const Vector &p_polygon_a, const Vector &p_polygon_b) { - Vector> polys = Geometry::intersect_polygons_2d(p_polygon_a, p_polygon_b); Array ret; @@ -1790,7 +1651,6 @@ Array _Geometry::intersect_polygons_2d(const Vector &p_polygon_a, const } Array _Geometry::exclude_polygons_2d(const Vector &p_polygon_a, const Vector &p_polygon_b) { - Vector> polys = Geometry::exclude_polygons_2d(p_polygon_a, p_polygon_b); Array ret; @@ -1802,7 +1662,6 @@ Array _Geometry::exclude_polygons_2d(const Vector &p_polygon_a, const V } Array _Geometry::clip_polyline_with_polygon_2d(const Vector &p_polyline, const Vector &p_polygon) { - Vector> polys = Geometry::clip_polyline_with_polygon_2d(p_polyline, p_polygon); Array ret; @@ -1814,7 +1673,6 @@ Array _Geometry::clip_polyline_with_polygon_2d(const Vector &p_polyline } Array _Geometry::intersect_polyline_with_polygon_2d(const Vector &p_polyline, const Vector &p_polygon) { - Vector> polys = Geometry::intersect_polyline_with_polygon_2d(p_polyline, p_polygon); Array ret; @@ -1826,7 +1684,6 @@ Array _Geometry::intersect_polyline_with_polygon_2d(const Vector &p_pol } Array _Geometry::offset_polygon_2d(const Vector &p_polygon, real_t p_delta, PolyJoinType p_join_type) { - Vector> polys = Geometry::offset_polygon_2d(p_polygon, p_delta, Geometry::PolyJoinType(p_join_type)); Array ret; @@ -1838,7 +1695,6 @@ Array _Geometry::offset_polygon_2d(const Vector &p_polygon, real_t p_de } Array _Geometry::offset_polyline_2d(const Vector &p_polygon, real_t p_delta, PolyJoinType p_join_type, PolyEndType p_end_type) { - Vector> polys = Geometry::offset_polyline_2d(p_polygon, p_delta, Geometry::PolyJoinType(p_join_type), Geometry::PolyEndType(p_end_type)); Array ret; @@ -1850,12 +1706,10 @@ Array _Geometry::offset_polyline_2d(const Vector &p_polygon, real_t p_d } Dictionary _Geometry::make_atlas(const Vector &p_rects) { - Dictionary ret; Vector rects; for (int i = 0; i < p_rects.size(); i++) { - rects.push_back(p_rects[i]); }; @@ -1867,7 +1721,6 @@ Dictionary _Geometry::make_atlas(const Vector &p_rects) { Size2 r_size = size; Vector r_result; for (int i = 0; i < result.size(); i++) { - r_result.push_back(result[i]); }; @@ -1878,12 +1731,10 @@ Dictionary _Geometry::make_atlas(const Vector &p_rects) { }; int _Geometry::get_uv84_normal_bit(const Vector3 &p_vector) { - return Geometry::get_uv84_normal_bit(p_vector); } void _Geometry::_bind_methods() { - ClassDB::bind_method(D_METHOD("build_box_planes", "extents"), &_Geometry::build_box_planes); ClassDB::bind_method(D_METHOD("build_cylinder_planes", "radius", "height", "sides", "axis"), &_Geometry::build_cylinder_planes, DEFVAL(Vector3::AXIS_Z)); ClassDB::bind_method(D_METHOD("build_capsule_planes", "radius", "height", "sides", "lats", "axis"), &_Geometry::build_capsule_planes, DEFVAL(Vector3::AXIS_Z)); @@ -1953,7 +1804,6 @@ _Geometry::_Geometry() { ///////////////////////// FILE 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) return err; @@ -1970,7 +1820,6 @@ 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) return err; @@ -1988,7 +1837,6 @@ Error _File::open_encrypted_pass(const String &p_path, ModeFlags p_mode_flags, c } Error _File::open_compressed(const String &p_path, ModeFlags p_mode_flags, CompressionMode p_compress_mode) { - FileAccessCompressed *fac = memnew(FileAccessCompressed); fac->configure("GCPF", (Compression::Mode)p_compress_mode); @@ -2005,7 +1853,6 @@ Error _File::open_compressed(const String &p_path, ModeFlags p_mode_flags, Compr } Error _File::open(const String &p_path, ModeFlags p_mode_flags) { - close(); Error err; f = FileAccess::open(p_path, p_mode_flags, &err); @@ -2020,94 +1867,77 @@ void _File::flush() { } void _File::close() { - if (f) memdelete(f); f = NULL; } bool _File::is_open() const { - return f != NULL; } String _File::get_path() const { - ERR_FAIL_COND_V_MSG(!f, "", "File must be opened before use."); return f->get_path(); } String _File::get_path_absolute() const { - ERR_FAIL_COND_V_MSG(!f, "", "File must be opened before use."); return f->get_path_absolute(); } void _File::seek(int64_t p_position) { - ERR_FAIL_COND_MSG(!f, "File must be opened before use."); f->seek(p_position); } void _File::seek_end(int64_t p_position) { - ERR_FAIL_COND_MSG(!f, "File must be opened before use."); f->seek_end(p_position); } int64_t _File::get_position() const { - ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use."); return f->get_position(); } int64_t _File::get_len() const { - ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use."); return f->get_len(); } bool _File::eof_reached() const { - ERR_FAIL_COND_V_MSG(!f, false, "File must be opened before use."); return f->eof_reached(); } uint8_t _File::get_8() const { - ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use."); return f->get_8(); } uint16_t _File::get_16() const { - ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use."); return f->get_16(); } uint32_t _File::get_32() const { - ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use."); return f->get_32(); } uint64_t _File::get_64() const { - ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use."); return f->get_64(); } float _File::get_float() const { - ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use."); return f->get_float(); } double _File::get_double() const { - ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use."); return f->get_double(); } real_t _File::get_real() const { - ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use."); return f->get_real(); } PoolVector _File::get_buffer(int p_length) const { - PoolVector data; ERR_FAIL_COND_V_MSG(!f, data, "File must be opened before use."); @@ -2131,7 +1961,6 @@ PoolVector _File::get_buffer(int p_length) const { } String _File::get_as_text() const { - ERR_FAIL_COND_V_MSG(!f, String(), "File must be opened before use."); String text; @@ -2151,17 +1980,14 @@ String _File::get_as_text() const { } String _File::get_md5(const String &p_path) const { - return FileAccess::get_md5(p_path); } String _File::get_sha256(const String &p_path) const { - return FileAccess::get_sha256(p_path); } String _File::get_line() const { - ERR_FAIL_COND_V_MSG(!f, String(), "File must be opened before use."); return f->get_line(); } @@ -2177,90 +2003,76 @@ Vector _File::get_csv_line(const String &p_delim) const { */ void _File::set_endian_swap(bool p_swap) { - eswap = p_swap; if (f) f->set_endian_swap(p_swap); } bool _File::get_endian_swap() { - return eswap; } Error _File::get_error() const { - if (!f) return ERR_UNCONFIGURED; return f->get_error(); } void _File::store_8(uint8_t p_dest) { - ERR_FAIL_COND_MSG(!f, "File must be opened before use."); f->store_8(p_dest); } void _File::store_16(uint16_t p_dest) { - ERR_FAIL_COND_MSG(!f, "File must be opened before use."); f->store_16(p_dest); } void _File::store_32(uint32_t p_dest) { - ERR_FAIL_COND_MSG(!f, "File must be opened before use."); f->store_32(p_dest); } void _File::store_64(uint64_t p_dest) { - ERR_FAIL_COND_MSG(!f, "File must be opened before use."); f->store_64(p_dest); } void _File::store_float(float p_dest) { - ERR_FAIL_COND_MSG(!f, "File must be opened before use."); f->store_float(p_dest); } void _File::store_double(double p_dest) { - ERR_FAIL_COND_MSG(!f, "File must be opened before use."); f->store_double(p_dest); } void _File::store_real(real_t p_real) { - ERR_FAIL_COND_MSG(!f, "File must be opened before use."); f->store_real(p_real); } void _File::store_string(const String &p_string) { - ERR_FAIL_COND_MSG(!f, "File must be opened before use."); f->store_string(p_string); } void _File::store_pascal_string(const String &p_string) { - ERR_FAIL_COND_MSG(!f, "File must be opened before use."); f->store_pascal_string(p_string); }; String _File::get_pascal_string() { - ERR_FAIL_COND_V_MSG(!f, "", "File must be opened before use."); return f->get_pascal_string(); }; void _File::store_line(const String &p_string) { - ERR_FAIL_COND_MSG(!f, "File must be opened before use."); f->store_line(p_string); } @@ -2271,7 +2083,6 @@ void _File::store_csv_line(const Vector &p_values, const String &p_delim } void _File::store_buffer(const PoolVector &p_buffer) { - ERR_FAIL_COND_MSG(!f, "File must be opened before use."); int len = p_buffer.size(); @@ -2284,12 +2095,10 @@ void _File::store_buffer(const PoolVector &p_buffer) { } bool _File::file_exists(const String &p_name) const { - return FileAccess::exists(p_name); } void _File::store_var(const Variant &p_var, bool p_full_objects) { - ERR_FAIL_COND_MSG(!f, "File must be opened before use."); int len; Error err = encode_variant(p_var, NULL, len, p_full_objects); @@ -2308,7 +2117,6 @@ void _File::store_var(const Variant &p_var, bool p_full_objects) { } Variant _File::get_var(bool p_allow_objects) const { - ERR_FAIL_COND_V_MSG(!f, Variant(), "File must be opened before use."); uint32_t len = get_32(); PoolVector buff = get_buffer(len); @@ -2324,12 +2132,10 @@ Variant _File::get_var(bool p_allow_objects) const { } uint64_t _File::get_modified_time(const String &p_file) const { - return FileAccess::get_modified_time(p_file); } void _File::_bind_methods() { - ClassDB::bind_method(D_METHOD("open_encrypted", "path", "mode_flags", "key"), &_File::open_encrypted); ClassDB::bind_method(D_METHOD("open_encrypted_with_pass", "path", "mode_flags", "pass"), &_File::open_encrypted_pass); ClassDB::bind_method(D_METHOD("open_compressed", "path", "mode_flags", "compression_mode"), &_File::open_compressed, DEFVAL(0)); @@ -2396,13 +2202,11 @@ void _File::_bind_methods() { } _File::_File() { - f = NULL; eswap = false; } _File::~_File() { - if (f) memdelete(f); } @@ -2423,7 +2227,6 @@ Error _Directory::open(const String &p_path) { } Error _Directory::list_dir_begin(bool p_skip_navigational, bool p_skip_hidden) { - ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory must be opened before use."); _list_skip_navigational = p_skip_navigational; @@ -2433,35 +2236,29 @@ Error _Directory::list_dir_begin(bool p_skip_navigational, bool p_skip_hidden) { } String _Directory::get_next() { - ERR_FAIL_COND_V_MSG(!d, "", "Directory must be opened before use."); String next = d->get_next(); while (next != "" && ((_list_skip_navigational && (next == "." || next == "..")) || (_list_skip_hidden && d->current_is_hidden()))) { - next = d->get_next(); } return next; } bool _Directory::current_is_dir() const { - ERR_FAIL_COND_V_MSG(!d, false, "Directory must be opened before use."); return d->current_is_dir(); } void _Directory::list_dir_end() { - ERR_FAIL_COND_MSG(!d, "Directory must be opened before use."); d->list_dir_end(); } int _Directory::get_drive_count() { - ERR_FAIL_COND_V_MSG(!d, 0, "Directory must be opened before use."); return d->get_drive_count(); } String _Directory::get_drive(int p_drive) { - ERR_FAIL_COND_V_MSG(!d, "", "Directory must be opened before use."); return d->get_drive(p_drive); } @@ -2471,17 +2268,14 @@ int _Directory::get_current_drive() { } Error _Directory::change_dir(String p_dir) { - ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory must be opened before use."); return d->change_dir(p_dir); } String _Directory::get_current_dir() { - ERR_FAIL_COND_V_MSG(!d, "", "Directory must be opened before use."); return d->get_current_dir(); } Error _Directory::make_dir(String p_dir) { - ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory must be opened before use."); if (!p_dir.is_rel_path()) { DirAccess *d = DirAccess::create_for_path(p_dir); @@ -2492,7 +2286,6 @@ Error _Directory::make_dir(String p_dir) { return d->make_dir(p_dir); } Error _Directory::make_dir_recursive(String p_dir) { - ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory must be opened before use."); if (!p_dir.is_rel_path()) { DirAccess *d = DirAccess::create_for_path(p_dir); @@ -2504,7 +2297,6 @@ Error _Directory::make_dir_recursive(String p_dir) { } bool _Directory::file_exists(String p_file) { - ERR_FAIL_COND_V_MSG(!d, false, "Directory must be opened before use."); if (!p_file.is_rel_path()) { @@ -2517,7 +2309,6 @@ bool _Directory::file_exists(String p_file) { bool _Directory::dir_exists(String p_dir) { ERR_FAIL_COND_V_MSG(!d, false, "Directory must be opened before use."); if (!p_dir.is_rel_path()) { - DirAccess *d = DirAccess::create_for_path(p_dir); bool exists = d->dir_exists(p_dir); memdelete(d); @@ -2529,18 +2320,15 @@ bool _Directory::dir_exists(String p_dir) { } int _Directory::get_space_left() { - ERR_FAIL_COND_V_MSG(!d, 0, "Directory must be opened before use."); return d->get_space_left() / 1024 * 1024; //return value in megabytes, given binding is int } Error _Directory::copy(String p_from, String p_to) { - ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory must be opened before use."); return d->copy(p_from, p_to); } Error _Directory::rename(String p_from, String p_to) { - ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory must be opened before use."); if (!p_from.is_rel_path()) { DirAccess *d = DirAccess::create_for_path(p_from); @@ -2554,7 +2342,6 @@ Error _Directory::rename(String p_from, String p_to) { return d->rename(p_from, p_to); } Error _Directory::remove(String p_name) { - ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory must be opened before use."); if (!p_name.is_rel_path()) { DirAccess *d = DirAccess::create_for_path(p_name); @@ -2567,7 +2354,6 @@ Error _Directory::remove(String p_name) { } void _Directory::_bind_methods() { - ClassDB::bind_method(D_METHOD("open", "path"), &_Directory::open); ClassDB::bind_method(D_METHOD("list_dir_begin", "skip_navigational", "skip_hidden"), &_Directory::list_dir_begin, DEFVAL(false), DEFVAL(false)); ClassDB::bind_method(D_METHOD("get_next"), &_Directory::get_next); @@ -2590,12 +2376,10 @@ void _Directory::_bind_methods() { } _Directory::_Directory() { - d = DirAccess::create(DirAccess::ACCESS_RESOURCES); } _Directory::~_Directory() { - if (d) memdelete(d); } @@ -2607,7 +2391,6 @@ _Marshalls *_Marshalls::get_singleton() { } String _Marshalls::variant_to_base64(const Variant &p_var, bool p_full_objects) { - int len; Error err = encode_variant(p_var, NULL, len, p_full_objects); ERR_FAIL_COND_V_MSG(err != OK, "", "Error when trying to encode Variant."); @@ -2626,7 +2409,6 @@ String _Marshalls::variant_to_base64(const Variant &p_var, bool p_full_objects) }; Variant _Marshalls::base64_to_variant(const String &p_str, bool p_allow_objects) { - int strlen = p_str.length(); CharString cstr = p_str.ascii(); @@ -2645,14 +2427,12 @@ Variant _Marshalls::base64_to_variant(const String &p_str, bool p_allow_objects) }; String _Marshalls::raw_to_base64(const PoolVector &p_arr) { - String ret = CryptoCore::b64_encode_str(p_arr.read().ptr(), p_arr.size()); ERR_FAIL_COND_V(ret == "", ret); return ret; }; PoolVector _Marshalls::base64_to_raw(const String &p_str) { - int strlen = p_str.length(); CharString cstr = p_str.ascii(); @@ -2670,7 +2450,6 @@ PoolVector _Marshalls::base64_to_raw(const String &p_str) { }; String _Marshalls::utf8_to_base64(const String &p_str) { - CharString cstr = p_str.utf8(); String ret = CryptoCore::b64_encode_str((unsigned char *)cstr.get_data(), cstr.length()); ERR_FAIL_COND_V(ret == "", ret); @@ -2678,7 +2457,6 @@ String _Marshalls::utf8_to_base64(const String &p_str) { }; String _Marshalls::base64_to_utf8(const String &p_str) { - int strlen = p_str.length(); CharString cstr = p_str.ascii(); @@ -2696,7 +2474,6 @@ String _Marshalls::base64_to_utf8(const String &p_str) { }; void _Marshalls::_bind_methods() { - ClassDB::bind_method(D_METHOD("variant_to_base64", "variant", "full_objects"), &_Marshalls::variant_to_base64, DEFVAL(false)); ClassDB::bind_method(D_METHOD("base64_to_variant", "base64_str", "allow_objects"), &_Marshalls::base64_to_variant, DEFVAL(false)); @@ -2710,19 +2487,16 @@ void _Marshalls::_bind_methods() { //////////////// Error _Semaphore::wait() { - semaphore.wait(); return OK; // Can't fail anymore; keep compat } Error _Semaphore::post() { - semaphore.post(); return OK; // Can't fail anymore; keep compat } void _Semaphore::_bind_methods() { - ClassDB::bind_method(D_METHOD("wait"), &_Semaphore::wait); ClassDB::bind_method(D_METHOD("post"), &_Semaphore::post); } @@ -2730,22 +2504,18 @@ void _Semaphore::_bind_methods() { /////////////// void _Mutex::lock() { - mutex.lock(); } Error _Mutex::try_lock() { - return mutex.try_lock(); } void _Mutex::unlock() { - mutex.unlock(); } void _Mutex::_bind_methods() { - ClassDB::bind_method(D_METHOD("lock"), &_Mutex::lock); ClassDB::bind_method(D_METHOD("try_lock"), &_Mutex::try_lock); ClassDB::bind_method(D_METHOD("unlock"), &_Mutex::unlock); @@ -2754,7 +2524,6 @@ void _Mutex::_bind_methods() { /////////////// void _Thread::_start_func(void *ud) { - Ref<_Thread> *tud = (Ref<_Thread> *)ud; Ref<_Thread> t = *tud; memdelete(tud); @@ -2765,23 +2534,18 @@ void _Thread::_start_func(void *ud) { t->ret = t->target_instance->call(t->target_method, arg, 1, ce); if (ce.error != Variant::CallError::CALL_OK) { - String reason; switch (ce.error) { case Variant::CallError::CALL_ERROR_INVALID_ARGUMENT: { - reason = "Invalid Argument #" + itos(ce.argument); } break; case Variant::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS: { - reason = "Too Many Arguments"; } break; case Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS: { - reason = "Too Few Arguments"; } break; case Variant::CallError::CALL_ERROR_INVALID_METHOD: { - reason = "Method Not Found"; } break; default: { @@ -2793,7 +2557,6 @@ void _Thread::_start_func(void *ud) { } Error _Thread::start(Object *p_instance, const StringName &p_method, const Variant &p_userdata, Priority p_priority) { - ERR_FAIL_COND_V_MSG(active.is_set(), ERR_ALREADY_IN_USE, "Thread already started."); ERR_FAIL_COND_V(!p_instance, ERR_INVALID_PARAMETER); ERR_FAIL_COND_V(p_method == StringName(), ERR_INVALID_PARAMETER); @@ -2815,16 +2578,13 @@ Error _Thread::start(Object *p_instance, const StringName &p_method, const Varia } String _Thread::get_id() const { - return itos(thread.get_id()); } bool _Thread::is_active() const { - return active.is_set(); } Variant _Thread::wait_to_finish() { - ERR_FAIL_COND_V_MSG(!active.is_set(), Variant(), "Thread must be active to wait for its completion."); thread.wait_to_finish(); Variant r = ret; @@ -2837,7 +2597,6 @@ Variant _Thread::wait_to_finish() { } void _Thread::_bind_methods() { - ClassDB::bind_method(D_METHOD("start", "instance", "method", "userdata", "priority"), &_Thread::start, DEFVAL(Variant()), DEFVAL(PRIORITY_NORMAL)); ClassDB::bind_method(D_METHOD("get_id"), &_Thread::get_id); ClassDB::bind_method(D_METHOD("is_active"), &_Thread::is_active); @@ -2848,19 +2607,16 @@ void _Thread::_bind_methods() { BIND_ENUM_CONSTANT(PRIORITY_HIGH); } _Thread::_Thread() { - target_instance = NULL; } _Thread::~_Thread() { - ERR_FAIL_COND_MSG(active.is_set(), "Reference to a Thread object was lost while the thread is still running..."); } ///////////////////////////////////// PoolStringArray _ClassDB::get_class_list() const { - List classes; ClassDB::get_class_list(&classes); @@ -2874,7 +2630,6 @@ PoolStringArray _ClassDB::get_class_list() const { return ret; } PoolStringArray _ClassDB::get_inheriters_from_class(const StringName &p_class) const { - List classes; ClassDB::get_inheriters_from_class(p_class, &classes); @@ -2888,23 +2643,18 @@ PoolStringArray _ClassDB::get_inheriters_from_class(const StringName &p_class) c return ret; } StringName _ClassDB::get_parent_class(const StringName &p_class) const { - return ClassDB::get_parent_class(p_class); } bool _ClassDB::class_exists(const StringName &p_class) const { - return ClassDB::class_exists(p_class); } bool _ClassDB::is_parent_class(const StringName &p_class, const StringName &p_inherits) const { - return ClassDB::is_parent_class(p_class, p_inherits); } bool _ClassDB::can_instance(const StringName &p_class) const { - return ClassDB::can_instance(p_class); } Variant _ClassDB::instance(const StringName &p_class) const { - Object *obj = ClassDB::instance(p_class); if (!obj) return Variant(); @@ -2918,11 +2668,9 @@ Variant _ClassDB::instance(const StringName &p_class) const { } bool _ClassDB::has_signal(StringName p_class, StringName p_signal) const { - return ClassDB::has_signal(p_class, p_signal); } Dictionary _ClassDB::get_signal(StringName p_class, StringName p_signal) const { - MethodInfo signal; if (ClassDB::get_signal(p_class, p_signal, &signal)) { return signal.operator Dictionary(); @@ -2931,7 +2679,6 @@ Dictionary _ClassDB::get_signal(StringName p_class, StringName p_signal) const { } } Array _ClassDB::get_signal_list(StringName p_class, bool p_no_inheritance) const { - List signals; ClassDB::get_signal_list(p_class, &signals, p_no_inheritance); Array ret; @@ -2944,7 +2691,6 @@ Array _ClassDB::get_signal_list(StringName p_class, bool p_no_inheritance) const } Array _ClassDB::get_property_list(StringName p_class, bool p_no_inheritance) const { - List plist; ClassDB::get_property_list(p_class, &plist, p_no_inheritance); Array ret; @@ -2973,12 +2719,10 @@ Error _ClassDB::set_property(Object *p_object, const StringName &p_property, con } bool _ClassDB::has_method(StringName p_class, StringName p_method, bool p_no_inheritance) const { - return ClassDB::has_method(p_class, p_method, p_no_inheritance); } Array _ClassDB::get_method_list(StringName p_class, bool p_no_inheritance) const { - List methods; ClassDB::get_method_list(p_class, &methods, p_no_inheritance); Array ret; @@ -2997,7 +2741,6 @@ Array _ClassDB::get_method_list(StringName p_class, bool p_no_inheritance) const } PoolStringArray _ClassDB::get_integer_constant_list(const StringName &p_class, bool p_no_inheritance) const { - List constants; ClassDB::get_integer_constant_list(p_class, &constants, p_no_inheritance); @@ -3012,31 +2755,26 @@ PoolStringArray _ClassDB::get_integer_constant_list(const StringName &p_class, b } bool _ClassDB::has_integer_constant(const StringName &p_class, const StringName &p_name) const { - bool success; ClassDB::get_integer_constant(p_class, p_name, &success); return success; } int _ClassDB::get_integer_constant(const StringName &p_class, const StringName &p_name) const { - bool found; int c = ClassDB::get_integer_constant(p_class, p_name, &found); ERR_FAIL_COND_V(!found, 0); return c; } StringName _ClassDB::get_category(const StringName &p_node) const { - return ClassDB::get_category(p_node); } bool _ClassDB::is_class_enabled(StringName p_class) const { - return ClassDB::is_class_enabled(p_class); } void _ClassDB::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_class_list"), &_ClassDB::get_class_list); ClassDB::bind_method(D_METHOD("get_inheriters_from_class", "class"), &_ClassDB::get_inheriters_from_class); ClassDB::bind_method(D_METHOD("get_parent_class", "class"), &_ClassDB::get_parent_class); @@ -3073,11 +2811,9 @@ _ClassDB::~_ClassDB() { /////////////////////////////// void _Engine::set_iterations_per_second(int p_ips) { - Engine::get_singleton()->set_iterations_per_second(p_ips); } int _Engine::get_iterations_per_second() const { - return Engine::get_singleton()->get_iterations_per_second(); } @@ -3102,17 +2838,14 @@ int _Engine::get_target_fps() const { } float _Engine::get_frames_per_second() const { - return Engine::get_singleton()->get_frames_per_second(); } uint64_t _Engine::get_physics_frames() const { - return Engine::get_singleton()->get_physics_frames(); } uint64_t _Engine::get_idle_frames() const { - return Engine::get_singleton()->get_idle_frames(); } @@ -3121,23 +2854,19 @@ void _Engine::set_time_scale(float p_scale) { } float _Engine::get_time_scale() { - return Engine::get_singleton()->get_time_scale(); } int _Engine::get_frames_drawn() { - return Engine::get_singleton()->get_frames_drawn(); } MainLoop *_Engine::get_main_loop() const { - //needs to remain in OS, since it's actually OS that interacts with it, but it's better exposed here return OS::get_singleton()->get_main_loop(); } Dictionary _Engine::get_version_info() const { - return Engine::get_singleton()->get_version_info(); } @@ -3166,27 +2895,22 @@ bool _Engine::is_in_physics_frame() const { } bool _Engine::has_singleton(const String &p_name) const { - return Engine::get_singleton()->has_singleton(p_name); } Object *_Engine::get_singleton_object(const String &p_name) const { - return Engine::get_singleton()->get_singleton_object(p_name); } void _Engine::set_editor_hint(bool p_enabled) { - Engine::get_singleton()->set_editor_hint(p_enabled); } bool _Engine::is_editor_hint() const { - return Engine::get_singleton()->is_editor_hint(); } void _Engine::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_iterations_per_second", "iterations_per_second"), &_Engine::set_iterations_per_second); ClassDB::bind_method(D_METHOD("get_iterations_per_second"), &_Engine::get_iterations_per_second); ClassDB::bind_method(D_METHOD("set_physics_jitter_fix", "physics_jitter_fix"), &_Engine::set_physics_jitter_fix); diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index 7ba784f424f..a536fd14fd4 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -399,7 +399,6 @@ VARIANT_ENUM_CAST(_OS::ScreenOrientation); VARIANT_ENUM_CAST(_OS::HandleType); class _Geometry : public Object { - GDCLASS(_Geometry, Object); static _Geometry *singleton; @@ -480,7 +479,6 @@ VARIANT_ENUM_CAST(_Geometry::PolyJoinType); VARIANT_ENUM_CAST(_Geometry::PolyEndType); class _File : public Reference { - GDCLASS(_File, Reference); FileAccess *f; bool eswap; @@ -583,7 +581,6 @@ VARIANT_ENUM_CAST(_File::ModeFlags); VARIANT_ENUM_CAST(_File::CompressionMode); class _Directory : public Reference { - GDCLASS(_Directory, Reference); DirAccess *d; @@ -627,7 +624,6 @@ private: }; class _Marshalls : public Object { - GDCLASS(_Marshalls, Object); static _Marshalls *singleton; @@ -652,7 +648,6 @@ public: }; class _Mutex : public Reference { - GDCLASS(_Mutex, Reference); Mutex mutex; @@ -665,7 +660,6 @@ public: }; class _Semaphore : public Reference { - GDCLASS(_Semaphore, Reference); Semaphore semaphore; @@ -677,7 +671,6 @@ public: }; class _Thread : public Reference { - GDCLASS(_Thread, Reference); protected: @@ -711,7 +704,6 @@ public: VARIANT_ENUM_CAST(_Thread::Priority); class _ClassDB : public Object { - GDCLASS(_ClassDB, Object); protected: diff --git a/core/class_db.cpp b/core/class_db.cpp index 2d34aea3597..b8906cd7320 100644 --- a/core/class_db.cpp +++ b/core/class_db.cpp @@ -40,14 +40,12 @@ #ifdef DEBUG_METHODS_ENABLED MethodDefinition D_METHOD(const char *p_name) { - MethodDefinition md; md.name = StaticCString::create(p_name); return md; } MethodDefinition D_METHOD(const char *p_name, const char *p_arg1) { - MethodDefinition md; md.name = StaticCString::create(p_name); md.args.push_back(StaticCString::create(p_arg1)); @@ -55,7 +53,6 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1) { } MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2) { - MethodDefinition md; md.name = StaticCString::create(p_name); md.args.resize(2); @@ -65,7 +62,6 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_ } MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3) { - MethodDefinition md; md.name = StaticCString::create(p_name); md.args.resize(3); @@ -76,7 +72,6 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_ } MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4) { - MethodDefinition md; md.name = StaticCString::create(p_name); md.args.resize(4); @@ -88,7 +83,6 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_ } MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5) { - MethodDefinition md; md.name = StaticCString::create(p_name); md.args.resize(5); @@ -101,7 +95,6 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_ } MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6) { - MethodDefinition md; md.name = StaticCString::create(p_name); md.args.resize(6); @@ -115,7 +108,6 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_ } MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7) { - MethodDefinition md; md.name = StaticCString::create(p_name); md.args.resize(7); @@ -130,7 +122,6 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_ } MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7, const char *p_arg8) { - MethodDefinition md; md.name = StaticCString::create(p_name); md.args.resize(8); @@ -146,7 +137,6 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_ } MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7, const char *p_arg8, const char *p_arg9) { - MethodDefinition md; md.name = StaticCString::create(p_name); md.args.resize(9); @@ -163,7 +153,6 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_ } MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7, const char *p_arg8, const char *p_arg9, const char *p_arg10) { - MethodDefinition md; md.name = StaticCString::create(p_name); md.args.resize(10); @@ -181,7 +170,6 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_ } MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7, const char *p_arg8, const char *p_arg9, const char *p_arg10, const char *p_arg11) { - MethodDefinition md; md.name = StaticCString::create(p_name); md.args.resize(11); @@ -200,7 +188,6 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_ } MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7, const char *p_arg8, const char *p_arg9, const char *p_arg10, const char *p_arg11, const char *p_arg12) { - MethodDefinition md; md.name = StaticCString::create(p_name); md.args.resize(12); @@ -220,7 +207,6 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_ } MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7, const char *p_arg8, const char *p_arg9, const char *p_arg10, const char *p_arg11, const char *p_arg12, const char *p_arg13) { - MethodDefinition md; md.name = StaticCString::create(p_name); md.args.resize(13); @@ -245,12 +231,10 @@ MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_ ClassDB::APIType ClassDB::current_api = API_CORE; void ClassDB::set_current_api(APIType p_api) { - current_api = p_api; } ClassDB::APIType ClassDB::get_current_api() { - return current_api; } @@ -259,7 +243,6 @@ HashMap ClassDB::resource_base_extensions; HashMap ClassDB::compat_classes; ClassDB::ClassInfo::ClassInfo() { - api = API_NONE; creation_func = NULL; inherits_ptr = NULL; @@ -271,11 +254,9 @@ ClassDB::ClassInfo::~ClassInfo() { } bool ClassDB::_is_parent_class(const StringName &p_class, const StringName &p_inherits) { - StringName inherits = p_class; while (inherits.operator String().length()) { - if (inherits == p_inherits) return true; inherits = _get_parent_class(inherits); @@ -285,20 +266,17 @@ bool ClassDB::_is_parent_class(const StringName &p_class, const StringName &p_in } bool ClassDB::is_parent_class(const StringName &p_class, const StringName &p_inherits) { - OBJTYPE_RLOCK; return _is_parent_class(p_class, p_inherits); } void ClassDB::get_class_list(List *p_classes) { - OBJTYPE_RLOCK; const StringName *k = NULL; while ((k = classes.next(k))) { - p_classes->push_back(*k); } @@ -306,33 +284,28 @@ void ClassDB::get_class_list(List *p_classes) { } void ClassDB::get_inheriters_from_class(const StringName &p_class, List *p_classes) { - OBJTYPE_RLOCK; const StringName *k = NULL; while ((k = classes.next(k))) { - if (*k != p_class && _is_parent_class(*k, p_class)) p_classes->push_back(*k); } } void ClassDB::get_direct_inheriters_from_class(const StringName &p_class, List *p_classes) { - OBJTYPE_RLOCK; const StringName *k = NULL; while ((k = classes.next(k))) { - if (*k != p_class && _get_parent_class(*k) == p_class) p_classes->push_back(*k); } } StringName ClassDB::get_parent_class_nocheck(const StringName &p_class) { - OBJTYPE_RLOCK; ClassInfo *ti = classes.getptr(p_class); @@ -342,21 +315,18 @@ StringName ClassDB::get_parent_class_nocheck(const StringName &p_class) { } StringName ClassDB::_get_parent_class(const StringName &p_class) { - ClassInfo *ti = classes.getptr(p_class); ERR_FAIL_COND_V_MSG(!ti, StringName(), "Cannot get class '" + String(p_class) + "'."); return ti->inherits; } StringName ClassDB::get_parent_class(const StringName &p_class) { - OBJTYPE_RLOCK; return _get_parent_class(p_class); } ClassDB::APIType ClassDB::get_api_type(const StringName &p_class) { - OBJTYPE_RLOCK; ClassInfo *ti = classes.getptr(p_class); @@ -366,7 +336,6 @@ ClassDB::APIType ClassDB::get_api_type(const StringName &p_class) { } uint64_t ClassDB::get_api_hash(APIType p_api) { - OBJTYPE_RLOCK; #ifdef DEBUG_METHODS_ENABLED @@ -377,14 +346,12 @@ uint64_t ClassDB::get_api_hash(APIType p_api) { const StringName *k = NULL; while ((k = classes.next(k))) { - names.push_back(*k); } //must be alphabetically sorted for hash to compute names.sort_custom(); 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) @@ -399,7 +366,6 @@ uint64_t ClassDB::get_api_hash(APIType p_api) { k = NULL; while ((k = t->method_map.next(k))) { - String name = k->operator String(); ERR_CONTINUE(name.empty()); @@ -413,7 +379,6 @@ uint64_t ClassDB::get_api_hash(APIType p_api) { snames.sort_custom(); for (List::Element *F = snames.front(); F; F = F->next()) { - MethodBind *mb = t->method_map[F->get()]; hash = hash_djb2_one_64(mb->get_name().hash(), hash); hash = hash_djb2_one_64(mb->get_argument_count(), hash); @@ -446,14 +411,12 @@ uint64_t ClassDB::get_api_hash(APIType p_api) { k = NULL; while ((k = t->constant_map.next(k))) { - snames.push_back(*k); } snames.sort_custom(); for (List::Element *F = snames.front(); F; F = F->next()) { - hash = hash_djb2_one_64(F->get().hash(), hash); hash = hash_djb2_one_64(t->constant_map[F->get()], hash); } @@ -466,14 +429,12 @@ uint64_t ClassDB::get_api_hash(APIType p_api) { k = NULL; while ((k = t->signal_map.next(k))) { - snames.push_back(*k); } snames.sort_custom(); for (List::Element *F = snames.front(); F; F = F->next()) { - MethodInfo &mi = t->signal_map[F->get()]; hash = hash_djb2_one_64(F->get().hash(), hash); for (int i = 0; i < mi.arguments.size(); i++) { @@ -489,14 +450,12 @@ uint64_t ClassDB::get_api_hash(APIType p_api) { k = NULL; while ((k = t->property_setget.next(k))) { - snames.push_back(*k); } snames.sort_custom(); for (List::Element *F = snames.front(); F; F = F->next()) { - PropertySetGet *psg = t->property_setget.getptr(F->get()); ERR_FAIL_COND_V(!psg, 0); @@ -508,7 +467,6 @@ uint64_t ClassDB::get_api_hash(APIType p_api) { //property list for (List::Element *F = t->property_list.front(); F; F = F->next()) { - hash = hash_djb2_one_64(F->get().name.hash(), hash); hash = hash_djb2_one_64(F->get().type, hash); hash = hash_djb2_one_64(F->get().hint, hash); @@ -524,19 +482,16 @@ uint64_t ClassDB::get_api_hash(APIType p_api) { } bool ClassDB::class_exists(const StringName &p_class) { - OBJTYPE_RLOCK; return classes.has(p_class); } void ClassDB::add_compatibility_class(const StringName &p_class, const StringName &p_fallback) { - OBJTYPE_WLOCK; compat_classes[p_class] = p_fallback; } Object *ClassDB::instance(const StringName &p_class) { - ClassInfo *ti; { OBJTYPE_RLOCK; @@ -559,7 +514,6 @@ Object *ClassDB::instance(const StringName &p_class) { return ti->creation_func(); } bool ClassDB::can_instance(const StringName &p_class) { - OBJTYPE_RLOCK; ClassInfo *ti = classes.getptr(p_class); @@ -573,7 +527,6 @@ bool ClassDB::can_instance(const StringName &p_class) { } void ClassDB::_add_class2(const StringName &p_class, const StringName &p_inherits) { - OBJTYPE_WLOCK; const StringName &name = p_class; @@ -587,7 +540,6 @@ void ClassDB::_add_class2(const StringName &p_class, const StringName &p_inherit ti.api = current_api; if (ti.inherits) { - ERR_FAIL_COND(!classes.has(ti.inherits)); //it MUST be registered. ti.inherits_ptr = &classes[ti.inherits]; @@ -597,15 +549,12 @@ void ClassDB::_add_class2(const StringName &p_class, const StringName &p_inherit } void ClassDB::get_method_list(StringName p_class, List *p_methods, bool p_no_inheritance, bool p_exclude_from_properties) { - OBJTYPE_RLOCK; ClassInfo *type = classes.getptr(p_class); while (type) { - if (type->disabled) { - if (p_no_inheritance) break; @@ -616,12 +565,10 @@ void ClassDB::get_method_list(StringName p_class, List *p_methods, b #ifdef DEBUG_METHODS_ENABLED for (List::Element *E = type->virtual_methods.front(); E; E = E->next()) { - p_methods->push_back(E->get()); } for (List::Element *E = type->method_order.front(); E; E = E->next()) { - MethodBind *method = type->method_map.get(E->get()); MethodInfo minfo; minfo.name = E->get(); @@ -631,7 +578,6 @@ void ClassDB::get_method_list(StringName p_class, List *p_methods, b continue; for (int i = 0; i < method->get_argument_count(); i++) { - //Variant::Type t=method->get_argument_type(i); minfo.arguments.push_back(method->get_argument_info(i)); @@ -653,7 +599,6 @@ void ClassDB::get_method_list(StringName p_class, List *p_methods, b const StringName *K = NULL; while ((K = type->method_map.next(K))) { - MethodBind *m = type->method_map[*K]; MethodInfo mi; mi.name = m->get_name(); @@ -670,13 +615,11 @@ void ClassDB::get_method_list(StringName p_class, List *p_methods, b } MethodBind *ClassDB::get_method(StringName p_class, StringName p_name) { - OBJTYPE_RLOCK; ClassInfo *type = classes.getptr(p_class); while (type) { - MethodBind **method = type->method_map.getptr(p_name); if (method && *method) return *method; @@ -686,7 +629,6 @@ MethodBind *ClassDB::get_method(StringName p_class, StringName p_name) { } void ClassDB::bind_integer_constant(const StringName &p_class, const StringName &p_enum, const StringName &p_name, int p_constant) { - OBJTYPE_WLOCK; ClassInfo *type = classes.getptr(p_class); @@ -694,7 +636,6 @@ void ClassDB::bind_integer_constant(const StringName &p_class, const StringName ERR_FAIL_COND(!type); if (type->constant_map.has(p_name)) { - ERR_FAIL(); } @@ -723,13 +664,11 @@ void ClassDB::bind_integer_constant(const StringName &p_class, const StringName } void ClassDB::get_integer_constant_list(const StringName &p_class, List *p_constants, bool p_no_inheritance) { - OBJTYPE_RLOCK; ClassInfo *type = classes.getptr(p_class); while (type) { - #ifdef DEBUG_METHODS_ENABLED for (List::Element *E = type->constant_order.front(); E; E = E->next()) p_constants->push_back(E->get()); @@ -749,16 +688,13 @@ void ClassDB::get_integer_constant_list(const StringName &p_class, List } int ClassDB::get_integer_constant(const StringName &p_class, const StringName &p_name, bool *p_success) { - OBJTYPE_RLOCK; ClassInfo *type = classes.getptr(p_class); while (type) { - int *constant = type->constant_map.getptr(p_name); if (constant) { - if (p_success) *p_success = true; return *constant; @@ -774,16 +710,13 @@ int ClassDB::get_integer_constant(const StringName &p_class, const StringName &p } StringName ClassDB::get_integer_constant_enum(const StringName &p_class, const StringName &p_name, bool p_no_inheritance) { - OBJTYPE_RLOCK; ClassInfo *type = classes.getptr(p_class); while (type) { - const StringName *k = NULL; 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) @@ -800,13 +733,11 @@ StringName ClassDB::get_integer_constant_enum(const StringName &p_class, const S } void ClassDB::get_enum_list(const StringName &p_class, List *p_enums, bool p_no_inheritance) { - OBJTYPE_RLOCK; ClassInfo *type = classes.getptr(p_class); while (type) { - const StringName *k = NULL; while ((k = type->enum_map.next(k))) { p_enums->push_back(*k); @@ -820,13 +751,11 @@ void ClassDB::get_enum_list(const StringName &p_class, List *p_enums } void ClassDB::get_enum_constants(const StringName &p_class, const StringName &p_enum, List *p_constants, bool p_no_inheritance) { - OBJTYPE_RLOCK; ClassInfo *type = classes.getptr(p_class); while (type) { - const List *constants = type->enum_map.getptr(p_enum); if (constants) { @@ -843,7 +772,6 @@ void ClassDB::get_enum_constants(const StringName &p_class, const StringName &p_ } void ClassDB::add_signal(StringName p_class, const MethodInfo &p_signal) { - OBJTYPE_WLOCK; ClassInfo *type = classes.getptr(p_class); @@ -863,7 +791,6 @@ void ClassDB::add_signal(StringName p_class, const MethodInfo &p_signal) { } void ClassDB::get_signal_list(StringName p_class, List *p_signals, bool p_no_inheritance) { - OBJTYPE_RLOCK; ClassInfo *type = classes.getptr(p_class); @@ -872,10 +799,8 @@ void ClassDB::get_signal_list(StringName p_class, List *p_signals, b ClassInfo *check = type; while (check) { - const StringName *S = NULL; while ((S = check->signal_map.next(S))) { - p_signals->push_back(check->signal_map[*S]); } @@ -887,7 +812,6 @@ void ClassDB::get_signal_list(StringName p_class, List *p_signals, b } bool ClassDB::has_signal(StringName p_class, StringName p_signal) { - OBJTYPE_RLOCK; ClassInfo *type = classes.getptr(p_class); ClassInfo *check = type; @@ -901,7 +825,6 @@ bool ClassDB::has_signal(StringName p_class, StringName p_signal) { } bool ClassDB::get_signal(StringName p_class, StringName p_signal, MethodInfo *r_signal) { - OBJTYPE_RLOCK; ClassInfo *type = classes.getptr(p_class); ClassInfo *check = type; @@ -919,7 +842,6 @@ bool ClassDB::get_signal(StringName p_class, StringName p_signal, MethodInfo *r_ } void ClassDB::add_property_group(StringName p_class, const String &p_name, const String &p_prefix) { - OBJTYPE_WLOCK; ClassInfo *type = classes.getptr(p_class); ERR_FAIL_COND(!type); @@ -928,7 +850,6 @@ void ClassDB::add_property_group(StringName p_class, const String &p_name, const } void ClassDB::add_property(StringName p_class, const PropertyInfo &p_pinfo, const StringName &p_setter, const StringName &p_getter, int p_index) { - lock.read_lock(); ClassInfo *type = classes.getptr(p_class); lock.read_unlock(); @@ -949,7 +870,6 @@ void ClassDB::add_property(StringName p_class, const PropertyInfo &p_pinfo, cons MethodBind *mb_get = NULL; if (p_getter) { - mb_get = get_method(p_class, p_getter); #ifdef DEBUG_METHODS_ENABLED @@ -994,15 +914,12 @@ void ClassDB::set_property_default_value(StringName p_class, const StringName &p } void ClassDB::get_property_list(StringName p_class, List *p_list, bool p_no_inheritance, const Object *p_validator) { - OBJTYPE_RLOCK; ClassInfo *type = classes.getptr(p_class); ClassInfo *check = type; while (check) { - for (List::Element *E = check->property_list.front(); E; E = E->next()) { - if (p_validator) { PropertyInfo pi = E->get(); p_validator->_validate_property(pi); @@ -1025,7 +942,6 @@ bool ClassDB::set_property(Object *p_object, const StringName &p_property, const while (check) { const PropertySetGet *psg = check->property_setget.getptr(p_property); if (psg) { - if (!psg->setter) { if (r_valid) *r_valid = false; @@ -1082,10 +998,8 @@ bool ClassDB::get_property(Object *p_object, const StringName &p_property, Varia r_value = p_object->call(psg->getter, arg, 1, ce); } else { - Variant::CallError ce; if (psg->_getptr) { - r_value = psg->_getptr->call(p_object, NULL, 0, ce); } else { r_value = p_object->call(psg->getter, NULL, 0, ce); @@ -1096,7 +1010,6 @@ bool ClassDB::get_property(Object *p_object, const StringName &p_property, Varia const int *c = check->constant_map.getptr(p_property); if (c) { - r_value = *c; return true; } @@ -1108,13 +1021,11 @@ bool ClassDB::get_property(Object *p_object, const StringName &p_property, Varia } int ClassDB::get_property_index(const StringName &p_class, const StringName &p_property, bool *r_is_valid) { - ClassInfo *type = classes.getptr(p_class); ClassInfo *check = type; while (check) { const PropertySetGet *psg = check->property_setget.getptr(p_property); if (psg) { - if (r_is_valid) *r_is_valid = true; @@ -1130,13 +1041,11 @@ int ClassDB::get_property_index(const StringName &p_class, const StringName &p_p } Variant::Type ClassDB::get_property_type(const StringName &p_class, const StringName &p_property, bool *r_is_valid) { - ClassInfo *type = classes.getptr(p_class); ClassInfo *check = type; while (check) { const PropertySetGet *psg = check->property_setget.getptr(p_property); if (psg) { - if (r_is_valid) *r_is_valid = true; @@ -1152,13 +1061,11 @@ Variant::Type ClassDB::get_property_type(const StringName &p_class, const String } StringName ClassDB::get_property_setter(StringName p_class, const StringName &p_property) { - ClassInfo *type = classes.getptr(p_class); ClassInfo *check = type; while (check) { const PropertySetGet *psg = check->property_setget.getptr(p_property); if (psg) { - return psg->setter; } @@ -1169,13 +1076,11 @@ StringName ClassDB::get_property_setter(StringName p_class, const StringName &p_ } StringName ClassDB::get_property_getter(StringName p_class, const StringName &p_property) { - ClassInfo *type = classes.getptr(p_class); ClassInfo *check = type; while (check) { const PropertySetGet *psg = check->property_setget.getptr(p_property); if (psg) { - return psg->getter; } @@ -1186,7 +1091,6 @@ StringName ClassDB::get_property_getter(StringName p_class, const StringName &p_ } bool ClassDB::has_property(const StringName &p_class, const StringName &p_property, bool p_no_inheritance) { - ClassInfo *type = classes.getptr(p_class); ClassInfo *check = type; while (check) { @@ -1202,7 +1106,6 @@ bool ClassDB::has_property(const StringName &p_class, const StringName &p_proper } void ClassDB::set_method_flags(StringName p_class, StringName p_method, int p_flags) { - OBJTYPE_WLOCK; ClassInfo *type = classes.getptr(p_class); ClassInfo *check = type; @@ -1212,7 +1115,6 @@ void ClassDB::set_method_flags(StringName p_class, StringName p_method, int p_fl } bool ClassDB::has_method(StringName p_class, StringName p_method, bool p_no_inheritance) { - ClassInfo *type = classes.getptr(p_class); ClassInfo *check = type; while (check) { @@ -1275,7 +1177,6 @@ MethodBind *ClassDB::bind_methodfi(uint32_t p_flags, MethodBind *p_bind, const c defvals.resize(p_defcount); for (int i = 0; i < p_defcount; i++) { - defvals.write[i] = *p_defs[p_defcount - i - 1]; } @@ -1299,7 +1200,6 @@ void ClassDB::add_virtual_method(const StringName &p_class, const MethodInfo &p_ } void ClassDB::get_virtual_methods(const StringName &p_class, List *p_methods, bool p_no_inheritance) { - ERR_FAIL_COND_MSG(!classes.has(p_class), "Request for nonexistent class '" + p_class + "'."); #ifdef DEBUG_METHODS_ENABLED @@ -1307,7 +1207,6 @@ void ClassDB::get_virtual_methods(const StringName &p_class, List *p ClassInfo *type = classes.getptr(p_class); ClassInfo *check = type; while (check) { - for (List::Element *E = check->virtual_methods.front(); E; E = E->next()) { p_methods->push_back(E->get()); } @@ -1321,7 +1220,6 @@ void ClassDB::get_virtual_methods(const StringName &p_class, List *p } void ClassDB::set_class_enabled(StringName p_class, bool p_enable) { - OBJTYPE_WLOCK; ERR_FAIL_COND_MSG(!classes.has(p_class), "Request for nonexistent class '" + p_class + "'."); @@ -1329,7 +1227,6 @@ void ClassDB::set_class_enabled(StringName p_class, bool p_enable) { } bool ClassDB::is_class_enabled(StringName p_class) { - OBJTYPE_RLOCK; ClassInfo *ti = classes.getptr(p_class); @@ -1344,7 +1241,6 @@ bool ClassDB::is_class_enabled(StringName p_class) { } bool ClassDB::is_class_exposed(StringName p_class) { - OBJTYPE_RLOCK; ClassInfo *ti = classes.getptr(p_class); @@ -1353,7 +1249,6 @@ bool ClassDB::is_class_exposed(StringName p_class) { } StringName ClassDB::get_category(const StringName &p_node) { - ERR_FAIL_COND_V(!classes.has(p_node), StringName()); #ifdef DEBUG_ENABLED return classes[p_node].category; @@ -1363,7 +1258,6 @@ 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)) return; @@ -1371,17 +1265,14 @@ void ClassDB::add_resource_base_extension(const StringName &p_extension, const S } void ClassDB::get_resource_base_extensions(List *p_extensions) { - const StringName *K = NULL; while ((K = resource_base_extensions.next(K))) { - p_extensions->push_back(*K); } } void ClassDB::get_extensions_for_type(const StringName &p_class, List *p_extensions) { - const StringName *K = NULL; while ((K = resource_base_extensions.next(K))) { @@ -1395,9 +1286,7 @@ HashMap> ClassDB::default_values; Set ClassDB::default_values_cached; Variant ClassDB::class_get_default_property_value(const StringName &p_class, const StringName &p_property, bool *r_valid) { - if (!default_values_cached.has(p_class)) { - if (!default_values.has(p_class)) { default_values[p_class] = HashMap(); } @@ -1414,12 +1303,10 @@ Variant ClassDB::class_get_default_property_value(const StringName &p_class, con } if (c) { - List plist; c->get_property_list(&plist); for (List::Element *E = plist.front(); E; E = E->next()) { if (E->get().usage & (PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_EDITOR)) { - if (!default_values[p_class].has(E->get().name)) { Variant v = c->get(E->get().name); default_values[p_class][E->get().name] = v; @@ -1455,24 +1342,20 @@ Variant ClassDB::class_get_default_property_value(const StringName &p_class, con RWLock ClassDB::lock; void ClassDB::cleanup_defaults() { - default_values.clear(); default_values_cached.clear(); } void ClassDB::cleanup() { - //OBJTYPE_LOCK; hah not here const StringName *k = NULL; while ((k = classes.next(k))) { - ClassInfo &ti = classes[*k]; const StringName *m = NULL; while ((m = ti.method_map.next(m))) { - memdelete(ti.method_map[*m]); } } diff --git a/core/class_db.h b/core/class_db.h index bc9308bcb23..7c558c6aa82 100644 --- a/core/class_db.h +++ b/core/class_db.h @@ -46,7 +46,6 @@ #ifdef DEBUG_METHODS_ENABLED struct MethodDefinition { - StringName name; Vector args; MethodDefinition() {} @@ -101,7 +100,6 @@ public: public: struct PropertySetGet { - int index; StringName setter; StringName getter; @@ -111,7 +109,6 @@ public: }; struct ClassInfo { - APIType api; ClassInfo *inherits_ptr; void *class_ptr; @@ -170,13 +167,11 @@ public: // DO NOT USE THIS!!!!!! NEEDS TO BE PUBLIC BUT DO NOT USE NO MATTER WHAT!!! template static void _add_class() { - _add_class2(T::get_class_static(), T::get_parent_class_static()); } template static void register_class() { - GLOBAL_LOCK_FUNCTION; T::initialize_class(); ClassInfo *t = classes.getptr(T::get_class_static()); @@ -189,7 +184,6 @@ public: template static void register_virtual_class() { - GLOBAL_LOCK_FUNCTION; T::initialize_class(); ClassInfo *t = classes.getptr(T::get_class_static()); @@ -201,13 +195,11 @@ public: template static Object *_create_ptr_func() { - return T::create(); } template static void register_custom_instance_class() { - GLOBAL_LOCK_FUNCTION; T::initialize_class(); ClassInfo *t = classes.getptr(T::get_class_static()); @@ -233,7 +225,6 @@ public: template static MethodBind *bind_method(N p_method_name, M p_method) { - MethodBind *bind = create_method_bind(p_method); return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, p_method_name, NULL, 0); //use static function, much smaller binary usage @@ -241,7 +232,6 @@ public: template static MethodBind *bind_method(N p_method_name, M p_method, const Variant &p_def1) { - MethodBind *bind = create_method_bind(p_method); const Variant *ptr[1] = { &p_def1 }; @@ -250,7 +240,6 @@ public: template static MethodBind *bind_method(N p_method_name, M p_method, const Variant &p_def1, const Variant &p_def2) { - MethodBind *bind = create_method_bind(p_method); const Variant *ptr[2] = { &p_def1, &p_def2 }; @@ -259,7 +248,6 @@ public: template static MethodBind *bind_method(N p_method_name, M p_method, const Variant &p_def1, const Variant &p_def2, const Variant &p_def3) { - MethodBind *bind = create_method_bind(p_method); const Variant *ptr[3] = { &p_def1, &p_def2, &p_def3 }; @@ -268,7 +256,6 @@ public: template static MethodBind *bind_method(N p_method_name, M p_method, const Variant &p_def1, const Variant &p_def2, const Variant &p_def3, const Variant &p_def4) { - MethodBind *bind = create_method_bind(p_method); const Variant *ptr[4] = { &p_def1, &p_def2, &p_def3, &p_def4 }; @@ -277,7 +264,6 @@ public: template static MethodBind *bind_method(N p_method_name, M p_method, const Variant &p_def1, const Variant &p_def2, const Variant &p_def3, const Variant &p_def4, const Variant &p_def5) { - MethodBind *bind = create_method_bind(p_method); const Variant *ptr[5] = { &p_def1, &p_def2, &p_def3, &p_def4, &p_def5 }; @@ -286,7 +272,6 @@ public: template static MethodBind *bind_method(N p_method_name, M p_method, const Variant &p_def1, const Variant &p_def2, const Variant &p_def3, const Variant &p_def4, const Variant &p_def5, const Variant &p_def6) { - MethodBind *bind = create_method_bind(p_method); const Variant *ptr[6] = { &p_def1, &p_def2, &p_def3, &p_def4, &p_def5, &p_def6 }; @@ -295,7 +280,6 @@ public: template static MethodBind *bind_method(N p_method_name, M p_method, const Variant &p_def1, const Variant &p_def2, const Variant &p_def3, const Variant &p_def4, const Variant &p_def5, const Variant &p_def6, const Variant &p_def7) { - MethodBind *bind = create_method_bind(p_method); const Variant *ptr[7] = { &p_def1, &p_def2, &p_def3, &p_def4, &p_def5, &p_def6, &p_def7 }; @@ -304,7 +288,6 @@ public: template static MethodBind *bind_method(N p_method_name, M p_method, const Variant &p_def1, const Variant &p_def2, const Variant &p_def3, const Variant &p_def4, const Variant &p_def5, const Variant &p_def6, const Variant &p_def7, const Variant &p_def8) { - MethodBind *bind = create_method_bind(p_method); const Variant *ptr[8] = { &p_def1, &p_def2, &p_def3, &p_def4, &p_def5, &p_def6, &p_def7, &p_def8 }; @@ -313,7 +296,6 @@ public: template static MethodBind *bind_vararg_method(uint32_t p_flags, StringName p_name, M p_method, const MethodInfo &p_info = MethodInfo(), const Vector &p_default_args = Vector(), bool p_return_nil_is_variant = true) { - GLOBAL_LOCK_FUNCTION; MethodBind *bind = create_vararg_method_bind(p_method, p_info, p_return_nil_is_variant); diff --git a/core/color.cpp b/core/color.cpp index 1dd32954b63..b1c75988e4b 100644 --- a/core/color.cpp +++ b/core/color.cpp @@ -36,7 +36,6 @@ #include "core/print_string.h" uint32_t Color::to_argb32() const { - uint32_t c = (uint8_t)Math::round(a * 255); c <<= 8; c |= (uint8_t)Math::round(r * 255); @@ -49,7 +48,6 @@ uint32_t Color::to_argb32() const { } uint32_t Color::to_abgr32() const { - uint32_t c = (uint8_t)Math::round(a * 255); c <<= 8; c |= (uint8_t)Math::round(b * 255); @@ -62,7 +60,6 @@ uint32_t Color::to_abgr32() const { } uint32_t Color::to_rgba32() const { - uint32_t c = (uint8_t)Math::round(r * 255); c <<= 8; c |= (uint8_t)Math::round(g * 255); @@ -75,7 +72,6 @@ uint32_t Color::to_rgba32() const { } uint64_t Color::to_abgr64() const { - uint64_t c = (uint16_t)Math::round(a * 65535); c <<= 16; c |= (uint16_t)Math::round(b * 65535); @@ -88,7 +84,6 @@ uint64_t Color::to_abgr64() const { } uint64_t Color::to_argb64() const { - uint64_t c = (uint16_t)Math::round(a * 65535); c <<= 16; c |= (uint16_t)Math::round(r * 65535); @@ -101,7 +96,6 @@ uint64_t Color::to_argb64() const { } uint64_t Color::to_rgba64() const { - uint64_t c = (uint16_t)Math::round(r * 65535); c <<= 16; c |= (uint16_t)Math::round(g * 65535); @@ -114,7 +108,6 @@ uint64_t Color::to_rgba64() const { } float Color::get_h() const { - float min = MIN(r, g); min = MIN(min, b); float max = MAX(r, g); @@ -141,7 +134,6 @@ float Color::get_h() const { } float Color::get_s() const { - float min = MIN(r, g); min = MIN(min, b); float max = MAX(r, g); @@ -153,14 +145,12 @@ float Color::get_s() const { } float Color::get_v() const { - float max = MAX(r, g); max = MAX(max, b); return max; } void Color::set_hsv(float p_h, float p_s, float p_v, float p_alpha) { - int i; float f, p, q, t; a = p_alpha; @@ -215,25 +205,21 @@ void Color::set_hsv(float p_h, float p_s, float p_v, float p_alpha) { } bool Color::is_equal_approx(const Color &p_color) const { - return Math::is_equal_approx(r, p_color.r) && Math::is_equal_approx(g, p_color.g) && Math::is_equal_approx(b, p_color.b) && Math::is_equal_approx(a, p_color.a); } void Color::invert() { - r = 1.0 - r; g = 1.0 - g; b = 1.0 - b; } void Color::contrast() { - r = Math::fmod(r + 0.5, 1.0); g = Math::fmod(g + 0.5, 1.0); b = Math::fmod(b + 0.5, 1.0); } Color Color::hex(uint32_t p_hex) { - float a = (p_hex & 0xFF) / 255.0; p_hex >>= 8; float b = (p_hex & 0xFF) / 255.0; @@ -246,7 +232,6 @@ Color Color::hex(uint32_t p_hex) { } Color Color::hex64(uint64_t p_hex) { - float a = (p_hex & 0xFFFF) / 65535.0; p_hex >>= 16; float b = (p_hex & 0xFFFF) / 65535.0; @@ -259,7 +244,6 @@ Color Color::hex64(uint64_t p_hex) { } Color Color::from_rgbe9995(uint32_t p_rgbe) { - float r = p_rgbe & 0x1ff; float g = (p_rgbe >> 9) & 0x1ff; float b = (p_rgbe >> 18) & 0x1ff; @@ -274,11 +258,9 @@ Color Color::from_rgbe9995(uint32_t p_rgbe) { } static float _parse_col(const String &p_str, int p_ofs) { - int ig = 0; for (int i = 0; i < 2; i++) { - int c = p_str[i + p_ofs]; int v = 0; @@ -304,21 +286,18 @@ static float _parse_col(const String &p_str, int p_ofs) { } Color Color::inverted() const { - Color c = *this; c.invert(); return c; } Color Color::contrasted() const { - Color c = *this; c.contrast(); return c; } Color Color::html(const String &p_color) { - String color = p_color; if (color.length() == 0) return Color(); @@ -362,7 +341,6 @@ Color Color::html(const String &p_color) { } bool Color::html_is_valid(const String &p_color) { - String color = p_color; if (color.length() == 0) @@ -423,13 +401,11 @@ Color Color::named(const String &p_name) { } String _to_hex(float p_val) { - int v = Math::round(p_val * 255); v = CLAMP(v, 0, 255); String ret; for (int i = 0; i < 2; i++) { - CharType c[2] = { 0, 0 }; int lv = v & 0xF; if (lv < 10) @@ -446,7 +422,6 @@ String _to_hex(float p_val) { } String Color::to_html(bool p_alpha) const { - String txt; txt += _to_hex(r); txt += _to_hex(g); @@ -464,18 +439,15 @@ Color Color::from_hsv(float p_h, float p_s, float p_v, float p_a) const { // FIXME: Remove once Godot 3.1 has been released float Color::gray() const { - WARN_DEPRECATED_MSG("'Color.gray()' is deprecated and will be removed in a future version. Use 'Color.v' for a better grayscale approximation."); return (r + g + b) / 3.0; } Color::operator String() const { - return rtos(r) + ", " + rtos(g) + ", " + rtos(b) + ", " + rtos(a); } Color Color::operator+(const Color &p_color) const { - return Color( r + p_color.r, g + p_color.g, @@ -484,7 +456,6 @@ Color Color::operator+(const Color &p_color) const { } void Color::operator+=(const Color &p_color) { - r = r + p_color.r; g = g + p_color.g; b = b + p_color.b; @@ -492,7 +463,6 @@ void Color::operator+=(const Color &p_color) { } Color Color::operator-(const Color &p_color) const { - return Color( r - p_color.r, g - p_color.g, @@ -501,7 +471,6 @@ Color Color::operator-(const Color &p_color) const { } void Color::operator-=(const Color &p_color) { - r = r - p_color.r; g = g - p_color.g; b = b - p_color.b; @@ -509,7 +478,6 @@ void Color::operator-=(const Color &p_color) { } Color Color::operator*(const Color &p_color) const { - return Color( r * p_color.r, g * p_color.g, @@ -518,7 +486,6 @@ Color Color::operator*(const Color &p_color) const { } Color Color::operator*(const real_t &rvalue) const { - return Color( r * rvalue, g * rvalue, @@ -527,7 +494,6 @@ Color Color::operator*(const real_t &rvalue) const { } void Color::operator*=(const Color &p_color) { - r = r * p_color.r; g = g * p_color.g; b = b * p_color.b; @@ -535,7 +501,6 @@ void Color::operator*=(const Color &p_color) { } void Color::operator*=(const real_t &rvalue) { - r = r * rvalue; g = g * rvalue; b = b * rvalue; @@ -543,7 +508,6 @@ void Color::operator*=(const real_t &rvalue) { } Color Color::operator/(const Color &p_color) const { - return Color( r / p_color.r, g / p_color.g, @@ -552,7 +516,6 @@ Color Color::operator/(const Color &p_color) const { } Color Color::operator/(const real_t &rvalue) const { - return Color( r / rvalue, g / rvalue, @@ -561,7 +524,6 @@ Color Color::operator/(const real_t &rvalue) const { } void Color::operator/=(const Color &p_color) { - r = r / p_color.r; g = g / p_color.g; b = b / p_color.b; @@ -569,7 +531,6 @@ void Color::operator/=(const Color &p_color) { } void Color::operator/=(const real_t &rvalue) { - if (rvalue == 0) { r = 1.0; g = 1.0; @@ -584,7 +545,6 @@ void Color::operator/=(const real_t &rvalue) { }; Color Color::operator-() const { - return Color( 1.0 - r, 1.0 - g, diff --git a/core/color.h b/core/color.h index a9c63a349ff..286608af549 100644 --- a/core/color.h +++ b/core/color.h @@ -35,9 +35,7 @@ #include "core/ustring.h" struct Color { - union { - struct { float r; float g; @@ -94,7 +92,6 @@ struct Color { Color contrasted() const; _FORCE_INLINE_ Color linear_interpolate(const Color &p_to, float p_weight) const { - Color res = *this; res.r += (p_weight * (p_to.r - r)); @@ -106,7 +103,6 @@ struct Color { } _FORCE_INLINE_ Color darkened(float p_amount) const { - Color res = *this; res.r = res.r * (1.0f - p_amount); res.g = res.g * (1.0f - p_amount); @@ -115,7 +111,6 @@ struct Color { } _FORCE_INLINE_ Color lightened(float p_amount) const { - Color res = *this; res.r = res.r + (1.0f - res.r) * p_amount; res.g = res.g + (1.0f - res.g) * p_amount; @@ -124,7 +119,6 @@ struct Color { } _FORCE_INLINE_ uint32_t to_rgbe9995() const { - const float pow2to9 = 512.0f; const float B = 15.0f; //const float Emax = 31.0f; @@ -158,7 +152,6 @@ struct Color { } _FORCE_INLINE_ Color blend(const Color &p_over) const { - Color res; float sa = 1.0 - p_over.a; res.a = a * sa + p_over.a; @@ -173,7 +166,6 @@ struct Color { } _FORCE_INLINE_ Color to_linear() const { - return Color( r < 0.04045 ? r * (1.0 / 12.92) : Math::pow((r + 0.055) * (1.0 / (1 + 0.055)), 2.4), g < 0.04045 ? g * (1.0 / 12.92) : Math::pow((g + 0.055) * (1.0 / (1 + 0.055)), 2.4), @@ -181,7 +173,6 @@ struct Color { a); } _FORCE_INLINE_ Color to_srgb() const { - return Color( r < 0.0031308 ? 12.92 * r : (1.0 + 0.055) * Math::pow(r, 1.0f / 2.4f) - 0.055, g < 0.0031308 ? 12.92 * g : (1.0 + 0.055) * Math::pow(g, 1.0f / 2.4f) - 0.055, @@ -222,7 +213,6 @@ struct Color { }; bool Color::operator<(const Color &p_color) const { - if (r == p_color.r) { if (g == p_color.g) { if (b == p_color.b) { diff --git a/core/command_queue_mt.cpp b/core/command_queue_mt.cpp index 316c6ce1c4f..d1bef64e8dc 100644 --- a/core/command_queue_mt.cpp +++ b/core/command_queue_mt.cpp @@ -34,30 +34,24 @@ #include "core/project_settings.h" void CommandQueueMT::lock() { - mutex.lock(); } void CommandQueueMT::unlock() { - mutex.unlock(); } void CommandQueueMT::wait_for_flush() { - // wait one millisecond for a flush to happen OS::get_singleton()->delay_usec(1000); } CommandQueueMT::SyncSemaphore *CommandQueueMT::_alloc_sync_sem() { - int idx = -1; while (true) { - lock(); for (int i = 0; i < SYNC_SEMAPHORES; i++) { - if (!sync_sems[i].in_use) { sync_sems[i].in_use = true; idx = i; @@ -101,7 +95,6 @@ tryagain: } CommandQueueMT::CommandQueueMT(bool p_sync) { - read_ptr_and_epoch = 0; write_ptr_and_epoch = 0; dealloc_ptr = 0; @@ -112,7 +105,6 @@ CommandQueueMT::CommandQueueMT(bool p_sync) { command_mem = (uint8_t *)memalloc(command_mem_size); for (int i = 0; i < SYNC_SEMAPHORES; i++) { - sync_sems[i].in_use = false; } if (p_sync) { @@ -123,7 +115,6 @@ CommandQueueMT::CommandQueueMT(bool p_sync) { } CommandQueueMT::~CommandQueueMT() { - if (sync) memdelete(sync); memfree(command_mem); diff --git a/core/command_queue_mt.h b/core/command_queue_mt.h index fa3c4e28766..776cb0f531a 100644 --- a/core/command_queue_mt.h +++ b/core/command_queue_mt.h @@ -277,22 +277,18 @@ #define MAX_CMD_PARAMS 13 class CommandQueueMT { - struct SyncSemaphore { - Semaphore sem; bool in_use; }; struct CommandBase { - virtual void call() = 0; virtual void post(){}; virtual ~CommandBase(){}; }; struct SyncCommand : public CommandBase { - SyncSemaphore *sync_sem; virtual void post() { @@ -329,7 +325,6 @@ class CommandQueueMT { template T *allocate() { - // alloc size is size+T+safeguard uint32_t alloc_size = ((sizeof(T) + 8 - 1) & ~(8 - 1)) + 8; @@ -342,7 +337,6 @@ class CommandQueueMT { if (write_ptr < dealloc_ptr) { // behind dealloc_ptr, check that there is room if ((dealloc_ptr - write_ptr) <= alloc_size) { - // There is no more room, try to deallocate something if (dealloc_one()) { goto tryagain; @@ -395,12 +389,10 @@ class CommandQueueMT { template T *allocate_and_lock() { - lock(); T *ret; while ((ret = allocate()) == NULL) { - unlock(); // sleep a little until fetch happened and some room is made wait_for_flush(); @@ -482,7 +474,6 @@ public: } void flush_all() { - //ERR_FAIL_COND(sync); lock(); while (flush_one(false)) diff --git a/core/compressed_translation.cpp b/core/compressed_translation.cpp index 0887316a6ec..3bd66b0e6bf 100644 --- a/core/compressed_translation.cpp +++ b/core/compressed_translation.cpp @@ -37,7 +37,6 @@ extern "C" { } struct _PHashTranslationCmp { - int orig_len; CharString compressed; int offset; @@ -66,7 +65,6 @@ void PHashTranslation::generate(const Ref &p_from) { int total_string_size = 0; for (List::Element *E = keys.front(); E; E = E->next()) { - //hash string CharString cs = E->get().operator String().utf8(); uint32_t h = hash(0, cs.get_data()); @@ -109,7 +107,6 @@ void PHashTranslation::generate(const Ref &p_from) { int bucket_table_size = 0; for (int i = 0; i < size; i++) { - const Vector> &b = buckets[i]; Map &t = table.write[i]; @@ -120,10 +117,8 @@ void PHashTranslation::generate(const Ref &p_from) { int item = 0; while (item < b.size()) { - uint32_t slot = hash(d, b[item].second.get_data()); if (t.has(slot)) { - item = 0; d++; t.clear(); @@ -152,7 +147,6 @@ void PHashTranslation::generate(const Ref &p_from) { int collisions = 0; for (int i = 0; i < size; i++) { - const Map &t = table[i]; if (t.size() == 0) { htw[i] = 0xFFFFFFFF; //nothing @@ -166,7 +160,6 @@ void PHashTranslation::generate(const Ref &p_from) { btw[btindex++] = hfunc_table[i]; for (Map::Element *E = t.front(); E; E = E->next()) { - btw[btindex++] = E->key(); btw[btindex++] = compressed[E->get()].offset; btw[btindex++] = compressed[E->get()].compressed.size(); @@ -188,7 +181,6 @@ void PHashTranslation::generate(const Ref &p_from) { } bool PHashTranslation::_set(const StringName &p_name, const Variant &p_value) { - String name = p_name.operator String(); if (name == "hash_table") { hash_table = p_value; @@ -205,7 +197,6 @@ bool PHashTranslation::_set(const StringName &p_name, const Variant &p_value) { } bool PHashTranslation::_get(const StringName &p_name, Variant &r_ret) const { - String name = p_name.operator String(); if (name == "hash_table") r_ret = hash_table; @@ -220,7 +211,6 @@ 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) @@ -249,9 +239,7 @@ StringName PHashTranslation::get_message(const StringName &p_src_text) const { int idx = -1; for (int i = 0; i < bucket.size; i++) { - if (bucket.elem[i].key == h) { - idx = i; break; } @@ -262,13 +250,11 @@ StringName PHashTranslation::get_message(const StringName &p_src_text) const { } if (bucket.elem[idx].comp_size == bucket.elem[idx].uncomp_size) { - String rstr; rstr.parse_utf8(&sptr[bucket.elem[idx].str_offset], bucket.elem[idx].uncomp_size); return rstr; } else { - CharString uncomp; uncomp.resize(bucket.elem[idx].uncomp_size + 1); smaz_decompress(&sptr[bucket.elem[idx].str_offset], bucket.elem[idx].comp_size, uncomp.ptrw(), bucket.elem[idx].uncomp_size); @@ -279,14 +265,12 @@ StringName PHashTranslation::get_message(const StringName &p_src_text) const { } void PHashTranslation::_get_property_list(List *p_list) const { - p_list->push_back(PropertyInfo(Variant::POOL_INT_ARRAY, "hash_table")); p_list->push_back(PropertyInfo(Variant::POOL_INT_ARRAY, "bucket_table")); p_list->push_back(PropertyInfo(Variant::POOL_BYTE_ARRAY, "strings")); p_list->push_back(PropertyInfo(Variant::OBJECT, "load_from", PROPERTY_HINT_RESOURCE_TYPE, "Translation", PROPERTY_USAGE_EDITOR)); } void PHashTranslation::_bind_methods() { - ClassDB::bind_method(D_METHOD("generate", "from"), &PHashTranslation::generate); } diff --git a/core/compressed_translation.h b/core/compressed_translation.h index c3190a38070..774601665ed 100644 --- a/core/compressed_translation.h +++ b/core/compressed_translation.h @@ -34,7 +34,6 @@ #include "core/translation.h" class PHashTranslation : public Translation { - GDCLASS(PHashTranslation, Translation); //this translation uses a sort of modified perfect hash algorithm @@ -48,12 +47,10 @@ class PHashTranslation : public Translation { PoolVector strings; struct Bucket { - int size; uint32_t func; struct Elem { - uint32_t key; uint32_t str_offset; uint32_t comp_size; @@ -64,11 +61,9 @@ class PHashTranslation : public Translation { }; _FORCE_INLINE_ uint32_t hash(uint32_t d, const char *p_str) const { - if (d == 0) d = 0x1000193; while (*p_str) { - d = (d * 0x1000193) ^ uint32_t(*p_str); p_str++; } diff --git a/core/core_string_names.h b/core/core_string_names.h index 46e351cc0ea..c9246a9320c 100644 --- a/core/core_string_names.h +++ b/core/core_string_names.h @@ -34,7 +34,6 @@ #include "core/string_name.h" class CoreStringNames { - friend void register_core_types(); friend void unregister_core_types(); diff --git a/core/cowdata.h b/core/cowdata.h index dbf4e28cea5..bb42be8bc76 100644 --- a/core/cowdata.h +++ b/core/cowdata.h @@ -63,7 +63,6 @@ private: // internal helpers _FORCE_INLINE_ SafeNumeric *_get_refcount() const { - if (!_ptr) return NULL; @@ -71,7 +70,6 @@ private: } _FORCE_INLINE_ uint32_t *_get_size() const { - if (!_ptr) return NULL; @@ -79,7 +77,6 @@ private: } _FORCE_INLINE_ T *_get_data() const { - if (!_ptr) return NULL; return reinterpret_cast(_ptr); @@ -139,21 +136,18 @@ public: _FORCE_INLINE_ bool empty() const { return _ptr == 0; } _FORCE_INLINE_ void set(int p_index, const T &p_elem) { - CRASH_BAD_INDEX(p_index, size()); _copy_on_write(); _get_data()[p_index] = p_elem; } _FORCE_INLINE_ T &get_m(int p_index) { - CRASH_BAD_INDEX(p_index, size()); _copy_on_write(); return _get_data()[p_index]; } _FORCE_INLINE_ const T &get(int p_index) const { - CRASH_BAD_INDEX(p_index, size()); return _get_data()[p_index]; @@ -162,12 +156,10 @@ public: Error resize(int p_size); _FORCE_INLINE_ void remove(int p_index) { - ERR_FAIL_INDEX(p_index, size()); T *p = ptrw(); int len = size(); for (int i = p_index; i < len - 1; i++) { - p[i] = p[i + 1]; }; @@ -175,7 +167,6 @@ 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--) @@ -194,7 +185,6 @@ public: template void CowData::_unref(void *p_data) { - if (!p_data) return; @@ -220,7 +210,6 @@ void CowData::_unref(void *p_data) { template uint32_t CowData::_copy_on_write() { - if (!_ptr) return 0; @@ -258,7 +247,6 @@ uint32_t CowData::_copy_on_write() { template Error CowData::resize(int p_size) { - ERR_FAIL_COND_V(p_size < 0, ERR_INVALID_PARAMETER); int current_size = size(); @@ -281,7 +269,6 @@ Error CowData::resize(int p_size) { ERR_FAIL_COND_V(!_get_alloc_size_checked(p_size, &alloc_size), ERR_OUT_OF_MEMORY); if (p_size > current_size) { - if (alloc_size != current_alloc_size) { if (current_size == 0) { // alloc from scratch @@ -314,7 +301,6 @@ Error CowData::resize(int p_size) { *_get_size() = p_size; } else if (p_size < current_size) { - if (!__has_trivial_destructor(T)) { // deinitialize no longer needed elements for (uint32_t i = p_size; i < *_get_size(); i++) { @@ -362,7 +348,6 @@ void CowData::_ref(const CowData *p_from) { template void CowData::_ref(const CowData &p_from) { - if (_ptr == p_from._ptr) return; // self assign, do nothing. @@ -379,13 +364,11 @@ void CowData::_ref(const CowData &p_from) { template CowData::CowData() { - _ptr = NULL; } template CowData::~CowData() { - _unref(_ptr); } diff --git a/core/crypto/crypto.cpp b/core/crypto/crypto.cpp index e18e84bc45f..e4709326afc 100644 --- a/core/crypto/crypto.cpp +++ b/core/crypto/crypto.cpp @@ -74,7 +74,6 @@ Crypto *Crypto::create() { } void Crypto::load_default_certificates(String p_path) { - if (_load_default_certificates) _load_default_certificates(p_path); } @@ -95,7 +94,6 @@ Crypto::Crypto() { /// Resource loader/saver RES ResourceFormatLoaderCrypto::load(const String &p_path, const String &p_original_path, Error *r_error) { - String el = p_path.get_extension().to_lower(); if (el == "crt") { X509Certificate *cert = X509Certificate::create(); @@ -117,19 +115,16 @@ RES ResourceFormatLoaderCrypto::load(const String &p_path, const String &p_origi } void ResourceFormatLoaderCrypto::get_recognized_extensions(List *p_extensions) const { - p_extensions->push_back("crt"); p_extensions->push_back("key"); p_extensions->push_back("pub"); } bool ResourceFormatLoaderCrypto::handles_type(const String &p_type) const { - return p_type == "X509Certificate" || p_type == "CryptoKey"; } String ResourceFormatLoaderCrypto::get_resource_type(const String &p_path) const { - String el = p_path.get_extension().to_lower(); if (el == "crt") return "X509Certificate"; @@ -139,7 +134,6 @@ String ResourceFormatLoaderCrypto::get_resource_type(const String &p_path) const } Error ResourceFormatSaverCrypto::save(const String &p_path, const RES &p_resource, uint32_t p_flags) { - Error err; Ref cert = p_resource; Ref key = p_resource; @@ -156,7 +150,6 @@ Error ResourceFormatSaverCrypto::save(const String &p_path, const RES &p_resourc } void ResourceFormatSaverCrypto::get_recognized_extensions(const RES &p_resource, List *p_extensions) const { - const X509Certificate *cert = Object::cast_to(*p_resource); const CryptoKey *key = Object::cast_to(*p_resource); if (cert) { @@ -170,6 +163,5 @@ void ResourceFormatSaverCrypto::get_recognized_extensions(const RES &p_resource, } } bool ResourceFormatSaverCrypto::recognize(const RES &p_resource) const { - return Object::cast_to(*p_resource) || Object::cast_to(*p_resource); } diff --git a/core/crypto/crypto_core.h b/core/crypto/crypto_core.h index 3784943c31b..76ba54b4ebb 100644 --- a/core/crypto/crypto_core.h +++ b/core/crypto/crypto_core.h @@ -34,10 +34,8 @@ #include "core/reference.h" class CryptoCore { - public: class MD5Context { - private: void *ctx; // To include, or not to include... @@ -51,7 +49,6 @@ public: }; class SHA1Context { - private: void *ctx; // To include, or not to include... @@ -65,7 +62,6 @@ public: }; class SHA256Context { - private: void *ctx; // To include, or not to include... @@ -79,7 +75,6 @@ public: }; class AESContext { - private: void *ctx; // To include, or not to include... diff --git a/core/crypto/hashing_context.cpp b/core/crypto/hashing_context.cpp index e7e13b60054..ccb7f5bdee3 100644 --- a/core/crypto/hashing_context.cpp +++ b/core/crypto/hashing_context.cpp @@ -104,7 +104,6 @@ void HashingContext::_create_ctx(HashType p_type) { } void HashingContext::_delete_ctx() { - switch (type) { case HASH_MD5: memdelete((CryptoCore::MD5Context *)ctx); diff --git a/core/dictionary.cpp b/core/dictionary.cpp index faf21e06866..1024276f6f3 100644 --- a/core/dictionary.cpp +++ b/core/dictionary.cpp @@ -35,13 +35,11 @@ #include "core/variant.h" struct DictionaryPrivate { - SafeRefCount refcount; OrderedHashMap variant_map; }; void Dictionary::get_key_list(List *p_keys) const { - if (_p->variant_map.empty()) return; @@ -51,7 +49,6 @@ void Dictionary::get_key_list(List *p_keys) const { } Variant Dictionary::get_key_at_index(int p_index) const { - int index = 0; for (OrderedHashMap::Element E = _p->variant_map.front(); E; E = E.next()) { if (index == p_index) { @@ -64,7 +61,6 @@ Variant Dictionary::get_key_at_index(int p_index) const { } Variant Dictionary::get_value_at_index(int p_index) const { - int index = 0; for (OrderedHashMap::Element E = _p->variant_map.front(); E; E = E.next()) { if (index == p_index) { @@ -77,16 +73,13 @@ Variant Dictionary::get_value_at_index(int p_index) const { } Variant &Dictionary::operator[](const Variant &p_key) { - return _p->variant_map[p_key]; } const Variant &Dictionary::operator[](const Variant &p_key) const { - return _p->variant_map[p_key]; } const Variant *Dictionary::getptr(const Variant &p_key) const { - OrderedHashMap::ConstElement E = ((const OrderedHashMap *)&_p->variant_map)->find(p_key); if (!E) @@ -95,7 +88,6 @@ const Variant *Dictionary::getptr(const Variant &p_key) const { } Variant *Dictionary::getptr(const Variant &p_key) { - OrderedHashMap::Element E = _p->variant_map.find(p_key); if (!E) @@ -104,7 +96,6 @@ Variant *Dictionary::getptr(const Variant &p_key) { } Variant Dictionary::get_valid(const Variant &p_key) const { - OrderedHashMap::ConstElement E = ((const OrderedHashMap *)&_p->variant_map)->find(p_key); if (!E) @@ -122,16 +113,13 @@ Variant Dictionary::get(const Variant &p_key, const Variant &p_default) const { } int Dictionary::size() const { - return _p->variant_map.size(); } bool Dictionary::empty() const { - return !_p->variant_map.size(); } bool Dictionary::has(const Variant &p_key) const { - return _p->variant_map.has(p_key); } @@ -145,22 +133,18 @@ bool Dictionary::has_all(const Array &p_keys) const { } bool Dictionary::erase(const Variant &p_key) { - return _p->variant_map.erase(p_key); } bool Dictionary::operator==(const Dictionary &p_dictionary) const { - return _p == p_dictionary._p; } bool Dictionary::operator!=(const Dictionary &p_dictionary) const { - return _p != p_dictionary._p; } void Dictionary::_ref(const Dictionary &p_from) const { - //make a copy first (thread safe) if (!p_from._p->refcount.ref()) return; // couldn't copy @@ -176,12 +160,10 @@ void Dictionary::_ref(const Dictionary &p_from) const { } void Dictionary::clear() { - _p->variant_map.clear(); } void Dictionary::_unref() const { - ERR_FAIL_COND(!_p); if (_p->refcount.unref()) { memdelete(_p); @@ -189,7 +171,6 @@ void Dictionary::_unref() const { _p = NULL; } uint32_t Dictionary::hash() const { - uint32_t h = hash_djb2_one_32(Variant::DICTIONARY); for (OrderedHashMap::Element E = _p->variant_map.front(); E; E = E.next()) { @@ -201,7 +182,6 @@ uint32_t Dictionary::hash() const { } Array Dictionary::keys() const { - Array varr; if (_p->variant_map.empty()) return varr; @@ -218,7 +198,6 @@ Array Dictionary::keys() const { } Array Dictionary::values() const { - Array varr; if (_p->variant_map.empty()) return varr; @@ -235,7 +214,6 @@ Array Dictionary::values() const { } const Variant *Dictionary::next(const Variant *p_key) const { - if (p_key == NULL) { // caller wants to get the first element if (_p->variant_map.front()) @@ -250,7 +228,6 @@ const Variant *Dictionary::next(const Variant *p_key) const { } Dictionary Dictionary::duplicate(bool p_deep) const { - Dictionary n; for (OrderedHashMap::Element E = _p->variant_map.front(); E; E = E.next()) { @@ -261,7 +238,6 @@ Dictionary Dictionary::duplicate(bool p_deep) const { } void Dictionary::operator=(const Dictionary &p_dictionary) { - _ref(p_dictionary); } @@ -275,11 +251,9 @@ Dictionary::Dictionary(const Dictionary &p_from) { } Dictionary::Dictionary() { - _p = memnew(DictionaryPrivate); _p->refcount.init(); } Dictionary::~Dictionary() { - _unref(); } diff --git a/core/dictionary.h b/core/dictionary.h index 841aa8dd703..3b65c4f3734 100644 --- a/core/dictionary.h +++ b/core/dictionary.h @@ -40,7 +40,6 @@ class Variant; struct DictionaryPrivate; class Dictionary { - mutable DictionaryPrivate *_p; void _ref(const Dictionary &p_from) const; diff --git a/core/engine.cpp b/core/engine.cpp index 6281df94f18..63e973fd53a 100644 --- a/core/engine.cpp +++ b/core/engine.cpp @@ -37,12 +37,10 @@ #include "core/version_hash.gen.h" void Engine::set_iterations_per_second(int p_ips) { - ERR_FAIL_COND_MSG(p_ips <= 0, "Engine iterations per second must be greater than 0."); ips = p_ips; } int Engine::get_iterations_per_second() const { - return ips; } @@ -65,32 +63,26 @@ int Engine::get_target_fps() const { } uint64_t Engine::get_frames_drawn() { - return frames_drawn; } void Engine::set_frame_delay(uint32_t p_msec) { - _frame_delay = p_msec; } uint32_t Engine::get_frame_delay() const { - return _frame_delay; } void Engine::set_time_scale(float p_scale) { - _time_scale = p_scale; } float Engine::get_time_scale() const { - return _time_scale; } Dictionary Engine::get_version_info() const { - Dictionary dict; dict["major"] = VERSION_MAJOR; dict["minor"] = VERSION_MINOR; @@ -187,25 +179,21 @@ String Engine::get_license_text() const { } void Engine::add_singleton(const Singleton &p_singleton) { - singletons.push_back(p_singleton); singleton_ptrs[p_singleton.name] = p_singleton.ptr; } Object *Engine::get_singleton_object(const String &p_name) const { - const Map::Element *E = singleton_ptrs.find(p_name); ERR_FAIL_COND_V_MSG(!E, NULL, "Failed to retrieve non-existent singleton '" + p_name + "'."); return E->get(); }; bool Engine::has_singleton(const String &p_name) const { - return singleton_ptrs.has(p_name); }; void Engine::get_singletons(List *p_singletons) { - for (List::Element *E = singletons.front(); E; E = E->next()) p_singletons->push_back(E->get()); } @@ -217,7 +205,6 @@ Engine *Engine::get_singleton() { } Engine::Engine() { - singleton = this; frames_drawn = 0; ips = 60; diff --git a/core/engine.h b/core/engine.h index 7ddae0ebbe2..ec1305760f5 100644 --- a/core/engine.h +++ b/core/engine.h @@ -37,7 +37,6 @@ #include "core/vector.h" class Engine { - public: struct Singleton { StringName name; diff --git a/core/error_macros.cpp b/core/error_macros.cpp index 37ab3132dfc..d956c1706b3 100644 --- a/core/error_macros.cpp +++ b/core/error_macros.cpp @@ -37,7 +37,6 @@ static ErrorHandlerList *error_handler_list = NULL; void add_error_handler(ErrorHandlerList *p_handler) { - _global_lock(); p_handler->next = error_handler_list; error_handler_list = p_handler; @@ -45,16 +44,13 @@ void add_error_handler(ErrorHandlerList *p_handler) { } void remove_error_handler(ErrorHandlerList *p_handler) { - _global_lock(); ErrorHandlerList *prev = NULL; ErrorHandlerList *l = error_handler_list; while (l) { - if (l == p_handler) { - if (prev) prev->next = l->next; else @@ -77,13 +73,11 @@ void _err_print_error(const char *p_function, const char *p_file, int p_line, co } void _err_print_error(const char *p_function, const char *p_file, int p_line, const char *p_error, const char *p_message, ErrorHandlerType p_type) { - OS::get_singleton()->print_error(p_function, p_file, p_line, p_error, p_message, (Logger::ErrorType)p_type); _global_lock(); ErrorHandlerList *l = error_handler_list; while (l) { - l->errfunc(l->userdata, p_function, p_file, p_line, p_error, p_message, p_type); l = l->next; } @@ -104,7 +98,6 @@ void _err_print_error(const char *p_function, const char *p_file, int p_line, co } void _err_print_index_error(const char *p_function, const char *p_file, int p_line, int64_t p_index, int64_t p_size, const char *p_index_str, const char *p_size_str, const char *p_message, bool fatal) { - String fstr(fatal ? "FATAL: " : ""); String err(fstr + "Index " + p_index_str + " = " + itos(p_index) + " is out of bounds (" + p_size_str + " = " + itos(p_size) + ")."); _err_print_error(p_function, p_file, p_line, err.utf8().get_data(), p_message); diff --git a/core/error_macros.h b/core/error_macros.h index c9ab2d58039..3248cf5efb3 100644 --- a/core/error_macros.h +++ b/core/error_macros.h @@ -61,7 +61,6 @@ class String; typedef void (*ErrorHandlerFunc)(void *, const char *, const char *, int p_line, const char *, const char *, ErrorHandlerType p_type); struct ErrorHandlerList { - ErrorHandlerFunc errfunc; void *userdata; diff --git a/core/func_ref.cpp b/core/func_ref.cpp index 233b748f3e0..a28d740e59a 100644 --- a/core/func_ref.cpp +++ b/core/func_ref.cpp @@ -31,7 +31,6 @@ #include "func_ref.h" Variant FuncRef::call_func(const Variant **p_args, int p_argcount, Variant::CallError &r_error) { - if (id == 0) { r_error.error = Variant::CallError::CALL_ERROR_INSTANCE_IS_NULL; return Variant(); @@ -47,7 +46,6 @@ Variant FuncRef::call_func(const Variant **p_args, int p_argcount, Variant::Call } Variant FuncRef::call_funcv(const Array &p_args) { - ERR_FAIL_COND_V(id == 0, Variant()); Object *obj = ObjectDB::get_instance(id); @@ -58,13 +56,11 @@ Variant FuncRef::call_funcv(const Array &p_args) { } void FuncRef::set_instance(Object *p_obj) { - ERR_FAIL_NULL(p_obj); id = p_obj->get_instance_id(); } void FuncRef::set_function(const StringName &p_func) { - function = p_func; } @@ -84,7 +80,6 @@ bool FuncRef::is_valid() const { } void FuncRef::_bind_methods() { - { MethodInfo mi; mi.name = "call_func"; diff --git a/core/func_ref.h b/core/func_ref.h index c4d369ee9cd..e6c60423669 100644 --- a/core/func_ref.h +++ b/core/func_ref.h @@ -34,7 +34,6 @@ #include "core/reference.h" class FuncRef : public Reference { - GDCLASS(FuncRef, Reference); ObjectID id; StringName function; diff --git a/core/global_constants.cpp b/core/global_constants.cpp index b460c2960e3..b1b804eacf9 100644 --- a/core/global_constants.cpp +++ b/core/global_constants.cpp @@ -36,7 +36,6 @@ #include "core/variant.h" struct _GlobalConstant { - #ifdef DEBUG_METHODS_ENABLED StringName enum_name; #endif @@ -92,7 +91,6 @@ VARIANT_ENUM_CAST(JoystickList); VARIANT_ENUM_CAST(MidiMessageList); void register_global_constants() { - //{ KEY_BACKSPACE, VK_BACK },// (0x08) // backspace BIND_GLOBAL_ENUM_CONSTANT(MARGIN_LEFT); @@ -667,33 +665,27 @@ void register_global_constants() { } void unregister_global_constants() { - _global_constants.clear(); } int GlobalConstants::get_global_constant_count() { - return _global_constants.size(); } #ifdef DEBUG_METHODS_ENABLED StringName GlobalConstants::get_global_constant_enum(int p_idx) { - return _global_constants[p_idx].enum_name; } #else StringName GlobalConstants::get_global_constant_enum(int p_idx) { - return StringName(); } #endif const char *GlobalConstants::get_global_constant_name(int p_idx) { - return _global_constants[p_idx].name; } int GlobalConstants::get_global_constant_value(int p_idx) { - return _global_constants[p_idx].value; } diff --git a/core/hash_map.h b/core/hash_map.h index d5dfcc4aee4..d80577800cd 100644 --- a/core/hash_map.h +++ b/core/hash_map.h @@ -59,7 +59,6 @@ template ((1 << hash_table_power) * RELATIONSHIP)) { @@ -129,17 +125,14 @@ private: new_hash_table_power = hash_table_power + 1; while ((int)elements > ((1 << new_hash_table_power) * RELATIONSHIP)) { - new_hash_table_power++; } } else if ((hash_table_power > (int)MIN_HASH_TABLE_POWER) && ((int)elements < ((1 << (hash_table_power - 1)) * RELATIONSHIP))) { - /* rehash down */ new_hash_table_power = hash_table_power - 1; while ((int)elements < ((1 << (new_hash_table_power - 1)) * RELATIONSHIP)) { - new_hash_table_power--; } @@ -154,15 +147,12 @@ private: ERR_FAIL_COND_MSG(!new_hash_table, "Out of memory."); for (int i = 0; i < (1 << new_hash_table_power); i++) { - new_hash_table[i] = 0; } if (hash_table) { for (int i = 0; i < (1 << hash_table_power); i++) { - while (hash_table[i]) { - Element *se = hash_table[i]; hash_table[i] = se->next; int new_pos = se->hash & ((1 << new_hash_table_power) - 1); @@ -179,17 +169,14 @@ private: /* I want to have only one function.. */ _FORCE_INLINE_ const Element *get_element(const TKey &p_key) const { - uint32_t hash = Hasher::hash(p_key); uint32_t index = hash & ((1 << hash_table_power) - 1); Element *e = hash_table[index]; while (e) { - /* checking hash first avoids comparing key, which may take longer */ if (e->hash == hash && Comparator::compare(e->pair.key, p_key)) { - /* the pair exists in this hashtable, so just update data */ return e; } @@ -201,7 +188,6 @@ private: } Element *create_element(const TKey &p_key) { - /* if element doesn't exist, create it */ Element *e = memnew(Element); ERR_FAIL_COND_V_MSG(!e, NULL, "Out of memory."); @@ -219,7 +205,6 @@ private: } void copy_from(const HashMap &p_t) { - if (&p_t == this) return; /* much less bother with that */ @@ -233,13 +218,11 @@ private: elements = p_t.elements; for (int i = 0; i < (1 << p_t.hash_table_power); i++) { - hash_table[i] = NULL; const Element *e = p_t.hash_table[i]; while (e) { - Element *le = memnew(Element); /* local element */ *le = *e; /* copy data */ @@ -259,7 +242,6 @@ public: } Element *set(const Pair &p_pair) { - Element *e = NULL; if (!hash_table) make_hash_table(); // if no table, make one @@ -269,7 +251,6 @@ public: /* 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) return NULL; @@ -281,7 +262,6 @@ public: } bool has(const TKey &p_key) const { - return getptr(p_key) != NULL; } @@ -292,14 +272,12 @@ public: */ const TData &get(const TKey &p_key) const { - const TData *res = getptr(p_key); CRASH_COND_MSG(!res, "Map key not found."); return *res; } TData &get(const TKey &p_key) { - TData *res = getptr(p_key); CRASH_COND_MSG(!res, "Map key not found."); return *res; @@ -311,7 +289,6 @@ public: */ _FORCE_INLINE_ TData *getptr(const TKey &p_key) { - if (unlikely(!hash_table)) return NULL; @@ -324,7 +301,6 @@ public: } _FORCE_INLINE_ const TData *getptr(const TKey &p_key) const { - if (unlikely(!hash_table)) return NULL; @@ -343,7 +319,6 @@ public: template _FORCE_INLINE_ TData *custom_getptr(C p_custom_key, uint32_t p_custom_hash) { - if (unlikely(!hash_table)) return NULL; @@ -353,10 +328,8 @@ public: Element *e = hash_table[index]; while (e) { - /* checking hash first avoids comparing key, which may take longer */ if (e->hash == hash && Comparator::compare(e->pair.key, p_custom_key)) { - /* the pair exists in this hashtable, so just update data */ return &e->pair.data; } @@ -369,7 +342,6 @@ public: template _FORCE_INLINE_ const TData *custom_getptr(C p_custom_key, uint32_t p_custom_hash) const { - if (unlikely(!hash_table)) return NULL; @@ -379,10 +351,8 @@ public: const Element *e = hash_table[index]; while (e) { - /* checking hash first avoids comparing key, which may take longer */ if (e->hash == hash && Comparator::compare(e->pair.key, p_custom_key)) { - /* the pair exists in this hashtable, so just update data */ return &e->pair.data; } @@ -398,7 +368,6 @@ public: */ bool erase(const TKey &p_key) { - if (unlikely(!hash_table)) return false; @@ -408,12 +377,9 @@ public: Element *e = hash_table[index]; Element *p = NULL; while (e) { - /* checking hash first avoids comparing key, which may take longer */ if (e->hash == hash && Comparator::compare(e->pair.key, p_key)) { - if (p) { - p->next = e->next; } else { //begin of list @@ -451,7 +417,6 @@ public: /* if we made it up to here, the pair doesn't exist, create */ if (!e) { - e = create_element(p_key); CRASH_COND(!e); check_hash_table(); // perform mantenience routine @@ -476,14 +441,12 @@ public: * */ const TKey *next(const TKey *p_key) const { - if (unlikely(!hash_table)) return NULL; if (!p_key) { /* get the first key */ for (int i = 0; i < (1 << hash_table_power); i++) { - if (hash_table[i]) { return &hash_table[i]->pair.key; } @@ -501,7 +464,6 @@ public: uint32_t index = e->hash & ((1 << hash_table_power) - 1); index++; for (int i = index; i < (1 << hash_table_power); i++) { - if (hash_table[i]) { return &hash_table[i]->pair.key; } @@ -515,23 +477,18 @@ public: } inline unsigned int size() const { - return elements; } inline bool empty() const { - return elements == 0; } void clear() { - /* clean up */ if (hash_table) { for (int i = 0; i < (1 << hash_table_power); i++) { - while (hash_table[i]) { - Element *e = hash_table[i]; hash_table[i] = e->next; memdelete(e); @@ -547,7 +504,6 @@ public: } void operator=(const HashMap &p_table) { - copy_from(p_table); } @@ -561,7 +517,6 @@ public: if (unlikely(!hash_table)) return; for (int i = 0; i < (1 << hash_table_power); i++) { - Element *e = hash_table[i]; while (e) { *p_pairs = &e->pair; @@ -575,7 +530,6 @@ public: if (unlikely(!hash_table)) return; for (int i = 0; i < (1 << hash_table_power); i++) { - Element *e = hash_table[i]; while (e) { p_keys->push_back(e->pair.key); @@ -585,7 +539,6 @@ public: } HashMap(const HashMap &p_table) { - hash_table = NULL; elements = 0; hash_table_power = 0; @@ -594,7 +547,6 @@ public: } ~HashMap() { - clear(); } }; diff --git a/core/hashfuncs.h b/core/hashfuncs.h index f83f055bf70..8791248af66 100644 --- a/core/hashfuncs.h +++ b/core/hashfuncs.h @@ -48,7 +48,6 @@ * @return 32-bits hashcode */ static inline uint32_t hash_djb2(const char *p_cstr) { - const unsigned char *chr = (const unsigned char *)p_cstr; uint32_t hash = 5381; uint32_t c; @@ -60,7 +59,6 @@ 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++) @@ -70,7 +68,6 @@ static inline uint32_t hash_djb2_buffer(const uint8_t *p_buff, int p_len, uint32 } static inline uint32_t hash_djb2_one_32(uint32_t p_in, uint32_t p_prev = 5381) { - return ((p_prev << 5) + p_prev) + p_in; } @@ -104,7 +101,6 @@ static inline uint32_t hash_djb2_one_float(double p_in, uint32_t p_prev = 5381) template static inline uint32_t make_uint32_t(T p_in) { - union { T t; uint32_t _u32; @@ -115,13 +111,11 @@ static inline uint32_t make_uint32_t(T p_in) { } static inline uint64_t hash_djb2_one_64(uint64_t p_in, uint64_t p_prev = 5381) { - return ((p_prev << 5) + p_prev) + p_in; } template static inline uint64_t make_uint64_t(T p_in) { - union { T t; uint64_t _u64; @@ -133,7 +127,6 @@ static inline uint64_t make_uint64_t(T p_in) { } struct HashMapHasherDefault { - static _FORCE_INLINE_ uint32_t hash(const String &p_string) { return p_string.hash(); } static _FORCE_INLINE_ uint32_t hash(const char *p_cstr) { return hash_djb2(p_cstr); } static _FORCE_INLINE_ uint32_t hash(const uint64_t p_int) { return hash_one_uint64(p_int); } diff --git a/core/image.cpp b/core/image.cpp index b2f493a50d6..3ada37badf1 100644 --- a/core/image.cpp +++ b/core/image.cpp @@ -88,7 +88,6 @@ SaveEXRFunc Image::save_exr_func = NULL; SavePNGBufferFunc Image::save_png_buffer_func = NULL; void Image::_put_pixelb(int p_x, int p_y, uint32_t p_pixelsize, uint8_t *p_data, const uint8_t *p_pixel) { - uint32_t ofs = (p_y * width + p_x) * p_pixelsize; for (uint32_t i = 0; i < p_pixelsize; i++) { @@ -97,7 +96,6 @@ void Image::_put_pixelb(int p_x, int p_y, uint32_t p_pixelsize, uint8_t *p_data, } void Image::_get_pixelb(int p_x, int p_y, uint32_t p_pixelsize, const uint8_t *p_data, uint8_t *p_pixel) { - uint32_t ofs = (p_y * width + p_x) * p_pixelsize; for (uint32_t i = 0; i < p_pixelsize; i++) { @@ -106,7 +104,6 @@ void Image::_get_pixelb(int p_x, int p_y, uint32_t p_pixelsize, const uint8_t *p } int Image::get_format_pixel_size(Format p_format) { - switch (p_format) { case FORMAT_L8: return 1; //luminance @@ -189,7 +186,6 @@ int Image::get_format_pixel_size(Format p_format) { } void Image::get_format_min_pixel_size(Format p_format, int &r_w, int &r_h) { - switch (p_format) { case FORMAT_DXT1: //s3tc bc1 case FORMAT_DXT3: //bc2 @@ -202,25 +198,21 @@ void Image::get_format_min_pixel_size(Format p_format, int &r_w, int &r_h) { } break; case FORMAT_PVRTC2: case FORMAT_PVRTC2A: { - r_w = 16; r_h = 8; } break; case FORMAT_PVRTC4A: case FORMAT_PVRTC4: { - r_w = 8; r_h = 8; } break; case FORMAT_ETC: { - r_w = 4; r_h = 4; } break; case FORMAT_BPTC_RGBA: case FORMAT_BPTC_RGBF: case FORMAT_BPTC_RGBFU: { - r_w = 4; r_h = 4; } break; @@ -231,7 +223,6 @@ void Image::get_format_min_pixel_size(Format p_format, int &r_w, int &r_h) { case FORMAT_ETC2_RGB8: case FORMAT_ETC2_RGBA8: case FORMAT_ETC2_RGB8A1: { - r_w = 4; r_h = 4; @@ -245,7 +236,6 @@ 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) return 1; else if (p_format == FORMAT_PVRTC2 || p_format == FORMAT_PVRTC2A) @@ -255,7 +245,6 @@ int Image::get_format_pixel_rshift(Format p_format) { } int Image::get_format_block_size(Format p_format) { - switch (p_format) { case FORMAT_DXT1: //s3tc bc1 case FORMAT_DXT3: //bc2 @@ -267,22 +256,18 @@ int Image::get_format_block_size(Format p_format) { } case FORMAT_PVRTC2: case FORMAT_PVRTC2A: { - return 4; } case FORMAT_PVRTC4A: case FORMAT_PVRTC4: { - return 4; } case FORMAT_ETC: { - return 4; } case FORMAT_BPTC_RGBA: case FORMAT_BPTC_RGBF: case FORMAT_BPTC_RGBFU: { - return 4; } case FORMAT_ETC2_R11: //etc2 @@ -292,7 +277,6 @@ int Image::get_format_block_size(Format p_format) { case FORMAT_ETC2_RGB8: case FORMAT_ETC2_RGBA8: case FORMAT_ETC2_RGB8A1: { - return 4; } default: { @@ -303,7 +287,6 @@ int Image::get_format_block_size(Format p_format) { } void Image::_get_mipmap_offset_and_size(int p_mipmap, int &r_offset, int &r_width, int &r_height) const { - int w = width; int h = height; int ofs = 0; @@ -333,7 +316,6 @@ void Image::_get_mipmap_offset_and_size(int p_mipmap, int &r_offset, int &r_widt } int Image::get_mipmap_offset(int p_mipmap) const { - ERR_FAIL_INDEX_V(p_mipmap, get_mipmap_count() + 1, -1); int ofs, w, h; @@ -342,7 +324,6 @@ int Image::get_mipmap_offset(int p_mipmap) const { } void Image::get_mipmap_offset_and_size(int p_mipmap, int &r_ofs, int &r_size) const { - int ofs, w, h; _get_mipmap_offset_and_size(p_mipmap, ofs, w, h); int ofs2; @@ -352,7 +333,6 @@ void Image::get_mipmap_offset_and_size(int p_mipmap, int &r_ofs, int &r_size) co } void Image::get_mipmap_offset_size_and_dimensions(int p_mipmap, int &r_ofs, int &r_size, int &w, int &h) const { - int ofs; _get_mipmap_offset_and_size(p_mipmap, ofs, w, h); int ofs2, w2, h2; @@ -362,27 +342,22 @@ void Image::get_mipmap_offset_size_and_dimensions(int p_mipmap, int &r_ofs, int } int Image::get_width() const { - return width; } int Image::get_height() const { - return height; } Vector2 Image::get_size() const { - return Vector2(width, height); } bool Image::has_mipmaps() const { - return mipmaps; } int Image::get_mipmap_count() const { - if (mipmaps) return get_image_required_mipmaps(width, height, format); else @@ -392,12 +367,10 @@ int Image::get_mipmap_count() const { //using template generates perfectly optimized code due to constant expression reduction and unused variable removal present in all compilers template static void _convert(int p_width, int p_height, const uint8_t *p_src, uint8_t *p_dst) { - uint32_t max_bytes = MAX(read_bytes, write_bytes); for (int y = 0; y < p_height; y++) { for (int x = 0; x < p_width; x++) { - const uint8_t *rofs = &p_src[((y * p_width) + x) * (read_bytes + (read_alpha ? 1 : 0))]; uint8_t *wofs = &p_dst[((y * p_width) + x) * (write_bytes + (write_alpha ? 1 : 0))]; @@ -408,9 +381,7 @@ static void _convert(int p_width, int p_height, const uint8_t *p_src, uint8_t *p rgba[1] = rofs[0]; rgba[2] = rofs[0]; } else { - for (uint32_t i = 0; i < max_bytes; i++) { - rgba[i] = (i < read_bytes) ? rofs[i] : 0; } } @@ -424,7 +395,6 @@ static void _convert(int p_width, int p_height, const uint8_t *p_src, uint8_t *p wofs[0] = uint8_t((uint16_t(rofs[0]) + uint16_t(rofs[1]) + uint16_t(rofs[2])) / 3); } else { for (uint32_t i = 0; i < write_bytes; i++) { - wofs[i] = rgba[i]; } } @@ -437,7 +407,6 @@ 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) return; @@ -447,11 +416,9 @@ void Image::convert(Format p_new_format) { ERR_FAIL_COND_MSG(write_lock.ptr(), "Cannot convert image when it is locked."); if (format > FORMAT_RGBE9995 || p_new_format > FORMAT_RGBE9995) { - ERR_FAIL_MSG("Cannot convert to <-> from compressed formats. Use compress() and decompress() instead."); } else if (format > FORMAT_RGBA8 || p_new_format > FORMAT_RGBA8) { - //use put/set pixel which is slower but works with non byte formats Image new_img(width, height, 0, p_new_format); lock(); @@ -459,7 +426,6 @@ void Image::convert(Format p_new_format) { for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { - new_img.set_pixel(i, j, get_pixel(i, j)); } } @@ -487,7 +453,6 @@ void Image::convert(Format p_new_format) { int conversion_type = format | p_new_format << 8; switch (conversion_type) { - case FORMAT_L8 | (FORMAT_LA8 << 8): _convert<1, false, 1, true, true, true>(width, height, rptr, wptr); break; @@ -592,12 +557,10 @@ void Image::convert(Format p_new_format) { } Image::Format Image::get_format() const { - return format; } static double _bicubic_interp_kernel(double x) { - x = ABS(x); double bc = 0; @@ -612,7 +575,6 @@ static double _bicubic_interp_kernel(double x) { template static void _scale_cubic(const uint8_t *__restrict p_src, uint8_t *__restrict p_dst, uint32_t p_src_width, uint32_t p_src_height, uint32_t p_dst_width, uint32_t p_dst_height) { - // get source image size int width = p_src_width; int height = p_src_height; @@ -696,7 +658,6 @@ static void _scale_cubic(const uint8_t *__restrict p_src, uint8_t *__restrict p_ template static void _scale_bilinear(const uint8_t *__restrict p_src, uint8_t *__restrict p_dst, uint32_t p_src_width, uint32_t p_src_height, uint32_t p_dst_width, uint32_t p_dst_height) { - enum { FRAC_BITS = 8, FRAC_LEN = (1 << FRAC_BITS), @@ -734,7 +695,6 @@ static void _scale_bilinear(const uint8_t *__restrict p_src, uint8_t *__restrict src_xofs_right *= CC; for (uint32_t l = 0; l < CC; l++) { - if (sizeof(T) == 1) { //uint8 uint32_t p00 = p_src[y_ofs_up + src_xofs_left + l] << FRAC_BITS; uint32_t p10 = p_src[y_ofs_up + src_xofs_right + l] << FRAC_BITS; @@ -788,19 +748,15 @@ static void _scale_bilinear(const uint8_t *__restrict p_src, uint8_t *__restrict template static void _scale_nearest(const uint8_t *__restrict p_src, uint8_t *__restrict p_dst, uint32_t p_src_width, uint32_t p_src_height, uint32_t p_dst_width, uint32_t p_dst_height) { - for (uint32_t i = 0; i < p_dst_height; i++) { - uint32_t src_yofs = i * p_src_height / p_dst_height; uint32_t y_ofs = src_yofs * p_src_width * CC; for (uint32_t j = 0; j < p_dst_width; j++) { - uint32_t src_xofs = j * p_src_width / p_dst_width; src_xofs *= CC; for (uint32_t l = 0; l < CC; l++) { - const T *src = ((const T *)p_src); T *dst = ((T *)p_dst); @@ -819,7 +775,6 @@ static float _lanczos(float p_x) { template static void _scale_lanczos(const uint8_t *__restrict p_src, uint8_t *__restrict p_dst, uint32_t p_src_width, uint32_t p_src_height, uint32_t p_dst_width, uint32_t p_dst_height) { - int32_t src_width = p_src_width; int32_t src_height = p_src_height; int32_t dst_height = p_dst_height; @@ -838,7 +793,6 @@ static void _scale_lanczos(const uint8_t *__restrict p_src, uint8_t *__restrict float *kernel = memnew_arr(float, half_kernel * 2); for (int32_t buffer_x = 0; buffer_x < dst_width; buffer_x++) { - // The corresponding point on the source image float src_x = (buffer_x + 0.5f) * x_scale; // Offset by 0.5 so it uses the pixel's center int32_t start_x = MAX(0, int32_t(src_x) - half_kernel + 1); @@ -849,12 +803,10 @@ static void _scale_lanczos(const uint8_t *__restrict p_src, uint8_t *__restrict 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 }; float weight = 0; for (int32_t target_x = start_x; target_x <= end_x; target_x++) { - float lanczos_val = kernel[target_x - start_x]; weight += lanczos_val; @@ -888,7 +840,6 @@ static void _scale_lanczos(const uint8_t *__restrict p_src, uint8_t *__restrict float *kernel = memnew_arr(float, half_kernel * 2); for (int32_t dst_y = 0; dst_y < dst_height; dst_y++) { - float buffer_y = (dst_y + 0.5f) * y_scale; 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); @@ -897,12 +848,10 @@ static void _scale_lanczos(const uint8_t *__restrict p_src, uint8_t *__restrict 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 }; float weight = 0; for (int32_t target_y = start_y; target_y <= end_y; target_y++) { - float lanczos_val = kernel[target_y - start_y]; weight += lanczos_val; @@ -934,11 +883,9 @@ static void _scale_lanczos(const uint8_t *__restrict p_src, uint8_t *__restrict } static void _overlay(const uint8_t *__restrict p_src, uint8_t *__restrict p_dst, float p_alpha, uint32_t p_width, uint32_t p_height, uint32_t p_pixel_size) { - uint16_t alpha = MIN((uint16_t)(p_alpha * 256.0f), 256); for (uint32_t i = 0; i < p_width * p_height * p_pixel_size; i++) { - p_dst[i] = (p_dst[i] * (256 - alpha) + p_src[i] * alpha) >> 8; } } @@ -948,7 +895,6 @@ bool Image::is_size_po2() const { } void Image::resize_to_po2(bool p_square, Interpolation p_interpolation) { - ERR_FAIL_COND_MSG(!_can_modify(format), "Cannot resize in compressed or custom image formats."); int w = next_power_of_2(width); @@ -958,7 +904,6 @@ void Image::resize_to_po2(bool p_square, Interpolation p_interpolation) { } if (w == width && h == height) { - if (!p_square || w == h) return; //nothing to do } @@ -967,7 +912,6 @@ void Image::resize_to_po2(bool p_square, Interpolation p_interpolation) { } void Image::resize(int p_width, int p_height, Interpolation p_interpolation) { - ERR_FAIL_COND_MSG(data.size() == 0, "Cannot resize image before creating it, use create() or create_from_data() first."); ERR_FAIL_COND_MSG(!_can_modify(format), "Cannot resize in compressed or custom image formats."); ERR_FAIL_COND_MSG(write_lock.ptr(), "Cannot resize image when it is locked."); @@ -1018,9 +962,7 @@ void Image::resize(int p_width, int p_height, Interpolation p_interpolation) { unsigned char *w_ptr = w.ptr(); switch (p_interpolation) { - case INTERPOLATE_NEAREST: { - if (format >= FORMAT_L8 && format <= FORMAT_RGBA8) { switch (get_format_pixel_size(format)) { case 1: @@ -1072,7 +1014,6 @@ void Image::resize(int p_width, int p_height, Interpolation p_interpolation) { } break; case INTERPOLATE_BILINEAR: case INTERPOLATE_TRILINEAR: { - for (int i = 0; i < 2; ++i) { int src_width; int src_height; @@ -1165,7 +1106,6 @@ void Image::resize(int p_width, int p_height, Interpolation p_interpolation) { } break; case INTERPOLATE_CUBIC: { - if (format >= FORMAT_L8 && format <= FORMAT_RGBA8) { switch (get_format_pixel_size(format)) { case 1: @@ -1214,7 +1154,6 @@ void Image::resize(int p_width, int p_height, Interpolation p_interpolation) { } } break; case INTERPOLATE_LANCZOS: { - if (format >= FORMAT_L8 && format <= FORMAT_RGBA8) { switch (get_format_pixel_size(format)) { case 1: @@ -1278,7 +1217,6 @@ void Image::resize(int p_width, int p_height, Interpolation p_interpolation) { } void Image::crop_from_point(int p_x, int p_y, int p_width, int p_height) { - ERR_FAIL_COND_MSG(!_can_modify(format), "Cannot crop in compressed or custom image formats."); ERR_FAIL_COND_MSG(p_x < 0, "Start x position cannot be smaller than 0."); @@ -1307,9 +1245,7 @@ void Image::crop_from_point(int p_x, int p_y, int p_width, int p_height) { int m_h = p_y + p_height; int m_w = p_x + p_width; 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++) pdata[i] = 0; @@ -1328,12 +1264,10 @@ void Image::crop_from_point(int p_x, int p_y, int p_width, int p_height) { } void Image::crop(int p_width, int p_height) { - crop_from_point(0, 0, p_width, p_height); } void Image::flip_y() { - ERR_FAIL_COND_MSG(!_can_modify(format), "Cannot flip_y in compressed or custom image formats."); bool used_mipmaps = has_mipmaps(); @@ -1348,9 +1282,7 @@ void Image::flip_y() { uint32_t pixel_size = get_format_pixel_size(format); for (int y = 0; y < height / 2; y++) { - for (int x = 0; x < width; x++) { - _get_pixelb(x, y, pixel_size, w.ptr(), up); _get_pixelb(x, height - y - 1, pixel_size, w.ptr(), down); @@ -1366,7 +1298,6 @@ void Image::flip_y() { } void Image::flip_x() { - ERR_FAIL_COND_MSG(!_can_modify(format), "Cannot flip_x in compressed or custom image formats."); bool used_mipmaps = has_mipmaps(); @@ -1381,9 +1312,7 @@ void Image::flip_x() { uint32_t pixel_size = get_format_pixel_size(format); for (int y = 0; y < height; y++) { - for (int x = 0; x < width / 2; x++) { - _get_pixelb(x, y, pixel_size, w.ptr(), up); _get_pixelb(width - x - 1, y, pixel_size, w.ptr(), down); @@ -1399,7 +1328,6 @@ void Image::flip_x() { } int Image::_get_dst_image_size(int p_width, int p_height, Format p_format, int &r_mipmaps, int p_mipmaps) { - int size = 0; int w = p_width; int h = p_height; @@ -1414,7 +1342,6 @@ int Image::_get_dst_image_size(int p_width, int p_height, Format p_format, int & int minw = 1, minh = 1; while (true) { - int bw = w % block != 0 ? w + (block - w % block) : w; int bh = h % block != 0 ? h + (block - h % block) : h; @@ -1429,7 +1356,6 @@ int Image::_get_dst_image_size(int p_width, int p_height, Format p_format, int & break; if (p_mipmaps >= 0) { - w = MAX(minw, w >> 1); h = MAX(minh, h >> 1); } else { @@ -1446,7 +1372,6 @@ int Image::_get_dst_image_size(int p_width, int p_height, Format p_format, int & } bool Image::_can_modify(Format p_format) const { - return p_format <= FORMAT_RGBE9995; } @@ -1454,7 +1379,6 @@ template static void _generate_po2_mipmap(const Component *p_src, Component *p_dst, uint32_t p_width, uint32_t p_height) { - //fast power of 2 mipmap generation uint32_t dst_w = MAX(p_width >> 1, 1); uint32_t dst_h = MAX(p_height >> 1, 1); @@ -1463,7 +1387,6 @@ static void _generate_po2_mipmap(const Component *p_src, Component *p_dst, uint3 int down_step = (p_height == 1) ? 0 : (p_width * CC); for (uint32_t i = 0; i < dst_h; i++) { - const Component *rup_ptr = &p_src[i * 2 * down_step]; const Component *rdown_ptr = rup_ptr + down_step; Component *dst_ptr = &p_dst[i * dst_w * CC]; @@ -1527,11 +1450,9 @@ void Image::expand_x2_hq2x() { } void Image::shrink_x2() { - ERR_FAIL_COND(data.size() == 0); if (mipmaps) { - //just use the lower mipmap as base and copy all PoolVector new_img; @@ -1553,7 +1474,6 @@ void Image::shrink_x2() { data = new_img; } else { - PoolVector new_img; ERR_FAIL_COND(!_can_modify(format)); @@ -1567,7 +1487,6 @@ void Image::shrink_x2() { PoolVector::Read r = data.read(); switch (format) { - case FORMAT_L8: case FORMAT_R8: _generate_po2_mipmap(r.ptr(), w.ptr(), width, height); @@ -1626,7 +1545,6 @@ void Image::shrink_x2() { } void Image::normalize() { - bool used_mipmaps = has_mipmaps(); if (used_mipmaps) { clear_mipmaps(); @@ -1635,9 +1553,7 @@ void Image::normalize() { lock(); for (int y = 0; y < height; y++) { - for (int x = 0; x < width; x++) { - Color c = get_pixel(x, y); Vector3 v(c.r * 2.0 - 1.0, c.g * 2.0 - 1.0, c.b * 2.0 - 1.0); v.normalize(); @@ -1656,7 +1572,6 @@ void Image::normalize() { } Error Image::generate_mipmaps(bool p_renormalize) { - ERR_FAIL_COND_V_MSG(!_can_modify(format), ERR_UNAVAILABLE, "Cannot generate mipmaps in compressed or custom image formats."); ERR_FAIL_COND_V_MSG(format == FORMAT_RGBA4444 || format == FORMAT_RGBA5551, ERR_UNAVAILABLE, "Cannot generate mipmaps in custom image formats."); @@ -1676,12 +1591,10 @@ Error Image::generate_mipmaps(bool p_renormalize) { int prev_w = width; for (int i = 1; i <= mmcount; i++) { - int ofs, w, h; _get_mipmap_offset_and_size(i, ofs, w, h); switch (format) { - case FORMAT_L8: case FORMAT_R8: _generate_po2_mipmap(&wp[prev_ofs], &wp[ofs], prev_w, prev_h); @@ -1765,7 +1678,6 @@ Error Image::generate_mipmaps(bool p_renormalize) { } void Image::clear_mipmaps() { - if (!mipmaps) return; @@ -1780,12 +1692,10 @@ void Image::clear_mipmaps() { } bool Image::empty() const { - return (data.size() == 0); } PoolVector Image::get_data() const { - return data; } @@ -1829,7 +1739,6 @@ void Image::create(int p_width, int p_height, bool p_use_mipmaps, Format p_forma } void Image::create(const char **p_xpm) { - int size_width = 0; int size_height = 0; int pixelchars = 0; @@ -1852,13 +1761,10 @@ void Image::create(const char **p_xpm) { PoolVector::Write w; while (status != DONE) { - const char *line_ptr = p_xpm[line]; switch (status) { - case READING_HEADER: { - String line_str = line_ptr; line_str.replace("\t", " "); @@ -1873,10 +1779,8 @@ void Image::create(const char **p_xpm) { status = READING_COLORS; } break; case READING_COLORS: { - String colorstring; for (int i = 0; i < pixelchars; i++) { - colorstring += *line_ptr; line_ptr++; } @@ -1887,7 +1791,6 @@ void Image::create(const char **p_xpm) { line_ptr++; } if (*line_ptr == 'c') { - line_ptr++; while (*line_ptr == ' ' || *line_ptr == '\t' || *line_ptr == 0) { if (*line_ptr == 0) @@ -1903,7 +1806,6 @@ void Image::create(const char **p_xpm) { //uint8_t col_a=255; for (int i = 0; i < 6; i++) { - char v = line_ptr[i]; if (v >= '0' && v <= '9') @@ -1939,17 +1841,14 @@ void Image::create(const char **p_xpm) { // magenta mask if (col_r == 255 && col_g == 0 && col_b == 255) { - colormap[colorstring] = Color(0, 0, 0, 0); has_alpha = true; } else { - colormap[colorstring] = Color(col_r / 255.0, col_g / 255.0, col_b / 255.0, 1.0); } } } if (line == colormap_size) { - status = READING_PIXELS; create(size_width, size_height, 0, has_alpha ? FORMAT_RGBA8 : FORMAT_RGB8); w = data.write(); @@ -1957,10 +1856,8 @@ void Image::create(const char **p_xpm) { } } break; case READING_PIXELS: { - 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++) pixelstr[i] = line_ptr[x * pixelchars + i]; @@ -1993,7 +1890,6 @@ void Image::create(const char **p_xpm) { if (value < DETECT_ALPHA_MIN_THRESHOLD) \ bit = true; \ else if (value < DETECT_ALPHA_MAX_THRESHOLD) { \ - \ detected = true; \ break; \ } \ @@ -2003,14 +1899,12 @@ void Image::create(const char **p_xpm) { { \ uint8_t value = m_value; \ if (value > 0) { \ - \ detected = true; \ break; \ } \ } bool Image::is_invisible() const { - if (format == FORMAT_L8 || format == FORMAT_RGB8 || format == FORMAT_RG8) return false; @@ -2029,16 +1923,13 @@ bool Image::is_invisible() const { bool detected = false; switch (format) { - case FORMAT_LA8: { - for (int i = 0; i < (len >> 1); i++) { DETECT_NON_ALPHA(data_ptr[(i << 1) + 1]); } } break; case FORMAT_RGBA8: { - for (int i = 0; i < (len >> 2); i++) { DETECT_NON_ALPHA(data_ptr[(i << 2) + 3]) } @@ -2059,7 +1950,6 @@ bool Image::is_invisible() const { } Image::AlphaMode Image::detect_alpha() const { - int len = data.size(); if (len == 0) @@ -2075,16 +1965,13 @@ Image::AlphaMode Image::detect_alpha() const { bool detected = false; switch (format) { - case FORMAT_LA8: { - for (int i = 0; i < (len >> 1); i++) { DETECT_ALPHA(data_ptr[(i << 1) + 1]); } } break; case FORMAT_RGBA8: { - for (int i = 0; i < (len >> 2); i++) { DETECT_ALPHA(data_ptr[(i << 2) + 3]) } @@ -2118,7 +2005,6 @@ Error Image::load(const String &p_path) { } Error Image::save_png(const String &p_path) const { - if (save_png_func == NULL) return ERR_UNAVAILABLE; @@ -2134,7 +2020,6 @@ PoolVector Image::save_png_to_buffer() const { } Error Image::save_exr(const String &p_path, bool p_grayscale) const { - if (save_exr_func == NULL) return ERR_UNAVAILABLE; @@ -2142,20 +2027,17 @@ Error Image::save_exr(const String &p_path, bool p_grayscale) const { } int Image::get_image_data_size(int p_width, int p_height, Format p_format, bool p_mipmaps) { - int mm; return _get_dst_image_size(p_width, p_height, p_format, mm, p_mipmaps ? -1 : 0); } int Image::get_image_required_mipmaps(int p_width, int p_height, Format p_format) { - int mm; _get_dst_image_size(p_width, p_height, p_format, mm, -1); return mm; } int Image::get_image_mipmap_offset(int p_width, int p_height, Format p_format, int p_mipmap) { - if (p_mipmap <= 0) { return 0; } @@ -2168,7 +2050,6 @@ bool Image::is_compressed() const { } Error Image::decompress() { - if (format >= FORMAT_DXT1 && format <= FORMAT_RGTC_RG && _image_decompress_bc) _image_decompress_bc(this); else if (format >= FORMAT_BPTC_RGBA && format <= FORMAT_BPTC_RGBFU && _image_decompress_bptc) @@ -2185,36 +2066,28 @@ Error Image::decompress() { } Error Image::compress(CompressMode p_mode, CompressSource p_source, float p_lossy_quality) { - switch (p_mode) { - case COMPRESS_S3TC: { - ERR_FAIL_COND_V(!_image_compress_bc_func, ERR_UNAVAILABLE); _image_compress_bc_func(this, p_lossy_quality, p_source); } break; case COMPRESS_PVRTC2: { - ERR_FAIL_COND_V(!_image_compress_pvrtc2_func, ERR_UNAVAILABLE); _image_compress_pvrtc2_func(this); } break; case COMPRESS_PVRTC4: { - ERR_FAIL_COND_V(!_image_compress_pvrtc4_func, ERR_UNAVAILABLE); _image_compress_pvrtc4_func(this); } break; case COMPRESS_ETC: { - ERR_FAIL_COND_V(!_image_compress_etc1_func, ERR_UNAVAILABLE); _image_compress_etc1_func(this, p_lossy_quality); } break; case COMPRESS_ETC2: { - ERR_FAIL_COND_V(!_image_compress_etc2_func, ERR_UNAVAILABLE); _image_compress_etc2_func(this, p_lossy_quality, p_source); } break; case COMPRESS_BPTC: { - ERR_FAIL_COND_V(!_image_compress_bptc_func, ERR_UNAVAILABLE); _image_compress_bptc_func(this, p_lossy_quality, p_source); } break; @@ -2224,7 +2097,6 @@ Error Image::compress(CompressMode p_mode, CompressSource p_source, float p_loss } Image::Image(const char **p_xpm) { - width = 0; height = 0; mipmaps = false; @@ -2234,7 +2106,6 @@ Image::Image(const char **p_xpm) { } Image::Image(int p_width, int p_height, bool p_use_mipmaps, Format p_format) { - width = 0; height = 0; mipmaps = p_use_mipmaps; @@ -2244,7 +2115,6 @@ Image::Image(int p_width, int p_height, bool p_use_mipmaps, Format p_format) { } Image::Image(int p_width, int p_height, bool p_mipmaps, Format p_format, const PoolVector &p_data) { - width = 0; height = 0; mipmaps = p_mipmaps; @@ -2254,7 +2124,6 @@ Image::Image(int p_width, int p_height, bool p_mipmaps, Format p_format, const P } Rect2 Image::get_used_rect() const { - if (format != FORMAT_LA8 && format != FORMAT_RGBA8 && format != FORMAT_RGBAF && format != FORMAT_RGBAH && format != FORMAT_RGBA4444 && format != FORMAT_RGBA5551) return Rect2(Point2(), Size2(width, height)); @@ -2268,7 +2137,6 @@ Rect2 Image::get_used_rect() const { 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)) continue; if (i > maxx) @@ -2291,14 +2159,12 @@ Rect2 Image::get_used_rect() const { } Ref Image::get_rect(const Rect2 &p_area) const { - Ref img = memnew(Image(p_area.size.x, p_area.size.y, mipmaps, format)); img->blit_rect(Ref((Image *)this), p_area, Point2(0, 0)); return img; } void Image::blit_rect(const Ref &p_src, const Rect2 &p_src_rect, const Point2 &p_dest) { - ERR_FAIL_COND_MSG(p_src.is_null(), "It's not a reference to a valid Image object."); int dsize = data.size(); int srcdsize = p_src->data.size(); @@ -2329,9 +2195,7 @@ void Image::blit_rect(const Ref &p_src, const Rect2 &p_src_rect, const Po int pixel_size = get_format_pixel_size(format); for (int i = 0; i < dest_rect.size.y; i++) { - for (int j = 0; j < dest_rect.size.x; j++) { - int src_x = clipped_src_rect.position.x + j; int src_y = clipped_src_rect.position.y + i; @@ -2349,7 +2213,6 @@ void Image::blit_rect(const Ref &p_src, const Rect2 &p_src_rect, const Po } void Image::blit_rect_mask(const Ref &p_src, const Ref &p_mask, const Rect2 &p_src_rect, const Point2 &p_dest) { - ERR_FAIL_COND_MSG(p_src.is_null(), "It's not a reference to a valid Image object."); ERR_FAIL_COND_MSG(p_mask.is_null(), "It's not a reference to a valid Image object."); int dsize = data.size(); @@ -2387,14 +2250,11 @@ void Image::blit_rect_mask(const Ref &p_src, const Ref &p_mask, co msk->lock(); for (int i = 0; i < dest_rect.size.y; i++) { - for (int j = 0; j < dest_rect.size.x; j++) { - int src_x = clipped_src_rect.position.x + j; int src_y = clipped_src_rect.position.y + i; if (msk->get_pixel(src_x, src_y).a != 0) { - int dst_x = dest_rect.position.x + j; int dst_y = dest_rect.position.y + i; @@ -2412,7 +2272,6 @@ void Image::blit_rect_mask(const Ref &p_src, const Ref &p_mask, co } void Image::blend_rect(const Ref &p_src, const Rect2 &p_src_rect, const Point2 &p_dest) { - ERR_FAIL_COND_MSG(p_src.is_null(), "It's not a reference to a valid Image object."); int dsize = data.size(); int srcdsize = p_src->data.size(); @@ -2438,9 +2297,7 @@ void Image::blend_rect(const Ref &p_src, const Rect2 &p_src_rect, const P img->lock(); for (int i = 0; i < dest_rect.size.y; i++) { - for (int j = 0; j < dest_rect.size.x; j++) { - int src_x = clipped_src_rect.position.x + j; int src_y = clipped_src_rect.position.y + i; @@ -2461,7 +2318,6 @@ void Image::blend_rect(const Ref &p_src, const Rect2 &p_src_rect, const P } void Image::blend_rect_mask(const Ref &p_src, const Ref &p_mask, const Rect2 &p_src_rect, const Point2 &p_dest) { - ERR_FAIL_COND_MSG(p_src.is_null(), "It's not a reference to a valid Image object."); ERR_FAIL_COND_MSG(p_mask.is_null(), "It's not a reference to a valid Image object."); int dsize = data.size(); @@ -2494,9 +2350,7 @@ void Image::blend_rect_mask(const Ref &p_src, const Ref &p_mask, c msk->lock(); for (int i = 0; i < dest_rect.size.y; i++) { - for (int j = 0; j < dest_rect.size.x; j++) { - int src_x = clipped_src_rect.position.x + j; int src_y = clipped_src_rect.position.y + i; @@ -2504,7 +2358,6 @@ void Image::blend_rect_mask(const Ref &p_src, const Ref &p_mask, c //Color c = msk->get_pixel(src_x, src_y); //if (c.a == 0) continue; if (msk->get_pixel(src_x, src_y).a != 0) { - int dst_x = dest_rect.position.x + j; int dst_y = dest_rect.position.y + i; @@ -2537,9 +2390,7 @@ void Image::fill(const Color &c) { set_pixel(0, 0, c); for (int y = 0; y < height; y++) { - for (int x = 0; x < width; x++) { - uint8_t *dst = &dst_data_ptr[(y * width + x) * pixel_size]; for (int k = 0; k < pixel_size; k++) { @@ -2575,7 +2426,6 @@ PoolVector (*Image::lossless_packer)(const Ref &) = NULL; Ref (*Image::lossless_unpacker)(const PoolVector &) = NULL; void Image::_set_data(const Dictionary &p_data) { - ERR_FAIL_COND(!p_data.has("width")); ERR_FAIL_COND(!p_data.has("height")); ERR_FAIL_COND(!p_data.has("format")); @@ -2601,7 +2451,6 @@ void Image::_set_data(const Dictionary &p_data) { } Dictionary Image::_get_data() const { - Dictionary d; d["width"] = width; d["height"] = height; @@ -2612,13 +2461,11 @@ Dictionary Image::_get_data() const { } void Image::lock() { - ERR_FAIL_COND(data.size() == 0); write_lock = data.write(); } void Image::unlock() { - write_lock.release(); } @@ -2627,7 +2474,6 @@ Color Image::get_pixelv(const Point2 &p_src) const { } Color Image::get_pixel(int p_x, int p_y) const { - uint8_t *ptr = write_lock.ptr(); #ifdef DEBUG_ENABLED ERR_FAIL_COND_V_MSG(!ptr, Color(), "Image must be locked with 'lock()' before using get_pixel()."); @@ -2650,12 +2496,10 @@ Color Image::get_pixel(int p_x, int p_y) const { return Color(l, l, l, a); } case FORMAT_R8: { - float r = ptr[ofs] / 255.0; return Color(r, 0, 0, 1); } case FORMAT_RG8: { - float r = ptr[ofs * 2 + 0] / 255.0; float g = ptr[ofs * 2 + 1] / 255.0; return Color(r, g, 0, 1); @@ -2682,7 +2526,6 @@ Color Image::get_pixel(int p_x, int p_y) const { return Color(r, g, b, a); } case FORMAT_RGBA5551: { - uint16_t u = ((uint16_t *)ptr)[ofs]; float r = ((u >> 11) & 0x1F) / 15.0; float g = ((u >> 6) & 0x1F) / 15.0; @@ -2691,25 +2534,21 @@ Color Image::get_pixel(int p_x, int p_y) const { return Color(r, g, b, a); } case FORMAT_RF: { - float r = ((float *)ptr)[ofs]; return Color(r, 0, 0, 1); } case FORMAT_RGF: { - float r = ((float *)ptr)[ofs * 2 + 0]; float g = ((float *)ptr)[ofs * 2 + 1]; return Color(r, g, 0, 1); } case FORMAT_RGBF: { - float r = ((float *)ptr)[ofs * 3 + 0]; float g = ((float *)ptr)[ofs * 3 + 1]; float b = ((float *)ptr)[ofs * 3 + 2]; return Color(r, g, b, 1); } case FORMAT_RGBAF: { - float r = ((float *)ptr)[ofs * 4 + 0]; float g = ((float *)ptr)[ofs * 4 + 1]; float b = ((float *)ptr)[ofs * 4 + 2]; @@ -2717,25 +2556,21 @@ Color Image::get_pixel(int p_x, int p_y) const { return Color(r, g, b, a); } case FORMAT_RH: { - uint16_t r = ((uint16_t *)ptr)[ofs]; return Color(Math::half_to_float(r), 0, 0, 1); } case FORMAT_RGH: { - uint16_t r = ((uint16_t *)ptr)[ofs * 2 + 0]; uint16_t g = ((uint16_t *)ptr)[ofs * 2 + 1]; return Color(Math::half_to_float(r), Math::half_to_float(g), 0, 1); } case FORMAT_RGBH: { - uint16_t r = ((uint16_t *)ptr)[ofs * 3 + 0]; uint16_t g = ((uint16_t *)ptr)[ofs * 3 + 1]; uint16_t b = ((uint16_t *)ptr)[ofs * 3 + 2]; return Color(Math::half_to_float(r), Math::half_to_float(g), Math::half_to_float(b), 1); } case FORMAT_RGBAH: { - uint16_t r = ((uint16_t *)ptr)[ofs * 4 + 0]; uint16_t g = ((uint16_t *)ptr)[ofs * 4 + 1]; uint16_t b = ((uint16_t *)ptr)[ofs * 4 + 2]; @@ -2756,7 +2591,6 @@ void Image::set_pixelv(const Point2 &p_dst, const Color &p_color) { } void Image::set_pixel(int p_x, int p_y, const Color &p_color) { - uint8_t *ptr = write_lock.ptr(); #ifdef DEBUG_ENABLED ERR_FAIL_COND_MSG(!ptr, "Image must be locked with 'lock()' before using set_pixel()."); @@ -2777,11 +2611,9 @@ void Image::set_pixel(int p_x, int p_y, const Color &p_color) { ptr[ofs * 2 + 1] = uint8_t(CLAMP(p_color.a * 255.0, 0, 255)); } break; case FORMAT_R8: { - ptr[ofs] = uint8_t(CLAMP(p_color.r * 255.0, 0, 255)); } break; case FORMAT_RG8: { - ptr[ofs * 2 + 0] = uint8_t(CLAMP(p_color.r * 255.0, 0, 255)); ptr[ofs * 2 + 1] = uint8_t(CLAMP(p_color.g * 255.0, 0, 255)); } break; @@ -2798,7 +2630,6 @@ void Image::set_pixel(int p_x, int p_y, const Color &p_color) { } break; case FORMAT_RGBA4444: { - uint16_t rgba = 0; rgba = uint16_t(CLAMP(p_color.r * 15.0, 0, 15)) << 12; @@ -2810,7 +2641,6 @@ void Image::set_pixel(int p_x, int p_y, const Color &p_color) { } break; case FORMAT_RGBA5551: { - uint16_t rgba = 0; rgba = uint16_t(CLAMP(p_color.r * 31.0, 0, 31)) << 11; @@ -2822,51 +2652,42 @@ void Image::set_pixel(int p_x, int p_y, const Color &p_color) { } break; case FORMAT_RF: { - ((float *)ptr)[ofs] = p_color.r; } break; case FORMAT_RGF: { - ((float *)ptr)[ofs * 2 + 0] = p_color.r; ((float *)ptr)[ofs * 2 + 1] = p_color.g; } break; case FORMAT_RGBF: { - ((float *)ptr)[ofs * 3 + 0] = p_color.r; ((float *)ptr)[ofs * 3 + 1] = p_color.g; ((float *)ptr)[ofs * 3 + 2] = p_color.b; } break; case FORMAT_RGBAF: { - ((float *)ptr)[ofs * 4 + 0] = p_color.r; ((float *)ptr)[ofs * 4 + 1] = p_color.g; ((float *)ptr)[ofs * 4 + 2] = p_color.b; ((float *)ptr)[ofs * 4 + 3] = p_color.a; } break; case FORMAT_RH: { - ((uint16_t *)ptr)[ofs] = Math::make_half_float(p_color.r); } break; case FORMAT_RGH: { - ((uint16_t *)ptr)[ofs * 2 + 0] = Math::make_half_float(p_color.r); ((uint16_t *)ptr)[ofs * 2 + 1] = Math::make_half_float(p_color.g); } break; case FORMAT_RGBH: { - ((uint16_t *)ptr)[ofs * 3 + 0] = Math::make_half_float(p_color.r); ((uint16_t *)ptr)[ofs * 3 + 1] = Math::make_half_float(p_color.g); ((uint16_t *)ptr)[ofs * 3 + 2] = Math::make_half_float(p_color.b); } break; case FORMAT_RGBAH: { - ((uint16_t *)ptr)[ofs * 4 + 0] = Math::make_half_float(p_color.r); ((uint16_t *)ptr)[ofs * 4 + 1] = Math::make_half_float(p_color.g); ((uint16_t *)ptr)[ofs * 4 + 2] = Math::make_half_float(p_color.b); ((uint16_t *)ptr)[ofs * 4 + 3] = Math::make_half_float(p_color.a); } break; case FORMAT_RGBE9995: { - ((uint32_t *)ptr)[ofs] = p_color.to_rgbe9995(); } break; @@ -2877,14 +2698,12 @@ void Image::set_pixel(int p_x, int p_y, const Color &p_color) { } Image::DetectChannels Image::get_detected_channels() { - ERR_FAIL_COND_V(data.size() == 0, DETECTED_RGBA); ERR_FAIL_COND_V(is_compressed(), DETECTED_RGBA); bool r = false, g = false, b = false, a = false, c = false; lock(); for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { - Color col = get_pixel(i, j); if (col.r > 0.001) @@ -2945,7 +2764,6 @@ void Image::optimize_channels() { } void Image::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_width"), &Image::get_width); ClassDB::bind_method(D_METHOD("get_height"), &Image::get_height); ClassDB::bind_method(D_METHOD("get_size"), &Image::get_size); @@ -3085,17 +2903,14 @@ void Image::_bind_methods() { } void Image::set_compress_bc_func(void (*p_compress_func)(Image *, float, CompressSource)) { - _image_compress_bc_func = p_compress_func; } void Image::set_compress_bptc_func(void (*p_compress_func)(Image *, float, CompressSource)) { - _image_compress_bptc_func = p_compress_func; } void Image::normalmap_to_xy() { - convert(Image::FORMAT_RGBA8); { @@ -3104,7 +2919,6 @@ void Image::normalmap_to_xy() { unsigned char *data_ptr = wp.ptr(); for (int i = 0; i < len; i++) { - data_ptr[(i << 2) + 3] = data_ptr[(i << 2) + 0]; //x to w data_ptr[(i << 2) + 0] = data_ptr[(i << 2) + 1]; //y to xz data_ptr[(i << 2) + 2] = data_ptr[(i << 2) + 1]; @@ -3115,7 +2929,6 @@ void Image::normalmap_to_xy() { } Ref Image::rgbe_to_srgb() { - if (data.size() == 0) return Ref(); @@ -3192,7 +3005,6 @@ void Image::bumpmap_to_normalmap(float bump_scale) { } void Image::srgb_to_linear() { - if (data.size() == 0) return; @@ -3201,26 +3013,22 @@ void Image::srgb_to_linear() { ERR_FAIL_COND(format != FORMAT_RGB8 && format != FORMAT_RGBA8); if (format == FORMAT_RGBA8) { - int len = data.size() / 4; PoolVector::Write wp = data.write(); unsigned char *data_ptr = wp.ptr(); for (int i = 0; i < len; i++) { - data_ptr[(i << 2) + 0] = srgb2lin[data_ptr[(i << 2) + 0]]; data_ptr[(i << 2) + 1] = srgb2lin[data_ptr[(i << 2) + 1]]; data_ptr[(i << 2) + 2] = srgb2lin[data_ptr[(i << 2) + 2]]; } } else if (format == FORMAT_RGB8) { - int len = data.size() / 3; PoolVector::Write wp = data.write(); unsigned char *data_ptr = wp.ptr(); for (int i = 0; i < len; i++) { - data_ptr[(i * 3) + 0] = srgb2lin[data_ptr[(i * 3) + 0]]; data_ptr[(i * 3) + 1] = srgb2lin[data_ptr[(i * 3) + 1]]; data_ptr[(i * 3) + 2] = srgb2lin[data_ptr[(i * 3) + 2]]; @@ -3229,7 +3037,6 @@ void Image::srgb_to_linear() { } void Image::premultiply_alpha() { - if (data.size() == 0) return; @@ -3241,7 +3048,6 @@ void Image::premultiply_alpha() { for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { - uint8_t *ptr = &data_ptr[(i * width + j) * 4]; ptr[0] = (uint16_t(ptr[0]) * uint16_t(ptr[3])) >> 8; @@ -3252,7 +3058,6 @@ void Image::premultiply_alpha() { } void Image::fix_alpha_edges() { - if (data.size() == 0) return; @@ -3272,7 +3077,6 @@ void Image::fix_alpha_edges() { for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { - const uint8_t *rptr = &srcptr[(i * width + j) * 4]; uint8_t *wptr = &data_ptr[(i * width + j) * 4]; @@ -3289,7 +3093,6 @@ void Image::fix_alpha_edges() { for (int k = from_y; k <= to_y; k++) { for (int l = from_x; l <= to_x; l++) { - int dy = i - k; int dx = j - l; int dist = dy * dy + dx * dx; @@ -3309,7 +3112,6 @@ void Image::fix_alpha_edges() { } if (closest_dist != max_dist) { - wptr[0] = closest_color[0]; wptr[1] = closest_color[1]; wptr[2] = closest_color[2]; @@ -3319,7 +3121,6 @@ void Image::fix_alpha_edges() { } String Image::get_format_name(Format p_format) { - ERR_FAIL_INDEX_V(p_format, FORMAT_MAX, String()); return format_names[p_format]; } @@ -3415,7 +3216,6 @@ void Image::renormalize_rgbe9995(uint32_t *p_rgb) { } Image::Image(const uint8_t *p_mem_png_jpg, int p_len) { - width = 0; height = 0; mipmaps = false; @@ -3431,7 +3231,6 @@ Image::Image(const uint8_t *p_mem_png_jpg, int p_len) { } Ref Image::duplicate(bool p_subresources) const { - Ref copy; copy.instance(); copy->_copy_internals_from(*this); @@ -3439,7 +3238,6 @@ Ref Image::duplicate(bool p_subresources) const { } Image::Image() { - width = 0; height = 0; mipmaps = false; @@ -3447,7 +3245,6 @@ Image::Image() { } Image::~Image() { - if (write_lock.ptr()) { unlock(); } diff --git a/core/input_map.cpp b/core/input_map.cpp index 076aba8e4ff..8380521be5c 100644 --- a/core/input_map.cpp +++ b/core/input_map.cpp @@ -39,7 +39,6 @@ InputMap *InputMap::singleton = NULL; int InputMap::ALL_DEVICES = -1; void InputMap::_bind_methods() { - ClassDB::bind_method(D_METHOD("has_action", "action"), &InputMap::has_action); ClassDB::bind_method(D_METHOD("get_actions"), &InputMap::_get_actions); ClassDB::bind_method(D_METHOD("add_action", "action", "deadzone"), &InputMap::add_action, DEFVAL(0.5f)); @@ -60,7 +59,6 @@ void InputMap::_bind_methods() { * matching action name (if possible). */ String InputMap::_suggest_actions(const StringName &p_action) const { - List actions = get_actions(); StringName closest_action; float closest_similarity = 0.0; @@ -85,7 +83,6 @@ String InputMap::_suggest_actions(const StringName &p_action) const { } void InputMap::add_action(const StringName &p_action, float p_deadzone) { - ERR_FAIL_COND_MSG(input_map.has(p_action), "InputMap already has action \"" + String(p_action) + "\"."); input_map[p_action] = Action(); static int last_id = 1; @@ -95,21 +92,18 @@ void InputMap::add_action(const StringName &p_action, float p_deadzone) { } void InputMap::erase_action(const StringName &p_action) { - ERR_FAIL_COND_MSG(!input_map.has(p_action), _suggest_actions(p_action)); input_map.erase(p_action); } Array InputMap::_get_actions() { - Array ret; List actions = get_actions(); if (actions.empty()) return ret; for (const List::Element *E = actions.front(); E; E = E->next()) { - ret.push_back(E->get()); } @@ -117,7 +111,6 @@ Array InputMap::_get_actions() { } List InputMap::get_actions() const { - List actions = List(); if (input_map.empty()) { return actions; @@ -134,7 +127,6 @@ List>::Element *InputMap::_find_event(Action &p_action, const Re ERR_FAIL_COND_V(!p_event.is_valid(), NULL); for (List>::Element *E = p_action.inputs.front(); E; E = E->next()) { - const Ref e = E->get(); //if (e.type != Ref::KEY && e.device != p_event.device) -- unsure about the KEY comparison, why is this here? @@ -152,19 +144,16 @@ List>::Element *InputMap::_find_event(Action &p_action, const Re } bool InputMap::has_action(const StringName &p_action) const { - return input_map.has(p_action); } void InputMap::action_set_deadzone(const StringName &p_action, float p_deadzone) { - ERR_FAIL_COND_MSG(!input_map.has(p_action), _suggest_actions(p_action)); input_map[p_action].deadzone = 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), _suggest_actions(p_action)); @@ -175,14 +164,12 @@ void InputMap::action_add_event(const StringName &p_action, const Ref &p_event) { - ERR_FAIL_COND_V_MSG(!input_map.has(p_action), false, _suggest_actions(p_action)); return (_find_event(input_map[p_action], p_event) != NULL); } void InputMap::action_erase_event(const StringName &p_action, const Ref &p_event) { - ERR_FAIL_COND_MSG(!input_map.has(p_action), _suggest_actions(p_action)); List>::Element *E = _find_event(input_map[p_action], p_event); @@ -195,19 +182,16 @@ void InputMap::action_erase_event(const StringName &p_action, const Ref> *al = get_action_list(p_action); if (al) { for (const List>::Element *E = al->front(); E; E = E->next()) { - ret.push_back(E->get()); } } @@ -216,7 +200,6 @@ 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) return NULL; @@ -260,7 +243,6 @@ const Map &InputMap::get_action_map() const { } void InputMap::load_from_globals() { - input_map.clear(); List pinfo; @@ -289,7 +271,6 @@ void InputMap::load_from_globals() { } void InputMap::load_default() { - Ref key; add_action("ui_accept"); @@ -368,7 +349,6 @@ void InputMap::load_default() { } InputMap::InputMap() { - ERR_FAIL_COND_MSG(singleton, "Singleton in InputMap already exist."); singleton = this; } diff --git a/core/input_map.h b/core/input_map.h index 963a48e23c8..2d7e82f52cb 100644 --- a/core/input_map.h +++ b/core/input_map.h @@ -35,7 +35,6 @@ #include "core/os/input_event.h" class InputMap : public Object { - GDCLASS(InputMap, Object); public: diff --git a/core/io/compression.cpp b/core/io/compression.cpp index 9405f2c60f0..62b0f78d03d 100644 --- a/core/io/compression.cpp +++ b/core/io/compression.cpp @@ -39,10 +39,8 @@ #include int Compression::compress(uint8_t *p_dst, const uint8_t *p_src, int p_src_size, Mode p_mode) { - switch (p_mode) { case MODE_FASTLZ: { - if (p_src_size < 16) { uint8_t src[16]; memset(&src[p_src_size], 0, 16 - p_src_size); @@ -55,7 +53,6 @@ int Compression::compress(uint8_t *p_dst, const uint8_t *p_src, int p_src_size, } break; case MODE_DEFLATE: case MODE_GZIP: { - int window_bits = p_mode == MODE_DEFLATE ? 15 : 15 + 16; z_stream strm; @@ -96,10 +93,8 @@ int Compression::compress(uint8_t *p_dst, const uint8_t *p_src, int p_src_size, } 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) ss = 66; @@ -108,7 +103,6 @@ int Compression::get_max_compressed_buffer_size(int p_src_size, Mode p_mode) { } break; case MODE_DEFLATE: case MODE_GZIP: { - int window_bits = p_mode == MODE_DEFLATE ? 15 : 15 + 16; z_stream strm; @@ -123,7 +117,6 @@ int Compression::get_max_compressed_buffer_size(int p_src_size, Mode p_mode) { return aout; } break; case MODE_ZSTD: { - return ZSTD_compressBound(p_src_size); } break; } @@ -132,10 +125,8 @@ int Compression::get_max_compressed_buffer_size(int p_src_size, Mode p_mode) { } int Compression::decompress(uint8_t *p_dst, int p_dst_max_size, const uint8_t *p_src, int p_src_size, Mode p_mode) { - switch (p_mode) { case MODE_FASTLZ: { - int ret_size = 0; if (p_dst_max_size < 16) { @@ -149,7 +140,6 @@ int Compression::decompress(uint8_t *p_dst, int p_dst_max_size, const uint8_t *p } break; case MODE_DEFLATE: case MODE_GZIP: { - int window_bits = p_mode == MODE_DEFLATE ? 15 : 15 + 16; z_stream strm; diff --git a/core/io/compression.h b/core/io/compression.h index fa49440677c..c6f62c5fc05 100644 --- a/core/io/compression.h +++ b/core/io/compression.h @@ -34,7 +34,6 @@ #include "core/typedefs.h" class Compression { - public: static int zlib_level; static int gzip_level; diff --git a/core/io/config_file.cpp b/core/io/config_file.cpp index 04e3fb053a7..5684988b3d6 100644 --- a/core/io/config_file.cpp +++ b/core/io/config_file.cpp @@ -35,14 +35,12 @@ #include "core/variant_parser.h" PoolStringArray ConfigFile::_get_sections() const { - List s; get_sections(&s); PoolStringArray arr; arr.resize(s.size()); int idx = 0; for (const List::Element *E = s.front(); E; E = E->next()) { - arr.set(idx++, E->get()); } @@ -50,14 +48,12 @@ PoolStringArray ConfigFile::_get_sections() const { } PoolStringArray ConfigFile::_get_section_keys(const String &p_section) const { - List s; get_section_keys(p_section, &s); PoolStringArray arr; arr.resize(s.size()); int idx = 0; for (const List::Element *E = s.front(); E; E = E->next()) { - arr.set(idx++, E->get()); } @@ -65,7 +61,6 @@ PoolStringArray 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)) @@ -84,7 +79,6 @@ void ConfigFile::set_value(const String &p_section, const String &p_key, const V } } Variant ConfigFile::get_value(const String &p_section, const String &p_key, Variant p_default) const { - if (!values.has(p_section) || !values[p_section].has(p_key)) { ERR_FAIL_COND_V_MSG(p_default.get_type() == Variant::NIL, Variant(), vformat("Couldn't find the given section \"%s\" and key \"%s\", and no default was given.", p_section, p_key)); @@ -94,24 +88,20 @@ Variant ConfigFile::get_value(const String &p_section, const String &p_key, Vari } bool ConfigFile::has_section(const String &p_section) const { - return values.has(p_section); } bool ConfigFile::has_section_key(const String &p_section, const String &p_key) const { - if (!values.has(p_section)) return false; return values[p_section].has(p_key); } void ConfigFile::get_sections(List *r_sections) const { - for (OrderedHashMap>::ConstElement E = values.front(); E; E = E.next()) { r_sections->push_back(E.key()); } } void ConfigFile::get_section_keys(const String &p_section, List *r_keys) const { - ERR_FAIL_COND_MSG(!values.has(p_section), vformat("Cannot get keys from nonexistent section \"%s\".", p_section)); for (OrderedHashMap::ConstElement E = values[p_section].front(); E; E = E.next()) { @@ -120,13 +110,11 @@ void ConfigFile::get_section_keys(const String &p_section, List *r_keys) } void ConfigFile::erase_section(const String &p_section) { - ERR_FAIL_COND_MSG(!values.has(p_section), vformat("Cannot erase nonexistent section \"%s\".", p_section)); values.erase(p_section); } void ConfigFile::erase_section_key(const String &p_section, const String &p_key) { - ERR_FAIL_COND_MSG(!values.has(p_section), vformat("Cannot erase key \"%s\" from nonexistent section \"%s\".", p_key, p_section)); ERR_FAIL_COND_MSG(!values[p_section].has(p_key), vformat("Cannot erase nonexistent key \"%s\" from section \"%s\".", p_key, p_section)); @@ -134,7 +122,6 @@ void ConfigFile::erase_section_key(const String &p_section, const String &p_key) } Error ConfigFile::save(const String &p_path) { - Error err; FileAccess *file = FileAccess::open(p_path, FileAccess::WRITE, &err); @@ -148,7 +135,6 @@ Error ConfigFile::save(const String &p_path) { } Error ConfigFile::save_encrypted(const String &p_path, const Vector &p_key) { - Error err; FileAccess *f = FileAccess::open(p_path, FileAccess::WRITE, &err); @@ -166,7 +152,6 @@ Error ConfigFile::save_encrypted(const String &p_path, const Vector &p_ } Error ConfigFile::save_encrypted_pass(const String &p_path, const String &p_pass) { - Error err; FileAccess *f = FileAccess::open(p_path, FileAccess::WRITE, &err); @@ -185,15 +170,12 @@ 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()) file->store_string("\n"); file->store_string("[" + E.key() + "]\n\n"); for (OrderedHashMap::Element F = E.get().front(); F; F = F.next()) { - String vstr; VariantWriter::write_to_string(F.get(), vstr); file->store_string(F.key() + "=" + vstr + "\n"); @@ -206,7 +188,6 @@ Error ConfigFile::_internal_save(FileAccess *file) { } Error ConfigFile::load(const String &p_path) { - Error err; FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err); @@ -217,7 +198,6 @@ Error ConfigFile::load(const String &p_path) { } Error ConfigFile::load_encrypted(const String &p_path, const Vector &p_key) { - Error err; FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err); @@ -235,7 +215,6 @@ Error ConfigFile::load_encrypted(const String &p_path, const Vector &p_ } Error ConfigFile::load_encrypted_pass(const String &p_path, const String &p_pass) { - Error err; FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err); @@ -254,7 +233,6 @@ Error ConfigFile::load_encrypted_pass(const String &p_path, const String &p_pass } Error ConfigFile::_internal_load(const String &p_path, FileAccess *f) { - VariantParser::StreamFile stream; stream.f = f; @@ -266,14 +244,12 @@ Error ConfigFile::_internal_load(const String &p_path, FileAccess *f) { } Error ConfigFile::parse(const String &p_data) { - VariantParser::StreamString stream; stream.s = p_data; return _parse("", &stream); } Error ConfigFile::_parse(const String &p_path, VariantParser::Stream *p_stream) { - String assign; Variant value; VariantParser::Tag next_tag; @@ -284,7 +260,6 @@ Error ConfigFile::_parse(const String &p_path, VariantParser::Stream *p_stream) String section; while (true) { - assign = Variant(); next_tag.fields.clear(); next_tag.name = String(); @@ -311,7 +286,6 @@ void ConfigFile::clear() { values.clear(); } void ConfigFile::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_value", "section", "key", "value"), &ConfigFile::set_value); ClassDB::bind_method(D_METHOD("get_value", "section", "key", "default"), &ConfigFile::get_value, DEFVAL(Variant())); diff --git a/core/io/config_file.h b/core/io/config_file.h index e3e26ffe124..63bd7087970 100644 --- a/core/io/config_file.h +++ b/core/io/config_file.h @@ -37,7 +37,6 @@ #include "core/variant_parser.h" class ConfigFile : public Reference { - GDCLASS(ConfigFile, Reference); OrderedHashMap> values; diff --git a/core/io/dtls_server.cpp b/core/io/dtls_server.cpp index 7c159048202..42df35f7e50 100644 --- a/core/io/dtls_server.cpp +++ b/core/io/dtls_server.cpp @@ -36,7 +36,6 @@ DTLSServer *(*DTLSServer::_create)() = NULL; bool DTLSServer::available = false; DTLSServer *DTLSServer::create() { - if (_create) { return _create(); } @@ -48,7 +47,6 @@ bool DTLSServer::is_available() { } void DTLSServer::_bind_methods() { - ClassDB::bind_method(D_METHOD("setup", "key", "certificate", "chain"), &DTLSServer::setup, DEFVAL(Ref())); ClassDB::bind_method(D_METHOD("take_connection", "udp_peer"), &DTLSServer::take_connection); } diff --git a/core/io/file_access_compressed.cpp b/core/io/file_access_compressed.cpp index 8d2c52b80c2..bf1f2aaf4b0 100644 --- a/core/io/file_access_compressed.cpp +++ b/core/io/file_access_compressed.cpp @@ -33,7 +33,6 @@ #include "core/print_string.h" 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) magic = magic.substr(0, 4); @@ -59,7 +58,6 @@ void FileAccessCompressed::configure(const String &p_magic, Compression::Mode p_ } Error FileAccessCompressed::open_after_magic(FileAccess *p_base) { - f = p_base; cmode = (Compression::Mode)f->get_32(); block_size = f->get_32(); @@ -72,7 +70,6 @@ Error FileAccessCompressed::open_after_magic(FileAccess *p_base) { int acc_ofs = f->get_position() + bc * 4; int max_bs = 0; for (int i = 0; i < bc; i++) { - ReadBlock rb; rb.offset = acc_ofs; rb.csize = f->get_32(); @@ -98,7 +95,6 @@ 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) @@ -114,7 +110,6 @@ Error FileAccessCompressed::_open(const String &p_path, int p_mode_flags) { } if (p_mode_flags & WRITE) { - buffer.clear(); writing = true; write_pos = 0; @@ -125,7 +120,6 @@ Error FileAccessCompressed::_open(const String &p_path, int p_mode_flags) { //don't store anything else unless it's done saving! } else { - char rmagic[5]; f->get_buffer((uint8_t *)rmagic, 4); rmagic[4] = 0; @@ -139,7 +133,6 @@ Error FileAccessCompressed::_open(const String &p_path, int p_mode_flags) { return OK; } void FileAccessCompressed::close() { - if (!f) return; @@ -159,7 +152,6 @@ void FileAccessCompressed::close() { Vector block_sizes; for (int i = 0; i < bc; i++) { - int bl = i == (bc - 1) ? write_max % block_size : block_size; uint8_t *bp = &write_ptr[i * block_size]; @@ -180,7 +172,6 @@ void FileAccessCompressed::close() { buffer.clear(); } else { - comp_buffer.clear(); buffer.clear(); read_blocks.clear(); @@ -191,21 +182,17 @@ void FileAccessCompressed::close() { } bool FileAccessCompressed::is_open() const { - return f != NULL; } void FileAccessCompressed::seek(size_t p_position) { - ERR_FAIL_COND_MSG(!f, "File must be opened before use."); if (writing) { - ERR_FAIL_COND(p_position > write_max); write_pos = p_position; } else { - ERR_FAIL_COND(p_position > read_total); if (p_position == read_total) { at_end = true; @@ -214,7 +201,6 @@ void FileAccessCompressed::seek(size_t p_position) { read_eof = false; int block_idx = p_position / block_size; if (block_idx != read_block) { - read_block = block_idx; f->seek(read_blocks[read_block].offset); f->get_buffer(comp_buffer.ptrw(), read_blocks[read_block].csize); @@ -228,32 +214,24 @@ void FileAccessCompressed::seek(size_t p_position) { } void FileAccessCompressed::seek_end(int64_t p_position) { - ERR_FAIL_COND_MSG(!f, "File must be opened before use."); if (writing) { - seek(write_max + p_position); } else { - seek(read_total + p_position); } } size_t FileAccessCompressed::get_position() const { - ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use."); if (writing) { - return write_pos; } else { - return read_block * block_size + read_pos; } } size_t FileAccessCompressed::get_len() const { - ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use."); if (writing) { - return write_max; } else { return read_total; @@ -261,7 +239,6 @@ size_t FileAccessCompressed::get_len() const { } bool FileAccessCompressed::eof_reached() const { - ERR_FAIL_COND_V_MSG(!f, false, "File must be opened before use."); if (writing) { return false; @@ -271,7 +248,6 @@ bool FileAccessCompressed::eof_reached() const { } uint8_t FileAccessCompressed::get_8() const { - ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use."); ERR_FAIL_COND_V_MSG(writing, 0, "File has not been opened in read mode."); @@ -313,7 +289,6 @@ int FileAccessCompressed::get_buffer(uint8_t *p_dst, int p_length) const { } for (int i = 0; i < p_length; i++) { - p_dst[i] = read_ptr[read_pos]; read_pos++; if (read_pos >= read_block_size) { @@ -340,7 +315,6 @@ int FileAccessCompressed::get_buffer(uint8_t *p_dst, int p_length) const { } Error FileAccessCompressed::get_error() const { - return read_eof ? ERR_FILE_EOF : OK; } @@ -352,7 +326,6 @@ void FileAccessCompressed::flush() { } void FileAccessCompressed::store_8(uint8_t p_dest) { - ERR_FAIL_COND_MSG(!f, "File must be opened before use."); ERR_FAIL_COND_MSG(!writing, "File has not been opened in write mode."); @@ -361,7 +334,6 @@ 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) return false; @@ -370,7 +342,6 @@ bool FileAccessCompressed::file_exists(const String &p_name) { } uint64_t FileAccessCompressed::_get_modified_time(const String &p_file) { - if (f) return f->get_modified_time(p_file); else @@ -410,7 +381,6 @@ FileAccessCompressed::FileAccessCompressed() : } FileAccessCompressed::~FileAccessCompressed() { - if (f) close(); } diff --git a/core/io/file_access_compressed.h b/core/io/file_access_compressed.h index 12d0b1f72de..32849384f9d 100644 --- a/core/io/file_access_compressed.h +++ b/core/io/file_access_compressed.h @@ -35,7 +35,6 @@ #include "core/os/file_access.h" class FileAccessCompressed : public FileAccess { - Compression::Mode cmode; bool writing; uint32_t write_pos; diff --git a/core/io/file_access_encrypted.cpp b/core/io/file_access_encrypted.cpp index 5385478cb2c..b335cdce057 100644 --- a/core/io/file_access_encrypted.cpp +++ b/core/io/file_access_encrypted.cpp @@ -39,7 +39,6 @@ #define COMP_MAGIC 0x43454447 Error FileAccessEncrypted::open_and_parse(FileAccess *p_base, const Vector &p_key, Mode p_mode) { - ERR_FAIL_COND_V_MSG(file != NULL, ERR_ALREADY_IN_USE, "Can't open file while another file from path '" + file->get_path_absolute() + "' is open."); ERR_FAIL_COND_V(p_key.size() != 32, ERR_INVALID_PARAMETER); @@ -47,7 +46,6 @@ Error FileAccessEncrypted::open_and_parse(FileAccess *p_base, const Vectorget_32(); @@ -84,7 +81,6 @@ Error FileAccessEncrypted::open_and_parse(FileAccess *p_base, const Vector key; key.resize(32); for (int i = 0; i < 32; i++) { - key.write[i] = cs[i]; } @@ -116,16 +110,13 @@ Error FileAccessEncrypted::open_and_parse_password(FileAccess *p_base, const Str } Error FileAccessEncrypted::_open(const String &p_path, int p_mode_flags) { - return OK; } void FileAccessEncrypted::close() { - if (!file) return; if (writing) { - Vector compressed; size_t len = data.size(); if (len % 16) { @@ -145,7 +136,6 @@ void FileAccessEncrypted::close() { ctx.set_encode_key(key.ptrw(), 256); for (size_t i = 0; i < len; i += 16) { - ctx.encrypt_ecb(&compressed.write[i], &compressed.write[i]); } @@ -162,7 +152,6 @@ void FileAccessEncrypted::close() { data.clear(); } else { - file->close(); memdelete(file); data.clear(); @@ -171,12 +160,10 @@ void FileAccessEncrypted::close() { } bool FileAccessEncrypted::is_open() const { - return file != NULL; } String FileAccessEncrypted::get_path() const { - if (file) return file->get_path(); else @@ -184,7 +171,6 @@ String FileAccessEncrypted::get_path() const { } String FileAccessEncrypted::get_path_absolute() const { - if (file) return file->get_path_absolute(); else @@ -192,7 +178,6 @@ String FileAccessEncrypted::get_path_absolute() const { } void FileAccessEncrypted::seek(size_t p_position) { - if (p_position > (size_t)data.size()) p_position = data.size(); @@ -201,25 +186,20 @@ void FileAccessEncrypted::seek(size_t p_position) { } void FileAccessEncrypted::seek_end(int64_t p_position) { - seek(data.size() + p_position); } size_t FileAccessEncrypted::get_position() const { - return pos; } size_t FileAccessEncrypted::get_len() const { - return data.size(); } bool FileAccessEncrypted::eof_reached() const { - return eofed; } uint8_t FileAccessEncrypted::get_8() const { - ERR_FAIL_COND_V_MSG(writing, 0, "File has not been opened in read mode."); if (pos >= data.size()) { eofed = true; @@ -238,7 +218,6 @@ int FileAccessEncrypted::get_buffer(uint8_t *p_dst, int p_length) const { int to_copy = MIN(p_length, data.size() - pos); for (int i = 0; i < to_copy; i++) { - p_dst[i] = data[pos++]; } @@ -250,25 +229,19 @@ int FileAccessEncrypted::get_buffer(uint8_t *p_dst, int p_length) const { } Error FileAccessEncrypted::get_error() const { - return eofed ? ERR_FILE_EOF : OK; } void FileAccessEncrypted::store_buffer(const uint8_t *p_src, int p_length) { - ERR_FAIL_COND_MSG(!writing, "File has not been opened in write mode."); if (pos < data.size()) { - for (int i = 0; i < p_length; i++) { - store_8(p_src[i]); } } else if (pos == data.size()) { - data.resize(pos + p_length); for (int i = 0; i < p_length; i++) { - data.write[pos + i] = p_src[i]; } pos += p_length; @@ -282,7 +255,6 @@ void FileAccessEncrypted::flush() { } void FileAccessEncrypted::store_8(uint8_t p_dest) { - ERR_FAIL_COND_MSG(!writing, "File has not been opened in write mode."); if (pos < data.size()) { @@ -295,7 +267,6 @@ 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) return false; @@ -304,12 +275,10 @@ bool FileAccessEncrypted::file_exists(const String &p_name) { } uint64_t FileAccessEncrypted::_get_modified_time(const String &p_file) { - return 0; } uint32_t FileAccessEncrypted::_get_unix_permissions(const String &p_file) { - return 0; } @@ -319,7 +288,6 @@ Error FileAccessEncrypted::_set_unix_permissions(const String &p_file, uint32_t } FileAccessEncrypted::FileAccessEncrypted() { - file = NULL; pos = 0; eofed = false; @@ -328,7 +296,6 @@ FileAccessEncrypted::FileAccessEncrypted() { } FileAccessEncrypted::~FileAccessEncrypted() { - if (file) close(); } diff --git a/core/io/file_access_memory.cpp b/core/io/file_access_memory.cpp index cb44bf65dd2..8f063daafce 100644 --- a/core/io/file_access_memory.cpp +++ b/core/io/file_access_memory.cpp @@ -37,7 +37,6 @@ static Map> *files = NULL; void FileAccessMemory::register_file(String p_name, Vector p_data) { - if (!files) { files = memnew((Map>)); } @@ -53,7 +52,6 @@ void FileAccessMemory::register_file(String p_name, Vector p_data) { } void FileAccessMemory::cleanup() { - if (!files) return; @@ -61,12 +59,10 @@ void FileAccessMemory::cleanup() { } FileAccess *FileAccessMemory::create() { - return memnew(FileAccessMemory); } bool FileAccessMemory::file_exists(const String &p_name) { - String name = fix_path(p_name); //name = DirAccess::normalize_path(name); @@ -74,7 +70,6 @@ bool FileAccessMemory::file_exists(const String &p_name) { } Error FileAccessMemory::open_custom(const uint8_t *p_data, int p_len) { - data = (uint8_t *)p_data; length = p_len; pos = 0; @@ -82,7 +77,6 @@ Error FileAccessMemory::open_custom(const uint8_t *p_data, int p_len) { } Error FileAccessMemory::_open(const String &p_path, int p_mode_flags) { - ERR_FAIL_COND_V(!files, ERR_FILE_NOT_FOUND); String name = fix_path(p_path); @@ -99,46 +93,38 @@ Error FileAccessMemory::_open(const String &p_path, int p_mode_flags) { } void FileAccessMemory::close() { - data = NULL; } bool FileAccessMemory::is_open() const { - return data != NULL; } void FileAccessMemory::seek(size_t p_position) { - ERR_FAIL_COND(!data); pos = p_position; } void FileAccessMemory::seek_end(int64_t p_position) { - ERR_FAIL_COND(!data); pos = length + p_position; } size_t FileAccessMemory::get_position() const { - ERR_FAIL_COND_V(!data, 0); return pos; } size_t FileAccessMemory::get_len() const { - ERR_FAIL_COND_V(!data, 0); return length; } bool FileAccessMemory::eof_reached() const { - return pos > length; } uint8_t FileAccessMemory::get_8() const { - uint8_t ret = 0; if (pos < length) { ret = data[pos]; @@ -167,7 +153,6 @@ int FileAccessMemory::get_buffer(uint8_t *p_dst, int p_length) const { } Error FileAccessMemory::get_error() const { - return pos >= length ? ERR_FILE_EOF : OK; } @@ -176,14 +161,12 @@ void FileAccessMemory::flush() { } void FileAccessMemory::store_8(uint8_t p_byte) { - ERR_FAIL_COND(!data); ERR_FAIL_COND(pos >= length); data[pos++] = p_byte; } void FileAccessMemory::store_buffer(const uint8_t *p_src, int p_length) { - int left = length - pos; int write = MIN(p_length, left); if (write < p_length) { @@ -195,6 +178,5 @@ void FileAccessMemory::store_buffer(const uint8_t *p_src, int p_length) { } FileAccessMemory::FileAccessMemory() { - data = NULL; } diff --git a/core/io/file_access_memory.h b/core/io/file_access_memory.h index b1aa23701d6..10a9d849b3c 100644 --- a/core/io/file_access_memory.h +++ b/core/io/file_access_memory.h @@ -34,7 +34,6 @@ #include "core/os/file_access.h" class FileAccessMemory : public FileAccess { - uint8_t *data; int length; mutable int pos; diff --git a/core/io/file_access_network.cpp b/core/io/file_access_network.cpp index 4bb67965a78..ccb9b2a0393 100644 --- a/core/io/file_access_network.cpp +++ b/core/io/file_access_network.cpp @@ -41,19 +41,16 @@ #define DEBUG_TIME(m_what) void FileAccessNetworkClient::lock_mutex() { - mutex.lock(); lockcount++; } void FileAccessNetworkClient::unlock_mutex() { - lockcount--; mutex.unlock(); } void FileAccessNetworkClient::put_32(int p_32) { - uint8_t buf[4]; encode_uint32(p_32, buf); client->put_data(buf, 4); @@ -61,7 +58,6 @@ void FileAccessNetworkClient::put_32(int p_32) { } void FileAccessNetworkClient::put_64(int64_t p_64) { - uint8_t buf[8]; encode_uint64(p_64, buf); client->put_data(buf, 8); @@ -69,24 +65,20 @@ void FileAccessNetworkClient::put_64(int64_t p_64) { } int FileAccessNetworkClient::get_32() { - uint8_t buf[4]; client->get_data(buf, 4); return decode_uint32(buf); } int64_t FileAccessNetworkClient::get_64() { - uint8_t buf[8]; client->get_data(buf, 8); return decode_uint64(buf); } void FileAccessNetworkClient::_thread_func() { - client->set_no_delay(true); while (!quit) { - DEBUG_PRINT("SEM WAIT - " + itos(sem->get())); sem.wait(); DEBUG_TIME("sem_unlock"); @@ -126,9 +118,7 @@ void FileAccessNetworkClient::_thread_func() { fa = accesses[id]; switch (response) { - case FileAccessNetwork::RESPONSE_OPEN: { - DEBUG_TIME("sem_open"); int status = get_32(); if (status != OK) { @@ -142,7 +132,6 @@ void FileAccessNetworkClient::_thread_func() { } break; case FileAccessNetwork::RESPONSE_DATA: { - int64_t offset = get_64(); uint32_t len = get_32(); @@ -155,14 +144,12 @@ void FileAccessNetworkClient::_thread_func() { } break; case FileAccessNetwork::RESPONSE_FILE_EXISTS: { - int status = get_32(); fa->exists_modtime = status != 0; fa->sem.post(); } break; case FileAccessNetwork::RESPONSE_GET_MODTIME: { - uint64_t status = get_64(); fa->exists_modtime = status; fa->sem.post(); @@ -175,14 +162,12 @@ void FileAccessNetworkClient::_thread_func() { } void FileAccessNetworkClient::_thread_func(void *s) { - FileAccessNetworkClient *self = (FileAccessNetworkClient *)s; self->_thread_func(); } Error FileAccessNetworkClient::connect(const String &p_host, int p_port, const String &p_password) { - IP_Address ip; if (p_host.is_valid_ip_address()) { @@ -221,7 +206,6 @@ Error FileAccessNetworkClient::connect(const String &p_host, int p_port, const S FileAccessNetworkClient *FileAccessNetworkClient::singleton = NULL; FileAccessNetworkClient::FileAccessNetworkClient() { - quit = false; singleton = this; last_id = 0; @@ -230,7 +214,6 @@ FileAccessNetworkClient::FileAccessNetworkClient() { } FileAccessNetworkClient::~FileAccessNetworkClient() { - if (thread.is_started()) { quit = true; sem.post(); @@ -239,7 +222,6 @@ FileAccessNetworkClient::~FileAccessNetworkClient() { } void FileAccessNetwork::_set_block(int p_offset, const Vector &p_block) { - int page = p_offset / page_size; ERR_FAIL_INDEX(page, pages.size()); if (page < pages.size() - 1) { @@ -260,7 +242,6 @@ 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) @@ -272,7 +253,6 @@ 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) close(); @@ -307,7 +287,6 @@ Error FileAccessNetwork::_open(const String &p_path, int p_mode_flags) { } void FileAccessNetwork::close() { - if (!opened) return; @@ -322,12 +301,10 @@ void FileAccessNetwork::close() { nc->unlock_mutex(); } bool FileAccessNetwork::is_open() const { - return opened; } void FileAccessNetwork::seek(size_t p_position) { - ERR_FAIL_COND_MSG(!opened, "File must be opened before use."); eof_flag = p_position > total_size; @@ -339,39 +316,32 @@ void FileAccessNetwork::seek(size_t p_position) { } void FileAccessNetwork::seek_end(int64_t p_position) { - seek(total_size + p_position); } size_t FileAccessNetwork::get_position() const { - ERR_FAIL_COND_V_MSG(!opened, 0, "File must be opened before use."); return pos; } size_t FileAccessNetwork::get_len() const { - ERR_FAIL_COND_V_MSG(!opened, 0, "File must be opened before use."); return total_size; } bool FileAccessNetwork::eof_reached() const { - ERR_FAIL_COND_V_MSG(!opened, false, "File must be opened before use."); return eof_flag; } uint8_t FileAccessNetwork::get_8() const { - uint8_t v; get_buffer(&v, 1); return v; } void FileAccessNetwork::_queue_page(int p_page) const { - if (p_page >= pages.size()) return; if (pages[p_page].buffer.empty() && !pages[p_page].queued) { - FileAccessNetworkClient *nc = FileAccessNetworkClient::singleton; nc->blockrequest_mutex.lock(); @@ -405,7 +375,6 @@ int FileAccessNetwork::get_buffer(uint8_t *p_dst, int p_length) const { uint8_t *buff = last_page_buff; for (int i = 0; i < p_length; i++) { - int page = pos / page_size; if (page != last_page) { @@ -413,7 +382,6 @@ int FileAccessNetwork::get_buffer(uint8_t *p_dst, int p_length) const { if (pages[page].buffer.empty()) { waiting_on_page = page; for (int j = 0; j < read_ahead; j++) { - _queue_page(page + j); } buffer_mutex.unlock(); @@ -421,9 +389,7 @@ int FileAccessNetwork::get_buffer(uint8_t *p_dst, int p_length) const { page_sem.wait(); DEBUG_PRINT("done"); } else { - for (int j = 0; j < read_ahead; j++) { - _queue_page(page + j); } //queue pages @@ -443,7 +409,6 @@ int FileAccessNetwork::get_buffer(uint8_t *p_dst, int p_length) const { } Error FileAccessNetwork::get_error() const { - return pos == total_size ? ERR_FILE_EOF : OK; } @@ -452,12 +417,10 @@ void FileAccessNetwork::flush() { } void FileAccessNetwork::store_8(uint8_t p_dest) { - ERR_FAIL(); } bool FileAccessNetwork::file_exists(const String &p_path) { - FileAccessNetworkClient *nc = FileAccessNetworkClient::singleton; nc->lock_mutex(); nc->put_32(id); @@ -474,7 +437,6 @@ bool FileAccessNetwork::file_exists(const String &p_path) { } uint64_t FileAccessNetwork::_get_modified_time(const String &p_file) { - FileAccessNetworkClient *nc = FileAccessNetworkClient::singleton; nc->lock_mutex(); nc->put_32(id); @@ -501,7 +463,6 @@ Error FileAccessNetwork::_set_unix_permissions(const String &p_file, uint32_t p_ } void FileAccessNetwork::configure() { - GLOBAL_DEF("network/remote_fs/page_size", 65536); ProjectSettings::get_singleton()->set_custom_property_info("network/remote_fs/page_size", PropertyInfo(Variant::INT, "network/remote_fs/page_size", PROPERTY_HINT_RANGE, "1,65536,1,or_greater")); //is used as denominator and can't be zero GLOBAL_DEF("network/remote_fs/page_read_ahead", 4); @@ -509,7 +470,6 @@ void FileAccessNetwork::configure() { } FileAccessNetwork::FileAccessNetwork() { - eof_flag = false; opened = false; pos = 0; @@ -526,7 +486,6 @@ FileAccessNetwork::FileAccessNetwork() { } FileAccessNetwork::~FileAccessNetwork() { - close(); FileAccessNetworkClient *nc = FileAccessNetworkClient::singleton; diff --git a/core/io/file_access_network.h b/core/io/file_access_network.h index c8edeaa1198..1b1b2e43952 100644 --- a/core/io/file_access_network.h +++ b/core/io/file_access_network.h @@ -39,9 +39,7 @@ class FileAccessNetwork; class FileAccessNetworkClient { - struct BlockRequest { - int id; uint64_t offset; int size; @@ -84,7 +82,6 @@ public: }; class FileAccessNetwork : public FileAccess { - Semaphore sem; Semaphore page_sem; Mutex buffer_mutex; diff --git a/core/io/file_access_pack.cpp b/core/io/file_access_pack.cpp index 1c4e5987542..ab8b0e55caf 100644 --- a/core/io/file_access_pack.cpp +++ b/core/io/file_access_pack.cpp @@ -35,11 +35,8 @@ #include Error PackedData::add_pack(const String &p_path, bool p_replace_files, size_t p_offset) { - for (int i = 0; i < sources.size(); i++) { - if (sources[i]->try_open_pack(p_path, p_replace_files, p_offset)) { - return OK; }; }; @@ -48,7 +45,6 @@ Error PackedData::add_pack(const String &p_path, bool p_replace_files, size_t p_ }; void PackedData::add_path(const String &pkg_path, const String &path, uint64_t ofs, uint64_t size, const uint8_t *p_md5, PackSource *p_src, bool p_replace_files) { - PathMD5 pmd5(path.md5_buffer()); //printf("adding path %ls, %lli, %lli\n", path.c_str(), pmd5.a, pmd5.b); @@ -75,9 +71,7 @@ void PackedData::add_path(const String &pkg_path, const String &path, uint64_t o Vector ds = p.get_base_dir().split("/"); for (int j = 0; j < ds.size(); j++) { - if (!cd->subdirs.has(ds[j])) { - PackedDir *pd = memnew(PackedDir); pd->name = ds[j]; pd->parent = cd; @@ -97,7 +91,6 @@ void PackedData::add_path(const String &pkg_path, const String &path, uint64_t o } void PackedData::add_pack_source(PackSource *p_source) { - if (p_source != NULL) { sources.push_back(p_source); } @@ -106,7 +99,6 @@ void PackedData::add_pack_source(PackSource *p_source) { PackedData *PackedData::singleton = NULL; PackedData::PackedData() { - singleton = this; root = memnew(PackedDir); root->parent = NULL; @@ -116,14 +108,12 @@ PackedData::PackedData() { } void PackedData::_free_packed_dirs(PackedDir *p_dir) { - for (Map::Element *E = p_dir->subdirs.front(); E; E = E->next()) _free_packed_dirs(E->get()); memdelete(p_dir); } PackedData::~PackedData() { - for (int i = 0; i < sources.size(); i++) { memdelete(sources[i]); } @@ -133,7 +123,6 @@ PackedData::~PackedData() { ////////////////////////////////////////////////////////////////// bool PackedSourcePCK::try_open_pack(const String &p_path, bool p_replace_files, size_t p_offset) { - FileAccess *f = FileAccess::open(p_path, FileAccess::READ); if (!f) return false; @@ -155,7 +144,6 @@ bool PackedSourcePCK::try_open_pack(const String &p_path, bool p_replace_files, f->seek(f->get_position() - 4); magic = f->get_32(); if (magic != PACK_HEADER_MAGIC) { - f->close(); memdelete(f); return false; @@ -167,7 +155,6 @@ bool PackedSourcePCK::try_open_pack(const String &p_path, bool p_replace_files, magic = f->get_32(); if (magic != PACK_HEADER_MAGIC) { - f->close(); memdelete(f); return false; @@ -198,7 +185,6 @@ bool PackedSourcePCK::try_open_pack(const String &p_path, bool p_replace_files, int file_count = f->get_32(); for (int i = 0; i < file_count; i++) { - uint32_t sl = f->get_32(); CharString cs; cs.resize(sl + 1); @@ -221,30 +207,25 @@ bool PackedSourcePCK::try_open_pack(const String &p_path, bool p_replace_files, }; FileAccess *PackedSourcePCK::get_file(const String &p_path, PackedData::PackedFile *p_file) { - return memnew(FileAccessPack(p_path, *p_file)); }; ////////////////////////////////////////////////////////////////// Error FileAccessPack::_open(const String &p_path, int p_mode_flags) { - ERR_FAIL_V(ERR_UNAVAILABLE); return ERR_UNAVAILABLE; } void FileAccessPack::close() { - f->close(); } bool FileAccessPack::is_open() const { - return f->is_open(); } void FileAccessPack::seek(size_t p_position) { - if (p_position > pf.size) { eof = true; } else { @@ -255,25 +236,20 @@ void FileAccessPack::seek(size_t p_position) { pos = p_position; } void FileAccessPack::seek_end(int64_t p_position) { - seek(pf.size + p_position); } size_t FileAccessPack::get_position() const { - return pos; } size_t FileAccessPack::get_len() const { - return pf.size; } bool FileAccessPack::eof_reached() const { - return eof; } uint8_t FileAccessPack::get_8() const { - if (pos >= pf.size) { eof = true; return 0; @@ -311,36 +287,30 @@ void FileAccessPack::set_endian_swap(bool p_swap) { } Error FileAccessPack::get_error() const { - if (eof) return ERR_FILE_EOF; return OK; } void FileAccessPack::flush() { - ERR_FAIL(); } void FileAccessPack::store_8(uint8_t p_dest) { - ERR_FAIL(); } void FileAccessPack::store_buffer(const uint8_t *p_src, int p_length) { - ERR_FAIL(); } bool FileAccessPack::file_exists(const String &p_name) { - return false; } FileAccessPack::FileAccessPack(const String &p_path, const PackedData::PackedFile &p_file) : pf(p_file), f(FileAccess::open(pf.pack, FileAccess::READ)) { - ERR_FAIL_COND_MSG(!f, "Can't open pack-referenced file '" + String(pf.pack) + "'."); f->seek(pf.offset); @@ -358,17 +328,14 @@ FileAccessPack::~FileAccessPack() { ////////////////////////////////////////////////////////////////////////////////// Error DirAccessPack::list_dir_begin() { - list_dirs.clear(); list_files.clear(); for (Map::Element *E = current->subdirs.front(); E; E = E->next()) { - list_dirs.push_back(E->key()); } for (Set::Element *E = current->files.front(); E; E = E->next()) { - list_files.push_back(E->get()); } @@ -376,7 +343,6 @@ Error DirAccessPack::list_dir_begin() { } String DirAccessPack::get_next() { - if (list_dirs.size()) { cdir = true; String d = list_dirs.front()->get(); @@ -392,30 +358,24 @@ String DirAccessPack::get_next() { } } bool DirAccessPack::current_is_dir() const { - return cdir; } bool DirAccessPack::current_is_hidden() const { - return false; } void DirAccessPack::list_dir_end() { - list_dirs.clear(); list_files.clear(); } int DirAccessPack::get_drive_count() { - return 0; } String DirAccessPack::get_drive(int p_drive) { - return ""; } PackedData::PackedDir *DirAccessPack::_find_dir(String p_dir) { - String nd = p_dir.replace("\\", "/"); // Special handling since simplify_path() will forbid it @@ -449,7 +409,6 @@ PackedData::PackedDir *DirAccessPack::_find_dir(String p_dir) { pd = current; for (int i = 0; i < paths.size(); i++) { - String p = paths[i]; if (p == ".") { continue; @@ -458,11 +417,9 @@ PackedData::PackedDir *DirAccessPack::_find_dir(String p_dir) { pd = pd->parent; } } else if (pd->subdirs.has(p)) { - pd = pd->subdirs[p]; } else { - return NULL; } } @@ -471,7 +428,6 @@ PackedData::PackedDir *DirAccessPack::_find_dir(String p_dir) { } Error DirAccessPack::change_dir(String p_dir) { - PackedData::PackedDir *pd = _find_dir(p_dir); if (pd) { current = pd; @@ -482,7 +438,6 @@ Error DirAccessPack::change_dir(String p_dir) { } String DirAccessPack::get_current_dir() { - PackedData::PackedDir *pd = current; String p = current->name; @@ -495,7 +450,6 @@ String DirAccessPack::get_current_dir() { } bool DirAccessPack::file_exists(String p_file) { - p_file = fix_path(p_file); PackedData::PackedDir *pd = _find_dir(p_file.get_base_dir()); @@ -506,28 +460,23 @@ bool DirAccessPack::file_exists(String p_file) { } bool DirAccessPack::dir_exists(String p_dir) { - p_dir = fix_path(p_dir); return _find_dir(p_dir) != NULL; } Error DirAccessPack::make_dir(String p_dir) { - return ERR_UNAVAILABLE; } Error DirAccessPack::rename(String p_from, String p_to) { - return ERR_UNAVAILABLE; } Error DirAccessPack::remove(String p_name) { - return ERR_UNAVAILABLE; } size_t DirAccessPack::get_space_left() { - return 0; } @@ -536,7 +485,6 @@ String DirAccessPack::get_filesystem_type() const { } DirAccessPack::DirAccessPack() { - current = PackedData::get_singleton()->root; cdir = false; } diff --git a/core/io/file_access_pack.h b/core/io/file_access_pack.h index 2a1e7315b59..db4029e6de3 100644 --- a/core/io/file_access_pack.h +++ b/core/io/file_access_pack.h @@ -52,7 +52,6 @@ class PackedData { public: struct PackedFile { - String pack; uint64_t offset; //if offset is ZERO, the file was ERASED uint64_t size; @@ -72,7 +71,6 @@ private: uint64_t a; uint64_t b; bool operator<(const PathMD5 &p_md5) const { - if (p_md5.a == a) { return b < p_md5.b; } else { @@ -127,7 +125,6 @@ public: }; class PackSource { - public: virtual bool try_open_pack(const String &p_path, bool p_replace_files, size_t p_offset) = 0; virtual FileAccess *get_file(const String &p_path, PackedData::PackedFile *p_file) = 0; @@ -135,14 +132,12 @@ public: }; class PackedSourcePCK : public PackSource { - public: virtual bool try_open_pack(const String &p_path, bool p_replace_files, size_t p_offset); virtual FileAccess *get_file(const String &p_path, PackedData::PackedFile *p_file); }; class FileAccessPack : public FileAccess { - PackedData::PackedFile pf; mutable size_t pos; @@ -185,7 +180,6 @@ public: }; FileAccess *PackedData::try_open_path(const String &p_path) { - PathMD5 pmd5(p_path.md5_buffer()); Map::Element *E = files.find(pmd5); if (!E) @@ -197,12 +191,10 @@ FileAccess *PackedData::try_open_path(const String &p_path) { } bool PackedData::has_path(const String &p_path) { - return files.has(PathMD5(p_path.md5_buffer())); } bool PackedData::has_directory(const String &p_path) { - DirAccess *da = try_open_directory(p_path); if (da) { memdelete(da); @@ -213,7 +205,6 @@ bool PackedData::has_directory(const String &p_path) { } class DirAccessPack : public DirAccess { - PackedData::PackedDir *current; List list_dirs; @@ -252,7 +243,6 @@ public: }; DirAccess *PackedData::try_open_directory(const String &p_path) { - DirAccess *da = memnew(DirAccessPack()); if (da->change_dir(p_path) != OK) { memdelete(da); diff --git a/core/io/file_access_zip.cpp b/core/io/file_access_zip.cpp index a8c0cfc41f5..5c56d643f06 100644 --- a/core/io/file_access_zip.cpp +++ b/core/io/file_access_zip.cpp @@ -39,7 +39,6 @@ ZipArchive *ZipArchive::instance = NULL; extern "C" { static void *godot_open(void *data, const char *p_fname, int mode) { - if (mode & ZLIB_FILEFUNC_MODE_WRITE) { return NULL; } @@ -51,30 +50,25 @@ static void *godot_open(void *data, const char *p_fname, int mode) { } static uLong godot_read(void *data, void *fdata, void *buf, uLong size) { - FileAccess *f = (FileAccess *)data; f->get_buffer((uint8_t *)buf, size); return size; } static uLong godot_write(voidpf opaque, voidpf stream, const void *buf, uLong size) { - return 0; } static long godot_tell(voidpf opaque, voidpf stream) { - FileAccess *f = (FileAccess *)opaque; return f->get_position(); } static long godot_seek(voidpf opaque, voidpf stream, uLong offset, int origin) { - FileAccess *f = (FileAccess *)opaque; int pos = offset; switch (origin) { - case ZLIB_FILEFUNC_SEEK_CUR: pos = f->get_position() + offset; break; @@ -90,32 +84,27 @@ static long godot_seek(voidpf opaque, voidpf stream, uLong offset, int origin) { } static int godot_close(voidpf opaque, voidpf stream) { - FileAccess *f = (FileAccess *)opaque; f->close(); return 0; } static int godot_testerror(voidpf opaque, voidpf stream) { - FileAccess *f = (FileAccess *)opaque; return f->get_error() != OK ? 1 : 0; } static voidpf godot_alloc(voidpf opaque, uInt items, uInt size) { - return memalloc(items * size); } static void godot_free(voidpf opaque, voidpf address) { - memfree(address); } } // extern "C" void ZipArchive::close_handle(unzFile p_file) const { - ERR_FAIL_COND_MSG(!p_file, "Cannot close a file if none is open."); FileAccess *f = (FileAccess *)unzGetOpaque(p_file); unzCloseCurrentFile(p_file); @@ -124,7 +113,6 @@ void ZipArchive::close_handle(unzFile p_file) const { } unzFile ZipArchive::get_file_handle(String p_file) const { - ERR_FAIL_COND_V_MSG(!file_exists(p_file), NULL, "File '" + p_file + " doesn't exist."); File file = files[p_file]; @@ -151,7 +139,6 @@ unzFile ZipArchive::get_file_handle(String p_file) const { ERR_FAIL_COND_V(!pkg, NULL); int unz_err = unzGoToFilePos(pkg, &file.file_pos); if (unz_err != UNZ_OK || unzOpenCurrentFile(pkg) != UNZ_OK) { - unzClose(pkg); ERR_FAIL_V(NULL); } @@ -160,7 +147,6 @@ unzFile ZipArchive::get_file_handle(String p_file) const { } bool ZipArchive::try_open_pack(const String &p_path, bool p_replace_files, size_t p_offset = 0) { - //printf("opening zip pack %ls, %i, %i\n", p_name.c_str(), p_name.extension().nocasecmp_to("zip"), p_name.extension().nocasecmp_to("pcz")); // load with offset feature only supported for PCK files ERR_FAIL_COND_V_MSG(p_offset != 0, false, "Invalid PCK data. Note that loading files with a non-zero offset isn't supported with ZIP archives."); @@ -197,7 +183,6 @@ bool ZipArchive::try_open_pack(const String &p_path, bool p_replace_files, size_ int pkg_num = packages.size() - 1; for (uint64_t i = 0; i < gi.number_entry; i++) { - char filename_inzip[256]; unz_file_info64 file_info; @@ -224,17 +209,14 @@ bool ZipArchive::try_open_pack(const String &p_path, bool p_replace_files, size_ } bool ZipArchive::file_exists(String p_name) const { - return files.has(p_name); } FileAccess *ZipArchive::get_file(const String &p_path, PackedData::PackedFile *p_file) { - return memnew(FileAccessZip(p_path, *p_file)); } ZipArchive *ZipArchive::get_singleton() { - if (instance == NULL) { instance = memnew(ZipArchive); } @@ -243,15 +225,12 @@ ZipArchive *ZipArchive::get_singleton() { } ZipArchive::ZipArchive() { - instance = this; //fa_create_func = FileAccess::get_create_func(); } ZipArchive::~ZipArchive() { - for (int i = 0; i < packages.size(); i++) { - FileAccess *f = (FileAccess *)unzGetOpaque(packages[i].zfile); unzClose(packages[i].zfile); memdelete(f); @@ -261,7 +240,6 @@ ZipArchive::~ZipArchive() { } Error FileAccessZip::_open(const String &p_path, int p_mode_flags) { - close(); ERR_FAIL_COND_V(p_mode_flags & FileAccess::WRITE, FAILED); @@ -277,7 +255,6 @@ Error FileAccessZip::_open(const String &p_path, int p_mode_flags) { } void FileAccessZip::close() { - if (!zfile) return; @@ -288,43 +265,36 @@ void FileAccessZip::close() { } bool FileAccessZip::is_open() const { - return zfile != NULL; } void FileAccessZip::seek(size_t p_position) { - ERR_FAIL_COND(!zfile); unzSeekCurrentFile(zfile, p_position); } void FileAccessZip::seek_end(int64_t p_position) { - ERR_FAIL_COND(!zfile); unzSeekCurrentFile(zfile, get_len() + p_position); } size_t FileAccessZip::get_position() const { - ERR_FAIL_COND_V(!zfile, 0); return unztell(zfile); } size_t FileAccessZip::get_len() const { - ERR_FAIL_COND_V(!zfile, 0); return file_info.uncompressed_size; } bool FileAccessZip::eof_reached() const { - ERR_FAIL_COND_V(!zfile, true); return at_eof; } uint8_t FileAccessZip::get_8() const { - uint8_t ret = 0; get_buffer(&ret, 1); return ret; @@ -345,9 +315,7 @@ int FileAccessZip::get_buffer(uint8_t *p_dst, int p_length) const { } Error FileAccessZip::get_error() const { - if (!zfile) { - return ERR_UNCONFIGURED; } if (eof_reached()) { @@ -358,17 +326,14 @@ Error FileAccessZip::get_error() const { } void FileAccessZip::flush() { - ERR_FAIL(); } void FileAccessZip::store_8(uint8_t p_dest) { - ERR_FAIL(); } bool FileAccessZip::file_exists(const String &p_name) { - return false; } @@ -378,7 +343,6 @@ FileAccessZip::FileAccessZip(const String &p_path, const PackedData::PackedFile } FileAccessZip::~FileAccessZip() { - close(); } diff --git a/core/io/file_access_zip.h b/core/io/file_access_zip.h index da85c47a6f4..20d5d40fe3d 100644 --- a/core/io/file_access_zip.h +++ b/core/io/file_access_zip.h @@ -41,14 +41,11 @@ #include class ZipArchive : public PackSource { - public: struct File { - int package; unz_file_pos file_pos; File() { - package = -1; }; }; diff --git a/core/io/http_client.cpp b/core/io/http_client.cpp index cc99dac585c..073a2c0e066 100644 --- a/core/io/http_client.cpp +++ b/core/io/http_client.cpp @@ -47,7 +47,6 @@ const char *HTTPClient::_methods[METHOD_MAX] = { #ifndef JAVASCRIPT_ENABLED Error HTTPClient::connect_to_host(const String &p_host, int p_port, bool p_ssl, bool p_verify_host) { - close(); conn_port = p_port; @@ -58,10 +57,8 @@ Error HTTPClient::connect_to_host(const String &p_host, int p_port, bool p_ssl, String host_lower = conn_host.to_lower(); if (host_lower.begins_with("http://")) { - conn_host = conn_host.substr(7, conn_host.length() - 7); } else if (host_lower.begins_with("https://")) { - ssl = true; conn_host = conn_host.substr(8, conn_host.length() - 8); } @@ -97,7 +94,6 @@ Error HTTPClient::connect_to_host(const String &p_host, int p_port, bool p_ssl, } void HTTPClient::set_connection(const Ref &p_connection) { - ERR_FAIL_COND_MSG(p_connection.is_null(), "Connection is not a reference to a valid StreamPeer object."); if (ssl) { @@ -115,7 +111,6 @@ void HTTPClient::set_connection(const Ref &p_connection) { } Ref HTTPClient::get_connection() const { - return connection; } @@ -212,7 +207,6 @@ Error HTTPClient::request_raw(Method p_method, const String &p_url, const Vector } Error HTTPClient::request(Method p_method, const String &p_url, const Vector &p_headers, const String &p_body) { - ERR_FAIL_INDEX_V(p_method, METHOD_MAX, ERR_INVALID_PARAMETER); ERR_FAIL_COND_V(!_check_request_url(p_method, p_url), ERR_INVALID_PARAMETER); ERR_FAIL_COND_V(status != STATUS_CONNECTED, ERR_INVALID_PARAMETER); @@ -274,27 +268,22 @@ Error HTTPClient::request(Method p_method, const String &p_url, const Vector *r_response) { - if (!response_headers.size()) return ERR_INVALID_PARAMETER; for (int i = 0; i < response_headers.size(); i++) { - r_response->push_back(response_headers[i]); } @@ -304,7 +293,6 @@ Error HTTPClient::get_response_headers(List *r_response) { } void HTTPClient::close() { - if (tcp_connection->get_status() != StreamPeerTCP::STATUS_NONE) tcp_connection->disconnect_from_host(); @@ -312,7 +300,6 @@ void HTTPClient::close() { status = STATUS_DISCONNECTED; head_request = false; if (resolving != IP::RESOLVER_INVALID_ID) { - IP::get_singleton()->erase_resolve_item(resolving); resolving = IP::RESOLVER_INVALID_ID; } @@ -329,9 +316,7 @@ void HTTPClient::close() { } Error HTTPClient::poll() { - switch (status) { - case STATUS_RESOLVING: { ERR_FAIL_COND_V(resolving == IP::RESOLVER_INVALID_ID, ERR_BUG); @@ -341,7 +326,6 @@ Error HTTPClient::poll() { return OK; // Still resolving case IP::RESOLVER_STATUS_DONE: { - IP_Address host = IP::get_singleton()->get_resolve_item_address(resolving); Error err = tcp_connection->connect_to_host(host, conn_port); IP::get_singleton()->erase_resolve_item(resolving); @@ -355,7 +339,6 @@ Error HTTPClient::poll() { } break; case IP::RESOLVER_STATUS_NONE: case IP::RESOLVER_STATUS_ERROR: { - IP::get_singleton()->erase_resolve_item(resolving); resolving = IP::RESOLVER_INVALID_ID; close(); @@ -365,10 +348,8 @@ Error HTTPClient::poll() { } } break; case STATUS_CONNECTING: { - StreamPeerTCP::Status s = tcp_connection->get_status(); switch (s) { - case StreamPeerTCP::STATUS_CONNECTING: { return OK; } break; @@ -418,7 +399,6 @@ Error HTTPClient::poll() { } break; case StreamPeerTCP::STATUS_ERROR: case StreamPeerTCP::STATUS_NONE: { - close(); status = STATUS_CANT_CONNECT; return ERR_CANT_CONNECT; @@ -443,7 +423,6 @@ Error HTTPClient::poll() { return OK; } break; case STATUS_REQUESTING: { - while (true) { uint8_t byte; int rec = 0; @@ -462,7 +441,6 @@ Error HTTPClient::poll() { if ( (rs >= 2 && response_str[rs - 2] == '\n' && response_str[rs - 1] == '\n') || (rs >= 4 && response_str[rs - 4] == '\r' && response_str[rs - 3] == '\n' && response_str[rs - 2] == '\r' && response_str[rs - 1] == '\n')) { - // End of response, parse. response_str.push_back(0); String response; @@ -484,7 +462,6 @@ Error HTTPClient::poll() { bool keep_alive = true; for (int i = 0; i < responses.size(); i++) { - String header = responses[i].strip_edges(); String s = header.to_lower(); if (s.length() == 0) @@ -503,11 +480,9 @@ Error HTTPClient::poll() { } if (i == 0 && responses[i].begins_with("HTTP")) { - String num = responses[i].get_slicec(' ', 1); response_num = num.to_int(); } else { - response_headers.push_back(header); } } @@ -519,14 +494,11 @@ Error HTTPClient::poll() { } if (body_size != -1 || chunked) { - status = STATUS_BODY; } else if (!keep_alive) { - read_until_eof = true; status = STATUS_BODY; } else { - status = STATUS_CONNECTED; } return OK; @@ -552,21 +524,17 @@ Error HTTPClient::poll() { } int HTTPClient::get_response_body_length() const { - return body_size; } PoolByteArray HTTPClient::read_response_body_chunk() { - ERR_FAIL_COND_V(status != STATUS_BODY, PoolByteArray()); PoolByteArray ret; Error err = OK; if (chunked) { - while (true) { - if (chunk_trailer_part) { // We need to consume the trailer part too or keep-alive will break uint8_t b; @@ -608,7 +576,6 @@ PoolByteArray HTTPClient::read_response_body_chunk() { } if (chunk.size() > 2 && chunk[chunk.size() - 2] == '\r' && chunk[chunk.size() - 1] == '\n') { - int len = 0; for (int i = 0; i < chunk.size() - 2; i++) { char c = chunk[i]; @@ -644,7 +611,6 @@ PoolByteArray HTTPClient::read_response_body_chunk() { chunk.resize(chunk_left); } } else { - int rec = 0; err = _get_http_data(&chunk.write[chunk.size() - chunk_left], chunk_left, rec); if (rec == 0) { @@ -653,7 +619,6 @@ PoolByteArray HTTPClient::read_response_body_chunk() { chunk_left -= rec; if (chunk_left == 0) { - if (chunk[chunk.size() - 2] != '\r' || chunk[chunk.size() - 1] != '\n') { ERR_PRINT("HTTP Invalid chunk terminator (not \\r\\n)"); status = STATUS_CONNECTION_ERROR; @@ -671,7 +636,6 @@ PoolByteArray HTTPClient::read_response_body_chunk() { } } else { - int to_read = !read_until_eof ? MIN(body_left, read_chunk_size) : read_chunk_size; ret.resize(to_read); int _offset = 0; @@ -697,18 +661,14 @@ PoolByteArray HTTPClient::read_response_body_chunk() { } if (err != OK) { - close(); if (err == ERR_FILE_EOF) { - status = STATUS_DISCONNECTED; // Server disconnected } else { - status = STATUS_CONNECTION_ERROR; } } else if (body_left == 0 && !chunked && !read_until_eof) { - status = STATUS_CONNECTED; } @@ -716,24 +676,19 @@ PoolByteArray HTTPClient::read_response_body_chunk() { } HTTPClient::Status HTTPClient::get_status() const { - return status; } void HTTPClient::set_blocking_mode(bool p_enable) { - blocking = p_enable; } bool HTTPClient::is_blocking_mode_enabled() const { - return blocking; } Error HTTPClient::_get_http_data(uint8_t *p_buffer, int p_bytes, int &r_received) { - if (blocking) { - // We can't use StreamPeer.get_data, since when reaching EOF we will get an // error without knowing how many bytes we received. Error err = ERR_FILE_EOF; @@ -768,7 +723,6 @@ int HTTPClient::get_read_chunk_size() const { } HTTPClient::HTTPClient() { - tcp_connection.instance(); resolving = IP::RESOLVER_INVALID_ID; status = STATUS_DISCONNECTED; @@ -824,7 +778,6 @@ String HTTPClient::query_string_from_dict(const Dictionary &p_dict) { } Dictionary HTTPClient::_get_response_headers_as_dictionary() { - List rh; get_response_headers(&rh); Dictionary ret; @@ -842,7 +795,6 @@ Dictionary HTTPClient::_get_response_headers_as_dictionary() { } PoolStringArray HTTPClient::_get_response_headers() { - List rh; get_response_headers(&rh); PoolStringArray ret; @@ -856,7 +808,6 @@ PoolStringArray HTTPClient::_get_response_headers() { } void HTTPClient::_bind_methods() { - ClassDB::bind_method(D_METHOD("connect_to_host", "host", "port", "use_ssl", "verify_host"), &HTTPClient::connect_to_host, DEFVAL(-1), DEFVAL(false), DEFVAL(true)); ClassDB::bind_method(D_METHOD("set_connection", "connection"), &HTTPClient::set_connection); ClassDB::bind_method(D_METHOD("get_connection"), &HTTPClient::get_connection); diff --git a/core/io/http_client.h b/core/io/http_client.h index 10748743c1d..9a14d72bd61 100644 --- a/core/io/http_client.h +++ b/core/io/http_client.h @@ -37,7 +37,6 @@ #include "core/reference.h" class HTTPClient : public Reference { - GDCLASS(HTTPClient, Reference); public: diff --git a/core/io/image_loader.cpp b/core/io/image_loader.cpp index ee52bc20d88..116cf35420d 100644 --- a/core/io/image_loader.cpp +++ b/core/io/image_loader.cpp @@ -33,11 +33,9 @@ #include "core/print_string.h" 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) return true; } @@ -61,7 +59,6 @@ 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)) continue; Error err = loader[i]->load_image(p_image, f, p_force_linear, p_scale); @@ -70,7 +67,6 @@ Error ImageLoader::load_image(String p_file, Ref p_image, FileAccess *p_c } if (err != ERR_FILE_UNRECOGNIZED) { - if (!p_custom) memdelete(f); @@ -85,17 +81,13 @@ Error ImageLoader::load_image(String p_file, Ref p_image, FileAccess *p_c } void ImageLoader::get_recognized_extensions(List *p_extensions) { - for (int i = 0; i < loader.size(); i++) { - loader[i]->get_recognized_extensions(p_extensions); } } ImageFormatLoader *ImageLoader::recognize(const String &p_extension) { - for (int i = 0; i < loader.size(); i++) { - if (loader[i]->recognize(p_extension)) return loader[i]; } @@ -106,22 +98,18 @@ ImageFormatLoader *ImageLoader::recognize(const String &p_extension) { Vector ImageLoader::loader; void ImageLoader::add_image_format_loader(ImageFormatLoader *p_loader) { - loader.push_back(p_loader); } void ImageLoader::remove_image_format_loader(ImageFormatLoader *p_loader) { - loader.erase(p_loader); } const Vector &ImageLoader::get_image_format_loaders() { - return loader; } void ImageLoader::cleanup() { - while (loader.size()) { remove_image_format_loader(loader[0]); } @@ -130,7 +118,6 @@ void ImageLoader::cleanup() { ///////////////// RES ResourceFormatLoaderImage::load(const String &p_path, const String &p_original_path, Error *r_error) { - FileAccess *f = FileAccess::open(p_path, FileAccess::READ); if (!f) { if (r_error) { @@ -192,16 +179,13 @@ RES ResourceFormatLoaderImage::load(const String &p_path, const String &p_origin } void ResourceFormatLoaderImage::get_recognized_extensions(List *p_extensions) const { - p_extensions->push_back("image"); } bool ResourceFormatLoaderImage::handles_type(const String &p_type) const { - return p_type == "Image"; } String ResourceFormatLoaderImage::get_resource_type(const String &p_path) const { - return p_path.get_extension().to_lower() == "image" ? "Image" : String(); } diff --git a/core/io/image_loader.h b/core/io/image_loader.h index 1bb2bc1dd52..6caad3384a6 100644 --- a/core/io/image_loader.h +++ b/core/io/image_loader.h @@ -53,7 +53,6 @@ public: }; class ImageLoader { - static Vector loader; friend class ResourceFormatLoaderImage; diff --git a/core/io/ip.cpp b/core/io/ip.cpp index 3c755be451d..8b0def6124c 100644 --- a/core/io/ip.cpp +++ b/core/io/ip.cpp @@ -39,9 +39,7 @@ VARIANT_ENUM_CAST(IP::ResolverStatus); /************* RESOLVER ******************/ struct _IP_ResolverPrivate { - struct QueueItem { - SafeNumeric status; IP_Address response; String hostname; @@ -62,7 +60,6 @@ struct _IP_ResolverPrivate { QueueItem queue[IP::RESOLVER_MAX_QUERIES]; IP::ResolverID find_empty_id() const { - for (int i = 0; i < IP::RESOLVER_MAX_QUERIES; i++) { if (queue[i].status.get() == IP::RESOLVER_STATUS_NONE) return i; @@ -78,9 +75,7 @@ struct _IP_ResolverPrivate { bool thread_abort; void resolve_queues() { - for (int i = 0; i < IP::RESOLVER_MAX_QUERIES; i++) { - if (queue[i].status.get() != IP::RESOLVER_STATUS_WAITING) continue; queue[i].response = IP::get_singleton()->resolve_hostname(queue[i].hostname, queue[i].type); @@ -93,11 +88,9 @@ struct _IP_ResolverPrivate { } static void _thread_function(void *self) { - _IP_ResolverPrivate *ipr = (_IP_ResolverPrivate *)self; while (!ipr->thread_abort) { - ipr->sem.wait(); ipr->mutex.lock(); @@ -114,7 +107,6 @@ struct _IP_ResolverPrivate { }; IP_Address IP::resolve_hostname(const String &p_hostname, IP::Type p_type) { - resolver->mutex.lock(); String key = _IP_ResolverPrivate::get_cache_key(p_hostname, p_type); @@ -131,7 +123,6 @@ IP_Address IP::resolve_hostname(const String &p_hostname, IP::Type p_type) { } IP::ResolverID IP::resolve_hostname_queue_item(const String &p_hostname, IP::Type p_type) { - resolver->mutex.lock(); ResolverID id = resolver->find_empty_id(); @@ -162,7 +153,6 @@ IP::ResolverID IP::resolve_hostname_queue_item(const String &p_hostname, IP::Typ } IP::ResolverStatus IP::get_resolve_item_status(ResolverID p_id) const { - ERR_FAIL_INDEX_V(p_id, IP::RESOLVER_MAX_QUERIES, IP::RESOLVER_STATUS_NONE); resolver->mutex.lock(); @@ -178,7 +168,6 @@ IP::ResolverStatus IP::get_resolve_item_status(ResolverID p_id) const { } IP_Address IP::get_resolve_item_address(ResolverID p_id) const { - ERR_FAIL_INDEX_V(p_id, IP::RESOLVER_MAX_QUERIES, IP_Address()); resolver->mutex.lock(); @@ -196,7 +185,6 @@ IP_Address IP::get_resolve_item_address(ResolverID p_id) const { } void IP::erase_resolve_item(ResolverID p_id) { - ERR_FAIL_INDEX(p_id, IP::RESOLVER_MAX_QUERIES); resolver->mutex.lock(); @@ -207,7 +195,6 @@ void IP::erase_resolve_item(ResolverID p_id) { } void IP::clear_cache(const String &p_hostname) { - resolver->mutex.lock(); if (p_hostname.empty()) { @@ -223,7 +210,6 @@ void IP::clear_cache(const String &p_hostname) { } Array IP::_get_local_addresses() const { - Array addresses; List ip_addresses; get_local_addresses(&ip_addresses); @@ -235,7 +221,6 @@ Array IP::_get_local_addresses() const { } Array IP::_get_local_interfaces() const { - Array results; Map interfaces; get_local_interfaces(&interfaces); @@ -259,7 +244,6 @@ Array IP::_get_local_interfaces() const { } void IP::get_local_addresses(List *r_addresses) const { - Map interfaces; get_local_interfaces(&interfaces); for (Map::Element *E = interfaces.front(); E; E = E->next()) { @@ -270,7 +254,6 @@ void IP::get_local_addresses(List *r_addresses) const { } void IP::_bind_methods() { - ClassDB::bind_method(D_METHOD("resolve_hostname", "host", "ip_type"), &IP::resolve_hostname, DEFVAL(IP::TYPE_ANY)); ClassDB::bind_method(D_METHOD("resolve_hostname_queue_item", "host", "ip_type"), &IP::resolve_hostname_queue_item, DEFVAL(IP::TYPE_ANY)); ClassDB::bind_method(D_METHOD("get_resolve_item_status", "id"), &IP::get_resolve_item_status); @@ -297,21 +280,18 @@ void IP::_bind_methods() { IP *IP::singleton = NULL; IP *IP::get_singleton() { - return singleton; } IP *(*IP::_create)() = NULL; IP *IP::create() { - ERR_FAIL_COND_V_MSG(singleton, NULL, "IP singleton already exist."); ERR_FAIL_COND_V(!_create, NULL); return _create(); } IP::IP() { - singleton = this; resolver = memnew(_IP_ResolverPrivate); @@ -320,7 +300,6 @@ IP::IP() { } IP::~IP() { - resolver->thread_abort = true; resolver->sem.post(); resolver->thread.wait_to_finish(); diff --git a/core/io/ip_address.cpp b/core/io/ip_address.cpp index 80afef03fc3..d473865fad0 100644 --- a/core/io/ip_address.cpp +++ b/core/io/ip_address.cpp @@ -39,7 +39,6 @@ IP_Address::operator Variant() const { #include IP_Address::operator String() const { - if (wildcard) return "*"; @@ -61,10 +60,8 @@ IP_Address::operator String() const { } static void _parse_hex(const String &p_string, int p_start, uint8_t *p_dst) { - uint16_t ret = 0; for (int i = p_start; i < p_start + 4; i++) { - if (i >= p_string.length()) { break; }; @@ -72,7 +69,6 @@ static void _parse_hex(const String &p_string, int p_start, uint8_t *p_dst) { int n = 0; CharType c = p_string[i]; if (c >= '0' && c <= '9') { - n = c - '0'; } else if (c >= 'a' && c <= 'f') { n = 10 + (c - 'a'); @@ -92,7 +88,6 @@ static void _parse_hex(const String &p_string, int p_start, uint8_t *p_dst) { }; void IP_Address::_parse_ipv6(const String &p_string) { - static const int parts_total = 8; int parts[parts_total] = { 0 }; int parts_count = 0; @@ -102,10 +97,8 @@ void IP_Address::_parse_ipv6(const String &p_string) { int parts_idx = 0; for (int i = 0; i < p_string.length(); i++) { - CharType c = p_string[i]; if (c == ':') { - if (i == 0) { continue; // next must be a ":" }; @@ -115,7 +108,6 @@ void IP_Address::_parse_ipv6(const String &p_string) { }; part_found = false; } else if (c == '.') { - part_ipv4 = true; } else if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')) { @@ -136,9 +128,7 @@ void IP_Address::_parse_ipv6(const String &p_string) { int idx = 0; for (int i = 0; i < parts_idx; i++) { - if (parts[i] == -1) { - for (int j = 0; j < parts_extra; j++) { field16[idx++] = 0; }; @@ -154,7 +144,6 @@ void IP_Address::_parse_ipv6(const String &p_string) { }; void IP_Address::_parse_ipv4(const String &p_string, int p_start, uint8_t *p_ret) { - String ip; if (p_start != 0) { ip = p_string.substr(p_start, p_string.length() - p_start); @@ -170,7 +159,6 @@ void IP_Address::_parse_ipv4(const String &p_string, int p_start, uint8_t *p_ret }; void IP_Address::clear() { - memset(&field8[0], 0, sizeof(field8)); valid = false; wildcard = false; @@ -204,7 +192,6 @@ void IP_Address::set_ipv6(const uint8_t *p_buf) { } IP_Address::IP_Address(const String &p_string) { - clear(); if (p_string == "*") { @@ -228,7 +215,6 @@ IP_Address::IP_Address(const String &p_string) { } _FORCE_INLINE_ static void _32_to_buf(uint8_t *p_dst, uint32_t p_n) { - p_dst[0] = (p_n >> 24) & 0xff; p_dst[1] = (p_n >> 16) & 0xff; p_dst[2] = (p_n >> 8) & 0xff; @@ -236,7 +222,6 @@ _FORCE_INLINE_ static void _32_to_buf(uint8_t *p_dst, uint32_t p_n) { }; IP_Address::IP_Address(uint32_t p_a, uint32_t p_b, uint32_t p_c, uint32_t p_d, bool is_v6) { - clear(); valid = true; if (!is_v6) { @@ -247,7 +232,6 @@ IP_Address::IP_Address(uint32_t p_a, uint32_t p_b, uint32_t p_c, uint32_t p_d, b field8[14] = p_c; field8[15] = p_d; } else { - _32_to_buf(&field8[0], p_a); _32_to_buf(&field8[4], p_b); _32_to_buf(&field8[8], p_c); diff --git a/core/io/ip_address.h b/core/io/ip_address.h index 98e657ae79c..46bb06475c1 100644 --- a/core/io/ip_address.h +++ b/core/io/ip_address.h @@ -34,7 +34,6 @@ #include "core/ustring.h" struct IP_Address { - private: union { uint8_t field8[16]; diff --git a/core/io/json.cpp b/core/io/json.cpp index 357c450170b..dbaf24174a8 100644 --- a/core/io/json.cpp +++ b/core/io/json.cpp @@ -46,7 +46,6 @@ 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++) @@ -56,7 +55,6 @@ static String _make_indent(const String &p_indent, int p_size) { } String JSON::_print_var(const Variant &p_var, const String &p_indent, int p_cur_indent, bool p_sort_keys) { - String colon = ":"; String end_statement = ""; @@ -66,7 +64,6 @@ String JSON::_print_var(const Variant &p_var, const String &p_indent, int p_cur_ } switch (p_var.get_type()) { - case Variant::NIL: return "null"; case Variant::BOOL: @@ -79,7 +76,6 @@ String JSON::_print_var(const Variant &p_var, const String &p_indent, int p_cur_ case Variant::POOL_REAL_ARRAY: case Variant::POOL_STRING_ARRAY: case Variant::ARRAY: { - String s = "["; s += end_statement; Array a = p_var; @@ -94,7 +90,6 @@ String JSON::_print_var(const Variant &p_var, const String &p_indent, int p_cur_ return s; }; case Variant::DICTIONARY: { - String s = "{"; s += end_statement; Dictionary d = p_var; @@ -105,7 +100,6 @@ String JSON::_print_var(const Variant &p_var, const String &p_indent, int p_cur_ keys.sort(); for (List::Element *E = keys.front(); E; E = E->next()) { - if (E != keys.front()) { s += ","; s += end_statement; @@ -124,17 +118,13 @@ String JSON::_print_var(const Variant &p_var, const String &p_indent, int p_cur_ } String JSON::print(const Variant &p_var, const String &p_indent, bool p_sort_keys) { - return _print_var(p_var, p_indent, 0, p_sort_keys); } Error JSON::_get_token(const CharType *p_str, int &index, int p_len, Token &r_token, int &line, String &r_err_str) { - while (p_len > 0) { switch (p_str[index]) { - case '\n': { - line++; index++; break; @@ -144,43 +134,36 @@ Error JSON::_get_token(const CharType *p_str, int &index, int p_len, Token &r_to return OK; } break; case '{': { - r_token.type = TK_CURLY_BRACKET_OPEN; index++; return OK; }; case '}': { - r_token.type = TK_CURLY_BRACKET_CLOSE; index++; return OK; }; case '[': { - r_token.type = TK_BRACKET_OPEN; index++; return OK; }; case ']': { - r_token.type = TK_BRACKET_CLOSE; index++; return OK; }; case ':': { - r_token.type = TK_COLON; index++; return OK; }; case ',': { - r_token.type = TK_COMMA; index++; return OK; }; case '"': { - index++; String str; while (true) { @@ -201,7 +184,6 @@ Error JSON::_get_token(const CharType *p_str, int &index, int p_len, Token &r_to CharType res = 0; switch (next) { - case 'b': res = 8; break; @@ -227,7 +209,6 @@ Error JSON::_get_token(const CharType *p_str, int &index, int p_len, Token &r_to return ERR_PARSE_ERROR; } if (!((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))) { - r_err_str = "Malformed hex constant in string"; return ERR_PARSE_ERROR; } @@ -277,7 +258,6 @@ Error JSON::_get_token(const CharType *p_str, int &index, int p_len, Token &r_to } break; default: { - if (p_str[index] <= 32) { index++; break; @@ -293,11 +273,9 @@ Error JSON::_get_token(const CharType *p_str, int &index, int p_len, Token &r_to return OK; } else if ((p_str[index] >= 'A' && p_str[index] <= 'Z') || (p_str[index] >= 'a' && p_str[index] <= 'z')) { - String id; while ((p_str[index] >= 'A' && p_str[index] <= 'Z') || (p_str[index] >= 'a' && p_str[index] <= 'z')) { - id += p_str[index]; index++; } @@ -317,23 +295,19 @@ Error JSON::_get_token(const CharType *p_str, int &index, int p_len, Token &r_to } Error JSON::_parse_value(Variant &value, Token &token, const CharType *p_str, int &index, int p_len, int &line, String &r_err_str) { - 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) return err; value = d; } 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) return err; value = a; } else if (token.type == TK_IDENTIFIER) { - String id = token.value; if (id == "true") value = true; @@ -346,10 +320,8 @@ Error JSON::_parse_value(Variant &value, Token &token, const CharType *p_str, in return ERR_PARSE_ERROR; } } else if (token.type == TK_NUMBER) { - value = token.value; } else if (token.type == TK_STRING) { - value = token.value; } else { r_err_str = "Expected value, got " + String(tk_name[token.type]) + "."; @@ -360,25 +332,20 @@ Error JSON::_parse_value(Variant &value, Token &token, const CharType *p_str, in } Error JSON::_parse_array(Array &array, const CharType *p_str, int &index, int p_len, int &line, String &r_err_str) { - Token token; bool need_comma = false; while (index < p_len) { - Error err = _get_token(p_str, index, p_len, token, line, r_err_str); if (err != OK) return err; if (token.type == TK_BRACKET_CLOSE) { - return OK; } if (need_comma) { - if (token.type != TK_COMMA) { - r_err_str = "Expected ','"; return ERR_PARSE_ERROR; } else { @@ -401,29 +368,23 @@ Error JSON::_parse_array(Array &array, const CharType *p_str, int &index, int p_ } Error JSON::_parse_object(Dictionary &object, const CharType *p_str, int &index, int p_len, int &line, String &r_err_str) { - bool at_key = true; String key; Token token; bool need_comma = false; while (index < p_len) { - if (at_key) { - Error err = _get_token(p_str, index, p_len, token, line, r_err_str); if (err != OK) return err; if (token.type == TK_CURLY_BRACKET_CLOSE) { - return OK; } if (need_comma) { - if (token.type != TK_COMMA) { - r_err_str = "Expected '}' or ','"; return ERR_PARSE_ERROR; } else { @@ -433,7 +394,6 @@ Error JSON::_parse_object(Dictionary &object, const CharType *p_str, int &index, } if (token.type != TK_STRING) { - r_err_str = "Expected key"; return ERR_PARSE_ERROR; } @@ -443,13 +403,11 @@ Error JSON::_parse_object(Dictionary &object, const CharType *p_str, int &index, if (err != OK) return err; if (token.type != TK_COLON) { - r_err_str = "Expected ':'"; return ERR_PARSE_ERROR; } at_key = false; } else { - Error err = _get_token(p_str, index, p_len, token, line, r_err_str); if (err != OK) return err; @@ -469,7 +427,6 @@ Error JSON::_parse_object(Dictionary &object, const CharType *p_str, int &index, } Error JSON::parse(const String &p_json, Variant &r_ret, String &r_err_str, int &r_err_line) { - const CharType *str = p_json.ptr(); int idx = 0; int len = p_json.length(); diff --git a/core/io/json.h b/core/io/json.h index fbff5391894..fbb2c75075d 100644 --- a/core/io/json.h +++ b/core/io/json.h @@ -34,7 +34,6 @@ #include "core/variant.h" class JSON { - enum TokenType { TK_CURLY_BRACKET_OPEN, TK_CURLY_BRACKET_CLOSE, @@ -58,7 +57,6 @@ class JSON { }; struct Token { - TokenType type; Variant value; }; diff --git a/core/io/logger.h b/core/io/logger.h index 750f03e6d09..f63d7cb02b5 100644 --- a/core/io/logger.h +++ b/core/io/logger.h @@ -66,7 +66,6 @@ public: * Writes messages to stdout/stderr. */ class StdLogger : public Logger { - public: virtual void logv(const char *p_format, va_list p_list, bool p_err) _PRINTF_FORMAT_ATTRIBUTE_2_0; virtual ~StdLogger(); diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp index 12a9b91a74f..88caf88e975 100644 --- a/core/io/marshalls.cpp +++ b/core/io/marshalls.cpp @@ -49,7 +49,6 @@ void EncodedObjectAsID::set_object_id(ObjectID p_id) { } ObjectID EncodedObjectAsID::get_object_id() const { - return id; } @@ -101,7 +100,6 @@ static Error _decode_string(const uint8_t *&buf, int &len, int *r_len, String &r } Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int *r_len, bool p_allow_objects) { - const uint8_t *buf = p_buffer; int len = p_len; @@ -117,13 +115,10 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int *r_len = 4; switch (type & ENCODE_MASK) { - case Variant::NIL: { - r_variant = Variant(); } break; case Variant::BOOL: { - ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); bool val = decode_uint32(buf); r_variant = val; @@ -131,7 +126,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int (*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); @@ -149,7 +143,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::REAL: { - if (type & ENCODE_FLAG_64) { ERR_FAIL_COND_V(len < 8, ERR_INVALID_DATA); double val = decode_double(buf); @@ -166,7 +159,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::STRING: { - String str; Error err = _decode_string(buf, len, r_len, str); if (err) @@ -177,7 +169,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int // math types case Variant::VECTOR2: { - ERR_FAIL_COND_V(len < 4 * 2, ERR_INVALID_DATA); Vector2 val; val.x = decode_float(&buf[0]); @@ -189,7 +180,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; // 5 case Variant::RECT2: { - ERR_FAIL_COND_V(len < 4 * 4, ERR_INVALID_DATA); Rect2 val; val.position.x = decode_float(&buf[0]); @@ -203,7 +193,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::VECTOR3: { - ERR_FAIL_COND_V(len < 4 * 3, ERR_INVALID_DATA); Vector3 val; val.x = decode_float(&buf[0]); @@ -216,12 +205,10 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::TRANSFORM2D: { - ERR_FAIL_COND_V(len < 4 * 6, ERR_INVALID_DATA); Transform2D val; for (int i = 0; i < 3; i++) { for (int j = 0; j < 2; j++) { - val.elements[i][j] = decode_float(&buf[(i * 2 + j) * 4]); } } @@ -233,7 +220,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::PLANE: { - ERR_FAIL_COND_V(len < 4 * 4, ERR_INVALID_DATA); Plane val; val.normal.x = decode_float(&buf[0]); @@ -247,7 +233,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::QUAT: { - ERR_FAIL_COND_V(len < 4 * 4, ERR_INVALID_DATA); Quat val; val.x = decode_float(&buf[0]); @@ -261,7 +246,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::AABB: { - ERR_FAIL_COND_V(len < 4 * 6, ERR_INVALID_DATA); AABB val; val.position.x = decode_float(&buf[0]); @@ -277,12 +261,10 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::BASIS: { - ERR_FAIL_COND_V(len < 4 * 9, ERR_INVALID_DATA); Basis val; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - val.elements[i][j] = decode_float(&buf[(i * 3 + j) * 4]); } } @@ -294,12 +276,10 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::TRANSFORM: { - ERR_FAIL_COND_V(len < 4 * 12, ERR_INVALID_DATA); Transform val; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - val.basis.elements[i][j] = decode_float(&buf[(i * 3 + j) * 4]); } } @@ -316,7 +296,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int // misc types case Variant::COLOR: { - ERR_FAIL_COND_V(len < 4 * 4, ERR_INVALID_DATA); Color val; val.r = decode_float(&buf[0]); @@ -330,7 +309,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::NODE_PATH: { - ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); int32_t strlen = decode_uint32(buf); @@ -356,7 +334,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int (*r_len) += 12; for (uint32_t i = 0; i < total; i++) { - String str; Error err = _decode_string(buf, len, r_len, str); if (err) @@ -378,11 +355,9 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::_RID: { - r_variant = RID(); } break; case Variant::OBJECT: { - if (type & ENCODE_FLAG_OBJECT_AS_ID) { //this _is_ allowed ERR_FAIL_COND_V(len < 8, ERR_INVALID_DATA); @@ -411,7 +386,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int if (str == String()) { r_variant = (Object *)NULL; } else { - Object *obj = ClassDB::instance(str); ERR_FAIL_COND_V(!obj, ERR_UNAVAILABLE); @@ -425,7 +399,6 @@ 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) @@ -457,7 +430,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::DICTIONARY: { - ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); int32_t count = decode_uint32(buf); // bool shared = count&0x80000000; @@ -473,7 +445,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int Dictionary d; for (int i = 0; i < count; i++) { - Variant key, value; int used; @@ -502,7 +473,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::ARRAY: { - ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); int32_t count = decode_uint32(buf); // bool shared = count&0x80000000; @@ -518,7 +488,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int Array varr; for (int i = 0; i < count; i++) { - int used = 0; Variant v; Error err = decode_variant(v, buf, len, &used, p_allow_objects); @@ -537,7 +506,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int // arrays case Variant::POOL_BYTE_ARRAY: { - ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); int32_t count = decode_uint32(buf); buf += 4; @@ -550,7 +518,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int data.resize(count); PoolVector::Write w = data.write(); for (int32_t i = 0; i < count; i++) { - w[i] = buf[i]; } } @@ -565,7 +532,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::POOL_INT_ARRAY: { - ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); int32_t count = decode_uint32(buf); buf += 4; @@ -580,7 +546,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int data.resize(count); PoolVector::Write w = data.write(); for (int32_t i = 0; i < count; i++) { - w[i] = decode_uint32(&buf[i * 4]); } } @@ -591,7 +556,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::POOL_REAL_ARRAY: { - ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); int32_t count = decode_uint32(buf); buf += 4; @@ -606,7 +570,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int data.resize(count); PoolVector::Write w = data.write(); for (int32_t i = 0; i < count; i++) { - w[i] = decode_float(&buf[i * 4]); } } @@ -618,7 +581,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::POOL_STRING_ARRAY: { - ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); int32_t count = decode_uint32(buf); @@ -631,7 +593,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int //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) @@ -644,7 +605,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::POOL_VECTOR2_ARRAY: { - ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); int32_t count = decode_uint32(buf); buf += 4; @@ -663,7 +623,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int PoolVector::Write w = varray.write(); for (int32_t i = 0; i < count; i++) { - w[i].x = decode_float(buf + i * 4 * 2 + 4 * 0); w[i].y = decode_float(buf + i * 4 * 2 + 4 * 1); } @@ -678,7 +637,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::POOL_VECTOR3_ARRAY: { - ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); int32_t count = decode_uint32(buf); buf += 4; @@ -698,7 +656,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int PoolVector::Write w = varray.write(); for (int32_t i = 0; i < count; i++) { - w[i].x = decode_float(buf + i * 4 * 3 + 4 * 0); w[i].y = decode_float(buf + i * 4 * 3 + 4 * 1); w[i].z = decode_float(buf + i * 4 * 3 + 4 * 2); @@ -714,7 +671,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } break; case Variant::POOL_COLOR_ARRAY: { - ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA); int32_t count = decode_uint32(buf); buf += 4; @@ -734,7 +690,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int PoolVector::Write w = carray.write(); for (int32_t i = 0; i < count; i++) { - w[i].r = decode_float(buf + i * 4 * 4 + 4 * 0); w[i].g = decode_float(buf + i * 4 * 4 + 4 * 1); w[i].b = decode_float(buf + i * 4 * 4 + 4 * 2); @@ -759,7 +714,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int } static void _encode_string(const String &p_string, uint8_t *&buf, int &r_len) { - CharString utf8 = p_string.utf8(); if (buf) { @@ -779,7 +733,6 @@ static void _encode_string(const String &p_string, uint8_t *&buf, int &r_len) { } Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bool p_full_objects) { - uint8_t *buf = r_buffer; r_len = 0; @@ -787,7 +740,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo uint32_t flags = 0; switch (p_variant.get_type()) { - case Variant::INT: { int64_t val = p_variant; if (val > (int64_t)INT_MAX || val < (int64_t)INT_MIN) { @@ -795,7 +747,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } } break; case Variant::REAL: { - double d = p_variant; float f = d; if (double(f) != d) { @@ -830,13 +781,10 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo r_len += 4; switch (p_variant.get_type()) { - case Variant::NIL: { - //nothing to do } break; case Variant::BOOL: { - if (buf) { encode_uint32(p_variant.operator bool(), buf); } @@ -845,7 +793,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::INT: { - if (flags & ENCODE_FLAG_64) { //64 bits if (buf) { @@ -862,7 +809,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } } break; case Variant::REAL: { - if (flags & ENCODE_FLAG_64) { if (buf) { encode_double(p_variant.operator double(), buf); @@ -871,7 +817,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo r_len += 8; } else { - if (buf) { encode_float(p_variant.operator float(), buf); } @@ -881,7 +826,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::NODE_PATH: { - NodePath np = p_variant; if (buf) { encode_uint32(uint32_t(np.get_name_count()) | 0x80000000, buf); //for compatibility with the old format @@ -900,7 +844,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo int total = np.get_name_count() + np.get_subname_count(); for (int i = 0; i < total; i++) { - String str; if (i < np.get_name_count()) @@ -927,14 +870,12 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::STRING: { - _encode_string(p_variant, buf, r_len); } break; // math types case Variant::VECTOR2: { - if (buf) { Vector2 v2 = p_variant; encode_float(v2.x, &buf[0]); @@ -945,7 +886,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; // 5 case Variant::RECT2: { - if (buf) { Rect2 r2 = p_variant; encode_float(r2.position.x, &buf[0]); @@ -957,7 +897,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::VECTOR3: { - if (buf) { Vector3 v3 = p_variant; encode_float(v3.x, &buf[0]); @@ -969,12 +908,10 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::TRANSFORM2D: { - if (buf) { Transform2D val = p_variant; for (int i = 0; i < 3; i++) { for (int j = 0; j < 2; j++) { - memcpy(&buf[(i * 2 + j) * 4], &val.elements[i][j], sizeof(float)); } } @@ -984,7 +921,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::PLANE: { - if (buf) { Plane p = p_variant; encode_float(p.normal.x, &buf[0]); @@ -997,7 +933,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::QUAT: { - if (buf) { Quat q = p_variant; encode_float(q.x, &buf[0]); @@ -1010,7 +945,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::AABB: { - if (buf) { AABB aabb = p_variant; encode_float(aabb.position.x, &buf[0]); @@ -1025,12 +959,10 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::BASIS: { - if (buf) { Basis val = p_variant; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - memcpy(&buf[(i * 3 + j) * 4], &val.elements[i][j], sizeof(float)); } } @@ -1040,12 +972,10 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::TRANSFORM: { - if (buf) { Transform val = p_variant; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - memcpy(&buf[(i * 3 + j) * 4], &val.basis.elements[i][j], sizeof(float)); } } @@ -1061,7 +991,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo // misc types case Variant::COLOR: { - if (buf) { Color c = p_variant; encode_float(c.r, &buf[0]); @@ -1074,12 +1003,9 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::_RID: { - } break; case Variant::OBJECT: { - if (p_full_objects) { - Object *obj = p_variant; if (!obj) { if (buf) { @@ -1095,7 +1021,6 @@ 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)) continue; pc++; @@ -1109,7 +1034,6 @@ 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)) continue; @@ -1127,7 +1051,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } } else { if (buf) { - Object *obj = p_variant; ObjectID id = 0; if (obj && ObjectDB::instance_validate(obj)) { @@ -1142,7 +1065,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::DICTIONARY: { - Dictionary d = p_variant; if (buf) { @@ -1155,7 +1077,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo d.get_key_list(&keys); for (List::Element *E = keys.front(); E; E = E->next()) { - /* CharString utf8 = E->->utf8(); @@ -1185,7 +1106,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::ARRAY: { - Array v = p_variant; if (buf) { @@ -1196,7 +1116,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo r_len += 4; for (int i = 0; i < v.size(); i++) { - int len; encode_variant(v.get(i), buf, len, p_full_objects); ERR_FAIL_COND_V(len % 4, ERR_BUG); @@ -1208,7 +1127,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; // arrays case Variant::POOL_BYTE_ARRAY: { - PoolVector data = p_variant; int datalen = data.size(); int datasize = sizeof(uint8_t); @@ -1230,7 +1148,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::POOL_INT_ARRAY: { - PoolVector data = p_variant; int datalen = data.size(); int datasize = sizeof(int32_t); @@ -1247,7 +1164,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::POOL_REAL_ARRAY: { - PoolVector data = p_variant; int datalen = data.size(); int datasize = sizeof(real_t); @@ -1264,7 +1180,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::POOL_STRING_ARRAY: { - PoolVector data = p_variant; int len = data.size(); @@ -1276,7 +1191,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo r_len += 4; for (int i = 0; i < len; i++) { - CharString utf8 = data.get(i).utf8(); if (buf) { @@ -1296,7 +1210,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::POOL_VECTOR2_ARRAY: { - PoolVector data = p_variant; int len = data.size(); @@ -1308,9 +1221,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo r_len += 4; if (buf) { - for (int i = 0; i < len; i++) { - Vector2 v = data.get(i); encode_float(v.x, &buf[0]); @@ -1323,7 +1234,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::POOL_VECTOR3_ARRAY: { - PoolVector data = p_variant; int len = data.size(); @@ -1335,9 +1245,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo r_len += 4; if (buf) { - for (int i = 0; i < len; i++) { - Vector3 v = data.get(i); encode_float(v.x, &buf[0]); @@ -1351,7 +1259,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } break; case Variant::POOL_COLOR_ARRAY: { - PoolVector data = p_variant; int len = data.size(); @@ -1363,9 +1270,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo r_len += 4; if (buf) { - for (int i = 0; i < len; i++) { - Color c = data.get(i); encode_float(c.r, &buf[0]); diff --git a/core/io/marshalls.h b/core/io/marshalls.h index 01f6f77fcfb..c9f55173148 100644 --- a/core/io/marshalls.h +++ b/core/io/marshalls.h @@ -41,21 +41,17 @@ */ union MarshallFloat { - uint32_t i; ///< int float f; ///< float }; union MarshallDouble { - uint64_t l; ///< long long double d; ///< double }; static inline unsigned int encode_uint16(uint16_t p_uint, uint8_t *p_arr) { - for (int i = 0; i < 2; i++) { - *p_arr = p_uint & 0xFF; p_arr++; p_uint >>= 8; @@ -65,9 +61,7 @@ static inline unsigned int encode_uint16(uint16_t p_uint, uint8_t *p_arr) { } static inline unsigned int encode_uint32(uint32_t p_uint, uint8_t *p_arr) { - for (int i = 0; i < 4; i++) { - *p_arr = p_uint & 0xFF; p_arr++; p_uint >>= 8; @@ -77,7 +71,6 @@ static inline unsigned int encode_uint32(uint32_t p_uint, uint8_t *p_arr) { } static inline unsigned int encode_float(float p_float, uint8_t *p_arr) { - MarshallFloat mf; mf.f = p_float; encode_uint32(mf.i, p_arr); @@ -86,9 +79,7 @@ static inline unsigned int encode_float(float p_float, uint8_t *p_arr) { } static inline unsigned int encode_uint64(uint64_t p_uint, uint8_t *p_arr) { - for (int i = 0; i < 8; i++) { - *p_arr = p_uint & 0xFF; p_arr++; p_uint >>= 8; @@ -98,7 +89,6 @@ static inline unsigned int encode_uint64(uint64_t p_uint, uint8_t *p_arr) { } static inline unsigned int encode_double(double p_double, uint8_t *p_arr) { - MarshallDouble md; md.d = p_double; encode_uint64(md.l, p_arr); @@ -107,13 +97,10 @@ static inline unsigned int encode_double(double p_double, uint8_t *p_arr) { } static inline int encode_cstring(const char *p_string, uint8_t *p_data) { - int len = 0; while (*p_string) { - if (p_data) { - *p_data = (uint8_t)*p_string; p_data++; } @@ -127,11 +114,9 @@ static inline int encode_cstring(const char *p_string, uint8_t *p_data) { } static inline uint16_t decode_uint16(const uint8_t *p_arr) { - uint16_t u = 0; for (int i = 0; i < 2; i++) { - uint16_t b = *p_arr; b <<= (i * 8); u |= b; @@ -142,11 +127,9 @@ static inline uint16_t decode_uint16(const uint8_t *p_arr) { } static inline uint32_t decode_uint32(const uint8_t *p_arr) { - uint32_t u = 0; for (int i = 0; i < 4; i++) { - uint32_t b = *p_arr; b <<= (i * 8); u |= b; @@ -157,18 +140,15 @@ static inline uint32_t decode_uint32(const uint8_t *p_arr) { } static inline float decode_float(const uint8_t *p_arr) { - MarshallFloat mf; mf.i = decode_uint32(p_arr); return mf.f; } static inline uint64_t decode_uint64(const uint8_t *p_arr) { - uint64_t u = 0; for (int i = 0; i < 8; i++) { - uint64_t b = (*p_arr) & 0xFF; b <<= (i * 8); u |= b; @@ -179,7 +159,6 @@ static inline uint64_t decode_uint64(const uint8_t *p_arr) { } static inline double decode_double(const uint8_t *p_arr) { - MarshallDouble md; md.l = decode_uint64(p_arr); return md.d; diff --git a/core/io/multiplayer_api.cpp b/core/io/multiplayer_api.cpp index 8db2f5c7796..0aee165a70e 100644 --- a/core/io/multiplayer_api.cpp +++ b/core/io/multiplayer_api.cpp @@ -38,9 +38,7 @@ #endif _FORCE_INLINE_ bool _should_call_local(MultiplayerAPI::RPCMode mode, bool is_master, bool &r_skip_rpc) { - switch (mode) { - case MultiplayerAPI::RPC_MODE_DISABLED: { // Do nothing. } break; @@ -71,7 +69,6 @@ _FORCE_INLINE_ bool _should_call_local(MultiplayerAPI::RPCMode mode, bool is_mas _FORCE_INLINE_ bool _can_call_mode(Node *p_node, MultiplayerAPI::RPCMode mode, int p_remote_id) { switch (mode) { - case MultiplayerAPI::RPC_MODE_DISABLED: { return false; } break; @@ -93,7 +90,6 @@ _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) return; @@ -103,7 +99,6 @@ void MultiplayerAPI::poll() { return; while (network_peer->get_available_packet_count()) { - int sender = network_peer->get_packet_peer(); const uint8_t *packet; int len; @@ -141,7 +136,6 @@ Node *MultiplayerAPI::get_root_node() { } void MultiplayerAPI::set_network_peer(const Ref &p_peer) { - if (p_peer == network_peer) return; // Nothing to do @@ -173,7 +167,6 @@ Ref MultiplayerAPI::get_network_peer() const { } void MultiplayerAPI::_process_packet(int p_from, const uint8_t *p_packet, int p_packet_len) { - ERR_FAIL_COND_MSG(root_node == NULL, "Multiplayer root node was not initialized. If you are using custom multiplayer, remember to set the root node via MultiplayerAPI.set_root_node before using it."); ERR_FAIL_COND_MSG(p_packet_len < 1, "Invalid packet received. Size too small."); @@ -188,20 +181,16 @@ void MultiplayerAPI::_process_packet(int p_from, const uint8_t *p_packet, int p_ uint8_t packet_type = p_packet[0]; switch (packet_type) { - case NETWORK_COMMAND_SIMPLIFY_PATH: { - _process_simplify_path(p_from, p_packet, p_packet_len); } break; case NETWORK_COMMAND_CONFIRM_PATH: { - _process_confirm_path(p_from, p_packet, p_packet_len); } break; case NETWORK_COMMAND_REMOTE_CALL: case NETWORK_COMMAND_REMOTE_SET: { - ERR_FAIL_COND_MSG(p_packet_len < 6, "Invalid packet received. Size too small."); Node *node = _process_get_node(p_from, p_packet, p_packet_len); @@ -221,25 +210,21 @@ void MultiplayerAPI::_process_packet(int p_from, const uint8_t *p_packet, int p_ StringName name = String::utf8((const char *)&p_packet[5]); if (packet_type == NETWORK_COMMAND_REMOTE_CALL) { - _process_rpc(node, name, p_from, p_packet, p_packet_len, len_end + 1); } else { - _process_rset(node, name, p_from, p_packet, p_packet_len, len_end + 1); } } break; case NETWORK_COMMAND_RAW: { - _process_raw(p_from, p_packet, p_packet_len); } break; } } Node *MultiplayerAPI::_process_get_node(int p_from, const uint8_t *p_packet, int p_packet_len) { - uint32_t target = decode_uint32(&p_packet[1]); Node *node = NULL; @@ -280,7 +265,6 @@ Node *MultiplayerAPI::_process_get_node(int p_from, const uint8_t *p_packet, int } void MultiplayerAPI::_process_rpc(Node *p_node, const StringName &p_name, int p_from, const uint8_t *p_packet, int p_packet_len, int p_offset) { - ERR_FAIL_COND_MSG(p_offset >= p_packet_len, "Invalid packet received. Size too small."); // Check that remote can call the RPC on this node. @@ -312,7 +296,6 @@ void MultiplayerAPI::_process_rpc(Node *p_node, const StringName &p_name, int p_ #endif for (int i = 0; i < argc; i++) { - ERR_FAIL_COND_MSG(p_offset >= p_packet_len, "Invalid packet received. Size too small."); int vlen; @@ -334,7 +317,6 @@ void MultiplayerAPI::_process_rpc(Node *p_node, const StringName &p_name, int p_ } void MultiplayerAPI::_process_rset(Node *p_node, const StringName &p_name, int p_from, const uint8_t *p_packet, int p_packet_len, int p_offset) { - ERR_FAIL_COND_MSG(p_offset >= p_packet_len, "Invalid packet received. Size too small."); // Check that remote can call the RSET on this node. @@ -372,7 +354,6 @@ void MultiplayerAPI::_process_rset(Node *p_node, const StringName &p_name, int p } void MultiplayerAPI::_process_simplify_path(int p_from, const uint8_t *p_packet, int p_packet_len) { - ERR_FAIL_COND_MSG(p_packet_len < 5, "Invalid packet received. Size too small."); int id = decode_uint32(&p_packet[1]); @@ -407,7 +388,6 @@ void MultiplayerAPI::_process_simplify_path(int p_from, const uint8_t *p_packet, } void MultiplayerAPI::_process_confirm_path(int p_from, const uint8_t *p_packet, int p_packet_len) { - ERR_FAIL_COND_MSG(p_packet_len < 2, "Invalid packet received. Size too small."); String paths; @@ -428,7 +408,6 @@ bool MultiplayerAPI::_send_confirm_path(NodePath p_path, PathSentCache *psc, int 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) continue; // Continue, excluded. @@ -451,7 +430,6 @@ bool MultiplayerAPI::_send_confirm_path(NodePath p_path, PathSentCache *psc, int // Those that need to be added, send a message for this. for (List::Element *E = peers_to_add.front(); E; E = E->next()) { - // Encode function name. CharString pname = String(p_path).utf8(); int len = encode_cstring(pname.get_data(), NULL); @@ -474,7 +452,6 @@ bool MultiplayerAPI::_send_confirm_path(NodePath p_path, PathSentCache *psc, int } void MultiplayerAPI::_send_rpc(Node *p_from, int p_to, bool p_unreliable, bool p_set, const StringName &p_name, const Variant **p_arg, int p_argcount) { - ERR_FAIL_COND_MSG(network_peer.is_null(), "Attempt to remote call/set when networking is not active in SceneTree."); ERR_FAIL_COND_MSG(network_peer->get_connection_status() == NetworkedMultiplayerPeer::CONNECTION_CONNECTING, "Attempt to remote call/set when networking is not connected yet in SceneTree."); @@ -563,7 +540,6 @@ void MultiplayerAPI::_send_rpc(Node *p_from, int p_to, bool p_unreliable, bool p network_peer->set_transfer_mode(p_unreliable ? NetworkedMultiplayerPeer::TRANSFER_MODE_UNRELIABLE : NetworkedMultiplayerPeer::TRANSFER_MODE_RELIABLE); if (has_all_peers) { - // They all have verified paths, so send fast. network_peer->set_target_peer(p_to); // To all of you. network_peer->put_packet(packet_cache.ptr(), ofs); // A message with love. @@ -577,7 +553,6 @@ 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) continue; // Continue, excluded. @@ -624,22 +599,18 @@ void MultiplayerAPI::_del_peer(int p_id) { } void MultiplayerAPI::_connected_to_server() { - emit_signal("connected_to_server"); } void MultiplayerAPI::_connection_failed() { - emit_signal("connection_failed"); } void MultiplayerAPI::_server_disconnected() { - emit_signal("server_disconnected"); } void MultiplayerAPI::rpcp(Node *p_node, int p_peer_id, bool p_unreliable, const StringName &p_method, const Variant **p_arg, int p_argcount) { - ERR_FAIL_COND_MSG(!network_peer.is_valid(), "Trying to call an RPC while no network peer is active."); ERR_FAIL_COND_MSG(!p_node->is_inside_tree(), "Trying to call an RPC on a node which is not inside SceneTree."); ERR_FAIL_COND_MSG(network_peer->get_connection_status() != NetworkedMultiplayerPeer::CONNECTION_CONNECTED, "Trying to call an RPC via a network peer which is not connected."); @@ -668,7 +639,6 @@ void MultiplayerAPI::rpcp(Node *p_node, int p_peer_id, bool p_unreliable, const } if (!skip_rpc) { - #ifdef DEBUG_ENABLED if (profiling) { ObjectID id = p_node->get_instance_id(); @@ -713,7 +683,6 @@ void MultiplayerAPI::rpcp(Node *p_node, int p_peer_id, bool p_unreliable, const } void MultiplayerAPI::rsetp(Node *p_node, int p_peer_id, bool p_unreliable, const StringName &p_property, const Variant &p_value) { - ERR_FAIL_COND_MSG(!network_peer.is_valid(), "Trying to RSET while no network peer is active."); ERR_FAIL_COND_MSG(!p_node->is_inside_tree(), "Trying to RSET on a node which is not inside SceneTree."); ERR_FAIL_COND_MSG(network_peer->get_connection_status() != NetworkedMultiplayerPeer::CONNECTION_CONNECTED, "Trying to send an RSET via a network peer which is not connected."); @@ -727,7 +696,6 @@ void MultiplayerAPI::rsetp(Node *p_node, int p_peer_id, bool p_unreliable, const // Check that send mode can use local call. const Map::Element *E = p_node->get_node_rset_mode(p_property); if (E) { - set_local = _should_call_local(E->get(), is_master, skip_rset); } @@ -785,7 +753,6 @@ void MultiplayerAPI::rsetp(Node *p_node, int p_peer_id, bool p_unreliable, const } Error MultiplayerAPI::send_bytes(PoolVector p_data, int p_to, NetworkedMultiplayerPeer::TransferMode p_mode) { - ERR_FAIL_COND_V_MSG(p_data.size() < 1, ERR_INVALID_DATA, "Trying to send an empty raw packet."); ERR_FAIL_COND_V_MSG(!network_peer.is_valid(), ERR_UNCONFIGURED, "Trying to send a raw packet while no network peer is active."); ERR_FAIL_COND_V_MSG(network_peer->get_connection_status() != NetworkedMultiplayerPeer::CONNECTION_CONNECTED, ERR_UNCONFIGURED, "Trying to send a raw packet via a network peer which is not connected."); @@ -802,7 +769,6 @@ Error MultiplayerAPI::send_bytes(PoolVector p_data, int p_to, Networked } void MultiplayerAPI::_process_raw(int p_from, const uint8_t *p_packet, int p_packet_len) { - ERR_FAIL_COND_MSG(p_packet_len < 2, "Invalid packet received. Size too small."); PoolVector out; @@ -816,32 +782,27 @@ void MultiplayerAPI::_process_raw(int p_from, const uint8_t *p_packet, int p_pac } int MultiplayerAPI::get_network_unique_id() const { - ERR_FAIL_COND_V_MSG(!network_peer.is_valid(), 0, "No network peer is assigned. Unable to get unique network ID."); return network_peer->get_unique_id(); } bool MultiplayerAPI::is_network_server() const { - // XXX Maybe fail silently? Maybe should actually return true to make development of both local and online multiplayer easier? ERR_FAIL_COND_V_MSG(!network_peer.is_valid(), false, "No network peer is assigned. I can't be a server."); return network_peer->is_server(); } void MultiplayerAPI::set_refuse_new_network_connections(bool p_refuse) { - ERR_FAIL_COND_MSG(!network_peer.is_valid(), "No network peer is assigned. Unable to set 'refuse_new_connections'."); network_peer->set_refuse_new_connections(p_refuse); } bool MultiplayerAPI::is_refusing_new_network_connections() const { - ERR_FAIL_COND_V_MSG(!network_peer.is_valid(), false, "No network peer is assigned. Unable to get 'refuse_new_connections'."); return network_peer->is_refusing_new_connections(); } Vector MultiplayerAPI::get_network_connected_peers() const { - ERR_FAIL_COND_V_MSG(!network_peer.is_valid(), Vector(), "No network peer is assigned. Assume no peers are connected."); Vector ret; @@ -853,12 +814,10 @@ Vector MultiplayerAPI::get_network_connected_peers() const { } void MultiplayerAPI::set_allow_object_decoding(bool p_enable) { - allow_object_decoding = p_enable; } bool MultiplayerAPI::is_object_decoding_allowed() const { - return allow_object_decoding; } diff --git a/core/io/multiplayer_api.h b/core/io/multiplayer_api.h index 69fc797cc87..1abd64d634f 100644 --- a/core/io/multiplayer_api.h +++ b/core/io/multiplayer_api.h @@ -35,7 +35,6 @@ #include "core/reference.h" class MultiplayerAPI : public Reference { - GDCLASS(MultiplayerAPI, Reference); public: diff --git a/core/io/net_socket.cpp b/core/io/net_socket.cpp index a406a6c1096..6ffd9b48598 100644 --- a/core/io/net_socket.cpp +++ b/core/io/net_socket.cpp @@ -33,7 +33,6 @@ NetSocket *(*NetSocket::_create)() = NULL; NetSocket *NetSocket::create() { - if (_create) return _create(); diff --git a/core/io/net_socket.h b/core/io/net_socket.h index de429ec4365..72a6038ab24 100644 --- a/core/io/net_socket.h +++ b/core/io/net_socket.h @@ -35,7 +35,6 @@ #include "core/reference.h" class NetSocket : public Reference { - protected: static NetSocket *(*_create)(); diff --git a/core/io/networked_multiplayer_peer.cpp b/core/io/networked_multiplayer_peer.cpp index c0afdd30063..98fdbfdfce7 100644 --- a/core/io/networked_multiplayer_peer.cpp +++ b/core/io/networked_multiplayer_peer.cpp @@ -31,7 +31,6 @@ #include "networked_multiplayer_peer.h" void NetworkedMultiplayerPeer::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_transfer_mode", "mode"), &NetworkedMultiplayerPeer::set_transfer_mode); ClassDB::bind_method(D_METHOD("get_transfer_mode"), &NetworkedMultiplayerPeer::get_transfer_mode); ClassDB::bind_method(D_METHOD("set_target_peer", "id"), &NetworkedMultiplayerPeer::set_target_peer); diff --git a/core/io/networked_multiplayer_peer.h b/core/io/networked_multiplayer_peer.h index 02b125177c7..ed48bdcc677 100644 --- a/core/io/networked_multiplayer_peer.h +++ b/core/io/networked_multiplayer_peer.h @@ -34,7 +34,6 @@ #include "core/io/packet_peer.h" class NetworkedMultiplayerPeer : public PacketPeer { - GDCLASS(NetworkedMultiplayerPeer, PacketPeer); protected: diff --git a/core/io/packet_peer.cpp b/core/io/packet_peer.cpp index 9e5827f50c6..ac2071c0d6d 100644 --- a/core/io/packet_peer.cpp +++ b/core/io/packet_peer.cpp @@ -42,17 +42,14 @@ PacketPeer::PacketPeer() : } void PacketPeer::set_allow_object_decoding(bool p_enable) { - allow_object_decoding = p_enable; } bool PacketPeer::is_object_decoding_allowed() const { - return allow_object_decoding; } void PacketPeer::set_encode_buffer_max_size(int p_max_size) { - ERR_FAIL_COND_MSG(p_max_size < 1024, "Max encode buffer must be at least 1024 bytes"); ERR_FAIL_COND_MSG(p_max_size > 256 * 1024 * 1024, "Max encode buffer cannot exceed 256 MiB"); encode_buffer_max_size = next_power_of_2(p_max_size); @@ -60,12 +57,10 @@ void PacketPeer::set_encode_buffer_max_size(int p_max_size) { } int PacketPeer::get_encode_buffer_max_size() const { - return encode_buffer_max_size; } Error PacketPeer::get_packet_buffer(PoolVector &r_buffer) { - const uint8_t *buffer; int buffer_size; Error err = get_packet(&buffer, buffer_size); @@ -84,7 +79,6 @@ Error PacketPeer::get_packet_buffer(PoolVector &r_buffer) { } Error PacketPeer::put_packet_buffer(const PoolVector &p_buffer) { - int len = p_buffer.size(); if (len == 0) return OK; @@ -94,7 +88,6 @@ Error PacketPeer::put_packet_buffer(const PoolVector &p_buffer) { } 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); @@ -105,7 +98,6 @@ 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, NULL, len, p_full_objects || allow_object_decoding); // compute len first if (err) @@ -140,19 +132,16 @@ Error PacketPeer::_put_packet(const PoolVector &p_buffer) { return put_packet_buffer(p_buffer); } PoolVector PacketPeer::_get_packet() { - PoolVector raw; last_get_error = get_packet_buffer(raw); return raw; } Error PacketPeer::_get_packet_error() const { - return last_get_error; } void PacketPeer::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_var", "allow_objects"), &PacketPeer::_bnd_get_var, DEFVAL(false)); ClassDB::bind_method(D_METHOD("put_var", "var", "full_objects"), &PacketPeer::put_var, DEFVAL(false)); ClassDB::bind_method(D_METHOD("get_packet"), &PacketPeer::_get_packet); @@ -172,13 +161,11 @@ void PacketPeer::_bind_methods() { /***************/ void PacketPeerStream::_set_stream_peer(REF p_peer) { - ERR_FAIL_COND_MSG(p_peer.is_null(), "It's not a reference to a valid Resource object."); set_stream_peer(p_peer); } void PacketPeerStream::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_stream_peer", "peer"), &PacketPeerStream::set_stream_peer); ClassDB::bind_method(D_METHOD("get_stream_peer"), &PacketPeerStream::get_stream_peer); ClassDB::bind_method(D_METHOD("set_input_buffer_max_size", "max_size_bytes"), &PacketPeerStream::set_input_buffer_max_size); @@ -192,7 +179,6 @@ void PacketPeerStream::_bind_methods() { } Error PacketPeerStream::_poll_buffer() const { - ERR_FAIL_COND_V(peer.is_null(), ERR_UNCONFIGURED); int read = 0; @@ -210,7 +196,6 @@ Error PacketPeerStream::_poll_buffer() const { } int PacketPeerStream::get_available_packet_count() const { - _poll_buffer(); uint32_t remaining = ring_buffer.data_left(); @@ -219,7 +204,6 @@ int PacketPeerStream::get_available_packet_count() const { int count = 0; while (remaining >= 4) { - uint8_t lbuf[4]; ring_buffer.copy(lbuf, ofs, 4); uint32_t len = decode_uint32(lbuf); @@ -236,7 +220,6 @@ int PacketPeerStream::get_available_packet_count() const { } Error PacketPeerStream::get_packet(const uint8_t **r_buffer, int &r_buffer_size) { - ERR_FAIL_COND_V(peer.is_null(), ERR_UNCONFIGURED); _poll_buffer(); @@ -258,7 +241,6 @@ Error PacketPeerStream::get_packet(const uint8_t **r_buffer, int &r_buffer_size) } 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 @@ -280,12 +262,10 @@ Error PacketPeerStream::put_packet(const uint8_t *p_buffer, int p_buffer_size) { } int PacketPeerStream::get_max_packet_size() const { - return output_buffer.size(); } void PacketPeerStream::set_stream_peer(const Ref &p_peer) { - //ERR_FAIL_COND(p_peer.is_null()); if (p_peer.ptr() != peer.ptr()) { @@ -296,12 +276,10 @@ void PacketPeerStream::set_stream_peer(const Ref &p_peer) { } Ref PacketPeerStream::get_stream_peer() const { - return peer; } void PacketPeerStream::set_input_buffer_max_size(int p_max_size) { - ERR_FAIL_COND_MSG(p_max_size < 0, "Max size of input buffer size cannot be smaller than 0."); //warning may lose packets ERR_FAIL_COND_MSG(ring_buffer.data_left(), "Buffer in use, resizing would cause loss of data."); @@ -310,22 +288,18 @@ void PacketPeerStream::set_input_buffer_max_size(int p_max_size) { } int PacketPeerStream::get_input_buffer_max_size() const { - return input_buffer.size() - 4; } void PacketPeerStream::set_output_buffer_max_size(int p_max_size) { - output_buffer.resize(next_power_of_2(p_max_size + 4)); } int PacketPeerStream::get_output_buffer_max_size() const { - return output_buffer.size() - 4; } PacketPeerStream::PacketPeerStream() { - int rbsize = GLOBAL_GET("network/limits/packet_peer_stream/max_buffer_po2"); ring_buffer.resize(rbsize); diff --git a/core/io/packet_peer.h b/core/io/packet_peer.h index d5d59269034..7e2624e0519 100644 --- a/core/io/packet_peer.h +++ b/core/io/packet_peer.h @@ -36,7 +36,6 @@ #include "core/ring_buffer.h" class PacketPeer : public Reference { - GDCLASS(PacketPeer, Reference); Variant _bnd_get_var(bool p_allow_objects = false); @@ -80,7 +79,6 @@ public: }; class PacketPeerStream : public PacketPeer { - GDCLASS(PacketPeerStream, PacketPeer); //the way the buffers work sucks, will change later diff --git a/core/io/packet_peer_dtls.cpp b/core/io/packet_peer_dtls.cpp index b243b4538d8..acc2342cc59 100644 --- a/core/io/packet_peer_dtls.cpp +++ b/core/io/packet_peer_dtls.cpp @@ -36,7 +36,6 @@ PacketPeerDTLS *(*PacketPeerDTLS::_create)() = NULL; bool PacketPeerDTLS::available = false; PacketPeerDTLS *PacketPeerDTLS::create() { - if (_create) { return _create(); } @@ -48,7 +47,6 @@ bool PacketPeerDTLS::is_available() { } void PacketPeerDTLS::_bind_methods() { - ClassDB::bind_method(D_METHOD("poll"), &PacketPeerDTLS::poll); ClassDB::bind_method(D_METHOD("connect_to_peer", "packet_peer", "validate_certs", "for_hostname", "valid_certificate"), &PacketPeerDTLS::connect_to_peer, DEFVAL(true), DEFVAL(String()), DEFVAL(Ref())); ClassDB::bind_method(D_METHOD("get_status"), &PacketPeerDTLS::get_status); diff --git a/core/io/packet_peer_udp.cpp b/core/io/packet_peer_udp.cpp index dd20184a3b9..ebe8a267e3b 100644 --- a/core/io/packet_peer_udp.cpp +++ b/core/io/packet_peer_udp.cpp @@ -34,7 +34,6 @@ #include "core/io/udp_server.h" void PacketPeerUDP::set_blocking_mode(bool p_enable) { - blocking = p_enable; } @@ -68,12 +67,10 @@ Error PacketPeerUDP::leave_multicast_group(IP_Address p_multi_address, String p_ } String PacketPeerUDP::_get_packet_ip() const { - return get_packet_address(); } Error PacketPeerUDP::_set_dest_address(const String &p_address, int p_port) { - IP_Address ip; if (p_address.is_valid_ip_address()) { ip = p_address; @@ -88,7 +85,6 @@ 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) @@ -98,7 +94,6 @@ int PacketPeerUDP::get_available_packet_count() const { } Error PacketPeerUDP::get_packet(const uint8_t **r_buffer, int &r_buffer_size) { - Error err = _poll(); if (err != OK) return err; @@ -119,7 +114,6 @@ Error PacketPeerUDP::get_packet(const uint8_t **r_buffer, int &r_buffer_size) { } Error PacketPeerUDP::put_packet(const uint8_t *p_buffer, int p_buffer_size) { - ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE); ERR_FAIL_COND_V(!peer_addr.is_valid(), ERR_UNCONFIGURED); @@ -156,12 +150,10 @@ Error PacketPeerUDP::put_packet(const uint8_t *p_buffer, int p_buffer_size) { } int PacketPeerUDP::get_max_packet_size() const { - return 512; // uhm maybe not } Error PacketPeerUDP::listen(int p_port, const IP_Address &p_bind_address, int p_recv_buffer_size) { - ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE); ERR_FAIL_COND_V(_sock->is_open(), ERR_ALREADY_IN_USE); ERR_FAIL_COND_V(!p_bind_address.is_valid() && !p_bind_address.is_wildcard(), ERR_INVALID_PARAMETER); @@ -258,13 +250,11 @@ void PacketPeerUDP::close() { } Error PacketPeerUDP::wait() { - ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE); return _sock->poll(NetSocket::POLL_TYPE_IN, -1); } Error PacketPeerUDP::_poll() { - ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE); if (!_sock->is_open()) { @@ -318,29 +308,24 @@ Error PacketPeerUDP::store_packet(IP_Address p_ip, uint32_t p_port, uint8_t *p_b } bool PacketPeerUDP::is_listening() const { - return _sock.is_valid() && _sock->is_open(); } IP_Address PacketPeerUDP::get_packet_address() const { - return packet_ip; } int PacketPeerUDP::get_packet_port() const { - return packet_port; } void PacketPeerUDP::set_dest_address(const IP_Address &p_address, int p_port) { - ERR_FAIL_COND_MSG(connected, "Destination address cannot be set for connected sockets"); peer_addr = p_address; peer_port = p_port; } void PacketPeerUDP::_bind_methods() { - ClassDB::bind_method(D_METHOD("listen", "port", "bind_address", "recv_buf_size"), &PacketPeerUDP::listen, DEFVAL("*"), DEFVAL(65536)); ClassDB::bind_method(D_METHOD("close"), &PacketPeerUDP::close); ClassDB::bind_method(D_METHOD("wait"), &PacketPeerUDP::wait); @@ -368,6 +353,5 @@ PacketPeerUDP::PacketPeerUDP() : } PacketPeerUDP::~PacketPeerUDP() { - close(); } diff --git a/core/io/pck_packer.cpp b/core/io/pck_packer.cpp index 45e29ca3544..fb669bc0692 100644 --- a/core/io/pck_packer.cpp +++ b/core/io/pck_packer.cpp @@ -35,7 +35,6 @@ #include "core/version.h" static uint64_t _align(uint64_t p_n, int p_alignment) { - if (p_alignment == 0) return p_n; @@ -47,22 +46,18 @@ static uint64_t _align(uint64_t p_n, int p_alignment) { }; static void _pad(FileAccess *p_file, int p_bytes) { - for (int i = 0; i < p_bytes; i++) { - p_file->store_8(0); }; }; void PCKPacker::_bind_methods() { - ClassDB::bind_method(D_METHOD("pck_start", "pck_name", "alignment"), &PCKPacker::pck_start, DEFVAL(0)); ClassDB::bind_method(D_METHOD("add_file", "pck_path", "source_path"), &PCKPacker::add_file); ClassDB::bind_method(D_METHOD("flush", "verbose"), &PCKPacker::flush, DEFVAL(false)); }; Error PCKPacker::pck_start(const String &p_file, int p_alignment) { - if (file != NULL) { memdelete(file); } @@ -80,7 +75,6 @@ Error PCKPacker::pck_start(const String &p_file, int p_alignment) { file->store_32(VERSION_PATCH); for (int i = 0; i < 16; i++) { - file->store_32(0); // reserved }; @@ -90,7 +84,6 @@ Error PCKPacker::pck_start(const String &p_file, int p_alignment) { }; Error PCKPacker::add_file(const String &p_file, const String &p_src) { - FileAccess *f = FileAccess::open(p_src, FileAccess::READ); if (!f) { return ERR_FILE_CANT_OPEN; @@ -111,7 +104,6 @@ Error PCKPacker::add_file(const String &p_file, const String &p_src) { }; Error PCKPacker::flush(bool p_verbose) { - ERR_FAIL_COND_V_MSG(!file, ERR_INVALID_PARAMETER, "File must be opened before use."); // write the index @@ -119,7 +111,6 @@ Error PCKPacker::flush(bool p_verbose) { file->store_32(files.size()); for (int i = 0; i < files.size(); i++) { - file->store_pascal_string(files[i].path); files.write[i].offset_offset = file->get_position(); file->store_64(0); // offset @@ -142,11 +133,9 @@ Error PCKPacker::flush(bool p_verbose) { int count = 0; for (int i = 0; i < files.size(); i++) { - FileAccess *src = FileAccess::open(files[i].src_path, FileAccess::READ); uint64_t to_write = files[i].size; while (to_write > 0) { - int read = src->get_buffer(buf, MIN(to_write, buf_max)); file->store_buffer(buf, read); to_write -= read; @@ -181,7 +170,6 @@ Error PCKPacker::flush(bool p_verbose) { }; PCKPacker::PCKPacker() { - file = NULL; }; diff --git a/core/io/pck_packer.h b/core/io/pck_packer.h index a9d601fe697..ccd0dba8386 100644 --- a/core/io/pck_packer.h +++ b/core/io/pck_packer.h @@ -36,7 +36,6 @@ class FileAccess; class PCKPacker : public Reference { - GDCLASS(PCKPacker, Reference); FileAccess *file; @@ -45,7 +44,6 @@ class PCKPacker : public Reference { static void _bind_methods(); struct File { - String path; String src_path; int size; diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index 91691a48d19..a083428242e 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -93,7 +93,6 @@ enum { }; void ResourceInteractiveLoaderBinary::_advance_padding(uint32_t p_len) { - uint32_t extra = 4 - (p_len % 4); if (extra < 4) { for (uint32_t i = 0; i < extra; i++) @@ -102,7 +101,6 @@ void ResourceInteractiveLoaderBinary::_advance_padding(uint32_t p_len) { } StringName ResourceInteractiveLoaderBinary::_get_string() { - uint32_t id = f->get_32(); if (id & 0x80000000) { uint32_t len = id & 0x7FFFFFFF; @@ -121,42 +119,32 @@ StringName ResourceInteractiveLoaderBinary::_get_string() { } Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) { - uint32_t type = f->get_32(); print_bl("find property of type: " + itos(type)); switch (type) { - case VARIANT_NIL: { - r_v = Variant(); } break; case VARIANT_BOOL: { - r_v = bool(f->get_32()); } break; case VARIANT_INT: { - r_v = int(f->get_32()); } break; case VARIANT_INT64: { - r_v = int64_t(f->get_64()); } break; case VARIANT_REAL: { - r_v = f->get_real(); } break; case VARIANT_DOUBLE: { - r_v = f->get_double(); } break; case VARIANT_STRING: { - r_v = get_unicode_string(); } break; case VARIANT_VECTOR2: { - Vector2 v; v.x = f->get_real(); v.y = f->get_real(); @@ -164,7 +152,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) { } break; case VARIANT_RECT2: { - Rect2 v; v.position.x = f->get_real(); v.position.y = f->get_real(); @@ -174,7 +161,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) { } break; case VARIANT_VECTOR3: { - Vector3 v; v.x = f->get_real(); v.y = f->get_real(); @@ -182,7 +168,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) { r_v = v; } break; case VARIANT_PLANE: { - Plane v; v.normal.x = f->get_real(); v.normal.y = f->get_real(); @@ -200,7 +185,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) { } break; case VARIANT_AABB: { - AABB v; v.position.x = f->get_real(); v.position.y = f->get_real(); @@ -212,7 +196,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) { } break; case VARIANT_MATRIX32: { - Transform2D v; v.elements[0].x = f->get_real(); v.elements[0].y = f->get_real(); @@ -224,7 +207,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) { } break; case VARIANT_MATRIX3: { - Basis v; v.elements[0].x = f->get_real(); v.elements[0].y = f->get_real(); @@ -239,7 +221,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) { } break; case VARIANT_TRANSFORM: { - Transform v; v.basis.elements[0].x = f->get_real(); v.basis.elements[0].y = f->get_real(); @@ -256,7 +237,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) { r_v = v; } break; case VARIANT_COLOR: { - Color v; v.r = f->get_real(); v.g = f->get_real(); @@ -267,7 +247,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) { } break; case VARIANT_NODE_PATH: { - Vector names; Vector subnames; bool absolute; @@ -291,15 +270,12 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) { } break; case VARIANT_RID: { - r_v = f->get_32(); } break; case VARIANT_OBJECT: { - uint32_t objtype = f->get_32(); switch (objtype) { - case OBJECT_EMPTY: { //do none @@ -345,7 +321,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) { WARN_PRINT("Broken external resource! (index out of size)"); r_v = Variant(); } else { - String exttype = external_resources[erindex].type; String path = external_resources[erindex].path; @@ -364,14 +339,12 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) { } break; default: { - ERR_FAIL_V(ERR_FILE_CORRUPT); } break; } } break; case VARIANT_DICTIONARY: { - uint32_t len = f->get_32(); Dictionary d; //last bit means shared len &= 0x7FFFFFFF; @@ -387,7 +360,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) { r_v = d; } break; case VARIANT_ARRAY: { - uint32_t len = f->get_32(); Array a; //last bit means shared len &= 0x7FFFFFFF; @@ -402,7 +374,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) { } break; case VARIANT_RAW_ARRAY: { - uint32_t len = f->get_32(); PoolVector array; @@ -415,7 +386,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) { } break; case VARIANT_INT_ARRAY: { - uint32_t len = f->get_32(); PoolVector array; @@ -426,7 +396,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) { { uint32_t *ptr = (uint32_t *)w.ptr(); for (int i = 0; i < len; i++) { - ptr[i] = BSWAP32(ptr[i]); } } @@ -436,7 +405,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) { r_v = array; } break; case VARIANT_REAL_ARRAY: { - uint32_t len = f->get_32(); PoolVector array; @@ -447,7 +415,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) { { uint32_t *ptr = (uint32_t *)w.ptr(); for (int i = 0; i < len; i++) { - ptr[i] = BSWAP32(ptr[i]); } } @@ -458,7 +425,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) { r_v = array; } break; case VARIANT_STRING_ARRAY: { - uint32_t len = f->get_32(); PoolVector array; array.resize(len); @@ -470,7 +436,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) { } break; case VARIANT_VECTOR2_ARRAY: { - uint32_t len = f->get_32(); PoolVector array; @@ -482,7 +447,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) { { uint32_t *ptr = (uint32_t *)w.ptr(); for (int i = 0; i < len * 2; i++) { - ptr[i] = BSWAP32(ptr[i]); } } @@ -497,7 +461,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) { } break; case VARIANT_VECTOR3_ARRAY: { - uint32_t len = f->get_32(); PoolVector array; @@ -509,7 +472,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) { { uint32_t *ptr = (uint32_t *)w.ptr(); for (int i = 0; i < len * 3; i++) { - ptr[i] = BSWAP32(ptr[i]); } } @@ -524,7 +486,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) { } break; case VARIANT_COLOR_ARRAY: { - uint32_t len = f->get_32(); PoolVector array; @@ -536,7 +497,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) { { uint32_t *ptr = (uint32_t *)w.ptr(); for (int i = 0; i < len * 4; i++) { - ptr[i] = BSWAP32(ptr[i]); } } @@ -567,7 +527,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) { const uint32_t current_version = 0; if (format_version > current_version) { - ERR_PRINT("Format version for encoded binary image is too new."); return ERR_PARSE_ERROR; } @@ -599,10 +558,8 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) { Ref image; if (encoding == IMAGE_ENCODING_LOSSY && Image::lossy_unpacker) { - image = Image::lossy_unpacker(data); } else if (encoding == IMAGE_ENCODING_LOSSLESS && Image::lossless_unpacker) { - image = Image::lossless_unpacker(data); } _advance_padding(data.size()); @@ -621,23 +578,19 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) { } void ResourceInteractiveLoaderBinary::set_local_path(const String &p_local_path) { - res_path = p_local_path; } Ref ResourceInteractiveLoaderBinary::get_resource() { - return resource; } Error ResourceInteractiveLoaderBinary::poll() { - if (error != OK) return error; int s = stage; if (s < external_resources.size()) { - String path = external_resources[s].path; if (remaps.has(path)) { @@ -645,12 +598,9 @@ Error ResourceInteractiveLoaderBinary::poll() { } RES res = ResourceLoader::load(path, external_resources[s].type); if (res.is_null()) { - if (!ResourceLoader::get_abort_on_missing_resources()) { - ResourceLoader::notify_dependency_error(local_path, path, external_resources[s].type); } else { - error = ERR_FILE_MISSING_DEPENDENCIES; ERR_FAIL_V_MSG(error, "Can't load dependency: " + path + "."); } @@ -666,7 +616,6 @@ Error ResourceInteractiveLoaderBinary::poll() { s -= external_resources.size(); if (s >= internal_resources.size()) { - error = ERR_BUG; ERR_FAIL_COND_V(s >= internal_resources.size(), error); } @@ -678,7 +627,6 @@ Error ResourceInteractiveLoaderBinary::poll() { int subindex = 0; if (!main) { - path = internal_resources[s].path; if (path.begins_with("local://")) { path = path.replace_first("local://", ""); @@ -693,7 +641,6 @@ Error ResourceInteractiveLoaderBinary::poll() { return error; } } else { - if (!ResourceCache::has(res_path)) path = res_path; } @@ -728,7 +675,6 @@ Error ResourceInteractiveLoaderBinary::poll() { //set properties for (int i = 0; i < pc; i++) { - StringName name = _get_string(); if (name == StringName()) { @@ -752,7 +698,6 @@ Error ResourceInteractiveLoaderBinary::poll() { resource_cache.push_back(res); if (main) { - f->close(); resource = res; resource->set_as_translation_remapped(translation_remapped); @@ -765,28 +710,23 @@ Error ResourceInteractiveLoaderBinary::poll() { return OK; } int ResourceInteractiveLoaderBinary::get_stage() const { - return stage; } int ResourceInteractiveLoaderBinary::get_stage_count() const { - return external_resources.size() + internal_resources.size(); } void ResourceInteractiveLoaderBinary::set_translation_remapped(bool p_remapped) { - translation_remapped = p_remapped; } static void save_ustring(FileAccess *f, const String &p_string) { - CharString utf8 = p_string.utf8(); f->store_32(utf8.length() + 1); f->store_buffer((const uint8_t *)utf8.get_data(), utf8.length() + 1); } static String get_ustring(FileAccess *f) { - int len = f->get_32(); Vector str_buf; str_buf.resize(len); @@ -797,7 +737,6 @@ static String get_ustring(FileAccess *f) { } String ResourceInteractiveLoaderBinary::get_unicode_string() { - int len = f->get_32(); if (len > str_buf.size()) { str_buf.resize(len); @@ -811,13 +750,11 @@ String ResourceInteractiveLoaderBinary::get_unicode_string() { } void ResourceInteractiveLoaderBinary::get_dependencies(FileAccess *p_f, List *p_dependencies, bool p_add_types) { - open(p_f); if (error) return; for (int i = 0; i < external_resources.size(); i++) { - String dep = external_resources[i].path; if (p_add_types && external_resources[i].type != String()) { @@ -829,7 +766,6 @@ void ResourceInteractiveLoaderBinary::get_dependencies(FileAccess *p_f, List FORMAT_VERSION || ver_major > VERSION_MAJOR) { - f->close(); ERR_FAIL_MSG(vformat("File '%s' can't be loaded, as it uses a format version (%d) or engine version (%d.%d) which are not supported by your engine version (%s).", local_path, ver_format, ver_major, ver_minor, VERSION_BRANCH)); @@ -891,7 +826,6 @@ void ResourceInteractiveLoaderBinary::open(FileAccess *p_f) { uint32_t string_table_size = f->get_32(); string_map.resize(string_table_size); for (uint32_t i = 0; i < string_table_size; i++) { - StringName s = get_unicode_string(); string_map.write[i] = s; } @@ -900,7 +834,6 @@ void ResourceInteractiveLoaderBinary::open(FileAccess *p_f) { uint32_t ext_resources_size = f->get_32(); for (uint32_t i = 0; i < ext_resources_size; i++) { - ExtResource er; er.type = get_unicode_string(); @@ -913,7 +846,6 @@ void ResourceInteractiveLoaderBinary::open(FileAccess *p_f) { uint32_t int_resources_size = f->get_32(); for (uint32_t i = 0; i < int_resources_size; i++) { - IntResource ir; ir.path = get_unicode_string(); ir.offset = f->get_64(); @@ -923,7 +855,6 @@ void ResourceInteractiveLoaderBinary::open(FileAccess *p_f) { print_bl("int resources: " + itos(int_resources_size)); if (f->eof_reached()) { - error = ERR_FILE_CORRUPT; f->close(); ERR_FAIL_MSG("Premature end of file (EOF): " + local_path + "."); @@ -931,7 +862,6 @@ void ResourceInteractiveLoaderBinary::open(FileAccess *p_f) { } String ResourceInteractiveLoaderBinary::recognize(FileAccess *p_f) { - error = OK; f = p_f; @@ -965,7 +895,6 @@ String ResourceInteractiveLoaderBinary::recognize(FileAccess *p_f) { uint32_t ver_format = f->get_32(); if (ver_format > FORMAT_VERSION || ver_major > VERSION_MAJOR) { - f->close(); return ""; } @@ -983,13 +912,11 @@ ResourceInteractiveLoaderBinary::ResourceInteractiveLoaderBinary() : } ResourceInteractiveLoaderBinary::~ResourceInteractiveLoaderBinary() { - if (f) memdelete(f); } Ref ResourceFormatLoaderBinary::load_interactive(const String &p_path, const String &p_original_path, Error *r_error) { - if (r_error) *r_error = ERR_FILE_CANT_OPEN; @@ -1009,7 +936,6 @@ Ref ResourceFormatLoaderBinary::load_interactive(cons } void ResourceFormatLoaderBinary::get_recognized_extensions_for_type(const String &p_type, List *p_extensions) const { - if (p_type == "") { get_recognized_extensions(p_extensions); return; @@ -1026,7 +952,6 @@ void ResourceFormatLoaderBinary::get_recognized_extensions_for_type(const String } } void ResourceFormatLoaderBinary::get_recognized_extensions(List *p_extensions) const { - List extensions; ClassDB::get_resource_base_extensions(&extensions); extensions.sort(); @@ -1038,12 +963,10 @@ void ResourceFormatLoaderBinary::get_recognized_extensions(List *p_exten } bool ResourceFormatLoaderBinary::handles_type(const String &p_type) const { - return true; //handles all } void ResourceFormatLoaderBinary::get_dependencies(const String &p_path, List *p_dependencies, bool p_add_types) { - FileAccess *f = FileAccess::open(p_path, FileAccess::READ); ERR_FAIL_COND_MSG(!f, "Cannot open file '" + p_path + "'."); @@ -1055,7 +978,6 @@ void ResourceFormatLoaderBinary::get_dependencies(const String &p_path, List &p_map) { - //Error error=OK; FileAccess *f = FileAccess::open(p_path, FileAccess::READ); @@ -1121,7 +1043,6 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons uint32_t ver_format = f->get_32(); if (ver_format < FORMAT_VERSION_CAN_RENAME_DEPS) { - memdelete(f); memdelete(fw); DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); @@ -1157,7 +1078,6 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons } if (ver_format > FORMAT_VERSION || ver_major > VERSION_MAJOR) { - memdelete(f); memdelete(fw); ERR_FAIL_V_MSG(ERR_FILE_UNRECOGNIZED, @@ -1188,7 +1108,6 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons fw->store_32(string_table_size); for (uint32_t i = 0; i < string_table_size; i++) { - String s = get_ustring(f); save_ustring(fw, s); } @@ -1197,7 +1116,6 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons uint32_t ext_resources_size = f->get_32(); fw->store_32(ext_resources_size); for (uint32_t i = 0; i < ext_resources_size; i++) { - String type = get_ustring(f); String path = get_ustring(f); @@ -1228,7 +1146,6 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons fw->store_32(int_resources_size); for (uint32_t i = 0; i < int_resources_size; i++) { - String path = get_ustring(f); uint64_t offset = f->get_64(); save_ustring(fw, path); @@ -1262,7 +1179,6 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons } String ResourceFormatLoaderBinary::get_resource_type(const String &p_path) const { - FileAccess *f = FileAccess::open(p_path, FileAccess::READ); if (!f) { return ""; //could not rwead @@ -1281,7 +1197,6 @@ 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++) @@ -1290,27 +1205,21 @@ void ResourceFormatSaverBinaryInstance::_pad_buffer(FileAccess *f, int p_bytes) } void ResourceFormatSaverBinaryInstance::_write_variant(const Variant &p_property, const PropertyInfo &p_hint) { - write_variant(f, p_property, resource_set, external_resources, string_map, p_hint); } void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Variant &p_property, Set &resource_set, Map &external_resources, Map &string_map, const PropertyInfo &p_hint) { - switch (p_property.get_type()) { - case Variant::NIL: { - f->store_32(VARIANT_NIL); // don't store anything } break; case Variant::BOOL: { - f->store_32(VARIANT_BOOL); bool val = p_property; f->store_32(val); } break; case Variant::INT: { - int64_t val = p_property; if (val > 0x7FFFFFFF || val < -(int64_t)0x80000000) { f->store_32(VARIANT_INT64); @@ -1323,28 +1232,24 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } break; case Variant::REAL: { - double d = p_property; float fl = d; if (double(fl) != d) { f->store_32(VARIANT_DOUBLE); f->store_double(d); } else { - f->store_32(VARIANT_REAL); f->store_real(fl); } } break; case Variant::STRING: { - f->store_32(VARIANT_STRING); String val = p_property; save_unicode_string(f, val); } break; case Variant::VECTOR2: { - f->store_32(VARIANT_VECTOR2); Vector2 val = p_property; f->store_real(val.x); @@ -1352,7 +1257,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } break; case Variant::RECT2: { - f->store_32(VARIANT_RECT2); Rect2 val = p_property; f->store_real(val.position.x); @@ -1362,7 +1266,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } break; case Variant::VECTOR3: { - f->store_32(VARIANT_VECTOR3); Vector3 val = p_property; f->store_real(val.x); @@ -1371,7 +1274,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } break; case Variant::PLANE: { - f->store_32(VARIANT_PLANE); Plane val = p_property; f->store_real(val.normal.x); @@ -1381,7 +1283,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } break; case Variant::QUAT: { - f->store_32(VARIANT_QUAT); Quat val = p_property; f->store_real(val.x); @@ -1391,7 +1292,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } break; case Variant::AABB: { - f->store_32(VARIANT_AABB); AABB val = p_property; f->store_real(val.position.x); @@ -1403,7 +1303,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } break; case Variant::TRANSFORM2D: { - f->store_32(VARIANT_MATRIX32); Transform2D val = p_property; f->store_real(val.elements[0].x); @@ -1415,7 +1314,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } break; case Variant::BASIS: { - f->store_32(VARIANT_MATRIX3); Basis val = p_property; f->store_real(val.elements[0].x); @@ -1430,7 +1328,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } break; case Variant::TRANSFORM: { - f->store_32(VARIANT_TRANSFORM); Transform val = p_property; f->store_real(val.basis.elements[0].x); @@ -1448,7 +1345,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } break; case Variant::COLOR: { - f->store_32(VARIANT_COLOR); Color val = p_property; f->store_real(val.r); @@ -1483,14 +1379,12 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } break; case Variant::_RID: { - f->store_32(VARIANT_RID); WARN_PRINT("Can't save RIDs."); RID val = p_property; f->store_32(val.get_id()); } break; case Variant::OBJECT: { - f->store_32(VARIANT_OBJECT); RES res = p_property; if (res.is_null()) { @@ -1502,7 +1396,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia f->store_32(OBJECT_EXTERNAL_RESOURCE_INDEX); f->store_32(external_resources[res]); } else { - if (!resource_set.has(res)) { f->store_32(OBJECT_EMPTY); ERR_FAIL_MSG("Resource was not pre cached for the resource section, most likely due to circular reference."); @@ -1515,7 +1408,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } break; case Variant::DICTIONARY: { - f->store_32(VARIANT_DICTIONARY); Dictionary d = p_property; f->store_32(uint32_t(d.size())); @@ -1524,7 +1416,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia d.get_key_list(&keys); for (List::Element *E = keys.front(); E; E = E->next()) { - /* if (!_check_type(dict[E->get()])) continue; @@ -1536,18 +1427,15 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } break; case Variant::ARRAY: { - f->store_32(VARIANT_ARRAY); Array a = p_property; f->store_32(uint32_t(a.size())); for (int i = 0; i < a.size(); i++) { - write_variant(f, a[i], resource_set, external_resources, string_map); } } break; case Variant::POOL_BYTE_ARRAY: { - f->store_32(VARIANT_RAW_ARRAY); PoolVector arr = p_property; int len = arr.size(); @@ -1558,7 +1446,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } break; case Variant::POOL_INT_ARRAY: { - f->store_32(VARIANT_INT_ARRAY); PoolVector arr = p_property; int len = arr.size(); @@ -1569,7 +1456,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } break; case Variant::POOL_REAL_ARRAY: { - f->store_32(VARIANT_REAL_ARRAY); PoolVector arr = p_property; int len = arr.size(); @@ -1581,7 +1467,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } break; case Variant::POOL_STRING_ARRAY: { - f->store_32(VARIANT_STRING_ARRAY); PoolVector arr = p_property; int len = arr.size(); @@ -1593,7 +1478,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } break; case Variant::POOL_VECTOR3_ARRAY: { - f->store_32(VARIANT_VECTOR3_ARRAY); PoolVector arr = p_property; int len = arr.size(); @@ -1607,7 +1491,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } break; case Variant::POOL_VECTOR2_ARRAY: { - f->store_32(VARIANT_VECTOR2_ARRAY); PoolVector arr = p_property; int len = arr.size(); @@ -1620,7 +1503,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } break; case Variant::POOL_COLOR_ARRAY: { - f->store_32(VARIANT_COLOR_ARRAY); PoolVector arr = p_property; int len = arr.size(); @@ -1635,17 +1517,14 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia } break; default: { - ERR_FAIL_MSG("Invalid variant."); } } } void ResourceFormatSaverBinaryInstance::_find_resources(const Variant &p_variant, bool p_main) { - switch (p_variant.get_type()) { case Variant::OBJECT: { - RES res = p_variant.operator RefPtr(); if (res.is_null() || external_resources.has(res)) @@ -1669,9 +1548,7 @@ void ResourceFormatSaverBinaryInstance::_find_resources(const Variant &p_variant res->get_property_list(&property_list); for (List::Element *E = property_list.front(); E; E = E->next()) { - if (E->get().usage & PROPERTY_USAGE_STORAGE) { - Variant value = res->get(E->get().name); if (E->get().usage & PROPERTY_USAGE_RESOURCE_NOT_PERSISTENT) { RES sres = value; @@ -1695,11 +1572,9 @@ void ResourceFormatSaverBinaryInstance::_find_resources(const Variant &p_variant } break; case Variant::ARRAY: { - Array varray = p_variant; int len = varray.size(); for (int i = 0; i < len; i++) { - const Variant &v = varray.get(i); _find_resources(v); } @@ -1707,12 +1582,10 @@ void ResourceFormatSaverBinaryInstance::_find_resources(const Variant &p_variant } break; case Variant::DICTIONARY: { - Dictionary d = p_variant; List keys; d.get_key_list(&keys); for (List::Element *E = keys.front(); E; E = E->next()) { - _find_resources(E->get()); Variant v = d[E->get()]; _find_resources(v); @@ -1733,7 +1606,6 @@ void ResourceFormatSaverBinaryInstance::_find_resources(const Variant &p_variant } void ResourceFormatSaverBinaryInstance::save_unicode_string(FileAccess *f, const String &p_string, bool p_bit_on_len) { - CharString utf8 = p_string.utf8(); if (p_bit_on_len) { f->store_32((utf8.length() + 1) | 0x80000000); @@ -1744,7 +1616,6 @@ 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)) return string_map[s]; @@ -1755,7 +1626,6 @@ int ResourceFormatSaverBinaryInstance::get_string_index(const String &p_string) } Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p_resource, uint32_t p_flags) { - Error err; if (p_flags & ResourceSaver::FLAG_COMPRESS) { FileAccessCompressed *fac = memnew(FileAccessCompressed); @@ -1816,9 +1686,7 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p List resources; { - for (List::Element *E = saved_resources.front(); E; E = E->next()) { - ResourceData &rd = resources.push_back(ResourceData())->get(); rd.type = E->get()->get_class(); @@ -1826,7 +1694,6 @@ 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")) continue; if ((F->get().usage & PROPERTY_USAGE_STORAGE)) { @@ -1873,7 +1740,6 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p } for (int i = 0; i < save_order.size(); i++) { - save_unicode_string(f, save_order[i]->get_save_class()); String path = save_order[i]->get_path(); path = relative_paths ? local_path.path_to_file(path) : path; @@ -1885,10 +1751,8 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p Set used_indices; for (List::Element *E = saved_resources.front(); E; E = E->next()) { - RES r = E->get(); if (r->get_path() == "" || r->get_path().find("::") != -1) { - if (r->get_subindex() != 0) { if (used_indices.has(r->get_subindex())) { r->set_subindex(0); //repeated @@ -1900,7 +1764,6 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p } for (List::Element *E = saved_resources.front(); E; E = E->next()) { - RES r = E->get(); if (r->get_path() == "" || r->get_path().find("::") != -1) { if (r->get_subindex() == 0) { @@ -1931,7 +1794,6 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p //now actually save the resources for (List::Element *E = resources.front(); E; E = E->next()) { - ResourceData &rd = E->get(); ofs_table.push_back(f->get_position()); @@ -1939,7 +1801,6 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p f->store_32(rd.properties.size()); for (List::Element *F = rd.properties.front(); F; F = F->next()) { - Property &p = F->get(); f->store_32(p.name_idx); _write_variant(p.value, F->get().pi); @@ -1968,19 +1829,16 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p } Error ResourceFormatSaverBinary::save(const String &p_path, const RES &p_resource, uint32_t p_flags) { - String local_path = ProjectSettings::get_singleton()->localize_path(p_path); ResourceFormatSaverBinaryInstance saver; return saver.save(local_path, p_resource, p_flags); } bool ResourceFormatSaverBinary::recognize(const RES &p_resource) const { - return true; //all recognized } 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") @@ -1990,6 +1848,5 @@ void ResourceFormatSaverBinary::get_recognized_extensions(const RES &p_resource, ResourceFormatSaverBinary *ResourceFormatSaverBinary::singleton = NULL; ResourceFormatSaverBinary::ResourceFormatSaverBinary() { - singleton = this; } diff --git a/core/io/resource_format_binary.h b/core/io/resource_format_binary.h index 06f31cae58e..ec8645bd80f 100644 --- a/core/io/resource_format_binary.h +++ b/core/io/resource_format_binary.h @@ -36,7 +36,6 @@ #include "core/os/file_access.h" class ResourceInteractiveLoaderBinary : public ResourceInteractiveLoader { - bool translation_remapped; String local_path; String res_path; @@ -111,7 +110,6 @@ public: }; class ResourceFormatSaverBinaryInstance { - String local_path; String path; @@ -144,7 +142,6 @@ class ResourceFormatSaverBinaryInstance { }; struct ResourceData { - String type; List properties; }; diff --git a/core/io/resource_importer.cpp b/core/io/resource_importer.cpp index 0b2ac9cb22a..ea6aa9fa2ef 100644 --- a/core/io/resource_importer.cpp +++ b/core/io/resource_importer.cpp @@ -38,7 +38,6 @@ bool ResourceFormatImporter::SortImporterByName::operator()(const Ref *p_extensions) const { - Set found; for (int i = 0; i < importers.size(); i++) { @@ -159,7 +154,6 @@ void ResourceFormatImporter::get_recognized_extensions(List *p_extension } void ResourceFormatImporter::get_recognized_extensions_for_type(const String &p_type, List *p_extensions) const { - if (p_type == "") { get_recognized_extensions(p_extensions); return; @@ -187,26 +181,21 @@ void ResourceFormatImporter::get_recognized_extensions_for_type(const String &p_ } bool ResourceFormatImporter::exists(const String &p_path) const { - return FileAccess::exists(p_path + ".import"); } bool ResourceFormatImporter::recognize_path(const String &p_path, const String &p_for_type) const { - return FileAccess::exists(p_path + ".import"); } bool ResourceFormatImporter::can_be_imported(const String &p_path) const { - return ResourceFormatLoader::recognize_path(p_path); } int ResourceFormatImporter::get_import_order(const String &p_path) const { - Ref importer; if (FileAccess::exists(p_path + ".import")) { - PathAndType pat; Error err = _get_path_and_type(p_path, pat); @@ -214,7 +203,6 @@ int ResourceFormatImporter::get_import_order(const String &p_path) const { importer = get_importer_by_name(pat.importer); } } else { - importer = get_importer_by_extension(p_path.get_extension().to_lower()); } @@ -225,9 +213,7 @@ 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()) continue; @@ -239,12 +225,10 @@ bool ResourceFormatImporter::handles_type(const String &p_type) const { } String ResourceFormatImporter::get_internal_resource_path(const String &p_path) const { - PathAndType pat; Error err = _get_path_and_type(p_path, pat); if (err != OK) { - return String(); } @@ -252,7 +236,6 @@ String ResourceFormatImporter::get_internal_resource_path(const String &p_path) } void ResourceFormatImporter::get_internal_resource_path_list(const String &p_path, List *r_paths) { - Error err; FileAccess *f = FileAccess::open(p_path + ".import", FileAccess::READ, &err); @@ -269,7 +252,6 @@ void ResourceFormatImporter::get_internal_resource_path_list(const String &p_pat int lines = 0; String error_text; while (true) { - assign = Variant(); next_tag.fields.clear(); next_tag.name = String(); @@ -298,7 +280,6 @@ void ResourceFormatImporter::get_internal_resource_path_list(const String &p_pat } String ResourceFormatImporter::get_import_group_file(const String &p_path) const { - bool valid = true; PathAndType pat; _get_path_and_type(p_path, pat, &valid); @@ -306,7 +287,6 @@ String ResourceFormatImporter::get_import_group_file(const String &p_path) const } bool ResourceFormatImporter::is_import_valid(const String &p_path) const { - bool valid = true; PathAndType pat; _get_path_and_type(p_path, pat, &valid); @@ -314,12 +294,10 @@ bool ResourceFormatImporter::is_import_valid(const String &p_path) const { } String ResourceFormatImporter::get_resource_type(const String &p_path) const { - PathAndType pat; Error err = _get_path_and_type(p_path, pat); if (err != OK) { - return ""; } @@ -331,7 +309,6 @@ Variant ResourceFormatImporter::get_resource_metadata(const String &p_path) cons Error err = _get_path_and_type(p_path, pat); if (err != OK) { - return Variant(); } @@ -339,12 +316,10 @@ Variant ResourceFormatImporter::get_resource_metadata(const String &p_path) cons } void ResourceFormatImporter::get_dependencies(const String &p_path, List *p_dependencies, bool p_add_types) { - PathAndType pat; Error err = _get_path_and_type(p_path, pat); if (err != OK) { - return; } @@ -352,7 +327,6 @@ void ResourceFormatImporter::get_dependencies(const String &p_path, List } Ref ResourceFormatImporter::get_importer_by_name(const String &p_name) const { - for (int i = 0; i < importers.size(); i++) { if (importers[i]->get_importer_name() == p_name) { return importers[i]; @@ -363,7 +337,6 @@ Ref ResourceFormatImporter::get_importer_by_name(const String } void ResourceFormatImporter::get_importers_for_extension(const String &p_extension, List> *r_importers) { - for (int i = 0; i < importers.size(); i++) { List local_exts; importers[i]->get_recognized_extensions(&local_exts); @@ -382,12 +355,10 @@ void ResourceFormatImporter::get_importers(List> *r_import } Ref ResourceFormatImporter::get_importer_by_extension(const String &p_extension) const { - Ref importer; float priority = 0; for (int i = 0; i < importers.size(); i++) { - List local_exts; importers[i]->get_recognized_extensions(&local_exts); for (List::Element *F = local_exts.front(); F; F = F->next()) { @@ -402,12 +373,10 @@ Ref ResourceFormatImporter::get_importer_by_extension(const St } String ResourceFormatImporter::get_import_base_path(const String &p_for_file) const { - return "res://.import/" + p_for_file.get_file() + "-" + p_for_file.md5_text(); } bool ResourceFormatImporter::are_import_settings_valid(const String &p_path) const { - bool valid = true; PathAndType pat; _get_path_and_type(p_path, pat, &valid); @@ -428,7 +397,6 @@ bool ResourceFormatImporter::are_import_settings_valid(const String &p_path) con } String ResourceFormatImporter::get_import_settings_hash() const { - Vector> sorted_importers = importers; sorted_importers.sort_custom(); diff --git a/core/io/resource_importer.h b/core/io/resource_importer.h index a8d7f6279ee..9a3cecdc15b 100644 --- a/core/io/resource_importer.h +++ b/core/io/resource_importer.h @@ -36,7 +36,6 @@ class ResourceImporter; class ResourceFormatImporter : public ResourceFormatLoader { - struct PathAndType { String path; String type; @@ -94,7 +93,6 @@ public: }; class ResourceImporter : public Reference { - GDCLASS(ResourceImporter, Reference); public: diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp index 60213b71cec..33cfeaa4b97 100644 --- a/core/io/resource_loader.cpp +++ b/core/io/resource_loader.cpp @@ -44,7 +44,6 @@ Ref ResourceLoader::loader[ResourceLoader::MAX_LOADERS]; int ResourceLoader::loader_count = 0; Error ResourceInteractiveLoader::wait() { - Error err = poll(); while (err == OK) { err = poll(); @@ -60,7 +59,6 @@ ResourceInteractiveLoader::~ResourceInteractiveLoader() { } bool ResourceFormatLoader::recognize_path(const String &p_path, const String &p_for_type) const { - String extension = p_path.get_extension(); List extensions; @@ -71,7 +69,6 @@ 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) return true; } @@ -80,7 +77,6 @@ bool ResourceFormatLoader::recognize_path(const String &p_path, const String &p_ } bool ResourceFormatLoader::handles_type(const String &p_type) const { - if (get_script_instance() && get_script_instance()->has_method("handles_type")) { // I guess custom loaders for custom resources should use "Resource" return get_script_instance()->call("handles_type", p_type); @@ -90,7 +86,6 @@ bool ResourceFormatLoader::handles_type(const String &p_type) const { } String ResourceFormatLoader::get_resource_type(const String &p_path) const { - if (get_script_instance() && get_script_instance()->has_method("get_resource_type")) { return get_script_instance()->call("get_resource_type", p_path); } @@ -99,20 +94,17 @@ 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)) get_recognized_extensions(p_extensions); } void ResourceLoader::get_recognized_extensions_for_type(const String &p_type, List *p_extensions) { - for (int i = 0; i < loader_count; i++) { loader[i]->get_recognized_extensions_for_type(p_type, p_extensions); } } void ResourceInteractiveLoader::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_resource"), &ResourceInteractiveLoader::get_resource); ClassDB::bind_method(D_METHOD("poll"), &ResourceInteractiveLoader::poll); ClassDB::bind_method(D_METHOD("wait"), &ResourceInteractiveLoader::wait); @@ -121,7 +113,6 @@ void ResourceInteractiveLoader::_bind_methods() { } class ResourceInteractiveLoaderDefault : public ResourceInteractiveLoader { - GDCLASS(ResourceInteractiveLoaderDefault, ResourceInteractiveLoader); public: @@ -139,7 +130,6 @@ public: }; Ref ResourceFormatLoader::load_interactive(const String &p_path, const String &p_original_path, Error *r_error) { - //either this Ref res = load(p_path, p_original_path, r_error); if (res.is_null()) @@ -155,7 +145,6 @@ bool ResourceFormatLoader::exists(const String &p_path) const { } void ResourceFormatLoader::get_recognized_extensions(List *p_extensions) const { - if (get_script_instance() && get_script_instance()->has_method("get_recognized_extensions")) { PoolStringArray exts = get_script_instance()->call("get_recognized_extensions"); @@ -169,17 +158,14 @@ void ResourceFormatLoader::get_recognized_extensions(List *p_extensions) } RES ResourceFormatLoader::load(const String &p_path, const String &p_original_path, Error *r_error) { - if (get_script_instance() && get_script_instance()->has_method("load")) { Variant res = get_script_instance()->call("load", p_path, p_original_path); if (res.get_type() == Variant::INT) { - if (r_error) *r_error = (Error)res.operator int64_t(); } else { - if (r_error) *r_error = OK; return res; @@ -193,7 +179,6 @@ RES ResourceFormatLoader::load(const String &p_path, const String &p_original_pa ril->set_local_path(p_original_path); while (true) { - Error err = ril->poll(); if (err == ERR_FILE_EOF) { @@ -210,7 +195,6 @@ RES ResourceFormatLoader::load(const String &p_path, const String &p_original_pa } void ResourceFormatLoader::get_dependencies(const String &p_path, List *p_dependencies, bool p_add_types) { - if (get_script_instance() && get_script_instance()->has_method("get_dependencies")) { PoolStringArray deps = get_script_instance()->call("get_dependencies", p_path, p_add_types); @@ -224,9 +208,7 @@ void ResourceFormatLoader::get_dependencies(const String &p_path, List * } Error ResourceFormatLoader::rename_dependencies(const String &p_path, const Map &p_map) { - if (get_script_instance() && get_script_instance()->has_method("rename_dependencies")) { - Dictionary deps_dict; for (Map::Element *E = p_map.front(); E; E = E->next()) { deps_dict[E->key()] = E->value(); @@ -240,7 +222,6 @@ Error ResourceFormatLoader::rename_dependencies(const String &p_path, const Map< } void ResourceFormatLoader::_bind_methods() { - { MethodInfo info = MethodInfo(Variant::NIL, "load", PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::STRING, "original_path")); info.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT; @@ -257,12 +238,10 @@ void ResourceFormatLoader::_bind_methods() { /////////////////////////////////// RES ResourceLoader::_load(const String &p_path, const String &p_original_path, const String &p_type_hint, bool p_no_cache, Error *r_error) { - bool found = false; // Try all loaders and pick the first match for the type hint for (int i = 0; i < loader_count; i++) { - if (!loader[i]->recognize_path(p_path, p_type_hint)) { continue; } @@ -287,7 +266,6 @@ RES ResourceLoader::_load(const String &p_path, const String &p_original_path, c } bool ResourceLoader::_add_to_loading_map(const String &p_path) { - bool success; loading_map_mutex.lock(); @@ -332,7 +310,6 @@ void ResourceLoader::_remove_from_loading_map_and_thread(const String &p_path, T } RES ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p_no_cache, Error *r_error) { - if (r_error) *r_error = ERR_CANT_OPEN; @@ -343,7 +320,6 @@ RES ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p local_path = ProjectSettings::get_singleton()->localize_path(p_path); if (!p_no_cache) { - { bool success = _add_to_loading_map(local_path); ERR_FAIL_COND_V_MSG(!success, RES(), "Resource: '" + local_path + "' is already being loaded. Cyclic reference?"); @@ -417,7 +393,6 @@ 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()) local_path = "res://" + p_path; @@ -425,7 +400,6 @@ bool ResourceLoader::exists(const String &p_path, const String &p_type_hint) { local_path = ProjectSettings::get_singleton()->localize_path(p_path); if (ResourceCache::has(local_path)) { - return true; // If cached, it probably exists } @@ -434,7 +408,6 @@ bool ResourceLoader::exists(const String &p_path, const String &p_type_hint) { // Try all loaders and pick the first match for the type hint for (int i = 0; i < loader_count; i++) { - if (!loader[i]->recognize_path(path, p_type_hint)) { continue; } @@ -447,7 +420,6 @@ bool ResourceLoader::exists(const String &p_path, const String &p_type_hint) { } Ref ResourceLoader::load_interactive(const String &p_path, const String &p_type_hint, bool p_no_cache, Error *r_error) { - if (r_error) *r_error = ERR_CANT_OPEN; @@ -458,12 +430,10 @@ Ref ResourceLoader::load_interactive(const String &p_ local_path = ProjectSettings::get_singleton()->localize_path(p_path); if (!p_no_cache) { - bool success = _add_to_loading_map(local_path); ERR_FAIL_COND_V_MSG(!success, RES(), "Resource: '" + local_path + "' is already being loaded. Cyclic reference?"); if (ResourceCache::has(local_path)) { - print_verbose("Loading resource: " + local_path + " (cached)"); Ref res_cached = ResourceCache::get(local_path); Ref ril = Ref(memnew(ResourceInteractiveLoaderDefault)); @@ -488,7 +458,6 @@ Ref ResourceLoader::load_interactive(const String &p_ bool found = false; for (int i = 0; i < loader_count; i++) { - if (!loader[i]->recognize_path(path, p_type_hint)) continue; found = true; @@ -517,7 +486,6 @@ Ref ResourceLoader::load_interactive(const String &p_ } void ResourceLoader::add_resource_format_loader(Ref p_format_loader, bool p_at_front) { - ERR_FAIL_COND(p_format_loader.is_null()); ERR_FAIL_COND(loader_count >= MAX_LOADERS); @@ -533,7 +501,6 @@ void ResourceLoader::add_resource_format_loader(Ref p_form } void ResourceLoader::remove_resource_format_loader(Ref p_format_loader) { - ERR_FAIL_COND(p_format_loader.is_null()); // Find loader @@ -554,7 +521,6 @@ void ResourceLoader::remove_resource_format_loader(Ref p_f } int ResourceLoader::get_import_order(const String &p_path) { - String path = _path_remap(p_path); String local_path; @@ -564,7 +530,6 @@ int ResourceLoader::get_import_order(const String &p_path) { local_path = ProjectSettings::get_singleton()->localize_path(path); for (int i = 0; i < loader_count; i++) { - if (!loader[i]->recognize_path(local_path)) continue; /* @@ -588,7 +553,6 @@ String ResourceLoader::get_import_group_file(const String &p_path) { local_path = ProjectSettings::get_singleton()->localize_path(path); for (int i = 0; i < loader_count; i++) { - if (!loader[i]->recognize_path(local_path)) continue; /* @@ -603,7 +567,6 @@ String ResourceLoader::get_import_group_file(const String &p_path) { } bool ResourceLoader::is_import_valid(const String &p_path) { - String path = _path_remap(p_path); String local_path; @@ -613,7 +576,6 @@ bool ResourceLoader::is_import_valid(const String &p_path) { local_path = ProjectSettings::get_singleton()->localize_path(path); for (int i = 0; i < loader_count; i++) { - if (!loader[i]->recognize_path(local_path)) continue; /* @@ -628,7 +590,6 @@ bool ResourceLoader::is_import_valid(const String &p_path) { } bool ResourceLoader::is_imported(const String &p_path) { - String path = _path_remap(p_path); String local_path; @@ -638,7 +599,6 @@ bool ResourceLoader::is_imported(const String &p_path) { local_path = ProjectSettings::get_singleton()->localize_path(path); for (int i = 0; i < loader_count; i++) { - if (!loader[i]->recognize_path(local_path)) continue; /* @@ -653,7 +613,6 @@ bool ResourceLoader::is_imported(const String &p_path) { } void ResourceLoader::get_dependencies(const String &p_path, List *p_dependencies, bool p_add_types) { - String path = _path_remap(p_path); String local_path; @@ -663,7 +622,6 @@ void ResourceLoader::get_dependencies(const String &p_path, List *p_depe local_path = ProjectSettings::get_singleton()->localize_path(path); for (int i = 0; i < loader_count; i++) { - if (!loader[i]->recognize_path(local_path)) continue; /* @@ -676,7 +634,6 @@ void ResourceLoader::get_dependencies(const String &p_path, List *p_depe } Error ResourceLoader::rename_dependencies(const String &p_path, const Map &p_map) { - String path = _path_remap(p_path); String local_path; @@ -686,7 +643,6 @@ 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)) continue; /* @@ -701,7 +657,6 @@ 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); if (result != "") return result; @@ -719,7 +673,6 @@ String ResourceLoader::get_resource_type(const String &p_path) { } String ResourceLoader::_path_remap(const String &p_path, bool *r_translation_remapped) { - String new_path = p_path; if (translation_remaps.has(p_path)) { @@ -778,7 +731,6 @@ String ResourceLoader::_path_remap(const String &p_path, bool *r_translation_rem FileAccess *f = FileAccess::open(p_path + ".remap", FileAccess::READ, &err); if (f) { - VariantParser::StreamFile stream; stream.f = f; @@ -789,7 +741,6 @@ String ResourceLoader::_path_remap(const String &p_path, bool *r_translation_rem int lines = 0; String error_text; while (true) { - assign = Variant(); next_tag.fields.clear(); next_tag.name = String(); @@ -818,9 +769,7 @@ String ResourceLoader::_path_remap(const String &p_path, bool *r_translation_rem } String ResourceLoader::import_remap(const String &p_path) { - if (ResourceFormatImporter::get_singleton()->recognize_path(p_path)) { - return ResourceFormatImporter::get_singleton()->get_internal_resource_path(p_path); } @@ -832,7 +781,6 @@ String ResourceLoader::path_remap(const String &p_path) { } void ResourceLoader::reload_translation_remaps() { - ResourceCache::lock.read_lock(); List to_reload; @@ -853,7 +801,6 @@ void ResourceLoader::reload_translation_remaps() { } void ResourceLoader::load_translation_remaps() { - if (!ProjectSettings::get_singleton()->has_setting("locale/translation_remaps")) return; @@ -861,7 +808,6 @@ void ResourceLoader::load_translation_remaps() { List keys; remaps.get_key_list(&keys); for (List::Element *E = keys.front(); E; E = E->next()) { - Array langs = remaps[E->get()]; Vector lang_remaps; lang_remaps.resize(langs.size()); @@ -881,7 +827,6 @@ void ResourceLoader::clear_translation_remaps() { } void ResourceLoader::load_path_remaps() { - if (!ProjectSettings::get_singleton()->has_setting("path_remap/remapped_paths")) return; @@ -891,13 +836,11 @@ void ResourceLoader::load_path_remaps() { PoolVector::Read r = remaps.read(); for (int i = 0; i < rc; i += 2) { - path_remaps[r[i]] = r[i + 1]; } } void ResourceLoader::clear_path_remaps() { - path_remaps.clear(); } @@ -917,7 +860,6 @@ 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()) return false; @@ -942,7 +884,6 @@ 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()) remove_resource_format_loader(custom_loader); @@ -957,7 +898,6 @@ void ResourceLoader::add_custom_loaders() { ScriptServer::get_global_class_list(&global_classes); for (List::Element *E = global_classes.front(); E; E = E->next()) { - StringName class_name = E->get(); StringName base_class = ScriptServer::get_global_class_native_base(class_name); @@ -969,7 +909,6 @@ void ResourceLoader::add_custom_loaders() { } void ResourceLoader::remove_custom_loaders() { - Vector> custom_loaders; for (int i = 0; i < loader_count; ++i) { if (loader[i]->get_script_instance()) { diff --git a/core/io/resource_loader.h b/core/io/resource_loader.h index 6c0436422dc..206325d0958 100644 --- a/core/io/resource_loader.h +++ b/core/io/resource_loader.h @@ -35,7 +35,6 @@ #include "core/resource.h" class ResourceInteractiveLoader : public Reference { - GDCLASS(ResourceInteractiveLoader, Reference); friend class ResourceLoader; String path_loading; @@ -58,7 +57,6 @@ public: }; class ResourceFormatLoader : public Reference { - GDCLASS(ResourceFormatLoader, Reference); protected: @@ -90,7 +88,6 @@ typedef Error (*ResourceLoaderImport)(const String &p_path); typedef void (*ResourceLoadedCallback)(RES p_resource, const String &p_path); class ResourceLoader { - enum { MAX_LOADERS = 64 }; @@ -131,7 +128,6 @@ class ResourceLoader { } }; struct LoadingMapKeyHasher { - static _FORCE_INLINE_ uint32_t hash(const LoadingMapKey &p_key) { return p_key.path.hash() + HashMapHasherDefault::hash(p_key.thread); } }; diff --git a/core/io/resource_saver.cpp b/core/io/resource_saver.cpp index 92d07dc1bb6..323ad4c109a 100644 --- a/core/io/resource_saver.cpp +++ b/core/io/resource_saver.cpp @@ -41,7 +41,6 @@ bool ResourceSaver::timestamp_on_save = false; ResourceSavedCallback ResourceSaver::save_callback = 0; Error ResourceFormatSaver::save(const String &p_path, const RES &p_resource, uint32_t p_flags) { - if (get_script_instance() && get_script_instance()->has_method("save")) { return (Error)get_script_instance()->call("save", p_path, p_resource, p_flags).operator int64_t(); } @@ -50,7 +49,6 @@ Error ResourceFormatSaver::save(const String &p_path, const RES &p_resource, uin } bool ResourceFormatSaver::recognize(const RES &p_resource) const { - if (get_script_instance() && get_script_instance()->has_method("recognize")) { return get_script_instance()->call("recognize", p_resource); } @@ -59,7 +57,6 @@ bool ResourceFormatSaver::recognize(const RES &p_resource) const { } void ResourceFormatSaver::get_recognized_extensions(const RES &p_resource, List *p_extensions) const { - if (get_script_instance() && get_script_instance()->has_method("get_recognized_extensions")) { PoolStringArray exts = get_script_instance()->call("get_recognized_extensions", p_resource); @@ -73,7 +70,6 @@ void ResourceFormatSaver::get_recognized_extensions(const RES &p_resource, List< } void ResourceFormatSaver::_bind_methods() { - { PropertyInfo arg0 = PropertyInfo(Variant::STRING, "path"); PropertyInfo arg1 = PropertyInfo(Variant::OBJECT, "resource", PROPERTY_HINT_RESOURCE_TYPE, "Resource"); @@ -86,12 +82,10 @@ void ResourceFormatSaver::_bind_methods() { } Error ResourceSaver::save(const String &p_path, const RES &p_resource, uint32_t p_flags) { - String extension = p_path.get_extension(); Error err = ERR_FILE_UNRECOGNIZED; for (int i = 0; i < saver_count; i++) { - if (!saver[i]->recognize(p_resource)) continue; @@ -100,7 +94,6 @@ Error ResourceSaver::save(const String &p_path, const RES &p_resource, uint32_t 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) recognized = true; } @@ -119,7 +112,6 @@ Error ResourceSaver::save(const String &p_path, const RES &p_resource, uint32_t err = saver[i]->save(p_path, p_resource, p_flags); if (err == OK) { - #ifdef TOOLS_ENABLED ((Resource *)p_resource.ptr())->set_edited(false); @@ -144,20 +136,16 @@ Error ResourceSaver::save(const String &p_path, const RES &p_resource, uint32_t } void ResourceSaver::set_save_callback(ResourceSavedCallback p_callback) { - save_callback = p_callback; } void ResourceSaver::get_recognized_extensions(const RES &p_resource, List *p_extensions) { - for (int i = 0; i < saver_count; i++) { - saver[i]->get_recognized_extensions(p_resource, p_extensions); } } void ResourceSaver::add_resource_format_saver(Ref p_format_saver, bool p_at_front) { - ERR_FAIL_COND_MSG(p_format_saver.is_null(), "It's not a reference to a valid ResourceFormatSaver object."); ERR_FAIL_COND(saver_count >= MAX_SAVERS); @@ -173,7 +161,6 @@ void ResourceSaver::add_resource_format_saver(Ref p_format_ } void ResourceSaver::remove_resource_format_saver(Ref p_format_saver) { - ERR_FAIL_COND_MSG(p_format_saver.is_null(), "It's not a reference to a valid ResourceFormatSaver object."); // Find saver @@ -203,7 +190,6 @@ 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()) return false; @@ -228,7 +214,6 @@ 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()) remove_resource_format_saver(custom_saver); @@ -243,7 +228,6 @@ void ResourceSaver::add_custom_savers() { ScriptServer::get_global_class_list(&global_classes); for (List::Element *E = global_classes.front(); E; E = E->next()) { - StringName class_name = E->get(); StringName base_class = ScriptServer::get_global_class_native_base(class_name); @@ -255,7 +239,6 @@ void ResourceSaver::add_custom_savers() { } void ResourceSaver::remove_custom_savers() { - Vector> custom_savers; for (int i = 0; i < saver_count; ++i) { if (saver[i]->get_script_instance()) { diff --git a/core/io/resource_saver.h b/core/io/resource_saver.h index 8100dfcfe8c..374ec175746 100644 --- a/core/io/resource_saver.h +++ b/core/io/resource_saver.h @@ -50,7 +50,6 @@ public: typedef void (*ResourceSavedCallback)(Ref p_resource, const String &p_path); class ResourceSaver { - enum { MAX_SAVERS = 64 }; diff --git a/core/io/stream_peer.cpp b/core/io/stream_peer.cpp index 47831d4cd59..67d5c7683d9 100644 --- a/core/io/stream_peer.cpp +++ b/core/io/stream_peer.cpp @@ -33,7 +33,6 @@ #include "core/io/marshalls.h" Error StreamPeer::_put_data(const PoolVector &p_data) { - int len = p_data.size(); if (len == 0) return OK; @@ -42,7 +41,6 @@ Error StreamPeer::_put_data(const PoolVector &p_data) { } Array StreamPeer::_put_partial_data(const PoolVector &p_data) { - Array ret; int len = p_data.size(); @@ -65,13 +63,11 @@ Array StreamPeer::_put_partial_data(const PoolVector &p_data) { } Array StreamPeer::_get_data(int p_bytes) { - Array ret; PoolVector data; data.resize(p_bytes); if (data.size() != p_bytes) { - ret.push_back(ERR_OUT_OF_MEMORY); ret.push_back(PoolVector()); return ret; @@ -86,13 +82,11 @@ Array StreamPeer::_get_data(int p_bytes) { } Array StreamPeer::_get_partial_data(int p_bytes) { - Array ret; PoolVector data; data.resize(p_bytes); if (data.size() != p_bytes) { - ret.push_back(ERR_OUT_OF_MEMORY); ret.push_back(PoolVector()); return ret; @@ -106,7 +100,6 @@ Array StreamPeer::_get_partial_data(int p_bytes) { if (err != OK) { data.resize(0); } else if (received != data.size()) { - data.resize(received); } @@ -116,12 +109,10 @@ Array StreamPeer::_get_partial_data(int p_bytes) { } void StreamPeer::set_big_endian(bool p_enable) { - big_endian = p_enable; } bool StreamPeer::is_big_endian_enabled() const { - return big_endian; } @@ -130,11 +121,9 @@ void StreamPeer::put_u8(uint8_t p_val) { } void StreamPeer::put_8(int8_t p_val) { - put_data((const uint8_t *)&p_val, 1); } void StreamPeer::put_u16(uint16_t p_val) { - if (big_endian) { p_val = BSWAP16(p_val); } @@ -143,7 +132,6 @@ void StreamPeer::put_u16(uint16_t p_val) { put_data(buf, 2); } void StreamPeer::put_16(int16_t p_val) { - if (big_endian) { p_val = BSWAP16(p_val); } @@ -152,7 +140,6 @@ void StreamPeer::put_16(int16_t p_val) { put_data(buf, 2); } void StreamPeer::put_u32(uint32_t p_val) { - if (big_endian) { p_val = BSWAP32(p_val); } @@ -161,7 +148,6 @@ void StreamPeer::put_u32(uint32_t p_val) { put_data(buf, 4); } void StreamPeer::put_32(int32_t p_val) { - if (big_endian) { p_val = BSWAP32(p_val); } @@ -170,7 +156,6 @@ void StreamPeer::put_32(int32_t p_val) { put_data(buf, 4); } void StreamPeer::put_u64(uint64_t p_val) { - if (big_endian) { p_val = BSWAP64(p_val); } @@ -179,7 +164,6 @@ void StreamPeer::put_u64(uint64_t p_val) { put_data(buf, 8); } void StreamPeer::put_64(int64_t p_val) { - if (big_endian) { p_val = BSWAP64(p_val); } @@ -188,7 +172,6 @@ void StreamPeer::put_64(int64_t p_val) { put_data(buf, 8); } void StreamPeer::put_float(float p_val) { - uint8_t buf[4]; encode_float(p_val, buf); @@ -200,7 +183,6 @@ void StreamPeer::put_float(float p_val) { put_data(buf, 4); } void StreamPeer::put_double(double p_val) { - uint8_t buf[8]; encode_double(p_val, buf); if (big_endian) { @@ -210,19 +192,16 @@ void StreamPeer::put_double(double p_val) { put_data(buf, 8); } void StreamPeer::put_string(const String &p_string) { - CharString cs = p_string.ascii(); put_u32(cs.length()); put_data((const uint8_t *)cs.get_data(), cs.length()); } void StreamPeer::put_utf8_string(const String &p_string) { - CharString cs = p_string.utf8(); put_u32(cs.length()); put_data((const uint8_t *)cs.get_data(), cs.length()); } void StreamPeer::put_var(const Variant &p_variant, bool p_full_objects) { - int len = 0; Vector buf; encode_variant(p_variant, NULL, len, p_full_objects); @@ -233,19 +212,16 @@ void StreamPeer::put_var(const Variant &p_variant, bool p_full_objects) { } uint8_t StreamPeer::get_u8() { - uint8_t buf[1]; get_data(buf, 1); return buf[0]; } int8_t StreamPeer::get_8() { - uint8_t buf[1]; get_data(buf, 1); return buf[0]; } uint16_t StreamPeer::get_u16() { - uint8_t buf[2]; get_data(buf, 2); uint16_t r = decode_uint16(buf); @@ -255,7 +231,6 @@ uint16_t StreamPeer::get_u16() { return r; } int16_t StreamPeer::get_16() { - uint8_t buf[2]; get_data(buf, 2); uint16_t r = decode_uint16(buf); @@ -265,7 +240,6 @@ int16_t StreamPeer::get_16() { return r; } uint32_t StreamPeer::get_u32() { - uint8_t buf[4]; get_data(buf, 4); uint32_t r = decode_uint32(buf); @@ -275,7 +249,6 @@ uint32_t StreamPeer::get_u32() { return r; } int32_t StreamPeer::get_32() { - uint8_t buf[4]; get_data(buf, 4); uint32_t r = decode_uint32(buf); @@ -285,7 +258,6 @@ int32_t StreamPeer::get_32() { return r; } uint64_t StreamPeer::get_u64() { - uint8_t buf[8]; get_data(buf, 8); uint64_t r = decode_uint64(buf); @@ -295,7 +267,6 @@ uint64_t StreamPeer::get_u64() { return r; } int64_t StreamPeer::get_64() { - uint8_t buf[8]; get_data(buf, 8); uint64_t r = decode_uint64(buf); @@ -305,7 +276,6 @@ int64_t StreamPeer::get_64() { return r; } float StreamPeer::get_float() { - uint8_t buf[4]; get_data(buf, 4); @@ -318,7 +288,6 @@ float StreamPeer::get_float() { } double StreamPeer::get_double() { - uint8_t buf[8]; get_data(buf, 8); @@ -330,7 +299,6 @@ double StreamPeer::get_double() { return decode_double(buf); } String StreamPeer::get_string(int p_bytes) { - if (p_bytes < 0) p_bytes = get_u32(); ERR_FAIL_COND_V(p_bytes < 0, String()); @@ -344,7 +312,6 @@ String StreamPeer::get_string(int p_bytes) { return buf.ptr(); } String StreamPeer::get_utf8_string(int p_bytes) { - if (p_bytes < 0) p_bytes = get_u32(); ERR_FAIL_COND_V(p_bytes < 0, String()); @@ -360,7 +327,6 @@ String StreamPeer::get_utf8_string(int p_bytes) { return ret; } Variant StreamPeer::get_var(bool p_allow_objects) { - int len = get_32(); Vector var; Error err = var.resize(len); @@ -376,7 +342,6 @@ Variant StreamPeer::get_var(bool p_allow_objects) { } void StreamPeer::_bind_methods() { - ClassDB::bind_method(D_METHOD("put_data", "data"), &StreamPeer::_put_data); ClassDB::bind_method(D_METHOD("put_partial_data", "data"), &StreamPeer::_put_partial_data); @@ -421,7 +386,6 @@ void StreamPeer::_bind_methods() { //////////////////////////////// void StreamPeerBuffer::_bind_methods() { - ClassDB::bind_method(D_METHOD("seek", "position"), &StreamPeerBuffer::seek); ClassDB::bind_method(D_METHOD("get_size"), &StreamPeerBuffer::get_size); ClassDB::bind_method(D_METHOD("get_position"), &StreamPeerBuffer::get_position); @@ -435,7 +399,6 @@ void StreamPeerBuffer::_bind_methods() { } Error StreamPeerBuffer::put_data(const uint8_t *p_data, int p_bytes) { - if (p_bytes <= 0) return OK; @@ -451,13 +414,11 @@ Error StreamPeerBuffer::put_data(const uint8_t *p_data, int p_bytes) { } Error StreamPeerBuffer::put_partial_data(const uint8_t *p_data, int p_bytes, int &r_sent) { - r_sent = p_bytes; return put_data(p_data, p_bytes); } 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) @@ -467,7 +428,6 @@ Error StreamPeerBuffer::get_data(uint8_t *p_buffer, int p_bytes) { } Error StreamPeerBuffer::get_partial_data(uint8_t *p_buffer, int p_bytes, int &r_received) { - if (pointer + p_bytes > data.size()) { r_received = data.size() - pointer; if (r_received <= 0) { @@ -488,50 +448,41 @@ Error StreamPeerBuffer::get_partial_data(uint8_t *p_buffer, int p_bytes, int &r_ } int StreamPeerBuffer::get_available_bytes() const { - return data.size() - pointer; } void StreamPeerBuffer::seek(int p_pos) { - ERR_FAIL_COND(p_pos < 0); ERR_FAIL_COND(p_pos > data.size()); pointer = p_pos; } int StreamPeerBuffer::get_size() const { - return data.size(); } int StreamPeerBuffer::get_position() const { - return pointer; } void StreamPeerBuffer::resize(int p_size) { - data.resize(p_size); } void StreamPeerBuffer::set_data_array(const PoolVector &p_data) { - data = p_data; pointer = 0; } PoolVector StreamPeerBuffer::get_data_array() const { - return data; } void StreamPeerBuffer::clear() { - data.resize(0); pointer = 0; } Ref StreamPeerBuffer::duplicate() const { - Ref spb; spb.instance(); spb->data = data; @@ -539,6 +490,5 @@ Ref StreamPeerBuffer::duplicate() const { } StreamPeerBuffer::StreamPeerBuffer() { - pointer = 0; } diff --git a/core/io/stream_peer.h b/core/io/stream_peer.h index 0be811a0e17..a74628e31de 100644 --- a/core/io/stream_peer.h +++ b/core/io/stream_peer.h @@ -93,7 +93,6 @@ public: }; class StreamPeerBuffer : public StreamPeer { - GDCLASS(StreamPeerBuffer, StreamPeer); PoolVector data; diff --git a/core/io/stream_peer_ssl.cpp b/core/io/stream_peer_ssl.cpp index 3cbb8d36032..d9442fdbafd 100644 --- a/core/io/stream_peer_ssl.cpp +++ b/core/io/stream_peer_ssl.cpp @@ -35,7 +35,6 @@ StreamPeerSSL *(*StreamPeerSSL::_create)() = NULL; StreamPeerSSL *StreamPeerSSL::create() { - if (_create) return _create(); return NULL; @@ -56,7 +55,6 @@ bool StreamPeerSSL::is_blocking_handshake_enabled() const { } void StreamPeerSSL::_bind_methods() { - ClassDB::bind_method(D_METHOD("poll"), &StreamPeerSSL::poll); ClassDB::bind_method(D_METHOD("accept_stream", "stream", "private_key", "certificate", "chain"), &StreamPeerSSL::accept_stream, DEFVAL(Ref())); ClassDB::bind_method(D_METHOD("connect_to_stream", "stream", "validate_certs", "for_hostname", "valid_certificate"), &StreamPeerSSL::connect_to_stream, DEFVAL(false), DEFVAL(String()), DEFVAL(Ref())); diff --git a/core/io/stream_peer_tcp.cpp b/core/io/stream_peer_tcp.cpp index 7dc1314efe7..b0a162bfa93 100644 --- a/core/io/stream_peer_tcp.cpp +++ b/core/io/stream_peer_tcp.cpp @@ -33,7 +33,6 @@ #include "core/project_settings.h" Error StreamPeerTCP::_poll_connection() { - ERR_FAIL_COND_V(status != STATUS_CONNECTING || !_sock.is_valid() || !_sock->is_open(), FAILED); Error err = _sock->connect_to_host(peer_host, peer_port); @@ -58,7 +57,6 @@ Error StreamPeerTCP::_poll_connection() { } void StreamPeerTCP::accept_socket(Ref p_sock, IP_Address p_host, uint16_t p_port) { - _sock = p_sock; _sock->set_blocking_enabled(false); @@ -70,7 +68,6 @@ void StreamPeerTCP::accept_socket(Ref p_sock, IP_Address p_host, uint } Error StreamPeerTCP::connect_to_host(const IP_Address &p_host, uint16_t p_port) { - ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE); ERR_FAIL_COND_V(_sock->is_open(), ERR_ALREADY_IN_USE); ERR_FAIL_COND_V(!p_host.is_valid(), ERR_INVALID_PARAMETER); @@ -103,18 +100,14 @@ Error StreamPeerTCP::connect_to_host(const IP_Address &p_host, uint16_t p_port) } Error StreamPeerTCP::write(const uint8_t *p_data, int p_bytes, int &r_sent, bool p_block) { - ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE); if (status == STATUS_NONE || status == STATUS_ERROR) { - return FAILED; } if (status != STATUS_CONNECTED) { - if (_poll_connection() != OK) { - return FAILED; } @@ -133,12 +126,10 @@ Error StreamPeerTCP::write(const uint8_t *p_data, int p_bytes, int &r_sent, bool int total_sent = 0; while (data_to_send) { - int sent_amount = 0; err = _sock->send(offset, data_to_send, sent_amount); if (err != OK) { - if (err != ERR_BUSY) { disconnect_from_host(); return FAILED; @@ -156,7 +147,6 @@ Error StreamPeerTCP::write(const uint8_t *p_data, int p_bytes, int &r_sent, bool return FAILED; } } else { - data_to_send -= sent_amount; offset += sent_amount; total_sent += sent_amount; @@ -169,16 +159,12 @@ Error StreamPeerTCP::write(const uint8_t *p_data, int p_bytes, int &r_sent, bool } Error StreamPeerTCP::read(uint8_t *p_buffer, int p_bytes, int &r_received, bool p_block) { - if (!is_connected_to_host()) { - return FAILED; } if (status == STATUS_CONNECTING) { - if (_poll_connection() != OK) { - return FAILED; } @@ -194,12 +180,10 @@ Error StreamPeerTCP::read(uint8_t *p_buffer, int p_bytes, int &r_received, bool r_received = 0; while (to_read) { - int read = 0; err = _sock->recv(p_buffer + total_read, to_read, read); if (err != OK) { - if (err != ERR_BUSY) { disconnect_from_host(); return FAILED; @@ -218,13 +202,11 @@ Error StreamPeerTCP::read(uint8_t *p_buffer, int p_bytes, int &r_received, bool } } else if (read == 0) { - disconnect_from_host(); r_received = total_read; return ERR_FILE_EOF; } else { - to_read -= read; total_read += read; @@ -241,18 +223,15 @@ Error StreamPeerTCP::read(uint8_t *p_buffer, int p_bytes, int &r_received, bool } void StreamPeerTCP::set_no_delay(bool p_enabled) { - ERR_FAIL_COND(!is_connected_to_host()); _sock->set_tcp_no_delay_enabled(p_enabled); } bool StreamPeerTCP::is_connected_to_host() const { - return _sock.is_valid() && _sock->is_open() && (status == STATUS_CONNECTED || status == STATUS_CONNECTING); } StreamPeerTCP::Status StreamPeerTCP::get_status() { - if (status == STATUS_CONNECTING) { _poll_connection(); } else if (status == STATUS_CONNECTED) { @@ -278,7 +257,6 @@ StreamPeerTCP::Status StreamPeerTCP::get_status() { } void StreamPeerTCP::disconnect_from_host() { - if (_sock.is_valid() && _sock->is_open()) _sock->close(); @@ -289,45 +267,37 @@ void StreamPeerTCP::disconnect_from_host() { } Error StreamPeerTCP::put_data(const uint8_t *p_data, int p_bytes) { - int total; return write(p_data, p_bytes, total, true); } Error StreamPeerTCP::put_partial_data(const uint8_t *p_data, int p_bytes, int &r_sent) { - return write(p_data, p_bytes, r_sent, false); } Error StreamPeerTCP::get_data(uint8_t *p_buffer, int p_bytes) { - int total; return read(p_buffer, p_bytes, total, true); } Error StreamPeerTCP::get_partial_data(uint8_t *p_buffer, int p_bytes, int &r_received) { - return read(p_buffer, p_bytes, r_received, false); } int StreamPeerTCP::get_available_bytes() const { - ERR_FAIL_COND_V(!_sock.is_valid(), -1); return _sock->get_available_bytes(); } IP_Address StreamPeerTCP::get_connected_host() const { - return peer_host; } uint16_t StreamPeerTCP::get_connected_port() const { - return peer_port; } Error StreamPeerTCP::_connect(const String &p_address, int p_port) { - IP_Address ip; if (p_address.is_valid_ip_address()) { ip = p_address; @@ -341,7 +311,6 @@ Error StreamPeerTCP::_connect(const String &p_address, int p_port) { } void StreamPeerTCP::_bind_methods() { - ClassDB::bind_method(D_METHOD("connect_to_host", "host", "port"), &StreamPeerTCP::_connect); ClassDB::bind_method(D_METHOD("is_connected_to_host"), &StreamPeerTCP::is_connected_to_host); ClassDB::bind_method(D_METHOD("get_status"), &StreamPeerTCP::get_status); @@ -364,6 +333,5 @@ StreamPeerTCP::StreamPeerTCP() : } StreamPeerTCP::~StreamPeerTCP() { - disconnect_from_host(); } diff --git a/core/io/stream_peer_tcp.h b/core/io/stream_peer_tcp.h index 9df73cf45a1..bb0c2622405 100644 --- a/core/io/stream_peer_tcp.h +++ b/core/io/stream_peer_tcp.h @@ -37,7 +37,6 @@ #include "core/io/stream_peer.h" class StreamPeerTCP : public StreamPeer { - GDCLASS(StreamPeerTCP, StreamPeer); OBJ_CATEGORY("Networking"); diff --git a/core/io/tcp_server.cpp b/core/io/tcp_server.cpp index 1f1f1a34513..1015bdc4172 100644 --- a/core/io/tcp_server.cpp +++ b/core/io/tcp_server.cpp @@ -31,7 +31,6 @@ #include "tcp_server.h" void TCP_Server::_bind_methods() { - ClassDB::bind_method(D_METHOD("listen", "port", "bind_address"), &TCP_Server::listen, DEFVAL("*")); ClassDB::bind_method(D_METHOD("is_connection_available"), &TCP_Server::is_connection_available); ClassDB::bind_method(D_METHOD("is_listening"), &TCP_Server::is_listening); @@ -40,7 +39,6 @@ void TCP_Server::_bind_methods() { } Error TCP_Server::listen(uint16_t p_port, const IP_Address &p_bind_address) { - ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE); ERR_FAIL_COND_V(_sock->is_open(), ERR_ALREADY_IN_USE); ERR_FAIL_COND_V(!p_bind_address.is_valid() && !p_bind_address.is_wildcard(), ERR_INVALID_PARAMETER); @@ -62,7 +60,6 @@ Error TCP_Server::listen(uint16_t p_port, const IP_Address &p_bind_address) { err = _sock->bind(p_bind_address, p_port); if (err != OK) { - _sock->close(); return ERR_ALREADY_IN_USE; } @@ -83,7 +80,6 @@ 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()) @@ -94,7 +90,6 @@ bool TCP_Server::is_connection_available() const { } Ref TCP_Server::take_connection() { - Ref conn; if (!is_connection_available()) { return conn; @@ -113,7 +108,6 @@ Ref TCP_Server::take_connection() { } void TCP_Server::stop() { - if (_sock.is_valid()) { _sock->close(); } @@ -124,6 +118,5 @@ TCP_Server::TCP_Server() : } TCP_Server::~TCP_Server() { - stop(); } diff --git a/core/io/tcp_server.h b/core/io/tcp_server.h index eac3ac8f677..f06ddd2d993 100644 --- a/core/io/tcp_server.h +++ b/core/io/tcp_server.h @@ -37,7 +37,6 @@ #include "core/io/stream_peer_tcp.h" class TCP_Server : public Reference { - GDCLASS(TCP_Server, Reference); protected: diff --git a/core/io/translation_loader_po.cpp b/core/io/translation_loader_po.cpp index e5823d906c1..f912c7ca2dd 100644 --- a/core/io/translation_loader_po.cpp +++ b/core/io/translation_loader_po.cpp @@ -57,13 +57,11 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) { const String path = f->get_path(); while (!is_eof) { - String l = f->get_line().strip_edges(); is_eof = f->eof_reached(); // If we reached last line and it's not a content line, break, otherwise let processing that last loop if (is_eof && l.empty()) { - if (status == STATUS_READING_ID) { memdelete(f); ERR_FAIL_V_MSG(RES(), "Unexpected EOF while reading 'msgid' at: " + path + ":" + itos(line)); @@ -73,7 +71,6 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) { } if (l.begins_with("msgid")) { - if (status == STATUS_READING_ID) { memdelete(f); ERR_FAIL_V_MSG(RES(), "Unexpected 'msgid', was expecting 'msgstr' while parsing: " + path + ":" + itos(line)); @@ -94,7 +91,6 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) { } if (l.begins_with("msgstr")) { - if (status != STATUS_READING_ID) { memdelete(f); ERR_FAIL_V_MSG(RES(), "Unexpected 'msgstr', was expecting 'msgid' while parsing: " + path + ":" + itos(line)); @@ -121,7 +117,6 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) { //find final quote int end_pos = -1; for (int i = 0; i < l.length(); i++) { - if (l[i] == '"' && (i == 0 || l[i - 1] != '\\')) { end_pos = i; break; @@ -147,7 +142,6 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) { memdelete(f); if (status == STATUS_READING_STRING) { - if (msg_id != "") { if (!skip_this) translation->add_message(msg_id, msg_str); @@ -159,7 +153,6 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) { Vector configs = config.split("\n"); for (int i = 0; i < configs.size(); i++) { - String c = configs[i].strip_edges(); int p = c.find(":"); if (p == -1) @@ -179,7 +172,6 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) { } RES TranslationLoaderPO::load(const String &p_path, const String &p_original_path, Error *r_error) { - if (r_error) *r_error = ERR_CANT_OPEN; @@ -190,16 +182,13 @@ RES TranslationLoaderPO::load(const String &p_path, const String &p_original_pat } void TranslationLoaderPO::get_recognized_extensions(List *p_extensions) const { - p_extensions->push_back("po"); } bool TranslationLoaderPO::handles_type(const String &p_type) const { - return (p_type == "Translation"); } String TranslationLoaderPO::get_resource_type(const String &p_path) const { - 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 1b946af8e28..23553531768 100644 --- a/core/io/udp_server.cpp +++ b/core/io/udp_server.cpp @@ -31,7 +31,6 @@ #include "udp_server.h" void UDPServer::_bind_methods() { - ClassDB::bind_method(D_METHOD("listen", "port", "bind_address"), &UDPServer::listen, DEFVAL("*")); ClassDB::bind_method(D_METHOD("poll"), &UDPServer::poll); ClassDB::bind_method(D_METHOD("is_connection_available"), &UDPServer::is_connection_available); @@ -88,7 +87,6 @@ Error UDPServer::poll() { } Error UDPServer::listen(uint16_t p_port, const IP_Address &p_bind_address) { - ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE); ERR_FAIL_COND_V(_sock->is_open(), ERR_ALREADY_IN_USE); ERR_FAIL_COND_V(!p_bind_address.is_valid() && !p_bind_address.is_wildcard(), ERR_INVALID_PARAMETER); @@ -124,7 +122,6 @@ bool UDPServer::is_listening() const { } bool UDPServer::is_connection_available() const { - ERR_FAIL_COND_V(!_sock.is_valid(), false); if (!_sock->is_open()) @@ -151,7 +148,6 @@ int UDPServer::get_max_pending_connections() const { } Ref UDPServer::take_connection() { - Ref conn; if (!is_connection_available()) { return conn; @@ -174,7 +170,6 @@ void UDPServer::remove_peer(IP_Address p_ip, int p_port) { } void UDPServer::stop() { - if (_sock.is_valid()) { _sock->close(); } @@ -200,6 +195,5 @@ UDPServer::UDPServer() : } UDPServer::~UDPServer() { - stop(); } diff --git a/core/io/xml_parser.cpp b/core/io/xml_parser.cpp index ec2f87bc0d8..5ee82287e72 100644 --- a/core/io/xml_parser.cpp +++ b/core/io/xml_parser.cpp @@ -48,7 +48,6 @@ static bool _equalsn(const CharType *str1, const CharType *str2, int len) { } String XMLParser::_replace_special_characters(const String &origstr) { - int pos = origstr.find("&"); int oldPos = 0; @@ -148,7 +147,6 @@ void XMLParser::_ignore_definition() { } bool XMLParser::_parse_cdata() { - if (*(P + 1) != '[') return false; @@ -190,7 +188,6 @@ bool XMLParser::_parse_cdata() { } void XMLParser::_parse_comment() { - node_type = NODE_COMMENT; P += 1; @@ -217,7 +214,6 @@ void XMLParser::_parse_comment() { } void XMLParser::_parse_opening_xml_element() { - node_type = NODE_ELEMENT; node_empty = false; attributes.clear(); @@ -304,7 +300,6 @@ void XMLParser::_parse_opening_xml_element() { } void XMLParser::_parse_current_node() { - char *start = P; node_offset = P - data; @@ -342,12 +337,10 @@ void XMLParser::_parse_current_node() { } uint64_t XMLParser::get_node_offset() const { - return node_offset; }; Error XMLParser::seek(uint64_t p_pos) { - ERR_FAIL_COND_V(!data, ERR_FILE_EOF); ERR_FAIL_COND_V(p_pos >= length, ERR_FILE_EOF); @@ -357,7 +350,6 @@ Error XMLParser::seek(uint64_t p_pos) { }; void XMLParser::_bind_methods() { - ClassDB::bind_method(D_METHOD("read"), &XMLParser::read); ClassDB::bind_method(D_METHOD("get_node_type"), &XMLParser::get_node_type); ClassDB::bind_method(D_METHOD("get_node_name"), &XMLParser::get_node_name); @@ -386,7 +378,6 @@ void XMLParser::_bind_methods() { }; Error XMLParser::read() { - // if not end reached, parse the node if (P && (P - data) < (int64_t)length - 1 && *P != 0) { _parse_current_node(); @@ -397,11 +388,9 @@ Error XMLParser::read() { } XMLParser::NodeType XMLParser::get_node_type() { - return node_type; } String XMLParser::get_node_data() const { - ERR_FAIL_COND_V(node_type != NODE_TEXT, ""); return node_name; } @@ -411,21 +400,17 @@ String XMLParser::get_node_name() const { return node_name; } int XMLParser::get_attribute_count() const { - return attributes.size(); } String XMLParser::get_attribute_name(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, attributes.size(), ""); return attributes[p_idx].name; } String XMLParser::get_attribute_value(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, attributes.size(), ""); return attributes[p_idx].value; } bool XMLParser::has_attribute(const String &p_name) const { - for (int i = 0; i < attributes.size(); i++) { if (attributes[i].name == p_name) return true; @@ -434,7 +419,6 @@ bool XMLParser::has_attribute(const String &p_name) const { return false; } String XMLParser::get_attribute_value(const String &p_name) const { - int idx = -1; for (int i = 0; i < attributes.size(); i++) { if (attributes[i].name == p_name) { @@ -449,7 +433,6 @@ String XMLParser::get_attribute_value(const String &p_name) const { } String XMLParser::get_attribute_value_safe(const String &p_name) const { - int idx = -1; for (int i = 0; i < attributes.size(); i++) { if (attributes[i].name == p_name) { @@ -463,12 +446,10 @@ String XMLParser::get_attribute_value_safe(const String &p_name) const { return attributes[idx].value; } bool XMLParser::is_empty() const { - return node_empty; } Error XMLParser::open_buffer(const Vector &p_buffer) { - ERR_FAIL_COND_V(p_buffer.size() == 0, ERR_INVALID_DATA); if (data) { @@ -484,7 +465,6 @@ Error XMLParser::open_buffer(const Vector &p_buffer) { } Error XMLParser::open(const String &p_path) { - Error err; FileAccess *file = FileAccess::open(p_path, FileAccess::READ, &err); @@ -508,7 +488,6 @@ Error XMLParser::open(const String &p_path) { } void XMLParser::skip_section() { - // skip if this element is empty anyway. if (is_empty()) return; @@ -526,7 +505,6 @@ void XMLParser::skip_section() { } void XMLParser::close() { - if (data) memdelete_arr(data); data = NULL; @@ -538,12 +516,10 @@ void XMLParser::close() { } int XMLParser::get_current_line() const { - return 0; } XMLParser::XMLParser() { - data = NULL; close(); special_characters.push_back("&"); @@ -553,7 +529,6 @@ XMLParser::XMLParser() { special_characters.push_back("'apos;"); } XMLParser::~XMLParser() { - if (data) memdelete_arr(data); } diff --git a/core/io/xml_parser.h b/core/io/xml_parser.h index cdf2e416aa3..8fecc9cd580 100644 --- a/core/io/xml_parser.h +++ b/core/io/xml_parser.h @@ -41,7 +41,6 @@ */ class XMLParser : public Reference { - GDCLASS(XMLParser, Reference); public: diff --git a/core/io/zip_io.cpp b/core/io/zip_io.cpp index b7359c1b0ba..29c7e58ccf4 100644 --- a/core/io/zip_io.cpp +++ b/core/io/zip_io.cpp @@ -31,7 +31,6 @@ #include "zip_io.h" void *zipio_open(void *data, const char *p_fname, int mode) { - FileAccess *&f = *(FileAccess **)data; String fname; @@ -40,7 +39,6 @@ void *zipio_open(void *data, const char *p_fname, int mode) { if (mode & ZLIB_FILEFUNC_MODE_WRITE) { f = FileAccess::open(fname, FileAccess::WRITE); } else { - f = FileAccess::open(fname, FileAccess::READ); } @@ -51,31 +49,26 @@ void *zipio_open(void *data, const char *p_fname, int mode) { } uLong zipio_read(void *data, void *fdata, void *buf, uLong size) { - FileAccess *f = *(FileAccess **)data; return f->get_buffer((uint8_t *)buf, size); } uLong zipio_write(voidpf opaque, voidpf stream, const void *buf, uLong size) { - FileAccess *f = *(FileAccess **)opaque; f->store_buffer((uint8_t *)buf, size); return size; } long zipio_tell(voidpf opaque, voidpf stream) { - FileAccess *f = *(FileAccess **)opaque; return f->get_position(); } long zipio_seek(voidpf opaque, voidpf stream, uLong offset, int origin) { - FileAccess *f = *(FileAccess **)opaque; int pos = offset; switch (origin) { - case ZLIB_FILEFUNC_SEEK_CUR: pos = f->get_position() + offset; break; @@ -91,7 +84,6 @@ long zipio_seek(voidpf opaque, voidpf stream, uLong offset, int origin) { } int zipio_close(voidpf opaque, voidpf stream) { - FileAccess *&f = *(FileAccess **)opaque; if (f) { f->close(); @@ -102,25 +94,21 @@ int zipio_close(voidpf opaque, voidpf stream) { } int zipio_testerror(voidpf opaque, voidpf stream) { - FileAccess *f = *(FileAccess **)opaque; return (f && f->get_error() != OK) ? 1 : 0; } voidpf zipio_alloc(voidpf opaque, uInt items, uInt size) { - voidpf ptr = memalloc(items * size); memset(ptr, 0, items * size); return ptr; } void zipio_free(voidpf opaque, voidpf address) { - memfree(address); } zlib_filefunc_def zipio_create_io_from_file(FileAccess **p_file) { - zlib_filefunc_def io; io.opaque = p_file; io.zopen_file = zipio_open; diff --git a/core/list.h b/core/list.h index becf9e2aac7..e525bdec96a 100644 --- a/core/list.h +++ b/core/list.h @@ -49,7 +49,6 @@ class List { public: class Element { - private: friend class List; @@ -63,14 +62,12 @@ public: * Get NEXT Element iterator, for constant lists. */ _FORCE_INLINE_ const Element *next() const { - return next_ptr; }; /** * Get NEXT Element iterator, */ _FORCE_INLINE_ Element *next() { - return next_ptr; }; @@ -78,14 +75,12 @@ public: * Get PREV Element iterator, for constant lists. */ _FORCE_INLINE_ const Element *prev() const { - return prev_ptr; }; /** * Get PREV Element iterator, */ _FORCE_INLINE_ Element *prev() { - return prev_ptr; }; @@ -99,7 +94,6 @@ public: * operator->, for using as iterator->, when iterators are defined on stack, for constant lists. */ _FORCE_INLINE_ const T *operator->() const { - return &value; }; /** @@ -135,7 +129,6 @@ public: }; void erase() { - data->erase(this); } @@ -148,13 +141,11 @@ public: private: struct _Data { - Element *first; Element *last; int size_cache; bool erase(const Element *p_I) { - ERR_FAIL_COND_V(!p_I, false); ERR_FAIL_COND_V(p_I->data != this, false); @@ -185,7 +176,6 @@ public: * return a const iterator to the beginning of the list. */ _FORCE_INLINE_ const Element *front() const { - return _data ? _data->first : 0; }; @@ -200,7 +190,6 @@ public: * return a const iterator to the last member of the list. */ _FORCE_INLINE_ const Element *back() const { - return _data ? _data->last : 0; }; @@ -208,7 +197,6 @@ public: * return an iterator to the last member of the list. */ _FORCE_INLINE_ Element *back() { - return _data ? _data->last : 0; }; @@ -216,9 +204,7 @@ public: * store a new element at the end of the list */ Element *push_back(const T &value) { - if (!_data) { - _data = memnew_allocator(_Data, A); _data->first = NULL; _data->last = NULL; @@ -233,7 +219,6 @@ public: n->data = _data; if (_data->last) { - _data->last->next_ptr = n; } @@ -248,7 +233,6 @@ public: }; void pop_back() { - if (_data && _data->last) erase(_data->last); } @@ -257,9 +241,7 @@ public: * store a new element at the beginning of the list */ Element *push_front(const T &value) { - if (!_data) { - _data = memnew_allocator(_Data, A); _data->first = NULL; _data->last = NULL; @@ -273,7 +255,6 @@ public: n->data = _data; if (_data->first) { - _data->first->prev_ptr = n; } @@ -288,7 +269,6 @@ public: }; void pop_front() { - if (_data && _data->first) erase(_data->first); } @@ -350,7 +330,6 @@ public: */ template Element *find(const T_v &p_val) { - Element *it = front(); while (it) { if (it->value == p_val) @@ -365,7 +344,6 @@ public: * erase an element in the list, by iterator pointing to it. Return true if it was found/erased. */ bool erase(const Element *p_I) { - if (_data) { bool ret = _data->erase(p_I); @@ -384,7 +362,6 @@ public: * erase the first element in the list, that contains value */ bool erase(const T &value) { - Element *I = find(value); return erase(I); }; @@ -393,7 +370,6 @@ public: * return whether the list is empty */ _FORCE_INLINE_ bool empty() const { - return (!_data || !_data->size_cache); } @@ -401,19 +377,16 @@ public: * clear the list */ void clear() { - while (front()) { erase(front()); }; }; _FORCE_INLINE_ int size() const { - return _data ? _data->size_cache : 0; } void swap(Element *p_A, Element *p_B) { - ERR_FAIL_COND(!p_A || !p_B); ERR_FAIL_COND(p_A->data != _data); ERR_FAIL_COND(p_B->data != _data); @@ -455,26 +428,21 @@ public: * copy the list */ void operator=(const List &p_list) { - clear(); const Element *it = p_list.front(); while (it) { - push_back(it->get()); it = it->next(); } } T &operator[](int p_index) { - CRASH_BAD_INDEX(p_index, size()); Element *I = front(); int c = 0; while (I) { - if (c == p_index) { - return I->get(); } I = I->next(); @@ -485,15 +453,12 @@ public: } const T &operator[](int p_index) const { - CRASH_BAD_INDEX(p_index, size()); const Element *I = front(); int c = 0; while (I) { - if (c == p_index) { - return I->get(); } I = I->next(); @@ -504,7 +469,6 @@ public: } void move_to_back(Element *p_I) { - ERR_FAIL_COND(p_I->data != _data); if (!p_I->next_ptr) return; @@ -528,12 +492,10 @@ public: } void invert() { - int s = size() / 2; Element *F = front(); Element *B = back(); for (int i = 0; i < s; i++) { - SWAP(F->value, B->value); F = F->next(); B = B->prev(); @@ -541,7 +503,6 @@ public: } void move_to_front(Element *p_I) { - ERR_FAIL_COND(p_I->data != _data); if (!p_I->prev_ptr) return; @@ -565,7 +526,6 @@ public: } void move_before(Element *value, Element *where) { - if (value->prev_ptr) { value->prev_ptr->next_ptr = value->next_ptr; } else { @@ -600,13 +560,11 @@ public: */ void sort() { - sort_custom>(); } template void sort_custom_inplace() { - if (size() < 2) return; @@ -615,18 +573,15 @@ public: Element *to = from; while (current) { - Element *next = current->next_ptr; if (from != current) { - current->prev_ptr = NULL; current->next_ptr = from; Element *find = from; C less; while (find && less(find->value, current->value)) { - current->prev_ptr = find; current->next_ptr = find->next_ptr; find = find->next_ptr; @@ -642,7 +597,6 @@ public: else to = current; } else { - current->prev_ptr = NULL; current->next_ptr = NULL; } @@ -655,17 +609,14 @@ public: template struct AuxiliaryComparator { - C compare; _FORCE_INLINE_ bool operator()(const Element *a, const Element *b) const { - return compare(a->value, b->value); } }; template void sort_custom() { - //this version uses auxiliary memory for speed. //if you don't want to use auxiliary memory, use the in_place version @@ -677,7 +628,6 @@ public: int idx = 0; for (Element *E = front(); E; E = E->next_ptr) { - aux_buffer[idx] = E; idx++; } @@ -694,7 +644,6 @@ public: aux_buffer[s - 1]->next_ptr = NULL; for (int i = 1; i < s - 1; i++) { - aux_buffer[i]->prev_ptr = aux_buffer[i - 1]; aux_buffer[i]->next_ptr = aux_buffer[i + 1]; } @@ -710,11 +659,9 @@ public: * copy constructor for the list */ List(const List &p_list) { - _data = NULL; const Element *it = p_list.front(); while (it) { - push_back(it->get()); it = it->next(); } @@ -726,7 +673,6 @@ public: ~List() { clear(); if (_data) { - ERR_FAIL_COND(_data->size_cache); memdelete_allocator<_Data, A>(_data); } diff --git a/core/map.h b/core/map.h index 96e25c8a742..1493b3a46e5 100644 --- a/core/map.h +++ b/core/map.h @@ -39,7 +39,6 @@ template , class A = DefaultAllocator> class Map { - enum Color { RED, BLACK @@ -48,7 +47,6 @@ class Map { public: class Element { - private: friend class Map; int color; @@ -63,19 +61,15 @@ public: public: const Element *next() const { - return _next; } Element *next() { - return _next; } const Element *prev() const { - return _prev; } Element *prev() { - return _prev; } const K &key() const { @@ -105,7 +99,6 @@ public: private: struct _Data { - Element *_root; Element *_nil; int size_cache; @@ -123,14 +116,12 @@ private: } void _create_root() { - _root = memnew_allocator(Element, A); _root->parent = _root->left = _root->right = _nil; _root->color = BLACK; } void _free_root() { - if (_root) { memdelete_allocator(_root); _root = NULL; @@ -138,7 +129,6 @@ private: } ~_Data() { - _free_root(); #ifdef GLOBALNIL_DISABLED @@ -150,13 +140,11 @@ private: _Data _data; inline void _set_color(Element *p_node, int p_color) { - ERR_FAIL_COND(p_node == _data._nil && p_color == RED); p_node->color = p_color; } inline void _rotate_left(Element *p_node) { - Element *r = p_node->right; p_node->right = r->left; if (r->left != _data._nil) @@ -172,7 +160,6 @@ private: } inline void _rotate_right(Element *p_node) { - Element *l = p_node->left; p_node->left = l->right; if (l->right != _data._nil) @@ -188,18 +175,15 @@ private: } inline Element *_successor(Element *p_node) const { - Element *node = p_node; if (node->right != _data._nil) { - node = node->right; while (node->left != _data._nil) { /* returns the minimum of the right subtree of node */ node = node->left; } return node; } else { - while (node == node->parent->right) { node = node->parent; } @@ -214,14 +198,12 @@ private: Element *node = p_node; if (node->left != _data._nil) { - node = node->left; while (node->right != _data._nil) { /* returns the minimum of the left subtree of node */ node = node->right; } return node; } else { - while (node == node->parent->left) { node = node->parent; } @@ -233,7 +215,6 @@ private: } Element *_find(const K &p_key) const { - Element *node = _data._root->left; C less; @@ -250,7 +231,6 @@ private: } Element *_find_closest(const K &p_key) const { - Element *node = _data._root->left; Element *prev = NULL; C less; @@ -276,7 +256,6 @@ private: } void _insert_rb_fix(Element *p_new_node) { - Element *node = p_new_node; Element *nparent = node->parent; Element *ngrand_parent; @@ -325,13 +304,11 @@ private: } Element *_insert(const K &p_key, const V &p_value) { - Element *new_parent = _data._root; Element *node = _data._root->left; C less; while (node != _data._nil) { - new_parent = node; if (less(p_key, node->_key)) @@ -371,7 +348,6 @@ private: } void _erase_fix_rb(Element *p_node) { - Element *root = _data._root->left; Element *node = _data._nil; Element *sibling = p_node; @@ -433,7 +409,6 @@ private: } void _erase(Element *p_node) { - Element *rp = ((p_node->left == _data._nil) || (p_node->right == _data._nil)) ? p_node : p_node->_next; Element *node = (rp->left == _data._nil) ? rp->right : rp->left; @@ -454,7 +429,6 @@ private: } if (rp != p_node) { - ERR_FAIL_COND(rp == _data._nil); rp->left = p_node->left; @@ -484,7 +458,6 @@ private: } void _calculate_depth(Element *p_element, int &max_d, int d) const { - if (p_element == _data._nil) return; @@ -496,7 +469,6 @@ private: } void _cleanup_tree(Element *p_element) { - if (p_element == _data._nil) return; @@ -506,18 +478,15 @@ private: } void _copy_from(const Map &p_map) { - clear(); // not the fastest way, but safeset to write. for (Element *I = p_map.front(); I; I = I->next()) { - insert(I->key(), I->value()); } } public: const Element *find(const K &p_key) const { - if (!_data._root) return NULL; @@ -526,7 +495,6 @@ public: } Element *find(const K &p_key) { - if (!_data._root) return NULL; @@ -535,7 +503,6 @@ public: } const Element *find_closest(const K &p_key) const { - if (!_data._root) return NULL; @@ -544,7 +511,6 @@ public: } Element *find_closest(const K &p_key) { - if (!_data._root) return NULL; @@ -553,19 +519,16 @@ public: } bool has(const K &p_key) const { - return find(p_key) != NULL; } Element *insert(const K &p_key, const V &p_value) { - if (!_data._root) _data._create_root(); return _insert(p_key, p_value); } void erase(Element *p_element) { - if (!_data._root || !p_element) return; @@ -575,7 +538,6 @@ public: } bool erase(const K &p_key) { - if (!_data._root) return false; @@ -590,7 +552,6 @@ public: } const V &operator[](const K &p_key) const { - CRASH_COND(!_data._root); const Element *e = find(p_key); CRASH_COND(!e); @@ -598,7 +559,6 @@ public: } V &operator[](const K &p_key) { - if (!_data._root) _data._create_root(); @@ -610,7 +570,6 @@ public: } Element *front() const { - if (!_data._root) return NULL; @@ -625,7 +584,6 @@ public: } Element *back() const { - if (!_data._root) return NULL; @@ -653,7 +611,6 @@ public: } void clear() { - if (!_data._root) return; @@ -664,12 +621,10 @@ public: } void operator=(const Map &p_map) { - _copy_from(p_map); } Map(const Map &p_map) { - _copy_from(p_map); } @@ -677,7 +632,6 @@ public: } ~Map() { - clear(); } }; diff --git a/core/math/a_star.cpp b/core/math/a_star.cpp index b9a3bad372e..ed1937c32be 100644 --- a/core/math/a_star.cpp +++ b/core/math/a_star.cpp @@ -35,7 +35,6 @@ #include "scene/scene_string_names.h" int AStar::get_available_point_id() const { - if (points.empty()) { return 1; } @@ -54,7 +53,6 @@ int AStar::get_available_point_id() const { } void AStar::add_point(int p_id, const Vector3 &p_pos, real_t p_weight_scale) { - ERR_FAIL_COND(p_id < 0); ERR_FAIL_COND(p_weight_scale < 1); @@ -78,7 +76,6 @@ void AStar::add_point(int p_id, const Vector3 &p_pos, real_t p_weight_scale) { } Vector3 AStar::get_point_position(int p_id) const { - Point *p; bool p_exists = points.lookup(p_id, p); ERR_FAIL_COND_V(!p_exists, Vector3()); @@ -87,7 +84,6 @@ Vector3 AStar::get_point_position(int p_id) const { } void AStar::set_point_position(int p_id, const Vector3 &p_pos) { - Point *p; bool p_exists = points.lookup(p_id, p); ERR_FAIL_COND(!p_exists); @@ -96,7 +92,6 @@ void AStar::set_point_position(int p_id, const Vector3 &p_pos) { } real_t AStar::get_point_weight_scale(int p_id) const { - Point *p; bool p_exists = points.lookup(p_id, p); ERR_FAIL_COND_V(!p_exists, 0); @@ -105,7 +100,6 @@ real_t AStar::get_point_weight_scale(int p_id) const { } void AStar::set_point_weight_scale(int p_id, real_t p_weight_scale) { - Point *p; bool p_exists = points.lookup(p_id, p); ERR_FAIL_COND(!p_exists); @@ -115,13 +109,11 @@ void AStar::set_point_weight_scale(int p_id, real_t p_weight_scale) { } void AStar::remove_point(int p_id) { - Point *p; bool p_exists = points.lookup(p_id, p); ERR_FAIL_COND(!p_exists); for (OAHashMap::Iterator it = p->neighbours.iter(); it.valid; it = p->neighbours.next_iter(it)) { - Segment s(p_id, (*it.key)); segments.erase(s); @@ -130,7 +122,6 @@ void AStar::remove_point(int p_id) { } for (OAHashMap::Iterator it = p->unlinked_neighbours.iter(); it.valid; it = p->unlinked_neighbours.next_iter(it)) { - Segment s(p_id, (*it.key)); segments.erase(s); @@ -144,7 +135,6 @@ void AStar::remove_point(int p_id) { } void AStar::connect_points(int p_id, int p_with_id, bool bidirectional) { - ERR_FAIL_COND(p_id == p_with_id); Point *a; @@ -182,7 +172,6 @@ void AStar::connect_points(int p_id, int p_with_id, bool bidirectional) { } void AStar::disconnect_points(int p_id, int p_with_id, bool bidirectional) { - Point *a; bool a_exists = points.lookup(p_id, a); ERR_FAIL_COND(!a_exists); @@ -221,12 +210,10 @@ void AStar::disconnect_points(int p_id, int p_with_id, bool bidirectional) { } bool AStar::has_point(int p_id) const { - return points.has(p_id); } Array AStar::get_points() { - Array point_list; for (OAHashMap::Iterator it = points.iter(); it.valid; it = points.next_iter(it)) { @@ -237,7 +224,6 @@ Array AStar::get_points() { } PoolVector AStar::get_point_connections(int p_id) { - Point *p; bool p_exists = points.lookup(p_id, p); ERR_FAIL_COND_V(!p_exists, PoolVector()); @@ -252,7 +238,6 @@ PoolVector AStar::get_point_connections(int p_id) { } bool AStar::are_points_connected(int p_id, int p_with_id, bool bidirectional) const { - Segment s(p_id, p_with_id); const Set::Element *element = segments.find(s); @@ -261,7 +246,6 @@ bool AStar::are_points_connected(int p_id, int p_with_id, bool bidirectional) co } void AStar::clear() { - last_free_id = 0; for (OAHashMap::Iterator it = points.iter(); it.valid; it = points.next_iter(it)) { memdelete(*(it.value)); @@ -285,12 +269,10 @@ void AStar::reserve_space(int p_num_nodes) { } int AStar::get_closest_point(const Vector3 &p_point, bool p_include_disabled) const { - int closest_id = -1; 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) continue; // Disabled points should not be considered. @@ -311,12 +293,10 @@ int AStar::get_closest_point(const Vector3 &p_point, bool p_include_disabled) co } Vector3 AStar::get_closest_position_in_segment(const Vector3 &p_point) const { - real_t closest_dist = 1e20; Vector3 closest_point; for (const Set::Element *E = segments.front(); E; E = E->next()) { - Point *from_point = nullptr, *to_point = nullptr; points.lookup(E->get().u, from_point); points.lookup(E->get().v, to_point); @@ -333,7 +313,6 @@ Vector3 AStar::get_closest_position_in_segment(const Vector3 &p_point) const { Vector3 p = Geometry::get_closest_point_to_segment(p_point, segment); real_t d = p_point.distance_squared_to(p); if (d < closest_dist) { - closest_point = p; closest_dist = d; } @@ -343,7 +322,6 @@ 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) @@ -359,7 +337,6 @@ bool AStar::_solve(Point *begin_point, Point *end_point) { open_list.push_back(begin_point); while (!open_list.empty()) { - Point *p = open_list[0]; // The currently processed point if (p == end_point) { @@ -372,7 +349,6 @@ bool AStar::_solve(Point *begin_point, Point *end_point) { p->closed_pass = pass; // Mark the point as closed for (OAHashMap::Iterator it = p->neighbours.iter(); it.valid; it = p->neighbours.next_iter(it)) { - Point *e = *(it.value); // The neighbour point if (!e->enabled || e->closed_pass == pass) { @@ -407,7 +383,6 @@ 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)) return get_script_instance()->call(SceneStringNames::get_singleton()->_estimate_cost, p_from_id, p_to_id); @@ -423,7 +398,6 @@ 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)) return get_script_instance()->call(SceneStringNames::get_singleton()->_compute_cost, p_from_id, p_to_id); @@ -439,7 +413,6 @@ real_t AStar::_compute_cost(int p_from_id, int p_to_id) { } PoolVector AStar::get_point_path(int p_from_id, int p_to_id) { - Point *a; bool from_exists = points.lookup(p_from_id, a); ERR_FAIL_COND_V(!from_exists, PoolVector()); @@ -488,7 +461,6 @@ PoolVector AStar::get_point_path(int p_from_id, int p_to_id) { } PoolVector AStar::get_id_path(int p_from_id, int p_to_id) { - Point *a; bool from_exists = points.lookup(p_from_id, a); ERR_FAIL_COND_V(!from_exists, PoolVector()); @@ -537,7 +509,6 @@ PoolVector AStar::get_id_path(int p_from_id, int p_to_id) { } void AStar::set_point_disabled(int p_id, bool p_disabled) { - Point *p; bool p_exists = points.lookup(p_id, p); ERR_FAIL_COND(!p_exists); @@ -546,7 +517,6 @@ void AStar::set_point_disabled(int p_id, bool p_disabled) { } bool AStar::is_point_disabled(int p_id) const { - Point *p; bool p_exists = points.lookup(p_id, p); ERR_FAIL_COND_V(!p_exists, false); @@ -555,7 +525,6 @@ bool AStar::is_point_disabled(int p_id) const { } void AStar::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_available_point_id"), &AStar::get_available_point_id); ClassDB::bind_method(D_METHOD("add_point", "id", "position", "weight_scale"), &AStar::add_point, DEFVAL(1.0)); ClassDB::bind_method(D_METHOD("get_point_position", "id"), &AStar::get_point_position); @@ -687,7 +656,6 @@ 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)) return get_script_instance()->call(SceneStringNames::get_singleton()->_estimate_cost, p_from_id, p_to_id); @@ -703,7 +671,6 @@ 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)) return get_script_instance()->call(SceneStringNames::get_singleton()->_compute_cost, p_from_id, p_to_id); @@ -719,7 +686,6 @@ real_t AStar2D::_compute_cost(int p_from_id, int p_to_id) { } PoolVector AStar2D::get_point_path(int p_from_id, int p_to_id) { - AStar::Point *a; bool from_exists = astar.points.lookup(p_from_id, a); ERR_FAIL_COND_V(!from_exists, PoolVector()); @@ -768,7 +734,6 @@ PoolVector AStar2D::get_point_path(int p_from_id, int p_to_id) { } PoolVector AStar2D::get_id_path(int p_from_id, int p_to_id) { - AStar::Point *a; bool from_exists = astar.points.lookup(p_from_id, a); ERR_FAIL_COND_V(!from_exists, PoolVector()); @@ -817,7 +782,6 @@ PoolVector 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) @@ -833,7 +797,6 @@ bool AStar2D::_solve(AStar::Point *begin_point, AStar::Point *end_point) { open_list.push_back(begin_point); while (!open_list.empty()) { - AStar::Point *p = open_list[0]; // The currently processed point if (p == end_point) { @@ -846,7 +809,6 @@ bool AStar2D::_solve(AStar::Point *begin_point, AStar::Point *end_point) { p->closed_pass = astar.pass; // Mark the point as closed for (OAHashMap::Iterator it = p->neighbours.iter(); it.valid; it = p->neighbours.next_iter(it)) { - AStar::Point *e = *(it.value); // The neighbour point if (!e->enabled || e->closed_pass == astar.pass) { @@ -881,7 +843,6 @@ bool AStar2D::_solve(AStar::Point *begin_point, AStar::Point *end_point) { } void AStar2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_available_point_id"), &AStar2D::get_available_point_id); ClassDB::bind_method(D_METHOD("add_point", "id", "position", "weight_scale"), &AStar2D::add_point, DEFVAL(1.0)); ClassDB::bind_method(D_METHOD("get_point_position", "id"), &AStar2D::get_point_position); diff --git a/core/math/a_star.h b/core/math/a_star.h index 01b9ff95401..4606ee1a244 100644 --- a/core/math/a_star.h +++ b/core/math/a_star.h @@ -41,12 +41,10 @@ */ class AStar : public Reference { - GDCLASS(AStar, Reference); friend class AStar2D; struct Point { - Point() : neighbours(4u), unlinked_neighbours(4u) {} diff --git a/core/math/aabb.cpp b/core/math/aabb.cpp index b7df2b55837..e227aced550 100644 --- a/core/math/aabb.cpp +++ b/core/math/aabb.cpp @@ -33,21 +33,17 @@ #include "core/print_string.h" real_t AABB::get_area() const { - return size.x * size.y * size.z; } bool AABB::operator==(const AABB &p_rval) const { - return ((position == p_rval.position) && (size == p_rval.size)); } bool AABB::operator!=(const AABB &p_rval) const { - return ((position != p_rval.position) || (size != p_rval.size)); } void AABB::merge_with(const AABB &p_aabb) { - Vector3 beg_1, beg_2; Vector3 end_1, end_2; Vector3 min, max; @@ -70,12 +66,10 @@ void AABB::merge_with(const AABB &p_aabb) { } bool AABB::is_equal_approx(const AABB &p_aabb) const { - return position.is_equal_approx(p_aabb.position) && size.is_equal_approx(p_aabb.size); } AABB AABB::intersection(const AABB &p_aabb) const { - Vector3 src_min = position; Vector3 src_max = position + size; Vector3 dst_min = p_aabb.position; @@ -86,7 +80,6 @@ AABB AABB::intersection(const AABB &p_aabb) const { if (src_min.x > dst_max.x || src_max.x < dst_min.x) return AABB(); 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; } @@ -94,7 +87,6 @@ AABB AABB::intersection(const AABB &p_aabb) const { if (src_min.y > dst_max.y || src_max.y < dst_min.y) return AABB(); 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; } @@ -102,7 +94,6 @@ AABB AABB::intersection(const AABB &p_aabb) const { if (src_min.z > dst_max.z || src_max.z < dst_min.z) return AABB(); 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; } @@ -111,7 +102,6 @@ AABB AABB::intersection(const AABB &p_aabb) const { } bool AABB::intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *r_clip, Vector3 *r_normal) const { - Vector3 c1, c2; Vector3 end = position + size; real_t near = -1e20; @@ -154,7 +144,6 @@ bool AABB::intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 * } bool AABB::intersects_segment(const Vector3 &p_from, const Vector3 &p_to, Vector3 *r_clip, Vector3 *r_normal) const { - real_t min = 0, max = 1; int axis = 0; real_t sign = 0; @@ -168,7 +157,6 @@ 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) return false; real_t length = seg_to - seg_from; @@ -177,7 +165,6 @@ bool AABB::intersects_segment(const Vector3 &p_from, const Vector3 &p_to, Vector csign = -1.0; } else { - if (seg_to > box_end || seg_from < box_begin) return false; real_t length = seg_to - seg_from; @@ -212,7 +199,6 @@ bool AABB::intersects_segment(const Vector3 &p_from, const Vector3 &p_to, Vector } bool AABB::intersects_plane(const Plane &p_plane) const { - Vector3 points[8] = { Vector3(position.x, position.y, position.z), Vector3(position.x, position.y, position.z + size.z), @@ -228,7 +214,6 @@ 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) over = true; else @@ -239,7 +224,6 @@ bool AABB::intersects_plane(const Plane &p_plane) const { } Vector3 AABB::get_longest_axis() const { - Vector3 axis(1, 0, 0); real_t max_size = size.x; @@ -255,7 +239,6 @@ Vector3 AABB::get_longest_axis() const { return axis; } int AABB::get_longest_axis_index() const { - int axis = 0; real_t max_size = size.x; @@ -272,7 +255,6 @@ int AABB::get_longest_axis_index() const { } Vector3 AABB::get_shortest_axis() const { - Vector3 axis(1, 0, 0); real_t max_size = size.x; @@ -288,7 +270,6 @@ Vector3 AABB::get_shortest_axis() const { return axis; } int AABB::get_shortest_axis_index() const { - int axis = 0; real_t max_size = size.x; @@ -305,7 +286,6 @@ int AABB::get_shortest_axis_index() const { } AABB AABB::merge(const AABB &p_with) const { - AABB aabb = *this; aabb.merge_with(p_with); return aabb; @@ -316,24 +296,19 @@ AABB AABB::expand(const Vector3 &p_vector) const { return aabb; } AABB AABB::grow(real_t p_by) const { - AABB aabb = *this; aabb.grow_by(p_by); return aabb; } void AABB::get_edge(int p_edge, Vector3 &r_from, Vector3 &r_to) const { - ERR_FAIL_INDEX(p_edge, 12); switch (p_edge) { - case 0: { - r_from = Vector3(position.x + size.x, position.y, position.z); r_to = Vector3(position.x, position.y, position.z); } break; case 1: { - r_from = Vector3(position.x + size.x, position.y, position.z + size.z); r_to = Vector3(position.x + size.x, position.y, position.z); } break; @@ -343,18 +318,15 @@ void AABB::get_edge(int p_edge, Vector3 &r_from, Vector3 &r_to) const { } break; case 3: { - r_from = Vector3(position.x, position.y, position.z); r_to = Vector3(position.x, position.y, position.z + size.z); } break; case 4: { - r_from = Vector3(position.x, position.y + size.y, position.z); r_to = Vector3(position.x + size.x, position.y + size.y, position.z); } break; case 5: { - r_from = Vector3(position.x + size.x, position.y + size.y, position.z); r_to = Vector3(position.x + size.x, position.y + size.y, position.z + size.z); } break; @@ -364,31 +336,26 @@ void AABB::get_edge(int p_edge, Vector3 &r_from, Vector3 &r_to) const { } break; case 7: { - r_from = Vector3(position.x, position.y + size.y, position.z + size.z); r_to = Vector3(position.x, position.y + size.y, position.z); } break; case 8: { - r_from = Vector3(position.x, position.y, position.z + size.z); r_to = Vector3(position.x, position.y + size.y, position.z + size.z); } break; case 9: { - r_from = Vector3(position.x, position.y, position.z); r_to = Vector3(position.x, position.y + size.y, position.z); } break; case 10: { - r_from = Vector3(position.x + size.x, position.y, position.z); r_to = Vector3(position.x + size.x, position.y + size.y, position.z); } break; case 11: { - r_from = Vector3(position.x + size.x, position.y, position.z + size.z); r_to = Vector3(position.x + size.x, position.y + size.y, position.z + size.z); @@ -397,6 +364,5 @@ void AABB::get_edge(int p_edge, Vector3 &r_from, Vector3 &r_to) const { } AABB::operator String() const { - return String() + position + " - " + size; } diff --git a/core/math/aabb.h b/core/math/aabb.h index 71dec61d755..1dfe25ef071 100644 --- a/core/math/aabb.h +++ b/core/math/aabb.h @@ -47,12 +47,10 @@ public: real_t get_area() const; /// get area _FORCE_INLINE_ bool has_no_area() const { - return (size.x <= 0 || size.y <= 0 || size.z <= 0); } _FORCE_INLINE_ bool has_no_surface() const { - return (size.x <= 0 && size.y <= 0 && size.z <= 0); } @@ -115,7 +113,6 @@ public: }; inline bool AABB::intersects(const AABB &p_aabb) const { - if (position.x >= (p_aabb.position.x + p_aabb.size.x)) return false; if ((position.x + size.x) <= p_aabb.position.x) @@ -133,7 +130,6 @@ inline bool AABB::intersects(const AABB &p_aabb) const { } inline bool AABB::intersects_inclusive(const AABB &p_aabb) const { - if (position.x > (p_aabb.position.x + p_aabb.size.x)) return false; if ((position.x + size.x) < p_aabb.position.x) @@ -151,7 +147,6 @@ inline bool AABB::intersects_inclusive(const AABB &p_aabb) const { } inline bool AABB::encloses(const AABB &p_aabb) const { - Vector3 src_min = position; Vector3 src_max = position + size; Vector3 dst_min = p_aabb.position; @@ -167,7 +162,6 @@ inline bool AABB::encloses(const AABB &p_aabb) const { } Vector3 AABB::get_support(const Vector3 &p_normal) const { - Vector3 half_extents = size * 0.5; Vector3 ofs = position + half_extents; @@ -179,7 +173,6 @@ Vector3 AABB::get_support(const Vector3 &p_normal) const { } Vector3 AABB::get_endpoint(int p_point) const { - switch (p_point) { case 0: return Vector3(position.x, position.y, position.z); @@ -203,7 +196,6 @@ Vector3 AABB::get_endpoint(int p_point) const { } bool AABB::intersects_convex_shape(const Plane *p_planes, int p_plane_count, const Vector3 *p_points, int p_point_count) const { - Vector3 half_extents = size * 0.5; Vector3 ofs = position + half_extents; @@ -224,7 +216,6 @@ bool AABB::intersects_convex_shape(const Plane *p_planes, int p_plane_count, con int bad_point_counts_negative[3] = { 0 }; for (int k = 0; k < 3; k++) { - for (int i = 0; i < p_point_count; i++) { if (p_points[i].coord[k] > ofs.coord[k] + half_extents.coord[k]) { bad_point_counts_positive[k]++; @@ -246,7 +237,6 @@ bool AABB::intersects_convex_shape(const Plane *p_planes, int p_plane_count, con } bool AABB::inside_convex_shape(const Plane *p_planes, int p_plane_count) const { - Vector3 half_extents = size * 0.5; Vector3 ofs = position + half_extents; @@ -265,7 +255,6 @@ bool AABB::inside_convex_shape(const Plane *p_planes, int p_plane_count) const { } bool AABB::has_point(const Vector3 &p_point) const { - if (p_point.x < position.x) return false; if (p_point.y < position.y) @@ -283,7 +272,6 @@ bool AABB::has_point(const Vector3 &p_point) const { } inline void AABB::expand_to(const Vector3 &p_vector) { - Vector3 begin = position; Vector3 end = position + size; @@ -306,7 +294,6 @@ inline void AABB::expand_to(const Vector3 &p_vector) { } void AABB::project_range_in_plane(const Plane &p_plane, real_t &r_min, real_t &r_max) const { - Vector3 half_extents(size.x * 0.5, size.y * 0.5, size.z * 0.5); Vector3 center(position.x + half_extents.x, position.y + half_extents.y, position.z + half_extents.z); @@ -317,7 +304,6 @@ void AABB::project_range_in_plane(const Plane &p_plane, real_t &r_min, real_t &r } inline real_t AABB::get_longest_axis_size() const { - real_t max_size = size.x; if (size.y > max_size) { @@ -332,7 +318,6 @@ inline real_t AABB::get_longest_axis_size() const { } inline real_t AABB::get_shortest_axis_size() const { - real_t max_size = size.x; if (size.y < max_size) { @@ -347,7 +332,6 @@ inline real_t AABB::get_shortest_axis_size() const { } bool AABB::smits_intersect_ray(const Vector3 &p_from, const Vector3 &p_dir, real_t t0, real_t t1) const { - real_t divx = 1.0 / p_dir.x; real_t divy = 1.0 / p_dir.y; real_t divz = 1.0 / p_dir.z; @@ -391,7 +375,6 @@ bool AABB::smits_intersect_ray(const Vector3 &p_from, const Vector3 &p_dir, real } void AABB::grow_by(real_t p_amount) { - position.x -= p_amount; position.y -= p_amount; position.z -= p_amount; diff --git a/core/math/audio_frame.h b/core/math/audio_frame.h index 73f9bdf4cc7..dd692f49f40 100644 --- a/core/math/audio_frame.h +++ b/core/math/audio_frame.h @@ -51,7 +51,6 @@ static const float AUDIO_PEAK_OFFSET = 0.0000000001f; static const float AUDIO_MIN_PEAK_DB = -200.0f; // linear2db(AUDIO_PEAK_OFFSET) struct AudioFrame { - //left and right samples float l, r; @@ -108,7 +107,6 @@ struct AudioFrame { } _FORCE_INLINE_ AudioFrame linear_interpolate(const AudioFrame &p_b, float p_t) const { - AudioFrame res = *this; res.l += (p_t * (p_b.l - l)); diff --git a/core/math/basis.cpp b/core/math/basis.cpp index c13d0902083..708b397c3e6 100644 --- a/core/math/basis.cpp +++ b/core/math/basis.cpp @@ -37,16 +37,13 @@ (elements[row1][col1] * elements[row2][col2] - elements[row1][col2] * elements[row2][col1]) void Basis::from_z(const Vector3 &p_z) { - if (Math::abs(p_z.z) > Math_SQRT12) { - // choose p in y-z plane real_t a = p_z[1] * p_z[1] + p_z[2] * p_z[2]; real_t k = 1.0 / Math::sqrt(a); elements[0] = Vector3(0, -p_z[2] * k, p_z[1] * k); elements[1] = Vector3(a * k, -p_z[0] * elements[0][2], p_z[0] * elements[0][1]); } else { - // choose p in x-y plane real_t a = p_z.x * p_z.x + p_z.y * p_z.y; real_t k = 1.0 / Math::sqrt(a); @@ -57,7 +54,6 @@ void Basis::from_z(const Vector3 &p_z) { } void Basis::invert() { - real_t co[3] = { cofac(1, 1, 2, 2), cofac(1, 2, 2, 0), cofac(1, 0, 2, 1) }; @@ -75,7 +71,6 @@ void Basis::invert() { } void Basis::orthonormalize() { - // Gram-Schmidt Process Vector3 x = get_axis(0); @@ -94,7 +89,6 @@ void Basis::orthonormalize() { } Basis Basis::orthonormalized() const { - Basis c = *this; c.orthonormalize(); return c; @@ -119,7 +113,6 @@ bool Basis::is_rotation() const { } bool Basis::is_symmetric() const { - 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)) @@ -131,7 +124,6 @@ bool Basis::is_symmetric() const { } Basis Basis::diagonalize() { - //NOTE: only implemented for symmetric matrices //with the Jacobi iterative method method #ifdef MATH_CHECKS @@ -192,21 +184,18 @@ Basis Basis::diagonalize() { } Basis Basis::inverse() const { - Basis inv = *this; inv.invert(); return inv; } void Basis::transpose() { - SWAP(elements[0][1], elements[1][0]); SWAP(elements[0][2], elements[2][0]); SWAP(elements[1][2], elements[2][1]); } Basis Basis::transposed() const { - Basis tr = *this; tr.transpose(); return tr; @@ -215,7 +204,6 @@ Basis Basis::transposed() const { // Multiplies the matrix from left by the scaling matrix: M -> S.M // See the comment for Basis::rotated for further explanation. void Basis::scale(const Vector3 &p_scale) { - elements[0][0] *= p_scale.x; elements[0][1] *= p_scale.x; elements[0][2] *= p_scale.x; @@ -247,7 +235,6 @@ Basis Basis::scaled_local(const Vector3 &p_scale) const { } Vector3 Basis::get_scale_abs() const { - return Vector3( Vector3(elements[0][0], elements[1][0], elements[2][0]).length(), Vector3(elements[0][1], elements[1][1], elements[2][1]).length(), @@ -328,7 +315,6 @@ void Basis::rotate_local(const Vector3 &p_axis, real_t p_phi) { *this = rotated_local(p_axis, p_phi); } Basis Basis::rotated_local(const Vector3 &p_axis, real_t p_phi) const { - return (*this) * Basis(p_axis, p_phi); } @@ -417,7 +403,6 @@ void Basis::get_rotation_axis_angle_local(Vector3 &p_axis, real_t &p_angle) cons // the angles in the decomposition R = X(a1).Y(a2).Z(a3) where Z(a) rotates // around the z-axis by a and so on. Vector3 Basis::get_euler_xyz() const { - // Euler angles in XYZ convention. // See https://en.wikipedia.org/wiki/Euler_angles#Rotation_matrix // @@ -458,7 +443,6 @@ Vector3 Basis::get_euler_xyz() const { // and similar for other axes. // The current implementation uses XYZ convention (Z is the first rotation). void Basis::set_euler_xyz(const Vector3 &p_euler) { - real_t c, s; c = Math::cos(p_euler.x); @@ -620,7 +604,6 @@ Vector3 Basis::get_euler_yxz() const { // and similar for other axes. // The current implementation uses YXZ convention (Z is the first rotation). void Basis::set_euler_yxz(const Vector3 &p_euler) { - real_t c, s; c = Math::cos(p_euler.x); @@ -734,12 +717,10 @@ void Basis::set_euler_zyx(const Vector3 &p_euler) { } bool Basis::is_equal_approx(const Basis &p_basis) const { - return elements[0].is_equal_approx(p_basis.elements[0]) && elements[1].is_equal_approx(p_basis.elements[1]) && elements[2].is_equal_approx(p_basis.elements[2]); } 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)) @@ -751,7 +732,6 @@ 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]) @@ -763,17 +743,13 @@ bool Basis::operator==(const Basis &p_matrix) const { } bool Basis::operator!=(const Basis &p_matrix) const { - return (!(*this == p_matrix)); } 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) mtx += ", "; @@ -785,7 +761,6 @@ Basis::operator String() const { } Quat Basis::get_quat() const { - #ifdef MATH_CHECKS ERR_FAIL_COND_V_MSG(!is_rotation(), Quat(), "Basis must be normalized in order to be casted to a Quaternion. Use get_rotation_quat() or call orthonormalized() instead."); #endif @@ -849,12 +824,10 @@ static const Basis _ortho_bases[24] = { }; int Basis::get_orthogonal_index() const { - //could be sped up if i come up with a way Basis orth = *this; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - real_t v = orth[i][j]; if (v > 0.5) v = 1.0; @@ -868,7 +841,6 @@ int Basis::get_orthogonal_index() const { } for (int i = 0; i < 24; i++) { - if (_ortho_bases[i] == orth) return i; } @@ -877,7 +849,6 @@ int Basis::get_orthogonal_index() const { } void Basis::set_orthogonal_index(int p_index) { - //there only exist 24 orthogonal bases in r3 ERR_FAIL_INDEX(p_index, 24); @@ -962,7 +933,6 @@ void Basis::get_axis_angle(Vector3 &r_axis, real_t &r_angle) const { } void Basis::set_quat(const Quat &p_quat) { - real_t d = p_quat.length_squared(); real_t s = 2.0 / d; real_t xs = p_quat.x * s, ys = p_quat.y * s, zs = p_quat.z * s; @@ -1034,7 +1004,6 @@ void Basis::set_diagonal(const Vector3 &p_diag) { } Basis Basis::slerp(const Basis &p_to, const real_t &p_weight) const { - //consider scale Quat from(*this); Quat to(p_to); diff --git a/core/math/basis.h b/core/math/basis.h index 83b51e5abbd..b65dff84de6 100644 --- a/core/math/basis.h +++ b/core/math/basis.h @@ -43,11 +43,9 @@ public: }; _FORCE_INLINE_ const Vector3 &operator[](int axis) const { - return elements[axis]; } _FORCE_INLINE_ Vector3 &operator[](int axis) { - return elements[axis]; } @@ -179,7 +177,6 @@ public: /* create / set */ _FORCE_INLINE_ void set(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz) { - elements[0][0] = xx; elements[0][1] = xy; elements[0][2] = xz; @@ -191,18 +188,15 @@ public: elements[2][2] = zz; } _FORCE_INLINE_ void set(const Vector3 &p_x, const Vector3 &p_y, const Vector3 &p_z) { - set_axis(0, p_x); set_axis(1, p_y); set_axis(2, p_z); } _FORCE_INLINE_ Vector3 get_column(int i) const { - return Vector3(elements[0][i], elements[1][i], elements[2][i]); } _FORCE_INLINE_ Vector3 get_row(int i) const { - return Vector3(elements[i][0], elements[i][1], elements[i][2]); } _FORCE_INLINE_ Vector3 get_main_diagonal() const { @@ -234,7 +228,6 @@ public: elements[0].z * m[0].z + elements[1].z * m[1].z + elements[2].z * m[2].z); } Basis(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz) { - set(xx, xy, xz, yx, yy, yz, zx, zy, zz); } @@ -265,7 +258,6 @@ public: }; _FORCE_INLINE_ void Basis::operator*=(const Basis &p_matrix) { - set( p_matrix.tdotx(elements[0]), p_matrix.tdoty(elements[0]), p_matrix.tdotz(elements[0]), p_matrix.tdotx(elements[1]), p_matrix.tdoty(elements[1]), p_matrix.tdotz(elements[1]), @@ -273,7 +265,6 @@ _FORCE_INLINE_ void Basis::operator*=(const Basis &p_matrix) { } _FORCE_INLINE_ Basis Basis::operator*(const Basis &p_matrix) const { - return Basis( p_matrix.tdotx(elements[0]), p_matrix.tdoty(elements[0]), p_matrix.tdotz(elements[0]), p_matrix.tdotx(elements[1]), p_matrix.tdoty(elements[1]), p_matrix.tdotz(elements[1]), @@ -281,49 +272,42 @@ _FORCE_INLINE_ Basis Basis::operator*(const Basis &p_matrix) const { } _FORCE_INLINE_ void Basis::operator+=(const Basis &p_matrix) { - elements[0] += p_matrix.elements[0]; elements[1] += p_matrix.elements[1]; elements[2] += p_matrix.elements[2]; } _FORCE_INLINE_ Basis Basis::operator+(const Basis &p_matrix) const { - Basis ret(*this); ret += p_matrix; return ret; } _FORCE_INLINE_ void Basis::operator-=(const Basis &p_matrix) { - elements[0] -= p_matrix.elements[0]; elements[1] -= p_matrix.elements[1]; elements[2] -= p_matrix.elements[2]; } _FORCE_INLINE_ Basis Basis::operator-(const Basis &p_matrix) const { - Basis ret(*this); ret -= p_matrix; return ret; } _FORCE_INLINE_ void Basis::operator*=(real_t p_val) { - elements[0] *= p_val; elements[1] *= p_val; elements[2] *= p_val; } _FORCE_INLINE_ Basis Basis::operator*(real_t p_val) const { - Basis ret(*this); ret *= p_val; return ret; } Vector3 Basis::xform(const Vector3 &p_vector) const { - return Vector3( elements[0].dot(p_vector), elements[1].dot(p_vector), @@ -331,7 +315,6 @@ Vector3 Basis::xform(const Vector3 &p_vector) const { } Vector3 Basis::xform_inv(const Vector3 &p_vector) const { - return Vector3( (elements[0][0] * p_vector.x) + (elements[1][0] * p_vector.y) + (elements[2][0] * p_vector.z), (elements[0][1] * p_vector.x) + (elements[1][1] * p_vector.y) + (elements[2][1] * p_vector.z), @@ -339,7 +322,6 @@ Vector3 Basis::xform_inv(const Vector3 &p_vector) const { } real_t Basis::determinant() const { - return elements[0][0] * (elements[1][1] * elements[2][2] - elements[2][1] * elements[1][2]) - elements[1][0] * (elements[0][1] * elements[2][2] - elements[2][1] * elements[0][2]) + elements[2][0] * (elements[0][1] * elements[1][2] - elements[1][1] * elements[0][2]); diff --git a/core/math/bsp_tree.cpp b/core/math/bsp_tree.cpp index 28af6ec3f21..7be7d5aff05 100644 --- a/core/math/bsp_tree.cpp +++ b/core/math/bsp_tree.cpp @@ -34,11 +34,9 @@ #include "core/print_string.h" void BSP_Tree::from_aabb(const AABB &p_aabb) { - planes.clear(); for (int i = 0; i < 3; i++) { - Vector3 n; n[i] = 1; planes.push_back(Plane(n, p_aabb.position[i] + p_aabb.size[i])); @@ -48,7 +46,6 @@ void BSP_Tree::from_aabb(const AABB &p_aabb) { nodes.clear(); for (int i = 0; i < 6; i++) { - Node n; n.plane = i; n.under = (i == 0) ? UNDER_LEAF : i - 1; @@ -61,21 +58,17 @@ void BSP_Tree::from_aabb(const AABB &p_aabb) { } Vector BSP_Tree::get_nodes() const { - return nodes; } Vector BSP_Tree::get_planes() const { - return planes; } AABB BSP_Tree::get_aabb() const { - return aabb; } int BSP_Tree::_get_points_inside(int p_node, const Vector3 *p_points, int *p_indices, const Vector3 &p_center, const Vector3 &p_half_extents, int p_indices_count) const { - const Node *node = &nodes[p_node]; const Plane &p = planes[node->plane]; @@ -96,11 +89,9 @@ int BSP_Tree::_get_points_inside(int p_node, const Vector3 *p_points, int *p_ind //sort points, so the are under first, over last for (int i = 0; i < p_indices_count; i++) { - int index = p_indices[i]; if (p.is_point_over(p_points[index])) { - // kind of slow (but cache friendly), should try something else, // but this is a corner case most of the time @@ -137,7 +128,6 @@ int BSP_Tree::_get_points_inside(int p_node, const Vector3 *p_points, int *p_ind } else if (dist_min > 0) { //all points over plane if (node->over == OVER_LEAF) { - return 0; // all these points are not visible } @@ -145,7 +135,6 @@ int BSP_Tree::_get_points_inside(int p_node, const Vector3 *p_points, int *p_ind } else { //all points behind plane if (node->under == UNDER_LEAF) { - return p_indices_count; // all these points are visible } return _get_points_inside(node->under, p_points, p_indices, p_center, p_half_extents, p_indices_count); @@ -153,7 +142,6 @@ int BSP_Tree::_get_points_inside(int p_node, const Vector3 *p_points, int *p_ind } int BSP_Tree::get_points_inside(const Vector3 *p_points, int p_point_count) const { - if (nodes.size() == 0) return 0; @@ -169,7 +157,6 @@ int BSP_Tree::get_points_inside(const Vector3 *p_points, int p_point_count) cons return 0; for (int i = 0; i < p_point_count; i++) { - const Vector3 &point = p_points[i]; if (!aabb.has_point(point)) { continue; @@ -180,7 +167,6 @@ int BSP_Tree::get_points_inside(const Vector3 *p_points, int p_point_count) cons bool pass = false; while (true) { - if (idx == OVER_LEAF) { pass = false; break; @@ -216,7 +202,6 @@ int BSP_Tree::get_points_inside(const Vector3 *p_points, int p_point_count) cons AABB bounds; for (int i = 0; i < p_point_count; i++) { - indices[i] = i; if (i == 0) bounds.pos = p_points[i]; @@ -230,7 +215,6 @@ int BSP_Tree::get_points_inside(const Vector3 *p_points, int p_point_count) cons } bool BSP_Tree::point_is_inside(const Vector3 &p_point) const { - if (!aabb.has_point(p_point)) { return false; } @@ -246,12 +230,10 @@ bool BSP_Tree::point_is_inside(const Vector3 &p_point) const { int idx = node_count - 1; while (true) { - if (idx == OVER_LEAF) { return false; } if (idx == UNDER_LEAF) { - return true; } @@ -272,7 +254,6 @@ bool BSP_Tree::point_is_inside(const Vector3 &p_point) const { } static int _bsp_find_best_half_plane(const Face3 *p_faces, const Vector &p_indices, real_t p_tolerance) { - int ic = p_indices.size(); const int *indices = p_indices.ptr(); @@ -282,14 +263,12 @@ static int _bsp_find_best_half_plane(const Face3 *p_faces, const Vector &p_ // Loop to find the polygon that best divides the set. for (int i = 0; i < ic; i++) { - const Face3 &f = p_faces[indices[i]]; Plane p = f.get_plane(); int num_over = 0, num_under = 0, num_spanning = 0; for (int j = 0; j < ic; j++) { - if (i == j) continue; @@ -297,11 +276,9 @@ static int _bsp_find_best_half_plane(const Face3 *p_faces, const Vector &p_ int over = 0, under = 0; for (int k = 0; k < 3; k++) { - real_t d = p.distance_to(g.vertex[j]); if (Math::abs(d) > p_tolerance) { - if (d > 0) over++; else @@ -327,7 +304,6 @@ static int _bsp_find_best_half_plane(const Face3 *p_faces, const Vector &p_ //printf("plane %i, %i over, %i under, %i spanning, cost is %g\n",i,num_over,num_under,num_spanning,plane_cost); if (plane_cost < best_plane_cost) { - best_plane = i; best_plane_cost = plane_cost; } @@ -337,7 +313,6 @@ static int _bsp_find_best_half_plane(const Face3 *p_faces, const Vector &p_ } static int _bsp_create_node(const Face3 *p_faces, const Vector &p_indices, Vector &p_planes, Vector &p_nodes, real_t p_tolerance) { - ERR_FAIL_COND_V(p_nodes.size() == BSP_Tree::MAX_NODES, -1); // should not reach here @@ -357,7 +332,6 @@ static int _bsp_create_node(const Face3 *p_faces, const Vector &p_indices, Plane divisor_plane = p_faces[indices[divisor_idx]].get_plane(); for (int i = 0; i < ic; i++) { - if (i == divisor_idx) continue; @@ -372,10 +346,8 @@ static int _bsp_create_node(const Face3 *p_faces, const Vector &p_indices, int under_count = 0; for (int j = 0; j < 3; j++) { - real_t d = divisor_plane.distance_to(f.vertex[j]); if (Math::abs(d) > p_tolerance) { - if (d > 0) over_count++; else @@ -411,7 +383,6 @@ static int _bsp_create_node(const Face3 *p_faces, const Vector &p_indices, int divisor_plane_idx = -1; for (int i = 0; i < p_planes.size(); i++) { - if (p_planes[i].is_equal_approx(divisor_plane)) { divisor_plane_idx = i; break; @@ -419,7 +390,6 @@ static int _bsp_create_node(const Face3 *p_faces, const Vector &p_indices, } if (divisor_plane_idx == -1) { - ERR_FAIL_COND_V(p_planes.size() == BSP_Tree::MAX_PLANES, -1); divisor_plane_idx = p_planes.size(); p_planes.push_back(divisor_plane); @@ -436,7 +406,6 @@ static int _bsp_create_node(const Face3 *p_faces, const Vector &p_indices, } BSP_Tree::operator Variant() const { - Dictionary d; d["error_radius"] = error_radius; @@ -444,7 +413,6 @@ BSP_Tree::operator Variant() const { plane_values.resize(planes.size() * 4); for (int i = 0; i < planes.size(); i++) { - plane_values.write[i * 4 + 0] = planes[i].normal.x; plane_values.write[i * 4 + 1] = planes[i].normal.y; plane_values.write[i * 4 + 2] = planes[i].normal.z; @@ -457,7 +425,6 @@ BSP_Tree::operator Variant() const { dst_nodes.resize(nodes.size() * 3); for (int i = 0; i < nodes.size(); i++) { - dst_nodes.set(i * 3 + 0, nodes[i].over); dst_nodes.set(i * 3 + 1, nodes[i].under); dst_nodes.set(i * 3 + 2, nodes[i].plane); @@ -473,7 +440,6 @@ BSP_Tree::BSP_Tree() { } BSP_Tree::BSP_Tree(const Variant &p_variant) { - Dictionary d = p_variant; ERR_FAIL_COND(!d.has("nodes")); ERR_FAIL_COND(!d.has("planes")); @@ -484,7 +450,6 @@ BSP_Tree::BSP_Tree(const Variant &p_variant) { ERR_FAIL_COND(src_nodes.size() % 3); if (d["planes"].get_type() == Variant::POOL_REAL_ARRAY) { - PoolVector src_planes = d["planes"]; int plane_count = src_planes.size(); ERR_FAIL_COND(plane_count % 4); @@ -493,7 +458,6 @@ BSP_Tree::BSP_Tree(const Variant &p_variant) { if (plane_count) { PoolVector::Read r = src_planes.read(); for (int i = 0; i < plane_count / 4; i++) { - planes.write[i].normal.x = r[i * 4 + 0]; planes.write[i].normal.y = r[i * 4 + 1]; planes.write[i].normal.z = r[i * 4 + 2]; @@ -502,7 +466,6 @@ BSP_Tree::BSP_Tree(const Variant &p_variant) { } } else { - planes = d["planes"]; } @@ -515,7 +478,6 @@ BSP_Tree::BSP_Tree(const Variant &p_variant) { PoolVector::Read r = src_nodes.read(); for (int i = 0; i < nodes.size(); i++) { - nodes.write[i].over = r[i * 3 + 0]; nodes.write[i].under = r[i * 3 + 1]; nodes.write[i].plane = r[i * 3 + 2]; @@ -523,7 +485,6 @@ BSP_Tree::BSP_Tree(const Variant &p_variant) { } BSP_Tree::BSP_Tree(const PoolVector &p_faces, real_t p_error_radius) { - // compute aabb int face_count = p_faces.size(); @@ -535,20 +496,16 @@ BSP_Tree::BSP_Tree(const PoolVector &p_faces, real_t p_error_radius) { Vector indices; for (int i = 0; i < face_count; i++) { - const Face3 &f = facesptr[i]; if (f.is_degenerate()) continue; for (int j = 0; j < 3; j++) { - if (first) { - aabb.position = f.vertex[0]; first = false; } else { - aabb.expand_to(f.vertex[j]); } } @@ -561,7 +518,6 @@ BSP_Tree::BSP_Tree(const PoolVector &p_faces, real_t p_error_radius) { int top = _bsp_create_node(faces_r.ptr(), indices, planes, nodes, aabb.get_longest_axis_size() * 0.0001); if (top < 0) { - nodes.clear(); planes.clear(); ERR_FAIL_COND(top < 0); diff --git a/core/math/bsp_tree.h b/core/math/bsp_tree.h index ddbd3c91072..7c0dfd62c55 100644 --- a/core/math/bsp_tree.h +++ b/core/math/bsp_tree.h @@ -50,7 +50,6 @@ public: }; struct Node { - uint16_t plane; uint16_t under; uint16_t over; @@ -95,7 +94,6 @@ public: template bool BSP_Tree::_test_convex(const Node *p_nodes, const Plane *p_planes, int p_current, const T &p_convex) const { - if (p_current == UNDER_LEAF) return true; else if (p_current == OVER_LEAF) @@ -122,7 +120,6 @@ bool BSP_Tree::_test_convex(const Node *p_nodes, const Plane *p_planes, int p_cu template bool BSP_Tree::convex_is_inside(const T &p_convex) const { - int node_count = nodes.size(); if (node_count == 0) return false; diff --git a/core/math/bvh.h b/core/math/bvh.h index 70dde53e839..c75f1d291aa 100644 --- a/core/math/bvh.h +++ b/core/math/bvh.h @@ -52,7 +52,6 @@ template class BVH_Manager { - public: // note we are using uint32_t instead of BVHHandle, losing type safety, but this // is for compatibility with octree @@ -89,7 +88,6 @@ public: } BVHHandle create(T *p_userdata, bool p_active, const Bounds &p_aabb = Bounds(), int p_subindex = 0, bool p_pairable = false, uint32_t p_pairable_type = 0, uint32_t p_pairable_mask = 1) { - // not sure if absolutely necessary to flush collisions here. It will cost performance to, instead // of waiting for update, so only uncomment this if there are bugs. if (USE_PAIRS) { @@ -181,7 +179,6 @@ public: //////////////////////////////////////////////////// void move(BVHHandle p_handle, const Bounds &p_aabb) { - if (tree.item_move(p_handle, p_aabb)) { if (USE_PAIRS) { _add_changed_item(p_handle, p_aabb); @@ -227,7 +224,6 @@ public: // returns success if (tree.item_activate(p_handle, p_aabb)) { if (USE_PAIRS) { - // in the special case of the render tree, when setting visibility we are using the combination of // activate then set_pairable. This would case 2 sets of collision checks. For efficiency here we allow // deferring to have a single collision check at the set_pairable call. @@ -285,7 +281,6 @@ public: tree.item_set_pairable(p_handle, p_pairable, p_pairable_type, p_pairable_mask); if (USE_PAIRS) { - // not sure if absolutely necessary to flush collisions here. It will cost performance to, instead // of waiting for update, so only uncomment this if there are bugs. //_check_for_collisions(); @@ -488,7 +483,6 @@ private: // callback if (unpair_callback) { - unpair_callback(pair_callback_userdata, p_from, exa.userdata, exa.subindex, p_to, exb.userdata, exb.subindex, ud_from); } } @@ -584,7 +578,6 @@ private: // if we remove an item, we need to immediately remove the pairs, to prevent reading the pair after deletion void _remove_pairs_containing(BVHHandle p_handle) { - typename BVHTREE_CLASS::ItemPairs &p_from = tree._pairs[p_handle.id()]; // remove from pairing list for every partner. @@ -609,7 +602,6 @@ private: } void _add_changed_item(BVHHandle p_handle, const Bounds &aabb, bool p_check_aabb = true) { - // Note that non pairable items can pair with pairable, // so all types must be added to the list @@ -644,7 +636,6 @@ private: } void _remove_changed_item(BVHHandle p_handle) { - // Care has to be taken here for items that are deleted. The ref ID // could be reused on the same tick for new items. This is probably // rare but should be taken into consideration diff --git a/core/math/bvh_abb.h b/core/math/bvh_abb.h index 269867389b0..67aac4d02b1 100644 --- a/core/math/bvh_abb.h +++ b/core/math/bvh_abb.h @@ -145,7 +145,6 @@ struct BVH_ABB { Vector3 ofs = min + half_extents; for (unsigned int i = 0; i < p_num_planes; i++) { - const Plane &p = p_hull.planes[p_plane_ids[i]]; Vector3 point( (p.normal.x > 0) ? -half_extents.x : half_extents.x, diff --git a/core/math/bvh_cull.inc b/core/math/bvh_cull.inc index 94e57b6d97b..7eb391e5874 100644 --- a/core/math/bvh_cull.inc +++ b/core/math/bvh_cull.inc @@ -53,7 +53,6 @@ void _cull_translate_hits(CullParams &p) { public: int cull_convex(CullParams &r_params, bool p_translate_hits = true) { - _cull_hits.clear(); r_params.result_count = 0; @@ -88,7 +87,6 @@ int cull_segment(CullParams &r_params, bool p_translate_hits = true) { } int cull_point(CullParams &r_params, bool p_translate_hits = true) { - _cull_hits.clear(); r_params.result_count = 0; @@ -150,7 +148,6 @@ bool _cull_pairing_mask_test_hit(uint32_t p_maskA, uint32_t p_typeA, uint32_t p_ } void _cull_hit(uint32_t p_ref_id, CullParams &p) { - // take into account masks etc // this would be more efficient to do before plane checks, // but done here for ease to get started @@ -166,7 +163,6 @@ void _cull_hit(uint32_t p_ref_id, CullParams &p) { } bool _cull_segment_iterative(uint32_t p_node_id, CullParams &r_params) { - // our function parameters to keep on a stack struct CullSegParams { uint32_t node_id; @@ -186,11 +182,9 @@ bool _cull_segment_iterative(uint32_t p_node_id, CullParams &r_params) { // while there are still more nodes on the stack while (ii.pop(csp)) { - TNode &tnode = _nodes[csp.node_id]; if (tnode.is_leaf()) { - // lazy check for hits full up condition if (_cull_hits_full(r_params)) { return false; @@ -212,12 +206,10 @@ bool _cull_segment_iterative(uint32_t p_node_id, CullParams &r_params) { } else { // test children individually for (int n = 0; n < tnode.num_children; n++) { - uint32_t child_id = tnode.children[n]; const BVHABB_CLASS &child_abb = _nodes[child_id].aabb; if (child_abb.intersects_segment(r_params.segment)) { - // add to the stack CullSegParams *child = ii.request(); child->node_id = child_id; @@ -251,14 +243,12 @@ bool _cull_point_iterative(uint32_t p_node_id, CullParams &r_params) { // while there are still more nodes on the stack while (ii.pop(cpp)) { - TNode &tnode = _nodes[cpp.node_id]; // no hit with this node? if (!tnode.aabb.intersects_point(r_params.point)) continue; if (tnode.is_leaf()) { - // lazy check for hits full up condition if (_cull_hits_full(r_params)) { return false; @@ -268,7 +258,6 @@ bool _cull_point_iterative(uint32_t p_node_id, CullParams &r_params) { // test children individually for (int n = 0; n < leaf.num_items; n++) { - if (leaf.get_aabb(n).intersects_point(r_params.point)) { uint32_t child_id = leaf.get_item_ref_id(n); @@ -294,7 +283,6 @@ bool _cull_point_iterative(uint32_t p_node_id, CullParams &r_params) { } bool _cull_aabb_iterative(uint32_t p_node_id, CullParams &r_params, bool p_fully_within = false) { - // our function parameters to keep on a stack struct CullAABBParams { uint32_t node_id; @@ -316,11 +304,9 @@ bool _cull_aabb_iterative(uint32_t p_node_id, CullParams &r_params, bool p_fully // while there are still more nodes on the stack while (ii.pop(cap)) { - TNode &tnode = _nodes[cap.node_id]; if (tnode.is_leaf()) { - // lazy check for hits full up condition if (_cull_hits_full(r_params)) { return false; @@ -353,7 +339,6 @@ bool _cull_aabb_iterative(uint32_t p_node_id, CullParams &r_params, bool p_fully if (!cap.fully_within) { // test children individually for (int n = 0; n < tnode.num_children; n++) { - uint32_t child_id = tnode.children[n]; const BVHABB_CLASS &child_abb = _nodes[child_id].aabb; @@ -391,7 +376,6 @@ bool _cull_aabb_iterative(uint32_t p_node_id, CullParams &r_params, bool p_fully // returns full up with results bool _cull_convex_iterative(uint32_t p_node_id, CullParams &r_params, bool p_fully_within = false) { - // our function parameters to keep on a stack struct CullConvexParams { uint32_t node_id; @@ -420,7 +404,6 @@ bool _cull_convex_iterative(uint32_t p_node_id, CullParams &r_params, bool p_ful const TNode &tnode = _nodes[ccp.node_id]; if (!ccp.fully_within) { - typename BVHABB_CLASS::IntersectResult res = tnode.aabb.intersects_convex(r_params.hull); switch (res) { @@ -437,7 +420,6 @@ bool _cull_convex_iterative(uint32_t p_node_id, CullParams &r_params, bool p_ful } // if not fully within already if (tnode.is_leaf()) { - // lazy check for hits full up condition if (_cull_hits_full(r_params)) { return false; @@ -448,9 +430,7 @@ bool _cull_convex_iterative(uint32_t p_node_id, CullParams &r_params, bool p_ful // if fully within, simply add all items to the result // (taking into account masks) if (ccp.fully_within) { - for (int n = 0; n < leaf.num_items; n++) { - uint32_t child_id = leaf.get_item_ref_id(n); // register hit @@ -458,7 +438,6 @@ bool _cull_convex_iterative(uint32_t p_node_id, CullParams &r_params, bool p_ful } } else { - // we can either use a naive check of all the planes against the AABB, // or an optimized check, which finds in advance which of the planes can possibly // cut the AABB, and only tests those. This can be much faster. @@ -524,7 +503,6 @@ bool _cull_convex_iterative(uint32_t p_node_id, CullParams &r_params, bool p_ful #endif // BVH_CONVEX_CULL_OPTIMIZED } // if not fully within } else { - for (int n = 0; n < tnode.num_children; n++) { uint32_t child_id = tnode.children[n]; diff --git a/core/math/bvh_logic.inc b/core/math/bvh_logic.inc index 6b96915f151..5b6dc00ecd3 100644 --- a/core/math/bvh_logic.inc +++ b/core/math/bvh_logic.inc @@ -193,7 +193,6 @@ int32_t _logic_balance(int32_t iA) { // either choose an existing node to add item to, or create a new node and return this uint32_t _logic_choose_item_add_node(uint32_t p_node_id, const BVHABB_CLASS &p_aabb) { - while (true) { BVH_ASSERT(p_node_id != BVHCommon::INVALID); TNode &tnode = _nodes[p_node_id]; diff --git a/core/math/bvh_refit.inc b/core/math/bvh_refit.inc index 46894303a6b..ea9bbb5271f 100644 --- a/core/math/bvh_refit.inc +++ b/core/math/bvh_refit.inc @@ -117,13 +117,11 @@ void refit_branch(uint32_t p_node_id) { // while there are still more nodes on the stack while (ii.pop(rp)) { - TNode &tnode = _nodes[rp.node_id]; // do children first if (!tnode.is_leaf()) { for (int n = 0; n < tnode.num_children; n++) { - uint32_t child_id = tnode.children[n]; // add to the stack diff --git a/core/math/camera_matrix.cpp b/core/math/camera_matrix.cpp index 4a8ac4d10d3..2fd6ead2187 100644 --- a/core/math/camera_matrix.cpp +++ b/core/math/camera_matrix.cpp @@ -34,29 +34,22 @@ #include "core/print_string.h" void CameraMatrix::set_identity() { - for (int i = 0; i < 4; i++) { - for (int j = 0; j < 4; j++) { - matrix[i][j] = (i == j) ? 1 : 0; } } } void CameraMatrix::set_zero() { - for (int i = 0; i < 4; i++) { - for (int j = 0; j < 4; j++) { - matrix[i][j] = 0; } } } Plane CameraMatrix::xform4(const Plane &p_vec4) const { - Plane ret; ret.normal.x = matrix[0][0] * p_vec4.normal.x + matrix[1][0] * p_vec4.normal.y + matrix[2][0] * p_vec4.normal.z + matrix[3][0] * p_vec4.d; @@ -67,7 +60,6 @@ Plane CameraMatrix::xform4(const Plane &p_vec4) const { } void CameraMatrix::set_perspective(real_t p_fovy_degrees, real_t p_aspect, real_t p_z_near, real_t p_z_far, bool p_flip_fov) { - if (p_flip_fov) { p_fovy_degrees = get_fovy(p_fovy_degrees, 1.0 / p_aspect); } @@ -160,7 +152,6 @@ void CameraMatrix::set_for_hmd(int p_eye, real_t p_aspect, real_t p_intraocular_ }; void CameraMatrix::set_orthogonal(real_t p_left, real_t p_right, real_t p_bottom, real_t p_top, real_t p_znear, real_t p_zfar) { - set_identity(); matrix[0][0] = 2.0 / (p_right - p_left); @@ -173,7 +164,6 @@ void CameraMatrix::set_orthogonal(real_t p_left, real_t p_right, real_t p_bottom } void CameraMatrix::set_orthogonal(real_t p_size, real_t p_aspect, real_t p_znear, real_t p_zfar, bool p_flip_fov) { - if (!p_flip_fov) { p_size *= p_aspect; } @@ -182,7 +172,6 @@ void CameraMatrix::set_orthogonal(real_t p_size, real_t p_aspect, real_t p_znear } void CameraMatrix::set_frustum(real_t p_left, real_t p_right, real_t p_bottom, real_t p_top, real_t p_near, real_t p_far) { - ERR_FAIL_COND(p_right <= p_left); ERR_FAIL_COND(p_top <= p_bottom); ERR_FAIL_COND(p_far <= p_near); @@ -223,7 +212,6 @@ void CameraMatrix::set_frustum(real_t p_size, real_t p_aspect, Vector2 p_offset, } real_t CameraMatrix::get_z_far() const { - const real_t *matrix = (const real_t *)this->matrix; Plane new_plane = Plane(matrix[3] - matrix[2], matrix[7] - matrix[6], @@ -236,7 +224,6 @@ real_t CameraMatrix::get_z_far() const { return new_plane.d; } real_t CameraMatrix::get_z_near() const { - const real_t *matrix = (const real_t *)this->matrix; Plane new_plane = Plane(matrix[3] + matrix[2], matrix[7] + matrix[6], @@ -248,7 +235,6 @@ real_t CameraMatrix::get_z_near() const { } Vector2 CameraMatrix::get_viewport_half_extents() const { - const real_t *matrix = (const real_t *)this->matrix; ///////--- Near Plane ---/////// Plane near_plane = Plane(matrix[3] + matrix[2], @@ -277,7 +263,6 @@ Vector2 CameraMatrix::get_viewport_half_extents() const { } bool CameraMatrix::get_endpoints(const Transform &p_transform, Vector3 *p_8points) const { - Vector planes = get_projection_planes(Transform()); const Planes intersections[8][3] = { { PLANE_FAR, PLANE_LEFT, PLANE_TOP }, @@ -291,7 +276,6 @@ bool CameraMatrix::get_endpoints(const Transform &p_transform, Vector3 *p_8point }; for (int i = 0; i < 8; i++) { - Vector3 point; bool res = planes[intersections[i][0]].intersect_3(planes[intersections[i][1]], planes[intersections[i][2]], &point); ERR_FAIL_COND_V(!res, false); @@ -302,7 +286,6 @@ bool CameraMatrix::get_endpoints(const Transform &p_transform, Vector3 *p_8point } Vector CameraMatrix::get_projection_planes(const Transform &p_transform) const { - /** Fast Plane Extraction from combined modelview/projection matrices. * References: * https://web.archive.org/web/20011221205252/http://www.markmorley.com/opengl/frustumculling.html @@ -385,14 +368,12 @@ Vector CameraMatrix::get_projection_planes(const Transform &p_transform) } CameraMatrix CameraMatrix::inverse() const { - CameraMatrix cm = *this; cm.invert(); return cm; } void CameraMatrix::invert() { - int i, j, k; int pvt_i[4], pvt_j[4]; /* Locations of pivot matrix */ real_t pvt_val; /* Value of current pivot element */ @@ -489,12 +470,10 @@ void CameraMatrix::invert() { } CameraMatrix::CameraMatrix() { - set_identity(); } CameraMatrix CameraMatrix::operator*(const CameraMatrix &p_matrix) const { - CameraMatrix new_matrix; for (int j = 0; j < 4; j++) { @@ -510,7 +489,6 @@ CameraMatrix CameraMatrix::operator*(const CameraMatrix &p_matrix) const { } void CameraMatrix::set_light_bias() { - real_t *m = &matrix[0][0]; m[0] = 0.5; @@ -532,7 +510,6 @@ void CameraMatrix::set_light_bias() { } void CameraMatrix::set_light_atlas_rect(const Rect2 &p_rect) { - real_t *m = &matrix[0][0]; m[0] = p_rect.size.width; @@ -554,7 +531,6 @@ 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++) @@ -564,20 +540,17 @@ CameraMatrix::operator String() const { } real_t CameraMatrix::get_aspect() const { - Vector2 vp_he = get_viewport_half_extents(); return vp_he.x / vp_he.y; } int CameraMatrix::get_pixels_per_meter(int p_for_pixel_width) const { - Vector3 result = xform(Vector3(1, 0, -1)); return int((result.x * 0.5 + 0.5) * p_for_pixel_width); } bool CameraMatrix::is_orthogonal() const { - return matrix[3][3] == 1.0; } @@ -605,7 +578,6 @@ real_t CameraMatrix::get_fov() const { } void CameraMatrix::make_scale(const Vector3 &p_scale) { - set_identity(); matrix[0][0] = p_scale.x; matrix[1][1] = p_scale.y; @@ -613,7 +585,6 @@ void CameraMatrix::make_scale(const Vector3 &p_scale) { } void CameraMatrix::scale_translate_to_fit(const AABB &p_aabb) { - Vector3 min = p_aabb.position; Vector3 max = p_aabb.position + p_aabb.size; @@ -639,7 +610,6 @@ void CameraMatrix::scale_translate_to_fit(const AABB &p_aabb) { } CameraMatrix::operator Transform() const { - Transform tr; const real_t *m = &matrix[0][0]; @@ -663,7 +633,6 @@ CameraMatrix::operator Transform() const { } CameraMatrix::CameraMatrix(const Transform &p_transform) { - const Transform &tr = p_transform; real_t *m = &matrix[0][0]; diff --git a/core/math/camera_matrix.h b/core/math/camera_matrix.h index 6d5a968e0d9..92b81420bee 100644 --- a/core/math/camera_matrix.h +++ b/core/math/camera_matrix.h @@ -35,7 +35,6 @@ #include "core/math/transform.h" struct CameraMatrix { - enum Planes { PLANE_NEAR, PLANE_FAR, @@ -60,7 +59,6 @@ struct CameraMatrix { void set_frustum(real_t p_size, real_t p_aspect, Vector2 p_offset, real_t p_near, real_t p_far, bool p_flip_fov = false); static real_t get_fovy(real_t p_fovx, real_t p_aspect) { - return Math::rad2deg(Math::atan(p_aspect * Math::tan(Math::deg2rad(p_fovx) * 0.5)) * 2.0); } @@ -96,7 +94,6 @@ struct CameraMatrix { }; Vector3 CameraMatrix::xform(const Vector3 &p_vec3) const { - Vector3 ret; ret.x = matrix[0][0] * p_vec3.x + matrix[1][0] * p_vec3.y + matrix[2][0] * p_vec3.z + matrix[3][0]; ret.y = matrix[0][1] * p_vec3.x + matrix[1][1] * p_vec3.y + matrix[2][1] * p_vec3.z + matrix[3][1]; diff --git a/core/math/delaunay.h b/core/math/delaunay.h index 3ddcc9281a2..6e3c026da79 100644 --- a/core/math/delaunay.h +++ b/core/math/delaunay.h @@ -36,7 +36,6 @@ class Delaunay2D { public: struct Triangle { - int points[3]; bool bad; Triangle() { bad = false; } @@ -60,7 +59,6 @@ public: }; static bool circum_circle_contains(const Vector &p_vertices, const Triangle &p_triangle, int p_vertex) { - Vector2 p1 = p_vertices[p_triangle.points[0]]; Vector2 p2 = p_vertices[p_triangle.points[1]]; Vector2 p3 = p_vertices[p_triangle.points[2]]; @@ -92,7 +90,6 @@ public: } static Vector triangulate(const Vector &p_points) { - Vector points = p_points; Vector triangles; @@ -146,7 +143,6 @@ public: } for (int j = 0; j < polygon.size(); j++) { - if (polygon[j].bad) { continue; } diff --git a/core/math/disjoint_set.h b/core/math/disjoint_set.h index 5523b30b8a9..0cd2293a77f 100644 --- a/core/math/disjoint_set.h +++ b/core/math/disjoint_set.h @@ -41,7 +41,6 @@ /* This DisjointSet class uses Find with path compression and Union by rank */ template , class AL = DefaultAllocator> class DisjointSet { - struct Element { T object; Element *parent = nullptr; @@ -103,7 +102,6 @@ typename DisjointSet::Element *DisjointSet::insert_or_get(T template void DisjointSet::create_union(T a, T b) { - Element *x = insert_or_get(a); Element *y = insert_or_get(b); diff --git a/core/math/expression.cpp b/core/math/expression.cpp index aae406de1e1..8f04e2d8019 100644 --- a/core/math/expression.cpp +++ b/core/math/expression.cpp @@ -111,7 +111,6 @@ 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]) return BuiltinFunc(i); @@ -121,15 +120,12 @@ Expression::BuiltinFunc Expression::find_function(const String &p_string) { } String Expression::get_func_name(BuiltinFunc p_func) { - ERR_FAIL_INDEX_V(p_func, FUNC_MAX, String()); return func_name[p_func]; } int Expression::get_func_argument_count(BuiltinFunc p_func) { - switch (p_func) { - case MATH_RANDOMIZE: case MATH_RAND: case MATH_RANDF: @@ -222,199 +218,161 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant r_error.error = Variant::CallError::CALL_OK; switch (p_func) { case MATH_SIN: { - VALIDATE_ARG_NUM(0); *r_return = Math::sin((double)*p_inputs[0]); } break; case MATH_COS: { - VALIDATE_ARG_NUM(0); *r_return = Math::cos((double)*p_inputs[0]); } break; case MATH_TAN: { - VALIDATE_ARG_NUM(0); *r_return = Math::tan((double)*p_inputs[0]); } break; case MATH_SINH: { - VALIDATE_ARG_NUM(0); *r_return = Math::sinh((double)*p_inputs[0]); } break; case MATH_COSH: { - VALIDATE_ARG_NUM(0); *r_return = Math::cosh((double)*p_inputs[0]); } break; case MATH_TANH: { - VALIDATE_ARG_NUM(0); *r_return = Math::tanh((double)*p_inputs[0]); } break; case MATH_ASIN: { - VALIDATE_ARG_NUM(0); *r_return = Math::asin((double)*p_inputs[0]); } break; case MATH_ACOS: { - VALIDATE_ARG_NUM(0); *r_return = Math::acos((double)*p_inputs[0]); } break; case MATH_ATAN: { - VALIDATE_ARG_NUM(0); *r_return = Math::atan((double)*p_inputs[0]); } break; case MATH_ATAN2: { - VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); *r_return = Math::atan2((double)*p_inputs[0], (double)*p_inputs[1]); } break; case MATH_SQRT: { - VALIDATE_ARG_NUM(0); *r_return = Math::sqrt((double)*p_inputs[0]); } break; case MATH_FMOD: { - VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); *r_return = Math::fmod((double)*p_inputs[0], (double)*p_inputs[1]); } break; case MATH_FPOSMOD: { - VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); *r_return = Math::fposmod((double)*p_inputs[0], (double)*p_inputs[1]); } break; case MATH_POSMOD: { - VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); *r_return = Math::posmod((int)*p_inputs[0], (int)*p_inputs[1]); } break; case MATH_FLOOR: { - VALIDATE_ARG_NUM(0); *r_return = Math::floor((double)*p_inputs[0]); } break; case MATH_CEIL: { - VALIDATE_ARG_NUM(0); *r_return = Math::ceil((double)*p_inputs[0]); } break; case MATH_ROUND: { - VALIDATE_ARG_NUM(0); *r_return = Math::round((double)*p_inputs[0]); } break; case MATH_ABS: { - if (p_inputs[0]->get_type() == Variant::INT) { - int64_t i = *p_inputs[0]; *r_return = ABS(i); } else if (p_inputs[0]->get_type() == Variant::REAL) { - real_t r = *p_inputs[0]; *r_return = Math::abs(r); } else { - r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; r_error.expected = Variant::REAL; } } break; case MATH_SIGN: { - if (p_inputs[0]->get_type() == Variant::INT) { - int64_t i = *p_inputs[0]; *r_return = i < 0 ? -1 : (i > 0 ? +1 : 0); } else if (p_inputs[0]->get_type() == Variant::REAL) { - real_t r = *p_inputs[0]; *r_return = r < 0.0 ? -1.0 : (r > 0.0 ? +1.0 : 0.0); } else { - r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; r_error.expected = Variant::REAL; } } break; case MATH_POW: { - VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); *r_return = Math::pow((double)*p_inputs[0], (double)*p_inputs[1]); } break; case MATH_LOG: { - VALIDATE_ARG_NUM(0); *r_return = Math::log((double)*p_inputs[0]); } break; case MATH_EXP: { - VALIDATE_ARG_NUM(0); *r_return = Math::exp((double)*p_inputs[0]); } break; case MATH_ISNAN: { - VALIDATE_ARG_NUM(0); *r_return = Math::is_nan((double)*p_inputs[0]); } break; case MATH_ISINF: { - VALIDATE_ARG_NUM(0); *r_return = Math::is_inf((double)*p_inputs[0]); } break; case MATH_EASE: { - VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); *r_return = Math::ease((double)*p_inputs[0], (double)*p_inputs[1]); } break; case MATH_DECIMALS: { - VALIDATE_ARG_NUM(0); *r_return = Math::step_decimals((double)*p_inputs[0]); } break; case MATH_STEP_DECIMALS: { - VALIDATE_ARG_NUM(0); *r_return = Math::step_decimals((double)*p_inputs[0]); } break; case MATH_STEPIFY: { - VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); *r_return = Math::stepify((double)*p_inputs[0], (double)*p_inputs[1]); } break; case MATH_LERP: { - VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); VALIDATE_ARG_NUM(2); *r_return = Math::lerp((double)*p_inputs[0], (double)*p_inputs[1], (double)*p_inputs[2]); } break; case MATH_LERP_ANGLE: { - VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); VALIDATE_ARG_NUM(2); *r_return = Math::lerp_angle((double)*p_inputs[0], (double)*p_inputs[1], (double)*p_inputs[2]); } break; case MATH_INVERSE_LERP: { - VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); VALIDATE_ARG_NUM(2); *r_return = Math::inverse_lerp((double)*p_inputs[0], (double)*p_inputs[1], (double)*p_inputs[2]); } break; case MATH_RANGE_LERP: { - VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); VALIDATE_ARG_NUM(2); @@ -429,14 +387,12 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant *r_return = Math::smoothstep((double)*p_inputs[0], (double)*p_inputs[1], (double)*p_inputs[2]); } break; case MATH_MOVE_TOWARD: { - VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); VALIDATE_ARG_NUM(2); *r_return = Math::move_toward((double)*p_inputs[0], (double)*p_inputs[1], (double)*p_inputs[2]); } break; case MATH_DECTIME: { - VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); VALIDATE_ARG_NUM(2); @@ -453,20 +409,17 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant *r_return = Math::randf(); } break; case MATH_RANDOM: { - VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); *r_return = Math::random((double)*p_inputs[0], (double)*p_inputs[1]); } break; case MATH_SEED: { - VALIDATE_ARG_NUM(0); uint64_t seed = *p_inputs[0]; Math::seed(seed); } break; case MATH_RANDSEED: { - VALIDATE_ARG_NUM(0); uint64_t seed = *p_inputs[0]; int ret = Math::rand_from_seed(&seed); @@ -477,22 +430,18 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant } break; case MATH_DEG2RAD: { - VALIDATE_ARG_NUM(0); *r_return = Math::deg2rad((double)*p_inputs[0]); } break; case MATH_RAD2DEG: { - VALIDATE_ARG_NUM(0); *r_return = Math::rad2deg((double)*p_inputs[0]); } break; case MATH_LINEAR2DB: { - VALIDATE_ARG_NUM(0); *r_return = Math::linear2db((double)*p_inputs[0]); } break; case MATH_DB2LINEAR: { - VALIDATE_ARG_NUM(0); *r_return = Math::db2linear((double)*p_inputs[0]); } break; @@ -523,9 +472,7 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant *r_return = Math::wrapf((double)*p_inputs[0], (double)*p_inputs[1], (double)*p_inputs[2]); } break; case LOGIC_MAX: { - if (p_inputs[0]->get_type() == Variant::INT && p_inputs[1]->get_type() == Variant::INT) { - int64_t a = *p_inputs[0]; int64_t b = *p_inputs[1]; *r_return = MAX(a, b); @@ -541,9 +488,7 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant } break; case LOGIC_MIN: { - if (p_inputs[0]->get_type() == Variant::INT && p_inputs[1]->get_type() == Variant::INT) { - int64_t a = *p_inputs[0]; int64_t b = *p_inputs[1]; *r_return = MIN(a, b); @@ -558,9 +503,7 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant } } break; case LOGIC_CLAMP: { - if (p_inputs[0]->get_type() == Variant::INT && p_inputs[1]->get_type() == Variant::INT && p_inputs[2]->get_type() == Variant::INT) { - int64_t a = *p_inputs[0]; int64_t b = *p_inputs[1]; int64_t c = *p_inputs[2]; @@ -578,15 +521,12 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant } } break; case LOGIC_NEAREST_PO2: { - VALIDATE_ARG_NUM(0); int64_t num = *p_inputs[0]; *r_return = next_power_of_2(num); } break; case OBJ_WEAKREF: { - if (p_inputs[0]->get_type() != Variant::OBJECT) { - r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; r_error.expected = Variant::OBJECT; @@ -595,10 +535,8 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant } if (p_inputs[0]->is_ref()) { - REF r = *p_inputs[0]; if (!r.is_valid()) { - return; } @@ -608,7 +546,6 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant } else { Object *obj = *p_inputs[0]; if (!obj) { - return; } Ref wref = memnew(WeakRef); @@ -618,9 +555,7 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant } break; case FUNC_FUNCREF: { - if (p_inputs[0]->get_type() != Variant::OBJECT) { - r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; r_error.expected = Variant::OBJECT; @@ -628,7 +563,6 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant return; } if (p_inputs[1]->get_type() != Variant::STRING && p_inputs[1]->get_type() != Variant::NODE_PATH) { - r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 1; r_error.expected = Variant::STRING; @@ -645,11 +579,9 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant } break; case TYPE_CONVERT: { - VALIDATE_ARG_NUM(1); int type = *p_inputs[1]; if (type < 0 || type >= Variant::VARIANT_MAX) { - r_error_str = RTR("Invalid type argument to convert(), use TYPE_* constants."); r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; @@ -657,31 +589,25 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant return; } else { - *r_return = Variant::construct(Variant::Type(type), p_inputs, 1, r_error); } } break; case TYPE_OF: { - *r_return = p_inputs[0]->get_type(); } break; case TYPE_EXISTS: { - *r_return = ClassDB::class_exists(*p_inputs[0]); } break; case TEXT_CHAR: { - CharType result[2] = { *p_inputs[0], 0 }; *r_return = String(result); } break; case TEXT_ORD: { - if (p_inputs[0]->get_type() != Variant::STRING) { - r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; r_error.expected = Variant::STRING; @@ -692,7 +618,6 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant String str = *p_inputs[0]; if (str.length() != 1) { - r_error_str = RTR("Expected a string of length 1 (a character)."); r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; @@ -705,39 +630,33 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant } break; case TEXT_STR: { - String str = *p_inputs[0]; *r_return = str; } break; case TEXT_PRINT: { - String str = *p_inputs[0]; print_line(str); } break; case TEXT_PRINTERR: { - String str = *p_inputs[0]; print_error(str); } break; case TEXT_PRINTRAW: { - String str = *p_inputs[0]; OS::get_singleton()->print("%s", str.utf8().get_data()); } break; case VAR_TO_STR: { - String vars; VariantWriter::write_to_string(*p_inputs[0], vars); *r_return = vars; } break; case STR_TO_VAR: { - if (p_inputs[0]->get_type() != Variant::STRING) { r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; @@ -763,7 +682,6 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant } break; case VAR_TO_BYTES: { - PoolByteArray barr; bool full_objects = *p_inputs[1]; int len; @@ -784,7 +702,6 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant *r_return = barr; } break; case BYTES_TO_VAR: { - if (p_inputs[0]->get_type() != Variant::POOL_BYTE_ARRAY) { r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; @@ -812,7 +729,6 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant } break; case COLORN: { - VALIDATE_ARG_NUM(1); Color color = Color::named(*p_inputs[0]); @@ -833,60 +749,49 @@ static bool _is_number(CharType c) { } Error Expression::_get_token(Token &r_token) { - while (true) { #define GET_CHAR() (str_ofs >= expression.length() ? 0 : expression[str_ofs++]) CharType cchar = GET_CHAR(); switch (cchar) { - case 0: { r_token.type = TK_EOF; return OK; }; case '{': { - r_token.type = TK_CURLY_BRACKET_OPEN; return OK; }; case '}': { - r_token.type = TK_CURLY_BRACKET_CLOSE; return OK; }; case '[': { - r_token.type = TK_BRACKET_OPEN; return OK; }; case ']': { - r_token.type = TK_BRACKET_CLOSE; return OK; }; case '(': { - r_token.type = TK_PARENTHESIS_OPEN; return OK; }; case ')': { - r_token.type = TK_PARENTHESIS_CLOSE; return OK; }; case ',': { - r_token.type = TK_COMMA; return OK; }; case ':': { - r_token.type = TK_COLON; return OK; }; case '$': { - r_token.type = TK_INPUT; int index = 0; do { @@ -905,7 +810,6 @@ Error Expression::_get_token(Token &r_token) { return OK; }; case '=': { - cchar = GET_CHAR(); if (cchar == '=') { r_token.type = TK_OP_EQUAL; @@ -917,7 +821,6 @@ Error Expression::_get_token(Token &r_token) { return OK; }; case '!': { - if (expression[str_ofs] == '=') { r_token.type = TK_OP_NOT_EQUAL; str_ofs++; @@ -927,7 +830,6 @@ Error Expression::_get_token(Token &r_token) { return OK; }; case '>': { - if (expression[str_ofs] == '=') { r_token.type = TK_OP_GREATER_EQUAL; str_ofs++; @@ -940,7 +842,6 @@ Error Expression::_get_token(Token &r_token) { return OK; }; case '<': { - if (expression[str_ofs] == '=') { r_token.type = TK_OP_LESS_EQUAL; str_ofs++; @@ -973,7 +874,6 @@ Error Expression::_get_token(Token &r_token) { return OK; }; case '&': { - if (expression[str_ofs] == '&') { r_token.type = TK_OP_AND; str_ofs++; @@ -983,7 +883,6 @@ Error Expression::_get_token(Token &r_token) { return OK; }; case '|': { - if (expression[str_ofs] == '|') { r_token.type = TK_OP_OR; str_ofs++; @@ -993,23 +892,19 @@ Error Expression::_get_token(Token &r_token) { return OK; }; case '^': { - r_token.type = TK_OP_BIT_XOR; return OK; }; case '~': { - r_token.type = TK_OP_BIT_INVERT; return OK; }; case '\'': case '"': { - String str; while (true) { - CharType ch = GET_CHAR(); if (ch == 0) { @@ -1031,7 +926,6 @@ Error Expression::_get_token(Token &r_token) { CharType res = 0; switch (next) { - case 'b': res = 8; break; @@ -1059,7 +953,6 @@ Error Expression::_get_token(Token &r_token) { return ERR_PARSE_ERROR; } if (!(_is_number(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))) { - _set_error("Malformed hex constant in string"); r_token.type = TK_ERROR; return ERR_PARSE_ERROR; @@ -1106,7 +999,6 @@ Error Expression::_get_token(Token &r_token) { } break; default: { - if (cchar <= 32) { break; } @@ -1129,10 +1021,8 @@ Error Expression::_get_token(Token &r_token) { bool is_float = false; while (true) { - switch (reading) { case READING_INT: { - if (_is_number(c)) { //pass } else if (c == '.') { @@ -1146,9 +1036,7 @@ Error Expression::_get_token(Token &r_token) { } break; case READING_DEC: { - if (_is_number(c)) { - } else if (c == 'e') { reading = READING_EXP; @@ -1158,7 +1046,6 @@ Error Expression::_get_token(Token &r_token) { } break; case READING_EXP: { - if (_is_number(c)) { exp_beg = true; @@ -1190,12 +1077,10 @@ Error Expression::_get_token(Token &r_token) { return OK; } else if ((cchar >= 'A' && cchar <= 'Z') || (cchar >= 'a' && cchar <= 'z') || cchar == '_') { - String id; bool first = true; while ((cchar >= 'A' && cchar <= 'Z') || (cchar >= 'a' && cchar <= 'z') || cchar == '_' || (!first && _is_number(cchar))) { - id += String::chr(cchar); cchar = GET_CHAR(); first = false; @@ -1235,7 +1120,6 @@ Error Expression::_get_token(Token &r_token) { } else if (id == "self") { r_token.type = TK_SELF; } else { - for (int i = 0; i < Variant::VARIANT_MAX; i++) { if (id == Variant::get_type_name(Variant::Type(i))) { r_token.type = TK_BASIC_TYPE; @@ -1318,7 +1202,6 @@ const char *Expression::token_name[TK_MAX] = { }; Expression::ENode *Expression::_parse_expression() { - Vector expression; while (true) { @@ -1336,7 +1219,6 @@ Expression::ENode *Expression::_parse_expression() { DictionaryNode *dn = alloc_node(); while (true) { - int cofs = str_ofs; _get_token(tk); if (tk.type == TK_CURLY_BRACKET_CLOSE) { @@ -1380,7 +1262,6 @@ Expression::ENode *Expression::_parse_expression() { ArrayNode *an = alloc_node(); while (true) { - int cofs = str_ofs; _get_token(tk); if (tk.type == TK_BRACKET_CLOSE) { @@ -1421,7 +1302,6 @@ Expression::ENode *Expression::_parse_expression() { } break; case TK_IDENTIFIER: { - String identifier = tk.value; int cofs = str_ofs; @@ -1434,7 +1314,6 @@ Expression::ENode *Expression::_parse_expression() { func_call->base = self_node; while (true) { - int cofs2 = str_ofs; _get_token(tk); if (tk.type == TK_PARENTHESIS_CLOSE) { @@ -1477,7 +1356,6 @@ Expression::ENode *Expression::_parse_expression() { input->index = input_index; expr = input; } else { - NamedIndexNode *index = alloc_node(); SelfNode *self_node = alloc_node(); index->base = self_node; @@ -1487,13 +1365,11 @@ Expression::ENode *Expression::_parse_expression() { } } break; case TK_INPUT: { - InputNode *input = alloc_node(); input->index = tk.value; expr = input; } break; case TK_SELF: { - SelfNode *self = alloc_node(); expr = self; } break; @@ -1516,7 +1392,6 @@ Expression::ENode *Expression::_parse_expression() { constructor->data_type = bt; while (true) { - int cofs = str_ofs; _get_token(tk); if (tk.type == TK_PARENTHESIS_CLOSE) { @@ -1557,7 +1432,6 @@ Expression::ENode *Expression::_parse_expression() { bifunc->func = BuiltinFunc(int(tk.value)); while (true) { - int cofs = str_ofs; _get_token(tk); if (tk.type == TK_PARENTHESIS_CLOSE) { @@ -1591,7 +1465,6 @@ Expression::ENode *Expression::_parse_expression() { } break; case TK_OP_SUB: { - ExpressionNode e; e.is_op = true; e.op = Variant::OP_NEGATE; @@ -1599,7 +1472,6 @@ Expression::ENode *Expression::_parse_expression() { continue; } break; case TK_OP_NOT: { - ExpressionNode e; e.is_op = true; e.op = Variant::OP_NOT; @@ -1663,7 +1535,6 @@ Expression::ENode *Expression::_parse_expression() { func_call->base = expr; while (true) { - int cofs3 = str_ofs; _get_token(tk); if (tk.type == TK_PARENTHESIS_CLOSE) { @@ -1812,15 +1683,12 @@ Expression::ENode *Expression::_parse_expression() { /* Reduce the set set of expressions and place them in an operator tree, respecting precedence */ while (expression.size() > 1) { - int next_op = -1; int min_priority = 0xFFFFF; bool is_unary = false; for (int i = 0; i < expression.size(); i++) { - if (!expression[i].is_op) { - continue; } @@ -1829,7 +1697,6 @@ Expression::ENode *Expression::_parse_expression() { bool unary = false; switch (expression[i].op) { - case Variant::OP_BIT_NEGATE: priority = 0; unary = true; @@ -1925,17 +1792,14 @@ Expression::ENode *Expression::_parse_expression() { } if (next_op == -1) { - _set_error("Yet another parser bug...."); ERR_FAIL_V(NULL); } // OK! create operator.. if (is_unary) { - int expr_pos = next_op; while (expression[expr_pos].is_op) { - expr_pos++; if (expr_pos == expression.size()) { //can happen.. @@ -1946,7 +1810,6 @@ Expression::ENode *Expression::_parse_expression() { //consecutively do unary operators for (int i = expr_pos - 1; i >= next_op; i--) { - OperatorNode *op = alloc_node(); op->op = expression[i].op; op->nodes[0] = expression[i + 1].node; @@ -1957,7 +1820,6 @@ Expression::ENode *Expression::_parse_expression() { } } else { - if (next_op < 1 || next_op >= (expression.size() - 1)) { _set_error("Parser bug..."); ERR_FAIL_V(NULL); @@ -1967,7 +1829,6 @@ Expression::ENode *Expression::_parse_expression() { op->op = expression[next_op].op; if (expression[next_op - 1].is_op) { - _set_error("Parser bug..."); ERR_FAIL_V(NULL); } @@ -1996,7 +1857,6 @@ Expression::ENode *Expression::_parse_expression() { } bool Expression::_compile_expression() { - if (!expression_dirty) return error_set; @@ -2026,10 +1886,8 @@ bool Expression::_compile_expression() { } bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression::ENode *p_node, Variant &r_ret, String &r_error_str) { - switch (p_node->type) { case Expression::ENode::TYPE_INPUT: { - const Expression::InputNode *in = static_cast(p_node); if (in->index < 0 || in->index >= p_inputs.size()) { r_error_str = vformat(RTR("Invalid input %i (not passed) in expression"), in->index); @@ -2038,13 +1896,11 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression: r_ret = p_inputs[in->index]; } break; case Expression::ENode::TYPE_CONSTANT: { - const Expression::ConstantNode *c = static_cast(p_node); r_ret = c->value; } break; case Expression::ENode::TYPE_SELF: { - if (!p_instance) { r_error_str = RTR("self can't be used because instance is null (not passed)"); return true; @@ -2052,7 +1908,6 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression: r_ret = p_instance; } break; case Expression::ENode::TYPE_OPERATOR: { - const Expression::OperatorNode *op = static_cast(p_node); Variant a; @@ -2077,7 +1932,6 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression: } break; case Expression::ENode::TYPE_INDEX: { - const Expression::IndexNode *index = static_cast(p_node); Variant base; @@ -2100,7 +1954,6 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression: } break; case Expression::ENode::TYPE_NAMED_INDEX: { - const Expression::NamedIndexNode *index = static_cast(p_node); Variant base; @@ -2122,7 +1975,6 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression: Array arr; arr.resize(array->array.size()); for (int i = 0; i < array->array.size(); i++) { - Variant value; bool ret = _execute(p_inputs, p_instance, array->array[i], value, r_error_str); @@ -2139,7 +1991,6 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression: Dictionary d; for (int i = 0; i < dictionary->dict.size(); i += 2) { - Variant key; bool ret = _execute(p_inputs, p_instance, dictionary->dict[i + 0], key, r_error_str); @@ -2157,7 +2008,6 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression: r_ret = d; } break; case Expression::ENode::TYPE_CONSTRUCTOR: { - const Expression::ConstructorNode *constructor = static_cast(p_node); Vector arr; @@ -2166,7 +2016,6 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression: argp.resize(constructor->arguments.size()); for (int i = 0; i < constructor->arguments.size(); i++) { - Variant value; bool ret = _execute(p_inputs, p_instance, constructor->arguments[i], value, r_error_str); @@ -2186,7 +2035,6 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression: } break; case Expression::ENode::TYPE_BUILTIN_FUNC: { - const Expression::BuiltinFuncNode *bifunc = static_cast(p_node); Vector arr; @@ -2195,7 +2043,6 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression: argp.resize(bifunc->arguments.size()); 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) @@ -2214,7 +2061,6 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression: } break; case Expression::ENode::TYPE_CALL: { - const Expression::CallNode *call = static_cast(p_node); Variant base; @@ -2229,7 +2075,6 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression: argp.resize(call->arguments.size()); for (int i = 0; i < call->arguments.size(); i++) { - Variant value; ret = _execute(p_inputs, p_instance, call->arguments[i], value, r_error_str); @@ -2253,7 +2098,6 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression: } Error Expression::parse(const String &p_expression, const Vector &p_input_names) { - if (nodes) { memdelete(nodes); nodes = NULL; @@ -2281,7 +2125,6 @@ Error Expression::parse(const String &p_expression, const Vector &p_inpu } Variant Expression::execute(Array p_inputs, Object *p_base, bool p_show_error) { - ERR_FAIL_COND_V_MSG(error_set, Variant(), "There was previously a parse error: " + error_str + "."); execution_error = false; @@ -2306,7 +2149,6 @@ String Expression::get_error_text() const { } void Expression::_bind_methods() { - ClassDB::bind_method(D_METHOD("parse", "expression", "input_names"), &Expression::parse, DEFVAL(Vector())); ClassDB::bind_method(D_METHOD("execute", "inputs", "base_instance", "show_error"), &Expression::execute, DEFVAL(Array()), DEFVAL(Variant()), DEFVAL(true)); ClassDB::bind_method(D_METHOD("has_execute_failed"), &Expression::has_execute_failed); @@ -2323,7 +2165,6 @@ Expression::Expression() : } Expression::~Expression() { - if (nodes) { memdelete(nodes); } diff --git a/core/math/expression.h b/core/math/expression.h index 0b0cec60c4f..e95b9f4a3d1 100644 --- a/core/math/expression.h +++ b/core/math/expression.h @@ -119,7 +119,6 @@ private: static const char *func_name[FUNC_MAX]; struct Input { - Variant::Type type; String name; @@ -183,7 +182,6 @@ private: static const char *token_name[TK_MAX]; struct Token { - TokenType type; Variant value; }; @@ -201,7 +199,6 @@ private: bool error_set; struct ENode { - enum Type { TYPE_INPUT, TYPE_CONSTANT, @@ -229,7 +226,6 @@ private: }; struct ExpressionNode { - bool is_op; union { Variant::Operator op; @@ -240,7 +236,6 @@ private: ENode *_parse_expression(); struct InputNode : public ENode { - int index; InputNode() { type = TYPE_INPUT; @@ -248,7 +243,6 @@ private: }; struct ConstantNode : public ENode { - Variant value; ConstantNode() { type = TYPE_CONSTANT; @@ -256,7 +250,6 @@ private: }; struct OperatorNode : public ENode { - Variant::Operator op; ENode *nodes[2]; @@ -267,7 +260,6 @@ private: }; struct SelfNode : public ENode { - SelfNode() { type = TYPE_SELF; } diff --git a/core/math/face3.cpp b/core/math/face3.cpp index 674c5068a8c..e2062e0058c 100644 --- a/core/math/face3.cpp +++ b/core/math/face3.cpp @@ -33,7 +33,6 @@ #include "core/math/geometry.h" int Face3::split_by_plane(const Plane &p_plane, Face3 p_res[3], bool p_is_point_over[3]) const { - ERR_FAIL_COND_V(is_degenerate(), 0); Vector3 above[4]; @@ -43,7 +42,6 @@ int Face3::split_by_plane(const Plane &p_plane, Face3 p_res[3], bool p_is_point_ int below_count = 0; for (int i = 0; i < 3; i++) { - if (p_plane.has_point(vertex[i], CMP_EPSILON)) { // point is in plane ERR_FAIL_COND_V(above_count >= 4, 0); @@ -52,7 +50,6 @@ int Face3::split_by_plane(const Plane &p_plane, Face3 p_res[3], bool p_is_point_ below[below_count++] = vertex[i]; } else { - if (p_plane.is_point_over(vertex[i])) { //Point is over ERR_FAIL_COND_V(above_count >= 4, 0); @@ -83,13 +80,11 @@ int Face3::split_by_plane(const Plane &p_plane, Face3 p_res[3], bool p_is_point_ ERR_FAIL_COND_V(above_count >= 4 && below_count >= 4, 0); //bug in the algo if (above_count >= 3) { - p_res[polygons_created] = Face3(above[0], above[1], above[2]); p_is_point_over[polygons_created] = true; polygons_created++; if (above_count == 4) { - p_res[polygons_created] = Face3(above[2], above[3], above[0]); p_is_point_over[polygons_created] = true; polygons_created++; @@ -97,13 +92,11 @@ int Face3::split_by_plane(const Plane &p_plane, Face3 p_res[3], bool p_is_point_ } if (below_count >= 3) { - p_res[polygons_created] = Face3(below[0], below[1], below[2]); p_is_point_over[polygons_created] = false; polygons_created++; if (below_count == 4) { - p_res[polygons_created] = Face3(below[2], below[3], below[0]); p_is_point_over[polygons_created] = false; polygons_created++; @@ -114,29 +107,24 @@ int Face3::split_by_plane(const Plane &p_plane, Face3 p_res[3], bool p_is_point_ } bool Face3::intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *p_intersection) const { - return Geometry::ray_intersects_triangle(p_from, p_dir, vertex[0], vertex[1], vertex[2], p_intersection); } bool Face3::intersects_segment(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *p_intersection) const { - return Geometry::segment_intersects_triangle(p_from, p_dir, vertex[0], vertex[1], vertex[2], p_intersection); } bool Face3::is_degenerate() const { - Vector3 normal = vec3_cross(vertex[0] - vertex[1], vertex[0] - vertex[2]); return (normal.length_squared() < CMP_EPSILON2); } Face3::Side Face3::get_side_of(const Face3 &p_face, ClockDirection p_clock_dir) const { - int over = 0, under = 0; Plane plane = get_plane(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 @@ -159,7 +147,6 @@ Face3::Side Face3::get_side_of(const Face3 &p_face, ClockDirection p_clock_dir) } Vector3 Face3::get_random_point_inside() const { - real_t a = Math::random(0, 1); real_t b = Math::random(0, 1); if (a > b) { @@ -170,12 +157,10 @@ Vector3 Face3::get_random_point_inside() const { } Plane Face3::get_plane(ClockDirection p_dir) const { - return Plane(vertex[0], vertex[1], vertex[2], p_dir); } Vector3 Face3::get_median_point() const { - return (vertex[0] + vertex[1] + vertex[2]) / 3.0; } @@ -184,14 +169,12 @@ real_t Face3::get_area() const { } ClockDirection Face3::get_clock_dir() const { - Vector3 normal = vec3_cross(vertex[0] - vertex[1], vertex[0] - vertex[2]); //printf("normal is %g,%g,%g x %g,%g,%g- wtfu is %g\n",tofloat(normal.x),tofloat(normal.y),tofloat(normal.z),tofloat(vertex[0].x),tofloat(vertex[0].y),tofloat(vertex[0].z),tofloat( normal.dot( vertex[0] ) ) ); return (normal.dot(vertex[0]) >= 0) ? CLOCKWISE : COUNTERCLOCKWISE; } bool Face3::intersects_aabb(const AABB &p_aabb) const { - /** TEST PLANE **/ if (!p_aabb.intersects_plane(get_plane())) return false; @@ -227,7 +210,6 @@ bool Face3::intersects_aabb(const AABB &p_aabb) const { }; for (int i = 0; i < 12; i++) { - Vector3 from, to; p_aabb.get_edge(i, from, to); Vector3 e1 = from - to; @@ -252,14 +234,11 @@ bool Face3::intersects_aabb(const AABB &p_aabb) const { } Face3::operator String() const { - return String() + vertex[0] + ", " + vertex[1] + ", " + vertex[2]; } void Face3::project_range(const Vector3 &p_normal, const Transform &p_transform, real_t &r_min, real_t &r_max) const { - for (int i = 0; i < 3; i++) { - Vector3 v = p_transform.xform(vertex[i]); real_t d = p_normal.dot(v); @@ -272,7 +251,6 @@ void Face3::project_range(const Vector3 &p_normal, const Transform &p_transform, } void Face3::get_support(const Vector3 &p_normal, const Transform &p_transform, Vector3 *p_vertices, int *p_count, int p_max) const { - #define _FACE_IS_VALID_SUPPORT_THRESHOLD 0.98 #define _EDGE_IS_VALID_SUPPORT_THRESHOLD 0.05 @@ -283,11 +261,9 @@ void Face3::get_support(const Vector3 &p_normal, const Transform &p_transform, V /** TEST FACE AS SUPPORT **/ if (get_plane().normal.dot(n) > _FACE_IS_VALID_SUPPORT_THRESHOLD) { - *p_count = MIN(3, p_max); for (int i = 0; i < *p_count; i++) { - p_vertices[i] = p_transform.xform(vertex[i]); } @@ -300,7 +276,6 @@ void Face3::get_support(const Vector3 &p_normal, const Transform &p_transform, V real_t support_max = 0; for (int i = 0; i < 3; i++) { - real_t d = n.dot(vertex[i]); if (i == 0 || d > support_max) { @@ -312,7 +287,6 @@ 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) continue; @@ -320,7 +294,6 @@ void Face3::get_support(const Vector3 &p_normal, const Transform &p_transform, V real_t dot = (vertex[i] - vertex[(i + 1) % 3]).normalized().dot(n); dot = ABS(dot); if (dot < _EDGE_IS_VALID_SUPPORT_THRESHOLD) { - *p_count = MIN(2, p_max); for (int j = 0; j < *p_count; j++) @@ -335,7 +308,6 @@ void Face3::get_support(const Vector3 &p_normal, const Transform &p_transform, V } Vector3 Face3::get_closest_point_to(const Vector3 &p_point) const { - Vector3 edge0 = vertex[1] - vertex[0]; Vector3 edge1 = vertex[2] - vertex[0]; Vector3 v0 = vertex[0] - p_point; diff --git a/core/math/face3.h b/core/math/face3.h index 1e2cdb6c425..d83e33399e4 100644 --- a/core/math/face3.h +++ b/core/math/face3.h @@ -78,7 +78,6 @@ public: void project_range(const Vector3 &p_normal, const Transform &p_transform, real_t &r_min, real_t &r_max) const; AABB get_aabb() const { - AABB aabb(vertex[0], Vector3()); aabb.expand_to(vertex[1]); aabb.expand_to(vertex[2]); @@ -98,7 +97,6 @@ public: }; bool Face3::intersects_aabb2(const AABB &p_aabb) const { - Vector3 perp = (vertex[0] - vertex[2]).cross(vertex[0] - vertex[1]); Vector3 half_extents = p_aabb.size * 0.5; @@ -145,17 +143,13 @@ bool Face3::intersects_aabb2(const AABB &p_aabb) const { }; for (int i = 0; i < 12; i++) { - Vector3 from, to; switch (i) { - case 0: { - from = Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y, p_aabb.position.z); to = Vector3(p_aabb.position.x, p_aabb.position.y, p_aabb.position.z); } break; case 1: { - from = Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y, p_aabb.position.z + p_aabb.size.z); to = Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y, p_aabb.position.z); } break; @@ -165,18 +159,15 @@ bool Face3::intersects_aabb2(const AABB &p_aabb) const { } break; case 3: { - from = Vector3(p_aabb.position.x, p_aabb.position.y, p_aabb.position.z); to = Vector3(p_aabb.position.x, p_aabb.position.y, p_aabb.position.z + p_aabb.size.z); } break; case 4: { - from = Vector3(p_aabb.position.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z); to = Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z); } break; case 5: { - from = Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z); to = Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z + p_aabb.size.z); } break; @@ -186,31 +177,26 @@ bool Face3::intersects_aabb2(const AABB &p_aabb) const { } break; case 7: { - from = Vector3(p_aabb.position.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z + p_aabb.size.z); to = Vector3(p_aabb.position.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z); } break; case 8: { - from = Vector3(p_aabb.position.x, p_aabb.position.y, p_aabb.position.z + p_aabb.size.z); to = Vector3(p_aabb.position.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z + p_aabb.size.z); } break; case 9: { - from = Vector3(p_aabb.position.x, p_aabb.position.y, p_aabb.position.z); to = Vector3(p_aabb.position.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z); } break; case 10: { - from = Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y, p_aabb.position.z); to = Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z); } break; case 11: { - from = Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y, p_aabb.position.z + p_aabb.size.z); to = Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z + p_aabb.size.z); @@ -240,7 +226,6 @@ bool Face3::intersects_aabb2(const AABB &p_aabb) const { real_t minT = 1e20, maxT = -1e20; for (int k = 0; k < 3; k++) { - real_t vert_d = axis.dot(vertex[k]); if (vert_d > maxT) diff --git a/core/math/geometry.cpp b/core/math/geometry.cpp index 5c9ff6e5837..7262b96f3e3 100644 --- a/core/math/geometry.cpp +++ b/core/math/geometry.cpp @@ -54,13 +54,10 @@ bool Geometry::is_point_in_polygon(const Vector2 &p_point, const Vector */ void Geometry::MeshData::optimize_vertices() { - Map vtx_remap; for (int i = 0; i < faces.size(); i++) { - for (int j = 0; j < faces[i].indices.size(); j++) { - int idx = faces[i].indices[j]; if (!vtx_remap.has(idx)) { int ni = vtx_remap.size(); @@ -72,7 +69,6 @@ void Geometry::MeshData::optimize_vertices() { } for (int i = 0; i < edges.size(); i++) { - int a = edges[i].a; int b = edges[i].b; @@ -93,7 +89,6 @@ void Geometry::MeshData::optimize_vertices() { new_vertices.resize(vtx_remap.size()); for (int i = 0; i < vertices.size(); i++) { - if (vtx_remap.has(i)) new_vertices.write[vtx_remap[i]] = vertices[i]; } @@ -101,9 +96,7 @@ void Geometry::MeshData::optimize_vertices() { } struct _FaceClassify { - struct _Link { - int face; int edge; void clear() { @@ -132,42 +125,34 @@ static bool _connect_faces(_FaceClassify *p_faces, int len, int p_group) { bool error = false; for (int i = 0; i < len; i++) { - for (int j = 0; j < 3; j++) { - p_faces[i].links[j].clear(); } } for (int i = 0; i < len; i++) { - if (p_faces[i].group != p_group) continue; for (int j = i + 1; j < len; j++) { - if (p_faces[j].group != p_group) continue; for (int k = 0; k < 3; k++) { - Vector3 vi1 = p_faces[i].face.vertex[k]; Vector3 vi2 = p_faces[i].face.vertex[(k + 1) % 3]; for (int l = 0; l < 3; l++) { - Vector3 vj2 = p_faces[j].face.vertex[l]; Vector3 vj1 = p_faces[j].face.vertex[(l + 1) % 3]; if (vi1.distance_to(vj1) < 0.00001 && vi2.distance_to(vj2) < 0.00001) { if (p_faces[i].links[k].face != -1) { - ERR_PRINT("already linked\n"); error = true; break; } if (p_faces[j].links[l].face != -1) { - ERR_PRINT("already linked\n"); error = true; break; @@ -190,10 +175,8 @@ static bool _connect_faces(_FaceClassify *p_faces, int len, int p_group) { } 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) p_faces[i].valid = false; } @@ -202,14 +185,12 @@ static bool _connect_faces(_FaceClassify *p_faces, int len, int p_group) { } static bool _group_face(_FaceClassify *p_faces, int len, int p_index, int p_group) { - if (p_faces[p_index].group >= 0) return false; p_faces[p_index].group = p_group; for (int i = 0; i < 3; i++) { - ERR_FAIL_INDEX_V(p_faces[p_index].links[i].face, len, true); _group_face(p_faces, len, p_faces[p_index].links[i].face, p_group); } @@ -218,7 +199,6 @@ static bool _group_face(_FaceClassify *p_faces, int len, int p_index, int p_grou } PoolVector> Geometry::separate_objects(PoolVector p_array) { - PoolVector> objects; int len = p_array.size(); @@ -236,7 +216,6 @@ PoolVector> Geometry::separate_objects(PoolVector p_arr _FaceClassify *_fcptr = fcw.ptr(); for (int i = 0; i < len; i++) { - _fcptr[i].face = arrayptr[i]; } @@ -248,7 +227,6 @@ PoolVector> Geometry::separate_objects(PoolVector p_arr int group = 0; for (int i = 0; i < len; i++) { - if (!_fcptr[i].valid) continue; if (_group_face(_fcptr, len, i, group)) { @@ -259,12 +237,10 @@ PoolVector> Geometry::separate_objects(PoolVector p_arr // Group connected faces in separate objects. for (int i = 0; i < len; i++) { - _fcptr[i].face = arrayptr[i]; } if (group >= 0) { - objects.resize(group); PoolVector>::Write obw = objects.write(); PoolVector *group_faces = obw.ptr(); @@ -273,7 +249,6 @@ PoolVector> Geometry::separate_objects(PoolVector p_arr if (!_fcptr[i].valid) continue; if (_fcptr[i].group >= 0 && _fcptr[i].group < group) { - group_faces[_fcptr[i].group].push_back(_fcptr[i].face); } } @@ -310,7 +285,6 @@ enum _CellFlags { }; static inline void _plot_face(uint8_t ***p_cell_status, int x, int y, int z, int len_x, int len_y, int len_z, const Vector3 &voxelsize, const Face3 &p_face) { - AABB aabb(Vector3(x, y, z), Vector3(len_x, len_y, len_z)); aabb.position = aabb.position * voxelsize; aabb.size = aabb.size * voxelsize; @@ -319,7 +293,6 @@ static inline void _plot_face(uint8_t ***p_cell_status, int x, int y, int z, int return; if (len_x == 1 && len_y == 1 && len_z == 1) { - p_cell_status[x][y][z] = _CELL_SOLID; return; } @@ -348,15 +321,12 @@ static inline void _plot_face(uint8_t ***p_cell_status, int x, int y, int z, int int new_len_z; for (int i = 0; i < div_x; i++) { - _SPLIT(i, div_x, x, len_x, new_x, new_len_x); for (int j = 0; j < div_y; j++) { - _SPLIT(j, div_y, y, len_y, new_y, new_len_y); for (int k = 0; k < div_z; k++) { - _SPLIT(k, div_z, z, len_z, new_z, new_len_z); _plot_face(p_cell_status, new_x, new_y, new_z, new_len_x, new_len_y, new_len_z, voxelsize, p_face); @@ -366,14 +336,12 @@ 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) return; // Nothing to do, already used and/or visited. p_cell_status[x][y][z] = _CELL_PREV_FIRST; while (true) { - uint8_t &c = p_cell_status[x][y][z]; if ((c & _CELL_STEP_MASK) == _CELL_STEP_NONE) { @@ -427,9 +395,7 @@ static inline void _mark_outside(uint8_t ***p_cell_status, int x, int y, int z, uint8_t prev = 0; switch (c & _CELL_STEP_MASK) { - case _CELL_STEP_Y_POS: { - next_y++; prev = _CELL_PREV_Y_NEG; } break; @@ -475,7 +441,6 @@ static inline void _mark_outside(uint8_t ***p_cell_status, int x, int y, int z, } static inline void _build_faces(uint8_t ***p_cell_status, int x, int y, int z, int len_x, int len_y, int len_z, PoolVector &p_faces) { - ERR_FAIL_INDEX(x, len_x); ERR_FAIL_INDEX(y, len_y); ERR_FAIL_INDEX(z, len_z); @@ -496,7 +461,6 @@ static inline void _build_faces(uint8_t ***p_cell_status, int x, int y, int z, i }; for (int i = 0; i < 6; i++) { - Vector3 face_points[4]; int disp_x = x + ((i % 3) == 0 ? ((i < 3) ? 1 : -1) : 0); int disp_y = y + (((i - 1) % 3) == 0 ? ((i < 3) ? 1 : -1) : 0); @@ -535,7 +499,6 @@ static inline void _build_faces(uint8_t ***p_cell_status, int x, int y, int z, i } PoolVector Geometry::wrap_geometry(PoolVector p_array, real_t *p_error) { - #define _MIN_SIZE 1.0 #define _MAX_LENGTH 20 @@ -546,12 +509,9 @@ PoolVector Geometry::wrap_geometry(PoolVector p_array, real_t *p_e AABB global_aabb; for (int i = 0; i < face_count; i++) { - if (i == 0) { - global_aabb = faces[i].get_aabb(); } else { - global_aabb.merge_with(faces[i].get_aabb()); } } @@ -585,15 +545,12 @@ PoolVector Geometry::wrap_geometry(PoolVector p_array, real_t *p_e uint8_t ***cell_status = memnew_arr(uint8_t **, div_x); for (int i = 0; i < div_x; i++) { - cell_status[i] = memnew_arr(uint8_t *, div_y); for (int j = 0; j < div_y; j++) { - cell_status[i][j] = memnew_arr(uint8_t, div_z); for (int k = 0; k < div_z; k++) { - cell_status[i][j][k] = 0; } } @@ -602,10 +559,8 @@ PoolVector Geometry::wrap_geometry(PoolVector p_array, real_t *p_e // Plot faces into cells. for (int i = 0; i < face_count; i++) { - Face3 f = faces[i]; for (int j = 0; j < 3; j++) { - f.vertex[j] -= global_aabb.position; } _plot_face(cell_status, 0, 0, 0, div_x, div_y, div_z, voxelsize, f); @@ -614,27 +569,21 @@ PoolVector Geometry::wrap_geometry(PoolVector p_array, real_t *p_e // Determine which cells connect to the outside by traversing the outside and recursively flood-fill marking. for (int i = 0; i < div_x; i++) { - for (int j = 0; j < div_y; j++) { - _mark_outside(cell_status, i, j, 0, div_x, div_y, div_z); _mark_outside(cell_status, i, j, div_z - 1, div_x, div_y, div_z); } } for (int i = 0; i < div_z; i++) { - for (int j = 0; j < div_y; j++) { - _mark_outside(cell_status, 0, j, i, div_x, div_y, div_z); _mark_outside(cell_status, div_x - 1, j, i, div_x, div_y, div_z); } } for (int i = 0; i < div_x; i++) { - for (int j = 0; j < div_z; j++) { - _mark_outside(cell_status, i, 0, j, div_x, div_y, div_z); _mark_outside(cell_status, i, div_y - 1, j, div_x, div_y, div_z); } @@ -645,11 +594,8 @@ PoolVector Geometry::wrap_geometry(PoolVector p_array, real_t *p_e PoolVector wrapped_faces; for (int i = 0; i < div_x; i++) { - for (int j = 0; j < div_y; j++) { - for (int k = 0; k < div_z; k++) { - _build_faces(cell_status, i, j, k, div_x, div_y, div_z, wrapped_faces); } } @@ -662,9 +608,7 @@ PoolVector Geometry::wrap_geometry(PoolVector p_array, real_t *p_e Face3 *wrapped_faces_ptr = wrapped_facesw.ptr(); for (int i = 0; i < wrapped_faces_count; i++) { - for (int j = 0; j < 3; j++) { - Vector3 &v = wrapped_faces_ptr[i].vertex[j]; v = v * voxelsize; v += global_aabb.position; @@ -674,9 +618,7 @@ PoolVector Geometry::wrap_geometry(PoolVector p_array, real_t *p_e // clean up grid for (int i = 0; i < div_x; i++) { - for (int j = 0; j < div_y; j++) { - memdelete_arr(cell_status[i][j]); } @@ -725,14 +667,12 @@ Vector> Geometry::decompose_polygon_in_convex(Vector pol } Geometry::MeshData Geometry::build_convex_mesh(const PoolVector &p_planes) { - MeshData mesh; #define SUBPLANE_SIZE 1024.0 real_t subplane_size = 1024.0; // Should compute this from the actual plane. for (int i = 0; i < p_planes.size(); i++) { - Plane p = p_planes[i]; Vector3 ref = Vector3(0.0, 1.0, 0.0); @@ -753,7 +693,6 @@ Geometry::MeshData Geometry::build_convex_mesh(const PoolVector &p_planes vertices.push_back(center + up * subplane_size + right * subplane_size); for (int j = 0; j < p_planes.size(); j++) { - if (j == i) continue; @@ -767,7 +706,6 @@ Geometry::MeshData Geometry::build_convex_mesh(const PoolVector &p_planes break; for (int k = 0; k < vertices.size(); k++) { - int k_n = (k + 1) % vertices.size(); Vector3 edge0_A = vertices[k]; @@ -783,7 +721,6 @@ Geometry::MeshData Geometry::build_convex_mesh(const PoolVector &p_planes // Check for different sides and non coplanar. if ((dist0 * dist1) < 0) { - // Calculate intersection. Vector3 rel = edge1_A - edge0_A; @@ -809,19 +746,15 @@ Geometry::MeshData Geometry::build_convex_mesh(const PoolVector &p_planes // Add face indices. for (int j = 0; j < vertices.size(); j++) { - int idx = -1; for (int k = 0; k < mesh.vertices.size(); k++) { - if (mesh.vertices[k].distance_to(vertices[j]) < 0.001) { - idx = k; break; } } if (idx == -1) { - idx = mesh.vertices.size(); mesh.vertices.push_back(vertices[j]); } @@ -834,13 +767,11 @@ Geometry::MeshData Geometry::build_convex_mesh(const PoolVector &p_planes // Add edge. for (int j = 0; j < face.indices.size(); j++) { - int a = face.indices[j]; int b = face.indices[(j + 1) % face.indices.size()]; bool found = false; for (int k = 0; k < mesh.edges.size(); k++) { - if (mesh.edges[k].a == a && mesh.edges[k].b == b) { found = true; break; @@ -864,7 +795,6 @@ Geometry::MeshData Geometry::build_convex_mesh(const PoolVector &p_planes } PoolVector Geometry::build_box_planes(const Vector3 &p_extents) { - PoolVector planes; planes.push_back(Plane(Vector3(1, 0, 0), p_extents.x)); @@ -883,7 +813,6 @@ PoolVector Geometry::build_cylinder_planes(real_t p_radius, real_t p_heig PoolVector planes; for (int i = 0; i < p_sides; i++) { - Vector3 normal; normal[(p_axis + 1) % 3] = Math::cos(i * (2.0 * Math_PI) / p_sides); normal[(p_axis + 2) % 3] = Math::sin(i * (2.0 * Math_PI) / p_sides); @@ -914,7 +843,6 @@ PoolVector Geometry::build_sphere_planes(real_t p_radius, int p_lats, int axis_neg[p_axis] = -1.0; for (int i = 0; i < p_lons; i++) { - Vector3 normal; normal[(p_axis + 1) % 3] = Math::cos(i * (2.0 * Math_PI) / p_lons); normal[(p_axis + 2) % 3] = Math::sin(i * (2.0 * Math_PI) / p_lons); @@ -922,7 +850,6 @@ PoolVector Geometry::build_sphere_planes(real_t p_radius, int p_lats, int planes.push_back(Plane(normal, p_radius)); for (int j = 1; j <= p_lats; j++) { - // FIXME: This is stupid. Vector3 angle = normal.linear_interpolate(axis, j / (real_t)p_lats).normalized(); Vector3 pos = angle * p_radius; @@ -948,7 +875,6 @@ PoolVector Geometry::build_capsule_planes(real_t p_radius, real_t p_heigh axis_neg[p_axis] = -1.0; for (int i = 0; i < p_sides; i++) { - Vector3 normal; normal[(p_axis + 1) % 3] = Math::cos(i * (2.0 * Math_PI) / p_sides); normal[(p_axis + 2) % 3] = Math::sin(i * (2.0 * Math_PI) / p_sides); @@ -956,7 +882,6 @@ PoolVector Geometry::build_capsule_planes(real_t p_radius, real_t p_heigh planes.push_back(Plane(normal, p_radius)); for (int j = 1; j <= p_lats; j++) { - Vector3 angle = normal.linear_interpolate(axis, j / (real_t)p_lats).normalized(); Vector3 pos = axis * p_height * 0.5 + angle * p_radius; planes.push_back(Plane(pos, angle)); @@ -968,7 +893,6 @@ PoolVector Geometry::build_capsule_planes(real_t p_radius, real_t p_heigh } struct _AtlasWorkRect { - Size2i s; Point2i p; int idx; @@ -976,14 +900,12 @@ struct _AtlasWorkRect { }; struct _AtlasWorkRectResult { - Vector<_AtlasWorkRect> result; int max_w; int max_h; }; void Geometry::make_atlas(const Vector &p_rects, Vector &r_result, Size2i &r_size) { - // Super simple, almost brute force scanline stacking fitter. // It's pretty basic for now, but it tries to make sure that the aspect ratio of the // resulting atlas is somehow square. This is necessary because video cards have limits. @@ -1010,7 +932,6 @@ void Geometry::make_atlas(const Vector &p_rects, Vector &r_resu Vector<_AtlasWorkRectResult> results; for (int i = 0; i <= 12; i++) { - int w = 1 << i; int max_h = 0; int max_w = 0; @@ -1026,15 +947,12 @@ void Geometry::make_atlas(const Vector &p_rects, Vector &r_resu int ofs = 0; int limit_h = 0; for (int j = 0; j < wrects.size(); j++) { - if (ofs + wrects[j].s.width > w) { - ofs = 0; } int from_y = 0; for (int k = 0; k < wrects[j].s.width; k++) { - if (hmax[ofs + k] > from_y) from_y = hmax[ofs + k]; } @@ -1047,7 +965,6 @@ void Geometry::make_atlas(const Vector &p_rects, Vector &r_resu limit_h = end_h; for (int k = 0; k < wrects[j].s.width; k++) { - hmax.write[ofs + k] = end_h; } @@ -1074,7 +991,6 @@ void Geometry::make_atlas(const Vector &p_rects, Vector &r_resu real_t best_aspect = 1e20; for (int i = 0; i < results.size(); i++) { - real_t h = next_power_of_2(results[i].max_h); real_t w = next_power_of_2(results[i].max_w); real_t aspect = h > w ? h / w : w / h; @@ -1087,7 +1003,6 @@ void Geometry::make_atlas(const Vector &p_rects, Vector &r_resu r_result.resize(p_rects.size()); for (int i = 0; i < p_rects.size(); i++) { - r_result.write[results[best].result[i].idx] = results[best].result[i].p; } @@ -1095,7 +1010,6 @@ void Geometry::make_atlas(const Vector &p_rects, Vector &r_resu } Vector> Geometry::_polypaths_do_operation(PolyBooleanOperation p_op, const Vector &p_polypath_a, const Vector &p_polypath_b, bool is_a_open) { - using namespace ClipperLib; ClipType op = ctUnion; @@ -1155,7 +1069,6 @@ Vector> Geometry::_polypaths_do_operation(PolyBooleanOperation p_ } Vector> Geometry::_polypath_offset(const Vector &p_polypath, real_t p_delta, PolyJoinType p_join_type, PolyEndType p_end_type) { - using namespace ClipperLib; JoinType jt = jtSquare; @@ -1222,19 +1135,16 @@ Vector> Geometry::_polypath_offset(const Vector &p_polypa } Vector Geometry::compute_convex_mesh_points(const Plane *p_planes, int p_plane_count) { - Vector points; // Iterate through every unique combination of any three planes. for (int i = p_plane_count - 1; i >= 0; i--) { for (int j = i - 1; j >= 0; j--) { for (int k = j - 1; k >= 0; k--) { - // Find the point where these planes all cross over (if they // do at all). Vector3 convex_shape_point; if (p_planes[i].intersect_3(p_planes[j], p_planes[k], &convex_shape_point)) { - // See if any *other* plane excludes this point because it's // on the wrong side. bool excluded = false; @@ -1261,7 +1171,6 @@ Vector Geometry::compute_convex_mesh_points(const Plane *p_planes, int } Vector Geometry::partial_pack_rects(const Vector &p_sizes, const Size2i &p_atlas_size) { - Vector nodes; nodes.resize(p_atlas_size.width); memset(nodes.ptrw(), 0, sizeof(stbrp_node) * nodes.size()); diff --git a/core/math/geometry.h b/core/math/geometry.h index 50ec3009b7e..60d1a8e0bb3 100644 --- a/core/math/geometry.h +++ b/core/math/geometry.h @@ -46,7 +46,6 @@ class Geometry { public: static real_t get_closest_points_between_segments(const Vector2 &p1, const Vector2 &q1, const Vector2 &p2, const Vector2 &q2, Vector2 &c1, Vector2 &c2) { - Vector2 d1 = q1 - p1; // Direction vector of segment S1. Vector2 d2 = q2 - p2; // Direction vector of segment S2. Vector2 r = p1 - p2; @@ -104,7 +103,6 @@ public: } static void get_closest_points_between_segments(const Vector3 &p1, const Vector3 &p2, const Vector3 &q1, const Vector3 &q2, Vector3 &c1, Vector3 &c2) { - // Do the function 'd' as defined by pb. I think is is dot product of some sort. #define d_of(m, n, o, p) ((m.x - n.x) * (o.x - p.x) + (m.y - n.y) * (o.y - p.y) + (m.z - n.z) * (o.z - p.z)) @@ -227,7 +225,6 @@ public: } 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 = 0) { - Vector3 rel = p_to - p_from; Vector3 e1 = p_v1 - p_v0; Vector3 e2 = p_v2 - p_v0; @@ -264,7 +261,6 @@ public: } 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 = 0, Vector3 *r_norm = 0) { - Vector3 sphere_pos = p_sphere_pos - p_from; Vector3 rel = (p_to - p_from); real_t rel_l = rel.length(); @@ -300,7 +296,6 @@ 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 = 0, Vector3 *r_norm = 0, int p_cylinder_axis = 2) { - Vector3 rel = (p_to - p_from); real_t rel_l = rel.length(); if (rel_l < CMP_EPSILON) @@ -347,7 +342,6 @@ public: int axis = -1; for (int i = 0; i < 2; i++) { - real_t seg_from = from2D[i]; real_t seg_to = to2D[i]; real_t box_begin = -size[i]; @@ -355,7 +349,6 @@ public: real_t cmin, cmax; if (seg_from < seg_to) { - if (seg_from > box_end || seg_to < box_begin) return false; real_t length = seg_to - seg_from; @@ -363,7 +356,6 @@ public: cmax = (seg_to > box_end) ? ((box_end - seg_from) / length) : 1; } else { - if (seg_to > box_end || seg_from < box_begin) return false; real_t length = seg_to - seg_from; @@ -405,7 +397,6 @@ public: } static bool segment_intersects_convex(const Vector3 &p_from, const Vector3 &p_to, const Plane *p_planes, int p_plane_count, Vector3 *p_res, Vector3 *p_norm) { - real_t min = -1e20, max = 1e20; Vector3 rel = p_to - p_from; @@ -419,7 +410,6 @@ public: int min_index = -1; for (int i = 0; i < p_plane_count; i++) { - const Plane &p = p_planes[i]; real_t den = p.normal.dot(dir); @@ -434,7 +424,6 @@ public: if (dist < max) max = dist; } else { - // Front facing plane. if (dist > min) { min = dist; @@ -455,7 +444,6 @@ public: } static Vector3 get_closest_point_to_segment(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(); @@ -473,7 +461,6 @@ public: } 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(); @@ -486,7 +473,6 @@ public: } static Vector2 get_closest_point_to_segment_2d(const Vector2 &p_point, const Vector2 *p_segment) { - Vector2 p = p_point - p_segment[0]; Vector2 n = p_segment[1] - p_segment[0]; real_t l2 = n.length_squared(); @@ -538,7 +524,6 @@ public: } static Vector2 get_closest_point_to_segment_uncapped_2d(const Vector2 &p_point, const Vector2 *p_segment) { - Vector2 p = p_point - p_segment[0]; Vector2 n = p_segment[1] - p_segment[0]; real_t l2 = n.length_squared(); @@ -551,7 +536,6 @@ public: } static bool line_intersects_line_2d(const Vector2 &p_from_a, const Vector2 &p_dir_a, const Vector2 &p_from_b, const Vector2 &p_dir_b, Vector2 &r_result) { - // See http://paulbourke.net/geometry/pointlineplane/ const real_t denom = p_dir_b.y * p_dir_a.x - p_dir_b.x * p_dir_a.y; @@ -566,7 +550,6 @@ public: } static bool segment_intersects_segment_2d(const Vector2 &p_from_a, const Vector2 &p_to_a, const Vector2 &p_from_b, const Vector2 &p_to_b, Vector2 *r_result) { - Vector2 B = p_to_a - p_from_a; Vector2 C = p_from_b - p_from_a; Vector2 D = p_to_b - p_from_a; @@ -595,7 +578,6 @@ public: } static inline bool point_in_projected_triangle(const Vector3 &p_point, const Vector3 &p_v1, const Vector3 &p_v2, const Vector3 &p_v3) { - Vector3 face_n = (p_v1 - p_v3).cross(p_v1 - p_v2); Vector3 n1 = (p_point - p_v3).cross(p_point - p_v2); @@ -617,7 +599,6 @@ 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. @@ -639,7 +620,6 @@ public: const Vector3 verts[4] = { p_triangle[0], p_triangle[1], p_triangle[2], p_triangle[0] }; // for() friendly for (int i = 0; i < 3; i++) { - // Check edge cylinder. Vector3 n1 = verts[i] - verts[i + 1]; @@ -664,7 +644,6 @@ public: real_t sphere_at = n1.dot(n2); if (sphere_at >= 0 && sphere_at < n1.dot(n1)) { - r_triangle_contact = p_sphere_pos - axis * (axis.dot(n2)); r_sphere_contact = p_sphere_pos - axis * p_sphere_radius; // Point inside here. @@ -674,7 +653,6 @@ public: real_t r2 = p_sphere_radius * p_sphere_radius; if (n2.length_squared() < r2) { - Vector3 n = (p_sphere_pos - verts[i + 1]).normalized(); r_triangle_contact = verts[i + 1]; @@ -697,12 +675,10 @@ public: } static inline bool is_point_in_circle(const Vector2 &p_point, const Vector2 &p_circle_pos, real_t p_circle_radius) { - return p_point.distance_squared_to(p_circle_pos) <= p_circle_radius * p_circle_radius; } static real_t segment_intersects_circle(const Vector2 &p_from, const Vector2 &p_to, const Vector2 &p_circle_pos, real_t p_circle_radius) { - Vector2 line_vec = p_to - p_from; Vector2 vec_to_line = p_from - p_circle_pos; @@ -735,7 +711,6 @@ public: } static inline Vector clip_polygon(const Vector &polygon, const Plane &p_plane) { - enum LocationCache { LOC_INSIDE = 1, LOC_BOUNDARY = 0, @@ -765,11 +740,9 @@ public: } if (outside_count == 0) { - return polygon; // No changes. } else if (inside_count == 0) { - return Vector(); // Empty. } @@ -829,49 +802,40 @@ public: }; static Vector> merge_polygons_2d(const Vector &p_polygon_a, const Vector &p_polygon_b) { - return _polypaths_do_operation(OPERATION_UNION, p_polygon_a, p_polygon_b); } static Vector> clip_polygons_2d(const Vector &p_polygon_a, const Vector &p_polygon_b) { - return _polypaths_do_operation(OPERATION_DIFFERENCE, p_polygon_a, p_polygon_b); } static Vector> intersect_polygons_2d(const Vector &p_polygon_a, const Vector &p_polygon_b) { - return _polypaths_do_operation(OPERATION_INTERSECTION, p_polygon_a, p_polygon_b); } static Vector> exclude_polygons_2d(const Vector &p_polygon_a, const Vector &p_polygon_b) { - return _polypaths_do_operation(OPERATION_XOR, p_polygon_a, p_polygon_b); } static Vector> clip_polyline_with_polygon_2d(const Vector &p_polyline, const Vector &p_polygon) { - return _polypaths_do_operation(OPERATION_DIFFERENCE, p_polyline, p_polygon, true); } static Vector> intersect_polyline_with_polygon_2d(const Vector &p_polyline, const Vector &p_polygon) { - return _polypaths_do_operation(OPERATION_INTERSECTION, p_polyline, p_polygon, true); } static Vector> offset_polygon_2d(const Vector &p_polygon, real_t p_delta, PolyJoinType p_join_type) { - return _polypath_offset(p_polygon, p_delta, p_join_type, END_POLYGON); } static Vector> offset_polyline_2d(const Vector &p_polygon, real_t p_delta, PolyJoinType p_join_type, PolyEndType p_end_type) { - ERR_FAIL_COND_V_MSG(p_end_type == END_POLYGON, Vector>(), "Attempt to offset a polyline like a polygon (use offset_polygon_2d instead)."); return _polypath_offset(p_polygon, p_delta, p_join_type, p_end_type); } static Vector triangulate_delaunay_2d(const Vector &p_points) { - Vector tr = Delaunay2D::triangulate(p_points); Vector triangles; @@ -884,7 +848,6 @@ public: } static Vector triangulate_polygon(const Vector &p_polygon) { - Vector triangles; if (!Triangulate::triangulate(p_polygon, triangles)) return Vector(); //fail @@ -943,7 +906,6 @@ public: static PoolVector wrap_geometry(PoolVector p_array, real_t *p_error = NULL); struct MeshData { - struct Face { Plane plane; Vector indices; @@ -952,7 +914,6 @@ public: Vector faces; struct Edge { - int a, b; }; @@ -964,7 +925,6 @@ public: }; _FORCE_INLINE_ static int get_uv84_normal_bit(const Vector3 &p_vector) { - int lat = Math::fast_ftoi(Math::floor(Math::acos(p_vector.dot(Vector3(0, 1, 0))) * 4.0 / Math_PI + 0.5)); if (lat == 0) { @@ -979,13 +939,11 @@ public: } _FORCE_INLINE_ static int get_uv84_normal_bit_neighbors(int p_idx) { - if (p_idx == 24) { return 1 | 2 | 4 | 8; } else if (p_idx == 25) { return (1 << 23) | (1 << 22) | (1 << 21) | (1 << 20); } else { - int ret = 0; if ((p_idx % 8) == 0) ret |= (1 << (p_idx + 7)); diff --git a/core/math/math_fieldwise.cpp b/core/math/math_fieldwise.cpp index 2dcb53ad444..0491f153e33 100644 --- a/core/math/math_fieldwise.cpp +++ b/core/math/math_fieldwise.cpp @@ -41,7 +41,6 @@ } Variant fieldwise_assign(const Variant &p_target, const Variant &p_source, const String &p_field) { - ERR_FAIL_COND_V(p_target.get_type() != p_source.get_type(), p_target); /* clang-format makes a mess of this macro usage */ diff --git a/core/math/math_funcs.cpp b/core/math/math_funcs.cpp index 894501dc282..fff7b3f211d 100644 --- a/core/math/math_funcs.cpp +++ b/core/math/math_funcs.cpp @@ -130,7 +130,6 @@ double Math::stepify(double p_value, double p_step) { } uint32_t Math::larger_prime(uint32_t p_val) { - static const uint32_t primes[] = { 5, 13, @@ -166,7 +165,6 @@ 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) return primes[idx]; diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h index 332e3d34485..c18085212e3 100644 --- a/core/math/math_funcs.h +++ b/core/math/math_funcs.h @@ -41,7 +41,6 @@ #include class Math { - static RandomPCG default_rand; public: @@ -331,7 +330,6 @@ public: } static _ALWAYS_INLINE_ float absf(float g) { - union { float f; uint32_t i; @@ -343,7 +341,6 @@ public: } static _ALWAYS_INLINE_ double absd(double g) { - union { double d; uint64_t i; @@ -355,7 +352,6 @@ public: //this function should be as fast as possible and rounding mode should not matter static _ALWAYS_INLINE_ int fast_ftoi(float a) { - static int b; #if (defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0603) || WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP // windows 8 phone? @@ -410,7 +406,6 @@ public: } static _ALWAYS_INLINE_ float halfptr_to_float(const uint16_t *h) { - union { uint32_t u32; float f32; @@ -425,7 +420,6 @@ public: } static _ALWAYS_INLINE_ uint16_t make_half_float(float f) { - union { float fv; uint32_t ui; @@ -456,7 +450,6 @@ public: } // check if exponent is <= -15 else if (exp <= 0x38000000) { - /*// store a denorm half-float value or zero exp = (0x38000000 - exp) >> 23; mantissa >>= (14 + exp); diff --git a/core/math/octree_definition.inc b/core/math/octree_definition.inc index 01aa641023a..ae14d585de6 100644 --- a/core/math/octree_definition.inc +++ b/core/math/octree_definition.inc @@ -75,7 +75,6 @@ private: }; struct PairKey { - union { struct { OctreeElementID A; @@ -85,18 +84,14 @@ private: }; _FORCE_INLINE_ bool operator<(const PairKey &p_pair) const { - return key < p_pair.key; } _FORCE_INLINE_ PairKey(OctreeElementID p_A, OctreeElementID p_B) { - if (p_A < p_B) { - A = p_A; B = p_B; } else { - B = p_A; A = p_B; } @@ -133,7 +128,6 @@ private: #endif struct Octant { - // cached for FAST plane check AABB aabb; @@ -197,7 +191,6 @@ private: } ~Octant() { - /* for (int i=0;i<8;i++) memdelete_notnull(children[i]); @@ -208,7 +201,6 @@ private: struct PairData; struct Element { - OCTREE_CLASS_NAME *octree; T *userdata; @@ -227,7 +219,6 @@ private: List pair_list; struct OctantOwner { - Octant *octant; typename List::Element *E; }; // an element can be in max 8 octants @@ -259,7 +250,6 @@ private: }; struct PairData { - int refcount; bool intersect; Element *A, *B; @@ -287,19 +277,15 @@ private: int octant_elements_limit; _FORCE_INLINE_ void _pair_check(PairData *p_pair) { - bool intersect = p_pair->A->aabb.intersects_inclusive(p_pair->B->aabb); if (intersect != p_pair->intersect) { - if (intersect) { - if (pair_callback) { p_pair->ud = pair_callback(pair_callback_userdata, p_pair->A->_id, p_pair->A->userdata, p_pair->A->subindex, p_pair->B->_id, p_pair->B->userdata, p_pair->B->subindex); } pair_count++; } else { - if (unpair_callback) { unpair_callback(pair_callback_userdata, p_pair->A->_id, p_pair->A->userdata, p_pair->A->subindex, p_pair->B->_id, p_pair->B->userdata, p_pair->B->subindex, p_pair->ud); } @@ -311,7 +297,6 @@ 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)) return; @@ -323,7 +308,6 @@ private: typename PairMap::Element *E = pair_map.find(key); if (!E) { - PairData pdata; pdata.refcount = 1; pdata.A = p_A; @@ -338,13 +322,11 @@ private: pair_callback(pair_callback_userdata,p_A->userdata,p_B->userdata); */ } else { - E->get().refcount++; } } _FORCE_INLINE_ void _pair_unreference(Element *p_A, Element *p_B) { - if (p_A == p_B) return; @@ -379,24 +361,18 @@ private: } _FORCE_INLINE_ void _element_check_pairs(Element *p_element) { - typename List::Element *E = p_element->pair_list.front(); while (E) { - _pair_check(E->get()); E = E->next(); } } _FORCE_INLINE_ void _optimize() { - while (root && root->children_count < 2 && !root->elements.size() && !(use_pairs && root->pairable_elements.size())) { - Octant *new_root = NULL; if (root->children_count == 1) { - for (int i = 0; i < 8; i++) { - if (root->children[i]) { new_root = root->children[i]; root->children[i] = NULL; @@ -422,7 +398,6 @@ private: void _unpair_element(Element *p_element, Octant *p_octant); struct _CullConvexData { - const Plane *planes; int plane_count; const Vector3 *points; @@ -439,12 +414,10 @@ 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) return; for (int i = 0; i < 8; i++) { - if (p_octant->children[i]) _remove_tree(p_octant->children[i]); } @@ -508,14 +481,12 @@ OCTREE_FUNC(T *)::get(OctreeElementID p_id) const { } OCTREE_FUNC(bool)::is_pairable(OctreeElementID p_id) const { - const typename ElementMap::Element *E = element_map.find(p_id); ERR_FAIL_COND_V(!E, false); return E->get().pairable; } OCTREE_FUNC(int)::get_subindex(OctreeElementID p_id) const { - const typename ElementMap::Element *E = element_map.find(p_id); ERR_FAIL_COND_V(!E, -1); return E->get().subindex; @@ -524,7 +495,6 @@ OCTREE_FUNC(int)::get_subindex(OctreeElementID p_id) const { #define OCTREE_DIVISOR 4 OCTREE_FUNC(void)::_insert_element(Element *p_element, Octant *p_octant) { - real_t element_size = p_element->aabb.get_longest_axis_size() * 1.01; // avoid precision issues // don't create new child octants unless there is more than a certain number in @@ -541,17 +511,14 @@ OCTREE_FUNC(void)::_insert_element(Element *p_element, Octant *p_octant) { } if (!can_split || (element_size > (p_octant->aabb.size.x / OCTREE_DIVISOR))) { - /* at smallest possible size for the element */ typename Element::OctantOwner owner; owner.octant = p_octant; if (use_pairs && p_element->pairable) { - p_octant->pairable_elements.push_back(p_element); owner.E = p_octant->pairable_elements.back(); } else { - p_octant->elements.push_back(p_element); owner.E = p_octant->elements.back(); } @@ -568,11 +535,9 @@ OCTREE_FUNC(void)::_insert_element(Element *p_element, Octant *p_octant) { } if (use_pairs && p_octant->children_count > 0) { - pass++; //elements below this only get ONE reference added for (int i = 0; i < 8; i++) { - if (p_octant->children[i]) { _pair_element(p_element, p_octant->children[i]); } @@ -584,7 +549,6 @@ OCTREE_FUNC(void)::_insert_element(Element *p_element, Octant *p_octant) { bool candidate = p_element->common_parent == NULL; for (int i = 0; i < 8; i++) { - if (p_octant->children[i]) { /* element exists, go straight to it */ if (p_octant->children[i]->aabb.intersects_inclusive(p_element->aabb)) { @@ -624,13 +588,11 @@ OCTREE_FUNC(void)::_insert_element(Element *p_element, Octant *p_octant) { } if (candidate && splits > 1) { - p_element->common_parent = p_octant; } } if (use_pairs) { - typename List::Element *E = p_octant->pairable_elements.front(); while (E) { @@ -650,14 +612,12 @@ OCTREE_FUNC(void)::_insert_element(Element *p_element, Octant *p_octant) { } OCTREE_FUNC(void)::_ensure_valid_root(const AABB &p_aabb) { - if (!root) { // octre is empty AABB base(Vector3(), Vector3(1.0, 1.0, 1.0) * unit_size); while (!base.encloses(p_aabb)) { - if (ABS(base.position.x + base.size.x) <= ABS(base.position.x)) { /* grow towards positive */ base.size *= 2.0; @@ -676,11 +636,9 @@ OCTREE_FUNC(void)::_ensure_valid_root(const AABB &p_aabb) { octant_count++; } else { - AABB base = root->aabb; while (!base.encloses(p_aabb)) { - ERR_FAIL_COND_MSG(base.size.x > OCTREE_SIZE_LIMIT, "Octree upper size limit reached, does the AABB supplied contain NAN?"); Octant *gp = memnew_allocator(Octant, AL); @@ -708,11 +666,9 @@ OCTREE_FUNC(void)::_ensure_valid_root(const AABB &p_aabb) { } OCTREE_FUNC(bool)::_remove_element_pair_and_remove_empty_octants(Element *p_element, Octant *p_octant, Octant *p_limit) { - bool octant_removed = false; while (true) { - // check all exit conditions if (p_octant == p_limit) // reached limit, nothing to erase, exit @@ -745,7 +701,6 @@ OCTREE_FUNC(bool)::_remove_element_pair_and_remove_empty_octants(Element *p_elem Octant *parent = p_octant->parent; if (p_octant->children_count == 0 && p_octant->elements.empty() && p_octant->pairable_elements.empty()) { - // erase octant if (p_octant == root) { // won't have a parent, just erase @@ -774,7 +729,6 @@ OCTREE_FUNC(bool)::_remove_element_pair_and_remove_empty_octants(Element *p_elem } OCTREE_FUNC(void)::_unpair_element(Element *p_element, Octant *p_octant) { - // always test pairable typename List::Element *E = p_octant->pairable_elements.front(); while (E) { @@ -803,20 +757,17 @@ OCTREE_FUNC(void)::_unpair_element(Element *p_element, Octant *p_octant) { return; // small optimization for leafs for (int i = 0; i < 8; i++) { - if (p_octant->children[i]) _unpair_element(p_element, p_octant->children[i]); } } OCTREE_FUNC(void)::_pair_element(Element *p_element, Octant *p_octant) { - // always test pairable typename List::Element *E = p_octant->pairable_elements.front(); while (E) { - if (E->get()->last_pass != pass) { // only get ONE reference _pair_reference(p_element, E->get()); E->get()->last_pass = pass; @@ -841,20 +792,17 @@ OCTREE_FUNC(void)::_pair_element(Element *p_element, Octant *p_octant) { return; // small optimization for leafs for (int i = 0; i < 8; i++) { - if (p_octant->children[i]) _pair_element(p_element, p_octant->children[i]); } } OCTREE_FUNC(void)::_remove_element(Element *p_element) { - pass++; // will do a new pass for this typename List::Element *I = p_element->octant_owners.front(); for (; I; I = I->next()) { - Octant *o = I->get().octant; if (!use_pairs) { @@ -884,7 +832,6 @@ OCTREE_FUNC(void)::_remove_element(Element *p_element) { p_element->octant_owners.clear(); if (use_pairs) { - int remaining = p_element->pair_list.size(); //p_element->pair_list.clear(); ERR_FAIL_COND(remaining); @@ -892,7 +839,6 @@ OCTREE_FUNC(void)::_remove_element(Element *p_element) { } OCTREE_FUNC(OctreeElementID)::create(T *p_userdata, const AABB &p_aabb, int p_subindex, bool p_pairable, uint32_t p_pairable_type, uint32_t p_pairable_mask) { - // check for AABB validity #ifdef DEBUG_ENABLED ERR_FAIL_COND_V(p_aabb.position.x > 1e15 || p_aabb.position.x < -1e15, 0); @@ -931,7 +877,6 @@ OCTREE_FUNC(OctreeElementID)::create(T *p_userdata, const AABB &p_aabb, int p_su } OCTREE_FUNC(void)::move(OctreeElementID p_id, const AABB &p_aabb) { - #ifdef DEBUG_ENABLED // check for AABB validity ERR_FAIL_COND(p_aabb.position.x > 1e15 || p_aabb.position.x < -1e15); @@ -952,7 +897,6 @@ OCTREE_FUNC(void)::move(OctreeElementID p_id, const AABB &p_aabb) { bool new_has_surf = !p_aabb.has_no_surface(); if (old_has_surf != new_has_surf) { - if (old_has_surf) { _remove_element(&e); // removing e.common_parent = NULL; @@ -975,7 +919,6 @@ OCTREE_FUNC(void)::move(OctreeElementID p_id, const AABB &p_aabb) { // 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) _element_check_pairs(&e); // must check pairs anyway @@ -1016,7 +959,6 @@ OCTREE_FUNC(void)::move(OctreeElementID p_id, const AABB &p_aabb) { pass++; for (typename List::Element *F = owners.front(); F;) { - Octant *o = F->get().octant; typename List::Element *N = F->next(); @@ -1035,7 +977,6 @@ OCTREE_FUNC(void)::move(OctreeElementID p_id, const AABB &p_aabb) { #endif if (_remove_element_pair_and_remove_empty_octants(&e, o, common_parent->parent)) { - owners.erase(F); } @@ -1045,13 +986,11 @@ OCTREE_FUNC(void)::move(OctreeElementID p_id, const AABB &p_aabb) { if (use_pairs) { //unpair child elements in anything that survived for (typename List::Element *F = owners.front(); F; F = F->next()) { - Octant *o = F->get().octant; // erase children pairs, unref ONCE pass++; for (int i = 0; i < 8; i++) { - if (o->children[i]) _unpair_element(&e, o->children[i]); } @@ -1064,7 +1003,6 @@ OCTREE_FUNC(void)::move(OctreeElementID p_id, const AABB &p_aabb) { } OCTREE_FUNC(void)::set_pairable(OctreeElementID p_id, bool p_pairable, uint32_t p_pairable_type, uint32_t p_pairable_mask) { - typename ElementMap::Element *E = element_map.find(p_id); ERR_FAIL_COND(!E); @@ -1091,14 +1029,12 @@ OCTREE_FUNC(void)::set_pairable(OctreeElementID p_id, bool p_pairable, uint32_t } OCTREE_FUNC(void)::erase(OctreeElementID p_id) { - typename ElementMap::Element *E = element_map.find(p_id); ERR_FAIL_COND(!E); Element &e = E->get(); if (!e.aabb.has_no_surface()) { - _remove_element(&e); } @@ -1107,12 +1043,10 @@ OCTREE_FUNC(void)::erase(OctreeElementID p_id) { } OCTREE_FUNC(void)::_cull_convex(Octant *p_octant, _CullConvexData *p_cull) { - if (*p_cull->result_idx == p_cull->result_max) return; //pointless if (!p_octant->elements.empty()) { - #ifdef OCTREE_USE_CACHED_LISTS // make sure cached list of element pointers and aabbs is up to date if this octant is dirty p_octant->update_cached_lists(); @@ -1126,7 +1060,6 @@ OCTREE_FUNC(void)::_cull_convex(Octant *p_octant, _CullConvexData *p_cull) { // The reason is that the later checks are more expensive because they are not in cache, and many of the AABB // tests will fail so we can avoid these cache misses. if (aabb.intersects_convex_shape(p_cull->planes, p_cull->plane_count, p_cull->points, p_cull->point_count)) { - if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_cull->mask))) continue; e->last_pass = pass; @@ -1144,7 +1077,6 @@ OCTREE_FUNC(void)::_cull_convex(Octant *p_octant, _CullConvexData *p_cull) { I = p_octant->elements.front(); for (; I; I = I->next()) { - Element *e = I->get(); const AABB &aabb = e->aabb; @@ -1157,7 +1089,6 @@ OCTREE_FUNC(void)::_cull_convex(Octant *p_octant, _CullConvexData *p_cull) { p_cull->result_array[*p_cull->result_idx] = e->userdata; (*p_cull->result_idx)++; } else { - return; // pointless to continue } } @@ -1166,7 +1097,6 @@ OCTREE_FUNC(void)::_cull_convex(Octant *p_octant, _CullConvexData *p_cull) { } // if elements not empty if (use_pairs && !p_octant->pairable_elements.empty()) { - #ifdef OCTREE_USE_CACHED_LISTS // make sure cached list of element pointers and aabbs is up to date if this octant is dirty p_octant->update_cached_lists(); @@ -1177,7 +1107,6 @@ OCTREE_FUNC(void)::_cull_convex(Octant *p_octant, _CullConvexData *p_cull) { Element *e = p_octant->clist_pairable.elements[n]; if (aabb.intersects_convex_shape(p_cull->planes, p_cull->plane_count, p_cull->points, p_cull->point_count)) { - if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_cull->mask))) continue; e->last_pass = pass; @@ -1186,7 +1115,6 @@ OCTREE_FUNC(void)::_cull_convex(Octant *p_octant, _CullConvexData *p_cull) { p_cull->result_array[*p_cull->result_idx] = e->userdata; (*p_cull->result_idx)++; } else { - return; // pointless to continue } } @@ -1197,7 +1125,6 @@ OCTREE_FUNC(void)::_cull_convex(Octant *p_octant, _CullConvexData *p_cull) { I = p_octant->pairable_elements.front(); for (; I; I = I->next()) { - Element *e = I->get(); const AABB &aabb = e->aabb; @@ -1206,13 +1133,10 @@ OCTREE_FUNC(void)::_cull_convex(Octant *p_octant, _CullConvexData *p_cull) { e->last_pass = pass; if (aabb.intersects_convex_shape(p_cull->planes, p_cull->plane_count, p_cull->points, p_cull->point_count)) { - if (*p_cull->result_idx < p_cull->result_max) { - p_cull->result_array[*p_cull->result_idx] = e->userdata; (*p_cull->result_idx)++; } else { - return; // pointless to continue } } @@ -1221,7 +1145,6 @@ OCTREE_FUNC(void)::_cull_convex(Octant *p_octant, _CullConvexData *p_cull) { } for (int i = 0; i < 8; i++) { - if (p_octant->children[i] && p_octant->children[i]->aabb.intersects_convex_shape(p_cull->planes, p_cull->plane_count, p_cull->points, p_cull->point_count)) { _cull_convex(p_octant->children[i], p_cull); } @@ -1229,12 +1152,10 @@ OCTREE_FUNC(void)::_cull_convex(Octant *p_octant, _CullConvexData *p_cull) { } OCTREE_FUNC(void)::_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) return; //pointless if (!p_octant->elements.empty()) { - #ifdef OCTREE_USE_CACHED_LISTS // make sure cached list of element pointers and aabbs is up to date if this octant is dirty p_octant->update_cached_lists(); @@ -1245,20 +1166,17 @@ OCTREE_FUNC(void)::_cull_aabb(Octant *p_octant, const AABB &p_aabb, T **p_result Element *e = p_octant->clist.elements[n]; if (p_aabb.intersects_inclusive(aabb)) { - if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_mask))) continue; e->last_pass = pass; if (*p_result_idx < p_result_max) { - p_result_array[*p_result_idx] = e->userdata; if (p_subindex_array) p_subindex_array[*p_result_idx] = e->subindex; (*p_result_idx)++; } else { - return; // pointless to continue } } @@ -1267,25 +1185,21 @@ OCTREE_FUNC(void)::_cull_aabb(Octant *p_octant, const AABB &p_aabb, T **p_result typename List::Element *I; I = p_octant->elements.front(); for (; I; I = I->next()) { - Element *e = I->get(); const AABB &aabb = e->aabb; if (p_aabb.intersects_inclusive(aabb)) { - if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_mask))) continue; e->last_pass = pass; if (*p_result_idx < p_result_max) { - p_result_array[*p_result_idx] = e->userdata; if (p_subindex_array) p_subindex_array[*p_result_idx] = e->subindex; (*p_result_idx)++; } else { - return; // pointless to continue } } @@ -1304,19 +1218,16 @@ OCTREE_FUNC(void)::_cull_aabb(Octant *p_octant, const AABB &p_aabb, T **p_result Element *e = p_octant->clist_pairable.elements[n]; if (p_aabb.intersects_inclusive(aabb)) { - if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_mask))) continue; e->last_pass = pass; if (*p_result_idx < p_result_max) { - p_result_array[*p_result_idx] = e->userdata; if (p_subindex_array) p_subindex_array[*p_result_idx] = e->subindex; (*p_result_idx)++; } else { - return; // pointless to continue } } @@ -1326,7 +1237,6 @@ OCTREE_FUNC(void)::_cull_aabb(Octant *p_octant, const AABB &p_aabb, T **p_result typename List::Element *I; I = p_octant->pairable_elements.front(); for (; I; I = I->next()) { - Element *e = I->get(); const AABB &aabb = e->aabb; @@ -1335,15 +1245,12 @@ OCTREE_FUNC(void)::_cull_aabb(Octant *p_octant, const AABB &p_aabb, T **p_result e->last_pass = pass; if (p_aabb.intersects_inclusive(aabb)) { - if (*p_result_idx < p_result_max) { - p_result_array[*p_result_idx] = e->userdata; if (p_subindex_array) p_subindex_array[*p_result_idx] = e->subindex; (*p_result_idx)++; } else { - return; // pointless to continue } } @@ -1352,7 +1259,6 @@ OCTREE_FUNC(void)::_cull_aabb(Octant *p_octant, const AABB &p_aabb, T **p_result } for (int i = 0; i < 8; i++) { - if (p_octant->children[i] && p_octant->children[i]->aabb.intersects_inclusive(p_aabb)) { _cull_aabb(p_octant->children[i], p_aabb, p_result_array, p_result_idx, p_result_max, p_subindex_array, p_mask); } @@ -1360,12 +1266,10 @@ OCTREE_FUNC(void)::_cull_aabb(Octant *p_octant, const AABB &p_aabb, T **p_result } OCTREE_FUNC(void)::_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) return; //pointless if (!p_octant->elements.empty()) { - #ifdef OCTREE_USE_CACHED_LISTS // make sure cached list of element pointers and aabbs is up to date if this octant is dirty p_octant->update_cached_lists(); @@ -1380,16 +1284,13 @@ OCTREE_FUNC(void)::_cull_segment(Octant *p_octant, const Vector3 &p_from, const e->last_pass = pass; if (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) p_subindex_array[*p_result_idx] = e->subindex; (*p_result_idx)++; } else { - return; // pointless to continue } } @@ -1399,7 +1300,6 @@ OCTREE_FUNC(void)::_cull_segment(Octant *p_octant, const Vector3 &p_from, const typename List::Element *I; I = p_octant->elements.front(); for (; I; I = I->next()) { - Element *e = I->get(); const AABB &aabb = e->aabb; @@ -1408,16 +1308,13 @@ OCTREE_FUNC(void)::_cull_segment(Octant *p_octant, const Vector3 &p_from, const e->last_pass = pass; if (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) p_subindex_array[*p_result_idx] = e->subindex; (*p_result_idx)++; } else { - return; // pointless to continue } } @@ -1426,7 +1323,6 @@ OCTREE_FUNC(void)::_cull_segment(Octant *p_octant, const Vector3 &p_from, const } if (use_pairs && !p_octant->pairable_elements.empty()) { - #ifdef OCTREE_USE_CACHED_LISTS // make sure cached list of element pointers and aabbs is up to date if this octant is dirty p_octant->update_cached_lists(); @@ -1442,9 +1338,7 @@ OCTREE_FUNC(void)::_cull_segment(Octant *p_octant, const Vector3 &p_from, const e->last_pass = pass; if (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) p_subindex_array[*p_result_idx] = e->subindex; @@ -1452,7 +1346,6 @@ OCTREE_FUNC(void)::_cull_segment(Octant *p_octant, const Vector3 &p_from, const (*p_result_idx)++; } else { - return; // pointless to continue } } @@ -1461,7 +1354,6 @@ OCTREE_FUNC(void)::_cull_segment(Octant *p_octant, const Vector3 &p_from, const typename List::Element *I; I = p_octant->pairable_elements.front(); for (; I; I = I->next()) { - Element *e = I->get(); const AABB &aabb = e->aabb; @@ -1471,9 +1363,7 @@ OCTREE_FUNC(void)::_cull_segment(Octant *p_octant, const Vector3 &p_from, const e->last_pass = pass; if (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) p_subindex_array[*p_result_idx] = e->subindex; @@ -1481,7 +1371,6 @@ OCTREE_FUNC(void)::_cull_segment(Octant *p_octant, const Vector3 &p_from, const (*p_result_idx)++; } else { - return; // pointless to continue } } @@ -1490,7 +1379,6 @@ OCTREE_FUNC(void)::_cull_segment(Octant *p_octant, const Vector3 &p_from, const } for (int i = 0; i < 8; i++) { - if (p_octant->children[i] && p_octant->children[i]->aabb.intersects_segment(p_from, p_to)) { _cull_segment(p_octant->children[i], p_from, p_to, p_result_array, p_result_idx, p_result_max, p_subindex_array, p_mask); } @@ -1498,12 +1386,10 @@ OCTREE_FUNC(void)::_cull_segment(Octant *p_octant, const Vector3 &p_from, const } OCTREE_FUNC(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) { - if (*p_result_idx == p_result_max) return; //pointless if (!p_octant->elements.empty()) { - #ifdef OCTREE_USE_CACHED_LISTS // make sure cached list of element pointers and aabbs is up to date if this octant is dirty p_octant->update_cached_lists(); @@ -1514,20 +1400,17 @@ OCTREE_FUNC(void)::_cull_point(Octant *p_octant, const Vector3 &p_point, T **p_r Element *e = p_octant->clist.elements[n]; if (aabb.has_point(p_point)) { - if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_mask))) continue; e->last_pass = pass; if (*p_result_idx < p_result_max) { - p_result_array[*p_result_idx] = e->userdata; if (p_subindex_array) p_subindex_array[*p_result_idx] = e->subindex; (*p_result_idx)++; } else { - return; // pointless to continue } } @@ -1536,7 +1419,6 @@ OCTREE_FUNC(void)::_cull_point(Octant *p_octant, const Vector3 &p_point, T **p_r typename List::Element *I; I = p_octant->elements.front(); for (; I; I = I->next()) { - Element *e = I->get(); const AABB &aabb = e->aabb; @@ -1545,16 +1427,13 @@ OCTREE_FUNC(void)::_cull_point(Octant *p_octant, const Vector3 &p_point, T **p_r e->last_pass = pass; if (aabb.has_point(p_point)) { - if (*p_result_idx < p_result_max) { - p_result_array[*p_result_idx] = e->userdata; if (p_subindex_array) p_subindex_array[*p_result_idx] = e->subindex; (*p_result_idx)++; } else { - return; // pointless to continue } } @@ -1563,7 +1442,6 @@ OCTREE_FUNC(void)::_cull_point(Octant *p_octant, const Vector3 &p_point, T **p_r } if (use_pairs && !p_octant->pairable_elements.empty()) { - #ifdef OCTREE_USE_CACHED_LISTS // make sure cached list of element pointers and aabbs is up to date if this octant is dirty p_octant->update_cached_lists(); @@ -1574,14 +1452,12 @@ OCTREE_FUNC(void)::_cull_point(Octant *p_octant, const Vector3 &p_point, T **p_r Element *e = p_octant->clist_pairable.elements[n]; if (aabb.has_point(p_point)) { - if (e->last_pass == pass || (use_pairs && !(e->pairable_type & p_mask))) continue; e->last_pass = pass; if (*p_result_idx < p_result_max) { - p_result_array[*p_result_idx] = e->userdata; if (p_subindex_array) p_subindex_array[*p_result_idx] = e->subindex; @@ -1589,7 +1465,6 @@ OCTREE_FUNC(void)::_cull_point(Octant *p_octant, const Vector3 &p_point, T **p_r (*p_result_idx)++; } else { - return; // pointless to continue } } @@ -1598,7 +1473,6 @@ OCTREE_FUNC(void)::_cull_point(Octant *p_octant, const Vector3 &p_point, T **p_r typename List::Element *I; I = p_octant->pairable_elements.front(); for (; I; I = I->next()) { - Element *e = I->get(); const AABB &aabb = e->aabb; @@ -1608,9 +1482,7 @@ OCTREE_FUNC(void)::_cull_point(Octant *p_octant, const Vector3 &p_point, T **p_r e->last_pass = pass; if (aabb.has_point(p_point)) { - if (*p_result_idx < p_result_max) { - p_result_array[*p_result_idx] = e->userdata; if (p_subindex_array) p_subindex_array[*p_result_idx] = e->subindex; @@ -1618,7 +1490,6 @@ OCTREE_FUNC(void)::_cull_point(Octant *p_octant, const Vector3 &p_point, T **p_r (*p_result_idx)++; } else { - return; // pointless to continue } } @@ -1627,7 +1498,6 @@ OCTREE_FUNC(void)::_cull_point(Octant *p_octant, const Vector3 &p_point, T **p_r } for (int i = 0; i < 8; i++) { - //could be optimized.. if (p_octant->children[i] && p_octant->children[i]->aabb.has_point(p_point)) { _cull_point(p_octant->children[i], p_point, p_result_array, p_result_idx, p_result_max, p_subindex_array, p_mask); @@ -1636,7 +1506,6 @@ OCTREE_FUNC(void)::_cull_point(Octant *p_octant, const Vector3 &p_point, T **p_r } OCTREE_FUNC(int)::cull_convex(const Vector &p_convex, T **p_result_array, int p_result_max, uint32_t p_mask) { - if (!root || p_convex.size() == 0) return 0; @@ -1662,7 +1531,6 @@ OCTREE_FUNC(int)::cull_convex(const Vector &p_convex, T **p_result_array, } OCTREE_FUNC(int)::cull_aabb(const AABB &p_aabb, T **p_result_array, int p_result_max, int *p_subindex_array, uint32_t p_mask) { - if (!root) return 0; @@ -1674,7 +1542,6 @@ OCTREE_FUNC(int)::cull_aabb(const AABB &p_aabb, T **p_result_array, int p_result } OCTREE_FUNC(int)::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) return 0; @@ -1686,7 +1553,6 @@ OCTREE_FUNC(int)::cull_segment(const Vector3 &p_from, const Vector3 &p_to, T **p } OCTREE_FUNC(int)::cull_point(const Vector3 &p_point, T **p_result_array, int p_result_max, int *p_subindex_array, uint32_t p_mask) { - if (!root) return 0; @@ -1698,19 +1564,16 @@ OCTREE_FUNC(int)::cull_point(const Vector3 &p_point, T **p_result_array, int p_r } OCTREE_FUNC(void)::set_pair_callback(PairCallback p_callback, void *p_userdata) { - pair_callback = p_callback; pair_callback_userdata = p_userdata; } OCTREE_FUNC(void)::set_unpair_callback(UnpairCallback p_callback, void *p_userdata) { - unpair_callback = p_callback; unpair_callback_userdata = p_userdata; } OCTREE_FUNC_CONSTRUCTOR::OCTREE_CLASS_NAME(real_t p_unit_size) { - last_element_id = 1; pass = 1; unit_size = p_unit_size; diff --git a/core/math/plane.cpp b/core/math/plane.cpp index d0dd68506db..95c9dc7c727 100644 --- a/core/math/plane.cpp +++ b/core/math/plane.cpp @@ -33,12 +33,10 @@ #include "core/math/math_funcs.h" void Plane::set_normal(const Vector3 &p_normal) { - normal = p_normal; } void Plane::normalize() { - real_t l = normal.length(); if (l == 0) { *this = Plane(0, 0, 0, 0); @@ -49,7 +47,6 @@ void Plane::normalize() { } Plane Plane::normalized() const { - Plane p = *this; p.normalize(); return p; @@ -60,7 +57,6 @@ Vector3 Plane::get_any_point() const { } Vector3 Plane::get_any_perpendicular_normal() const { - static const Vector3 p1 = Vector3(1, 0, 0); static const Vector3 p2 = Vector3(0, 1, 0); Vector3 p; @@ -79,7 +75,6 @@ Vector3 Plane::get_any_perpendicular_normal() const { /* intersections */ bool Plane::intersect_3(const Plane &p_plane1, const Plane &p_plane2, Vector3 *r_result) const { - const Plane &p_plane0 = *this; Vector3 normal0 = p_plane0.normal; Vector3 normal1 = p_plane1.normal; @@ -101,13 +96,11 @@ bool Plane::intersect_3(const Plane &p_plane1, const Plane &p_plane2, Vector3 *r } bool Plane::intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *p_intersection) const { - Vector3 segment = p_dir; real_t den = normal.dot(segment); //printf("den is %i\n",den); if (Math::is_zero_approx(den)) { - return false; } @@ -126,13 +119,11 @@ bool Plane::intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 } bool Plane::intersects_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 *p_intersection) const { - Vector3 segment = p_begin - p_end; real_t den = normal.dot(segment); //printf("den is %i\n",den); if (Math::is_zero_approx(den)) { - return false; } @@ -140,7 +131,6 @@ bool Plane::intersects_segment(const Vector3 &p_begin, const Vector3 &p_end, Vec //printf("dist is %i\n",dist); if (dist < -CMP_EPSILON || dist > (1.0 + CMP_EPSILON)) { - return false; } @@ -153,11 +143,9 @@ bool Plane::intersects_segment(const Vector3 &p_begin, const Vector3 &p_end, Vec /* misc */ bool Plane::is_equal_approx(const Plane &p_plane) const { - return normal.is_equal_approx(p_plane.normal) && Math::is_equal_approx(d, p_plane.d); } Plane::operator String() const { - return normal.operator String() + ", " + rtos(d); } diff --git a/core/math/plane.h b/core/math/plane.h index 9b55667c8c7..843e68db1a2 100644 --- a/core/math/plane.h +++ b/core/math/plane.h @@ -61,7 +61,6 @@ public: bool intersects_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 *p_intersection) const; _FORCE_INLINE_ Vector3 project(const Vector3 &p_point) const { - return p_point - normal * distance_to(p_point); } @@ -86,17 +85,14 @@ public: }; bool Plane::is_point_over(const Vector3 &p_point) const { - return (normal.dot(p_point) > d); } real_t Plane::distance_to(const Vector3 &p_point) const { - return (normal.dot(p_point) - d); } bool Plane::has_point(const Vector3 &p_point, real_t _epsilon) const { - real_t dist = normal.dot(p_point) - d; dist = ABS(dist); return (dist <= _epsilon); @@ -113,7 +109,6 @@ 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) normal = (p_point1 - p_point3).cross(p_point1 - p_point2); else @@ -124,12 +119,10 @@ Plane::Plane(const Vector3 &p_point1, const Vector3 &p_point2, const Vector3 &p_ } bool Plane::operator==(const Plane &p_plane) const { - return normal == p_plane.normal && d == p_plane.d; } bool Plane::operator!=(const Plane &p_plane) const { - return normal != p_plane.normal || d != p_plane.d; } diff --git a/core/math/quat.cpp b/core/math/quat.cpp index 11c023da606..2c895b4dcd8 100644 --- a/core/math/quat.cpp +++ b/core/math/quat.cpp @@ -107,7 +107,6 @@ Vector3 Quat::get_euler_yxz() const { } void Quat::operator*=(const Quat &p_q) { - set(w * p_q.x + x * p_q.w + y * p_q.z - z * p_q.y, w * p_q.y + y * p_q.w + z * p_q.x - x * p_q.z, w * p_q.z + z * p_q.w + x * p_q.y - y * p_q.x, @@ -115,19 +114,16 @@ void Quat::operator*=(const Quat &p_q) { } Quat Quat::operator*(const Quat &p_q) const { - Quat r = *this; r *= p_q; return r; } bool Quat::is_equal_approx(const Quat &p_quat) const { - return Math::is_equal_approx(x, p_quat.x) && Math::is_equal_approx(y, p_quat.y) && Math::is_equal_approx(z, p_quat.z) && Math::is_equal_approx(w, p_quat.w); } real_t Quat::length() const { - return Math::sqrt(length_squared()); } @@ -233,7 +229,6 @@ Quat Quat::cubic_slerp(const Quat &p_b, const Quat &p_pre_a, const Quat &p_post_ } Quat::operator String() const { - return String::num(x) + ", " + String::num(y) + ", " + String::num(z) + ", " + String::num(w); } diff --git a/core/math/quat.h b/core/math/quat.h index 20a94b9df46..4b131738549 100644 --- a/core/math/quat.h +++ b/core/math/quat.h @@ -147,7 +147,6 @@ public: z = 0; w = 0; } else { - real_t s = Math::sqrt((1.0 + d) * 2.0); real_t rs = 1.0 / s; @@ -196,7 +195,6 @@ void Quat::operator*=(const real_t &s) { } void Quat::operator/=(const real_t &s) { - *this *= 1.0 / s; } diff --git a/core/math/quick_hull.cpp b/core/math/quick_hull.cpp index efdd163b4da..62969aa41b5 100644 --- a/core/math/quick_hull.cpp +++ b/core/math/quick_hull.cpp @@ -35,12 +35,10 @@ uint32_t QuickHull::debug_stop_after = 0xFFFFFFFF; Error QuickHull::build(const Vector &p_points, Geometry::MeshData &r_mesh) { - /* CREATE AABB VOLUME */ AABB aabb; for (int i = 0; i < p_points.size(); i++) { - if (i == 0) { aabb.position = p_points[i]; } else { @@ -57,7 +55,6 @@ Error QuickHull::build(const Vector &p_points, Geometry::MeshData &r_me Set valid_cache; for (int i = 0; i < p_points.size(); i++) { - Vector3 sp = p_points[i].snapped(Vector3(0.0001, 0.0001, 0.0001)); if (valid_cache.has(sp)) { valid_points.write[i] = false; @@ -78,12 +75,10 @@ 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]) continue; real_t d = p_points[i][longest_axis]; if (i == 0 || d < min) { - simplex[0] = i; min = d; } @@ -102,7 +97,6 @@ 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]) continue; @@ -110,7 +104,6 @@ Error QuickHull::build(const Vector &p_points, Geometry::MeshData &r_me real_t d = Math::abs(n.dot(p_points[simplex[0]]) - n.dot(p_points[i])); if (i == 0 || d > maxd) { - maxd = d; simplex[2] = i; } @@ -124,14 +117,12 @@ 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]) continue; real_t d = Math::abs(p.distance_to(p_points[i])); if (i == 0 || d > maxd) { - maxd = d; simplex[3] = i; } @@ -152,7 +143,6 @@ Error QuickHull::build(const Vector &p_points, Geometry::MeshData &r_me List faces; for (int i = 0; i < 4; i++) { - static const int face_order[4][3] = { { 0, 1, 2 }, { 0, 1, 3 }, @@ -183,7 +173,6 @@ 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]) continue; if (i == simplex[1]) @@ -196,9 +185,7 @@ Error QuickHull::build(const Vector &p_points, Geometry::MeshData &r_me continue; for (List::Element *E = faces.front(); E; E = E->next()) { - if (E->get().plane.distance_to(p_points[i]) > over_tolerance) { - E->get().points_over.push_back(i); break; } @@ -219,7 +206,6 @@ Error QuickHull::build(const Vector &p_points, Geometry::MeshData &r_me uint32_t debug_stop = debug_stop_after; while (debug_stop > 0 && faces.back()->get().points_over.size()) { - debug_stop--; Face &f = faces.back()->get(); @@ -228,7 +214,6 @@ Error QuickHull::build(const Vector &p_points, Geometry::MeshData &r_me real_t next_d = 0; for (int i = 0; i < f.points_over.size(); i++) { - real_t d = f.plane.distance_to(p_points[f.points_over[i]]); if (d > next_d) { @@ -247,9 +232,7 @@ Error QuickHull::build(const Vector &p_points, Geometry::MeshData &r_me Map lit_edges; //create this on the flight, should not be that bad for performance and simplifies code a lot for (List::Element *E = faces.front(); E; E = E->next()) { - if (E->get().plane.distance_to(v) > 0) { - lit_faces.push_back(E); for (int i = 0; i < 3; i++) { @@ -265,7 +248,6 @@ Error QuickHull::build(const Vector &p_points, Geometry::MeshData &r_me //left F->get().left = E; } else { - F->get().right = E; } } @@ -276,7 +258,6 @@ Error QuickHull::build(const Vector &p_points, Geometry::MeshData &r_me List::Element *> new_faces; //new faces for (Map::Element *E = lit_edges.front(); E; E = E->next()) { - FaceConnect &fc = E->get(); if (fc.left && fc.right) { continue; //edge is uninteresting, not on horizont @@ -304,17 +285,14 @@ Error QuickHull::build(const Vector &p_points, Geometry::MeshData &r_me //distribute points into new faces for (List::Element *>::Element *F = lit_faces.front(); F; F = F->next()) { - 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 continue; Vector3 p = p_points[lf.points_over[i]]; for (List::Element *>::Element *E = new_faces.front(); E; E = E->next()) { - Face &f2 = E->get()->get(); if (f2.plane.distance_to(p) > over_tolerance) { f2.points_over.push_back(lf.points_over[i]); @@ -327,7 +305,6 @@ Error QuickHull::build(const Vector &p_points, Geometry::MeshData &r_me //erase lit faces while (lit_faces.size()) { - faces.erase(lit_faces.front()->get()); lit_faces.pop_front(); } @@ -335,7 +312,6 @@ Error QuickHull::build(const Vector &p_points, Geometry::MeshData &r_me //put faces that contain no points on the front for (List::Element *>::Element *E = new_faces.front(); E; E = E->next()) { - Face &f2 = E->get()->get(); if (f2.points_over.size() == 0) { faces.move_to_front(E->get()); @@ -352,7 +328,6 @@ Error QuickHull::build(const Vector &p_points, Geometry::MeshData &r_me List ret_faces; for (List::Element *E = faces.front(); E; E = E->next()) { - Geometry::MeshData::Face f; f.plane = E->get().plane; @@ -363,7 +338,6 @@ Error QuickHull::build(const Vector &p_points, Geometry::MeshData &r_me List::Element *F = ret_faces.push_back(f); for (int i = 0; i < 3; i++) { - uint32_t a = E->get().vertices[i]; uint32_t b = E->get().vertices[(i + 1) % 3]; Edge e(a, b); @@ -376,7 +350,6 @@ Error QuickHull::build(const Vector &p_points, Geometry::MeshData &r_me //left G->get().left = F; } else { - G->get().right = F; } } @@ -385,11 +358,9 @@ Error QuickHull::build(const Vector &p_points, Geometry::MeshData &r_me //fill faces for (List::Element *E = ret_faces.front(); E; E = E->next()) { - Geometry::MeshData::Face &f = E->get(); for (int i = 0; i < f.indices.size(); i++) { - int a = E->get().indices[i]; int b = E->get().indices[(i + 1) % f.indices.size()]; Edge e(a, b); @@ -411,7 +382,6 @@ Error QuickHull::build(const Vector &p_points, Geometry::MeshData &r_me if (O->get().indices[j] == a) { //append the rest for (int k = 0; k < ois; k++) { - int idx = O->get().indices[(k + j) % ois]; int idxn = O->get().indices[(k + j + 1) % ois]; if (idx == b && idxn == a) { //already have b! @@ -463,7 +433,6 @@ Error QuickHull::build(const Vector &p_points, Geometry::MeshData &r_me r_mesh.edges.resize(ret_edges.size()); idx = 0; for (Map::Element *E = ret_edges.front(); E; E = E->next()) { - Geometry::MeshData::Edge e; e.a = E->key().vertices[0]; e.b = E->key().vertices[1]; diff --git a/core/math/quick_hull.h b/core/math/quick_hull.h index 0dcd891dde8..fd71bc61687 100644 --- a/core/math/quick_hull.h +++ b/core/math/quick_hull.h @@ -37,10 +37,8 @@ #include "core/set.h" class QuickHull { - public: struct Edge { - union { uint32_t vertices[2]; uint64_t id; @@ -51,7 +49,6 @@ public: } Edge(int p_vtx_a = 0, int p_vtx_b = 0) { - if (p_vtx_a > p_vtx_b) { SWAP(p_vtx_a, p_vtx_b); } @@ -62,13 +59,11 @@ public: }; struct Face { - Plane plane; uint32_t vertices[3]; Vector points_over; bool operator<(const Face &p_face) const { - return points_over.size() < p_face.points_over.size(); } }; diff --git a/core/math/rect2.cpp b/core/math/rect2.cpp index 4373930a4f6..ac34cd643f0 100644 --- a/core/math/rect2.cpp +++ b/core/math/rect2.cpp @@ -31,12 +31,10 @@ #include "core/math/transform_2d.h" // Includes rect2.h but Rect2 needs Transform2D bool Rect2::is_equal_approx(const Rect2 &p_rect) const { - return position.is_equal_approx(p_rect.position) && size.is_equal_approx(p_rect.size); } bool Rect2::intersects_segment(const Point2 &p_from, const Point2 &p_to, Point2 *r_pos, Point2 *r_normal) const { - real_t min = 0, max = 1; int axis = 0; real_t sign = 0; @@ -50,7 +48,6 @@ 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) return false; real_t length = seg_to - seg_from; @@ -59,7 +56,6 @@ bool Rect2::intersects_segment(const Point2 &p_from, const Point2 &p_to, Point2 csign = -1.0; } else { - if (seg_to > box_end || seg_from < box_begin) return false; real_t length = seg_to - seg_from; @@ -94,7 +90,6 @@ bool Rect2::intersects_segment(const Point2 &p_from, const Point2 &p_to, Point2 } bool Rect2::intersects_transformed(const Transform2D &p_xform, const Rect2 &p_rect) const { - //SAT intersection between local and transformed rect2 Vector2 xf_points[4] = { diff --git a/core/math/rect2.h b/core/math/rect2.h index ea8aeda8a8c..748fe9d36b2 100644 --- a/core/math/rect2.h +++ b/core/math/rect2.h @@ -36,7 +36,6 @@ struct Transform2D; struct Rect2 { - Point2 position; Size2 size; @@ -72,7 +71,6 @@ struct Rect2 { } inline real_t distance_to(const Vector2 &p_point) const { - real_t dist = 0.0; bool inside = true; @@ -108,14 +106,12 @@ struct Rect2 { bool intersects_segment(const Point2 &p_from, const Point2 &p_to, Point2 *r_pos = NULL, Point2 *r_normal = NULL) const; inline bool encloses(const Rect2 &p_rect) const { - return (p_rect.position.x >= position.x) && (p_rect.position.y >= position.y) && ((p_rect.position.x + p_rect.size.x) <= (position.x + size.x)) && ((p_rect.position.y + p_rect.size.y) <= (position.y + size.y)); } _FORCE_INLINE_ bool has_no_area() const { - return (size.x <= 0 || size.y <= 0); } inline Rect2 clip(const Rect2 &p_rect) const { /// return a clipped rect @@ -192,7 +188,6 @@ struct Rect2 { } inline Rect2 grow_individual(real_t p_left, real_t p_top, real_t p_right, real_t p_bottom) const { - Rect2 g = *this; g.position.x -= p_left; g.position.y -= p_top; @@ -203,7 +198,6 @@ struct Rect2 { } _FORCE_INLINE_ Rect2 expand(const Vector2 &p_vector) const { - Rect2 r = *this; r.expand_to(p_vector); return r; @@ -229,7 +223,6 @@ struct Rect2 { } _FORCE_INLINE_ Rect2 abs() const { - return Rect2(Point2(position.x + MIN(size.x, 0), position.y + MIN(size.y, 0)), size.abs()); } @@ -247,7 +240,6 @@ struct Rect2 { }; struct Rect2i { - Point2i position; Size2i size; @@ -272,14 +264,12 @@ struct Rect2i { } inline bool encloses(const Rect2i &p_rect) const { - return (p_rect.position.x >= position.x) && (p_rect.position.y >= position.y) && ((p_rect.position.x + p_rect.size.x) < (position.x + size.x)) && ((p_rect.position.y + p_rect.size.y) < (position.y + size.y)); } _FORCE_INLINE_ bool has_no_area() const { - return (size.x <= 0 || size.y <= 0); } inline Rect2i clip(const Rect2i &p_rect) const { /// return a clipped rect @@ -333,7 +323,6 @@ struct Rect2i { bool operator!=(const Rect2i &p_rect) const { return position != p_rect.position || size != p_rect.size; } Rect2i grow(int p_by) const { - Rect2i g = *this; g.position.x -= p_by; g.position.y -= p_by; @@ -352,7 +341,6 @@ struct Rect2i { } inline Rect2i grow_individual(int p_left, int p_top, int p_right, int p_bottom) const { - Rect2i g = *this; g.position.x -= p_left; g.position.y -= p_top; @@ -363,14 +351,12 @@ struct Rect2i { } _FORCE_INLINE_ Rect2i expand(const Vector2i &p_vector) const { - Rect2i r = *this; r.expand_to(p_vector); return r; } inline void expand_to(const Point2i &p_vector) { - Point2i begin = position; Point2i end = position + size; diff --git a/core/math/transform.cpp b/core/math/transform.cpp index 91d50b7edbe..ffa68b1b2c2 100644 --- a/core/math/transform.cpp +++ b/core/math/transform.cpp @@ -34,20 +34,17 @@ #include "core/print_string.h" void Transform::affine_invert() { - basis.invert(); origin = basis.xform(-origin); } Transform Transform::affine_inverse() const { - Transform ret = *this; ret.affine_invert(); return ret; } void Transform::invert() { - basis.transpose(); origin = basis.xform(-origin); } @@ -61,22 +58,18 @@ Transform Transform::inverse() const { } void Transform::rotate(const Vector3 &p_axis, real_t p_phi) { - *this = rotated(p_axis, p_phi); } Transform Transform::rotated(const Vector3 &p_axis, real_t p_phi) const { - return Transform(Basis(p_axis, p_phi), Vector3()) * (*this); } void Transform::rotate_basis(const Vector3 &p_axis, real_t p_phi) { - basis.rotate(p_axis, p_phi); } Transform Transform::looking_at(const Vector3 &p_target, const Vector3 &p_up) const { - Transform t = *this; t.set_look_at(origin, p_target, p_up); return t; @@ -116,7 +109,6 @@ void Transform::set_look_at(const Vector3 &p_eye, const Vector3 &p_target, const } Transform Transform::interpolate_with(const Transform &p_transform, real_t p_c) const { - /* not sure if very "efficient" but good enough? */ Vector3 src_scale = basis.get_scale(); @@ -135,20 +127,17 @@ Transform Transform::interpolate_with(const Transform &p_transform, real_t p_c) } void Transform::scale(const Vector3 &p_scale) { - basis.scale(p_scale); origin *= p_scale; } Transform Transform::scaled(const Vector3 &p_scale) const { - Transform t = *this; t.scale(p_scale); return t; } void Transform::scale_basis(const Vector3 &p_scale) { - basis.scale(p_scale); } @@ -156,60 +145,50 @@ void Transform::translate(real_t p_tx, real_t p_ty, real_t p_tz) { translate(Vector3(p_tx, p_ty, p_tz)); } void Transform::translate(const Vector3 &p_translation) { - for (int i = 0; i < 3; i++) { origin[i] += basis[i].dot(p_translation); } } Transform Transform::translated(const Vector3 &p_translation) const { - Transform t = *this; t.translate(p_translation); return t; } void Transform::orthonormalize() { - basis.orthonormalize(); } Transform Transform::orthonormalized() const { - Transform _copy = *this; _copy.orthonormalize(); return _copy; } bool Transform::is_equal_approx(const Transform &p_transform) const { - return basis.is_equal_approx(p_transform.basis) && origin.is_equal_approx(p_transform.origin); } bool Transform::operator==(const Transform &p_transform) const { - return (basis == p_transform.basis && origin == p_transform.origin); } bool Transform::operator!=(const Transform &p_transform) const { - return (basis != p_transform.basis || origin != p_transform.origin); } void Transform::operator*=(const Transform &p_transform) { - origin = xform(p_transform.origin); basis *= p_transform.basis; } Transform Transform::operator*(const Transform &p_transform) const { - Transform t = *this; t *= p_transform; return t; } Transform::operator String() const { - return basis.operator String() + " - " + origin.operator String(); } diff --git a/core/math/transform.h b/core/math/transform.h index c65bbd02609..f8bd2a4baee 100644 --- a/core/math/transform.h +++ b/core/math/transform.h @@ -93,14 +93,12 @@ public: Transform interpolate_with(const Transform &p_transform, real_t p_c) const; _FORCE_INLINE_ Transform inverse_xform(const Transform &t) const { - Vector3 v = t.origin - origin; return Transform(basis.transpose_xform(t.basis), basis.xform(v)); } void set(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz, real_t tx, real_t ty, real_t tz) { - basis.set(xx, xy, xz, yx, yy, yz, zx, zy, zz); origin.x = tx; origin.y = ty; @@ -115,14 +113,12 @@ public: }; _FORCE_INLINE_ Vector3 Transform::xform(const Vector3 &p_vector) const { - return Vector3( basis[0].dot(p_vector) + origin.x, basis[1].dot(p_vector) + origin.y, basis[2].dot(p_vector) + origin.z); } _FORCE_INLINE_ Vector3 Transform::xform_inv(const Vector3 &p_vector) const { - Vector3 v = p_vector - origin; return Vector3( @@ -132,7 +128,6 @@ _FORCE_INLINE_ Vector3 Transform::xform_inv(const Vector3 &p_vector) const { } _FORCE_INLINE_ Plane Transform::xform(const Plane &p_plane) const { - Vector3 point = p_plane.normal * p_plane.d; Vector3 point_dir = point + p_plane.normal; point = xform(point); @@ -145,7 +140,6 @@ _FORCE_INLINE_ Plane Transform::xform(const Plane &p_plane) const { return Plane(normal, d); } _FORCE_INLINE_ Plane Transform::xform_inv(const Plane &p_plane) const { - Vector3 point = p_plane.normal * p_plane.d; Vector3 point_dir = point + p_plane.normal; point = xform_inv(point); @@ -159,7 +153,6 @@ _FORCE_INLINE_ Plane Transform::xform_inv(const Plane &p_plane) const { } _FORCE_INLINE_ AABB Transform::xform(const AABB &p_aabb) const { - /* http://dev.theomader.com/transform-bounding-boxes/ */ Vector3 min = p_aabb.position; Vector3 max = p_aabb.position + p_aabb.size; @@ -185,7 +178,6 @@ _FORCE_INLINE_ AABB Transform::xform(const AABB &p_aabb) const { } _FORCE_INLINE_ AABB Transform::xform_inv(const AABB &p_aabb) const { - /* define vertices */ Vector3 vertices[8] = { Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z + p_aabb.size.z), @@ -203,7 +195,6 @@ _FORCE_INLINE_ AABB Transform::xform_inv(const AABB &p_aabb) const { ret.position = xform_inv(vertices[0]); for (int i = 1; i < 8; i++) { - ret.expand_to(xform_inv(vertices[i])); } @@ -211,7 +202,6 @@ _FORCE_INLINE_ AABB Transform::xform_inv(const AABB &p_aabb) const { } PoolVector Transform::xform(const PoolVector &p_array) const { - PoolVector array; array.resize(p_array.size()); @@ -225,7 +215,6 @@ PoolVector Transform::xform(const PoolVector &p_array) const { } PoolVector Transform::xform_inv(const PoolVector &p_array) const { - PoolVector array; array.resize(p_array.size()); diff --git a/core/math/transform_2d.cpp b/core/math/transform_2d.cpp index 8dd5ab5e646..1319522e3cf 100644 --- a/core/math/transform_2d.cpp +++ b/core/math/transform_2d.cpp @@ -38,14 +38,12 @@ void Transform2D::invert() { } Transform2D Transform2D::inverse() const { - Transform2D inv = *this; inv.invert(); return inv; } void Transform2D::affine_invert() { - real_t det = basis_determinant(); #ifdef MATH_CHECKS ERR_FAIL_COND(det == 0); @@ -60,7 +58,6 @@ void Transform2D::affine_invert() { } Transform2D Transform2D::affine_inverse() const { - Transform2D inv = *this; inv.affine_invert(); return inv; @@ -86,7 +83,6 @@ void Transform2D::set_rotation(real_t p_rot) { } Transform2D::Transform2D(real_t p_rot, const Vector2 &p_pos) { - real_t cr = Math::cos(p_rot); real_t sr = Math::sin(p_rot); elements[0][0] = cr; @@ -113,23 +109,19 @@ void Transform2D::scale(const Size2 &p_scale) { elements[2] *= p_scale; } void Transform2D::scale_basis(const Size2 &p_scale) { - elements[0][0] *= p_scale.x; elements[0][1] *= p_scale.y; elements[1][0] *= p_scale.x; elements[1][1] *= p_scale.y; } void Transform2D::translate(real_t p_tx, real_t p_ty) { - translate(Vector2(p_tx, p_ty)); } void Transform2D::translate(const Vector2 &p_translation) { - elements[2] += basis_xform(p_translation); } void Transform2D::orthonormalize() { - // Gram-Schmidt Process Vector2 x = elements[0]; @@ -144,19 +136,16 @@ void Transform2D::orthonormalize() { } Transform2D Transform2D::orthonormalized() const { - Transform2D on = *this; on.orthonormalize(); return on; } bool Transform2D::is_equal_approx(const Transform2D &p_transform) const { - return elements[0].is_equal_approx(p_transform.elements[0]) && elements[1].is_equal_approx(p_transform.elements[1]) && elements[2].is_equal_approx(p_transform.elements[2]); } bool Transform2D::operator==(const Transform2D &p_transform) const { - for (int i = 0; i < 3; i++) { if (elements[i] != p_transform.elements[i]) return false; @@ -166,7 +155,6 @@ 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]) return true; @@ -176,7 +164,6 @@ bool Transform2D::operator!=(const Transform2D &p_transform) const { } void Transform2D::operator*=(const Transform2D &p_transform) { - elements[2] = xform(p_transform.elements[2]); real_t x0, x1, y0, y1; @@ -193,54 +180,46 @@ void Transform2D::operator*=(const Transform2D &p_transform) { } Transform2D Transform2D::operator*(const Transform2D &p_transform) const { - Transform2D t = *this; t *= p_transform; return t; } Transform2D Transform2D::scaled(const Size2 &p_scale) const { - Transform2D copy = *this; copy.scale(p_scale); return copy; } Transform2D Transform2D::basis_scaled(const Size2 &p_scale) const { - Transform2D copy = *this; copy.scale_basis(p_scale); return copy; } Transform2D Transform2D::untranslated() const { - Transform2D copy = *this; copy.elements[2] = Vector2(); return copy; } Transform2D Transform2D::translated(const Vector2 &p_offset) const { - Transform2D copy = *this; copy.translate(p_offset); return copy; } Transform2D Transform2D::rotated(real_t p_phi) const { - Transform2D copy = *this; copy.rotate(p_phi); return copy; } real_t Transform2D::basis_determinant() const { - return elements[0].x * elements[1].y - elements[0].y * elements[1].x; } Transform2D Transform2D::interpolate_with(const Transform2D &p_transform, real_t p_c) const { - //extract parameters Vector2 p1 = get_origin(); Vector2 p2 = p_transform.get_origin(); @@ -276,6 +255,5 @@ Transform2D Transform2D::interpolate_with(const Transform2D &p_transform, real_t } Transform2D::operator String() const { - return String(String() + elements[0] + ", " + elements[1] + ", " + elements[2]); } diff --git a/core/math/transform_2d.h b/core/math/transform_2d.h index f4b0f738b80..e8a1fed2303 100644 --- a/core/math/transform_2d.h +++ b/core/math/transform_2d.h @@ -118,7 +118,6 @@ struct Transform2D { operator String() const; Transform2D(real_t xx, real_t xy, real_t yx, real_t yy, real_t ox, real_t oy) { - elements[0][0] = xx; elements[0][1] = xy; elements[1][0] = yx; @@ -135,28 +134,24 @@ struct Transform2D { }; Vector2 Transform2D::basis_xform(const Vector2 &p_vec) const { - return Vector2( tdotx(p_vec), tdoty(p_vec)); } Vector2 Transform2D::basis_xform_inv(const Vector2 &p_vec) const { - return Vector2( elements[0].dot(p_vec), elements[1].dot(p_vec)); } Vector2 Transform2D::xform(const Vector2 &p_vec) const { - return Vector2( tdotx(p_vec), tdoty(p_vec)) + elements[2]; } Vector2 Transform2D::xform_inv(const Vector2 &p_vec) const { - Vector2 v = p_vec - elements[2]; return Vector2( @@ -164,7 +159,6 @@ Vector2 Transform2D::xform_inv(const Vector2 &p_vec) const { elements[1].dot(v)); } Rect2 Transform2D::xform(const Rect2 &p_rect) const { - Vector2 x = elements[0] * p_rect.size.x; Vector2 y = elements[1] * p_rect.size.y; Vector2 pos = xform(p_rect.position); @@ -178,7 +172,6 @@ Rect2 Transform2D::xform(const Rect2 &p_rect) const { } void Transform2D::set_rotation_and_scale(real_t p_rot, const Size2 &p_scale) { - elements[0][0] = Math::cos(p_rot) * p_scale.x; elements[1][1] = Math::cos(p_rot) * p_scale.y; elements[1][0] = -Math::sin(p_rot) * p_scale.y; @@ -186,7 +179,6 @@ void Transform2D::set_rotation_and_scale(real_t p_rot, const Size2 &p_scale) { } Rect2 Transform2D::xform_inv(const Rect2 &p_rect) const { - Vector2 ends[4] = { xform_inv(p_rect.position), xform_inv(Vector2(p_rect.position.x, p_rect.position.y + p_rect.size.y)), @@ -204,7 +196,6 @@ Rect2 Transform2D::xform_inv(const Rect2 &p_rect) const { } PoolVector Transform2D::xform(const PoolVector &p_array) const { - PoolVector array; array.resize(p_array.size()); @@ -218,7 +209,6 @@ PoolVector Transform2D::xform(const PoolVector &p_array) const } PoolVector Transform2D::xform_inv(const PoolVector &p_array) const { - PoolVector array; array.resize(p_array.size()); diff --git a/core/math/triangle_mesh.cpp b/core/math/triangle_mesh.cpp index 779bb174379..caba8b8342a 100644 --- a/core/math/triangle_mesh.cpp +++ b/core/math/triangle_mesh.cpp @@ -33,30 +33,25 @@ #include "core/sort_array.h" int TriangleMesh::_create_bvh(BVH *p_bvh, BVH **p_bb, int p_from, int p_size, int p_depth, int &max_depth, int &max_alloc) { - if (p_depth > max_depth) { max_depth = p_depth; } if (p_size == 1) { - return p_bb[p_from] - p_bvh; } else if (p_size == 0) { - return -1; } AABB aabb; aabb = p_bb[p_from]->aabb; for (int i = 1; i < p_size; i++) { - aabb.merge_with(p_bb[p_from + i]->aabb); } int li = aabb.get_longest_axis_index(); switch (li) { - case Vector3::AXIS_X: { SortArray sort_x; sort_x.nth_element(0, p_size, p_size / 2, &p_bb[p_from]); @@ -90,7 +85,6 @@ int TriangleMesh::_create_bvh(BVH *p_bvh, BVH **p_bb, int p_from, int p_size, in } void TriangleMesh::get_indices(PoolVector *r_triangles_indices) const { - if (!valid) return; @@ -110,7 +104,6 @@ void TriangleMesh::get_indices(PoolVector *r_triangles_indices) const { } void TriangleMesh::create(const PoolVector &p_faces) { - valid = false; int fc = p_faces.size(); @@ -122,7 +115,6 @@ void TriangleMesh::create(const PoolVector &p_faces) { PoolVector::Write bw = bvh.write(); { - //create faces and indices and base bvh //except for the Set for repeated triangles, everything //goes in-place. @@ -132,12 +124,10 @@ void TriangleMesh::create(const PoolVector &p_faces) { Map db; for (int i = 0; i < fc; i++) { - Triangle &f = w[i]; const Vector3 *v = &r[i * 3]; for (int j = 0; j < 3; j++) { - int vidx = -1; Vector3 vs = v[j].snapped(Vector3(0.0001, 0.0001, 0.0001)); Map::Element *E = db.find(vs); @@ -174,7 +164,6 @@ void TriangleMesh::create(const PoolVector &p_faces) { bwptrs.resize(fc); PoolVector::Write bwp = bwptrs.write(); for (int i = 0; i < fc; i++) { - bwp[i] = &bw[i]; } @@ -189,7 +178,6 @@ void TriangleMesh::create(const PoolVector &p_faces) { } Vector3 TriangleMesh::get_area_normal(const AABB &p_aabb) const { - uint32_t *stack = (uint32_t *)alloca(sizeof(int) * max_depth); enum { @@ -218,23 +206,18 @@ Vector3 TriangleMesh::get_area_normal(const AABB &p_aabb) const { stack[0] = pos; while (true) { - uint32_t node = stack[level] & NODE_IDX_MASK; const BVH &b = bvhptr[node]; bool done = false; switch (stack[level] >> VISITED_BIT_SHIFT) { case TEST_AABB_BIT: { - bool valid = b.aabb.intersects(p_aabb); if (!valid) { - stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node; } else { - if (b.face_index >= 0) { - const Triangle &s = triangleptr[b.face_index]; n += s.normal; n_count++; @@ -242,28 +225,24 @@ Vector3 TriangleMesh::get_area_normal(const AABB &p_aabb) const { stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node; } else { - stack[level] = (VISIT_LEFT_BIT << VISITED_BIT_SHIFT) | node; } } continue; } case VISIT_LEFT_BIT: { - stack[level] = (VISIT_RIGHT_BIT << VISITED_BIT_SHIFT) | node; stack[level + 1] = b.left | TEST_AABB_BIT; level++; continue; } case VISIT_RIGHT_BIT: { - stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node; stack[level + 1] = b.right | TEST_AABB_BIT; level++; continue; } case VISIT_DONE_BIT: { - if (level == 0) { done = true; break; @@ -284,7 +263,6 @@ Vector3 TriangleMesh::get_area_normal(const AABB &p_aabb) const { } bool TriangleMesh::intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_point, Vector3 &r_normal) const { - uint32_t *stack = (uint32_t *)alloca(sizeof(int) * max_depth); enum { @@ -315,35 +293,28 @@ bool TriangleMesh::intersect_segment(const Vector3 &p_begin, const Vector3 &p_en stack[0] = pos; while (true) { - uint32_t node = stack[level] & NODE_IDX_MASK; const BVH &b = bvhptr[node]; bool done = false; switch (stack[level] >> VISITED_BIT_SHIFT) { case TEST_AABB_BIT: { - bool valid = b.aabb.intersects_segment(p_begin, p_end); //bool valid = b.aabb.intersects(ray_aabb); if (!valid) { - stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node; } else { - if (b.face_index >= 0) { - const Triangle &s = triangleptr[b.face_index]; Face3 f3(vertexptr[s.indices[0]], vertexptr[s.indices[1]], vertexptr[s.indices[2]]); Vector3 res; if (f3.intersects_segment(p_begin, p_end, &res)) { - real_t nd = n.dot(res); if (nd < d) { - d = nd; r_point = res; r_normal = f3.get_plane().get_normal(); @@ -354,28 +325,24 @@ bool TriangleMesh::intersect_segment(const Vector3 &p_begin, const Vector3 &p_en stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node; } else { - stack[level] = (VISIT_LEFT_BIT << VISITED_BIT_SHIFT) | node; } } continue; } case VISIT_LEFT_BIT: { - stack[level] = (VISIT_RIGHT_BIT << VISITED_BIT_SHIFT) | node; stack[level + 1] = b.left | TEST_AABB_BIT; level++; continue; } case VISIT_RIGHT_BIT: { - stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node; stack[level + 1] = b.right | TEST_AABB_BIT; level++; continue; } case VISIT_DONE_BIT: { - if (level == 0) { done = true; break; @@ -390,7 +357,6 @@ bool TriangleMesh::intersect_segment(const Vector3 &p_begin, const Vector3 &p_en } if (inters) { - if (n.dot(r_normal) > 0) r_normal = -r_normal; } @@ -399,7 +365,6 @@ bool TriangleMesh::intersect_segment(const Vector3 &p_begin, const Vector3 &p_en } bool TriangleMesh::intersect_ray(const Vector3 &p_begin, const Vector3 &p_dir, Vector3 &r_point, Vector3 &r_normal) const { - uint32_t *stack = (uint32_t *)alloca(sizeof(int) * max_depth); enum { @@ -430,33 +395,26 @@ bool TriangleMesh::intersect_ray(const Vector3 &p_begin, const Vector3 &p_dir, V stack[0] = pos; while (true) { - uint32_t node = stack[level] & NODE_IDX_MASK; const BVH &b = bvhptr[node]; bool done = false; switch (stack[level] >> VISITED_BIT_SHIFT) { case TEST_AABB_BIT: { - bool valid = b.aabb.intersects_ray(p_begin, p_dir); if (!valid) { - stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node; } else { - if (b.face_index >= 0) { - const Triangle &s = triangleptr[b.face_index]; Face3 f3(vertexptr[s.indices[0]], vertexptr[s.indices[1]], vertexptr[s.indices[2]]); Vector3 res; if (f3.intersects_ray(p_begin, p_dir, &res)) { - real_t nd = n.dot(res); if (nd < d) { - d = nd; r_point = res; r_normal = f3.get_plane().get_normal(); @@ -467,28 +425,24 @@ bool TriangleMesh::intersect_ray(const Vector3 &p_begin, const Vector3 &p_dir, V stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node; } else { - stack[level] = (VISIT_LEFT_BIT << VISITED_BIT_SHIFT) | node; } } continue; } case VISIT_LEFT_BIT: { - stack[level] = (VISIT_RIGHT_BIT << VISITED_BIT_SHIFT) | node; stack[level + 1] = b.left | TEST_AABB_BIT; level++; continue; } case VISIT_RIGHT_BIT: { - stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node; stack[level + 1] = b.right | TEST_AABB_BIT; level++; continue; } case VISIT_DONE_BIT: { - if (level == 0) { done = true; break; @@ -503,7 +457,6 @@ bool TriangleMesh::intersect_ray(const Vector3 &p_begin, const Vector3 &p_dir, V } if (inters) { - if (n.dot(r_normal) > 0) r_normal = -r_normal; } @@ -540,23 +493,18 @@ bool TriangleMesh::intersect_convex_shape(const Plane *p_planes, int p_plane_cou stack[0] = pos; while (true) { - uint32_t node = stack[level] & NODE_IDX_MASK; const BVH &b = bvhptr[node]; bool done = false; switch (stack[level] >> VISITED_BIT_SHIFT) { case TEST_AABB_BIT: { - bool valid = b.aabb.intersects_convex_shape(p_planes, p_plane_count, p_points, p_point_count); if (!valid) { - stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node; } else { - if (b.face_index >= 0) { - const Triangle &s = triangleptr[b.face_index]; for (int j = 0; j < 3; ++j) { @@ -594,28 +542,24 @@ bool TriangleMesh::intersect_convex_shape(const Plane *p_planes, int p_plane_cou stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node; } else { - stack[level] = (VISIT_LEFT_BIT << VISITED_BIT_SHIFT) | node; } } continue; } case VISIT_LEFT_BIT: { - stack[level] = (VISIT_RIGHT_BIT << VISITED_BIT_SHIFT) | node; stack[level + 1] = b.left | TEST_AABB_BIT; level++; continue; } case VISIT_RIGHT_BIT: { - stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node; stack[level + 1] = b.right | TEST_AABB_BIT; level++; continue; } case VISIT_DONE_BIT: { - if (level == 0) { done = true; break; @@ -661,25 +605,21 @@ bool TriangleMesh::inside_convex_shape(const Plane *p_planes, int p_plane_count, stack[0] = pos; while (true) { - uint32_t node = stack[level] & NODE_IDX_MASK; const BVH &b = bvhptr[node]; bool done = false; 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) return false; bool inside = scale.xform(b.aabb).inside_convex_shape(p_planes, p_plane_count); if (inside) { - stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node; } else { - if (b.face_index >= 0) { const Triangle &s = triangleptr[b.face_index]; for (int j = 0; j < 3; ++j) { @@ -694,28 +634,24 @@ bool TriangleMesh::inside_convex_shape(const Plane *p_planes, int p_plane_count, stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node; } else { - stack[level] = (VISIT_LEFT_BIT << VISITED_BIT_SHIFT) | node; } } continue; } case VISIT_LEFT_BIT: { - stack[level] = (VISIT_RIGHT_BIT << VISITED_BIT_SHIFT) | node; stack[level + 1] = b.left | TEST_AABB_BIT; level++; continue; } case VISIT_RIGHT_BIT: { - stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node; stack[level + 1] = b.right | TEST_AABB_BIT; level++; continue; } case VISIT_DONE_BIT: { - if (level == 0) { done = true; break; @@ -733,12 +669,10 @@ bool TriangleMesh::inside_convex_shape(const Plane *p_planes, int p_plane_count, } bool TriangleMesh::is_valid() const { - return valid; } PoolVector TriangleMesh::get_faces() const { - if (!valid) return PoolVector(); @@ -761,7 +695,6 @@ PoolVector TriangleMesh::get_faces() const { } TriangleMesh::TriangleMesh() { - valid = false; max_depth = 0; } diff --git a/core/math/triangle_mesh.h b/core/math/triangle_mesh.h index a8b32382640..15c890c16a6 100644 --- a/core/math/triangle_mesh.h +++ b/core/math/triangle_mesh.h @@ -35,11 +35,9 @@ #include "core/reference.h" class TriangleMesh : public Reference { - GDCLASS(TriangleMesh, Reference); struct Triangle { - Vector3 normal; int indices[3]; }; @@ -48,7 +46,6 @@ class TriangleMesh : public Reference { PoolVector vertices; struct BVH { - AABB aabb; Vector3 center; //used for sorting int left; @@ -58,24 +55,18 @@ class TriangleMesh : public Reference { }; struct BVHCmpX { - bool operator()(const BVH *p_left, const BVH *p_right) const { - return p_left->center.x < p_right->center.x; } }; struct BVHCmpY { - bool operator()(const BVH *p_left, const BVH *p_right) const { - return p_left->center.y < p_right->center.y; } }; struct BVHCmpZ { - bool operator()(const BVH *p_left, const BVH *p_right) const { - return p_left->center.z < p_right->center.z; } }; diff --git a/core/math/triangulate.cpp b/core/math/triangulate.cpp index 22afd333793..107ce08d1f6 100644 --- a/core/math/triangulate.cpp +++ b/core/math/triangulate.cpp @@ -31,7 +31,6 @@ #include "triangulate.h" real_t Triangulate::get_area(const Vector &contour) { - int n = contour.size(); const Vector2 *c = &contour[0]; diff --git a/core/math/vector2.cpp b/core/math/vector2.cpp index 3f91f201fd5..3c580b92f87 100644 --- a/core/math/vector2.cpp +++ b/core/math/vector2.cpp @@ -31,25 +31,20 @@ #include "vector2.h" real_t Vector2::angle() const { - return Math::atan2(y, x); } real_t Vector2::length() const { - return Math::sqrt(x * x + y * y); } real_t Vector2::length_squared() const { - return x * x + y * y; } void Vector2::normalize() { - real_t l = x * x + y * y; if (l != 0) { - l = Math::sqrt(l); x /= l; y /= l; @@ -57,7 +52,6 @@ void Vector2::normalize() { } Vector2 Vector2::normalized() const { - Vector2 v = *this; v.normalize(); return v; @@ -69,57 +63,46 @@ bool Vector2::is_normalized() const { } real_t Vector2::distance_to(const Vector2 &p_vector2) const { - return Math::sqrt((x - p_vector2.x) * (x - p_vector2.x) + (y - p_vector2.y) * (y - p_vector2.y)); } real_t Vector2::distance_squared_to(const Vector2 &p_vector2) const { - return (x - p_vector2.x) * (x - p_vector2.x) + (y - p_vector2.y) * (y - p_vector2.y); } real_t Vector2::angle_to(const Vector2 &p_vector2) const { - return Math::atan2(cross(p_vector2), dot(p_vector2)); } real_t Vector2::angle_to_point(const Vector2 &p_vector2) const { - return Math::atan2(y - p_vector2.y, x - p_vector2.x); } real_t Vector2::dot(const Vector2 &p_other) const { - return x * p_other.x + y * p_other.y; } real_t Vector2::cross(const Vector2 &p_other) const { - return x * p_other.y - y * p_other.x; } Vector2 Vector2::sign() const { - return Vector2(SGN(x), SGN(y)); } Vector2 Vector2::floor() const { - return Vector2(Math::floor(x), Math::floor(y)); } Vector2 Vector2::ceil() const { - return Vector2(Math::ceil(x), Math::ceil(y)); } Vector2 Vector2::round() const { - return Vector2(Math::round(x), Math::round(y)); } Vector2 Vector2::rotated(real_t p_by) const { - Vector2 v; v.set_rotation(angle() + p_by); v *= length(); @@ -139,18 +122,15 @@ Vector2 Vector2::project(const Vector2 &p_to) const { } Vector2 Vector2::snapped(const Vector2 &p_by) const { - return Vector2( Math::stepify(x, p_by.x), Math::stepify(y, p_by.y)); } Vector2 Vector2::clamped(real_t p_len) const { - real_t l = length(); Vector2 v = *this; if (l > 0 && p_len < l) { - v /= l; v *= p_len; } @@ -159,7 +139,6 @@ Vector2 Vector2::clamped(real_t p_len) const { } Vector2 Vector2::cubic_interpolate(const Vector2 &p_b, const Vector2 &p_pre_a, const Vector2 &p_post_b, real_t p_weight) const { - Vector2 p0 = p_pre_a; Vector2 p1 = *this; Vector2 p2 = p_b; @@ -210,65 +189,52 @@ bool Vector2::is_equal_approx(const Vector2 &p_v) const { /* Vector2i */ Vector2i Vector2i::operator+(const Vector2i &p_v) const { - return Vector2i(x + p_v.x, y + p_v.y); } void Vector2i::operator+=(const Vector2i &p_v) { - x += p_v.x; y += p_v.y; } Vector2i Vector2i::operator-(const Vector2i &p_v) const { - return Vector2i(x - p_v.x, y - p_v.y); } void Vector2i::operator-=(const Vector2i &p_v) { - x -= p_v.x; y -= p_v.y; } Vector2i Vector2i::operator*(const Vector2i &p_v1) const { - return Vector2i(x * p_v1.x, y * p_v1.y); }; Vector2i Vector2i::operator*(const int &rvalue) const { - return Vector2i(x * rvalue, y * rvalue); }; void Vector2i::operator*=(const int &rvalue) { - x *= rvalue; y *= rvalue; }; Vector2i Vector2i::operator/(const Vector2i &p_v1) const { - return Vector2i(x / p_v1.x, y / p_v1.y); }; Vector2i Vector2i::operator/(const int &rvalue) const { - return Vector2i(x / rvalue, y / rvalue); }; void Vector2i::operator/=(const int &rvalue) { - x /= rvalue; y /= rvalue; }; Vector2i Vector2i::operator-() const { - return Vector2i(-x, -y); } bool Vector2i::operator==(const Vector2i &p_vec2) const { - return x == p_vec2.x && y == p_vec2.y; } bool Vector2i::operator!=(const Vector2i &p_vec2) const { - return x != p_vec2.x || y != p_vec2.y; } diff --git a/core/math/vector2.h b/core/math/vector2.h index c040be1173f..96ff644905d 100644 --- a/core/math/vector2.h +++ b/core/math/vector2.h @@ -143,19 +143,16 @@ struct Vector2 { real_t angle() const; void set_rotation(real_t p_radians) { - x = Math::cos(p_radians); y = Math::sin(p_radians); } _FORCE_INLINE_ Vector2 abs() const { - return Vector2(Math::abs(x), Math::abs(y)); } Vector2 rotated(real_t p_by) const; Vector2 tangent() const { - return Vector2(y, -x); } @@ -176,81 +173,65 @@ struct Vector2 { }; _FORCE_INLINE_ Vector2 Vector2::plane_project(real_t p_d, const Vector2 &p_vec) const { - return p_vec - *this * (dot(p_vec) - p_d); } _FORCE_INLINE_ Vector2 operator*(real_t p_scalar, const Vector2 &p_vec) { - return p_vec * p_scalar; } _FORCE_INLINE_ Vector2 Vector2::operator+(const Vector2 &p_v) const { - return Vector2(x + p_v.x, y + p_v.y); } _FORCE_INLINE_ void Vector2::operator+=(const Vector2 &p_v) { - x += p_v.x; y += p_v.y; } _FORCE_INLINE_ Vector2 Vector2::operator-(const Vector2 &p_v) const { - return Vector2(x - p_v.x, y - p_v.y); } _FORCE_INLINE_ void Vector2::operator-=(const Vector2 &p_v) { - x -= p_v.x; y -= p_v.y; } _FORCE_INLINE_ Vector2 Vector2::operator*(const Vector2 &p_v1) const { - return Vector2(x * p_v1.x, y * p_v1.y); }; _FORCE_INLINE_ Vector2 Vector2::operator*(const real_t &rvalue) const { - return Vector2(x * rvalue, y * rvalue); }; _FORCE_INLINE_ void Vector2::operator*=(const real_t &rvalue) { - x *= rvalue; y *= rvalue; }; _FORCE_INLINE_ Vector2 Vector2::operator/(const Vector2 &p_v1) const { - return Vector2(x / p_v1.x, y / p_v1.y); }; _FORCE_INLINE_ Vector2 Vector2::operator/(const real_t &rvalue) const { - return Vector2(x / rvalue, y / rvalue); }; _FORCE_INLINE_ void Vector2::operator/=(const real_t &rvalue) { - x /= rvalue; y /= rvalue; }; _FORCE_INLINE_ Vector2 Vector2::operator-() const { - return Vector2(-x, -y); } _FORCE_INLINE_ bool Vector2::operator==(const Vector2 &p_vec2) const { - return x == p_vec2.x && y == p_vec2.y; } _FORCE_INLINE_ bool Vector2::operator!=(const Vector2 &p_vec2) const { - return x != p_vec2.x || y != p_vec2.y; } Vector2 Vector2::linear_interpolate(const Vector2 &p_to, real_t p_weight) const { - Vector2 res = *this; res.x += (p_weight * (p_to.x - x)); @@ -274,7 +255,6 @@ Vector2 Vector2::direction_to(const Vector2 &p_to) const { } Vector2 Vector2::linear_interpolate(const Vector2 &p_a, const Vector2 &p_b, real_t p_weight) { - Vector2 res = p_a; res.x += (p_weight * (p_b.x - p_a.x)); @@ -289,7 +269,6 @@ typedef Vector2 Point2; /* INTEGER STUFF */ struct Vector2i { - enum Axis { AXIS_X, AXIS_Y, diff --git a/core/math/vector3.cpp b/core/math/vector3.cpp index f37a32443f1..3bc715b2e85 100644 --- a/core/math/vector3.cpp +++ b/core/math/vector3.cpp @@ -33,12 +33,10 @@ #include "core/math/basis.h" void Vector3::rotate(const Vector3 &p_axis, real_t p_phi) { - *this = Basis(p_axis, p_phi).xform(*this); } Vector3 Vector3::rotated(const Vector3 &p_axis, real_t p_phi) const { - Vector3 r = *this; r.rotate(p_axis, p_phi); return r; @@ -49,26 +47,22 @@ void Vector3::set_axis(int p_axis, real_t p_value) { coord[p_axis] = p_value; } real_t Vector3::get_axis(int p_axis) const { - ERR_FAIL_INDEX_V(p_axis, 3, 0); return operator[](p_axis); } void Vector3::snap(Vector3 p_val) { - x = Math::stepify(x, p_val.x); y = Math::stepify(y, p_val.y); z = Math::stepify(z, p_val.z); } Vector3 Vector3::snapped(Vector3 p_val) const { - Vector3 v = *this; v.snap(p_val); return v; } Vector3 Vector3::cubic_interpolaten(const Vector3 &p_b, const Vector3 &p_pre_a, const Vector3 &p_post_b, real_t p_weight) const { - Vector3 p0 = p_pre_a; Vector3 p1 = *this; Vector3 p2 = p_b; @@ -100,7 +94,6 @@ Vector3 Vector3::cubic_interpolaten(const Vector3 &p_b, const Vector3 &p_pre_a, } Vector3 Vector3::cubic_interpolate(const Vector3 &p_b, const Vector3 &p_pre_a, const Vector3 &p_post_b, real_t p_weight) const { - Vector3 p0 = p_pre_a; Vector3 p1 = *this; Vector3 p2 = p_b; @@ -126,7 +119,6 @@ Vector3 Vector3::move_toward(const Vector3 &p_to, const real_t p_delta) const { } Basis Vector3::outer(const Vector3 &p_b) const { - Vector3 row0(x * p_b.x, x * p_b.y, x * p_b.z); Vector3 row1(y * p_b.x, y * p_b.y, y * p_b.z); Vector3 row2(z * p_b.x, z * p_b.y, z * p_b.z); @@ -141,11 +133,9 @@ Basis Vector3::to_diagonal_matrix() const { } bool Vector3::is_equal_approx(const Vector3 &p_v) const { - return Math::is_equal_approx(x, p_v.x) && Math::is_equal_approx(y, p_v.y) && Math::is_equal_approx(z, p_v.z); } Vector3::operator String() const { - return (rtos(x) + ", " + rtos(y) + ", " + rtos(z)); } diff --git a/core/math/vector3.h b/core/math/vector3.h index 65227d53cc1..89e9a5efffe 100644 --- a/core/math/vector3.h +++ b/core/math/vector3.h @@ -56,12 +56,10 @@ struct Vector3 { }; _FORCE_INLINE_ const real_t &operator[](int p_axis) const { - return coord[p_axis]; } _FORCE_INLINE_ real_t &operator[](int p_axis) { - return coord[p_axis]; } @@ -167,7 +165,6 @@ struct Vector3 { }; Vector3 Vector3::cross(const Vector3 &p_b) const { - Vector3 ret( (y * p_b.z) - (z * p_b.y), (z * p_b.x) - (x * p_b.z), @@ -177,37 +174,30 @@ Vector3 Vector3::cross(const Vector3 &p_b) const { } real_t Vector3::dot(const Vector3 &p_b) const { - return x * p_b.x + y * p_b.y + z * p_b.z; } Vector3 Vector3::abs() const { - return Vector3(Math::abs(x), Math::abs(y), Math::abs(z)); } Vector3 Vector3::sign() const { - return Vector3(SGN(x), SGN(y), SGN(z)); } Vector3 Vector3::floor() const { - return Vector3(Math::floor(x), Math::floor(y), Math::floor(z)); } Vector3 Vector3::ceil() const { - return Vector3(Math::ceil(x), Math::ceil(y), Math::ceil(z)); } Vector3 Vector3::round() const { - return Vector3(Math::round(x), Math::round(y), Math::round(z)); } Vector3 Vector3::linear_interpolate(const Vector3 &p_to, real_t p_weight) const { - return Vector3( x + (p_weight * (p_to.x - x)), y + (p_weight * (p_to.y - y)), @@ -220,12 +210,10 @@ Vector3 Vector3::slerp(const Vector3 &p_to, real_t p_weight) const { } real_t Vector3::distance_to(const Vector3 &p_to) const { - return (p_to - *this).length(); } real_t Vector3::distance_squared_to(const Vector3 &p_to) const { - return (p_to - *this).length_squared(); } @@ -242,7 +230,6 @@ Vector3 Vector3::project(const Vector3 &p_to) const { } real_t Vector3::angle_to(const Vector3 &p_to) const { - return Math::atan2(cross(p_to).length(), dot(p_to)); } @@ -255,7 +242,6 @@ Vector3 Vector3::direction_to(const Vector3 &p_to) const { /* Operators */ Vector3 &Vector3::operator+=(const Vector3 &p_v) { - x += p_v.x; y += p_v.y; z += p_v.z; @@ -263,36 +249,30 @@ Vector3 &Vector3::operator+=(const Vector3 &p_v) { } Vector3 Vector3::operator+(const Vector3 &p_v) const { - return Vector3(x + p_v.x, y + p_v.y, z + p_v.z); } Vector3 &Vector3::operator-=(const Vector3 &p_v) { - x -= p_v.x; y -= p_v.y; z -= p_v.z; return *this; } Vector3 Vector3::operator-(const Vector3 &p_v) const { - return Vector3(x - p_v.x, y - p_v.y, z - p_v.z); } Vector3 &Vector3::operator*=(const Vector3 &p_v) { - x *= p_v.x; y *= p_v.y; z *= p_v.z; return *this; } Vector3 Vector3::operator*(const Vector3 &p_v) const { - return Vector3(x * p_v.x, y * p_v.y, z * p_v.z); } Vector3 &Vector3::operator/=(const Vector3 &p_v) { - x /= p_v.x; y /= p_v.y; z /= p_v.z; @@ -300,12 +280,10 @@ Vector3 &Vector3::operator/=(const Vector3 &p_v) { } Vector3 Vector3::operator/(const Vector3 &p_v) const { - return Vector3(x / p_v.x, y / p_v.y, z / p_v.z); } Vector3 &Vector3::operator*=(real_t p_scalar) { - x *= p_scalar; y *= p_scalar; z *= p_scalar; @@ -313,17 +291,14 @@ Vector3 &Vector3::operator*=(real_t p_scalar) { } _FORCE_INLINE_ Vector3 operator*(real_t p_scalar, const Vector3 &p_vec) { - return p_vec * p_scalar; } Vector3 Vector3::operator*(real_t p_scalar) const { - return Vector3(x * p_scalar, y * p_scalar, z * p_scalar); } Vector3 &Vector3::operator/=(real_t p_scalar) { - x /= p_scalar; y /= p_scalar; z /= p_scalar; @@ -331,27 +306,22 @@ Vector3 &Vector3::operator/=(real_t p_scalar) { } Vector3 Vector3::operator/(real_t p_scalar) const { - return Vector3(x / p_scalar, y / p_scalar, z / p_scalar); } Vector3 Vector3::operator-() const { - return Vector3(-x, -y, -z); } bool Vector3::operator==(const Vector3 &p_v) const { - return x == p_v.x && y == p_v.y && z == p_v.z; } bool Vector3::operator!=(const Vector3 &p_v) const { - return x != p_v.x || y != p_v.y || z != p_v.z; } bool Vector3::operator<(const Vector3 &p_v) const { - if (x == p_v.x) { if (y == p_v.y) return z < p_v.z; @@ -363,7 +333,6 @@ bool Vector3::operator<(const Vector3 &p_v) const { } bool Vector3::operator>(const Vector3 &p_v) const { - if (x == p_v.x) { if (y == p_v.y) return z > p_v.z; @@ -375,7 +344,6 @@ bool Vector3::operator>(const Vector3 &p_v) const { } bool Vector3::operator<=(const Vector3 &p_v) const { - if (x == p_v.x) { if (y == p_v.y) return z <= p_v.z; @@ -387,7 +355,6 @@ bool Vector3::operator<=(const Vector3 &p_v) const { } bool Vector3::operator>=(const Vector3 &p_v) const { - if (x == p_v.x) { if (y == p_v.y) return z >= p_v.z; @@ -399,17 +366,14 @@ bool Vector3::operator>=(const Vector3 &p_v) const { } _FORCE_INLINE_ Vector3 vec3_cross(const Vector3 &p_a, const Vector3 &p_b) { - return p_a.cross(p_b); } _FORCE_INLINE_ real_t vec3_dot(const Vector3 &p_a, const Vector3 &p_b) { - return p_a.dot(p_b); } real_t Vector3::length() const { - real_t x2 = x * x; real_t y2 = y * y; real_t z2 = z * z; @@ -418,7 +382,6 @@ real_t Vector3::length() const { } real_t Vector3::length_squared() const { - real_t x2 = x * x; real_t y2 = y * y; real_t z2 = z * z; @@ -427,7 +390,6 @@ real_t Vector3::length_squared() const { } void Vector3::normalize() { - real_t lengthsq = length_squared(); if (lengthsq == 0) { x = y = z = 0; @@ -440,7 +402,6 @@ void Vector3::normalize() { } Vector3 Vector3::normalized() const { - Vector3 v = *this; v.normalize(); return v; @@ -452,12 +413,10 @@ bool Vector3::is_normalized() const { } Vector3 Vector3::inverse() const { - return Vector3(1.0 / x, 1.0 / y, 1.0 / z); } void Vector3::zero() { - x = y = z = 0; } diff --git a/core/message_queue.cpp b/core/message_queue.cpp index f3ab6d3c1e7..72a07251b96 100644 --- a/core/message_queue.cpp +++ b/core/message_queue.cpp @@ -36,12 +36,10 @@ MessageQueue *MessageQueue::singleton = NULL; MessageQueue *MessageQueue::get_singleton() { - return singleton; } Error MessageQueue::push_call(ObjectID p_id, const StringName &p_method, const Variant **p_args, int p_argcount, bool p_show_error) { - _THREAD_SAFE_METHOD_ int room_needed = sizeof(Message) + sizeof(Variant) * p_argcount; @@ -66,7 +64,6 @@ Error MessageQueue::push_call(ObjectID p_id, const StringName &p_method, const V buffer_end += sizeof(Message); for (int i = 0; i < p_argcount; i++) { - Variant *v = memnew_placement(&buffer[buffer_end], Variant); buffer_end += sizeof(Variant); *v = *p_args[i]; @@ -76,7 +73,6 @@ Error MessageQueue::push_call(ObjectID p_id, const StringName &p_method, const V } Error MessageQueue::push_call(ObjectID p_id, const StringName &p_method, VARIANT_ARG_DECLARE) { - VARIANT_ARGPTRS; int argc = 0; @@ -91,7 +87,6 @@ Error MessageQueue::push_call(ObjectID p_id, const StringName &p_method, VARIANT } Error MessageQueue::push_set(ObjectID p_id, const StringName &p_prop, const Variant &p_value) { - _THREAD_SAFE_METHOD_ uint8_t room_needed = sizeof(Message) + sizeof(Variant); @@ -121,7 +116,6 @@ Error MessageQueue::push_set(ObjectID p_id, const StringName &p_prop, const Vari } Error MessageQueue::push_notification(ObjectID p_id, int p_notification) { - _THREAD_SAFE_METHOD_ ERR_FAIL_COND_V(p_notification < 0, ERR_INVALID_PARAMETER); @@ -147,21 +141,17 @@ Error MessageQueue::push_notification(ObjectID p_id, int p_notification) { } Error MessageQueue::push_call(Object *p_object, const StringName &p_method, VARIANT_ARG_DECLARE) { - return push_call(p_object->get_instance_id(), p_method, VARIANT_ARG_PASS); } Error MessageQueue::push_notification(Object *p_object, int p_notification) { - return push_notification(p_object->get_instance_id(), p_notification); } Error MessageQueue::push_set(Object *p_object, const StringName &p_prop, const Variant &p_value) { - return push_set(p_object->get_instance_id(), p_prop, p_value); } void MessageQueue::statistics() { - Map set_count; Map notify_count; Map call_count; @@ -174,11 +164,8 @@ void MessageQueue::statistics() { Object *target = ObjectDB::get_instance(message->instance_id); if (target != NULL) { - switch (message->type & FLAG_MASK) { - case TYPE_CALL: { - if (!call_count.has(message->target)) call_count[message->target] = 0; @@ -186,7 +173,6 @@ void MessageQueue::statistics() { } break; case TYPE_NOTIFICATION: { - if (!notify_count.has(message->notification)) notify_count[message->notification] = 0; @@ -194,7 +180,6 @@ void MessageQueue::statistics() { } break; case TYPE_SET: { - if (!set_count.has(message->target)) set_count[message->target] = 0; @@ -232,12 +217,10 @@ void MessageQueue::statistics() { } int MessageQueue::get_max_buffer_usage() const { - return buffer_max_used; } void MessageQueue::_call_function(Object *p_target, const StringName &p_func, const Variant *p_args, int p_argcount, bool p_show_error) { - const Variant **argptrs = NULL; if (p_argcount) { argptrs = (const Variant **)alloca(sizeof(Variant *) * p_argcount); @@ -249,13 +232,11 @@ void MessageQueue::_call_function(Object *p_target, const StringName &p_func, co Variant::CallError ce; p_target->call(p_func, argptrs, p_argcount, ce); if (p_show_error && ce.error != Variant::CallError::CALL_OK) { - ERR_PRINTS("Error calling deferred method: " + Variant::get_call_error_text(p_target, p_func, argptrs, p_argcount, ce) + "."); } } void MessageQueue::flush() { - if (buffer_end > buffer_max_used) { buffer_max_used = buffer_end; } @@ -269,7 +250,6 @@ void MessageQueue::flush() { flushing = true; while (read_pos < buffer_end) { - //lock on each iteration, so a call can re-add itself to the message queue Message *message = (Message *)&buffer[read_pos]; @@ -286,10 +266,8 @@ void MessageQueue::flush() { Object *target = ObjectDB::get_instance(message->instance_id); if (target != NULL) { - switch (message->type & FLAG_MASK) { case TYPE_CALL: { - Variant *args = (Variant *)(message + 1); // messages don't expect a return value @@ -298,13 +276,11 @@ void MessageQueue::flush() { } break; case TYPE_NOTIFICATION: { - // messages don't expect a return value target->notification(message->notification); } break; case TYPE_SET: { - Variant *arg = (Variant *)(message + 1); // messages don't expect a return value target->set(message->target, *arg); @@ -331,12 +307,10 @@ void MessageQueue::flush() { } bool MessageQueue::is_flushing() const { - return flushing; } MessageQueue::MessageQueue() { - ERR_FAIL_COND_MSG(singleton != NULL, "A MessageQueue singleton already exists."); singleton = this; flushing = false; @@ -350,11 +324,9 @@ MessageQueue::MessageQueue() { } MessageQueue::~MessageQueue() { - uint32_t read_pos = 0; while (read_pos < buffer_end) { - Message *message = (Message *)&buffer[read_pos]; Variant *args = (Variant *)(message + 1); int argc = message->args; diff --git a/core/message_queue.h b/core/message_queue.h index e34407b2d41..ec30fee3835 100644 --- a/core/message_queue.h +++ b/core/message_queue.h @@ -35,7 +35,6 @@ #include "core/os/thread_safe.h" class MessageQueue { - _THREAD_SAFE_CLASS_ enum { @@ -52,7 +51,6 @@ class MessageQueue { }; struct Message { - ObjectID instance_id; StringName target; int16_t type; diff --git a/core/method_bind.cpp b/core/method_bind.cpp index 0f7adc935e4..19533efbb9a 100644 --- a/core/method_bind.cpp +++ b/core/method_bind.cpp @@ -36,7 +36,6 @@ #ifdef DEBUG_METHODS_ENABLED PropertyInfo MethodBind::get_argument_info(int p_argument) const { - ERR_FAIL_INDEX_V(p_argument, get_argument_count(), PropertyInfo()); PropertyInfo info = _gen_argument_type_info(p_argument); @@ -45,18 +44,15 @@ PropertyInfo MethodBind::get_argument_info(int p_argument) const { } PropertyInfo MethodBind::get_return_info() const { - return _gen_argument_type_info(-1); } #endif void MethodBind::_set_const(bool p_const) { - _const = p_const; } void MethodBind::_set_returns(bool p_returns) { - _returns = p_returns; } @@ -69,11 +65,9 @@ void MethodBind::set_name(const StringName &p_name) { #ifdef DEBUG_METHODS_ENABLED void MethodBind::set_argument_names(const Vector &p_names) { - arg_names = p_names; } Vector MethodBind::get_argument_names() const { - return arg_names; } @@ -86,7 +80,6 @@ void MethodBind::set_default_arguments(const Vector &p_defargs) { #ifdef DEBUG_METHODS_ENABLED void MethodBind::_generate_argument_types(int p_count) { - set_argument_count(p_count); Variant::Type *argt = memnew_arr(Variant::Type, p_count + 1); diff --git a/core/method_bind.h b/core/method_bind.h index 0d970e4bb41..aaaeec6feed 100644 --- a/core/method_bind.h +++ b/core/method_bind.h @@ -59,27 +59,21 @@ enum MethodFlags { template struct VariantCaster { - static _FORCE_INLINE_ T cast(const Variant &p_variant) { - return p_variant; } }; template struct VariantCaster { - static _FORCE_INLINE_ T cast(const Variant &p_variant) { - return p_variant; } }; template struct VariantCaster { - static _FORCE_INLINE_ T cast(const Variant &p_variant) { - return p_variant; } }; @@ -93,7 +87,6 @@ struct VariantCaster { MAKE_ENUM_TYPE_INFO(m_enum) \ template <> \ struct VariantCaster { \ - \ static _FORCE_INLINE_ m_enum cast(const Variant &p_variant) { \ return (m_enum)p_variant.operator int(); \ } \ @@ -114,7 +107,6 @@ struct VariantCaster { MAKE_ENUM_TYPE_INFO(m_enum) \ template <> \ struct VariantCaster { \ - \ static _FORCE_INLINE_ m_enum cast(const Variant &p_variant) { \ return (m_enum)p_variant.operator int(); \ } \ @@ -206,7 +198,6 @@ struct PtrToArg { #endif class MethodBind { - int method_id; uint32_t hint_flags; StringName name; @@ -237,7 +228,6 @@ public: _FORCE_INLINE_ int get_default_argument_count() const { return default_argument_count; } _FORCE_INLINE_ Variant has_default_argument(int p_arg) const { - int idx = argument_count - p_arg - 1; if (idx < 0 || idx >= default_arguments.size()) @@ -247,7 +237,6 @@ public: } _FORCE_INLINE_ Variant get_default_argument(int p_arg) const { - int idx = argument_count - p_arg - 1; if (idx < 0 || idx >= default_arguments.size()) @@ -259,7 +248,6 @@ public: #ifdef DEBUG_METHODS_ENABLED _FORCE_INLINE_ Variant::Type get_argument_type(int p_argument) const { - ERR_FAIL_COND_V(p_argument < -1 || p_argument > argument_count, Variant::NIL); return argument_types[p_argument + 1]; } @@ -314,7 +302,6 @@ public: #ifdef DEBUG_METHODS_ENABLED virtual PropertyInfo _gen_argument_type_info(int p_arg) const { - if (p_arg < 0) { return arguments.return_val; } else if (p_arg < arguments.arguments.size()) { @@ -340,23 +327,19 @@ public: #endif virtual Variant call(Object *p_object, const Variant **p_args, int p_arg_count, Variant::CallError &r_error) { - T *instance = static_cast(p_object); return (instance->*call_method)(p_args, p_arg_count, r_error); } void set_method_info(const MethodInfo &p_info, bool p_return_nil_is_variant) { - set_argument_count(p_info.arguments.size()); #ifdef DEBUG_METHODS_ENABLED Variant::Type *at = memnew_arr(Variant::Type, p_info.arguments.size() + 1); at[0] = p_info.return_val.type; if (p_info.arguments.size()) { - Vector names; names.resize(p_info.arguments.size()); for (int i = 0; i < p_info.arguments.size(); i++) { - at[i + 1] = p_info.arguments[i].type; names.write[i] = p_info.arguments[i].name; } @@ -391,7 +374,6 @@ public: template MethodBind *create_vararg_method_bind(Variant (T::*p_method)(const Variant **, int, Variant::CallError &), const MethodInfo &p_info, bool p_return_nil_is_variant) { - MethodBindVarArg *a = memnew((MethodBindVarArg)); a->set_method(p_method); a->set_method_info(p_info, p_return_nil_is_variant); diff --git a/core/method_ptrcall.h b/core/method_ptrcall.h index b44542e087b..830f22ac90e 100644 --- a/core/method_ptrcall.h +++ b/core/method_ptrcall.h @@ -141,28 +141,22 @@ MAKE_PTRARG_BY_REFERENCE(Variant); template struct PtrToArg { - _FORCE_INLINE_ static T *convert(const void *p_ptr) { - return const_cast(reinterpret_cast(p_ptr)); } _FORCE_INLINE_ static void encode(T *p_var, void *p_ptr) { - *((T **)p_ptr) = p_var; } }; template struct PtrToArg { - _FORCE_INLINE_ static const T *convert(const void *p_ptr) { - return reinterpret_cast(p_ptr); } _FORCE_INLINE_ static void encode(T *p_var, void *p_ptr) { - *((T **)p_ptr) = p_var; } }; diff --git a/core/node_path.cpp b/core/node_path.cpp index fc3d890ca09..7a60e0b2950 100644 --- a/core/node_path.cpp +++ b/core/node_path.cpp @@ -33,7 +33,6 @@ #include "core/print_string.h" void NodePath::_update_hash_cache() const { - uint32_t h = data->absolute ? 1 : 0; int pc = data->path.size(); const StringName *sn = data->path.ptr(); @@ -51,7 +50,6 @@ void NodePath::_update_hash_cache() const { } void NodePath::prepend_period() { - if (data->path.size() && data->path[0].operator String() != ".") { data->path.insert(0, "."); data->hash_cache_valid = false; @@ -59,51 +57,43 @@ void NodePath::prepend_period() { } bool NodePath::is_absolute() const { - if (!data) return false; return data->absolute; } int NodePath::get_name_count() const { - if (!data) return 0; return data->path.size(); } StringName NodePath::get_name(int p_idx) const { - ERR_FAIL_COND_V(!data, StringName()); ERR_FAIL_INDEX_V(p_idx, data->path.size(), StringName()); return data->path[p_idx]; } int NodePath::get_subname_count() const { - if (!data) return 0; return data->subpath.size(); } StringName NodePath::get_subname(int p_idx) const { - ERR_FAIL_COND_V(!data, StringName()); ERR_FAIL_INDEX_V(p_idx, data->subpath.size(), StringName()); return data->subpath[p_idx]; } void NodePath::unref() { - if (data && data->refcount.unref()) { - memdelete(data); } data = NULL; } bool NodePath::operator==(const NodePath &p_path) const { - if (data == p_path.data) return true; @@ -129,7 +119,6 @@ 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]) return false; } @@ -138,7 +127,6 @@ bool NodePath::operator==(const NodePath &p_path) const { 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]) return false; } @@ -146,25 +134,21 @@ bool NodePath::operator==(const NodePath &p_path) const { return true; } bool NodePath::operator!=(const NodePath &p_path) const { - return (!(*this == p_path)); } void NodePath::operator=(const NodePath &p_path) { - if (this == &p_path) return; unref(); if (p_path.data && p_path.data->refcount.ref()) { - data = p_path.data; } } NodePath::operator String() const { - if (!data) return String(); @@ -173,14 +157,12 @@ NodePath::operator String() const { ret = "/"; for (int i = 0; i < data->path.size(); i++) { - if (i > 0) ret += "/"; ret += data->path[i].operator String(); } for (int i = 0; i < data->subpath.size(); i++) { - ret += ":" + data->subpath[i].operator String(); } @@ -188,24 +170,20 @@ NodePath::operator String() const { } NodePath::NodePath(const NodePath &p_path) { - data = NULL; if (p_path.data && p_path.data->refcount.ref()) { - data = p_path.data; } } Vector NodePath::get_names() const { - if (data) return data->path; return Vector(); } Vector NodePath::get_subnames() const { - if (data) return data->subpath; return Vector(); @@ -227,7 +205,6 @@ StringName NodePath::get_concatenated_subnames() const { } NodePath NodePath::rel_path_to(const NodePath &p_np) const { - ERR_FAIL_COND_V(!is_absolute(), NodePath()); ERR_FAIL_COND_V(!p_np.is_absolute(), NodePath()); @@ -252,12 +229,10 @@ NodePath NodePath::rel_path_to(const NodePath &p_np) const { Vector relpath; for (int i = src_dirs.size() - 1; i > common_parent; i--) { - relpath.push_back(".."); } for (int i = common_parent + 1; i < dst_dirs.size(); i++) { - relpath.push_back(dst_dirs[i]); } @@ -268,7 +243,6 @@ NodePath NodePath::rel_path_to(const NodePath &p_np) const { } NodePath NodePath::get_as_property_path() const { - if (!data || !data->path.size()) { return *this; } else { @@ -286,7 +260,6 @@ NodePath NodePath::get_as_property_path() const { } NodePath::NodePath(const Vector &p_path, bool p_absolute) { - data = NULL; if (p_path.size() == 0) @@ -301,7 +274,6 @@ NodePath::NodePath(const Vector &p_path, bool p_absolute) { } NodePath::NodePath(const Vector &p_path, const Vector &p_subpath, bool p_absolute) { - data = NULL; if (p_path.size() == 0 && p_subpath.size() == 0) @@ -317,7 +289,6 @@ NodePath::NodePath(const Vector &p_path, const Vector &p } void NodePath::simplify() { - if (!data) return; for (int i = 0; i < data->path.size(); i++) { @@ -341,14 +312,12 @@ void NodePath::simplify() { } NodePath NodePath::simplified() const { - NodePath np = *this; np.simplify(); return np; } NodePath::NodePath(const String &p_path) { - data = NULL; if (p_path.length() == 0) @@ -364,13 +333,10 @@ NodePath::NodePath(const String &p_path) { int subpath_pos = path.find(":"); if (subpath_pos != -1) { - int from = subpath_pos + 1; for (int i = from; i <= path.length(); i++) { - if (path[i] == ':' || path[i] == 0) { - String str = path.substr(from, i - from); if (str == "") { if (path[i] == 0) @@ -388,13 +354,10 @@ NodePath::NodePath(const String &p_path) { } for (int i = (int)absolute; i < path.length(); i++) { - if (path[i] == '/') { - last_is_slash = true; has_slashes = true; } else { - if (last_is_slash) slices++; @@ -420,11 +383,8 @@ NodePath::NodePath(const String &p_path) { int slice = 0; for (int i = (int)absolute; i < path.length() + 1; i++) { - if (path[i] == '/' || path[i] == 0) { - if (!last_is_slash) { - String name = path.substr(from, i - from); ERR_FAIL_INDEX(slice, data->path.size()); data->path.write[slice++] = name; @@ -438,15 +398,12 @@ NodePath::NodePath(const String &p_path) { } bool NodePath::is_empty() const { - return !data; } NodePath::NodePath() { - data = NULL; } NodePath::~NodePath() { - unref(); } diff --git a/core/node_path.h b/core/node_path.h index 8754cba3004..9fe381a333d 100644 --- a/core/node_path.h +++ b/core/node_path.h @@ -35,9 +35,7 @@ #include "core/ustring.h" class NodePath { - struct Data { - SafeRefCount refcount; Vector path; Vector subpath; @@ -55,7 +53,6 @@ class NodePath { public: _FORCE_INLINE_ StringName get_sname() const { - if (data && data->path.size() == 1 && data->subpath.empty()) { return data->path[0]; } else { diff --git a/core/oa_hash_map.h b/core/oa_hash_map.h index da09214c6f4..bc1d7f0b6a3 100644 --- a/core/oa_hash_map.h +++ b/core/oa_hash_map.h @@ -52,7 +52,6 @@ template > class OAHashMap { - private: TValue *values; TKey *keys; @@ -112,7 +111,6 @@ private: } void _insert_with_hash(uint32_t p_hash, const TKey &p_key, const TValue &p_value) { - uint32_t hash = p_hash; uint32_t distance = 0; uint32_t pos = hash % capacity; @@ -142,7 +140,6 @@ private: } void _resize_and_rehash(uint32_t p_new_capacity) { - uint32_t old_capacity = capacity; capacity = p_new_capacity; @@ -188,9 +185,7 @@ public: } void clear() { - for (uint32_t i = 0; i < capacity; i++) { - if (hashes[i] == EMPTY_HASH) { continue; } @@ -204,7 +199,6 @@ public: } void insert(const TKey &p_key, const TValue &p_value) { - if (num_elements + 1 > 0.9 * capacity) { _resize_and_rehash(); } @@ -304,7 +298,6 @@ public: } Iterator next_iter(const Iterator &p_iter) const { - if (!p_iter.valid) { return p_iter; } @@ -335,7 +328,6 @@ public: OAHashMap &operator=(const OAHashMap &) = delete; // Same for assignment operator. OAHashMap(uint32_t p_initial_capacity = 64) { - capacity = p_initial_capacity; num_elements = 0; @@ -349,9 +341,7 @@ public: } ~OAHashMap() { - for (uint32_t i = 0; i < capacity; i++) { - if (hashes[i] == EMPTY_HASH) { continue; } diff --git a/core/object.cpp b/core/object.cpp index ace5265e06d..d41309b3d55 100644 --- a/core/object.cpp +++ b/core/object.cpp @@ -43,7 +43,6 @@ #ifdef DEBUG_ENABLED struct _ObjectDebugLock { - Object *obj; _ObjectDebugLock(Object *p_obj) { @@ -64,7 +63,6 @@ struct _ObjectDebugLock { #endif PropertyInfo::operator Dictionary() const { - Dictionary d; d["name"] = name; d["class_name"] = class_name; @@ -76,7 +74,6 @@ PropertyInfo::operator Dictionary() const { } PropertyInfo PropertyInfo::from_dict(const Dictionary &p_dict) { - PropertyInfo pi; if (p_dict.has("type")) @@ -102,10 +99,8 @@ PropertyInfo PropertyInfo::from_dict(const Dictionary &p_dict) { } Array convert_property_list(const List *p_list) { - Array va; for (const List::Element *E = p_list->front(); E; E = E->next()) { - va.push_back(Dictionary(E->get())); } @@ -113,7 +108,6 @@ Array convert_property_list(const List *p_list) { } MethodInfo::operator Dictionary() const { - Dictionary d; d["name"] = name; d["args"] = convert_property_list(&arguments); @@ -134,7 +128,6 @@ MethodInfo::MethodInfo() : } MethodInfo MethodInfo::from_dict(const Dictionary &p_dict) { - MethodInfo mi; if (p_dict.has("name")) @@ -334,7 +327,6 @@ MethodInfo::MethodInfo(const PropertyInfo &p_ret, const String &p_name, const Pr } Object::Connection::operator Variant() const { - Dictionary d; d["source"] = source; d["signal"] = signal; @@ -346,16 +338,11 @@ Object::Connection::operator Variant() const { } bool Object::Connection::operator<(const Connection &p_conn) const { - if (source == p_conn.source) { - if (signal == p_conn.signal) { - if (target == p_conn.target) { - return method < p_conn.method; } else { - return target < p_conn.target; } } else @@ -365,7 +352,6 @@ bool Object::Connection::operator<(const Connection &p_conn) const { } } Object::Connection::Connection(const Variant &p_variant) { - Dictionary d = p_variant; if (d.has("source")) source = d["source"]; @@ -382,7 +368,6 @@ Object::Connection::Connection(const Variant &p_variant) { } bool Object::_predelete() { - _predelete_ok = 1; notification(NOTIFICATION_PREDELETE, true); if (_predelete_ok) { @@ -403,14 +388,12 @@ void Object::_get_valid_parents_static(List *p_parents) { } void Object::set(const StringName &p_name, const Variant &p_value, bool *r_valid) { - #ifdef TOOLS_ENABLED _edited = true; #endif if (script_instance) { - if (script_instance->set(p_name, p_value)) { if (r_valid) *r_valid = true; @@ -478,11 +461,9 @@ void Object::set(const StringName &p_name, const Variant &p_value, bool *r_valid } Variant Object::get(const StringName &p_name, bool *r_valid) const { - Variant ret; if (script_instance) { - if (script_instance->get(p_name, ret)) { if (r_valid) *r_valid = true; @@ -585,7 +566,6 @@ void Object::set_indexed(const Vector &p_names, const Variant &p_val value_stack.push_back(p_value); // p_names[p_names.size() - 1] for (int i = p_names.size() - 1; i > 0; i--) { - value_stack.back()->prev()->get().set_named(p_names[i], value_stack.back()->get(), r_valid); value_stack.pop_back(); @@ -623,7 +603,6 @@ Variant Object::get_indexed(const Vector &p_names, bool *r_valid) co } void Object::get_property_list(List *p_list, bool p_reversed) const { - if (script_instance && p_reversed) { p_list->push_back(PropertyInfo(Variant::NIL, "Script Variables", PROPERTY_HINT_NONE, String(), PROPERTY_USAGE_CATEGORY)); script_instance->get_property_list(p_list); @@ -647,7 +626,6 @@ void Object::_validate_property(PropertyInfo &property) const { } void Object::get_method_list(List *p_list) const { - ClassDB::get_method_list(get_class_name(), p_list); if (script_instance) { script_instance->get_method_list(p_list); @@ -655,7 +633,6 @@ void Object::get_method_list(List *p_list) const { } Variant Object::_call_bind(const Variant **p_args, int p_argcount, Variant::CallError &r_error) { - if (p_argcount < 1) { r_error.error = Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; r_error.argument = 0; @@ -675,7 +652,6 @@ Variant Object::_call_bind(const Variant **p_args, int p_argcount, Variant::Call } Variant Object::_call_deferred_bind(const Variant **p_args, int p_argcount, Variant::CallError &r_error) { - if (p_argcount < 1) { r_error.error = Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; r_error.argument = 0; @@ -700,24 +676,19 @@ Variant Object::_call_deferred_bind(const Variant **p_args, int p_argcount, Vari #ifdef DEBUG_ENABLED static void _test_call_error(const StringName &p_func, const Variant::CallError &error) { - switch (error.error) { - case Variant::CallError::CALL_OK: case Variant::CallError::CALL_ERROR_INVALID_METHOD: break; case Variant::CallError::CALL_ERROR_INVALID_ARGUMENT: { - ERR_FAIL_MSG("Error calling function: " + String(p_func) + " - Invalid type for argument " + itos(error.argument) + ", expected " + Variant::get_type_name(error.expected) + "."); break; } case Variant::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS: { - ERR_FAIL_MSG("Error calling function: " + String(p_func) + " - Too many arguments, expected " + itos(error.argument) + "."); break; } case Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS: { - ERR_FAIL_MSG("Error calling function: " + String(p_func) + " - Too few arguments, expected " + itos(error.argument) + "."); break; } @@ -732,7 +703,6 @@ static void _test_call_error(const StringName &p_func, const Variant::CallError #endif void Object::call_multilevel(const StringName &p_method, const Variant **p_args, int p_argcount) { - if (p_method == CoreStringNames::get_singleton()->_free) { #ifdef DEBUG_ENABLED ERR_FAIL_COND_MSG(Object::cast_to(this), "Can't 'free' a reference."); @@ -758,21 +728,18 @@ void Object::call_multilevel(const StringName &p_method, const Variant **p_args, MethodBind *method = ClassDB::get_method(get_class_name(), p_method); if (method) { - method->call(this, p_args, p_argcount, error); _test_call_error(p_method, error); } } void Object::call_multilevel_reversed(const StringName &p_method, const Variant **p_args, int p_argcount) { - MethodBind *method = ClassDB::get_method(get_class_name(), p_method); Variant::CallError error; OBJ_DEBUG_LOCK if (method) { - method->call(this, p_args, p_argcount, error); _test_call_error(p_method, error); } @@ -786,7 +753,6 @@ void Object::call_multilevel_reversed(const StringName &p_method, const Variant } bool Object::has_method(const StringName &p_method) const { - if (p_method == CoreStringNames::get_singleton()->_free) { return true; } @@ -801,13 +767,11 @@ bool Object::has_method(const StringName &p_method) const { } Variant Object::getvar(const Variant &p_key, bool *r_valid) const { - 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) *r_valid = false; } @@ -831,7 +795,6 @@ Variant Object::callv(const StringName &p_method, const Array &p_args) { } Variant Object::call(const StringName &p_name, VARIANT_ARG_DECLARE) { - VARIANT_ARGPTRS; int argc = 0; @@ -848,7 +811,6 @@ Variant Object::call(const StringName &p_name, VARIANT_ARG_DECLARE) { } void Object::call_multilevel(const StringName &p_name, VARIANT_ARG_DECLARE) { - VARIANT_ARGPTRS; int argc = 0; @@ -863,7 +825,6 @@ void Object::call_multilevel(const StringName &p_name, VARIANT_ARG_DECLARE) { } Variant Object::call(const StringName &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error) { - r_error.error = Variant::CallError::CALL_OK; if (p_method == CoreStringNames::get_singleton()->_free) { @@ -899,7 +860,6 @@ Variant Object::call(const StringName &p_method, const Variant **p_args, int p_a ret = script_instance->call(p_method, p_args, p_argcount, r_error); //force jumptable switch (r_error.error) { - case Variant::CallError::CALL_OK: return ret; case Variant::CallError::CALL_ERROR_INVALID_METHOD: @@ -916,7 +876,6 @@ Variant Object::call(const StringName &p_method, const Variant **p_args, int p_a MethodBind *method = ClassDB::get_method(get_class_name(), p_method); if (method) { - ret = method->call(this, p_args, p_argcount, r_error); } else { r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD; @@ -926,7 +885,6 @@ Variant Object::call(const StringName &p_method, const Variant **p_args, int p_a } void Object::notification(int p_notification, bool p_reversed) { - _notificationv(p_notification, p_reversed); if (script_instance) { @@ -948,28 +906,23 @@ void Object::_changed_callback(Object *p_changed, const char *p_prop) { } void Object::add_change_receptor(Object *p_receptor) { - change_receptors.insert(p_receptor); } void Object::remove_change_receptor(Object *p_receptor) { - change_receptors.erase(p_receptor); } void Object::property_list_changed_notify() { - _change_notify(); } void Object::cancel_delete() { - _predelete_ok = true; } #ifdef DEBUG_ENABLED ObjectRC *Object::_use_rc() { - // The RC object is lazily created the first time it's requested; // that way, there's no need to allocate and release it at all if this Object // is not being referred by any Variant at all. @@ -999,7 +952,6 @@ ObjectRC *Object::_use_rc() { #endif void Object::set_script_and_instance(const RefPtr &p_script, ScriptInstance *p_instance) { - //this function is not meant to be used in any of these ways ERR_FAIL_COND(p_script.is_null()); ERR_FAIL_COND(!p_instance); @@ -1010,7 +962,6 @@ void Object::set_script_and_instance(const RefPtr &p_script, ScriptInstance *p_i } void Object::set_script(const RefPtr &p_script) { - if (script == p_script) return; @@ -1037,7 +988,6 @@ void Object::set_script(const RefPtr &p_script) { } void Object::set_script_instance(ScriptInstance *p_instance) { - if (script_instance == p_instance) return; @@ -1053,17 +1003,14 @@ void Object::set_script_instance(ScriptInstance *p_instance) { } RefPtr Object::get_script() const { - return script; } bool Object::has_meta(const String &p_name) const { - return metadata.has(p_name); } void Object::set_meta(const String &p_name, const Variant &p_value) { - if (p_value.get_type() == Variant::NIL) { metadata.erase(p_name); return; @@ -1073,7 +1020,6 @@ void Object::set_meta(const String &p_name, const Variant &p_value) { } Variant Object::get_meta(const String &p_name) const { - ERR_FAIL_COND_V(!metadata.has(p_name), Variant()); return metadata[p_name]; } @@ -1083,20 +1029,17 @@ void Object::remove_meta(const String &p_name) { } Array Object::_get_property_list_bind() const { - List lpi; get_property_list(&lpi); return convert_property_list(&lpi); } Array Object::_get_method_list_bind() const { - List ml; get_method_list(&ml); Array ret; for (List::Element *E = ml.front(); E; E = E->next()) { - Dictionary d = E->get(); //va.push_back(d); ret.push_back(d); @@ -1106,30 +1049,25 @@ Array Object::_get_method_list_bind() const { } PoolVector Object::_get_meta_list_bind() const { - PoolVector _metaret; List keys; metadata.get_key_list(&keys); for (List::Element *E = keys.front(); E; E = E->next()) { - _metaret.push_back(E->get()); } return _metaret; } void Object::get_meta_list(List *p_list) const { - List keys; metadata.get_key_list(&keys); for (List::Element *E = keys.front(); E; E = E->next()) { - p_list->push_back(E->get()); } } void Object::add_user_signal(const MethodInfo &p_signal) { - ERR_FAIL_COND_MSG(p_signal.name == "", "Signal name cannot be empty."); ERR_FAIL_COND_MSG(ClassDB::has_signal(get_class_name(), p_signal.name), "User signal's name conflicts with a built-in signal of '" + get_class_name() + "'."); ERR_FAIL_COND_MSG(signal_map.has(p_signal.name), "Trying to add already existing signal '" + p_signal.name + "'."); @@ -1139,21 +1077,18 @@ 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)) return false; return signal_map[p_name].user.name.length() > 0; } struct _ObjectSignalDisconnectData { - StringName signal; Object *target; StringName method; }; Variant Object::_emit_signal(const Variant **p_args, int p_argcount, Variant::CallError &r_error) { - r_error.error = Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; ERR_FAIL_COND_V(p_argcount < 1, Variant()); @@ -1181,7 +1116,6 @@ Variant Object::_emit_signal(const Variant **p_args, int p_argcount, Variant::Ca } Error Object::emit_signal(const StringName &p_name, const Variant **p_args, int p_argcount) { - if (_block_signals) return ERR_CANT_ACQUIRE_RESOURCE; //no emit, signals blocked @@ -1212,7 +1146,6 @@ Error Object::emit_signal(const StringName &p_name, const Variant **p_args, int Error err = OK; for (int i = 0; i < ssize; i++) { - const Connection &c = slot_map.getv(i).conn; Object *target = ObjectDB::get_instance(slot_map.getk(i)._id); @@ -1269,7 +1202,6 @@ Error Object::emit_signal(const StringName &p_name, const Variant **p_args, int } #endif if (disconnect) { - _ObjectSignalDisconnectData dd; dd.signal = p_name; dd.target = target; @@ -1279,7 +1211,6 @@ Error Object::emit_signal(const StringName &p_name, const Variant **p_args, int } while (!disconnect_data.empty()) { - const _ObjectSignalDisconnectData &dd = disconnect_data.front()->get(); disconnect(dd.signal, dd.target, dd.method); disconnect_data.pop_front(); @@ -1289,13 +1220,11 @@ Error Object::emit_signal(const StringName &p_name, const Variant **p_args, int } Error Object::emit_signal(const StringName &p_name, VARIANT_ARG_DECLARE) { - VARIANT_ARGPTRS; int argc = 0; for (int i = 0; i < VARIANT_ARG_MAX; i++) { - if (argptr[i]->get_type() == Variant::NIL) break; argc++; @@ -1305,7 +1234,6 @@ Error Object::emit_signal(const StringName &p_name, VARIANT_ARG_DECLARE) { } void Object::_add_user_signal(const String &p_name, const Array &p_args) { - // this version of add_user_signal is meant to be used from scripts or external apis // without access to ADD_SIGNAL in bind_methods // added events are per instance, as opposed to the other ones, which are global @@ -1314,7 +1242,6 @@ void Object::_add_user_signal(const String &p_name, const Array &p_args) { mi.name = p_name; for (int i = 0; i < p_args.size(); i++) { - Dictionary d = p_args[i]; PropertyInfo param; @@ -1330,13 +1257,11 @@ void Object::_add_user_signal(const String &p_name, const Array &p_args) { } Array Object::_get_signal_list() const { - List signal_list; get_signal_list(&signal_list); Array ret; for (List::Element *E = signal_list.front(); E; E = E->next()) { - ret.push_back(Dictionary(E->get())); } @@ -1344,14 +1269,12 @@ Array Object::_get_signal_list() const { } Array Object::_get_signal_connection_list(const String &p_signal) const { - List conns; get_all_signal_connections(&conns); Array ret; for (List::Element *E = conns.front(); E; E = E->next()) { - Connection &c = E->get(); if (c.signal == p_signal) { Dictionary rc; @@ -1369,7 +1292,6 @@ Array Object::_get_signal_connection_list(const String &p_signal) const { } Array Object::_get_incoming_connections() const { - Array ret; int connections_amount = connections.size(); for (int idx_conn = 0; idx_conn < connections_amount; idx_conn++) { @@ -1403,7 +1325,6 @@ bool Object::has_signal(const StringName &p_name) const { } void Object::get_signal_list(List *p_signals) const { - if (!script.is_null()) { Ref