-
Notifications
You must be signed in to change notification settings - Fork 1
/
free.c
109 lines (100 loc) · 2.49 KB
/
free.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
97
98
99
100
101
102
103
104
105
106
107
108
109
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* free.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mbousbaa <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/01 05:11:17 by wzakkabi #+# #+# */
/* Updated: 2023/12/06 00:52:43 by mbousbaa ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
void free_all(t_map *map)
{
int i;
i = ((free(map->ea)), (free(map->c)), (free(map->f)), -1);
mlx_close_window(map->mlx);
mlx_close_hook(map->mlx, update_key, map);
mlx_delete_image(map->mlx, map->img);
mlx_delete_texture(map->txt->east);
mlx_delete_texture(map->txt->west);
mlx_delete_texture(map->txt->north);
mlx_delete_texture(map->txt->south);
mlx_terminate(map->mlx);
(free(map->txt), free(map->plr));
free(map->wall3d->a_f);
free(map->wall3d->rays_angle);
free(map->wall3d->small_distance);
free(map->wall3d->x_vertical);
free(map->wall3d);
free(map->width_map);
free(map->no);
free(map->so);
free(map->we);
while (map->map_s[++i])
free(map->map_s[i]);
free(map->map_s);
free(map);
}
void count_and_check(char *types, char l, int *ret)
{
int i;
i = -1;
while (types[++i] != '\0')
{
if (types[i] == l)
{
*ret = 0;
return ;
}
}
if (i != -1)
{
types[*ret] = l;
*ret += 1;
}
}
int get_map_index(char *map)
{
int i;
i = 0;
while (map[i])
{
while (map[i] && (map[i] == '\n' | map[i] == '\t' || map[i] == ' '))
i++;
if (map[i] == 'N' || map[i] == 'S' || map[i] == 'W'
|| map[i] == 'E' || map[i] == 'F' || map[i] == 'C')
{
while (map[i] && map[i] != '\n')
i++;
}
else
{
while (map[i] && map[i] != '1')
i++;
if (map[i] == '1')
return (i);
}
if (map[i])
i++;
}
return (0);
}
void check_map_newlines(char *map)
{
int i;
i = get_map_index(map);
while (map[i])
{
if (map[i] == '\n')
{
i += 1;
while (map[i] && map[i] == ' ')
i++;
if (map[i] == '\n')
error_("Multiple new lines in a map", NULL);
}
i++;
}
}