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

@ -222,8 +222,9 @@ int32_t handleevents_peekkeys(void);
extern void (*keypresscallback)(int32_t,int32_t);
extern void (*g_mouseCallback)(int32_t,int32_t);
extern void (*g_controllerHotplugCallback)(void);
int32_t initinput(void);
int32_t initinput(void(*hotplugCallback)(void) = NULL);
void uninitinput(void);
void keySetCallback(void (*callback)(int32_t,int32_t));
void mouseSetCallback(void (*callback)(int32_t,int32_t));

View file

@ -102,6 +102,8 @@ bool g_mouseLockedToWindow = 1;
void (*g_mouseCallback)(int32_t, int32_t);
void mouseSetCallback(void(*callback)(int32_t, int32_t)) { g_mouseCallback = callback; }
void (*g_controllerHotplugCallback)(void);
int32_t mouseAdvanceClickState(void)
{
switch (g_mouseClickState)

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)

View file

@ -683,7 +683,7 @@ int32_t handleevents(void)
//
// initinput() -- init input system
//
int32_t initinput(void)
int32_t initinput(void(*hotplugCallback)(void) /*= NULL*/)
{
Win_GetOriginalLayoutName();
Win_SetKeyboardLayoutUS(1);

View file

@ -955,7 +955,7 @@ bool CONTROL_Startup(controltype which, int32_t(*TimeFunction)(void), int32_t ti
if (CONTROL_DoubleClickSpeed <= 0)
CONTROL_DoubleClickSpeed = 1;
if (initinput())
if (initinput(CONTROL_ScanForControllers))
return true;
KB_Startup();