From df7fab51a39c6e03a033fe6f0e9a3885cb4a87d9 Mon Sep 17 00:00:00 2001 From: lawnjelly Date: Wed, 4 May 2022 19:56:06 +0100 Subject: [PATCH] Physics Interpolation - Flush transforms after physics tick Leftover transforms from the physics tick were being flushed during idle, which was causing problems for physics interpolation. This PR flushes the transforms at the end of the physics tick when physics interpolation is active. --- core/os/main_loop.h | 1 + main/main.cpp | 2 ++ scene/main/scene_tree.cpp | 8 ++++++++ scene/main/scene_tree.h | 1 + 4 files changed, 12 insertions(+) diff --git a/core/os/main_loop.h b/core/os/main_loop.h index 408040c967b..c36c05ae221 100644 --- a/core/os/main_loop.h +++ b/core/os/main_loop.h @@ -68,6 +68,7 @@ public: virtual void init(); virtual bool iteration(float p_time); + virtual void iteration_end() {} virtual bool idle(float p_time); virtual void finish(); diff --git a/main/main.cpp b/main/main.cpp index f2acdd0fc51..6f97da61723 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -2257,6 +2257,8 @@ bool Main::iteration() { message_queue->flush(); + OS::get_singleton()->get_main_loop()->iteration_end(); + physics_process_ticks = MAX(physics_process_ticks, OS::get_singleton()->get_ticks_usec() - physics_begin); // keep the largest one for reference physics_process_max = MAX(OS::get_singleton()->get_ticks_usec() - physics_begin, physics_process_max); Engine::get_singleton()->_physics_frames++; diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp index a0c365cf062..6de9cfacdb6 100644 --- a/scene/main/scene_tree.cpp +++ b/scene/main/scene_tree.cpp @@ -525,6 +525,14 @@ void SceneTree::client_physics_interpolation_remove_spatial(SelfList *p _client_physics_interpolation._spatials_list.remove(p_elem); } +void SceneTree::iteration_end() { + // When physics interpolation is active, we want all pending transforms + // to be flushed to the VisualServer before finishing a physics tick. + if (_physics_interpolation_enabled) { + flush_transform_notifications(); + } +} + bool SceneTree::iteration(float p_time) { root_lock++; diff --git a/scene/main/scene_tree.h b/scene/main/scene_tree.h index c9780006860..e1f93af924e 100644 --- a/scene/main/scene_tree.h +++ b/scene/main/scene_tree.h @@ -306,6 +306,7 @@ public: virtual void init(); virtual bool iteration(float p_time); + virtual void iteration_end(); virtual bool idle(float p_time); virtual void finish();