aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-04-06 15:31:58 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-04-06 15:31:58 +0200
commit7359ab92230a7b4f05855de50f36aa4880901f3b (patch)
treec5de0e375f3f49d308950b24e199591dd8a2c1a8 /src
parentTweak (diff)
download42-cub3d-7359ab92230a7b4f05855de50f36aa4880901f3b.tar.gz
42-cub3d-7359ab92230a7b4f05855de50f36aa4880901f3b.tar.bz2
42-cub3d-7359ab92230a7b4f05855de50f36aa4880901f3b.tar.xz
42-cub3d-7359ab92230a7b4f05855de50f36aa4880901f3b.tar.zst
42-cub3d-7359ab92230a7b4f05855de50f36aa4880901f3b.zip
Better sound handling, few changes
Diffstat (limited to 'src')
-rw-r--r--src/ft_exit.c2
-rw-r--r--src/ft_extra_keys.c15
-rw-r--r--src/ft_find_item.c5
-rw-r--r--src/ft_init_sfx.c32
-rw-r--r--src/ft_sfx_bb_death.c1
-rw-r--r--src/ft_sfx_bb_fire.c1
-rw-r--r--src/ft_sfx_bb_scream.c1
-rw-r--r--src/ft_sfx_death.c1
-rw-r--r--src/ft_sfx_footstep.c1
-rw-r--r--src/ft_sfx_heal.c1
-rw-r--r--src/ft_sfx_new_level.c1
-rw-r--r--src/ft_sfx_ooa.c1
-rw-r--r--src/ft_sfx_pain.c1
-rw-r--r--src/ft_sfx_trap.c1
-rw-r--r--src/ft_sfx_weapon_one.c6
-rw-r--r--src/ft_sfx_weapon_three.c2
-rw-r--r--src/ft_sfx_weapon_two.c6
-rw-r--r--src/ft_sfx_weapon_two_alt.c65
18 files changed, 110 insertions, 33 deletions
diff --git a/src/ft_exit.c b/src/ft_exit.c
index 85c812f..6d93f8e 100644
--- a/src/ft_exit.c
+++ b/src/ft_exit.c
@@ -49,7 +49,7 @@ static void
pthread_join(clist->mtid, NULL);
}
i = -1;
- while (++i < 16)
+ while (++i < FT_TOTAL_SFX)
{
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 c1ea721..e4d0853 100644
--- a/src/ft_extra_keys.c
+++ b/src/ft_extra_keys.c
@@ -73,6 +73,7 @@ int
ft_space_key(t_cub *clist)
{
uint8_t w_id;
+ static uint8_t ref = 0;
w_id = clist->plist.handles_weapon;
w_id = (w_id == 2) ? (1) : (w_id);
@@ -81,7 +82,19 @@ int
(clist->plist.ammo[w_id] > 0 || clist->plist.ammo[w_id] == -4))
{
clist->plist.ammo[w_id] -= w_id;
- clist->sfx[clist->plist.handles_weapon + 7].sfx_play(clist->sfx);
+ if (clist->plist.handles_weapon != 2)
+ clist->sfx[clist->plist.handles_weapon + 7].sfx_play(clist->sfx);
+ else
+ {
+ if (ref % 3 == 0)
+ clist->sfx[9].sfx_play(clist->sfx);
+ else if (ref % 3 == 2)
+ clist->sfx[16].sfx_play(clist->sfx);
+ else if (ref % 3 == 1)
+ clist->sfx[17].sfx_play(clist->sfx);
+ ref += 2;
+ ref = (ref > 200) ? (0) : (ref);
+ }
clist->plist.fire = 1;
ft_shoot(clist);
return (0);
diff --git a/src/ft_find_item.c b/src/ft_find_item.c
index f9504d1..1de7613 100644
--- a/src/ft_find_item.c
+++ b/src/ft_find_item.c
@@ -55,6 +55,11 @@ static void
pl->ammo[1] += FT_WEAP_TWO_STRT_AMMO;
else if (weap_id == 2)
pl->ammo[2] += FT_WEAP_THREE_STRT_AMMO;
+ else if (weap_id == 3)
+ {
+ pl->ammo[2] += FT_AMMO_PACK;
+ weap_id = 2;
+ }
if (pl->ammo[weap_id] > FT_WEAP_MAX_AMMO)
pl->ammo[weap_id] = FT_WEAP_MAX_AMMO;
}
diff --git a/src/ft_init_sfx.c b/src/ft_init_sfx.c
index 1725c91..2e0b268 100644
--- a/src/ft_init_sfx.c
+++ b/src/ft_init_sfx.c
@@ -38,6 +38,8 @@
** 13: enemy death
** 14: enemy scream | double
** 15: enemy fire
+** 16: weapon two fire overdub
+** 17: weapon two fire overdub x2
*/
static int8_t
@@ -62,14 +64,10 @@ static void
pthread_create(&cl->sfx[3].tid, NULL, ft_sfx_pain_thread, &cl->sfx);
pthread_create(&cl->sfx[4].tid, NULL, ft_sfx_trap_thread, &cl->sfx);
pthread_create(&cl->sfx[5].tid, NULL, ft_sfx_heal_thread, &cl->sfx);
- pthread_create(&cl->sfx[6].tid, NULL,
- ft_sfx_weapon_one_load_thread, &cl->sfx);
- pthread_create(&cl->sfx[7].tid, NULL,
- ft_sfx_weapon_one_fire_thread, &cl->sfx);
- pthread_create(&cl->sfx[8].tid, NULL,
- ft_sfx_weapon_two_load_thread, &cl->sfx);
- pthread_create(&cl->sfx[9].tid, NULL,
- ft_sfx_weapon_two_fire_thread, &cl->sfx);
+ pthread_create(&cl->sfx[6].tid, NULL, ft_sfx_w_one_load_thread, &cl->sfx);
+ pthread_create(&cl->sfx[7].tid, NULL, ft_sfx_w_one_fire_thread, &cl->sfx);
+ pthread_create(&cl->sfx[8].tid, NULL, ft_sfx_w_two_load_thread, &cl->sfx);
+ pthread_create(&cl->sfx[9].tid, NULL, ft_sfx_w_two_fire_thread, &cl->sfx);
pthread_create(&cl->sfx[10].tid, NULL,
ft_sfx_weapon_three_load_thread, &cl->sfx);
pthread_create(&cl->sfx[11].tid, NULL,
@@ -78,6 +76,10 @@ static void
pthread_create(&cl->sfx[13].tid, NULL, ft_sfx_bb_death_thread, &cl->sfx);
pthread_create(&cl->sfx[14].tid, NULL, ft_sfx_bb_scream_thread, &cl->sfx);
pthread_create(&cl->sfx[15].tid, NULL, ft_sfx_bb_fire_thread, &cl->sfx);
+ pthread_create(&cl->sfx[16].tid, NULL,
+ ft_sfx_weapon_two_fire_thread_alt, &cl->sfx);
+ pthread_create(&cl->sfx[17].tid, NULL,
+ ft_sfx_weapon_two_fire_thread_alt_alt, &cl->sfx);
}
static void
@@ -99,6 +101,8 @@ static void
cl->sfx[13].sfx_play = ft_sfx_bb_death;
cl->sfx[14].sfx_play = ft_sfx_bb_scream;
cl->sfx[15].sfx_play = ft_sfx_bb_fire;
+ cl->sfx[16].sfx_play = ft_sfx_weapon_two_fire_alt;
+ cl->sfx[17].sfx_play = ft_sfx_weapon_two_fire_alt_alt;
}
static int8_t
@@ -122,7 +126,9 @@ static int8_t
ft_init_sfx_cmd(&cl->sfx[13].cmd, FT_SFX_ENMY_DEATH_PATH) < 0 ||
ft_init_sfx_cmd(&cl->sfx[14].cmd, FT_SFX_ENMY_SCR_ONE_PATH) < 0 ||
ft_init_sfx_cmd(&cl->sfx[14].cmd_alt, FT_SFX_ENMY_SCR_TWO_PATH) < 0 ||
- ft_init_sfx_cmd(&cl->sfx[15].cmd, FT_SFX_ENMY_FIRE_PATH) < 0)
+ ft_init_sfx_cmd(&cl->sfx[15].cmd, FT_SFX_ENMY_FIRE_PATH) < 0 ||
+ ft_init_sfx_cmd(&cl->sfx[16].cmd, FT_SFX_W_TWO_FIRE_PATH) < 0 ||
+ ft_init_sfx_cmd(&cl->sfx[17].cmd, FT_SFX_W_TWO_FIRE_PATH) < 0)
return (-1);
return (0);
}
@@ -134,9 +140,13 @@ int8_t
if (ft_init_sfx_cmds(cl) < 0)
return (-1);
- i = -1;
- while (++i < 16)
+ i = 0;
+ while (i < FT_TOTAL_SFX)
+ {
pthread_mutex_init(&cl->sfx[i].mutex, NULL);
+ pthread_mutex_lock(&cl->sfx[i].mutex);
+ i++;
+ }
ft_init_sfx_pthreads(cl);
ft_init_sfx_funptr(cl);
return (0);
diff --git a/src/ft_sfx_bb_death.c b/src/ft_sfx_bb_death.c
index ce86c82..23a96d8 100644
--- a/src/ft_sfx_bb_death.c
+++ b/src/ft_sfx_bb_death.c
@@ -25,7 +25,6 @@ void
else
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
sfx = (t_sfx *)vargp;
- pthread_mutex_lock(&sfx[13].mutex);
while (1)
{
pthread_mutex_lock(&sfx[13].mutex);
diff --git a/src/ft_sfx_bb_fire.c b/src/ft_sfx_bb_fire.c
index 8ebeb6d..df89544 100644
--- a/src/ft_sfx_bb_fire.c
+++ b/src/ft_sfx_bb_fire.c
@@ -25,7 +25,6 @@ void
else
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
sfx = (t_sfx *)vargp;
- pthread_mutex_lock(&sfx[15].mutex);
while (1)
{
pthread_mutex_lock(&sfx[15].mutex);
diff --git a/src/ft_sfx_bb_scream.c b/src/ft_sfx_bb_scream.c
index da93bdc..7c68c53 100644
--- a/src/ft_sfx_bb_scream.c
+++ b/src/ft_sfx_bb_scream.c
@@ -25,7 +25,6 @@ void
else
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
sfx = (t_sfx *)vargp;
- pthread_mutex_lock(&sfx[14].mutex);
while (1)
{
pthread_mutex_lock(&sfx[14].mutex);
diff --git a/src/ft_sfx_death.c b/src/ft_sfx_death.c
index 23dd26f..76a98cd 100644
--- a/src/ft_sfx_death.c
+++ b/src/ft_sfx_death.c
@@ -24,7 +24,6 @@ void
else
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
sfx = (t_sfx *)vargp;
- pthread_mutex_lock(&sfx[0].mutex);
while (1)
{
pthread_mutex_lock(&sfx[0].mutex);
diff --git a/src/ft_sfx_footstep.c b/src/ft_sfx_footstep.c
index a940852..628660b 100644
--- a/src/ft_sfx_footstep.c
+++ b/src/ft_sfx_footstep.c
@@ -25,7 +25,6 @@ void
else
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
sfx = (t_sfx *)vargp;
- pthread_mutex_lock(&sfx[1].mutex);
while (1)
{
ref = (ref > 201) ? (0) : (ref + 1);
diff --git a/src/ft_sfx_heal.c b/src/ft_sfx_heal.c
index 81704ee..b95fc2c 100644
--- a/src/ft_sfx_heal.c
+++ b/src/ft_sfx_heal.c
@@ -24,7 +24,6 @@ void
else
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
sfx = (t_sfx *)vargp;
- pthread_mutex_lock(&sfx[5].mutex);
while (1)
{
pthread_mutex_lock(&sfx[5].mutex);
diff --git a/src/ft_sfx_new_level.c b/src/ft_sfx_new_level.c
index 6dfe564..e4f3bff 100644
--- a/src/ft_sfx_new_level.c
+++ b/src/ft_sfx_new_level.c
@@ -24,7 +24,6 @@ void
else
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
sfx = (t_sfx *)vargp;
- pthread_mutex_lock(&sfx[2].mutex);
while (1)
{
pthread_mutex_lock(&sfx[2].mutex);
diff --git a/src/ft_sfx_ooa.c b/src/ft_sfx_ooa.c
index 880aea5..5950d2e 100644
--- a/src/ft_sfx_ooa.c
+++ b/src/ft_sfx_ooa.c
@@ -24,7 +24,6 @@ void
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);
diff --git a/src/ft_sfx_pain.c b/src/ft_sfx_pain.c
index 2670b99..d55c01c 100644
--- a/src/ft_sfx_pain.c
+++ b/src/ft_sfx_pain.c
@@ -25,7 +25,6 @@ void
else
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
sfx = (t_sfx *)vargp;
- pthread_mutex_lock(&sfx[3].mutex);
while (1)
{
pthread_mutex_lock(&sfx[3].mutex);
diff --git a/src/ft_sfx_trap.c b/src/ft_sfx_trap.c
index 98f210b..5ae39f0 100644
--- a/src/ft_sfx_trap.c
+++ b/src/ft_sfx_trap.c
@@ -24,7 +24,6 @@ void
else
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
sfx = (t_sfx *)vargp;
- pthread_mutex_lock(&sfx[4].mutex);
while (1)
{
pthread_mutex_lock(&sfx[4].mutex);
diff --git a/src/ft_sfx_weapon_one.c b/src/ft_sfx_weapon_one.c
index fca86f5..2cc8dcc 100644
--- a/src/ft_sfx_weapon_one.c
+++ b/src/ft_sfx_weapon_one.c
@@ -15,7 +15,7 @@
#include <pthread.h>
void
- *ft_sfx_weapon_one_load_thread(void *vargp)
+ *ft_sfx_w_one_load_thread(void *vargp)
{
t_sfx *sfx;
@@ -24,7 +24,6 @@ void
else
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
sfx = (t_sfx *)vargp;
- pthread_mutex_lock(&sfx[6].mutex);
while (1)
{
pthread_mutex_lock(&sfx[6].mutex);
@@ -41,7 +40,7 @@ void
}
void
- *ft_sfx_weapon_one_fire_thread(void *vargp)
+ *ft_sfx_w_one_fire_thread(void *vargp)
{
t_sfx *sfx;
@@ -50,7 +49,6 @@ void
else
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
sfx = (t_sfx *)vargp;
- pthread_mutex_lock(&sfx[7].mutex);
while (1)
{
pthread_mutex_lock(&sfx[7].mutex);
diff --git a/src/ft_sfx_weapon_three.c b/src/ft_sfx_weapon_three.c
index a737230..65c6903 100644
--- a/src/ft_sfx_weapon_three.c
+++ b/src/ft_sfx_weapon_three.c
@@ -24,7 +24,6 @@ void
else
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
sfx = (t_sfx *)vargp;
- pthread_mutex_lock(&sfx[10].mutex);
while (1)
{
pthread_mutex_lock(&sfx[10].mutex);
@@ -50,7 +49,6 @@ void
else
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
sfx = (t_sfx *)vargp;
- pthread_mutex_lock(&sfx[11].mutex);
while (1)
{
pthread_mutex_lock(&sfx[11].mutex);
diff --git a/src/ft_sfx_weapon_two.c b/src/ft_sfx_weapon_two.c
index 1afc933..6d8e4a7 100644
--- a/src/ft_sfx_weapon_two.c
+++ b/src/ft_sfx_weapon_two.c
@@ -15,7 +15,7 @@
#include <pthread.h>
void
- *ft_sfx_weapon_two_load_thread(void *vargp)
+ *ft_sfx_w_two_load_thread(void *vargp)
{
t_sfx *sfx;
@@ -24,7 +24,6 @@ void
else
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
sfx = (t_sfx *)vargp;
- pthread_mutex_lock(&sfx[8].mutex);
while (1)
{
pthread_mutex_lock(&sfx[8].mutex);
@@ -41,7 +40,7 @@ void
}
void
- *ft_sfx_weapon_two_fire_thread(void *vargp)
+ *ft_sfx_w_two_fire_thread(void *vargp)
{
t_sfx *sfx;
@@ -50,7 +49,6 @@ void
else
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
sfx = (t_sfx *)vargp;
- pthread_mutex_lock(&sfx[9].mutex);
while (1)
{
pthread_mutex_lock(&sfx[9].mutex);
diff --git a/src/ft_sfx_weapon_two_alt.c b/src/ft_sfx_weapon_two_alt.c
new file mode 100644
index 0000000..7702fce
--- /dev/null
+++ b/src/ft_sfx_weapon_two_alt.c
@@ -0,0 +1,65 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_sfx_weapon_two_alt.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_weapon_two_fire_thread_alt(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;
+ while (1)
+ {
+ pthread_mutex_lock(&sfx[16].mutex);
+ if (system(sfx[16].cmd))
+ pthread_exit(NULL);
+ }
+ return (NULL);
+}
+
+void
+ ft_sfx_weapon_two_fire_alt(t_sfx *sfx)
+{
+ pthread_mutex_unlock(&sfx[16].mutex);
+}
+
+void
+ *ft_sfx_weapon_two_fire_thread_alt_alt(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;
+ while (1)
+ {
+ pthread_mutex_lock(&sfx[17].mutex);
+ if (system(sfx[17].cmd))
+ pthread_exit(NULL);
+ }
+ return (NULL);
+}
+
+void
+ ft_sfx_weapon_two_fire_alt_alt(t_sfx *sfx)
+{
+ pthread_mutex_unlock(&sfx[17].mutex);
+}