some joystick fixes

Turns out P3/P4 controllers are broken (and still are)
This commit is contained in:
TehRealSalt 2017-12-24 08:20:58 -05:00
parent c2db0ddca2
commit 0dfd7fc41e
8 changed files with 127 additions and 48 deletions

View File

@ -1079,7 +1079,7 @@ static INT32 Joy4Axis(axis_input_e axissel)
#ifdef _arch_dreamcast #ifdef _arch_dreamcast
if (axisval == 7) // special case if (axisval == 7) // special case
{ {
retaxis = joy4xmove[1] - joy4ymove[1]; retaxis = joy2xmove[1] - joy2ymove[1];
goto skipDC; goto skipDC;
} }
else else

View File

@ -2036,7 +2036,7 @@ void Command_Setcontrol3_f(void)
if (na != 3 && na != 4) if (na != 3 && na != 4)
{ {
CONS_Printf(M_GetText("setcontrol23 <controlname> <keyname> [<2nd keyname>]: set controls for player 3\n")); CONS_Printf(M_GetText("setcontrol3 <controlname> <keyname> [<2nd keyname>]: set controls for player 3\n"));
return; return;
} }

View File

@ -330,6 +330,14 @@ void I_GetJoystickEvents(void);
*/ */
void I_GetJoystick2Events(void); void I_GetJoystick2Events(void);
/** \brief Third Joystick's events
*/
void I_GetJoystick3Events(void);
/** \brief Fourth Joystick's events
*/
void I_GetJoystick4Events(void);
/** \brief Mouses events /** \brief Mouses events
*/ */
void I_GetMouseEvents(void); void I_GetMouseEvents(void);

View File

