aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_sort_s_t.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ft_sort_s_t.c')
-rw-r--r--src/ft_sort_s_t.c96
1 files changed, 67 insertions, 29 deletions
diff --git a/src/ft_sort_s_t.c b/src/ft_sort_s_t.c
index 28a372d..bcf033f 100644
--- a/src/ft_sort_s_t.c
+++ b/src/ft_sort_s_t.c
@@ -33,58 +33,96 @@ float
return (dist_tab);
}
+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)
+ return (st_o + 8);
+ return (0);
+}
+
+static void
+ ft_alloc_and_fill_big_t(float **dist_tab, t_cub *cl)
+{
+ int32_t i;
+ int32_t j;
+ int32_t k;
+
+ if (!(cl->big_t = (float**)malloc(cl->big_t_val * sizeof(float*))))
+ ft_alloc_error(cl);
+ i = -1;
+ while (++i < cl->big_t_val)
+ if (!(cl->big_t[i] = (float*)malloc(4 * sizeof(float))))
+ ft_alloc_error(cl);
+ i = 0;
+ j = 0;
+ k = 0;
+ while (i < cl->big_t_val)
+ {
+ if (dist_tab[j][k])
+ {
+ ft_printf("%d\n", j);
+ 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][2] = (float)j;
+ cl->big_t[i][3] = (float)k;
+ k++;
+ }
+ else
+ {
+ k = 0;
+ j++;
+ }
+ i++;
+ }
+}
+
static void
ft_init_st(t_cub *cl, int32_t *st_o, float **dist_tab)
{
int8_t i;
int8_t j;
- j = 0;
+ j = -1;
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)
+ if (cl->mlist.sprite_nbr[i] > 0)
{
- st_o[j] = i;
- ft_memcpy(dist_tab[j], dist_tab[i], 4096);
- j++;
+ st_o[++j] = i;
+ ft_memcpy(dist_tab[j], dist_tab[i], 4096 * sizeof(float));
}
}
}
-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;
+ int32_t i;
- i = -1;
ft_init_st(cl, cl->mlist.st_o, dist_tab);
+ i = -1;
+ while (++i < cl->big_t_val)
+ ft_memdel((void*)&cl->big_t[i]);
+ ft_memdel((void*)&cl->big_t);
+ i = -1;
+ cl->big_t_val = 0;
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;
- }
- }
+ cl->big_t_val += cl->mlist.sprite_nbr[i];
+ ft_alloc_and_fill_big_t(dist_tab, cl);
i = -1;
while (++i < FT_TOTAL_SPRT + 1)
ft_memdel((void*)&dist_tab[i]);