diff options
| author | Ryan Houdek <Sonicadvance1@gmail.com> | 2014-12-07 01:22:03 -0600 |
|---|---|---|
| committer | Ryan Houdek <Sonicadvance1@gmail.com> | 2014-12-07 01:22:03 -0600 |
| commit | d9d0e285c94b205d3b59b55b4d0dfec9d78b2683 (patch) | |
| tree | 166e75747843fc652a39cc683b4aa399c30e2c17 /Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp | |
| parent | 4e98078dafe0075a02c371ae463a4b933ca04d6d (diff) | |
| parent | 854f6b8688063544310edbc0fc27a8c42f517d9b (diff) | |
Merge pull request #1560 from magcius/pad-cleanup-1
Pad cleanup 1
Diffstat (limited to 'Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp')
| -rw-r--r-- | Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp | 176 |
1 files changed, 61 insertions, 115 deletions
diff --git a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp index b745f7b2d4..a46a08100d 100644 --- a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp +++ b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp @@ -121,40 +121,26 @@ Joystick::Joystick(SDL_Joystick* const joystick, const int sdl_index, const unsi // constant effect if (supported_effects & SDL_HAPTIC_CONSTANT) - { - m_state_out.push_back(EffectIDState()); - AddOutput(new ConstantEffect(m_state_out.back())); - } + AddOutput(new ConstantEffect(m_haptic)); // ramp effect if (supported_effects & SDL_HAPTIC_RAMP) - { - m_state_out.push_back(EffectIDState()); - AddOutput(new RampEffect(m_state_out.back())); - } + AddOutput(new RampEffect(m_haptic)); // sine effect if (supported_effects & SDL_HAPTIC_SINE) - { - m_state_out.push_back(EffectIDState()); - AddOutput(new SineEffect(m_state_out.back())); - } + AddOutput(new SineEffect(m_haptic)); #ifdef SDL_HAPTIC_SQUARE // square effect if (supported_effects & SDL_HAPTIC_SQUARE) - { - m_state_out.push_back(EffectIDState()); - AddOutput(new SquareEffect(m_state_out.back())); - } + AddOutput(new SquareEffect(m_haptic)); + #endif // defined(SDL_HAPTIC_SQUARE) // triangle effect if (supported_effects & SDL_HAPTIC_TRIANGLE) - { - m_state_out.push_back(EffectIDState()); - AddOutput(new TriangleEffect(m_state_out.back())); - } + AddOutput(new TriangleEffect(m_haptic)); } #endif @@ -167,13 +153,6 @@ Joystick::~Joystick() { // stop/destroy all effects SDL_HapticStopAll(m_haptic); - for (auto &i : m_state_out) - { - if (i.id != -1) - { - SDL_HapticDestroyEffect(m_haptic, i.id); - } - } // close haptic first SDL_HapticClose(m_haptic); } @@ -184,6 +163,26 @@ Joystick::~Joystick() } #ifdef USE_SDL_HAPTIC +void Joystick::HapticEffect::Update() +{ + if (m_id == -1 && m_effect.type > 0) + { + m_id = SDL_HapticNewEffect(m_haptic, &m_effect); + if (m_id > -1) + SDL_HapticRunEffect(m_haptic, m_id, 1); + } + else if (m_id > -1 && m_effect.type == 0) + { + SDL_HapticStopEffect(m_haptic, m_id); + SDL_HapticDestroyEffect(m_haptic, m_id); + m_id = -1; + } + else if (m_id > -1) + { + SDL_HapticUpdateEffect(m_haptic, m_id, &m_effect); + } +} + std::string Joystick::ConstantEffect::GetName() const { return "Constant"; @@ -215,58 +214,51 @@ void Joystick::ConstantEffect::SetState(ControlState state) { if (state) { - m_effect.effect.type = SDL_HAPTIC_CONSTANT; - m_effect.effect.constant.length = SDL_HAPTIC_INFINITY; + m_effect.type = SDL_HAPTIC_CONSTANT; + m_effect.constant.length = SDL_HAPTIC_INFINITY; } else { - m_effect.effect.type = 0; + m_effect.type = 0; } - const Sint16 old = m_effect.effect.constant.level; - m_effect.effect.constant.level = (Sint16)(state * 0x7FFF); - if (old != m_effect.effect.constant.level) - m_effect.changed = true; + m_effect.constant.level = (Sint16)(state * 0x7FFF); + Update(); } void Joystick::RampEffect::SetState(ControlState state) { if (state) { - m_effect.effect.type = SDL_HAPTIC_RAMP; - m_effect.effect.ramp.length = SDL_HAPTIC_INFINITY; + m_effect.type = SDL_HAPTIC_RAMP; + m_effect.ramp.length = SDL_HAPTIC_INFINITY; } else { - m_effect.effect.type = 0; + m_effect.type = 0; } - const Sint16 old = m_effect.effect.ramp.start; - m_effect.effect.ramp.start = (Sint16)(state * 0x7FFF); - if (old != m_effect.effect.ramp.start) - m_effect.changed = true; + m_effect.ramp.start = (Sint16)(state * 0x7FFF); + Update(); } void Joystick::SineEffect::SetState(ControlState state) { if (state) { - m_effect.effect.type = SDL_HAPTIC_SINE; - m_effect.effect.periodic.length = 250; + m_effect.type = SDL_HAPTIC_SINE; + m_effect.periodic.length = 250; } else { - m_effect.effect.type = 0; + m_effect.type = 0; } - const Sint16 old = m_effect.effect.periodic.magnitude; - m_effect.effect.periodic.period = 5; - m_effect.effect.periodic.magnitude = (Sint16)(state * 0x5000); - m_effect.effect.periodic.attack_length = 0; - m_effect.effect.periodic.fade_length = 500; - - if (old != m_effect.effect.periodic.magnitude) - m_effect.changed = true; + m_effect.periodic.period = 5; + m_effect.periodic.magnitude = (Sint16)(state * 0x5000); + m_effect.periodic.attack_length = 0; + m_effect.periodic.fade_length = 500; + Update(); } #ifdef SDL_HAPTIC_SQUARE @@ -274,22 +266,19 @@ void Joystick::SquareEffect::SetState(ControlState state) { if (state) { - m_effect.effect.type = SDL_HAPTIC_SQUARE; - m_effect.effect.periodic.length = 250; + m_effect.type = SDL_HAPTIC_SQUARE; + m_effect.periodic.length = 250; } else { - m_effect.effect.type = 0; + m_effect.type = 0; } - const Sint16 old = m_effect.effect.periodic.magnitude; - m_effect.effect.periodic.period = 5; - m_effect.effect.periodic.magnitude = state * 0x5000; - m_effect.effect.periodic.attack_length = 0; - m_effect.effect.periodic.fade_length = 100; - - if (old != m_effect.effect.periodic.magnitude) - m_effect.changed = true; + m_effect.periodic.period = 5; + m_effect.periodic.magnitude = state * 0x5000; + m_effect.periodic.attack_length = 0; + m_effect.periodic.fade_length = 100; + Update(); } #endif // defined(SDL_HAPTIC_SQUARE) @@ -297,69 +286,26 @@ void Joystick::TriangleEffect::SetState(ControlState state) { if (state) { - m_effect.effect.type = SDL_HAPTIC_TRIANGLE; - m_effect.effect.periodic.length = 250; + m_effect.type = SDL_HAPTIC_TRIANGLE; + m_effect.periodic.length = 250; } else { - m_effect.effect.type = 0; + m_effect.type = 0; } - const Sint16 old = m_effect.effect.periodic.magnitude; - m_effect.effect.periodic.period = 5; - m_effect.effect.periodic.magnitude = (Sint16)(state * 0x5000); - m_effect.effect.periodic.attack_length = 0; - m_effect.effect.periodic.fade_length = 100; - - if (old != m_effect.effect.periodic.magnitude) - m_effect.changed = true; + m_effect.periodic.period = 5; + m_effect.periodic.magnitude = (Sint16)(state * 0x5000); + m_effect.periodic.attack_length = 0; + m_effect.periodic.fade_length = 100; + Update(); } #endif -bool Joystick::UpdateInput() +void Joystick::UpdateInput() { // each joystick is doin this, o well SDL_JoystickUpdate(); - - return true; -} - -bool Joystick::UpdateOutput() -{ -#ifdef USE_SDL_HAPTIC - for (auto &i : m_state_out) - { - if (i.changed) // if SetState was called on this output - { - if (-1 == i.id) // effect isn't currently uploaded - { - if (i.effect.type) // if outputstate is >0 this would be true - { - if ((i.id = SDL_HapticNewEffect(m_haptic, &i.effect)) > -1) // upload the effect - { - SDL_HapticRunEffect(m_haptic, i.id, 1); // run the effect - } - } - } - else // effect is already uploaded - { - if (i.effect.type) // if ouputstate >0 - { - SDL_HapticUpdateEffect(m_haptic, i.id, &i.effect); // update the effect - } - else - { - SDL_HapticStopEffect(m_haptic, i.id); // else, stop and remove the effect - SDL_HapticDestroyEffect(m_haptic, i.id); - i.id = -1; // mark it as not uploaded - } - } - - i.changed = false; - } - } -#endif - return true; } std::string Joystick::GetName() const |
