From 34692ab826abc8f8faa61bdb2280b742424528f1 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Sat, 7 Dec 2013 15:14:29 -0500 Subject: Remove unnecessary Src/ folders --- .../InputCommon/ControllerInterface/SDL/SDL.cpp | 406 +++++++++++++++++++++ 1 file changed, 406 insertions(+) create mode 100644 Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp (limited to 'Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp new file mode 100644 index 0000000000..24e0d0de58 --- /dev/null +++ b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp @@ -0,0 +1,406 @@ + +#include "SDL.h" +#include + +#include +#include +#include + +#ifdef _WIN32 +#pragma comment(lib, "SDL2.lib") +#endif + +namespace ciface +{ +namespace SDL +{ + +std::string GetJoystickName(int index) +{ +#if SDL_VERSION_ATLEAST(2, 0, 0) + return SDL_JoystickNameForIndex(index); +#else + return SDL_JoystickName(index); +#endif +} + +void Init( std::vector& devices ) +{ + // this is used to number the joysticks + // multiple joysticks with the same name shall get unique ids starting at 0 + std::map name_counts; + + if (SDL_Init( SDL_INIT_FLAGS ) >= 0) + { + // joysticks + for(int i = 0; i < SDL_NumJoysticks(); ++i) + { + SDL_Joystick* dev = SDL_JoystickOpen(i); + if (dev) + { + Joystick* js = new Joystick(dev, i, name_counts[GetJoystickName(i)]++); + // only add if it has some inputs/outputs + if (js->Inputs().size() || js->Outputs().size()) + devices.push_back( js ); + else + delete js; + } + } + } +} + +Joystick::Joystick(SDL_Joystick* const joystick, const int sdl_index, const unsigned int index) + : m_joystick(joystick) + , m_sdl_index(sdl_index) + , m_index(index) +{ + // really bad HACKS: + // to not use SDL for an XInput device + // too many people on the forums pick the SDL device and ask: + // "why don't my 360 gamepad triggers/rumble work correctly" +#ifdef _WIN32 + // checking the name is probably good (and hacky) enough + // but I'll double check with the num of buttons/axes + std::string lcasename = GetName(); + std::transform(lcasename.begin(), lcasename.end(), lcasename.begin(), tolower); + + if ((std::string::npos != lcasename.find("xbox 360")) + && (10 == SDL_JoystickNumButtons(joystick)) + && (5 == SDL_JoystickNumAxes(joystick)) + && (1 == SDL_JoystickNumHats(joystick)) + && (0 == SDL_JoystickNumBalls(joystick)) + ) + { + // this device won't be used + return; + } +#endif + + // get buttons + for (u8 i = 0; i != SDL_JoystickNumButtons(m_joystick); ++i) + AddInput(new Button(i, m_joystick)); + + // get hats + for (u8 i = 0; i != SDL_JoystickNumHats(m_joystick); ++i) + { + // each hat gets 4 input instances associated with it, (up down left right) + for (u8 d = 0; d != 4; ++d) + AddInput(new Hat(i, m_joystick, d)); + } + + // get axes + for (u8 i = 0; i != SDL_JoystickNumAxes(m_joystick); ++i) + { + // each axis gets a negative and a positive input instance associated with it + AddAnalogInputs(new Axis(i, m_joystick, -32768), + new Axis(i, m_joystick, 32767)); + } + +#ifdef USE_SDL_HAPTIC + // try to get supported ff effects + m_haptic = SDL_HapticOpenFromJoystick( m_joystick ); + if (m_haptic) + { + //SDL_HapticSetGain( m_haptic, 1000 ); + //SDL_HapticSetAutocenter( m_haptic, 0 ); + + const unsigned int supported_effects = SDL_HapticQuery( m_haptic ); + + // constant effect + if (supported_effects & SDL_HAPTIC_CONSTANT) + { + m_state_out.push_back(EffectIDState()); + AddOutput(new ConstantEffect(m_state_out.back())); + } + + // ramp effect + if (supported_effects & SDL_HAPTIC_RAMP) + { + m_state_out.push_back(EffectIDState()); + AddOutput(new RampEffect(m_state_out.back())); + } + + // sine effect + if (supported_effects & SDL_HAPTIC_SINE) + { + m_state_out.push_back(EffectIDState()); + AddOutput(new SineEffect(m_state_out.back())); + } + +#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())); + } +#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())); + } + } +#endif + +} + +Joystick::~Joystick() +{ +#ifdef USE_SDL_HAPTIC + if (m_haptic) + { + // 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); + } +#endif + + // close joystick + SDL_JoystickClose(m_joystick); +} + +#ifdef USE_SDL_HAPTIC +std::string Joystick::ConstantEffect::GetName() const +{ + return "Constant"; +} + +std::string Joystick::RampEffect::GetName() const +{ + return "Ramp"; +} + +std::string Joystick::SineEffect::GetName() const +{ + return "Sine"; +} + +#ifdef SDL_HAPTIC_SQUARE +std::string Joystick::SquareEffect::GetName() const +{ + return "Square"; +} +#endif // defined(SDL_HAPTIC_SQUARE) + +std::string Joystick::TriangleEffect::GetName() const +{ + return "Triangle"; +} + +void Joystick::ConstantEffect::SetState(ControlState state) +{ + if (state) + { + m_effect.effect.type = SDL_HAPTIC_CONSTANT; + m_effect.effect.constant.length = SDL_HAPTIC_INFINITY; + } + else + { + m_effect.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; +} + +void Joystick::RampEffect::SetState(ControlState state) +{ + if (state) + { + m_effect.effect.type = SDL_HAPTIC_RAMP; + m_effect.effect.ramp.length = SDL_HAPTIC_INFINITY; + } + else + { + m_effect.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; +} + +void Joystick::SineEffect::SetState(ControlState state) +{ + if (state) + { + m_effect.effect.type = SDL_HAPTIC_SINE; + m_effect.effect.periodic.length = 250; + } + else + { + m_effect.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; +} + +#ifdef SDL_HAPTIC_SQUARE +void Joystick::SquareEffect::SetState(ControlState state) +{ + if (state) + { + m_effect.effect.type = SDL_HAPTIC_SQUARE; + m_effect.effect.periodic.length = 250; + } + else + { + m_effect.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; +} +#endif // defined(SDL_HAPTIC_SQUARE) + +void Joystick::TriangleEffect::SetState(ControlState state) +{ + if (state) + { + m_effect.effect.type = SDL_HAPTIC_TRIANGLE; + m_effect.effect.periodic.length = 250; + } + else + { + m_effect.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; +} +#endif + +bool 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 +{ + return StripSpaces(GetJoystickName(m_sdl_index)); +} + +std::string Joystick::GetSource() const +{ + return "SDL"; +} + +int Joystick::GetId() const +{ + return m_index; +} + +std::string Joystick::Button::GetName() const +{ + std::ostringstream ss; + ss << "Button " << (int)m_index; + return ss.str(); +} + +std::string Joystick::Axis::GetName() const +{ + std::ostringstream ss; + ss << "Axis " << (int)m_index << (m_range<0 ? '-' : '+'); + return ss.str(); +} + +std::string Joystick::Hat::GetName() const +{ + static char tmpstr[] = "Hat . ."; + // I don't think more than 10 hats are supported + tmpstr[4] = (char)('0' + m_index); + tmpstr[6] = "NESW"[m_direction]; + return tmpstr; +} + +ControlState Joystick::Button::GetState() const +{ + return SDL_JoystickGetButton(m_js, m_index); +} + +ControlState Joystick::Axis::GetState() const +{ + return std::max(0.0f, ControlState(SDL_JoystickGetAxis(m_js, m_index)) / m_range); +} + +ControlState Joystick::Hat::GetState() const +{ + return (SDL_JoystickGetHat(m_js, m_index) & (1 << m_direction)) > 0; +} + +} +} -- cgit v1.2.3 From d2038049f51192fbb55fbde2fc08128bacfb7707 Mon Sep 17 00:00:00 2001 From: lioncash Date: Mon, 10 Feb 2014 13:54:46 -0500 Subject: Replace all include guard ifdefs with "#pragma once" --- Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp index 24e0d0de58..c4cdae71bc 100644 --- a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp +++ b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp @@ -1,3 +1,6 @@ +// Copyright 2014 Dolphin Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. #include "SDL.h" #include -- cgit v1.2.3 From 6c4ee1753aa2b9e620138801b479365b0569317c Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 16 Feb 2014 15:30:18 -0500 Subject: Fix some vertical alignments ie. uses spaces for alignment. --- .../Core/InputCommon/ControllerInterface/SDL/SDL.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp index c4cdae71bc..23d247d704 100644 --- a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp +++ b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp @@ -319,29 +319,29 @@ bool Joystick::UpdateOutput() #ifdef USE_SDL_HAPTIC for (auto &i : m_state_out) { - if (i.changed) // if SetState was called on this output + if (i.changed) // if SetState was called on this output { - if (-1 == i.id) // effect isn't currently uploaded + if (-1 == i.id) // effect isn't currently uploaded { - if (i.effect.type) // if outputstate is >0 this would be true + 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 + if ((i.id = SDL_HapticNewEffect(m_haptic, &i.effect)) > -1) // upload the effect { - SDL_HapticRunEffect(m_haptic, i.id, 1); // run the effect + SDL_HapticRunEffect(m_haptic, i.id, 1); // run the effect } } } - else // effect is already uploaded + else // effect is already uploaded { - if (i.effect.type) // if ouputstate >0 + 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_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.id = -1; // mark it as not uploaded } } -- cgit v1.2.3 From 3fd87a7636ff434118a5d7f7334550be8db55c0b Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 16 Feb 2014 23:51:41 -0500 Subject: Second and final pass of clearing out tabs. --- Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp index 23d247d704..074308305c 100644 --- a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp +++ b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp @@ -31,7 +31,7 @@ void Init( std::vector& devices ) { // this is used to number the joysticks // multiple joysticks with the same name shall get unique ids starting at 0 - std::map name_counts; + std::map name_counts; if (SDL_Init( SDL_INIT_FLAGS ) >= 0) { @@ -335,7 +335,7 @@ bool Joystick::UpdateOutput() { if (i.effect.type) // if ouputstate >0 { - SDL_HapticUpdateEffect(m_haptic, i.id, &i.effect); // update the effect + SDL_HapticUpdateEffect(m_haptic, i.id, &i.effect); // update the effect } else { -- cgit v1.2.3 From 2afe2152712981e21d6bda6f029292ed2b1cf91e Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 17 Feb 2014 05:18:15 -0500 Subject: Convert all includes to relative paths. --- Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp index 074308305c..64c012c1c1 100644 --- a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp +++ b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp @@ -2,12 +2,12 @@ // Licensed under GPLv2 // Refer to the license.txt file included. -#include "SDL.h" -#include - +#include #include #include -#include + +#include "Common/StringUtil.h" +#include "InputCommon/ControllerInterface/SDL/SDL.h" #ifdef _WIN32 #pragma comment(lib, "SDL2.lib") -- cgit v1.2.3 From 31cfc73a09a8685cbab20502b4bc132e98e2feb5 Mon Sep 17 00:00:00 2001 From: Matthew Parlane Date: Tue, 11 Mar 2014 00:30:55 +1300 Subject: Fixes spacing for "for", "while", "switch" and "if" Also moved && and || to ends of lines instead of start. Fixed misc vertical alignments and some { needed newlining. --- Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp index 64c012c1c1..56c526a079 100644 --- a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp +++ b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp @@ -36,7 +36,7 @@ void Init( std::vector& devices ) if (SDL_Init( SDL_INIT_FLAGS ) >= 0) { // joysticks - for(int i = 0; i < SDL_NumJoysticks(); ++i) + for (int i = 0; i < SDL_NumJoysticks(); ++i) { SDL_Joystick* dev = SDL_JoystickOpen(i); if (dev) @@ -67,12 +67,11 @@ Joystick::Joystick(SDL_Joystick* const joystick, const int sdl_index, const unsi std::string lcasename = GetName(); std::transform(lcasename.begin(), lcasename.end(), lcasename.begin(), tolower); - if ((std::string::npos != lcasename.find("xbox 360")) - && (10 == SDL_JoystickNumButtons(joystick)) - && (5 == SDL_JoystickNumAxes(joystick)) - && (1 == SDL_JoystickNumHats(joystick)) - && (0 == SDL_JoystickNumBalls(joystick)) - ) + if ((std::string::npos != lcasename.find("xbox 360")) && + (10 == SDL_JoystickNumButtons(joystick)) && + (5 == SDL_JoystickNumAxes(joystick)) && + (1 == SDL_JoystickNumHats(joystick)) && + (0 == SDL_JoystickNumBalls(joystick))) { // this device won't be used return; -- cgit v1.2.3 From c88b83699ee40147fa73b7ee8548aef1881fb0ca Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Tue, 15 Apr 2014 23:02:17 -0500 Subject: Don't use SDL devices that report invalid ranges. If Buttons, Axes, Hats, or Balls > 255 then reject it. --- Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp index 56c526a079..4b738d4dbf 100644 --- a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp +++ b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp @@ -78,6 +78,17 @@ Joystick::Joystick(SDL_Joystick* const joystick, const int sdl_index, const unsi } #endif + if (SDL_JoystickNumButtons(joystick) > 255 || + SDL_JoystickNumAxes(joystick) > 255 || + SDL_JoystickNumHats(joystick) > 255 || + SDL_JoystickNumBalls(joystick) > 255) + { + // This device is invalid, don't use it + // Some crazy devices(HP webcam 2100) end up as HID devices + // SDL tries parsing these as joysticks + return; + } + // get buttons for (u8 i = 0; i != SDL_JoystickNumButtons(m_joystick); ++i) AddInput(new Button(i, m_joystick)); -- cgit v1.2.3 From 22e1aa5bb4a159d6d66a321f978917614aa36331 Mon Sep 17 00:00:00 2001 From: degasus Date: Tue, 8 Jul 2014 14:29:26 +0200 Subject: mark all local functions as static --- Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp index 4b738d4dbf..c43cd255e8 100644 --- a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp +++ b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp @@ -18,7 +18,7 @@ namespace ciface namespace SDL { -std::string GetJoystickName(int index) +static std::string GetJoystickName(int index) { #if SDL_VERSION_ATLEAST(2, 0, 0) return SDL_JoystickNameForIndex(index); -- cgit v1.2.3 From 5adbc83453d14b23818442f545ceede0e4548196 Mon Sep 17 00:00:00 2001 From: Rachel Bryk Date: Mon, 11 Aug 2014 13:43:26 -0400 Subject: Change ControlState typedef to double, and change all related floats/doubles to use it. Fixes an off by 1 issue related to double->float->double conversion, and eliminates numerous warnings. --- Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp index c43cd255e8..b745f7b2d4 100644 --- a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp +++ b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp @@ -407,7 +407,7 @@ ControlState Joystick::Button::GetState() const ControlState Joystick::Axis::GetState() const { - return std::max(0.0f, ControlState(SDL_JoystickGetAxis(m_js, m_index)) / m_range); + return std::max(0.0, ControlState(SDL_JoystickGetAxis(m_js, m_index)) / m_range); } ControlState Joystick::Hat::GetState() const -- cgit v1.2.3 From f2787f620eebbbfb746f59cfbd0318210297061b Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Thu, 13 Nov 2014 00:55:14 -0800 Subject: ControllerInterface: Make UpdateInput / UpdateOutput return void The return values here have never been checked, so it doesn't make sense to return a value to begin with. --- Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp index b745f7b2d4..5428778163 100644 --- a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp +++ b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp @@ -316,15 +316,13 @@ void Joystick::TriangleEffect::SetState(ControlState state) } #endif -bool Joystick::UpdateInput() +void Joystick::UpdateInput() { // each joystick is doin this, o well SDL_JoystickUpdate(); - - return true; } -bool Joystick::UpdateOutput() +void Joystick::UpdateOutput() { #ifdef USE_SDL_HAPTIC for (auto &i : m_state_out) @@ -359,7 +357,6 @@ bool Joystick::UpdateOutput() } } #endif - return true; } std::string Joystick::GetName() const -- cgit v1.2.3 From 1b3d0173f5492fa19e3b440d43623ca2145c2a82 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Thu, 13 Nov 2014 00:49:18 -0800 Subject: SDL: Apply updates immediately rather than going through UpdateOutput We're going to remove UpdateOutput as it's redundant, and horribly complicates the code. --- .../InputCommon/ControllerInterface/SDL/SDL.cpp | 171 ++++++++------------- 1 file changed, 60 insertions(+), 111 deletions(-) (limited to 'Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp index 5428778163..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,22 +286,19 @@ 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 @@ -322,43 +308,6 @@ void Joystick::UpdateInput() SDL_JoystickUpdate(); } -void 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 -} - std::string Joystick::GetName() const { return StripSpaces(GetJoystickName(m_sdl_index)); -- cgit v1.2.3 From fba3abe4cf3342ac609d31eec38b1cd1e1a49b1b Mon Sep 17 00:00:00 2001 From: comex Date: Sat, 20 Dec 2014 00:21:40 -0500 Subject: Manually revert d34418100be19fdbdf112febde3303edd48c9247 --- .../InputCommon/ControllerInterface/SDL/SDL.cpp | 91 ---------------------- 1 file changed, 91 deletions(-) (limited to 'Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp index a46a08100d..4402b286c3 100644 --- a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp +++ b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp @@ -126,21 +126,6 @@ Joystick::Joystick(SDL_Joystick* const joystick, const int sdl_index, const unsi // ramp effect if (supported_effects & SDL_HAPTIC_RAMP) AddOutput(new RampEffect(m_haptic)); - - // sine effect - if (supported_effects & SDL_HAPTIC_SINE) - AddOutput(new SineEffect(m_haptic)); - -#ifdef SDL_HAPTIC_SQUARE - // square effect - if (supported_effects & SDL_HAPTIC_SQUARE) - AddOutput(new SquareEffect(m_haptic)); - -#endif // defined(SDL_HAPTIC_SQUARE) - - // triangle effect - if (supported_effects & SDL_HAPTIC_TRIANGLE) - AddOutput(new TriangleEffect(m_haptic)); } #endif @@ -193,23 +178,6 @@ std::string Joystick::RampEffect::GetName() const return "Ramp"; } -std::string Joystick::SineEffect::GetName() const -{ - return "Sine"; -} - -#ifdef SDL_HAPTIC_SQUARE -std::string Joystick::SquareEffect::GetName() const -{ - return "Square"; -} -#endif // defined(SDL_HAPTIC_SQUARE) - -std::string Joystick::TriangleEffect::GetName() const -{ - return "Triangle"; -} - void Joystick::ConstantEffect::SetState(ControlState state) { if (state) @@ -241,65 +209,6 @@ void Joystick::RampEffect::SetState(ControlState state) m_effect.ramp.start = (Sint16)(state * 0x7FFF); Update(); } - -void Joystick::SineEffect::SetState(ControlState state) -{ - if (state) - { - m_effect.type = SDL_HAPTIC_SINE; - m_effect.periodic.length = 250; - } - else - { - m_effect.type = 0; - } - - 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 -void Joystick::SquareEffect::SetState(ControlState state) -{ - if (state) - { - m_effect.type = SDL_HAPTIC_SQUARE; - m_effect.periodic.length = 250; - } - else - { - m_effect.type = 0; - } - - 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) - -void Joystick::TriangleEffect::SetState(ControlState state) -{ - if (state) - { - m_effect.type = SDL_HAPTIC_TRIANGLE; - m_effect.periodic.length = 250; - } - else - { - m_effect.type = 0; - } - - 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 void Joystick::UpdateInput() -- cgit v1.2.3 From 306c8d14db47a7b3c8d0bd2a3877772bcc8ce21d Mon Sep 17 00:00:00 2001 From: Adam Moss Date: Tue, 6 Jan 2015 19:17:43 +0000 Subject: SDL Input: Support more types of force feedback for controllers through SDL. --- .../InputCommon/ControllerInterface/SDL/SDL.cpp | 92 ++++++++++++++++++++++ 1 file changed, 92 insertions(+) (limited to 'Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp index 4402b286c3..b75670394c 100644 --- a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp +++ b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp @@ -126,6 +126,18 @@ Joystick::Joystick(SDL_Joystick* const joystick, const int sdl_index, const unsi // ramp effect if (supported_effects & SDL_HAPTIC_RAMP) AddOutput(new RampEffect(m_haptic)); + + // sine effect + if (supported_effects & SDL_HAPTIC_SINE) + AddOutput(new SineEffect(m_haptic)); + + // triangle effect + if (supported_effects & SDL_HAPTIC_TRIANGLE) + AddOutput(new TriangleEffect(m_haptic)); + + // left-right effect + if (supported_effects & SDL_HAPTIC_LEFTRIGHT) + AddOutput(new LeftRightEffect(m_haptic)); } #endif @@ -178,8 +190,24 @@ std::string Joystick::RampEffect::GetName() const return "Ramp"; } +std::string Joystick::SineEffect::GetName() const +{ + return "Sine"; +} + +std::string Joystick::TriangleEffect::GetName() const +{ + return "Triangle"; +} + +std::string Joystick::LeftRightEffect::GetName() const +{ + return "LeftRight"; +} + void Joystick::ConstantEffect::SetState(ControlState state) { + memset(&m_effect, 0, sizeof(m_effect)); if (state) { m_effect.type = SDL_HAPTIC_CONSTANT; @@ -196,6 +224,7 @@ void Joystick::ConstantEffect::SetState(ControlState state) void Joystick::RampEffect::SetState(ControlState state) { + memset(&m_effect, 0, sizeof(m_effect)); if (state) { m_effect.type = SDL_HAPTIC_RAMP; @@ -209,6 +238,69 @@ void Joystick::RampEffect::SetState(ControlState state) m_effect.ramp.start = (Sint16)(state * 0x7FFF); Update(); } + +void Joystick::SineEffect::SetState(ControlState state) +{ + memset(&m_effect, 0, sizeof(m_effect)); + if (state) + { + m_effect.type = SDL_HAPTIC_SINE; + m_effect.periodic.period = 1000; + m_effect.periodic.magnitude = (Sint16)(state * 0x7FFF); + m_effect.periodic.offset = 0; + m_effect.periodic.phase = 18000; + m_effect.periodic.length = SDL_HAPTIC_INFINITY; + m_effect.periodic.delay = 0; + m_effect.periodic.attack_length = 0; + } + else + { + m_effect.type = 0; + } + + Update(); +} + +void Joystick::TriangleEffect::SetState(ControlState state) +{ + memset(&m_effect, 0, sizeof(m_effect)); + if (state) + { + m_effect.type = SDL_HAPTIC_TRIANGLE; + m_effect.periodic.period = 1000; + m_effect.periodic.magnitude = (Sint16)(state * 0x7FFF); + m_effect.periodic.offset = 0; + m_effect.periodic.phase = 18000; + m_effect.periodic.length = SDL_HAPTIC_INFINITY; + m_effect.periodic.delay = 0; + m_effect.periodic.attack_length = 0; + } + else + { + m_effect.type = 0; + } + + Update(); +} + +void Joystick::LeftRightEffect::SetState(ControlState state) +{ + memset(&m_effect, 0, sizeof(m_effect)); + if (state) + { + m_effect.type = SDL_HAPTIC_LEFTRIGHT; + m_effect.leftright.length = SDL_HAPTIC_INFINITY; + // 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.small_magnitude = (Uint16)(state * 0xFFFF); + } + else + { + m_effect.type = 0; + } + + Update(); +} #endif void Joystick::UpdateInput() -- cgit v1.2.3 From 17ad68ff86c7508f4e8a82ae65f31bc2d59cee79 Mon Sep 17 00:00:00 2001 From: Karol Herbst Date: Thu, 8 Jan 2015 13:37:06 +0100 Subject: SDL: more global memset --- .../Core/InputCommon/ControllerInterface/SDL/SDL.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp index b75670394c..8ed142740e 100644 --- a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp +++ b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp @@ -205,9 +205,14 @@ std::string Joystick::LeftRightEffect::GetName() const return "LeftRight"; } -void Joystick::ConstantEffect::SetState(ControlState state) +void Joystick::HapticEffect::SetState(ControlState state) { memset(&m_effect, 0, sizeof(m_effect)); + _SetState(state); +} + +void Joystick::ConstantEffect::_SetState(ControlState state) +{ if (state) { m_effect.type = SDL_HAPTIC_CONSTANT; @@ -222,9 +227,8 @@ void Joystick::ConstantEffect::SetState(ControlState state) Update(); } -void Joystick::RampEffect::SetState(ControlState state) +void Joystick::RampEffect::_SetState(ControlState state) { - memset(&m_effect, 0, sizeof(m_effect)); if (state) { m_effect.type = SDL_HAPTIC_RAMP; @@ -239,9 +243,8 @@ void Joystick::RampEffect::SetState(ControlState state) Update(); } -void Joystick::SineEffect::SetState(ControlState state) +void Joystick::SineEffect::_SetState(ControlState state) { - memset(&m_effect, 0, sizeof(m_effect)); if (state) { m_effect.type = SDL_HAPTIC_SINE; @@ -261,9 +264,8 @@ void Joystick::SineEffect::SetState(ControlState state) Update(); } -void Joystick::TriangleEffect::SetState(ControlState state) +void Joystick::TriangleEffect::_SetState(ControlState state) { - memset(&m_effect, 0, sizeof(m_effect)); if (state) { m_effect.type = SDL_HAPTIC_TRIANGLE; @@ -283,9 +285,8 @@ void Joystick::TriangleEffect::SetState(ControlState state) Update(); } -void Joystick::LeftRightEffect::SetState(ControlState state) +void Joystick::LeftRightEffect::_SetState(ControlState state) { - memset(&m_effect, 0, sizeof(m_effect)); if (state) { m_effect.type = SDL_HAPTIC_LEFTRIGHT; -- cgit v1.2.3 From f47cce2210883033a8bdbdccc2ae34cfe8ca1bc5 Mon Sep 17 00:00:00 2001 From: "Adam D. Moss" Date: Thu, 8 Jan 2015 15:17:29 +0000 Subject: SDL: Refactor the SDL haptic effects a little. --- .../InputCommon/ControllerInterface/SDL/SDL.cpp | 27 ++++++++-------------- 1 file changed, 9 insertions(+), 18 deletions(-) (limited to 'Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp index 8ed142740e..ae1b8be06f 100644 --- a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp +++ b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp @@ -208,42 +208,39 @@ std::string Joystick::LeftRightEffect::GetName() const void Joystick::HapticEffect::SetState(ControlState state) { memset(&m_effect, 0, sizeof(m_effect)); - _SetState(state); + SetSDLHapticEffect(state); + Update(); } -void Joystick::ConstantEffect::_SetState(ControlState state) +void Joystick::ConstantEffect::SetSDLHapticEffect(ControlState state) { if (state) { m_effect.type = SDL_HAPTIC_CONSTANT; m_effect.constant.length = SDL_HAPTIC_INFINITY; + m_effect.constant.level = (Sint16)(state * 0x7FFF); } else { m_effect.type = 0; } - - m_effect.constant.level = (Sint16)(state * 0x7FFF); - Update(); } -void Joystick::RampEffect::_SetState(ControlState state) +void Joystick::RampEffect::SetSDLHapticEffect(ControlState state) { if (state) { m_effect.type = SDL_HAPTIC_RAMP; m_effect.ramp.length = SDL_HAPTIC_INFINITY; + m_effect.ramp.start = (Sint16)(state * 0x7FFF); } else { m_effect.type = 0; } - - m_effect.ramp.start = (Sint16)(state * 0x7FFF); - Update(); } -void Joystick::SineEffect::_SetState(ControlState state) +void Joystick::SineEffect::SetSDLHapticEffect(ControlState state) { if (state) { @@ -260,11 +257,9 @@ void Joystick::SineEffect::_SetState(ControlState state) { m_effect.type = 0; } - - Update(); } -void Joystick::TriangleEffect::_SetState(ControlState state) +void Joystick::TriangleEffect::SetSDLHapticEffect(ControlState state) { if (state) { @@ -281,11 +276,9 @@ void Joystick::TriangleEffect::_SetState(ControlState state) { m_effect.type = 0; } - - Update(); } -void Joystick::LeftRightEffect::_SetState(ControlState state) +void Joystick::LeftRightEffect::SetSDLHapticEffect(ControlState state) { if (state) { @@ -299,8 +292,6 @@ void Joystick::LeftRightEffect::_SetState(ControlState state) { m_effect.type = 0; } - - Update(); } #endif -- cgit v1.2.3 From 63660cb17c5050c0298ff9c353ad2bfd9a5de190 Mon Sep 17 00:00:00 2001 From: "Adam D. Moss" Date: Sun, 11 Jan 2015 11:42:30 +0000 Subject: SDL Input: More minor refactoring of SDL haptic effects --- .../InputCommon/ControllerInterface/SDL/SDL.cpp | 95 ++++++++-------------- 1 file changed, 34 insertions(+), 61 deletions(-) (limited to 'Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp index ae1b8be06f..ddd2f26e6e 100644 --- a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp +++ b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp @@ -208,90 +208,63 @@ std::string Joystick::LeftRightEffect::GetName() const void Joystick::HapticEffect::SetState(ControlState state) { memset(&m_effect, 0, sizeof(m_effect)); - SetSDLHapticEffect(state); - Update(); -} - -void Joystick::ConstantEffect::SetSDLHapticEffect(ControlState state) -{ if (state) { - m_effect.type = SDL_HAPTIC_CONSTANT; - m_effect.constant.length = SDL_HAPTIC_INFINITY; - m_effect.constant.level = (Sint16)(state * 0x7FFF); + SetSDLHapticEffect(state); } else { + // this module uses type==0 to indicate 'off' m_effect.type = 0; } + Update(); +} + +void Joystick::ConstantEffect::SetSDLHapticEffect(ControlState state) +{ + m_effect.type = SDL_HAPTIC_CONSTANT; + m_effect.constant.length = SDL_HAPTIC_INFINITY; + m_effect.constant.level = (Sint16)(state * 0x7FFF); } void Joystick::RampEffect::SetSDLHapticEffect(ControlState state) { - if (state) - { - m_effect.type = SDL_HAPTIC_RAMP; - m_effect.ramp.length = SDL_HAPTIC_INFINITY; - m_effect.ramp.start = (Sint16)(state * 0x7FFF); - } - else - { - m_effect.type = 0; - } + m_effect.type = SDL_HAPTIC_RAMP; + m_effect.ramp.length = SDL_HAPTIC_INFINITY; + m_effect.ramp.start = (Sint16)(state * 0x7FFF); } void Joystick::SineEffect::SetSDLHapticEffect(ControlState state) { - if (state) - { - m_effect.type = SDL_HAPTIC_SINE; - m_effect.periodic.period = 1000; - m_effect.periodic.magnitude = (Sint16)(state * 0x7FFF); - m_effect.periodic.offset = 0; - m_effect.periodic.phase = 18000; - m_effect.periodic.length = SDL_HAPTIC_INFINITY; - m_effect.periodic.delay = 0; - m_effect.periodic.attack_length = 0; - } - else - { - m_effect.type = 0; - } + m_effect.type = SDL_HAPTIC_SINE; + m_effect.periodic.period = 1000; + m_effect.periodic.magnitude = (Sint16)(state * 0x7FFF); + m_effect.periodic.offset = 0; + m_effect.periodic.phase = 18000; + m_effect.periodic.length = SDL_HAPTIC_INFINITY; + m_effect.periodic.delay = 0; + m_effect.periodic.attack_length = 0; } void Joystick::TriangleEffect::SetSDLHapticEffect(ControlState state) { - if (state) - { - m_effect.type = SDL_HAPTIC_TRIANGLE; - m_effect.periodic.period = 1000; - m_effect.periodic.magnitude = (Sint16)(state * 0x7FFF); - m_effect.periodic.offset = 0; - m_effect.periodic.phase = 18000; - m_effect.periodic.length = SDL_HAPTIC_INFINITY; - m_effect.periodic.delay = 0; - m_effect.periodic.attack_length = 0; - } - else - { - m_effect.type = 0; - } + m_effect.type = SDL_HAPTIC_TRIANGLE; + m_effect.periodic.period = 1000; + m_effect.periodic.magnitude = (Sint16)(state * 0x7FFF); + m_effect.periodic.offset = 0; + m_effect.periodic.phase = 18000; + m_effect.periodic.length = SDL_HAPTIC_INFINITY; + m_effect.periodic.delay = 0; + m_effect.periodic.attack_length = 0; } void Joystick::LeftRightEffect::SetSDLHapticEffect(ControlState state) { - if (state) - { - m_effect.type = SDL_HAPTIC_LEFTRIGHT; - m_effect.leftright.length = SDL_HAPTIC_INFINITY; - // 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.small_magnitude = (Uint16)(state * 0xFFFF); - } - else - { - m_effect.type = 0; - } + m_effect.type = SDL_HAPTIC_LEFTRIGHT; + m_effect.leftright.length = SDL_HAPTIC_INFINITY; + // 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.small_magnitude = (Uint16)(state * 0xFFFF); } #endif -- cgit v1.2.3 From 076c2b8ec70531ce02e5a7b3da3173ce5e2998fe Mon Sep 17 00:00:00 2001 From: "Adam D. Moss" Date: Sun, 11 Jan 2015 11:57:48 +0000 Subject: SDL input: unhardcode a few values. & change effect length to half a second instead of infinite, in futile attempt to avoid runaway rumbles. --- .../InputCommon/ControllerInterface/SDL/SDL.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp index ddd2f26e6e..f37a674b03 100644 --- a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp +++ b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp @@ -18,6 +18,14 @@ namespace ciface namespace SDL { +namespace +{ +// 10ms = 100Hz which homebrew docs very roughly imply is within WiiMote normal +// range, used for periodic haptic effects though often ignored by devices +const u16 RUMBLE_PERIOD = 10; +const u16 RUMBLE_LENGTH_MAX = 500; // ms: enough to span multiple frames at low FPS, but still finite +} + static std::string GetJoystickName(int index) { #if SDL_VERSION_ATLEAST(2, 0, 0) @@ -223,25 +231,25 @@ void Joystick::HapticEffect::SetState(ControlState state) void Joystick::ConstantEffect::SetSDLHapticEffect(ControlState state) { m_effect.type = SDL_HAPTIC_CONSTANT; - m_effect.constant.length = SDL_HAPTIC_INFINITY; + m_effect.constant.length = RUMBLE_LENGTH_MAX; m_effect.constant.level = (Sint16)(state * 0x7FFF); } void Joystick::RampEffect::SetSDLHapticEffect(ControlState state) { m_effect.type = SDL_HAPTIC_RAMP; - m_effect.ramp.length = SDL_HAPTIC_INFINITY; + m_effect.ramp.length = RUMBLE_LENGTH_MAX; m_effect.ramp.start = (Sint16)(state * 0x7FFF); } void Joystick::SineEffect::SetSDLHapticEffect(ControlState state) { m_effect.type = SDL_HAPTIC_SINE; - m_effect.periodic.period = 1000; + m_effect.periodic.period = RUMBLE_PERIOD; m_effect.periodic.magnitude = (Sint16)(state * 0x7FFF); m_effect.periodic.offset = 0; m_effect.periodic.phase = 18000; - m_effect.periodic.length = SDL_HAPTIC_INFINITY; + m_effect.periodic.length = RUMBLE_LENGTH_MAX; m_effect.periodic.delay = 0; m_effect.periodic.attack_length = 0; } @@ -249,11 +257,11 @@ void Joystick::SineEffect::SetSDLHapticEffect(ControlState state) void Joystick::TriangleEffect::SetSDLHapticEffect(ControlState state) { m_effect.type = SDL_HAPTIC_TRIANGLE; - m_effect.periodic.period = 1000; + m_effect.periodic.period = RUMBLE_PERIOD; m_effect.periodic.magnitude = (Sint16)(state * 0x7FFF); m_effect.periodic.offset = 0; m_effect.periodic.phase = 18000; - m_effect.periodic.length = SDL_HAPTIC_INFINITY; + m_effect.periodic.length = RUMBLE_LENGTH_MAX; m_effect.periodic.delay = 0; m_effect.periodic.attack_length = 0; } @@ -261,7 +269,7 @@ void Joystick::TriangleEffect::SetSDLHapticEffect(ControlState state) void Joystick::LeftRightEffect::SetSDLHapticEffect(ControlState state) { m_effect.type = SDL_HAPTIC_LEFTRIGHT; - m_effect.leftright.length = SDL_HAPTIC_INFINITY; + m_effect.leftright.length = RUMBLE_LENGTH_MAX; // 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.small_magnitude = (Uint16)(state * 0xFFFF); -- cgit v1.2.3 From 3300c176e46fda826e528d1ac10ff514ef3d9ec2 Mon Sep 17 00:00:00 2001 From: "Adam D. Moss" Date: Tue, 13 Jan 2015 16:00:35 +0000 Subject: SDL haptic: minor style change based on review feedback --- Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp index f37a674b03..a1fd428a0d 100644 --- a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp +++ b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp @@ -18,13 +18,10 @@ namespace ciface namespace SDL { -namespace -{ // 10ms = 100Hz which homebrew docs very roughly imply is within WiiMote normal // range, used for periodic haptic effects though often ignored by devices -const u16 RUMBLE_PERIOD = 10; -const u16 RUMBLE_LENGTH_MAX = 500; // ms: enough to span multiple frames at low FPS, but still finite -} +static const u16 RUMBLE_PERIOD = 10; +static const u16 RUMBLE_LENGTH_MAX = 500; // ms: enough to span multiple frames at low FPS, but still finite static std::string GetJoystickName(int index) { -- cgit v1.2.3 From 817abdd579b2918d55141ac8efc9f8c4ef720634 Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Mon, 19 Jan 2015 16:05:21 -0600 Subject: Remove an assumption in SDL. We can compile with haptic support, and then not initialize due to haptics not being available. So if we are compiling with haptics, test initializing with haptics and if that fails attempt to initialize without haptics before bailing out. --- .../InputCommon/ControllerInterface/SDL/SDL.cpp | 36 ++++++++++++++-------- 1 file changed, 23 insertions(+), 13 deletions(-) (limited to 'Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp index a1fd428a0d..2525e273b8 100644 --- a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp +++ b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp @@ -38,21 +38,31 @@ void Init( std::vector& devices ) // multiple joysticks with the same name shall get unique ids starting at 0 std::map name_counts; - if (SDL_Init( SDL_INIT_FLAGS ) >= 0) +#ifdef USE_SDL_HAPTIC + if (SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC) >= 0) + { + // Correctly initialized + } + else +#endif + if (SDL_Init(SDL_INIT_JOYSTICK) < 0) + { + // Failed to initialize + return; + } + + // joysticks + for (int i = 0; i < SDL_NumJoysticks(); ++i) { - // joysticks - for (int i = 0; i < SDL_NumJoysticks(); ++i) + SDL_Joystick* dev = SDL_JoystickOpen(i); + if (dev) { - SDL_Joystick* dev = SDL_JoystickOpen(i); - if (dev) - { - Joystick* js = new Joystick(dev, i, name_counts[GetJoystickName(i)]++); - // only add if it has some inputs/outputs - if (js->Inputs().size() || js->Outputs().size()) - devices.push_back( js ); - else - delete js; - } + Joystick* js = new Joystick(dev, i, name_counts[GetJoystickName(i)]++); + // only add if it has some inputs/outputs + if (js->Inputs().size() || js->Outputs().size()) + devices.push_back( js ); + else + delete js; } } } -- cgit v1.2.3 From cefcb0ace9d363b3679b4e93bcc9ec05f1e5f4f8 Mon Sep 17 00:00:00 2001 From: Tillmann Karras Date: Mon, 18 May 2015 01:08:10 +0200 Subject: Update license headers to GPLv2+ --- Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp index 2525e273b8..c3b3c4b9c5 100644 --- a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp +++ b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp @@ -1,5 +1,5 @@ // Copyright 2014 Dolphin Emulator Project -// Licensed under GPLv2 +// Licensed under GPLv2+ // Refer to the license.txt file included. #include -- cgit v1.2.3 From 30ebb2459eb97ba544547183854775df8460b475 Mon Sep 17 00:00:00 2001 From: Tillmann Karras Date: Sun, 24 May 2015 06:55:12 +0200 Subject: Set copyright year to when a file was created --- Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp index c3b3c4b9c5..6cdfa470cd 100644 --- a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp +++ b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp @@ -1,4 +1,4 @@ -// Copyright 2014 Dolphin Emulator Project +// Copyright 2010 Dolphin Emulator Project // Licensed under GPLv2+ // Refer to the license.txt file included. -- cgit v1.2.3 From 9ec5a4544f207a31678e6c5c7636873e9d9e88a1 Mon Sep 17 00:00:00 2001 From: Tillmann Karras Date: Fri, 5 Jun 2015 19:34:06 +0200 Subject: SDL: handle SDL_QUIT event Using SDL_INIT_JOYSTICK implies SDL_INIT_EVENTS which installs a signal handler for SIGINT and SIGTERM. There will be a way to prevent this in 2.0.4 but for now we'll need to handle SDL_QUIT. --- .../Core/InputCommon/ControllerInterface/SDL/SDL.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp index 6cdfa470cd..6e60cf0f7a 100644 --- a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp +++ b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp @@ -7,6 +7,7 @@ #include #include "Common/StringUtil.h" +#include "Core/Host.h" #include "InputCommon/ControllerInterface/SDL/SDL.h" #ifdef _WIN32 @@ -67,6 +68,19 @@ void Init( std::vector& devices ) } } +void UpdateInput() +{ + // Using SDL_INIT_JOYSTICK implies SDL_INIT_EVENT which installs a signal handler for SIGINT and SIGTERM. + // In the future, we will be able to prevent this from happening: + // SDL_SetHint(SDL_HINT_NO_SIGNAL_HANDLERS, "1"); + // but this was added after SDL 2.0.3 and is scheduled to be included in 2.0.4. + // Until then, handle SDL_QUIT events here and tell Dolphin to exit. + if (SDL_QuitRequested()) + Host_Message(WM_USER_QUIT); + + SDL_JoystickUpdate(); +} + Joystick::Joystick(SDL_Joystick* const joystick, const int sdl_index, const unsigned int index) : m_joystick(joystick) , m_sdl_index(sdl_index) @@ -283,12 +297,6 @@ void Joystick::LeftRightEffect::SetSDLHapticEffect(ControlState state) } #endif -void Joystick::UpdateInput() -{ - // each joystick is doin this, o well - SDL_JoystickUpdate(); -} - std::string Joystick::GetName() const { return StripSpaces(GetJoystickName(m_sdl_index)); -- cgit v1.2.3 From 9e1aab663f2afdd61bda773764cc3c8f652659aa Mon Sep 17 00:00:00 2001 From: Matthew Parlane Date: Mon, 8 Jun 2015 13:43:39 +1200 Subject: Revert "SDL: handle SDL_QUIT event" --- .../Core/InputCommon/ControllerInterface/SDL/SDL.cpp | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) (limited to 'Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp index 6e60cf0f7a..6cdfa470cd 100644 --- a/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp +++ b/Source/Core/InputCommon/ControllerInterface/SDL/SDL.cpp @@ -7,7 +7,6 @@ #include #include "Common/StringUtil.h" -#include "Core/Host.h" #include "InputCommon/ControllerInterface/SDL/SDL.h" #ifdef _WIN32 @@ -68,19 +67,6 @@ void Init( std::vector& devices ) } } -void UpdateInput() -{ - // Using SDL_INIT_JOYSTICK implies SDL_INIT_EVENT which installs a signal handler for SIGINT and SIGTERM. - // In the future, we will be able to prevent this from happening: - // SDL_SetHint(SDL_HINT_NO_SIGNAL_HANDLERS, "1"); - // but this was added after SDL 2.0.3 and is scheduled to be included in 2.0.4. - // Until then, handle SDL_QUIT events here and tell Dolphin to exit. - if (SDL_QuitRequested()) - Host_Message(WM_USER_QUIT); - - SDL_JoystickUpdate(); -} - Joystick::Joystick(SDL_Joystick* const joystick, const int sdl_index, const unsigned int index) : m_joystick(joystick) , m_sdl_index(sdl_index) @@ -297,6 +283,12 @@ void Joystick::LeftRightEffect::SetSDLHapticEffect(ControlState state) } #endif +void Joystick::UpdateInput() +{ + // each joystick is doin this, o well + SDL_JoystickUpdate(); +} + std::string Joystick::GetName() const { return StripSpaces(GetJoystickName(m_sdl_index)); -- cgit v1.2.3