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.
This commit is contained in:
@ -315,10 +315,6 @@ Vector3 InputDefault::get_gyroscope() const {
|
||||
return gyroscope;
|
||||
}
|
||||
|
||||
void InputDefault::parse_input_event(const Ref<InputEvent> &p_event) {
|
||||
_parse_input_event_impl(p_event, false);
|
||||
}
|
||||
|
||||
void InputDefault::_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
|
||||
@ -327,8 +323,6 @@ void InputDefault::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool
|
||||
// - 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_scancode() != 0) {
|
||||
if (k->is_pressed()) {
|
||||
@ -697,11 +691,13 @@ void InputDefault::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_sh
|
||||
OS::get_singleton()->set_custom_mouse_cursor(p_cursor, (OS::CursorShape)p_shape, p_hotspot);
|
||||
}
|
||||
|
||||
void InputDefault::accumulate_input_event(const Ref<InputEvent> &p_event) {
|
||||
void InputDefault::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.empty() && accumulated_events.back()->get()->accumulate(p_event)) {
|
||||
@ -711,8 +707,10 @@ void InputDefault::accumulate_input_event(const Ref<InputEvent> &p_event) {
|
||||
accumulated_events.push_back(p_event);
|
||||
}
|
||||
void InputDefault::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();
|
||||
}
|
||||
}
|
||||
@ -736,7 +734,7 @@ void InputDefault::release_pressed_events() {
|
||||
}
|
||||
|
||||
InputDefault::InputDefault() {
|
||||
use_accumulated_input = true;
|
||||
use_accumulated_input = false;
|
||||
mouse_button_mask = 0;
|
||||
emulate_touch_from_mouse = false;
|
||||
emulate_mouse_from_touch = false;
|
||||
|
||||
Reference in New Issue
Block a user