diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ft_exit.c | 38 | ||||
-rw-r--r-- | src/ft_init_lists.c | 2 | ||||
-rw-r--r-- | src/ft_init_sfx.c | 83 | ||||
-rw-r--r-- | src/ft_sfx_death.c | 2 | ||||
-rw-r--r-- | src/ft_sfx_footstep.c | 2 | ||||
-rw-r--r-- | src/ft_sfx_new_level.c | 2 | ||||
-rw-r--r-- | src/ft_sfx_pain.c | 2 | ||||
-rw-r--r-- | src/ft_sfx_trap.c | 2 |
8 files changed, 87 insertions, 46 deletions
diff --git a/src/ft_exit.c b/src/ft_exit.c index d140739..f753f84 100644 --- a/src/ft_exit.c +++ b/src/ft_exit.c @@ -50,6 +50,8 @@ static void static void ft_free_lists(t_cub *clist) { + uint8_t i; + ft_memdel((void*)&clist->mlist.filename); ft_memdel((void*)&clist->mlist.no_tex_path); ft_memdel((void*)&clist->mlist.so_tex_path); @@ -65,13 +67,11 @@ static void ft_memdel((void*)&clist->mlist.music_cmd); ft_memdel((void*)&clist->mlist.mapl); ft_free_words(clist->mlist.map); - ft_memdel((void*)&clist->sfx.death); - ft_memdel((void*)&clist->sfx.footstep_one); - ft_memdel((void*)&clist->sfx.footstep_two); - ft_memdel((void*)&clist->sfx.new_lvl); - ft_memdel((void*)&clist->sfx.pain_one); - ft_memdel((void*)&clist->sfx.pain_two); - ft_memdel((void*)&clist->sfx.trap); + i = -1; + while (++i < 10) + ft_memdel((void*)&clist->sfx[i].cmd); + ft_memdel((void*)&clist->sfx[1].cmd_alt); + ft_memdel((void*)&clist->sfx[3].cmd_alt); ft_free_sprites(clist->mlist.sprite_path); if (!clist->wlist.inited) ft_memdel((void*)&clist->wlist.winptr); @@ -108,26 +108,20 @@ static void static void ft_cancel_threads(t_cub *clist) { + uint8_t i; + if (clist->isoldmus && clist->wlist.inited) { pthread_cancel(clist->mtid); pthread_join(clist->mtid, NULL); } - pthread_mutex_unlock(&clist->sfx.death_mutex); - pthread_cancel(clist->sfx.death_tid); - pthread_join(clist->sfx.death_tid, NULL); - pthread_mutex_unlock(&clist->sfx.footstep_mutex); - pthread_cancel(clist->sfx.footstep_tid); - pthread_join(clist->sfx.footstep_tid, NULL); - pthread_mutex_unlock(&clist->sfx.new_lvl_mutex); - pthread_cancel(clist->sfx.new_lvl_tid); - pthread_join(clist->sfx.new_lvl_tid, NULL); - pthread_mutex_unlock(&clist->sfx.pain_mutex); - pthread_cancel(clist->sfx.pain_tid); - pthread_join(clist->sfx.pain_tid, NULL); - pthread_mutex_unlock(&clist->sfx.trap_mutex); - pthread_cancel(clist->sfx.trap_tid); - pthread_join(clist->sfx.trap_tid, NULL); + i = -1; + while (++i < 10) + { + pthread_mutex_unlock(&clist->sfx[i].mutex); + pthread_cancel(clist->sfx[i].tid); + pthread_join(clist->sfx[i].tid, NULL); + } } int diff --git a/src/ft_init_lists.c b/src/ft_init_lists.c index b876e8d..dbf4e8f 100644 --- a/src/ft_init_lists.c +++ b/src/ft_init_lists.c @@ -90,7 +90,7 @@ static int8_t cl->f_rgb = ft_init_rgb(); cl->c_rgb = ft_init_rgb(); cl->rlist = ft_init_s_ray(); - if (ft_init_sfx(&cl->sfx) < 0) + if (ft_init_sfx(cl) < 0) return (-1); cl->currlvl = 0; cl->walltexgood = 0; diff --git a/src/ft_init_sfx.c b/src/ft_init_sfx.c index 35ab57d..5efc5a4 100644 --- a/src/ft_init_sfx.c +++ b/src/ft_init_sfx.c @@ -19,6 +19,22 @@ #include <unistd.h> #include <pthread.h> + +/* +** sfx[] index summary +** ------------------- +** 0: death +** 1: footstep +** 2: new level +** 3: pain +** 4: trap +** 5: heal +** 6: weapon one load +** 7: weapon one fire +** 8: weapon two load +** 9: weapon two fire +*/ + static int8_t ft_init_sfx_cmd(char **target, const char *path) { @@ -32,26 +48,57 @@ static int8_t return (0); } +static void + ft_init_sfx_pthreads(t_cub *cl) +{ + pthread_create(cl->sfx[0].tid, NULL, ft_sfx_death_thread, sfx); + pthread_create(cl->sfx[1].tid, NULL, ft_sfx_footstep_thread, sfx); + pthread_create(cl->sfx[2].tid, NULL, ft_sfx_new_lvl_thread, sfx); + pthread_create(cl->sfx[3].tid, NULL, ft_sfx_pain_thread, sfx); + pthread_create(cl->sfx[4].tid, NULL, ft_sfx_trap_thread, sfx); + pthread_create(cl->sfx[5].tid, NULL, ft_sfx_heal_thread, sfx); + pthread_create(cl->sfx[6].tid, NULL, ft_sfx_weap_one_load_thread, sfx); + pthread_create(cl->sfx[7].tid, NULL, ft_sfx_weap_one_fire_thread, sfx); + pthread_create(cl->sfx[8].tid, NULL, ft_sfx_weap_two_load_thread, sfx); + pthread_create(cl->sfx[9].tid, NULL, ft_sfx_weap_two_fire_thread, sfx); +} + +static void + ft_init_sfx_funptr(cl) +{ + cl->sfx[0].ft_sfx_play = ft_sfx_death; + cl->sfx[1].ft_sfx_play = ft_sfx_footstep; + cl->sfx[2].ft_sfx_play = ft_sfx_new_level; + cl->sfx[3].ft_sfx_play = ft_sfx_pain; + cl->sfx[4].ft_sfx_play = ft_sfx_trap; + cl->sfx[5].ft_sfx_play = ft_sfx_heal; + cl->sfx[6].ft_sfx_play = ft_sfx_weap_one_load; + cl->sfx[7].ft_sfx_play = ft_sfx_weap_one_fire; + cl->sfx[8].ft_sfx_play = ft_sfx_weap_two_load; + cl->sfx[9].ft_sfx_play = ft_sfx_weap_two_fire; +} + int8_t - ft_init_sfx(t_sfx *sfx) + ft_init_sfx(t_cub *cl) { - if (ft_init_sfx_cmd(&sfx->death, FT_SFX_DEATH_PATH) < 0 || - ft_init_sfx_cmd(&sfx->footstep_one, FT_SFX_FS_ONE_PATH) < 0 || - ft_init_sfx_cmd(&sfx->footstep_two, FT_SFX_FS_TWO_PATH) < 0 || - ft_init_sfx_cmd(&sfx->new_lvl, FT_SFX_N_LVL_PATH) < 0 || - ft_init_sfx_cmd(&sfx->pain_one, FT_SFX_SCR_ONE_PATH) < 0 || - ft_init_sfx_cmd(&sfx->pain_two, FT_SFX_SCR_TWO_PATH) < 0 || - ft_init_sfx_cmd(&sfx->trap, FT_SFX_TRAP_PATH) < 0) + uint8_t i; + if (ft_init_sfx_cmd(&cl->sfx[0].cmd, FT_SFX_DEATH_PATH) < 0 || + ft_init_sfx_cmd(&cl->sfx[1].cmd, FT_SFX_FS_ONE_PATH) < 0 || + ft_init_sfx_cmd(&cl->sfx[1].cmd_alt, FT_SFX_FS_TWO_PATH) < 0 || + ft_init_sfx_cmd(&cl->sfx[2].cmd, FT_SFX_N_LVL_PATH) < 0 || + ft_init_sfx_cmd(&cl->sfx[3].cmd, FT_SFX_SCR_ONE_PATH) < 0 || + ft_init_sfx_cmd(&cl->sfx[3].cmd_alt, FT_SFX_SCR_TWO_PATH) < 0 || + ft_init_sfx_cmd(&cl->sfx[4].cmd, FT_SFX_TRAP_PATH) < 0 || + ft_init_sfx_cmd(&cl->sfx[5].cmd, FT_SFX_HEAL_PATH) < 0 || + ft_init_sfx_cmd(&cl->sfx[6].cmd, FT_SFX_W_ONE_LOAD_PATH) < 0 || + ft_init_sfx_cmd(&cl->sfx[7].cmd, FT_SFX_W_ONE_FIRE_PATH) < 0 || + 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) return (-1); - pthread_mutex_init(&sfx->death_mutex, NULL); - pthread_mutex_init(&sfx->footstep_mutex, NULL); - pthread_mutex_init(&sfx->new_lvl_mutex, NULL); - pthread_mutex_init(&sfx->pain_mutex, NULL); - pthread_mutex_init(&sfx->trap_mutex, NULL); - pthread_create(&sfx->death_tid, NULL, ft_sfx_death_thread, sfx); - pthread_create(&sfx->footstep_tid, NULL, ft_sfx_footstep_thread, sfx); - pthread_create(&sfx->new_lvl_tid, NULL, ft_sfx_new_lvl_thread, sfx); - pthread_create(&sfx->pain_tid, NULL, ft_sfx_pain_thread, sfx); - pthread_create(&sfx->trap_tid, NULL, ft_sfx_trap_thread, sfx); + i = -1; + while (++i < 10) + pthread_mutex_init(cl->sfx[i].mutex, NULL); + ft_init_sfx_pthreads(cl); + ft_init_sfx_funptr(cl); return (0); } diff --git a/src/ft_sfx_death.c b/src/ft_sfx_death.c index 32ad6fe..edc38ef 100644 --- a/src/ft_sfx_death.c +++ b/src/ft_sfx_death.c @@ -35,7 +35,7 @@ void } void - ft_sfx_death(t_cub *cl) + ft_sfx_death(t_sfx *sfx) { pthread_mutex_unlock(&cl->sfx.death_mutex); } diff --git a/src/ft_sfx_footstep.c b/src/ft_sfx_footstep.c index c0c9ffe..a6b2105 100644 --- a/src/ft_sfx_footstep.c +++ b/src/ft_sfx_footstep.c @@ -42,7 +42,7 @@ void } void - ft_sfx_footstep(t_cub *cl) + ft_sfx_footstep(t_sfx *sfx) { pthread_mutex_unlock(&cl->sfx.footstep_mutex); } diff --git a/src/ft_sfx_new_level.c b/src/ft_sfx_new_level.c index 2cde15c..7e5d4ea 100644 --- a/src/ft_sfx_new_level.c +++ b/src/ft_sfx_new_level.c @@ -35,7 +35,7 @@ void } void - ft_sfx_new_level(t_cub *cl) + ft_sfx_new_level(t_sfx *sfx) { pthread_mutex_unlock(&cl->sfx.new_lvl_mutex); } diff --git a/src/ft_sfx_pain.c b/src/ft_sfx_pain.c index 68340c5..fe9ecaa 100644 --- a/src/ft_sfx_pain.c +++ b/src/ft_sfx_pain.c @@ -42,7 +42,7 @@ void } void - ft_sfx_pain(t_cub *cl) + ft_sfx_pain(t_sfx *sfx) { static uint8_t ref = 0; diff --git a/src/ft_sfx_trap.c b/src/ft_sfx_trap.c index a395450..2c35ef9 100644 --- a/src/ft_sfx_trap.c +++ b/src/ft_sfx_trap.c @@ -35,7 +35,7 @@ void } void - ft_sfx_trap(t_cub *cl) + ft_sfx_trap(t_sfx *sfx) { pthread_mutex_unlock(&cl->sfx.trap_mutex); } |