Port Use SDL Game Controllers API by Eidolon
This commit is contained in:
parent
968c705c7c
commit
a733ea2baa
8 changed files with 237 additions and 140 deletions
|
|
@ -2233,6 +2233,12 @@ static boolean CV_FilterVarByVersion(consvar_t *v, const char *valstr)
|
|||
|
||||
// axis defaults were changed to be friendly to 360 controllers
|
||||
// if ALL axis settings are defaults, then change them to new values
|
||||
if (!CV_FilterJoyAxisVars(v, valstr))
|
||||
return false;
|
||||
}
|
||||
|
||||
if (GETMAJOREXECVERSION(cv_execversion.value) < 10) // 10 = 1.6
|
||||
{
|
||||
// axis defaults changed again to SDL game controllers
|
||||
if (!CV_FilterJoyAxisVars2(v, valstr))
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -1021,25 +1021,53 @@ INT32 G_CheckDoubleUsage(INT32 keynum, boolean modify)
|
|||
|
||||
static INT32 G_FilterKeyByVersion(INT32 numctrl, INT32 keyidx, INT32 player, INT32 *keynum1, INT32 *keynum2, boolean *nestedoverride)
|
||||
{
|
||||
// Special case: ignore KEY_PAUSE because it's hardcoded
|
||||
if (keyidx == 0 && *keynum1 == KEY_PAUSE)
|
||||
{
|
||||
if (*keynum2 != KEY_PAUSE)
|
||||
{
|
||||
*keynum1 = *keynum2; // shift down keynum2 and continue
|
||||
*keynum2 = 0;
|
||||
}
|
||||
else
|
||||
return -1; // skip setting control
|
||||
}
|
||||
else if (keyidx == 1 && *keynum2 == KEY_PAUSE)
|
||||
return -1; // skip setting control
|
||||
|
||||
#if 1
|
||||
// We don't have changed control defaults yet
|
||||
(void)numctrl;
|
||||
(void)player;
|
||||
#if 1 // SRB2Kart filters/migrations
|
||||
(void)nestedoverride;
|
||||
|
||||
// Migration: 1.6 (majorexec 10) Joystick Defaults changed to use SDL Game Controllers
|
||||
if (GETMAJOREXECVERSION(cv_execversion.value) < 10)
|
||||
{
|
||||
|
||||
INT32 joybuttonbase = KEY_JOY1;
|
||||
|
||||
switch (player)
|
||||
{
|
||||
case 0:
|
||||
joybuttonbase = KEY_JOY1;
|
||||
break;
|
||||
case 1:
|
||||
joybuttonbase = KEY_2JOY1;
|
||||
break;
|
||||
case 2:
|
||||
joybuttonbase = KEY_3JOY1;
|
||||
break;
|
||||
case 3:
|
||||
joybuttonbase = KEY_4JOY1;
|
||||
break;
|
||||
}
|
||||
|
||||
// The face buttons match, so we don't need to rebind those.
|
||||
|
||||
if (keyidx == 1 && numctrl == gc_fire && *keynum2 == joybuttonbase + 4) // Xbox DInput LB
|
||||
{
|
||||
*keynum2 = joybuttonbase + 9; // SDL LEFTSHOULDER
|
||||
}
|
||||
if (keyidx == 1 && numctrl == gc_drift && *keynum2 == joybuttonbase + 5) // Xbox DInput RB
|
||||
{
|
||||
*keynum2 = joybuttonbase + 10; // SDL RIGHTSHOULDER
|
||||
}
|
||||
|
||||
// Pause and Systemmenu are only bound for P1
|
||||
if (keyidx == 1 && player == 0 && numctrl == gc_pause && *keynum2 == joybuttonbase + 6) // Xbox DInput Back
|
||||
{
|
||||
*keynum2 = joybuttonbase + 4; // SDL BACK
|
||||
}
|
||||
if (keyidx == 0 && player == 0 && numctrl == gc_systemmenu && *keynum1 == joybuttonbase + 7) // Xbox DInput Start
|
||||
{
|
||||
*keynum1 = joybuttonbase + 6; // SDL START
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
if (GETMAJOREXECVERSION(cv_execversion.value) < 27 && ( // v2.1.22
|
||||
numctrl == gc_weaponnext || numctrl == gc_weaponprev || numctrl == gc_tossflag ||
|
||||
|
|
|
|||
98
src/m_menu.c
98
src/m_menu.c
|
|
@ -2532,8 +2532,8 @@ boolean M_Responder(event_t *ev)
|
|||
{
|
||||
INT32 ch = -1;
|
||||
// INT32 i;
|
||||
static tic_t joywait = 0, mousewait = 0;
|
||||
static INT32 pjoyx = 0, pjoyy = 0;
|
||||
static tic_t joywait = 0, joywaitaccel = 0, mousewait = 0;
|
||||
static INT32 pjoyx = 0, pjoyy = 0, pjoyaccel = 0;
|
||||
static INT32 pmousex = 0, pmousey = 0;
|
||||
static INT32 lastx = 0, lasty = 0;
|
||||
void (*routine)(INT32 choice); // for some casting problem
|
||||
|
|
@ -2588,44 +2588,74 @@ boolean M_Responder(event_t *ev)
|
|||
if (ev->type == ev_joystick)
|
||||
{
|
||||
const INT32 jdeadzone = ((JOYAXISRANGE-1) * cv_deadzone[0].value) >> FRACBITS;
|
||||
if (ev->data3 != INT32_MAX)
|
||||
|
||||
INT32 accelaxis = abs(cv_moveaxis->value);
|
||||
if (ev->data1 == 0)
|
||||
{
|
||||
if (Joystick[0].bGamepadStyle || abs(ev->data3) > jdeadzone)
|
||||
if (ev->data3 != INT32_MAX)
|
||||
{
|
||||
if (ev->data3 < 0 && pjoyy >= 0)
|
||||
if (Joystick[0].bGamepadStyle || abs(ev->data3) > jdeadzone)
|
||||
{
|
||||
ch = KEY_UPARROW;
|
||||
joywait = thistime + NEWTICRATE/7;
|
||||
}
|
||||
else if (ev->data3 > 0 && pjoyy <= 0)
|
||||
{
|
||||
ch = KEY_DOWNARROW;
|
||||
joywait = thistime + NEWTICRATE/7;
|
||||
}
|
||||
pjoyy = ev->data3;
|
||||
}
|
||||
else
|
||||
pjoyy = 0;
|
||||
}
|
||||
if (joywait < thistime
|
||||
&& (pjoyy == 0 || (ev->data3 < 0) != (pjoyy < 0))) // no previous direction OR change direction
|
||||
{
|
||||
ch = (ev->data3 < 0) ? KEY_UPARROW : KEY_DOWNARROW;
|
||||
joywait = thistime + NEWTICRATE/7;
|
||||
}
|
||||
pjoyy = ev->data3;
|
||||
|
||||
if (ev->data2 != INT32_MAX)
|
||||
{
|
||||
if (Joystick[0].bGamepadStyle || abs(ev->data2) > jdeadzone)
|
||||
{
|
||||
if (ev->data2 < 0 && pjoyx >= 0)
|
||||
{
|
||||
ch = KEY_LEFTARROW;
|
||||
joywait = thistime + NEWTICRATE/17;
|
||||
}
|
||||
else if (ev->data2 > 0 && pjoyx <= 0)
|
||||
{
|
||||
ch = KEY_RIGHTARROW;
|
||||
joywait = thistime + NEWTICRATE/17;
|
||||
}
|
||||
pjoyx = ev->data2;
|
||||
else
|
||||
pjoyy = 0;
|
||||
}
|
||||
|
||||
|
||||
if (ev->data2 != INT32_MAX && joywait < thistime)
|
||||
{
|
||||
if (Joystick[0].bGamepadStyle || abs(ev->data2) > jdeadzone)
|
||||
{
|
||||
if (joywait < thistime
|
||||
&& (pjoyx == 0 || (ev->data2 < 0) != (pjoyx < 0))) // no previous direction OR change direction
|
||||
{
|
||||
ch = (ev->data2 < 0) ? KEY_LEFTARROW : KEY_RIGHTARROW;
|
||||
joywait = thistime + NEWTICRATE/7;
|
||||
}
|
||||
pjoyx = ev->data2;
|
||||
}
|
||||
else
|
||||
pjoyx = 0;
|
||||
}
|
||||
}
|
||||
else if (!(accelaxis > JOYAXISSET*2 || accelaxis == 0))
|
||||
{
|
||||
// The following borrows heavily from Joy1Axis.
|
||||
const boolean xmode = (accelaxis%2);
|
||||
INT32 retaxis = 0;
|
||||
if (!xmode)
|
||||
accelaxis--;
|
||||
accelaxis /= 2;
|
||||
if (ev->data1 == accelaxis)
|
||||
{
|
||||
const INT32 jacceldeadzone = xmode ? jdeadzone : jdeadzone;
|
||||
retaxis = xmode ? ev->data2 : ev->data3;
|
||||
if (retaxis != INT32_MAX)
|
||||
{
|
||||
if (cv_moveaxis[0].value < 0)
|
||||
retaxis = -retaxis;
|
||||
|
||||
if (Joystick[0].bGamepadStyle || retaxis > jacceldeadzone)
|
||||
{
|
||||
if (joywaitaccel < thistime && retaxis > pjoyaccel) // only on upwards event
|
||||
{
|
||||
ch = KEY_ENTER;
|
||||
joywaitaccel = thistime + NEWTICRATE/3;
|
||||
}
|
||||
pjoyaccel = retaxis;
|
||||
}
|
||||
else
|
||||
pjoyaccel = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
pjoyx = 0;
|
||||
}
|
||||
}
|
||||
else if (ev->type == ev_mouse && mousewait < I_GetTime())
|
||||
|
|
|
|||
|
|
@ -753,10 +753,11 @@ void P_Ticker(boolean run)
|
|||
|
||||
if (demo.recording)
|
||||
{
|
||||
INT32 axis = PlayerJoyAxis(AXISLOOKBACK, 1);
|
||||
G_WriteAllGhostTics();
|
||||
|
||||
if (cv_recordmultiplayerdemos.value && (demo.savemode == DSM_NOTSAVING || demo.savemode == DSM_WILLAUTOSAVE))
|
||||
if (demo.savebutton && demo.savebutton + 3*TICRATE < leveltime && PlayerInputDown(1, gc_lookback))
|
||||
if (demo.savebutton && demo.savebutton + 3*TICRATE < leveltime && PlayerInputDown(1, gc_lookback) || (cv_usejoystick[0].value && axis > 0))
|
||||
demo.savemode = DSM_TITLEENTRY;
|
||||
}
|
||||
else if (demo.playback) // Use Ghost data for consistency checks.
|
||||
|
|
|
|||
|
|
@ -207,7 +207,7 @@ static void JoyReset(SDLJoyInfo_t *JoySet)
|
|||
{
|
||||
if (JoySet->dev)
|
||||
{
|
||||
SDL_JoystickClose(JoySet->dev);
|
||||
SDL_GameControllerClose(JoySet->dev);
|
||||
}
|
||||
JoySet->dev = NULL;
|
||||
JoySet->oldjoy = -1;
|
||||
|
|
@ -953,28 +953,15 @@ void I_JoyScale4(void)
|
|||
}
|
||||
|
||||
// Cheat to get the device index for a joystick handle
|
||||
INT32 I_GetJoystickDeviceIndex(SDL_Joystick *dev)
|
||||
INT32 I_GetJoystickDeviceIndex(SDL_GameController *dev)
|
||||
{
|
||||
INT32 i, count = SDL_NumJoysticks();
|
||||
SDL_Joystick *joystick = NULL;
|
||||
|
||||
for (i = 0; dev && i < count; i++)
|
||||
joystick = SDL_GameControllerGetJoystick(dev);
|
||||
|
||||
if (joystick)
|
||||
{
|
||||
SDL_Joystick *test = SDL_JoystickOpen(i);
|
||||
if (test && test == dev)
|
||||
return i;
|
||||
else
|
||||
{
|
||||
UINT8 j;
|
||||
|
||||
for (j = 0; j < MAXSPLITSCREENPLAYERS; j++)
|
||||
{
|
||||
if (JoyInfo[j].dev == test)
|
||||
break;
|
||||
}
|
||||
|
||||
if (j == MAXSPLITSCREENPLAYERS)
|
||||
SDL_JoystickClose(test);
|
||||
}
|
||||
return SDL_JoystickInstanceID(joystick);
|
||||
}
|
||||
|
||||
return -1;
|
||||
|
|
@ -1096,10 +1083,11 @@ void I_GetJoystickEvents(UINT8 index)
|
|||
UINT64 joyhats = 0;
|
||||
#if 0
|
||||
UINT64 joybuttons = 0;
|
||||
Sint16 axisx, axisy;
|
||||
UINT32 axisx, axisy;
|
||||
#endif
|
||||
|
||||
if (!joystick_started[index]) return;
|
||||
if (!joystick_started[index])
|
||||
return;
|
||||
|
||||
if (!JoyInfo[index].dev) //I_ShutdownJoystick(index);
|
||||
return;
|
||||
|
|
@ -1135,15 +1123,12 @@ void I_GetJoystickEvents(UINT8 index)
|
|||
}
|
||||
#endif
|
||||
|
||||
for (i = JoyInfo[index].hats - 1; i >= 0; i--)
|
||||
{
|
||||
Uint8 hat = SDL_JoystickGetHat(JoyInfo[index].dev, i);
|
||||
|
||||
if (hat & SDL_HAT_UP ) joyhats|=(UINT64)0x1<<(0 + 4*i);
|
||||
if (hat & SDL_HAT_DOWN ) joyhats|=(UINT64)0x1<<(1 + 4*i);
|
||||
if (hat & SDL_HAT_LEFT ) joyhats|=(UINT64)0x1<<(2 + 4*i);
|
||||
if (hat & SDL_HAT_RIGHT) joyhats|=(UINT64)0x1<<(3 + 4*i);
|
||||
}
|
||||
joyhats |= SDL_GameControllerGetButton(JoyInfo[index].dev, SDL_CONTROLLER_BUTTON_DPAD_UP);
|
||||
joyhats |= SDL_GameControllerGetButton(JoyInfo[index].dev, SDL_CONTROLLER_BUTTON_DPAD_DOWN) << 1;
|
||||
joyhats |= SDL_GameControllerGetButton(JoyInfo[index].dev, SDL_CONTROLLER_BUTTON_DPAD_LEFT) << 2;
|
||||
joyhats |= SDL_GameControllerGetButton(JoyInfo[index].dev, SDL_CONTROLLER_BUTTON_DPAD_RIGHT) << 3;
|
||||
|
||||
|
||||
if (joyhats != lastjoyhats[index])
|
||||
{
|
||||
|
|
@ -1192,12 +1177,14 @@ void I_GetJoystickEvents(UINT8 index)
|
|||
event.data2 = -1;
|
||||
else if (axisx > (JOYAXISRANGE/2))
|
||||
event.data2 = 1;
|
||||
else event.data2 = 0;
|
||||
else
|
||||
event.data2 = 0;
|
||||
if (axisy < -(JOYAXISRANGE/2))
|
||||
event.data3 = -1;
|
||||
else if (axisy > (JOYAXISRANGE/2))
|
||||
event.data3 = 1;
|
||||
else event.data3 = 0;
|
||||
else
|
||||
event.data3 = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -1229,7 +1216,7 @@ void I_GetJoystickEvents(UINT8 index)
|
|||
*/
|
||||
static int joy_open(int playerIndex, int joyIndex)
|
||||
{
|
||||
SDL_Joystick *newdev = NULL;
|
||||
SDL_GameController *newdev = NULL;
|
||||
int num_joy = 0;
|
||||
|
||||
if (SDL_WasInit(SDL_INIT_JOYSTICK) == 0)
|
||||
|
|
@ -1237,6 +1224,12 @@ static int joy_open(int playerIndex, int joyIndex)
|
|||
CONS_Printf(M_GetText("Joystick subsystem not started\n"));
|
||||
return -1;
|
||||
}
|
||||
if (SDL_WasInit(SDL_INIT_GAMECONTROLLER) == 0)
|
||||
{
|
||||
CONS_Printf(M_GetText("Game Controller subsystem not started\n"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if (joyIndex <= 0)
|
||||
return -1;
|
||||
|
|
@ -1249,7 +1242,7 @@ static int joy_open(int playerIndex, int joyIndex)
|
|||
return -1;
|
||||
}
|
||||
|
||||
newdev = SDL_JoystickOpen(joyIndex-1);
|
||||
newdev = SDL_GameControllerOpen(joyIndex-1);
|
||||
|
||||
// Handle the edge case where the device <-> joystick index assignment can change due to hotplugging
|
||||
// This indexing is SDL's responsibility and there's not much we can do about it.
|
||||
|
|
@ -1264,9 +1257,9 @@ static int joy_open(int playerIndex, int joyIndex)
|
|||
if (JoyInfo[playerIndex].dev)
|
||||
{
|
||||
if (JoyInfo[playerIndex].dev == newdev // same device, nothing to do
|
||||
|| (newdev == NULL && SDL_JoystickGetAttached(JoyInfo[playerIndex].dev))) // we failed, but already have a working device
|
||||
|| (newdev == NULL && SDL_GameControllerGetAttached(JoyInfo[playerIndex].dev))) // we failed, but already have a working device
|
||||
{
|
||||
return JoyInfo[playerIndex].axises;
|
||||
return SDL_CONTROLLER_AXIS_MAX;
|
||||
}
|
||||
|
||||
// Else, we're changing devices, so send neutral joy events
|
||||
|
|
@ -1283,9 +1276,9 @@ static int joy_open(int playerIndex, int joyIndex)
|
|||
}
|
||||
else
|
||||
{
|
||||
CONS_Debug(DBG_GAMELOGIC, M_GetText("Joystick%d: %s\n"), playerIndex+1, SDL_JoystickName(JoyInfo[playerIndex].dev));
|
||||
CONS_Debug(DBG_GAMELOGIC, M_GetText("Joystick%d: %s\n"), playerIndex+1, SDL_GameControllerName(JoyInfo[playerIndex].dev));
|
||||
|
||||
JoyInfo[playerIndex].axises = SDL_JoystickNumAxes(JoyInfo[playerIndex].dev);
|
||||
JoyInfo[playerIndex].axises = SDL_CONTROLLER_AXIS_MAX;
|
||||
if (JoyInfo[playerIndex].axises > JOYAXISSET*2)
|
||||
JoyInfo[playerIndex].axises = JOYAXISSET*2;
|
||||
|
||||
|
|
@ -1297,15 +1290,15 @@ static int joy_open(int playerIndex, int joyIndex)
|
|||
}
|
||||
*/
|
||||
|
||||
JoyInfo[playerIndex].buttons = SDL_JoystickNumButtons(JoyInfo[playerIndex].dev);
|
||||
JoyInfo[playerIndex].buttons = SDL_CONTROLLER_BUTTON_MAX;
|
||||
if (JoyInfo[playerIndex].buttons > JOYBUTTONS)
|
||||
JoyInfo[playerIndex].buttons = JOYBUTTONS;
|
||||
|
||||
JoyInfo[playerIndex].hats = SDL_JoystickNumHats(JoyInfo[playerIndex].dev);
|
||||
JoyInfo[playerIndex].hats = 4;
|
||||
if (JoyInfo[playerIndex].hats > JOYHATS)
|
||||
JoyInfo[playerIndex].hats = JOYHATS;
|
||||
|
||||
JoyInfo[playerIndex].balls = SDL_JoystickNumBalls(JoyInfo[playerIndex].dev);
|
||||
JoyInfo[playerIndex].balls = 0;
|
||||
|
||||
//JoyInfo[playerIndex].bGamepadStyle = !stricmp(SDL_JoystickName(JoyInfo[playerIndex].dev), "pad");
|
||||
|
||||
|
|
@ -1318,7 +1311,7 @@ static int joy_open(int playerIndex, int joyIndex)
|
|||
//
|
||||
void I_InitJoystick(UINT8 index)
|
||||
{
|
||||
SDL_Joystick *newjoy = NULL;
|
||||
SDL_GameController *newcontroller = NULL;
|
||||
UINT8 i;
|
||||
|
||||
//I_ShutdownJoystick();
|
||||
|
|
@ -1342,24 +1335,33 @@ void I_InitJoystick(UINT8 index)
|
|||
return;
|
||||
}
|
||||
}
|
||||
if (SDL_WasInit(SDL_INIT_GAMECONTROLLER) == 0)
|
||||
{
|
||||
if (SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER) == -1)
|
||||
{
|
||||
CONS_Printf(M_GetText("Couldn't initialize gamepads: %s\n"), SDL_GetError());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (cv_usejoystick[index].value)
|
||||
newjoy = SDL_JoystickOpen(cv_usejoystick[index].value-1);
|
||||
newcontroller = SDL_GameControllerOpen(cv_usejoystick[index].value-1);
|
||||
|
||||
for (i = 0; i < MAXSPLITSCREENPLAYERS; i++)
|
||||
{
|
||||
if (i == index)
|
||||
continue;
|
||||
|
||||
if (JoyInfo[i].dev == newjoy)
|
||||
if (JoyInfo[i].dev == newcontroller)
|
||||
break;
|
||||
}
|
||||
|
||||
if (newjoy && i < MAXSPLITSCREENPLAYERS) // don't override an active device
|
||||
if (newcontroller && i < MAXSPLITSCREENPLAYERS) // don't override an active device
|
||||
{
|
||||
cv_usejoystick[index].value = I_GetJoystickDeviceIndex(JoyInfo[index].dev) + 1;
|
||||
}
|
||||
else if (newjoy && joy_open(index, cv_usejoystick[index].value) != -1)
|
||||
else if (newcontroller && joy_open(index, cv_usejoystick[index].value) != -1)
|
||||
{
|
||||
// SDL's device indexes are unstable, so cv_usejoystick may not match
|
||||
// the actual device index. So let's cheat a bit and find the device's current index.
|
||||
|
|
@ -1376,14 +1378,14 @@ void I_InitJoystick(UINT8 index)
|
|||
|
||||
for (i = 0; i < MAXSPLITSCREENPLAYERS; i++)
|
||||
{
|
||||
if (JoyInfo[i].dev == newjoy)
|
||||
if (JoyInfo[i].dev == newcontroller)
|
||||
break;
|
||||
}
|
||||
|
||||
if (i == MAXSPLITSCREENPLAYERS)
|
||||
{
|
||||
// Joystick didn't end up being used
|
||||
SDL_JoystickClose(newjoy);
|
||||
SDL_GameControllerClose(newcontroller);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -828,17 +828,17 @@ static void Impl_HandleMouseWheelEvent(SDL_MouseWheelEvent evt)
|
|||
}
|
||||
}
|
||||
|
||||
static void Impl_HandleJoystickAxisEvent(SDL_JoyAxisEvent evt)
|
||||
static void Impl_HandleControllerAxisEvent(SDL_ControllerAxisEvent evt)
|
||||
{
|
||||
event_t event;
|
||||
SDL_JoystickID joyid[MAXSPLITSCREENPLAYERS];
|
||||
UINT8 i;
|
||||
INT32 value;
|
||||
|
||||
// Determine the Joystick IDs for each current open joystick
|
||||
for (i = 0; i < MAXSPLITSCREENPLAYERS; i++)
|
||||
joyid[i] = SDL_JoystickInstanceID(JoyInfo[i].dev);
|
||||
joyid[i] = SDL_JoystickInstanceID(SDL_GameControllerGetJoystick(JoyInfo[i].dev));
|
||||
|
||||
evt.axis++;
|
||||
event.data1 = event.data2 = event.data3 = INT32_MAX;
|
||||
|
||||
if (evt.which == joyid[0])
|
||||
|
|
@ -861,17 +861,36 @@ static void Impl_HandleJoystickAxisEvent(SDL_JoyAxisEvent evt)
|
|||
//axis
|
||||
if (evt.axis > JOYAXISSET*2)
|
||||
return;
|
||||
//vaule
|
||||
if (evt.axis%2)
|
||||
//value
|
||||
value = SDLJoyAxis(evt.value, event.type);
|
||||
switch (evt.axis)
|
||||
{
|
||||
event.data1 = evt.axis / 2;
|
||||
event.data2 = SDLJoyAxis(evt.value, event.type);
|
||||
}
|
||||
else
|
||||
{
|
||||
evt.axis--;
|
||||
event.data1 = evt.axis / 2;
|
||||
event.data3 = SDLJoyAxis(evt.value, event.type);
|
||||
case SDL_CONTROLLER_AXIS_LEFTX:
|
||||
event.data1 = 0;
|
||||
event.data2 = value;
|
||||
break;
|
||||
case SDL_CONTROLLER_AXIS_LEFTY:
|
||||
event.data1 = 0;
|
||||
event.data3 = value;
|
||||
break;
|
||||
case SDL_CONTROLLER_AXIS_RIGHTX:
|
||||
event.data1 = 1;
|
||||
event.data2 = value;
|
||||
break;
|
||||
case SDL_CONTROLLER_AXIS_RIGHTY:
|
||||
event.data1 = 1;
|
||||
event.data3 = value;
|
||||
break;
|
||||
case SDL_CONTROLLER_AXIS_TRIGGERLEFT:
|
||||
event.data1 = 2;
|
||||
event.data2 = value;
|
||||
break;
|
||||
case SDL_CONTROLLER_AXIS_TRIGGERRIGHT:
|
||||
event.data1 = 2;
|
||||
event.data3 = value;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
D_PostEvent(&event);
|
||||
}
|
||||
|
|
@ -912,7 +931,7 @@ static void Impl_HandleJoystickHatEvent(SDL_JoyHatEvent evt)
|
|||
}
|
||||
#endif
|
||||
|
||||
static void Impl_HandleJoystickButtonEvent(SDL_JoyButtonEvent evt, Uint32 type)
|
||||
static void Impl_HandleControllerButtonEvent(SDL_ControllerButtonEvent evt, Uint32 type)
|
||||
{
|
||||
event_t event;
|
||||
SDL_JoystickID joyid[MAXSPLITSCREENPLAYERS];
|
||||
|
|
@ -920,7 +939,16 @@ static void Impl_HandleJoystickButtonEvent(SDL_JoyButtonEvent evt, Uint32 type)
|
|||
|
||||
// Determine the Joystick IDs for each current open joystick
|
||||
for (i = 0; i < MAXSPLITSCREENPLAYERS; i++)
|
||||
joyid[i] = SDL_JoystickInstanceID(JoyInfo[i].dev);
|
||||
joyid[i] = SDL_JoystickInstanceID(SDL_GameControllerGetJoystick(JoyInfo[i].dev));
|
||||
|
||||
if (evt.button == SDL_CONTROLLER_BUTTON_DPAD_UP
|
||||
|| evt.button == SDL_CONTROLLER_BUTTON_DPAD_DOWN
|
||||
|| evt.button == SDL_CONTROLLER_BUTTON_DPAD_LEFT
|
||||
|| evt.button == SDL_CONTROLLER_BUTTON_DPAD_RIGHT)
|
||||
{
|
||||
// dpad buttons are mapped as the hat instead
|
||||
return;
|
||||
}
|
||||
|
||||
if (evt.which == joyid[0])
|
||||
{
|
||||
|
|
@ -939,11 +967,11 @@ static void Impl_HandleJoystickButtonEvent(SDL_JoyButtonEvent evt, Uint32 type)
|
|||
event.data1 = KEY_4JOY1;
|
||||
}
|
||||
else return;
|
||||
if (type == SDL_JOYBUTTONUP)
|
||||
if (type == SDL_CONTROLLERBUTTONUP)
|
||||
{
|
||||
event.type = ev_keyup;
|
||||
}
|
||||
else if (type == SDL_JOYBUTTONDOWN)
|
||||
else if (type == SDL_CONTROLLERBUTTONDOWN)
|
||||
{
|
||||
event.type = ev_keydown;
|
||||
}
|
||||
|
|
@ -1000,26 +1028,27 @@ void I_GetEvent(void)
|
|||
case SDL_MOUSEWHEEL:
|
||||
Impl_HandleMouseWheelEvent(evt.wheel);
|
||||
break;
|
||||
case SDL_JOYAXISMOTION:
|
||||
Impl_HandleJoystickAxisEvent(evt.jaxis);
|
||||
case SDL_CONTROLLERAXISMOTION:
|
||||
Impl_HandleControllerAxisEvent(evt.caxis);
|
||||
break;
|
||||
#if 0
|
||||
case SDL_JOYHATMOTION:
|
||||
Impl_HandleJoystickHatEvent(evt.jhat)
|
||||
break;
|
||||
#endif
|
||||
case SDL_JOYBUTTONUP:
|
||||
case SDL_JOYBUTTONDOWN:
|
||||
Impl_HandleJoystickButtonEvent(evt.jbutton, evt.type);
|
||||
case SDL_CONTROLLERBUTTONUP:
|
||||
case SDL_CONTROLLERBUTTONDOWN:
|
||||
Impl_HandleControllerButtonEvent(evt.cbutton, evt.type);
|
||||
break;
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
case SDL_JOYDEVICEADDED:
|
||||
case SDL_CONTROLLERDEVICEADDED:
|
||||
{
|
||||
// OH BOY are you in for a good time! #abominationstation
|
||||
|
||||
SDL_Joystick *newjoy = SDL_JoystickOpen(evt.jdevice.which);
|
||||
SDL_GameController *newcontroller = SDL_GameControllerOpen(evt.cdevice.which);
|
||||
|
||||
CONS_Debug(DBG_GAMELOGIC, "Joystick device index %d added\n", evt.jdevice.which + 1);
|
||||
|
||||
|
|
@ -1036,7 +1065,7 @@ void I_GetEvent(void)
|
|||
|
||||
for (i = 0; i < MAXSPLITSCREENPLAYERS; i++)
|
||||
{
|
||||
if (newjoy && (!JoyInfo[i].dev || !SDL_JoystickGetAttached(JoyInfo[i].dev)))
|
||||
if (newcontroller && (!JoyInfo[i].dev || !SDL_GameControllerGetAttached(JoyInfo[i].dev)))
|
||||
{
|
||||
UINT8 j;
|
||||
|
||||
|
|
@ -1045,14 +1074,14 @@ void I_GetEvent(void)
|
|||
if (i == j)
|
||||
continue;
|
||||
|
||||
if (JoyInfo[j].dev == newjoy)
|
||||
if (JoyInfo[j].dev == newcontroller)
|
||||
break;
|
||||
}
|
||||
|
||||
if (j == MAXSPLITSCREENPLAYERS)
|
||||
{
|
||||
// ensures we aren't overriding a currently active device
|
||||
cv_usejoystick[i].value = evt.jdevice.which + 1;
|
||||
cv_usejoystick[i].value = evt.cdevice.which + 1;
|
||||
I_UpdateJoystickDeviceIndices(0);
|
||||
}
|
||||
}
|
||||
|
|
@ -1092,21 +1121,21 @@ void I_GetEvent(void)
|
|||
|
||||
for (i = 0; i < MAXSPLITSCREENPLAYERS; i++)
|
||||
{
|
||||
if (JoyInfo[i].dev == newjoy)
|
||||
if (JoyInfo[i].dev == newcontroller)
|
||||
break;
|
||||
}
|
||||
|
||||
if (i == MAXSPLITSCREENPLAYERS)
|
||||
SDL_JoystickClose(newjoy);
|
||||
SDL_GameControllerClose(newcontroller);
|
||||
}
|
||||
break;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
case SDL_JOYDEVICEREMOVED:
|
||||
case SDL_CONTROLLERDEVICEREMOVED:
|
||||
for (i = 0; i < MAXSPLITSCREENPLAYERS; i++)
|
||||
{
|
||||
if (JoyInfo[i].dev && !SDL_JoystickGetAttached(JoyInfo[i].dev))
|
||||
if (JoyInfo[i].dev && !SDL_GameControllerGetAttached(JoyInfo[i].dev))
|
||||
{
|
||||
CONS_Debug(DBG_GAMELOGIC, "Joystick%d removed, device index: %d\n", i+1, JoyInfo[i].oldjoy);
|
||||
I_ShutdownJoystick(i);
|
||||
|
|
@ -1205,9 +1234,10 @@ void I_OsPolling(void)
|
|||
|
||||
if (consolevent)
|
||||
I_GetConsoleEvents();
|
||||
if (SDL_WasInit(SDL_INIT_JOYSTICK) == SDL_INIT_JOYSTICK)
|
||||
|
||||
if (SDL_WasInit(SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER) == (SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER))
|
||||
{
|
||||
SDL_JoystickUpdate();
|
||||
SDL_GameControllerUpdate();
|
||||
for (i = 0; i < MAXSPLITSCREENPLAYERS; i++)
|
||||
I_GetJoystickEvents(i);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,8 +41,8 @@ extern SDL_bool framebuffer;
|
|||
*/
|
||||
typedef struct SDLJoyInfo_s
|
||||
{
|
||||
/// Joystick handle
|
||||
SDL_Joystick *dev;
|
||||
/// Controller handle
|
||||
SDL_GameController *dev;
|
||||
/// number of old joystick
|
||||
int oldjoy;
|
||||
/// number of axies
|
||||
|
|
@ -58,7 +58,7 @@ typedef struct SDLJoyInfo_s
|
|||
|
||||
} SDLJoyInfo_t;
|
||||
|
||||
/** \brief SDL info about joysticks
|
||||
/** \brief SDL info about controllers
|
||||
*/
|
||||
extern SDLJoyInfo_t JoyInfo[MAXSPLITSCREENPLAYERS];
|
||||
|
||||
|
|
@ -72,8 +72,8 @@ void I_GetConsoleEvents(void);
|
|||
// So we can call this from i_video event loop
|
||||
void I_ShutdownJoystick(UINT8 index);
|
||||
|
||||
// Cheat to get the device index for a joystick handle
|
||||
INT32 I_GetJoystickDeviceIndex(SDL_Joystick *dev);
|
||||
// Cheat to get the device index for a game controller handle
|
||||
INT32 I_GetJoystickDeviceIndex(SDL_GameController *dev);
|
||||
|
||||
// Quick thing to make SDL_JOYDEVICEADDED events less of an abomination
|
||||
void I_UpdateJoystickDeviceIndex(UINT8 player);
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
// it's only for detection of the version the player is using so the MS can alert them of an update.
|
||||
// Only set it higher, not lower, obviously.
|
||||
// Note that we use this to help keep internal testing in check; this is why v2.0 is not version "2".
|
||||
#define MODVERSION 6
|
||||
#define MODVERSION 11
|
||||
|
||||
// Define this as a prerelease version suffix
|
||||
// #define BETAVERSION "Alpha"
|
||||
|
|
|
|||
Loading…
Reference in a new issue