From 09767f333dfe811f66da87ba7fa73ac0ea616278 Mon Sep 17 00:00:00 2001 From: pineappleEA Date: Sat, 15 May 2021 14:21:39 +0200 Subject: [PATCH] early-access version 1682 --- README.md | 2 +- src/input_common/sdl/sdl_impl.cpp | 54 ++++++++++++++++--------------- src/input_common/udp/client.cpp | 23 +++++++++++++ 3 files changed, 52 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index d42d2fe11..8be079faf 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ yuzu emulator early access ============= -This is the source code for early-access 1681. +This is the source code for early-access 1682. ## Legal Notice diff --git a/src/input_common/sdl/sdl_impl.cpp b/src/input_common/sdl/sdl_impl.cpp index 7c9841994..0465a34d9 100755 --- a/src/input_common/sdl/sdl_impl.cpp +++ b/src/input_common/sdl/sdl_impl.cpp @@ -321,7 +321,9 @@ void SDLState::CloseJoystick(SDL_Joystick* sdl_joystick) { return joystick->GetSDLJoystick() == sdl_joystick; }); - (*joystick_it)->SetSDLJoystick(nullptr, nullptr); + if (joystick_it != std::end(joystick_guid_list)) { + (*joystick_it)->SetSDLJoystick(nullptr, nullptr); + } } void SDLState::HandleGameControllerEvent(const SDL_Event& event) { @@ -1313,51 +1315,51 @@ public: void Start(const std::string& device_id) override { SDLPoller::Start(device_id); // Reset stored axes - analog_x_axis = -1; - analog_y_axis = -1; + first_axis = -1; } Common::ParamPackage GetNextInput() override { SDL_Event event; while (state.event_queue.Pop(event)) { - // Filter out axis events that are below a threshold - if (event.type == SDL_JOYAXISMOTION && std::abs(event.jaxis.value / 32767.0) < 0.5) { - continue; - } - if (event.type == SDL_JOYAXISMOTION) { - const auto axis = event.jaxis.axis; - // In order to return a complete analog param, we need inputs for both axes. - // First we take the x-axis (horizontal) input, then the y-axis (vertical) input. - if (analog_x_axis == -1) { - analog_x_axis = axis; - } else if (analog_y_axis == -1 && analog_x_axis != axis) { - analog_y_axis = axis; - } - } else { - // If the press wasn't accepted as a joy axis, check for a button press + if (event.type != SDL_JOYAXISMOTION) { + // Check for a button press auto button_press = button_poller.FromEvent(event); if (button_press) { return *button_press; } + continue; + } + const auto axis = event.jaxis.axis; + + // Filter out axis events that are below a threshold + if (std::abs(event.jaxis.value / 32767.0) < 0.5) { + continue; + } + + // Filter out axis events that are the same + if (first_axis == axis) { + continue; + } + + // In order to return a complete analog param, we need inputs for both axes. + // If the first axis isn't set we set the value then wait till next event + if (first_axis == -1) { + first_axis = axis; + continue; } - } - if (analog_x_axis != -1 && analog_y_axis != -1) { if (const auto joystick = state.GetSDLJoystickBySDLID(event.jaxis.which)) { auto params = BuildParamPackageForAnalog(joystick->GetPort(), joystick->GetGUID(), - analog_x_axis, analog_y_axis); - analog_x_axis = -1; - analog_y_axis = -1; + first_axis, axis); + first_axis = -1; return params; } } - return {}; } private: - int analog_x_axis = -1; - int analog_y_axis = -1; + int first_axis = -1; SDLButtonPoller button_poller; }; } // namespace Polling diff --git a/src/input_common/udp/client.cpp b/src/input_common/udp/client.cpp index 8a38a380d..bc1dfab3d 100755 --- a/src/input_common/udp/client.cpp +++ b/src/input_common/udp/client.cpp @@ -86,6 +86,7 @@ private: case Type::PadData: { Response::PadData pad_data; std::memcpy(&pad_data, &receive_buffer[sizeof(Header)], sizeof(Response::PadData)); + SanitizeMotion(pad_data); callback.pad_data(std::move(pad_data)); break; } @@ -114,6 +115,28 @@ private: StartSend(timer.expiry()); } + void SanitizeMotion(Response::PadData& data) { + // Zero out any non number value + if (!std::isnormal(data.gyro.pitch)) { + data.gyro.pitch = 0; + } + if (!std::isnormal(data.gyro.roll)) { + data.gyro.roll = 0; + } + if (!std::isnormal(data.gyro.yaw)) { + data.gyro.yaw = 0; + } + if (!std::isnormal(data.accel.x)) { + data.accel.x = 0; + } + if (!std::isnormal(data.accel.y)) { + data.accel.y = 0; + } + if (!std::isnormal(data.accel.z)) { + data.accel.z = 0; + } + } + SocketCallback callback; boost::asio::io_service io_service; boost::asio::basic_waitable_timer timer;