a la norme et sans leaks

This commit is contained in:
hugogogo
2021-07-25 14:56:05 +02:00
parent e4b4f5e751
commit 463ce19ce3
5 changed files with 40 additions and 26 deletions

View File

@@ -3,12 +3,10 @@
# include "../libft/includes/libft.h" # include "../libft/includes/libft.h"
# include <mlx.h> # include <mlx.h>
# include <unistd.h> // for sleep()
# include <math.h> // for M_PI # include <math.h> // for M_PI
# include <stdio.h> // for printf()
# include <fcntl.h> // for open # include <fcntl.h> // for open
typedef struct s_fdf typedef struct s_fdf
{ {
void *mlx_ptr; void *mlx_ptr;
void *win_ptr; void *win_ptr;
@@ -40,22 +38,35 @@ typedef struct s_fdf
int img_endian; int img_endian;
} t_fdf; } t_fdf;
// fdf.c
int main(int ac, char **av);
void init_fdf(t_fdf *fdf); void init_fdf(t_fdf *fdf);
void init_offset(t_fdf *fdf); void init_offset(t_fdf *fdf);
void init_server(t_fdf *fdf); void init_server(t_fdf *fdf);
int print_keycode(int keycode);
int shut_down(t_fdf *fdf); int shut_down(t_fdf *fdf);
// draw.c
void draw_image(t_fdf *fdf); 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_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 ESCAPE 65307
# define UP 65362 # define UP 65362

View File

@@ -42,7 +42,7 @@ void init_server(t_fdf *fdf)
void init_offset(t_fdf *fdf) void init_offset(t_fdf *fdf)
{ {
int diagonal; int diagonal;
int x; int x;
x = (fdf->map_width) * (fdf->map_width); x = (fdf->map_width) * (fdf->map_width);
x += (fdf->map_height) * (fdf->map_height); x += (fdf->map_height) * (fdf->map_height);
@@ -77,7 +77,7 @@ void init_fdf(t_fdf *fdf)
draw_image(fdf); draw_image(fdf);
} }
int main(int ac, char **av) int main(int ac, char **av)
{ {
t_fdf *fdf; t_fdf *fdf;
int fd; int fd;

View File

@@ -69,4 +69,3 @@ int keypress(int keycode, t_fdf *fdf)
draw_image(fdf); draw_image(fdf);
return (0); return (0);
} }

View File

@@ -73,4 +73,4 @@ void position_state(t_fdf *fdf)
** ft_putchar(' '); ** ft_putchar(' ');
** return (0); ** return (0);
** } ** }
*/ */

View File

@@ -14,8 +14,6 @@ int **split_to_map(t_fdf *fdf, char *raw)
int j; int j;
int **map; int **map;
if (fdf->map_height == 0)
shut_down(fdf);
map = ft_calloc(fdf->map_height, sizeof(map)); map = ft_calloc(fdf->map_height, sizeof(map));
if (!map) if (!map)
shut_down(fdf); shut_down(fdf);
@@ -50,11 +48,13 @@ int is_color(char *color)
return (i); return (i);
} }
int size_width(char *raw) void size_map(t_fdf *fdf, char *raw, int height)
{ {
int i; int i;
int j; int j;
if (height == 0)
shut_down(fdf);
i = 0; i = 0;
while (raw[i] && raw[i] != '!') while (raw[i] && raw[i] != '!')
{ {
@@ -67,7 +67,10 @@ int size_width(char *raw)
i += is_color(raw + i); i += is_color(raw + i);
j++; 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) int **parse_map(t_fdf *fdf, int fd)
@@ -76,6 +79,7 @@ int **parse_map(t_fdf *fdf, int fd)
int ret; int ret;
char *line; char *line;
char *raw; char *raw;
int **map;
height = 0; height = 0;
ret = 1; ret = 1;
@@ -91,9 +95,9 @@ int **parse_map(t_fdf *fdf, int fd)
raw = ft_strjoinfree(raw, ft_strdup("!")); raw = ft_strjoinfree(raw, ft_strdup("!"));
} }
} }
fdf->map_height = height; size_map(fdf, raw, height);
fdf->map_width = size_width(raw); map = split_to_map(fdf, raw);
fdf->min_z = 0; free(line);
fdf->max_z = 0; free(raw);
return (split_to_map(fdf, raw)); return (map);
} }