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:
Jordan Woyak 2011-04-01 23:57:06 +00:00
parent 021193b22f
commit 0ed542206a
2 changed files with 41 additions and 35 deletions

View File

@ -93,7 +93,7 @@ Joystick::Joystick(SDL_Joystick* const joystick, const int sdl_index, const unsi
#ifdef USE_SDL_HAPTIC #ifdef USE_SDL_HAPTIC
// try to get supported ff effects // try to get supported ff effects
m_haptic = SDL_HapticOpenFromJoystick( m_joystick ); m_haptic = SDL_HapticOpenFromJoystick( m_joystick );
if ( m_haptic ) if (m_haptic)
{ {
//SDL_HapticSetGain( m_haptic, 1000 ); //SDL_HapticSetGain( m_haptic, 1000 );
//SDL_HapticSetAutocenter( m_haptic, 0 ); //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 ); const unsigned int supported_effects = SDL_HapticQuery( m_haptic );
// constant effect // 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 // 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 #endif
@ -125,9 +125,10 @@ Joystick::~Joystick()
{ {
// stop/destroy all effects // stop/destroy all effects
SDL_HapticStopAll(m_haptic); 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(); e = m_state_out.end();
for ( ; i!=e; ++i) for ( ; i != e; ++i)
if (i->id != -1) if (i->id != -1)
SDL_HapticDestroyEffect(m_haptic, i->id); SDL_HapticDestroyEffect(m_haptic, i->id);
// close haptic first // close haptic first
@ -150,36 +151,36 @@ std::string Joystick::RampEffect::GetName() const
return "Ramp"; return "Ramp";
} }
void Joystick::ConstantEffect::SetState( const ControlState state, Joystick::EffectIDState* const effect ) void Joystick::ConstantEffect::SetState(const ControlState state)
{ {
if (state) if (state)
{ {
effect->effect.type = SDL_HAPTIC_CONSTANT; m_effect.effect.type = SDL_HAPTIC_CONSTANT;
effect->effect.constant.length = SDL_HAPTIC_INFINITY; m_effect.effect.constant.length = SDL_HAPTIC_INFINITY;
} }
else else
effect->effect.type = 0; m_effect.effect.type = 0;
Sint16 old = effect->effect.constant.level; const Sint16 old = m_effect.effect.constant.level;
effect->effect.constant.level = state * 0x7FFF; m_effect.effect.constant.level = state * 0x7FFF;
if (old != effect->effect.constant.level) if (old != m_effect.effect.constant.level)
effect->changed = true; m_effect.changed = true;
} }
void Joystick::RampEffect::SetState( const ControlState state, Joystick::EffectIDState* const effect ) void Joystick::RampEffect::SetState(const ControlState state)
{ {
if (state) if (state)
{ {
effect->effect.type = SDL_HAPTIC_RAMP; m_effect.effect.type = SDL_HAPTIC_RAMP;
effect->effect.ramp.length = SDL_HAPTIC_INFINITY; m_effect.effect.ramp.length = SDL_HAPTIC_INFINITY;
} }
else else
effect->effect.type = 0; m_effect.effect.type = 0;
Sint16 old = effect->effect.ramp.start; const Sint16 old = m_effect.effect.ramp.start;
effect->effect.ramp.start = state * 0x7FFF; m_effect.effect.ramp.start = state * 0x7FFF;
if (old != effect->effect.ramp.start) if (old != m_effect.effect.ramp.start)
effect->changed = true; m_effect.changed = true;
} }
#endif #endif
@ -194,9 +195,11 @@ bool Joystick::UpdateInput()
bool Joystick::UpdateOutput() bool Joystick::UpdateOutput()
{ {
#ifdef USE_SDL_HAPTIC #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(); e = m_state_out.end();
for ( ; i!=e; ++i) for ( ; i != e; ++i)
{
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
@ -219,6 +222,7 @@ bool Joystick::UpdateOutput()
i->changed = false; i->changed = false;
} }
}
#endif #endif
return true; return true;
} }

View File

@ -3,6 +3,8 @@
#include "../ControllerInterface.h" #include "../ControllerInterface.h"
#include <list>
#ifdef _WIN32 #ifdef _WIN32
#include <SDL.h> #include <SDL.h>
#else #else
@ -38,7 +40,7 @@ private:
#ifdef USE_SDL_HAPTIC #ifdef USE_SDL_HAPTIC
struct EffectIDState struct EffectIDState
{ {
EffectIDState() : id(-1), changed(false) { memset( &effect, 0, sizeof(effect)); } EffectIDState() : effect(SDL_HapticEffect()), id(-1), changed(false) {}
SDL_HapticEffect effect; SDL_HapticEffect effect;
int id; int id;
@ -86,20 +88,20 @@ private:
{ {
public: public:
std::string GetName() const; std::string GetName() const;
ConstantEffect( const size_t index ) : Output(index) {} ConstantEffect(EffectIDState& effect) : m_effect(effect) {}
void SetState( const ControlState state, EffectIDState* const effect ); void SetState(const ControlState state);
private: private:
SDL_Joystick* const m_js; EffectIDState& m_effect;
}; };
class RampEffect : public Output class RampEffect : public Output
{ {
public: public:
std::string GetName() const; std::string GetName() const;
RampEffect( const size_t index ) : Output(index) {} RampEffect(EffectIDState& effect) : m_effect(effect) {}
void SetState( const ControlState state, EffectIDState* const effect ); void SetState(const ControlState state);
private: private:
SDL_Joystick* const m_js; EffectIDState& m_effect;
}; };
#endif #endif
@ -120,7 +122,7 @@ private:
const unsigned int m_index; const unsigned int m_index;
#ifdef USE_SDL_HAPTIC #ifdef USE_SDL_HAPTIC
std::vector<EffectIDState> m_state_out; std::list<EffectIDState> m_state_out;
SDL_Haptic* m_haptic; SDL_Haptic* m_haptic;
#endif #endif
}; };