diff --git a/scene/2d/light_2d.cpp b/scene/2d/light_2d.cpp index db34558bf66..6ee4732e4fd 100644 --- a/scene/2d/light_2d.cpp +++ b/scene/2d/light_2d.cpp @@ -216,7 +216,7 @@ void Light2D::_notification(int p_what) { } break; case NOTIFICATION_RESET_PHYSICS_INTERPOLATION: { - if (is_visible_in_tree() && is_physics_interpolated()) { + if (is_visible_in_tree() && is_physics_interpolated_and_enabled()) { // Explicitly make sure the transform is up to date in RenderingServer before // resetting. This is necessary because NOTIFICATION_TRANSFORM_CHANGED // is normally deferred, and a client change to transform will not always be sent diff --git a/scene/2d/light_occluder_2d.cpp b/scene/2d/light_occluder_2d.cpp index a0ee730e437..d6c28ad6eb5 100644 --- a/scene/2d/light_occluder_2d.cpp +++ b/scene/2d/light_occluder_2d.cpp @@ -206,7 +206,7 @@ void LightOccluder2D::_notification(int p_what) { } break; case NOTIFICATION_RESET_PHYSICS_INTERPOLATION: { - if (is_visible_in_tree() && is_physics_interpolated()) { + if (is_visible_in_tree() && is_physics_interpolated_and_enabled()) { // Explicitly make sure the transform is up to date in RenderingServer before // resetting. This is necessary because NOTIFICATION_TRANSFORM_CHANGED // is normally deferred, and a client change to transform will not always be sent diff --git a/scene/2d/physics/physics_body_2d.cpp b/scene/2d/physics/physics_body_2d.cpp index 18a29ee1344..ecdd1571bd7 100644 --- a/scene/2d/physics/physics_body_2d.cpp +++ b/scene/2d/physics/physics_body_2d.cpp @@ -173,7 +173,7 @@ void PhysicsBody2D::remove_collision_exception_with(Node *p_node) { PackedStringArray PhysicsBody2D::get_configuration_warnings() const { PackedStringArray warnings = CollisionObject2D::get_configuration_warnings(); - if (!is_physics_interpolated()) { + if (SceneTree::is_fti_enabled_in_project() && !is_physics_interpolated()) { warnings.push_back(RTR("PhysicsBody2D will not work correctly on a non-interpolated branch of the SceneTree.\nCheck the node's inherited physics_interpolation_mode.")); } diff --git a/scene/2d/tile_map_layer.cpp b/scene/2d/tile_map_layer.cpp index 1f2e324823d..7978408af56 100644 --- a/scene/2d/tile_map_layer.cpp +++ b/scene/2d/tile_map_layer.cpp @@ -239,7 +239,7 @@ void TileMapLayer::_rendering_update(bool p_force_cleanup) { } // Update all dirty quadrants. - bool needs_set_not_interpolated = is_inside_tree() && get_tree()->is_physics_interpolation_enabled() && !is_physics_interpolated(); + bool needs_set_not_interpolated = SceneTree::is_fti_enabled() && !is_physics_interpolated(); for (SelfList *quadrant_list_element = dirty_rendering_quadrant_list.first(); quadrant_list_element;) { SelfList *next_quadrant_list_element = quadrant_list_element->next(); // "Hack" to clear the list while iterating. @@ -593,7 +593,7 @@ void TileMapLayer::_rendering_occluders_update_cell(CellData &r_cell_data) { bool transpose = (r_cell_data.cell.alternative_tile & TileSetAtlasSource::TRANSFORM_TRANSPOSE); // Create, update or clear occluders. - bool needs_set_not_interpolated = is_inside_tree() && get_tree()->is_physics_interpolation_enabled() && !is_physics_interpolated(); + bool needs_set_not_interpolated = SceneTree::is_fti_enabled() && !is_physics_interpolated(); for (uint32_t occlusion_layer_index = 0; occlusion_layer_index < r_cell_data.occluders.size(); occlusion_layer_index++) { LocalVector &occluders = r_cell_data.occluders[occlusion_layer_index]; diff --git a/scene/3d/node_3d.cpp b/scene/3d/node_3d.cpp index 00a40b12cc3..b2449607df9 100644 --- a/scene/3d/node_3d.cpp +++ b/scene/3d/node_3d.cpp @@ -509,7 +509,7 @@ Transform3D Node3D::get_global_transform_interpolated() { // Pass through if physics interpolation is switched off. // This is a convenience, as it allows you to easy turn off interpolation // without changing any code. - if (is_inside_tree() && get_tree()->is_physics_interpolation_enabled() && !Engine::get_singleton()->is_in_physics_frame()) { + if (SceneTree::is_fti_enabled() && is_inside_tree() && !Engine::get_singleton()->is_in_physics_frame()) { // Note that with SceneTreeFTI, we may want to calculate interpolated transform for a node // with physics interpolation set to OFF, if it has a parent that is ON. diff --git a/scene/3d/physics/physics_body_3d.cpp b/scene/3d/physics/physics_body_3d.cpp index c844e5ddf7a..5518c8fd279 100644 --- a/scene/3d/physics/physics_body_3d.cpp +++ b/scene/3d/physics/physics_body_3d.cpp @@ -213,7 +213,7 @@ real_t PhysicsBody3D::get_inverse_mass() const { PackedStringArray PhysicsBody3D::get_configuration_warnings() const { PackedStringArray warnings = CollisionObject3D::get_configuration_warnings(); - if (!is_physics_interpolated()) { + if (SceneTree::is_fti_enabled_in_project() && !is_physics_interpolated()) { warnings.push_back(RTR("PhysicsBody3D will not work correctly on a non-interpolated branch of the SceneTree.\nCheck the node's inherited physics_interpolation_mode.")); } diff --git a/scene/3d/xr/xr_nodes.cpp b/scene/3d/xr/xr_nodes.cpp index 3ca927acc84..d4321d442de 100644 --- a/scene/3d/xr/xr_nodes.cpp +++ b/scene/3d/xr/xr_nodes.cpp @@ -92,7 +92,7 @@ PackedStringArray XRCamera3D::get_configuration_warnings() const { warnings.push_back(RTR("XRCamera3D may not function as expected without an XROrigin3D node as its parent.")); }; - if (is_physics_interpolated()) { + if (SceneTree::is_fti_enabled_in_project() && is_physics_interpolated()) { warnings.push_back(RTR("XRCamera3D should have physics_interpolation_mode set to OFF in order to avoid jitter.")); } } @@ -501,7 +501,7 @@ PackedStringArray XRNode3D::get_configuration_warnings() const { warnings.push_back(RTR("No pose is set.")); } - if (is_physics_interpolated()) { + if (SceneTree::is_fti_enabled_in_project() && is_physics_interpolated()) { warnings.push_back(RTR("XRNode3D should have physics_interpolation_mode set to OFF in order to avoid jitter.")); } } diff --git a/scene/main/canvas_item.cpp b/scene/main/canvas_item.cpp index 1aa2d964eda..9373dc1c8be 100644 --- a/scene/main/canvas_item.cpp +++ b/scene/main/canvas_item.cpp @@ -405,7 +405,7 @@ void CanvasItem::_notification(int p_what) { } break; case NOTIFICATION_RESET_PHYSICS_INTERPOLATION: { - if (is_visible_in_tree() && is_physics_interpolated()) { + if (is_visible_in_tree() && is_physics_interpolated_and_enabled()) { RenderingServer::get_singleton()->canvas_item_reset_physics_interpolation(canvas_item); } } break; diff --git a/scene/main/node.h b/scene/main/node.h index 9e21065b802..9bc0100914b 100644 --- a/scene/main/node.h +++ b/scene/main/node.h @@ -711,7 +711,7 @@ public: void set_physics_interpolation_mode(PhysicsInterpolationMode p_mode); PhysicsInterpolationMode get_physics_interpolation_mode() const { return data.physics_interpolation_mode; } _FORCE_INLINE_ bool is_physics_interpolated() const { return data.physics_interpolated; } - _FORCE_INLINE_ bool is_physics_interpolated_and_enabled() const { return is_inside_tree() && get_tree()->is_physics_interpolation_enabled() && is_physics_interpolated(); } + _FORCE_INLINE_ bool is_physics_interpolated_and_enabled() const { return SceneTree::is_fti_enabled() && is_physics_interpolated(); } void reset_physics_interpolation(); bool is_enabled() const; diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp index 8216a28ec2d..a24745dc194 100644 --- a/scene/main/scene_tree.cpp +++ b/scene/main/scene_tree.cpp @@ -137,6 +137,9 @@ void SceneTree::ClientPhysicsInterpolation::physics_process() { } #endif // _3D_DISABLED +bool SceneTree::_physics_interpolation_enabled = false; +bool SceneTree::_physics_interpolation_enabled_in_project = false; + void SceneTree::tree_changed() { emit_signal(tree_changed_name); } @@ -566,6 +569,9 @@ void SceneTree::initialize() { } void SceneTree::set_physics_interpolation_enabled(bool p_enabled) { + // This version is for use in editor. + _physics_interpolation_enabled_in_project = p_enabled; + // We never want interpolation in the editor. if (Engine::get_singleton()->is_editor_hint()) { p_enabled = false; @@ -586,10 +592,6 @@ void SceneTree::set_physics_interpolation_enabled(bool p_enabled) { } } -bool SceneTree::is_physics_interpolation_enabled() const { - return _physics_interpolation_enabled; -} - #ifndef _3D_DISABLED void SceneTree::client_physics_interpolation_add_node_3d(SelfList *p_elem) { // This ensures that _update_physics_interpolation_data() will be called at least once every diff --git a/scene/main/scene_tree.h b/scene/main/scene_tree.h index 76cb0234c11..1b4ad6bd559 100644 --- a/scene/main/scene_tree.h +++ b/scene/main/scene_tree.h @@ -146,7 +146,14 @@ private: HashMap group_map; bool _quit = false; - bool _physics_interpolation_enabled = false; + // Static so we can get directly instead of via SceneTree pointer. + static bool _physics_interpolation_enabled; + + // Note that physics interpolation is hard coded to OFF in the editor, + // therefore we have a second bool to enable e.g. configuration warnings + // to only take effect when the project is using physics interpolation. + static bool _physics_interpolation_enabled_in_project; + SceneTreeFTI scene_tree_fti; StringName tree_changed_name = "tree_changed"; @@ -446,7 +453,11 @@ public: //default texture settings void set_physics_interpolation_enabled(bool p_enabled); - bool is_physics_interpolation_enabled() const; + bool is_physics_interpolation_enabled() const { return _physics_interpolation_enabled; } + + // Different name to disambiguate fast static versions from the user bound versions. + static bool is_fti_enabled() { return _physics_interpolation_enabled; } + static bool is_fti_enabled_in_project() { return _physics_interpolation_enabled_in_project; } #ifndef _3D_DISABLED void client_physics_interpolation_add_node_3d(SelfList *p_elem);