/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_floor_cast.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rbousset +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/14 17:22:57 by rbousset #+# #+# */ /* Updated: 2020/02/14 17:23:42 by rbousset ### ########lyon.fr */ /* */ /* ************************************************************************** */ #include #include #include static void ft_draw_plain_horizontal(t_rgb rgb, t_cub *cl, int32_t y, int32_t x) { float dist; if ((dist = cl->rlist.row_dist_tab[y]) <= 0) dist = 0.0001; *(int*)(cl->img.ptr + (x * 4 + (y * cl->img.sizeline))) = ft_rgb_to_hex(dist, rgb, cl); } static void ft_draw_extra_tex(uint8_t tid, uint16_t y, uint16_t x, t_cub *cl) { float dist; t_rgb rgb; if ((dist = cl->rlist.row_dist_tab[y]) <= 0) dist = 0.0001; rgb.b = (uint8_t)cl->tlist[tid].ptr[cl->rlist.fc_tex_x_tab[tid - 6][y][x] * 4 + 4 * cl->tlist[tid].img_h * cl->rlist.fc_tex_y_tab[tid - 6][y][x]]; rgb.g = (uint8_t)cl->tlist[tid].ptr[cl->rlist.fc_tex_x_tab[tid - 6][y][x] * 4 + 4 * cl->tlist[tid].img_h * cl->rlist.fc_tex_y_tab[tid - 6][y][x] + 1]; rgb.r = (uint8_t)cl->tlist[tid].ptr[cl->rlist.fc_tex_x_tab[tid - 6][y][x] * 4 + 4 * cl->tlist[tid].img_h * cl->rlist.fc_tex_y_tab[tid - 6][y][x] + 2]; *(int*)(cl->img.ptr + ((uint16_t)x * 4 + (y * cl->img.sizeline))) = ft_rgb_to_hex(dist, rgb, cl); } static void ft_floor_cast_loop(uint16_t y, uint16_t x, t_cub *cl) { if (cl->mlist.isftex) { ft_draw_extra_tex(6, y, x, cl); } else ft_draw_plain_horizontal(cl->f_rgb, cl, y, x); if (cl->mlist.isctex && !cl->mlist.isskybox) { ft_draw_extra_tex(7, cl->wlist.y_size - y - 1, x, cl); } else if (!cl->mlist.isctex && !cl->mlist.isskybox) ft_draw_plain_horizontal(cl->c_rgb, cl, cl->wlist.y_size - y - 1, x); } void *ft_floor_one(void *vargp) { uint16_t x; uint16_t y; t_cub *cl; cl = (t_cub *)vargp; y = (cl->wlist.y_size / 2); while (y < (cl->wlist.y_size)) { x = 0; while (x < cl->wlist.x_size / 4) { if (cl->rlist.wall_bz[x] <= y) ft_floor_cast_loop(y, x, cl); x++; } y++; } pthread_exit(0x0); return (0x0); } void *ft_floor_two(void *vargp) { uint16_t x; uint16_t y; t_cub *cl; cl = (t_cub *)vargp; y = (cl->wlist.y_size / 2); /* y += 1 * (cl->wlist.y_size / 2 / 4); */ while (y < (cl->wlist.y_size)) { x = cl->wlist.x_size / 4; while (x < 2 * (cl->wlist.x_size / 4)) { if (cl->rlist.wall_bz[x] <= y) ft_floor_cast_loop(y, x, cl); x++; } y++; } pthread_exit(0x0); return (0x0); } void *ft_floor_three(void *vargp) { uint16_t x; uint16_t y; t_cub *cl; cl = (t_cub *)vargp; y = (cl->wlist.y_size / 2); while (y < (cl->wlist.y_size)) { x = 2 * (cl->wlist.x_size / 4); while (x < 3 * (cl->wlist.x_size / 4)) { if (cl->rlist.wall_bz[x] <= y) ft_floor_cast_loop(y, x, cl); x++; } y++; } pthread_exit(0x0); return (0x0); } void *ft_floor_four(void *vargp) { uint16_t x; uint16_t y; t_cub *cl; cl = (t_cub *)vargp; y = (cl->wlist.y_size / 2); while (y < (cl->wlist.y_size)) { x = 3 * (cl->wlist.x_size / 4); while (x < 4 * (cl->wlist.x_size / 4)) { if (cl->rlist.wall_bz[x] <= y) ft_floor_cast_loop(y, x, cl); x++; } y++; } pthread_exit(0x0); return (0x0); } void *ft_floor_cast(void *vargp) { pthread_t tid[4]; t_cub *cl; cl = (t_cub *)vargp; pthread_create(&tid[0], 0x0, ft_floor_one, (void*)cl); pthread_create(&tid[1], 0x0, ft_floor_two, (void*)cl); pthread_create(&tid[2], 0x0, ft_floor_three, (void*)cl); pthread_create(&tid[3], 0x0, ft_floor_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); }