diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ft_del_lists.c (renamed from src/ft_del_extra_sprites.c) | 32 | ||||
-rw-r--r-- | src/ft_del_map.c | 36 | ||||
-rw-r--r-- | src/ft_del_tex.c | 101 | ||||
-rw-r--r-- | src/ft_exit.c | 99 | ||||
-rw-r--r-- | src/ft_free_words.c | 2 | ||||
-rw-r--r-- | src/ft_treat_args.c | 2 | ||||
-rw-r--r-- | src/ft_warp_level.c | 54 | ||||
-rw-r--r-- | src/main.c | 2 |
8 files changed, 167 insertions, 161 deletions
diff --git a/src/ft_del_extra_sprites.c b/src/ft_del_lists.c index 21df608..e1a5288 100644 --- a/src/ft_del_extra_sprites.c +++ b/src/ft_del_lists.c @@ -1,31 +1,43 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* ft_key_loop.c :+: :+: :+: */ +/* ft_del_lists.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2020/02/17 20:06:26 by rbousset #+# #+# */ -/* Updated: 2020/02/17 20:06:29 by rbousset ### ########lyon.fr */ +/* Created: 2020/02/14 17:28:46 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:28:46 by rbousset ### ########lyon.fr */ /* */ /* ************************************************************************** */ #include <libft.h> #include <cub3d.h> -#include <mlx.h> #include <stdint.h> -#include <stddef.h> void - ft_del_extra_sprites(t_cub *cl) + ft_del_lists(t_cub *clist) { uint8_t i; - i = 1; - while ((i + 2) <= cl->mlist.topsp) + i = 0; + while (i < 10) { - if (cl->tlist[i + 7].img) - mlx_destroy_image(cl->wlist.wlx, cl->tlist[i + 7].img); + 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 <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:28:46 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:28:46 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include <libft.h> +#include <cub3d.h> +#include <stdint.h> + +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 <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:28:46 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:28:46 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include <cub3d.h> +#include <mlx.h> +#include <stdint.h> + +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 <pthread.h> 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); @@ -56,72 +30,6 @@ static void } 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) { uint8_t i; @@ -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 <libft.h> 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 @@ -21,27 +21,6 @@ #include <pthread.h> 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) { int16_t tmp_life; @@ -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]); @@ -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); } |