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

[3.2] Provide support for buttons and D-pads mapped to half axes. #42800

Merged
merged 1 commit into from
Oct 26, 2020

Conversation

madmiraal
Copy link
Contributor

3.2 version of #42799.

@madmiraal madmiraal added this to the 3.2 milestone Oct 14, 2020
@madmiraal madmiraal changed the title [3.2] Provide support for D-pads mapped to axes. [3.2] Provide support for buttons and D-pads mapped to half axes. Oct 14, 2020
@salvob41
Copy link
Contributor

Thank you @madmiraal for this work. I did try the build with my 2in1 Controller and it didn't actually change anything of the current 3.2.3 build.
I tried the joypad demo from godot and the results were the same. :(

@salvob41
Copy link
Contributor

salvob41 commented Oct 15, 2020

image

In this picture I was keep pressing the left arrow on the Dpad. Only that button

@madmiraal
Copy link
Contributor Author

madmiraal commented Oct 15, 2020

@salvob41 Thank you for testing. The picture provides really useful feedback. If you don't mind, please provide similar pictures for pressing each of the other directions on the D-pad.

Also, please provide pictures after releasing each of the direction buttons; so I can see what happens when they are supposed to be resetting.

@salvob41
Copy link
Contributor

THis is at the start of the scene:

image

right button Dpad only:
image

Up button DPAD only:
image

Down button DPAD only:
image

Analogic:

If I move the analogic up and/or right it seems that it keeps stucked in that position

Left or right analogic:
image

Up or down analogic:
image

Things to note:

  • Right joypad, right buttons, Back triggering buttons (R1, L1, L2, R2), and Start button and "select button" work good!
  • when, as I mentioned earlier, move analogic buttons it seems as I still keep pressing them (example: in this pictures I moved the analogic, but at the time of the picture I am not pressing anything, the joypad is resting on the table with nothing being pressed)
    image
  • If I move the window of the joypad scene, it seems that the buttons pressed are resetted (weird behaviour)
  • 2in1 controller have a button in the middle that change a behaviour of Dpad and Analogic: that is if I pressed the HOME button the dpad buttons seems to become the same input as the analogic and viceversa for the analogic
    image

Hope this shed more lights on this issue

@salvob41
Copy link
Contributor

the pencil in the picture is to give a nice little "arty" touch ...

@madmiraal madmiraal force-pushed the fix-41065-3.2 branch 2 times, most recently from ec9e642 to 3f86387 Compare October 15, 2020 12:23
@madmiraal
Copy link
Contributor Author

I've updated this PR to include two new fixes:

  1. Fixes the mapping to a negative half-axis
  2. Fixes the axis mappings to D-Pad buttons not resetting.

@salvob41 Please test it again.

@salvob41
Copy link
Contributor

things are happening:

Analogic left now works well. Dpad has still same problems.

ezgif com-gif-maker

@salvob41
Copy link
Contributor

Hope you can see here:

ezgif com-gif-maker (1)

Pressing RIGHT triggers the RIGHT arrow on the DPAD in joypads demo - and stay pressed for some reasons
Pressing LEFT does the same

Pressing DOWN triggers the DOWN arrow on the DPAD in joypads demo - and stay pressed for some reasons
Pressing UP does the same

@madmiraal
Copy link
Contributor Author

@salvob41 Thanks for all the testing and images. You're my eyes with this one. I think I've fixed the negative axis (i.e up and left) to button mapping; so hopefully it will work now. Please try again.

@salvob41
Copy link
Contributor

glad to help, @madmiraal. Thanks for your patience and work.

Dpad still gives problems. I put some testing video here:
https://imgur.com/a/JSwlZEX

@madmiraal
Copy link
Contributor Author

Marked as draft, because I've added a debug warning message in the axis to button mapping process. Hopefully this will provide the information needed to work out what is going wrong.

@salvob41 Please test again, moving left, right, up and then down, and post the output console messages.

@salvob41
Copy link
Contributor

Good idea putting some debug message.

At the start:

WARNING: joy_axis: Axis0 = 0.501961 -> Button15 = 0.501961
   At: main/input_default.cpp:828.
WARNING: joy_axis: Axis1 = 0.501961 -> Button13 = 0.501961
   At: main/input_default.cpp:828.

Nothing happens when I press RIGHT and DOWN buttons.

when I press and release the UP button (this debug print happens at the act of releasing the button)

WARNING: joy_axis: Axis1 = 0.4 -> Button13 = 0.4
   At: main/input_default.cpp:828.
WARNING: joy_axis: Axis1 = 0.501961 -> Button13 = 0.501961
   At: main/input_default.cpp:828.
WARNING: joy_axis: Axis1 = 0.4 -> Button13 = 0.4
   At: main/input_default.cpp:828.
WARNING: joy_axis: Axis1 = 0.501961 -> Button13 = 0.501961
   At: main/input_default.cpp:828.

similar with LEFT button:

WARNING: joy_axis: Axis0 = 0.4 -> Button15 = 0.4
   At: main/input_default.cpp:828.
WARNING: joy_axis: Axis0 = 0.501961 -> Button15 = 0.501961
   At: main/input_default.cpp:828.
WARNING: joy_axis: Axis0 = 0.4 -> Button15 = 0.4
   At: main/input_default.cpp:828.
WARNING: joy_axis: Axis0 = 0.501961 -> Button15 = 0.501961
   At: main/input_default.cpp:828.

@madmiraal madmiraal marked this pull request as ready for review October 18, 2020 15:40
@madmiraal madmiraal force-pushed the fix-41065-3.2 branch 2 times, most recently from fb3ebe6 to 8ec1bfc Compare October 18, 2020 15:54
@salvob41
Copy link
Contributor

it seems that the last buld works good!! I will test it better in a few minutes

@madmiraal
Copy link
Contributor Author

I've added a fix for the mapping not taking into account that an axis range may be only positive even if it represents negative values, and removed the debug message.

@salvob41
Copy link
Contributor

Yeahh! I tested it with my controllers and I confirm that this work!

Congratulation @madmiraal on your work, perseverance and patience.
Great job!

@salvob41
Copy link
Contributor

But there is a problem @madmiraal .

If I use the get_action_strength on the left analogic it gives me 0 when not pressed or 1 when pressed. not middle values.

In 3.2.2 it gives me values between 0 and 1

@madmiraal
Copy link
Contributor Author

madmiraal commented Oct 19, 2020

If I use the get_action_strength on the left analogic it gives me 0 when not pressed or 1 when pressed. not middle values.

The controller's mapping takes D-Pad hat events and maps them to axis events. Hat events only contain a direction, not a magnitude, so they can only be mapped to 0 or 1.

In 3.2.2 the mapping wasn't supported; so there was no mapping: axis0 events were simply treated as left x-axis events and axis1 events were simply treated as left y-axis events.

I think the mapping is odd. It maps axis events to hat events and visa-versa. This is always going to result in this lost information. If you think the mapping is wrong, then it needs to be updated upstream: https://github.com/gabomdq/SDL_GameControllerDB.

@salvob41
Copy link
Contributor

Yes.... I am diving into the mapping and there is something weird.

I tried it on a Linux and it recognised the joypad as PS3 controller.

Will try to see what is wrong with the mapping

@salvob41
Copy link
Contributor

So I put this mapping:

030000008f0e00000300000009010000,2In1 USB Joystick,a:b2,b:b1,x:b3,y:b0,back:b8,start:b9,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,platform:Mac OS X

and the analogic works. I only see that when I press the Dpad (it works well) but the buttons seems to be held pressed.

@madmiraal
Copy link
Contributor Author

when I press the Dpad (it works well) but the buttons seems to be held pressed.

Are you saying that when you release the D-pad, the buttons (12, 13, 14 and 15) are remaining pressed?

@salvob41
Copy link
Contributor

when I press the Dpad (it works well) but the buttons seems to be held pressed.

Are you saying that when you release the D-pad, the buttons (12, 13, 14 and 15) are remaining pressed?

Yes

@madmiraal
Copy link
Contributor Author

@salvob41 I'm confused. Please provide one of your videos with what you're seeing now.

@salvob41
Copy link
Contributor

salvob41 commented Oct 23, 2020

@salvob41 I'm confused. Please provide one of your videos with what you're seeing now.

@madmiraal Sorry for the confusion. Here's a video:
https://imgur.com/a/WyvgzXC

Dpad button works great, but seems the are kept pressed (weird).

Analogic works well (you can see it even shows the strength)

@madmiraal
Copy link
Contributor Author

I think I've fixed the bug that was causing the D-Pad buttons to stick.

@salvob41 If you don't mind, please test it again.

@salvob41
Copy link
Contributor

salvob41 commented Oct 26, 2020

@madmiraal Something added recently on 3.2 doesn't make me build from source. I receive this error message:

$ scons platform=osx arch=x86_64 --jobs=$(sysctl -n hw.logicalcpu)
scons: Reading SConscript files ...
xcrun: error: SDK "iphoneos" cannot be located
xcrun: error: SDK "iphoneos" cannot be located
xcrun: error: unable to lookup item 'SDKVersion' in SDK 'iphoneos'
Failed to find SDK version while running xcrun --sdk iphoneos --show-sdk-version.
CalledProcessError: Command '['xcrun', '--sdk', 'iphoneos', '--show-sdk-version']' returned non-zero exit status 1.:
  File "/Users/panoramix/Desktop/coding/notapixelstudio/godot/SConstruct", line 43:
    if detect.can_build():
  File "./platform/iphone/detect.py", line 17:
    if get_darwin_sdk_version("iphone") < 13.0:
  File "/Users/panoramix/Desktop/coding/notapixelstudio/godot/methods.py", line 717:
    return float(decode_utf8(subprocess.check_output(["xcrun", "--sdk", sdk_name, "--show-sdk-version"]).strip()))
  File "/usr/local/opt/[email protected]/Frameworks/Python.framework/Versions/3.8/lib/python3.8/subprocess.py", line 411:
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "/usr/local/opt/[email protected]/Frameworks/Python.framework/Versions/3.8/lib/python3.8/subprocess.py", line 512:
    raise CalledProcessError(retcode, process.args,

I should open a issue, but I cannot test it otherwise

edited:
This will be fixed in #43091 But now I can test it, will let you know soon

@madmiraal
Copy link
Contributor Author

Rebased following merge of #43091.

@salvob41
Copy link
Contributor

🥳 @madmiraal !! It works! Everything is in place.

Analogic stick: perfect.
Dpad correctly pressed.
Dpad correctly released.

For the 2in1 USB Joystick in particular: This needs to be merged
as the correct mapping mdqinc/SDL_GameControllerDB#391 .
Then we will sync the game_controllerdb.txt in Godot.

Thank you, @madmiraal

@akien-mga
Copy link
Member

Thanks a ton to both of you, amazing work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants