Throttle hotplug re-enumeration retries and reduce log noise
This commit is contained in:
parent
5f41d9a4c3
commit
e94f0c5990
1 changed files with 25 additions and 5 deletions
|
|
@ -25,6 +25,7 @@ static bool isKeyboardMouseInputAllowed()
|
|||
#define MOUSE_EMULATION_POLLING_INTERVAL 50
|
||||
|
||||
#define HOTPLUG_REENUMERATION_INTERVAL_MS 2000
|
||||
#define HOTPLUG_REENUMERATION_MAX_INTERVAL_MS 8000
|
||||
|
||||
// Determines how fast the mouse will move each interval
|
||||
#define MOUSE_EMULATION_MOTION_MULTIPLIER 4
|
||||
|
|
@ -102,6 +103,8 @@ SdlInputHandler::ensureStateForGamepad(SDL_JoystickID id)
|
|||
void SdlInputHandler::pollForMissingGamepads()
|
||||
{
|
||||
static uint32_t s_LastForcedReenumerationTick = 0;
|
||||
static uint32_t s_ReenumerationIntervalMs = HOTPLUG_REENUMERATION_INTERVAL_MS;
|
||||
static uint32_t s_ReenumerationAttempts = 0;
|
||||
|
||||
SDL_JoystickUpdate();
|
||||
SDL_GameControllerUpdate();
|
||||
|
|
@ -138,6 +141,11 @@ void SdlInputHandler::pollForMissingGamepads()
|
|||
m_LastJoystickCount = joystickCount;
|
||||
}
|
||||
|
||||
if (joystickCount > 0) {
|
||||
s_ReenumerationAttempts = 0;
|
||||
s_ReenumerationIntervalMs = HOTPLUG_REENUMERATION_INTERVAL_MS;
|
||||
}
|
||||
|
||||
for (int i = 0; i < MAX_GAMEPADS; i++) {
|
||||
GamepadState* state = &m_GamepadState[i];
|
||||
if (state->controller == nullptr) {
|
||||
|
|
@ -156,7 +164,7 @@ void SdlInputHandler::pollForMissingGamepads()
|
|||
continue;
|
||||
}
|
||||
|
||||
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
|
||||
"Polling detected disconnected gamepad instance %d in slot %d; cleaning up",
|
||||
state->jsId,
|
||||
i);
|
||||
|
|
@ -171,11 +179,14 @@ void SdlInputHandler::pollForMissingGamepads()
|
|||
|
||||
if (joystickCount == 0) {
|
||||
uint32_t now = SDL_GetTicks();
|
||||
if (SDL_TICKS_PASSED(now, s_LastForcedReenumerationTick + HOTPLUG_REENUMERATION_INTERVAL_MS)) {
|
||||
if (SDL_TICKS_PASSED(now, s_LastForcedReenumerationTick + s_ReenumerationIntervalMs)) {
|
||||
s_LastForcedReenumerationTick = now;
|
||||
s_ReenumerationAttempts++;
|
||||
|
||||
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
|
||||
"No joysticks visible; forcing SDL joystick/gamecontroller re-enumeration");
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
|
||||
"No joysticks visible; forcing SDL joystick/gamecontroller re-enumeration (attempt %u, interval %u ms)",
|
||||
s_ReenumerationAttempts,
|
||||
s_ReenumerationIntervalMs);
|
||||
|
||||
SDL_QuitSubSystem(SDL_INIT_GAMECONTROLLER);
|
||||
SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
|
||||
|
|
@ -210,6 +221,15 @@ void SdlInputHandler::pollForMissingGamepads()
|
|||
}
|
||||
|
||||
recoverUntrackedGamepads(joystickCount);
|
||||
|
||||
if (joystickCount > 0) {
|
||||
s_ReenumerationAttempts = 0;
|
||||
s_ReenumerationIntervalMs = HOTPLUG_REENUMERATION_INTERVAL_MS;
|
||||
}
|
||||
else {
|
||||
s_ReenumerationIntervalMs = qMin(s_ReenumerationIntervalMs * 2,
|
||||
static_cast<uint32_t>(HOTPLUG_REENUMERATION_MAX_INTERVAL_MS));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -777,7 +797,7 @@ void SdlInputHandler::handleControllerDeviceEvent(SDL_ControllerDeviceEvent* eve
|
|||
// before we've processed the add event.
|
||||
for (int i = 0; i < MAX_GAMEPADS; i++) {
|
||||
if (m_GamepadState[i].controller != nullptr && m_GamepadState[i].jsId == jsId) {
|
||||
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
|
||||
"Received duplicate add event for joystick instance ID: %d",
|
||||
jsId);
|
||||
SDL_GameControllerClose(controller);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue