invalid test maps OK!

This commit is contained in:
whaffman 2025-05-29 13:08:04 +02:00
parent c40c3bb9d6
commit 09fa9aa66f
7 changed files with 82 additions and 39 deletions

View File

@ -6,7 +6,7 @@
# By: whaffman <whaffman@student.codam.nl> +#+ #
# +#+ #
# Created: 2024/10/15 11:48:46 by whaffman #+# #+# #
# Updated: 2025/05/28 18:53:50 by whaffman ######## odam.nl #
# Updated: 2025/05/29 12:58:16 by whaffman ######## odam.nl #
# #
# **************************************************************************** #
@ -50,7 +50,7 @@ BUILD_CONFIGS = release debug asan tsan
release_CFLAGS = -Wall -Werror -Werror -flto -Ofast -march=native -mtune=native -ffast-math
unity_CFLAGS = -Wall -Werror -Werror -Ofast -march=native -mtune=native -ffast-math
debug_CFLAGS = -Wall -Werror -Werror -g3 -DDEBUG -DDBG='fprintf(stderr, RED "DEBUG: " RESET "%s:%d (%s)\n", __FILE__, __LINE__, __PRETTY_FUNCTION__);'
asan_CFLAGS = -Wall -Werror -Werror -fsanitize=address,leak,undefined -g3
asan_CFLAGS = -Wall -Werror -Werror -flto -fsanitize=address,leak,undefined -g3
tsan_CFLAGS = -Wall -Werror -Werror -fsanitize=thread -g3
RUN_ARGS=test.cub

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/04/19 14:41:55 by whaffman #+# #+# */
/* Updated: 2025/05/23 14:00:34 by whaffman ######## odam.nl */
/* Updated: 2025/05/29 12:47:28 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
@ -30,5 +30,5 @@ int parse_map_line(char **lines, t_game *game, int i);
t_tile **copy_map(t_tile **grid, int width, int height);
char **pointer_lines(char *buffer, char c);
int valid_arguments(int argc, char **argv);
int map_entries_present(t_game *game);
#endif

View File

@ -0,0 +1,60 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* map_entries_present.c :+: :+: */
/* +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/05/29 12:38:19 by whaffman #+# #+# */
/* Updated: 2025/05/29 12:44:10 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
#include "cub3d.h"
int wall_texture_present(t_map *map)
{
if (!map->textures[0] || !map->textures[1]
|| !map->textures[2] || !map->textures[3])
{
ft_putstr_fd("Error: Missing wall textures\n", 2);
return (FAILURE);
}
return (SUCCESS);
}
int floor_ceiling_color_present(t_map *map)
{
if (map->floor_color == 0 || map->ceiling_color == 0)
{
ft_putstr_fd("Error: Missing floor or ceiling color\n", 2);
return (FAILURE);
}
return (SUCCESS);
}
int player_present(t_game *game)
{
if (game->player->pos.x == -1 || game->player->pos.y == -1)
{
ft_putstr_fd("Error: Missing player position\n", 2);
return (FAILURE);
}
return (SUCCESS);
}
int map_entries_present(t_game *game)
{
t_map *map;
if (!game || !game->map)
return (FAILURE);
map = game->map;
if (!wall_texture_present(map))
return (FAILURE);
if (!floor_ceiling_color_present(map))
return (FAILURE);
if (!player_present(game))
return (FAILURE);
return (SUCCESS);
}

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/04/22 13:10:06 by whaffman #+# #+# */
/* Updated: 2025/05/29 11:40:47 by whaffman ######## odam.nl */
/* Updated: 2025/05/29 12:52:32 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
@ -61,6 +61,9 @@ int handle_fc_color(char *token, t_map *map)
int color;
color_str = ft_strtok(NULL, " ");
if ((ft_strcmp(token, "F") == 0 && map->floor_color != 0x0)
|| (ft_strcmp(token, "C") == 0 && map->ceiling_color != 0x0))
return (ft_putstr_fd("Error: Color already set or fully transparent\n", 2), FAILURE);
if (!color_str)
return (ft_putstr_fd("Error: Missing color value\n", 2), FAILURE);
if (ft_strtok(NULL, " "))
@ -81,6 +84,9 @@ int handle_fc_texture(char *token, t_map *map)
char *texture_path;
texture_path = ft_strtok(NULL, " ");
if ((ft_strcmp(token, "FT") == 0 && map->texture_floor != 0x0)
|| (ft_strcmp(token, "CT") == 0 && map->texture_ceiling != 0x0))
return (ft_putstr_fd("Error: Texture already set\n", 2), FAILURE);
if (!texture_path)
return (ft_putstr_fd("Error: Missing texture path\n", 2), FAILURE);
if (ft_strtok(NULL, " "))
@ -103,7 +109,7 @@ int handle_fc_texture(char *token, t_map *map)
int handle_sprite(char *token, t_map *map)
{
t_sprite_lib sprite;
char symbol;
char *symbol;
char *texture_path;
if (token[1] == 'c')
@ -121,8 +127,8 @@ int handle_sprite(char *token, t_map *map)
sprite.collectible = 0;
sprite.type = SPRITE_TYPE_DEFAULT;
}
symbol = *ft_strtok(NULL, " ");
if (symbol < 'a' || symbol > 'z')
symbol = ft_strtok(NULL, " ");
if (*symbol < 'a' || *symbol > 'z' ||ft_strlen(symbol) != 1)
return (ft_putstr_fd("Error: Invalid sprite symbol\n", 2), FAILURE);
texture_path = ft_strtok(NULL, " ");
if (texture_path == NULL)
@ -132,10 +138,10 @@ int handle_sprite(char *token, t_map *map)
sprite.texture = load_texture(texture_path);
if (sprite.texture == NULL)
return (FAILURE);
if (map->sprite_lib[symbol - 'a'].texture != NULL)
if (map->sprite_lib[*symbol - 'a'].texture != NULL)
return (ft_putstr_fd(
"Error: Sprite already defined for this symbol\n", 2), FAILURE);
map->sprite_lib[symbol - 'a'] = sprite;
map->sprite_lib[*symbol - 'a'] = sprite;
return (SUCCESS);
}

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/04/22 13:11:37 by whaffman #+# #+# */
/* Updated: 2025/05/07 11:48:25 by whaffman ######## odam.nl */
/* Updated: 2025/05/29 12:47:35 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
@ -30,5 +30,7 @@ int parse_file(char *buffer, t_game *game)
if (!parse_map(&lines[i], game))
return (free(lines), FAILURE);
free(lines);
if (!map_entries_present(game))
return (FAILURE);
return (SUCCESS);
}

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2025/05/14 13:06:39 by whaffman #+# #+# */
/* Updated: 2025/05/23 17:27:52 by whaffman ######## odam.nl */
/* Updated: 2025/05/29 12:57:37 by whaffman ######## odam.nl */
/* */
/* ************************************************************************** */
@ -56,6 +56,8 @@ static void draw_floor_row(t_game *game,
row_dist /= (coord.y - 0.5 * game->screen->height);
floor_step = calc_floor_step(game, row_dist, left_ray, right_ray);
floor_pos = add(game->player->pos, mul(left_ray, row_dist));
if (isinf(floor_pos.x) || isinf(floor_pos.y))
return;
while (coord.x < game->screen->width)
{
draw_floor_ceiling_pixel(game, coord, row_dist, floor_pos);

View File

@ -1,27 +0,0 @@
KO! maps/invalid/double_floor_color.cub
KO! maps/invalid/double_floor_texture.cub
OK! maps/invalid/double_player.cub
OK! maps/invalid/double_sprite_identifier.cub
OK! maps/invalid/double_wall_texture.cub
KO! maps/invalid/empty_line_in_map.cub
OK! maps/invalid/extra_floor_token.cub
OK! maps/invalid/extra_sprite_token.cub
OK! maps/invalid/extra_wall_token.cub
OK! maps/invalid/garbage_config_line.cub
OK! maps/invalid/invalid_color.cub
OK! maps/invalid/invalid_sprite_character.cub
KO! maps/invalid/invalid_sprite_identifier_token.cub
KO! maps/invalid/missing_floor_color.cub
OK! maps/invalid/missing_floor_path.cub
OK! maps/invalid/missing_sprite_path.cub
OK! maps/invalid/missing_wall_path.cub
KO! maps/invalid/missing_wall_texture.cub
KO! maps/invalid/no_player.cub
OK! maps/invalid/non-existing_floor_texture.cub
OK! maps/invalid/non-existing_sprite_texture.cub
OK! maps/invalid/non-existing_texture.cub
KO! maps/invalid/not_enclosed_map.cub
KO! maps/invalid/not_enclosed_map_extra_empty_tile.cub
KO! maps/invalid/sprite_outside_wall.cub
OK! maps/invalid/test.cub
OK! maps/invalid/unknown_existing_sprite.cub