Fix keyboard input

Thanks once again Alug!
This commit is contained in:
NepDisk 2026-02-15 17:27:24 -05:00
parent fb5287f335
commit ead335b1fd
5 changed files with 14 additions and 65 deletions

View file

@ -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++)
{

View file

@ -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)

View file

@ -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());

View file

@ -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);

View file

@ -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