diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ft_exit.c | 15 | ||||
-rw-r--r-- | src/ft_get_music.c | 23 | ||||
-rw-r--r-- | src/ft_init_map.c | 1 | ||||
-rw-r--r-- | src/ft_music.c | 17 | ||||
-rw-r--r-- | src/ft_treat_args.c | 1 | ||||
-rw-r--r-- | src/ft_warp_level.c | 7 |
6 files changed, 45 insertions, 19 deletions
diff --git a/src/ft_exit.c b/src/ft_exit.c index d4fb4f9..40860e7 100644 --- a/src/ft_exit.c +++ b/src/ft_exit.c @@ -29,6 +29,7 @@ static void ft_memdel((void**)&clist->mlist->nl_tex_path); ft_memdel((void**)&clist->mlist->nlevel_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); ft_memdel((void**)&clist->mlist); @@ -42,6 +43,9 @@ static void int ft_exit(uint8_t exit_code, t_cub *clist) { + uint8_t ismus; + pthread_t ttid; + if (clist->walltexgood) { if (clist->tlist[0].img) @@ -54,7 +58,7 @@ int 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->tlist[5].img && clist->mlist->isnlvl) + if (clist->mlist->isnlvl && clist->tlist[5].img) mlx_destroy_image(clist->wlist->wlx, clist->tlist[5].img); } if (clist->wlist->inited) @@ -62,10 +66,15 @@ int mlx_destroy_window(clist->wlist->wlx, clist->wlist->winptr); clist->wlist->winptr = NULL; } + ismus = clist->mlist->ismusic; + ttid = clist->tid; ft_free_lists(clist); + if (ismus) + { + pthread_cancel(ttid); + pthread_join(ttid, NULL); + } ft_printf("Exiting program\n"); - pthread_cancel(clist->tid); - pthread_exit(NULL); exit(exit_code); return (0); } diff --git a/src/ft_get_music.c b/src/ft_get_music.c index 86ec7d6..21c6331 100644 --- a/src/ft_get_music.c +++ b/src/ft_get_music.c @@ -12,8 +12,30 @@ #include <libft.h> #include <cub3d.h> +#include <stdlib.h> #include <stdint.h> +static void + ft_set_music_cmd(t_map *mlist) +{ + uint8_t len; + + len = ft_strlen(mlist->music_path); + if (FT_OS == 2) + len += 22; + else + len += 18; + ft_memdel((void**)&mlist->music_cmd); + if (!(mlist->music_cmd = (char *)malloc((len + 1) * sizeof(char)))) + return ; + if (FT_OS == 2) + { + ft_sprintf(mlist->music_cmd, + "aplay -f cd -t wav -q %s", mlist->music_path); + } + else {} +} + int8_t ft_get_music(char **words, t_cub *clist) { @@ -39,5 +61,6 @@ int8_t return (-1); } clist->mlist->ismusic = 1; + ft_set_music_cmd(clist->mlist); return (0); } diff --git a/src/ft_init_map.c b/src/ft_init_map.c index 13448c6..c611ba2 100644 --- a/src/ft_init_map.c +++ b/src/ft_init_map.c @@ -26,6 +26,7 @@ static int8_t !(mlist->nl_tex_path = (char*)ft_calloc(1, sizeof(char))) || !(mlist->nlevel_path = (char*)ft_calloc(1, sizeof(char))) || !(mlist->music_path = (char*)ft_calloc(1, sizeof(char))) || + !(mlist->music_cmd = (char*)ft_calloc(1, sizeof(char))) || !(mlist->mapl = (char*)ft_calloc(1, sizeof(char))) || !(mlist->map = (char**)ft_calloc(2, sizeof(char*))) || !(mlist->map[0] = (char*)ft_calloc(1, sizeof(char)))) diff --git a/src/ft_music.c b/src/ft_music.c index a4d588a..8006928 100644 --- a/src/ft_music.c +++ b/src/ft_music.c @@ -19,24 +19,11 @@ void *ft_music_thread(void *vargp) { - char *cmd; - uint8_t len; t_cub *cl; cl = (t_cub *)vargp; - len = ft_strlen(cl->mlist->music_path); - if (FT_OS == 2) - len += 22; - else - len += 18; - if (!(cmd = (char *)malloc((len + 1) * sizeof(char)))) - return (NULL); - if (FT_OS == 2) - ft_sprintf(cmd, "aplay -f cd -t wav -q %s", cl->mlist->music_path); - else {} - ft_printf("\n\n========= QWEQWE =========\n%s\n", cmd); - system(cmd); - ft_memdel((void**)&cmd); + ft_printf("%s\n", cl->mlist->music_cmd); + system(cl->mlist->music_cmd); return (NULL); } diff --git a/src/ft_treat_args.c b/src/ft_treat_args.c index 25c56d1..dab29ac 100644 --- a/src/ft_treat_args.c +++ b/src/ft_treat_args.c @@ -40,7 +40,6 @@ uint8_t if (clist->mlist->ismusic) { pthread_create(&clist->tid, NULL, ft_music_thread, clist); - /* ft_music_thread(clist); */ } ft_hooks_and_loops(clist->wlist, clist); } diff --git a/src/ft_warp_level.c b/src/ft_warp_level.c index 9a61484..866bd69 100644 --- a/src/ft_warp_level.c +++ b/src/ft_warp_level.c @@ -16,6 +16,7 @@ #include <stddef.h> #include <stdint.h> #include <mlx.h> +#include <pthread.h> static void ft_del_map(t_map *ml) @@ -28,6 +29,7 @@ static void ft_memdel((void**)&ml->nl_tex_path); ft_memdel((void**)&ml->nlevel_path); ft_memdel((void**)&ml->music_path); + ft_memdel((void**)&ml->music_cmd); ft_memdel((void**)&ml->mapl); ft_free_words(ml->map); ft_memdel((void**)&ml); @@ -57,6 +59,11 @@ static void cl->tlist[i].img = NULL; i++; } + if (cl->mlist->ismusic) + { + pthread_cancel(cl->tid); + pthread_exit(NULL); + } } int8_t |