From 977d729ee050693a68678f29dcd8b9859d156059 Mon Sep 17 00:00:00 2001 From: Megamouse Date: Sun, 29 Aug 2021 08:56:22 +0200 Subject: [PATCH] input: use buffers during button translation This should reduce some random noise by assgning the values once instead of twice --- rpcs3/Emu/Io/PadHandler.cpp | 6 ++++-- rpcs3/Input/evdev_joystick_handler.cpp | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/rpcs3/Emu/Io/PadHandler.cpp b/rpcs3/Emu/Io/PadHandler.cpp index 7069428852..381f79eb0f 100644 --- a/rpcs3/Emu/Io/PadHandler.cpp +++ b/rpcs3/Emu/Io/PadHandler.cpp @@ -555,8 +555,10 @@ void PadHandlerBase::get_mapping(const std::shared_ptr& device, const // Translate any corresponding keycodes to our normal DS3 buttons and triggers for (auto& btn : pad->m_buttons) { - btn.m_value = button_values[btn.m_keyCode]; - TranslateButtonPress(device, btn.m_keyCode, btn.m_pressed, btn.m_value); + Button tmp = btn; // Using a buffer because the values can change during translation + tmp.m_value = button_values[btn.m_keyCode]; + TranslateButtonPress(device, tmp.m_keyCode, tmp.m_pressed, tmp.m_value); + btn = tmp; } // used to get the absolute value of an axis diff --git a/rpcs3/Input/evdev_joystick_handler.cpp b/rpcs3/Input/evdev_joystick_handler.cpp index a4130e3c8d..72a85be33f 100644 --- a/rpcs3/Input/evdev_joystick_handler.cpp +++ b/rpcs3/Input/evdev_joystick_handler.cpp @@ -782,8 +782,10 @@ void evdev_joystick_handler::get_mapping(const std::shared_ptr& devic } } - button.m_value = static_cast(value); - TranslateButtonPress(m_dev, button_code, button.m_pressed, button.m_value); + Button tmp = button; // Using a buffer because the values can change during translation + tmp.m_value = static_cast(value); + TranslateButtonPress(m_dev, button_code, tmp.m_pressed, tmp.m_value); + button = tmp; } // Translate any corresponding keycodes to our two sticks. (ignoring thresholds for now)