/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* main.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: cchauvet mlx = mlx_init(); ft_printf("Generating assets ..."); if (ft_gen_assets(data) == 1) { ft_printf("\rGenerating assets [ERROR]"); ft_exit(data); } ft_printf("\rGenerating assets [FINISHED]\n"); data->map = map; data->window = mlx_new_window(data->mlx, (RENDER_DISTANCE * 2 + 1) * CASE_SIZE, (RENDER_DISTANCE * 2 + 1) * CASE_SIZE, "long"); ft_draw_map(data); mlx_hook(data->window, 17, (0L), ft_exit, data); mlx_hook(data->window, 2, (1L << 0), ft_key, data); mlx_loop(data->mlx); return (0); } int ft_exit(t_data *data) { size_t i; i = 0; while (i < NB_COLORS + 1) { if (data->assets[i] != NULL) mlx_destroy_image(data->mlx, data->assets[i]); i++; } if (data->map != NULL && data->map->patern != NULL) ft_freer_tab_ultimate(1, data->map->patern); if (data->window != NULL && data->mlx != NULL) mlx_destroy_window(data->mlx, data->window); if (data->mlx != NULL) mlx_destroy_display(data->mlx); if (data->mlx != NULL) free(data->mlx); if (data->map != NULL) free(data->map); exit(0); } int main(int ac, char **av) { t_data data; if (ac != 2 || ft_strcmp(av[1] + ft_strlen(av[1]) - 4, ".ber")) { ft_printf("Map error\n"); return (1); } data.map = NULL; data.window = NULL; if (ft_initialised(av[1], &data)) ft_printf("Memory error"); return (1); }