aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-03-19 20:59:02 +0100
committerJozanLeClerc <bousset.rudy@gmail.com>2020-03-19 20:59:02 +0100
commitf63e12e2f7aca68d867e362223804afdc987af73 (patch)
tree9a3c02963378f55982d590a78831017067c094c3
parentStarting sfx rework (diff)
download42-cub3d-f63e12e2f7aca68d867e362223804afdc987af73.tar.gz
42-cub3d-f63e12e2f7aca68d867e362223804afdc987af73.tar.bz2
42-cub3d-f63e12e2f7aca68d867e362223804afdc987af73.tar.xz
42-cub3d-f63e12e2f7aca68d867e362223804afdc987af73.tar.zst
42-cub3d-f63e12e2f7aca68d867e362223804afdc987af73.zip
Rework in progress
Diffstat (limited to '')
-rw-r--r--inc/cub3d.h12
-rw-r--r--inc/cub3d_structs.h5
-rw-r--r--src/ft_exit.c38
-rw-r--r--src/ft_init_lists.c2
-rw-r--r--src/ft_init_sfx.c83
-rw-r--r--src/ft_sfx_death.c2
-rw-r--r--src/ft_sfx_footstep.c2
-rw-r--r--src/ft_sfx_new_level.c2
-rw-r--r--src/ft_sfx_pain.c2
-rw-r--r--src/ft_sfx_trap.c2
10 files changed, 96 insertions, 54 deletions
diff --git a/inc/cub3d.h b/inc/cub3d.h
index c91f97f..d543dbb 100644
--- a/inc/cub3d.h
+++ b/inc/cub3d.h
@@ -34,7 +34,7 @@ int8_t ft_init_map(t_map *mlist);
t_bmp_file ft_init_bmp(void);
t_bmp_info ft_init_bmp_info(void);
t_rgb ft_hex_to_og_rgb(uint32_t color);
-int8_t ft_init_sfx(t_sfx *sfx);
+int8_t ft_init_sfx(t_cub *cl);
int8_t ft_init_sprites(t_sprite ***sprites);
/*
@@ -159,11 +159,11 @@ void ft_floor_cast_inits(uint16_t y, t_ray *rl, t_cub *cl);
** ====== SFX ======
*/
-void ft_sfx_death(t_cub *cl);
-void ft_sfx_footstep(t_cub *cl);
-void ft_sfx_new_level(t_cub *cl);
-void ft_sfx_pain(t_cub *cl);
-void ft_sfx_trap(t_cub *cl);
+void ft_sfx_death(t_sfx *sfx);
+void ft_sfx_footstep(t_sfx *sfx);
+void ft_sfx_new_level(t_sfx *sfx);
+void ft_sfx_pain(t_sfx *sfx);
+void ft_sfx_trap(t_sfx *sfx);
void *ft_sfx_death_thread(void *vargp);
void *ft_sfx_footstep_thread(void *vargp);
void *ft_sfx_new_lvl_thread(void *vargp);
diff --git a/inc/cub3d_structs.h b/inc/cub3d_structs.h
index a45af47..3ad9eec 100644
--- a/inc/cub3d_structs.h
+++ b/inc/cub3d_structs.h
@@ -58,10 +58,11 @@ typedef struct s_bmp_info
typedef struct s_sfx
{
- char *cmd_one;
- char *cmd_two;
+ char *cmd;
+ char *cmd_alt;
pthread_t tid;
pthread_mutex_t mutex;
+ void (*ft_sfx_play)(struct s_sfx*);
/* old */
/* ========= */
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);
}