[PATCH} FIx controller hotplug

Thanks Alug
This commit is contained in:
NepDisk 2025-08-07 09:20:24 -04:00
parent 361c1b50ff
commit ec7fbb9be8
4 changed files with 35 additions and 18 deletions

View file

@ -938,7 +938,7 @@ INT32 G_PlayerInputAnalog(UINT8 p, INT32 gc, boolean digital)
deadzone = (JOYAXISRANGE * cv_deadzone[p].value) / FRACUNIT;
deviceID = cv_usejoystick[p].value;
deviceID = I_GetJoystickDeviceIndexForPlayer(p) + 1;
retrygetcontrol:
for (i = 0; i < MAXINPUTMAPPING; i++)
@ -1056,7 +1056,7 @@ static void G_DoCameraTurn(ticcmd_t *cmd, INT32 realtics, UINT8 ssplayer, player
if (player->mo)
cmd->angle = K_GetKartTurnValue(player, cmd->angle);
cmd->angle *= realtics;
if (P_CanPlayerTurn(player, cmd))
@ -1315,7 +1315,7 @@ void G_BuildTiccmd(ticcmd_t *cmd, INT32 realtics, UINT8 ssplayer)
cmd->sidemove = MAXPLMOVE;
else if (cmd->sidemove < -MAXPLMOVE)
cmd->sidemove = -MAXPLMOVE;
if (cmd->turning > KART_FULLTURN)
cmd->turning = KART_FULLTURN;
else if (cmd->turning < -KART_FULLTURN)
@ -2397,9 +2397,9 @@ void G_PlayerReborn(INT32 player, boolean betweenmaps)
boolean followerready;
INT32 followerskin;
UINT16 followercolor;
mobj_t *follower; // old follower, will probably be removed by the time we're dead but you never know.
INT32 charflags;
UINT32 followitem;
@ -2416,7 +2416,7 @@ void G_PlayerReborn(INT32 player, boolean betweenmaps)
tic_t starposttime; // The time of the last cheatcheck you hit
INT32 prevcheck; // Distance from Previous Legacy Checkpoint
INT32 nextcheck; // Distace to Next Legacy Checkpoint
INT32 exiting;
INT32 khudcardanimation;
INT16 totalring;
@ -2564,7 +2564,7 @@ void G_PlayerReborn(INT32 player, boolean betweenmaps)
wanted = players[player].wanted;
rings = players[player].rings;
kickstartaccel = players[player].kickstartaccel;
nocontrol = players[player].nocontrol;
laps = players[player].laps;
@ -2574,7 +2574,7 @@ void G_PlayerReborn(INT32 player, boolean betweenmaps)
exiting = players[player].exiting;
khudcardanimation = (exiting > 0) ? players[player].karthud[khud_cardanimation] : 0;
starpostx = players[player].starpostx;
starposty = players[player].starposty;
starpostz = players[player].starpostz;
@ -2601,7 +2601,7 @@ void G_PlayerReborn(INT32 player, boolean betweenmaps)
{
follower = NULL;
}
spectatorreentry = players[player].spectatorreentry;
grieftime = players[player].grieftime;
@ -2644,7 +2644,7 @@ void G_PlayerReborn(INT32 player, boolean betweenmaps)
p->starposttime = starposttime;
p->prevcheck = prevcheck;
p->nextcheck = nextcheck;
p->exiting = exiting;
p->karthud[khud_cardanimation] = khudcardanimation;
@ -2676,7 +2676,7 @@ void G_PlayerReborn(INT32 player, boolean betweenmaps)
p->ringvolume = 255;
p->ringtransparency = 255;
p->spectatorreentry = spectatorreentry;
p->grieftime = grieftime;
p->griefstrikes = griefstrikes;
@ -2754,7 +2754,7 @@ void G_PlayerReborn(INT32 player, boolean betweenmaps)
if (songcredit)
S_ShowMusicCredit();
if (leveltime > (starttime + (TICRATE/2)) && !p->spectator)
p->respawn = 48; // Respawn effect
}
@ -2817,7 +2817,7 @@ void G_SpawnPlayer(INT32 playernum, boolean starpost)
}
void G_MovePlayerToSpawnOrStarpost(INT32 playernum, boolean starpost)
{
{
if ((leveltime > starttime) && starpost)
P_MovePlayerToStarpost(playernum);
else
@ -3143,10 +3143,10 @@ void G_DoReborn(INT32 playernum)
{
// respawn at the start
mobj_t *oldmo = NULL;
if (player->spectator)
;
else if ((player->starpostnum || ((player->nextwaypoint != NULL) && player->starposttime))
else if ((player->starpostnum || ((player->nextwaypoint != NULL) && player->starposttime))
|| ((mapheaderinfo[gamemap - 1]->levelflags & LF_SECTIONRACE) && player->laps)) // SRB2kart
starpost = true;
@ -4585,7 +4585,7 @@ void G_LoadGameData(void)
if (vspowerlevel[i] < PWRLVRECORD_MIN || vspowerlevel[i] > PWRLVRECORD_MAX)
goto datacorrupt;
}
modded = READUINT8(save.p);
// Aha! Someone's been screwing with the save file!

View file

@ -14,6 +14,7 @@
#include "doomdef.h"
#include "doomstat.h"
#include "g_input.h"
#include "i_system.h"
#include "keys.h"
#include "hu_stuff.h" // need HUFONT start & end
#include "d_net.h"
@ -38,7 +39,7 @@ consvar_t cv_turnsmooth = CVAR_INIT ("turnsmoothing", "Off", CV_SAVE, turnsmooth
// current state of the keys
// JOYAXISRANGE for fully pressed, 0 for not pressed
INT32 gamekeydown[MAXDEVICES][NUMINPUTS];
boolean deviceResponding[MAXDEVICES];
boolean deviceResponding[MAXDEVICES];
// several key codes (or virtual key) per game control
INT32 gamecontrol[MAXSPLITSCREENPLAYERS][num_gamecontrols][MAXINPUTMAPPING];
@ -100,7 +101,7 @@ INT32 G_GetDevicePlayer(INT32 deviceID)
for (i = 0; i < MAXSPLITSCREENPLAYERS; i++)
{
if (deviceID == cv_usejoystick[i].value)
if (deviceID == I_GetJoystickDeviceIndexForPlayer(i) + 1)
{
return i;
}

View file

@ -310,6 +310,8 @@ const char *I_LocateWad(void);
*/
void I_GetJoystickEvents(UINT8 index);
INT32 I_GetJoystickDeviceIndexForPlayer(UINT8 pnum);
/** \brief Checks if the mouse needs to be grabbed
*/
void I_UpdateMouseGrab(void);

View file

@ -1098,6 +1098,20 @@ INT32 I_GetJoystickDeviceIndex(SDL_GameController *dev)
return -1;
}
INT32 I_GetJoystickDeviceIndexForPlayer(UINT8 pnum)
{
SDL_Joystick *joystick = NULL;
joystick = SDL_GameControllerGetJoystick(JoyInfo[pnum].dev);
if (joystick)
{
return SDL_JoystickInstanceID(joystick);
}
return -1;
}
void I_UpdateJoystickDeviceIndex(UINT8 player)
{
///////////////////////////////////////////////