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

Cannot move craft with Joystick #26

Closed
The-King-of-Toasters opened this issue Aug 16, 2023 · 15 comments
Closed

Cannot move craft with Joystick #26

The-King-of-Toasters opened this issue Aug 16, 2023 · 15 comments

Comments

@The-King-of-Toasters
Copy link
Contributor

The-King-of-Toasters commented Aug 16, 2023

It seems after your work re: controller bindings, the ability to move the ships with the controller was removed. This is with the SDL2 platform, of course.

Edit: bisected to b2e3ae8.

@enigma9o7
Copy link
Contributor

In my case, the controller still works as before - unless I customize controls in the new menu. Any button I change in controller settings doesn't work (on new button or old). The movement still works as I didn't change that. If I delete the save.dat contoller works (with default buttons) again.

Also during the controller setup, it doesn't recognize my right shoulder button at all. Seems to recognize everything else. I'm using cheap usb gamepad (Mafiti GP100).

@phoboslab
Copy link
Owner

Yeah, the Analog Stick is not bound by default anymore, but you should be able to bind it again in the options -> controls.

Any button I change in controller settings doesn't work (on new button or old)

To clarify: you're able to set the buttons in the options but then cannot use them in the game?

@enigma9o7
Copy link
Contributor

I realize now my issue is unrelated to the thread topic, as I'm not using a joystick, only dpad.

To clarify: you're able to set the buttons in the options but then cannot use them in the game?

Yes, but I figured out if I restart the game after making button changes, then they work as expected. The only issue I dunno how to work around is why it ignores my right shoulder, but there's enough other buttons I'm okay without it anyway.

Thanks again for great job, gameplay is great.

@phoboslab
Copy link
Owner

Yes, but I figured out if I restart the game after making button changes, then they work as expected.

Ah, meh. I thought I had fixed that issue. I believe it's caused by the buttons states not set correctly when a new button is bound. I'll look into it.

The only issue I dunno how to work around is why it ignores my right shoulder

The mapping in platform_sdl.c is missing some that I (falsely?) assumed to be mostly unused. SDL provides these buttons: https://wiki.libsdl.org/SDL2/SDL_GameControllerButton – I guess the shoulder button on your gamepad is one of the SDL_CONTROLLER_BUTTON_PADDLE* ones!? Curious that the left one works though.

Can you maybe add a printf("button %d", ev.cbutton.button) here and check whether it's triggered by this button at all?

@enigma9o7
Copy link
Contributor

enigma9o7 commented Aug 19, 2023

Can you maybe add a printf("button %d", ev.cbutton.button) here and check

Did it, and I see output in the terminal for other buttons similar to:
button 3button 0button 0button 9wrote save.dat
but nothing for right shoulder, and the new 3 second timer just times out when I try pushing my right shoulder to record it.

It does work in other sdl2 games and identifies it as button5, for example dolphin emulator:
shot-2023-08-19_13-27-15
Note that there is no Z button on this controller so I used "Select" for that. (And no control sticks, simple snes style gamepad).

@phoboslab
Copy link
Owner

phoboslab commented Aug 19, 2023

Button 5 is SDL_CONTROLLER_BUTTON_GUIDE which indeed was not mapped. The above commit fixes this. Can you try again?

(not sure what I was thinking there; I guess we should also use the SDL names for these buttons. I believe the internal names where initially from an old game controller in the browser test of mine...)

If it doesn't work: the printf() should have printed button 5 nevertheless. If you added this statement to the right place and it still didn't print, we're not getting the event from SDL at all.

It should be right here

