Skip to main content

InputManager Class

InputManager providing access to various input states. More...

Declaration

class helios::input::InputManager { ... }

Public Constructors Index

InputManager (std::unique_ptr< helios::input::InputAdapter > input)

Creates a new InputManager with the specified InputAdapter. More...

Public Member Functions Index

voidobserve (const helios::window::Window &win) noexcept

Sets the window this InputManager will observe for input. More...

const helios::window::Window *observedWindow () const

Returns a non-owning pointer to the currently observed window. More...

voidpoll (float deltaTime) noexcept

Polls events from the currently observed window and registered gamepads. More...

boolisKeyPressed (const helios::input::types::Key &key) const noexcept

Returns true if the specified key is currently pressed, otherwise false. More...

boolisKeyReleased (const helios::input::types::Key &key) const noexcept

Returns true if the specified key is currently released, otherwise false. More...

unsigned intregisterGamepads (unsigned int mask) noexcept

Explicitly tells this InputManager which gamepads to poll for input states in `poll()`. More...

const helios::input::gamepad::GamepadState &gamepadState (helios::input::types::Gamepad gamepadId) const noexcept

Returns a const reference to the `GamepadState` for the specified `gamepadId`. More...

boolisConnected (helios::input::types::Gamepad gamepadId) const noexcept

Returns true if the specified gamepad is connected, otherwise false. More...

const helios::input::InputAdapter &inputAdapter () const noexcept

Retrieves the InputAdapter associated with this InputManager. More...

helios::input::InputAdapter &inputAdapter () noexcept

Retrieves the InputAdapter associated with this InputManager. More...

Private Member Attributes Index

const helios::window::Window *observedWin_ = nullptr

A pointer to the currently observed window, which might be nullptr. More...

std::unique_ptr< helios::input::InputAdapter >input_

The InputAdapter owned by this InputManager. More...

unsigned intgamepadMask_ = 0x00

A bitmask used for registering the gamepads that should be polled for inputs. More...

Protected Static Attributes Index

static const helios::util::log::Logger &logger_ = helios::util::log::LogManager::loggerForScope(HELIOS_LOG_SCOPE)

Shared logger instance for all InputManager objects. More...

Description

InputManager providing access to various input states.

The `InputManager` acts as an intermediary between the application and the underlying systems that provide input. Raw events are processed by InputAdapters owned by this `InputManager`.

An `InputManager` allows querying `GamepadState` objects by calling `gamepadState()`. The method accepts an id that identifies the gamepad whose input state should be returned.

Definition at line 36 of file InputManager.ixx.

Public Constructors

InputManager()

helios::input::InputManager::InputManager (std::unique_ptr< helios::input::InputAdapter > input)
inline explicit

Creates a new InputManager with the specified InputAdapter.

Ownership of the InputAdapter is transferred to this InputManager.

Parameters
input

The InputAdapter used with this InputManager.

Definition at line 69 of file InputManager.ixx.

69 explicit InputManager(std::unique_ptr<helios::input::InputAdapter> input)
70 : input_(std::move(input)) {}

Public Member Functions

gamepadState()

const helios::input::gamepad::GamepadState & helios::input::InputManager::gamepadState (helios::input::types::Gamepad gamepadId)
inline nodiscard noexcept

Returns a const reference to the `GamepadState` for the specified `gamepadId`.

This method queries the `InputAdapter` owned by this `InputManager` for the `GamepadState` identified by the specified `gamepadId`. If no `GamepadState` exists for the given id, this method returns a `GamepadState` object initialized to its default values. To test whether a gamepad is available, use `isConnected()`.

`GamepadState` objects are updated by calling `poll()`.

Parameters
gamepadId

The id of the gamepad for which the `GamepadState` is queried.

Returns

A const reference to the `GamepadState` for the specified gamepad.

See Also

isConnected()

See Also

poll()

Definition at line 206 of file InputManager.ixx.

207 return input_->gamepadState(gamepadId);
208 }

inputAdapter()

const helios::input::InputAdapter & helios::input::InputManager::inputAdapter ()
inline nodiscard noexcept

Retrieves the InputAdapter associated with this InputManager.

Returns

A reference to the InputAdapter associated with this InputManager.

Definition at line 227 of file InputManager.ixx.

227 [[nodiscard]] const helios::input::InputAdapter& inputAdapter() const noexcept {
228 return *input_;
229 }

inputAdapter()

helios::input::InputAdapter & helios::input::InputManager::inputAdapter ()
inline nodiscard noexcept

Retrieves the InputAdapter associated with this InputManager.

This non-const overload allows modification of InputAdapter settings, such as gamepad deadzone and axis inversion configuration.

Returns

A reference to the InputAdapter associated with this InputManager.

Definition at line 239 of file InputManager.ixx.

239 [[nodiscard]] helios::input::InputAdapter& inputAdapter() noexcept {
240 return *input_;
241 }

isConnected()

bool helios::input::InputManager::isConnected (helios::input::types::Gamepad gamepadId)
inline nodiscard noexcept

Returns true if the specified gamepad is connected, otherwise false.

Parameters
gamepadId

The id of the gamepad to test.

Returns

True if a gamepad was found for the specified `gamepadId`, otherwise false.

Definition at line 217 of file InputManager.ixx.

217 [[nodiscard]] bool isConnected(helios::input::types::Gamepad gamepadId) const noexcept {
218 return input_->isConnected(gamepadId);
219 }

isKeyPressed()

