diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2024-07-07 21:58:55 +0200 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2024-07-07 21:58:55 +0200 |
commit | 307b4e30919ae9762ed12fafbe9b04c90bd105ab (patch) | |
tree | 4e21fa8f0b7ff8ab9f5818dad3af6983d6454a7e | |
parent | aec5c85acb7e052c64588b708c8ee6d22b3a6489 (diff) | |
parent | 23521635d2f68525a6e41dde17bf34a53225e3e1 (diff) | |
download | redot-engine-307b4e30919ae9762ed12fafbe9b04c90bd105ab.tar.gz |
Merge pull request #94039 from rburing/fix_physics_tickcounter
Fix physics tick counter
-rw-r--r-- | core/input/input.cpp | 5 | ||||
-rw-r--r-- | main/main.cpp | 2 | ||||
-rw-r--r-- | scene/2d/camera_2d.h | 2 | ||||
-rw-r--r-- | scene/2d/navigation_agent_2d.cpp | 3 | ||||
-rw-r--r-- | scene/2d/navigation_agent_2d.h | 2 | ||||
-rw-r--r-- | scene/3d/navigation_agent_3d.cpp | 3 | ||||
-rw-r--r-- | scene/3d/navigation_agent_3d.h | 2 |
7 files changed, 5 insertions, 14 deletions
diff --git a/core/input/input.cpp b/core/input/input.cpp index 56f616fac4..ec0303df06 100644 --- a/core/input/input.cpp +++ b/core/input/input.cpp @@ -758,12 +758,13 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em bool was_pressed = action_state.cache.pressed; _update_action_cache(E.key, action_state); + // As input may come in part way through a physics tick, the earliest we can react to it is the next physics tick. if (action_state.cache.pressed && !was_pressed) { - action_state.pressed_physics_frame = Engine::get_singleton()->get_physics_frames(); + action_state.pressed_physics_frame = Engine::get_singleton()->get_physics_frames() + 1; action_state.pressed_process_frame = Engine::get_singleton()->get_process_frames(); } if (!action_state.cache.pressed && was_pressed) { - action_state.released_physics_frame = Engine::get_singleton()->get_physics_frames(); + action_state.released_physics_frame = Engine::get_singleton()->get_physics_frames() + 1; action_state.released_process_frame = Engine::get_singleton()->get_process_frames(); } } diff --git a/main/main.cpp b/main/main.cpp index e6be23034d..060b3fe2f6 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -4043,6 +4043,7 @@ bool Main::iteration() { } Engine::get_singleton()->_in_physics = true; + Engine::get_singleton()->_physics_frames++; uint64_t physics_begin = OS::get_singleton()->get_ticks_usec(); @@ -4090,7 +4091,6 @@ bool Main::iteration() { 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++; Engine::get_singleton()->_in_physics = false; } diff --git a/scene/2d/camera_2d.h b/scene/2d/camera_2d.h index 8754e35e88..be2da8b97a 100644 --- a/scene/2d/camera_2d.h +++ b/scene/2d/camera_2d.h @@ -108,7 +108,7 @@ protected: struct InterpolationData { Transform2D xform_curr; Transform2D xform_prev; - uint32_t last_update_physics_tick = 0; + uint32_t last_update_physics_tick = UINT32_MAX; // Ensure tick 0 is detected as a change. } _interpolation_data; void _ensure_update_interpolation_data(); diff --git a/scene/2d/navigation_agent_2d.cpp b/scene/2d/navigation_agent_2d.cpp index 9e3e6ea583..d0fae611d8 100644 --- a/scene/2d/navigation_agent_2d.cpp +++ b/scene/2d/navigation_agent_2d.cpp @@ -671,8 +671,6 @@ void NavigationAgent2D::_update_navigation() { return; } - update_frame_id = Engine::get_singleton()->get_physics_frames(); - Vector2 origin = agent_parent->get_global_position(); bool reload_path = false; @@ -767,7 +765,6 @@ void NavigationAgent2D::_request_repath() { target_reached = false; navigation_finished = false; last_waypoint_reached = false; - update_frame_id = 0; } bool NavigationAgent2D::_is_last_waypoint() const { diff --git a/scene/2d/navigation_agent_2d.h b/scene/2d/navigation_agent_2d.h index 0acfc82162..8741f578d0 100644 --- a/scene/2d/navigation_agent_2d.h +++ b/scene/2d/navigation_agent_2d.h @@ -91,8 +91,6 @@ class NavigationAgent2D : public Node { bool target_reached = false; bool navigation_finished = true; bool last_waypoint_reached = false; - // No initialized on purpose - uint32_t update_frame_id = 0; // Debug properties for exposed bindings bool debug_enabled = false; diff --git a/scene/3d/navigation_agent_3d.cpp b/scene/3d/navigation_agent_3d.cpp index dff413f5d2..5bbb724e2f 100644 --- a/scene/3d/navigation_agent_3d.cpp +++ b/scene/3d/navigation_agent_3d.cpp @@ -737,8 +737,6 @@ void NavigationAgent3D::_update_navigation() { return; } - update_frame_id = Engine::get_singleton()->get_physics_frames(); - Vector3 origin = agent_parent->get_global_position(); bool reload_path = false; @@ -835,7 +833,6 @@ void NavigationAgent3D::_request_repath() { target_reached = false; navigation_finished = false; last_waypoint_reached = false; - update_frame_id = 0; } bool NavigationAgent3D::_is_last_waypoint() const { diff --git a/scene/3d/navigation_agent_3d.h b/scene/3d/navigation_agent_3d.h index ade6afd445..d5721a56c8 100644 --- a/scene/3d/navigation_agent_3d.h +++ b/scene/3d/navigation_agent_3d.h @@ -98,8 +98,6 @@ class NavigationAgent3D : public Node { bool target_reached = false; bool navigation_finished = true; bool last_waypoint_reached = false; - // No initialized on purpose - uint32_t update_frame_id = 0; // Debug properties for exposed bindings bool debug_enabled = false; |