Skip to content

Commit

Permalink
Controller hot plug support.
Browse files Browse the repository at this point in the history
  • Loading branch information
SmileTheory committed Aug 5, 2016
1 parent 1972128 commit d098668
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions code/sdl/sdl_input.c
Expand Up @@ -434,15 +434,15 @@ static void IN_InitJoystick( void )
stick = NULL;
memset(&stick_state, '\0', sizeof (stick_state));

if (!SDL_WasInit(SDL_INIT_JOYSTICK))
if (!SDL_WasInit(SDL_INIT_GAMECONTROLLER))
{
Com_DPrintf("Calling SDL_Init(SDL_INIT_JOYSTICK)...\n");
if (SDL_Init(SDL_INIT_JOYSTICK) != 0)
Com_DPrintf("Calling SDL_Init(SDL_INIT_GAMECONTROLLER)...\n");
if (SDL_Init(SDL_INIT_GAMECONTROLLER) != 0)
{
Com_DPrintf("SDL_Init(SDL_INIT_JOYSTICK) failed: %s\n", SDL_GetError());
Com_DPrintf("SDL_Init(SDL_INIT_GAMECONTROLLER) failed: %s\n", SDL_GetError());
return;
}
Com_DPrintf("SDL_Init(SDL_INIT_JOYSTICK) passed.\n");
Com_DPrintf("SDL_Init(SDL_INIT_GAMECONTROLLER) passed.\n");
}

total = SDL_NumJoysticks();
Expand All @@ -459,7 +459,7 @@ static void IN_InitJoystick( void )

if( !in_joystick->integer ) {
Com_DPrintf( "Joystick is not active.\n" );
SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
SDL_QuitSubSystem(SDL_INIT_GAMECONTROLLER);
return;
}

Expand Down Expand Up @@ -494,7 +494,7 @@ IN_ShutdownJoystick
*/
static void IN_ShutdownJoystick( void )
{
if ( !SDL_WasInit( SDL_INIT_JOYSTICK ) )
if ( !SDL_WasInit( SDL_INIT_GAMECONTROLLER ) )
return;

if (stick)
Expand All @@ -503,7 +503,7 @@ static void IN_ShutdownJoystick( void )
stick = NULL;
}

SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
SDL_QuitSubSystem(SDL_INIT_GAMECONTROLLER);
}

/*
Expand Down Expand Up @@ -840,6 +840,11 @@ static void IN_ProcessEvents( void )
}
break;

case SDL_CONTROLLERDEVICEADDED:
case SDL_CONTROLLERDEVICEREMOVED:
IN_InitJoystick();
break;

case SDL_QUIT:
Cbuf_ExecuteText(EXEC_NOW, "quit Closed window\n");
break;
Expand Down

0 comments on commit d098668

Please sign in to comment.