Flint Engine
Modular C++20 2D game engine powered by SDL3
Loading...
Searching...
No Matches
Flint::InputManager Namespace Reference

Namespace encapsulating all input polling and gamepad management. More...

Functions

FLINT_API InputSnapshot pollCurrentState ()
 Build a snapshot of the current state of all input devices.
 
FLINT_API std::set< SDL_Keycode > pollKeyboardState ()
 Return the set of keyboard keys that are currently held down.
 
FLINT_API void detectController ()
 Detect and open the first available gamepad.
 
FLINT_API void updateInputSource (const IWindow &window)
 Update isControllerActive based on recent device activity.
 
FLINT_API void rumble (float lowFrequencyStrength, float highFrequencyStrength, Uint32 durationMs)
 Trigger a rumble effect on the active gamepad.
 
FLINT_API void resetKeyboardState ()
 Reset SDL's internal keyboard state, clearing any stuck keys.
 
FLINT_API void shutdown ()
 Shut down the input system and release all resources.
 
FLINT_API void requestKeyboardRestore ()
 Schedule a one-shot keyboard state restore.
 
FLINT_API bool consumeKeyboardRestoreRequest ()
 Consume and return any pending keyboard-restore request.
 

Variables

FLINT_API bool isControllerActive
 True when the most recently active input source was a gamepad.
 
FLINT_API SDL_Gamepad * g_gamepad
 Handle to the currently open gamepad, or nullptr if none is connected.
 

Detailed Description

Namespace encapsulating all input polling and gamepad management.

Call detectController() once at startup and updateInputSource() each frame to keep isControllerActive in sync with recent hardware activity.

Function Documentation

◆ consumeKeyboardRestoreRequest()

FLINT_API bool Flint::InputManager::consumeKeyboardRestoreRequest ( )

Consume and return any pending keyboard-restore request.

Returns true once for each prior call to requestKeyboardRestore(), then resets the internal flag so subsequent calls return false until a new request is made.

Returns
true if a restore was requested since the last check.

◆ detectController()

FLINT_API void Flint::InputManager::detectController ( )

Detect and open the first available gamepad.

Enumerates attached controllers and opens the first one found, storing the handle in g_gamepad and setting isControllerActive to true. Safe to call when a controller is already open; the existing handle is reused.

◆ pollCurrentState()

FLINT_API InputSnapshot Flint::InputManager::pollCurrentState ( )

Build a snapshot of the current state of all input devices.

Queries SDL directly for keyboard state and, if g_gamepad is non-null, for gamepad buttons and axes. Each call is independent of prior calls.

Returns
An InputSnapshot capturing keyboard keys, gamepad buttons, analogue sticks, and the right trigger.

◆ pollKeyboardState()

FLINT_API std::set< SDL_Keycode > Flint::InputManager::pollKeyboardState ( )

Return the set of keyboard keys that are currently held down.

Convenience wrapper that ignores gamepad state.

Returns
A set of SDL_Keycode values for all currently pressed keys.

◆ requestKeyboardRestore()

FLINT_API void Flint::InputManager::requestKeyboardRestore ( )

Schedule a one-shot keyboard state restore.

Sets an internal flag that is consumed by consumeKeyboardRestoreRequest(). Intended for use when an external event (e.g. focus change) requires a keyboard state refresh on the next frame. Thread-safe.

◆ resetKeyboardState()

FLINT_API void Flint::InputManager::resetKeyboardState ( )

Reset SDL's internal keyboard state, clearing any stuck keys.

Call after focus changes or synthetic input injection to ensure the next poll reflects actual hardware state.

◆ rumble()

FLINT_API void Flint::InputManager::rumble ( float lowFrequencyStrength,
float highFrequencyStrength,
Uint32 durationMs )

Trigger a rumble effect on the active gamepad.

Clamps both strength parameters to [0, 1], converts to the 16-bit range expected by SDL, and invokes the SDL rumble API. No-op if g_gamepad is nullptr.

Parameters
lowFrequencyStrengthIntensity of the low-frequency motor in [0, 1].
highFrequencyStrengthIntensity of the high-frequency motor in [0, 1].
durationMsDuration in milliseconds.

◆ shutdown()

FLINT_API void Flint::InputManager::shutdown ( )

Shut down the input system and release all resources.

Closes the active gamepad (if any) and clears g_gamepad. Gamepad operations become no-ops until detectController() is called again.

◆ updateInputSource()

FLINT_API void Flint::InputManager::updateInputSource ( const IWindow & window)

Update isControllerActive based on recent device activity.

Inspects keyboard, mouse, and gamepad activity this frame:

  • Any keyboard or mouse activity → isControllerActive = false.
  • Any gamepad button or axis activity → isControllerActive = true.

Does nothing if window is not currently open.

Parameters
windowThe window whose open state gates input processing.