diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-13 19:31:49 +0100 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-13 19:31:49 +0100 |
commit | 162df0a132b3baa19086a16b1c34ea871e3cd418 (patch) | |
tree | 01c1c58fbabb8c5baa74991405ae96819d6b8229 | |
parent | I hate code (diff) | |
download | 42-cub3d-162df0a132b3baa19086a16b1c34ea871e3cd418.tar.gz 42-cub3d-162df0a132b3baa19086a16b1c34ea871e3cd418.tar.bz2 42-cub3d-162df0a132b3baa19086a16b1c34ea871e3cd418.tar.xz 42-cub3d-162df0a132b3baa19086a16b1c34ea871e3cd418.tar.zst 42-cub3d-162df0a132b3baa19086a16b1c34ea871e3cd418.zip |
There is no way I pthread
Diffstat (limited to '')
-rw-r--r-- | Makefile | 5 | ||||
-rw-r--r-- | inc/cub3d_structs.h | 5 | ||||
-rw-r--r-- | src/ft_sfx_footstep.c | 40 | ||||
-rw-r--r-- | src/ft_sfx_trap.c | 3 |
4 files changed, 27 insertions, 26 deletions
@@ -127,7 +127,6 @@ CFLAGS += -Wall CFLAGS += -Wextra CFLAGS += -Werror CFLAGS += -pedantic -CFLAGS += -pthread #--------------------------------------------------------------------------------------------------# ifdef ASAN CFLAGS += ${DEBUG} @@ -164,10 +163,10 @@ else @$(MAKE) --no-print-directory -C ${LFT_DIR} all endif ifeq (${OS}, Darwin) - ${CC} ${CFLAGS} -o $@ ${OBJS} -L${LFT_DIR} -L${MLX_DIR} -lft -lmlx -lm -lpthread \ + ${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 -lpthread + ${CC} ${CFLAGS} -o $@ ${OBJS} -L${LFT_DIR} -lft -lX11 -lXext -lmlx -lm -lbsd endif #--------------------------------------------------------------------------------------------------# all: ${NAME} diff --git a/inc/cub3d_structs.h b/inc/cub3d_structs.h index 04ee59c..3d61900 100644 --- a/inc/cub3d_structs.h +++ b/inc/cub3d_structs.h @@ -69,6 +69,11 @@ typedef struct s_sfx pid_t new_lvl_pid; pid_t pain_pid; pid_t trap_pid; + pthread_t death_tid; + pthread_t footstep_tid; + pthread_t new_lvl_tid; + pthread_t pain_tid; + pthread_t trap_tid; } t_sfx; typedef struct s_bmp_rgb diff --git a/src/ft_sfx_footstep.c b/src/ft_sfx_footstep.c index bccb847..d9f083d 100644 --- a/src/ft_sfx_footstep.c +++ b/src/ft_sfx_footstep.c @@ -16,29 +16,27 @@ #include <sys/types.h> #include <sys/wait.h> -#include <sys/types.h> -#include <sys/time.h> -#include <sys/resource.h> -#include <libft.h> void ft_sfx_footstep(t_cub *cl) { - (void)cl; - /* static uint8_t ref = 0; */ + static uint8_t ref = 0; - /* cl->sfx.footstep_pid = fork(); */ - /* if (cl->sfx.footstep_pid == 0) */ - /* { */ - /* ref += 1; */ - /* if (ref > 201) */ - /* ref = 0; */ - /* if (ref % 2) */ - /* execve(*(cl->sfx.footstep_one + 0), */ - /* cl->sfx.footstep_one, cl->envp); */ - /* else */ - /* execve(*(cl->sfx.footstep_two + 0), */ - /* cl->sfx.footstep_two, cl->envp); */ - /* } */ - /* else */ - /* wait(&cl->sfx.footstep_pid); */ + if (waitpid(cl->sfx.footstep_pid, 0, WNOHANG) > 0) + { + cl->sfx.footstep_pid = fork(); + if (cl->sfx.footstep_pid == 0) + { + ref += 1; + if (ref > 201) + ref = 0; + if (ref % 2) + execve(*(cl->sfx.footstep_one + 0), + cl->sfx.footstep_one, cl->envp); + else + execve(*(cl->sfx.footstep_two + 0), + cl->sfx.footstep_two, cl->envp); + } + else + wait(&cl->sfx.footstep_pid); + } } diff --git a/src/ft_sfx_trap.c b/src/ft_sfx_trap.c index b52b9c1..1499ecf 100644 --- a/src/ft_sfx_trap.c +++ b/src/ft_sfx_trap.c @@ -15,7 +15,6 @@ #include <unistd.h> #include <stdint.h> -#include <pthread.h> static void ft_sfx_pain(t_cub *cl) { @@ -41,7 +40,7 @@ void ft_sfx_trap(t_cub *cl) { cl->sfx.trap_pid = fork(); - else if (cl->sfx.trap_pid == 0) + if (cl->sfx.trap_pid == 0) execve(*(cl->sfx.trap + 0), cl->sfx.trap, cl->envp); else { |