diff --git a/src/tr1/specific/s_input.c b/src/tr1/specific/s_input.c index 02ecb0651..a7ae2a5c5 100644 --- a/src/tr1/specific/s_input.c +++ b/src/tr1/specific/s_input.c @@ -14,363 +14,115 @@ #define KEY_DOWN(a) (m_KeyboardState[(a)]) -typedef union BIND_TYPE { - SDL_GameControllerButton button; - SDL_GameControllerAxis axis; -} BIND_TYPE; - typedef struct { BUTTON_TYPE type; - BIND_TYPE bind; + union { + SDL_GameControllerButton button; + SDL_GameControllerAxis axis; + } bind; int16_t axis_dir; } CONTROLLER_MAP; -static INPUT_SCANCODE m_Layout[INPUT_LAYOUT_NUMBER_OF][INPUT_ROLE_NUMBER_OF] = { +typedef struct { + INPUT_ROLE role; + INPUT_SCANCODE scancode; +} BUILTIN_KEYBOARD_LAYOUT; + +typedef struct { + INPUT_ROLE role; + CONTROLLER_MAP map; +} BUILTIN_CONTROLLER_LAYOUT; + +static BUILTIN_KEYBOARD_LAYOUT m_BuiltinKeyboardLayout[] = { // clang-format off - // built-in controls - { - SDL_SCANCODE_UP, // INPUT_ROLE_UP - SDL_SCANCODE_DOWN, // INPUT_ROLE_DOWN - SDL_SCANCODE_LEFT, // INPUT_ROLE_LEFT - SDL_SCANCODE_RIGHT, // INPUT_ROLE_RIGHT - SDL_SCANCODE_DELETE, // INPUT_ROLE_STEP_L - SDL_SCANCODE_PAGEDOWN, // INPUT_ROLE_STEP_R - SDL_SCANCODE_RSHIFT, // INPUT_ROLE_SLOW - SDL_SCANCODE_RALT, // INPUT_ROLE_JUMP - SDL_SCANCODE_RCTRL, // INPUT_ROLE_ACTION - SDL_SCANCODE_SPACE, // INPUT_ROLE_DRAW - SDL_SCANCODE_KP_0, // INPUT_ROLE_LOOK - SDL_SCANCODE_END, // INPUT_ROLE_ROLL - SDL_SCANCODE_ESCAPE, // INPUT_ROLE_OPTION - SDL_SCANCODE_O, // INPUT_ROLE_FLY_CHEAT, - SDL_SCANCODE_I, // INPUT_ROLE_ITEM_CHEAT, - SDL_SCANCODE_L, // INPUT_ROLE_LEVEL_SKIP_CHEAT, - SDL_SCANCODE_TAB, // INPUT_ROLE_TURBO_CHEAT, - SDL_SCANCODE_P, // INPUT_ROLE_PAUSE, - SDL_SCANCODE_W, // INPUT_ROLE_CAMERA_FORWARD - SDL_SCANCODE_S, // INPUT_ROLE_CAMERA_BACK - SDL_SCANCODE_A, // INPUT_ROLE_CAMERA_LEFT - SDL_SCANCODE_D, // INPUT_ROLE_CAMERA_RIGHT - 0, // padding - SDL_SCANCODE_1, // INPUT_ROLE_EQUIP_PISTOLS - SDL_SCANCODE_2, // INPUT_ROLE_EQUIP_SHOTGUN - SDL_SCANCODE_3, // INPUT_ROLE_EQUIP_MAGNUMS - SDL_SCANCODE_4, // INPUT_ROLE_EQUIP_UZIS - SDL_SCANCODE_8, // INPUT_ROLE_USE_SMALL_MEDI - SDL_SCANCODE_9, // INPUT_ROLE_USE_BIG_MEDI - SDL_SCANCODE_F5, // INPUT_ROLE_SAVE - SDL_SCANCODE_F6, // INPUT_ROLE_LOAD - SDL_SCANCODE_F2, // INPUT_ROLE_FPS - SDL_SCANCODE_F3, // INPUT_ROLE_BILINEAR - SDL_SCANCODE_SLASH, // INPUT_ROLE_ENTER_CONSOLE - SDL_SCANCODE_Z, // INPUT_ROLE_CHANGE_TARGET - SDL_SCANCODE_H, // INPUT_ROLE_TOGGLE_UI - SDL_SCANCODE_Q, // INPUT_ROLE_CAMERA_UP - SDL_SCANCODE_E, // INPUT_ROLE_CAMERA_DOWN - SDL_SCANCODE_F1, // INPUT_ROLE_TOGGLE_PHOTO_MODE - }, - - // custom user controls - { - SDL_SCANCODE_UP, // INPUT_ROLE_UP - SDL_SCANCODE_DOWN, // INPUT_ROLE_DOWN - SDL_SCANCODE_LEFT, // INPUT_ROLE_LEFT - SDL_SCANCODE_RIGHT, // INPUT_ROLE_RIGHT - SDL_SCANCODE_DELETE, // INPUT_ROLE_STEP_L - SDL_SCANCODE_PAGEDOWN, // INPUT_ROLE_STEP_R - SDL_SCANCODE_RSHIFT, // INPUT_ROLE_SLOW - SDL_SCANCODE_RALT, // INPUT_ROLE_JUMP - SDL_SCANCODE_RCTRL, // INPUT_ROLE_ACTION - SDL_SCANCODE_SPACE, // INPUT_ROLE_DRAW - SDL_SCANCODE_KP_0, // INPUT_ROLE_LOOK - SDL_SCANCODE_END, // INPUT_ROLE_ROLL - SDL_SCANCODE_ESCAPE, // INPUT_ROLE_OPTION - SDL_SCANCODE_O, // INPUT_ROLE_FLY_CHEAT, - SDL_SCANCODE_I, // INPUT_ROLE_ITEM_CHEAT, - SDL_SCANCODE_L, // INPUT_ROLE_LEVEL_SKIP_CHEAT, - SDL_SCANCODE_TAB, // INPUT_ROLE_TURBO_CHEAT, - SDL_SCANCODE_P, // INPUT_ROLE_PAUSE, - SDL_SCANCODE_W, // INPUT_ROLE_CAMERA_FORWARD - SDL_SCANCODE_S, // INPUT_ROLE_CAMERA_BACK - SDL_SCANCODE_A, // INPUT_ROLE_CAMERA_LEFT - SDL_SCANCODE_D, // INPUT_ROLE_CAMERA_RIGHT - 0, // padding - SDL_SCANCODE_1, // INPUT_ROLE_EQUIP_PISTOLS - SDL_SCANCODE_2, // INPUT_ROLE_EQUIP_SHOTGUN - SDL_SCANCODE_3, // INPUT_ROLE_EQUIP_MAGNUMS - SDL_SCANCODE_4, // INPUT_ROLE_EQUIP_UZIS - SDL_SCANCODE_8, // INPUT_ROLE_USE_SMALL_MEDI - SDL_SCANCODE_9, // INPUT_ROLE_USE_BIG_MEDI - SDL_SCANCODE_F5, // INPUT_ROLE_SAVE - SDL_SCANCODE_F6, // INPUT_ROLE_LOAD - SDL_SCANCODE_F2, // INPUT_ROLE_FPS - SDL_SCANCODE_F3, // INPUT_ROLE_BILINEAR - SDL_SCANCODE_SLASH, // INPUT_ROLE_ENTER_CONSOLE - SDL_SCANCODE_Z, // INPUT_ROLE_CHANGE_TARGET - SDL_SCANCODE_H, // INPUT_ROLE_TOGGLE_UI - SDL_SCANCODE_Q, // INPUT_ROLE_CAMERA_UP - SDL_SCANCODE_E, // INPUT_ROLE_CAMERA_DOWN - SDL_SCANCODE_F1, // INPUT_ROLE_TOGGLE_PHOTO_MODE - }, - - { - SDL_SCANCODE_UP, // INPUT_ROLE_UP - SDL_SCANCODE_DOWN, // INPUT_ROLE_DOWN - SDL_SCANCODE_LEFT, // INPUT_ROLE_LEFT - SDL_SCANCODE_RIGHT, // INPUT_ROLE_RIGHT - SDL_SCANCODE_DELETE, // INPUT_ROLE_STEP_L - SDL_SCANCODE_PAGEDOWN, // INPUT_ROLE_STEP_R - SDL_SCANCODE_RSHIFT, // INPUT_ROLE_SLOW - SDL_SCANCODE_RALT, // INPUT_ROLE_JUMP - SDL_SCANCODE_RCTRL, // INPUT_ROLE_ACTION - SDL_SCANCODE_SPACE, // INPUT_ROLE_DRAW - SDL_SCANCODE_KP_0, // INPUT_ROLE_LOOK - SDL_SCANCODE_END, // INPUT_ROLE_ROLL - SDL_SCANCODE_ESCAPE, // INPUT_ROLE_OPTION - SDL_SCANCODE_O, // INPUT_ROLE_FLY_CHEAT, - SDL_SCANCODE_I, // INPUT_ROLE_ITEM_CHEAT, - SDL_SCANCODE_L, // INPUT_ROLE_LEVEL_SKIP_CHEAT, - SDL_SCANCODE_TAB, // INPUT_ROLE_TURBO_CHEAT, - SDL_SCANCODE_P, // INPUT_ROLE_PAUSE, - SDL_SCANCODE_W, // INPUT_ROLE_CAMERA_FORWARD - SDL_SCANCODE_S, // INPUT_ROLE_CAMERA_BACK - SDL_SCANCODE_A, // INPUT_ROLE_CAMERA_LEFT - SDL_SCANCODE_D, // INPUT_ROLE_CAMERA_RIGHT - 0, // padding - SDL_SCANCODE_1, // INPUT_ROLE_EQUIP_PISTOLS - SDL_SCANCODE_2, // INPUT_ROLE_EQUIP_SHOTGUN - SDL_SCANCODE_3, // INPUT_ROLE_EQUIP_MAGNUMS - SDL_SCANCODE_4, // INPUT_ROLE_EQUIP_UZIS - SDL_SCANCODE_8, // INPUT_ROLE_USE_SMALL_MEDI - SDL_SCANCODE_9, // INPUT_ROLE_USE_BIG_MEDI - SDL_SCANCODE_F5, // INPUT_ROLE_SAVE - SDL_SCANCODE_F6, // INPUT_ROLE_LOAD - SDL_SCANCODE_F2, // INPUT_ROLE_FPS - SDL_SCANCODE_F3, // INPUT_ROLE_BILINEAR - SDL_SCANCODE_SLASH, // INPUT_ROLE_ENTER_CONSOLE - SDL_SCANCODE_Z, // INPUT_ROLE_CHANGE_TARGET - SDL_SCANCODE_H, // INPUT_ROLE_TOGGLE_UI - SDL_SCANCODE_Q, // INPUT_ROLE_CAMERA_UP - SDL_SCANCODE_E, // INPUT_ROLE_CAMERA_DOWN - SDL_SCANCODE_F1, // INPUT_ROLE_TOGGLE_PHOTO_MODE - }, - - { - SDL_SCANCODE_UP, // INPUT_ROLE_UP - SDL_SCANCODE_DOWN, // INPUT_ROLE_DOWN - SDL_SCANCODE_LEFT, // INPUT_ROLE_LEFT - SDL_SCANCODE_RIGHT, // INPUT_ROLE_RIGHT - SDL_SCANCODE_DELETE, // INPUT_ROLE_STEP_L - SDL_SCANCODE_PAGEDOWN, // INPUT_ROLE_STEP_R - SDL_SCANCODE_RSHIFT, // INPUT_ROLE_SLOW - SDL_SCANCODE_RALT, // INPUT_ROLE_JUMP - SDL_SCANCODE_RCTRL, // INPUT_ROLE_ACTION - SDL_SCANCODE_SPACE, // INPUT_ROLE_DRAW - SDL_SCANCODE_KP_0, // INPUT_ROLE_LOOK - SDL_SCANCODE_END, // INPUT_ROLE_ROLL - SDL_SCANCODE_ESCAPE, // INPUT_ROLE_OPTION - SDL_SCANCODE_O, // INPUT_ROLE_FLY_CHEAT, - SDL_SCANCODE_I, // INPUT_ROLE_ITEM_CHEAT, - SDL_SCANCODE_L, // INPUT_ROLE_LEVEL_SKIP_CHEAT, - SDL_SCANCODE_TAB, // INPUT_ROLE_TURBO_CHEAT, - SDL_SCANCODE_P, // INPUT_ROLE_PAUSE, - SDL_SCANCODE_W, // INPUT_ROLE_CAMERA_FORWARD - SDL_SCANCODE_S, // INPUT_ROLE_CAMERA_BACK - SDL_SCANCODE_A, // INPUT_ROLE_CAMERA_LEFT - SDL_SCANCODE_D, // INPUT_ROLE_CAMERA_RIGHT - 0, // padding - SDL_SCANCODE_1, // INPUT_ROLE_EQUIP_PISTOLS - SDL_SCANCODE_2, // INPUT_ROLE_EQUIP_SHOTGUN - SDL_SCANCODE_3, // INPUT_ROLE_EQUIP_MAGNUMS - SDL_SCANCODE_4, // INPUT_ROLE_EQUIP_UZIS - SDL_SCANCODE_8, // INPUT_ROLE_USE_SMALL_MEDI - SDL_SCANCODE_9, // INPUT_ROLE_USE_BIG_MEDI - SDL_SCANCODE_F5, // INPUT_ROLE_SAVE - SDL_SCANCODE_F6, // INPUT_ROLE_LOAD - SDL_SCANCODE_F2, // INPUT_ROLE_FPS - SDL_SCANCODE_F3, // INPUT_ROLE_BILINEAR - SDL_SCANCODE_SLASH, // INPUT_ROLE_ENTER_CONSOLE - SDL_SCANCODE_Z, // INPUT_ROLE_CHANGE_TARGET - SDL_SCANCODE_H, // INPUT_ROLE_TOGGLE_UI - SDL_SCANCODE_Q, // INPUT_ROLE_CAMERA_UP - SDL_SCANCODE_E, // INPUT_ROLE_CAMERA_DOWN - SDL_SCANCODE_F1, // INPUT_ROLE_TOGGLE_PHOTO_MODE - } + { INPUT_ROLE_UP, SDL_SCANCODE_UP }, + { INPUT_ROLE_DOWN, SDL_SCANCODE_DOWN }, + { INPUT_ROLE_LEFT, SDL_SCANCODE_LEFT }, + { INPUT_ROLE_RIGHT, SDL_SCANCODE_RIGHT }, + { INPUT_ROLE_STEP_L, SDL_SCANCODE_DELETE }, + { INPUT_ROLE_STEP_R, SDL_SCANCODE_PAGEDOWN }, + { INPUT_ROLE_SLOW, SDL_SCANCODE_RSHIFT }, + { INPUT_ROLE_JUMP, SDL_SCANCODE_RALT }, + { INPUT_ROLE_ACTION, SDL_SCANCODE_RCTRL }, + { INPUT_ROLE_DRAW, SDL_SCANCODE_SPACE }, + { INPUT_ROLE_LOOK, SDL_SCANCODE_KP_0 }, + { INPUT_ROLE_ROLL, SDL_SCANCODE_END }, + { INPUT_ROLE_OPTION, SDL_SCANCODE_ESCAPE }, + { INPUT_ROLE_FLY_CHEAT, SDL_SCANCODE_O }, + { INPUT_ROLE_ITEM_CHEAT, SDL_SCANCODE_I }, + { INPUT_ROLE_LEVEL_SKIP_CHEAT, SDL_SCANCODE_L }, + { INPUT_ROLE_TURBO_CHEAT, SDL_SCANCODE_TAB }, + { INPUT_ROLE_PAUSE, SDL_SCANCODE_P }, + { INPUT_ROLE_CAMERA_FORWARD, SDL_SCANCODE_W }, + { INPUT_ROLE_CAMERA_BACK, SDL_SCANCODE_S }, + { INPUT_ROLE_CAMERA_LEFT, SDL_SCANCODE_A }, + { INPUT_ROLE_CAMERA_RIGHT, SDL_SCANCODE_D }, + { INPUT_ROLE_EQUIP_PISTOLS, SDL_SCANCODE_1 }, + { INPUT_ROLE_EQUIP_SHOTGUN, SDL_SCANCODE_2 }, + { INPUT_ROLE_EQUIP_MAGNUMS, SDL_SCANCODE_3 }, + { INPUT_ROLE_EQUIP_UZIS, SDL_SCANCODE_4 }, + { INPUT_ROLE_USE_SMALL_MEDI, SDL_SCANCODE_8 }, + { INPUT_ROLE_USE_BIG_MEDI, SDL_SCANCODE_9 }, + { INPUT_ROLE_SAVE, SDL_SCANCODE_F5 }, + { INPUT_ROLE_LOAD, SDL_SCANCODE_F6 }, + { INPUT_ROLE_FPS, SDL_SCANCODE_F2 }, + { INPUT_ROLE_BILINEAR, SDL_SCANCODE_F3 }, + { INPUT_ROLE_ENTER_CONSOLE, SDL_SCANCODE_SLASH }, + { INPUT_ROLE_CHANGE_TARGET, SDL_SCANCODE_Z }, + { INPUT_ROLE_TOGGLE_UI, SDL_SCANCODE_H }, + { INPUT_ROLE_CAMERA_UP, SDL_SCANCODE_Q }, + { INPUT_ROLE_CAMERA_DOWN, SDL_SCANCODE_E }, + { INPUT_ROLE_TOGGLE_PHOTO_MODE, SDL_SCANCODE_F1 }, + { -1, SDL_SCANCODE_UNKNOWN }, // clang-format on }; -static CONTROLLER_MAP - m_ControllerLayout[INPUT_LAYOUT_NUMBER_OF][INPUT_ROLE_NUMBER_OF] = { - // clang-format off - { - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_DPAD_UP}, 0 }, // INPUT_ROLE_UP - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_DPAD_DOWN}, 0 }, // INPUT_ROLE_DOWN - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_DPAD_LEFT}, 0 }, // INPUT_ROLE_LEFT - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_DPAD_RIGHT}, 0 }, // INPUT_ROLE_RIGHT - { BT_AXIS, {SDL_CONTROLLER_AXIS_TRIGGERLEFT}, 1 }, // INPUT_ROLE_STEP_L - { BT_AXIS, {SDL_CONTROLLER_AXIS_TRIGGERRIGHT}, 1 }, // INPUT_ROLE_STEP_R - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_RIGHTSHOULDER}, 0 }, // INPUT_ROLE_SLOW - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_X}, 0 }, // INPUT_ROLE_JUMP - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_A}, 0 }, // INPUT_ROLE_ACTION - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_Y}, 0 }, // INPUT_ROLE_DRAW - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_LEFTSHOULDER}, 0 }, // INPUT_ROLE_LOOK - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_B}, 0 }, // INPUT_ROLE_ROLL - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_BACK}, 0 }, // INPUT_ROLE_OPTION - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_FLY_CHEAT, - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_ITEM_CHEAT, - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_LEVEL_SKIP_CHEAT, - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_TURBO_CHEAT, - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_START}, 0 }, // INPUT_ROLE_PAUSE, - { BT_AXIS, {SDL_CONTROLLER_AXIS_RIGHTY}, -1 }, // INPUT_ROLE_CAMERA_FORWARD - { BT_AXIS, {SDL_CONTROLLER_AXIS_RIGHTY}, 1 }, // INPUT_ROLE_CAMERA_BACK - { BT_AXIS, {SDL_CONTROLLER_AXIS_RIGHTX}, -1 }, // INPUT_ROLE_CAMERA_LEFT - { BT_AXIS, {SDL_CONTROLLER_AXIS_RIGHTX}, 1 }, // INPUT_ROLE_CAMERA_RIGHT - { 0, {0}, 0 }, // padding - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_EQUIP_PISTOLS - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_EQUIP_SHOTGUN - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_EQUIP_MAGNUMS - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_EQUIP_UZIS - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_USE_SMALL_MEDI - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_USE_BIG_MEDI - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_SAVE - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_LOAD - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_FPS - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_BILINEAR - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_ENTER_CONSOLE - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_LEFTSTICK}, 0 }, // INPUT_ROLE_CHANGE_TARGET - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_TOGGLE_UI - { BT_AXIS, {SDL_CONTROLLER_AXIS_LEFTY}, -1 }, // INPUT_ROLE_CAMERA_UP - { BT_AXIS, {SDL_CONTROLLER_AXIS_LEFTY}, 1 }, // INPUT_ROLE_CAMERA_DOWN - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_TOGGLE_PHOTO_MODE - }, - - { - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_DPAD_UP}, 0 }, // INPUT_ROLE_UP - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_DPAD_DOWN}, 0 }, // INPUT_ROLE_DOWN - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_DPAD_LEFT}, 0 }, // INPUT_ROLE_LEFT - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_DPAD_RIGHT}, 0 }, // INPUT_ROLE_RIGHT - { BT_AXIS, {SDL_CONTROLLER_AXIS_TRIGGERLEFT}, 1 }, // INPUT_ROLE_STEP_L - { BT_AXIS, {SDL_CONTROLLER_AXIS_TRIGGERRIGHT}, 1 }, // INPUT_ROLE_STEP_R - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_RIGHTSHOULDER}, 0 }, // INPUT_ROLE_SLOW - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_X}, 0 }, // INPUT_ROLE_JUMP - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_A}, 0 }, // INPUT_ROLE_ACTION - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_Y}, 0 }, // INPUT_ROLE_DRAW - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_LEFTSHOULDER}, 0 }, // INPUT_ROLE_LOOK - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_B}, 0 }, // INPUT_ROLE_ROLL - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_BACK}, 0 }, // INPUT_ROLE_OPTION - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_FLY_CHEAT, - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_ITEM_CHEAT, - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_LEVEL_SKIP_CHEAT, - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_TURBO_CHEAT, - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_START}, 0 }, // INPUT_ROLE_PAUSE, - { BT_AXIS, {SDL_CONTROLLER_AXIS_RIGHTY}, -1 }, // INPUT_ROLE_CAMERA_FORWARD - { BT_AXIS, {SDL_CONTROLLER_AXIS_RIGHTY}, 1 }, // INPUT_ROLE_CAMERA_BACK - { BT_AXIS, {SDL_CONTROLLER_AXIS_RIGHTX}, -1 }, // INPUT_ROLE_CAMERA_LEFT - { BT_AXIS, {SDL_CONTROLLER_AXIS_RIGHTX}, 1 }, // INPUT_ROLE_CAMERA_RIGHT - { 0, {0}, 0 }, // padding - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_EQUIP_PISTOLS - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_EQUIP_SHOTGUN - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_EQUIP_MAGNUMS - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_EQUIP_UZIS - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_USE_SMALL_MEDI - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_USE_BIG_MEDI - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_SAVE - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_LOAD - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_FPS - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_BILINEAR - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_ENTER_CONSOLE - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_LEFTSTICK}, 0 }, // INPUT_ROLE_CHANGE_TARGET - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_TOGGLE_UI - { BT_AXIS, {SDL_CONTROLLER_AXIS_LEFTY}, -1 }, // INPUT_ROLE_CAMERA_UP - { BT_AXIS, {SDL_CONTROLLER_AXIS_LEFTY}, 1 }, // INPUT_ROLE_CAMERA_DOWN - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_TOGGLE_PHOTO_MODE - }, - - { - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_DPAD_UP}, 0 }, // INPUT_ROLE_UP - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_DPAD_DOWN}, 0 }, // INPUT_ROLE_DOWN - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_DPAD_LEFT}, 0 }, // INPUT_ROLE_LEFT - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_DPAD_RIGHT}, 0 }, // INPUT_ROLE_RIGHT - { BT_AXIS, {SDL_CONTROLLER_AXIS_TRIGGERLEFT}, 1 }, // INPUT_ROLE_STEP_L - { BT_AXIS, {SDL_CONTROLLER_AXIS_TRIGGERRIGHT}, 1 }, // INPUT_ROLE_STEP_R - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_RIGHTSHOULDER}, 0 }, // INPUT_ROLE_SLOW - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_X}, 0 }, // INPUT_ROLE_JUMP - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_A}, 0 }, // INPUT_ROLE_ACTION - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_Y}, 0 }, // INPUT_ROLE_DRAW - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_LEFTSHOULDER}, 0 }, // INPUT_ROLE_LOOK - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_B}, 0 }, // INPUT_ROLE_ROLL - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_BACK}, 0 }, // INPUT_ROLE_OPTION - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_FLY_CHEAT, - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_ITEM_CHEAT, - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_LEVEL_SKIP_CHEAT, - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_TURBO_CHEAT, - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_START}, 0 }, // INPUT_ROLE_PAUSE, - { BT_AXIS, {SDL_CONTROLLER_AXIS_RIGHTY}, -1 }, // INPUT_ROLE_CAMERA_FORWARD - { BT_AXIS, {SDL_CONTROLLER_AXIS_RIGHTY}, 1 }, // INPUT_ROLE_CAMERA_BACK - { BT_AXIS, {SDL_CONTROLLER_AXIS_RIGHTX}, -1 }, // INPUT_ROLE_CAMERA_LEFT - { BT_AXIS, {SDL_CONTROLLER_AXIS_RIGHTX}, 1 }, // INPUT_ROLE_CAMERA_RIGHT - { 0, {0}, 0 }, // padding - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_EQUIP_PISTOLS - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_EQUIP_SHOTGUN - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_EQUIP_MAGNUMS - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_EQUIP_UZIS - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_USE_SMALL_MEDI - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_USE_BIG_MEDI - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_SAVE - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_LOAD - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_FPS - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_BILINEAR - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_ENTER_CONSOLE - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_LEFTSTICK}, 0 }, // INPUT_ROLE_CHANGE_TARGET - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_TOGGLE_UI - { BT_AXIS, {SDL_CONTROLLER_AXIS_LEFTY}, -1 }, // INPUT_ROLE_CAMERA_UP - { BT_AXIS, {SDL_CONTROLLER_AXIS_LEFTY}, 1 }, // INPUT_ROLE_CAMERA_DOWN - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_TOGGLE_PHOTO_MODE - }, - - { - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_DPAD_UP}, 0 }, // INPUT_ROLE_UP - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_DPAD_DOWN}, 0 }, // INPUT_ROLE_DOWN - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_DPAD_LEFT}, 0 }, // INPUT_ROLE_LEFT - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_DPAD_RIGHT}, 0 }, // INPUT_ROLE_RIGHT - { BT_AXIS, {SDL_CONTROLLER_AXIS_TRIGGERLEFT}, 1 }, // INPUT_ROLE_STEP_L - { BT_AXIS, {SDL_CONTROLLER_AXIS_TRIGGERRIGHT}, 1 }, // INPUT_ROLE_STEP_R - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_RIGHTSHOULDER}, 0 }, // INPUT_ROLE_SLOW - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_X}, 0 }, // INPUT_ROLE_JUMP - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_A}, 0 }, // INPUT_ROLE_ACTION - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_Y}, 0 }, // INPUT_ROLE_DRAW - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_LEFTSHOULDER}, 0 }, // INPUT_ROLE_LOOK - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_B}, 0 }, // INPUT_ROLE_ROLL - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_BACK}, 0 }, // INPUT_ROLE_OPTION - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_FLY_CHEAT, - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_ITEM_CHEAT, - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_LEVEL_SKIP_CHEAT, - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_TURBO_CHEAT, - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_START}, 0 }, // INPUT_ROLE_PAUSE, - { BT_AXIS, {SDL_CONTROLLER_AXIS_RIGHTY}, -1 }, // INPUT_ROLE_CAMERA_FORWARD - { BT_AXIS, {SDL_CONTROLLER_AXIS_RIGHTY}, 1 }, // INPUT_ROLE_CAMERA_BACK - { BT_AXIS, {SDL_CONTROLLER_AXIS_RIGHTX}, -1 }, // INPUT_ROLE_CAMERA_LEFT - { BT_AXIS, {SDL_CONTROLLER_AXIS_RIGHTX}, 1 }, // INPUT_ROLE_CAMERA_RIGHT - { 0, {0}, 0 }, // padding - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_EQUIP_PISTOLS - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_EQUIP_SHOTGUN - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_EQUIP_MAGNUMS - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_EQUIP_UZIS - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_USE_SMALL_MEDI - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_USE_BIG_MEDI - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_SAVE - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_LOAD - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_FPS - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_BILINEAR - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_ENTER_CONSOLE - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_LEFTSTICK}, 0 }, // INPUT_ROLE_CHANGE_TARGET - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_TOGGLE_UI - { BT_AXIS, {SDL_CONTROLLER_AXIS_LEFTY}, -1 }, // INPUT_ROLE_CAMERA_UP - { BT_AXIS, {SDL_CONTROLLER_AXIS_LEFTY}, 1 }, // INPUT_ROLE_CAMERA_DOWN - { BT_BUTTON, {SDL_CONTROLLER_BUTTON_INVALID}, 0 }, // INPUT_ROLE_TOGGLE_PHOTO_MODE - } - // clang-format on - }; +static BUILTIN_CONTROLLER_LAYOUT m_BuiltinControllerLayout[] = { + // clang-format off + { INPUT_ROLE_UP, { BT_BUTTON, { SDL_CONTROLLER_BUTTON_DPAD_UP }, 0 } }, + { INPUT_ROLE_DOWN, { BT_BUTTON, { SDL_CONTROLLER_BUTTON_DPAD_DOWN }, 0 } }, + { INPUT_ROLE_LEFT, { BT_BUTTON, { SDL_CONTROLLER_BUTTON_DPAD_LEFT }, 0 } }, + { INPUT_ROLE_RIGHT, { BT_BUTTON, { SDL_CONTROLLER_BUTTON_DPAD_RIGHT }, 0 } }, + { INPUT_ROLE_STEP_L, { BT_AXIS, { SDL_CONTROLLER_AXIS_TRIGGERLEFT }, 1 } }, + { INPUT_ROLE_STEP_R, { BT_AXIS, { SDL_CONTROLLER_AXIS_TRIGGERRIGHT }, 1 } }, + { INPUT_ROLE_SLOW, { BT_BUTTON, { SDL_CONTROLLER_BUTTON_RIGHTSHOULDER }, 0 } }, + { INPUT_ROLE_JUMP, { BT_BUTTON, { SDL_CONTROLLER_BUTTON_X }, 0 } }, + { INPUT_ROLE_ACTION, { BT_BUTTON, { SDL_CONTROLLER_BUTTON_A }, 0 } }, + { INPUT_ROLE_DRAW, { BT_BUTTON, { SDL_CONTROLLER_BUTTON_Y }, 0 } }, + { INPUT_ROLE_LOOK, { BT_BUTTON, { SDL_CONTROLLER_BUTTON_LEFTSHOULDER }, 0 } }, + { INPUT_ROLE_ROLL, { BT_BUTTON, { SDL_CONTROLLER_BUTTON_B }, 0 } }, + { INPUT_ROLE_OPTION, { BT_BUTTON, { SDL_CONTROLLER_BUTTON_BACK }, 0 } }, + { INPUT_ROLE_FLY_CHEAT, { BT_BUTTON, { SDL_CONTROLLER_BUTTON_INVALID }, 0 } }, + { INPUT_ROLE_ITEM_CHEAT, { BT_BUTTON, { SDL_CONTROLLER_BUTTON_INVALID }, 0 } }, + { INPUT_ROLE_LEVEL_SKIP_CHEAT, { BT_BUTTON, { SDL_CONTROLLER_BUTTON_INVALID }, 0 } }, + { INPUT_ROLE_TURBO_CHEAT, { BT_BUTTON, { SDL_CONTROLLER_BUTTON_INVALID }, 0 } }, + { INPUT_ROLE_PAUSE, { BT_BUTTON, { SDL_CONTROLLER_BUTTON_START }, 0 } }, + { INPUT_ROLE_CAMERA_FORWARD, { BT_AXIS, { SDL_CONTROLLER_AXIS_RIGHTY }, -1 } }, + { INPUT_ROLE_CAMERA_BACK, { BT_AXIS, { SDL_CONTROLLER_AXIS_RIGHTY }, 1 } }, + { INPUT_ROLE_CAMERA_LEFT, { BT_AXIS, { SDL_CONTROLLER_AXIS_RIGHTX }, -1 } }, + { INPUT_ROLE_CAMERA_RIGHT, { BT_AXIS, { SDL_CONTROLLER_AXIS_RIGHTX }, 1 } }, + { INPUT_ROLE_EQUIP_PISTOLS, { BT_BUTTON, { SDL_CONTROLLER_BUTTON_INVALID }, 0 } }, + { INPUT_ROLE_EQUIP_SHOTGUN, { BT_BUTTON, { SDL_CONTROLLER_BUTTON_INVALID }, 0 } }, + { INPUT_ROLE_EQUIP_MAGNUMS, { BT_BUTTON, { SDL_CONTROLLER_BUTTON_INVALID }, 0 } }, + { INPUT_ROLE_EQUIP_UZIS, { BT_BUTTON, { SDL_CONTROLLER_BUTTON_INVALID }, 0 } }, + { INPUT_ROLE_USE_SMALL_MEDI, { BT_BUTTON, { SDL_CONTROLLER_BUTTON_INVALID }, 0 } }, + { INPUT_ROLE_USE_BIG_MEDI, { BT_BUTTON, { SDL_CONTROLLER_BUTTON_INVALID }, 0 } }, + { INPUT_ROLE_SAVE, { BT_BUTTON, { SDL_CONTROLLER_BUTTON_INVALID }, 0 } }, + { INPUT_ROLE_LOAD, { BT_BUTTON, { SDL_CONTROLLER_BUTTON_INVALID }, 0 } }, + { INPUT_ROLE_FPS, { BT_BUTTON, { SDL_CONTROLLER_BUTTON_INVALID }, 0 } }, + { INPUT_ROLE_BILINEAR, { BT_BUTTON, { SDL_CONTROLLER_BUTTON_INVALID }, 0 } }, + { INPUT_ROLE_ENTER_CONSOLE, { BT_BUTTON, { SDL_CONTROLLER_BUTTON_INVALID }, 0 } }, + { INPUT_ROLE_CHANGE_TARGET, { BT_BUTTON, { SDL_CONTROLLER_BUTTON_LEFTSTICK }, 0 } }, + { INPUT_ROLE_TOGGLE_UI, { BT_BUTTON, { SDL_CONTROLLER_BUTTON_INVALID }, 0 } }, + { INPUT_ROLE_CAMERA_UP, { BT_AXIS, { SDL_CONTROLLER_AXIS_LEFTY }, -1 } }, + { INPUT_ROLE_CAMERA_DOWN, { BT_AXIS, { SDL_CONTROLLER_AXIS_LEFTY }, 1 } }, + { INPUT_ROLE_TOGGLE_PHOTO_MODE, { BT_BUTTON, { SDL_CONTROLLER_BUTTON_INVALID }, 0 } }, + // clang-format on +}; + +static INPUT_SCANCODE m_Layout[INPUT_LAYOUT_NUMBER_OF][INPUT_ROLE_NUMBER_OF]; +static CONTROLLER_MAP m_ControllerLayout[INPUT_LAYOUT_NUMBER_OF] + [INPUT_ROLE_NUMBER_OF]; const Uint8 *m_KeyboardState; static SDL_GameController *m_Controller = NULL; @@ -865,50 +617,48 @@ static bool M_GetBindState(INPUT_ROLE role, INPUT_LAYOUT cntlr_layout_num) static INPUT_STATE M_GetControllerState( INPUT_STATE state, INPUT_LAYOUT cntlr_layout_num) { - for (int role = 0; role < INPUT_ROLE_NUMBER_OF; role++) { - // clang-format off - state.forward |= M_GetBindState(INPUT_ROLE_UP, cntlr_layout_num); - state.back |= M_GetBindState(INPUT_ROLE_DOWN, cntlr_layout_num); - state.left |= M_GetBindState(INPUT_ROLE_LEFT, cntlr_layout_num); - state.right |= M_GetBindState(INPUT_ROLE_RIGHT, cntlr_layout_num); - state.step_left |= M_GetBindState(INPUT_ROLE_STEP_L, cntlr_layout_num); - state.step_right |= M_GetBindState(INPUT_ROLE_STEP_R, cntlr_layout_num); - state.slow |= M_GetBindState(INPUT_ROLE_SLOW, cntlr_layout_num); - state.jump |= M_GetBindState(INPUT_ROLE_JUMP, cntlr_layout_num); - state.action |= M_GetBindState(INPUT_ROLE_ACTION, cntlr_layout_num); - state.draw |= M_GetBindState(INPUT_ROLE_DRAW, cntlr_layout_num); - state.look |= M_GetBindState(INPUT_ROLE_LOOK, cntlr_layout_num); - state.roll |= M_GetBindState(INPUT_ROLE_ROLL, cntlr_layout_num); - state.option |= M_GetBindState(INPUT_ROLE_OPTION, cntlr_layout_num); - state.pause |= M_GetBindState(INPUT_ROLE_PAUSE, cntlr_layout_num); - state.toggle_photo_mode |= M_GetBindState(INPUT_ROLE_TOGGLE_PHOTO_MODE, cntlr_layout_num); - state.camera_up |= M_GetBindState(INPUT_ROLE_CAMERA_UP, cntlr_layout_num); - state.camera_down |= M_GetBindState(INPUT_ROLE_CAMERA_DOWN, cntlr_layout_num); - state.camera_forward |= M_GetBindState(INPUT_ROLE_CAMERA_FORWARD, cntlr_layout_num); - state.camera_back |= M_GetBindState(INPUT_ROLE_CAMERA_BACK, cntlr_layout_num); - state.camera_left |= M_GetBindState(INPUT_ROLE_CAMERA_LEFT, cntlr_layout_num); - state.camera_right |= M_GetBindState(INPUT_ROLE_CAMERA_RIGHT, cntlr_layout_num); - state.item_cheat |= M_GetBindState(INPUT_ROLE_ITEM_CHEAT, cntlr_layout_num); - state.fly_cheat |= M_GetBindState(INPUT_ROLE_FLY_CHEAT, cntlr_layout_num); - state.level_skip_cheat |= M_GetBindState(INPUT_ROLE_LEVEL_SKIP_CHEAT, cntlr_layout_num); - state.turbo_cheat |= M_GetBindState(INPUT_ROLE_TURBO_CHEAT, cntlr_layout_num); - state.equip_pistols |= M_GetBindState(INPUT_ROLE_EQUIP_PISTOLS, cntlr_layout_num); - state.equip_shotgun |= M_GetBindState(INPUT_ROLE_EQUIP_SHOTGUN, cntlr_layout_num); - state.equip_magnums |= M_GetBindState(INPUT_ROLE_EQUIP_MAGNUMS, cntlr_layout_num); - state.equip_uzis |= M_GetBindState(INPUT_ROLE_EQUIP_UZIS, cntlr_layout_num); - state.use_small_medi |= M_GetBindState(INPUT_ROLE_USE_SMALL_MEDI, cntlr_layout_num); - state.use_big_medi |= M_GetBindState(INPUT_ROLE_USE_BIG_MEDI, cntlr_layout_num); - state.save |= M_GetBindState(INPUT_ROLE_SAVE, cntlr_layout_num); - state.load |= M_GetBindState(INPUT_ROLE_LOAD, cntlr_layout_num); - state.toggle_fps_counter |= M_GetBindState(INPUT_ROLE_FPS, cntlr_layout_num); - state.toggle_bilinear_filter |= M_GetBindState(INPUT_ROLE_BILINEAR, cntlr_layout_num); - state.toggle_ui |= M_GetBindState(INPUT_ROLE_TOGGLE_UI, cntlr_layout_num); - state.change_target |= M_GetBindState(INPUT_ROLE_CHANGE_TARGET, cntlr_layout_num); - state.menu_confirm |= M_JoyBtn(SDL_CONTROLLER_BUTTON_A); - state.menu_back |= M_JoyBtn(SDL_CONTROLLER_BUTTON_B); - state.menu_back |= M_JoyBtn(SDL_CONTROLLER_BUTTON_Y); - // clang-format on - } + // clang-format off + state.forward |= M_GetBindState(INPUT_ROLE_UP, cntlr_layout_num); + state.back |= M_GetBindState(INPUT_ROLE_DOWN, cntlr_layout_num); + state.left |= M_GetBindState(INPUT_ROLE_LEFT, cntlr_layout_num); + state.right |= M_GetBindState(INPUT_ROLE_RIGHT, cntlr_layout_num); + state.step_left |= M_GetBindState(INPUT_ROLE_STEP_L, cntlr_layout_num); + state.step_right |= M_GetBindState(INPUT_ROLE_STEP_R, cntlr_layout_num); + state.slow |= M_GetBindState(INPUT_ROLE_SLOW, cntlr_layout_num); + state.jump |= M_GetBindState(INPUT_ROLE_JUMP, cntlr_layout_num); + state.action |= M_GetBindState(INPUT_ROLE_ACTION, cntlr_layout_num); + state.draw |= M_GetBindState(INPUT_ROLE_DRAW, cntlr_layout_num); + state.look |= M_GetBindState(INPUT_ROLE_LOOK, cntlr_layout_num); + state.roll |= M_GetBindState(INPUT_ROLE_ROLL, cntlr_layout_num); + state.option |= M_GetBindState(INPUT_ROLE_OPTION, cntlr_layout_num); + state.pause |= M_GetBindState(INPUT_ROLE_PAUSE, cntlr_layout_num); + state.toggle_photo_mode |= M_GetBindState(INPUT_ROLE_TOGGLE_PHOTO_MODE, cntlr_layout_num); + state.camera_up |= M_GetBindState(INPUT_ROLE_CAMERA_UP, cntlr_layout_num); + state.camera_down |= M_GetBindState(INPUT_ROLE_CAMERA_DOWN, cntlr_layout_num); + state.camera_forward |= M_GetBindState(INPUT_ROLE_CAMERA_FORWARD, cntlr_layout_num); + state.camera_back |= M_GetBindState(INPUT_ROLE_CAMERA_BACK, cntlr_layout_num); + state.camera_left |= M_GetBindState(INPUT_ROLE_CAMERA_LEFT, cntlr_layout_num); + state.camera_right |= M_GetBindState(INPUT_ROLE_CAMERA_RIGHT, cntlr_layout_num); + state.item_cheat |= M_GetBindState(INPUT_ROLE_ITEM_CHEAT, cntlr_layout_num); + state.fly_cheat |= M_GetBindState(INPUT_ROLE_FLY_CHEAT, cntlr_layout_num); + state.level_skip_cheat |= M_GetBindState(INPUT_ROLE_LEVEL_SKIP_CHEAT, cntlr_layout_num); + state.turbo_cheat |= M_GetBindState(INPUT_ROLE_TURBO_CHEAT, cntlr_layout_num); + state.equip_pistols |= M_GetBindState(INPUT_ROLE_EQUIP_PISTOLS, cntlr_layout_num); + state.equip_shotgun |= M_GetBindState(INPUT_ROLE_EQUIP_SHOTGUN, cntlr_layout_num); + state.equip_magnums |= M_GetBindState(INPUT_ROLE_EQUIP_MAGNUMS, cntlr_layout_num); + state.equip_uzis |= M_GetBindState(INPUT_ROLE_EQUIP_UZIS, cntlr_layout_num); + state.use_small_medi |= M_GetBindState(INPUT_ROLE_USE_SMALL_MEDI, cntlr_layout_num); + state.use_big_medi |= M_GetBindState(INPUT_ROLE_USE_BIG_MEDI, cntlr_layout_num); + state.save |= M_GetBindState(INPUT_ROLE_SAVE, cntlr_layout_num); + state.load |= M_GetBindState(INPUT_ROLE_LOAD, cntlr_layout_num); + state.toggle_fps_counter |= M_GetBindState(INPUT_ROLE_FPS, cntlr_layout_num); + state.toggle_bilinear_filter |= M_GetBindState(INPUT_ROLE_BILINEAR, cntlr_layout_num); + state.toggle_ui |= M_GetBindState(INPUT_ROLE_TOGGLE_UI, cntlr_layout_num); + state.change_target |= M_GetBindState(INPUT_ROLE_CHANGE_TARGET, cntlr_layout_num); + state.menu_confirm |= M_JoyBtn(SDL_CONTROLLER_BUTTON_A); + state.menu_back |= M_JoyBtn(SDL_CONTROLLER_BUTTON_B); + state.menu_back |= M_JoyBtn(SDL_CONTROLLER_BUTTON_Y); + // clang-format on return state; } @@ -917,6 +667,23 @@ void S_Input_Init(void) { m_KeyboardState = SDL_GetKeyboardState(NULL); + for (int32_t layout = INPUT_LAYOUT_DEFAULT; layout < INPUT_LAYOUT_NUMBER_OF; + layout++) { + for (int32_t i = 0; m_BuiltinKeyboardLayout[i].role != (INPUT_ROLE)-1; + i++) { + const BUILTIN_KEYBOARD_LAYOUT *const builtin = + &m_BuiltinKeyboardLayout[i]; + m_Layout[layout][builtin->role] = builtin->scancode; + } + + for (int32_t i = 0; m_BuiltinControllerLayout[i].role != (INPUT_ROLE)-1; + i++) { + const BUILTIN_CONTROLLER_LAYOUT *const builtin = + &m_BuiltinControllerLayout[i]; + m_ControllerLayout[layout][builtin->role] = builtin->map; + } + } + int32_t result = SDL_Init(SDL_INIT_GAMECONTROLLER | SDL_INIT_SENSOR); if (result < 0) { LOG_ERROR("Error while calling SDL_Init: 0x%lx", result);