diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-11 00:00:07 +0100 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-11 00:00:07 +0100 |
commit | 25247ca1f3ffc9485b02686f616c41a52f8eb82a (patch) | |
tree | 38897a8228b34f4b77a3b506c278ced62514ff68 | |
parent | Freed multiple leaks (diff) | |
download | 42-cub3d-25247ca1f3ffc9485b02686f616c41a52f8eb82a.tar.gz 42-cub3d-25247ca1f3ffc9485b02686f616c41a52f8eb82a.tar.bz2 42-cub3d-25247ca1f3ffc9485b02686f616c41a52f8eb82a.tar.xz 42-cub3d-25247ca1f3ffc9485b02686f616c41a52f8eb82a.tar.zst 42-cub3d-25247ca1f3ffc9485b02686f616c41a52f8eb82a.zip |
Pas trop ecole opti memoire mais ok
-rw-r--r-- | inc/cub3d.h | 2 | ||||
-rw-r--r-- | inc/cub3d_structs.h | 1 | ||||
-rw-r--r-- | map/map_five.cub | 3 | ||||
-rw-r--r-- | src/ft_floor_cast.c | 46 | ||||
-rw-r--r-- | src/ft_raycasting.c | 16 |
5 files changed, 40 insertions, 28 deletions
diff --git a/inc/cub3d.h b/inc/cub3d.h index 7de1df7..2a9d66e 100644 --- a/inc/cub3d.h +++ b/inc/cub3d.h @@ -130,7 +130,7 @@ uint8_t ft_use_args(int argc, const char *argv[], void ft_castray(t_cub *cl); void ft_detect(t_cub *cl); -void ft_floor_cast(uint16_t y, t_cub *cl); +void ft_floor_cast(t_cub *cl); /* ** ====== OTHER ====== diff --git a/inc/cub3d_structs.h b/inc/cub3d_structs.h index f1dfdfc..144de6f 100644 --- a/inc/cub3d_structs.h +++ b/inc/cub3d_structs.h @@ -137,6 +137,7 @@ 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; diff --git a/map/map_five.cub b/map/map_five.cub index 3c6bc4a..d5c3361 100644 --- a/map/map_five.cub +++ b/map/map_five.cub @@ -8,11 +8,10 @@ S ./media/img/crapaud.xpm F ./media/img/terre.xpm C 225,30,0 -SB ./media/img/normal_sky.xpm LT ./media/img/linuz.xpm L ./map/map_two.cub -SH 5 +SH 4 1111111111111111111111111111111 1000000000110000000000000000001 diff --git a/src/ft_floor_cast.c b/src/ft_floor_cast.c index 384f699..d2c6046 100644 --- a/src/ft_floor_cast.c +++ b/src/ft_floor_cast.c @@ -78,8 +78,6 @@ static void { ft_set_tex_xy(7, rl, cl); } - rl->x_floor += cl->mlist.x_floor_step; - rl->y_floor += cl->mlist.y_floor_step; if (cl->mlist.isftex) ft_draw_extra_tex(6, y, x, cl); else @@ -91,28 +89,38 @@ static void } void - ft_floor_cast(uint16_t y, t_cub *cl) + ft_floor_cast(t_cub *cl) { t_ray *rl; uint16_t x; + uint16_t y; rl = &cl->rlist; - rl->x_f_ray_dir = cl->plist.dir_x - cl->plist.plane_x; - rl->y_f_ray_dir = cl->plist.dir_y - cl->plist.plane_y; - rl->x_f_ray_dir_bis = cl->plist.dir_x + cl->plist.plane_x; - rl->y_f_ray_dir_bis = cl->plist.dir_y + cl->plist.plane_y; - rl->p = y - cl->wlist.y_size / 2; - cl->plist.pos_z = 0.5 * cl->wlist.y_size; - rl->row_dist = cl->plist.pos_z / rl->p; - cl->mlist.x_floor_step = rl->row_dist * - (rl->x_f_ray_dir_bis - rl->x_f_ray_dir) / cl->wlist.x_size; - cl->mlist.y_floor_step = rl->row_dist * - (rl->y_f_ray_dir_bis - rl->y_f_ray_dir) / cl->wlist.x_size; - rl->x_floor = cl->plist.pos_y + rl->row_dist * rl->x_f_ray_dir; - rl->y_floor = cl->plist.pos_x + rl->row_dist * rl->y_f_ray_dir; - x = 0; - while (++x < cl->wlist.x_size) + y = (cl->wlist.y_size / 2) + 1; + while (++y < cl->wlist.y_size) { - ft_floor_cast_loop(y, x, rl, cl); + rl->x_f_ray_dir = cl->plist.dir_x - cl->plist.plane_x; + rl->y_f_ray_dir = cl->plist.dir_y - cl->plist.plane_y; + rl->x_f_ray_dir_bis = cl->plist.dir_x + cl->plist.plane_x; + rl->y_f_ray_dir_bis = cl->plist.dir_y + cl->plist.plane_y; + rl->p = y - cl->wlist.y_size / 2; + cl->plist.pos_z = 0.5 * cl->wlist.y_size; + rl->row_dist = cl->plist.pos_z / rl->p; + cl->mlist.x_floor_step = rl->row_dist * + (rl->x_f_ray_dir_bis - rl->x_f_ray_dir) / cl->wlist.x_size; + cl->mlist.y_floor_step = rl->row_dist * + (rl->y_f_ray_dir_bis - rl->y_f_ray_dir) / cl->wlist.x_size; + rl->x_floor = cl->plist.pos_y + rl->row_dist * rl->x_f_ray_dir; + rl->y_floor = cl->plist.pos_x + rl->row_dist * rl->y_f_ray_dir; + x = -1; + while (++x < cl->wlist.x_size) + { + if (cl->rlist.wall_bz[x] <= y) + { + ft_floor_cast_loop(y, x, rl, cl); + } + rl->x_floor += cl->mlist.x_floor_step; + rl->y_floor += cl->mlist.y_floor_step; + } } } diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c index baa71af..5c57044 100644 --- a/src/ft_raycasting.c +++ b/src/ft_raycasting.c @@ -76,24 +76,25 @@ static void if (cl->rlist.wall_t < 0) cl->rlist.wall_t = 0; cl->rlist.wall_b = cl->rlist.line_h / 2 + wl->y_size / 2; - if (cl->rlist.wall_b >= (float)wl->y_size) + if (cl->rlist.wall_b >= (int16_t)wl->y_size) cl->rlist.wall_b = wl->y_size - 1; + cl->rlist.wall_bz[i] = cl->rlist.wall_b; } void ft_castray(t_cub *cl) { - uint16_t i; - t_win *wl; + uint16_t i; + t_win *wl; ft_memdel((void**)&cl->rlist.wall_dist_tab); wl = &cl->wlist; - i = (wl->y_size / 2) + 1; - while (++i < wl->y_size) - ft_floor_cast(i, cl); if (!(cl->rlist.wall_dist_tab = (float*)malloc(sizeof(float) * cl->wlist.x_size))) return ; + if (!(cl->rlist.wall_bz = + (int16_t*)malloc(cl->wlist.x_size * sizeof(int16_t)))) + return ; i = 0; while (i < wl->x_size) { @@ -104,4 +105,7 @@ void cl->rlist.wall_dist_tab[i] = cl->rlist.wall_dist; i++; } + ft_floor_cast(cl); + i = 0; + ft_memdel((void**)&cl->rlist.wall_bz); } |