Solarus Forum

Solarus => Bugs & Feature requests => Topic started by: duffy on December 06, 2017, 04:40:40 pm

Title: Improve gamepad support
Post by: duffy on December 06, 2017, 04:40:40 pm
Gamepad can be better handled by using SDL_gamecontroller instead of directly SDL_joystick API.

Pros :
Cons :

What I propose to do :

It should not break backward compatibility and be transparent from the user point of view except if the gamepad is not supported.


One future improvement which can be nice is to deport saved mapping from save game to an engine settings file + an engine menu and save mapping by controller.
Title: Re: Improve gamepad support
Post by: Christopho on December 06, 2017, 04:51:10 pm
Looks great. It is annoying that we can't guess correct buttons automatically with the current solarus.
A pull request will be welcome :)

I think joystick added/removed events and a haptic rumble API are other subjects (new features) and should be developed in separate works later.
Title: Re: Improve gamepad support
Post by: darknior on December 06, 2017, 04:54:22 pm
I love the idea of GENERIC joystick mapping :)
And the RUMBLE with x360 gamepad on PC or PI is really excellent to use <3
Title: Re: Improve gamepad support
Post by: duffy on December 06, 2017, 05:03:22 pm
You are right about haptic rumble (I'm not sure about added/removed event but why not).
I will post here when it's done before a PR if there are some stuff that you want me to change and because it's maybe better to PR  this on a "joystick" branch (of course I can't create a branch).
Title: Re: Improve gamepad support
Post by: Christopho on December 06, 2017, 05:22:34 pm
Don't worry about that, you can make a PR to the dev branch and if I want to put it in a new branch I can still do it.
Title: Re: Improve gamepad support
Post by: duffy on December 13, 2017, 05:38:50 pm
It's pretty much done, there is only Convert "button X" from old save game with new mapping which is not finished yet.

For now there are some issues :

Convert "button X" from old save game with new mapping

I just discovered that in ROTH SE "button" is hard coded in Lua and it's a problem when you bind a joypad button to a command (now button strings are checked):

[Solarus] [73860] Error: In on_joypad_button_pressed: scripts/menus/pause_commands.lua:65: bad argument #2 to set_command_joypad_binding (Invalid joypad string: 'button 6')

I will see if I can do something about it, but I'm not sure if I can so it may be require to update ROTH SE with a new Lua function like "string get_joypad_button_string(int button)".

Map both left joystick (axis) and dpad (hat) to directions.

If you map the right joystick for directions, both joysticks + dpad will work for directions (as expected).
The problem is if your left joystick is quite sensible an event can be emitted while you are moving with the right one and the hero will stop.
I tried with my xbox one controller and it's really annoying. (with my 360 gamepad it's ok)

There is at least 3 solutions :

Try to create a default (SDL) mapping if the controller is not supported

It's maybe useless (I didn't tried to do it), for example my xbox one controller get this mapping (which is correct) :

00000000000000000000000000000000,XInput Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3

It's weird because I don't use xinput (gamepads are disabled in xorg) and as expected xinput doesn't return it.
My gamepad uid is "030000005e040000d102000002010000" (which is neither in SDL source nor in gamecontrollerdb) and the mapping returns "00000000000000000000000000000000" which is why I guess (maybe I'm wrong) SDL already try to create a mapping.

So I will not add it.


I will try to finish it this week end.
Title: Re: Improve gamepad support
Post by: trigger_x21 on April 21, 2018, 01:11:50 am
Very new to all this... is there a way to increase the deadspace for joysticks on controllers?
Title: Re: Improve gamepad support
Post by: CrookiNari on April 28, 2018, 11:10:07 am
Do you have an idea of which gamepads you'd like to implement? Xbox 360 seems obvious but I'd personally love the option to use my 8Bitdo controllers with these kinds of games for a slightly more authentic experience.
Title: Re: Improve gamepad support
Post by: alexgleason on October 14, 2018, 10:03:14 pm
SDL_gamecontroller sounds like magic. Did this pull request ever happen?