diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-16 19:41:26 +0100 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-16 19:41:26 +0100 |
commit | a8c9c04ec24a71f076891bdc1c26860db7c5c9c3 (patch) | |
tree | a5dc6905f6987c4d5fcd27276f7fc338f2af8f0b /src/ft_init_sfx.c | |
parent | Cleaner memdels (diff) | |
parent | Merge branch 'master' into back-to-pthread (diff) | |
download | 42-cub3d-a8c9c04ec24a71f076891bdc1c26860db7c5c9c3.tar.gz 42-cub3d-a8c9c04ec24a71f076891bdc1c26860db7c5c9c3.tar.bz2 42-cub3d-a8c9c04ec24a71f076891bdc1c26860db7c5c9c3.tar.xz 42-cub3d-a8c9c04ec24a71f076891bdc1c26860db7c5c9c3.tar.zst 42-cub3d-a8c9c04ec24a71f076891bdc1c26860db7c5c9c3.zip |
Merge branch 'back-to-pthread'
Diffstat (limited to 'src/ft_init_sfx.c')
-rw-r--r-- | src/ft_init_sfx.c | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/src/ft_init_sfx.c b/src/ft_init_sfx.c index 1a06d11..35ab57d 100644 --- a/src/ft_init_sfx.c +++ b/src/ft_init_sfx.c @@ -17,39 +17,41 @@ #include <stdlib.h> #include <stdint.h> #include <unistd.h> +#include <pthread.h> static int8_t - ft_split_sfx(char ***target, const char *path) + ft_init_sfx_cmd(char **target, const char *path) { uint8_t len; - char *tmp; len = ft_strlen(path); len += ft_strlen(FT_SND_CMD) - 2; - if (!(tmp = (char *)malloc((len + 1) * sizeof(char)))) + if (!(*target = (char *)malloc((len + 1) * sizeof(char)))) return (-1); - ft_sprintf(tmp, FT_SND_CMD, path); - if (!(*target = ft_split(tmp, ' '))) - { - ft_memdel((void*)&tmp); - return (-1); - } - ft_memdel((void*)&tmp); + ft_sprintf(*target, FT_SND_CMD, path); return (0); } int8_t ft_init_sfx(t_sfx *sfx) { - sfx->death_pid = 0; - sfx->new_lvl_pid = 0; - sfx->pain_pid = 0; - sfx->trap_pid = 0; - if (ft_split_sfx(&sfx->death, FT_SFX_DEATH_PATH) < 0 || - ft_split_sfx(&sfx->new_lvl, FT_SFX_N_LVL_PATH) < 0 || - ft_split_sfx(&sfx->pain_one, FT_SFX_SCR_ONE_PATH) < 0 || - ft_split_sfx(&sfx->pain_two, FT_SFX_SCR_TWO_PATH) < 0 || - ft_split_sfx(&sfx->trap, FT_SFX_TRAP_PATH) < 0) + if (ft_init_sfx_cmd(&sfx->death, FT_SFX_DEATH_PATH) < 0 || + ft_init_sfx_cmd(&sfx->footstep_one, FT_SFX_FS_ONE_PATH) < 0 || + ft_init_sfx_cmd(&sfx->footstep_two, FT_SFX_FS_TWO_PATH) < 0 || + ft_init_sfx_cmd(&sfx->new_lvl, FT_SFX_N_LVL_PATH) < 0 || + ft_init_sfx_cmd(&sfx->pain_one, FT_SFX_SCR_ONE_PATH) < 0 || + ft_init_sfx_cmd(&sfx->pain_two, FT_SFX_SCR_TWO_PATH) < 0 || + ft_init_sfx_cmd(&sfx->trap, FT_SFX_TRAP_PATH) < 0) return (-1); + pthread_mutex_init(&sfx->death_mutex, NULL); + pthread_mutex_init(&sfx->footstep_mutex, NULL); + pthread_mutex_init(&sfx->new_lvl_mutex, NULL); + pthread_mutex_init(&sfx->pain_mutex, NULL); + pthread_mutex_init(&sfx->trap_mutex, NULL); + pthread_create(&sfx->death_tid, NULL, ft_sfx_death_thread, sfx); + pthread_create(&sfx->footstep_tid, NULL, ft_sfx_footstep_thread, sfx); + pthread_create(&sfx->new_lvl_tid, NULL, ft_sfx_new_lvl_thread, sfx); + pthread_create(&sfx->pain_tid, NULL, ft_sfx_pain_thread, sfx); + pthread_create(&sfx->trap_tid, NULL, ft_sfx_trap_thread, sfx); return (0); } |