diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-27 15:07:32 +0100 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-27 15:07:32 +0100 |
commit | a713e118950f62700a43d21aa33fd2e3d7673af9 (patch) | |
tree | 6ee55630bb28d6626823ad819c62195a9c2bbb5a | |
parent | In progress (diff) | |
download | 42-cub3d-a713e118950f62700a43d21aa33fd2e3d7673af9.tar.gz 42-cub3d-a713e118950f62700a43d21aa33fd2e3d7673af9.tar.bz2 42-cub3d-a713e118950f62700a43d21aa33fd2e3d7673af9.tar.xz 42-cub3d-a713e118950f62700a43d21aa33fd2e3d7673af9.tar.zst 42-cub3d-a713e118950f62700a43d21aa33fd2e3d7673af9.zip |
Problem
-rw-r--r-- | inc/cub3d_structs.h | 2 | ||||
-rw-r--r-- | map/map_one.cub | 3 | ||||
-rw-r--r-- | src/ft_draw_sprite.c | 4 | ||||
-rw-r--r-- | src/ft_draw_sprite_extra.c | 23 | ||||
-rw-r--r-- | src/ft_extra_keys.c | 1 | ||||
-rw-r--r-- | src/ft_init_map.c | 1 | ||||
-rw-r--r-- | src/ft_sort_s_t.c | 37 |
7 files changed, 47 insertions, 24 deletions
diff --git a/inc/cub3d_structs.h b/inc/cub3d_structs.h index 836d168..ce45a92 100644 --- a/inc/cub3d_structs.h +++ b/inc/cub3d_structs.h @@ -202,7 +202,7 @@ typedef struct s_map size_t map_w; size_t map_h; size_t mapl_len; - int32_t sprite_nbr[FT_TOTAL_SPRT]; + int16_t sprite_nbr[FT_TOTAL_SPRT]; uint8_t sprite_var; uint8_t weapon_var; int32_t sprite_order[FT_TOTAL_SPRT][4096]; diff --git a/map/map_one.cub b/map/map_one.cub index dbe6894..cbc3634 100644 --- a/map/map_one.cub +++ b/map/map_one.cub @@ -11,6 +11,7 @@ F ./media/img/tex/parquet_small.xpm S ./media/img/sprites/pillar.xpm S3 ./media/img/sprites/pylon.xpm S4 ./media/img/sprites/larry.xpm +S5 ./media/img/sprites/linus.xpm T ./media/img/sprites/spikes.xpm @@ -21,7 +22,7 @@ SH 2 1000000000000000001 1000000000000000001 111111111111000000000000000001 -100000000000000000000000000001 +10000000000000000T0T0T00000001 100000000000020304000000T0T001 100000000000000000000000000001 1001000000T0000000000000000001 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) diff --git a/src/ft_draw_sprite_extra.c b/src/ft_draw_sprite_extra.c index e592da0..5133231 100644 --- a/src/ft_draw_sprite_extra.c +++ b/src/ft_draw_sprite_extra.c @@ -47,25 +47,38 @@ static void (1 + sprite->transformx / sprite->transformy); } +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); + return (0); +} + void ft_calc_sprite(t_cub *cl) { t_sprite sprite; - int32_t i; - int32_t j; + int16_t i; + int8_t j; i = -1; j = -1; ft_sort_sprites(cl, -1, -1); - while (++j < cl->mlist.sprite_var) + while (++j < FT_TOTAL_SPRT) { while (++i < cl->mlist.sprite_nbr[j]) { sprite = cl->sprites[cl->mlist.st_o[j]][cl->mlist.sprite_order[ cl->mlist.st_o[j]][i]]; - sprite.current_sprite = (cl->mlist.st_o[j] == 0) ? - 4 : cl->mlist.st_o[j] + 7; + sprite.current_sprite = ft_set_current_sprite(cl, j); sprite.spritey = sprite.s_pos_x - (cl->plist.pos_x - 0.5); sprite.spritex = sprite.s_pos_y - (cl->plist.pos_y - 0.5); ft_init_sprite(cl, &sprite); diff --git a/src/ft_extra_keys.c b/src/ft_extra_keys.c index f8a6db8..1a71402 100644 --- a/src/ft_extra_keys.c +++ b/src/ft_extra_keys.c @@ -12,7 +12,6 @@ #include <cub3d.h> #include <stdint.h> -#include <stdio.h> #include <math.h> #include <time.h> #include <libft.h> diff --git a/src/ft_init_map.c b/src/ft_init_map.c index e85c6a6..72a02fd 100644 --- a/src/ft_init_map.c +++ b/src/ft_init_map.c @@ -67,7 +67,6 @@ int8_t mlist->weapon_var = 0; mlist->topsp = 0; ft_bzero(mlist->sprite_nbr, FT_TOTAL_SPRT); - ft_bzero(mlist->sprite_order, FT_TOTAL_SPRT); i = -1; while (++i < FT_TOTAL_SPRT) ft_bzero(mlist->sprite_order[i], 4096); diff --git a/src/ft_sort_s_t.c b/src/ft_sort_s_t.c index 6c08882..9cbde8b 100644 --- a/src/ft_sort_s_t.c +++ b/src/ft_sort_s_t.c @@ -21,10 +21,10 @@ float uint16_t i; float **dist_tab; - if (!(dist_tab = (float **)malloc(8 * sizeof(float*)))) + if (!(dist_tab = (float **)malloc((FT_TOTAL_SPRT + 1) * sizeof(float*)))) return (NULL); i = 0; - while (i < 8) + while (i < FT_TOTAL_SPRT + 1) { if (!(dist_tab[i] = (float *)malloc(4096 * sizeof(float)))) return (NULL); @@ -34,13 +34,26 @@ float } static void - ft_init_st(uint16_t sprite_var, int32_t *st_o) + ft_init_st(int32_t *st_o) { int8_t i; - i = -1; - while (++i < sprite_var) + i = 0; + while (i < FT_TOTAL_SPRT) + { st_o[i] = i; + i++; + } +} + +static void + ft_swap_them(int16_t i, float **dist_tab) +{ + float 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 @@ -48,25 +61,23 @@ void { int16_t i; int32_t tmp; - float tmp_i[4096]; i = -1; - ft_init_st(cl->mlist.sprite_var, cl->mlist.st_o); - while (++i < cl->mlist.sprite_var) + ft_init_st(cl->mlist.st_o); + while (++i < FT_TOTAL_SPRT) { - if (i < 7 && dist_tab[i][0] < dist_tab[i + 1][0]) + if (i < FT_TOTAL_SPRT && dist_tab[i][0] + && 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_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); + ft_swap_them(i, dist_tab); i = -1; } } i = -1; - while (++i < 8) + while (++i < FT_TOTAL_SPRT + 1) ft_memdel((void*)&dist_tab[i]); ft_memdel((void*)&dist_tab); } |