The Wayback Machine - https://web.archive.org/web/20200603214631/https://github.com/MonoGame/MonoGame/issues/7019
Skip to content
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

SDL GamePad - Allow adding mappings from file #7019

Open
tdeeb opened this issue Feb 12, 2020 · 7 comments
Open

SDL GamePad - Allow adding mappings from file #7019

tdeeb opened this issue Feb 12, 2020 · 7 comments

Comments

@tdeeb
Copy link
Contributor

@tdeeb tdeeb commented Feb 12, 2020

I have several obscure controllers that aren't yet in SDL's database, so I'm unable to use the GamePad API with them. MonoGame loads the SDL controller database on startup, but there is no way to supply your own file to load in, if, for instance, the player's controller isn't supported by SDL. While I plan to submit a PR with the mappings for my controllers to SDL, the average player won't be willing to do this to play a game they bought with their favorite controller.

The idea would be to provide something like a static GamePad.LoadMappingsFromFile(string file) method that would call Sdl.RwFromMem followed by Sdl.GameController.AddMappingFromRw to register the new controller mappings, just like the initial database load.

What version of MonoGame does the bug occur on:

  • Develop

What operating system are you using:

  • Windows, Linux

What MonoGame platform are you using:

  • DesktopGL
@harry-cpp
Copy link
Member

@harry-cpp harry-cpp commented Feb 12, 2020

You can just call the native Sdl method if you need to.

If you are playing your game using Steam, and you configured the controller in the Steam big picture mode, the games that are using Sdl will recognize your controller.

@tdeeb
Copy link
Contributor Author

@tdeeb tdeeb commented Feb 12, 2020

I tested this out using the native SDL calls and there's a caveat: if the controller is already plugged in before adding the mappings, the player will need to unplug and replug the controller because the controller isn't recognized as a gamepad yet. This would be required on every launch of the game.

However, I found that the controller is picked up as a gamepad while plugged in only if the mappings are added before the first SDL event loop is fired, which means it has to be in the constructor to your game (Ex. Game1.cs). I feel there may be some room for improvement (Ex. a ReconnectDevice method the developer can call if a Joystick is connected but the GamePad at the same index isn't).

@Jjagg
Copy link
Contributor

@Jjagg Jjagg commented Feb 13, 2020

I'm fine with adding API to check for gamepads.
Edit: actually would it be enough to let users specify a custom gamepad mapping file?

@harry-cpp
Copy link
Member

@harry-cpp harry-cpp commented Feb 13, 2020

I'm fine with adding APIs per platforms (I know of a few I could use myself), but we need to setup an API for that. We shouldn't be just adding it to the Gamepad class, etc.

@Apostolique
Copy link

@Apostolique Apostolique commented Feb 15, 2020

I really dislike fragmentation in the API between platforms. It forces me to write code like https://github.com/Apostolique/Apos.Input/blob/master/Source/InputHelper.cs#L112

https://github.com/Apostolique/Apos.Input/blob/master/Source/InputHelper.cs#L166

(If there's a better way to do what I did above, I'd be really interested.)

If the API is different in some platforms, I think a stub that does nothing should be provided for the other platforms.

@harry-cpp
Copy link
Member

@harry-cpp harry-cpp commented Feb 15, 2020

Yes, that is why I said what I said above.

@Jjagg
Copy link
Contributor

@Jjagg Jjagg commented Feb 16, 2020

Yes, I believe all API should be shared as well. Per platform API is very bad for portability, which is supposed to be a key selling point of MG, so we don't want to compromise on it.

But in this case I think we can have a build setting to override the gamepad mapping file, so we don't have to add API that does not make sense for all platforms.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.