libretro / Craft

A simple Minecraft clone written in C using modern OpenGL (shaders).
http://www.michaelfogleman.com/craft/
MIT License
43 stars 19 forks source link

Gamepad: Character won't stop moving. #9

Closed orbea closed 4 years ago

orbea commented 8 years ago

OS: Slackware64-current RetroArch-1.3.4-x86_64-6_SBo Craft-libretro-2aff567_2016.06.23_master-x86_64-1_git

With some gamepads plugged in the character won't stop moving even if nothing is being pressed on the keyboard or gamepad, both movement and view. This will stop and start as soon as the gamepad is removed or plugged in and will not happen with only the keyboard. One idea is that any gamepads with more than a d-pad will do it?

Causes issues: https://github.com/libretro/retroarch-joypad-autoconfig/blob/master/udev/Logic3%20Controller.cfg https://github.com/libretro/retroarch-joypad-autoconfig/blob/master/udev/Sony-PlayStation3-DualShock3-Controller-USB.cfg

No issues: https://github.com/libretro/retroarch-joypad-autoconfig/blob/master/udev/Smartjoy%20Family%20Super%20Smartjoy%202.cfg https://github.com/libretro/retroarch-joypad-autoconfig/blob/master/udev/HORI%20CO.%2CLTD.%20REAL%20ARCADE%20PRO.3.cfg

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/35475639-gamepad-character-won-t-stop-moving?utm_campaign=plugin&utm_content=tracker%2F32425093&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F32425093&utm_medium=issues&utm_source=github).
orbea commented 8 years ago

I checked my old packages and found this issue did not used to exist so I did a git bisect and got this.

$ git bisect bad
6afd540ac19ec29b48ecf1997136d5a31ab7fd1e is the first bad commit
commit 6afd540ac19ec29b48ecf1997136d5a31ab7fd1e
Author: rz5 <razevok@gmail.com>
Date:   Fri Mar 11 18:50:39 2016 +0000

    Prevent camera flip and add 3 core options.
    Right analog sensitivity and deadzone size and invert aim.

:040000 040000 b2e37add493b5ddd30690129c9c58f0416c8c51c d787c736e8b4aaaa0c8e7678dc2e17a41811d2e3 M  libretro
:040000 040000 ac8ee3c3d6c6c745b0437cdeee0691b39aa89d59 3e8f83018e0aaf92ff669e0558c68fbc2177eb22 M  src

So to confirm this I built each commit.

Commit https://github.com/libretro/Craft/commit/6afd540ac19ec29b48ecf1997136d5a31ab7fd1e causes the issue obviously. Commit https://github.com/libretro/Craft/commit/28ce0e17b37181396caa6b7b0c54c792ce65f296 does not obviously cause the issue, but will still cause it if the right stick is moved left, but then can be stopped again if moved in another direction.

So I tried to git bisect again.

$ git bisect bad
a37a4147c1b378ab7d9006faff0ed3602f31a9b4 is the first bad commit
commit a37a4147c1b378ab7d9006faff0ed3602f31a9b4
Author: rz5 <razevok@gmail.com>
Date:   Fri Mar 11 01:44:27 2016 +0000

    Implemented analog controls for movement and aim.

:040000 040000 ab6928fc40a0eed8d109731a1130ed2109589402 7b4ea68989c5bb1f8d0fb8b76ea21b1532b24635 M  src

And tried each commit manually again.

Commit https://github.com/libretro/Craft/commit/a37a4147c1b378ab7d9006faff0ed3602f31a9b4 introduced both the issue and the ability to aim with the right control stick. This means the aiming implementation has not been working quite right from the start. Commit https://github.com/libretro/Craft/commit/2b781e7946a12c61ee2ec075a12db242cfa348be does not cause the issue, but of course it lacks the functionality to aim with the right stick altogether.

Another issue is that both of the above commits are in the midst of when Craft-libretro was in an extremely broken state where no textures rendered and all that was visible was a vast blue nothing and some empty boxes. 1

So once more I tried to git bisect it.

