diff --git a/core/math/a_star.cpp b/core/math/a_star.cpp index c85201a9739..a70aea5663f 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 cbaafc10183..e510923bd0f 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 22eb5a7a3fe..927e457de2c 100644 --- a/core/object/ref_counted.h +++ b/core/object/ref_counted.h @@ -222,7 +222,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 c819fa6b402..6530b40b1ca 100644 --- a/core/os/condition_variable.h +++ b/core/os/condition_variable.h @@ -57,12 +57,12 @@ class ConditionVariable { public: template _ALWAYS_INLINE_ void wait(const MutexLock &p_lock) const { - condition.wait(const_cast &>(p_lock._get_lock())); + condition.wait(p_lock._get_lock()); } template _ALWAYS_INLINE_ void wait(const MutexLock> &p_lock) const { - condition.wait(const_cast &>(p_lock.mutex._get_lock())); + condition.wait(p_lock.mutex._get_lock()); } _ALWAYS_INLINE_ void notify_one() const { diff --git a/core/variant/method_ptrcall.h b/core/variant/method_ptrcall.h index 1e10709b12b..540dcc4a4d9 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/editor/editor_help_search.cpp b/editor/editor_help_search.cpp index 0fc7052a2b4..9f4bb3ab2f5 100644 --- a/editor/editor_help_search.cpp +++ b/editor/editor_help_search.cpp @@ -957,7 +957,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_resource_preview.cpp b/editor/editor_resource_preview.cpp index 32c44133e0b..47034104ee9 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 88cd753a583..876b42b101d 100644 --- a/editor/editor_resource_preview.h +++ b/editor/editor_resource_preview.h @@ -54,11 +54,11 @@ protected: 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 013706034eb..2c740db90a8 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 2b3da76a9d0..98c08fc83ff 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 3213c290fd1..c65c72687d6 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 3018b609355..5539862752b 100644 --- a/editor/plugins/visual_shader_editor_plugin.cpp +++ b/editor/plugins/visual_shader_editor_plugin.cpp @@ -2329,7 +2329,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 6b7c07e5a74..4e20a0a980a 100644 --- a/editor/plugins/visual_shader_editor_plugin.h +++ b/editor/plugins/visual_shader_editor_plugin.h @@ -398,7 +398,7 @@ class VisualShaderEditor : public ShaderEditor { 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 9c9302a51cb..f66f5867368 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 8c094c0ab05..7c497f7fccd 100644 --- a/modules/gdscript/gdscript.cpp +++ b/modules/gdscript/gdscript.cpp @@ -1834,7 +1834,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; @@ -1893,7 +1893,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 8f45420442b..87fa8d3913f 100644 --- a/modules/gdscript/gdscript_compiler.cpp +++ b/modules/gdscript/gdscript_compiler.cpp @@ -3078,9 +3078,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 cfff20f6d33..ecaf424091a 100644 --- a/modules/gdscript/gdscript_editor.cpp +++ b/modules/gdscript/gdscript_editor.cpp @@ -2631,7 +2631,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(); @@ -2642,7 +2642,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/godot_physics_2d/godot_physics_server_2d.cpp b/modules/godot_physics_2d/godot_physics_server_2d.cpp index 2516ed3616d..47df6a25267 100644 --- a/modules/godot_physics_2d/godot_physics_server_2d.cpp +++ b/modules/godot_physics_2d/godot_physics_server_2d.cpp @@ -239,7 +239,7 @@ void GodotPhysicsServer2D::space_set_active(RID p_space, bool p_active) { } bool GodotPhysicsServer2D::space_is_active(RID p_space) const { - const GodotSpace2D *space = space_owner.get_or_null(p_space); + GodotSpace2D *space = space_owner.get_or_null(p_space); ERR_FAIL_NULL_V(space, false); return active_spaces.has(space); @@ -1297,8 +1297,8 @@ void GodotPhysicsServer2D::step(real_t p_step) { island_count = 0; active_objects = 0; collision_pairs = 0; - for (const GodotSpace2D *E : active_spaces) { - stepper->step(const_cast(E), p_step); + for (GodotSpace2D *E : active_spaces) { + stepper->step(E, p_step); island_count += E->get_island_count(); active_objects += E->get_active_objects(); collision_pairs += E->get_collision_pairs(); @@ -1318,9 +1318,8 @@ void GodotPhysicsServer2D::flush_queries() { uint64_t time_beg = OS::get_singleton()->get_ticks_usec(); - for (const GodotSpace2D *E : active_spaces) { - GodotSpace2D *space = const_cast(E); - space->call_queries(); + for (GodotSpace2D *E : active_spaces) { + E->call_queries(); } flushing_queries = false; diff --git a/modules/godot_physics_2d/godot_physics_server_2d.h b/modules/godot_physics_2d/godot_physics_server_2d.h index 991cf67c951..ce052ddde8b 100644 --- a/modules/godot_physics_2d/godot_physics_server_2d.h +++ b/modules/godot_physics_2d/godot_physics_server_2d.h @@ -56,7 +56,7 @@ class GodotPhysicsServer2D : public PhysicsServer2D { bool flushing_queries = false; GodotStep2D *stepper = nullptr; - HashSet active_spaces; + HashSet active_spaces; mutable RID_PtrOwner shape_owner; mutable RID_PtrOwner space_owner; diff --git a/modules/godot_physics_2d/godot_shape_2d.cpp b/modules/godot_physics_2d/godot_shape_2d.cpp index d77b1a77e38..e691f0a7e41 100644 --- a/modules/godot_physics_2d/godot_shape_2d.cpp +++ b/modules/godot_physics_2d/godot_shape_2d.cpp @@ -37,8 +37,7 @@ void GodotShape2D::configure(const Rect2 &p_aabb) { aabb = p_aabb; configured = true; for (const KeyValue &E : owners) { - GodotShapeOwner2D *co = const_cast(E.key); - co->_shape_changed(); + E.key->_shape_changed(); } } diff --git a/modules/godot_physics_2d/godot_step_2d.cpp b/modules/godot_physics_2d/godot_step_2d.cpp index 418b9313e85..2d8f69e13fc 100644 --- a/modules/godot_physics_2d/godot_step_2d.cpp +++ b/modules/godot_physics_2d/godot_step_2d.cpp @@ -48,7 +48,7 @@ void GodotStep2D::_populate_island(GodotBody2D *p_body, LocalVector &E : p_body->get_constraint_list()) { - GodotConstraint2D *constraint = const_cast(E.first); + GodotConstraint2D *constraint = E.first; if (constraint->get_island_step() == _step) { continue; // Already processed. } diff --git a/modules/godot_physics_3d/godot_physics_server_3d.cpp b/modules/godot_physics_3d/godot_physics_server_3d.cpp index ad55e415e62..35aa538ef51 100644 --- a/modules/godot_physics_3d/godot_physics_server_3d.cpp +++ b/modules/godot_physics_3d/godot_physics_server_3d.cpp @@ -169,7 +169,7 @@ void GodotPhysicsServer3D::space_set_active(RID p_space, bool p_active) { } bool GodotPhysicsServer3D::space_is_active(RID p_space) const { - const GodotSpace3D *space = space_owner.get_or_null(p_space); + GodotSpace3D *space = space_owner.get_or_null(p_space); ERR_FAIL_NULL_V(space, false); return active_spaces.has(space); @@ -1638,8 +1638,8 @@ void GodotPhysicsServer3D::step(real_t p_step) { island_count = 0; active_objects = 0; collision_pairs = 0; - for (const GodotSpace3D *E : active_spaces) { - stepper->step(const_cast(E), p_step); + for (GodotSpace3D *E : active_spaces) { + stepper->step(E, p_step); island_count += E->get_island_count(); active_objects += E->get_active_objects(); collision_pairs += E->get_collision_pairs(); @@ -1659,8 +1659,8 @@ void GodotPhysicsServer3D::flush_queries() { uint64_t time_beg = OS::get_singleton()->get_ticks_usec(); - for (const GodotSpace3D *E : active_spaces) { - GodotSpace3D *space = const_cast(E); + for (GodotSpace3D *E : active_spaces) { + GodotSpace3D *space = E; space->call_queries(); } diff --git a/modules/godot_physics_3d/godot_physics_server_3d.h b/modules/godot_physics_3d/godot_physics_server_3d.h index 040e673dcd8..94003a7087f 100644 --- a/modules/godot_physics_3d/godot_physics_server_3d.h +++ b/modules/godot_physics_3d/godot_physics_server_3d.h @@ -54,7 +54,7 @@ class GodotPhysicsServer3D : public PhysicsServer3D { bool flushing_queries = false; GodotStep3D *stepper = nullptr; - HashSet active_spaces; + HashSet active_spaces; mutable RID_PtrOwner shape_owner; mutable RID_PtrOwner space_owner; diff --git a/modules/godot_physics_3d/godot_shape_3d.cpp b/modules/godot_physics_3d/godot_shape_3d.cpp index 4356ebe2f27..dbda3da8ecb 100644 --- a/modules/godot_physics_3d/godot_shape_3d.cpp +++ b/modules/godot_physics_3d/godot_shape_3d.cpp @@ -69,7 +69,7 @@ void GodotShape3D::configure(const AABB &p_aabb) { aabb = p_aabb; configured = true; for (const KeyValue &E : owners) { - GodotShapeOwner3D *co = const_cast(E.key); + GodotShapeOwner3D *co = E.key; co->_shape_changed(); } } diff --git a/modules/godot_physics_3d/godot_step_3d.cpp b/modules/godot_physics_3d/godot_step_3d.cpp index b6cec4ba599..7b5afcb9486 100644 --- a/modules/godot_physics_3d/godot_step_3d.cpp +++ b/modules/godot_physics_3d/godot_step_3d.cpp @@ -50,7 +50,7 @@ void GodotStep3D::_populate_island(GodotBody3D *p_body, LocalVector &E : p_body->get_constraint_map()) { - GodotConstraint3D *constraint = const_cast(E.key); + GodotConstraint3D *constraint = E.key; if (constraint->get_island_step() == _step) { continue; // Already processed. } @@ -88,8 +88,8 @@ void GodotStep3D::_populate_island(GodotBody3D *p_body, LocalVector &p_body_island, LocalVector &p_constraint_island) { p_soft_body->set_island_step(_step); - for (const GodotConstraint3D *E : p_soft_body->get_constraints()) { - GodotConstraint3D *constraint = const_cast(E); + for (GodotConstraint3D *E : p_soft_body->get_constraints()) { + GodotConstraint3D *constraint = E; if (constraint->get_island_step() == _step) { continue; // Already processed. } diff --git a/modules/text_server_adv/text_server_adv.cpp b/modules/text_server_adv/text_server_adv.cpp index 8d557aae2a2..4365927826f 100644 --- a/modules/text_server_adv/text_server_adv.cpp +++ b/modules/text_server_adv/text_server_adv.cpp @@ -4846,10 +4846,10 @@ double TextServerAdvanced::_shaped_text_fit_to_width(const RID &p_shaped, double MutexLock lock(sd->mutex); if (!sd->valid.is_set()) { - 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; @@ -5003,10 +5003,10 @@ double TextServerAdvanced::_shaped_text_tab_align(const RID &p_shaped, const Pac MutexLock lock(sd->mutex); if (!sd->valid.is_set()) { - 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++) { @@ -6596,7 +6596,7 @@ const Glyph *TextServerAdvanced::_shaped_text_sort_logical(const RID &p_shaped) MutexLock lock(sd->mutex); if (!sd->valid.is_set()) { - 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 ae636a31516..a36253ffee7 100644 --- a/modules/text_server_fb/text_server_fb.cpp +++ b/modules/text_server_fb/text_server_fb.cpp @@ -3625,10 +3625,10 @@ double TextServerFallback::_shaped_text_fit_to_width(const RID &p_shaped, double MutexLock lock(sd->mutex); if (!sd->valid.is_set()) { - 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; @@ -3734,10 +3734,10 @@ double TextServerFallback::_shaped_text_tab_align(const RID &p_shaped, const Pac MutexLock lock(sd->mutex); if (!sd->valid.is_set()) { - 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++) { @@ -4444,7 +4444,7 @@ const Glyph *TextServerFallback::_shaped_text_sort_logical(const RID &p_shaped) MutexLock lock(sd->mutex); if (!sd->valid.is_set()) { - 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 06f5df48712..f2bdb438715 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 fb3cdf0d4c0..e4aa6165833 100644 --- a/platform/android/os_android.h +++ b/platform/android/os_android.h @@ -75,15 +75,15 @@ private: 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 6c1f49f0466..95cae58fb3f 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 2a3d33221d7..00ea88d19a4 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 97af6d0a5a2..2c621fc605c 100644 --- a/platform/macos/display_server_macos.h +++ b/platform/macos/display_server_macos.h @@ -175,16 +175,16 @@ private: 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; @@ -217,7 +217,7 @@ private: 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); @@ -225,7 +225,7 @@ private: 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 f1078d9868f..c723537d3b6 100644 --- a/platform/macos/display_server_macos.mm +++ b/platform/macos/display_server_macos.mm @@ -283,7 +283,7 @@ void DisplayServerMacOS::set_window_per_pixel_transparency_enabled(bool p_enable } } -void DisplayServerMacOS::_update_displays_arrangement() { +void DisplayServerMacOS::_update_displays_arrangement() const { origin = Point2i(); for (int i = 0; i < get_screen_count(); i++) { @@ -309,7 +309,7 @@ Point2i DisplayServerMacOS::_get_screens_origin() const { // 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; @@ -470,7 +470,7 @@ void DisplayServerMacOS::_process_key_events() { key_event_pos = 0; } -void DisplayServerMacOS::_update_keyboard_layouts() { +void DisplayServerMacOS::_update_keyboard_layouts() const { kbd_layouts.clear(); current_layout = 0; @@ -2935,14 +2935,14 @@ bool DisplayServerMacOS::get_swap_cancel_ok() { 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()); @@ -2972,7 +2972,7 @@ void DisplayServerMacOS::keyboard_set_current_layout(int p_index) { int DisplayServerMacOS::keyboard_get_current_layout() const { if (keyboard_layout_dirty) { - const_cast(this)->_update_keyboard_layouts(); + _update_keyboard_layouts(); } return current_layout; @@ -2980,7 +2980,7 @@ int DisplayServerMacOS::keyboard_get_current_layout() const { 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(), ""); @@ -2989,7 +2989,7 @@ String DisplayServerMacOS::keyboard_get_layout_language(int p_index) const { 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 fc14e6ed627..df6ec65d9c5 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 39cfccf983f..66a2d07783d 100644 --- a/scene/2d/skeleton_2d.cpp +++ b/scene/2d/skeleton_2d.cpp @@ -613,6 +613,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 b723b452c16..fa27312dd5c 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 08bd60034b6..ef509ee5e72 100644 --- a/scene/3d/skeleton_3d.cpp +++ b/scene/3d/skeleton_3d.cpp @@ -236,7 +236,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; } @@ -280,7 +280,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 { @@ -468,7 +468,7 @@ void Skeleton3D::_make_modifiers_dirty() { _update_deferred(UPDATE_FLAG_MODIFIER); } -void Skeleton3D::_update_bones_nested_set() { +void Skeleton3D::_update_bones_nested_set() const { nested_set_offset_to_bone_index.resize(bones.size()); bone_global_pose_dirty.resize(bones.size()); _make_bone_global_poses_dirty(); @@ -479,7 +479,7 @@ void Skeleton3D::_update_bones_nested_set() { } } -int Skeleton3D::_update_bone_nested_set(int p_bone, int p_offset) { +int Skeleton3D::_update_bone_nested_set(int p_bone, int p_offset) const { Bone &bone = bones[p_bone]; int offset = p_offset + 1; int span = 1; @@ -497,13 +497,13 @@ int Skeleton3D::_update_bone_nested_set(int p_bone, int p_offset) { return span; } -void Skeleton3D::_make_bone_global_poses_dirty() { +void Skeleton3D::_make_bone_global_poses_dirty() const { for (uint32_t i = 0; i < bone_global_pose_dirty.size(); i++) { bone_global_pose_dirty[i] = true; } } -void Skeleton3D::_make_bone_global_pose_subtree_dirty(int p_bone) { +void Skeleton3D::_make_bone_global_pose_subtree_dirty(int p_bone) const { if (process_order_dirty) { return; } @@ -522,7 +522,7 @@ void Skeleton3D::_make_bone_global_pose_subtree_dirty(int p_bone) { } } -void Skeleton3D::_update_bone_global_pose(int p_bone) { +void Skeleton3D::_update_bone_global_pose(int p_bone) const { const int bone_size = bones.size(); ERR_FAIL_INDEX(p_bone, bone_size); @@ -572,7 +572,7 @@ void Skeleton3D::_update_bone_global_pose(int p_bone) { 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)->_update_bone_global_pose(p_bone); + _update_bone_global_pose(p_bone); return bones[p_bone].global_pose; } @@ -756,7 +756,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; } @@ -765,14 +765,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; } @@ -796,7 +796,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; } @@ -921,7 +921,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[p_bone].update_pose_cache(); + bones[p_bone].update_pose_cache(); return bones[p_bone].pose_cache; } @@ -1037,20 +1037,28 @@ void Skeleton3D::force_update_deferred() { } 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(); + _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_children_transforms(parentless_bones[i]); } if (rest_dirty) { rest_dirty = false; - emit_signal(SNAME("rest_updated")); + const_cast(this)->emit_signal(SNAME("rest_updated")); } else { rest_dirty = false; } @@ -1058,10 +1066,14 @@ void Skeleton3D::force_update_all_bone_transforms() { if (updating) { return; } - emit_signal(SceneStringName(pose_updated)); + const_cast(this)->emit_signal(SceneStringName(pose_updated)); } void Skeleton3D::force_update_bone_children_transforms(int p_bone_idx) { + _force_update_bone_children_transforms(p_bone_idx); +} + +void Skeleton3D::_force_update_bone_children_transforms(int p_bone_idx) const { const int bone_size = bones.size(); ERR_FAIL_INDEX(p_bone_idx, bone_size); @@ -1321,7 +1333,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 c224a795509..73731462871 100644 --- a/scene/3d/skeleton_3d.h +++ b/scene/3d/skeleton_3d.h @@ -156,25 +156,25 @@ private: HashSet skin_bindings; void _skin_changed(); - LocalVector bones; - bool process_order_dirty = false; + mutable LocalVector bones; + mutable bool process_order_dirty = false; - Vector parentless_bones; + mutable Vector parentless_bones; AHashMap name_to_bone_index; mutable StringName concatenated_bone_names; 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; @@ -184,16 +184,16 @@ private: void _process_modifiers(); void _process_changed(); void _make_modifiers_dirty(); - LocalVector bones_backup; + mutable LocalVector bones_backup; // Global bone pose calculation. - LocalVector nested_set_offset_to_bone_index; // Map from Bone::nested_set_offset to bone index. - LocalVector bone_global_pose_dirty; // Indexable with Bone::nested_set_offset. - void _update_bones_nested_set(); - int _update_bone_nested_set(int p_bone, int p_offset); - void _make_bone_global_poses_dirty(); - void _make_bone_global_pose_subtree_dirty(int p_bone); - void _update_bone_global_pose(int p_bone); + mutable LocalVector nested_set_offset_to_bone_index; // Map from Bone::nested_set_offset to bone index. + mutable LocalVector bone_global_pose_dirty; // Indexable with Bone::nested_set_offset. + void _update_bones_nested_set() const; + int _update_bone_nested_set(int p_bone, int p_offset) const; + void _make_bone_global_poses_dirty() const; + void _make_bone_global_pose_subtree_dirty(int p_bone) const; + void _update_bone_global_pose(int p_bone) const; #ifndef DISABLE_DEPRECATED void _add_bone_bind_compat_88791(const String &p_name); @@ -283,8 +283,11 @@ public: 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_all_bone_transforms() const; void force_update_bone_children_transforms(int bone_idx); + void _force_update_bone_children_transforms(int bone_idx) const; void force_update_deferred(); void set_modifier_callback_mode_process(ModifierCallbackModeProcess p_mode); diff --git a/scene/animation/animation_tree.cpp b/scene/animation/animation_tree.cpp index f2871cda795..0eb967d38a3 100644 --- a/scene/animation/animation_tree.cpp +++ b/scene/animation/animation_tree.cpp @@ -745,7 +745,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] = AHashMap(); @@ -792,7 +792,7 @@ void AnimationTree::_update_properties_for_node(const String &p_base_path, Ref(this)->notify_property_list_changed(); } void AnimationTree::_notification(int p_what) { @@ -925,7 +925,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)) { @@ -938,7 +938,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 5a2a822ff04..a354ece1315 100644 --- a/scene/animation/animation_tree.h +++ b/scene/animation/animation_tree.h @@ -284,15 +284,15 @@ private: friend class AnimationNode; - List properties; - AHashMap> property_parent_map; - AHashMap property_reference_map; - AHashMap> property_map; // Property value and read-only flag. + mutable List properties; + mutable AHashMap> property_parent_map; + mutable AHashMap property_reference_map; + mutable AHashMap> 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); @@ -302,8 +302,8 @@ private: 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 3e593a83720..3dae2b780d3 100644 --- a/scene/gui/button.cpp +++ b/scene/gui/button.cpp @@ -488,7 +488,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(); @@ -527,7 +527,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 686d4806dbc..ebbdae1ef14 100644 --- a/scene/gui/button.h +++ b/scene/gui/button.h @@ -103,7 +103,7 @@ private: int line_spacing = 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 4a3f7f24146..4010d57b1d2 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -1672,7 +1672,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); @@ -1683,7 +1683,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; } @@ -3059,11 +3059,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()) { @@ -3071,22 +3071,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 // TOOLS_ENABLED @@ -3094,35 +3094,35 @@ 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_APPLICATION_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 if (data.layout_dir == LAYOUT_DIRECTION_SYSTEM_LOCALE) { if (GLOBAL_GET(SNAME("internationalization/rendering/force_right_to_left_layout_direction"))) { @@ -3132,7 +3132,7 @@ bool Control::is_layout_rtl() const { const_cast(this)->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 ac386659ec4..23190381f3f 100644 --- a/scene/gui/control.h +++ b/scene/gui/control.h @@ -200,8 +200,8 @@ private: 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; @@ -258,8 +258,8 @@ private: // 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; @@ -299,7 +299,7 @@ private: 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 7dd24cc14d3..eca5756fe3f 100644 --- a/scene/gui/label.cpp +++ b/scene/gui/label.cpp @@ -107,7 +107,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); @@ -326,11 +326,11 @@ void Label::_shape() { _update_visible(); if (autowrap_mode == TextServer::AUTOWRAP_OFF || !clip || overrun_behavior == TextServer::OVERRUN_NO_TRIMMING) { - update_minimum_size(); + const_cast