diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-27 15:07:32 +0100 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-27 15:07:32 +0100 |
commit | a713e118950f62700a43d21aa33fd2e3d7673af9 (patch) | |
tree | 6ee55630bb28d6626823ad819c62195a9c2bbb5a /src/ft_sort_s_t.c | |
parent | In progress (diff) | |
download | 42-cub3d-a713e118950f62700a43d21aa33fd2e3d7673af9.tar.gz 42-cub3d-a713e118950f62700a43d21aa33fd2e3d7673af9.tar.bz2 42-cub3d-a713e118950f62700a43d21aa33fd2e3d7673af9.tar.xz 42-cub3d-a713e118950f62700a43d21aa33fd2e3d7673af9.tar.zst 42-cub3d-a713e118950f62700a43d21aa33fd2e3d7673af9.zip |
Problem
Diffstat (limited to 'src/ft_sort_s_t.c')
-rw-r--r-- | src/ft_sort_s_t.c | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/src/ft_sort_s_t.c b/src/ft_sort_s_t.c index 6c08882..9cbde8b 100644 --- a/src/ft_sort_s_t.c +++ b/src/ft_sort_s_t.c @@ -21,10 +21,10 @@ float uint16_t i; float **dist_tab; - if (!(dist_tab = (float **)malloc(8 * sizeof(float*)))) + if (!(dist_tab = (float **)malloc((FT_TOTAL_SPRT + 1) * sizeof(float*)))) return (NULL); i = 0; - while (i < 8) + while (i < FT_TOTAL_SPRT + 1) { if (!(dist_tab[i] = (float *)malloc(4096 * sizeof(float)))) return (NULL); @@ -34,13 +34,26 @@ float } static void - ft_init_st(uint16_t sprite_var, int32_t *st_o) + ft_init_st(int32_t *st_o) { int8_t i; - i = -1; - while (++i < sprite_var) + i = 0; + while (i < FT_TOTAL_SPRT) + { st_o[i] = i; + i++; + } +} + +static void + ft_swap_them(int16_t i, float **dist_tab) +{ + float tmp_i[4096]; + + ft_memcpy(tmp_i, dist_tab[i], 4096); + ft_memcpy(dist_tab[i], dist_tab[i + 1], 4096); + ft_memcpy(dist_tab[i + 1], tmp_i, 4096); } void @@ -48,25 +61,23 @@ void { 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) + ft_init_st(cl->mlist.st_o); + while (++i < FT_TOTAL_SPRT) { - if (i < 7 && dist_tab[i][0] < dist_tab[i + 1][0]) + if (i < FT_TOTAL_SPRT && dist_tab[i][0] + && 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]; cl->mlist.st_o[i + 1] = tmp; - ft_memcpy(tmp_i, dist_tab[i], 4096); - ft_memcpy(dist_tab[i], dist_tab[i + 1], 4096); - ft_memcpy(dist_tab[i + 1], tmp_i, 4096); + ft_swap_them(i, dist_tab); i = -1; } } i = -1; - while (++i < 8) + while (++i < FT_TOTAL_SPRT + 1) ft_memdel((void*)&dist_tab[i]); ft_memdel((void*)&dist_tab); } |