Skip to content

Commit

Permalink
Merge pull request godotengine#92941 from lawnjelly/fix_physics_tickc…
Browse files Browse the repository at this point in the history
…ounter

[3.x] Fix physics tick counter
  • Loading branch information
lawnjelly authored Jul 1, 2024
2 parents f137eb3 + 40961d6 commit 98e2483
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions main/input_default.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,13 +506,14 @@ void InputDefault::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool

// If not echo and action pressed state has changed
if (!p_event->is_echo() && is_action_pressed(E->key(), false) != p_event->is_action_pressed(E->key())) {
// As input may come in part way through a physics tick, the earliest we can react to it is the next physics tick.
if (p_event->is_action_pressed(E->key())) {
action.pressed = true;
action.pressed_physics_frame = Engine::get_singleton()->get_physics_frames();
action.pressed_physics_frame = Engine::get_singleton()->get_physics_frames() + 1;
action.pressed_idle_frame = Engine::get_singleton()->get_idle_frames();
} else {
action.pressed = false;
action.released_physics_frame = Engine::get_singleton()->get_physics_frames();
action.released_physics_frame = Engine::get_singleton()->get_physics_frames() + 1;
action.released_idle_frame = Engine::get_singleton()->get_idle_frames();
}
action.strength = 0.0f;
Expand Down
2 changes: 1 addition & 1 deletion main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2364,6 +2364,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();

Expand Down Expand Up @@ -2398,7 +2399,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;
}
Expand Down
2 changes: 1 addition & 1 deletion scene/2d/camera_2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class Camera2D : public Node2D {
struct InterpolationData {
Transform2D xform_curr;
Transform2D xform_prev;
uint32_t last_update_physics_tick = 0;
uint32_t last_update_physics_tick = UINT32_MAX;
} _interpolation_data;

protected:
Expand Down
2 changes: 1 addition & 1 deletion scene/2d/navigation_agent_2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class NavigationAgent2D : public Node {
bool target_reached = false;
bool navigation_finished = true;
// No initialized on purpose
uint32_t update_frame_id = 0;
uint32_t update_frame_id = UINT32_MAX;

protected:
static void _bind_methods();
Expand Down

0 comments on commit 98e2483

Please sign in to comment.