diff options
| author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-03 16:57:36 +0100 | 
|---|---|---|
| committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-03 16:57:36 +0100 | 
| commit | d4f853942aa2031c4bd85539ef9f3470967ffdc5 (patch) | |
| tree | d2c5ffb0027860722185bf26b526757360ff1584 | |
| parent | tweaks (diff) | |
| parent | Going full stack is bav (diff) | |
| download | 42-cub3d-d4f853942aa2031c4bd85539ef9f3470967ffdc5.tar.gz 42-cub3d-d4f853942aa2031c4bd85539ef9f3470967ffdc5.tar.bz2 42-cub3d-d4f853942aa2031c4bd85539ef9f3470967ffdc5.tar.xz 42-cub3d-d4f853942aa2031c4bd85539ef9f3470967ffdc5.tar.zst 42-cub3d-d4f853942aa2031c4bd85539ef9f3470967ffdc5.zip | |
Merge branch 'bmp'
Diffstat (limited to '')
38 files changed, 289 insertions, 312 deletions
| diff --git a/inc/cub3d.h b/inc/cub3d.h index 1f8abd4..edc462f 100644 --- a/inc/cub3d.h +++ b/inc/cub3d.h @@ -23,12 +23,12 @@  */  void		ft_init_funptr(t_cub *clist); -int8_t		ft_init_cub3d(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);  t_ray		ft_init_s_ray(void);  t_rgb		ft_init_rgb(void); -t_map		*ft_init_map(void); +int8_t		ft_init_map(t_map *mlist);  /*  ** ====== HOOKS ====== diff --git a/inc/cub3d_structs.h b/inc/cub3d_structs.h index b7d49a7..b19eae6 100644 --- a/inc/cub3d_structs.h +++ b/inc/cub3d_structs.h @@ -144,9 +144,9 @@ typedef struct		s_cub  	pthread_t		tid;  	int				(*key_ptr[6])(struct s_cub*);  	int8_t			(*get_ptr[11])(char**, struct s_cub*); -	struct s_win	*wlist; -	struct s_player	*plist; -	struct s_map	*mlist; +	struct s_win	wlist; +	struct s_player	plist; +	struct s_map	mlist;  	struct s_ray	rlist;  	struct s_img	img;  	struct s_rgb	f_rgb; diff --git a/src/ft_basic_keys.c b/src/ft_basic_keys.c index ff74262..29044d9 100644 --- a/src/ft_basic_keys.c +++ b/src/ft_basic_keys.c @@ -19,7 +19,7 @@ int  	t_player	*pl;  	const float	move_speed = FT_MOVE_SPEED; -	pl = clist->plist; +	pl = &clist->plist;  	pl->pos_y += move_speed * pl->dir_x;  	pl->pos_x += move_speed * pl->dir_y;  	return (0); @@ -31,7 +31,7 @@ int  	t_player	*pl;  	const float	move_speed = FT_STRAFE_SPEED; -	pl = clist->plist; +	pl = &clist->plist;  	pl->pos_y += move_speed * -pl->dir_y;  	pl->pos_x += move_speed * pl->dir_x;  	return (0); @@ -43,7 +43,7 @@ int  	t_player	*pl;  	const float	move_speed = FT_MOVE_SPEED; -	pl = clist->plist; +	pl = &clist->plist;  	pl->pos_y += move_speed * -pl->dir_x;  	pl->pos_x += move_speed * -pl->dir_y;  	return (0); @@ -55,7 +55,7 @@ int  	t_player	*pl;  	const float	move_speed = FT_STRAFE_SPEED; -	pl = clist->plist; +	pl = &clist->plist;  	pl->pos_y += move_speed * pl->dir_y;  	pl->pos_x += move_speed * -pl->dir_x;  	return (0); diff --git a/src/ft_check_map_line.c b/src/ft_check_map_line.c index 184e489..a3e60f5 100644 --- a/src/ft_check_map_line.c +++ b/src/ft_check_map_line.c @@ -24,15 +24,15 @@ static int8_t  		return (-1);  	}  	if (ft_ischarset("NSEW", line[i])) -		clist->mlist->isspawn += 1; -	if (clist->mlist->isspawn > 1) +		clist->mlist.isspawn += 1; +	if (clist->mlist.isspawn > 1)  	{  		ft_sprintf(clist->errmsg, "%s", FT_ERR_MULT_SPAWN);  		return (-1);  	}  	if (line[i] == 'L') -		clist->mlist->isnlvl += 1; -	if (clist->mlist->isnlvl > 1) +		clist->mlist.isnlvl += 1; +	if (clist->mlist.isnlvl > 1)  	{  		ft_sprintf(clist->errmsg, "%s", FT_ERR_MULT_NLVL);  		return (-1); @@ -100,7 +100,7 @@ int8_t  	}  	if (ft_check_side_walls(line, i, clist) < 0)  		return (-1); -	if (ft_get_line_len(line) != clist->mlist->map_w) +	if (ft_get_line_len(line) != clist->mlist.map_w)  	{  		ft_sprintf(clist->errmsg, "%s", FT_ERR_MAP_LEN);  		return (-1); diff --git a/src/ft_check_missing.c b/src/ft_check_missing.c index 4828250..02893bf 100644 --- a/src/ft_check_missing.c +++ b/src/ft_check_missing.c @@ -26,17 +26,17 @@ int  int  	ft_check_missing(t_cub *clist)  { -	if (!clist->mlist->no_tex_path[0]) +	if (!clist->mlist.no_tex_path[0])  		return (ft_missing_error(FT_ERR_MISS_NORTH, clist)); -	else if (!clist->mlist->so_tex_path[0]) +	else if (!clist->mlist.so_tex_path[0])  		return (ft_missing_error(FT_ERR_MISS_SOUTH, clist)); -	else if (!clist->mlist->ea_tex_path[0]) +	else if (!clist->mlist.ea_tex_path[0])  		return (ft_missing_error(FT_ERR_MISS_EAST, clist)); -	else if (!clist->mlist->we_tex_path[0]) +	else if (!clist->mlist.we_tex_path[0])  		return (ft_missing_error(FT_ERR_MISS_WEST, clist)); -	else if (!clist->mlist->sprite_path[0]) +	else if (!clist->mlist.sprite_path[0])  		return (ft_missing_error(FT_ERR_MISS_SPRITE, clist)); -	else if (clist->wlist->x_size == 0 || clist->wlist->y_size == 0) +	else if (clist->wlist.x_size == 0 || clist->wlist.y_size == 0)  		return (ft_missing_error(FT_ERR_MISS_RESOLUTION, clist));  	else if (clist->f_rgb.r == -1 || clist->f_rgb.g == -1  				|| clist->f_rgb.b == -1) @@ -44,11 +44,11 @@ int  	else if (clist->c_rgb.r == -1 || clist->c_rgb.g == -1  				|| clist->c_rgb.b == -1)  		return (ft_missing_error(FT_ERR_MISS_CEIL_C, clist)); -	else if (clist->plist->pos_x == 0 || clist->plist->pos_y == 0) +	else if (clist->plist.pos_x == 0 || clist->plist.pos_y == 0)  		return (ft_missing_error(FT_ERR_MISS_PLAYER_SPAWN, clist)); -	else if (clist->mlist->isnlvl && !clist->mlist->nl_tex_path[0]) +	else if (clist->mlist.isnlvl && !clist->mlist.nl_tex_path[0])  		return (ft_missing_error(FT_ERR_MISS_NLVL, clist)); -	else if (clist->mlist->isnlvl && !clist->mlist->nlevel_path[0]) +	else if (clist->mlist.isnlvl && !clist->mlist.nlevel_path[0])  		return (ft_missing_error(FT_ERR_MISS_NLVL_PATH, clist));  	return (0);  } diff --git a/src/ft_detect.c b/src/ft_detect.c index a8b5a6c..8ab3d57 100644 --- a/src/ft_detect.c +++ b/src/ft_detect.c @@ -22,13 +22,13 @@ static void  		cl->rlist.y_ray_dir));  	if (cl->rlist.y_ray_dir < 0)  	{ -		cl->mlist->y_step = -1; +		cl->mlist.y_step = -1;  		cl->rlist.y_side_dist = (cl->rlist.y_ray_pos -  			cl->rlist.sqy) * cl->rlist.y_delta_dist;  	}  	else  	{ -		cl->mlist->y_step = 1; +		cl->mlist.y_step = 1;  		cl->rlist.y_side_dist = (cl->rlist.sqy + 1.0 -  			cl->rlist.y_ray_pos) * cl->rlist.y_delta_dist;  	} @@ -42,13 +42,13 @@ static void  		cl->rlist.x_ray_dir));  	if (cl->rlist.x_ray_dir < 0)  	{ -		cl->mlist->x_step = -1; +		cl->mlist.x_step = -1;  		cl->rlist.x_side_dist = (cl->rlist.x_ray_pos -  			cl->rlist.sqx) * cl->rlist.x_delta_dist;  	}  	else  	{ -		cl->mlist->x_step = 1; +		cl->mlist.x_step = 1;  		cl->rlist.x_side_dist = (cl->rlist.sqx + 1.0 -  			cl->rlist.x_ray_pos) * cl->rlist.x_delta_dist;  	} @@ -65,17 +65,17 @@ void  		if (cl->rlist.x_side_dist < cl->rlist.y_side_dist)  		{  			cl->rlist.x_side_dist += cl->rlist.x_delta_dist; -			cl->rlist.sqx += cl->mlist->x_step; +			cl->rlist.sqx += cl->mlist.x_step;  			cl->rlist.side = 0;  		}  		else  		{  			cl->rlist.y_side_dist += cl->rlist.y_delta_dist; -			cl->rlist.sqy += cl->mlist->y_step; +			cl->rlist.sqy += cl->mlist.y_step;  			cl->rlist.side = 1;  		} -		if (cl->mlist->map[cl->rlist.sqx][cl->rlist.sqy] == '1' || -			cl->mlist->map[cl->rlist.sqx][cl->rlist.sqy] == 'L') +		if (cl->mlist.map[cl->rlist.sqx][cl->rlist.sqy] == '1' || +			cl->mlist.map[cl->rlist.sqx][cl->rlist.sqy] == 'L')  			cl->rlist.hit = 1;  	}  } diff --git a/src/ft_draw_circle.c b/src/ft_draw_circle.c index 570543a..249b2e9 100644 --- a/src/ft_draw_circle.c +++ b/src/ft_draw_circle.c @@ -25,7 +25,7 @@ void  	float	y1;  	i = 0; -	scale = cl->mlist->scale / 2.5; +	scale = cl->mlist.scale / 2.5;  	while (scale > 0)  	{  		while (i < 360) diff --git a/src/ft_draw_hud.c b/src/ft_draw_hud.c index 9cb5b1c..e1439ae 100644 --- a/src/ft_draw_hud.c +++ b/src/ft_draw_hud.c @@ -17,14 +17,14 @@  static void  	ft_draw_hud_back(t_win *wl, t_cub *cl)  { -	const uint16_t	scl = cl->mlist->scale; +	const uint16_t	scl = cl->mlist.scale;  	uint32_t		x;  	uint32_t		y;  	int32_t			col;  	col = 0x00404040;  	x = 0; -	y = wl->y_size - ((cl->mlist->map_h * scl)); +	y = wl->y_size - ((cl->mlist.map_h * scl));  	while (x < wl->x_size)  	{  		while (y < wl->y_size) @@ -38,7 +38,7 @@ static void  			y++;  		}  		col = 0x00404040; -		y = wl->y_size - ((cl->mlist->map_h * scl)); +		y = wl->y_size - ((cl->mlist.map_h * scl));  		x++;  	}  } @@ -46,7 +46,7 @@ static void  static void  	ft_draw_hud_back_top_l(size_t map_h, size_t map_w, t_win *wl, t_cub *cl)  { -	const uint16_t	scl = cl->mlist->scale; +	const uint16_t	scl = cl->mlist.scale;  	uint32_t		x;  	uint32_t		y;  	int32_t			col; @@ -75,7 +75,7 @@ static void  static void  	ft_draw_hud_back_top_r(size_t map_h, size_t map_w, t_win *wl, t_cub *cl)  { -	const uint16_t	scl = cl->mlist->scale; +	const uint16_t	scl = cl->mlist.scale;  	uint32_t		x;  	uint32_t		y;  	int32_t			col; @@ -104,10 +104,10 @@ static void  void  	ft_draw_hud(t_cub *clist)  { -	ft_draw_hud_back(clist->wlist, clist); -	ft_draw_hud_back_top_l(clist->mlist->map_h, -		clist->mlist->map_w, clist->wlist, clist); -	ft_draw_hud_back_top_r(clist->mlist->map_h, -		clist->mlist->map_w, clist->wlist, clist); -	ft_draw_map(clist->mlist->map, clist); +	ft_draw_hud_back(&clist->wlist, clist); +	ft_draw_hud_back_top_l(clist->mlist.map_h, +		clist->mlist.map_w, &clist->wlist, clist); +	ft_draw_hud_back_top_r(clist->mlist.map_h, +		clist->mlist.map_w, &clist->wlist, clist); +	ft_draw_map(clist->mlist.map, clist);  } diff --git a/src/ft_draw_map.c b/src/ft_draw_map.c index a334fc1..acf671a 100644 --- a/src/ft_draw_map.c +++ b/src/ft_draw_map.c @@ -16,15 +16,15 @@  static uint16_t  	ft_y_offset(t_cub *clist)  { -	return (clist->wlist->y_size -				- (clist->mlist->map_h * clist->mlist->scale) -				+ clist->mlist->scale - 1); +	return (clist->wlist.y_size +				- (clist->mlist.map_h * clist->mlist.scale) +				+ clist->mlist.scale - 1);  }  static void  	ft_draw_player(t_player *plist, t_cub *clist)  { -	const uint16_t	scale = clist->mlist->scale; +	const uint16_t	scale = clist->mlist.scale;  	const float		x = plist->pos_x;  	const float		y = plist->pos_y; @@ -38,7 +38,7 @@ static void  void  	ft_draw_map(char **map, t_cub *clist)  { -	const uint8_t	scale = clist->mlist->scale; +	const uint8_t	scale = clist->mlist.scale;  	size_t			x;  	size_t			y; @@ -62,5 +62,5 @@ void  		x = 0;  		y++;  	} -	ft_draw_player(clist->plist, clist); +	ft_draw_player(&clist->plist, clist);  } diff --git a/src/ft_draw_scene.c b/src/ft_draw_scene.c index a356cab..345c66b 100644 --- a/src/ft_draw_scene.c +++ b/src/ft_draw_scene.c @@ -18,26 +18,26 @@  void  	ft_draw_scene(t_cub *clist)  { -	clist->img.img = mlx_new_image(clist->wlist->wlx, -				clist->wlist->x_size, clist->wlist->y_size); +	clist->img.img = mlx_new_image(clist->wlist.wlx, +				clist->wlist.x_size, clist->wlist.y_size);  	clist->img.ptr = mlx_get_data_addr(clist->img.img, &clist->img.bpp,  				&clist->img.sizeline, &clist->img.endian);  	ft_castray(clist);  	if (clist->ishud)  		ft_draw_hud(clist); -	mlx_put_image_to_window(clist->wlist->wlx, -							clist->wlist->winptr, clist->img.img, 0, 0); -	mlx_destroy_image(clist->wlist->wlx, clist->img.img); +	mlx_put_image_to_window(clist->wlist.wlx, +							clist->wlist.winptr, clist->img.img, 0, 0); +	mlx_destroy_image(clist->wlist.wlx, clist->img.img);  }  void  	ft_draw_scene_bmp(t_cub *clist)  { -	clist->img.img = mlx_new_image(clist->wlist->wlx, -				clist->wlist->x_size, clist->wlist->y_size); +	clist->img.img = mlx_new_image(clist->wlist.wlx, +				clist->wlist.x_size, clist->wlist.y_size);  	clist->img.ptr = mlx_get_data_addr(clist->img.img, &clist->img.bpp,  				&clist->img.sizeline, &clist->img.endian);  	ft_castray(clist); -	mlx_destroy_image(clist->wlist->wlx, clist->img.img); +	mlx_destroy_image(clist->wlist.wlx, clist->img.img);  	ft_save_to_bmp();  } diff --git a/src/ft_draw_sprite.c b/src/ft_draw_sprite.c index 9cd7dae..9dc1b63 100644 --- a/src/ft_draw_sprite.c +++ b/src/ft_draw_sprite.c @@ -30,7 +30,7 @@ void  	cl->img.ptr[x * 4 + (cl->img.sizeline * y) + 2] =  			(char)cl->tlist[4].ptr[cl->tlist[4].tex_x * 4 + 4 *  									cl->tlist[4].img_h * tex_y + 2]; -	cl->img.ptr[x * 4 + cl->wlist->x_size * y + 3] = (char)0; +	cl->img.ptr[x * 4 + cl->wlist.x_size * y + 3] = (char)0;  }  void @@ -43,7 +43,7 @@ void  	hor_it = cl->sp_list.s_start_y;  	while (hor_it < cl->sp_list.s_end_y)  	{ -		d = hor_it * 256 - cl->wlist->y_size * 128 + cl->rlist.line_h * 128; +		d = hor_it * 256 - cl->wlist.y_size * 128 + cl->rlist.line_h * 128;  		d = (d <= 0) ? (-d) : (d);  		tex_y = ((d * cl->tlist[4].img_h) / cl->rlist.line_h) / 256;  		(tex_y < 0) ? (tex_y = 0) : 0; diff --git a/src/ft_draw_square.c b/src/ft_draw_square.c index 355969e..4223f26 100644 --- a/src/ft_draw_square.c +++ b/src/ft_draw_square.c @@ -17,7 +17,7 @@  void  	ft_draw_square(int a, int b, int rgb, t_cub *clist)  { -	const uint16_t	scale = clist->mlist->scale; +	const uint16_t	scale = clist->mlist.scale;  	int				x;  	int				y; diff --git a/src/ft_draw_textures.c b/src/ft_draw_textures.c index 39d6278..00f8e5a 100644 --- a/src/ft_draw_textures.c +++ b/src/ft_draw_textures.c @@ -33,13 +33,13 @@ void	ft_draw_texture(t_cub *cl, int x, int y, int tex_y)  	cl->img.ptr[x * 4 + (cl->img.sizeline * y) + 2] =  		(char)cl->tlist[cl->w_side].ptr[cl->tlist[cl->w_side].tex_x * 4 + 4 *  		cl->tlist[cl->w_side].img_h * tex_y + 2]; -	cl->img.ptr[x * 4 + cl->wlist->x_size * y + 3] = (char)0; +	cl->img.ptr[x * 4 + cl->wlist.x_size * y + 3] = (char)0;  }  void	ft_choose_tex(t_cub *clist)  { -	if (clist->rlist.sqy == clist->mlist->nlx -		&& clist->rlist.sqx == clist->mlist->nly) +	if (clist->rlist.sqy == clist->mlist.nlx +		&& clist->rlist.sqx == clist->mlist.nly)  	{  		clist->w_side = 5;  	} diff --git a/src/ft_draw_verline.c b/src/ft_draw_verline.c index b0f9880..d9a35cc 100644 --- a/src/ft_draw_verline.c +++ b/src/ft_draw_verline.c @@ -15,7 +15,7 @@  static void  	ft_draw_floor(t_cub *cl, int32_t y, int32_t x)  { -	while ((uint32_t)y < cl->wlist->y_size) +	while ((uint32_t)y < cl->wlist.y_size)  	{  		*(int*)(cl->img.ptr +  				(x * 4 + (y * cl->img.sizeline))) = ft_rgb_to_hex(cl->f_rgb); @@ -49,7 +49,7 @@ static void  ** 	i = 0;  ** 	while (i < y)  ** 	{ -** 		d = i * 256 - cl->wlist->y_size * 128 + cl->rlist.line_h * 128; +** 		d = i * 256 - cl->wlist.y_size * 128 + cl->rlist.line_h * 128;  ** 		d = (d <= 0) ? (-d) : (d);  ** 		ft_printf("%d\n", d);  ** 		tex_y = ((d * cl->tlist[1].img_h) / cl->rlist.line_h) / 256; @@ -63,7 +63,7 @@ static void  ** 		cl->img.ptr[x * 4 + (cl->img.sizeline * i) + 2] =  ** 			(int8_t)cl->tlist[1].ptr[cl->tlist[1].tex_x * 4 + 4 *  ** 						cl->tlist[1].img_h * tex_y + 2]; -** 		cl->img.ptr[x * 4 + cl->wlist->x_size * i + 3] = (char)0; +** 		cl->img.ptr[x * 4 + cl->wlist.x_size * i + 3] = (char)0;  ** 		i++;  ** 	}  ** } @@ -81,7 +81,7 @@ int8_t  	(cl->rlist.line_h <= 0) ? (cl->rlist.line_h = 1) : 0;  	while (y < y2)  	{ -		d = y * 256 - cl->wlist->y_size * 128 + cl->rlist.line_h * 128; +		d = y * 256 - cl->wlist.y_size * 128 + cl->rlist.line_h * 128;  		d = (d <= 0) ? (-d) : (d);  		tex_y = ((d * cl->tlist[cl->w_side].img_h) / cl->rlist.line_h) / 256;  		(tex_y <= 0) ? (tex_y = 1) : 0; diff --git a/src/ft_exit.c b/src/ft_exit.c index c022627..1be7a32 100644 --- a/src/ft_exit.c +++ b/src/ft_exit.c @@ -21,23 +21,19 @@  static void  	ft_free_lists(t_cub *clist)  { -	ft_memdel((void**)&clist->mlist->no_tex_path); -	ft_memdel((void**)&clist->mlist->so_tex_path); -	ft_memdel((void**)&clist->mlist->ea_tex_path); -	ft_memdel((void**)&clist->mlist->we_tex_path); -	ft_memdel((void**)&clist->mlist->sprite_path); -	ft_memdel((void**)&clist->mlist->nl_tex_path); -	ft_memdel((void**)&clist->mlist->nlevel_path); -	ft_memdel((void**)&clist->mlist->music_path); -	ft_memdel((void**)&clist->mlist->music_cmd); -	ft_memdel((void**)&clist->mlist->mapl); -	ft_free_words(clist->mlist->map); -	ft_memdel((void**)&clist->mlist); -	ft_memdel((void**)&clist->plist); -	if (!clist->wlist->inited) -		ft_memdel((void**)&clist->wlist->winptr); -	ft_memdel((void**)&clist->wlist); -	ft_memdel((void**)&clist); +	ft_memdel((void**)&clist->mlist.no_tex_path); +	ft_memdel((void**)&clist->mlist.so_tex_path); +	ft_memdel((void**)&clist->mlist.ea_tex_path); +	ft_memdel((void**)&clist->mlist.we_tex_path); +	ft_memdel((void**)&clist->mlist.sprite_path); +	ft_memdel((void**)&clist->mlist.nl_tex_path); +	ft_memdel((void**)&clist->mlist.nlevel_path); +	ft_memdel((void**)&clist->mlist.music_path); +	ft_memdel((void**)&clist->mlist.music_cmd); +	ft_memdel((void**)&clist->mlist.mapl); +	ft_free_words(clist->mlist.map); +	if (!clist->wlist.inited) +		ft_memdel((void**)&clist->wlist.winptr);  }  int @@ -46,24 +42,24 @@ int  	if (clist->walltexgood)  	{  		if (clist->tlist[0].img) -			mlx_destroy_image(clist->wlist->wlx, clist->tlist[0].img); +			mlx_destroy_image(clist->wlist.wlx, clist->tlist[0].img);  		if (clist->tlist[1].img) -			mlx_destroy_image(clist->wlist->wlx, clist->tlist[1].img); +			mlx_destroy_image(clist->wlist.wlx, clist->tlist[1].img);  		if (clist->tlist[2].img) -			mlx_destroy_image(clist->wlist->wlx, clist->tlist[2].img); +			mlx_destroy_image(clist->wlist.wlx, clist->tlist[2].img);  		if (clist->tlist[3].img) -			mlx_destroy_image(clist->wlist->wlx, clist->tlist[3].img); +			mlx_destroy_image(clist->wlist.wlx, clist->tlist[3].img);  		if (clist->tlist[4].img) -			mlx_destroy_image(clist->wlist->wlx, clist->tlist[4].img); -		if (clist->mlist->isnlvl && clist->tlist[5].img) -			mlx_destroy_image(clist->wlist->wlx, clist->tlist[5].img); +			mlx_destroy_image(clist->wlist.wlx, clist->tlist[4].img); +		if (clist->mlist.isnlvl && clist->tlist[5].img) +			mlx_destroy_image(clist->wlist.wlx, clist->tlist[5].img);  	} -	if (clist->wlist->inited) +	if (clist->wlist.inited)  	{ -		mlx_destroy_window(clist->wlist->wlx, clist->wlist->winptr); -		clist->wlist->winptr = NULL; +		mlx_destroy_window(clist->wlist.wlx, clist->wlist.winptr); +		clist->wlist.winptr = NULL;  	} -	if (clist->isoldmus && clist->wlist->inited) +	if (clist->isoldmus && clist->wlist.inited)  	{  		pthread_cancel(clist->tid);  		pthread_join(clist->tid, NULL); diff --git a/src/ft_extra_keys.c b/src/ft_extra_keys.c index 507f808..e694667 100644 --- a/src/ft_extra_keys.c +++ b/src/ft_extra_keys.c @@ -22,7 +22,7 @@ int  	float			sav_plane_x;  	const float		rot_speed = FT_ROT_SPEED; -	pl = clist->plist; +	pl = &clist->plist;  	sav_dir_x = pl->dir_x;  	pl->dir_x = pl->dir_x * cos(rot_speed) - pl->dir_y * sin(rot_speed);  	pl->dir_y = sav_dir_x * sin(rot_speed) + pl->dir_y * cos(rot_speed); @@ -40,7 +40,7 @@ int  	float			sav_plane_x;  	const float		rot_speed = FT_ROT_SPEED; -	pl = clist->plist; +	pl = &clist->plist;  	sav_dir_x = pl->dir_x;  	pl->dir_x = pl->dir_x * cos(-rot_speed) - pl->dir_y * sin(-rot_speed);  	pl->dir_y = sav_dir_x * sin(-rot_speed) + pl->dir_y * cos(-rot_speed); diff --git a/src/ft_get_map.c b/src/ft_get_map.c index f609c50..60bcee0 100644 --- a/src/ft_get_map.c +++ b/src/ft_get_map.c @@ -50,35 +50,35 @@ static void  static int8_t  	ft_cat_mapl(char *line, size_t i, t_cub *clist)  { -	if (!(clist->mlist->mapl = (char *)ft_nrealloc(clist->mlist->mapl, -				((clist->mlist->map_w + 1) * i) * sizeof(char), -				((clist->mlist->map_w + 1) * (i + 1)) * sizeof(char)))) +	if (!(clist->mlist.mapl = (char *)ft_nrealloc(clist->mlist.mapl, +				((clist->mlist.map_w + 1) * i) * sizeof(char), +				((clist->mlist.map_w + 1) * (i + 1)) * sizeof(char))))  	{  		ft_sprintf(clist->errmsg, "%s", FT_ERR_ALLOCATE);  		return (-1);  	} -	ft_linecpy(line, clist->mlist->mapl, (clist->mlist->map_w + 1) * i); +	ft_linecpy(line, clist->mlist.mapl, (clist->mlist.map_w + 1) * i);  	return (0);  }  int  	ft_get_map_first_line(char *line, t_cub *clist)  { -	clist->mlist->map_start = clist->mlist->line_chk; +	clist->mlist.map_start = clist->mlist.line_chk;  	if (!line[0])  	{  		ft_memdel((void**)&line);  		ft_sprintf(clist->errmsg, "%s", FT_ERR_READ);  		return (-1);  	} -	clist->mlist->map_w = ft_get_line_len(line); +	clist->mlist.map_w = ft_get_line_len(line);  	if (ft_check_map_line(line, 1, clist) < 0)  	{  		ft_memdel((void**)&line);  		ft_sprintf(clist->errmsg, "%s", FT_ERR_READ);  		return (-1);  	} -	ft_memdel((void**)&clist->mlist->mapl); +	ft_memdel((void**)&clist->mlist.mapl);  	if (ft_cat_mapl(line, 0, clist) < 0)  	{  		ft_memdel((void**)&line); @@ -99,7 +99,7 @@ int  	ret = 1;  	while ((ret = get_next_line(fd, &line)) > 0)  	{ -		clist->mlist->line_chk += 1; +		clist->mlist.line_chk += 1;  		if (!line[0] || ft_check_map_line(line, 0, clist) < 0  			|| ft_cat_mapl(line, i, clist) < 0)  		{ @@ -110,10 +110,10 @@ int  		i++;  	}  	ft_memdel((void**)&line); -	clist->mlist->mapl[((clist->mlist->map_w + 1) * i) - 1] = '\0'; -	ft_free_words(clist->mlist->map); -	clist->mlist->map = ft_split(clist->mlist->mapl, '\n'); -	clist->mlist->map_h = ft_get_map_h(clist->mlist->map); -	ft_memdel((void**)&clist->mlist->mapl); +	clist->mlist.mapl[((clist->mlist.map_w + 1) * i) - 1] = '\0'; +	ft_free_words(clist->mlist.map); +	clist->mlist.map = ft_split(clist->mlist.mapl, '\n'); +	clist->mlist.map_h = ft_get_map_h(clist->mlist.map); +	ft_memdel((void**)&clist->mlist.mapl);  	return (0);  } diff --git a/src/ft_get_music.c b/src/ft_get_music.c index df65a7f..eb25af3 100644 --- a/src/ft_get_music.c +++ b/src/ft_get_music.c @@ -49,18 +49,18 @@ int8_t  		ft_sprintf(clist->errmsg, FT_ERR_NOT_A_WAV);  		return (-1);  	} -	ft_memdel((void**)&clist->mlist->music_path); -	if (!(clist->mlist->music_path = ft_strdup(*(words + 1)))) +	ft_memdel((void**)&clist->mlist.music_path); +	if (!(clist->mlist.music_path = ft_strdup(*(words + 1))))  	{  		ft_sprintf(clist->errmsg, FT_ERR_ALLOCATE);  		return (-1);  	} -	if (ft_check_not_found(clist->mlist->music_path) < 0) +	if (ft_check_not_found(clist->mlist.music_path) < 0)  	{  		ft_sprintf(clist->errmsg, FT_ERR_RD_MUSIC);  		return (-1);  	} -	clist->mlist->ismusic = 1; -	ft_set_music_cmd(clist->mlist); +	clist->mlist.ismusic = 1; +	ft_set_music_cmd(&clist->mlist);  	return (0);  } diff --git a/src/ft_get_path_nl.c b/src/ft_get_path_nl.c index b14595f..68de5c6 100644 --- a/src/ft_get_path_nl.c +++ b/src/ft_get_path_nl.c @@ -27,13 +27,13 @@ int8_t  		ft_sprintf(clist->errmsg, FT_ERR_NOT_A_CUB);  		return (-1);  	} -	ft_memdel((void**)&clist->mlist->nlevel_path); -	if (!(clist->mlist->nlevel_path = ft_strdup(*(words + 1)))) +	ft_memdel((void**)&clist->mlist.nlevel_path); +	if (!(clist->mlist.nlevel_path = ft_strdup(*(words + 1))))  	{  		ft_sprintf(clist->errmsg, FT_ERR_ALLOCATE);  		return (-1);  	} -	if (ft_check_not_found(clist->mlist->nlevel_path) < 0) +	if (ft_check_not_found(clist->mlist.nlevel_path) < 0)  	{  		ft_sprintf(clist->errmsg, FT_ERR_RD_NL_MAP);  		return (-1); diff --git a/src/ft_get_player_spawn.c b/src/ft_get_player_spawn.c index 617ec22..fabcba8 100644 --- a/src/ft_get_player_spawn.c +++ b/src/ft_get_player_spawn.c @@ -71,17 +71,17 @@ void  	x = 1;  	y = 1; -	while (clist->mlist->map[y]) +	while (clist->mlist.map[y])  	{ -		while (clist->mlist->map[y][x]) +		while (clist->mlist.map[y][x])  		{ -			if (ft_ischarset("NSEW", clist->mlist->map[y][x])) +			if (ft_ischarset("NSEW", clist->mlist.map[y][x]))  			{  				plist->pos_x = x + 0.5;  				plist->pos_y = y + 0.5;  				plist->start_x = plist->pos_x;  				plist->start_y = plist->pos_y; -				ft_get_start_side(clist->mlist->map[y][x], clist->plist); +				ft_get_start_side(clist->mlist.map[y][x], plist);  				return ;  			}  			x++; diff --git a/src/ft_get_res.c b/src/ft_get_res.c index aa1bec4..013b061 100644 --- a/src/ft_get_res.c +++ b/src/ft_get_res.c @@ -56,7 +56,7 @@ int8_t  {  	t_win	*wlist; -	wlist = clist->wlist; +	wlist = &clist->wlist;  	if (clist->currlvl > 0)  		return (0);  	if (ft_check_res_args(words, clist) < 0) diff --git a/src/ft_get_sprite.c b/src/ft_get_sprite.c index c9546fb..4580681 100644 --- a/src/ft_get_sprite.c +++ b/src/ft_get_sprite.c @@ -22,11 +22,11 @@ void  	x = 1;  	y = 1; -	while (clist->mlist->map[y]) +	while (clist->mlist.map[y])  	{ -		while (clist->mlist->map[y][x]) +		while (clist->mlist.map[y][x])  		{ -			if (ft_ischarset("2", clist->mlist->map[y][x])) +			if (ft_ischarset("2", clist->mlist.map[y][x]))  			{  				clist->sp_list.s_pos_x = x + 0.5;  				clist->sp_list.s_pos_y = y + 0.5; @@ -52,13 +52,13 @@ int8_t  		ft_sprintf(clist->errmsg, "%s", FT_ERR_NOT_A_XPM);  		return (-1);  	} -	ft_memdel((void**)&clist->mlist->sprite_path); -	if (!(clist->mlist->sprite_path = ft_strdup(*(words + 1)))) +	ft_memdel((void**)&clist->mlist.sprite_path); +	if (!(clist->mlist.sprite_path = ft_strdup(*(words + 1))))  	{  		ft_sprintf(clist->errmsg, "%s", FT_ERR_ALLOCATE);  		return (-1);  	} -	if (ft_check_not_found(clist->mlist->sprite_path) < 0) +	if (ft_check_not_found(clist->mlist.sprite_path) < 0)  	{  		ft_sprintf(clist->errmsg, "%s", FT_ERR_RD_SP);  		return (-1); diff --git a/src/ft_get_tex.c b/src/ft_get_tex.c index 2611fef..f8a817c 100644 --- a/src/ft_get_tex.c +++ b/src/ft_get_tex.c @@ -27,13 +27,13 @@ int8_t  		ft_sprintf(clist->errmsg, "%s", FT_ERR_NOT_A_XPM);  		return (-1);  	} -	ft_memdel((void**)&clist->mlist->no_tex_path); -	if (!(clist->mlist->no_tex_path = ft_strdup(*(words + 1)))) +	ft_memdel((void**)&clist->mlist.no_tex_path); +	if (!(clist->mlist.no_tex_path = ft_strdup(*(words + 1))))  	{  		ft_sprintf(clist->errmsg, "%s", FT_ERR_ALLOCATE);  		return (-1);  	} -	if (ft_check_not_found(clist->mlist->no_tex_path) < 0) +	if (ft_check_not_found(clist->mlist.no_tex_path) < 0)  	{  		ft_sprintf(clist->errmsg, "%s", FT_ERR_RD_NO);  		return (-1); @@ -54,13 +54,13 @@ int8_t  		ft_sprintf(clist->errmsg, "%s", FT_ERR_NOT_A_XPM);  		return (-1);  	} -	ft_memdel((void**)&clist->mlist->so_tex_path); -	if (!(clist->mlist->so_tex_path = ft_strdup(*(words + 1)))) +	ft_memdel((void**)&clist->mlist.so_tex_path); +	if (!(clist->mlist.so_tex_path = ft_strdup(*(words + 1))))  	{  		ft_sprintf(clist->errmsg, "%s", FT_ERR_ALLOCATE);  		return (-1);  	} -	if (ft_check_not_found(clist->mlist->so_tex_path) < 0) +	if (ft_check_not_found(clist->mlist.so_tex_path) < 0)  	{  		ft_sprintf(clist->errmsg, "%s", FT_ERR_RD_SO);  		return (-1); @@ -81,13 +81,13 @@ int8_t  		ft_sprintf(clist->errmsg, "%s", FT_ERR_NOT_A_XPM);  		return (-1);  	} -	ft_memdel((void**)&clist->mlist->ea_tex_path); -	if (!(clist->mlist->ea_tex_path = ft_strdup(*(words + 1)))) +	ft_memdel((void**)&clist->mlist.ea_tex_path); +	if (!(clist->mlist.ea_tex_path = ft_strdup(*(words + 1))))  	{  		ft_sprintf(clist->errmsg, "%s", FT_ERR_ALLOCATE);  		return (-1);  	} -	if (ft_check_not_found(clist->mlist->ea_tex_path) < 0) +	if (ft_check_not_found(clist->mlist.ea_tex_path) < 0)  	{  		ft_sprintf(clist->errmsg, "%s", FT_ERR_RD_EA);  		return (-1); @@ -108,13 +108,13 @@ int8_t  		ft_sprintf(clist->errmsg, "%s", FT_ERR_NOT_A_XPM);  		return (-1);  	} -	ft_memdel((void**)&clist->mlist->we_tex_path); -	if (!(clist->mlist->we_tex_path = ft_strdup(*(words + 1)))) +	ft_memdel((void**)&clist->mlist.we_tex_path); +	if (!(clist->mlist.we_tex_path = ft_strdup(*(words + 1))))  	{  		ft_sprintf(clist->errmsg, "%s", FT_ERR_ALLOCATE);  		return (-1);  	} -	if (ft_check_not_found(clist->mlist->we_tex_path) < 0) +	if (ft_check_not_found(clist->mlist.we_tex_path) < 0)  	{  		ft_sprintf(clist->errmsg, "%s", FT_ERR_RD_WE);  		return (-1); diff --git a/src/ft_get_tex_nl.c b/src/ft_get_tex_nl.c index 00155de..bb071f7 100644 --- a/src/ft_get_tex_nl.c +++ b/src/ft_get_tex_nl.c @@ -27,13 +27,13 @@ int8_t  		ft_sprintf(clist->errmsg, "%s", FT_ERR_NOT_A_XPM);  		return (-1);  	} -	ft_memdel((void**)&clist->mlist->nl_tex_path); -	if (!(clist->mlist->nl_tex_path = ft_strdup(*(words + 1)))) +	ft_memdel((void**)&clist->mlist.nl_tex_path); +	if (!(clist->mlist.nl_tex_path = ft_strdup(*(words + 1))))  	{  		ft_sprintf(clist->errmsg, "%s", FT_ERR_ALLOCATE);  		return (-1);  	} -	if (ft_check_not_found(clist->mlist->nl_tex_path) < 0) +	if (ft_check_not_found(clist->mlist.nl_tex_path) < 0)  	{  		ft_sprintf(clist->errmsg, FT_ERR_RD_NL_TEX);  		return (-1); diff --git a/src/ft_init_lists.c b/src/ft_init_lists.c index c98e0b1..8e874ac 100644 --- a/src/ft_init_lists.c +++ b/src/ft_init_lists.c @@ -15,8 +15,7 @@  #include <cub3d.h>  #include <stddef.h>  #include <stdlib.h> -#include <limits.h> -#include <math.h> +#include <stdint.h>  t_rgb  	ft_init_rgb(void) @@ -30,83 +29,70 @@ t_rgb  }  static t_player -	*ft_init_player(void) +	ft_init_player(void)  { -	t_player	*plist; +	t_player	plist; -	if (!(plist = (t_player*)malloc(sizeof(t_player)))) -		return (NULL); -	plist->pos_x = 0; -	plist->pos_y = 0; -	plist->start_x = 0; -	plist->start_y = 0; -	plist->cam_x = 0; -	plist->dir_x = -1; -	plist->dir_y = 0; -	plist->plane_x = 0; -	plist->plane_y = 0.80; +	plist.pos_x = 0; +	plist.pos_y = 0; +	plist.start_x = 0; +	plist.start_y = 0; +	plist.cam_x = 0; +	plist.dir_x = -1; +	plist.dir_y = 0; +	plist.plane_x = 0; +	plist.plane_y = 0.80;  	return (plist);  } -static t_win -	*ft_init_win(void) +static int8_t +	ft_init_win(t_win *wl)  { -	t_win	*wlist; - -	if (!(wlist = (t_win*)malloc(sizeof(t_win)))) -		return (NULL); -	if (!(wlist->winptr = malloc(1))) -		return (NULL); -	wlist->inited = 0; -	wlist->x_size = 0; -	wlist->y_size = 0; -	wlist->x_max_size = 0; -	wlist->y_max_size = 0; -	return (wlist); +	if (!(wl->winptr = malloc(1))) +		return (-1); +	wl->inited = 0; +	wl->x_size = 0; +	wl->y_size = 0; +	wl->x_max_size = 0; +	wl->y_max_size = 0; +	/* wlist = &wl; */ +	return (0);  } -static t_cub -	*ft_init_cub(void) +static int8_t +	ft_init_cub(t_cub *cl)  { -	t_cub		*clist; -	uint8_t		i; +	int8_t		i; -	if (!(clist = (t_cub*)malloc(sizeof(t_cub)))) -		return (NULL); -	if (!(clist->plist = ft_init_player()) || -		!(clist->mlist = ft_init_map())) -		return (NULL); -	ft_bzero(clist->errmsg, 40); +	if (ft_init_map(&cl->mlist) < 0) +		return (-1); +	cl->plist = ft_init_player(); +	ft_bzero(cl->errmsg, 40);  	i = -1;  	while (++i < 5) -		clist->key_input[i] = -1; -	clist->ishud = 0; -	clist->isoldmus = 0; -	clist->f_rgb = ft_init_rgb(); -	clist->c_rgb = ft_init_rgb(); -	clist->rlist = ft_init_s_ray(); -	clist->currlvl = 0; -	clist->walltexgood = 0; -	ft_init_funptr(clist); -	return (clist); +		cl->key_input[i] = -1; +	cl->ishud = 0; +	cl->isoldmus = 0; +	cl->f_rgb = ft_init_rgb(); +	cl->c_rgb = ft_init_rgb(); +	cl->rlist = ft_init_s_ray(); +	cl->currlvl = 0; +	cl->walltexgood = 0; +	ft_init_funptr(cl); +	return (0);  }  int8_t -	ft_init_cub3d(t_cub **clist) +	ft_init_cub3d(t_cub *clist)  { -	t_cub	*cl; +	/* t_cub	*cl; */ -	if (!(cl = ft_init_cub())) -	{ -		ft_memdel((void**)&cl); +	/* if (!(cl = (t_cub*)malloc(sizeof(t_cub)))) */ +	/* 	return (-1); */ +	if (ft_init_cub(clist) < 0)  		return (-1); -	} -	if (!(cl->wlist = ft_init_win())) -	{ -		ft_memdel((void**)&cl->wlist); -		ft_memdel((void**)&cl); +	if (ft_init_win(&clist->wlist) < 0)  		return (-1); -	} -	*clist = cl; +	/* *clist = cl; */  	return (0);  } diff --git a/src/ft_init_map.c b/src/ft_init_map.c index c611ba2..a6704b6 100644 --- a/src/ft_init_map.c +++ b/src/ft_init_map.c @@ -34,15 +34,11 @@ static int8_t  	return (0);  } -t_map -	*ft_init_map(void) +int8_t +	ft_init_map(t_map *mlist)  { -	t_map		*mlist; - -	if (!(mlist = (t_map*)malloc(sizeof(t_map)))) -		return (NULL);  	if (ft_init_map_callocs(mlist) < 0) -		return (NULL); +		return (-1);  	mlist->map[1] = 0;  	mlist->map_w = 0;  	mlist->map_h = 0; @@ -56,5 +52,5 @@ t_map  	mlist->scale = 0;  	mlist->nlx = 0;  	mlist->nly = 0; -	return (mlist); +	return (0);  } diff --git a/src/ft_init_winlx.c b/src/ft_init_winlx.c index 87398e4..dee4009 100644 --- a/src/ft_init_winlx.c +++ b/src/ft_init_winlx.c @@ -18,7 +18,7 @@  int  	ft_init_winlx(t_cub *clist)  { -	if (!(clist->wlist->wlx = mlx_init())) +	if (!(clist->wlist.wlx = mlx_init()))  		return (-1);  	return (0);  } @@ -26,10 +26,10 @@ int  int  	ft_init_winptr(t_cub *clist)  { -	ft_memdel((void**)&clist->wlist->winptr); -	if (!(clist->wlist->winptr = mlx_new_window(clist->wlist->wlx, -				clist->wlist->x_size, clist->wlist->y_size, "Cub3D"))) +	ft_memdel((void**)&clist->wlist.winptr); +	if (!(clist->wlist.winptr = mlx_new_window(clist->wlist.wlx, +				clist->wlist.x_size, clist->wlist.y_size, "Cub3D")))  		return (-1); -	clist->wlist->inited = 1; +	clist->wlist.inited = 1;  	return (0);  } diff --git a/src/ft_key_loop.c b/src/ft_key_loop.c index a7eaccf..e2e2b5c 100644 --- a/src/ft_key_loop.c +++ b/src/ft_key_loop.c @@ -50,10 +50,10 @@ static void  	uint64_t	y;  	t_player	*pl; -	pl = cl->plist; +	pl = &cl->plist;  	x = ft_find_x(key, pl);  	y = ft_find_y(key, pl); -	if (cl->mlist->map[y][x] == '1' || cl->mlist->map[y][x] == '2') +	if (cl->mlist.map[y][x] == '1' || cl->mlist.map[y][x] == '2')  	{  		pl->pos_y = old_y;  		pl->pos_x = old_x; @@ -64,15 +64,15 @@ int  	ft_key_loop(t_cub *cl)  {  	uint8_t			i; -	const float		old_y = cl->plist->pos_y; -	const float		old_x = cl->plist->pos_x; +	const float		old_y = cl->plist.pos_y; +	const float		old_x = cl->plist.pos_x;  	i = 0;  	while (i < 5 && cl->key_input[i] != -1 && cl->key_input[i] <= 5)  	{  		cl->key_ptr[cl->key_input[i]](cl);  		ft_collision(old_y, old_x, cl->key_input[i], cl); -		if (cl->mlist->isnlvl) +		if (cl->mlist.isnlvl)  		{  			if (ft_warp_level(cl) < 0)  				return (ft_exit(FT_RET_FAILED_STRUCTS, cl)); diff --git a/src/ft_map_error.c b/src/ft_map_error.c index a36507a..b777415 100644 --- a/src/ft_map_error.c +++ b/src/ft_map_error.c @@ -20,7 +20,7 @@ int  	ft_dprintf(STDERR_FILENO, "Error\n");  	ft_dprintf(STDERR_FILENO,  				"\033[1;31mMap error: line %lu: %s\033[0m\n", -				clist->mlist->line_chk, +				clist->mlist.line_chk,  				errmsg);  	return (ft_exit(4, clist));  } diff --git a/src/ft_music.c b/src/ft_music.c index d110256..f3369bd 100644 --- a/src/ft_music.c +++ b/src/ft_music.c @@ -23,6 +23,6 @@ void  	cl = (t_cub *)vargp;  	cl->isoldmus = 1; -	system(cl->mlist->music_cmd); +	system(cl->mlist.music_cmd);  	return (NULL);  } diff --git a/src/ft_parse_map.c b/src/ft_parse_map.c index 48201fd..e54b53c 100644 --- a/src/ft_parse_map.c +++ b/src/ft_parse_map.c @@ -25,7 +25,7 @@ static void  	size_t	j;  	i = 0; -	ml = clist->mlist; +	ml = &clist->mlist;  	while (ml->map[i])  		i++;  	j = 0; @@ -51,7 +51,7 @@ static int8_t  	char	**words;  	int		ret; -	clist->mlist->line_chk += 1; +	clist->mlist.line_chk += 1;  	if ((ret = get_next_line(fd, &line)) < 0)  		return (ft_map_error(FT_ERR_READ, clist));  	if (ret == 0) @@ -97,8 +97,8 @@ void  	if (ft_get_map_core(fd, clist) < 0)  		ft_map_error(clist->errmsg, clist);  	ft_check_map_last_line(clist); -	ft_get_player_spawn(clist->plist, clist); -	ft_get_nlvl_pos(clist->mlist); +	ft_get_player_spawn(&clist->plist, clist); +	ft_get_nlvl_pos(&clist->mlist);  	ft_check_missing(clist);  	ft_set_minimap_scale(clist);  	clist->currlvl += 1; diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c index cd34014..50bdbf9 100644 --- a/src/ft_raycasting.c +++ b/src/ft_raycasting.c @@ -21,38 +21,38 @@  /* { */  /* 	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.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; */ +/* 	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.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->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) */ +/* 		* (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; */ +/* 		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); */  /* } */ @@ -60,10 +60,10 @@ void  	ft_calc_tex(t_cub *clist)  {  	if (clist->rlist.side == 0) -		clist->rlist.wall_hit_x = (clist->plist->pos_x) + +		clist->rlist.wall_hit_x = (clist->plist.pos_x) +  			clist->rlist.wall_dist * clist->rlist.y_ray_dir;  	else -		clist->rlist.wall_hit_x = (clist->plist->pos_y) + +		clist->rlist.wall_hit_x = (clist->plist.pos_y) +  			clist->rlist.wall_dist * clist->rlist.x_ray_dir;  	clist->rlist.wall_hit_x -= floor(clist->rlist.wall_hit_x);  	clist->tlist[clist->w_side].tex_x = (int)(clist->rlist.wall_hit_x * @@ -82,8 +82,8 @@ static void  	t_win		*wl;  	t_player	*pl; -	wl = cl->wlist; -	pl = cl->plist; +	wl = &cl->wlist; +	pl = &cl->plist;  	pl->cam_x = 2 * i / (float)(wl->x_size) - 1;  	cl->rlist.x_ray_pos = pl->pos_y;  	cl->rlist.y_ray_pos = pl->pos_x; @@ -97,11 +97,11 @@ static void  	if (cl->rlist.side == 0)  	{  		cl->rlist.wall_dist = (cl->rlist.sqx - cl->rlist.x_ray_pos + -		(1 - cl->mlist->x_step) / 2) / cl->rlist.x_ray_dir; +		(1 - cl->mlist.x_step) / 2) / cl->rlist.x_ray_dir;  	}  	else  		cl->rlist.wall_dist = (cl->rlist.sqy - cl->rlist.y_ray_pos + -		(1 - cl->mlist->y_step) / 2) / cl->rlist.y_ray_dir; +		(1 - cl->mlist.y_step) / 2) / cl->rlist.y_ray_dir;  }  void @@ -111,7 +111,7 @@ void  	t_win		*wl;  	i = 0; -	wl = cl->wlist; +	wl = &cl->wlist;  	while (i < wl->x_size)  	{  		ft_initray(cl, i); diff --git a/src/ft_select_get.c b/src/ft_select_get.c index ed569ff..124c208 100644 --- a/src/ft_select_get.c +++ b/src/ft_select_get.c @@ -21,17 +21,17 @@ static int8_t  	if (ret == 12)  		return (12);  	if (ret == 0 && clist->currlvl == 0 && -		(clist->wlist->x_size != 0 || clist->wlist->y_size != 0)) +		(clist->wlist.x_size != 0 || clist->wlist.y_size != 0))  		return (-1); -	else if (ret == 1 && (clist->mlist->no_tex_path[0])) +	else if (ret == 1 && (clist->mlist.no_tex_path[0]))  		return (-1); -	else if (ret == 2 && (clist->mlist->so_tex_path[0])) +	else if (ret == 2 && (clist->mlist.so_tex_path[0]))  		return (-1); -	else if (ret == 3 && (clist->mlist->ea_tex_path[0])) +	else if (ret == 3 && (clist->mlist.ea_tex_path[0]))  		return (-1); -	else if (ret == 4 && (clist->mlist->we_tex_path[0])) +	else if (ret == 4 && (clist->mlist.we_tex_path[0]))  		return (-1); -	else if (ret == 5 && (clist->mlist->sprite_path[0])) +	else if (ret == 5 && (clist->mlist.sprite_path[0]))  		return (-1);  	else if (ret == 6 && ((clist->f_rgb.r != -1) || (clist->f_rgb.g != -1)  			|| (clist->f_rgb.b != -1))) @@ -47,11 +47,11 @@ static int8_t  {  	if (ret == 12)  		return (12); -	if (ret == 8 && (clist->mlist->nlevel_path[0])) +	if (ret == 8 && (clist->mlist.nlevel_path[0]))  		return (-1); -	if (ret == 9 && (clist->mlist->nl_tex_path[0])) +	if (ret == 9 && (clist->mlist.nl_tex_path[0]))  		return (-1); -	if (ret == 10 && (clist->mlist->music_path[0])) +	if (ret == 10 && (clist->mlist.music_path[0]))  		return (-1);  	return (ret);  } diff --git a/src/ft_set_minimap_scale.c b/src/ft_set_minimap_scale.c index dc4bd12..52c63e6 100644 --- a/src/ft_set_minimap_scale.c +++ b/src/ft_set_minimap_scale.c @@ -17,10 +17,10 @@ void  {  	t_map	*ml; -	ml = clist->mlist; -	((ml->scale = (clist->wlist->x_size / (uint16_t)ml->map_w) - 1) < 1) +	ml = &clist->mlist; +	((ml->scale = (clist->wlist.x_size / (uint16_t)ml->map_w) - 1) < 1)  		? (ml->scale = 1) : 0; -	(clist->wlist->y_size < (ml->map_h * ml->scale)) ? (ml->scale = -		(clist->wlist->y_size / (uint16_t)ml->map_h) - 1) : 0; +	(clist->wlist.y_size < (ml->map_h * ml->scale)) ? (ml->scale = +		(clist->wlist.y_size / (uint16_t)ml->map_h) - 1) : 0;  	(ml->scale >= 10) ? (ml->scale /= 4) : 0;  } diff --git a/src/ft_tex_init.c b/src/ft_tex_init.c index 6e12a56..c19bd20 100644 --- a/src/ft_tex_init.c +++ b/src/ft_tex_init.c @@ -27,8 +27,8 @@  static void  	ft_get_nlvl_img(t_cub *cl)  { -	cl->tlist[5].img = mlx_xpm_file_to_image(cl->wlist->wlx, -			cl->mlist->nl_tex_path, &cl->tlist[5].img_w, &cl->tlist[5].img_h); +	cl->tlist[5].img = mlx_xpm_file_to_image(cl->wlist.wlx, +			cl->mlist.nl_tex_path, &cl->tlist[5].img_w, &cl->tlist[5].img_h);  	cl->tlist[5].ptr = mlx_get_data_addr(cl->tlist[5].img,  		&cl->tlist[5].bpp, &cl->tlist[5].sizeline, &cl->tlist[5].endian);  } @@ -36,27 +36,27 @@ static void  void  	ft_wall_tex_init(t_cub *cl)  { -	cl->tlist[0].img = mlx_xpm_file_to_image(cl->wlist->wlx, -			cl->mlist->no_tex_path, &cl->tlist[0].img_w, &cl->tlist[0].img_h); +	cl->tlist[0].img = mlx_xpm_file_to_image(cl->wlist.wlx, +			cl->mlist.no_tex_path, &cl->tlist[0].img_w, &cl->tlist[0].img_h);  	cl->tlist[0].ptr = mlx_get_data_addr(cl->tlist[0].img,  		&cl->tlist[0].bpp, &cl->tlist[0].sizeline, &cl->tlist[0].endian); -	cl->tlist[1].img = mlx_xpm_file_to_image(cl->wlist->wlx, -			cl->mlist->so_tex_path, &cl->tlist[1].img_w, &cl->tlist[1].img_h); +	cl->tlist[1].img = mlx_xpm_file_to_image(cl->wlist.wlx, +			cl->mlist.so_tex_path, &cl->tlist[1].img_w, &cl->tlist[1].img_h);  	cl->tlist[1].ptr = mlx_get_data_addr(cl->tlist[1].img,  		&cl->tlist[1].bpp, &cl->tlist[1].sizeline, &cl->tlist[1].endian); -	cl->tlist[2].img = mlx_xpm_file_to_image(cl->wlist->wlx, -			cl->mlist->ea_tex_path, &cl->tlist[2].img_w, &cl->tlist[2].img_h); +	cl->tlist[2].img = mlx_xpm_file_to_image(cl->wlist.wlx, +			cl->mlist.ea_tex_path, &cl->tlist[2].img_w, &cl->tlist[2].img_h);  	cl->tlist[2].ptr = mlx_get_data_addr(cl->tlist[2].img,  		&cl->tlist[2].bpp, &cl->tlist[2].sizeline, &cl->tlist[2].endian); -	cl->tlist[3].img = mlx_xpm_file_to_image(cl->wlist->wlx, -			cl->mlist->we_tex_path, &cl->tlist[3].img_w, &cl->tlist[3].img_h); +	cl->tlist[3].img = mlx_xpm_file_to_image(cl->wlist.wlx, +			cl->mlist.we_tex_path, &cl->tlist[3].img_w, &cl->tlist[3].img_h);  	cl->tlist[3].ptr = mlx_get_data_addr(cl->tlist[3].img,  		&cl->tlist[3].bpp, &cl->tlist[3].sizeline, &cl->tlist[3].endian); -	cl->tlist[4].img = mlx_xpm_file_to_image(cl->wlist->wlx, -			cl->mlist->sprite_path, &cl->tlist[4].img_w, &cl->tlist[4].img_h); +	cl->tlist[4].img = mlx_xpm_file_to_image(cl->wlist.wlx, +			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) +	if (cl->mlist.isnlvl)  		ft_get_nlvl_img(cl);  	cl->walltexgood = 1;  } diff --git a/src/ft_treat_args.c b/src/ft_treat_args.c index 6f8ef87..2571709 100644 --- a/src/ft_treat_args.c +++ b/src/ft_treat_args.c @@ -37,9 +37,9 @@ uint8_t  		if (ft_init_winptr(clist) < 0)  			return (ft_exit(FT_RET_FAILED_MLX, clist));  		ft_draw_scene(clist); -		if (clist->mlist->ismusic) +		if (clist->mlist.ismusic)  			pthread_create(&clist->tid, NULL, ft_music_thread, clist); -		ft_hooks_and_loops(clist->wlist, clist); +		ft_hooks_and_loops(&clist->wlist, clist);  	}  	else if (argc == 3 && !ft_strncmp("--save", argv[2], 7))  	{ diff --git a/src/ft_warp_level.c b/src/ft_warp_level.c index de87187..b122e46 100644 --- a/src/ft_warp_level.c +++ b/src/ft_warp_level.c @@ -32,7 +32,6 @@ static void  	ft_memdel((void**)&ml->music_cmd);  	ft_memdel((void**)&ml->mapl);  	ft_free_words(ml->map); -	ft_memdel((void**)&ml);  }  static void @@ -40,22 +39,22 @@ static void  {  	uint8_t	i; -	cl->plist->pos_x = 0; -	cl->plist->pos_y = 0; -	cl->plist->start_x = 0; -	cl->plist->start_y = 0; -	cl->plist->cam_x = 0; -	cl->plist->dir_x = -1; -	cl->plist->dir_y = 0; -	cl->plist->plane_x = 0; -	cl->plist->plane_y = 0.66666666; +	cl->plist.pos_x = 0; +	cl->plist.pos_y = 0; +	cl->plist.start_x = 0; +	cl->plist.start_y = 0; +	cl->plist.cam_x = 0; +	cl->plist.dir_x = -1; +	cl->plist.dir_y = 0; +	cl->plist.plane_x = 0; +	cl->plist.plane_y = 0.66666666;  	cl->f_rgb = ft_init_rgb();  	cl->c_rgb = ft_init_rgb();  	cl->rlist = ft_init_s_ray();  	i = 0;  	while (i <= 5)  	{ -		mlx_destroy_image(cl->wlist->wlx, cl->tlist[i].img); +		mlx_destroy_image(cl->wlist.wlx, cl->tlist[i].img);  		cl->tlist[i].img = NULL;  		i++;  	} @@ -64,21 +63,21 @@ static void  static void  	ft_treat_music(uint8_t isoldmus, char *tmp_mup, t_cub *cl)  { -	if (isoldmus && !cl->mlist->ismusic) +	if (isoldmus && !cl->mlist.ismusic)  	{  		pthread_cancel(cl->tid);  		pthread_join(cl->tid, NULL);  		cl->isoldmus = 0;  	} -	else if (isoldmus && cl->mlist->ismusic -		&& ft_strncmp(tmp_mup, cl->mlist->music_path, ft_strlen(tmp_mup) + 1)) +	else if (isoldmus && cl->mlist.ismusic +		&& ft_strncmp(tmp_mup, cl->mlist.music_path, ft_strlen(tmp_mup) + 1))  	{  		pthread_cancel(cl->tid);  		pthread_join(cl->tid, NULL);  		pthread_create(&cl->tid, NULL, ft_music_thread, cl);  	} -	else if (isoldmus && cl->mlist->ismusic -		&& !ft_strncmp(tmp_mup, cl->mlist->music_path, ft_strlen(tmp_mup) + 1)) +	else if (isoldmus && cl->mlist.ismusic +		&& !ft_strncmp(tmp_mup, cl->mlist.music_path, ft_strlen(tmp_mup) + 1))  		return ;  } @@ -89,19 +88,19 @@ int8_t  	char	*tmp_mup;  	uint8_t	isoldmus; -	if ((uint32_t)cl->plist->pos_x == cl->mlist->nlx && -		(uint32_t)cl->plist->pos_y == cl->mlist->nly) +	if ((uint32_t)cl->plist.pos_x == cl->mlist.nlx && +		(uint32_t)cl->plist.pos_y == cl->mlist.nly)  	{  		if (!(next_path = (char *)malloc((ft_strlen( -				cl->mlist->nlevel_path) + 1) * sizeof(char)))) +				cl->mlist.nlevel_path) + 1) * sizeof(char))))  			return (-1); -		ft_sprintf(next_path, "%s", cl->mlist->nlevel_path); -		isoldmus = cl->mlist->ismusic; +		ft_sprintf(next_path, "%s", cl->mlist.nlevel_path); +		isoldmus = cl->mlist.ismusic;  		if (isoldmus) -			tmp_mup = ft_strdup(cl->mlist->music_path); +			tmp_mup = ft_strdup(cl->mlist.music_path);  		ft_del_some(cl); -		ft_del_map(cl->mlist); -		if (!(cl->mlist = ft_init_map())) +		ft_del_map(&cl->mlist); +		if (ft_init_map(&cl->mlist) < 0)  			return (-1);  		ft_parse_map(next_path, cl);  		ft_treat_music(isoldmus, tmp_mup, cl); @@ -17,16 +17,16 @@  int  	main(int argc, const char *argv[])  { -	t_cub	*clist; +	t_cub	clist;  	if (ft_check_map_arg(argc, argv) == FT_RET_BAD_ARGV)  		return (FT_RET_BAD_ARGV);  	if (ft_init_cub3d(&clist) < 0)  		return (FT_RET_FAILED_STRUCTS); -	ft_parse_map(argv[1], clist); -	if (ft_init_winlx(clist) < 0) -		return (ft_exit(FT_RET_FAILED_MLX, clist)); -	ft_wall_tex_init(clist); -	ft_use_args(argc, argv, clist); +	ft_parse_map(argv[1], &clist); +	if (ft_init_winlx(&clist) < 0) +		return (ft_exit(FT_RET_FAILED_MLX, &clist)); +	ft_wall_tex_init(&clist); +	ft_use_args(argc, argv, &clist);  	return (FT_RET_FINE);  } | 
