mono/MonoGame — pull request #2000 by tomspilman (2013-09-17 03:21:19+00:00)
Title: GamePad XInput Performance

This PR fixes some bugs as well as addresses some issues which caused bad performance of `GamePad.GetState()` and `GamePad.GetCapabilities()` on Windows Store and Windows desktop.

- GamePad now throws InvalidOperationException when called with a bad player index.
- Removed all redundant namespace qualifications.
- Removed excessive function call nesting in GamePad methods.
- Removed uses of extremely slow Enum.HasFlag() in GamePad.
- Fixed GamePadCapabilities.HasDPadRightButton which was incorrectly testing the left dpad button state.
- GamePad.GetState() was essentially doing double the work by calling IsConnected.
- We now throttle the rate at which we check disconnected gamepads.

That last item... the throttling of checking the connected state of disconnected gamepads is a big one. It seems like a disconnected gamepad takes longer to report back state than a connected one. This overhead adds up when you check state once per frame at 60fps. By only re-trying the disconnected state once per-second we save alot of CPU time.

I've only tested on Windows DirectX desktop apps... it would be good to test on some Windows Store apps as well.