Fix physics tick counter

The counter is now incremented at the start of a physics tick rather than the end.
This commit is contained in:
lawnjelly 2024-06-09 15:34:23 +01:00 committed by Relintai
parent 131880d444
commit 21f913be43
5 changed files with 8 additions and 7 deletions

View File

@ -512,13 +512,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();
}

View File

@ -2421,6 +2421,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();
@ -2461,7 +2462,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;
}

View File

@ -99,7 +99,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;
} _interpolation_data;
protected:

View File

@ -308,7 +308,7 @@ NavigationAgent2D::NavigationAgent2D() {
target_position_submitted = false;
nav_path_index = 0;
update_frame_id = 0;
update_frame_id = UINT32_MAX;
agent = Navigation2DServer::get_singleton()->agent_create();
@ -955,4 +955,4 @@ void NavigationAgent2D::_update_debug_path() {
RenderingServer::get_singleton()->canvas_item_add_rect(debug_path_instance, path_point_rect, debug_path_color);
}
}
#endif // DEBUG_ENABLED
#endif // DEBUG_ENABLED

View File

@ -93,7 +93,7 @@ class NavigationAgent2D : public Node {
bool target_reached;
bool navigation_finished;
// No initialized on purpose
uint32_t update_frame_id;
bool debug_enabled;