diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-29 17:07:09 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-29 17:07:09 +0200 |
commit | 1d0be73de37e2b60ecc7babbbdf385e24e86dfee (patch) | |
tree | c6808d08c59fe574aa66b21a3c9d6439e94516f4 /src/ft_sort_s_t.c | |
parent | I must be close (diff) | |
download | 42-cub3d-1d0be73de37e2b60ecc7babbbdf385e24e86dfee.tar.gz 42-cub3d-1d0be73de37e2b60ecc7babbbdf385e24e86dfee.tar.bz2 42-cub3d-1d0be73de37e2b60ecc7babbbdf385e24e86dfee.tar.xz 42-cub3d-1d0be73de37e2b60ecc7babbbdf385e24e86dfee.tar.zst 42-cub3d-1d0be73de37e2b60ecc7babbbdf385e24e86dfee.zip |
litteral god
Diffstat (limited to 'src/ft_sort_s_t.c')
-rw-r--r-- | src/ft_sort_s_t.c | 79 |
1 files changed, 56 insertions, 23 deletions
diff --git a/src/ft_sort_s_t.c b/src/ft_sort_s_t.c index f51437e..00627e5 100644 --- a/src/ft_sort_s_t.c +++ b/src/ft_sort_s_t.c @@ -52,22 +52,35 @@ static int8_t } static void - ft_alloc_and_fill_big_t(float **dist_tab, t_cub *cl) + ft_alloc_big_t(t_cub *cl) { int32_t i; - int32_t j; - int32_t k; - if (!(cl->big_t = (float**)malloc(cl->big_t_val * sizeof(float*)))) + if (!(cl->big_t = (float**)malloc((cl->big_t_val) * sizeof(float*)))) + { ft_alloc_error(cl); - i = -1; - while (++i < cl->big_t_val) + } + i = 0; + while (i < cl->big_t_val) + { if (!(cl->big_t[i] = (float*)malloc(4 * sizeof(float)))) + { ft_alloc_error(cl); + } + i++; + } +} + +static void + ft_fill_big_t(float **dist_tab, t_cub *cl) +{ + int32_t i; + int32_t j; + int32_t k; + i = 0; j = 0; k = 0; - ft_printf("%d %d %d %d %d %d %d %d\n", (int32_t)dist_tab[8][0], (int32_t)dist_tab[8][1], (int32_t)dist_tab[8][2], (int32_t)dist_tab[8][3], (int32_t)dist_tab[8][4], (int32_t)dist_tab[8][5], (int32_t)dist_tab[8][6], (int32_t)dist_tab[8][7]); while (i < cl->big_t_val) { if (dist_tab[j][k]) @@ -77,35 +90,53 @@ static void cl->big_t[i][2] = (float)j; cl->big_t[i][3] = (float)k; k++; + i++; } else { k = 0; j++; } - i++; } } static void - ft_init_st(t_cub *cl, int32_t *st_o, float **dist_tab) + ft_sort_big_t(t_cub *cl) { - int8_t i; - int8_t j; + int32_t i; + int8_t j; + float tmp[4]; - j = -1; - i = -1; - (void)dist_tab; - while (++i < FT_TOTAL_SPRT) - st_o[i] = -1; - i = -1; - while (++i < FT_TOTAL_SPRT) + i = 0; + while (i < cl->big_t_val - 1) { - if (cl->mlist.sprite_nbr[i] > 0) + if (cl->big_t[i][0] < cl->big_t[i + 1][0]) { - st_o[++j] = i; - /* ft_memcpy(dist_tab[j], dist_tab[i], 4096 * sizeof(float)); */ + j = -1; + while (++j < 4) + tmp[j] = cl->big_t[i][j]; + j = -1; + while (++j < 4) + cl->big_t[i][j] = cl->big_t[i + 1][j]; + j = -1; + while (++j < 4) + cl->big_t[i + 1][j] = tmp[j]; + i = -1; } + i++; + } +} + +static void + ft_init_st(int32_t *st_o) +{ + int8_t i; + + i = 0; + while (i < FT_TOTAL_SPRT) + { + st_o[i] = i; + i++; } } @@ -114,7 +145,7 @@ void { int32_t i; - ft_init_st(cl, cl->mlist.st_o, dist_tab); + ft_init_st(cl->mlist.st_o); i = -1; while (++i < cl->big_t_val) ft_memdel((void*)&cl->big_t[i]); @@ -123,7 +154,9 @@ void cl->big_t_val = 0; while (++i < FT_TOTAL_SPRT) cl->big_t_val += cl->mlist.sprite_nbr[i]; - ft_alloc_and_fill_big_t(dist_tab, cl); + ft_alloc_big_t(cl); + ft_fill_big_t(dist_tab, cl); + ft_sort_big_t(cl); i = -1; while (++i < FT_TOTAL_SPRT + 1) ft_memdel((void*)&dist_tab[i]); |