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

46 lines
1.4 KiB
C++

#pragma once
// input_unified — frame-based unified input snapshot for SDL3.
// Issue 0072b. Keyboard + mouse + gamepad + touch mapped to logical buttons.
#include <SDL3/SDL.h>
namespace fn::input {
struct InputState {
// Logical buttons (any source mapped here).
bool left = false, right = false, up = false, down = false;
bool action_a = false, action_b = false, action_x = false, action_y = false;
bool start = false, back = false;
// Same buttons but "just pressed this frame" (rising edge).
bool left_pressed = false, right_pressed = false, up_pressed = false, down_pressed = false;
bool a_pressed = false, b_pressed = false, x_pressed = false, y_pressed = false;
bool start_pressed = false, back_pressed = false;
// Analog sticks [-1, 1].
float lx = 0.0f, ly = 0.0f, rx = 0.0f, ry = 0.0f;
// Mouse (window coords, pixels).
float mx = 0.0f, my = 0.0f;
bool m_left = false, m_right = false;
bool m_left_pressed = false, m_right_pressed = false;
// Touch (mobile / WASM). x/y normalized [0, 1].
struct Touch {
float x = 0.0f, y = 0.0f;
bool pressed = false;
int id = -1;
};
Touch touches[8];
int touch_count = 0;
};
// Call once per frame BEFORE processing SDL events. Clears *_pressed edges.
void input_begin_frame(InputState& s);
// Call for each SDL_Event in PollEvent loop.
void input_process_event(InputState& s, const SDL_Event* e);
} // namespace fn::input