From 7ad35d62ea84afa533cf7f993d0c167f17c36d30 Mon Sep 17 00:00:00 2001 From: Relintai Date: Fri, 29 Jul 2022 10:59:58 +0200 Subject: [PATCH] Ported: Physics Interpolation - fix stale interpolation data when unhiding A previous optimization prevented instances being added to the interpolation lists when hidden to save processing. This caused a regression when unhiding nodes outside of the physics tick - the interpolated transforms would be stale until the next physics tick, causing a glitch. This PR readds instances immediately to the interpolation lists when they are unhidden, preventing this glitch. - lawnjelly and Physics Interpolation - fix continuous updating in unmoving objects Adds instances to the transform update list as well as the interpolate update list when unhiding them. This ensures that the system auto-detects non-moving objects, and removes them from the interpolate update list on the next tick, preventing unnecessary updates. - lawnjelly https://github.com/godotengine/godot/commit/991687cc10dca2d06258854b3546d708ecb91fb3 https://github.com/godotengine/godot/commit/e4f252d94fec9e4ea5afe3934458617be04d67f5 Properly this time. --- servers/visual/visual_server_scene.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/servers/visual/visual_server_scene.cpp b/servers/visual/visual_server_scene.cpp index 2d3ba6601..4defbc2f3 100644 --- a/servers/visual/visual_server_scene.cpp +++ b/servers/visual/visual_server_scene.cpp @@ -989,6 +989,25 @@ void VisualServerScene::instance_set_visible(RID p_instance, bool p_visible) { instance->visible = p_visible; + // Special case for physics interpolation, we want to ensure the interpolated data is up to date + if (instance->scenario->_interpolation_data.interpolation_enabled && p_visible && instance->interpolated && instance->scenario && !instance->on_interpolate_list) { + // Do all the extra work we normally do on instance_set_transform(), because this is optimized out for hidden instances. + // This prevents a glitch of stale interpolation transform data when unhiding before the next physics tick. + instance->interpolation_method = TransformInterpolator::find_method(instance->transform_prev.basis, instance->transform_curr.basis); + instance->scenario->_interpolation_data.instance_interpolate_update_list.push_back(p_instance); + instance->on_interpolate_list = true; + _instance_queue_update(instance, true); + + // We must also place on the transform update list for a tick, so the system + // can auto-detect if the instance is no longer moving, and remove from the interpolate lists again. + // If this step is ignored, an unmoving instance could remain on the interpolate lists indefinitely + // (or rather until the object is deleted) and cause unnecessary updates and drawcalls. + if (!instance->on_interpolate_transform_list) { + instance->scenario->_interpolation_data.instance_transform_update_list_curr->push_back(p_instance); + instance->on_interpolate_transform_list = true; + } + } + // give the opportunity for the spatial partitioning scene to use a special implementation of visibility // for efficiency (supported in BVH but not octree)