diff options
Diffstat (limited to 'core')
36 files changed, 164 insertions, 160 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<EngineProfiler *>(p_user)->toggle(p_enable, p_opts); }, [](void *p_user, const Array &p_data) { - ((EngineProfiler *)p_user)->add(p_data); + static_cast<EngineProfiler *>(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<EngineProfiler *>(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<ScriptsProfiler *>(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<ScriptsProfiler *>(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<RemoteDebugger *>(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<RemoteDebugger *>(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<RemoteDebuggerPeer> 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<RemoteDebugger *>(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<RemoteDebugger *>(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<RemoteDebuggerPeerTCP *>(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<StreamPeerTCP> p_stream = Ref<StreamPeerTCP>()); ~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<NativeExtension *>(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<NativeExtension *>(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<NativeExtension *>(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<NativeExtension *>(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<NativeExtension *>(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<NativeExtension *>(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<NativeExtension *>(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<NativeExtension *>(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>((InputEvent *)this), p_action, p_exact_match); + return InputMap::get_singleton()->event_is_action(Ref<InputEvent>(const_cast<InputEvent *>(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>((InputEvent *)this), p_action, p_exact_match, &pressed, nullptr, nullptr); + bool valid = InputMap::get_singleton()->event_get_action_status(Ref<InputEvent>(const_cast<InputEvent *>(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>((InputEvent *)this), p_action, p_exact_match, &pressed, nullptr, nullptr); + bool valid = InputMap::get_singleton()->event_get_action_status(Ref<InputEvent>(const_cast<InputEvent *>(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>((InputEvent *)this), p_action, p_exact_match, nullptr, &strength, nullptr); + bool valid = InputMap::get_singleton()->event_get_action_status(Ref<InputEvent>(const_cast<InputEvent *>(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>((InputEvent *)this), p_action, p_exact_match, nullptr, nullptr, &raw_strength); + bool valid = InputMap::get_singleton()->event_get_action_status(Ref<InputEvent>(const_cast<InputEvent *>(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> InputEvent::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const { - return Ref<InputEvent>((InputEvent *)this); + return Ref<InputEvent>(const_cast<InputEvent *>(this)); } bool InputEvent::action_match(const Ref<InputEvent> &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<FileAccessNetworkClient *>(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<PackedDataContainerRef> pdcr = memnew(PackedDataContainerRef); - Ref<PackedDataContainer> pdc = Ref<PackedDataContainer>((PackedDataContainer *)this); + Ref<PackedDataContainer> pdc = Ref<PackedDataContainer>(const_cast<PackedDataContainer *>(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<uint8_t> 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<String> 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<Ref<T>> { typedef Ref<T> EncodeT; _FORCE_INLINE_ static void encode(Ref<T> p_val, const void *p_ptr) { - *(Ref<RefCounted> *)p_ptr = p_val; + *(const_cast<Ref<RefCounted> *>(reinterpret_cast<const Ref<RefCounted> *>(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<Script> script; public: - virtual bool set(const StringName &p_name, const Variant &p_value); - virtual bool get(const StringName &p_name, Variant &r_ret) const; - virtual void get_property_list(List<PropertyInfo> *p_properties) const; - virtual Variant::Type get_property_type(const StringName &p_name, bool *r_is_valid = nullptr) const; + virtual bool set(const StringName &p_name, const Variant &p_value) override; + virtual bool get(const StringName &p_name, Variant &r_ret) const override; + virtual void get_property_list(List<PropertyInfo> *p_properties) const override; + virtual Variant::Type get_property_type(const StringName &p_name, bool *r_is_valid = nullptr) const override; - virtual void get_method_list(List<MethodInfo> *p_list) const; - virtual bool has_method(const StringName &p_method) const; + virtual void get_method_list(List<MethodInfo> *p_list) const override; + virtual bool has_method(const StringName &p_method) const override; - virtual Variant callp(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) { + virtual Variant callp(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) override { r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; return Variant(); } - virtual void notification(int p_notification) {} + virtual void notification(int p_notification) override {} - virtual Ref<Script> get_script() const { return script; } + virtual Ref<Script> get_script() const override { return script; } - virtual ScriptLanguage *get_language() { return language; } + virtual ScriptLanguage *get_language() override { return language; } - Object *get_owner() { return owner; } + Object *get_owner() override { return owner; } void update(const List<PropertyInfo> &p_properties, const Map<StringName, Variant> &p_values); //likely changed in editor - virtual bool is_placeholder() const { return true; } + virtual bool is_placeholder() const override { return true; } - virtual void property_set_fallback(const StringName &p_name, const Variant &p_value, bool *r_valid = nullptr); - virtual Variant property_get_fallback(const StringName &p_name, bool *r_valid = nullptr); + virtual void property_set_fallback(const StringName &p_name, const Variant &p_value, bool *r_valid = nullptr) override; + virtual Variant property_get_fallback(const StringName &p_name, bool *r_valid = nullptr) override; - virtual const Vector<Multiplayer::RPCConfig> get_rpc_methods() const { return Vector<Multiplayer::RPCConfig>(); } + virtual const Vector<Multiplayer::RPCConfig> get_rpc_methods() const override { return Vector<Multiplayer::RPCConfig>(); } PlaceHolderScriptInstance(ScriptLanguage *p_language, Ref<Script> p_script, Object *p_owner); ~PlaceHolderScriptInstance(); diff --git a/core/os/pool_allocator.cpp b/core/os/pool_allocator.cpp index 190617f967..f622e2c7c5 100644 --- a/core/os/pool_allocator.cpp +++ b/core/os/pool_allocator.cpp @@ -149,7 +149,7 @@ void PoolAllocator::compact_up(int p_from) { } } -bool PoolAllocator::find_entry_index(EntryIndicesPos *p_map_pos, Entry *p_entry) { +bool PoolAllocator::find_entry_index(EntryIndicesPos *p_map_pos, const Entry *p_entry) { EntryArrayPos entry_pos = entry_max; for (int i = 0; i < entry_count; i++) { @@ -424,7 +424,7 @@ bool PoolAllocator::is_locked(ID p_mem) const { } mt_lock(); - const Entry *e = ((PoolAllocator *)(this))->get_entry(p_mem); + const Entry *e = const_cast<PoolAllocator *>(this)->get_entry(p_mem); if (!e) { mt_unlock(); ERR_PRINT("!e"); diff --git a/core/os/pool_allocator.h b/core/os/pool_allocator.h index 0919a024e2..27a936ed78 100644 --- a/core/os/pool_allocator.h +++ b/core/os/pool_allocator.h @@ -108,7 +108,7 @@ private: void compact_up(int p_from = 0); bool get_free_entry(EntryArrayPos *p_pos); bool find_hole(EntryArrayPos *p_pos, int p_for_size); - bool find_entry_index(EntryIndicesPos *p_map_pos, Entry *p_entry); + bool find_entry_index(EntryIndicesPos *p_map_pos, const Entry *p_entry); Entry *get_entry(ID p_mem); const Entry *get_entry(ID p_mem) const; diff --git a/core/string/print_string.cpp b/core/string/print_string.cpp index 97e119bcf6..919c9e08e3 100644 --- a/core/string/print_string.cpp +++ b/core/string/print_string.cpp @@ -45,7 +45,7 @@ void add_print_handler(PrintHandlerList *p_handler) { _global_unlock(); } -void remove_print_handler(PrintHandlerList *p_handler) { +void remove_print_handler(const PrintHandlerList *p_handler) { _global_lock(); PrintHandlerList *prev = nullptr; diff --git a/core/string/print_string.h b/core/string/print_string.h index 669d2ea316..f19573ad45 100644 --- a/core/string/print_string.h +++ b/core/string/print_string.h @@ -54,7 +54,7 @@ String stringify_variants(Variant p_var, Args... p_args) { } void add_print_handler(PrintHandlerList *p_handler); -void remove_print_handler(PrintHandlerList *p_handler); +void remove_print_handler(const PrintHandlerList *p_handler); extern bool _print_line_enabled; extern bool _print_error_enabled; diff --git a/core/string/translation.cpp b/core/string/translation.cpp index c41828de05..d6d361b5f1 100644 --- a/core/string/translation.cpp +++ b/core/string/translation.cpp @@ -891,7 +891,7 @@ String TranslationServer::wrap_with_fakebidi_characters(String &p_message) const return res; } -String TranslationServer::add_padding(String &p_message, int p_length) const { +String TranslationServer::add_padding(const String &p_message, int p_length) const { String res; String prefix = pseudolocalization_prefix; String suffix; @@ -921,7 +921,7 @@ const char32_t *TranslationServer::get_accented_version(char32_t p_character) co } bool TranslationServer::is_placeholder(String &p_message, int p_index) const { - return p_message[p_index] == '%' && p_index < p_message.size() - 1 && + return p_index < p_message.size() - 1 && p_message[p_index] == '%' && (p_message[p_index + 1] == 's' || p_message[p_index + 1] == 'c' || p_message[p_index + 1] == 'd' || p_message[p_index + 1] == 'o' || p_message[p_index + 1] == 'x' || p_message[p_index + 1] == 'X' || p_message[p_index + 1] == 'f'); } diff --git a/core/string/translation.h b/core/string/translation.h index 947ca4c6d8..ded6ed5925 100644 --- a/core/string/translation.h +++ b/core/string/translation.h @@ -96,7 +96,7 @@ class TranslationServer : public Object { String double_vowels(String &p_message) const; String replace_with_accented_string(String &p_message) const; String wrap_with_fakebidi_characters(String &p_message) const; - String add_padding(String &p_message, int p_length) const; + String add_padding(const String &p_message, int p_length) const; const char32_t *get_accented_version(char32_t p_character) const; bool is_placeholder(String &p_message, int p_index) const; diff --git a/core/templates/command_queue_mt.h b/core/templates/command_queue_mt.h index 0aa1cfd541..7d3e31b5bc 100644 --- a/core/templates/command_queue_mt.h +++ b/core/templates/command_queue_mt.h @@ -215,7 +215,7 @@ T *instance; \ M method; \ SEMIC_SEP_LIST(PARAM_DECL, N); \ - virtual void call() { \ + virtual void call() override { \ (instance->*method)(COMMA_SEP_LIST(ARG, N)); \ } \ }; @@ -227,7 +227,7 @@ T *instance; \ M method; \ SEMIC_SEP_LIST(PARAM_DECL, N); \ - virtual void call() { \ + virtual void call() override { \ *ret = (instance->*method)(COMMA_SEP_LIST(ARG, N)); \ } \ }; @@ -238,7 +238,7 @@ T *instance; \ M method; \ SEMIC_SEP_LIST(PARAM_DECL, N); \ - virtual void call() { \ + virtual void call() override { \ (instance->*method)(COMMA_SEP_LIST(ARG, N)); \ } \ }; @@ -313,7 +313,7 @@ class CommandQueueMT { struct SyncCommand : public CommandBase { SyncSemaphore *sync_sem = nullptr; - virtual void post() { + virtual void post() override { sync_sem->sem.post(); } }; diff --git a/core/templates/thread_work_pool.h b/core/templates/thread_work_pool.h index d364ac4fd8..b0cebf04f1 100644 --- a/core/templates/thread_work_pool.h +++ b/core/templates/thread_work_pool.h @@ -52,7 +52,7 @@ class ThreadWorkPool { C *instance; M method; U userdata; - virtual void work() { + virtual void work() override { while (true) { uint32_t work_index = index->fetch_add(1, std::memory_order_relaxed); if (work_index >= max_elements) { diff --git a/core/variant/callable_bind.cpp b/core/variant/callable_bind.cpp index 797e8afede..1a400b4360 100644 --- a/core/variant/callable_bind.cpp +++ b/core/variant/callable_bind.cpp @@ -40,8 +40,8 @@ String CallableCustomBind::get_as_text() const { } bool CallableCustomBind::_equal_func(const CallableCustom *p_a, const CallableCustom *p_b) { - const CallableCustomBind *a = (const CallableCustomBind *)p_a; - const CallableCustomBind *b = (const CallableCustomBind *)p_b; + const CallableCustomBind *a = static_cast<const CallableCustomBind *>(p_a); + const CallableCustomBind *b = static_cast<const CallableCustomBind *>(p_b); if (!(a->callable != b->callable)) { return false; @@ -55,8 +55,8 @@ bool CallableCustomBind::_equal_func(const CallableCustom *p_a, const CallableCu } bool CallableCustomBind::_less_func(const CallableCustom *p_a, const CallableCustom *p_b) { - const CallableCustomBind *a = (const CallableCustomBind *)p_a; - const CallableCustomBind *b = (const CallableCustomBind *)p_b; + const CallableCustomBind *a = static_cast<const CallableCustomBind *>(p_a); + const CallableCustomBind *b = static_cast<const CallableCustomBind *>(p_b); if (a->callable < b->callable) { return true; @@ -117,8 +117,8 @@ String CallableCustomUnbind::get_as_text() const { } bool CallableCustomUnbind::_equal_func(const CallableCustom *p_a, const CallableCustom *p_b) { - const CallableCustomUnbind *a = (const CallableCustomUnbind *)p_a; - const CallableCustomUnbind *b = (const CallableCustomUnbind *)p_b; + const CallableCustomUnbind *a = static_cast<const CallableCustomUnbind *>(p_a); + const CallableCustomUnbind *b = static_cast<const CallableCustomUnbind *>(p_b); if (!(a->callable != b->callable)) { return false; @@ -132,8 +132,8 @@ bool CallableCustomUnbind::_equal_func(const CallableCustom *p_a, const Callable } bool CallableCustomUnbind::_less_func(const CallableCustom *p_a, const CallableCustom *p_b) { - const CallableCustomUnbind *a = (const CallableCustomUnbind *)p_a; - const CallableCustomUnbind *b = (const CallableCustomUnbind *)p_b; + const CallableCustomUnbind *a = static_cast<const CallableCustomUnbind *>(p_a); + const CallableCustomUnbind *b = static_cast<const CallableCustomUnbind *>(p_b); if (a->callable < b->callable) { return true; diff --git a/core/variant/callable_bind.h b/core/variant/callable_bind.h index 4f79a29629..a5c830e109 100644 --- a/core/variant/callable_bind.h +++ b/core/variant/callable_bind.h @@ -43,14 +43,14 @@ class CallableCustomBind : public CallableCustom { public: //for every type that inherits, these must always be the same for this type - virtual uint32_t hash() const; - virtual String get_as_text() const; - virtual CompareEqualFunc get_compare_equal_func() const; - virtual CompareLessFunc get_compare_less_func() const; - virtual StringName get_method() const; - virtual ObjectID get_object() const; //must always be able to provide an object - virtual void call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const; - virtual const Callable *get_base_comparator() const; + virtual uint32_t hash() const override; + virtual String get_as_text() const override; + virtual CompareEqualFunc get_compare_equal_func() const override; + virtual CompareLessFunc get_compare_less_func() const override; + virtual StringName get_method() const override; + virtual ObjectID get_object() const override; //must always be able to provide an object + virtual void call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const override; + virtual const Callable *get_base_comparator() const override; Callable get_callable() { return callable; } Vector<Variant> get_binds() { return binds; } @@ -68,14 +68,14 @@ class CallableCustomUnbind : public CallableCustom { public: //for every type that inherits, these must always be the same for this type - virtual uint32_t hash() const; - virtual String get_as_text() const; - virtual CompareEqualFunc get_compare_equal_func() const; - virtual CompareLessFunc get_compare_less_func() const; - virtual StringName get_method() const; - virtual ObjectID get_object() const; //must always be able to provide an object - virtual void call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const; - virtual const Callable *get_base_comparator() const; + virtual uint32_t hash() const override; + virtual String get_as_text() const override; + virtual CompareEqualFunc get_compare_equal_func() const override; + virtual CompareLessFunc get_compare_less_func() const override; + virtual StringName get_method() const override; + virtual ObjectID get_object() const override; //must always be able to provide an object + virtual void call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const override; + virtual const Callable *get_base_comparator() const override; Callable get_callable() { return callable; } int get_unbinds() { return argcount; } diff --git a/core/variant/variant_parser.h b/core/variant/variant_parser.h index e5585076c2..b297babd6f 100644 --- a/core/variant/variant_parser.h +++ b/core/variant/variant_parser.h @@ -51,9 +51,9 @@ public: struct StreamFile : public Stream { FileAccess *f = nullptr; - virtual char32_t get_char(); - virtual bool is_utf8() const; - virtual bool is_eof() const; + virtual char32_t get_char() override; + virtual bool is_utf8() const override; + virtual bool is_eof() const override; StreamFile() {} }; @@ -62,9 +62,9 @@ public: String s; int pos = 0; - virtual char32_t get_char(); - virtual bool is_utf8() const; - virtual bool is_eof() const; + virtual char32_t get_char() override; + virtual bool is_utf8() const override; + virtual bool is_eof() const override; StreamString() {} }; diff --git a/core/variant/variant_utility.cpp b/core/variant/variant_utility.cpp index 05fb577e2c..6ed85815be 100644 --- a/core/variant/variant_utility.cpp +++ b/core/variant/variant_utility.cpp @@ -470,20 +470,20 @@ struct VariantUtilityFunctions { r_error.argument = 1; return String(); } - String str; + String s; for (int i = 0; i < p_arg_count; i++) { String os = p_args[i]->operator String(); if (i == 0) { - str = os; + s = os; } else { - str += os; + s += os; } } r_error.error = Callable::CallError::CALL_OK; - return str; + return s; } static inline String error_string(Error error) { @@ -495,98 +495,98 @@ struct VariantUtilityFunctions { } static inline void print(const Variant **p_args, int p_arg_count, Callable::CallError &r_error) { - String str; + String s; for (int i = 0; i < p_arg_count; i++) { String os = p_args[i]->operator String(); if (i == 0) { - str = os; + s = os; } else { - str += os; + s += os; } } - print_line(str); + print_line(s); r_error.error = Callable::CallError::CALL_OK; } static inline void print_verbose(const Variant **p_args, int p_arg_count, Callable::CallError &r_error) { if (OS::get_singleton()->is_stdout_verbose()) { - String str; + String s; for (int i = 0; i < p_arg_count; i++) { String os = p_args[i]->operator String(); if (i == 0) { - str = os; + s = os; } else { - str += os; + s += os; } } // No need to use `print_verbose()` as this call already only happens // when verbose mode is enabled. This avoids performing string argument concatenation // when not needed. - print_line(str); + print_line(s); } r_error.error = Callable::CallError::CALL_OK; } static inline void printerr(const Variant **p_args, int p_arg_count, Callable::CallError &r_error) { - String str; + String s; for (int i = 0; i < p_arg_count; i++) { String os = p_args[i]->operator String(); if (i == 0) { - str = os; + s = os; } else { - str += os; + s += os; } } - print_error(str); + print_error(s); r_error.error = Callable::CallError::CALL_OK; } static inline void printt(const Variant **p_args, int p_arg_count, Callable::CallError &r_error) { - String str; + String s; for (int i = 0; i < p_arg_count; i++) { if (i) { - str += "\t"; + s += "\t"; } - str += p_args[i]->operator String(); + s += p_args[i]->operator String(); } - print_line(str); + print_line(s); r_error.error = Callable::CallError::CALL_OK; } static inline void prints(const Variant **p_args, int p_arg_count, Callable::CallError &r_error) { - String str; + String s; for (int i = 0; i < p_arg_count; i++) { if (i) { - str += " "; + s += " "; } - str += p_args[i]->operator String(); + s += p_args[i]->operator String(); } - print_line(str); + print_line(s); r_error.error = Callable::CallError::CALL_OK; } static inline void printraw(const Variant **p_args, int p_arg_count, Callable::CallError &r_error) { - String str; + String s; for (int i = 0; i < p_arg_count; i++) { String os = p_args[i]->operator String(); if (i == 0) { - str = os; + s = os; } else { - str += os; + s += os; } } - OS::get_singleton()->print("%s", str.utf8().get_data()); + OS::get_singleton()->print("%s", s.utf8().get_data()); r_error.error = Callable::CallError::CALL_OK; } @@ -595,18 +595,18 @@ struct VariantUtilityFunctions { r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; r_error.argument = 1; } - String str; + String s; for (int i = 0; i < p_arg_count; i++) { String os = p_args[i]->operator String(); if (i == 0) { - str = os; + s = os; } else { - str += os; + s += os; } } - ERR_PRINT(str); + ERR_PRINT(s); r_error.error = Callable::CallError::CALL_OK; } @@ -615,18 +615,18 @@ struct VariantUtilityFunctions { r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; r_error.argument = 1; } - String str; + String s; for (int i = 0; i < p_arg_count; i++) { String os = p_args[i]->operator String(); if (i == 0) { - str = os; + s = os; } else { - str += os; + s += os; } } - WARN_PRINT(str); + WARN_PRINT(s); r_error.error = Callable::CallError::CALL_OK; } |