diff --git a/check.c b/check.c index 8eaf01d..37e274b 100644 --- a/check.c +++ b/check.c @@ -6,7 +6,7 @@ /* By: yantoine +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/14 18:28:42 by yantoine #+# #+# */ -/* Updated: 2025/02/14 18:51:17 by yantoine ### ########.fr */ +/* Updated: 2025/02/14 20:15:29 by yantoine ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,9 +17,9 @@ inline int check_tokens(char **tokens, int expected) return (tokens && ft_arraylen(tokens) == expected); } -inline void check_if_max(t_scene scene, const int lower_than) +inline void check_if_max(t_scene scene, const int to_test, const int max) { - if (scene.numAmbient >= lower_than) + if (to_test >= max) { printf("error:\n"); close(scene.fd_if_exit); diff --git a/miniRT.h b/miniRT.h index 8d0940f..118322c 100644 --- a/miniRT.h +++ b/miniRT.h @@ -6,7 +6,7 @@ /* By: yantoine +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/13 20:02:36 by yantoine #+# #+# */ -/* Updated: 2025/02/14 18:49:30 by yantoine ### ########.fr */ +/* Updated: 2025/02/14 20:45:21 by yantoine ### ########.fr */ /* */ /* ************************************************************************** */ @@ -126,8 +126,12 @@ t_scene parsing_light(const char *line, t_scene scene); t_scene parsing_sphere(const char *line, t_scene scene); t_scene parsing_plane(const char *line, t_scene scene); t_scene parsing_cylindre(const char *line, t_scene scene); +t_color parse_color(const char *token, t_scene scene); + +// Parsing utils +inline char **get_tokens_secure(t_scene scene, const int numObject, const int numObjectMax, const int supposed_nb_token); // Check -inline int check_tokens(char **tokens, int expected) -inline void check_if_max(t_scene scene, const int lower_than); +inline int check_tokens(char **tokens, const int to_test, int expected); +inline void check_if_max(t_scene scene, const int to_test, const int max); #endif diff --git a/parsing_ambiant.c b/parsing_ambiant.c index 2d3d5f4..099c0f7 100644 --- a/parsing_ambiant.c +++ b/parsing_ambiant.c @@ -6,7 +6,7 @@ /* By: yantoine +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/14 18:04:39 by yantoine #+# #+# */ -/* Updated: 2025/02/14 18:56:00 by yantoine ### ########.fr */ +/* Updated: 2025/02/14 20:52:08 by yantoine ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,19 +15,10 @@ t_scene parsing_ambiant(const char *line, t_scene scene) { - const int result_if_max = check_if_max(scene, MAX_AMBIENT); - const char **tokens = ft_split(line, ' '); - const int result_check_tokens = check_tokens(tokens, 3); - - if (!result_check_tokens) - { - ft_free_array(tokens); - ft_putendl_fd("error", 2); - close(scene.fd); - exit(1); - } + const char **tokens = get_tokens_secure(scene, scene.numAmbient, MAX_AMBIENT, 3); scene.ambient.ambient_ratio = ft_atof(tokens[1]); scene.ambient.ambient_color = parse_color(tokens[2], scene); ft_free_array(tokens); + scene.numAmbient++; return (scene); } diff --git a/parsing_camera.c b/parsing_camera.c new file mode 100644 index 0000000..54b3967 --- /dev/null +++ b/parsing_camera.c @@ -0,0 +1,17 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* parsing_camera.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/02/14 20:02:29 by yantoine #+# #+# */ +/* Updated: 2025/02/14 20:03:25 by yantoine ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "miniRT.h" + +t_scene parsing_camera(const char *line, t_scene scene) +{ +} diff --git a/parsing_color.c b/parsing_color.c new file mode 100644 index 0000000..74f517c --- /dev/null +++ b/parsing_color.c @@ -0,0 +1,17 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* parsing_color.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/02/14 20:05:49 by yantoine #+# #+# */ +/* Updated: 2025/02/14 20:25:45 by yantoine ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "miniRT.h" + +t_color parse_color(const char *token, t_scene scene) +{ +} diff --git a/parsing_utils.c b/parsing_utils.c new file mode 100644 index 0000000..54bd35e --- /dev/null +++ b/parsing_utils.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* parsing_utils.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: yantoine +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/02/14 20:23:21 by yantoine #+# #+# */ +/* Updated: 2025/02/14 20:48:49 by yantoine ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "miniRT.h" + + +inline char **get_tokens_secure(t_scene scene, const int numObject, const int numObjectMax, const int supposed_nb_token) +{ + 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) + { + ft_free_array(tokens); + ft_putendl_fd("error", 2); + free(scene.line_if_exit); + close(scene.fd); + exit(1); + } + return (tokens); +} diff --git a/tags b/tags index 8647b94..8f9ab37 100644 --- a/tags +++ b/tags @@ -91,7 +91,7 @@ camPos miniRT.h /^ t_vec3 camPos;$/;" m struct:s_camera typeref:typename:t_vec3 camPos raytracer_formatted.c /^t_vec3 camPos = {0.0f, 0.0f, 0.0f};$/;" v typeref:typename:t_vec3 center miniRT.h /^ t_vec3 center;$/;" m struct:s_cylinder typeref:typename:t_vec3 center miniRT.h /^ t_vec3 center;$/;" m struct:s_sphere typeref:typename:t_vec3 -check_if_max check.c /^inline void check_if_max(t_scene scene, const int lower_than)$/;" f typeref:typename:void +check_if_max check.c /^inline void check_if_max(t_scene scene, const int to_test, const int max)$/;" f typeref:typename:void check_tokens check.c /^inline int check_tokens(char **tokens, int expected)$/;" f typeref:typename:int color miniRT.h /^ t_vec3 color;$/;" m struct:s_cylinder typeref:typename:t_vec3 color miniRT.h /^ t_vec3 color;$/;" m struct:s_light typeref:typename:t_vec3 @@ -102,6 +102,7 @@ cylinders miniRT.h /^ t_cylinder cylinders[MAX_CYLINDERS];$/;" m struct:s_scene dir miniRT.h /^ t_vec3 dir;$/;" m struct:s_ray typeref:typename:t_vec3 fov miniRT.h /^ float fov;$/;" m struct:s_camera typeref:typename:float fov raytracer_formatted.c /^float fov = 90.0f;$/;" v typeref:typename:float +get_tokens_secure parsing_utils.c /^inline char **get_tokens_secure(t_scene scene, const int numObject, const int numObjectMax, cons/;" f typeref:typename:char ** height miniRT.h /^ float height;$/;" m struct:s_cylinder typeref:typename:float intersectCylinder raytracer_formatted.c /^float intersectCylinder(Ray ray, Cylinder cy, t_vec3 *hitNormal)$/;" f typeref:typename:float intersectPlane raytracer_formatted.c /^float intersectPlane(Ray ray, Plane p, t_vec3 *hitNormal)$/;" f typeref:typename:float @@ -119,7 +120,9 @@ numLights miniRT.h /^ int numLights;$/;" m struct:s_scene typeref:typename:int numPlanes miniRT.h /^ int numPlanes;$/;" m struct:s_scene typeref:typename:int numSpheres miniRT.h /^ int numSpheres;$/;" m struct:s_scene typeref:typename:int origin miniRT.h /^ t_vec3 origin;$/;" m struct:s_ray typeref:typename:t_vec3 +parse_color parsing_color.c /^t_color parse_color(const char *token, t_scene scene)$/;" f typeref:typename:t_color parsing_ambiant parsing_ambiant.c /^t_scene parsing_ambiant(const char *line, t_scene scene)$/;" f typeref:typename:t_scene +parsing_camera parsing_camera.c /^t_scene parsing_camera(const char *line, t_scene scene)$/;" f typeref:typename:t_scene parsing_line config.c /^static inline t_scene parsing_line(const char *line, t_scene scene)$/;" f typeref:typename:t_scene file: pitch miniRT.h /^ float pitch; \/\/ vue de haut en bas en radians$/;" m struct:s_camera typeref:typename:float pitch raytracer_formatted.c /^float pitch = 0.0f; \/\/ vue de haut en bas en radians$/;" v typeref:typename:float