From 18ac9ca03c82e045f8653f13e92a201e1e605f43 Mon Sep 17 00:00:00 2001 From: nicolas-arnaud Date: Sun, 20 Nov 2022 19:27:21 +0100 Subject: [PATCH] exit when X ask to close window --- Makefile | 4 ++++ includes/cub3d.h | 1 + src/mlx/mlx_1.c | 1 + src/mlx/mlx_2.c | 8 +++++++- 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 5080206..7996651 100644 --- a/Makefile +++ b/Makefile @@ -29,13 +29,16 @@ all: $(NAME) $(VERBOSE).SILENT: $(LIBFT): + echo "Downloading narnaud/libft and making library" bash -c "if [[ ! -d "libft" ]]; then git clone \ https://git.narnaud.net/nicolas-arnaud/Libft.git libft; fi" ${MAKE} -C libft/ cp libft/libft.a lib/ cp libft/libft.h includes/ + echo ✅ $(MLX): + echo "Downloading 42Paris/minilibx and making library" bash -c "if [[ ! -d "mlx" ]]; then git clone \ https://github.com/42Paris/minilibx-linux.git mlx; fi" ${MAKE} -C mlx/ @@ -46,6 +49,7 @@ ifeq ($(UNAME_S), Darwin) cp mlx/libmlx.a lib/ endif cp mlx/mlx.h includes/ + echo ✅ $(NAME): $(LIBFT) $(MLX) $(OBJS) echo Making Cub3D... diff --git a/includes/cub3d.h b/includes/cub3d.h index faf545e..1a816a2 100644 --- a/includes/cub3d.h +++ b/includes/cub3d.h @@ -114,6 +114,7 @@ int mouse_move_hook(int x, int y, t_env *env); int mouse_up_hook(int buton, int x, int y, t_env *env); int update_hook(t_env *env); void init_window(t_env *nv); +int exit_game(t_env *env); int init_game(t_env *env); // Utils diff --git a/src/mlx/mlx_1.c b/src/mlx/mlx_1.c index 0da814e..fc6987c 100644 --- a/src/mlx/mlx_1.c +++ b/src/mlx/mlx_1.c @@ -92,5 +92,6 @@ int init_game(t_env *env) mlx_hook(env->win, 2, 1L << 0, key_press_hook, env); mlx_hook(env->win, 3, 1L << 1, key_release_hook, env); mlx_hook(env->win, 6, 0L, mouse_move_hook, env); + mlx_hook(env->win, 17, 0L, exit_game, env); return (EXIT_SUCCESS); } diff --git a/src/mlx/mlx_2.c b/src/mlx/mlx_2.c index 3b6c92c..fcb988c 100644 --- a/src/mlx/mlx_2.c +++ b/src/mlx/mlx_2.c @@ -12,12 +12,18 @@ #include "../../includes/cub3d.h" +int exit_game(t_env *env) +{ + (void)env; + exit(EXIT_SUCCESS); +} + int key_press_hook(int keycode, t_env *env) { if (keycode == KEY_M) env->minimap = !env->minimap; else if (keycode == KEY_ECHAP) - exit(EXIT_SUCCESS); + exit_game(env); else env->controls[keycode] = 1; return (1);