diff options
Diffstat (limited to '')
-rw-r--r-- | inc/cub3d.h | 3 | ||||
-rw-r--r-- | map/map_one.cub | 17 | ||||
-rw-r--r-- | src/ft_draw_sprite.c | 3 | ||||
-rw-r--r-- | src/ft_sort_s_t.c | 31 |
4 files changed, 40 insertions, 14 deletions
diff --git a/inc/cub3d.h b/inc/cub3d.h index 38d4e3f..92e57ce 100644 --- a/inc/cub3d.h +++ b/inc/cub3d.h @@ -87,8 +87,9 @@ void ft_draw_circle(float a, float b, int32_t color, t_cub *cl); void ft_draw_verline(t_cub *cl, int32_t x, int32_t y, int32_t y2); void ft_sprite_h_w(t_cub *cl, t_sprite *sprite); +void ft_alloc_dist_tab(float ***dist_tab, t_cub *cl); void ft_sort_sprites(t_cub *cl, int16_t i, int16_t j); -void ft_sort_s_t(t_cub *cl, float dist_tab[8][4096]); +void ft_sort_s_t(t_cub *cl, float **dist_tab); void ft_calc_sprite(t_cub *cl); void ft_draw_sprite(t_cub *cl, t_sprite *sprite); void ft_calc_trap(t_cub *cl); diff --git a/map/map_one.cub b/map/map_one.cub index e7395cb..f0a498b 100644 --- a/map/map_one.cub +++ b/map/map_one.cub @@ -11,10 +11,11 @@ F ./media/img/tex/parquet.xpm S ./media/img/sprites/pillar.xpm S3 ./media/img/sprites/pylon.xpm S4 ./media/img/sprites/hey.xpm -S5 ./media/img/sprites/hey.xpm -S6 ./media/img/sprites/hey.xpm -S7 ./media/img/sprites/hey.xpm -S8 ./media/img/sprites/hey.xpm +S5 ./media/img/sprites/larry.xpm +S6 ./media/img/sprites/linus.xpm +S7 ./media/img/sprites/spikes.xpm +S8 ./media/img/sprites/wood_chest.xpm +S9 ./media/img/sprites/first_aid.xpm T ./media/img/sprites/spikes.xpm @@ -23,12 +24,12 @@ SH 2 1111111111111111111 111111111111000000000000000001 100000000000000000000000000001 -10000E000000020304050607000001 +100000000000020304050607080901 100000000000000000000000000001 1001000000T0000000000000000001 -10110+0+0111000001111111111111 -111111111111110011 -1000001 100001 +10110+0+0111000001110000000111 +111111111111110011 1000N0001 +1000001 100001 111111111 1001001 100001 1011001 100001 111101111111110111 diff --git a/src/ft_draw_sprite.c b/src/ft_draw_sprite.c index 5c0fe41..7f4e913 100644 --- a/src/ft_draw_sprite.c +++ b/src/ft_draw_sprite.c @@ -39,8 +39,9 @@ static void void ft_sort_sprites(t_cub *cl, int16_t it, int16_t jt) { - float dist_tab[8][4096]; + float **dist_tab; + ft_alloc_dist_tab(&dist_tab, cl); while (++jt < cl->mlist.sprite_var) { while (++it < cl->mlist.sprite_nbr[jt]) diff --git a/src/ft_sort_s_t.c b/src/ft_sort_s_t.c index 24ed358..6af1d43 100644 --- a/src/ft_sort_s_t.c +++ b/src/ft_sort_s_t.c @@ -12,10 +12,27 @@ #include <libft.h> #include <cub3d.h> +#include <stdlib.h> #include <stdint.h> +void + ft_alloc_dist_tab(float ***dist_tab, t_cub *cl) +{ + uint16_t i; + + if (!(*dist_tab = (float **)malloc(8 * sizeof(float*)))) + ft_error(FT_RET_ALLOC_ERR, FT_ERR_ALLOCATE, cl); + i = 0; + while (i < 8) + { + if (!((*dist_tab)[i] = (float *)malloc(4096 * sizeof(float)))) + ft_error(FT_RET_ALLOC_ERR, FT_ERR_ALLOCATE, cl); + i++; + } +} + static void - ft_init_st(uint16_t sprite_var, int32_t st_o[8]) + ft_init_st(uint16_t sprite_var, int32_t *st_o) { int8_t i; @@ -25,16 +42,17 @@ static void } void - ft_sort_s_t(t_cub *cl, float dist_tab[8][4096]) + ft_sort_s_t(t_cub *cl, float **dist_tab) { - int16_t i; + int16_t i; int32_t tmp; float tmp_i[4096]; i = -1; ft_init_st(cl->mlist.sprite_var, cl->mlist.st_o); while (++i < cl->mlist.sprite_var) - if (dist_tab[i][0] < dist_tab[i + 1][0]) + { + if (i < 7 && dist_tab[i][0] < dist_tab[i + 1][0]) { tmp = cl->mlist.st_o[i]; cl->mlist.st_o[i] = cl->mlist.st_o[i + 1]; @@ -44,4 +62,9 @@ void ft_memcpy(dist_tab[i + 1], tmp_i, 4096); i = -1; } + } + i = -1; + while (++i < 8) + ft_memdel((void*)&dist_tab[i]); + ft_memdel((void*)&dist_tab); } |