aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-03-15 01:02:32 +0100
committerJozanLeClerc <bousset.rudy@gmail.com>2020-03-15 01:02:32 +0100
commit9f35e7fab50809cd74e3bfffff67a81023abc837 (patch)
tree8ed891643db7c95aa7f72a1bab2a5f02efbbd078
parentLooks like I have to pthread this shit (diff)
download42-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
-rw-r--r--inc/cub3d_structs.h5
-rw-r--r--map/lvl_one.cub2
-rw-r--r--src/ft_draw_scene.c1
-rw-r--r--src/ft_exit.c9
-rw-r--r--src/ft_get_music.c3
-rw-r--r--src/ft_init_map.c5
-rw-r--r--src/ft_music.c23
-rw-r--r--src/ft_warp_level.c9
8 files changed, 29 insertions, 28 deletions
diff --git a/inc/cub3d_structs.h b/inc/cub3d_structs.h
index 7545f3b..aaf8498 100644
--- a/inc/cub3d_structs.h
+++ b/inc/cub3d_structs.h
@@ -14,9 +14,9 @@
# define CUB3D_STRUCTS_H
#include <stddef.h>
-#include <stdlib.h>
#include <stdint.h>
#include <sys/types.h>
+#include <pthread.h>
typedef struct s_win
{
@@ -189,7 +189,6 @@ typedef struct s_map
char *mapl;
char **sprite_path;
char **map;
- char **mcmd_words;
int8_t x_step;
int8_t y_step;
size_t map_w;
@@ -230,7 +229,7 @@ typedef struct s_cub
char *const *envp;
char errmsg[64];
int32_t key_input[5];
- pid_t mpid;
+ pthread_t mtid;
int (*key_ptr[6])(struct s_cub*);
int8_t (*get_ptr[14])(char**, struct s_cub*);
char ref[22][3];
diff --git a/map/lvl_one.cub b/map/lvl_one.cub
index 688f216..e6b93c7 100644
--- a/map/lvl_one.cub
+++ b/map/lvl_one.cub
@@ -14,7 +14,7 @@ SH 4
L ./map/lvl_two.cub
LT ./media/img/crapaud.xpm
-MU ./media/sound/BITURE-ET-MELANCOLIE.wav
+MU ./media/sound/sfx/death_screen.wav
1111111
111111111111L00001
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