From 0b9f8798eb3b6597b446ecb1c1a50ffeee9c3081 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=A4rkl?= Date: Thu, 2 Jul 2020 19:16:23 +0200 Subject: [PATCH] Add Touches to Controller State --- lib/include/chiaki/controller.h | 25 +++++++++++++++++++++++-- lib/src/controller.c | 13 +++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/lib/include/chiaki/controller.h b/lib/include/chiaki/controller.h index 0239c6c..2a870d0 100644 --- a/lib/include/chiaki/controller.h +++ b/lib/include/chiaki/controller.h @@ -56,6 +56,14 @@ typedef enum chiaki_controller_analog_button_t CHIAKI_CONTROLLER_ANALOG_BUTTON_R2 = (1 << 17) } ChiakiControllerAnalogButton; +typedef struct chiaki_controller_touch_t +{ + uint16_t x, y; + int8_t id; // -1 = up +} ChiakiControllerTouch; + +#define CHIAKI_CONTROLLER_TOUCHES_MAX 2 + typedef struct chiaki_controller_state_t { /** @@ -70,19 +78,32 @@ typedef struct chiaki_controller_state_t int16_t left_y; int16_t right_x; int16_t right_y; + + uint8_t touch_id_next; + ChiakiControllerTouch touches[CHIAKI_CONTROLLER_TOUCHES_MAX]; } ChiakiControllerState; CHIAKI_EXPORT void chiaki_controller_state_set_idle(ChiakiControllerState *state); static inline bool chiaki_controller_state_equals(ChiakiControllerState *a, ChiakiControllerState *b) { - return a->buttons == b->buttons + if(!(a->buttons == b->buttons && a->l2_state == b->l2_state && a->r2_state == b->r2_state && a->left_x == b->left_x && a->left_y == b->left_y && a->right_x == b->right_x - && a->right_y == b->right_y; + && a->right_y == b->right_y)) + return false; + + for(size_t i=0; itouches[i].id != b->touches[i].id) + return false; + if(a->touches[i].id >= 0 && (a->touches[i].x != b->touches[i].x || a->touches[i].y != b->touches[i].y)) + return false; + } + return true; } CHIAKI_EXPORT void chiaki_controller_state_or(ChiakiControllerState *out, ChiakiControllerState *a, ChiakiControllerState *b); diff --git a/lib/src/controller.c b/lib/src/controller.c index f71371c..a3853bd 100644 --- a/lib/src/controller.c +++ b/lib/src/controller.c @@ -39,4 +39,17 @@ CHIAKI_EXPORT void chiaki_controller_state_or(ChiakiControllerState *out, Chiaki out->left_y = MAX_ABS(a->left_y, b->left_y); out->right_x = MAX_ABS(a->right_x, b->right_x); out->right_y = MAX_ABS(a->right_y, b->right_y); + + out->touch_id_next = 0; + for(size_t i=0; itouches[i].id >= 0 ? &a->touches[i] : b->touches[i].id >= 0 ? &b->touches[i] : NULL; + if(!touch) + { + out->touches[i].id = -1; + out->touches[i].x = out->touches[i].y = 0; + continue; + } + out->touches[i] = *touch; + } }