SDL Input: More minor refactoring of SDL haptic effects

This commit is contained in:
Adam D. Moss 2015-01-11 11:42:30 +00:00
parent f47cce2210
commit 63660cb17c
1 changed files with 36 additions and 63 deletions

View File

@ -208,42 +208,34 @@ std::string Joystick::LeftRightEffect::GetName() const
void Joystick::HapticEffect::SetState(ControlState state) void Joystick::HapticEffect::SetState(ControlState state)
{ {
memset(&m_effect, 0, sizeof(m_effect)); memset(&m_effect, 0, sizeof(m_effect));
if (state)
{
SetSDLHapticEffect(state); SetSDLHapticEffect(state);
}
else
{
// this module uses type==0 to indicate 'off'
m_effect.type = 0;
}
Update(); Update();
} }
void Joystick::ConstantEffect::SetSDLHapticEffect(ControlState state) void Joystick::ConstantEffect::SetSDLHapticEffect(ControlState state)
{ {
if (state)
{
m_effect.type = SDL_HAPTIC_CONSTANT; m_effect.type = SDL_HAPTIC_CONSTANT;
m_effect.constant.length = SDL_HAPTIC_INFINITY; m_effect.constant.length = SDL_HAPTIC_INFINITY;
m_effect.constant.level = (Sint16)(state * 0x7FFF); m_effect.constant.level = (Sint16)(state * 0x7FFF);
}
else
{
m_effect.type = 0;
}
} }
void Joystick::RampEffect::SetSDLHapticEffect(ControlState state) void Joystick::RampEffect::SetSDLHapticEffect(ControlState state)
{ {
if (state)
{
m_effect.type = SDL_HAPTIC_RAMP; m_effect.type = SDL_HAPTIC_RAMP;
m_effect.ramp.length = SDL_HAPTIC_INFINITY; m_effect.ramp.length = SDL_HAPTIC_INFINITY;
m_effect.ramp.start = (Sint16)(state * 0x7FFF); m_effect.ramp.start = (Sint16)(state * 0x7FFF);
}
else
{
m_effect.type = 0;
}
} }
void Joystick::SineEffect::SetSDLHapticEffect(ControlState state) void Joystick::SineEffect::SetSDLHapticEffect(ControlState state)
{ {
if (state)
{
m_effect.type = SDL_HAPTIC_SINE; m_effect.type = SDL_HAPTIC_SINE;
m_effect.periodic.period = 1000; m_effect.periodic.period = 1000;
m_effect.periodic.magnitude = (Sint16)(state * 0x7FFF); m_effect.periodic.magnitude = (Sint16)(state * 0x7FFF);
@ -252,17 +244,10 @@ void Joystick::SineEffect::SetSDLHapticEffect(ControlState state)
m_effect.periodic.length = SDL_HAPTIC_INFINITY; m_effect.periodic.length = SDL_HAPTIC_INFINITY;
m_effect.periodic.delay = 0; m_effect.periodic.delay = 0;
m_effect.periodic.attack_length = 0; m_effect.periodic.attack_length = 0;
}
else
{
m_effect.type = 0;
}
} }
void Joystick::TriangleEffect::SetSDLHapticEffect(ControlState state) void Joystick::TriangleEffect::SetSDLHapticEffect(ControlState state)
{ {
if (state)
{
m_effect.type = SDL_HAPTIC_TRIANGLE; m_effect.type = SDL_HAPTIC_TRIANGLE;
m_effect.periodic.period = 1000; m_effect.periodic.period = 1000;
m_effect.periodic.magnitude = (Sint16)(state * 0x7FFF); m_effect.periodic.magnitude = (Sint16)(state * 0x7FFF);
@ -271,27 +256,15 @@ void Joystick::TriangleEffect::SetSDLHapticEffect(ControlState state)
m_effect.periodic.length = SDL_HAPTIC_INFINITY; m_effect.periodic.length = SDL_HAPTIC_INFINITY;
m_effect.periodic.delay = 0; m_effect.periodic.delay = 0;
m_effect.periodic.attack_length = 0; m_effect.periodic.attack_length = 0;
}
else
{
m_effect.type = 0;
}
} }
void Joystick::LeftRightEffect::SetSDLHapticEffect(ControlState state) void Joystick::LeftRightEffect::SetSDLHapticEffect(ControlState state)
{ {
if (state)
{
m_effect.type = SDL_HAPTIC_LEFTRIGHT; m_effect.type = SDL_HAPTIC_LEFTRIGHT;
m_effect.leftright.length = SDL_HAPTIC_INFINITY; m_effect.leftright.length = SDL_HAPTIC_INFINITY;
// max ranges tuned to 'feel' similar in magnitude to triangle/sine on xbox360 controller // max ranges tuned to 'feel' similar in magnitude to triangle/sine on xbox360 controller
m_effect.leftright.large_magnitude = (Uint16)(state * 0x4000); m_effect.leftright.large_magnitude = (Uint16)(state * 0x4000);
m_effect.leftright.small_magnitude = (Uint16)(state * 0xFFFF); m_effect.leftright.small_magnitude = (Uint16)(state * 0xFFFF);
}
else
{
m_effect.type = 0;
}
} }
#endif #endif