validate_player(app, lines, map_start) Counts player spawn symbols in the map block.
Map validation guarantees that the parsed map can be safely used by movement,
collision, and raycasting. It is executed before init_mlx, so invalid maps do
not create windows, textures, or frame buffers.
Validation gate
Map validation is a hard startup gate. If player, character, or enclosure checks fail, the program exits before graphics resources are created.
validate_map(app, lines, map_start) sequential checks, first failure stops startup validate_player(app, lines, map_start) Counts player spawn symbols in the map block.
0 or >1 spawn -> abort validate_chars(app, lines, map_start) Checks every map character against the mandatory and bonus-aware alphabets.
unknown char -> abort check_enclosure(app, lines, map_start) Runs BFS from the spawn and detects any leak to void or unreachable open area.
init_bfs_context find_player, dimensions, visited matrix, queue run_bfs 4-neighbor flood fill from spawn scan_unreachable reject open cells never visited leak / isolated zone / alloc fail -> abort map validated → parse_map() → init_player_vectors() → init_mlx() `app->player` has the validated spawn; `parse_map()` then copies safe rows into `app->map.grid`.
The validator enforces four core guarantees:
These checks protect the engine from invalid traversal during movement, collision, and DDA raycasting.
Validation is called from the parsing pipeline:
parse_file(...)validate_map(app, lines, map_start)Inside validate_map(...), the current sequence is:
validate_player(app, lines, start)validate_chars(app, lines, start)check_enclosure(app, lines, start)Any failure aborts startup before rendering begins.
validate_player(...) counts spawn symbols from the player set N/S/E/W.
Failure cases:
On success, the later enclosure setup can safely call find_player(...).
That BFS setup stores the centered spawn position and orientation in
app->player.
validate_chars(...) scans every map row from map_start.
Mandatory symbols are accepted directly:
01N, S, E, WBonus symbols are accepted through bonus_is_valid_map_char(...), keeping the
same validation entry point compatible with mandatory and bonus builds.
check_enclosure(...) performs BFS-based closure validation.
Setup includes:
find_player(...)calculate_dimensions(...)allocate_visited(...)Traversal rules:
This is what makes irregular or non-rectangular maps safe: missing columns on short rows behave like outside space.
Validation does not take ownership of the parsed lines array. Temporary BFS
state is local to validation and released through the finish path even on error.
Temporary resources include:
After successful validation, parse_map(...) stores the final map copy in
app->map.grid.
Let:
H be map heightW be max row widthN be the number of reachable open cellsThe traversal cost is O(N), while the visited matrix and queues are bounded by
O(H * W).
srcs/validation/validate_map.csrcs/validation/validate_map_player.csrcs/validation/validate_map_chars.csrcs/validation/validate_map_closed.csrcs/validation/validate_closed_setup.csrcs/validation/validate_bfs.c