aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsalaaad2 <arthudurant263@gmail.com>2020-03-18 22:35:26 +0100
committersalaaad2 <arthudurant263@gmail.com>2020-03-18 22:35:26 +0100
commit768b140f6659e6e110d37a7f8557c3da3669155b (patch)
tree2fe3655ea1c4ea607e1f9da2a40a337f16f3cb07
parentfatfingers 2 (diff)
download42-cub3d-768b140f6659e6e110d37a7f8557c3da3669155b.tar.gz
42-cub3d-768b140f6659e6e110d37a7f8557c3da3669155b.tar.bz2
42-cub3d-768b140f6659e6e110d37a7f8557c3da3669155b.tar.xz
42-cub3d-768b140f6659e6e110d37a7f8557c3da3669155b.tar.zst
42-cub3d-768b140f6659e6e110d37a7f8557c3da3669155b.zip
fatfingers master
-rw-r--r--inc/cub3d.h2
-rw-r--r--inc/cub3d_structs.h2
-rw-r--r--map/map_one.cub6
-rw-r--r--src/ft_draw_sprite.c33
-rw-r--r--src/ft_draw_sprite_extra.c4
-rw-r--r--src/ft_draw_traps.c2
-rw-r--r--src/ft_get_sprite_spawns.c4
-rw-r--r--src/ft_init_map.c2
8 files changed, 23 insertions, 32 deletions
diff --git a/inc/cub3d.h b/inc/cub3d.h
index 9c906be..a7f6b7d 100644
--- a/inc/cub3d.h
+++ b/inc/cub3d.h
@@ -77,7 +77,7 @@ void ft_draw_circle(float a, float b,
int8_t ft_draw_verline(t_cub *cl, int32_t x,
int32_t y1, int32_t y2);
void ft_sprite_h_w(t_cub *cl, t_sprite *sprite);
-void ft_sort_sprites(t_cub *cl);
+void ft_sort_sprites(t_cub *cl, int16_t i, int16_t j);
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 6db79de..29c6ac7 100644
--- a/inc/cub3d_structs.h
+++ b/inc/cub3d_structs.h
@@ -195,7 +195,7 @@ typedef struct s_map
size_t map_w;
size_t map_h;
size_t mapl_len;
- int32_t sprite_nbr;
+ int32_t sprite_nbr[4096];
uint8_t sprite_var;
int32_t sprite_order[8][4096];
int32_t traps_nbr;
diff --git a/map/map_one.cub b/map/map_one.cub
index 81982ca..d9adb38 100644
--- a/map/map_one.cub
+++ b/map/map_one.cub
@@ -18,9 +18,9 @@ T ./media/img/spikes.xpm
SH 2
111111111111111111
-100000000000333301
-10000000E000444401
-100000000000222201
+100000000001222211
+10000000E001333311
+100000000000444401
100100000000000001
101100000111000001
111111111111110011
diff --git a/src/ft_draw_sprite.c b/src/ft_draw_sprite.c
index d0447f6..cb9a573 100644
--- a/src/ft_draw_sprite.c
+++ b/src/ft_draw_sprite.c
@@ -18,7 +18,7 @@
#include <math.h>
static void
- ft_sort_sprites_norme(float *dist_tab, uint16_t *i, uint16_t j, t_cub *cl)
+ ft_sort_sprites_norme(float *dist_tab, int16_t *i, uint16_t j, t_cub *cl)
{
uint32_t tmp;
uint32_t it;
@@ -33,22 +33,18 @@ static void
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 = 0;
+ *i = -1;
}
}
void
- ft_sort_sprites(t_cub *cl)
+ ft_sort_sprites(t_cub *cl, int16_t it, int16_t jt)
{
float dist_tab[8][4096];
- uint16_t it;
- uint16_t jt;
- it = -1;
- jt = -1;
while (++jt <= cl->mlist.sprite_var)
{
- while (++it <= cl->mlist.sprite_nbr)
+ while (++it <= cl->mlist.sprite_nbr[jt])
{
dist_tab[jt][it] =
((cl->plist.pos_x - cl->sprites[jt][it].s_pos_x) *
@@ -59,19 +55,14 @@ void
}
it = -1;
}
- it = 0;
- jt = 0;
- while (jt < 3)
- {
- while (it < 6)
- {
- ft_sort_sprites_norme(dist_tab[jt], &it, jt, cl);
- printf("%d\n", jt);
- it++;
- }
- it = 0;
- jt++;
- }
+ it = -1;
+ jt = -1;
+ while (++jt < cl->mlist.sprite_var)
+ {
+ while (++it < cl->mlist.sprite_nbr[jt] - 1)
+ ft_sort_sprites_norme(dist_tab[jt], &it, jt, cl);
+ it = -1;
+ }
}
static void
diff --git a/src/ft_draw_sprite_extra.c b/src/ft_draw_sprite_extra.c
index 9198e8d..f4ac6ee 100644
--- a/src/ft_draw_sprite_extra.c
+++ b/src/ft_draw_sprite_extra.c
@@ -58,10 +58,10 @@ void
i = 0;
j = 0;
- ft_sort_sprites(cl);
+ ft_sort_sprites(cl, -1, -1);
while (j < cl->mlist.sprite_var)
{
- while (i < cl->mlist.sprite_nbr)
+ 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;
diff --git a/src/ft_draw_traps.c b/src/ft_draw_traps.c
index abde37e..f1acc20 100644
--- a/src/ft_draw_traps.c
+++ b/src/ft_draw_traps.c
@@ -41,7 +41,7 @@ void
int32_t it;
it = 0;
- while (it < cl->mlist.sprite_nbr)
+ while (it < cl->mlist.traps_nbr)
{
dist_tab[it] = ((cl->plist.pos_x - cl->traps[it].s_pos_x) *
(cl->plist.pos_x - cl->traps[it].s_pos_x) +
diff --git a/src/ft_get_sprite_spawns.c b/src/ft_get_sprite_spawns.c
index 3a44f56..e0b37b5 100644
--- a/src/ft_get_sprite_spawns.c
+++ b/src/ft_get_sprite_spawns.c
@@ -29,7 +29,7 @@ void
{
if (clist->mlist.map[y][x] == c)
{
- clist->mlist.sprite_nbr++;
+ clist->mlist.sprite_nbr[s_n]++;
clist->sprites[s_n][i].s_pos_x = x;
clist->sprites[s_n][i].s_pos_y = y;
i++;
@@ -59,7 +59,7 @@ void
{
if (ft_ischarset("2", clist->mlist.map[y][x]))
{
- clist->mlist.sprite_nbr++;
+ clist->mlist.sprite_nbr[0]++;
clist->sprites[0][i].s_pos_x = x;
clist->sprites[0][i].s_pos_y = y;
i++;
diff --git a/src/ft_init_map.c b/src/ft_init_map.c
index 813a795..4ee8def 100644
--- a/src/ft_init_map.c
+++ b/src/ft_init_map.c
@@ -64,6 +64,7 @@ int8_t
mlist->nly = 0;
mlist->sprite_var = 0;
mlist->topsp = 0;
+ ft_bzero(mlist->sprite_nbr, 4096);
ft_bzero(mlist->sprite_order, 4096);
ft_bzero(mlist->traps_order, 512);
return (0);
@@ -92,7 +93,6 @@ int8_t
mlist->ismusic = 0;
mlist->isskybox = 0;
mlist->istraps = 0;
- mlist->sprite_nbr = 0;
mlist->traps_nbr = 0;
mlist->darklvl = 0;
return (ft_init_map_norme(mlist));