diff --git a/libft/ft_lstclear.c b/libft/ft_lstclear.c index 152fb31..80fdf38 100644 --- a/libft/ft_lstclear.c +++ b/libft/ft_lstclear.c @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/12/09 19:58:04 by apommier #+# #+# */ -/* Updated: 2022/01/17 11:28:39 by apommier ### ########.fr */ +/* Updated: 2022/06/15 13:14:54 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,7 +20,7 @@ void ft_lstclear(t_list **lst, void (*del)(void*)) while (*lst) { chr = (*lst)->next; - del((*lst)->nbr); + del((*lst)->content); free(*lst); *lst = chr; } diff --git a/libft/ft_lstdelone.c b/libft/ft_lstdelone.c index f0dea04..156f3b9 100644 --- a/libft/ft_lstdelone.c +++ b/libft/ft_lstdelone.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* ft_lstdelone.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: apommier +#+ +:+ +#+ */ +/* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/12/09 19:54:40 by apommier #+# #+# */ -/* Updated: 2020/12/12 09:10:11 by apommier ### ########.fr */ +/* Updated: 2022/06/15 13:15:15 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,6 +16,6 @@ void ft_lstdelone(t_list *lst, void (*del)(void*)) { if (!lst) return ; - del(lst->nbr); + del(lst->content); free(lst); } diff --git a/libft/ft_lstiter.c b/libft/ft_lstiter.c index 0e9ea7a..25592c3 100644 --- a/libft/ft_lstiter.c +++ b/libft/ft_lstiter.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* ft_lstiter.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: apommier +#+ +:+ +#+ */ +/* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/12/09 20:14:47 by apommier #+# #+# */ -/* Updated: 2020/12/11 17:47:39 by apommier ### ########.fr */ +/* Updated: 2022/06/15 13:15:24 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,7 +16,7 @@ void ft_lstiter(t_list *lst, void (*f)(void *)) { while (lst) { - f(lst->nbr); + f(lst->content); lst = lst->next; } } diff --git a/libft/ft_lstmap.c b/libft/ft_lstmap.c index 252c0c6..ccc2b70 100644 --- a/libft/ft_lstmap.c +++ b/libft/ft_lstmap.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* ft_lstmap.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: apommier +#+ +:+ +#+ */ +/* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/12/11 00:10:12 by apommier #+# #+# */ -/* Updated: 2020/12/13 22:37:30 by apommier ### ########.fr */ +/* Updated: 2022/06/15 13:15:33 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,7 +20,7 @@ t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *)) begin = 0; while (lst) { - new = ft_lstnew(f(lst->nbr)); + new = ft_lstnew(f(lst->content)); if (!new) { ft_lstclear(&begin, *del); diff --git a/libft/ft_lstnew.c b/libft/ft_lstnew.c index e108f42..53dc142 100644 --- a/libft/ft_lstnew.c +++ b/libft/ft_lstnew.c @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/12/09 01:06:20 by apommier #+# #+# */ -/* Updated: 2022/01/17 11:29:09 by apommier ### ########.fr */ +/* Updated: 2022/06/15 13:15:45 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,8 +19,7 @@ t_list *ft_lstnew(void *content) new = (t_list *)malloc(sizeof(t_list)); if (!new) return (0); - new->swap = 0; - new->nbr = content; + new->content = content; new->next = 0; return (new); } diff --git a/libft/libft.h b/libft/libft.h index 4e83ab8..88fe92b 100644 --- a/libft/libft.h +++ b/libft/libft.h @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/12/11 03:21:27 by apommier #+# #+# */ -/* Updated: 2022/05/06 19:29:58 by apommier ### ########.fr */ +/* Updated: 2022/06/15 13:14:31 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,8 +19,7 @@ typedef struct t_slist { - void *nbr; - int index; + void *content; int swap; struct t_slist *next; } t_list; diff --git a/srcs/get_texture_array.c b/srcs/get_texture_array.c index 1ff1185..8272ad2 100644 --- a/srcs/get_texture_array.c +++ b/srcs/get_texture_array.c @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/05/06 16:10:11 by apommier #+# #+# */ -/* Updated: 2022/06/15 00:34:01 by apommier ### ########.fr */ +/* Updated: 2022/06/15 14:23:32 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -40,6 +40,25 @@ void put_texture_in_struct(char type, unsigned char *texture, t_data *img) } } +int verify_texture() +{ + +} + +int is_nbr(char *str) +{ + int i; + + i = 0; + while (str[i]) + { + if (!ft_isdigit(str[i])) + return (0); + i++; + } + return (1); +} + unsigned char *get_texture(char type, char *path, t_data *img)//change in list { int fd; @@ -47,19 +66,20 @@ unsigned char *get_texture(char type, char *path, t_data *img)//change in list int count; char *swap = 0; - if (!path) - { - //printf("no path\n"); - path = ft_strjoin("./sprite/brick_wall.ppm", 0); - } (void)type; count = 0; + if (!path) + return(0); + fd = open(path, O_DIRECTORY); + if (fd >= 0) + { + close(fd); + ft_exit("Error\nTexture path is a directory\n"); + } fd = open(path, O_RDONLY); if (fd == -1) - { - printf("path= %s\n", path); - ft_exit("Error\nBad texture file prout"); - } + quit_game(img); + img->to_be_free.fd_one = fd; while (swap || !count) { if (swap) @@ -68,26 +88,44 @@ unsigned char *get_texture(char type, char *path, t_data *img)//change in list swap = get_next_line(fd); } close(fd); + img->to_be_free.fd_one = -1; + printf("count= %d\n", count); + if (count != 12291) + ft_exit("Error\n Bad texture file\n"); ret = ft_calloc(sizeof(char), count); - fd = open(path, O_RDONLY); if (!ret) - return (0); + quit_game(img); + fd = open(path, O_RDONLY); + if (fd == -1) + ft_exit("Error\nBad texture file"); + img->to_be_free.fd_one = fd; count = 0; while (swap || !count) { if (swap) free(swap); swap = get_next_line(fd); + //printf("str = -%s-\n", swap); if (!count) { free(swap); swap = get_next_line(fd); + } if (swap) + swap[ft_strlen(swap) - 1] = 0; + if ((swap && is_nbr(swap) && ft_strlen(swap) <= 3 && ft_atoi(swap) <= 255 && ft_atoi(swap) >= 0) || !count) ret[count] = (unsigned char)ft_atoi(swap); + else if (swap) + { + //printf("isnbr= %d swap= %s ft_atoi(swap)= ---%ld--- strlen= %ld\n",is_nbr(swap) ,swap , ft_atoi(swap), ft_strlen(swap) ); + free(ret); + ft_exit("Error\nBad texture file\n"); + } count++; } close(fd); + img->to_be_free.fd_one = -1; put_texture_in_struct(type, ret, img); return (ret); -} \ No newline at end of file +} diff --git a/srcs/parsing/check_color_texture.c b/srcs/parsing/check_color_texture.c index 3f532fb..2f2679c 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/15 01:04:34 by apommier ### ########.fr */ +/* Updated: 2022/06/15 12:40:19 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -115,7 +115,7 @@ void check_value(char **tab) } } -void set_color_utils(char **tab, color *img) +void set_color_utils(char **tab, color *rgb) { if (ft_strlen(tab[0]) > 3 || !(ft_atoi(tab[0]) >= 0 && ft_atoi(tab[0]) <= 255)) ft_exit("Error\nBad syntax in map file (RGB)\n"); @@ -124,9 +124,10 @@ void set_color_utils(char **tab, color *img) if (ft_strlen(tab[0]) > 3 || !(ft_atoi(tab[2]) >= 0 && ft_atoi(tab[2]) <= 255)) ft_exit("Error\nBad syntax in map file (RGB)\n"); check_value(tab); - img->r = (unsigned char)ft_atoi(tab[0]); - img->g = (unsigned char)ft_atoi(tab[1]); - img->b = (unsigned char)ft_atoi(tab[2]); + rgb->r = (unsigned char)ft_atoi(tab[0]); + rgb->g = (unsigned char)ft_atoi(tab[1]); + rgb->b = (unsigned char)ft_atoi(tab[2]); + rgb->set = 1; //printf("---%d\n", img->g); } @@ -137,15 +138,15 @@ void set_color(char *str, t_data *img) int index; char **tab; - printf("str=%s \n", str); + //printf("str=%s \n", str); c = next_space(str, 0); index = next_space_index(str + 1, 0); tab = ft_split(str + index + 1, ','); if (!tab) quit_game(img); - if (double_size(tab) != 3) - ft_exit("Error\nBad syntax in map file (RGB) 1\n"); - print_double_fd(tab, 1); + //if (double_size(tab) != 3) + // ft_exit("Error\nBad syntax in map file (RGB) 1\n"); + //print_double_fd(tab, 1); if (c == 'F') set_color_utils(tab, &img->map.floor); if (c == 'C') diff --git a/srcs/utils.c b/srcs/utils.c index 27d482f..2555e71 100644 --- a/srcs/utils.c +++ b/srcs/utils.c @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/02/13 23:37:02 by apommier #+# #+# */ -/* Updated: 2022/06/15 00:54:36 by apommier ### ########.fr */ +/* Updated: 2022/06/15 12:33:07 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -55,9 +55,6 @@ double reset_angle(double angle) void ft_error(char *error_msg) { - /*int i; - - i = 0;*/ ft_putendl_fd(error_msg, 2); exit(1); } @@ -107,43 +104,11 @@ int update_pos(t_data *img) return (0); } -int create_trgb(unsigned char t, unsigned char r, unsigned char g, unsigned char b) -{ - return (*(int *)(unsigned char [4]){b, g, r, t}); -} - void set_back(t_data *img) { - /*for(int y = 0; y < 512; ++y) - for(int x = 0; x < 960; ++x) - { - int pixel = (y * img->size_line) + (x * 4); + int x; - if (endian == 1) // Most significant (Alpha) byte first - { - buffer[pixel + 0] = (color >> 24); - buffer[pixel + 1] = (color >> 16) & 0xFF; - buffer[pixel + 2] = (color >> 8) & 0xFF; - buffer[pixel + 3] = (color) & 0xFF; - } - //else if (endian == 0) // Least significant (Blue) byte first - //{ - img->buffer[pixel + 0] = (color) & 0xFF; - img->buffer[pixel + 1] = (color >> 8) & 0xFF; - img->buffer[pixel + 2] = (color >> 16) & 0xFF; - img->buffer[pixel + 3] = (color >> 24); - //} - }*/ - int x = 0; - //int tmp; - - //tmp = (int *)img->buffer; - // img->map.floor.r = 128; - // img->map.floor.g = 128; - // img->map.floor.b = 128; - // img->map.sky.r = 0; - // img->map.sky.g = 191; - // img->map.sky.b = 255; + x = 0; while (x < 512 * 960 * 4) { if (x > 512 * 960 * 2) @@ -155,14 +120,6 @@ void set_back(t_data *img) img->buffer[x + 2] =img->map.floor.r; img->buffer[x + 3] = 0; } - //tmp = create_trgb(128, 128, 128, 0); - else - { - img->buffer[x + 0] = 128; - img->buffer[x + 1] = 128; - img->buffer[x + 2] = 128; - img->buffer[x + 3] = 0; - } } else { @@ -170,11 +127,6 @@ void set_back(t_data *img) img->buffer[x + 1] = img->map.sky.g; img->buffer[x + 2] =img->map.sky.r; img->buffer[x + 3] = 0; - //tmp = create_trgb(255, 191, 0, 0); - /*img->buffer[x + 0] = 255; - img->buffer[x + 1] = 191; - img->buffer[x + 2] = 0; - img->buffer[x + 3] = 0;*/ } x += 4; }