hid: clean-up

This commit is contained in:
Hyper 2024-12-11 23:06:20 +00:00
parent 86c60e7bbe
commit 099dde82a2

View file

@ -169,48 +169,29 @@ int HID_OnSDLEvent(void*, SDL_Event* event)
{
switch (event->type)
{
case SDL_KEYDOWN:
case SDL_KEYUP:
hid::detail::g_inputDevice = hid::detail::EInputDevice::Keyboard;
break;
case SDL_MOUSEMOTION:
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP:
hid::detail::g_inputDevice = hid::detail::EInputDevice::Mouse;
break;
case SDL_WINDOWEVENT:
{
if (event->window.event == SDL_WINDOWEVENT_FOCUS_LOST)
{
// Stop vibrating controllers on focus lost.
for (auto& controller : g_controllers)
controller.SetVibration({ 0, 0 });
}
break;
}
default:
{
if (event->type >= SDL_CONTROLLERAXISMOTION && event->type < SDL_FINGERDOWN)
{
if (event->type == SDL_CONTROLLERDEVICEADDED)
case SDL_CONTROLLERDEVICEADDED:
{
const auto freeIndex = FindFreeController();
if (freeIndex != -1)
g_controllers[freeIndex] = Controller(event->cdevice.which);
break;
}
if (event->type == SDL_CONTROLLERDEVICEREMOVED)
case SDL_CONTROLLERDEVICEREMOVED:
{
auto* controller = FindController(event->cdevice.which);
if (controller)
controller->Close();
break;
}
else if (event->type == SDL_CONTROLLERBUTTONDOWN || event->type == SDL_CONTROLLERBUTTONUP || event->type == SDL_CONTROLLERAXISMOTION)
case SDL_CONTROLLERBUTTONDOWN:
case SDL_CONTROLLERBUTTONUP:
case SDL_CONTROLLERAXISMOTION:
{
auto* controller = FindController(event->cdevice.which);
@ -230,7 +211,28 @@ int HID_OnSDLEvent(void*, SDL_Event* event)
controller->Poll();
}
}
break;
}
case SDL_KEYDOWN:
case SDL_KEYUP:
hid::detail::g_inputDevice = hid::detail::EInputDevice::Keyboard;
break;
case SDL_MOUSEMOTION:
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP:
hid::detail::g_inputDevice = hid::detail::EInputDevice::Mouse;
break;
case SDL_WINDOWEVENT:
{
if (event->window.event == SDL_WINDOWEVENT_FOCUS_LOST)
{
// Stop vibrating controllers on focus lost.
for (auto& controller : g_controllers)
controller.SetVibration({ 0, 0 });
}
break;