$ git bisect good
46128bd93846ef81321db2426e9f1ac783701b6a is the first bad commit
commit 46128bd93846ef81321db2426e9f1ac783701b6a
Author: twinaphex <libretro@gmail.com>
Date:   Fri Mar 11 13:02:21 2016 +0100

    Fix desktop GL

:040000 040000 eb4494355f7c5fadabd1439e1104d031170af3f9 a426a858fb25055649750939a64134be76113c4e M  src

Commit https://github.com/libretro/Craft/commit/46128bd93846ef81321db2426e9f1ac783701b6a is where the blue screen was fixed. Commit https://github.com/libretro/Craft/commit/0d47b397b3693592711ab64fccd99e8a7c3ba38c causes a new black screen + crosshair. Commit https://github.com/libretro/Craft/commit/4e406e1ffb956b3374ed97b54b2955f35570f4cd causes the familiar blue screen.

orbea commented 8 years ago

A deadzone of 0.055 stops the right analog view from moving, but does not stop the left analog character movement.

Edit: Even with a deadzone of 0.055 or higher I can still trigger the spinning/tilting by pushing the right stick left as was case in commit https://github.com/libretro/Craft/commit/28ce0e17b37181396caa6b7b0c54c792ce65f296 and earlier.

rz5 commented 8 years ago

As it is, the same deadzone radius is used for right and left analog sticks. If the player is moving while the gamepad is idle (sticks centered), then my best guess is that the sticks don't properly go back to the center; the problem is so bad that the sticks are reporting values outside of the deadzone.

For now, I can bump up how big the deadzone can be.

orbea commented 8 years ago

Craft-libretro-f7fe382_2016.06.25_master-x86_64-1_git

Thanks, with the latest commit for my Logic3 Controller (Xbox 360) the right stick spinning stops at 0.065 and the left stick character movement stops at 0.090.

However for my Sony PlayStation3 DualShock3 USB Controller I can cause it to easily spin and move even at 0.100.

orbea commented 8 years ago

My Sony PlayStation3 DualShock3 USB Controller will stop spinning with a deadzone of 0.175. This problem has been mitigated for me, but in hopes a better solution can be found I will leave this open. If this solution is good enough feel free to close this.

orbea commented 8 years ago

This might be the problem. As shown with sdl(2)-jstest my Logic3 Controller is constantly sending out garbage events.

$ sdl2-jstest --event 1
Joystick Name:     'Logic3 Controller'
Joystick GUID:     030000006f0e00000104000000010000
Joystick Number:    1
Number of Axes:     6
Number of Buttons: 11
Number of Hats:     1
Number of Balls:    0
GameController:
  not a gamepad

Entering joystick test loop, press Ctrl-c to exit
SDL_JOYDEVICEADDED which:0
SDL_JOYDEVICEADDED which:1
SDL_CONTROLLERDEVICEADDED which:1
SDL_JOYAXISMOTION: joystick: 1 axis: 0 value: -399
SDL_JOYAXISMOTION: joystick: 1 axis: 1 value: -1671
SDL_JOYAXISMOTION: joystick: 1 axis: 2 value: -32768
SDL_JOYAXISMOTION: joystick: 1 axis: 3 value: -1592
SDL_JOYAXISMOTION: joystick: 1 axis: 4 value: 490
SDL_JOYAXISMOTION: joystick: 1 axis: 5 value: -32768
SDL_JOYAXISMOTION: joystick: 1 axis: 1 value: -1750
SDL_JOYAXISMOTION: joystick: 1 axis: 1 value: -1671
SDL_JOYAXISMOTION: joystick: 1 axis: 1 value: -1750
SDL_JOYAXISMOTION: joystick: 1 axis: 1 value: -1671
SDL_JOYAXISMOTION: joystick: 1 axis: 1 value: -1750
SDL_JOYAXISMOTION: joystick: 1 axis: 1 value: -1671
SDL_JOYAXISMOTION: joystick: 1 axis: 1 value: -1750
SDL_JOYAXISMOTION: joystick: 1 axis: 1 value: -1671
SDL_JOYAXISMOTION: joystick: 1 axis: 0 value: -293
SDL_JOYAXISMOTION: joystick: 1 axis: 0 value: -399
SDL_JOYAXISMOTION: joystick: 1 axis: 1 value: -1750
SDL_JOYAXISMOTION: joystick: 1 axis: 1 value: -1671
...

