Skip to main content

InputManager Class

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

Declaration

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

Public Constructors Index

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

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

Public Member Functions Index

voidpoll (float deltaTime) noexcept

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

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

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

boolisKeyReleased (const helios::engine::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::engine::input::gamepad::GamepadState &gamepadState (const helios::engine::input::types::Gamepad gamepadId) const noexcept

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

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

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

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

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

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

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

Private Member Attributes Index

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

A pointer to the currently observed window, which might be nullptr. 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::engine::util::log::Logger &logger_ = helios::engine::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 41 of file InputManager.ixx.

Public Constructors

InputManager()

helios::engine::input::InputManager::InputManager (std::unique_ptr< helios::engine::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 74 of file InputManager.ixx.

74 explicit InputManager(std::unique_ptr<helios::engine::input::InputAdapter> input)
75 : input_(std::move(input)) {}

Public Member Functions

gamepadState()

const helios::engine::input::gamepad::GamepadState & helios::engine::input::InputManager::gamepadState (const helios::engine::input::types::Gamepad gamepadId)
inline 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 213 of file InputManager.ixx.

214 return input_->gamepadState(gamepadId);
215 }

Reference helios::registerComponents.

inputAdapter()

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

Retrieves the InputAdapter associated with this InputManager.

Returns

A reference to the InputAdapter associated with this InputManager.

Definition at line 234 of file InputManager.ixx.

235 return *input_;
236 }

inputAdapter()

helios::engine::input::InputAdapter & helios::engine::input::InputManager::inputAdapter ()
inline 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 246 of file InputManager.ixx.

isConnected()

bool helios::engine::input::InputManager::isConnected (helios::engine::input::types::Gamepad gamepadId)
inline 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 224 of file InputManager.ixx.

225 return input_->isConnected(gamepadId);
226 }

Reference helios::registerComponents.

isKeyPressed()

bool helios::engine::input::InputManager::isKeyPressed (const helios::engine::input::types::Key & key)
inline 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 136 of file InputManager.ixx.

136 [[nodiscard]] bool isKeyPressed(const helios::engine::input::types::Key& key) const noexcept {
137 /* if (observedWin_ == nullptr) {
138 logger_.warn("No window to observe.");
139 return false;
140 }*/
141
142 //return input_->isKeyPressed(key, observedWin_);
143 return false;
144 }

isKeyReleased()

bool helios::engine::input::InputManager::isKeyReleased (const helios::engine::input::types::Key & key)
inline 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 157 of file InputManager.ixx.

157 [[nodiscard]] bool isKeyReleased(const helios::engine::input::types::Key& key) const noexcept {
158 /* if (observedWin_ == nullptr) {
159 logger_.warn("No window to observe.");
160 return false;
161 }
162*/
163 return false;
164 //return input_->isKeyReleased(key, *observedWin_);
165 }

poll()

void helios::engine::input::InputManager::poll (float deltaTime)
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.

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.

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 115 of file InputManager.ixx.

115 void poll(float deltaTime) noexcept {
116 // if (observedWin_ != nullptr) {
117 // observedWin_->pollEvents();
118 //} else {
119 // logger_.warn("No window to observe.");
120 //}
121 input_->updateGamepadState(gamepadMask_);
122 }

registerGamepads()

unsigned int helios::engine::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 178 of file InputManager.ixx.

178 unsigned int registerGamepads(unsigned int mask) noexcept {
179 const unsigned int maxMask = static_cast<int>(std::pow(
180 helios::engine::input::types::Gamepad::size_,
181 2.0f
182 ) - 1);
183 assert(mask <= maxMask && "mask out of bounds");
184 if (mask > maxMask) {
185 logger_.warn("Gamepad mask out of bounds. Clamping to maximum valid value.");
186 mask = maxMask;
187 }
188
189
190 gamepadMask_ = mask;
191
192 return gamepadMask_;
193 }

References logger_, helios::registerComponents and helios::engine::util::log::Logger::warn.

Private Member Attributes

gamepadMask_

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

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

Definition at line 57 of file InputManager.ixx.

57 unsigned int gamepadMask_ = 0x00;

input_

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

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

The InputAdapter owned by this InputManager.

Definition at line 52 of file InputManager.ixx.

52 std::unique_ptr<helios::engine::input::InputAdapter> input_;

Protected Static Attributes

logger_

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

Shared logger instance for all InputManager objects.

Definition at line 63 of file InputManager.ixx.

Referenced by registerGamepads.


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


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.