-
Notifications
You must be signed in to change notification settings - Fork 0
/
minirt.c
80 lines (75 loc) · 2.37 KB
/
minirt.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* minirt.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: zkerriga <zkerriga@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/06/17 16:36:27 by zkerriga #+# #+# */
/* Updated: 2020/06/17 16:38:17 by zkerriga ### ########.fr */
/* */
/* ************************************************************************** */
#include "minirt.h"
#include "render.h"
#include "parser.h"
#include "events.h"
void argparse(t_args *args, int ac, char **av)
{
args->path = NULL;
args->save = FALSE;
args->help = FALSE;
if (ac == 1)
args->help = TRUE;
else
{
while (--ac > 0)
{
if (ft_memcmp(av[ac], "--help", 7) == 0
|| ft_memcmp(av[ac], "-h", 3) == 0)
args->help = TRUE;
else if (ft_memcmp(av[ac], "--save", 7) == 0
|| ft_memcmp(av[ac], "-s", 3) == 0)
args->save = TRUE;
else if (args->path == NULL)
args->path = av[ac];
else
args->help = TRUE;
}
}
if (args->path == NULL)
args->help = TRUE;
}
void start_scene_with_hook(t_scene *scene)
{
scene->dmlx->set_win(scene->dmlx, scene->resolution->x_size,
scene->resolution->y_size);
render(scene, scene->dmlx->addr, scene->resolution->x_size,
scene->resolution->y_size);
scene->dmlx->put_win(scene->dmlx);
mlx_hook(scene->dmlx->win, 2, 1L << 0, key_handler, scene);
mlx_hook(scene->dmlx->win, 17, 1L << 17, close_handler, scene);
mlx_loop(scene->dmlx->mlx);
}
int main(int ac, char **av)
{
t_scene *scene;
t_args args;
argparse(&args, ac, av);
if (args.help)
show_help();
else
{
scene = parser(av[1], NULL);
scene->act_cam = scene->get_cam(scene, NONE);
if (args.save)
{
render(scene, scene->dmlx->addr, scene->resolution->x_size,
scene->resolution->y_size);
scene->dmlx->put_bmp(scene->dmlx, scene->resolution->x_size,
scene->resolution->y_size);
}
else
start_scene_with_hook(scene);
}
return (0);
}