diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-01-10 11:44:44 +0100 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-01-10 17:53:02 +0100 |
| commit | 988e058680280e25d345b17d840c3c6d40e30a76 (patch) | |
| tree | 0cdb0fe6bbf2b3a55edb5347d35aadf6576876c1 /main.c | |
| parent | 2875f205e24f19964d44ddce2470659d21fe902d (diff) | |
| download | cub3d-988e058680280e25d345b17d840c3c6d40e30a76.tar.gz cub3d-988e058680280e25d345b17d840c3c6d40e30a76.tar.bz2 cub3d-988e058680280e25d345b17d840c3c6d40e30a76.zip | |
refactoring
Diffstat (limited to 'main.c')
| -rw-r--r-- | main.c | 83 |
1 files changed, 51 insertions, 32 deletions
@@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/11/15 06:39:39 by cacharle #+# #+# */ -/* Updated: 2019/11/19 17:09:53 by cacharle ### ########.fr */ +/* Updated: 2020/01/10 10:59:09 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,24 +14,61 @@ int main(int argc, char **argv) { - if (argc != 2) + t_parsing *p; + void *mlx_ptr; + void *window_ptr; + t_state *state; + + if (argc == 3 && ft_strcmp(argv[2], "--save") == 0) + return (save_image()); + else if (argc != 2) + error_put_usage_exit(argv[0]); + if ((p = parse(argv[1])) == NULL) + { + ft_putendl_fd("Error: wrong file format", STDERR_FILENO); + return (1); + } + + if ((mlx_ptr = mlx_init()) == NULL) + { + ft_putendl_fd("Error: minilibx init", STDERR_FILENO); + return (1); + } + if ((window_ptr = mlx_new_window(mlx_ptr, p->resolution_width, + p->resolution_height, WINDOW_TITLE)) == NULL) { - ft_putendl("Error"); + ft_putendl_fd("Error: minilibx window creation", STDERR_FILENO); return (1); } + if ((state = state_new(mlx_ptr, window_ptr, p)) == NULL) + { + ft_putendl_fd("Error: state creation", STDERR_FILENO); + return (1); + } + + mlx_hook(window_ptr, 2, (1L<<1), handle_keydown, (void*)state); + mlx_loop_hook(mlx_ptr, graphics_update, (void*)state); + mlx_loop(mlx_ptr); + + return (0); +} + +/* +int main(int argc, char argv) +{ t_parsing *p = parse(argv[1]); if (p == NULL) return (1); - /* printf("R %d %d\n", p->resolution_width, p->resolution_height); */ - /* printf("NO %s\n", p->north_texture_path); */ - /* printf("SO %s\n", p->south_texture_path); */ - /* printf("WE %s\n", p->west_texture_path); */ - /* printf("EA %s\n\n", p->east_texture_path); */ - /* printf("S %s\n", p->sprite_texture_path); */ - /* printf("F %d,%d,%d\n", p->floor_color.r, p->floor_color.g, p->floor_color.b); */ - /* printf("C %d,%d,%d\n\n", p->ceilling_color.r, p->ceilling_color.g, p->ceilling_color.b); */ + printf("R %d %d\n", p->resolution_width, p->resolution_height); + printf("NO %s\n", p->north_texture_path); + printf("SO %s\n", p->south_texture_path); + printf("WE %s\n", p->west_texture_path); + printf("EA %s\n\n", p->east_texture_path); + printf("S %s\n", p->sprite_texture_path); + printf("F %d,%d,%d\n", p->floor_color.r, p->floor_color.g, p->floor_color.b); + printf("C %d,%d,%d\n\n", p->ceilling_color.r, p->ceilling_color.g, p->ceilling_color.b); - /* printf("%dx%d\n", p->map_height, p->map_width); */ + printf("%dx%d\n", p->map_height, p->map_width); for (int i = 0; i < p->map_height; i++) { for (int j = 0; j < p->map_width; j++) @@ -47,24 +84,6 @@ int main(int argc, char **argv) } printf("\n"); } - - void *mlx_ptr = mlx_init(); - if (mlx_ptr == NULL) - return (1); - void *window_ptr = mlx_new_window(mlx_ptr, p->resolution_width, p->resolution_height, WINDOW_TITLE); - if (window_ptr == NULL) - return (1); - - t_state *state = create_state(mlx_ptr, window_ptr, p); - if (state == NULL) - return (1); - - /* for (int i = 0; i < 20; i++) */ - /* draw_column(state, i); */ - - mlx_key_hook(window_ptr, handle_key, (void*)state); - mlx_loop_hook(mlx_ptr, graphics_update, (void*)state); - mlx_loop(mlx_ptr); - - return (0); + return 0; } +*/ |
