diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-25 17:16:48 +0100 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-25 17:16:48 +0100 |
commit | a88662bebb21d598c7d06f09433950ba10155cff (patch) | |
tree | 42af13d4544744253fa55fbea0e9cbd40a6354e4 | |
parent | Get normed (diff) | |
parent | pourquoi se priver de stack (diff) | |
download | 42-cub3d-a88662bebb21d598c7d06f09433950ba10155cff.tar.gz 42-cub3d-a88662bebb21d598c7d06f09433950ba10155cff.tar.bz2 42-cub3d-a88662bebb21d598c7d06f09433950ba10155cff.tar.xz 42-cub3d-a88662bebb21d598c7d06f09433950ba10155cff.tar.zst 42-cub3d-a88662bebb21d598c7d06f09433950ba10155cff.zip |
Merge branch 'better_m_s'
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | inc/cub3d.h | 1 | ||||
-rw-r--r-- | inc/cub3d_structs.h | 1 | ||||
-rw-r--r-- | map/map_one.cub | 24 | ||||
-rw-r--r-- | map/map_two.cub | 36 | ||||
-rw-r--r-- | src/ft_draw_sprite.c | 5 | ||||
-rw-r--r-- | src/ft_draw_sprite_extra.c | 18 | ||||
-rw-r--r-- | src/ft_init_map.c | 1 | ||||
-rw-r--r-- | src/ft_sort_s_t.c | 47 |
9 files changed, 95 insertions, 39 deletions
@@ -134,6 +134,7 @@ SRCS_NAME += ft_hud_threads_next.c SRCS_NAME += ft_wall_threads.c SRCS_NAME += ft_floor_threads.c SRCS_NAME += ft_castray_loop.c +SRCS_NAME += ft_sort_s_t.c #--------------------------------------------------------------------------------------------------# SRCS = $(addprefix ${SRCS_DIR},${SRCS_NAME}) #--------------------------------------------------------------------------------------------------# diff --git a/inc/cub3d.h b/inc/cub3d.h index 454dc46..38d4e3f 100644 --- a/inc/cub3d.h +++ b/inc/cub3d.h @@ -88,6 +88,7 @@ void ft_draw_circle(float a, float b, void ft_draw_verline(t_cub *cl, int32_t x, int32_t y, int32_t y2); void ft_sprite_h_w(t_cub *cl, t_sprite *sprite); void ft_sort_sprites(t_cub *cl, int16_t i, int16_t j); +void ft_sort_s_t(t_cub *cl, float dist_tab[8][4096]); void ft_calc_sprite(t_cub *cl); void ft_draw_sprite(t_cub *cl, t_sprite *sprite); void ft_calc_trap(t_cub *cl); diff --git a/inc/cub3d_structs.h b/inc/cub3d_structs.h index 3f3fb0e..1b46312 100644 --- a/inc/cub3d_structs.h +++ b/inc/cub3d_structs.h @@ -206,6 +206,7 @@ typedef struct s_map uint8_t sprite_var; uint8_t weapon_var; int32_t sprite_order[8][4096]; + int32_t st_o[8]; int32_t traps_nbr; int32_t heals_nbr; int32_t weaps_nbr[3]; diff --git a/map/map_one.cub b/map/map_one.cub index b11ff6d..a627cf2 100644 --- a/map/map_one.cub +++ b/map/map_one.cub @@ -1,39 +1,39 @@ -R 1600 1000 +R 1280 1024 NO ./media/img/tex/wood_wall_1.xpm SO ./media/img/tex/wood_wall_1.xpm EA ./media/img/tex/wood_wall_1.xpm WE ./media/img/tex/wood_wall_1.xpm -S ./media/img/sprites/pillar.xpm C ./media/img/tex/wood_ceil.xpm F ./media/img/tex/parquet.xpm +S ./media/img/sprites/pillar.xpm S3 ./media/img/sprites/pylon.xpm -S4 ./media/img/sprites/wood_chest.xpm +S4 ./media/img/sprites/hey.xpm T ./media/img/sprites/spikes.xpm SH 2 - 1111111 -111111111111000001 -100000000+00000301 -10000E000T00000301 -100000000000000301 -100100000+00000001 -101100000111000001 + 11111111111111111111 +1111111111110000000000000000001 +1000000000000000000000000000001 +10000E0000000203040506070809001 +1000000000000000000000000000001 +1001000000000000000000000000001 +1011000001110000011111111111111 111111111111110011 1000001 100001 1001001 100001 1011001 100001 111101111111110111 10000000110101011 -12020202020000001 +10000000000000001 1#000000000000001 1@000000000000001 1!000000000000001 -12020202020000001 +10000000000000001 11000000110100011 11110111111101011 11111 1 1111 diff --git a/map/map_two.cub b/map/map_two.cub index 9300699..2d817a1 100644 --- a/map/map_two.cub +++ b/map/map_two.cub @@ -1,25 +1,29 @@ -R 1280 800 +R 800 800 NO ./media/img/tex/linuz.xpm SO ./media/img/tex/linuz.xpm EA ./media/img/tex/linuz.xpm WE ./media/img/tex/linuz.xpm + + S ./media/img/sprites/pillar.xpm -S3 ./media/img/sprites/pillar.xpm -S4 ./media/img/sprites/pillar.xpm +S3 ./media/img/sprites/pylon.xpm +S4 ./media/img/sprites/hey.xpm + + SH 5 -C ./media/img/tex/arrow1.xpm -F ./media/img/tex/arrow2.xpm +C 0,150,150 +F 0,150,150 -111111111111111111111111111111111111 -100000000000000000000000000000000001 -100000000000030000000000000000000001 -100000000000000000000000000000000001 -10000000000002020202000W000000000001 -100000000000000000000000000000000001 -100000000000040000000000000000000001 -100000000000000000000000000000000001 -100000000000000000000000000000000001 -100000000000000000000000000000000001 -111111111111111111111111111111111111 +11111111111111111111111111111 +10000000000000000000000000001 +10000000000000000000000000001 +10000023000004000000000000001 +1000002300W004000000000000001 +10000023000004000000000000001 +10000000000000000000000000001 +10000000000000000000000000001 +10000000000000000000000000001 +10000000000000000000000000001 +11111111111111111111111111111 diff --git a/src/ft_draw_sprite.c b/src/ft_draw_sprite.c index b381957..5c0fe41 100644 --- a/src/ft_draw_sprite.c +++ b/src/ft_draw_sprite.c @@ -41,9 +41,9 @@ void { float dist_tab[8][4096]; - while (++jt <= cl->mlist.sprite_var) + while (++jt < cl->mlist.sprite_var) { - while (++it <= cl->mlist.sprite_nbr[jt]) + while (++it < cl->mlist.sprite_nbr[jt]) { dist_tab[jt][it] = ((cl->plist.pos_x - cl->sprites[jt][it].s_pos_x) * @@ -62,6 +62,7 @@ void ft_sort_sprites_norme(dist_tab[jt], &it, jt, cl); it = -1; } + ft_sort_s_t(cl, dist_tab); } static void diff --git a/src/ft_draw_sprite_extra.c b/src/ft_draw_sprite_extra.c index 323906a..0830d2c 100644 --- a/src/ft_draw_sprite_extra.c +++ b/src/ft_draw_sprite_extra.c @@ -54,23 +54,23 @@ void int32_t i; int32_t j; - i = 0; - j = 0; + i = -1; + j = -1; ft_sort_sprites(cl, -1, -1); - while (j < cl->mlist.sprite_var) + while (++j < cl->mlist.sprite_var) { - while (i < cl->mlist.sprite_nbr[j]) + while (++i < cl->mlist.sprite_nbr[j]) { - sprite = cl->sprites[j][cl->mlist.sprite_order[j][i]]; - sprite.current_sprite = (j == 0) ? 4 : j + 7; + 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.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); ft_sprite_h_w(cl, &sprite); ft_draw_sprite(cl, &sprite); - i++; } - i = 0; - j++; + i = -1; } } diff --git a/src/ft_init_map.c b/src/ft_init_map.c index 9ddbb47..d252f2e 100644 --- a/src/ft_init_map.c +++ b/src/ft_init_map.c @@ -66,6 +66,7 @@ int8_t mlist->topsp = 0; ft_bzero(mlist->sprite_nbr, 4096); ft_bzero(mlist->sprite_order, 4096); + ft_bzero(mlist->st_o, 4096); ft_bzero(mlist->traps_order, 512); ft_bzero(mlist->heals_order, 64); mlist->weaps_nbr[0] = 0; diff --git a/src/ft_sort_s_t.c b/src/ft_sort_s_t.c new file mode 100644 index 0000000..24ed358 --- /dev/null +++ b/src/ft_sort_s_t.c @@ -0,0 +1,47 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_sort_s_t.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/24 20:22:45 by rbousset #+# #+# */ +/* Updated: 2020/03/09 18:56:01 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include <libft.h> +#include <cub3d.h> +#include <stdint.h> + +static void + ft_init_st(uint16_t sprite_var, int32_t st_o[8]) +{ + int8_t i; + + i = -1; + while (++i < sprite_var) + st_o[i] = i; +} + +void + ft_sort_s_t(t_cub *cl, float dist_tab[8][4096]) +{ + 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) + if (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); + i = -1; + } +} |