diff options
Diffstat (limited to 'src/input_common')
| -rw-r--r-- | src/input_common/CMakeLists.txt | 4 | ||||
| -rwxr-xr-x | src/input_common/analog_from_button.cpp | 122 | ||||
| -rw-r--r-- | src/input_common/gcadapter/gc_poller.cpp | 4 | ||||
| -rw-r--r-- | src/input_common/sdl/sdl.h | 2 | ||||
| -rw-r--r-- | src/input_common/sdl/sdl_impl.cpp | 7 | ||||
| -rw-r--r-- | src/input_common/touch_from_button.cpp | 3 | ||||
| -rw-r--r-- | src/input_common/udp/client.cpp | 10 | ||||
| -rw-r--r-- | src/input_common/udp/protocol.h | 11 |
8 files changed, 131 insertions, 32 deletions
diff --git a/src/input_common/CMakeLists.txt b/src/input_common/CMakeLists.txt index 7b39a38c1..1d1b2e08a 100644 --- a/src/input_common/CMakeLists.txt +++ b/src/input_common/CMakeLists.txt | |||
| @@ -31,6 +31,9 @@ add_library(input_common STATIC | |||
| 31 | 31 | ||
| 32 | if (MSVC) | 32 | if (MSVC) |
| 33 | target_compile_options(input_common PRIVATE | 33 | target_compile_options(input_common PRIVATE |
| 34 | /W4 | ||
| 35 | /WX | ||
| 36 | |||
| 34 | # 'expression' : signed/unsigned mismatch | 37 | # 'expression' : signed/unsigned mismatch |
| 35 | /we4018 | 38 | /we4018 |
| 36 | # 'argument' : conversion from 'type1' to 'type2', possible loss of data (floating-point) | 39 | # 'argument' : conversion from 'type1' to 'type2', possible loss of data (floating-point) |
| @@ -46,6 +49,7 @@ if (MSVC) | |||
| 46 | ) | 49 | ) |
| 47 | else() | 50 | else() |
| 48 | target_compile_options(input_common PRIVATE | 51 | target_compile_options(input_common PRIVATE |
| 52 | -Werror | ||
| 49 | -Werror=conversion | 53 | -Werror=conversion |
| 50 | -Werror=ignored-qualifiers | 54 | -Werror=ignored-qualifiers |
| 51 | -Werror=implicit-fallthrough | 55 | -Werror=implicit-fallthrough |
diff --git a/src/input_common/analog_from_button.cpp b/src/input_common/analog_from_button.cpp index 74744d7f3..d748c1c04 100755 --- a/src/input_common/analog_from_button.cpp +++ b/src/input_common/analog_from_button.cpp | |||
| @@ -2,6 +2,10 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <chrono> | ||
| 6 | #include <cmath> | ||
| 7 | #include <thread> | ||
| 8 | #include "common/math_util.h" | ||
| 5 | #include "input_common/analog_from_button.h" | 9 | #include "input_common/analog_from_button.h" |
| 6 | 10 | ||
| 7 | namespace InputCommon { | 11 | namespace InputCommon { |
| @@ -11,31 +15,104 @@ public: | |||
| 11 | using Button = std::unique_ptr<Input::ButtonDevice>; | 15 | using Button = std::unique_ptr<Input::ButtonDevice>; |
| 12 | 16 | ||
| 13 | Analog(Button up_, Button down_, Button left_, Button right_, Button modifier_, | 17 | Analog(Button up_, Button down_, Button left_, Button right_, Button modifier_, |
| 14 | float modifier_scale_) | 18 | float modifier_scale_, float modifier_angle_) |
| 15 | : up(std::move(up_)), down(std::move(down_)), left(std::move(left_)), | 19 | : up(std::move(up_)), down(std::move(down_)), left(std::move(left_)), |
| 16 | right(std::move(right_)), modifier(std::move(modifier_)), | 20 | right(std::move(right_)), modifier(std::move(modifier_)), modifier_scale(modifier_scale_), |
| 17 | modifier_scale(modifier_scale_) {} | 21 | modifier_angle(modifier_angle_) { |
| 18 | 22 | update_thread = std::thread(&Analog::UpdateStatus, this); | |
| 19 | std::tuple<float, float> GetStatus() const override { | 23 | } |
| 20 | constexpr float SQRT_HALF = 0.707106781f; | ||
| 21 | int x = 0, y = 0; | ||
| 22 | 24 | ||
| 23 | if (right->GetStatus()) { | 25 | ~Analog() override { |
| 24 | ++x; | 26 | update_thread_running = false; |
| 27 | if (update_thread.joinable()) { | ||
| 28 | update_thread.join(); | ||
| 25 | } | 29 | } |
| 26 | if (left->GetStatus()) { | 30 | } |
| 27 | --x; | 31 | |
| 32 | void MoveToDirection(bool enable, float to_angle) { | ||
| 33 | if (!enable) { | ||
| 34 | return; | ||
| 28 | } | 35 | } |
| 29 | if (up->GetStatus()) { | 36 | constexpr float TAU = Common::PI * 2.0f; |
| 30 | ++y; | 37 | // Use wider angle to ease the transition. |
| 38 | constexpr float aperture = TAU * 0.15f; | ||
| 39 | const float top_limit = to_angle + aperture; | ||
| 40 | const float bottom_limit = to_angle - aperture; | ||
| 41 | |||
| 42 | if ((angle > to_angle && angle <= top_limit) || | ||
| 43 | (angle + TAU > to_angle && angle + TAU <= top_limit)) { | ||
| 44 | angle -= modifier_angle; | ||
| 45 | if (angle < 0) { | ||
| 46 | angle += TAU; | ||
| 47 | } | ||
| 48 | } else if ((angle >= bottom_limit && angle < to_angle) || | ||
| 49 | (angle - TAU >= bottom_limit && angle - TAU < to_angle)) { | ||
| 50 | angle += modifier_angle; | ||
| 51 | if (angle >= TAU) { | ||
| 52 | angle -= TAU; | ||
| 53 | } | ||
| 54 | } else { | ||
| 55 | angle = to_angle; | ||
| 31 | } | 56 | } |
| 32 | if (down->GetStatus()) { | 57 | } |
| 33 | --y; | 58 | |
| 59 | void UpdateStatus() { | ||
| 60 | while (update_thread_running) { | ||
| 61 | const float coef = modifier->GetStatus() ? modifier_scale : 1.0f; | ||
| 62 | |||
| 63 | bool r = right->GetStatus(); | ||
| 64 | bool l = left->GetStatus(); | ||
| 65 | bool u = up->GetStatus(); | ||
| 66 | bool d = down->GetStatus(); | ||
| 67 | |||
| 68 | // Eliminate contradictory movements | ||
| 69 | if (r && l) { | ||
| 70 | r = false; | ||
| 71 | l = false; | ||
| 72 | } | ||
| 73 | if (u && d) { | ||
| 74 | u = false; | ||
| 75 | d = false; | ||
| 76 | } | ||
| 77 | |||
| 78 | // Move to the right | ||
| 79 | MoveToDirection(r && !u && !d, 0.0f); | ||
| 80 | |||
| 81 | // Move to the upper right | ||
| 82 | MoveToDirection(r && u && !d, Common::PI * 0.25f); | ||
| 83 | |||
| 84 | // Move up | ||
| 85 | MoveToDirection(u && !l && !r, Common::PI * 0.5f); | ||
| 86 | |||
| 87 | // Move to the upper left | ||
| 88 | MoveToDirection(l && u && !d, Common::PI * 0.75f); | ||
| 89 | |||
| 90 | // Move to the left | ||
| 91 | MoveToDirection(l && !u && !d, Common::PI); | ||
| 92 | |||
| 93 | // Move to the bottom left | ||
| 94 | MoveToDirection(l && !u && d, Common::PI * 1.25f); | ||
| 95 | |||
| 96 | // Move down | ||
| 97 | MoveToDirection(d && !l && !r, Common::PI * 1.5f); | ||
| 98 | |||
| 99 | // Move to the bottom right | ||
| 100 | MoveToDirection(r && !u && d, Common::PI * 1.75f); | ||
| 101 | |||
| 102 | // Move if a key is pressed | ||
| 103 | if (r || l || u || d) { | ||
| 104 | amplitude = coef; | ||
| 105 | } else { | ||
| 106 | amplitude = 0; | ||
| 107 | } | ||
| 108 | |||
| 109 | // Delay the update rate to 100hz | ||
| 110 | std::this_thread::sleep_for(std::chrono::milliseconds(10)); | ||
| 34 | } | 111 | } |
| 112 | } | ||
| 35 | 113 | ||
| 36 | const float coef = modifier->GetStatus() ? modifier_scale : 1.0f; | 114 | std::tuple<float, float> GetStatus() const override { |
| 37 | return std::make_tuple(static_cast<float>(x) * coef * (y == 0 ? 1.0f : SQRT_HALF), | 115 | return std::make_tuple(std::cos(angle) * amplitude, std::sin(angle) * amplitude); |
| 38 | static_cast<float>(y) * coef * (x == 0 ? 1.0f : SQRT_HALF)); | ||
| 39 | } | 116 | } |
| 40 | 117 | ||
| 41 | bool GetAnalogDirectionStatus(Input::AnalogDirection direction) const override { | 118 | bool GetAnalogDirectionStatus(Input::AnalogDirection direction) const override { |
| @@ -59,6 +136,11 @@ private: | |||
| 59 | Button right; | 136 | Button right; |
| 60 | Button modifier; | 137 | Button modifier; |
| 61 | float modifier_scale; | 138 | float modifier_scale; |
| 139 | float modifier_angle; | ||
| 140 | float angle{}; | ||
| 141 | float amplitude{}; | ||
| 142 | std::thread update_thread; | ||
| 143 | bool update_thread_running{true}; | ||
| 62 | }; | 144 | }; |
| 63 | 145 | ||
| 64 | std::unique_ptr<Input::AnalogDevice> AnalogFromButton::Create(const Common::ParamPackage& params) { | 146 | std::unique_ptr<Input::AnalogDevice> AnalogFromButton::Create(const Common::ParamPackage& params) { |
| @@ -69,8 +151,10 @@ std::unique_ptr<Input::AnalogDevice> AnalogFromButton::Create(const Common::Para | |||
| 69 | auto right = Input::CreateDevice<Input::ButtonDevice>(params.Get("right", null_engine)); | 151 | auto right = Input::CreateDevice<Input::ButtonDevice>(params.Get("right", null_engine)); |
| 70 | auto modifier = Input::CreateDevice<Input::ButtonDevice>(params.Get("modifier", null_engine)); | 152 | auto modifier = Input::CreateDevice<Input::ButtonDevice>(params.Get("modifier", null_engine)); |
| 71 | auto modifier_scale = params.Get("modifier_scale", 0.5f); | 153 | auto modifier_scale = params.Get("modifier_scale", 0.5f); |
| 154 | auto modifier_angle = params.Get("modifier_angle", 0.035f); | ||
| 72 | return std::make_unique<Analog>(std::move(up), std::move(down), std::move(left), | 155 | return std::make_unique<Analog>(std::move(up), std::move(down), std::move(left), |
| 73 | std::move(right), std::move(modifier), modifier_scale); | 156 | std::move(right), std::move(modifier), modifier_scale, |
| 157 | modifier_angle); | ||
| 74 | } | 158 | } |
| 75 | 159 | ||
| 76 | } // namespace InputCommon | 160 | } // namespace InputCommon |
diff --git a/src/input_common/gcadapter/gc_poller.cpp b/src/input_common/gcadapter/gc_poller.cpp index d95574bb5..4d1052414 100644 --- a/src/input_common/gcadapter/gc_poller.cpp +++ b/src/input_common/gcadapter/gc_poller.cpp | |||
| @@ -96,7 +96,6 @@ std::unique_ptr<Input::ButtonDevice> GCButtonFactory::Create(const Common::Param | |||
| 96 | adapter.get()); | 96 | adapter.get()); |
| 97 | } | 97 | } |
| 98 | 98 | ||
| 99 | UNREACHABLE(); | ||
| 100 | return nullptr; | 99 | return nullptr; |
| 101 | } | 100 | } |
| 102 | 101 | ||
| @@ -300,7 +299,8 @@ public: | |||
| 300 | return gcadapter->RumblePlay(port, 0); | 299 | return gcadapter->RumblePlay(port, 0); |
| 301 | } | 300 | } |
| 302 | 301 | ||
| 303 | bool SetRumblePlay(f32 amp_low, f32 freq_low, f32 amp_high, f32 freq_high) const override { | 302 | bool SetRumblePlay(f32 amp_low, [[maybe_unused]] f32 freq_low, f32 amp_high, |
| 303 | [[maybe_unused]] f32 freq_high) const override { | ||
| 304 | const auto mean_amplitude = (amp_low + amp_high) * 0.5f; | 304 | const auto mean_amplitude = (amp_low + amp_high) * 0.5f; |
| 305 | const auto processed_amplitude = | 305 | const auto processed_amplitude = |
| 306 | static_cast<u8>((mean_amplitude + std::pow(mean_amplitude, 0.3f)) * 0.5f * 0x8); | 306 | static_cast<u8>((mean_amplitude + std::pow(mean_amplitude, 0.3f)) * 0.5f * 0x8); |
diff --git a/src/input_common/sdl/sdl.h b/src/input_common/sdl/sdl.h index f3554be9a..42bbf14d4 100644 --- a/src/input_common/sdl/sdl.h +++ b/src/input_common/sdl/sdl.h | |||
| @@ -23,7 +23,7 @@ public: | |||
| 23 | /// Unregisters SDL device factories and shut them down. | 23 | /// Unregisters SDL device factories and shut them down. |
| 24 | virtual ~State() = default; | 24 | virtual ~State() = default; |
| 25 | 25 | ||
| 26 | virtual Pollers GetPollers(Polling::DeviceType type) { | 26 | virtual Pollers GetPollers(Polling::DeviceType) { |
| 27 | return {}; | 27 | return {}; |
| 28 | } | 28 | } |
| 29 | 29 | ||
diff --git a/src/input_common/sdl/sdl_impl.cpp b/src/input_common/sdl/sdl_impl.cpp index c395d96cf..7827e324c 100644 --- a/src/input_common/sdl/sdl_impl.cpp +++ b/src/input_common/sdl/sdl_impl.cpp | |||
| @@ -400,7 +400,8 @@ public: | |||
| 400 | return joystick->RumblePlay(0, 0); | 400 | return joystick->RumblePlay(0, 0); |
| 401 | } | 401 | } |
| 402 | 402 | ||
| 403 | bool SetRumblePlay(f32 amp_low, f32 freq_low, f32 amp_high, f32 freq_high) const override { | 403 | bool SetRumblePlay(f32 amp_low, [[maybe_unused]] f32 freq_low, f32 amp_high, |
| 404 | [[maybe_unused]] f32 freq_high) const override { | ||
| 404 | const auto process_amplitude = [](f32 amplitude) { | 405 | const auto process_amplitude = [](f32 amplitude) { |
| 405 | return static_cast<u16>((amplitude + std::pow(amplitude, 0.3f)) * 0.5f * 0xFFFF); | 406 | return static_cast<u16>((amplitude + std::pow(amplitude, 0.3f)) * 0.5f * 0xFFFF); |
| 406 | }; | 407 | }; |
| @@ -864,6 +865,8 @@ Common::ParamPackage SDLEventToMotionParamPackage(SDLState& state, const SDL_Eve | |||
| 864 | Common::ParamPackage BuildParamPackageForBinding(int port, const std::string& guid, | 865 | Common::ParamPackage BuildParamPackageForBinding(int port, const std::string& guid, |
| 865 | const SDL_GameControllerButtonBind& binding) { | 866 | const SDL_GameControllerButtonBind& binding) { |
| 866 | switch (binding.bindType) { | 867 | switch (binding.bindType) { |
| 868 | case SDL_CONTROLLER_BINDTYPE_NONE: | ||
| 869 | break; | ||
| 867 | case SDL_CONTROLLER_BINDTYPE_AXIS: | 870 | case SDL_CONTROLLER_BINDTYPE_AXIS: |
| 868 | return BuildAnalogParamPackageForButton(port, guid, binding.value.axis); | 871 | return BuildAnalogParamPackageForButton(port, guid, binding.value.axis); |
| 869 | case SDL_CONTROLLER_BINDTYPE_BUTTON: | 872 | case SDL_CONTROLLER_BINDTYPE_BUTTON: |
| @@ -984,7 +987,7 @@ class SDLPoller : public InputCommon::Polling::DevicePoller { | |||
| 984 | public: | 987 | public: |
| 985 | explicit SDLPoller(SDLState& state_) : state(state_) {} | 988 | explicit SDLPoller(SDLState& state_) : state(state_) {} |
| 986 | 989 | ||
| 987 | void Start(const std::string& device_id) override { | 990 | void Start([[maybe_unused]] const std::string& device_id) override { |
| 988 | state.event_queue.Clear(); | 991 | state.event_queue.Clear(); |
| 989 | state.polling = true; | 992 | state.polling = true; |
| 990 | } | 993 | } |
diff --git a/src/input_common/touch_from_button.cpp b/src/input_common/touch_from_button.cpp index c37716aae..a07124a86 100644 --- a/src/input_common/touch_from_button.cpp +++ b/src/input_common/touch_from_button.cpp | |||
| @@ -44,8 +44,7 @@ private: | |||
| 44 | std::vector<std::tuple<std::unique_ptr<Input::ButtonDevice>, int, int>> map; | 44 | std::vector<std::tuple<std::unique_ptr<Input::ButtonDevice>, int, int>> map; |
| 45 | }; | 45 | }; |
| 46 | 46 | ||
| 47 | std::unique_ptr<Input::TouchDevice> TouchFromButtonFactory::Create( | 47 | std::unique_ptr<Input::TouchDevice> TouchFromButtonFactory::Create(const Common::ParamPackage&) { |
| 48 | const Common::ParamPackage& params) { | ||
| 49 | return std::make_unique<TouchFromButtonDevice>(); | 48 | return std::make_unique<TouchFromButtonDevice>(); |
| 50 | } | 49 | } |
| 51 | 50 | ||
diff --git a/src/input_common/udp/client.cpp b/src/input_common/udp/client.cpp index 3677e79ca..c0bb90048 100644 --- a/src/input_common/udp/client.cpp +++ b/src/input_common/udp/client.cpp | |||
| @@ -63,7 +63,7 @@ public: | |||
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | private: | 65 | private: |
| 66 | void HandleReceive(const boost::system::error_code& error, std::size_t bytes_transferred) { | 66 | void HandleReceive(const boost::system::error_code&, std::size_t bytes_transferred) { |
| 67 | if (auto type = Response::Validate(receive_buffer.data(), bytes_transferred)) { | 67 | if (auto type = Response::Validate(receive_buffer.data(), bytes_transferred)) { |
| 68 | switch (*type) { | 68 | switch (*type) { |
| 69 | case Type::Version: { | 69 | case Type::Version: { |
| @@ -90,7 +90,7 @@ private: | |||
| 90 | StartReceive(); | 90 | StartReceive(); |
| 91 | } | 91 | } |
| 92 | 92 | ||
| 93 | void HandleSend(const boost::system::error_code& error) { | 93 | void HandleSend(const boost::system::error_code&) { |
| 94 | boost::system::error_code _ignored{}; | 94 | boost::system::error_code _ignored{}; |
| 95 | // Send a request for getting port info for the pad | 95 | // Send a request for getting port info for the pad |
| 96 | const Request::PortInfo port_info{1, {static_cast<u8>(pad_index), 0, 0, 0}}; | 96 | const Request::PortInfo port_info{1, {static_cast<u8>(pad_index), 0, 0, 0}}; |
| @@ -189,11 +189,11 @@ void Client::ReloadSocket(const std::string& host, u16 port, std::size_t pad_ind | |||
| 189 | StartCommunication(client, host, port, pad_index, client_id); | 189 | StartCommunication(client, host, port, pad_index, client_id); |
| 190 | } | 190 | } |
| 191 | 191 | ||
| 192 | void Client::OnVersion(Response::Version data) { | 192 | void Client::OnVersion([[maybe_unused]] Response::Version data) { |
| 193 | LOG_TRACE(Input, "Version packet received: {}", data.version); | 193 | LOG_TRACE(Input, "Version packet received: {}", data.version); |
| 194 | } | 194 | } |
| 195 | 195 | ||
| 196 | void Client::OnPortInfo(Response::PortInfo data) { | 196 | void Client::OnPortInfo([[maybe_unused]] Response::PortInfo data) { |
| 197 | LOG_TRACE(Input, "PortInfo packet received: {}", data.model); | 197 | LOG_TRACE(Input, "PortInfo packet received: {}", data.model); |
| 198 | } | 198 | } |
| 199 | 199 | ||
| @@ -369,7 +369,7 @@ CalibrationConfigurationJob::CalibrationConfigurationJob( | |||
| 369 | u16 max_y{}; | 369 | u16 max_y{}; |
| 370 | 370 | ||
| 371 | Status current_status{Status::Initialized}; | 371 | Status current_status{Status::Initialized}; |
| 372 | SocketCallback callback{[](Response::Version version) {}, [](Response::PortInfo info) {}, | 372 | SocketCallback callback{[](Response::Version) {}, [](Response::PortInfo) {}, |
| 373 | [&](Response::PadData data) { | 373 | [&](Response::PadData data) { |
| 374 | if (current_status == Status::Initialized) { | 374 | if (current_status == Status::Initialized) { |
| 375 | // Receiving data means the communication is ready now | 375 | // Receiving data means the communication is ready now |
diff --git a/src/input_common/udp/protocol.h b/src/input_common/udp/protocol.h index 3ba4d1fc8..fc1aea4b9 100644 --- a/src/input_common/udp/protocol.h +++ b/src/input_common/udp/protocol.h | |||
| @@ -7,7 +7,16 @@ | |||
| 7 | #include <array> | 7 | #include <array> |
| 8 | #include <optional> | 8 | #include <optional> |
| 9 | #include <type_traits> | 9 | #include <type_traits> |
| 10 | |||
| 11 | #ifdef _MSC_VER | ||
| 12 | #pragma warning(push) | ||
| 13 | #pragma warning(disable : 4701) | ||
| 14 | #endif | ||
| 10 | #include <boost/crc.hpp> | 15 | #include <boost/crc.hpp> |
| 16 | #ifdef _MSC_VER | ||
| 17 | #pragma warning(pop) | ||
| 18 | #endif | ||
| 19 | |||
| 11 | #include "common/bit_field.h" | 20 | #include "common/bit_field.h" |
| 12 | #include "common/swap.h" | 21 | #include "common/swap.h" |
| 13 | 22 | ||
| @@ -93,7 +102,7 @@ static_assert(std::is_trivially_copyable_v<PadData>, | |||
| 93 | 102 | ||
| 94 | /** | 103 | /** |
| 95 | * Creates a message with the proper header data that can be sent to the server. | 104 | * Creates a message with the proper header data that can be sent to the server. |
| 96 | * @param T data Request body to send | 105 | * @param data Request body to send |
| 97 | * @param client_id ID of the udp client (usually not checked on the server) | 106 | * @param client_id ID of the udp client (usually not checked on the server) |
| 98 | */ | 107 | */ |
| 99 | template <typename T> | 108 | template <typename T> |