From 8fb14efb49d202f6af9dc1f1e6a767298dacf9e6 Mon Sep 17 00:00:00 2001 From: rune-scape Date: Mon, 29 Jul 2024 21:23:12 -0700 Subject: [PATCH] Clean up const_cast --- core/math/a_star.cpp | 2 +- core/math/a_star.h | 2 +- core/object/ref_counted.h | 6 +-- core/os/condition_variable.h | 2 +- core/os/mutex.h | 2 +- core/os/pool_allocator.cpp | 2 +- core/os/safe_binary_mutex.h | 2 +- core/templates/rid_owner.h | 6 +-- core/variant/method_ptrcall.h | 2 +- core/variant/variant.cpp | 4 +- drivers/windows/dir_access_windows.cpp | 2 +- editor/editor_help_search.cpp | 12 +++--- editor/editor_help_search.h | 2 +- editor/editor_resource_preview.cpp | 8 ++-- editor/editor_resource_preview.h | 6 +-- .../dedicated_server_export_plugin.cpp | 2 +- editor/plugins/editor_preview_plugins.h | 6 +-- editor/plugins/tiles/tiles_editor_plugin.cpp | 4 +- .../plugins/visual_shader_editor_plugin.cpp | 2 +- editor/plugins/visual_shader_editor_plugin.h | 2 +- modules/enet/enet_connection.cpp | 4 +- modules/gdscript/gdscript.cpp | 4 +- modules/gdscript/gdscript_compiler.cpp | 4 +- modules/gdscript/gdscript_editor.cpp | 4 +- modules/text_server_adv/text_server_adv.cpp | 10 ++--- modules/text_server_fb/text_server_fb.cpp | 10 ++--- platform/android/os_android.cpp | 8 ++-- platform/android/os_android.h | 10 ++--- platform/linuxbsd/tts_linux.cpp | 4 +- platform/linuxbsd/tts_linux.h | 6 +-- platform/macos/display_server_macos.h | 14 +++---- platform/macos/display_server_macos.mm | 14 +++---- scene/2d/physics/physics_body_2d.cpp | 3 +- scene/2d/skeleton_2d.cpp | 1 + scene/3d/physics/physics_body_3d.cpp | 3 +- scene/3d/skeleton_3d.cpp | 40 +++++++++++------- scene/3d/skeleton_3d.h | 19 +++++---- scene/animation/animation_tree.cpp | 10 ++--- scene/animation/animation_tree.h | 18 ++++---- scene/gui/button.cpp | 4 +- scene/gui/button.h | 2 +- scene/gui/control.cpp | 36 ++++++++-------- scene/gui/control.h | 10 ++--- scene/gui/label.cpp | 16 +++---- scene/gui/label.h | 16 +++---- scene/gui/popup_menu.cpp | 4 +- scene/gui/popup_menu.h | 4 +- scene/gui/tree.cpp | 8 ++-- scene/gui/tree.h | 4 +- scene/main/canvas_layer.cpp | 8 ++-- scene/main/canvas_layer.h | 10 ++--- scene/main/viewport.cpp | 8 ++-- scene/main/viewport.h | 2 +- scene/resources/audio_stream_polyphonic.cpp | 28 ++++++++++--- scene/resources/audio_stream_polyphonic.h | 2 + scene/resources/curve.cpp | 6 ++- scene/resources/curve.h | 5 ++- scene/resources/font.cpp | 36 ++++++++-------- scene/resources/font.h | 4 +- scene/resources/text_line.cpp | 22 +++++----- scene/resources/text_line.h | 4 +- scene/resources/text_paragraph.cpp | 42 +++++++++---------- scene/resources/text_paragraph.h | 10 ++--- scene/resources/visual_shader.cpp | 16 +++---- .../physics_2d/godot_physics_server_2d.cpp | 11 +++-- servers/physics_2d/godot_physics_server_2d.h | 2 +- servers/physics_2d/godot_shape_2d.cpp | 3 +- servers/physics_2d/godot_step_2d.cpp | 2 +- .../physics_3d/godot_physics_server_3d.cpp | 10 ++--- servers/physics_3d/godot_physics_server_3d.h | 2 +- servers/physics_3d/godot_shape_3d.cpp | 2 +- servers/physics_3d/godot_step_3d.cpp | 6 +-- servers/physics_server_2d.h | 2 +- servers/physics_server_3d.h | 2 +- servers/rendering/renderer_scene_cull.cpp | 36 ++++++++-------- servers/rendering/renderer_scene_cull.h | 26 ++++++------ 76 files changed, 356 insertions(+), 317 deletions(-) diff --git a/core/math/a_star.cpp b/core/math/a_star.cpp index 449760494735..b35c151d865b 100644 --- a/core/math/a_star.cpp +++ b/core/math/a_star.cpp @@ -40,7 +40,7 @@ int64_t AStar3D::get_available_point_id() const { while (points.has(cur_new_id)) { cur_new_id++; } - const_cast(last_free_id) = cur_new_id; + last_free_id = cur_new_id; } return last_free_id; diff --git a/core/math/a_star.h b/core/math/a_star.h index 8e054c478989..99a84ae875b9 100644 --- a/core/math/a_star.h +++ b/core/math/a_star.h @@ -108,7 +108,7 @@ class AStar3D : public RefCounted { } }; - int64_t last_free_id = 0; + mutable int64_t last_free_id = 0; uint64_t pass = 1; OAHashMap points; diff --git a/core/object/ref_counted.h b/core/object/ref_counted.h index 5b358135c44a..d2f4f98c64f2 100644 --- a/core/object/ref_counted.h +++ b/core/object/ref_counted.h @@ -119,7 +119,7 @@ class Ref { template void operator=(const Ref &p_from) { - RefCounted *refb = const_cast(static_cast(p_from.ptr())); + RefCounted *refb = static_cast(p_from.ptr()); if (!refb) { unref(); return; @@ -168,7 +168,7 @@ class Ref { template Ref(const Ref &p_from) { - RefCounted *refb = const_cast(static_cast(p_from.ptr())); + RefCounted *refb = static_cast(p_from.ptr()); if (!refb) { unref(); return; @@ -247,7 +247,7 @@ struct PtrToArg> { return Ref(); } // p_ptr points to a RefCounted object - return Ref(const_cast(*reinterpret_cast(p_ptr))); + return Ref(*reinterpret_cast(p_ptr)); } typedef Ref EncodeT; diff --git a/core/os/condition_variable.h b/core/os/condition_variable.h index fa1355e98c70..e66789c1c38a 100644 --- a/core/os/condition_variable.h +++ b/core/os/condition_variable.h @@ -56,7 +56,7 @@ class ConditionVariable { public: template _ALWAYS_INLINE_ void wait(const MutexLock &p_lock) const { - condition.wait(const_cast &>(p_lock.lock)); + condition.wait(p_lock.lock); } _ALWAYS_INLINE_ void notify_one() const { diff --git a/core/os/mutex.h b/core/os/mutex.h index 3e7aa81bc1a5..13aac7447f5d 100644 --- a/core/os/mutex.h +++ b/core/os/mutex.h @@ -74,7 +74,7 @@ template class MutexLock { friend class ConditionVariable; - THREADING_NAMESPACE::unique_lock lock; + mutable THREADING_NAMESPACE::unique_lock lock; public: explicit MutexLock(const MutexT &p_mutex) : diff --git a/core/os/pool_allocator.cpp b/core/os/pool_allocator.cpp index 9a993cd14f77..d1397e4a647a 100644 --- a/core/os/pool_allocator.cpp +++ b/core/os/pool_allocator.cpp @@ -418,7 +418,7 @@ bool PoolAllocator::is_locked(ID p_mem) const { } mt_lock(); - const Entry *e = const_cast(this)->get_entry(p_mem); + const Entry *e = get_entry(p_mem); if (!e) { mt_unlock(); ERR_PRINT("!e"); diff --git a/core/os/safe_binary_mutex.h b/core/os/safe_binary_mutex.h index 1e98cc074cdc..8d0a355d5110 100644 --- a/core/os/safe_binary_mutex.h +++ b/core/os/safe_binary_mutex.h @@ -93,7 +93,7 @@ template class MutexLock> { friend class ConditionVariable; - THREADING_NAMESPACE::unique_lock lock; + mutable THREADING_NAMESPACE::unique_lock lock; public: _ALWAYS_INLINE_ explicit MutexLock(const SafeBinaryMutex &p_mutex) : diff --git a/core/templates/rid_owner.h b/core/templates/rid_owner.h index 86304d3c73ef..e18d604b27ff 100644 --- a/core/templates/rid_owner.h +++ b/core/templates/rid_owner.h @@ -152,7 +152,7 @@ class RID_Alloc : public RID_AllocBase { return _allocate_rid(); } - _FORCE_INLINE_ T *get_or_null(const RID &p_rid, bool p_initialize = false) { + _FORCE_INLINE_ T *get_or_null(const RID &p_rid, bool p_initialize = false) const { if (p_rid == RID()) { return nullptr; } @@ -381,7 +381,7 @@ class RID_PtrOwner { alloc.initialize_rid(p_rid, p_ptr); } - _FORCE_INLINE_ T *get_or_null(const RID &p_rid) { + _FORCE_INLINE_ T *get_or_null(const RID &p_rid) const { T **ptr = alloc.get_or_null(p_rid); if (unlikely(!ptr)) { return nullptr; @@ -447,7 +447,7 @@ class RID_Owner { alloc.initialize_rid(p_rid, p_ptr); } - _FORCE_INLINE_ T *get_or_null(const RID &p_rid) { + _FORCE_INLINE_ T *get_or_null(const RID &p_rid) const { return alloc.get_or_null(p_rid); } diff --git a/core/variant/method_ptrcall.h b/core/variant/method_ptrcall.h index 1e10709b12bd..540dcc4a4d91 100644 --- a/core/variant/method_ptrcall.h +++ b/core/variant/method_ptrcall.h @@ -160,7 +160,7 @@ MAKE_PTRARG_BY_REFERENCE(Variant); template struct PtrToArg { _FORCE_INLINE_ static T *convert(const void *p_ptr) { - return likely(p_ptr) ? const_cast(*reinterpret_cast(p_ptr)) : nullptr; + return likely(p_ptr) ? *reinterpret_cast(p_ptr) : nullptr; } typedef Object *EncodeT; _FORCE_INLINE_ static void encode(T *p_var, void *p_ptr) { diff --git a/core/variant/variant.cpp b/core/variant/variant.cpp index c1ef31c784d6..103439691ac1 100644 --- a/core/variant/variant.cpp +++ b/core/variant/variant.cpp @@ -1073,7 +1073,7 @@ bool Variant::is_null() const { } bool Variant::initialize_ref(Object *p_object) { - RefCounted *ref_counted = const_cast(static_cast(p_object)); + RefCounted *ref_counted = static_cast(p_object); if (!ref_counted->init_ref()) { return false; } @@ -1182,7 +1182,7 @@ void Variant::reference(const Variant &p_variant) { } } - _get_obj().obj = const_cast(p_variant._get_obj().obj); + _get_obj().obj = p_variant._get_obj().obj; _get_obj().id = p_variant._get_obj().id; } break; case CALLABLE: { diff --git a/drivers/windows/dir_access_windows.cpp b/drivers/windows/dir_access_windows.cpp index 63ba6a6c9681..0ade57814f4c 100644 --- a/drivers/windows/dir_access_windows.cpp +++ b/drivers/windows/dir_access_windows.cpp @@ -339,7 +339,7 @@ uint64_t DirAccessWindows::get_space_left() { } String DirAccessWindows::get_filesystem_type() const { - String path = fix_path(const_cast(this)->get_current_dir()); + String path = fix_path(get_current_dir()); int unit_end = path.find(":"); ERR_FAIL_COND_V(unit_end == -1, String()); diff --git a/editor/editor_help_search.cpp b/editor/editor_help_search.cpp index ff5bc6ba8778..ccaad3029586 100644 --- a/editor/editor_help_search.cpp +++ b/editor/editor_help_search.cpp @@ -505,7 +505,7 @@ bool EditorHelpSearch::Runner::_phase_match_classes() { signal.name = _all_terms_in_name(class_doc->signals[i].name); signal.keyword = _match_keywords_in_all_terms(class_doc->signals[i].keywords); if (signal.name || !signal.keyword.is_empty()) { - signal.doc = const_cast(&class_doc->signals[i]); + signal.doc = &class_doc->signals[i]; match.signals.push_back(signal); } } @@ -516,7 +516,7 @@ bool EditorHelpSearch::Runner::_phase_match_classes() { constant.name = _all_terms_in_name(class_doc->constants[i].name); constant.keyword = _match_keywords_in_all_terms(class_doc->constants[i].keywords); if (constant.name || !constant.keyword.is_empty()) { - constant.doc = const_cast(&class_doc->constants[i]); + constant.doc = &class_doc->constants[i]; match.constants.push_back(constant); } } @@ -527,7 +527,7 @@ bool EditorHelpSearch::Runner::_phase_match_classes() { property.name = _all_terms_in_name(class_doc->properties[i].name); property.keyword = _match_keywords_in_all_terms(class_doc->properties[i].keywords); if (property.name || !property.keyword.is_empty()) { - property.doc = const_cast(&class_doc->properties[i]); + property.doc = &class_doc->properties[i]; match.properties.push_back(property); } } @@ -538,7 +538,7 @@ bool EditorHelpSearch::Runner::_phase_match_classes() { theme_property.name = _all_terms_in_name(class_doc->theme_properties[i].name); theme_property.keyword = _match_keywords_in_all_terms(class_doc->theme_properties[i].keywords); if (theme_property.name || !theme_property.keyword.is_empty()) { - theme_property.doc = const_cast(&class_doc->theme_properties[i]); + theme_property.doc = &class_doc->theme_properties[i]; match.theme_properties.push_back(theme_property); } } @@ -549,7 +549,7 @@ bool EditorHelpSearch::Runner::_phase_match_classes() { annotation.name = _all_terms_in_name(class_doc->annotations[i].name); annotation.keyword = _match_keywords_in_all_terms(class_doc->annotations[i].keywords); if (annotation.name || !annotation.keyword.is_empty()) { - annotation.doc = const_cast(&class_doc->annotations[i]); + annotation.doc = &class_doc->annotations[i]; match.annotations.push_back(annotation); } } @@ -716,7 +716,7 @@ void EditorHelpSearch::Runner::_match_method_name_and_push_back(Vector(&p_methods[i]); + method.doc = &p_methods[i]; r_match_methods->push_back(method); } } diff --git a/editor/editor_help_search.h b/editor/editor_help_search.h index 58061dae4c2d..2885480af02e 100644 --- a/editor/editor_help_search.h +++ b/editor/editor_help_search.h @@ -119,7 +119,7 @@ class EditorHelpSearch::Runner : public RefCounted { template struct MemberMatch { - T *doc = nullptr; + const T *doc = nullptr; bool name = false; String keyword; }; diff --git a/editor/editor_resource_preview.cpp b/editor/editor_resource_preview.cpp index 71865f7e8cc0..b1f5584c2606 100644 --- a/editor/editor_resource_preview.cpp +++ b/editor/editor_resource_preview.cpp @@ -96,12 +96,12 @@ void EditorResourcePreviewGenerator::_bind_methods() { EditorResourcePreviewGenerator::EditorResourcePreviewGenerator() { } -void EditorResourcePreviewGenerator::DrawRequester::request_and_wait(RID p_viewport) const { +void EditorResourcePreviewGenerator::DrawRequester::request_and_wait(RID p_viewport) { Callable request_vp_update_once = callable_mp(RS::get_singleton(), &RS::viewport_set_update_mode).bind(p_viewport, RS::VIEWPORT_UPDATE_ONCE); if (EditorResourcePreview::get_singleton()->is_threaded()) { RS::get_singleton()->connect(SNAME("frame_pre_draw"), request_vp_update_once, Object::CONNECT_ONE_SHOT); - RS::get_singleton()->request_frame_drawn_callback(callable_mp(const_cast(this), &EditorResourcePreviewGenerator::DrawRequester::_post_semaphore)); + RS::get_singleton()->request_frame_drawn_callback(callable_mp(this, &EditorResourcePreviewGenerator::DrawRequester::_post_semaphore)); semaphore.wait(); } else { @@ -119,13 +119,13 @@ void EditorResourcePreviewGenerator::DrawRequester::request_and_wait(RID p_viewp } } -void EditorResourcePreviewGenerator::DrawRequester::abort() const { +void EditorResourcePreviewGenerator::DrawRequester::abort() { if (EditorResourcePreview::get_singleton()->is_threaded()) { semaphore.post(); } } -Variant EditorResourcePreviewGenerator::DrawRequester::_post_semaphore() const { +Variant EditorResourcePreviewGenerator::DrawRequester::_post_semaphore() { semaphore.post(); return Variant(); // Needed because of how the callback is used. } diff --git a/editor/editor_resource_preview.h b/editor/editor_resource_preview.h index 2870f9a2019b..33a20343f8df 100644 --- a/editor/editor_resource_preview.h +++ b/editor/editor_resource_preview.h @@ -54,11 +54,11 @@ class EditorResourcePreviewGenerator : public RefCounted { class DrawRequester : public Object { Semaphore semaphore; - Variant _post_semaphore() const; + Variant _post_semaphore(); public: - void request_and_wait(RID p_viewport) const; - void abort() const; + void request_and_wait(RID p_viewport); + void abort(); }; public: diff --git a/editor/plugins/dedicated_server_export_plugin.cpp b/editor/plugins/dedicated_server_export_plugin.cpp index 013706034eb1..2c740db90a85 100644 --- a/editor/plugins/dedicated_server_export_plugin.cpp +++ b/editor/plugins/dedicated_server_export_plugin.cpp @@ -121,7 +121,7 @@ Ref DedicatedServerExportPlugin::_customize_resource(const Refhas_method("create_placeholder")) { Callable::CallError err; - Ref result = const_cast(p_resource.ptr())->callp("create_placeholder", nullptr, 0, err); + Ref result = p_resource->callp("create_placeholder", nullptr, 0, err); if (err.error == Callable::CallError::CALL_OK) { return result; } diff --git a/editor/plugins/editor_preview_plugins.h b/editor/plugins/editor_preview_plugins.h index 2b3da76a9d0b..98c08fc83ffe 100644 --- a/editor/plugins/editor_preview_plugins.h +++ b/editor/plugins/editor_preview_plugins.h @@ -96,7 +96,7 @@ class EditorMaterialPreviewPlugin : public EditorResourcePreviewGenerator { RID light_instance2; RID camera; RID camera_attributes; - DrawRequester draw_requester; + mutable DrawRequester draw_requester; public: virtual bool handles(const String &p_type) const override; @@ -144,7 +144,7 @@ class EditorMeshPreviewPlugin : public EditorResourcePreviewGenerator { RID light_instance2; RID camera; RID camera_attributes; - DrawRequester draw_requester; + mutable DrawRequester draw_requester; public: virtual bool handles(const String &p_type) const override; @@ -162,7 +162,7 @@ class EditorFontPreviewPlugin : public EditorResourcePreviewGenerator { RID viewport_texture; RID canvas; RID canvas_item; - DrawRequester draw_requester; + mutable DrawRequester draw_requester; public: virtual bool handles(const String &p_type) const override; diff --git a/editor/plugins/tiles/tiles_editor_plugin.cpp b/editor/plugins/tiles/tiles_editor_plugin.cpp index 3213c290fd1f..c65c72687d66 100644 --- a/editor/plugins/tiles/tiles_editor_plugin.cpp +++ b/editor/plugins/tiles/tiles_editor_plugin.cpp @@ -57,7 +57,7 @@ TileMapEditorPlugin *tile_map_plugin_singleton = nullptr; TileSetEditorPlugin *tile_set_plugin_singleton = nullptr; void TilesEditorUtils::_preview_frame_started() { - RS::get_singleton()->request_frame_drawn_callback(callable_mp(const_cast(this), &TilesEditorUtils::_pattern_preview_done)); + RS::get_singleton()->request_frame_drawn_callback(callable_mp(this, &TilesEditorUtils::_pattern_preview_done)); } void TilesEditorUtils::_pattern_preview_done() { @@ -130,7 +130,7 @@ void TilesEditorUtils::_thread() { // Add the viewport at the last moment to avoid rendering too early. callable_mp((Node *)EditorNode::get_singleton(), &Node::add_child).call_deferred(viewport, false, Node::INTERNAL_MODE_DISABLED); - RS::get_singleton()->connect(SNAME("frame_pre_draw"), callable_mp(const_cast(this), &TilesEditorUtils::_preview_frame_started), Object::CONNECT_ONE_SHOT); + RS::get_singleton()->connect(SNAME("frame_pre_draw"), callable_mp(this, &TilesEditorUtils::_preview_frame_started), Object::CONNECT_ONE_SHOT); pattern_preview_done.wait(); diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp index 3215f85293a8..3c8b1130fa1d 100644 --- a/editor/plugins/visual_shader_editor_plugin.cpp +++ b/editor/plugins/visual_shader_editor_plugin.cpp @@ -2155,7 +2155,7 @@ void VisualShaderEditor::_update_options_menu() { if ((add_options[i].func != current_func && add_options[i].func != -1) || !_is_available(add_options[i].mode)) { continue; } - const_cast(add_options[i]).temp_idx = i; // save valid id + add_options[i].temp_idx = i; // save valid id if (add_options[i].is_custom) { custom_options.push_back(add_options[i]); } else { diff --git a/editor/plugins/visual_shader_editor_plugin.h b/editor/plugins/visual_shader_editor_plugin.h index a9826fd61780..b57ef34da19d 100644 --- a/editor/plugins/visual_shader_editor_plugin.h +++ b/editor/plugins/visual_shader_editor_plugin.h @@ -364,7 +364,7 @@ class VisualShaderEditor : public VBoxContainer { bool highend = false; bool is_custom = false; bool is_native = false; - int temp_idx = 0; + mutable int temp_idx = 0; AddOption(const String &p_name = String(), const String &p_category = String(), const String &p_type = String(), const String &p_description = String(), const Vector &p_ops = Vector(), int p_return_type = -1, int p_mode = -1, int p_func = -1, bool p_highend = false) { name = p_name; diff --git a/modules/enet/enet_connection.cpp b/modules/enet/enet_connection.cpp index 2ccfd5d3263b..b021055886de 100644 --- a/modules/enet/enet_connection.cpp +++ b/modules/enet/enet_connection.cpp @@ -277,7 +277,7 @@ Error ENetConnection::dtls_server_setup(const Ref &p_options) { #ifdef GODOT_ENET ERR_FAIL_NULL_V_MSG(host, ERR_UNCONFIGURED, "The ENetConnection instance isn't currently active."); ERR_FAIL_COND_V(p_options.is_null() || !p_options->is_server(), ERR_INVALID_PARAMETER); - return enet_host_dtls_server_setup(host, const_cast(p_options.ptr())) ? FAILED : OK; + return enet_host_dtls_server_setup(host, p_options.ptr()) ? FAILED : OK; #else ERR_FAIL_V_MSG(ERR_UNAVAILABLE, "ENet DTLS support not available in this build."); #endif @@ -296,7 +296,7 @@ Error ENetConnection::dtls_client_setup(const String &p_hostname, const Refis_server(), ERR_INVALID_PARAMETER); - return enet_host_dtls_client_setup(host, p_hostname.utf8().get_data(), const_cast(p_options.ptr())) ? FAILED : OK; + return enet_host_dtls_client_setup(host, p_hostname.utf8().get_data(), p_options.ptr()) ? FAILED : OK; #else ERR_FAIL_V_MSG(ERR_UNAVAILABLE, "ENet DTLS support not available in this build."); #endif diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp index eaf2565e6920..d6ee757997f1 100644 --- a/modules/gdscript/gdscript.cpp +++ b/modules/gdscript/gdscript.cpp @@ -1793,7 +1793,7 @@ bool GDScriptInstance::get(const StringName &p_name, Variant &r_ret) const { const Variant *args[1] = { &name }; Callable::CallError err; - Variant ret = const_cast(E->value)->call(const_cast(this), (const Variant **)args, 1, err); + Variant ret = E->value->call(const_cast(this), (const Variant **)args, 1, err); if (err.error == Callable::CallError::CALL_OK && ret.get_type() != Variant::NIL) { r_ret = ret; return true; @@ -1852,7 +1852,7 @@ void GDScriptInstance::get_property_list(List *p_properties) const HashMap::ConstIterator E = sptr->member_functions.find(GDScriptLanguage::get_singleton()->strings._get_property_list); if (E) { Callable::CallError err; - Variant ret = const_cast(E->value)->call(const_cast(this), nullptr, 0, err); + Variant ret = E->value->call(const_cast(this), nullptr, 0, err); if (err.error == Callable::CallError::CALL_OK) { ERR_FAIL_COND_MSG(ret.get_type() != Variant::ARRAY, "Wrong type for _get_property_list, must be an array of dictionaries."); diff --git a/modules/gdscript/gdscript_compiler.cpp b/modules/gdscript/gdscript_compiler.cpp index d8b44a558f67..a4c4869bc290 100644 --- a/modules/gdscript/gdscript_compiler.cpp +++ b/modules/gdscript/gdscript_compiler.cpp @@ -3048,9 +3048,9 @@ void GDScriptCompiler::convert_to_initializer_type(Variant &p_variant, const GDS if (member_t.is_hard_type() && init_t.is_hard_type() && member_t.kind == GDScriptParser::DataType::BUILTIN && init_t.kind == GDScriptParser::DataType::BUILTIN) { if (Variant::can_convert_strict(init_t.builtin_type, member_t.builtin_type)) { - Variant *v = &p_node->initializer->reduced_value; + const Variant *v = &p_node->initializer->reduced_value; Callable::CallError ce; - Variant::construct(member_t.builtin_type, p_variant, const_cast(&v), 1, ce); + Variant::construct(member_t.builtin_type, p_variant, &v, 1, ce); } } } diff --git a/modules/gdscript/gdscript_editor.cpp b/modules/gdscript/gdscript_editor.cpp index 822fc412b448..f42cde784539 100644 --- a/modules/gdscript/gdscript_editor.cpp +++ b/modules/gdscript/gdscript_editor.cpp @@ -2589,7 +2589,7 @@ static bool _guess_method_return_type_from_base(GDScriptParser::CompletionContex switch (base_type.kind) { case GDScriptParser::DataType::CLASS: if (base_type.class_type->has_function(p_method)) { - const GDScriptParser::FunctionNode *method = base_type.class_type->get_member(p_method).function; + GDScriptParser::FunctionNode *method = base_type.class_type->get_member(p_method).function; if (!is_static || method->is_static) { if (method->get_datatype().is_set() && !method->get_datatype().is_variant()) { r_type.type = method->get_datatype(); @@ -2600,7 +2600,7 @@ static bool _guess_method_return_type_from_base(GDScriptParser::CompletionContex const GDScriptParser::ExpressionNode *last_returned_value = nullptr; GDScriptParser::CompletionContext c = p_context; c.current_class = base_type.class_type; - c.current_function = const_cast(method); + c.current_function = method; c.current_suite = method->body; _find_last_return_in_block(c, last_return_line, &last_returned_value); diff --git a/modules/text_server_adv/text_server_adv.cpp b/modules/text_server_adv/text_server_adv.cpp index 499ddb703b0f..77dc7f2f5359 100644 --- a/modules/text_server_adv/text_server_adv.cpp +++ b/modules/text_server_adv/text_server_adv.cpp @@ -4713,10 +4713,10 @@ double TextServerAdvanced::_shaped_text_fit_to_width(const RID &p_shaped, double MutexLock lock(sd->mutex); if (!sd->valid) { - const_cast(this)->_shaped_text_shape(p_shaped); + _shaped_text_shape(p_shaped); } if (!sd->justification_ops_valid) { - const_cast(this)->_shaped_text_update_justification_ops(p_shaped); + _shaped_text_update_justification_ops(p_shaped); } sd->fit_width_minimum_reached = false; @@ -4870,10 +4870,10 @@ double TextServerAdvanced::_shaped_text_tab_align(const RID &p_shaped, const Pac MutexLock lock(sd->mutex); if (!sd->valid) { - const_cast(this)->_shaped_text_shape(p_shaped); + _shaped_text_shape(p_shaped); } if (!sd->line_breaks_valid) { - const_cast(this)->_shaped_text_update_breaks(p_shaped); + _shaped_text_update_breaks(p_shaped); } for (int i = 0; i < p_tab_stops.size(); i++) { @@ -6456,7 +6456,7 @@ const Glyph *TextServerAdvanced::_shaped_text_sort_logical(const RID &p_shaped) MutexLock lock(sd->mutex); if (!sd->valid) { - const_cast(this)->_shaped_text_shape(p_shaped); + _shaped_text_shape(p_shaped); } if (!sd->sort_valid) { diff --git a/modules/text_server_fb/text_server_fb.cpp b/modules/text_server_fb/text_server_fb.cpp index b45c004011a1..b72aee99f8ae 100644 --- a/modules/text_server_fb/text_server_fb.cpp +++ b/modules/text_server_fb/text_server_fb.cpp @@ -3502,10 +3502,10 @@ double TextServerFallback::_shaped_text_fit_to_width(const RID &p_shaped, double MutexLock lock(sd->mutex); if (!sd->valid) { - const_cast(this)->_shaped_text_shape(p_shaped); + _shaped_text_shape(p_shaped); } if (!sd->justification_ops_valid) { - const_cast(this)->_shaped_text_update_justification_ops(p_shaped); + _shaped_text_update_justification_ops(p_shaped); } int start_pos = 0; @@ -3611,10 +3611,10 @@ double TextServerFallback::_shaped_text_tab_align(const RID &p_shaped, const Pac MutexLock lock(sd->mutex); if (!sd->valid) { - const_cast(this)->_shaped_text_shape(p_shaped); + _shaped_text_shape(p_shaped); } if (!sd->line_breaks_valid) { - const_cast(this)->_shaped_text_update_breaks(p_shaped); + _shaped_text_update_breaks(p_shaped); } for (int i = 0; i < p_tab_stops.size(); i++) { @@ -4316,7 +4316,7 @@ const Glyph *TextServerFallback::_shaped_text_sort_logical(const RID &p_shaped) MutexLock lock(sd->mutex); if (!sd->valid) { - const_cast(this)->_shaped_text_shape(p_shaped); + _shaped_text_shape(p_shaped); } return sd->glyphs.ptr(); // Already in the logical order, return as is. diff --git a/platform/android/os_android.cpp b/platform/android/os_android.cpp index 764959eef358..2b7cb6057716 100644 --- a/platform/android/os_android.cpp +++ b/platform/android/os_android.cpp @@ -416,7 +416,7 @@ String OS_Android::get_data_path() const { return get_user_data_dir(); } -void OS_Android::_load_system_font_config() { +void OS_Android::_load_system_font_config() const { font_aliases.clear(); fonts.clear(); font_names.clear(); @@ -541,7 +541,7 @@ void OS_Android::_load_system_font_config() { Vector OS_Android::get_system_fonts() const { if (!font_config_loaded) { - const_cast(this)->_load_system_font_config(); + _load_system_font_config(); } Vector ret; for (const String &E : font_names) { @@ -552,7 +552,7 @@ Vector OS_Android::get_system_fonts() const { Vector OS_Android::get_system_font_path_for_text(const String &p_font_name, const String &p_text, const String &p_locale, const String &p_script, int p_weight, int p_stretch, bool p_italic) const { if (!font_config_loaded) { - const_cast(this)->_load_system_font_config(); + _load_system_font_config(); } String font_name = p_font_name.to_lower(); if (font_aliases.has(font_name)) { @@ -604,7 +604,7 @@ Vector OS_Android::get_system_font_path_for_text(const String &p_font_na String OS_Android::get_system_font_path(const String &p_font_name, int p_weight, int p_stretch, bool p_italic) const { if (!font_config_loaded) { - const_cast(this)->_load_system_font_config(); + _load_system_font_config(); } String font_name = p_font_name.to_lower(); if (font_aliases.has(font_name)) { diff --git a/platform/android/os_android.h b/platform/android/os_android.h index b150ef4f6161..55001b74a51d 100644 --- a/platform/android/os_android.h +++ b/platform/android/os_android.h @@ -75,15 +75,15 @@ class OS_Android : public OS_Unix { String filename; }; - HashMap font_aliases; - List fonts; - HashSet font_names; - bool font_config_loaded = false; + mutable HashMap font_aliases; + mutable List fonts; + mutable HashSet font_names; + mutable bool font_config_loaded = false; GodotJavaWrapper *godot_java = nullptr; GodotIOJavaWrapper *godot_io_java = nullptr; - void _load_system_font_config(); + void _load_system_font_config() const; String get_system_property(const char *key) const; public: diff --git a/platform/linuxbsd/tts_linux.cpp b/platform/linuxbsd/tts_linux.cpp index 6c1f49f0466d..95cae58fb3f0 100644 --- a/platform/linuxbsd/tts_linux.cpp +++ b/platform/linuxbsd/tts_linux.cpp @@ -101,7 +101,7 @@ void TTS_Linux::speech_event_callback(size_t p_msg_id, size_t p_client_id, SPDNo } } -void TTS_Linux::_load_voices() { +void TTS_Linux::_load_voices() const { if (!voices_loaded) { SPDVoice **spd_voices = spd_list_synthesis_voices(synth); if (spd_voices != nullptr) { @@ -193,7 +193,7 @@ Array TTS_Linux::get_voices() const { _THREAD_SAFE_METHOD_ ERR_FAIL_NULL_V(synth, Array()); - const_cast(this)->_load_voices(); + _load_voices(); Array list; for (const KeyValue &E : voices) { diff --git a/platform/linuxbsd/tts_linux.h b/platform/linuxbsd/tts_linux.h index 2a3d33221d7e..00ea88d19a4c 100644 --- a/platform/linuxbsd/tts_linux.h +++ b/platform/linuxbsd/tts_linux.h @@ -59,8 +59,8 @@ class TTS_Linux : public Object { String language; String variant; }; - bool voices_loaded = false; - HashMap voices; + mutable bool voices_loaded = false; + mutable HashMap voices; Thread init_thread; @@ -71,7 +71,7 @@ class TTS_Linux : public Object { static TTS_Linux *singleton; protected: - void _load_voices(); + void _load_voices() const; void _speech_event(int p_msg_id, int p_type); void _speech_index_mark(int p_msg_id, int p_type, const String &p_index_mark); diff --git a/platform/macos/display_server_macos.h b/platform/macos/display_server_macos.h index bd3c6af273b3..d5b5c702f37e 100644 --- a/platform/macos/display_server_macos.h +++ b/platform/macos/display_server_macos.h @@ -172,16 +172,16 @@ class DisplayServerMacOS : public DisplayServer { String name; String code; }; - Vector kbd_layouts; - int current_layout = 0; - bool keyboard_layout_dirty = true; + mutable Vector kbd_layouts; + mutable int current_layout = 0; + mutable bool keyboard_layout_dirty = true; WindowID window_mouseover_id = INVALID_WINDOW_ID; WindowID last_focused_window = INVALID_WINDOW_ID; WindowID window_id_counter = MAIN_WINDOW_ID; float display_max_scale = 1.f; - Point2i origin; - bool displays_arrangement_dirty = true; + mutable Point2i origin; + mutable bool displays_arrangement_dirty = true; bool is_resizing = false; CursorShape cursor_shape = CURSOR_ARROW; @@ -214,7 +214,7 @@ class DisplayServerMacOS : public DisplayServer { WindowID _create_window(WindowMode p_mode, VSyncMode p_vsync_mode, const Rect2i &p_rect); void _update_window_style(WindowData p_wd); - void _update_displays_arrangement(); + void _update_displays_arrangement() const; Point2i _get_native_screen_position(int p_screen) const; static void _displays_arrangement_changed(CGDirectDisplayID display_id, CGDisplayChangeSummaryFlags flags, void *user_info); @@ -222,7 +222,7 @@ class DisplayServerMacOS : public DisplayServer { void _dispatch_input_event(const Ref &p_event); void _push_input(const Ref &p_event); void _process_key_events(); - void _update_keyboard_layouts(); + void _update_keyboard_layouts() const; static void _keyboard_layout_changed(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef user_info); static NSCursor *_cursor_from_selector(SEL p_selector, SEL p_fallback = nil); diff --git a/platform/macos/display_server_macos.mm b/platform/macos/display_server_macos.mm index cd2d8a60ace3..83e7ebb685fd 100644 --- a/platform/macos/display_server_macos.mm +++ b/platform/macos/display_server_macos.mm @@ -275,7 +275,7 @@ } } -void DisplayServerMacOS::_update_displays_arrangement() { +void DisplayServerMacOS::_update_displays_arrangement() const { origin = Point2i(); for (int i = 0; i < get_screen_count(); i++) { @@ -301,7 +301,7 @@ // to convert between macOS native screen coordinates and the ones expected by Godot. if (displays_arrangement_dirty) { - const_cast(this)->_update_displays_arrangement(); + _update_displays_arrangement(); } return origin; @@ -2904,14 +2904,14 @@ int DisplayServerMacOS::keyboard_get_layout_count() const { if (keyboard_layout_dirty) { - const_cast(this)->_update_keyboard_layouts(); + _update_keyboard_layouts(); } return kbd_layouts.size(); } void DisplayServerMacOS::keyboard_set_current_layout(int p_index) { if (keyboard_layout_dirty) { - const_cast(this)->_update_keyboard_layouts(); + _update_keyboard_layouts(); } ERR_FAIL_INDEX(p_index, kbd_layouts.size()); @@ -2941,7 +2941,7 @@ int DisplayServerMacOS::keyboard_get_current_layout() const { if (keyboard_layout_dirty) { - const_cast(this)->_update_keyboard_layouts(); + _update_keyboard_layouts(); } return current_layout; @@ -2949,7 +2949,7 @@ String DisplayServerMacOS::keyboard_get_layout_language(int p_index) const { if (keyboard_layout_dirty) { - const_cast(this)->_update_keyboard_layouts(); + _update_keyboard_layouts(); } ERR_FAIL_INDEX_V(p_index, kbd_layouts.size(), ""); @@ -2958,7 +2958,7 @@ String DisplayServerMacOS::keyboard_get_layout_name(int p_index) const { if (keyboard_layout_dirty) { - const_cast(this)->_update_keyboard_layouts(); + _update_keyboard_layouts(); } ERR_FAIL_INDEX_V(p_index, kbd_layouts.size(), ""); diff --git a/scene/2d/physics/physics_body_2d.cpp b/scene/2d/physics/physics_body_2d.cpp index fc14e6ed6276..df6ec65d9c5d 100644 --- a/scene/2d/physics/physics_body_2d.cpp +++ b/scene/2d/physics/physics_body_2d.cpp @@ -126,8 +126,7 @@ bool PhysicsBody2D::test_move(const Transform2D &p_from, const Vector2 &p_motion PhysicsServer2D::MotionResult *r = nullptr; PhysicsServer2D::MotionResult temp_result; if (r_collision.is_valid()) { - // Needs const_cast because method bindings don't support non-const Ref. - r = const_cast(&r_collision->result); + r = &r_collision->result; } else { r = &temp_result; } diff --git a/scene/2d/skeleton_2d.cpp b/scene/2d/skeleton_2d.cpp index 8aa50668ebb8..4fdf80eaaea5 100644 --- a/scene/2d/skeleton_2d.cpp +++ b/scene/2d/skeleton_2d.cpp @@ -623,6 +623,7 @@ int Skeleton2D::get_bone_count() const { ERR_FAIL_COND_V(!is_inside_tree(), 0); if (bone_setup_dirty) { + // TODO: Is this necessary? It doesn't seem to change bones.size() const_cast(this)->_update_bone_setup(); } diff --git a/scene/3d/physics/physics_body_3d.cpp b/scene/3d/physics/physics_body_3d.cpp index b723b452c16a..fa27312dd5c3 100644 --- a/scene/3d/physics/physics_body_3d.cpp +++ b/scene/3d/physics/physics_body_3d.cpp @@ -167,8 +167,7 @@ bool PhysicsBody3D::test_move(const Transform3D &p_from, const Vector3 &p_motion PhysicsServer3D::MotionResult *r = nullptr; PhysicsServer3D::MotionResult temp_result; if (r_collision.is_valid()) { - // Needs const_cast because method bindings don't support non-const Ref. - r = const_cast(&r_collision->result); + r = &r_collision->result; } else { r = &temp_result; } diff --git a/scene/3d/skeleton_3d.cpp b/scene/3d/skeleton_3d.cpp index 3d24b3bbe9cf..9fc5b22fa684 100644 --- a/scene/3d/skeleton_3d.cpp +++ b/scene/3d/skeleton_3d.cpp @@ -227,7 +227,7 @@ void Skeleton3D::_validate_property(PropertyInfo &p_property) const { } } -void Skeleton3D::_update_process_order() { +void Skeleton3D::_update_process_order() const { if (!process_order_dirty) { return; } @@ -269,7 +269,7 @@ void Skeleton3D::_update_process_order() { process_order_dirty = false; - emit_signal("bone_list_changed"); + const_cast(this)->emit_signal("bone_list_changed"); } void Skeleton3D::_update_bone_names() const { @@ -451,7 +451,7 @@ void Skeleton3D::_make_modifiers_dirty() { Transform3D Skeleton3D::get_bone_global_pose(int p_bone) const { const int bone_size = bones.size(); ERR_FAIL_INDEX_V(p_bone, bone_size, Transform3D()); - const_cast(this)->force_update_all_dirty_bones(); + _force_update_all_dirty_bones(); return bones[p_bone].global_pose; } @@ -584,7 +584,7 @@ int Skeleton3D::get_bone_parent(int p_bone) const { const int bone_size = bones.size(); ERR_FAIL_INDEX_V(p_bone, bone_size, -1); if (process_order_dirty) { - const_cast(this)->_update_process_order(); + _update_process_order(); } return bones[p_bone].parent; } @@ -593,14 +593,14 @@ Vector Skeleton3D::get_bone_children(int p_bone) const { const int bone_size = bones.size(); ERR_FAIL_INDEX_V(p_bone, bone_size, Vector()); if (process_order_dirty) { - const_cast(this)->_update_process_order(); + _update_process_order(); } return bones[p_bone].child_bones; } Vector Skeleton3D::get_parentless_bones() const { if (process_order_dirty) { - const_cast(this)->_update_process_order(); + _update_process_order(); } return parentless_bones; } @@ -623,7 +623,7 @@ Transform3D Skeleton3D::get_bone_global_rest(int p_bone) const { const int bone_size = bones.size(); ERR_FAIL_INDEX_V(p_bone, bone_size, Transform3D()); if (rest_dirty) { - const_cast(this)->force_update_all_bone_transforms(); + _force_update_all_bone_transforms(); } return bones[p_bone].global_rest; } @@ -742,7 +742,7 @@ void Skeleton3D::reset_bone_poses() { Transform3D Skeleton3D::get_bone_pose(int p_bone) const { const int bone_size = bones.size(); ERR_FAIL_INDEX_V(p_bone, bone_size, Transform3D()); - const_cast(this)->bones.write[p_bone].update_pose_cache(); + bones.write[p_bone].update_pose_cache(); return bones[p_bone].pose_cache; } @@ -854,26 +854,38 @@ Ref Skeleton3D::register_skin(const Ref &p_skin) { } void Skeleton3D::force_update_all_dirty_bones() { + _force_update_all_dirty_bones(); +} + +void Skeleton3D::_force_update_all_dirty_bones() const { if (!dirty) { return; } - force_update_all_bone_transforms(); + return _force_update_all_bone_transforms(); } void Skeleton3D::force_update_all_bone_transforms() { + _force_update_all_bone_transforms(); +} + +void Skeleton3D::_force_update_all_bone_transforms() const { _update_process_order(); for (int i = 0; i < parentless_bones.size(); i++) { - force_update_bone_children_transforms(parentless_bones[i]); + _force_update_bone_child_transform(parentless_bones[i]); } rest_dirty = false; dirty = false; if (updating) { return; } - emit_signal(SceneStringName(pose_updated)); + const_cast(this)->emit_signal(SceneStringName(pose_updated)); +} + +void Skeleton3D::force_update_bone_child_transform(int p_bone_idx) { + _force_update_bone_child_transform(p_bone_idx); } -void Skeleton3D::force_update_bone_children_transforms(int p_bone_idx) { +void Skeleton3D::_force_update_bone_child_transform(int p_bone_idx) const { const int bone_size = bones.size(); ERR_FAIL_INDEX(p_bone_idx, bone_size); @@ -1059,7 +1071,7 @@ void Skeleton3D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_bone_global_pose", "bone_idx", "pose"), &Skeleton3D::set_bone_global_pose); ClassDB::bind_method(D_METHOD("force_update_all_bone_transforms"), &Skeleton3D::force_update_all_bone_transforms); - ClassDB::bind_method(D_METHOD("force_update_bone_child_transform", "bone_idx"), &Skeleton3D::force_update_bone_children_transforms); + ClassDB::bind_method(D_METHOD("force_update_bone_child_transform", "bone_idx"), &Skeleton3D::force_update_bone_child_transform); ClassDB::bind_method(D_METHOD("set_motion_scale", "motion_scale"), &Skeleton3D::set_motion_scale); ClassDB::bind_method(D_METHOD("get_motion_scale"), &Skeleton3D::get_motion_scale); @@ -1131,7 +1143,7 @@ Transform3D Skeleton3D::get_bone_global_pose_override(int p_bone) const { Transform3D Skeleton3D::get_bone_global_pose_no_override(int p_bone) const { const int bone_size = bones.size(); ERR_FAIL_INDEX_V(p_bone, bone_size, Transform3D()); - const_cast(this)->force_update_all_dirty_bones(); + _force_update_all_dirty_bones(); return bones[p_bone].pose_global_no_override; } diff --git a/scene/3d/skeleton_3d.h b/scene/3d/skeleton_3d.h index a009383f45ca..f3bc249dc7ee 100644 --- a/scene/3d/skeleton_3d.h +++ b/scene/3d/skeleton_3d.h @@ -151,25 +151,25 @@ class Skeleton3D : public Node3D { HashSet skin_bindings; void _skin_changed(); - Vector bones; - bool process_order_dirty = false; + mutable Vector bones; + mutable bool process_order_dirty = false; - Vector parentless_bones; + mutable Vector parentless_bones; HashMap name_to_bone_index; mutable StringName concatenated_bone_names = StringName(); void _update_bone_names() const; void _make_dirty(); - bool dirty = false; - bool rest_dirty = false; + mutable bool dirty = false; + mutable bool rest_dirty = false; bool show_rest_only = false; float motion_scale = 1.0; uint64_t version = 1; - void _update_process_order(); + void _update_process_order() const; // To process modifiers. ModifierCallbackModeProcess modifier_callback_mode_process = MODIFIER_CALLBACK_MODE_PROCESS_IDLE; @@ -179,7 +179,7 @@ class Skeleton3D : public Node3D { void _process_modifiers(); void _process_changed(); void _make_modifiers_dirty(); - LocalVector bones_backup; + mutable LocalVector bones_backup; #ifndef DISABLE_DEPRECATED void _add_bone_bind_compat_88791(const String &p_name); @@ -261,8 +261,11 @@ class Skeleton3D : public Node3D { Ref register_skin(const Ref &p_skin); void force_update_all_dirty_bones(); + void _force_update_all_dirty_bones() const; void force_update_all_bone_transforms(); - void force_update_bone_children_transforms(int bone_idx); + void _force_update_all_bone_transforms() const; + void force_update_bone_child_transform(int bone_idx); + void _force_update_bone_child_transform(int bone_idx) const; void set_modifier_callback_mode_process(ModifierCallbackModeProcess p_mode); ModifierCallbackModeProcess get_modifier_callback_mode_process() const; diff --git a/scene/animation/animation_tree.cpp b/scene/animation/animation_tree.cpp index 69287478dbe8..b9eacff48cd0 100644 --- a/scene/animation/animation_tree.cpp +++ b/scene/animation/animation_tree.cpp @@ -728,7 +728,7 @@ void AnimationTree::_animation_node_removed(const ObjectID &p_oid, const StringN _update_properties(); } -void AnimationTree::_update_properties_for_node(const String &p_base_path, Ref p_node) { +void AnimationTree::_update_properties_for_node(const String &p_base_path, Ref p_node) const { ERR_FAIL_COND(p_node.is_null()); if (!property_parent_map.has(p_base_path)) { property_parent_map[p_base_path] = HashMap(); @@ -775,7 +775,7 @@ void AnimationTree::_update_properties_for_node(const String &p_base_path, Ref(this)->notify_property_list_changed(); } void AnimationTree::_notification(int p_what) { @@ -908,7 +908,7 @@ bool AnimationTree::_get(const StringName &p_name, Variant &r_ret) const { } #endif // DISABLE_DEPRECATED if (properties_dirty) { - const_cast(this)->_update_properties(); + _update_properties(); } if (property_map.has(p_name)) { @@ -921,7 +921,7 @@ bool AnimationTree::_get(const StringName &p_name, Variant &r_ret) const { void AnimationTree::_get_property_list(List *p_list) const { if (properties_dirty) { - const_cast(this)->_update_properties(); + _update_properties(); } for (const PropertyInfo &E : properties) { diff --git a/scene/animation/animation_tree.h b/scene/animation/animation_tree.h index 6698427233ef..2d4112d216ef 100644 --- a/scene/animation/animation_tree.h +++ b/scene/animation/animation_tree.h @@ -249,15 +249,15 @@ class AnimationTree : public AnimationMixer { friend class AnimationNode; - List properties; - HashMap> property_parent_map; - HashMap property_reference_map; - HashMap> property_map; // Property value and read-only flag. + mutable List properties; + mutable HashMap> property_parent_map; + mutable HashMap property_reference_map; + mutable HashMap> property_map; // Property value and read-only flag. - bool properties_dirty = true; + mutable bool properties_dirty = true; - void _update_properties(); - void _update_properties_for_node(const String &p_base_path, Ref p_node); + void _update_properties() const; + void _update_properties_for_node(const String &p_base_path, Ref p_node) const; void _tree_changed(); void _animation_node_renamed(const ObjectID &p_oid, const String &p_old_name, const String &p_new_name); @@ -267,8 +267,8 @@ class AnimationTree : public AnimationMixer { uint64_t last_pass = 0; real_t activity = 0.0; }; - HashMap> input_activity_map; - HashMap *> input_activity_map_get; + mutable HashMap> input_activity_map; + mutable HashMap *> input_activity_map_get; NodePath animation_player; diff --git a/scene/gui/button.cpp b/scene/gui/button.cpp index dd344121e1a9..c3fcaf1906f6 100644 --- a/scene/gui/button.cpp +++ b/scene/gui/button.cpp @@ -494,7 +494,7 @@ Size2 Button::get_minimum_size_for_text_and_icon(const String &p_text, Ref(this)->_shape(paragraph, p_text); + _shape(paragraph, p_text); } Size2 minsize = paragraph->get_size(); @@ -533,7 +533,7 @@ Size2 Button::get_minimum_size_for_text_and_icon(const String &p_text, Refget_minimum_size()) + minsize; } -void Button::_shape(Ref p_paragraph, String p_text) { +void Button::_shape(Ref p_paragraph, String p_text) const { if (p_paragraph.is_null()) { p_paragraph = text_buf; } diff --git a/scene/gui/button.h b/scene/gui/button.h index 5f4429bc1d34..c19a9a9be420 100644 --- a/scene/gui/button.h +++ b/scene/gui/button.h @@ -102,7 +102,7 @@ class Button : public BaseButton { int icon_max_width = 0; } theme_cache; - void _shape(Ref p_paragraph = Ref(), String p_text = ""); + void _shape(Ref p_paragraph = Ref(), String p_text = "") const; void _texture_changed(); protected: diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index d169e82e5dba..1e7900df4f7a 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -1677,7 +1677,7 @@ Size2 Control::get_custom_minimum_size() const { return data.custom_minimum_size; } -void Control::_update_minimum_size_cache() { +void Control::_update_minimum_size_cache() const { Size2 minsize = get_minimum_size(); minsize = minsize.max(data.custom_minimum_size); @@ -1688,7 +1688,7 @@ void Control::_update_minimum_size_cache() { Size2 Control::get_combined_minimum_size() const { ERR_READ_THREAD_GUARD_V(Size2()); if (!data.minimum_size_valid) { - const_cast(this)->_update_minimum_size_cache(); + _update_minimum_size_cache(); } return data.minimum_size_cache; } @@ -3041,11 +3041,11 @@ Control::LayoutDirection Control::get_layout_direction() const { bool Control::is_layout_rtl() const { ERR_READ_THREAD_GUARD_V(false); if (data.is_rtl_dirty) { - const_cast(this)->data.is_rtl_dirty = false; + data.is_rtl_dirty = false; if (data.layout_dir == LAYOUT_DIRECTION_INHERITED) { #ifdef TOOLS_ENABLED if (is_part_of_edited_scene() && GLOBAL_GET(SNAME("internationalization/rendering/force_right_to_left_layout_direction"))) { - const_cast(this)->data.is_rtl = true; + data.is_rtl = true; return data.is_rtl; } if (is_inside_tree()) { @@ -3053,22 +3053,22 @@ bool Control::is_layout_rtl() const { if (edited_scene_root == this) { int proj_root_layout_direction = GLOBAL_GET(SNAME("internationalization/rendering/root_node_layout_direction")); if (proj_root_layout_direction == 1) { - const_cast(this)->data.is_rtl = false; + data.is_rtl = false; } else if (proj_root_layout_direction == 2) { - const_cast(this)->data.is_rtl = true; + data.is_rtl = true; } else if (proj_root_layout_direction == 3) { String locale = OS::get_singleton()->get_locale(); - const_cast(this)->data.is_rtl = TS->is_locale_right_to_left(locale); + data.is_rtl = TS->is_locale_right_to_left(locale); } else { String locale = TranslationServer::get_singleton()->get_tool_locale(); - const_cast(this)->data.is_rtl = TS->is_locale_right_to_left(locale); + data.is_rtl = TS->is_locale_right_to_left(locale); } return data.is_rtl; } } #else if (GLOBAL_GET(SNAME("internationalization/rendering/force_right_to_left_layout_direction"))) { - const_cast(this)->data.is_rtl = true; + data.is_rtl = true; return data.is_rtl; } #endif @@ -3076,38 +3076,38 @@ bool Control::is_layout_rtl() const { while (parent_node) { Control *parent_control = Object::cast_to(parent_node); if (parent_control) { - const_cast(this)->data.is_rtl = parent_control->is_layout_rtl(); + data.is_rtl = parent_control->is_layout_rtl(); return data.is_rtl; } Window *parent_window = Object::cast_to(parent_node); if (parent_window) { - const_cast(this)->data.is_rtl = parent_window->is_layout_rtl(); + data.is_rtl = parent_window->is_layout_rtl(); return data.is_rtl; } parent_node = parent_node->get_parent(); } if (root_layout_direction == 1) { - const_cast(this)->data.is_rtl = false; + data.is_rtl = false; } else if (root_layout_direction == 2) { - const_cast(this)->data.is_rtl = true; + data.is_rtl = true; } else if (root_layout_direction == 3) { String locale = OS::get_singleton()->get_locale(); - const_cast(this)->data.is_rtl = TS->is_locale_right_to_left(locale); + data.is_rtl = TS->is_locale_right_to_left(locale); } else { String locale = TranslationServer::get_singleton()->get_tool_locale(); - const_cast(this)->data.is_rtl = TS->is_locale_right_to_left(locale); + data.is_rtl = TS->is_locale_right_to_left(locale); } } else if (data.layout_dir == LAYOUT_DIRECTION_LOCALE) { if (GLOBAL_GET(SNAME("internationalization/rendering/force_right_to_left_layout_direction"))) { - const_cast(this)->data.is_rtl = true; + data.is_rtl = true; } else { String locale = TranslationServer::get_singleton()->get_tool_locale(); - const_cast(this)->data.is_rtl = TS->is_locale_right_to_left(locale); + data.is_rtl = TS->is_locale_right_to_left(locale); } } else { - const_cast(this)->data.is_rtl = (data.layout_dir == LAYOUT_DIRECTION_RTL); + data.is_rtl = (data.layout_dir == LAYOUT_DIRECTION_RTL); } } return data.is_rtl; diff --git a/scene/gui/control.h b/scene/gui/control.h index c784d4330dac..96d9c58662a3 100644 --- a/scene/gui/control.h +++ b/scene/gui/control.h @@ -196,8 +196,8 @@ class Control : public CanvasItem { Point2 pos_cache; Size2 size_cache; - Size2 minimum_size_cache; - bool minimum_size_valid = false; + mutable Size2 minimum_size_cache; + mutable bool minimum_size_valid = false; Size2 last_minimum_size; bool updating_last_minimum_size = false; @@ -254,8 +254,8 @@ class Control : public CanvasItem { // Internationalization. LayoutDirection layout_dir = LAYOUT_DIRECTION_INHERITED; - bool is_rtl_dirty = true; - bool is_rtl = false; + mutable bool is_rtl_dirty = true; + mutable bool is_rtl = false; bool localize_numeral_system = true; @@ -294,7 +294,7 @@ class Control : public CanvasItem { void _set_anchors_layout_preset(int p_preset); int _get_anchors_layout_preset() const; - void _update_minimum_size_cache(); + void _update_minimum_size_cache() const; void _update_minimum_size(); void _size_changed(); diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp index 42b4e56b484b..74bdc3f22cab 100644 --- a/scene/gui/label.cpp +++ b/scene/gui/label.cpp @@ -101,7 +101,7 @@ int Label::get_line_height(int p_line) const { } } -void Label::_shape() { +void Label::_shape() const { Ref style = theme_cache.normal_style; int width = (get_size().width - style->get_minimum_size().width); @@ -285,11 +285,11 @@ void Label::_shape() { _update_visible(); if (autowrap_mode == TextServer::AUTOWRAP_OFF || !clip || overrun_behavior == TextServer::OVERRUN_NO_TRIMMING) { - update_minimum_size(); + const_cast