diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ft_check_missing_sfx.c | 3 | ||||
-rw-r--r-- | src/ft_del_sfx_cmd.c | 2 | ||||
-rw-r--r-- | src/ft_draw_ammo_bar.c | 4 | ||||
-rw-r--r-- | src/ft_exit.c | 2 | ||||
-rw-r--r-- | src/ft_extra_keys.c | 3 | ||||
-rw-r--r-- | src/ft_init_sfx.c | 29 | ||||
-rw-r--r-- | src/ft_sfx_ooa.c | 41 |
7 files changed, 68 insertions, 16 deletions
diff --git a/src/ft_check_missing_sfx.c b/src/ft_check_missing_sfx.c index 1273457..34d08e2 100644 --- a/src/ft_check_missing_sfx.c +++ b/src/ft_check_missing_sfx.c @@ -34,6 +34,9 @@ static int if (ft_check_not_found(FT_SFX_W_THREE_FIRE_PATH) < 0 || ft_check_ext(FT_SFX_W_THREE_FIRE_PATH, ".wav") < 0) return (ft_missing_error(FT_ERR_MISS_SFX_W_THREE_FIRE, clist)); + if (ft_check_not_found(FT_SFX_OOA_PATH) < 0 || + ft_check_ext(FT_SFX_OOA_PATH, ".wav") < 0) + return (ft_missing_error(FT_ERR_MISS_SFX_OOA, clist)); return (0); } diff --git a/src/ft_del_sfx_cmd.c b/src/ft_del_sfx_cmd.c index 701bfa9..4fd38ee 100644 --- a/src/ft_del_sfx_cmd.c +++ b/src/ft_del_sfx_cmd.c @@ -20,7 +20,7 @@ void uint8_t i; i = 0; - while (i < 12) + while (i < 13) { ft_memdel((void*)&clist->sfx[i].cmd); i++; diff --git a/src/ft_draw_ammo_bar.c b/src/ft_draw_ammo_bar.c index 8a73f68..667eee9 100644 --- a/src/ft_draw_ammo_bar.c +++ b/src/ft_draw_ammo_bar.c @@ -121,8 +121,8 @@ void uint8_t w_id; w_id = cl->plist.handles_weapon; - w_id = (cl->plist.handles_weapon == 2) ? (1) : (w_id); - w_id = (cl->plist.handles_weapon == 4) ? (2) : (w_id); + w_id = (w_id == 2) ? (1) : (w_id); + w_id = (w_id == 4) ? (2) : (w_id); ft_get_hw(cl); if (cl->plist.ammo[w_id] >= 0) { diff --git a/src/ft_exit.c b/src/ft_exit.c index 4f955f4..ed1191c 100644 --- a/src/ft_exit.c +++ b/src/ft_exit.c @@ -40,7 +40,7 @@ static void pthread_join(clist->mtid, NULL); } i = -1; - while (++i < 12) + while (++i < 13) { pthread_mutex_unlock(&clist->sfx[i].mutex); pthread_cancel(clist->sfx[i].tid); diff --git a/src/ft_extra_keys.c b/src/ft_extra_keys.c index 097e2e2..0ccf3fc 100644 --- a/src/ft_extra_keys.c +++ b/src/ft_extra_keys.c @@ -82,6 +82,9 @@ int clist->plist.ammo[w_id] -= w_id; clist->sfx[clist->plist.handles_weapon + 7].sfx_play(clist->sfx); clist->plist.fire = 1; + return (0); } + else if (clist->plist.fire == 0 && clist->plist.ammo[w_id] <= 0) + clist->sfx[12].sfx_play(clist->sfx); return (0); } diff --git a/src/ft_init_sfx.c b/src/ft_init_sfx.c index 202e647..9b58656 100644 --- a/src/ft_init_sfx.c +++ b/src/ft_init_sfx.c @@ -22,18 +22,19 @@ /* ** sfx[] index summary ** ------------------- -** 0: death -** 1: footstep | double -** 2: new level -** 3: pain | double -** 4: trap -** 5: heal -** 6: weapon one load -** 7: weapon one fire -** 8: weapon two load -** 9: weapon two fire +** 0: death +** 1: footstep | double +** 2: new level +** 3: pain | double +** 4: trap +** 5: heal +** 6: weapon one load +** 7: weapon one fire +** 8: weapon two load +** 9: weapon two fire ** 10: weapon three load ** 11: weapon three fire +** 12: out of ammunitions */ static int8_t @@ -70,6 +71,8 @@ static void ft_sfx_weapon_three_load_thread, &cl->sfx); pthread_create(&cl->sfx[11].tid, NULL, ft_sfx_weapon_three_fire_thread, &cl->sfx); + pthread_create(&cl->sfx[12].tid, NULL, + ft_sfx_ooa_thread, &cl->sfx); } static void @@ -87,6 +90,7 @@ static void cl->sfx[9].sfx_play = ft_sfx_weapon_two_fire; cl->sfx[10].sfx_play = ft_sfx_weapon_three_load; cl->sfx[11].sfx_play = ft_sfx_weapon_three_fire; + cl->sfx[12].sfx_play = ft_sfx_ooa; } int8_t @@ -106,10 +110,11 @@ int8_t ft_init_sfx_cmd(&cl->sfx[8].cmd, FT_SFX_W_TWO_LOAD_PATH) < 0 || ft_init_sfx_cmd(&cl->sfx[9].cmd, FT_SFX_W_TWO_FIRE_PATH) < 0 || ft_init_sfx_cmd(&cl->sfx[10].cmd, FT_SFX_W_THREE_LOAD_PATH) < 0 || - ft_init_sfx_cmd(&cl->sfx[11].cmd, FT_SFX_W_THREE_FIRE_PATH) < 0) + ft_init_sfx_cmd(&cl->sfx[11].cmd, FT_SFX_W_THREE_FIRE_PATH) < 0 || + ft_init_sfx_cmd(&cl->sfx[12].cmd, FT_SFX_OOA_PATH) < 0) return (-1); i = -1; - while (++i < 12) + while (++i < 13) pthread_mutex_init(&cl->sfx[i].mutex, NULL); ft_init_sfx_pthreads(cl); ft_init_sfx_funptr(cl); diff --git a/src/ft_sfx_ooa.c b/src/ft_sfx_ooa.c new file mode 100644 index 0000000..880aea5 --- /dev/null +++ b/src/ft_sfx_ooa.c @@ -0,0 +1,41 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_sfx_ooa.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/24 17:17:54 by rbousset #+# #+# */ +/* Updated: 2020/02/24 17:17:56 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include <cub3d.h> +#include <stdlib.h> +#include <pthread.h> + +void + *ft_sfx_ooa_thread(void *vargp) +{ + t_sfx *sfx; + + if (FT_OS == 1) + pthread_setcancelstate(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); + else + pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); + sfx = (t_sfx *)vargp; + pthread_mutex_lock(&sfx[12].mutex); + while (1) + { + pthread_mutex_lock(&sfx[12].mutex); + if (system(sfx[12].cmd)) + pthread_exit(NULL); + } + return (NULL); +} + +void + ft_sfx_ooa(t_sfx *sfx) +{ + pthread_mutex_unlock(&sfx[12].mutex); +} |