- Added deadzone handling to SDL joystick support.

SVN r3605 (trunk)
This commit is contained in:
Braden Obrzut 2012-04-28 03:44:10 +00:00
parent c07eaa4d31
commit 0065c29902
2 changed files with 27 additions and 1 deletions

View file

@ -493,10 +493,13 @@ void I_StartTic ()
I_GetEvent ();
}
void I_ProcessJoysticks ();
void I_StartFrame ()
{
if (KeySymToDIK[SDLK_BACKSPACE] == 0)
{
InitKeySymMap ();
}
I_ProcessJoysticks();
}

View file

@ -98,6 +98,7 @@ public:
info.Name.Format("Axis %d", i);
info.DeadZone = 0.0f;
info.Multiplier = 1.0f;
info.Value = 0.0;
if(i >= 5)
info.GameAxis = JOYAXIS_None;
else
@ -118,7 +119,16 @@ public:
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);
axes[Axes[i].GameAxis] -= float(Axes[i].Value * Multiplier * Axes[i].Multiplier);
}
}
void ProcessInput()
{
for (int i = 0; i < GetNumAxes(); ++i)
{
Axes[i].Value = SDL_JoystickGetAxis(Device, i)/32768.0;
Axes[i].Value = Joy_RemoveDeadZone(Axes[i].Value, Axes[i].DeadZone, NULL);
}
}
@ -129,6 +139,7 @@ protected:
float DeadZone;
float Multiplier;
EJoyAxis GameAxis;
double Value;
};
static const EJoyAxis DefaultAxes[5];
@ -173,6 +184,12 @@ public:
sticks.Push(Joysticks[i]);
}
}
void ProcessInput() const
{
for(unsigned int i = 0;i < Joysticks.Size();++i)
Joysticks[i]->ProcessInput();
}
protected:
TArray<SDLInputJoystick *> Joysticks;
};
@ -206,6 +223,12 @@ void I_GetAxes(float axes[NUM_JOYAXIS])
}
}
void I_ProcessJoysticks()
{
if (use_joystick)
JoystickManager->ProcessInput();
}
IJoystickConfig *I_UpdateDeviceList()
{
return NULL;