From 40f8821b47d9b96e588e98d34ce5d0a645eec358 Mon Sep 17 00:00:00 2001 From: YANNIS Date: Sat, 15 Feb 2025 03:02:33 +0100 Subject: [PATCH] MAJ parsing_color et config_ambient --- .gitmodules | 3 +++ libft | 1 + miniRT.h | 5 ++++- parsing_ambiant.c | 1 + parsing_color.c | 15 +++++++++++++++ parsing_utils.c | 3 +-- 6 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 .gitmodules create mode 160000 libft diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..1cba40a --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "libft"] + path = libft + url = git@github.com:H3XploR/libft.git diff --git a/libft b/libft new file mode 160000 index 0000000..060e991 --- /dev/null +++ b/libft @@ -0,0 +1 @@ +Subproject commit 060e991b6fce3d4d9418cd47b3b14f7cbd438ccc diff --git a/miniRT.h b/miniRT.h index 118322c..07e6f6e 100644 --- a/miniRT.h +++ b/miniRT.h @@ -19,6 +19,7 @@ # include # include # include +# include "libft.h" // ----- Taille ecran ---- # define WIDTH 320 @@ -104,7 +105,9 @@ typedef struct s_scene int numCylinders; int numLights; int numAmbient; - const char *line; + const char *line_if_exit; + const int fd_if_exit; + const char **token_if_exit; } t_scene; // Calcul de vecteur diff --git a/parsing_ambiant.c b/parsing_ambiant.c index 099c0f7..f928de4 100644 --- a/parsing_ambiant.c +++ b/parsing_ambiant.c @@ -16,6 +16,7 @@ t_scene parsing_ambiant(const char *line, t_scene scene) { const char **tokens = get_tokens_secure(scene, scene.numAmbient, MAX_AMBIENT, 3); + scene.token_if_exit = tokens; scene.ambient.ambient_ratio = ft_atof(tokens[1]); scene.ambient.ambient_color = parse_color(tokens[2], scene); ft_free_array(tokens); diff --git a/parsing_color.c b/parsing_color.c index 74f517c..b0fd570 100644 --- a/parsing_color.c +++ b/parsing_color.c @@ -14,4 +14,19 @@ t_color parse_color(const char *token, t_scene scene) { + const char **token_color = ft_split(token, ','); + t_color color; + + if (!check_tokens(token_color, 3)) + { + ft_free_array(tokens_color); + ft_free_array(scene.token_if_exit); + ft_putendl_fd("error", 2); + free(scene.line_if_exit); + close(scene.fd); + exit(1); + } + color.r = ft_atoi(token_color[0]) / 255; + color.g = ft_atoi(token_color[1]) / 255; + color.b = ft_atoi(token_color[2]) / 255; } diff --git a/parsing_utils.c b/parsing_utils.c index 54bd35e..bbfa1af 100644 --- a/parsing_utils.c +++ b/parsing_utils.c @@ -17,9 +17,8 @@ inline char **get_tokens_secure(t_scene scene, const int numObject, const int nu { const int result_if_max = check_if_max(scene, numObject, numObjectMax); const char **tokens = ft_split(scene.line_if_exit, ' '); - const int result_check_tokens = check_tokens(tokens, supposed_nb_token); - if (!result_check_tokens) + if (!check_tokens(tokens, supposed_nb_token)) { ft_free_array(tokens); ft_putendl_fd("error", 2);