diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-01-29 23:21:16 +0100 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-01-29 23:21:16 +0100 |
commit | 3fe40e249fbad468347b2a0d643b19f1f5f3f524 (patch) | |
tree | f696e53265307a1b15b36c2d72bb6dfbd95a8885 | |
parent | it's wonderful (diff) | |
download | 42-cub3d-3fe40e249fbad468347b2a0d643b19f1f5f3f524.tar.gz 42-cub3d-3fe40e249fbad468347b2a0d643b19f1f5f3f524.tar.bz2 42-cub3d-3fe40e249fbad468347b2a0d643b19f1f5f3f524.tar.xz 42-cub3d-3fe40e249fbad468347b2a0d643b19f1f5f3f524.tar.zst 42-cub3d-3fe40e249fbad468347b2a0d643b19f1f5f3f524.zip |
I've seen enough
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | map/map_one.cub | 2 | ||||
-rw-r--r-- | src/ft_exit.c | 9 | ||||
-rw-r--r-- | src/ft_get_colors.c | 2 | ||||
-rw-r--r-- | src/ft_get_map.c | 109 | ||||
-rw-r--r-- | src/ft_get_map_redo.c | 90 | ||||
-rw-r--r-- | src/ft_get_res.c | 3 | ||||
-rw-r--r-- | src/ft_init_lists.c | 11 | ||||
-rw-r--r-- | src/ft_init_winlx.c | 3 |
9 files changed, 57 insertions, 176 deletions
@@ -27,11 +27,9 @@ SRCS_NAME += ft_get_res.c 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_redo.c +SRCS_NAME += ft_get_map.c SRCS_NAME += ft_check_missing.c SRCS_NAME += ft_check_map_line.c -# SRCS_NAME += ft_check_empty_line.c SRCS_NAME += ft_free_words.c SRCS_NAME += ft_map_error.c SRCS_NAME += ft_init_winlx.c diff --git a/map/map_one.cub b/map/map_one.cub index 837c115..1133597 100644 --- a/map/map_one.cub +++ b/map/map_one.cub @@ -1,4 +1,4 @@ -R 1400 900 +R 1200 600 NO ./path_to_the_north_texture SO ./path_to_the_south_texture diff --git a/src/ft_exit.c b/src/ft_exit.c index c445e37..8bd8ac0 100644 --- a/src/ft_exit.c +++ b/src/ft_exit.c @@ -14,8 +14,8 @@ ft_free_lists(t_cub *clist) ft_memdel(clist->we_tex_path); ft_memdel(clist->sprite_path); ft_free_words(clist->map); - /* if (!clist->wlist->inited) */ - ft_memdel(clist->wlist->winptr); + if (!clist->wlist->inited) + ft_memdel(clist->wlist->winptr); ft_memdel(clist->wlist->wlx); ft_memdel(clist->wlist); ft_memdel(clist); @@ -25,14 +25,11 @@ int ft_exit(uint8_t exit_code, t_cub *clist) { if (clist->wlist->inited) - { mlx_destroy_window(clist->wlist->wlx, clist->wlist->winptr); - clist->wlist->winptr = NULL; - } + ft_free_lists(clist); ft_printf("Exiting program\n"); if (exit_code < 0 || exit_code > 0) ft_printf("Exit code: %hhu\n", exit_code); - ft_free_lists(clist); exit(exit_code); return (0); } diff --git a/src/ft_get_colors.c b/src/ft_get_colors.c index 226b427..f21cd99 100644 --- a/src/ft_get_colors.c +++ b/src/ft_get_colors.c @@ -37,6 +37,7 @@ ft_get_f_color(char **words, t_cub *clist) clist->f_color += ft_atoi(num[1]); clist->f_color *= 1000; clist->f_color += ft_atoi(num[2]); + ft_free_words(num); return (0); } @@ -62,5 +63,6 @@ ft_get_c_color(char **words, t_cub *clist) clist->c_color += ft_atoi(num[1]); clist->c_color *= 1000; clist->c_color += ft_atoi(num[2]); + ft_free_words(num); return (0); } diff --git a/src/ft_get_map.c b/src/ft_get_map.c index ff16df1..12ab7f7 100644 --- a/src/ft_get_map.c +++ b/src/ft_get_map.c @@ -1,110 +1,91 @@ #include <libft.h> #include <cub3d.h> #include <stddef.h> -#include <stdlib.h> +#include <stdint.h> -static int +static void ft_linecpy(char *line, char *mapl, size_t start) { size_t i; size_t j; + size_t slen; i = 0; j = start; - while (i < ft_strlen(line) && line[i]) + slen = ft_strlen(line); + while (i < slen && line[i]) { + while (line[i] == ' ') + i++; mapl[j] = line[i]; - i += 2; + i++; j++; } mapl[j] = '\n'; - return (0); } -static int -ft_check_err(char *line, size_t size) +static int8_t +ft_cat_mapl(char *line, size_t i, t_cub *clist) { - size_t i; - - i = 1; - if (ft_strlen(line) != size || line[0] != '1' - || line[ft_strlen(line) - 1] != '1') + if (!(clist->mapl = (char *)ft_nrealloc(clist->mapl, + ((clist->map_w + 1) * i) * sizeof(char), + ((clist->map_w + 1) * (i + 1)) * sizeof(char)))) return (-1); - while (i < ft_strlen(line) && line[i]) - { - if (line[i] != ' ') - return (-1); - i += 2; - } + ft_linecpy(line, clist->mapl, (clist->map_w + 1) * i); return (0); } -static char -*ft_get_first_line(char *line, t_cub *clist) +int +ft_get_map_first_line(char *line, t_cub *clist) { - size_t i; - char *mapl; - - i = 0; - while (i < ft_strlen(line) && line[i]) + if (!line[0]) { - if (line[i] != '1' && line[i] != '\0') - return (NULL); - i += 2; + ft_memdel(line); + return (-1); } - clist->map_w = ft_strlen(line); - if (clist->map_w <= 2 || ft_check_err(line, clist->map_w) < 0) - return (NULL); - if (!(mapl = (char*)malloc(((clist->map_w / 2) + 2) * sizeof(char)))) - return (NULL); - ft_linecpy(line, mapl, 0); - ft_memdel(line); - return (mapl); -} - -static char -*ft_get_core_map(char *line, char *mapl, size_t i, t_cub *clist) -{ - if (ft_check_err(line, clist->map_w) < 0) + clist->map_w = ft_get_line_len(line); + if (ft_check_map_line(line, 1, clist) < 0) + { + ft_memdel(line); + return (-1); + } + clist->mapl = NULL; + if (ft_cat_mapl(line, 0, clist) < 0) { ft_memdel(line); - ft_memdel(mapl); - return (NULL); + return (-1); } - if (!(mapl = (char*)ft_nrealloc(mapl, (((clist->map_w / 2) + 2) * i) - * sizeof(char), ((((clist->map_w / 2) + 2) * i) + - (clist->map_w / 2) + 2) * sizeof(char)))) - return (NULL); - ft_linecpy(line, mapl, ((clist->map_w / 2) + 2) * i); ft_memdel(line); - return (mapl); + return (1); } int -ft_get_map(int fd, t_cub *clist) +ft_get_map_core(int fd, t_cub *clist) { - size_t i; int ret; + size_t i; char *line; - char *mapl; - if ((ret = get_next_line(fd, &line)) <= 0 || - !(mapl = ft_get_first_line(line, clist))) - { - ft_memdel(line); - return (-1); - } i = 1; + ret = 1; while (ret > 0) { + clist->line_chk += 1; ret = get_next_line(fd, &line); - if (!(mapl = ft_get_core_map(line, mapl, i, clist))) + if (ret < 0) + return (-1); + if (!line[0] || ft_check_map_line(line, 0, clist) < 0 + || ft_cat_mapl(line, i, clist) < 0) + { + ft_memdel(line); return (-1); + } + ft_memdel(line); i++; } - mapl[(i * ((clist->map_w / 2) + 2)) - 1] = '\0'; - ft_free_words(clist->map, NULL); - clist->map = ft_split(mapl, '\n'); - ft_memdel(mapl); + clist->mapl[((clist->map_w + 1) * i) - 1] = '\0'; + ft_free_words(clist->map); + clist->map = ft_split(clist->mapl, '\n'); + ft_memdel(clist->mapl); return (0); } diff --git a/src/ft_get_map_redo.c b/src/ft_get_map_redo.c deleted file mode 100644 index 2f020f9..0000000 --- a/src/ft_get_map_redo.c +++ /dev/null @@ -1,90 +0,0 @@ -#include <libft.h> -#include <cub3d.h> -#include <stddef.h> -#include <stdint.h> - -static void -ft_linecpy(char *line, char *mapl, size_t start) -{ - size_t i; - size_t j; - size_t slen; - - i = 0; - j = start; - slen = ft_strlen(line); - while (i < slen && line[i]) - { - while (line[i] == ' ') - i++; - mapl[j] = line[i]; - i++; - j++; - } - mapl[j] = '\n'; -} - -static int8_t -ft_cat_mapl(char *line, size_t i, t_cub *clist) -{ - if (!(clist->mapl = (char *)ft_nrealloc(clist->mapl, - ((clist->map_w + 1) * i) * sizeof(char), - ((clist->map_w + 1) * (i + 1)) * sizeof(char)))) - return (-1); - ft_linecpy(line, clist->mapl, (clist->map_w + 1) * i); - return (0); -} - -int -ft_get_map_first_line(char *line, t_cub *clist) -{ - if (!line[0]) - { - ft_memdel(line); - return (-1); - } - clist->map_w = ft_get_line_len(line); - if (ft_check_map_line(line, 1, clist) < 0) - { - ft_memdel(line); - return (-1); - } - clist->mapl = NULL; - if (ft_cat_mapl(line, 0, clist) < 0) - { - ft_memdel(line); - return (-1); - } - ft_memdel(line); - return (1); -} - -int -ft_get_map_core(int fd, t_cub *clist) -{ - int ret; - size_t i; - char *line; - - i = 1; - ret = 1; - while (ret > 0) - { - clist->line_chk += 1; - ret = get_next_line(fd, &line); - if (ret < 0) - return (-1); - if (!line[0] || ft_check_map_line(line, 0, clist) < 0 - || ft_cat_mapl(line, i, clist) < 0) - { - ft_memdel(line); - return (-1); - } - i++; - } - clist->mapl[((clist->map_w + 1) * i) - 1] = '\0'; - ft_free_words(clist->map); - clist->map = ft_split(clist->mapl, '\n'); - ft_memdel(clist->mapl); - return (0); -} diff --git a/src/ft_get_res.c b/src/ft_get_res.c index 6fecb74..372ebca 100644 --- a/src/ft_get_res.c +++ b/src/ft_get_res.c @@ -23,5 +23,8 @@ ft_get_res(char **words, t_cub *clist) ft_checkdigit(words[2], clist); clist->wlist->x_size = ft_atoi(words[1]); clist->wlist->y_size = ft_atoi(words[2]); + if (clist->wlist->x_size < 10 + || clist->wlist->y_size < 10) + return (-1); return (0); } diff --git a/src/ft_init_lists.c b/src/ft_init_lists.c index 4fb5256..217d303 100644 --- a/src/ft_init_lists.c +++ b/src/ft_init_lists.c @@ -11,11 +11,9 @@ t_win if (!(wlist = (t_win*)malloc(sizeof(t_win)))) return (NULL); - if (!(wlist->wlx = ft_calloc(1, 1)) || - !(wlist->winptr = ft_calloc(1, 1))) + if (!(wlist->wlx = malloc(1)) || + !(wlist->winptr = malloc(1))) return (NULL); - wlist->wlx = NULL; - wlist->winptr = NULL; wlist->inited = 0; wlist->x_size = -1; wlist->y_size = -1; @@ -44,10 +42,5 @@ t_cub clist->map[1] = 0; clist->map_w = 0; clist->line_chk = 0; - clist->no_tex_path = NULL; - clist->so_tex_path = NULL; - clist->ea_tex_path = NULL; - clist->we_tex_path = NULL; - clist->sprite_path = NULL; return (clist); } diff --git a/src/ft_init_winlx.c b/src/ft_init_winlx.c index ff42e69..d45f19d 100644 --- a/src/ft_init_winlx.c +++ b/src/ft_init_winlx.c @@ -10,9 +10,6 @@ ft_init_winlx(t_cub *clist) if (!(clist->wlist->wlx = mlx_init())) return (-1); ft_memdel(clist->wlist->winptr); - if (!(clist->wlist->winptr = malloc(clist->wlist->x_size - * clist->wlist->y_size))) - return (-1); if (!(clist->wlist->winptr = mlx_new_window(clist->wlist->wlx, clist->wlist->x_size, clist->wlist->y_size, "Cub3D"))) return (-1); |