/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* 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 #include float **ft_alloc_dist_tab(void) { uint16_t i; float **dist_tab; if (!(dist_tab = (float **)malloc((FT_TOTAL_SPRT + 1) * sizeof(float*)))) return (NULL); i = 0; while (i < FT_TOTAL_SPRT + 1) { if (!(dist_tab[i] = (float *)malloc(4096 * sizeof(float)))) return (NULL); i++; } return (dist_tab); } static void ft_init_st(t_cub *cl, int32_t *st_o, float **dist_tab) { int8_t i; int8_t j; j = 0; i = -1; while (++i < FT_TOTAL_SPRT) st_o[i] = -1; i = -1; while (++i < FT_TOTAL_SPRT) { if (cl->sprites[i][0].exists == 1) { st_o[j] = i; ft_memcpy(dist_tab[j], dist_tab[i], 4096); j++; } } } static void ft_swap_them(int16_t i, float **dist_tab) { float tmp_i[4096]; ft_bzero(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 ft_sort_s_t(t_cub *cl, float **dist_tab) { int16_t i; int32_t tmp; i = -1; ft_init_st(cl, cl->mlist.st_o, dist_tab); while (++i < FT_TOTAL_SPRT) { if (cl->mlist.st_o[i] != -1 && 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_swap_them(i, dist_tab); i = -1; } } i = -1; while (++i < FT_TOTAL_SPRT + 1) ft_memdel((void*)&dist_tab[i]); ft_memdel((void*)&dist_tab); }