diff options
author | salaaad2 <arthudurant263@gmail.com> | 2020-03-16 18:57:40 +0100 |
---|---|---|
committer | salaaad2 <arthudurant263@gmail.com> | 2020-03-16 18:57:40 +0100 |
commit | 575990647d8ee677ff9515ecb0c17da9fe66312f (patch) | |
tree | 786ae284e2d9a22499d1ac013b2b0377df9bfe23 /src | |
parent | Suppressed most valgrind errors, one remaining (diff) | |
download | 42-cub3d-575990647d8ee677ff9515ecb0c17da9fe66312f.tar.gz 42-cub3d-575990647d8ee677ff9515ecb0c17da9fe66312f.tar.bz2 42-cub3d-575990647d8ee677ff9515ecb0c17da9fe66312f.tar.xz 42-cub3d-575990647d8ee677ff9515ecb0c17da9fe66312f.tar.zst 42-cub3d-575990647d8ee677ff9515ecb0c17da9fe66312f.zip |
fatfingered solution to the sprites problem, changes needed
Diffstat (limited to 'src')
-rw-r--r-- | src/ft_draw_sprite.c | 60 | ||||
-rw-r--r-- | src/ft_draw_sprite_extra.c | 3 |
2 files changed, 41 insertions, 22 deletions
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 <libft.h> #include <cub3d.h> #include <stdint.h> +#include <stdio.h> #include <stdlib.h> #include <math.h> -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 diff --git a/src/ft_draw_sprite_extra.c b/src/ft_draw_sprite_extra.c index 2545ec0..696bdff 100644 --- a/src/ft_draw_sprite_extra.c +++ b/src/ft_draw_sprite_extra.c @@ -63,11 +63,12 @@ void i = 0; j = 0; + ft_sort_sprites(cl); while (j < cl->mlist.sprite_var) { while (i < cl->mlist.sprite_nbr) { - sprite = cl->sprites[j][i]; + sprite = cl->sprites[j][cl->mlist.sprite_order[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); |