From a713e118950f62700a43d21aa33fd2e3d7673af9 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Fri, 27 Mar 2020 15:07:32 +0100 Subject: Problem --- src/ft_draw_sprite.c | 4 ++-- src/ft_draw_sprite_extra.c | 23 ++++++++++++++++++----- src/ft_extra_keys.c | 1 - src/ft_init_map.c | 1 - src/ft_sort_s_t.c | 37 ++++++++++++++++++++++++------------- 5 files changed, 44 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/ft_draw_sprite.c b/src/ft_draw_sprite.c index 615bbd3..2aa1b43 100644 --- a/src/ft_draw_sprite.c +++ b/src/ft_draw_sprite.c @@ -43,7 +43,7 @@ void if (!(dist_tab = ft_alloc_dist_tab())) ft_error(FT_RET_ALLOC_ERR, FT_ERR_ALLOCATE, cl); - while (++jt < cl->mlist.sprite_var) + while (++jt < FT_TOTAL_SPRT) { while (++it < cl->mlist.sprite_nbr[jt]) { @@ -57,7 +57,7 @@ void it = -1; } jt = -1; - while (++jt < cl->mlist.sprite_var) + while (++jt < FT_TOTAL_SPRT) { it = -1; while (++it < cl->mlist.sprite_nbr[jt] - 1) diff --git a/src/ft_draw_sprite_extra.c b/src/ft_draw_sprite_extra.c index e592da0..5133231 100644 --- a/src/ft_draw_sprite_extra.c +++ b/src/ft_draw_sprite_extra.c @@ -47,25 +47,38 @@ static void (1 + sprite->transformx / sprite->transformy); } +static int8_t + ft_set_current_sprite(t_cub *cl, int8_t j) +{ + const int8_t st_o = cl->mlist.st_o[j]; + + if (st_o == 0) + return (4); + else if (st_o >= 1 && st_o <= 7) + return (st_o + 7); + else if (st_o == 8) + return (15); + return (0); +} + void ft_calc_sprite(t_cub *cl) { t_sprite sprite; - int32_t i; - int32_t j; + int16_t i; + int8_t j; i = -1; j = -1; ft_sort_sprites(cl, -1, -1); - while (++j < cl->mlist.sprite_var) + while (++j < FT_TOTAL_SPRT) { while (++i < cl->mlist.sprite_nbr[j]) { 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.current_sprite = ft_set_current_sprite(cl, j); 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); diff --git a/src/ft_extra_keys.c b/src/ft_extra_keys.c index f8a6db8..1a71402 100644 --- a/src/ft_extra_keys.c +++ b/src/ft_extra_keys.c @@ -12,7 +12,6 @@ #include #include -#include #include #include #include diff --git a/src/ft_init_map.c b/src/ft_init_map.c index e85c6a6..72a02fd 100644 --- a/src/ft_init_map.c +++ b/src/ft_init_map.c @@ -67,7 +67,6 @@ int8_t mlist->weapon_var = 0; mlist->topsp = 0; ft_bzero(mlist->sprite_nbr, FT_TOTAL_SPRT); - ft_bzero(mlist->sprite_order, FT_TOTAL_SPRT); i = -1; while (++i < FT_TOTAL_SPRT) ft_bzero(mlist->sprite_order[i], 4096); diff --git a/src/ft_sort_s_t.c b/src/ft_sort_s_t.c index 6c08882..9cbde8b 100644 --- a/src/ft_sort_s_t.c +++ b/src/ft_sort_s_t.c @@ -21,10 +21,10 @@ float uint16_t i; float **dist_tab; - if (!(dist_tab = (float **)malloc(8 * sizeof(float*)))) + if (!(dist_tab = (float **)malloc((FT_TOTAL_SPRT + 1) * sizeof(float*)))) return (NULL); i = 0; - while (i < 8) + while (i < FT_TOTAL_SPRT + 1) { if (!(dist_tab[i] = (float *)malloc(4096 * sizeof(float)))) return (NULL); @@ -34,13 +34,26 @@ float } static void - ft_init_st(uint16_t sprite_var, int32_t *st_o) + ft_init_st(int32_t *st_o) { int8_t i; - i = -1; - while (++i < sprite_var) + i = 0; + while (i < FT_TOTAL_SPRT) + { st_o[i] = i; + i++; + } +} + +static void + ft_swap_them(int16_t i, float **dist_tab) +{ + float tmp_i[4096]; + + 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); } void @@ -48,25 +61,23 @@ void { 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) + ft_init_st(cl->mlist.st_o); + while (++i < FT_TOTAL_SPRT) { - if (i < 7 && dist_tab[i][0] < dist_tab[i + 1][0]) + if (i < FT_TOTAL_SPRT && dist_tab[i][0] + && 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); + ft_swap_them(i, dist_tab); i = -1; } } i = -1; - while (++i < 8) + while (++i < FT_TOTAL_SPRT + 1) ft_memdel((void*)&dist_tab[i]); ft_memdel((void*)&dist_tab); } -- cgit v1.2.3