aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--inc/cub3d.h2
-rw-r--r--inc/cub3d_structs.h8
-rw-r--r--src/ft_draw_textures.c17
-rw-r--r--src/ft_draw_verline.c7
-rw-r--r--src/ft_raycasting.c20
5 files changed, 38 insertions, 16 deletions
diff --git a/inc/cub3d.h b/inc/cub3d.h
index 25b80ee..8fcafc6 100644
--- a/inc/cub3d.h
+++ b/inc/cub3d.h
@@ -160,7 +160,7 @@ uint8_t ft_use_args(int argc, const char *argv[], t_cub *clist);
*/
void ft_castray(t_cub *cl);
-void ft_choose_tex(t_cub *clist);
+void ft_choose_tex(uint16_t x, t_cub *clist);
void ft_detect(t_cub *cl);
void ft_detection_init_x(t_cub *cl);
void ft_detection_init_y(t_cub *cl);
diff --git a/inc/cub3d_structs.h b/inc/cub3d_structs.h
index 809963c..fb690ee 100644
--- a/inc/cub3d_structs.h
+++ b/inc/cub3d_structs.h
@@ -142,7 +142,6 @@ typedef struct s_ray
{
uint16_t line_h;
float wall_dist;
- float *wall_dist_tab;
float x_ray_pos;
float y_ray_pos;
float x_ray_dir;
@@ -153,7 +152,6 @@ typedef struct s_ray
float y_delta_dist;
int16_t wall_t;
int16_t wall_b;
- int16_t *wall_bz;
uint8_t side;
size_t sqx;
size_t sqy;
@@ -170,6 +168,12 @@ typedef struct s_ray
float y_floor;
int32_t x_cell;
int32_t y_cell;
+ int16_t *wall_t_tab;
+ int16_t *wall_b_tab;
+ uint8_t *w_side_tab;
+ uint16_t *line_h_tab;
+ float *wall_dist_tab;
+ int16_t *wall_bz;
} t_ray;
typedef struct s_map
diff --git a/src/ft_draw_textures.c b/src/ft_draw_textures.c
index 0724a6d..c7684f9 100644
--- a/src/ft_draw_textures.c
+++ b/src/ft_draw_textures.c
@@ -28,20 +28,20 @@ void
float dist;
t_rgb rgb;
- if ((dist = cl->rlist.wall_dist) <= 0)
+ if ((dist = cl->rlist.wall_dist_tab[x]) <= 0)
dist = 0.0001;
- rgb.b = (uint8_t)cl->tlist[cl->w_side].ptr[cl->tlist[cl->w_side].tex_x
- * 4 + 4 * cl->tlist[cl->w_side].img_h * tex_y];
- rgb.g = (uint8_t)cl->tlist[cl->w_side].ptr[cl->tlist[cl->w_side].tex_x
- * 4 + 4 * cl->tlist[cl->w_side].img_h * tex_y + 1];
- rgb.r = (uint8_t)cl->tlist[cl->w_side].ptr[cl->tlist[cl->w_side].tex_x
- * 4 + 4 * cl->tlist[cl->w_side].img_h * tex_y + 2];
+ rgb.r = (uint8_t)cl->tlist[cl->rlist.w_side_tab[x]].ptr[cl->tlist[cl->rlist.w_side_tab[x]].tex_x
+ * 4 + 4 * cl->tlist[cl->rlist.w_side_tab[x]].img_h * tex_y + 2];
+ rgb.g = (uint8_t)cl->tlist[cl->rlist.w_side_tab[x]].ptr[cl->tlist[cl->rlist.w_side_tab[x]].tex_x
+ * 4 + 4 * cl->tlist[cl->rlist.w_side_tab[x]].img_h * tex_y + 1];
+ rgb.b = (uint8_t)cl->tlist[cl->rlist.w_side_tab[x]].ptr[cl->tlist[cl->rlist.w_side_tab[x]].tex_x
+ * 4 + 4 * cl->tlist[cl->rlist.w_side_tab[x]].img_h * tex_y];
*(int*)(cl->img.ptr + ((uint16_t)x * 4 +
(y * cl->img.sizeline))) = ft_rgb_to_hex(dist, rgb, cl);
}
void
- ft_choose_tex(t_cub *clist)
+ ft_choose_tex(uint16_t x, t_cub *clist)
{
if (clist->rlist.sqy == clist->mlist.nlx
&& clist->rlist.sqx == clist->mlist.nly)
@@ -59,4 +59,5 @@ void
else
clist->w_side = 2;
}
+ clist->rlist.w_side_tab[x] = clist->w_side;
}
diff --git a/src/ft_draw_verline.c b/src/ft_draw_verline.c
index 7bfba8d..3ecde46 100644
--- a/src/ft_draw_verline.c
+++ b/src/ft_draw_verline.c
@@ -21,12 +21,13 @@ int8_t
(y < 0) ? (y = 0) : 0;
(y2 < 0) ? (y2 = 0) : 0;
- (cl->rlist.line_h <= 0) ? (cl->rlist.line_h = 1) : 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 * 128;
+ 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->w_side].img_h) / cl->rlist.line_h) / 256;
+ 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++;
diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c
index 1a12c46..3429f20 100644
--- a/src/ft_raycasting.c
+++ b/src/ft_raycasting.c
@@ -71,13 +71,16 @@ static void
{
ft_initray(i, cl);
cl->rlist.line_h = (int16_t)(wl->y_size / cl->rlist.wall_dist);
+ cl->rlist.line_h_tab[i] = cl->rlist.line_h;
cl->rlist.wall_t = -cl->rlist.line_h / 2 + wl->y_size / 2;
if (cl->rlist.wall_t < 0)
cl->rlist.wall_t = 0;
+ cl->rlist.wall_t_tab[i] = cl->rlist.wall_t;
cl->rlist.wall_b = cl->rlist.line_h / 2 + wl->y_size / 2;
if (cl->rlist.wall_b >= (int16_t)wl->y_size)
cl->rlist.wall_b = wl->y_size - 1;
- ft_choose_tex(cl);
+ cl->rlist.wall_b_tab[i] = cl->rlist.wall_b;
+ ft_choose_tex(i, cl);
ft_calc_tex(cl);
cl->rlist.wall_bz[i] = cl->rlist.wall_b;
cl->rlist.wall_dist_tab[i] = cl->rlist.wall_dist;
@@ -94,11 +97,20 @@ void
if (!(cl->rlist.wall_bz =
(int16_t*)malloc(cl->wlist.x_size * sizeof(int16_t))))
return ;
+ cl->rlist.w_side_tab = (uint8_t*)ft_calloc(cl->wlist.x_size, sizeof(uint8_t));
+ cl->rlist.line_h_tab = (uint16_t*)ft_calloc(cl->wlist.x_size, sizeof(uint16_t));
+ cl->rlist.wall_t_tab = (int16_t*)ft_calloc(cl->wlist.x_size, sizeof(int16_t));
+ cl->rlist.wall_b_tab = (int16_t*)ft_calloc(cl->wlist.x_size, sizeof(int16_t));
i = 0;
while (i < cl->wlist.x_size)
{
ft_castray_loop(i, &cl->wlist, cl);
- ft_draw_verline(cl, i, cl->rlist.wall_t, cl->rlist.wall_b);
+ i++;
+ }
+ i = 0;
+ while (i < cl->wlist.x_size)
+ {
+ ft_draw_verline(cl, i, cl->rlist.wall_t_tab[i], cl->rlist.wall_b_tab[i]);
i++;
}
ft_floor_cast(cl);
@@ -108,6 +120,10 @@ void
ft_calc_weaps(cl);
if (cl->plist.handles_weapon > -1)
ft_draw_handweap(cl);
+ ft_memdel((void*)&cl->rlist.wall_t_tab);
+ ft_memdel((void*)&cl->rlist.wall_b_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);
}