1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-22 02:32:36 +01:00

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
This commit is contained in:
Megamouse 2024-09-08 20:03:14 +02:00
parent 8131f40269
commit e5a526e4d6
7 changed files with 211 additions and 266 deletions

View File

@ -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<u16, u16> 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<u16, u16>(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);
}
}

View File

@ -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<u16, u16> 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.

View File

@ -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 };

View File

@ -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();

View File

@ -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<AnalogStick> 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);
}
}

View File

@ -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);

View File

@ -2248,10 +2248,166 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="gb_squircle">
<property name="title">
<string>Squircle Values</string>
</property>
<layout class="QHBoxLayout" name="layout_squircle">
<property name="leftMargin">
<number>5</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<number>5</number>
</property>
<item>
<widget class="QLabel" name="label_squircle_left">
<property name="text">
<string>Left</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="squircle_left">
<property name="maximum">
<number>1000000</number>
</property>
<property name="singleStep">
<number>1000</number>
</property>
</widget>
</item>
<item>
<spacer name="spacer_squircle_left">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_squircle_right">
<property name="text">
<string>Right</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="squircle_right">
<property name="maximum">
<number>1000000</number>
</property>
<property name="singleStep">
<number>1000</number>
</property>
</widget>
</item>
<item>
<spacer name="spacer_squircle_right">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="gb_stick_multi">
<property name="title">
<string>Stick Multipliers</string>
</property>
<layout class="QHBoxLayout" name="gb_stick_multi_layout">
<property name="leftMargin">
<number>5</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<number>5</number>
</property>
<item>
<widget class="QLabel" name="label_stick_multi_left">
<property name="text">
<string>Left</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="stick_multi_left">
<property name="singleStep">
<double>0.100000000000000</double>
</property>
</widget>
</item>
<item>
<spacer name="spacer_stick_multi_left">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_stick_multi_right">
<property name="text">
<string>Right</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="stick_multi_right">
<property name="singleStep">
<double>0.100000000000000</double>
</property>
</widget>
</item>
<item>
<spacer name="spacer_stick_multi_right">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QStackedWidget" name="right_stack">
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<widget class="QWidget" name="stick_page">
<layout class="QVBoxLayout" name="stick_page_layout">
@ -2267,159 +2423,6 @@
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QGroupBox" name="gb_stick_multi">
<property name="title">
<string>Stick Multipliers</string>
</property>
<layout class="QHBoxLayout" name="gb_stick_multi_layout">
<property name="leftMargin">
<number>5</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<number>5</number>
</property>
<item>
<widget class="QLabel" name="label_stick_multi_left">
<property name="text">
<string>Left</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="stick_multi_left">
<property name="singleStep">
<double>0.100000000000000</double>
</property>
</widget>
</item>
<item>
<spacer name="spacer_stick_multi_left">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_stick_multi_right">
<property name="text">
<string>Right</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="stick_multi_right">
<property name="singleStep">
<double>0.100000000000000</double>
</property>
</widget>
</item>
<item>
<spacer name="spacer_stick_multi_right">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="gb_squircle">
<property name="title">
<string>Squircle Values</string>
</property>
<layout class="QHBoxLayout" name="layout_squircle">
<property name="leftMargin">
<number>5</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<number>5</number>
</property>
<item>
<widget class="QLabel" name="label_squircle_left">
<property name="text">
<string>Left</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="squircle_left">
<property name="maximum">
<number>1000000</number>
</property>
<property name="singleStep">
<number>1000</number>
</property>
</widget>
</item>
<item>
<spacer name="spacer_squircle_left">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_squircle_right">
<property name="text">
<string>Right</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="squircle_right">
<property name="maximum">
<number>1000000</number>
</property>
</widget>
</item>
<item>
<spacer name="spacer_squircle_right">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="gb_stick_deadzones">
<property name="title">
@ -2570,81 +2573,6 @@
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QGroupBox" name="gb_kb_stick_multi">
<property name="title">
<string>Stick Multipliers</string>
</property>
<layout class="QHBoxLayout" name="gb_kb_stick_multi_layout">
<property name="leftMargin">
<number>5</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<number>5</number>
</property>
<item>
<widget class="QLabel" name="label_kb_stick_multi_left">
<property name="text">
<string>Left</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="kb_stick_multi_left">
<property name="singleStep">
<double>0.100000000000000</double>
</property>
</widget>
</item>
<item>
<spacer name="spacer_kb_stick_multi_left">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_kb_stick_multi_right">
<property name="text">
<string>Right</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="kb_stick_multi_right">
<property name="singleStep">
<double>0.100000000000000</double>
</property>
</widget>
</item>
<item>
<spacer name="spacer_kb_stick_multi_right">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="gb_stick_lerp">
<property name="title">