From ba7cbd8dbffac2b75ccac01d628ca493426ecf70 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Sun, 22 Mar 2020 15:25:01 +0100 Subject: Pretty bav --- Makefile | 4 +- inc/cub3d.h | 15 +++++-- src/ft_del_extra_sprites.c | 31 -------------- src/ft_del_lists.c | 43 +++++++++++++++++++ src/ft_del_map.c | 36 ++++++++++++++++ src/ft_del_tex.c | 101 +++++++++++++++++++++++++++++++++++++++++++++ src/ft_exit.c | 99 ++------------------------------------------ src/ft_free_words.c | 2 +- src/ft_treat_args.c | 2 + src/ft_warp_level.c | 54 +----------------------- src/main.c | 2 - 11 files changed, 202 insertions(+), 187 deletions(-) delete mode 100644 src/ft_del_extra_sprites.c create mode 100644 src/ft_del_lists.c create mode 100644 src/ft_del_map.c create mode 100644 src/ft_del_tex.c diff --git a/Makefile b/Makefile index 21eebd3..f40452f 100644 --- a/Makefile +++ b/Makefile @@ -90,7 +90,6 @@ SRCS_NAME += ft_suffer_animation.c SRCS_NAME += ft_draw_traps.c SRCS_NAME += ft_draw_traps_extra.c SRCS_NAME += ft_draw_life_bar.c -SRCS_NAME += ft_del_extra_sprites.c SRCS_NAME += ft_init_sfx.c SRCS_NAME += ft_sfx_death.c SRCS_NAME += ft_sfx_footstep.c @@ -117,6 +116,9 @@ SRCS_NAME += ft_switch_weapons.c SRCS_NAME += ft_init_weaps.c SRCS_NAME += ft_check_missing_defines.c SRCS_NAME += ft_check_missing_sfx.c +SRCS_NAME += ft_del_tex.c +SRCS_NAME += ft_del_map.c +SRCS_NAME += ft_del_lists.c #--------------------------------------------------------------------------------------------------# SRCS = $(addprefix ${SRCS_DIR},${SRCS_NAME}) #--------------------------------------------------------------------------------------------------# diff --git a/inc/cub3d.h b/inc/cub3d.h index 6a1ed2d..b8b6681 100644 --- a/inc/cub3d.h +++ b/inc/cub3d.h @@ -182,6 +182,17 @@ void *ft_sfx_weapon_one_fire_thread(void *vargp); void *ft_sfx_weapon_two_load_thread(void *vargp); void *ft_sfx_weapon_two_fire_thread(void *vargp); +/* +** ====== DELETION ====== +*/ + +void ft_del_tex(t_cub *clist); +void ft_del_map(t_map *ml); +void ft_del_lists(t_cub *clist); +uint8_t ft_free_words(char **words); +uint8_t ft_free_sprites_path(char **sprites); +int ft_exit(uint8_t exit_code, t_cub *clist); + /* ** ====== OTHER ====== */ @@ -191,11 +202,7 @@ void ft_enable_music(t_cub *cl); void ft_music_fork(char **mcmd_words, char *const envp[]); int8_t ft_save_to_bmp(t_cub *cl); int ft_error(uint8_t retval, const char *errmsg, t_cub *clist); -uint8_t ft_free_words(char **words); -uint8_t ft_free_sprites(char **sprites); -void ft_del_extra_sprites(t_cub *cl); int8_t ft_warp_level(char *path, t_cub *cl); -int ft_exit(uint8_t exit_code, t_cub *clist); uint32_t ft_rgb_to_hex(t_rgb rgb); t_bmp_rgb ft_hex_to_rgb(uint32_t color); uint32_t ft_darken(t_rgb rgb, t_cub *cl); diff --git a/src/ft_del_extra_sprites.c b/src/ft_del_extra_sprites.c deleted file mode 100644 index 21df608..0000000 --- a/src/ft_del_extra_sprites.c +++ /dev/null @@ -1,31 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_key_loop.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: rbousset +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2020/02/17 20:06:26 by rbousset #+# #+# */ -/* Updated: 2020/02/17 20:06:29 by rbousset ### ########lyon.fr */ -/* */ -/* ************************************************************************** */ - -#include -#include -#include -#include -#include - -void - ft_del_extra_sprites(t_cub *cl) -{ - uint8_t i; - - i = 1; - while ((i + 2) <= cl->mlist.topsp) - { - if (cl->tlist[i + 7].img) - mlx_destroy_image(cl->wlist.wlx, cl->tlist[i + 7].img); - i++; - } -} diff --git a/src/ft_del_lists.c b/src/ft_del_lists.c new file mode 100644 index 0000000..e1a5288 --- /dev/null +++ b/src/ft_del_lists.c @@ -0,0 +1,43 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_del_lists.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:28:46 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:28:46 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include + +void + ft_del_lists(t_cub *clist) +{ + uint8_t i; + + i = 0; + while (i < 10) + { + ft_memdel((void*)&clist->sfx[i].cmd); + i++; + } + ft_memdel((void*)&clist->sfx[1].cmd_alt); + ft_memdel((void*)&clist->sfx[3].cmd_alt); + while (i < 8) + { + ft_memdel((void*)&clist->sprites[i]); + i++; + } + ft_memdel((void*)&clist->sprites); + i = 0; + while (i < 2) + { + ft_memdel((void*)&clist->weaps[i]); + i++; + } + ft_memdel((void*)&clist->weaps); +} diff --git a/src/ft_del_map.c b/src/ft_del_map.c new file mode 100644 index 0000000..0c03007 --- /dev/null +++ b/src/ft_del_map.c @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_del_map.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:28:46 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:28:46 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include + +void + ft_del_map(t_map *ml) +{ + ft_memdel((void*)&ml->filename); + ft_memdel((void*)&ml->no_tex_path); + ft_memdel((void*)&ml->so_tex_path); + ft_memdel((void*)&ml->ea_tex_path); + ft_memdel((void*)&ml->we_tex_path); + ft_memdel((void*)&ml->nl_tex_path); + ft_memdel((void*)&ml->fl_tex_path); + ft_memdel((void*)&ml->ce_tex_path); + ft_memdel((void*)&ml->nlevel_path); + ft_memdel((void*)&ml->skybox_path); + ft_memdel((void*)&ml->traps_path); + ft_memdel((void*)&ml->music_path); + ft_memdel((void*)&ml->music_cmd); + ft_memdel((void*)&ml->mapl); + ft_free_words(ml->map); + ft_free_sprites_path(ml->sprite_path); +} diff --git a/src/ft_del_tex.c b/src/ft_del_tex.c new file mode 100644 index 0000000..839387a --- /dev/null +++ b/src/ft_del_tex.c @@ -0,0 +1,101 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_del_tex.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:28:46 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:28:46 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include + +static void + ft_del_extra_sprites(t_cub *cl) +{ + uint8_t i; + + i = 1; + while ((i + 2) <= cl->mlist.topsp) + { + if (cl->tlist[i + 7].img) + mlx_destroy_image(cl->wlist.wlx, cl->tlist[i + 7].img); + i++; + } +} + +static void + ft_del_tnum(t_cub *cl) +{ + int8_t i; + + i = 0; + while (i < 11) + { + if (cl->tnum[i].img) + mlx_destroy_image(cl->wlist.wlx, cl->tnum[i].img); + i++; + } +} + +static void + ft_del_tweap(t_cub *cl) +{ + int8_t i; + + i = 0; + while (i < 4) + { + if (cl->tweap[i].img) + mlx_destroy_image(cl->wlist.wlx, cl->tweap[i].img); + i++; + } +} + +static void + ft_del_bonus_tex(t_cub *cl) +{ + if (cl->mlist.isnlvl && cl->tlist[5].img) + mlx_destroy_image(cl->wlist.wlx, cl->tlist[5].img); + if (cl->mlist.isftex && cl->tlist[6].img) + mlx_destroy_image(cl->wlist.wlx, cl->tlist[6].img); + if (cl->mlist.isctex && cl->tlist[7].img) + mlx_destroy_image(cl->wlist.wlx, cl->tlist[7].img); + if (cl->mlist.istraps && cl->tlist[15].img) + mlx_destroy_image(cl->wlist.wlx, cl->tlist[15].img); + if (cl->tlist[16].img) + mlx_destroy_image(cl->wlist.wlx, cl->tlist[16].img); + if (cl->mlist.isheals && cl->tlist[17].img) + mlx_destroy_image(cl->wlist.wlx, cl->tlist[17].img); + if (cl->tlist[18].img) + mlx_destroy_image(cl->wlist.wlx, cl->tlist[18].img); + if (cl->tlist[19].img) + mlx_destroy_image(cl->wlist.wlx, cl->tlist[19].img); +} + +void + ft_del_tex(t_cub *cl) +{ + if (cl->wlist.inited) + { + if (cl->tlist[0].img) + mlx_destroy_image(cl->wlist.wlx, cl->tlist[0].img); + if (cl->tlist[1].img) + mlx_destroy_image(cl->wlist.wlx, cl->tlist[1].img); + if (cl->tlist[2].img) + mlx_destroy_image(cl->wlist.wlx, cl->tlist[2].img); + if (cl->tlist[3].img) + mlx_destroy_image(cl->wlist.wlx, cl->tlist[3].img); + if (cl->tlist[4].img) + mlx_destroy_image(cl->wlist.wlx, cl->tlist[4].img); + ft_del_bonus_tex(cl); + ft_del_tweap(cl); + ft_del_tnum(cl); + ft_del_extra_sprites(cl); + } +} + diff --git a/src/ft_exit.c b/src/ft_exit.c index 8bf79ce..2af15c7 100644 --- a/src/ft_exit.c +++ b/src/ft_exit.c @@ -19,34 +19,8 @@ #include static void - ft_free_some_extras(t_cub *clist) + ft_del_last_remains(t_cub *clist) { - uint8_t i; - - i = 0; - while (i < 8) - { - ft_memdel((void*)&clist->sprites[i]); - i++; - } - ft_memdel((void*)&clist->sprites); - if (clist->wlist.inited) - { - i = 0; - while (i < 4) - { - if (clist->tweap[i].img) - mlx_destroy_image(clist->wlist.wlx, clist->tweap[i].img); - i++; - } - i = 0; - while (i < 2) - { - if (clist->tlist[i + 18].img) - mlx_destroy_image(clist->wlist.wlx, clist->tlist[i + 18].img); - i++; - } - } if (!clist->wlist.inited) { ft_memdel((void*)&clist->wlist.winptr); @@ -55,72 +29,6 @@ static void ft_memdel((void*)&clist); } -static void - ft_free_lists(t_cub *clist) -{ - uint8_t i; - - ft_memdel((void*)&clist->mlist.filename); - ft_memdel((void*)&clist->mlist.no_tex_path); - ft_memdel((void*)&clist->mlist.so_tex_path); - ft_memdel((void*)&clist->mlist.ea_tex_path); - ft_memdel((void*)&clist->mlist.we_tex_path); - ft_memdel((void*)&clist->mlist.nl_tex_path); - ft_memdel((void*)&clist->mlist.fl_tex_path); - ft_memdel((void*)&clist->mlist.ce_tex_path); - ft_memdel((void*)&clist->mlist.nlevel_path); - ft_memdel((void*)&clist->mlist.skybox_path); - ft_memdel((void*)&clist->mlist.traps_path); - ft_memdel((void*)&clist->mlist.music_path); - ft_memdel((void*)&clist->mlist.music_cmd); - ft_memdel((void*)&clist->mlist.mapl); - ft_free_words(clist->mlist.map); - i = -1; - while (++i < 10) - ft_memdel((void*)&clist->sfx[i].cmd); - ft_memdel((void*)&clist->sfx[1].cmd_alt); - ft_memdel((void*)&clist->sfx[3].cmd_alt); - ft_free_sprites(clist->mlist.sprite_path); - i = -1; - while (++i < 2) - ft_memdel((void*)&clist->weaps[i]); - ft_memdel((void*)&clist->weaps); -} - -static void - ft_del_tex(t_cub *clist) -{ - int8_t i; - - if (clist->tlist[0].img) - mlx_destroy_image(clist->wlist.wlx, clist->tlist[0].img); - if (clist->tlist[1].img) - mlx_destroy_image(clist->wlist.wlx, clist->tlist[1].img); - if (clist->tlist[2].img) - mlx_destroy_image(clist->wlist.wlx, clist->tlist[2].img); - if (clist->tlist[3].img) - mlx_destroy_image(clist->wlist.wlx, clist->tlist[3].img); - if (clist->tlist[4].img) - mlx_destroy_image(clist->wlist.wlx, clist->tlist[4].img); - if (clist->mlist.isnlvl && clist->tlist[5].img) - mlx_destroy_image(clist->wlist.wlx, clist->tlist[5].img); - if (clist->mlist.isftex && clist->tlist[6].img) - mlx_destroy_image(clist->wlist.wlx, clist->tlist[6].img); - if (clist->mlist.isctex && clist->tlist[7].img) - mlx_destroy_image(clist->wlist.wlx, clist->tlist[7].img); - if (clist->mlist.istraps && clist->tlist[15].img) - mlx_destroy_image(clist->wlist.wlx, clist->tlist[15].img); - if (clist->tlist[16].img) - mlx_destroy_image(clist->wlist.wlx, clist->tlist[16].img); - if (clist->mlist.isheals && clist->tlist[17].img) - mlx_destroy_image(clist->wlist.wlx, clist->tlist[17].img); - i = -1; - while (++i < 11) - if (clist->tnum[i].img) - mlx_destroy_image(clist->wlist.wlx, clist->tnum[i].img); - ft_del_extra_sprites(clist); -} - static void ft_cancel_threads(t_cub *clist) { @@ -152,8 +60,9 @@ int mlx_destroy_window(clist->wlist.wlx, clist->wlist.winptr); } ft_cancel_threads(clist); - ft_free_lists(clist); - ft_free_some_extras(clist); + ft_del_map(&clist->mlist); + ft_del_lists(clist); + ft_del_last_remains(clist); ft_printf("Exiting program\n"); exit(exit_code); return (0); diff --git a/src/ft_free_words.c b/src/ft_free_words.c index 3ca01c8..50795c2 100644 --- a/src/ft_free_words.c +++ b/src/ft_free_words.c @@ -13,7 +13,7 @@ #include uint8_t - ft_free_sprites(char **sprites) + ft_free_sprites_path(char **sprites) { uint8_t i; diff --git a/src/ft_treat_args.c b/src/ft_treat_args.c index 0e1eae3..cf487f7 100644 --- a/src/ft_treat_args.c +++ b/src/ft_treat_args.c @@ -36,6 +36,8 @@ uint8_t { if (ft_init_winptr(clist) < 0) return (ft_exit(FT_RET_FAILED_MLX, clist)); + ft_wall_tex_init(clist); + ft_weap_tex_init(clist); if (FT_OS == 1) { clist->img.img = mlx_new_image(clist->wlist.wlx, diff --git a/src/ft_warp_level.c b/src/ft_warp_level.c index 2eb165e..8fb5415 100644 --- a/src/ft_warp_level.c +++ b/src/ft_warp_level.c @@ -20,27 +20,6 @@ #include #include -static void - ft_del_map(t_map *ml) -{ - ft_memdel((void*)&ml->filename); - ft_memdel((void*)&ml->no_tex_path); - ft_memdel((void*)&ml->so_tex_path); - ft_memdel((void*)&ml->ea_tex_path); - ft_memdel((void*)&ml->we_tex_path); - ft_memdel((void*)&ml->nl_tex_path); - ft_memdel((void*)&ml->fl_tex_path); - ft_memdel((void*)&ml->ce_tex_path); - ft_memdel((void*)&ml->nlevel_path); - ft_memdel((void*)&ml->skybox_path); - ft_memdel((void*)&ml->traps_path); - ft_memdel((void*)&ml->music_path); - ft_memdel((void*)&ml->music_cmd); - ft_memdel((void*)&ml->mapl); - ft_free_sprites(ml->sprite_path); - ft_free_words(ml->map); -} - static void ft_player_keepings(t_cub *cl) { @@ -69,38 +48,7 @@ static void cl->f_rgb = ft_init_rgb(); cl->c_rgb = ft_init_rgb(); cl->rlist = ft_init_s_ray(); - i = -1; - while (++i < 5) - mlx_destroy_image(cl->wlist.wlx, cl->tlist[i].img); - if (cl->mlist.isnlvl && cl->tlist[5].img) - mlx_destroy_image(cl->wlist.wlx, cl->tlist[5].img); - if (cl->mlist.isftex && cl->tlist[6].img) - mlx_destroy_image(cl->wlist.wlx, cl->tlist[6].img); - if (cl->mlist.isctex && cl->tlist[7].img) - mlx_destroy_image(cl->wlist.wlx, cl->tlist[7].img); - if (cl->mlist.istraps && cl->tlist[15].img) - mlx_destroy_image(cl->wlist.wlx, cl->tlist[15].img); - if (cl->tlist[16].img) - mlx_destroy_image(cl->wlist.wlx, cl->tlist[16].img); - if (cl->mlist.isheals && cl->tlist[17].img) - mlx_destroy_image(cl->wlist.wlx, cl->tlist[17].img); - if (cl->tlist[18].img) - mlx_destroy_image(cl->wlist.wlx, cl->tlist[18].img); - if (cl->tlist[19].img) - mlx_destroy_image(cl->wlist.wlx, cl->tlist[19].img); - if (cl->tweap[0].img) - mlx_destroy_image(cl->wlist.wlx, cl->tweap[0].img); - if (cl->tweap[1].img) - mlx_destroy_image(cl->wlist.wlx, cl->tweap[1].img); - if (cl->tweap[2].img) - mlx_destroy_image(cl->wlist.wlx, cl->tweap[2].img); - if (cl->tweap[3].img) - mlx_destroy_image(cl->wlist.wlx, cl->tweap[3].img); - ft_del_extra_sprites(cl); - i = -1; - while (++i < 11) - if (cl->tnum[i].img) - mlx_destroy_image(cl->wlist.wlx, cl->tnum[i].img); + ft_del_tex(cl); i = -1; while (++i < 8) ft_memdel((void*)&cl->sprites[i]); diff --git a/src/main.c b/src/main.c index c50508f..4cbd7a2 100644 --- a/src/main.c +++ b/src/main.c @@ -29,8 +29,6 @@ int ft_parse_map(argv[1], clist); if (ft_init_winlx(clist) < 0) return (ft_exit(FT_RET_FAILED_MLX, clist)); - ft_wall_tex_init(clist); - ft_weap_tex_init(clist); ft_use_args(argc, argv, clist); return (FT_RET_FINE); } -- cgit v1.2.3