1
1
mirror of synced 2025-02-25 13:54:49 +01:00

550 lines
18 KiB
C
Raw Normal View History

2022-06-20 05:36:27 +12:00
#include "poll.h"
#include "helpers.h"
#include <windows.h>
struct {
const char *string;
uint8_t keycode;
} ConfigKeyboardButtons[] = {
2022-06-20 07:17:39 +12:00
{ "F1", 0x70 }, { "F2", 0x71 }, { "F3", 0x72 }, { "F4", 0x73 }, { "F5", 0x74 }, { "F6", 0x75 },
{ "F7", 0x76 }, { "F8", 0x77 }, { "F9", 0x78 }, { "F10", 0x79 }, { "F11", 0x7A }, { "F12", 0x7B },
{ "NUM1", '1' }, { "NUM2", '2' }, { "NUM3", '3' }, { "NUM4", '4' }, { "NUM5", '5' }, { "NUM6", '6' },
{ "NUM7", '7' }, { "NUM8", '8' }, { "NUM9", '9' }, { "NUM0", '0' }, { "Q", 'Q' }, { "W", 'W' },
{ "E", 'E' }, { "R", 'R' }, { "T", 'T' }, { "Y", 'Y' }, { "U", 'U' }, { "I", 'I' },
{ "O", 'O' }, { "P", 'P' }, { "A", 'A' }, { "S", 'S' }, { "D", 'D' }, { "F", 'F' },
{ "G", 'G' }, { "H", 'H' }, { "J", 'J' }, { "K", 'K' }, { "L", 'L' }, { "Z", 'Z' },
{ "X", 'X' }, { "C", 'C' }, { "V", 'V' }, { "B", 'B' }, { "N", 'N' }, { "M", 'M' },
{ "UPARROW", 0x26 }, { "LEFTARROW", 0x25 }, { "DOWNARROW", 0x28 }, { "RIGHTARROW", 0x27 }, { "ENTER", 0x0D }, { "SPACE", 0x20 },
2022-06-20 07:17:39 +12:00
{ "CONTROL", 0x11 }, { "SHIFT", 0x10 }, { "TAB", 0x09 }, { "ESCAPE", 0x1B },
2022-06-20 05:36:27 +12:00
};
struct {
const char *string;
SDL_GameControllerButton button;
} ConfigControllerButtons[] = {
{ "SDL_A", SDL_CONTROLLER_BUTTON_A },
{ "SDL_B", SDL_CONTROLLER_BUTTON_B },
{ "SDL_X", SDL_CONTROLLER_BUTTON_X },
{ "SDL_Y", SDL_CONTROLLER_BUTTON_Y },
{ "SDL_BACK", SDL_CONTROLLER_BUTTON_BACK },
{ "SDL_GUIDE", SDL_CONTROLLER_BUTTON_GUIDE },
{ "SDL_START", SDL_CONTROLLER_BUTTON_START },
{ "SDL_LSTICK_PRESS", SDL_CONTROLLER_BUTTON_LEFTSTICK },
{ "SDL_RSTICK_PRESS", SDL_CONTROLLER_BUTTON_RIGHTSTICK },
{ "SDL_LSHOULDER", SDL_CONTROLLER_BUTTON_LEFTSHOULDER },
{ "SDL_RSHOULDER", SDL_CONTROLLER_BUTTON_RIGHTSHOULDER },
{ "SDL_DPAD_UP", SDL_CONTROLLER_BUTTON_DPAD_UP },
{ "SDL_DPAD_DOWN", SDL_CONTROLLER_BUTTON_DPAD_DOWN },
{ "SDL_DPAD_LEFT", SDL_CONTROLLER_BUTTON_DPAD_LEFT },
{ "SDL_DPAD_RIGHT", SDL_CONTROLLER_BUTTON_DPAD_RIGHT },
{ "SDL_MISC", SDL_CONTROLLER_BUTTON_MISC1 },
{ "SDL_PADDLE1", SDL_CONTROLLER_BUTTON_PADDLE1 },
{ "SDL_PADDLE2", SDL_CONTROLLER_BUTTON_PADDLE2 },
{ "SDL_PADDLE3", SDL_CONTROLLER_BUTTON_PADDLE3 },
{ "SDL_PADDLE4", SDL_CONTROLLER_BUTTON_PADDLE4 },
{ "SDL_TOUCHPAD", SDL_CONTROLLER_BUTTON_TOUCHPAD },
};
struct {
const char *string;
enum SDLAxis axis;
} ConfigControllerAXIS[] = {
2022-06-20 07:17:39 +12:00
{ "SDL_LSTICK_LEFT", SDL_AXIS_LEFT_LEFT }, { "SDL_LSTICK_UP", SDL_AXIS_LEFT_UP }, { "SDL_LSTICK_DOWN", SDL_AXIS_LEFT_DOWN },
{ "SDL_LSTICK_RIGHT", SDL_AXIS_LEFT_RIGHT }, { "SDL_RSTICK_LEFT", SDL_AXIS_RIGHT_LEFT }, { "SDL_RSTICK_UP", SDL_AXIS_RIGHT_UP },
2022-06-20 07:17:39 +12:00
{ "SDL_RSTICK_DOWN", SDL_AXIS_RIGHT_DOWN }, { "SDL_RSTICK_RIGHT", SDL_AXIS_RIGHT_RIGHT }, { "SDL_LTRIGGER", SDL_AXIS_LTRIGGER_DOWN },
2022-06-20 05:36:27 +12:00
{ "SDL_RTRIGGER", SDL_AXIS_RTRIGGER_DOWN },
};
struct {
const char *string;
enum Scroll scroll;
} ConfigMouseScroll[] = {
{ "SCROLL_UP", MOUSE_SCROLL_UP },
{ "SCROLL_DOWN", MOUSE_SCROLL_DOWN },
};
struct MouseState {
POINT Position;
POINT RelativePosition;
bool ScrolledUp;
bool ScrolledDown;
} currentMouseState, lastMouseState;
bool currentKeyboardState[0xFF];
bool lastKeyboardState[0xFF];
bool currentControllerButtonsState[SDL_CONTROLLER_BUTTON_MAX];
bool lastControllerButtonsState[SDL_CONTROLLER_BUTTON_MAX];
struct SDLAxisState currentControllerAxisState;
struct SDLAxisState lastControllerAxisState;
SDL_Window *window;
SDL_GameController *controllers[255];
void
SetConfigValue (toml_table_t *table, char *key, struct Keybindings *keybind) {
toml_array_t *array = toml_array_in (table, key);
if (!array) {
printWarning ("%s (%s): Cannot find array\n", __func__, key);
return;
}
memset (keybind, 0, sizeof (*keybind));
for (int i = 0; i < COUNTOFARR (keybind->buttons); i++)
keybind->buttons[i] = SDL_CONTROLLER_BUTTON_INVALID;
for (int i = 0;; i++) {
toml_datum_t bind = toml_string_at (array, i);
2022-06-20 07:17:39 +12:00
if (!bind.ok) break;
2022-06-20 05:36:27 +12:00
struct ConfigValue value = StringToConfigEnum (bind.u.s);
free (bind.u.s);
switch (value.type) {
case keycode:
for (int i = 0; i < COUNTOFARR (keybind->keycodes); i++) {
if (keybind->keycodes[i] == 0) {
keybind->keycodes[i] = value.keycode;
break;
}
}
break;
case button:
for (int i = 0; i < COUNTOFARR (keybind->buttons); i++) {
if (keybind->buttons[i] == SDL_CONTROLLER_BUTTON_INVALID) {
keybind->buttons[i] = value.button;
break;
}
}
break;
case axis:
for (int i = 0; i < COUNTOFARR (keybind->axis); i++) {
if (keybind->axis[i] == 0) {
keybind->axis[i] = value.axis;
break;
}
}
case scroll:
for (int i = 0; i < COUNTOFARR (keybind->scroll); i++) {
if (keybind->scroll[i] == 0) {
keybind->scroll[i] = value.scroll;
break;
}
}
break;
2022-06-20 07:17:39 +12:00
default: break;
2022-06-20 05:36:27 +12:00
}
}
}
bool
InitializePoll (void *DivaWindowHandle) {
bool hasRumble = true;
SDL_SetMainReady ();
SDL_SetHint (SDL_HINT_JOYSTICK_HIDAPI_PS4, "1");
SDL_SetHint (SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE, "1");
SDL_SetHint (SDL_HINT_JOYSTICK_HIDAPI_PS5, "1");
SDL_SetHint (SDL_HINT_JOYSTICK_HIDAPI_PS5_RUMBLE, "1");
if (SDL_Init (SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | SDL_INIT_GAMECONTROLLER | SDL_INIT_EVENTS | SDL_INIT_VIDEO) != 0) {
if (SDL_Init (SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER | SDL_INIT_EVENTS | SDL_INIT_VIDEO) == 0) {
2022-06-20 05:36:27 +12:00
hasRumble = false;
} else {
printError (
2022-06-20 07:17:39 +12:00
"SDL_Init (SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | "
"SDL_INIT_GAMECONTROLLER | SDL_INIT_EVENTS | SDL_INIT_VIDEO): "
"%s\n",
SDL_GetError ());
2022-06-20 05:36:27 +12:00
return false;
}
}
if (SDL_GameControllerAddMappingsFromFile (configPath ("gamecontrollerdb.txt")) == -1)
2022-06-20 05:36:27 +12:00
printError ("%s (): Cannot read "
2022-06-20 07:17:39 +12:00
"plugins/gamecontrollerdb.txt\n",
__func__);
2022-06-20 05:36:27 +12:00
SDL_GameControllerEventState (SDL_ENABLE);
for (int i = 0; i < SDL_NumJoysticks (); i++) {
2022-06-20 07:17:39 +12:00
if (!SDL_IsGameController (i)) continue;
2022-06-20 05:36:27 +12:00
SDL_GameController *controller = SDL_GameControllerOpen (i);
if (!controller) {
printWarning ("Could not open gamecontroller %s: %s\n", SDL_GameControllerNameForIndex (i), SDL_GetError ());
2022-06-20 05:36:27 +12:00
continue;
}
controllers[i] = controller;
break;
}
window = SDL_CreateWindowFrom (DivaWindowHandle);
2022-06-20 07:17:39 +12:00
if (window != NULL) SDL_SetWindowResizable (window, true);
else printError ("SDL_CreateWindowFrom (DivaWindowHandle): %s\n", SDL_GetError ());
2022-06-20 05:36:27 +12:00
return hasRumble;
}
void
UpdatePoll (void *DivaWindowHandle) {
2022-06-20 07:17:39 +12:00
if (DivaWindowHandle == NULL || GetForegroundWindow () != DivaWindowHandle) return;
2022-06-20 05:36:27 +12:00
memcpy (lastKeyboardState, currentKeyboardState, 255);
memcpy (lastControllerButtonsState, currentControllerButtonsState, 21);
2022-06-20 07:17:39 +12:00
lastMouseState = currentMouseState;
2022-06-20 05:36:27 +12:00
lastControllerAxisState = currentControllerAxisState;
for (uint8_t i = 0; i < 0xFF; i++)
currentKeyboardState[i] = GetAsyncKeyState (i) != 0;
2022-06-20 07:17:39 +12:00
currentMouseState.ScrolledUp = false;
2022-06-20 05:36:27 +12:00
currentMouseState.ScrolledDown = false;
SDL_Event event;
while (SDL_PollEvent (&event) != 0) {
switch (event.type) {
case SDL_CONTROLLERDEVICEADDED:
2022-06-20 07:17:39 +12:00
if (!SDL_IsGameController (event.cdevice.which)) break;
2022-06-20 05:36:27 +12:00
SDL_GameController *controller = SDL_GameControllerOpen (event.cdevice.which);
2022-06-20 05:36:27 +12:00
if (!controller) {
printError (
2022-06-20 07:17:39 +12:00
"%s (): Could not open "
"gamecontroller %s: %s\n",
__func__, SDL_GameControllerNameForIndex (event.cdevice.which), SDL_GetError ());
2022-06-20 05:36:27 +12:00
continue;
}
controllers[event.cdevice.which] = controller;
break;
case SDL_CONTROLLERDEVICEREMOVED:
2022-06-20 07:17:39 +12:00
if (!SDL_IsGameController (event.cdevice.which)) break;
2022-06-20 05:36:27 +12:00
SDL_GameControllerClose (controllers[event.cdevice.which]);
break;
case SDL_MOUSEWHEEL:
2022-06-20 07:17:39 +12:00
if (event.wheel.y > 0) currentMouseState.ScrolledUp = true;
else if (event.wheel.y < 0) currentMouseState.ScrolledDown = true;
2022-06-20 05:36:27 +12:00
break;
case SDL_CONTROLLERBUTTONUP:
2022-06-20 07:17:39 +12:00
case SDL_CONTROLLERBUTTONDOWN: currentControllerButtonsState[event.cbutton.button] = event.cbutton.state; break;
2022-06-20 05:36:27 +12:00
case SDL_CONTROLLERAXISMOTION:
if (event.caxis.value > 8000) {
switch (event.caxis.axis) {
2022-06-20 07:17:39 +12:00
case SDL_CONTROLLER_AXIS_LEFTX: currentControllerAxisState.LeftRight = 1; break;
case SDL_CONTROLLER_AXIS_LEFTY: currentControllerAxisState.LeftDown = 1; break;
case SDL_CONTROLLER_AXIS_RIGHTX: currentControllerAxisState.RightRight = 1; break;
case SDL_CONTROLLER_AXIS_RIGHTY: currentControllerAxisState.RightDown = 1; break;
case SDL_CONTROLLER_AXIS_TRIGGERLEFT: currentControllerAxisState.LTriggerDown = 1; break;
case SDL_CONTROLLER_AXIS_TRIGGERRIGHT: currentControllerAxisState.RTriggerDown = 1; break;
2022-06-20 05:36:27 +12:00
}
} else if (event.caxis.value < -8000) {
switch (event.caxis.axis) {
2022-06-20 07:17:39 +12:00
case SDL_CONTROLLER_AXIS_LEFTX: currentControllerAxisState.LeftLeft = 1; break;
case SDL_CONTROLLER_AXIS_LEFTY: currentControllerAxisState.LeftUp = 1; break;
case SDL_CONTROLLER_AXIS_RIGHTX: currentControllerAxisState.RightLeft = 1; break;
case SDL_CONTROLLER_AXIS_RIGHTY: currentControllerAxisState.RightUp = 1; break;
2022-06-20 05:36:27 +12:00
}
} else {
switch (event.caxis.axis) {
case SDL_CONTROLLER_AXIS_LEFTX:
currentControllerAxisState.LeftRight = 0;
2022-06-20 07:17:39 +12:00
currentControllerAxisState.LeftLeft = 0;
2022-06-20 05:36:27 +12:00
break;
case SDL_CONTROLLER_AXIS_LEFTY:
currentControllerAxisState.LeftDown = 0;
2022-06-20 07:17:39 +12:00
currentControllerAxisState.LeftUp = 0;
2022-06-20 05:36:27 +12:00
break;
case SDL_CONTROLLER_AXIS_RIGHTX:
currentControllerAxisState.RightRight = 0;
2022-06-20 07:17:39 +12:00
currentControllerAxisState.RightLeft = 0;
2022-06-20 05:36:27 +12:00
break;
case SDL_CONTROLLER_AXIS_RIGHTY:
currentControllerAxisState.RightDown = 0;
2022-06-20 07:17:39 +12:00
currentControllerAxisState.RightUp = 0;
2022-06-20 05:36:27 +12:00
break;
2022-06-20 07:17:39 +12:00
case SDL_CONTROLLER_AXIS_TRIGGERLEFT: currentControllerAxisState.LTriggerDown = 0; break;
case SDL_CONTROLLER_AXIS_TRIGGERRIGHT: currentControllerAxisState.RTriggerDown = 0; break;
2022-06-20 05:36:27 +12:00
}
}
break;
}
}
}
void
DisposePoll () {
SDL_DestroyWindow (window);
SDL_Quit ();
}
struct ConfigValue
StringToConfigEnum (char *value) {
struct ConfigValue rval = { 0 };
for (int i = 0; i < COUNTOFARR (ConfigKeyboardButtons); ++i)
if (!strcmp (value, ConfigKeyboardButtons[i].string)) {
2022-06-20 07:17:39 +12:00
rval.type = keycode;
2022-06-20 05:36:27 +12:00
rval.keycode = ConfigKeyboardButtons[i].keycode;
return rval;
}
for (int i = 0; i < COUNTOFARR (ConfigControllerButtons); ++i)
if (!strcmp (value, ConfigControllerButtons[i].string)) {
2022-06-20 07:17:39 +12:00
rval.type = button;
2022-06-20 05:36:27 +12:00
rval.button = ConfigControllerButtons[i].button;
return rval;
}
for (int i = 0; i < COUNTOFARR (ConfigControllerAXIS); ++i)
if (!strcmp (value, ConfigControllerAXIS[i].string)) {
rval.type = axis;
rval.axis = ConfigControllerAXIS[i].axis;
return rval;
}
for (int i = 0; i < COUNTOFARR (ConfigMouseScroll); ++i)
if (!strcmp (value, ConfigMouseScroll[i].string)) {
2022-06-20 07:17:39 +12:00
rval.type = scroll;
2022-06-20 05:36:27 +12:00
rval.scroll = ConfigMouseScroll[i].scroll;
return rval;
}
printError ("%s (%s): Unknown value\n", __func__, value);
return rval;
}
struct InternalButtonState
GetInternalButtonState (struct Keybindings bindings) {
struct InternalButtonState buttons = { 0 };
for (int i = 0; i < COUNTOFARR (ConfigKeyboardButtons); i++) {
2022-06-20 07:17:39 +12:00
if (bindings.keycodes[i] == 0) continue;
if (KeyboardIsReleased (bindings.keycodes[i])) buttons.Released = 1;
if (KeyboardIsDown (bindings.keycodes[i])) buttons.Down = 1;
if (KeyboardIsTapped (bindings.keycodes[i])) buttons.Tapped = 1;
2022-06-20 05:36:27 +12:00
}
for (int i = 0; i < COUNTOFARR (ConfigControllerButtons); i++) {
2022-06-20 07:17:39 +12:00
if (bindings.buttons[i] == SDL_CONTROLLER_BUTTON_INVALID) continue;
if (ControllerButtonIsReleased (bindings.buttons[i])) buttons.Released = 1;
if (ControllerButtonIsDown (bindings.buttons[i])) buttons.Down = 1;
if (ControllerButtonIsTapped (bindings.buttons[i])) buttons.Tapped = 1;
2022-06-20 05:36:27 +12:00
}
for (int i = 0; i < COUNTOFARR (ConfigControllerAXIS); i++) {
2022-06-20 07:17:39 +12:00
if (bindings.axis[i] == 0) continue;
if (ControllerAxisIsReleased (bindings.axis[i])) buttons.Released = 1;
if (ControllerAxisIsDown (bindings.axis[i])) buttons.Down = 1;
if (ControllerAxisIsTapped (bindings.axis[i])) buttons.Tapped = 1;
2022-06-20 05:36:27 +12:00
}
for (int i = 0; i < COUNTOFARR (ConfigMouseScroll); i++) {
2022-06-20 07:17:39 +12:00
if (bindings.scroll[i] == 0) continue;
if (GetMouseScrollIsReleased (bindings.scroll[i])) buttons.Released = 1;
if (GetMouseScrollIsDown (bindings.scroll[i])) buttons.Down = 1;
if (GetMouseScrollIsTapped (bindings.scroll[i])) buttons.Tapped = 1;
2022-06-20 05:36:27 +12:00
}
return buttons;
}
void
SetRumble (int left, int right) {
for (int i = 0; i < COUNTOFARR (controllers); i++) {
2022-06-20 07:17:39 +12:00
if (!controllers[i] || !SDL_GameControllerHasRumble (controllers[i])) continue;
2022-06-20 05:36:27 +12:00
SDL_GameControllerRumble (controllers[i], left, right, 1000);
}
}
inline bool
KeyboardIsDown (uint8_t keycode) {
return currentKeyboardState[keycode];
}
inline bool
KeyboardIsUp (uint8_t keycode) {
return !KeyboardIsDown (keycode);
}
inline bool
KeyboardIsTapped (uint8_t keycode) {
return KeyboardIsDown (keycode) && KeyboardWasUp (keycode);
}
inline bool
KeyboardIsReleased (uint8_t keycode) {
return KeyboardIsUp (keycode) && KeyboardWasDown (keycode);
}
inline bool
KeyboardWasDown (uint8_t keycode) {
return lastKeyboardState[keycode];
}
inline bool
KeyboardWasUp (uint8_t keycode) {
return !KeyboardWasDown (keycode);
}
inline POINT
GetMousePosition () {
return currentMouseState.Position;
}
inline POINT
GetLastMousePosition () {
return lastMouseState.Position;
}
inline POINT
GetMouseRelativePosition () {
return currentMouseState.RelativePosition;
}
inline POINT
GetLastMouseRelativePosition () {
return lastMouseState.RelativePosition;
}
inline void
SetMousePosition (POINT new) {
currentMouseState.Position = new;
}
inline bool
GetMouseScrollUp () {
return currentMouseState.ScrolledUp;
}
inline bool
GetMouseScrollDown () {
return currentMouseState.ScrolledDown;
}
inline bool
GetWasMouseScrollUp () {
return lastMouseState.ScrolledUp;
}
inline bool
GetWasMouseScrollDown () {
return lastMouseState.ScrolledDown;
}
inline bool
GetMouseScrollIsReleased (enum Scroll scroll) {
2022-06-20 07:17:39 +12:00
if (scroll == MOUSE_SCROLL_UP) return !GetMouseScrollUp () && GetWasMouseScrollUp ();
else return !GetMouseScrollDown () && GetWasMouseScrollDown ();
2022-06-20 05:36:27 +12:00
}
inline bool
GetMouseScrollIsDown (enum Scroll scroll) {
2022-06-20 07:17:39 +12:00
if (scroll == MOUSE_SCROLL_UP) return GetMouseScrollUp ();
else return GetMouseScrollDown ();
2022-06-20 05:36:27 +12:00
}
inline bool
GetMouseScrollIsTapped (enum Scroll scroll) {
2022-06-20 07:17:39 +12:00
if (scroll == MOUSE_SCROLL_UP) return GetMouseScrollUp () && !GetWasMouseScrollUp ();
else return GetMouseScrollDown () && !GetWasMouseScrollDown ();
2022-06-20 05:36:27 +12:00
}
inline bool
ControllerButtonIsDown (SDL_GameControllerButton button) {
return currentControllerButtonsState[button];
}
inline bool
ControllerButtonIsUp (SDL_GameControllerButton button) {
return !ControllerButtonIsDown (button);
}
inline bool
ControllerButtonWasDown (SDL_GameControllerButton button) {
return lastControllerButtonsState[button];
}
inline bool
ControllerButtonWasUp (SDL_GameControllerButton button) {
return !ControllerButtonWasDown (button);
}
inline bool
ControllerButtonIsTapped (SDL_GameControllerButton button) {
return ControllerButtonIsDown (button) && ControllerButtonWasUp (button);
}
inline bool
ControllerButtonIsReleased (SDL_GameControllerButton button) {
return ControllerButtonIsUp (button) && ControllerButtonWasDown (button);
}
inline bool
ControllerAxisIsDown (enum SDLAxis axis) {
switch (axis) {
2022-06-20 07:17:39 +12:00
case SDL_AXIS_LEFT_LEFT: return currentControllerAxisState.LeftLeft;
case SDL_AXIS_LEFT_RIGHT: return currentControllerAxisState.LeftRight;
case SDL_AXIS_LEFT_UP: return currentControllerAxisState.LeftUp;
case SDL_AXIS_LEFT_DOWN: return currentControllerAxisState.LeftDown;
case SDL_AXIS_RIGHT_LEFT: return currentControllerAxisState.RightLeft;
case SDL_AXIS_RIGHT_RIGHT: return currentControllerAxisState.RightRight;
case SDL_AXIS_RIGHT_UP: return currentControllerAxisState.RightUp;
case SDL_AXIS_RIGHT_DOWN: return currentControllerAxisState.RightDown;
case SDL_AXIS_LTRIGGER_DOWN: return currentControllerAxisState.LTriggerDown;
case SDL_AXIS_RTRIGGER_DOWN: return currentControllerAxisState.RTriggerDown;
2022-06-20 05:36:27 +12:00
case SDL_AXIS_NULL:
2022-06-20 07:17:39 +12:00
case SDL_AXIS_MAX: return false;
2022-06-20 05:36:27 +12:00
}
}
inline bool
ControllerAxisIsUp (enum SDLAxis axis) {
return !ControllerAxisIsDown (axis);
}
inline bool
ControllerAxisWasDown (enum SDLAxis axis) {
switch (axis) {
2022-06-20 07:17:39 +12:00
case SDL_AXIS_LEFT_LEFT: return lastControllerAxisState.LeftLeft;
case SDL_AXIS_LEFT_RIGHT: return lastControllerAxisState.LeftRight;
case SDL_AXIS_LEFT_UP: return lastControllerAxisState.LeftUp;
case SDL_AXIS_LEFT_DOWN: return lastControllerAxisState.LeftDown;
case SDL_AXIS_RIGHT_LEFT: return lastControllerAxisState.RightLeft;
case SDL_AXIS_RIGHT_RIGHT: return lastControllerAxisState.RightRight;
case SDL_AXIS_RIGHT_UP: return lastControllerAxisState.RightUp;
case SDL_AXIS_RIGHT_DOWN: return lastControllerAxisState.RightDown;
case SDL_AXIS_LTRIGGER_DOWN: return lastControllerAxisState.LTriggerDown;
case SDL_AXIS_RTRIGGER_DOWN: return lastControllerAxisState.RTriggerDown;
2022-06-20 05:36:27 +12:00
case SDL_AXIS_NULL:
2022-06-20 07:17:39 +12:00
case SDL_AXIS_MAX: return false;
2022-06-20 05:36:27 +12:00
}
}
inline bool
ControllerAxisWasUp (enum SDLAxis axis) {
return !ControllerAxisWasDown (axis);
}
inline bool
ControllerAxisIsTapped (enum SDLAxis axis) {
return ControllerAxisIsDown (axis) && ControllerAxisWasUp (axis);
}
inline bool
ControllerAxisIsReleased (enum SDLAxis axis) {
return ControllerAxisIsUp (axis) && ControllerAxisWasDown (axis);
}
inline bool
IsButtonTapped (struct Keybindings bindings) {
return GetInternalButtonState (bindings).Tapped;
}
inline bool
IsButtonReleased (struct Keybindings bindings) {
return GetInternalButtonState (bindings).Released;
}
inline bool
IsButtonDown (struct Keybindings bindings) {
return GetInternalButtonState (bindings).Down;
}