aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ft_draw_ammo_back.c18
-rw-r--r--src/ft_draw_ammo_bar.c20
-rw-r--r--src/ft_draw_hud.c91
-rw-r--r--src/ft_draw_verline.c36
-rw-r--r--src/ft_floor_cast.c17
-rw-r--r--src/ft_raycasting.c34
-rw-r--r--src/ft_wall_cast.c199
7 files changed, 333 insertions, 82 deletions
diff --git a/src/ft_draw_ammo_back.c b/src/ft_draw_ammo_back.c
index b9bb408..767127d 100644
--- a/src/ft_draw_ammo_back.c
+++ b/src/ft_draw_ammo_back.c
@@ -19,20 +19,20 @@ static void
const uint16_t scl = cl->mlist.scale;
cl->img.ptr[x * 4 +
- (cl->img.sizeline * (y + cl->wlist.y_size -
+ (cl->img.sizeline * (y + cl->wlist.y_size -
(2 * ((cl->mlist.map_h * scl)) + 20)))] =
- (uint8_t)cl->tlist[16].ptr[cl->tlist[16].tex_x * 4 + 4 *
- cl->tlist[16].img_w * cl->tlist[16].tex_y];
+ (uint8_t)cl->tlist[16].ptr[cl->tlist[16].tex_x_alt * 4 + 4 *
+ cl->tlist[16].img_w * cl->tlist[16].tex_y_alt];
cl->img.ptr[x * 4 +
(cl->img.sizeline * (y + cl->wlist.y_size -
(2 * ((cl->mlist.map_h * scl)) + 20))) + 1] =
- (uint8_t)cl->tlist[16].ptr[cl->tlist[16].tex_x * 4 + 4 *
- cl->tlist[16].img_w * cl->tlist[16].tex_y + 1];
+ (uint8_t)cl->tlist[16].ptr[cl->tlist[16].tex_x_alt * 4 + 4 *
+ cl->tlist[16].img_w * cl->tlist[16].tex_y_alt + 1];
cl->img.ptr[x * 4 +
(cl->img.sizeline * (y + cl->wlist.y_size -
(2 * ((cl->mlist.map_h * scl)) + 20))) + 2] =
- (uint8_t)cl->tlist[16].ptr[cl->tlist[16].tex_x * 4 + 4 *
- cl->tlist[16].img_w * cl->tlist[16].tex_y + 2];
+ (uint8_t)cl->tlist[16].ptr[cl->tlist[16].tex_x_alt * 4 + 4 *
+ cl->tlist[16].img_w * cl->tlist[16].tex_y_alt + 2];
}
static void
@@ -48,11 +48,11 @@ static void
y = 0;
while (y < cl->amm_back_h)
{
- cl->tlist[16].tex_y = ((y * y_ratio) >> 16);
+ cl->tlist[16].tex_y_alt = ((y * y_ratio) >> 16);
x = 0;
while (x < cl->amm_back_w)
{
- cl->tlist[16].tex_x = ((x * x_ratio) >> 16);
+ cl->tlist[16].tex_x_alt = ((x * x_ratio) >> 16);
ft_draw_back(y, x, cl);
x++;
}
diff --git a/src/ft_draw_ammo_bar.c b/src/ft_draw_ammo_bar.c
index bf8dbda..febeb55 100644
--- a/src/ft_draw_ammo_bar.c
+++ b/src/ft_draw_ammo_bar.c
@@ -22,18 +22,18 @@ static void
cl->img.ptr[(x + 10) * 4 +
(cl->img.sizeline * (int)(y + ((cl->wlist.y_size - 10) -
(2 * ((cl->mlist.map_h * scl) / 1.3)) - 40)))] =
- (uint8_t)cl->tnum[id].ptr[cl->tnum[id].tex_x * 4 + 4 *
- cl->tnum[id].img_w * cl->tnum[id].tex_y];
+ (uint8_t)cl->tnum[id].ptr[cl->tnum[id].tex_x_alt * 4 + 4 *
+ cl->tnum[id].img_w * cl->tnum[id].tex_y_alt];
cl->img.ptr[(x + 10) * 4 +
(cl->img.sizeline * (int)(y + ((cl->wlist.y_size - 10) -
(2 * ((cl->mlist.map_h * scl) / 1.3)) - 40))) + 1] =
- (uint8_t)cl->tnum[id].ptr[cl->tnum[id].tex_x * 4 + 4 *
- cl->tnum[id].img_w * cl->tnum[id].tex_y + 1];
+ (uint8_t)cl->tnum[id].ptr[cl->tnum[id].tex_x_alt * 4 + 4 *
+ cl->tnum[id].img_w * cl->tnum[id].tex_y_alt + 1];
cl->img.ptr[(x + 10) * 4 +
(cl->img.sizeline * (int)(y + ((cl->wlist.y_size - 10) -
(2 * ((cl->mlist.map_h * scl) / 1.3)) - 40))) + 2] =
- (uint8_t)cl->tnum[id].ptr[cl->tnum[id].tex_x * 4 + 4 *
- cl->tnum[id].img_w * cl->tnum[id].tex_y + 2];
+ (uint8_t)cl->tnum[id].ptr[cl->tnum[id].tex_x_alt * 4 + 4 *
+ cl->tnum[id].img_w * cl->tnum[id].tex_y_alt + 2];
}
static void
@@ -49,13 +49,13 @@ static void
y = 0;
while (y < cl->ammo_num_h)
{
- cl->tnum[n - 48].tex_y = ((y * y_ratio) >> 16);
+ cl->tnum[n - 48].tex_y_alt = ((y * y_ratio) >> 16);
x = 0;
while (x < cl->ammo_num_w)
{
- cl->tnum[n - 48].tex_x = ((x * x_ratio) >> 16);
- if (cl->tnum[n - 48].ptr[cl->tnum[n - 48].tex_x * 4 + 4 *
- cl->tnum[n - 48].img_h * cl->tnum[n - 48].tex_y])
+ cl->tnum[n - 48].tex_x_alt = ((x * x_ratio) >> 16);
+ if (cl->tnum[n - 48].ptr[cl->tnum[n - 48].tex_x_alt * 4 + 4 *
+ cl->tnum[n - 48].img_h * cl->tnum[n - 48].tex_y_alt])
ft_draw_tnum(n - 48, y, x + x_offset, cl);
x++;
}
diff --git a/src/ft_draw_hud.c b/src/ft_draw_hud.c
index a10b2f3..6e4f86f 100644
--- a/src/ft_draw_hud.c
+++ b/src/ft_draw_hud.c
@@ -12,6 +12,7 @@
#include <cub3d.h>
#include <stdint.h>
+#include <pthread.h>
static void
ft_draw_stage_back(t_cub *clist)
@@ -41,16 +42,102 @@ static void
}
}
-int8_t
- ft_draw_hud(t_cub *clist)
+void
+*ft_ammo_back_thread(void *vargp)
{
+ t_cub *clist;
+
+ clist = (t_cub *)vargp;
ft_draw_ammo_back(clist);
+ pthread_exit(0x0);
+ return (0x0);
+}
+
+void
+*ft_minimap_back_thread(void *vargp)
+{
+ t_cub *clist;
+
+ clist = (t_cub *)vargp;
ft_draw_minimap_back(clist);
+ pthread_exit(0x0);
+ return (0x0);
+}
+
+void
+*ft_map_thread(void *vargp)
+{
+ t_cub *clist;
+
+ clist = (t_cub *)vargp;
ft_draw_map(clist->mlist.map, clist);
+ pthread_exit(0x0);
+ return (0x0);
+}
+
+void
+*ft_life_bar_thread(void *vargp)
+{
+ t_cub *clist;
+
+ clist = (t_cub *)vargp;
ft_draw_life_bar(clist);
+ pthread_exit(0x0);
+ return (0x0);
+}
+
+void
+*ft_ammo_bar_thread(void *vargp)
+{
+ t_cub *clist;
+
+ clist = (t_cub *)vargp;
ft_draw_ammo_bar(clist);
+ pthread_exit(0x0);
+ return (0x0);
+}
+
+void
+*ft_health_cap_thread(void *vargp)
+{
+ t_cub *clist;
+
+ clist = (t_cub *)vargp;
ft_draw_health_caption(clist);
+ pthread_exit(0x0);
+ return (0x0);
+}
+
+void
+*ft_ammo_cap_thread(void *vargp)
+{
+ t_cub *clist;
+
+ clist = (t_cub *)vargp;
ft_draw_ammo_caption(clist);
+ pthread_exit(0x0);
+ return (0x0);
+}
+
+int8_t
+ ft_draw_hud(t_cub *clist)
+{
+ pthread_t tid[7];
+
+ pthread_create(&tid[0], 0x0, ft_ammo_back_thread, (void*)clist);
+ pthread_create(&tid[1], 0x0, ft_minimap_back_thread, (void*)clist);
+ pthread_join(tid[0], 0x0);
+ pthread_join(tid[1], 0x0);
+ pthread_create(&tid[2], 0x0, ft_map_thread, (void*)clist);
+ pthread_create(&tid[3], 0x0, ft_life_bar_thread, (void*)clist);
+ pthread_create(&tid[4], 0x0, ft_ammo_bar_thread, (void*)clist);
+ pthread_create(&tid[5], 0x0, ft_health_cap_thread, (void*)clist);
+ pthread_create(&tid[6], 0x0, ft_ammo_cap_thread, (void*)clist);
+ pthread_join(tid[2], 0x0);
+ pthread_join(tid[3], 0x0);
+ pthread_join(tid[4], 0x0);
+ pthread_join(tid[5], 0x0);
+ pthread_join(tid[6], 0x0);
if (clist->mlist.isnlvl)
{
ft_draw_stage_back(clist);
diff --git a/src/ft_draw_verline.c b/src/ft_draw_verline.c
deleted file mode 100644
index 3ecde46..0000000
--- a/src/ft_draw_verline.c
+++ /dev/null
@@ -1,36 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* ft_draw_verline.c :+: :+: :+: */
-/* +:+ +:+ +:+ */
-/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
-/* +#+#+#+#+#+ +#+ */
-/* Created: 2020/02/14 17:22:23 by rbousset #+# #+# */
-/* Updated: 2020/02/14 17:23:42 by rbousset ### ########lyon.fr */
-/* */
-/* ************************************************************************** */
-
-#include <cub3d.h>
-#include <stdint.h>
-
-int8_t
- ft_draw_verline(t_cub *cl, int32_t x, int32_t y, int32_t y2)
-{
- int32_t d;
- int32_t tex_y;
-
- (y < 0) ? (y = 0) : 0;
- (y2 < 0) ? (y2 = 0) : 0;
- (cl->rlist.line_h_tab[x] <= 0) ? (cl->rlist.line_h_tab[x] = 1) : 0;
- while (y < y2)
- {
- d = y * 256 - cl->wlist.y_size * 128 + cl->rlist.line_h_tab[x] * 128;
- d = (d <= 0) ? (-d) : (d);
- tex_y = ((d * cl->tlist[cl->rlist.w_side_tab[x]].img_h)
- / cl->rlist.line_h_tab[x]) / 256;
- (tex_y <= 0) ? (tex_y = 1) : 0;
- ft_draw_texture(cl, x, y, tex_y);
- y++;
- }
- return (0);
-}
diff --git a/src/ft_floor_cast.c b/src/ft_floor_cast.c
index e9315ed..09e0493 100644
--- a/src/ft_floor_cast.c
+++ b/src/ft_floor_cast.c
@@ -77,28 +77,27 @@ static void
}
void
- ft_floor_cast(t_cub *cl)
+ *ft_floor_cast(void *vargp)
{
- t_ray *rl;
+ t_cub *cl;
uint16_t x;
uint16_t y;
- rl = &cl->rlist;
+ cl = (t_cub *)vargp;
y = (cl->wlist.y_size / 2);
while (y < cl->wlist.y_size)
{
- ft_floor_cast_inits(y, rl, cl);
+ ft_floor_cast_inits(y, &cl->rlist, cl);
x = 0;
while (x < cl->wlist.x_size)
{
if (cl->rlist.wall_bz[x] <= y)
- {
- ft_floor_cast_loop(y, x, rl, cl);
- }
- rl->x_floor += cl->mlist.x_floor_step;
- rl->y_floor += cl->mlist.y_floor_step;
+ ft_floor_cast_loop(y, x, &cl->rlist, cl);
+ cl->rlist.x_floor += cl->mlist.x_floor_step;
+ cl->rlist.y_floor += cl->mlist.y_floor_step;
x++;
}
y++;
}
+ return (0x0);
}
diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c
index 99fabeb..89cc61f 100644
--- a/src/ft_raycasting.c
+++ b/src/ft_raycasting.c
@@ -15,6 +15,7 @@
#include <stdint.h>
#include <stdlib.h>
#include <math.h>
+#include <pthread.h>
static void
ft_calc_tex(t_cub *cl)
@@ -89,31 +90,32 @@ static void
void
ft_castray(t_cub *cl)
{
+ pthread_t tid[2];
uint16_t i;
- if (!(cl->rlist.wall_dist_tab =
- (float*)malloc(sizeof(float) * cl->wlist.x_size)))
+ if (!(cl->rlist.wall_dist_tab = (float*)malloc(cl->wlist.x_size *
+ sizeof(float))) ||
+ !(cl->rlist.wall_bz = (int16_t*)malloc(cl->wlist.x_size *
+ sizeof(int16_t))) ||
+ !(cl->rlist.w_side_tab = (uint8_t*)malloc(cl->wlist.x_size *
+ sizeof(uint8_t))) ||
+ !(cl->rlist.line_h_tab = (uint16_t*)malloc(cl->wlist.x_size *
+ sizeof(uint16_t))) ||
+ !(cl->rlist.wall_t_tab = (int16_t*)malloc(cl->wlist.x_size *
+ sizeof(int16_t))) ||
+ !(cl->rlist.tex_x_tab = (int32_t*)malloc(cl->wlist.x_size *
+ sizeof(int32_t))))
return ;
- if (!(cl->rlist.wall_bz =
- (int16_t*)malloc(cl->wlist.x_size * sizeof(int16_t))))
- return ;
- cl->rlist.w_side_tab = (uint8_t*)malloc(cl->wlist.x_size * sizeof(uint8_t));
- cl->rlist.line_h_tab = (uint16_t*)malloc(cl->wlist.x_size * sizeof(uint16_t));
- cl->rlist.wall_t_tab = (int16_t*)malloc(cl->wlist.x_size * sizeof(int16_t));
- cl->rlist.tex_x_tab = (int32_t*)malloc(cl->wlist.x_size * sizeof(int32_t));
i = 0;
while (i < cl->wlist.x_size)
{
ft_castray_loop(i, &cl->wlist, cl);
i++;
}
- i = 0;
- while (i < cl->wlist.x_size)
- {
- ft_draw_verline(cl, i, cl->rlist.wall_t_tab[i], cl->rlist.wall_bz[i]);
- i++;
- }
- ft_floor_cast(cl);
+ pthread_create(&tid[0], 0x0, ft_wall_cast, (void*)cl);
+ pthread_create(&tid[1], 0x0, ft_floor_cast, (void*)cl);
+ pthread_join(tid[0], 0x0);
+ pthread_join(tid[1], 0x0);
ft_calc_sprite(cl);
ft_calc_heal(cl);
ft_calc_trap(cl);
diff --git a/src/ft_wall_cast.c b/src/ft_wall_cast.c
new file mode 100644
index 0000000..b10d2a6
--- /dev/null
+++ b/src/ft_wall_cast.c
@@ -0,0 +1,199 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_wall_cast.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:22:23 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:23:42 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <cub3d.h>
+#include <stdint.h>
+#include <pthread.h>
+
+static void
+ ft_draw_verline(t_cub *cl, int32_t x, int32_t y, int32_t y2)
+{
+ int32_t d;
+ int32_t tex_y;
+
+ (y < 0) ? (y = 0) : 0;
+ (y2 < 0) ? (y2 = 0) : 0;
+ (cl->rlist.line_h_tab[x] <= 0) ? (cl->rlist.line_h_tab[x] = 1) : 0;
+ while (y < y2)
+ {
+ d = y * 256 - cl->wlist.y_size * 128 + cl->rlist.line_h_tab[x] * 128;
+ d = (d <= 0) ? (-d) : (d);
+ tex_y = ((d * cl->tlist[cl->rlist.w_side_tab[x]].img_h)
+ / cl->rlist.line_h_tab[x]) / 256;
+ (tex_y <= 0) ? (tex_y = 1) : 0;
+ ft_draw_texture(cl, x, y, tex_y);
+ y++;
+ }
+}
+
+static void
+*ft_wall_one(void *vargp)
+{
+ t_cub *cl;
+ uint16_t i;
+
+ cl = (t_cub *)vargp;
+ i = 0;
+ while (i < cl->wlist.x_size / 8)
+ {
+ ft_draw_verline(cl, i, cl->rlist.wall_t_tab[i], cl->rlist.wall_bz[i]);
+ i++;
+ }
+ pthread_exit(0x0);
+ return (0x0);
+}
+
+static void
+*ft_wall_two(void *vargp)
+{
+ t_cub *cl;
+ uint16_t i;
+
+ cl = (t_cub *)vargp;
+ i = cl->wlist.x_size / 8;
+ while (i < 2 * (cl->wlist.x_size / 8))
+ {
+ ft_draw_verline(cl, i, cl->rlist.wall_t_tab[i], cl->rlist.wall_bz[i]);
+ i++;
+ }
+ pthread_exit(0x0);
+ return (0x0);
+}
+
+static void
+*ft_wall_three(void *vargp)
+{
+ t_cub *cl;
+ uint16_t i;
+
+ cl = (t_cub *)vargp;
+ i = 2 * (cl->wlist.x_size / 8);
+ while (i < 3 * (cl->wlist.x_size / 8))
+ {
+ ft_draw_verline(cl, i, cl->rlist.wall_t_tab[i], cl->rlist.wall_bz[i]);
+ i++;
+ }
+ pthread_exit(0x0);
+ return (0x0);
+}
+
+static void
+*ft_wall_four(void *vargp)
+{
+ t_cub *cl;
+ uint16_t i;
+
+ cl = (t_cub *)vargp;
+ i = 3 * (cl->wlist.x_size / 8);
+ while (i < 4 * (cl->wlist.x_size / 8))
+ {
+ ft_draw_verline(cl, i, cl->rlist.wall_t_tab[i], cl->rlist.wall_bz[i]);
+ i++;
+ }
+ pthread_exit(0x0);
+ return (0x0);
+}
+
+static void
+*ft_wall_five(void *vargp)
+{
+ t_cub *cl;
+ uint16_t i;
+
+ cl = (t_cub *)vargp;
+ i = 4 * (cl->wlist.x_size / 8);
+ while (i < 5 * (cl->wlist.x_size / 8))
+ {
+ ft_draw_verline(cl, i, cl->rlist.wall_t_tab[i], cl->rlist.wall_bz[i]);
+ i++;
+ }
+ pthread_exit(0x0);
+ return (0x0);
+}
+
+static void
+*ft_wall_six(void *vargp)
+{
+ t_cub *cl;
+ uint16_t i;
+
+ cl = (t_cub *)vargp;
+ i = 5 * (cl->wlist.x_size / 8);
+ while (i < 6 * (cl->wlist.x_size / 8))
+ {
+ ft_draw_verline(cl, i, cl->rlist.wall_t_tab[i], cl->rlist.wall_bz[i]);
+ i++;
+ }
+ pthread_exit(0x0);
+ return (0x0);
+}
+
+static void
+*ft_wall_seven(void *vargp)
+{
+ t_cub *cl;
+ uint16_t i;
+
+ cl = (t_cub *)vargp;
+ i = 6 * (cl->wlist.x_size / 8);
+ while (i < 7 * (cl->wlist.x_size / 8))
+ {
+ ft_draw_verline(cl, i, cl->rlist.wall_t_tab[i], cl->rlist.wall_bz[i]);
+ i++;
+ }
+ pthread_exit(0x0);
+ return (0x0);
+}
+
+static void
+*ft_wall_eight(void *vargp)
+{
+ t_cub *cl;
+ uint16_t i;
+
+ cl = (t_cub *)vargp;
+ i = 7 * (cl->wlist.x_size / 8);
+ while (i < cl->wlist.x_size)
+ {
+ ft_draw_verline(cl, i, cl->rlist.wall_t_tab[i], cl->rlist.wall_bz[i]);
+ i++;
+ }
+ pthread_exit(0x0);
+ return (0x0);
+}
+
+void
+ *ft_wall_cast(void *vargp)
+{
+ pthread_t tid[8];
+ t_cub *cl;
+
+ cl = (t_cub *)vargp;
+ pthread_create(&tid[0], 0x0, ft_wall_one, (void*)cl);
+ pthread_create(&tid[1], 0x0, ft_wall_two, (void*)cl);
+ pthread_create(&tid[2], 0x0, ft_wall_three, (void*)cl);
+ pthread_create(&tid[3], 0x0, ft_wall_four, (void*)cl);
+ pthread_create(&tid[4], 0x0, ft_wall_five, (void*)cl);
+ pthread_create(&tid[5], 0x0, ft_wall_six, (void*)cl);
+ pthread_create(&tid[6], 0x0, ft_wall_seven, (void*)cl);
+ pthread_create(&tid[7], 0x0, ft_wall_eight, (void*)cl);
+ pthread_join(tid[0], 0x0);
+ pthread_join(tid[1], 0x0);
+ pthread_join(tid[2], 0x0);
+ pthread_join(tid[3], 0x0);
+ pthread_join(tid[4], 0x0);
+ pthread_join(tid[5], 0x0);
+ pthread_join(tid[6], 0x0);
+ pthread_join(tid[7], 0x0);
+ pthread_exit(0x0);
+ return (0x0);
+}