aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_init_sfx.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ft_init_sfx.c')
-rw-r--r--src/ft_init_sfx.c83
1 files changed, 65 insertions, 18 deletions
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);
}