aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ft_extra_keys.c4
-rw-r--r--src/ft_find_item.c4
-rw-r--r--src/ft_init_sfx.c49
-rw-r--r--src/ft_key_loop.c4
-rw-r--r--src/ft_sfx_death.c8
-rw-r--r--src/ft_sfx_footstep.c10
-rw-r--r--src/ft_sfx_heal.c41
-rw-r--r--src/ft_sfx_new_level.c8
-rw-r--r--src/ft_sfx_pain.c10
-rw-r--r--src/ft_sfx_trap.c8
-rw-r--r--src/ft_sfx_weapon_one.c67
-rw-r--r--src/ft_sfx_weapon_two.c67
-rw-r--r--src/ft_suffer_animation.c12
13 files changed, 234 insertions, 58 deletions
diff --git a/src/ft_extra_keys.c b/src/ft_extra_keys.c
index e99b32f..a78f821 100644
--- a/src/ft_extra_keys.c
+++ b/src/ft_extra_keys.c
@@ -71,8 +71,10 @@ int
int
ft_space_key(t_cub *clist)
{
- /* TODO: ft_sfx_weapon_fire(3) */
if (clist->plist.fire == 0)
+ {
+ clist->sfx[clist->plist.handles_weapon + 7].sfx_play(clist->sfx);
clist->plist.fire = 1;
+ }
return (0);
}
diff --git a/src/ft_find_item.c b/src/ft_find_item.c
index 7332e19..b55e9d9 100644
--- a/src/ft_find_item.c
+++ b/src/ft_find_item.c
@@ -42,7 +42,7 @@ static void
cl->weaps[weap_id][0].s_pos_y = 0;
pl->has_weapon[weap_id] = 1;
pl->handles_weapon = (weap_id == 1) ? (2) : (weap_id);
- /* TODO: ft_sfx_weapon(3) */
+ cl->sfx[((weap_id == 1) ? (2) : (weap_id)) + 6].sfx_play(cl->sfx);
}
}
@@ -63,7 +63,7 @@ void
(uint64_t)pl->pos_x, cl);
cl->heals[id].s_pos_x = 0;
cl->heals[id].s_pos_y = 0;
- /* TODO: ft_sfx_heal(3) */
+ cl->sfx[5].sfx_play(cl->sfx);
}
ft_weapon_check(map_char, pl, cl);
}
diff --git a/src/ft_init_sfx.c b/src/ft_init_sfx.c
index 5efc5a4..6fc8504 100644
--- a/src/ft_init_sfx.c
+++ b/src/ft_init_sfx.c
@@ -19,14 +19,13 @@
#include <unistd.h>
#include <pthread.h>
-
/*
** sfx[] index summary
** -------------------
** 0: death
-** 1: footstep
+** 1: footstep | double
** 2: new level
-** 3: pain
+** 3: pain | double
** 4: trap
** 5: heal
** 6: weapon one load
@@ -51,31 +50,31 @@ static int8_t
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);
+ pthread_create(&cl->sfx[0].tid, NULL, ft_sfx_death_thread, &cl->sfx);
+ pthread_create(&cl->sfx[1].tid, NULL, ft_sfx_footstep_thread, &cl->sfx);
+ pthread_create(&cl->sfx[2].tid, NULL, ft_sfx_new_lvl_thread, &cl->sfx);
+ 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);
}
static void
- ft_init_sfx_funptr(cl)
+ ft_init_sfx_funptr(t_cub *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;
+ cl->sfx[0].sfx_play = ft_sfx_death;
+ cl->sfx[1].sfx_play = ft_sfx_footstep;
+ cl->sfx[2].sfx_play = ft_sfx_new_level;
+ cl->sfx[3].sfx_play = ft_sfx_pain;
+ cl->sfx[4].sfx_play = ft_sfx_trap;
+ cl->sfx[5].sfx_play = ft_sfx_heal;
+ cl->sfx[6].sfx_play = ft_sfx_weapon_one_load;
+ cl->sfx[7].sfx_play = ft_sfx_weapon_one_fire;
+ cl->sfx[8].sfx_play = ft_sfx_weapon_two_load;
+ cl->sfx[9].sfx_play = ft_sfx_weapon_two_fire;
}
int8_t
@@ -97,7 +96,7 @@ int8_t
return (-1);
i = -1;
while (++i < 10)
- pthread_mutex_init(cl->sfx[i].mutex, NULL);
+ 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_key_loop.c b/src/ft_key_loop.c
index f44da13..cf412f7 100644
--- a/src/ft_key_loop.c
+++ b/src/ft_key_loop.c
@@ -86,7 +86,7 @@ int
cl->key_ptr[cl->key_input[i]](cl);
if (cl->key_input[i] >= 0 && cl->key_input[i] <= 3)
{
- ft_sfx_footstep(cl);
+ cl->sfx[1].sfx_play(cl->sfx);
ft_collision(old_y, old_x, cl->key_input[i], cl);
ft_find_item(&cl->plist, &cl->mlist, cl);
if (cl->mlist.isnlvl)
@@ -94,7 +94,7 @@ int
if ((uint32_t)cl->plist.pos_x == cl->mlist.nlx &&
(uint32_t)cl->plist.pos_y == cl->mlist.nly)
{
- ft_sfx_new_level(cl);
+ cl->sfx[2].sfx_play(cl->sfx);
return ((ft_warp_level(cl->mlist.nlevel_path, cl) < 0) ?
(ft_exit(FT_RET_FAILED_STRUCTS, cl)) : (0));
}
diff --git a/src/ft_sfx_death.c b/src/ft_sfx_death.c
index edc38ef..23dd26f 100644
--- a/src/ft_sfx_death.c
+++ b/src/ft_sfx_death.c
@@ -24,11 +24,11 @@ void
else
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
sfx = (t_sfx *)vargp;
- pthread_mutex_lock(&sfx->death_mutex);
+ pthread_mutex_lock(&sfx[0].mutex);
while (1)
{
- pthread_mutex_lock(&sfx->death_mutex);
- if (system(sfx->death))
+ pthread_mutex_lock(&sfx[0].mutex);
+ if (system(sfx[0].cmd))
pthread_exit(NULL);
}
return (NULL);
@@ -37,5 +37,5 @@ void
void
ft_sfx_death(t_sfx *sfx)
{
- pthread_mutex_unlock(&cl->sfx.death_mutex);
+ pthread_mutex_unlock(&sfx[0].mutex);
}
diff --git a/src/ft_sfx_footstep.c b/src/ft_sfx_footstep.c
index a6b2105..a940852 100644
--- a/src/ft_sfx_footstep.c
+++ b/src/ft_sfx_footstep.c
@@ -25,17 +25,17 @@ void
else
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
sfx = (t_sfx *)vargp;
- pthread_mutex_lock(&sfx->footstep_mutex);
+ pthread_mutex_lock(&sfx[1].mutex);
while (1)
{
ref = (ref > 201) ? (0) : (ref + 1);
- pthread_mutex_lock(&sfx->footstep_mutex);
+ pthread_mutex_lock(&sfx[1].mutex);
if (ref % 2)
{
- if (system(sfx->footstep_one))
+ if (system(sfx[1].cmd))
pthread_exit(NULL);
}
- else if (system(sfx->footstep_two))
+ else if (system(sfx[1].cmd_alt))
pthread_exit(NULL);
}
return (NULL);
@@ -44,5 +44,5 @@ void
void
ft_sfx_footstep(t_sfx *sfx)
{
- pthread_mutex_unlock(&cl->sfx.footstep_mutex);
+ pthread_mutex_unlock(&sfx[1].mutex);
}
diff --git a/src/ft_sfx_heal.c b/src/ft_sfx_heal.c
new file mode 100644
index 0000000..81704ee
--- /dev/null
+++ b/src/ft_sfx_heal.c
@@ -0,0 +1,41 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_sfx_heal.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_heal_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[5].mutex);
+ while (1)
+ {
+ pthread_mutex_lock(&sfx[5].mutex);
+ if (system(sfx[5].cmd))
+ pthread_exit(NULL);
+ }
+ return (NULL);
+}
+
+void
+ ft_sfx_heal(t_sfx *sfx)
+{
+ pthread_mutex_unlock(&sfx[5].mutex);
+}
diff --git a/src/ft_sfx_new_level.c b/src/ft_sfx_new_level.c
index 7e5d4ea..6dfe564 100644
--- a/src/ft_sfx_new_level.c
+++ b/src/ft_sfx_new_level.c
@@ -24,11 +24,11 @@ void
else
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
sfx = (t_sfx *)vargp;
- pthread_mutex_lock(&sfx->new_lvl_mutex);
+ pthread_mutex_lock(&sfx[2].mutex);
while (1)
{
- pthread_mutex_lock(&sfx->new_lvl_mutex);
- if (system(sfx->new_lvl))
+ pthread_mutex_lock(&sfx[2].mutex);
+ if (system(sfx[2].cmd))
pthread_exit(NULL);
}
return (NULL);
@@ -37,5 +37,5 @@ void
void
ft_sfx_new_level(t_sfx *sfx)
{
- pthread_mutex_unlock(&cl->sfx.new_lvl_mutex);
+ pthread_mutex_unlock(&sfx[2].mutex);
}
diff --git a/src/ft_sfx_pain.c b/src/ft_sfx_pain.c
index fe9ecaa..890f38c 100644
--- a/src/ft_sfx_pain.c
+++ b/src/ft_sfx_pain.c
@@ -25,17 +25,17 @@ void
else
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
sfx = (t_sfx *)vargp;
- pthread_mutex_lock(&sfx->pain_mutex);
+ pthread_mutex_lock(&sfx[3].mutex);
while (1)
{
- pthread_mutex_lock(&sfx->pain_mutex);
+ pthread_mutex_lock(&sfx[3].mutex);
ref = (ref > 201) ? (0) : (ref + 1);
if (ref % 3)
{
- if (system(sfx->pain_one))
+ if (system(sfx[3].cmd))
pthread_exit(NULL);
}
- else if (system(sfx->pain_two))
+ else if (system(sfx[3].cmd_alt))
pthread_exit(NULL);
}
return (NULL);
@@ -48,5 +48,5 @@ void
ref = (ref > 201) ? (0) : (ref + 1);
if (ref % 2)
- pthread_mutex_unlock(&cl->sfx.pain_mutex);
+ pthread_mutex_unlock(&sfx[3].mutex);
}
diff --git a/src/ft_sfx_trap.c b/src/ft_sfx_trap.c
index 2c35ef9..98f210b 100644
--- a/src/ft_sfx_trap.c
+++ b/src/ft_sfx_trap.c
@@ -24,11 +24,11 @@ void
else
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
sfx = (t_sfx *)vargp;
- pthread_mutex_lock(&sfx->trap_mutex);
+ pthread_mutex_lock(&sfx[4].mutex);
while (1)
{
- pthread_mutex_lock(&sfx->trap_mutex);
- if (system(sfx->trap))
+ pthread_mutex_lock(&sfx[4].mutex);
+ if (system(sfx[4].cmd))
pthread_exit(NULL);
}
return (NULL);
@@ -37,5 +37,5 @@ void
void
ft_sfx_trap(t_sfx *sfx)
{
- pthread_mutex_unlock(&cl->sfx.trap_mutex);
+ pthread_mutex_unlock(&sfx[4].mutex);
}
diff --git a/src/ft_sfx_weapon_one.c b/src/ft_sfx_weapon_one.c
new file mode 100644
index 0000000..fca86f5
--- /dev/null
+++ b/src/ft_sfx_weapon_one.c
@@ -0,0 +1,67 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_sfx_weapon_one.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_one_load_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[6].mutex);
+ while (1)
+ {
+ pthread_mutex_lock(&sfx[6].mutex);
+ if (system(sfx[6].cmd))
+ pthread_exit(NULL);
+ }
+ return (NULL);
+}
+
+void
+ ft_sfx_weapon_one_load(t_sfx *sfx)
+{
+ pthread_mutex_unlock(&sfx[6].mutex);
+}
+
+void
+ *ft_sfx_weapon_one_fire_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[7].mutex);
+ while (1)
+ {
+ pthread_mutex_lock(&sfx[7].mutex);
+ if (system(sfx[7].cmd))
+ pthread_exit(NULL);
+ }
+ return (NULL);
+}
+
+void
+ ft_sfx_weapon_one_fire(t_sfx *sfx)
+{
+ pthread_mutex_unlock(&sfx[7].mutex);
+}
diff --git a/src/ft_sfx_weapon_two.c b/src/ft_sfx_weapon_two.c
new file mode 100644
index 0000000..1afc933
--- /dev/null
+++ b/src/ft_sfx_weapon_two.c
@@ -0,0 +1,67 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_sfx_weapon_two.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_load_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[8].mutex);
+ while (1)
+ {
+ pthread_mutex_lock(&sfx[8].mutex);
+ if (system(sfx[8].cmd))
+ pthread_exit(NULL);
+ }
+ return (NULL);
+}
+
+void
+ ft_sfx_weapon_two_load(t_sfx *sfx)
+{
+ pthread_mutex_unlock(&sfx[8].mutex);
+}
+
+void
+ *ft_sfx_weapon_two_fire_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[9].mutex);
+ while (1)
+ {
+ pthread_mutex_lock(&sfx[9].mutex);
+ if (system(sfx[9].cmd))
+ pthread_exit(NULL);
+ }
+ return (NULL);
+}
+
+void
+ ft_sfx_weapon_two_fire(t_sfx *sfx)
+{
+ pthread_mutex_unlock(&sfx[9].mutex);
+}
diff --git a/src/ft_suffer_animation.c b/src/ft_suffer_animation.c
index 9ee7882..6a325bc 100644
--- a/src/ft_suffer_animation.c
+++ b/src/ft_suffer_animation.c
@@ -40,13 +40,13 @@ void
if (cl->plist.life <= 0)
{
cl->isdead = 1;
- ft_sfx_death(cl);
+ cl->sfx[0].sfx_play(cl->sfx);
ft_death_screen(cl);
}
else
{
- ft_sfx_trap(cl);
- ft_sfx_pain(cl);
+ cl->sfx[4].sfx_play(cl->sfx);
+ cl->sfx[3].sfx_play(cl->sfx);
}
}
@@ -76,13 +76,13 @@ void
if (cl->plist.life <= 0)
{
cl->isdead = 1;
- ft_sfx_death(cl);
+ cl->sfx[0].sfx_play(cl->sfx);
ft_death_screen(cl);
}
else
{
- ft_sfx_trap(cl);
- ft_sfx_pain(cl);
+ cl->sfx[4].sfx_play(cl->sfx);
+ cl->sfx[3].sfx_play(cl->sfx);
}
cl->doicast = 0;
}