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/core/api.h"
6#include "flint/input/event.h"
7#include "flint/window/IWindow.h"
8
9#include <SDL3/SDL_gamepad.h>
10#include <SDL3/SDL_keycode.h>
11
12#include <set>
13
14namespace Flint {
22 std::set<SDL_Keycode> keysDown;
23 std::set<Flint::GamepadButton> buttonsDown;
26 float rightTrigger = 0.f;
27 };
28
35 namespace InputManager {
37 extern FLINT_API bool isControllerActive;
38
40 extern FLINT_API SDL_Gamepad *g_gamepad;
41
52
60 FLINT_API std::set<SDL_Keycode> pollKeyboardState();
61
69 FLINT_API void detectController();
70
82 FLINT_API void updateInputSource(const IWindow &window);
83
94 FLINT_API void rumble(float lowFrequencyStrength, float highFrequencyStrength,
95 Uint32 durationMs);
96
103 FLINT_API void resetKeyboardState();
104
111 FLINT_API void shutdown();
112
120 FLINT_API void requestKeyboardRestore();
121
132
133 static constexpr float AXIS_MAX_POSITIVE = 32767.f;
134 static constexpr float AXIS_MAX_NEGATIVE = 32768.f;
135 }
136}
Abstract interface for a platform window.
Definition IWindow.h:27
FLINT_API std::set< SDL_Keycode > pollKeyboardState()
Return the set of keyboard keys that are currently held down.
FLINT_API void rumble(float lowFrequencyStrength, float highFrequencyStrength, Uint32 durationMs)
Trigger a rumble effect on the active gamepad.
FLINT_API void shutdown()
Shut down the input system and release all resources.
FLINT_API void detectController()
Detect and open the first available gamepad.
FLINT_API bool consumeKeyboardRestoreRequest()
Consume and return any pending keyboard-restore request.
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.
FLINT_API void requestKeyboardRestore()
Schedule a one-shot keyboard state restore.
FLINT_API void updateInputSource(const IWindow &window)
Update isControllerActive based on recent device activity.
FLINT_API void resetKeyboardState()
Reset SDL's internal keyboard state, clearing any stuck keys.
FLINT_API InputSnapshot pollCurrentState()
Build a snapshot of the current state of all input devices.
Immutable snapshot of all input device states at a single point in time.
Definition input.h:21
std::set< SDL_Keycode > keysDown
Definition input.h:22
std::set< Flint::GamepadButton > buttonsDown
Definition input.h:23