From ead335b1fdc6551ca7d65cdd5acdb2abf817f392 Mon Sep 17 00:00:00 2001 From: NepDisk Date: Sun, 15 Feb 2026 17:27:24 -0500 Subject: [PATCH] Fix keyboard input Thanks once again Alug! --- src/g_game.c | 8 ++++++- src/g_input.c | 9 ++----- src/sdl/i_gamepad.c | 3 +++ src/sdl/i_video.cpp | 57 +-------------------------------------------- src/sdl/sdlmain.h | 2 +- 5 files changed, 14 insertions(+), 65 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index 1add0e7f0..48796acab 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -19,6 +19,7 @@ #include "d_clisrv.h" #include "f_finale.h" #include "filesrch.h" // for refreshdirmenu +#include "g_input.h" #include "m_fixed.h" #include "p_setup.h" #include "p_saveg.h" @@ -1267,9 +1268,14 @@ INT32 G_PlayerInputAnalog(UINT8 p, INT32 gc, boolean digital, SINT8 type) deadzone = (JOYAXISRANGE * deadzonetype) / FRACUNIT; deviceID = I_GetControllerSlotfromID(I_GetControllerIDForPlayer(p)); - if (deviceID == INVALID_DEVICE) + if (deviceID >= MAXDEVICES) return 0; + // not a controller? + // then its a keyboard or mouse + if (deviceID == INVALID_DEVICE) + deviceID = KEYBOARD_MOUSE_DEVICE; + retrygetcontrol: for (i = 0; i < MAXINPUTMAPPING; i++) { diff --git a/src/g_input.c b/src/g_input.c index 748244f3f..c0d8015ec 100644 --- a/src/g_input.c +++ b/src/g_input.c @@ -230,18 +230,13 @@ void G_MapEventsToControls(event_t *ev) INT32 device = ev->device; - // invalid - if (device < KEYBOARD_MOUSE_DEVICE || device >= UINT32_MAX) - return; - // not a keyboard? // try to see if its a controller in use if (device > KEYBOARD_MOUSE_DEVICE) device = I_GetControllerSlotfromID(device-1); - // nope no controller thats used - // so ignore it - if (device == INVALID_DEVICE) + // invalid device + if (device < KEYBOARD_MOUSE_DEVICE || device >= MAXDEVICES) return; switch (ev->type) diff --git a/src/sdl/i_gamepad.c b/src/sdl/i_gamepad.c index 410292502..020cef1ef 100644 --- a/src/sdl/i_gamepad.c +++ b/src/sdl/i_gamepad.c @@ -304,6 +304,9 @@ INT32 I_GetControllerID(SDL_Gamepad *dev) INT32 I_GetControllerSlotfromID(INT32 id) { + if (id < 0) + return -1; + if (!controllerlist) { CONS_Debug(DBG_GAMELOGIC, "Failed to fetch Controller list: %s\n", SDL_GetError()); diff --git a/src/sdl/i_video.cpp b/src/sdl/i_video.cpp index fdb6a3d16..c2c9e7cfd 100644 --- a/src/sdl/i_video.cpp +++ b/src/sdl/i_video.cpp @@ -832,61 +832,6 @@ static void Impl_HandleMouseWheelEvent(SDL_MouseWheelEvent evt) } } -// ill put this here if blan wants this -// allows controller dpads to scroll through menus -/* -static UINT8 hatrepeattimer[MAXSPLITSCREENPLAYERS]; -#define HATREPEATDELAY 19 - -void I_HandleControllerHatRepeat(void) -{ - // why bother if theres no controllers? - if (numcontrollers == 0) - return; - - event_t event = {ev_keydown, 0, 0, 0}; - - static const SDL_GameControllerButton hatbutt[4] = - { - SDL_CONTROLLER_BUTTON_DPAD_UP, - SDL_CONTROLLER_BUTTON_DPAD_DOWN, - SDL_CONTROLLER_BUTTON_DPAD_LEFT, - SDL_CONTROLLER_BUTTON_DPAD_RIGHT - }; - - for (int i = 0; i < MAXSPLITSCREENPLAYERS; i++) - { - if (!cv_usejoystick[i].value) - continue; - - SDL_GameController *controller = JoyInfo[i].dev; - - if (!controller) - continue; - - for (UINT8 h = 0; h < JOYHATS; h++) - { - if (SDL_GameControllerGetButton(controller, hatbutt[h])) - { - if (hatrepeattimer[i] < HATREPEATDELAY) - { - hatrepeattimer[i]++; - } - else if (hatrepeattimer[i] == HATREPEATDELAY) - { - event.data1 = KEY_HAT1 + (i * JOYHATS) + h; - D_PostEvent(&event); - } - - return; - } - } - - hatrepeattimer[i] = 0; - } -} -*/ - static void Impl_HandleControllerAxisEvent(SDL_GamepadAxisEvent evt) { event_t event; @@ -1031,7 +976,7 @@ static void Impl_HandleControllerRemoveEvent(SDL_Event evt) for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) { - if (controllerInfo[i].dev && (controllerInfo[i].id == (INT32)joystick_id) && !SDL_GamepadConnected(controllerInfo[i].dev)) + if (controllerInfo[i].dev && (controllerInfo[i].id == joystick_id) && !SDL_GamepadConnected(controllerInfo[i].dev)) { CONS_Debug(DBG_GAMELOGIC, "Controller for Player %d removed, device index: %d\n", i+1, joystick_id); I_ShutdownController(i); diff --git a/src/sdl/sdlmain.h b/src/sdl/sdlmain.h index 1118e5e46..90592fae8 100644 --- a/src/sdl/sdlmain.h +++ b/src/sdl/sdlmain.h @@ -47,7 +47,7 @@ typedef struct SDLJoyInfo_s /// Joystick handle //SDL_Joystick *joydev; /// Controller index - INT32 id; // SDL_JoystickID + SDL_JoystickID id; /// name of controller //const char *name; /// scale of axises