mirror of
https://codeberg.org/ACME-Corporation/cub3d.git
synced 2025-12-06 09:58:09 +01:00
fixed some checking
This commit is contained in:
parent
63d4eb28ef
commit
b30dda9c62
7 changed files with 87 additions and 23 deletions
|
|
@ -27,6 +27,8 @@ typedef struct s_mapdata
|
|||
char **mapflood;
|
||||
int skipped_lines;
|
||||
bool isvalid;
|
||||
int startx;
|
||||
int starty;
|
||||
char error[1024];
|
||||
} t_mapdata;
|
||||
|
||||
|
|
|
|||
22
ressources/bad_maps/wrongmap_invalidchars.cub
Normal file
22
ressources/bad_maps/wrongmap_invalidchars.cub
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
NO ./path_to_the_north_texture
|
||||
SO ./path_to_the_south_texture
|
||||
WE ./path_to_the_west_texture
|
||||
EA ./path_to_the_east_texture
|
||||
|
||||
F 220,100,0
|
||||
C 225,30,0
|
||||
|
||||
1111111111111111111111111
|
||||
1000000000110000000000001
|
||||
1011000001110000000000001
|
||||
1001000000000000000000001
|
||||
111111111011000001110000000000001
|
||||
100H0000001100000111011111D111111
|
||||
11110111111111011100000010001
|
||||
11110111111111011101010010001
|
||||
11000000110101011100000010001
|
||||
10000000000000001100000010001
|
||||
10000000000000001101010010001
|
||||
11000001110101011111011110N0111
|
||||
11110111 1110101 101111010001
|
||||
11111111 1111111 111111111111
|
||||
23
ressources/bad_maps/wrongmap_wrongcolors.cub
Normal file
23
ressources/bad_maps/wrongmap_wrongcolors.cub
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
NO ./path_to_the_north_texture
|
||||
SO ./path_to_the_south_texture
|
||||
WE ./path_to_the_west_texture
|
||||
EA ./path_to_the_east_texture
|
||||
|
||||
F this_color_doesnt_exists_wtf
|
||||
C 225,30,0
|
||||
|
||||
111111111111111111111111
|
||||
1000000000110000000000001
|
||||
1011000001110000000000001
|
||||
1001000000000000000000001
|
||||
111111111011000001110000000000001
|
||||
100000000011000001110111111111111
|
||||
11110111111111011100000010001
|
||||
11110111111111011101010010001
|
||||
11000000110101011100000010001
|
||||
10000000000000001100000010001
|
||||
10000000000000001101010010001
|
||||
11000001110101011111011110N0111
|
||||
11110111 1110101 101111010001
|
||||
11111111 1111111 111111111111
|
||||
|
||||
|
|
@ -11,7 +11,7 @@ C 225,30,0
|
|||
1011000001110000000000001
|
||||
1001000000000000000000001
|
||||
111111111011000001110000000000001
|
||||
10000000001100000111011111D111111
|
||||
100000000011000001110111110111111
|
||||
11110111111111011100000010001
|
||||
11110111111111011101010010001
|
||||
11000000110101011100000010001
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: tchampio <tchampio@student.42lehavre. +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/06/06 17:54:42 by tchampio #+# #+# */
|
||||
/* Updated: 2025/06/20 15:40:20 by tchampio ### ########.fr */
|
||||
/* Updated: 2025/06/20 19:45:07 by tchampio ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -175,10 +175,10 @@ void add_map_line(const char *line, t_mapdata *map)
|
|||
char **newmapflood;
|
||||
int i;
|
||||
|
||||
newmap = ft_calloc(sizeof(char *), (length + 1));
|
||||
newmap = ft_calloc(sizeof(char *), (length + 2));
|
||||
if (!newmap)
|
||||
return ;
|
||||
newmapflood = ft_calloc(sizeof(char *), (length + 1));
|
||||
newmapflood = ft_calloc(sizeof(char *), (length + 2));
|
||||
if (!newmapflood)
|
||||
return ;
|
||||
i = copy_old_map(map, newmap, newmapflood, length);
|
||||
|
|
@ -208,13 +208,13 @@ void populate_maps(t_mapdata *map, int fd)
|
|||
|
||||
bool has_forbidden_characters(char *line)
|
||||
{
|
||||
static const char *allowedchars = "10NSEW";
|
||||
static const char *allowedchars = " 10NSEW\n";
|
||||
size_t strsize;
|
||||
int i;
|
||||
|
||||
strsize = ft_strlen(line);
|
||||
i = 0;
|
||||
while (i < strsize)
|
||||
while (i < (int)strsize)
|
||||
{
|
||||
if (!ft_strchr(allowedchars, line[i]))
|
||||
return (true);
|
||||
|
|
@ -246,24 +246,12 @@ bool check_walls(t_mapdata *map)
|
|||
return (false);
|
||||
}
|
||||
if (has_forbidden_characters(map->map[i]))
|
||||
return (true);
|
||||
return (false);
|
||||
i++;
|
||||
}
|
||||
return (true);
|
||||
}
|
||||
|
||||
bool check_bare_minimum(char **map)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
}
|
||||
|
||||
bool flood_fill(char **mapflood)
|
||||
{
|
||||
return (false);
|
||||
}
|
||||
|
||||
void print_map(char **map)
|
||||
{
|
||||
int i;
|
||||
|
|
@ -277,6 +265,35 @@ void print_map(char **map)
|
|||
ft_printf("(%p) %s", map[i], map[i]);
|
||||
}
|
||||
|
||||
bool check_bare_minimum(t_mapdata *map)
|
||||
{
|
||||
int i;
|
||||
int spawncount;
|
||||
int j;
|
||||
|
||||
i = 0;
|
||||
spawncount = 0;
|
||||
while (map->map[i])
|
||||
{
|
||||
j = 0;
|
||||
while (map->map[i][j])
|
||||
{
|
||||
if (map->map[i][j] == 'N' || map->map[i][j] == 'E'
|
||||
|| map->map[i][j] == 'S' || map->map[i][j] == 'W')
|
||||
{
|
||||
spawncount++;
|
||||
map->startx = j;
|
||||
map->starty = i;
|
||||
}
|
||||
j++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if (spawncount == 1)
|
||||
return (true);
|
||||
return (false);
|
||||
}
|
||||
|
||||
bool check_cubfile(char *file, t_mapdata *map)
|
||||
{
|
||||
int fd;
|
||||
|
|
@ -295,10 +312,10 @@ bool check_cubfile(char *file, t_mapdata *map)
|
|||
if (!check_walls(map))
|
||||
return (close(fd), ft_strlcpy(map->error,
|
||||
"Map is malformed (invalid chars or missing walls)", 51), false);
|
||||
if (!check_bare_minimum(map->map))
|
||||
if (!check_bare_minimum(map))
|
||||
return (close(fd), false);
|
||||
if (!flood_fill(map->mapflood))
|
||||
return (close(fd), ft_strlcpy(map->error,
|
||||
"Map is not possible (flood fill failed)", 41), false);
|
||||
// if (!flood_fill(map->mapflood))
|
||||
// return (close(fd), ft_strlcpy(map->error,
|
||||
// "Map is not possible (flood fill failed)", 41), false);
|
||||
return (true);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue