summaryrefslogtreecommitdiffstats
path: root/src/input_common
diff options
context:
space:
mode:
Diffstat (limited to 'src/input_common')
-rw-r--r--src/input_common/CMakeLists.txt4
-rwxr-xr-xsrc/input_common/analog_from_button.cpp122
-rw-r--r--src/input_common/gcadapter/gc_poller.cpp4
-rw-r--r--src/input_common/sdl/sdl.h2
-rw-r--r--src/input_common/sdl/sdl_impl.cpp7
-rw-r--r--src/input_common/touch_from_button.cpp3
-rw-r--r--src/input_common/udp/client.cpp10
-rw-r--r--src/input_common/udp/protocol.h11
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
if (MSVC)
target_compile_options(input_common PRIVATE
+ /W4
+ /WX
+
# 'expression' : signed/unsigned mismatch
/we4018
# 'argument' : conversion from 'type1' to 'type2', possible loss of data (floating-point)
@@ -46,6 +49,7 @@ if (MSVC)
)
else()
target_compile_options(input_common PRIVATE
+ -Werror
-Werror=conversion
-Werror=ignored-qualifiers
-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 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
+#include <chrono>
+#include <cmath>
+#include <thread>
+#include "common/math_util.h"
#include "input_common/analog_from_button.h"
namespace InputCommon {
@@ -11,31 +15,104 @@ public:
using Button = std::unique_ptr<Input::ButtonDevice>;
Analog(Button up_, Button down_, Button left_, Button right_, Button modifier_,
- float modifier_scale_)
+ float modifier_scale_, float modifier_angle_)
: up(std::move(up_)), down(std::move(down_)), left(std::move(left_)),
- right(std::move(right_)), modifier(std::move(modifier_)),
- modifier_scale(modifier_scale_) {}
-
- std::tuple<float, float> GetStatus() const override {
- constexpr float SQRT_HALF = 0.707106781f;
- int x = 0, y = 0;
+ right(std::move(right_)), modifier(std::move(modifier_)), modifier_scale(modifier_scale_),
+ modifier_angle(modifier_angle_) {
+ update_thread = std::thread(&Analog::UpdateStatus, this);
+ }
- if (right->GetStatus()) {
- ++x;
+ ~Analog() override {
+ update_thread_running = false;
+ if (update_thread.joinable()) {
+ update_thread.join();
}
- if (left->GetStatus()) {
- --x;
+ }
+
+ void MoveToDirection(bool enable, float to_angle) {
+ if (!enable) {
+ return;
}
- if (up->GetStatus()) {
- ++y;
+ constexpr float TAU = Common::PI * 2.0f;
+ // Use wider angle to ease the transition.
+ constexpr float aperture = TAU * 0.15f;
+ const float top_limit = to_angle + aperture;
+ const float bottom_limit = to_angle - aperture;
+
+ if ((angle > to_angle && angle <= top_limit) ||
+ (angle + TAU > to_angle && angle + TAU <= top_limit)) {
+ angle -= modifier_angle;
+ if (angle < 0) {
+ angle += TAU;
+ }
+ } else if ((angle >= bottom_limit && angle < to_angle) ||
+ (angle - TAU >= bottom_limit && angle - TAU < to_angle)) {
+ angle += modifier_angle;
+ if (angle >= TAU) {
+ angle -= TAU;
+ }
+ } else {
+ angle = to_angle;
}
- if (down->GetStatus()) {
- --y;
+ }
+
+ void UpdateStatus() {
+ while (update_thread_running) {
+ const float coef = modifier->GetStatus() ? modifier_scale : 1.0f;
+
+ bool r = right->GetStatus();
+ bool l = left->GetStatus();
+ bool u = up->GetStatus();
+ bool d = down->GetStatus();
+
+ // Eliminate contradictory movements
+ if (r && l) {
+ r = false;
+ l = false;
+ }
+ if (u && d) {
+ u = false;
+ d = false;
+ }
+
+ // Move to the right
+ MoveToDirection(r && !u && !d, 0.0f);
+
+ // Move to the upper right
+ MoveToDirection(r && u && !d, Common::PI * 0.25f);
+
+ // Move up
+ MoveToDirection(u && !l && !r, Common::PI * 0.5f);
+
+ // Move to the upper left
+ MoveToDirection(l && u && !d, Common::PI * 0.75f);
+
+ // Move to the left
+ MoveToDirection(l && !u && !d, Common::PI);
+
+ // Move to the bottom left
+ MoveToDirection(l && !u && d, Common::PI * 1.25f);
+
+ // Move down
+ MoveToDirection(d && !l && !r, Common::PI * 1.5f);
+
+ // Move to the bottom right
+ MoveToDirection(r && !u && d, Common::PI * 1.75f);
+
+ // Move if a key is pressed
+ if (r || l || u || d) {
+ amplitude = coef;
+ } else {
+ amplitude = 0;
+ }
+
+ // Delay the update rate to 100hz
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
+ }
- const float coef = modifier->GetStatus() ? modifier_scale : 1.0f;
- return std::make_tuple(static_cast<float>(x) * coef * (y == 0 ? 1.0f : SQRT_HALF),
- static_cast<float>(y) * coef * (x == 0 ? 1.0f : SQRT_HALF));
+ std::tuple<float, float> GetStatus() const override {
+ return std::make_tuple(std::cos(angle) * amplitude, std::sin(angle) * amplitude);
}
bool GetAnalogDirectionStatus(Input::AnalogDirection direction) const override {
@@ -59,6 +136,11 @@ private:
Button right;
Button modifier;
float modifier_scale;
+ float modifier_angle;
+ float angle{};
+ float amplitude{};
+ std::thread update_thread;
+ bool update_thread_running{true};
};
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
auto right = Input::CreateDevice<Input::ButtonDevice>(params.Get("right", null_engine));
auto modifier = Input::CreateDevice<Input::ButtonDevice>(params.Get("modifier", null_engine));
auto modifier_scale = params.Get("modifier_scale", 0.5f);
+ auto modifier_angle = params.Get("modifier_angle", 0.035f);
return std::make_unique<Analog>(std::move(up), std::move(down), std::move(left),
- std::move(right), std::move(modifier), modifier_scale);
+ std::move(right), std::move(modifier), modifier_scale,
+ modifier_angle);
}
} // 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
adapter.get());
}
- UNREACHABLE();
return nullptr;
}
@@ -300,7 +299,8 @@ public:
return gcadapter->RumblePlay(port, 0);
}
- bool SetRumblePlay(f32 amp_low, f32 freq_low, f32 amp_high, f32 freq_high) const override {
+ bool SetRumblePlay(f32 amp_low, [[maybe_unused]] f32 freq_low, f32 amp_high,
+ [[maybe_unused]] f32 freq_high) const override {
const auto mean_amplitude = (amp_low + amp_high) * 0.5f;
const auto processed_amplitude =
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:
/// Unregisters SDL device factories and shut them down.
virtual ~State() = default;
- virtual Pollers GetPollers(Polling::DeviceType type) {
+ virtual Pollers GetPollers(Polling::DeviceType) {
return {};
}
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:
return joystick->RumblePlay(0, 0);
}
- bool SetRumblePlay(f32 amp_low, f32 freq_low, f32 amp_high, f32 freq_high) const override {
+ bool SetRumblePlay(f32 amp_low, [[maybe_unused]] f32 freq_low, f32 amp_high,
+ [[maybe_unused]] f32 freq_high) const override {
const auto process_amplitude = [](f32 amplitude) {
return static_cast<u16>((amplitude + std::pow(amplitude, 0.3f)) * 0.5f * 0xFFFF);
};
@@ -864,6 +865,8 @@ Common::ParamPackage SDLEventToMotionParamPackage(SDLState& state, const SDL_Eve
Common::ParamPackage BuildParamPackageForBinding(int port, const std::string& guid,
const SDL_GameControllerButtonBind& binding) {
switch (binding.bindType) {
+ case SDL_CONTROLLER_BINDTYPE_NONE:
+ break;
case SDL_CONTROLLER_BINDTYPE_AXIS:
return BuildAnalogParamPackageForButton(port, guid, binding.value.axis);
case SDL_CONTROLLER_BINDTYPE_BUTTON:
@@ -984,7 +987,7 @@ class SDLPoller : public InputCommon::Polling::DevicePoller {
public:
explicit SDLPoller(SDLState& state_) : state(state_) {}
- void Start(const std::string& device_id) override {
+ void Start([[maybe_unused]] const std::string& device_id) override {
state.event_queue.Clear();
state.polling = true;
}
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:
std::vector<std::tuple<std::unique_ptr<Input::ButtonDevice>, int, int>> map;
};
-std::unique_ptr<Input::TouchDevice> TouchFromButtonFactory::Create(
- const Common::ParamPackage& params) {
+std::unique_ptr<Input::TouchDevice> TouchFromButtonFactory::Create(const Common::ParamPackage&) {
return std::make_unique<TouchFromButtonDevice>();
}
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:
}
private:
- void HandleReceive(const boost::system::error_code& error, std::size_t bytes_transferred) {
+ void HandleReceive(const boost::system::error_code&, std::size_t bytes_transferred) {
if (auto type = Response::Validate(receive_buffer.data(), bytes_transferred)) {
switch (*type) {
case Type::Version: {
@@ -90,7 +90,7 @@ private:
StartReceive();
}
- void HandleSend(const boost::system::error_code& error) {
+ void HandleSend(const boost::system::error_code&) {
boost::system::error_code _ignored{};
// Send a request for getting port info for the pad
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
StartCommunication(client, host, port, pad_index, client_id);
}
-void Client::OnVersion(Response::Version data) {
+void Client::OnVersion([[maybe_unused]] Response::Version data) {
LOG_TRACE(Input, "Version packet received: {}", data.version);
}
-void Client::OnPortInfo(Response::PortInfo data) {
+void Client::OnPortInfo([[maybe_unused]] Response::PortInfo data) {
LOG_TRACE(Input, "PortInfo packet received: {}", data.model);
}
@@ -369,7 +369,7 @@ CalibrationConfigurationJob::CalibrationConfigurationJob(
u16 max_y{};
Status current_status{Status::Initialized};
- SocketCallback callback{[](Response::Version version) {}, [](Response::PortInfo info) {},
+ SocketCallback callback{[](Response::Version) {}, [](Response::PortInfo) {},
[&](Response::PadData data) {
if (current_status == Status::Initialized) {
// 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 @@
#include <array>
#include <optional>
#include <type_traits>
+
+#ifdef _MSC_VER
+#pragma warning(push)
+#pragma warning(disable : 4701)
+#endif
#include <boost/crc.hpp>
+#ifdef _MSC_VER
+#pragma warning(pop)
+#endif
+
#include "common/bit_field.h"
#include "common/swap.h"
@@ -93,7 +102,7 @@ static_assert(std::is_trivially_copyable_v<PadData>,
/**
* Creates a message with the proper header data that can be sent to the server.
- * @param T data Request body to send
+ * @param data Request body to send
* @param client_id ID of the udp client (usually not checked on the server)
*/
template <typename T>