aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--Makefile2
-rw-r--r--inc/cub3d.h2
-rw-r--r--src/ft_get_music.c3
-rw-r--r--src/ft_music.c28
-rw-r--r--src/ft_parse_map.c2
-rw-r--r--src/ft_treat_args.c10
6 files changed, 33 insertions, 14 deletions
diff --git a/Makefile b/Makefile
index 9aee1f4..429b30b 100644
--- a/Makefile
+++ b/Makefile
@@ -147,7 +147,7 @@ ifeq (${OS}, Darwin)
${CC} ${CFLAGS} -o $@ ${OBJS} -L${LFT_DIR} -L${MLX_DIR} -lft -lmlx -lm -framework OpenGL \
-framework AppKit
else
- ${CC} ${CFLAGS} -o $@ ${OBJS} -L${LFT_DIR} -lft -lX11 -lXext -lmlx -lm -lbsd
+ ${CC} ${CFLAGS} -o $@ ${OBJS} -L${LFT_DIR} -lft -lX11 -lXext -lmlx -lm -lbsd -lpthread
endif
#--------------------------------------------------------------------------------------------------#
all: ${NAME}
diff --git a/inc/cub3d.h b/inc/cub3d.h
index 3ddf188..751d6b0 100644
--- a/inc/cub3d.h
+++ b/inc/cub3d.h
@@ -114,7 +114,7 @@ uint8_t ft_use_args(int argc, const char *argv[], t_cub *clist);
*/
void ft_set_minimap_scale(t_cub *clist);
-void ft_music(t_cub *cl);
+void *ft_music(void *vargp);
void ft_detect(t_cub *cl);
void ft_castray(t_cub *cl);
void ft_save_to_bmp(void);
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))