This has been mentioned here before, but we are also having problems with XInputGetState performance with code similar to the DX SDK sample code. I have modified the "XInput Sample: SimpleController" code to profile around the for loop that calls XInputGetState(). This code takes over
1.6ms when less than 4 controllers are plugged in. I assume this is because it is attempting to enumerate other devices.
If the code is changed to poll for a single controller that is plugged in, the XInputGetState call takes
.08ms. So it appears that one should *
not* call this code the way it is done in the samples. This should be made clear in the documentation and the sample code if this is the case as 1.6ms is a substantial amount of frame time.
So if this is not the correct way to poll for controller changes, what are people using to detect that a new controller is available? It would be nice if it behaved more like the X360 using a callback for detection. The best I can come up with is to set a flag to only have it call XInputGetState when on a screen that is initially trying to detect a new controller. However, we have seen the controller id change from "1" to "2" or "3" when unplugging a controller. So if a user accidentally pulls out a controller while playing this could be a problem.
We have also noticed that with two controllers plugged in, removing one and replugging it will often not detect the reinserted controller. This happens in the SimpleController sample under 64bit Vista, though I imagine it's a problem on all OSes.
Thanks for the help,
-Douglas Cox
Engine Programming Director
Vicious Cycle Software, Inc.