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-19 07:41:58 -05:00
|
|
|
/* Updated: 2023/01/18 17:31:16 by cchauvet ### ########.fr */
|
2022-12-22 11:41:31 -05:00
|
|
|
/* */
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
|
|
|
#include "solong.h"
|
2023-01-05 13:04:29 -05:00
|
|
|
|
2023-01-11 13:10:28 -05:00
|
|
|
int ft_initialised(char *path, t_data *data)
|
2022-12-22 11:41:31 -05:00
|
|
|
{
|
2023-01-08 12:03:40 -05:00
|
|
|
t_map *map;
|
2022-12-22 11:41:31 -05:00
|
|
|
|
2023-01-08 12:03:40 -05:00
|
|
|
map = ft_getmap(path);
|
|
|
|
if (map == NULL)
|
|
|
|
{
|
|
|
|
ft_printf("Map error\n");
|
2023-01-10 13:04:46 -05:00
|
|
|
exit(1);
|
2023-01-08 12:03:40 -05:00
|
|
|
}
|
2023-01-13 09:10:27 -05:00
|
|
|
data->mlx = mlx_init();
|
|
|
|
ft_printf("Generating assets ...");
|
2023-01-16 12:38:47 -05:00
|
|
|
if (ft_gen_assets(data) == 1)
|
|
|
|
{
|
|
|
|
ft_printf("\rGenerating assets [ERROR]");
|
|
|
|
ft_exit(data);
|
|
|
|
}
|
2023-01-13 09:10:27 -05:00
|
|
|
ft_printf("\rGenerating assets [FINISHED]\n");
|
2023-01-09 14:41:06 -05:00
|
|
|
data->map = map;
|
2023-01-19 07:41:58 -05:00
|
|
|
data->window = mlx_new_window(data->mlx,
|
|
|
|
(RENDER_DISTANCE * 2 + 1) * CASE_SIZE,
|
|
|
|
(RENDER_DISTANCE * 2 + 1) * CASE_SIZE, "long");
|
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);
|
2023-01-11 13:10:28 -05:00
|
|
|
mlx_hook(data->window, 2, (1L << 0), 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)
|
|
|
|
{
|
2023-01-11 13:10:28 -05:00
|
|
|
size_t i;
|
2023-01-10 13:04:46 -05:00
|
|
|
|
2023-01-11 13:10:28 -05:00
|
|
|
i = 0;
|
2023-01-16 12:38:47 -05:00
|
|
|
while (i < NB_COLORS + 1)
|
2023-01-11 13:10:28 -05:00
|
|
|
{
|
|
|
|
if (data->assets[i] != NULL)
|
|
|
|
mlx_destroy_image(data->mlx, data->assets[i]);
|
|
|
|
i++;
|
|
|
|
}
|
2023-01-13 09:10:27 -05:00
|
|
|
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);
|
2023-01-10 13:04:46 -05:00
|
|
|
exit(0);
|
2023-01-08 12:03:40 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int ac, char **av)
|
|
|
|
{
|
2023-01-11 13:10:28 -05:00
|
|
|
t_data data;
|
|
|
|
|
2023-01-13 10:10:11 -05:00
|
|
|
if (ac != 2 || ft_strcmp(av[1] + ft_strlen(av[1]) - 4, ".ber"))
|
2023-01-08 12:03:40 -05:00
|
|
|
{
|
|
|
|
ft_printf("Map error\n");
|
|
|
|
return (1);
|
|
|
|
}
|
2023-01-13 09:10:27 -05:00
|
|
|
data.map = NULL;
|
|
|
|
data.window = NULL;
|
2023-01-11 13:10:28 -05:00
|
|
|
if (ft_initialised(av[1], &data))
|
2023-01-10 13:04:46 -05:00
|
|
|
ft_printf("Memory error");
|
2023-01-05 13:04:29 -05:00
|
|
|
return (1);
|
2022-12-22 11:41:31 -05:00
|
|
|
}
|