mirror of
https://codeberg.org/ACME-Corporation/cub3d.git
synced 2025-12-06 09:58:09 +01:00
dev: Improved memory management of sprites
This commit is contained in:
parent
3230a60c9f
commit
f1697a6c73
6 changed files with 73 additions and 16 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/07/17 14:59:37 by kcolin #+# #+# */
|
||||
/* Updated: 2025/08/07 11:28:49 by tchampio ### ########.fr */
|
||||
/* Updated: 2025/08/11 11:59:21 by tchampio ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -20,6 +20,9 @@
|
|||
# include "utils/keypresses.h"
|
||||
# include "consts.h"
|
||||
|
||||
// FIXME: Delete this line to let it compile for bonus part
|
||||
# define BONUS 1
|
||||
|
||||
// the 4 static sprites are some of the perks and the mystery box
|
||||
typedef struct s_cub3d_data
|
||||
{
|
||||
|
|
|
|||
41
src/utils/destroy_utils.c
Normal file
41
src/utils/destroy_utils.c
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* destroy_utils.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/08/11 12:04:26 by tchampio #+# #+# */
|
||||
/* Updated: 2025/08/11 12:30:06 by tchampio ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../cub3d_data.h"
|
||||
#include "../../mlx/mlx.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
void destroy_textures(t_cub3d_data *data)
|
||||
{
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
void destroy_sprites(t_cub3d_data *data)
|
||||
{
|
||||
int sprite;
|
||||
|
||||
sprite = 0;
|
||||
while (sprite < MAX_SPRITES)
|
||||
free(data->sprite_list[sprite++]);
|
||||
}
|
||||
21
src/utils/destroy_utils.h
Normal file
21
src/utils/destroy_utils.h
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* destroy_utils.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/08/11 12:07:48 by tchampio #+# #+# */
|
||||
/* Updated: 2025/08/11 12:10:21 by tchampio ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef DESTROY_UTILS_H
|
||||
# define DESTROY_UTILS_H
|
||||
|
||||
# include "../cub3d_data.h"
|
||||
|
||||
void destroy_textures(t_cub3d_data *data);
|
||||
void destroy_sprites(t_cub3d_data *data);
|
||||
|
||||
#endif
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/07/17 13:59:27 by kcolin #+# #+# */
|
||||
/* Updated: 2025/07/31 14:25:10 by kcolin ### ########.fr */
|
||||
/* Updated: 2025/08/11 12:45:32 by tchampio ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,6 +14,7 @@
|
|||
#include "../../libft/includes/libft.h"
|
||||
#include "../map/mapdata.h"
|
||||
#include "../cub3d_data.h"
|
||||
#include "./destroy_utils.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
void free_tab(char **tab)
|
||||
|
|
@ -65,21 +66,11 @@ int destroy(t_cub3d_data *data, int exit_code)
|
|||
mlx_destroy_window(data->mlx, data->mlx_win);
|
||||
if (data->img_data)
|
||||
mlx_destroy_image(data->mlx, data->img_data->img);
|
||||
destroy_textures(data);
|
||||
free(data->img_data);
|
||||
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);
|
||||
if (data->mlx)
|
||||
mlx_destroy_display(data->mlx);
|
||||
free(data->sprite_list);
|
||||
free(data->mlx);
|
||||
free(data->screen_matrix);
|
||||
exit(exit_code);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/07/31 13:43:05 by kcolin #+# #+# */
|
||||
/* Updated: 2025/08/11 11:52:31 by tchampio ### ########.fr */
|
||||
/* Updated: 2025/08/11 12:44:57 by tchampio ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue