diff options
author | Ricardo Buring <ricardo.buring@gmail.com> | 2024-02-17 00:57:32 +0100 |
---|---|---|
committer | Ricardo Buring <ricardo.buring@gmail.com> | 2024-03-23 12:28:36 +0100 |
commit | 2ed2ccc2d8ff17b97d8ac0fd80fc0190ea47ed00 (patch) | |
tree | 0b0595cc3bf93413b4a394967ea96fde2f7cd3d3 /scene/main/canvas_item.cpp | |
parent | fe01776f05b1787b28b4a270d53037a3c25f4ca2 (diff) | |
download | redot-engine-2ed2ccc2d8ff17b97d8ac0fd80fc0190ea47ed00.tar.gz |
Fixed Timestep Interpolation (2D)
Adds fixed timestep interpolation to the rendering server (2D only).
Switchable on and off with a project setting (default is off).
Co-authored-by: lawnjelly <lawnjelly@gmail.com>
Diffstat (limited to 'scene/main/canvas_item.cpp')
-rw-r--r-- | scene/main/canvas_item.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/scene/main/canvas_item.cpp b/scene/main/canvas_item.cpp index 2d0da075ba..768c83954b 100644 --- a/scene/main/canvas_item.cpp +++ b/scene/main/canvas_item.cpp @@ -336,6 +336,19 @@ void CanvasItem::_notification(int p_what) { get_parent()->connect(SNAME("child_order_changed"), callable_mp(get_viewport(), &Viewport::canvas_parent_mark_dirty).bind(get_parent()), CONNECT_REFERENCE_COUNTED); } + // If using physics interpolation, reset for this node only, + // as a helper, as in most cases, users will want items reset when + // adding to the tree. + // In cases where they move immediately after adding, + // there will be little cost in having two resets as these are cheap, + // and it is worth it for convenience. + // Do not propagate to children, as each child of an added branch + // receives its own NOTIFICATION_ENTER_TREE, and this would + // cause unnecessary duplicate resets. + if (is_physics_interpolated_and_enabled()) { + notification(NOTIFICATION_RESET_PHYSICS_INTERPOLATION); + } + } break; case NOTIFICATION_EXIT_TREE: { ERR_MAIN_THREAD_GUARD; @@ -360,6 +373,12 @@ void CanvasItem::_notification(int p_what) { } } break; + case NOTIFICATION_RESET_PHYSICS_INTERPOLATION: { + if (is_visible_in_tree() && is_physics_interpolated()) { + RenderingServer::get_singleton()->canvas_item_reset_physics_interpolation(canvas_item); + } + } break; + case NOTIFICATION_VISIBILITY_CHANGED: { ERR_MAIN_THREAD_GUARD; @@ -921,6 +940,10 @@ void CanvasItem::_notify_transform(CanvasItem *p_node) { } } +void CanvasItem::_physics_interpolated_changed() { + RenderingServer::get_singleton()->canvas_item_set_interpolated(canvas_item, is_physics_interpolated()); +} + Rect2 CanvasItem::get_viewport_rect() const { ERR_READ_THREAD_GUARD_V(Rect2()); ERR_FAIL_COND_V(!is_inside_tree(), Rect2()); |