While the obviously higher quality Hori Co. Ltd. Real Aracade Pro 3 fight stick does not suffer from this issue.

rz5 commented 8 years ago

So it is the hardware not behaving properly, ok. I'm not sure which of those values is the the joystick at resting position, but I think that if you take the absolute of that value (seems to be ~1800?) and divide it by the upper limit (~ 2^16 / 2), that should tell you what the deadzone radius should look like.

E.g. (1800 / (2^16 / 2)) = ~0.055 deadzone radius

Alternatively, you could try to see if there's a way to calibrate your gamepad's analog inputs. Specifically, if it looks like the sticks rest at (and fall back to) the same value, then that value would become the new zero.

orbea commented 8 years ago

The controller was never touched during the test. It seems the higher numbers represent the right stick and the lower numbers represent the left stick then. I'm not sure I can calibrate the gamepad, but I will look for a program that allows me to do that.

For comparison here is the PS3 controller.

$ sdl2-jstest --event 1
Joystick Name:     'Sony PLAYSTATION(R)3 Controller'
Joystick GUID:     030000004c0500006802000011010000
Joystick Number:    1
Number of Axes:    27
Number of Buttons: 19
Number of Hats:     0
Number of Balls:    0
GameController:
  not a gamepad

Entering joystick test loop, press Ctrl-c to exit
SDL_JOYDEVICEADDED which:0
SDL_JOYDEVICEADDED which:1
SDL_CONTROLLERDEVICEADDED which:1
SDL_JOYAXISMOTION: joystick: 1 axis: 4 value: -32768
SDL_JOYAXISMOTION: joystick: 1 axis: 5 value: -32768
SDL_JOYAXISMOTION: joystick: 1 axis: 6 value: -32768
SDL_JOYAXISMOTION: joystick: 1 axis: 7 value: -32768
SDL_JOYAXISMOTION: joystick: 1 axis: 8 value: -32768
SDL_JOYAXISMOTION: joystick: 1 axis: 9 value: -32768
SDL_JOYAXISMOTION: joystick: 1 axis: 10 value: -32768
SDL_JOYAXISMOTION: joystick: 1 axis: 11 value: -32768
SDL_JOYAXISMOTION: joystick: 1 axis: 12 value: -32768
SDL_JOYAXISMOTION: joystick: 1 axis: 13 value: -32768
SDL_JOYAXISMOTION: joystick: 1 axis: 14 value: -32768
SDL_JOYAXISMOTION: joystick: 1 axis: 15 value: -32768
SDL_JOYAXISMOTION: joystick: 1 axis: 16 value: -32768
SDL_JOYAXISMOTION: joystick: 1 axis: 17 value: -32768
SDL_JOYAXISMOTION: joystick: 1 axis: 18 value: -32768
SDL_JOYAXISMOTION: joystick: 1 axis: 19 value: -32768
SDL_JOYAXISMOTION: joystick: 1 axis: 25 value: -2763
SDL_JOYAXISMOTION: joystick: 1 axis: 25 value: -2678
SDL_JOYAXISMOTION: joystick: 1 axis: 25 value: -2763
SDL_JOYAXISMOTION: joystick: 1 axis: 25 value: -2678
SDL_JOYAXISMOTION: joystick: 1 axis: 25 value: -2593
SDL_JOYAXISMOTION: joystick: 1 axis: 25 value: -2678
SDL_JOYAXISMOTION: joystick: 1 axis: 25 value: -2593
SDL_JOYAXISMOTION: joystick: 1 axis: 25 value: -2678
SDL_JOYAXISMOTION: joystick: 1 axis: 25 value: -2593
SDL_JOYAXISMOTION: joystick: 1 axis: 25 value: -2678
SDL_JOYAXISMOTION: joystick: 1 axis: 25 value: -2593