From db4b4e40cb5c9d00940cdb76478b632804cdf244 Mon Sep 17 00:00:00 2001 From: iwubcode Date: Mon, 20 Apr 2020 23:16:07 -0500 Subject: InputCommon / DolphinQt / Core: Add a "RelativeMouse" input which provides the raw delta mouse input Co-authored-by: Jordan Woyak --- .../ControllerInterface/ControllerInterface.h | 53 ++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'Source/Core/InputCommon/ControllerInterface/ControllerInterface.h') diff --git a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.h b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.h index 254516fb6e..12d17614da 100644 --- a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.h +++ b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.h @@ -32,6 +32,23 @@ #endif #define CIFACE_USE_DUALSHOCKUDPCLIENT +namespace ciface +{ +// A thread local "input channel" is maintained to handle the state of relative inputs. +// This allows simultaneous use of relative inputs across different input contexts. +// e.g. binding relative mouse movements to both GameCube controllers and FreeLook. +// These operate at different rates and processing one would break the other without separate state. +enum class InputChannel +{ + Host, + SerialInterface, + Bluetooth, + FreeLook, + Count, +}; + +} // namespace ciface + // // ControllerInterface // @@ -66,6 +83,9 @@ public: void UnregisterDevicesChangedCallback(const HotplugCallbackHandle& handle); void InvokeDevicesChangedCallbacks() const; + static void SetCurrentInputChannel(ciface::InputChannel); + static ciface::InputChannel GetCurrentInputChannel(); + private: std::list> m_devices_changed_callbacks; mutable std::mutex m_callbacks_mutex; @@ -75,4 +95,37 @@ private: std::atomic m_aspect_ratio_adjustment = 1; }; +namespace ciface +{ +template +class RelativeInputState +{ +public: + void Update() + { + const auto channel = int(ControllerInterface::GetCurrentInputChannel()); + + m_value[channel] = m_delta[channel]; + m_delta[channel] = {}; + } + + T GetValue() const + { + const auto channel = int(ControllerInterface::GetCurrentInputChannel()); + + return m_value[channel]; + } + + void Move(T delta) + { + for (auto& d : m_delta) + d += delta; + } + +private: + std::array m_value; + std::array m_delta; +}; +} // namespace ciface + extern ControllerInterface g_controller_interface; -- cgit v1.2.3