Add option to disable SDL joystick support.

This also adds some extra sanity checks to avoid crashes when the joystick isn't initialized.
This commit is contained in:
Cacodemon345 2020-06-04 15:48:59 +06:00 committed by alexey.lysiuk
parent 5151dff03c
commit 9bf0f9bbfc
2 changed files with 11 additions and 3 deletions

View file

@ -159,6 +159,11 @@ else()
endif()
endif()
option( NO_SDL_JOYSTICK "Disable SDL joystick support (Not applicable to Windows)" OFF )
if ( NO_SDL_JOYSTICK )
add_definitions( -DNO_SDL_JOYSTICK=1 )
endif ( NO_SDL_JOYSTICK )
if( NO_GTK )
add_definitions( -DNO_GTK )
elseif( DYN_GTK )

View file

@ -300,8 +300,10 @@ static SDLInputJoystickManager *JoystickManager;
void I_StartupJoysticks()
{
#ifndef NO_SDL_JOYSTICK
if(SDL_InitSubSystem(SDL_INIT_JOYSTICK) >= 0)
JoystickManager = new SDLInputJoystickManager();
#endif
}
void I_ShutdownInput()
{
@ -316,7 +318,8 @@ void I_GetJoysticks(TArray<IJoystickConfig *> &sticks)
{
sticks.Clear();
JoystickManager->GetDevices(sticks);
if (JoystickManager)
JoystickManager->GetDevices(sticks);
}
void I_GetAxes(float axes[NUM_JOYAXIS])
@ -325,7 +328,7 @@ void I_GetAxes(float axes[NUM_JOYAXIS])
{
axes[i] = 0;
}
if (use_joystick)
if (use_joystick && JoystickManager)
{
JoystickManager->AddAxes(axes);
}
@ -333,7 +336,7 @@ void I_GetAxes(float axes[NUM_JOYAXIS])
void I_ProcessJoysticks()
{
if (use_joystick)
if (use_joystick && JoystickManager)
JoystickManager->ProcessInput();
}