summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon/Src/ControllerInterface/SDL/SDL.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/Core/InputCommon/Src/ControllerInterface/SDL/SDL.cpp')
-rw-r--r--Source/Core/InputCommon/Src/ControllerInterface/SDL/SDL.cpp90
1 files changed, 37 insertions, 53 deletions
diff --git a/Source/Core/InputCommon/Src/ControllerInterface/SDL/SDL.cpp b/Source/Core/InputCommon/Src/ControllerInterface/SDL/SDL.cpp
index 603f63d946..8c49a5766f 100644
--- a/Source/Core/InputCommon/Src/ControllerInterface/SDL/SDL.cpp
+++ b/Source/Core/InputCommon/Src/ControllerInterface/SDL/SDL.cpp
@@ -30,11 +30,11 @@ void Init( std::vector<ControllerInterface::Device*>& devices )
for(int i = 0; i < SDL_NumJoysticks(); ++i)
{
SDL_Joystick* dev = SDL_JoystickOpen(i);
- if ( dev )
+ if (dev)
{
Joystick* js = new Joystick(dev, i, name_counts[SDL_JoystickName(i)]++);
// only add if it has some inputs/outputs
- if ( js->Inputs().size() || js->Outputs().size() )
+ if (js->Inputs().size() || js->Outputs().size())
devices.push_back( js );
else
delete js;
@@ -71,25 +71,23 @@ Joystick::Joystick(SDL_Joystick* const joystick, const int sdl_index, const unsi
#endif
// get buttons
- for ( int i = 0; i < SDL_JoystickNumButtons( m_joystick ); ++i )
- {
- AddInput( new Button( i ) );
- }
+ for (u8 i = 0; i != SDL_JoystickNumButtons(m_joystick); ++i)
+ AddInput(new Button(i, m_joystick));
// get hats
- for ( int i = 0; i < SDL_JoystickNumHats( m_joystick ); ++i )
+ for (u8 i = 0; i != SDL_JoystickNumHats(m_joystick); ++i)
{
// each hat gets 4 input instances associated with it, (up down left right)
- for ( unsigned int d = 0; d < 4; ++d )
- AddInput( new Hat( i, d ) );
+ for (u8 d = 0; d != 4; ++d)
+ AddInput(new Hat(i, m_joystick, d));
}
// get axes
- for ( int i = 0; i < SDL_JoystickNumAxes( m_joystick ); ++i )
+ for (u8 i = 0; i != SDL_JoystickNumAxes(m_joystick); ++i)
{
// each axis gets a negative and a positive input instance associated with it
- AddInput( new Axis( i, -32768 ) );
- AddInput( new Axis( i, 32767 ) );
+ AddInput(new Axis(i, m_joystick, -32768));
+ AddInput(new Axis(i, m_joystick, 32767));
}
#ifdef USE_SDL_HAPTIC
@@ -123,22 +121,22 @@ Joystick::Joystick(SDL_Joystick* const joystick, const int sdl_index, const unsi
Joystick::~Joystick()
{
#ifdef USE_SDL_HAPTIC
- if ( m_haptic )
+ if (m_haptic)
{
// stop/destroy all effects
- SDL_HapticStopAll( m_haptic );
+ SDL_HapticStopAll(m_haptic);
std::vector<EffectIDState>::iterator i = m_state_out.begin(),
e = m_state_out.end();
- for ( ; i!=e; ++i )
- if ( i->id != -1 )
- SDL_HapticDestroyEffect( m_haptic, i->id );
+ for ( ; i!=e; ++i)
+ if (i->id != -1)
+ SDL_HapticDestroyEffect(m_haptic, i->id);
// close haptic first
- SDL_HapticClose( m_haptic );
+ SDL_HapticClose(m_haptic);
}
#endif
// close joystick
- SDL_JoystickClose( m_joystick );
+ SDL_JoystickClose(m_joystick);
}
#ifdef USE_SDL_HAPTIC
@@ -154,7 +152,7 @@ std::string Joystick::RampEffect::GetName() const
void Joystick::ConstantEffect::SetState( const ControlState state, Joystick::EffectIDState* const effect )
{
- if ( state )
+ if (state)
{
effect->effect.type = SDL_HAPTIC_CONSTANT;
effect->effect.constant.length = SDL_HAPTIC_INFINITY;
@@ -164,13 +162,13 @@ void Joystick::ConstantEffect::SetState( const ControlState state, Joystick::Eff
Sint16 old = effect->effect.constant.level;
effect->effect.constant.level = state * 0x7FFF;
- if ( old != effect->effect.constant.level )
+ if (old != effect->effect.constant.level)
effect->changed = true;
}
void Joystick::RampEffect::SetState( const ControlState state, Joystick::EffectIDState* const effect )
{
- if ( state )
+ if (state)
{
effect->effect.type = SDL_HAPTIC_RAMP;
effect->effect.ramp.length = SDL_HAPTIC_INFINITY;
@@ -180,23 +178,11 @@ void Joystick::RampEffect::SetState( const ControlState state, Joystick::EffectI
Sint16 old = effect->effect.ramp.start;
effect->effect.ramp.start = state * 0x7FFF;
- if ( old != effect->effect.ramp.start )
+ if (old != effect->effect.ramp.start)
effect->changed = true;
}
#endif
-ControlState Joystick::GetInputState(const ControllerInterface::Device::Input* input) const
-{
- return ((Input*)input)->GetState( m_joystick );
-}
-
-void Joystick::SetOutputState(const ControllerInterface::Device::Output* output, const ControlState state)
-{
-#ifdef USE_SDL_HAPTIC
- ((Output*)output)->SetState( state, &m_state_out[ ((Output*)output)->m_index ] );
-#endif
-}
-
bool Joystick::UpdateInput()
{
// each joystick is doin this, o well
@@ -210,23 +196,23 @@ bool Joystick::UpdateOutput()
#ifdef USE_SDL_HAPTIC
std::vector<EffectIDState>::iterator i = m_state_out.begin(),
e = m_state_out.end();
- for ( ; i!=e; ++i )
- if ( i->changed ) // if SetState was called on this output
+ for ( ; i!=e; ++i)
+ 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->id = SDL_HapticNewEffect( m_haptic, &i->effect )) > -1 ) // upload the effect
- SDL_HapticRunEffect( m_haptic, i->id, 1 ); // run the effect
+ 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
+ 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 );
+ 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
}
}
@@ -275,23 +261,21 @@ std::string Joystick::Hat::GetName() const
return tmpstr;
}
-ControlState Joystick::Button::GetState( SDL_Joystick* const js ) const
+ControlState Joystick::Button::GetState() const
{
- return SDL_JoystickGetButton( js, m_index );
+ return SDL_JoystickGetButton(m_js, m_index);
}
-ControlState Joystick::Axis::GetState( SDL_Joystick* const js ) const
+ControlState Joystick::Axis::GetState() const
{
- return std::max( 0.0f, ControlState(SDL_JoystickGetAxis( js, m_index )) / m_range );
+ return std::max(0.0f, ControlState(SDL_JoystickGetAxis(m_js, m_index)) / m_range);
}
-ControlState Joystick::Hat::GetState( SDL_Joystick* const js ) const
+ControlState Joystick::Hat::GetState() const
{
- return (SDL_JoystickGetHat( js, m_index ) & ( 1 << m_direction )) > 0;
+ return (SDL_JoystickGetHat(m_js, m_index) & (1 << m_direction)) > 0;
}
-
-
}
}