cub3d/src/utils/destroy_utils.c

80 lines
2.4 KiB
C
Raw Normal View History

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* destroy_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/08/18 13:05:31 by kcolin #+# #+# */
2025-09-11 23:41:00 +02:00
/* Updated: 2025/09/10 16:00:47 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
#include "../cub3d_data.h"
#include "../../mlx/mlx.h"
#include <stdlib.h>
2025-09-08 17:11:58 +02:00
void destroy_texture(t_cub3d_data *data, t_img_data *data_img)
{
if (data)
{
mlx_destroy_image(data->mlx, data_img->img);
}
free(data_img);
}
void destroy_textures(t_cub3d_data *data)
{
2025-09-10 15:19:30 +02:00
int i;
if (data->no_texture)
mlx_destroy_image(data->mlx, data->no_texture->img);
free(data->no_texture);
if (data->so_texture)
mlx_destroy_image(data->mlx, data->so_texture->img);
free(data->so_texture);
if (data->ea_texture)
mlx_destroy_image(data->mlx, data->ea_texture->img);
free(data->ea_texture);
if (data->we_texture)
mlx_destroy_image(data->mlx, data->we_texture->img);
free(data->we_texture);
2025-09-10 15:19:30 +02:00
i = 0;
while (i < 7)
destroy_texture(data, data->barricades_texture[i++]);
}
void destroy_sprites(t_cub3d_data *data)
{
int sprite;
sprite = 0;
if (data->sprite_list == NULL)
return ;
while (data->sprite_list[sprite] && sprite < MAX_SPRITES)
{
mlx_destroy_image(data->mlx, data->sprite_list[sprite]->image->img);
free(data->sprite_list[sprite]->image);
free(data->sprite_list[sprite]);
sprite++;
}
}
2025-09-08 17:11:58 +02:00
void destroy_hud_textures(t_cub3d_data *data)
{
int i;
i = 0;
while (i < 10)
destroy_texture(data, data->point_figures[i++]);
i = 0;
while (i < 10)
destroy_texture(data, data->round_figures[i++]);
i = 0;
while (i < 5)
destroy_texture(data, data->tally_marks[i++]);
i = 0;
while (i < 3)
destroy_texture(data, data->perk_logos[i++]);
2025-09-11 23:41:00 +02:00
destroy_texture(data, data->player.weapon.texture);
2025-09-08 17:11:58 +02:00
}