Headers: src/loop/loopScheduler.h, src/system/input/inputMapper.h, src/system/input/inputEvent.h
Namespaces: glitter::loop, glitter::input
glitter::loop::LoopScheduler
Manages per-frame callbacks for the engine's main loop. Retrieve via engine::loop().
Callback types
src/loop/loopScheduler.h
using RenderCallback = std::function<void(float dt)>;
using EventCallback = std::function<void(const SDL_Event&)>;
using InputCallback = std::function<void(const input::InputEvent&)>;
Registering callbacks
Multiple callbacks can be registered per slot; they are called in registration order.
| Member | Returns | Description |
|---|
onPreRender(cb) | void | Called before rendering each frame. Use for game logic, physics, animation. |
onRender(cb) | void | Called during the render phase |
onPostRender(cb) | void | Called after rendering — use for UI, debug overlays, ImGui panels |
onEvent(cb) | void | Called for every raw SDL_Event (window resize, mouse button, etc.) |
onInput(cb) | void | Called for every translated semantic InputEvent |
| Member | Returns | Description |
|---|
inputMapper() | InputMapper& | Direct access to the input mapper for axis polling |
Frame dispatch (called by engine::run())
These are called by the engine loop — game code does not call them directly.
| Member | Returns | Description |
|---|
runPreRender(dt) | void | Dispatch all pre-render callbacks |
runRender(dt) | void | Dispatch all render callbacks |
runPostRender(dt) | void | Dispatch all post-render callbacks |
dispatchEvent(ev) | void | Translate an SDL event to input events and dispatch to all callbacks |
glitter::loop::TickGroup
Thread-affinity tag for future multi-threading support. Currently informational — all groups execute on the main thread.
| Value | Future purpose |
|---|
Render | Vsync-rate render thread |
Logic | Fixed-rate game logic thread (e.g. 30 Hz) |
Physics | Fixed-rate physics simulation thread |
UI | Event-driven UI thread |
Translates raw SDL events into semantic InputEvent values using a loaded KeybindScheme. Retrieve via engine::input() or LoopScheduler::inputMapper().
Constructor
Methods
| Member | Returns | Description |
|---|
applyScheme(scheme) | void | Replace all key→action and key→axis bindings with those from scheme. Also sets mouse-look mode from scheme.mouseLook. |
translate(sdlEvent) | std::vector<InputEvent> | Map a raw SDL event to zero or more semantic InputEvent values |
getAxis(axis) | float | Poll a keyboard-driven axis in [-1, 1]. ScrollWheel is fire-once and always returns 0 here — read it from the dispatched AxisEvent instead. |
beginFrame() | void | Called once per frame before callbacks. Reserved for gamepad polling. |
KeybindScheme
| Field | Type | Default | Description |
|---|
name | std::string | "" | Scheme identifier |
mouseLook | bool | true | Enable relative mouse mode (hides cursor) when this scheme is active |
keyActions | map<SDL_Keycode, Action> | {} | Key → discrete action bindings |
keyAxes | map<SDL_Keycode, AxisBinding> | {} | Key → axis contribution bindings (e.g. W → {MoveZ, +1.0}) |
Semantic event produced by InputMapper::translate(). A std::variant over three event types:
src/system/input/inputEvent.h
using InputEvent = std::variant<ActionEvent, AxisEvent, WindowResized>;
ActionEvent
| Field | Type | Description |
|---|
action | Action | The bound action |
pressed | bool | true on key-down, false on key-up |
AxisEvent
| Field | Type | Description |
|---|
axis | Axis | The bound axis |
value | float | Keyboard axes: the scaled key contribution. Mouse: pixel delta. |
WindowResized
| Field | Type | Description |
|---|
width | int | New window width in pixels |
height | int | New window height in pixels |
Discrete actions that can be bound to keys:
| Value | Description |
|---|
ToggleFXAA | Toggle FXAA anti-aliasing |
ToggleFullscreen | Toggle fullscreen mode |
SpeedBoost | Multiply free-fly camera movement speed (typically Shift) |
Continuous axes for polling or binding:
| Value | Description |
|---|
MoveX | Strafe left/right (A = -1, D = +1) |
MoveZ | Move forward/back (W = +1, S = -1) |
MoveY | Move up/down (Q = +1, E = -1) |
LookX | Mouse horizontal delta |
LookY | Mouse vertical delta |
ScrollWheel | Mouse scroll — fire-once, not polled via getAxis |