diff options
Diffstat (limited to 'src/ft_draw_sprite.c')
-rw-r--r-- | src/ft_draw_sprite.c | 68 |
1 files changed, 32 insertions, 36 deletions
diff --git a/src/ft_draw_sprite.c b/src/ft_draw_sprite.c index 5c0fe41..e41484e 100644 --- a/src/ft_draw_sprite.c +++ b/src/ft_draw_sprite.c @@ -16,51 +16,47 @@ #include <stdlib.h> #include <math.h> -static void - ft_sort_sprites_norme(float *dist_tab, int16_t *i, uint16_t j, t_cub *cl) +static float + **ft_alloc_dist_tab(void) { - uint32_t tmp; - uint32_t it; + uint16_t i; + float **dist_tab; - it = *i; - tmp = 0; - if (dist_tab[it] < dist_tab[it + 1]) + if (!(dist_tab = (float **)ft_calloc((FT_TOTAL_SPRT + 1), sizeof(float*)))) + return (NULL); + i = 0; + while (i < FT_TOTAL_SPRT + 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; - *i = -1; + if (!(dist_tab[i] = (float *)ft_calloc(4096, sizeof(float)))) + return (NULL); + i++; } + return (dist_tab); } void ft_sort_sprites(t_cub *cl, int16_t it, int16_t jt) { - float dist_tab[8][4096]; + float **dist_tab; - while (++jt < cl->mlist.sprite_var) + if (!(dist_tab = ft_alloc_dist_tab())) + ft_alloc_error(cl); + while (++jt < FT_TOTAL_SPRT) { - while (++it < cl->mlist.sprite_nbr[jt]) + if (cl->mlist.sprite_nbr[jt] == 0) + dist_tab[jt][0] = 0; + else { - 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; + while (++it < cl->mlist.sprite_nbr[jt]) + { + 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)); + } + it = -1; } - it = -1; - } - it = -1; - jt = -1; - while (++jt < cl->mlist.sprite_var) - { - while (++it < cl->mlist.sprite_nbr[jt] - 1) - ft_sort_sprites_norme(dist_tab[jt], &it, jt, cl); - it = -1; } ft_sort_s_t(cl, dist_tab); } @@ -75,11 +71,11 @@ static void + powf(cl->plist.pos_y - sprite->s_pos_y, 2))) <= 0) dist = 0.0001; rgb.r = (uint8_t)cl->tlist[sprite->current_sprite].ptr[sprite->tex_x - * 4 + 4 * cl->tlist[sprite->current_sprite].img_h * sprite->tex_y + 2]; + * 4 + 4 * cl->tlist[sprite->current_sprite].img_w * sprite->tex_y + 2]; rgb.g = (uint8_t)cl->tlist[sprite->current_sprite].ptr[sprite->tex_x - * 4 + 4 * cl->tlist[sprite->current_sprite].img_h * sprite->tex_y + 1]; + * 4 + 4 * cl->tlist[sprite->current_sprite].img_w * sprite->tex_y + 1]; rgb.b = (uint8_t)cl->tlist[sprite->current_sprite].ptr[sprite->tex_x - * 4 + 4 * cl->tlist[sprite->current_sprite].img_h * sprite->tex_y]; + * 4 + 4 * cl->tlist[sprite->current_sprite].img_w * sprite->tex_y]; *(int*)(cl->img.ptr + ((uint16_t)sprite->x * 4 + (sprite->y * cl->img.sizeline))) = ft_rgb_to_hex(dist, rgb, cl); } @@ -104,7 +100,7 @@ void sprite->spriteheight) / 128; if (sprite->transformy > 0 && cl->tlist[sprite->current_sprite].ptr[sprite->tex_x * 4 + 4 * - cl->tlist[sprite->current_sprite].img_h * sprite->tex_y] + cl->tlist[sprite->current_sprite].img_w * sprite->tex_y] && cl->rlist.wall_dist_tab[sprite->x] > sprite->transformy) ft_put_sprite(sprite, cl); sprite->y++; |