Skip to main content

InputAdapter.ixx File

Abstract interface for platform-specific input adapters. More...

Included Headers

#include <bit> #include <memory> #include <array> #include <utility> #include <helios.input.gamepad.DeadzoneStrategy> #include <helios.input.gamepad.GamepadSettings> #include <helios.util.log.LogManager> #include <helios.util.log.Logger> #include <helios.window.Window> #include <helios.input.types.Key> #include <helios.input.gamepad.GamepadState> #include <helios.input.types.Gamepad>

Namespaces Index

namespacehelios
namespaceinput

Input handling and management. More...

Classes Index

classInputAdapter

Abstract interface for platform-specific input adapters. More...

Macro Definitions Index

#defineHELIOS_LOG_SCOPE   "helios::input::InputAdapter"

Description

Abstract interface for platform-specific input adapters.

Macro Definitions

HELIOS_LOG_SCOPE

#define HELIOS_LOG_SCOPE   "helios::input::InputAdapter"

Definition at line 23 of file InputAdapter.ixx.

23#define HELIOS_LOG_SCOPE "helios::input::InputAdapter"

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file InputAdapter.ixx
3 * @brief Abstract interface for platform-specific input adapters.
4 */
5module;
6
7#include <bit>
8#include <memory>
9#include <array>
10#include <utility>
11
12export module helios.input.InputAdapter;
13
14import helios.input.types.Gamepad;
15import helios.input.gamepad.GamepadState;
16import helios.input.types.Key;
17import helios.window.Window;
18import helios.util.log.Logger;
19import helios.util.log.LogManager;
20import helios.input.gamepad.GamepadSettings;
21import helios.input.gamepad.DeadzoneStrategy;
22
23#define HELIOS_LOG_SCOPE "helios::input::InputAdapter"
24export namespace helios::input {
25
26 /**
27 * @brief Abstract interface for platform-specific input adapters.
28 *
29 * Provides a unified interface for querying input device states across different
30 * platforms. Concrete implementations translate generic input queries into
31 * platform-specific API calls.
32 *
33 * The adapter manages per-gamepad configuration through `GamepadSettings` and applies
34 * input normalization via a configurable `DeadzoneStrategy`.
35 *
36 * @see GLFWInputAdapter for a GLFW-based implementation.
37 * @see GamepadSettings for per-controller configuration options.
38 * @see DeadzoneStrategy for input normalization strategies.
39 */
41
42 protected:
43 /**
44 * @brief Shared logger instance for all InputAdapter objects.
45 */
47
48 /**
49 * @brief Strategy used to normalize analog stick input within deadzones.
50 *
51 * Ownership is held by the adapter. Applied during gamepad state updates
52 * to filter out hardware drift and rescale input values.
53 */
54 std::unique_ptr<helios::input::gamepad::DeadzoneStrategy> deadzoneStrategy_;
55
56 /**
57 * @brief Per-gamepad configuration settings.
58 *
59 * Array indexed by gamepad ID, storing deadzone thresholds and axis
60 * inversion flags for each connected controller.
61 */
62 std::array<helios::input::gamepad::GamepadSettings, std::to_underlying(helios::input::types::Gamepad::size_)> gamepadSettings_ = {};
63
64
65 public:
66
67 /**
68 * @brief Virtual destructor for proper polymorphic cleanup.
69 */
70 virtual ~InputAdapter() = default;
71
72 /**
73 * @brief Constructs an InputAdapter with the specified deadzone strategy.
74 *
75 * @param deadzoneStrategy The strategy used for analog stick normalization.
76 * Ownership is transferred to this adapter.
77 */
78 explicit InputAdapter(std::unique_ptr<helios::input::gamepad::DeadzoneStrategy> deadzoneStrategy) :
79 deadzoneStrategy_(std::move(deadzoneStrategy))
80 {}
81
82 /**
83 * @brief Returns true if the key is pressed, otherwise false.
84 *
85 * @param key The key to query for the `pressed` state.
86 * @param win The window instance from which the state should be queried.
87 *
88 * @return True if the key is pressed, otherwise false.
89 */
90 [[nodiscard]] virtual bool isKeyPressed(
92 const helios::window::Window& win) const noexcept = 0;
93
94 /**
95 * @brief Returns true if the key is released, otherwise false.
96 *
97 * @param key The key to query for the `released` state.
98 * @param win The window instance from which the state should be queried.
99 *
100 * @return True if the key is released, otherwise false.
101 */
102 [[nodiscard]] virtual bool isKeyReleased(
104 const helios::window::Window& win) const noexcept = 0;
105
106
107 /**
108 * @brief Returns a boolean value indicating the availability (i.e., connect state)
109 * of the gamepad identified by the specified gamepadId.
110 *
111 * @param gamepadId The gamepadId to query for availability.
112 *
113 * @return true if the Gamepad identified by gamepadId is connected, otherwise false.
114 */
115 [[nodiscard]] virtual bool isConnected(helios::input::types::Gamepad gamepadId) const noexcept = 0;
116
117
118 /**
119 * @brief Updates the GamepadState objects with the values queried from the
120 * underlying Gamepad identified by the specified mask.
121 *
122 * Updates the GamepadState objects with the current values of the underlying
123 * hardware. If querying the underlying hardware fails, this method will
124 * update the GamepadState values to a valid initial state (no movement or interaction).
125 * Implementations should use `isConnected()` to check whether the current values of a
126 * `GamepadState` object can be trusted.
127 *
128 * @param gamepadMask A bitmask representing all GamepadState objects to update,
129 * e.g. Gamepad::ONE | Gamepad::TWO...
130 */
131 virtual void updateGamepadState(unsigned int gamepadMask) noexcept = 0;
132
133
134 /**
135 * @brief Returns a const ref to the GamepadState-object for the specified gamepadId.
136 *
137 * Implementing APIs can call this method in each frame to retrieve the current
138 * state for the gamepad, as computed by updateGamepadState().
139 * This method guarantees that for a given gamepadId, a single GamepadState object is
140 * reused across calls, avoiding re-instantiation overhead.
141 *
142 * @param gamepadId The id of the gamepad to query
143 *
144 * @return Returns a const ref to the GamepadState. If the GamepadState was never queried
145 * before, or if a recent call to updateGamepadState did not succeed, the values of the
146 * GamepadState will not hold representative values. Implementing APIs should verify the
147 * availability of the Gamepad by calling isConnected()
148 *
149 * @see updateGamepadState
150 * @see isConnected
151 */
153 helios::input::types::Gamepad gamepadId) const noexcept = 0;
154
155
156 /**
157 * @brief Returns the configuration settings for the specified gamepad.
158 *
159 * Provides access to the mutable settings object for the given gamepad,
160 * allowing runtime configuration of deadzone thresholds and axis inversion.
161 * Changes to the returned settings are applied during subsequent calls
162 * to `updateGamepadState()`.
163 *
164 * @param gamepadId The gamepad to retrieve settings for.
165 *
166 * @return Reference to the mutable GamepadSettings for the specified gamepad.
167 *
168 * @see GamepadSettings for available configuration options.
169 */
171 const auto id = static_cast<unsigned int>(gamepadId);
172 const auto idx = std::countr_zero(id);
173
174 return gamepadSettings_[idx];
175 }
176 };
177
178}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.