cb6d9e61d1
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
49 lines
2.0 KiB
Markdown
49 lines
2.0 KiB
Markdown
---
|
|
name: input_unified
|
|
kind: function
|
|
lang: cpp
|
|
domain: gamedev
|
|
version: "0.1.0"
|
|
purity: impure
|
|
signature: "input_begin_frame(InputState&); input_process_event(InputState&, const SDL_Event*)"
|
|
description: "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."
|
|
tags: [gamedev, input, sdl3, touch, gamepad]
|
|
uses_functions: []
|
|
uses_types: []
|
|
returns: []
|
|
returns_optional: false
|
|
error_type: "error_go_core"
|
|
imports: []
|
|
example: |
|
|
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;
|
|
tested: false
|
|
tests: []
|
|
test_file_path: ""
|
|
file_path: "cpp/functions/gamedev/input_unified.cpp"
|
|
params:
|
|
- name: state
|
|
desc: "InputState mantenido por la app entre frames (bools held + analog axes + touch slots)."
|
|
- name: event
|
|
desc: "Puntero al SDL_Event devuelto por SDL_PollEvent en el loop principal."
|
|
output: "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`.
|