support for gamepad events
This commit is contained in:
@@ -877,7 +877,7 @@ int main(int argc, char **argv)
|
||||
profile_enabled = 1; script_start = 2;
|
||||
}
|
||||
|
||||
if (!SDL_Init(SDL_INIT_EVENTS)) {
|
||||
if (!SDL_Init(SDL_INIT_EVENTS | SDL_INIT_GAMEPAD)) {
|
||||
printf("CRITICAL ERROR: %s\n", SDL_GetError());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -653,16 +653,26 @@ static void event2wota_write(WotaBuffer *wb, const SDL_Event *e, int c) {
|
||||
wota_write_text(wb, "which");
|
||||
wota_write_number(wb, (double)e->gaxis.which);
|
||||
wota_write_text(wb, "axis");
|
||||
wota_write_number(wb, (double)e->gaxis.axis);
|
||||
wota_write_text(wb, SDL_GetGamepadStringForAxis(e->gaxis.axis));
|
||||
wota_write_text(wb, "value");
|
||||
wota_write_number(wb, (double)e->gaxis.value);
|
||||
// Normalize axis values
|
||||
double normalized_value;
|
||||
if (e->gaxis.axis == SDL_GAMEPAD_AXIS_LEFT_TRIGGER ||
|
||||
e->gaxis.axis == SDL_GAMEPAD_AXIS_RIGHT_TRIGGER) {
|
||||
// Triggers: 0 to 32767 -> 0 to 1
|
||||
normalized_value = (double)e->gaxis.value / 32767.0;
|
||||
} else {
|
||||
// Thumbsticks: -32768 to 32767 -> -1 to 1
|
||||
normalized_value = (double)e->gaxis.value / 32767.0;
|
||||
}
|
||||
wota_write_number(wb, normalized_value);
|
||||
break;
|
||||
case SDL_EVENT_GAMEPAD_BUTTON_DOWN:
|
||||
case SDL_EVENT_GAMEPAD_BUTTON_UP:
|
||||
wota_write_text(wb, "which");
|
||||
wota_write_number(wb, (double)e->gbutton.which);
|
||||
wota_write_text(wb, "button");
|
||||
wota_write_number(wb, (double)e->gbutton.button);
|
||||
wota_write_text(wb, SDL_GetGamepadStringForButton(e->gbutton.button));
|
||||
wota_write_text(wb, "down");
|
||||
wota_write_sym(wb, e->gbutton.down ? WOTA_TRUE : WOTA_FALSE);
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user