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
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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
*/
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_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[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);
}
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;
}
int8_t
ft_init_sfx(t_cub *cl)
{
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 ||
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)
return (-1);
i = -1;
while (++i < 12)
pthread_mutex_init(&cl->sfx[i].mutex, NULL);
ft_init_sfx_pthreads(cl);
ft_init_sfx_funptr(cl);
return (0);
}
|