From b07960d3bccdcb8d3050774b8502573f98f3455b Mon Sep 17 00:00:00 2001 From: Megamouse Date: Sun, 29 Aug 2021 09:08:31 +0200 Subject: [PATCH] input: move pressure sensitivity to the handlers This removes a data race where the button was kept pressed but the values ingame could vary --- rpcs3/Emu/Io/PadHandler.cpp | 15 ++++++++++++++- rpcs3/Input/evdev_joystick_handler.cpp | 15 ++++++++++++++- rpcs3/Input/pad_thread.cpp | 8 -------- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/rpcs3/Emu/Io/PadHandler.cpp b/rpcs3/Emu/Io/PadHandler.cpp index 381f79eb0f..e9ece45819 100644 --- a/rpcs3/Emu/Io/PadHandler.cpp +++ b/rpcs3/Emu/Io/PadHandler.cpp @@ -552,12 +552,25 @@ void PadHandlerBase::get_mapping(const std::shared_ptr& device, const auto button_values = get_button_values(device); + // Find out if special buttons are pressed (introduced by RPCS3). + // These buttons will have a delay of one cycle, but whatever. + const bool adjust_pressure = pad->m_pressure_intensity_button_index >= 0 && pad->m_buttons[pad->m_pressure_intensity_button_index].m_pressed; + // Translate any corresponding keycodes to our normal DS3 buttons and triggers for (auto& btn : pad->m_buttons) { - Button tmp = btn; // Using a buffer because the values can change during translation + // Using a temporary buffer because the values can change during translation + Button tmp = btn; tmp.m_value = button_values[btn.m_keyCode]; + TranslateButtonPress(device, tmp.m_keyCode, tmp.m_pressed, tmp.m_value); + + // Modify pressure if necessary if the button was pressed + if (adjust_pressure && tmp.m_pressed) + { + tmp.m_value = pad->m_pressure_intensity; + } + btn = tmp; } diff --git a/rpcs3/Input/evdev_joystick_handler.cpp b/rpcs3/Input/evdev_joystick_handler.cpp index 72a85be33f..03000d1e96 100644 --- a/rpcs3/Input/evdev_joystick_handler.cpp +++ b/rpcs3/Input/evdev_joystick_handler.cpp @@ -753,6 +753,10 @@ void evdev_joystick_handler::get_mapping(const std::shared_ptr& devic auto axis_orientations = m_dev->axis_orientations; + // Find out if special buttons are pressed (introduced by RPCS3). + // These buttons will have a delay of one cycle, but whatever. + const bool adjust_pressure = pad->m_pressure_intensity_button_index >= 0 && pad->m_buttons[pad->m_pressure_intensity_button_index].m_pressed; + // Translate any corresponding keycodes to our normal DS3 buttons and triggers for (int i = 0; i < static_cast(pad->m_buttons.size()); i++) { @@ -782,9 +786,18 @@ void evdev_joystick_handler::get_mapping(const std::shared_ptr& devic } } - Button tmp = button; // Using a buffer because the values can change during translation + // Using a temporary buffer because the values can change during translation + Button tmp = button; tmp.m_value = static_cast(value); + TranslateButtonPress(m_dev, button_code, tmp.m_pressed, tmp.m_value); + + // Modify pressure if necessary if the button was pressed + if (adjust_pressure && tmp.m_pressed) + { + tmp.m_value = pad->m_pressure_intensity; + } + button = tmp; } diff --git a/rpcs3/Input/pad_thread.cpp b/rpcs3/Input/pad_thread.cpp index 75d0b07cfb..799979373d 100644 --- a/rpcs3/Input/pad_thread.cpp +++ b/rpcs3/Input/pad_thread.cpp @@ -244,11 +244,8 @@ void pad_thread::ThreadFunc() { const auto& pad = m_pads[i]; - // I guess this is the best place to add pressure sensitivity without too much code duplication. if (pad->m_port_status & CELL_PAD_STATUS_CONNECTED) { - const bool adjust_pressure = pad->m_pressure_intensity_button_index >= 0 && pad->m_buttons[pad->m_pressure_intensity_button_index].m_pressed; - for (auto& button : pad->m_buttons) { if (button.m_pressed) @@ -262,11 +259,6 @@ void pad_thread::ThreadFunc() { any_button_pressed = true; } - - if (adjust_pressure) - { - button.m_value = pad->m_pressure_intensity; - } } } }