[r3386] [SDL] Joystick deadzone settings are ignored - PATCH

Forum rules
Please don't bump threads here if you have a problem - it will often be forgotten about if you do. Instead, make a new thread here.

Post a reply

Smilies
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :geek: :ugeek: :!: :?: :idea: :arrow: :| :mrgreen: :3: :wub: >:( :blergh:
View more smilies

BBCode is OFF
Smilies are ON

Topic review
   

Expand view Topic review: [r3386] [SDL] Joystick deadzone settings are ignored - PATCH

Re: [r3386] [SDL] Joystick deadzone settings are ignored - P

by Blzut3 » Sat Apr 28, 2012 6:55 pm

I realized I had a crappy wireless USB controller laying around so went and added the button mapping (and POV hat support). Is it intentional the the menu move up/down is assigned to joystick axis 1 (x) and left right assigned to joystick axis 2 (y) for generic joysticks?

Also, I should note that in regards to button mapping all axes. From what I can tell ZDoom only support mapping 8 axes due to the limitation in DirectInput. On Linux there is no problem with having a much larger number of axes. (IIRC the PS3 controller has 24.) That said, besides the sixaxis motion axes (which are the final 4), the others are all button mapped in the driver since they're just the individual button's pressure sensitivity.

Re: [r3386] [SDL] Joystick deadzone settings are ignored - P

by randi » Sat Apr 28, 2012 4:38 pm

I have an XBox 360 Controller. For the best parallel with Windows, every axis also needs to generate button events.

As for referencing the Windows code, you should probably be looking at the XInput code instead of DirectInput. The DirectInput version is rather complicated, since it needs to work with completely generic input devices, whereas the XInput code is short and to-the-point.

Re: [r3386] [SDL] Joystick deadzone settings are ignored - P

by Blzut3 » Fri Apr 27, 2012 10:21 pm

Do you have such a controller on hand? The only joystick I have that matches that description is my PS3 Sixaxis/Dual Shock 3 controllers, but on Linux the button mapping is already done for those controllers.

I suppose I could make due with button mapping the analog sticks, but I notice the direct input code makes an exception for the first one or something like that.

Re: [r3386] [SDL] Joystick deadzone settings are ignored - P

by randi » Fri Apr 27, 2012 10:16 pm

Blzut3 wrote:the direct input code on Windows has some kind of Axis to button mapping code that I'm not entirely sure if that needs to be ported.
It should be. Controllers these days commonly have two trigger buttons that are analog axes, so if you don't do axis to button mapping, you can't use them as buttons.

Re: [r3386] [SDL] Joystick deadzone settings are ignored - P

by Blzut3 » Fri Apr 27, 2012 9:45 pm

For some reason I thought that would be more work than it was... Anyways, fixed. One thing to note is that the direct input code on Windows has some kind of Axis to button mapping code that I'm not entirely sure if that needs to be ported.

Re: [r3386] [SDL] Joystick deadzone settings are ignored - P

by Blzut3 » Fri Feb 24, 2012 8:11 pm

Looking at the relevent Windows code this is not the proper way to handle the Dead Zones. The Windows code has a ProcessInput() function which is called from I_StartFrame. The negation of the dead zone should be handled by Joy_RemoveDeadZone().

[r3386] [SDL] Joystick deadzone settings are ignored - PATCH

by _mental_ » Thu Feb 23, 2012 10:19 am

In SDL-based builds joystick deadzone settings are not taken into account when setting axes values.
This issue can be fixed with a small change, here is a patch:

Code: Select all

Index: src/sdl/i_joystick.cpp
===================================================================
--- src/sdl/i_joystick.cpp	(revision 3386)
+++ src/sdl/i_joystick.cpp	(working copy)
@@ -118,7 +118,13 @@
 		for (int i = 0; i < GetNumAxes(); ++i)
 		{
 			if(Axes[i].GameAxis != JOYAXIS_None)
-				axes[Axes[i].GameAxis] -= float(((double)SDL_JoystickGetAxis(Device, i)/32768.0) * Multiplier * Axes[i].Multiplier);
+			{
+				const float axisValue = SDL_JoystickGetAxis( Device, i ) / 32768.0f * Multiplier * Axes[i].Multiplier;
+				if ( fabsf( axisValue ) > Axes[i].DeadZone )
+				{
+					axes[Axes[i].GameAxis] -= axisValue;
+				}
+			}
 		}
 	}
Tested on Mac OS X but will work on all SDL-based target platform.

Top