aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_init_sfx.c
blob: 35ab57df794cc945351080948930e765b1b0f0e7 (plain)
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
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   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>

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);
}

int8_t
	ft_init_sfx(t_sfx *sfx)
{
	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)
		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);
	return (0);
}