Skip to content

Texture and Color Headers

The parser requires six configuration headers before the map can be accepted: four wall textures and two RGB colors.

Configuration headers

Six required headers before the map body can be trusted

The parser validates four wall texture paths and two RGB color entries before map storage and runtime rendering can continue.

01
texture headers

Each direction points to a readable `.xpm` file.

NO North north wall texture
SO South south wall texture
WE West west wall texture
EA East east wall texture
02
color headers

Floor and ceiling colors must use strict `r,g,b` syntax.

F Floor floor RGB color
C Ceiling ceiling RGB color
03
parse_texture(app, id, value)

Texture validation resolves absolute or `.cub`-relative paths before later MLX loading.

if (slot != NULL)
  return error("duplicate");
value = trim(line after identifier);
resolved = resolve_from_map_dir_or_absolute(value);
if (!resolved && ends_with(value, ".xpm"))
  return error("unreadable");
if (!resolved)
  return error("not .xpm");
*slot = resolved;
04
parse_color(app, id, value)

RGB values are parsed in place with strict separators and stored as three integers.

skip spaces;
for k in 0..2:
  parse decimal digits
  if missing digits:
    return error("not numeric");
  if (v < 0 || v > 255)
    return error("out of range");
  require comma for first two values
reject trailing non-space content;
05
validation points

Each failure exits before MLX runtime rendering starts.

Duplicate texture or color slot slot already set / rgb != -1
Missing required header check_required_headers(app)
Texture extension is not .xpm ends_with(".xpm")
Texture file is unreadable open(path) < 0
RGB separator or trailing content is invalid strict parse_rgb_triplet()
RGB component is not numeric ft_isdigit(line[i])
RGB component is out of range v < 0 || v > 255
Relative path requires normalization relative to .cub directory
interactive header validator

Try texture and RGB values against the same documented parser rules.

NO ./textures/north.xpmSO ./textures/south.xpmWE ./textures/west.xpmEA ./textures/east.xpmF 220,100,0C 50,50,200
Enter a header value and validate it.
check_required_headers(app)

Startup continues only when the four texture slots and both RGB triplets are present and valid.

After success, texture paths are owned by `app` and MLX loads the `.xpm` images during initialization.

Texture headers:

  • NO for north wall texture
  • SO for south wall texture
  • WE for west wall texture
  • EA for east wall texture

Color headers:

  • F for floor color
  • C for ceiling color

Texture values must be non-empty readable .xpm paths. Relative texture paths are normalized from the .cub file directory so maps can be launched from different working directories.

Color values must use strict r,g,b syntax, with exactly three numeric components and each component in [0..255].

Duplicate headers, missing headers, unreadable texture files, invalid texture extensions, malformed RGB syntax, and out-of-range RGB values all abort startup through the normal Error\n... path before rendering begins.