mirror of
https://codeberg.org/ACME-Corporation/cub3d.git
synced 2025-12-06 09:58:09 +01:00
started to parse the 'real' map
This commit is contained in:
parent
d336d7bc15
commit
02079dfa87
4 changed files with 92 additions and 6 deletions
|
|
@ -20,6 +20,10 @@ typedef struct s_mapdata
|
||||||
char *SO_texture;
|
char *SO_texture;
|
||||||
char *WE_texture;
|
char *WE_texture;
|
||||||
char *EA_texture;
|
char *EA_texture;
|
||||||
|
int f_color;
|
||||||
|
int c_color;
|
||||||
|
char **map;
|
||||||
|
char **mapflood;
|
||||||
bool isvalid;
|
bool isvalid;
|
||||||
char error[1024];
|
char error[1024];
|
||||||
} t_mapdata;
|
} t_mapdata;
|
||||||
|
|
|
||||||
22
ressources/wrongmap_invalid_colors.cub
Normal file
22
ressources/wrongmap_invalid_colors.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 256,100,0
|
||||||
|
C 225,30,0
|
||||||
|
|
||||||
|
1111111111111111111111111
|
||||||
|
1000000000110000000000001
|
||||||
|
1011000001110000000000001
|
||||||
|
1001000000000000000000001
|
||||||
|
111111111011000001110000000000001
|
||||||
|
100000000011000001110111111111111
|
||||||
|
11110111111111011100000010001
|
||||||
|
11110111111111011101010010001
|
||||||
|
11000000110101011100000010001
|
||||||
|
10000000000000001100000010001
|
||||||
|
10000000000000001101010010001
|
||||||
|
11000001110101011111011110N0111
|
||||||
|
11110111 1110101 101111010001
|
||||||
|
11111111 1111111 111111111111
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: tchampio <tchampio@student.42lehavre. +#+ +:+ +#+ */
|
/* By: tchampio <tchampio@student.42lehavre. +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/05/06 13:16:11 by tchampio #+# #+# */
|
/* Created: 2025/05/06 13:16:11 by tchampio #+# #+# */
|
||||||
/* Updated: 2025/06/06 17:43:26 by tchampio ### ########.fr */
|
/* Updated: 2025/06/16 16:12:50 by tchampio ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -61,6 +61,7 @@ int main(int argc, char **argv)
|
||||||
t_mlx_data data;
|
t_mlx_data data;
|
||||||
t_mapdata map;
|
t_mapdata map;
|
||||||
|
|
||||||
|
ft_bzero(&map, sizeof(map));
|
||||||
if (argc < 2)
|
if (argc < 2)
|
||||||
return (ft_printf("Error: Missing cub3d file\n"), 1);
|
return (ft_printf("Error: Missing cub3d file\n"), 1);
|
||||||
if (!check_cubfile(argv[1], &map))
|
if (!check_cubfile(argv[1], &map))
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: tchampio <tchampio@student.42lehavre. +#+ +:+ +#+ */
|
/* By: tchampio <tchampio@student.42lehavre. +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/06/06 17:54:42 by tchampio #+# #+# */
|
/* Created: 2025/06/06 17:54:42 by tchampio #+# #+# */
|
||||||
/* Updated: 2025/06/08 20:28:57 by tchampio ### ########.fr */
|
/* Updated: 2025/06/16 17:03:00 by tchampio ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -23,6 +23,8 @@ void print_mapdata(const t_mapdata *data)
|
||||||
ft_printf(BOLD "SO Texture: " RESET "%s\n", data->SO_texture);
|
ft_printf(BOLD "SO Texture: " RESET "%s\n", data->SO_texture);
|
||||||
ft_printf(BOLD "WE Texture: " RESET "%s\n", data->WE_texture);
|
ft_printf(BOLD "WE Texture: " RESET "%s\n", data->WE_texture);
|
||||||
ft_printf(BOLD "EA Texture: " RESET "%s\n", data->EA_texture);
|
ft_printf(BOLD "EA Texture: " RESET "%s\n", data->EA_texture);
|
||||||
|
ft_printf(BOLD "F color: " RESET "%x\n", data->f_color);
|
||||||
|
ft_printf(BOLD "C color: " RESET "%x\n", data->c_color);
|
||||||
ft_printf(BOLD "Validity: " RESET);
|
ft_printf(BOLD "Validity: " RESET);
|
||||||
if (data->isvalid)
|
if (data->isvalid)
|
||||||
ft_printf(GREEN "VALID\n" RESET);
|
ft_printf(GREEN "VALID\n" RESET);
|
||||||
|
|
@ -35,6 +37,33 @@ void print_mapdata(const t_mapdata *data)
|
||||||
ft_printf(CYAN "=================\n" RESET);
|
ft_printf(CYAN "=================\n" RESET);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned long set_color(const char *s, t_mapdata *map)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
unsigned long finalcolor;
|
||||||
|
char **tab;
|
||||||
|
int rgb[100];
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
tab = ft_split(s, ',');
|
||||||
|
while (tab[i])
|
||||||
|
{
|
||||||
|
if (i > 2)
|
||||||
|
ft_strlcpy(map->error, "too many colors", 16);
|
||||||
|
rgb[i] = ft_atoi(tab[i]);
|
||||||
|
free(tab[i]);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
free(tab);
|
||||||
|
if (rgb[0] < 0 || rgb[0] > 255
|
||||||
|
|| rgb[1] < 0 || rgb[1] > 255
|
||||||
|
|| rgb[2] < 0 || rgb[2] > 255)
|
||||||
|
return (ft_strlcpy(map->error, "Invalid color", 14), 0);
|
||||||
|
finalcolor = ((rgb[0] & 0xff) << 16)
|
||||||
|
+ ((rgb[1] & 0xff) << 8) + (rgb[2] & 0xff);
|
||||||
|
return (finalcolor);
|
||||||
|
}
|
||||||
|
|
||||||
bool set_textures(char *line, t_mapdata *map)
|
bool set_textures(char *line, t_mapdata *map)
|
||||||
{
|
{
|
||||||
char **tab;
|
char **tab;
|
||||||
|
|
@ -54,21 +83,24 @@ bool set_textures(char *line, t_mapdata *map)
|
||||||
map->WE_texture = ft_strdup(tab[1]);
|
map->WE_texture = ft_strdup(tab[1]);
|
||||||
if (!ft_strncmp(tab[0], "EA", 3) || !ft_strncmp(tab[0], "ea", 3))
|
if (!ft_strncmp(tab[0], "EA", 3) || !ft_strncmp(tab[0], "ea", 3))
|
||||||
map->EA_texture = ft_strdup(tab[1]);
|
map->EA_texture = ft_strdup(tab[1]);
|
||||||
|
if (!ft_strncmp(tab[0], "F", 2) || !ft_strncmp(tab[0], "f", 2))
|
||||||
|
map->f_color = set_color(tab[1], map);
|
||||||
|
if (!ft_strncmp(tab[0], "C", 2) || !ft_strncmp(tab[0], "c", 2))
|
||||||
|
map->c_color = set_color(tab[1], map);
|
||||||
}
|
}
|
||||||
while (tab[i])
|
while (tab[i])
|
||||||
free(tab[i++]);
|
free(tab[i++]);
|
||||||
free(tab);
|
return (free(tab), true);
|
||||||
return (true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool add_textures(int fd, t_mapdata *map)
|
bool add_textures(int fd, t_mapdata *map)
|
||||||
{
|
{
|
||||||
char *line;
|
char *line;
|
||||||
int set_lines;
|
int set_lines;
|
||||||
|
|
||||||
line = get_next_line(fd);
|
line = get_next_line(fd);
|
||||||
set_lines = 0;
|
set_lines = 0;
|
||||||
while (line && set_lines < 4)
|
while (line && set_lines < 6)
|
||||||
{
|
{
|
||||||
if (!set_textures(line, map))
|
if (!set_textures(line, map))
|
||||||
return (free(line), false);
|
return (free(line), false);
|
||||||
|
|
@ -77,6 +109,7 @@ bool add_textures(int fd, t_mapdata *map)
|
||||||
free(line);
|
free(line);
|
||||||
line = get_next_line(fd);
|
line = get_next_line(fd);
|
||||||
}
|
}
|
||||||
|
free(line);
|
||||||
print_mapdata(map);
|
print_mapdata(map);
|
||||||
return (true);
|
return (true);
|
||||||
}
|
}
|
||||||
|
|
@ -104,6 +137,27 @@ bool check_filename(char *file)
|
||||||
return (true);
|
return (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void populate_maps(t_mapdata *map, int fd)
|
||||||
|
{
|
||||||
|
char *line;
|
||||||
|
|
||||||
|
line = get_next_line(fd);
|
||||||
|
while (line)
|
||||||
|
{
|
||||||
|
free(line);
|
||||||
|
line = get_next_line(fd);
|
||||||
|
}
|
||||||
|
free(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool check_walls(int fd, t_mapdata *map)
|
||||||
|
{
|
||||||
|
bool last_first;
|
||||||
|
|
||||||
|
populate_maps(map, fd);
|
||||||
|
return (true);
|
||||||
|
}
|
||||||
|
|
||||||
bool check_cubfile(char *file, t_mapdata *map)
|
bool check_cubfile(char *file, t_mapdata *map)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
|
|
@ -116,6 +170,11 @@ bool check_cubfile(char *file, t_mapdata *map)
|
||||||
if (!add_textures(fd, map))
|
if (!add_textures(fd, map))
|
||||||
return (close(fd), ft_strlcpy(map->error,
|
return (close(fd), ft_strlcpy(map->error,
|
||||||
"Map started before all the textures", 37), false);
|
"Map started before all the textures", 37), false);
|
||||||
|
if (map->error[0])
|
||||||
|
return (close(fd), false);
|
||||||
|
if (!check_walls(fd, map))
|
||||||
|
return (close(fd), ft_strlcpy(map->error,
|
||||||
|
"Map is malformed (invalid chars or missing walls)", 51), false);
|
||||||
close(fd);
|
close(fd);
|
||||||
return (true);
|
return (true);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue