diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ft_draw_sprite.c | 3 | ||||
-rw-r--r-- | src/ft_sort_s_t.c | 31 |
2 files changed, 29 insertions, 5 deletions
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); } |