-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.c
47 lines (43 loc) · 1.83 KB
/
main.c
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ncolomer <ncolomer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/29 12:45:06 by ncolomer #+# #+# */
/* Updated: 2019/11/09 17:37:35 by ncolomer ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include "cub3d.h"
int
exit_error(t_game *game, char const *str)
{
if (str)
write(STDOUT_FILENO, str, ft_strlen(str));
exit_game(game, EXIT_FAILURE);
return (EXIT_FAILURE);
}
int
main(int argc, char **argv)
{
t_game game;
int save_opt;
save_opt = (argc >= 2 && !ft_strcmp(argv[1], "-save"));
if (argc < (2 + save_opt))
return (exit_error(&game, "Error:\nno map specified.\n"));
init_game(&game, save_opt);
if (!parse_config(&game.config, argv[1 + save_opt]))
return (exit_error(&game, "Error:\ninvalid map.\n"));
if (!finish_init(&game))
return (EXIT_FAILURE);
if (game.options & FLAG_SAVE)
return (screenshot(&game));
mlx_hook(game.window.win, X_EVENT_KEY_PRESS, 0, &key_press, &game);
mlx_hook(game.window.win, X_EVENT_KEY_RELEASE, 0, &key_release, &game);
mlx_hook(game.window.win, X_EVENT_EXIT, 0, &exit_hook, &game);
mlx_loop_hook(game.window.ptr, &main_loop, &game);
mlx_loop(game.window.ptr);
return (EXIT_SUCCESS);
}