diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/input_common/gcadapter/gc_adapter.cpp | 12 | ||||
| -rw-r--r-- | src/input_common/gcadapter/gc_poller.cpp | 32 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_input_player.cpp | 71 |
3 files changed, 80 insertions, 35 deletions
diff --git a/src/input_common/gcadapter/gc_adapter.cpp b/src/input_common/gcadapter/gc_adapter.cpp index 1ddb9cdb4..82f97572f 100644 --- a/src/input_common/gcadapter/gc_adapter.cpp +++ b/src/input_common/gcadapter/gc_adapter.cpp | |||
| @@ -144,6 +144,18 @@ void Adapter::Read() { | |||
| 144 | pads[port].axis_value = pads[port].substick_y; | 144 | pads[port].axis_value = pads[port].substick_y; |
| 145 | pad_queue[port].Push(pads[port]); | 145 | pad_queue[port].Push(pads[port]); |
| 146 | } | 146 | } |
| 147 | if (pads[port].trigger_left > pads[port].TRIGGER_CENTER + pads[port].THRESHOLD || | ||
| 148 | pads[port].trigger_left < pads[port].TRIGGER_CENTER - pads[port].THRESHOLD) { | ||
| 149 | pads[port].axis = GCAdapter::PadAxes::TriggerLeft; | ||
| 150 | pads[port].axis_value = pads[port].trigger_left; | ||
| 151 | pad_queue[port].Push(pads[port]); | ||
| 152 | } | ||
| 153 | if (pads[port].trigger_right > pads[port].TRIGGER_CENTER + pads[port].THRESHOLD || | ||
| 154 | pads[port].trigger_right < pads[port].TRIGGER_CENTER - pads[port].THRESHOLD) { | ||
| 155 | pads[port].axis = GCAdapter::PadAxes::TriggerRight; | ||
| 156 | pads[port].axis_value = pads[port].trigger_right; | ||
| 157 | pad_queue[port].Push(pads[port]); | ||
| 158 | } | ||
| 147 | } | 159 | } |
| 148 | PadToState(pads[port], state[port]); | 160 | PadToState(pads[port], state[port]); |
| 149 | } | 161 | } |
diff --git a/src/input_common/gcadapter/gc_poller.cpp b/src/input_common/gcadapter/gc_poller.cpp index a9de9fedf..a04c507b8 100644 --- a/src/input_common/gcadapter/gc_poller.cpp +++ b/src/input_common/gcadapter/gc_poller.cpp | |||
| @@ -34,7 +34,13 @@ public: | |||
| 34 | explicit GCAxisButton(int port_, int axis_, float threshold_, bool trigger_if_greater_, | 34 | explicit GCAxisButton(int port_, int axis_, float threshold_, bool trigger_if_greater_, |
| 35 | GCAdapter::Adapter* adapter) | 35 | GCAdapter::Adapter* adapter) |
| 36 | : port(port_), axis(axis_), threshold(threshold_), trigger_if_greater(trigger_if_greater_), | 36 | : port(port_), axis(axis_), threshold(threshold_), trigger_if_greater(trigger_if_greater_), |
| 37 | gcadapter(adapter) {} | 37 | gcadapter(adapter) { |
| 38 | // L/R triggers range is only in positive direction beginning near 0 | ||
| 39 | // 0.0 threshold equates to near half trigger press, but threshold accounts for variability. | ||
| 40 | if (axis > 3) { | ||
| 41 | threshold *= -0.5; | ||
| 42 | } | ||
| 43 | } | ||
| 38 | 44 | ||
| 39 | bool GetStatus() const override { | 45 | bool GetStatus() const override { |
| 40 | const float axis_value = (gcadapter->GetPadState()[port].axes.at(axis) - 128.0f) / 128.0f; | 46 | const float axis_value = (gcadapter->GetPadState()[port].axes.at(axis) - 128.0f) / 128.0f; |
| @@ -60,10 +66,20 @@ GCButton::~GCButton() = default; | |||
| 60 | std::unique_ptr<Input::ButtonDevice> GCButtonFactory::Create(const Common::ParamPackage& params) { | 66 | std::unique_ptr<Input::ButtonDevice> GCButtonFactory::Create(const Common::ParamPackage& params) { |
| 61 | const int button_id = params.Get("button", 0); | 67 | const int button_id = params.Get("button", 0); |
| 62 | const int port = params.Get("port", 0); | 68 | const int port = params.Get("port", 0); |
| 69 | |||
| 70 | constexpr int PAD_STICK_ID = static_cast<u16>(GCAdapter::PadButton::PAD_STICK); | ||
| 71 | |||
| 72 | // button is not an axis/stick button | ||
| 73 | if (button_id != PAD_STICK_ID) { | ||
| 74 | std::unique_ptr<GCButton> button = | ||
| 75 | std::make_unique<GCButton>(port, button_id, params.Get("axis", 0), adapter.get()); | ||
| 76 | return std::move(button); | ||
| 77 | } | ||
| 78 | |||
| 63 | // For Axis buttons, used by the binary sticks. | 79 | // For Axis buttons, used by the binary sticks. |
| 64 | if (params.Has("axis")) { | 80 | if (button_id == PAD_STICK_ID) { |
| 65 | const int axis = params.Get("axis", 0); | 81 | const int axis = params.Get("axis", 0); |
| 66 | const float threshold = params.Get("threshold", 0.5f); | 82 | const float threshold = params.Get("threshold", 0.25f); |
| 67 | const std::string direction_name = params.Get("direction", ""); | 83 | const std::string direction_name = params.Get("direction", ""); |
| 68 | bool trigger_if_greater; | 84 | bool trigger_if_greater; |
| 69 | if (direction_name == "+") { | 85 | if (direction_name == "+") { |
| @@ -77,10 +93,6 @@ std::unique_ptr<Input::ButtonDevice> GCButtonFactory::Create(const Common::Param | |||
| 77 | return std::make_unique<GCAxisButton>(port, axis, threshold, trigger_if_greater, | 93 | return std::make_unique<GCAxisButton>(port, axis, threshold, trigger_if_greater, |
| 78 | adapter.get()); | 94 | adapter.get()); |
| 79 | } | 95 | } |
| 80 | |||
| 81 | std::unique_ptr<GCButton> button = | ||
| 82 | std::make_unique<GCButton>(port, button_id, params.Get("axis", 0), adapter.get()); | ||
| 83 | return std::move(button); | ||
| 84 | } | 96 | } |
| 85 | 97 | ||
| 86 | Common::ParamPackage GCButtonFactory::GetNextInput() { | 98 | Common::ParamPackage GCButtonFactory::GetNextInput() { |
| @@ -106,10 +118,10 @@ Common::ParamPackage GCButtonFactory::GetNextInput() { | |||
| 106 | params.Set("button", static_cast<u16>(GCAdapter::PadButton::PAD_STICK)); | 118 | params.Set("button", static_cast<u16>(GCAdapter::PadButton::PAD_STICK)); |
| 107 | if (pad.axis_value > 128) { | 119 | if (pad.axis_value > 128) { |
| 108 | params.Set("direction", "+"); | 120 | params.Set("direction", "+"); |
| 109 | params.Set("threshold", "0.5"); | 121 | params.Set("threshold", "0.25"); |
| 110 | } else { | 122 | } else { |
| 111 | params.Set("direction", "-"); | 123 | params.Set("direction", "-"); |
| 112 | params.Set("threshold", "-0.5"); | 124 | params.Set("threshold", "-0.25"); |
| 113 | } | 125 | } |
| 114 | break; | 126 | break; |
| 115 | } | 127 | } |
| @@ -232,7 +244,7 @@ Common::ParamPackage GCAnalogFactory::GetNextInput() { | |||
| 232 | continue; | 244 | continue; |
| 233 | } | 245 | } |
| 234 | // An analog device needs two axes, so we need to store the axis for later and wait for | 246 | // An analog device needs two axes, so we need to store the axis for later and wait for |
| 235 | // a second SDL event. The axes also must be from the same joystick. | 247 | // a second input event. The axes also must be from the same joystick. |
| 236 | const u8 axis = static_cast<u8>(pad.axis); | 248 | const u8 axis = static_cast<u8>(pad.axis); |
| 237 | if (analog_x_axis == -1) { | 249 | if (analog_x_axis == -1) { |
| 238 | analog_x_axis = axis; | 250 | analog_x_axis = axis; |
diff --git a/src/yuzu/configuration/configure_input_player.cpp b/src/yuzu/configuration/configure_input_player.cpp index 1d7418122..49b8c8386 100644 --- a/src/yuzu/configuration/configure_input_player.cpp +++ b/src/yuzu/configuration/configure_input_player.cpp | |||
| @@ -120,7 +120,7 @@ static QString AnalogToText(const Common::ParamPackage& param, const std::string | |||
| 120 | return ButtonToText(Common::ParamPackage{param.Get(dir, "")}); | 120 | return ButtonToText(Common::ParamPackage{param.Get(dir, "")}); |
| 121 | } | 121 | } |
| 122 | 122 | ||
| 123 | if (param.Get("engine", "") == "sdl" || param.Get("engine", "") == "gcpad") { | 123 | if (param.Get("engine", "") == "sdl") { |
| 124 | if (dir == "modifier") { | 124 | if (dir == "modifier") { |
| 125 | return QObject::tr("[unused]"); | 125 | return QObject::tr("[unused]"); |
| 126 | } | 126 | } |
| @@ -140,6 +140,25 @@ static QString AnalogToText(const Common::ParamPackage& param, const std::string | |||
| 140 | return {}; | 140 | return {}; |
| 141 | } | 141 | } |
| 142 | 142 | ||
| 143 | if (param.Get("engine", "") == "gcpad") { | ||
| 144 | if (dir == "modifier") { | ||
| 145 | return QObject::tr("[unused]"); | ||
| 146 | } | ||
| 147 | |||
| 148 | if (dir == "left" || dir == "right") { | ||
| 149 | const QString axis_x_str = QString::fromStdString(param.Get("axis_x", "")); | ||
| 150 | |||
| 151 | return QObject::tr("GC Axis %1").arg(axis_x_str); | ||
| 152 | } | ||
| 153 | |||
| 154 | if (dir == "up" || dir == "down") { | ||
| 155 | const QString axis_y_str = QString::fromStdString(param.Get("axis_y", "")); | ||
| 156 | |||
| 157 | return QObject::tr("GC Axis %1").arg(axis_y_str); | ||
| 158 | } | ||
| 159 | |||
| 160 | return {}; | ||
| 161 | } | ||
| 143 | return QObject::tr("[unknown]"); | 162 | return QObject::tr("[unknown]"); |
| 144 | } | 163 | } |
| 145 | 164 | ||
| @@ -262,24 +281,25 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i | |||
| 262 | 281 | ||
| 263 | button->setContextMenuPolicy(Qt::CustomContextMenu); | 282 | button->setContextMenuPolicy(Qt::CustomContextMenu); |
| 264 | connect(button, &QPushButton::clicked, [=] { | 283 | connect(button, &QPushButton::clicked, [=] { |
| 265 | HandleClick(button_map[button_id], | 284 | HandleClick( |
| 266 | [=](Common::ParamPackage params) { | 285 | button_map[button_id], |
| 267 | // Workaround for ZL & ZR for analog triggers like on XBOX controllors. | 286 | [=](Common::ParamPackage params) { |
| 268 | // Analog triggers (from controllers like the XBOX controller) would not | 287 | // Workaround for ZL & ZR for analog triggers like on XBOX controllors. |
| 269 | // work due to a different range of their signals (from 0 to 255 on | 288 | // Analog triggers (from controllers like the XBOX controller) would not |
| 270 | // analog triggers instead of -32768 to 32768 on analog joysticks). The | 289 | // work due to a different range of their signals (from 0 to 255 on |
| 271 | // SDL driver misinterprets analog triggers as analog joysticks. | 290 | // analog triggers instead of -32768 to 32768 on analog joysticks). The |
| 272 | // TODO: reinterpret the signal range for analog triggers to map the | 291 | // SDL driver misinterprets analog triggers as analog joysticks. |
| 273 | // values correctly. This is required for the correct emulation of the | 292 | // TODO: reinterpret the signal range for analog triggers to map the |
| 274 | // analog triggers of the GameCube controller. | 293 | // values correctly. This is required for the correct emulation of the |
| 275 | if (button_id == Settings::NativeButton::ZL || | 294 | // analog triggers of the GameCube controller. |
| 276 | button_id == Settings::NativeButton::ZR) { | 295 | if (button_id == Settings::NativeButton::ZL || |
| 277 | params.Set("direction", "+"); | 296 | button_id == Settings::NativeButton::ZR) { |
| 278 | params.Set("threshold", "0.5"); | 297 | params.Set("direction", "+"); |
| 279 | } | 298 | params.Set("threshold", "0.5"); |
| 280 | buttons_param[button_id] = std::move(params); | 299 | } |
| 281 | }, | 300 | buttons_param[button_id] = std::move(params); |
| 282 | InputCommon::Polling::DeviceType::Button); | 301 | }, |
| 302 | InputCommon::Polling::DeviceType::Button); | ||
| 283 | }); | 303 | }); |
| 284 | connect(button, &QPushButton::customContextMenuRequested, [=](const QPoint& menu_location) { | 304 | connect(button, &QPushButton::customContextMenuRequested, [=](const QPoint& menu_location) { |
| 285 | QMenu context_menu; | 305 | QMenu context_menu; |
| @@ -305,12 +325,13 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i | |||
| 305 | 325 | ||
| 306 | analog_button->setContextMenuPolicy(Qt::CustomContextMenu); | 326 | analog_button->setContextMenuPolicy(Qt::CustomContextMenu); |
| 307 | connect(analog_button, &QPushButton::clicked, [=]() { | 327 | connect(analog_button, &QPushButton::clicked, [=]() { |
| 308 | HandleClick(analog_map_buttons[analog_id][sub_button_id], | 328 | HandleClick( |
| 309 | [=](const Common::ParamPackage& params) { | 329 | analog_map_buttons[analog_id][sub_button_id], |
| 310 | SetAnalogButton(params, analogs_param[analog_id], | 330 | [=](const Common::ParamPackage& params) { |
| 311 | analog_sub_buttons[sub_button_id]); | 331 | SetAnalogButton(params, analogs_param[analog_id], |
| 312 | }, | 332 | analog_sub_buttons[sub_button_id]); |
| 313 | InputCommon::Polling::DeviceType::Button); | 333 | }, |
| 334 | InputCommon::Polling::DeviceType::Button); | ||
| 314 | }); | 335 | }); |
| 315 | connect(analog_button, &QPushButton::customContextMenuRequested, | 336 | connect(analog_button, &QPushButton::customContextMenuRequested, |
| 316 | [=](const QPoint& menu_location) { | 337 | [=](const QPoint& menu_location) { |