diff options
Diffstat (limited to '')
| -rw-r--r-- | inc/cub3d.h | 12 | ||||
| -rw-r--r-- | inc/cub3d_structs.h | 2 | ||||
| -rw-r--r-- | src/ft_death_hooks.c | 2 | ||||
| -rw-r--r-- | src/ft_draw_scene.c | 2 | ||||
| -rw-r--r-- | src/ft_draw_sprite.c | 2 | ||||
| -rw-r--r-- | src/ft_draw_sprite_extra.c | 42 | ||||
| -rw-r--r-- | src/ft_error.c | 11 | ||||
| -rw-r--r-- | src/ft_exit.c | 9 | ||||
| -rw-r--r-- | src/ft_init_lists.c | 5 | ||||
| -rw-r--r-- | src/ft_init_map.c | 2 | ||||
| -rw-r--r-- | src/ft_parse_map.c | 2 | ||||
| -rw-r--r-- | src/ft_raycasting.c | 6 | ||||
| -rw-r--r-- | src/ft_sort_s_t.c | 96 | 
13 files changed, 121 insertions, 72 deletions
diff --git a/inc/cub3d.h b/inc/cub3d.h index a6a0db7..82808f4 100644 --- a/inc/cub3d.h +++ b/inc/cub3d.h @@ -157,12 +157,19 @@ void			ft_check_map_surrounds(t_map *ml, t_cub *cl);  int				ft_check_missing(t_cub *clist);  int				ft_check_missing_tex_defines(t_cub *clist);  int				ft_check_missing_sfx(t_cub *clist); -int				ft_missing_error(const char *err, t_cub *clist); -int				ft_map_error(const char *errmsg, t_cub *clist);  size_t			ft_get_line_len(char *line);  void			ft_get_spawns(t_cub *cl);  /* +** ====== ERROR ====== +*/ + +int				ft_error(uint8_t retval, const char *errmsg, t_cub *clist); +int				ft_missing_error(const char *err, t_cub *clist); +int				ft_map_error(const char *errmsg, t_cub *clist); +int				ft_alloc_error(t_cub *clist); + +/*  ** ====== ARGS ======  */ @@ -239,7 +246,6 @@ void			ft_set_minimap_scale(t_cub *clist);  void			ft_enable_music(t_cub *cl);  void			ft_music_fork(char **mcmd_words, char *const envp[]);  int8_t			ft_save_to_bmp(t_cub *cl); -int				ft_error(uint8_t retval, const char *errmsg, t_cub *clist);  int8_t			ft_warp_level(char *path, t_cub *cl);  uint32_t		ft_rgb_to_hex(float dist, t_rgb rgb, t_cub *cl);  t_bmp_rgb		ft_hex_to_rgb(uint32_t color); diff --git a/inc/cub3d_structs.h b/inc/cub3d_structs.h index 5af18a4..5497ae9 100644 --- a/inc/cub3d_structs.h +++ b/inc/cub3d_structs.h @@ -236,6 +236,8 @@ typedef struct			s_cub  	uint16_t			currlvl;  	uint16_t			i;  	uint16_t			y; +	float				**big_t; +	uint16_t			big_t_val;  	char				errmsg[64];  	int32_t				key_input[5];  	char				fps_count[9]; diff --git a/src/ft_death_hooks.c b/src/ft_death_hooks.c index 1f0cb6c..c6705b0 100644 --- a/src/ft_death_hooks.c +++ b/src/ft_death_hooks.c @@ -26,7 +26,7 @@ static int  	if (keycode == FT_RET_KEY)  	{  		if (ft_warp_level(clist->mlist.filename, clist) < 0) -			return (ft_error(FT_RET_ALLOC_ERR, FT_ERR_ALLOCATE, clist)); +			return (ft_alloc_error(clist));  		ft_draw_scene(clist);  		ft_hooks_and_loops(&clist->wlist, clist);  		return (0); diff --git a/src/ft_draw_scene.c b/src/ft_draw_scene.c index 86009f6..74b8315 100644 --- a/src/ft_draw_scene.c +++ b/src/ft_draw_scene.c @@ -75,7 +75,7 @@ void  	{  		ft_put_fps(clist);  		if (clist->mlist.isnlvl && ft_put_stage(clist) < 0) -			ft_error(FT_RET_ALLOC_ERR, FT_ERR_ALLOCATE, clist); +			ft_alloc_error(clist);  	}  } diff --git a/src/ft_draw_sprite.c b/src/ft_draw_sprite.c index 1b3f912..dc6f54f 100644 --- a/src/ft_draw_sprite.c +++ b/src/ft_draw_sprite.c @@ -42,7 +42,7 @@ void  	float	**dist_tab;  	if (!(dist_tab = ft_alloc_dist_tab())) -		ft_error(FT_RET_ALLOC_ERR, FT_ERR_ALLOCATE, cl); +		ft_alloc_error(cl);  	while (++jt < FT_TOTAL_SPRT)  	{  		while (++it < cl->mlist.sprite_nbr[jt]) diff --git a/src/ft_draw_sprite_extra.c b/src/ft_draw_sprite_extra.c index c64d2c1..598f637 100644 --- a/src/ft_draw_sprite_extra.c +++ b/src/ft_draw_sprite_extra.c @@ -47,24 +47,7 @@ static void  		(1 + sprite->transformx / sprite->transformy);  } -static int8_t -	ft_set_current_sprite(t_cub *cl, int8_t j) -{ -	const int8_t	st_o = cl->mlist.st_o[j]; - -	if (st_o == 0) -		return (4); -	else if (st_o >= 1 && st_o <= 7) -		return (st_o + 7); -	else if (st_o == 8) -		return (15); -	else if (st_o == 9) -		return (17); -	else if (st_o >= 10) -		return (st_o + 8); -	return (0); -} - +#include <libft.h>  void  	ft_calc_sprite(t_cub *cl)  { @@ -75,20 +58,17 @@ void  	i = -1;  	j = -1;  	ft_sort_sprites(cl, -1, -1); -	while (++j < FT_TOTAL_SPRT) +	while (++j < cl->big_t_val)  	{ -		while (++i < cl->mlist.sprite_nbr[cl->mlist.st_o[j]] && cl->mlist.st_o[j] != -1 ) -		{ -			sprite = -				cl->sprites[cl->mlist.st_o[j]][cl->mlist.sprite_order[ -				cl->mlist.st_o[j]][i]]; -			sprite.current_sprite = ft_set_current_sprite(cl, j); -			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_h_w(cl, &sprite); -			ft_draw_sprite(cl, &sprite); -		} +		sprite = +			cl->sprites[(int8_t)cl->big_t[j][2]] +					   [(int16_t)cl->big_t[j][3]]; +		sprite.current_sprite = (int8_t)cl->big_t[j][1]; +		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_h_w(cl, &sprite); +		ft_draw_sprite(cl, &sprite);  		i = -1;  	}  } diff --git a/src/ft_error.c b/src/ft_error.c index 0f2bc97..a643b5c 100644 --- a/src/ft_error.c +++ b/src/ft_error.c @@ -36,10 +36,19 @@ int  }  int +	ft_alloc_error(t_cub *clist) +{ +	ft_dprintf(STDERR_FILENO, "Error\n"); +	ft_dprintf(STDERR_FILENO, +				"\033[1;31m%s\033[0m\n", FT_ERR_ALLOCATE); +	return (ft_exit(FT_RET_ALLOC_ERR, clist)); +} + +int  	ft_missing_error(const char *err, t_cub *clist)  {  	ft_dprintf(STDERR_FILENO, "Error\n");  	ft_dprintf(STDERR_FILENO, -			"\033[1;31m%s %s\033[0m\n", FT_ERR_MISS_ELEMENT, err); +				"\033[1;31m%s %s\033[0m\n", FT_ERR_MISS_ELEMENT, err);  	return (ft_exit(FT_ERR_MISSING, clist));  } diff --git a/src/ft_exit.c b/src/ft_exit.c index ed1191c..79b3068 100644 --- a/src/ft_exit.c +++ b/src/ft_exit.c @@ -21,6 +21,15 @@  static void  	ft_del_last_remains(t_cub *clist)  { +	uint16_t	i; + +	i = 0; +	while (i < clist->big_t_val) +	{ +		ft_memdel((void*)&clist->big_t[i]); +		i++; +	} +	ft_memdel((void*)&clist->big_t);  	if (!clist->wlist.inited)  	{  		ft_memdel((void*)&clist->wlist.winptr); diff --git a/src/ft_init_lists.c b/src/ft_init_lists.c index 25b8eb6..2105a64 100644 --- a/src/ft_init_lists.c +++ b/src/ft_init_lists.c @@ -115,6 +115,11 @@ int8_t  		return (-1);  	if (ft_init_sprites(&clist->sprites) < 0)  		return (-1); +	if (!(clist->big_t = (float**)ft_calloc(2, sizeof(float*))) || +		!(clist->big_t[0] = (float*)ft_calloc(1, sizeof(float))) || +		!(clist->big_t[1] = (float*)ft_calloc(1, sizeof(float)))) +		return (-1); +	clist->big_t_val = 2;  	ft_sprintf(clist->fps_count, "fps: 60");  	clist->isdead = 0;  	clist->moves = 0; diff --git a/src/ft_init_map.c b/src/ft_init_map.c index a7f82f5..0abfcb1 100644 --- a/src/ft_init_map.c +++ b/src/ft_init_map.c @@ -65,7 +65,7 @@ int8_t  	mlist->nly = 0;  	mlist->sprite_var = 0;  	mlist->topsp = 0; -	ft_bzero(mlist->sprite_nbr, FT_TOTAL_SPRT); +	ft_bzero(mlist->sprite_nbr, FT_TOTAL_SPRT * sizeof(int16_t));  	i = -1;  	while (++i < FT_TOTAL_SPRT)  		ft_bzero(mlist->sprite_order[i], 4096); diff --git a/src/ft_parse_map.c b/src/ft_parse_map.c index 46fe022..3141171 100644 --- a/src/ft_parse_map.c +++ b/src/ft_parse_map.c @@ -80,7 +80,7 @@ static void  	ft_memdel((void*)&clist->mlist.filename);  	if (!(clist->mlist.filename =  		(char*)malloc((ft_strlen(map_path) + 1) * sizeof(char)))) -		ft_error(FT_RET_ALLOC_ERR, FT_ERR_ALLOCATE, clist); +		ft_alloc_error(clist);  	ft_sprintf(clist->mlist.filename, "%s", map_path);  } diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c index f9a0e45..3bfd038 100644 --- a/src/ft_raycasting.c +++ b/src/ft_raycasting.c @@ -32,18 +32,18 @@ static void  		!(rl->fc_tex_x_tab = (int32_t***)malloc(2 * sizeof(int32_t**))) ||  		!(rl->fc_tex_y_tab = (int32_t***)malloc(2 * sizeof(int32_t**))) ||  		!(rl->row_dist_tab = (float*)malloc(y_s * sizeof(float)))) -			ft_error(FT_RET_ALLOC_ERR, FT_ERR_ALLOCATE, cl); +		ft_alloc_error(cl);  	x = -1;  	while (++x < 2)  	{  		if (!(rl->fc_tex_x_tab[x] = (int**)malloc(y_s * sizeof(int*))) ||  			!(rl->fc_tex_y_tab[x] = (int**)malloc(y_s * sizeof(int*)))) -			ft_error(FT_RET_ALLOC_ERR, FT_ERR_ALLOCATE, cl); +			ft_alloc_error(cl);  		y = -1;  		while (++y < y_s)  			if (!(rl->fc_tex_x_tab[x][y] = (int*)malloc(x_s * sizeof(int))) ||  				!(rl->fc_tex_y_tab[x][y] = (int*)malloc(x_s * sizeof(int)))) -				ft_error(FT_RET_ALLOC_ERR, FT_ERR_ALLOCATE, cl); +				ft_alloc_error(cl);  	}  } diff --git a/src/ft_sort_s_t.c b/src/ft_sort_s_t.c index 28a372d..bcf033f 100644 --- a/src/ft_sort_s_t.c +++ b/src/ft_sort_s_t.c @@ -33,58 +33,96 @@ float  	return (dist_tab);  } +static int8_t +	ft_set_current_sprite(t_cub *cl, int8_t j) +{ +	const int8_t	st_o = cl->mlist.st_o[j]; + +	if (st_o == 0) +		return (4); +	else if (st_o >= 1 && st_o <= 7) +		return (st_o + 7); +	else if (st_o == 8) +		return (15); +	else if (st_o == 9) +		return (17); +	else if (st_o >= 10) +		return (st_o + 8); +	return (0); +} + +static void +	ft_alloc_and_fill_big_t(float **dist_tab, t_cub *cl) +{ +	int32_t	i; +	int32_t	j; +	int32_t	k; + +	if (!(cl->big_t = (float**)malloc(cl->big_t_val * sizeof(float*)))) +		ft_alloc_error(cl); +	i = -1; +	while (++i < cl->big_t_val) +		if (!(cl->big_t[i] = (float*)malloc(4 * sizeof(float)))) +			ft_alloc_error(cl); +	i = 0; +	j = 0; +	k = 0; +	while (i < cl->big_t_val) +	{ +		if (dist_tab[j][k]) +		{ +			ft_printf("%d\n", j); +			cl->big_t[i][0] = dist_tab[j][k]; +			cl->big_t[i][1] = (float)ft_set_current_sprite(cl, j); +			cl->big_t[i][2] = (float)j; +			cl->big_t[i][3] = (float)k; +			k++; +		} +		else +		{ +			k = 0; +			j++; +		} +		i++; +	} +} +  static void  	ft_init_st(t_cub *cl, int32_t *st_o, float **dist_tab)  {  	int8_t	i;  	int8_t	j; -	j = 0; +	j = -1;  	i = -1;  	while (++i < FT_TOTAL_SPRT)  		st_o[i] = -1;  	i = -1;  	while (++i < FT_TOTAL_SPRT)  	{ -		if (cl->sprites[i][0].exists == 1) +		if (cl->mlist.sprite_nbr[i] > 0)  		{ -			st_o[j] = i; -			ft_memcpy(dist_tab[j], dist_tab[i], 4096); -			j++; +			st_o[++j] = i; +			ft_memcpy(dist_tab[j], dist_tab[i], 4096 * sizeof(float));  		}  	}  } -static void -	ft_swap_them(int16_t i, float **dist_tab) -{ -	float       tmp_i[4096]; - -	ft_bzero(tmp_i, 4096); -	ft_memcpy(tmp_i, dist_tab[i], 4096); -	ft_memcpy(dist_tab[i], dist_tab[i + 1], 4096); -	ft_memcpy(dist_tab[i + 1], tmp_i, 4096); -} -  void  	ft_sort_s_t(t_cub *cl, float **dist_tab)  { -	int16_t		i; -	int32_t     tmp; +	int32_t		i; -	i = -1;  	ft_init_st(cl, cl->mlist.st_o, dist_tab); +	i = -1; +	while (++i < cl->big_t_val) +		ft_memdel((void*)&cl->big_t[i]); +	ft_memdel((void*)&cl->big_t); +	i = -1; +	cl->big_t_val = 0;  	while (++i < FT_TOTAL_SPRT) -	{ -		if (cl->mlist.st_o[i] != -1 && dist_tab[i][0] < dist_tab[i + 1][0]) -		{ -			tmp = cl->mlist.st_o[i]; -			cl->mlist.st_o[i] = cl->mlist.st_o[i + 1]; -			cl->mlist.st_o[i + 1] = tmp; -			ft_swap_them(i, dist_tab); -			i = -1; -		} -	} +		cl->big_t_val += cl->mlist.sprite_nbr[i]; +	ft_alloc_and_fill_big_t(dist_tab, cl);  	i = -1;  	while (++i < FT_TOTAL_SPRT + 1)  		ft_memdel((void*)&dist_tab[i]);  | 
