MAJ parsing_color et config_ambient
This commit is contained in:
@@ -0,0 +1,3 @@
|
|||||||
|
[submodule "libft"]
|
||||||
|
path = libft
|
||||||
|
url = git@github.com:H3XploR/libft.git
|
||||||
Submodule
+1
Submodule libft added at 060e991b6f
@@ -19,6 +19,7 @@
|
|||||||
# include <stdio.h>
|
# include <stdio.h>
|
||||||
# include <stdlib.h>
|
# include <stdlib.h>
|
||||||
# include <string.h>
|
# include <string.h>
|
||||||
|
# include "libft.h"
|
||||||
|
|
||||||
// ----- Taille ecran ----
|
// ----- Taille ecran ----
|
||||||
# define WIDTH 320
|
# define WIDTH 320
|
||||||
@@ -104,7 +105,9 @@ typedef struct s_scene
|
|||||||
int numCylinders;
|
int numCylinders;
|
||||||
int numLights;
|
int numLights;
|
||||||
int numAmbient;
|
int numAmbient;
|
||||||
const char *line;
|
const char *line_if_exit;
|
||||||
|
const int fd_if_exit;
|
||||||
|
const char **token_if_exit;
|
||||||
} t_scene;
|
} t_scene;
|
||||||
|
|
||||||
// Calcul de vecteur
|
// Calcul de vecteur
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
t_scene parsing_ambiant(const char *line, t_scene scene)
|
t_scene parsing_ambiant(const char *line, t_scene scene)
|
||||||
{
|
{
|
||||||
const char **tokens = get_tokens_secure(scene, scene.numAmbient, MAX_AMBIENT, 3);
|
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_ratio = ft_atof(tokens[1]);
|
||||||
scene.ambient.ambient_color = parse_color(tokens[2], scene);
|
scene.ambient.ambient_color = parse_color(tokens[2], scene);
|
||||||
ft_free_array(tokens);
|
ft_free_array(tokens);
|
||||||
|
|||||||
@@ -14,4 +14,19 @@
|
|||||||
|
|
||||||
t_color parse_color(const char *token, t_scene scene)
|
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;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-2
@@ -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 int result_if_max = check_if_max(scene, numObject, numObjectMax);
|
||||||
const char **tokens = ft_split(scene.line_if_exit, ' ');
|
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_free_array(tokens);
|
||||||
ft_putendl_fd("error", 2);
|
ft_putendl_fd("error", 2);
|
||||||
|
|||||||
Reference in New Issue
Block a user