Files
fn_registry/cpp/functions/gamedev/input_unified.md
T

2.0 KiB

name, kind, lang, domain, version, purity, signature, description, tags, uses_functions, uses_types, returns, returns_optional, error_type, imports, example, tested, tests, test_file_path, file_path, params, output
name kind lang domain version purity signature description tags uses_functions uses_types returns returns_optional error_type imports example tested tests test_file_path file_path params output
input_unified function cpp gamedev 0.1.0 impure input_begin_frame(InputState&); input_process_event(InputState&, const SDL_Event*) Snapshot unificado de input por frame para SDL3. Mapea keyboard (WASD+arrows), mouse, gamepad (SDL_Gamepad) y touch a botones logicos (left/right/up/down/action_a..y/start/back) y ejes analogicos. Expone flags *_pressed con rising edge limpio cada frame. Issue 0072b — runtime gamedev PC + WASM.
gamedev
input
sdl3
touch
gamepad
false error_go_core
fn::input::InputState input{}; // per frame: fn::input::input_begin_frame(input); SDL_Event e; while (SDL_PollEvent(&e)) { fn::input::input_process_event(input, &e); } if (input.a_pressed) jump(); player.x += input.lx * speed * dt; false
cpp/functions/gamedev/input_unified.cpp
name desc
state InputState mantenido por la app entre frames (bools held + analog axes + touch slots).
name desc
event Puntero al SDL_Event devuelto por SDL_PollEvent en el loop principal.
Mutaciones in-place sobre InputState. Sin retorno. Sin asignaciones dinamicas.

input_unified

Capa fina sobre SDL3 que normaliza todas las fuentes de input a un struct plano consultable cada frame. Sirve como fundacion para apps gamedev del registry (issue 0072b) y para tests headless.

Reglas de uso:

  • input_begin_frame se llama UNA vez por frame antes de bombear eventos. Limpia los flags *_pressed (rising edge), no los * held.
  • input_process_event se llama por cada SDL_Event recibido. Acumula state hasta que el siguiente begin_frame resetee edges.
  • Stick deadzone fijo a 0.15 — si la app necesita custom, reescribir snapshot tras la lectura.
  • Touch ids estables mientras el dedo este pressed; al soltar se compacta el array.
  • Gamepads conectados se abren automaticamente en SDL_EVENT_GAMEPAD_ADDED.