Skip to content

Gamepads

Generated from engine/input/gamepads.h at 862e08b. The text under each declaration is the header's own comment, word for word. About the reference says how these pages are made.

Browse the input module

#include "engine/input/gamepads.h" · namespace labrador

class Gamepads

Every pad, this frame and last, and the edges between them.

WHY THE ENGINE POLLS THIS AND A GAME DOES NOT. An edge is "down now, up last frame", so it is only right if "last frame" is the frame before this one. An edge detector a game keeps for itself advances its "previous" only on the frames its owner happens to be running, so it needs priming by hand at every transition, and a second one - menus beside gameplay - drifts from the first. Application polls this once per frame, before any state updates, so every reader measures across the same two frames and nothing is primed.

A slot is a slot. It is the index the pad API answers for, not the order pads were plugged in, and it is not stable across a replug - a controller that comes back in a different slot is a different slot. Binding a player to one for the length of a match is a decision a game makes; the engine reports connected(), just_connected() and just_disconnected() so that it can make it, and makes none itself.

static constexpr int max_count = 4;
explicit Gamepads(GamepadReader* reader);

reader is borrowed and must outlive this.

void poll();

Reads every slot. What was current becomes previous, so every edge below is measured across exactly one frame.

const GamepadState& state(int slot) const;
const GamepadState& previous_state(int slot) const;

Throw std::out_of_range naming the slot if it is not in [0, max_count). A slot outside that is a bug in the caller rather than an absent pad, and the two deserve different answers (T6).

bool held(int slot, GamepadButton button) const;
bool pressed(int slot, GamepadButton button) const;
bool released(int slot, GamepadButton button) const;

trigger_held · trigger_pressed · trigger_released

Section titled “trigger_held · trigger_pressed · trigger_released”
bool trigger_held(int slot, GamepadTrigger trigger,
float threshold) const;
bool trigger_pressed(int slot, GamepadTrigger trigger,
float threshold) const;
bool trigger_released(int slot, GamepadTrigger trigger,
float threshold) const;

A trigger is analogue, so an edge on one needs the threshold that makes it a button. The caller supplies it because no single value is right for every use of the same trigger.

connected · just_connected · just_disconnected

Section titled “connected · just_connected · just_disconnected”
bool connected(int slot) const;
bool just_connected(int slot) const;
bool just_disconnected(int slot) const;

Named in the public declarations above: GamepadButton, GamepadReader, GamepadState, GamepadTrigger.

The files that include this header directly. A file can also reach it through another header.

Development documentation (unreleased). Built from Labrador 862e08b of 2026-10-08.