diff --git a/Makefile b/Makefile index 278d1d0..f19824a 100644 --- a/Makefile +++ b/Makefile @@ -4,13 +4,14 @@ CC = cc # https://github.com/google/sanitizers/wiki/AddressSanitizer SANITIZERS = -fsanitize=address,undefined -fno-omit-frame-pointer ifeq ($(CFLAGS),) - CFLAGS = -Wall -Wextra -Werror -g -O3 -ffast-math + CFLAGS = -Wall -Wextra -Werror -g -O2 endif IFLAGS = -I./mlx -I./libft SOURCEFILES = \ src/utils/inits.c \ src/utils/time.c \ + src/utils/destroy_utils.c \ src/draw/draw_map.c \ src/draw/drawutils.c \ src/main.c \ diff --git a/src/cub3d_data.h b/src/cub3d_data.h index 215ac14..aff808c 100644 --- a/src/cub3d_data.h +++ b/src/cub3d_data.h @@ -6,7 +6,7 @@ /* By: kcolin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 { diff --git a/src/utils/destroy_utils.c b/src/utils/destroy_utils.c new file mode 100644 index 0000000..1fb12f9 --- /dev/null +++ b/src/utils/destroy_utils.c @@ -0,0 +1,41 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* destroy_utils.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tchampio +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 + +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++]); +} diff --git a/src/utils/destroy_utils.h b/src/utils/destroy_utils.h new file mode 100644 index 0000000..710f707 --- /dev/null +++ b/src/utils/destroy_utils.h @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* destroy_utils.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tchampio +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 diff --git a/src/utils/frees.c b/src/utils/frees.c index 8cb62ca..ed3dd88 100644 --- a/src/utils/frees.c +++ b/src/utils/frees.c @@ -6,7 +6,7 @@ /* By: kcolin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 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); diff --git a/src/utils/inits.c b/src/utils/inits.c index 2432197..987e6a7 100644 --- a/src/utils/inits.c +++ b/src/utils/inits.c @@ -6,7 +6,7 @@ /* By: kcolin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 */ /* */ /* ************************************************************************** */