From e5a526e4d6b41050e9245e9e6a5377af4a5751ea Mon Sep 17 00:00:00 2001 From: Megamouse Date: Sun, 8 Sep 2024 20:03:14 +0200 Subject: [PATCH] input: enable squircle settings in keyboard pad handler Clamp squircled values to radius 1. Also set kb and evdev default to 8000 as the others --- rpcs3/Emu/Io/PadHandler.cpp | 26 +- rpcs3/Emu/Io/PadHandler.h | 3 +- rpcs3/Emu/Io/pad_config.h | 4 +- rpcs3/Input/evdev_joystick_handler.cpp | 4 +- rpcs3/Input/keyboard_pad_handler.cpp | 35 ++- rpcs3/rpcs3qt/pad_settings_dialog.cpp | 19 +- rpcs3/rpcs3qt/pad_settings_dialog.ui | 386 ++++++++++--------------- 7 files changed, 211 insertions(+), 266 deletions(-) diff --git a/rpcs3/Emu/Io/PadHandler.cpp b/rpcs3/Emu/Io/PadHandler.cpp index ce1bf81abe..1667aa3b1d 100644 --- a/rpcs3/Emu/Io/PadHandler.cpp +++ b/rpcs3/Emu/Io/PadHandler.cpp @@ -172,24 +172,28 @@ u16 PadHandlerBase::ConvertAxis(f32 value) // using a simple scale/sensitivity increase would *work* although it eats a chunk of our usable range in exchange // this might be the best for now, in practice it seems to push the corners to max of 20x20, with a squircle_factor of 8000 // This function assumes inX and inY is already in 0-255 -std::tuple PadHandlerBase::ConvertToSquirclePoint(u16 inX, u16 inY, u32 squircle_factor) +void PadHandlerBase::ConvertToSquirclePoint(u16& inX, u16& inY, u32 squircle_factor) { - // convert inX and Y to a (-1, 1) vector; - const f32 x = (inX - 127.5f) / 127.5f; - const f32 y = (inY - 127.5f) / 127.5f; + if (!squircle_factor) + return; - // compute angle and len of given point to be used for squircle radius + constexpr f32 radius = 127.5f; + + // convert inX and Y to a (-1, 1) vector; + const f32 x = (inX - radius) / radius; + const f32 y = (inY - radius) / radius; + + // compute angle and len of given point to be used for squircle radius. Clamp to circle, we don't want to exceed the squircle. const f32 angle = std::atan2(y, x); - const f32 r = std::sqrt(std::pow(x, 2.f) + std::pow(y, 2.f)); + const f32 distance_to_center = std::min(1.0f, std::sqrt(std::pow(x, 2.f) + std::pow(y, 2.f))); // now find len/point on the given squircle from our current angle and radius in polar coords // https://thatsmaths.com/2016/07/14/squircles/ - const f32 newLen = (1 + std::pow(std::sin(2 * angle), 2.f) / (squircle_factor / 1000.f)) * r; + const f32 new_len = (1 + std::pow(std::sin(2 * angle), 2.f) / (squircle_factor / 1000.f)) * distance_to_center; // we now have len and angle, convert to cartesian - const int newX = Clamp0To255(std::round(((newLen * std::cos(angle)) + 1) * 127.5f)); - const int newY = Clamp0To255(std::round(((newLen * std::sin(angle)) + 1) * 127.5f)); - return std::tuple(newX, newY); + inX = Clamp0To255(std::round(((new_len * std::cos(angle)) + 1) * radius)); + inY = Clamp0To255(std::round(((new_len * std::sin(angle)) + 1) * radius)); } void PadHandlerBase::init_configs() @@ -366,7 +370,7 @@ void PadHandlerBase::convert_stick_values(u16& x_out, u16& y_out, s32 x_in, s32 // Apply pad squircling if necessary if (padsquircling != 0) { - std::tie(x_out, y_out) = ConvertToSquirclePoint(x_out, y_out, padsquircling); + ConvertToSquirclePoint(x_out, y_out, padsquircling); } } diff --git a/rpcs3/Emu/Io/PadHandler.h b/rpcs3/Emu/Io/PadHandler.h index 8c6010cc62..d7811a0dcb 100644 --- a/rpcs3/Emu/Io/PadHandler.h +++ b/rpcs3/Emu/Io/PadHandler.h @@ -245,6 +245,7 @@ protected: // get clamped value between 0 and 255 static u16 Clamp0To255(f32 input); + // get clamped value between 0 and 1023 static u16 Clamp0To1023(f32 input); @@ -255,7 +256,7 @@ protected: // using a simple scale/sensitivity increase would *work* although it eats a chunk of our usable range in exchange // this might be the best for now, in practice it seems to push the corners to max of 20x20, with a squircle_factor of 8000 // This function assumes inX and inY is already in 0-255 - static std::tuple ConvertToSquirclePoint(u16 inX, u16 inY, u32 squircle_factor); + static void ConvertToSquirclePoint(u16& inX, u16& inY, u32 squircle_factor); public: // u32 thumb_min = 0; // Unused. Make sure all handlers report 0+ values for sticks in get_button_values. diff --git a/rpcs3/Emu/Io/pad_config.h b/rpcs3/Emu/Io/pad_config.h index f27228ccf0..662280d7b2 100644 --- a/rpcs3/Emu/Io/pad_config.h +++ b/rpcs3/Emu/Io/pad_config.h @@ -81,8 +81,8 @@ struct cfg_pad final : cfg::node cfg::uint<0, 1000000> rstick_anti_deadzone{ this, "Right Stick Anti-Deadzone", 0 }; cfg::uint<0, 1000000> ltriggerthreshold{ this, "Left Trigger Threshold", 0 }; cfg::uint<0, 1000000> rtriggerthreshold{ this, "Right Trigger Threshold", 0 }; - cfg::uint<0, 1000000> lpadsquircling{ this, "Left Pad Squircling Factor", 0 }; - cfg::uint<0, 1000000> rpadsquircling{ this, "Right Pad Squircling Factor", 0 }; + cfg::uint<0, 1000000> lpadsquircling{ this, "Left Pad Squircling Factor", 8000 }; + cfg::uint<0, 1000000> rpadsquircling{ this, "Right Pad Squircling Factor", 8000 }; cfg::uint<0, 255> colorR{ this, "Color Value R", 0 }; cfg::uint<0, 255> colorG{ this, "Color Value G", 0 }; diff --git a/rpcs3/Input/evdev_joystick_handler.cpp b/rpcs3/Input/evdev_joystick_handler.cpp index d885fd30fa..b3cf313df3 100644 --- a/rpcs3/Input/evdev_joystick_handler.cpp +++ b/rpcs3/Input/evdev_joystick_handler.cpp @@ -92,8 +92,8 @@ void evdev_joystick_handler::init_config(cfg_pad* cfg) 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->lpadsquircling.def = 5000; - cfg->rpadsquircling.def = 5000; + cfg->lpadsquircling.def = 8000; + cfg->rpadsquircling.def = 8000; // apply defaults cfg->from_default(); diff --git a/rpcs3/Input/keyboard_pad_handler.cpp b/rpcs3/Input/keyboard_pad_handler.cpp index 8ed2aa88d4..926c355f38 100644 --- a/rpcs3/Input/keyboard_pad_handler.cpp +++ b/rpcs3/Input/keyboard_pad_handler.cpp @@ -68,8 +68,8 @@ void keyboard_pad_handler::init_config(cfg_pad* cfg) cfg->rstickdeadzone.def = 0; cfg->ltriggerthreshold.def = 0; cfg->rtriggerthreshold.def = 0; - cfg->lpadsquircling.def = 0; - cfg->rpadsquircling.def = 0; + cfg->lpadsquircling.def = 8000; + cfg->rpadsquircling.def = 8000; // apply defaults cfg->from_default(); @@ -1277,7 +1277,34 @@ void keyboard_pad_handler::process() { auto& pad = m_bindings[i].pad; ensure(pad); - pad->m_buttons = m_pads_internal[i].m_buttons; - pad->m_sticks = m_pads_internal[i].m_sticks; + + const cfg_pad* cfg = &m_pad_configs[pad->m_player_id]; + ensure(cfg); + + const Pad& pad_internal = m_pads_internal[i]; + + // Normalize and apply pad squircling + // Copy sticks first. We don't want to modify the raw internal values + std::vector squircled_sticks = pad_internal.m_sticks; + + // Apply squircling + if (cfg->lpadsquircling != 0) + { + u16& lx = squircled_sticks[0].m_value; + u16& ly = squircled_sticks[1].m_value; + + ConvertToSquirclePoint(lx, ly, cfg->lpadsquircling); + } + + if (cfg->rpadsquircling != 0) + { + u16& rx = squircled_sticks[2].m_value; + u16& ry = squircled_sticks[3].m_value; + + ConvertToSquirclePoint(rx, ry, cfg->rpadsquircling); + } + + pad->m_buttons = pad_internal.m_buttons; + pad->m_sticks = std::move(squircled_sticks); } } diff --git a/rpcs3/rpcs3qt/pad_settings_dialog.cpp b/rpcs3/rpcs3qt/pad_settings_dialog.cpp index 16f7771199..8676c36506 100644 --- a/rpcs3/rpcs3qt/pad_settings_dialog.cpp +++ b/rpcs3/rpcs3qt/pad_settings_dialog.cpp @@ -1177,14 +1177,10 @@ void pad_settings_dialog::UpdateLabels(bool is_reset) range = cfg.lstickmultiplier.to_list(); ui->stick_multi_left->setRange(std::stod(range.front()) / 100.0, std::stod(range.back()) / 100.0); ui->stick_multi_left->setValue(cfg.lstickmultiplier / 100.0); - ui->kb_stick_multi_left->setRange(std::stod(range.front()) / 100.0, std::stod(range.back()) / 100.0); - ui->kb_stick_multi_left->setValue(cfg.lstickmultiplier / 100.0); range = cfg.rstickmultiplier.to_list(); ui->stick_multi_right->setRange(std::stod(range.front()) / 100.0, std::stod(range.back()) / 100.0); ui->stick_multi_right->setValue(cfg.rstickmultiplier / 100.0); - ui->kb_stick_multi_right->setRange(std::stod(range.front()) / 100.0, std::stod(range.back()) / 100.0); - ui->kb_stick_multi_right->setValue(cfg.rstickmultiplier / 100.0); // Update Squircle Factors range = cfg.lpadsquircling.to_list(); @@ -1247,8 +1243,6 @@ void pad_settings_dialog::SwitchButtons(bool is_enabled) ui->chb_show_emulated_values->setEnabled(is_enabled); ui->stick_multi_left->setEnabled(is_enabled); ui->stick_multi_right->setEnabled(is_enabled); - ui->kb_stick_multi_left->setEnabled(is_enabled); - ui->kb_stick_multi_right->setEnabled(is_enabled); ui->squircle_left->setEnabled(is_enabled); ui->squircle_right->setEnabled(is_enabled); ui->gb_pressure_intensity_deadzone->setEnabled(is_enabled); @@ -1855,16 +1849,8 @@ void pad_settings_dialog::ApplyCurrentPlayerConfig(int new_player_id) // Apply rest of config auto& cfg = player->config; - if (m_handler->m_type == pad_handler::keyboard) - { - cfg.lstickmultiplier.set(ui->kb_stick_multi_left->value() * 100); - cfg.rstickmultiplier.set(ui->kb_stick_multi_right->value() * 100); - } - else - { - cfg.lstickmultiplier.set(ui->stick_multi_left->value() * 100); - cfg.rstickmultiplier.set(ui->stick_multi_right->value() * 100); - } + cfg.lstickmultiplier.set(ui->stick_multi_left->value() * 100); + cfg.rstickmultiplier.set(ui->stick_multi_right->value() * 100); cfg.lpadsquircling.set(ui->squircle_left->value()); cfg.rpadsquircling.set(ui->squircle_right->value()); @@ -2091,7 +2077,6 @@ void pad_settings_dialog::SubscribeTooltips() SubscribeTooltip(ui->gb_pressure_intensity_deadzone, tooltips.gamepad_settings.pressure_deadzone); SubscribeTooltip(ui->gb_squircle, tooltips.gamepad_settings.squircle_factor); SubscribeTooltip(ui->gb_stick_multi, tooltips.gamepad_settings.stick_multiplier); - SubscribeTooltip(ui->gb_kb_stick_multi, tooltips.gamepad_settings.stick_multiplier); SubscribeTooltip(ui->gb_vibration, tooltips.gamepad_settings.vibration); SubscribeTooltip(ui->gb_motion_controls, tooltips.gamepad_settings.motion_controls); SubscribeTooltip(ui->gb_stick_deadzones, tooltips.gamepad_settings.stick_deadzones); diff --git a/rpcs3/rpcs3qt/pad_settings_dialog.ui b/rpcs3/rpcs3qt/pad_settings_dialog.ui index 94f78f01b7..86add99c28 100644 --- a/rpcs3/rpcs3qt/pad_settings_dialog.ui +++ b/rpcs3/rpcs3qt/pad_settings_dialog.ui @@ -2248,10 +2248,166 @@ + + + + Squircle Values + + + + 5 + + + 5 + + + 5 + + + 5 + + + + + Left + + + + + + + 1000000 + + + 1000 + + + + + + + Qt::Horizontal + + + + 0 + 0 + + + + + + + + Right + + + + + + + 1000000 + + + 1000 + + + + + + + Qt::Horizontal + + + + 0 + 0 + + + + + + + + + + + Stick Multipliers + + + + 5 + + + 5 + + + 5 + + + 5 + + + + + Left + + + + + + + 0.100000000000000 + + + + + + + Qt::Horizontal + + + + 0 + 0 + + + + + + + + Right + + + + + + + 0.100000000000000 + + + + + + + Qt::Horizontal + + + + 0 + 0 + + + + + + + - 0 + 1 @@ -2267,159 +2423,6 @@ 0 - - - - Stick Multipliers - - - - 5 - - - 5 - - - 5 - - - 5 - - - - - Left - - - - - - - 0.100000000000000 - - - - - - - Qt::Orientation::Horizontal - - - - 0 - 0 - - - - - - - - Right - - - - - - - 0.100000000000000 - - - - - - - Qt::Orientation::Horizontal - - - - 0 - 0 - - - - - - - - - - - Squircle Values - - - - 5 - - - 5 - - - 5 - - - 5 - - - - - Left - - - - - - - 1000000 - - - 1000 - - - - - - - Qt::Orientation::Horizontal - - - - 0 - 0 - - - - - - - - Right - - - - - - - 1000000 - - - - - - - Qt::Orientation::Horizontal - - - - 0 - 0 - - - - - - - @@ -2570,81 +2573,6 @@ 0 - - - - Stick Multipliers - - - - 5 - - - 5 - - - 5 - - - 5 - - - - - Left - - - - - - - 0.100000000000000 - - - - - - - Qt::Orientation::Horizontal - - - - 0 - 0 - - - - - - - - Right - - - - - - - 0.100000000000000 - - - - - - - Qt::Orientation::Horizontal - - - - 0 - 0 - - - - - - -