-
-
Notifications
You must be signed in to change notification settings - Fork 22
refactor!: Update to windows GameInput api #81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Breaking change: event keys does change as well as the value range of axis input. Fixes: * Crash when gamepad is disconnected * Possible stale thread on disconnect * Sleep(4) in input loop to reduce CPU load
|
Not sure if this is a "fix" or "feat" PR. but the motivation is to fix issues and make it more stable. Which is yet to find out if this is/becomes more stable overall than the current windows bindings. The new API is just the means I ended up following as it has potential to remove the read thread entirely if GameInput RegisterReadingCallback() actually would work. |
|
Since buttons now use named values like "a", "b", "menu" etc. I decided to drop the "button-" leading part of the key. I did take a look on other platforms and could not see that they use this prefix so decided to drop it for slightly shorter key values. |
Maybe a |
|
Great Work! I have been waiting for this for very long time. :) |
|
|
||
| std::cout << "Gamepad connected: " << gp->id << " : " << gp->name << std::endl; | ||
|
|
||
| std::thread read_thread( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we still have a thread reading the gamepad state?Can we use RegisterReadingCallback to listen to the update of gamepad states?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have an experiment branch on my github using that. I haven't wired it up back to Flutter, but it prints out to the log when those events are recevied.
However, it requires both developers and end-users to install an MSI that the NuGet package downloads which requires elevated user privileges in Windows.
I had a chat with @spydon in discord where we decided that due to that limitation, it was better to stay at GameInput v0 which this PR uses that does not require this MSI to be installed in order to receive gamepad data.
That said, if you have a game title that ship with an installer, at that point it probably is doable to include it. But then I think it is more and more common for even games to install to you user folder to skip the elevated user privileges dialog.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it wasn't for the requirement to install this .msi-file, I am all with you and I think using the callback would be better as GameInput itself has an input thread that calls the callback.
Now it is a question of priority - easy setup and easy distribution vs best possible performance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense!
|
Hi! I'm currently trying out your implementation and I'm struggling with Is there anything special I need to install? I installed Microsoft GDK and fiddled a bit with the CMakeLists.txt of my project. I have limited experience with Windows dev |
For me the file is located at this path: I believe that is Windows SDK which I think has been a requirement for Flutter on Windows, potentially via Visual Studio. I am also a bit of a beginner in how to manage C++ dependencies in Windows, so potentially made a mistake here by assuming that Windows SDK can be taken for granted. |
|
I see now, the install instructions for Windows as a target, does still require installing Visual Studio and the Desktop Development C++ task. I am still not sure if that installs Windows SDK or not for you. It would be helpful to know if it is the case that it will make Windows SDK installed or not. Especially because if it doesn't, this PR likely has to use NuGet to get the header files. |
|
I set up a new Windows machine following the official instructions (Visual Studio + C++) and it worked without issues. My initial issue was also fixed by... a restart. What I did notice is that the analog button values are reported in the opposite format to that on e.g. Android. For my test device (an 8bitdo mini) Windows reports button pressed as 1.0 and button released as 0.0. I have yet to confirm if it's the same case when not using your fork. EDIT: also happens without your fork |
Breaking changes:
Event keys does change. The new axis names are based on GameInputGamepadState. The new button names are based on GameInputGamepadButtons
dwXpos->leftThumbstickXdwYpos->leftThumbstickYbutton-0=>abutton-1=>bThe range of analog axises has changed to [-1.0, 1.0].
Gampad id:s are different. It now uses GameInputDeviceInfo.deviceId.
Fixes:
Sleep(1) in input loop to reduce CPU load High CPU usage #54I used Sleep(8), then 4, but had issues with missing events so I am down to Sleep(1) in the PR, so might not be the best CPU reduction at the current state.Non-goal
For now as it appears that the different platforms use different names on buttons, axis etc. I have not tried to mimic a different platform in the gamepads library, but instead tries to keep it close to GameInput API, which does break against the current windows bindings.
Testing/feedback
Feel free to test this out. For me it works, but love if people test it out, break it and report issues or suggest fixes. :)
Pop this in your pubspec.yaml to use this PR: