From f851c4aa330e1064a66db50be62db2466f4fb768 Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Tue, 5 Apr 2022 13:40:26 +0300 Subject: Fix some issues found by cppcheck. --- core/debugger/engine_profiler.cpp | 6 +- core/debugger/local_debugger.cpp | 4 +- core/debugger/remote_debugger.cpp | 11 ++- core/debugger/remote_debugger_peer.cpp | 4 +- core/debugger/remote_debugger_peer.h | 14 +-- core/error/error_macros.cpp | 2 +- core/error/error_macros.h | 2 +- core/extension/native_extension.cpp | 16 ++-- core/input/input.cpp | 6 +- core/input/input.h | 6 +- core/input/input_event.cpp | 12 +-- core/io/file_access_network.cpp | 2 +- core/io/file_access_pack.h | 4 +- core/io/file_access_zip.h | 4 +- core/io/ip.cpp | 2 +- core/io/packed_data_container.cpp | 2 +- core/io/translation_loader_po.cpp | 2 +- core/math/basis.cpp | 2 +- core/math/face3.cpp | 2 +- core/math/face3.h | 2 +- core/math/math_funcs.h | 25 ++--- core/object/ref_counted.h | 2 +- core/object/script_language.cpp | 2 +- core/object/script_language.h | 32 +++---- core/os/pool_allocator.cpp | 4 +- core/os/pool_allocator.h | 2 +- core/string/print_string.cpp | 2 +- core/string/print_string.h | 2 +- core/string/translation.cpp | 4 +- core/string/translation.h | 2 +- core/templates/command_queue_mt.h | 8 +- core/templates/thread_work_pool.h | 2 +- core/variant/callable_bind.cpp | 16 ++-- core/variant/callable_bind.h | 32 +++---- core/variant/variant_parser.h | 12 +-- core/variant/variant_utility.cpp | 72 +++++++------- drivers/alsa/audio_driver_alsa.cpp | 2 +- drivers/alsamidi/midi_driver_alsamidi.cpp | 2 +- drivers/coreaudio/audio_driver_coreaudio.cpp | 8 +- drivers/gles3/rasterizer_canvas_gles3.cpp | 1 - drivers/gles3/shader_gles3.cpp | 8 +- drivers/gles3/storage/material_storage.cpp | 6 +- drivers/pulseaudio/audio_driver_pulseaudio.cpp | 12 +-- drivers/vulkan/rendering_device_vulkan.cpp | 16 ++-- drivers/wasapi/audio_driver_wasapi.cpp | 2 +- drivers/xaudio2/audio_driver_xaudio2.cpp | 2 +- editor/animation_bezier_editor.cpp | 3 +- editor/editor_asset_installer.cpp | 3 + editor/editor_data.cpp | 2 +- editor/editor_log.cpp | 4 +- editor/editor_node.cpp | 6 +- editor/editor_node.h | 2 +- editor/editor_run.cpp | 5 +- editor/editor_settings.cpp | 2 +- editor/editor_settings.h | 2 +- editor/export_template_manager.cpp | 19 +++- editor/fileserver/editor_file_server.cpp | 4 +- editor/find_in_files.cpp | 4 +- editor/plugins/animation_state_machine_editor.cpp | 2 +- editor/plugins/canvas_item_editor_plugin.cpp | 23 ++--- editor/plugins/material_editor_plugin.cpp | 4 +- editor/plugins/node_3d_editor_plugin.cpp | 4 +- editor/plugins/tiles/tiles_editor_plugin.cpp | 2 +- editor/plugins/visual_shader_editor_plugin.cpp | 6 +- editor/pot_generator.cpp | 4 +- editor/project_manager.cpp | 11 ++- editor/project_settings_editor.cpp | 2 +- editor/scene_tree_dock.cpp | 2 +- main/main.cpp | 2 - modules/basis_universal/register_types.cpp | 2 +- modules/gdscript/gdscript_parser.h | 2 +- modules/gdscript/gdscript_utility_functions.cpp | 10 +- modules/mbedtls/packet_peer_mbed_dtls.cpp | 8 +- modules/mbedtls/stream_peer_mbedtls.cpp | 8 +- modules/navigation/godot_navigation_server.h | 52 +++++------ modules/noise/noise_texture.cpp | 2 +- modules/text_server_adv/script_iterator.cpp | 4 +- modules/text_server_adv/text_server_adv.cpp | 48 +++++----- modules/text_server_fb/text_server_fb.cpp | 30 +++--- modules/theora/video_stream_theora.cpp | 2 +- .../visual_script/visual_script_builtin_funcs.cpp | 4 +- modules/visual_script/visual_script_expression.cpp | 4 +- .../visual_script/visual_script_flow_control.cpp | 28 +++--- modules/visual_script/visual_script_func_nodes.cpp | 14 +-- modules/visual_script/visual_script_nodes.cpp | 104 ++++++++++----------- .../visual_script/visual_script_yield_nodes.cpp | 8 +- modules/webrtc/webrtc_peer_connection_js.h | 18 ++-- modules/websocket/emws_client.h | 18 ++-- modules/websocket/emws_peer.h | 26 +++--- modules/websocket/emws_server.h | 22 ++--- modules/websocket/remote_debugger_peer_websocket.h | 16 ++-- modules/websocket/wsl_client.h | 18 ++-- modules/websocket/wsl_peer.cpp | 10 +- modules/websocket/wsl_peer.h | 28 +++--- modules/websocket/wsl_server.cpp | 4 +- modules/websocket/wsl_server.h | 22 ++--- platform/android/audio_driver_opensl.cpp | 4 +- platform/android/display_server_android.cpp | 4 +- platform/android/export/export_plugin.cpp | 14 ++- platform/android/export/gradle_export_util.cpp | 2 +- platform/iphone/export/export_plugin.cpp | 5 +- platform/iphone/export/export_plugin.h | 2 +- platform/javascript/export/export_plugin.cpp | 2 +- platform/linuxbsd/display_server_x11.cpp | 4 +- platform/linuxbsd/gl_manager_x11.h | 11 +-- platform/linuxbsd/joypad_linux.cpp | 2 +- platform/osx/export/codesign.cpp | 2 +- platform/osx/export/export_plugin.cpp | 3 + platform/osx/export/plist.cpp | 1 - platform/osx/joypad_osx.cpp | 6 +- platform/uwp/export/app_packager.cpp | 1 - platform/uwp/export/export_plugin.cpp | 3 + platform/uwp/export/export_plugin.h | 2 +- platform/windows/display_server_windows.cpp | 24 ++--- platform/windows/gl_manager_windows.h | 11 +-- platform/windows/joypad_windows.cpp | 10 +- scene/2d/node_2d.cpp | 16 ++-- scene/2d/physics_body_2d.cpp | 4 +- scene/gui/rich_text_label.cpp | 68 ++++++-------- scene/gui/video_stream_player.cpp | 4 +- scene/main/http_request.cpp | 2 +- scene/resources/animation.cpp | 3 +- scene/resources/importer_mesh.cpp | 4 +- scene/resources/resource_format_text.cpp | 2 +- scene/resources/resource_format_text.h | 4 +- servers/audio/audio_driver_dummy.cpp | 2 +- servers/audio/effects/audio_effect_record.cpp | 2 +- servers/physics_2d/godot_area_2d.h | 4 +- servers/physics_2d/godot_body_2d.h | 4 +- servers/physics_2d/godot_body_pair_2d.cpp | 2 +- servers/physics_2d/godot_broad_phase_2d_bvh.cpp | 4 +- servers/physics_2d/godot_broad_phase_2d_bvh.h | 24 ++--- servers/physics_2d/godot_collision_object_2d.h | 4 +- servers/physics_2d/godot_collision_solver_2d.cpp | 2 +- servers/physics_2d/godot_physics_server_2d.cpp | 8 +- servers/physics_2d/godot_shape_2d.cpp | 2 +- servers/physics_2d/godot_space_2d.cpp | 6 +- servers/physics_2d/godot_step_2d.cpp | 2 +- servers/physics_3d/godot_area_3d.h | 4 +- servers/physics_3d/godot_body_3d.h | 4 +- servers/physics_3d/godot_body_pair_3d.cpp | 4 +- servers/physics_3d/godot_broad_phase_3d_bvh.cpp | 4 +- servers/physics_3d/godot_broad_phase_3d_bvh.h | 26 +++--- servers/physics_3d/godot_collision_object_3d.h | 4 +- servers/physics_3d/godot_collision_solver_3d.cpp | 10 +- servers/physics_3d/godot_physics_server_3d.cpp | 8 +- servers/physics_3d/godot_shape_3d.cpp | 2 +- servers/physics_3d/godot_soft_body_3d.cpp | 2 +- servers/physics_3d/godot_soft_body_3d.h | 8 +- servers/physics_3d/godot_space_3d.cpp | 12 +-- servers/physics_3d/godot_step_3d.cpp | 4 +- .../rendering/renderer_rd/cluster_builder_rd.cpp | 2 +- .../forward_clustered/render_forward_clustered.cpp | 20 ++-- .../scene_shader_forward_clustered.cpp | 4 +- .../forward_mobile/render_forward_mobile.cpp | 16 ++-- .../forward_mobile/scene_shader_forward_mobile.cpp | 4 +- .../rendering/renderer_rd/pipeline_cache_rd.cpp | 2 +- .../renderer_rd/renderer_canvas_render_rd.cpp | 12 +-- .../renderer_rd/renderer_scene_render_rd.cpp | 14 +-- .../renderer_rd/renderer_scene_sky_rd.cpp | 36 +++---- .../rendering/renderer_rd/renderer_storage_rd.cpp | 8 +- servers/rendering/shader_language.cpp | 36 +++---- servers/rendering_server.cpp | 2 - 163 files changed, 778 insertions(+), 769 deletions(-) diff --git a/core/debugger/engine_profiler.cpp b/core/debugger/engine_profiler.cpp index c858b1febd..6235d19405 100644 --- a/core/debugger/engine_profiler.cpp +++ b/core/debugger/engine_profiler.cpp @@ -55,13 +55,13 @@ Error EngineProfiler::bind(const String &p_name) { EngineDebugger::Profiler prof( this, [](void *p_user, bool p_enable, const Array &p_opts) { - ((EngineProfiler *)p_user)->toggle(p_enable, p_opts); + static_cast(p_user)->toggle(p_enable, p_opts); }, [](void *p_user, const Array &p_data) { - ((EngineProfiler *)p_user)->add(p_data); + static_cast(p_user)->add(p_data); }, [](void *p_user, double p_frame_time, double p_idle_time, double p_physics_time, double p_physics_frame_time) { - ((EngineProfiler *)p_user)->tick(p_frame_time, p_idle_time, p_physics_time, p_physics_frame_time); + static_cast(p_user)->tick(p_frame_time, p_idle_time, p_physics_time, p_physics_frame_time); }); registration = p_name; EngineDebugger::register_profiler(p_name, prof); diff --git a/core/debugger/local_debugger.cpp b/core/debugger/local_debugger.cpp index c9f7d81a90..131cbaed6c 100644 --- a/core/debugger/local_debugger.cpp +++ b/core/debugger/local_debugger.cpp @@ -369,11 +369,11 @@ LocalDebugger::LocalDebugger() { Profiler scr_prof( scripts_profiler, [](void *p_user, bool p_enable, const Array &p_opts) { - ((ScriptsProfiler *)p_user)->toggle(p_enable, p_opts); + static_cast(p_user)->toggle(p_enable, p_opts); }, nullptr, [](void *p_user, double p_frame_time, double p_idle_time, double p_physics_time, double p_physics_frame_time) { - ((ScriptsProfiler *)p_user)->tick(p_frame_time, p_idle_time, p_physics_time, p_physics_frame_time); + static_cast(p_user)->tick(p_frame_time, p_idle_time, p_physics_time, p_physics_frame_time); }); register_profiler("scripts", scr_prof); } diff --git a/core/debugger/remote_debugger.cpp b/core/debugger/remote_debugger.cpp index 2fce23d003..425261aa6c 100644 --- a/core/debugger/remote_debugger.cpp +++ b/core/debugger/remote_debugger.cpp @@ -161,8 +161,9 @@ public: if (!monitor_value.is_num()) { ERR_PRINT("Value of custom monitor '" + String(custom_monitor_names[i]) + "' is not a number"); arr[i + max] = Variant(); + } else { + arr[i + max] = monitor_value; } - arr[i + max] = monitor_value; } EngineDebugger::get_singleton()->send_message("performance:profile_frame", arr); @@ -189,7 +190,7 @@ void RemoteDebugger::_err_handler(void *p_this, const char *p_func, const char * return; //ignore script errors, those go through debugger } - RemoteDebugger *rd = (RemoteDebugger *)p_this; + RemoteDebugger *rd = static_cast(p_this); if (rd->flushing && Thread::get_caller_id() == rd->flush_thread) { // Can't handle recursive errors during flush. return; } @@ -208,7 +209,7 @@ void RemoteDebugger::_err_handler(void *p_this, const char *p_func, const char * } void RemoteDebugger::_print_handler(void *p_this, const String &p_string, bool p_error) { - RemoteDebugger *rd = (RemoteDebugger *)p_this; + RemoteDebugger *rd = static_cast(p_this); if (rd->flushing && Thread::get_caller_id() == rd->flush_thread) { // Can't handle recursive prints during flush. return; @@ -656,12 +657,12 @@ RemoteDebugger::RemoteDebugger(Ref p_peer) { // Core and profiler captures. Capture core_cap(this, [](void *p_user, const String &p_cmd, const Array &p_data, bool &r_captured) { - return ((RemoteDebugger *)p_user)->_core_capture(p_cmd, p_data, r_captured); + return static_cast(p_user)->_core_capture(p_cmd, p_data, r_captured); }); register_message_capture("core", core_cap); Capture profiler_cap(this, [](void *p_user, const String &p_cmd, const Array &p_data, bool &r_captured) { - return ((RemoteDebugger *)p_user)->_profiler_capture(p_cmd, p_data, r_captured); + return static_cast(p_user)->_profiler_capture(p_cmd, p_data, r_captured); }); register_message_capture("profiler", profiler_cap); diff --git a/core/debugger/remote_debugger_peer.cpp b/core/debugger/remote_debugger_peer.cpp index 7c7d38ab0a..950500884e 100644 --- a/core/debugger/remote_debugger_peer.cpp +++ b/core/debugger/remote_debugger_peer.cpp @@ -162,7 +162,7 @@ Error RemoteDebuggerPeerTCP::connect_to_host(const String &p_host, uint16_t p_po int port = p_port; const int tries = 6; - int waits[tries] = { 1, 10, 100, 1000, 1000, 1000 }; + const int waits[tries] = { 1, 10, 100, 1000, 1000, 1000 }; tcp_client->connect_to_host(ip, port); @@ -192,7 +192,7 @@ Error RemoteDebuggerPeerTCP::connect_to_host(const String &p_host, uint16_t p_po void RemoteDebuggerPeerTCP::_thread_func(void *p_ud) { // Update in time for 144hz monitors const uint64_t min_tick = 6900; - RemoteDebuggerPeerTCP *peer = (RemoteDebuggerPeerTCP *)p_ud; + RemoteDebuggerPeerTCP *peer = static_cast(p_ud); while (peer->running && peer->is_peer_connected()) { uint64_t ticks_usec = OS::get_singleton()->get_ticks_usec(); peer->_poll(); diff --git a/core/debugger/remote_debugger_peer.h b/core/debugger/remote_debugger_peer.h index 010336ffd3..473fd8d712 100644 --- a/core/debugger/remote_debugger_peer.h +++ b/core/debugger/remote_debugger_peer.h @@ -81,13 +81,13 @@ public: Error connect_to_host(const String &p_host, uint16_t p_port); - void poll(); - bool is_peer_connected(); - bool has_message(); - Array get_message(); - Error put_message(const Array &p_arr); - int get_max_message_size() const; - void close(); + void poll() override; + bool is_peer_connected() override; + bool has_message() override; + Array get_message() override; + Error put_message(const Array &p_arr) override; + int get_max_message_size() const override; + void close() override; RemoteDebuggerPeerTCP(Ref p_stream = Ref()); ~RemoteDebuggerPeerTCP(); diff --git a/core/error/error_macros.cpp b/core/error/error_macros.cpp index ceccd43259..8add4b9a3a 100644 --- a/core/error/error_macros.cpp +++ b/core/error/error_macros.cpp @@ -50,7 +50,7 @@ void add_error_handler(ErrorHandlerList *p_handler) { _global_unlock(); } -void remove_error_handler(ErrorHandlerList *p_handler) { +void remove_error_handler(const ErrorHandlerList *p_handler) { _global_lock(); ErrorHandlerList *prev = nullptr; diff --git a/core/error/error_macros.h b/core/error/error_macros.h index 01e22e84b7..2cfb5421c6 100644 --- a/core/error/error_macros.h +++ b/core/error/error_macros.h @@ -58,7 +58,7 @@ struct ErrorHandlerList { }; void add_error_handler(ErrorHandlerList *p_handler); -void remove_error_handler(ErrorHandlerList *p_handler); +void remove_error_handler(const ErrorHandlerList *p_handler); // Functions used by the error macros. void _err_print_error(const char *p_function, const char *p_file, int p_line, const char *p_error, bool p_editor_notify = false, ErrorHandlerType p_type = ERR_HANDLER_ERROR); diff --git a/core/extension/native_extension.cpp b/core/extension/native_extension.cpp index 1a39c937e8..34a11758f8 100644 --- a/core/extension/native_extension.cpp +++ b/core/extension/native_extension.cpp @@ -112,7 +112,7 @@ public: static GDNativeInterface gdnative_interface; void NativeExtension::_register_extension_class(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const char *p_parent_class_name, const GDNativeExtensionClassCreationInfo *p_extension_funcs) { - NativeExtension *self = (NativeExtension *)p_library; + NativeExtension *self = static_cast(p_library); StringName class_name = p_class_name; ERR_FAIL_COND_MSG(!String(class_name).is_valid_identifier(), "Attempt to register extension class '" + class_name + "', which is not a valid class identifier."); @@ -163,7 +163,7 @@ void NativeExtension::_register_extension_class(const GDNativeExtensionClassLibr ClassDB::register_extension_class(&extension->native_extension); } void NativeExtension::_register_extension_class_method(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const GDNativeExtensionClassMethodInfo *p_method_info) { - NativeExtension *self = (NativeExtension *)p_library; + NativeExtension *self = static_cast(p_library); StringName class_name = p_class_name; StringName method_name = p_method_info->name; @@ -177,7 +177,7 @@ void NativeExtension::_register_extension_class_method(const GDNativeExtensionCl ClassDB::bind_method_custom(class_name, method); } void NativeExtension::_register_extension_class_integer_constant(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const char *p_enum_name, const char *p_constant_name, GDNativeInt p_constant_value) { - NativeExtension *self = (NativeExtension *)p_library; + NativeExtension *self = static_cast(p_library); StringName class_name = p_class_name; ERR_FAIL_COND_MSG(!self->extension_classes.has(class_name), "Attempt to register extension constant '" + String(p_constant_name) + "' for unexisting class '" + class_name + "'."); @@ -188,7 +188,7 @@ void NativeExtension::_register_extension_class_integer_constant(const GDNativeE } void NativeExtension::_register_extension_class_property(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const GDNativePropertyInfo *p_info, const char *p_setter, const char *p_getter) { - NativeExtension *self = (NativeExtension *)p_library; + NativeExtension *self = static_cast(p_library); StringName class_name = p_class_name; ERR_FAIL_COND_MSG(!self->extension_classes.has(class_name), "Attempt to register extension class property '" + String(p_info->name) + "' for unexisting class '" + class_name + "'."); @@ -206,7 +206,7 @@ void NativeExtension::_register_extension_class_property(const GDNativeExtension } void NativeExtension::_register_extension_class_property_group(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const char *p_group_name, const char *p_prefix) { - NativeExtension *self = (NativeExtension *)p_library; + NativeExtension *self = static_cast(p_library); StringName class_name = p_class_name; ERR_FAIL_COND_MSG(!self->extension_classes.has(class_name), "Attempt to register extension class property group '" + String(p_group_name) + "' for unexisting class '" + class_name + "'."); @@ -215,7 +215,7 @@ void NativeExtension::_register_extension_class_property_group(const GDNativeExt } void NativeExtension::_register_extension_class_property_subgroup(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const char *p_subgroup_name, const char *p_prefix) { - NativeExtension *self = (NativeExtension *)p_library; + NativeExtension *self = static_cast(p_library); StringName class_name = p_class_name; ERR_FAIL_COND_MSG(!self->extension_classes.has(class_name), "Attempt to register extension class property subgroup '" + String(p_subgroup_name) + "' for unexisting class '" + class_name + "'."); @@ -224,7 +224,7 @@ void NativeExtension::_register_extension_class_property_subgroup(const GDNative } void NativeExtension::_register_extension_class_signal(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name, const char *p_signal_name, const GDNativePropertyInfo *p_argument_info, GDNativeInt p_argument_count) { - NativeExtension *self = (NativeExtension *)p_library; + NativeExtension *self = static_cast(p_library); StringName class_name = p_class_name; ERR_FAIL_COND_MSG(!self->extension_classes.has(class_name), "Attempt to register extension class signal '" + String(p_signal_name) + "' for unexisting class '" + class_name + "'."); @@ -245,7 +245,7 @@ void NativeExtension::_register_extension_class_signal(const GDNativeExtensionCl } void NativeExtension::_unregister_extension_class(const GDNativeExtensionClassLibraryPtr p_library, const char *p_class_name) { - NativeExtension *self = (NativeExtension *)p_library; + NativeExtension *self = static_cast(p_library); StringName class_name = p_class_name; ERR_FAIL_COND_MSG(!self->extension_classes.has(class_name), "Attempt to unregister unexisting extension class '" + class_name + "'."); diff --git a/core/input/input.cpp b/core/input/input.cpp index e64b5a3ab7..343076b4e1 100644 --- a/core/input/input.cpp +++ b/core/input/input.cpp @@ -772,6 +772,8 @@ void Input::action_press(const StringName &p_action, float p_strength) { action.process_frame = Engine::get_singleton()->get_process_frames(); action.pressed = true; action.strength = p_strength; + action.raw_strength = p_strength; + action.exact = true; action_state[p_action] = action; } @@ -783,6 +785,8 @@ void Input::action_release(const StringName &p_action) { action.process_frame = Engine::get_singleton()->get_process_frames(); action.pressed = false; action.strength = 0.f; + action.raw_strength = 0.f; + action.exact = true; action_state[p_action] = action; } @@ -1070,7 +1074,6 @@ void Input::_axis_event(int p_device, JoyAxis p_axis, float p_value) { Input::JoyEvent Input::_get_mapped_button_event(const JoyDeviceMapping &mapping, JoyButton p_button) { JoyEvent event; - event.type = TYPE_MAX; for (int i = 0; i < mapping.bindings.size(); i++) { const JoyBinding binding = mapping.bindings[i]; @@ -1106,7 +1109,6 @@ Input::JoyEvent Input::_get_mapped_button_event(const JoyDeviceMapping &mapping, Input::JoyEvent Input::_get_mapped_axis_event(const JoyDeviceMapping &mapping, JoyAxis p_axis, float p_value) { JoyEvent event; - event.type = TYPE_MAX; for (int i = 0; i < mapping.bindings.size(); i++) { const JoyBinding binding = mapping.bindings[i]; diff --git a/core/input/input.h b/core/input/input.h index ac688b53b8..bbdac46805 100644 --- a/core/input/input.h +++ b/core/input/input.h @@ -157,9 +157,9 @@ private: }; struct JoyEvent { - int type; - int index; // Can be either JoyAxis or JoyButton. - float value; + int type = TYPE_MAX; + int index = -1; // Can be either JoyAxis or JoyButton. + float value = 0.f; }; struct JoyBinding { diff --git a/core/input/input_event.cpp b/core/input/input_event.cpp index b8ab722b12..2d4c203748 100644 --- a/core/input/input_event.cpp +++ b/core/input/input_event.cpp @@ -47,30 +47,30 @@ int InputEvent::get_device() const { } bool InputEvent::is_action(const StringName &p_action, bool p_exact_match) const { - return InputMap::get_singleton()->event_is_action(Ref((InputEvent *)this), p_action, p_exact_match); + return InputMap::get_singleton()->event_is_action(Ref(const_cast(this)), p_action, p_exact_match); } bool InputEvent::is_action_pressed(const StringName &p_action, bool p_allow_echo, bool p_exact_match) const { bool pressed; - bool valid = InputMap::get_singleton()->event_get_action_status(Ref((InputEvent *)this), p_action, p_exact_match, &pressed, nullptr, nullptr); + bool valid = InputMap::get_singleton()->event_get_action_status(Ref(const_cast(this)), p_action, p_exact_match, &pressed, nullptr, nullptr); return valid && pressed && (p_allow_echo || !is_echo()); } bool InputEvent::is_action_released(const StringName &p_action, bool p_exact_match) const { bool pressed; - bool valid = InputMap::get_singleton()->event_get_action_status(Ref((InputEvent *)this), p_action, p_exact_match, &pressed, nullptr, nullptr); + bool valid = InputMap::get_singleton()->event_get_action_status(Ref(const_cast(this)), p_action, p_exact_match, &pressed, nullptr, nullptr); return valid && !pressed; } float InputEvent::get_action_strength(const StringName &p_action, bool p_exact_match) const { float strength; - bool valid = InputMap::get_singleton()->event_get_action_status(Ref((InputEvent *)this), p_action, p_exact_match, nullptr, &strength, nullptr); + bool valid = InputMap::get_singleton()->event_get_action_status(Ref(const_cast(this)), p_action, p_exact_match, nullptr, &strength, nullptr); return valid ? strength : 0.0f; } float InputEvent::get_action_raw_strength(const StringName &p_action, bool p_exact_match) const { float raw_strength; - bool valid = InputMap::get_singleton()->event_get_action_status(Ref((InputEvent *)this), p_action, p_exact_match, nullptr, nullptr, &raw_strength); + bool valid = InputMap::get_singleton()->event_get_action_status(Ref(const_cast(this)), p_action, p_exact_match, nullptr, nullptr, &raw_strength); return valid ? raw_strength : 0.0f; } @@ -83,7 +83,7 @@ bool InputEvent::is_echo() const { } Ref InputEvent::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const { - return Ref((InputEvent *)this); + return Ref(const_cast(this)); } bool InputEvent::action_match(const Ref &p_event, bool p_exact_match, float p_deadzone, bool *r_pressed, float *r_strength, float *r_raw_strength) const { diff --git a/core/io/file_access_network.cpp b/core/io/file_access_network.cpp index cb38ac0928..612181f8d5 100644 --- a/core/io/file_access_network.cpp +++ b/core/io/file_access_network.cpp @@ -165,7 +165,7 @@ void FileAccessNetworkClient::_thread_func() { } void FileAccessNetworkClient::_thread_func(void *s) { - FileAccessNetworkClient *self = (FileAccessNetworkClient *)s; + FileAccessNetworkClient *self = static_cast(s); self->_thread_func(); } diff --git a/core/io/file_access_pack.h b/core/io/file_access_pack.h index fe4b12aef6..d4b32df2c7 100644 --- a/core/io/file_access_pack.h +++ b/core/io/file_access_pack.h @@ -139,8 +139,8 @@ public: class PackedSourcePCK : public PackSource { public: - virtual bool try_open_pack(const String &p_path, bool p_replace_files, uint64_t p_offset); - virtual FileAccess *get_file(const String &p_path, PackedData::PackedFile *p_file); + virtual bool try_open_pack(const String &p_path, bool p_replace_files, uint64_t p_offset) override; + virtual FileAccess *get_file(const String &p_path, PackedData::PackedFile *p_file) override; }; class FileAccessPack : public FileAccess { diff --git a/core/io/file_access_zip.h b/core/io/file_access_zip.h index 7cd5893101..a238c66437 100644 --- a/core/io/file_access_zip.h +++ b/core/io/file_access_zip.h @@ -67,8 +67,8 @@ public: bool file_exists(String p_name) const; - virtual bool try_open_pack(const String &p_path, bool p_replace_files, uint64_t p_offset); - FileAccess *get_file(const String &p_path, PackedData::PackedFile *p_file); + virtual bool try_open_pack(const String &p_path, bool p_replace_files, uint64_t p_offset) override; + FileAccess *get_file(const String &p_path, PackedData::PackedFile *p_file) override; static ZipArchive *get_singleton(); diff --git a/core/io/ip.cpp b/core/io/ip.cpp index 2f88307d94..52674150bb 100644 --- a/core/io/ip.cpp +++ b/core/io/ip.cpp @@ -109,7 +109,7 @@ struct _IP_ResolverPrivate { } static void _thread_function(void *self) { - _IP_ResolverPrivate *ipr = (_IP_ResolverPrivate *)self; + _IP_ResolverPrivate *ipr = static_cast<_IP_ResolverPrivate *>(self); while (!ipr->thread_abort) { ipr->sem.wait(); diff --git a/core/io/packed_data_container.cpp b/core/io/packed_data_container.cpp index 14183b472b..027fdd51aa 100644 --- a/core/io/packed_data_container.cpp +++ b/core/io/packed_data_container.cpp @@ -105,7 +105,7 @@ Variant PackedDataContainer::_get_at_ofs(uint32_t p_ofs, const uint8_t *p_buf, b if (type == TYPE_ARRAY || type == TYPE_DICT) { Ref pdcr = memnew(PackedDataContainerRef); - Ref pdc = Ref((PackedDataContainer *)this); + Ref pdc = Ref(const_cast(this)); pdcr->from = pdc; pdcr->offset = p_ofs; diff --git a/core/io/translation_loader_po.cpp b/core/io/translation_loader_po.cpp index 801bd8b0bf..30df46a6b4 100644 --- a/core/io/translation_loader_po.cpp +++ b/core/io/translation_loader_po.cpp @@ -98,7 +98,6 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) { { Vector data; f->seek(trans_table_offset + i * 8); - uint32_t str_start = 0; uint32_t str_len = f->get_32(); uint32_t str_offset = f->get_32(); @@ -116,6 +115,7 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) { translation->set_plural_rule(config.substr(p_start, p_end - p_start)); } } else { + uint32_t str_start = 0; Vector plural_msg; for (uint32_t j = 0; j < str_len + 1; j++) { if (data[j] == 0x00) { diff --git a/core/math/basis.cpp b/core/math/basis.cpp index 84f9d12bb1..eb6703aff2 100644 --- a/core/math/basis.cpp +++ b/core/math/basis.cpp @@ -1002,7 +1002,7 @@ void Basis::rotate_sh(real_t *p_values) { const static real_t s_scale_dst2 = s_c3 * s_c_scale_inv; const static real_t s_scale_dst4 = s_c5 * s_c_scale_inv; - real_t src[9] = { p_values[0], p_values[1], p_values[2], p_values[3], p_values[4], p_values[5], p_values[6], p_values[7], p_values[8] }; + const real_t src[9] = { p_values[0], p_values[1], p_values[2], p_values[3], p_values[4], p_values[5], p_values[6], p_values[7], p_values[8] }; real_t m00 = elements[0][0]; real_t m01 = elements[0][1]; diff --git a/core/math/face3.cpp b/core/math/face3.cpp index 5bc1bc25e6..fb92f6b0df 100644 --- a/core/math/face3.cpp +++ b/core/math/face3.cpp @@ -208,7 +208,7 @@ bool Face3::intersects_aabb(const AABB &p_aabb) const { /** TEST ALL EDGES **/ - Vector3 edge_norms[3] = { + const Vector3 edge_norms[3] = { vertex[0] - vertex[1], vertex[1] - vertex[2], vertex[2] - vertex[0], diff --git a/core/math/face3.h b/core/math/face3.h index c61d6ad66e..23260336fa 100644 --- a/core/math/face3.h +++ b/core/math/face3.h @@ -133,7 +133,7 @@ bool Face3::intersects_aabb2(const AABB &p_aabb) const { #undef TEST_AXIS - Vector3 edge_norms[3] = { + const Vector3 edge_norms[3] = { vertex[0] - vertex[1], vertex[1] - vertex[2], vertex[2] - vertex[0], diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h index 44340b97ae..b741277872 100644 --- a/core/math/math_funcs.h +++ b/core/math/math_funcs.h @@ -473,16 +473,16 @@ public: uint32_t x = ci.ui; uint32_t sign = (unsigned short)(x >> 31); uint32_t mantissa; - uint32_t exp; + uint32_t exponent; uint16_t hf; // get mantissa mantissa = x & ((1 << 23) - 1); // get exponent bits - exp = x & (0xFF << 23); - if (exp >= 0x47800000) { + exponent = x & (0xFF << 23); + if (exponent >= 0x47800000) { // check if the original single precision float number is a NaN - if (mantissa && (exp == (0xFF << 23))) { + if (mantissa && (exponent == (0xFF << 23))) { // we have a single precision NaN mantissa = (1 << 23) - 1; } else { @@ -493,17 +493,18 @@ public: (uint16_t)(mantissa >> 13); } // check if exponent is <= -15 - else if (exp <= 0x38000000) { - /*// store a denorm half-float value or zero - exp = (0x38000000 - exp) >> 23; - mantissa >>= (14 + exp); - - hf = (((uint16_t)sign) << 15) | (uint16_t)(mantissa); - */ + else if (exponent <= 0x38000000) { + /* + // store a denorm half-float value or zero + exponent = (0x38000000 - exponent) >> 23; + mantissa >>= (14 + exponent); + + hf = (((uint16_t)sign) << 15) | (uint16_t)(mantissa); + */ hf = 0; //denormals do not work for 3D, convert to zero } else { hf = (((uint16_t)sign) << 15) | - (uint16_t)((exp - 0x38000000) >> 13) | + (uint16_t)((exponent - 0x38000000) >> 13) | (uint16_t)(mantissa >> 13); } diff --git a/core/object/ref_counted.h b/core/object/ref_counted.h index 8eb1c97cce..dcacf19890 100644 --- a/core/object/ref_counted.h +++ b/core/object/ref_counted.h @@ -261,7 +261,7 @@ struct PtrToArg> { typedef Ref EncodeT; _FORCE_INLINE_ static void encode(Ref p_val, const void *p_ptr) { - *(Ref *)p_ptr = p_val; + *(const_cast *>(reinterpret_cast *>(p_ptr))) = p_val; } }; diff --git a/core/object/script_language.cpp b/core/object/script_language.cpp index 11440c37fe..a5d25bf533 100644 --- a/core/object/script_language.cpp +++ b/core/object/script_language.cpp @@ -144,7 +144,7 @@ void ScriptServer::register_language(ScriptLanguage *p_language) { _languages[_language_count++] = p_language; } -void ScriptServer::unregister_language(ScriptLanguage *p_language) { +void ScriptServer::unregister_language(const ScriptLanguage *p_language) { for (int i = 0; i < _language_count; i++) { if (_languages[i] == p_language) { _language_count--; diff --git a/core/object/script_language.h b/core/object/script_language.h index 08b82d798e..69002c81f4 100644 --- a/core/object/script_language.h +++ b/core/object/script_language.h @@ -68,7 +68,7 @@ public: _FORCE_INLINE_ static int get_language_count() { return _language_count; } static ScriptLanguage *get_language(int p_idx); static void register_language(ScriptLanguage *p_language); - static void unregister_language(ScriptLanguage *p_language); + static void unregister_language(const ScriptLanguage *p_language); static void set_reload_scripts_on_save(bool p_enable); static bool is_reload_scripts_on_save_enabled(); @@ -438,34 +438,34 @@ class PlaceHolderScriptInstance : public ScriptInstance { Ref