From 575990647d8ee677ff9515ecb0c17da9fe66312f Mon Sep 17 00:00:00 2001 From: salaaad2 Date: Mon, 16 Mar 2020 18:57:40 +0100 Subject: fatfingered solution to the sprites problem, changes needed --- src/ft_draw_sprite.c | 60 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 21 deletions(-) (limited to 'src/ft_draw_sprite.c') diff --git a/src/ft_draw_sprite.c b/src/ft_draw_sprite.c index 73f277a..ca38fcd 100644 --- a/src/ft_draw_sprite.c +++ b/src/ft_draw_sprite.c @@ -13,26 +13,30 @@ #include #include #include +#include #include #include -static void - ft_sort_sprites_norme(float *dist_tab, int32_t it, t_cub *cl) -{ - uint32_t tmp; +/* static void */ +/* ft_sort_sprites_norme(float *dist_tab, int32_t *i, t_cub *cl) */ +/* { */ +/* uint32_t tmp; */ +/* uint32_t it; */ - 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[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]) */ +/* { */ +/* 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; */ +/* } */ +/* } */ void ft_sort_sprites(t_cub *cl) @@ -40,6 +44,7 @@ void float dist_tab[4096]; int32_t it; int32_t jt; + int32_t tmp; it = 0; jt = 0; @@ -47,10 +52,11 @@ void { while (it < cl->mlist.sprite_nbr) { - dist_tab[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)); + 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++; } @@ -60,8 +66,20 @@ void it = 0; while (it < cl->mlist.sprite_nbr) { - ft_sort_sprites_norme(dist_tab, it, cl); + 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++; } + for (int i = 0; i < 4; i++) + printf("%d\n", cl->mlist.sprite_order[i]); } static void -- cgit v1.2.3 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 +++++++++++++++++++++------------------------------- 1 file changed, 37 insertions(+), 53 deletions(-) (limited to 'src/ft_draw_sprite.c') 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 -- cgit v1.2.3 From 322f3191c5a76cf702d4ddd7b1122219be3f5779 Mon Sep 17 00:00:00 2001 From: salaaad2 Date: Mon, 16 Mar 2020 19:24:29 +0100 Subject: fix norme --- src/ft_draw_sprite.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/ft_draw_sprite.c') diff --git a/src/ft_draw_sprite.c b/src/ft_draw_sprite.c index c4e305e..1294738 100644 --- a/src/ft_draw_sprite.c +++ b/src/ft_draw_sprite.c @@ -23,7 +23,7 @@ static void uint32_t tmp; uint32_t it; - it = *i; + it = *i; tmp = 0; if (dist_tab[it] < dist_tab[it + 1]) { @@ -61,9 +61,9 @@ void } 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); + while (++jt < cl->mlist.sprite_var) + while (++it < cl->mlist.sprite_nbr) + ft_sort_sprites_norme(dist_tab[jt], &it, jt, cl); } static void -- cgit v1.2.3 From b4bee5505af7e0cfb3681ed9b866d51bbc3f2690 Mon Sep 17 00:00:00 2001 From: salaaad2 Date: Mon, 16 Mar 2020 19:26:15 +0100 Subject: fix norme2 --- src/ft_draw_sprite.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/ft_draw_sprite.c') diff --git a/src/ft_draw_sprite.c b/src/ft_draw_sprite.c index 1294738..a196d96 100644 --- a/src/ft_draw_sprite.c +++ b/src/ft_draw_sprite.c @@ -18,10 +18,10 @@ #include static void - ft_sort_sprites_norme(float *dist_tab, uint16_t *i, uint16_t j, t_cub *cl) + ft_sort_sprites_norme(float *dist_tab, uint16_t *i, uint16_t j, t_cub *cl) { uint32_t tmp; - uint32_t it; + uint32_t it; it = *i; tmp = 0; @@ -51,7 +51,7 @@ void while (++it < cl->mlist.sprite_nbr) { 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_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)); @@ -60,7 +60,7 @@ void it = -1; } it = -1; - jt = -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); -- cgit v1.2.3 From 96c7c712f2cffeff9a4bae604715e0edfd6f758e Mon Sep 17 00:00:00 2001 From: salaaad2 Date: Wed, 18 Mar 2020 19:10:35 +0100 Subject: cangelog, norme --- src/ft_draw_sprite.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/ft_draw_sprite.c') diff --git a/src/ft_draw_sprite.c b/src/ft_draw_sprite.c index a196d96..66d69e5 100644 --- a/src/ft_draw_sprite.c +++ b/src/ft_draw_sprite.c @@ -40,7 +40,7 @@ static void void ft_sort_sprites(t_cub *cl) { - float dist_tab[8][4096]; + float dist_tab[8][4096]; uint16_t it; uint16_t jt; -- cgit v1.2.3