From 4d9533ea54b43b339ce5d4810aa8643eb8202605 Mon Sep 17 00:00:00 2001 From: Megamouse Date: Sun, 12 Jul 2020 19:30:45 +0200 Subject: [PATCH] input: use left and right squircle values --- rpcs3/Emu/Io/PadHandler.cpp | 26 ++++++++++++++++---------- rpcs3/Emu/Io/PadHandler.h | 7 ++++--- rpcs3/Emu/Io/pad_config.h | 3 ++- rpcs3/Input/ds3_pad_handler.cpp | 7 ++++--- rpcs3/Input/ds4_pad_handler.cpp | 3 ++- rpcs3/Input/evdev_joystick_handler.cpp | 16 +++++----------- rpcs3/Input/mm_joystick_handler.cpp | 3 ++- rpcs3/Input/xinput_pad_handler.cpp | 3 ++- 8 files changed, 37 insertions(+), 31 deletions(-) diff --git a/rpcs3/Emu/Io/PadHandler.cpp b/rpcs3/Emu/Io/PadHandler.cpp index 5d8685afcc..262f4b9d3a 100644 --- a/rpcs3/Emu/Io/PadHandler.cpp +++ b/rpcs3/Emu/Io/PadHandler.cpp @@ -172,7 +172,7 @@ u16 PadHandlerBase::NormalizeStickInput(u16 raw_value, int threshold, int multip // This function normalizes stick deadzone based on the DS3's deadzone, which is ~13% // X and Y is expected to be in (-255) to 255 range, deadzone should be in terms of thumb stick range // return is new x and y values in 0-255 range -std::tuple PadHandlerBase::NormalizeStickDeadzone(s32 inX, s32 inY, u32 deadzone) +std::tuple PadHandlerBase::NormalizeStickDeadzone(s32 inX, s32 inY, u32 deadzone) const { const float dz_range = deadzone / static_cast(std::abs(thumb_max)); // NOTE: thumb_max should be positive anyway @@ -388,6 +388,18 @@ void PadHandlerBase::get_next_button_press(const std::string& pad_id, const pad_ return; } +void PadHandlerBase::convert_stick_values(u16& x_out, u16& y_out, const s32& x_in, const s32& y_in, const s32& deadzone, const s32& padsquircling) const +{ + // Normalize our stick axis based on the deadzone + std::tie(x_out, y_out) = NormalizeStickDeadzone(x_in, y_in, deadzone); + + // Apply pad squircling if necessary + if (padsquircling != 0) + { + std::tie(x_out, y_out) = ConvertToSquirclePoint(x_out, y_out, padsquircling); + } +} + // Update the pad button values based on their type and thresholds. With this you can use axis or triggers as buttons or vice versa void PadHandlerBase::TranslateButtonPress(const std::shared_ptr& device, u64 keyCode, bool& pressed, u16& val, bool ignore_stick_threshold, bool ignore_trigger_threshold) { @@ -568,15 +580,9 @@ void PadHandlerBase::get_mapping(const std::shared_ptr& device, const u16 lx, ly, rx, ry; - // Normalize our two stick's axis based on the thresholds - std::tie(lx, ly) = NormalizeStickDeadzone(stick_val[0], stick_val[1], profile->lstickdeadzone); - std::tie(rx, ry) = NormalizeStickDeadzone(stick_val[2], stick_val[3], profile->rstickdeadzone); - - if (profile->padsquircling != 0) - { - std::tie(lx, ly) = ConvertToSquirclePoint(lx, ly, profile->padsquircling); - std::tie(rx, ry) = ConvertToSquirclePoint(rx, ry, profile->padsquircling); - } + // Normalize and apply pad squircling + convert_stick_values(lx, ly, stick_val[0], stick_val[1], profile->lstickdeadzone, profile->lpadsquircling); + convert_stick_values(rx, ry, stick_val[2], stick_val[3], profile->rstickdeadzone, profile->rpadsquircling); if (m_type == pad_handler::ds4) { diff --git a/rpcs3/Emu/Io/PadHandler.h b/rpcs3/Emu/Io/PadHandler.h index f451d7dafe..401fd03796 100644 --- a/rpcs3/Emu/Io/PadHandler.h +++ b/rpcs3/Emu/Io/PadHandler.h @@ -101,12 +101,10 @@ protected: // the input values must lie in 0+ u16 NormalizeDirectedInput(s32 raw_value, s32 threshold, s32 maximum) const; - u16 NormalizeStickInput(u16 raw_value, int threshold, int multiplier, bool ignore_threshold = false) const; - // This function normalizes stick deadzone based on the DS3's deadzone, which is ~13% // X and Y is expected to be in (-255) to 255 range, deadzone should be in terms of thumb stick range // return is new x and y values in 0-255 range - std::tuple NormalizeStickDeadzone(s32 inX, s32 inY, u32 deadzone); + std::tuple NormalizeStickDeadzone(s32 inX, s32 inY, u32 deadzone) const; // get clamped value between 0 and 255 static u16 Clamp0To255(f32 input); @@ -144,6 +142,9 @@ public: static std::string get_config_dir(pad_handler type, const std::string& title_id = ""); static std::string get_config_filename(int i, const std::string& title_id = ""); + u16 NormalizeStickInput(u16 raw_value, int threshold, int multiplier, bool ignore_threshold = false) const; + void convert_stick_values(u16& x_out, u16& y_out, const s32& x_in, const s32& y_in, const s32& deadzone, const s32& padsquircling) const; + virtual bool Init() { return true; } PadHandlerBase(pad_handler type = pad_handler::null); virtual ~PadHandlerBase() = default; diff --git a/rpcs3/Emu/Io/pad_config.h b/rpcs3/Emu/Io/pad_config.h index eab99d5aaf..104636cc2d 100644 --- a/rpcs3/Emu/Io/pad_config.h +++ b/rpcs3/Emu/Io/pad_config.h @@ -69,7 +69,8 @@ struct pad_config final : cfg::node cfg::_int<0, 1000000> rstickdeadzone{ this, "Right Stick Deadzone", 0 }; cfg::_int<0, 1000000> ltriggerthreshold{ this, "Left Trigger Threshold", 0 }; cfg::_int<0, 1000000> rtriggerthreshold{ this, "Right Trigger Threshold", 0 }; - cfg::_int<0, 1000000> padsquircling{ this, "Pad Squircling Factor", 0 }; + cfg::_int<0, 1000000> lpadsquircling{ this, "Left Pad Squircling Factor", 0 }; + cfg::_int<0, 1000000> rpadsquircling{ this, "Right Pad Squircling Factor", 0 }; cfg::_int<0, 255> colorR{ this, "Color Value R", 0 }; cfg::_int<0, 255> colorG{ this, "Color Value G", 0 }; diff --git a/rpcs3/Input/ds3_pad_handler.cpp b/rpcs3/Input/ds3_pad_handler.cpp index c51e696d63..b0e710e08c 100644 --- a/rpcs3/Input/ds3_pad_handler.cpp +++ b/rpcs3/Input/ds3_pad_handler.cpp @@ -262,11 +262,12 @@ void ds3_pad_handler::init_config(pad_config* cfg, const std::string& name) cfg->l3.def = button_list.at(DS3KeyCodes::L3); // Set default misc variables - cfg->lstickdeadzone.def = 40; // between 0 and 255 - cfg->rstickdeadzone.def = 40; // between 0 and 255 + cfg->lstickdeadzone.def = 40; // between 0 and 255 + cfg->rstickdeadzone.def = 40; // between 0 and 255 cfg->ltriggerthreshold.def = 0; // between 0 and 255 cfg->rtriggerthreshold.def = 0; // between 0 and 255 - cfg->padsquircling.def = 0; + cfg->lpadsquircling.def = 0; + cfg->rpadsquircling.def = 0; // Set color value cfg->colorR.def = 0; diff --git a/rpcs3/Input/ds4_pad_handler.cpp b/rpcs3/Input/ds4_pad_handler.cpp index f71dd2a735..522c1c02e4 100644 --- a/rpcs3/Input/ds4_pad_handler.cpp +++ b/rpcs3/Input/ds4_pad_handler.cpp @@ -171,7 +171,8 @@ void ds4_pad_handler::init_config(pad_config* cfg, const std::string& name) cfg->rstickdeadzone.def = 40; // between 0 and 255 cfg->ltriggerthreshold.def = 0; // between 0 and 255 cfg->rtriggerthreshold.def = 0; // between 0 and 255 - cfg->padsquircling.def = 8000; + cfg->lpadsquircling.def = 8000; + cfg->rpadsquircling.def = 8000; // Set default color value cfg->colorR.def = 0; diff --git a/rpcs3/Input/evdev_joystick_handler.cpp b/rpcs3/Input/evdev_joystick_handler.cpp index a44d6a0bf5..ee5f461c27 100644 --- a/rpcs3/Input/evdev_joystick_handler.cpp +++ b/rpcs3/Input/evdev_joystick_handler.cpp @@ -84,7 +84,8 @@ void evdev_joystick_handler::init_config(pad_config* cfg, const std::string& nam cfg->rstickdeadzone.def = 30; // between 0 and 255 cfg->ltriggerthreshold.def = 0; // between 0 and 255 cfg->rtriggerthreshold.def = 0; // between 0 and 255 - cfg->padsquircling.def = 5000; + cfg->lpadsquircling.def = 5000; + cfg->rpadsquircling.def = 5000; // apply defaults cfg->from_default(); @@ -830,18 +831,11 @@ void evdev_joystick_handler::get_mapping(const std::shared_ptr& devic const auto profile = m_dev->config; - // Normalize our two stick's axis based on the thresholds u16 lx, ly, rx, ry; - // Normalize our two stick's axis based on the thresholds - std::tie(lx, ly) = NormalizeStickDeadzone(m_dev->stick_val[0], m_dev->stick_val[1], profile->lstickdeadzone); - std::tie(rx, ry) = NormalizeStickDeadzone(m_dev->stick_val[2], m_dev->stick_val[3], profile->rstickdeadzone); - - if (profile->padsquircling != 0) - { - std::tie(lx, ly) = ConvertToSquirclePoint(lx, ly, profile->padsquircling); - std::tie(rx, ry) = ConvertToSquirclePoint(rx, ry, profile->padsquircling); - } + // Normalize and apply pad squircling + convert_stick_values(lx, ly, m_dev->stick_val[0], m_dev->stick_val[1], profile->lstickdeadzone, profile->lpadsquircling); + convert_stick_values(rx, ry, m_dev->stick_val[2], m_dev->stick_val[3], profile->rstickdeadzone, profile->rpadsquircling); pad->m_sticks[0].m_value = lx; pad->m_sticks[1].m_value = 255 - ly; diff --git a/rpcs3/Input/mm_joystick_handler.cpp b/rpcs3/Input/mm_joystick_handler.cpp index 9c6e144b7a..d6f22bc26c 100644 --- a/rpcs3/Input/mm_joystick_handler.cpp +++ b/rpcs3/Input/mm_joystick_handler.cpp @@ -67,7 +67,8 @@ void mm_joystick_handler::init_config(pad_config* cfg, const std::string& name) cfg->rstickdeadzone.def = 0; // between 0 and 255 cfg->ltriggerthreshold.def = 0; // between 0 and 255 cfg->rtriggerthreshold.def = 0; // between 0 and 255 - cfg->padsquircling.def = 8000; + cfg->lpadsquircling.def = 8000; + cfg->rpadsquircling.def = 8000; // apply defaults cfg->from_default(); diff --git a/rpcs3/Input/xinput_pad_handler.cpp b/rpcs3/Input/xinput_pad_handler.cpp index bd8c8969e0..b85c4433e5 100644 --- a/rpcs3/Input/xinput_pad_handler.cpp +++ b/rpcs3/Input/xinput_pad_handler.cpp @@ -117,7 +117,8 @@ void xinput_pad_handler::init_config(pad_config* cfg, const std::string& name) cfg->rstickdeadzone.def = XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE; // between 0 and 32767 cfg->ltriggerthreshold.def = XINPUT_GAMEPAD_TRIGGER_THRESHOLD; // between 0 and 255 cfg->rtriggerthreshold.def = XINPUT_GAMEPAD_TRIGGER_THRESHOLD; // between 0 and 255 - cfg->padsquircling.def = 8000; + cfg->lpadsquircling.def = 8000; + cfg->rpadsquircling.def = 8000; // apply defaults cfg->from_default();