diff options
Diffstat (limited to 'Source/Core/InputCommon/ControllerInterface/ControllerInterface.h')
| -rw-r--r-- | Source/Core/InputCommon/ControllerInterface/ControllerInterface.h | 53 |
1 files changed, 53 insertions, 0 deletions
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<std::function<void()>> m_devices_changed_callbacks; mutable std::mutex m_callbacks_mutex; @@ -75,4 +95,37 @@ private: std::atomic<float> m_aspect_ratio_adjustment = 1; }; +namespace ciface +{ +template <typename T> +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<T, int(InputChannel::Count)> m_value; + std::array<T, int(InputChannel::Count)> m_delta; +}; +} // namespace ciface + extern ControllerInterface g_controller_interface; |
