summaryrefslogtreecommitdiff
path: root/core/input/input.cpp
diff options
context:
space:
mode:
authorPedro J. Estébanez <pedrojrulez@gmail.com>2021-08-13 00:31:16 +0200
committerPedro J. Estébanez <pedrojrulez@gmail.com>2021-08-13 11:19:19 +0200
commit7c864d41c9aa8c6b1c585175fc997af8070f6b30 (patch)
tree03ee430a5d2787190969291619bfa7af1063fd52 /core/input/input.cpp
parent39efccf3b8298e30aa67a726ffd8752b3dff4c66 (diff)
Improve input event accumulation
- API has been simplified: all events now go through `parse_input_event()`. Whether they are accumulated or not depends on the `use_accumulated_input` flag. - Event accumulation is now thread-safe (it was not needed so far, but it prepares the ground for the following changes). - Touch drag events now support accumulation.
Diffstat (limited to 'core/input/input.cpp')
-rw-r--r--core/input/input.cpp16
1 files changed, 7 insertions, 9 deletions
diff --git a/core/input/input.cpp b/core/input/input.cpp
index 2da50b7dff..ffe2659126 100644
--- a/core/input/input.cpp
+++ b/core/input/input.cpp
@@ -460,10 +460,6 @@ Vector3 Input::get_gyroscope() const {
return gyroscope;
}
-void Input::parse_input_event(const Ref<InputEvent> &p_event) {
- _parse_input_event_impl(p_event, false);
-}
-
void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_emulated) {
// Notes on mouse-touch emulation:
// - Emulated mouse events are parsed, that is, re-routed to this method, so they make the same effects
@@ -472,8 +468,6 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em
// - Emulated touch events are handed right to the main loop (i.e., the SceneTree) because they don't
// require additional handling by this class.
- _THREAD_SAFE_METHOD_
-
Ref<InputEventKey> k = p_event;
if (k.is_valid() && !k->is_echo() && k->get_keycode() != 0) {
if (k->is_pressed()) {
@@ -838,11 +832,13 @@ void Input::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, co
set_custom_mouse_cursor_func(p_cursor, p_shape, p_hotspot);
}
-void Input::accumulate_input_event(const Ref<InputEvent> &p_event) {
+void Input::parse_input_event(const Ref<InputEvent> &p_event) {
+ _THREAD_SAFE_METHOD_
+
ERR_FAIL_COND(p_event.is_null());
if (!use_accumulated_input) {
- parse_input_event(p_event);
+ _parse_input_event_impl(p_event, false);
return;
}
if (!accumulated_events.is_empty() && accumulated_events.back()->get()->accumulate(p_event)) {
@@ -853,8 +849,10 @@ void Input::accumulate_input_event(const Ref<InputEvent> &p_event) {
}
void Input::flush_accumulated_events() {
+ _THREAD_SAFE_METHOD_
+
while (accumulated_events.front()) {
- parse_input_event(accumulated_events.front()->get());
+ _parse_input_event_impl(accumulated_events.front()->get(), false);
accumulated_events.pop_front();
}
}