From e415b62a2e85f44e6ff285e08b16525605d2fc0f Mon Sep 17 00:00:00 2001 From: Johnny Richard Date: Sun, 14 Nov 2021 01:27:15 +0100 Subject: controller_t: Reduce memory usage using bitwise --- src/controller.h | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'src/controller.h') diff --git a/src/controller.h b/src/controller.h index 736b9e6..ecc0389 100644 --- a/src/controller.h +++ b/src/controller.h @@ -33,23 +33,25 @@ #include #include +#include -#ifdef __cplusplus -extern "C" { -#endif +enum btn_t { + BTN_UP = 1 << 0, + BTN_DOWN = 1 << 1, + BTN_RIGHT = 1 << 2, + BTN_LEFT = 1 << 3 +}; typedef struct controller_t { - bool up; - bool down; - bool left; - bool right; + uint8_t pressed_buttons; } controller_t; void controller_update(controller_t *self, SDL_Event *event); -#ifdef __cplusplus -} -#endif +bool controller_is_up_pressed(controller_t *self); +bool controller_is_down_pressed(controller_t *self); +bool controller_is_right_pressed(controller_t *self); +bool controller_is_left_pressed(controller_t *self); #endif /* CONTROLLER_H */ -- cgit v1.2.3