@ -7138,9 +7138,7 @@ static void M_SetupJoystickMenu(INT32 choice)
static void M_Setup1PJoystickMenu(INT32 choice) static void M_Setup1PJoystickMenu(INT32 choice)
{ {
setupcontrols_secondaryplayer = false; setupcontrols_secondaryplayer = setupcontrols_thirdplayer = setupcontrols_fourthplayer = false;
setupcontrols_thirdplayer = false;
setupcontrols_fourthplayer = false;
OP_JoystickSetDef.prevMenu = &OP_Joystick1Def; OP_JoystickSetDef.prevMenu = &OP_Joystick1Def;
M_SetupJoystickMenu(choice); M_SetupJoystickMenu(choice);
} }
@ -7148,8 +7146,7 @@ static void M_Setup1PJoystickMenu(INT32 choice)
static void M_Setup2PJoystickMenu(INT32 choice) static void M_Setup2PJoystickMenu(INT32 choice)
{ {
setupcontrols_secondaryplayer = true; setupcontrols_secondaryplayer = true;
setupcontrols_thirdplayer = false; setupcontrols_thirdplayer = setupcontrols_fourthplayer = false;
setupcontrols_fourthplayer = false;
OP_JoystickSetDef.prevMenu = &OP_Joystick2Def; OP_JoystickSetDef.prevMenu = &OP_Joystick2Def;
M_SetupJoystickMenu(choice); M_SetupJoystickMenu(choice);
} }
@ -7157,8 +7154,7 @@ static void M_Setup2PJoystickMenu(INT32 choice)
static void M_Setup3PJoystickMenu(INT32 choice) static void M_Setup3PJoystickMenu(INT32 choice)
{ {
setupcontrols_thirdplayer = true; setupcontrols_thirdplayer = true;
setupcontrols_secondaryplayer = false; setupcontrols_secondaryplayer = setupcontrols_fourthplayer = false;
setupcontrols_fourthplayer = false;
OP_JoystickSetDef.prevMenu = &OP_Joystick3Def; OP_JoystickSetDef.prevMenu = &OP_Joystick3Def;
M_SetupJoystickMenu(choice); M_SetupJoystickMenu(choice);
} }
@ -7166,15 +7162,18 @@ static void M_Setup3PJoystickMenu(INT32 choice)
static void M_Setup4PJoystickMenu(INT32 choice) static void M_Setup4PJoystickMenu(INT32 choice)
{ {
setupcontrols_fourthplayer = true; setupcontrols_fourthplayer = true;
setupcontrols_secondaryplayer = false; setupcontrols_secondaryplayer = setupcontrols_thirdplayer = false;
setupcontrols_thirdplayer = false;
OP_JoystickSetDef.prevMenu = &OP_Joystick4Def; OP_JoystickSetDef.prevMenu = &OP_Joystick4Def;
M_SetupJoystickMenu(choice); M_SetupJoystickMenu(choice);
} }
static void M_AssignJoystick(INT32 choice) static void M_AssignJoystick(INT32 choice)
{ {
if (setupcontrols_secondaryplayer) if (setupcontrols_fourthplayer)
CV_SetValue(&cv_usejoystick4, choice);
else if (setupcontrols_thirdplayer)
CV_SetValue(&cv_usejoystick3, choice);
else if (setupcontrols_secondaryplayer)
CV_SetValue(&cv_usejoystick2, choice); CV_SetValue(&cv_usejoystick2, choice);
else else
CV_SetValue(&cv_usejoystick, choice); CV_SetValue(&cv_usejoystick, choice);
@ -7187,9 +7186,7 @@ static void M_AssignJoystick(INT32 choice)
static void M_Setup1PControlsMenu(INT32 choice) static void M_Setup1PControlsMenu(INT32 choice)
{ {
(void)choice; (void)choice;
setupcontrols_secondaryplayer = false; setupcontrols_secondaryplayer = setupcontrols_thirdplayer = setupcontrols_fourthplayer = false;
setupcontrols_thirdplayer = false;
setupcontrols_fourthplayer = false;
setupcontrols = gamecontrol; // was called from main Options (for console player, then) setupcontrols = gamecontrol; // was called from main Options (for console player, then)
currentMenu->lastOn = itemOn; currentMenu->lastOn = itemOn;
@ -7339,6 +7336,8 @@ static void M_ChangecontrolResponse(event_t *ev)
case ev_mouse2: case ev_mouse2:
case ev_joystick: case ev_joystick:
case ev_joystick2: case ev_joystick2:
case ev_joystick3:
case ev_joystick4:
ch = KEY_NULL; // no key ch = KEY_NULL; // no key
break; break;

View File

@ -2036,7 +2036,7 @@ void I_InitJoystick4(void)
{ {
I_ShutdownJoystick4(); I_ShutdownJoystick4();
SDL_SetHintWithPriority("SDL_XINPUT_ENABLED", "0", SDL_HINT_OVERRIDE); SDL_SetHintWithPriority("SDL_XINPUT_ENABLED", "0", SDL_HINT_OVERRIDE);
if (!strcmp(cv_usejoystick3.string, "0") || M_CheckParm("-nojoy")) if (!strcmp(cv_usejoystick4.string, "0") || M_CheckParm("-nojoy"))
return; return;
if (joy_open4(cv_usejoystick4.string) != -1) if (joy_open4(cv_usejoystick4.string) != -1)
JoyInfo4.oldjoy = atoi(cv_usejoystick4.string); JoyInfo4.oldjoy = atoi(cv_usejoystick4.string);

View File

@ -522,6 +522,48 @@ static INT32 SDLJoyAxis(const Sint16 axis, evtype_t which)
{ {
raxis = JoyInfo2.scale!=1?((raxis/JoyInfo2.scale)*JoyInfo2.scale):raxis; raxis = JoyInfo2.scale!=1?((raxis/JoyInfo2.scale)*JoyInfo2.scale):raxis;
#ifdef SDL_JDEADZONE
if (-SDL_JDEADZONE <= raxis && raxis <= SDL_JDEADZONE)
raxis = 0;
#endif
}
}
else if (which == ev_joystick3)
{
if (Joystick3.bGamepadStyle)
{
// gamepad control type, on or off, live or die
if (raxis < -(JOYAXISRANGE/2))
raxis = -1;
else if (raxis > (JOYAXISRANGE/2))
raxis = 1;
else raxis = 0;
}
else
{
raxis = JoyInfo3.scale!=1?((raxis/JoyInfo3.scale)*JoyInfo3.scale):raxis;
#ifdef SDL_JDEADZONE
if (-SDL_JDEADZONE <= raxis && raxis <= SDL_JDEADZONE)
raxis = 0;
#endif
}
}
else if (which == ev_joystick4)
{
if (Joystick4.bGamepadStyle)
{
// gamepad control type, on or off, live or die
if (raxis < -(JOYAXISRANGE/2))
raxis = -1;
else if (raxis > (JOYAXISRANGE/2))
raxis = 1;
else raxis = 0;
}
else
{
raxis = JoyInfo4.scale!=1?((raxis/JoyInfo4.scale)*JoyInfo4.scale):raxis;
#ifdef SDL_JDEADZONE #ifdef SDL_JDEADZONE
if (-SDL_JDEADZONE <= raxis && raxis <= SDL_JDEADZONE) if (-SDL_JDEADZONE <= raxis && raxis <= SDL_JDEADZONE)
raxis = 0; raxis = 0;
@ -717,11 +759,13 @@ static void Impl_HandleMouseWheelEvent(SDL_MouseWheelEvent evt)
static void Impl_HandleJoystickAxisEvent(SDL_JoyAxisEvent evt) static void Impl_HandleJoystickAxisEvent(SDL_JoyAxisEvent evt)
{ {
event_t event; event_t event;
SDL_JoystickID joyid[2]; SDL_JoystickID joyid[4];
// Determine the Joystick IDs for each current open joystick // Determine the Joystick IDs for each current open joystick
joyid[0] = SDL_JoystickInstanceID(JoyInfo.dev); joyid[0] = SDL_JoystickInstanceID(JoyInfo.dev);
joyid[1] = SDL_JoystickInstanceID(JoyInfo2.dev); joyid[1] = SDL_JoystickInstanceID(JoyInfo2.dev);
joyid[2] = SDL_JoystickInstanceID(JoyInfo3.dev);
joyid[3] = SDL_JoystickInstanceID(JoyInfo4.dev);
evt.axis++; evt.axis++;
event.data1 = event.data2 = event.data3 = INT32_MAX; event.data1 = event.data2 = event.data3 = INT32_MAX;
@ -734,6 +778,14 @@ static void Impl_HandleJoystickAxisEvent(SDL_JoyAxisEvent evt)
{ {
event.type = ev_joystick2; event.type = ev_joystick2;
} }
else if (evt.which == joyid[2])
{
event.type = ev_joystick3;
}
else if (evt.which == joyid[3])
{
event.type = ev_joystick4;
}
else return; else return;
//axis //axis
if (evt.axis > JOYAXISSET*2) if (evt.axis > JOYAXISSET*2)
@ -756,11 +808,13 @@ static void Impl_HandleJoystickAxisEvent(SDL_JoyAxisEvent evt)
static void Impl_HandleJoystickButtonEvent(SDL_JoyButtonEvent evt, Uint32 type) static void Impl_HandleJoystickButtonEvent(SDL_JoyButtonEvent evt, Uint32 type)
{ {
event_t event; event_t event;
SDL_JoystickID joyid[2]; SDL_JoystickID joyid[4];
// Determine the Joystick IDs for each current open joystick // Determine the Joystick IDs for each current open joystick
joyid[0] = SDL_JoystickInstanceID(JoyInfo.dev); joyid[0] = SDL_JoystickInstanceID(JoyInfo.dev);
joyid[1] = SDL_JoystickInstanceID(JoyInfo2.dev); joyid[1] = SDL_JoystickInstanceID(JoyInfo2.dev);
joyid[2] = SDL_JoystickInstanceID(JoyInfo3.dev);
joyid[3] = SDL_JoystickInstanceID(JoyInfo4.dev);
if (evt.which == joyid[0]) if (evt.which == joyid[0])
{ {
@ -770,6 +824,14 @@ static void Impl_HandleJoystickButtonEvent(SDL_JoyButtonEvent evt, Uint32 type)
{ {
event.data1 = KEY_2JOY1; event.data1 = KEY_2JOY1;
} }
else if (evt.which == joyid[2])
{
event.data1 = KEY_3JOY1;
}
else if (evt.which == joyid[3])
{
event.data1 = KEY_4JOY1;
}
else return; else return;
if (type == SDL_JOYBUTTONUP) if (type == SDL_JOYBUTTONUP)
{ {
@ -891,6 +953,8 @@ void I_OsPolling(void)
SDL_JoystickUpdate(); SDL_JoystickUpdate();
I_GetJoystickEvents(); I_GetJoystickEvents();
I_GetJoystick2Events(); I_GetJoystick2Events();
I_GetJoystick3Events();
I_GetJoystick4Events();
} }
I_GetMouseEvents(); I_GetMouseEvents();

View File

@ -67,6 +67,14 @@ extern SDLJoyInfo_t JoyInfo;
*/ */
extern SDLJoyInfo_t JoyInfo2; extern SDLJoyInfo_t JoyInfo2;
/** \brief SDL inof about joystick 3
*/
extern SDLJoyInfo_t JoyInfo3;
/** \brief SDL inof about joystick 4
*/
extern SDLJoyInfo_t JoyInfo4;
void I_GetConsoleEvents(void); void I_GetConsoleEvents(void);
void SDLforceUngrabMouse(void); void SDLforceUngrabMouse(void);