From 7b2b82106491c78e7a288a77db1f5080ef089d0f Mon Sep 17 00:00:00 2001 From: Rudy Bousset Date: Wed, 19 Feb 2020 17:42:39 +0100 Subject: go merge --- Makefile | 1 + inc/cub3d.h | 2 ++ inc/cub3d_defines.h | 5 +++++ inc/cub3d_structs.h | 8 -------- src/ft_check_not_found.c | 15 +++++++++++++++ src/ft_get_sprite.c | 5 +++++ src/ft_get_tex.c | 20 ++++++++++++++++++++ src/ft_parse_map.c | 1 - src/ft_print_list.c | 40 ---------------------------------------- src/ft_tex_init.c | 12 ++++++------ 10 files changed, 54 insertions(+), 55 deletions(-) create mode 100644 src/ft_check_not_found.c delete mode 100644 src/ft_print_list.c diff --git a/Makefile b/Makefile index a120b23..cc07e31 100644 --- a/Makefile +++ b/Makefile @@ -35,6 +35,7 @@ SRCS_NAME += ft_get_map.c SRCS_NAME += ft_get_player_spawn.c SRCS_NAME += ft_set_minimap_scale.c SRCS_NAME += ft_check_missing.c +SRCS_NAME += ft_check_not_found.c SRCS_NAME += ft_check_map_line.c SRCS_NAME += ft_free_words.c SRCS_NAME += ft_map_error.c diff --git a/inc/cub3d.h b/inc/cub3d.h index f7e4d79..87f6ef3 100644 --- a/inc/cub3d.h +++ b/inc/cub3d.h @@ -25,6 +25,7 @@ ** 3: failed mlx init ** 4: map error ** 5: no map +** 6: read error */ int8_t ft_init_cub3d(t_cub **clist); @@ -81,5 +82,6 @@ int ft_key_loop(t_cub *cl); void ft_draw_circle(int32_t a, int32_t b, int32_t color, t_cub *cl); void ft_draw_texture(t_cub *cl, int x, int y, int tex_y); +int8_t ft_check_not_found(const char *path); # endif diff --git a/inc/cub3d_defines.h b/inc/cub3d_defines.h index 209d0bc..49b559a 100644 --- a/inc/cub3d_defines.h +++ b/inc/cub3d_defines.h @@ -82,6 +82,11 @@ # define FT_ERR_ILL_MAP "map contains illegal char" # define FT_ERR_MULT_SPAWN "multiple spawn points" # define FT_ERR_MAP_L_L "last line is invalid" +# define FT_ERR_RD_NO "could not find north side texture file" +# define FT_ERR_RD_SO "could not find south side texture file" +# define FT_ERR_RD_EA "could not find east side texture file" +# define FT_ERR_RD_WE "could not find west side texture file" +# define FT_ERR_RD_SP "could not find sprite texture file" /* ** ====== MISSING ERROR MSG ====== diff --git a/inc/cub3d_structs.h b/inc/cub3d_structs.h index 18edfd8..2c77758 100644 --- a/inc/cub3d_structs.h +++ b/inc/cub3d_structs.h @@ -47,14 +47,6 @@ typedef struct s_rgb int16_t b; } t_rgb; -/* -** player view_side: -** 1: North -** 2: East -** 3: South -** 4: West -*/ - typedef struct s_player { float pos_x; diff --git a/src/ft_check_not_found.c b/src/ft_check_not_found.c new file mode 100644 index 0000000..9233846 --- /dev/null +++ b/src/ft_check_not_found.c @@ -0,0 +1,15 @@ +#include +#include +#include +#include + +int8_t + ft_check_not_found(const char *path) +{ + int fd; + + if ((fd = open(path, O_RDONLY)) < 0) + return (-1); + close(fd); + return (0); +} diff --git a/src/ft_get_sprite.c b/src/ft_get_sprite.c index 791f51f..ebf0566 100644 --- a/src/ft_get_sprite.c +++ b/src/ft_get_sprite.c @@ -35,5 +35,10 @@ int8_t ft_strlen(FT_ERR_ALLOCATE) + 1); return (-1); } + if (ft_check_not_found(clist->mlist->sprite_path) < 0) + { + ft_strlcpy(clist->errmsg, FT_ERR_RD_SP, ft_strlen(FT_ERR_RD_SP) + 1); + return (-1); + } return (0); } diff --git a/src/ft_get_tex.c b/src/ft_get_tex.c index ad093ed..58a0358 100644 --- a/src/ft_get_tex.c +++ b/src/ft_get_tex.c @@ -35,6 +35,11 @@ int8_t ft_strlen(FT_ERR_ALLOCATE) + 1); return (-1); } + if (ft_check_not_found(clist->mlist->no_tex_path) < 0) + { + ft_strlcpy(clist->errmsg, FT_ERR_RD_NO, ft_strlen(FT_ERR_RD_NO) + 1); + return (-1); + } return (0); } @@ -59,6 +64,11 @@ int8_t ft_strlen(FT_ERR_ALLOCATE) + 1); return (-1); } + if (ft_check_not_found(clist->mlist->so_tex_path) < 0) + { + ft_strlcpy(clist->errmsg, FT_ERR_RD_SO, ft_strlen(FT_ERR_RD_SO) + 1); + return (-1); + } return (0); } @@ -83,6 +93,11 @@ int8_t ft_strlen(FT_ERR_ALLOCATE) + 1); return (-1); } + if (ft_check_not_found(clist->mlist->ea_tex_path) < 0) + { + ft_strlcpy(clist->errmsg, FT_ERR_RD_EA, ft_strlen(FT_ERR_RD_EA) + 1); + return (-1); + } return (0); } @@ -107,5 +122,10 @@ int8_t ft_strlen(FT_ERR_ALLOCATE) + 1); return (-1); } + if (ft_check_not_found(clist->mlist->we_tex_path) < 0) + { + ft_strlcpy(clist->errmsg, FT_ERR_RD_WE, ft_strlen(FT_ERR_RD_WE) + 1); + return (-1); + } return (0); } diff --git a/src/ft_parse_map.c b/src/ft_parse_map.c index 4fd870b..0dfb779 100644 --- a/src/ft_parse_map.c +++ b/src/ft_parse_map.c @@ -100,6 +100,5 @@ void ft_get_player_spawn(clist->plist, clist); ft_check_missing(clist); ft_set_minimap_scale(clist); - ft_print_list(clist); close(fd); } diff --git a/src/ft_print_list.c b/src/ft_print_list.c deleted file mode 100644 index 3b44115..0000000 --- a/src/ft_print_list.c +++ /dev/null @@ -1,40 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_print_list.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: rbousset +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2020/02/14 17:28:57 by rbousset #+# #+# */ -/* Updated: 2020/02/14 17:28:57 by rbousset ### ########lyon.fr */ -/* */ -/* ************************************************************************** */ - -#include -#include - -void - ft_print_list(t_cub *clist) -{ - size_t i; - - ft_printf("x size ----- [%d]\n", clist->wlist->x_size); - ft_printf("y size ----- [%d]\n", clist->wlist->y_size); - ft_printf("North ------ [%s]\n", clist->mlist->no_tex_path); - ft_printf("South ------ [%s]\n", clist->mlist->so_tex_path); - ft_printf("West ------- [%s]\n", clist->mlist->we_tex_path); - ft_printf("East ------- [%s]\n", clist->mlist->ea_tex_path); - ft_printf("Sprite ----- [%s]\n", clist->mlist->sprite_path); - ft_printf("F color ---- [%d]\n", ft_rgb_to_hex(clist->f_rgb)); - ft_printf("C color ---- [%d]\n", ft_rgb_to_hex(clist->c_rgb)); - i = 0; - ft_printf("Map\n----\n"); - while (clist->mlist->map[i]) - { - ft_printf("%2zu -- [%s]\n", i + 1, clist->mlist->map[i]); - i++; - } - ft_printf("Map width -- [%zu]\n", clist->mlist->map_w); - ft_printf("2D scale --- [%hhu]\n", clist->mlist->scale); - ft_printf("----------------------\n"); -} diff --git a/src/ft_tex_init.c b/src/ft_tex_init.c index 724877f..40e39e5 100644 --- a/src/ft_tex_init.c +++ b/src/ft_tex_init.c @@ -10,10 +10,10 @@ /* */ /* ************************************************************************** */ +#include #include #include #include -#include /* ** 0 : no @@ -26,23 +26,23 @@ 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->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->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->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->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->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); } -- cgit v1.2.3