diff options
| author | Pedro J. Estébanez <pedrojrulez@gmail.com> | 2021-08-13 00:38:41 +0200 |
|---|---|---|
| committer | Pedro J. Estébanez <pedrojrulez@gmail.com> | 2021-08-13 11:19:19 +0200 |
| commit | dc187324beded208b8aef77d2e5e0cc1650f4d78 (patch) | |
| tree | 1702509036e22af9b296d0b6b32dba4ac86b520c /core/input/input.cpp | |
| parent | 7c864d41c9aa8c6b1c585175fc997af8070f6b30 (diff) | |
| download | redot-engine-dc187324beded208b8aef77d2e5e0cc1650f4d78.tar.gz | |
Add input buffering framework
Input buffering is implicitly used by event accumulation, but this commit makes it more generic so it can be enabled for other uses.
For desktop OSs it's currently not feasible given main and UI threads are the same).
Diffstat (limited to 'core/input/input.cpp')
| -rw-r--r-- | core/input/input.cpp | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/core/input/input.cpp b/core/input/input.cpp index ffe2659126..8ba8b892ac 100644 --- a/core/input/input.cpp +++ b/core/input/input.cpp @@ -837,32 +837,40 @@ void Input::parse_input_event(const Ref<InputEvent> &p_event) { ERR_FAIL_COND(p_event.is_null()); - if (!use_accumulated_input) { + if (use_accumulated_input) { + if (buffered_events.is_empty() || !buffered_events.back()->get()->accumulate(p_event)) { + buffered_events.push_back(p_event); + } + } else if (use_input_buffering) { + buffered_events.push_back(p_event); + } else { _parse_input_event_impl(p_event, false); - return; } - if (!accumulated_events.is_empty() && accumulated_events.back()->get()->accumulate(p_event)) { - return; //event was accumulated, exit - } - - accumulated_events.push_back(p_event); } -void Input::flush_accumulated_events() { +void Input::flush_buffered_events() { _THREAD_SAFE_METHOD_ - while (accumulated_events.front()) { - _parse_input_event_impl(accumulated_events.front()->get(), false); - accumulated_events.pop_front(); + while (buffered_events.front()) { + _parse_input_event_impl(buffered_events.front()->get(), false); + buffered_events.pop_front(); } } +bool Input::is_using_input_buffering() { + return use_input_buffering; +} + +void Input::set_use_input_buffering(bool p_enable) { + use_input_buffering = p_enable; +} + void Input::set_use_accumulated_input(bool p_enable) { use_accumulated_input = p_enable; } void Input::release_pressed_events() { - flush_accumulated_events(); // this is needed to release actions strengths + flush_buffered_events(); // this is needed to release actions strengths keys_pressed.clear(); joy_buttons_pressed.clear(); |
