diff options
-rw-r--r-- | src/ft_draw_sprite.c | 21 | ||||
-rw-r--r-- | src/ft_draw_sprite_extra.c | 1 | ||||
-rw-r--r-- | src/ft_sort_s_t.c | 79 |
3 files changed, 69 insertions, 32 deletions
diff --git a/src/ft_draw_sprite.c b/src/ft_draw_sprite.c index fcc2a8b..41daec4 100644 --- a/src/ft_draw_sprite.c +++ b/src/ft_draw_sprite.c @@ -45,16 +45,21 @@ void ft_alloc_error(cl); while (++jt < FT_TOTAL_SPRT) { - while (++it < cl->mlist.sprite_nbr[jt]) + if (cl->mlist.sprite_nbr[jt] == 0) + dist_tab[jt][0] = 0; + else { - dist_tab[jt][it] = - ((cl->plist.pos_x - cl->sprites[jt][it].s_pos_x) * - (cl->plist.pos_x - cl->sprites[jt][it].s_pos_x) + - (cl->plist.pos_y - cl->sprites[jt][it].s_pos_y) * - (cl->plist.pos_y - cl->sprites[jt][it].s_pos_y)); - /* cl->mlist.sprite_order[jt][it] = it; */ + while (++it < cl->mlist.sprite_nbr[jt]) + { + dist_tab[jt][it] = + ((cl->plist.pos_x - cl->sprites[jt][it].s_pos_x) * + (cl->plist.pos_x - cl->sprites[jt][it].s_pos_x) + + (cl->plist.pos_y - cl->sprites[jt][it].s_pos_y) * + (cl->plist.pos_y - cl->sprites[jt][it].s_pos_y)); + /* cl->mlist.sprite_order[jt][it] = it; */ + } + it = -1; } - it = -1; } /* jt = -1; */ /* while (++jt < FT_TOTAL_SPRT) */ diff --git a/src/ft_draw_sprite_extra.c b/src/ft_draw_sprite_extra.c index 598f637..ba2dac5 100644 --- a/src/ft_draw_sprite_extra.c +++ b/src/ft_draw_sprite_extra.c @@ -47,7 +47,6 @@ static void (1 + sprite->transformx / sprite->transformy); } -#include <libft.h> void ft_calc_sprite(t_cub *cl) { 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]); |