diff --git a/includes/Cub3D.h b/includes/Cub3D.h index d5d264c..9867dc1 100644 --- a/includes/Cub3D.h +++ b/includes/Cub3D.h @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/02/13 16:30:59 by apommier #+# #+# */ -/* Updated: 2022/06/14 14:59:08 by apommier ### ########.fr */ +/* Updated: 2022/06/14 21:26:20 by sadjigui ### ########.fr */ /* */ /* ************************************************************************** */ @@ -40,7 +40,7 @@ typedef struct ray_info{ int wall_type; int pixel; char texture_type; - + } ray; typedef struct all_wall_texture{ @@ -53,9 +53,12 @@ typedef struct all_wall_texture{ typedef struct s_color{ //unsigned char t; - unsigned char r; - unsigned char g; - unsigned char b; + // unsigned char r; + // unsigned char g; + // unsigned char b; + int r; + int g; + int b; } color; typedef struct map_information{ diff --git a/map/map8.cub b/map/map8.cub index ee654af..b41a0cd 100644 --- a/map/map8.cub +++ b/map/map8.cub @@ -1,14 +1,14 @@ NO ./sprite/brick_wall.ppm SO ./sprite/brick_wall.ppm + EA ./sprite/brick_wall.ppm WE ./sprite/brick_wall.ppm - 11111111 -11000001 -10000001 -10E00001 +11111001 +10131001 +10111001 +1000E001 11000001 11000001 -11000001 -11111111 \ No newline at end of file +11111111 diff --git a/map/real_subject.cub b/map/real_subject.cub index 7376094..9cd70b4 100644 --- a/map/real_subject.cub +++ b/map/real_subject.cub @@ -1,3 +1,8 @@ +NO ./sprite/magma.ppm +SO ./sprite/stone_bricks.ppm +EA ./sprite/glowstone.ppm +WE ./sprite/obsidian.ppm + F 220,100,0 C 225,30,0 diff --git a/srcs/parsing.c b/srcs/parsing.c new file mode 100644 index 0000000..3df01a5 --- /dev/null +++ b/srcs/parsing.c @@ -0,0 +1,94 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* parsing.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: sadjigui +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/05/24 14:17:25 by sadjigui #+# #+# */ +/* Updated: 2022/05/24 14:49:21 by sadjigui ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../includes/Cub3D.h" + +int parsing(char **av); +{ + char *line; + int fd; + int i; + + i = 0; + fd = open(argv[1], O_RDONLY); + if (fd == -1) + ft_error("Error: Open call fail"); + line = get_next_line(fd); + while (line != NULL) + i++; + close(fd); + if (set_map_test) + return (1); + return (ret_map); +} + +int set_map_test(char **av, int size) +{ + char *line; + char **map; + int fd; + int i; + + i = 0; + fd = open(argv[1], O_RDONLY); + if (fd == -1) + ft_error("Error: Open call fail"); + map = malloc(sizeof(char *) * (size + 1)); + if (!map) + return (0); + line = get_next_line(fd); + while (line != NULL) + { + map[i] = line; + free(line); + line = get_next_line(fd); + i++; + } + map[i] = 0; + test_map(map, size); + // free map + close(fd); +} + +char *out_of_map(int size) +{ + int i; + char *str; + + i = 0; + str = malloc(sizeof(char) * (size + 1)); + if (!str) + return (NULL); + while (i < size) + { + str[i] = '3'; + i++; + } + return (str); +} + +int test_map(char **map, int height) +{ + char **tmp; + int width; + int i; + + i = 0; + width = find_max(map); + tmp = malloc(sizeof(char *) * (height + 3)); + if (!tmp) + return (0); + while (tmp[i]) + { + tmp[i] = out_of_map(width); + } +} diff --git a/srcs/parsing/check_color_texture.c b/srcs/parsing/check_color_texture.c index 00e1c48..152751d 100644 --- a/srcs/parsing/check_color_texture.c +++ b/srcs/parsing/check_color_texture.c @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/06/11 01:00:17 by apommier #+# #+# */ -/* Updated: 2022/06/14 16:35:53 by apommier ### ########.fr */ +/* Updated: 2022/06/14 21:36:53 by sadjigui ### ########.fr */ /* */ /* ************************************************************************** */ @@ -64,7 +64,7 @@ char *transform_map(char **double_map, t_data *img) } img->map.simple_map = map; //printf("map = -%s-\n", map); - return (0); + return (0); } void set_texture_file(char *str, t_data *img, char c) @@ -96,6 +96,41 @@ void set_texture_file(char *str, t_data *img, char c) get_texture(c, str + index + 3, img); } +void check_value(char **tab, int index) +{ + int i; + int j; + + i = 0; + while (tab[i]) + { + j = 0; + while (tab[i][j]) + { + if (ft_isdigit(tab[i][j])) + ft_exit("Error\nBad syntax in map file (RGB)\n"); + j++; + } + i++; + } +} + +void set_color_utils(char **tab, int index, color *img) +{ + check_value(tab, index); + img->r = ft_atoi(tab[0] + index); + img->g = ft_atoi(tab[1]); + img->b = ft_atoi(tab[2]); + + printf("---%d\n", img->g); + if (!(img->r >= 0 && img->r <= 255)) + ft_exit("Error\nBad syntax in map file (RGB)\n"); + if (!(img->g >= 0 && img->r <= 255)) + ft_exit("Error\nBad syntax in map file (RGB)\n"); + if (!(img->b >= 0 && img->r <= 255)) + ft_exit("Error\nBad syntax in map file (RGB)\n"); +} + void set_color(char *str, t_data *img) { char c; @@ -104,7 +139,7 @@ void set_color(char *str, t_data *img) c = next_space(str, 0); index = next_space_index(str, 0); - tab = ft_split(str + 1, ','); + tab = ft_split(str, ','); if (!tab) quit_game(img); if (double_size(tab) != 3) @@ -113,13 +148,23 @@ void set_color(char *str, t_data *img) { if (str[index + 1] != ' ') ft_exit("Error\nBad syntax in map file (RGB)\n"); - + else + { + index += next_space_index(str, index + 1); + set_color_utils(tab, index, &img->map.floor); + } } if (c == 'C') { if (str[index + 1] != ' ') ft_exit("Error\nBad syntax in map file (RGB)\n"); + else + { + index += next_space_index(str, index + 1); + set_color_utils(tab, index, &img->map.sky); + } } + free_double(tab); } int check_texture_color(char **tab, t_data *img) @@ -142,7 +187,10 @@ int check_texture_color(char **tab, t_data *img) if (next_space(tab[index], 0) == 'N' || next_space(tab[index], 0) == 'S' || next_space(tab[index], 0) == 'W' || next_space(tab[index], 0) == 'E') set_texture_file(tab[index], img, next_space(tab[index], 0)); else if (next_space(tab[index], 0) == 'F' || next_space(tab[index], 0) == 'C') + { set_color(tab[index], img); + + } else if (next_space(tab[index], 0)) ft_exit("Error\nBad syntax in map file\n"); index++;