From 94c06bc705b8598eb9ce30514f14f583f2538de8 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Wed, 25 Mar 2020 19:27:47 +0100 Subject: Solved segfault, fuck stack --- src/ft_draw_sprite.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/ft_draw_sprite.c') diff --git a/src/ft_draw_sprite.c b/src/ft_draw_sprite.c index 5c0fe41..7f4e913 100644 --- a/src/ft_draw_sprite.c +++ b/src/ft_draw_sprite.c @@ -39,8 +39,9 @@ static void void ft_sort_sprites(t_cub *cl, int16_t it, int16_t jt) { - float dist_tab[8][4096]; + float **dist_tab; + ft_alloc_dist_tab(&dist_tab, cl); while (++jt < cl->mlist.sprite_var) { while (++it < cl->mlist.sprite_nbr[jt]) -- cgit v1.2.3 From fe2d41368dce9f3594aee2491a36841a88a6a28d Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Thu, 26 Mar 2020 13:24:41 +0100 Subject: wqe --- src/ft_draw_sprite.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/ft_draw_sprite.c') diff --git a/src/ft_draw_sprite.c b/src/ft_draw_sprite.c index 7f4e913..0c5a8b2 100644 --- a/src/ft_draw_sprite.c +++ b/src/ft_draw_sprite.c @@ -51,7 +51,6 @@ void (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; } it = -1; } -- cgit v1.2.3 From d29165bbb95aef86aeb9d9d9668d035b4430769f Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Thu, 26 Mar 2020 14:15:26 +0100 Subject: Cool malloc --- src/ft_draw_sprite.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/ft_draw_sprite.c') diff --git a/src/ft_draw_sprite.c b/src/ft_draw_sprite.c index 0c5a8b2..423080d 100644 --- a/src/ft_draw_sprite.c +++ b/src/ft_draw_sprite.c @@ -41,7 +41,8 @@ void { float **dist_tab; - ft_alloc_dist_tab(&dist_tab, cl); + if (!(dist_tab = ft_alloc_dist_tab())) + ft_error(FT_RET_ALLOC_ERR, FT_ERR_ALLOCATE, cl); while (++jt < cl->mlist.sprite_var) { while (++it < cl->mlist.sprite_nbr[jt]) -- cgit v1.2.3 From 9967f9792bf4c828dd805a8e65cf20aabcf05f31 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Thu, 26 Mar 2020 14:33:15 +0100 Subject: important bug fix --- src/ft_draw_sprite.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/ft_draw_sprite.c') diff --git a/src/ft_draw_sprite.c b/src/ft_draw_sprite.c index 423080d..19ceb9f 100644 --- a/src/ft_draw_sprite.c +++ b/src/ft_draw_sprite.c @@ -52,6 +52,7 @@ void (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; } it = -1; } -- cgit v1.2.3 From b5982b835d46ba6ae7363b60254ebfa2c3439a4d Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Thu, 26 Mar 2020 14:58:02 +0100 Subject: Solved 9th sprite problem --- src/ft_draw_sprite.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/ft_draw_sprite.c') diff --git a/src/ft_draw_sprite.c b/src/ft_draw_sprite.c index 19ceb9f..615bbd3 100644 --- a/src/ft_draw_sprite.c +++ b/src/ft_draw_sprite.c @@ -56,13 +56,12 @@ void } it = -1; } - it = -1; jt = -1; while (++jt < cl->mlist.sprite_var) { + it = -1; 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); } -- cgit v1.2.3 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 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/ft_draw_sprite.c') 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) -- cgit v1.2.3 From 44d5f7f4da8465f4829de1232e4cf2c6c2bf76bc Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Fri, 27 Mar 2020 16:44:30 +0100 Subject: Segv fix --- src/ft_draw_sprite.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/ft_draw_sprite.c') diff --git a/src/ft_draw_sprite.c b/src/ft_draw_sprite.c index 2aa1b43..1b3f912 100644 --- a/src/ft_draw_sprite.c +++ b/src/ft_draw_sprite.c @@ -76,11 +76,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); } @@ -105,7 +105,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++; -- cgit v1.2.3 From 76cefdc4dc3efa6eb410574a0f5ec42188ba11bd Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Sun, 29 Mar 2020 15:42:37 +0200 Subject: Almost --- src/ft_draw_sprite.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/ft_draw_sprite.c') diff --git a/src/ft_draw_sprite.c b/src/ft_draw_sprite.c index 1b3f912..dc6f54f 100644 --- a/src/ft_draw_sprite.c +++ b/src/ft_draw_sprite.c @@ -42,7 +42,7 @@ void float **dist_tab; if (!(dist_tab = ft_alloc_dist_tab())) - ft_error(FT_RET_ALLOC_ERR, FT_ERR_ALLOCATE, cl); + ft_alloc_error(cl); while (++jt < FT_TOTAL_SPRT) { while (++it < cl->mlist.sprite_nbr[jt]) -- cgit v1.2.3 From fe29469eee3a78905e05ab95ea20e1c9ed7045fe Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Sun, 29 Mar 2020 16:05:58 +0200 Subject: I must be close --- src/ft_draw_sprite.c | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) (limited to 'src/ft_draw_sprite.c') diff --git a/src/ft_draw_sprite.c b/src/ft_draw_sprite.c index dc6f54f..fcc2a8b 100644 --- a/src/ft_draw_sprite.c +++ b/src/ft_draw_sprite.c @@ -16,25 +16,25 @@ #include #include -static void - ft_sort_sprites_norme(float *dist_tab, int16_t *i, uint16_t j, t_cub *cl) -{ - uint32_t tmp; - uint32_t it; +/* static void */ +/* ft_sort_sprites_norme(float *dist_tab, int16_t *i, uint16_t j, t_cub *cl) */ +/* { */ +/* uint32_t tmp; */ +/* uint32_t it; */ - it = *i; - tmp = 0; - if (dist_tab[it] < dist_tab[it + 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; - } -} +/* it = *i; */ +/* tmp = 0; */ +/* if (dist_tab[it] < dist_tab[it + 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; */ +/* } */ +/* } */ void ft_sort_sprites(t_cub *cl, int16_t it, int16_t jt) @@ -52,17 +52,17 @@ void (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; + /* cl->mlist.sprite_order[jt][it] = it; */ } it = -1; } - jt = -1; - while (++jt < FT_TOTAL_SPRT) - { - it = -1; - while (++it < cl->mlist.sprite_nbr[jt] - 1) - ft_sort_sprites_norme(dist_tab[jt], &it, jt, cl); - } + /* jt = -1; */ + /* while (++jt < FT_TOTAL_SPRT) */ + /* { */ + /* it = -1; */ + /* while (++it < cl->mlist.sprite_nbr[jt] - 1) */ + /* ft_sort_sprites_norme(dist_tab[jt], &it, jt, cl); */ + /* } */ ft_sort_s_t(cl, dist_tab); } -- cgit v1.2.3 From 1d0be73de37e2b60ecc7babbbdf385e24e86dfee Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Sun, 29 Mar 2020 17:07:09 +0200 Subject: litteral god --- src/ft_draw_sprite.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'src/ft_draw_sprite.c') diff --git a/src/ft_draw_sprite.c b/src/ft_draw_sprite.c index fcc2a8b..41daec4 100644 --- a/src/ft_draw_sprite.c +++ b/src/ft_draw_sprite.c @@ -45,16 +45,21 @@ void 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)); + /* cl->mlist.sprite_order[jt][it] = it; */ + } + it = -1; } - it = -1; } /* jt = -1; */ /* while (++jt < FT_TOTAL_SPRT) */ -- cgit v1.2.3 From 69ca60b6f989dedc94c2e25ab9927b26d63cbdf8 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Sun, 29 Mar 2020 17:34:48 +0200 Subject: Norm --- src/ft_draw_sprite.c | 42 ++++++++++++++++-------------------------- 1 file changed, 16 insertions(+), 26 deletions(-) (limited to 'src/ft_draw_sprite.c') diff --git a/src/ft_draw_sprite.c b/src/ft_draw_sprite.c index 41daec4..e41484e 100644 --- a/src/ft_draw_sprite.c +++ b/src/ft_draw_sprite.c @@ -16,25 +16,23 @@ #include #include -/* static void */ -/* ft_sort_sprites_norme(float *dist_tab, int16_t *i, uint16_t j, t_cub *cl) */ -/* { */ -/* uint32_t tmp; */ -/* uint32_t it; */ +static float + **ft_alloc_dist_tab(void) +{ + uint16_t i; + float **dist_tab; -/* it = *i; */ -/* tmp = 0; */ -/* if (dist_tab[it] < dist_tab[it + 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 = (float **)ft_calloc((FT_TOTAL_SPRT + 1), sizeof(float*)))) + return (NULL); + i = 0; + while (i < FT_TOTAL_SPRT + 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) @@ -56,18 +54,10 @@ void (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; */ } it = -1; } } - /* jt = -1; */ - /* while (++jt < FT_TOTAL_SPRT) */ - /* { */ - /* it = -1; */ - /* while (++it < cl->mlist.sprite_nbr[jt] - 1) */ - /* ft_sort_sprites_norme(dist_tab[jt], &it, jt, cl); */ - /* } */ ft_sort_s_t(cl, dist_tab); } -- cgit v1.2.3