aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_wall_cast.c
blob: b8d4e3cd3d3d63ba7a10b234c6d98d941340f36c (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
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
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   ft_wall_cast.c                                     :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: rbousset <marvin@42.fr>                    +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/02/14 17:22:23 by rbousset          #+#    #+#             */
/*   Updated: 2020/02/14 17:23:42 by rbousset         ###   ########lyon.fr   */
/*                                                                            */
/* ************************************************************************** */

#include <cub3d.h>
#include <stdint.h>
#include <pthread.h>

static void
	ft_draw_verline(t_cub *cl, int32_t x, int32_t y, int32_t y2)
{
	int32_t	d;
	int32_t tex_y;

	(y < 0) ? (y = 0) : 0;
	(y2 < 0) ? (y2 = 0) : 0;
	(cl->rlist.line_h_tab[x] <= 0) ? (cl->rlist.line_h_tab[x] = 1) : 0;
	while (y < y2)
	{
		d = y * 256 - cl->wlist.y_size * 128 + cl->rlist.line_h_tab[x] * 128;
		d = (d <= 0) ? (-d) : (d);
		tex_y = ((d * cl->tlist[cl->rlist.w_side_tab[x]].img_h)
			/ cl->rlist.line_h_tab[x]) / 256;
		(tex_y <= 0) ? (tex_y = 1) : 0;
		ft_draw_texture(cl, x, y, tex_y);
		y++;
	}
}

static void
*ft_wall_one(void *vargp)
{
	t_cub		*cl;
	uint16_t	i;

	cl = (t_cub *)vargp;
	i = 0;
	while (i < cl->wlist.x_size / 4)
	{
		ft_draw_verline(cl, i, cl->rlist.wall_t_tab[i], cl->rlist.wall_bz[i]);
		i++;
	}
	pthread_exit(0x0);
	return (0x0);
}

static void
*ft_wall_two(void *vargp)
{
	t_cub		*cl;
	uint16_t	i;

	cl = (t_cub *)vargp;
	i = cl->wlist.x_size / 4;
	while (i < 2 * (cl->wlist.x_size / 4))
	{
		ft_draw_verline(cl, i, cl->rlist.wall_t_tab[i], cl->rlist.wall_bz[i]);
		i++;
	}
	pthread_exit(0x0);
	return (0x0);
}

static void
*ft_wall_three(void *vargp)
{
	t_cub		*cl;
	uint16_t	i;

	cl = (t_cub *)vargp;
	i = 2 * (cl->wlist.x_size / 4);
	while (i < 3 * (cl->wlist.x_size / 4))
	{
		ft_draw_verline(cl, i, cl->rlist.wall_t_tab[i], cl->rlist.wall_bz[i]);
		i++;
	}
	pthread_exit(0x0);
	return (0x0);
}

static void
*ft_wall_four(void *vargp)
{
	t_cub		*cl;
	uint16_t	i;

	cl = (t_cub *)vargp;
	i = 3 * (cl->wlist.x_size / 4);
	while (i < 4 * (cl->wlist.x_size / 4))
	{
		ft_draw_verline(cl, i, cl->rlist.wall_t_tab[i], cl->rlist.wall_bz[i]);
		i++;
	}
	pthread_exit(0x0);
	return (0x0);
}

void
	*ft_wall_cast(void *vargp)
{
	pthread_t	tid[8];
	t_cub		*cl;

	cl = (t_cub *)vargp;
	pthread_create(&tid[0], 0x0, ft_wall_one, (void*)cl);
	pthread_create(&tid[1], 0x0, ft_wall_two, (void*)cl);
	pthread_create(&tid[2], 0x0, ft_wall_three, (void*)cl);
	pthread_create(&tid[3], 0x0, ft_wall_four, (void*)cl);
	pthread_join(tid[0], 0x0);
	pthread_join(tid[1], 0x0);
	pthread_join(tid[2], 0x0);
	pthread_join(tid[3], 0x0);
	/* pthread_exit(0x0); */
	return (0x0);
}