/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_floor_cast.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: joelecle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/14 17:22:57 by joelecle #+# #+# */ /* Updated: 2020/02/14 17:23:42 by joelecle ### ########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; dist = cl->rlist.row_dist_tab[y]; if (dist <= 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); } 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 if (!cl->mlist.isftex) ft_draw_plain_horizontal(cl->f_rgb, cl, y, x); if (cl->mlist.isctex) { ft_draw_extra_tex(7, cl->wlist.y_size - y - 1, x, cl); } else if (!cl->mlist.isctex) ft_draw_plain_horizontal(cl->c_rgb, cl, cl->wlist.y_size - y - 1, x); } void *ft_floor_cast(void *vargp) { pthread_t tid[5]; 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_create(&tid[4], 0x0, ft_floor_five, (void*)cl); pthread_join(tid[4], 0x0); pthread_join(tid[3], 0x0); pthread_join(tid[2], 0x0); pthread_join(tid[1], 0x0); pthread_join(tid[0], 0x0); pthread_exit(0x0); return (0x0); }