diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ft_draw_sprite.c | 5 | ||||
-rw-r--r-- | src/ft_draw_sprite_extra.c | 18 | ||||
-rw-r--r-- | src/ft_init_map.c | 1 | ||||
-rw-r--r-- | src/ft_sort_s_t.c | 47 |
4 files changed, 60 insertions, 11 deletions
diff --git a/src/ft_draw_sprite.c b/src/ft_draw_sprite.c index b381957..5c0fe41 100644 --- a/src/ft_draw_sprite.c +++ b/src/ft_draw_sprite.c @@ -41,9 +41,9 @@ void { float dist_tab[8][4096]; - while (++jt <= cl->mlist.sprite_var) + while (++jt < cl->mlist.sprite_var) { - while (++it <= cl->mlist.sprite_nbr[jt]) + while (++it < cl->mlist.sprite_nbr[jt]) { dist_tab[jt][it] = ((cl->plist.pos_x - cl->sprites[jt][it].s_pos_x) * @@ -62,6 +62,7 @@ void ft_sort_sprites_norme(dist_tab[jt], &it, jt, cl); it = -1; } + ft_sort_s_t(cl, dist_tab); } static void diff --git a/src/ft_draw_sprite_extra.c b/src/ft_draw_sprite_extra.c index 323906a..0830d2c 100644 --- a/src/ft_draw_sprite_extra.c +++ b/src/ft_draw_sprite_extra.c @@ -54,23 +54,23 @@ void int32_t i; int32_t j; - i = 0; - j = 0; + i = -1; + j = -1; ft_sort_sprites(cl, -1, -1); - while (j < cl->mlist.sprite_var) + while (++j < cl->mlist.sprite_var) { - while (i < cl->mlist.sprite_nbr[j]) + while (++i < cl->mlist.sprite_nbr[j]) { - sprite = cl->sprites[j][cl->mlist.sprite_order[j][i]]; - sprite.current_sprite = (j == 0) ? 4 : j + 7; + sprite = cl->sprites[cl->mlist.st_o[j]][cl->mlist.sprite_order[cl->mlist + .st_o[j]][i]]; + sprite.current_sprite = (cl->mlist.st_o[j] == 0) ? + 4 : cl->mlist.st_o[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); ft_init_sprite(cl, &sprite); ft_sprite_h_w(cl, &sprite); ft_draw_sprite(cl, &sprite); - i++; } - i = 0; - j++; + i = -1; } } diff --git a/src/ft_init_map.c b/src/ft_init_map.c index 9ddbb47..d252f2e 100644 --- a/src/ft_init_map.c +++ b/src/ft_init_map.c @@ -66,6 +66,7 @@ int8_t mlist->topsp = 0; ft_bzero(mlist->sprite_nbr, 4096); ft_bzero(mlist->sprite_order, 4096); + ft_bzero(mlist->st_o, 4096); ft_bzero(mlist->traps_order, 512); ft_bzero(mlist->heals_order, 64); mlist->weaps_nbr[0] = 0; diff --git a/src/ft_sort_s_t.c b/src/ft_sort_s_t.c new file mode 100644 index 0000000..24ed358 --- /dev/null +++ b/src/ft_sort_s_t.c @@ -0,0 +1,47 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_sort_s_t.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/24 20:22:45 by rbousset #+# #+# */ +/* Updated: 2020/03/09 18:56:01 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include <libft.h> +#include <cub3d.h> +#include <stdint.h> + +static void + ft_init_st(uint16_t sprite_var, int32_t st_o[8]) +{ + int8_t i; + + i = -1; + while (++i < sprite_var) + st_o[i] = i; +} + +void + ft_sort_s_t(t_cub *cl, float dist_tab[8][4096]) +{ + 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) + if (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); + i = -1; + } +} |