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

Configure gamepad on Linux #35

Open
Silicomancer opened this issue Mar 10, 2023 · 52 comments
Open

Configure gamepad on Linux #35

Silicomancer opened this issue Mar 10, 2023 · 52 comments

Comments

@Silicomancer
Copy link

I tried to install the fantastic Hurrican game on Kubuntu 22.04 via flatpak. The game seems to run fine but I'm unable to configure my game pad (I tried two completely different pads) in a usable way.

I could select all my desired mappings just fine. This includes using the right trigger button (displayed as button 8 in the game settings) as fire button (this mapping is important for me).

The configuration works completely. However whenever I press the selected fire button the game exits to the main menu like when pressing the escape button. It appears to me that the trigger button now has two functions: Fire (as selected by myself) and some pause/exit/escape function (I could not find a way to modify this function).

Is this a bug? Is there a workaround?

BTW In case of keyboard configuration I noticed that I can not select 'x' as a fire button at all. I simply don't get any reaction. I can use virtually any key... except 'x'. Maybe this is connected to the game pad issue?

@drfiemost
Copy link
Member

Is the flatpack built with the latest code from this repository?
I can select the 'x' button fine and the pause/exit/escape function should be mapped to the gamepad start button. There was a discussion specifically on this issue time ago drfiemost#7
You should either build the code yourself or contact the flatpack maintainer to check if the problems are still present in the latest version.

@Silicomancer
Copy link
Author

Silicomancer commented Mar 11, 2023

Well, its the Flatpak that comes with Kubuntu 22.04 by default. I installed it using Discover. It says "Source: flathub (flatpak)" and "Version: 1.0, published 03.04.22". It links to this GitHub repository. I have have no idea who maintains that flatpak.

@thrimbor
Copy link
Member

@drfiemost I created the flatpak image last year, mainly to make Hurrican available on the steam deck. The commit it's built off is cb4d008

Ideally the flatpak repo should get automatically updated by a CI job whenever this repo has a release tagged. I didn't set it up that way back then because there was no recent-ish release.

@Silicomancer which controllers are we talking about, and what do you mean by "trigger button"? Usually, the triggers are analog and not buttons

@Silicomancer
Copy link
Author

A Final Fantasy XIV controller. It has button numbers imprinted on it. I attached 2 images where you can see the numbers. The button I want to use as a fire button (only) is 8.

The other one is a very old Saitek P220 controller: https://www.picclickimg.com/cJIAAOSws81jJuJ0/Saitek-P220-Digital-USB-PC-Controller-Pad.webp

Both behave exactly the same with Hurrican. I'm sure that I used one of them (maybe both?) many years ago to play Hurrican on Windows.

top
front2

@Silicomancer
Copy link
Author

Would it be possible to add a setting for the pause/exit/escape function? This surely would allow fixing the behavior anyway.

@drfiemost
Copy link
Member

Ok, so the 'x' button issue is related to #27 which was merged after the flatpack build.

Not sure about the gamepad, you should check in the log if there's a line mentioning 'Start function mapped to button START'. If not it defaults to button 7.

@Silicomancer
Copy link
Author

Where can I find the log?

@thrimbor
Copy link
Member

Where can I find the log?

For the flatpak version it should be in /tmp/

@drfiemost I'll try to update the flatpak version over the weekend

@Silicomancer
Copy link
Author

Where can I find the log?

For the flatpak version it should be in /tmp/

I couldn't find it...

@drfiemost
Copy link
Member

The file is Game_Log.txt, the directory is not specified so it should be the current dir from where you launch the game, maybe your home?

In case the start button is not correctly detected you may try tweaking your gamepad mapping to workaround the issue as mentioned here drfiemost#13 (comment).

@Silicomancer
Copy link
Author

Silicomancer commented Mar 16, 2023

I just installed the updated version. Thanks a lot!
Selecting "X" in keyboard configuration works fine now. However I am still unable to use the desired fire button.

I found the log here:
/run/user/1000/.flatpak/io.github.hurricangame.hurrican/tmp/

This should probably be the relevant part:

-> OpenGL init successful!

DirectInput8 polling for 512 keys!
Joystick 0: Acquire successful!
Buttons: 12 
Name: FUJIWORK CO., FF-GP1
Force-feedback: false
Initializing SDL_mixer
Requested 24 sound channels and got 24
Loaded texture demofont
Loading font: demofont.png
Loaded texture copper1
Loaded texture copper2
Loaded texture copper3
Loaded texture demozahlen
Loaded texture demologo
Loaded texture star
Loaded song file /app/share/hurrican//data/music/Cracktro.it

