aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRudy Bousset <rbousset@z2r5p6.le-101.fr>2020-03-09 17:41:08 +0100
committerRudy Bousset <rbousset@z2r5p6.le-101.fr>2020-03-09 17:41:08 +0100
commitfffd37b3423720af58c416221ffbdbc5960b1439 (patch)
treed5f8c2946fff86e5bcc533484cf886bfd92c048e
parentPerf (diff)
download42-cub3d-fffd37b3423720af58c416221ffbdbc5960b1439.tar.gz
42-cub3d-fffd37b3423720af58c416221ffbdbc5960b1439.tar.bz2
42-cub3d-fffd37b3423720af58c416221ffbdbc5960b1439.tar.xz
42-cub3d-fffd37b3423720af58c416221ffbdbc5960b1439.tar.zst
42-cub3d-fffd37b3423720af58c416221ffbdbc5960b1439.zip
Norme
Diffstat (limited to '')
-rw-r--r--inc/cub3d.h2
-rw-r--r--inc/cub3d_structs.h1
-rw-r--r--src/ft_detect.c3
-rw-r--r--src/ft_floor_cast.c19
-rw-r--r--src/ft_init_funptr.c19
-rw-r--r--src/ft_init_lists.c1
-rw-r--r--src/ft_parse_map.c12
-rw-r--r--src/ft_raycasting.c44
-rw-r--r--src/ft_select_get.c16
-rw-r--r--src/ft_set_minimap_scale.c1
-rw-r--r--src/ft_tex_init.c20
11 files changed, 53 insertions, 85 deletions
diff --git a/inc/cub3d.h b/inc/cub3d.h
index 39df1ea..a961dcb 100644
--- a/inc/cub3d.h
+++ b/inc/cub3d.h
@@ -23,6 +23,7 @@
*/
void ft_init_funptr(t_cub *clist);
+void ft_init_ref(t_cub *clist);
int8_t ft_init_cub3d(t_cub *clist);
int ft_init_winlx(t_cub *clist);
int ft_init_winptr(t_cub *clist);
@@ -56,7 +57,6 @@ int32_t ft_convert_keycode(const int32_t tmp_code);
void ft_wall_tex_init(t_cub *clist);
void ft_choose_tex(t_cub *clist);
-void ft_calc_tex(t_cub *clist);
/*
** ====== DRAW ======
diff --git a/inc/cub3d_structs.h b/inc/cub3d_structs.h
index 7149b4d..1160015 100644
--- a/inc/cub3d_structs.h
+++ b/inc/cub3d_structs.h
@@ -201,6 +201,7 @@ typedef struct s_cub
pid_t mpid;
int (*key_ptr[6])(struct s_cub*);
int8_t (*get_ptr[12])(char**, struct s_cub*);
+ char ref[13][3];
struct s_win wlist;
struct s_player plist;
struct s_map mlist;
diff --git a/src/ft_detect.c b/src/ft_detect.c
index 42ecb3f..7ec0473 100644
--- a/src/ft_detect.c
+++ b/src/ft_detect.c
@@ -74,7 +74,8 @@ void
cl->rlist.sqy += cl->mlist.y_step;
cl->rlist.side = 1;
}
- if (ft_ischarset(FT_CHRST_DETECT, cl->mlist.map[cl->rlist.sqx][cl->rlist.sqy]))
+ if (ft_ischarset(FT_CHRST_DETECT,
+ cl->mlist.map[cl->rlist.sqx][cl->rlist.sqy]))
cl->rlist.hit = 1;
}
}
diff --git a/src/ft_floor_cast.c b/src/ft_floor_cast.c
index 715eacc..6111eca 100644
--- a/src/ft_floor_cast.c
+++ b/src/ft_floor_cast.c
@@ -17,8 +17,7 @@ static void
ft_draw_plain_horizontal(t_rgb rgb, t_cub *cl, int32_t y, int32_t x)
{
*(int*)(cl->img.ptr +
- (x * 4 + (y * cl->img.sizeline)))
- = ft_darken(rgb, cl);
+ (x * 4 + (y * cl->img.sizeline))) = ft_darken(rgb, cl);
}
static void
@@ -47,14 +46,14 @@ static void
static void
ft_set_tex_xy(uint8_t tid, t_ray *rl, t_cub *cl)
{
- cl->tlist[tid].tex_y = (int32_t)(cl->tlist[tid].img_w
- * (rl->x_floor - rl->x_cell)) % (cl->tlist[tid].img_w);
- cl->tlist[tid].tex_x = (int32_t)(cl->tlist[tid].img_h
- * (rl->y_floor - rl->y_cell)) % (cl->tlist[tid].img_h);
- cl->tlist[tid].tex_x = (cl->tlist[tid].tex_x > 0)
- ? (cl->tlist[tid].tex_x) : (-cl->tlist[tid].tex_x);
- cl->tlist[tid].tex_y = (cl->tlist[tid].tex_y > 0)
- ? (cl->tlist[tid].tex_y) : (-cl->tlist[tid].tex_y);
+ cl->tlist[tid].tex_y = (int32_t)(cl->tlist[tid].img_w
+ * (rl->x_floor - rl->x_cell)) % (cl->tlist[tid].img_w);
+ cl->tlist[tid].tex_x = (int32_t)(cl->tlist[tid].img_h
+ * (rl->y_floor - rl->y_cell)) % (cl->tlist[tid].img_h);
+ cl->tlist[tid].tex_x = (cl->tlist[tid].tex_x > 0)
+ ? (cl->tlist[tid].tex_x) : (-cl->tlist[tid].tex_x);
+ cl->tlist[tid].tex_y = (cl->tlist[tid].tex_y > 0)
+ ? (cl->tlist[tid].tex_y) : (-cl->tlist[tid].tex_y);
}
static void
diff --git a/src/ft_init_funptr.c b/src/ft_init_funptr.c
index 75b3cee..f95e020 100644
--- a/src/ft_init_funptr.c
+++ b/src/ft_init_funptr.c
@@ -10,9 +10,28 @@
/* */
/* ************************************************************************** */
+#include <libft.h>
#include <cub3d.h>
void
+ ft_init_ref(t_cub *clist)
+{
+ ft_sprintf(clist->ref[0], "R");
+ ft_sprintf(clist->ref[1], "NO");
+ ft_sprintf(clist->ref[2], "SO");
+ ft_sprintf(clist->ref[3], "EA");
+ ft_sprintf(clist->ref[4], "WE");
+ ft_sprintf(clist->ref[5], "S");
+ ft_sprintf(clist->ref[6], "F");
+ ft_sprintf(clist->ref[7], "C");
+ ft_sprintf(clist->ref[8], "L");
+ ft_sprintf(clist->ref[9], "LT");
+ ft_sprintf(clist->ref[10], "MU");
+ ft_sprintf(clist->ref[11], "SH");
+ ft_bzero(clist->ref[12], 3);
+}
+
+void
ft_init_funptr(t_cub *clist)
{
clist->key_ptr[0] = ft_w_key;
diff --git a/src/ft_init_lists.c b/src/ft_init_lists.c
index e4eb72d..d27df52 100644
--- a/src/ft_init_lists.c
+++ b/src/ft_init_lists.c
@@ -79,6 +79,7 @@ static int8_t
cl->currlvl = 0;
cl->walltexgood = 0;
ft_init_funptr(cl);
+ ft_init_ref(cl);
return (0);
}
diff --git a/src/ft_parse_map.c b/src/ft_parse_map.c
index a93cca3..f1df73d 100644
--- a/src/ft_parse_map.c
+++ b/src/ft_parse_map.c
@@ -6,7 +6,7 @@
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/14 17:28:56 by rbousset #+# #+# */
-/* Updated: 2020/02/14 17:28:56 by rbousset ### ########lyon.fr */
+/* Updated: 2020/03/09 17:27:29 by rbousset ### ########lyon.fr */
/* */
/* ************************************************************************** */
@@ -64,14 +64,12 @@ static int8_t
return (ft_parse_it(fd, clist));
}
if (ft_ischarset("1 ", line[0]))
- return ((ft_get_map_first_line(line, clist) < 0) ?
- (-1) : (FT_PARSE_END_RET));
- if (!ft_ischarset(FT_CHRST_VALID_PARSE, line[0])
- || !(words = ft_split(line, ' ')))
+ return ((ft_get_map_first_line(line, clist) < 0) ? (-1) : (25));
+ if (!ft_ischarset(FT_CHRST_VALID_PARSE, line[0]) ||
+ !(words = ft_split(line, ' ')))
return (ft_error_here(FT_ERR_ILL_ENTRY, line, clist));
if ((ret = ft_select_get(words, clist)) == FT_PARSE_END_RET)
- return ((ft_get_map_first_line(line, clist) < 0) ?
- (-1) : (FT_PARSE_END_RET));
+ return ((ft_get_map_first_line(line, clist) < 0) ? (-1) : (25));
ft_memdel((void**)&line);
return (ret);
}
diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c
index 1c5818a..bf84b9e 100644
--- a/src/ft_raycasting.c
+++ b/src/ft_raycasting.c
@@ -16,47 +16,7 @@
#include <stdlib.h>
#include <math.h>
-/* static void */
-/* ft_calc_sprite_norme(t_cub *cl) */
-/* { */
-/* if (cl->sp_list.s_start_y < 0) */
-/* cl->sp_list.s_start_y = 0; */
-/* cl->sp_list.s_end_y = cl->sp_list.s_h / 2 + cl->wlist.y_size / 2; */
-/* if (cl->sp_list.s_end_y > (int)cl->wlist.y_size) */
-/* cl->sp_list.s_end_y = cl->wlist.y_size - 1; */
-/* cl->sp_list.s_w = abs((int)(cl->wlist.x_size */
-/* * cl->sp_list.sprite_transform_y)); /\*sprite width*\/ */
-/* cl->sp_list.s_start_x = -cl->sp_list.s_w / 2 + cl->sp_list.s_screen_x; */
-/* if (cl->sp_list.s_start_x < 0) */
-/* cl->sp_list.s_start_y = 0; */
-/* cl->sp_list.s_end_x = cl->sp_list.s_w / 2 + cl->wlist.x_size; */
-/* if (cl->sp_list.s_end_x < (int)cl->wlist.x_size) */
-/* cl->sp_list.s_end_x = cl->wlist.x_size - 1; */
-/* } */
-
-/* static void */
-/* ft_calc_sprite(t_cub *cl) */
-/* { */
-/* cl->sp_list.s_x = cl->sp_list.s_pos_x - cl->plist.pos_x; */
-/* cl->sp_list.s_y = cl->sp_list.s_pos_y - cl->plist.pos_y; */
-/* cl->sp_list.inv_c_m = 1.0 / (cl->plist.plane_x * cl->plist.dir_x */
-/* - cl->plist.dir_y * cl->plist.plane_y); */
-/* cl->sp_list.sprite_transform_x = cl->sp_list.inv_c_m */
-/* * (cl->plist.dir_y * cl->sp_list.s_x */
-/* - cl->plist.dir_x * cl->sp_list.s_y); */
-/* cl->sp_list.sprite_transform_y = cl->sp_list.inv_c_m */
-/* * (cl->plist.plane_y * cl->sp_list.s_x */
-/* - cl->plist.plane_x * cl->sp_list.s_y); */
-/* cl->sp_list.s_screen_x = (int)((cl->wlist.y_size / 2) */
-/* * (1 + cl->sp_list.sprite_transform_x */
-/* / cl->sp_list.sprite_transform_y)); */
-/* cl->sp_list.s_h = */
-/* abs((int)(cl->wlist.y_size * cl->sp_list.sprite_transform_y)); */
-/* cl->sp_list.s_start_y = -cl->sp_list.s_h / 2 + cl->wlist.y_size / 2; */
-/* ft_calc_sprite_norme(cl); */
-/* } */
-
-void
+static void
ft_calc_tex(t_cub *clist)
{
if (clist->rlist.side == 0)
@@ -129,8 +89,6 @@ void
cl->rlist.wall_b = wl->y_size - 1;
ft_choose_tex(cl);
ft_calc_tex(cl);
- /* ft_calc_sprite(cl); */
- /* ft_draw_sprite(cl , i); */
ft_draw_verline(cl, i, cl->rlist.wall_t, cl->rlist.wall_b);
i++;
}
diff --git a/src/ft_select_get.c b/src/ft_select_get.c
index 2ed439c..c246d25 100644
--- a/src/ft_select_get.c
+++ b/src/ft_select_get.c
@@ -60,25 +60,11 @@ static int8_t
ft_get_id(char **words, t_cub *clist)
{
int8_t ret;
- char ref[13][3];
- ft_sprintf(ref[0], "R");
- ft_sprintf(ref[1], "NO");
- ft_sprintf(ref[2], "SO");
- ft_sprintf(ref[3], "EA");
- ft_sprintf(ref[4], "WE");
- ft_sprintf(ref[5], "S");
- ft_sprintf(ref[6], "F");
- ft_sprintf(ref[7], "C");
- ft_sprintf(ref[8], "L");
- ft_sprintf(ref[9], "LT");
- ft_sprintf(ref[10], "MU");
- ft_sprintf(ref[11], "SH");
- ft_bzero(ref[12], 3);
if (words[0][0] == ' ' || words[0][0] == '1')
return (FT_PARSE_END_RET);
ret = 0;
- while (ft_strncmp(words[0], ref[ret], 3) && ref[ret][0])
+ while (ft_strncmp(words[0], clist->ref[ret], 3) && clist->ref[ret][0])
ret++;
if (ret == 12)
ret = FT_PARSE_END_RET;
diff --git a/src/ft_set_minimap_scale.c b/src/ft_set_minimap_scale.c
index ed5ca1a..14a6f56 100644
--- a/src/ft_set_minimap_scale.c
+++ b/src/ft_set_minimap_scale.c
@@ -12,7 +12,6 @@
#include <cub3d.h>
-#include <libft.h>
void
ft_set_minimap_scale(t_cub *clist)
{
diff --git a/src/ft_tex_init.c b/src/ft_tex_init.c
index 1fce584..adc7fd0 100644
--- a/src/ft_tex_init.c
+++ b/src/ft_tex_init.c
@@ -51,6 +51,18 @@ static void
&cl->tlist[7].bpp, &cl->tlist[7].sizeline, &cl->tlist[7].endian);
}
+static void
+ ft_wall_tex_init_norme(t_cub *cl)
+{
+ if (cl->mlist.isnlvl)
+ ft_get_nlvl_img(cl);
+ if (cl->mlist.isftex)
+ ft_get_floor_tex(cl);
+ if (cl->mlist.isctex)
+ ft_get_ceil_tex(cl);
+ cl->walltexgood = 1;
+}
+
void
ft_wall_tex_init(t_cub *cl)
{
@@ -74,11 +86,5 @@ void
cl->mlist.sprite_path, &cl->tlist[4].img_w, &cl->tlist[4].img_h);
cl->tlist[4].ptr = mlx_get_data_addr(cl->tlist[4].img,
&cl->tlist[4].bpp, &cl->tlist[4].sizeline, &cl->tlist[4].endian);
- if (cl->mlist.isnlvl)
- ft_get_nlvl_img(cl);
- if (cl->mlist.isftex)
- ft_get_floor_tex(cl);
- if (cl->mlist.isctex)
- ft_get_ceil_tex(cl);
- cl->walltexgood = 1;
+ ft_wall_tex_init_norme(cl);
}