else if (
	ev.type == SDL_CONTROLLERBUTTONDOWN || 
	ev.type == SDL_CONTROLLERBUTTONUP
) {
	printf("button %d\n", ev.cbutton.button);
	...

Edit: maybe this program can also provide some clarity: https://github.com/Grumbel/sdl-jstest

@enigma9o7
Copy link
Contributor

enigma9o7 commented Aug 19, 2023

I updated and modified file again. Now for buttons that work, it just outputs stuff like "button 0". But still nothing for the right shoulder.

That tool works, and when I run sdl2-jstest --test 0, and press right shoulder, button 5 gets #, and all other buttons work too (except 6&7 which I dont actually have, that test reports 10 buttons but its really only dpad + 8 buttons).

$ ./sdl2-jstest --list
Found 1 joystick(s)

Joystick Name:     'usb gamepad'
Joystick GUID:     030000001008000001e5000010010000
Joystick Number:    0
Number of Axes:     2
Number of Buttons: 10
Number of Hats:     0
Number of Balls:    0
GameControllerConfig:
  Name:    'NEXT SNES Controller'
  Mapping: '030000001008000001e5000010010000,NEXT SNES Controller,a:b2,b:b1,back:b8,dpdown:+a1,dpleft:-a0,dpright:+a0,dpup:-a1,leftshoulder:b4,rightshoulder:b5,righttrigger:b6,start:b9,x:b3,y:b0,platform:Linux,'

shot-2023-08-19_15-13-44

@phoboslab
Copy link
Owner

Well, now I'm a bit confused. When you launch sdl2-jstest --test 0, you actually test joystick events which are apparently different from gamepad events. Why is there two APIs? I guess I have some reading to do...

Does the button work when testing gamepad events? ./sdl2-jstest -g 0

@enigma9o7
Copy link
Contributor

Yes, it works that way too. The output is a bit messier, but it shows a 1 on right shoulder when I press it.

shot-2023-08-19_15-53-03

@mickski56
Copy link

mickski56 commented Aug 19, 2023

Why is there two APIs?

Ancient history the joystick api came first as part of alsa.
Think analog joystick ports that used to come as part of sound cards back in the day.

The event api came later as part of the kernel.
For testing event interface devices use evtest /dev/input/eventXX and testgamecontroller X (which is part of sdl2 don't know whether you get it unless you've built the sdl2 tests yourself)
testgamecontroller is what you want for reporting sdl2 controller button and axis names.
https://github.com/libsdl-org/SDL/tree/main/test

https://docs.kernel.org/input/input_uapi.html for all the gory details. Its what sdl2 uses under the hood on linux.

@phoboslab
Copy link
Owner

The output is a bit messier, but it shows a 1 on right shoulder

Ok, I previously thought that maybe this button would only work through the joystick API. Now I'm wondering how in the hell this button is not registered in the code here.

One last thing: sdl2-jstest uses polling for the gamecontroller test, but it also has some commented out code that uses the event API instead (like we do here). Can you test that again? Switch the comments in 456-457 like so:

    test_gamecontroller_events(gamepad);
    // test_gamecontroller_state(gamepad);

And remove the #if 0 in line 316 and the #endif in line 409. Thanks for your patience ._.

Thanks mickski56; that puts some perspective on things!

@enigma9o7
Copy link
Contributor

enigma9o7 commented Aug 21, 2023

Still works. the -t 0 behaves the same as before, all buttons working. the -g 0 has a much cleaner output and still works.

bodhi@athlon:~/sdl-jstest/build$ ./sdl2-jstest --list
Found 1 joystick(s)

Joystick Name:     'usb gamepad'
Joystick GUID:     030000001008000001e5000010010000
Joystick Number:    0
Number of Axes:     2
Number of Buttons: 10
Number of Hats:     0
Number of Balls:    0
GameControllerConfig:
  Name:    'NEXT SNES Controller'
  Mapping: '030000001008000001e5000010010000,NEXT SNES Controller,a:b2,b:b1,back:b8,dpdown:+a1,dpleft:-a0,dpright:+a0,dpup:-a1,leftshoulder:b4,rightshoulder:b5,righttrigger:b6,start:b9,x:b3,y:b0,platform:Linux,'

bodhi@athlon:~/sdl-jstest/build$ ./sdl2-jstest -g 0
Entering gamecontroller test loop, press Ctrl-c to exit
SDL_CONTROLLERDEVICEADDED which:0
SDL_CONTROLLERBUTTONDOWN controller: 0 button: rightshoulder state: 1
SDL_CONTROLLERBUTTONUP   controller: 0 button: rightshoulder state: 0

sdl2-jstest.c.txt

@phoboslab
Copy link
Owner

The only remaining differences I can see from the implementation here and in sdl-jstest are:

  1. We only init SDL_INIT_GAMECONTROLLER but not SDL_INIT_JOYSTICK or SDL_INIT_HAPTIC (you can change it here and see if it makes a difference)
  2. We're not loading the gamecontrollerdb.txt (as in here)

I suspect 2. is the culprit. I'll implement this later today.

@phoboslab
Copy link
Owner

Above commit loads the gamecontrollerdb.txt (you need to manually download it from here and place it in the root directory of this project). Additionally, Joysticks will be initialized. Please try again <3

@enigma9o7
Copy link
Contributor

enigma9o7 commented Aug 21, 2023

WOOHOO! It now works in the game after adding gamecontrollerdb.txt to wipeout-rewrite folder.

Thanks so much for spending so much time figuring this out!
shot-2023-08-21_09-06-20

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

4 participants