diff options
| author | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2022-09-20 13:43:18 +0200 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2022-09-20 16:56:30 +0200 |
| commit | 87b4ef3a15af505f5ed5150ee1dadd2e2bc94c17 (patch) | |
| tree | f3d317088514089d0f84fb553cf9e307dffca549 /src/camera | |
| parent | 14df82ee4db71509f4ec4968df439d4659ca1ac3 (diff) | |
| download | jancity-87b4ef3a15af505f5ed5150ee1dadd2e2bc94c17.tar.gz | |
Remap calls to pad/mouse/keyboard to input
Diffstat (limited to 'src/camera')
| -rw-r--r-- | src/camera/CMakeLists.txt | 11 | ||||
| -rw-r--r-- | src/camera/inc/camera.h | 5 | ||||
| -rw-r--r-- | src/camera/privinc/camera_private.h | 9 | ||||
| -rw-r--r-- | src/camera/src/camera.c | 7 | ||||
| -rw-r--r-- | src/camera/src/pad.c | 41 | ||||
| -rw-r--r-- | src/camera/src/touch.c | 10 |
6 files changed, 52 insertions, 31 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 <mouse.h> -#include <pad.h> +#include <input.h> #include <peripheral.h> #include <util.h> #include <stdbool.h> @@ -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 <camera.h> +#include <input.h> +#include <mouse.h> +#include <pad.h> #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 <camera.h> #include <camera_private.h> +#include <input.h> #include <pad.h> #include <peripheral.h> #include <gfx.h> @@ -7,7 +8,8 @@ #include <stdbool.h> #include <stdlib.h> -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); } |
