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

The binding of joystick buttons is different from SDL 1.2 to SDL 2.0 #2193

Closed
Noxalus opened this issue Mar 6, 2014 · 10 comments
Closed

The binding of joystick buttons is different from SDL 1.2 to SDL 2.0 #2193

Noxalus opened this issue Mar 6, 2014 · 10 comments
Labels

Comments

@Noxalus
Copy link
Contributor

Noxalus commented Mar 6, 2014

I work on a multiplatform project that use SDL 2.0 for other targets than HTML 5 that use SDL 1.2.

But for a reason I don't know, the value of event.jbutton.button (for SDL_JOYBUTTONUP or SDL_JOYBUTTONDOWN) is different between SDL 1.2 and SDL 2.0.

Do you know why and where I can found the source code which is causing the problem ?

Thanks in advance.

@Noxalus
Copy link
Contributor Author

Noxalus commented Mar 6, 2014

To complete my question, here is the binding IDs of each button for a classic Xbox 360 gamepad with SDL 1.2 and SDL 2.0:

Buttons SDL 1.2 SDL 2.0
A 0 10
B 1 11
X 2 12
Y 3 13
Home Not a button 14
LB 4 8
RB 5 9
LT 6 Not a button (axis)
RT 7 Not a button (axis)
Select 8 5
Start 9 4
L3 10 6
R3 11 7
DPad Up 12 0
DPad Down 13 1
DPad Left 14 2
DPad Right 15 3
Infos SDL 1.2 SDL 2.0
SDL_JoystickName Xbox 360 Controller (XInput STANDARD GAMEPAD) XInput Controller #1
SDL_JoystickNumAxes 4 6
SDL_JoystickNumButtons 16 15

@haneefmubarak
Copy link
Contributor

As far as I can tell, (almost) everything related to SDL ought to be in:

/system/include/SDL

@Noxalus
Copy link
Contributor Author

Noxalus commented Mar 6, 2014

I found a post in relation with my question: http://forums.libsdl.org/viewtopic.php?t=9205

It seems that this problem can be resolved using the new Gamepad API of SDL 2.0.

Can we expect a migration of Emscripten from SDL 1.2 to SDL 2.0 ? Is it on the roadmap ?

@kripken
Copy link
Member

kripken commented Mar 6, 2014

Some people have voiced interest in a proper port of SDL 2.0 from source, and I hope this will happen in the near future, but I don't know for sure.

You can use the html5.h support in emscripten to get direct access to things like joysticks, might be simpler to just do that. But, proper SDL 2.0 is of course the thing that we want.

@JMLX42
Copy link

JMLX42 commented Mar 7, 2014

Thx for the advice. We have other problems with the keyboard scancode/keycode which seems to be different between SDL 1.3 and SDL 2.0. The result is that in native we don't have the same keyboard mapping than in emscripten.

I think SDL2.0 is largely backward compatible, and we could support SDL2 differences first and then the new features afterward. The keyboard mapping issue is a major issue I think. I want to start by:

  • adding the proper SDL2 headers in system/includes/SDL2
  • forking library_sdl.js into library_sdl2.js

But I don't know how to make sure library_sdl2.js will be used when I'm actually trying to link with SDL2.

@haneefmubarak
Copy link
Contributor

I would personally love a port of SDL2; rock on @promethe42!

@kripken
Copy link
Member

kripken commented Mar 7, 2014

If we go this route, we could use SDL2 when -lSDL2 is used with emcc, or something like that. Might need some emcc changes, I can help if it isn't trivial stuff.

But, a bigger question is whether forking the current js file is the way to go. It will mean duplication which could cause us to need to fix bugs in two places. Also, the current js is a small subset of SDL - if we ported SDL2 from source, we would get all of it more easily. I suspect that route is more promising, but I don't know the SDL codebase so I'm not sure.

@mel15
Copy link

mel15 commented Apr 30, 2014

I love you Noxalus ;___;

@juj juj added the SDL label Jul 27, 2014
@icculus
Copy link
Contributor

icculus commented Sep 18, 2017

I'm bouncing into this issue 3.5 years later, because I just searched for "gamepad" and this is still open:

  • SDL joysticks (in 1.2 and 2.0) never make any promises about the order of buttons. The SDL2 gamepad API is what you want if you want to make sure an XBox360 controller always looks like an XBox360 controller, even if it happens to be a PlayStation 3 controller in real life. My assumption is that the Emscripten 1.2 reimplementation just picked different buttons than the SDL2/emscripten port. Since you can pick one or the other for your project, I wouldn't change either implementation at this point.
  • SDL2 was ported to Emscripten a while ago, and we're shipping commercial games with it. :) This is a tiny plea to not reimplement it for Emscripten, as it's a big API and we are actively maintaining and improving our Emscripten target so you don't have to. :)

tl;dr: this bug should be closed, imho.

Your friendly neighborhood SDL maintainer,
--ryan.

@kripken
Copy link
Member

kripken commented Sep 18, 2017

Agreed on those points, and thanks for the help, finding old bugs to close is great.

@kripken kripken closed this as completed Sep 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants