diff options
Diffstat (limited to '')
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | inc/cub3d.h | 2 | ||||
-rw-r--r-- | inc/cub3d_structs.h | 1 | ||||
-rw-r--r-- | map/map_five.cub | 8 | ||||
-rw-r--r-- | map/map_one.cub | 30 | ||||
-rw-r--r-- | src/ft_check_map_line.c | 12 | ||||
-rw-r--r-- | src/ft_get_map.c | 41 | ||||
-rw-r--r-- | src/ft_get_map_dims.c | 48 | ||||
-rw-r--r-- | src/ft_init_map.c | 1 | ||||
-rw-r--r-- | src/ft_parse_map.c | 8 |
10 files changed, 97 insertions, 55 deletions
@@ -33,6 +33,7 @@ SRCS_NAME += ft_get_tex.c SRCS_NAME += ft_get_sprite.c SRCS_NAME += ft_get_colors.c SRCS_NAME += ft_get_map.c +SRCS_NAME += ft_get_map_dims.c SRCS_NAME += ft_get_tex_nl.c SRCS_NAME += ft_get_path_nl.c SRCS_NAME += ft_get_nlvl_pos.c diff --git a/inc/cub3d.h b/inc/cub3d.h index edc462f..5808560 100644 --- a/inc/cub3d.h +++ b/inc/cub3d.h @@ -92,6 +92,8 @@ int8_t ft_get_c_color(char **words, t_cub *clist); int8_t ft_get_path_nl(char **words, t_cub *clist); int8_t ft_get_tex_nl(char **words, t_cub *clist); int8_t ft_get_music(char **words, t_cub *clist); +size_t ft_get_map_h(char **map); +size_t ft_get_map_w(char **map); int8_t ft_check_map_line(char *line, uint8_t l, t_cub *clist); int8_t ft_check_ext(const char *filep, const char *ext); int8_t ft_check_not_found(const char *path); diff --git a/inc/cub3d_structs.h b/inc/cub3d_structs.h index b19eae6..ae5ee02 100644 --- a/inc/cub3d_structs.h +++ b/inc/cub3d_structs.h @@ -121,6 +121,7 @@ typedef struct s_map int8_t y_step; size_t map_w; size_t map_h; + size_t mapl_len; size_t line_chk; size_t map_start; uint8_t isspawn; diff --git a/map/map_five.cub b/map/map_five.cub index cea7045..80ebff6 100644 --- a/map/map_five.cub +++ b/map/map_five.cub @@ -15,10 +15,10 @@ C 225,30,0 111111111011000001110000000000001 100000000011000001110111111111111 11110111111111011100000010001 -11110111111111011101010010001 -11000000110101011100000010001 -10002000000000001100000010001 -10000000000000001101010010001 +11110111111111011101010000001 +11000000110101011100000000001 +10002000000000000000000000001 +10000000000000000001010000001 11000001110101011111011110N0111 11110111 1110101 101111010001 11111111 1111111 111111111111 diff --git a/map/map_one.cub b/map/map_one.cub index f19a0ab..4dad431 100644 --- a/map/map_one.cub +++ b/map/map_one.cub @@ -9,18 +9,18 @@ S ./media/img/pillar.xpm C 50,100,200 F 50,190,124 -1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 -1 2 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 1 -1 0 0 1 0 2 0 0 0 0 0 0 0 0 0 0 0 1 -1 N 1 1 0 0 0 0 0 1 1 1 0 0 0 0 0 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 -1 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 1 -1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 -1 0 1 1 0 0 0 0 0 1 1 1 0 0 0 0 0 1 -1 1 1 1 0 1 1 1 1 1 1 1 1 1 0 1 1 1 -1 1 0 0 0 0 0 0 1 1 0 1 0 1 0 1 1 1 -1 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 1 1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 -1 1 0 0 0 0 0 0 1 1 0 1 0 1 0 1 1 1 -1 1 1 1 0 1 1 1 1 1 1 1 0 1 0 1 1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 +111111111111111111 +120000000011000001 +100102000000000001 +1N1100000111000001 +111111111111110011 +100000000011000001 +100100000000000001 +101100000111000001 +111101111111110111 +110000001101010111 +100020000000000011 +100000000000000011 +110000001101010111 +111101111111010111 +111111111111111111 diff --git a/src/ft_check_map_line.c b/src/ft_check_map_line.c index c5b4cdc..2d69545 100644 --- a/src/ft_check_map_line.c +++ b/src/ft_check_map_line.c @@ -71,7 +71,7 @@ size_t static int8_t ft_check_side_walls(char *line, size_t i, t_cub *clist) { - if (line[0] != '1' || line[i - 1] != '1') + if ((line [0] != ' ' && line[0] != '1') || line[i - 1] != '1') { ft_sprintf(clist->errmsg, FT_ERR_MAP_WALLS); return (-1); @@ -100,10 +100,10 @@ int8_t } if (ft_check_side_walls(line, i, clist) < 0) return (-1); - if (ft_get_line_len(line) != clist->mlist.map_w) - { - ft_sprintf(clist->errmsg, FT_ERR_MAP_LEN); - return (-1); - } + /* if (ft_get_line_len(line) != clist->mlist.map_w) */ + /* { */ + /* ft_sprintf(clist->errmsg, FT_ERR_MAP_LEN); */ + /* return (-1); */ + /* } */ return (0); } diff --git a/src/ft_get_map.c b/src/ft_get_map.c index fb8e0f2..08c9734 100644 --- a/src/ft_get_map.c +++ b/src/ft_get_map.c @@ -12,20 +12,10 @@ #include <libft.h> #include <cub3d.h> +#include <stdlib.h> #include <stddef.h> #include <stdint.h> -static size_t - ft_get_map_h(char **map) -{ - size_t i; - - i = 0; - while (map[i]) - i++; - return (i); -} - static void ft_linecpy(char *line, char *mapl, size_t start) { @@ -38,8 +28,6 @@ static void slen = ft_strlen(line); while (i < slen && line[i]) { - while (line[i] == ' ') - i++; mapl[j] = line[i]; i++; j++; @@ -48,16 +36,19 @@ static void } static int8_t - ft_cat_mapl(char *line, size_t i, t_cub *clist) + ft_cat_mapl(char *line, 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 (!line[0] || + !(clist->mlist.mapl = (char *)ft_nrealloc(clist->mlist.mapl, + clist->mlist.mapl_len * sizeof(char), + (clist->mlist.mapl_len + ft_strlen(line) + 1) * sizeof(char)))) { ft_sprintf(clist->errmsg, 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.mapl_len); + clist->mlist.mapl_len += ft_strlen(line) + 1; return (0); } @@ -68,18 +59,16 @@ int if (!line[0]) { ft_memdel((void**)&line); - ft_sprintf(clist->errmsg, "%s", FT_ERR_READ); + ft_sprintf(clist->errmsg, FT_ERR_READ); return (-1); } - 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); - if (ft_cat_mapl(line, 0, clist) < 0) + if (ft_cat_mapl(line, clist) < 0) { ft_memdel((void**)&line); return (-1); @@ -92,16 +81,14 @@ int ft_get_map_core(int fd, t_cub *clist) { int ret; - size_t i; char *line; - i = 1; ret = 1; while ((ret = get_next_line(fd, &line)) > 0) { clist->mlist.line_chk += 1; if (!line[0] || ft_check_map_line(line, 0, clist) < 0 - || ft_cat_mapl(line, i, clist) < 0) + || ft_cat_mapl(line, clist) < 0) { if (!line[0]) ft_sprintf(clist->errmsg, FT_ERR_MAP_EMPL); @@ -109,13 +96,13 @@ int return (-1); } ft_memdel((void**)&line); - i++; } ft_memdel((void**)&line); - clist->mlist.mapl[((clist->mlist.map_w + 1) * i) - 1] = '\0'; + clist->mlist.mapl[clist->mlist.mapl_len - 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); + clist->mlist.map_w = ft_get_map_w(clist->mlist.map); ft_memdel((void**)&clist->mlist.mapl); return (0); } diff --git a/src/ft_get_map_dims.c b/src/ft_get_map_dims.c new file mode 100644 index 0000000..a26a891 --- /dev/null +++ b/src/ft_get_map_dims.c @@ -0,0 +1,48 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_get_map_dims.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:28:47 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:28:47 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include <libft.h> +#include <cub3d.h> +#include <stdlib.h> +#include <stddef.h> +#include <stdint.h> + +size_t + ft_get_map_h(char **map) +{ + size_t i; + + i = 0; + while (map[i]) + i++; + return (i); +} + +size_t + ft_get_map_w(char **map) +{ + size_t i; + size_t big; + size_t tmp; + + i = 0; + big = 0; + tmp = 0; + while (map[i]) + { + tmp = ft_strlen(map[i]); + if (tmp > big) + big = tmp; + i++; + } + return (big); +} diff --git a/src/ft_init_map.c b/src/ft_init_map.c index a6704b6..e2cfa21 100644 --- a/src/ft_init_map.c +++ b/src/ft_init_map.c @@ -42,6 +42,7 @@ int8_t mlist->map[1] = 0; mlist->map_w = 0; mlist->map_h = 0; + mlist->mapl_len = 0; mlist->x_step = 0; mlist->y_step = 0; mlist->line_chk = 0; diff --git a/src/ft_parse_map.c b/src/ft_parse_map.c index 256d131..0d54c6f 100644 --- a/src/ft_parse_map.c +++ b/src/ft_parse_map.c @@ -29,9 +29,11 @@ static void while (ml->map[i]) i++; j = 0; - while (ml->map[i - 1][j]) + i -= 1; + while (ml->map[i][j]) { - if (ml->map[i - 1][j] != '1' && ml->map[i - 1][j] != '\0') + if (ml->map[i][j] != '1' && ml->map[i][j] != ' ' && + ml->map[i][j] != '\0') ft_map_error(FT_ERR_MAP_L_L, clist); j++; } @@ -112,11 +114,11 @@ void if (ft_get_map_core(fd, clist) < 0) ft_map_error(clist->errmsg, clist); ft_check_map_last_line(clist); + ft_print_map(&clist->mlist); ft_get_player_spawn(&clist->plist, clist); ft_get_nlvl_pos(&clist->mlist); ft_check_missing(clist); ft_set_minimap_scale(clist); - ft_print_map(&clist->mlist); clist->currlvl += 1; close(fd); } |