diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-15 01:02:32 +0100 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-15 01:02:32 +0100 |
commit | 9f35e7fab50809cd74e3bfffff67a81023abc837 (patch) | |
tree | 8ed891643db7c95aa7f72a1bab2a5f02efbbd078 /src | |
parent | Looks like I have to pthread this shit (diff) | |
download | 42-cub3d-9f35e7fab50809cd74e3bfffff67a81023abc837.tar.gz 42-cub3d-9f35e7fab50809cd74e3bfffff67a81023abc837.tar.bz2 42-cub3d-9f35e7fab50809cd74e3bfffff67a81023abc837.tar.xz 42-cub3d-9f35e7fab50809cd74e3bfffff67a81023abc837.tar.zst 42-cub3d-9f35e7fab50809cd74e3bfffff67a81023abc837.zip |
I need a macOS
Diffstat (limited to 'src')
-rw-r--r-- | src/ft_draw_scene.c | 1 | ||||
-rw-r--r-- | src/ft_exit.c | 9 | ||||
-rw-r--r-- | src/ft_get_music.c | 3 | ||||
-rw-r--r-- | src/ft_init_map.c | 5 | ||||
-rw-r--r-- | src/ft_music.c | 23 | ||||
-rw-r--r-- | src/ft_warp_level.c | 9 |
6 files changed, 26 insertions, 24 deletions
diff --git a/src/ft_draw_scene.c b/src/ft_draw_scene.c index 1edef2a..a9ea6c5 100644 --- a/src/ft_draw_scene.c +++ b/src/ft_draw_scene.c @@ -13,6 +13,7 @@ #include <libft.h> #include <cub3d.h> #include <mlx.h> +#include <stdlib.h> #include <stdint.h> static int8_t diff --git a/src/ft_exit.c b/src/ft_exit.c index f1da643..60e950a 100644 --- a/src/ft_exit.c +++ b/src/ft_exit.c @@ -38,7 +38,6 @@ static void ft_memdel((void**)&clist->mlist.music_cmd); ft_memdel((void**)&clist->mlist.mapl); ft_free_words(clist->mlist.map); - ft_free_words(clist->mlist.mcmd_words); ft_free_words(clist->sfx.death); ft_free_words(clist->sfx.pain_one); ft_free_words(clist->sfx.pain_two); @@ -77,9 +76,11 @@ static void { pid_t tmp; - if (!(tmp = waitpid(clist->mpid, NULL, WNOHANG))) - kill(clist->mpid, SIGTERM); - wait(&clist->mpid); + if (clist->isoldmus && clist->wlist.inited) + { + pthread_cancel(clist->mtid); + pthread_join(clist->mtid, NULL); + } if (!(tmp = waitpid(clist->sfx.death_pid, NULL, WNOHANG))) kill(clist->sfx.death_pid, SIGTERM); wait(&clist->sfx.death_pid); diff --git a/src/ft_get_music.c b/src/ft_get_music.c index 7a8d36f..7e6c6be 100644 --- a/src/ft_get_music.c +++ b/src/ft_get_music.c @@ -27,9 +27,6 @@ static int8_t return (-1); ft_sprintf(mlist->music_cmd, FT_SND_CMD, mlist->music_path); - ft_free_words(mlist->mcmd_words); - if (!(mlist->mcmd_words = ft_split(mlist->music_cmd, ' '))) - return (-1); return (0); } diff --git a/src/ft_init_map.c b/src/ft_init_map.c index 813a795..cf5bebe 100644 --- a/src/ft_init_map.c +++ b/src/ft_init_map.c @@ -34,9 +34,7 @@ static int8_t !(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))) || - !(mlist->mcmd_words = (char**)ft_calloc(2, sizeof(char*))) || - !(mlist->mcmd_words[0] = (char*)ft_calloc(1, sizeof(char)))) + !(mlist->map[0] = (char*)ft_calloc(1, sizeof(char)))) return (-1); return (0); } @@ -75,7 +73,6 @@ int8_t if (ft_init_map_callocs(mlist) < 0) return (-1); mlist->map[1] = 0; - mlist->mcmd_words[1] = 0; if (ft_calloc_sprites(mlist) < 0) return (-1); mlist->map_w = 0; diff --git a/src/ft_music.c b/src/ft_music.c index 234f86e..13da479 100644 --- a/src/ft_music.c +++ b/src/ft_music.c @@ -11,21 +11,28 @@ /* ************************************************************************** */ #include <cub3d.h> -#include <unistd.h> +#include <stddef.h> +#include <stdlib.h> +#include <pthread.h> void - ft_music_fork(char **mcmd_words, char *const envp[]) + *ft_music_thread(void *vargp) { - execve(*(mcmd_words + 0), mcmd_words, envp); + t_cub *cl; + + if (FT_OS == 1) + pthread_setcancelstate(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); + else + pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); + cl = (t_cub *)vargp; + while (1) + system(cl->mlist.music_cmd); + return(NULL); } void ft_enable_music(t_cub *cl) { cl->isoldmus = 1; - cl->mpid = fork(); - if (cl->mpid == 0) - { - ft_music_fork(cl->mlist.mcmd_words, cl->envp); - } + pthread_create(&cl->mtid, NULL, ft_music_thread, cl); } diff --git a/src/ft_warp_level.c b/src/ft_warp_level.c index 56d4d67..dd4ed1b 100644 --- a/src/ft_warp_level.c +++ b/src/ft_warp_level.c @@ -39,7 +39,6 @@ static void ft_memdel((void**)&ml->mapl); ft_free_sprites(ml->sprite_path); ft_free_words(ml->map); - ft_free_words(ml->mcmd_words); } static void @@ -74,15 +73,15 @@ static void { if (isoldmus && !cl->mlist.ismusic) { - kill(cl->mpid, SIGTERM); - wait(&cl->mpid); + pthread_cancel(cl->mtid); + pthread_join(cl->mtid, NULL); cl->isoldmus = 0; } else if (isoldmus && cl->mlist.ismusic && ft_strncmp(tmp_mup, cl->mlist.music_path, ft_strlen(tmp_mup) + 1)) { - kill(cl->mpid, SIGTERM); - wait(&cl->mpid); + pthread_cancel(cl->mtid); + pthread_join(cl->mtid, NULL); ft_enable_music(cl); } else if (isoldmus && cl->mlist.ismusic |