mirror of
https://github.com/Ladebeze66/cub3D.git
synced 2026-11-09 13:47:10 +01:00
onapprochefin
This commit is contained in:
73
exit/ft_exit.c
Normal file
73
exit/ft_exit.c
Normal file
@@ -0,0 +1,73 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_exit.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/30 16:06:24 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/01/30 16:07:27 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../cub3d.h"
|
||||
|
||||
static void free_texture_images(t_structure_main *w)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (++i <= 10)
|
||||
{
|
||||
if (w->s_img.roomadslam[i])
|
||||
mlx_destroy_image(w->s_win.mlx, w->s_img.roomadslam[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void free_textures(t_texture *t)
|
||||
{
|
||||
if (t->north)
|
||||
free(t->north);
|
||||
if (t->south)
|
||||
free(t->south);
|
||||
if (t->west)
|
||||
free(t->west);
|
||||
if (t->east)
|
||||
free(t->east);
|
||||
}
|
||||
|
||||
static void destroy_images(t_structure_main *w)
|
||||
{
|
||||
if (w->s_win.mlx)
|
||||
{
|
||||
mlx_destroy_image(w->s_win.mlx, w->s_img.buffer);
|
||||
mlx_destroy_image(w->s_win.mlx, w->s_img.img_player);
|
||||
mlx_destroy_image(w->s_win.mlx, w->s_img.img_wall);
|
||||
mlx_destroy_image(w->s_win.mlx, w->s_img.pedro_wall);
|
||||
mlx_destroy_image(w->s_win.mlx, w->s_img.north_texture);
|
||||
mlx_destroy_image(w->s_win.mlx, w->s_img.south_texture);
|
||||
mlx_destroy_image(w->s_win.mlx, w->s_img.west_texture);
|
||||
mlx_destroy_image(w->s_win.mlx, w->s_img.east_texture);
|
||||
mlx_destroy_image(w->s_win.mlx, w->s_img.door_texture);
|
||||
free_texture_images(w);
|
||||
}
|
||||
}
|
||||
|
||||
void exit_error(t_structure_main *w)
|
||||
{
|
||||
if (w->s_win.mlx)
|
||||
{
|
||||
mlx_destroy_window(w->s_win.mlx, w->s_win.win);
|
||||
destroy_images(w);
|
||||
mlx_destroy_display(w->s_win.mlx);
|
||||
free(w->s_win.mlx);
|
||||
}
|
||||
if (w->s_map.map && (w->error != 1))
|
||||
free(w->s_map.map);
|
||||
if (w->t)
|
||||
{
|
||||
free_textures(w->t);
|
||||
free(w->t);
|
||||
}
|
||||
exit(1);
|
||||
}
|
||||
65
exit/ft_kill_prog.c
Normal file
65
exit/ft_kill_prog.c
Normal file
@@ -0,0 +1,65 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_kill_prog.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/30 16:12:26 by fgras-ca #+# #+# */
|
||||
/* Updated: 2024/01/30 16:17:45 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../cub3d.h"
|
||||
|
||||
static void destroy_images_and_window(t_structure_main *w)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = -1;
|
||||
if (w->s_win.mlx)
|
||||
{
|
||||
mlx_destroy_window(w->s_win.mlx, w->s_win.win);
|
||||
mlx_destroy_image(w->s_win.mlx, w->s_img.buffer);
|
||||
mlx_destroy_image(w->s_win.mlx, w->s_img.img_player);
|
||||
mlx_destroy_image(w->s_win.mlx, w->s_img.img_wall);
|
||||
mlx_destroy_image(w->s_win.mlx, w->s_img.pedro_wall);
|
||||
mlx_destroy_image(w->s_win.mlx, w->s_img.north_texture);
|
||||
mlx_destroy_image(w->s_win.mlx, w->s_img.south_texture);
|
||||
mlx_destroy_image(w->s_win.mlx, w->s_img.west_texture);
|
||||
mlx_destroy_image(w->s_win.mlx, w->s_img.east_texture);
|
||||
mlx_destroy_image(w->s_win.mlx, w->s_img.door_texture);
|
||||
while (++i <= 10)
|
||||
mlx_destroy_image(w->s_win.mlx, w->s_img.roomadslam[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void cleanup_and_exit(t_structure_main *w)
|
||||
{
|
||||
if (w->s_map.map)
|
||||
{
|
||||
free(w->s_map.map);
|
||||
w->s_map.map = NULL;
|
||||
}
|
||||
if (w->t)
|
||||
{
|
||||
free(w->t->north);
|
||||
free(w->t->south);
|
||||
free(w->t->west);
|
||||
free(w->t->east);
|
||||
free(w->t);
|
||||
}
|
||||
if (w->s_win.mlx)
|
||||
{
|
||||
mlx_destroy_display(w->s_win.mlx);
|
||||
free(w->s_win.mlx);
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
||||
int *kill_prog(t_structure_main *w)
|
||||
{
|
||||
destroy_images_and_window(w);
|
||||
cleanup_and_exit(w);
|
||||
return (0);
|
||||
}
|
||||
Reference in New Issue
Block a user