aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.c
blob: b1437ccf2e38728324e8e6b1f9c9e51d8babe8c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* ************************************************************************** */
/*                                                          LE - /            */
/*                                                              /             */
/*   main.c                                           .::    .:/ .      .::   */
/*                                                 +:+:+   +:    +:  +:+:+    */
/*   By: rbousset <marvin@le-101.fr>                +:+   +:    +:    +:+     */
/*                                                 #+#   #+    #+    #+#      */
/*   Created: 2020/02/02 17:19:34 by rbousset     #+#   ##    ##    #+#       */
/*   Updated: 2020/02/02 17:19:34 by rbousset    ###    #+. /#+    ###.fr     */
/*                                                         /                  */
/*                                                        /                   */
/* ************************************************************************** */

#include <libft.h>
#include <mlx.h>
#include <cub3d.h>
#include <unistd.h>

int
	main(int argc, const char *argv[])
{
	t_cub	*clist;

	if (argc < 2)
	{
		ft_dprintf(STDERR_FILENO, "Error\n\033[1;31mNo map selected\n\033[0m");
		return (1);
	}
	if (!(clist = ft_init_cub()))
	{
		ft_memdel((void**)&clist);
		return (2);
	}
	if (!(clist->wlist = ft_init_win()))
	{
		ft_memdel((void**)&clist->wlist);
		ft_memdel((void**)&clist);
		return (2);
	}
	ft_parse_map(argv[1], clist);
	if (ft_init_winlx(clist) < 0)
		return (ft_exit(3, clist));
	mlx_hook(clist->wlist->winptr, 2, 1L << 1, ft_key_event, clist);
	mlx_hook(clist->wlist->winptr, 17, 1L << 3, ft_click_close, clist);
	ft_drawmap(clist);
	mlx_loop(clist->wlist->wlx);
	return (0);
}