Skip to main content

Loop & Input API

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)>;           // dt = frame delta seconds
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.

MemberReturnsDescription
onPreRender(cb)voidCalled before rendering each frame. Use for game logic, physics, animation.
onRender(cb)voidCalled during the render phase
onPostRender(cb)voidCalled after rendering — use for UI, debug overlays, ImGui panels
onEvent(cb)voidCalled for every raw SDL_Event (window resize, mouse button, etc.)
onInput(cb)voidCalled for every translated semantic InputEvent

Input access

MemberReturnsDescription
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.

MemberReturnsDescription
runPreRender(dt)voidDispatch all pre-render callbacks
runRender(dt)voidDispatch all render callbacks
runPostRender(dt)voidDispatch all post-render callbacks
dispatchEvent(ev)voidTranslate 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.

ValueFuture purpose
RenderVsync-rate render thread
LogicFixed-rate game logic thread (e.g. 30 Hz)
PhysicsFixed-rate physics simulation thread
UIEvent-driven UI thread

glitter::input::InputMapper

Translates raw SDL events into semantic InputEvent values using a loaded KeybindScheme. Retrieve via engine::input() or LoopScheduler::inputMapper().

Constructor

Methods

MemberReturnsDescription
applyScheme(scheme)voidReplace 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)floatPoll a keyboard-driven axis in [-1, 1]. ScrollWheel is fire-once and always returns 0 here — read it from the dispatched AxisEvent instead.
beginFrame()voidCalled once per frame before callbacks. Reserved for gamepad polling.

KeybindScheme

FieldTypeDefaultDescription
namestd::string""Scheme identifier
mouseLookbooltrueEnable relative mouse mode (hides cursor) when this scheme is active
keyActionsmap<SDL_Keycode, Action>{}Key → discrete action bindings
keyAxesmap<SDL_Keycode, AxisBinding>{}Key → axis contribution bindings (e.g. W → {MoveZ, +1.0})

glitter::input::InputEvent

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

FieldTypeDescription
actionActionThe bound action
pressedbooltrue on key-down, false on key-up

AxisEvent

FieldTypeDescription
axisAxisThe bound axis
valuefloatKeyboard axes: the scaled key contribution. Mouse: pixel delta.

WindowResized

FieldTypeDescription
widthintNew window width in pixels
heightintNew window height in pixels

glitter::input::Action

Discrete actions that can be bound to keys:

ValueDescription
ToggleFXAAToggle FXAA anti-aliasing
ToggleFullscreenToggle fullscreen mode
SpeedBoostMultiply free-fly camera movement speed (typically Shift)

glitter::input::Axis

Continuous axes for polling or binding:

ValueDescription
MoveXStrafe left/right (A = -1, D = +1)
MoveZMove forward/back (W = +1, S = -1)
MoveYMove up/down (Q = +1, E = -1)
LookXMouse horizontal delta
LookYMouse vertical delta
ScrollWheelMouse scroll — fire-once, not polled via getAxis