From 8ca4c9563629c60122ba998ad64ad2d999d0902a Mon Sep 17 00:00:00 2001 From: salaaad2 Date: Mon, 16 Mar 2020 19:14:11 +0100 Subject: it just works (unpeu) --- src/ft_draw_sprite.c | 90 +++++++++++++++++++--------------------------- src/ft_draw_sprite_extra.c | 2 +- 2 files changed, 38 insertions(+), 54 deletions(-) (limited to 'src') diff --git a/src/ft_draw_sprite.c b/src/ft_draw_sprite.c index ca38fcd..c4e305e 100644 --- a/src/ft_draw_sprite.c +++ b/src/ft_draw_sprite.c @@ -17,69 +17,53 @@ #include #include -/* static void */ -/* ft_sort_sprites_norme(float *dist_tab, int32_t *i, t_cub *cl) */ -/* { */ -/* uint32_t tmp; */ -/* uint32_t it; */ +static void + ft_sort_sprites_norme(float *dist_tab, uint16_t *i, uint16_t j, t_cub *cl) +{ + uint32_t tmp; + uint32_t it; -/* it = *i; */ -/* tmp = 0; */ -/* if (dist_tab[it] > dist_tab[it + 1]) */ -/* { */ -/* puts("qwe"); */ -/* tmp = dist_tab[it]; */ -/* dist_tab[it] = dist_tab[it + 1]; */ -/* dist_tab[it + 1] = tmp; */ -/* tmp = cl->mlist.sprite_order[it]; */ -/* cl->mlist.sprite_order[it] = cl->mlist.sprite_order[it + 1]; */ -/* cl->mlist.sprite_order[it + 1] = tmp; */ -/* it = 0; */ -/* } */ -/* } */ + it = *i; + tmp = 0; + if (dist_tab[it] < dist_tab[it + 1]) + { + tmp = dist_tab[it]; + dist_tab[it] = dist_tab[it + 1]; + dist_tab[it + 1] = tmp; + tmp = cl->mlist.sprite_order[j][it]; + cl->mlist.sprite_order[j][it] = cl->mlist.sprite_order[j][it + 1]; + cl->mlist.sprite_order[j][it + 1] = tmp; + it = 0; + } +} void ft_sort_sprites(t_cub *cl) { - float dist_tab[4096]; - int32_t it; - int32_t jt; - int32_t tmp; + float dist_tab[8][4096]; + uint16_t it; + uint16_t jt; - it = 0; - jt = 0; - while (jt < cl->mlist.sprite_var) + it = -1; + jt = -1; + while (++jt < cl->mlist.sprite_var) { - while (it < cl->mlist.sprite_nbr) + while (++it < cl->mlist.sprite_nbr) { - dist_tab[it] = - ((cl->plist.pos_x - cl->sprites[0][it].s_pos_x) * - (cl->plist.pos_x - cl->sprites[0][it].s_pos_x) + - (cl->plist.pos_y - cl->sprites[0][it].s_pos_y) * - (cl->plist.pos_y - cl->sprites[0][it].s_pos_y)); - cl->mlist.sprite_order[it] = it; - it++; + 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 = 0; - jt++; - } - it = 0; - while (it < cl->mlist.sprite_nbr) - { - if (dist_tab[it] < dist_tab[it + 1]) - { - tmp = dist_tab[it]; - dist_tab[it] = dist_tab[it + 1]; - dist_tab[it + 1] = tmp; - tmp = cl->mlist.sprite_order[it]; - cl->mlist.sprite_order[it] = cl->mlist.sprite_order[it + 1]; - cl->mlist.sprite_order[it + 1] = tmp; - it = 0; - } - it++; + it = -1; } - for (int i = 0; i < 4; i++) - printf("%d\n", cl->mlist.sprite_order[i]); + it = -1; + jt = -1; + while (++jt < cl->mlist.sprite_var) + while (++it < cl->mlist.sprite_nbr) + ft_sort_sprites_norme(dist_tab[jt], &it, jt, cl); } static void diff --git a/src/ft_draw_sprite_extra.c b/src/ft_draw_sprite_extra.c index 696bdff..25c9c7a 100644 --- a/src/ft_draw_sprite_extra.c +++ b/src/ft_draw_sprite_extra.c @@ -68,7 +68,7 @@ void { while (i < cl->mlist.sprite_nbr) { - sprite = cl->sprites[j][cl->mlist.sprite_order[i]]; + sprite = cl->sprites[j][cl->mlist.sprite_order[j][i]]; sprite.current_sprite = (j == 0) ? 4 : j + 7; sprite.spritey = sprite.s_pos_x - (cl->plist.pos_x - 0.5); sprite.spritex = sprite.s_pos_y - (cl->plist.pos_y - 0.5); -- cgit v1.2.3