diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-24 14:25:19 +0100 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-24 14:25:19 +0100 |
commit | 4f154eaf3a8f531999db140c2040f10016042b9d (patch) | |
tree | 7933ef9c6cdf5363ea6b08ff16e9a07ee5253490 /src/ft_floor_cast.c | |
parent | Doesn't look too bad (diff) | |
download | 42-cub3d-4f154eaf3a8f531999db140c2040f10016042b9d.tar.gz 42-cub3d-4f154eaf3a8f531999db140c2040f10016042b9d.tar.bz2 42-cub3d-4f154eaf3a8f531999db140c2040f10016042b9d.tar.xz 42-cub3d-4f154eaf3a8f531999db140c2040f10016042b9d.tar.zst 42-cub3d-4f154eaf3a8f531999db140c2040f10016042b9d.zip |
Ram issues
Diffstat (limited to '')
-rw-r--r-- | src/ft_floor_cast.c | 239 |
1 files changed, 215 insertions, 24 deletions
diff --git a/src/ft_floor_cast.c b/src/ft_floor_cast.c index aa89f99..b00792e 100644 --- a/src/ft_floor_cast.c +++ b/src/ft_floor_cast.c @@ -12,6 +12,7 @@ #include <cub3d.h> #include <stdint.h> +#include <pthread.h> static void ft_draw_plain_horizontal(t_rgb rgb, t_cub *cl, int32_t y, int32_t x) @@ -32,41 +33,27 @@ static void if ((dist = cl->rlist.row_dist_tab[y]) <= 0) dist = 0.0001; - rgb.b = (uint8_t)cl->tlist[tid].ptr[cl->tlist[tid].tex_x - * 4 + 4 * cl->tlist[tid].img_h * cl->tlist[tid].tex_y]; - rgb.g = (uint8_t)cl->tlist[tid].ptr[cl->tlist[tid].tex_x - * 4 + 4 * cl->tlist[tid].img_h * cl->tlist[tid].tex_y + 1]; - rgb.r = (uint8_t)cl->tlist[tid].ptr[cl->tlist[tid].tex_x - * 4 + 4 * cl->tlist[tid].img_h * cl->tlist[tid].tex_y + 2]; + 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_set_tex_xy(uint8_t tid, uint16_t x, t_ray *rl, t_cub *cl) -{ - const int32_t x_cell = (int32_t)(rl->x_floor_tab[x]); - const int32_t y_cell = (int32_t)(rl->y_floor_tab[x]); - - cl->tlist[tid].tex_x = (int32_t)(cl->tlist[tid].img_h - * (rl->y_floor_tab[x] - y_cell)); - cl->tlist[tid].tex_y = (int32_t)(cl->tlist[tid].img_w - * (rl->x_floor_tab[x] - x_cell)); -} - -static void - ft_floor_cast_loop(uint16_t y, uint16_t x, t_ray *rl, t_cub *cl) + ft_floor_cast_loop(uint16_t y, uint16_t x, t_cub *cl) { if (cl->mlist.isftex) { - ft_set_tex_xy(6, x, rl, cl); 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_set_tex_xy(7, x, rl, cl); ft_draw_extra_tex(7, cl->wlist.y_size - y - 1, x, cl); } else if (!cl->mlist.isctex && !cl->mlist.isskybox) @@ -74,24 +61,228 @@ static void } void - *ft_floor_cast(void *vargp) +*ft_floor_one(void *vargp) { + uint16_t x; + uint16_t y; t_cub *cl; + + cl = (t_cub *)vargp; + y = (cl->wlist.y_size / 2); + y += 0 * (cl->wlist.y_size / 2 / 8); + while (y < (cl->wlist.y_size / 2) + (1 * (cl->wlist.y_size / 2 / 8))) + { + x = 0; + while (x < cl->wlist.x_size) + { + 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); - while (y < cl->wlist.y_size) + y += 1 * (cl->wlist.y_size / 2 / 8); + while (y < (cl->wlist.y_size / 2) + (2 * (cl->wlist.y_size / 2 / 8))) { x = 0; while (x < cl->wlist.x_size) { if (cl->rlist.wall_bz[x] <= y) - ft_floor_cast_loop(y, x, &cl->rlist, cl); + 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); + y += (2 * (cl->wlist.y_size / 2 / 8)); + while (y < (cl->wlist.y_size / 2) + (3 * (cl->wlist.y_size / 2 / 8))) + { + x = 0; + while (x < cl->wlist.x_size) + { + 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); + y += (3 * (cl->wlist.y_size / 2 / 8)); + while (y < (cl->wlist.y_size / 2) + (4 * (cl->wlist.y_size / 2 / 8))) + { + x = 0; + while (x < cl->wlist.x_size) + { + if (cl->rlist.wall_bz[x] <= y) + ft_floor_cast_loop(y, x, cl); + x++; + } + y++; + } + pthread_exit(0x0); + return (0x0); +} + +void +*ft_floor_five(void *vargp) +{ + uint16_t x; + uint16_t y; + t_cub *cl; + + cl = (t_cub *)vargp; + y = (cl->wlist.y_size / 2); + y += (4 * (cl->wlist.y_size / 2 / 8)); + while (y < (cl->wlist.y_size / 2) + (5 * (cl->wlist.y_size / 2 / 8))) + { + x = 0; + while (x < cl->wlist.x_size) + { + if (cl->rlist.wall_bz[x] <= y) + ft_floor_cast_loop(y, x, cl); + x++; + } + y++; + } + pthread_exit(0x0); + return (0x0); +} + +void +*ft_floor_six(void *vargp) +{ + uint16_t x; + uint16_t y; + t_cub *cl; + + cl = (t_cub *)vargp; + y = (cl->wlist.y_size / 2); + y += (5 * (cl->wlist.y_size / 2 / 8)); + while (y < (cl->wlist.y_size / 2) + (6 * (cl->wlist.y_size / 2 / 8))) + { + x = 0; + while (x < cl->wlist.x_size) + { + if (cl->rlist.wall_bz[x] <= y) + ft_floor_cast_loop(y, x, cl); + x++; + } + y++; + } + pthread_exit(0x0); + return (0x0); +} + +void +*ft_floor_seven(void *vargp) +{ + uint16_t x; + uint16_t y; + t_cub *cl; + + cl = (t_cub *)vargp; + y = (cl->wlist.y_size / 2); + y += (6 * (cl->wlist.y_size / 2 / 8)); + while (y < (cl->wlist.y_size / 2) + (7 * (cl->wlist.y_size / 2 / 8))) + { + x = 0; + while (x < cl->wlist.x_size) + { + if (cl->rlist.wall_bz[x] <= y) + ft_floor_cast_loop(y, x, cl); + x++; + } + y++; + } + pthread_exit(0x0); + return (0x0); +} + +void +*ft_floor_eight(void *vargp) +{ + uint16_t x; + uint16_t y; + t_cub *cl; + + cl = (t_cub *)vargp; + y = (cl->wlist.y_size / 2); + y += (7 * (cl->wlist.y_size / 2 / 8)); + while (y < (cl->wlist.y_size / 2) + (8 * (cl->wlist.y_size / 2 / 8))) + { + x = 0; + while (x < cl->wlist.x_size) + { + 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[8]; + 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_create(&tid[5], 0x0, ft_floor_six, (void*)cl); + pthread_create(&tid[6], 0x0, ft_floor_seven, (void*)cl); + pthread_create(&tid[7], 0x0, ft_floor_eight, (void*)cl); + pthread_join(tid[0], 0x0); + pthread_join(tid[1], 0x0); + pthread_join(tid[2], 0x0); + pthread_join(tid[3], 0x0); + pthread_join(tid[4], 0x0); + pthread_join(tid[5], 0x0); + pthread_join(tid[6], 0x0); + pthread_join(tid[7], 0x0); + pthread_exit(0x0); return (0x0); } |