diff --git a/includes/Cub3D.h b/includes/Cub3D.h index 2a19225..c305489 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/15 15:29:25 by apommier ### ########.fr */ +/* Updated: 2022/06/15 15:51:37 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -72,11 +72,11 @@ typedef struct map_information{ typedef struct player_position { - double x; - double y; - double angle; - double vx; - double vy; + double x; + double y; + double angle; + double vx; + double vy; int front; int side; int angle_side; @@ -85,24 +85,26 @@ typedef struct player_position typedef struct need_to_be_free { - char **tab; - int fd; + char **tab; + char **tab_two; + unsigned char *str; + int fd; } to_free; typedef struct s_data { - void *mlx; - void *mlx_win; - void *mlx_test; - int bits_per_pixel; - int size_line; - int endian; - char *buffer; - void *mlx_win_test; - char **double_map; - map_info map; - player player; - to_free to_be_free; - int err; + void *mlx; + void *mlx_win; + void *mlx_test; + int bits_per_pixel; + int size_line; + int endian; + char *buffer; + void *mlx_win_test; + char **double_map; + map_info map; + player player; + to_free to_be_free; + int err; } t_data; int update_pos(t_data *img); diff --git a/srcs/get_texture_array.c b/srcs/get_texture_array.c index c54c93c..a13a3ad 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 15:30:23 by apommier ### ########.fr */ +/* Updated: 2022/06/15 16:12:02 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -85,10 +85,11 @@ unsigned char *get_texture(char type, char *path, t_data *img)//change in list close(fd); img->to_be_free.fd = -1; if (count != 12291) - ft_exit("Error\n Bad texture file\n", img); + ft_exit("Error\nBad texture file\n", img); ret = ft_calloc(sizeof(char), count); if (!ret) quit_game(img); + img->to_be_free.str = ret; fd = open(path, O_RDONLY); if (fd == -1) ft_exit("Error\nBad texture file", img); @@ -104,7 +105,6 @@ unsigned char *get_texture(char type, char *path, t_data *img)//change in list { free(swap); swap = get_next_line(fd); - } if (swap) swap[ft_strlen(swap) - 1] = 0; @@ -112,14 +112,14 @@ unsigned char *get_texture(char type, char *path, t_data *img)//change in list 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", img); + free(swap); + ft_exit("Error\nBad texture file2\n", img); } count++; } close(fd); img->to_be_free.fd = -1; put_texture_in_struct(type, ret, img); + img->to_be_free.str = 0; return (ret); } diff --git a/srcs/main.c b/srcs/main.c index 7fa9c00..0861ab6 100644 --- a/srcs/main.c +++ b/srcs/main.c @@ -6,18 +6,19 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/02/13 16:42:55 by apommier #+# #+# */ -/* Updated: 2022/06/15 15:25:12 by apommier ### ########.fr */ +/* Updated: 2022/06/15 15:52:45 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ #include "../includes/Cub3D.h" -void set_map(t_data *img) +void set_map_player(t_data *img) { img->map.texture.north = 0; img->map.texture.east = 0; img->map.texture.south = 0; img->map.texture.west = 0; + img->map.simple_map = 0; img->player.x = 0; img->player.y = 0; img->player.angle = 0; @@ -27,8 +28,12 @@ void set_map(t_data *img) img->player.side = 0; img->player.angle_side = 0; img->player.shift = 0; + img->to_be_free.str = 0; img->to_be_free.tab = NULL; + img->to_be_free.tab_two = NULL; img->to_be_free.fd = -1; + img->mlx = 0; + img->mlx_win = 0; } int key_pressed(int type, t_data *img) @@ -84,7 +89,7 @@ int main(int argc, char **argv) if (argc != 2) ft_error("Error\nBad number of arguments, only need a map\n"); - set_map(&img); + set_map_player(&img); img.player.x = 0; img.player.y = 0; if (check_map(argv, &img)) diff --git a/srcs/parsing/check_color_texture.c b/srcs/parsing/check_color_texture.c index b2ca5e3..743b68d 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 15:27:14 by apommier ### ########.fr */ +/* Updated: 2022/06/15 15:49:19 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -108,7 +108,7 @@ void check_value(char **tab, t_data *img) while (tab[i][j]) { if (!ft_isdigit(tab[i][j])) - ft_exit("Error\nBad syntax in map file (RGB)2\n", img); + ft_exit("Error\nRGB parameters need to be only digits\n", img); j++; } i++; @@ -118,11 +118,11 @@ void check_value(char **tab, t_data *img) void set_color_utils(char **tab, color *rgb, t_data *img) { 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", img); + ft_exit("Error\nBad parameter in map file identifier(RGB)\n", img); if (ft_strlen(tab[0]) > 3 || !(ft_atoi(tab[1]) >= 0 && ft_atoi(tab[1]) <= 255)) - ft_exit("Error\nBad syntax in map file (RGB)\n", img); + ft_exit("Error\nBad parameter in map file identifier(RGB)\n", 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", img); + ft_exit("Error\nBad parameter in map file identifier(RGB)\n", img); check_value(tab, img); rgb->r = (unsigned char)ft_atoi(tab[0]); rgb->g = (unsigned char)ft_atoi(tab[1]); @@ -138,12 +138,19 @@ void set_color(char *str, t_data *img) int index; char **tab; + index = -1; + while (str[++index]) + { + if (str[index] == ',' && str[index + 1] == ',') + ft_exit("Error\nBad syntax for RGB identifier\n", img); + } //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); + img->to_be_free.tab_two = tab; //if (double_size(tab) != 3) // ft_exit("Error\nBad syntax in map file (RGB) 1\n"); //print_double_fd(tab, 1); @@ -152,6 +159,7 @@ void set_color(char *str, t_data *img) if (c == 'C') set_color_utils(tab, &img->map.sky, img); free_double(tab); + img->to_be_free.tab_two = 0; } int check_texture_color(char **tab, t_data *img) @@ -168,7 +176,7 @@ int check_texture_color(char **tab, t_data *img) while (next_space(tab[next], 0) != '1' && tab[next]) next++; if (!tab[next]) - ft_exit("Error\nBad syntax in map file\n", img); + ft_exit("Error\nBad syntax in map file (identifier)\n", img); while (index < next) { 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') @@ -179,7 +187,7 @@ int check_texture_color(char **tab, t_data *img) } else if (next_space(tab[index], 0)) - ft_exit("Error\nBad syntax in map file\n", img); + ft_exit("Error\nBad syntax in map file (identifier)\n", img); index++; } return (next); diff --git a/srcs/parsing/parse_map.c b/srcs/parsing/parse_map.c index b959f0c..266bc0f 100644 --- a/srcs/parsing/parse_map.c +++ b/srcs/parsing/parse_map.c @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/05/10 17:54:25 by sadjigui #+# #+# */ -/* Updated: 2022/06/15 15:26:12 by apommier ### ########.fr */ +/* Updated: 2022/06/15 15:54:55 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -37,13 +37,13 @@ void verifie_texture_color(t_data *img) void error_msg(t_data *img) { if (img->map.error == 1) - ft_exit("Error: Map isn't closed\n", img); + ft_exit("Error\nMap isn't closed\n", img); if (img->map.error == 2) - ft_exit("Error: Missing player\n", img); + ft_exit("Error\nMissing player\n", img); if (img->map.error == 3) - ft_exit("Error: Too many players\n", img); + ft_exit("Error\nToo many players\n", img); if (img->map.error == -1) - ft_exit("Error: Bad character in map\n", img); + ft_exit("Error\nBad character in map\n", img); } void size_line(char *str, t_data *img) @@ -289,7 +289,7 @@ char **isafile(char **av, t_data *img) str = NULL; tmp = NULL; if (fd == - 1) - ft_exit("Error: File doesn't exist\n", img); + ft_exit("Error\nFile doesn't exist\n", img); while ((line = get_next_line(fd)) != NULL) { if (line[0] != '\n' && img->err == 0) @@ -337,7 +337,7 @@ int check_map(char **av, t_data *img) if (reverse_comp(av[1], ".cub") || (ft_strlen(av[1]) == ft_strlen(".cub"))) { - ft_exit("Error: Not a valid file \".cub\"\n", img); + ft_exit("Error\nNot a valid file \".cub\"\n", img); return (1); } isafile(av, img); diff --git a/srcs/utils.c b/srcs/utils.c index dfe65fe..3fb05a7 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 15:29:19 by apommier ### ########.fr */ +/* Updated: 2022/06/15 15:53:35 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,15 +25,23 @@ void free_texture(t_data *img) } int quit_game(t_data *img) -{ - mlx_destroy_window(img->mlx, img->mlx_win); - mlx_destroy_display(img->mlx); +{ if (img->mlx) + { + if (img->mlx_win) + mlx_destroy_window(img->mlx, img->mlx_win); + mlx_destroy_display(img->mlx); free(img->mlx); + } free_texture(img); - free(img->map.simple_map); + if (img->map.simple_map) + free(img->map.simple_map); if (img->to_be_free.tab) free_double(img->to_be_free.tab); + if (img->to_be_free.tab_two) + free_double(img->to_be_free.tab_two); + if (img->to_be_free.str) + free(img->to_be_free.str); if (img->to_be_free.fd != -1) close(img->to_be_free.fd);