set img in ft_exit to quit_game
This commit is contained in:
parent
8540ddc1ce
commit
ff64788b94
@ -6,7 +6,7 @@
|
|||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/02/13 16:30:59 by apommier #+# #+# */
|
/* Created: 2022/02/13 16:30:59 by apommier #+# #+# */
|
||||||
/* Updated: 2022/06/15 14:40:14 by apommier ### ########.fr */
|
/* Updated: 2022/06/15 15:29:25 by apommier ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -48,7 +48,6 @@ typedef struct all_wall_texture{
|
|||||||
unsigned char *east;
|
unsigned char *east;
|
||||||
unsigned char *west;
|
unsigned char *west;
|
||||||
unsigned char *south;
|
unsigned char *south;
|
||||||
unsigned char *basic;
|
|
||||||
} sprite;
|
} sprite;
|
||||||
|
|
||||||
typedef struct s_color{
|
typedef struct s_color{
|
||||||
@ -86,10 +85,8 @@ typedef struct player_position
|
|||||||
|
|
||||||
typedef struct need_to_be_free
|
typedef struct need_to_be_free
|
||||||
{
|
{
|
||||||
char **one_tab;
|
char **tab;
|
||||||
char **two_tab;
|
int fd;
|
||||||
char *one_str;
|
|
||||||
int fd_one;
|
|
||||||
} to_free;
|
} to_free;
|
||||||
|
|
||||||
typedef struct s_data {
|
typedef struct s_data {
|
||||||
@ -112,7 +109,7 @@ int update_pos(t_data *img);
|
|||||||
char *transform_map(char **double_map, t_data *img);
|
char *transform_map(char **double_map, t_data *img);
|
||||||
int check_texture_color(char **tab, t_data *img);
|
int check_texture_color(char **tab, t_data *img);
|
||||||
int check_map(char **av, t_data *img);
|
int check_map(char **av, t_data *img);
|
||||||
void ft_exit(char *str);
|
void ft_exit(char *str, t_data *img);
|
||||||
void set_back(t_data *img);
|
void set_back(t_data *img);
|
||||||
unsigned char *get_texture(char type, char *path, t_data *img);
|
unsigned char *get_texture(char type, char *path, t_data *img);
|
||||||
int get_color(char one, char two, char three);
|
int get_color(char one, char two, char three);
|
||||||
|
|||||||
@ -134,8 +134,6 @@ void draw_ray3d(t_data *img, ray ray)
|
|||||||
color = get_color(img->map.texture.west[ray.pixel], img->map.texture.west[ray.pixel + 1], img->map.texture.west[ray.pixel + 2]);
|
color = get_color(img->map.texture.west[ray.pixel], img->map.texture.west[ray.pixel + 1], img->map.texture.west[ray.pixel + 2]);
|
||||||
else if (ray.texture_type == 'E' && img->map.texture.east)
|
else if (ray.texture_type == 'E' && img->map.texture.east)
|
||||||
color = get_color(img->map.texture.east[ray.pixel], img->map.texture.east[ray.pixel + 1], img->map.texture.east[ray.pixel + 2]);
|
color = get_color(img->map.texture.east[ray.pixel], img->map.texture.east[ray.pixel + 1], img->map.texture.east[ray.pixel + 2]);
|
||||||
else
|
|
||||||
color = get_color(img->map.texture.basic[ray.pixel], img->map.texture.basic[ray.pixel + 1], img->map.texture.basic[ray.pixel + 2]);//here read
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
color = 0;
|
color = 0;
|
||||||
@ -177,7 +175,7 @@ void draw_ray(t_data *img)
|
|||||||
|
|
||||||
new_img = mlx_new_image(img->mlx, 960, 512);
|
new_img = mlx_new_image(img->mlx, 960, 512);
|
||||||
if (!new_img)
|
if (!new_img)
|
||||||
ft_exit("Error\nmlx_new_image failed\n");
|
ft_exit("Error\nmlx_new_image failed\n", img);
|
||||||
//printf("newimg= %p\n", new_img);
|
//printf("newimg= %p\n", new_img);
|
||||||
img->buffer = mlx_get_data_addr(new_img, &bits_per_pixel, &size_line, &endian);
|
img->buffer = mlx_get_data_addr(new_img, &bits_per_pixel, &size_line, &endian);
|
||||||
//img->buffer// = (char*)new_img;
|
//img->buffer// = (char*)new_img;
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/05/06 16:10:11 by apommier #+# #+# */
|
/* Created: 2022/05/06 16:10:11 by apommier #+# #+# */
|
||||||
/* Updated: 2022/06/15 14:36:04 by apommier ### ########.fr */
|
/* Updated: 2022/06/15 15:30:23 by apommier ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -17,25 +17,25 @@ void put_texture_in_struct(char type, unsigned char *texture, t_data *img)
|
|||||||
if (type == 'N')
|
if (type == 'N')
|
||||||
{
|
{
|
||||||
if (img->map.texture.north)
|
if (img->map.texture.north)
|
||||||
ft_exit("Error\nMultiple declaration of texture\n");
|
ft_exit("Error\nMultiple declaration of texture\n", img);
|
||||||
img->map.texture.north = texture;
|
img->map.texture.north = texture;
|
||||||
}
|
}
|
||||||
if (type == 'S')
|
if (type == 'S')
|
||||||
{
|
{
|
||||||
if (img->map.texture.south)
|
if (img->map.texture.south)
|
||||||
ft_exit("Error\nMultiple declaration of texture\n");
|
ft_exit("Error\nMultiple declaration of texture\n", img);
|
||||||
img->map.texture.south = texture;
|
img->map.texture.south = texture;
|
||||||
}
|
}
|
||||||
if (type == 'W')
|
if (type == 'W')
|
||||||
{
|
{
|
||||||
if (img->map.texture.west)
|
if (img->map.texture.west)
|
||||||
ft_exit("Error\nMultiple declaration of texture\n");
|
ft_exit("Error\nMultiple declaration of texture\n", img);
|
||||||
img->map.texture.west = texture;
|
img->map.texture.west = texture;
|
||||||
}
|
}
|
||||||
if (type == 'E')
|
if (type == 'E')
|
||||||
{
|
{
|
||||||
if (img->map.texture.east)
|
if (img->map.texture.east)
|
||||||
ft_exit("Error\nMultiple declaration of texture\n");
|
ft_exit("Error\nMultiple declaration of texture\n", img);
|
||||||
img->map.texture.east = texture;
|
img->map.texture.east = texture;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -69,12 +69,12 @@ unsigned char *get_texture(char type, char *path, t_data *img)//change in list
|
|||||||
if (fd >= 0)
|
if (fd >= 0)
|
||||||
{
|
{
|
||||||
close(fd);
|
close(fd);
|
||||||
ft_exit("Error\nTexture path is a directory\n");
|
ft_exit("Error\nTexture path is a directory\n", img);
|
||||||
}
|
}
|
||||||
fd = open(path, O_RDONLY);
|
fd = open(path, O_RDONLY);
|
||||||
if (fd == -1)
|
if (fd == -1)
|
||||||
quit_game(img);
|
quit_game(img);
|
||||||
img->to_be_free.fd_one = fd;
|
img->to_be_free.fd = fd;
|
||||||
while (swap || !count)
|
while (swap || !count)
|
||||||
{
|
{
|
||||||
if (swap)
|
if (swap)
|
||||||
@ -83,17 +83,16 @@ unsigned char *get_texture(char type, char *path, t_data *img)//change in list
|
|||||||
swap = get_next_line(fd);
|
swap = get_next_line(fd);
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
img->to_be_free.fd_one = -1;
|
img->to_be_free.fd = -1;
|
||||||
printf("count= %d\n", count);
|
|
||||||
if (count != 12291)
|
if (count != 12291)
|
||||||
ft_exit("Error\n Bad texture file\n");
|
ft_exit("Error\n Bad texture file\n", img);
|
||||||
ret = ft_calloc(sizeof(char), count);
|
ret = ft_calloc(sizeof(char), count);
|
||||||
if (!ret)
|
if (!ret)
|
||||||
quit_game(img);
|
quit_game(img);
|
||||||
fd = open(path, O_RDONLY);
|
fd = open(path, O_RDONLY);
|
||||||
if (fd == -1)
|
if (fd == -1)
|
||||||
ft_exit("Error\nBad texture file");
|
ft_exit("Error\nBad texture file", img);
|
||||||
img->to_be_free.fd_one = fd;
|
img->to_be_free.fd = fd;
|
||||||
count = 0;
|
count = 0;
|
||||||
while (swap || !count)
|
while (swap || !count)
|
||||||
{
|
{
|
||||||
@ -115,12 +114,12 @@ unsigned char *get_texture(char type, char *path, t_data *img)//change in list
|
|||||||
{
|
{
|
||||||
//printf("isnbr= %d swap= %s ft_atoi(swap)= ---%ld--- strlen= %ld\n",is_nbr(swap) ,swap , ft_atoi(swap), ft_strlen(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);
|
free(ret);
|
||||||
ft_exit("Error\nBad texture file\n");
|
ft_exit("Error\nBad texture file\n", img);
|
||||||
}
|
}
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
img->to_be_free.fd_one = -1;
|
img->to_be_free.fd = -1;
|
||||||
put_texture_in_struct(type, ret, img);
|
put_texture_in_struct(type, ret, img);
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|||||||
10
srcs/main.c
10
srcs/main.c
@ -6,7 +6,7 @@
|
|||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/02/13 16:42:55 by apommier #+# #+# */
|
/* Created: 2022/02/13 16:42:55 by apommier #+# #+# */
|
||||||
/* Updated: 2022/06/15 15:19:08 by apommier ### ########.fr */
|
/* Updated: 2022/06/15 15:25:12 by apommier ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -27,8 +27,8 @@ void set_map(t_data *img)
|
|||||||
img->player.side = 0;
|
img->player.side = 0;
|
||||||
img->player.angle_side = 0;
|
img->player.angle_side = 0;
|
||||||
img->player.shift = 0;
|
img->player.shift = 0;
|
||||||
img->to_be_free.one_tab = NULL;
|
img->to_be_free.tab = NULL;
|
||||||
img->to_be_free.fd_one = -1;
|
img->to_be_free.fd = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int key_pressed(int type, t_data *img)
|
int key_pressed(int type, t_data *img)
|
||||||
@ -83,7 +83,7 @@ int main(int argc, char **argv)
|
|||||||
t_data img;
|
t_data img;
|
||||||
|
|
||||||
if (argc != 2)
|
if (argc != 2)
|
||||||
ft_error("Error: bad number of arguments, only need a map");
|
ft_error("Error\nBad number of arguments, only need a map\n");
|
||||||
set_map(&img);
|
set_map(&img);
|
||||||
img.player.x = 0;
|
img.player.x = 0;
|
||||||
img.player.y = 0;
|
img.player.y = 0;
|
||||||
@ -91,7 +91,7 @@ int main(int argc, char **argv)
|
|||||||
return (0);
|
return (0);
|
||||||
img.mlx = mlx_init();
|
img.mlx = mlx_init();
|
||||||
if (!img.mlx)
|
if (!img.mlx)
|
||||||
ft_error("Error: mlx_init fail");
|
ft_exit("Error\nmlx_init fail\n", &img);
|
||||||
img.mlx_win = mlx_new_window(img.mlx, 960, 512, "Cub3D");
|
img.mlx_win = mlx_new_window(img.mlx, 960, 512, "Cub3D");
|
||||||
img.player.vx = cos(deg_to_rad(img.player.angle));
|
img.player.vx = cos(deg_to_rad(img.player.angle));
|
||||||
img.player.vy = sin(deg_to_rad(img.player.angle));
|
img.player.vy = sin(deg_to_rad(img.player.angle));
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/06/11 01:00:17 by apommier #+# #+# */
|
/* Created: 2022/06/11 01:00:17 by apommier #+# #+# */
|
||||||
/* Updated: 2022/06/15 12:40:19 by apommier ### ########.fr */
|
/* Updated: 2022/06/15 15:27:14 by apommier ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -75,28 +75,28 @@ void set_texture_file(char *str, t_data *img, char c)
|
|||||||
if (c == 'N')
|
if (c == 'N')
|
||||||
{
|
{
|
||||||
if (str[index + 1] != 'O' || str[index + 2] != ' ')
|
if (str[index + 1] != 'O' || str[index + 2] != ' ')
|
||||||
ft_exit("Error\nBad syntax in map file\n");
|
ft_exit("Error\nBad syntax in map file\n", img);
|
||||||
}
|
}
|
||||||
if (c == 'S')
|
if (c == 'S')
|
||||||
{
|
{
|
||||||
if (str[index + 1] != 'O' || str[index + 2] != ' ')
|
if (str[index + 1] != 'O' || str[index + 2] != ' ')
|
||||||
ft_exit("Error\nBad syntax in map file\n");
|
ft_exit("Error\nBad syntax in map file\n", img);
|
||||||
}
|
}
|
||||||
if (c == 'W')
|
if (c == 'W')
|
||||||
{
|
{
|
||||||
if (str[index + 1] != 'E' || str[index + 2] != ' ')
|
if (str[index + 1] != 'E' || str[index + 2] != ' ')
|
||||||
ft_exit("Error\nBad syntax in map file\n");
|
ft_exit("Error\nBad syntax in map file\n", img);
|
||||||
}
|
}
|
||||||
if (c == 'E')
|
if (c == 'E')
|
||||||
{
|
{
|
||||||
if (str[index + 1] != 'A' || str[index + 2] != ' ')
|
if (str[index + 1] != 'A' || str[index + 2] != ' ')
|
||||||
ft_exit("Error\nBad syntax in map file\n");
|
ft_exit("Error\nBad syntax in map file\n", img);
|
||||||
}
|
}
|
||||||
//printf("path= -%s-\n", str + index + 3);
|
//printf("path= -%s-\n", str + index + 3);
|
||||||
get_texture(c, str + index + 3, img);
|
get_texture(c, str + index + 3, img);
|
||||||
}
|
}
|
||||||
|
|
||||||
void check_value(char **tab)
|
void check_value(char **tab, t_data *img)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int j;
|
int j;
|
||||||
@ -108,22 +108,22 @@ void check_value(char **tab)
|
|||||||
while (tab[i][j])
|
while (tab[i][j])
|
||||||
{
|
{
|
||||||
if (!ft_isdigit(tab[i][j]))
|
if (!ft_isdigit(tab[i][j]))
|
||||||
ft_exit("Error\nBad syntax in map file (RGB)2\n");
|
ft_exit("Error\nBad syntax in map file (RGB)2\n", img);
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_color_utils(char **tab, color *rgb)
|
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))
|
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");
|
ft_exit("Error\nBad syntax in map file (RGB)\n", img);
|
||||||
if (ft_strlen(tab[0]) > 3 || !(ft_atoi(tab[1]) >= 0 && ft_atoi(tab[1]) <= 255))
|
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");
|
ft_exit("Error\nBad syntax in map file (RGB)\n", img);
|
||||||
if (ft_strlen(tab[0]) > 3 || !(ft_atoi(tab[2]) >= 0 && ft_atoi(tab[2]) <= 255))
|
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");
|
ft_exit("Error\nBad syntax in map file (RGB)\n", img);
|
||||||
check_value(tab);
|
check_value(tab, img);
|
||||||
rgb->r = (unsigned char)ft_atoi(tab[0]);
|
rgb->r = (unsigned char)ft_atoi(tab[0]);
|
||||||
rgb->g = (unsigned char)ft_atoi(tab[1]);
|
rgb->g = (unsigned char)ft_atoi(tab[1]);
|
||||||
rgb->b = (unsigned char)ft_atoi(tab[2]);
|
rgb->b = (unsigned char)ft_atoi(tab[2]);
|
||||||
@ -148,9 +148,9 @@ void set_color(char *str, t_data *img)
|
|||||||
// ft_exit("Error\nBad syntax in map file (RGB) 1\n");
|
// ft_exit("Error\nBad syntax in map file (RGB) 1\n");
|
||||||
//print_double_fd(tab, 1);
|
//print_double_fd(tab, 1);
|
||||||
if (c == 'F')
|
if (c == 'F')
|
||||||
set_color_utils(tab, &img->map.floor);
|
set_color_utils(tab, &img->map.floor, img);
|
||||||
if (c == 'C')
|
if (c == 'C')
|
||||||
set_color_utils(tab, &img->map.sky);
|
set_color_utils(tab, &img->map.sky, img);
|
||||||
free_double(tab);
|
free_double(tab);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,7 +168,7 @@ int check_texture_color(char **tab, t_data *img)
|
|||||||
while (next_space(tab[next], 0) != '1' && tab[next])
|
while (next_space(tab[next], 0) != '1' && tab[next])
|
||||||
next++;
|
next++;
|
||||||
if (!tab[next])
|
if (!tab[next])
|
||||||
ft_exit("Error\nBad syntax in map file\n");
|
ft_exit("Error\nBad syntax in map file\n", img);
|
||||||
while (index < next)
|
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')
|
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 +179,7 @@ int check_texture_color(char **tab, t_data *img)
|
|||||||
|
|
||||||
}
|
}
|
||||||
else if (next_space(tab[index], 0))
|
else if (next_space(tab[index], 0))
|
||||||
ft_exit("Error\nBad syntax in map file\n");
|
ft_exit("Error\nBad syntax in map file\n", img);
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
return (next);
|
return (next);
|
||||||
|
|||||||
@ -6,44 +6,44 @@
|
|||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/05/10 17:54:25 by sadjigui #+# #+# */
|
/* Created: 2022/05/10 17:54:25 by sadjigui #+# #+# */
|
||||||
/* Updated: 2022/06/15 15:19:20 by apommier ### ########.fr */
|
/* Updated: 2022/06/15 15:26:12 by apommier ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "../../includes/Cub3D.h"
|
#include "../../includes/Cub3D.h"
|
||||||
|
|
||||||
void ft_exit(char *str)
|
void ft_exit(char *str, t_data *img)
|
||||||
{
|
{
|
||||||
ft_putstr_fd(str, 2);
|
ft_putstr_fd(str, 2);
|
||||||
exit(1);
|
quit_game(img);
|
||||||
}
|
}
|
||||||
|
|
||||||
void verifie_texture_color(t_data *img)
|
void verifie_texture_color(t_data *img)
|
||||||
{
|
{
|
||||||
if (img->map.texture.north == NULL)
|
if (img->map.texture.north == NULL)
|
||||||
ft_exit("Error\nTexture isn't loaded properly\n");
|
ft_exit("Error\nTexture isn't loaded properly\n", img);
|
||||||
if (img->map.texture.east == NULL)
|
if (img->map.texture.east == NULL)
|
||||||
ft_exit("Error\nTexture isn't loaded properly\n");
|
ft_exit("Error\nTexture isn't loaded properly\n", img);
|
||||||
if (img->map.texture.south == NULL)
|
if (img->map.texture.south == NULL)
|
||||||
ft_exit("Error\nTexture isn't loaded properly\n");
|
ft_exit("Error\nTexture isn't loaded properly\n", img);
|
||||||
if (img->map.texture.west == NULL)
|
if (img->map.texture.west == NULL)
|
||||||
ft_exit("Error\nTexture isn't loaded properly\n");
|
ft_exit("Error\nTexture isn't loaded properly\n", img);
|
||||||
if (img->map.floor.set != 1)
|
if (img->map.floor.set != 1)
|
||||||
ft_exit("Error\nColor not set properly\n");
|
ft_exit("Error\nColor not set properly\n", img);
|
||||||
if (img->map.sky.set != 1)
|
if (img->map.sky.set != 1)
|
||||||
ft_exit("Error\nColor not set properly\n");
|
ft_exit("Error\nColor not set properly\n", img);
|
||||||
}
|
}
|
||||||
|
|
||||||
void error_msg(t_data *img)
|
void error_msg(t_data *img)
|
||||||
{
|
{
|
||||||
if (img->map.error == 1)
|
if (img->map.error == 1)
|
||||||
ft_exit("Error: Map isn't closed\n");
|
ft_exit("Error: Map isn't closed\n", img);
|
||||||
if (img->map.error == 2)
|
if (img->map.error == 2)
|
||||||
ft_exit("Error: Missing player\n");
|
ft_exit("Error: Missing player\n", img);
|
||||||
if (img->map.error == 3)
|
if (img->map.error == 3)
|
||||||
ft_exit("Error: Too many players\n");
|
ft_exit("Error: Too many players\n", img);
|
||||||
if (img->map.error == -1)
|
if (img->map.error == -1)
|
||||||
ft_exit("Error: Bad character in map\n");
|
ft_exit("Error: Bad character in map\n", img);
|
||||||
}
|
}
|
||||||
|
|
||||||
void size_line(char *str, t_data *img)
|
void size_line(char *str, t_data *img)
|
||||||
@ -285,11 +285,11 @@ char **isafile(char **av, t_data *img)
|
|||||||
|
|
||||||
img->err = 0;
|
img->err = 0;
|
||||||
fd = open(av[1], O_RDONLY);
|
fd = open(av[1], O_RDONLY);
|
||||||
img->to_be_free.fd_one = fd;
|
img->to_be_free.fd = fd;
|
||||||
str = NULL;
|
str = NULL;
|
||||||
tmp = NULL;
|
tmp = NULL;
|
||||||
if (fd == - 1)
|
if (fd == - 1)
|
||||||
ft_exit("Error: File doesn't exist\n");
|
ft_exit("Error: File doesn't exist\n", img);
|
||||||
while ((line = get_next_line(fd)) != NULL)
|
while ((line = get_next_line(fd)) != NULL)
|
||||||
{
|
{
|
||||||
if (line[0] != '\n' && img->err == 0)
|
if (line[0] != '\n' && img->err == 0)
|
||||||
@ -311,21 +311,21 @@ char **isafile(char **av, t_data *img)
|
|||||||
if (img->err == 2)
|
if (img->err == 2)
|
||||||
{
|
{
|
||||||
free(str);
|
free(str);
|
||||||
ft_exit("Error\nBad texture file\n");
|
ft_exit("Error\nBad texture file\n", img);
|
||||||
}
|
}
|
||||||
split = ft_split(str, '\n');
|
split = ft_split(str, '\n');
|
||||||
img->to_be_free.one_tab = split;
|
img->to_be_free.tab = split;
|
||||||
free(str);
|
free(str);
|
||||||
free(line);
|
free(line);
|
||||||
close(fd);
|
close(fd);
|
||||||
img->to_be_free.fd_one = -1;
|
img->to_be_free.fd = -1;
|
||||||
int pass = 0;
|
int pass = 0;
|
||||||
pass = check_texture_color(split, img);
|
pass = check_texture_color(split, img);
|
||||||
check_zero_one(split + pass, img);
|
check_zero_one(split + pass, img);
|
||||||
//leaks here -- normalement c bon
|
//leaks here -- normalement c bon
|
||||||
transform_map(split + pass, img);
|
transform_map(split + pass, img);
|
||||||
free_double(split);
|
free_double(split);
|
||||||
img->to_be_free.one_tab = 0;
|
img->to_be_free.tab = 0;
|
||||||
return (0);
|
return (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")))
|
if (reverse_comp(av[1], ".cub") || (ft_strlen(av[1]) == ft_strlen(".cub")))
|
||||||
{
|
{
|
||||||
ft_putstr_fd("Error: Not a valid file \".cub\"\n", 2);
|
ft_exit("Error: Not a valid file \".cub\"\n", img);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
isafile(av, img);
|
isafile(av, img);
|
||||||
@ -348,7 +348,7 @@ int check_map(char **av, t_data *img)
|
|||||||
if (img->map.error != 0)
|
if (img->map.error != 0)
|
||||||
{
|
{
|
||||||
error_msg(img);
|
error_msg(img);
|
||||||
exit(1);//surely leak
|
quit_game(img);//surely leak???
|
||||||
}
|
}
|
||||||
verifie_texture_color(img);
|
verifie_texture_color(img);
|
||||||
return (0);
|
return (0);
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/02/13 23:37:02 by apommier #+# #+# */
|
/* Created: 2022/02/13 23:37:02 by apommier #+# #+# */
|
||||||
/* Updated: 2022/06/15 14:40:49 by apommier ### ########.fr */
|
/* Updated: 2022/06/15 15:29:19 by apommier ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -22,8 +22,6 @@ void free_texture(t_data *img)
|
|||||||
free(img->map.texture.east);
|
free(img->map.texture.east);
|
||||||
if (img->map.texture.west)
|
if (img->map.texture.west)
|
||||||
free(img->map.texture.west);
|
free(img->map.texture.west);
|
||||||
if (img->map.texture.basic)
|
|
||||||
free(img->map.texture.basic);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int quit_game(t_data *img)
|
int quit_game(t_data *img)
|
||||||
@ -34,7 +32,10 @@ int quit_game(t_data *img)
|
|||||||
free(img->mlx);
|
free(img->mlx);
|
||||||
free_texture(img);
|
free_texture(img);
|
||||||
free(img->map.simple_map);
|
free(img->map.simple_map);
|
||||||
if ()
|
if (img->to_be_free.tab)
|
||||||
|
free_double(img->to_be_free.tab);
|
||||||
|
if (img->to_be_free.fd != -1)
|
||||||
|
close(img->to_be_free.fd);
|
||||||
|
|
||||||
//free(img->map.texture.north);
|
//free(img->map.texture.north);
|
||||||
//free_double(img->map);
|
//free_double(img->map);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user