This should be enough for SDL controller hotplug support but I haven't tested it

git-svn-id: https://svn.eduke32.com/eduke32@8003 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2019-08-14 14:26:53 +00:00 committed by Christoph Oelckers
parent c72a69ff6f
commit 7ec6a6beca
5 changed files with 31 additions and 7 deletions

View file

@ -825,6 +825,8 @@ static void LoadSDLControllerDB()
}
#endif
static int numjoysticks;
void joyScanDevices()
{
inputdevices &= ~4;
@ -840,7 +842,8 @@ void joyScanDevices()
joydev = nullptr;
}
int numjoysticks = SDL_NumJoysticks();
numjoysticks = SDL_NumJoysticks();
if (numjoysticks < 1)
{
buildputs("No game controllers found\n");
@ -925,10 +928,20 @@ void joyScanDevices()
//
// initinput() -- init input system
//
int32_t initinput(void)
int32_t initinput(void(*hotplugCallback)(void) /*= NULL*/)
{
int32_t i;
#if SDL_MAJOR_VERSION >= 2
if (hotplugCallback)
{
g_controllerHotplugCallback = hotplugCallback;
SDL_JoystickEventState(SDL_ENABLE);
}
#else
UNREFERENCED_PARAMETER(hotplugCallback);
#endif
#ifdef _WIN32
Win_GetOriginalLayoutName();
Win_SetKeyboardLayoutUS(1);
@ -974,7 +987,6 @@ int32_t initinput(void)
#if SDL_MAJOR_VERSION >= 2
LoadSDLControllerDB();
#endif
joyScanDevices();
}
@ -2099,7 +2111,13 @@ int32_t handleevents_sdlcommon(SDL_Event *ev)
break;
# endif
#endif
#if SDL_MAJOR_VERSION >= 2
case SDL_CONTROLLERDEVICEADDED:
case SDL_CONTROLLERDEVICEREMOVED:
if (g_controllerHotplugCallback && SDL_NumJoysticks() != numjoysticks)
g_controllerHotplugCallback();
break;
#endif
case SDL_JOYAXISMOTION:
#if SDL_MAJOR_VERSION >= 2
if (joystick.isGameController)
@ -2187,6 +2205,9 @@ int32_t handleevents_pollsdl(void)
int32_t code, rv=0, j;
SDL_Event ev;
if (g_controllerHotplugCallback && SDL_NumJoysticks() != numjoysticks)
g_controllerHotplugCallback();
while (SDL_PollEvent(&ev))
{
switch (ev.type)