-> GameInit successful!

@drfiemost
Copy link
Member

Yes, that's it. I see the standard buttons are not being mapped. @thrimbor is the flatpack built with SDL2?
Gamepad support is quite limited with SDL1, even force-feedback is disabled.

@thrimbor
Copy link
Member

Yeah, SDL 2.24.0

@drfiemost
Copy link
Member

Good, so the gampad should be supported.
@Silicomancer can you please check your gamepad id with SDL2 Gamepad Mapper, or any similar software, if it matches the one in SDL?
https://github.com/libsdl-org/SDL/blob/8c9beb0c873f6ca5efbd88f1ad2648bfc793b2ac/src/joystick/SDL_gamecontrollerdb.h#L133

@Silicomancer
Copy link
Author

Silicomancer commented Mar 18, 2023

Sure. How do I do that?

I started the SDL2 Gamepad Mapper application and this is what it says:

SDL2 Gamepad Mapper 0.0.4 (Compiled with SDL 2.26.0, DLL version 2.26.0)

Checking for latest GameController mapping file
Loading any existing mappings into SDL
Scan for controllers
Found 1 gamepad(s)
"FUJIWORK CO., FF-GP1", 03005036852100000201000010010000 
Environmental variable "SDL_GAMECONTROLLERCONFIG" was not found
The GUID for "FUJIWORK CO., FF-GP1" is "03005036852100000201000010010000"

Does this help? Do I need to do more?

@drfiemost
Copy link
Member

Ah, your controller's GUID is slightly different from the one in SDL. Try setting the following environment variable before running the game:

export SDL_GAMECONTROLLERCONFIG="
03005036852100000201000010010000,FF-GP1,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,platform:Linux,
"

More details in the arch wiki.

If it works it might be worth reporting to SDL for inclusion in the controller db.

@Silicomancer
Copy link
Author

Just tried as you said. I run the export command and then started Hurrican in the same bash. Behavior didn't change. Also the name of the controller ("FUJIWORK CO., FF-GP1") in the configuration menu is the same. I guess this means the env. variable was ignored or overruled.

I tried the same with that SDL2_Gamepad_Mapper tool. The tool finds the env. variable and it changes the disabled controller name from "FUJIWORK CO., FF-GP1" to "FF-GP1".

So I guess your idea should work. Could it be flatpak related problem that the env. var. is not found?

@drfiemost
Copy link
Member

Not familiar with flatpack but flatpak-override --env seems to be what you're looking for.

@Silicomancer
Copy link
Author

I have never used flatpak before. I tried to pass the env. var. via CLI but it didn't work. I got errors. I tried flatseal instead. It allows to permanently set an env. var. for a selected flatpak application. I added the new variable successfully but I can't see any effect in Hurrican. It still shows a "FUJIWORK CO., FF-GP1" controller.

@thrimbor Any ideas?

@Silicomancer
Copy link
Author

Any idea how to proceed?

I guess I should report the missing controller to the SDL team but currently I don't think this will resolve the issue. I suppose something else is wrong as well. The fact that two completely different game-pads suffer from the same problem is a strong indicator that the issue is not (only) controller related.

Has someone tried to reproduce my issue using another kind of game-pad?

@drfiemost
Copy link
Member

My gamepad (a cheap xbox controler clone) is recognized out of the box

Joystick 0: Acquire successful!
Buttons: 11 
Name: Xbox 360 Controller
Force-feedback: true
It's a Game Controller, mapping standard buttons...
Start function mapped to button START (7)
Enter function mapped to button A (0)
Back function mapped to button B (1)
Delete function mapped to button LB (4)

and the GUID is not even in the DB

SDL2 Gamepad Mapper 0.0.4 (Compiled with SDL 2.26.4, DLL version 2.26.1)

Loading any existing mappings into SDL
Scan for controllers
Found 1 gamepad(s)
"Xbox 360 Controller", 030003f05e0400008e02000010010000 (mapping available)
Environmental variable "SDL_GAMECONTROLLERCONFIG" was not found

I also notice that there are kernel drivers loaded, including the force-feedback one

$ lsmod
Module                  Size  Used by
xpad                   40960  0
ff_memless             16384  1 xpad

I'm clueless at this point, guess you'd better ask the SDL guys for advice.

@Silicomancer
Copy link
Author

