mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-27 22:33:17 +00:00
- Minor adjustments to SDL joystick code so that all axes have at least a small deadzone so that button mapping works properly.
This commit is contained in:
parent
27f6b3c9f3
commit
811a75ebf6
1 changed files with 8 additions and 4 deletions
|
@ -1,8 +1,12 @@
|
||||||
#include <SDL_joystick.h>
|
#include <SDL_joystick.h>
|
||||||
|
|
||||||
#include "doomdef.h"
|
#include "doomdef.h"
|
||||||
|
#include "templates.h"
|
||||||
#include "m_joy.h"
|
#include "m_joy.h"
|
||||||
|
|
||||||
|
// Very small deadzone so that floating point magic doesn't happen
|
||||||
|
#define MIN_DEADZONE 0.000001f
|
||||||
|
|
||||||
class SDLInputJoystick: public IJoystickConfig
|
class SDLInputJoystick: public IJoystickConfig
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -65,7 +69,7 @@ public:
|
||||||
|
|
||||||
void SetAxisDeadZone(int axis, float zone)
|
void SetAxisDeadZone(int axis, float zone)
|
||||||
{
|
{
|
||||||
Axes[axis].DeadZone = zone;
|
Axes[axis].DeadZone = clamp(zone, MIN_DEADZONE, 1.f);
|
||||||
}
|
}
|
||||||
void SetAxisMap(int axis, EJoyAxis gameaxis)
|
void SetAxisMap(int axis, EJoyAxis gameaxis)
|
||||||
{
|
{
|
||||||
|
@ -83,7 +87,7 @@ public:
|
||||||
}
|
}
|
||||||
bool IsAxisDeadZoneDefault(int axis)
|
bool IsAxisDeadZoneDefault(int axis)
|
||||||
{
|
{
|
||||||
return Axes[axis].DeadZone == 0.0f;
|
return Axes[axis].DeadZone <= MIN_DEADZONE;
|
||||||
}
|
}
|
||||||
bool IsAxisMapDefault(int axis)
|
bool IsAxisMapDefault(int axis)
|
||||||
{
|
{
|
||||||
|
@ -105,7 +109,7 @@ public:
|
||||||
info.Name.Format("Axis %d", i+1);
|
info.Name.Format("Axis %d", i+1);
|
||||||
else
|
else
|
||||||
info.Name.Format("Hat %d (%c)", (i-NumAxes)/2 + 1, (i-NumAxes)%2 == 0 ? 'x' : 'y');
|
info.Name.Format("Hat %d (%c)", (i-NumAxes)/2 + 1, (i-NumAxes)%2 == 0 ? 'x' : 'y');
|
||||||
info.DeadZone = 0.0f;
|
info.DeadZone = MIN_DEADZONE;
|
||||||
info.Multiplier = 1.0f;
|
info.Multiplier = 1.0f;
|
||||||
info.Value = 0.0;
|
info.Value = 0.0;
|
||||||
info.ButtonValue = 0;
|
info.ButtonValue = 0;
|
||||||
|
@ -141,7 +145,7 @@ public:
|
||||||
{
|
{
|
||||||
buttonstate = 0;
|
buttonstate = 0;
|
||||||
|
|
||||||
Axes[i].Value = SDL_JoystickGetAxis(Device, i)/32768.0;
|
Axes[i].Value = SDL_JoystickGetAxis(Device, i)/32767.0;
|
||||||
Axes[i].Value = Joy_RemoveDeadZone(Axes[i].Value, Axes[i].DeadZone, &buttonstate);
|
Axes[i].Value = Joy_RemoveDeadZone(Axes[i].Value, Axes[i].DeadZone, &buttonstate);
|
||||||
|
|
||||||
// Map button to axis
|
// Map button to axis
|
||||||
|
|
Loading…
Reference in a new issue