diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-01-28 16:22:51 +0100 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-01-28 16:22:51 +0100 |
commit | 6ee3017b31456ae8bcf4f21389e514b67d885098 (patch) | |
tree | 39a8354d65268b607d110c67deee9faac081cb5d | |
parent | Bug fix (diff) | |
download | 42-cub3d-6ee3017b31456ae8bcf4f21389e514b67d885098.tar.gz 42-cub3d-6ee3017b31456ae8bcf4f21389e514b67d885098.tar.bz2 42-cub3d-6ee3017b31456ae8bcf4f21389e514b67d885098.tar.xz 42-cub3d-6ee3017b31456ae8bcf4f21389e514b67d885098.tar.zst 42-cub3d-6ee3017b31456ae8bcf4f21389e514b67d885098.zip |
Got tex
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | inc/cub3d.h | 9 | ||||
-rw-r--r-- | map/map_one.cub | 15 | ||||
-rw-r--r-- | src/ft_get_sprite.c | 29 | ||||
-rw-r--r-- | src/ft_get_sprite_tex.c | 2 | ||||
-rw-r--r-- | src/ft_get_tex.c | 111 | ||||
-rw-r--r-- | src/ft_parse_map.c | 4 | ||||
-rw-r--r-- | src/ft_select_get.c | 19 |
8 files changed, 90 insertions, 101 deletions
@@ -24,7 +24,7 @@ SRCS_NAME += ft_drawsquare.c SRCS_NAME += ft_parse_map.c SRCS_NAME += ft_select_get.c SRCS_NAME += ft_get_res.c -# SRCS_NAME += ft_get_tex.c +SRCS_NAME += ft_get_tex.c # SRCS_NAME += ft_get_sprite_tex.c # SRCS_NAME += ft_get_colors.c # SRCS_NAME += ft_get_map.c diff --git a/inc/cub3d.h b/inc/cub3d.h index 3a18cd8..e0b2f79 100644 --- a/inc/cub3d.h +++ b/inc/cub3d.h @@ -50,10 +50,13 @@ int ft_key_event(int keycode, void *param); int ft_exit(uint8_t exit_code, t_cub *clist); void ft_drawsquare(int a, int b, int rgb, t_cub *clist); void ft_parse_map(const char *map_path, t_cub *clist); -int ft_select_get(char **words, t_cub *clist); +uint8_t ft_select_get(char **words, t_cub *clist); int ft_get_res(char **words, t_cub *clist); -int ft_get_tex(int fd, t_cub *clist); -int ft_get_sprite_tex(int fd, t_cub *clist); +int ft_get_tex_no(char **words, t_cub *clist); +int ft_get_tex_so(char **words, t_cub *clist); +int ft_get_tex_ea(char **words, t_cub *clist); +int ft_get_tex_we(char **words, t_cub *clist); +int ft_get_sprite(char **words, t_cub *clist); int ft_get_colors(int fd, t_cub *clist); int ft_get_map(int fd, t_cub *clist); void ft_check_empty_line(int fd, diff --git a/map/map_one.cub b/map/map_one.cub index 9728683..70d8d5d 100644 --- a/map/map_one.cub +++ b/map/map_one.cub @@ -1,7 +1,20 @@ + + + R 1400 900 + + + + NO ./path_to_the_north_texture + + + + + + SO ./path_to_the_south_texture -WE ./path_to_the_west_texture +WE ./path_to_the_west_texture qweqwe EA ./path_to_the_east_texture S ./path_to_the_sprite_texture diff --git a/src/ft_get_sprite.c b/src/ft_get_sprite.c new file mode 100644 index 0000000..568e513 --- /dev/null +++ b/src/ft_get_sprite.c @@ -0,0 +1,29 @@ +#include <libft.h> +#include <cub3d.h> +#include <stdlib.h> + +int +ft_get_sprite(int fd, t_cub *clist) +{ + char *line; + char **words; + + if (get_next_line(fd, &line) <= 0 || !(words = ft_split(line, ' '))) + { + ft_memdel(line); + return (ft_map_error(7, clist)); + } + if (!(*words) || ft_strcmp(*words, "S") || !words[1] || words[2]) + { + ft_free_words(words, line); + return (ft_map_error(7, clist)); + } + ft_memdel(clist->sprite_path); + if (!(clist->sprite_path = ft_strdup(*(words + 1)))) + { + ft_free_words(words, line); + return (-1); + } + ft_free_words(words, line); + return (0); +} diff --git a/src/ft_get_sprite_tex.c b/src/ft_get_sprite_tex.c index 4db469a..8eb9481 100644 --- a/src/ft_get_sprite_tex.c +++ b/src/ft_get_sprite_tex.c @@ -3,7 +3,7 @@ #include <stdlib.h> int -ft_get_sprite_tex(int fd, t_cub *clist) +ft_get_sprite(char **words, t_cub *clist) { char *line; char **words; diff --git a/src/ft_get_tex.c b/src/ft_get_tex.c index 1a936bd..a409a3c 100644 --- a/src/ft_get_tex.c +++ b/src/ft_get_tex.c @@ -2,121 +2,50 @@ #include <cub3d.h> #include <stdlib.h> -static int -ft_get_tex_no(int fd, t_cub *clist) +int +ft_get_tex_no(char **words, t_cub *clist) { - char *line; - char **words; - - if (get_next_line(fd, &line) <= 0 || !(words = ft_split(line, ' '))) - { - ft_memdel(line); - return (ft_map_error(2, clist)); - } - if (!(*words) || ft_strcmp(*words, "NO") - || !(*(words + 1)) || (*(words + 2))) - { - ft_free_words(words, line); - return (ft_map_error(2, clist)); - } + if (!(*words) || !(*(words + 1)) || (*(words + 2))) + return (-1); ft_memdel(clist->no_tex_path); if (!(clist->no_tex_path = ft_strdup(*(words + 1)))) - { - ft_free_words(words, line); return (-1); - } - ft_free_words(words, line); + ft_free_words(words); return (0); } -static int -ft_get_tex_so(int fd, t_cub *clist) +int +ft_get_tex_so(char **words, t_cub *clist) { - char *line; - char **words; - - if (get_next_line(fd, &line) <= 0 || !(words = ft_split(line, ' '))) - { - ft_memdel(line); - return (ft_map_error(3, clist)); - } - if (!(*words) || ft_strcmp(*words, "SO") - || !(*(words + 1)) || (*(words + 2))) - { - ft_free_words(words, line); - return (ft_map_error(3, clist)); - } + if (!(*words) || !(*(words + 1)) || (*(words + 2))) + return (-1); ft_memdel(clist->so_tex_path); if (!(clist->so_tex_path = ft_strdup(*(words + 1)))) - { - ft_free_words(words, line); return (-1); - } - ft_free_words(words, line); + ft_free_words(words); return (0); } -static int -ft_get_tex_we(int fd, t_cub *clist) +int +ft_get_tex_ea(char **words, t_cub *clist) { - char *line; - char **words; - - if (get_next_line(fd, &line) <= 0 || !(words = ft_split(line, ' '))) - { - ft_memdel(line); - return (ft_map_error(4, clist)); - } - if (!(*words) || ft_strcmp(*words, "WE") - || !(*(words + 1)) || (*(words + 2))) - { - ft_free_words(words, line); - return (ft_map_error(4, clist)); - } - ft_memdel(clist->we_tex_path); - if (!(clist->we_tex_path = ft_strdup(*(words + 1)))) - { - ft_free_words(words, line); + if (!(*words) || !(*(words + 1)) || (*(words + 2))) return (-1); - } - ft_free_words(words, line); - return (0); -} - -static int -ft_get_tex_ea(int fd, t_cub *clist) -{ - char *line; - char **words; - - if (get_next_line(fd, &line) <= 0 || !(words = ft_split(line, ' '))) - { - ft_memdel(line); - return (ft_map_error(5, clist)); - } - if (!(*words) || ft_strcmp(*words, "EA") - || !(*(words + 1)) || (*(words + 2))) - { - ft_free_words(words, line); - return (ft_map_error(5, clist)); - } ft_memdel(clist->ea_tex_path); if (!(clist->ea_tex_path = ft_strdup(*(words + 1)))) - { - ft_free_words(words, line); return (-1); - } - ft_free_words(words, line); + ft_free_words(words); return (0); } int -ft_get_tex(int fd, t_cub *clist) +ft_get_tex_we(char **words, t_cub *clist) { - if (ft_get_tex_no(fd, clist) < 0 || - ft_get_tex_so(fd, clist) < 0 || - ft_get_tex_we(fd, clist) < 0 || - ft_get_tex_ea(fd, clist) < 0) + if (!(*words) || !(*(words + 1)) || (*(words + 2))) + return (-1); + ft_memdel(clist->we_tex_path); + if (!(clist->we_tex_path = ft_strdup(*(words + 1)))) return (-1); + ft_free_words(words); return (0); } diff --git a/src/ft_parse_map.c b/src/ft_parse_map.c index dfa1ba6..7704ff2 100644 --- a/src/ft_parse_map.c +++ b/src/ft_parse_map.c @@ -91,7 +91,7 @@ ft_parse_map(const char *map_path, t_cub *clist) ret = 1; while (ret != 12) ret = ft_parse_it(fd, clist); - ft_get_map(void); + /* ft_get_map(void); */ /* if (ft_get_tex(fd, clist) < 0) */ /* return ; */ /* ft_check_empty_line(fd, 6, clist); */ @@ -102,6 +102,6 @@ ft_parse_map(const char *map_path, t_cub *clist) /* if (ft_get_map(fd, clist) < 0) */ /* ft_map_error(11, clist); */ /* ft_check_map_last_line(clist); */ - /* ft_print_list(clist); */ + ft_print_list(clist); close(fd); } diff --git a/src/ft_select_get.c b/src/ft_select_get.c index 25320d7..7b1b524 100644 --- a/src/ft_select_get.c +++ b/src/ft_select_get.c @@ -9,19 +9,34 @@ ft_get_id(char **words) return (0); if (!ft_strcmp(words[0], "NO")) return (1); + if (!ft_strcmp(words[0], "SO")) + return (2); + if (!ft_strcmp(words[0], "EA")) + return (3); + if (!ft_strcmp(words[0], "WE")) + return (4); + if (!ft_strcmp(words[0], "S")) + return (5); return (12); } uint8_t ft_select_get(char **words, t_cub *clist) { - int (*fun_ptr[4])(char**, t_cub*); + int (*fun_ptr[6])(char**, t_cub*); uint8_t id; fun_ptr[0] = ft_get_res; - fun_ptr[1] = ft_get_tex; + fun_ptr[1] = ft_get_tex_no; + fun_ptr[2] = ft_get_tex_so; + fun_ptr[3] = ft_get_tex_ea; + fun_ptr[4] = ft_get_tex_we; + fun_ptr[5] = ft_get_sprite; if ((id = ft_get_id(words)) == 12) + { + ft_free_words(words); return (12); + } if ((*fun_ptr[id])(words, clist) < 0) { ft_free_words(words); |