Exemple #1
0
int				main(int argc, char **argv)
{
	int				i;
	t_main			main;

	ft_logf_set_enabled(LOG_DEBUG, true);
	ft_logf_set_enabled(LOG_VERBOSE, true);
	main = (t_main){
		NULL,
		NULL,
		{},
		VECTOR(t_scene),
		-1,
		-1,
		false,
	};
	if ((main.thread_pool = ft_thread_pool_create(THREAD_COUNT)) == NULL)
		return (ft_dprintf(2, "Failed to create threads"), 1);
	if ((main.mlx = mlx_init()) == NULL || !ft_mlx_open(&main.win, main.mlx,
			VEC2U(WIN_WIDTH, WIN_HEIGHT), SUBC(WIN_TITLE)))
		return (1);

	i = 0;
	while (++i < argc)
	{
		ft_logf(LOG_VERBOSE, "Loading scene file: %s", argv[i]);
		if (!load_scenes(argv[i], &main.scenes))
			return (1);
	}

	if (main.scenes.length == 0)
	{
		ft_logf(LOG_ERROR, "No scene loaded");
		return (1);
	}
	ft_logf(LOG_SUCCESS, "%d scene(s) loaded", main.scenes.length);

	mlx_loop_hook(main.mlx, &loop_hook, &main);
	mlx_key_hook(main.win.win_id, &key_hook, &main);
	mlx_expose_hook(main.win.win_id, &expose_hook, &main);

	render(&main, 0, 0);

	mlx_loop(main.mlx);

	ASSERT(false);
	main_destroy(&main);
	return (0);
}
Exemple #2
0
static int		key_hook(int keycode, t_main *main)
{
	if (keycode == KEYCODE_ESC || keycode == KEYCODE_Q)
		main_destroy(main);
	else if (keycode == KEYCODE_LEFT && main->scenes.length > 1)
		render(main, main->current_scene - 1, 0);
	else if (keycode == KEYCODE_RIGHT && main->scenes.length > 1)
		render(main, main->current_scene + 1, 0);
	else if (keycode == KEYCODE_UP
		&& VGETC(t_scene, main->scenes, main->current_scene).cameras.length > 1)
		render(main, main->current_scene, main->current_camera + 1);
	else if (keycode == KEYCODE_DOWN
		&& VGETC(t_scene, main->scenes, main->current_scene).cameras.length > 1)
		render(main, main->current_scene, main->current_camera - 1);
	else if (keycode == KEYCODE_R)
		render(main, main->current_scene, main->current_camera);
	return (0);
}
Exemple #3
0
int __attribute__((destructor)) sock_redirect_lib_load_destructor(void)
{
        return main_destroy();
}