Closed vchelaru closed 2 months ago
UWP uses the Windows.Gaming.Input
API for gamepads:
https://github.com/MonoGame/MonoGame/blob/develop/MonoGame.Framework/Input/GamePad.UWP.cs
I don't see any special initialization in this code which suggests to me that WGI internally depends on some other system we enable/trigger/initialize during base.Initialize()
.
I suggest stepping into base.Initialize()
and put Windows.Gaming.Input.Gamepad.Gamepads.Count
in the watch window. Then as you step you should see the count go up from zero once the code that "enables" the gamepads is triggered.
@cra0zy - You did the UWP input code here originally. Have any ideas?
I don't see any special initialization in this code which suggests to me that WGI internally depends on some other system we enable/trigger/initialize during base.Initialize(). I suggest stepping into base.Initialize() ...
Apologies if this wasn't clearly explained above, even if I call base.Initialize() before looking at at the connected, the value is still false for the entirety of the Initialize call.
So I'd guess the critical code isn't in base.Initialize(), but rather somewhere else before Update().
but rather somewhere else before Update().
Oh... i mis-read that. Sorry.
Well then it is deeper in. Still stepping thru the bowels of MG code with Windows.Gaming.Input.Gamepad.Gamepads.Count
in the Watch Window should let you detect the specific call where it starts working.
Long story short: https://docs.microsoft.com/en-us/uwp/api/windows.gaming.input.gamepad
Remarks This list is initally empty and will not list gamepads even if they are already connected. After a short period this will return a complete list of gamepads.
After a short period this will return a complete list of gamepads.
Uggh... yuck!
Hack... if we put a 5 second delay at launch does it hack around this issue?
Hack... if we put a 5 second delay at launch does it hack around this issue?
Do we really want a 5 second delay due to this?
Do we really want a 5 second delay due to this?
Not really... just wondering if just waiting a bit solves it.
If so i could see the UWP code look like this:
RETRY:
if (Gamepad.Gamepads.Count == 0)
{
if (FirstCall)
{
FirstCall = false;
Sleep(1000);
goto RETRY;
}
return GetDefaultState();
}
or something like that.
I don't know if it's on a separate thread, but I did put a breakpoint in the Init method and let it sit, then proceeded - it still returned false.
I did put a breakpoint in the Init method and let it sit, then proceeded - it still returned false.
Well a breakpoint stops all threads in the application. So i wouldn't expect that to do it. If you put a Sleep in there it might work.
Or it might just depend on some messages pumping in UWP and we can do nothing about it.
Take look at: https://github.com/Microsoft/DirectXTK/blob/master/Src/GamePad.cpp maybe we need to attach to added/removed or rework the gamepad logic
Good idea to check DirectXTK @amerkoleci !
@cra0zy @vchelaru ?
Possible, someone would need to test it out ofc.
I'm closing out this issue since I don't think anyone cares about UWP anymore. Per @AristurtleDev 's request I'm tagging @SimonDarksideJ in case this really should be left open.
Summary
The following code returns
false
on MonoGame UWP when a controller is connected inGame.Initialize
, but returnstrue
in Microsoft XNA:Code Example
To reproduce:
Note that some functions (such as Draw) have been removed for brevity. They are not necessary to reproduce the bug.
Additional Information and Workarounds
The
IsConnected
property will accurately reflect the connected state of a game pad in a game's Update method (after Initialize has finished). The issue is isolated specifically to the Initialize method. Changing the code to callbase.Initialize()
before getting the GamePad state does not fix the bug.Why does this matter?
Tutorials and simple games may query the connected state of the GamePad to identify whether to use gamepad controls or keyboard controls. This behavior may lead programmers to believe that controller support is broken in UWP, when it in fact is not.