void WindowsGamepadService::ScanForDevices() { for (int i = mGamepads.Length() - 1; i >= 0; i--) { mGamepads[i].present = false; } if (mHID) { ScanForRawInputDevices(); } if (mXInput) { mXInputPollTimer->Cancel(); if (ScanForXInputDevices()) { mXInputPollTimer->InitWithFuncCallback(XInputPollTimerCallback, this, kXInputPollInterval, nsITimer::TYPE_REPEATING_SLACK); } } // Look for devices that are no longer present and remove them. for (int i = mGamepads.Length() - 1; i >= 0; i--) { if (!mGamepads[i].present) { RemoveGamepad(mGamepads[i].id); mGamepads.RemoveElementAt(i); } } }
void GamepadService::Update(const GamepadChangeEvent& aEvent) { if (aEvent.type() == GamepadChangeEvent::TGamepadAdded) { const GamepadAdded& a = aEvent.get_GamepadAdded(); AddGamepad(a.index(), a.id(), static_cast<GamepadMappingType>(a.mapping()), a.num_buttons(), a.num_axes()); } else if (aEvent.type() == GamepadChangeEvent::TGamepadRemoved) { const GamepadRemoved& a = aEvent.get_GamepadRemoved(); RemoveGamepad(a.index()); } else if (aEvent.type() == GamepadChangeEvent::TGamepadButtonInformation) { const GamepadButtonInformation& a = aEvent.get_GamepadButtonInformation(); NewButtonEvent(a.index(), a.button(), a.pressed(), a.value()); } else if (aEvent.type() == GamepadChangeEvent::TGamepadAxisInformation) { const GamepadAxisInformation& a = aEvent.get_GamepadAxisInformation(); NewAxisMoveEvent(a.index(), a.axis(), a.value()); } else { MOZ_CRASH("We shouldn't be here!"); } }