Fix SDL 1.3 support.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@7434 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
parent
021193b22f
commit
0ed542206a
|
@ -93,7 +93,7 @@ Joystick::Joystick(SDL_Joystick* const joystick, const int sdl_index, const unsi
|
|||
#ifdef USE_SDL_HAPTIC
|
||||
// try to get supported ff effects
|
||||
m_haptic = SDL_HapticOpenFromJoystick( m_joystick );
|
||||
if ( m_haptic )
|
||||
if (m_haptic)
|
||||
{
|
||||
//SDL_HapticSetGain( m_haptic, 1000 );
|
||||
//SDL_HapticSetAutocenter( m_haptic, 0 );
|
||||
|
@ -101,17 +101,17 @@ Joystick::Joystick(SDL_Joystick* const joystick, const int sdl_index, const unsi
|
|||
const unsigned int supported_effects = SDL_HapticQuery( m_haptic );
|
||||
|
||||
// constant effect
|
||||
if ( supported_effects & SDL_HAPTIC_CONSTANT )
|
||||
if (supported_effects & SDL_HAPTIC_CONSTANT)
|
||||
{
|
||||
AddOutput( new ConstantEffect( m_state_out.size() ) );
|
||||
m_state_out.push_back( EffectIDState() );
|
||||
m_state_out.push_back(EffectIDState());
|
||||
AddOutput(new ConstantEffect(m_state_out.back()));
|
||||
}
|
||||
|
||||
// ramp effect
|
||||
if ( supported_effects & SDL_HAPTIC_RAMP )
|
||||
if (supported_effects & SDL_HAPTIC_RAMP)
|
||||
{
|
||||
AddOutput( new RampEffect( m_state_out.size() ) );
|
||||
m_state_out.push_back( EffectIDState() );
|
||||
m_state_out.push_back(EffectIDState());
|
||||
AddOutput(new RampEffect(m_state_out.back()));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -125,9 +125,10 @@ Joystick::~Joystick()
|
|||
{
|
||||
// stop/destroy all effects
|
||||
SDL_HapticStopAll(m_haptic);
|
||||
std::vector<EffectIDState>::iterator i = m_state_out.begin(),
|
||||
std::list<EffectIDState>::iterator
|
||||
i = m_state_out.begin(),
|
||||
e = m_state_out.end();
|
||||
for ( ; i!=e; ++i)
|
||||
for ( ; i != e; ++i)
|
||||
if (i->id != -1)
|
||||
SDL_HapticDestroyEffect(m_haptic, i->id);
|
||||
// close haptic first
|
||||
|
@ -150,36 +151,36 @@ std::string Joystick::RampEffect::GetName() const
|
|||
return "Ramp";
|
||||
}
|
||||
|
||||
void Joystick::ConstantEffect::SetState( const ControlState state, Joystick::EffectIDState* const effect )
|
||||
void Joystick::ConstantEffect::SetState(const ControlState state)
|
||||
{
|
||||
if (state)
|
||||
{
|
||||
effect->effect.type = SDL_HAPTIC_CONSTANT;
|
||||
effect->effect.constant.length = SDL_HAPTIC_INFINITY;
|
||||
m_effect.effect.type = SDL_HAPTIC_CONSTANT;
|
||||
m_effect.effect.constant.length = SDL_HAPTIC_INFINITY;
|
||||
}
|
||||
else
|
||||
effect->effect.type = 0;
|
||||
m_effect.effect.type = 0;
|
||||
|
||||
Sint16 old = effect->effect.constant.level;
|
||||
effect->effect.constant.level = state * 0x7FFF;
|
||||
if (old != effect->effect.constant.level)
|
||||
effect->changed = true;
|
||||
const Sint16 old = m_effect.effect.constant.level;
|
||||
m_effect.effect.constant.level = state * 0x7FFF;
|
||||
if (old != m_effect.effect.constant.level)
|
||||
m_effect.changed = true;
|
||||
}
|
||||
|
||||
void Joystick::RampEffect::SetState( const ControlState state, Joystick::EffectIDState* const effect )
|
||||
void Joystick::RampEffect::SetState(const ControlState state)
|
||||
{
|
||||
if (state)
|
||||
{
|
||||
effect->effect.type = SDL_HAPTIC_RAMP;
|
||||
effect->effect.ramp.length = SDL_HAPTIC_INFINITY;
|
||||
m_effect.effect.type = SDL_HAPTIC_RAMP;
|
||||
m_effect.effect.ramp.length = SDL_HAPTIC_INFINITY;
|
||||
}
|
||||
else
|
||||
effect->effect.type = 0;
|
||||
m_effect.effect.type = 0;
|
||||
|
||||
Sint16 old = effect->effect.ramp.start;
|
||||
effect->effect.ramp.start = state * 0x7FFF;
|
||||
if (old != effect->effect.ramp.start)
|
||||
effect->changed = true;
|
||||
const Sint16 old = m_effect.effect.ramp.start;
|
||||
m_effect.effect.ramp.start = state * 0x7FFF;
|
||||
if (old != m_effect.effect.ramp.start)
|
||||
m_effect.changed = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -194,9 +195,11 @@ bool Joystick::UpdateInput()
|
|||
bool Joystick::UpdateOutput()
|
||||
{
|
||||
#ifdef USE_SDL_HAPTIC
|
||||
std::vector<EffectIDState>::iterator i = m_state_out.begin(),
|
||||
std::list<EffectIDState>::iterator
|
||||
i = m_state_out.begin(),
|
||||
e = m_state_out.end();
|
||||
for ( ; i!=e; ++i)
|
||||
for ( ; i != e; ++i)
|
||||
{
|
||||
if (i->changed) // if SetState was called on this output
|
||||
{
|
||||
if (-1 == i->id) // effect isn't currently uploaded
|
||||
|
@ -219,6 +222,7 @@ bool Joystick::UpdateOutput()
|
|||
|
||||
i->changed = false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
#include "../ControllerInterface.h"
|
||||
|
||||
#include <list>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <SDL.h>
|
||||
#else
|
||||
|
@ -38,7 +40,7 @@ private:
|
|||
#ifdef USE_SDL_HAPTIC
|
||||
struct EffectIDState
|
||||
{
|
||||
EffectIDState() : id(-1), changed(false) { memset( &effect, 0, sizeof(effect)); }
|
||||
EffectIDState() : effect(SDL_HapticEffect()), id(-1), changed(false) {}
|
||||
|
||||
SDL_HapticEffect effect;
|
||||
int id;
|
||||
|
@ -86,20 +88,20 @@ private:
|
|||
{
|
||||
public:
|
||||
std::string GetName() const;
|
||||
ConstantEffect( const size_t index ) : Output(index) {}
|
||||
void SetState( const ControlState state, EffectIDState* const effect );
|
||||
ConstantEffect(EffectIDState& effect) : m_effect(effect) {}
|
||||
void SetState(const ControlState state);
|
||||
private:
|
||||
SDL_Joystick* const m_js;
|
||||
EffectIDState& m_effect;
|
||||
};
|
||||
|
||||
class RampEffect : public Output
|
||||
{
|
||||
public:
|
||||
std::string GetName() const;
|
||||
RampEffect( const size_t index ) : Output(index) {}
|
||||
void SetState( const ControlState state, EffectIDState* const effect );
|
||||
RampEffect(EffectIDState& effect) : m_effect(effect) {}
|
||||
void SetState(const ControlState state);
|
||||
private:
|
||||
SDL_Joystick* const m_js;
|
||||
EffectIDState& m_effect;
|
||||
};
|
||||
#endif
|
||||
|
||||
|
@ -120,7 +122,7 @@ private:
|
|||
const unsigned int m_index;
|
||||
|
||||
#ifdef USE_SDL_HAPTIC
|
||||
std::vector<EffectIDState> m_state_out;
|
||||
std::list<EffectIDState> m_state_out;
|
||||
SDL_Haptic* m_haptic;
|
||||
#endif
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue