42_solong/main.c

72 lines
1.9 KiB
C
Raw Normal View History

2022-12-22 11:41:31 -05:00
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/12 17:20:17 by cchauvet #+# #+# */
2023-01-10 13:04:46 -05:00
/* Updated: 2023/01/10 18:33:10 by cchauvet ### ########.fr */
2022-12-22 11:41:31 -05:00
/* */
/* ************************************************************************** */
#include "solong.h"
2023-01-05 13:04:29 -05:00
int ft_initialised(char *path)
2022-12-22 11:41:31 -05:00
{
2023-01-09 14:41:06 -05:00
t_data *data;
t_map *map;
2022-12-22 11:41:31 -05:00
2023-01-09 14:41:06 -05:00
data = ft_calloc(1, sizeof(t_data));
if (data == NULL)
2023-01-10 13:04:46 -05:00
{
ft_printf("Memory error");
2023-01-09 14:41:06 -05:00
return (1);
2023-01-10 13:04:46 -05:00
}
map = ft_getmap(path);
if (map == NULL)
{
2023-01-10 13:04:46 -05:00
free(data);
ft_printf("Map error\n");
2023-01-10 13:04:46 -05:00
exit(1);
}
2023-01-09 14:41:06 -05:00
data->map = map;
data->mlx = mlx_init();
2023-01-10 13:04:46 -05:00
data->window = mlx_new_window(data->mlx, WINDOW_SIZE, WINDOW_SIZE, "");
2023-01-09 14:41:06 -05:00
ft_draw_map(data);
2023-01-10 13:04:46 -05:00
mlx_hook(data->window, 17, (0L), ft_exit, data);
mlx_hook(data->window, 3, (1L << 1), ft_key, data);
2023-01-09 14:41:06 -05:00
mlx_loop(data->mlx);
2023-01-10 13:04:46 -05:00
return (0);
}
int ft_exit(t_data *data)
{
t_map *map;
map = data->map;
2023-01-09 14:41:06 -05:00
ft_freer_tab_ultimate(1, map->patern);
mlx_destroy_window(data->mlx, data->window);
mlx_destroy_display(data->mlx);
free(data->mlx);
free(data);
free(map);
2023-01-10 13:04:46 -05:00
exit(0);
return (0);
}
int main(int ac, char **av)
{
if (ac != 2)
{
ft_printf("Map error\n");
return (1);
}
ft_printf("Generating assets ...\n");
ft_gen_assets();
ft_printf("Generating assets [FINISHED]\n");
2023-01-10 13:04:46 -05:00
if (ft_initialised(av[1]))
ft_printf("Memory error");
2023-01-05 13:04:29 -05:00
return (1);
2022-12-22 11:41:31 -05:00
}