You are right, Hurrican reacts in a different way. I don't see those mapping messages. But why? There must be some condition in the Hurrican code... what condition causes Hurrican to do the mapping?

I am afraid that asking the SDL guys will result in a "Hurrican? We don't know what Hurrican does internally. Your problem doesn't look like a SDL issue. Ask the Hurrican guys!". I guess we need to understand more of what is going on in Hurrican before I can ask the SDL people.

Have you tried to use the right shoulder button #8 as fire button? Does it definitely work for you?

@drfiemost
Copy link
Member

You are right, Hurrican reacts in a different way. I don't see those mapping messages. But why? There must be some condition in the Hurrican code... what condition causes Hurrican to do the mapping?

There is just a call to SDL_IsGameController, which in your case returns false:

if (SDL_IsGameController(joy)) {

We also use SDL_JoystickHasRumble to detect if force-feedback is supported.

Have you tried to use the right shoulder button #8 as fire button? Does it definitely work for you?

Hmm, both L2 and R2 are not recognized, maybe they're treated as analog and not handled, need to check...

@Silicomancer
Copy link
Author

Silicomancer commented Mar 27, 2023

Hm. Not much information in the web. But looks like this issue actually could be caused by missing controller mapping. Which would mean I had the luck to use two controllers without supported mapping.

I tried to find more about that. And I looked into the SDL database header you linked above and I looked into SDL2 Gamepad Mapper tool again. This confused me a lot.

The mapper tool detects the controllers as "FUJIWORK CO., FF-GP1" (03005036852100000201000010010000) and "SAITEK P220" (03003d0ba30600000701000000010000).

But I could not find the controllers in the header file. There is nothing like "P220" in the header. There is a "FF-GP1" in the header. But nothing like "FUJIWORK". So where does the SDL2 Gamepad Mapper tool take the full names of my controller from?

Additionally the tool says "mapping available" for both controllers. But I could not find the IDs in the header. So where does the SDL2 Gamepad Mapper tool take the mappings from?

It feels like the mapping tool works different compared to Hurrican. Are there any external databases the tool could use additionally to the compiled header? Or maybe a local file? A system file? An online DB?

@drfiemost
Copy link
Member

drfiemost commented Mar 28, 2023

It seems Gamepad Mapper downloads the file from https://raw.githubusercontent.com/gabomdq/SDL_GameControllerDB/master/gamecontrollerdb.txt
But there's no exact matching in there too so I guess there's some magic going on. Would be interesting to look at what SDL_IsGameController is doing.

BTW as I supposed L2 and R2 are handled as axis and not as buttons so there's some work to do to support them.

@Silicomancer
Copy link
Author

It seems Gamepad Mapper downloads the file from https://raw.githubusercontent.com/gabomdq/SDL_GameControllerDB/master/gamecontrollerdb.txt

Could be a good idea for Hurrican anyway. I saw there is a special function in the SDL API for loading mappings from a file easily.

But there's no matching in there too so I guess there's some magic going on.

I found two mappings for "Saitek P220". But you are right that my controller IDs aren't mentioned there as well.
So there is definitely more magic in the tool.

Are those IDs monolithic or do they contain sub-fields with specials meanings so that they could be matched like patterns?

@drfiemost
Copy link
Member

It looks like the GUID contains sub-fields, if there's no exact match a partial match is tried.

https://github.com/libsdl-org/SDL/blob/4fa21ee5edb6f00ae9d3489961e659745bd4f4d8/src/joystick/SDL_gamecontroller.c#L2019

The FF-GP1 is included in the SDL2 db so it should be supported out of the box and the P220 could be configured with the SDL_GAMECONTROLLERCONFIG env variable.

Maybe trying with a minimal test program that calls SDL_IsGameController could help. If it still doesn't work it should be reported upstream.

@Silicomancer
Copy link
Author

Very good. This could also explain where the vendor name came from.

Well, since the mapping tool already matches both of my controllers I would like suggest to enable Hurrican to load the Text file in the same way first. This seems a good idea anyway and it would improve Hurrican independently of this issue. And I could re-test the behavior of both controllers easily. I guess the chances are good to fix this issue this way.

@drfiemost
Copy link
Member

Fine, we can provide a copy of the game controller db in the data dir and load it at startup, it wouldn't hurt.

@Silicomancer
Copy link
Author

Silicomancer commented Mar 29, 2023

Thanks a lot. I can't wait to test it :-)

BTW, since I already tried the environment variable and it didn't work for me... would it be possible for me to edit the text file in the released flatpak? This would be a way to test mappings in case the default database text file doesn't solve the problems entirely.

@drfiemost
Copy link
Member

The change is ready (see #38), I want to give it another spin in the weekend before merging.

I have no clue if it's possible to edit files inside a flatpak, you'd better refer to the docs for this.

@Silicomancer
Copy link
Author

Ok, looks good. I will try it as soon as I can see a new flatpak in the repo.

@drfiemost
Copy link
Member

Ok, the problems should be fixed now (#38). There is still a pending issue (#39) that will be merged in the upcoming days but it seems the Linux version is not affected for some reason.
Asking @thrimbor to update the flatpak and @Silicomancer to test if everything is good now, thanks.

@thrimbor
Copy link
Member

thrimbor commented Apr 4, 2023

Flatpak update is out.

@Silicomancer
Copy link
Author

Ok, good news and bad news.

For the P220 controller I can see the mapping log messages now. I guess it is an SDL database issue that my other controller isn't detected in the same way.

However the behavior didn't change. The game still exits AND shoots when pressing button 8. For both controllers. I guess there is another bug luring in the code.

Am I right that button 3 should exit an active game with the P220 now? I tried it and button 3 doesn't do anything. Also there is no other button (except button 8) that exits.

-> OpenGL init successful!

DirectInput8 polling for 512 keys!
Loaded 271 mappings from game controller db
Joystick 0: Acquire successful! 
Name: FUJIWORK CO., FF-GP1 
Axis: 4 
Hats: 1 
Buttons: 12
Force-feedback: false
Joystick 1: Acquire successful! 
Name: SAITEK P220 
Axis: 3 
Hats: 0 
Buttons: 8
Force-feedback: false
It's a Game Controller, mapping standard buttons...
Enter function mapped to button A (2)
Back function mapped to button B (3)
Delete function mapped to button LB (6)
Initializing SDL_mixer
Requested 24 sound channels and got 24
Loaded texture demofont
Loading font: demofont.png
Loaded texture copper1
Loaded texture copper2
Loaded texture copper3
Loaded texture demozahlen
Loaded texture demologo
Loaded texture star
Loaded song file /app/share/hurrican//data/music/Cracktro.it

-> GameInit successful!

@drfiemost
Copy link
Member

That's a nice step forward! The remaining problem is the P220 has no start button so the default button with id 7 is used. This can be fixed by using a fallback mechanism, something like:

START  -> use SDL_CONTROLLER_BUTTON_START or SDL_CONTROLLER_BUTTON_X
Enter  -> use SDL_CONTROLLER_BUTTON_A
Back   -> use SDL_CONTROLLER_BUTTON_BACK or SDL_CONTROLLER_BUTTON_B
Delete -> use SDL_CONTROLLER_BUTTON_LEFTSHOULDER or SDL_CONTROLLER_BUTTON_Y

I'm not a gamer so this may not be the best choice but at least it seems tha buttons A, B, X and Y are always available.

As for the other controller you'd better contact the SDL_GameControllerDB project, they sure know better what to do.

@Silicomancer
Copy link
Author

What about adding new entries to the configuration menu where users can select the corresponding button(s)?

@Silicomancer
Copy link
Author

Regarding the controller:
mdqinc/SDL_GameControllerDB#678

@drfiemost
Copy link
Member

What about adding new entries to the configuration menu where users can select the corresponding button(s)?

There's not enough space left in the controller menu, also I don't think it would belong there.
For now I've added the fallback so the functions should always be mapped to a gamepad button.

Regarding the controller: gabomdq/SDL_GameControllerDB#678

Cool, GCDB updated! If @thrimbor can rebiuld the flatpak (hopefully the last time for now) you should be able to enjoy the game with your controllers.

@Silicomancer
Copy link
Author

@thrimbor ?

@thrimbor
Copy link
Member

Update is out now

@Silicomancer
Copy link
Author

Tried it. For the FF-GP1 behavior didn't change.

For the Saitek the behavior changed. But not better, only different. The exit button now is hard wired to button 1 which should be the jump button. So now whenever I try to jump, it exits the game.

This is my current log:

-> OpenGL init successful!

DirectInput8 polling for 512 keys!
Loaded 273 mappings from game controller db
Joystick 0: Acquire successful! 
Name: FUJIWORK CO., FF-GP1 
Axis: 4 
Hats: 1 
Buttons: 12
Force-feedback: false
Joystick 1: Acquire successful! 
Name: SAITEK P220 
Axis: 3 
Hats: 0 
Buttons: 8
Force-feedback: false
It's a Game Controller, mapping standard buttons...
Start function mapped to button X (0)
Enter function mapped to button A (2)
Back function mapped to button B (3)
Delete function mapped to button LB (6)
Initializing SDL_mixer
Requested 24 sound channels and got 24
Loaded texture demofont
Loading font: demofont.png
Loaded texture copper1
Loaded texture copper2
Loaded texture copper3
Loaded texture demozahlen
Loaded texture demologo
Loaded texture star
Loaded song file /app/share/hurrican//data/music/Cracktro.it

-> GameInit successful!

@drfiemost
Copy link
Member

Hmmm, maybe using button X as a fallback was not a good idea :/
Unfortunately I don't see a better alternative, these are the buttons available for the P220:

Saitek P220
a:b2
b:b3
dpdown:+a1
dpleft:-a0
dpright:+a0
dpup:-a1
leftshoulder:b6
lefttrigger:b7
rightshoulder:b4
righttrigger:b5
x:b0
y:b1

As for the FF-GP1 I don't know, there are 273 mapping loaded on more than five hundred lines in the GCDB, maybe it's being skipped for some reason?

@Silicomancer
Copy link
Author

Hmmm, maybe using button X as a fallback was not a good idea :/ Unfortunately I don't see a better alternative, these are the buttons available for the P220:

Well, I don't know much about game controllers variants. But I guess the safest thing would be some configuration settings. I simply have no idea if it is possible at all to find a fall back or default that works for all controllers.

As for the FF-GP1 I don't know, there are 273 mapping loaded on more than five hundred lines in the GCDB, maybe it's being skipped for some reason?

I guess this is a good question for the GCDB project... I suppose the people there can answer this easily. Would you like to open an issue there? I would prefer you to ask because you wrote the GCDB code.

@drfiemost
Copy link
Member

I guess this is a good question for the GCDB project... I suppose the people there can answer this easily. Would you like to open an issue there? I would prefer you to ask because you wrote the GCDB code.

Added a follow-up on your issue.

@drfiemost
Copy link
Member

Opened libsdl-org/SDL#7700

@drfiemost
Copy link
Member

@Silicomancer any way you can check the proposed patch? libsdl-org/SDL#7700 (comment)

drfiemost added a commit that referenced this issue Jun 21, 2023
Also add Final Fantasy XIV mapping as suggested at libsdl-org/SDL#7700
@drfiemost
Copy link
Member

Added the suggested mapping to the GCDB. If @thrimbor could update the flatpak and @Silicomancer test it we can report back if it works, thanks.

@thrimbor
Copy link
Member

Done

@Silicomancer
Copy link
Author

@drfiemost Did you include any change regarding the default button issue?

@Silicomancer
Copy link
Author

I can't see any changes in the log:

-> OpenGL init successful!

DirectInput8 polling for 512 keys!
Loaded 284 mappings from game controller db
Joystick 0: Acquire successful! 
Name: FUJIWORK CO., FF-GP1 
Axis: 4 
Hats: 1 
Buttons: 12
Force-feedback: false
Joystick 1: Acquire successful! 
Name: SAITEK P220 
Axis: 3 
Hats: 0 
Buttons: 8
Force-feedback: false
It's a Game Controller, mapping standard buttons...
Start function mapped to button X (0)
Enter function mapped to button A (2)
Back function mapped to button B (3)
Delete function mapped to button LB (6)
Initializing SDL_mixer
Requested 24 sound channels and got 24
Loaded texture demofont
Loading font: demofont.png
Loaded texture copper1
Loaded texture copper2
Loaded texture copper3
Loaded texture demozahlen
Loaded texture demologo
Loaded texture star
Loaded song file /app/share/hurrican//data/music/Cracktro.it

-> GameInit successful!

@drfiemost
Copy link
Member

@drfiemost Did you include any change regarding the default button issue?

I tought I did but I was wrong. I should remove the fallback to X button since it was a bad idea. Not sure how to improve the situation though, I was thinking of a --start-button command line option but it could cause trouble when using two gamepads.

I can't see any changes in the log:
[...]

Not sure what to think, guess you should handle the issue with the SDL team.

drfiemost added a commit that referenced this issue Jul 3, 2023
The start function is required in game too and it may conflict with the usage of X button
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants