aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_raycasting.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/ft_raycasting.c81
1 files changed, 66 insertions, 15 deletions
diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c
index 73aaf30..e83c8f7 100644
--- a/src/ft_raycasting.c
+++ b/src/ft_raycasting.c
@@ -87,6 +87,20 @@ static void
cl->rlist.wall_dist_tab[i] = cl->rlist.wall_dist;
}
+static void
+ ft_set_fc_tex_xy(uint8_t tid, uint16_t x, uint16_t y, t_cub *cl)
+{
+ const int32_t x_cell = (int32_t)(cl->rlist.x_floor);
+ const int32_t y_cell = (int32_t)(cl->rlist.y_floor);
+
+ cl->tlist[tid].tex_x = (int32_t)(cl->tlist[tid].img_h
+ * (cl->rlist.y_floor - y_cell));
+ cl->tlist[tid].tex_y = (int32_t)(cl->tlist[tid].img_w
+ * (cl->rlist.x_floor - x_cell));
+ cl->rlist.fc_tex_x_tab[tid - 6][y][x] = cl->tlist[tid].tex_x;
+ cl->rlist.fc_tex_y_tab[tid - 6][y][x] = cl->tlist[tid].tex_y;
+}
+
void
ft_castray(t_cub *cl)
{
@@ -106,13 +120,31 @@ void
sizeof(int16_t))) ||
!(cl->rlist.tex_x_tab = (int32_t*)malloc(cl->wlist.x_size *
sizeof(int32_t))) ||
- !(cl->rlist.y_floor_tab = (float*)malloc(cl->wlist.x_size *
- sizeof(float))) ||
- !(cl->rlist.x_floor_tab = (float*)malloc(cl->wlist.x_size *
- sizeof(float))) ||
+ !(cl->rlist.fc_tex_x_tab = (int32_t***)malloc(2 * sizeof(int32_t**))) ||
+ !(cl->rlist.fc_tex_y_tab = (int32_t***)malloc(2 * sizeof(int32_t**))) ||
!(cl->rlist.row_dist_tab = (float*)malloc(cl->wlist.y_size *
sizeof(float))))
- return ;
+ ft_error(FT_RET_ALLOC_ERR, FT_ERR_ALLOCATE, cl);
+ x = 0;
+ while (x < 2)
+ {
+ if (!(cl->rlist.fc_tex_x_tab[x] = (int**)malloc(cl->wlist.y_size *
+ sizeof(int*))) ||
+ !(cl->rlist.fc_tex_y_tab[x] = (int**)malloc(cl->wlist.y_size *
+ sizeof(int*))))
+ ft_error(FT_RET_ALLOC_ERR, FT_ERR_ALLOCATE, cl);
+ y = 0;
+ while (y < cl->wlist.y_size)
+ {
+ if (!(cl->rlist.fc_tex_x_tab[x][y] = (int*)malloc(cl->wlist.x_size *
+ sizeof(int))) ||
+ !(cl->rlist.fc_tex_y_tab[x][y] = (int*)malloc(cl->wlist.x_size *
+ sizeof(int))))
+ ft_error(FT_RET_ALLOC_ERR, FT_ERR_ALLOCATE, cl);
+ y++;
+ }
+ x++;
+ }
x = 0;
while (x < cl->wlist.x_size)
{
@@ -126,10 +158,15 @@ void
ft_floor_cast_inits(y, &cl->rlist, cl);
while (x < cl->wlist.x_size)
{
+ if (cl->rlist.wall_bz[x] <= y)
+ {
+ if (cl->mlist.isftex)
+ ft_set_fc_tex_xy(6, x, y, cl);
+ if (cl->mlist.isctex && !cl->mlist.isskybox)
+ ft_set_fc_tex_xy(7, x, cl->wlist.y_size - y - 1, cl);
+ }
cl->rlist.x_floor += cl->mlist.x_floor_step;
cl->rlist.y_floor += cl->mlist.y_floor_step;
- cl->rlist.x_floor_tab[x] = cl->rlist.x_floor;
- cl->rlist.y_floor_tab[x] = cl->rlist.y_floor;
x++;
}
cl->rlist.row_dist_tab[y] = cl->rlist.row_dist;
@@ -140,19 +177,33 @@ void
pthread_create(&tid[1], 0x0, ft_floor_cast, (void*)cl);
pthread_join(tid[0], 0x0);
pthread_join(tid[1], 0x0);
+ x = 0;
+ y = 0;
+ while (x < 2)
+ {
+ while (y < cl->wlist.y_size)
+ {
+ free(cl->rlist.fc_tex_x_tab[x][y]);
+ free(cl->rlist.fc_tex_y_tab[x][y]);
+ y++;
+ }
+ free(cl->rlist.fc_tex_x_tab[x]);
+ free(cl->rlist.fc_tex_y_tab[x]);
+ x++;
+ }
+ free(cl->rlist.fc_tex_x_tab);
+ free(cl->rlist.fc_tex_y_tab);
+ ft_memdel((void*)&cl->rlist.tex_x_tab);
+ ft_memdel((void*)&cl->rlist.row_dist_tab);
+ ft_memdel((void*)&cl->rlist.wall_t_tab);
+ ft_memdel((void*)&cl->rlist.w_side_tab);
+ ft_memdel((void*)&cl->rlist.line_h_tab);
+ ft_memdel((void*)&cl->rlist.wall_bz);
ft_calc_sprite(cl);
ft_calc_heal(cl);
ft_calc_trap(cl);
ft_calc_weaps(cl);
if (cl->plist.handles_weapon > -1)
ft_draw_handweap(cl);
- ft_memdel((void*)&cl->rlist.tex_x_tab);
- ft_memdel((void*)&cl->rlist.y_floor_tab);
- ft_memdel((void*)&cl->rlist.x_floor_tab);
- ft_memdel((void*)&cl->rlist.row_dist_tab);
- ft_memdel((void*)&cl->rlist.wall_t_tab);
- ft_memdel((void*)&cl->rlist.w_side_tab);
- ft_memdel((void*)&cl->rlist.line_h_tab);
ft_memdel((void*)&cl->rlist.wall_dist_tab);
- ft_memdel((void*)&cl->rlist.wall_bz);
}