check_map - 1Fr3aK2/Cub3d GitHub Wiki
📝 check_map
This function validates the map structure and its associated resources (floor, ceiling, and textures).
It ensures that the map is logically correct, properly configured, and ready to be used in the game engine.
⚙️ Parameters
| Parameter | Type | Description |
|---|---|---|
floor |
char * |
String representing the RGB color or texture path for the floor. |
ceiling |
char * |
String representing the RGB color or texture path for the ceiling. |
map |
t_map * |
Pointer to the map structure that will be validated. |
🔁 Returns
| Return value | Description |
|---|---|
bool |
Returns true if all validation checks pass, or false if any check fails. |
📖 Description
The check_map function performs a series of validation steps to ensure that the provided map and its visual components (floor and ceiling) are correctly defined and usable in the game:
-
Pointer validation: Checks whether the
floor,ceiling, ormappointers areNULL.- If any of them are invalid, returns
false.
- If any of them are invalid, returns
-
Character validation: Calls
check_valid_chars(map)to ensure that all characters inside the map are valid and recognizable by the parser. -
Player presence: Calls
check_player(map)to verify that there is exactly one player defined in the map. -
Temporary memory allocation: Calls
alloc_temp_map(map)to allocate temporary storage required for map analysis (e.g., flood fill checks). -
Boundary validation: Calls
check_surroundings(map)to ensure the map boundaries are properly closed and do not contain leaks or invalid open areas. -
Texture and color verification: Calls
check_textures(floor, ceiling, map)to confirm that all required textures, as well as the floor and ceiling color values, are properly configured.
If any of these checks fail, the function immediately returns false.
If all validations succeed, it returns true.
💡 Example Usage
t_map map;
// Assume map has been previously loaded and parsed
if (check_map("220,100,0", "225,30,0", &map))
printf("✅ Map validation successful! Ready to start the game.\n");
else
printf("❌ Map validation failed. Please check your .cub file.\n");