summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon/ControllerInterface/ControllerInterface.h
diff options
context:
space:
mode:
authoriwubcode <iwubcode@users.noreply.github.com>2020-04-20 23:16:07 -0500
committeriwubcode <iwubcode@users.noreply.github.com>2021-03-17 20:58:33 -0500
commitdb4b4e40cb5c9d00940cdb76478b632804cdf244 (patch)
treeed9ba12bcc60ec1a34a72ada599853115b6c91d8 /Source/Core/InputCommon/ControllerInterface/ControllerInterface.h
parent679d51c2898b99c24ad904e891781a147b2f6667 (diff)
InputCommon / DolphinQt / Core: Add a "RelativeMouse" input which provides the raw delta mouse input
Co-authored-by: Jordan Woyak <jordan.woyak@gmail.com>
Diffstat (limited to 'Source/Core/InputCommon/ControllerInterface/ControllerInterface.h')
-rw-r--r--Source/Core/InputCommon/ControllerInterface/ControllerInterface.h53
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;