diff options
author | Johnny Richard <johnny@johnnyrichard.com> | 2021-11-14 01:27:15 +0100 |
---|---|---|
committer | Johnny Richard <johnny@johnnyrichard.com> | 2021-11-14 01:27:15 +0100 |
commit | e415b62a2e85f44e6ff285e08b16525605d2fc0f (patch) | |
tree | f31f2ad1c8309b4fc5c5bfde2172efdb10076db3 /src/controller.h | |
parent | f584871064596b52efe12c2f8258f0839f6eb0fa (diff) |
controller_t: Reduce memory usage using bitwise
Diffstat (limited to 'src/controller.h')
-rw-r--r-- | src/controller.h | 22 |
1 files changed, 12 insertions, 10 deletions
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 <SDL.h> #include <stdbool.h> +#include <stdint.h> -#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 */ |