Menu

#101 SDL joypad Improvements

Latest SVN
closed-fixed
None
5
2010-05-09
2010-05-07
tomsires
No

1) Larger dead zone for analog controls. Also fixed possible issue where negative side of dead zone might not be applied. (right bitwise shift applied to negative integers, implementation seems to vary)
2) Analog controls can now be assigned to buttons, and non-analog controls can now be assigned to the directional controls.
3) Differentiates between positive and negative movement for analog controls.
4) In the GTK and Glade ports, directional buttons can now be set independently of their "twins".
5) Hat/POV/D-Pad controls are usable now.
6) Differentiates between multiple controllers.
7) Slightly modified method of storing joypad key codes, in a way similar to VBA-M's method of configging controls, though I kept the codes as u16's. The way it's arranged now will allow for up to 16 unique joypads, and up to 128 axes, 64 POV hats, and 256 Buttons per joypad, which should probably be enough. The method of determining a key code is explained in ctrlssdl.cpp. Basically, it starts with 0x1000 * joypad_index. For buttons, add 0x200 + button_index. For hats, add 0x100 + 4 * hat_index + (0, 1, 2, or 3 for R, L, U, D). For axes, add 2 * axis_index + (0 or 1 for negative or positive). Maybe there's a way to get the config file to save these values in a hexadecimal representation for easier editing, but I didn't really mess with the configs.

So, the reason I decided to try this was that I was having some issues with my wired XBox 360 controller in the Linux GTK, Glade, and CLI ports (The controller works fine otherwise). It seemed to be very sensitive, so it was impossible to "zero" the axes, which leads to constantly scrolling through menus, etc. The slightest touch would trigger the input. Also wanted to be able to use the D-Pad and Analog triggers for something useful. The distinction between multiple "joypads" should also help anyone with any other odd input devices being recognized, like accelerometers.

Anyways, I don't normally do this (submitting patches and stuff), so if I've done something wrong or anything else is needed, let me know.

Discussion

  •  tomsires

    tomsires - 2010-05-07

    Various improvements to the SDL handling of joypad input, with minor changes for consistency in Glade and GTK ports. (For r3602)

     
  • Magliocchetti Riccardo

    • assigned_to: nobody --> riccardom
     
  • Magliocchetti Riccardo

    Maybe i'm mising something useful, but why we need up to 16 unique joypads?

     
  •  tomsires

    tomsires - 2010-05-08

    The point isn't to use 16 joypads simultaneously, it's that it allows up to 16 joypads to be plugged in without having two "overlap" as they currently do. Currently, the device ID is completely ignored, and multiple joypads (or other devices detected as joypads) will trigger the same inputs. Basically, this alleviates the need to unplug all other joypads prior to using DeSmuME, and avoids issues with other devices that can't be "unplugged".

    And 16 is arbitrary, really, I just used the first hexadecimal digit to represent the device ID, out of the four available in a u16. Ideally, it would use a larger date type (like u32) that would allow space for 256 joypads and 256 each of axes, hats, and buttons, the maximum supported by SDL (they're all Uint8's). Once again, not because 200+ buttoned joypads are common, but rather to make it robust enough to handle all possible setups. That would be the "right way" to do it, but I just used the existing data type so that I could avoid making additional changes for other stuff that would be affected.

     
  • Magliocchetti Riccardo

    Applied, thanks!

     
  • Magliocchetti Riccardo

    • status: open --> closed-fixed
     

Log in to post a comment.

MongoDB Logo MongoDB