mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-24 14:49:42 -06:00
GCPadNew now compiles with SDL 1.2, disabling haptic features.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5267 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
@ -5,12 +5,13 @@
|
|||||||
#include "SDL.h"
|
#include "SDL.h"
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
#if SDL_VERSION_ATLEAST(1, 3, 0)
|
||||||
#pragma comment(lib, "SDL.1.3.lib")
|
#pragma comment(lib, "SDL.1.3.lib")
|
||||||
|
#else
|
||||||
|
#pragma comment(lib, "SDL.lib")
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// temp for debuggin
|
|
||||||
//#include <fstream>
|
|
||||||
|
|
||||||
namespace ciface
|
namespace ciface
|
||||||
{
|
{
|
||||||
namespace SDL
|
namespace SDL
|
||||||
@ -18,7 +19,7 @@ namespace SDL
|
|||||||
|
|
||||||
void Init( std::vector<ControllerInterface::Device*>& devices )
|
void Init( std::vector<ControllerInterface::Device*>& devices )
|
||||||
{
|
{
|
||||||
if ( SDL_Init( SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC ) >= 0 )
|
if ( SDL_Init( SDL_INIT_FLAGS ) >= 0 )
|
||||||
{
|
{
|
||||||
// joysticks
|
// joysticks
|
||||||
for( int i = 0; i < SDL_NumJoysticks(); ++i )
|
for( int i = 0; i < SDL_NumJoysticks(); ++i )
|
||||||
@ -60,15 +61,16 @@ Joystick::Joystick( SDL_Joystick* const joystick, const unsigned int index ) : m
|
|||||||
inputs.push_back( new Axis( i, -32768 ) );
|
inputs.push_back( new Axis( i, -32768 ) );
|
||||||
inputs.push_back( new Axis( i, 32767 ) );
|
inputs.push_back( new Axis( i, 32767 ) );
|
||||||
}
|
}
|
||||||
m_haptic = SDL_HapticOpenFromJoystick( m_joystick );
|
|
||||||
|
#ifdef USE_SDL_HAPTIC
|
||||||
// try to get supported ff effects
|
// try to get supported ff effects
|
||||||
|
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 );
|
||||||
|
|
||||||
const unsigned int supported_effects = SDL_HapticQuery( m_haptic ); // use this later
|
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 )
|
||||||
@ -84,15 +86,17 @@ Joystick::Joystick( SDL_Joystick* const joystick, const unsigned int index ) : m
|
|||||||
m_state_out.push_back( EffectIDState() );
|
m_state_out.push_back( EffectIDState() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Joystick::~Joystick()
|
Joystick::~Joystick()
|
||||||
{
|
{
|
||||||
|
#ifdef USE_SDL_HAPTIC
|
||||||
if ( m_haptic )
|
if ( m_haptic )
|
||||||
{
|
{
|
||||||
// stop/destroy all effects
|
// stop/destroy all effects
|
||||||
//SDL_HapticStopAll( m_haptic ); // ControllerInterface handles this
|
SDL_HapticStopAll( m_haptic );
|
||||||
std::vector<EffectIDState>::iterator i = m_state_out.begin(),
|
std::vector<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 )
|
||||||
@ -101,16 +105,13 @@ Joystick::~Joystick()
|
|||||||
// close haptic first
|
// close haptic first
|
||||||
SDL_HapticClose( m_haptic );
|
SDL_HapticClose( m_haptic );
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// close joystick
|
// close joystick
|
||||||
SDL_JoystickClose( m_joystick );
|
SDL_JoystickClose( m_joystick );
|
||||||
}
|
}
|
||||||
|
|
||||||
//std::string Joystick::Effect::GetName() const
|
#ifdef USE_SDL_HAPTIC
|
||||||
//{
|
|
||||||
// return haptic_named_effects[m_index].name;
|
|
||||||
//}
|
|
||||||
|
|
||||||
std::string Joystick::ConstantEffect::GetName() const
|
std::string Joystick::ConstantEffect::GetName() const
|
||||||
{
|
{
|
||||||
return "Constant";
|
return "Constant";
|
||||||
@ -125,14 +126,8 @@ void Joystick::ConstantEffect::SetState( const ControlState state, Joystick::Eff
|
|||||||
{
|
{
|
||||||
if ( state )
|
if ( state )
|
||||||
{
|
{
|
||||||
//debuggin here ...
|
|
||||||
//memset( &effect->effect, 0, sizeof(effect->effect) );
|
|
||||||
effect->effect.type = SDL_HAPTIC_CONSTANT;
|
effect->effect.type = SDL_HAPTIC_CONSTANT;
|
||||||
effect->effect.constant.length = SDL_HAPTIC_INFINITY;
|
effect->effect.constant.length = SDL_HAPTIC_INFINITY;
|
||||||
//effect->effect.constant.attack_length = 3000;
|
|
||||||
//effect->effect.constant.direction.type = SDL_HAPTIC_CARTESIAN;
|
|
||||||
//effect->effect
|
|
||||||
//effect->effect.constant.button = 0xFFFFFFFF;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
effect->effect.type = 0;
|
effect->effect.type = 0;
|
||||||
@ -158,6 +153,7 @@ void Joystick::RampEffect::SetState( const ControlState state, Joystick::EffectI
|
|||||||
if ( old != effect->effect.ramp.start )
|
if ( old != effect->effect.ramp.start )
|
||||||
effect->changed = true;
|
effect->changed = true;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
ControlState Joystick::GetInputState(const ControllerInterface::Device::Input* input)
|
ControlState Joystick::GetInputState(const ControllerInterface::Device::Input* input)
|
||||||
{
|
{
|
||||||
@ -166,18 +162,22 @@ ControlState Joystick::GetInputState(const ControllerInterface::Device::Input* i
|
|||||||
|
|
||||||
void Joystick::SetOutputState(const ControllerInterface::Device::Output* output, const ControlState state)
|
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 ] );
|
((Output*)output)->SetState( state, &m_state_out[ ((Output*)output)->m_index ] );
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Joystick::UpdateInput()
|
bool Joystick::UpdateInput()
|
||||||
{
|
{
|
||||||
SDL_JoystickUpdate(); // each joystick is doin this, o well
|
// each joystick is doin this, o well
|
||||||
|
SDL_JoystickUpdate();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Joystick::UpdateOutput()
|
bool Joystick::UpdateOutput()
|
||||||
{
|
{
|
||||||
|
#ifdef USE_SDL_HAPTIC
|
||||||
std::vector<EffectIDState>::iterator i = m_state_out.begin(),
|
std::vector<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 )
|
||||||
@ -187,25 +187,7 @@ bool Joystick::UpdateOutput()
|
|||||||
{
|
{
|
||||||
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
|
||||||
//std::ofstream file( "SDLgood.txt" );
|
|
||||||
|
|
||||||
/*if ( 0 == */SDL_HapticRunEffect( m_haptic, i->id, 1 );//) // run the effect
|
|
||||||
// file << "all good";
|
|
||||||
//else
|
|
||||||
// file << "not good";
|
|
||||||
//file.close();
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// DEBUG
|
|
||||||
|
|
||||||
//std::ofstream file( "SDLerror.txt" );
|
|
||||||
//file << SDL_GetError();
|
|
||||||
//file.close();
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else // effect is already uploaded
|
else // effect is already uploaded
|
||||||
{
|
{
|
||||||
@ -221,6 +203,7 @@ bool Joystick::UpdateOutput()
|
|||||||
|
|
||||||
i->changed = false;
|
i->changed = false;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,15 +3,25 @@
|
|||||||
|
|
||||||
#include "../ControllerInterface.h"
|
#include "../ControllerInterface.h"
|
||||||
|
|
||||||
// getting rid of warning, sdl/wxwidgets both define it
|
|
||||||
#undef M_PI
|
|
||||||
// really dum
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
#include <SDL_haptic.h>
|
|
||||||
#else
|
#else
|
||||||
#include <SDL/SDL.h>
|
#include <SDL/SDL.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if SDL_VERSION_ATLEAST(1, 3, 0)
|
||||||
|
#define USE_SDL_HAPTIC
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef USE_SDL_HAPTIC
|
||||||
|
#define SDL_INIT_FLAGS SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include <SDL_haptic.h>
|
||||||
|
#else
|
||||||
#include <SDL/SDL_haptic.h>
|
#include <SDL/SDL_haptic.h>
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#define SDL_INIT_FLAGS SDL_INIT_JOYSTICK
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace ciface
|
namespace ciface
|
||||||
@ -28,6 +38,7 @@ class Joystick : public ControllerInterface::Device
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
#ifdef USE_SDL_HAPTIC
|
||||||
class EffectIDState
|
class EffectIDState
|
||||||
{
|
{
|
||||||
friend class Joystick;
|
friend class Joystick;
|
||||||
@ -38,6 +49,7 @@ protected:
|
|||||||
int id;
|
int id;
|
||||||
bool changed;
|
bool changed;
|
||||||
};
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
class Input : public ControllerInterface::Device::Input
|
class Input : public ControllerInterface::Device::Input
|
||||||
{
|
{
|
||||||
@ -49,6 +61,7 @@ protected:
|
|||||||
const unsigned int m_index;
|
const unsigned int m_index;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifdef USE_SDL_HAPTIC
|
||||||
class Output : public ControllerInterface::Device::Output
|
class Output : public ControllerInterface::Device::Output
|
||||||
{
|
{
|
||||||
friend class Joystick;
|
friend class Joystick;
|
||||||
@ -58,6 +71,7 @@ protected:
|
|||||||
|
|
||||||
const size_t m_index;
|
const size_t m_index;
|
||||||
};
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
class Button : public Input
|
class Button : public Input
|
||||||
{
|
{
|
||||||
@ -92,6 +106,7 @@ protected:
|
|||||||
const unsigned int m_direction;
|
const unsigned int m_direction;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifdef USE_SDL_HAPTIC
|
||||||
class ConstantEffect : public Output
|
class ConstantEffect : public Output
|
||||||
{
|
{
|
||||||
friend class Joystick;
|
friend class Joystick;
|
||||||
@ -111,6 +126,7 @@ protected:
|
|||||||
RampEffect( const size_t index ) : Output(index) {}
|
RampEffect( const size_t index ) : Output(index) {}
|
||||||
void SetState( const ControlState state, EffectIDState* const effect );
|
void SetState( const ControlState state, EffectIDState* const effect );
|
||||||
};
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
bool UpdateInput();
|
bool UpdateInput();
|
||||||
bool UpdateOutput();
|
bool UpdateOutput();
|
||||||
@ -127,11 +143,13 @@ public:
|
|||||||
std::string GetSource() const;
|
std::string GetSource() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<EffectIDState> m_state_out;
|
|
||||||
|
|
||||||
SDL_Haptic* m_haptic;
|
|
||||||
SDL_Joystick* const m_joystick;
|
SDL_Joystick* const m_joystick;
|
||||||
const unsigned int m_index;
|
const unsigned int m_index;
|
||||||
|
|
||||||
|
#ifdef USE_SDL_HAPTIC
|
||||||
|
std::vector<EffectIDState> m_state_out;
|
||||||
|
SDL_Haptic* m_haptic;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user