main() binds MLX hooks One-time setup before `mlx_loop`, not part of the hot path.
The input layer translates raw MLX events into persistent runtime intent stored
in app->input. Event callbacks only update state; the frame loop applies
movement and rotation once per render tick.
Input pipeline
`cub3D` does not move the player directly from event callbacks. MLX hooks update `app->input`, then `draw_frame()` consumes that state once per frame for stable movement and rotation.
main() binds MLX hooks One-time setup before `mlx_loop`, not part of the hot path.
handlers mutate `app->input` Callbacks store intent only, so movement remains frame-rate aware.
sets explicit movement or turn flags in `app->input`
input.forward = 1 clears the same explicit flags when the OS reports release
input.forward = 0 trigger cleanup, door toggle, resize, level, or weapon actions immediately
ESC / E / Space / F1-F4 accumulates horizontal delta for bonus camera rotation
input.mouse_dx += delta_x routes direct exit actions through cleanup
close_window(app) interactive input state Press keys to see how persistent flags and movement compose.
`t_input = ` `update_player_input(app)` once per frame `draw_frame()` consumes input in a deterministic order.
`raycast_scene()` sees coherent camera state Position, direction vector, and camera plane are updated before the current frame is rendered.
Hooks are bound in main before entering mlx_loop.
Typical bindings cover:
These handlers either mutate app->input or trigger direct actions such as
close_window(...).
The project uses a state-based keyboard model:
Those flags are explicit fields such as forward, backward, left,
right, turn_left, and turn_right; the project does not use a generic
keys[] table.
This avoids missing movement when event timing and frame timing differ.
In bonus mode, mouse movement contributes to horizontal look by accumulating
relative delta in the input state. That value is then consumed during
update_player_input(...) and reset after the frame update.
Mouse buttons and wheel events are used for bonus actions such as firing and
minimap zoom, depending on the active build. Other direct action keys, such as
ESC, E, Space, and F1-F4, trigger their action in the event handler
instead of becoming persistent movement flags.
draw_frame(...) calls update_player_input(...) once per frame.
The current flow is:
t_inputdelta_timeThis keeps controls stable and frame-rate aware.
Primary ownership stays inside t_app:
app->input stores persistent key and mouse statedir and planeThe input hot path does not allocate heap memory. Unknown keys are ignored safely, and quit actions still route through the normal cleanup path.
srcs/core/main.csrcs/input/input_keys.csrcs/input/input_mouse.csrcs/input/input_update.csrcs/input/move_player.csrcs/input/move_collision.csrcs/input/rotation.c