sdl2: restore joystick code

remarkably it still works even though the API has changed.
This commit is contained in:
Ronald Kinard 2014-04-06 21:43:40 -05:00
parent 6ea03a23b4
commit 080f8e4008
2 changed files with 64 additions and 14 deletions

View File

@ -994,10 +994,8 @@ void I_GetJoystickEvents(void)
static event_t event = {0,0,0,0};
INT32 i = 0;
UINT64 joyhats = 0;
#if 0
UINT64 joybuttons = 0;
Sint16 axisx, axisy;
#endif
if (!joystick_started) return;
@ -1070,7 +1068,6 @@ void I_GetJoystickEvents(void)
}
}
#if 0
// send joystick axis positions
event.type = ev_joystick;
@ -1123,7 +1120,6 @@ void I_GetJoystickEvents(void)
}
D_PostEvent(&event);
}
#endif
}
/** \brief Open joystick handle
@ -1136,8 +1132,6 @@ void I_GetJoystickEvents(void)
*/
static int joy_open(const char *fname)
{
return -1; // TODO SDL2 joystick overhaul
#if 0
int joyindex = atoi(fname);
int num_joy = 0;
int i;
@ -1225,7 +1219,6 @@ static int joy_open(const char *fname)
return JoyInfo.axises;
}
#endif
}
//Joystick2
@ -1291,10 +1284,8 @@ void I_GetJoystick2Events(void)
static event_t event = {0,0,0,0};
INT32 i = 0;
UINT64 joyhats = 0;
#if 0
INT64 joybuttons = 0;
INT32 axisx, axisy;
#endif
if (!joystick2_started)
return;
@ -1364,7 +1355,6 @@ void I_GetJoystick2Events(void)
}
}
#if 0
// send joystick axis positions
event.type = ev_joystick2;
@ -1419,7 +1409,6 @@ void I_GetJoystick2Events(void)
}
D_PostEvent(&event);
}
#endif
}
@ -1433,8 +1422,6 @@ void I_GetJoystick2Events(void)
*/
static int joy_open2(const char *fname)
{
return -1; // TODO SDL2 joystick overhaul
#if 0
int joyindex = atoi(fname);
int num_joy = 0;
int i;
@ -1520,7 +1507,6 @@ static int joy_open2(const char *fname)
return JoyInfo2.axises;
}
#endif
}
//

View File

@ -918,6 +918,63 @@ static void Impl_HandleMouseWheelEvent(SDL_MouseWheelEvent evt)
}
}
static void Impl_HandleJoystickAxisEvent(SDL_JoyAxisEvent evt)
{
event_t event;
evt.which++;
evt.axis++;
event.data1 = event.data2 = event.data3 = INT32_MAX;
if (cv_usejoystick.value == evt.which)
{
event.type = ev_joystick;
}
else if (cv_usejoystick.value == evt.which)
{
event.type = ev_joystick2;
}
else return;
//axis
if (evt.axis > JOYAXISSET*2)
return;
//vaule
if (evt.axis%2)
{
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);
}
D_PostEvent(&event);
}
static void Impl_HandleJoystickButtonEvent(SDL_JoyButtonEvent evt, Uint32 type)
{
event_t event;
evt.which++;
if (cv_usejoystick.value == evt.which)
event.data1 = KEY_JOY1;
else if (cv_usejoystick.value == evt.which)
event.data1 = KEY_2JOY1;
else return;
if (type == SDL_JOYBUTTONUP)
event.type = ev_keyup;
else if (type == SDL_JOYBUTTONDOWN)
event.type = ev_keydown;
else return;
if (evt.button < JOYBUTTONS)
event.data1 += evt.button;
else
return;
SDLJoyRemap(&event);
if (event.type != ev_console) D_PostEvent(&event);
}
void I_GetEvent(void)
{
SDL_Event evt;
@ -948,6 +1005,13 @@ void I_GetEvent(void)
case SDL_MOUSEWHEEL:
Impl_HandleMouseWheelEvent(evt.wheel);
break;
case SDL_JOYAXISMOTION:
Impl_HandleJoystickAxisEvent(evt.jaxis);
break;
case SDL_JOYBUTTONUP:
case SDL_JOYBUTTONDOWN:
Impl_HandleJoystickButtonEvent(evt.jbutton, evt.type);
break;
case SDL_QUIT:
I_Quit();
M_QuitResponse('y');