From 4c5630b0d409419d6de905379a06893eac64996b Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Tue, 20 Sep 2022 13:43:18 +0200 Subject: [PATCH] Remap calls to pad/mouse/keyboard to input --- src/camera/CMakeLists.txt | 11 +++- src/camera/inc/camera.h | 5 +- src/camera/privinc/camera_private.h | 9 +++- src/camera/src/camera.c | 7 +-- src/camera/src/pad.c | 41 +++++++------- src/camera/src/touch.c | 10 ++-- src/gui/CMakeLists.txt | 2 +- src/gui/inc/gui.h | 5 +- src/gui/privinc/gui_private.h | 7 +++ src/gui/src/button.c | 42 ++++----------- src/gui/src/container.c | 4 +- src/gui/src/gui.c | 84 +++++++++++++++++++++++++++-- src/menu/CMakeLists.txt | 2 +- src/menu/privinc/menu_private.h | 2 + src/menu/src/gamecfg_menu.c | 4 +- src/menu/src/hostjoin_menu.c | 2 +- src/menu/src/main_menu.c | 2 +- src/menu/src/menu.c | 6 ++- src/peripheral/inc/peripheral.h | 1 + src/player/CMakeLists.txt | 1 + src/player/inc/human_player.h | 2 + src/player/src/human_player.c | 40 ++++++++------ 22 files changed, 195 insertions(+), 94 deletions(-) diff --git a/src/camera/CMakeLists.txt b/src/camera/CMakeLists.txt index 2ef522a..44da6b8 100644 --- a/src/camera/CMakeLists.txt +++ b/src/camera/CMakeLists.txt @@ -1,3 +1,12 @@ add_library(camera "src/camera.c" "src/pad.c" "src/mouse.c" "src/touch.c") target_include_directories(camera PUBLIC "inc" PRIVATE "privinc") -target_link_libraries(camera PUBLIC container mouse pad peripheral util PRIVATE gfx) +target_link_libraries(camera + PUBLIC + container + input + peripheral + util + PRIVATE + gfx + mouse + pad) diff --git a/src/camera/inc/camera.h b/src/camera/inc/camera.h index 9841315..a108c98 100644 --- a/src/camera/inc/camera.h +++ b/src/camera/inc/camera.h @@ -1,8 +1,7 @@ #ifndef CAMERA_H #define CAMERA_H -#include -#include +#include #include #include #include @@ -50,7 +49,7 @@ struct camera extern struct sprite cursor_sprite; -void camera_update(struct camera *cam, const union peripheral *p); +void camera_update(struct camera *cam, const union peripheral *p, const struct input *in); bool camera_translate(const struct camera *cam, const struct util_rect *dim, short *x, short *y); void cursor_init(struct cursor *c); bool cursor_collision(const struct camera *cam, const struct util_rect *d); diff --git a/src/camera/privinc/camera_private.h b/src/camera/privinc/camera_private.h index c3cb64c..e83c255 100644 --- a/src/camera/privinc/camera_private.h +++ b/src/camera/privinc/camera_private.h @@ -2,6 +2,9 @@ #define CAMERA_PRIVATE_H #include +#include +#include +#include #ifdef __cplusplus extern "C" @@ -15,9 +18,11 @@ enum }; void camera_update_pos(struct camera *cam); -void camera_update_pad(struct camera *cam, const struct pad *p); +void camera_update_pad(struct camera *cam, const struct pad *p, + const struct input *in); void camera_update_mouse(struct camera *cam, const struct mouse *m); -void camera_update_touch(struct camera *cam, const struct mouse *m); +void camera_update_touch(struct camera *cam, const struct mouse *m, + const struct input *in); #ifdef __cplusplus } diff --git a/src/camera/src/camera.c b/src/camera/src/camera.c index 6d114c5..a9c6814 100644 --- a/src/camera/src/camera.c +++ b/src/camera/src/camera.c @@ -124,12 +124,13 @@ void cursor_set_pos_list(struct cursor *const c, }; } -void camera_update(struct camera *const cam, const union peripheral *const p) +void camera_update(struct camera *const cam, + const union peripheral *const p, const struct input *const in) { switch (p->common.type) { case PERIPHERAL_TYPE_PAD: - camera_update_pad(cam, &p->pad.pad); + camera_update_pad(cam, &p->pad.pad, in); break; case PERIPHERAL_TYPE_KEYBOARD_MOUSE: @@ -137,7 +138,7 @@ void camera_update(struct camera *const cam, const union peripheral *const p) break; case PERIPHERAL_TYPE_TOUCH: - camera_update_touch(cam, &p->kbm.mouse); + camera_update_touch(cam, &p->kbm.mouse, in); break; } } diff --git a/src/camera/src/pad.c b/src/camera/src/pad.c index 317616f..13cb43e 100644 --- a/src/camera/src/pad.c +++ b/src/camera/src/pad.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -7,7 +8,8 @@ #include #include -static void cursor_update(struct camera *const cam, const struct pad *const p) +static void cursor_update(struct camera *const cam, + const struct pad *const p, const struct input *const in) { struct cursor *const c = &cam->cursor; enum {STEP = 4}; @@ -16,29 +18,31 @@ static void cursor_update(struct camera *const cam, const struct pad *const p) || c->screen.last_h != screen_h) cursor_init(c); - if (pad_pressed(p, PAD_KEY_LEFT) + if (input_pad_pressed(in, p, PAD_KEY_LEFT) && (c->x - STEP) && (!cam->x || c->x != c->x_init)) c->x -= STEP; - else if (pad_pressed(p, PAD_KEY_RIGHT) + else if (input_pad_pressed(in, p, PAD_KEY_RIGHT) && (c->x + STEP < screen_w) && (c->x != c->x_init || cam->x <= -cam->dim.w)) c->x += STEP; - if (pad_pressed(p, PAD_KEY_UP) + if (input_pad_pressed(in, p, PAD_KEY_UP) && (c->y - STEP) && (c->y != c->y_init || !cam->y)) c->y -= STEP; - else if (pad_pressed(p, PAD_KEY_DOWN) + else if (input_pad_pressed(in, p, PAD_KEY_DOWN) && (c->y + STEP < screen_h) && (c->y != c->y_init || cam->y <= -cam->dim.h)) c->y += STEP; - c->state = pad_pressed(p, PAD_KEY_A) || pad_pressed(p, PAD_KEY_B) ? + c->state = input_pad_pressed(in, p, PAD_KEY_A) || + input_pad_pressed(in, p, PAD_KEY_B) ? CURSOR_STATE_PRESSED: CURSOR_STATE_IDLE; } -static void update_speed(struct camera *const cam, const struct pad *const p) +static void update_speed(struct camera *const cam, + const struct pad *const p, const struct input *const in) { enum { @@ -52,14 +56,14 @@ static void update_speed(struct camera *const cam, const struct pad *const p) if (c->x == c->x_init && (!cam->x_speed || ++cam->xt >= T_STEP)) { - if (pad_pressed(p, PAD_KEY_RIGHT)) + if (input_pad_pressed(in, p, PAD_KEY_RIGHT)) { if (cam->x_speed > 0) cam->x_speed = -STEP; else if (cam->x_speed - STEP >= -MAX_SPEED) cam->x_speed -= STEP; } - else if (pad_pressed(p, PAD_KEY_LEFT)) + else if (input_pad_pressed(in, p, PAD_KEY_LEFT)) { if (cam->x_speed < 0) cam->x_speed = STEP; @@ -77,14 +81,14 @@ static void update_speed(struct camera *const cam, const struct pad *const p) if (c->y == c->y_init && (!cam->y_speed || ++cam->yt >= T_STEP)) { - if (pad_pressed(p, PAD_KEY_DOWN)) + if (input_pad_pressed(in, p, PAD_KEY_DOWN)) { if (cam->y_speed > 0) cam->y_speed = STEP; else if (cam->y_speed - STEP >= -MAX_SPEED) cam->y_speed -= STEP; } - else if (pad_pressed(p, PAD_KEY_UP)) + else if (input_pad_pressed(in, p, PAD_KEY_UP)) { if (cam->y_speed < 0) cam->y_speed = -STEP; @@ -119,7 +123,7 @@ static enum pad_key get_ref_key(struct cursor_pos_rt *const rt, } static void cursor_update_fixed(struct camera *const cam, - const struct pad *const p) + const struct pad *const p, const struct input *const in) { struct cursor *const c = &cam->cursor; struct cursor_pos_rt *const rt = &c->rt; @@ -129,7 +133,7 @@ static void cursor_update_fixed(struct camera *const cam, { const enum pad_key key = get_ref_key(rt, next); - if (pad_justpressed(p, key)) + if (input_pad_justpressed(in, p, key)) rt->i = next; } else if (rt->i) @@ -137,7 +141,7 @@ static void cursor_update_fixed(struct camera *const cam, const size_t prev = rt->i - 1; const enum pad_key key = get_ref_key(rt, prev); - if (pad_justpressed(p, key)) + if (input_pad_justpressed(in, p, key)) rt->i = prev; } @@ -147,14 +151,15 @@ static void cursor_update_fixed(struct camera *const cam, c->y = cur->y; } -void camera_update_pad(struct camera *const cam, const struct pad *const p) +void camera_update_pad(struct camera *const cam, const struct pad *const p, + const struct input *const in) { if (cam->cursor.rt.list) - cursor_update_fixed(cam, p); + cursor_update_fixed(cam, p, in); else { - cursor_update(cam, p); - update_speed(cam, p); + cursor_update(cam, p, in); + update_speed(cam, p, in); camera_update_pos(cam); } } diff --git a/src/camera/src/touch.c b/src/camera/src/touch.c index e4fc118..27ac4a7 100644 --- a/src/camera/src/touch.c +++ b/src/camera/src/touch.c @@ -13,11 +13,12 @@ static void cursor_update(struct cursor *const c, const struct mouse *const m) c->y = m->y; } -static void update_speed(struct camera *const cam, const struct mouse *const m) +static void update_speed(struct camera *const cam, const struct mouse *const m, + const struct input *const in) { int *const sx = &cam->x_speed, *const sy = &cam->y_speed; - if (mouse_pressed(m, MOUSE_BUTTON_LEFT)) + if (input_mouse_pressed(in, m, MOUSE_BUTTON_LEFT)) { *sx = m->dx; *sy = m->dy; @@ -42,9 +43,10 @@ static void update_speed(struct camera *const cam, const struct mouse *const m) } } -void camera_update_touch(struct camera *const cam, const struct mouse *const m) +void camera_update_touch(struct camera *const cam, const struct mouse *const m, + const struct input *const in) { cursor_update(&cam->cursor, m); - update_speed(cam, m); + update_speed(cam, m, in); camera_update_pos(cam); } diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index b7fe2c1..6ff3a71 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -9,4 +9,4 @@ add_library(gui "src/rounded_rect.c" ) target_include_directories(gui PUBLIC "inc" PRIVATE "privinc") -target_link_libraries(gui PUBLIC camera gfx peripheral font) +target_link_libraries(gui PUBLIC camera gfx input peripheral font) diff --git a/src/gui/inc/gui.h b/src/gui/inc/gui.h index 84a6c66..9093572 100644 --- a/src/gui/inc/gui.h +++ b/src/gui/inc/gui.h @@ -3,6 +3,7 @@ #include #include +#include #include #ifdef __cplusplus @@ -16,7 +17,7 @@ struct gui_common { void (*add_child)(struct gui_common *parent, struct gui_common *child); int (*update)(struct gui_common *, const union peripheral *, - const struct camera *); + const struct camera *, struct input *); int (*render)(const struct gui_common *); void (*get_dim)(const struct gui_common *, short *w, short *h); } *cb; @@ -29,7 +30,7 @@ struct gui_common void gui_add_child(struct gui_common *parent, struct gui_common *child); void gui_add_sibling(struct gui_common *g, struct gui_common *sibling); int gui_update(struct gui_common *g, const union peripheral *p, - const struct camera *c); + const struct camera *c, struct input *in); int gui_render(const struct gui_common *g); #ifdef __cplusplus diff --git a/src/gui/privinc/gui_private.h b/src/gui/privinc/gui_private.h index af18dcd..c03d04c 100644 --- a/src/gui/privinc/gui_private.h +++ b/src/gui/privinc/gui_private.h @@ -2,6 +2,9 @@ #define GUI_PRIVATE_H #include +#include +#include +#include #ifdef __cplusplus extern "C" @@ -9,6 +12,10 @@ extern "C" #endif void gui_coords(const struct gui_common *g, short *x, short *y); +bool gui_pressed(const struct gui_common *g, const struct input *in, + const union peripheral *p, const struct camera *cam, short w, short h); +bool gui_released(const struct gui_common *g, const union peripheral *p, + const struct camera *cam, short w, short h); #ifdef __cplusplus } diff --git a/src/gui/src/button.c b/src/gui/src/button.c index f4f94e0..cf49679 100644 --- a/src/gui/src/button.c +++ b/src/gui/src/button.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -37,47 +38,22 @@ static void get_dim(const struct gui_common *const g, static bool pressed(const struct gui_button *const b, const union peripheral *const p, - const struct camera *const cam) + const struct camera *const cam, + const struct input *const in) { - bool check = false; + short w, h; - switch (p->common.type) - { - case PERIPHERAL_TYPE_PAD: - check = pad_justpressed(&p->pad.pad, PAD_KEY_A); - break; - - case PERIPHERAL_TYPE_KEYBOARD_MOUSE: - check = mouse_justreleased(&p->kbm.mouse, MOUSE_BUTTON_LEFT); - break; - - case PERIPHERAL_TYPE_TOUCH: - check = mouse_justpressed(&p->kbm.mouse, MOUSE_BUTTON_LEFT); - break; - } - - if (check) - { - short x, y; - struct util_rect d; - - gui_coords(&b->common, &x, &y); - get_dim(&b->common, &d.w, &d.h); - d.x = x; - d.y = y; - - return cursor_collision(cam, &d); - } - - return false; + get_dim(&b->common, &w, &h); + return gui_pressed(&b->common, in, p, cam, w, h); } static int update(struct gui_common *const g, - const union peripheral *const p, const struct camera *const c) + const union peripheral *const p, const struct camera *const c, + struct input *const in) { struct gui_button *const b = (struct gui_button *)g; - if (pressed(b, p, c) && b->on_pressed) + if (pressed(b, p, c, in) && b->on_pressed) b->on_pressed(b->arg); return 0; diff --git a/src/gui/src/container.c b/src/gui/src/container.c index ad3b901..e7d4049 100644 --- a/src/gui/src/container.c +++ b/src/gui/src/container.c @@ -1,6 +1,7 @@ #include #include #include +#include #include static void add_child(struct gui_common *const parent, @@ -52,7 +53,8 @@ static void get_dim(const struct gui_common *const g, } static int update(struct gui_common *const g, - const union peripheral *const p, const struct camera *const cam) + const union peripheral *const p, const struct camera *const cam, + struct input *const in) { struct gui_container *const c = (struct gui_container *)g; diff --git a/src/gui/src/gui.c b/src/gui/src/gui.c index 022ce73..b99300b 100644 --- a/src/gui/src/gui.c +++ b/src/gui/src/gui.c @@ -1,4 +1,7 @@ #include +#include +#include +#include static void get_centered(const struct gui_common *const g, short *const x, short *const y) @@ -51,6 +54,79 @@ void gui_coords(const struct gui_common *const g, short *const x, get_centered(g, x, y); } + +static bool check_collision(const struct gui_common *const g, + const union peripheral *const p, + const struct camera *cam, const short w, const short h) +{ + short x, y; + + gui_coords(g, &x, &y); + + const struct util_rect d = + { + .x = x, + .y = y, + .w = w, + .h = h + }; + + return cursor_collision(cam, &d); +} + +bool gui_pressed(const struct gui_common *const g, + const struct input *const in, + const union peripheral *const p, + const struct camera *cam, const short w, const short h) +{ + bool check = false; + + switch (p->common.type) + { + case PERIPHERAL_TYPE_PAD: + check = input_pad_justpressed(in, &p->pad.pad, PAD_KEY_A); + break; + + case PERIPHERAL_TYPE_KEYBOARD_MOUSE: + /* Fall through. */ + case PERIPHERAL_TYPE_TOUCH: + check = input_mouse_justreleased(in, &p->kbm.mouse, + MOUSE_BUTTON_LEFT); + break; + } + + if (check) + return check_collision(g, p, cam, w, h); + + return false; +} + +bool gui_released(const struct gui_common *const g, + const union peripheral *const p, + const struct camera *cam, const short w, const short h) +{ + bool check = false; + + switch (p->common.type) + { + case PERIPHERAL_TYPE_PAD: + check = pad_justpressed(&p->pad.pad, PAD_KEY_A); + break; + + case PERIPHERAL_TYPE_KEYBOARD_MOUSE: + /* Fall through. */ + case PERIPHERAL_TYPE_TOUCH: + check = mouse_justreleased(&p->kbm.mouse, + MOUSE_BUTTON_LEFT); + break; + } + + if (check) + return !check_collision(g, p, cam, w, h); + + return false; +} + void gui_add_sibling(struct gui_common *const g, struct gui_common *const s) { @@ -77,16 +153,16 @@ void gui_add_child(struct gui_common *const p, } int gui_update(struct gui_common *const g, const union peripheral *const p, - const struct camera *const c) + const struct camera *const c, struct input *const in) { - if (g->child && gui_update(g->child, p, c)) + if (g->child && gui_update(g->child, p, c, in)) return -1; - if (g->cb && g->cb->update && g->cb->update(g, p, c)) + if (g->cb && g->cb->update && g->cb->update(g, p, c, in)) return -1; for (struct gui_common *s = g->sibling; s; s = s->sibling) - if (gui_update(s, p, c)) + if (gui_update(s, p, c, in)) return -1; return 0; diff --git a/src/menu/CMakeLists.txt b/src/menu/CMakeLists.txt index 50246c4..940b26b 100644 --- a/src/menu/CMakeLists.txt +++ b/src/menu/CMakeLists.txt @@ -5,4 +5,4 @@ add_library(menu "src/main_menu.c" ) target_include_directories(menu PUBLIC "inc" PRIVATE "privinc") -target_link_libraries(menu PRIVATE camera game gfx gui system) +target_link_libraries(menu PRIVATE camera game gfx gui input system) diff --git a/src/menu/privinc/menu_private.h b/src/menu/privinc/menu_private.h index 1ab267b..0276b20 100644 --- a/src/menu/privinc/menu_private.h +++ b/src/menu/privinc/menu_private.h @@ -2,6 +2,7 @@ #define MENU_PRIVATE_H #include +#include #include #include @@ -14,6 +15,7 @@ struct menu_common { struct camera cam; union peripheral p; + struct input in; }; int menu_update(struct menu_common *c, diff --git a/src/menu/src/gamecfg_menu.c b/src/menu/src/gamecfg_menu.c index 2cdd48f..12184f5 100644 --- a/src/menu/src/gamecfg_menu.c +++ b/src/menu/src/gamecfg_menu.c @@ -23,8 +23,8 @@ static int update(struct menu_common *const c, void *const arg) m->r.w = screen_w / 2; m->r.h = screen_h / 2; - if (gui_update(&m->cnt.common, &c->p, &c->cam) - || gui_update(&m->bcnt.common, &c->p, &c->cam)) + if (gui_update(&m->cnt.common, &c->p, &c->cam, &c->in) + || gui_update(&m->bcnt.common, &c->p, &c->cam, &c->in)) return -1; return 0; diff --git a/src/menu/src/hostjoin_menu.c b/src/menu/src/hostjoin_menu.c index 33ad3c8..49d5ec9 100644 --- a/src/menu/src/hostjoin_menu.c +++ b/src/menu/src/hostjoin_menu.c @@ -16,7 +16,7 @@ static int update(struct menu_common *const c, void *const arg) { struct menu_hostjoin *const m = arg; - if (gui_update(&m->cnt.common, &c->p, &c->cam)) + if (gui_update(&m->cnt.common, &c->p, &c->cam, &c->in)) return -1; return 0; diff --git a/src/menu/src/main_menu.c b/src/menu/src/main_menu.c index 9a99e7c..0c9ddb0 100644 --- a/src/menu/src/main_menu.c +++ b/src/menu/src/main_menu.c @@ -18,7 +18,7 @@ static int update(struct menu_common *const c, void *const arg) { struct main_menu *const m = arg; - if (gui_update(&m->play.common, &c->p, &c->cam)) + if (gui_update(&m->play.common, &c->p, &c->cam, &c->in)) return -1; return 0; diff --git a/src/menu/src/menu.c b/src/menu/src/menu.c index 200023c..ba90708 100644 --- a/src/menu/src/menu.c +++ b/src/menu/src/menu.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -19,7 +20,8 @@ int menu_update(struct menu_common *const c, { system_loop(); peripheral_update(&c->p); - camera_update(&c->cam, &c->p); + input_update(&c->in, &c->p); + camera_update(&c->cam, &c->p, &c->in); if (update && update(c, arg)) return -1; @@ -32,6 +34,8 @@ int menu_update(struct menu_common *const c, if (render && render(c, arg)) return -1; + else if (input_render(&c->in, &c->p)) + return -1; switch (c->p.common.type) { diff --git a/src/peripheral/inc/peripheral.h b/src/peripheral/inc/peripheral.h index 956d965..8f8f73b 100644 --- a/src/peripheral/inc/peripheral.h +++ b/src/peripheral/inc/peripheral.h @@ -56,6 +56,7 @@ UTIL_STATIC_ASSERT(!offsetof(struct peripheral_kbm, common), "unexpected offsetof for struct peripheral_kbm"); void peripheral_init(const struct peripheral_cfg *cfg, union peripheral *p); +void peripheral_input_set(union peripheral *p, void (*cb)(char, void *)); void peripheral_update(union peripheral *p); #ifdef __cplusplus diff --git a/src/player/CMakeLists.txt b/src/player/CMakeLists.txt index 3d995ee..f722a53 100644 --- a/src/player/CMakeLists.txt +++ b/src/player/CMakeLists.txt @@ -11,6 +11,7 @@ target_link_libraries(player gfx keyboard instance + input mouse pad resource diff --git a/src/player/inc/human_player.h b/src/player/inc/human_player.h index 7d28b34..173ff80 100644 --- a/src/player/inc/human_player.h +++ b/src/player/inc/human_player.h @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -32,6 +33,7 @@ struct human_player struct player pl; struct camera cam; union peripheral periph; + struct input in; struct sel_instance { diff --git a/src/player/src/human_player.c b/src/player/src/human_player.c index 1d2af7d..314581b 100644 --- a/src/player/src/human_player.c +++ b/src/player/src/human_player.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -542,26 +543,28 @@ static void update_target(struct human_player *const h) static void update_from_pad(struct human_player *const h, struct player_others *const o) { - struct pad *const p = &h->periph.pad.pad; + const struct pad *const p = &h->periph.pad.pad; + const struct input *const in = &h->in; - if (pad_justpressed(p, PAD_KEY_A)) + if (input_pad_justpressed(in, p, PAD_KEY_A)) select_instances(h, o, false, false); - else if (pad_justpressed(p, PAD_KEY_B)) + else if (input_pad_justpressed(in, p, PAD_KEY_B)) move_units(h, o); - else if (pad_justpressed(p, PAD_KEY_C)) + else if (input_pad_justpressed(in, p, PAD_KEY_C)) deselect_instances(h); - else if (pad_justpressed(p, PAD_KEY_E)) + else if (input_pad_justpressed(in, p, PAD_KEY_E)) h->top_gui ^= true; } static void update_from_touch(struct human_player *const h, struct player_others *const o) { - struct mouse *const m = &h->periph.kbm.mouse; + const struct mouse *const m = &h->periph.kbm.mouse; + const struct input *const in = &h->in; struct peripheral_kbm *const kbm = &h->periph.kbm; bool *const pan = &h->cam.pan; - if (mouse_pressed(m, MOUSE_BUTTON_LEFT) && !*pan) + if (input_mouse_pressed(in, m, MOUSE_BUTTON_LEFT) && !*pan) { enum {LONG_PRESS_THRESHOLD = 30}; @@ -573,7 +576,7 @@ static void update_from_touch(struct human_player *const h, deselect_instances(h); } } - else if (mouse_justreleased(m, MOUSE_BUTTON_LEFT)) + else if (input_mouse_justreleased(in, m, MOUSE_BUTTON_LEFT)) { if (!*pan && !select_instances(h, o, false, true)) move_units(h, o); @@ -587,19 +590,22 @@ static void update_from_touch(struct human_player *const h, static void update_from_keyboard_mouse(struct human_player *const h, struct player_others *const o) { - struct mouse *const m = &h->periph.kbm.mouse; - struct keyboard *const k = &h->periph.kbm.keyboard; + const struct mouse *const m = &h->periph.kbm.mouse; + const struct keyboard *const k = &h->periph.kbm.keyboard; + const struct input *const in = &h->in; - if (mouse_justreleased(m, MOUSE_BUTTON_LEFT)) + if (input_mouse_justreleased(in, m, MOUSE_BUTTON_LEFT)) { const bool shift_pressed = - keyboard_pressed(k, &KEYBOARD_COMBO(KEYBOARD_KEY_LSHIFT)) - || keyboard_pressed(k, &KEYBOARD_COMBO(KEYBOARD_KEY_RSHIFT)); + input_keyboard_pressed(in, k, + &KEYBOARD_COMBO(KEYBOARD_KEY_LSHIFT)) + || input_keyboard_pressed(in, k, + &KEYBOARD_COMBO(KEYBOARD_KEY_RSHIFT)); if (!select_instances(h, o, !shift_pressed, false)) deselect_instances(h); } - else if (mouse_justreleased(m, MOUSE_BUTTON_RIGHT)) + else if (input_mouse_justreleased(in, m, MOUSE_BUTTON_RIGHT)) move_units(h, o); } @@ -614,6 +620,7 @@ void human_player_update(struct human_player *const h, update_selected(h); update_target(h); peripheral_update(&h->periph); + input_update(&h->in, &h->periph); switch (h->periph.common.type) { @@ -630,7 +637,7 @@ void human_player_update(struct human_player *const h, break; } - camera_update(&h->cam, &h->periph); + camera_update(&h->cam, &h->periph, &h->in); player_update(p); } } @@ -702,7 +709,8 @@ int human_player_render(const struct human_player *const h, || render_own_units(h) || render_own_buildings(h) || render_resources(h, o->res, o->n_res) - || human_player_gui_render(h)) + || human_player_gui_render(h) + || input_render(&h->in, &h->periph)) return -1; switch (h->periph.common.type)