NewGCPad: Sliders should be functional on DirectInput, also Axes renamed. XInput devices won't have their limited DirectInput counterparts listed. Minor cleanup, warning removal.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5260 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
parent
4e1719e98b
commit
c3df2e93d7
|
@ -27,25 +27,10 @@ public:
|
||||||
void LoadConfig();
|
void LoadConfig();
|
||||||
void SaveConfig();
|
void SaveConfig();
|
||||||
|
|
||||||
class Pad : public std::vector<ControllerInterface::ControlReference*>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
class Options
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Options() : adjust_diagonal(1), allow_background_input(false) {}
|
|
||||||
|
|
||||||
ControlState adjust_diagonal; // will contain the full diagonal value from the input device
|
|
||||||
bool allow_background_input;
|
|
||||||
|
|
||||||
} options;
|
|
||||||
};
|
|
||||||
|
|
||||||
std::vector< ControllerEmu* > controllers;
|
std::vector< ControllerEmu* > controllers;
|
||||||
|
|
||||||
Common::CriticalSection controls_crit, interface_crit; // lock controls first
|
Common::CriticalSection controls_crit, interface_crit; // lock controls first
|
||||||
ControllerInterface controller_interface;
|
ControllerInterface controller_interface;
|
||||||
const std::string name;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -220,7 +220,7 @@ void GamepadPage::SetDevice( wxCommandEvent& event )
|
||||||
controller->default_device.FromString( std::string( device_cbox->GetValue().ToAscii() ) );
|
controller->default_device.FromString( std::string( device_cbox->GetValue().ToAscii() ) );
|
||||||
|
|
||||||
// show user what it was validated as
|
// show user what it was validated as
|
||||||
device_cbox->SetLabel( wxString::FromAscii( controller->default_device.ToString().c_str() ) );
|
device_cbox->SetValue( wxString::FromAscii( controller->default_device.ToString().c_str() ) );
|
||||||
|
|
||||||
// this will set all the controls to this default device
|
// this will set all the controls to this default device
|
||||||
controller->UpdateDefaultDevice();
|
controller->UpdateDefaultDevice();
|
||||||
|
@ -233,7 +233,7 @@ void GamepadPage::SetDevice( wxCommandEvent& event )
|
||||||
{
|
{
|
||||||
m_control_dialog->control_reference->device_qualifier.FromString( std::string( m_control_dialog->device_cbox->GetValue().ToAscii() ) );
|
m_control_dialog->control_reference->device_qualifier.FromString( std::string( m_control_dialog->device_cbox->GetValue().ToAscii() ) );
|
||||||
|
|
||||||
m_control_dialog->device_cbox->SetLabel( wxString::FromAscii( m_control_dialog->control_reference->device_qualifier.ToString().c_str() ) );
|
m_control_dialog->device_cbox->SetValue( wxString::FromAscii( m_control_dialog->control_reference->device_qualifier.ToString().c_str() ) );
|
||||||
|
|
||||||
m_plugin.controller_interface.UpdateReference( m_control_dialog->control_reference );
|
m_plugin.controller_interface.UpdateReference( m_control_dialog->control_reference );
|
||||||
|
|
||||||
|
@ -769,7 +769,7 @@ ConfigDialog::ConfigDialog( wxWindow* const parent, Plugin& plugin, const std::s
|
||||||
|
|
||||||
SetSizerAndFit( szr );
|
SetSizerAndFit( szr );
|
||||||
// not needed here it seems, but it cant hurt
|
// not needed here it seems, but it cant hurt
|
||||||
Layout();
|
//Layout();
|
||||||
|
|
||||||
Center();
|
Center();
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,7 @@ void ControllerEmu::LoadConfig( IniFile::Section& sec )
|
||||||
std::vector<ControlGroup::Setting*>::const_iterator si = (*i)->settings.begin(),
|
std::vector<ControlGroup::Setting*>::const_iterator si = (*i)->settings.begin(),
|
||||||
se = (*i)->settings.end();
|
se = (*i)->settings.end();
|
||||||
for ( ; si!=se; ++si )
|
for ( ; si!=se; ++si )
|
||||||
(*si)->value = sec.GetValue(group+(*si)->name, (*si)->default_value*100) / 100;
|
(*si)->value = sec.Get(group+(*si)->name, (*si)->default_value*100) / 100;
|
||||||
|
|
||||||
// controls
|
// controls
|
||||||
std::vector<ControlGroup::Control*>::const_iterator ci = (*i)->controls.begin(),
|
std::vector<ControlGroup::Control*>::const_iterator ci = (*i)->controls.begin(),
|
||||||
|
@ -64,15 +64,15 @@ void ControllerEmu::LoadConfig( IniFile::Section& sec )
|
||||||
{
|
{
|
||||||
// control and dev qualifier
|
// control and dev qualifier
|
||||||
(*ci)->control_ref->control_qualifier.name = sec[group + (*ci)->name];
|
(*ci)->control_ref->control_qualifier.name = sec[group + (*ci)->name];
|
||||||
(*ci)->control_ref->device_qualifier.FromString( sec.GetValue( group+(*ci)->name+"/Device", default_dev ) );
|
(*ci)->control_ref->device_qualifier.FromString( sec.Get( group+(*ci)->name+"/Device", default_dev ) );
|
||||||
|
|
||||||
// range
|
// range
|
||||||
(*ci)->control_ref->range = sec.GetValue( group+(*ci)->name+"/Range", 100.0f ) / 100;
|
(*ci)->control_ref->range = sec.Get( group+(*ci)->name+"/Range", 100.0f ) / 100;
|
||||||
|
|
||||||
// input mode
|
// input mode
|
||||||
if ( (*ci)->control_ref->is_input )
|
if ( (*ci)->control_ref->is_input )
|
||||||
((ControllerInterface::InputReference*)((*ci)->control_ref))->mode
|
((ControllerInterface::InputReference*)((*ci)->control_ref))->mode
|
||||||
= sec.GetValue( group+(*ci)->name+"/Mode", 0 );
|
= sec.Get( group+(*ci)->name+"/Mode", 0 );
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -93,7 +93,7 @@ void ControllerEmu::SaveConfig( IniFile::Section& sec )
|
||||||
std::vector<ControlGroup::Setting*>::const_iterator si = (*i)->settings.begin(),
|
std::vector<ControlGroup::Setting*>::const_iterator si = (*i)->settings.begin(),
|
||||||
se = (*i)->settings.end();
|
se = (*i)->settings.end();
|
||||||
for ( ; si!=se; ++si )
|
for ( ; si!=se; ++si )
|
||||||
sec.SetValue( group+(*si)->name, (*si)->value*100, (*si)->default_value*100 );
|
sec.Set( group+(*si)->name, (*si)->value*100, (*si)->default_value*100 );
|
||||||
|
|
||||||
// controls
|
// controls
|
||||||
std::vector<ControlGroup::Control*>::const_iterator ci = (*i)->controls.begin(),
|
std::vector<ControlGroup::Control*>::const_iterator ci = (*i)->controls.begin(),
|
||||||
|
@ -102,14 +102,14 @@ void ControllerEmu::SaveConfig( IniFile::Section& sec )
|
||||||
{
|
{
|
||||||
// control and dev qualifier
|
// control and dev qualifier
|
||||||
sec[group + (*ci)->name] = (*ci)->control_ref->control_qualifier.name;
|
sec[group + (*ci)->name] = (*ci)->control_ref->control_qualifier.name;
|
||||||
sec.SetValue( group+(*ci)->name+"/Device", (*ci)->control_ref->device_qualifier.ToString(), default_dev );
|
sec.Set( group+(*ci)->name+"/Device", (*ci)->control_ref->device_qualifier.ToString(), default_dev );
|
||||||
|
|
||||||
// range
|
// range
|
||||||
sec.SetValue( group+(*ci)->name+"/Range", (*ci)->control_ref->range*100, 100 );
|
sec.Set( group+(*ci)->name+"/Range", (*ci)->control_ref->range*100, 100 );
|
||||||
|
|
||||||
// input mode
|
// input mode
|
||||||
if ( (*ci)->control_ref->is_input )
|
if ( (*ci)->control_ref->is_input )
|
||||||
sec.SetValue( group+(*ci)->name+"/Mode",
|
sec.Set( group+(*ci)->name+"/Mode",
|
||||||
((ControllerInterface::InputReference*)((*ci)->control_ref))->mode, (unsigned int)0 );
|
((ControllerInterface::InputReference*)((*ci)->control_ref))->mode, (unsigned int)0 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -194,7 +194,7 @@ public:
|
||||||
*digital |= *bitmasks;
|
*digital |= *bitmasks;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
*analog = controls[i+trig_count]->control_ref->State() * range;
|
*analog = S(controls[i+trig_count]->control_ref->State() * range);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -371,26 +371,12 @@ void ControllerInterface::ControlQualifier::FromControl(const ControllerInterfac
|
||||||
// ControlQualifier = = Device :: Control*
|
// ControlQualifier = = Device :: Control*
|
||||||
//
|
//
|
||||||
// check if a control qualifier matches a device control
|
// check if a control qualifier matches a device control
|
||||||
// if qualifier name is /.../ form, uses a regular expression match
|
|
||||||
// also |control1|control2| form, || matches all
|
// also |control1|control2| form, || matches all
|
||||||
//
|
//
|
||||||
bool ControllerInterface::ControlQualifier::operator==(const ControllerInterface::Device::Control* const control) const
|
bool ControllerInterface::ControlQualifier::operator==(const ControllerInterface::Device::Control* const control) const
|
||||||
{
|
{
|
||||||
if ( name.size() )
|
if ( name.size() )
|
||||||
{
|
{
|
||||||
#ifdef CIFACE_USE_REGEX
|
|
||||||
if ( '/' == name[0] && '/' == (*name.rbegin()) ) // check if regex
|
|
||||||
{
|
|
||||||
wxRegEx re(
|
|
||||||
wxString::FromAscii(name.substr( 1, name.size()-2).c_str()).Prepend(wxT("^(")).Append(wxT(")$"))
|
|
||||||
, wxRE_ADVANCED | wxRE_EXTENDED | wxRE_NOSUB | wxRE_ICASE );
|
|
||||||
|
|
||||||
if ( re.IsValid() )
|
|
||||||
return re.Matches( wxString::FromAscii( control->GetName().c_str() ) );
|
|
||||||
else
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
if ( '|' == name[0] && '|' == (*name.rbegin()) ) // check if using |button1|button2| format
|
if ( '|' == name[0] && '|' == (*name.rbegin()) ) // check if using |button1|button2| format
|
||||||
{
|
{
|
||||||
return ( name.find( '|' + control->GetName() + '|' ) != name.npos || "||" == name );
|
return ( name.find( '|' + control->GetName() + '|' ) != name.npos || "||" == name );
|
||||||
|
|
|
@ -7,8 +7,6 @@
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
//#define CIFACE_USE_REGEX
|
|
||||||
|
|
||||||
// enable disable sources
|
// enable disable sources
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#define CIFACE_USE_XINPUT
|
#define CIFACE_USE_XINPUT
|
||||||
|
@ -24,14 +22,6 @@
|
||||||
#define CIFACE_USE_SDL
|
#define CIFACE_USE_SDL
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(HAVE_WX) && HAVE_WX
|
|
||||||
#ifdef CIFACE_USE_REGEX
|
|
||||||
#include <wx/regex.h>
|
|
||||||
#endif
|
|
||||||
#include <wx/stopwatch.h>
|
|
||||||
#include <wx/utils.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// idk in case i wanted to change it to double or somethin, idk what's best
|
// idk in case i wanted to change it to double or somethin, idk what's best
|
||||||
typedef float ControlState;
|
typedef float ControlState;
|
||||||
|
|
||||||
|
@ -137,7 +127,6 @@ public:
|
||||||
//
|
//
|
||||||
// control qualifier includes input and output qualifiers
|
// control qualifier includes input and output qualifiers
|
||||||
// used to match controls on devices, only has name property
|
// used to match controls on devices, only has name property
|
||||||
// if name is blank it matches nothing, if name is /../ form, it matches controls using a regex
|
|
||||||
// |input1|input2| form as well, || matches anything, might change this to * or something
|
// |input1|input2| form as well, || matches anything, might change this to * or something
|
||||||
//
|
//
|
||||||
class ControlQualifier
|
class ControlQualifier
|
||||||
|
@ -182,7 +171,7 @@ public:
|
||||||
// they have a vector < struct { device , vector < controls > } >
|
// they have a vector < struct { device , vector < controls > } >
|
||||||
//
|
//
|
||||||
// after being binded to devices and controls with ControllerInterface::UpdateReference,
|
// after being binded to devices and controls with ControllerInterface::UpdateReference,
|
||||||
// each one can binded to 0+ devices, and 0+ controls on each device
|
// each one can binded to a devices, and 0+ controls the device
|
||||||
// ControlReference can update its own controls when you change its control qualifier
|
// ControlReference can update its own controls when you change its control qualifier
|
||||||
// using ControlReference::UpdateControls but when you change its device qualifer
|
// using ControlReference::UpdateControls but when you change its device qualifer
|
||||||
// you must use ControllerInterface::UpdateReference
|
// you must use ControllerInterface::UpdateReference
|
||||||
|
|
|
@ -9,6 +9,112 @@ namespace ciface
|
||||||
namespace DirectInput
|
namespace DirectInput
|
||||||
{
|
{
|
||||||
|
|
||||||
|
#ifdef NO_DUPLICATE_DINPUT_XINPUT
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Modified some MSDN code to get all the XInput device GUID.Data1 values in a vector,
|
||||||
|
// faster than checking all the devices for each DirectInput device, like MSDN says to do
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
void GetXInputGUIDS( std::vector<DWORD>& guids )
|
||||||
|
{
|
||||||
|
|
||||||
|
#define SAFE_RELEASE(p) { if(p) { (p)->Release(); (p)=NULL; } }
|
||||||
|
|
||||||
|
IWbemLocator* pIWbemLocator = NULL;
|
||||||
|
IEnumWbemClassObject* pEnumDevices = NULL;
|
||||||
|
IWbemClassObject* pDevices[20] = {0};
|
||||||
|
IWbemServices* pIWbemServices = NULL;
|
||||||
|
BSTR bstrNamespace = NULL;
|
||||||
|
BSTR bstrDeviceID = NULL;
|
||||||
|
BSTR bstrClassName = NULL;
|
||||||
|
DWORD uReturned = 0;
|
||||||
|
VARIANT var;
|
||||||
|
HRESULT hr;
|
||||||
|
|
||||||
|
// CoInit if needed
|
||||||
|
hr = CoInitialize(NULL);
|
||||||
|
bool bCleanupCOM = SUCCEEDED(hr);
|
||||||
|
|
||||||
|
// Create WMI
|
||||||
|
hr = CoCreateInstance( __uuidof(WbemLocator),
|
||||||
|
NULL,
|
||||||
|
CLSCTX_INPROC_SERVER,
|
||||||
|
__uuidof(IWbemLocator),
|
||||||
|
(LPVOID*) &pIWbemLocator);
|
||||||
|
if( FAILED(hr) || pIWbemLocator == NULL )
|
||||||
|
goto LCleanup;
|
||||||
|
|
||||||
|
bstrNamespace = SysAllocString( L"\\\\.\\root\\cimv2" );if( bstrNamespace == NULL ) goto LCleanup;
|
||||||
|
bstrClassName = SysAllocString( L"Win32_PNPEntity" ); if( bstrClassName == NULL ) goto LCleanup;
|
||||||
|
bstrDeviceID = SysAllocString( L"DeviceID" ); if( bstrDeviceID == NULL ) goto LCleanup;
|
||||||
|
|
||||||
|
// Connect to WMI
|
||||||
|
hr = pIWbemLocator->ConnectServer( bstrNamespace, NULL, NULL, 0L, 0L, NULL, NULL, &pIWbemServices );
|
||||||
|
if( FAILED(hr) || pIWbemServices == NULL )
|
||||||
|
goto LCleanup;
|
||||||
|
|
||||||
|
// Switch security level to IMPERSONATE.
|
||||||
|
CoSetProxyBlanket( pIWbemServices, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, NULL,
|
||||||
|
RPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE );
|
||||||
|
|
||||||
|
hr = pIWbemServices->CreateInstanceEnum( bstrClassName, 0, NULL, &pEnumDevices );
|
||||||
|
if( FAILED(hr) || pEnumDevices == NULL )
|
||||||
|
goto LCleanup;
|
||||||
|
|
||||||
|
// Loop over all devices
|
||||||
|
while( true )
|
||||||
|
{
|
||||||
|
// Get 20 at a time
|
||||||
|
hr = pEnumDevices->Next( 10000, 20, pDevices, &uReturned );
|
||||||
|
if( FAILED(hr) || uReturned == 0 )
|
||||||
|
break;
|
||||||
|
|
||||||
|
for( UINT iDevice=0; iDevice<uReturned; ++iDevice )
|
||||||
|
{
|
||||||
|
// For each device, get its device ID
|
||||||
|
hr = pDevices[iDevice]->Get( bstrDeviceID, 0L, &var, NULL, NULL );
|
||||||
|
if( SUCCEEDED( hr ) && var.vt == VT_BSTR && var.bstrVal != NULL )
|
||||||
|
{
|
||||||
|
// Check if the device ID contains "IG_". If it does, then it's an XInput device
|
||||||
|
// This information can not be found from DirectInput
|
||||||
|
if( wcsstr( var.bstrVal, L"IG_" ) )
|
||||||
|
{
|
||||||
|
// If it does, then get the VID/PID from var.bstrVal
|
||||||
|
DWORD dwPid = 0, dwVid = 0;
|
||||||
|
WCHAR* strVid = wcsstr( var.bstrVal, L"VID_" );
|
||||||
|
if( strVid && swscanf( strVid, L"VID_%4X", &dwVid ) != 1 )
|
||||||
|
dwVid = 0;
|
||||||
|
WCHAR* strPid = wcsstr( var.bstrVal, L"PID_" );
|
||||||
|
if( strPid && swscanf( strPid, L"PID_%4X", &dwPid ) != 1 )
|
||||||
|
dwPid = 0;
|
||||||
|
|
||||||
|
// Compare the VID/PID to the DInput device
|
||||||
|
DWORD dwVidPid = MAKELONG( dwVid, dwPid );
|
||||||
|
guids.push_back( dwVidPid );
|
||||||
|
//bIsXinputDevice = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SAFE_RELEASE( pDevices[iDevice] );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LCleanup:
|
||||||
|
if(bstrNamespace)
|
||||||
|
SysFreeString(bstrNamespace);
|
||||||
|
if(bstrDeviceID)
|
||||||
|
SysFreeString(bstrDeviceID);
|
||||||
|
if(bstrClassName)
|
||||||
|
SysFreeString(bstrClassName);
|
||||||
|
for( UINT iDevice=0; iDevice<20; iDevice++ )
|
||||||
|
SAFE_RELEASE( pDevices[iDevice] );
|
||||||
|
SAFE_RELEASE( pEnumDevices );
|
||||||
|
SAFE_RELEASE( pIWbemLocator );
|
||||||
|
SAFE_RELEASE( pIWbemServices );
|
||||||
|
|
||||||
|
if( bCleanupCOM )
|
||||||
|
CoUninitialize();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
std::string TStringToString( const std::basic_string<TCHAR>& in )
|
std::string TStringToString( const std::basic_string<TCHAR>& in )
|
||||||
{
|
{
|
||||||
const int size = WideCharToMultiByte( CP_UTF8, 0, in.data(), int(in.length()), NULL, 0, NULL, NULL );
|
const int size = WideCharToMultiByte( CP_UTF8, 0, in.data(), int(in.length()), NULL, 0, NULL, NULL );
|
||||||
|
@ -52,10 +158,20 @@ void InitJoystick( IDirectInput8* const idi8, std::vector<ControllerInterface::D
|
||||||
// multiple joysticks with the same name shall get unique ids starting at 0
|
// multiple joysticks with the same name shall get unique ids starting at 0
|
||||||
std::map< std::basic_string<TCHAR>, ZeroedInt > name_counts;
|
std::map< std::basic_string<TCHAR>, ZeroedInt > name_counts;
|
||||||
|
|
||||||
|
#ifdef NO_DUPLICATE_DINPUT_XINPUT
|
||||||
|
std::vector<DWORD> xinput_guids;
|
||||||
|
GetXInputGUIDS( xinput_guids );
|
||||||
|
#endif
|
||||||
|
|
||||||
std::vector<DIDEVICEINSTANCE>::iterator i = joysticks.begin(),
|
std::vector<DIDEVICEINSTANCE>::iterator i = joysticks.begin(),
|
||||||
e = joysticks.end();
|
e = joysticks.end();
|
||||||
for ( ; i!=e; ++i )
|
for ( ; i!=e; ++i )
|
||||||
{
|
{
|
||||||
|
#ifdef NO_DUPLICATE_DINPUT_XINPUT
|
||||||
|
// skip XInput Devices
|
||||||
|
if ( std::find( xinput_guids.begin(), xinput_guids.end(), i->guidProduct.Data1 ) != xinput_guids.end() )
|
||||||
|
continue;
|
||||||
|
#endif
|
||||||
// TODO: this has potential to mess up on createdev or setdatafmt failure
|
// TODO: this has potential to mess up on createdev or setdatafmt failure
|
||||||
LPDIRECTINPUTDEVICE8 js_device;
|
LPDIRECTINPUTDEVICE8 js_device;
|
||||||
if ( DI_OK == idi8->CreateDevice( i->guidInstance, &js_device, NULL ) )
|
if ( DI_OK == idi8->CreateDevice( i->guidInstance, &js_device, NULL ) )
|
||||||
|
@ -113,17 +229,22 @@ Joystick::Joystick( /*const LPCDIDEVICEINSTANCE lpddi, */const LPDIRECTINPUTDEVI
|
||||||
for ( unsigned int d = 0; d<4; ++d )
|
for ( unsigned int d = 0; d<4; ++d )
|
||||||
inputs.push_back( new Hat( i, d ) );
|
inputs.push_back( new Hat( i, d ) );
|
||||||
}
|
}
|
||||||
// axes / only the first 6 currently
|
// get up to 6 axes and 2 sliders
|
||||||
std::vector<DIDEVICEOBJECTINSTANCE> axes;
|
std::vector<DIDEVICEOBJECTINSTANCE> axes;
|
||||||
|
unsigned int cur_slider = 0;
|
||||||
m_device->EnumObjects( DIEnumDeviceObjectsCallback, (LPVOID)&axes, DIDFT_AXIS );
|
m_device->EnumObjects( DIEnumDeviceObjectsCallback, (LPVOID)&axes, DIDFT_AXIS );
|
||||||
for( unsigned int i = 0; i<axes.size() && i<6; ++i )
|
|
||||||
|
// going in reverse leaves the list more organized in the end for me :/
|
||||||
|
std::vector<DIDEVICEOBJECTINSTANCE>::const_reverse_iterator i = axes.rbegin(),
|
||||||
|
e = axes.rend();
|
||||||
|
for( ; i!=e; ++i )
|
||||||
{
|
{
|
||||||
DIPROPRANGE range;
|
DIPROPRANGE range;
|
||||||
ZeroMemory( &range, sizeof(range ) );
|
ZeroMemory( &range, sizeof(range ) );
|
||||||
range.diph.dwSize = sizeof(range);
|
range.diph.dwSize = sizeof(range);
|
||||||
range.diph.dwHeaderSize = sizeof(range.diph);
|
range.diph.dwHeaderSize = sizeof(range.diph);
|
||||||
range.diph.dwHow = DIPH_BYID;
|
range.diph.dwHow = DIPH_BYID;
|
||||||
range.diph.dwObj = axes[i].dwType;
|
range.diph.dwObj = i->dwType;
|
||||||
// try to set some nice power of 2 values (8192)
|
// try to set some nice power of 2 values (8192)
|
||||||
range.lMin = -(1<<13);
|
range.lMin = -(1<<13);
|
||||||
range.lMax = (1<<13);
|
range.lMax = (1<<13);
|
||||||
|
@ -131,14 +252,36 @@ Joystick::Joystick( /*const LPCDIDEVICEINSTANCE lpddi, */const LPDIRECTINPUTDEVI
|
||||||
m_device->SetProperty( DIPROP_RANGE, &range.diph );
|
m_device->SetProperty( DIPROP_RANGE, &range.diph );
|
||||||
// so i getproperty right afterward incase it didn't set :P
|
// so i getproperty right afterward incase it didn't set :P
|
||||||
if ( DI_OK == m_device->GetProperty( DIPROP_RANGE, &range.diph ) )
|
if ( DI_OK == m_device->GetProperty( DIPROP_RANGE, &range.diph ) )
|
||||||
|
{
|
||||||
|
int offset = -1;
|
||||||
|
const GUID type = i->guidType;
|
||||||
|
|
||||||
|
// figure out which axis this is
|
||||||
|
if ( type == GUID_XAxis )
|
||||||
|
offset = 0;
|
||||||
|
else if ( type == GUID_YAxis )
|
||||||
|
offset = 1;
|
||||||
|
else if ( type == GUID_ZAxis )
|
||||||
|
offset = 2;
|
||||||
|
else if ( type == GUID_RxAxis )
|
||||||
|
offset = 3;
|
||||||
|
else if ( type == GUID_RyAxis )
|
||||||
|
offset = 4;
|
||||||
|
else if ( type == GUID_RzAxis )
|
||||||
|
offset = 5;
|
||||||
|
else if ( type == GUID_Slider )
|
||||||
|
if ( cur_slider < 2 )
|
||||||
|
offset = 6 + cur_slider++;
|
||||||
|
|
||||||
|
if ( offset >= 0 )
|
||||||
{
|
{
|
||||||
const LONG base = (range.lMin + range.lMax) / 2;
|
const LONG base = (range.lMin + range.lMax) / 2;
|
||||||
// each axis gets a negative and a positive input instance associated with it
|
// each axis gets a negative and a positive input instance associated with it
|
||||||
inputs.push_back( new Axis( i, base, range.lMin-base ) );
|
inputs.push_back( new Axis( offset, base, range.lMin-base ) );
|
||||||
inputs.push_back( new Axis( i, base, range.lMax-base ) );
|
inputs.push_back( new Axis( offset, base, range.lMax-base ) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// do people need sliders? maybe later
|
|
||||||
|
|
||||||
// get supported ff effects
|
// get supported ff effects
|
||||||
std::vector<DIDEVICEOBJECTINSTANCE> objects;
|
std::vector<DIDEVICEOBJECTINSTANCE> objects;
|
||||||
|
@ -255,7 +398,7 @@ bool Joystick::UpdateOutput()
|
||||||
{
|
{
|
||||||
i->changed = false;
|
i->changed = false;
|
||||||
DICONSTANTFORCE cf;
|
DICONSTANTFORCE cf;
|
||||||
cf.lMagnitude = 10000 * i->magnitude;
|
cf.lMagnitude = LONG(10000 * i->magnitude);
|
||||||
|
|
||||||
if ( cf.lMagnitude )
|
if ( cf.lMagnitude )
|
||||||
{
|
{
|
||||||
|
@ -290,7 +433,18 @@ std::string Joystick::Button::GetName() const
|
||||||
std::string Joystick::Axis::GetName() const
|
std::string Joystick::Axis::GetName() const
|
||||||
{
|
{
|
||||||
std::ostringstream ss;
|
std::ostringstream ss;
|
||||||
ss << "Axis " << m_index << ( m_range>0 ? '+' : '-' );
|
// axis
|
||||||
|
if ( m_index < 6 )
|
||||||
|
{
|
||||||
|
ss << "Axis " << "XYZ"[m_index%3];
|
||||||
|
if ( m_index > 2 )
|
||||||
|
ss << 'r';
|
||||||
|
}
|
||||||
|
// slider
|
||||||
|
else
|
||||||
|
ss << "Slider " << m_index-6;
|
||||||
|
|
||||||
|
ss << ( m_range>0 ? '+' : '-' );
|
||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,13 @@
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#include <dinput.h>
|
#include <dinput.h>
|
||||||
|
|
||||||
|
#ifdef CIFACE_USE_XINPUT
|
||||||
|
// this takes so long, idk if it should be enabled :(
|
||||||
|
#define NO_DUPLICATE_DINPUT_XINPUT
|
||||||
|
#include <wbemidl.h>
|
||||||
|
#include <oleauto.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace ciface
|
namespace ciface
|
||||||
{
|
{
|
||||||
namespace DirectInput
|
namespace DirectInput
|
||||||
|
|
|
@ -9,6 +9,9 @@
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#include <dinput.h>
|
#include <dinput.h>
|
||||||
|
|
||||||
|
#include <wx/stopwatch.h>
|
||||||
|
#include <wx/utils.h>
|
||||||
|
|
||||||
namespace ciface
|
namespace ciface
|
||||||
{
|
{
|
||||||
namespace DirectInput
|
namespace DirectInput
|
||||||
|
|
|
@ -18,12 +18,12 @@ std::string TrimChars( const std::string& str, const S space )
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// IniSection :: SetValue
|
// IniSection :: Set
|
||||||
//
|
//
|
||||||
// set key's value if it doesn't match the default
|
// set key's value if it doesn't match the default
|
||||||
// otherwise remove the key from the section if it exists
|
// otherwise remove the key from the section if it exists
|
||||||
//
|
//
|
||||||
void IniSection::SetValue( const std::string& key, const std::string& val, const std::string& def )
|
void IniSection::Set( const std::string& key, const std::string& val, const std::string& def )
|
||||||
{
|
{
|
||||||
if ( val != def )
|
if ( val != def )
|
||||||
operator[](key) = val;
|
operator[](key) = val;
|
||||||
|
@ -36,12 +36,12 @@ void IniSection::SetValue( const std::string& key, const std::string& val, const
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// IniSection :: GetValue
|
// IniSection :: Get
|
||||||
//
|
//
|
||||||
// return a key's value if it exists
|
// return a key's value if it exists
|
||||||
// otherwise return the default
|
// otherwise return the default
|
||||||
//
|
//
|
||||||
std::string IniSection::GetValue( const std::string& key, const std::string& def )
|
std::string IniSection::Get( const std::string& key, const std::string& def )
|
||||||
{
|
{
|
||||||
const const_iterator f = find(key);
|
const const_iterator f = find(key);
|
||||||
if ( f != end() )
|
if ( f != end() )
|
||||||
|
|
|
@ -12,11 +12,11 @@
|
||||||
class IniSection : public std::map< std::string, std::string >
|
class IniSection : public std::map< std::string, std::string >
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void SetValue( const std::string& key, const std::string& val, const std::string& def = "" );
|
void Set( const std::string& key, const std::string& val, const std::string& def = "" );
|
||||||
std::string GetValue( const std::string& key, const std::string& def = "" );
|
std::string Get( const std::string& key, const std::string& def = "" );
|
||||||
|
|
||||||
template <typename V, typename D>
|
template <typename V, typename D>
|
||||||
void SetValue( const std::string& key, const V& val, const D& def = 0 )
|
void Set( const std::string& key, const V& val, const D& def = 0 )
|
||||||
{
|
{
|
||||||
if ( val != def )
|
if ( val != def )
|
||||||
{
|
{
|
||||||
|
@ -32,7 +32,7 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
template <typename V>
|
template <typename V>
|
||||||
V GetValue( const std::string& key, const V& def = 0 )
|
V Get( const std::string& key, const V& def = 0 )
|
||||||
{
|
{
|
||||||
const const_iterator f = find(key);
|
const const_iterator f = find(key);
|
||||||
if ( f != end() )
|
if ( f != end() )
|
||||||
|
|
Loading…
Reference in New Issue