-
Notifications
You must be signed in to change notification settings - Fork 0
/
leave_program.c
executable file
·65 lines (60 loc) · 1.76 KB
/
leave_program.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* leave_program.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: roduquen <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/11 00:34:33 by roduquen #+# #+# */
/* Updated: 2019/07/15 21:15:23 by roduquen ### ########.fr */
/* */
/* ************************************************************************** */
#include "wolf.h"
#include <SDL.h>
static int free_surface_and_texture(t_wolf *data, int type)
{
int i;
t_door *tmp;
i = 0;
while (i < TEXTURE_NB + SPRITE_NB + MENU_NB)
{
if (data->surfaces[i])
SDL_FreeSurface(data->surfaces[i]);
i++;
}
i = 0;
while (i < MENU_NB)
{
if (data->menu[i])
SDL_DestroyTexture(data->menu[i]);
i++;
}
while (data->doors)
{
tmp = data->doors;
data->doors = data->doors->next;
free(tmp);
}
return (type);
}
int leave_sdl_and_program(t_wolf *data, int type)
{
int i;
i = 0;
if (data->texture)
SDL_DestroyTexture(data->texture);
if (data->renderer)
SDL_DestroyRenderer(data->renderer);
if (data->window)
SDL_DestroyWindow(data->window);
SDL_Quit();
if (data->map)
free(data->map);
if (data->board)
{
while (data->board[i])
free(data->board[i++]);
free(data->board);
}
return (free_surface_and_texture(data, type));
}