aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRudy Bousset <rbousset@z2r4p3.le-101.fr>2020-02-17 19:14:45 +0100
committerRudy Bousset <rbousset@z2r4p3.le-101.fr>2020-02-17 19:14:45 +0100
commit3843a3acf8553e3a01f3c2b80410ccf69142e23f (patch)
tree3afd9f0e92cfc1f18aa43389a56d39e20091e526
parentMakefile update (diff)
download42-cub3d-3843a3acf8553e3a01f3c2b80410ccf69142e23f.tar.gz
42-cub3d-3843a3acf8553e3a01f3c2b80410ccf69142e23f.tar.bz2
42-cub3d-3843a3acf8553e3a01f3c2b80410ccf69142e23f.tar.xz
42-cub3d-3843a3acf8553e3a01f3c2b80410ccf69142e23f.tar.zst
42-cub3d-3843a3acf8553e3a01f3c2b80410ccf69142e23f.zip
Multi-key in progress
-rw-r--r--Makefile2
-rw-r--r--inc/cub3d.h2
-rw-r--r--inc/cub3d_structs.h1
-rw-r--r--map/map_one.cub2
-rw-r--r--src/ft_convert_keycode.c36
-rw-r--r--src/ft_draw_scene.c2
-rw-r--r--src/ft_hooks_and_loops.c1
-rw-r--r--src/ft_init_lists.c7
-rw-r--r--src/ft_key_events.c35
-rw-r--r--src/ft_key_release.c43
10 files changed, 110 insertions, 21 deletions
diff --git a/Makefile b/Makefile
index 9664724..13238d9 100644
--- a/Makefile
+++ b/Makefile
@@ -54,6 +54,8 @@ SRCS_NAME += ft_tex_init.c
SRCS_NAME += ft_detect.c
SRCS_NAME += ft_check_ext.c
SRCS_NAME += ft_draw_textures.c
+SRCS_NAME += ft_key_release.c
+SRCS_NAME += ft_convert_keycode.c
#--------------------------------------------------------------------------------------------------#
SRCS = $(addprefix ${SRCS_DIR},${SRCS_NAME})
#--------------------------------------------------------------------------------------------------#
diff --git a/inc/cub3d.h b/inc/cub3d.h
index a691023..eacb997 100644
--- a/inc/cub3d.h
+++ b/inc/cub3d.h
@@ -74,6 +74,8 @@ int ft_d_key(t_cub *clist);
int ft_f1_key(t_cub *clist);
int ft_left_key(t_cub *clist);
int ft_right_key(t_cub *clist);
+int ft_key_release(int keycode, t_cub *clist);
int8_t ft_check_ext(const char *filep, const char *ext);
+int32_t ft_convert_keycode(const int32_t tmp_code);
# endif
diff --git a/inc/cub3d_structs.h b/inc/cub3d_structs.h
index 38472a6..83b38a7 100644
--- a/inc/cub3d_structs.h
+++ b/inc/cub3d_structs.h
@@ -111,6 +111,7 @@ typedef struct s_cub
uint8_t w_side;
uint8_t minimap;
char errmsg[40];
+ int32_t key_input[5];
struct s_win *wlist;
struct s_player *plist;
struct s_map *mlist;
diff --git a/map/map_one.cub b/map/map_one.cub
index 80bb599..7cb6311 100644
--- a/map/map_one.cub
+++ b/map/map_one.cub
@@ -1,4 +1,4 @@
-R 1800 1100
+R 1600 900
NO ./map/img/crapaud.xpm
SO ./map/img/linus.xpm
diff --git a/src/ft_convert_keycode.c b/src/ft_convert_keycode.c
new file mode 100644
index 0000000..c676920
--- /dev/null
+++ b/src/ft_convert_keycode.c
@@ -0,0 +1,36 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_convert_keycode.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/17 19:00:20 by rbousset #+# #+# */
+/* Updated: 2020/02/17 19:00:21 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <cub3d.h>
+#include <stdint.h>
+
+int32_t
+ ft_convert_keycode(const int32_t tmp_code)
+{
+ uint16_t keycode;
+
+ keycode = UINT16_MAX;
+ (tmp_code == FT_W_KEY) ? (keycode = 0) : 0;
+ (tmp_code == FT_A_KEY) ? (keycode = 1) : 0;
+ (tmp_code == FT_S_KEY) ? (keycode = 2) : 0;
+ (tmp_code == FT_D_KEY) ? (keycode = 3) : 0;
+ (tmp_code == FT_L_ARR_KEY) ? (keycode = 4) : 0;
+ (tmp_code == FT_R_ARR_KEY) ? (keycode = 5) : 0;
+ (tmp_code == 3) ? (keycode = UINT16_MAX) : 0;
+ (tmp_code == 4) ? (keycode = UINT16_MAX) : 0;
+ (tmp_code == 5) ? (keycode = UINT16_MAX) : 0;
+ (tmp_code == FT_ESC_KEY) ? (keycode = FT_ESC_KEY) : 0;
+ (tmp_code == FT_F1_KEY) ? (keycode = FT_F1_KEY) : 0;
+ (tmp_code == FT_TAB_KEY) ? (keycode = FT_TAB_KEY) : 0;
+ return (keycode);
+}
+
diff --git a/src/ft_draw_scene.c b/src/ft_draw_scene.c
index ec2cc89..966d357 100644
--- a/src/ft_draw_scene.c
+++ b/src/ft_draw_scene.c
@@ -18,7 +18,7 @@
void
ft_draw_scene(t_cub *clist)
{
- mlx_clear_window(clist->wlist->wlx, clist->wlist->winptr);
+ /* mlx_clear_window(clist->wlist->wlx, clist->wlist->winptr); */
clist->img.img = mlx_new_image(clist->wlist->wlx,
clist->wlist->x_size, clist->wlist->y_size);
clist->img.ptr = mlx_get_data_addr(clist->img.img, &clist->img.bpp,
diff --git a/src/ft_hooks_and_loops.c b/src/ft_hooks_and_loops.c
index a494597..e7f9d58 100644
--- a/src/ft_hooks_and_loops.c
+++ b/src/ft_hooks_and_loops.c
@@ -18,6 +18,7 @@ void
ft_hooks_and_loops(t_win *wl, t_cub *cl)
{
mlx_hook(wl->winptr, 2, 1L << 0, ft_key_event, cl);
+ mlx_key_hook(wl->winptr, ft_key_release, cl);
mlx_hook(wl->winptr, 17, 0L, ft_click_close, cl);
mlx_loop(wl->wlx);
}
diff --git a/src/ft_init_lists.c b/src/ft_init_lists.c
index 95f0488..90b8638 100644
--- a/src/ft_init_lists.c
+++ b/src/ft_init_lists.c
@@ -67,6 +67,7 @@ static t_cub
*ft_init_cub(void)
{
t_cub *clist;
+ uint8_t i;
if (!(clist = (t_cub*)malloc(sizeof(t_cub))))
return (NULL);
@@ -74,6 +75,12 @@ static t_cub
!(clist->mlist = ft_init_map()))
return (NULL);
ft_bzero(clist->errmsg, 40);
+ i = 0;
+ while (i < 5)
+ {
+ clist->key_input[i] = -1;
+ i++;
+ }
clist->minimap = 0;
clist->f_rgb = ft_init_rgb();
clist->c_rgb = ft_init_rgb();
diff --git a/src/ft_key_events.c b/src/ft_key_events.c
index 267bccf..54f3033 100644
--- a/src/ft_key_events.c
+++ b/src/ft_key_events.c
@@ -15,25 +15,15 @@
#include <stdlib.h>
#include <stdint.h>
-static uint16_t
- ft_set_keycode(const uint16_t tmp_code)
+static void
+ ft_insert_key(uint16_t keycode, t_cub *clist)
{
- uint16_t keycode;
+ uint8_t i;
- keycode = UINT16_MAX;
- (tmp_code == FT_W_KEY) ? (keycode = 0) : 0;
- (tmp_code == FT_A_KEY) ? (keycode = 1) : 0;
- (tmp_code == FT_S_KEY) ? (keycode = 2) : 0;
- (tmp_code == FT_D_KEY) ? (keycode = 3) : 0;
- (tmp_code == FT_L_ARR_KEY) ? (keycode = 4) : 0;
- (tmp_code == FT_R_ARR_KEY) ? (keycode = 5) : 0;
- (tmp_code == 3) ? (keycode = UINT16_MAX) : 0;
- (tmp_code == 4) ? (keycode = UINT16_MAX) : 0;
- (tmp_code == 5) ? (keycode = UINT16_MAX) : 0;
- (tmp_code == FT_ESC_KEY) ? (keycode = FT_ESC_KEY) : 0;
- (tmp_code == FT_F1_KEY) ? (keycode = FT_F1_KEY) : 0;
- (tmp_code == FT_TAB_KEY) ? (keycode = FT_TAB_KEY) : 0;
- return (keycode);
+ i = 0;
+ while (i < 5 && clist->key_input[i] != keycode && clist->key_input[i] != -1)
+ i++;
+ clist->key_input[i] = keycode;
}
static void
@@ -53,7 +43,7 @@ int
ft_key_event(int keycode, t_cub *clist)
{
int (*fun_ptr[6])(t_cub*);
- const uint16_t tmp_code = keycode;
+ const int32_t tmp_code = keycode;
const float old_y = clist->plist->pos_y;
const float old_x = clist->plist->pos_x;
@@ -63,7 +53,14 @@ int
fun_ptr[3] = ft_d_key;
fun_ptr[4] = ft_left_key;
fun_ptr[5] = ft_right_key;
- keycode = ft_set_keycode(tmp_code);
+ keycode = ft_convert_keycode(tmp_code);
+ ft_insert_key(keycode, clist);
+ ft_printf("keys [%d][%d][%d][%d][%d]\n",
+ clist->key_input[0],
+ clist->key_input[1],
+ clist->key_input[2],
+ clist->key_input[3],
+ clist->key_input[4]);
if (keycode <= 5)
{
(*fun_ptr[keycode])(clist);
diff --git a/src/ft_key_release.c b/src/ft_key_release.c
new file mode 100644
index 0000000..e56b9d0
--- /dev/null
+++ b/src/ft_key_release.c
@@ -0,0 +1,43 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_key_release.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/17 18:43:56 by rbousset #+# #+# */
+/* Updated: 2020/02/17 18:43:59 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <libft.h>
+#include <cub3d.h>
+#include <stdint.h>
+
+static void
+ ft_pop_key(uint16_t keycode, t_cub *clist)
+{
+ uint8_t i;
+
+ i = 0;
+ while (i < 5)
+ {
+ if (clist->key_input[i] != keycode)
+ clist->key_input[i] = -1;
+ i++;
+ }
+}
+
+int
+ ft_key_release(int keycode, t_cub *clist)
+{
+ keycode = ft_convert_keycode(keycode);
+ ft_pop_key(keycode, clist);
+ ft_printf("keys [%d][%d][%d][%d][%d]\n",
+ clist->key_input[0],
+ clist->key_input[1],
+ clist->key_input[2],
+ clist->key_input[3],
+ clist->key_input[4]);
+ return (0);
+}