1 #include <bz/input/input_internal.h>
2 #include <bz/input/platform.h>
4 #include <bz/input/input_id_internal.h>
7 typedef enum BZInputCode
{
10 const BZInputCode BZInputCodeMax
= BZInputCodeQuit
;
12 typedef union BZInputTableEntry
{
18 static BZInput bzQuitInput
= { .id
= BZInputCodeQuit
, };
19 BZInputID bzQuitInputID
= &bzQuitInput
;
21 const size_t inputTableSize
= BZInputCodeMax
+ 1;
22 static BZInputTableEntry inputTable
[inputTableSize
];
29 #define kButtonCount 12
31 static Button buttons
[kButtonCount
];
33 static SDL_Joystick
*joy
;
35 int buttonIdx(SDL_KeyCode keyCode
) {
73 for (size_t i
= 0; i
< kButtonCount
; ++i
) {
74 buttons
[i
].down
= false;
77 for (size_t i
= 0, c
= SDL_NumJoysticks(); i
< c
; ++i
) {
78 bzLog("Joystick: %s", SDL_JoystickName(i
));
82 if (SDL_NumJoysticks() > 0) {
83 joy
= SDL_JoystickOpen(0);
87 void bzInputTeardown() {
91 void bzInputProcessFrame() {
92 for (size_t i
= 0; i
< inputTableSize
; ++i
) {
93 inputTable
[i
].integerValue
= 0; // FIXME, max size and whatever.
96 for (size_t i
= 0; i
< kButtonCount
; ++i
) {
97 buttons
[i
].down
= buttons
[i
].down
|| buttons
[i
].pressed
;
98 buttons
[i
].pressed
= false;
102 while (SDL_PollEvent(&event
)) {
103 switch (event
.type
) {
105 inputTable
[BZInputCodeQuit
].booleanValue
= true;
109 buttons
[buttonIdx(event
.key
.keysym
.sym
)].pressed
= true;
113 buttons
[buttonIdx(event
.key
.keysym
.sym
)].pressed
= false;
114 buttons
[buttonIdx(event
.key
.keysym
.sym
)].down
= false;
120 bool bzInputGetBooleanValue(BZInputID inputID
) {
121 return inputTable
[inputID
->id
].booleanValue
;
124 int bzInputGetIntegerValue(BZInputID inputID
) {
125 return inputTable
[inputID
->id
].integerValue
;
128 float bzInputGetFloatValue(BZInputID inputID
) {
129 return inputTable
[inputID
->id
].floatValue
;
132 bool bzInputBtn(int id
) {
133 return buttons
[id
].down
|| buttons
[id
].pressed
;
136 bool bzInputBtnP(int id
) {
137 return buttons
[id
].pressed
;