mirror of
https://github.com/hedge-dev/UnleashedRecomp.git
synced 2025-10-30 07:11:05 +00:00
hid: clean-up
This commit is contained in:
parent
86c60e7bbe
commit
099dde82a2
1 changed files with 46 additions and 44 deletions
|
|
@ -169,6 +169,52 @@ int HID_OnSDLEvent(void*, SDL_Event* event)
|
||||||
{
|
{
|
||||||
switch (event->type)
|
switch (event->type)
|
||||||
{
|
{
|
||||||
|
case SDL_CONTROLLERDEVICEADDED:
|
||||||
|
{
|
||||||
|
const auto freeIndex = FindFreeController();
|
||||||
|
|
||||||
|
if (freeIndex != -1)
|
||||||
|
g_controllers[freeIndex] = Controller(event->cdevice.which);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case SDL_CONTROLLERDEVICEREMOVED:
|
||||||
|
{
|
||||||
|
auto* controller = FindController(event->cdevice.which);
|
||||||
|
|
||||||
|
if (controller)
|
||||||
|
controller->Close();
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case SDL_CONTROLLERBUTTONDOWN:
|
||||||
|
case SDL_CONTROLLERBUTTONUP:
|
||||||
|
case SDL_CONTROLLERAXISMOTION:
|
||||||
|
{
|
||||||
|
auto* controller = FindController(event->cdevice.which);
|
||||||
|
|
||||||
|
if (controller)
|
||||||
|
{
|
||||||
|
if (event->type == SDL_CONTROLLERAXISMOTION)
|
||||||
|
{
|
||||||
|
if (abs(event->caxis.value) > 8000)
|
||||||
|
SetControllerInputDevice(controller);
|
||||||
|
|
||||||
|
controller->PollAxis();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SetControllerInputDevice(controller);
|
||||||
|
|
||||||
|
controller->Poll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case SDL_KEYDOWN:
|
case SDL_KEYDOWN:
|
||||||
case SDL_KEYUP:
|
case SDL_KEYUP:
|
||||||
hid::detail::g_inputDevice = hid::detail::EInputDevice::Keyboard;
|
hid::detail::g_inputDevice = hid::detail::EInputDevice::Keyboard;
|
||||||
|
|
@ -191,50 +237,6 @@ int HID_OnSDLEvent(void*, SDL_Event* event)
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
if (event->type >= SDL_CONTROLLERAXISMOTION && event->type < SDL_FINGERDOWN)
|
|
||||||
{
|
|
||||||
if (event->type == SDL_CONTROLLERDEVICEADDED)
|
|
||||||
{
|
|
||||||
const auto freeIndex = FindFreeController();
|
|
||||||
|
|
||||||
if (freeIndex != -1)
|
|
||||||
g_controllers[freeIndex] = Controller(event->cdevice.which);
|
|
||||||
}
|
|
||||||
if (event->type == SDL_CONTROLLERDEVICEREMOVED)
|
|
||||||
{
|
|
||||||
auto* controller = FindController(event->cdevice.which);
|
|
||||||
|
|
||||||
if (controller)
|
|
||||||
controller->Close();
|
|
||||||
}
|
|
||||||
else if (event->type == SDL_CONTROLLERBUTTONDOWN || event->type == SDL_CONTROLLERBUTTONUP || event->type == SDL_CONTROLLERAXISMOTION)
|
|
||||||
{
|
|
||||||
auto* controller = FindController(event->cdevice.which);
|
|
||||||
|
|
||||||
if (controller)
|
|
||||||
{
|
|
||||||
if (event->type == SDL_CONTROLLERAXISMOTION)
|
|
||||||
{
|
|
||||||
if (abs(event->caxis.value) > 8000)
|
|
||||||
SetControllerInputDevice(controller);
|
|
||||||
|
|
||||||
controller->PollAxis();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
SetControllerInputDevice(controller);
|
|
||||||
|
|
||||||
controller->Poll();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue