diff options
author | kobewi <kobewi4e@gmail.com> | 2023-08-30 17:17:30 +0200 |
---|---|---|
committer | kobewi <kobewi4e@gmail.com> | 2023-09-04 15:47:26 +0200 |
commit | a490fad82d5fc772174b4363092923f00b11f7a6 (patch) | |
tree | 51ada5697ea05521eeb4fdb779ffed17b835e9e2 /core/input/input.cpp | |
parent | 75de1ca76871fdf7f5a9e081aa57ec0e33061107 (diff) | |
download | redot-engine-a490fad82d5fc772174b4363092923f00b11f7a6.tar.gz |
Prevent axis-based actions from getting stuck
Diffstat (limited to 'core/input/input.cpp')
-rw-r--r-- | core/input/input.cpp | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/core/input/input.cpp b/core/input/input.cpp index e89c71d762..19ea8c7317 100644 --- a/core/input/input.cpp +++ b/core/input/input.cpp @@ -701,18 +701,39 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em if (!p_event->is_echo()) { if (p_event->is_action_pressed(E.key)) { - action.pressed++; + if (jm.is_valid()) { + // If axis is already pressed, don't increase the pressed counter. + if (!action.axis_pressed) { + action.pressed++; + action.axis_pressed = true; + } + } else { + action.pressed++; + } + is_pressed = true; if (action.pressed == 1) { action.pressed_physics_frame = Engine::get_singleton()->get_physics_frames(); action.pressed_process_frame = Engine::get_singleton()->get_process_frames(); } } else { - if (action.pressed == 1) { - action.released_physics_frame = Engine::get_singleton()->get_physics_frames(); - action.released_process_frame = Engine::get_singleton()->get_process_frames(); + bool is_released = true; + if (jm.is_valid()) { + // Same as above. Don't release axis when not pressed. + if (action.axis_pressed) { + action.axis_pressed = false; + } else { + is_released = false; + } + } + + if (is_released) { + if (action.pressed == 1) { + action.released_physics_frame = Engine::get_singleton()->get_physics_frames(); + action.released_process_frame = Engine::get_singleton()->get_process_frames(); + } + action.pressed = MAX(action.pressed - 1, 0); } - action.pressed = MAX(action.pressed - 1, 0); } action.exact = InputMap::get_singleton()->event_is_action(p_event, E.key, true); } |