/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_sort_s_t.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rbousset +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/24 20:22:45 by rbousset #+# #+# */ /* Updated: 2020/03/09 18:56:01 by rbousset ### ########lyon.fr */ /* */ /* ************************************************************************** */ #include #include #include 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); else if (st_o == 9) return (17); else if (st_o >= 10 && st_o <= 12) return (st_o + 8); else if (st_o == 13) return (23); return (0); } void ft_alloc_big_t(t_cub *cl) { int32_t i; if (!(cl->big_t = (float**)malloc((cl->big_t_val) * sizeof(float*)))) { ft_alloc_error(cl); } i = 0; while (i < cl->big_t_val) { if (!(cl->big_t[i] = (float*)malloc(4 * sizeof(float)))) { ft_alloc_error(cl); } i++; } } void ft_fill_big_t(float **dist_tab, t_cub *cl) { int32_t i; int32_t j; int32_t k; i = 0; j = 0; k = 0; while (i < cl->big_t_val) { if (dist_tab[j][k]) { cl->big_t[i][0] = dist_tab[j][k]; cl->big_t[i][1] = (float)ft_set_current_sprite(cl, j); cl->big_t[i][1] += (j == 13) ? (cl->bad_boy[k].does) : (0); cl->big_t[i][2] = (float)j; cl->big_t[i][3] = (float)k; k++; i++; } else { k = 0; j++; } } } void ft_sort_big_t(t_cub *cl) { int32_t i; int8_t j; float tmp[4]; i = 0; while (i < cl->big_t_val - 1) { if (cl->big_t[i][0] < cl->big_t[i + 1][0]) { j = -1; while (++j < 4) { tmp[j] = cl->big_t[i][j]; cl->big_t[i][j] = cl->big_t[i + 1][j]; cl->big_t[i + 1][j] = tmp[j]; } i = -1; } i++; } }