1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_init_lists.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/14 17:28:53 by rbousset #+# #+# */
/* Updated: 2020/02/14 17:28:53 by rbousset ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include <libft.h>
#include <mlx.h>
#include <cub3d.h>
#include <stddef.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <pthread.h>
/*
** sfx[] index summary
** -------------------
** 0: death
** 1: footstep | double
** 2: new level
** 3: pain | double
** 4: trap
** 5: heal
** 6: weapon one load
** 7: weapon one fire
** 8: weapon two load
** 9: weapon two fire
** 10: weapon three load
** 11: weapon three fire
** 12: out of ammunitions
** 13: enemy death
** 14: enemy scream | double
** 15: enemy fire
** 16: weapon two fire overdub
** 17: weapon two fire overdub x2
*/
static int8_t
ft_init_sfx_cmd(char **target, const char *path)
{
uint8_t len;
len = ft_strlen(path);
len += ft_strlen(FT_SND_CMD) - 2;
if (!(*target = (char *)malloc((len + 1) * sizeof(char))))
return (-1);
ft_sprintf(*target, FT_SND_CMD, path);
return (0);
}
static void
ft_init_sfx_pthreads(t_cub *cl)
{
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_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,
ft_sfx_weapon_three_fire_thread, &cl->sfx);
pthread_create(&cl->sfx[12].tid, NULL, ft_sfx_ooa_thread, &cl->sfx);
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
ft_init_sfx_funptr(t_cub *cl)
{
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;
cl->sfx[10].sfx_play = ft_sfx_weapon_three_load;
cl->sfx[11].sfx_play = ft_sfx_weapon_three_fire;
cl->sfx[12].sfx_play = ft_sfx_ooa;
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
ft_init_sfx_cmds(t_cub *cl)
{
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 ||
ft_init_sfx_cmd(&cl->sfx[10].cmd, FT_SFX_W_THREE_LOAD_PATH) < 0 ||
ft_init_sfx_cmd(&cl->sfx[11].cmd, FT_SFX_W_THREE_FIRE_PATH) < 0 ||
ft_init_sfx_cmd(&cl->sfx[12].cmd, FT_SFX_OOA_PATH) < 0 ||
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[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);
}
int8_t
ft_init_sfx(t_cub *cl)
{
uint8_t i;
if (ft_init_sfx_cmds(cl) < 0)
return (-1);
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);
}
|