diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-02 00:56:03 +0100 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-02 00:56:03 +0100 |
commit | d812df80d26f879d4d49ec45453866574e995839 (patch) | |
tree | d6c143d0356d72a4274dc125e354b4e51acf0f4b /src | |
parent | in progress (diff) | |
download | 42-cub3d-d812df80d26f879d4d49ec45453866574e995839.tar.gz 42-cub3d-d812df80d26f879d4d49ec45453866574e995839.tar.bz2 42-cub3d-d812df80d26f879d4d49ec45453866574e995839.tar.xz 42-cub3d-d812df80d26f879d4d49ec45453866574e995839.tar.zst 42-cub3d-d812df80d26f879d4d49ec45453866574e995839.zip |
trying to thread
Diffstat (limited to 'src')
-rw-r--r-- | src/ft_get_music.c | 3 | ||||
-rw-r--r-- | src/ft_music.c | 28 | ||||
-rw-r--r-- | src/ft_parse_map.c | 2 | ||||
-rw-r--r-- | src/ft_treat_args.c | 10 |
4 files changed, 31 insertions, 12 deletions
diff --git a/src/ft_get_music.c b/src/ft_get_music.c index 0b6fede..b232980 100644 --- a/src/ft_get_music.c +++ b/src/ft_get_music.c @@ -22,7 +22,6 @@ int8_t ft_sprintf(clist->errmsg, FT_ERR_ARGS); return (-1); } - ft_printf("%s", *(words + 1)); if (ft_check_ext(*(words + 1), ".wav") < 0) { ft_sprintf(clist->errmsg, FT_ERR_NOT_A_WAV); @@ -34,7 +33,7 @@ int8_t ft_sprintf(clist->errmsg, FT_ERR_ALLOCATE); return (-1); } - if (ft_check_not_found(clist->mlist->nlevel_path) < 0) + if (ft_check_not_found(clist->mlist->music_path) < 0) { ft_sprintf(clist->errmsg, FT_ERR_RD_MUSIC); return (-1); diff --git a/src/ft_music.c b/src/ft_music.c index 3050f44..2d97f99 100644 --- a/src/ft_music.c +++ b/src/ft_music.c @@ -12,17 +12,29 @@ #include <libft.h> #include <cub3d.h> +#include <stddef.h> #include <stdlib.h> void - ft_music(t_cub *cl) + *ft_music(void *vargp) { - /* char *cmd; */ - /* uint8_t len; */ + char *cmd; + uint8_t len; + t_cub *cl; - (void)cl; - /* if (FT_OS == 2) */ - /* ft_sprintf(cmd, "aplay -f cd -t wav %s", cl->mlist->music_path); */ - /* else {} */ - /* system(cmd); */ + 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("%s\n", cmd); + system(cmd); + ft_memdel((void**)&cmd); + return (NULL); } diff --git a/src/ft_parse_map.c b/src/ft_parse_map.c index 75eb403..48201fd 100644 --- a/src/ft_parse_map.c +++ b/src/ft_parse_map.c @@ -61,7 +61,7 @@ static int8_t ft_memdel((void**)&line); return (ft_parse_it(fd, clist)); } - if (!ft_ischarset("RNSEWFCL1\0", line[0]) + if (!ft_ischarset("RNSEWFCLM1\0", line[0]) || !(words = ft_split(line, ' '))) return (ft_error_here(FT_ERR_ILL_ENTRY, line, clist)); if ((ret = ft_select_get(words, clist)) == 12) diff --git a/src/ft_treat_args.c b/src/ft_treat_args.c index aee2776..cc1391a 100644 --- a/src/ft_treat_args.c +++ b/src/ft_treat_args.c @@ -12,7 +12,9 @@ #include <libft.h> #include <cub3d.h> +#include <stddef.h> #include <stdint.h> +#include <pthread.h> #include <unistd.h> uint8_t @@ -30,12 +32,18 @@ uint8_t uint8_t ft_use_args(int argc, const char *argv[], t_cub *clist) { + pthread_t tid; + if (argc < 3) { if (ft_init_winptr(clist) < 0) return (ft_exit(FT_RET_FAILED_MLX, clist)); ft_draw_scene(clist); - /* ft_music(clist); */ + if (clist->mlist->ismusic) + { + pthread_create(&tid, NULL, ft_music, clist); + pthread_join(tid, NULL); + } ft_hooks_and_loops(clist->wlist, clist); } else if (argc == 3 && !ft_strncmp("--save", argv[2], 7)) |