Skip to content

Commit 307b4e3

Browse files
committed
Merge pull request godotengine#94039 from rburing/fix_physics_tickcounter
Fix physics tick counter
2 parents aec5c85 + 2352163 commit 307b4e3

File tree

7 files changed

+5
-14
lines changed

7 files changed

+5
-14
lines changed

core/input/input.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -758,12 +758,13 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em
758758

759759
bool was_pressed = action_state.cache.pressed;
760760
_update_action_cache(E.key, action_state);
761+
// As input may come in part way through a physics tick, the earliest we can react to it is the next physics tick.
761762
if (action_state.cache.pressed && !was_pressed) {
762-
action_state.pressed_physics_frame = Engine::get_singleton()->get_physics_frames();
763+
action_state.pressed_physics_frame = Engine::get_singleton()->get_physics_frames() + 1;
763764
action_state.pressed_process_frame = Engine::get_singleton()->get_process_frames();
764765
}
765766
if (!action_state.cache.pressed && was_pressed) {
766-
action_state.released_physics_frame = Engine::get_singleton()->get_physics_frames();
767+
action_state.released_physics_frame = Engine::get_singleton()->get_physics_frames() + 1;
767768
action_state.released_process_frame = Engine::get_singleton()->get_process_frames();
768769
}
769770
}

main/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4043,6 +4043,7 @@ bool Main::iteration() {
40434043
}
40444044

40454045
Engine::get_singleton()->_in_physics = true;
4046+
Engine::get_singleton()->_physics_frames++;
40464047

40474048
uint64_t physics_begin = OS::get_singleton()->get_ticks_usec();
40484049

@@ -4090,7 +4091,6 @@ bool Main::iteration() {
40904091

40914092
physics_process_ticks = MAX(physics_process_ticks, OS::get_singleton()->get_ticks_usec() - physics_begin); // keep the largest one for reference
40924093
physics_process_max = MAX(OS::get_singleton()->get_ticks_usec() - physics_begin, physics_process_max);
4093-
Engine::get_singleton()->_physics_frames++;
40944094

40954095
Engine::get_singleton()->_in_physics = false;
40964096
}

scene/2d/camera_2d.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class Camera2D : public Node2D {
108108
struct InterpolationData {
109109
Transform2D xform_curr;
110110
Transform2D xform_prev;
111-
uint32_t last_update_physics_tick = 0;
111+
uint32_t last_update_physics_tick = UINT32_MAX; // Ensure tick 0 is detected as a change.
112112
} _interpolation_data;
113113

114114
void _ensure_update_interpolation_data();

scene/2d/navigation_agent_2d.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -671,8 +671,6 @@ void NavigationAgent2D::_update_navigation() {
671671
return;
672672
}
673673

674-
update_frame_id = Engine::get_singleton()->get_physics_frames();
675-
676674
Vector2 origin = agent_parent->get_global_position();
677675

678676
bool reload_path = false;
@@ -767,7 +765,6 @@ void NavigationAgent2D::_request_repath() {
767765
target_reached = false;
768766
navigation_finished = false;
769767
last_waypoint_reached = false;
770-
update_frame_id = 0;
771768
}
772769

773770
bool NavigationAgent2D::_is_last_waypoint() const {

scene/2d/navigation_agent_2d.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,6 @@ class NavigationAgent2D : public Node {
9191
bool target_reached = false;
9292
bool navigation_finished = true;
9393
bool last_waypoint_reached = false;
94-
// No initialized on purpose
95-
uint32_t update_frame_id = 0;
9694

9795
// Debug properties for exposed bindings
9896
bool debug_enabled = false;

scene/3d/navigation_agent_3d.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -737,8 +737,6 @@ void NavigationAgent3D::_update_navigation() {
737737
return;
738738
}
739739

740-
update_frame_id = Engine::get_singleton()->get_physics_frames();
741-
742740
Vector3 origin = agent_parent->get_global_position();
743741

744742
bool reload_path = false;
@@ -835,7 +833,6 @@ void NavigationAgent3D::_request_repath() {
835833
target_reached = false;
836834
navigation_finished = false;
837835
last_waypoint_reached = false;
838-
update_frame_id = 0;
839836
}
840837

841838
bool NavigationAgent3D::_is_last_waypoint() const {

scene/3d/navigation_agent_3d.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,6 @@ class NavigationAgent3D : public Node {
9898
bool target_reached = false;
9999
bool navigation_finished = true;
100100
bool last_waypoint_reached = false;
101-
// No initialized on purpose
102-
uint32_t update_frame_id = 0;
103101

104102
// Debug properties for exposed bindings
105103
bool debug_enabled = false;

0 commit comments

Comments
 (0)