Flint Engine
Modular C++20 2D game engine powered by SDL3
Loading...
Searching...
No Matches
input.h
1// SPDX-License-Identifier: MIT
2// SPDX-FileCopyrightText: 2025-2026 Manuel Osorio
3#pragma once
4
5#include "flint/input/event.h"
6#include "flint/window/IWindow.h"
7
8#include <SDL3/SDL_gamepad.h>
9#include <SDL3/SDL_keycode.h>
10
11#include <set>
12
13namespace Flint {
21 std::set<SDL_Keycode> keysDown;
22 std::set<Flint::GamepadButton> buttonsDown;
25 float rightTrigger = 0.f;
26 };
27
34 namespace InputManager {
36 extern bool isControllerActive;
37
39 extern SDL_Gamepad *g_gamepad;
40
51
59 std::set<SDL_Keycode> pollKeyboardState();
60
69
81 void updateInputSource(const IWindow &window);
82
93 void rumble(float lowFrequencyStrength, float highFrequencyStrength, Uint32 durationMs);
94
102
109 void shutdown();
110
119
130
131 static constexpr float AXIS_MAX_POSITIVE = 32767.f;
132 static constexpr float AXIS_MAX_NEGATIVE = 32768.f;
133 }
134}
Abstract interface for a platform window.
Definition IWindow.h:27
void shutdown()
Shut down the input system and release all resources.
InputSnapshot pollCurrentState()
Build a snapshot of the current state of all input devices.
void requestKeyboardRestore()
Schedule a one-shot keyboard state restore.
void detectController()
Detect and open the first available gamepad.
void updateInputSource(const IWindow &window)
Update isControllerActive based on recent device activity.
std::set< SDL_Keycode > pollKeyboardState()
Return the set of keyboard keys that are currently held down.
void resetKeyboardState()
Reset SDL's internal keyboard state, clearing any stuck keys.
void rumble(float lowFrequencyStrength, float highFrequencyStrength, Uint32 durationMs)
Trigger a rumble effect on the active gamepad.
bool consumeKeyboardRestoreRequest()
Consume and return any pending keyboard-restore request.
SDL_Gamepad * g_gamepad
Handle to the currently open gamepad, or nullptr if none is connected.
bool isControllerActive
True when the most recently active input source was a gamepad.
std::set< SDL_Keycode > keysDown
Definition input.h:21
std::set< Flint::GamepadButton > buttonsDown
Definition input.h:22
Immutable snapshot of all input device states at a single point in time.
Definition input.h:20