diff --git a/includes/fdf.h b/includes/fdf.h index e37abee..a310172 100644 --- a/includes/fdf.h +++ b/includes/fdf.h @@ -3,12 +3,10 @@ # include "../libft/includes/libft.h" # include -# include // for sleep() # include // for M_PI -# include // for printf() # include // for open -typedef struct s_fdf +typedef struct s_fdf { void *mlx_ptr; void *win_ptr; @@ -40,22 +38,35 @@ typedef struct s_fdf int img_endian; } t_fdf; +// fdf.c +int main(int ac, char **av); void init_fdf(t_fdf *fdf); void init_offset(t_fdf *fdf); void init_server(t_fdf *fdf); -int print_keycode(int keycode); int shut_down(t_fdf *fdf); + +// draw.c void draw_image(t_fdf *fdf); -void draw_pixel(t_fdf *fdf, int x, int y, int color); -void draw_color_pixel(t_fdf *fdf, int new_x, int new_y, int z); -int keypress(int keycode, t_fdf *fdf); -void keypress_more(int keycode, t_fdf *fdf); -void position_state(t_fdf *fdf); -int is_color(char *color); -int **parse_map(t_fdf *fdf, int fd); -int *new_coordinates(t_fdf *fdf, int i, int j); -void draw_lines(t_fdf *fdf, int *start, int *end); void draw_grid(t_fdf *fdf, int i, int j); +void draw_lines(t_fdf *fdf, int *start, int *end); +void draw_color_pixel(t_fdf *fdf, int new_x, int new_y, int z); +void draw_pixel(t_fdf *fdf, int x, int y, int color); + +// keypress.c +void keypress_more(int keycode, t_fdf *fdf); +int keypress(int keycode, t_fdf *fdf); + +// modifs.c +int *new_coordinates(t_fdf *fdf, int i, int j); +void position_state(t_fdf *fdf); +int print_keycode(int keycode); + +// parse.c +void z_amplitude(t_fdf*fdf, int i); +int **split_to_map(t_fdf *fdf, char *raw); +int is_color(char *color); +void size_map(t_fdf *fdf, char *raw, int height); +int **parse_map(t_fdf *fdf, int fd); # define ESCAPE 65307 # define UP 65362 diff --git a/srcs/fdf.c b/srcs/fdf.c index 26a7bd8..c44283d 100644 --- a/srcs/fdf.c +++ b/srcs/fdf.c @@ -42,7 +42,7 @@ void init_server(t_fdf *fdf) void init_offset(t_fdf *fdf) { int diagonal; - int x; + int x; x = (fdf->map_width) * (fdf->map_width); x += (fdf->map_height) * (fdf->map_height); @@ -77,7 +77,7 @@ void init_fdf(t_fdf *fdf) draw_image(fdf); } -int main(int ac, char **av) +int main(int ac, char **av) { t_fdf *fdf; int fd; diff --git a/srcs/keypress.c b/srcs/keypress.c index 6f1af88..311a04b 100644 --- a/srcs/keypress.c +++ b/srcs/keypress.c @@ -69,4 +69,3 @@ int keypress(int keycode, t_fdf *fdf) draw_image(fdf); return (0); } - diff --git a/srcs/modifs.c b/srcs/modifs.c index 427a295..74031cc 100644 --- a/srcs/modifs.c +++ b/srcs/modifs.c @@ -73,4 +73,4 @@ void position_state(t_fdf *fdf) ** ft_putchar(' '); ** return (0); ** } -*/ +*/ diff --git a/srcs/parse.c b/srcs/parse.c index c31e9de..0306520 100644 --- a/srcs/parse.c +++ b/srcs/parse.c @@ -14,8 +14,6 @@ int **split_to_map(t_fdf *fdf, char *raw) int j; int **map; - if (fdf->map_height == 0) - shut_down(fdf); map = ft_calloc(fdf->map_height, sizeof(map)); if (!map) shut_down(fdf); @@ -50,11 +48,13 @@ int is_color(char *color) return (i); } -int size_width(char *raw) +void size_map(t_fdf *fdf, char *raw, int height) { int i; int j; + if (height == 0) + shut_down(fdf); i = 0; while (raw[i] && raw[i] != '!') { @@ -67,7 +67,10 @@ int size_width(char *raw) i += is_color(raw + i); j++; } - return (j); + fdf->map_width = j; + fdf->map_height = height; + fdf->min_z = 0; + fdf->max_z = 0; } int **parse_map(t_fdf *fdf, int fd) @@ -76,6 +79,7 @@ int **parse_map(t_fdf *fdf, int fd) int ret; char *line; char *raw; + int **map; height = 0; ret = 1; @@ -91,9 +95,9 @@ int **parse_map(t_fdf *fdf, int fd) raw = ft_strjoinfree(raw, ft_strdup("!")); } } - fdf->map_height = height; - fdf->map_width = size_width(raw); - fdf->min_z = 0; - fdf->max_z = 0; - return (split_to_map(fdf, raw)); + size_map(fdf, raw, height); + map = split_to_map(fdf, raw); + free(line); + free(raw); + return (map); }