summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar bunnei2020-02-01 14:02:41 -0500
committerGravatar GitHub2020-02-01 14:02:41 -0500
commit69a6796de10357947d3e0411126b13c59628cb51 (patch)
tree4478c6e702785340b1d453ed55da23448d88e8f5
parentMerge pull request #3364 from lioncash/thread (diff)
parentMoved analog direction logic to sdl_impl (diff)
downloadyuzu-69a6796de10357947d3e0411126b13c59628cb51.tar.gz
yuzu-69a6796de10357947d3e0411126b13c59628cb51.tar.xz
yuzu-69a6796de10357947d3e0411126b13c59628cb51.zip
Merge pull request #3284 from CJBok/hid-fix
hid: Fix analog sticks directional states
-rw-r--r--src/core/frontend/input.h10
-rw-r--r--src/core/hle/service/hid/controllers/npad.cpp39
-rw-r--r--src/input_common/sdl/sdl_impl.cpp16
3 files changed, 52 insertions, 13 deletions
diff --git a/src/core/frontend/input.h b/src/core/frontend/input.h
index 7c11d7546..2b098b7c6 100644
--- a/src/core/frontend/input.h
+++ b/src/core/frontend/input.h
@@ -15,6 +15,13 @@
15 15
16namespace Input { 16namespace Input {
17 17
18enum class AnalogDirection : u8 {
19 RIGHT,
20 LEFT,
21 UP,
22 DOWN,
23};
24
18/// An abstract class template for an input device (a button, an analog input, etc.). 25/// An abstract class template for an input device (a button, an analog input, etc.).
19template <typename StatusType> 26template <typename StatusType>
20class InputDevice { 27class InputDevice {
@@ -23,6 +30,9 @@ public:
23 virtual StatusType GetStatus() const { 30 virtual StatusType GetStatus() const {
24 return {}; 31 return {};
25 } 32 }
33 virtual bool GetAnalogDirectionStatus(AnalogDirection direction) const {
34 return {};
35 }
26}; 36};
27 37
28/// An abstract class template for a factory that can create input devices. 38/// An abstract class template for a factory that can create input devices.
diff --git a/src/core/hle/service/hid/controllers/npad.cpp b/src/core/hle/service/hid/controllers/npad.cpp
index 4d952adc0..15c09f04c 100644
--- a/src/core/hle/service/hid/controllers/npad.cpp
+++ b/src/core/hle/service/hid/controllers/npad.cpp
@@ -250,6 +250,10 @@ void Controller_NPad::RequestPadStateUpdate(u32 npad_id) {
250 auto& rstick_entry = npad_pad_states[controller_idx].r_stick; 250 auto& rstick_entry = npad_pad_states[controller_idx].r_stick;
251 const auto& button_state = buttons[controller_idx]; 251 const auto& button_state = buttons[controller_idx];
252 const auto& analog_state = sticks[controller_idx]; 252 const auto& analog_state = sticks[controller_idx];
253 const auto [stick_l_x_f, stick_l_y_f] =
254 analog_state[static_cast<std::size_t>(JoystickId::Joystick_Left)]->GetStatus();
255 const auto [stick_r_x_f, stick_r_y_f] =
256 analog_state[static_cast<std::size_t>(JoystickId::Joystick_Right)]->GetStatus();
253 257
254 using namespace Settings::NativeButton; 258 using namespace Settings::NativeButton;
255 pad_state.a.Assign(button_state[A - BUTTON_HID_BEGIN]->GetStatus()); 259 pad_state.a.Assign(button_state[A - BUTTON_HID_BEGIN]->GetStatus());
@@ -270,23 +274,32 @@ void Controller_NPad::RequestPadStateUpdate(u32 npad_id) {
270 pad_state.d_right.Assign(button_state[DRight - BUTTON_HID_BEGIN]->GetStatus()); 274 pad_state.d_right.Assign(button_state[DRight - BUTTON_HID_BEGIN]->GetStatus());
271 pad_state.d_down.Assign(button_state[DDown - BUTTON_HID_BEGIN]->GetStatus()); 275 pad_state.d_down.Assign(button_state[DDown - BUTTON_HID_BEGIN]->GetStatus());
272 276
273 pad_state.l_stick_left.Assign(button_state[LStick_Left - BUTTON_HID_BEGIN]->GetStatus()); 277 pad_state.l_stick_right.Assign(
274 pad_state.l_stick_up.Assign(button_state[LStick_Up - BUTTON_HID_BEGIN]->GetStatus()); 278 analog_state[static_cast<std::size_t>(JoystickId::Joystick_Left)]->GetAnalogDirectionStatus(
275 pad_state.l_stick_right.Assign(button_state[LStick_Right - BUTTON_HID_BEGIN]->GetStatus()); 279 Input::AnalogDirection::RIGHT));
276 pad_state.l_stick_down.Assign(button_state[LStick_Down - BUTTON_HID_BEGIN]->GetStatus()); 280 pad_state.l_stick_left.Assign(
277 281 analog_state[static_cast<std::size_t>(JoystickId::Joystick_Left)]->GetAnalogDirectionStatus(
278 pad_state.r_stick_left.Assign(button_state[RStick_Left - BUTTON_HID_BEGIN]->GetStatus()); 282 Input::AnalogDirection::LEFT));
279 pad_state.r_stick_up.Assign(button_state[RStick_Up - BUTTON_HID_BEGIN]->GetStatus()); 283 pad_state.l_stick_up.Assign(
280 pad_state.r_stick_right.Assign(button_state[RStick_Right - BUTTON_HID_BEGIN]->GetStatus()); 284 analog_state[static_cast<std::size_t>(JoystickId::Joystick_Left)]->GetAnalogDirectionStatus(
281 pad_state.r_stick_down.Assign(button_state[RStick_Down - BUTTON_HID_BEGIN]->GetStatus()); 285 Input::AnalogDirection::UP));
286 pad_state.l_stick_down.Assign(
287 analog_state[static_cast<std::size_t>(JoystickId::Joystick_Left)]->GetAnalogDirectionStatus(
288 Input::AnalogDirection::DOWN));
289
290 pad_state.r_stick_up.Assign(analog_state[static_cast<std::size_t>(JoystickId::Joystick_Right)]
291 ->GetAnalogDirectionStatus(Input::AnalogDirection::RIGHT));
292 pad_state.r_stick_left.Assign(analog_state[static_cast<std::size_t>(JoystickId::Joystick_Right)]
293 ->GetAnalogDirectionStatus(Input::AnalogDirection::LEFT));
294 pad_state.r_stick_right.Assign(
295 analog_state[static_cast<std::size_t>(JoystickId::Joystick_Right)]
296 ->GetAnalogDirectionStatus(Input::AnalogDirection::UP));
297 pad_state.r_stick_down.Assign(analog_state[static_cast<std::size_t>(JoystickId::Joystick_Right)]
298 ->GetAnalogDirectionStatus(Input::AnalogDirection::DOWN));
282 299
283 pad_state.left_sl.Assign(button_state[SL - BUTTON_HID_BEGIN]->GetStatus()); 300 pad_state.left_sl.Assign(button_state[SL - BUTTON_HID_BEGIN]->GetStatus());
284 pad_state.left_sr.Assign(button_state[SR - BUTTON_HID_BEGIN]->GetStatus()); 301 pad_state.left_sr.Assign(button_state[SR - BUTTON_HID_BEGIN]->GetStatus());
285 302
286 const auto [stick_l_x_f, stick_l_y_f] =
287 analog_state[static_cast<std::size_t>(JoystickId::Joystick_Left)]->GetStatus();
288 const auto [stick_r_x_f, stick_r_y_f] =
289 analog_state[static_cast<std::size_t>(JoystickId::Joystick_Right)]->GetStatus();
290 lstick_entry.x = static_cast<s32>(stick_l_x_f * HID_JOYSTICK_MAX); 303 lstick_entry.x = static_cast<s32>(stick_l_x_f * HID_JOYSTICK_MAX);
291 lstick_entry.y = static_cast<s32>(stick_l_y_f * HID_JOYSTICK_MAX); 304 lstick_entry.y = static_cast<s32>(stick_l_y_f * HID_JOYSTICK_MAX);
292 rstick_entry.x = static_cast<s32>(stick_r_x_f * HID_JOYSTICK_MAX); 305 rstick_entry.x = static_cast<s32>(stick_r_x_f * HID_JOYSTICK_MAX);
diff --git a/src/input_common/sdl/sdl_impl.cpp b/src/input_common/sdl/sdl_impl.cpp
index d2e9d278f..a2e0c0bd2 100644
--- a/src/input_common/sdl/sdl_impl.cpp
+++ b/src/input_common/sdl/sdl_impl.cpp
@@ -342,6 +342,22 @@ public:
342 return std::make_tuple<float, float>(0.0f, 0.0f); 342 return std::make_tuple<float, float>(0.0f, 0.0f);
343 } 343 }
344 344
345 bool GetAnalogDirectionStatus(Input::AnalogDirection direction) const override {
346 const auto [x, y] = GetStatus();
347 const float directional_deadzone = 0.4f;
348 switch (direction) {
349 case Input::AnalogDirection::RIGHT:
350 return x > directional_deadzone;
351 case Input::AnalogDirection::LEFT:
352 return x < -directional_deadzone;
353 case Input::AnalogDirection::UP:
354 return y > directional_deadzone;
355 case Input::AnalogDirection::DOWN:
356 return y < -directional_deadzone;
357 }
358 return false;
359 }
360
345private: 361private:
346 std::shared_ptr<SDLJoystick> joystick; 362 std::shared_ptr<SDLJoystick> joystick;
347 const int axis_x; 363 const int axis_x;