bool helios::input::InputManager::isKeyPressed (const helios::input::types::Key & key)
inline nodiscard noexcept

Returns true if the specified key is currently pressed, otherwise false.

This method delegates to the underlying `InputAdapter`.

See Also

InputAdapter::isKeyPressed

Parameters
key

The key to check for the pressed state.

Returns

True if the key is pressed; returns false if the observed window is not set.

Definition at line 131 of file InputManager.ixx.

131 [[nodiscard]] bool isKeyPressed(const helios::input::types::Key& key) const noexcept {
132 if (observedWin_ == nullptr) {
133 logger_.warn("No window to observe.");
134 return false;
135 }
136
137 return input_->isKeyPressed(key, *observedWin_);
138 }

Reference logger_.

isKeyReleased()

bool helios::input::InputManager::isKeyReleased (const helios::input::types::Key & key)
inline nodiscard noexcept

Returns true if the specified key is currently released, otherwise false.

This method delegates to the underlying `InputAdapter`.

See Also

InputAdapter::isKeyReleased

Parameters
key

The key to check for the released state.

Returns

True if the key is released; returns false if the observed window is not set.

Definition at line 151 of file InputManager.ixx.

151 [[nodiscard]] bool isKeyReleased(const helios::input::types::Key& key) const noexcept {
152 if (observedWin_ == nullptr) {
153 logger_.warn("No window to observe.");
154 return false;
155 }
156
157 return input_->isKeyReleased(key, *observedWin_);
158 }

Reference logger_.

observe()

void helios::input::InputManager::observe (const helios::window::Window & win)
inline noexcept

Sets the window this InputManager will observe for input.

All subsequent input queries will be performed on this window.

Parameters
win

A const reference to the window to observe.

Definition at line 80 of file InputManager.ixx.

80 void observe(const helios::window::Window& win) noexcept {
81 observedWin_ = &win;
82 }

observedWindow()

const helios::window::Window * helios::input::InputManager::observedWindow ()
inline nodiscard

Returns a non-owning pointer to the currently observed window.

Returns `nullptr` if no window is currently observed.

Returns

A non-owning pointer to the currently observed window, or `nullptr`.

Definition at line 92 of file InputManager.ixx.

92 [[nodiscard]] const helios::window::Window* observedWindow() const {
93 return observedWin_;
94 }

poll()

void helios::input::InputManager::poll (float deltaTime)
inline noexcept

Polls events from the currently observed window and registered gamepads.

Calls the `pollEvents()` method of the observed window to process any pending window-related input events. This method should be called regularly, preferably once per frame. For updating `GamepadState` objects with their current input states, call `registerGamepads()` with a bitmask representing the gamepads to poll.

See Also

Window::pollEvents

Parameters
deltaTime

The time elapsed since the last frame, in seconds.

Definition at line 110 of file InputManager.ixx.

110 void poll(float deltaTime) noexcept {
111 if (observedWin_ != nullptr) {
112 observedWin_->pollEvents();
113 } else {
114 logger_.warn("No window to observe.");
115 }
116 input_->updateGamepadState(gamepadMask_);
117 }

Reference logger_.

registerGamepads()

unsigned int helios::input::InputManager::registerGamepads (unsigned int mask)
inline noexcept

Explicitly tells this InputManager which gamepads to poll for input states in `poll()`.

Parameters
gamepadMask

A bitmask representing the gamepad ids that should be observed by this InputManager (e.g. `registerGamepads(Gamepad::ONE | Gamepad::THREE)`).

Returns

The bitmask this InputManager uses for polling gamepad states. If an invalid mask is provided, the method returns a mask that represents no gamepads.

Definition at line 171 of file InputManager.ixx.

171 unsigned int registerGamepads(unsigned int mask) noexcept {
172 const unsigned int maxMask = static_cast<int>(std::pow(
173 helios::input::types::Gamepad::size_,
174 2.0f
175 ) - 1);
176 assert(mask <= maxMask && "mask out of bounds");
177 if (mask > maxMask) {
178 logger_.warn("Gamepad mask out of bounds. Clamping to maximum valid value.");
179 mask = maxMask;
180 }
181
182
183 gamepadMask_ = mask;
184
185 return gamepadMask_;
186 }

Reference logger_.

Private Member Attributes

gamepadMask_

unsigned int helios::input::InputManager::gamepadMask_ = 0x00

A bitmask used for registering the gamepads that should be polled for inputs.

Definition at line 52 of file InputManager.ixx.

52 unsigned int gamepadMask_ = 0x00;

input_

std::unique_ptr<helios::input::InputAdapter> helios::input::InputManager::input_

The InputAdapter owned by this InputManager.

Definition at line 47 of file InputManager.ixx.

47 std::unique_ptr<helios::input::InputAdapter> input_;

observedWin_

const helios::window::Window* helios::input::InputManager::observedWin_ = nullptr

A pointer to the currently observed window, which might be nullptr.

Definition at line 42 of file InputManager.ixx.

42 const helios::window::Window* observedWin_ = nullptr;

Protected Static Attributes

logger_

const helios::util::log::Logger& helios::input::InputManager::logger_ = helios::util::log::LogManager::loggerForScope(HELIOS_LOG_SCOPE)
protected static

Shared logger instance for all InputManager objects.

Definition at line 58 of file InputManager.ixx.

Referenced by isKeyPressed, isKeyReleased, poll and registerGamepads.


The documentation for this class was generated from the following file:


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.