aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-03-18 20:07:20 +0100
committerJozanLeClerc <bousset.rudy@gmail.com>2020-03-18 20:07:20 +0100
commit3ce74f6396bf76650853aba3bfc307847adb0bba (patch)
tree57f6040f2d1fd1e8ef59f20c3aa4c2157f404b5c
parentReady to merge (diff)
parentcangelog (diff)
download42-cub3d-3ce74f6396bf76650853aba3bfc307847adb0bba.tar.gz
42-cub3d-3ce74f6396bf76650853aba3bfc307847adb0bba.tar.bz2
42-cub3d-3ce74f6396bf76650853aba3bfc307847adb0bba.tar.xz
42-cub3d-3ce74f6396bf76650853aba3bfc307847adb0bba.tar.zst
42-cub3d-3ce74f6396bf76650853aba3bfc307847adb0bba.zip
Merge branch 'better_sprites'
-rw-r--r--inc/cub3d.h4
-rw-r--r--inc/cub3d_structs.h2
-rw-r--r--map/map_one.cub8
-rw-r--r--src/ft_draw_sprite.c46
-rw-r--r--src/ft_draw_sprite_extra.c15
-rw-r--r--src/ft_draw_traps_extra.c3
6 files changed, 37 insertions, 41 deletions
diff --git a/inc/cub3d.h b/inc/cub3d.h
index 61c4f01..042faa3 100644
--- a/inc/cub3d.h
+++ b/inc/cub3d.h
@@ -78,8 +78,8 @@ void ft_draw_circle(float a, float b,
int32_t color, t_cub *cl);
int8_t ft_draw_verline(t_cub *cl, int32_t x,
int32_t y1, int32_t y2);
-void ft_sprite_width(t_cub *cl, t_sprite *sprite);
-void ft_sprite_height(t_cub *cl, t_sprite *sprite);
+void ft_sprite_h_w(t_cub *cl, t_sprite *sprite);
+void ft_sort_sprites(t_cub *cl);
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 a08d7b2..66f139d 100644
--- a/inc/cub3d_structs.h
+++ b/inc/cub3d_structs.h
@@ -204,7 +204,7 @@ typedef struct s_map
size_t mapl_len;
int32_t sprite_nbr;
uint8_t sprite_var;
- int32_t sprite_order[4096];
+ int32_t sprite_order[8][4096];
int32_t traps_nbr;
int32_t traps_order[512];
size_t line_chk;
diff --git a/map/map_one.cub b/map/map_one.cub
index 6123a8d..46f5aac 100644
--- a/map/map_one.cub
+++ b/map/map_one.cub
@@ -18,16 +18,16 @@ T ./media/img/spikes.xpm
SH 2
111111111111111111
-140000000000300001
-1000E0000000000001
-100100000000300001
+140000000000020201
+100000E00000000001
+100100000000030301
101100000111000001
111111111111110011
1000001 100001
1001001 100001
1011001 100001
111101111111110111
-120500001101010111
+100500001101010111
100000000000000011
100000000000000011
11T000001101000111
diff --git a/src/ft_draw_sprite.c b/src/ft_draw_sprite.c
index b304102..ceea280 100644
--- a/src/ft_draw_sprite.c
+++ b/src/ft_draw_sprite.c
@@ -13,23 +13,26 @@
#include <libft.h>
#include <cub3d.h>
#include <stdint.h>
+#include <stdio.h>
#include <stdlib.h>
#include <math.h>
static void
- ft_sort_sprites_norme(float *dist_tab, int32_t it, t_cub *cl)
+ ft_sort_sprites_norme(float *dist_tab, uint16_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])
+ 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[it];
- cl->mlist.sprite_order[it] = cl->mlist.sprite_order[it + 1];
- cl->mlist.sprite_order[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;
it = 0;
}
}
@@ -37,31 +40,30 @@ static void
void
ft_sort_sprites(t_cub *cl)
{
- float dist_tab[4096];
- int32_t it;
- int32_t jt;
+ float dist_tab[8][4096];
+ uint16_t it;
+ uint16_t jt;
- it = 0;
- jt = 0;
- while (jt < cl->mlist.sprite_var)
+ it = -1;
+ jt = -1;
+ while (++jt < cl->mlist.sprite_var)
{
- while (it < cl->mlist.sprite_nbr)
+ while (++it < cl->mlist.sprite_nbr)
{
- dist_tab[it] = ((cl->plist.pos_x - cl->sprites[jt][it].s_pos_x) *
+ 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[it] = it;
- it++;
+ cl->mlist.sprite_order[jt][it] = it;
}
- it = 0;
- jt++;
- }
- it = 0;
- while (it < cl->mlist.sprite_nbr)
- {
- ft_sort_sprites_norme(dist_tab, it, cl);
+ it = -1;
}
+ it = -1;
+ jt = -1;
+ while (++jt < cl->mlist.sprite_var)
+ while (++it < cl->mlist.sprite_nbr)
+ ft_sort_sprites_norme(dist_tab[jt], &it, jt, cl);
}
static void
diff --git a/src/ft_draw_sprite_extra.c b/src/ft_draw_sprite_extra.c
index 2545ec0..9198e8d 100644
--- a/src/ft_draw_sprite_extra.c
+++ b/src/ft_draw_sprite_extra.c
@@ -13,12 +13,11 @@
#include <libft.h>
#include <cub3d.h>
#include <stdint.h>
-#include <stdio.h>
#include <stdlib.h>
#include <math.h>
void
- ft_sprite_height(t_cub *cl, t_sprite *sprite)
+ ft_sprite_h_w(t_cub *cl, t_sprite *sprite)
{
sprite->spriteheight = abs((int)(cl->wlist.y_size / (sprite->transformy)));
sprite->drawstarty = -sprite->spriteheight / 2 + cl->wlist.y_size / 2;
@@ -27,11 +26,6 @@ void
sprite->drawendy = sprite->spriteheight / 2 + cl->wlist.y_size / 2;
if (sprite->drawendy >= (int)cl->wlist.y_size)
sprite->drawendy = cl->wlist.y_size - 1;
-}
-
-void
- ft_sprite_width(t_cub *cl, t_sprite *sprite)
-{
sprite->spritewidth = abs((int)(cl->wlist.x_size / (sprite->transformy)));
sprite->drawstartx = -sprite->spritewidth / 2 + sprite->spritescreenx;
if (sprite->drawstartx < 0)
@@ -41,6 +35,7 @@ void
sprite->drawendx = cl->wlist.x_size - 1;
}
+
static void
ft_init_sprite(t_cub *cl, t_sprite *sprite)
{
@@ -63,17 +58,17 @@ void
i = 0;
j = 0;
+ ft_sort_sprites(cl);
while (j < cl->mlist.sprite_var)
{
while (i < cl->mlist.sprite_nbr)
{
- sprite = cl->sprites[j][i];
+ sprite = cl->sprites[j][cl->mlist.sprite_order[j][i]];
sprite.current_sprite = (j == 0) ? 4 : 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_height(cl, &sprite);
- ft_sprite_width(cl, &sprite);
+ ft_sprite_h_w(cl, &sprite);
ft_draw_sprite(cl, &sprite);
i++;
}
diff --git a/src/ft_draw_traps_extra.c b/src/ft_draw_traps_extra.c
index a2fd0ab..c524190 100644
--- a/src/ft_draw_traps_extra.c
+++ b/src/ft_draw_traps_extra.c
@@ -36,8 +36,7 @@ void
+ cl->plist.plane_x * sprite.spritey);
sprite.spritescreenx = (int)(cl->wlist.x_size / 2) *
(1 + sprite.transformx / sprite.transformy);
- ft_sprite_height(cl, &sprite);
- ft_sprite_width(cl, &sprite);
+ ft_sprite_h_w(cl, &sprite);
ft_draw_traps(cl, &sprite);
i++;
}