-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.c
96 lines (89 loc) · 2.67 KB
/
init.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* init.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aboncine <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/22 15:41:13 by aboncine #+# #+# */
/* Updated: 2023/02/23 13:00:27 by aboncine ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
static void ft_create_map_2(t_cub3d *box, int count, int fd, char *argv)
{
int i;
i = 0;
box->map = (char **) malloc(sizeof(char *) * (count + 1));
if (!box->map)
ft_perror_exit("Error allocation memory");
close(fd);
fd = open(argv, O_RDONLY);
if (fd < 0)
ft_perror_exit("Error\n");
while (i < count)
box->map[i++] = get_next_line(fd);
box->map[i] = 0;
close(fd);
}
void ft_create_map(t_cub3d *box, char *argv)
{
int fd;
int count;
char *tmp;
count = 0;
fd = open(argv, O_RDONLY);
if (fd < 0)
ft_perror_exit("Error\n");
tmp = get_next_line(fd);
if (tmp != NULL)
count++;
else
ft_perror_exit("Error\n");
while (tmp != NULL)
{
free (tmp);
tmp = get_next_line(fd);
count++;
}
ft_create_map_2(box, count, fd, argv);
}
void ft_init_struct(t_cub3d *box)
{
box->width = 800;
box->height = 600;
box->half_h = box->height / 2;
box->half_w = box->width / 2;
box->rdelay = 30;
box->fov = 66;
box->half_fov = 0;
box->player_x = 2;
box->player_y = 2;
box->angle = 360;
box->rc_precision = 64;
box->rc_incrementing = box->fov / box->width;
box->half_fov = box->fov / 2;
box->path_to_north = NULL;
box->path_to_south = NULL;
box->path_to_east = NULL;
box->path_to_west = NULL;
}
int ft_free_n_exit(t_cub3d *box)
{
mlx_destroy_image(box->mlx_ptr, box->north.img_ptr);
mlx_destroy_image(box->mlx_ptr, box->south.img_ptr);
mlx_destroy_image(box->mlx_ptr, box->east.img_ptr);
mlx_destroy_image(box->mlx_ptr, box->west.img_ptr);
mlx_destroy_image(box->mlx_ptr, box->img.img_ptr);
mlx_destroy_window(box->mlx_ptr, box->win_ptr);
mlx_destroy_display(box->mlx_ptr);
free(box->mlx_ptr);
free(box->path_to_east);
free(box->path_to_west);
free(box->path_to_north);
free(box->path_to_south);
ft_free_map(box->map);
ft_free_map(box->parsed_map);
exit(0);
return (0);
}